All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] media: ov5640: Fix set format, v4l2_mbus_pixelcode not updated
@ 2021-11-01 19:52 Mirela Rabulea (OSS)
       [not found] ` <PAXPR10MB4734B68AC186DCDA40A97CDFFE919@PAXPR10MB4734.EURPRD10.PROD.OUTLOOK.COM>
  2021-12-14 18:36 ` Jacopo Mondi
  0 siblings, 2 replies; 4+ messages in thread
From: Mirela Rabulea (OSS) @ 2021-11-01 19:52 UTC (permalink / raw)
  To: slongerbeam, mchehab, hugues.fruchet, jacopo+renesas
  Cc: guoniu.zhou, manish.bajaj, robert.chiras, xavier.roumegue,
	linux-media, linux-kernel, linux-imx, Mirela Rabulea

From: Mirela Rabulea <mirela.rabulea@nxp.com>

In ov5640_set_fmt, pending_fmt_change will always be false, because the
sensor format is saved before comparing it with the previous format:
	fmt = &sensor->fmt;...
	*fmt = *mbus_fmt;...
	if (mbus_fmt->code != sensor->fmt.code)
		sensor->pending_fmt_change = true;
This causes the sensor to capture with the previous pixelcode.

Also, changes might happen even for V4L2_SUBDEV_FORMAT_TRY, so fix that.

Basically, revert back to the state before
commit 071154499193 ("media: ov5640: Fix set format regression")
as it was more clear, and then update format even when pixelcode does
not change, as resolution might change.

Fixes: 071154499193 ("media: ov5640: Fix set format regression")
Fixes: 6949d864776e ("media: ov5640: do not change mode if format or frame interval is unchanged")
Fixes: fb98e29ff1ea5 ("media: ov5640: fix mode change regression")

Signed-off-by: Mirela Rabulea <mirela.rabulea@nxp.com>
---
 drivers/media/i2c/ov5640.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
index ddbd71394db3..db5a19babe67 100644
--- a/drivers/media/i2c/ov5640.c
+++ b/drivers/media/i2c/ov5640.c
@@ -2293,7 +2293,6 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd,
 	struct ov5640_dev *sensor = to_ov5640_dev(sd);
 	const struct ov5640_mode_info *new_mode;
 	struct v4l2_mbus_framefmt *mbus_fmt = &format->format;
-	struct v4l2_mbus_framefmt *fmt;
 	int ret;
 
 	if (format->pad != 0)
@@ -2311,12 +2310,10 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd,
 	if (ret)
 		goto out;
 
-	if (format->which == V4L2_SUBDEV_FORMAT_TRY)
-		fmt = v4l2_subdev_get_try_format(sd, sd_state, 0);
-	else
-		fmt = &sensor->fmt;
-
-	*fmt = *mbus_fmt;
+	if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
+		*v4l2_subdev_get_try_format(sd, sd_state, 0) = *mbus_fmt;
+		goto out;
+	}
 
 	if (new_mode != sensor->current_mode) {
 		sensor->current_mode = new_mode;
@@ -2325,6 +2322,9 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd,
 	if (mbus_fmt->code != sensor->fmt.code)
 		sensor->pending_fmt_change = true;
 
+	/* update format even if code is unchanged, resolution might change */
+	sensor->fmt = *mbus_fmt;
+
 	__v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate,
 				 ov5640_calc_pixel_rate(sensor));
 out:
-- 
2.25.1


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

