[U-Boot] [RFC] drivers: serial: Check only input buffers in pending

matthias.bgg at kernel.org matthias.bgg at kernel.org
Tue Feb 26 16:30:41 UTC 2019


From: Matthias Brugger <mbrugger at suse.com>

Serial device function pending allows to check the state of the input
and output buffers. But in fact only a check for the input buffers
is used in the device model. There are even some driver which discard a
check on the output buffers. So delete the check for the output buffers
to reflect that fact in the function definition.

Signed-off-by: Matthias Brugger <mbrugger at suse.com>
---
 drivers/serial/altera_jtag_uart.c      |  7 ++-----
 drivers/serial/altera_uart.c           |  7 ++-----
 drivers/serial/arm_dcc.c               |  8 ++------
 drivers/serial/atmel_usart.c           |  7 ++-----
 drivers/serial/lpc32xx_hsuart.c        | 11 +++--------
 drivers/serial/mcfuart.c               |  9 ++-------
 drivers/serial/ns16550.c               |  7 ++-----
 drivers/serial/sandbox.c               |  7 ++-----
 drivers/serial/serial-uclass.c         |  2 +-
 drivers/serial/serial_ar933x.c         |  8 +++-----
 drivers/serial/serial_arc.c            |  7 ++-----
 drivers/serial/serial_bcm283x_mu.c     | 10 +++-------
 drivers/serial/serial_bcm6345.c        |  7 ++-----
 drivers/serial/serial_efi.c            |  6 +-----
 drivers/serial/serial_linflexuart.c    |  7 ++-----
 drivers/serial/serial_lpuart.c         | 14 +++-----------
 drivers/serial/serial_meson.c          |  7 ++-----
 drivers/serial/serial_mpc8xx.c         |  5 +----
 drivers/serial/serial_msm.c            |  8 +++-----
 drivers/serial/serial_mtk.c            |  9 +++------
 drivers/serial/serial_mvebu_a3700.c    |  2 +-
 drivers/serial/serial_mxc.c            |  7 ++-----
 drivers/serial/serial_nulldev.c        |  2 +-
 drivers/serial/serial_owl.c            |  7 ++-----
 drivers/serial/serial_pic32.c          |  7 ++-----
 drivers/serial/serial_pl01x.c          |  7 ++-----
 drivers/serial/serial_pl01x_internal.h |  2 +-
 drivers/serial/serial_pxa.c            |  9 ++-------
 drivers/serial/serial_s5p.c            |  7 ++-----
 drivers/serial/serial_sh.c             |  2 +-
 drivers/serial/serial_sifive.c         | 14 +++++---------
 drivers/serial/serial_sti_asc.c        | 11 ++++++++---
 drivers/serial/serial_stm32.c          | 10 +++-------
 drivers/serial/serial_uniphier.c       |  7 ++-----
 drivers/serial/serial_xuartlite.c      |  7 ++-----
 drivers/serial/serial_zynq.c           |  7 ++-----
 include/serial.h                       |  4 ++--
 37 files changed, 83 insertions(+), 182 deletions(-)

diff --git a/drivers/serial/altera_jtag_uart.c b/drivers/serial/altera_jtag_uart.c
index 86c3de4e45..7f52399312 100644
--- a/drivers/serial/altera_jtag_uart.c
+++ b/drivers/serial/altera_jtag_uart.c
@@ -53,16 +53,13 @@ static int altera_jtaguart_putc(struct udevice *dev, const char ch)
 	return 0;
 }
 
-static int altera_jtaguart_pending(struct udevice *dev, bool input)
+static int altera_jtaguart_pending(struct udevice *dev)
 {
 	struct altera_jtaguart_platdata *plat = dev->platdata;
 	struct altera_jtaguart_regs *const regs = plat->regs;
 	u32 st = readl(&regs->control);
 
-	if (input)
-		return st & ALTERA_JTAG_RRDY ? 1 : 0;
-	else
-		return !(ALTERA_JTAG_WSPACE(st) == ALTERA_JTAG_WRITE_DEPTH);
+	return st & ALTERA_JTAG_RRDY ? 1 : 0;
 }
 
 static int altera_jtaguart_getc(struct udevice *dev)
diff --git a/drivers/serial/altera_uart.c b/drivers/serial/altera_uart.c
index 67d47199aa..f3f8d908bf 100644
--- a/drivers/serial/altera_uart.c
+++ b/drivers/serial/altera_uart.c
@@ -56,16 +56,13 @@ static int altera_uart_putc(struct udevice *dev, const char ch)
 	return 0;
 }
 
-static int altera_uart_pending(struct udevice *dev, bool input)
+static int altera_uart_pending(struct udevice *dev)
 {
 	struct altera_uart_platdata *plat = dev->platdata;
 	struct altera_uart_regs *const regs = plat->regs;
 	u32 st = readl(&regs->status);
 
-	if (input)
-		return st & ALTERA_UART_RRDY ? 1 : 0;
-	else
-		return !(st & ALTERA_UART_TMT);
+	return st & ALTERA_UART_RRDY ? 1 : 0;
 }
 
 static int altera_uart_getc(struct udevice *dev)
