1 From a73ced40f7ca1b0735e5d0d1c45087e02023a618 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,
7 The Rockchip driver was based on a 4.4 kernel, and had several custom
10 Update to 5.4 kernel APIs, with the relevant controls required by
11 libcamera, and remove custom Rockchip parts.
13 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
15 drivers/media/i2c/ov9281.c | 361 +++++++++++++------------------------
16 1 file changed, 122 insertions(+), 239 deletions(-)
18 --- a/drivers/media/i2c/ov9281.c
19 +++ b/drivers/media/i2c/ov9281.c
21 // SPDX-License-Identifier: GPL-2.0
24 + * Omnivision OV9281 1280x800 global shutter image sensor driver
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.
31 * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
32 * V0.0X01.0X02 fix mclk issue when probe multiple camera.
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>
44 -#define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x3)
46 -#ifndef V4L2_CID_DIGITAL_GAIN
47 -#define V4L2_CID_DIGITAL_GAIN V4L2_CID_GAIN
50 #define OV9281_LINK_FREQ_400MHZ 400000000
51 +#define OV9281_LANES 2
52 +#define OV9281_BITS_PER_SAMPLE 10
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
60 #define CHIP_ID 0x9281
63 #define OV9281_REG_VTS 0x380e
66 + * OV9281 native and active pixel array size.
67 + * Datasheet not available to confirm these values, so assume there are no
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
77 #define REG_NULL 0xFFFF
79 #define OV9281_REG_VALUE_08BIT 1
80 #define OV9281_REG_VALUE_16BIT 2
81 #define OV9281_REG_VALUE_24BIT 3
83 -#define OV9281_LANES 2
84 -#define OV9281_BITS_PER_SAMPLE 10
86 -#define OF_CAMERA_PINCTRL_STATE_DEFAULT "rockchip,camera_default"
87 -#define OF_CAMERA_PINCTRL_STATE_SLEEP "rockchip,camera_sleep"
89 #define OV9281_NAME "ov9281"
91 static const char * const ov9281_supply_names[] = {
92 @@ -93,10 +100,10 @@ struct regval {
96 - struct v4l2_fract max_fps;
100 + struct v4l2_rect crop;
101 const struct regval *reg_list;
104 @@ -107,10 +114,6 @@ struct ov9281 {
105 struct gpio_desc *pwdn_gpio;
106 struct regulator_bulk_data supplies[OV9281_NUM_SUPPLIES];
108 - struct pinctrl *pinctrl;
109 - struct pinctrl_state *pins_default;
110 - struct pinctrl_state *pins_sleep;
112 struct v4l2_subdev subdev;
113 struct media_pad pad;
114 struct v4l2_ctrl_handler ctrl_handler;
115 @@ -124,23 +127,12 @@ struct ov9281 {
118 const struct ov9281_mode *cur_mode;
120 - const char *module_facing;
121 - const char *module_name;
122 - const char *len_name;
125 #define to_ov9281(sd) container_of(sd, struct ov9281, subdev)
130 -static const struct regval ov9281_global_regs[] = {
136 * max_framerate 120fps
137 * mipi_datarate per lane 800Mbps
139 @@ -247,13 +239,15 @@ static const struct ov9281_mode supporte
144 - .numerator = 10000,
145 - .denominator = 1200000,
148 - .hts_def = 0x0b60,//0x2d8*4
149 + .hts_def = 0x05b0, /* 0x2d8*2 */
157 .reg_list = ov9281_1280x800_regs,
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);
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;
177 - mutex_unlock(&ov9281->mutex);
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,
190 + __v4l2_ctrl_s_ctrl(ov9281->vblank, vblank_def);
193 mutex_unlock(&ov9281->mutex);
194 @@ -421,17 +421,21 @@ static int ov9281_get_fmt(struct v4l2_su
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);
201 - mutex_unlock(&ov9281->mutex);
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);
219 mutex_unlock(&ov9281->mutex);
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)
225 - if (code->index != 0)
228 code->code = MEDIA_BUS_FMT_Y10_1X10;
230 @@ -480,88 +484,56 @@ static int ov9281_enable_test_pattern(st
231 OV9281_REG_VALUE_08BIT, val);
234 -static int OV9281_g_frame_interval(struct v4l2_subdev *sd,
235 - struct v4l2_subdev_frame_interval *fi)
237 - struct ov9281 *ov9281 = to_ov9281(sd);
238 - const struct ov9281_mode *mode = ov9281->cur_mode;
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)
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;
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)
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));
270 + switch (sel->target) {
271 + case V4L2_SEL_TGT_CROP: {
272 + struct ov9281 *ov9281 = to_ov9281(sd);
274 -static long ov9281_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
276 - struct ov9281 *ov9281 = to_ov9281(sd);
278 + mutex_lock(&ov9281->mutex);
279 + sel->r = *__ov9281_get_pad_crop(ov9281, cfg, sel->pad,
281 + mutex_unlock(&ov9281->mutex);
284 - case RKMODULE_GET_MODULE_INFO:
285 - ov9281_get_module_inf(ov9281, (struct rkmodule_inf *)arg);
288 - ret = -ENOIOCTLCMD;
295 + case V4L2_SEL_TGT_NATIVE_SIZE:
298 + sel->r.width = OV9281_NATIVE_WIDTH;
299 + sel->r.height = OV9281_NATIVE_HEIGHT;
301 -#ifdef CONFIG_COMPAT
302 -static long ov9281_compat_ioctl32(struct v4l2_subdev *sd,
303 - unsigned int cmd, unsigned long arg)
305 - void __user *up = compat_ptr(arg);
306 - struct rkmodule_inf *inf;
307 - struct rkmodule_awb_cfg *cfg;
311 - case RKMODULE_GET_MODULE_INFO:
312 - inf = kzalloc(sizeof(*inf), GFP_KERNEL);
319 - ret = ov9281_ioctl(sd, cmd, inf);
321 - ret = copy_to_user(up, inf, sizeof(*inf));
324 - case RKMODULE_AWB_CFG:
325 - cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
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;
337 - ret = copy_from_user(cfg, up, sizeof(*cfg));
339 - ret = ov9281_ioctl(sd, cmd, cfg);
343 - ret = -ENOIOCTLCMD;
353 static int __ov9281_start_stream(struct ov9281 *ov9281)
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;
359 - ret = ov9281_write_array(ov9281->client, ov9281_global_regs);
361 - v4l2_err(sd, "could not set init registers\n");
362 - pm_runtime_put_noidle(&client->dev);
363 - goto unlock_and_return;
365 ov9281->power_on = true;
367 pm_runtime_put(&client->dev);
368 @@ -673,18 +639,12 @@ static int __ov9281_power_on(struct ov92
370 struct device *dev = &ov9281->client->dev;
372 - if (!IS_ERR_OR_NULL(ov9281->pins_default)) {
373 - ret = pinctrl_select_state(ov9281->pinctrl,
374 - ov9281->pins_default);
376 - dev_err(dev, "could not set pins\n");
379 ret = clk_set_rate(ov9281->xvclk, OV9281_XVCLK_FREQ);
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));
387 ret = clk_prepare_enable(ov9281->xvclk);
389 @@ -722,20 +682,11 @@ disable_clk:
391 static void __ov9281_power_off(struct ov9281 *ov9281)
394 - struct device *dev = &ov9281->client->dev;
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);
405 - dev_dbg(dev, "could not set pins\n");
407 regulator_bulk_disable(OV9281_NUM_SUPPLIES, ov9281->supplies);
410 @@ -759,7 +710,6 @@ static int ov9281_runtime_suspend(struct
414 -#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
415 static int ov9281_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
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);
429 mutex_unlock(&ov9281->mutex);
430 /* No crop or compose */
437 -ov9281_enum_frame_interval(struct v4l2_subdev *sd,
438 - struct v4l2_subdev_pad_config *cfg,
439 - struct v4l2_subdev_frame_interval_enum *fie)
441 - if (fie->index >= ARRAY_SIZE(supported_modes))
444 - if (fie->code != MEDIA_BUS_FMT_Y10_1X10)
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;
453 static const struct dev_pm_ops ov9281_pm_ops = {
454 SET_RUNTIME_PM_OPS(ov9281_runtime_suspend,
455 ov9281_runtime_resume, NULL)
458 -#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
459 static const struct v4l2_subdev_internal_ops ov9281_internal_ops = {
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,
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,
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,
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
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);
504 ov9281->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
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,
511 + V4L2_CID_VBLANK, vblank_def,
512 + OV9281_VTS_MAX - mode->height, 1,
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,
521 + OV9281_EXPOSURE_MIN, exposure_max,
522 + OV9281_EXPOSURE_STEP,
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);
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,
537 + OV9281_GAIN_DEFAULT);
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);
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)
550 struct device *dev = &client->dev;
551 - struct device_node *node = dev->of_node;
552 struct ov9281 *ov9281;
553 struct v4l2_subdev *sd;
557 - dev_info(dev, "driver version: %02x.%02x.%02x",
558 - DRIVER_VERSION >> 16,
559 - (DRIVER_VERSION & 0xff00) >> 8,
560 - DRIVER_VERSION & 0x00ff);
562 ov9281 = devm_kzalloc(dev, sizeof(*ov9281), GFP_KERNEL);
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);
575 - dev_err(dev, "could not get module information!\n");
579 ov9281->client = client;
580 ov9281->cur_mode = &supported_modes[0];
582 @@ -1037,31 +952,15 @@ static int ov9281_probe(struct i2c_clien
586 - ov9281->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
587 + ov9281->reset_gpio = devm_gpiod_get_optional(dev, "reset",
589 if (IS_ERR(ov9281->reset_gpio))
590 dev_warn(dev, "Failed to get reset-gpios\n");
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");
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");
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");
611 - dev_err(dev, "no pinctrl\n");
614 ret = ov9281_configure_regulators(ov9281);
616 dev_err(dev, "Failed to get power regulators\n");
617 @@ -1084,26 +983,16 @@ static int ov9281_probe(struct i2c_clien
621 -#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
622 sd->internal_ops = &ov9281_internal_ops;
623 sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
625 -#if defined(CONFIG_MEDIA_CONTROLLER)
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);
636 - memset(facing, 0, sizeof(facing));
637 - if (strcmp(ov9281->module_facing, "back") == 0)
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_common(sd);
648 @@ -1118,9 +1007,7 @@ static int ov9281_probe(struct i2c_clien
652 -#if defined(CONFIG_MEDIA_CONTROLLER)
653 media_entity_cleanup(&sd->entity);
656 __ov9281_power_off(ov9281);
658 @@ -1137,9 +1024,7 @@ static int ov9281_remove(struct i2c_clie
659 struct ov9281 *ov9281 = to_ov9281(sd);
661 v4l2_async_unregister_subdev(sd);
662 -#if defined(CONFIG_MEDIA_CONTROLLER)
663 media_entity_cleanup(&sd->entity);
665 v4l2_ctrl_handler_free(&ov9281->ctrl_handler);
666 mutex_destroy(&ov9281->mutex);
668 @@ -1151,13 +1036,11 @@ static int ov9281_remove(struct i2c_clie
672 -#if IS_ENABLED(CONFIG_OF)
673 static const struct of_device_id ov9281_of_match[] = {
674 { .compatible = "ovti,ov9281" },
677 MODULE_DEVICE_TABLE(of, ov9281_of_match);
680 static const struct i2c_device_id ov9281_match_id[] = {
681 { "ovti,ov9281", 0 },