* Re: [PATCH] media: ov5640: Fix set format, v4l2_mbus_pixelcode not updated
       [not found] ` <PAXPR10MB4734B68AC186DCDA40A97CDFFE919@PAXPR10MB4734.EURPRD10.PROD.OUTLOOK.COM>
@ 2021-11-09 14:19   ` Hugues FRUCHET - FOSS
  2021-11-10 18:03     ` [EXT] " Mirela Rabulea
  0 siblings, 1 reply; 4+ messages in thread
From: Hugues FRUCHET - FOSS @ 2021-11-09 14:19 UTC (permalink / raw)
  To: Mirela Rabulea (OSS), mchehab, Steve Longerbeam, jacopo+renesas
  Cc: guoniu.zhou, manish.bajaj, robert.chiras, xavier.roumegue,
	linux-media, linux-kernel, linux-imx, Mirela Rabulea

Hi Mirela,

Thanks for patch, tested OK on my side:

Acked-by: Hugues Fruchet <hugues.fruchet@st.com>
Tested-by: Hugues Fruchet <hugues.fruchet@st.com>

BR,
Hugues.
> 
> 
> -----Original Message-----
> From: Mirela Rabulea (OSS) <mirela.rabulea@oss.nxp.com>
> Sent: lundi 1 novembre 2021 20:53
> To: slongerbeam@gmail.com; mchehab@kernel.org; Hugues FRUCHET <hugues.fruchet@st.com>; jacopo+renesas@jmondi.org
> Cc: guoniu.zhou@nxp.com; manish.bajaj@nxp.com; robert.chiras@nxp.com; xavier.roumegue@oss.nxp.com; linux-media@vger.kernel.org; linux-kernel@vger.kernel.org; linux-imx@nxp.com; Mirela Rabulea <mirela.rabulea@nxp.com>
> Subject: [PATCH] media: ov5640: Fix set format, v4l2_mbus_pixelcode not updated
> 
> From: Mirela Rabulea <mirela.rabulea@nxp.com>
> 
> In ov5640_set_fmt, pending_fmt_change will always be false, because the sensor format is saved before comparing it with the previous format:
> 	fmt = &sensor->fmt;...
> 	*fmt = *mbus_fmt;...
> 	if (mbus_fmt->code != sensor->fmt.code)
> 		sensor->pending_fmt_change = true;
> This causes the sensor to capture with the previous pixelcode.
> 
> Also, changes might happen even for V4L2_SUBDEV_FORMAT_TRY, so fix that.
> 
> Basically, revert back to the state before commit 071154499193 ("media: ov5640: Fix set format regression") as it was more clear, and then update format even when pixelcode does not change, as resolution might change.
> 
> Fixes: 071154499193 ("media: ov5640: Fix set format regression")
> Fixes: 6949d864776e ("media: ov5640: do not change mode if format or frame interval is unchanged")
> Fixes: fb98e29ff1ea5 ("media: ov5640: fix mode change regression")
> 
> Signed-off-by: Mirela Rabulea <mirela.rabulea@nxp.com>
> ---
>   drivers/media/i2c/ov5640.c | 14 +++++++-------
>   1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c index ddbd71394db3..db5a19babe67 100644
> --- a/drivers/media/i2c/ov5640.c
> +++ b/drivers/media/i2c/ov5640.c
> @@ -2293,7 +2293,6 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd,
>   	struct ov5640_dev *sensor = to_ov5640_dev(sd);
>   	const struct ov5640_mode_info *new_mode;
>   	struct v4l2_mbus_framefmt *mbus_fmt = &format->format;
> -	struct v4l2_mbus_framefmt *fmt;
>   	int ret;
>   
>   	if (format->pad != 0)
> @@ -2311,12 +2310,10 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd,
>   	if (ret)
>   		goto out;
>   
> -	if (format->which == V4L2_SUBDEV_FORMAT_TRY)
> -		fmt = v4l2_subdev_get_try_format(sd, sd_state, 0);
> -	else
> -		fmt = &sensor->fmt;
> -
> -	*fmt = *mbus_fmt;
> +	if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
> +		*v4l2_subdev_get_try_format(sd, sd_state, 0) = *mbus_fmt;
> +		goto out;
> +	}
>   
>   	if (new_mode != sensor->current_mode) {
>   		sensor->current_mode = new_mode;
> @@ -2325,6 +2322,9 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd,
>   	if (mbus_fmt->code != sensor->fmt.code)
>   		sensor->pending_fmt_change = true;
>   
> +	/* update format even if code is unchanged, resolution might change */
> +	sensor->fmt = *mbus_fmt;
> +
>   	__v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate,
>   				 ov5640_calc_pixel_rate(sensor));
>   out:
> --
> 2.25.1
> 

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

* Re: [EXT] Re: [PATCH] media: ov5640: Fix set format, v4l2_mbus_pixelcode not updated
  2021-11-09 14:19   ` Hugues FRUCHET - FOSS