diff --git a/drivers/serial/arm_dcc.c b/drivers/serial/arm_dcc.c
index dfcb6fd698..0771f90e7c 100644
--- a/drivers/serial/arm_dcc.c
+++ b/drivers/serial/arm_dcc.c
@@ -126,15 +126,11 @@ static int arm_dcc_putc(struct udevice *dev, char ch)
 	return 0;
 }
 
-static int arm_dcc_pending(struct udevice *dev, bool input)
+static int arm_dcc_pending(struct udevice *dev)
 {
 	register unsigned int reg;
 
-	if (input) {
-		can_read_dcc(reg);
-	} else {
-		can_write_dcc(reg);
-	}
+	can_read_dcc(reg);
 
 	return reg;
 }
diff --git a/drivers/serial/atmel_usart.c b/drivers/serial/atmel_usart.c
index aa8cdff840..fdde966da2 100644
--- a/drivers/serial/atmel_usart.c
+++ b/drivers/serial/atmel_usart.c
@@ -200,15 +200,12 @@ static int atmel_serial_putc(struct udevice *dev, const char ch)
 	return 0;
 }
 
-static int atmel_serial_pending(struct udevice *dev, bool input)
+static int atmel_serial_pending(struct udevice *dev)
 {
 	struct atmel_serial_priv *priv = dev_get_priv(dev);
 	uint32_t csr = readl(&priv->usart->csr);
 
-	if (input)
-		return csr & USART3_BIT(RXRDY) ? 1 : 0;
-	else
-		return csr & USART3_BIT(TXEMPTY) ? 0 : 1;
+	return csr & USART3_BIT(RXRDY) ? 1 : 0;
 }
 
 static const struct dm_serial_ops atmel_serial_ops = {
diff --git a/drivers/serial/lpc32xx_hsuart.c b/drivers/serial/lpc32xx_hsuart.c
index 8b0fd254b1..82c01ec2d8 100644
--- a/drivers/serial/lpc32xx_hsuart.c
+++ b/drivers/serial/lpc32xx_hsuart.c
@@ -56,18 +56,13 @@ static int lpc32xx_serial_putc(struct udevice *dev, const char c)
 	return 0;
 }
 
-static int lpc32xx_serial_pending(struct udevice *dev, bool input)
+static int lpc32xx_serial_pending(struct udevice *dev)
 {
 	struct lpc32xx_hsuart_priv *priv = dev_get_priv(dev);
 	struct hsuart_regs *hsuart = priv->hsuart;
 
-	if (input) {
-		if (readl(&hsuart->level) & HSUART_LEVEL_RX)
-			return 1;
-	} else {
-		if (readl(&hsuart->level) & HSUART_LEVEL_TX)
-			return 1;
-	}
+	if (readl(&hsuart->level) & HSUART_LEVEL_RX)
+		return 1;
 
 	return 0;
 }
diff --git a/drivers/serial/mcfuart.c b/drivers/serial/mcfuart.c
index 1371049de2..5dca0ec282 100644
--- a/drivers/serial/mcfuart.c
+++ b/drivers/serial/mcfuart.c
@@ -199,17 +199,12 @@ int coldfire_serial_setbrg(struct udevice *dev, int baudrate)
 	return 0;
 }
 
-static int coldfire_serial_pending(struct udevice *dev, bool input)
+static int coldfire_serial_pending(struct udevice *dev)
 {
 	struct coldfire_serial_platdata *plat = dev->platdata;
 	uart_t *uart = (uart_t *)(plat->base);
 
-	if (input)
-		return readb(&uart->usr) & UART_USR_RXRDY ? 1 : 0;
-	else
-		return readb(&uart->usr) & UART_USR_TXRDY ? 0 : 1;
-
-	return 0;
+	return readb(&uart->usr) & UART_USR_RXRDY ? 1 : 0;
 }
 
 static const struct dm_serial_ops coldfire_serial_ops = {
diff --git a/drivers/serial/ns16550.c b/drivers/serial/ns16550.c
index 6cf2be8f2b..9a6bc28d4c 100644
--- a/drivers/serial/ns16550.c
+++ b/drivers/serial/ns16550.c
@@ -322,14 +322,11 @@ static int ns16550_serial_putc(struct udevice *dev, const char ch)
 	return 0;
 }
 
-static int ns16550_serial_pending(struct udevice *dev, bool input)
+static int ns16550_serial_pending(struct udevice *dev)
 {
 	struct NS16550 *const com_port = dev_get_priv(dev);
 
-	if (input)
-		return (serial_in(&com_port->lsr) & UART_LSR_DR) ? 1 : 0;
-	else
-		return (serial_in(&com_port->lsr) & UART_LSR_THRE) ? 0 : 1;
+	return (serial_in(&com_port->lsr) & UART_LSR_DR) ? 1 : 0;
 }
 
 static int ns16550_serial_getc(struct udevice *dev)
