1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup QorIQ |
---|
5 | * |
---|
6 | * @brief Console configuration. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2010 embedded brains GmbH. All rights reserved. |
---|
11 | * |
---|
12 | * embedded brains GmbH |
---|
13 | * Obere Lagerstr. 30 |
---|
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.com/license/LICENSE. |
---|
21 | * |
---|
22 | * $Id$ |
---|
23 | */ |
---|
24 | |
---|
25 | #include <assert.h> |
---|
26 | |
---|
27 | #include <rtems/bspIo.h> |
---|
28 | |
---|
29 | #include <libchip/serial.h> |
---|
30 | #include <libchip/ns16550.h> |
---|
31 | |
---|
32 | #include <bspopts.h> |
---|
33 | #include <bsp/irq.h> |
---|
34 | #include <bsp/qoriq.h> |
---|
35 | #include <bsp/intercom.h> |
---|
36 | #include <bsp/uart-bridge.h> |
---|
37 | |
---|
38 | #define CONSOLE_COUNT \ |
---|
39 | (QORIQ_UART_0_ENABLE \ |
---|
40 | + QORIQ_UART_1_ENABLE \ |
---|
41 | + QORIQ_UART_BRIDGE_0_ENABLE \ |
---|
42 | + QORIQ_UART_BRIDGE_1_ENABLE) |
---|
43 | |
---|
44 | #if (QORIQ_UART_0_ENABLE + QORIQ_UART_BRIDGE_0_ENABLE == 2) \ |
---|
45 | || (QORIQ_UART_1_ENABLE + QORIQ_UART_BRIDGE_1_ENABLE == 2) |
---|
46 | #define BRIDGE_MASTER |
---|
47 | #elif QORIQ_UART_BRIDGE_0_ENABLE || QORIQ_UART_BRIDGE_1_ENABLE |
---|
48 | #define BRIDGE_SLAVE |
---|
49 | #endif |
---|
50 | |
---|
51 | #ifdef BRIDGE_MASTER |
---|
52 | #define BRIDGE_FNS &qoriq_uart_bridge_master |
---|
53 | #if QORIQ_UART_BRIDGE_0_ENABLE |
---|
54 | static uart_bridge_master_control bridge_0_control = { |
---|
55 | .device_path = "/dev/ttyS0", |
---|
56 | .type = INTERCOM_TYPE_UART_0, |
---|
57 | .transmit_fifo = RTEMS_CHAIN_INITIALIZER_EMPTY( |
---|
58 | bridge_0_control.transmit_fifo |
---|
59 | ) |
---|
60 | }; |
---|
61 | #define BRIDGE_0_CONTROL &bridge_0_control |
---|
62 | #endif |
---|
63 | #if QORIQ_UART_BRIDGE_1_ENABLE |
---|
64 | static uart_bridge_master_control bridge_1_control = { |
---|
65 | .device_path = "/dev/ttyS1", |
---|
66 | .type = INTERCOM_TYPE_UART_1, |
---|
67 | .transmit_fifo = RTEMS_CHAIN_INITIALIZER_EMPTY( |
---|
68 | bridge_1_control.transmit_fifo |
---|
69 | ) |
---|
70 | }; |
---|
71 | #define BRIDGE_1_CONTROL &bridge_1_control |
---|
72 | #endif |
---|
73 | #endif |
---|
74 | |
---|
75 | #ifdef BRIDGE_SLAVE |
---|
76 | #define BRIDGE_FNS &qoriq_uart_bridge_slave |
---|
77 | #if QORIQ_UART_BRIDGE_0_ENABLE |
---|
78 | static uart_bridge_slave_control bridge_0_control = { |
---|
79 | .type = INTERCOM_TYPE_UART_0, |
---|
80 | .transmit_fifo = RTEMS_CHAIN_INITIALIZER_EMPTY( |
---|
81 | bridge_0_control.transmit_fifo |
---|
82 | ) |
---|
83 | }; |
---|
84 | #define BRIDGE_0_CONTROL &bridge_0_control |
---|
85 | #endif |
---|
86 | #if QORIQ_UART_BRIDGE_1_ENABLE |
---|
87 | static uart_bridge_slave_control bridge_1_control = { |
---|
88 | .type = INTERCOM_TYPE_UART_1, |
---|
89 | .transmit_fifo = RTEMS_CHAIN_INITIALIZER_EMPTY( |
---|
90 | bridge_1_control.transmit_fifo |
---|
91 | ) |
---|
92 | }; |
---|
93 | #define BRIDGE_1_CONTROL &bridge_1_control |
---|
94 | #endif |
---|
95 | #endif |
---|
96 | |
---|
97 | #ifdef BSP_USE_UART_INTERRUPTS |
---|
98 | #define DEVICE_FNS &ns16550_fns |
---|
99 | #else |
---|
100 | #define DEVICE_FNS &ns16550_fns_polled |
---|
101 | #endif |
---|
102 | |
---|
103 | #if QORIQ_UART_0_ENABLE || QORIQ_UART_1_ENABLE |
---|
104 | static uint8_t get_register(uintptr_t addr, uint8_t i) |
---|
105 | { |
---|
106 | volatile uint8_t *reg = (uint8_t *) addr; |
---|
107 | |
---|
108 | return reg [i]; |
---|
109 | } |
---|
110 | |
---|
111 | static void set_register(uintptr_t addr, uint8_t i, uint8_t val) |
---|
112 | { |
---|
113 | volatile uint8_t *reg = (uint8_t *) addr; |
---|
114 | |
---|
115 | reg [i] = val; |
---|
116 | } |
---|
117 | #endif |
---|
118 | |
---|
119 | unsigned long Console_Port_Count = CONSOLE_COUNT; |
---|
120 | |
---|
121 | rtems_device_minor_number Console_Port_Minor; |
---|
122 | |
---|
123 | console_data Console_Port_Data [CONSOLE_COUNT]; |
---|
124 | |
---|
125 | console_tbl Console_Port_Tbl [CONSOLE_COUNT] = { |
---|
126 | #if QORIQ_UART_0_ENABLE |
---|
127 | { |
---|
128 | .sDeviceName = "/dev/ttyS0", |
---|
129 | .deviceType = SERIAL_NS16550, |
---|
130 | .pDeviceFns = DEVICE_FNS, |
---|
131 | .deviceProbe = NULL, |
---|
132 | .pDeviceFlow = NULL, |
---|
133 | .ulMargin = 16, |
---|
134 | .ulHysteresis = 8, |
---|
135 | .pDeviceParams = (void *) BSP_CONSOLE_BAUD, |
---|
136 | .ulCtrlPort1 = (uintptr_t) &qoriq.uart_0, |
---|
137 | .ulCtrlPort2 = 0, |
---|
138 | .ulDataPort = (uintptr_t) &qoriq.uart_0, |
---|
139 | .getRegister = get_register, |
---|
140 | .setRegister = set_register, |
---|
141 | .getData = NULL, |
---|
142 | .setData = NULL, |
---|
143 | .ulClock = 0, |
---|
144 | .ulIntVector = QORIQ_IRQ_DUART |
---|
145 | }, |
---|
146 | #endif |
---|
147 | #if QORIQ_UART_1_ENABLE |
---|
148 | { |
---|
149 | .sDeviceName = "/dev/ttyS1", |
---|
150 | .deviceType = SERIAL_NS16550, |
---|
151 | .pDeviceFns = DEVICE_FNS, |
---|
152 | .deviceProbe = NULL, |
---|
153 | .pDeviceFlow = NULL, |
---|
154 | .ulMargin = 16, |
---|
155 | .ulHysteresis = 8, |
---|
156 | .pDeviceParams = (void *) BSP_CONSOLE_BAUD, |
---|
157 | .ulCtrlPort1 = (uintptr_t) &qoriq.uart_1, |
---|
158 | .ulCtrlPort2 = 0, |
---|
159 | .ulDataPort = (uintptr_t) &qoriq.uart_1, |
---|
160 | .getRegister = get_register, |
---|
161 | .setRegister = set_register, |
---|
162 | .getData = NULL, |
---|
163 | .setData = NULL, |
---|
164 | .ulClock = 0, |
---|
165 | .ulIntVector = QORIQ_IRQ_DUART |
---|
166 | }, |
---|
167 | #endif |
---|
168 | #if QORIQ_UART_BRIDGE_0_ENABLE |
---|
169 | { |
---|
170 | #if QORIQ_UART_1_ENABLE |
---|
171 | .sDeviceName = "/dev/ttyB0", |
---|
172 | #else |
---|
173 | .sDeviceName = "/dev/ttyS0", |
---|
174 | #endif |
---|
175 | .deviceType = SERIAL_CUSTOM, |
---|
176 | .pDeviceFns = BRIDGE_FNS, |
---|
177 | .pDeviceParams = BRIDGE_0_CONTROL |
---|
178 | }, |
---|
179 | #endif |
---|
180 | #if QORIQ_UART_BRIDGE_1_ENABLE |
---|
181 | { |
---|
182 | #if QORIQ_UART_1_ENABLE |
---|
183 | .sDeviceName = "/dev/ttyB1", |
---|
184 | #else |
---|
185 | .sDeviceName = "/dev/ttyS1", |
---|
186 | #endif |
---|
187 | .deviceType = SERIAL_CUSTOM, |
---|
188 | .pDeviceFns = BRIDGE_FNS, |
---|
189 | .pDeviceParams = BRIDGE_1_CONTROL |
---|
190 | } |
---|
191 | #endif |
---|
192 | }; |
---|
193 | |
---|
194 | static void output_char(char c) |
---|
195 | { |
---|
196 | const console_fns *con = Console_Port_Tbl [Console_Port_Minor].pDeviceFns; |
---|
197 | |
---|
198 | if (c == '\n') { |
---|
199 | con->deviceWritePolled((int) Console_Port_Minor, '\r'); |
---|
200 | } |
---|
201 | con->deviceWritePolled((int) Console_Port_Minor, c); |
---|
202 | } |
---|
203 | |
---|
204 | BSP_output_char_function_type BSP_output_char = output_char; |
---|
205 | |
---|
206 | BSP_polling_getchar_function_type BSP_poll_char = NULL; |
---|