From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: linux-media@vger.kernel.org
Cc: Sakari Ailus <sakari.ailus@iki.fi>,
Michael Riesch <michael.riesch@wolfvision.net>
Subject: Re: [PATCH] media: i2c: imx415: Replace streaming flag with runtime PM check
Date: Mon, 18 Sep 2023 15:10:07 +0300 [thread overview]
Message-ID: <20230918121007.GA9789@pendragon.ideasonboard.com> (raw)
In-Reply-To: <20230914174600.850-1-laurent.pinchart@ideasonboard.com>
On Thu, Sep 14, 2023 at 08:46:00PM +0300, Laurent Pinchart wrote:
> The streaming flag in the driver private structure is used for the sole
> purpose of gating register writes when setting a V4L2 control. This is
> better handled by checking if the sensor is powered up using the runtime
> PM API. Do so and drop the streaming flag.
>
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> ---
> drivers/media/i2c/imx415.c | 32 +++++++++++++++-----------------
> 1 file changed, 15 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/media/i2c/imx415.c b/drivers/media/i2c/imx415.c
> index 3f00172df3cc..346f623c1331 100644
> --- a/drivers/media/i2c/imx415.c
> +++ b/drivers/media/i2c/imx415.c
> @@ -353,8 +353,6 @@ struct imx415 {
>
> const struct imx415_clk_params *clk_params;
>
> - bool streaming;
> -
> struct v4l2_subdev subdev;
> struct media_pad pad;
>
> @@ -542,8 +540,9 @@ static int imx415_s_ctrl(struct v4l2_ctrl *ctrl)
> struct v4l2_subdev_state *state;
> unsigned int vmax;
> unsigned int flip;
> + int ret;
>
> - if (!sensor->streaming)
> + if (!pm_runtime_get_if_in_use(sensor->dev))
> return 0;
>
> state = v4l2_subdev_get_locked_active_state(&sensor->subdev);
> @@ -554,24 +553,33 @@ static int imx415_s_ctrl(struct v4l2_ctrl *ctrl)
> /* clamp the exposure value to VMAX. */
> vmax = format->height + sensor->vblank->cur.val;
> ctrl->val = min_t(int, ctrl->val, vmax);
> - return imx415_write(sensor, IMX415_SHR0, vmax - ctrl->val);
> + ret = imx415_write(sensor, IMX415_SHR0, vmax - ctrl->val);
> + break;
>
> case V4L2_CID_ANALOGUE_GAIN:
> /* analogue gain in 0.3 dB step size */
> return imx415_write(sensor, IMX415_GAIN_PCG_0, ctrl->val);
This should be
ret = imx415_write(sensor, IMX415_GAIN_PCG_0, ctrl->val);
Sakari, would you like a v2, or would you prefer fixing this locally ?
> + break;
>
> case V4L2_CID_HFLIP:
> case V4L2_CID_VFLIP:
> flip = (sensor->hflip->val << IMX415_HREVERSE_SHIFT) |
> (sensor->vflip->val << IMX415_VREVERSE_SHIFT);
> - return imx415_write(sensor, IMX415_REVERSE, flip);
> + ret = imx415_write(sensor, IMX415_REVERSE, flip);
> + break;
>
> case V4L2_CID_TEST_PATTERN:
> - return imx415_set_testpattern(sensor, ctrl->val);
> + ret = imx415_set_testpattern(sensor, ctrl->val);
> + break;
>
> default:
> - return -EINVAL;
> + ret = -EINVAL;
> + break;
> }
> +
> + pm_runtime_put(sensor->dev);
> +
> + return ret;
> }
>
> static const struct v4l2_ctrl_ops imx415_ctrl_ops = {
> @@ -766,8 +774,6 @@ static int imx415_s_stream(struct v4l2_subdev *sd, int enable)
> pm_runtime_mark_last_busy(sensor->dev);
> pm_runtime_put_autosuspend(sensor->dev);
>
> - sensor->streaming = false;
> -
> goto unlock;
> }
>
> @@ -779,13 +785,6 @@ static int imx415_s_stream(struct v4l2_subdev *sd, int enable)
> if (ret)
> goto err_pm;
>
> - /*
> - * Set streaming to true to ensure __v4l2_ctrl_handler_setup() will set
> - * the controls. The flag is reset to false further down if an error
> - * occurs.
> - */
> - sensor->streaming = true;
> -
> ret = __v4l2_ctrl_handler_setup(&sensor->ctrls);
> if (ret < 0)
> goto err_pm;
> @@ -807,7 +806,6 @@ static int imx415_s_stream(struct v4l2_subdev *sd, int enable)
> * likely has no other chance to recover.
> */
> pm_runtime_put_sync(sensor->dev);
> - sensor->streaming = false;
>
> goto unlock;
> }
>
> base-commit: 0bb80ecc33a8fb5a682236443c1e740d5c917d1d
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2023-09-18 12:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-14 17:46 [PATCH] media: i2c: imx415: Replace streaming flag with runtime PM check Laurent Pinchart
2023-09-18 12:10 ` Laurent Pinchart [this message]
2023-09-18 12:19 ` Sakari Ailus
2023-10-02 11:37 ` Michael Riesch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230918121007.GA9789@pendragon.ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=michael.riesch@wolfvision.net \
--cc=sakari.ailus@iki.fi \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox