]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/staging/media/atomisp/i2c/ov5693/atomisp-ov5693.c
media: staging: atomisp: Remove FSF snail address
[mirror_ubuntu-bionic-kernel.git] / drivers / staging / media / atomisp / i2c / ov5693 / atomisp-ov5693.c
CommitLineData
a49d2536
AC
1/*
2 * Support for OmniVision OV5693 1080p HD camera sensor.
3 *
4 * Copyright (c) 2013 Intel Corporation. All Rights Reserved.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License version
8 * 2 as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
a49d2536
AC
15 *
16 */
17
18#include <linux/module.h>
19#include <linux/types.h>
20#include <linux/kernel.h>
21#include <linux/mm.h>
22#include <linux/string.h>
23#include <linux/errno.h>
24#include <linux/init.h>
25#include <linux/kmod.h>
26#include <linux/device.h>
27#include <linux/delay.h>
28#include <linux/slab.h>
29#include <linux/i2c.h>
a49d2536
AC
30#include <linux/moduleparam.h>
31#include <media/v4l2-device.h>
32#include <linux/io.h>
33#include <linux/acpi.h>
25016567 34#include "../../include/linux/atomisp_gmin_platform.h"
a49d2536
AC
35
36#include "ov5693.h"
37#include "ad5823.h"
38
39#define __cci_delay(t) \
40 do { \
41 if ((t) < 10) { \
42 usleep_range((t) * 1000, ((t) + 1) * 1000); \
43 } else { \
44 msleep((t)); \
45 } \
46 } while (0)
47
48/* Value 30ms reached through experimentation on byt ecs.
49 * The DS specifies a much lower value but when using a smaller value
50 * the I2C bus sometimes locks up permanently when starting the camera.
51 * This issue could not be reproduced on cht, so we can reduce the
52 * delay value to a lower value when insmod.
53 */
54static uint up_delay = 30;
55module_param(up_delay, uint, 0644);
56MODULE_PARM_DESC(up_delay, "Delay prior to the first CCI transaction for ov5693");
57
58static int vcm_ad_i2c_wr8(struct i2c_client *client, u8 reg, u8 val)
59{
60 int err;
61 struct i2c_msg msg;
62 u8 buf[2];
63
64 buf[0] = reg;
65 buf[1] = val;
66
67 msg.addr = VCM_ADDR;
68 msg.flags = 0;
69 msg.len = 2;
70 msg.buf = &buf[0];
71
72 err = i2c_transfer(client->adapter, &msg, 1);
73 if (err != 1) {
74 dev_err(&client->dev, "%s: vcm i2c fail, err code = %d\n",
75 __func__, err);
76 return -EIO;
77 }
78 return 0;
79}
a49d2536 80
a49d2536
AC
81static int ad5823_i2c_write(struct i2c_client *client, u8 reg, u8 val)
82{
83 struct i2c_msg msg;
84 u8 buf[2];
85 buf[0] = reg;
86 buf[1] = val;
87 msg.addr = AD5823_VCM_ADDR;
88 msg.flags = 0;
89 msg.len = 0x02;
90 msg.buf = &buf[0];
91
92 if (i2c_transfer(client->adapter, &msg, 1) != 1)
93 return -EIO;
94 return 0;
95}
96
97static int ad5823_i2c_read(struct i2c_client *client, u8 reg, u8 *val)
98{
99 struct i2c_msg msg[2];
100 u8 buf[2];
101 buf[0] = reg;
102 buf[1] = 0;
103
104 msg[0].addr = AD5823_VCM_ADDR;
105 msg[0].flags = 0;
106 msg[0].len = 0x01;
107 msg[0].buf = &buf[0];
108
109 msg[1].addr = 0x0c;
110 msg[1].flags = I2C_M_RD;
111 msg[1].len = 0x01;
112 msg[1].buf = &buf[1];
113 *val = 0;
114 if (i2c_transfer(client->adapter, msg, 2) != 2)
115 return -EIO;
116 *val = buf[1];
117 return 0;
118}
119
120
121static const uint32_t ov5693_embedded_effective_size = 28;
122
123/* i2c read/write stuff */
124static int ov5693_read_reg(struct i2c_client *client,
125 u16 data_length, u16 reg, u16 *val)
126{
127 int err;
128 struct i2c_msg msg[2];
129 unsigned char data[6];
130
131 if (!client->adapter) {
132 dev_err(&client->dev, "%s error, no client->adapter\n",
133 __func__);
134 return -ENODEV;
135 }
136
137 if (data_length != OV5693_8BIT && data_length != OV5693_16BIT
138 && data_length != OV5693_32BIT) {
139 dev_err(&client->dev, "%s error, invalid data length\n",
140 __func__);
141 return -EINVAL;
142 }
143
14c23a51 144 memset(msg, 0, sizeof(msg));
a49d2536
AC
145
146 msg[0].addr = client->addr;
147 msg[0].flags = 0;
148 msg[0].len = I2C_MSG_LENGTH;
149 msg[0].buf = data;
150
151 /* high byte goes out first */
152 data[0] = (u8)(reg >> 8);
153 data[1] = (u8)(reg & 0xff);
154
155 msg[1].addr = client->addr;
156 msg[1].len = data_length;
157 msg[1].flags = I2C_M_RD;
158 msg[1].buf = data;
159
160 err = i2c_transfer(client->adapter, msg, 2);
161 if (err != 2) {
162 if (err >= 0)
163 err = -EIO;
164 dev_err(&client->dev,
165 "read from offset 0x%x error %d", reg, err);
166 return err;
167 }
168
169 *val = 0;
170 /* high byte comes first */
171 if (data_length == OV5693_8BIT)
172 *val = (u8)data[0];
173 else if (data_length == OV5693_16BIT)
174 *val = be16_to_cpu(*(u16 *)&data[0]);
175 else
176 *val = be32_to_cpu(*(u32 *)&data[0]);
177
178 return 0;
179}
180
181static int ov5693_i2c_write(struct i2c_client *client, u16 len, u8 *data)
182{
183 struct i2c_msg msg;
184 const int num_msg = 1;
185 int ret;
186
187 msg.addr = client->addr;
188 msg.flags = 0;
189 msg.len = len;
190 msg.buf = data;
191 ret = i2c_transfer(client->adapter, &msg, 1);
192
193 return ret == num_msg ? 0 : -EIO;
194}
195
196static int vcm_dw_i2c_write(struct i2c_client *client, u16 data)
197{
198 struct i2c_msg msg;
199 const int num_msg = 1;
200 int ret;
201 u16 val;
202
203 val = cpu_to_be16(data);
204 msg.addr = VCM_ADDR;
205 msg.flags = 0;
206 msg.len = OV5693_16BIT;
207 msg.buf = (u8 *)&val;
208
209 ret = i2c_transfer(client->adapter, &msg, 1);
210
211 return ret == num_msg ? 0 : -EIO;
212}
213
214/* Theory: per datasheet, the two VCMs both allow for a 2-byte read.
215 * The DW9714 doesn't actually specify what this does (it has a
216 * two-byte write-only protocol, but specifies the read sequence as
217 * legal), but it returns the same data (zeroes) always, after an
218 * undocumented initial NAK. The AD5823 has a one-byte address
219 * register to which all writes go, and subsequent reads will cycle
220 * through the 8 bytes of registers. Notably, the default values (the
221 * device is always power-cycled affirmatively, so we can rely on
222 * these) in AD5823 are not pairwise repetitions of the same 16 bit
223 * word. So all we have to do is sequentially read two bytes at a
224 * time and see if we detect a difference in any of the first four
225 * pairs. */
226static int vcm_detect(struct i2c_client *client)
227{
228 int i, ret;
229 struct i2c_msg msg;
230 u16 data0 = 0, data;
231 for (i = 0; i < 4; i++) {
232 msg.addr = VCM_ADDR;
233 msg.flags = I2C_M_RD;
234 msg.len = sizeof(data);
235 msg.buf = (u8 *)&data;
236 ret = i2c_transfer(client->adapter, &msg, 1);
237
238 /* DW9714 always fails the first read and returns
239 * zeroes for subsequent ones */
240 if (i == 0 && ret == -EREMOTEIO) {
241 data0 = 0;
242 continue;
243 }
244
245 if (i == 0)
246 data0 = data;
247
248 if (data != data0)
249 return VCM_AD5823;
250 }
251 return ret == 1 ? VCM_DW9714 : ret;
252}
253
254static int ov5693_write_reg(struct i2c_client *client, u16 data_length,
255 u16 reg, u16 val)
256{
257 int ret;
258 unsigned char data[4] = {0};
259 u16 *wreg = (u16 *)data;
260 const u16 len = data_length + sizeof(u16); /* 16-bit address + data */
261
262 if (data_length != OV5693_8BIT && data_length != OV5693_16BIT) {
263 dev_err(&client->dev,
264 "%s error, invalid data_length\n", __func__);
265 return -EINVAL;
266 }
267
268 /* high byte goes out first */
269 *wreg = cpu_to_be16(reg);
270
271 if (data_length == OV5693_8BIT) {
272 data[2] = (u8)(val);
273 } else {
274 /* OV5693_16BIT */
275 u16 *wdata = (u16 *)&data[2];
276 *wdata = cpu_to_be16(val);
277 }
278
279 ret = ov5693_i2c_write(client, len, data);
280 if (ret)
281 dev_err(&client->dev,
282 "write error: wrote 0x%x to offset 0x%x error %d",
283 val, reg, ret);
284
285 return ret;
286}
287
288/*
289 * ov5693_write_reg_array - Initializes a list of OV5693 registers
290 * @client: i2c driver client structure
291 * @reglist: list of registers to be written
292 *
293 * This function initializes a list of registers. When consecutive addresses
294 * are found in a row on the list, this function creates a buffer and sends
295 * consecutive data in a single i2c_transfer().
296 *
297 * __ov5693_flush_reg_array, __ov5693_buf_reg_array() and
298 * __ov5693_write_reg_is_consecutive() are internal functions to
299 * ov5693_write_reg_array_fast() and should be not used anywhere else.
300 *
301 */
302
303static int __ov5693_flush_reg_array(struct i2c_client *client,
304 struct ov5693_write_ctrl *ctrl)
305{
306 u16 size;
307
308 if (ctrl->index == 0)
309 return 0;
310
311 size = sizeof(u16) + ctrl->index; /* 16-bit address + data */
312 ctrl->buffer.addr = cpu_to_be16(ctrl->buffer.addr);
313 ctrl->index = 0;
314
315 return ov5693_i2c_write(client, size, (u8 *)&ctrl->buffer);
316}
317
318static int __ov5693_buf_reg_array(struct i2c_client *client,
319 struct ov5693_write_ctrl *ctrl,
320 const struct ov5693_reg *next)
321{
322 int size;
323 u16 *data16;
324
325 switch (next->type) {
326 case OV5693_8BIT:
327 size = 1;
328 ctrl->buffer.data[ctrl->index] = (u8)next->val;
329 break;
330 case OV5693_16BIT:
331 size = 2;
332 data16 = (u16 *)&ctrl->buffer.data[ctrl->index];
333 *data16 = cpu_to_be16((u16)next->val);
334 break;
335 default:
336 return -EINVAL;
337 }
338
339 /* When first item is added, we need to store its starting address */
340 if (ctrl->index == 0)
341 ctrl->buffer.addr = next->reg;
342
343 ctrl->index += size;
344
345 /*
346 * Buffer cannot guarantee free space for u32? Better flush it to avoid
347 * possible lack of memory for next item.
348 */
349 if (ctrl->index + sizeof(u16) >= OV5693_MAX_WRITE_BUF_SIZE)
350 return __ov5693_flush_reg_array(client, ctrl);
351
352 return 0;
353}
354
355static int __ov5693_write_reg_is_consecutive(struct i2c_client *client,
356 struct ov5693_write_ctrl *ctrl,
357 const struct ov5693_reg *next)
358{
359 if (ctrl->index == 0)
360 return 1;
361
362 return ctrl->buffer.addr + ctrl->index == next->reg;
363}
364
365static int ov5693_write_reg_array(struct i2c_client *client,
366 const struct ov5693_reg *reglist)
367{
368 const struct ov5693_reg *next = reglist;
369 struct ov5693_write_ctrl ctrl;
370 int err;
371
372 ctrl.index = 0;
373 for (; next->type != OV5693_TOK_TERM; next++) {
374 switch (next->type & OV5693_TOK_MASK) {
375 case OV5693_TOK_DELAY:
376 err = __ov5693_flush_reg_array(client, &ctrl);
377 if (err)
378 return err;
379 msleep(next->val);
380 break;
381 default:
382 /*
383 * If next address is not consecutive, data needs to be
384 * flushed before proceed.
385 */
386 if (!__ov5693_write_reg_is_consecutive(client, &ctrl,
387 next)) {
388 err = __ov5693_flush_reg_array(client, &ctrl);
389 if (err)
390 return err;
391 }
392 err = __ov5693_buf_reg_array(client, &ctrl, next);
393 if (err) {
394 dev_err(&client->dev,
395 "%s: write error, aborted\n",
396 __func__);
397 return err;
398 }
399 break;
400 }
401 }
402
403 return __ov5693_flush_reg_array(client, &ctrl);
404}
405static int ov5693_g_focal(struct v4l2_subdev *sd, s32 *val)
406{
407 *val = (OV5693_FOCAL_LENGTH_NUM << 16) | OV5693_FOCAL_LENGTH_DEM;
408 return 0;
409}
410
411static int ov5693_g_fnumber(struct v4l2_subdev *sd, s32 *val)
412{
413 /*const f number for imx*/
414 *val = (OV5693_F_NUMBER_DEFAULT_NUM << 16) | OV5693_F_NUMBER_DEM;
415 return 0;
416}
417
418static int ov5693_g_fnumber_range(struct v4l2_subdev *sd, s32 *val)
419{
420 *val = (OV5693_F_NUMBER_DEFAULT_NUM << 24) |
421 (OV5693_F_NUMBER_DEM << 16) |
422 (OV5693_F_NUMBER_DEFAULT_NUM << 8) | OV5693_F_NUMBER_DEM;
423 return 0;
424}
425
426static int ov5693_g_bin_factor_x(struct v4l2_subdev *sd, s32 *val)
427{
428 struct ov5693_device *dev = to_ov5693_sensor(sd);
429
430 *val = ov5693_res[dev->fmt_idx].bin_factor_x;
431
432 return 0;
433}
434
435static int ov5693_g_bin_factor_y(struct v4l2_subdev *sd, s32 *val)
436{
437 struct ov5693_device *dev = to_ov5693_sensor(sd);
438
439 *val = ov5693_res[dev->fmt_idx].bin_factor_y;
440
441 return 0;
442}
443
444static int ov5693_get_intg_factor(struct i2c_client *client,
445 struct camera_mipi_info *info,
446 const struct ov5693_resolution *res)
447{
448 struct v4l2_subdev *sd = i2c_get_clientdata(client);
449 struct ov5693_device *dev = to_ov5693_sensor(sd);
450 struct atomisp_sensor_mode_data *buf = &info->data;
451 unsigned int pix_clk_freq_hz;
452 u16 reg_val;
453 int ret;
454
455 if (info == NULL)
456 return -EINVAL;
457
458 /* pixel clock */
459 pix_clk_freq_hz = res->pix_clk_freq * 1000000;
460
461 dev->vt_pix_clk_freq_mhz = pix_clk_freq_hz;
462 buf->vt_pix_clk_freq_mhz = pix_clk_freq_hz;
463
464 /* get integration time */
465 buf->coarse_integration_time_min = OV5693_COARSE_INTG_TIME_MIN;
466 buf->coarse_integration_time_max_margin =
467 OV5693_COARSE_INTG_TIME_MAX_MARGIN;
468
469 buf->fine_integration_time_min = OV5693_FINE_INTG_TIME_MIN;
470 buf->fine_integration_time_max_margin =
471 OV5693_FINE_INTG_TIME_MAX_MARGIN;
472
473 buf->fine_integration_time_def = OV5693_FINE_INTG_TIME_MIN;
474 buf->frame_length_lines = res->lines_per_frame;
475 buf->line_length_pck = res->pixels_per_line;
476 buf->read_mode = res->bin_mode;
477
478 /* get the cropping and output resolution to ISP for this mode. */
479 ret = ov5693_read_reg(client, OV5693_16BIT,
480 OV5693_HORIZONTAL_START_H, &reg_val);
481 if (ret)
482 return ret;
483 buf->crop_horizontal_start = reg_val;
484
485 ret = ov5693_read_reg(client, OV5693_16BIT,
486 OV5693_VERTICAL_START_H, &reg_val);
487 if (ret)
488 return ret;
489 buf->crop_vertical_start = reg_val;
490
491 ret = ov5693_read_reg(client, OV5693_16BIT,
492 OV5693_HORIZONTAL_END_H, &reg_val);
493 if (ret)
494 return ret;
495 buf->crop_horizontal_end = reg_val;
496
497 ret = ov5693_read_reg(client, OV5693_16BIT,
498 OV5693_VERTICAL_END_H, &reg_val);
499 if (ret)
500 return ret;
501 buf->crop_vertical_end = reg_val;
502
503 ret = ov5693_read_reg(client, OV5693_16BIT,
504 OV5693_HORIZONTAL_OUTPUT_SIZE_H, &reg_val);
505 if (ret)
506 return ret;
507 buf->output_width = reg_val;
508
509 ret = ov5693_read_reg(client, OV5693_16BIT,
510 OV5693_VERTICAL_OUTPUT_SIZE_H, &reg_val);
511 if (ret)
512 return ret;
513 buf->output_height = reg_val;
514
515 buf->binning_factor_x = res->bin_factor_x ?
516 res->bin_factor_x : 1;
517 buf->binning_factor_y = res->bin_factor_y ?
518 res->bin_factor_y : 1;
519 return 0;
520}
521
522static long __ov5693_set_exposure(struct v4l2_subdev *sd, int coarse_itg,
523 int gain, int digitgain)
524
525{
526 struct i2c_client *client = v4l2_get_subdevdata(sd);
527 struct ov5693_device *dev = to_ov5693_sensor(sd);
528 u16 vts, hts;
529 int ret, exp_val;
530
531 hts = ov5693_res[dev->fmt_idx].pixels_per_line;
532 vts = ov5693_res[dev->fmt_idx].lines_per_frame;
533 /*If coarse_itg is larger than 1<<15, can not write to reg directly.
534 The way is to write coarse_itg/2 to the reg, meanwhile write 2*hts
535 to the reg. */
536 if (coarse_itg > (1 << 15)) {
537 hts = hts * 2;
538 coarse_itg = (int)coarse_itg / 2;
539 }
540 /* group hold */
541 ret = ov5693_write_reg(client, OV5693_8BIT,
542 OV5693_GROUP_ACCESS, 0x00);
543 if (ret) {
544 dev_err(&client->dev, "%s: write %x error, aborted\n",
545 __func__, OV5693_GROUP_ACCESS);
546 return ret;
547 }
548
549 ret = ov5693_write_reg(client, OV5693_8BIT,
550 OV5693_TIMING_HTS_H, (hts >> 8) & 0xFF);
551 if (ret) {
552 dev_err(&client->dev, "%s: write %x error, aborted\n",
553 __func__, OV5693_TIMING_HTS_H);
554 return ret;
555 }
556
557 ret = ov5693_write_reg(client, OV5693_8BIT,
558 OV5693_TIMING_HTS_L, hts & 0xFF);
559 if (ret) {
560 dev_err(&client->dev, "%s: write %x error, aborted\n",
561 __func__, OV5693_TIMING_HTS_L);
562 return ret;
563 }
564 /* Increase the VTS to match exposure + MARGIN */
565 if (coarse_itg > vts - OV5693_INTEGRATION_TIME_MARGIN)
566 vts = (u16) coarse_itg + OV5693_INTEGRATION_TIME_MARGIN;
567
568 ret = ov5693_write_reg(client, OV5693_8BIT,
569 OV5693_TIMING_VTS_H, (vts >> 8) & 0xFF);
570 if (ret) {
571 dev_err(&client->dev, "%s: write %x error, aborted\n",
572 __func__, OV5693_TIMING_VTS_H);
573 return ret;
574 }
575
576 ret = ov5693_write_reg(client, OV5693_8BIT,
577 OV5693_TIMING_VTS_L, vts & 0xFF);
578 if (ret) {
579 dev_err(&client->dev, "%s: write %x error, aborted\n",
580 __func__, OV5693_TIMING_VTS_L);
581 return ret;
582 }
583
584 /* set exposure */
585
586 /* Lower four bit should be 0*/
587 exp_val = coarse_itg << 4;
588 ret = ov5693_write_reg(client, OV5693_8BIT,
589 OV5693_EXPOSURE_L, exp_val & 0xFF);
590 if (ret) {
591 dev_err(&client->dev, "%s: write %x error, aborted\n",
592 __func__, OV5693_EXPOSURE_L);
593 return ret;
594 }
595
596 ret = ov5693_write_reg(client, OV5693_8BIT,
597 OV5693_EXPOSURE_M, (exp_val >> 8) & 0xFF);
598 if (ret) {
599 dev_err(&client->dev, "%s: write %x error, aborted\n",
600 __func__, OV5693_EXPOSURE_M);
601 return ret;
602 }
603
604 ret = ov5693_write_reg(client, OV5693_8BIT,
605 OV5693_EXPOSURE_H, (exp_val >> 16) & 0x0F);
606 if (ret) {
607 dev_err(&client->dev, "%s: write %x error, aborted\n",
608 __func__, OV5693_EXPOSURE_H);
609 return ret;
610 }
611
612 /* Analog gain */
613 ret = ov5693_write_reg(client, OV5693_8BIT,
614 OV5693_AGC_L, gain & 0xff);
615 if (ret) {
616 dev_err(&client->dev, "%s: write %x error, aborted\n",
617 __func__, OV5693_AGC_L);
618 return ret;
619 }
620
621 ret = ov5693_write_reg(client, OV5693_8BIT,
622 OV5693_AGC_H, (gain >> 8) & 0xff);
623 if (ret) {
624 dev_err(&client->dev, "%s: write %x error, aborted\n",
625 __func__, OV5693_AGC_H);
626 return ret;
627 }
628
629 /* Digital gain */
630 if (digitgain) {
631 ret = ov5693_write_reg(client, OV5693_16BIT,
632 OV5693_MWB_RED_GAIN_H, digitgain);
633 if (ret) {
634 dev_err(&client->dev, "%s: write %x error, aborted\n",
635 __func__, OV5693_MWB_RED_GAIN_H);
636 return ret;
637 }
638
639 ret = ov5693_write_reg(client, OV5693_16BIT,
640 OV5693_MWB_GREEN_GAIN_H, digitgain);
641 if (ret) {
642 dev_err(&client->dev, "%s: write %x error, aborted\n",
643 __func__, OV5693_MWB_RED_GAIN_H);
644 return ret;
645 }
646
647 ret = ov5693_write_reg(client, OV5693_16BIT,
648 OV5693_MWB_BLUE_GAIN_H, digitgain);
649 if (ret) {
650 dev_err(&client->dev, "%s: write %x error, aborted\n",
651 __func__, OV5693_MWB_RED_GAIN_H);
652 return ret;
653 }
654 }
655
656 /* End group */
657 ret = ov5693_write_reg(client, OV5693_8BIT,
658 OV5693_GROUP_ACCESS, 0x10);
659 if (ret)
660 return ret;
661
662 /* Delay launch group */
663 ret = ov5693_write_reg(client, OV5693_8BIT,
664 OV5693_GROUP_ACCESS, 0xa0);
665 if (ret)
666 return ret;
667 return ret;
668}
669
670static int ov5693_set_exposure(struct v4l2_subdev *sd, int exposure,
671 int gain, int digitgain)
672{
673 struct ov5693_device *dev = to_ov5693_sensor(sd);
674 int ret;
675
676 mutex_lock(&dev->input_lock);
677 ret = __ov5693_set_exposure(sd, exposure, gain, digitgain);
678 mutex_unlock(&dev->input_lock);
679
680 return ret;
681}
682
683static long ov5693_s_exposure(struct v4l2_subdev *sd,
684 struct atomisp_exposure *exposure)
685{
686 u16 coarse_itg = exposure->integration_time[0];
687 u16 analog_gain = exposure->gain[0];
688 u16 digital_gain = exposure->gain[1];
689
690 /* we should not accept the invalid value below */
691 if (analog_gain == 0) {
692 struct i2c_client *client = v4l2_get_subdevdata(sd);
693 v4l2_err(client, "%s: invalid value\n", __func__);
694 return -EINVAL;
695 }
696 return ov5693_set_exposure(sd, coarse_itg, analog_gain, digital_gain);
697}
698
699static int ov5693_read_otp_reg_array(struct i2c_client *client, u16 size,
14c23a51 700 u16 addr, u8 *buf)
a49d2536
AC
701{
702 u16 index;
703 int ret;
e1b28f13 704 u16 *pVal = NULL;
a49d2536
AC
705
706 for (index = 0; index <= size; index++) {
707 pVal = (u16 *) (buf + index);
708 ret =
709 ov5693_read_reg(client, OV5693_8BIT, addr + index,
710 pVal);
711 if (ret)
712 return ret;
713 }
714
715 return 0;
716}
717
14c23a51 718static int __ov5693_otp_read(struct v4l2_subdev *sd, u8 *buf)
a49d2536
AC
719{
720 struct i2c_client *client = v4l2_get_subdevdata(sd);
721 struct ov5693_device *dev = to_ov5693_sensor(sd);
722 int ret;
723 int i;
724 u8 *b = buf;
725 dev->otp_size = 0;
726 for (i = 1; i < OV5693_OTP_BANK_MAX; i++) {
727 /*set bank NO and OTP read mode. */
728 ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_OTP_BANK_REG, (i | 0xc0)); //[7:6] 2'b11 [5:0] bank no
729 if (ret) {
730 dev_err(&client->dev, "failed to prepare OTP page\n");
731 return ret;
732 }
733 //pr_debug("write 0x%x->0x%x\n",OV5693_OTP_BANK_REG,(i|0xc0));
734
735 /*enable read */
736 ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_OTP_READ_REG, OV5693_OTP_MODE_READ); // enable :1
737 if (ret) {
738 dev_err(&client->dev,
739 "failed to set OTP reading mode page");
740 return ret;
741 }
742 //pr_debug("write 0x%x->0x%x\n",OV5693_OTP_READ_REG,OV5693_OTP_MODE_READ);
743
744 /* Reading the OTP data array */
745 ret = ov5693_read_otp_reg_array(client, OV5693_OTP_BANK_SIZE,
746 OV5693_OTP_START_ADDR,
747 b);
748 if (ret) {
749 dev_err(&client->dev, "failed to read OTP data\n");
750 return ret;
751 }
752
753 //pr_debug("BANK[%2d] %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", i, *b, *(b+1), *(b+2), *(b+3), *(b+4), *(b+5), *(b+6), *(b+7), *(b+8), *(b+9), *(b+10), *(b+11), *(b+12), *(b+13), *(b+14), *(b+15));
754
755 //Intel OTP map, try to read 320byts first.
756 if (21 == i) {
757 if ((*b) == 0) {
758 dev->otp_size = 320;
759 break;
760 } else {
761 b = buf;
762 continue;
763 }
764 } else if (24 == i) { //if the first 320bytes data doesn't not exist, try to read the next 32bytes data.
765 if ((*b) == 0) {
766 dev->otp_size = 32;
767 break;
768 } else {
769 b = buf;
770 continue;
771 }
772 } else if (27 == i) { //if the prvious 32bytes data doesn't exist, try to read the next 32bytes data again.
773 if ((*b) == 0) {
774 dev->otp_size = 32;
775 break;
776 } else {
777 dev->otp_size = 0; // no OTP data.
778 break;
779 }
780 }
781
782 b = b + OV5693_OTP_BANK_SIZE;
783 }
784 return 0;
785}
786
787/*
788 * Read otp data and store it into a kmalloced buffer.
789 * The caller must kfree the buffer when no more needed.
790 * @size: set to the size of the returned otp data.
791 */
792static void *ov5693_otp_read(struct v4l2_subdev *sd)
793{
794 struct i2c_client *client = v4l2_get_subdevdata(sd);
795 u8 *buf;
796 int ret;
797
798 buf = devm_kzalloc(&client->dev, (OV5693_OTP_DATA_SIZE + 16), GFP_KERNEL);
799 if (!buf)
800 return ERR_PTR(-ENOMEM);
801
802 //otp valid after mipi on and sw stream on
803 ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_FRAME_OFF_NUM, 0x00);
804
805 ret = ov5693_write_reg(client, OV5693_8BIT,
806 OV5693_SW_STREAM, OV5693_START_STREAMING);
807
808 ret = __ov5693_otp_read(sd, buf);
809
810 //mipi off and sw stream off after otp read
811 ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_FRAME_OFF_NUM, 0x0f);
812
813 ret = ov5693_write_reg(client, OV5693_8BIT,
814 OV5693_SW_STREAM, OV5693_STOP_STREAMING);
815
816 /* Driver has failed to find valid data */
817 if (ret) {
818 dev_err(&client->dev, "sensor found no valid OTP data\n");
819 return ERR_PTR(ret);
820 }
821
822 return buf;
823}
824
825static int ov5693_g_priv_int_data(struct v4l2_subdev *sd,
826 struct v4l2_private_int_data *priv)
827{
828 struct i2c_client *client = v4l2_get_subdevdata(sd);
829 struct ov5693_device *dev = to_ov5693_sensor(sd);
830 u8 __user *to = priv->data;
831 u32 read_size = priv->size;
832 int ret;
833
834 /* No need to copy data if size is 0 */
835 if (!read_size)
836 goto out;
837
838 if (IS_ERR(dev->otp_data)) {
839 dev_err(&client->dev, "OTP data not available");
840 return PTR_ERR(dev->otp_data);
841 }
842
843 /* Correct read_size value only if bigger than maximum */
844 if (read_size > OV5693_OTP_DATA_SIZE)
845 read_size = OV5693_OTP_DATA_SIZE;
846
847 ret = copy_to_user(to, dev->otp_data, read_size);
848 if (ret) {
849 dev_err(&client->dev, "%s: failed to copy OTP data to user\n",
850 __func__);
851 return -EFAULT;
852 }
853
854 pr_debug("%s read_size:%d\n", __func__, read_size);
855
856out:
857 /* Return correct size */
858 priv->size = dev->otp_size;
859
860 return 0;
861
862}
863
864static long ov5693_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg)
865{
866
867 switch (cmd) {
868 case ATOMISP_IOC_S_EXPOSURE:
869 return ov5693_s_exposure(sd, arg);
870 case ATOMISP_IOC_G_SENSOR_PRIV_INT_DATA:
871 return ov5693_g_priv_int_data(sd, arg);
872 default:
873 return -EINVAL;
874 }
875 return 0;
876}
877
878/* This returns the exposure time being used. This should only be used
879 for filling in EXIF data, not for actual image processing. */
880static int ov5693_q_exposure(struct v4l2_subdev *sd, s32 *value)
881{
882 struct i2c_client *client = v4l2_get_subdevdata(sd);
883 u16 reg_v, reg_v2;
884 int ret;
885
886 /* get exposure */
887 ret = ov5693_read_reg(client, OV5693_8BIT,
888 OV5693_EXPOSURE_L,
889 &reg_v);
890 if (ret)
891 goto err;
892
893 ret = ov5693_read_reg(client, OV5693_8BIT,
894 OV5693_EXPOSURE_M,
895 &reg_v2);
896 if (ret)
897 goto err;
898
899 reg_v += reg_v2 << 8;
900 ret = ov5693_read_reg(client, OV5693_8BIT,
901 OV5693_EXPOSURE_H,
902 &reg_v2);
903 if (ret)
904 goto err;
905
906 *value = reg_v + (((u32)reg_v2 << 16));
907err:
908 return ret;
909}
910
4a3039e2 911static int ad5823_t_focus_vcm(struct v4l2_subdev *sd, u16 val)
a49d2536
AC
912{
913 struct i2c_client *client = v4l2_get_subdevdata(sd);
914 int ret = -EINVAL;
915 u8 vcm_code;
916
917 ret = ad5823_i2c_read(client, AD5823_REG_VCM_CODE_MSB, &vcm_code);
918 if (ret)
919 return ret;
920
921 /* set reg VCM_CODE_MSB Bit[1:0] */
922 vcm_code = (vcm_code & VCM_CODE_MSB_MASK) |
923 ((val >> 8) & ~VCM_CODE_MSB_MASK);
924 ret = ad5823_i2c_write(client, AD5823_REG_VCM_CODE_MSB, vcm_code);
925 if (ret)
926 return ret;
927
928 /* set reg VCM_CODE_LSB Bit[7:0] */
929 ret = ad5823_i2c_write(client, AD5823_REG_VCM_CODE_LSB, (val & 0xff));
930 if (ret)
931 return ret;
932
933 /* set required vcm move time */
934 vcm_code = AD5823_RESONANCE_PERIOD / AD5823_RESONANCE_COEF
935 - AD5823_HIGH_FREQ_RANGE;
936 ret = ad5823_i2c_write(client, AD5823_REG_VCM_MOVE_TIME, vcm_code);
937
938 return ret;
939}
940
941int ad5823_t_focus_abs(struct v4l2_subdev *sd, s32 value)
942{
a49d2536 943 value = min(value, AD5823_MAX_FOCUS_POS);
34d340b7 944 return ad5823_t_focus_vcm(sd, value);
a49d2536
AC
945}
946
947static int ov5693_t_focus_abs(struct v4l2_subdev *sd, s32 value)
948{
949 struct ov5693_device *dev = to_ov5693_sensor(sd);
950 struct i2c_client *client = v4l2_get_subdevdata(sd);
951 int ret = 0;
952
953 dev_dbg(&client->dev, "%s: FOCUS_POS: 0x%x\n", __func__, value);
954 value = clamp(value, 0, OV5693_VCM_MAX_FOCUS_POS);
955 if (dev->vcm == VCM_DW9714) {
956 if (dev->vcm_update) {
957 ret = vcm_dw_i2c_write(client, VCM_PROTECTION_OFF);
958 if (ret)
959 return ret;
960 ret = vcm_dw_i2c_write(client, DIRECT_VCM);
961 if (ret)
962 return ret;
963 ret = vcm_dw_i2c_write(client, VCM_PROTECTION_ON);
964 if (ret)
965 return ret;
966 dev->vcm_update = false;
967 }
968 ret = vcm_dw_i2c_write(client,
969 vcm_val(value, VCM_DEFAULT_S));
970 } else if (dev->vcm == VCM_AD5823) {
971 ad5823_t_focus_abs(sd, value);
972 }
973 if (ret == 0) {
974 dev->number_of_steps = value - dev->focus;
975 dev->focus = value;
976 getnstimeofday(&(dev->timestamp_t_focus_abs));
977 } else
978 dev_err(&client->dev,
979 "%s: i2c failed. ret %d\n", __func__, ret);
980
981 return ret;
982}
983
984static int ov5693_t_focus_rel(struct v4l2_subdev *sd, s32 value)
985{
986 struct ov5693_device *dev = to_ov5693_sensor(sd);
987 return ov5693_t_focus_abs(sd, dev->focus + value);
988}
989
990#define DELAY_PER_STEP_NS 1000000
991#define DELAY_MAX_PER_STEP_NS (1000000 * 1023)
992static int ov5693_q_focus_status(struct v4l2_subdev *sd, s32 *value)
993{
994 u32 status = 0;
995 struct ov5693_device *dev = to_ov5693_sensor(sd);
996 struct timespec temptime;
997 const struct timespec timedelay = {
998 0,
999 min((u32)abs(dev->number_of_steps) * DELAY_PER_STEP_NS,
1000 (u32)DELAY_MAX_PER_STEP_NS),
1001 };
1002
1003 getnstimeofday(&temptime);
1004 temptime = timespec_sub(temptime, (dev->timestamp_t_focus_abs));
1005 if (timespec_compare(&temptime, &timedelay) <= 0) {
1006 status |= ATOMISP_FOCUS_STATUS_MOVING;
1007 status |= ATOMISP_FOCUS_HP_IN_PROGRESS;
1008 } else {
1009 status |= ATOMISP_FOCUS_STATUS_ACCEPTS_NEW_MOVE;
1010 status |= ATOMISP_FOCUS_HP_COMPLETE;
1011 }
1012
1013 *value = status;
1014
1015 return 0;
1016}
1017
1018static int ov5693_q_focus_abs(struct v4l2_subdev *sd, s32 *value)
1019{
1020 struct ov5693_device *dev = to_ov5693_sensor(sd);
1021 s32 val;
1022
1023 ov5693_q_focus_status(sd, &val);
1024
1025 if (val & ATOMISP_FOCUS_STATUS_MOVING)
1026 *value = dev->focus - dev->number_of_steps;
1027 else
1028 *value = dev->focus;
1029
1030 return 0;
1031}
1032
1033static int ov5693_t_vcm_slew(struct v4l2_subdev *sd, s32 value)
1034{
1035 struct ov5693_device *dev = to_ov5693_sensor(sd);
1036 dev->number_of_steps = value;
1037 dev->vcm_update = true;
1038 return 0;
1039}
1040
1041static int ov5693_t_vcm_timing(struct v4l2_subdev *sd, s32 value)
1042{
1043 struct ov5693_device *dev = to_ov5693_sensor(sd);
1044 dev->number_of_steps = value;
1045 dev->vcm_update = true;
1046 return 0;
1047}
1048
1049static int ov5693_s_ctrl(struct v4l2_ctrl *ctrl)
1050{
1051 struct ov5693_device *dev =
1052 container_of(ctrl->handler, struct ov5693_device, ctrl_handler);
1053 struct i2c_client *client = v4l2_get_subdevdata(&dev->sd);
1054 int ret = 0;
1055
1056 switch (ctrl->id) {
1057 case V4L2_CID_FOCUS_ABSOLUTE:
1058 dev_dbg(&client->dev, "%s: CID_FOCUS_ABSOLUTE:%d.\n",
1059 __func__, ctrl->val);
1060 ret = ov5693_t_focus_abs(&dev->sd, ctrl->val);
1061 break;
1062 case V4L2_CID_FOCUS_RELATIVE:
1063 dev_dbg(&client->dev, "%s: CID_FOCUS_RELATIVE:%d.\n",
1064 __func__, ctrl->val);
1065 ret = ov5693_t_focus_rel(&dev->sd, ctrl->val);
1066 break;
1067 case V4L2_CID_VCM_SLEW:
1068 ret = ov5693_t_vcm_slew(&dev->sd, ctrl->val);
1069 break;
1070 case V4L2_CID_VCM_TIMEING:
1071 ret = ov5693_t_vcm_timing(&dev->sd, ctrl->val);
1072 break;
1073 default:
1074 ret = -EINVAL;
1075 }
1076 return ret;
1077}
1078
1079static int ov5693_g_volatile_ctrl(struct v4l2_ctrl *ctrl)
1080{
1081 struct ov5693_device *dev =
1082 container_of(ctrl->handler, struct ov5693_device, ctrl_handler);
1083 int ret = 0;
1084
1085 switch (ctrl->id) {
1086 case V4L2_CID_EXPOSURE_ABSOLUTE:
1087 ret = ov5693_q_exposure(&dev->sd, &ctrl->val);
1088 break;
1089 case V4L2_CID_FOCAL_ABSOLUTE:
1090 ret = ov5693_g_focal(&dev->sd, &ctrl->val);
1091 break;
1092 case V4L2_CID_FNUMBER_ABSOLUTE:
1093 ret = ov5693_g_fnumber(&dev->sd, &ctrl->val);
1094 break;
1095 case V4L2_CID_FNUMBER_RANGE:
1096 ret = ov5693_g_fnumber_range(&dev->sd, &ctrl->val);
1097 break;
1098 case V4L2_CID_FOCUS_ABSOLUTE:
1099 ret = ov5693_q_focus_abs(&dev->sd, &ctrl->val);
1100 break;
1101 case V4L2_CID_FOCUS_STATUS:
1102 ret = ov5693_q_focus_status(&dev->sd, &ctrl->val);
9e7b319e 1103 break;
a49d2536
AC
1104 case V4L2_CID_BIN_FACTOR_HORZ:
1105 ret = ov5693_g_bin_factor_x(&dev->sd, &ctrl->val);
1106 break;
1107 case V4L2_CID_BIN_FACTOR_VERT:
1108 ret = ov5693_g_bin_factor_y(&dev->sd, &ctrl->val);
1109 break;
1110 default:
1111 ret = -EINVAL;
1112 }
1113
1114 return ret;
1115}
1116
1117static const struct v4l2_ctrl_ops ctrl_ops = {
1118 .s_ctrl = ov5693_s_ctrl,
1119 .g_volatile_ctrl = ov5693_g_volatile_ctrl
1120};
1121
1122struct v4l2_ctrl_config ov5693_controls[] = {
1123 {
1124 .ops = &ctrl_ops,
1125 .id = V4L2_CID_EXPOSURE_ABSOLUTE,
1126 .type = V4L2_CTRL_TYPE_INTEGER,
1127 .name = "exposure",
1128 .min = 0x0,
1129 .max = 0xffff,
1130 .step = 0x01,
1131 .def = 0x00,
1132 .flags = 0,
1133 },
1134 {
1135 .ops = &ctrl_ops,
1136 .id = V4L2_CID_FOCAL_ABSOLUTE,
1137 .type = V4L2_CTRL_TYPE_INTEGER,
1138 .name = "focal length",
1139 .min = OV5693_FOCAL_LENGTH_DEFAULT,
1140 .max = OV5693_FOCAL_LENGTH_DEFAULT,
1141 .step = 0x01,
1142 .def = OV5693_FOCAL_LENGTH_DEFAULT,
1143 .flags = 0,
1144 },
1145 {
1146 .ops = &ctrl_ops,
1147 .id = V4L2_CID_FNUMBER_ABSOLUTE,
1148 .type = V4L2_CTRL_TYPE_INTEGER,
1149 .name = "f-number",
1150 .min = OV5693_F_NUMBER_DEFAULT,
1151 .max = OV5693_F_NUMBER_DEFAULT,
1152 .step = 0x01,
1153 .def = OV5693_F_NUMBER_DEFAULT,
1154 .flags = 0,
1155 },
1156 {
1157 .ops = &ctrl_ops,
1158 .id = V4L2_CID_FNUMBER_RANGE,
1159 .type = V4L2_CTRL_TYPE_INTEGER,
1160 .name = "f-number range",
1161 .min = OV5693_F_NUMBER_RANGE,
1162 .max = OV5693_F_NUMBER_RANGE,
1163 .step = 0x01,
1164 .def = OV5693_F_NUMBER_RANGE,
1165 .flags = 0,
1166 },
1167 {
1168 .ops = &ctrl_ops,
1169 .id = V4L2_CID_FOCUS_ABSOLUTE,
1170 .type = V4L2_CTRL_TYPE_INTEGER,
1171 .name = "focus move absolute",
1172 .min = 0,
1173 .max = OV5693_VCM_MAX_FOCUS_POS,
1174 .step = 1,
1175 .def = 0,
1176 .flags = 0,
1177 },
1178 {
1179 .ops = &ctrl_ops,
1180 .id = V4L2_CID_FOCUS_RELATIVE,
1181 .type = V4L2_CTRL_TYPE_INTEGER,
1182 .name = "focus move relative",
1183 .min = OV5693_VCM_MAX_FOCUS_NEG,
1184 .max = OV5693_VCM_MAX_FOCUS_POS,
1185 .step = 1,
1186 .def = 0,
1187 .flags = 0,
1188 },
1189 {
1190 .ops = &ctrl_ops,
1191 .id = V4L2_CID_FOCUS_STATUS,
1192 .type = V4L2_CTRL_TYPE_INTEGER,
1193 .name = "focus status",
1194 .min = 0,
1195 .max = 100, /* allow enum to grow in the future */
1196 .step = 1,
1197 .def = 0,
1198 .flags = 0,
1199 },
1200 {
1201 .ops = &ctrl_ops,
1202 .id = V4L2_CID_VCM_SLEW,
1203 .type = V4L2_CTRL_TYPE_INTEGER,
1204 .name = "vcm slew",
1205 .min = 0,
1206 .max = OV5693_VCM_SLEW_STEP_MAX,
1207 .step = 1,
1208 .def = 0,
1209 .flags = 0,
1210 },
1211 {
1212 .ops = &ctrl_ops,
1213 .id = V4L2_CID_VCM_TIMEING,
1214 .type = V4L2_CTRL_TYPE_INTEGER,
1215 .name = "vcm step time",
1216 .min = 0,
1217 .max = OV5693_VCM_SLEW_TIME_MAX,
1218 .step = 1,
1219 .def = 0,
1220 .flags = 0,
1221 },
1222 {
1223 .ops = &ctrl_ops,
1224 .id = V4L2_CID_BIN_FACTOR_HORZ,
1225 .type = V4L2_CTRL_TYPE_INTEGER,
1226 .name = "horizontal binning factor",
1227 .min = 0,
1228 .max = OV5693_BIN_FACTOR_MAX,
1229 .step = 1,
1230 .def = 0,
1231 .flags = 0,
1232 },
1233 {
1234 .ops = &ctrl_ops,
1235 .id = V4L2_CID_BIN_FACTOR_VERT,
1236 .type = V4L2_CTRL_TYPE_INTEGER,
1237 .name = "vertical binning factor",
1238 .min = 0,
1239 .max = OV5693_BIN_FACTOR_MAX,
1240 .step = 1,
1241 .def = 0,
1242 .flags = 0,
1243 },
1244};
1245
1246static int ov5693_init(struct v4l2_subdev *sd)
1247{
1248 struct ov5693_device *dev = to_ov5693_sensor(sd);
1249 struct i2c_client *client = v4l2_get_subdevdata(sd);
1250 int ret;
1251
1252 pr_info("%s\n", __func__);
1253 mutex_lock(&dev->input_lock);
1254 dev->vcm_update = false;
1255
1256 if (dev->vcm == VCM_AD5823) {
1257 ret = vcm_ad_i2c_wr8(client, 0x01, 0x01); /* vcm init test */
1258 if (ret)
1259 dev_err(&client->dev,
1260 "vcm reset failed\n");
1261 /*change the mode*/
1262 ret = ad5823_i2c_write(client, AD5823_REG_VCM_CODE_MSB,
1263 AD5823_RING_CTRL_ENABLE);
1264 if (ret)
1265 dev_err(&client->dev,
1266 "vcm enable ringing failed\n");
1267 ret = ad5823_i2c_write(client, AD5823_REG_MODE,
1268 AD5823_ARC_RES1);
1269 if (ret)
1270 dev_err(&client->dev,
1271 "vcm change mode failed\n");
1272 }
1273
1274 /*change initial focus value for ad5823*/
1275 if (dev->vcm == VCM_AD5823) {
1276 dev->focus = AD5823_INIT_FOCUS_POS;
1277 ov5693_t_focus_abs(sd, AD5823_INIT_FOCUS_POS);
1278 } else {
1279 dev->focus = 0;
1280 ov5693_t_focus_abs(sd, 0);
1281 }
1282
1283 mutex_unlock(&dev->input_lock);
1284
1285 return 0;
1286}
1287
1288static int power_ctrl(struct v4l2_subdev *sd, bool flag)
1289{
1290 int ret;
1291 struct ov5693_device *dev = to_ov5693_sensor(sd);
1292
1293 if (!dev || !dev->platform_data)
1294 return -ENODEV;
1295
a49d2536
AC
1296 /* This driver assumes "internal DVDD, PWDNB tied to DOVDD".
1297 * In this set up only gpio0 (XSHUTDN) should be available
1298 * but in some products (for example ECS) gpio1 (PWDNB) is
1299 * also available. If gpio1 is available we emulate it being
1300 * tied to DOVDD here. */
1301 if (flag) {
1302 ret = dev->platform_data->v2p8_ctrl(sd, 1);
1303 dev->platform_data->gpio1_ctrl(sd, 1);
1304 if (ret == 0) {
1305 ret = dev->platform_data->v1p8_ctrl(sd, 1);
1306 if (ret) {
1307 dev->platform_data->gpio1_ctrl(sd, 0);
1308 ret = dev->platform_data->v2p8_ctrl(sd, 0);
1309 }
1310 }
1311 } else {
1312 dev->platform_data->gpio1_ctrl(sd, 0);
1313 ret = dev->platform_data->v1p8_ctrl(sd, 0);
1314 ret |= dev->platform_data->v2p8_ctrl(sd, 0);
1315 }
1316
1317 return ret;
1318}
1319
1320static int gpio_ctrl(struct v4l2_subdev *sd, bool flag)
1321{
a49d2536
AC
1322 struct ov5693_device *dev = to_ov5693_sensor(sd);
1323
1324 if (!dev || !dev->platform_data)
1325 return -ENODEV;
1326
34d340b7 1327 return dev->platform_data->gpio0_ctrl(sd, flag);
a49d2536
AC
1328}
1329
1330static int __power_up(struct v4l2_subdev *sd)
1331{
1332 struct ov5693_device *dev = to_ov5693_sensor(sd);
1333 struct i2c_client *client = v4l2_get_subdevdata(sd);
1334 int ret;
1335
1336 if (NULL == dev->platform_data) {
1337 dev_err(&client->dev,
1338 "no camera_sensor_platform_data");
1339 return -ENODEV;
1340 }
1341
1342 /* power control */
1343 ret = power_ctrl(sd, 1);
1344 if (ret)
1345 goto fail_power;
1346
1347 /* according to DS, at least 5ms is needed between DOVDD and PWDN */
1348 /* add this delay time to 10~11ms*/
1349 usleep_range(10000, 11000);
1350
1351 /* gpio ctrl */
1352 ret = gpio_ctrl(sd, 1);
1353 if (ret) {
1354 ret = gpio_ctrl(sd, 1);
1355 if (ret)
1356 goto fail_power;
1357 }
1358
1359 /* flis clock control */
1360 ret = dev->platform_data->flisclk_ctrl(sd, 1);
1361 if (ret)
1362 goto fail_clk;
1363
1364 __cci_delay(up_delay);
1365
1366 return 0;
1367
1368fail_clk:
1369 gpio_ctrl(sd, 0);
1370fail_power:
1371 power_ctrl(sd, 0);
1372 dev_err(&client->dev, "sensor power-up failed\n");
1373
1374 return ret;
1375}
1376
1377static int power_down(struct v4l2_subdev *sd)
1378{
1379 struct ov5693_device *dev = to_ov5693_sensor(sd);
1380 struct i2c_client *client = v4l2_get_subdevdata(sd);
1381 int ret = 0;
1382
1383 dev->focus = OV5693_INVALID_CONFIG;
1384 if (NULL == dev->platform_data) {
1385 dev_err(&client->dev,
1386 "no camera_sensor_platform_data");
1387 return -ENODEV;
1388 }
1389
1390 ret = dev->platform_data->flisclk_ctrl(sd, 0);
1391 if (ret)
1392 dev_err(&client->dev, "flisclk failed\n");
1393
1394 /* gpio ctrl */
1395 ret = gpio_ctrl(sd, 0);
1396 if (ret) {
1397 ret = gpio_ctrl(sd, 0);
1398 if (ret)
1399 dev_err(&client->dev, "gpio failed 2\n");
1400 }
1401
1402 /* power control */
1403 ret = power_ctrl(sd, 0);
1404 if (ret)
1405 dev_err(&client->dev, "vprog failed.\n");
1406
1407 return ret;
1408}
1409
1410static int power_up(struct v4l2_subdev *sd)
1411{
1412 static const int retry_count = 4;
1413 int i, ret;
1414
1415 for (i = 0; i < retry_count; i++) {
1416 ret = __power_up(sd);
1417 if (!ret)
1418 return 0;
1419
1420 power_down(sd);
1421 }
1422 return ret;
1423}
1424
1425static int ov5693_s_power(struct v4l2_subdev *sd, int on)
1426{
1427 int ret;
1428
1429 pr_info("%s: on %d\n", __func__, on);
1430 if (on == 0)
1431 return power_down(sd);
1432 else {
1433 ret = power_up(sd);
1434 if (!ret) {
1435 ret = ov5693_init(sd);
1436 /* restore settings */
1437 ov5693_res = ov5693_res_preview;
1438 N_RES = N_RES_PREVIEW;
1439 }
1440 }
1441 return ret;
1442}
1443
1444/*
1445 * distance - calculate the distance
1446 * @res: resolution
1447 * @w: width
1448 * @h: height
1449 *
1450 * Get the gap between res_w/res_h and w/h.
1451 * distance = (res_w/res_h - w/h) / (w/h) * 8192
1452 * res->width/height smaller than w/h wouldn't be considered.
1453 * The gap of ratio larger than 1/8 wouldn't be considered.
1454 * Returns the value of gap or -1 if fail.
1455 */
1456#define LARGEST_ALLOWED_RATIO_MISMATCH 1024
1457static int distance(struct ov5693_resolution *res, u32 w, u32 h)
1458{
1459 int ratio;
1460 int distance;
1461
1462 if (w == 0 || h == 0 ||
1463 res->width < w || res->height < h)
1464 return -1;
1465
6c492211 1466 ratio = res->width << 13;
a49d2536
AC
1467 ratio /= w;
1468 ratio *= h;
1469 ratio /= res->height;
1470
1471 distance = abs(ratio - 8192);
1472
1473 if (distance > LARGEST_ALLOWED_RATIO_MISMATCH)
1474 return -1;
1475
1476 return distance;
1477}
1478
1479/* Return the nearest higher resolution index
1480 * Firstly try to find the approximate aspect ratio resolution
1481 * If we find multiple same AR resolutions, choose the
1482 * minimal size.
1483 */
1484static int nearest_resolution_index(int w, int h)
1485{
1486 int i;
1487 int idx = -1;
1488 int dist;
1489 int min_dist = INT_MAX;
1490 int min_res_w = INT_MAX;
1491 struct ov5693_resolution *tmp_res = NULL;
1492
1493 for (i = 0; i < N_RES; i++) {
1494 tmp_res = &ov5693_res[i];
1495 dist = distance(tmp_res, w, h);
1496 if (dist == -1)
1497 continue;
1498 if (dist < min_dist) {
1499 min_dist = dist;
1500 idx = i;
1501 min_res_w = ov5693_res[i].width;
1502 continue;
1503 }
1504 if (dist == min_dist && ov5693_res[i].width < min_res_w)
1505 idx = i;
1506 }
1507
1508 return idx;
1509}
1510
1511static int get_resolution_index(int w, int h)
1512{
1513 int i;
1514
1515 for (i = 0; i < N_RES; i++) {
1516 if (w != ov5693_res[i].width)
1517 continue;
1518 if (h != ov5693_res[i].height)
1519 continue;
1520
1521 return i;
1522 }
1523
1524 return -1;
1525}
1526
1527/* TODO: remove it. */
1528static int startup(struct v4l2_subdev *sd)
1529{
1530 struct ov5693_device *dev = to_ov5693_sensor(sd);
1531 struct i2c_client *client = v4l2_get_subdevdata(sd);
1532 int ret = 0;
1533
1534 ret = ov5693_write_reg(client, OV5693_8BIT,
1535 OV5693_SW_RESET, 0x01);
1536 if (ret) {
1537 dev_err(&client->dev, "ov5693 reset err.\n");
1538 return ret;
1539 }
1540
1541 ret = ov5693_write_reg_array(client, ov5693_global_setting);
1542 if (ret) {
1543 dev_err(&client->dev, "ov5693 write register err.\n");
1544 return ret;
1545 }
1546
1547 ret = ov5693_write_reg_array(client, ov5693_res[dev->fmt_idx].regs);
1548 if (ret) {
1549 dev_err(&client->dev, "ov5693 write register err.\n");
1550 return ret;
1551 }
1552
1553 return ret;
1554}
1555
1556static int ov5693_set_fmt(struct v4l2_subdev *sd,
1557 struct v4l2_subdev_pad_config *cfg,
1558 struct v4l2_subdev_format *format)
1559{
1560 struct v4l2_mbus_framefmt *fmt = &format->format;
1561 struct ov5693_device *dev = to_ov5693_sensor(sd);
1562 struct i2c_client *client = v4l2_get_subdevdata(sd);
1563 struct camera_mipi_info *ov5693_info = NULL;
1564 int ret = 0;
1565 int idx;
1566 if (format->pad)
1567 return -EINVAL;
1568 if (!fmt)
1569 return -EINVAL;
1570 ov5693_info = v4l2_get_subdev_hostdata(sd);
1571 if (ov5693_info == NULL)
1572 return -EINVAL;
1573
1574 mutex_lock(&dev->input_lock);
1575 idx = nearest_resolution_index(fmt->width, fmt->height);
1576 if (idx == -1) {
1577 /* return the largest resolution */
1578 fmt->width = ov5693_res[N_RES - 1].width;
1579 fmt->height = ov5693_res[N_RES - 1].height;
1580 } else {
1581 fmt->width = ov5693_res[idx].width;
1582 fmt->height = ov5693_res[idx].height;
1583 }
1584
1585 fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10;
1586 if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
1587 cfg->try_fmt = *fmt;
1588 mutex_unlock(&dev->input_lock);
1589 return 0;
1590 }
1591
1592 dev->fmt_idx = get_resolution_index(fmt->width, fmt->height);
1593 if (dev->fmt_idx == -1) {
1594 dev_err(&client->dev, "get resolution fail\n");
1595 mutex_unlock(&dev->input_lock);
1596 return -EINVAL;
1597 }
1598
1599 ret = startup(sd);
1600 if (ret) {
1601 int i = 0;
1602 dev_err(&client->dev, "ov5693 startup err, retry to power up\n");
1603 for (i = 0; i < OV5693_POWER_UP_RETRY_NUM; i++) {
1604 dev_err(&client->dev,
1605 "ov5693 retry to power up %d/%d times, result: ",
1606 i+1, OV5693_POWER_UP_RETRY_NUM);
1607 power_down(sd);
1608 ret = power_up(sd);
1609 if (!ret) {
1610 mutex_unlock(&dev->input_lock);
1611 ov5693_init(sd);
1612 mutex_lock(&dev->input_lock);
1613 } else {
1614 dev_err(&client->dev, "power up failed, continue\n");
1615 continue;
1616 }
1617 ret = startup(sd);
1618 if (ret) {
1619 dev_err(&client->dev, " startup FAILED!\n");
1620 } else {
1621 dev_err(&client->dev, " startup SUCCESS!\n");
1622 break;
1623 }
1624 }
1625 }
1626
1627 /*
1628 * After sensor settings are set to HW, sometimes stream is started.
1629 * This would cause ISP timeout because ISP is not ready to receive
1630 * data yet. So add stop streaming here.
1631 */
1632 ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_SW_STREAM,
1633 OV5693_STOP_STREAMING);
1634 if (ret)
1635 dev_warn(&client->dev, "ov5693 stream off err\n");
1636
1637 ret = ov5693_get_intg_factor(client, ov5693_info,
1638 &ov5693_res[dev->fmt_idx]);
1639 if (ret) {
1640 dev_err(&client->dev, "failed to get integration_factor\n");
1641 goto err;
1642 }
1643
1644 ov5693_info->metadata_width = fmt->width * 10 / 8;
1645 ov5693_info->metadata_height = 1;
1646 ov5693_info->metadata_effective_width = &ov5693_embedded_effective_size;
1647
1648err:
1649 mutex_unlock(&dev->input_lock);
1650 return ret;
1651}
1652static int ov5693_get_fmt(struct v4l2_subdev *sd,
1653 struct v4l2_subdev_pad_config *cfg,
1654 struct v4l2_subdev_format *format)
1655{
1656 struct v4l2_mbus_framefmt *fmt = &format->format;
1657 struct ov5693_device *dev = to_ov5693_sensor(sd);
1658 if (format->pad)
1659 return -EINVAL;
1660
1661 if (!fmt)
1662 return -EINVAL;
1663
1664 fmt->width = ov5693_res[dev->fmt_idx].width;
1665 fmt->height = ov5693_res[dev->fmt_idx].height;
1666 fmt->code = MEDIA_BUS_FMT_SBGGR10_1X10;
1667
1668 return 0;
1669}
1670
1671static int ov5693_detect(struct i2c_client *client)
1672{
1673 struct i2c_adapter *adapter = client->adapter;
1674 u16 high, low;
1675 int ret;
1676 u16 id;
1677 u8 revision;
1678
1679 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
1680 return -ENODEV;
1681
1682 ret = ov5693_read_reg(client, OV5693_8BIT,
1683 OV5693_SC_CMMN_CHIP_ID_H, &high);
1684 if (ret) {
1685 dev_err(&client->dev, "sensor_id_high = 0x%x\n", high);
1686 return -ENODEV;
1687 }
1688 ret = ov5693_read_reg(client, OV5693_8BIT,
1689 OV5693_SC_CMMN_CHIP_ID_L, &low);
1690 id = ((((u16) high) << 8) | (u16) low);
1691
1692 if (id != OV5693_ID) {
1693 dev_err(&client->dev, "sensor ID error 0x%x\n", id);
1694 return -ENODEV;
1695 }
1696
1697 ret = ov5693_read_reg(client, OV5693_8BIT,
1698 OV5693_SC_CMMN_SUB_ID, &high);
1699 revision = (u8) high & 0x0f;
1700
1701 dev_dbg(&client->dev, "sensor_revision = 0x%x\n", revision);
1702 dev_dbg(&client->dev, "detect ov5693 success\n");
1703 return 0;
1704}
1705
1706static int ov5693_s_stream(struct v4l2_subdev *sd, int enable)
1707{
1708 struct ov5693_device *dev = to_ov5693_sensor(sd);
1709 struct i2c_client *client = v4l2_get_subdevdata(sd);
1710 int ret;
1711
1712 mutex_lock(&dev->input_lock);
1713
1714 ret = ov5693_write_reg(client, OV5693_8BIT, OV5693_SW_STREAM,
1715 enable ? OV5693_START_STREAMING :
1716 OV5693_STOP_STREAMING);
1717
1718 mutex_unlock(&dev->input_lock);
1719
1720 return ret;
1721}
1722
1723
1724static int ov5693_s_config(struct v4l2_subdev *sd,
1725 int irq, void *platform_data)
1726{
1727 struct ov5693_device *dev = to_ov5693_sensor(sd);
1728 struct i2c_client *client = v4l2_get_subdevdata(sd);
1729 int ret = 0;
1730
1731 if (platform_data == NULL)
1732 return -ENODEV;
1733
1734 dev->platform_data =
1735 (struct camera_sensor_platform_data *)platform_data;
1736
1737 mutex_lock(&dev->input_lock);
1738 /* power off the module, then power on it in future
1739 * as first power on by board may not fulfill the
1740 * power on sequqence needed by the module
1741 */
1742 ret = power_down(sd);
1743 if (ret) {
1744 dev_err(&client->dev, "ov5693 power-off err.\n");
1745 goto fail_power_off;
1746 }
1747
1748 ret = power_up(sd);
1749 if (ret) {
1750 dev_err(&client->dev, "ov5693 power-up err.\n");
1751 goto fail_power_on;
1752 }
1753
1754 if (!dev->vcm)
1755 dev->vcm = vcm_detect(client);
1756
1757 ret = dev->platform_data->csi_cfg(sd, 1);
1758 if (ret)
1759 goto fail_csi_cfg;
1760
1761 /* config & detect sensor */
1762 ret = ov5693_detect(client);
1763 if (ret) {
1764 dev_err(&client->dev, "ov5693_detect err s_config.\n");
1765 goto fail_csi_cfg;
1766 }
1767
1768 dev->otp_data = ov5693_otp_read(sd);
1769
1770 /* turn off sensor, after probed */
1771 ret = power_down(sd);
1772 if (ret) {
1773 dev_err(&client->dev, "ov5693 power-off err.\n");
1774 goto fail_csi_cfg;
1775 }
1776 mutex_unlock(&dev->input_lock);
1777
1778 return ret;
1779
1780fail_csi_cfg:
1781 dev->platform_data->csi_cfg(sd, 0);
1782fail_power_on:
1783 power_down(sd);
1784 dev_err(&client->dev, "sensor power-gating failed\n");
1785fail_power_off:
1786 mutex_unlock(&dev->input_lock);
1787 return ret;
1788}
1789
1790static int ov5693_g_parm(struct v4l2_subdev *sd,
1791 struct v4l2_streamparm *param)
1792{
1793 struct ov5693_device *dev = to_ov5693_sensor(sd);
1794 struct i2c_client *client = v4l2_get_subdevdata(sd);
1795
1796 if (!param)
1797 return -EINVAL;
1798
1799 if (param->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1800 dev_err(&client->dev, "unsupported buffer type.\n");
1801 return -EINVAL;
1802 }
1803
1804 memset(param, 0, sizeof(*param));
1805 param->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1806
1807 if (dev->fmt_idx >= 0 && dev->fmt_idx < N_RES) {
1808 param->parm.capture.capability = V4L2_CAP_TIMEPERFRAME;
1809 param->parm.capture.timeperframe.numerator = 1;
1810 param->parm.capture.capturemode = dev->run_mode;
1811 param->parm.capture.timeperframe.denominator =
1812 ov5693_res[dev->fmt_idx].fps;
1813 }
1814 return 0;
1815}
1816
1817static int ov5693_s_parm(struct v4l2_subdev *sd,
1818 struct v4l2_streamparm *param)
1819{
1820 struct ov5693_device *dev = to_ov5693_sensor(sd);
1821 dev->run_mode = param->parm.capture.capturemode;
1822
1823 mutex_lock(&dev->input_lock);
1824 switch (dev->run_mode) {
1825 case CI_MODE_VIDEO:
1826 ov5693_res = ov5693_res_video;
1827 N_RES = N_RES_VIDEO;
1828 break;
1829 case CI_MODE_STILL_CAPTURE:
1830 ov5693_res = ov5693_res_still;
1831 N_RES = N_RES_STILL;
1832 break;
1833 default:
1834 ov5693_res = ov5693_res_preview;
1835 N_RES = N_RES_PREVIEW;
1836 }
1837 mutex_unlock(&dev->input_lock);
1838 return 0;
1839}
1840
1841static int ov5693_g_frame_interval(struct v4l2_subdev *sd,
1842 struct v4l2_subdev_frame_interval *interval)
1843{
1844 struct ov5693_device *dev = to_ov5693_sensor(sd);
1845
1846 interval->interval.numerator = 1;
1847 interval->interval.denominator = ov5693_res[dev->fmt_idx].fps;
1848
1849 return 0;
1850}
1851
1852static int ov5693_enum_mbus_code(struct v4l2_subdev *sd,
1853 struct v4l2_subdev_pad_config *cfg,
1854 struct v4l2_subdev_mbus_code_enum *code)
1855{
1856 if (code->index >= MAX_FMTS)
1857 return -EINVAL;
1858
1859 code->code = MEDIA_BUS_FMT_SBGGR10_1X10;
1860 return 0;
1861}
1862
1863static int ov5693_enum_frame_size(struct v4l2_subdev *sd,
1864 struct v4l2_subdev_pad_config *cfg,
1865 struct v4l2_subdev_frame_size_enum *fse)
1866{
1867 int index = fse->index;
1868
1869 if (index >= N_RES)
1870 return -EINVAL;
1871
1872 fse->min_width = ov5693_res[index].width;
1873 fse->min_height = ov5693_res[index].height;
1874 fse->max_width = ov5693_res[index].width;
1875 fse->max_height = ov5693_res[index].height;
1876
1877 return 0;
1878
1879}
1880
1881static const struct v4l2_subdev_video_ops ov5693_video_ops = {
1882 .s_stream = ov5693_s_stream,
1883 .g_parm = ov5693_g_parm,
1884 .s_parm = ov5693_s_parm,
1885 .g_frame_interval = ov5693_g_frame_interval,
1886};
1887
1888static const struct v4l2_subdev_core_ops ov5693_core_ops = {
1889 .s_power = ov5693_s_power,
1890 .ioctl = ov5693_ioctl,
1891};
1892
1893static const struct v4l2_subdev_pad_ops ov5693_pad_ops = {
1894 .enum_mbus_code = ov5693_enum_mbus_code,
1895 .enum_frame_size = ov5693_enum_frame_size,
1896 .get_fmt = ov5693_get_fmt,
1897 .set_fmt = ov5693_set_fmt,
1898};
1899
1900static const struct v4l2_subdev_ops ov5693_ops = {
1901 .core = &ov5693_core_ops,
1902 .video = &ov5693_video_ops,
1903 .pad = &ov5693_pad_ops,
1904};
1905
1906static int ov5693_remove(struct i2c_client *client)
1907{
1908 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1909 struct ov5693_device *dev = to_ov5693_sensor(sd);
1910 dev_dbg(&client->dev, "ov5693_remove...\n");
1911
1912 dev->platform_data->csi_cfg(sd, 0);
1913
1914 v4l2_device_unregister_subdev(sd);
1915
1916 atomisp_gmin_remove_subdev(sd);
1917
1918 media_entity_cleanup(&dev->sd.entity);
1919 v4l2_ctrl_handler_free(&dev->ctrl_handler);
1920 kfree(dev);
1921
1922 return 0;
1923}
1924
e19c9205 1925static int ov5693_probe(struct i2c_client *client)
a49d2536
AC
1926{
1927 struct ov5693_device *dev;
1928 int i2c;
1929 int ret = 0;
1930 void *pdata = client->dev.platform_data;
1931 struct acpi_device *adev;
1932 unsigned int i;
1933
1934 /* Firmware workaround: Some modules use a "secondary default"
1935 * address of 0x10 which doesn't appear on schematics, and
1936 * some BIOS versions haven't gotten the memo. Work around
1937 * via config. */
1938 i2c = gmin_get_var_int(&client->dev, "I2CAddr", -1);
1939 if (i2c != -1) {
1940 dev_info(&client->dev,
1941 "Overriding firmware-provided I2C address (0x%x) with 0x%x\n",
1942 client->addr, i2c);
1943 client->addr = i2c;
1944 }
1945
1946 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
309167b9 1947 if (!dev)
a49d2536 1948 return -ENOMEM;
a49d2536
AC
1949
1950 mutex_init(&dev->input_lock);
1951
1952 dev->fmt_idx = 0;
1953 v4l2_i2c_subdev_init(&(dev->sd), client, &ov5693_ops);
1954
1955 adev = ACPI_COMPANION(&client->dev);
1956 if (adev) {
1957 adev->power.flags.power_resources = 0;
1958 pdata = gmin_camera_platform_data(&dev->sd,
1959 ATOMISP_INPUT_FORMAT_RAW_10,
1960 atomisp_bayer_order_bggr);
1961 }
1962
1963 if (!pdata)
1964 goto out_free;
1965
1966 ret = ov5693_s_config(&dev->sd, client->irq, pdata);
1967 if (ret)
1968 goto out_free;
1969
1970 ret = atomisp_register_i2c_module(&dev->sd, pdata, RAW_CAMERA);
1971 if (ret)
1972 goto out_free;
1973
1974 dev->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE;
1975 dev->pad.flags = MEDIA_PAD_FL_SOURCE;
1976 dev->format.code = MEDIA_BUS_FMT_SBGGR10_1X10;
1977 dev->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;
1978 ret =
1979 v4l2_ctrl_handler_init(&dev->ctrl_handler,
1980 ARRAY_SIZE(ov5693_controls));
1981 if (ret) {
1982 ov5693_remove(client);
1983 return ret;
1984 }
1985
1986 for (i = 0; i < ARRAY_SIZE(ov5693_controls); i++)
1987 v4l2_ctrl_new_custom(&dev->ctrl_handler, &ov5693_controls[i],
1988 NULL);
1989
1990 if (dev->ctrl_handler.error) {
1991 ov5693_remove(client);
1992 return dev->ctrl_handler.error;
1993 }
1994
1995 /* Use same lock for controls as for everything else. */
1996 dev->ctrl_handler.lock = &dev->input_lock;
1997 dev->sd.ctrl_handler = &dev->ctrl_handler;
1998
1999 ret = media_entity_pads_init(&dev->sd.entity, 1, &dev->pad);
2000 if (ret)
2001 ov5693_remove(client);
2002
2003 return ret;
2004out_free:
2005 v4l2_device_unregister_subdev(&dev->sd);
2006 kfree(dev);
2007 return ret;
2008}
2009
02cc60ca 2010static const struct acpi_device_id ov5693_acpi_match[] = {
a49d2536
AC
2011 {"INT33BE"},
2012 {},
2013};
2014MODULE_DEVICE_TABLE(acpi, ov5693_acpi_match);
2015
2016static struct i2c_driver ov5693_driver = {
2017 .driver = {
e19c9205
AS
2018 .name = "ov5693",
2019 .acpi_match_table = ov5693_acpi_match,
a49d2536 2020 },
e19c9205 2021 .probe_new = ov5693_probe,
a49d2536 2022 .remove = ov5693_remove,
a49d2536 2023};
2cb63c4c 2024module_i2c_driver(ov5693_driver);
a49d2536
AC
2025
2026MODULE_DESCRIPTION("A low-level driver for OmniVision 5693 sensors");
2027MODULE_LICENSE("GPL");