mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tarang Raval <tarang.raval@siliconsignals.io>
To: sakari.ailus@linux.intel.com, kieran.bingham@ideasonboard.com
Cc: Shravan.Chippa@microchip.com,
	Tarang Raval <tarang.raval@siliconsignals.io>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hverkuil@xs4all.nl>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Zhi Mao <zhi.mao@mediatek.com>,
	Julien Massot <julien.massot@collabora.com>,
	Kory Maincent <kory.maincent@bootlin.com>,
	Luis Garcia <git@luigi311.com>,
	Umang Jain <umang.jain@ideasonboard.com>,
	Benjamin Mugnier <benjamin.mugnier@foss.st.com>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 5/9] media: i2c: imx334: Fix power management and control handling
Date: Sat, 29 Mar 2025 11:13:27 +0530	[thread overview]
Message-ID: <20250329054335.19931-6-tarang.raval@siliconsignals.io> (raw)
In-Reply-To: <20250329054335.19931-1-tarang.raval@siliconsignals.io>

Some controls may need the sensor to be powered on to update their
values. Currently, only the exposure control does this. To ensure
proper handling, the power-up sequence is moved outside the switch-case.

Additionally, VBLANK control is now processed earlier so its changes
can correctly affect other controls.

Signed-off-by: Tarang Raval <tarang.raval@siliconsignals.io>
---
 drivers/media/i2c/imx334.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/drivers/media/i2c/imx334.c b/drivers/media/i2c/imx334.c
index f7be303af024..56d5576ccf94 100644
--- a/drivers/media/i2c/imx334.c
+++ b/drivers/media/i2c/imx334.c
@@ -578,8 +578,7 @@ static int imx334_set_ctrl(struct v4l2_ctrl *ctrl)
 	u32 exposure;
 	int ret;
 
-	switch (ctrl->id) {
-	case V4L2_CID_VBLANK:
+	if (ctrl->id == V4L2_CID_VBLANK) {
 		imx334->vblank = imx334->vblank_ctrl->val;
 
 		dev_dbg(imx334->dev, "Received vblank %u, new lpfr %u\n",
@@ -592,13 +591,24 @@ static int imx334_set_ctrl(struct v4l2_ctrl *ctrl)
 					       imx334->cur_mode->height -
 					       IMX334_EXPOSURE_OFFSET,
 					       1, IMX334_EXPOSURE_DEFAULT);
+		if (ret)
+			return ret;
+	}
+
+	/* Set controls only if sensor is in power on state */
+	if (!pm_runtime_get_if_in_use(imx334->dev))
+		return 0;
+
+	switch (ctrl->id) {
+	case V4L2_CID_VBLANK:
+		exposure = imx334->exp_ctrl->val;
+		analog_gain = imx334->again_ctrl->val;
+
+		ret = imx334_update_exp_gain(imx334, exposure, analog_gain);
+
 		break;
 	case V4L2_CID_EXPOSURE:
 
-		/* Set controls only if sensor is in power on state */
-		if (!pm_runtime_get_if_in_use(imx334->dev))
-			return 0;
-
 		exposure = ctrl->val;
 		analog_gain = imx334->again_ctrl->val;
 
@@ -607,8 +617,6 @@ static int imx334_set_ctrl(struct v4l2_ctrl *ctrl)
 
 		ret = imx334_update_exp_gain(imx334, exposure, analog_gain);
 
-		pm_runtime_put(imx334->dev);
-
 		break;
 	case V4L2_CID_PIXEL_RATE:
 	case V4L2_CID_LINK_FREQ:
@@ -640,6 +648,8 @@ static int imx334_set_ctrl(struct v4l2_ctrl *ctrl)
 		ret = -EINVAL;
 	}
 
+	pm_runtime_put(imx334->dev);
+
 	return ret;
 }
 
-- 
2.34.1


  parent reply	other threads:[~2025-03-29  5:45 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-29  5:43 [PATCH v2 0/9] media: i2c: imx334: Miscellaneous cleanups and improvements Tarang Raval
2025-03-29  5:43 ` [PATCH v2 1/9] media: i2c: imx334: Simplify with dev_err_probe() Tarang Raval
2025-03-29  5:43 ` [PATCH v2 2/9] media: i2c: imx334: Convert to CCI register access helpers Tarang Raval
2025-03-29  5:43 ` [PATCH v2 3/9] media: i2c: imx334: Remove redundant register entries Tarang Raval
2025-03-29  5:43 ` [PATCH v2 4/9] media: i2c: imx334: Configure lane mode Dynamically Tarang Raval
2025-03-29  5:43 ` Tarang Raval [this message]
2025-03-29  5:43 ` [PATCH v2 6/9] media: i2c: imx334: Fix runtime PM handling in remove function Tarang Raval
2025-03-29  5:43 ` [PATCH v2 7/9] media: i2c: imx334: Enable runtime PM before sub-device registration Tarang Raval
2025-03-29  5:43 ` [PATCH v2 8/9] media: i2c: imx334: Use subdev state lock for synchronization Tarang Raval
2025-03-29  5:43 ` [PATCH v2 9/9] media: i2c: imx334: switch to {enable,disable}_streams Tarang Raval
2025-04-15  9:23 ` [PATCH v2 0/9] media: i2c: imx334: Miscellaneous cleanups and improvements Tarang Raval
2025-04-25  5:54   ` sakari.ailus

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=20250329054335.19931-6-tarang.raval@siliconsignals.io \
    --to=tarang.raval@siliconsignals.io \
    --cc=Shravan.Chippa@microchip.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=benjamin.mugnier@foss.st.com \
    --cc=git@luigi311.com \
    --cc=hverkuil@xs4all.nl \
    --cc=julien.massot@collabora.com \
    --cc=kieran.bingham@ideasonboard.com \
    --cc=kory.maincent@bootlin.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=umang.jain@ideasonboard.com \
    --cc=zhi.mao@mediatek.com \
    /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

all inboxes | Powered by JetHome®