1427eba70SAlison Wang /*
2427eba70SAlison Wang  * Copyright 2013 Freescale Semiconductor, Inc.
3427eba70SAlison Wang  *
41a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
5427eba70SAlison Wang  */
6427eba70SAlison Wang 
7427eba70SAlison Wang #include <common.h>
8*fdbae099SBin Meng #include <dm.h>
9427eba70SAlison Wang #include <watchdog.h>
10427eba70SAlison Wang #include <asm/io.h>
11427eba70SAlison Wang #include <serial.h>
12427eba70SAlison Wang #include <linux/compiler.h>
13427eba70SAlison Wang #include <asm/arch/imx-regs.h>
14427eba70SAlison Wang #include <asm/arch/clock.h>
15427eba70SAlison Wang 
16427eba70SAlison Wang #define US1_TDRE	(1 << 7)
17427eba70SAlison Wang #define US1_RDRF	(1 << 5)
18a3db78d8SStefan Agner #define US1_OR		(1 << 3)
19427eba70SAlison Wang #define UC2_TE		(1 << 3)
20427eba70SAlison Wang #define UC2_RE		(1 << 2)
2189e69fd4SStefan Agner #define CFIFO_TXFLUSH	(1 << 7)
2289e69fd4SStefan Agner #define CFIFO_RXFLUSH	(1 << 6)
2389e69fd4SStefan Agner #define SFIFO_RXOF	(1 << 2)
2489e69fd4SStefan Agner #define SFIFO_RXUF	(1 << 0)
25427eba70SAlison Wang 
266209e14cSJingchang Lu #define STAT_LBKDIF	(1 << 31)
276209e14cSJingchang Lu #define STAT_RXEDGIF	(1 << 30)
286209e14cSJingchang Lu #define STAT_TDRE	(1 << 23)
296209e14cSJingchang Lu #define STAT_RDRF	(1 << 21)
306209e14cSJingchang Lu #define STAT_IDLE	(1 << 20)
316209e14cSJingchang Lu #define STAT_OR		(1 << 19)
326209e14cSJingchang Lu #define STAT_NF		(1 << 18)
336209e14cSJingchang Lu #define STAT_FE		(1 << 17)
346209e14cSJingchang Lu #define STAT_PF		(1 << 16)
356209e14cSJingchang Lu #define STAT_MA1F	(1 << 15)
366209e14cSJingchang Lu #define STAT_MA2F	(1 << 14)
376209e14cSJingchang Lu #define STAT_FLAGS	(STAT_LBKDIF | STAT_RXEDGIF | STAT_IDLE | STAT_OR | \
386209e14cSJingchang Lu 			 STAT_NF | STAT_FE | STAT_PF | STAT_MA1F | STAT_MA2F)
396209e14cSJingchang Lu 
406209e14cSJingchang Lu #define CTRL_TE		(1 << 19)
416209e14cSJingchang Lu #define CTRL_RE		(1 << 18)
426209e14cSJingchang Lu 
436209e14cSJingchang Lu #define FIFO_TXFE		0x80
446209e14cSJingchang Lu #define FIFO_RXFE		0x40
456209e14cSJingchang Lu 
466209e14cSJingchang Lu #define WATER_TXWATER_OFF	1
476209e14cSJingchang Lu #define WATER_RXWATER_OFF	16
486209e14cSJingchang Lu 
49427eba70SAlison Wang DECLARE_GLOBAL_DATA_PTR;
50427eba70SAlison Wang 
51427eba70SAlison Wang struct lpuart_fsl *base = (struct lpuart_fsl *)LPUART_BASE;
52427eba70SAlison Wang 
53*fdbae099SBin Meng struct lpuart_serial_platdata {
54*fdbae099SBin Meng 	struct lpuart_fsl *reg;
55*fdbae099SBin Meng };
56*fdbae099SBin Meng 
576209e14cSJingchang Lu #ifndef CONFIG_LPUART_32B_REG
586ca13b12SBin Meng static void _lpuart_serial_setbrg(struct lpuart_fsl *base, int baudrate)
59427eba70SAlison Wang {
60427eba70SAlison Wang 	u32 clk = mxc_get_clock(MXC_UART_CLK);
61427eba70SAlison Wang 	u16 sbr;
62427eba70SAlison Wang 
636ca13b12SBin Meng 	sbr = (u16)(clk / (16 * baudrate));
64427eba70SAlison Wang 
6547f1bfcaSBin Meng 	/* place adjustment later - n/32 BRFA */
66427eba70SAlison Wang 	__raw_writeb(sbr >> 8, &base->ubdh);
67427eba70SAlison Wang 	__raw_writeb(sbr & 0xff, &base->ubdl);
68427eba70SAlison Wang }
69427eba70SAlison Wang 
706ca13b12SBin Meng static int _lpuart_serial_getc(struct lpuart_fsl *base)
71427eba70SAlison Wang {
72a3db78d8SStefan Agner 	while (!(__raw_readb(&base->us1) & (US1_RDRF | US1_OR)))
73427eba70SAlison Wang 		WATCHDOG_RESET();
74427eba70SAlison Wang 
75a3db78d8SStefan Agner 	barrier();
76427eba70SAlison Wang 
77427eba70SAlison Wang 	return __raw_readb(&base->ud);
78427eba70SAlison Wang }
79427eba70SAlison Wang 
806ca13b12SBin Meng static void _lpuart_serial_putc(struct lpuart_fsl *base, const char c)
81427eba70SAlison Wang {
82427eba70SAlison Wang 	if (c == '\n')
836ca13b12SBin Meng 		_lpuart_serial_putc(base, '\r');
84427eba70SAlison Wang 
85427eba70SAlison Wang 	while (!(__raw_readb(&base->us1) & US1_TDRE))
86427eba70SAlison Wang 		WATCHDOG_RESET();
87427eba70SAlison Wang 
88427eba70SAlison Wang 	__raw_writeb(c, &base->ud);
89427eba70SAlison Wang }
90427eba70SAlison Wang 
9147f1bfcaSBin Meng /* Test whether a character is in the RX buffer */
926ca13b12SBin Meng static int _lpuart_serial_tstc(struct lpuart_fsl *base)
93427eba70SAlison Wang {
94427eba70SAlison Wang 	if (__raw_readb(&base->urcfifo) == 0)
95427eba70SAlison Wang 		return 0;
96427eba70SAlison Wang 
97427eba70SAlison Wang 	return 1;
98427eba70SAlison Wang }
99427eba70SAlison Wang 
100427eba70SAlison Wang /*
101427eba70SAlison Wang  * Initialise the serial port with the given baudrate. The settings
102427eba70SAlison Wang  * are always 8 data bits, no parity, 1 stop bit, no start bits.
103427eba70SAlison Wang  */
1046ca13b12SBin Meng static int _lpuart_serial_init(struct lpuart_fsl *base)
105427eba70SAlison Wang {
106427eba70SAlison Wang 	u8 ctrl;
107427eba70SAlison Wang 
108427eba70SAlison Wang 	ctrl = __raw_readb(&base->uc2);
109427eba70SAlison Wang 	ctrl &= ~UC2_RE;
110427eba70SAlison Wang 	ctrl &= ~UC2_TE;
111427eba70SAlison Wang 	__raw_writeb(ctrl, &base->uc2);
112427eba70SAlison Wang 
113427eba70SAlison Wang 	__raw_writeb(0, &base->umodem);
114427eba70SAlison Wang 	__raw_writeb(0, &base->uc1);
115427eba70SAlison Wang 
11689e69fd4SStefan Agner 	/* Disable FIFO and flush buffer */
11789e69fd4SStefan Agner 	__raw_writeb(0x0, &base->upfifo);
11889e69fd4SStefan Agner 	__raw_writeb(0x0, &base->utwfifo);
11989e69fd4SStefan Agner 	__raw_writeb(0x1, &base->urwfifo);
12089e69fd4SStefan Agner 	__raw_writeb(CFIFO_TXFLUSH | CFIFO_RXFLUSH, &base->ucfifo);
12189e69fd4SStefan Agner 
122427eba70SAlison Wang 	/* provide data bits, parity, stop bit, etc */
1236ca13b12SBin Meng 	_lpuart_serial_setbrg(base, gd->baudrate);
124427eba70SAlison Wang 
125427eba70SAlison Wang 	__raw_writeb(UC2_RE | UC2_TE, &base->uc2);
126427eba70SAlison Wang 
127427eba70SAlison Wang 	return 0;
128427eba70SAlison Wang }
129427eba70SAlison Wang 
130*fdbae099SBin Meng #ifndef CONFIG_DM_SERIAL
1316ca13b12SBin Meng static void lpuart_serial_setbrg(void)
1326ca13b12SBin Meng {
1336ca13b12SBin Meng 	_lpuart_serial_setbrg(base, gd->baudrate);
1346ca13b12SBin Meng }
1356ca13b12SBin Meng 
1366ca13b12SBin Meng static int lpuart_serial_getc(void)
1376ca13b12SBin Meng {
1386ca13b12SBin Meng 	return _lpuart_serial_getc(base);
1396ca13b12SBin Meng }
1406ca13b12SBin Meng 
1416ca13b12SBin Meng static void lpuart_serial_putc(const char c)
1426ca13b12SBin Meng {
1436ca13b12SBin Meng 	_lpuart_serial_putc(base, c);
1446ca13b12SBin Meng }
1456ca13b12SBin Meng 
1466ca13b12SBin Meng static int lpuart_serial_tstc(void)
1476ca13b12SBin Meng {
1486ca13b12SBin Meng 	return _lpuart_serial_tstc(base);
1496ca13b12SBin Meng }
1506ca13b12SBin Meng 
1516ca13b12SBin Meng static int lpuart_serial_init(void)
1526ca13b12SBin Meng {
1536ca13b12SBin Meng 	return _lpuart_serial_init(base);
1546ca13b12SBin Meng }
1556ca13b12SBin Meng 
156427eba70SAlison Wang static struct serial_device lpuart_serial_drv = {
157427eba70SAlison Wang 	.name = "lpuart_serial",
158427eba70SAlison Wang 	.start = lpuart_serial_init,
159427eba70SAlison Wang 	.stop = NULL,
160427eba70SAlison Wang 	.setbrg = lpuart_serial_setbrg,
161427eba70SAlison Wang 	.putc = lpuart_serial_putc,
162427eba70SAlison Wang 	.puts = default_serial_puts,
163427eba70SAlison Wang 	.getc = lpuart_serial_getc,
164427eba70SAlison Wang 	.tstc = lpuart_serial_tstc,
165427eba70SAlison Wang };
166*fdbae099SBin Meng #else /* CONFIG_DM_SERIAL */
167*fdbae099SBin Meng static int lpuart_serial_setbrg(struct udevice *dev, int baudrate)
168*fdbae099SBin Meng {
169*fdbae099SBin Meng 	struct lpuart_serial_platdata *plat = dev->platdata;
170*fdbae099SBin Meng 	struct lpuart_fsl *reg = plat->reg;
171*fdbae099SBin Meng 
172*fdbae099SBin Meng 	_lpuart_serial_setbrg(reg, baudrate);
173*fdbae099SBin Meng 
174*fdbae099SBin Meng 	return 0;
175*fdbae099SBin Meng }
176*fdbae099SBin Meng 
177*fdbae099SBin Meng static int lpuart_serial_getc(struct udevice *dev)
178*fdbae099SBin Meng {
179*fdbae099SBin Meng 	struct lpuart_serial_platdata *plat = dev->platdata;
180*fdbae099SBin Meng 	struct lpuart_fsl *reg = plat->reg;
181*fdbae099SBin Meng 
182*fdbae099SBin Meng 	return _lpuart_serial_getc(reg);
183*fdbae099SBin Meng }
184*fdbae099SBin Meng 
185*fdbae099SBin Meng static int lpuart_serial_putc(struct udevice *dev, const char c)
186*fdbae099SBin Meng {
187*fdbae099SBin Meng 	struct lpuart_serial_platdata *plat = dev->platdata;
188*fdbae099SBin Meng 	struct lpuart_fsl *reg = plat->reg;
189*fdbae099SBin Meng 
190*fdbae099SBin Meng 	_lpuart_serial_putc(reg, c);
191*fdbae099SBin Meng 
192*fdbae099SBin Meng 	return 0;
193*fdbae099SBin Meng }
194*fdbae099SBin Meng 
195*fdbae099SBin Meng static int lpuart_serial_pending(struct udevice *dev, bool input)
196*fdbae099SBin Meng {
197*fdbae099SBin Meng 	struct lpuart_serial_platdata *plat = dev->platdata;
198*fdbae099SBin Meng 	struct lpuart_fsl *reg = plat->reg;
199*fdbae099SBin Meng 
200*fdbae099SBin Meng 	if (input)
201*fdbae099SBin Meng 		return _lpuart_serial_tstc(reg);
202*fdbae099SBin Meng 	else
203*fdbae099SBin Meng 		return __raw_readb(&reg->us1) & US1_TDRE ? 0 : 1;
204*fdbae099SBin Meng }
205*fdbae099SBin Meng 
206*fdbae099SBin Meng static int lpuart_serial_probe(struct udevice *dev)
207*fdbae099SBin Meng {
208*fdbae099SBin Meng 	struct lpuart_serial_platdata *plat = dev->platdata;
209*fdbae099SBin Meng 	struct lpuart_fsl *reg = plat->reg;
210*fdbae099SBin Meng 
211*fdbae099SBin Meng 	return _lpuart_serial_init(reg);
212*fdbae099SBin Meng }
213*fdbae099SBin Meng #endif /* CONFIG_DM_SERIAL */
2146209e14cSJingchang Lu #else
2156ca13b12SBin Meng static void _lpuart32_serial_setbrg(struct lpuart_fsl *base, int baudrate)
2166209e14cSJingchang Lu {
2176209e14cSJingchang Lu 	u32 clk = CONFIG_SYS_CLK_FREQ;
2186209e14cSJingchang Lu 	u32 sbr;
2196209e14cSJingchang Lu 
2206ca13b12SBin Meng 	sbr = (clk / (16 * baudrate));
2216209e14cSJingchang Lu 
22247f1bfcaSBin Meng 	/* place adjustment later - n/32 BRFA */
2236209e14cSJingchang Lu 	out_be32(&base->baud, sbr);
2246209e14cSJingchang Lu }
2256209e14cSJingchang Lu 
2266ca13b12SBin Meng static int _lpuart32_serial_getc(struct lpuart_fsl *base)
2276209e14cSJingchang Lu {
2286209e14cSJingchang Lu 	u32 stat;
2296209e14cSJingchang Lu 
2306209e14cSJingchang Lu 	while (((stat = in_be32(&base->stat)) & STAT_RDRF) == 0) {
2316209e14cSJingchang Lu 		out_be32(&base->stat, STAT_FLAGS);
2326209e14cSJingchang Lu 		WATCHDOG_RESET();
2336209e14cSJingchang Lu 	}
2346209e14cSJingchang Lu 
2356209e14cSJingchang Lu 	return in_be32(&base->data) & 0x3ff;
2366209e14cSJingchang Lu }
2376209e14cSJingchang Lu 
2386ca13b12SBin Meng static void _lpuart32_serial_putc(struct lpuart_fsl *base, const char c)
2396209e14cSJingchang Lu {
2406209e14cSJingchang Lu 	if (c == '\n')
2416ca13b12SBin Meng 		_lpuart32_serial_putc(base, '\r');
2426209e14cSJingchang Lu 
2436209e14cSJingchang Lu 	while (!(in_be32(&base->stat) & STAT_TDRE))
2446209e14cSJingchang Lu 		WATCHDOG_RESET();
2456209e14cSJingchang Lu 
2466209e14cSJingchang Lu 	out_be32(&base->data, c);
2476209e14cSJingchang Lu }
2486209e14cSJingchang Lu 
24947f1bfcaSBin Meng /* Test whether a character is in the RX buffer */
2506ca13b12SBin Meng static int _lpuart32_serial_tstc(struct lpuart_fsl *base)
2516209e14cSJingchang Lu {
2526209e14cSJingchang Lu 	if ((in_be32(&base->water) >> 24) == 0)
2536209e14cSJingchang Lu 		return 0;
2546209e14cSJingchang Lu 
2556209e14cSJingchang Lu 	return 1;
2566209e14cSJingchang Lu }
2576209e14cSJingchang Lu 
2586209e14cSJingchang Lu /*
2596209e14cSJingchang Lu  * Initialise the serial port with the given baudrate. The settings
2606209e14cSJingchang Lu  * are always 8 data bits, no parity, 1 stop bit, no start bits.
2616209e14cSJingchang Lu  */
2626ca13b12SBin Meng static int _lpuart32_serial_init(struct lpuart_fsl *base)
2636209e14cSJingchang Lu {
2646209e14cSJingchang Lu 	u8 ctrl;
2656209e14cSJingchang Lu 
2666209e14cSJingchang Lu 	ctrl = in_be32(&base->ctrl);
2676209e14cSJingchang Lu 	ctrl &= ~CTRL_RE;
2686209e14cSJingchang Lu 	ctrl &= ~CTRL_TE;
2696209e14cSJingchang Lu 	out_be32(&base->ctrl, ctrl);
2706209e14cSJingchang Lu 
2716209e14cSJingchang Lu 	out_be32(&base->modir, 0);
2726209e14cSJingchang Lu 	out_be32(&base->fifo, ~(FIFO_TXFE | FIFO_RXFE));
2736209e14cSJingchang Lu 
2746209e14cSJingchang Lu 	out_be32(&base->match, 0);
2756209e14cSJingchang Lu 
27647f1bfcaSBin Meng 	/* provide data bits, parity, stop bit, etc */
2776ca13b12SBin Meng 	_lpuart32_serial_setbrg(base, gd->baudrate);
2786209e14cSJingchang Lu 
2796209e14cSJingchang Lu 	out_be32(&base->ctrl, CTRL_RE | CTRL_TE);
2806209e14cSJingchang Lu 
2816209e14cSJingchang Lu 	return 0;
2826209e14cSJingchang Lu }
2836209e14cSJingchang Lu 
284*fdbae099SBin Meng #ifndef CONFIG_DM_SERIAL
2856ca13b12SBin Meng static void lpuart32_serial_setbrg(void)
2866ca13b12SBin Meng {
2876ca13b12SBin Meng 	_lpuart32_serial_setbrg(base, gd->baudrate);
2886ca13b12SBin Meng }
2896ca13b12SBin Meng 
2906ca13b12SBin Meng static int lpuart32_serial_getc(void)
2916ca13b12SBin Meng {
2926ca13b12SBin Meng 	return _lpuart32_serial_getc(base);
2936ca13b12SBin Meng }
2946ca13b12SBin Meng 
2956ca13b12SBin Meng static void lpuart32_serial_putc(const char c)
2966ca13b12SBin Meng {
2976ca13b12SBin Meng 	_lpuart32_serial_putc(base, c);
2986ca13b12SBin Meng }
2996ca13b12SBin Meng 
3006ca13b12SBin Meng static int lpuart32_serial_tstc(void)
3016ca13b12SBin Meng {
3026ca13b12SBin Meng 	return _lpuart32_serial_tstc(base);
3036ca13b12SBin Meng }
3046ca13b12SBin Meng 
3056ca13b12SBin Meng static int lpuart32_serial_init(void)
3066ca13b12SBin Meng {
3076ca13b12SBin Meng 	return _lpuart32_serial_init(base);
3086ca13b12SBin Meng }
3096ca13b12SBin Meng 
3106209e14cSJingchang Lu static struct serial_device lpuart32_serial_drv = {
3116209e14cSJingchang Lu 	.name = "lpuart32_serial",
3126209e14cSJingchang Lu 	.start = lpuart32_serial_init,
3136209e14cSJingchang Lu 	.stop = NULL,
3146209e14cSJingchang Lu 	.setbrg = lpuart32_serial_setbrg,
3156209e14cSJingchang Lu 	.putc = lpuart32_serial_putc,
3166209e14cSJingchang Lu 	.puts = default_serial_puts,
3176209e14cSJingchang Lu 	.getc = lpuart32_serial_getc,
3186209e14cSJingchang Lu 	.tstc = lpuart32_serial_tstc,
3196209e14cSJingchang Lu };
320*fdbae099SBin Meng #else /* CONFIG_DM_SERIAL */
321*fdbae099SBin Meng static int lpuart32_serial_setbrg(struct udevice *dev, int baudrate)
322*fdbae099SBin Meng {
323*fdbae099SBin Meng 	struct lpuart_serial_platdata *plat = dev->platdata;
324*fdbae099SBin Meng 	struct lpuart_fsl *reg = plat->reg;
325*fdbae099SBin Meng 
326*fdbae099SBin Meng 	_lpuart32_serial_setbrg(reg, baudrate);
327*fdbae099SBin Meng 
328*fdbae099SBin Meng 	return 0;
329*fdbae099SBin Meng }
330*fdbae099SBin Meng 
331*fdbae099SBin Meng static int lpuart32_serial_getc(struct udevice *dev)
332*fdbae099SBin Meng {
333*fdbae099SBin Meng 	struct lpuart_serial_platdata *plat = dev->platdata;
334*fdbae099SBin Meng 	struct lpuart_fsl *reg = plat->reg;
335*fdbae099SBin Meng 
336*fdbae099SBin Meng 	return _lpuart32_serial_getc(reg);
337*fdbae099SBin Meng }
338*fdbae099SBin Meng 
339*fdbae099SBin Meng static int lpuart32_serial_putc(struct udevice *dev, const char c)
340*fdbae099SBin Meng {
341*fdbae099SBin Meng 	struct lpuart_serial_platdata *plat = dev->platdata;
342*fdbae099SBin Meng 	struct lpuart_fsl *reg = plat->reg;
343*fdbae099SBin Meng 
344*fdbae099SBin Meng 	_lpuart32_serial_putc(reg, c);
345*fdbae099SBin Meng 
346*fdbae099SBin Meng 	return 0;
347*fdbae099SBin Meng }
348*fdbae099SBin Meng 
349*fdbae099SBin Meng static int lpuart32_serial_pending(struct udevice *dev, bool input)
350*fdbae099SBin Meng {
351*fdbae099SBin Meng 	struct lpuart_serial_platdata *plat = dev->platdata;
352*fdbae099SBin Meng 	struct lpuart_fsl *reg = plat->reg;
353*fdbae099SBin Meng 
354*fdbae099SBin Meng 	if (input)
355*fdbae099SBin Meng 		return _lpuart32_serial_tstc(reg);
356*fdbae099SBin Meng 	else
357*fdbae099SBin Meng 		return in_be32(&reg->stat) & STAT_TDRE ? 0 : 1;
358*fdbae099SBin Meng }
359*fdbae099SBin Meng 
360*fdbae099SBin Meng static int lpuart32_serial_probe(struct udevice *dev)
361*fdbae099SBin Meng {
362*fdbae099SBin Meng 	struct lpuart_serial_platdata *plat = dev->platdata;
363*fdbae099SBin Meng 	struct lpuart_fsl *reg = plat->reg;
364*fdbae099SBin Meng 
365*fdbae099SBin Meng 	return _lpuart32_serial_init(reg);
366*fdbae099SBin Meng }
367*fdbae099SBin Meng #endif /* CONFIG_DM_SERIAL */
3686209e14cSJingchang Lu #endif
369427eba70SAlison Wang 
370*fdbae099SBin Meng #ifndef CONFIG_DM_SERIAL
371427eba70SAlison Wang void lpuart_serial_initialize(void)
372427eba70SAlison Wang {
3736209e14cSJingchang Lu #ifdef CONFIG_LPUART_32B_REG
3746209e14cSJingchang Lu 	serial_register(&lpuart32_serial_drv);
3756209e14cSJingchang Lu #else
376427eba70SAlison Wang 	serial_register(&lpuart_serial_drv);
3776209e14cSJingchang Lu #endif
378427eba70SAlison Wang }
379427eba70SAlison Wang 
380427eba70SAlison Wang __weak struct serial_device *default_serial_console(void)
381427eba70SAlison Wang {
3826209e14cSJingchang Lu #ifdef CONFIG_LPUART_32B_REG
3836209e14cSJingchang Lu 	return &lpuart32_serial_drv;
3846209e14cSJingchang Lu #else
385427eba70SAlison Wang 	return &lpuart_serial_drv;
3866209e14cSJingchang Lu #endif
387427eba70SAlison Wang }
388*fdbae099SBin Meng #else /* CONFIG_DM_SERIAL */
389*fdbae099SBin Meng static int lpuart_serial_ofdata_to_platdata(struct udevice *dev)
390*fdbae099SBin Meng {
391*fdbae099SBin Meng 	struct lpuart_serial_platdata *plat = dev->platdata;
392*fdbae099SBin Meng 	fdt_addr_t addr;
393*fdbae099SBin Meng 
394*fdbae099SBin Meng 	addr = dev_get_addr(dev);
395*fdbae099SBin Meng 	if (addr == FDT_ADDR_T_NONE)
396*fdbae099SBin Meng 		return -EINVAL;
397*fdbae099SBin Meng 
398*fdbae099SBin Meng 	plat->reg = (struct lpuart_fsl *)addr;
399*fdbae099SBin Meng 
400*fdbae099SBin Meng 	return 0;
401*fdbae099SBin Meng }
402*fdbae099SBin Meng 
403*fdbae099SBin Meng #ifndef CONFIG_LPUART_32B_REG
404*fdbae099SBin Meng static const struct dm_serial_ops lpuart_serial_ops = {
405*fdbae099SBin Meng 	.putc = lpuart_serial_putc,
406*fdbae099SBin Meng 	.pending = lpuart_serial_pending,
407*fdbae099SBin Meng 	.getc = lpuart_serial_getc,
408*fdbae099SBin Meng 	.setbrg = lpuart_serial_setbrg,
409*fdbae099SBin Meng };
410*fdbae099SBin Meng 
411*fdbae099SBin Meng static const struct udevice_id lpuart_serial_ids[] = {
412*fdbae099SBin Meng 	{ .compatible = "fsl,vf610-lpuart" },
413*fdbae099SBin Meng 	{ }
414*fdbae099SBin Meng };
415*fdbae099SBin Meng 
416*fdbae099SBin Meng U_BOOT_DRIVER(serial_lpuart) = {
417*fdbae099SBin Meng 	.name	= "serial_lpuart",
418*fdbae099SBin Meng 	.id	= UCLASS_SERIAL,
419*fdbae099SBin Meng 	.of_match = lpuart_serial_ids,
420*fdbae099SBin Meng 	.ofdata_to_platdata = lpuart_serial_ofdata_to_platdata,
421*fdbae099SBin Meng 	.platdata_auto_alloc_size = sizeof(struct lpuart_serial_platdata),
422*fdbae099SBin Meng 	.probe = lpuart_serial_probe,
423*fdbae099SBin Meng 	.ops	= &lpuart_serial_ops,
424*fdbae099SBin Meng 	.flags = DM_FLAG_PRE_RELOC,
425*fdbae099SBin Meng };
426*fdbae099SBin Meng #else /* CONFIG_LPUART_32B_REG */
427*fdbae099SBin Meng static const struct dm_serial_ops lpuart32_serial_ops = {
428*fdbae099SBin Meng 	.putc = lpuart32_serial_putc,
429*fdbae099SBin Meng 	.pending = lpuart32_serial_pending,
430*fdbae099SBin Meng 	.getc = lpuart32_serial_getc,
431*fdbae099SBin Meng 	.setbrg = lpuart32_serial_setbrg,
432*fdbae099SBin Meng };
433*fdbae099SBin Meng 
434*fdbae099SBin Meng static const struct udevice_id lpuart32_serial_ids[] = {
435*fdbae099SBin Meng 	{ .compatible = "fsl,ls1021a-lpuart" },
436*fdbae099SBin Meng 	{ }
437*fdbae099SBin Meng };
438*fdbae099SBin Meng 
439*fdbae099SBin Meng U_BOOT_DRIVER(serial_lpuart32) = {
440*fdbae099SBin Meng 	.name	= "serial_lpuart32",
441*fdbae099SBin Meng 	.id	= UCLASS_SERIAL,
442*fdbae099SBin Meng 	.of_match = lpuart32_serial_ids,
443*fdbae099SBin Meng 	.ofdata_to_platdata = lpuart_serial_ofdata_to_platdata,
444*fdbae099SBin Meng 	.platdata_auto_alloc_size = sizeof(struct lpuart_serial_platdata),
445*fdbae099SBin Meng 	.probe = lpuart32_serial_probe,
446*fdbae099SBin Meng 	.ops	= &lpuart32_serial_ops,
447*fdbae099SBin Meng 	.flags = DM_FLAG_PRE_RELOC,
448*fdbae099SBin Meng };
449*fdbae099SBin Meng #endif /* CONFIG_LPUART_32B_REG */
450*fdbae099SBin Meng #endif /* CONFIG_DM_SERIAL */
451