2 * udbg for for NS16550 compatable serial ports
4 * Copyright (C) 2001-2005 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.
11 #include <linux/config.h>
12 #include <linux/types.h>
16 extern u8 real_readb(volatile u8 __iomem *addr);
17 extern void real_writeb(u8 data, volatile u8 __iomem *addr);
20 /* this struct must be packed */
21 unsigned char rbr; /* 0 */
22 unsigned char ier; /* 1 */
23 unsigned char fcr; /* 2 */
24 unsigned char lcr; /* 3 */
25 unsigned char mcr; /* 4 */
26 unsigned char lsr; /* 5 */
27 unsigned char msr; /* 6 */
28 unsigned char scr; /* 7 */
37 #define LSR_DR 0x01 /* Data ready */
38 #define LSR_OE 0x02 /* Overrun */
39 #define LSR_PE 0x04 /* Parity error */
40 #define LSR_FE 0x08 /* Framing error */
41 #define LSR_BI 0x10 /* Break */
42 #define LSR_THRE 0x20 /* Xmit holding register empty */
43 #define LSR_TEMT 0x40 /* Xmitter empty */
44 #define LSR_ERR 0x80 /* Error */
46 static volatile struct NS16550 __iomem *udbg_comport;
48 static void udbg_550_putc(unsigned char c)
51 while ((in_8(&udbg_comport->lsr) & LSR_THRE) == 0)
53 out_8(&udbg_comport->thr, c);
59 static int udbg_550_getc_poll(void)
62 if ((in_8(&udbg_comport->lsr) & LSR_DR) != 0)
63 return in_8(&udbg_comport->rbr);
70 static unsigned char udbg_550_getc(void)
73 while ((in_8(&udbg_comport->lsr) & LSR_DR) == 0)
75 return in_8(&udbg_comport->rbr);
80 void udbg_init_uart(void __iomem *comport, unsigned int speed)
82 u16 dll = speed ? (115200 / speed) : 12;
85 udbg_comport = (struct NS16550 __iomem *)comport;
86 out_8(&udbg_comport->lcr, 0x00);
87 out_8(&udbg_comport->ier, 0xff);
88 out_8(&udbg_comport->ier, 0x00);
89 out_8(&udbg_comport->lcr, 0x80); /* Access baud rate */
90 out_8(&udbg_comport->dll, dll & 0xff); /* 1 = 115200, 2 = 57600,
91 3 = 38400, 12 = 9600 baud */
92 out_8(&udbg_comport->dlm, dll >> 8); /* dll >> 8 which should be zero
94 out_8(&udbg_comport->lcr, 0x03); /* 8 data, 1 stop, no parity */
95 out_8(&udbg_comport->mcr, 0x03); /* RTS/DTR */
96 out_8(&udbg_comport->fcr ,0x07); /* Clear & enable FIFOs */
97 udbg_putc = udbg_550_putc;
98 udbg_getc = udbg_550_getc;
99 udbg_getc_poll = udbg_550_getc_poll;
103 #ifdef CONFIG_PPC_MAPLE
104 void udbg_maple_real_putc(unsigned char c)
107 while ((real_readb(&udbg_comport->lsr) & LSR_THRE) == 0)
109 real_writeb(c, &udbg_comport->thr); eieio();
111 udbg_maple_real_putc('\r');
115 void udbg_init_maple_realmode(void)
117 udbg_comport = (volatile struct NS16550 __iomem *)0xf40003f8;
119 udbg_putc = udbg_maple_real_putc;
121 udbg_getc_poll = NULL;
123 #endif /* CONFIG_PPC_MAPLE */