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.
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>
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
);
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 */
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;
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
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
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 */
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
)
101 np
= of_find_node_by_name(NULL
, "escc");
102 if (np
== NULL
|| np
->parent
== NULL
)
105 udbg_printf("found SCC...\n");
106 /* Get address within mac-io ASIC */
107 reg
= (u32
*)get_property(np
, "reg", NULL
);
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
);
117 udbg_printf("final addr: %lx\n", addr
);
119 /* Setup for 57600 8N1 */
121 sccc
= (volatile u8
* __iomem
) ioremap(addr
& PAGE_MASK
, PAGE_SIZE
) ;
122 sccc
+= addr
& ~PAGE_MASK
;
125 udbg_printf("ioremap result sccc: %p\n", sccc
);
128 for (i
= 20000; i
!= 0; --i
)
130 out_8(sccc
, 0x09); /* reset A or B side */
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 */
145 static void udbg_real_putc(unsigned char c
)
147 while ((real_readb(sccc
) & SCC_TXRDY
) == 0)
149 real_writeb(c
, sccd
);
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
)
169 while ((real_readb(&udbg_comport
->lsr
) & LSR_THRE
) == 0)
171 real_writeb(c
, &udbg_comport
->thr
); eieio();
173 /* Also put a CR. This is for convenience. */
174 while ((real_readb(&udbg_comport
->lsr
) & LSR_THRE
) == 0)
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
)
194 while ((in_8(&udbg_comport
->lsr
) & LSR_THRE
) == 0)
196 out_8(&udbg_comport
->thr
, c
);
198 /* Also put a CR. This is for convenience. */
199 while ((in_8(&udbg_comport
->lsr
) & LSR_THRE
) == 0)
201 out_8(&udbg_comport
->thr
, '\r');
204 #ifdef CONFIG_PPC_PMAC
206 while ((in_8(sccc
) & SCC_TXRDY
) == 0)
212 #endif /* CONFIG_PPC_PMAC */
215 int udbg_getc_poll(void)
218 if ((in_8(&udbg_comport
->lsr
) & LSR_DR
) != 0)
219 return in_8(&udbg_comport
->rbr
);
223 #ifdef CONFIG_PPC_PMAC
225 if ((in_8(sccc
) & SCC_RXRDY
) != 0)
230 #endif /* CONFIG_PPC_PMAC */
234 unsigned char udbg_getc(void)
237 while ((in_8(&udbg_comport
->lsr
) & LSR_DR
) == 0)
239 return in_8(&udbg_comport
->rbr
);
241 #ifdef CONFIG_PPC_PMAC
243 while ((in_8(sccc
) & SCC_RXRDY
) == 0)
247 #endif /* CONFIG_PPC_PMAC */
251 void udbg_puts(const char *s
)
253 if (ppc_md
.udbg_putc
) {
256 if (s
&& *s
!= '\0') {
257 while ((c
= *s
++) != '\0')
268 int udbg_write(const char *s
, int n
)
273 if (!ppc_md
.udbg_putc
)
276 if (s
&& *s
!= '\0') {
277 while (((c
= *s
++) != '\0') && (remain
-- > 0)) {
285 int udbg_read(char *buf
, int buflen
)
290 if (!ppc_md
.udbg_getc
)
293 for (i
= 0; i
< buflen
; ++i
) {
295 c
= ppc_md
.udbg_getc();
296 } while (c
== 0x11 || c
== 0x13);
305 void udbg_console_write(struct console
*con
, const char *s
, unsigned int n
)
310 #define UDBG_BUFSIZE 256
311 void udbg_printf(const char *fmt
, ...)
313 unsigned char buf
[UDBG_BUFSIZE
];
317 vsnprintf(buf
, UDBG_BUFSIZE
, fmt
, 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
;
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
) &&
335 len
+= strlen(trace_names
[i
]);
336 udbg_puts(trace_names
[i
]);
341 snprintf(buf
, UDBG_BUFSIZE
, " [%s]: ", current
->comm
);
351 vsnprintf(buf
, UDBG_BUFSIZE
, fmt
, ap
);
357 unsigned long udbg_ifdebug(unsigned long flags
)
359 return (flags
& ppc64_debug_switch
);