Skip to content

Commit 1cb67bc

Browse files
committed
Merge tag 'tty-6.10-final' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
Pull tty / serial fixes from Greg KH: "Here are some small serial driver fixes for 6.10-final. Included in here are: - qcom-geni fixes for a much much much discussed issue and everyone now seems to be agreed that this is the proper way forward to resolve the reported lockups - imx serial driver bugfixes - 8250_omap errata fix - ma35d1 serial driver bugfix All of these have been in linux-next for over a week with no reported issues" * tag 'tty-6.10-final' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty: serial: qcom-geni: do not kill the machine on fifo underrun serial: qcom-geni: fix hard lockup on buffer flush serial: qcom-geni: fix soft lockup on sw flow control and suspend serial: imx: ensure RTS signal is not left active after shutdown tty: serial: ma35d1: Add a NULL check for of_node serial: 8250_omap: Fix Errata i2310 with RX FIFO level check serial: imx: only set receiver level if it is zero
2 parents 1293147 + 2ac3397 commit 1cb67bc

File tree

4 files changed

+104
-22
lines changed

4 files changed

+104
-22
lines changed

drivers/tty/serial/8250/8250_omap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,8 @@ static irqreturn_t omap8250_irq(int irq, void *dev_id)
672672
* https://www.ti.com/lit/pdf/sprz536
673673
*/
674674
if (priv->habit & UART_RX_TIMEOUT_QUIRK &&
675-
(iir & UART_IIR_RX_TIMEOUT) == UART_IIR_RX_TIMEOUT) {
675+
(iir & UART_IIR_RX_TIMEOUT) == UART_IIR_RX_TIMEOUT &&
676+
serial_port_in(port, UART_OMAP_RX_LVL) == 0) {
676677
unsigned char efr2, timeout_h, timeout_l;
677678

678679
efr2 = serial_in(up, UART_OMAP_EFR2);

drivers/tty/serial/imx.c

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
#define UCR4_OREN (1<<1) /* Receiver overrun interrupt enable */
121121
#define UCR4_DREN (1<<0) /* Recv data ready interrupt enable */
122122
#define UFCR_RXTL_SHF 0 /* Receiver trigger level shift */
123+
#define UFCR_RXTL_MASK 0x3F /* Receiver trigger 6 bits wide */
123124
#define UFCR_DCEDTE (1<<6) /* DCE/DTE mode select */
124125
#define UFCR_RFDIV (7<<7) /* Reference freq divider mask */
125126
#define UFCR_RFDIV_REG(x) (((x) < 7 ? 6 - (x) : 6) << 7)
@@ -1551,6 +1552,7 @@ static void imx_uart_shutdown(struct uart_port *port)
15511552
struct imx_port *sport = (struct imx_port *)port;
15521553
unsigned long flags;
15531554
u32 ucr1, ucr2, ucr4, uts;
1555+
int loops;
15541556

15551557
if (sport->dma_is_enabled) {
15561558
dmaengine_terminate_sync(sport->dma_chan_tx);
@@ -1613,6 +1615,56 @@ static void imx_uart_shutdown(struct uart_port *port)
16131615
ucr4 &= ~UCR4_TCEN;
16141616
imx_uart_writel(sport, ucr4, UCR4);
16151617

1618+
/*
1619+
* We have to ensure the tx state machine ends up in OFF. This
1620+
* is especially important for rs485 where we must not leave
1621+
* the RTS signal high, blocking the bus indefinitely.
1622+
*
1623+
* All interrupts are now disabled, so imx_uart_stop_tx() will
1624+
* no longer be called from imx_uart_transmit_buffer(). It may
1625+
* still be called via the hrtimers, and if those are in play,
1626+
* we have to honour the delays.
1627+
*/
1628+
if (sport->tx_state == WAIT_AFTER_RTS || sport->tx_state == SEND)
1629+
imx_uart_stop_tx(port);
1630+
1631+
/*
1632+
* In many cases (rs232 mode, or if tx_state was
1633+
* WAIT_AFTER_RTS, or if tx_state was SEND and there is no
1634+
* delay_rts_after_send), this will have moved directly to
1635+
* OFF. In rs485 mode, tx_state might already have been
1636+
* WAIT_AFTER_SEND and the hrtimer thus already started, or
1637+
* the above imx_uart_stop_tx() call could have started it. In
1638+
* those cases, we have to wait for the hrtimer to fire and
1639+
* complete the transition to OFF.
1640+
*/
1641+
loops = port->rs485.flags & SER_RS485_ENABLED ?
1642+
port->rs485.delay_rts_after_send : 0;
1643+
while (sport->tx_state != OFF && loops--) {
1644+
uart_port_unlock_irqrestore(&sport->port, flags);
1645+
msleep(1);
1646+
uart_port_lock_irqsave(&sport->port, &flags);
1647+
}
1648+
1649+
if (sport->tx_state != OFF) {
1650+
dev_warn(sport->port.dev, "unexpected tx_state %d\n",
1651+
sport->tx_state);
1652+
/*
1653+
* This machine may be busted, but ensure the RTS
1654+
* signal is inactive in order not to block other
1655+
* devices.
1656+
*/
1657+
if (port->rs485.flags & SER_RS485_ENABLED) {
1658+
ucr2 = imx_uart_readl(sport, UCR2);
1659+
if (port->rs485.flags & SER_RS485_RTS_AFTER_SEND)
1660+
imx_uart_rts_active(sport, &ucr2);
1661+
else
1662+
imx_uart_rts_inactive(sport, &ucr2);
1663+
imx_uart_writel(sport, ucr2, UCR2);
1664+
}
1665+
sport->tx_state = OFF;
1666+
}
1667+
16161668
uart_port_unlock_irqrestore(&sport->port, flags);
16171669

16181670
clk_disable_unprepare(sport->clk_per);
@@ -1933,7 +1985,7 @@ static int imx_uart_rs485_config(struct uart_port *port, struct ktermios *termio
19331985
struct serial_rs485 *rs485conf)
19341986
{
19351987
struct imx_port *sport = (struct imx_port *)port;
1936-
u32 ucr2;
1988+
u32 ucr2, ufcr;
19371989

19381990
if (rs485conf->flags & SER_RS485_ENABLED) {
19391991
/* Enable receiver if low-active RTS signal is requested */
@@ -1953,7 +2005,10 @@ static int imx_uart_rs485_config(struct uart_port *port, struct ktermios *termio
19532005
/* Make sure Rx is enabled in case Tx is active with Rx disabled */
19542006
if (!(rs485conf->flags & SER_RS485_ENABLED) ||
19552007
rs485conf->flags & SER_RS485_RX_DURING_TX) {
1956-
imx_uart_setup_ufcr(sport, TXTL_DEFAULT, RXTL_DEFAULT);
2008+
/* If the receiver trigger is 0, set it to a default value */
2009+
ufcr = imx_uart_readl(sport, UFCR);
2010+
if ((ufcr & UFCR_RXTL_MASK) == 0)
2011+
imx_uart_setup_ufcr(sport, TXTL_DEFAULT, RXTL_DEFAULT);
19572012
imx_uart_start_rx(port);
19582013
}
19592014

drivers/tty/serial/ma35d1_serial.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -688,12 +688,13 @@ static int ma35d1serial_probe(struct platform_device *pdev)
688688
struct uart_ma35d1_port *up;
689689
int ret = 0;
690690

691-
if (pdev->dev.of_node) {
692-
ret = of_alias_get_id(pdev->dev.of_node, "serial");
693-
if (ret < 0) {
694-
dev_err(&pdev->dev, "failed to get alias/pdev id, errno %d\n", ret);
695-
return ret;
696-
}
691+
if (!pdev->dev.of_node)
692+
return -ENODEV;
693+
694+
ret = of_alias_get_id(pdev->dev.of_node, "serial");
695+
if (ret < 0) {
696+
dev_err(&pdev->dev, "failed to get alias/pdev id, errno %d\n", ret);
697+
return ret;
697698
}
698699
up = &ma35d1serial_ports[ret];
699700
up->port.line = ret;

drivers/tty/serial/qcom_geni_serial.c

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -649,29 +649,43 @@ static void qcom_geni_serial_start_tx_dma(struct uart_port *uport)
649649

650650
static void qcom_geni_serial_start_tx_fifo(struct uart_port *uport)
651651
{
652+
unsigned char c;
652653
u32 irq_en;
653654

654-
if (qcom_geni_serial_main_active(uport) ||
655-
!qcom_geni_serial_tx_empty(uport))
656-
return;
655+
/*
656+
* Start a new transfer in case the previous command was cancelled and
657+
* left data in the FIFO which may prevent the watermark interrupt
658+
* from triggering. Note that the stale data is discarded.
659+
*/
660+
if (!qcom_geni_serial_main_active(uport) &&
661+
!qcom_geni_serial_tx_empty(uport)) {
662+
if (uart_fifo_out(uport, &c, 1) == 1) {
663+
writel(M_CMD_DONE_EN, uport->membase + SE_GENI_M_IRQ_CLEAR);
664+
qcom_geni_serial_setup_tx(uport, 1);
665+
writel(c, uport->membase + SE_GENI_TX_FIFOn);
666+
}
667+
}
657668

658669
irq_en = readl(uport->membase + SE_GENI_M_IRQ_EN);
659670
irq_en |= M_TX_FIFO_WATERMARK_EN | M_CMD_DONE_EN;
660-
661671
writel(DEF_TX_WM, uport->membase + SE_GENI_TX_WATERMARK_REG);
662672
writel(irq_en, uport->membase + SE_GENI_M_IRQ_EN);
663673
}
664674

665675
static void qcom_geni_serial_stop_tx_fifo(struct uart_port *uport)
666676
{
667677
u32 irq_en;
668-
struct qcom_geni_serial_port *port = to_dev_port(uport);
669678

670679
irq_en = readl(uport->membase + SE_GENI_M_IRQ_EN);
671680
irq_en &= ~(M_CMD_DONE_EN | M_TX_FIFO_WATERMARK_EN);
672681
writel(0, uport->membase + SE_GENI_TX_WATERMARK_REG);
673682
writel(irq_en, uport->membase + SE_GENI_M_IRQ_EN);
674-
/* Possible stop tx is called multiple times. */
683+
}
684+
685+
static void qcom_geni_serial_cancel_tx_cmd(struct uart_port *uport)
686+
{
687+
struct qcom_geni_serial_port *port = to_dev_port(uport);
688+
675689
if (!qcom_geni_serial_main_active(uport))
676690
return;
677691

@@ -684,6 +698,8 @@ static void qcom_geni_serial_stop_tx_fifo(struct uart_port *uport)
684698
writel(M_CMD_ABORT_EN, uport->membase + SE_GENI_M_IRQ_CLEAR);
685699
}
686700
writel(M_CMD_CANCEL_EN, uport->membase + SE_GENI_M_IRQ_CLEAR);
701+
702+
port->tx_remaining = 0;
687703
}
688704

689705
static void qcom_geni_serial_handle_rx_fifo(struct uart_port *uport, bool drop)
@@ -862,7 +878,7 @@ static void qcom_geni_serial_send_chunk_fifo(struct uart_port *uport,
862878
memset(buf, 0, sizeof(buf));
863879
tx_bytes = min(remaining, BYTES_PER_FIFO_WORD);
864880

865-
tx_bytes = uart_fifo_out(uport, buf, tx_bytes);
881+
uart_fifo_out(uport, buf, tx_bytes);
866882

867883
iowrite32_rep(uport->membase + SE_GENI_TX_FIFOn, buf, 1);
868884

@@ -890,13 +906,17 @@ static void qcom_geni_serial_handle_tx_fifo(struct uart_port *uport,
890906
else
891907
pending = kfifo_len(&tport->xmit_fifo);
892908

893-
/* All data has been transmitted and acknowledged as received */
894-
if (!pending && !status && done) {
909+
/* All data has been transmitted or command has been cancelled */
910+
if (!pending && done) {
895911
qcom_geni_serial_stop_tx_fifo(uport);
896912
goto out_write_wakeup;
897913
}
898914

899-
avail = port->tx_fifo_depth - (status & TX_FIFO_WC);
915+
if (active)
916+
avail = port->tx_fifo_depth - (status & TX_FIFO_WC);
917+
else
918+
avail = port->tx_fifo_depth;
919+
900920
avail *= BYTES_PER_FIFO_WORD;
901921

902922
chunk = min(avail, pending);
@@ -1069,11 +1089,15 @@ static void qcom_geni_serial_shutdown(struct uart_port *uport)
10691089
{
10701090
disable_irq(uport->irq);
10711091

1072-
if (uart_console(uport))
1073-
return;
1074-
10751092
qcom_geni_serial_stop_tx(uport);
10761093
qcom_geni_serial_stop_rx(uport);
1094+
1095+
qcom_geni_serial_cancel_tx_cmd(uport);
1096+
}
1097+
1098+
static void qcom_geni_serial_flush_buffer(struct uart_port *uport)
1099+
{
1100+
qcom_geni_serial_cancel_tx_cmd(uport);
10771101
}
10781102

10791103
static int qcom_geni_serial_port_setup(struct uart_port *uport)
@@ -1532,6 +1556,7 @@ static const struct uart_ops qcom_geni_console_pops = {
15321556
.request_port = qcom_geni_serial_request_port,
15331557
.config_port = qcom_geni_serial_config_port,
15341558
.shutdown = qcom_geni_serial_shutdown,
1559+
.flush_buffer = qcom_geni_serial_flush_buffer,
15351560
.type = qcom_geni_serial_get_type,
15361561
.set_mctrl = qcom_geni_serial_set_mctrl,
15371562
.get_mctrl = qcom_geni_serial_get_mctrl,

0 commit comments

Comments
 (0)