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