Commit a52cf086ace7e6107f399fcf37059dc9e02916f3

Authored by Lokesh Vutla
Committed by Tom Rini
1 parent 46f51dc9c7

serial: omap: Support debug UART

Add debug UART functions to permit omap specific ns16550 to
provide an early debug UART. This is mostly in common with
DEBUG_UART_NS16550 except for Mode definition register which
is required for selecting UART mode(16x auto-baud or 13x mode).

Signed-off-by: Lokesh Vutla <lokeshvutla@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Tom Rini <trini@konsulko.com>

Showing 3 changed files with 54 additions and 11 deletions Inline Diff

drivers/serial/Kconfig
1 # 1 #
2 # Serial device configuration 2 # Serial device configuration
3 # 3 #
4 4
5 menu "Serial drivers" 5 menu "Serial drivers"
6 6
7 config BAUDRATE 7 config BAUDRATE
8 int "Default baudrate" 8 int "Default baudrate"
9 default 115200 9 default 115200
10 help 10 help
11 Select a default baudrate, where "default" has a driver-specific 11 Select a default baudrate, where "default" has a driver-specific
12 meaning of either setting the baudrate for the early debug UART 12 meaning of either setting the baudrate for the early debug UART
13 in the SPL stage (most drivers) or for choosing a default baudrate 13 in the SPL stage (most drivers) or for choosing a default baudrate
14 in the absence of an environment setting (serial_mxc.c). 14 in the absence of an environment setting (serial_mxc.c).
15 15
16 config REQUIRE_SERIAL_CONSOLE 16 config REQUIRE_SERIAL_CONSOLE
17 bool "Require a serial port for console" 17 bool "Require a serial port for console"
18 # Running without a serial console is not supported by the 18 # Running without a serial console is not supported by the
19 # non-dm serial code 19 # non-dm serial code
20 depends on DM_SERIAL 20 depends on DM_SERIAL
21 default y 21 default y
22 help 22 help
23 Require a serial port for the console, and panic if none is found 23 Require a serial port for the console, and panic if none is found
24 during serial port initialization (default y). Set this to n on 24 during serial port initialization (default y). Set this to n on
25 boards which have no debug serial port whatsoever. 25 boards which have no debug serial port whatsoever.
26 26
27 config SERIAL_PRESENT 27 config SERIAL_PRESENT
28 bool "Provide a serial driver" 28 bool "Provide a serial driver"
29 depends on DM_SERIAL 29 depends on DM_SERIAL
30 default y 30 default y
31 help 31 help
32 In very space-constrained devices even the full UART driver is too 32 In very space-constrained devices even the full UART driver is too
33 large. In this case the debug UART can still be used in some cases. 33 large. In this case the debug UART can still be used in some cases.
34 This option enables the full UART in U-Boot, so if is it disabled, 34 This option enables the full UART in U-Boot, so if is it disabled,
35 the full UART driver will be omitted, thus saving space. 35 the full UART driver will be omitted, thus saving space.
36 36
37 config SPL_SERIAL_PRESENT 37 config SPL_SERIAL_PRESENT
38 bool "Provide a serial driver in SPL" 38 bool "Provide a serial driver in SPL"
39 depends on DM_SERIAL 39 depends on DM_SERIAL
40 default y 40 default y
41 help 41 help
42 In very space-constrained devices even the full UART driver is too 42 In very space-constrained devices even the full UART driver is too
43 large. In this case the debug UART can still be used in some cases. 43 large. In this case the debug UART can still be used in some cases.
44 This option enables the full UART in SPL, so if is it disabled, 44 This option enables the full UART in SPL, so if is it disabled,
45 the full UART driver will be omitted, thus saving space. 45 the full UART driver will be omitted, thus saving space.
46 46
47 config CONS_INDEX 47 config CONS_INDEX
48 int "UART used for console" 48 int "UART used for console"
49 depends on ARCH_SUNXI 49 depends on ARCH_SUNXI
50 default 2 if MACH_SUN5I 50 default 2 if MACH_SUN5I
51 default 5 if MACH_SUN8I_A23 || MACH_SUN8I_A33 51 default 5 if MACH_SUN8I_A23 || MACH_SUN8I_A33
52 default 1 52 default 1
53 help 53 help
54 Configures the console index. 54 Configures the console index.
55 For Allwinner SoC., default values are 2 for SUN5I and 5 for A23/A33. 55 For Allwinner SoC., default values are 2 for SUN5I and 5 for A23/A33.
56 Otherwise, the index equals 1. 56 Otherwise, the index equals 1.
57 57
58 config DM_SERIAL 58 config DM_SERIAL
59 bool "Enable Driver Model for serial drivers" 59 bool "Enable Driver Model for serial drivers"
60 depends on DM 60 depends on DM
61 help 61 help
62 Enable driver model for serial. This replaces 62 Enable driver model for serial. This replaces
63 drivers/serial/serial.c with the serial uclass, which 63 drivers/serial/serial.c with the serial uclass, which
64 implements serial_putc() etc. The uclass interface is 64 implements serial_putc() etc. The uclass interface is
65 defined in include/serial.h. 65 defined in include/serial.h.
66 66
67 config SPL_DM_SERIAL 67 config SPL_DM_SERIAL
68 bool "Enable Driver Model for serial drivers" 68 bool "Enable Driver Model for serial drivers"
69 depends on DM_SERIAL 69 depends on DM_SERIAL
70 default y if SPL && DM_SERIAL 70 default y if SPL && DM_SERIAL
71 help 71 help
72 Enable driver model for serial in SPL. This replaces 72 Enable driver model for serial in SPL. This replaces
73 drivers/serial/serial.c with the serial uclass, which 73 drivers/serial/serial.c with the serial uclass, which
74 implements serial_putc() etc. The uclass interface is 74 implements serial_putc() etc. The uclass interface is
75 defined in include/serial.h. 75 defined in include/serial.h.
76 76
77 config TPL_DM_SERIAL 77 config TPL_DM_SERIAL
78 bool "Enable Driver Model for serial drivers" 78 bool "Enable Driver Model for serial drivers"
79 depends on DM_SERIAL 79 depends on DM_SERIAL
80 default y if TPL && DM_SERIAL 80 default y if TPL && DM_SERIAL
81 help 81 help
82 Enable driver model for serial in TPL. This replaces 82 Enable driver model for serial in TPL. This replaces
83 drivers/serial/serial.c with the serial uclass, which 83 drivers/serial/serial.c with the serial uclass, which
84 implements serial_putc() etc. The uclass interface is 84 implements serial_putc() etc. The uclass interface is
85 defined in include/serial.h. 85 defined in include/serial.h.
86 86
87 config DEBUG_UART 87 config DEBUG_UART
88 bool "Enable an early debug UART for debugging" 88 bool "Enable an early debug UART for debugging"
89 help 89 help
90 The debug UART is intended for use very early in U-Boot to debug 90 The debug UART is intended for use very early in U-Boot to debug
91 problems when an ICE or other debug mechanism is not available. 91 problems when an ICE or other debug mechanism is not available.
92 92
93 To use it you should: 93 To use it you should:
94 - Make sure your UART supports this interface 94 - Make sure your UART supports this interface
95 - Enable CONFIG_DEBUG_UART 95 - Enable CONFIG_DEBUG_UART
96 - Enable the CONFIG for your UART to tell it to provide this interface 96 - Enable the CONFIG for your UART to tell it to provide this interface
97 (e.g. CONFIG_DEBUG_UART_NS16550) 97 (e.g. CONFIG_DEBUG_UART_NS16550)
98 - Define the required settings as needed (see below) 98 - Define the required settings as needed (see below)
99 - Call debug_uart_init() before use 99 - Call debug_uart_init() before use
100 - Call debug_uart_putc() to output a character 100 - Call debug_uart_putc() to output a character
101 101
102 Depending on your platform it may be possible to use this UART before 102 Depending on your platform it may be possible to use this UART before
103 a stack is available. 103 a stack is available.
104 104
105 If your UART does not support this interface you can probably add 105 If your UART does not support this interface you can probably add
106 support quite easily. Remember that you cannot use driver model and 106 support quite easily. Remember that you cannot use driver model and
107 it is preferred to use no stack. 107 it is preferred to use no stack.
108 108
109 You must not use this UART once driver model is working and the 109 You must not use this UART once driver model is working and the
110 serial drivers are up and running (done in serial_init()). Otherwise 110 serial drivers are up and running (done in serial_init()). Otherwise
111 the drivers may conflict and you will get strange output. 111 the drivers may conflict and you will get strange output.
112 112
113 choice 113 choice
114 prompt "Select which UART will provide the debug UART" 114 prompt "Select which UART will provide the debug UART"
115 depends on DEBUG_UART 115 depends on DEBUG_UART
116 default DEBUG_UART_NS16550 116 default DEBUG_UART_NS16550
117 117
118 config DEBUG_UART_ALTERA_JTAGUART 118 config DEBUG_UART_ALTERA_JTAGUART
119 bool "Altera JTAG UART" 119 bool "Altera JTAG UART"
120 help 120 help
121 Select this to enable a debug UART using the altera_jtag_uart driver. 121 Select this to enable a debug UART using the altera_jtag_uart driver.
122 You will need to provide parameters to make this work. The driver will 122 You will need to provide parameters to make this work. The driver will
123 be available until the real driver model serial is running. 123 be available until the real driver model serial is running.
124 124
125 config DEBUG_UART_ALTERA_UART 125 config DEBUG_UART_ALTERA_UART
126 bool "Altera UART" 126 bool "Altera UART"
127 help 127 help
128 Select this to enable a debug UART using the altera_uart driver. 128 Select this to enable a debug UART using the altera_uart driver.
129 You will need to provide parameters to make this work. The driver will 129 You will need to provide parameters to make this work. The driver will
130 be available until the real driver model serial is running. 130 be available until the real driver model serial is running.
131 131
132 config DEBUG_UART_AR933X 132 config DEBUG_UART_AR933X
133 bool "QCA/Atheros ar933x" 133 bool "QCA/Atheros ar933x"
134 depends on AR933X_UART 134 depends on AR933X_UART
135 help 135 help
136 Select this to enable a debug UART using the ar933x uart driver. 136 Select this to enable a debug UART using the ar933x uart driver.
137 You will need to provide parameters to make this work. The 137 You will need to provide parameters to make this work. The
138 driver will be available until the real driver model serial is 138 driver will be available until the real driver model serial is
139 running. 139 running.
140 140
141 config DEBUG_UART_ATMEL 141 config DEBUG_UART_ATMEL
142 bool "Atmel USART" 142 bool "Atmel USART"
143 help 143 help
144 Select this to enable a debug UART using the atmel usart driver. You 144 Select this to enable a debug UART using the atmel usart driver. You
145 will need to provide parameters to make this work. The driver will 145 will need to provide parameters to make this work. The driver will
146 be available until the real driver-model serial is running. 146 be available until the real driver-model serial is running.
147 147
148 config DEBUG_UART_BCM6345 148 config DEBUG_UART_BCM6345
149 bool "BCM6345 UART" 149 bool "BCM6345 UART"
150 depends on BCM6345_SERIAL 150 depends on BCM6345_SERIAL
151 help 151 help
152 Select this to enable a debug UART on BCM6345 SoCs. You 152 Select this to enable a debug UART on BCM6345 SoCs. You
153 will need to provide parameters to make this work. The driver will 153 will need to provide parameters to make this work. The driver will
154 be available until the real driver model serial is running. 154 be available until the real driver model serial is running.
155 155
156 config DEBUG_UART_NS16550 156 config DEBUG_UART_NS16550
157 bool "ns16550" 157 bool "ns16550"
158 help 158 help
159 Select this to enable a debug UART using the ns16550 driver. You 159 Select this to enable a debug UART using the ns16550 driver. You
160 will need to provide parameters to make this work. The driver will 160 will need to provide parameters to make this work. The driver will
161 be available until the real driver model serial is running. 161 be available until the real driver model serial is running.
162 162
163 config DEBUG_EFI_CONSOLE 163 config DEBUG_EFI_CONSOLE
164 bool "EFI" 164 bool "EFI"
165 depends on EFI_APP 165 depends on EFI_APP
166 help 166 help
167 Select this to enable a debug console which calls back to EFI to 167 Select this to enable a debug console which calls back to EFI to
168 output to the console. This can be useful for early debugging of 168 output to the console. This can be useful for early debugging of
169 U-Boot when running on top of EFI (Extensive Firmware Interface). 169 U-Boot when running on top of EFI (Extensive Firmware Interface).
170 This is a type of BIOS used by PCs. 170 This is a type of BIOS used by PCs.
171 171
172 config DEBUG_UART_S5P 172 config DEBUG_UART_S5P
173 bool "Samsung S5P" 173 bool "Samsung S5P"
174 help 174 help
175 Select this to enable a debug UART using the serial_s5p driver. You 175 Select this to enable a debug UART using the serial_s5p driver. You
176 will need to provide parameters to make this work. The driver will 176 will need to provide parameters to make this work. The driver will
177 be available until the real driver-model serial is running. 177 be available until the real driver-model serial is running.
178 178
179 config DEBUG_UART_MESON 179 config DEBUG_UART_MESON
180 bool "Amlogic Meson" 180 bool "Amlogic Meson"
181 depends on MESON_SERIAL 181 depends on MESON_SERIAL
182 help 182 help
183 Select this to enable a debug UART using the serial_meson driver. You 183 Select this to enable a debug UART using the serial_meson driver. You
184 will need to provide parameters to make this work. The driver will 184 will need to provide parameters to make this work. The driver will
185 be available until the real driver-model serial is running. 185 be available until the real driver-model serial is running.
186 186
187 config DEBUG_UART_UARTLITE 187 config DEBUG_UART_UARTLITE
188 bool "Xilinx Uartlite" 188 bool "Xilinx Uartlite"
189 help 189 help
190 Select this to enable a debug UART using the serial_uartlite driver. 190 Select this to enable a debug UART using the serial_uartlite driver.
191 You will need to provide parameters to make this work. The driver will 191 You will need to provide parameters to make this work. The driver will
192 be available until the real driver-model serial is running. 192 be available until the real driver-model serial is running.
193 193
194 config DEBUG_UART_ARM_DCC 194 config DEBUG_UART_ARM_DCC
195 bool "ARM DCC" 195 bool "ARM DCC"
196 help 196 help
197 Select this to enable a debug UART using the ARM JTAG DCC port. 197 Select this to enable a debug UART using the ARM JTAG DCC port.
198 The DCC port can be used for very early debugging and doesn't require 198 The DCC port can be used for very early debugging and doesn't require
199 any additional setting like address/baudrate/clock. On systems without 199 any additional setting like address/baudrate/clock. On systems without
200 any serial interface this is the easiest way how to get console. 200 any serial interface this is the easiest way how to get console.
201 Every ARM core has own DCC port which is the part of debug interface. 201 Every ARM core has own DCC port which is the part of debug interface.
202 This port is available at least on ARMv6, ARMv7, ARMv8 and XScale 202 This port is available at least on ARMv6, ARMv7, ARMv8 and XScale
203 architectures. 203 architectures.
204 204
205 config DEBUG_MVEBU_A3700_UART 205 config DEBUG_MVEBU_A3700_UART
206 bool "Marvell Armada 3700" 206 bool "Marvell Armada 3700"
207 help 207 help
208 Select this to enable a debug UART using the serial_mvebu driver. You 208 Select this to enable a debug UART using the serial_mvebu driver. You
209 will need to provide parameters to make this work. The driver will 209 will need to provide parameters to make this work. The driver will
210 be available until the real driver-model serial is running. 210 be available until the real driver-model serial is running.
211 211
212 config DEBUG_UART_ZYNQ 212 config DEBUG_UART_ZYNQ
213 bool "Xilinx Zynq" 213 bool "Xilinx Zynq"
214 help 214 help
215 Select this to enable a debug UART using the serial_zynq driver. You 215 Select this to enable a debug UART using the serial_zynq driver. You
216 will need to provide parameters to make this work. The driver will 216 will need to provide parameters to make this work. The driver will
217 be available until the real driver-model serial is running. 217 be available until the real driver-model serial is running.
218 218
219 config DEBUG_UART_APBUART 219 config DEBUG_UART_APBUART
220 depends on LEON3 220 depends on LEON3
221 bool "Gaisler APBUART" 221 bool "Gaisler APBUART"
222 help 222 help
223 Select this to enable a debug UART using the serial_leon3 driver. You 223 Select this to enable a debug UART using the serial_leon3 driver. You
224 will need to provide parameters to make this work. The driver will 224 will need to provide parameters to make this work. The driver will
225 be available until the real driver model serial is running. 225 be available until the real driver model serial is running.
226 226
227 config DEBUG_UART_PL010 227 config DEBUG_UART_PL010
228 bool "pl010" 228 bool "pl010"
229 help 229 help
230 Select this to enable a debug UART using the pl01x driver with the 230 Select this to enable a debug UART using the pl01x driver with the
231 PL010 UART type. You will need to provide parameters to make this 231 PL010 UART type. You will need to provide parameters to make this
232 work. The driver will be available until the real driver model 232 work. The driver will be available until the real driver model
233 serial is running. 233 serial is running.
234 234
235 config DEBUG_UART_PL011 235 config DEBUG_UART_PL011
236 bool "pl011" 236 bool "pl011"
237 help 237 help
238 Select this to enable a debug UART using the pl01x driver with the 238 Select this to enable a debug UART using the pl01x driver with the
239 PL011 UART type. You will need to provide parameters to make this 239 PL011 UART type. You will need to provide parameters to make this
240 work. The driver will be available until the real driver model 240 work. The driver will be available until the real driver model
241 serial is running. 241 serial is running.
242 242
243 config DEBUG_UART_PIC32 243 config DEBUG_UART_PIC32
244 bool "Microchip PIC32" 244 bool "Microchip PIC32"
245 depends on PIC32_SERIAL 245 depends on PIC32_SERIAL
246 help 246 help
247 Select this to enable a debug UART using the serial_pic32 driver. You 247 Select this to enable a debug UART using the serial_pic32 driver. You
248 will need to provide parameters to make this work. The driver will 248 will need to provide parameters to make this work. The driver will
249 be available until the real driver model serial is running. 249 be available until the real driver model serial is running.
250 250
251 config DEBUG_UART_UNIPHIER 251 config DEBUG_UART_UNIPHIER
252 bool "UniPhier on-chip UART" 252 bool "UniPhier on-chip UART"
253 depends on ARCH_UNIPHIER 253 depends on ARCH_UNIPHIER
254 help 254 help
255 Select this to enable a debug UART using the UniPhier on-chip UART. 255 Select this to enable a debug UART using the UniPhier on-chip UART.
256 You will need to provide DEBUG_UART_BASE to make this work. The 256 You will need to provide DEBUG_UART_BASE to make this work. The
257 driver will be available until the real driver-model serial is 257 driver will be available until the real driver-model serial is
258 running. 258 running.
259 259
260 config DEBUG_UART_OMAP
261 bool "OMAP uart"
262 help
263 Select this to enable a debug UART using the omap ns16550 driver.
264 You will need to provide parameters to make this work. The driver
265 will be available until the real driver model serial is running.
266
260 endchoice 267 endchoice
261 268
262 config DEBUG_UART_BASE 269 config DEBUG_UART_BASE
263 hex "Base address of UART" 270 hex "Base address of UART"
264 depends on DEBUG_UART 271 depends on DEBUG_UART
265 help 272 help
266 This is the base address of your UART for memory-mapped UARTs. 273 This is the base address of your UART for memory-mapped UARTs.
267 274
268 A default should be provided by your board, but if not you will need 275 A default should be provided by your board, but if not you will need
269 to use the correct value here. 276 to use the correct value here.
270 277
271 config DEBUG_UART_CLOCK 278 config DEBUG_UART_CLOCK
272 int "UART input clock" 279 int "UART input clock"
273 depends on DEBUG_UART 280 depends on DEBUG_UART
274 help 281 help
275 The UART input clock determines the speed of the internal UART 282 The UART input clock determines the speed of the internal UART
276 circuitry. The baud rate is derived from this by dividing the input 283 circuitry. The baud rate is derived from this by dividing the input
277 clock down. 284 clock down.
278 285
279 A default should be provided by your board, but if not you will need 286 A default should be provided by your board, but if not you will need
280 to use the correct value here. 287 to use the correct value here.
281 288
282 config DEBUG_UART_SHIFT 289 config DEBUG_UART_SHIFT
283 int "UART register shift" 290 int "UART register shift"
284 depends on DEBUG_UART 291 depends on DEBUG_UART
285 default 0 if DEBUG_UART 292 default 0 if DEBUG_UART
286 help 293 help
287 Some UARTs (notably ns16550) support different register layouts 294 Some UARTs (notably ns16550) support different register layouts
288 where the registers are spaced either as bytes, words or some other 295 where the registers are spaced either as bytes, words or some other
289 value. Use this value to specify the shift to use, where 0=byte 296 value. Use this value to specify the shift to use, where 0=byte
290 registers, 2=32-bit word registers, etc. 297 registers, 2=32-bit word registers, etc.
291 298
292 config DEBUG_UART_BOARD_INIT 299 config DEBUG_UART_BOARD_INIT
293 bool "Enable board-specific debug UART init" 300 bool "Enable board-specific debug UART init"
294 depends on DEBUG_UART 301 depends on DEBUG_UART
295 help 302 help
296 Some boards need to set things up before the debug UART can be used. 303 Some boards need to set things up before the debug UART can be used.
297 On these boards a call to debug_uart_init() is insufficient. When 304 On these boards a call to debug_uart_init() is insufficient. When
298 this option is enabled, the function board_debug_uart_init() will 305 this option is enabled, the function board_debug_uart_init() will
299 be called when debug_uart_init() is called. You can put any code 306 be called when debug_uart_init() is called. You can put any code
300 here that is needed to set up the UART ready for use, such as set 307 here that is needed to set up the UART ready for use, such as set
301 pin multiplexing or enable clocks. 308 pin multiplexing or enable clocks.
302 309
303 config DEBUG_UART_ANNOUNCE 310 config DEBUG_UART_ANNOUNCE
304 bool "Show a message when the debug UART starts up" 311 bool "Show a message when the debug UART starts up"
305 depends on DEBUG_UART 312 depends on DEBUG_UART
306 help 313 help
307 Enable this option to show a message when the debug UART is ready 314 Enable this option to show a message when the debug UART is ready
308 for use. You will see a message like "<debug_uart> " as soon as 315 for use. You will see a message like "<debug_uart> " as soon as
309 U-Boot has the UART ready for use (i.e. your code calls 316 U-Boot has the UART ready for use (i.e. your code calls
310 debug_uart_init()). This can be useful just as a check that 317 debug_uart_init()). This can be useful just as a check that
311 everything is working. 318 everything is working.
312 319
313 config DEBUG_UART_SKIP_INIT 320 config DEBUG_UART_SKIP_INIT
314 bool "Skip UART initialization" 321 bool "Skip UART initialization"
315 help 322 help
316 Select this if the UART you want to use for debug output is already 323 Select this if the UART you want to use for debug output is already
317 initialized by the time U-Boot starts its execution. 324 initialized by the time U-Boot starts its execution.
318 325
319 config ALTERA_JTAG_UART 326 config ALTERA_JTAG_UART
320 bool "Altera JTAG UART support" 327 bool "Altera JTAG UART support"
321 depends on DM_SERIAL 328 depends on DM_SERIAL
322 help 329 help
323 Select this to enable an JTAG UART for Altera devices.The JTAG UART 330 Select this to enable an JTAG UART for Altera devices.The JTAG UART
324 core implements a method to communicate serial character streams 331 core implements a method to communicate serial character streams
325 between a host PC and a Qsys system on an Altera FPGA. Please find 332 between a host PC and a Qsys system on an Altera FPGA. Please find
326 details on the "Embedded Peripherals IP User Guide" of Altera. 333 details on the "Embedded Peripherals IP User Guide" of Altera.
327 334
328 config ALTERA_JTAG_UART_BYPASS 335 config ALTERA_JTAG_UART_BYPASS
329 bool "Bypass output when no connection" 336 bool "Bypass output when no connection"
330 depends on ALTERA_JTAG_UART 337 depends on ALTERA_JTAG_UART
331 help 338 help
332 Bypass console output and keep going even if there is no JTAG 339 Bypass console output and keep going even if there is no JTAG
333 terminal connection with the host. The console output will resume 340 terminal connection with the host. The console output will resume
334 once the JTAG terminal is connected. Without the bypass, the console 341 once the JTAG terminal is connected. Without the bypass, the console
335 output will wait forever until a JTAG terminal is connected. If you 342 output will wait forever until a JTAG terminal is connected. If you
336 not are sure, say Y. 343 not are sure, say Y.
337 344
338 config ALTERA_UART 345 config ALTERA_UART
339 bool "Altera UART support" 346 bool "Altera UART support"
340 depends on DM_SERIAL 347 depends on DM_SERIAL
341 help 348 help
342 Select this to enable an UART for Altera devices. Please find 349 Select this to enable an UART for Altera devices. Please find
343 details on the "Embedded Peripherals IP User Guide" of Altera. 350 details on the "Embedded Peripherals IP User Guide" of Altera.
344 351
345 config AR933X_UART 352 config AR933X_UART
346 bool "QCA/Atheros ar933x UART support" 353 bool "QCA/Atheros ar933x UART support"
347 depends on DM_SERIAL && SOC_AR933X 354 depends on DM_SERIAL && SOC_AR933X
348 help 355 help
349 Select this to enable UART support for QCA/Atheros ar933x 356 Select this to enable UART support for QCA/Atheros ar933x
350 devices. This driver uses driver model and requires a device 357 devices. This driver uses driver model and requires a device
351 tree binding to operate, please refer to the document at 358 tree binding to operate, please refer to the document at
352 doc/device-tree-bindings/serial/qca,ar9330-uart.txt. 359 doc/device-tree-bindings/serial/qca,ar9330-uart.txt.
353 360
354 config ATMEL_USART 361 config ATMEL_USART
355 bool "Atmel USART support" 362 bool "Atmel USART support"
356 help 363 help
357 Select this to enable USART support for Atmel SoCs. It can be 364 Select this to enable USART support for Atmel SoCs. It can be
358 configured in the device tree, and input clock frequency can 365 configured in the device tree, and input clock frequency can
359 be got from the clk node. 366 be got from the clk node.
360 367
361 config BCM6345_SERIAL 368 config BCM6345_SERIAL
362 bool "Support for BCM6345 UART" 369 bool "Support for BCM6345 UART"
363 depends on DM_SERIAL && ARCH_BMIPS 370 depends on DM_SERIAL && ARCH_BMIPS
364 help 371 help
365 Select this to enable UART on BCM6345 SoCs. 372 Select this to enable UART on BCM6345 SoCs.
366 373
367 config FSL_LPUART 374 config FSL_LPUART
368 bool "Freescale LPUART support" 375 bool "Freescale LPUART support"
369 help 376 help
370 Select this to enable a Low Power UART for Freescale VF610 and 377 Select this to enable a Low Power UART for Freescale VF610 and
371 QorIQ Layerscape devices. 378 QorIQ Layerscape devices.
372 379
373 config MVEBU_A3700_UART 380 config MVEBU_A3700_UART
374 bool "UART support for Armada 3700" 381 bool "UART support for Armada 3700"
375 default n 382 default n
376 help 383 help
377 Choose this option to add support for UART driver on the Marvell 384 Choose this option to add support for UART driver on the Marvell
378 Armada 3700 SoC. The base address is configured via DT. 385 Armada 3700 SoC. The base address is configured via DT.
379 386
380 config MXC_UART 387 config MXC_UART
381 bool "IMX serial port support" 388 bool "IMX serial port support"
382 depends on MX5 || MX6 389 depends on MX5 || MX6
383 help 390 help
384 If you have a machine based on a Motorola IMX CPU you 391 If you have a machine based on a Motorola IMX CPU you
385 can enable its onboard serial port by enabling this option. 392 can enable its onboard serial port by enabling this option.
386 393
387 config PIC32_SERIAL 394 config PIC32_SERIAL
388 bool "Support for Microchip PIC32 on-chip UART" 395 bool "Support for Microchip PIC32 on-chip UART"
389 depends on DM_SERIAL && MACH_PIC32 396 depends on DM_SERIAL && MACH_PIC32
390 default y 397 default y
391 help 398 help
392 Support for the UART found on Microchip PIC32 SoC's. 399 Support for the UART found on Microchip PIC32 SoC's.
393 400
394 config SYS_NS16550 401 config SYS_NS16550
395 bool "NS16550 UART or compatible" 402 bool "NS16550 UART or compatible"
396 help 403 help
397 Support NS16550 UART or compatible. This can be enabled in the 404 Support NS16550 UART or compatible. This can be enabled in the
398 device tree with the correct input clock frequency. If the input 405 device tree with the correct input clock frequency. If the input
399 clock frequency is not defined in the device tree, the macro 406 clock frequency is not defined in the device tree, the macro
400 CONFIG_SYS_NS16550_CLK defined in a legacy board header file will 407 CONFIG_SYS_NS16550_CLK defined in a legacy board header file will
401 be used. It can be a constant or a function to get clock, eg, 408 be used. It can be a constant or a function to get clock, eg,
402 get_serial_clock(). 409 get_serial_clock().
403 410
404 config INTEL_MID_SERIAL 411 config INTEL_MID_SERIAL
405 bool "Intel MID platform UART support" 412 bool "Intel MID platform UART support"
406 depends on DM_SERIAL && OF_CONTROL 413 depends on DM_SERIAL && OF_CONTROL
407 depends on INTEL_MID 414 depends on INTEL_MID
408 select SYS_NS16550 415 select SYS_NS16550
409 help 416 help
410 Select this to enable a UART for Intel MID platforms. 417 Select this to enable a UART for Intel MID platforms.
411 This uses the ns16550 driver as a library. 418 This uses the ns16550 driver as a library.
412 419
413 config ROCKCHIP_SERIAL 420 config ROCKCHIP_SERIAL
414 bool "Rockchip on-chip UART support" 421 bool "Rockchip on-chip UART support"
415 depends on DM_SERIAL && SPL_OF_PLATDATA 422 depends on DM_SERIAL && SPL_OF_PLATDATA
416 help 423 help
417 Select this to enable a debug UART for Rockchip devices when using 424 Select this to enable a debug UART for Rockchip devices when using
418 CONFIG_SPL_OF_PLATDATA (i.e. a compiled-in device tree replacemenmt). 425 CONFIG_SPL_OF_PLATDATA (i.e. a compiled-in device tree replacemenmt).
419 This uses the ns16550 driver, converting the platdata from of-platdata 426 This uses the ns16550 driver, converting the platdata from of-platdata
420 to the ns16550 format. 427 to the ns16550 format.
421 428
422 config SANDBOX_SERIAL 429 config SANDBOX_SERIAL
423 bool "Sandbox UART support" 430 bool "Sandbox UART support"
424 depends on SANDBOX 431 depends on SANDBOX
425 help 432 help
426 Select this to enable a seral UART for sandbox. This is required to 433 Select this to enable a seral UART for sandbox. This is required to
427 operate correctly, otherwise you will see no serial output from 434 operate correctly, otherwise you will see no serial output from
428 sandbox. The emulated UART will display to the console and console 435 sandbox. The emulated UART will display to the console and console
429 input will be fed into the UART. This allows you to interact with 436 input will be fed into the UART. This allows you to interact with
430 U-Boot. 437 U-Boot.
431 438
432 The operation of the console is controlled by the -t command-line 439 The operation of the console is controlled by the -t command-line
433 flag. In raw mode, U-Boot sees all characters from the terminal 440 flag. In raw mode, U-Boot sees all characters from the terminal
434 before they are processed, including Ctrl-C. In cooked mode, Ctrl-C 441 before they are processed, including Ctrl-C. In cooked mode, Ctrl-C
435 is processed by the terminal, and terminates U-Boot. Valid options 442 is processed by the terminal, and terminates U-Boot. Valid options
436 are: 443 are:
437 444
438 -t raw-with-sigs Raw mode, Ctrl-C will terminate U-Boot 445 -t raw-with-sigs Raw mode, Ctrl-C will terminate U-Boot
439 -t raw Raw mode, Ctrl-C is processed by U-Boot 446 -t raw Raw mode, Ctrl-C is processed by U-Boot
440 -t cooked Cooked mode, Ctrl-C terminates 447 -t cooked Cooked mode, Ctrl-C terminates
441 448
442 config UNIPHIER_SERIAL 449 config UNIPHIER_SERIAL
443 bool "Support for UniPhier on-chip UART" 450 bool "Support for UniPhier on-chip UART"
444 depends on ARCH_UNIPHIER 451 depends on ARCH_UNIPHIER
445 default y 452 default y
446 help 453 help
447 If you have a UniPhier based board and want to use the on-chip 454 If you have a UniPhier based board and want to use the on-chip
448 serial ports, say Y to this option. If unsure, say N. 455 serial ports, say Y to this option. If unsure, say N.
449 456
450 config XILINX_UARTLITE 457 config XILINX_UARTLITE
451 bool "Xilinx Uarlite support" 458 bool "Xilinx Uarlite support"
452 depends on DM_SERIAL && (MICROBLAZE || ARCH_ZYNQ || ARCH_ZYNQMP || 4xx) 459 depends on DM_SERIAL && (MICROBLAZE || ARCH_ZYNQ || ARCH_ZYNQMP || 4xx)
453 help 460 help
454 If you have a Xilinx based board and want to use the uartlite 461 If you have a Xilinx based board and want to use the uartlite
455 serial ports, say Y to this option. If unsure, say N. 462 serial ports, say Y to this option. If unsure, say N.
456 463
457 config MESON_SERIAL 464 config MESON_SERIAL
458 bool "Support for Amlogic Meson UART" 465 bool "Support for Amlogic Meson UART"
459 depends on DM_SERIAL && ARCH_MESON 466 depends on DM_SERIAL && ARCH_MESON
460 help 467 help
461 If you have an Amlogic Meson based board and want to use the on-chip 468 If you have an Amlogic Meson based board and want to use the on-chip
462 serial ports, say Y to this option. If unsure, say N. 469 serial ports, say Y to this option. If unsure, say N.
463 470
464 config MSM_SERIAL 471 config MSM_SERIAL
465 bool "Qualcomm on-chip UART" 472 bool "Qualcomm on-chip UART"
466 depends on DM_SERIAL 473 depends on DM_SERIAL
467 help 474 help
468 Support Data Mover UART used on Qualcomm Snapdragon SoCs. 475 Support Data Mover UART used on Qualcomm Snapdragon SoCs.
469 It should support all Qualcomm devices with UARTDM version 1.4, 476 It should support all Qualcomm devices with UARTDM version 1.4,
470 for example APQ8016 and MSM8916. 477 for example APQ8016 and MSM8916.
471 Single baudrate is supported in current implementation (115200). 478 Single baudrate is supported in current implementation (115200).
472 479
473 config PXA_SERIAL 480 config PXA_SERIAL
474 bool "PXA serial port support" 481 bool "PXA serial port support"
475 help 482 help
476 If you have a machine based on a Marvell XScale PXA2xx CPU you 483 If you have a machine based on a Marvell XScale PXA2xx CPU you
477 can enable its onboard serial ports by enabling this option. 484 can enable its onboard serial ports by enabling this option.
478 485
479 config STI_ASC_SERIAL 486 config STI_ASC_SERIAL
480 bool "STMicroelectronics on-chip UART" 487 bool "STMicroelectronics on-chip UART"
481 depends on DM_SERIAL && ARCH_STI 488 depends on DM_SERIAL && ARCH_STI
482 help 489 help
483 Select this to enable Asynchronous Serial Controller available 490 Select this to enable Asynchronous Serial Controller available
484 on STiH410 SoC. This is a basic implementation, it supports 491 on STiH410 SoC. This is a basic implementation, it supports
485 following baudrate 9600, 19200, 38400, 57600 and 115200. 492 following baudrate 9600, 19200, 38400, 57600 and 115200.
486 493
487 endmenu 494 endmenu
488 495
drivers/serial/ns16550.c
1 /* 1 /*
2 * COM1 NS16550 support 2 * COM1 NS16550 support
3 * originally from linux source (arch/powerpc/boot/ns16550.c) 3 * originally from linux source (arch/powerpc/boot/ns16550.c)
4 * modified to use CONFIG_SYS_ISA_MEM and new defines 4 * modified to use CONFIG_SYS_ISA_MEM and new defines
5 */ 5 */
6 6
7 #include <common.h> 7 #include <common.h>
8 #include <clk.h> 8 #include <clk.h>
9 #include <dm.h> 9 #include <dm.h>
10 #include <errno.h> 10 #include <errno.h>
11 #include <fdtdec.h> 11 #include <fdtdec.h>
12 #include <ns16550.h> 12 #include <ns16550.h>
13 #include <serial.h> 13 #include <serial.h>
14 #include <watchdog.h> 14 #include <watchdog.h>
15 #include <linux/types.h> 15 #include <linux/types.h>
16 #include <asm/io.h> 16 #include <asm/io.h>
17 17
18 DECLARE_GLOBAL_DATA_PTR; 18 DECLARE_GLOBAL_DATA_PTR;
19 19
20 #define UART_LCRVAL UART_LCR_8N1 /* 8 data, 1 stop, no parity */ 20 #define UART_LCRVAL UART_LCR_8N1 /* 8 data, 1 stop, no parity */
21 #define UART_MCRVAL (UART_MCR_DTR | \ 21 #define UART_MCRVAL (UART_MCR_DTR | \
22 UART_MCR_RTS) /* RTS/DTR */ 22 UART_MCR_RTS) /* RTS/DTR */
23 23
24 #ifndef CONFIG_DM_SERIAL 24 #ifndef CONFIG_DM_SERIAL
25 #ifdef CONFIG_SYS_NS16550_PORT_MAPPED 25 #ifdef CONFIG_SYS_NS16550_PORT_MAPPED
26 #define serial_out(x, y) outb(x, (ulong)y) 26 #define serial_out(x, y) outb(x, (ulong)y)
27 #define serial_in(y) inb((ulong)y) 27 #define serial_in(y) inb((ulong)y)
28 #elif defined(CONFIG_SYS_NS16550_MEM32) && (CONFIG_SYS_NS16550_REG_SIZE > 0) 28 #elif defined(CONFIG_SYS_NS16550_MEM32) && (CONFIG_SYS_NS16550_REG_SIZE > 0)
29 #define serial_out(x, y) out_be32(y, x) 29 #define serial_out(x, y) out_be32(y, x)
30 #define serial_in(y) in_be32(y) 30 #define serial_in(y) in_be32(y)
31 #elif defined(CONFIG_SYS_NS16550_MEM32) && (CONFIG_SYS_NS16550_REG_SIZE < 0) 31 #elif defined(CONFIG_SYS_NS16550_MEM32) && (CONFIG_SYS_NS16550_REG_SIZE < 0)
32 #define serial_out(x, y) out_le32(y, x) 32 #define serial_out(x, y) out_le32(y, x)
33 #define serial_in(y) in_le32(y) 33 #define serial_in(y) in_le32(y)
34 #else 34 #else
35 #define serial_out(x, y) writeb(x, y) 35 #define serial_out(x, y) writeb(x, y)
36 #define serial_in(y) readb(y) 36 #define serial_in(y) readb(y)
37 #endif 37 #endif
38 #endif /* !CONFIG_DM_SERIAL */ 38 #endif /* !CONFIG_DM_SERIAL */
39 39
40 #if defined(CONFIG_SOC_KEYSTONE) 40 #if defined(CONFIG_SOC_KEYSTONE)
41 #define UART_REG_VAL_PWREMU_MGMT_UART_DISABLE 0 41 #define UART_REG_VAL_PWREMU_MGMT_UART_DISABLE 0
42 #define UART_REG_VAL_PWREMU_MGMT_UART_ENABLE ((1 << 14) | (1 << 13) | (1 << 0)) 42 #define UART_REG_VAL_PWREMU_MGMT_UART_ENABLE ((1 << 14) | (1 << 13) | (1 << 0))
43 #undef UART_MCRVAL 43 #undef UART_MCRVAL
44 #ifdef CONFIG_SERIAL_HW_FLOW_CONTROL 44 #ifdef CONFIG_SERIAL_HW_FLOW_CONTROL
45 #define UART_MCRVAL (UART_MCR_RTS | UART_MCR_AFE) 45 #define UART_MCRVAL (UART_MCR_RTS | UART_MCR_AFE)
46 #else 46 #else
47 #define UART_MCRVAL (UART_MCR_RTS) 47 #define UART_MCRVAL (UART_MCR_RTS)
48 #endif 48 #endif
49 #endif 49 #endif
50 50
51 #ifndef CONFIG_SYS_NS16550_IER 51 #ifndef CONFIG_SYS_NS16550_IER
52 #define CONFIG_SYS_NS16550_IER 0x00 52 #define CONFIG_SYS_NS16550_IER 0x00
53 #endif /* CONFIG_SYS_NS16550_IER */ 53 #endif /* CONFIG_SYS_NS16550_IER */
54 54
55 static inline void serial_out_shift(void *addr, int shift, int value) 55 static inline void serial_out_shift(void *addr, int shift, int value)
56 { 56 {
57 #ifdef CONFIG_SYS_NS16550_PORT_MAPPED 57 #ifdef CONFIG_SYS_NS16550_PORT_MAPPED
58 outb(value, (ulong)addr); 58 outb(value, (ulong)addr);
59 #elif defined(CONFIG_SYS_NS16550_MEM32) && !defined(CONFIG_SYS_BIG_ENDIAN) 59 #elif defined(CONFIG_SYS_NS16550_MEM32) && !defined(CONFIG_SYS_BIG_ENDIAN)
60 out_le32(addr, value); 60 out_le32(addr, value);
61 #elif defined(CONFIG_SYS_NS16550_MEM32) && defined(CONFIG_SYS_BIG_ENDIAN) 61 #elif defined(CONFIG_SYS_NS16550_MEM32) && defined(CONFIG_SYS_BIG_ENDIAN)
62 out_be32(addr, value); 62 out_be32(addr, value);
63 #elif defined(CONFIG_SYS_NS16550_MEM32) 63 #elif defined(CONFIG_SYS_NS16550_MEM32)
64 writel(value, addr); 64 writel(value, addr);
65 #elif defined(CONFIG_SYS_BIG_ENDIAN) 65 #elif defined(CONFIG_SYS_BIG_ENDIAN)
66 writeb(value, addr + (1 << shift) - 1); 66 writeb(value, addr + (1 << shift) - 1);
67 #else 67 #else
68 writeb(value, addr); 68 writeb(value, addr);
69 #endif 69 #endif
70 } 70 }
71 71
72 static inline int serial_in_shift(void *addr, int shift) 72 static inline int serial_in_shift(void *addr, int shift)
73 { 73 {
74 #ifdef CONFIG_SYS_NS16550_PORT_MAPPED 74 #ifdef CONFIG_SYS_NS16550_PORT_MAPPED
75 return inb((ulong)addr); 75 return inb((ulong)addr);
76 #elif defined(CONFIG_SYS_NS16550_MEM32) && !defined(CONFIG_SYS_BIG_ENDIAN) 76 #elif defined(CONFIG_SYS_NS16550_MEM32) && !defined(CONFIG_SYS_BIG_ENDIAN)
77 return in_le32(addr); 77 return in_le32(addr);
78 #elif defined(CONFIG_SYS_NS16550_MEM32) && defined(CONFIG_SYS_BIG_ENDIAN) 78 #elif defined(CONFIG_SYS_NS16550_MEM32) && defined(CONFIG_SYS_BIG_ENDIAN)
79 return in_be32(addr); 79 return in_be32(addr);
80 #elif defined(CONFIG_SYS_NS16550_MEM32) 80 #elif defined(CONFIG_SYS_NS16550_MEM32)
81 return readl(addr); 81 return readl(addr);
82 #elif defined(CONFIG_SYS_BIG_ENDIAN) 82 #elif defined(CONFIG_SYS_BIG_ENDIAN)
83 return readb(addr + (1 << shift) - 1); 83 return readb(addr + (1 << shift) - 1);
84 #else 84 #else
85 return readb(addr); 85 return readb(addr);
86 #endif 86 #endif
87 } 87 }
88 88
89 #ifdef CONFIG_DM_SERIAL 89 #ifdef CONFIG_DM_SERIAL
90 90
91 #ifndef CONFIG_SYS_NS16550_CLK 91 #ifndef CONFIG_SYS_NS16550_CLK
92 #define CONFIG_SYS_NS16550_CLK 0 92 #define CONFIG_SYS_NS16550_CLK 0
93 #endif 93 #endif
94 94
95 static void ns16550_writeb(NS16550_t port, int offset, int value) 95 static void ns16550_writeb(NS16550_t port, int offset, int value)
96 { 96 {
97 struct ns16550_platdata *plat = port->plat; 97 struct ns16550_platdata *plat = port->plat;
98 unsigned char *addr; 98 unsigned char *addr;
99 99
100 offset *= 1 << plat->reg_shift; 100 offset *= 1 << plat->reg_shift;
101 addr = (unsigned char *)plat->base + offset; 101 addr = (unsigned char *)plat->base + offset;
102 102
103 /* 103 /*
104 * As far as we know it doesn't make sense to support selection of 104 * As far as we know it doesn't make sense to support selection of
105 * these options at run-time, so use the existing CONFIG options. 105 * these options at run-time, so use the existing CONFIG options.
106 */ 106 */
107 serial_out_shift(addr + plat->reg_offset, plat->reg_shift, value); 107 serial_out_shift(addr + plat->reg_offset, plat->reg_shift, value);
108 } 108 }
109 109
110 static int ns16550_readb(NS16550_t port, int offset) 110 static int ns16550_readb(NS16550_t port, int offset)
111 { 111 {
112 struct ns16550_platdata *plat = port->plat; 112 struct ns16550_platdata *plat = port->plat;
113 unsigned char *addr; 113 unsigned char *addr;
114 114
115 offset *= 1 << plat->reg_shift; 115 offset *= 1 << plat->reg_shift;
116 addr = (unsigned char *)plat->base + offset; 116 addr = (unsigned char *)plat->base + offset;
117 117
118 return serial_in_shift(addr + plat->reg_offset, plat->reg_shift); 118 return serial_in_shift(addr + plat->reg_offset, plat->reg_shift);
119 } 119 }
120 120
121 static u32 ns16550_getfcr(NS16550_t port) 121 static u32 ns16550_getfcr(NS16550_t port)
122 { 122 {
123 struct ns16550_platdata *plat = port->plat; 123 struct ns16550_platdata *plat = port->plat;
124 124
125 return plat->fcr; 125 return plat->fcr;
126 } 126 }
127 127
128 /* We can clean these up once everything is moved to driver model */ 128 /* We can clean these up once everything is moved to driver model */
129 #define serial_out(value, addr) \ 129 #define serial_out(value, addr) \
130 ns16550_writeb(com_port, \ 130 ns16550_writeb(com_port, \
131 (unsigned char *)addr - (unsigned char *)com_port, value) 131 (unsigned char *)addr - (unsigned char *)com_port, value)
132 #define serial_in(addr) \ 132 #define serial_in(addr) \
133 ns16550_readb(com_port, \ 133 ns16550_readb(com_port, \
134 (unsigned char *)addr - (unsigned char *)com_port) 134 (unsigned char *)addr - (unsigned char *)com_port)
135 #else 135 #else
136 static u32 ns16550_getfcr(NS16550_t port) 136 static u32 ns16550_getfcr(NS16550_t port)
137 { 137 {
138 return UART_FCR_DEFVAL; 138 return UART_FCR_DEFVAL;
139 } 139 }
140 #endif 140 #endif
141 141
142 int ns16550_calc_divisor(NS16550_t port, int clock, int baudrate) 142 int ns16550_calc_divisor(NS16550_t port, int clock, int baudrate)
143 { 143 {
144 const unsigned int mode_x_div = 16; 144 const unsigned int mode_x_div = 16;
145 145
146 return DIV_ROUND_CLOSEST(clock, mode_x_div * baudrate); 146 return DIV_ROUND_CLOSEST(clock, mode_x_div * baudrate);
147 } 147 }
148 148
149 static void NS16550_setbrg(NS16550_t com_port, int baud_divisor) 149 static void NS16550_setbrg(NS16550_t com_port, int baud_divisor)
150 { 150 {
151 serial_out(UART_LCR_BKSE | UART_LCRVAL, &com_port->lcr); 151 serial_out(UART_LCR_BKSE | UART_LCRVAL, &com_port->lcr);
152 serial_out(baud_divisor & 0xff, &com_port->dll); 152 serial_out(baud_divisor & 0xff, &com_port->dll);
153 serial_out((baud_divisor >> 8) & 0xff, &com_port->dlm); 153 serial_out((baud_divisor >> 8) & 0xff, &com_port->dlm);
154 serial_out(UART_LCRVAL, &com_port->lcr); 154 serial_out(UART_LCRVAL, &com_port->lcr);
155 } 155 }
156 156
157 void NS16550_init(NS16550_t com_port, int baud_divisor) 157 void NS16550_init(NS16550_t com_port, int baud_divisor)
158 { 158 {
159 #if (defined(CONFIG_SPL_BUILD) && \ 159 #if (defined(CONFIG_SPL_BUILD) && \
160 (defined(CONFIG_OMAP34XX) || defined(CONFIG_OMAP44XX))) 160 (defined(CONFIG_OMAP34XX) || defined(CONFIG_OMAP44XX)))
161 /* 161 /*
162 * On some OMAP3/OMAP4 devices when UART3 is configured for boot mode 162 * On some OMAP3/OMAP4 devices when UART3 is configured for boot mode
163 * before SPL starts only THRE bit is set. We have to empty the 163 * before SPL starts only THRE bit is set. We have to empty the
164 * transmitter before initialization starts. 164 * transmitter before initialization starts.
165 */ 165 */
166 if ((serial_in(&com_port->lsr) & (UART_LSR_TEMT | UART_LSR_THRE)) 166 if ((serial_in(&com_port->lsr) & (UART_LSR_TEMT | UART_LSR_THRE))
167 == UART_LSR_THRE) { 167 == UART_LSR_THRE) {
168 if (baud_divisor != -1) 168 if (baud_divisor != -1)
169 NS16550_setbrg(com_port, baud_divisor); 169 NS16550_setbrg(com_port, baud_divisor);
170 serial_out(0, &com_port->mdr1); 170 serial_out(0, &com_port->mdr1);
171 } 171 }
172 #endif 172 #endif
173 173
174 while (!(serial_in(&com_port->lsr) & UART_LSR_TEMT)) 174 while (!(serial_in(&com_port->lsr) & UART_LSR_TEMT))
175 ; 175 ;
176 176
177 serial_out(CONFIG_SYS_NS16550_IER, &com_port->ier); 177 serial_out(CONFIG_SYS_NS16550_IER, &com_port->ier);
178 #if defined(CONFIG_OMAP) || defined(CONFIG_AM33XX) || \ 178 #if defined(CONFIG_OMAP) || defined(CONFIG_AM33XX) || \
179 defined(CONFIG_TI81XX) || defined(CONFIG_AM43XX) 179 defined(CONFIG_TI81XX) || defined(CONFIG_AM43XX)
180 serial_out(0x7, &com_port->mdr1); /* mode select reset TL16C750*/ 180 serial_out(0x7, &com_port->mdr1); /* mode select reset TL16C750*/
181 #endif 181 #endif
182 serial_out(UART_MCRVAL, &com_port->mcr); 182 serial_out(UART_MCRVAL, &com_port->mcr);
183 serial_out(ns16550_getfcr(com_port), &com_port->fcr); 183 serial_out(ns16550_getfcr(com_port), &com_port->fcr);
184 if (baud_divisor != -1) 184 if (baud_divisor != -1)
185 NS16550_setbrg(com_port, baud_divisor); 185 NS16550_setbrg(com_port, baud_divisor);
186 #if defined(CONFIG_OMAP) || \ 186 #if defined(CONFIG_OMAP) || \
187 defined(CONFIG_AM33XX) || defined(CONFIG_SOC_DA8XX) || \ 187 defined(CONFIG_AM33XX) || defined(CONFIG_SOC_DA8XX) || \
188 defined(CONFIG_TI81XX) || defined(CONFIG_AM43XX) 188 defined(CONFIG_TI81XX) || defined(CONFIG_AM43XX)
189 189
190 /* /16 is proper to hit 115200 with 48MHz */ 190 /* /16 is proper to hit 115200 with 48MHz */
191 serial_out(0, &com_port->mdr1); 191 serial_out(0, &com_port->mdr1);
192 #endif /* CONFIG_OMAP */ 192 #endif /* CONFIG_OMAP */
193 #if defined(CONFIG_SOC_KEYSTONE) 193 #if defined(CONFIG_SOC_KEYSTONE)
194 serial_out(UART_REG_VAL_PWREMU_MGMT_UART_ENABLE, &com_port->regC); 194 serial_out(UART_REG_VAL_PWREMU_MGMT_UART_ENABLE, &com_port->regC);
195 #endif 195 #endif
196 } 196 }
197 197
198 #ifndef CONFIG_NS16550_MIN_FUNCTIONS 198 #ifndef CONFIG_NS16550_MIN_FUNCTIONS
199 void NS16550_reinit(NS16550_t com_port, int baud_divisor) 199 void NS16550_reinit(NS16550_t com_port, int baud_divisor)
200 { 200 {
201 serial_out(CONFIG_SYS_NS16550_IER, &com_port->ier); 201 serial_out(CONFIG_SYS_NS16550_IER, &com_port->ier);
202 NS16550_setbrg(com_port, 0); 202 NS16550_setbrg(com_port, 0);
203 serial_out(UART_MCRVAL, &com_port->mcr); 203 serial_out(UART_MCRVAL, &com_port->mcr);
204 serial_out(ns16550_getfcr(com_port), &com_port->fcr); 204 serial_out(ns16550_getfcr(com_port), &com_port->fcr);
205 NS16550_setbrg(com_port, baud_divisor); 205 NS16550_setbrg(com_port, baud_divisor);
206 } 206 }
207 #endif /* CONFIG_NS16550_MIN_FUNCTIONS */ 207 #endif /* CONFIG_NS16550_MIN_FUNCTIONS */
208 208
209 void NS16550_putc(NS16550_t com_port, char c) 209 void NS16550_putc(NS16550_t com_port, char c)
210 { 210 {
211 while ((serial_in(&com_port->lsr) & UART_LSR_THRE) == 0) 211 while ((serial_in(&com_port->lsr) & UART_LSR_THRE) == 0)
212 ; 212 ;
213 serial_out(c, &com_port->thr); 213 serial_out(c, &com_port->thr);
214 214
215 /* 215 /*
216 * Call watchdog_reset() upon newline. This is done here in putc 216 * Call watchdog_reset() upon newline. This is done here in putc
217 * since the environment code uses a single puts() to print the complete 217 * since the environment code uses a single puts() to print the complete
218 * environment upon "printenv". So we can't put this watchdog call 218 * environment upon "printenv". So we can't put this watchdog call
219 * in puts(). 219 * in puts().
220 */ 220 */
221 if (c == '\n') 221 if (c == '\n')
222 WATCHDOG_RESET(); 222 WATCHDOG_RESET();
223 } 223 }
224 224
225 #ifndef CONFIG_NS16550_MIN_FUNCTIONS 225 #ifndef CONFIG_NS16550_MIN_FUNCTIONS
226 char NS16550_getc(NS16550_t com_port) 226 char NS16550_getc(NS16550_t com_port)
227 { 227 {
228 while ((serial_in(&com_port->lsr) & UART_LSR_DR) == 0) { 228 while ((serial_in(&com_port->lsr) & UART_LSR_DR) == 0) {
229 #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_USB_TTY) 229 #if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_USB_TTY)
230 extern void usbtty_poll(void); 230 extern void usbtty_poll(void);
231 usbtty_poll(); 231 usbtty_poll();
232 #endif 232 #endif
233 WATCHDOG_RESET(); 233 WATCHDOG_RESET();
234 } 234 }
235 return serial_in(&com_port->rbr); 235 return serial_in(&com_port->rbr);
236 } 236 }
237 237
238 int NS16550_tstc(NS16550_t com_port) 238 int NS16550_tstc(NS16550_t com_port)
239 { 239 {
240 return (serial_in(&com_port->lsr) & UART_LSR_DR) != 0; 240 return (serial_in(&com_port->lsr) & UART_LSR_DR) != 0;
241 } 241 }
242 242
243 #endif /* CONFIG_NS16550_MIN_FUNCTIONS */ 243 #endif /* CONFIG_NS16550_MIN_FUNCTIONS */
244 244
245 #ifdef CONFIG_DEBUG_UART_NS16550 245 #ifdef CONFIG_DEBUG_UART_NS16550
246 246
247 #include <debug_uart.h> 247 #include <debug_uart.h>
248 248
249 #define serial_dout(reg, value) \
250 serial_out_shift((char *)com_port + \
251 ((char *)reg - (char *)com_port) * \
252 (1 << CONFIG_DEBUG_UART_SHIFT), \
253 CONFIG_DEBUG_UART_SHIFT, value)
254 #define serial_din(reg) \
255 serial_in_shift((char *)com_port + \
256 ((char *)reg - (char *)com_port) * \
257 (1 << CONFIG_DEBUG_UART_SHIFT), \
258 CONFIG_DEBUG_UART_SHIFT)
259
260 static inline void _debug_uart_init(void) 249 static inline void _debug_uart_init(void)
261 { 250 {
262 struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE; 251 struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
263 int baud_divisor; 252 int baud_divisor;
264 253
265 /* 254 /*
266 * We copy the code from above because it is already horribly messy. 255 * We copy the code from above because it is already horribly messy.
267 * Trying to refactor to nicely remove the duplication doesn't seem 256 * Trying to refactor to nicely remove the duplication doesn't seem
268 * feasible. The better fix is to move all users of this driver to 257 * feasible. The better fix is to move all users of this driver to
269 * driver model. 258 * driver model.
270 */ 259 */
271 baud_divisor = ns16550_calc_divisor(com_port, CONFIG_DEBUG_UART_CLOCK, 260 baud_divisor = ns16550_calc_divisor(com_port, CONFIG_DEBUG_UART_CLOCK,
272 CONFIG_BAUDRATE); 261 CONFIG_BAUDRATE);
273 serial_dout(&com_port->ier, CONFIG_SYS_NS16550_IER); 262 serial_dout(&com_port->ier, CONFIG_SYS_NS16550_IER);
274 serial_dout(&com_port->mcr, UART_MCRVAL); 263 serial_dout(&com_port->mcr, UART_MCRVAL);
275 serial_dout(&com_port->fcr, UART_FCR_DEFVAL); 264 serial_dout(&com_port->fcr, UART_FCR_DEFVAL);
276 265
277 serial_dout(&com_port->lcr, UART_LCR_BKSE | UART_LCRVAL); 266 serial_dout(&com_port->lcr, UART_LCR_BKSE | UART_LCRVAL);
278 serial_dout(&com_port->dll, baud_divisor & 0xff); 267 serial_dout(&com_port->dll, baud_divisor & 0xff);
279 serial_dout(&com_port->dlm, (baud_divisor >> 8) & 0xff); 268 serial_dout(&com_port->dlm, (baud_divisor >> 8) & 0xff);
280 serial_dout(&com_port->lcr, UART_LCRVAL); 269 serial_dout(&com_port->lcr, UART_LCRVAL);
270 }
271
272 static inline void _debug_uart_putc(int ch)
273 {
274 struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
275
276 while (!(serial_din(&com_port->lsr) & UART_LSR_THRE))
277 ;
278 serial_dout(&com_port->thr, ch);
279 }
280
281 DEBUG_UART_FUNCS
282
283 #endif
284
285 #ifdef CONFIG_DEBUG_UART_OMAP
286
287 #include <debug_uart.h>
288
289 static inline void _debug_uart_init(void)
290 {
291 struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
292 int baud_divisor;
293
294 baud_divisor = ns16550_calc_divisor(com_port, CONFIG_DEBUG_UART_CLOCK,
295 CONFIG_BAUDRATE);
296 serial_dout(&com_port->ier, CONFIG_SYS_NS16550_IER);
297 serial_dout(&com_port->mdr1, 0x7);
298 serial_dout(&com_port->mcr, UART_MCRVAL);
299 serial_dout(&com_port->fcr, UART_FCR_DEFVAL);
300
301 serial_dout(&com_port->lcr, UART_LCR_BKSE | UART_LCRVAL);
302 serial_dout(&com_port->dll, baud_divisor & 0xff);
303 serial_dout(&com_port->dlm, (baud_divisor >> 8) & 0xff);
304 serial_dout(&com_port->lcr, UART_LCRVAL);
305 serial_dout(&com_port->mdr1, 0x0);
281 } 306 }
282 307
283 static inline void _debug_uart_putc(int ch) 308 static inline void _debug_uart_putc(int ch)
284 { 309 {
285 struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE; 310 struct NS16550 *com_port = (struct NS16550 *)CONFIG_DEBUG_UART_BASE;
286 311
287 while (!(serial_din(&com_port->lsr) & UART_LSR_THRE)) 312 while (!(serial_din(&com_port->lsr) & UART_LSR_THRE))
288 ; 313 ;
289 serial_dout(&com_port->thr, ch); 314 serial_dout(&com_port->thr, ch);
290 } 315 }
291 316
292 DEBUG_UART_FUNCS 317 DEBUG_UART_FUNCS
293 318
294 #endif 319 #endif
295 320
296 #ifdef CONFIG_DM_SERIAL 321 #ifdef CONFIG_DM_SERIAL
297 static int ns16550_serial_putc(struct udevice *dev, const char ch) 322 static int ns16550_serial_putc(struct udevice *dev, const char ch)
298 { 323 {
299 struct NS16550 *const com_port = dev_get_priv(dev); 324 struct NS16550 *const com_port = dev_get_priv(dev);
300 325
301 if (!(serial_in(&com_port->lsr) & UART_LSR_THRE)) 326 if (!(serial_in(&com_port->lsr) & UART_LSR_THRE))
302 return -EAGAIN; 327 return -EAGAIN;
303 serial_out(ch, &com_port->thr); 328 serial_out(ch, &com_port->thr);
304 329
305 /* 330 /*
306 * Call watchdog_reset() upon newline. This is done here in putc 331 * Call watchdog_reset() upon newline. This is done here in putc
307 * since the environment code uses a single puts() to print the complete 332 * since the environment code uses a single puts() to print the complete
308 * environment upon "printenv". So we can't put this watchdog call 333 * environment upon "printenv". So we can't put this watchdog call
309 * in puts(). 334 * in puts().
310 */ 335 */
311 if (ch == '\n') 336 if (ch == '\n')
312 WATCHDOG_RESET(); 337 WATCHDOG_RESET();
313 338
314 return 0; 339 return 0;
315 } 340 }
316 341
317 static int ns16550_serial_pending(struct udevice *dev, bool input) 342 static int ns16550_serial_pending(struct udevice *dev, bool input)
318 { 343 {
319 struct NS16550 *const com_port = dev_get_priv(dev); 344 struct NS16550 *const com_port = dev_get_priv(dev);
320 345
321 if (input) 346 if (input)
322 return serial_in(&com_port->lsr) & UART_LSR_DR ? 1 : 0; 347 return serial_in(&com_port->lsr) & UART_LSR_DR ? 1 : 0;
323 else 348 else
324 return serial_in(&com_port->lsr) & UART_LSR_THRE ? 0 : 1; 349 return serial_in(&com_port->lsr) & UART_LSR_THRE ? 0 : 1;
325 } 350 }
326 351
327 static int ns16550_serial_getc(struct udevice *dev) 352 static int ns16550_serial_getc(struct udevice *dev)
328 { 353 {
329 struct NS16550 *const com_port = dev_get_priv(dev); 354 struct NS16550 *const com_port = dev_get_priv(dev);
330 355
331 if (!(serial_in(&com_port->lsr) & UART_LSR_DR)) 356 if (!(serial_in(&com_port->lsr) & UART_LSR_DR))
332 return -EAGAIN; 357 return -EAGAIN;
333 358
334 return serial_in(&com_port->rbr); 359 return serial_in(&com_port->rbr);
335 } 360 }
336 361
337 static int ns16550_serial_setbrg(struct udevice *dev, int baudrate) 362 static int ns16550_serial_setbrg(struct udevice *dev, int baudrate)
338 { 363 {
339 struct NS16550 *const com_port = dev_get_priv(dev); 364 struct NS16550 *const com_port = dev_get_priv(dev);
340 struct ns16550_platdata *plat = com_port->plat; 365 struct ns16550_platdata *plat = com_port->plat;
341 int clock_divisor; 366 int clock_divisor;
342 367
343 clock_divisor = ns16550_calc_divisor(com_port, plat->clock, baudrate); 368 clock_divisor = ns16550_calc_divisor(com_port, plat->clock, baudrate);
344 369
345 NS16550_setbrg(com_port, clock_divisor); 370 NS16550_setbrg(com_port, clock_divisor);
346 371
347 return 0; 372 return 0;
348 } 373 }
349 374
350 int ns16550_serial_probe(struct udevice *dev) 375 int ns16550_serial_probe(struct udevice *dev)
351 { 376 {
352 struct NS16550 *const com_port = dev_get_priv(dev); 377 struct NS16550 *const com_port = dev_get_priv(dev);
353 378
354 com_port->plat = dev_get_platdata(dev); 379 com_port->plat = dev_get_platdata(dev);
355 NS16550_init(com_port, -1); 380 NS16550_init(com_port, -1);
356 381
357 return 0; 382 return 0;
358 } 383 }
359 384
360 #if CONFIG_IS_ENABLED(OF_CONTROL) 385 #if CONFIG_IS_ENABLED(OF_CONTROL)
361 enum { 386 enum {
362 PORT_NS16550 = 0, 387 PORT_NS16550 = 0,
363 PORT_JZ4780, 388 PORT_JZ4780,
364 }; 389 };
365 #endif 390 #endif
366 391
367 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) 392 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
368 int ns16550_serial_ofdata_to_platdata(struct udevice *dev) 393 int ns16550_serial_ofdata_to_platdata(struct udevice *dev)
369 { 394 {
370 struct ns16550_platdata *plat = dev->platdata; 395 struct ns16550_platdata *plat = dev->platdata;
371 const u32 port_type = dev_get_driver_data(dev); 396 const u32 port_type = dev_get_driver_data(dev);
372 fdt_addr_t addr; 397 fdt_addr_t addr;
373 struct clk clk; 398 struct clk clk;
374 int err; 399 int err;
375 400
376 /* try Processor Local Bus device first */ 401 /* try Processor Local Bus device first */
377 addr = dev_get_addr(dev); 402 addr = dev_get_addr(dev);
378 #if defined(CONFIG_PCI) && defined(CONFIG_DM_PCI) 403 #if defined(CONFIG_PCI) && defined(CONFIG_DM_PCI)
379 if (addr == FDT_ADDR_T_NONE) { 404 if (addr == FDT_ADDR_T_NONE) {
380 /* then try pci device */ 405 /* then try pci device */
381 struct fdt_pci_addr pci_addr; 406 struct fdt_pci_addr pci_addr;
382 u32 bar; 407 u32 bar;
383 int ret; 408 int ret;
384 409
385 /* we prefer to use a memory-mapped register */ 410 /* we prefer to use a memory-mapped register */
386 ret = fdtdec_get_pci_addr(gd->fdt_blob, dev_of_offset(dev), 411 ret = fdtdec_get_pci_addr(gd->fdt_blob, dev_of_offset(dev),
387 FDT_PCI_SPACE_MEM32, "reg", 412 FDT_PCI_SPACE_MEM32, "reg",
388 &pci_addr); 413 &pci_addr);
389 if (ret) { 414 if (ret) {
390 /* try if there is any i/o-mapped register */ 415 /* try if there is any i/o-mapped register */
391 ret = fdtdec_get_pci_addr(gd->fdt_blob, 416 ret = fdtdec_get_pci_addr(gd->fdt_blob,
392 dev_of_offset(dev), 417 dev_of_offset(dev),
393 FDT_PCI_SPACE_IO, 418 FDT_PCI_SPACE_IO,
394 "reg", &pci_addr); 419 "reg", &pci_addr);
395 if (ret) 420 if (ret)
396 return ret; 421 return ret;
397 } 422 }
398 423
399 ret = fdtdec_get_pci_bar32(dev, &pci_addr, &bar); 424 ret = fdtdec_get_pci_bar32(dev, &pci_addr, &bar);
400 if (ret) 425 if (ret)
401 return ret; 426 return ret;
402 427
403 addr = bar; 428 addr = bar;
404 } 429 }
405 #endif 430 #endif
406 431
407 if (addr == FDT_ADDR_T_NONE) 432 if (addr == FDT_ADDR_T_NONE)
408 return -EINVAL; 433 return -EINVAL;
409 434
410 #ifdef CONFIG_SYS_NS16550_PORT_MAPPED 435 #ifdef CONFIG_SYS_NS16550_PORT_MAPPED
411 plat->base = addr; 436 plat->base = addr;
412 #else 437 #else
413 plat->base = (unsigned long)map_physmem(addr, 0, MAP_NOCACHE); 438 plat->base = (unsigned long)map_physmem(addr, 0, MAP_NOCACHE);
414 #endif 439 #endif
415 440
416 plat->reg_offset = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), 441 plat->reg_offset = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
417 "reg-offset", 0); 442 "reg-offset", 0);
418 plat->reg_shift = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), 443 plat->reg_shift = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
419 "reg-shift", 0); 444 "reg-shift", 0);
420 445
421 err = clk_get_by_index(dev, 0, &clk); 446 err = clk_get_by_index(dev, 0, &clk);
422 if (!err) { 447 if (!err) {
423 err = clk_get_rate(&clk); 448 err = clk_get_rate(&clk);
424 if (!IS_ERR_VALUE(err)) 449 if (!IS_ERR_VALUE(err))
425 plat->clock = err; 450 plat->clock = err;
426 } else if (err != -ENOENT && err != -ENODEV && err != -ENOSYS) { 451 } else if (err != -ENOENT && err != -ENODEV && err != -ENOSYS) {
427 debug("ns16550 failed to get clock\n"); 452 debug("ns16550 failed to get clock\n");
428 return err; 453 return err;
429 } 454 }
430 455
431 if (!plat->clock) 456 if (!plat->clock)
432 plat->clock = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), 457 plat->clock = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
433 "clock-frequency", 458 "clock-frequency",
434 CONFIG_SYS_NS16550_CLK); 459 CONFIG_SYS_NS16550_CLK);
435 if (!plat->clock) { 460 if (!plat->clock) {
436 debug("ns16550 clock not defined\n"); 461 debug("ns16550 clock not defined\n");
437 return -EINVAL; 462 return -EINVAL;
438 } 463 }
439 464
440 plat->fcr = UART_FCR_DEFVAL; 465 plat->fcr = UART_FCR_DEFVAL;
441 if (port_type == PORT_JZ4780) 466 if (port_type == PORT_JZ4780)
442 plat->fcr |= UART_FCR_UME; 467 plat->fcr |= UART_FCR_UME;
443 468
444 return 0; 469 return 0;
445 } 470 }
446 #endif 471 #endif
447 472
448 const struct dm_serial_ops ns16550_serial_ops = { 473 const struct dm_serial_ops ns16550_serial_ops = {
449 .putc = ns16550_serial_putc, 474 .putc = ns16550_serial_putc,
450 .pending = ns16550_serial_pending, 475 .pending = ns16550_serial_pending,
451 .getc = ns16550_serial_getc, 476 .getc = ns16550_serial_getc,
452 .setbrg = ns16550_serial_setbrg, 477 .setbrg = ns16550_serial_setbrg,
453 }; 478 };
454 479
455 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) 480 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
456 /* 481 /*
457 * Please consider existing compatible strings before adding a new 482 * Please consider existing compatible strings before adding a new
458 * one to keep this table compact. Or you may add a generic "ns16550" 483 * one to keep this table compact. Or you may add a generic "ns16550"
459 * compatible string to your dts. 484 * compatible string to your dts.
460 */ 485 */
461 static const struct udevice_id ns16550_serial_ids[] = { 486 static const struct udevice_id ns16550_serial_ids[] = {
462 { .compatible = "ns16550", .data = PORT_NS16550 }, 487 { .compatible = "ns16550", .data = PORT_NS16550 },
463 { .compatible = "ns16550a", .data = PORT_NS16550 }, 488 { .compatible = "ns16550a", .data = PORT_NS16550 },
464 { .compatible = "ingenic,jz4780-uart", .data = PORT_JZ4780 }, 489 { .compatible = "ingenic,jz4780-uart", .data = PORT_JZ4780 },
465 { .compatible = "nvidia,tegra20-uart", .data = PORT_NS16550 }, 490 { .compatible = "nvidia,tegra20-uart", .data = PORT_NS16550 },
466 { .compatible = "snps,dw-apb-uart", .data = PORT_NS16550 }, 491 { .compatible = "snps,dw-apb-uart", .data = PORT_NS16550 },
467 { .compatible = "ti,omap2-uart", .data = PORT_NS16550 }, 492 { .compatible = "ti,omap2-uart", .data = PORT_NS16550 },
468 { .compatible = "ti,omap3-uart", .data = PORT_NS16550 }, 493 { .compatible = "ti,omap3-uart", .data = PORT_NS16550 },
469 { .compatible = "ti,omap4-uart", .data = PORT_NS16550 }, 494 { .compatible = "ti,omap4-uart", .data = PORT_NS16550 },
470 { .compatible = "ti,am3352-uart", .data = PORT_NS16550 }, 495 { .compatible = "ti,am3352-uart", .data = PORT_NS16550 },
471 { .compatible = "ti,am4372-uart", .data = PORT_NS16550 }, 496 { .compatible = "ti,am4372-uart", .data = PORT_NS16550 },
472 { .compatible = "ti,dra742-uart", .data = PORT_NS16550 }, 497 { .compatible = "ti,dra742-uart", .data = PORT_NS16550 },
473 {} 498 {}
474 }; 499 };
475 #endif /* OF_CONTROL && !OF_PLATDATA */ 500 #endif /* OF_CONTROL && !OF_PLATDATA */
476 501
477 #if CONFIG_IS_ENABLED(SERIAL_PRESENT) 502 #if CONFIG_IS_ENABLED(SERIAL_PRESENT)
478 503
479 /* TODO(sjg@chromium.org): Integrate this into a macro like CONFIG_IS_ENABLED */ 504 /* TODO(sjg@chromium.org): Integrate this into a macro like CONFIG_IS_ENABLED */
480 #if !defined(CONFIG_TPL_BUILD) || defined(CONFIG_TPL_DM_SERIAL) 505 #if !defined(CONFIG_TPL_BUILD) || defined(CONFIG_TPL_DM_SERIAL)
481 U_BOOT_DRIVER(ns16550_serial) = { 506 U_BOOT_DRIVER(ns16550_serial) = {
482 .name = "ns16550_serial", 507 .name = "ns16550_serial",
483 .id = UCLASS_SERIAL, 508 .id = UCLASS_SERIAL,
484 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) 509 #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA)
485 .of_match = ns16550_serial_ids, 510 .of_match = ns16550_serial_ids,
486 .ofdata_to_platdata = ns16550_serial_ofdata_to_platdata, 511 .ofdata_to_platdata = ns16550_serial_ofdata_to_platdata,
487 .platdata_auto_alloc_size = sizeof(struct ns16550_platdata), 512 .platdata_auto_alloc_size = sizeof(struct ns16550_platdata),
include/debug_uart.h
1 /* 1 /*
2 * Early debug UART support 2 * Early debug UART support
3 * 3 *
4 * (C) Copyright 2014 Google, Inc 4 * (C) Copyright 2014 Google, Inc
5 * Writte by Simon Glass <sjg@chromium.org> 5 * Writte by Simon Glass <sjg@chromium.org>
6 * 6 *
7 * SPDX-License-Identifier: GPL-2.0+ 7 * SPDX-License-Identifier: GPL-2.0+
8 */ 8 */
9 9
10 #ifndef _DEBUG_UART_H 10 #ifndef _DEBUG_UART_H
11 #define _DEBUG_UART_H 11 #define _DEBUG_UART_H
12 12
13 /* 13 /*
14 * The debug UART is intended for use very early in U-Boot to debug problems 14 * The debug UART is intended for use very early in U-Boot to debug problems
15 * when an ICE or other debug mechanism is not available. 15 * when an ICE or other debug mechanism is not available.
16 * 16 *
17 * To use it you should: 17 * To use it you should:
18 * - Make sure your UART supports this interface 18 * - Make sure your UART supports this interface
19 * - Enable CONFIG_DEBUG_UART 19 * - Enable CONFIG_DEBUG_UART
20 * - Enable the CONFIG for your UART to tell it to provide this interface 20 * - Enable the CONFIG for your UART to tell it to provide this interface
21 * (e.g. CONFIG_DEBUG_UART_NS16550) 21 * (e.g. CONFIG_DEBUG_UART_NS16550)
22 * - Define the required settings as needed (see below) 22 * - Define the required settings as needed (see below)
23 * - Call debug_uart_init() before use 23 * - Call debug_uart_init() before use
24 * - Call printch() to output a character 24 * - Call printch() to output a character
25 * 25 *
26 * Depending on your platform it may be possible to use this UART before a 26 * Depending on your platform it may be possible to use this UART before a
27 * stack is available. 27 * stack is available.
28 * 28 *
29 * If your UART does not support this interface you can probably add support 29 * If your UART does not support this interface you can probably add support
30 * quite easily. Remember that you cannot use driver model and it is preferred 30 * quite easily. Remember that you cannot use driver model and it is preferred
31 * to use no stack. 31 * to use no stack.
32 * 32 *
33 * You must not use this UART once driver model is working and the serial 33 * You must not use this UART once driver model is working and the serial
34 * drivers are up and running (done in serial_init()). Otherwise the drivers 34 * drivers are up and running (done in serial_init()). Otherwise the drivers
35 * may conflict and you will get strange output. 35 * may conflict and you will get strange output.
36 * 36 *
37 * 37 *
38 * To enable the debug UART in your serial driver: 38 * To enable the debug UART in your serial driver:
39 * 39 *
40 * - #include <debug_uart.h> 40 * - #include <debug_uart.h>
41 * - Define _debug_uart_init(), trying to avoid using the stack 41 * - Define _debug_uart_init(), trying to avoid using the stack
42 * - Define _debug_uart_putc() as static inline (avoiding stack usage) 42 * - Define _debug_uart_putc() as static inline (avoiding stack usage)
43 * - Immediately afterwards, add DEBUG_UART_FUNCS to define the rest of the 43 * - Immediately afterwards, add DEBUG_UART_FUNCS to define the rest of the
44 * functionality (printch(), etc.) 44 * functionality (printch(), etc.)
45 * 45 *
46 * If your board needs additional init for the UART to work, enable 46 * If your board needs additional init for the UART to work, enable
47 * CONFIG_DEBUG_UART_BOARD_INIT and write a function called 47 * CONFIG_DEBUG_UART_BOARD_INIT and write a function called
48 * board_debug_uart_init() to perform that init. When debug_uart_init() is 48 * board_debug_uart_init() to perform that init. When debug_uart_init() is
49 * called, the init will happen automatically. 49 * called, the init will happen automatically.
50 */ 50 */
51 51
52 /** 52 /**
53 * debug_uart_init() - Set up the debug UART ready for use 53 * debug_uart_init() - Set up the debug UART ready for use
54 * 54 *
55 * This sets up the UART with the correct baud rate, etc. 55 * This sets up the UART with the correct baud rate, etc.
56 * 56 *
57 * Available CONFIG is: 57 * Available CONFIG is:
58 * 58 *
59 * - CONFIG_DEBUG_UART_BASE: Base address of UART 59 * - CONFIG_DEBUG_UART_BASE: Base address of UART
60 * - CONFIG_BAUDRATE: Requested baud rate 60 * - CONFIG_BAUDRATE: Requested baud rate
61 * - CONFIG_DEBUG_UART_CLOCK: Input clock for UART 61 * - CONFIG_DEBUG_UART_CLOCK: Input clock for UART
62 */ 62 */
63 void debug_uart_init(void); 63 void debug_uart_init(void);
64 64
65 #ifdef CONFIG_DEBUG_UART_BOARD_INIT 65 #ifdef CONFIG_DEBUG_UART_BOARD_INIT
66 void board_debug_uart_init(void); 66 void board_debug_uart_init(void);
67 #else 67 #else
68 static inline void board_debug_uart_init(void) 68 static inline void board_debug_uart_init(void)
69 { 69 {
70 } 70 }
71 #endif 71 #endif
72 72
73 /** 73 /**
74 * printch() - Output a character to the debug UART 74 * printch() - Output a character to the debug UART
75 * 75 *
76 * @ch: Character to output 76 * @ch: Character to output
77 */ 77 */
78 void printch(int ch); 78 void printch(int ch);
79 79
80 /** 80 /**
81 * printascii() - Output an ASCII string to the debug UART 81 * printascii() - Output an ASCII string to the debug UART
82 * 82 *
83 * @str: String to output 83 * @str: String to output
84 */ 84 */
85 void printascii(const char *str); 85 void printascii(const char *str);
86 86
87 /** 87 /**
88 * printhex2() - Output a 2-digit hex value 88 * printhex2() - Output a 2-digit hex value
89 * 89 *
90 * @value: Value to output 90 * @value: Value to output
91 */ 91 */
92 void printhex2(uint value); 92 void printhex2(uint value);
93 93
94 /** 94 /**
95 * printhex4() - Output a 4-digit hex value 95 * printhex4() - Output a 4-digit hex value
96 * 96 *
97 * @value: Value to output 97 * @value: Value to output
98 */ 98 */
99 void printhex4(uint value); 99 void printhex4(uint value);
100 100
101 /** 101 /**
102 * printhex8() - Output a 8-digit hex value 102 * printhex8() - Output a 8-digit hex value
103 * 103 *
104 * @value: Value to output 104 * @value: Value to output
105 */ 105 */
106 void printhex8(uint value); 106 void printhex8(uint value);
107 107
108 #ifdef CONFIG_DEBUG_UART_ANNOUNCE 108 #ifdef CONFIG_DEBUG_UART_ANNOUNCE
109 #define _DEBUG_UART_ANNOUNCE printascii("<debug_uart> "); 109 #define _DEBUG_UART_ANNOUNCE printascii("<debug_uart> ");
110 #else 110 #else
111 #define _DEBUG_UART_ANNOUNCE 111 #define _DEBUG_UART_ANNOUNCE
112 #endif 112 #endif
113 113
114 #define serial_dout(reg, value) \
115 serial_out_shift((char *)com_port + \
116 ((char *)reg - (char *)com_port) * \
117 (1 << CONFIG_DEBUG_UART_SHIFT), \
118 CONFIG_DEBUG_UART_SHIFT, value)
119 #define serial_din(reg) \
120 serial_in_shift((char *)com_port + \
121 ((char *)reg - (char *)com_port) * \
122 (1 << CONFIG_DEBUG_UART_SHIFT), \
123 CONFIG_DEBUG_UART_SHIFT)
124
114 /* 125 /*
115 * Now define some functions - this should be inserted into the serial driver 126 * Now define some functions - this should be inserted into the serial driver
116 */ 127 */
117 #define DEBUG_UART_FUNCS \ 128 #define DEBUG_UART_FUNCS \
118 \ 129 \
119 static inline void _printch(int ch) \ 130 static inline void _printch(int ch) \
120 { \ 131 { \
121 if (ch == '\n') \ 132 if (ch == '\n') \
122 _debug_uart_putc('\r'); \ 133 _debug_uart_putc('\r'); \
123 _debug_uart_putc(ch); \ 134 _debug_uart_putc(ch); \
124 } \ 135 } \
125 \ 136 \
126 void printch(int ch) \ 137 void printch(int ch) \
127 { \ 138 { \
128 _printch(ch); \ 139 _printch(ch); \
129 } \ 140 } \
130 \ 141 \
131 void printascii(const char *str) \ 142 void printascii(const char *str) \
132 { \ 143 { \
133 while (*str) \ 144 while (*str) \
134 _printch(*str++); \ 145 _printch(*str++); \
135 } \ 146 } \
136 \ 147 \
137 static inline void printhex1(uint digit) \ 148 static inline void printhex1(uint digit) \
138 { \ 149 { \
139 digit &= 0xf; \ 150 digit &= 0xf; \
140 _debug_uart_putc(digit > 9 ? digit - 10 + 'a' : digit + '0'); \ 151 _debug_uart_putc(digit > 9 ? digit - 10 + 'a' : digit + '0'); \
141 } \ 152 } \
142 \ 153 \
143 static inline void printhex(uint value, int digits) \ 154 static inline void printhex(uint value, int digits) \
144 { \ 155 { \
145 while (digits-- > 0) \ 156 while (digits-- > 0) \
146 printhex1(value >> (4 * digits)); \ 157 printhex1(value >> (4 * digits)); \
147 } \ 158 } \
148 \ 159 \
149 void printhex2(uint value) \ 160 void printhex2(uint value) \
150 { \ 161 { \
151 printhex(value, 2); \ 162 printhex(value, 2); \
152 } \ 163 } \
153 \ 164 \
154 void printhex4(uint value) \ 165 void printhex4(uint value) \
155 { \ 166 { \
156 printhex(value, 4); \ 167 printhex(value, 4); \
157 } \ 168 } \
158 \ 169 \
159 void printhex8(uint value) \ 170 void printhex8(uint value) \
160 { \ 171 { \
161 printhex(value, 8); \ 172 printhex(value, 8); \
162 } \ 173 } \
163 \ 174 \
164 void debug_uart_init(void) \ 175 void debug_uart_init(void) \
165 { \ 176 { \
166 board_debug_uart_init(); \ 177 board_debug_uart_init(); \
167 _debug_uart_init(); \ 178 _debug_uart_init(); \
168 _DEBUG_UART_ANNOUNCE \ 179 _DEBUG_UART_ANNOUNCE \
169 } \ 180 } \
170 181
171 #endif 182 #endif
172 183