xref: /rk3399_rockchip-uboot/drivers/serial/serial_pxa.c (revision 2d221489df021393654805536be7effcb9d39702)
1379be585SJean-Christophe PLAGNIOL-VILLARD /*
2237ce0feSMarek Vasut  * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
3237ce0feSMarek Vasut  *
4379be585SJean-Christophe PLAGNIOL-VILLARD  * (C) Copyright 2002
5379be585SJean-Christophe PLAGNIOL-VILLARD  * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
6379be585SJean-Christophe PLAGNIOL-VILLARD  *
7379be585SJean-Christophe PLAGNIOL-VILLARD  * (C) Copyright 2002
8379be585SJean-Christophe PLAGNIOL-VILLARD  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
9379be585SJean-Christophe PLAGNIOL-VILLARD  * Marius Groeger <mgroeger@sysgo.de>
10379be585SJean-Christophe PLAGNIOL-VILLARD  *
11379be585SJean-Christophe PLAGNIOL-VILLARD  * (C) Copyright 2002
12379be585SJean-Christophe PLAGNIOL-VILLARD  * Sysgo Real-Time Solutions, GmbH <www.elinos.com>
13379be585SJean-Christophe PLAGNIOL-VILLARD  * Alex Zuepke <azu@sysgo.de>
14379be585SJean-Christophe PLAGNIOL-VILLARD  *
15379be585SJean-Christophe PLAGNIOL-VILLARD  * Copyright (C) 1999 2000 2001 Erik Mouw (J.A.K.Mouw@its.tudelft.nl)
16379be585SJean-Christophe PLAGNIOL-VILLARD  *
17*cbfa67a1SMarcel Ziswiler  * Modified to add driver model (DM) support
18*cbfa67a1SMarcel Ziswiler  * (C) Copyright 2016 Marcel Ziswiler <marcel.ziswiler@toradex.com>
19*cbfa67a1SMarcel Ziswiler  *
201a459660SWolfgang Denk  * SPDX-License-Identifier:	GPL-2.0+
21379be585SJean-Christophe PLAGNIOL-VILLARD  */
22379be585SJean-Christophe PLAGNIOL-VILLARD 
23379be585SJean-Christophe PLAGNIOL-VILLARD #include <common.h>
24379be585SJean-Christophe PLAGNIOL-VILLARD #include <asm/arch/pxa-regs.h>
25237ce0feSMarek Vasut #include <asm/arch/regs-uart.h>
263ba8bf7cSMarek Vasut #include <asm/io.h>
27*cbfa67a1SMarcel Ziswiler #include <dm.h>
28*cbfa67a1SMarcel Ziswiler #include <dm/platform_data/serial_pxa.h>
29407e6a28SMarek Vasut #include <linux/compiler.h>
308648b235SMarcel Ziswiler #include <serial.h>
318648b235SMarcel Ziswiler #include <watchdog.h>
32379be585SJean-Christophe PLAGNIOL-VILLARD 
33379be585SJean-Christophe PLAGNIOL-VILLARD DECLARE_GLOBAL_DATA_PTR;
34379be585SJean-Christophe PLAGNIOL-VILLARD 
pxa_uart_get_baud_divider(int baudrate)35*cbfa67a1SMarcel Ziswiler static uint32_t pxa_uart_get_baud_divider(int baudrate)
36379be585SJean-Christophe PLAGNIOL-VILLARD {
37*cbfa67a1SMarcel Ziswiler 	return 921600 / baudrate;
38379be585SJean-Christophe PLAGNIOL-VILLARD }
39379be585SJean-Christophe PLAGNIOL-VILLARD 
pxa_uart_toggle_clock(uint32_t uart_index,int enable)404808f106SMarek Vasut static void pxa_uart_toggle_clock(uint32_t uart_index, int enable)
41237ce0feSMarek Vasut {
42237ce0feSMarek Vasut 	uint32_t clk_reg, clk_offset, reg;
43237ce0feSMarek Vasut 
44237ce0feSMarek Vasut 	clk_reg = UART_CLK_REG;
45237ce0feSMarek Vasut 	clk_offset = UART_CLK_BASE << uart_index;
46237ce0feSMarek Vasut 
47237ce0feSMarek Vasut 	reg = readl(clk_reg);
48237ce0feSMarek Vasut 
49237ce0feSMarek Vasut 	if (enable)
50237ce0feSMarek Vasut 		reg |= clk_offset;
51237ce0feSMarek Vasut 	else
52237ce0feSMarek Vasut 		reg &= ~clk_offset;
53237ce0feSMarek Vasut 
54237ce0feSMarek Vasut 	writel(reg, clk_reg);
55237ce0feSMarek Vasut }
56237ce0feSMarek Vasut 
57237ce0feSMarek Vasut /*
58237ce0feSMarek Vasut  * Enable clock and set baud rate, parity etc.
59237ce0feSMarek Vasut  */
pxa_setbrg_common(struct pxa_uart_regs * uart_regs,int port,int baudrate)60*cbfa67a1SMarcel Ziswiler void pxa_setbrg_common(struct pxa_uart_regs *uart_regs, int port, int baudrate)
61237ce0feSMarek Vasut {
62*cbfa67a1SMarcel Ziswiler 	uint32_t divider = pxa_uart_get_baud_divider(baudrate);
63237ce0feSMarek Vasut 	if (!divider)
64237ce0feSMarek Vasut 		hang();
65237ce0feSMarek Vasut 
66237ce0feSMarek Vasut 
67*cbfa67a1SMarcel Ziswiler 	pxa_uart_toggle_clock(port, 1);
68237ce0feSMarek Vasut 
69237ce0feSMarek Vasut 	/* Disable interrupts and FIFOs */
70237ce0feSMarek Vasut 	writel(0, &uart_regs->ier);
71237ce0feSMarek Vasut 	writel(0, &uart_regs->fcr);
72237ce0feSMarek Vasut 
73237ce0feSMarek Vasut 	/* Set baud rate */
74237ce0feSMarek Vasut 	writel(LCR_WLS0 | LCR_WLS1 | LCR_DLAB, &uart_regs->lcr);
75237ce0feSMarek Vasut 	writel(divider & 0xff, &uart_regs->dll);
76237ce0feSMarek Vasut 	writel(divider >> 8, &uart_regs->dlh);
77237ce0feSMarek Vasut 	writel(LCR_WLS0 | LCR_WLS1, &uart_regs->lcr);
78237ce0feSMarek Vasut 
79237ce0feSMarek Vasut 	/* Enable UART */
80237ce0feSMarek Vasut 	writel(IER_UUE, &uart_regs->ier);
81237ce0feSMarek Vasut }
82379be585SJean-Christophe PLAGNIOL-VILLARD 
83*cbfa67a1SMarcel Ziswiler #ifndef CONFIG_DM_SERIAL
pxa_uart_index_to_regs(uint32_t uart_index)84*cbfa67a1SMarcel Ziswiler static struct pxa_uart_regs *pxa_uart_index_to_regs(uint32_t uart_index)
85*cbfa67a1SMarcel Ziswiler {
86*cbfa67a1SMarcel Ziswiler 	switch (uart_index) {
87*cbfa67a1SMarcel Ziswiler 	case FFUART_INDEX: return (struct pxa_uart_regs *)FFUART_BASE;
88*cbfa67a1SMarcel Ziswiler 	case BTUART_INDEX: return (struct pxa_uart_regs *)BTUART_BASE;
89*cbfa67a1SMarcel Ziswiler 	case STUART_INDEX: return (struct pxa_uart_regs *)STUART_BASE;
90*cbfa67a1SMarcel Ziswiler 	case HWUART_INDEX: return (struct pxa_uart_regs *)HWUART_BASE;
91*cbfa67a1SMarcel Ziswiler 	default:
92*cbfa67a1SMarcel Ziswiler 		return NULL;
93*cbfa67a1SMarcel Ziswiler 	}
94*cbfa67a1SMarcel Ziswiler }
95*cbfa67a1SMarcel Ziswiler 
96*cbfa67a1SMarcel Ziswiler /*
97*cbfa67a1SMarcel Ziswiler  * Enable clock and set baud rate, parity etc.
98*cbfa67a1SMarcel Ziswiler  */
pxa_setbrg_dev(uint32_t uart_index)99*cbfa67a1SMarcel Ziswiler void pxa_setbrg_dev(uint32_t uart_index)
100*cbfa67a1SMarcel Ziswiler {
101*cbfa67a1SMarcel Ziswiler 	struct pxa_uart_regs *uart_regs = pxa_uart_index_to_regs(uart_index);
102*cbfa67a1SMarcel Ziswiler 	if (!uart_regs)
103*cbfa67a1SMarcel Ziswiler 		panic("Failed getting UART registers\n");
104*cbfa67a1SMarcel Ziswiler 
105*cbfa67a1SMarcel Ziswiler 	pxa_setbrg_common(uart_regs, uart_index, gd->baudrate);
106*cbfa67a1SMarcel Ziswiler }
107*cbfa67a1SMarcel Ziswiler 
108379be585SJean-Christophe PLAGNIOL-VILLARD /*
109379be585SJean-Christophe PLAGNIOL-VILLARD  * Initialise the serial port with the given baudrate. The settings
110379be585SJean-Christophe PLAGNIOL-VILLARD  * are always 8 data bits, no parity, 1 stop bit, no start bits.
111379be585SJean-Christophe PLAGNIOL-VILLARD  */
pxa_init_dev(unsigned int uart_index)112379be585SJean-Christophe PLAGNIOL-VILLARD int pxa_init_dev(unsigned int uart_index)
113379be585SJean-Christophe PLAGNIOL-VILLARD {
114379be585SJean-Christophe PLAGNIOL-VILLARD 	pxa_setbrg_dev(uart_index);
115237ce0feSMarek Vasut 	return 0;
116379be585SJean-Christophe PLAGNIOL-VILLARD }
117379be585SJean-Christophe PLAGNIOL-VILLARD 
118379be585SJean-Christophe PLAGNIOL-VILLARD /*
119379be585SJean-Christophe PLAGNIOL-VILLARD  * Output a single byte to the serial port.
120379be585SJean-Christophe PLAGNIOL-VILLARD  */
pxa_putc_dev(unsigned int uart_index,const char c)121379be585SJean-Christophe PLAGNIOL-VILLARD void pxa_putc_dev(unsigned int uart_index, const char c)
122379be585SJean-Christophe PLAGNIOL-VILLARD {
123237ce0feSMarek Vasut 	struct pxa_uart_regs *uart_regs;
124379be585SJean-Christophe PLAGNIOL-VILLARD 
125055457efSAlison Wang 	/* If \n, also do \r */
126055457efSAlison Wang 	if (c == '\n')
127055457efSAlison Wang 		pxa_putc_dev(uart_index, '\r');
128055457efSAlison Wang 
129237ce0feSMarek Vasut 	uart_regs = pxa_uart_index_to_regs(uart_index);
130237ce0feSMarek Vasut 	if (!uart_regs)
131237ce0feSMarek Vasut 		hang();
132379be585SJean-Christophe PLAGNIOL-VILLARD 
133237ce0feSMarek Vasut 	while (!(readl(&uart_regs->lsr) & LSR_TEMT))
134237ce0feSMarek Vasut 		WATCHDOG_RESET();
135237ce0feSMarek Vasut 	writel(c, &uart_regs->thr);
136379be585SJean-Christophe PLAGNIOL-VILLARD }
137379be585SJean-Christophe PLAGNIOL-VILLARD 
138379be585SJean-Christophe PLAGNIOL-VILLARD /*
139379be585SJean-Christophe PLAGNIOL-VILLARD  * Read a single byte from the serial port. Returns 1 on success, 0
140379be585SJean-Christophe PLAGNIOL-VILLARD  * otherwise. When the function is succesfull, the character read is
141379be585SJean-Christophe PLAGNIOL-VILLARD  * written into its argument c.
142379be585SJean-Christophe PLAGNIOL-VILLARD  */
pxa_tstc_dev(unsigned int uart_index)143379be585SJean-Christophe PLAGNIOL-VILLARD int pxa_tstc_dev(unsigned int uart_index)
144379be585SJean-Christophe PLAGNIOL-VILLARD {
145237ce0feSMarek Vasut 	struct pxa_uart_regs *uart_regs;
146237ce0feSMarek Vasut 
147237ce0feSMarek Vasut 	uart_regs = pxa_uart_index_to_regs(uart_index);
148237ce0feSMarek Vasut 	if (!uart_regs)
149379be585SJean-Christophe PLAGNIOL-VILLARD 		return -1;
150237ce0feSMarek Vasut 
151237ce0feSMarek Vasut 	return readl(&uart_regs->lsr) & LSR_DR;
152379be585SJean-Christophe PLAGNIOL-VILLARD }
153379be585SJean-Christophe PLAGNIOL-VILLARD 
154379be585SJean-Christophe PLAGNIOL-VILLARD /*
155379be585SJean-Christophe PLAGNIOL-VILLARD  * Read a single byte from the serial port. Returns 1 on success, 0
156379be585SJean-Christophe PLAGNIOL-VILLARD  * otherwise. When the function is succesfull, the character read is
157379be585SJean-Christophe PLAGNIOL-VILLARD  * written into its argument c.
158379be585SJean-Christophe PLAGNIOL-VILLARD  */
pxa_getc_dev(unsigned int uart_index)159379be585SJean-Christophe PLAGNIOL-VILLARD int pxa_getc_dev(unsigned int uart_index)
160379be585SJean-Christophe PLAGNIOL-VILLARD {
161237ce0feSMarek Vasut 	struct pxa_uart_regs *uart_regs;
162379be585SJean-Christophe PLAGNIOL-VILLARD 
163237ce0feSMarek Vasut 	uart_regs = pxa_uart_index_to_regs(uart_index);
164237ce0feSMarek Vasut 	if (!uart_regs)
165379be585SJean-Christophe PLAGNIOL-VILLARD 		return -1;
166237ce0feSMarek Vasut 
167237ce0feSMarek Vasut 	while (!(readl(&uart_regs->lsr) & LSR_DR))
168237ce0feSMarek Vasut 		WATCHDOG_RESET();
169237ce0feSMarek Vasut 	return readl(&uart_regs->rbr) & 0xff;
170379be585SJean-Christophe PLAGNIOL-VILLARD }
171379be585SJean-Christophe PLAGNIOL-VILLARD 
pxa_puts_dev(unsigned int uart_index,const char * s)172237ce0feSMarek Vasut void pxa_puts_dev(unsigned int uart_index, const char *s)
173379be585SJean-Christophe PLAGNIOL-VILLARD {
174237ce0feSMarek Vasut 	while (*s)
175379be585SJean-Christophe PLAGNIOL-VILLARD 		pxa_putc_dev(uart_index, *s++);
176379be585SJean-Christophe PLAGNIOL-VILLARD }
177379be585SJean-Christophe PLAGNIOL-VILLARD 
178237ce0feSMarek Vasut #define	pxa_uart(uart, UART)						\
179237ce0feSMarek Vasut 	int uart##_init(void)						\
180237ce0feSMarek Vasut 	{								\
181237ce0feSMarek Vasut 		return pxa_init_dev(UART##_INDEX);			\
182237ce0feSMarek Vasut 	}								\
183237ce0feSMarek Vasut 									\
184237ce0feSMarek Vasut 	void uart##_setbrg(void)					\
185237ce0feSMarek Vasut 	{								\
186237ce0feSMarek Vasut 		return pxa_setbrg_dev(UART##_INDEX);			\
187237ce0feSMarek Vasut 	}								\
188237ce0feSMarek Vasut 									\
189237ce0feSMarek Vasut 	void uart##_putc(const char c)					\
190237ce0feSMarek Vasut 	{								\
191237ce0feSMarek Vasut 		return pxa_putc_dev(UART##_INDEX, c);			\
192237ce0feSMarek Vasut 	}								\
193237ce0feSMarek Vasut 									\
194237ce0feSMarek Vasut 	void uart##_puts(const char *s)					\
195237ce0feSMarek Vasut 	{								\
196237ce0feSMarek Vasut 		return pxa_puts_dev(UART##_INDEX, s);			\
197237ce0feSMarek Vasut 	}								\
198237ce0feSMarek Vasut 									\
199237ce0feSMarek Vasut 	int uart##_getc(void)						\
200237ce0feSMarek Vasut 	{								\
201237ce0feSMarek Vasut 		return pxa_getc_dev(UART##_INDEX);			\
202237ce0feSMarek Vasut 	}								\
203237ce0feSMarek Vasut 									\
204237ce0feSMarek Vasut 	int uart##_tstc(void)						\
205237ce0feSMarek Vasut 	{								\
206237ce0feSMarek Vasut 		return pxa_tstc_dev(UART##_INDEX);			\
207237ce0feSMarek Vasut 	}								\
208379be585SJean-Christophe PLAGNIOL-VILLARD 
209237ce0feSMarek Vasut #define	pxa_uart_desc(uart)						\
210237ce0feSMarek Vasut 	struct serial_device serial_##uart##_device =			\
211237ce0feSMarek Vasut 	{								\
21290bad891SMarek Vasut 		.name	= "serial_"#uart,				\
21390bad891SMarek Vasut 		.start	= uart##_init,					\
21490bad891SMarek Vasut 		.stop	= NULL,						\
21590bad891SMarek Vasut 		.setbrg	= uart##_setbrg,				\
21690bad891SMarek Vasut 		.getc	= uart##_getc,					\
21790bad891SMarek Vasut 		.tstc	= uart##_tstc,					\
21890bad891SMarek Vasut 		.putc	= uart##_putc,					\
21990bad891SMarek Vasut 		.puts	= uart##_puts,					\
220379be585SJean-Christophe PLAGNIOL-VILLARD 	};
221237ce0feSMarek Vasut 
222237ce0feSMarek Vasut #define	pxa_uart_multi(uart, UART)					\
223237ce0feSMarek Vasut 	pxa_uart(uart, UART)						\
224237ce0feSMarek Vasut 	pxa_uart_desc(uart)
225237ce0feSMarek Vasut 
226237ce0feSMarek Vasut #if defined(CONFIG_HWUART)
pxa_uart_multi(hwuart,HWUART)227237ce0feSMarek Vasut 	pxa_uart_multi(hwuart, HWUART)
228379be585SJean-Christophe PLAGNIOL-VILLARD #endif
229379be585SJean-Christophe PLAGNIOL-VILLARD #if defined(CONFIG_STUART)
230237ce0feSMarek Vasut 	pxa_uart_multi(stuart, STUART)
231379be585SJean-Christophe PLAGNIOL-VILLARD #endif
232237ce0feSMarek Vasut #if defined(CONFIG_FFUART)
233237ce0feSMarek Vasut 	pxa_uart_multi(ffuart, FFUART)
234237ce0feSMarek Vasut #endif
235237ce0feSMarek Vasut #if defined(CONFIG_BTUART)
236237ce0feSMarek Vasut 	pxa_uart_multi(btuart, BTUART)
237237ce0feSMarek Vasut #endif
238379be585SJean-Christophe PLAGNIOL-VILLARD 
239407e6a28SMarek Vasut __weak struct serial_device *default_serial_console(void)
240407e6a28SMarek Vasut {
241407e6a28SMarek Vasut #if CONFIG_CONS_INDEX == 1
242407e6a28SMarek Vasut 	return &serial_hwuart_device;
243407e6a28SMarek Vasut #elif CONFIG_CONS_INDEX == 2
244407e6a28SMarek Vasut 	return &serial_stuart_device;
245407e6a28SMarek Vasut #elif CONFIG_CONS_INDEX == 3
246407e6a28SMarek Vasut 	return &serial_ffuart_device;
247407e6a28SMarek Vasut #elif CONFIG_CONS_INDEX == 4
248407e6a28SMarek Vasut 	return &serial_btuart_device;
249407e6a28SMarek Vasut #else
250407e6a28SMarek Vasut #error "Bad CONFIG_CONS_INDEX."
251407e6a28SMarek Vasut #endif
252407e6a28SMarek Vasut }
2531fe5c110SMarek Vasut 
pxa_serial_initialize(void)2541fe5c110SMarek Vasut void pxa_serial_initialize(void)
2551fe5c110SMarek Vasut {
2561fe5c110SMarek Vasut #if defined(CONFIG_FFUART)
2571fe5c110SMarek Vasut 	serial_register(&serial_ffuart_device);
2581fe5c110SMarek Vasut #endif
2591fe5c110SMarek Vasut #if defined(CONFIG_BTUART)
2601fe5c110SMarek Vasut 	serial_register(&serial_btuart_device);
2611fe5c110SMarek Vasut #endif
2621fe5c110SMarek Vasut #if defined(CONFIG_STUART)
2631fe5c110SMarek Vasut 	serial_register(&serial_stuart_device);
2641fe5c110SMarek Vasut #endif
2651fe5c110SMarek Vasut }
266*cbfa67a1SMarcel Ziswiler #endif /* CONFIG_DM_SERIAL */
267*cbfa67a1SMarcel Ziswiler 
268*cbfa67a1SMarcel Ziswiler #ifdef CONFIG_DM_SERIAL
pxa_serial_probe(struct udevice * dev)269*cbfa67a1SMarcel Ziswiler static int pxa_serial_probe(struct udevice *dev)
270*cbfa67a1SMarcel Ziswiler {
271*cbfa67a1SMarcel Ziswiler 	struct pxa_serial_platdata *plat = dev->platdata;
272*cbfa67a1SMarcel Ziswiler 
273*cbfa67a1SMarcel Ziswiler 	pxa_setbrg_common((struct pxa_uart_regs *)plat->base, plat->port,
274*cbfa67a1SMarcel Ziswiler 			  plat->baudrate);
275*cbfa67a1SMarcel Ziswiler 	return 0;
276*cbfa67a1SMarcel Ziswiler }
277*cbfa67a1SMarcel Ziswiler 
pxa_serial_putc(struct udevice * dev,const char ch)278*cbfa67a1SMarcel Ziswiler static int pxa_serial_putc(struct udevice *dev, const char ch)
279*cbfa67a1SMarcel Ziswiler {
280*cbfa67a1SMarcel Ziswiler 	struct pxa_serial_platdata *plat = dev->platdata;
281*cbfa67a1SMarcel Ziswiler 	struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base;
282*cbfa67a1SMarcel Ziswiler 
283*cbfa67a1SMarcel Ziswiler 	/* Wait for last character to go. */
284*cbfa67a1SMarcel Ziswiler 	if (!(readl(&uart_regs->lsr) & LSR_TEMT))
285*cbfa67a1SMarcel Ziswiler 		return -EAGAIN;
286*cbfa67a1SMarcel Ziswiler 
287*cbfa67a1SMarcel Ziswiler 	writel(ch, &uart_regs->thr);
288*cbfa67a1SMarcel Ziswiler 
289*cbfa67a1SMarcel Ziswiler 	return 0;
290*cbfa67a1SMarcel Ziswiler }
291*cbfa67a1SMarcel Ziswiler 
pxa_serial_getc(struct udevice * dev)292*cbfa67a1SMarcel Ziswiler static int pxa_serial_getc(struct udevice *dev)
293*cbfa67a1SMarcel Ziswiler {
294*cbfa67a1SMarcel Ziswiler 	struct pxa_serial_platdata *plat = dev->platdata;
295*cbfa67a1SMarcel Ziswiler 	struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base;
296*cbfa67a1SMarcel Ziswiler 
297*cbfa67a1SMarcel Ziswiler 	/* Wait for a character to arrive. */
298*cbfa67a1SMarcel Ziswiler 	if (!(readl(&uart_regs->lsr) & LSR_DR))
299*cbfa67a1SMarcel Ziswiler 		return -EAGAIN;
300*cbfa67a1SMarcel Ziswiler 
301*cbfa67a1SMarcel Ziswiler 	return readl(&uart_regs->rbr) & 0xff;
302*cbfa67a1SMarcel Ziswiler }
303*cbfa67a1SMarcel Ziswiler 
pxa_serial_setbrg(struct udevice * dev,int baudrate)304*cbfa67a1SMarcel Ziswiler int pxa_serial_setbrg(struct udevice *dev, int baudrate)
305*cbfa67a1SMarcel Ziswiler {
306*cbfa67a1SMarcel Ziswiler 	struct pxa_serial_platdata *plat = dev->platdata;
307*cbfa67a1SMarcel Ziswiler 	struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base;
308*cbfa67a1SMarcel Ziswiler 	int port = plat->port;
309*cbfa67a1SMarcel Ziswiler 
310*cbfa67a1SMarcel Ziswiler 	pxa_setbrg_common(uart_regs, port, baudrate);
311*cbfa67a1SMarcel Ziswiler 
312*cbfa67a1SMarcel Ziswiler 	return 0;
313*cbfa67a1SMarcel Ziswiler }
314*cbfa67a1SMarcel Ziswiler 
pxa_serial_pending(struct udevice * dev,bool input)315*cbfa67a1SMarcel Ziswiler static int pxa_serial_pending(struct udevice *dev, bool input)
316*cbfa67a1SMarcel Ziswiler {
317*cbfa67a1SMarcel Ziswiler 	struct pxa_serial_platdata *plat = dev->platdata;
318*cbfa67a1SMarcel Ziswiler 	struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base;
319*cbfa67a1SMarcel Ziswiler 
320*cbfa67a1SMarcel Ziswiler 	if (input)
321*cbfa67a1SMarcel Ziswiler 		return readl(&uart_regs->lsr) & LSR_DR ? 1 : 0;
322*cbfa67a1SMarcel Ziswiler 	else
323*cbfa67a1SMarcel Ziswiler 		return readl(&uart_regs->lsr) & LSR_TEMT ? 0 : 1;
324*cbfa67a1SMarcel Ziswiler 
325*cbfa67a1SMarcel Ziswiler 	return 0;
326*cbfa67a1SMarcel Ziswiler }
327*cbfa67a1SMarcel Ziswiler 
328*cbfa67a1SMarcel Ziswiler static const struct dm_serial_ops pxa_serial_ops = {
329*cbfa67a1SMarcel Ziswiler 	.putc		= pxa_serial_putc,
330*cbfa67a1SMarcel Ziswiler 	.pending	= pxa_serial_pending,
331*cbfa67a1SMarcel Ziswiler 	.getc		= pxa_serial_getc,
332*cbfa67a1SMarcel Ziswiler 	.setbrg		= pxa_serial_setbrg,
333*cbfa67a1SMarcel Ziswiler };
334*cbfa67a1SMarcel Ziswiler 
335*cbfa67a1SMarcel Ziswiler U_BOOT_DRIVER(serial_pxa) = {
336*cbfa67a1SMarcel Ziswiler 	.name	= "serial_pxa",
337*cbfa67a1SMarcel Ziswiler 	.id	= UCLASS_SERIAL,
338*cbfa67a1SMarcel Ziswiler 	.probe	= pxa_serial_probe,
339*cbfa67a1SMarcel Ziswiler 	.ops	= &pxa_serial_ops,
340*cbfa67a1SMarcel Ziswiler 	.flags	= DM_FLAG_PRE_RELOC,
341*cbfa67a1SMarcel Ziswiler };
342*cbfa67a1SMarcel Ziswiler #endif /* CONFIG_DM_SERIAL */
343