mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] media: i2c: imx415: Use the new VBLANK value for SHR0
@ 2026-11-28  0:31 Petr Kracík via B4 Relay
  2026-11-30  8:26 ` Sakari Ailus
  2026-11-30  8:29 ` Michael Riesch
  0 siblings, 2 replies; 3+ messages in thread
From: Petr Kracík via B4 Relay @ 2026-11-28  0:31 UTC (permalink / raw)
  To: Michael Riesch, Sakari Ailus, Mauro Carvalho Chehab,
	Hans Verkuil, Dave Stevenson
  Cc: linux-media, linux-kernel, stable, Petr Kracík

From: Petr Kracík <petrkr@petrkr.net>

When V4L2_CID_VBLANK is set, imx415_s_ctrl() writes the new VMAX and then
falls through to the exposure case to program SHR0 = VMAX - exposure.
The exposure case computes VMAX from sensor->vblank->cur.val, which still
holds the old value at this point, because the control core updates
cur.val only after s_ctrl() has returned. SHR0 is therefore calculated
for the previous frame length. If the exposure control is not written
afterwards, SHR0 stays wrong and the actual exposure differs from the
requested one (for example when the frame rate is changed).

Take the VBLANK value from the control being set instead.

Fixes: 3bcae55ab96a ("media: i2c: imx415: Add read/write control of VBLANK")
Cc: stable@vger.kernel.org
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Petr Kracík <petrkr@petrkr.net>
---
 drivers/media/i2c/imx415.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/media/i2c/imx415.c b/drivers/media/i2c/imx415.c
index 7bb27bdf1446..282dc0c3e021 100644
--- a/drivers/media/i2c/imx415.c
+++ b/drivers/media/i2c/imx415.c
@@ -697,6 +697,7 @@ static int imx415_s_ctrl(struct v4l2_ctrl *ctrl)
 	struct v4l2_subdev_state *state;
 	u32 exposure_max;
 	unsigned int vmax;
+	unsigned int vblank;
 	unsigned int flip;
 	int ret;
 
@@ -715,10 +716,14 @@ static int imx415_s_ctrl(struct v4l2_ctrl *ctrl)
 	if (!pm_runtime_get_if_in_use(sensor->dev))
 		return 0;
 
+	vblank = sensor->vblank->cur.val;
+
 	switch (ctrl->id) {
 	case V4L2_CID_VBLANK:
+		/* cur.val is updated only after s_ctrl returns */
+		vblank = ctrl->val;
 		ret = cci_write(sensor->regmap, IMX415_VMAX,
-				format->height + ctrl->val, NULL);
+				format->height + vblank, NULL);
 		if (ret)
 			break;
 		/*
@@ -729,7 +734,7 @@ static int imx415_s_ctrl(struct v4l2_ctrl *ctrl)
 		fallthrough;
 	case V4L2_CID_EXPOSURE:
 		/* clamp the exposure value to VMAX. */
-		vmax = format->height + sensor->vblank->cur.val;
+		vmax = format->height + vblank;
 		ctrl->val = min_t(int, ctrl->val, vmax);
 		ret = cci_write(sensor->regmap, IMX415_SHR0,
 				vmax - ctrl->val, NULL);

---
base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
change-id: 20261128-imx415-vblank-fix-32d83a43da46

Best regards,
--  
Petr Kracík <petrkr@petrkr.net>



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

* Re: [PATCH] media: i2c: imx415: Use the new VBLANK value for SHR0
  2026-11-28  0:31 [PATCH] media: i2c: imx415: Use the new VBLANK value for SHR0 Petr Kracík via B4 Relay
@ 2026-11-30  8:26 ` Sakari Ailus
  2026-11-30  8:29 ` Michael Riesch
  1 sibling, 0 replies; 3+ messages in thread
From: Sakari Ailus @ 2026-11-30  8:26 UTC (permalink / raw)
  To: petrkr
  Cc: Michael Riesch, Mauro Carvalho Chehab, Hans Verkuil,
	Dave Stevenson, linux-media, linux-kernel, stable

Hi Petr,

On Sat, Nov 28, 2026 at 01:31:53AM +0100, Petr Kracík via B4 Relay wrote:
> From: Petr Kracík <petrkr@petrkr.net>
> 
> When V4L2_CID_VBLANK is set, imx415_s_ctrl() writes the new VMAX and then
> falls through to the exposure case to program SHR0 = VMAX - exposure.
> The exposure case computes VMAX from sensor->vblank->cur.val, which still
> holds the old value at this point, because the control core updates
> cur.val only after s_ctrl() has returned. SHR0 is therefore calculated
> for the previous frame length. If the exposure control is not written
> afterwards, SHR0 stays wrong and the actual exposure differs from the
> requested one (for example when the frame rate is changed).
> 
> Take the VBLANK value from the control being set instead.
> 
> Fixes: 3bcae55ab96a ("media: i2c: imx415: Add read/write control of VBLANK")
> Cc: stable@vger.kernel.org
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Petr Kracík <petrkr@petrkr.net>
> ---
>  drivers/media/i2c/imx415.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/i2c/imx415.c b/drivers/media/i2c/imx415.c
> index 7bb27bdf1446..282dc0c3e021 100644
> --- a/drivers/media/i2c/imx415.c
> +++ b/drivers/media/i2c/imx415.c
> @@ -697,6 +697,7 @@ static int imx415_s_ctrl(struct v4l2_ctrl *ctrl)
>  	struct v4l2_subdev_state *state;
>  	u32 exposure_max;
>  	unsigned int vmax;
> +	unsigned int vblank;
>  	unsigned int flip;
>  	int ret;
>  
> @@ -715,10 +716,14 @@ static int imx415_s_ctrl(struct v4l2_ctrl *ctrl)
>  	if (!pm_runtime_get_if_in_use(sensor->dev))
>  		return 0;
>  
> +	vblank = sensor->vblank->cur.val;
> +
>  	switch (ctrl->id) {
>  	case V4L2_CID_VBLANK:
> +		/* cur.val is updated only after s_ctrl returns */
> +		vblank = ctrl->val;
>  		ret = cci_write(sensor->regmap, IMX415_VMAX,
> -				format->height + ctrl->val, NULL);
> +				format->height + vblank, NULL);
>  		if (ret)
>  			break;
>  		/*
> @@ -729,7 +734,7 @@ static int imx415_s_ctrl(struct v4l2_ctrl *ctrl)
>  		fallthrough;
>  	case V4L2_CID_EXPOSURE:
>  		/* clamp the exposure value to VMAX. */
> -		vmax = format->height + sensor->vblank->cur.val;
> +		vmax = format->height + vblank;

