b807db513e65c6229f566084c918f24a462e6a47
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.10 / 950-0284-media-i2c-add-ov9281-driver.patch
1 From 63ef88ff48e864eed44d25e6edd61c743e6efd30 Mon Sep 17 00:00:00 2001
2 From: Zefa Chen <zefa.chen@rock-chips.com>
3 Date: Fri, 17 May 2019 18:23:03 +0800
4 Subject: [PATCH] media: i2c: add ov9281 driver.
5
6 Change-Id: I7b77250bbc56d2f861450cf77271ad15f9b88ab1
7 Signed-off-by: Zefa Chen <zefa.chen@rock-chips.com>
8 ---
9 drivers/media/i2c/Kconfig | 11 +
10 drivers/media/i2c/Makefile | 1 +
11 drivers/media/i2c/ov9281.c | 1171 ++++++++++++++++++++++++++++++++++++
12 3 files changed, 1183 insertions(+)
13 create mode 100644 drivers/media/i2c/ov9281.c
14
15 --- a/drivers/media/i2c/Kconfig
16 +++ b/drivers/media/i2c/Kconfig
17 @@ -1040,6 +1040,17 @@ config VIDEO_OV9640
18 This is a Video4Linux2 sensor driver for the OmniVision
19 OV9640 camera sensor.
20
21 +config VIDEO_OV9281
22 + tristate "OmniVision OV9281 sensor support"
23 + depends on I2C && VIDEO_V4L2
24 + depends on MEDIA_CAMERA_SUPPORT
25 + help
26 + This is a Video4Linux2 sensor-level driver for the OmniVision
27 + OV9281 camera.
28 +
29 + To compile this driver as a module, choose M here: the
30 + module will be called ov9281.
31 +
32 config VIDEO_OV9650
33 tristate "OmniVision OV9650/OV9652 sensor support"
34 depends on I2C && VIDEO_V4L2
35 --- a/drivers/media/i2c/Makefile
36 +++ b/drivers/media/i2c/Makefile
37 @@ -81,6 +81,7 @@ obj-$(CONFIG_VIDEO_OV7670) += ov7670.o
38 obj-$(CONFIG_VIDEO_OV772X) += ov772x.o
39 obj-$(CONFIG_VIDEO_OV7740) += ov7740.o
40 obj-$(CONFIG_VIDEO_OV8856) += ov8856.o
41 +obj-$(CONFIG_VIDEO_OV9281) += ov9281.o
42 obj-$(CONFIG_VIDEO_OV9640) += ov9640.o
43 obj-$(CONFIG_VIDEO_OV9650) += ov9650.o
44 obj-$(CONFIG_VIDEO_OV13858) += ov13858.o
45 --- /dev/null
46 +++ b/drivers/media/i2c/ov9281.c
47 @@ -0,0 +1,1171 @@
48 +// SPDX-License-Identifier: GPL-2.0
49 +/*
50 + * ov9281 driver
51 + *
52 + * Copyright (C) 2017 Fuzhou Rockchip Electronics Co., Ltd.
53 + */
54 +
55 +#include <linux/clk.h>
56 +#include <linux/device.h>
57 +#include <linux/delay.h>
58 +#include <linux/gpio/consumer.h>
59 +#include <linux/i2c.h>
60 +#include <linux/module.h>
61 +#include <linux/pm_runtime.h>
62 +#include <linux/regulator/consumer.h>
63 +#include <linux/sysfs.h>
64 +#include <linux/slab.h>
65 +#include <linux/rk-camera-module.h>
66 +#include <media/media-entity.h>
67 +#include <media/v4l2-async.h>
68 +#include <media/v4l2-ctrls.h>
69 +#include <media/v4l2-subdev.h>
70 +#include <linux/pinctrl/consumer.h>
71 +
72 +#define DRIVER_VERSION KERNEL_VERSION(0, 0x01, 0x0)
73 +
74 +#ifndef V4L2_CID_DIGITAL_GAIN
75 +#define V4L2_CID_DIGITAL_GAIN V4L2_CID_GAIN
76 +#endif
77 +
78 +#define OV9281_LINK_FREQ_400MHZ 400000000
79 +/* pixel rate = link frequency * 2 * lanes / BITS_PER_SAMPLE */
80 +#define OV9281_PIXEL_RATE (OV9281_LINK_FREQ_400MHZ * 2 * 2 / 10)
81 +#define OV9281_XVCLK_FREQ 24000000
82 +
83 +#define CHIP_ID 0x9281
84 +#define OV9281_REG_CHIP_ID 0x300a
85 +
86 +#define OV9281_REG_CTRL_MODE 0x0100
87 +#define OV9281_MODE_SW_STANDBY 0x0
88 +#define OV9281_MODE_STREAMING BIT(0)
89 +
90 +#define OV9281_REG_EXPOSURE 0x3500
91 +#define OV9281_EXPOSURE_MIN 4
92 +#define OV9281_EXPOSURE_STEP 1
93 +#define OV9281_VTS_MAX 0x7fff
94 +
95 +#define OV9281_REG_GAIN_H 0x3508
96 +#define OV9281_REG_GAIN_L 0x3509
97 +#define OV9281_GAIN_H_MASK 0x07
98 +#define OV9281_GAIN_H_SHIFT 8
99 +#define OV9281_GAIN_L_MASK 0xff
100 +#define OV9281_GAIN_MIN 0x10
101 +#define OV9281_GAIN_MAX 0xf8
102 +#define OV9281_GAIN_STEP 1
103 +#define OV9281_GAIN_DEFAULT 0x10
104 +
105 +#define OV9281_REG_TEST_PATTERN 0x5e00
106 +#define OV9281_TEST_PATTERN_ENABLE 0x80
107 +#define OV9281_TEST_PATTERN_DISABLE 0x0
108 +
109 +#define OV9281_REG_VTS 0x380e
110 +
111 +#define REG_NULL 0xFFFF
112 +
113 +#define OV9281_REG_VALUE_08BIT 1
114 +#define OV9281_REG_VALUE_16BIT 2
115 +#define OV9281_REG_VALUE_24BIT 3
116 +
117 +#define OV9281_LANES 2
118 +#define OV9281_BITS_PER_SAMPLE 10
119 +
120 +#define OF_CAMERA_PINCTRL_STATE_DEFAULT "rockchip,camera_default"
121 +#define OF_CAMERA_PINCTRL_STATE_SLEEP "rockchip,camera_sleep"
122 +
123 +#define OV9281_NAME "ov9281"
124 +
125 +static const char * const ov9281_supply_names[] = {
126 + "avdd", /* Analog power */
127 + "dovdd", /* Digital I/O power */
128 + "dvdd", /* Digital core power */
129 +};
130 +
131 +#define OV9281_NUM_SUPPLIES ARRAY_SIZE(ov9281_supply_names)
132 +
133 +struct regval {
134 + u16 addr;
135 + u8 val;
136 +};
137 +
138 +struct ov9281_mode {
139 + u32 width;
140 + u32 height;
141 + u32 max_fps;
142 + u32 hts_def;
143 + u32 vts_def;
144 + u32 exp_def;
145 + const struct regval *reg_list;
146 +};
147 +
148 +struct ov9281 {
149 + struct i2c_client *client;
150 + struct clk *xvclk;
151 + struct gpio_desc *reset_gpio;
152 + struct gpio_desc *pwdn_gpio;
153 + struct regulator_bulk_data supplies[OV9281_NUM_SUPPLIES];
154 +
155 + struct pinctrl *pinctrl;
156 + struct pinctrl_state *pins_default;
157 + struct pinctrl_state *pins_sleep;
158 +
159 + struct v4l2_subdev subdev;
160 + struct media_pad pad;
161 + struct v4l2_ctrl_handler ctrl_handler;
162 + struct v4l2_ctrl *exposure;
163 + struct v4l2_ctrl *anal_gain;
164 + struct v4l2_ctrl *digi_gain;
165 + struct v4l2_ctrl *hblank;
166 + struct v4l2_ctrl *vblank;
167 + struct v4l2_ctrl *test_pattern;
168 + struct mutex mutex;
169 + bool streaming;
170 + bool power_on;
171 + const struct ov9281_mode *cur_mode;
172 + u32 module_index;
173 + const char *module_facing;
174 + const char *module_name;
175 + const char *len_name;
176 +};
177 +
178 +#define to_ov9281(sd) container_of(sd, struct ov9281, subdev)
179 +
180 +/*
181 + * Xclk 24Mhz
182 + */
183 +static const struct regval ov9281_global_regs[] = {
184 + {REG_NULL, 0x00},
185 +};
186 +
187 +/*
188 + * Xclk 24Mhz
189 + * max_framerate 120fps
190 + * mipi_datarate per lane 800Mbps
191 + */
192 +static const struct regval ov9281_1280x800_regs[] = {
193 + {0x0103, 0x01},
194 + {0x0302, 0x32},
195 + {0x030d, 0x50},
196 + {0x030e, 0x02},
197 + {0x3001, 0x00},
198 + {0x3004, 0x00},
199 + {0x3005, 0x00},
200 + {0x3006, 0x04},
201 + {0x3011, 0x0a},
202 + {0x3013, 0x18},
203 + {0x3022, 0x01},
204 + {0x3023, 0x00},
205 + {0x302c, 0x00},
206 + {0x302f, 0x00},
207 + {0x3030, 0x04},
208 + {0x3039, 0x32},
209 + {0x303a, 0x00},
210 + {0x303f, 0x01},
211 + {0x3500, 0x00},
212 + {0x3501, 0x2a},
213 + {0x3502, 0x90},
214 + {0x3503, 0x08},
215 + {0x3505, 0x8c},
216 + {0x3507, 0x03},
217 + {0x3508, 0x00},
218 + {0x3509, 0x10},
219 + {0x3610, 0x80},
220 + {0x3611, 0xa0},
221 + {0x3620, 0x6f},
222 + {0x3632, 0x56},
223 + {0x3633, 0x78},
224 + {0x3662, 0x05},
225 + {0x3666, 0x00},
226 + {0x366f, 0x5a},
227 + {0x3680, 0x84},
228 + {0x3712, 0x80},
229 + {0x372d, 0x22},
230 + {0x3731, 0x80},
231 + {0x3732, 0x30},
232 + {0x3778, 0x00},
233 + {0x377d, 0x22},
234 + {0x3788, 0x02},
235 + {0x3789, 0xa4},
236 + {0x378a, 0x00},
237 + {0x378b, 0x4a},
238 + {0x3799, 0x20},
239 + {0x3800, 0x00},
240 + {0x3801, 0x00},
241 + {0x3802, 0x00},
242 + {0x3803, 0x00},
243 + {0x3804, 0x05},
244 + {0x3805, 0x0f},
245 + {0x3806, 0x03},
246 + {0x3807, 0x2f},
247 + {0x3808, 0x05},
248 + {0x3809, 0x00},
249 + {0x380a, 0x03},
250 + {0x380b, 0x20},
251 + {0x380c, 0x02},
252 + {0x380d, 0xd8},
253 + {0x380e, 0x03},
254 + {0x380f, 0x8e},
255 + {0x3810, 0x00},
256 + {0x3811, 0x08},
257 + {0x3812, 0x00},
258 + {0x3813, 0x08},
259 + {0x3814, 0x11},
260 + {0x3815, 0x11},
261 + {0x3820, 0x40},
262 + {0x3821, 0x00},
263 + {0x3881, 0x42},
264 + {0x38b1, 0x00},
265 + {0x3920, 0xff},
266 + {0x4003, 0x40},
267 + {0x4008, 0x04},
268 + {0x4009, 0x0b},
269 + {0x400c, 0x00},
270 + {0x400d, 0x07},
271 + {0x4010, 0x40},
272 + {0x4043, 0x40},
273 + {0x4307, 0x30},
274 + {0x4317, 0x00},
275 + {0x4501, 0x00},
276 + {0x4507, 0x00},
277 + {0x4509, 0x00},
278 + {0x450a, 0x08},
279 + {0x4601, 0x04},
280 + {0x470f, 0x00},
281 + {0x4f07, 0x00},
282 + {0x4800, 0x00},
283 + {0x5000, 0x9f},
284 + {0x5001, 0x00},
285 + {0x5e00, 0x00},
286 + {0x5d00, 0x07},
287 + {0x5d01, 0x00},
288 + {REG_NULL, 0x00},
289 +};
290 +
291 +static const struct ov9281_mode supported_modes[] = {
292 + {
293 + .width = 1280,
294 + .height = 800,
295 + .max_fps = 120,
296 + .exp_def = 0x0320,
297 + .hts_def = 0x0b60,//0x2d8*4
298 + .vts_def = 0x038e,
299 + .reg_list = ov9281_1280x800_regs,
300 + },
301 +};
302 +
303 +static const s64 link_freq_menu_items[] = {
304 + OV9281_LINK_FREQ_400MHZ
305 +};
306 +
307 +static const char * const ov9281_test_pattern_menu[] = {
308 + "Disabled",
309 + "Vertical Color Bar Type 1",
310 + "Vertical Color Bar Type 2",
311 + "Vertical Color Bar Type 3",
312 + "Vertical Color Bar Type 4"
313 +};
314 +
315 +/* Write registers up to 4 at a time */
316 +static int ov9281_write_reg(struct i2c_client *client, u16 reg,
317 + u32 len, u32 val)
318 +{
319 + u32 buf_i, val_i;
320 + u8 buf[6];
321 + u8 *val_p;
322 + __be32 val_be;
323 +
324 + if (len > 4)
325 + return -EINVAL;
326 +
327 + buf[0] = reg >> 8;
328 + buf[1] = reg & 0xff;
329 +
330 + val_be = cpu_to_be32(val);
331 + val_p = (u8 *)&val_be;
332 + buf_i = 2;
333 + val_i = 4 - len;
334 +
335 + while (val_i < 4)
336 + buf[buf_i++] = val_p[val_i++];
337 +
338 + if (i2c_master_send(client, buf, len + 2) != len + 2)
339 + return -EIO;
340 +
341 + return 0;
342 +}
343 +
344 +static int ov9281_write_array(struct i2c_client *client,
345 + const struct regval *regs)
346 +{
347 + u32 i;
348 + int ret = 0;
349 +
350 + for (i = 0; ret == 0 && regs[i].addr != REG_NULL; i++)
351 + ret = ov9281_write_reg(client, regs[i].addr,
352 + OV9281_REG_VALUE_08BIT, regs[i].val);
353 +
354 + return ret;
355 +}
356 +
357 +/* Read registers up to 4 at a time */
358 +static int ov9281_read_reg(struct i2c_client *client, u16 reg, unsigned int len,
359 + u32 *val)
360 +{
361 + struct i2c_msg msgs[2];
362 + u8 *data_be_p;
363 + __be32 data_be = 0;
364 + __be16 reg_addr_be = cpu_to_be16(reg);
365 + int ret;
366 +
367 + if (len > 4 || !len)
368 + return -EINVAL;
369 +
370 + data_be_p = (u8 *)&data_be;
371 + /* Write register address */
372 + msgs[0].addr = client->addr;
373 + msgs[0].flags = 0;
374 + msgs[0].len = 2;
375 + msgs[0].buf = (u8 *)&reg_addr_be;
376 +
377 + /* Read data from register */
378 + msgs[1].addr = client->addr;
379 + msgs[1].flags = I2C_M_RD;
380 + msgs[1].len = len;
381 + msgs[1].buf = &data_be_p[4 - len];
382 +
383 + ret = i2c_transfer(client->adapter, msgs, ARRAY_SIZE(msgs));
384 + if (ret != ARRAY_SIZE(msgs))
385 + return -EIO;
386 +
387 + *val = be32_to_cpu(data_be);
388 +
389 + return 0;
390 +}
391 +
392 +static int ov9281_get_reso_dist(const struct ov9281_mode *mode,
393 + struct v4l2_mbus_framefmt *framefmt)
394 +{
395 + return abs(mode->width - framefmt->width) +
396 + abs(mode->height - framefmt->height);
397 +}
398 +
399 +static const struct ov9281_mode *
400 +ov9281_find_best_fit(struct v4l2_subdev_format *fmt)
401 +{
402 + struct v4l2_mbus_framefmt *framefmt = &fmt->format;
403 + int dist;
404 + int cur_best_fit = 0;
405 + int cur_best_fit_dist = -1;
406 + unsigned int i;
407 +
408 + for (i = 0; i < ARRAY_SIZE(supported_modes); i++) {
409 + dist = ov9281_get_reso_dist(&supported_modes[i], framefmt);
410 + if (cur_best_fit_dist == -1 || dist < cur_best_fit_dist) {
411 + cur_best_fit_dist = dist;
412 + cur_best_fit = i;
413 + }
414 + }
415 +
416 + return &supported_modes[cur_best_fit];
417 +}
418 +
419 +static int ov9281_set_fmt(struct v4l2_subdev *sd,
420 + struct v4l2_subdev_pad_config *cfg,
421 + struct v4l2_subdev_format *fmt)
422 +{
423 + struct ov9281 *ov9281 = to_ov9281(sd);
424 + const struct ov9281_mode *mode;
425 + s64 h_blank, vblank_def;
426 +
427 + mutex_lock(&ov9281->mutex);
428 +
429 + mode = ov9281_find_best_fit(fmt);
430 + fmt->format.code = MEDIA_BUS_FMT_Y10_1X10;
431 + fmt->format.width = mode->width;
432 + fmt->format.height = mode->height;
433 + fmt->format.field = V4L2_FIELD_NONE;
434 + if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
435 +#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
436 + *v4l2_subdev_get_try_format(sd, cfg, fmt->pad) = fmt->format;
437 +#else
438 + mutex_unlock(&ov9281->mutex);
439 + return -ENOTTY;
440 +#endif
441 + } else {
442 + ov9281->cur_mode = mode;
443 + h_blank = mode->hts_def - mode->width;
444 + __v4l2_ctrl_modify_range(ov9281->hblank, h_blank,
445 + h_blank, 1, h_blank);
446 + vblank_def = mode->vts_def - mode->height;
447 + __v4l2_ctrl_modify_range(ov9281->vblank, vblank_def,
448 + OV9281_VTS_MAX - mode->height,
449 + 1, vblank_def);
450 + }
451 +
452 + mutex_unlock(&ov9281->mutex);
453 +
454 + return 0;
455 +}
456 +
457 +static int ov9281_get_fmt(struct v4l2_subdev *sd,
458 + struct v4l2_subdev_pad_config *cfg,
459 + struct v4l2_subdev_format *fmt)
460 +{
461 + struct ov9281 *ov9281 = to_ov9281(sd);
462 + const struct ov9281_mode *mode = ov9281->cur_mode;
463 +
464 + mutex_lock(&ov9281->mutex);
465 + if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
466 +#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
467 + fmt->format = *v4l2_subdev_get_try_format(sd, cfg, fmt->pad);
468 +#else
469 + mutex_unlock(&ov9281->mutex);
470 + return -ENOTTY;
471 +#endif
472 + } else {
473 + fmt->format.width = mode->width;
474 + fmt->format.height = mode->height;
475 + fmt->format.code = MEDIA_BUS_FMT_Y10_1X10;
476 + fmt->format.field = V4L2_FIELD_NONE;
477 + }
478 + mutex_unlock(&ov9281->mutex);
479 +
480 + return 0;
481 +}
482 +
483 +static int ov9281_enum_mbus_code(struct v4l2_subdev *sd,
484 + struct v4l2_subdev_pad_config *cfg,
485 + struct v4l2_subdev_mbus_code_enum *code)
486 +{
487 + if (code->index != 0)
488 + return -EINVAL;
489 + code->code = MEDIA_BUS_FMT_Y10_1X10;
490 +
491 + return 0;
492 +}
493 +
494 +static int ov9281_enum_frame_sizes(struct v4l2_subdev *sd,
495 + struct v4l2_subdev_pad_config *cfg,
496 + struct v4l2_subdev_frame_size_enum *fse)
497 +{
498 + if (fse->index >= ARRAY_SIZE(supported_modes))
499 + return -EINVAL;
500 +
501 + if (fse->code != MEDIA_BUS_FMT_Y10_1X10)
502 + return -EINVAL;
503 +
504 + fse->min_width = supported_modes[fse->index].width;
505 + fse->max_width = supported_modes[fse->index].width;
506 + fse->max_height = supported_modes[fse->index].height;
507 + fse->min_height = supported_modes[fse->index].height;
508 +
509 + return 0;
510 +}
511 +
512 +static int ov9281_enable_test_pattern(struct ov9281 *ov9281, u32 pattern)
513 +{
514 + u32 val;
515 +
516 + if (pattern)
517 + val = (pattern - 1) | OV9281_TEST_PATTERN_ENABLE;
518 + else
519 + val = OV9281_TEST_PATTERN_DISABLE;
520 +
521 + return ov9281_write_reg(ov9281->client, OV9281_REG_TEST_PATTERN,
522 + OV9281_REG_VALUE_08BIT, val);
523 +}
524 +
525 +static int OV9281_g_frame_interval(struct v4l2_subdev *sd,
526 + struct v4l2_subdev_frame_interval *fi)
527 +{
528 + struct ov9281 *ov9281 = to_ov9281(sd);
529 + const struct ov9281_mode *mode = ov9281->cur_mode;
530 +
531 + mutex_lock(&ov9281->mutex);
532 + fi->interval.numerator = 10000;
533 + fi->interval.denominator = mode->max_fps * 10000;
534 + mutex_unlock(&ov9281->mutex);
535 +
536 + return 0;
537 +}
538 +
539 +static void ov9281_get_module_inf(struct ov9281 *ov9281,
540 + struct rkmodule_inf *inf)
541 +{
542 + memset(inf, 0, sizeof(*inf));
543 + strlcpy(inf->base.sensor, OV9281_NAME, sizeof(inf->base.sensor));
544 + strlcpy(inf->base.module, ov9281->module_name,
545 + sizeof(inf->base.module));
546 + strlcpy(inf->base.lens, ov9281->len_name, sizeof(inf->base.lens));
547 +}
548 +
549 +static long ov9281_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
550 +{
551 + struct ov9281 *ov9281 = to_ov9281(sd);
552 + long ret = 0;
553 +
554 + switch (cmd) {
555 + case RKMODULE_GET_MODULE_INFO:
556 + ov9281_get_module_inf(ov9281, (struct rkmodule_inf *)arg);
557 + break;
558 + default:
559 + ret = -ENOIOCTLCMD;
560 + break;
561 + }
562 +
563 + return ret;
564 +}
565 +
566 +#ifdef CONFIG_COMPAT
567 +static long ov9281_compat_ioctl32(struct v4l2_subdev *sd,
568 + unsigned int cmd, unsigned long arg)
569 +{
570 + void __user *up = compat_ptr(arg);
571 + struct rkmodule_inf *inf;
572 + struct rkmodule_awb_cfg *cfg;
573 + long ret;
574 +
575 + switch (cmd) {
576 + case RKMODULE_GET_MODULE_INFO:
577 + inf = kzalloc(sizeof(*inf), GFP_KERNEL);
578 + if (!inf) {
579 + ret = -ENOMEM;
580 + return ret;
581 + }
582 +
583 + ret = ov9281_ioctl(sd, cmd, inf);
584 + if (!ret)
585 + ret = copy_to_user(up, inf, sizeof(*inf));
586 + kfree(inf);
587 + break;
588 + case RKMODULE_AWB_CFG:
589 + cfg = kzalloc(sizeof(*cfg), GFP_KERNEL);
590 + if (!cfg) {
591 + ret = -ENOMEM;
592 + return ret;
593 + }
594 +
595 + ret = copy_from_user(cfg, up, sizeof(*cfg));
596 + if (!ret)
597 + ret = ov9281_ioctl(sd, cmd, cfg);
598 + kfree(cfg);
599 + break;
600 + default:
601 + ret = -ENOIOCTLCMD;
602 + break;
603 + }
604 +
605 + return ret;
606 +}
607 +#endif
608 +
609 +static int __ov9281_start_stream(struct ov9281 *ov9281)
610 +{
611 + int ret;
612 +
613 + ret = ov9281_write_array(ov9281->client, ov9281->cur_mode->reg_list);
614 + if (ret)
615 + return ret;
616 +
617 + /* In case these controls are set before streaming */
618 + mutex_unlock(&ov9281->mutex);
619 + ret = v4l2_ctrl_handler_setup(&ov9281->ctrl_handler);
620 + mutex_lock(&ov9281->mutex);
621 + if (ret)
622 + return ret;
623 +
624 + return ov9281_write_reg(ov9281->client, OV9281_REG_CTRL_MODE,
625 + OV9281_REG_VALUE_08BIT, OV9281_MODE_STREAMING);
626 +}
627 +
628 +static int __ov9281_stop_stream(struct ov9281 *ov9281)
629 +{
630 + return ov9281_write_reg(ov9281->client, OV9281_REG_CTRL_MODE,
631 + OV9281_REG_VALUE_08BIT, OV9281_MODE_SW_STANDBY);
632 +}
633 +
634 +static int ov9281_s_stream(struct v4l2_subdev *sd, int on)
635 +{
636 + struct ov9281 *ov9281 = to_ov9281(sd);
637 + struct i2c_client *client = ov9281->client;
638 + int ret = 0;
639 +
640 + mutex_lock(&ov9281->mutex);
641 + on = !!on;
642 + if (on == ov9281->streaming)
643 + goto unlock_and_return;
644 +
645 + if (on) {
646 + ret = pm_runtime_get_sync(&client->dev);
647 + if (ret < 0) {
648 + pm_runtime_put_noidle(&client->dev);
649 + goto unlock_and_return;
650 + }
651 +
652 + ret = __ov9281_start_stream(ov9281);
653 + if (ret) {
654 + v4l2_err(sd, "start stream failed while write regs\n");
655 + pm_runtime_put(&client->dev);
656 + goto unlock_and_return;
657 + }
658 + } else {
659 + __ov9281_stop_stream(ov9281);
660 + pm_runtime_put(&client->dev);
661 + }
662 +
663 + ov9281->streaming = on;
664 +
665 +unlock_and_return:
666 + mutex_unlock(&ov9281->mutex);
667 +
668 + return ret;
669 +}
670 +
671 +static int ov9281_s_power(struct v4l2_subdev *sd, int on)
672 +{
673 + struct ov9281 *ov9281 = to_ov9281(sd);
674 + struct i2c_client *client = ov9281->client;
675 + int ret = 0;
676 +
677 + mutex_lock(&ov9281->mutex);
678 +
679 + /* If the power state is not modified - no work to do. */
680 + if (ov9281->power_on == !!on)
681 + goto unlock_and_return;
682 +
683 + if (on) {
684 + ret = pm_runtime_get_sync(&client->dev);
685 + if (ret < 0) {
686 + pm_runtime_put_noidle(&client->dev);
687 + goto unlock_and_return;
688 + }
689 + ret = ov9281_write_array(ov9281->client, ov9281_global_regs);
690 + if (ret) {
691 + v4l2_err(sd, "could not set init registers\n");
692 + pm_runtime_put_noidle(&client->dev);
693 + goto unlock_and_return;
694 + }
695 + ov9281->power_on = true;
696 + } else {
697 + pm_runtime_put(&client->dev);
698 + ov9281->power_on = false;
699 + }
700 +
701 +unlock_and_return:
702 + mutex_unlock(&ov9281->mutex);
703 +
704 + return ret;
705 +}
706 +
707 +/* Calculate the delay in us by clock rate and clock cycles */
708 +static inline u32 ov9281_cal_delay(u32 cycles)
709 +{
710 + return DIV_ROUND_UP(cycles, OV9281_XVCLK_FREQ / 1000 / 1000);
711 +}
712 +
713 +static int __ov9281_power_on(struct ov9281 *ov9281)
714 +{
715 + int ret;
716 + u32 delay_us;
717 + struct device *dev = &ov9281->client->dev;
718 +
719 + if (!IS_ERR_OR_NULL(ov9281->pins_default)) {
720 + ret = pinctrl_select_state(ov9281->pinctrl,
721 + ov9281->pins_default);
722 + if (ret < 0)
723 + dev_err(dev, "could not set pins\n");
724 + }
725 +
726 + ret = clk_prepare_enable(ov9281->xvclk);
727 + if (ret < 0) {
728 + dev_err(dev, "Failed to enable xvclk\n");
729 + return ret;
730 + }
731 +
732 + if (!IS_ERR(ov9281->reset_gpio))
733 + gpiod_set_value_cansleep(ov9281->reset_gpio, 0);
734 +
735 + ret = regulator_bulk_enable(OV9281_NUM_SUPPLIES, ov9281->supplies);
736 + if (ret < 0) {
737 + dev_err(dev, "Failed to enable regulators\n");
738 + goto disable_clk;
739 + }
740 +
741 + if (!IS_ERR(ov9281->reset_gpio))
742 + gpiod_set_value_cansleep(ov9281->reset_gpio, 1);
743 +
744 + usleep_range(500, 1000);
745 + if (!IS_ERR(ov9281->pwdn_gpio))
746 + gpiod_set_value_cansleep(ov9281->pwdn_gpio, 1);
747 +
748 + /* 8192 cycles prior to first SCCB transaction */
749 + delay_us = ov9281_cal_delay(8192);
750 + usleep_range(delay_us, delay_us * 2);
751 +
752 + return 0;
753 +
754 +disable_clk:
755 + clk_disable_unprepare(ov9281->xvclk);
756 +
757 + return ret;
758 +}
759 +
760 +static void __ov9281_power_off(struct ov9281 *ov9281)
761 +{
762 + int ret;
763 + struct device *dev = &ov9281->client->dev;
764 +
765 + if (!IS_ERR(ov9281->pwdn_gpio))
766 + gpiod_set_value_cansleep(ov9281->pwdn_gpio, 0);
767 + clk_disable_unprepare(ov9281->xvclk);
768 + if (!IS_ERR(ov9281->reset_gpio))
769 + gpiod_set_value_cansleep(ov9281->reset_gpio, 0);
770 + if (!IS_ERR_OR_NULL(ov9281->pins_sleep)) {
771 + ret = pinctrl_select_state(ov9281->pinctrl,
772 + ov9281->pins_sleep);
773 + if (ret < 0)
774 + dev_dbg(dev, "could not set pins\n");
775 + }
776 + regulator_bulk_disable(OV9281_NUM_SUPPLIES, ov9281->supplies);
777 +}
778 +
779 +static int ov9281_runtime_resume(struct device *dev)
780 +{
781 + struct i2c_client *client = to_i2c_client(dev);
782 + struct v4l2_subdev *sd = i2c_get_clientdata(client);
783 + struct ov9281 *ov9281 = to_ov9281(sd);
784 +
785 + return __ov9281_power_on(ov9281);
786 +}
787 +
788 +static int ov9281_runtime_suspend(struct device *dev)
789 +{
790 + struct i2c_client *client = to_i2c_client(dev);
791 + struct v4l2_subdev *sd = i2c_get_clientdata(client);
792 + struct ov9281 *ov9281 = to_ov9281(sd);
793 +
794 + __ov9281_power_off(ov9281);
795 +
796 + return 0;
797 +}
798 +
799 +#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
800 +static int ov9281_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
801 +{
802 + struct ov9281 *ov9281 = to_ov9281(sd);
803 + struct v4l2_mbus_framefmt *try_fmt =
804 + v4l2_subdev_get_try_format(sd, fh->pad, 0);
805 + const struct ov9281_mode *def_mode = &supported_modes[0];
806 +
807 + mutex_lock(&ov9281->mutex);
808 + /* Initialize try_fmt */
809 + try_fmt->width = def_mode->width;
810 + try_fmt->height = def_mode->height;
811 + try_fmt->code = MEDIA_BUS_FMT_Y10_1X10;
812 + try_fmt->field = V4L2_FIELD_NONE;
813 +
814 + mutex_unlock(&ov9281->mutex);
815 + /* No crop or compose */
816 +
817 + return 0;
818 +}
819 +#endif
820 +
821 +static const struct dev_pm_ops ov9281_pm_ops = {
822 + SET_RUNTIME_PM_OPS(ov9281_runtime_suspend,
823 + ov9281_runtime_resume, NULL)
824 +};
825 +
826 +#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
827 +static const struct v4l2_subdev_internal_ops ov9281_internal_ops = {
828 + .open = ov9281_open,
829 +};
830 +#endif
831 +
832 +static const struct v4l2_subdev_core_ops ov9281_core_ops = {
833 + .s_power = ov9281_s_power,
834 + .ioctl = ov9281_ioctl,
835 +#ifdef CONFIG_COMPAT
836 + .compat_ioctl32 = ov9281_compat_ioctl32,
837 +#endif
838 +};
839 +
840 +static const struct v4l2_subdev_video_ops ov9281_video_ops = {
841 + .s_stream = ov9281_s_stream,
842 + .g_frame_interval = OV9281_g_frame_interval,
843 +};
844 +
845 +static const struct v4l2_subdev_pad_ops ov9281_pad_ops = {
846 + .enum_mbus_code = ov9281_enum_mbus_code,
847 + .enum_frame_size = ov9281_enum_frame_sizes,
848 + .get_fmt = ov9281_get_fmt,
849 + .set_fmt = ov9281_set_fmt,
850 +};
851 +
852 +static const struct v4l2_subdev_ops ov9281_subdev_ops = {
853 + .core = &ov9281_core_ops,
854 + .video = &ov9281_video_ops,
855 + .pad = &ov9281_pad_ops,
856 +};
857 +
858 +static int ov9281_set_ctrl(struct v4l2_ctrl *ctrl)
859 +{
860 + struct ov9281 *ov9281 = container_of(ctrl->handler,
861 + struct ov9281, ctrl_handler);
862 + struct i2c_client *client = ov9281->client;
863 + s64 max;
864 + int ret = 0;
865 +
866 + /* Propagate change of current control to all related controls */
867 + switch (ctrl->id) {
868 + case V4L2_CID_VBLANK:
869 + /* Update max exposure while meeting expected vblanking */
870 + max = ov9281->cur_mode->height + ctrl->val - 4;
871 + __v4l2_ctrl_modify_range(ov9281->exposure,
872 + ov9281->exposure->minimum, max,
873 + ov9281->exposure->step,
874 + ov9281->exposure->default_value);
875 + break;
876 + }
877 +
878 + if (pm_runtime_get(&client->dev) <= 0)
879 + return 0;
880 +
881 + switch (ctrl->id) {
882 + case V4L2_CID_EXPOSURE:
883 + /* 4 least significant bits of expsoure are fractional part */
884 + ret = ov9281_write_reg(ov9281->client, OV9281_REG_EXPOSURE,
885 + OV9281_REG_VALUE_24BIT, ctrl->val << 4);
886 + break;
887 + case V4L2_CID_ANALOGUE_GAIN:
888 + ret = ov9281_write_reg(ov9281->client, OV9281_REG_GAIN_H,
889 + OV9281_REG_VALUE_08BIT,
890 + (ctrl->val >> OV9281_GAIN_H_SHIFT) & OV9281_GAIN_H_MASK);
891 + ret |= ov9281_write_reg(ov9281->client, OV9281_REG_GAIN_L,
892 + OV9281_REG_VALUE_08BIT,
893 + ctrl->val & OV9281_GAIN_L_MASK);
894 + break;
895 + case V4L2_CID_VBLANK:
896 + ret = ov9281_write_reg(ov9281->client, OV9281_REG_VTS,
897 + OV9281_REG_VALUE_16BIT,
898 + ctrl->val + ov9281->cur_mode->height);
899 + break;
900 + case V4L2_CID_TEST_PATTERN:
901 + ret = ov9281_enable_test_pattern(ov9281, ctrl->val);
902 + break;
903 + default:
904 + dev_warn(&client->dev, "%s Unhandled id:0x%x, val:0x%x\n",
905 + __func__, ctrl->id, ctrl->val);
906 + break;
907 + }
908 +
909 + pm_runtime_put(&client->dev);
910 +
911 + return ret;
912 +}
913 +
914 +static const struct v4l2_ctrl_ops ov9281_ctrl_ops = {
915 + .s_ctrl = ov9281_set_ctrl,
916 +};
917 +
918 +static int ov9281_initialize_controls(struct ov9281 *ov9281)
919 +{
920 + const struct ov9281_mode *mode;
921 + struct v4l2_ctrl_handler *handler;
922 + struct v4l2_ctrl *ctrl;
923 + s64 exposure_max, vblank_def;
924 + u32 h_blank;
925 + int ret;
926 +
927 + handler = &ov9281->ctrl_handler;
928 + mode = ov9281->cur_mode;
929 + ret = v4l2_ctrl_handler_init(handler, 8);
930 + if (ret)
931 + return ret;
932 + handler->lock = &ov9281->mutex;
933 +
934 + ctrl = v4l2_ctrl_new_int_menu(handler, NULL, V4L2_CID_LINK_FREQ,
935 + 0, 0, link_freq_menu_items);
936 + if (ctrl)
937 + ctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
938 +
939 + v4l2_ctrl_new_std(handler, NULL, V4L2_CID_PIXEL_RATE,
940 + 0, OV9281_PIXEL_RATE, 1, OV9281_PIXEL_RATE);
941 +
942 + h_blank = mode->hts_def - mode->width;
943 + ov9281->hblank = v4l2_ctrl_new_std(handler, NULL, V4L2_CID_HBLANK,
944 + h_blank, h_blank, 1, h_blank);
945 + if (ov9281->hblank)
946 + ov9281->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
947 +
948 + vblank_def = mode->vts_def - mode->height;
949 + ov9281->vblank = v4l2_ctrl_new_std(handler, &ov9281_ctrl_ops,
950 + V4L2_CID_VBLANK, vblank_def,
951 + OV9281_VTS_MAX - mode->height,
952 + 1, vblank_def);
953 +
954 + exposure_max = mode->vts_def - 4;
955 + ov9281->exposure = v4l2_ctrl_new_std(handler, &ov9281_ctrl_ops,
956 + V4L2_CID_EXPOSURE, OV9281_EXPOSURE_MIN,
957 + exposure_max, OV9281_EXPOSURE_STEP,
958 + mode->exp_def);
959 +
960 + ov9281->anal_gain = v4l2_ctrl_new_std(handler, &ov9281_ctrl_ops,
961 + V4L2_CID_ANALOGUE_GAIN, OV9281_GAIN_MIN,
962 + OV9281_GAIN_MAX, OV9281_GAIN_STEP,
963 + OV9281_GAIN_DEFAULT);
964 +
965 + ov9281->test_pattern = v4l2_ctrl_new_std_menu_items(handler,
966 + &ov9281_ctrl_ops, V4L2_CID_TEST_PATTERN,
967 + ARRAY_SIZE(ov9281_test_pattern_menu) - 1,
968 + 0, 0, ov9281_test_pattern_menu);
969 +
970 + if (handler->error) {
971 + ret = handler->error;
972 + dev_err(&ov9281->client->dev,
973 + "Failed to init controls(%d)\n", ret);
974 + goto err_free_handler;
975 + }
976 +
977 + ov9281->subdev.ctrl_handler = handler;
978 +
979 + return 0;
980 +
981 +err_free_handler:
982 + v4l2_ctrl_handler_free(handler);
983 +
984 + return ret;
985 +}
986 +
987 +static int ov9281_check_sensor_id(struct ov9281 *ov9281,
988 + struct i2c_client *client)
989 +{
990 + struct device *dev = &ov9281->client->dev;
991 + u32 id = 0;
992 + int ret;
993 +
994 + ret = ov9281_read_reg(client, OV9281_REG_CHIP_ID,
995 + OV9281_REG_VALUE_16BIT, &id);
996 + if (id != CHIP_ID) {
997 + dev_err(dev, "Unexpected sensor id(%06x), ret(%d)\n", id, ret);
998 + return -ENODEV;
999 + }
1000 +
1001 + dev_info(dev, "Detected OV%06x sensor\n", CHIP_ID);
1002 +
1003 + return 0;
1004 +}
1005 +
1006 +static int ov9281_configure_regulators(struct ov9281 *ov9281)
1007 +{
1008 + unsigned int i;
1009 +
1010 + for (i = 0; i < OV9281_NUM_SUPPLIES; i++)
1011 + ov9281->supplies[i].supply = ov9281_supply_names[i];
1012 +
1013 + return devm_regulator_bulk_get(&ov9281->client->dev,
1014 + OV9281_NUM_SUPPLIES,
1015 + ov9281->supplies);
1016 +}
1017 +
1018 +static int ov9281_probe(struct i2c_client *client,
1019 + const struct i2c_device_id *id)
1020 +{
1021 + struct device *dev = &client->dev;
1022 + struct device_node *node = dev->of_node;
1023 + struct ov9281 *ov9281;
1024 + struct v4l2_subdev *sd;
1025 + char facing[2];
1026 + int ret;
1027 +
1028 + dev_info(dev, "driver version: %02x.%02x.%02x",
1029 + DRIVER_VERSION >> 16,
1030 + (DRIVER_VERSION & 0xff00) >> 8,
1031 + DRIVER_VERSION & 0x00ff);
1032 +
1033 + ov9281 = devm_kzalloc(dev, sizeof(*ov9281), GFP_KERNEL);
1034 + if (!ov9281)
1035 + return -ENOMEM;
1036 +
1037 + ret = of_property_read_u32(node, RKMODULE_CAMERA_MODULE_INDEX,
1038 + &ov9281->module_index);
1039 + ret |= of_property_read_string(node, RKMODULE_CAMERA_MODULE_FACING,
1040 + &ov9281->module_facing);
1041 + ret |= of_property_read_string(node, RKMODULE_CAMERA_MODULE_NAME,
1042 + &ov9281->module_name);
1043 + ret |= of_property_read_string(node, RKMODULE_CAMERA_LENS_NAME,
1044 + &ov9281->len_name);
1045 + if (ret) {
1046 + dev_err(dev, "could not get module information!\n");
1047 + return -EINVAL;
1048 + }
1049 +
1050 + ov9281->client = client;
1051 + ov9281->cur_mode = &supported_modes[0];
1052 +
1053 + ov9281->xvclk = devm_clk_get(dev, "xvclk");
1054 + if (IS_ERR(ov9281->xvclk)) {
1055 + dev_err(dev, "Failed to get xvclk\n");
1056 + return -EINVAL;
1057 + }
1058 + ret = clk_set_rate(ov9281->xvclk, OV9281_XVCLK_FREQ);
1059 + if (ret < 0) {
1060 + dev_err(dev, "Failed to set xvclk rate (24MHz)\n");
1061 + return ret;
1062 + }
1063 + if (clk_get_rate(ov9281->xvclk) != OV9281_XVCLK_FREQ)
1064 + dev_warn(dev, "xvclk mismatched, modes are based on 24MHz\n");
1065 +
1066 + ov9281->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_LOW);
1067 + if (IS_ERR(ov9281->reset_gpio))
1068 + dev_warn(dev, "Failed to get reset-gpios\n");
1069 +
1070 + ov9281->pwdn_gpio = devm_gpiod_get(dev, "pwdn", GPIOD_OUT_LOW);
1071 + if (IS_ERR(ov9281->pwdn_gpio))
1072 + dev_warn(dev, "Failed to get pwdn-gpios\n");
1073 +
1074 + ov9281->pinctrl = devm_pinctrl_get(dev);
1075 + if (!IS_ERR(ov9281->pinctrl)) {
1076 + ov9281->pins_default =
1077 + pinctrl_lookup_state(ov9281->pinctrl,
1078 + OF_CAMERA_PINCTRL_STATE_DEFAULT);
1079 + if (IS_ERR(ov9281->pins_default))
1080 + dev_err(dev, "could not get default pinstate\n");
1081 +
1082 + ov9281->pins_sleep =
1083 + pinctrl_lookup_state(ov9281->pinctrl,
1084 + OF_CAMERA_PINCTRL_STATE_SLEEP);
1085 + if (IS_ERR(ov9281->pins_sleep))
1086 + dev_err(dev, "could not get sleep pinstate\n");
1087 + } else {
1088 + dev_err(dev, "no pinctrl\n");
1089 + }
1090 +
1091 + ret = ov9281_configure_regulators(ov9281);
1092 + if (ret) {
1093 + dev_err(dev, "Failed to get power regulators\n");
1094 + return ret;
1095 + }
1096 +
1097 + mutex_init(&ov9281->mutex);
1098 +
1099 + sd = &ov9281->subdev;
1100 + v4l2_i2c_subdev_init(sd, client, &ov9281_subdev_ops);
1101 + ret = ov9281_initialize_controls(ov9281);
1102 + if (ret)
1103 + goto err_destroy_mutex;
1104 +
1105 + ret = __ov9281_power_on(ov9281);
1106 + if (ret)
1107 + goto err_free_handler;
1108 +
1109 + ret = ov9281_check_sensor_id(ov9281, client);
1110 + if (ret)
1111 + goto err_power_off;
1112 +
1113 +#ifdef CONFIG_VIDEO_V4L2_SUBDEV_API
1114 + sd->internal_ops = &ov9281_internal_ops;
1115 + sd->flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1116 +#endif
1117 +#if defined(CONFIG_MEDIA_CONTROLLER)
1118 + ov9281->pad.flags = MEDIA_PAD_FL_SOURCE;
1119 + sd->entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;
1120 + ret = media_entity_init(&sd->entity, 1, &ov9281->pad, 0);
1121 + if (ret < 0)
1122 + goto err_power_off;
1123 +#endif
1124 +
1125 + memset(facing, 0, sizeof(facing));
1126 + if (strcmp(ov9281->module_facing, "back") == 0)
1127 + facing[0] = 'b';
1128 + else
1129 + facing[0] = 'f';
1130 +
1131 + snprintf(sd->name, sizeof(sd->name), "m%02d_%s_%s %s",
1132 + ov9281->module_index, facing,
1133 + OV9281_NAME, dev_name(sd->dev));
1134 + ret = v4l2_async_register_subdev_sensor_common(sd);
1135 + if (ret) {
1136 + dev_err(dev, "v4l2 async register subdev failed\n");
1137 + goto err_clean_entity;
1138 + }
1139 +
1140 + pm_runtime_set_active(dev);
1141 + pm_runtime_enable(dev);
1142 + pm_runtime_idle(dev);
1143 +
1144 + return 0;
1145 +
1146 +err_clean_entity:
1147 +#if defined(CONFIG_MEDIA_CONTROLLER)
1148 + media_entity_cleanup(&sd->entity);
1149 +#endif
1150 +err_power_off:
1151 + __ov9281_power_off(ov9281);
1152 +err_free_handler:
1153 + v4l2_ctrl_handler_free(&ov9281->ctrl_handler);
1154 +err_destroy_mutex:
1155 + mutex_destroy(&ov9281->mutex);
1156 +
1157 + return ret;
1158 +}
1159 +
1160 +static int ov9281_remove(struct i2c_client *client)
1161 +{
1162 + struct v4l2_subdev *sd = i2c_get_clientdata(client);
1163 + struct ov9281 *ov9281 = to_ov9281(sd);
1164 +
1165 + v4l2_async_unregister_subdev(sd);
1166 +#if defined(CONFIG_MEDIA_CONTROLLER)
1167 + media_entity_cleanup(&sd->entity);
1168 +#endif
1169 + v4l2_ctrl_handler_free(&ov9281->ctrl_handler);
1170 + mutex_destroy(&ov9281->mutex);
1171 +
1172 + pm_runtime_disable(&client->dev);
1173 + if (!pm_runtime_status_suspended(&client->dev))
1174 + __ov9281_power_off(ov9281);
1175 + pm_runtime_set_suspended(&client->dev);
1176 +
1177 + return 0;
1178 +}
1179 +
1180 +#if IS_ENABLED(CONFIG_OF)
1181 +static const struct of_device_id ov9281_of_match[] = {
1182 + { .compatible = "ovti,ov9281" },
1183 + {},
1184 +};
1185 +MODULE_DEVICE_TABLE(of, ov9281_of_match);
1186 +#endif
1187 +
1188 +static const struct i2c_device_id ov9281_match_id[] = {
1189 + { "ovti,ov9281", 0 },
1190 + { },
1191 +};
1192 +
1193 +static struct i2c_driver ov9281_i2c_driver = {
1194 + .driver = {
1195 + .name = OV9281_NAME,
1196 + .pm = &ov9281_pm_ops,
1197 + .of_match_table = of_match_ptr(ov9281_of_match),
1198 + },
1199 + .probe = &ov9281_probe,
1200 + .remove = &ov9281_remove,
1201 + .id_table = ov9281_match_id,
1202 +};
1203 +
1204 +static int __init sensor_mod_init(void)
1205 +{
1206 + return i2c_add_driver(&ov9281_i2c_driver);
1207 +}
1208 +
1209 +static void __exit sensor_mod_exit(void)
1210 +{
1211 + i2c_del_driver(&ov9281_i2c_driver);
1212 +}
1213 +
1214 +device_initcall_sync(sensor_mod_init);
1215 +module_exit(sensor_mod_exit);
1216 +
1217 +MODULE_DESCRIPTION("OmniVision ov9281 sensor driver");
1218 +MODULE_LICENSE("GPL v2");