diff options
Diffstat (limited to 'arch/ppc64/kernel/udbg_16550.c')
-rw-r--r-- | arch/ppc64/kernel/udbg_16550.c | 123 |
1 files changed, 123 insertions, 0 deletions
diff --git a/arch/ppc64/kernel/udbg_16550.c b/arch/ppc64/kernel/udbg_16550.c new file mode 100644 index 000000000000..9313574ab935 --- /dev/null +++ b/arch/ppc64/kernel/udbg_16550.c | |||
@@ -0,0 +1,123 @@ | |||
1 | /* | ||
2 | * udbg for for NS16550 compatable serial ports | ||
3 | * | ||
4 | * Copyright (C) 2001-2005 PPC 64 Team, IBM Corp | ||
5 | * | ||
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. | ||
10 | */ | ||
11 | #include <linux/config.h> | ||
12 | #include <linux/types.h> | ||
13 | #include <asm/udbg.h> | ||
14 | #include <asm/io.h> | ||
15 | |||
16 | extern u8 real_readb(volatile u8 __iomem *addr); | ||
17 | extern void real_writeb(u8 data, volatile u8 __iomem *addr); | ||
18 | |||
19 | struct NS16550 { | ||
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 */ | ||
29 | }; | ||
30 | |||
31 | #define thr rbr | ||
32 | #define iir fcr | ||
33 | #define dll rbr | ||
34 | #define dlm ier | ||
35 | #define dlab lcr | ||
36 | |||
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 */ | ||
45 | |||
46 | static volatile struct NS16550 __iomem *udbg_comport; | ||
47 | |||
48 | static void udbg_550_putc(unsigned char c) | ||
49 | { | ||
50 | if (udbg_comport) { | ||
51 | while ((in_8(&udbg_comport->lsr) & LSR_THRE) == 0) | ||
52 | /* wait for idle */; | ||
53 | out_8(&udbg_comport->thr, c); | ||
54 | if (c == '\n') | ||
55 | udbg_550_putc('\r'); | ||
56 | } | ||
57 | } | ||
58 | |||
59 | static int udbg_550_getc_poll(void) | ||
60 | { | ||
61 | if (udbg_comport) { | ||
62 | if ((in_8(&udbg_comport->lsr) & LSR_DR) != 0) | ||
63 | return in_8(&udbg_comport->rbr); | ||
64 | else | ||
65 | return -1; | ||
66 | } | ||
67 | return -1; | ||
68 | } | ||
69 | |||
70 | static unsigned char udbg_550_getc(void) | ||
71 | { | ||
72 | if (udbg_comport) { | ||
73 | while ((in_8(&udbg_comport->lsr) & LSR_DR) == 0) | ||
74 | /* wait for char */; | ||
75 | return in_8(&udbg_comport->rbr); | ||
76 | } | ||
77 | return 0; | ||
78 | } | ||
79 | |||
80 | void udbg_init_uart(void __iomem *comport, unsigned int speed) | ||
81 | { | ||
82 | u16 dll = speed ? (115200 / speed) : 12; | ||
83 | |||
84 | if (comport) { | ||
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 | ||
93 | for fast rates; */ | ||
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; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | #ifdef CONFIG_PPC_MAPLE | ||
104 | void udbg_maple_real_putc(unsigned char c) | ||
105 | { | ||
106 | if (udbg_comport) { | ||
107 | while ((real_readb(&udbg_comport->lsr) & LSR_THRE) == 0) | ||
108 | /* wait for idle */; | ||
109 | real_writeb(c, &udbg_comport->thr); eieio(); | ||
110 | if (c == '\n') | ||
111 | udbg_maple_real_putc('\r'); | ||
112 | } | ||
113 | } | ||
114 | |||
115 | void udbg_init_maple_realmode(void) | ||
116 | { | ||
117 | udbg_comport = (volatile struct NS16550 __iomem *)0xf40003f8; | ||
118 | |||
119 | udbg_putc = udbg_maple_real_putc; | ||
120 | udbg_getc = NULL; | ||
121 | udbg_getc_poll = NULL; | ||
122 | } | ||
123 | #endif /* CONFIG_PPC_MAPLE */ | ||