1 | /* |
---|
2 | * console driver for S3C2400 UARTs |
---|
3 | * |
---|
4 | * This driver uses the shared console driver in |
---|
5 | * ...../libbsp/shared/console.c |
---|
6 | * |
---|
7 | * If you want the driver to be interrupt driven, you |
---|
8 | * need to write the ISR, and in the ISR insert the |
---|
9 | * chars into termios's queue. |
---|
10 | * |
---|
11 | * Copyright (c) 2004 Cogent Computer Systems |
---|
12 | * Written by Jay Monkman <jtm@lopingdog.com> |
---|
13 | * |
---|
14 | * The license and distribution terms for this file may be |
---|
15 | * found in the file LICENSE in this distribution or at |
---|
16 | * |
---|
17 | * http://www.rtems.com/license/LICENSE. |
---|
18 | * |
---|
19 | * |
---|
20 | * $Id$ |
---|
21 | */ |
---|
22 | #include <bsp.h> /* Must be before libio.h */ |
---|
23 | #include <rtems/libio.h> |
---|
24 | #include <termios.h> |
---|
25 | #include <rtems/bspIo.h> |
---|
26 | |
---|
27 | /* Put the CPU (or UART) specific header file #include here */ |
---|
28 | #include <s3c2400.h> |
---|
29 | #include <libchip/serial.h> |
---|
30 | #include <libchip/sersupp.h> |
---|
31 | |
---|
32 | /* How many serial ports? */ |
---|
33 | #define NUM_DEVS 1 |
---|
34 | |
---|
35 | int uart_poll_read(int minor); |
---|
36 | |
---|
37 | int dbg_dly; |
---|
38 | |
---|
39 | /* static function prototypes */ |
---|
40 | static int uart_first_open(int major, int minor, void *arg); |
---|
41 | static int uart_last_close(int major, int minor, void *arg); |
---|
42 | static int uart_read(int minor); |
---|
43 | static int uart_write(int minor, const char *buf, int len); |
---|
44 | static void uart_init(int minor); |
---|
45 | static void uart_write_polled(int minor, char c); |
---|
46 | static int uart_set_attributes(int minor, const struct termios *t); |
---|
47 | |
---|
48 | /* These are used by code in console.c */ |
---|
49 | unsigned long Console_Port_Count = NUM_DEVS; |
---|
50 | console_data Console_Port_Data[NUM_DEVS]; |
---|
51 | |
---|
52 | /* rtems console uses the following minor number */ |
---|
53 | rtems_device_minor_number Console_Port_Minor = 0; |
---|
54 | |
---|
55 | /* Pointers to functions for handling the UART. */ |
---|
56 | console_fns uart_fns = |
---|
57 | { |
---|
58 | libchip_serial_default_probe, |
---|
59 | uart_first_open, |
---|
60 | uart_last_close, |
---|
61 | uart_read, |
---|
62 | uart_write, |
---|
63 | uart_init, |
---|
64 | uart_write_polled, /* not used in this driver */ |
---|
65 | uart_set_attributes, |
---|
66 | FALSE /* TRUE if interrupt driven, FALSE if not. */ |
---|
67 | }; |
---|
68 | |
---|
69 | /* |
---|
70 | * There's one item in array for each UART. |
---|
71 | * |
---|
72 | * Some of these fields are marked "NOT USED". They are not used |
---|
73 | * by console.c, but may be used by drivers in libchip |
---|
74 | * |
---|
75 | */ |
---|
76 | console_tbl Console_Port_Tbl[] = { |
---|
77 | { |
---|
78 | "/dev/com0", /* sDeviceName */ |
---|
79 | SERIAL_CUSTOM, /* deviceType */ |
---|
80 | &uart_fns, /* pDeviceFns */ |
---|
81 | NULL, /* deviceProbe */ |
---|
82 | NULL, /* pDeviceFlow */ |
---|
83 | 0, /* ulMargin - NOT USED */ |
---|
84 | 0, /* ulHysteresis - NOT USED */ |
---|
85 | NULL, /* pDeviceParams */ |
---|
86 | 0, /* ulCtrlPort1 - NOT USED */ |
---|
87 | 0, /* ulCtrlPort2 - NOT USED */ |
---|
88 | 0, /* ulDataPort - NOT USED */ |
---|
89 | NULL, /* getRegister - NOT USED */ |
---|
90 | NULL, /* setRegister - NOT USED */ |
---|
91 | NULL, /* getData - NOT USED */ |
---|
92 | NULL, /* setData - NOT USED */ |
---|
93 | 0, /* ulClock - NOT USED */ |
---|
94 | 0 /* ulIntVector - NOT USED */ |
---|
95 | } |
---|
96 | }; |
---|
97 | |
---|
98 | /*********************************************************************/ |
---|
99 | /* Functions called via termios callbacks (i.e. the ones in uart_fns */ |
---|
100 | /*********************************************************************/ |
---|
101 | |
---|
102 | /* |
---|
103 | * This is called the first time each device is opened. If the driver |
---|
104 | * is interrupt driven, you should enable interrupts here. Otherwise, |
---|
105 | * it's probably safe to do nothing. |
---|
106 | * |
---|
107 | * Since micromonitor already set up the UART, we do nothing. |
---|
108 | */ |
---|
109 | static int uart_first_open(int major, int minor, void *arg) |
---|
110 | { |
---|
111 | return 0; |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | /* |
---|
116 | * This is called the last time each device is closed. If the driver |
---|
117 | * is interrupt driven, you should disable interrupts here. Otherwise, |
---|
118 | * it's probably safe to do nothing. |
---|
119 | */ |
---|
120 | static int uart_last_close(int major, int minor, void *arg) |
---|
121 | { |
---|
122 | return 0; |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | /* |
---|
127 | * Read one character from UART. |
---|
128 | * |
---|
129 | * Return -1 if there's no data, otherwise return |
---|
130 | * the character in lowest 8 bits of returned int. |
---|
131 | */ |
---|
132 | static int uart_read(int minor) |
---|
133 | { |
---|
134 | char c; |
---|
135 | |
---|
136 | if (minor == 0) { |
---|
137 | if (rUTRSTAT0 & 0x1) { |
---|
138 | c = rURXH0 & 0xff; |
---|
139 | return c; |
---|
140 | } else { |
---|
141 | return -1; |
---|
142 | } |
---|
143 | } else { |
---|
144 | printk("Unknown console minor number: %d\n", minor); |
---|
145 | return -1; |
---|
146 | } |
---|
147 | |
---|
148 | } |
---|
149 | |
---|
150 | |
---|
151 | /* |
---|
152 | * Write buffer to UART |
---|
153 | * |
---|
154 | * return 1 on success, -1 on error |
---|
155 | */ |
---|
156 | static int uart_write(int minor, const char *buf, int len) |
---|
157 | { |
---|
158 | int i; |
---|
159 | |
---|
160 | if (minor == 0) { |
---|
161 | for (i = 0; i < len; i++) { |
---|
162 | /* Wait for fifo to have room */ |
---|
163 | while(!(rUTRSTAT0 & 0x2)) { |
---|
164 | continue; |
---|
165 | } |
---|
166 | |
---|
167 | rUTXH0 = (char) buf[i]; |
---|
168 | } |
---|
169 | } else { |
---|
170 | printk("Unknown console minor number: %d\n", minor); |
---|
171 | return -1; |
---|
172 | } |
---|
173 | |
---|
174 | return 1; |
---|
175 | } |
---|
176 | |
---|
177 | |
---|
178 | /* Set up the UART. */ |
---|
179 | static void uart_init(int minor) |
---|
180 | { |
---|
181 | int i; |
---|
182 | unsigned int reg = 0; |
---|
183 | |
---|
184 | /* enable UART0 */ |
---|
185 | rCLKCON|=0x100; |
---|
186 | |
---|
187 | /* value is calculated so : (int)(PCLK/16./baudrate) -1 */ |
---|
188 | reg = get_PCLK() / (16 * 115200) - 1; |
---|
189 | |
---|
190 | /* FIFO enable, Tx/Rx FIFO clear */ |
---|
191 | rUFCON0 = 0x07; |
---|
192 | rUMCON0 = 0x0; |
---|
193 | /* Normal,No parity,1 stop,8 bit */ |
---|
194 | rULCON0 = 0x3; |
---|
195 | /* |
---|
196 | * tx=level,rx=edge,disable timeout int.,enable rx error int., |
---|
197 | * normal,interrupt or polling |
---|
198 | */ |
---|
199 | rUCON0 = 0x245; |
---|
200 | rUBRDIV0 = reg; |
---|
201 | |
---|
202 | for (i = 0; i < 100; i++); |
---|
203 | |
---|
204 | } |
---|
205 | |
---|
206 | /* I'm not sure this is needed for the shared console driver. */ |
---|
207 | static void uart_write_polled(int minor, char c) |
---|
208 | { |
---|
209 | uart_write(minor, &c, 1); |
---|
210 | } |
---|
211 | |
---|
212 | /* This is for setting baud rate, bits, etc. */ |
---|
213 | static int uart_set_attributes(int minor, const struct termios *t) |
---|
214 | { |
---|
215 | return 0; |
---|
216 | } |
---|
217 | |
---|
218 | /***********************************************************************/ |
---|
219 | /* |
---|
220 | * The following functions are not used by TERMIOS, but other RTEMS |
---|
221 | * functions use them instead. |
---|
222 | */ |
---|
223 | /***********************************************************************/ |
---|
224 | /* |
---|
225 | * Read from UART. This is used in the exit code, and can't |
---|
226 | * rely on interrupts. |
---|
227 | */ |
---|
228 | int uart_poll_read(int minor) |
---|
229 | { |
---|
230 | return uart_read(minor); |
---|
231 | } |
---|
232 | |
---|
233 | |
---|
234 | /* |
---|
235 | * Write a character to the console. This is used by printk() and |
---|
236 | * maybe other low level functions. It should not use interrupts or any |
---|
237 | * RTEMS system calls. It needs to be very simple |
---|
238 | */ |
---|
239 | static void _BSP_put_char( char c ) { |
---|
240 | uart_write_polled(0, c); |
---|
241 | if (c == '\n') { |
---|
242 | uart_write_polled(0, '\r'); |
---|
243 | } |
---|
244 | } |
---|
245 | |
---|
246 | BSP_output_char_function_type BSP_output_char = _BSP_put_char; |
---|
247 | |
---|
248 | |
---|
249 | |
---|