Skip to contentSkip to conversation

serial: qcom_geni: prevent spurious UART input from stopping autoboot

PATCH In review Balaji Selvanathan 3 participants 10 messages Jul 7 – Oct 28

lore
Share & tools
lore
#0 lore raw

v2 cover serial: qcom_geni: prevent spurious UART input from stopping autoboot

This series fixes an issue on the QCS615 EVK where U-Boot incorrectly stops at the CLI prompt instead of continuing the boot process when the UART cable is disconnected.

Electrical noise on floating RX lines can be interpreted as valid UART data. Without proper runtime validation of received data, U-Boot treats this noise as legitimate keypresses, causing it to halt at the prompt rather than continue the boot sequence. This series updates the initialization sequence to properly drain FIFO contents and adds runtime checks to distinguish valid UART data from noise.

---
Changes in v2:
- Add initialization sequence for RX init based on Kernel driver.
- Link to v1: https://lore.kernel.org/u-boot/[email protected]/

To: Sumit Garg <[email protected]>
To: [email protected]
To: [email protected]

Cc Casey Connolly <[email protected]>
Cc Neil Armstrong <[email protected]>
Cc Tom Rini <[email protected]>
Cc Andrew Goodbody <[email protected]>
Cc Stephen Boyd <[email protected]>

---
Balaji Selvanathan (2):
serial: msm_geni: fix RX FIFO init with proper cancel sequence
serial: msm_geni: validate RX FIFO data with IRQ status flags

 drivers/serial/serial_msm_geni.c | 91 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 82 insertions(+), 9 deletions(-)

---
base-commit: ece349ade2973e220f524ce59e59711cc919263f
change-id: 20260707-uart-af9daffadb54

Best regards,

Signature · 1 line
Balaji Selvanathan <[email protected]>
#1 lore raw

PATCH v2 1/2 serial: msm_geni: fix RX FIFO init with proper cancel sequence

Replace the abort-only RX initialization with a proper stop sequence that matches the Linux driver approach. The new qcom_geni_serial_stop_rx_fifo function sends a CANCEL command instead of immediately aborting, waits for completion, drains any remaining FIFO data if S_RX_FIFO_LAST_EN is set, and only sends ABORT as a fallback if the secondary sequencer remains active after cancellation.

Taken from 679aac5ead2f ("tty: serial: qcom_geni_serial: Fix RX cancel command failure")

---
Changes in v2:
- Replace the abort-only RX initialization with a proper stop sequence that matches the Linux driver approach.

---
 drivers/serial/serial_msm_geni.c | 63 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 61 insertions(+), 2 deletions(-)
drivers/serial/serial_msm_geni.c +61 -2
index 3dca581f68f..a580dee8c8a 100644
@@ -362,11 +362,70 @@ static void qcom_geni_serial_abort_rx(struct udevice *dev)
 	writel(FORCE_DEFAULT, priv->base + GENI_FORCE_DEFAULT_REG);
 }
 
