Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Freescale Semiconductor, Inc. |
| 3 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 8 | #include <dm.h> |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 9 | #include <watchdog.h> |
| 10 | #include <asm/io.h> |
| 11 | #include <serial.h> |
| 12 | #include <linux/compiler.h> |
| 13 | #include <asm/arch/imx-regs.h> |
| 14 | #include <asm/arch/clock.h> |
| 15 | |
Bin Meng | a8cc172 | 2016-01-13 19:39:01 -0800 | [diff] [blame] | 16 | #define US1_TDRE (1 << 7) |
| 17 | #define US1_RDRF (1 << 5) |
| 18 | #define US1_OR (1 << 3) |
| 19 | #define UC2_TE (1 << 3) |
| 20 | #define UC2_RE (1 << 2) |
| 21 | #define CFIFO_TXFLUSH (1 << 7) |
| 22 | #define CFIFO_RXFLUSH (1 << 6) |
| 23 | #define SFIFO_RXOF (1 << 2) |
| 24 | #define SFIFO_RXUF (1 << 0) |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 25 | |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 26 | #define STAT_LBKDIF (1 << 31) |
| 27 | #define STAT_RXEDGIF (1 << 30) |
| 28 | #define STAT_TDRE (1 << 23) |
| 29 | #define STAT_RDRF (1 << 21) |
| 30 | #define STAT_IDLE (1 << 20) |
| 31 | #define STAT_OR (1 << 19) |
| 32 | #define STAT_NF (1 << 18) |
| 33 | #define STAT_FE (1 << 17) |
| 34 | #define STAT_PF (1 << 16) |
| 35 | #define STAT_MA1F (1 << 15) |
| 36 | #define STAT_MA2F (1 << 14) |
| 37 | #define STAT_FLAGS (STAT_LBKDIF | STAT_RXEDGIF | STAT_IDLE | STAT_OR | \ |
Bin Meng | a8cc172 | 2016-01-13 19:39:01 -0800 | [diff] [blame] | 38 | STAT_NF | STAT_FE | STAT_PF | STAT_MA1F | STAT_MA2F) |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 39 | |
| 40 | #define CTRL_TE (1 << 19) |
| 41 | #define CTRL_RE (1 << 18) |
| 42 | |
| 43 | #define FIFO_TXFE 0x80 |
| 44 | #define FIFO_RXFE 0x40 |
| 45 | |
| 46 | #define WATER_TXWATER_OFF 1 |
| 47 | #define WATER_RXWATER_OFF 16 |
| 48 | |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 49 | DECLARE_GLOBAL_DATA_PTR; |
| 50 | |
| 51 | struct lpuart_fsl *base = (struct lpuart_fsl *)LPUART_BASE; |
| 52 | |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 53 | struct lpuart_serial_platdata { |
| 54 | struct lpuart_fsl *reg; |
| 55 | }; |
| 56 | |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 57 | #ifndef CONFIG_LPUART_32B_REG |
Bin Meng | 6338fbd | 2016-01-13 19:39:03 -0800 | [diff] [blame] | 58 | static void _lpuart_serial_setbrg(struct lpuart_fsl *base, int baudrate) |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 59 | { |
| 60 | u32 clk = mxc_get_clock(MXC_UART_CLK); |
| 61 | u16 sbr; |
| 62 | |
Bin Meng | 6338fbd | 2016-01-13 19:39:03 -0800 | [diff] [blame] | 63 | sbr = (u16)(clk / (16 * baudrate)); |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 64 | |
Bin Meng | a8cc172 | 2016-01-13 19:39:01 -0800 | [diff] [blame] | 65 | /* place adjustment later - n/32 BRFA */ |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 66 | __raw_writeb(sbr >> 8, &base->ubdh); |
| 67 | __raw_writeb(sbr & 0xff, &base->ubdl); |
| 68 | } |
| 69 | |
Bin Meng | 6338fbd | 2016-01-13 19:39:03 -0800 | [diff] [blame] | 70 | static int _lpuart_serial_getc(struct lpuart_fsl *base) |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 71 | { |
Stefan Agner | 2448291 | 2014-08-19 17:54:27 +0200 | [diff] [blame] | 72 | while (!(__raw_readb(&base->us1) & (US1_RDRF | US1_OR))) |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 73 | WATCHDOG_RESET(); |
| 74 | |
Stefan Agner | 2448291 | 2014-08-19 17:54:27 +0200 | [diff] [blame] | 75 | barrier(); |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 76 | |
| 77 | return __raw_readb(&base->ud); |
| 78 | } |
| 79 | |
Bin Meng | 6338fbd | 2016-01-13 19:39:03 -0800 | [diff] [blame] | 80 | static void _lpuart_serial_putc(struct lpuart_fsl *base, const char c) |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 81 | { |
| 82 | if (c == '\n') |
Bin Meng | 6338fbd | 2016-01-13 19:39:03 -0800 | [diff] [blame] | 83 | _lpuart_serial_putc(base, '\r'); |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 84 | |
| 85 | while (!(__raw_readb(&base->us1) & US1_TDRE)) |
| 86 | WATCHDOG_RESET(); |
| 87 | |
| 88 | __raw_writeb(c, &base->ud); |
| 89 | } |
| 90 | |
Bin Meng | a8cc172 | 2016-01-13 19:39:01 -0800 | [diff] [blame] | 91 | /* Test whether a character is in the RX buffer */ |
Bin Meng | 6338fbd | 2016-01-13 19:39:03 -0800 | [diff] [blame] | 92 | static int _lpuart_serial_tstc(struct lpuart_fsl *base) |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 93 | { |
| 94 | if (__raw_readb(&base->urcfifo) == 0) |
| 95 | return 0; |
| 96 | |
| 97 | return 1; |
| 98 | } |
| 99 | |
| 100 | /* |
| 101 | * Initialise the serial port with the given baudrate. The settings |
| 102 | * are always 8 data bits, no parity, 1 stop bit, no start bits. |
| 103 | */ |
Bin Meng | 6338fbd | 2016-01-13 19:39:03 -0800 | [diff] [blame] | 104 | static int _lpuart_serial_init(struct lpuart_fsl *base) |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 105 | { |
| 106 | u8 ctrl; |
| 107 | |
| 108 | ctrl = __raw_readb(&base->uc2); |
| 109 | ctrl &= ~UC2_RE; |
| 110 | ctrl &= ~UC2_TE; |
| 111 | __raw_writeb(ctrl, &base->uc2); |
| 112 | |
| 113 | __raw_writeb(0, &base->umodem); |
| 114 | __raw_writeb(0, &base->uc1); |
| 115 | |
Stefan Agner | 190f1d2 | 2014-08-19 17:54:28 +0200 | [diff] [blame] | 116 | /* Disable FIFO and flush buffer */ |
| 117 | __raw_writeb(0x0, &base->upfifo); |
| 118 | __raw_writeb(0x0, &base->utwfifo); |
| 119 | __raw_writeb(0x1, &base->urwfifo); |
| 120 | __raw_writeb(CFIFO_TXFLUSH | CFIFO_RXFLUSH, &base->ucfifo); |
| 121 | |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 122 | /* provide data bits, parity, stop bit, etc */ |
Bin Meng | 6338fbd | 2016-01-13 19:39:03 -0800 | [diff] [blame] | 123 | _lpuart_serial_setbrg(base, gd->baudrate); |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 124 | |
| 125 | __raw_writeb(UC2_RE | UC2_TE, &base->uc2); |
| 126 | |
| 127 | return 0; |
| 128 | } |
| 129 | |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 130 | #ifndef CONFIG_DM_SERIAL |
Bin Meng | 6338fbd | 2016-01-13 19:39:03 -0800 | [diff] [blame] | 131 | static void lpuart_serial_setbrg(void) |
| 132 | { |
| 133 | _lpuart_serial_setbrg(base, gd->baudrate); |
| 134 | } |
| 135 | |
| 136 | static int lpuart_serial_getc(void) |
| 137 | { |
| 138 | return _lpuart_serial_getc(base); |
| 139 | } |
| 140 | |
| 141 | static void lpuart_serial_putc(const char c) |
| 142 | { |
| 143 | _lpuart_serial_putc(base, c); |
| 144 | } |
| 145 | |
| 146 | static int lpuart_serial_tstc(void) |
| 147 | { |
| 148 | return _lpuart_serial_tstc(base); |
| 149 | } |
| 150 | |
| 151 | static int lpuart_serial_init(void) |
| 152 | { |
| 153 | return _lpuart_serial_init(base); |
| 154 | } |
| 155 | |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 156 | static struct serial_device lpuart_serial_drv = { |
| 157 | .name = "lpuart_serial", |
| 158 | .start = lpuart_serial_init, |
| 159 | .stop = NULL, |
| 160 | .setbrg = lpuart_serial_setbrg, |
| 161 | .putc = lpuart_serial_putc, |
| 162 | .puts = default_serial_puts, |
| 163 | .getc = lpuart_serial_getc, |
| 164 | .tstc = lpuart_serial_tstc, |
| 165 | }; |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 166 | #else /* CONFIG_DM_SERIAL */ |
| 167 | static int lpuart_serial_setbrg(struct udevice *dev, int baudrate) |
| 168 | { |
| 169 | struct lpuart_serial_platdata *plat = dev->platdata; |
| 170 | struct lpuart_fsl *reg = plat->reg; |
| 171 | |
| 172 | _lpuart_serial_setbrg(reg, baudrate); |
| 173 | |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | static int lpuart_serial_getc(struct udevice *dev) |
| 178 | { |
| 179 | struct lpuart_serial_platdata *plat = dev->platdata; |
| 180 | struct lpuart_fsl *reg = plat->reg; |
| 181 | |
| 182 | return _lpuart_serial_getc(reg); |
| 183 | } |
| 184 | |
| 185 | static int lpuart_serial_putc(struct udevice *dev, const char c) |
| 186 | { |
| 187 | struct lpuart_serial_platdata *plat = dev->platdata; |
| 188 | struct lpuart_fsl *reg = plat->reg; |
| 189 | |
| 190 | _lpuart_serial_putc(reg, c); |
| 191 | |
| 192 | return 0; |
| 193 | } |
| 194 | |
| 195 | static int lpuart_serial_pending(struct udevice *dev, bool input) |
| 196 | { |
| 197 | struct lpuart_serial_platdata *plat = dev->platdata; |
| 198 | struct lpuart_fsl *reg = plat->reg; |
| 199 | |
| 200 | if (input) |
| 201 | return _lpuart_serial_tstc(reg); |
| 202 | else |
| 203 | return __raw_readb(®->us1) & US1_TDRE ? 0 : 1; |
| 204 | } |
| 205 | |
| 206 | static int lpuart_serial_probe(struct udevice *dev) |
| 207 | { |
| 208 | struct lpuart_serial_platdata *plat = dev->platdata; |
| 209 | struct lpuart_fsl *reg = plat->reg; |
| 210 | |
| 211 | return _lpuart_serial_init(reg); |
| 212 | } |
| 213 | #endif /* CONFIG_DM_SERIAL */ |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 214 | #else |
Bin Meng | 6338fbd | 2016-01-13 19:39:03 -0800 | [diff] [blame] | 215 | static void _lpuart32_serial_setbrg(struct lpuart_fsl *base, int baudrate) |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 216 | { |
| 217 | u32 clk = CONFIG_SYS_CLK_FREQ; |
| 218 | u32 sbr; |
| 219 | |
Bin Meng | 6338fbd | 2016-01-13 19:39:03 -0800 | [diff] [blame] | 220 | sbr = (clk / (16 * baudrate)); |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 221 | |
Bin Meng | a8cc172 | 2016-01-13 19:39:01 -0800 | [diff] [blame] | 222 | /* place adjustment later - n/32 BRFA */ |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 223 | out_be32(&base->baud, sbr); |
| 224 | } |
| 225 | |
Bin Meng | 6338fbd | 2016-01-13 19:39:03 -0800 | [diff] [blame] | 226 | static int _lpuart32_serial_getc(struct lpuart_fsl *base) |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 227 | { |
| 228 | u32 stat; |
| 229 | |
| 230 | while (((stat = in_be32(&base->stat)) & STAT_RDRF) == 0) { |
| 231 | out_be32(&base->stat, STAT_FLAGS); |
| 232 | WATCHDOG_RESET(); |
| 233 | } |
| 234 | |
| 235 | return in_be32(&base->data) & 0x3ff; |
| 236 | } |
| 237 | |
Bin Meng | 6338fbd | 2016-01-13 19:39:03 -0800 | [diff] [blame] | 238 | static void _lpuart32_serial_putc(struct lpuart_fsl *base, const char c) |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 239 | { |
| 240 | if (c == '\n') |
Bin Meng | 6338fbd | 2016-01-13 19:39:03 -0800 | [diff] [blame] | 241 | _lpuart32_serial_putc(base, '\r'); |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 242 | |
| 243 | while (!(in_be32(&base->stat) & STAT_TDRE)) |
| 244 | WATCHDOG_RESET(); |
| 245 | |
| 246 | out_be32(&base->data, c); |
| 247 | } |
| 248 | |
Bin Meng | a8cc172 | 2016-01-13 19:39:01 -0800 | [diff] [blame] | 249 | /* Test whether a character is in the RX buffer */ |
Bin Meng | 6338fbd | 2016-01-13 19:39:03 -0800 | [diff] [blame] | 250 | static int _lpuart32_serial_tstc(struct lpuart_fsl *base) |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 251 | { |
| 252 | if ((in_be32(&base->water) >> 24) == 0) |
| 253 | return 0; |
| 254 | |
| 255 | return 1; |
| 256 | } |
| 257 | |
| 258 | /* |
| 259 | * Initialise the serial port with the given baudrate. The settings |
| 260 | * are always 8 data bits, no parity, 1 stop bit, no start bits. |
| 261 | */ |
Bin Meng | 6338fbd | 2016-01-13 19:39:03 -0800 | [diff] [blame] | 262 | static int _lpuart32_serial_init(struct lpuart_fsl *base) |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 263 | { |
| 264 | u8 ctrl; |
| 265 | |
| 266 | ctrl = in_be32(&base->ctrl); |
| 267 | ctrl &= ~CTRL_RE; |
| 268 | ctrl &= ~CTRL_TE; |
| 269 | out_be32(&base->ctrl, ctrl); |
| 270 | |
| 271 | out_be32(&base->modir, 0); |
| 272 | out_be32(&base->fifo, ~(FIFO_TXFE | FIFO_RXFE)); |
| 273 | |
| 274 | out_be32(&base->match, 0); |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 275 | |
Bin Meng | a8cc172 | 2016-01-13 19:39:01 -0800 | [diff] [blame] | 276 | /* provide data bits, parity, stop bit, etc */ |
Bin Meng | 6338fbd | 2016-01-13 19:39:03 -0800 | [diff] [blame] | 277 | _lpuart32_serial_setbrg(base, gd->baudrate); |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 278 | |
| 279 | out_be32(&base->ctrl, CTRL_RE | CTRL_TE); |
| 280 | |
| 281 | return 0; |
| 282 | } |
| 283 | |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 284 | #ifndef CONFIG_DM_SERIAL |
Bin Meng | 6338fbd | 2016-01-13 19:39:03 -0800 | [diff] [blame] | 285 | static void lpuart32_serial_setbrg(void) |
| 286 | { |
| 287 | _lpuart32_serial_setbrg(base, gd->baudrate); |
| 288 | } |
| 289 | |
| 290 | static int lpuart32_serial_getc(void) |
| 291 | { |
| 292 | return _lpuart32_serial_getc(base); |
| 293 | } |
| 294 | |
| 295 | static void lpuart32_serial_putc(const char c) |
| 296 | { |
| 297 | _lpuart32_serial_putc(base, c); |
| 298 | } |
| 299 | |
| 300 | static int lpuart32_serial_tstc(void) |
| 301 | { |
| 302 | return _lpuart32_serial_tstc(base); |
| 303 | } |
| 304 | |
| 305 | static int lpuart32_serial_init(void) |
| 306 | { |
| 307 | return _lpuart32_serial_init(base); |
| 308 | } |
| 309 | |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 310 | static struct serial_device lpuart32_serial_drv = { |
| 311 | .name = "lpuart32_serial", |
| 312 | .start = lpuart32_serial_init, |
| 313 | .stop = NULL, |
| 314 | .setbrg = lpuart32_serial_setbrg, |
| 315 | .putc = lpuart32_serial_putc, |
| 316 | .puts = default_serial_puts, |
| 317 | .getc = lpuart32_serial_getc, |
| 318 | .tstc = lpuart32_serial_tstc, |
| 319 | }; |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 320 | #else /* CONFIG_DM_SERIAL */ |
| 321 | static int lpuart32_serial_setbrg(struct udevice *dev, int baudrate) |
| 322 | { |
| 323 | struct lpuart_serial_platdata *plat = dev->platdata; |
| 324 | struct lpuart_fsl *reg = plat->reg; |
| 325 | |
| 326 | _lpuart32_serial_setbrg(reg, baudrate); |
| 327 | |
| 328 | return 0; |
| 329 | } |
| 330 | |
| 331 | static int lpuart32_serial_getc(struct udevice *dev) |
| 332 | { |
| 333 | struct lpuart_serial_platdata *plat = dev->platdata; |
| 334 | struct lpuart_fsl *reg = plat->reg; |
| 335 | |
| 336 | return _lpuart32_serial_getc(reg); |
| 337 | } |
| 338 | |
| 339 | static int lpuart32_serial_putc(struct udevice *dev, const char c) |
| 340 | { |
| 341 | struct lpuart_serial_platdata *plat = dev->platdata; |
| 342 | struct lpuart_fsl *reg = plat->reg; |
| 343 | |
| 344 | _lpuart32_serial_putc(reg, c); |
| 345 | |
| 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | static int lpuart32_serial_pending(struct udevice *dev, bool input) |
| 350 | { |
| 351 | struct lpuart_serial_platdata *plat = dev->platdata; |
| 352 | struct lpuart_fsl *reg = plat->reg; |
| 353 | |
| 354 | if (input) |
| 355 | return _lpuart32_serial_tstc(reg); |
| 356 | else |
| 357 | return in_be32(®->stat) & STAT_TDRE ? 0 : 1; |
| 358 | } |
| 359 | |
| 360 | static int lpuart32_serial_probe(struct udevice *dev) |
| 361 | { |
| 362 | struct lpuart_serial_platdata *plat = dev->platdata; |
| 363 | struct lpuart_fsl *reg = plat->reg; |
| 364 | |
| 365 | return _lpuart32_serial_init(reg); |
| 366 | } |
| 367 | #endif /* CONFIG_DM_SERIAL */ |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 368 | #endif |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 369 | |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 370 | #ifndef CONFIG_DM_SERIAL |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 371 | void lpuart_serial_initialize(void) |
| 372 | { |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 373 | #ifdef CONFIG_LPUART_32B_REG |
| 374 | serial_register(&lpuart32_serial_drv); |
| 375 | #else |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 376 | serial_register(&lpuart_serial_drv); |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 377 | #endif |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | __weak struct serial_device *default_serial_console(void) |
| 381 | { |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 382 | #ifdef CONFIG_LPUART_32B_REG |
| 383 | return &lpuart32_serial_drv; |
| 384 | #else |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 385 | return &lpuart_serial_drv; |
Jingchang Lu | 4a7154e | 2014-09-05 13:52:47 +0800 | [diff] [blame] | 386 | #endif |
Alison Wang | e283053 | 2013-05-27 22:55:45 +0000 | [diff] [blame] | 387 | } |
Bin Meng | 8a70d6d | 2016-01-13 19:39:04 -0800 | [diff] [blame] | 388 | #else /* CONFIG_DM_SERIAL */ |
| 389 | static int lpuart_serial_ofdata_to_platdata(struct udevice *dev) |
| 390 | { |
| 391 | struct lpuart_serial_platdata *plat = dev->platdata; |
| 392 | fdt_addr_t addr; |
| 393 | |
| 394 | addr = dev_get_addr(dev); |
| 395 | if (addr == FDT_ADDR_T_NONE) |
| 396 | return -EINVAL; |
| 397 | |
| 398 | plat->reg = (struct lpuart_fsl *)addr; |
| 399 | |
| 400 | return 0; |
| 401 | } |
| 402 | |
| 403 | #ifndef CONFIG_LPUART_32B_REG |
| 404 | static const struct dm_serial_ops lpuart_serial_ops = { |
| 405 | .putc = lpuart_serial_putc, |
| 406 | .pending = lpuart_serial_pending, |
| 407 | .getc = lpuart_serial_getc, |
| 408 | .setbrg = lpuart_serial_setbrg, |
| 409 | }; |
| 410 | |
| 411 | static const struct udevice_id lpuart_serial_ids[] = { |
| 412 | { .compatible = "fsl,vf610-lpuart" }, |
| 413 | { } |
| 414 | }; |
| 415 | |
| 416 | U_BOOT_DRIVER(serial_lpuart) = { |
| 417 | .name = "serial_lpuart", |
| 418 | .id = UCLASS_SERIAL, |
| 419 | .of_match = lpuart_serial_ids, |
| 420 | .ofdata_to_platdata = lpuart_serial_ofdata_to_platdata, |
| 421 | .platdata_auto_alloc_size = sizeof(struct lpuart_serial_platdata), |
| 422 | .probe = lpuart_serial_probe, |
| 423 | .ops = &lpuart_serial_ops, |
| 424 | .flags = DM_FLAG_PRE_RELOC, |
| 425 | }; |
| 426 | #else /* CONFIG_LPUART_32B_REG */ |
| 427 | static const struct dm_serial_ops lpuart32_serial_ops = { |
| 428 | .putc = lpuart32_serial_putc, |
| 429 | .pending = lpuart32_serial_pending, |
| 430 | .getc = lpuart32_serial_getc, |
| 431 | .setbrg = lpuart32_serial_setbrg, |
| 432 | }; |
| 433 | |
| 434 | static const struct udevice_id lpuart32_serial_ids[] = { |
| 435 | { .compatible = "fsl,ls1021a-lpuart" }, |
| 436 | { } |
| 437 | }; |
| 438 | |
| 439 | U_BOOT_DRIVER(serial_lpuart32) = { |
| 440 | .name = "serial_lpuart32", |
| 441 | .id = UCLASS_SERIAL, |
| 442 | .of_match = lpuart32_serial_ids, |
| 443 | .ofdata_to_platdata = lpuart_serial_ofdata_to_platdata, |
| 444 | .platdata_auto_alloc_size = sizeof(struct lpuart_serial_platdata), |
| 445 | .probe = lpuart32_serial_probe, |
| 446 | .ops = &lpuart32_serial_ops, |
| 447 | .flags = DM_FLAG_PRE_RELOC, |
| 448 | }; |
| 449 | #endif /* CONFIG_LPUART_32B_REG */ |
| 450 | #endif /* CONFIG_DM_SERIAL */ |