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+
13 #include <linux/linkage.h>
16 * The debug UART is intended for use very early in U-Boot to debug problems
17 * when an ICE or other debug mechanism is not available.
19 * To use it you should:
20 * - Make sure your UART supports this interface
21 * - Enable CONFIG_DEBUG_UART
22 * - Enable the CONFIG for your UART to tell it to provide this interface
23 * (e.g. CONFIG_DEBUG_UART_NS16550)
24 * - Define the required settings as needed (see below)
25 * - Call debug_uart_init() before use
26 * - Call printch() to output a character
28 * Depending on your platform it may be possible to use this UART before a
31 * If your UART does not support this interface you can probably add support
32 * quite easily. Remember that you cannot use driver model and it is preferred
35 * You must not use this UART once driver model is working and the serial
36 * drivers are up and running (done in serial_init()). Otherwise the drivers
37 * may conflict and you will get strange output.
40 * To enable the debug UART in your serial driver:
42 * - #include <debug_uart.h>
43 * - Define debug_uart_init(), trying to avoid using the stack
44 * - Define _debug_uart_putc() as static inline (avoiding stack usage)
45 * - Immediately afterwards, add DEBUG_UART_FUNCS to define the rest of the
46 * functionality (printch(), etc.)
50 * debug_uart_init() - Set up the debug UART ready for use
52 * This sets up the UART with the correct baud rate, etc.
54 * Available CONFIG is:
56 * - CONFIG_DEBUG_UART_BASE: Base address of UART
57 * - CONFIG_BAUDRATE: Requested baud rate
58 * - CONFIG_DEBUG_UART_CLOCK: Input clock for UART
60 void debug_uart_init(void);
63 * printch() - Output a character to the debug UART
65 * @ch: Character to output
67 asmlinkage void printch(int ch);
70 * printascii() - Output an ASCII string to the debug UART
72 * @str: String to output
74 asmlinkage void printascii(const char *str);
77 * printhex2() - Output a 2-digit hex value
79 * @value: Value to output
81 asmlinkage void printhex2(uint value);
84 * printhex4() - Output a 4-digit hex value
86 * @value: Value to output
88 asmlinkage void printhex4(uint value);
91 * printhex8() - Output a 8-digit hex value
93 * @value: Value to output
95 asmlinkage void printhex8(uint value);
98 * Now define some functions - this should be inserted into the serial driver
100 #define DEBUG_UART_FUNCS \
101 asmlinkage void printch(int ch) \
103 _debug_uart_putc(ch); \
106 asmlinkage void printascii(const char *str) \
109 _debug_uart_putc(*str++); \
112 static inline void printhex1(uint digit) \
115 _debug_uart_putc(digit > 9 ? digit - 10 + 'a' : digit + '0'); \
118 static inline void printhex(uint value, int digits) \
120 while (digits-- > 0) \
121 printhex1(value >> (4 * digits)); \
124 asmlinkage void printhex2(uint value) \
126 printhex(value, 2); \
129 asmlinkage void printhex4(uint value) \
131 printhex(value, 4); \
134 asmlinkage void printhex8(uint value) \
136 printhex(value, 8); \