+static void qcom_geni_serial_stop_rx_fifo(struct udevice *dev)
+{
+	struct msm_serial_data *priv = dev_get_priv(dev);
+	u32 irq_en;
+	u32 s_irq_status;
+	u32 status;
+	u32 rx_fifo_status;
+
+	/* Disable RX interrupts */
+	irq_en = readl(priv->base + SE_GENI_S_IRQ_EN);
+	irq_en &= ~(S_RX_FIFO_WATERMARK_EN | S_RX_FIFO_LAST_EN);
+	writel(irq_en, priv->base + SE_GENI_S_IRQ_EN);
+
+	irq_en = readl(priv->base + SE_GENI_M_IRQ_EN);
+	irq_en &= ~(M_RX_FIFO_WATERMARK_EN | M_RX_FIFO_LAST_EN);
+	writel(irq_en, priv->base + SE_GENI_M_IRQ_EN);
+
+	/* Check if secondary sequencer is active */
+	status = readl(priv->base + SE_GENI_STATUS);
+	if (!(status & S_GENI_CMD_ACTIVE))
+		return;
+
+	/* Send CANCEL command */
+	writel(S_GENI_CMD_CANCEL, priv->base + SE_GENI_S_CMD_CTRL_REG);
+
+	/* Poll for CANCEL completion */
+	qcom_geni_serial_poll_bit(dev, SE_GENI_S_CMD_CTRL_REG,
+				  S_GENI_CMD_CANCEL, false);
+
+	/* Read IRQ status and check if S_RX_FIFO_LAST_EN is set */
+	s_irq_status = readl(priv->base + SE_GENI_S_IRQ_STATUS);
+
+	/* Flush/drain the RX FIFO if needed */
+	if (s_irq_status & S_RX_FIFO_LAST_EN) {
+		while ((rx_fifo_status = readl(priv->base + SE_GENI_RX_FIFO_STATUS)) &
+		       RX_FIFO_WC_MSK) {
+			readl(priv->base + SE_GENI_RX_FIFOn);
+		}
+	}
+
+	/* Clear all pending IRQ status bits */
+	writel(s_irq_status, priv->base + SE_GENI_S_IRQ_CLEAR);
+
+	/* Check if still active after CANCEL */
+	status = readl(priv->base + SE_GENI_STATUS);
+	if (status & S_GENI_CMD_ACTIVE) {
+		/* Send ABORT as fallback */
+		writel(S_GENI_CMD_ABORT, priv->base + SE_GENI_S_CMD_CTRL_REG);
+		qcom_geni_serial_poll_bit(dev, SE_GENI_S_CMD_CTRL_REG,
+					  S_GENI_CMD_ABORT, false);
+
+		/* Clear ABORT IRQ status */
+		s_irq_status = readl(priv->base + SE_GENI_S_IRQ_STATUS);
+		writel(s_irq_status, priv->base + SE_GENI_S_IRQ_CLEAR);
+	}
+
+	writel(FORCE_DEFAULT, priv->base + GENI_FORCE_DEFAULT_REG);
+}
+
 static void msm_geni_serial_setup_rx(struct udevice *dev)
 {
 	struct msm_serial_data *priv = dev_get_priv(dev);
 
-	qcom_geni_serial_abort_rx(dev);
+	qcom_geni_serial_stop_rx_fifo(dev);
 
 	writel(UART_PACKING_CFG0, priv->base + SE_GENI_RX_PACKING_CFG0);
 	writel(UART_PACKING_CFG1, priv->base + SE_GENI_RX_PACKING_CFG1);
@@ -494,7 +553,7 @@ static inline void geni_serial_init(struct udevice *dev)
 	 * it else we could end up in data loss scenarios.
 	 */
 	qcom_geni_serial_poll_tx_done(dev);
-	qcom_geni_serial_abort_rx(dev);
+	qcom_geni_serial_stop_rx_fifo(dev);
 
 	writel(UART_PACKING_CFG0, base_address + SE_GENI_TX_PACKING_CFG0);
 	writel(UART_PACKING_CFG1, base_address + SE_GENI_TX_PACKING_CFG1);
Signature · 1 line
2.34.1
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] serial: msm_geni: fix RX FIFO init with proper cancel sequence

Quoted 10 lines · Balaji Selvanathan

Replace the abort-only RX initialization with a proper stop sequence that matches the Linux driver approach. The new qcom_geni_serial_stop_rx_fifo function sends a CANCEL command instead of immediately aborting, waits for completion, drains any remaining FIFO data if S_RX_FIFO_LAST_EN is set, and only sends ABORT as a fallback if the secondary sequencer remains active after cancellation.

Taken from 679aac5ead2f ("tty: serial: qcom_geni_serial: Fix RX cancel command failure")

#3 lore raw

PATCH v2 2/2 serial: msm_geni: validate RX FIFO data with IRQ status flags

In reply to Balaji Selvanathan

Add IRQ status validation to distinguish legitimate UART data from electrical noise in the RX FIFO.

When the UART cable is disconnected, the floating RX line can pick up noise that the GENI hardware interprets as valid data and places in the FIFO. So, check the RX IRQ status register for RX watermark or last flags before reporting pending data.

---
Changes in v2:
- No changes