diff --git a/drivers/serial/sandbox.c b/drivers/serial/sandbox.c
index 33102fc872..32253bcd7d 100644
--- a/drivers/serial/sandbox.c
+++ b/drivers/serial/sandbox.c
@@ -110,15 +110,12 @@ static unsigned int increment_buffer_index(unsigned int index)
 	return (index + 1) % ARRAY_SIZE(serial_buf);
 }
 
-static int sandbox_serial_pending(struct udevice *dev, bool input)
+static int sandbox_serial_pending(struct udevice *dev)
 {
 	const unsigned int next_index =
 		increment_buffer_index(serial_buf_write);
 	ssize_t count;
 
-	if (!input)
-		return 0;
-
 	os_usleep(100);
 #ifndef CONFIG_SPL_BUILD
 	video_sync_all();
@@ -137,7 +134,7 @@ static int sandbox_serial_getc(struct udevice *dev)
 {
 	int result;
 
-	if (!sandbox_serial_pending(dev, true))
+	if (!sandbox_serial_pending(dev))
 		return -EAGAIN;	/* buffer empty */
 
 	result = serial_buf[serial_buf_read];
diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index d4488a2cc2..e0b7f68ebb 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -208,7 +208,7 @@ static int __serial_tstc(struct udevice *dev)
 	struct dm_serial_ops *ops = serial_get_ops(dev);
 
 	if (ops->pending)
-		return ops->pending(dev, true);
+		return ops->pending(dev);
 
 	return 1;
 }
diff --git a/drivers/serial/serial_ar933x.c b/drivers/serial/serial_ar933x.c
index 5249c55398..4ee9f26fd3 100644
--- a/drivers/serial/serial_ar933x.c
+++ b/drivers/serial/serial_ar933x.c
@@ -130,16 +130,14 @@ static int ar933x_serial_getc(struct udevice *dev)
 	return data & AR933X_UART_DATA_TX_RX_MASK;
 }
 
-static int ar933x_serial_pending(struct udevice *dev, bool input)
+static int ar933x_serial_pending(struct udevice *dev)
 {
 	struct ar933x_serial_priv *priv = dev_get_priv(dev);
 	u32 data;
 
 	data = readl(priv->regs + AR933X_UART_DATA_REG);
-	if (input)
-		return (data & AR933X_UART_DATA_RX_CSR) ? 1 : 0;
-	else
-		return (data & AR933X_UART_DATA_TX_CSR) ? 0 : 1;
+
+	return (data & AR933X_UART_DATA_RX_CSR) ? 1 : 0;
 }
 
 static int ar933x_serial_probe(struct udevice *dev)
diff --git a/drivers/serial/serial_arc.c b/drivers/serial/serial_arc.c
index 70dbc6d6b5..410411d765 100644
--- a/drivers/serial/serial_arc.c
+++ b/drivers/serial/serial_arc.c
@@ -65,16 +65,13 @@ static int arc_serial_tstc(struct arc_serial_regs *const regs)
 	return !(readb(&regs->status) & UART_RXEMPTY);
 }
 
-static int arc_serial_pending(struct udevice *dev, bool input)
+static int arc_serial_pending(struct udevice *dev)
 {
 	struct arc_serial_platdata *plat = dev->platdata;
 	struct arc_serial_regs *const regs = plat->reg;
 	uint32_t status = readb(&regs->status);
 
-	if (input)
-		return status & UART_RXEMPTY ? 0 : 1;
-	else
-		return status & UART_TXEMPTY ? 0 : 1;
+	return status & UART_RXEMPTY ? 0 : 1;
 }
 
 static int arc_serial_getc(struct udevice *dev)
diff --git a/drivers/serial/serial_bcm283x_mu.c b/drivers/serial/serial_bcm283x_mu.c
index bd1d89ec83..7c07939ca3 100644
--- a/drivers/serial/serial_bcm283x_mu.c
+++ b/drivers/serial/serial_bcm283x_mu.c
@@ -114,7 +114,7 @@ static int bcm283x_mu_serial_putc(struct udevice *dev, const char data)
 	return 0;
 }
 
-static int bcm283x_mu_serial_pending(struct udevice *dev, bool input)
+static int bcm283x_mu_serial_pending(struct udevice *dev)
 {
 	struct bcm283x_mu_priv *priv = dev_get_priv(dev);
 	struct bcm283x_mu_regs *regs = priv->regs;
@@ -122,12 +122,8 @@ static int bcm283x_mu_serial_pending(struct udevice *dev, bool input)
 
 	lsr = readl(&regs->lsr);
 
-	if (input) {
-		WATCHDOG_RESET();
-		return (lsr & BCM283X_MU_LSR_RX_READY) ? 1 : 0;
-	} else {
-		return (lsr & BCM283X_MU_LSR_TX_IDLE) ? 0 : 1;
-	}
+	WATCHDOG_RESET();
+	return (lsr & BCM283X_MU_LSR_RX_READY) ? 1 : 0;
 }
 
 static const struct dm_serial_ops bcm283x_mu_serial_ops = {
diff --git a/drivers/serial/serial_bcm6345.c b/drivers/serial/serial_bcm6345.c
index 9ad8c770d5..59f2b62454 100644
--- a/drivers/serial/serial_bcm6345.c
+++ b/drivers/serial/serial_bcm6345.c
@@ -172,15 +172,12 @@ static int bcm6345_serial_init(void __iomem *base, ulong clk, u32 baudrate)
 	return 0;
 }
 
