On Tue, 20 Sep 2022, Jiri Slaby wrote: > uart_port_tx_limited() is a new helper to send characters to the device. > Use it in these drivers. > > mux.c also needs to define tx_done(). But I'm not sure if the driver > really wants to wait for all the characters to dismiss from the HW fifo > at this code point. Hence I marked this as FIXME. > > Signed-off-by: Jiri Slaby > Cc: Russell King > Cc: Florian Fainelli > Cc: bcm-kernel-feedback-list@broadcom.com > Cc: "Pali Rohár" > Cc: Kevin Cernekee > Cc: Palmer Dabbelt > Cc: Paul Walmsley > Cc: Orson Zhai > Cc: Baolin Wang > Cc: Chunyan Zhang > Cc: Patrice Chotard > Cc: linux-riscv@lists.infradead.org Reviewed-by: Ilpo Järvinen One improvement suggestion below. > diff --git a/drivers/tty/serial/altera_jtaguart.c b/drivers/tty/serial/altera_jtaguart.c > index 23f339757894..f224f5141726 100644 > --- a/drivers/tty/serial/altera_jtaguart.c > +++ b/drivers/tty/serial/altera_jtaguart.c > @@ -137,39 +137,17 @@ static void altera_jtaguart_rx_chars(struct altera_jtaguart *pp) > static void altera_jtaguart_tx_chars(struct altera_jtaguart *pp) > { > struct uart_port *port = &pp->port; > - struct circ_buf *xmit = &port->state->xmit; > - unsigned int pending, count; > - > - if (port->x_char) { > - /* Send special char - probably flow control */ > - writel(port->x_char, port->membase + ALTERA_JTAGUART_DATA_REG); > - port->x_char = 0; > - port->icount.tx++; > - return; > - } > + unsigned int space; > + u8 ch; > > - pending = uart_circ_chars_pending(xmit); > - if (pending > 0) { > - count = (readl(port->membase + ALTERA_JTAGUART_CONTROL_REG) & > - ALTERA_JTAGUART_CONTROL_WSPACE_MSK) >> > - ALTERA_JTAGUART_CONTROL_WSPACE_OFF; > - if (count > pending) > - count = pending; > - if (count > 0) { > - pending -= count; > - while (count--) { > - writel(xmit->buf[xmit->tail], > - port->membase + ALTERA_JTAGUART_DATA_REG); > - xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); > - port->icount.tx++; > - } > - if (pending < WAKEUP_CHARS) > - uart_write_wakeup(port); > - } > - } > + space = readl(port->membase + ALTERA_JTAGUART_CONTROL_REG); > + space &= ALTERA_JTAGUART_CONTROL_WSPACE_MSK; > + space >>= ALTERA_JTAGUART_CONTROL_WSPACE_OFF; This is FIELD_GET(ALTERA_JTAGUART_CONTROL_WSPACE_MSK, ...) & then allows killing ALTERA_JTAGUART_CONTROL_WSPACE_OFF. I'd probably do it in a separate patch though. -- i.