1 From ee95eb32c4202a2d290af6c754806ef3bdfb3fda Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Tue, 7 Jul 2020 11:23:48 +0100
4 Subject: [PATCH] media: i2c: imx290: Add support for g_selection to
7 Userspace needs to know the cropping arrangements for each mode,
8 so expose this through g_selection.
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
12 drivers/media/i2c/imx290.c | 84 ++++++++++++++++++++++++++++++++++++++
13 1 file changed, 84 insertions(+)
15 --- a/drivers/media/i2c/imx290.c
16 +++ b/drivers/media/i2c/imx290.c
17 @@ -61,6 +61,13 @@ enum imx290_clk_index {
18 #define IMX290_PGCTRL_THRU BIT(1)
19 #define IMX290_PGCTRL_MODE(n) ((n) << 4)
21 +#define IMX290_NATIVE_WIDTH 1945U
22 +#define IMX290_NATIVE_HEIGHT 1109U
23 +#define IMX290_PIXEL_ARRAY_LEFT 4U
24 +#define IMX290_PIXEL_ARRAY_TOP 12U
25 +#define IMX290_PIXEL_ARRAY_WIDTH 1937U
26 +#define IMX290_PIXEL_ARRAY_HEIGHT 1097U
28 static const char * const imx290_supply_name[] = {
31 @@ -80,6 +87,7 @@ struct imx290_mode {
35 + struct v4l2_rect crop;
37 const struct imx290_regval *data;
39 @@ -384,6 +392,12 @@ static const struct imx290_mode imx290_m
42 .link_freq_index = FREQ_INDEX_1080P,
49 .data = imx290_1080p_settings,
50 .data_size = ARRAY_SIZE(imx290_1080p_settings),
52 @@ -398,6 +412,12 @@ static const struct imx290_mode imx290_m
55 .link_freq_index = FREQ_INDEX_720P,
57 + .left = 4 + 8 + 320,
58 + .top = 12 + 8 + 180,
62 .data = imx290_720p_settings,
63 .data_size = ARRAY_SIZE(imx290_720p_settings),
65 @@ -415,6 +435,12 @@ static const struct imx290_mode imx290_m
68 .link_freq_index = FREQ_INDEX_1080P,
75 .data = imx290_1080p_settings,
76 .data_size = ARRAY_SIZE(imx290_1080p_settings),
78 @@ -429,6 +455,12 @@ static const struct imx290_mode imx290_m
81 .link_freq_index = FREQ_INDEX_720P,
83 + .left = 4 + 8 + 320,
84 + .top = 12 + 8 + 180,
88 .data = imx290_720p_settings,
89 .data_size = ARRAY_SIZE(imx290_720p_settings),
91 @@ -875,6 +907,57 @@ static int imx290_write_current_format(s
95 +static const struct v4l2_rect *
96 +__imx290_get_pad_crop(struct imx290 *imx290, struct v4l2_subdev_pad_config *cfg,
97 + unsigned int pad, enum v4l2_subdev_format_whence which)
100 + case V4L2_SUBDEV_FORMAT_TRY:
101 + return v4l2_subdev_get_try_crop(&imx290->sd, cfg, pad);
102 + case V4L2_SUBDEV_FORMAT_ACTIVE:
103 + return &imx290->current_mode->crop;
109 +static int imx290_get_selection(struct v4l2_subdev *sd,
110 + struct v4l2_subdev_pad_config *cfg,
111 + struct v4l2_subdev_selection *sel)
113 + switch (sel->target) {
114 + case V4L2_SEL_TGT_CROP: {
115 + struct imx290 *imx290 = to_imx290(sd);
117 + mutex_lock(&imx290->lock);
118 + sel->r = *__imx290_get_pad_crop(imx290, cfg, sel->pad,
120 + mutex_unlock(&imx290->lock);
125 + case V4L2_SEL_TGT_NATIVE_SIZE:
128 + sel->r.width = IMX290_NATIVE_WIDTH;
129 + sel->r.height = IMX290_NATIVE_HEIGHT;
133 + case V4L2_SEL_TGT_CROP_DEFAULT:
134 + case V4L2_SEL_TGT_CROP_BOUNDS:
135 + sel->r.top = IMX290_PIXEL_ARRAY_TOP;
136 + sel->r.left = IMX290_PIXEL_ARRAY_LEFT;
137 + sel->r.width = IMX290_PIXEL_ARRAY_WIDTH;
138 + sel->r.height = IMX290_PIXEL_ARRAY_HEIGHT;
146 /* Start streaming */
147 static int imx290_start_streaming(struct imx290 *imx290)
149 @@ -1073,6 +1156,7 @@ static const struct v4l2_subdev_pad_ops
150 .enum_frame_size = imx290_enum_frame_size,
151 .get_fmt = imx290_get_fmt,
152 .set_fmt = imx290_set_fmt,
153 + .get_selection = imx290_get_selection,
156 static const struct v4l2_subdev_ops imx290_subdev_ops = {