Linux Media Controller development
 help / color / mirror / Atom feed
From: Bogdan Radulescu <bogdan@nimblex.net>
To: linux-media@vger.kernel.org
Cc: Sakari Ailus <sakari.ailus@linux.intel.com>,
	Jimmy Su <jimmy.su@intel.com>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans de Goede <hansg@kernel.org>,
	linux-kernel@vger.kernel.org,
	Bogdan Radulescu <bogdan@nimblex.net>
Subject: [PATCH] media: i2c: ov08x40: implement .get_selection
Date: Tue, 12 May 2026 19:30:10 +0300	[thread overview]
Message-ID: <20260512163010.2893978-1-bogdan@nimblex.net> (raw)

libcamera and other V4L2 subdev clients use VIDIOC_SUBDEV_G_SELECTION
to query the sensor's native size and crop bounds, as required by
Documentation/driver-api/media/camera-sensor.rst.  ov08x40 doesn't
implement the pad op, so libcamera falls back to a defaulted geometry
and complains at every probe:

  ov08x40 N-0010: Failed to retrieve the sensor crop rectangle
  ov08x40 N-0010: The sensor kernel driver needs to be fixed

The sensor has no optical-black margin and no analogue/digital crop
in any of its supported modes; native size, crop bounds and crop
default all coincide with the full 3856x2416 pixel array.  Report
that explicitly.

While at it, add OV08X40_NATIVE_WIDTH / OV08X40_NATIVE_HEIGHT for
the dimensions and drop the now-misleading 'No crop or compose'
comment from ov08x40_open().

Tested on a Lenovo ThinkPad X1 Carbon Gen 13 (Lunar Lake, IPU7):
the warnings above are gone and libcamera's simple pipeline reads
back the correct rectangles.

Signed-off-by: Bogdan Radulescu <bogdan@nimblex.net>
---
 drivers/media/i2c/ov08x40.c | 28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/drivers/media/i2c/ov08x40.c b/drivers/media/i2c/ov08x40.c
index 5eaf454f4763..31062eedbd71 100644
--- a/drivers/media/i2c/ov08x40.c
+++ b/drivers/media/i2c/ov08x40.c
@@ -38,6 +38,10 @@
 #define OV08X40_REG_CHIP_ID		0x300a
 #define OV08X40_CHIP_ID			0x560858
 
+/* Pixel array */
+#define OV08X40_NATIVE_WIDTH		3856U
+#define OV08X40_NATIVE_HEIGHT		2416U
+
 /* V_TIMING internal */
 #define OV08X40_REG_VTS			0x380e
 #define OV08X40_VTS_30FPS		0x09c4	/* the VTS need to be half in normal mode */
@@ -1556,12 +1560,33 @@ static int ov08x40_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
 	try_fmt->code = MEDIA_BUS_FMT_SGRBG10_1X10;
 	try_fmt->field = V4L2_FIELD_NONE;
 
-	/* No crop or compose */
 	mutex_unlock(&ov08x->mutex);
 
 	return 0;
 }
 
+static int ov08x40_get_selection(struct v4l2_subdev *sd,
+				 struct v4l2_subdev_state *state,
+				 struct v4l2_subdev_selection *sel)
+{
+	if (sel->which != V4L2_SUBDEV_FORMAT_ACTIVE)
+		return -EINVAL;
+
+	switch (sel->target) {
+	case V4L2_SEL_TGT_NATIVE_SIZE:
+	case V4L2_SEL_TGT_CROP_BOUNDS:
+	case V4L2_SEL_TGT_CROP_DEFAULT:
+	case V4L2_SEL_TGT_CROP:
+		sel->r.top = 0;
+		sel->r.left = 0;
+		sel->r.width = OV08X40_NATIVE_WIDTH;
+		sel->r.height = OV08X40_NATIVE_HEIGHT;
+		return 0;
+	}
+
+	return -EINVAL;
+}
+
 static int ov08x40_update_digital_gain(struct ov08x40 *ov08x, u32 d_gain)
 {
 	int ret;
@@ -2059,6 +2084,7 @@ 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.54.0


                 reply	other threads:[~2026-05-12 16:31 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20260512163010.2893978-1-bogdan@nimblex.net \
    --to=bogdan@nimblex.net \
    --cc=hansg@kernel.org \
    --cc=jimmy.su@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --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