1 From 8acf47ea3641126ed10ec54a8f6d72622dd2c61e Mon Sep 17 00:00:00 2001
2 From: Lee Jackson <info@arducam.com>
3 Date: Wed, 18 May 2022 15:18:59 +0800
4 Subject: [PATCH] media: i2c: arducam_64mp: Advertise embedded data
7 This commit updates the arducam_64mp driver to adverise support for
10 The arducam_64mp sensor subdevice overloads the media pad to differentiate
11 between image stream (pad 0) and embedded data stream (pad 1) when
12 performing the v4l2_subdev_pad_ops functions.
14 Signed-off-by: Lee Jackson <info@arducam.com>
16 drivers/media/i2c/arducam_64mp.c | 146 ++++++++++++++++++++++---------
17 1 file changed, 107 insertions(+), 39 deletions(-)
19 --- a/drivers/media/i2c/arducam_64mp.c
20 +++ b/drivers/media/i2c/arducam_64mp.c
22 #define ARDUCAM_64MP_TEST_PATTERN_B_DEFAULT 0
23 #define ARDUCAM_64MP_TEST_PATTERN_GB_DEFAULT 0
25 +/* Embedded metadata stream structure */
26 +#define ARDUCAM_64MP_EMBEDDED_LINE_WIDTH 16384
27 +#define ARDUCAM_64MP_NUM_EMBEDDED_LINES 1
35 /* ARDUCAM_64MP native and active pixel array size. */
36 #define ARDUCAM_64MP_NATIVE_WIDTH 9344U
37 #define ARDUCAM_64MP_NATIVE_HEIGHT 7032U
38 @@ -1273,7 +1283,7 @@ static const char * const arducam_64mp_s
41 struct v4l2_subdev sd;
42 - struct media_pad pad;
43 + struct media_pad pad[NUM_PADS];
45 unsigned int fmt_code;
47 @@ -1406,7 +1416,9 @@ static int arducam_64mp_open(struct v4l2
49 struct arducam_64mp *arducam_64mp = to_arducam_64mp(sd);
50 struct v4l2_mbus_framefmt *try_fmt_img =
51 - v4l2_subdev_get_try_format(sd, fh->state, 0);
52 + v4l2_subdev_get_try_format(sd, fh->state, IMAGE_PAD);
53 + struct v4l2_mbus_framefmt *try_fmt_meta =
54 + v4l2_subdev_get_try_format(sd, fh->state, METADATA_PAD);
55 struct v4l2_rect *try_crop;
57 mutex_lock(&arducam_64mp->mutex);
58 @@ -1417,8 +1429,14 @@ static int arducam_64mp_open(struct v4l2
59 try_fmt_img->code = arducam_64mp_get_format_code(arducam_64mp);
60 try_fmt_img->field = V4L2_FIELD_NONE;
62 + /* Initialize try_fmt for the embedded metadata pad */
63 + try_fmt_meta->width = ARDUCAM_64MP_EMBEDDED_LINE_WIDTH;
64 + try_fmt_meta->height = ARDUCAM_64MP_NUM_EMBEDDED_LINES;
65 + try_fmt_meta->code = MEDIA_BUS_FMT_SENSOR_DATA;
66 + try_fmt_meta->field = V4L2_FIELD_NONE;
68 /* Initialize try_crop */
69 - try_crop = v4l2_subdev_get_try_crop(sd, fh->state, 0);
70 + try_crop = v4l2_subdev_get_try_crop(sd, fh->state, IMAGE_PAD);
71 try_crop->left = ARDUCAM_64MP_PIXEL_ARRAY_LEFT;
72 try_crop->top = ARDUCAM_64MP_PIXEL_ARRAY_TOP;
73 try_crop->width = ARDUCAM_64MP_PIXEL_ARRAY_WIDTH;
74 @@ -1574,10 +1592,20 @@ static int arducam_64mp_enum_mbus_code(s
76 struct arducam_64mp *arducam_64mp = to_arducam_64mp(sd);
78 - if (code->index > 0)
79 + if (code->pad >= NUM_PADS)
82 - code->code = arducam_64mp_get_format_code(arducam_64mp);
83 + if (code->pad == IMAGE_PAD) {
84 + if (code->index > 0)
87 + code->code = arducam_64mp_get_format_code(arducam_64mp);
89 + if (code->index > 0)
92 + code->code = MEDIA_BUS_FMT_SENSOR_DATA;
97 @@ -1588,16 +1616,29 @@ static int arducam_64mp_enum_frame_size(
99 struct arducam_64mp *arducam_64mp = to_arducam_64mp(sd);
101 - if (fse->index >= ARRAY_SIZE(supported_modes))
102 + if (fse->pad >= NUM_PADS)
105 - if (fse->code != arducam_64mp_get_format_code(arducam_64mp))
107 + if (fse->pad == IMAGE_PAD) {
108 + if (fse->index >= ARRAY_SIZE(supported_modes))
111 + if (fse->code != arducam_64mp_get_format_code(arducam_64mp))
114 + fse->min_width = supported_modes[fse->index].width;
115 + fse->max_width = fse->min_width;
116 + fse->min_height = supported_modes[fse->index].height;
117 + fse->max_height = fse->min_height;
119 + if (fse->code != MEDIA_BUS_FMT_SENSOR_DATA || fse->index > 0)
122 - fse->min_width = supported_modes[fse->index].width;
123 - fse->max_width = fse->min_width;
124 - fse->min_height = supported_modes[fse->index].height;
125 - fse->max_height = fse->min_height;
126 + fse->min_width = ARDUCAM_64MP_EMBEDDED_LINE_WIDTH;
127 + fse->max_width = fse->min_width;
128 + fse->min_height = ARDUCAM_64MP_NUM_EMBEDDED_LINES;
129 + fse->max_height = fse->min_height;
134 @@ -1623,13 +1664,22 @@ arducam_64mp_update_image_pad_format(str
135 arducam_64mp_reset_colorspace(&fmt->format);
139 +arducam_64mp_update_metadata_pad_format(struct v4l2_subdev_format *fmt)
141 + fmt->format.width = ARDUCAM_64MP_EMBEDDED_LINE_WIDTH;
142 + fmt->format.height = ARDUCAM_64MP_NUM_EMBEDDED_LINES;
143 + fmt->format.code = MEDIA_BUS_FMT_SENSOR_DATA;
144 + fmt->format.field = V4L2_FIELD_NONE;
147 static int arducam_64mp_get_pad_format(struct v4l2_subdev *sd,
148 struct v4l2_subdev_state *sd_state,
149 struct v4l2_subdev_format *fmt)
151 struct arducam_64mp *arducam_64mp = to_arducam_64mp(sd);
154 + if (fmt->pad >= NUM_PADS)
157 mutex_lock(&arducam_64mp->mutex);
158 @@ -1639,14 +1689,20 @@ static int arducam_64mp_get_pad_format(s
159 v4l2_subdev_get_try_format(&arducam_64mp->sd, sd_state,
161 /* update the code which could change due to vflip or hflip: */
162 - try_fmt->code = arducam_64mp_get_format_code(arducam_64mp);
163 + try_fmt->code = fmt->pad == IMAGE_PAD ?
164 + arducam_64mp_get_format_code(arducam_64mp) :
165 + MEDIA_BUS_FMT_SENSOR_DATA;
166 fmt->format = *try_fmt;
168 - arducam_64mp_update_image_pad_format(arducam_64mp,
169 - arducam_64mp->mode,
172 - arducam_64mp_get_format_code(arducam_64mp);
173 + if (fmt->pad == IMAGE_PAD) {
174 + arducam_64mp_update_image_pad_format(arducam_64mp,
175 + arducam_64mp->mode,
178 + arducam_64mp_get_format_code(arducam_64mp);
180 + arducam_64mp_update_metadata_pad_format(fmt);
184 mutex_unlock(&arducam_64mp->mutex);
185 @@ -1714,28 +1770,39 @@ static int arducam_64mp_set_pad_format(s
186 const struct arducam_64mp_mode *mode;
187 struct arducam_64mp *arducam_64mp = to_arducam_64mp(sd);
190 + if (fmt->pad >= NUM_PADS)
193 mutex_lock(&arducam_64mp->mutex);
195 - /* Bayer order varies with flips */
196 - fmt->format.code = arducam_64mp_get_format_code(arducam_64mp);
198 - mode = v4l2_find_nearest_size(supported_modes,
199 - ARRAY_SIZE(supported_modes),
202 - fmt->format.height);
203 - arducam_64mp_update_image_pad_format(arducam_64mp, mode, fmt);
204 - if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
205 - framefmt = v4l2_subdev_get_try_format(sd, sd_state,
207 - *framefmt = fmt->format;
208 + if (fmt->pad == IMAGE_PAD) {
209 + /* Bayer order varies with flips */
210 + fmt->format.code = arducam_64mp_get_format_code(arducam_64mp);
212 + mode = v4l2_find_nearest_size(supported_modes,
213 + ARRAY_SIZE(supported_modes),
216 + fmt->format.height);
217 + arducam_64mp_update_image_pad_format(arducam_64mp, mode, fmt);
218 + if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
219 + framefmt = v4l2_subdev_get_try_format(sd, sd_state,
221 + *framefmt = fmt->format;
223 + arducam_64mp->mode = mode;
224 + arducam_64mp->fmt_code = fmt->format.code;
225 + arducam_64mp_set_framing_limits(arducam_64mp);
228 - arducam_64mp->mode = mode;
229 - arducam_64mp->fmt_code = fmt->format.code;
230 - arducam_64mp_set_framing_limits(arducam_64mp);
231 + if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
232 + framefmt = v4l2_subdev_get_try_format(sd, sd_state,
234 + *framefmt = fmt->format;
236 + /* Only one embedded data mode is supported */
237 + arducam_64mp_update_metadata_pad_format(fmt);
241 mutex_unlock(&arducam_64mp->mutex);
242 @@ -2329,10 +2396,11 @@ static int arducam_64mp_probe(struct i2c
243 arducam_64mp->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
245 /* Initialize source pads */
246 - arducam_64mp->pad.flags = MEDIA_PAD_FL_SOURCE;
247 + arducam_64mp->pad[IMAGE_PAD].flags = MEDIA_PAD_FL_SOURCE;
248 + arducam_64mp->pad[METADATA_PAD].flags = MEDIA_PAD_FL_SOURCE;
250 - ret = media_entity_pads_init(&arducam_64mp->sd.entity, 1,
251 - &arducam_64mp->pad);
252 + ret = media_entity_pads_init(&arducam_64mp->sd.entity, NUM_PADS,
253 + arducam_64mp->pad);
255 dev_err(dev, "failed to init entity pads: %d\n", ret);
256 goto error_handler_free;