diff mbox series

[v2,10/18] media: i2c: imx219: Access height from active format in imx219_set_ctrl

Message ID 20230821223001.28480-11-laurent.pinchart@ideasonboard.com
State Accepted
Commit aa86ac42eec4dd7e987c12390a0a487187e2d9ae
Headers show
Series [v2,01/18] media: i2c: imx219: Convert to CCI register access helpers | expand

Commit Message

Laurent Pinchart Aug. 21, 2023, 10:29 p.m. UTC
Use the active format height instead of the mode height in
imx219_set_ctrl(). This prepares for dropping the mode field from the
imx219 structure.

The state is retrieved using v4l2_subdev_get_locked_active_state() as
the subdev active state and the control handler share the same lock.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/media/i2c/imx219.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Dave Stevenson Aug. 29, 2023, 9:56 a.m. UTC | #1
On Mon, 21 Aug 2023 at 23:30, Laurent Pinchart
<laurent.pinchart@ideasonboard.com> wrote:
>
> Use the active format height instead of the mode height in
> imx219_set_ctrl(). This prepares for dropping the mode field from the
> imx219 structure.
>
> The state is retrieved using v4l2_subdev_get_locked_active_state() as
> the subdev active state and the control handler share the same lock.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Dave Stevenson <dave.stevenson@raspberrypi.com>

> ---
>  drivers/media/i2c/imx219.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
> index 0c26cbfe58f3..4e9a50117a0a 100644
> --- a/drivers/media/i2c/imx219.c
> +++ b/drivers/media/i2c/imx219.c
> @@ -401,13 +401,18 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl)
>         struct imx219 *imx219 =
>                 container_of(ctrl->handler, struct imx219, ctrl_handler);
>         struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd);
> +       const struct v4l2_mbus_framefmt *format;
> +       struct v4l2_subdev_state *state;
>         int ret = 0;
>
> +       state = v4l2_subdev_get_locked_active_state(&imx219->sd);
> +       format = v4l2_subdev_get_pad_format(&imx219->sd, state, 0);
> +
>         if (ctrl->id == V4L2_CID_VBLANK) {
>                 int exposure_max, exposure_def;
>
>                 /* Update max exposure while meeting expected vblanking */
> -               exposure_max = imx219->mode->height + ctrl->val - 4;
> +               exposure_max = format->height + ctrl->val - 4;
>                 exposure_def = (exposure_max < IMX219_EXPOSURE_DEFAULT) ?
>                         exposure_max : IMX219_EXPOSURE_DEFAULT;
>                 __v4l2_ctrl_modify_range(imx219->exposure,
> @@ -447,7 +452,7 @@ static int imx219_set_ctrl(struct v4l2_ctrl *ctrl)
>                 break;
>         case V4L2_CID_VBLANK:
>                 cci_write(imx219->regmap, IMX219_REG_VTS,
> -                         imx219->mode->height + ctrl->val, &ret);
> +                         format->height + ctrl->val, &ret);
>                 break;
>         case V4L2_CID_TEST_PATTERN_RED:
>                 cci_write(imx219->regmap, IMX219_REG_TESTP_RED,
> --
> Regards,
>
> Laurent Pinchart
>
diff mbox series

Patch

diff --git a/drivers/media/i2c/imx219.c b/drivers/media/i2c/imx219.c
index 0c26cbfe58f3..4e9a50117a0a 100644
--- a/drivers/media/i2c/imx219.c
+++ b/drivers/media/i2c/imx219.c
@@ -401,13 +401,18 @@  static int imx219_set_ctrl(struct v4l2_ctrl *ctrl)
 	struct imx219 *imx219 =
 		container_of(ctrl->handler, struct imx219, ctrl_handler);
 	struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd);
+	const struct v4l2_mbus_framefmt *format;
+	struct v4l2_subdev_state *state;
 	int ret = 0;
 
+	state = v4l2_subdev_get_locked_active_state(&imx219->sd);
+	format = v4l2_subdev_get_pad_format(&imx219->sd, state, 0);
+
 	if (ctrl->id == V4L2_CID_VBLANK) {
 		int exposure_max, exposure_def;
 
 		/* Update max exposure while meeting expected vblanking */
-		exposure_max = imx219->mode->height + ctrl->val - 4;
+		exposure_max = format->height + ctrl->val - 4;
 		exposure_def = (exposure_max < IMX219_EXPOSURE_DEFAULT) ?
 			exposure_max : IMX219_EXPOSURE_DEFAULT;
 		__v4l2_ctrl_modify_range(imx219->exposure,
@@ -447,7 +452,7 @@  static int imx219_set_ctrl(struct v4l2_ctrl *ctrl)
 		break;
 	case V4L2_CID_VBLANK:
 		cci_write(imx219->regmap, IMX219_REG_VTS,
-			  imx219->mode->height + ctrl->val, &ret);
+			  format->height + ctrl->val, &ret);
 		break;
 	case V4L2_CID_TEST_PATTERN_RED:
 		cci_write(imx219->regmap, IMX219_REG_TESTP_RED,