-static int bcm6345_serial_pending(struct udevice *dev, bool input)
+static int bcm6345_serial_pending(struct udevice *dev)
 {
 	struct bcm6345_serial_priv *priv = dev_get_priv(dev);
 	u32 val = readl(priv->base + UART_IR_REG);
 
-	if (input)
-		return !!(val & UART_IR_STAT(UART_IR_RXNOTEMPTY));
-	else
-		return !(val & UART_IR_STAT(UART_IR_TXEMPTY));
+	return !!(val & UART_IR_STAT(UART_IR_RXNOTEMPTY));
 }
 
 static int bcm6345_serial_setbrg(struct udevice *dev, int baudrate)
diff --git a/drivers/serial/serial_efi.c b/drivers/serial/serial_efi.c
index dd3e511fc9..1385ed3e55 100644
--- a/drivers/serial/serial_efi.c
+++ b/drivers/serial/serial_efi.c
@@ -84,15 +84,11 @@ static int serial_efi_putc(struct udevice *dev, const char ch)
 	return 0;
 }
 
-static int serial_efi_pending(struct udevice *dev, bool input)
+static int serial_efi_pending(struct udevice *dev)
 {
 	struct serial_efi_priv *priv = dev_get_priv(dev);
 	int ret;
 
-	/* We assume that EFI will stall if its output buffer fills up */
-	if (!input)
-		return 0;
-
 	ret = serial_efi_get_key(priv);
 	if (ret == -EAGAIN)
 		return 0;
diff --git a/drivers/serial/serial_linflexuart.c b/drivers/serial/serial_linflexuart.c
index 83dc96c449..cabe7dd283 100644
--- a/drivers/serial/serial_linflexuart.c
+++ b/drivers/serial/serial_linflexuart.c
@@ -148,15 +148,12 @@ static int linflex_serial_putc(struct udevice *dev, const char ch)
 	return _linflex_serial_putc(priv->lfuart, ch);
 }
 
-static int linflex_serial_pending(struct udevice *dev, bool input)
+static int linflex_serial_pending(struct udevice *dev)
 {
 	struct linflex_serial_priv *priv = dev_get_priv(dev);
 	uint32_t uartsr = __raw_readl(&priv->lfuart->uartsr);
 
-	if (input)
-		return ((uartsr & UARTSR_DRF) && (uartsr & UARTSR_RMB)) ? 1 : 0;
-	else
-		return uartsr & UARTSR_DTF ? 0 : 1;
+	return ((uartsr & UARTSR_DRF) && (uartsr & UARTSR_RMB)) ? 1 : 0;
 }
 
 static void linflex_serial_init_internal(struct linflex_fsl *lfuart)
diff --git a/drivers/serial/serial_lpuart.c b/drivers/serial/serial_lpuart.c
index a357b00d28..49982cd1ef 100644
--- a/drivers/serial/serial_lpuart.c
+++ b/drivers/serial/serial_lpuart.c
@@ -458,7 +458,7 @@ static int lpuart_serial_putc(struct udevice *dev, const char c)
 	return 0;
 }
 
-static int lpuart_serial_pending(struct udevice *dev, bool input)
+static int lpuart_serial_pending(struct udevice *dev)
 {
 	struct lpuart_serial_platdata *plat = dev->platdata;
 	struct lpuart_fsl *reg = plat->reg;
@@ -466,18 +466,10 @@ static int lpuart_serial_pending(struct udevice *dev, bool input)
 	u32 stat;
 
 	if (is_lpuart32(dev)) {
-		if (input) {
-			return _lpuart32_serial_tstc(plat);
-		} else {
-			lpuart_read32(plat->flags, &reg32->stat, &stat);
-			return stat & STAT_TDRE ? 0 : 1;
-		}
+		return _lpuart32_serial_tstc(plat);
 	}
 
-	if (input)
-		return _lpuart_serial_tstc(plat);
-	else
-		return __raw_readb(&reg->us1) & US1_TDRE ? 0 : 1;
+	return _lpuart_serial_tstc(plat);
 }
 
 static int lpuart_serial_probe(struct udevice *dev)
diff --git a/drivers/serial/serial_meson.c b/drivers/serial/serial_meson.c
index b3dad77aa2..db8e6c249b 100644
--- a/drivers/serial/serial_meson.c
+++ b/drivers/serial/serial_meson.c
@@ -88,16 +88,13 @@ static int meson_serial_putc(struct udevice *dev, const char ch)
 	return 0;
 }
 
-static int meson_serial_pending(struct udevice *dev, bool input)
+static int meson_serial_pending(struct udevice *dev)
 {
 	struct meson_serial_platdata *plat = dev->platdata;
 	struct meson_uart *const uart = plat->reg;
 	uint32_t status = readl(&uart->status);
 
-	if (input)
-		return !(status & AML_UART_RX_EMPTY);
-	else
-		return !(status & AML_UART_TX_FULL);
+	return !(status & AML_UART_RX_EMPTY);
 }
 
 static int meson_serial_ofdata_to_platdata(struct udevice *dev)