@ 2021-11-10 18:03     ` Mirela Rabulea
  0 siblings, 0 replies; 4+ messages in thread
From: Mirela Rabulea @ 2021-11-10 18:03 UTC (permalink / raw)
  To: mchehab, slongerbeam, hugues.fruchet, jacopo+renesas
  Cc: Xavier Roumegue (OSS),
	linux-media, G.N. Zhou, Manish Bajaj, Robert Chiras,
	dl-linux-imx, linux-kernel

Hi Hugues,

On Tue, 2021-11-09 at 15:19 +0100, Hugues FRUCHET - FOSS wrote:
> 
> Hi Mirela,
> 
> Thanks for patch, tested OK on my side:

Thanks, for testing!

Regards,
Mirela

> 
> Acked-by: Hugues Fruchet <hugues.fruchet@st.com>
> Tested-by: Hugues Fruchet <hugues.fruchet@st.com>
> 
> BR,
> Hugues.
> > 
> > -----Original Message-----
> > From: Mirela Rabulea (OSS) <mirela.rabulea@oss.nxp.com>
> > Sent: lundi 1 novembre 2021 20:53
> > To: slongerbeam@gmail.com; mchehab@kernel.org; Hugues FRUCHET <
> > hugues.fruchet@st.com>; jacopo+renesas@jmondi.org
> > Cc: guoniu.zhou@nxp.com; manish.bajaj@nxp.com; 
> > robert.chiras@nxp.com; xavier.roumegue@oss.nxp.com; 
> > linux-media@vger.kernel.org; linux-kernel@vger.kernel.org; 
> > linux-imx@nxp.com; Mirela Rabulea <mirela.rabulea@nxp.com>
> > Subject: [PATCH] media: ov5640: Fix set format, v4l2_mbus_pixelcode
> > not updated
> > 
> > From: Mirela Rabulea <mirela.rabulea@nxp.com>
> > 
> > In ov5640_set_fmt, pending_fmt_change will always be false, because
> > the sensor format is saved before comparing it with the previous
> > format:
> >       fmt = &sensor->fmt;...
> >       *fmt = *mbus_fmt;...
> >       if (mbus_fmt->code != sensor->fmt.code)
> >               sensor->pending_fmt_change = true;
> > This causes the sensor to capture with the previous pixelcode.
> > 
> > Also, changes might happen even for V4L2_SUBDEV_FORMAT_TRY, so fix
> > that.
> > 
> > Basically, revert back to the state before commit 071154499193
> > ("media: ov5640: Fix set format regression") as it was more clear,
> > and then update format even when pixelcode does not change, as
> > resolution might change.
> > 
> > Fixes: 071154499193 ("media: ov5640: Fix set format regression")
> > Fixes: 6949d864776e ("media: ov5640: do not change mode if format
> > or frame interval is unchanged")
> > Fixes: fb98e29ff1ea5 ("media: ov5640: fix mode change regression")
> > 
> > Signed-off-by: Mirela Rabulea <mirela.rabulea@nxp.com>
> > ---
> >   drivers/media/i2c/ov5640.c | 14 +++++++-------
> >   1 file changed, 7 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/media/i2c/ov5640.c
> > b/drivers/media/i2c/ov5640.c index ddbd71394db3..db5a19babe67
> > 100644
> > --- a/drivers/media/i2c/ov5640.c
> > +++ b/drivers/media/i2c/ov5640.c
> > @@ -2293,7 +2293,6 @@ static int ov5640_set_fmt(struct v4l2_subdev
> > *sd,
> >       struct ov5640_dev *sensor = to_ov5640_dev(sd);
> >       const struct ov5640_mode_info *new_mode;
> >       struct v4l2_mbus_framefmt *mbus_fmt = &format->format;
> > -     struct v4l2_mbus_framefmt *fmt;
> >       int ret;
> > 
> >       if (format->pad != 0)
> > @@ -2311,12 +2310,10 @@ static int ov5640_set_fmt(struct
> > v4l2_subdev *sd,
> >       if (ret)
> >               goto out;
> > 
> > -     if (format->which == V4L2_SUBDEV_FORMAT_TRY)
> > -             fmt = v4l2_subdev_get_try_format(sd, sd_state, 0);
> > -     else
> > -             fmt = &sensor->fmt;
> > -
> > -     *fmt = *mbus_fmt;
> > +     if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
> > +             *v4l2_subdev_get_try_format(sd, sd_state, 0) =
> > *mbus_fmt;
> > +             goto out;
> > +     }
> > 
> >       if (new_mode != sensor->current_mode) {
> >               sensor->current_mode = new_mode;
> > @@ -2325,6 +2322,9 @@ static int ov5640_set_fmt(struct v4l2_subdev
> > *sd,
> >       if (mbus_fmt->code != sensor->fmt.code)
> >               sensor->pending_fmt_change = true;
> > 
> > +     /* update format even if code is unchanged, resolution might
> > change */
> > +     sensor->fmt = *mbus_fmt;
> > +
> >       __v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate,
> >                                ov5640_calc_pixel_rate(sensor));
> >   out:
> > --
> > 2.25.1
> > 

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

* Re: [PATCH] media: ov5640: Fix set format, v4l2_mbus_pixelcode not updated
  2021-11-01 19:52 [PATCH] media: ov5640: Fix set format, v4l2_mbus_pixelcode not updated Mirela Rabulea (OSS)
       [not found] ` <PAXPR10MB4734B68AC186DCDA40A97CDFFE919@PAXPR10MB4734.EURPRD10.PROD.OUTLOOK.COM>
