[PATCH v12 52/86] media: ov2740: Add support for G_SELECTION IOCTL

Sakari Ailus
2026-04-09T20:14:56Z

Add support for the G_SELECTION IOCTL in the ov2740 driver.

Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
---
drivers/media/i2c/ov2740.c | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)

diff --git a/drivers/media/i2c/ov2740.c b/drivers/media/i2c/ov2740.c
index 3308c51933aa..1ab2b82f4099 100644
--- a/drivers/media/i2c/ov2740.c
+++ b/drivers/media/i2c/ov2740.c
@@ -1139,6 +1139,32 @@ static int ov2740_set_format(struct v4l2_subdev *sd,
fmt->pad, fmt->stream);
}

+static int ov2740_get_selection(struct v4l2_subdev *sd,
+ const struct v4l2_subdev_client_info *ci,
+ struct v4l2_subdev_state *state,
+ struct v4l2_subdev_selection *sel)
+{
+ if (!(ci && ci->client_caps & V4L2_SUBDEV_CLIENT_CAP_COMMON_RAW_SENSOR))
+ return -EINVAL;
+
+ if (sel->stream != OV2740_STREAM_PIXEL ||
+ sel->pad != OV2740_PAD_PIXEL)
+ return -EINVAL;
+
+ switch (sel->target) {
+ case V4L2_SEL_TGT_CROP_BOUNDS:
+ case V4L2_SEL_TGT_CROP_DEFAULT:
+ case V4L2_SEL_TGT_CROP:
+ sel->r.top = OV2740_CROP_TOP;
+ sel->r.left = OV2740_CROP_LEFT;
+ sel->r.width = OV2740_ACTIVE_WIDTH - OV2740_CROP_LEFT;
+ sel->r.height = OV2740_ACTIVE_HEIGHT - OV2740_CROP_TOP;
+ return 0;
+ }
+
+ return -EINVAL;
+}
+
static int ov2740_enum_mbus_code(struct v4l2_subdev *sd,
struct v4l2_subdev_state *sd_state,
struct v4l2_subdev_mbus_code_enum *code)
@@ -1263,6 +1289,7 @@ static const struct v4l2_subdev_video_ops ov2740_video_ops = {
static const struct v4l2_subdev_pad_ops ov2740_pad_ops = {
.get_fmt = v4l2_subdev_get_fmt,
.set_fmt = ov2740_set_format,
+ .get_selection = ov2740_get_selection,
.enum_mbus_code = ov2740_enum_mbus_code,
.enum_frame_size = ov2740_enum_frame_size,
.enable_streams = ov2740_enable_streams,
--
2.47.3