[PATCH] ppc64: Split SCC and 15550 udbg code
[linux-2.6/btrfs-unstable.git] / arch / ppc64 / kernel / udbg_16550.c
blob46a23e34f7c9c742959064e993c5460f0328b18f
1 /*
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>
13 #include <asm/ppcdebug.h>
14 #include <asm/processor.h>
15 #include <asm/naca.h>
16 #include <asm/uaccess.h>
17 #include <asm/machdep.h>
18 #include <asm/io.h>
19 #include <asm/prom.h>
21 extern u8 real_readb(volatile u8 __iomem *addr);
22 extern void real_writeb(u8 data, volatile u8 __iomem *addr);
24 struct NS16550 {
25 /* this struct must be packed */
26 unsigned char rbr; /* 0 */
27 unsigned char ier; /* 1 */
28 unsigned char fcr; /* 2 */
29 unsigned char lcr; /* 3 */
30 unsigned char mcr; /* 4 */
31 unsigned char lsr; /* 5 */
32 unsigned char msr; /* 6 */
33 unsigned char scr; /* 7 */
36 #define thr rbr
37 #define iir fcr
38 #define dll rbr
39 #define dlm ier
40 #define dlab lcr
42 #define LSR_DR 0x01 /* Data ready */
43 #define LSR_OE 0x02 /* Overrun */
44 #define LSR_PE 0x04 /* Parity error */
45 #define LSR_FE 0x08 /* Framing error */
46 #define LSR_BI 0x10 /* Break */
47 #define LSR_THRE 0x20 /* Xmit holding register empty */
48 #define LSR_TEMT 0x40 /* Xmitter empty */
49 #define LSR_ERR 0x80 /* Error */
51 static volatile struct NS16550 __iomem *udbg_comport;
53 static void udbg_550_putc(unsigned char c)
55 if (udbg_comport) {
56 while ((in_8(&udbg_comport->lsr) & LSR_THRE) == 0)
57 /* wait for idle */;
58 out_8(&udbg_comport->thr, c);
59 if (c == '\n')
60 udbg_550_putc('\r');
64 static int udbg_550_getc_poll(void)
66 if (udbg_comport) {
67 if ((in_8(&udbg_comport->lsr) & LSR_DR) != 0)
68 return in_8(&udbg_comport->rbr);
69 else
70 return -1;
72 return -1;
75 static unsigned char udbg_550_getc(void)
77 if (udbg_comport) {
78 while ((in_8(&udbg_comport->lsr) & LSR_DR) == 0)
79 /* wait for char */;
80 return in_8(&udbg_comport->rbr);
82 return 0;
85 void udbg_init_uart(void __iomem *comport, unsigned int speed)
87 u16 dll = speed ? (115200 / speed) : 12;
89 if (comport) {
90 udbg_comport = (struct NS16550 __iomem *)comport;
91 out_8(&udbg_comport->lcr, 0x00);
92 out_8(&udbg_comport->ier, 0xff);
93 out_8(&udbg_comport->ier, 0x00);
94 out_8(&udbg_comport->lcr, 0x80); /* Access baud rate */
95 out_8(&udbg_comport->dll, dll & 0xff); /* 1 = 115200, 2 = 57600,
96 3 = 38400, 12 = 9600 baud */
97 out_8(&udbg_comport->dlm, dll >> 8); /* dll >> 8 which should be zero
98 for fast rates; */
99 out_8(&udbg_comport->lcr, 0x03); /* 8 data, 1 stop, no parity */
100 out_8(&udbg_comport->mcr, 0x03); /* RTS/DTR */
101 out_8(&udbg_comport->fcr ,0x07); /* Clear & enable FIFOs */
102 ppc_md.udbg_putc = udbg_550_putc;
103 ppc_md.udbg_getc = udbg_550_getc;
104 ppc_md.udbg_getc_poll = udbg_550_getc_poll;
108 #ifdef CONFIG_PPC_MAPLE
109 void udbg_maple_real_putc(unsigned char c)
111 if (udbg_comport) {
112 while ((real_readb(&udbg_comport->lsr) & LSR_THRE) == 0)
113 /* wait for idle */;
114 real_writeb(c, &udbg_comport->thr); eieio();
115 if (c == '\n')
116 udbg_maple_real_putc('\r');
120 void udbg_init_maple_realmode(void)
122 udbg_comport = (volatile struct NS16550 __iomem *)0xf40003f8;
124 ppc_md.udbg_putc = udbg_maple_real_putc;
125 ppc_md.udbg_getc = NULL;
126 ppc_md.udbg_getc_poll = NULL;
128 #endif /* CONFIG_PPC_MAPLE */