Simon Glass | 2f964aa | 2015-01-26 18:27:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Early debug UART support |
| 3 | * |
| 4 | * (C) Copyright 2014 Google, Inc |
| 5 | * Writte by Simon Glass <sjg@chromium.org> |
| 6 | * |
| 7 | * SPDX-License-Identifier: GPL-2.0+ |
| 8 | */ |
| 9 | |
| 10 | #ifndef _DEBUG_UART_H |
| 11 | #define _DEBUG_UART_H |
| 12 | |
| 13 | #include <linux/linkage.h> |
| 14 | |
| 15 | /* |
| 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. |
| 18 | * |
| 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 |
| 27 | * |
| 28 | * Depending on your platform it may be possible to use this UART before a |
| 29 | * stack is available. |
| 30 | * |
| 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 |
| 33 | * to use no stack. |
| 34 | * |
| 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. |
| 38 | * |
| 39 | * |
| 40 | * To enable the debug UART in your serial driver: |
| 41 | * |
| 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.) |
| 47 | */ |
| 48 | |
| 49 | /** |
| 50 | * debug_uart_init() - Set up the debug UART ready for use |
| 51 | * |
| 52 | * This sets up the UART with the correct baud rate, etc. |
| 53 | * |
| 54 | * Available CONFIG is: |
| 55 | * |
| 56 | * - CONFIG_DEBUG_UART_BASE: Base address of UART |
| 57 | * - CONFIG_BAUDRATE: Requested baud rate |
| 58 | * - CONFIG_DEBUG_UART_CLOCK: Input clock for UART |
| 59 | */ |
| 60 | void debug_uart_init(void); |
| 61 | |
| 62 | /** |
| 63 | * printch() - Output a character to the debug UART |
| 64 | * |
| 65 | * @ch: Character to output |
| 66 | */ |
| 67 | asmlinkage void printch(int ch); |
| 68 | |
| 69 | /** |
| 70 | * printascii() - Output an ASCII string to the debug UART |
| 71 | * |
| 72 | * @str: String to output |
| 73 | */ |
| 74 | asmlinkage void printascii(const char *str); |
| 75 | |
| 76 | /** |
| 77 | * printhex2() - Output a 2-digit hex value |
| 78 | * |
| 79 | * @value: Value to output |
| 80 | */ |
| 81 | asmlinkage void printhex2(uint value); |
| 82 | |
| 83 | /** |
| 84 | * printhex4() - Output a 4-digit hex value |
| 85 | * |
| 86 | * @value: Value to output |
| 87 | */ |
| 88 | asmlinkage void printhex4(uint value); |
| 89 | |
| 90 | /** |
| 91 | * printhex8() - Output a 8-digit hex value |
| 92 | * |
| 93 | * @value: Value to output |
| 94 | */ |
| 95 | asmlinkage void printhex8(uint value); |
| 96 | |
| 97 | /* |
| 98 | * Now define some functions - this should be inserted into the serial driver |
| 99 | */ |
| 100 | #define DEBUG_UART_FUNCS \ |
| 101 | asmlinkage void printch(int ch) \ |
| 102 | { \ |
| 103 | _debug_uart_putc(ch); \ |
| 104 | } \ |
| 105 | \ |
| 106 | asmlinkage void printascii(const char *str) \ |
| 107 | { \ |
| 108 | while (*str) \ |
| 109 | _debug_uart_putc(*str++); \ |
| 110 | } \ |
| 111 | \ |
| 112 | static inline void printhex1(uint digit) \ |
| 113 | { \ |
| 114 | digit &= 0xf; \ |
| 115 | _debug_uart_putc(digit > 9 ? digit - 10 + 'a' : digit + '0'); \ |
| 116 | } \ |
| 117 | \ |
| 118 | static inline void printhex(uint value, int digits) \ |
| 119 | { \ |
| 120 | while (digits-- > 0) \ |
| 121 | printhex1(value >> (4 * digits)); \ |
| 122 | } \ |
| 123 | \ |
| 124 | asmlinkage void printhex2(uint value) \ |
| 125 | { \ |
| 126 | printhex(value, 2); \ |
| 127 | } \ |
| 128 | \ |
| 129 | asmlinkage void printhex4(uint value) \ |
| 130 | { \ |
| 131 | printhex(value, 4); \ |
| 132 | } \ |
| 133 | \ |
| 134 | asmlinkage void printhex8(uint value) \ |
| 135 | { \ |
| 136 | printhex(value, 8); \ |
| 137 | } |
| 138 | |
| 139 | #endif |