How about sensor->vblank->val here?

>  		ctrl->val = min_t(int, ctrl->val, vmax);
>  		ret = cci_write(sensor->regmap, IMX415_SHR0,
>  				vmax - ctrl->val, NULL);
> 

-- 
Regards,

Sakari Ailus

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

* Re: [PATCH] media: i2c: imx415: Use the new VBLANK value for SHR0
  2026-11-28  0:31 [PATCH] media: i2c: imx415: Use the new VBLANK value for SHR0 Petr Kracík via B4 Relay
  2026-11-30  8:26 ` Sakari Ailus
@ 2026-11-30  8:29 ` Michael Riesch
  1 sibling, 0 replies; 3+ messages in thread
From: Michael Riesch @ 2026-11-30  8:29 UTC (permalink / raw)
  To: petrkr, Sakari Ailus, Mauro Carvalho Chehab, Hans Verkuil,
	Dave Stevenson
  Cc: linux-media, linux-kernel, stable

Hi Petr,

On 11/28/26 01:31, Petr Kracík via B4 Relay wrote:
> From: Petr Kracík <petrkr@petrkr.net>
> 
> When V4L2_CID_VBLANK is set, imx415_s_ctrl() writes the new VMAX and then
> falls through to the exposure case to program SHR0 = VMAX - exposure.
> The exposure case computes VMAX from sensor->vblank->cur.val, which still
> holds the old value at this point, because the control core updates
> cur.val only after s_ctrl() has returned. SHR0 is therefore calculated
> for the previous frame length. If the exposure control is not written
> afterwards, SHR0 stays wrong and the actual exposure differs from the
> requested one (for example when the frame rate is changed).
> 
> Take the VBLANK value from the control being set instead.

This patch:
https://lore.kernel.org/linux-media/20261018-fix-imx415-vblank-exposure-sync-20261018-v1-1-920383f39185@gmail.com/
was submitted a while ago, can you check whether this fixes your issue?

Best regards,
Michael

> 
> Fixes: 3bcae55ab96a ("media: i2c: imx415: Add read/write control of VBLANK")
> Cc: stable@vger.kernel.org
> Assisted-by: Claude:claude-opus-5-5
> Signed-off-by: Petr Kracík <petrkr@petrkr.net>
> ---
>  drivers/media/i2c/imx415.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/i2c/imx415.c b/drivers/media/i2c/imx415.c
> index 7bb27bdf1446..282dc0c3e021 100644
> --- a/drivers/media/i2c/imx415.c
> +++ b/drivers/media/i2c/imx415.c
> @@ -697,6 +697,7 @@ static int imx415_s_ctrl(struct v4l2_ctrl *ctrl)
>  	struct v4l2_subdev_state *state;
>  	u32 exposure_max;
>  	unsigned int vmax;
> +	unsigned int vblank;
>  	unsigned int flip;
>  	int ret;
>  
> @@ -715,10 +716,14 @@ static int imx415_s_ctrl(struct v4l2_ctrl *ctrl)
>  	if (!pm_runtime_get_if_in_use(sensor->dev))
>  		return 0;
>  
> +	vblank = sensor->vblank->cur.val;
> +
>  	switch (ctrl->id) {
>  	case V4L2_CID_VBLANK:
> +		/* cur.val is updated only after s_ctrl returns */
> +		vblank = ctrl->val;
>  		ret = cci_write(sensor->regmap, IMX415_VMAX,
> -				format->height + ctrl->val, NULL);
> +				format->height + vblank, NULL);
>  		if (ret)
>  			break;
>  		/*
> @@ -729,7 +734,7 @@ static int imx415_s_ctrl(struct v4l2_ctrl *ctrl)
>  		fallthrough;
>  	case V4L2_CID_EXPOSURE:
>  		/* clamp the exposure value to VMAX. */
> -		vmax = format->height + sensor->vblank->cur.val;
> +		vmax = format->height + vblank;
>  		ctrl->val = min_t(int, ctrl->val, vmax);
>  		ret = cci_write(sensor->regmap, IMX415_SHR0,
>  				vmax - ctrl->val, NULL);
> 
> ---
> base-commit: 97d73c8251226cf27cc6656b4c542869bb8c69fa
> change-id: 20261128-imx415-vblank-fix-32d83a43da46
> 
> Best regards,
> --  
> Petr Kracík <petrkr@petrkr.net>
> 
> 


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

end of thread, other threads:[~2026-11-30  8:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-28  0:31 [PATCH] media: i2c: imx415: Use the new VBLANK value for SHR0 Petr Kracík via B4 Relay
2026-11-30  8:26 ` Sakari Ailus
2026-11-30  8:29 ` Michael Riesch

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®