1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup arm_lpc32xx |
---|
5 | * |
---|
6 | * @brief Console configuration. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2009-2014 embedded brains GmbH. All rights reserved. |
---|
11 | * |
---|
12 | * embedded brains GmbH |
---|
13 | * Dornierstr. 4 |
---|
14 | * 82178 Puchheim |
---|
15 | * Germany |
---|
16 | * <rtems@embedded-brains.de> |
---|
17 | * |
---|
18 | * The license and distribution terms for this file may be |
---|
19 | * found in the file LICENSE in this distribution or at |
---|
20 | * http://www.rtems.org/license/LICENSE. |
---|
21 | */ |
---|
22 | |
---|
23 | #include <libchip/ns16550.h> |
---|
24 | |
---|
25 | #include <bsp.h> |
---|
26 | #include <bsp/lpc32xx.h> |
---|
27 | #include <bsp/irq.h> |
---|
28 | #include <bsp/hsu.h> |
---|
29 | #include <bsp/console-termios.h> |
---|
30 | |
---|
31 | static uint8_t lpc32xx_uart_get_register(uintptr_t addr, uint8_t i) |
---|
32 | { |
---|
33 | volatile uint32_t *reg = (volatile uint32_t *) addr; |
---|
34 | |
---|
35 | return (uint8_t) reg [i]; |
---|
36 | } |
---|
37 | |
---|
38 | static void lpc32xx_uart_set_register(uintptr_t addr, uint8_t i, uint8_t val) |
---|
39 | { |
---|
40 | volatile uint32_t *reg = (volatile uint32_t *) addr; |
---|
41 | |
---|
42 | reg [i] = val; |
---|
43 | } |
---|
44 | |
---|
45 | #ifdef LPC32XX_UART_3_BAUD |
---|
46 | static bool lpc32xx_uart_probe_3(rtems_termios_device_context *context) |
---|
47 | { |
---|
48 | LPC32XX_UARTCLK_CTRL |= BSP_BIT32(0); |
---|
49 | LPC32XX_U3CLK = LPC32XX_CONFIG_U3CLK; |
---|
50 | LPC32XX_UART_CLKMODE = BSP_FLD32SET(LPC32XX_UART_CLKMODE, 0x2, 4, 5); |
---|
51 | |
---|
52 | return ns16550_probe(context); |
---|
53 | } |
---|
54 | #endif |
---|
55 | |
---|
56 | #ifdef LPC32XX_UART_4_BAUD |
---|
57 | static bool lpc32xx_uart_probe_4(rtems_termios_device_context *context) |
---|
58 | { |
---|
59 | volatile lpc32xx_gpio *gpio = &lpc32xx.gpio; |
---|
60 | |
---|
61 | /* |
---|
62 | * Set GPO_21/U4_TX/LCDVD[3] to U4_TX. This works only if LCD module is |
---|
63 | * disabled. |
---|
64 | */ |
---|
65 | gpio->p2_mux_set = BSP_BIT32(2); |
---|
66 | |
---|
67 | LPC32XX_UARTCLK_CTRL |= BSP_BIT32(1); |
---|
68 | LPC32XX_U4CLK = LPC32XX_CONFIG_U4CLK; |
---|
69 | LPC32XX_UART_CLKMODE = BSP_FLD32SET(LPC32XX_UART_CLKMODE, 0x2, 6, 7); |
---|
70 | |
---|
71 | return ns16550_probe(context); |
---|
72 | } |
---|
73 | #endif |
---|
74 | |
---|
75 | #ifdef LPC32XX_UART_6_BAUD |
---|
76 | static bool lpc32xx_uart_probe_6(rtems_termios_device_context *context) |
---|
77 | { |
---|
78 | /* Bypass the IrDA modulator/demodulator */ |
---|
79 | LPC32XX_UART_CTRL |= BSP_BIT32(5); |
---|
80 | |
---|
81 | LPC32XX_UARTCLK_CTRL |= BSP_BIT32(3); |
---|
82 | LPC32XX_U6CLK = LPC32XX_CONFIG_U6CLK; |
---|
83 | LPC32XX_UART_CLKMODE = BSP_FLD32SET(LPC32XX_UART_CLKMODE, 0x2, 10, 11); |
---|
84 | |
---|
85 | return ns16550_probe(context); |
---|
86 | } |
---|
87 | #endif |
---|
88 | |
---|
89 | /* FIXME: Console selection */ |
---|
90 | |
---|
91 | #ifdef LPC32XX_UART_5_BAUD |
---|
92 | static ns16550_context lpc32xx_uart_context_5 = { |
---|
93 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 5"), |
---|
94 | .get_reg = lpc32xx_uart_get_register, |
---|
95 | .set_reg = lpc32xx_uart_set_register, |
---|
96 | .port = LPC32XX_BASE_UART_5, |
---|
97 | .irq = LPC32XX_IRQ_UART_5, |
---|
98 | .clock = 16 * LPC32XX_UART_5_BAUD, |
---|
99 | .initial_baud = LPC32XX_UART_5_BAUD |
---|
100 | }; |
---|
101 | #endif |
---|
102 | |
---|
103 | #ifdef LPC32XX_UART_3_BAUD |
---|
104 | static ns16550_context lpc32xx_uart_context_3 = { |
---|
105 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 3"), |
---|
106 | .get_reg = lpc32xx_uart_get_register, |
---|
107 | .set_reg = lpc32xx_uart_set_register, |
---|
108 | .port = LPC32XX_BASE_UART_3, |
---|
109 | .irq = LPC32XX_IRQ_UART_3, |
---|
110 | .clock = 16 * LPC32XX_UART_3_BAUD, |
---|
111 | .initial_baud = LPC32XX_UART_3_BAUD |
---|
112 | }; |
---|
113 | #endif |
---|
114 | |
---|
115 | #ifdef LPC32XX_UART_4_BAUD |
---|
116 | static ns16550_context lpc32xx_uart_context_4 = { |
---|
117 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 4"), |
---|
118 | .get_reg = lpc32xx_uart_get_register, |
---|
119 | .set_reg = lpc32xx_uart_set_register, |
---|
120 | .port = LPC32XX_BASE_UART_4, |
---|
121 | .irq = LPC32XX_IRQ_UART_4, |
---|
122 | .clock = 16 * LPC32XX_UART_4_BAUD, |
---|
123 | .initial_baud = LPC32XX_UART_4_BAUD |
---|
124 | }; |
---|
125 | #endif |
---|
126 | |
---|
127 | #ifdef LPC32XX_UART_6_BAUD |
---|
128 | static ns16550_context lpc32xx_uart_context_6 = { |
---|
129 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 6"), |
---|
130 | .get_reg = lpc32xx_uart_get_register, |
---|
131 | .set_reg = lpc32xx_uart_set_register, |
---|
132 | .port = LPC32XX_BASE_UART_6, |
---|
133 | .irq = LPC32XX_IRQ_UART_6, |
---|
134 | .clock = 16 * LPC32XX_UART_6_BAUD, |
---|
135 | .initial_baud = LPC32XX_UART_6_BAUD |
---|
136 | }; |
---|
137 | #endif |
---|
138 | |
---|
139 | #ifdef LPC32XX_UART_1_BAUD |
---|
140 | static lpc32xx_hsu_context lpc32xx_uart_context_1 = { |
---|
141 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 1"), |
---|
142 | .hsu = (volatile lpc32xx_hsu *) LPC32XX_BASE_UART_1, |
---|
143 | .irq = LPC32XX_IRQ_UART_1, |
---|
144 | .initial_baud = LPC32XX_UART_1_BAUD |
---|
145 | }; |
---|
146 | #endif |
---|
147 | |
---|
148 | #ifdef LPC32XX_UART_2_BAUD |
---|
149 | static lpc32xx_hsu_context lpc32xx_uart_context_2 = { |
---|
150 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 2"), |
---|
151 | .hsu = (volatile lpc32xx_hsu *) LPC32XX_BASE_UART_2, |
---|
152 | .irq = LPC32XX_IRQ_UART_2, |
---|
153 | .initial_baud = LPC32XX_UART_2_BAUD |
---|
154 | }; |
---|
155 | #endif |
---|
156 | |
---|
157 | #ifdef LPC32XX_UART_7_BAUD |
---|
158 | static lpc32xx_hsu_context lpc32xx_uart_context_7 = { |
---|
159 | .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("UART 7"), |
---|
160 | .hsu = (volatile lpc32xx_hsu *) LPC32XX_BASE_UART_7, |
---|
161 | .irq = LPC32XX_IRQ_UART_7, |
---|
162 | .initial_baud = LPC32XX_UART_7_BAUD |
---|
163 | }; |
---|
164 | #endif |
---|
165 | |
---|
166 | const console_device console_device_table[] = { |
---|
167 | #ifdef LPC32XX_UART_5_BAUD |
---|
168 | { |
---|
169 | .device_file = "/dev/ttyS5", |
---|
170 | .probe = console_device_probe_default, |
---|
171 | .handler = &ns16550_handler_interrupt, |
---|
172 | .context = &lpc32xx_uart_context_5.base |
---|
173 | }, |
---|
174 | #endif |
---|
175 | #ifdef LPC32XX_UART_3_BAUD |
---|
176 | { |
---|
177 | .device_file = "/dev/ttyS3", |
---|
178 | .probe = lpc32xx_uart_probe_3, |
---|
179 | .handler = &ns16550_handler_interrupt, |
---|
180 | .context = &lpc32xx_uart_context_3.base |
---|
181 | }, |
---|
182 | #endif |
---|
183 | #ifdef LPC32XX_UART_4_BAUD |
---|
184 | { |
---|
185 | .device_file = "/dev/ttyS4", |
---|
186 | .probe = lpc32xx_uart_probe_4, |
---|
187 | .handler = &ns16550_handler_interrupt, |
---|
188 | .context = &lpc32xx_uart_context_4.base |
---|
189 | }, |
---|
190 | #endif |
---|
191 | #ifdef LPC32XX_UART_6_BAUD |
---|
192 | { |
---|
193 | .device_file = "/dev/ttyS6", |
---|
194 | .probe = lpc32xx_uart_probe_6, |
---|
195 | .handler = &ns16550_handler_interrupt, |
---|
196 | .context = &lpc32xx_uart_context_6.base |
---|
197 | }, |
---|
198 | #endif |
---|
199 | #ifdef LPC32XX_UART_1_BAUD |
---|
200 | { |
---|
201 | .device_file = "/dev/ttyS1", |
---|
202 | .probe = lpc32xx_hsu_probe, |
---|
203 | .handler = &lpc32xx_hsu_fns, |
---|
204 | .context = &lpc32xx_uart_context_1.base |
---|
205 | }, |
---|
206 | #endif |
---|
207 | #ifdef LPC32XX_UART_2_BAUD |
---|
208 | { |
---|
209 | .device_file = "/dev/ttyS2", |
---|
210 | .probe = lpc32xx_hsu_probe, |
---|
211 | .handler = &lpc32xx_hsu_fns, |
---|
212 | .context = &lpc32xx_uart_context_2.base |
---|
213 | }, |
---|
214 | #endif |
---|
215 | #ifdef LPC32XX_UART_7_BAUD |
---|
216 | { |
---|
217 | .device_file = "/dev/ttyS7", |
---|
218 | .probe = lpc32xx_hsu_probe, |
---|
219 | .handler = &lpc32xx_hsu_fns, |
---|
220 | .context = &lpc32xx_uart_context_7.base |
---|
221 | }, |
---|
222 | #endif |
---|
223 | }; |
---|
224 | |
---|
225 | const size_t console_device_count = RTEMS_ARRAY_SIZE(console_device_table); |
---|