diff options
Diffstat (limited to 'arch/ppc64/kernel/udbg.c')
-rw-r--r-- | arch/ppc64/kernel/udbg.c | 300 |
1 files changed, 57 insertions, 243 deletions
diff --git a/arch/ppc64/kernel/udbg.c b/arch/ppc64/kernel/udbg.c index c0da45540f0f..ed6766e21f5a 100644 --- a/arch/ppc64/kernel/udbg.c +++ b/arch/ppc64/kernel/udbg.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * NS16550 Serial Port (uart) debugging stuff. | 2 | * polling mode stateless debugging stuff, originally for NS16550 Serial Ports |
3 | * | 3 | * |
4 | * c 2001 PPC 64 Team, IBM Corp | 4 | * c 2001 PPC 64 Team, IBM Corp |
5 | * | 5 | * |
@@ -13,249 +13,24 @@ | |||
13 | #define WANT_PPCDBG_TAB /* Only defined here */ | 13 | #define WANT_PPCDBG_TAB /* Only defined here */ |
14 | #include <linux/config.h> | 14 | #include <linux/config.h> |
15 | #include <linux/types.h> | 15 | #include <linux/types.h> |
16 | #include <linux/sched.h> | ||
17 | #include <linux/console.h> | ||
16 | #include <asm/ppcdebug.h> | 18 | #include <asm/ppcdebug.h> |
17 | #include <asm/processor.h> | 19 | #include <asm/processor.h> |
18 | #include <asm/uaccess.h> | ||
19 | #include <asm/machdep.h> | ||
20 | #include <asm/io.h> | ||
21 | #include <asm/prom.h> | ||
22 | #include <asm/pmac_feature.h> | ||
23 | 20 | ||
24 | extern u8 real_readb(volatile u8 __iomem *addr); | 21 | void (*udbg_putc)(unsigned char c); |
25 | extern void real_writeb(u8 data, volatile u8 __iomem *addr); | 22 | unsigned char (*udbg_getc)(void); |
26 | 23 | int (*udbg_getc_poll)(void); | |
27 | struct NS16550 { | ||
28 | /* this struct must be packed */ | ||
29 | unsigned char rbr; /* 0 */ | ||
30 | unsigned char ier; /* 1 */ | ||
31 | unsigned char fcr; /* 2 */ | ||
32 | unsigned char lcr; /* 3 */ | ||
33 | unsigned char mcr; /* 4 */ | ||
34 | unsigned char lsr; /* 5 */ | ||
35 | unsigned char msr; /* 6 */ | ||
36 | unsigned char scr; /* 7 */ | ||
37 | }; | ||
38 | |||
39 | #define thr rbr | ||
40 | #define iir fcr | ||
41 | #define dll rbr | ||
42 | #define dlm ier | ||
43 | #define dlab lcr | ||
44 | |||
45 | #define LSR_DR 0x01 /* Data ready */ | ||
46 | #define LSR_OE 0x02 /* Overrun */ | ||
47 | #define LSR_PE 0x04 /* Parity error */ | ||
48 | #define LSR_FE 0x08 /* Framing error */ | ||
49 | #define LSR_BI 0x10 /* Break */ | ||
50 | #define LSR_THRE 0x20 /* Xmit holding register empty */ | ||
51 | #define LSR_TEMT 0x40 /* Xmitter empty */ | ||
52 | #define LSR_ERR 0x80 /* Error */ | ||
53 | |||
54 | static volatile struct NS16550 __iomem *udbg_comport; | ||
55 | |||
56 | void udbg_init_uart(void __iomem *comport, unsigned int speed) | ||
57 | { | ||
58 | u16 dll = speed ? (115200 / speed) : 12; | ||
59 | |||
60 | if (comport) { | ||
61 | udbg_comport = (struct NS16550 __iomem *)comport; | ||
62 | out_8(&udbg_comport->lcr, 0x00); | ||
63 | out_8(&udbg_comport->ier, 0xff); | ||
64 | out_8(&udbg_comport->ier, 0x00); | ||
65 | out_8(&udbg_comport->lcr, 0x80); /* Access baud rate */ | ||
66 | out_8(&udbg_comport->dll, dll & 0xff); /* 1 = 115200, 2 = 57600, | ||
67 | 3 = 38400, 12 = 9600 baud */ | ||
68 | out_8(&udbg_comport->dlm, dll >> 8); /* dll >> 8 which should be zero | ||
69 | for fast rates; */ | ||
70 | out_8(&udbg_comport->lcr, 0x03); /* 8 data, 1 stop, no parity */ | ||
71 | out_8(&udbg_comport->mcr, 0x03); /* RTS/DTR */ | ||
72 | out_8(&udbg_comport->fcr ,0x07); /* Clear & enable FIFOs */ | ||
73 | } | ||
74 | } | ||
75 | |||
76 | #ifdef CONFIG_PPC_PMAC | ||
77 | |||
78 | #define SCC_TXRDY 4 | ||
79 | #define SCC_RXRDY 1 | ||
80 | |||
81 | static volatile u8 __iomem *sccc; | ||
82 | static volatile u8 __iomem *sccd; | ||
83 | |||
84 | static unsigned char scc_inittab[] = { | ||
85 | 13, 0, /* set baud rate divisor */ | ||
86 | 12, 0, | ||
87 | 14, 1, /* baud rate gen enable, src=rtxc */ | ||
88 | 11, 0x50, /* clocks = br gen */ | ||
89 | 5, 0xea, /* tx 8 bits, assert DTR & RTS */ | ||
90 | 4, 0x46, /* x16 clock, 1 stop */ | ||
91 | 3, 0xc1, /* rx enable, 8 bits */ | ||
92 | }; | ||
93 | |||
94 | void udbg_init_scc(struct device_node *np) | ||
95 | { | ||
96 | u32 *reg; | ||
97 | unsigned long addr; | ||
98 | int i, x; | ||
99 | |||
100 | if (np == NULL) | ||
101 | np = of_find_node_by_name(NULL, "escc"); | ||
102 | if (np == NULL || np->parent == NULL) | ||
103 | return; | ||
104 | |||
105 | udbg_printf("found SCC...\n"); | ||
106 | /* Get address within mac-io ASIC */ | ||
107 | reg = (u32 *)get_property(np, "reg", NULL); | ||
108 | if (reg == NULL) | ||
109 | return; | ||
110 | addr = reg[0]; | ||
111 | udbg_printf("local addr: %lx\n", addr); | ||
112 | /* Get address of mac-io PCI itself */ | ||
113 | reg = (u32 *)get_property(np->parent, "assigned-addresses", NULL); | ||
114 | if (reg == NULL) | ||
115 | return; | ||
116 | addr += reg[2]; | ||
117 | udbg_printf("final addr: %lx\n", addr); | ||
118 | |||
119 | /* Setup for 57600 8N1 */ | ||
120 | addr += 0x20; | ||
121 | sccc = (volatile u8 * __iomem) ioremap(addr & PAGE_MASK, PAGE_SIZE) ; | ||
122 | sccc += addr & ~PAGE_MASK; | ||
123 | sccd = sccc + 0x10; | ||
124 | |||
125 | udbg_printf("ioremap result sccc: %p\n", sccc); | ||
126 | mb(); | ||
127 | |||
128 | for (i = 20000; i != 0; --i) | ||
129 | x = in_8(sccc); | ||
130 | out_8(sccc, 0x09); /* reset A or B side */ | ||
131 | out_8(sccc, 0xc0); | ||
132 | for (i = 0; i < sizeof(scc_inittab); ++i) | ||
133 | out_8(sccc, scc_inittab[i]); | ||
134 | |||
135 | ppc_md.udbg_putc = udbg_putc; | ||
136 | ppc_md.udbg_getc = udbg_getc; | ||
137 | ppc_md.udbg_getc_poll = udbg_getc_poll; | ||
138 | |||
139 | udbg_puts("Hello World !\n"); | ||
140 | } | ||
141 | |||
142 | #endif /* CONFIG_PPC_PMAC */ | ||
143 | |||
144 | #ifdef CONFIG_PPC_PMAC | ||
145 | static void udbg_real_putc(unsigned char c) | ||
146 | { | ||
147 | while ((real_readb(sccc) & SCC_TXRDY) == 0) | ||
148 | ; | ||
149 | real_writeb(c, sccd); | ||
150 | if (c == '\n') | ||
151 | udbg_real_putc('\r'); | ||
152 | } | ||
153 | |||
154 | void udbg_init_pmac_realmode(void) | ||
155 | { | ||
156 | sccc = (volatile u8 __iomem *)0x80013020ul; | ||
157 | sccd = (volatile u8 __iomem *)0x80013030ul; | ||
158 | |||
159 | ppc_md.udbg_putc = udbg_real_putc; | ||
160 | ppc_md.udbg_getc = NULL; | ||
161 | ppc_md.udbg_getc_poll = NULL; | ||
162 | } | ||
163 | #endif /* CONFIG_PPC_PMAC */ | ||
164 | |||
165 | #ifdef CONFIG_PPC_MAPLE | ||
166 | void udbg_maple_real_putc(unsigned char c) | ||
167 | { | ||
168 | if (udbg_comport) { | ||
169 | while ((real_readb(&udbg_comport->lsr) & LSR_THRE) == 0) | ||
170 | /* wait for idle */; | ||
171 | real_writeb(c, &udbg_comport->thr); eieio(); | ||
172 | if (c == '\n') { | ||
173 | /* Also put a CR. This is for convenience. */ | ||
174 | while ((real_readb(&udbg_comport->lsr) & LSR_THRE) == 0) | ||
175 | /* wait for idle */; | ||
176 | real_writeb('\r', &udbg_comport->thr); eieio(); | ||
177 | } | ||
178 | } | ||
179 | } | ||
180 | |||
181 | void udbg_init_maple_realmode(void) | ||
182 | { | ||
183 | udbg_comport = (volatile struct NS16550 __iomem *)0xf40003f8; | ||
184 | |||
185 | ppc_md.udbg_putc = udbg_maple_real_putc; | ||
186 | ppc_md.udbg_getc = NULL; | ||
187 | ppc_md.udbg_getc_poll = NULL; | ||
188 | } | ||
189 | #endif /* CONFIG_PPC_MAPLE */ | ||
190 | |||
191 | void udbg_putc(unsigned char c) | ||
192 | { | ||
193 | if (udbg_comport) { | ||
194 | while ((in_8(&udbg_comport->lsr) & LSR_THRE) == 0) | ||
195 | /* wait for idle */; | ||
196 | out_8(&udbg_comport->thr, c); | ||
197 | if (c == '\n') { | ||
198 | /* Also put a CR. This is for convenience. */ | ||
199 | while ((in_8(&udbg_comport->lsr) & LSR_THRE) == 0) | ||
200 | /* wait for idle */; | ||
201 | out_8(&udbg_comport->thr, '\r'); | ||
202 | } | ||
203 | } | ||
204 | #ifdef CONFIG_PPC_PMAC | ||
205 | else if (sccc) { | ||
206 | while ((in_8(sccc) & SCC_TXRDY) == 0) | ||
207 | ; | ||
208 | out_8(sccd, c); | ||
209 | if (c == '\n') | ||
210 | udbg_putc('\r'); | ||
211 | } | ||
212 | #endif /* CONFIG_PPC_PMAC */ | ||
213 | } | ||
214 | |||
215 | int udbg_getc_poll(void) | ||
216 | { | ||
217 | if (udbg_comport) { | ||
218 | if ((in_8(&udbg_comport->lsr) & LSR_DR) != 0) | ||
219 | return in_8(&udbg_comport->rbr); | ||
220 | else | ||
221 | return -1; | ||
222 | } | ||
223 | #ifdef CONFIG_PPC_PMAC | ||
224 | else if (sccc) { | ||
225 | if ((in_8(sccc) & SCC_RXRDY) != 0) | ||
226 | return in_8(sccd); | ||
227 | else | ||
228 | return -1; | ||
229 | } | ||
230 | #endif /* CONFIG_PPC_PMAC */ | ||
231 | return -1; | ||
232 | } | ||
233 | |||
234 | unsigned char udbg_getc(void) | ||
235 | { | ||
236 | if (udbg_comport) { | ||
237 | while ((in_8(&udbg_comport->lsr) & LSR_DR) == 0) | ||
238 | /* wait for char */; | ||
239 | return in_8(&udbg_comport->rbr); | ||
240 | } | ||
241 | #ifdef CONFIG_PPC_PMAC | ||
242 | else if (sccc) { | ||
243 | while ((in_8(sccc) & SCC_RXRDY) == 0) | ||
244 | ; | ||
245 | return in_8(sccd); | ||
246 | } | ||
247 | #endif /* CONFIG_PPC_PMAC */ | ||
248 | return 0; | ||
249 | } | ||
250 | 24 | ||
25 | /* udbg library, used by xmon et al */ | ||
251 | void udbg_puts(const char *s) | 26 | void udbg_puts(const char *s) |
252 | { | 27 | { |
253 | if (ppc_md.udbg_putc) { | 28 | if (udbg_putc) { |
254 | char c; | 29 | char c; |
255 | 30 | ||
256 | if (s && *s != '\0') { | 31 | if (s && *s != '\0') { |
257 | while ((c = *s++) != '\0') | 32 | while ((c = *s++) != '\0') |
258 | ppc_md.udbg_putc(c); | 33 | udbg_putc(c); |
259 | } | 34 | } |
260 | } | 35 | } |
261 | #if 0 | 36 | #if 0 |
@@ -270,12 +45,12 @@ int udbg_write(const char *s, int n) | |||
270 | int remain = n; | 45 | int remain = n; |
271 | char c; | 46 | char c; |
272 | 47 | ||
273 | if (!ppc_md.udbg_putc) | 48 | if (!udbg_putc) |
274 | return 0; | 49 | return 0; |
275 | 50 | ||
276 | if (s && *s != '\0') { | 51 | if (s && *s != '\0') { |
277 | while (((c = *s++) != '\0') && (remain-- > 0)) { | 52 | while (((c = *s++) != '\0') && (remain-- > 0)) { |
278 | ppc_md.udbg_putc(c); | 53 | udbg_putc(c); |
279 | } | 54 | } |
280 | } | 55 | } |
281 | 56 | ||
@@ -287,12 +62,12 @@ int udbg_read(char *buf, int buflen) | |||
287 | char c, *p = buf; | 62 | char c, *p = buf; |
288 | int i; | 63 | int i; |
289 | 64 | ||
290 | if (!ppc_md.udbg_getc) | 65 | if (!udbg_getc) |
291 | return 0; | 66 | return 0; |
292 | 67 | ||
293 | for (i = 0; i < buflen; ++i) { | 68 | for (i = 0; i < buflen; ++i) { |
294 | do { | 69 | do { |
295 | c = ppc_md.udbg_getc(); | 70 | c = udbg_getc(); |
296 | } while (c == 0x11 || c == 0x13); | 71 | } while (c == 0x11 || c == 0x13); |
297 | if (c == 0) | 72 | if (c == 0) |
298 | break; | 73 | break; |
@@ -302,11 +77,6 @@ int udbg_read(char *buf, int buflen) | |||
302 | return i; | 77 | return i; |
303 | } | 78 | } |
304 | 79 | ||
305 | void udbg_console_write(struct console *con, const char *s, unsigned int n) | ||
306 | { | ||
307 | udbg_write(s, n); | ||
308 | } | ||
309 | |||
310 | #define UDBG_BUFSIZE 256 | 80 | #define UDBG_BUFSIZE 256 |
311 | void udbg_printf(const char *fmt, ...) | 81 | void udbg_printf(const char *fmt, ...) |
312 | { | 82 | { |
@@ -319,6 +89,10 @@ void udbg_printf(const char *fmt, ...) | |||
319 | va_end(args); | 89 | va_end(args); |
320 | } | 90 | } |
321 | 91 | ||
92 | /* PPCDBG stuff */ | ||
93 | |||
94 | u64 ppc64_debug_switch; | ||
95 | |||
322 | /* Special print used by PPCDBG() macro */ | 96 | /* Special print used by PPCDBG() macro */ |
323 | void udbg_ppcdbg(unsigned long debug_flags, const char *fmt, ...) | 97 | void udbg_ppcdbg(unsigned long debug_flags, const char *fmt, ...) |
324 | { | 98 | { |
@@ -358,3 +132,43 @@ unsigned long udbg_ifdebug(unsigned long flags) | |||
358 | { | 132 | { |
359 | return (flags & ppc64_debug_switch); | 133 | return (flags & ppc64_debug_switch); |
360 | } | 134 | } |
135 | |||
136 | /* | ||
137 | * Initialize the PPCDBG state. Called before relocation has been enabled. | ||
138 | */ | ||
139 | void __init ppcdbg_initialize(void) | ||
140 | { | ||
141 | ppc64_debug_switch = PPC_DEBUG_DEFAULT; /* | PPCDBG_BUSWALK | */ | ||
142 | /* PPCDBG_PHBINIT | PPCDBG_MM | PPCDBG_MMINIT | PPCDBG_TCEINIT | PPCDBG_TCE */; | ||
143 | } | ||
144 | |||
145 | /* | ||
146 | * Early boot console based on udbg | ||
147 | */ | ||
148 | static void udbg_console_write(struct console *con, const char *s, | ||
149 | unsigned int n) | ||
150 | { | ||
151 | udbg_write(s, n); | ||
152 | } | ||
153 | |||
154 | static struct console udbg_console = { | ||
155 | .name = "udbg", | ||
156 | .write = udbg_console_write, | ||
157 | .flags = CON_PRINTBUFFER, | ||
158 | .index = -1, | ||
159 | }; | ||
160 | |||
161 | void __init disable_early_printk(void) | ||
162 | { | ||
163 | unregister_console(&udbg_console); | ||
164 | } | ||
165 | |||
166 | /* called by setup_system */ | ||
167 | void register_early_udbg_console(void) | ||
168 | { | ||
169 | register_console(&udbg_console); | ||
170 | } | ||
171 | |||
172 | #if 0 /* if you want to use this as a regular output console */ | ||
173 | console_initcall(register_udbg_console); | ||
174 | #endif | ||