1 From f479cf37ccda2be7204a964fe2747dfcb4b56bf6 Mon Sep 17 00:00:00 2001
2 From: Jacopo Mondi <jacopo@jmondi.org>
3 Date: Wed, 29 Apr 2020 11:50:38 +0200
4 Subject: [PATCH] media: i2c: imx219: Implement get_selection
6 Implement the get_selection pad operation for the IMX219 sensor driver.
7 The supported targets report the sensor's native size, the crop default
8 rectangle and the crop rectangle.
10 Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
11 Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>
13 drivers/media/i2c/imx219.c | 94 ++++++++++++++++++++++++++++++++++++++
14 1 file changed, 94 insertions(+)
16 --- a/drivers/media/i2c/imx219.c
17 +++ b/drivers/media/i2c/imx219.c
18 @@ -122,6 +122,14 @@ enum pad_types {
22 +/* IMX219 native and active pixel array size. */
23 +#define IMX219_NATIVE_WIDTH 3296U
24 +#define IMX219_NATIVE_HEIGHT 2480U
25 +#define IMX219_PIXEL_ARRAY_LEFT 8U
26 +#define IMX219_PIXEL_ARRAY_TOP 8U
27 +#define IMX219_PIXEL_ARRAY_WIDTH 3280U
28 +#define IMX219_PIXEL_ARRAY_HEIGHT 2464U
33 @@ -139,6 +147,9 @@ struct imx219_mode {
37 + /* Analog crop rectangle. */
38 + struct v4l2_rect crop;
43 @@ -473,6 +484,12 @@ static const struct imx219_mode supporte
44 /* 8MPix 15fps mode */
53 .vts_def = IMX219_VTS_15FPS,
55 .num_of_regs = ARRAY_SIZE(mode_3280x2464_regs),
56 @@ -483,6 +500,12 @@ static const struct imx219_mode supporte
57 /* 1080P 30fps cropped */
66 .vts_def = IMX219_VTS_30FPS_1080P,
68 .num_of_regs = ARRAY_SIZE(mode_1920_1080_regs),
69 @@ -493,6 +516,12 @@ static const struct imx219_mode supporte
70 /* 2x2 binned 30fps mode */
79 .vts_def = IMX219_VTS_30FPS_BINNED,
81 .num_of_regs = ARRAY_SIZE(mode_1640_1232_regs),
82 @@ -503,6 +532,12 @@ static const struct imx219_mode supporte
83 /* 640x480 30fps mode */
92 .vts_def = IMX219_VTS_30FPS_640x480,
94 .num_of_regs = ARRAY_SIZE(mode_640_480_regs),
95 @@ -666,6 +701,7 @@ static int imx219_open(struct v4l2_subde
96 v4l2_subdev_get_try_format(sd, fh->pad, IMAGE_PAD);
97 struct v4l2_mbus_framefmt *try_fmt_meta =
98 v4l2_subdev_get_try_format(sd, fh->pad, METADATA_PAD);
99 + struct v4l2_rect *try_crop;
101 mutex_lock(&imx219->mutex);
103 @@ -682,6 +718,13 @@ static int imx219_open(struct v4l2_subde
104 try_fmt_meta->code = MEDIA_BUS_FMT_SENSOR_DATA;
105 try_fmt_meta->field = V4L2_FIELD_NONE;
107 + /* Initialize try_crop rectangle. */
108 + try_crop = v4l2_subdev_get_try_crop(sd, fh->pad, 0);
109 + try_crop->top = IMX219_PIXEL_ARRAY_TOP;
110 + try_crop->left = IMX219_PIXEL_ARRAY_LEFT;
111 + try_crop->width = IMX219_PIXEL_ARRAY_WIDTH;
112 + try_crop->height = IMX219_PIXEL_ARRAY_HEIGHT;
114 mutex_unlock(&imx219->mutex);
117 @@ -1011,6 +1054,56 @@ static int imx219_set_framefmt(struct im
121 +static const struct v4l2_rect *
122 +__imx219_get_pad_crop(struct imx219 *imx219, struct v4l2_subdev_pad_config *cfg,
123 + unsigned int pad, enum v4l2_subdev_format_whence which)
126 + case V4L2_SUBDEV_FORMAT_TRY:
127 + return v4l2_subdev_get_try_crop(&imx219->sd, cfg, pad);
128 + case V4L2_SUBDEV_FORMAT_ACTIVE:
129 + return &imx219->mode->crop;
135 +static int imx219_get_selection(struct v4l2_subdev *sd,
136 + struct v4l2_subdev_pad_config *cfg,
137 + struct v4l2_subdev_selection *sel)
139 + switch (sel->target) {
140 + case V4L2_SEL_TGT_CROP: {
141 + struct imx219 *imx219 = to_imx219(sd);
143 + mutex_lock(&imx219->mutex);
144 + sel->r = *__imx219_get_pad_crop(imx219, cfg, sel->pad,
146 + mutex_unlock(&imx219->mutex);
151 + case V4L2_SEL_TGT_NATIVE_SIZE:
154 + sel->r.width = IMX219_NATIVE_WIDTH;
155 + sel->r.height = IMX219_NATIVE_HEIGHT;
159 + case V4L2_SEL_TGT_CROP_DEFAULT:
160 + sel->r.top = IMX219_PIXEL_ARRAY_TOP;
161 + sel->r.left = IMX219_PIXEL_ARRAY_LEFT;
162 + sel->r.width = IMX219_PIXEL_ARRAY_WIDTH;
163 + sel->r.height = IMX219_PIXEL_ARRAY_HEIGHT;
171 static int imx219_start_streaming(struct imx219 *imx219)
173 struct i2c_client *client = v4l2_get_subdevdata(&imx219->sd);
174 @@ -1235,6 +1328,7 @@ static const struct v4l2_subdev_pad_ops
175 .enum_mbus_code = imx219_enum_mbus_code,
176 .get_fmt = imx219_get_pad_format,
177 .set_fmt = imx219_set_pad_format,
178 + .get_selection = imx219_get_selection,
179 .enum_frame_size = imx219_enum_frame_size,