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