diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /arch/ppc/syslib/gen550_dbg.c |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'arch/ppc/syslib/gen550_dbg.c')
-rw-r--r-- | arch/ppc/syslib/gen550_dbg.c | 182 |
1 files changed, 182 insertions, 0 deletions
diff --git a/arch/ppc/syslib/gen550_dbg.c b/arch/ppc/syslib/gen550_dbg.c new file mode 100644 index 000000000000..9ef0113c83d1 --- /dev/null +++ b/arch/ppc/syslib/gen550_dbg.c | |||
@@ -0,0 +1,182 @@ | |||
1 | /* | ||
2 | * arch/ppc/syslib/gen550_dbg.c | ||
3 | * | ||
4 | * A library of polled 16550 serial routines. These are intended to | ||
5 | * be used to support progress messages, xmon, kgdb, etc. on a | ||
6 | * variety of platforms. | ||
7 | * | ||
8 | * Adapted from lots of code ripped from the arch/ppc/boot/ polled | ||
9 | * 16550 support. | ||
10 | * | ||
11 | * Author: Matt Porter <mporter@mvista.com> | ||
12 | * | ||
13 | * 2002-2003 (c) MontaVista Software, Inc. This file is licensed under | ||
14 | * the terms of the GNU General Public License version 2. This program | ||
15 | * is licensed "as is" without any warranty of any kind, whether express | ||
16 | * or implied. | ||
17 | */ | ||
18 | |||
19 | #include <linux/config.h> | ||
20 | #include <linux/types.h> | ||
21 | #include <linux/serial.h> | ||
22 | #include <linux/tty.h> /* For linux/serial_core.h */ | ||
23 | #include <linux/serial_core.h> | ||
24 | #include <linux/serialP.h> | ||
25 | #include <linux/serial_reg.h> | ||
26 | #include <asm/machdep.h> | ||
27 | #include <asm/serial.h> | ||
28 | #include <asm/io.h> | ||
29 | |||
30 | #define SERIAL_BAUD 9600 | ||
31 | |||
32 | /* SERIAL_PORT_DFNS is defined in <asm/serial.h> */ | ||
33 | #ifndef SERIAL_PORT_DFNS | ||
34 | #define SERIAL_PORT_DFNS | ||
35 | #endif | ||
36 | |||
37 | static struct serial_state rs_table[RS_TABLE_SIZE] = { | ||
38 | SERIAL_PORT_DFNS /* defined in <asm/serial.h> */ | ||
39 | }; | ||
40 | |||
41 | static void (*serial_outb)(unsigned long, unsigned char); | ||
42 | static unsigned long (*serial_inb)(unsigned long); | ||
43 | |||
44 | static int shift; | ||
45 | |||
46 | unsigned long direct_inb(unsigned long addr) | ||
47 | { | ||
48 | return readb((void __iomem *)addr); | ||
49 | } | ||
50 | |||
51 | void direct_outb(unsigned long addr, unsigned char val) | ||
52 | { | ||
53 | writeb(val, (void __iomem *)addr); | ||
54 | } | ||
55 | |||
56 | unsigned long io_inb(unsigned long port) | ||
57 | { | ||
58 | return inb(port); | ||
59 | } | ||
60 | |||
61 | void io_outb(unsigned long port, unsigned char val) | ||
62 | { | ||
63 | outb(val, port); | ||
64 | } | ||
65 | |||
66 | unsigned long serial_init(int chan, void *ignored) | ||
67 | { | ||
68 | unsigned long com_port; | ||
69 | unsigned char lcr, dlm; | ||
70 | |||
71 | /* We need to find out which type io we're expecting. If it's | ||
72 | * 'SERIAL_IO_PORT', we get an offset from the isa_io_base. | ||
73 | * If it's 'SERIAL_IO_MEM', we can the exact location. -- Tom */ | ||
74 | switch (rs_table[chan].io_type) { | ||
75 | case SERIAL_IO_PORT: | ||
76 | com_port = rs_table[chan].port; | ||
77 | serial_outb = io_outb; | ||
78 | serial_inb = io_inb; | ||
79 | break; | ||
80 | case SERIAL_IO_MEM: | ||
81 | com_port = (unsigned long)rs_table[chan].iomem_base; | ||
82 | serial_outb = direct_outb; | ||
83 | serial_inb = direct_inb; | ||
84 | break; | ||
85 | default: | ||
86 | /* We can't deal with it. */ | ||
87 | return -1; | ||
88 | } | ||
89 | |||
90 | /* How far apart the registers are. */ | ||
91 | shift = rs_table[chan].iomem_reg_shift; | ||
92 | |||
93 | /* save the LCR */ | ||
94 | lcr = serial_inb(com_port + (UART_LCR << shift)); | ||
95 | |||
96 | /* Access baud rate */ | ||
97 | serial_outb(com_port + (UART_LCR << shift), UART_LCR_DLAB); | ||
98 | dlm = serial_inb(com_port + (UART_DLM << shift)); | ||
99 | |||
100 | /* | ||
101 | * Test if serial port is unconfigured | ||
102 | * We assume that no-one uses less than 110 baud or | ||
103 | * less than 7 bits per character these days. | ||
104 | * -- paulus. | ||
105 | */ | ||
106 | if ((dlm <= 4) && (lcr & 2)) { | ||
107 | /* port is configured, put the old LCR back */ | ||
108 | serial_outb(com_port + (UART_LCR << shift), lcr); | ||
109 | } | ||
110 | else { | ||
111 | /* Input clock. */ | ||
112 | serial_outb(com_port + (UART_DLL << shift), | ||
113 | (rs_table[chan].baud_base / SERIAL_BAUD) & 0xFF); | ||
114 | serial_outb(com_port + (UART_DLM << shift), | ||
115 | (rs_table[chan].baud_base / SERIAL_BAUD) >> 8); | ||
116 | /* 8 data, 1 stop, no parity */ | ||
117 | serial_outb(com_port + (UART_LCR << shift), 0x03); | ||
118 | /* RTS/DTR */ | ||
119 | serial_outb(com_port + (UART_MCR << shift), 0x03); | ||
120 | |||
121 | /* Clear & enable FIFOs */ | ||
122 | serial_outb(com_port + (UART_FCR << shift), 0x07); | ||
123 | } | ||
124 | |||
125 | return (com_port); | ||
126 | } | ||
127 | |||
128 | void | ||
129 | serial_putc(unsigned long com_port, unsigned char c) | ||
130 | { | ||
131 | while ((serial_inb(com_port + (UART_LSR << shift)) & UART_LSR_THRE) == 0) | ||
132 | ; | ||
133 | serial_outb(com_port, c); | ||
134 | } | ||
135 | |||
136 | unsigned char | ||
137 | serial_getc(unsigned long com_port) | ||
138 | { | ||
139 | while ((serial_inb(com_port + (UART_LSR << shift)) & UART_LSR_DR) == 0) | ||
140 | ; | ||
141 | return serial_inb(com_port); | ||
142 | } | ||
143 | |||
144 | int | ||
145 | serial_tstc(unsigned long com_port) | ||
146 | { | ||
147 | return ((serial_inb(com_port + (UART_LSR << shift)) & UART_LSR_DR) != 0); | ||
148 | } | ||
149 | |||
150 | void | ||
151 | serial_close(unsigned long com_port) | ||
152 | { | ||
153 | } | ||
154 | |||
155 | void | ||
156 | gen550_init(int i, struct uart_port *serial_req) | ||
157 | { | ||
158 | rs_table[i].io_type = serial_req->iotype; | ||
159 | rs_table[i].port = serial_req->iobase; | ||
160 | rs_table[i].iomem_base = serial_req->membase; | ||
161 | rs_table[i].iomem_reg_shift = serial_req->regshift; | ||
162 | rs_table[i].baud_base = serial_req->uartclk ? serial_req->uartclk / 16 : BASE_BAUD; | ||
163 | } | ||
164 | |||
165 | #ifdef CONFIG_SERIAL_TEXT_DEBUG | ||
166 | void | ||
167 | gen550_progress(char *s, unsigned short hex) | ||
168 | { | ||
169 | volatile unsigned int progress_debugport; | ||
170 | volatile char c; | ||
171 | |||
172 | progress_debugport = serial_init(0, NULL); | ||
173 | |||
174 | serial_putc(progress_debugport, '\r'); | ||
175 | |||
176 | while ((c = *s++) != 0) | ||
177 | serial_putc(progress_debugport, c); | ||
178 | |||
179 | serial_putc(progress_debugport, '\n'); | ||
180 | serial_putc(progress_debugport, '\r'); | ||
181 | } | ||
182 | #endif /* CONFIG_SERIAL_TEXT_DEBUG */ | ||