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