diff mbox series

[2/2] media: i2c: ov5670: Add .get_selection support

Message ID 20201211141424.277975-3-jacopo@jmondi.org
State New
Headers show
Series media: Add get_selecton to ov56470 and ov13858 | expand

Commit Message

Jacopo Mondi Dec. 11, 2020, 2:14 p.m. UTC
Add support for the get_selection subdev pad operation.

Support the V4L2_SEL_TGT_CROP_DEFAULT and V4L2_SEL_TGT_CROP_BOUNDS
static targets only to report the active pixel array size.

Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
---
 drivers/media/i2c/ov5670.c | 32 +++++++++++++++++++++++++++++++-
 1 file changed, 31 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/media/i2c/ov5670.c b/drivers/media/i2c/ov5670.c
index 148fd4e05029a..7f85ae1d93faf 100644
--- a/drivers/media/i2c/ov5670.c
+++ b/drivers/media/i2c/ov5670.c
@@ -67,6 +67,10 @@ 
 /* Initial number of frames to skip to avoid possible garbage */
 #define OV5670_NUM_OF_SKIP_FRAMES	2
 
+/* OV5670 pixel array size. */
+#define OV5670_PIXEL_ARRAY_WIDTH	2592
+#define OV5670_PIXEL_ARRAY_HEIGHT	1944
+
 struct ov5670_reg {
 	u16 address;
 	u8 val;
@@ -1938,6 +1942,7 @@  static int ov5670_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
 	struct ov5670 *ov5670 = to_ov5670(sd);
 	struct v4l2_mbus_framefmt *try_fmt =
 				v4l2_subdev_get_try_format(sd, fh->pad, 0);
+	struct v4l2_rect *try_crop;
 
 	mutex_lock(&ov5670->mutex);
 
@@ -1947,7 +1952,13 @@  static int ov5670_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 */
+	/* Initialize try_crop */
+	try_crop = v4l2_subdev_get_try_crop(sd, fh->pad, 0);
+	try_crop->top = 0;
+	try_crop->left = 0;
+	try_crop->width = OV5670_PIXEL_ARRAY_WIDTH;
+	try_crop->height = OV5670_PIXEL_ARRAY_HEIGHT;
+
 	mutex_unlock(&ov5670->mutex);
 
 	return 0;
@@ -2263,6 +2274,24 @@  static int ov5670_set_pad_format(struct v4l2_subdev *sd,
 	return 0;
 }
 
+static int ov5670_get_selection(struct v4l2_subdev *sd,
+				struct v4l2_subdev_pad_config *cfg,
+				struct v4l2_subdev_selection *sel)
+{
+	switch (sel->target) {
+	case V4L2_SEL_TGT_CROP_DEFAULT:
+	case V4L2_SEL_TGT_CROP_BOUNDS:
+		sel->r.top = 0;
+		sel->r.left = 0;
+		sel->r.width = OV5670_PIXEL_ARRAY_WIDTH;
+		sel->r.height = OV5670_PIXEL_ARRAY_HEIGHT;
+
+		return 0;
+	}
+
+	return -EINVAL;
+}
+
 static int ov5670_get_skip_frames(struct v4l2_subdev *sd, u32 *frames)
 {
 	*frames = OV5670_NUM_OF_SKIP_FRAMES;
@@ -2428,6 +2457,7 @@  static const struct v4l2_subdev_pad_ops ov5670_pad_ops = {
 	.enum_mbus_code = ov5670_enum_mbus_code,
 	.get_fmt = ov5670_get_pad_format,
 	.set_fmt = ov5670_set_pad_format,
+	.get_selection = ov5670_get_selection,
 	.enum_frame_size = ov5670_enum_frame_size,
 };