diff --git a/drivers/serial/serial_mpc8xx.c b/drivers/serial/serial_mpc8xx.c
index 50d6e70f17..60cd34c99f 100644
--- a/drivers/serial/serial_mpc8xx.c
+++ b/drivers/serial/serial_mpc8xx.c
@@ -221,15 +221,12 @@ static int serial_mpc8xx_getc(struct udevice *dev)
 	return c;
 }
 
-static int serial_mpc8xx_pending(struct udevice *dev, bool input)
+static int serial_mpc8xx_pending(struct udevice *dev)
 {
 	immap_t	__iomem *im = (immap_t __iomem *)CONFIG_SYS_IMMR;
 	cpm8xx_t	__iomem *cpmp = &(im->im_cpm);
 	struct serialbuffer	__iomem *rtx;
 
-	if (!input)
-		return 0;
-
 	rtx = (struct serialbuffer __iomem *)&cpmp->cp_dpmem[CPM_SERIAL_BASE];
 
 	return !(in_be16(&rtx->rxbd.cbd_sc) & BD_SC_EMPTY);
diff --git a/drivers/serial/serial_msm.c b/drivers/serial/serial_msm.c
index c462394dbd..bea5fc16a4 100644
--- a/drivers/serial/serial_msm.c
+++ b/drivers/serial/serial_msm.c
@@ -135,12 +135,10 @@ static int msm_serial_putc(struct udevice *dev, const char ch)
 	return 0;
 }
 
-static int msm_serial_pending(struct udevice *dev, bool input)
+static int msm_serial_pending(struct udevice *dev)
 {
-	if (input) {
-		if (msm_serial_fetch(dev))
-			return 1;
-	}
+	if (msm_serial_fetch(dev))
+		return 1;
 
 	return 0;
 }
diff --git a/drivers/serial/serial_mtk.c b/drivers/serial/serial_mtk.c
index bce1be8227..e59351da7e 100644
--- a/drivers/serial/serial_mtk.c
+++ b/drivers/serial/serial_mtk.c
@@ -158,14 +158,11 @@ static int mtk_serial_getc(struct udevice *dev)
 	return readl(&priv->regs->rbr);
 }
 
-static int mtk_serial_pending(struct udevice *dev, bool input)
+static int mtk_serial_pending(struct udevice *dev)
 {
 	struct mtk_serial_priv *priv = dev_get_priv(dev);
 
-	if (input)
-		return (readl(&priv->regs->lsr) & UART_LSR_DR) ? 1 : 0;
-	else
-		return (readl(&priv->regs->lsr) & UART_LSR_THRE) ? 0 : 1;
+	return (readl(&priv->regs->lsr) & UART_LSR_DR) ? 1 : 0;
 }
 
 static int mtk_serial_probe(struct udevice *dev)
@@ -265,4 +262,4 @@ static inline void _debug_uart_putc(int ch)
 
 DEBUG_UART_FUNCS
 
-#endif
\ No newline at end of file
+#endif
diff --git a/drivers/serial/serial_mvebu_a3700.c b/drivers/serial/serial_mvebu_a3700.c
index 7e4cd6c4b4..986c75e6cb 100644
--- a/drivers/serial/serial_mvebu_a3700.c
+++ b/drivers/serial/serial_mvebu_a3700.c
@@ -54,7 +54,7 @@ static int mvebu_serial_getc(struct udevice *dev)
 	return readl(base + UART_RX_REG) & 0xff;
 }
 
-static int mvebu_serial_pending(struct udevice *dev, bool input)
+static int mvebu_serial_pending(struct udevice *dev)
 {
 	struct mvebu_platdata *plat = dev_get_platdata(dev);
 	void __iomem *base = plat->base;
diff --git a/drivers/serial/serial_mxc.c b/drivers/serial/serial_mxc.c
index df35ac9114..5a05fc50c3 100644
--- a/drivers/serial/serial_mxc.c
+++ b/drivers/serial/serial_mxc.c
@@ -305,16 +305,13 @@ static int mxc_serial_putc(struct udevice *dev, const char ch)
 	return 0;
 }
 
-static int mxc_serial_pending(struct udevice *dev, bool input)
+static int mxc_serial_pending(struct udevice *dev)
 {
 	struct mxc_serial_platdata *plat = dev->platdata;
 	struct mxc_uart *const uart = plat->reg;
 	uint32_t sr2 = readl(&uart->sr2);
 
-	if (input)
-		return sr2 & USR2_RDR ? 1 : 0;
-	else
-		return sr2 & USR2_TXDC ? 0 : 1;
+	return sr2 & USR2_RDR ? 1 : 0;
 }
 
 static const struct dm_serial_ops mxc_serial_ops = {
diff --git a/drivers/serial/serial_nulldev.c b/drivers/serial/serial_nulldev.c
index efae14dd6c..f582725b44 100644
--- a/drivers/serial/serial_nulldev.c
+++ b/drivers/serial/serial_nulldev.c
@@ -17,7 +17,7 @@ static int nulldev_serial_getc(struct udevice *dev)
 	return -EAGAIN;
 }
 
