[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / arch / ppc64 / kernel / udbg.c
blobd4ccd6f1ef475c2f9d98b1c17ffa3958199abfd1
1 /*
2 * NS16550 Serial Port (uart) debugging stuff.
4 * c 2001 PPC 64 Team, IBM Corp
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
12 #include <stdarg.h>
13 #define WANT_PPCDBG_TAB /* Only defined here */
14 #include <linux/config.h>
15 #include <linux/types.h>
16 #include <asm/ppcdebug.h>
17 #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>
24 extern u8 real_readb(volatile u8 __iomem *addr);
25 extern void real_writeb(u8 data, volatile u8 __iomem *addr);
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 */
39 #define thr rbr
40 #define iir fcr
41 #define dll rbr
42 #define dlm ier
43 #define dlab lcr
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 */
54 static volatile struct NS16550 __iomem *udbg_comport;
56 void udbg_init_uart(void __iomem *comport, unsigned int speed)
58 u16 dll = speed ? (115200 / speed) : 12;
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 */
76 #ifdef CONFIG_PPC_PMAC
78 #define SCC_TXRDY 4
79 #define SCC_RXRDY 1
81 static volatile u8 __iomem *sccc;
82 static volatile u8 __iomem *sccd;
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 */
94 void udbg_init_scc(struct device_node *np)
96 u32 *reg;
97 unsigned long addr;
98 int i, x;
100 if (np == NULL)
101 np = of_find_node_by_name(NULL, "escc");
102 if (np == NULL || np->parent == NULL)
103 return;
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);
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;
125 udbg_printf("ioremap result sccc: %p\n", sccc);
126 mb();
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]);
135 ppc_md.udbg_putc = udbg_putc;
136 ppc_md.udbg_getc = udbg_getc;
137 ppc_md.udbg_getc_poll = udbg_getc_poll;
139 udbg_puts("Hello World !\n");
142 #endif /* CONFIG_PPC_PMAC */
144 #if CONFIG_PPC_PMAC
145 static void udbg_real_putc(unsigned char c)
147 while ((real_readb(sccc) & SCC_TXRDY) == 0)
149 real_writeb(c, sccd);
150 if (c == '\n')
151 udbg_real_putc('\r');
154 void udbg_init_pmac_realmode(void)
156 sccc = (volatile u8 __iomem *)0x80013020ul;
157 sccd = (volatile u8 __iomem *)0x80013030ul;
159 ppc_md.udbg_putc = udbg_real_putc;
160 ppc_md.udbg_getc = NULL;
161 ppc_md.udbg_getc_poll = NULL;
163 #endif /* CONFIG_PPC_PMAC */
165 #ifdef CONFIG_PPC_MAPLE
166 void udbg_maple_real_putc(unsigned char c)
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();
181 void udbg_init_maple_realmode(void)
183 udbg_comport = (volatile struct NS16550 __iomem *)0xf40003f8;
185 ppc_md.udbg_putc = udbg_maple_real_putc;
186 ppc_md.udbg_getc = NULL;
187 ppc_md.udbg_getc_poll = NULL;
189 #endif /* CONFIG_PPC_MAPLE */
191 void udbg_putc(unsigned char c)
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');
204 #ifdef CONFIG_PPC_PMAC
205 else if (sccc) {
206 while ((in_8(sccc) & SCC_TXRDY) == 0)
208 out_8(sccd, c);
209 if (c == '\n')
210 udbg_putc('\r');
212 #endif /* CONFIG_PPC_PMAC */
215 int udbg_getc_poll(void)
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;
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;
230 #endif /* CONFIG_PPC_PMAC */
231 return -1;
234 unsigned char udbg_getc(void)
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);
241 #ifdef CONFIG_PPC_PMAC
242 else if (sccc) {
243 while ((in_8(sccc) & SCC_RXRDY) == 0)
245 return in_8(sccd);
247 #endif /* CONFIG_PPC_PMAC */
248 return 0;
251 void udbg_puts(const char *s)
253 if (ppc_md.udbg_putc) {
254 char c;
256 if (s && *s != '\0') {
257 while ((c = *s++) != '\0')
258 ppc_md.udbg_putc(c);
261 #if 0
262 else {
263 printk("%s", s);
265 #endif
268 int udbg_write(const char *s, int n)
270 int remain = n;
271 char c;
273 if (!ppc_md.udbg_putc)
274 return 0;
276 if (s && *s != '\0') {
277 while (((c = *s++) != '\0') && (remain-- > 0)) {
278 ppc_md.udbg_putc(c);
282 return n - remain;
285 int udbg_read(char *buf, int buflen)
287 char c, *p = buf;
288 int i;
290 if (!ppc_md.udbg_getc)
291 return 0;
293 for (i = 0; i < buflen; ++i) {
294 do {
295 c = ppc_md.udbg_getc();
296 } while (c == 0x11 || c == 0x13);
297 if (c == 0)
298 break;
299 *p++ = c;
302 return i;
305 void udbg_console_write(struct console *con, const char *s, unsigned int n)
307 udbg_write(s, n);
310 #define UDBG_BUFSIZE 256
311 void udbg_printf(const char *fmt, ...)
313 unsigned char buf[UDBG_BUFSIZE];
314 va_list args;
316 va_start(args, fmt);
317 vsnprintf(buf, UDBG_BUFSIZE, fmt, args);
318 udbg_puts(buf);
319 va_end(args);
322 /* Special print used by PPCDBG() macro */
323 void udbg_ppcdbg(unsigned long debug_flags, const char *fmt, ...)
325 unsigned long active_debugs = debug_flags & ppc64_debug_switch;
327 if (active_debugs) {
328 va_list ap;
329 unsigned char buf[UDBG_BUFSIZE];
330 unsigned long i, len = 0;
332 for (i=0; i < PPCDBG_NUM_FLAGS; i++) {
333 if (((1U << i) & active_debugs) &&
334 trace_names[i]) {
335 len += strlen(trace_names[i]);
336 udbg_puts(trace_names[i]);
337 break;
341 snprintf(buf, UDBG_BUFSIZE, " [%s]: ", current->comm);
342 len += strlen(buf);
343 udbg_puts(buf);
345 while (len < 18) {
346 udbg_puts(" ");
347 len++;
350 va_start(ap, fmt);
351 vsnprintf(buf, UDBG_BUFSIZE, fmt, ap);
352 udbg_puts(buf);
353 va_end(ap);
357 unsigned long udbg_ifdebug(unsigned long flags)
359 return (flags & ppc64_debug_switch);