@ 2021-12-14 18:36 ` Jacopo Mondi
  1 sibling, 0 replies; 4+ messages in thread
From: Jacopo Mondi @ 2021-12-14 18:36 UTC (permalink / raw)
  To: Mirela Rabulea (OSS)
  Cc: slongerbeam, mchehab, hugues.fruchet, jacopo+renesas,
	guoniu.zhou, manish.bajaj, robert.chiras, xavier.roumegue,
	linux-media, linux-kernel, linux-imx, Mirela Rabulea

Hi Mirela,

On Mon, Nov 01, 2021 at 09:52:51PM +0200, Mirela Rabulea (OSS) wrote:
> From: Mirela Rabulea <mirela.rabulea@nxp.com>
>
> In ov5640_set_fmt, pending_fmt_change will always be false, because the
> sensor format is saved before comparing it with the previous format:
> 	fmt = &sensor->fmt;...
> 	*fmt = *mbus_fmt;...
> 	if (mbus_fmt->code != sensor->fmt.code)
> 		sensor->pending_fmt_change = true;
> This causes the sensor to capture with the previous pixelcode.
>
> Also, changes might happen even for V4L2_SUBDEV_FORMAT_TRY, so fix that.
>
> Basically, revert back to the state before
> commit 071154499193 ("media: ov5640: Fix set format regression")
> as it was more clear, and then update format even when pixelcode does
> not change, as resolution might change.
>
> Fixes: 071154499193 ("media: ov5640: Fix set format regression")
> Fixes: 6949d864776e ("media: ov5640: do not change mode if format or frame interval is unchanged")
> Fixes: fb98e29ff1ea5 ("media: ov5640: fix mode change regression")

Wow, we really piled bug over bug. So sorry about this and thanks for
fixing

Reviewed-by: Jacopo Mondi <jacopo+renesas@jmondi.org>

Thanks
   j
>
> Signed-off-by: Mirela Rabulea <mirela.rabulea@nxp.com>
> ---
>  drivers/media/i2c/ov5640.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c
> index ddbd71394db3..db5a19babe67 100644
> --- a/drivers/media/i2c/ov5640.c
> +++ b/drivers/media/i2c/ov5640.c
> @@ -2293,7 +2293,6 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd,
>  	struct ov5640_dev *sensor = to_ov5640_dev(sd);
>  	const struct ov5640_mode_info *new_mode;
>  	struct v4l2_mbus_framefmt *mbus_fmt = &format->format;
> -	struct v4l2_mbus_framefmt *fmt;
>  	int ret;
>
>  	if (format->pad != 0)
> @@ -2311,12 +2310,10 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd,
>  	if (ret)
>  		goto out;
>
> -	if (format->which == V4L2_SUBDEV_FORMAT_TRY)
> -		fmt = v4l2_subdev_get_try_format(sd, sd_state, 0);
> -	else
> -		fmt = &sensor->fmt;
> -
> -	*fmt = *mbus_fmt;
> +	if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
> +		*v4l2_subdev_get_try_format(sd, sd_state, 0) = *mbus_fmt;
> +		goto out;
> +	}
>
>  	if (new_mode != sensor->current_mode) {
>  		sensor->current_mode = new_mode;
> @@ -2325,6 +2322,9 @@ static int ov5640_set_fmt(struct v4l2_subdev *sd,
>  	if (mbus_fmt->code != sensor->fmt.code)
>  		sensor->pending_fmt_change = true;
>
> +	/* update format even if code is unchanged, resolution might change */
> +	sensor->fmt = *mbus_fmt;
> +
>  	__v4l2_ctrl_s_ctrl_int64(sensor->ctrls.pixel_rate,
>  				 ov5640_calc_pixel_rate(sensor));
>  out:
> --
> 2.25.1
>

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

end of thread, other threads:[~2021-12-14 18:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-01 19:52 [PATCH] media: ov5640: Fix set format, v4l2_mbus_pixelcode not updated Mirela Rabulea (OSS)
     [not found] ` <PAXPR10MB4734B68AC186DCDA40A97CDFFE919@PAXPR10MB4734.EURPRD10.PROD.OUTLOOK.COM>
2021-11-09 14:19   ` Hugues FRUCHET - FOSS
2021-11-10 18:03     ` [EXT] " Mirela Rabulea
2021-12-14 18:36 ` Jacopo Mondi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.