-static int nulldev_serial_pending(struct udevice *dev, bool input)
+static int nulldev_serial_pending(struct udevice *dev)
 {
 	return 0;
 }
diff --git a/drivers/serial/serial_owl.c b/drivers/serial/serial_owl.c
index 7ead73e6b7..851bb9a54a 100644
--- a/drivers/serial/serial_owl.c
+++ b/drivers/serial/serial_owl.c
@@ -64,15 +64,12 @@ static int owl_serial_putc(struct udevice *dev,	const char ch)
 	return 0;
 }
 
-static int owl_serial_pending(struct udevice *dev, bool	input)
+static int owl_serial_pending(struct udevice *dev)
 {
 	struct owl_serial_priv *priv = dev_get_priv(dev);
 	unsigned int stat = readl(priv->base + OWL_UART_STAT);
 
-	if (input)
-		return !(stat &	OWL_UART_STAT_RFEM);
-	else
-		return !(stat &	OWL_UART_STAT_TFES);
+	return !(stat &	OWL_UART_STAT_RFEM);
 }
 
 static int owl_serial_probe(struct udevice *dev)
diff --git a/drivers/serial/serial_pic32.c b/drivers/serial/serial_pic32.c
index 84600b1201..e95f45013c 100644
--- a/drivers/serial/serial_pic32.c
+++ b/drivers/serial/serial_pic32.c
@@ -88,14 +88,11 @@ static int pic32_uart_pending_input(void __iomem *base)
 	return readl(base + U_STA) & UART_RX_DATA_AVAIL;
 }
 
-static int pic32_uart_pending(struct udevice *dev, bool input)
+static int pic32_uart_pending(struct udevice *dev)
 {
 	struct pic32_uart_priv *priv = dev_get_priv(dev);
 
-	if (input)
-		return pic32_uart_pending_input(priv->base);
-
-	return !(readl(priv->base + U_STA) & UART_TX_EMPTY);
+	return pic32_uart_pending_input(priv->base);
 }
 
 static int pic32_uart_setbrg(struct udevice *dev, int baudrate)
diff --git a/drivers/serial/serial_pl01x.c b/drivers/serial/serial_pl01x.c
index 2a5f256184..68b6076372 100644
--- a/drivers/serial/serial_pl01x.c
+++ b/drivers/serial/serial_pl01x.c
@@ -312,15 +312,12 @@ int pl01x_serial_putc(struct udevice *dev, const char ch)
 	return pl01x_putc(priv->regs, ch);
 }
 
-int pl01x_serial_pending(struct udevice *dev, bool input)
+int pl01x_serial_pending(struct udevice *dev)
 {
 	struct pl01x_priv *priv = dev_get_priv(dev);
 	unsigned int fr = readl(&priv->regs->fr);
 
-	if (input)
-		return pl01x_tstc(priv->regs);
-	else
-		return fr & UART_PL01x_FR_TXFF ? 0 : 1;
+	return pl01x_tstc(priv->regs);
 }
 
 static const struct dm_serial_ops pl01x_serial_ops = {
diff --git a/drivers/serial/serial_pl01x_internal.h b/drivers/serial/serial_pl01x_internal.h
index c5c706b153..2ac32867d5 100644
--- a/drivers/serial/serial_pl01x_internal.h
+++ b/drivers/serial/serial_pl01x_internal.h
@@ -45,7 +45,7 @@ int pl01x_serial_probe(struct udevice *dev);
 
 /* Needed for external pl01x_serial_ops drivers */
 int pl01x_serial_putc(struct udevice *dev, const char ch);
-int pl01x_serial_pending(struct udevice *dev, bool input);
+int pl01x_serial_pending(struct udevice *dev);
 int pl01x_serial_getc(struct udevice *dev);
 int pl01x_serial_setbrg(struct udevice *dev, int baudrate);
 
diff --git a/drivers/serial/serial_pxa.c b/drivers/serial/serial_pxa.c
index cf4d8f6442..f5be13fc05 100644
--- a/drivers/serial/serial_pxa.c
+++ b/drivers/serial/serial_pxa.c
@@ -311,17 +311,12 @@ int pxa_serial_setbrg(struct udevice *dev, int baudrate)
 	return 0;
 }
 
-static int pxa_serial_pending(struct udevice *dev, bool input)
+static int pxa_serial_pending(struct udevice *dev)
 {
 	struct pxa_serial_platdata *plat = dev->platdata;
 	struct pxa_uart_regs *uart_regs = (struct pxa_uart_regs *)plat->base;
 
-	if (input)
-		return readl(&uart_regs->lsr) & LSR_DR ? 1 : 0;
-	else
-		return readl(&uart_regs->lsr) & LSR_TEMT ? 0 : 1;
-
-	return 0;
+	return readl(&uart_regs->lsr) & LSR_DR ? 1 : 0;
 }
 
 static const struct dm_serial_ops pxa_serial_ops = {
diff --git a/drivers/serial/serial_s5p.c b/drivers/serial/serial_s5p.c
index e3160cf1bd..4d39cf828b 100644
--- a/drivers/serial/serial_s5p.c
+++ b/drivers/serial/serial_s5p.c
@@ -164,16 +164,13 @@ static int s5p_serial_putc(struct udevice *dev, const char ch)
 	return 0;
 }
 
