All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Marshall <pm@petermarshall.ca>
To: Sakari Ailus <sakari.ailus@linux.intel.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Benjamin Mugnier <benjamin.mugnier@foss.st.com>,
	Sylvain Petinot <sylvain.petinot@foss.st.com>
Cc: linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	linux-media@vger.kernel.org, platform-driver-x86@vger.kernel.org,
	Peter Marshall <pm@petermarshall.ca>
Subject: [PATCH 08/11] media: i2c: st-vd55g1: Unify frame timing calculations
Date: Fri, 18 Sep 2026 18:17:02 -0400	[thread overview]
Message-ID: <20260918221705.323510-9-pm@petermarshall.ca> (raw)
In-Reply-To: <20260918221705.323510-1-pm@petermarshall.ca>

The calculation of frame length and maximum exposure lines is currently
duplicated both when changing to a new format and when adjusting vblank
time. Introduce a reusable function writing calculated frame time and
exposure limit to an info struct.

Signed-off-by: Peter Marshall <pm@petermarshall.ca>
---
 drivers/media/i2c/vd55g1.c | 37 ++++++++++++++++++++++++-------------
 1 file changed, 24 insertions(+), 13 deletions(-)

diff --git a/drivers/media/i2c/vd55g1.c b/drivers/media/i2c/vd55g1.c
index f54f8ba71284..1776f5ec6a7d 100644
--- a/drivers/media/i2c/vd55g1.c
+++ b/drivers/media/i2c/vd55g1.c
@@ -559,6 +559,11 @@ struct vd55g1_vblank_limits {
 	u16 max;
 };
 
