mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/2] media: ti,cadence: Fixes for CSI2RX
@ 2024-02-23  8:23 Jai Luthra
  2024-02-23  8:23 ` [PATCH 1/2] media: cadence: csi2rx: configure DPHY before starting source stream Jai Luthra
  2024-02-23  8:23 ` [PATCH 2/2] media: ti: j721e-csi2rx: Fix races while restarting DMA Jai Luthra
  0 siblings, 2 replies; 3+ messages in thread
From: Jai Luthra @ 2024-02-23  8:23 UTC (permalink / raw)
  To: Maxime Ripard, Mauro Carvalho Chehab, Laurent Pinchart,
	Sakari Ailus, Jack Zhu, Hans Verkuil, Vaishnav Achath,
	Tomi Valkeinen
  Cc: linux-media, linux-kernel, Julien Massot, Changhuang Liang,
	Jai Luthra, Pratyush Yadav

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/20240222-multistream-v1-0-1837ed916eeb@ti.com/

Signed-off-by: Jai Luthra <j-luthra@ti.com>
---
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,
-- 
Jai Luthra <j-luthra@ti.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/2] media: cadence: csi2rx: configure DPHY before starting source stream
  2024-02-23  8:23 [PATCH 0/2] media: ti,cadence: Fixes for CSI2RX Jai Luthra
@ 2024-02-23  8:23 ` Jai Luthra
  2024-02-23  8:23 ` [PATCH 2/2] media: ti: j721e-csi2rx: Fix races while restarting DMA Jai Luthra
  1 sibling, 0 replies; 3+ messages in thread
From: Jai Luthra @ 2024-02-23  8:23 UTC (permalink / raw)
  To: Maxime Ripard, Mauro Carvalho Chehab, Laurent Pinchart,
	Sakari Ailus, Jack Zhu, Hans Verkuil, Vaishnav Achath,
	Tomi Valkeinen
  Cc: linux-media, linux-kernel, Julien Massot, Changhuang Liang,
	Jai Luthra, Pratyush Yadav

From: Pratyush Yadav <p.yadav@ti.com>

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.

Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
Fixes: 3295cf1241d3 ("media: cadence: Add support for external dphy")
Tested-by: Julien Massot <julien.massot@collabora.com>
Tested-by: Changhuang Liang <Changhuang.liang@starfivetech.com>
Reviewed-by: Julien Massot <julien.massot@collabora.com>
Reviewed-by: Changhuang Liang <Changhuang.liang@starfivetech.com>
Signed-off-by: Jai Luthra <j-luthra@ti.com>
---
 drivers/media/platform/cadence/cdns-csi2rx.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c
index 2d7b0508cc9a..6f7d27a48eff 100644
--- a/drivers/media/platform/cadence/cdns-csi2rx.c
+++ b/drivers/media/platform/cadence/cdns-csi2rx.c
@@ -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);
 

-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 2/2] media: ti: j721e-csi2rx: Fix races while restarting DMA
  2024-02-23  8:23 [PATCH 0/2] media: ti,cadence: Fixes for CSI2RX Jai Luthra
  2024-02-23  8:23 ` [PATCH 1/2] media: cadence: csi2rx: configure DPHY before starting source stream Jai Luthra
@ 2024-02-23  8:23 ` Jai Luthra
  1 sibling, 0 replies; 3+ messages in thread
From: Jai Luthra @ 2024-02-23  8:23 UTC (permalink / raw)
  To: Maxime Ripard, Mauro Carvalho Chehab, Laurent Pinchart,
	Sakari Ailus, Jack Zhu, Hans Verkuil, Vaishnav Achath,
	Tomi Valkeinen
  Cc: linux-media, linux-kernel, Julien Massot, Changhuang Liang, 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")
Signed-off-by: Jai Luthra <j-luthra@ti.com>
---
 drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
index 54aba055c96b..d47570f5d35a 100644
--- a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
+++ b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c
@@ -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);
 		}

-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-23  8:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-23  8:23 [PATCH 0/2] media: ti,cadence: Fixes for CSI2RX Jai Luthra
2024-02-23  8:23 ` [PATCH 1/2] media: cadence: csi2rx: configure DPHY before starting source stream Jai Luthra
2024-02-23  8:23 ` [PATCH 2/2] media: ti: j721e-csi2rx: Fix races while restarting DMA Jai Luthra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®