Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 2 | /* |
Vabhav Sharma | a8f78c6 | 2019-01-31 12:08:10 +0000 | [diff] [blame] | 3 | * Copyright 2019 NXP |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 4 | * Copyright 2013 Freescale Semiconductor, Inc. |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Tom Rini | 8c70baa | 2021-12-14 13:36:40 -0500 | [diff] [blame] | 7 | #include <clock_legacy.h> |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 8 | #include <clk.h> |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 9 | #include <dm.h> |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 10 | #include <fsl_lpuart.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 12 | #include <watchdog.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 13 | #include <asm/global_data.h> |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 14 | #include <asm/io.h> |
| 15 | #include <serial.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 16 | #include <dm/device_compat.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 17 | #include <linux/bitops.h> |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 18 | #include <linux/compiler.h> |
| 19 | #include <asm/arch/imx-regs.h> |
| 20 | #include <asm/arch/clock.h> |
| 21 | |
Bin Meng | a8cc172 | 2016-01-13 19:39:01 -0800 | [diff] [blame] | 22 | #define US1_TDRE (1 << 7) |
| 23 | #define US1_RDRF (1 << 5) |
| 24 | #define US1_OR (1 << 3) |
| 25 | #define UC2_TE (1 << 3) |
| 26 | #define UC2_RE (1 << 2) |
| 27 | #define CFIFO_TXFLUSH (1 << 7) |
| 28 | #define CFIFO_RXFLUSH (1 << 6) |
| 29 | #define SFIFO_RXOF (1 << 2) |
| 30 | #define SFIFO_RXUF (1 << 0) |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 31 | |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 32 | #define STAT_LBKDIF (1 << 31) |
| 33 | #define STAT_RXEDGIF (1 << 30) |
| 34 | #define STAT_TDRE (1 << 23) |
| 35 | #define STAT_RDRF (1 << 21) |
| 36 | #define STAT_IDLE (1 << 20) |
| 37 | #define STAT_OR (1 << 19) |
| 38 | #define STAT_NF (1 << 18) |
| 39 | #define STAT_FE (1 << 17) |
| 40 | #define STAT_PF (1 << 16) |
| 41 | #define STAT_MA1F (1 << 15) |
| 42 | #define STAT_MA2F (1 << 14) |
| 43 | #define STAT_FLAGS (STAT_LBKDIF | STAT_RXEDGIF | STAT_IDLE | STAT_OR | \ |
Bin Meng | a8cc172 | 2016-01-13 19:39:01 -0800 | [diff] [blame] | 44 | STAT_NF | STAT_FE | STAT_PF | STAT_MA1F | STAT_MA2F) |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 45 | |
| 46 | #define CTRL_TE (1 << 19) |
| 47 | #define CTRL_RE (1 << 18) |
| 48 | |
Ye Li | a2aedcb | 2018-10-18 14:28:32 +0200 | [diff] [blame] | 49 | #define FIFO_RXFLUSH BIT(14) |
| 50 | #define FIFO_TXFLUSH BIT(15) |
| 51 | #define FIFO_TXSIZE_MASK 0x70 |
| 52 | #define FIFO_TXSIZE_OFF 4 |
| 53 | #define FIFO_RXSIZE_MASK 0x7 |
| 54 | #define FIFO_RXSIZE_OFF 0 |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 55 | #define FIFO_TXFE 0x80 |
Giulio Benetti | 5eaa97e | 2020-01-10 15:51:43 +0100 | [diff] [blame] | 56 | #if defined(CONFIG_ARCH_IMX8) || defined(CONFIG_ARCH_IMXRT) |
Peng Fan | b7f9ea9 | 2018-10-18 14:28:31 +0200 | [diff] [blame] | 57 | #define FIFO_RXFE 0x08 |
| 58 | #else |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 59 | #define FIFO_RXFE 0x40 |
Peng Fan | b7f9ea9 | 2018-10-18 14:28:31 +0200 | [diff] [blame] | 60 | #endif |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 61 | |
Ye Li | a2aedcb | 2018-10-18 14:28:32 +0200 | [diff] [blame] | 62 | #define WATER_TXWATER_OFF 0 |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 63 | #define WATER_RXWATER_OFF 16 |
| 64 | |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 65 | DECLARE_GLOBAL_DATA_PTR; |
| 66 | |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 67 | #define LPUART_FLAG_REGMAP_32BIT_REG BIT(0) |
| 68 | #define LPUART_FLAG_REGMAP_ENDIAN_BIG BIT(1) |
| 69 | |
Peng Fan | dac2c94 | 2017-02-22 16:21:52 +0800 | [diff] [blame] | 70 | enum lpuart_devtype { |
| 71 | DEV_VF610 = 1, |
| 72 | DEV_LS1021A, |
Peng Fan | b7f9ea9 | 2018-10-18 14:28:31 +0200 | [diff] [blame] | 73 | DEV_MX7ULP, |
Giulio Benetti | 5eaa97e | 2020-01-10 15:51:43 +0100 | [diff] [blame] | 74 | DEV_IMX8, |
| 75 | DEV_IMXRT, |
Peng Fan | dac2c94 | 2017-02-22 16:21:52 +0800 | [diff] [blame] | 76 | }; |
| 77 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 78 | struct lpuart_serial_plat { |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 79 | void *reg; |
Peng Fan | dac2c94 | 2017-02-22 16:21:52 +0800 | [diff] [blame] | 80 | enum lpuart_devtype devtype; |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 81 | ulong flags; |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 82 | }; |
| 83 | |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 84 | static void lpuart_read32(u32 flags, u32 *addr, u32 *val) |
| 85 | { |
| 86 | if (flags & LPUART_FLAG_REGMAP_32BIT_REG) { |
| 87 | if (flags & LPUART_FLAG_REGMAP_ENDIAN_BIG) |
| 88 | *(u32 *)val = in_be32(addr); |
| 89 | else |
| 90 | *(u32 *)val = in_le32(addr); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | static void lpuart_write32(u32 flags, u32 *addr, u32 val) |
| 95 | { |
| 96 | if (flags & LPUART_FLAG_REGMAP_32BIT_REG) { |
| 97 | if (flags & LPUART_FLAG_REGMAP_ENDIAN_BIG) |
| 98 | out_be32(addr, val); |
| 99 | else |
| 100 | out_le32(addr, val); |
| 101 | } |
| 102 | } |
| 103 | |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 104 | u32 __weak get_lpuart_clk(void) |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 105 | { |
Tom Rini | 8c70baa | 2021-12-14 13:36:40 -0500 | [diff] [blame] | 106 | return get_board_sys_clk(); |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 107 | } |
| 108 | |
Ye Li | 86cf699 | 2019-07-11 03:33:34 +0000 | [diff] [blame] | 109 | #if CONFIG_IS_ENABLED(CLK) |
Peng Fan | eec6f38 | 2024-04-12 22:24:52 +0800 | [diff] [blame] | 110 | static int get_lpuart_clk_rate(struct udevice *dev, u32 *clk_rate) |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 111 | { |
Peng Fan | eec6f38 | 2024-04-12 22:24:52 +0800 | [diff] [blame] | 112 | struct lpuart_serial_plat *plat = dev_get_plat(dev); |
| 113 | struct clk clk; |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 114 | ulong rate; |
| 115 | int ret; |
Peng Fan | eec6f38 | 2024-04-12 22:24:52 +0800 | [diff] [blame] | 116 | char *name; |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 117 | |
Peng Fan | eec6f38 | 2024-04-12 22:24:52 +0800 | [diff] [blame] | 118 | if (plat->devtype == DEV_MX7ULP) |
| 119 | name = "ipg"; |
| 120 | else |
| 121 | name = "per"; |
| 122 | |
| 123 | ret = clk_get_by_name(dev, name, &clk); |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 124 | if (ret) { |
Peng Fan | eec6f38 | 2024-04-12 22:24:52 +0800 | [diff] [blame] | 125 | dev_err(dev, "Failed to get clk: %d\n", ret); |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 126 | return ret; |
| 127 | } |
| 128 | |
Peng Fan | eec6f38 | 2024-04-12 22:24:52 +0800 | [diff] [blame] | 129 | rate = clk_get_rate(&clk); |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 130 | if ((long)rate <= 0) { |
Peng Fan | eec6f38 | 2024-04-12 22:24:52 +0800 | [diff] [blame] | 131 | dev_err(dev, "Failed to get clk rate: %ld\n", (long)rate); |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 132 | return ret; |
| 133 | } |
Peng Fan | eec6f38 | 2024-04-12 22:24:52 +0800 | [diff] [blame] | 134 | *clk_rate = rate; |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 135 | return 0; |
| 136 | } |
| 137 | #else |
Peng Fan | eec6f38 | 2024-04-12 22:24:52 +0800 | [diff] [blame] | 138 | static inline int get_lpuart_clk_rate(struct udevice *dev, u32 *clk_rate) |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 139 | { return -ENOSYS; } |
| 140 | #endif |
| 141 | |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 142 | static bool is_lpuart32(struct udevice *dev) |
| 143 | { |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 144 | struct lpuart_serial_plat *plat = dev_get_plat(dev); |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 145 | |
| 146 | return plat->flags & LPUART_FLAG_REGMAP_32BIT_REG; |
| 147 | } |
| 148 | |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 149 | static void _lpuart_serial_setbrg(struct udevice *dev, |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 150 | int baudrate) |
| 151 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 152 | struct lpuart_serial_plat *plat = dev_get_plat(dev); |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 153 | struct lpuart_fsl *base = plat->reg; |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 154 | u32 clk; |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 155 | u16 sbr; |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 156 | int ret; |
| 157 | |
Ye Li | 86cf699 | 2019-07-11 03:33:34 +0000 | [diff] [blame] | 158 | if (CONFIG_IS_ENABLED(CLK)) { |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 159 | ret = get_lpuart_clk_rate(dev, &clk); |
| 160 | if (ret) |
| 161 | return; |
| 162 | } else { |
| 163 | clk = get_lpuart_clk(); |
| 164 | } |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 165 | |
Bin Meng | 6338fbd | 2016-01-13 19:39:03 -0800 | [diff] [blame] | 166 | sbr = (u16)(clk / (16 * baudrate)); |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 167 | |
Bin Meng | a8cc172 | 2016-01-13 19:39:01 -0800 | [diff] [blame] | 168 | /* place adjustment later - n/32 BRFA */ |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 169 | __raw_writeb(sbr >> 8, &base->ubdh); |
| 170 | __raw_writeb(sbr & 0xff, &base->ubdl); |
| 171 | } |
| 172 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 173 | static int _lpuart_serial_getc(struct lpuart_serial_plat *plat) |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 174 | { |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 175 | struct lpuart_fsl *base = plat->reg; |
Pali Rohár | 241f12d | 2022-12-11 00:31:21 +0100 | [diff] [blame] | 176 | if (!(__raw_readb(&base->us1) & (US1_RDRF | US1_OR))) |
| 177 | return -EAGAIN; |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 178 | |
Stefan Agner | 2448291 | 2014-08-19 17:54:27 +0200 | [diff] [blame] | 179 | barrier(); |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 180 | |
| 181 | return __raw_readb(&base->ud); |
| 182 | } |
| 183 | |
Pali Rohár | 241f12d | 2022-12-11 00:31:21 +0100 | [diff] [blame] | 184 | static int _lpuart_serial_putc(struct lpuart_serial_plat *plat, |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 185 | const char c) |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 186 | { |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 187 | struct lpuart_fsl *base = plat->reg; |
| 188 | |
Pali Rohár | 241f12d | 2022-12-11 00:31:21 +0100 | [diff] [blame] | 189 | if (!(__raw_readb(&base->us1) & US1_TDRE)) |
| 190 | return -EAGAIN; |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 191 | |
| 192 | __raw_writeb(c, &base->ud); |
Pali Rohár | 241f12d | 2022-12-11 00:31:21 +0100 | [diff] [blame] | 193 | return 0; |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 194 | } |
| 195 | |
Bin Meng | a8cc172 | 2016-01-13 19:39:01 -0800 | [diff] [blame] | 196 | /* Test whether a character is in the RX buffer */ |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 197 | static int _lpuart_serial_tstc(struct lpuart_serial_plat *plat) |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 198 | { |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 199 | struct lpuart_fsl *base = plat->reg; |
| 200 | |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 201 | if (__raw_readb(&base->urcfifo) == 0) |
| 202 | return 0; |
| 203 | |
| 204 | return 1; |
| 205 | } |
| 206 | |
| 207 | /* |
| 208 | * Initialise the serial port with the given baudrate. The settings |
| 209 | * are always 8 data bits, no parity, 1 stop bit, no start bits. |
| 210 | */ |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 211 | static int _lpuart_serial_init(struct udevice *dev) |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 212 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 213 | struct lpuart_serial_plat *plat = dev_get_plat(dev); |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 214 | struct lpuart_fsl *base = (struct lpuart_fsl *)plat->reg; |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 215 | u8 ctrl; |
| 216 | |
| 217 | ctrl = __raw_readb(&base->uc2); |
| 218 | ctrl &= ~UC2_RE; |
| 219 | ctrl &= ~UC2_TE; |
| 220 | __raw_writeb(ctrl, &base->uc2); |
| 221 | |
| 222 | __raw_writeb(0, &base->umodem); |
| 223 | __raw_writeb(0, &base->uc1); |
| 224 | |
Stefan Agner | 190f1d2 | 2014-08-19 17:54:28 +0200 | [diff] [blame] | 225 | /* Disable FIFO and flush buffer */ |
| 226 | __raw_writeb(0x0, &base->upfifo); |
| 227 | __raw_writeb(0x0, &base->utwfifo); |
| 228 | __raw_writeb(0x1, &base->urwfifo); |
| 229 | __raw_writeb(CFIFO_TXFLUSH | CFIFO_RXFLUSH, &base->ucfifo); |
| 230 | |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 231 | /* provide data bits, parity, stop bit, etc */ |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 232 | _lpuart_serial_setbrg(dev, gd->baudrate); |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 233 | |
| 234 | __raw_writeb(UC2_RE | UC2_TE, &base->uc2); |
| 235 | |
| 236 | return 0; |
| 237 | } |
| 238 | |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 239 | static void _lpuart32_serial_setbrg_7ulp(struct udevice *dev, |
Peng Fan | dac2c94 | 2017-02-22 16:21:52 +0800 | [diff] [blame] | 240 | int baudrate) |
| 241 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 242 | struct lpuart_serial_plat *plat = dev_get_plat(dev); |
Peng Fan | dac2c94 | 2017-02-22 16:21:52 +0800 | [diff] [blame] | 243 | struct lpuart_fsl_reg32 *base = plat->reg; |
| 244 | u32 sbr, osr, baud_diff, tmp_osr, tmp_sbr, tmp_diff, tmp; |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 245 | u32 clk; |
| 246 | int ret; |
| 247 | |
Ye Li | 86cf699 | 2019-07-11 03:33:34 +0000 | [diff] [blame] | 248 | if (CONFIG_IS_ENABLED(CLK)) { |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 249 | ret = get_lpuart_clk_rate(dev, &clk); |
| 250 | if (ret) |
| 251 | return; |
| 252 | } else { |
| 253 | clk = get_lpuart_clk(); |
| 254 | } |
Peng Fan | dac2c94 | 2017-02-22 16:21:52 +0800 | [diff] [blame] | 255 | |
| 256 | baud_diff = baudrate; |
| 257 | osr = 0; |
| 258 | sbr = 0; |
| 259 | |
| 260 | for (tmp_osr = 4; tmp_osr <= 32; tmp_osr++) { |
| 261 | tmp_sbr = (clk / (baudrate * tmp_osr)); |
| 262 | |
| 263 | if (tmp_sbr == 0) |
| 264 | tmp_sbr = 1; |
| 265 | |
| 266 | /*calculate difference in actual buad w/ current values */ |
| 267 | tmp_diff = (clk / (tmp_osr * tmp_sbr)); |
| 268 | tmp_diff = tmp_diff - baudrate; |
| 269 | |
| 270 | /* select best values between sbr and sbr+1 */ |
| 271 | if (tmp_diff > (baudrate - (clk / (tmp_osr * (tmp_sbr + 1))))) { |
| 272 | tmp_diff = baudrate - (clk / (tmp_osr * (tmp_sbr + 1))); |
| 273 | tmp_sbr++; |
| 274 | } |
| 275 | |
| 276 | if (tmp_diff <= baud_diff) { |
| 277 | baud_diff = tmp_diff; |
| 278 | osr = tmp_osr; |
| 279 | sbr = tmp_sbr; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | /* |
| 284 | * TODO: handle buadrate outside acceptable rate |
| 285 | * if (baudDiff > ((config->baudRate_Bps / 100) * 3)) |
| 286 | * { |
| 287 | * Unacceptable baud rate difference of more than 3% |
| 288 | * return kStatus_LPUART_BaudrateNotSupport; |
| 289 | * } |
| 290 | */ |
| 291 | tmp = in_le32(&base->baud); |
| 292 | |
| 293 | if ((osr > 3) && (osr < 8)) |
| 294 | tmp |= LPUART_BAUD_BOTHEDGE_MASK; |
| 295 | |
| 296 | tmp &= ~LPUART_BAUD_OSR_MASK; |
| 297 | tmp |= LPUART_BAUD_OSR(osr-1); |
| 298 | |
| 299 | tmp &= ~LPUART_BAUD_SBR_MASK; |
| 300 | tmp |= LPUART_BAUD_SBR(sbr); |
| 301 | |
| 302 | /* explicitly disable 10 bit mode & set 1 stop bit */ |
| 303 | tmp &= ~(LPUART_BAUD_M10_MASK | LPUART_BAUD_SBNS_MASK); |
| 304 | |
| 305 | out_le32(&base->baud, tmp); |
| 306 | } |
| 307 | |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 308 | static void _lpuart32_serial_setbrg(struct udevice *dev, |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 309 | int baudrate) |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 310 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 311 | struct lpuart_serial_plat *plat = dev_get_plat(dev); |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 312 | struct lpuart_fsl_reg32 *base = plat->reg; |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 313 | u32 clk; |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 314 | u32 sbr; |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 315 | int ret; |
| 316 | |
Ye Li | 86cf699 | 2019-07-11 03:33:34 +0000 | [diff] [blame] | 317 | if (CONFIG_IS_ENABLED(CLK)) { |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 318 | ret = get_lpuart_clk_rate(dev, &clk); |
| 319 | if (ret) |
| 320 | return; |
| 321 | } else { |
| 322 | clk = get_lpuart_clk(); |
| 323 | } |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 324 | |
Bin Meng | 6338fbd | 2016-01-13 19:39:03 -0800 | [diff] [blame] | 325 | sbr = (clk / (16 * baudrate)); |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 326 | |
Bin Meng | a8cc172 | 2016-01-13 19:39:01 -0800 | [diff] [blame] | 327 | /* place adjustment later - n/32 BRFA */ |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 328 | lpuart_write32(plat->flags, &base->baud, sbr); |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 329 | } |
| 330 | |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 331 | static int _lpuart32_serial_getc(struct lpuart_serial_plat *plat) |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 332 | { |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 333 | struct lpuart_fsl_reg32 *base = plat->reg; |
Peng Fan | dac2c94 | 2017-02-22 16:21:52 +0800 | [diff] [blame] | 334 | u32 stat, val; |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 335 | |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 336 | lpuart_read32(plat->flags, &base->stat, &stat); |
Pali Rohár | 241f12d | 2022-12-11 00:31:21 +0100 | [diff] [blame] | 337 | if ((stat & STAT_RDRF) == 0) { |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 338 | lpuart_write32(plat->flags, &base->stat, STAT_FLAGS); |
Pali Rohár | 241f12d | 2022-12-11 00:31:21 +0100 | [diff] [blame] | 339 | return -EAGAIN; |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 340 | } |
| 341 | |
Peng Fan | dac2c94 | 2017-02-22 16:21:52 +0800 | [diff] [blame] | 342 | lpuart_read32(plat->flags, &base->data, &val); |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 343 | |
Sriram Dash | 32cf46c | 2018-01-10 11:57:14 +0530 | [diff] [blame] | 344 | lpuart_read32(plat->flags, &base->stat, &stat); |
| 345 | if (stat & STAT_OR) |
| 346 | lpuart_write32(plat->flags, &base->stat, STAT_OR); |
Peng Fan | dac2c94 | 2017-02-22 16:21:52 +0800 | [diff] [blame] | 347 | |
| 348 | return val & 0x3ff; |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 349 | } |
| 350 | |
Pali Rohár | 241f12d | 2022-12-11 00:31:21 +0100 | [diff] [blame] | 351 | static int _lpuart32_serial_putc(struct lpuart_serial_plat *plat, |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 352 | const char c) |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 353 | { |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 354 | struct lpuart_fsl_reg32 *base = plat->reg; |
| 355 | u32 stat; |
| 356 | |
Pali Rohár | 241f12d | 2022-12-11 00:31:21 +0100 | [diff] [blame] | 357 | lpuart_read32(plat->flags, &base->stat, &stat); |
| 358 | if (!(stat & STAT_TDRE)) |
| 359 | return -EAGAIN; |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 360 | |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 361 | lpuart_write32(plat->flags, &base->data, c); |
Pali Rohár | 241f12d | 2022-12-11 00:31:21 +0100 | [diff] [blame] | 362 | return 0; |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 363 | } |
| 364 | |
Bin Meng | a8cc172 | 2016-01-13 19:39:01 -0800 | [diff] [blame] | 365 | /* Test whether a character is in the RX buffer */ |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 366 | static int _lpuart32_serial_tstc(struct lpuart_serial_plat *plat) |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 367 | { |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 368 | struct lpuart_fsl_reg32 *base = plat->reg; |
| 369 | u32 water; |
| 370 | |
| 371 | lpuart_read32(plat->flags, &base->water, &water); |
| 372 | |
| 373 | if ((water >> 24) == 0) |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 374 | return 0; |
| 375 | |
| 376 | return 1; |
| 377 | } |
| 378 | |
| 379 | /* |
| 380 | * Initialise the serial port with the given baudrate. The settings |
| 381 | * are always 8 data bits, no parity, 1 stop bit, no start bits. |
| 382 | */ |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 383 | static int _lpuart32_serial_init(struct udevice *dev) |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 384 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 385 | struct lpuart_serial_plat *plat = dev_get_plat(dev); |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 386 | struct lpuart_fsl_reg32 *base = (struct lpuart_fsl_reg32 *)plat->reg; |
Ye Li | a2aedcb | 2018-10-18 14:28:32 +0200 | [diff] [blame] | 387 | u32 val, tx_fifo_size; |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 388 | |
Ye Li | a2aedcb | 2018-10-18 14:28:32 +0200 | [diff] [blame] | 389 | lpuart_read32(plat->flags, &base->ctrl, &val); |
| 390 | val &= ~CTRL_RE; |
| 391 | val &= ~CTRL_TE; |
| 392 | lpuart_write32(plat->flags, &base->ctrl, val); |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 393 | |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 394 | lpuart_write32(plat->flags, &base->modir, 0); |
Ye Li | a2aedcb | 2018-10-18 14:28:32 +0200 | [diff] [blame] | 395 | |
| 396 | lpuart_read32(plat->flags, &base->fifo, &val); |
| 397 | tx_fifo_size = (val & FIFO_TXSIZE_MASK) >> FIFO_TXSIZE_OFF; |
| 398 | /* Set the TX water to half of FIFO size */ |
| 399 | if (tx_fifo_size > 1) |
| 400 | tx_fifo_size = tx_fifo_size >> 1; |
| 401 | |
| 402 | /* Set RX water to 0, to be triggered by any receive data */ |
| 403 | lpuart_write32(plat->flags, &base->water, |
| 404 | (tx_fifo_size << WATER_TXWATER_OFF)); |
| 405 | |
| 406 | /* Enable TX and RX FIFO */ |
| 407 | val |= (FIFO_TXFE | FIFO_RXFE | FIFO_TXFLUSH | FIFO_RXFLUSH); |
| 408 | lpuart_write32(plat->flags, &base->fifo, val); |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 409 | |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 410 | lpuart_write32(plat->flags, &base->match, 0); |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 411 | |
Giulio Benetti | 5eaa97e | 2020-01-10 15:51:43 +0100 | [diff] [blame] | 412 | if (plat->devtype == DEV_MX7ULP || plat->devtype == DEV_IMX8 || |
| 413 | plat->devtype == DEV_IMXRT) { |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 414 | _lpuart32_serial_setbrg_7ulp(dev, gd->baudrate); |
Peng Fan | dac2c94 | 2017-02-22 16:21:52 +0800 | [diff] [blame] | 415 | } else { |
| 416 | /* provide data bits, parity, stop bit, etc */ |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 417 | _lpuart32_serial_setbrg(dev, gd->baudrate); |
Peng Fan | dac2c94 | 2017-02-22 16:21:52 +0800 | [diff] [blame] | 418 | } |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 419 | |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 420 | lpuart_write32(plat->flags, &base->ctrl, CTRL_RE | CTRL_TE); |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 421 | |
| 422 | return 0; |
| 423 | } |
| 424 | |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 425 | static int lpuart_serial_setbrg(struct udevice *dev, int baudrate) |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 426 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 427 | struct lpuart_serial_plat *plat = dev_get_plat(dev); |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 428 | |
Peng Fan | dac2c94 | 2017-02-22 16:21:52 +0800 | [diff] [blame] | 429 | if (is_lpuart32(dev)) { |
Giulio Benetti | 5eaa97e | 2020-01-10 15:51:43 +0100 | [diff] [blame] | 430 | if (plat->devtype == DEV_MX7ULP || plat->devtype == DEV_IMX8 || |
| 431 | plat->devtype == DEV_IMXRT) |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 432 | _lpuart32_serial_setbrg_7ulp(dev, baudrate); |
Peng Fan | dac2c94 | 2017-02-22 16:21:52 +0800 | [diff] [blame] | 433 | else |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 434 | _lpuart32_serial_setbrg(dev, baudrate); |
Peng Fan | dac2c94 | 2017-02-22 16:21:52 +0800 | [diff] [blame] | 435 | } else { |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 436 | _lpuart_serial_setbrg(dev, baudrate); |
Peng Fan | dac2c94 | 2017-02-22 16:21:52 +0800 | [diff] [blame] | 437 | } |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 438 | |
| 439 | return 0; |
| 440 | } |
| 441 | |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 442 | static int lpuart_serial_getc(struct udevice *dev) |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 443 | { |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 444 | struct lpuart_serial_plat *plat = dev_get_plat(dev); |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 445 | |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 446 | if (is_lpuart32(dev)) |
| 447 | return _lpuart32_serial_getc(plat); |
| 448 | |
| 449 | return _lpuart_serial_getc(plat); |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 450 | } |
| 451 | |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 452 | static int lpuart_serial_putc(struct udevice *dev, const char c) |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 453 | { |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 454 | struct lpuart_serial_plat *plat = dev_get_plat(dev); |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 455 | |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 456 | if (is_lpuart32(dev)) |
Pali Rohár | 241f12d | 2022-12-11 00:31:21 +0100 | [diff] [blame] | 457 | return _lpuart32_serial_putc(plat, c); |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 458 | |
Pali Rohár | 241f12d | 2022-12-11 00:31:21 +0100 | [diff] [blame] | 459 | return _lpuart_serial_putc(plat, c); |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 460 | } |
| 461 | |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 462 | static int lpuart_serial_pending(struct udevice *dev, bool input) |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 463 | { |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 464 | struct lpuart_serial_plat *plat = dev_get_plat(dev); |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 465 | struct lpuart_fsl *reg = plat->reg; |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 466 | struct lpuart_fsl_reg32 *reg32 = plat->reg; |
| 467 | u32 stat; |
| 468 | |
| 469 | if (is_lpuart32(dev)) { |
| 470 | if (input) { |
| 471 | return _lpuart32_serial_tstc(plat); |
| 472 | } else { |
| 473 | lpuart_read32(plat->flags, ®32->stat, &stat); |
| 474 | return stat & STAT_TDRE ? 0 : 1; |
| 475 | } |
| 476 | } |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 477 | |
| 478 | if (input) |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 479 | return _lpuart_serial_tstc(plat); |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 480 | else |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 481 | return __raw_readb(®->us1) & US1_TDRE ? 0 : 1; |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 482 | } |
| 483 | |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 484 | static int lpuart_serial_probe(struct udevice *dev) |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 485 | { |
Giulio Benetti | 0ad8b9c | 2020-01-10 15:47:05 +0100 | [diff] [blame] | 486 | #if CONFIG_IS_ENABLED(CLK) |
Peng Fan | eec6f38 | 2024-04-12 22:24:52 +0800 | [diff] [blame] | 487 | struct lpuart_serial_plat *plat = dev_get_plat(dev); |
Giulio Benetti | 0ad8b9c | 2020-01-10 15:47:05 +0100 | [diff] [blame] | 488 | struct clk per_clk; |
Ye Li | 3759c0a | 2023-07-25 10:08:55 +0200 | [diff] [blame] | 489 | struct clk ipg_clk; |
Giulio Benetti | 0ad8b9c | 2020-01-10 15:47:05 +0100 | [diff] [blame] | 490 | int ret; |
| 491 | |
Peng Fan | eec6f38 | 2024-04-12 22:24:52 +0800 | [diff] [blame] | 492 | if (plat->devtype != DEV_MX7ULP) { |
| 493 | ret = clk_get_by_name(dev, "per", &per_clk); |
| 494 | if (!ret) { |
| 495 | ret = clk_enable(&per_clk); |
| 496 | if (ret) { |
| 497 | dev_err(dev, "Failed to enable per clk: %d\n", ret); |
| 498 | return ret; |
| 499 | } |
| 500 | } else { |
| 501 | debug("%s: Failed to get per clk: %d\n", __func__, ret); |
Giulio Benetti | 0ad8b9c | 2020-01-10 15:47:05 +0100 | [diff] [blame] | 502 | } |
Giulio Benetti | 0ad8b9c | 2020-01-10 15:47:05 +0100 | [diff] [blame] | 503 | } |
Ye Li | 3759c0a | 2023-07-25 10:08:55 +0200 | [diff] [blame] | 504 | |
| 505 | ret = clk_get_by_name(dev, "ipg", &ipg_clk); |
| 506 | if (!ret) { |
| 507 | ret = clk_enable(&ipg_clk); |
| 508 | if (ret) { |
| 509 | dev_err(dev, "Failed to enable ipg clk: %d\n", ret); |
| 510 | return ret; |
| 511 | } |
| 512 | } else { |
| 513 | debug("%s: Failed to get ipg clk: %d\n", __func__, ret); |
| 514 | } |
Giulio Benetti | 0ad8b9c | 2020-01-10 15:47:05 +0100 | [diff] [blame] | 515 | #endif |
| 516 | |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 517 | if (is_lpuart32(dev)) |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 518 | return _lpuart32_serial_init(dev); |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 519 | else |
Peng Fan | 68e4563 | 2018-10-19 00:26:23 +0200 | [diff] [blame] | 520 | return _lpuart_serial_init(dev); |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 521 | } |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 522 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 523 | static int lpuart_serial_of_to_plat(struct udevice *dev) |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 524 | { |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 525 | struct lpuart_serial_plat *plat = dev_get_plat(dev); |
Peng Fan | dac2c94 | 2017-02-22 16:21:52 +0800 | [diff] [blame] | 526 | const void *blob = gd->fdt_blob; |
Simon Glass | 7a49443 | 2017-05-17 17:18:09 -0600 | [diff] [blame] | 527 | int node = dev_of_offset(dev); |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 528 | fdt_addr_t addr; |
| 529 | |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 530 | addr = dev_read_addr(dev); |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 531 | if (addr == FDT_ADDR_T_NONE) |
| 532 | return -EINVAL; |
| 533 | |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 534 | plat->reg = (void *)addr; |
| 535 | plat->flags = dev_get_driver_data(dev); |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 536 | |
Vabhav Sharma | a8f78c6 | 2019-01-31 12:08:10 +0000 | [diff] [blame] | 537 | if (fdtdec_get_bool(blob, node, "little-endian")) |
| 538 | plat->flags &= ~LPUART_FLAG_REGMAP_ENDIAN_BIG; |
| 539 | |
Peng Fan | dac2c94 | 2017-02-22 16:21:52 +0800 | [diff] [blame] | 540 | if (!fdt_node_check_compatible(blob, node, "fsl,ls1021a-lpuart")) |
| 541 | plat->devtype = DEV_LS1021A; |
| 542 | else if (!fdt_node_check_compatible(blob, node, "fsl,imx7ulp-lpuart")) |
| 543 | plat->devtype = DEV_MX7ULP; |
| 544 | else if (!fdt_node_check_compatible(blob, node, "fsl,vf610-lpuart")) |
| 545 | plat->devtype = DEV_VF610; |
Peng Fan | b7f9ea9 | 2018-10-18 14:28:31 +0200 | [diff] [blame] | 546 | else if (!fdt_node_check_compatible(blob, node, "fsl,imx8qm-lpuart")) |
| 547 | plat->devtype = DEV_IMX8; |
Giulio Benetti | 5eaa97e | 2020-01-10 15:51:43 +0100 | [diff] [blame] | 548 | else if (!fdt_node_check_compatible(blob, node, "fsl,imxrt-lpuart")) |
| 549 | plat->devtype = DEV_IMXRT; |
Peng Fan | dac2c94 | 2017-02-22 16:21:52 +0800 | [diff] [blame] | 550 | |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 551 | return 0; |
| 552 | } |
| 553 | |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 554 | static const struct dm_serial_ops lpuart_serial_ops = { |
| 555 | .putc = lpuart_serial_putc, |
| 556 | .pending = lpuart_serial_pending, |
| 557 | .getc = lpuart_serial_getc, |
| 558 | .setbrg = lpuart_serial_setbrg, |
| 559 | }; |
| 560 | |
| 561 | static const struct udevice_id lpuart_serial_ids[] = { |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 562 | { .compatible = "fsl,ls1021a-lpuart", .data = |
| 563 | LPUART_FLAG_REGMAP_32BIT_REG | LPUART_FLAG_REGMAP_ENDIAN_BIG }, |
Michael Walle | b285de4 | 2021-10-13 18:14:19 +0200 | [diff] [blame] | 564 | { .compatible = "fsl,ls1028a-lpuart", |
| 565 | .data = LPUART_FLAG_REGMAP_32BIT_REG }, |
Peng Fan | dac2c94 | 2017-02-22 16:21:52 +0800 | [diff] [blame] | 566 | { .compatible = "fsl,imx7ulp-lpuart", |
| 567 | .data = LPUART_FLAG_REGMAP_32BIT_REG }, |
Peng Fan | 836a6cc | 2017-02-22 16:21:51 +0800 | [diff] [blame] | 568 | { .compatible = "fsl,vf610-lpuart"}, |
Peng Fan | b7f9ea9 | 2018-10-18 14:28:31 +0200 | [diff] [blame] | 569 | { .compatible = "fsl,imx8qm-lpuart", |
| 570 | .data = LPUART_FLAG_REGMAP_32BIT_REG }, |
Giulio Benetti | 5eaa97e | 2020-01-10 15:51:43 +0100 | [diff] [blame] | 571 | { .compatible = "fsl,imxrt-lpuart", |
| 572 | .data = LPUART_FLAG_REGMAP_32BIT_REG }, |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 573 | { } |
| 574 | }; |
| 575 | |
| 576 | U_BOOT_DRIVER(serial_lpuart) = { |
| 577 | .name = "serial_lpuart", |
| 578 | .id = UCLASS_SERIAL, |
| 579 | .of_match = lpuart_serial_ids, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 580 | .of_to_plat = lpuart_serial_of_to_plat, |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 581 | .plat_auto = sizeof(struct lpuart_serial_plat), |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 582 | .probe = lpuart_serial_probe, |
| 583 | .ops = &lpuart_serial_ops, |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 584 | }; |