2 * Early debug UART support
4 * (C) Copyright 2014 Google, Inc
5 * Writte by Simon Glass <sjg@chromium.org>
7 * SPDX-License-Identifier: GPL-2.0+
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.
17 * To use it you should:
18 * - Make sure your UART supports this interface
19 * - Enable CONFIG_DEBUG_UART
20 * - Enable the CONFIG for your UART to tell it to provide this interface
21 * (e.g. CONFIG_DEBUG_UART_NS16550)
22 * - Define the required settings as needed (see below)
23 * - Call debug_uart_init() before use
24 * - Call printch() to output a character
26 * Depending on your platform it may be possible to use this UART before a
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
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
35 * may conflict and you will get strange output.
38 * To enable the debug UART in your serial driver:
40 * - #include <debug_uart.h>
41 * - Define debug_uart_init(), trying to avoid using the stack
42 * - Define _debug_uart_putc() as static inline (avoiding stack usage)
43 * - Immediately afterwards, add DEBUG_UART_FUNCS to define the rest of the
44 * functionality (printch(), etc.)
48 * debug_uart_init() - Set up the debug UART ready for use
50 * This sets up the UART with the correct baud rate, etc.
52 * Available CONFIG is:
54 * - CONFIG_DEBUG_UART_BASE: Base address of UART
55 * - CONFIG_BAUDRATE: Requested baud rate
56 * - CONFIG_DEBUG_UART_CLOCK: Input clock for UART
58 void debug_uart_init(void);
61 * printch() - Output a character to the debug UART
63 * @ch: Character to output
68 * printascii() - Output an ASCII string to the debug UART
70 * @str: String to output
72 void printascii(const char *str);
75 * printhex2() - Output a 2-digit hex value
77 * @value: Value to output
79 void printhex2(uint value);
82 * printhex4() - Output a 4-digit hex value
84 * @value: Value to output
86 void printhex4(uint value);
89 * printhex8() - Output a 8-digit hex value
91 * @value: Value to output
93 void printhex8(uint value);
96 * Now define some functions - this should be inserted into the serial driver
98 #define DEBUG_UART_FUNCS \
99 void printch(int ch) \
101 _debug_uart_putc(ch); \
104 void printascii(const char *str) \
107 _debug_uart_putc(*str++); \
110 static inline void printhex1(uint digit) \
113 _debug_uart_putc(digit > 9 ? digit - 10 + 'a' : digit + '0'); \
116 static inline void printhex(uint value, int digits) \
118 while (digits-- > 0) \
119 printhex1(value >> (4 * digits)); \
122 void printhex2(uint value) \
124 printhex(value, 2); \
127 void printhex4(uint value) \
129 printhex(value, 4); \
132 void printhex8(uint value) \
134 printhex(value, 8); \