2 * NS16550 Serial Port (uart) debugging stuff.
4 * c 2001 PPC 64 Team, IBM Corp
6 * NOTE: I am trying to make this code avoid any static data references to
7 * simplify debugging early boot. We'll see how that goes...
9 * To use this call udbg_init() first. It will init the uart to 9600 8N1.
10 * You may need to update the COM1 define if your uart is at a different addr.
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
19 #define WANT_PPCDBG_TAB /* Only defined here */
20 #include <asm/ppcdebug.h>
21 #include <asm/processor.h>
23 #include <asm/uaccess.h>
24 #include <asm/machdep.h>
27 /* this struct must be packed */
28 unsigned char rbr; /* 0 */
29 unsigned char ier; /* 1 */
30 unsigned char fcr; /* 2 */
31 unsigned char lcr; /* 3 */
32 unsigned char mcr; /* 4 */
33 unsigned char lsr; /* 5 */
34 unsigned char msr; /* 6 */
35 unsigned char scr; /* 7 */
44 #define LSR_DR 0x01 /* Data ready */
45 #define LSR_OE 0x02 /* Overrun */
46 #define LSR_PE 0x04 /* Parity error */
47 #define LSR_FE 0x08 /* Framing error */
48 #define LSR_BI 0x10 /* Break */
49 #define LSR_THRE 0x20 /* Xmit holding register empty */
50 #define LSR_TEMT 0x40 /* Xmitter empty */
51 #define LSR_ERR 0x80 /* Error */
53 volatile struct NS16550 *udbg_comport;
56 udbg_init_uart(void *comport)
59 udbg_comport = (struct NS16550 *)comport;
60 udbg_comport->lcr = 0x00; eieio();
61 udbg_comport->ier = 0xFF; eieio();
62 udbg_comport->ier = 0x00; eieio();
63 udbg_comport->lcr = 0x80; eieio(); /* Access baud rate */
64 udbg_comport->dll = 12; eieio(); /* 1 = 115200, 2 = 57600, 3 = 38400, 12 = 9600 baud */
65 udbg_comport->dlm = 0; eieio(); /* dll >> 8 which should be zero for fast rates; */
66 udbg_comport->lcr = 0x03; eieio(); /* 8 data, 1 stop, no parity */
67 udbg_comport->mcr = 0x03; eieio(); /* RTS/DTR */
68 udbg_comport->fcr = 0x07; eieio(); /* Clear & enable FIFOs */
73 udbg_putc(unsigned char c)
76 while ((udbg_comport->lsr & LSR_THRE) == 0)
78 udbg_comport->thr = c; eieio();
80 /* Also put a CR. This is for convenience. */
81 while ((udbg_comport->lsr & LSR_THRE) == 0)
83 udbg_comport->thr = '\r'; eieio();
85 } else if (systemcfg->platform == PLATFORM_ISERIES_LPAR) {
86 /* ToDo: switch this via ppc_md */
91 int udbg_getc_poll(void)
94 if ((udbg_comport->lsr & LSR_DR) != 0)
95 return udbg_comport->rbr;
105 if ( udbg_comport ) {
106 while ((udbg_comport->lsr & LSR_DR) == 0)
108 return udbg_comport->rbr;
114 udbg_puts(const char *s)
116 if (ppc_md.udbg_putc) {
119 if (s && *s != '\0') {
120 while ((c = *s++) != '\0')
129 udbg_write(const char *s, int n)
133 if (!ppc_md.udbg_putc)
134 for (;;); /* stop here for cpuctl */
135 if ( s && *s != '\0' ) {
136 while ( (( c = *s++ ) != '\0') && (remain-- > 0)) {
144 udbg_read(char *buf, int buflen) {
147 if (!ppc_md.udbg_putc)
148 for (;;); /* stop here for cpuctl */
149 for (i = 0; i < buflen; ++i) {
151 c = ppc_md.udbg_getc();
152 } while (c == 0x11 || c == 0x13);
159 udbg_console_write(struct console *con, const char *s, unsigned int n)
165 udbg_puthex(unsigned long val)
167 int i, nibbles = sizeof(val)*2;
168 unsigned char buf[sizeof(val)*2+1];
169 for (i = nibbles-1; i >= 0; i--) {
170 buf[i] = (val & 0xf) + '0';
172 buf[i] += ('a'-'0'-10);
180 udbg_printSP(const char *s)
182 if (systemcfg->platform == PLATFORM_PSERIES) {
184 asm("mr %0,1" : "=r" (sp) :);
192 udbg_printf(const char *fmt, ...)
194 unsigned char buf[256];
199 vsprintf(buf, fmt, args);
205 /* Special print used by PPCDBG() macro */
207 udbg_ppcdbg(unsigned long debug_flags, const char *fmt, ...)
209 unsigned long active_debugs = debug_flags & naca->debug_switch;
211 if ( active_debugs ) {
213 unsigned char buf[256];
214 unsigned long i, len = 0;
216 for(i=0; i < PPCDBG_NUM_FLAGS ;i++) {
217 if (((1U << i) & active_debugs) &&
219 len += strlen(trace_names[i]);
220 udbg_puts(trace_names[i]);
224 sprintf(buf, " [%s]: ", current->comm);
234 vsprintf(buf, fmt, ap);
242 udbg_ifdebug(unsigned long flags)
244 return (flags & naca->debug_switch);