Skip to contentSkip to conversation

media: imx-csi: Skip first few frames from a BT.656 source

PATCH In review Fabio Estevam 2 participants 2 messages May 17, 2021 – May 27, 2021

Subsystems (4)
lore
Share & tools
lore

Fabio Estevam

author reviewer
#0 lore raw

PATCH v3 1/1 media: imx-csi: Skip first few frames from a BT.656 source

From: Steve Longerbeam <[email protected]>

Some BT.656 sensors (e.g. ADV718x) transmit frames with unstable BT.656 sync codes after initial power on. This confuses the imx CSI,resulting in vertical and/or horizontal sync issues. Skip the first 20 frames to avoid the unstable sync codes.

[fabio: fixed checkpatch warning and increased the frame skipping to 20]

---
Changes since v2:
- Increase 'bad_frames' to 20 as 10 was not enough to avoid the problem when using an NTSC camera.

 drivers/staging/media/imx/imx-media-csi.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/staging/media/imx/imx-media-csi.c +13 -1
index e3bfd635a89a..6a94fff49bf6 100644
@@ -750,9 +750,10 @@ static int csi_setup(struct csi_priv *priv)
 
 static int csi_start(struct csi_priv *priv)
 {
-	struct v4l2_fract *output_fi;
+	struct v4l2_fract *input_fi, *output_fi;
 	int ret;
 
+	input_fi = &priv->frame_interval[CSI_SINK_PAD];
 	output_fi = &priv->frame_interval[priv->active_output_pad];
 
 	/* start upstream */
@@ -761,6 +762,17 @@ static int csi_start(struct csi_priv *priv)
 	if (ret)
 		return ret;
 
+	/* Skip first few frames from a BT.656 source */
+	if (priv->upstream_ep.bus_type == V4L2_MBUS_BT656) {
+		u32 delay_usec, bad_frames = 20;
+
+		delay_usec = DIV_ROUND_UP_ULL((u64)USEC_PER_SEC *
+			input_fi->numerator * bad_frames,
+			input_fi->denominator);
+
+		usleep_range(delay_usec, delay_usec + 1000);
+	}
+
 	if (priv->dest == IPU_CSI_DEST_IDMAC) {
 		ret = csi_idmac_start(priv);
 		if (ret)
Signature · 1 line
2.25.1
Reviewed-by on v3 1/1
#1 lore raw
Quoted 54 lines · Fabio Estevam

From: Steve Longerbeam <[email protected]>

Some BT.656 sensors (e.g. ADV718x) transmit frames with unstable BT.656 sync codes after initial power on. This confuses the imx CSI,resulting in vertical and/or horizontal sync issues. Skip the first 20 frames to avoid the unstable sync codes.

[fabio: fixed checkpatch warning and increased the frame skipping to 20]

---
Changes since v2:
- Increase 'bad_frames' to 20 as 10 was not enough to avoid the problem when using an NTSC camera.

 drivers/staging/media/imx/imx-media-csi.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)
drivers/staging/media/imx/imx-media-csi.c +13 -2
index e3bfd635a89a..6a94fff49bf6 100644
@@ -750,9 +750,10 @@ static int csi_setup(struct csi_priv *priv)
 
 static int csi_start(struct csi_priv *priv)
 {
-       struct v4l2_fract *output_fi;
+       struct v4l2_fract *input_fi, *output_fi;
        int ret;
 
+       input_fi = &priv->frame_interval[CSI_SINK_PAD];
        output_fi = &priv->frame_interval[priv->active_output_pad];
 
        /* start upstream */
@@ -761,6 +762,17 @@ static int csi_start(struct csi_priv *priv)
        if (ret)
                return ret;
 
+       /* Skip first few frames from a BT.656 source */
+       if (priv->upstream_ep.bus_type == V4L2_MBUS_BT656) {
+               u32 delay_usec, bad_frames = 20;
+
+               delay_usec = DIV_ROUND_UP_ULL((u64)USEC_PER_SEC *
+                       input_fi->numerator * bad_frames,
+                       input_fi->denominator);
+
+               usleep_range(delay_usec, delay_usec + 1000);
+       }
+
        if (priv->dest == IPU_CSI_DEST_IDMAC) {
                ret = csi_idmac_start(priv);
                if (ret)
--
Quoted 2 lines

2.25.1