---
 drivers/serial/serial_msm_geni.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
drivers/serial/serial_msm_geni.c +21 -7
index a580dee8c8a..07d38178759 100644
@@ -483,15 +483,29 @@ static int msm_serial_getc(struct udevice *dev)
 static int msm_serial_pending(struct udevice *dev, bool input)
 {
 	struct msm_serial_data *priv = dev_get_priv(dev);
+	u32 fifo_status;
+	u32 s_irq_status;
+	int word_count;
 
-	if (input)
-		return readl(priv->base + SE_GENI_RX_FIFO_STATUS) &
-			   RX_FIFO_WC_MSK;
-	else
-		return readl(priv->base + SE_GENI_TX_FIFO_STATUS) &
-			   TX_FIFO_WC_MSK;
+	if (input) {
+		fifo_status = readl(priv->base + SE_GENI_RX_FIFO_STATUS);
+		word_count = fifo_status & RX_FIFO_WC_MSK;
 
-	return 0;
+		if (word_count > 0) {
+			/* Validate RX FIFO data with IRQ status */
+			s_irq_status = readl(priv->base + SE_GENI_S_IRQ_STATUS);
+
+			if (!(s_irq_status & (S_RX_FIFO_WATERMARK_EN | S_RX_FIFO_LAST_EN)))
+				return 0;
+		}
+
+		return word_count;
+	} else {
+		fifo_status = readl(priv->base + SE_GENI_TX_FIFO_STATUS);
+		word_count = fifo_status & TX_FIFO_WC_MSK;
+
+		return word_count;
+	}
 }
 
 static const struct dm_serial_ops msm_serial_ops = {
Signature · 1 line
2.34.1
Reviewed-by on v2 2/2
#4 lore raw

Re: [PATCH v2 2/2] serial: msm_geni: validate RX FIFO data with IRQ status flags

Quoted 9 lines · Balaji Selvanathan

Add IRQ status validation to distinguish legitimate UART data from electrical noise in the RX FIFO.

When the UART cable is disconnected, the floating RX line can pick up noise that the GENI hardware interprets as valid data and places in the FIFO. So, check the RX IRQ status register for RX watermark or last flags before reporting pending data.

#5 lore raw

Re: [PATCH v2 2/2] serial: msm_geni: validate RX FIFO data with IRQ status flags

In reply to Balaji Selvanathan

Hi Balaji,

Quoted 7 lines · Balaji Selvanathan

Add IRQ status validation to distinguish legitimate UART data from electrical noise in the RX FIFO.

When the UART cable is disconnected, the floating RX line can pick up noise that the GENI hardware interprets as valid data and places in the FIFO. So, check the RX IRQ status register for RX watermark or last flags before reporting pending data.

Thanks for respinning this series. Is this patch still necessary with the first one? Since we should no longer be in this state with noise in the FIFO after resetting it correctly iiuc?

Thanks,
// Casey

Quoted 51 lines

---
Changes in v2:
- No changes

---
  drivers/serial/serial_msm_geni.c | 28 +++++++++++++++++++++-------
  1 file changed, 21 insertions(+), 7 deletions(-)
drivers/serial/serial_msm_geni.c +21 -7
index a580dee8c8a..07d38178759 100644
@@ -483,15 +483,29 @@ static int msm_serial_getc(struct udevice *dev)
  static int msm_serial_pending(struct udevice *dev, bool input)
  {
  	struct msm_serial_data *priv = dev_get_priv(dev);
+	u32 fifo_status;
+	u32 s_irq_status;
+	int word_count;
 
-	if (input)
-		return readl(priv->base + SE_GENI_RX_FIFO_STATUS) &
-			   RX_FIFO_WC_MSK;
-	else
-		return readl(priv->base + SE_GENI_TX_FIFO_STATUS) &
-			   TX_FIFO_WC_MSK;
+	if (input) {
+		fifo_status = readl(priv->base + SE_GENI_RX_FIFO_STATUS);
+		word_count = fifo_status & RX_FIFO_WC_MSK;
 
-	return 0;
+		if (word_count > 0) {
+			/* Validate RX FIFO data with IRQ status */
+			s_irq_status = readl(priv->base + SE_GENI_S_IRQ_STATUS);
+
+			if (!(s_irq_status & (S_RX_FIFO_WATERMARK_EN | S_RX_FIFO_LAST_EN)))
+				return 0;
+		}
+
+		return word_count;
+	} else {
+		fifo_status = readl(priv->base + SE_GENI_TX_FIFO_STATUS);
+		word_count = fifo_status & TX_FIFO_WC_MSK;
+
+		return word_count;
+	}
  }
 
  static const struct dm_serial_ops msm_serial_ops = {
#6 lore raw

Re: [PATCH v2 2/2] serial: msm_geni: validate RX FIFO data with IRQ status flags

Hi Casey,

Quoted 6 lines · Casey Connolly

Hi Balaji,

Quoted 3 lines · Balaji Selvanathan

Add IRQ status validation to distinguish legitimate UART data from electrical noise in the RX FIFO.

Quoted 6 lines
Quoted 4 lines

When the UART cable is disconnected, the floating RX line can pick up noise that the GENI hardware interprets as valid data and places in the FIFO. So, check the RX IRQ status register for RX watermark or last flags before reporting pending data.

Thanks for respinning this series. Is this patch still necessary with the first one? Since we should no longer be in this state with noise in the FIFO after resetting it correctly iiuc?

Even after fixing init sequence, still it stops at U-Boot CLI when the UART cable is disconnected on QCS615-EVK, so seems SE_GENI_S_IRQ_STATUS register has to be checked to make sure data is valid.

Thanks,

Balaji

Quoted 54 lines

Thanks,
// Casey

Quoted 49 lines

---
Changes in v2:
- No changes
---
  drivers/serial/serial_msm_geni.c | 28 +++++++++++++++++++++-------

  1 file changed, 21 insertions(+), 7 deletions(-)
drivers/serial/serial_msm_geni.c +21 -5
index a580dee8c8a..07d38178759 100644
@@ -483,15 +483,29 @@ static int msm_serial_getc(struct udevice *dev)
   static int msm_serial_pending(struct udevice *dev, bool input)
   {
       struct msm_serial_data *priv = dev_get_priv(dev);
+    u32 fifo_status;
+    u32 s_irq_status;
+    int word_count;
   -    if (input)
-        return readl(priv->base + SE_GENI_RX_FIFO_STATUS) &
-               RX_FIFO_WC_MSK;
-    else
-        return readl(priv->base + SE_GENI_TX_FIFO_STATUS) &
-               TX_FIFO_WC_MSK;
+    if (input) {
+        fifo_status = readl(priv->base + SE_GENI_RX_FIFO_STATUS);
+        word_count = fifo_status & RX_FIFO_WC_MSK;
   -    return 0;
+        if (word_count > 0) {
+            /* Validate RX FIFO data with IRQ status */
+            s_irq_status = readl(priv->base + SE_GENI_S_IRQ_STATUS);
+
+            if (!(s_irq_status & (S_RX_FIFO_WATERMARK_EN | 
 S_RX_FIFO_LAST_EN)))
+                return 0;
+        }
+
+        return word_count;
+    } else {
+        fifo_status = readl(priv->base + SE_GENI_TX_FIFO_STATUS);
+        word_count = fifo_status & TX_FIFO_WC_MSK;
+
+        return word_count;
+    }
   }
     static const struct dm_serial_ops msm_serial_ops = {
#7 lore raw

Re: [PATCH v2 2/2] serial: msm_geni: validate RX FIFO data with IRQ status flags

Quoted 9 lines · Balaji Selvanathan

Hi Casey,

Quoted 6 lines · Casey Connolly

Hi Balaji,

Quoted 3 lines · Balaji Selvanathan

Add IRQ status validation to distinguish legitimate UART data from electrical noise in the RX FIFO.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

When the UART cable is disconnected, the floating RX line can pick up noise that the GENI hardware interprets as valid data and places in the FIFO. So, check the RX IRQ status register for RX watermark or last flags before reporting pending data.

Thanks for respinning this series. Is this patch still necessary with the first one? Since we should no longer be in this state with noise in the FIFO after resetting it correctly iiuc?

Even after fixing init sequence, still it stops at U-Boot CLI when the UART cable is disconnected on QCS615-EVK, so seems SE_GENI_S_IRQ_STATUS register has to be checked to make sure data is valid.

If that's the case then I suspect we're missing something in the init sequence, since it should drain the fifo... Why would you send me patch 1 if it doesn't even work???

Quoted 59 lines

Thanks,

Balaji

Quoted 54 lines

Thanks,
// Casey

Quoted 49 lines

---
Changes in v2:
- No changes
---
  drivers/serial/serial_msm_geni.c | 28 +++++++++++++++++++++-------

  1 file changed, 21 insertions(+), 7 deletions(-)
drivers/serial/serial_msm_geni.c +21 -5
index a580dee8c8a..07d38178759 100644
@@ -483,15 +483,29 @@ static int msm_serial_getc(struct udevice *dev)
   static int msm_serial_pending(struct udevice *dev, bool input)
   {
       struct msm_serial_data *priv = dev_get_priv(dev);
+    u32 fifo_status;
+    u32 s_irq_status;
+    int word_count;
   -    if (input)
-        return readl(priv->base + SE_GENI_RX_FIFO_STATUS) &
-               RX_FIFO_WC_MSK;
-    else
-        return readl(priv->base + SE_GENI_TX_FIFO_STATUS) &
-               TX_FIFO_WC_MSK;
+    if (input) {
+        fifo_status = readl(priv->base + SE_GENI_RX_FIFO_STATUS);
+        word_count = fifo_status & RX_FIFO_WC_MSK;
   -    return 0;
+        if (word_count > 0) {
+            /* Validate RX FIFO data with IRQ status */
+            s_irq_status = readl(priv->base + SE_GENI_S_IRQ_STATUS);
+
+            if (!(s_irq_status & (S_RX_FIFO_WATERMARK_EN | 
 S_RX_FIFO_LAST_EN)))
+                return 0;
+        }
+
+        return word_count;
+    } else {
+        fifo_status = readl(priv->base + SE_GENI_TX_FIFO_STATUS);
+        word_count = fifo_status & TX_FIFO_WC_MSK;
+
+        return word_count;
+    }
   }
     static const struct dm_serial_ops msm_serial_ops = {
#8 lore raw

Re: [PATCH v2 2/2] serial: msm_geni: validate RX FIFO data with IRQ status flags

Quoted 17 lines · Casey Connolly
Quoted 14 lines · Balaji Selvanathan

Hi Casey,

Quoted 11 lines · Casey Connolly

Hi Balaji,

Quoted 7 lines · Balaji Selvanathan

Add IRQ status validation to distinguish legitimate UART data from electrical noise in the RX FIFO.

When the UART cable is disconnected, the floating RX line can pick up noise that the GENI hardware interprets as valid data and places in the FIFO. So, check the RX IRQ status register for RX watermark or last flags before reporting pending data.

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Thanks for respinning this series. Is this patch still necessary with the first one? Since we should no longer be in this state with noise in the FIFO after resetting it correctly iiuc?

Even after fixing init sequence, still it stops at U-Boot CLI when the UART cable is disconnected on QCS615-EVK, so seems SE_GENI_S_IRQ_STATUS register has to be checked to make sure data is valid.

If that's the case then I suspect we're missing something in the init sequence, since it should drain the fifo... Why would you send me patch 1 if it doesn't even work???

Unless the issue is that we continue picking up noise after init? It would be good if you could confirm that (e.g. make sure the fifo drain logic actually happens during setup and that we get bogus data afterwards)

Perhaps this is actually a pinctrl issue on your board if the floating rx pin is causes noise? Shouldn't it be pulled (up I think?).

Thanks>

Quoted 61 lines
Quoted 60 lines

Thanks,

Balaji

Quoted 54 lines

Thanks,
// Casey

Quoted 49 lines

---
Changes in v2:
- No changes
---
  drivers/serial/serial_msm_geni.c | 28 +++++++++++++++++++++-------

  1 file changed, 21 insertions(+), 7 deletions(-)
drivers/serial/serial_msm_geni.c +21 -5
index a580dee8c8a..07d38178759 100644
@@ -483,15 +483,29 @@ static int msm_serial_getc(struct udevice *dev)
   static int msm_serial_pending(struct udevice *dev, bool input)
   {
       struct msm_serial_data *priv = dev_get_priv(dev);
+    u32 fifo_status;
+    u32 s_irq_status;
+    int word_count;
   -    if (input)
-        return readl(priv->base + SE_GENI_RX_FIFO_STATUS) &
-               RX_FIFO_WC_MSK;
-    else
-        return readl(priv->base + SE_GENI_TX_FIFO_STATUS) &
-               TX_FIFO_WC_MSK;
+    if (input) {
+        fifo_status = readl(priv->base + SE_GENI_RX_FIFO_STATUS);
+        word_count = fifo_status & RX_FIFO_WC_MSK;
   -    return 0;
+        if (word_count > 0) {
+            /* Validate RX FIFO data with IRQ status */
+            s_irq_status = readl(priv->base + SE_GENI_S_IRQ_STATUS);
+
+            if (!(s_irq_status & (S_RX_FIFO_WATERMARK_EN | 
 S_RX_FIFO_LAST_EN)))
+                return 0;
+        }
+
+        return word_count;
+    } else {
+        fifo_status = readl(priv->base + SE_GENI_TX_FIFO_STATUS);
+        word_count = fifo_status & TX_FIFO_WC_MSK;
+
+        return word_count;
+    }
   }
     static const struct dm_serial_ops msm_serial_ops = {
#9 lore raw

Re: [PATCH v2 2/2] serial: msm_geni: validate RX FIFO data with IRQ status flags

In reply to Balaji Selvanathan

Hi Balaji,

Quoted 7 lines · Balaji Selvanathan

Add IRQ status validation to distinguish legitimate UART data from electrical noise in the RX FIFO.

When the UART cable is disconnected, the floating RX line can pick up noise that the GENI hardware interprets as valid data and places in the FIFO. So, check the RX IRQ status register for RX watermark or last flags before reporting pending data.

Went to test this on Lanai and it seems to be broken on sm8650, TX works but RX never reads. Picking up the other patch.

Please check this and rebase it, you can also drop the fifo_status intermediate variable.

Thanks,

Quoted 51 lines

---
Changes in v2:
- No changes

---
 drivers/serial/serial_msm_geni.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)
drivers/serial/serial_msm_geni.c +21 -7
index a580dee8c8a..07d38178759 100644
@@ -483,15 +483,29 @@ static int msm_serial_getc(struct udevice *dev)
 static int msm_serial_pending(struct udevice *dev, bool input)
 {
 	struct msm_serial_data *priv = dev_get_priv(dev);
+	u32 fifo_status;
+	u32 s_irq_status;
+	int word_count;
 
-	if (input)
-		return readl(priv->base + SE_GENI_RX_FIFO_STATUS) &
-			   RX_FIFO_WC_MSK;
-	else
-		return readl(priv->base + SE_GENI_TX_FIFO_STATUS) &
-			   TX_FIFO_WC_MSK;
+	if (input) {
+		fifo_status = readl(priv->base + SE_GENI_RX_FIFO_STATUS);
+		word_count = fifo_status & RX_FIFO_WC_MSK;
 
-	return 0;
+		if (word_count > 0) {
+			/* Validate RX FIFO data with IRQ status */
+			s_irq_status = readl(priv->base + SE_GENI_S_IRQ_STATUS);
+
+			if (!(s_irq_status & (S_RX_FIFO_WATERMARK_EN | S_RX_FIFO_LAST_EN)))
+				return 0;
+		}
+
+		return word_count;
+	} else {
+		fifo_status = readl(priv->base + SE_GENI_TX_FIFO_STATUS);
+		word_count = fifo_status & TX_FIFO_WC_MSK;
+
+		return word_count;
+	}
 }
 
 static const struct dm_serial_ops msm_serial_ops = {
Signature · 1 line
// Casey (she/her)