Skip to contentSkip to conversation

rcar-csi2: Propagate the FLD signal for NTSC and PAL

PATCH Superseded Niklas Söderlund 3 participants 5 messages Mar 8, 2019 – Mar 12, 2019

Subsystems (2)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 rcar-csi2: Propagate the FLD signal for NTSC and PAL

Depending on which video standard is used the driver needs to setup the hardware to correctly handle fields. If stream is identified as NTSC or PAL setup field detection and propagate the field detection signal.

Later versions of the datasheet have been updated to make it clear that FLD register should be set to 0 when dealing with non-interlaced field formats.

---
 drivers/media/platform/rcar-vin/rcar-csi2.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

---

Hi,

This patch depends on [PATCH v2 0/2] rcar-csi2: Use standby mode instead of resetting

drivers/media/platform/rcar-vin/rcar-csi2.c +12 -3
index 7a1c9b549e0fffc6..d9b29dbbcc2949de 100644
@@ -475,7 +475,7 @@ static int rcsi2_calc_mbps(struct rcar_csi2 *priv, unsigned int bpp)
 static int rcsi2_start_receiver(struct rcar_csi2 *priv)
 {
 	const struct rcar_csi2_format *format;
-	u32 phycnt, vcdt = 0, vcdt2 = 0;
+	u32 phycnt, vcdt = 0, vcdt2 = 0, fld = 0;
 	unsigned int i;
 	int mbps, ret;
 
@@ -507,6 +507,16 @@ static int rcsi2_start_receiver(struct rcar_csi2 *priv)
 			vcdt2 |= vcdt_part << ((i % 2) * 16);
 	}
 
+	if (priv->mf.field != V4L2_FIELD_NONE &&
+	    (priv->mf.height == 240 || priv->mf.height == 288)) {
+		fld =  FLD_FLD_EN4 | FLD_FLD_EN3 | FLD_FLD_EN2 | FLD_FLD_EN;
+
+		if (priv->mf.height == 240)
+			fld |= FLD_FLD_NUM(2);
+		else
+			fld |= FLD_FLD_NUM(1);
+	}
+
 	phycnt = PHYCNT_ENABLECLK;
 	phycnt |= (1 << priv->lanes) - 1;
 
@@ -519,8 +529,7 @@ static int rcsi2_start_receiver(struct rcar_csi2 *priv)
 	rcsi2_write(priv, PHTC_REG, 0);
 
 	/* Configure */
-	rcsi2_write(priv, FLD_REG, FLD_FLD_NUM(2) | FLD_FLD_EN4 |
-		    FLD_FLD_EN3 | FLD_FLD_EN2 | FLD_FLD_EN);
+	rcsi2_write(priv, FLD_REG, fld);
 	rcsi2_write(priv, VCDT_REG, vcdt);
 	if (vcdt2)
 		rcsi2_write(priv, VCDT2_REG, vcdt2);
Signature · 1 line
2.21.0
#1 lore raw

Hi Niklas,

Thank you for the patch.

Quoted 34 lines · Niklas Söderlund

Depending on which video standard is used the driver needs to setup the hardware to correctly handle fields. If stream is identified as NTSC or PAL setup field detection and propagate the field detection signal.

Later versions of the datasheet have been updated to make it clear that FLD register should be set to 0 when dealing with non-interlaced field formats.

---
 drivers/media/platform/rcar-vin/rcar-csi2.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

---

Hi,

This patch depends on [PATCH v2 0/2] rcar-csi2: Use standby mode instead of resetting

drivers/media/platform/rcar-vin/rcar-csi2.c +1 -1
index 7a1c9b549e0fffc6..d9b29dbbcc2949de 100644
@@ -475,7 +475,7 @@ static int rcsi2_calc_mbps(struct rcar_csi2 *priv, unsigned int bpp)
 static int rcsi2_start_receiver(struct rcar_csi2 *priv)
 {
 	const struct rcar_csi2_format *format;
-	u32 phycnt, vcdt = 0, vcdt2 = 0;
+	u32 phycnt, vcdt = 0, vcdt2 = 0, fld = 0;
 	unsigned int i;
 	int mbps, ret;
 

drivers/media/platform/rcar-vin/rcar-csi2.c static int rcsi2_start_receiver(struct rcar_csi2 *priv) · line 510

Quoted 4 lines
drivers/media/platform/rcar-vin/rcar-csi2.c +1 -0
@@ -507,6 +507,16 @@ static int rcsi2_start_receiver(struct rcar_csi2 *priv)
 			vcdt2 |= vcdt_part << ((i % 2) * 16);
 	}
 
