1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /** |
---|
4 | * @file |
---|
5 | * |
---|
6 | * This file contains the libchip configuration information |
---|
7 | * to instantiate the libchip driver for the VGA console |
---|
8 | * and serial ports on a PC. |
---|
9 | */ |
---|
10 | |
---|
11 | /* |
---|
12 | * COPYRIGHT (c) 1989-2014, 2016. |
---|
13 | * On-Line Applications Research Corporation (OAR). |
---|
14 | * |
---|
15 | * Redistribution and use in source and binary forms, with or without |
---|
16 | * modification, are permitted provided that the following conditions |
---|
17 | * are met: |
---|
18 | * 1. Redistributions of source code must retain the above copyright |
---|
19 | * notice, this list of conditions and the following disclaimer. |
---|
20 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
21 | * notice, this list of conditions and the following disclaimer in the |
---|
22 | * documentation and/or other materials provided with the distribution. |
---|
23 | * |
---|
24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
28 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
34 | * POSSIBILITY OF SUCH DAMAGE. |
---|
35 | */ |
---|
36 | |
---|
37 | #include <bsp.h> |
---|
38 | #include <bsp/bspimpl.h> |
---|
39 | #include <libchip/serial.h> |
---|
40 | #include <libchip/ns16550.h> |
---|
41 | #if BSP_ENABLE_VGA |
---|
42 | #include <rtems/vgacons.h> |
---|
43 | #endif |
---|
44 | #include <bsp/irq.h> |
---|
45 | #include "../../shared/dev/serial/legacy-console.h" |
---|
46 | |
---|
47 | #if BSP_ENABLE_VGA |
---|
48 | #define VGA_CONSOLE_FUNCTIONS &vgacons_fns |
---|
49 | #endif |
---|
50 | |
---|
51 | #if BSP_ENABLE_COM1_COM4 |
---|
52 | #if 0 |
---|
53 | #define COM_CONSOLE_FUNCTIONS &ns16550_fns_polled |
---|
54 | #else |
---|
55 | #define COM_CONSOLE_FUNCTIONS &ns16550_fns |
---|
56 | #endif |
---|
57 | |
---|
58 | /* |
---|
59 | * Base IO for UART |
---|
60 | */ |
---|
61 | #define COM1_BASE_IO 0x3F8 |
---|
62 | #define COM2_BASE_IO 0x3E8 |
---|
63 | #define COM3_BASE_IO 0x2F8 |
---|
64 | #define COM4_BASE_IO 0x2E8 |
---|
65 | |
---|
66 | #define CLOCK_RATE (115200 * 16) |
---|
67 | |
---|
68 | static uint8_t com_get_register(uintptr_t addr, uint8_t i) |
---|
69 | { |
---|
70 | uint8_t val; |
---|
71 | inport_byte( (addr + i), val ); |
---|
72 | return val; |
---|
73 | } |
---|
74 | |
---|
75 | static void com_set_register(uintptr_t addr, uint8_t i, uint8_t val) |
---|
76 | { |
---|
77 | outport_byte( (addr + i), val ); |
---|
78 | } |
---|
79 | #endif |
---|
80 | |
---|
81 | /* |
---|
82 | * Default to the PC VGA console if present and configured. |
---|
83 | */ |
---|
84 | console_tbl Console_Configuration_Ports[] = { |
---|
85 | #if BSP_ENABLE_VGA |
---|
86 | /* |
---|
87 | * If present the VGA console must always be minor 0. |
---|
88 | * See console_control. |
---|
89 | */ |
---|
90 | { |
---|
91 | "/dev/vgacons", /* sDeviceName */ |
---|
92 | VGA_CONSOLE, /* deviceType */ |
---|
93 | VGA_CONSOLE_FUNCTIONS, /* pDeviceFns */ |
---|
94 | vgacons_probe, /* deviceProbe */ |
---|
95 | NULL, /* pDeviceFlow */ |
---|
96 | 16, /* ulMargin */ |
---|
97 | 8, /* ulHysteresis */ |
---|
98 | (void *) NULL, /* NULL */ /* pDeviceParams */ |
---|
99 | 0x00000000, /* ulCtrlPort1 */ |
---|
100 | 0x00000000, /* ulCtrlPort2 */ |
---|
101 | 0x00000000, /* ulDataPort */ |
---|
102 | NULL, /* getRegister */ |
---|
103 | NULL, /* setRegister */ |
---|
104 | NULL,/* unused */ /* getData */ |
---|
105 | NULL,/* unused */ /* setData */ |
---|
106 | 0x0, /* ulClock */ |
---|
107 | 0x0 /* ulIntVector -- base for port */ |
---|
108 | }, |
---|
109 | #endif |
---|
110 | }; |
---|
111 | |
---|
112 | unsigned long Console_Configuration_Count = |
---|
113 | (sizeof(Console_Configuration_Ports)/sizeof(console_tbl)); |
---|
114 | |
---|
115 | static console_tbl Legacy_Ports[] = { |
---|
116 | #if BSP_ENABLE_COM1_COM4 |
---|
117 | { |
---|
118 | "/dev/com1", /* sDeviceName */ |
---|
119 | SERIAL_NS16550, /* deviceType */ |
---|
120 | COM_CONSOLE_FUNCTIONS, /* pDeviceFns */ |
---|
121 | NULL, /* deviceProbe */ |
---|
122 | NULL, /* pDeviceFlow */ |
---|
123 | 16, /* ulMargin */ |
---|
124 | 8, /* ulHysteresis */ |
---|
125 | (void *) 9600, /* Baud Rate */ /* pDeviceParams */ |
---|
126 | COM1_BASE_IO, /* ulCtrlPort1 */ |
---|
127 | 0x00000000, /* ulCtrlPort2 */ |
---|
128 | COM1_BASE_IO, /* ulDataPort */ |
---|
129 | com_get_register, /* getRegister */ |
---|
130 | com_set_register, /* setRegister */ |
---|
131 | NULL,/* unused */ /* getData */ |
---|
132 | NULL,/* unused */ /* setData */ |
---|
133 | CLOCK_RATE, /* ulClock */ |
---|
134 | BSP_UART_COM1_IRQ /* ulIntVector -- base for port */ |
---|
135 | }, |
---|
136 | { |
---|
137 | "/dev/com2", /* sDeviceName */ |
---|
138 | SERIAL_NS16550, /* deviceType */ |
---|
139 | COM_CONSOLE_FUNCTIONS, /* pDeviceFns */ |
---|
140 | NULL, /* deviceProbe */ |
---|
141 | NULL, /* pDeviceFlow */ |
---|
142 | 16, /* ulMargin */ |
---|
143 | 8, /* ulHysteresis */ |
---|
144 | (void *) 9600, /* Baud Rate */ /* pDeviceParams */ |
---|
145 | COM2_BASE_IO, /* ulCtrlPort1 */ |
---|
146 | 0x00000000, /* ulCtrlPort2 */ |
---|
147 | COM2_BASE_IO, /* ulDataPort */ |
---|
148 | com_get_register, /* getRegister */ |
---|
149 | com_set_register, /* setRegister */ |
---|
150 | NULL,/* unused */ /* getData */ |
---|
151 | NULL,/* unused */ /* setData */ |
---|
152 | CLOCK_RATE, /* ulClock */ |
---|
153 | BSP_UART_COM2_IRQ /* ulIntVector -- base for port */ |
---|
154 | }, |
---|
155 | { |
---|
156 | "/dev/com3", /* sDeviceName */ |
---|
157 | SERIAL_NS16550, /* deviceType */ |
---|
158 | COM_CONSOLE_FUNCTIONS, /* pDeviceFns */ |
---|
159 | NULL, /* deviceProbe */ |
---|
160 | NULL, /* pDeviceFlow */ |
---|
161 | 16, /* ulMargin */ |
---|
162 | 8, /* ulHysteresis */ |
---|
163 | (void *) 9600, /* Baud Rate */ /* pDeviceParams */ |
---|
164 | COM3_BASE_IO, /* ulCtrlPort1 */ |
---|
165 | 0x00000000, /* ulCtrlPort2 */ |
---|
166 | COM3_BASE_IO, /* ulDataPort */ |
---|
167 | com_get_register, /* getRegister */ |
---|
168 | com_set_register, /* setRegister */ |
---|
169 | NULL,/* unused */ /* getData */ |
---|
170 | NULL,/* unused */ /* setData */ |
---|
171 | CLOCK_RATE, /* ulClock */ |
---|
172 | BSP_UART_COM3_IRQ /* ulIntVector -- base for port */ |
---|
173 | }, |
---|
174 | { |
---|
175 | "/dev/com4", /* sDeviceName */ |
---|
176 | SERIAL_NS16550, /* deviceType */ |
---|
177 | COM_CONSOLE_FUNCTIONS, /* pDeviceFns */ |
---|
178 | NULL, /* deviceProbe */ |
---|
179 | NULL, /* pDeviceFlow */ |
---|
180 | 16, /* ulMargin */ |
---|
181 | 8, /* ulHysteresis */ |
---|
182 | (void *) 9600, /* Baud Rate */ /* pDeviceParams */ |
---|
183 | COM4_BASE_IO, /* ulCtrlPort1 */ |
---|
184 | 0x00000000, /* ulCtrlPort2 */ |
---|
185 | COM4_BASE_IO, /* ulDataPort */ |
---|
186 | com_get_register, /* getRegister */ |
---|
187 | com_set_register, /* setRegister */ |
---|
188 | NULL,/* unused */ /* getData */ |
---|
189 | NULL,/* unused */ /* setData */ |
---|
190 | CLOCK_RATE, /* ulClock */ |
---|
191 | BSP_UART_COM4_IRQ /* ulIntVector -- base for port */ |
---|
192 | }, |
---|
193 | #endif |
---|
194 | }; |
---|
195 | |
---|
196 | #define Legacy_Port_Count \ |
---|
197 | (sizeof(Legacy_Ports)/sizeof(console_tbl)) |
---|
198 | |
---|
199 | void legacy_uart_probe(void) |
---|
200 | { |
---|
201 | #if BSP_ENABLE_COM1_COM4 |
---|
202 | const char *opt; |
---|
203 | /* |
---|
204 | * Check the command line to see if com1-com4 are disabled. |
---|
205 | */ |
---|
206 | opt = bsp_cmdline_arg("--disable-com1-com4"); |
---|
207 | if ( opt ) { |
---|
208 | printk( "COM1-COM4: disabled\n" ); |
---|
209 | } else { |
---|
210 | if (Legacy_Port_Count) { |
---|
211 | printk("Legacy UART Ports: COM1-COM4\n"); |
---|
212 | console_register_devices( Legacy_Ports, Legacy_Port_Count ); |
---|
213 | } |
---|
214 | } |
---|
215 | #endif |
---|
216 | } |
---|