tty: TX helpers
Subsystems (17)
v4 cover tty: TX helpers
This series introduces uart_port_tx() + uart_port_tx_limited() TX helpers. See PATCH 8/10 for the details. Comments welcome.
First the series performs simple cleanups, so that the later patches are easier to follow.
Then it switches drivers to use them. First, to uart_port_tx() in 9/10 and then uart_port_tx_limited() in 10/10.
The diffstat of patches 9+10 is as follows:
26 files changed, 145 insertions(+), 740 deletions(-)
which appears to be nice.
Jiri Slaby (10):
tty: serial: move and cleanup vt8500_tx_empty()
tty: serial: clean up stop-tx part in altera_uart_tx_chars()
tty: serial: altera_uart_{r,t}x_chars() need only uart_port
tty: serial: extract lqasc_tx_ready() from lqasc_tx_chars()
tty: serial: extract tx_ready() from __serial_lpc32xx_tx()
tty: serial: switch mpc52xx_uart_int_{r,t}x_chars() to bool
tty: serial: extract serial_omap_put_char() from transmit_chars()
tty: serial: introduce transmit helpers
tty: serial: use uart_port_tx() helper
tty: serial: use uart_port_tx_limited()
Documentation/driver-api/serial/driver.rst | 3 + drivers/tty/serial/21285.c | 32 ++------- drivers/tty/serial/altera_jtaguart.c | 40 +++-------- drivers/tty/serial/altera_uart.c | 41 +++-------- drivers/tty/serial/amba-pl010.c | 32 ++------- drivers/tty/serial/apbuart.c | 34 ++------- drivers/tty/serial/atmel_serial.c | 28 ++------ drivers/tty/serial/bcm63xx_uart.c | 47 +++---------- drivers/tty/serial/fsl_lpuart.c | 30 ++------ drivers/tty/serial/lantiq.c | 44 +++--------- drivers/tty/serial/lpc32xx_hs.c | 39 +++-------- drivers/tty/serial/mcf.c | 28 ++------ drivers/tty/serial/mpc52xx_uart.c | 49 +++---------- drivers/tty/serial/mps2-uart.c | 26 ++----- drivers/tty/serial/mux.c | 45 ++++-------- drivers/tty/serial/mvebu-uart.c | 38 ++-------- drivers/tty/serial/mxs-auart.c | 32 +++------ drivers/tty/serial/omap-serial.c | 46 ++++--------- drivers/tty/serial/owl-uart.c | 32 ++------- drivers/tty/serial/pxa.c | 33 ++------- drivers/tty/serial/rp2.c | 31 ++------- drivers/tty/serial/sa1100.c | 34 ++------- drivers/tty/serial/serial_txx9.c | 32 ++------- drivers/tty/serial/sifive.c | 31 ++------- drivers/tty/serial/sprd_serial.c | 33 ++------- drivers/tty/serial/st-asc.c | 48 ++----------- drivers/tty/serial/vt8500_serial.c | 41 +++-------- include/linux/serial_core.h | 80 ++++++++++++++++++++++ 28 files changed, 264 insertions(+), 765 deletions(-)
Signature · 1 line
2.37.3
PATCH v4 1/10 tty: serial: move and cleanup vt8500_tx_empty()
Make vt8500_tx_empty() more readable by introducing a new local variable and move the function before handle_tx(). That way we can reuse it in there too.
---
Notes:
[v3] this is new in v3 -- extracted as a separate change from later
patches
drivers/tty/serial/vt8500_serial.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/tty/serial/vt8500_serial.c +8 -7
@@ -187,6 +187,13 @@ static void handle_rx(struct uart_port *port)tty_flip_buffer_push (tport); } +static unsigned int vt8500_tx_empty (struct uart_port *port) +{ +unsigned int idx =vt8500_read (port,VT8500_URFIDX ) &0x1f ; + +return idx <16 ?TIOCSER_TEMT :0 ; +} +static void handle_tx (struct uart_port *port) {struct circ_buf *xmit = &port->state->xmit;
@@ -201,7 +208,7 @@ static void handle_tx(struct uart_port *port)return ; } -while ((vt8500_read (port,VT8500_URFIDX ) &0x1f ) <16 ) { +while (vt8500_tx_empty (port)) {if (uart_circ_empty (xmit))break ;
@@ -260,12 +267,6 @@ static irqreturn_t vt8500_irq(int irq, void *dev_id)return IRQ_HANDLED ; } -static unsigned int vt8500_tx_empty (struct uart_port *port) -{ -return (vt8500_read (port,VT8500_URFIDX ) &0x1f ) <16 ? -TIOCSER_TEMT :0 ; -} -static unsigned int vt8500_get_mctrl (struct uart_port *port) {unsigned int usr;
Signature · 1 line
2.37.3
Re: [PATCH v4 01/10] tty: serial: move and cleanup vt8500_tx_empty()
Quoted 6 lines · Jiri Slaby
Make
vt8500_tx_empty()more readable by introducing a new local variable and move the function beforehandle_tx(). That way we can reuse it in there too.Cc <[email protected]>Signed-off-by Jiri Slaby <[email protected]>
Signature · 1 line
i.
PATCH v4 2/10 tty: serial: clean up stop-tx part in altera_uart_tx_chars()
In reply to Jiri SlabyThe "stop TX" path in altera_uart_tx_chars() is open-coded, so:
* use uart_circ_empty() to check if the buffer is empty, and
* when true, call altera_uart_stop_tx().
---
Notes:
[v4] this is new in v4 -- extracted as a separate change
drivers/tty/serial/altera_uart.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/tty/serial/altera_uart.c +2 -4
@@ -272,10 +272,8 @@ static void altera_uart_tx_chars(struct altera_uart *pp)if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS )uart_write_wakeup (port); -if (xmit->head == xmit->tail) { - pp->imr &= ~ALTERA_UART_CONTROL_TRDY_MSK ; -altera_uart_update_ctrl_reg (pp); - } +if (uart_circ_empty (xmit)) +altera_uart_stop_tx (port); }static irqreturn_t altera_uart_interrupt (int irq,void *data)
Signature · 1 line
2.37.3
Re: [PATCH v4 02/10] tty: serial: clean up stop-tx part in altera_uart_tx_chars()
Quoted 6 lines · Jiri Slaby
The "stop TX" path in
altera_uart_tx_chars()is open-coded, so:
* useuart_circ_empty()to check if the buffer is empty, and
* when true, callaltera_uart_stop_tx().Cc Tobias Klauser <[email protected]>Signed-off-by Jiri Slaby <[email protected]>
Signature · 1 line
i.
Re: [PATCH v4 02/10] tty: serial: clean up stop-tx part in altera_uart_tx_chars()
In reply to Jiri SlabyQuoted 6 lines · Jiri Slaby
The "stop TX" path in
altera_uart_tx_chars()is open-coded, so:
* useuart_circ_empty()to check if the buffer is empty, and
* when true, callaltera_uart_stop_tx().Cc Tobias Klauser <[email protected]>Signed-off-by Jiri Slaby <[email protected]>
PATCH v4 3/10 tty: serial: altera_uart_{r,t}x_chars() need only uart_port
In reply to Jiri SlabyBoth altera_uart_{r,t}x_chars() need only uart_port, not altera_uart. So pass the former from altera_uart_interrupt() directly.
Apart it maybe saves a dereference, this makes the transition of altera_uart_tx_chars() easier to follow in the next patch.
---
Notes:
[v4] this is new in v4 -- extracted as a separate change
drivers/tty/serial/altera_uart.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/tty/serial/altera_uart.c +4 -6
@@ -199,9 +199,8 @@ static void altera_uart_set_termios(struct uart_port *port,*/ } -static void altera_uart_rx_chars (struct altera_uart *pp) +static void altera_uart_rx_chars (struct uart_port *port) { -struct uart_port *port = &pp->port;unsigned char ch, flag;unsigned short status;
@@ -246,9 +245,8 @@ static void altera_uart_rx_chars(struct altera_uart *pp)tty_flip_buffer_push (&port->state->port); } -static void altera_uart_tx_chars (struct altera_uart *pp) +static void altera_uart_tx_chars (struct uart_port *port) { -struct uart_port *port = &pp->port;struct circ_buf *xmit = &port->state->xmit;if (port->x_char) {
@@ -286,9 +284,9 @@ static irqreturn_t altera_uart_interrupt(int irq, void *data)spin_lock (&port->lock);if (isr &ALTERA_UART_STATUS_RRDY_MSK ) -altera_uart_rx_chars (pp); +altera_uart_rx_chars (port);if (isr &ALTERA_UART_STATUS_TRDY_MSK ) -altera_uart_tx_chars (pp); +altera_uart_tx_chars (port);spin_unlock (&port->lock);return IRQ_RETVAL (isr);
Signature · 1 line
2.37.3
Re: [PATCH v4 03/10] tty: serial: altera_uart_{r,t}x_chars() need only uart_port
Quoted 8 lines · Jiri Slaby
Both altera_uart_{r,t}x_chars() need only
uart_port, notaltera_uart. So pass the former fromaltera_uart_interrupt()directly.Apart it maybe saves a dereference, this makes the transition of
altera_uart_tx_chars()easier to follow in the next patch.Cc Tobias Klauser <[email protected]>Signed-off-by Jiri Slaby <[email protected]>
Signature · 1 line
i.
Re: [PATCH v4 03/10] tty: serial: altera_uart_{r,t}x_chars() need only uart_port
In reply to Jiri SlabyQuoted 8 lines · Jiri Slaby
Both altera_uart_{r,t}x_chars() need only
uart_port, notaltera_uart. So pass the former fromaltera_uart_interrupt()directly.Apart it maybe saves a dereference, this makes the transition of
altera_uart_tx_chars()easier to follow in the next patch.Cc Tobias Klauser <[email protected]>Signed-off-by Jiri Slaby <[email protected]>
PATCH v4 4/10 tty: serial: extract lqasc_tx_ready() from lqasc_tx_chars()
In reply to Jiri SlabyThe condition in lqasc_tx_chars()'s loop is barely readable. Extract it to a separate function. This will make the cleanup in the next patches easier too.
(Put it before lqasc_start_tx(), so that we can use it there later.)
---
Notes:
[v4] this is new in v4 -- extracted as a separate change
drivers/tty/serial/lantiq.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/tty/serial/lantiq.c +8 -2
@@ -139,6 +139,13 @@ lqasc_stop_tx(struct uart_port *port)return ; } +static bool lqasc_tx_ready (struct uart_port *port) +{ +u32 fstat =__raw_readl (port->membase +LTQ_ASC_FSTAT ); + +return (fstat &ASCFSTAT_TXFREEMASK ) >>ASCFSTAT_TXFREEOFF ; +} +static void lqasc_start_tx (struct uart_port *port) {
@@ -228,8 +235,7 @@ lqasc_tx_chars(struct uart_port *port)return ; } -while (((__raw_readl (port->membase +LTQ_ASC_FSTAT ) & -ASCFSTAT_TXFREEMASK ) >>ASCFSTAT_TXFREEOFF ) !=0 ) { +while (lqasc_tx_ready (port)) {if (port->x_char) {writeb (port->x_char, port->membase +LTQ_ASC_TBUF ); port->icount.tx++;
Signature · 1 line
2.37.3
Re: [PATCH v4 04/10] tty: serial: extract lqasc_tx_ready() from lqasc_tx_chars()
Quoted 20 lines · Jiri Slaby
The condition in lqasc_tx_chars()'s loop is barely readable. Extract it to a separate function. This will make the cleanup in the next patches easier too.
(Put it before
lqasc_start_tx(), so that we can use it there later.)Signed-off-by Jiri Slaby <[email protected]>---
Notes:
[v4] this is new in v4 -- extracted as a separate changedrivers/tty/serial/lantiq.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)drivers/tty/serial/lantiq.c +0
-0
drivers/tty/serial/lantiq.c lqasc_stop_tx(struct uart_port *port) · line 146
Quoted 8 lines
drivers/tty/serial/lantiq.c +5
-0@@ -139,6 +139,13 @@ lqasc_stop_tx(struct uart_port *port)return ; } +static bool lqasc_tx_ready (struct uart_port *port) +{ +u32 fstat =__raw_readl (port->membase +LTQ_ASC_FSTAT ); + +return (fstat &ASCFSTAT_TXFREEMASK ) >>ASCFSTAT_TXFREEOFF ;
FIELD_GET(ASCFSTAT_TXFREEMASK, fstat)
Quoted 6 lines
drivers/tty/serial/lantiq.c +2
-0+} +static void lqasc_start_tx (struct uart_port *port) {
drivers/tty/serial/lantiq.c lqasc_tx_chars(struct uart_port *port) · line 241
Quoted 9 lines
drivers/tty/serial/lantiq.c +1
-2@@ -228,8 +235,7 @@ lqasc_tx_chars(struct uart_port *port)return ; } -while (((__raw_readl (port->membase +LTQ_ASC_FSTAT ) & -ASCFSTAT_TXFREEMASK ) >>ASCFSTAT_TXFREEOFF ) !=0 ) { +while (lqasc_tx_ready (port)) {if (port->x_char) {writeb (port->x_char, port->membase +LTQ_ASC_TBUF ); port->icount.tx++;
There's similar construct in lqasc_console_putchar() that could take advantage of the same helper.
With FIELD_GET + the other place using the new helper, ASCFSTAT_TXFREEOFF can be dropped as well.
Signature · 1 line
i.
PATCH v4 5/10 tty: serial: extract tx_ready() from __serial_lpc32xx_tx()
In reply to Jiri SlabyThe condition in __serial_lpc32xx_tx()'s loop is barely readable. Extract it to a separate function. This will make the cleanup in the next patches easier too.
---
Notes:
[v4] this is new in v4 -- extracted as a separate change
drivers/tty/serial/lpc32xx_hs.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
drivers/tty/serial/lpc32xx_hs.c +8 -2
@@ -278,6 +278,13 @@ static void __serial_lpc32xx_rx(struct uart_port *port)static void serial_lpc32xx_stop_tx (struct uart_port *port); +static bool serial_lpc32xx_tx_ready (struct uart_port *port) +{ +u32 level =readl (LPC32XX_HSUART_LEVEL (port->membase)); + +return LPC32XX_HSU_TX_LEV (level) <64 ; +} +static void __serial_lpc32xx_tx (struct uart_port *port) {struct circ_buf *xmit = &port->state->xmit;
@@ -293,8 +300,7 @@ static void __serial_lpc32xx_tx(struct uart_port *port) goto exit_tx;/* Transfer data */ -while (LPC32XX_HSU_TX_LEV (readl ( -LPC32XX_HSUART_LEVEL (port->membase))) <64 ) { +while (serial_lpc32xx_tx_ready (port)) {writel ((u32 ) xmit->buf[xmit->tail],LPC32XX_HSUART_FIFO (port->membase)); xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 );
Signature · 1 line
2.37.3
Re: [PATCH v4 05/10] tty: serial: extract tx_ready() from __serial_lpc32xx_tx()
Quoted 7 lines · Jiri Slaby
The condition in __serial_lpc32xx_tx()'s loop is barely readable. Extract it to a separate function. This will make the cleanup in the next patches easier too.
Cc Vladimir Zapolskiy <[email protected]>Cc <[email protected]>Signed-off-by Jiri Slaby <[email protected]>
I noticed that wait_for_xmit_ready() uses < 32 for the similar check which seems fishy...
Signature · 1 line
i.
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v4 6/10 tty: serial: switch mpc52xx_uart_int_{r,t}x_chars() to bool
In reply to Jiri Slabympc52xx_uart_int_rx_chars() returns unsigned int.mpc52xx_uart_int_tx_chars() returns int.
The both results are binary ORed to the "keepgoing" variable. Unify all three to bool as the only interesting value is whether we should keep looping (true/false).
---
Notes:
[v4] this is new in v4 -- extracted as a separate change
drivers/tty/serial/mpc52xx_uart.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
drivers/tty/serial/mpc52xx_uart.c +9 -9
@@ -1364,7 +1364,7 @@ static const struct uart_ops mpc52xx_uart_ops = {/* Interrupt handling */ /* ======================================================================== */ -static inline unsigned int +static inline bool mpc52xx_uart_int_rx_chars (struct uart_port *port) {struct tty_port *tport = &port->state->port;
@@ -1425,7 +1425,7 @@ mpc52xx_uart_int_rx_chars(struct uart_port *port)return psc_ops->raw_rx_rdy (port); } -static inline int +static inline bool mpc52xx_uart_int_tx_chars (struct uart_port *port) {struct circ_buf *xmit = &port->state->xmit;
@@ -1435,13 +1435,13 @@ mpc52xx_uart_int_tx_chars(struct uart_port *port) psc_ops->write_char (port, port->x_char); port->icount.tx++; port->x_char =0 ; -return 1 ; +return true; }/* Nothing to do ? */ if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) {mpc52xx_uart_stop_tx (port); -return 0 ; +return false; }/* Send chars */
@@ -1460,23 +1460,23 @@ mpc52xx_uart_int_tx_chars(struct uart_port *port)/* Maybe we're done after all */ if (uart_circ_empty (xmit)) {mpc52xx_uart_stop_tx (port); -return 0 ; +return false; } -return 1 ; +return true; }static irqreturn_t mpc5xxx_uart_process_int (struct uart_port *port) {unsigned long pass =ISR_PASS_LIMIT ; -unsigned int keepgoing; +bool keepgoing;u8 status;/* While we have stuff to do, we continue */ do { /* If we don't find anything to do, we stop */ - keepgoing = 0; + keepgoing = false; psc_ops->rx_clr_irq(port); if (psc_ops->rx_rdy(port))
@@ -1495,7 +1495,7 @@ mpc5xxx_uart_process_int(struct uart_port *port)/* Limit number of iteration */ if (!(--pass)) - keepgoing =0 ; + keepgoing = false; }while (keepgoing);
Signature · 1 line
2.37.3
Re: [PATCH v4 06/10] tty: serial: switch mpc52xx_uart_int_{r,t}x_chars() to bool
Quoted 8 lines · Jiri Slaby
mpc52xx_uart_int_rx_chars()returns unsigned int.mpc52xx_uart_int_tx_chars()returns int.The both results are binary ORed to the "keepgoing" variable. Unify all three to bool as the only interesting value is whether we should keep looping (true/false).
Signed-off-by Jiri Slaby <[email protected]>
Signature · 1 line
i.
PATCH v4 7/10 tty: serial: extract serial_omap_put_char() from transmit_chars()
In reply to Jiri SlabyThis non-trivial code is doubled in transmit_chars(), so it deserves its own function. This will make next patches easier.
---
Notes:
[v4] this is new in v4 -- extracted as a separate change
drivers/tty/serial/omap-serial.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-)
drivers/tty/serial/omap-serial.c +11 -9
@@ -337,19 +337,24 @@ static void serial_omap_stop_rx(struct uart_port *port)serial_out (up,UART_IER , up->ier); } +static void serial_omap_put_char (struct uart_omap_port *up,unsigned char ch) +{ +serial_out (up,UART_TX , ch); + +if ((up->port.rs485.flags &SER_RS485_ENABLED ) && + !(up->port.rs485.flags &SER_RS485_RX_DURING_TX )) + up->rs485_tx_filter_count++; +} +static void transmit_chars (struct uart_omap_port *up,unsigned int lsr) {struct circ_buf *xmit = &up->port.state->xmit;int count;if (up->port.x_char) { -serial_out (up,UART_TX , up->port.x_char); +serial_omap_put_char (up, up->port.x_char); up->port.icount.tx++; up->port.x_char =0 ; -if ((up->port.rs485.flags &SER_RS485_ENABLED ) && - !(up->port.rs485.flags &SER_RS485_RX_DURING_TX )) - up->rs485_tx_filter_count++; -return ; }if (uart_circ_empty (xmit) ||uart_tx_stopped (&up->port)) {
@@ -358,12 +363,9 @@ static void transmit_chars(struct uart_omap_port *up, unsigned int lsr) } count = up->port.fifosize /4 ; do { - serial_out(up, UART_TX, xmit->buf[xmit->tail]); + serial_omap_put_char(up, xmit->buf[xmit->tail]); xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1); up->port.icount.tx++; - if ((up->port.rs485.flags & SER_RS485_ENABLED) && - !(up->port.rs485.flags & SER_RS485_RX_DURING_TX)) - up->rs485_tx_filter_count++; if (uart_circ_empty(xmit)) break;
Signature · 1 line
2.37.3
Re: [PATCH v4 07/10] tty: serial: extract serial_omap_put_char() from transmit_chars()
Quoted 4 lines · Jiri Slaby
This non-trivial code is doubled in
transmit_chars(), so it deserves its own function. This will make next patches easier.Signed-off-by Jiri Slaby <[email protected]>
Signature · 1 line
i.
PATCH v4 8/10 tty: serial: introduce transmit helpers
In reply to Jiri SlabyMany serial drivers do the same thing:
* send x_char if set
* keep sending from the xmit circular buffer until either
- the loop reaches the end of the xmit buffer
- TX is stopped
- HW fifo is full
* check for pending characters and:
- wake up tty writers to fill for more data into xmit buffer
- stop TX if there is nothing in the xmit buffer
The only differences are:
* how to write the character to the HW fifo
* the check of the end condition:
- is the HW fifo full?
- is limit of the written characters reached?
So unify the above into two helpers:
* uart_port_tx_limited() -- it performs the above taking the written characters limit into account, and
* uart_port_tx() -- the same as above, except it only checks the HW readiness, not the characters limit.
The HW specific operations (as stated as "differences" above) are passed as arguments to the macros. They are:
* tx_ready -- returns true if HW can accept more data.
* put_char -- write a character to the device.
* tx_done -- when the write loop is done, perform arbitrary action before potential invocation of ops->stop_tx() happens.
Note that the above are macros. This means the code is generated in place and the above 3 arguments are "inlined". I.e. no added penalty by generating call instructions for every single character. Nor any indirect calls. (As in some previous versions of this patchset.)
---
Notes:
[v4] switch from helper generators to helpers similar to wait_event()
[Arnd]
Documentation/driver-api/serial/driver.rst | 3 + include/linux/serial_core.h | 80 ++++++++++++++++++++++ 2 files changed, 83 insertions(+)
Documentation/driver-api/serial/driver.rst +3 -0
@@ -78,6 +78,9 @@ Other functions uart_get_lsr_info uart_handle_dcd_change uart_handle_cts_change uart_try_toggle_sysrq uart_get_console +.. kernel-doc:: include/linux/serial_core.h + :identifiers: uart_port_tx_limited uart_port_tx + Other notes -----------
include/linux/serial_core.h +80 -0
86 lines not on this page · raw message
Signature · 1 line
2.37.3
Re: [PATCH v4 08/10] tty: serial: introduce transmit helpers
Quoted 29 lines · Jiri Slaby
Many serial drivers do the same thing:
* sendx_charif set
* keep sending from the xmit circular buffer until either
- the loop reaches the end of the xmit buffer
- TX is stopped
- HW fifo is full
* check for pending characters and:
- wake up tty writers to fill for more data into xmit buffer
- stop TX if there is nothing in the xmit bufferThe only differences are:
* how to write the character to the HW fifo
* the check of the end condition:
- is the HW fifo full?
- is limit of the written characters reached?So unify the above into two helpers:
*uart_port_tx_limited()-- it performs the above taking the written characters limit into account, and
*uart_port_tx()-- the same as above, except it only checks the HW readiness, not the characters limit.The HW specific operations (as stated as "differences" above) are passed as arguments to the macros. They are:
*tx_ready-- returns true if HW can accept more data.
*put_char-- write a character to the device.
*tx_done-- when the write loop is done, perform arbitrary action before potential invocation ofops->stop_tx()happens.
Quoted 6 lines
Note that the above are macros. This means the code is generated in place and the above 3 arguments are "inlined". I.e. no added penalty by generating call instructions for every single character. Nor any indirect calls. (As in some previous versions of this patchset.)
Signed-off-by Jiri Slaby <[email protected]>
Signature · 1 line
i.
PATCH v4 9/10 tty: serial: use uart_port_tx() helper
In reply to Jiri Slabyuart_port_tx() is a new helper to send characters to the device. Use it in these drivers.
---
Notes:
[v4] switch from DEFINE_UART_PORT_TX_HELPER() (helper generator) to
uart_port_tx() (akin to wait_event())
[v3] remove stray \n removal (Ilpo)
drivers/tty/serial/altera_uart.c | 29 ++++------------------ drivers/tty/serial/atmel_serial.c | 28 +++++---------------- drivers/tty/serial/fsl_lpuart.c | 30 ++++------------------- drivers/tty/serial/lantiq.c | 36 +++------------------------ drivers/tty/serial/lpc32xx_hs.c | 33 +++---------------------- drivers/tty/serial/mcf.c | 28 +++++---------------- drivers/tty/serial/mpc52xx_uart.c | 39 +++--------------------------- drivers/tty/serial/mps2-uart.c | 26 +++----------------- drivers/tty/serial/mxs-auart.c | 32 ++++++------------------ drivers/tty/serial/owl-uart.c | 32 +++--------------------- drivers/tty/serial/sa1100.c | 34 +++----------------------- drivers/tty/serial/vt8500_serial.c | 30 +++-------------------- 12 files changed, 58 insertions(+), 319 deletions(-)
drivers/tty/serial/altera_uart.c +5 -24
@@ -247,31 +247,12 @@ static void altera_uart_rx_chars(struct uart_port *port)static void altera_uart_tx_chars (struct uart_port *port) { -struct circ_buf *xmit = &port->state->xmit; - -if (port->x_char) { -/* Send special char - probably flow control */ -altera_uart_writel (port, port->x_char,ALTERA_UART_TXDATA_REG ); - port->x_char =0 ; - port->icount.tx++; -return ; - } - -while (altera_uart_readl (port,ALTERA_UART_STATUS_REG ) & -ALTERA_UART_STATUS_TRDY_MSK ) { -if (xmit->head == xmit->tail) -break ; -altera_uart_writel (port, xmit->buf[xmit->tail], -ALTERA_UART_TXDATA_REG ); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - port->icount.tx++; - } - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (port); +u8 ch; -if (uart_circ_empty (xmit)) -altera_uart_stop_tx (port); +uart_port_tx (port, ch, +altera_uart_readl (port,ALTERA_UART_STATUS_REG ) & +ALTERA_UART_STATUS_TRDY_MSK , +altera_uart_writel (port, ch,ALTERA_UART_TXDATA_REG )); }static irqreturn_t altera_uart_interrupt (int irq,void *data)
drivers/tty/serial/atmel_serial.c +6 -22
@@ -816,30 +816,14 @@ static void atmel_rx_chars(struct uart_port *port)*/ static void atmel_tx_chars (struct uart_port *port) { -struct circ_buf *xmit = &port->state->xmit;struct atmel_uart_port *atmel_port =to_atmel_uart_port (port); +bool pending; +u8 ch; -if (port->x_char && - (atmel_uart_readl (port,ATMEL_US_CSR ) &ATMEL_US_TXRDY )) { -atmel_uart_write_char (port, port->x_char); - port->icount.tx++; - port->x_char =0 ; - } -if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) -return ; - -while (atmel_uart_readl (port,ATMEL_US_CSR ) &ATMEL_US_TXRDY ) { -atmel_uart_write_char (port, xmit->buf[xmit->tail]); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - port->icount.tx++; -if (uart_circ_empty (xmit)) -break ; - } - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (port); - -if (!uart_circ_empty (xmit)) { + pending =uart_port_tx (port, ch, +atmel_uart_readl (port,ATMEL_US_CSR ) &ATMEL_US_TXRDY , +atmel_uart_write_char (port, ch)); +if (pending) {/* we still have characters to transmit, so we should continue * transmitting them when TX is ready, regardless of * mode or duplexity
drivers/tty/serial/fsl_lpuart.c +5 -25
@@ -742,32 +742,12 @@ static int lpuart32_poll_get_char(struct uart_port *port)static inline void lpuart_transmit_buffer (struct lpuart_port *sport) { -struct circ_buf *xmit = &sport->port.state->xmit; - -if (sport->port.x_char) { -writeb (sport->port.x_char, sport->port.membase +UARTDR ); - sport->port.icount.tx++; - sport->port.x_char =0 ; -return ; - } - -if (lpuart_stopped_or_empty (&sport->port)) { -lpuart_stop_tx (&sport->port); -return ; - } - -while (!uart_circ_empty (xmit) && - (readb (sport->port.membase +UARTTCFIFO ) < sport->txfifo_size)) { -writeb (xmit->buf[xmit->tail], sport->port.membase +UARTDR ); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - sport->port.icount.tx++; - } - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (&sport->port); +struct uart_port *port = &sport->port; +u8 ch; -if (uart_circ_empty (xmit)) -lpuart_stop_tx (&sport->port); +uart_port_tx (port, ch, +readb (port->membase +UARTTCFIFO ) < sport->txfifo_size, +writeb (ch, port->membase +UARTDR )); }static inline void lpuart32_transmit_buffer (struct lpuart_port *sport)
drivers/tty/serial/lantiq.c +4 -32
@@ -95,7 +95,6 @@#define ASCFSTAT_TXFREEMASK 0x3F000000#define ASCFSTAT_TXFREEOFF 24 -static void lqasc_tx_chars (struct uart_port *port);static struct ltq_uart_port *lqasc_port[MAXPORTS ];static struct uart_driver lqasc_reg;
@@ -151,9 +150,12 @@ lqasc_start_tx(struct uart_port *port) {unsigned long flags;struct ltq_uart_port *ltq_port =to_ltq_uart_port (port); +u8 ch;spin_lock_irqsave (<q_port->lock, flags); -lqasc_tx_chars (port); +uart_port_tx (port, ch, +lqasc_tx_ready (port), +writeb (ch, port->membase +LTQ_ASC_TBUF ));spin_unlock_irqrestore (<q_port->lock, flags);return ; }
@@ -226,36 +228,6 @@ lqasc_rx_chars(struct uart_port *port)return 0 ; } -static void -lqasc_tx_chars (struct uart_port *port) -{ -struct circ_buf *xmit = &port->state->xmit; -if (uart_tx_stopped (port)) { -lqasc_stop_tx (port); -return ; - } - -while (lqasc_tx_ready (port)) { -if (port->x_char) { -writeb (port->x_char, port->membase +LTQ_ASC_TBUF ); - port->icount.tx++; - port->x_char =0 ; -continue ; - } - -if (uart_circ_empty (xmit)) -break ; - -writeb (port->state->xmit.buf[port->state->xmit.tail], - port->membase +LTQ_ASC_TBUF ); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - port->icount.tx++; - } - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (port); -} -static irqreturn_t lqasc_tx_int (int irq,void *_port) {
drivers/tty/serial/lpc32xx_hs.c +4 -29
@@ -276,8 +276,6 @@ static void __serial_lpc32xx_rx(struct uart_port *port)tty_flip_buffer_push (tport); } -static void serial_lpc32xx_stop_tx (struct uart_port *port); -static bool serial_lpc32xx_tx_ready (struct uart_port *port) {u32 level =readl (LPC32XX_HSUART_LEVEL (port->membase));
@@ -287,34 +285,11 @@ static bool serial_lpc32xx_tx_ready(struct uart_port *port)static void __serial_lpc32xx_tx (struct uart_port *port) { -struct circ_buf *xmit = &port->state->xmit; - -if (port->x_char) { -writel ((u32 )port->x_char,LPC32XX_HSUART_FIFO (port->membase)); - port->icount.tx++; - port->x_char =0 ; -return ; - } - -if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) - goto exit_tx; - -/* Transfer data */ -while (serial_lpc32xx_tx_ready (port)) { -writel ((u32 ) xmit->buf[xmit->tail], -LPC32XX_HSUART_FIFO (port->membase)); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - port->icount.tx++; -if (uart_circ_empty (xmit)) -break ; - } - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (port); +u8 ch; -exit_tx: -if (uart_circ_empty (xmit)) -serial_lpc32xx_stop_tx (port); +uart_port_tx (port, ch, +serial_lpc32xx_tx_ready (port), +writel (ch,LPC32XX_HSUART_FIFO (port->membase))); }static irqreturn_t serial_lpc32xx_interrupt (int irq,void *dev_id)
drivers/tty/serial/mcf.c +6 -22
@@ -327,29 +327,13 @@ static void mcf_rx_chars(struct mcf_uart *pp)static void mcf_tx_chars (struct mcf_uart *pp) {struct uart_port *port = &pp->port; -struct circ_buf *xmit = &port->state->xmit; - -if (port->x_char) { -/* Send special char - probably flow control */ -writeb (port->x_char, port->membase +MCFUART_UTB ); - port->x_char =0 ; - port->icount.tx++; -return ; - } - -while (readb (port->membase +MCFUART_USR ) &MCFUART_USR_TXREADY ) { -if (uart_circ_empty (xmit)) -break ; -writeb (xmit->buf[xmit->tail], port->membase +MCFUART_UTB ); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - port->icount.tx++; - } - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (port); +unsigned int pending; +u8 ch; -if (uart_circ_empty (xmit)) { -mcf_stop_tx (port); + pending =uart_port_tx (port, ch, +readb (port->membase +MCFUART_USR ) &MCFUART_USR_TXREADY , +writeb (ch, port->membase +MCFUART_UTB )); +if (!pending) {/* Disable TX to negate RTS automatically */ if (port->rs485.flags &SER_RS485_ENABLED ) writeb(MCFUART_UCR_TXDISABLE,
drivers/tty/serial/mpc52xx_uart.c +4 -35
@@ -1428,42 +1428,11 @@ mpc52xx_uart_int_rx_chars(struct uart_port *port)static inline bool mpc52xx_uart_int_tx_chars (struct uart_port *port) { -struct circ_buf *xmit = &port->state->xmit; - -/* Process out of band chars */ -if (port->x_char) { - psc_ops->write_char (port, port->x_char); - port->icount.tx++; - port->x_char =0 ; -return true; - } - -/* Nothing to do ? */ -if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) { -mpc52xx_uart_stop_tx (port); -return false; - } - -/* Send chars */ -while (psc_ops->raw_tx_rdy (port)) { - psc_ops->write_char (port, xmit->buf[xmit->tail]); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - port->icount.tx++; -if (uart_circ_empty (xmit)) -break ; - } - -/* Wake up */ -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (port); - -/* Maybe we're done after all */ -if (uart_circ_empty (xmit)) { -mpc52xx_uart_stop_tx (port); -return false; - } +u8 ch; -return true; +return uart_port_tx (port, ch, + psc_ops->raw_tx_rdy (port), + psc_ops->write_char (port, ch)); } static irqreturn_t
drivers/tty/serial/mps2-uart.c +4 -22
@@ -129,29 +129,11 @@ static void mps2_uart_stop_tx(struct uart_port *port)static void mps2_uart_tx_chars (struct uart_port *port) { -struct circ_buf *xmit = &port->state->xmit; - -while (!(mps2_uart_read8 (port, UARTn_STATE) & UARTn_STATE_TX_FULL)) { -if (port->x_char) { -mps2_uart_write8 (port, port->x_char, UARTn_DATA); - port->x_char =0 ; - port->icount.tx++; -continue ; - } - -if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) -break ; - -mps2_uart_write8 (port, xmit->buf[xmit->tail], UARTn_DATA); - xmit->tail = (xmit->tail +1 ) %UART_XMIT_SIZE ; - port->icount.tx++; - } - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (port); +u8 ch; -if (uart_circ_empty (xmit)) -mps2_uart_stop_tx (port); +uart_port_tx (port, ch, +mps2_uart_tx_empty (port), +mps2_uart_write8 (port, ch, UARTn_DATA)); }static void mps2_uart_start_tx (struct uart_port *port)
drivers/tty/serial/mxs-auart.c +8 -24
@@ -569,6 +569,8 @@ static int mxs_auart_dma_tx(struct mxs_auart_port *s, int size)static void mxs_auart_tx_chars (struct mxs_auart_port *s) {struct circ_buf *xmit = &s->port.state->xmit; +bool pending; +u8 ch;if (auart_dma_enabled (s)) {u32 i =0 ;
@@ -603,31 +605,13 @@ static void mxs_auart_tx_chars(struct mxs_auart_port *s)return ; } - -while (!(mxs_read (s,REG_STAT ) &AUART_STAT_TXFF )) { -if (s->port.x_char) { - s->port.icount.tx++; -mxs_write (s->port.x_char, s,REG_DATA ); - s->port.x_char =0 ; -continue ; - } -if (!uart_circ_empty (xmit) && !uart_tx_stopped (&s->port)) { - s->port.icount.tx++; -mxs_write (xmit->buf[xmit->tail], s,REG_DATA ); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - }else -break ; - } -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (&s->port); - -if (uart_circ_empty (&(s->port.state->xmit))) -mxs_clr (AUART_INTR_TXIEN , s,REG_INTR ); -else + pending =uart_port_tx (&s->port, ch, + !(mxs_read (s,REG_STAT ) &AUART_STAT_TXFF ), +mxs_write (ch, s,REG_DATA )); +if (pending)mxs_set (AUART_INTR_TXIEN , s,REG_INTR ); - -if (uart_tx_stopped (&s->port)) -mxs_auart_stop_tx (&s->port); +else +mxs_clr (AUART_INTR_TXIEN , s,REG_INTR ); }static void mxs_auart_rx_char (struct mxs_auart_port *s)
drivers/tty/serial/owl-uart.c +4 -28
@@ -181,35 +181,11 @@ static void owl_uart_start_tx(struct uart_port *port)static void owl_uart_send_chars (struct uart_port *port) { -struct circ_buf *xmit = &port->state->xmit; -unsigned int ch; - -if (port->x_char) { -while (!(owl_uart_read (port,OWL_UART_STAT ) &OWL_UART_STAT_TFFU )) -cpu_relax (); -owl_uart_write (port, port->x_char,OWL_UART_TXDAT ); - port->icount.tx++; - port->x_char =0 ; - } - -if (uart_tx_stopped (port)) -return ; - -while (!(owl_uart_read (port,OWL_UART_STAT ) &OWL_UART_STAT_TFFU )) { -if (uart_circ_empty (xmit)) -break ; +u8 ch; - ch = xmit->buf[xmit->tail]; -owl_uart_write (port, ch,OWL_UART_TXDAT ); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - port->icount.tx++; - } - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (port); - -if (uart_circ_empty (xmit)) -owl_uart_stop_tx (port); +uart_port_tx (port, ch, + !(owl_uart_read (port,OWL_UART_STAT ) &OWL_UART_STAT_TFFU ), +owl_uart_write (port, ch,OWL_UART_TXDAT )); }static void owl_uart_receive_chars (struct uart_port *port)
drivers/tty/serial/sa1100.c +4 -30
@@ -228,14 +228,7 @@ sa1100_rx_chars(struct sa1100_port *sport)static void sa1100_tx_chars (struct sa1100_port *sport) { -struct circ_buf *xmit = &sport->port.state->xmit; - -if (sport->port.x_char) { -UART_PUT_CHAR (sport, sport->port.x_char); - sport->port.icount.tx++; - sport->port.x_char =0 ; -return ; - } +u8 ch;/* * Check the modem control lines before
@@ -243,28 +236,9 @@ static void sa1100_tx_chars(struct sa1100_port *sport)*/ sa1100_mctrl_check (sport); -if (uart_circ_empty (xmit) ||uart_tx_stopped (&sport->port)) { -sa1100_stop_tx (&sport->port); -return ; - } - -/* -* Tried using FIFO (not checking TNF) for fifo fill: -* still had the '4 bytes repeated' problem. -*/ -while (UART_GET_UTSR1 (sport) &UTSR1_TNF ) { -UART_PUT_CHAR (sport, xmit->buf[xmit->tail]); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - sport->port.icount.tx++; -if (uart_circ_empty (xmit)) -break ; - } - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (&sport->port); - -if (uart_circ_empty (xmit)) -sa1100_stop_tx (&sport->port); +uart_port_tx (&sport->port, ch, +UART_GET_UTSR1 (sport) &UTSR1_TNF , +UART_PUT_CHAR (sport, ch)); }static irqreturn_t sa1100_int (int irq,void *dev_id)
drivers/tty/serial/vt8500_serial.c +4 -26
@@ -196,33 +196,11 @@ static unsigned int vt8500_tx_empty(struct uart_port *port)static void handle_tx (struct uart_port *port) { -struct circ_buf *xmit = &port->state->xmit; +u8 ch; -if (port->x_char) { -writeb (port->x_char, port->membase +VT8500_TXFIFO ); - port->icount.tx++; - port->x_char =0 ; - } -if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) { -vt8500_stop_tx (port); -return ; - } - -while (vt8500_tx_empty (port)) { -if (uart_circ_empty (xmit)) -break ; - -writeb (xmit->buf[xmit->tail], port->membase +VT8500_TXFIFO ); - - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - port->icount.tx++; - } - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (port); - -if (uart_circ_empty (xmit)) -vt8500_stop_tx (port); +uart_port_tx (port, ch, +vt8500_tx_empty (port), +writeb (ch, port->membase +VT8500_TXFIFO )); }static void vt8500_start_tx (struct uart_port *port)
Signature · 1 line
2.37.3
Re: [PATCH v4 09/10] tty: serial: use uart_port_tx() helper
Quoted 49 lines · Jiri Slaby
uart_port_tx()is a new helper to send characters to the device. Use it in these drivers.Cc Tobias Klauser <[email protected]>Cc Richard Genoud <[email protected]>Cc Nicolas Ferre <[email protected]>Cc Alexandre Belloni <[email protected]>Cc Claudiu Beznea <[email protected]>Cc Vladimir Zapolskiy <[email protected]>Cc Liviu Dudau <[email protected]>Cc Sudeep Holla <[email protected]>Cc Lorenzo Pieralisi <[email protected]>Cc Shawn Guo <[email protected]>Cc Sascha Hauer <[email protected]>Cc Pengutronix Kernel Team <[email protected]>Cc Fabio Estevam <[email protected]>Cc NXP Linux Team <[email protected]>Cc "Andreas Färber" <[email protected]>Cc Manivannan Sadhasivam <[email protected]>Signed-off-by Jiri Slaby <[email protected]>---
drivers/tty/serial/mcf.c +0
-19@@ -327,29 +327,13 @@ static void mcf_rx_chars(struct mcf_uart *pp)static void mcf_tx_chars (struct mcf_uart *pp) {struct uart_port *port = &pp->port; -struct circ_buf *xmit = &port->state->xmit; - -if (port->x_char) { -/* Send special char - probably flow control */ -writeb (port->x_char, port->membase +MCFUART_UTB ); - port->x_char =0 ; - port->icount.tx++; -return ; - } - -while (readb (port->membase +MCFUART_USR ) &MCFUART_USR_TXREADY ) { -if (uart_circ_empty (xmit)) -break ; -writeb (xmit->buf[xmit->tail], port->membase +MCFUART_UTB ); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - port->icount.tx++; - } - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS )
drivers/tty/serial/mcf.c static void mcf_rx_chars(struct mcf_uart *pp) · line 336
Quoted 10 lines
drivers/tty/serial/mcf.c +6
-3-uart_write_wakeup (port); +unsigned int pending; +u8 ch; -if (uart_circ_empty (xmit)) { -mcf_stop_tx (port); + pending =uart_port_tx (port, ch, +readb (port->membase +MCFUART_USR ) &MCFUART_USR_TXREADY , +writeb (ch, port->membase +MCFUART_UTB )); +if (!pending) {
Why unsigned int pending here and bool pending in the other cases?
Signature · 1 line
i.
Jiri Slaby
maintainerRe: [PATCH v4 09/10] tty: serial: use uart_port_tx() helper
Quoted 55 lines · Ilpo Järvinen
Quoted 53 lines · Jiri Slaby
uart_port_tx()is a new helper to send characters to the device. Use it in these drivers.Cc Tobias Klauser <[email protected]>Cc Richard Genoud <[email protected]>Cc Nicolas Ferre <[email protected]>Cc Alexandre Belloni <[email protected]>Cc Claudiu Beznea <[email protected]>Cc Vladimir Zapolskiy <[email protected]>Cc Liviu Dudau <[email protected]>Cc Sudeep Holla <[email protected]>Cc Lorenzo Pieralisi <[email protected]>Cc Shawn Guo <[email protected]>Cc Sascha Hauer <[email protected]>Cc Pengutronix Kernel Team <[email protected]>Cc Fabio Estevam <[email protected]>Cc NXP Linux Team <[email protected]>Cc "Andreas Färber" <[email protected]>Cc Manivannan Sadhasivam <[email protected]>Signed-off-by Jiri Slaby <[email protected]>---
drivers/tty/serial/mcf.c +2
-20@@ -327,29 +327,13 @@ static void mcf_rx_chars(struct mcf_uart *pp)static void mcf_tx_chars (struct mcf_uart *pp) {struct uart_port *port = &pp->port; -struct circ_buf *xmit = &port->state->xmit; - -if (port->x_char) { -/* Send special char - probably flow control */ -writeb (port->x_char, port->membase +MCFUART_UTB ); - port->x_char =0 ; - port->icount.tx++; -return ; - } - -while (readb (port->membase +MCFUART_USR ) &MCFUART_USR_TXREADY ) { -if (uart_circ_empty (xmit)) -break ; -writeb (xmit->buf[xmit->tail], port->membase +MCFUART_UTB ); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - port->icount.tx++; - } - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (port); +unsigned int pending; +u8 ch;
Quoted 8 lines
drivers/tty/serial/mcf.c static void mcf_rx_chars(struct mcf_uart *pp) · line 336
Quoted 6 lines
drivers/tty/serial/mcf.c +4
-2-if (uart_circ_empty (xmit)) { -mcf_stop_tx (port); + pending =uart_port_tx (port, ch, +readb (port->membase +MCFUART_USR ) &MCFUART_USR_TXREADY , +writeb (ch, port->membase +MCFUART_UTB )); +if (!pending) {Why unsigned int pending here and bool pending in the other cases?
Right, I somehow omitted that pending is not used anywhere else. This should be bool too, of course.
Quoted 1 line
Reviewed-by Ilpo Järvinen <[email protected]>
thanks,
Signature · 2 lines
js suse labs
PATCH v4 10/10 tty: serial: use uart_port_tx_limited()
In reply to Jiri Slabyuart_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.
---
Notes:
[v4] switch from DEFINE_UART_PORT_TX_HELPER_LIMITED() (helper generator)
to uart_port_tx_limited() (akin to wait_event())
drivers/tty/serial/21285.c | 32 +++---------------- drivers/tty/serial/altera_jtaguart.c | 40 ++++++----------------- drivers/tty/serial/amba-pl010.c | 32 +++---------------- drivers/tty/serial/apbuart.c | 34 +++----------------- drivers/tty/serial/bcm63xx_uart.c | 47 ++++++--------------------- drivers/tty/serial/mux.c | 45 ++++++++------------------ drivers/tty/serial/mvebu-uart.c | 38 +++------------------- drivers/tty/serial/omap-serial.c | 32 +++---------------- drivers/tty/serial/pxa.c | 33 +++---------------- drivers/tty/serial/rp2.c | 31 ++++-------------- drivers/tty/serial/serial_txx9.c | 32 +++---------------- drivers/tty/serial/sifive.c | 31 +++--------------- drivers/tty/serial/sprd_serial.c | 33 +++---------------- drivers/tty/serial/st-asc.c | 48 +++------------------------- 14 files changed, 87 insertions(+), 421 deletions(-)
drivers/tty/serial/21285.c +5 -27
@@ -154,35 +154,13 @@ static irqreturn_t serial21285_rx_chars(int irq, void *dev_id)static irqreturn_t serial21285_tx_chars (int irq,void *dev_id) {struct uart_port *port = dev_id; -struct circ_buf *xmit = &port->state->xmit; -int count =256 ; - -if (port->x_char) { - *CSR_UARTDR = port->x_char; - port->icount.tx++; - port->x_char =0 ; - goto out; - } -if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) { -serial21285_stop_tx (port); - goto out; - } - -do { - *CSR_UARTDR = xmit->buf[xmit->tail]; - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - port->icount.tx++; -if (uart_circ_empty (xmit)) -break ; - }while (--count >0 && !(*CSR_UARTFLG &0x20 )); - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (port); +u8 ch; -if (uart_circ_empty (xmit)) -serial21285_stop_tx (port); +uart_port_tx_limited (port, ch,256 , + !(*CSR_UARTFLG &0x20 ), + *CSR_UARTDR = ch, + ({})); - out:return IRQ_HANDLED ; }
drivers/tty/serial/altera_jtaguart.c +9 -31
@@ -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 ; -if (pending ==0 ) -altera_jtaguart_stop_tx (port); +uart_port_tx_limited (port, ch, space, + true, +writel (ch, port->membase +ALTERA_JTAGUART_DATA_REG ), + ({})); }static irqreturn_t altera_jtaguart_interrupt (int irq,void *data)
drivers/tty/serial/amba-pl010.c +5 -27
@@ -164,34 +164,12 @@ static void pl010_rx_chars(struct uart_port *port)static void pl010_tx_chars (struct uart_port *port) { -struct circ_buf *xmit = &port->state->xmit; -int count; +u8 ch; -if (port->x_char) { -writel (port->x_char, port->membase + UART01x_DR); - port->icount.tx++; - port->x_char =0 ; -return ; - } -if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) { -pl010_stop_tx (port); -return ; - } - - count = port->fifosize >>1 ; -do { -writel (xmit->buf[xmit->tail], port->membase + UART01x_DR); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - port->icount.tx++; -if (uart_circ_empty (xmit)) -break ; - }while (--count >0 ); - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (port); - -if (uart_circ_empty (xmit)) -pl010_stop_tx (port); +uart_port_tx_limited (port, ch, port->fifosize >>1 , + true, +writel (ch, port->membase + UART01x_DR), + ({})); }static void pl010_modem_status (struct uart_amba_port *uap)
drivers/tty/serial/apbuart.c +5 -29
@@ -122,36 +122,12 @@ static void apbuart_rx_chars(struct uart_port *port)static void apbuart_tx_chars (struct uart_port *port) { -struct circ_buf *xmit = &port->state->xmit; -int count; - -if (port->x_char) { -UART_PUT_CHAR (port, port->x_char); - port->icount.tx++; - port->x_char =0 ; -return ; - } - -if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) { -apbuart_stop_tx (port); -return ; - } - -/* amba: fill FIFO */ - count = port->fifosize >>1 ; -do { -UART_PUT_CHAR (port, xmit->buf[xmit->tail]); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - port->icount.tx++; -if (uart_circ_empty (xmit)) -break ; - }while (--count >0 ); - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (port); +u8 ch; -if (uart_circ_empty (xmit)) -apbuart_stop_tx (port); +uart_port_tx_limited (port, ch, port->fifosize >>1 , + true, +UART_PUT_CHAR (port, ch), + ({})); }static irqreturn_t apbuart_int (int irq,void *dev_id)
drivers/tty/serial/bcm63xx_uart.c +9 -38
62 lines not on this page · raw message
drivers/tty/serial/mux.c +13 -32
58 lines not on this page · raw message
drivers/tty/serial/mvebu-uart.c +5 -33
@@ -335,40 +335,12 @@ static void mvebu_uart_rx_chars(struct uart_port *port, unsigned int status)static void mvebu_uart_tx_chars (struct uart_port *port,unsigned int status) { -struct circ_buf *xmit = &port->state->xmit; -unsigned int count; -unsigned int st; - -if (port->x_char) { -writel (port->x_char, port->membase +UART_TSH (port)); - port->icount.tx++; - port->x_char =0 ; -return ; - } - -if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) { -mvebu_uart_stop_tx (port); -return ; - } - -for (count =0 ; count < port->fifosize; count++) { -writel (xmit->buf[xmit->tail], port->membase +UART_TSH (port)); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - port->icount.tx++; - -if (uart_circ_empty (xmit)) -break ; - - st =readl (port->membase +UART_STAT ); -if (st &STAT_TX_FIFO_FUL ) -break ; - } - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (port); +u8 ch; -if (uart_circ_empty (xmit)) -mvebu_uart_stop_tx (port); +uart_port_tx_limited (port, ch, port->fifosize, + !(readl (port->membase +UART_STAT ) &STAT_TX_FIFO_FUL ), +writel (ch, port->membase +UART_TSH (port)), + ({})); }static irqreturn_t mvebu_uart_isr (int irq,void *dev_id)
drivers/tty/serial/omap-serial.c +5 -27
@@ -348,34 +348,12 @@ static void serial_omap_put_char(struct uart_omap_port *up, unsigned char ch)static void transmit_chars (struct uart_omap_port *up,unsigned int lsr) { -struct circ_buf *xmit = &up->port.state->xmit; -int count; +u8 ch; -if (up->port.x_char) { -serial_omap_put_char (up, up->port.x_char); - up->port.icount.tx++; - up->port.x_char =0 ; -return ; - } -if (uart_circ_empty (xmit) ||uart_tx_stopped (&up->port)) { -serial_omap_stop_tx (&up->port); -return ; - } - count = up->port.fifosize /4 ; -do { -serial_omap_put_char (up, xmit->buf[xmit->tail]); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - up->port.icount.tx++; - -if (uart_circ_empty (xmit)) -break ; - }while (--count >0 ); - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (&up->port); - -if (uart_circ_empty (xmit)) -serial_omap_stop_tx (&up->port); +uart_port_tx_limited (&up->port, ch, up->port.fifosize /4 , + true, +serial_omap_put_char (up, ch), + ({})); }static inline void serial_omap_enable_ier_thri (struct uart_omap_port *up)
drivers/tty/serial/pxa.c +5 -28
@@ -174,35 +174,12 @@ static inline void receive_chars(struct uart_pxa_port *up, int *status)static void transmit_chars (struct uart_pxa_port *up) { -struct circ_buf *xmit = &up->port.state->xmit; -int count; +u8 ch; -if (up->port.x_char) { -serial_out (up,UART_TX , up->port.x_char); - up->port.icount.tx++; - up->port.x_char =0 ; -return ; - } -if (uart_circ_empty (xmit) ||uart_tx_stopped (&up->port)) { -serial_pxa_stop_tx (&up->port); -return ; - } - - count = up->port.fifosize /2 ; -do { -serial_out (up,UART_TX , xmit->buf[xmit->tail]); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - up->port.icount.tx++; -if (uart_circ_empty (xmit)) -break ; - }while (--count >0 ); - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (&up->port); - - -if (uart_circ_empty (xmit)) -serial_pxa_stop_tx (&up->port); +uart_port_tx_limited (&up->port, ch, up->port.fifosize /2 , + true, +serial_out (up,UART_TX , ch), + ({})); }static void serial_pxa_start_tx (struct uart_port *port)
drivers/tty/serial/rp2.c +6 -25
@@ -427,32 +427,13 @@ static void rp2_rx_chars(struct rp2_uart_port *up)static void rp2_tx_chars (struct rp2_uart_port *up) { -u16 max_tx =FIFO_SIZE -readw (up->base +RP2_TX_FIFO_COUNT ); -struct circ_buf *xmit = &up->port.state->xmit; +u8 ch; -if (uart_tx_stopped (&up->port)) { -rp2_uart_stop_tx (&up->port); -return ; - } - -for (; max_tx !=0 ; max_tx--) { -if (up->port.x_char) { -writeb (up->port.x_char, up->base +RP2_DATA_BYTE ); - up->port.x_char =0 ; - up->port.icount.tx++; -continue ; - } -if (uart_circ_empty (xmit)) { -rp2_uart_stop_tx (&up->port); -break ; - } -writeb (xmit->buf[xmit->tail], up->base +RP2_DATA_BYTE ); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - up->port.icount.tx++; - } - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (&up->port); +uart_port_tx_limited (&up->port, ch, +FIFO_SIZE -readw (up->base +RP2_TX_FIFO_COUNT ), + true, +writeb (ch, up->base +RP2_DATA_BYTE ), + ({})); }static void rp2_ch_interrupt (struct rp2_uart_port *up)
drivers/tty/serial/serial_txx9.c +5 -27
@@ -321,34 +321,12 @@ receive_chars(struct uart_port *up, unsigned int *status)static inline void transmit_chars (struct uart_port *up) { -struct circ_buf *xmit = &up->state->xmit; -int count; +u8 ch; -if (up->x_char) { -sio_out (up,TXX9_SITFIFO , up->x_char); - up->icount.tx++; - up->x_char =0 ; -return ; - } -if (uart_circ_empty (xmit) ||uart_tx_stopped (up)) { -serial_txx9_stop_tx (up); -return ; - } - - count =TXX9_SIO_TX_FIFO ; -do { -sio_out (up,TXX9_SITFIFO , xmit->buf[xmit->tail]); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - up->icount.tx++; -if (uart_circ_empty (xmit)) -break ; - }while (--count >0 ); - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (up); - -if (uart_circ_empty (xmit)) -serial_txx9_stop_tx (up); +uart_port_tx_limited (up, ch,TXX9_SIO_TX_FIFO , + true, +sio_out (up,TXX9_SITFIFO , ch), + ({})); }static irqreturn_t serial_txx9_interrupt (int irq,void *dev_id)
drivers/tty/serial/sifive.c +5 -26
@@ -288,33 +288,12 @@ static void __ssp_transmit_char(struct sifive_serial_port *ssp, int ch)*/ static void __ssp_transmit_chars (struct sifive_serial_port *ssp) { -struct circ_buf *xmit = &ssp->port.state->xmit; -int count; - -if (ssp->port.x_char) { -__ssp_transmit_char (ssp, ssp->port.x_char); - ssp->port.icount.tx++; - ssp->port.x_char =0 ; -return ; - } -if (uart_circ_empty (xmit) ||uart_tx_stopped (&ssp->port)) { -sifive_serial_stop_tx (&ssp->port); -return ; - } - count =SIFIVE_TX_FIFO_DEPTH ; -do { -__ssp_transmit_char (ssp, xmit->buf[xmit->tail]); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - ssp->port.icount.tx++; -if (uart_circ_empty (xmit)) -break ; - }while (--count >0 ); - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (&ssp->port); +u8 ch; -if (uart_circ_empty (xmit)) -sifive_serial_stop_tx (&ssp->port); +uart_port_tx_limited (&ssp->port, ch,SIFIVE_TX_FIFO_DEPTH , + true, +__ssp_transmit_char (ssp, ch), + ({})); }/**
drivers/tty/serial/sprd_serial.c +5 -28
@@ -626,35 +626,12 @@ static inline void sprd_rx(struct uart_port *port)static inline void sprd_tx (struct uart_port *port) { -struct circ_buf *xmit = &port->state->xmit; -int count; - -if (port->x_char) { -serial_out (port,SPRD_TXD , port->x_char); - port->icount.tx++; - port->x_char =0 ; -return ; - } - -if (uart_circ_empty (xmit) ||uart_tx_stopped (port)) { -sprd_stop_tx (port); -return ; - } - - count =THLD_TX_EMPTY ; -do { -serial_out (port,SPRD_TXD , xmit->buf[xmit->tail]); - xmit->tail = (xmit->tail +1 ) & (UART_XMIT_SIZE -1 ); - port->icount.tx++; -if (uart_circ_empty (xmit)) -break ; - }while (--count >0 ); - -if (uart_circ_chars_pending (xmit) <WAKEUP_CHARS ) -uart_write_wakeup (port); +u8 ch; -if (uart_circ_empty (xmit)) -sprd_stop_tx (port); +uart_port_tx_limited (port, ch,THLD_TX_EMPTY , + true, +serial_out (port,SPRD_TXD , ch), + ({})); }/* this handles the interrupt from one port */
drivers/tty/serial/st-asc.c +5 -43
55 lines not on this page · raw message
Signature · 1 line
2.37.3
Re: [PATCH v4 10/10] tty: serial: use uart_port_tx_limited()
Quoted 7 lines · Jiri Slaby
uart_port_tx_limited()is a new helper to send characters to the device. Use it in these drivers.
mux.calso needs to definetx_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.
Quoted 13 lines
Signed-off-by Jiri Slaby <[email protected]>Cc Russell King <[email protected]>Cc Florian Fainelli <[email protected]>Cc "Pali Rohár" <[email protected]>Cc Kevin Cernekee <[email protected]>Cc Palmer Dabbelt <[email protected]>Cc Paul Walmsley <[email protected]>Cc Orson Zhai <[email protected]>Cc Baolin Wang <[email protected]>Cc Chunyan Zhang <[email protected]>Cc Patrice Chotard <[email protected]>
One improvement suggestion below.
Quoted 33 lines
drivers/tty/serial/altera_jtaguart.c +2
-22@@ -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 );
drivers/tty/serial/altera_jtaguart.c static void altera_jtaguart_rx_chars(struct altera_jtaguart *pp) · line 145
Quoted 10 lines
drivers/tty/serial/altera_jtaguart.c +3
-7- 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.
Signature · 1 line
i.
Jiri Slaby
maintainerRe: [PATCH v4 10/10] tty: serial: use uart_port_tx_limited()
Quoted 8 lines · Ilpo Järvinen
One improvement suggestion below.
Quoted 6 lines
drivers/tty/serial/altera_jtaguart.c +0
-0@@ -137,39 +137,17 @@ static void altera_jtaguart_rx_chars(struct altera_jtaguart *pp)static void altera_jtaguart_tx_chars (struct altera_jtaguart *pp)
...
Quoted 7 lines
drivers/tty/serial/altera_jtaguart.c static void altera_jtaguart_rx_chars(struct altera_jtaguart *pp) · line 145
Quoted 3 lines
drivers/tty/serial/altera_jtaguart.c +3
-0+ 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 killingALTERA_JTAGUART_CONTROL_WSPACE_OFF. I'd probably do it in a separate patch though.
Right. Prepared for v5.
thanks,
Signature · 2 lines
js suse labs
Greg KH
maintainerQuoted 6 lines · Jiri Slaby
This series introduces
uart_port_tx()+uart_port_tx_limited()TX helpers. See PATCH 8/10 for the details. Comments welcome.First the series performs simple cleanups, so that the later patches are easier to follow.
Quoted 6 lines
Then it switches drivers to use them. First, to
uart_port_tx()in 9/10 and thenuart_port_tx_limited()in 10/10.The diffstat of patches 9+10 is as follows:
26 files changed, 145 insertions(+), 740 deletions(-)which appears to be nice.
I've queued up the first 7 patches here, as they were the preparation / cleanup patches and deserved to go in no matter what.
thanks,
greg k-h