blob: 536d30f66a035db9ab5f4b060a8ec2f4968f9e5f [file] [log] [blame]
Alison Wange2830532013-05-27 22:55:45 +00001/*
2 * Copyright 2013 Freescale Semiconductor, Inc.
3 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02004 * SPDX-License-Identifier: GPL-2.0+
Alison Wange2830532013-05-27 22:55:45 +00005 */
6
7#include <common.h>
Bin Meng8a70d6d2016-01-13 19:39:04 -08008#include <dm.h>
Peng Fan836a6cc2017-02-22 16:21:51 +08009#include <fsl_lpuart.h>
Alison Wange2830532013-05-27 22:55:45 +000010#include <watchdog.h>
11#include <asm/io.h>
12#include <serial.h>
13#include <linux/compiler.h>
14#include <asm/arch/imx-regs.h>
15#include <asm/arch/clock.h>
16
Bin Menga8cc1722016-01-13 19:39:01 -080017#define US1_TDRE (1 << 7)
18#define US1_RDRF (1 << 5)
19#define US1_OR (1 << 3)
20#define UC2_TE (1 << 3)
21#define UC2_RE (1 << 2)
22#define CFIFO_TXFLUSH (1 << 7)
23#define CFIFO_RXFLUSH (1 << 6)
24#define SFIFO_RXOF (1 << 2)
25#define SFIFO_RXUF (1 << 0)
Alison Wange2830532013-05-27 22:55:45 +000026
Jingchang Lu4a7154e2014-09-05 13:52:47 +080027#define STAT_LBKDIF (1 << 31)
28#define STAT_RXEDGIF (1 << 30)
29#define STAT_TDRE (1 << 23)
30#define STAT_RDRF (1 << 21)
31#define STAT_IDLE (1 << 20)
32#define STAT_OR (1 << 19)
33#define STAT_NF (1 << 18)
34#define STAT_FE (1 << 17)
35#define STAT_PF (1 << 16)
36#define STAT_MA1F (1 << 15)
37#define STAT_MA2F (1 << 14)
38#define STAT_FLAGS (STAT_LBKDIF | STAT_RXEDGIF | STAT_IDLE | STAT_OR | \
Bin Menga8cc1722016-01-13 19:39:01 -080039 STAT_NF | STAT_FE | STAT_PF | STAT_MA1F | STAT_MA2F)
Jingchang Lu4a7154e2014-09-05 13:52:47 +080040
41#define CTRL_TE (1 << 19)
42#define CTRL_RE (1 << 18)
43
44#define FIFO_TXFE 0x80
45#define FIFO_RXFE 0x40
46
47#define WATER_TXWATER_OFF 1
48#define WATER_RXWATER_OFF 16
49
Alison Wange2830532013-05-27 22:55:45 +000050DECLARE_GLOBAL_DATA_PTR;
51
Peng Fan836a6cc2017-02-22 16:21:51 +080052#define LPUART_FLAG_REGMAP_32BIT_REG BIT(0)
53#define LPUART_FLAG_REGMAP_ENDIAN_BIG BIT(1)
54
Peng Fandac2c942017-02-22 16:21:52 +080055enum lpuart_devtype {
56 DEV_VF610 = 1,
57 DEV_LS1021A,
58 DEV_MX7ULP
59};
60
Bin Meng8a70d6d2016-01-13 19:39:04 -080061struct lpuart_serial_platdata {
Peng Fan836a6cc2017-02-22 16:21:51 +080062 void *reg;
Peng Fandac2c942017-02-22 16:21:52 +080063 enum lpuart_devtype devtype;
Peng Fan836a6cc2017-02-22 16:21:51 +080064 ulong flags;
Bin Meng8a70d6d2016-01-13 19:39:04 -080065};
66
Peng Fan836a6cc2017-02-22 16:21:51 +080067static void lpuart_read32(u32 flags, u32 *addr, u32 *val)
68{
69 if (flags & LPUART_FLAG_REGMAP_32BIT_REG) {
70 if (flags & LPUART_FLAG_REGMAP_ENDIAN_BIG)
71 *(u32 *)val = in_be32(addr);
72 else
73 *(u32 *)val = in_le32(addr);
74 }
75}
76
77static void lpuart_write32(u32 flags, u32 *addr, u32 val)
78{
79 if (flags & LPUART_FLAG_REGMAP_32BIT_REG) {
80 if (flags & LPUART_FLAG_REGMAP_ENDIAN_BIG)
81 out_be32(addr, val);
82 else
83 out_le32(addr, val);
84 }
85}
86
87
88#ifndef CONFIG_SYS_CLK_FREQ
89#define CONFIG_SYS_CLK_FREQ 0
90#endif
91
92u32 __weak get_lpuart_clk(void)
Alison Wange2830532013-05-27 22:55:45 +000093{
Peng Fan836a6cc2017-02-22 16:21:51 +080094 return CONFIG_SYS_CLK_FREQ;
95}
96
97static bool is_lpuart32(struct udevice *dev)
98{
99 struct lpuart_serial_platdata *plat = dev->platdata;
100
101 return plat->flags & LPUART_FLAG_REGMAP_32BIT_REG;
102}
103
104static void _lpuart_serial_setbrg(struct lpuart_serial_platdata *plat,
105 int baudrate)
106{
107 struct lpuart_fsl *base = plat->reg;
108 u32 clk = get_lpuart_clk();
Alison Wange2830532013-05-27 22:55:45 +0000109 u16 sbr;
110
Bin Meng6338fbd2016-01-13 19:39:03 -0800111 sbr = (u16)(clk / (16 * baudrate));
Alison Wange2830532013-05-27 22:55:45 +0000112
Bin Menga8cc1722016-01-13 19:39:01 -0800113 /* place adjustment later - n/32 BRFA */
Alison Wange2830532013-05-27 22:55:45 +0000114 __raw_writeb(sbr >> 8, &base->ubdh);
115 __raw_writeb(sbr & 0xff, &base->ubdl);
116}
117
Peng Fan836a6cc2017-02-22 16:21:51 +0800118static int _lpuart_serial_getc(struct lpuart_serial_platdata *plat)
Alison Wange2830532013-05-27 22:55:45 +0000119{
Peng Fan836a6cc2017-02-22 16:21:51 +0800120 struct lpuart_fsl *base = plat->reg;
Stefan Agner24482912014-08-19 17:54:27 +0200121 while (!(__raw_readb(&base->us1) & (US1_RDRF | US1_OR)))
Alison Wange2830532013-05-27 22:55:45 +0000122 WATCHDOG_RESET();
123
Stefan Agner24482912014-08-19 17:54:27 +0200124 barrier();
Alison Wange2830532013-05-27 22:55:45 +0000125
126 return __raw_readb(&base->ud);
127}
128
Peng Fan836a6cc2017-02-22 16:21:51 +0800129static void _lpuart_serial_putc(struct lpuart_serial_platdata *plat,
130 const char c)
Alison Wange2830532013-05-27 22:55:45 +0000131{
Peng Fan836a6cc2017-02-22 16:21:51 +0800132 struct lpuart_fsl *base = plat->reg;
133
Alison Wange2830532013-05-27 22:55:45 +0000134 while (!(__raw_readb(&base->us1) & US1_TDRE))
135 WATCHDOG_RESET();
136
137 __raw_writeb(c, &base->ud);
138}
139
Bin Menga8cc1722016-01-13 19:39:01 -0800140/* Test whether a character is in the RX buffer */
Peng Fan836a6cc2017-02-22 16:21:51 +0800141static int _lpuart_serial_tstc(struct lpuart_serial_platdata *plat)
Alison Wange2830532013-05-27 22:55:45 +0000142{
Peng Fan836a6cc2017-02-22 16:21:51 +0800143 struct lpuart_fsl *base = plat->reg;
144
Alison Wange2830532013-05-27 22:55:45 +0000145 if (__raw_readb(&base->urcfifo) == 0)
146 return 0;
147
148 return 1;
149}
150
151/*
152 * Initialise the serial port with the given baudrate. The settings
153 * are always 8 data bits, no parity, 1 stop bit, no start bits.
154 */
Peng Fan836a6cc2017-02-22 16:21:51 +0800155static int _lpuart_serial_init(struct lpuart_serial_platdata *plat)
Alison Wange2830532013-05-27 22:55:45 +0000156{
Peng Fan836a6cc2017-02-22 16:21:51 +0800157 struct lpuart_fsl *base = (struct lpuart_fsl *)plat->reg;
Alison Wange2830532013-05-27 22:55:45 +0000158 u8 ctrl;
159
160 ctrl = __raw_readb(&base->uc2);
161 ctrl &= ~UC2_RE;
162 ctrl &= ~UC2_TE;
163 __raw_writeb(ctrl, &base->uc2);
164
165 __raw_writeb(0, &base->umodem);
166 __raw_writeb(0, &base->uc1);
167
Stefan Agner190f1d22014-08-19 17:54:28 +0200168 /* Disable FIFO and flush buffer */
169 __raw_writeb(0x0, &base->upfifo);
170 __raw_writeb(0x0, &base->utwfifo);
171 __raw_writeb(0x1, &base->urwfifo);
172 __raw_writeb(CFIFO_TXFLUSH | CFIFO_RXFLUSH, &base->ucfifo);
173
Alison Wange2830532013-05-27 22:55:45 +0000174 /* provide data bits, parity, stop bit, etc */
Peng Fan836a6cc2017-02-22 16:21:51 +0800175 _lpuart_serial_setbrg(plat, gd->baudrate);
Alison Wange2830532013-05-27 22:55:45 +0000176
177 __raw_writeb(UC2_RE | UC2_TE, &base->uc2);
178
179 return 0;
180}
181
Peng Fandac2c942017-02-22 16:21:52 +0800182static void _lpuart32_serial_setbrg_7ulp(struct lpuart_serial_platdata *plat,
183 int baudrate)
184{
185 struct lpuart_fsl_reg32 *base = plat->reg;
186 u32 sbr, osr, baud_diff, tmp_osr, tmp_sbr, tmp_diff, tmp;
187 u32 clk = get_lpuart_clk();
188
189 baud_diff = baudrate;
190 osr = 0;
191 sbr = 0;
192
193 for (tmp_osr = 4; tmp_osr <= 32; tmp_osr++) {
194 tmp_sbr = (clk / (baudrate * tmp_osr));
195
196 if (tmp_sbr == 0)
197 tmp_sbr = 1;
198
199 /*calculate difference in actual buad w/ current values */
200 tmp_diff = (clk / (tmp_osr * tmp_sbr));
201 tmp_diff = tmp_diff - baudrate;
202
203 /* select best values between sbr and sbr+1 */
204 if (tmp_diff > (baudrate - (clk / (tmp_osr * (tmp_sbr + 1))))) {
205 tmp_diff = baudrate - (clk / (tmp_osr * (tmp_sbr + 1)));
206 tmp_sbr++;
207 }
208
209 if (tmp_diff <= baud_diff) {
210 baud_diff = tmp_diff;
211 osr = tmp_osr;
212 sbr = tmp_sbr;
213 }
214 }
215
216 /*
217 * TODO: handle buadrate outside acceptable rate
218 * if (baudDiff > ((config->baudRate_Bps / 100) * 3))
219 * {
220 * Unacceptable baud rate difference of more than 3%
221 * return kStatus_LPUART_BaudrateNotSupport;
222 * }
223 */
224 tmp = in_le32(&base->baud);
225
226 if ((osr > 3) && (osr < 8))
227 tmp |= LPUART_BAUD_BOTHEDGE_MASK;
228
229 tmp &= ~LPUART_BAUD_OSR_MASK;
230 tmp |= LPUART_BAUD_OSR(osr-1);
231
232 tmp &= ~LPUART_BAUD_SBR_MASK;
233 tmp |= LPUART_BAUD_SBR(sbr);
234
235 /* explicitly disable 10 bit mode & set 1 stop bit */
236 tmp &= ~(LPUART_BAUD_M10_MASK | LPUART_BAUD_SBNS_MASK);
237
238 out_le32(&base->baud, tmp);
239}
240
Peng Fan836a6cc2017-02-22 16:21:51 +0800241static void _lpuart32_serial_setbrg(struct lpuart_serial_platdata *plat,
242 int baudrate)
Bin Meng8a70d6d2016-01-13 19:39:04 -0800243{
Peng Fan836a6cc2017-02-22 16:21:51 +0800244 struct lpuart_fsl_reg32 *base = plat->reg;
Shaohui Xie957b6722016-10-28 14:23:30 +0800245 u32 clk = get_lpuart_clk();
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800246 u32 sbr;
247
Bin Meng6338fbd2016-01-13 19:39:03 -0800248 sbr = (clk / (16 * baudrate));
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800249
Bin Menga8cc1722016-01-13 19:39:01 -0800250 /* place adjustment later - n/32 BRFA */
Peng Fan836a6cc2017-02-22 16:21:51 +0800251 lpuart_write32(plat->flags, &base->baud, sbr);
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800252}
253
Peng Fan836a6cc2017-02-22 16:21:51 +0800254static int _lpuart32_serial_getc(struct lpuart_serial_platdata *plat)
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800255{
Peng Fan836a6cc2017-02-22 16:21:51 +0800256 struct lpuart_fsl_reg32 *base = plat->reg;
Peng Fandac2c942017-02-22 16:21:52 +0800257 u32 stat, val;
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800258
Peng Fan836a6cc2017-02-22 16:21:51 +0800259 lpuart_read32(plat->flags, &base->stat, &stat);
260 while ((stat & STAT_RDRF) == 0) {
261 lpuart_write32(plat->flags, &base->stat, STAT_FLAGS);
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800262 WATCHDOG_RESET();
Peng Fan836a6cc2017-02-22 16:21:51 +0800263 lpuart_read32(plat->flags, &base->stat, &stat);
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800264 }
265
Peng Fandac2c942017-02-22 16:21:52 +0800266 lpuart_read32(plat->flags, &base->data, &val);
Peng Fan836a6cc2017-02-22 16:21:51 +0800267
Sriram Dash32cf46c2018-01-10 11:57:14 +0530268 lpuart_read32(plat->flags, &base->stat, &stat);
269 if (stat & STAT_OR)
270 lpuart_write32(plat->flags, &base->stat, STAT_OR);
Peng Fandac2c942017-02-22 16:21:52 +0800271
272 return val & 0x3ff;
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800273}
274
Peng Fan836a6cc2017-02-22 16:21:51 +0800275static void _lpuart32_serial_putc(struct lpuart_serial_platdata *plat,
276 const char c)
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800277{
Peng Fan836a6cc2017-02-22 16:21:51 +0800278 struct lpuart_fsl_reg32 *base = plat->reg;
279 u32 stat;
280
Sriram Dash32cf46c2018-01-10 11:57:14 +0530281 if (c == '\n')
282 serial_putc('\r');
Peng Fandac2c942017-02-22 16:21:52 +0800283
Peng Fan836a6cc2017-02-22 16:21:51 +0800284 while (true) {
285 lpuart_read32(plat->flags, &base->stat, &stat);
286
287 if ((stat & STAT_TDRE))
288 break;
289
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800290 WATCHDOG_RESET();
Peng Fan836a6cc2017-02-22 16:21:51 +0800291 }
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800292
Peng Fan836a6cc2017-02-22 16:21:51 +0800293 lpuart_write32(plat->flags, &base->data, c);
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800294}
295
Bin Menga8cc1722016-01-13 19:39:01 -0800296/* Test whether a character is in the RX buffer */
Peng Fan836a6cc2017-02-22 16:21:51 +0800297static int _lpuart32_serial_tstc(struct lpuart_serial_platdata *plat)
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800298{
Peng Fan836a6cc2017-02-22 16:21:51 +0800299 struct lpuart_fsl_reg32 *base = plat->reg;
300 u32 water;
301
302 lpuart_read32(plat->flags, &base->water, &water);
303
304 if ((water >> 24) == 0)
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800305 return 0;
306
307 return 1;
308}
309
310/*
311 * Initialise the serial port with the given baudrate. The settings
312 * are always 8 data bits, no parity, 1 stop bit, no start bits.
313 */
Peng Fan836a6cc2017-02-22 16:21:51 +0800314static int _lpuart32_serial_init(struct lpuart_serial_platdata *plat)
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800315{
Peng Fan836a6cc2017-02-22 16:21:51 +0800316 struct lpuart_fsl_reg32 *base = (struct lpuart_fsl_reg32 *)plat->reg;
317 u32 ctrl;
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800318
Peng Fan836a6cc2017-02-22 16:21:51 +0800319 lpuart_read32(plat->flags, &base->ctrl, &ctrl);
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800320 ctrl &= ~CTRL_RE;
321 ctrl &= ~CTRL_TE;
Peng Fan836a6cc2017-02-22 16:21:51 +0800322 lpuart_write32(plat->flags, &base->ctrl, ctrl);
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800323
Peng Fan836a6cc2017-02-22 16:21:51 +0800324 lpuart_write32(plat->flags, &base->modir, 0);
325 lpuart_write32(plat->flags, &base->fifo, ~(FIFO_TXFE | FIFO_RXFE));
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800326
Peng Fan836a6cc2017-02-22 16:21:51 +0800327 lpuart_write32(plat->flags, &base->match, 0);
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800328
Sriram Dash32cf46c2018-01-10 11:57:14 +0530329 if (plat->devtype == DEV_MX7ULP) {
Peng Fandac2c942017-02-22 16:21:52 +0800330 _lpuart32_serial_setbrg_7ulp(plat, gd->baudrate);
331 } else {
332 /* provide data bits, parity, stop bit, etc */
333 _lpuart32_serial_setbrg(plat, gd->baudrate);
334 }
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800335
Peng Fan836a6cc2017-02-22 16:21:51 +0800336 lpuart_write32(plat->flags, &base->ctrl, CTRL_RE | CTRL_TE);
Jingchang Lu4a7154e2014-09-05 13:52:47 +0800337
338 return 0;
339}
340
Peng Fan836a6cc2017-02-22 16:21:51 +0800341static int lpuart_serial_setbrg(struct udevice *dev, int baudrate)
Bin Meng8a70d6d2016-01-13 19:39:04 -0800342{
343 struct lpuart_serial_platdata *plat = dev->platdata;
Bin Meng8a70d6d2016-01-13 19:39:04 -0800344
Peng Fandac2c942017-02-22 16:21:52 +0800345 if (is_lpuart32(dev)) {
Sriram Dash32cf46c2018-01-10 11:57:14 +0530346 if (plat->devtype == DEV_MX7ULP)
Peng Fandac2c942017-02-22 16:21:52 +0800347 _lpuart32_serial_setbrg_7ulp(plat, baudrate);
348 else
349 _lpuart32_serial_setbrg(plat, baudrate);
350 } else {
Peng Fan836a6cc2017-02-22 16:21:51 +0800351 _lpuart_serial_setbrg(plat, baudrate);
Peng Fandac2c942017-02-22 16:21:52 +0800352 }
Bin Meng8a70d6d2016-01-13 19:39:04 -0800353
354 return 0;
355}
356
Peng Fan836a6cc2017-02-22 16:21:51 +0800357static int lpuart_serial_getc(struct udevice *dev)
Bin Meng8a70d6d2016-01-13 19:39:04 -0800358{
359 struct lpuart_serial_platdata *plat = dev->platdata;
Bin Meng8a70d6d2016-01-13 19:39:04 -0800360
Peng Fan836a6cc2017-02-22 16:21:51 +0800361 if (is_lpuart32(dev))
362 return _lpuart32_serial_getc(plat);
363
364 return _lpuart_serial_getc(plat);
Bin Meng8a70d6d2016-01-13 19:39:04 -0800365}
366
Peng Fan836a6cc2017-02-22 16:21:51 +0800367static int lpuart_serial_putc(struct udevice *dev, const char c)
Bin Meng8a70d6d2016-01-13 19:39:04 -0800368{
369 struct lpuart_serial_platdata *plat = dev->platdata;
Bin Meng8a70d6d2016-01-13 19:39:04 -0800370
Peng Fan836a6cc2017-02-22 16:21:51 +0800371 if (is_lpuart32(dev))
372 _lpuart32_serial_putc(plat, c);
373 else
374 _lpuart_serial_putc(plat, c);
Bin Meng8a70d6d2016-01-13 19:39:04 -0800375
376 return 0;
377}
378
Peng Fan836a6cc2017-02-22 16:21:51 +0800379static int lpuart_serial_pending(struct udevice *dev, bool input)
Bin Meng8a70d6d2016-01-13 19:39:04 -0800380{
381 struct lpuart_serial_platdata *plat = dev->platdata;
382 struct lpuart_fsl *reg = plat->reg;
Peng Fan836a6cc2017-02-22 16:21:51 +0800383 struct lpuart_fsl_reg32 *reg32 = plat->reg;
384 u32 stat;
385
386 if (is_lpuart32(dev)) {
387 if (input) {
388 return _lpuart32_serial_tstc(plat);
389 } else {
390 lpuart_read32(plat->flags, &reg32->stat, &stat);
391 return stat & STAT_TDRE ? 0 : 1;
392 }
393 }
Bin Meng8a70d6d2016-01-13 19:39:04 -0800394
395 if (input)
Peng Fan836a6cc2017-02-22 16:21:51 +0800396 return _lpuart_serial_tstc(plat);
Bin Meng8a70d6d2016-01-13 19:39:04 -0800397 else
Peng Fan836a6cc2017-02-22 16:21:51 +0800398 return __raw_readb(&reg->us1) & US1_TDRE ? 0 : 1;
Bin Meng8a70d6d2016-01-13 19:39:04 -0800399}
400
Peng Fan836a6cc2017-02-22 16:21:51 +0800401static int lpuart_serial_probe(struct udevice *dev)
Bin Meng8a70d6d2016-01-13 19:39:04 -0800402{
403 struct lpuart_serial_platdata *plat = dev->platdata;
Bin Meng8a70d6d2016-01-13 19:39:04 -0800404
Peng Fan836a6cc2017-02-22 16:21:51 +0800405 if (is_lpuart32(dev))
406 return _lpuart32_serial_init(plat);
407 else
408 return _lpuart_serial_init(plat);
Bin Meng8a70d6d2016-01-13 19:39:04 -0800409}
Alison Wange2830532013-05-27 22:55:45 +0000410
Bin Meng8a70d6d2016-01-13 19:39:04 -0800411static int lpuart_serial_ofdata_to_platdata(struct udevice *dev)
412{
413 struct lpuart_serial_platdata *plat = dev->platdata;
Peng Fandac2c942017-02-22 16:21:52 +0800414 const void *blob = gd->fdt_blob;
Simon Glass7a494432017-05-17 17:18:09 -0600415 int node = dev_of_offset(dev);
Bin Meng8a70d6d2016-01-13 19:39:04 -0800416 fdt_addr_t addr;
417
Simon Glassba1dea42017-05-17 17:18:05 -0600418 addr = devfdt_get_addr(dev);
Bin Meng8a70d6d2016-01-13 19:39:04 -0800419 if (addr == FDT_ADDR_T_NONE)
420 return -EINVAL;
421
Peng Fan836a6cc2017-02-22 16:21:51 +0800422 plat->reg = (void *)addr;
423 plat->flags = dev_get_driver_data(dev);
Bin Meng8a70d6d2016-01-13 19:39:04 -0800424
Peng Fandac2c942017-02-22 16:21:52 +0800425 if (!fdt_node_check_compatible(blob, node, "fsl,ls1021a-lpuart"))
426 plat->devtype = DEV_LS1021A;
427 else if (!fdt_node_check_compatible(blob, node, "fsl,imx7ulp-lpuart"))
428 plat->devtype = DEV_MX7ULP;
429 else if (!fdt_node_check_compatible(blob, node, "fsl,vf610-lpuart"))
430 plat->devtype = DEV_VF610;
431
Bin Meng8a70d6d2016-01-13 19:39:04 -0800432 return 0;
433}
434
Bin Meng8a70d6d2016-01-13 19:39:04 -0800435static const struct dm_serial_ops lpuart_serial_ops = {
436 .putc = lpuart_serial_putc,
437 .pending = lpuart_serial_pending,
438 .getc = lpuart_serial_getc,
439 .setbrg = lpuart_serial_setbrg,
440};
441
442static const struct udevice_id lpuart_serial_ids[] = {
Peng Fan836a6cc2017-02-22 16:21:51 +0800443 { .compatible = "fsl,ls1021a-lpuart", .data =
444 LPUART_FLAG_REGMAP_32BIT_REG | LPUART_FLAG_REGMAP_ENDIAN_BIG },
Peng Fandac2c942017-02-22 16:21:52 +0800445 { .compatible = "fsl,imx7ulp-lpuart",
446 .data = LPUART_FLAG_REGMAP_32BIT_REG },
Peng Fan836a6cc2017-02-22 16:21:51 +0800447 { .compatible = "fsl,vf610-lpuart"},
Bin Meng8a70d6d2016-01-13 19:39:04 -0800448 { }
449};
450
451U_BOOT_DRIVER(serial_lpuart) = {
452 .name = "serial_lpuart",
453 .id = UCLASS_SERIAL,
454 .of_match = lpuart_serial_ids,
455 .ofdata_to_platdata = lpuart_serial_ofdata_to_platdata,
456 .platdata_auto_alloc_size = sizeof(struct lpuart_serial_platdata),
457 .probe = lpuart_serial_probe,
458 .ops = &lpuart_serial_ops,
459 .flags = DM_FLAG_PRE_RELOC,
460};