mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Pierre Pinon <pierre@pinon1.fr>
To: okerixx@gmail.com
Cc: hansg@kernel.org, jason.z.chen@intel.com, jimmy.su@intel.com,
	linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
	mchehab@kernel.org, pierre@pinon1.fr,
	sakari.ailus@linux.intel.com
Subject: [PATCH v2] media: i2c: ov08x40: Implement get_selection
Date: Fri,  2 Oct 2026 11:49:13 +0200	[thread overview]
Message-ID: <20261002094913.28722-1-pierre@pinon1.fr> (raw)
In-Reply-To: <178939442771.2622.14821982022354625878@gmail.com>

Report the crop of each mode, derived from the window registers in
ov08x40_global_regs and the mode lists, so that libcamera can tell the
2x2 binned modes apart from cropped ones and select them.

Signed-off-by: Pierre Pinon <pierre@pinon1.fr>
---
Hi Oleg,

Thanks a lot for the review, and for checking the rectangles on the
Yoga Slim 7x. You were right about ov08x40_global_regs, I had missed
those writes. v2 looks up the mode matching the TRY format as you
suggested.

While reworking that path I noticed a pre-existing issue on 2-lane
setups such as yours: ov08x40_open() initialises the TRY format to
supported_modes[0] (3856x2416), which is a 4-lane only mode, and probe
likewise sets cur_mode to it regardless of mipi_lanes. On a 2-lane
sensor the TRY format is therefore 3856x2416 right after open, while
the closest 2-lane mode, and so the TRY crop, is 3856x2176. I left it
out of this patch to keep it focused; I can send a separate fix that
picks the default mode according to mipi_lanes, if that sounds right
to you.

Changes in v2:
- Rebase onto media/next, which adds the client_info argument to
  .get_selection
- Reword the commit message: the X window and Y window high bytes are
  programmed in ov08x40_global_regs, not left at power-on values (Oleg)
- Return the TRY mode's crop for V4L2_SUBDEV_FORMAT_TRY (Oleg)
- Move the OV08X40_NATIVE_* defines out of the OV08X40_REG_VALUE_* group

 drivers/media/i2c/ov08x40.c | 85 +++++++++++++++++++++++++++++++++++++
 1 file changed, 85 insertions(+)

diff --git a/drivers/media/i2c/ov08x40.c b/drivers/media/i2c/ov08x40.c
index 6de0c17e6..d202e3d5a 100644
--- a/drivers/media/i2c/ov08x40.c
+++ b/drivers/media/i2c/ov08x40.c
@@ -38,6 +38,14 @@
 #define OV08X40_REG_CHIP_ID		0x300a
 #define OV08X40_CHIP_ID			0x560858
 
+/*
+ * Full readable pixel array, as programmed by the X window (0x3800-0x3801,
+ * 0x3804-0x3805) and Y window high byte (0x3802, 0x3806) registers in
+ * ov08x40_global_regs.
+ */
+#define OV08X40_NATIVE_WIDTH		3872U
+#define OV08X40_NATIVE_HEIGHT		2432U
+
 /* V_TIMING internal */
 #define OV08X40_REG_VTS			0x380e
 #define OV08X40_VTS_30FPS		0x09c4	/* the VTS need to be half in normal mode */