-static int s5p_serial_pending(struct udevice *dev, bool input)
+static int s5p_serial_pending(struct udevice *dev)
 {
 	struct s5p_serial_platdata *plat = dev->platdata;
 	struct s5p_uart *const uart = plat->reg;
 	uint32_t ufstat = readl(&uart->ufstat);
 
-	if (input)
-		return (ufstat & RX_FIFO_COUNT_MASK) >> RX_FIFO_COUNT_SHIFT;
-	else
-		return (ufstat & TX_FIFO_COUNT_MASK) >> TX_FIFO_COUNT_SHIFT;
+	return (ufstat & RX_FIFO_COUNT_MASK) >> RX_FIFO_COUNT_SHIFT;
 }
 
 static int s5p_serial_ofdata_to_platdata(struct udevice *dev)
diff --git a/drivers/serial/serial_sh.c b/drivers/serial/serial_sh.c
index c934d5f25a..1aa1a6573e 100644
--- a/drivers/serial/serial_sh.c
+++ b/drivers/serial/serial_sh.c
@@ -150,7 +150,7 @@ static int sh_serial_getc_generic(struct uart_port *port)
 
 #if CONFIG_IS_ENABLED(DM_SERIAL)
 
-static int sh_serial_pending(struct udevice *dev, bool input)
+static int sh_serial_pending(struct udevice *dev)
 {
 	struct uart_port *priv = dev_get_priv(dev);
 
diff --git a/drivers/serial/serial_sifive.c b/drivers/serial/serial_sifive.c
index 341728a690..0ec3e3ed94 100644
--- a/drivers/serial/serial_sifive.c
+++ b/drivers/serial/serial_sifive.c
@@ -142,19 +142,15 @@ static int sifive_serial_putc(struct udevice *dev, const char ch)
 	return rc;
 }
 
-static int sifive_serial_pending(struct udevice *dev, bool input)
+static int sifive_serial_pending(struct udevice *dev)
 {
 	struct sifive_uart_platdata *platdata = dev_get_platdata(dev);
 	struct uart_sifive *regs = platdata->regs;
 
-	if (input) {
-		if (platdata->saved_input_char > 0)
-			return 1;
-		platdata->saved_input_char = _sifive_serial_getc(regs);
-		return (platdata->saved_input_char > 0) ? 1 : 0;
-	} else {
-		return !!(readl(&regs->txfifo) & UART_TXFIFO_FULL);
-	}
+	if (platdata->saved_input_char > 0)
+		return 1;
+	platdata->saved_input_char = _sifive_serial_getc(regs);
+	return (platdata->saved_input_char > 0) ? 1 : 0;
 }
 
 static int sifive_serial_ofdata_to_platdata(struct udevice *dev)