+	if (priv->mf.field != V4L2_FIELD_NONE &&

Shouldn't this be

	if (priv->mf.field == V4L2_FIELD_ALTERNATE) {

If the CSI-2 receiver gets a top/bottom-only or sequential field order I would expect it not to toggle the field signal.

drivers/media/platform/rcar-vin/rcar-csi2.c static int rcsi2_start_receiver(struct rcar_csi2 *priv) · line 511

Quoted 1 line
drivers/media/platform/rcar-vin/rcar-csi2.c +1 -0
+	    (priv->mf.height == 240 || priv->mf.height == 288)) {

I think you can drop this part of the check.

drivers/media/platform/rcar-vin/rcar-csi2.c static int rcsi2_start_receiver(struct rcar_csi2 *priv) · line 517

Quoted 6 lines
drivers/media/platform/rcar-vin/rcar-csi2.c +6 -0
+		fld =  FLD_FLD_EN4 | FLD_FLD_EN3 | FLD_FLD_EN2 | FLD_FLD_EN;
+
+		if (priv->mf.height == 240)
+			fld |= FLD_FLD_NUM(2);
+		else
+			fld |= FLD_FLD_NUM(1);

How does this work ? Looking at the datasheet, I was expecting FLD_DET_SEL field to be set to 01 in order for the field signal to toggle every frame.

Quoted 15 lines
drivers/media/platform/rcar-vin/rcar-csi2.c +3 -2
+	}
+
 	phycnt = PHYCNT_ENABLECLK;
 	phycnt |= (1 << priv->lanes) - 1;
 
@@ -519,8 +529,7 @@ static int rcsi2_start_receiver(struct rcar_csi2 *priv)
 	rcsi2_write(priv, PHTC_REG, 0);
 
 	/* Configure */
-	rcsi2_write(priv, FLD_REG, FLD_FLD_NUM(2) | FLD_FLD_EN4 |
-		    FLD_FLD_EN3 | FLD_FLD_EN2 | FLD_FLD_EN);
+	rcsi2_write(priv, FLD_REG, fld);
 	rcsi2_write(priv, VCDT_REG, vcdt);
 	if (vcdt2)
 		rcsi2_write(priv, VCDT2_REG, vcdt2);
Signature · 3 lines
Regards,

Laurent Pinchart
#2 lore raw

Hi Laurent,

Thanks for your feedback.

Quoted 42 lines · Laurent Pinchart

Hi Niklas,

Thank you for the patch.

Quoted 37 lines · Niklas Söderlund

Depending on which video standard is used the driver needs to setup the hardware to correctly handle fields. If stream is identified as NTSC or PAL setup field detection and propagate the field detection signal.

Later versions of the datasheet have been updated to make it clear that FLD register should be set to 0 when dealing with non-interlaced field formats.

---
 drivers/media/platform/rcar-vin/rcar-csi2.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

---

Hi,

This patch depends on [PATCH v2 0/2] rcar-csi2: Use standby mode instead of resetting

drivers/media/platform/rcar-vin/rcar-csi2.c +1 -1
index 7a1c9b549e0fffc6..d9b29dbbcc2949de 100644
@@ -475,7 +475,7 @@ static int rcsi2_calc_mbps(struct rcar_csi2 *priv, unsigned int bpp)
 static int rcsi2_start_receiver(struct rcar_csi2 *priv)
 {
 	const struct rcar_csi2_format *format;
-	u32 phycnt, vcdt = 0, vcdt2 = 0;
+	u32 phycnt, vcdt = 0, vcdt2 = 0, fld = 0;
 	unsigned int i;
 	int mbps, ret;
 
@@ -507,6 +507,16 @@ static int rcsi2_start_receiver(struct rcar_csi2 *priv)
 			vcdt2 |= vcdt_part << ((i % 2) * 16);
 	}
 
Quoted 8 lines

drivers/media/platform/rcar-vin/rcar-csi2.c static int rcsi2_start_receiver(struct rcar_csi2 *priv) · line 510

Quoted 1 line
drivers/media/platform/rcar-vin/rcar-csi2.c +1 -0
+	if (priv->mf.field != V4L2_FIELD_NONE &&

Shouldn't this be

	if (priv->mf.field == V4L2_FIELD_ALTERNATE) {

If the CSI-2 receiver gets a top/bottom-only or sequential field order I would expect it not to toggle the field signal.

For some reason I mixed all interlaced formats in to the mix while now it's clear ALTERNATE is the only one which make sens, thanks!

Quoted 4 lines

drivers/media/platform/rcar-vin/rcar-csi2.c static int rcsi2_start_receiver(struct rcar_csi2 *priv) · line 511

Quoted 2 lines
drivers/media/platform/rcar-vin/rcar-csi2.c +1 -0
+	    (priv->mf.height == 240 || priv->mf.height == 288)) {

I think you can drop this part of the check.

I added it to guard so this special case only would trigger for PAL and NTSC resolutions. But I think I agree with you that I might be over cautious.

Quoted 11 lines

drivers/media/platform/rcar-vin/rcar-csi2.c static int rcsi2_start_receiver(struct rcar_csi2 *priv) · line 517

Quoted 7 lines
drivers/media/platform/rcar-vin/rcar-csi2.c +6 -0
+		fld =  FLD_FLD_EN4 | FLD_FLD_EN3 | FLD_FLD_EN2 | FLD_FLD_EN;
+
+		if (priv->mf.height == 240)
+			fld |= FLD_FLD_NUM(2);
+		else
+			fld |= FLD_FLD_NUM(1);

How does this work ? Looking at the datasheet, I was expecting FLD_DET_SEL field to be set to 01 in order for the field signal to toggle every frame.

I thought so too then I read 26.4.5 FLD Signal which fits what is done in the BSP code and fits with how the hardware behaves.

Quoted 21 lines
Quoted 16 lines
drivers/media/platform/rcar-vin/rcar-csi2.c +3 -2
+	}
+
 	phycnt = PHYCNT_ENABLECLK;
 	phycnt |= (1 << priv->lanes) - 1;
 
@@ -519,8 +529,7 @@ static int rcsi2_start_receiver(struct rcar_csi2 *priv)
 	rcsi2_write(priv, PHTC_REG, 0);
 
 	/* Configure */
-	rcsi2_write(priv, FLD_REG, FLD_FLD_NUM(2) | FLD_FLD_EN4 |
-		    FLD_FLD_EN3 | FLD_FLD_EN2 | FLD_FLD_EN);
+	rcsi2_write(priv, FLD_REG, fld);
 	rcsi2_write(priv, VCDT_REG, vcdt);
 	if (vcdt2)
 		rcsi2_write(priv, VCDT2_REG, vcdt2);
Signature · 3 lines
Regards,

Laurent Pinchart
Signature · 2 lines
Regards,
Niklas Söderlund
#3 lore raw

Hi Niklas,

Quoted 72 lines · Niklas Söderlund
Quoted 38 lines · Laurent Pinchart
Quoted 37 lines · Niklas Söderlund

Depending on which video standard is used the driver needs to setup the hardware to correctly handle fields. If stream is identified as NTSC or PAL setup field detection and propagate the field detection signal.

Later versions of the datasheet have been updated to make it clear that FLD register should be set to 0 when dealing with non-interlaced field formats.

---
 drivers/media/platform/rcar-vin/rcar-csi2.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

---

Hi,

This patch depends on [PATCH v2 0/2] rcar-csi2: Use standby mode instead of resetting

drivers/media/platform/rcar-vin/rcar-csi2.c +1 -1
index 7a1c9b549e0fffc6..d9b29dbbcc2949de 100644
@@ -475,7 +475,7 @@ static int rcsi2_calc_mbps(struct rcar_csi2 *priv, unsigned int bpp)
 static int rcsi2_start_receiver(struct rcar_csi2 *priv)
 {
 	const struct rcar_csi2_format *format;
-	u32 phycnt, vcdt = 0, vcdt2 = 0;
+	u32 phycnt, vcdt = 0, vcdt2 = 0, fld = 0;
 	unsigned int i;
 	int mbps, ret;
 
@@ -507,6 +507,16 @@ static int rcsi2_start_receiver(struct rcar_csi2 *priv)
 			vcdt2 |= vcdt_part << ((i % 2) * 16);
 	}
 
Quoted 8 lines

drivers/media/platform/rcar-vin/rcar-csi2.c static int rcsi2_start_receiver(struct rcar_csi2 *priv) · line 510

Quoted 1 line
drivers/media/platform/rcar-vin/rcar-csi2.c +1 -0
+	if (priv->mf.field != V4L2_FIELD_NONE &&

Shouldn't this be

	if (priv->mf.field == V4L2_FIELD_ALTERNATE) {

If the CSI-2 receiver gets a top/bottom-only or sequential field order I would expect it not to toggle the field signal.

For some reason I mixed all interlaced formats in to the mix while now it's clear ALTERNATE is the only one which make sens, thanks!

Quoted 4 lines

drivers/media/platform/rcar-vin/rcar-csi2.c static int rcsi2_start_receiver(struct rcar_csi2 *priv) · line 511

Quoted 2 lines
drivers/media/platform/rcar-vin/rcar-csi2.c +1 -0
+	    (priv->mf.height == 240 || priv->mf.height == 288)) {

I think you can drop this part of the check.

I added it to guard so this special case only would trigger for PAL and NTSC resolutions. But I think I agree with you that I might be over cautious.

Quoted 11 lines

drivers/media/platform/rcar-vin/rcar-csi2.c static int rcsi2_start_receiver(struct rcar_csi2 *priv) · line 517

Quoted 7 lines
drivers/media/platform/rcar-vin/rcar-csi2.c +6 -0
+		fld =  FLD_FLD_EN4 | FLD_FLD_EN3 | FLD_FLD_EN2 | FLD_FLD_EN;
+
+		if (priv->mf.height == 240)
+			fld |= FLD_FLD_NUM(2);
+		else
+			fld |= FLD_FLD_NUM(1);

How does this work ? Looking at the datasheet, I was expecting FLD_DET_SEL field to be set to 01 in order for the field signal to toggle every frame.

Quoted 2 lines

I thought so too then I read 26.4.5 FLD Signal which fits what is done in the BSP code and fits with how the hardware behaves.

Do we have a guarantee that all alternate sources will cycle the frame number between 1 and 2 ? If not I think you should select based on the LSB.

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
drivers/media/platform/rcar-vin/rcar-csi2.c +3 -2
+	}
+
 	phycnt = PHYCNT_ENABLECLK;
 	phycnt |= (1 << priv->lanes) - 1;
 
@@ -519,8 +529,7 @@ static int rcsi2_start_receiver(struct rcar_csi2 *priv)
 	rcsi2_write(priv, PHTC_REG, 0);
 
 	/* Configure */
-	rcsi2_write(priv, FLD_REG, FLD_FLD_NUM(2) | FLD_FLD_EN4 |
-		    FLD_FLD_EN3 | FLD_FLD_EN2 | FLD_FLD_EN);
+	rcsi2_write(priv, FLD_REG, fld);
 	rcsi2_write(priv, VCDT_REG, vcdt);
 	if (vcdt2)
 		rcsi2_write(priv, VCDT2_REG, vcdt2);
Signature · 3 lines
Regards,

Laurent Pinchart
#4 lore raw

Hi Laurent,

Quoted 12 lines · Laurent Pinchart
Quoted 12 lines
Quoted 11 lines

drivers/media/platform/rcar-vin/rcar-csi2.c static int rcsi2_start_receiver(struct rcar_csi2 *priv) · line 517

Quoted 7 lines
(quoted diff) +1 -0
+		fld =  FLD_FLD_EN4 | FLD_FLD_EN3 | FLD_FLD_EN2 | 

FLD_FLD_EN;

drivers/media/platform/rcar-vin/rcar-csi2.c +5 -0
+
+		if (priv->mf.height == 240)
+			fld |= FLD_FLD_NUM(2);
+		else
+			fld |= FLD_FLD_NUM(1);

How does this work ? Looking at the datasheet, I was expecting FLD_DET_SEL field to be set to 01 in order for the field signal to toggle every frame.

Quoted 7 lines
Quoted 2 lines

I thought so too then I read 26.4.5 FLD Signal which fits what is done in the BSP code and fits with how the hardware behaves.

Do we have a guarantee that all alternate sources will cycle the frame number between 1 and 2 ? If not I think you should select based on the LSB.

I can't imagine we have such guarantees and experimenting with FLD_DET_SEL set to 01 one works as expected. I will do so in next version. Thanks for finding this.

Signature · 2 lines
Regards,
Niklas Söderlund