@@ -151,6 +159,9 @@ struct ov08x40_mode {
 	/* Exposure calculation */
 	u16 exposure_margin;
 	u16 exposure_shift;
+
+	/* Analogue crop rectangle, in native pixel array coordinates */
+	struct v4l2_rect crop;
 };
 
 static const struct ov08x40_reg ov08x40_global_regs[] = {
@@ -1232,6 +1243,12 @@ static const struct ov08x40_mode supported_modes[] = {
 			.num_of_regs = ARRAY_SIZE(mode_3856x2416_regs),
 			.regs = mode_3856x2416_regs,
 		},
+		.crop = {
+			.left = 0,
+			.top = 0,
+			.width = 3872,
+			.height = 2432,
+		},
 		.link_freq_index = OV08X40_LINK_FREQ_400MHZ_INDEX,
 		.exposure_shift = 1,
 		.exposure_margin = OV08X40_EXPOSURE_MAX_MARGIN,
@@ -1247,6 +1264,12 @@ static const struct ov08x40_mode supported_modes[] = {
 			.num_of_regs = ARRAY_SIZE(mode_3856x2176_regs_800mbps),
 			.regs = mode_3856x2176_regs_800mbps,
 		},
+		.crop = {
+			.left = 0,
+			.top = 112,
+			.width = 3872,
+			.height = 2208,
+		},
 		.link_freq_index = OV08X40_LINK_FREQ_400MHZ_INDEX,
 		.exposure_shift = 1,
 		.exposure_margin = OV08X40_EXPOSURE_MAX_MARGIN,
@@ -1263,6 +1286,12 @@ static const struct ov08x40_mode supported_modes[] = {
 			.num_of_regs = ARRAY_SIZE(mode_1928x1208_regs),
 			.regs = mode_1928x1208_regs,
 		},
+		.crop = {
+			.left = 0,
+			.top = 0,
+			.width = 3872,
+			.height = 2432,
+		},
 		.link_freq_index = OV08X40_LINK_FREQ_400MHZ_INDEX,
 		.exposure_shift = 0,
 		.exposure_margin = OV08X40_EXPOSURE_BIN_MAX_MARGIN,
@@ -1278,6 +1307,12 @@ static const struct ov08x40_mode supported_modes[] = {
 			.num_of_regs = ARRAY_SIZE(mode_3856x2176_regs_1500mbps),
 			.regs = mode_3856x2176_regs_1500mbps,
 		},
+		.crop = {
+			.left = 0,
+			.top = 112,
+			.width = 3872,
+			.height = 2208,
+		},
 		.link_freq_index = OV08X40_LINK_FREQ_749MHZ_INDEX,
 		.exposure_shift = 1,
 		.exposure_margin = OV08X40_EXPOSURE_MAX_MARGIN,
@@ -1293,6 +1328,12 @@ static const struct ov08x40_mode supported_modes[] = {
 			.num_of_regs = ARRAY_SIZE(mode_1928x1088_regs_1500mbps),
 			.regs = mode_1928x1088_regs_1500mbps,
 		},
+		.crop = {
+			.left = 0,
+			.top = 120,
+			.width = 3872,
+			.height = 2192,
+		},
 		.link_freq_index = OV08X40_LINK_FREQ_749MHZ_INDEX,
 		.exposure_shift = 0,
 		.exposure_margin = OV08X40_EXPOSURE_MAX_MARGIN,
@@ -2056,10 +2097,54 @@ static const struct v4l2_subdev_video_ops ov08x40_video_ops = {
 	.s_stream = ov08x40_set_stream,
 };
 
+static int ov08x40_get_selection(struct v4l2_subdev *sd,
+				 const struct v4l2_subdev_client_info *ci,
+				 struct v4l2_subdev_state *sd_state,
+				 struct v4l2_subdev_selection *sel)
+{
+	struct ov08x40 *ov08x = to_ov08x40(sd);
+	const struct v4l2_mbus_framefmt *framefmt;
+	const struct ov08x40_mode *mode;
+
+	switch (sel->target) {
+	case V4L2_SEL_TGT_CROP:
+		mutex_lock(&ov08x->mutex);
+		if (sel->which == V4L2_SUBDEV_FORMAT_TRY) {
+			framefmt = v4l2_subdev_state_get_format(sd_state,
+								sel->pad);
+			mode = v4l2_find_nearest_size_conditional(supported_modes,
+								  ARRAY_SIZE(supported_modes),
+								  width, height,
+								  framefmt->width,
+								  framefmt->height,
+								  filter_by_mipi_lanes,
+								  ov08x);
+		} else {
+			mode = ov08x->cur_mode;
+		}
+		sel->r = mode->crop;
+		mutex_unlock(&ov08x->mutex);
+		return 0;
+	case V4L2_SEL_TGT_NATIVE_SIZE:
+	case V4L2_SEL_TGT_CROP_BOUNDS:
+		sel->r.left = 0;
+		sel->r.top = 0;
+		sel->r.width = OV08X40_NATIVE_WIDTH;
+		sel->r.height = OV08X40_NATIVE_HEIGHT;
+		return 0;
+	case V4L2_SEL_TGT_CROP_DEFAULT:
+		sel->r = supported_modes[0].crop;
+		return 0;
+	}
+
+	return -EINVAL;
+}
+
 static const struct v4l2_subdev_pad_ops ov08x40_pad_ops = {
 	.enum_mbus_code = ov08x40_enum_mbus_code,
 	.get_fmt = ov08x40_get_pad_format,
 	.set_fmt = ov08x40_set_pad_format,
+	.get_selection = ov08x40_get_selection,
 	.enum_frame_size = ov08x40_enum_frame_size,
 };
 
-- 
2.55.0


  reply	other threads:[~2026-10-02  9:49 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-04 13:45 [PATCH 1/2] media: i2c: ov08x40: Implement the selection API Pierre Pinon
2026-09-14 14:00 ` Oleg Keri
2026-10-02  9:49   ` Pierre Pinon [this message]
2026-10-02 17:24     ` [PATCH v2] media: i2c: ov08x40: Implement get_selection Oleg Keri
2026-10-05  8:15       ` Pierre Pinon
2026-10-05  8:53         ` Oleg Keri

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=20261002094913.28722-1-pierre@pinon1.fr \
    --to=pierre@pinon1.fr \
    --cc=hansg@kernel.org \
    --cc=jason.z.chen@intel.com \
    --cc=jimmy.su@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=okerixx@gmail.com \
    --cc=sakari.ailus@linux.intel.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®