+struct vd55g1_frame_timings {
+	u16 frame_length;
+	u16 expo_max;
+};
+
 struct vd55g1 {
 	struct device *dev;
 	const struct vd55g1_version *version;
@@ -722,6 +727,15 @@ static void vd55g1_get_vblank_limits(struct vd55g1 *sensor,
 	limits->max = VD55G1_VBLANK_MAX - crop->height;
 }
 
+static void vd55g1_get_frame_timings(struct vd55g1 *sensor,
+				     struct v4l2_rect *crop,
+				     struct vd55g1_frame_timings *timings)
+{
+	timings->frame_length = crop->height + sensor->vblank_ctrl->val;
+
+	timings->expo_max = timings->frame_length - VD55G1_EXPO_MAX_TERM;
+}
+
 #define vd55g1_read(sensor, reg, val, err) \
 	cci_read((sensor)->regmap, reg, val, err)
 
@@ -1304,9 +1318,8 @@ static int vd55g1_new_format_change_controls(struct vd55g1 *sensor,
 					     struct v4l2_rect *crop)
 {
 	struct vd55g1_vblank_limits vblank;
+	struct vd55g1_frame_timings timings;
 	unsigned int hblank;
-	unsigned int frame_length = 0;
-	unsigned int expo_max;
 	int ret;
 
 	/* Reset vblank and frame length to default */
@@ -1317,10 +1330,9 @@ static int vd55g1_new_format_change_controls(struct vd55g1 *sensor,
 		return ret;
 
 	/* Max exposure changes with vblank */
-	frame_length = crop->height + sensor->vblank_ctrl->val;
-	expo_max = frame_length - VD55G1_EXPO_MAX_TERM;
-	ret = __v4l2_ctrl_modify_range(sensor->expo_ctrl, 0, expo_max, 1,
-				       VD55G1_EXPO_DEF);
+	vd55g1_get_frame_timings(sensor, crop, &timings);
+	ret = __v4l2_ctrl_modify_range(sensor->expo_ctrl, 0, timings.expo_max,
+				       1, VD55G1_EXPO_DEF);
 	if (ret)
 		return ret;
 
@@ -1478,8 +1490,6 @@ static int vd55g1_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
 static int vd55g1_s_ctrl(struct v4l2_ctrl *ctrl)
 {
 	struct vd55g1 *sensor = ctrl_to_vd55g1(ctrl);
-	unsigned int frame_length = 0;
-	unsigned int expo_max;
 	struct v4l2_subdev_state *state =
 		v4l2_subdev_get_locked_active_state(&sensor->sd);
 	struct v4l2_rect *crop =
@@ -1487,6 +1497,7 @@ static int vd55g1_s_ctrl(struct v4l2_ctrl *ctrl)
 	struct v4l2_mbus_framefmt *format =
 		v4l2_subdev_state_get_format(state, 0);
 	unsigned int hblank = vd55g1_get_hblank_min(sensor, format, crop);
+	struct vd55g1_frame_timings timings;
 	bool is_auto = false;
 	int ret = 0;
 
@@ -1496,10 +1507,10 @@ static int vd55g1_s_ctrl(struct v4l2_ctrl *ctrl)
 	/* Update controls state, range, etc. whatever the state of the HW */
 	switch (ctrl->id) {
 	case V4L2_CID_VBLANK:
-		frame_length = crop->height + ctrl->val;
-		expo_max = frame_length - VD55G1_EXPO_MAX_TERM;
-		ret = __v4l2_ctrl_modify_range(sensor->expo_ctrl, 0, expo_max,
-					       1, VD55G1_EXPO_DEF);
+		vd55g1_get_frame_timings(sensor, crop, &timings);
+		ret = __v4l2_ctrl_modify_range(sensor->expo_ctrl, 0,
+					       timings.expo_max, 1,
+					       VD55G1_EXPO_DEF);
 		break;
 	case V4L2_CID_EXPOSURE_AUTO:
 		is_auto = (ctrl->val == V4L2_EXPOSURE_AUTO);
@@ -1551,7 +1562,7 @@ static int vd55g1_s_ctrl(struct v4l2_ctrl *ctrl)
 		ret = vd55g1_update_exposure_target(sensor, ctrl->val);
 		break;
 	case V4L2_CID_VBLANK:
-		ret = vd55g1_update_frame_length(sensor, frame_length);
+		ret = vd55g1_update_frame_length(sensor, timings.frame_length);
 		break;
 	case V4L2_CID_FLASH_LED_MODE:
 		ret = vd55g1_update_gpios(sensor, sensor->ext_leds_mask);
-- 
2.55.0


  parent reply	other threads:[~2026-09-18 22:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-18 22:16 [PATCH v2 00/11] media: i2c: st-vd55g1: Genericize driver and add VD55G0 support Peter Marshall
2026-09-18 22:16 ` [PATCH 01/11] dt-bindings: media: i2c: st,vd55g1: Move allOf: after required: Peter Marshall
2026-09-19  7:04   ` Krzysztof Kozlowski
2026-09-18 22:16 ` [PATCH 02/11] media: dt-bindings: i2c: vd55g1: Add vd55g0 compatible Peter Marshall
2026-09-19  7:06   ` Krzysztof Kozlowski
2026-09-18 22:16 ` [PATCH 03/11] media: ipu-bridge: Add VD55G0 to the list of supported sensors Peter Marshall
2026-09-18 22:16 ` [PATCH 04/11] platform/x86: int3472: Add VD55G0 supply GPIO mapping Peter Marshall
2026-09-18 22:16 ` [PATCH 05/11] media: i2c: st-vd55g1: Default to illuminator on GPIO 1 Peter Marshall
2026-09-18 22:17 ` [PATCH 06/11] media: i2c: st,vd55g1: Handle virtual firmware graph endpoints Peter Marshall
2026-09-18 22:17 ` [PATCH 07/11] media: i2c: st-vd55g1: Clean up module error reporting Peter Marshall
2026-09-18 22:17 ` Peter Marshall [this message]
2026-09-18 22:17 ` [PATCH 09/11] media: i2c: st-vd55g1: Abstract sensor models, revisions, and features Peter Marshall
2026-09-21  9:20 ` [PATCH v2 00/11] media: i2c: st-vd55g1: Genericize driver and add VD55G0 support Benjamin Mugnier

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=20260918221705.323510-9-pm@petermarshall.ca \
    --to=pm@petermarshall.ca \
    --cc=benjamin.mugnier@foss.st.com \
    --cc=devicetree@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    --cc=sylvain.petinot@foss.st.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 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.