Skip to contentSkip to conversation

media: ti,cadence: Fixes for CSI2RX

PATCH New Jai Luthra 1 participant 3 messages Feb 23, 2024

Subsystems (3)
lore
Share & tools
lore

Jai Luthra

author
#0 lore raw

cover media: ti,cadence: Fixes for CSI2RX

This series fixes two bugs:
1. When Cadence CSI2RX is used with an external DPHY controller, fix the programming sequence to configure the DPHY controller before starting streaming on the source
2. Fix a possible race condition in TI CSI2RX Shim driver when restarting DMA after stalling due to lack of buffers

These fixes were originally posted in the multi-stream RFC series [1], but as these are unrelated and urgent, posting them separately now so they can get picked independently.

Test logs with SK-AM62A + OV5640 https://0x0.st/H5pN.txt

[1]: https://lore.kernel.org/all/[email protected]/

---
Jai Luthra (1):
media: ti: j721e-csi2rx: Fix races while restarting DMA

Pratyush Yadav (1):
media: cadence: csi2rx: configure DPHY before starting source stream

 drivers/media/platform/cadence/cdns-csi2rx.c       | 26 ++++++++++++----------
 .../media/platform/ti/j721e-csi2rx/j721e-csi2rx.c  |  5 ++---
 2 files changed, 16 insertions(+), 15 deletions(-)

---
base-commit: 33e1d31873f87d119e5120b88cd350efa68ef276
change-id: 20240223-csi_fixes-71ddf5181df8

Best regards,

Signature · 1 line
Jai Luthra <[email protected]>
author
#1 lore raw

PATCH 1/2 media: cadence: csi2rx: configure DPHY before starting source stream

From: Pratyush Yadav <[email protected]>

When the source device is operating above 1.5 Gbps per lane, it needs to send the Skew Calibration Sequence before sending any HS data. If the DPHY is initialized after the source stream is started, then it might miss the sequence and not be able to receive data properly. Move the start of source subdev to the end of the sequence to make sure everything is ready to receive data before the source starts streaming.

Fixes 3295cf1241d3 ("media: cadence: Add support for external dphy")
---
 drivers/media/platform/cadence/cdns-csi2rx.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)
drivers/media/platform/cadence/cdns-csi2rx.c +14 -12
index 2d7b0508cc9a..6f7d27a48eff 100644
@@ -239,10 +239,6 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)
 
 	writel(reg, csi2rx->base + CSI2RX_STATIC_CFG_REG);
 
-	ret = v4l2_subdev_call(csi2rx->source_subdev, video, s_stream, true);
-	if (ret)
-		goto err_disable_pclk;
-
 	/* Enable DPHY clk and data lanes. */
 	if (csi2rx->dphy) {
 		reg = CSI2RX_DPHY_CL_EN | CSI2RX_DPHY_CL_RST;
@@ -252,6 +248,13 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)
 		}
 
 		writel(reg, csi2rx->base + CSI2RX_DPHY_LANE_CTRL_REG);
+
+		ret = csi2rx_configure_ext_dphy(csi2rx);
+		if (ret) {
+			dev_err(csi2rx->dev,
+				"Failed to configure external DPHY: %d\n", ret);
+			goto err_disable_pclk;
+		}
 	}
 
 	/*
@@ -291,14 +294,9 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)
 
 	reset_control_deassert(csi2rx->sys_rst);
 
-	if (csi2rx->dphy) {
-		ret = csi2rx_configure_ext_dphy(csi2rx);
-		if (ret) {
-			dev_err(csi2rx->dev,
-				"Failed to configure external DPHY: %d\n", ret);
-			goto err_disable_sysclk;
-		}
-	}
+	ret = v4l2_subdev_call(csi2rx->source_subdev, video, s_stream, true);
+	if (ret)
+		goto err_disable_sysclk;
 
 	clk_disable_unprepare(csi2rx->p_clk);
 
@@ -312,6 +310,10 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx)
 		clk_disable_unprepare(csi2rx->pixel_clk[i - 1]);
 	}
 
+	if (csi2rx->dphy) {
+		writel(0, csi2rx->base + CSI2RX_DPHY_LANE_CTRL_REG);
+		phy_power_off(csi2rx->dphy);
+	}
 err_disable_pclk:
 	clk_disable_unprepare(csi2rx->p_clk);
 
Signature · 1 line
2.43.0
author
#2 lore raw

PATCH 2/2 media: ti: j721e-csi2rx: Fix races while restarting DMA

In reply to Jai Luthra

After the frame is submitted to DMA, it may happen that the submitted list is not updated soon enough, and the DMA callback is triggered before that.

This can lead to kernel crashes, so move everything in a single lock/unlock section to prevent such races.

Fixes b4a3d877dc92 ("media: ti: Add CSI2RX support for J721E")
---
 drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c +2 -3
index 54aba055c96b..d47570f5d35a 100644
@@ -786,15 +786,14 @@ static void ti_csi2rx_buffer_queue(struct vb2_buffer *vb)
 			dev_warn(csi->dev,
 				 "Failed to drain DMA. Next frame might be bogus\n");
 
+		spin_lock_irqsave(&dma->lock, flags);
 		ret = ti_csi2rx_start_dma(csi, buf);
 		if (ret) {
-			dev_err(csi->dev, "Failed to start DMA: %d\n", ret);
-			spin_lock_irqsave(&dma->lock, flags);
 			vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR);
 			dma->state = TI_CSI2RX_DMA_IDLE;
 			spin_unlock_irqrestore(&dma->lock, flags);
+			dev_err(csi->dev, "Failed to start DMA: %d\n", ret);
 		} else {
-			spin_lock_irqsave(&dma->lock, flags);
 			list_add_tail(&buf->list, &dma->submitted);
 			spin_unlock_irqrestore(&dma->lock, flags);
 		}
Signature · 1 line
2.43.0