Skip to contentSkip to conversation

media: imx: imx7-media-csi: Sync frames to start of frame for MIPI

PATCH In review Stefan Riedmüller 3 participants 6 messages Oct 17, 2023 – Dec 5, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 media: imx: imx7-media-csi: Sync frames to start of frame for MIPI

The default behavior for a base address change is to do it automatically after a DMA completion. This can lead to the situation, were one corrupted frame, with less lines than configured, results in all following frames being corrupted as well, due to a missing re-synchronization to the beginning of the next frame.

Fix this by configuring the base address switch to be synced with the start of frame event.

Currently this is already implemented for the parallel interface. To have it with MIPI as well, simply configure it unconditionally.

Tested on i.MX 8MM.

---
 drivers/media/platform/nxp/imx7-media-csi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/platform/nxp/imx7-media-csi.c +3 -3
index 15049c6aab37..0c9e3f01e96d 100644
@@ -529,13 +529,13 @@ static void imx7_csi_configure(struct imx7_csi *csi,
 		stride = out_pix->width;
 	}
 
+	cr18 |= BIT_BASEADDR_SWITCH_EN | BIT_BASEADDR_SWITCH_SEL |
+		BIT_BASEADDR_CHG_ERR_EN;
+
 	if (!csi->is_csi2) {
 		cr1 = BIT_SOF_POL | BIT_REDGE | BIT_GCLK_MODE | BIT_HSYNC_POL
 		    | BIT_FCC | BIT_MCLKDIV(1) | BIT_MCLKEN;
 
-		cr18 |= BIT_BASEADDR_SWITCH_EN | BIT_BASEADDR_SWITCH_SEL |
-			BIT_BASEADDR_CHG_ERR_EN;
-
 		if (out_pix->pixelformat == V4L2_PIX_FMT_UYVY ||
 		    out_pix->pixelformat == V4L2_PIX_FMT_YUYV)
 			width *= 2;
Signature · 1 line
2.25.1
reviewer
#1 lore raw

Hi Stefan,

Quoted 7 lines · Stefan Riedmüller

The default behavior for a base address change is to do it automatically after a DMA completion. This can lead to the situation, were one corrupted frame, with less lines than configured, results in all following frames being corrupted as well, due to a missing re-synchronization to the beginning of the next frame.

Quoted 7 lines

Fix this by configuring the base address switch to be synced with the start of frame event.

Currently this is already implemented for the parallel interface. To have it with MIPI as well, simply configure it unconditionally.

Tested on i.MX 8MM.

Should this contain a Fixes tag? Thanks

#2 lore raw

Hi Fabio,

Quoted 14 lines · Fabio Estevam

Hi Stefan,

Quoted 10 lines · Stefan Riedmüller

The default behavior for a base address change is to do it automatically after a DMA completion. This can lead to the situation, were one corrupted frame, with less lines than configured, results in all following frames being corrupted as well, due to a missing re-synchronization to the beginning of the next frame.

Fix this by configuring the base address switch to be synced with the start of frame event.

Quoted 6 lines
Quoted 4 lines

Currently this is already implemented for the parallel interface. To have it with MIPI as well, simply configure it unconditionally.

Tested on i.MX 8MM.

Should this contain a Fixes tag? Thanks

Now that you mention it, I guess it could. I'm just not sure which commit to select for the fixes tag. I think this issue is there since day one of the driver, but I doubt that it would apply on every version of it. The fixes tag is to trigger a stable fix, right? Or is it just meant as a note?

Do you have any suggestions?

Thanks,
Stefan

maintainer
#3 lore raw
In reply to Stefan Riedmüller

Hi Stefan,

Thank you for the patch.

Quoted 6 lines · Stefan Riedmüller

The default behavior for a base address change is to do it automatically after a DMA completion. This can lead to the situation, were one corrupted frame, with less lines than configured, results in all following frames being corrupted as well, due to a missing re-synchronization to the beginning of the next frame.

Quoted 7 lines

Fix this by configuring the base address switch to be synced with the start of frame event.

Currently this is already implemented for the parallel interface. To have it with MIPI as well, simply configure it unconditionally.

Tested on i.MX 8MM.

I recall not doing this unconditionally as it didn't work on some of the platforms I was testing, but I'm not sure of the details anymore. I'll retest on i.MX7.

Do we have any buffer overflow protection in this mode ? If the sensor happens to send more lines than expected, will extra lines be dropped, or overflow the buffer ?

Quoted 26 lines
---
 drivers/media/platform/nxp/imx7-media-csi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/platform/nxp/imx7-media-csi.c +3 -3
index 15049c6aab37..0c9e3f01e96d 100644
@@ -529,13 +529,13 @@ static void imx7_csi_configure(struct imx7_csi *csi,
 		stride = out_pix->width;
 	}
 
+	cr18 |= BIT_BASEADDR_SWITCH_EN | BIT_BASEADDR_SWITCH_SEL |
+		BIT_BASEADDR_CHG_ERR_EN;
+
 	if (!csi->is_csi2) {
 		cr1 = BIT_SOF_POL | BIT_REDGE | BIT_GCLK_MODE | BIT_HSYNC_POL
 		    | BIT_FCC | BIT_MCLKDIV(1) | BIT_MCLKEN;
 
-		cr18 |= BIT_BASEADDR_SWITCH_EN | BIT_BASEADDR_SWITCH_SEL |
-			BIT_BASEADDR_CHG_ERR_EN;
-
 		if (out_pix->pixelformat == V4L2_PIX_FMT_UYVY ||
 		    out_pix->pixelformat == V4L2_PIX_FMT_YUYV)
 			width *= 2;
Signature · 3 lines
Regards,

Laurent Pinchart
#4 lore raw

Hi Laurant,

Quoted 14 lines · Laurent Pinchart

Hi Stefan,

Thank you for the patch.

Quoted 9 lines · Stefan Riedmüller

The default behavior for a base address change is to do it automatically after a DMA completion. This can lead to the situation, were one corrupted frame, with less lines than configured, results in all following frames being corrupted as well, due to a missing re-synchronization to the beginning of the next frame.

Fix this by configuring the base address switch to be synced with the start of frame event.

Quoted 8 lines
Quoted 4 lines

Currently this is already implemented for the parallel interface. To have it with MIPI as well, simply configure it unconditionally.

Tested on i.MX 8MM.

I recall not doing this unconditionally as it didn't work on some of the platforms I was testing, but I'm not sure of the details anymore. I'll retest on i.MX7.

Thanks!

Quoted 3 lines

Do we have any buffer overflow protection in this mode ? If the sensor happens to send more lines than expected, will extra lines be dropped, or overflow the buffer ?

As far as I understand the imx8mm reference manual, I think there is a buffer overflow protection, in the form that the DMA will only write the amount of data which was configured in CSI_IMAG_PARA. If additional data arrives on the bus, without a new start of frame event, a new DMA transfer will be triggered eventually. Since there was no base address change, due to the missing start frame event, the new DMA transfer will use the same buffer as before and corrupt that data. But all subsequent frames will be ok since a new frame will trigger the start of frame event and thus a base address change.

Regards,
Stefan

Quoted 31 lines
Quoted 30 lines

---
 drivers/media/platform/nxp/imx7-media-csi.c | 6 +++---

 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/platform/nxp/imx7-media-csi.c +0 -0
index 15049c6aab37..0c9e3f01e96d 100644
@@ -529,13 +529,13 @@ static void imx7_csi_configure(struct imx7_csi *csi,
  		stride = out_pix->width;
  	}

drivers/media/platform/nxp/imx7-media-csi.c +3 -0
+	cr18 |= BIT_BASEADDR_SWITCH_EN | BIT_BASEADDR_SWITCH_SEL |
+		BIT_BASEADDR_CHG_ERR_EN;
+

  if (!csi->is_csi2) {
  cr1 = BIT_SOF_POL | BIT_REDGE | BIT_GCLK_MODE | BIT_HSYNC_POL
      | BIT_FCC | BIT_MCLKDIV(1) | BIT_MCLKEN;

drivers/media/platform/nxp/imx7-media-csi.c +0 -1
-		cr18 |= BIT_BASEADDR_SWITCH_EN | BIT_BASEADDR_SWITCH_SEL

|

drivers/media/platform/nxp/imx7-media-csi.c +0 -2
-			BIT_BASEADDR_CHG_ERR_EN;
-

  if (out_pix->pixelformat == V4L2_PIX_FMT_UYVY || out_pix->pixelformat == V4L2_PIX_FMT_YUYV) width *= 2;

#5 lore raw

Hi Laurent,

Quoted 20 lines · Stefan Riedmüller

Hi Laurant,

Quoted 17 lines · Laurent Pinchart

Hi Stefan,

Thank you for the patch.

Quoted 12 lines · Stefan Riedmüller

The default behavior for a base address change is to do it automatically after a DMA completion. This can lead to the situation, were one corrupted frame, with less lines than configured, results in all following frames being corrupted as well, due to a missing re-synchronization to the beginning of the next frame.

Fix this by configuring the base address switch to be synced with the start of frame event.

Currently this is already implemented for the parallel interface. To have it with MIPI as well, simply configure it unconditionally.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Tested on i.MX 8MM.

I recall not doing this unconditionally as it didn't work on some of the platforms I was testing, but I'm not sure of the details anymore. I'll retest on i.MX7.

Thanks!

Any update yet on the i.MX7 test?

Regards,
Stefan

Quoted 59 lines
Quoted 4 lines

Do we have any buffer overflow protection in this mode ? If the sensor happens to send more lines than expected, will extra lines be dropped, or overflow the buffer ?

As far as I understand the imx8mm reference manual, I think there is a buffer
overflow protection, in the form that the DMA will only write the amount of data which was configured in CSI_IMAG_PARA. If additional data arrives on the
bus, without a new start of frame event, a new DMA transfer will be triggered
eventually. Since there was no base address change, due to the missing start frame event, the new DMA transfer will use the same buffer as before and corrupt that data. But all subsequent frames will be ok since a new frame will
trigger the start of frame event and thus a base address change.

Regards,
Stefan  t

Quoted 27 lines
Quoted 27 lines

---
 drivers/media/platform/nxp/imx7-media-csi.c | 6 +++---

 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/media/platform/nxp/imx7-media-csi.c +0 -0
index 15049c6aab37..0c9e3f01e96d 100644
@@ -529,13 +529,13 @@ static void imx7_csi_configure(struct imx7_csi
 *csi,
  		stride = out_pix->width;
  	}

drivers/media/platform/nxp/imx7-media-csi.c +3 -0
+	cr18 |= BIT_BASEADDR_SWITCH_EN | BIT_BASEADDR_SWITCH_SEL |
+		BIT_BASEADDR_CHG_ERR_EN;
+

  if (!csi->is_csi2) {
  cr1 = BIT_SOF_POL | BIT_REDGE | BIT_GCLK_MODE | BIT_HSYNC_POL
      | BIT_FCC | BIT_MCLKDIV(1) | BIT_MCLKEN;

drivers/media/platform/nxp/imx7-media-csi.c +0 -1
-		cr18 |= BIT_BASEADDR_SWITCH_EN |

BIT_BASEADDR_SWITCH_SEL

Quoted 1 line
Quoted 6 lines
Quoted 5 lines
drivers/media/platform/nxp/imx7-media-csi.c +0 -2
-			BIT_BASEADDR_CHG_ERR_EN;
-

  if (out_pix->pixelformat == V4L2_PIX_FMT_UYVY || out_pix->pixelformat == V4L2_PIX_FMT_YUYV) width *= 2;

_______________________________________________
upstream mailing list
[email protected]
http://lists.phytec.de/cgi-bin/mailman/listinfo/upstream