Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2009 SAMSUNG Electronics |
| 4 | * Minkyu Kang <mk7.kang@samsung.com> |
| 5 | * Heungjun Kim <riverful.kim@samsung.com> |
| 6 | * |
| 7 | * based on drivers/serial/s3c64xx.c |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 11 | #include <dm.h> |
| 12 | #include <errno.h> |
Rajeshwari Shinde | d4ec8f0 | 2013-06-24 16:47:22 +0530 | [diff] [blame] | 13 | #include <fdtdec.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 14 | #include <asm/global_data.h> |
Mike Frysinger | 6c768ca | 2011-04-29 18:03:29 +0000 | [diff] [blame] | 15 | #include <linux/compiler.h> |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 16 | #include <asm/io.h> |
Mark Kettenis | 053827b | 2023-01-26 14:44:09 +0100 | [diff] [blame] | 17 | #if !IS_ENABLED(CONFIG_ARCH_APPLE) |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 18 | #include <asm/arch/clk.h> |
Mark Kettenis | d520e1f | 2021-10-23 16:58:04 +0200 | [diff] [blame] | 19 | #endif |
Simon Glass | 89ca935 | 2015-07-02 18:15:53 -0600 | [diff] [blame] | 20 | #include <asm/arch/uart.h> |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 21 | #include <serial.h> |
Thomas Abraham | cf75cdf | 2016-04-23 22:18:11 +0530 | [diff] [blame] | 22 | #include <clk.h> |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 23 | |
John Rigby | 2956532 | 2010-12-20 18:27:51 -0700 | [diff] [blame] | 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
Mark Kettenis | d520e1f | 2021-10-23 16:58:04 +0200 | [diff] [blame] | 26 | enum { |
| 27 | PORT_S5P = 0, |
| 28 | PORT_S5L |
| 29 | }; |
| 30 | |
| 31 | #define S5L_RX_FIFO_COUNT_SHIFT 0 |
| 32 | #define S5L_RX_FIFO_COUNT_MASK (0xf << S5L_RX_FIFO_COUNT_SHIFT) |
| 33 | #define S5L_RX_FIFO_FULL (1 << 8) |
| 34 | #define S5L_TX_FIFO_COUNT_SHIFT 4 |
| 35 | #define S5L_TX_FIFO_COUNT_MASK (0xf << S5L_TX_FIFO_COUNT_SHIFT) |
| 36 | #define S5L_TX_FIFO_FULL (1 << 9) |
| 37 | |
| 38 | #define S5P_RX_FIFO_COUNT_SHIFT 0 |
| 39 | #define S5P_RX_FIFO_COUNT_MASK (0xff << S5P_RX_FIFO_COUNT_SHIFT) |
| 40 | #define S5P_RX_FIFO_FULL (1 << 8) |
| 41 | #define S5P_TX_FIFO_COUNT_SHIFT 16 |
| 42 | #define S5P_TX_FIFO_COUNT_MASK (0xff << S5P_TX_FIFO_COUNT_SHIFT) |
| 43 | #define S5P_TX_FIFO_FULL (1 << 24) |
Akshay Saraswat | ffbff1d | 2013-03-21 20:33:04 +0000 | [diff] [blame] | 44 | |
Rajeshwari Shinde | d4ec8f0 | 2013-06-24 16:47:22 +0530 | [diff] [blame] | 45 | /* Information about a serial port */ |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 46 | struct s5p_serial_plat { |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 47 | struct s5p_uart *reg; /* address of registers in physical memory */ |
Mark Kettenis | d520e1f | 2021-10-23 16:58:04 +0200 | [diff] [blame] | 48 | u8 reg_width; /* register width */ |
Rajeshwari Shinde | d4ec8f0 | 2013-06-24 16:47:22 +0530 | [diff] [blame] | 49 | u8 port_id; /* uart port number */ |
Mark Kettenis | d520e1f | 2021-10-23 16:58:04 +0200 | [diff] [blame] | 50 | u8 rx_fifo_count_shift; |
| 51 | u8 tx_fifo_count_shift; |
| 52 | u32 rx_fifo_count_mask; |
| 53 | u32 tx_fifo_count_mask; |
| 54 | u32 rx_fifo_full; |
| 55 | u32 tx_fifo_full; |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 56 | }; |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 57 | |
| 58 | /* |
Minkyu Kang | 46a3b5c | 2010-03-24 16:59:30 +0900 | [diff] [blame] | 59 | * The coefficient, used to calculate the baudrate on S5P UARTs is |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 60 | * calculated as |
| 61 | * C = UBRDIV * 16 + number_of_set_bits_in_UDIVSLOT |
| 62 | * however, section 31.6.11 of the datasheet doesn't recomment using 1 for 1, |
| 63 | * 3 for 2, ... (2^n - 1) for n, instead, they suggest using these constants: |
| 64 | */ |
| 65 | static const int udivslot[] = { |
| 66 | 0, |
| 67 | 0x0080, |
| 68 | 0x0808, |
| 69 | 0x0888, |
| 70 | 0x2222, |
| 71 | 0x4924, |
| 72 | 0x4a52, |
| 73 | 0x54aa, |
| 74 | 0x5555, |
| 75 | 0xd555, |
| 76 | 0xd5d5, |
| 77 | 0xddd5, |
| 78 | 0xdddd, |
| 79 | 0xdfdd, |
| 80 | 0xdfdf, |
| 81 | 0xffdf, |
| 82 | }; |
| 83 | |
Simon Glass | 89ca935 | 2015-07-02 18:15:53 -0600 | [diff] [blame] | 84 | static void __maybe_unused s5p_serial_init(struct s5p_uart *uart) |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 85 | { |
Simon Glass | 89ca935 | 2015-07-02 18:15:53 -0600 | [diff] [blame] | 86 | /* enable FIFOs, auto clear Rx FIFO */ |
| 87 | writel(0x3, &uart->ufcon); |
| 88 | writel(0, &uart->umcon); |
| 89 | /* 8N1 */ |
| 90 | writel(0x3, &uart->ulcon); |
| 91 | /* No interrupts, no DMA, pure polling */ |
| 92 | writel(0x245, &uart->ucon); |
| 93 | } |
| 94 | |
Mark Kettenis | d520e1f | 2021-10-23 16:58:04 +0200 | [diff] [blame] | 95 | static void __maybe_unused s5p_serial_baud(struct s5p_uart *uart, u8 reg_width, |
| 96 | uint uclk, int baudrate) |
Simon Glass | 89ca935 | 2015-07-02 18:15:53 -0600 | [diff] [blame] | 97 | { |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 98 | u32 val; |
| 99 | |
Minkyu Kang | f70409a | 2010-08-24 15:51:55 +0900 | [diff] [blame] | 100 | val = uclk / baudrate; |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 101 | |
| 102 | writel(val / 16 - 1, &uart->ubrdiv); |
Minkyu Kang | 1628cfc | 2010-09-28 14:35:02 +0900 | [diff] [blame] | 103 | |
Minkyu Kang | e0617c6 | 2011-01-24 14:43:25 +0900 | [diff] [blame] | 104 | if (s5p_uart_divslot()) |
Minkyu Kang | 1628cfc | 2010-09-28 14:35:02 +0900 | [diff] [blame] | 105 | writew(udivslot[val % 16], &uart->rest.slot); |
Mark Kettenis | d520e1f | 2021-10-23 16:58:04 +0200 | [diff] [blame] | 106 | else if (reg_width == 4) |
| 107 | writel(val % 16, &uart->rest.value); |
Minkyu Kang | 1628cfc | 2010-09-28 14:35:02 +0900 | [diff] [blame] | 108 | else |
| 109 | writeb(val % 16, &uart->rest.value); |
Simon Glass | 89ca935 | 2015-07-02 18:15:53 -0600 | [diff] [blame] | 110 | } |
| 111 | |
Simon Glass | 7fb5739 | 2015-07-02 18:15:55 -0600 | [diff] [blame] | 112 | #ifndef CONFIG_SPL_BUILD |
Simon Glass | 89ca935 | 2015-07-02 18:15:53 -0600 | [diff] [blame] | 113 | int s5p_serial_setbrg(struct udevice *dev, int baudrate) |
| 114 | { |
Simon Glass | 0fd3d91 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 115 | struct s5p_serial_plat *plat = dev_get_plat(dev); |
Simon Glass | 89ca935 | 2015-07-02 18:15:53 -0600 | [diff] [blame] | 116 | struct s5p_uart *const uart = plat->reg; |
Thomas Abraham | cf75cdf | 2016-04-23 22:18:11 +0530 | [diff] [blame] | 117 | u32 uclk; |
| 118 | |
Mark Kettenis | 053827b | 2023-01-26 14:44:09 +0100 | [diff] [blame] | 119 | #if IS_ENABLED(CONFIG_CLK_EXYNOS) || IS_ENABLED(CONFIG_ARCH_APPLE) |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 120 | struct clk clk; |
Thomas Abraham | cf75cdf | 2016-04-23 22:18:11 +0530 | [diff] [blame] | 121 | u32 ret; |
| 122 | |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 123 | ret = clk_get_by_index(dev, 1, &clk); |
Thomas Abraham | cf75cdf | 2016-04-23 22:18:11 +0530 | [diff] [blame] | 124 | if (ret < 0) |
| 125 | return ret; |
Stephen Warren | 135aa95 | 2016-06-17 09:44:00 -0600 | [diff] [blame] | 126 | uclk = clk_get_rate(&clk); |
Thomas Abraham | cf75cdf | 2016-04-23 22:18:11 +0530 | [diff] [blame] | 127 | #else |
| 128 | uclk = get_uart_clk(plat->port_id); |
| 129 | #endif |
Simon Glass | 89ca935 | 2015-07-02 18:15:53 -0600 | [diff] [blame] | 130 | |
Mark Kettenis | d520e1f | 2021-10-23 16:58:04 +0200 | [diff] [blame] | 131 | s5p_serial_baud(uart, plat->reg_width, uclk, baudrate); |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 132 | |
| 133 | return 0; |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 134 | } |
| 135 | |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 136 | static int s5p_serial_probe(struct udevice *dev) |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 137 | { |
Simon Glass | 0fd3d91 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 138 | struct s5p_serial_plat *plat = dev_get_plat(dev); |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 139 | struct s5p_uart *const uart = plat->reg; |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 140 | |
Simon Glass | 89ca935 | 2015-07-02 18:15:53 -0600 | [diff] [blame] | 141 | s5p_serial_init(uart); |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 142 | |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 143 | return 0; |
| 144 | } |
| 145 | |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 146 | static int serial_err_check(const struct s5p_uart *const uart, int op) |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 147 | { |
Minkyu Kang | 9400322 | 2009-11-10 20:23:50 +0900 | [diff] [blame] | 148 | unsigned int mask; |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 149 | |
Minkyu Kang | 9400322 | 2009-11-10 20:23:50 +0900 | [diff] [blame] | 150 | /* |
| 151 | * UERSTAT |
| 152 | * Break Detect [3] |
| 153 | * Frame Err [2] : receive operation |
| 154 | * Parity Err [1] : receive operation |
| 155 | * Overrun Err [0] : receive operation |
| 156 | */ |
| 157 | if (op) |
| 158 | mask = 0x8; |
| 159 | else |
| 160 | mask = 0xf; |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 161 | |
Minkyu Kang | 9400322 | 2009-11-10 20:23:50 +0900 | [diff] [blame] | 162 | return readl(&uart->uerstat) & mask; |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 163 | } |
| 164 | |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 165 | static int s5p_serial_getc(struct udevice *dev) |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 166 | { |
Simon Glass | 0fd3d91 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 167 | struct s5p_serial_plat *plat = dev_get_plat(dev); |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 168 | struct s5p_uart *const uart = plat->reg; |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 169 | |
Mark Kettenis | d520e1f | 2021-10-23 16:58:04 +0200 | [diff] [blame] | 170 | if (!(readl(&uart->ufstat) & plat->rx_fifo_count_mask)) |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 171 | return -EAGAIN; |
Rajeshwari Shinde | d4ec8f0 | 2013-06-24 16:47:22 +0530 | [diff] [blame] | 172 | |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 173 | serial_err_check(uart, 0); |
Mark Kettenis | d520e1f | 2021-10-23 16:58:04 +0200 | [diff] [blame] | 174 | if (plat->reg_width == 4) |
| 175 | return (int)(readl(&uart->urxh) & 0xff); |
| 176 | else |
| 177 | return (int)(readb(&uart->urxh) & 0xff); |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 178 | } |
| 179 | |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 180 | static int s5p_serial_putc(struct udevice *dev, const char ch) |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 181 | { |
Simon Glass | 0fd3d91 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 182 | struct s5p_serial_plat *plat = dev_get_plat(dev); |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 183 | struct s5p_uart *const uart = plat->reg; |
Minkyu Kang | dd2c9e6 | 2009-10-01 17:20:28 +0900 | [diff] [blame] | 184 | |
Mark Kettenis | d520e1f | 2021-10-23 16:58:04 +0200 | [diff] [blame] | 185 | if (readl(&uart->ufstat) & plat->tx_fifo_full) |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 186 | return -EAGAIN; |
Rajeshwari Shinde | d4ec8f0 | 2013-06-24 16:47:22 +0530 | [diff] [blame] | 187 | |
Mark Kettenis | d520e1f | 2021-10-23 16:58:04 +0200 | [diff] [blame] | 188 | if (plat->reg_width == 4) |
| 189 | writel(ch, &uart->utxh); |
| 190 | else |
| 191 | writeb(ch, &uart->utxh); |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 192 | serial_err_check(uart, 1); |
Rajeshwari Shinde | d4ec8f0 | 2013-06-24 16:47:22 +0530 | [diff] [blame] | 193 | |
| 194 | return 0; |
| 195 | } |
Rajeshwari Shinde | d4ec8f0 | 2013-06-24 16:47:22 +0530 | [diff] [blame] | 196 | |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 197 | static int s5p_serial_pending(struct udevice *dev, bool input) |
Mike Frysinger | 6c768ca | 2011-04-29 18:03:29 +0000 | [diff] [blame] | 198 | { |
Simon Glass | 0fd3d91 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 199 | struct s5p_serial_plat *plat = dev_get_plat(dev); |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 200 | struct s5p_uart *const uart = plat->reg; |
| 201 | uint32_t ufstat = readl(&uart->ufstat); |
Rajeshwari Shinde | d4ec8f0 | 2013-06-24 16:47:22 +0530 | [diff] [blame] | 202 | |
Mark Kettenis | d520e1f | 2021-10-23 16:58:04 +0200 | [diff] [blame] | 203 | if (input) { |
| 204 | return (ufstat & plat->rx_fifo_count_mask) >> |
| 205 | plat->rx_fifo_count_shift; |
| 206 | } else { |
| 207 | return (ufstat & plat->tx_fifo_count_mask) >> |
| 208 | plat->tx_fifo_count_shift; |
| 209 | } |
Mike Frysinger | 6c768ca | 2011-04-29 18:03:29 +0000 | [diff] [blame] | 210 | } |
Marek Vasut | b498051 | 2012-09-12 19:39:57 +0200 | [diff] [blame] | 211 | |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 212 | static int s5p_serial_of_to_plat(struct udevice *dev) |
Marek Vasut | b498051 | 2012-09-12 19:39:57 +0200 | [diff] [blame] | 213 | { |
Simon Glass | 0fd3d91 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 214 | struct s5p_serial_plat *plat = dev_get_plat(dev); |
Mark Kettenis | d520e1f | 2021-10-23 16:58:04 +0200 | [diff] [blame] | 215 | const ulong port_type = dev_get_driver_data(dev); |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 216 | fdt_addr_t addr; |
| 217 | |
Masahiro Yamada | 2548493 | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 218 | addr = dev_read_addr(dev); |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 219 | if (addr == FDT_ADDR_T_NONE) |
| 220 | return -EINVAL; |
| 221 | |
| 222 | plat->reg = (struct s5p_uart *)addr; |
Mark Kettenis | d520e1f | 2021-10-23 16:58:04 +0200 | [diff] [blame] | 223 | plat->reg_width = dev_read_u32_default(dev, "reg-io-width", 1); |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 224 | plat->port_id = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), |
Simon Glass | 8b85dfc | 2020-12-16 21:20:07 -0700 | [diff] [blame] | 225 | "id", dev_seq(dev)); |
Mark Kettenis | d520e1f | 2021-10-23 16:58:04 +0200 | [diff] [blame] | 226 | |
| 227 | if (port_type == PORT_S5L) { |
| 228 | plat->rx_fifo_count_shift = S5L_RX_FIFO_COUNT_SHIFT; |
| 229 | plat->rx_fifo_count_mask = S5L_RX_FIFO_COUNT_MASK; |
| 230 | plat->rx_fifo_full = S5L_RX_FIFO_FULL; |
| 231 | plat->tx_fifo_count_shift = S5L_TX_FIFO_COUNT_SHIFT; |
| 232 | plat->tx_fifo_count_mask = S5L_TX_FIFO_COUNT_MASK; |
| 233 | plat->tx_fifo_full = S5L_TX_FIFO_FULL; |
| 234 | } else { |
| 235 | plat->rx_fifo_count_shift = S5P_RX_FIFO_COUNT_SHIFT; |
| 236 | plat->rx_fifo_count_mask = S5P_RX_FIFO_COUNT_MASK; |
| 237 | plat->rx_fifo_full = S5P_RX_FIFO_FULL; |
| 238 | plat->tx_fifo_count_shift = S5P_TX_FIFO_COUNT_SHIFT; |
| 239 | plat->tx_fifo_count_mask = S5P_TX_FIFO_COUNT_MASK; |
| 240 | plat->tx_fifo_full = S5P_TX_FIFO_FULL; |
| 241 | } |
| 242 | |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 243 | return 0; |
Marek Vasut | b498051 | 2012-09-12 19:39:57 +0200 | [diff] [blame] | 244 | } |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 245 | |
| 246 | static const struct dm_serial_ops s5p_serial_ops = { |
| 247 | .putc = s5p_serial_putc, |
| 248 | .pending = s5p_serial_pending, |
| 249 | .getc = s5p_serial_getc, |
| 250 | .setbrg = s5p_serial_setbrg, |
| 251 | }; |
| 252 | |
| 253 | static const struct udevice_id s5p_serial_ids[] = { |
Mark Kettenis | d520e1f | 2021-10-23 16:58:04 +0200 | [diff] [blame] | 254 | { .compatible = "samsung,exynos4210-uart", .data = PORT_S5P }, |
| 255 | { .compatible = "apple,s5l-uart", .data = PORT_S5L }, |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 256 | { } |
| 257 | }; |
| 258 | |
| 259 | U_BOOT_DRIVER(serial_s5p) = { |
| 260 | .name = "serial_s5p", |
| 261 | .id = UCLASS_SERIAL, |
| 262 | .of_match = s5p_serial_ids, |
Simon Glass | d1998a9 | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 263 | .of_to_plat = s5p_serial_of_to_plat, |
Simon Glass | 8a8d24b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 264 | .plat_auto = sizeof(struct s5p_serial_plat), |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 265 | .probe = s5p_serial_probe, |
| 266 | .ops = &s5p_serial_ops, |
Simon Glass | 73e256c | 2014-09-14 16:36:17 -0600 | [diff] [blame] | 267 | }; |
Simon Glass | 7fb5739 | 2015-07-02 18:15:55 -0600 | [diff] [blame] | 268 | #endif |
Simon Glass | bf6e702 | 2015-07-02 18:15:54 -0600 | [diff] [blame] | 269 | |
| 270 | #ifdef CONFIG_DEBUG_UART_S5P |
| 271 | |
| 272 | #include <debug_uart.h> |
| 273 | |
Simon Glass | 97b0597 | 2015-10-18 19:51:23 -0600 | [diff] [blame] | 274 | static inline void _debug_uart_init(void) |
Simon Glass | bf6e702 | 2015-07-02 18:15:54 -0600 | [diff] [blame] | 275 | { |
Dzmitry Sankouski | 85fcf94 | 2021-10-17 13:45:39 +0300 | [diff] [blame] | 276 | if (IS_ENABLED(CONFIG_DEBUG_UART_SKIP_INIT)) |
| 277 | return; |
| 278 | |
Pali Rohár | b62450c | 2022-05-27 22:15:24 +0200 | [diff] [blame] | 279 | struct s5p_uart *uart = (struct s5p_uart *)CONFIG_VAL(DEBUG_UART_BASE); |
Simon Glass | bf6e702 | 2015-07-02 18:15:54 -0600 | [diff] [blame] | 280 | |
| 281 | s5p_serial_init(uart); |
Mark Kettenis | 053827b | 2023-01-26 14:44:09 +0100 | [diff] [blame] | 282 | #if IS_ENABLED(CONFIG_ARCH_APPLE) |
Mark Kettenis | d520e1f | 2021-10-23 16:58:04 +0200 | [diff] [blame] | 283 | s5p_serial_baud(uart, 4, CONFIG_DEBUG_UART_CLOCK, CONFIG_BAUDRATE); |
| 284 | #else |
| 285 | s5p_serial_baud(uart, 1, CONFIG_DEBUG_UART_CLOCK, CONFIG_BAUDRATE); |
| 286 | #endif |
Simon Glass | bf6e702 | 2015-07-02 18:15:54 -0600 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | static inline void _debug_uart_putc(int ch) |
| 290 | { |
Pali Rohár | b62450c | 2022-05-27 22:15:24 +0200 | [diff] [blame] | 291 | struct s5p_uart *uart = (struct s5p_uart *)CONFIG_VAL(DEBUG_UART_BASE); |
Simon Glass | bf6e702 | 2015-07-02 18:15:54 -0600 | [diff] [blame] | 292 | |
Mark Kettenis | 053827b | 2023-01-26 14:44:09 +0100 | [diff] [blame] | 293 | #if IS_ENABLED(CONFIG_ARCH_APPLE) |
Mark Kettenis | d520e1f | 2021-10-23 16:58:04 +0200 | [diff] [blame] | 294 | while (readl(&uart->ufstat) & S5L_TX_FIFO_FULL); |
| 295 | writel(ch, &uart->utxh); |
| 296 | #else |
| 297 | while (readl(&uart->ufstat) & S5P_TX_FIFO_FULL); |
Simon Glass | bf6e702 | 2015-07-02 18:15:54 -0600 | [diff] [blame] | 298 | writeb(ch, &uart->utxh); |
Mark Kettenis | d520e1f | 2021-10-23 16:58:04 +0200 | [diff] [blame] | 299 | #endif |
Simon Glass | bf6e702 | 2015-07-02 18:15:54 -0600 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | DEBUG_UART_FUNCS |
| 303 | |
| 304 | #endif |