diff --git a/drivers/serial/serial_sti_asc.c b/drivers/serial/serial_sti_asc.c
index c972f1e9af..a87abe307e 100644
--- a/drivers/serial/serial_sti_asc.c
+++ b/drivers/serial/serial_sti_asc.c
@@ -64,7 +64,7 @@ struct sti_asc_serial {
  * Mode 0 should be used for all baudrates below 19200.
  */
 
-static int sti_asc_pending(struct udevice *dev, bool input)
+static int _sti_asc_pending(struct udevice *dev, bool input)
 {
 	struct sti_asc_serial *priv = dev_get_priv(dev);
 	struct sti_asc_uart *const uart = priv->regs;
@@ -77,6 +77,11 @@ static int sti_asc_pending(struct udevice *dev, bool input)
 		return status & STA_TF;
 }
 
+static int sti_asc_pending(struct udevice *dev)
+{
+	return _sti_asc_pending(dev, true);
+}
+
 static int _sti_asc_serial_setbrg(struct sti_asc_uart *uart, int baudrate)
 {
 	unsigned long val;
@@ -140,7 +145,7 @@ static int sti_asc_serial_getc(struct udevice *dev)
 	struct sti_asc_uart *const uart = priv->regs;
 
 	/* polling wait: for a char to be read */
-	if (!sti_asc_pending(dev, true))
+	if (!_sti_asc_pending(dev, true))
 		return -EAGAIN;
 
 	return readl(&uart->rxbuf);
@@ -153,7 +158,7 @@ static int sti_asc_serial_putc(struct udevice *dev, const char c)
 	struct sti_asc_uart *const uart = priv->regs;
 
 	/* wait till safe to write next char */
-	if (sti_asc_pending(dev, false))
+	if (_sti_asc_pending(dev, false))
 		return -EAGAIN;
 
 	/* finally, write next char */
diff --git a/drivers/serial/serial_stm32.c b/drivers/serial/serial_stm32.c
index e31c87b9ac..60d59f78f4 100644
--- a/drivers/serial/serial_stm32.c
+++ b/drivers/serial/serial_stm32.c
@@ -139,18 +139,14 @@ static int stm32_serial_putc(struct udevice *dev, const char c)
 	return _stm32_serial_putc(plat->base, plat->uart_info, c);
 }
 
-static int stm32_serial_pending(struct udevice *dev, bool input)
+static int stm32_serial_pending(struct udevice *dev)
 {
 	struct stm32x7_serial_platdata *plat = dev_get_platdata(dev);
 	bool stm32f4 = plat->uart_info->stm32f4;
 	fdt_addr_t base = plat->base;
 
-	if (input)
-		return readl(base + ISR_OFFSET(stm32f4)) &
-			USART_ISR_RXNE ? 1 : 0;
-	else
-		return readl(base + ISR_OFFSET(stm32f4)) &
-			USART_ISR_TXE ? 0 : 1;
+	return readl(base + ISR_OFFSET(stm32f4)) &
+		USART_ISR_RXNE ? 1 : 0;
 }
 
 static void _stm32_serial_init(fdt_addr_t base,
diff --git a/drivers/serial/serial_uniphier.c b/drivers/serial/serial_uniphier.c
index c7f46e5598..2a5bb19eb0 100644
--- a/drivers/serial/serial_uniphier.c
+++ b/drivers/serial/serial_uniphier.c
@@ -78,14 +78,11 @@ static int uniphier_serial_putc(struct udevice *dev, const char c)
 	return 0;
 }
 
-static int uniphier_serial_pending(struct udevice *dev, bool input)
+static int uniphier_serial_pending(struct udevice *dev)
 {
 	struct uniphier_serial __iomem *port = uniphier_serial_port(dev);
 
-	if (input)
-		return readl(&port->lsr) & UART_LSR_DR;
-	else
-		return !(readl(&port->lsr) & UART_LSR_THRE);
+	return readl(&port->lsr) & UART_LSR_DR;
 }
 
 /*
diff --git a/drivers/serial/serial_xuartlite.c b/drivers/serial/serial_xuartlite.c
index 1be777bd3b..c0805f0f3d 100644
--- a/drivers/serial/serial_xuartlite.c
+++ b/drivers/serial/serial_xuartlite.c
@@ -57,15 +57,12 @@ static int uartlite_serial_getc(struct udevice *dev)
 	return in_be32(&regs->rx_fifo) & 0xff;
 }
 
-static int uartlite_serial_pending(struct udevice *dev, bool input)
+static int uartlite_serial_pending(struct udevice *dev)
 {
 	struct uartlite_platdata *plat = dev_get_platdata(dev);
 	struct uartlite *regs = plat->regs;
 
-	if (input)
-		return in_be32(&regs->status) & SR_RX_FIFO_VALID_DATA;
-
-	return !(in_be32(&regs->status) & SR_TX_FIFO_EMPTY);
+	return in_be32(&regs->status) & SR_RX_FIFO_VALID_DATA;
 }
 
 static int uartlite_serial_probe(struct udevice *dev)
diff --git a/drivers/serial/serial_zynq.c b/drivers/serial/serial_zynq.c
index 7e486a68ff..67c16a964b 100644
--- a/drivers/serial/serial_zynq.c
+++ b/drivers/serial/serial_zynq.c
@@ -166,15 +166,12 @@ static int zynq_serial_putc(struct udevice *dev, const char ch)
 	return _uart_zynq_serial_putc(platdata->regs, ch);
 }
 
-static int zynq_serial_pending(struct udevice *dev, bool input)
+static int zynq_serial_pending(struct udevice *dev)
 {
 	struct zynq_uart_platdata *platdata = dev_get_platdata(dev);
 	struct uart_zynq *regs = platdata->regs;
 
-	if (input)
-		return !(readl(&regs->channel_sts) & ZYNQ_UART_SR_RXEMPTY);
-	else
-		return !!(readl(&regs->channel_sts) & ZYNQ_UART_SR_TXACTIVE);
+	return !(readl(&regs->channel_sts) & ZYNQ_UART_SR_RXEMPTY);
 }
 
 static int zynq_serial_ofdata_to_platdata(struct udevice *dev)
diff --git a/include/serial.h b/include/serial.h
index c1368c68b6..277a62c864 100644
--- a/include/serial.h
+++ b/include/serial.h
@@ -190,7 +190,7 @@ struct dm_serial_ops {
 	 */
 	int (*putc)(struct udevice *dev, const char ch);
 	/**
-	 * pending() - Check if input/output characters are waiting
+	 * pending() - Check if input characters are waiting
 	 *
 	 * This can be used to return an indication of the number of waiting
 	 * characters if the driver knows this (e.g. by looking at the FIFO
@@ -203,7 +203,7 @@ struct dm_serial_ops {
 	 * @input: true to check input characters, false for output
 	 * @return number of waiting characters, 0 for none, -ve on error
 	 */
-	int (*pending)(struct udevice *dev, bool input);
+	int (*pending)(struct udevice *dev);
 	/**
 	 * clear() - Clear the serial FIFOs/holding registers
 	 *
-- 
2.20.1



More information about the U-Boot mailing list