Skip to content
Digital Rhyme
Embedded camera sensor board with register-table and I2C control overlays

ov5693.c Source Code

Stylized source browser with permanent line anchors for explanation links.

1/*
2 * Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#include <linux/delay.h>
17#include <linux/fs.h>
18#include <linux/i2c.h>
19#include <linux/clk.h>
20#include <linux/miscdevice.h>
21#include <linux/slab.h>
22#include <linux/uaccess.h>
23#include <linux/regulator/consumer.h>
24#include <linux/gpio.h>
25#include <linux/module.h>
26#include <linux/regmap.h>
27#include <linux/gpio.h>
28#include <linux/of.h>
29#include <linux/of_device.h>
30#include <linux/of_gpio.h>
31#include <media/ov5693.h>
32#define OV5693_ID 0x5693
33#define OV5693_SENSOR_TYPE NVC_IMAGER_TYPE_RAW
34#define OV5693_RES_CHG_WAIT_TIME_MS 100
35#define OV5693_SIZEOF_I2C_BUF 16
36#define OV5693_TABLE_WAIT_MS 0
37#define OV5693_TABLE_END 1
38#define OV5693_TABLE_RESET 2
39#define OV5693_TABLE_RESET_TIMEOUT 50
40#define OV5693_LENS_MAX_APERTURE 0 /* _INT2FLOAT_DIVISOR */
41#define OV5693_LENS_FNUMBER 0 /* _INT2FLOAT_DIVISOR */
42#define OV5693_LENS_FOCAL_LENGTH 6120 /* _INT2FLOAT_DIVISOR */
43#define OV5693_LENS_VIEW_ANGLE_H 60000 /* _INT2FLOAT_DIVISOR */
44#define OV5693_LENS_VIEW_ANGLE_V 60000 /* _INT2FLOAT_DIVISOR */
45static struct nvc_gpio_init ov5693_gpio[] = {
46 { OV5693_GPIO_TYPE_PWRDN, GPIOF_OUT_INIT_LOW, "pwrdn", false, true, },
47};
48struct ov5693_info {
49 atomic_t in_use;
50 struct i2c_client *i2c_client;
51 struct ov5693_platform_data *pdata;
52 struct clk *mclk;
53 struct miscdevice miscdev;
54 int pwr_api;
55 int pwr_dev;
56 struct nvc_gpio gpio[ARRAY_SIZE(ov5693_gpio)];
57 struct ov5693_power_rail regulators;
58 bool power_on;
59 u32 mode_index;
60 bool mode_valid;
61 bool mode_enable;
62 unsigned test_pattern;
63 struct nvc_imager_static_nvc sdata;
64 u8 bin_en;
65 struct ov5693_fuseid fuseid;
66 struct regmap *regmap;
67 struct regulator *ext_vcm_vdd;
68};
69struct ov5693_reg {
70 u16 addr;
71 u16 val;
72};
73struct ov5693_mode_data {
74 struct nvc_imager_mode sensor_mode;
75 struct nvc_imager_dynamic_nvc sensor_dnvc;
76 struct ov5693_reg *p_mode_i2c;
77};
78static struct ov5693_platform_data ov5693_dflt_pdata = {
79 .cfg = 0,
80 .num = 0,
81 .dev_name = "camera",
82};
83/*
84 * NOTE: static vs dynamic
85 * If a member in the nvc_imager_static_nvc structure is not actually
86 * static data, then leave blank and add the parameter to the parameter
87 * read function that dynamically reads the data. The NVC user driver
88 * will call the parameter read for the data if the member data is 0.
89 * If the dynamic data becomes static during probe (a one time read
90 * such as device ID) then add the dynamic read to the _sdata_init
91 * function.
92 */
93static struct nvc_imager_static_nvc ov5693_dflt_sdata = {
94 .api_version = NVC_IMAGER_API_STATIC_VER,
95 .sensor_type = OV5693_SENSOR_TYPE,
96 .bits_per_pixel = 10,
97 .sensor_id = OV5693_ID,
98 .sensor_id_minor = 0,
99 .focal_len = OV5693_LENS_FOCAL_LENGTH,
100 .max_aperture = OV5693_LENS_MAX_APERTURE,
101 .fnumber = OV5693_LENS_FNUMBER,
102 .view_angle_h = OV5693_LENS_VIEW_ANGLE_H,
103 .view_angle_v = OV5693_LENS_VIEW_ANGLE_V,
104 .res_chg_wait_time = OV5693_RES_CHG_WAIT_TIME_MS,
105};
106static const struct ov5693_reg ov5693_2592x1944_i2c[] = {
107 {OV5693_TABLE_RESET, 0},/* Including sw reset */
108 {0x3001, 0x0a},
109 {0x3002, 0x80},
110 {0x3006, 0x00},
111 {0x3011, 0x21},
112 {0x3012, 0x09},
113 {0x3013, 0x10},
114 {0x3014, 0x00},
115 {0x3015, 0x08},
116 {0x3016, 0xf0},
117 {0x3017, 0xf0},
118 {0x3018, 0xf0},
119 {0x301b, 0xb4},
120 {0x301d, 0x02},
121 {0x3021, 0x00},
122 {0x3022, 0x01},
123 {0x3028, 0x44},
124 {0x3090, 0x02},
125 {0x3091, 0x0e},
126 {0x3092, 0x00},
127 {0x3093, 0x00},
128 {0x3098, 0x03},
129 {0x3099, 0x1e},
130 {0x309a, 0x02},
131 {0x309b, 0x01},
132 {0x309c, 0x00},
133 {0x30a0, 0xd2},
134 {0x30a2, 0x01},
135 {0x30b2, 0x00},
136 {0x30b3, 0x68},
137 {0x30b4, 0x03},
138 {0x30b5, 0x04},
139 {0x30b6, 0x01},
140 {0x3104, 0x21},
141 {0x3106, 0x00},
142 {0x3400, 0x04},
143 {0x3401, 0x00},
144 {0x3402, 0x04},
145 {0x3403, 0x00},
146 {0x3404, 0x04},
147 {0x3405, 0x00},
148 {0x3406, 0x01},
149 {0x3500, 0x00},
150 {0x3501, 0x7b},
151 {0x3502, 0x00},
152 {0x3503, 0x07},
153 {0x3504, 0x00},
154 {0x3505, 0x00},
155 {0x3506, 0x00},
156 {0x3507, 0x02},
157 {0x3508, 0x00},
158 {0x3509, 0x08},
159 {0x350a, 0x00},
160 {0x350b, 0x40},
161 {0x3601, 0x0a},
162 {0x3602, 0x18},
163 {0x3612, 0x80},
164 {0x3620, 0x54},
165 {0x3621, 0xc7},
166 {0x3622, 0x0f},
167 {0x3625, 0x10},
168 {0x3630, 0x55},
169 {0x3631, 0xf4},
170 {0x3632, 0x00},
171 {0x3633, 0x34},
172 {0x3634, 0x02},
173 {0x364d, 0x0d},
174 {0x364f, 0xdd},
175 {0x3660, 0x04},
176 {0x3662, 0x10},
177 {0x3663, 0xf1},
178 {0x3665, 0x00},
179 {0x3666, 0x20},
180 {0x3667, 0x00},
181 {0x366a, 0x80},
182 {0x3680, 0xe0},
183 {0x3681, 0x00},
184 {0x3700, 0x42},
185 {0x3701, 0x14},
186 {0x3702, 0xa0},
187 {0x3703, 0xd8},
188 {0x3704, 0x78},
189 {0x3705, 0x02},
190 {0x3708, 0xe2},
191 {0x3709, 0xc3},
192 {0x370a, 0x00},
193 {0x370b, 0x20},
194 {0x370c, 0x0c},
195 {0x370d, 0x11},
196 {0x370e, 0x00},
197 {0x370f, 0x40},
198 {0x3710, 0x00},
199 {0x371a, 0x1c},
200 {0x371b, 0x05},
201 {0x371c, 0x01},
202 {0x371e, 0xa1},
203 {0x371f, 0x0c},
204 {0x3721, 0x00},
205 {0x3726, 0x00},
206 {0x372a, 0x01},
207 {0x3730, 0x10},
208 {0x3738, 0x22},
209 {0x3739, 0xe5},
210 {0x373a, 0x50},
211 {0x373b, 0x02},
212 {0x373c, 0x41},
213 {0x373f, 0x02},
214 {0x3740, 0x42},
215 {0x3741, 0x02},
216 {0x3742, 0x18},
217 {0x3743, 0x01},
218 {0x3744, 0x02},
219 {0x3747, 0x10},
220 {0x374c, 0x04},
221 {0x3751, 0xf0},
222 {0x3752, 0x00},
223 {0x3753, 0x00},
224 {0x3754, 0xc0},
225 {0x3755, 0x00},
226 {0x3756, 0x1a},
227 {0x3758, 0x00},
228 {0x3759, 0x0f},
229 {0x376b, 0x44},
230 {0x375c, 0x04},
231 {0x3776, 0x00},
232 {0x377f, 0x08},
233 {0x3780, 0x22},
234 {0x3781, 0x0c},
235 {0x3784, 0x2c},
236 {0x3785, 0x1e},
237 {0x378f, 0xf5},
238 {0x3791, 0xb0},
239 {0x3795, 0x00},
240 {0x3796, 0x64},
241 {0x3797, 0x11},
242 {0x3798, 0x30},
243 {0x3799, 0x41},
244 {0x379a, 0x07},
245 {0x379b, 0xb0},
246 {0x379c, 0x0c},
247 {0x37c5, 0x00},
248 {0x37c6, 0x00},
249 {0x37c7, 0x00},
250 {0x37c9, 0x00},
251 {0x37ca, 0x00},
252 {0x37cb, 0x00},
253 {0x37de, 0x00},
254 {0x37df, 0x00},
255 {0x3800, 0x00},
256 {0x3801, 0x00},
257 {0x3802, 0x00},
258 {0x3803, 0x00},
259 {0x3804, 0x0a},
260 {0x3805, 0x3f},
261 {0x3806, 0x07},
262 {0x3807, 0xa3},
263 {0x3808, 0x0a},
264 {0x3809, 0x20},
265 {0x380a, 0x07},
266 {0x380b, 0x98},
267 {0x380c, 0x0a},
268 {0x380d, 0x80},
269 {0x380e, 0x07},
270 {0x380f, 0xc0},
271 {0x3810, 0x00},
272 {0x3811, 0x02},
273 {0x3812, 0x00},
274 {0x3813, 0x02},
275 {0x3814, 0x11},
276 {0x3815, 0x11},
277 {0x3820, 0x00},
278 {0x3821, 0x1e},
279 {0x3823, 0x00},
280 {0x3824, 0x00},
281 {0x3825, 0x00},
282 {0x3826, 0x00},
283 {0x3827, 0x00},
284 {0x382a, 0x04},
285 {0x3a04, 0x06},
286 {0x3a05, 0x14},
287 {0x3a06, 0x00},
288 {0x3a07, 0xfe},
289 {0x3b00, 0x00},
290 {0x3b02, 0x00},
291 {0x3b03, 0x00},
292 {0x3b04, 0x00},
293 {0x3b05, 0x00},
294 {0x3d00, 0x00},
295 {0x3d01, 0x00},
296 {0x3d02, 0x00},
297 {0x3d03, 0x00},
298 {0x3d04, 0x00},
299 {0x3d05, 0x00},
300 {0x3d06, 0x00},
301 {0x3d07, 0x00},
302 {0x3d08, 0x00},
303 {0x3d09, 0x00},
304 {0x3d0a, 0x00},
305 {0x3d0b, 0x00},
306 {0x3d0c, 0x00},
307 {0x3d0d, 0x00},
308 {0x3d0e, 0x00},
309 {0x3d0f, 0x00},
310 {0x3d80, 0x00},
311 {0x3d81, 0x00},
312 {0x3d84, 0x00},
313 {0x3e07, 0x20},
314 {0x4000, 0x08},
315 {0x4001, 0x04},
316 {0x4002, 0x45},
317 {0x4004, 0x08},
318 {0x4005, 0x18},
319 {0x4006, 0x20},
320 {0x4008, 0x24},
321 {0x4009, 0x10},
322 {0x400c, 0x00},
323 {0x400d, 0x00},
324 {0x4058, 0x00},
325 {0x4101, 0xb2},
326 {0x4303, 0x00},
327 {0x4304, 0x08},
328 {0x4307, 0x30},
329 {0x4311, 0x04},
330 {0x4315, 0x01},
331 {0x4511, 0x05},
332 {0x4512, 0x01},
333 {0x4806, 0x00},
334 {0x4816, 0x52},
335 {0x481f, 0x30},
336 {0x4826, 0x2c},
337 {0x4831, 0x64},
338 {0x4d00, 0x04},
339 {0x4d01, 0x71},
340 {0x4d02, 0xfd},
341 {0x4d03, 0xf5},
342 {0x4d04, 0x0c},
343 {0x4d05, 0xcc},
344 {0x4837, 0x09},
345 {0x5000, 0x06},
346 {0x5001, 0x01},
347 {0x5002, 0x00},
348 {0x5003, 0x20},
349 {0x5046, 0x0a},
350 {0x5013, 0x00},
351 {0x5046, 0x0a},
352 {0x5780, 0x1c},
353 {0x5786, 0x20},
354 {0x5787, 0x10},
355 {0x5788, 0x18},
356 {0x578a, 0x04},
357 {0x578b, 0x02},
358 {0x578c, 0x02},
359 {0x578e, 0x06},
360 {0x578f, 0x02},
361 {0x5790, 0x02},
362 {0x5791, 0xff},
363 {0x5842, 0x01},
364 {0x5843, 0x2b},
365 {0x5844, 0x01},
366 {0x5845, 0x92},
367 {0x5846, 0x01},
368 {0x5847, 0x8f},
369 {0x5848, 0x01},
370 {0x5849, 0x0c},
371 {0x5e00, 0x00},
372 {0x5e10, 0x0c},
373 {0x0100, 0x01},
374 {OV5693_TABLE_END, 0x0000}
375};
376static const struct ov5693_reg ov5693_1296x972_i2c[] = {
377 {OV5693_TABLE_RESET, 0},/* Including sw reset */
378 {0x0103, 0x01},
379 {0x3001, 0x0a},
380 {0x3002, 0x80},
381 {0x3006, 0x00},
382 {0x3011, 0x21},
383 {0x3012, 0x09},
384 {0x3013, 0x10},
385 {0x3014, 0x00},
386 {0x3015, 0x08},
387 {0x3016, 0xf0},
388 {0x3017, 0xf0},
389 {0x3018, 0xf0},
390 {0x301b, 0xb4},
391 {0x301d, 0x02},
392 {0x3021, 0x00},
393 {0x3022, 0x01},
394 {0x3028, 0x44},
395 {0x3098, 0x03},
396 {0x3099, 0x1e},
397 {0x309a, 0x02},
398 {0x309b, 0x01},
399 {0x309c, 0x00},
400 {0x30a0, 0xd2},
401 {0x30a2, 0x01},
402 {0x30b2, 0x00},
403 {0x30b3, 0x64},
404 {0x30b4, 0x03},
405 {0x30b5, 0x04},
406 {0x30b6, 0x01},
407 {0x3104, 0x21},
408 {0x3106, 0x00},
409 {0x3400, 0x04},
410 {0x3401, 0x00},
411 {0x3402, 0x04},
412 {0x3403, 0x00},
413 {0x3404, 0x04},
414 {0x3405, 0x00},
415 {0x3406, 0x01},
416 {0x3500, 0x00},
417 {0x3501, 0x7b},
418 {0x3502, 0x00},
419 {0x3503, 0x07},
420 {0x3504, 0x00},
421 {0x3505, 0x00},
422 {0x3506, 0x00},
423 {0x3507, 0x02},
424 {0x3508, 0x00},
425 {0x3509, 0x08},
426 {0x350a, 0x00},
427 {0x350b, 0x40},
428 {0x3601, 0x0a},
429 {0x3602, 0x38},
430 {0x3612, 0x80},
431 {0x3620, 0x54},
432 {0x3621, 0xc7},
433 {0x3622, 0x0f},
434 {0x3625, 0x10},
435 {0x3630, 0x55},
436 {0x3631, 0xf4},
437 {0x3632, 0x00},
438 {0x3633, 0x34},
439 {0x3634, 0x02},
440 {0x364d, 0x0d},
441 {0x364f, 0xdd},
442 {0x3660, 0x04},
443 {0x3662, 0x10},
444 {0x3663, 0xf1},
445 {0x3665, 0x00},
446 {0x3666, 0x20},
447 {0x3667, 0x00},
448 {0x366a, 0x80},
449 {0x3680, 0xe0},
450 {0x3681, 0x00},
451 {0x3700, 0x42},
452 {0x3701, 0x14},
453 {0x3702, 0xa0},
454 {0x3703, 0xd8},
455 {0x3704, 0x78},
456 {0x3705, 0x02},
457 {0x3708, 0xe6},
458 {0x3709, 0xc3},
459 {0x370a, 0x00},
460 {0x370b, 0x20},
461 {0x370c, 0x0c},
462 {0x370d, 0x11},
463 {0x370e, 0x00},
464 {0x370f, 0x40},
465 {0x3710, 0x00},
466 {0x371a, 0x1c},
467 {0x371b, 0x05},
468 {0x371c, 0x01},
469 {0x371e, 0xa1},
470 {0x371f, 0x0c},
471 {0x3721, 0x00},
472 {0x3724, 0x10},
473 {0x3726, 0x00},
474 {0x372a, 0x01},
475 {0x3730, 0x10},
476 {0x3738, 0x22},
477 {0x3739, 0xe5},
478 {0x373a, 0x50},
479 {0x373b, 0x02},
480 {0x373c, 0x41},
481 {0x373f, 0x02},
482 {0x3740, 0x42},
483 {0x3741, 0x02},
484 {0x3742, 0x18},
485 {0x3743, 0x01},
486 {0x3744, 0x02},
487 {0x3747, 0x10},
488 {0x374c, 0x04},
489 {0x3751, 0xf0},
490 {0x3752, 0x00},
491 {0x3753, 0x00},
492 {0x3754, 0xc0},
493 {0x3755, 0x00},
494 {0x3756, 0x1a},
495 {0x3758, 0x00},
496 {0x3759, 0x0f},
497 {0x376b, 0x44},
498 {0x375c, 0x04},
499 {0x3774, 0x10},
500 {0x3776, 0x00},
501 {0x377f, 0x08},
502 {0x3780, 0x22},
503 {0x3781, 0x0c},
504 {0x3784, 0x2c},
505 {0x3785, 0x1e},
506 {0x378f, 0xf5},
507 {0x3791, 0xb0},
508 {0x3795, 0x00},
509 {0x3796, 0x64},
510 {0x3797, 0x11},
511 {0x3798, 0x30},
512 {0x3799, 0x41},
513 {0x379a, 0x07},
514 {0x379b, 0xb0},
515 {0x379c, 0x0c},
516 {0x37c5, 0x00},
517 {0x37c6, 0x00},
518 {0x37c7, 0x00},
519 {0x37c9, 0x00},
520 {0x37ca, 0x00},
521 {0x37cb, 0x00},
522 {0x37de, 0x00},
523 {0x37df, 0x00},
524 {0x3800, 0x00},
525 {0x3801, 0x00},
526 {0x3802, 0x00},
527 {0x3803, 0x00},
528 {0x3804, 0x0a},
529 {0x3805, 0x3f},
530 {0x3806, 0x07},
531 {0x3807, 0xa3},
532 {0x3808, 0x05},
533 {0x3809, 0x10},
534 {0x380a, 0x03},
535 {0x380b, 0xcc},
536 {0x380c, 0x0a},
537 {0x380d, 0x80},
538 {0x380e, 0x07},
539 {0x380f, 0xc0},
540 {0x3810, 0x00},
541 {0x3811, 0x02},
542 {0x3812, 0x00},
543 {0x3813, 0x02},
544 {0x3814, 0x31},
545 {0x3815, 0x31},
546 {0x3820, 0x01},
547 {0x3821, 0x1f},
548 {0x3823, 0x00},
549 {0x3824, 0x00},
550 {0x3825, 0x00},
551 {0x3826, 0x00},
552 {0x3827, 0x00},
553 {0x382a, 0x04},
554 {0x3a04, 0x06},
555 {0x3a05, 0x14},
556 {0x3a06, 0x00},
557 {0x3a07, 0xfe},
558 {0x3b00, 0x00},
559 {0x3b02, 0x00},
560 {0x3b03, 0x00},
561 {0x3b04, 0x00},
562 {0x3b05, 0x00},
563 {0x3e07, 0x20},
564 {0x4000, 0x08},
565 {0x4001, 0x04},
566 {0x4002, 0x45},
567 {0x4004, 0x08},
568 {0x4005, 0x18},
569 {0x4006, 0x20},
570 {0x4008, 0x24},
571 {0x4009, 0x40},
572 {0x400c, 0x00},
573 {0x400d, 0x00},
574 {0x4058, 0x00},
575 {0x404e, 0x37},
576 {0x404f, 0x8f},
577 {0x4058, 0x00},
578 {0x4101, 0xb2},
579 {0x4303, 0x00},
580 {0x4304, 0x08},
581 {0x4307, 0x30},
582 {0x4311, 0x04},
583 {0x4315, 0x01},
584 {0x4511, 0x05},
585 {0x4512, 0x01},
586 {0x4806, 0x00},
587 {0x4816, 0x52},
588 {0x481f, 0x30},
589 {0x4826, 0x2c},
590 {0x4831, 0x64},
591 {0x4d00, 0x04},
592 {0x4d01, 0x71},
593 {0x4d02, 0xfd},
594 {0x4d03, 0xf5},
595 {0x4d04, 0x0c},
596 {0x4d05, 0xcc},
597 {0x4837, 0x0a},
598 {0x5000, 0x06},
599 {0x5001, 0x01},
600 {0x5002, 0x00},
601 {0x5003, 0x20},
602 {0x5046, 0x0a},
603 {0x5013, 0x00},
604 {0x5046, 0x0a},
605 {0x5780, 0x1c},
606 {0x5786, 0x20},
607 {0x5787, 0x10},
608 {0x5788, 0x18},
609 {0x578a, 0x04},
610 {0x578b, 0x02},
611 {0x578c, 0x02},
612 {0x578e, 0x06},
613 {0x578f, 0x02},
614 {0x5790, 0x02},
615 {0x5791, 0xff},
616 {0x5842, 0x01},
617 {0x5843, 0x2b},
618 {0x5844, 0x01},
619 {0x5845, 0x92},
620 {0x5846, 0x01},
621 {0x5847, 0x8f},
622 {0x5848, 0x01},
623 {0x5849, 0x0c},
624 {0x5e00, 0x00},
625 {0x5e10, 0x0c},
626 {0x0100, 0x01},
627 {OV5693_TABLE_END, 0x0000}
628};
629static const struct ov5693_reg ov5693_1920x1080_i2c[] = {
630 {OV5693_TABLE_RESET, 0x0},/*, 0xIncluding, 0xsw, 0xreset, 0x*/
631 {0x3001, 0x0a},
632 {0x3002, 0x80},
633 {0x3006, 0x00},
634 {0x3011, 0x21},
635 {0x3012, 0x09},
636 {0x3013, 0x10},
637 {0x3014, 0x00},
638 {0x3015, 0x08},
639 {0x3016, 0xf0},
640 {0x3017, 0xf0},
641 {0x3018, 0xf0},
642 {0x301b, 0xb4},
643 {0x301d, 0x02},
644 {0x3021, 0x00},
645 {0x3022, 0x01},
646 {0x3028, 0x44},
647 {0x3098, 0x03},
648 {0x3099, 0x1e},
649 {0x309a, 0x02},
650 {0x309b, 0x01},
651 {0x309c, 0x00},
652 {0x30a0, 0xd2},
653 {0x30a2, 0x01},
654 {0x30b2, 0x00},
655 {0x30b3, 0x64},
656 {0x30b4, 0x03},
657 {0x30b5, 0x04},
658 {0x30b6, 0x01},
659 {0x3104, 0x21},
660 {0x3106, 0x00},
661 {0x3400, 0x04},
662 {0x3401, 0x00},
663 {0x3402, 0x04},
664 {0x3403, 0x00},
665 {0x3404, 0x04},
666 {0x3405, 0x00},
667 {0x3406, 0x01},
668 {0x3500, 0x00},
669 {0x3501, 0x7b},
670 {0x3502, 0x00},
671 {0x3503, 0x07},
672 {0x3504, 0x00},
673 {0x3505, 0x00},
674 {0x3506, 0x00},
675 {0x3507, 0x02},
676 {0x3508, 0x00},
677 {0x3509, 0x08},
678 {0x350a, 0x00},
679 {0x350b, 0x40},
680 {0x3601, 0x0a},
681 {0x3602, 0x38},
682 {0x3612, 0x80},
683 {0x3620, 0x54},
684 {0x3621, 0xc7},
685 {0x3622, 0x0f},
686 {0x3625, 0x10},
687 {0x3630, 0x55},
688 {0x3631, 0xf4},
689 {0x3632, 0x00},
690 {0x3633, 0x34},
691 {0x3634, 0x02},
692 {0x364d, 0x0d},
693 {0x364f, 0xdd},
694 {0x3660, 0x04},
695 {0x3662, 0x10},
696 {0x3663, 0xf1},
697 {0x3665, 0x00},
698 {0x3666, 0x20},
699 {0x3667, 0x00},
700 {0x366a, 0x80},
701 {0x3680, 0xe0},
702 {0x3681, 0x00},
703 {0x3700, 0x42},
704 {0x3701, 0x14},
705 {0x3702, 0xa0},
706 {0x3703, 0xd8},
707 {0x3704, 0x78},
708 {0x3705, 0x02},
709 {0x3708, 0xe2},
710 {0x3709, 0xc3},
711 {0x370a, 0x00},
712 {0x370b, 0x20},
713 {0x370c, 0x0c},
714 {0x370d, 0x11},
715 {0x370e, 0x00},
716 {0x370f, 0x40},
717 {0x3710, 0x00},
718 {0x371a, 0x1c},
719 {0x371b, 0x05},
720 {0x371c, 0x01},
721 {0x371e, 0xa1},
722 {0x371f, 0x0c},
723 {0x3721, 0x00},
724 {0x3724, 0x10},
725 {0x3726, 0x00},
726 {0x372a, 0x01},
727 {0x3730, 0x10},
728 {0x3738, 0x22},
729 {0x3739, 0xe5},
730 {0x373a, 0x50},
731 {0x373b, 0x02},
732 {0x373c, 0x41},
733 {0x373f, 0x02},
734 {0x3740, 0x42},
735 {0x3741, 0x02},
736 {0x3742, 0x18},
737 {0x3743, 0x01},
738 {0x3744, 0x02},
739 {0x3747, 0x10},
740 {0x374c, 0x04},
741 {0x3751, 0xf0},
742 {0x3752, 0x00},
743 {0x3753, 0x00},
744 {0x3754, 0xc0},
745 {0x3755, 0x00},
746 {0x3756, 0x1a},
747 {0x3758, 0x00},
748 {0x3759, 0x0f},
749 {0x376b, 0x44},
750 {0x375c, 0x04},
751 {0x3774, 0x10},
752 {0x3776, 0x00},
753 {0x377f, 0x08},
754 {0x3780, 0x22},
755 {0x3781, 0x0c},
756 {0x3784, 0x2c},
757 {0x3785, 0x1e},
758 {0x378f, 0xf5},
759 {0x3791, 0xb0},
760 {0x3795, 0x00},
761 {0x3796, 0x64},
762 {0x3797, 0x11},
763 {0x3798, 0x30},
764 {0x3799, 0x41},
765 {0x379a, 0x07},
766 {0x379b, 0xb0},
767 {0x379c, 0x0c},
768 {0x37c5, 0x00},
769 {0x37c6, 0x00},
770 {0x37c7, 0x00},
771 {0x37c9, 0x00},
772 {0x37ca, 0x00},
773 {0x37cb, 0x00},
774 {0x37de, 0x00},
775 {0x37df, 0x00},
776 {0x3800, 0x00},
777 {0x3801, 0x00},
778 {0x3802, 0x00},
779 {0x3803, 0xf8},
780 {0x3804, 0x0a},
781 {0x3805, 0x3f},
782 {0x3806, 0x06},
783 {0x3807, 0xab},
784 {0x3808, 0x07},
785 {0x3809, 0x80},
786 {0x380a, 0x04},
787 {0x380b, 0x38},
788 {0x380c, 0x0a},
789 {0x380d, 0x80},
790 {0x380e, 0x07},
791 {0x380f, 0xc0},
792 {0x3810, 0x00},
793 {0x3811, 0x02},
794 {0x3812, 0x00},
795 {0x3813, 0x02},
796 {0x3814, 0x11},
797 {0x3815, 0x11},
798 {0x3820, 0x00},
799 {0x3821, 0x1e},
800 {0x3823, 0x00},
801 {0x3824, 0x00},
802 {0x3825, 0x00},
803 {0x3826, 0x00},
804 {0x3827, 0x00},
805 {0x382a, 0x04},
806 {0x3a04, 0x06},
807 {0x3a05, 0x14},
808 {0x3a06, 0x00},
809 {0x3a07, 0xfe},
810 {0x3b00, 0x00},
811 {0x3b02, 0x00},
812 {0x3b03, 0x00},
813 {0x3b04, 0x00},
814 {0x3b05, 0x00},
815 {0x3e07, 0x20},
816 {0x4000, 0x08},
817 {0x4001, 0x04},
818 {0x4002, 0x45},
819 {0x4004, 0x08},
820 {0x4005, 0x18},
821 {0x4006, 0x20},
822 {0x4008, 0x24},
823 {0x4009, 0x40},
824 {0x400c, 0x00},
825 {0x400d, 0x00},
826 {0x4058, 0x00},
827 {0x404e, 0x37},
828 {0x404f, 0x8f},
829 {0x4058, 0x00},
830 {0x4101, 0xb2},
831 {0x4303, 0x00},
832 {0x4304, 0x08},
833 {0x4307, 0x30},
834 {0x4311, 0x04},
835 {0x4315, 0x01},
836 {0x4511, 0x05},
837 {0x4512, 0x01},
838 {0x4806, 0x00},
839 {0x4816, 0x52},
840 {0x481f, 0x30},
841 {0x4826, 0x2c},
842 {0x4831, 0x64},
843 {0x4d00, 0x04},
844 {0x4d01, 0x71},
845 {0x4d02, 0xfd},
846 {0x4d03, 0xf5},
847 {0x4d04, 0x0c},
848 {0x4d05, 0xcc},
849 {0x4837, 0x0a},
850 {0x5000, 0x06},
851 {0x5001, 0x01},
852 {0x5002, 0x80},
853 {0x5003, 0x20},
854 {0x5046, 0x0a},
855 {0x5013, 0x00},
856 {0x5046, 0x0a},
857 {0x5780, 0x1c},
858 {0x5786, 0x20},
859 {0x5787, 0x10},
860 {0x5788, 0x18},
861 {0x578a, 0x04},
862 {0x578b, 0x02},
863 {0x578c, 0x02},
864 {0x578e, 0x06},
865 {0x578f, 0x02},
866 {0x5790, 0x02},
867 {0x5791, 0xff},
868 {0x5842, 0x01},
869 {0x5843, 0x2b},
870 {0x5844, 0x01},
871 {0x5845, 0x92},
872 {0x5846, 0x01},
873 {0x5847, 0x8f},
874 {0x5848, 0x01},
875 {0x5849, 0x0c},
876 {0x5e00, 0x00},
877 {0x5e10, 0x0c},
878 {0x0100, 0x01},
879 {OV5693_TABLE_END, 0x0000}
880};
881static const struct ov5693_reg ov5693_1280x720_120fps_i2c[] = {
882 {OV5693_TABLE_RESET, 0},/* Including sw reset */
883 {0x3001, 0x0a},
884 {0x3002, 0x80},
885 {0x3006, 0x00},
886 {0x3011, 0x21},
887 {0x3012, 0x09},
888 {0x3013, 0x10},
889 {0x3014, 0x00},
890 {0x3015, 0x08},
891 {0x3016, 0xf0},
892 {0x3017, 0xf0},
893 {0x3018, 0xf0},
894 {0x301b, 0xb4},
895 {0x301d, 0x02},
896 {0x3021, 0x00},
897 {0x3022, 0x01},
898 {0x3028, 0x44},
899 {0x3098, 0x03},
900 {0x3099, 0x1e},
901 {0x309a, 0x02},
902 {0x309b, 0x01},
903 {0x309c, 0x00},
904 {0x30a0, 0xd2},
905 {0x30a2, 0x01},
906 {0x30b2, 0x00},
907 {0x30b3, 0x64},
908 {0x30b4, 0x03},
909 {0x30b5, 0x04},
910 {0x30b6, 0x01},
911 {0x3104, 0x21},
912 {0x3106, 0x00},
913 {0x3400, 0x04},
914 {0x3401, 0x00},
915 {0x3402, 0x04},
916 {0x3403, 0x00},
917 {0x3404, 0x04},
918 {0x3405, 0x00},
919 {0x3406, 0x01},
920 {0x3500, 0x00},
921 {0x3501, 0x2e},
922 {0x3502, 0x80},
923 {0x3503, 0x07},
924 {0x3504, 0x00},
925 {0x3505, 0x00},
926 {0x3506, 0x00},
927 {0x3507, 0x02},
928 {0x3508, 0x00},
929 {0x3509, 0x08},
930 {0x350a, 0x00},
931 {0x350b, 0x40},
932 {0x3601, 0x0a},
933 {0x3602, 0x38},
934 {0x3612, 0x80},
935 {0x3620, 0x54},
936 {0x3621, 0xc7},
937 {0x3622, 0x0f},
938 {0x3625, 0x10},
939 {0x3630, 0x55},
940 {0x3631, 0xf4},
941 {0x3632, 0x00},
942 {0x3633, 0x34},
943 {0x3634, 0x02},
944 {0x364d, 0x0d},
945 {0x364f, 0xdd},
946 {0x3660, 0x04},
947 {0x3662, 0x10},
948 {0x3663, 0xf1},
949 {0x3665, 0x00},
950 {0x3666, 0x20},
951 {0x3667, 0x00},
952 {0x366a, 0x80},
953 {0x3680, 0xe0},
954 {0x3681, 0x00},
955 {0x3700, 0x42},
956 {0x3701, 0x14},
957 {0x3702, 0xa0},
958 {0x3703, 0xd8},
959 {0x3704, 0x78},
960 {0x3705, 0x02},
961 {0x3708, 0xe6},
962 {0x3709, 0xc7},
963 {0x370a, 0x00},
964 {0x370b, 0x20},
965 {0x370c, 0x0c},
966 {0x370d, 0x11},
967 {0x370e, 0x00},
968 {0x370f, 0x40},
969 {0x3710, 0x00},
970 {0x371a, 0x1c},
971 {0x371b, 0x05},
972 {0x371c, 0x01},
973 {0x371e, 0xa1},
974 {0x371f, 0x0c},
975 {0x3721, 0x00},
976 {0x3724, 0x10},
977 {0x3726, 0x00},
978 {0x372a, 0x01},
979 {0x3730, 0x10},
980 {0x3738, 0x22},
981 {0x3739, 0xe5},
982 {0x373a, 0x50},
983 {0x373b, 0x02},
984 {0x373c, 0x41},
985 {0x373f, 0x02},
986 {0x3740, 0x42},
987 {0x3741, 0x02},
988 {0x3742, 0x18},
989 {0x3743, 0x01},
990 {0x3744, 0x02},
991 {0x3747, 0x10},
992 {0x374c, 0x04},
993 {0x3751, 0xf0},
994 {0x3752, 0x00},
995 {0x3753, 0x00},
996 {0x3754, 0xc0},
997 {0x3755, 0x00},
998 {0x3756, 0x1a},
999 {0x3758, 0x00},
1000 {0x3759, 0x0f},
1001 {0x376b, 0x44},
1002 {0x375c, 0x04},
1003 {0x3774, 0x10},
1004 {0x3776, 0x00},
1005 {0x377f, 0x08},
1006 {0x3780, 0x22},
1007 {0x3781, 0x0c},
1008 {0x3784, 0x2c},
1009 {0x3785, 0x1e},
1010 {0x378f, 0xf5},
1011 {0x3791, 0xb0},
1012 {0x3795, 0x00},
1013 {0x3796, 0x64},
1014 {0x3797, 0x11},
1015 {0x3798, 0x30},
1016 {0x3799, 0x41},
1017 {0x379a, 0x07},
1018 {0x379b, 0xb0},
1019 {0x379c, 0x0c},
1020 {0x37c5, 0x00},
1021 {0x37c6, 0x00},
1022 {0x37c7, 0x00},
1023 {0x37c9, 0x00},
1024 {0x37ca, 0x00},
1025 {0x37cb, 0x00},
1026 {0x37de, 0x00},
1027 {0x37df, 0x00},
1028 {0x3800, 0x00},
1029 {0x3801, 0x00},
1030 {0x3802, 0x00},
1031 {0x3803, 0xf4},
1032 {0x3804, 0x0a},
1033 {0x3805, 0x3f},
1034 {0x3806, 0x06},
1035 {0x3807, 0xab},
1036 {0x3808, 0x05},
1037 {0x3809, 0x00},
1038 {0x380a, 0x02},
1039 {0x380b, 0xd0},
1040 {0x380c, 0x06},
1041 {0x380d, 0xd8},
1042 {0x380e, 0x02},
1043 {0x380f, 0xf8},
1044 {0x3810, 0x00},
1045 {0x3811, 0x02},
1046 {0x3812, 0x00},
1047 {0x3813, 0x02},
1048 {0x3814, 0x31},
1049 {0x3815, 0x31},
1050 {0x3820, 0x04},
1051 {0x3821, 0x1f},
1052 {0x3823, 0x00},
1053 {0x3824, 0x00},
1054 {0x3825, 0x00},
1055 {0x3826, 0x00},
1056 {0x3827, 0x00},
1057 {0x382a, 0x04},
1058 {0x3a04, 0x06},
1059 {0x3a05, 0x14},
1060 {0x3a06, 0x00},
1061 {0x3a07, 0xfe},
1062 {0x3b00, 0x00},
1063 {0x3b02, 0x00},
1064 {0x3b03, 0x00},
1065 {0x3b04, 0x00},
1066 {0x3b05, 0x00},
1067 {0x3e07, 0x20},
1068 {0x4000, 0x08},
1069 {0x4001, 0x04},
1070 {0x4002, 0x45},
1071 {0x4004, 0x08},
1072 {0x4005, 0x18},
1073 {0x4006, 0x20},
1074 {0x4008, 0x24},
1075 {0x4009, 0x40},
1076 {0x400c, 0x00},
1077 {0x400d, 0x00},
1078 {0x4058, 0x00},
1079 {0x404e, 0x37},
1080 {0x404f, 0x8f},
1081 {0x4058, 0x00},
1082 {0x4101, 0xb2},
1083 {0x4303, 0x00},
1084 {0x4304, 0x08},
1085 {0x4307, 0x30},
1086 {0x4311, 0x04},
1087 {0x4315, 0x01},
1088 {0x4511, 0x05},
1089 {0x4512, 0x01},
1090 {0x4806, 0x00},
1091 {0x4816, 0x52},
1092 {0x481f, 0x30},
1093 {0x4826, 0x2c},
1094 {0x4831, 0x64},
1095 {0x4d00, 0x04},
1096 {0x4d01, 0x71},
1097 {0x4d02, 0xfd},
1098 {0x4d03, 0xf5},
1099 {0x4d04, 0x0c},
1100 {0x4d05, 0xcc},
1101 {0x4837, 0x0a},
1102 {0x5000, 0x06},
1103 {0x5001, 0x01},
1104 {0x5002, 0x00},
1105 {0x5003, 0x20},
1106 {0x5046, 0x0a},
1107 {0x5013, 0x00},
1108 {0x5046, 0x0a},
1109 {0x5780, 0x1c},
1110 {0x5786, 0x20},
1111 {0x5787, 0x10},
1112 {0x5788, 0x18},
1113 {0x578a, 0x04},
1114 {0x578b, 0x02},
1115 {0x578c, 0x02},
1116 {0x578e, 0x06},
1117 {0x578f, 0x02},
1118 {0x5790, 0x02},
1119 {0x5791, 0xff},
1120 {0x5842, 0x01},
1121 {0x5843, 0x2b},
1122 {0x5844, 0x01},
1123 {0x5845, 0x92},
1124 {0x5846, 0x01},
1125 {0x5847, 0x8f},
1126 {0x5848, 0x01},
1127 {0x5849, 0x0c},
1128 {0x5e00, 0x00},
1129 {0x5e10, 0x0c},
1130 {0x0100, 0x01},
1131 {0x350b, 0xF8},
1132 {OV5693_TABLE_END, 0x0000}
1133};
1134enum {
1135 OV5693_MODE_2592x1944 = 0,
1136 OV5693_MODE_1920x1080,
1137 OV5693_MODE_1296x972,
1138 OV5693_MODE_1280x720_120FPS,
1139};
1140static const struct ov5693_reg *mode_table[] = {
1141 [OV5693_MODE_2592x1944] = ov5693_2592x1944_i2c,
1142 [OV5693_MODE_1920x1080] = ov5693_1920x1080_i2c,
1143 [OV5693_MODE_1296x972] = ov5693_1296x972_i2c,
1144 [OV5693_MODE_1280x720_120FPS] = ov5693_1280x720_120fps_i2c,
1145};
1146static int ov5693_i2c_rd8(struct ov5693_info *info, u16 reg, u8 *val)
1147{
1148 unsigned int data;
1149 int ret = regmap_read(info->regmap, reg, &data);
1150 *val = data;
1151 return ret;
1152}
1153static int ov5693_i2c_wr_table(struct ov5693_info *info,
1154 const struct ov5693_reg table[])
1155{
1156 int err;
1157 int buf_count = 0;
1158 const struct ov5693_reg *next, *n_next;
1159 u16 i2c_reg = 0;
1160 u8 i2c_buf[OV5693_SIZEOF_I2C_BUF];
1161 u8 *b_ptr = i2c_buf;
1162 u8 reset_status = 1;
1163 u8 reset_tries_left = OV5693_TABLE_RESET_TIMEOUT;
1164 for (next = table; next->addr != OV5693_TABLE_END; next++) {
1165 if (next->addr == OV5693_TABLE_WAIT_MS) {
1166 msleep(next->val);
1167 continue;
1168 } else if (next->addr == OV5693_TABLE_RESET) {
1169 err = regmap_write(info->regmap, 0x0103, 0x01);
1170 if (err)
1171 return err;
1172 while (reset_status) {
1173 usleep_range(200, 300);
1174 if (reset_tries_left < 1)
1175 return -EIO;
1176 err = ov5693_i2c_rd8(info, 0x0103,
1177 &reset_status);
1178 if (err)
1179 return err;
1180 reset_status &= 0x01;
1181 reset_tries_left -= 1;
1182 }
1183 continue;
1184 }
1185 if (buf_count == 0) {
1186 b_ptr = i2c_buf;
1187 i2c_reg = next->addr;
1188 }
1189 *b_ptr++ = next->val;
1190 buf_count++;
1191 n_next = next + 1;
1192 if (n_next->addr == next->addr + 1 &&
1193 n_next->addr != OV5693_TABLE_WAIT_MS &&
1194 buf_count < OV5693_SIZEOF_I2C_BUF &&
1195 n_next->addr != OV5693_TABLE_RESET &&
1196 n_next->addr != OV5693_TABLE_END)
1197 continue;
1198 err = regmap_bulk_write(info->regmap, i2c_reg,
1199 i2c_buf, buf_count);
1200 if (err)
1201 return err;
1202 buf_count = 0;
1203 }
1204 return 0;
1205}
1206static inline int ov5693_frame_length_reg(struct ov5693_reg *regs,
1207 u32 frame_length)
1208{
1209 regs->addr = 0x380E;
1210 regs->val = (frame_length >> 8) & 0xff;
1211 (regs + 1)->addr = 0x380F;
1212 (regs + 1)->val = (frame_length) & 0xff;
1213 return 2;
1214}
1215static inline int ov5693_coarse_time_reg(struct ov5693_reg *regs,
1216 u32 coarse_time)
1217{
1218 regs->addr = 0x3500;
1219 regs->val = (coarse_time >> 12) & 0xff;
1220 (regs + 1)->addr = 0x3501;
1221 (regs + 1)->val = (coarse_time >> 4) & 0xff;
1222 (regs + 2)->addr = 0x3502;
1223 (regs + 2)->val = (coarse_time & 0xf) << 4;
1224 return 3;
1225}
1226#define OV5693_ENTER_GROUP_HOLD(group_hold) \
1227 do { \
1228 if (group_hold) { \
1229 reg_list[offset].addr = 0x3208; \
1230 reg_list[offset].val = 0x01;\
1231 offset++; \
1232 } \
1233 } while (0)
1234#define OV5693_LEAVE_GROUP_HOLD(group_hold) \
1235 do { \
1236 if (group_hold) { \
1237 reg_list[offset].addr = 0x3208; \
1238 reg_list[offset].val = 0x11;\
1239 offset++; \
1240 reg_list[offset].addr = 0x3208; \
1241 reg_list[offset].val = 0xe1;\
1242 offset++; \
1243 } \
1244 } while (0)
1245static int ov5693_set_frame_length(struct ov5693_info *info,
1246 u32 frame_length, bool group_hold)
1247{
1248 struct ov5693_reg reg_list[9];
1249 int err = 0;
1250 int offset = 0;
1251 OV5693_ENTER_GROUP_HOLD(group_hold);
1252 offset += ov5693_frame_length_reg(reg_list + offset, frame_length);
1253 OV5693_LEAVE_GROUP_HOLD(group_hold);
1254 reg_list[offset].addr = OV5693_TABLE_END;
1255 offset++;
1256 err = ov5693_i2c_wr_table(info, reg_list);
1257 return err;
1258}
1259static int ov5693_set_coarse_time(struct ov5693_info *info,
1260 u32 coarse_time, bool group_hold)
1261{
1262 struct ov5693_reg reg_list[16];
1263 int err = 0;
1264 int offset = 0;
1265 OV5693_ENTER_GROUP_HOLD(group_hold);
1266 offset += ov5693_coarse_time_reg(reg_list + offset, coarse_time);
1267 OV5693_LEAVE_GROUP_HOLD(group_hold);
1268 reg_list[offset].addr = OV5693_TABLE_END;
1269 offset++;
1270 err = ov5693_i2c_wr_table(info, reg_list);
1271 return err;
1272}
1273static inline int ov5693_gain_reg(struct ov5693_reg *regs, u32 gain)
1274{
1275 (regs)->addr = 0x350B;
1276 (regs)->val = gain;
1277 return 1;
1278}
1279static int ov5693_bin_wr(struct ov5693_info *info, u8 enable)
1280{
1281 int err = 0;
1282 if (enable == info->bin_en)
1283 return 0;
1284 if (!err)
1285 info->bin_en = enable;
1286 dev_dbg(&info->i2c_client->dev, "%s bin_en=%x err=%d\n",
1287 __func__, info->bin_en, err);
1288 return err;
1289}
1290static int ov5693_exposure_wr(struct ov5693_info *info,
1291 struct ov5693_mode *mode)
1292{
1293 struct ov5693_reg reg_list[16];
1294 int err = 0;
1295 int offset = 0;
1296 bool group_hold = true; /* To use GROUP_HOLD macros */
1297 OV5693_ENTER_GROUP_HOLD(group_hold);
1298 offset += ov5693_coarse_time_reg(reg_list + offset, mode->coarse_time);
1299 offset += ov5693_gain_reg(reg_list + offset, mode->gain);
1300 OV5693_LEAVE_GROUP_HOLD(group_hold);
1301 reg_list[offset].addr = OV5693_TABLE_END;
1302 err = ov5693_i2c_wr_table(info, reg_list);
1303 return err;
1304}
1305static int ov5693_set_gain(struct ov5693_info *info, u32 gain, bool group_hold)
1306{
1307 struct ov5693_reg reg_list[9];
1308 int err = 0;
1309 int offset = 0;
1310 OV5693_ENTER_GROUP_HOLD(group_hold);
1311 offset += ov5693_gain_reg(reg_list + offset, gain);
1312 OV5693_LEAVE_GROUP_HOLD(group_hold);
1313 reg_list[offset].addr = OV5693_TABLE_END;
1314 offset++;
1315 err = ov5693_i2c_wr_table(info, reg_list);
1316 return err;
1317}
1318static int ov5693_set_group_hold(struct ov5693_info *info,
1319 struct ov5693_ae *ae)
1320{
1321 int err = 0;
1322 struct ov5693_reg reg_list[16];
1323 int offset = 0;
1324 bool group_hold = true; /* To use GROUP_HOLD macros */
1325 OV5693_ENTER_GROUP_HOLD(group_hold);
1326 if (ae->gain_enable)
1327 offset += ov5693_gain_reg(reg_list + offset,
1328 ae->gain);
1329 if (ae->frame_length_enable)
1330 offset += ov5693_frame_length_reg(reg_list + offset,
1331 ae->frame_length);
1332 if (ae->coarse_time_enable)
1333 offset += ov5693_coarse_time_reg(reg_list + offset,
1334 ae->coarse_time);
1335 OV5693_LEAVE_GROUP_HOLD(group_hold);
1336 reg_list[offset].addr = OV5693_TABLE_END;
1337 err |= ov5693_i2c_wr_table(info, reg_list);
1338 return err;
1339}
1340static int ov5693_gpio_rd(struct ov5693_info *info,
1341 enum ov5693_gpio_type type)
1342{
1343 int val = -EINVAL;
1344 if (info->gpio[type].gpio) {
1345 val = gpio_get_value_cansleep(info->gpio[type].gpio);
1346 dev_dbg(&info->i2c_client->dev, "%s %u %d\n", __func__,
1347 info->gpio[type].gpio, val);
1348 if (!info->gpio[type].active_high)
1349 val = !val;
1350 val &= 1;
1351 }
1352 return val; /* return read value or error */
1353}
1354static int ov5693_gpio_wr(struct ov5693_info *info,
1355 enum ov5693_gpio_type type,
1356 int val) /* val: 0=deassert, 1=assert */
1357{
1358 int err = -EINVAL;
1359 if (info->gpio[type].gpio) {
1360 if (!info->gpio[type].active_high)
1361 val = !val;
1362 val &= 1;
1363 err = val;
1364 gpio_set_value_cansleep(info->gpio[type].gpio, val);
1365 dev_dbg(&info->i2c_client->dev, "%s %u %d\n", __func__,
1366 info->gpio[type].gpio, val);
1367 }
1368 return err; /* return value written or error */
1369}
1370static void ov5693_gpio_pwrdn(struct ov5693_info *info, int val)
1371{
1372 int prev_val;
1373 prev_val = ov5693_gpio_rd(info, OV5693_GPIO_TYPE_PWRDN);
1374 if ((prev_val < 0) || (val == prev_val))
1375 return;
1376 ov5693_gpio_wr(info, OV5693_GPIO_TYPE_PWRDN, val);
1377 if (!val && prev_val)
1378 /* if transition from assert to deassert then delay for I2C */
1379 msleep(50);
1380}
1381static void ov5693_gpio_exit(struct ov5693_info *info)
1382{
1383 unsigned int i;
1384 for (i = 0; i < ARRAY_SIZE(ov5693_gpio); i++) {
1385 if (info->gpio[i].gpio && info->gpio[i].own)
1386 gpio_free(info->gpio[i].gpio);
1387 }
1388}
1389static void ov5693_gpio_init(struct ov5693_info *info)
1390{
1391 char label[32];
1392 unsigned long flags;
1393 unsigned type;
1394 unsigned i;
1395 unsigned j;
1396 int err;
1397 if (!info->pdata->gpio_count || !info->pdata->gpio)
1398 return;
1399 for (i = 0; i < ARRAY_SIZE(ov5693_gpio); i++) {
1400 type = ov5693_gpio[i].gpio_type;
1401 for (j = 0; j < info->pdata->gpio_count; j++) {
1402 if (type == info->pdata->gpio[j].gpio_type)
1403 break;
1404 }
1405 if (j == info->pdata->gpio_count)
1406 continue;
1407 info->gpio[type].gpio = info->pdata->gpio[j].gpio;
1408 if (ov5693_gpio[i].use_flags) {
1409 flags = ov5693_gpio[i].flags;
1410 info->gpio[type].active_high =
1411 ov5693_gpio[i].active_high;
1412 } else {
1413 info->gpio[type].active_high =
1414 info->pdata->gpio[j].active_high;
1415 if (info->gpio[type].active_high)
1416 flags = GPIOF_OUT_INIT_LOW;
1417 else
1418 flags = GPIOF_OUT_INIT_HIGH;
1419 }
1420 if (!info->pdata->gpio[j].init_en)
1421 continue;
1422 snprintf(label, sizeof(label), "ov5693_%u_%s",
1423 info->pdata->num, ov5693_gpio[i].label);
1424 err = gpio_request_one(info->gpio[type].gpio, flags, label);
1425 if (err) {
1426 dev_err(&info->i2c_client->dev,
1427 "%s ERR %s %u\n", __func__, label,
1428 info->gpio[type].gpio);
1429 } else {
1430 info->gpio[type].own = true;
1431 dev_dbg(&info->i2c_client->dev,
1432 "%s %s %u\n", __func__, label,
1433 info->gpio[type].gpio);
1434 }
1435 }
1436}
1437static void ov5693_mclk_disable(struct ov5693_info *info)
1438{
1439 dev_dbg(&info->i2c_client->dev, "%s: disable MCLK\n", __func__);
1440 clk_disable_unprepare(info->mclk);
1441}
1442static int ov5693_mclk_enable(struct ov5693_info *info)
1443{
1444 int err;
1445 unsigned long mclk_init_rate = 24000000;
1446 dev_dbg(&info->i2c_client->dev, "%s: enable MCLK with %lu Hz\n",
1447 __func__, mclk_init_rate);
1448 err = clk_set_rate(info->mclk, mclk_init_rate);
1449 if (!err)
1450 err = clk_prepare_enable(info->mclk);
1451 return err;
1452}
1453static int ov5693_power_off(struct ov5693_info *info)
1454{
1455 struct ov5693_power_rail *pw = &info->regulators;
1456 int err;
1457 if (false == info->power_on)
1458 return 0;
1459 if (info->pdata && info->pdata->power_off) {
1460 err = info->pdata->power_off(pw);
1461 if (0 > err)
1462 return err;
1463 info->power_on = false;
1464 ov5693_gpio_pwrdn(info, 1);
1465 ov5693_mclk_disable(info);
1466 } else {
1467 dev_err(&info->i2c_client->dev,
1468 "%s ERR: has no power_off function\n", __func__);
1469 err = -EINVAL;
1470 }
1471 return err;
1472}
1473static int ov5693_power_on(struct ov5693_info *info, bool standby)
1474{
1475 struct ov5693_power_rail *pw = &info->regulators;
1476 int err;
1477 if (true == info->power_on)
1478 return 0;
1479 err = ov5693_mclk_enable(info);
1480 if (err)
1481 return err;
1482 if (info->pdata && info->pdata->power_on) {
1483 err = info->pdata->power_on(pw);
1484 if (err >= 0) {
1485 info->power_on = true;
1486 ov5693_gpio_pwrdn(info, standby ? 1 : 0);
1487 msleep(100);
1488 }
1489 } else {
1490 dev_err(&info->i2c_client->dev,
1491 "%s ERR: has no power_on function\n", __func__);
1492 err = -EINVAL;
1493 }
1494 if (err < 0)
1495 ov5693_mclk_disable(info);
1496 return err;
1497}
1498static int ov5693_pm_wr(struct ov5693_info *info, int pwr)
1499{
1500 int err = 0;
1501 if ((info->pdata->cfg & (NVC_CFG_OFF2STDBY | NVC_CFG_BOOT_INIT)) &&
1502 (pwr == NVC_PWR_OFF ||
1503 pwr == NVC_PWR_STDBY_OFF))
1504 pwr = NVC_PWR_STDBY;
1505 if (pwr == info->pwr_dev)
1506 return 0;
1507 switch (pwr) {
1508 case NVC_PWR_OFF_FORCE:
1509 case NVC_PWR_OFF:
1510 case NVC_PWR_STDBY_OFF:
1511 err = ov5693_power_off(info);
1512 info->mode_valid = false;
1513 info->bin_en = 0;
1514 break;
1515 case NVC_PWR_STDBY:
1516 err = ov5693_power_on(info, true);
1517 break;
1518 case NVC_PWR_COMM:
1519 case NVC_PWR_ON:
1520 err = ov5693_power_on(info, false);
1521 break;
1522 default:
1523 err = -EINVAL;
1524 break;
1525 }
1526 if (err < 0) {
1527 dev_err(&info->i2c_client->dev, "%s err %d\n", __func__, err);
1528 pwr = NVC_PWR_ERR;
1529 }
1530 info->pwr_dev = pwr;
1531 dev_dbg(&info->i2c_client->dev, "%s pwr_dev=%d\n",
1532 __func__, info->pwr_dev);
1533 if (err > 0)
1534 return 0;
1535 return err;
1536}
1537static int ov5693_pm_dev_wr(struct ov5693_info *info, int pwr)
1538{
1539 if (info->mode_enable)
1540 pwr = NVC_PWR_ON;
1541 if (pwr < info->pwr_api)
1542 pwr = info->pwr_api;
1543 return ov5693_pm_wr(info, pwr);
1544}
1545static void ov5693_pm_exit(struct ov5693_info *info)
1546{
1547 ov5693_pm_wr(info, NVC_PWR_OFF_FORCE);
1548 ov5693_gpio_exit(info);
1549}
1550static void ov5693_regulator_get(struct ov5693_info *info,
1551 struct regulator **vreg,
1552 const char vreg_name[])
1553{
1554 struct regulator *reg = NULL;
1555 int err = 0;
1556 reg = devm_regulator_get(&info->i2c_client->dev, vreg_name);
1557 if (IS_ERR(reg)) {
1558 dev_err(&info->i2c_client->dev, "%s %s ERR: %d\n",
1559 __func__, vreg_name, (int)reg);
1560 err = PTR_ERR(reg);
1561 reg = NULL;
1562 } else {
1563 dev_dbg(&info->i2c_client->dev, "%s: %s\n",
1564 __func__, vreg_name);
1565 }
1566 *vreg = reg;
1567}
1568static void ov5693_pm_init(struct ov5693_info *info)
1569{
1570 struct ov5693_power_rail *pw = &info->regulators;
1571 ov5693_gpio_init(info);
1572 ov5693_regulator_get(info, &pw->dvdd, "dvdd");
1573 ov5693_regulator_get(info, &pw->avdd, "avdd");
1574 ov5693_regulator_get(info, &pw->dovdd, "dovdd");
1575 info->power_on = false;
1576}
1577static int ov5693_mode_able(struct ov5693_info *info, bool mode_enable)
1578{
1579 u8 val;
1580 int err;
1581 if (mode_enable)
1582 val = 0x01;
1583 else
1584 val = 0x00;
1585 err = regmap_write(info->regmap, 0x0100, val);
1586 if (!err) {
1587 info->mode_enable = mode_enable;
1588 dev_dbg(&info->i2c_client->dev, "%s streaming=%x\n",
1589 __func__, info->mode_enable);
1590 if (!mode_enable)
1591 ov5693_pm_dev_wr(info, NVC_PWR_STDBY);
1592 }
1593 return err;
1594}
1595static int ov5693_mode_wr_full(struct ov5693_info *info, u32 mode_index)
1596{
1597 int err;
1598 ov5693_pm_dev_wr(info, NVC_PWR_ON);
1599 ov5693_bin_wr(info, 0);
1600 err = ov5693_i2c_wr_table(info, mode_table[mode_index]);
1601 if (!err) {
1602 dev_dbg(&info->i2c_client->dev,
1603 "init done(mode=%d)!!!\n", mode_index);
1604 info->mode_index = mode_index;
1605 info->mode_valid = true;
1606 } else {
1607 dev_dbg(&info->i2c_client->dev,
1608 "init error(mode=%d)!!!\n", mode_index);
1609 info->mode_valid = false;
1610 }
1611 return err;
1612}
1613static int ov5693_set_mode(struct ov5693_info *info,
1614 struct ov5693_mode *mode)
1615{
1616 u32 mode_index = 0;
1617 int err = 0;
1618 if (!mode->res_x && !mode->res_y) {
1619 if (mode->frame_length || mode->coarse_time || mode->gain) {
1620 /* write exposure only */
1621 err = ov5693_exposure_wr(info, mode);
1622 return err;
1623 } else {
1624 /* turn off streaming */
1625 err = ov5693_mode_able(info, false);
1626 return err;
1627 }
1628 }
1629 if (mode->res_x == 2592 && mode->res_y == 1944)
1630 mode_index = OV5693_MODE_2592x1944;
1631 else if (mode->res_x == 1296 && mode->res_y == 972)
1632 mode_index = OV5693_MODE_1296x972;
1633 else if (mode->res_x == 1920 && mode->res_y == 1080)
1634 mode_index = OV5693_MODE_1920x1080;
1635 else if (mode->res_x == 1280 && mode->res_y == 720)
1636 mode_index = OV5693_MODE_1280x720_120FPS;
1637 if (!info->mode_valid || (info->mode_index != mode_index))
1638 err = ov5693_mode_wr_full(info, mode_index);
1639 else
1640 dev_dbg(&info->i2c_client->dev, "%s short mode\n", __func__);
1641 dev_dbg(&info->i2c_client->dev, "%s: mode #: %d\n",
1642 __func__, mode_index);
1643 dev_dbg(&info->i2c_client->dev, "%s: AE: %d, %d, %d\n",
1644 __func__, mode->frame_length,
1645 mode->coarse_time, mode->gain);
1646 err |= ov5693_exposure_wr(info, mode);
1647 if (err < 0) {
1648 info->mode_valid = false;
1649 dev_err(&info->i2c_client->dev,
1650 "%s set_mode error\n", __func__);
1651 goto ov5693_mode_wr_err;
1652 }
1653 return 0;
1654ov5693_mode_wr_err:
1655 if (!info->mode_enable)
1656 ov5693_pm_dev_wr(info, NVC_PWR_OFF);
1657 return err;
1658}
1659static int ov5693_get_fuse_id(struct ov5693_info *info)
1660{
1661 ov5693_i2c_rd8(info, 0x300A, &info->fuseid.id[0]);
1662 ov5693_i2c_rd8(info, 0x300B, &info->fuseid.id[1]);
1663 info->fuseid.size = 2;
1664 dev_dbg(&info->i2c_client->dev, "ov5693 fuse_id: %x,%x\n",
1665 info->fuseid.id[0], info->fuseid.id[1]);
1666 return 0;
1667}
1668static long ov5693_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
1669{
1670 struct ov5693_info *info = file->private_data;
1671 int err;
1672 switch (cmd) {
1673 case OV5693_IOCTL_SET_MODE:
1674 {
1675 struct ov5693_mode mode;
1676 if (copy_from_user(&mode,
1677 (const void __user *)arg,
1678 sizeof(struct ov5693_mode))) {
1679 dev_err(&info->i2c_client->dev,
1680 "%s:Failed to get mode from user.\n",
1681 __func__);
1682 return -EFAULT;
1683 }
1684 return ov5693_set_mode(info, &mode);
1685 }
1686 case OV5693_IOCTL_GET_STATUS: {
1687 u8 status = 0;
1688 if (copy_to_user((void __user *)arg, &status, sizeof(status))) {
1689 dev_err(&info->i2c_client->dev,
1690 "%s:Failed to copy status to user.\n",
1691 __func__);
1692 return -EFAULT;
1693 }
1694 return 0;
1695 }
1696 case OV5693_IOCTL_SET_GROUP_HOLD: {
1697 struct ov5693_ae ae;
1698 if (copy_from_user(&ae, (const void __user *)arg,
1699 sizeof(struct ov5693_ae))) {
1700 dev_dbg(&info->i2c_client->dev,
1701 "%s:fail group hold\n", __func__);
1702 return -EFAULT;
1703 }
1704 return ov5693_set_group_hold(info, &ae);
1705 }
1706 case OV5693_IOCTL_SET_FRAME_LENGTH:
1707 return ov5693_set_frame_length(info, (u32)arg, true);
1708 case OV5693_IOCTL_SET_COARSE_TIME:
1709 return ov5693_set_coarse_time(info, (u32)arg, true);
1710 case OV5693_IOCTL_SET_GAIN:
1711 return ov5693_set_gain(info, (u32)arg, true);
1712 case OV5693_IOCTL_GET_FUSEID:
1713 {
1714 err = ov5693_get_fuse_id(info);
1715 if (err) {
1716 dev_err(&info->i2c_client->dev, "%s:Failed to get fuse id info.\n",
1717 __func__);
1718 return err;
1719 }
1720 if (copy_to_user((void __user *)arg,
1721 &info->fuseid,
1722 sizeof(struct ov5693_fuseid))) {
1723 dev_dbg(&info->i2c_client->dev, "%s:Fail copy fuse id to user space\n",
1724 __func__);
1725 return -EFAULT;
1726 }
1727 return 0;
1728 }
1729 default:
1730 dev_err(&info->i2c_client->dev, "%s unsupported ioctl: %x\n",
1731 __func__, cmd);
1732 }
1733 return -EINVAL;
1734}
1735static void ov5693_sdata_init(struct ov5693_info *info)
1736{
1737 memcpy(&info->sdata, &ov5693_dflt_sdata, sizeof(info->sdata));
1738 if (info->pdata->lens_focal_length)
1739 info->sdata.focal_len = info->pdata->lens_focal_length;
1740 if (info->pdata->lens_max_aperture)
1741 info->sdata.max_aperture = info->pdata->lens_max_aperture;
1742 if (info->pdata->lens_fnumber)
1743 info->sdata.fnumber = info->pdata->lens_fnumber;
1744 if (info->pdata->lens_view_angle_h)
1745 info->sdata.view_angle_h = info->pdata->lens_view_angle_h;
1746 if (info->pdata->lens_view_angle_v)
1747 info->sdata.view_angle_v = info->pdata->lens_view_angle_v;
1748}
1749static int ov5693_open(struct inode *inode, struct file *file)
1750{
1751 int err;
1752 struct miscdevice *miscdev = file->private_data;
1753 struct ov5693_info *info = dev_get_drvdata(miscdev->parent);
1754 if (atomic_xchg(&info->in_use, 1))
1755 return -EBUSY;
1756 file->private_data = info;
1757 dev_dbg(&info->i2c_client->dev, "%s\n", __func__);
1758 err = ov5693_power_on(info, false);
1759 return err;
1760}
1761int ov5693_release(struct inode *inode, struct file *file)
1762{
1763 struct ov5693_info *info = file->private_data;
1764 dev_dbg(&info->i2c_client->dev, "%s\n", __func__);
1765 ov5693_pm_wr(info, NVC_PWR_OFF);
1766 file->private_data = NULL;
1767 WARN_ON(!atomic_xchg(&info->in_use, 0));
1768 return 0;
1769}
1770static const struct file_operations ov5693_fileops = {
1771 .owner = THIS_MODULE,
1772 .open = ov5693_open,
1773 .unlocked_ioctl = ov5693_ioctl,
1774 .release = ov5693_release,
1775};
1776static void ov5693_del(struct ov5693_info *info)
1777{
1778 ov5693_pm_exit(info);
1779 synchronize_rcu();
1780}
1781static int ov5693_remove(struct i2c_client *client)
1782{
1783 struct ov5693_info *info = i2c_get_clientdata(client);
1784 dev_dbg(&info->i2c_client->dev, "%s\n", __func__);
1785 misc_deregister(&info->miscdev);
1786 ov5693_del(info);
1787 return 0;
1788}
1789static struct of_device_id ov5693_of_match[] = {
1790 { .compatible = "nvidia,ov5693", },
1791 { },
1792};
1793MODULE_DEVICE_TABLE(of, ov5693_of_match);
1794static int ov5693_platform_power_on(struct ov5693_power_rail *pw)
1795{
1796 int err;
1797 struct ov5693_info *info = container_of(pw, struct ov5693_info,
1798 regulators);
1799 if (info->pdata->use_vcm_vdd) {
1800 err = regulator_enable(info->ext_vcm_vdd);
1801 if (unlikely(err))
1802 goto ov5693_vcm_fail;
1803 }
1804 ov5693_gpio_wr(info, OV5693_GPIO_TYPE_PWRDN, 0);
1805 usleep_range(10, 20);
1806 err = regulator_enable(pw->avdd);
1807 if (err)
1808 goto ov5693_avdd_fail;
1809 err = regulator_enable(pw->dovdd);
1810 if (err)
1811 goto ov5693_iovdd_fail;
1812 usleep_range(1, 2);
1813 ov5693_gpio_wr(info, OV5693_GPIO_TYPE_PWRDN, 1);
1814 usleep_range(300, 310);
1815 return 0;
1816ov5693_iovdd_fail:
1817 regulator_disable(pw->avdd);
1818ov5693_avdd_fail:
1819 if (info->pdata->use_vcm_vdd)
1820 regulator_disable(info->ext_vcm_vdd);
1821ov5693_vcm_fail:
1822 pr_err("%s FAILED\n", __func__);
1823 return err;
1824}
1825static int ov5693_platform_power_off(struct ov5693_power_rail *pw)
1826{
1827 struct ov5693_info *info = container_of(pw, struct ov5693_info,
1828 regulators);
1829 usleep_range(21, 25);
1830 ov5693_gpio_wr(info, OV5693_GPIO_TYPE_PWRDN, 0);
1831 usleep_range(1, 2);
1832 regulator_disable(pw->dovdd);
1833 regulator_disable(pw->avdd);
1834 if (info->pdata->use_vcm_vdd)
1835 regulator_disable(info->ext_vcm_vdd);
1836 return 0;
1837}
1838static int ov5693_parse_dt_gpio(struct device_node *np, const char *name,
1839 enum ov5693_gpio_type type,
1840 struct nvc_gpio_pdata *pdata)
1841{
1842 enum of_gpio_flags gpio_flags;
1843 if (of_find_property(np, name, NULL)) {
1844 pdata->gpio = of_get_named_gpio_flags(np, name, 0, &gpio_flags);
1845 pdata->gpio_type = type;
1846 pdata->init_en = true;
1847 pdata->active_high = !(gpio_flags & OF_GPIO_ACTIVE_LOW);
1848 return 1;
1849 }
1850 return 0;
1851}
1852static struct ov5693_platform_data *ov5693_parse_dt(struct i2c_client *client)
1853{
1854 struct device_node *np = client->dev.of_node;
1855 struct ov5693_platform_data *pdata;
1856 struct nvc_gpio_pdata *gpio_pdata = NULL;
1857 pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
1858 if (!pdata) {
1859 dev_err(&client->dev, "Failed to allocate pdata\n");
1860 return ERR_PTR(-ENOMEM);
1861 }
1862 gpio_pdata = devm_kzalloc(&client->dev,
1863 sizeof(*gpio_pdata) * ARRAY_SIZE(ov5693_gpio), GFP_KERNEL);
1864 if (!gpio_pdata) {
1865 dev_err(&client->dev, "cannot allocate gpio data memory\n");
1866 return ERR_PTR(-ENOMEM);
1867 }
1868 /* init with default platform data values */
1869 memcpy(pdata, &ov5693_dflt_pdata, sizeof(*pdata));
1870 /* extra regulators info */
1871 pdata->use_vcm_vdd = of_property_read_bool(np, "nvidia,use-vcm-vdd");
1872 /* generic info */
1873 of_property_read_u32(np, "nvidia,num", &pdata->num);
1874 of_property_read_string(np, "nvidia,dev-name", &pdata->dev_name);
1875 /* ov5693 gpios */
1876 pdata->gpio_count = 0;
1877 pdata->gpio_count += ov5693_parse_dt_gpio(np,
1878 "reset-gpios", OV5693_GPIO_TYPE_PWRDN,
1879 &gpio_pdata[pdata->gpio_count]);
1880 pdata->gpio = gpio_pdata;
1881 /* MCLK clock info */
1882 of_property_read_string(np, "nvidia,mclk_name",
1883 &pdata->mclk_name);
1884 /* ov5693 power functions */
1885 pdata->power_on = ov5693_platform_power_on;
1886 pdata->power_off = ov5693_platform_power_off;
1887 return pdata;
1888}
1889static int ov5693_probe(
1890 struct i2c_client *client,
1891 const struct i2c_device_id *id)
1892{
1893 struct ov5693_info *info;
1894 char dname[16];
1895 unsigned long clock_probe_rate;
1896 int err;
1897 const char *mclk_name;
1898 static struct regmap_config ad5823_regmap_config = {
1899 .reg_bits = 16,
1900 .val_bits = 8,
1901 };
1902 dev_dbg(&client->dev, "%s\n", __func__);
1903 info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL);
1904 if (info == NULL) {
1905 dev_err(&client->dev, "%s: kzalloc error\n", __func__);
1906 return -ENOMEM;
1907 }
1908 info->i2c_client = client;
1909 if (client->dev.of_node) {
1910 info->pdata = ov5693_parse_dt(client);
1911 if (IS_ERR(info->pdata)) {
1912 err = PTR_ERR(info->pdata);
1913 dev_err(&client->dev,
1914 "Failed to parse OF node: %d\n", err);
1915 return err;
1916 }
1917 } else if (client->dev.platform_data)
1918 info->pdata = client->dev.platform_data;
1919 else {
1920 info->pdata = &ov5693_dflt_pdata;
1921 dev_dbg(&client->dev,
1922 "%s No platform data. Using defaults.\n",
1923 __func__);
1924 }
1925 if (info->pdata->use_vcm_vdd) {
1926 info->ext_vcm_vdd = devm_regulator_get(&info->i2c_client->dev,
1927 "ext_vcm_vdd");
1928 if (WARN_ON(IS_ERR(info->ext_vcm_vdd))) {
1929 err = PTR_ERR(info->ext_vcm_vdd);
1930 dev_err(&client->dev,
1931 "ext_vcm_vdd get failed %d\n", err);
1932 info->ext_vcm_vdd = NULL;
1933 return err;
1934 }
1935 }
1936 info->regmap = devm_regmap_init_i2c(client, &ad5823_regmap_config);
1937 if (IS_ERR(info->regmap)) {
1938 err = PTR_ERR(info->regmap);
1939 dev_err(&client->dev,
1940 "Failed to allocate register map: %d\n", err);
1941 return err;
1942 }
1943 mclk_name = info->pdata->mclk_name ?
1944 info->pdata->mclk_name : "default_mclk";
1945 info->mclk = devm_clk_get(&client->dev, mclk_name);
1946 if (IS_ERR(info->mclk)) {
1947 dev_err(&client->dev, "%s: unable to get clock %s\n",
1948 __func__, mclk_name);
1949 return PTR_ERR(info->mclk);
1950 }
1951 i2c_set_clientdata(client, info);
1952 ov5693_pm_init(info);
1953 if (!info->regulators.avdd || !info->regulators.dovdd)
1954 return -EFAULT;
1955 ov5693_sdata_init(info);
1956 if (info->pdata->cfg & (NVC_CFG_NODEV | NVC_CFG_BOOT_INIT)) {
1957 if (info->pdata->probe_clock) {
1958 clock_probe_rate = 6000; /* initial_clcok*/
1959 clock_probe_rate *= 1000;
1960 info->pdata->probe_clock(clock_probe_rate);
1961 }
1962 ov5693_pm_dev_wr(info, NVC_PWR_COMM);
1963 ov5693_pm_dev_wr(info, NVC_PWR_OFF);
1964 if (info->pdata->probe_clock)
1965 info->pdata->probe_clock(0);
1966 }
1967 if (info->pdata->dev_name != NULL)
1968 strcpy(dname, info->pdata->dev_name);
1969 else
1970 strcpy(dname, "ov5693");
1971 if (info->pdata->num)
1972 snprintf(dname, sizeof(dname), "%s.%u",
1973 dname, info->pdata->num);
1974 info->miscdev.name = dname;
1975 info->miscdev.fops = &ov5693_fileops;
1976 info->miscdev.minor = MISC_DYNAMIC_MINOR;
1977 info->miscdev.parent = &client->dev;
1978 if (misc_register(&info->miscdev)) {
1979 dev_err(&client->dev, "%s unable to register misc device %s\n",
1980 __func__, dname);
1981 ov5693_del(info);
1982 return -ENODEV;
1983 }
1984 dev_dbg(&client->dev, "ov5693 sensor driver loading done\n");
1985 return 0;
1986}
1987static const struct i2c_device_id ov5693_id[] = {
1988 { "ov5693", 0 },
1989 { },
1990};
1991MODULE_DEVICE_TABLE(i2c, ov5693_id);
1992static struct i2c_driver ov5693_i2c_driver = {
1993 .driver = {
1994 .name = "ov5693",
1995 .owner = THIS_MODULE,
1996 .of_match_table = ov5693_of_match,
1997 },
1998 .id_table = ov5693_id,
1999 .probe = ov5693_probe,
2000 .remove = ov5693_remove,
2001};
2002module_i2c_driver(ov5693_i2c_driver);
2003MODULE_LICENSE("GPL v2");