ab9683d1eef4023a96b5d4d14e4b9e38da8c6802
[openwrt/staging/blogic.git] /
1 From 39d7bf57e12edfb28cbc8a329d546fe8a6a396ef Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Tue, 14 Apr 2020 16:12:33 +0100
4 Subject: [PATCH] media: i2c: ov9281: Fixup for recent kernel releases,
5 and remove custom code
6
7 The Rockchip driver was based on a 4.4 kernel, and had several custom
8 Rockchip parts.
9
10 Update to 5.4 kernel APIs, with the relevant controls required by
11 libcamera, and remove custom Rockchip parts.
12
13 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
14 ---
15 drivers/media/i2c/ov9281.c | 361 +++++++++++++------------------------
16 1 file changed, 122 insertions(+), 239 deletions(-)
17
18 --- a/drivers/media/i2c/ov9281.c
19 +++ b/drivers/media/i2c/ov9281.c
20 @@ -1,6 +1,11 @@
21 // SPDX-License-Identifier: GPL-2.0
22 /*
23 - * ov9281 driver
24 + * Omnivision OV9281 1280x800 global shutter image sensor driver
25 + *
26 + * This driver has been taken from
27 + * https://github.com/rockchip-linux/kernel/blob/develop-4.4/drivers/media/i2c/ov9281.c
28 + * cleaned up, made to compile against mainline kernels instead of the Rockchip
29 + * vendor kernel, and the relevant controls added to work with libcamera.
30 *
31 * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
32 * V0.0X01.0X02 fix mclk issue when probe multiple camera.
33 @@ -17,22 +22,18 @@
34 #include <linux/regulator/consumer.h>
35 #include <linux/sysfs.h>
36 #include <linux/slab.h>
37 -#include <linux/rk-camera-module.h>
38 #include <media/media-entity.h>
39 #include <media/v4l2-async.h>
40 #include <media/v4l2-ctrls.h>
41 #include <media/v4l2-subdev.h>
42 -#include <linux/pinctrl/consumer.h>
43 -
44 -#define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x3)
45 -
46 -#ifndef V4L2_CID_DIGITAL_GAIN
47 -#define V4L2_CID_DIGITAL_GAIN V4L2_CID_GAIN
48 -#endif
49
50 #define OV9281_LINK_FREQ_400MHZ 400000000
51 +#define OV9281_LANES 2
52 +#define OV9281_BITS_PER_SAMPLE 10
53 +
54 /* pixel rate = link frequency * 2 * lanes / BITS_PER_SAMPLE */
55 -#define OV9281_PIXEL_RATE (OV9281_LINK_FREQ_400MHZ * 2 * 2 / 10)
56 +#define OV9281_PIXEL_RATE (OV9281_LINK_FREQ_400MHZ * 2 * \
57 + OV9281_LANES / OV9281_BITS_PER_SAMPLE)
58 #define OV9281_XVCLK_FREQ 24000000
59
60 #define CHIP_ID 0x9281
61 @@ -63,18 +64,24 @@
62
63 #define OV9281_REG_VTS 0x380e
64
65 +/*
66 + * OV9281 native and active pixel array size.
67 + * Datasheet not available to confirm these values, so assume there are no
68 + * border pixels.
69 + */
70 +#define OV9281_NATIVE_WIDTH 1280U
71 +#define OV9281_NATIVE_HEIGHT 800U
72 +#define OV9281_PIXEL_ARRAY_LEFT 0U
73 +#define OV9281_PIXEL_ARRAY_TOP 0U
74 +#define OV9281_PIXEL_ARRAY_WIDTH 1280U
75 +#define OV9281_PIXEL_ARRAY_HEIGHT 800U
76 +
77 #define REG_NULL 0xFFFF
78
79 #define OV9281_REG_VALUE_08BIT 1
80 #define OV9281_REG_VALUE_16BIT 2
81 #define OV9281_REG_VALUE_24BIT 3
82
83 -#define OV9281_LANES 2
84 -#define OV9281_BITS_PER_SAMPLE 10
85 -
86 -#define OF_CAMERA_PINCTRL_STATE_DEFAULT "rockchip,camera_default"
87 -#define OF_CAMERA_PINCTRL_STATE_SLEEP "rockchip,camera_sleep"
88 -
89 #define OV9281_NAME "ov9281"
90
91 static const char * const ov9281_supply_names[] = {
92 @@ -93,10 +100,10 @@ struct regval {
93 struct ov9281_mode {
94 u32 width;
95 u32 height;
96 - struct v4l2_fract max_fps;
97 u32 hts_def;
98 u32 vts_def;
99 u32 exp_def;
100 + struct v4l2_rect crop;
101 const struct regval *reg_list;
102 };
103
104 @@ -107,10 +114,6 @@ struct ov9281 {
105 struct gpio_desc *pwdn_gpio;
106 struct regulator_bulk_data supplies[OV9281_NUM_SUPPLIES];
107
108 - struct pinctrl *pinctrl;
109 - struct pinctrl_state *pins_default;
110 - struct pinctrl_state *pins_sleep;
111 -
112 struct v4l2_subdev subdev;
113 struct media_pad pad;
114 struct v4l2_ctrl_handler ctrl_handler;
115 @@ -124,23 +127,12 @@ struct ov9281 {
116 bool streaming;
117 bool power_on;
118 const struct ov9281_mode *cur_mode;
119 - u32 module_index;
120 - const char *module_facing;
121 - const char *module_name;
122 - const char *len_name;
123 };
124
125 #define to_ov9281(sd) container_of(sd, struct ov9281, subdev)
126
127 /*
128 * Xclk 24Mhz
129 - */
130 -static const struct regval ov9281_global_regs[] = {
131 - {REG_NULL, 0x00},
132 -};
133 -
134 -/*
135 - * Xclk 24Mhz
136 * max_framerate 120fps
137 * mipi_datarate per lane 800Mbps
138 */
139 @@ -247,13 +239,15 @@ static const struct ov9281_mode supporte
140 {
141 .width = 1280,
142 .height = 800,
143 - .max_fps = {
144 - .numerator = 10000,
145 - .denominator = 1200000,
146 - },
147 .exp_def = 0x0320,
148 - .hts_def = 0x0b60,//0x2d8*4
149 + .hts_def = 0x05b0, /* 0x2d8*2 */
150 .vts_def = 0x038e,
151 + .crop = {
152 + .left = 0,
153 + .top = 0,
154 + .width = 1280,
155 + .height = 800
156 + },
157 .reg_list = ov9281_1280x800_regs,
158 },
159 };
160 @@ -389,22 +383,28 @@ static int ov9281_set_fmt(struct v4l2_su
161 fmt->format.width = mode->width;
162 fmt->format.height = mode->height;
163 fmt->format.field = V4L2_FIELD_NONE;
164 + fmt->format.colorspace = V4L2_COLORSPACE_SRGB;
165 + fmt->format.ycbcr_enc =
166 + V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->format.colorspace);
167 + fmt->format.quantization =
168 + V4L2_MAP_QUANTIZATION_DEFAULT(true, fmt->format.colorspace,
169 + fmt->format.ycbcr_enc);
170 + fmt->format.xfer_func =
171 + V4L2_MAP_XFER_FUNC_DEFAULT(fmt->format.colorspace);
172 +
173 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
174 -#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
175 *v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format;
176 -#else
177 - mutex_unlock(&ov9281->mutex);
178 - return -ENOTTY;
179 -#endif
180 } else {
181 ov9281->cur_mode = mode;
182 h_blank = mode->hts_def - mode->width;
183 __v4l2_ctrl_modify_range(ov9281->hblank, h_blank,
184 h_blank, 1, h_blank);
185 + __v4l2_ctrl_s_ctrl(ov9281->hblank, h_blank);
186 vblank_def = mode->vts_def - mode->height;
187 __v4l2_ctrl_modify_range(ov9281->vblank, vblank_def,
188 OV9281_VTS_MAX - mode->height,
189 1, vblank_def);
190 + __v4l2_ctrl_s_ctrl(ov9281->vblank, vblank_def);
191 }
192
193 mutex_unlock(&ov9281->mutex);
194 @@ -421,17 +421,21 @@ static int ov9281_get_fmt(struct v4l2_su
195
196 mutex_lock(&ov9281->mutex);
197 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
198 -#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
199 fmt->format = *v4l2_subdev_get_try_format(sd, cfg, fmt->pad);
200 -#else
201 - mutex_unlock(&ov9281->mutex);
202 - return -ENOTTY;
203 -#endif
204 } else {
205 fmt->format.width = mode->width;
206 fmt->format.height = mode->height;
207 fmt->format.code = MEDIA_BUS_FMT_Y10_1X10;
208 fmt->format.field = V4L2_FIELD_NONE;
209 + fmt->format.colorspace = V4L2_COLORSPACE_SRGB;
210 + fmt->format.ycbcr_enc =
211 + V4L2_MAP_YCBCR_ENC_DEFAULT(fmt->format.colorspace);
212 + fmt->format.quantization =
213 + V4L2_MAP_QUANTIZATION_DEFAULT(true,
214 + fmt->format.colorspace,
215 + fmt->format.ycbcr_enc);
216 + fmt->format.xfer_func =
217 + V4L2_MAP_XFER_FUNC_DEFAULT(fmt->format.colorspace);
218 }
219 mutex_unlock(&ov9281->mutex);
220
221 @@ -442,7 +446,7 @@ static int ov9281_enum_mbus_code(struct
222 struct v4l2_subdev_pad_config *cfg,
223 struct v4l2_subdev_mbus_code_enum *code)
224 {
225 - if (code->index != 0)
226 + if (code->index)
227 return -EINVAL;
228 code->code = MEDIA_BUS_FMT_Y10_1X10;
229
230 @@ -480,88 +484,56 @@ static int ov9281_enable_test_pattern(st
231 OV9281_REG_VALUE_08BIT, val);
232 }
233
234 -static int OV9281_g_frame_interval(struct v4l2_subdev *sd,
235 - struct v4l2_subdev_frame_interval *fi)
236 -{
237 - struct ov9281 *ov9281 = to_ov9281(sd);
238 - const struct ov9281_mode *mode = ov9281->cur_mode;
239 -
240 - mutex_lock(&ov9281->mutex);
241 - fi->interval = mode->max_fps;
242 - mutex_unlock(&ov9281->mutex);
243 +static const struct v4l2_rect *
244 +__ov9281_get_pad_crop(struct ov9281 *ov9281, struct v4l2_subdev_pad_config *cfg,
245 + unsigned int pad, enum v4l2_subdev_format_whence which)
246 +{
247 + switch (which) {
248 + case V4L2_SUBDEV_FORMAT_TRY:
249 + return v4l2_subdev_get_try_crop(&ov9281->subdev, cfg, pad);
250 + case V4L2_SUBDEV_FORMAT_ACTIVE:
251 + return &ov9281->cur_mode->crop;
252 + }
253
254 - return 0;
255 + return NULL;
256 }
257
258 -static void ov9281_get_module_inf(struct ov9281 *ov9281,
259 - struct rkmodule_inf *inf)
260 +static int ov9281_get_selection(struct v4l2_subdev *sd,
261 + struct v4l2_subdev_pad_config *cfg,
262 + struct v4l2_subdev_selection *sel)
263 {
264 - memset(inf, 0, sizeof(*inf));
265 - strlcpy(inf->base.sensor, OV9281_NAME, sizeof(inf->base.sensor));
266 - strlcpy(inf->base.module, ov9281->module_name,
267 - sizeof(inf->base.module));
268 - strlcpy(inf->base.lens, ov9281->len_name, sizeof(inf->base.lens));
269 -}
270 + switch (sel->target) {
271 + case V4L2_SEL_TGT_CROP: {
272 + struct ov9281 *ov9281 = to_ov9281(sd);
273
274 -static long ov9281_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
275 -{
276 - struct ov9281 *ov9281 = to_ov9281(sd);
277 - long ret = 0;
278 + mutex_lock(&ov9281->mutex);
279 + sel->r = *__ov9281_get_pad_crop(ov9281, cfg, sel->pad,
280 + sel->which);
281 + mutex_unlock(&ov9281->mutex);
282
283 - switch (cmd) {
284 - case RKMODULE_GET_MODULE_INFO:
285 - ov9281_get_module_inf(ov9281, (struct rkmodule_inf *)arg);
286 - break;
287 - default:
288 - ret = -ENOIOCTLCMD;
289 - break;
290 + return 0;
291 }
292
293 - return ret;
294 -}
295 + case V4L2_SEL_TGT_NATIVE_SIZE:
296 + sel->r.top = 0;
297 + sel->r.left = 0;
298 + sel->r.width = OV9281_NATIVE_WIDTH;
299 + sel->r.height = OV9281_NATIVE_HEIGHT;
300
301 -#ifdef CONFIG_COMPAT
302 -static long ov9281_compat_ioctl32(struct v4l2_subdev *sd,
303 - unsigned int cmd, unsigned long arg)
304 -{
305 - void __user *up = compat_ptr(arg);
306 - struct rkmodule_inf *inf;
307 - struct rkmodule_awb_cfg *cfg;
308 - long ret;
309 -
310 - switch (cmd) {
311 - case RKMODULE_GET_MODULE_INFO:
312 - inf = kzalloc(sizeof(*inf), GFP_KERNEL);
313 - if (!inf) {
314 - ret = -ENOMEM;
315 - return ret;
316 - }
317 + return 0;
318
319 - ret = ov9281_ioctl(sd, cmd, inf);
320 - if (!ret)
321 - ret = copy_to_user(up, inf, sizeof(*inf));
322 - kfree(inf);
323 - break;
324 - case RKMODULE_AWB_CFG:
325 - cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
326 - if (!cfg) {
327 - ret = -ENOMEM;
328 - return ret;
329 - }
330 + case V4L2_SEL_TGT_CROP_DEFAULT:
331 + case V4L2_SEL_TGT_CROP_BOUNDS:
332 + sel->r.top = OV9281_PIXEL_ARRAY_TOP;
333 + sel->r.left = OV9281_PIXEL_ARRAY_LEFT;
334 + sel->r.width = OV9281_PIXEL_ARRAY_WIDTH;
335 + sel->r.height = OV9281_PIXEL_ARRAY_HEIGHT;
336
337 - ret = copy_from_user(cfg, up, sizeof(*cfg));
338 - if (!ret)
339 - ret = ov9281_ioctl(sd, cmd, cfg);
340 - kfree(cfg);
341 - break;
342 - default:
343 - ret = -ENOIOCTLCMD;
344 - break;
345 + return 0;
346 }
347
348 - return ret;
349 + return -EINVAL;
350 }
351 -#endif
352
353 static int __ov9281_start_stream(struct ov9281 *ov9281)
354 {
355 @@ -643,12 +615,6 @@ static int ov9281_s_power(struct v4l2_su
356 pm_runtime_put_noidle(&client->dev);
357 goto unlock_and_return;
358 }
359 - ret = ov9281_write_array(ov9281->client, ov9281_global_regs);
360 - if (ret) {
361 - v4l2_err(sd, "could not set init registers\n");
362 - pm_runtime_put_noidle(&client->dev);
363 - goto unlock_and_return;
364 - }
365 ov9281->power_on = true;
366 } else {
367 pm_runtime_put(&client->dev);
368 @@ -673,18 +639,12 @@ static int __ov9281_power_on(struct ov92
369 u32 delay_us;
370 struct device *dev = &ov9281->client->dev;
371
372 - if (!IS_ERR_OR_NULL(ov9281->pins_default)) {
373 - ret = pinctrl_select_state(ov9281->pinctrl,
374 - ov9281->pins_default);
375 - if (ret < 0)
376 - dev_err(dev, "could not set pins\n");
377 - }
378 -
379 ret = clk_set_rate(ov9281->xvclk, OV9281_XVCLK_FREQ);
380 if (ret < 0)
381 dev_warn(dev, "Failed to set xvclk rate (24MHz)\n");
382 if (clk_get_rate(ov9281->xvclk) != OV9281_XVCLK_FREQ)
383 - dev_warn(dev, "xvclk mismatched, modes are based on 24MHz\n");
384 + dev_warn(dev, "xvclk mismatched, modes are based on 24MHz - rate is %lu\n",
385 + clk_get_rate(ov9281->xvclk));
386
387 ret = clk_prepare_enable(ov9281->xvclk);
388 if (ret < 0) {
389 @@ -722,20 +682,11 @@ disable_clk:
390
391 static void __ov9281_power_off(struct ov9281 *ov9281)
392 {
393 - int ret;
394 - struct device *dev = &ov9281->client->dev;
395 -
396 if (!IS_ERR(ov9281->pwdn_gpio))
397 gpiod_set_value_cansleep(ov9281->pwdn_gpio, 0);
398 clk_disable_unprepare(ov9281->xvclk);
399 if (!IS_ERR(ov9281->reset_gpio))
400 gpiod_set_value_cansleep(ov9281->reset_gpio, 0);
401 - if (!IS_ERR_OR_NULL(ov9281->pins_sleep)) {
402 - ret = pinctrl_select_state(ov9281->pinctrl,
403 - ov9281->pins_sleep);
404 - if (ret < 0)
405 - dev_dbg(dev, "could not set pins\n");
406 - }
407 regulator_bulk_disable(OV9281_NUM_SUPPLIES, ov9281->supplies);
408 }
409
410 @@ -759,7 +710,6 @@ static int ov9281_runtime_suspend(struct
411 return 0;
412 }
413
414 -#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
415 static int ov9281_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
416 {
417 struct ov9281 *ov9281 = to_ov9281(sd);
418 @@ -773,61 +723,42 @@ static int ov9281_open(struct v4l2_subde
419 try_fmt->height = def_mode->height;
420 try_fmt->code = MEDIA_BUS_FMT_Y10_1X10;
421 try_fmt->field = V4L2_FIELD_NONE;
422 + try_fmt->colorspace = V4L2_COLORSPACE_SRGB;
423 + try_fmt->ycbcr_enc = V4L2_MAP_YCBCR_ENC_DEFAULT(try_fmt->colorspace);
424 + try_fmt->quantization =
425 + V4L2_MAP_QUANTIZATION_DEFAULT(true, try_fmt->colorspace,
426 + try_fmt->ycbcr_enc);
427 + try_fmt->xfer_func = V4L2_MAP_XFER_FUNC_DEFAULT(try_fmt->colorspace);
428
429 mutex_unlock(&ov9281->mutex);
430 /* No crop or compose */
431
432 return 0;
433 }
434 -#endif
435 -
436 -static int
437 -ov9281_enum_frame_interval(struct v4l2_subdev *sd,
438 - struct v4l2_subdev_pad_config *cfg,
439 - struct v4l2_subdev_frame_interval_enum *fie)
440 -{
441 - if (fie->index >= ARRAY_SIZE(supported_modes))
442 - return -EINVAL;
443 -
444 - if (fie->code != MEDIA_BUS_FMT_Y10_1X10)
445 - return -EINVAL;
446 -
447 - fie->width = supported_modes[fie->index].width;
448 - fie->height = supported_modes[fie->index].height;
449 - fie->interval = supported_modes[fie->index].max_fps;
450 - return 0;
451 -}
452
453 static const struct dev_pm_ops ov9281_pm_ops = {
454 SET_RUNTIME_PM_OPS(ov9281_runtime_suspend,
455 ov9281_runtime_resume, NULL)
456 };
457
458 -#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
459 static const struct v4l2_subdev_internal_ops ov9281_internal_ops = {
460 .open = ov9281_open,
461 };
462 -#endif
463
464 static const struct v4l2_subdev_core_ops ov9281_core_ops = {
465 .s_power = ov9281_s_power,
466 - .ioctl = ov9281_ioctl,
467 -#ifdef CONFIG_COMPAT
468 - .compat_ioctl32 = ov9281_compat_ioctl32,
469 -#endif
470 };
471
472 static const struct v4l2_subdev_video_ops ov9281_video_ops = {
473 .s_stream = ov9281_s_stream,
474 - .g_frame_interval = OV9281_g_frame_interval,
475 };
476
477 static const struct v4l2_subdev_pad_ops ov9281_pad_ops = {
478 .enum_mbus_code = ov9281_enum_mbus_code,
479 .enum_frame_size = ov9281_enum_frame_sizes,
480 - .enum_frame_interval = ov9281_enum_frame_interval,
481 .get_fmt = ov9281_get_fmt,
482 .set_fmt = ov9281_set_fmt,
483 + .get_selection = ov9281_get_selection,
484 };
485
486 static const struct v4l2_subdev_ops ov9281_subdev_ops = {
487 @@ -868,7 +799,8 @@ static int ov9281_set_ctrl(struct v4l2_c
488 case V4L2_CID_ANALOGUE_GAIN:
489 ret = ov9281_write_reg(ov9281->client, OV9281_REG_GAIN_H,
490 OV9281_REG_VALUE_08BIT,
491 - (ctrl->val >> OV9281_GAIN_H_SHIFT) & OV9281_GAIN_H_MASK);
492 + (ctrl->val >> OV9281_GAIN_H_SHIFT) &
493 + OV9281_GAIN_H_MASK);
494 ret |= ov9281_write_reg(ov9281->client, OV9281_REG_GAIN_L,
495 OV9281_REG_VALUE_08BIT,
496 ctrl->val & OV9281_GAIN_L_MASK);
497 @@ -922,31 +854,34 @@ static int ov9281_initialize_controls(st
498
499 h_blank = mode->hts_def - mode->width;
500 ov9281->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK,
501 - h_blank, h_blank, 1, h_blank);
502 + h_blank, h_blank, 1, h_blank);
503 if (ov9281->hblank)
504 ov9281->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
505
506 vblank_def = mode->vts_def - mode->height;
507 ov9281->vblank = v4l2_ctrl_new_std(handler, &ov9281_ctrl_ops,
508 - V4L2_CID_VBLANK, vblank_def,
509 - OV9281_VTS_MAX - mode->height,
510 - 1, vblank_def);
511 + V4L2_CID_VBLANK, vblank_def,
512 + OV9281_VTS_MAX - mode->height, 1,
513 + vblank_def);
514
515 exposure_max = mode->vts_def - 4;
516 ov9281->exposure = v4l2_ctrl_new_std(handler, &ov9281_ctrl_ops,
517 - V4L2_CID_EXPOSURE, OV9281_EXPOSURE_MIN,
518 - exposure_max, OV9281_EXPOSURE_STEP,
519 - mode->exp_def);
520 + V4L2_CID_EXPOSURE,
521 + OV9281_EXPOSURE_MIN, exposure_max,
522 + OV9281_EXPOSURE_STEP,
523 + mode->exp_def);
524
525 ov9281->anal_gain = v4l2_ctrl_new_std(handler, &ov9281_ctrl_ops,
526 - V4L2_CID_ANALOGUE_GAIN, OV9281_GAIN_MIN,
527 - OV9281_GAIN_MAX, OV9281_GAIN_STEP,
528 - OV9281_GAIN_DEFAULT);
529 -
530 - ov9281->test_pattern = v4l2_ctrl_new_std_menu_items(handler,
531 - &ov9281_ctrl_ops, V4L2_CID_TEST_PATTERN,
532 - ARRAY_SIZE(ov9281_test_pattern_menu) - 1,
533 - 0, 0, ov9281_test_pattern_menu);
534 + V4L2_CID_ANALOGUE_GAIN,
535 + OV9281_GAIN_MIN, OV9281_GAIN_MAX,
536 + OV9281_GAIN_STEP,
537 + OV9281_GAIN_DEFAULT);
538 +
539 + ov9281->test_pattern =
540 + v4l2_ctrl_new_std_menu_items(handler, &ov9281_ctrl_ops,
541 + V4L2_CID_TEST_PATTERN,
542 + ARRAY_SIZE(ov9281_test_pattern_menu) - 1,
543 + 0, 0, ov9281_test_pattern_menu);
544
545 if (handler->error) {
546 ret = handler->error;
547 @@ -1000,34 +935,14 @@ static int ov9281_probe(struct i2c_clien
548 const struct i2c_device_id *id)
549 {
550 struct device *dev = &client->dev;
551 - struct device_node *node = dev->of_node;
552 struct ov9281 *ov9281;
553 struct v4l2_subdev *sd;
554 - char facing[2];
555 int ret;
556
557 - dev_info(dev, "driver version: %02x.%02x.%02x",
558 - DRIVER_VERSION >> 16,
559 - (DRIVER_VERSION & 0xff00) >> 8,
560 - DRIVER_VERSION & 0x00ff);
561 -
562 ov9281 = devm_kzalloc(dev, sizeof(*ov9281), GFP_KERNEL);
563 if (!ov9281)
564 return -ENOMEM;
565
566 - ret = of_property_read_u32(node, RKMODULE_CAMERA_MODULE_INDEX,
567 - &ov9281->module_index);
568 - ret |= of_property_read_string(node, RKMODULE_CAMERA_MODULE_FACING,
569 - &ov9281->module_facing);
570 - ret |= of_property_read_string(node, RKMODULE_CAMERA_MODULE_NAME,
571 - &ov9281->module_name);
572 - ret |= of_property_read_string(node, RKMODULE_CAMERA_LENS_NAME,
573 - &ov9281->len_name);
574 - if (ret) {
575 - dev_err(dev, "could not get module information!\n");
576 - return -EINVAL;
577 - }
578 -
579 ov9281->client = client;
580 ov9281->cur_mode = &supported_modes[0];
581
582 @@ -1037,31 +952,15 @@ static int ov9281_probe(struct i2c_clien
583 return -EINVAL;
584 }
585
586 - ov9281->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
587 + ov9281->reset_gpio = devm_gpiod_get_optional(dev, "reset",
588 + GPIOD_OUT_LOW);
589 if (IS_ERR(ov9281->reset_gpio))
590 dev_warn(dev, "Failed to get reset-gpios\n");
591
592 - ov9281->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_OUT_LOW);
593 + ov9281->pwdn_gpio = devm_gpiod_get_optional(dev, "pwdn", GPIOD_OUT_LOW);
594 if (IS_ERR(ov9281->pwdn_gpio))
595 dev_warn(dev, "Failed to get pwdn-gpios\n");
596
597 - ov9281->pinctrl = devm_pinctrl_get(dev);
598 - if (!IS_ERR(ov9281->pinctrl)) {
599 - ov9281->pins_default =
600 - pinctrl_lookup_state(ov9281->pinctrl,
601 - OF_CAMERA_PINCTRL_STATE_DEFAULT);
602 - if (IS_ERR(ov9281->pins_default))
603 - dev_err(dev, "could not get default pinstate\n");
604 -
605 - ov9281->pins_sleep =
606 - pinctrl_lookup_state(ov9281->pinctrl,
607 - OF_CAMERA_PINCTRL_STATE_SLEEP);
608 - if (IS_ERR(ov9281->pins_sleep))
609 - dev_err(dev, "could not get sleep pinstate\n");
610 - } else {
611 - dev_err(dev, "no pinctrl\n");
612 - }
613 -
614 ret = ov9281_configure_regulators(ov9281);
615 if (ret) {
616 dev_err(dev, "Failed to get power regulators\n");
617 @@ -1084,26 +983,16 @@ static int ov9281_probe(struct i2c_clien
618 if (ret)
619 goto err_power_off;
620
621 -#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
622 sd->internal_ops = &ov9281_internal_ops;
623 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
624 -#endif
625 -#if defined(CONFIG_MEDIA_CONTROLLER)
626 +
627 ov9281->pad.flags = MEDIA_PAD_FL_SOURCE;
628 - sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
629 - ret = media_entity_init(&sd->entity, 1, &ov9281->pad, 0);
630 + sd->entity.function = MEDIA_ENT_F_CAM_SENSOR;
631 + ret = media_entity_pads_init(&sd->entity, 1, &ov9281->pad);
632 if (ret < 0)
633 goto err_power_off;
634 -#endif
635 -
636 - memset(facing, 0, sizeof(facing));
637 - if (strcmp(ov9281->module_facing, "back") == 0)
638 - facing[0] = 'b';
639 - else
640 - facing[0] = 'f';
641
642 - snprintf(sd->name, sizeof(sd->name), "m%02d_%s_%s %s",
643 - ov9281->module_index, facing,
644 + snprintf(sd->name, sizeof(sd->name), "m%s %s",
645 OV9281_NAME, dev_name(sd->dev));
646 ret = v4l2_async_register_subdev_sensor(sd);
647 if (ret) {
648 @@ -1118,9 +1007,7 @@ static int ov9281_probe(struct i2c_clien
649 return 0;
650
651 err_clean_entity:
652 -#if defined(CONFIG_MEDIA_CONTROLLER)
653 media_entity_cleanup(&sd->entity);
654 -#endif
655 err_power_off:
656 __ov9281_power_off(ov9281);
657 err_free_handler:
658 @@ -1137,9 +1024,7 @@ static int ov9281_remove(struct i2c_clie
659 struct ov9281 *ov9281 = to_ov9281(sd);
660
661 v4l2_async_unregister_subdev(sd);
662 -#if defined(CONFIG_MEDIA_CONTROLLER)
663 media_entity_cleanup(&sd->entity);
664 -#endif
665 v4l2_ctrl_handler_free(&ov9281->ctrl_handler);
666 mutex_destroy(&ov9281->mutex);
667
668 @@ -1151,13 +1036,11 @@ static int ov9281_remove(struct i2c_clie
669 return 0;
670 }
671
672 -#if IS_ENABLED(CONFIG_OF)
673 static const struct of_device_id ov9281_of_match[] = {
674 { .compatible = "ovti,ov9281" },
675 {},
676 };
677 MODULE_DEVICE_TABLE(of, ov9281_of_match);
678 -#endif
679
680 static const struct i2c_device_id ov9281_match_id[] = {
681 { "ovti,ov9281", 0 },