]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/blob - drivers/media/platform/tegra/ov5693.c
ov5693: fix fuse ID read
[sojka/nv-tegra/linux-3.10.git] / drivers / media / platform / tegra / ov5693.c
1 /*
2  * Copyright (c) 2013-2014, 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
17 #include <linux/delay.h>
18 #include <linux/fs.h>
19 #include <linux/i2c.h>
20 #include <linux/clk.h>
21 #include <linux/miscdevice.h>
22 #include <linux/slab.h>
23 #include <linux/uaccess.h>
24 #include <linux/regulator/consumer.h>
25 #include <linux/gpio.h>
26 #include <linux/module.h>
27 #include <linux/regmap.h>
28 #include <linux/gpio.h>
29 #include <linux/of.h>
30 #include <linux/of_device.h>
31 #include <linux/of_gpio.h>
32 #include <linux/sysedp.h>
33 #include <media/ov5693.h>
34 #include <media/nvc.h>
35
36 #define OV5693_ID                       0x5693
37 #define OV5693_SENSOR_TYPE              NVC_IMAGER_TYPE_RAW
38 #define OV5693_RES_CHG_WAIT_TIME_MS     100
39 #define OV5693_SIZEOF_I2C_BUF           16
40 #define OV5693_TABLE_WAIT_MS            0
41 #define OV5693_TABLE_END                1
42 #define OV5693_TABLE_RESET              2
43 #define OV5693_TABLE_RESET_TIMEOUT      50
44 #define OV5693_LENS_MAX_APERTURE        0       /* _INT2FLOAT_DIVISOR */
45 #define OV5693_LENS_FNUMBER             0       /* _INT2FLOAT_DIVISOR */
46 #define OV5693_LENS_FOCAL_LENGTH        6120    /* _INT2FLOAT_DIVISOR */
47 #define OV5693_LENS_VIEW_ANGLE_H        60000   /* _INT2FLOAT_DIVISOR */
48 #define OV5693_LENS_VIEW_ANGLE_V        60000   /* _INT2FLOAT_DIVISOR */
49 #define OV5693_OTP_BUF_SIZE             16
50 #define OV5693_FUSE_ID_SIZE             8
51
52 static struct nvc_gpio_init ov5693_gpio[] = {
53         { OV5693_GPIO_TYPE_PWRDN, GPIOF_OUT_INIT_LOW, "pwrdn", false, true, },
54 };
55
56 struct ov5693_info {
57         atomic_t in_use;
58         struct i2c_client *i2c_client;
59         struct ov5693_platform_data *pdata;
60         struct clk *mclk;
61         struct miscdevice miscdev;
62         int pwr_api;
63         int pwr_dev;
64         struct nvc_gpio gpio[ARRAY_SIZE(ov5693_gpio)];
65         struct ov5693_power_rail regulators;
66         bool power_on;
67         u32 mode_index;
68         bool mode_valid;
69         bool mode_enable;
70         unsigned test_pattern;
71         struct nvc_imager_static_nvc sdata;
72         u8 bin_en;
73         struct nvc_fuseid fuseid;
74         struct regmap *regmap;
75         struct regulator *ext_vcm_vdd;
76         struct ov5693_cal_data cal;
77         struct sysedp_consumer *sysedpc;
78         char devname[16];
79         struct ov5693_eeprom_data eeprom[OV5693_EEPROM_NUM_BLOCKS];
80         u8 eeprom_buf[OV5693_EEPROM_SIZE];
81 };
82
83 struct ov5693_reg {
84         u16 addr;
85         u16 val;
86 };
87
88 struct ov5693_mode_data {
89         struct nvc_imager_mode sensor_mode;
90         struct nvc_imager_dynamic_nvc sensor_dnvc;
91         struct ov5693_reg *p_mode_i2c;
92 };
93
94 static struct ov5693_platform_data ov5693_dflt_pdata = {
95         .cfg            = 0,
96         .num            = 0,
97         .dev_name       = "camera",
98 };
99
100 /*
101  * NOTE: static vs dynamic
102  * If a member in the nvc_imager_static_nvc structure is not actually
103  * static data, then leave blank and add the parameter to the parameter
104  * read function that dynamically reads the data.  The NVC user driver
105  * will call the parameter read for the data if the member data is 0.
106  * If the dynamic data becomes static during probe (a one time read
107  * such as device ID) then add the dynamic read to the _sdata_init
108  * function.
109  */
110 static struct nvc_imager_static_nvc ov5693_dflt_sdata = {
111         .api_version            = NVC_IMAGER_API_STATIC_VER,
112         .sensor_type            = OV5693_SENSOR_TYPE,
113         .bits_per_pixel         = 10,
114         .sensor_id              = OV5693_ID,
115         .sensor_id_minor        = 0,
116         .focal_len              = OV5693_LENS_FOCAL_LENGTH,
117         .max_aperture           = OV5693_LENS_MAX_APERTURE,
118         .fnumber                = OV5693_LENS_FNUMBER,
119         .view_angle_h           = OV5693_LENS_VIEW_ANGLE_H,
120         .view_angle_v           = OV5693_LENS_VIEW_ANGLE_V,
121         .res_chg_wait_time      = OV5693_RES_CHG_WAIT_TIME_MS,
122 };
123
124 static const struct ov5693_reg ov5693_2592x1944_i2c[] = {
125         {OV5693_TABLE_RESET, 0},/* Including sw reset */
126         {0x3001, 0x0a},
127         {0x3002, 0x80},
128         {0x3006, 0x00},
129         {0x3011, 0x21},
130         {0x3012, 0x09},
131         {0x3013, 0x10},
132         {0x3014, 0x00},
133         {0x3015, 0x08},
134         {0x3016, 0xf0},
135         {0x3017, 0xf0},
136         {0x3018, 0xf0},
137         {0x301b, 0xb4},
138         {0x301d, 0x02},
139         {0x3021, 0x00},
140         {0x3022, 0x01},
141         {0x3028, 0x44},
142         {0x3090, 0x02},
143         {0x3091, 0x0e},
144         {0x3092, 0x00},
145         {0x3093, 0x00},
146         {0x3098, 0x03},
147         {0x3099, 0x1e},
148         {0x309a, 0x02},
149         {0x309b, 0x01},
150         {0x309c, 0x00},
151         {0x30a0, 0xd2},
152         {0x30a2, 0x01},
153         {0x30b2, 0x00},
154         {0x30b3, 0x68},
155         {0x30b4, 0x03},
156         {0x30b5, 0x04},
157         {0x30b6, 0x01},
158         {0x3104, 0x21},
159         {0x3106, 0x00},
160         {0x3406, 0x01},
161         {0x3500, 0x00},
162         {0x3501, 0x7b},
163         {0x3502, 0x00},
164         {0x3503, 0x07},
165         {0x3504, 0x00},
166         {0x3505, 0x00},
167         {0x3506, 0x00},
168         {0x3507, 0x02},
169         {0x3508, 0x00},
170         {0x3509, 0x10},
171         {0x350a, 0x00},
172         {0x350b, 0x40},
173         {0x3601, 0x0a},
174         {0x3602, 0x18},
175         {0x3612, 0x80},
176         {0x3620, 0x54},
177         {0x3621, 0xc7},
178         {0x3622, 0x0f},
179         {0x3625, 0x10},
180         {0x3630, 0x55},
181         {0x3631, 0xf4},
182         {0x3632, 0x00},
183         {0x3633, 0x34},
184         {0x3634, 0x02},
185         {0x364d, 0x0d},
186         {0x364f, 0xdd},
187         {0x3660, 0x04},
188         {0x3662, 0x10},
189         {0x3663, 0xf1},
190         {0x3665, 0x00},
191         {0x3666, 0x20},
192         {0x3667, 0x00},
193         {0x366a, 0x80},
194         {0x3680, 0xe0},
195         {0x3681, 0x00},
196         {0x3700, 0x42},
197         {0x3701, 0x14},
198         {0x3702, 0xa0},
199         {0x3703, 0xd8},
200         {0x3704, 0x78},
201         {0x3705, 0x02},
202         {0x3708, 0xe2},
203         {0x3709, 0xc3},
204         {0x370a, 0x00},
205         {0x370b, 0x20},
206         {0x370c, 0x0c},
207         {0x370d, 0x11},
208         {0x370e, 0x00},
209         {0x370f, 0x40},
210         {0x3710, 0x00},
211         {0x371a, 0x1c},
212         {0x371b, 0x05},
213         {0x371c, 0x01},
214         {0x371e, 0xa1},
215         {0x371f, 0x0c},
216         {0x3721, 0x00},
217         {0x3724, 0x10},
218         {0x3726, 0x00},
219         {0x372a, 0x01},
220         {0x3730, 0x10},
221         {0x3738, 0x22},
222         {0x3739, 0xe5},
223         {0x373a, 0x50},
224         {0x373b, 0x02},
225         {0x373c, 0x41},
226         {0x373f, 0x02},
227         {0x3740, 0x42},
228         {0x3741, 0x02},
229         {0x3742, 0x18},
230         {0x3743, 0x01},
231         {0x3744, 0x02},
232         {0x3747, 0x10},
233         {0x374c, 0x04},
234         {0x3751, 0xf0},
235         {0x3752, 0x00},
236         {0x3753, 0x00},
237         {0x3754, 0xc0},
238         {0x3755, 0x00},
239         {0x3756, 0x1a},
240         {0x3758, 0x00},
241         {0x3759, 0x0f},
242         {0x376b, 0x44},
243         {0x375c, 0x04},
244         {0x3776, 0x00},
245         {0x377f, 0x08},
246         {0x3780, 0x22},
247         {0x3781, 0x0c},
248         {0x3784, 0x2c},
249         {0x3785, 0x1e},
250         {0x378f, 0xf5},
251         {0x3791, 0xb0},
252         {0x3795, 0x00},
253         {0x3796, 0x64},
254         {0x3797, 0x11},
255         {0x3798, 0x30},
256         {0x3799, 0x41},
257         {0x379a, 0x07},
258         {0x379b, 0xb0},
259         {0x379c, 0x0c},
260         {0x37c5, 0x00},
261         {0x37c6, 0x00},
262         {0x37c7, 0x00},
263         {0x37c9, 0x00},
264         {0x37ca, 0x00},
265         {0x37cb, 0x00},
266         {0x37de, 0x00},
267         {0x37df, 0x00},
268         {0x3800, 0x00},
269         {0x3801, 0x02},
270         {0x3802, 0x00},
271         {0x3803, 0x02},
272         {0x3804, 0x0a},
273         {0x3805, 0x41},
274         {0x3806, 0x07},
275         {0x3807, 0xa5},
276         {0x3808, 0x0a},
277         {0x3809, 0x20},
278         {0x380a, 0x07},
279         {0x380b, 0x98},
280         {0x380c, 0x0a},
281         {0x380d, 0x80},
282         {0x380e, 0x07},
283         {0x380f, 0xc0},
284         {0x3810, 0x00},
285         {0x3811, 0x02},
286         {0x3812, 0x00},
287         {0x3813, 0x02},
288         {0x3814, 0x11},
289         {0x3815, 0x11},
290         {0x3820, 0x00},
291         {0x3821, 0x1e},
292         {0x3823, 0x00},
293         {0x3824, 0x00},
294         {0x3825, 0x00},
295         {0x3826, 0x00},
296         {0x3827, 0x00},
297         {0x382a, 0x04},
298         {0x3a04, 0x06},
299         {0x3a05, 0x14},
300         {0x3a06, 0x00},
301         {0x3a07, 0xfe},
302         {0x3b00, 0x00},
303         {0x3b02, 0x00},
304         {0x3b03, 0x00},
305         {0x3b04, 0x00},
306         {0x3b05, 0x00},
307         {0x3d00, 0x00},
308         {0x3d01, 0x00},
309         {0x3d02, 0x00},
310         {0x3d03, 0x00},
311         {0x3d04, 0x00},
312         {0x3d05, 0x00},
313         {0x3d06, 0x00},
314         {0x3d07, 0x00},
315         {0x3d08, 0x00},
316         {0x3d09, 0x00},
317         {0x3d0a, 0x00},
318         {0x3d0b, 0x00},
319         {0x3d0c, 0x00},
320         {0x3d0d, 0x00},
321         {0x3d0e, 0x00},
322         {0x3d0f, 0x00},
323         {0x3d80, 0x00},
324         {0x3d81, 0x00},
325         {0x3d84, 0x00},
326         {0x3e07, 0x20},
327         {0x4000, 0x08},
328         {0x4001, 0x04},
329         {0x4002, 0x45},
330         {0x4004, 0x08},
331         {0x4005, 0x18},
332         {0x4006, 0x20},
333         {0x4008, 0x24},
334         {0x4009, 0x10},
335         {0x400c, 0x00},
336         {0x400d, 0x00},
337         {0x4058, 0x00},
338         {0x4101, 0xb2},
339         {0x4303, 0x00},
340         {0x4304, 0x08},
341         {0x4307, 0x30},
342         {0x4311, 0x04},
343         {0x4315, 0x01},
344         {0x4511, 0x05},
345         {0x4512, 0x01},
346         {0x4800, 0x20}, /* dis-continuous */
347         {0x4806, 0x00},
348         {0x4816, 0x52},
349         {0x481f, 0x30},
350         {0x4826, 0x2c},
351         {0x4831, 0x64},
352         {0x4d00, 0x04},
353         {0x4d01, 0x71},
354         {0x4d02, 0xfd},
355         {0x4d03, 0xf5},
356         {0x4d04, 0x0c},
357         {0x4d05, 0xcc},
358         {0x4837, 0x0a},
359         {0x5000, 0x06},
360         {0x5001, 0x01},
361         {0x5002, 0x00},
362         {0x5003, 0x20},
363         {0x5046, 0x0a},
364         {0x5013, 0x00},
365         {0x5046, 0x0a},
366         {0x5780, 0x1c},
367         {0x5786, 0x20},
368         {0x5787, 0x10},
369         {0x5788, 0x18},
370         {0x578a, 0x04},
371         {0x578b, 0x02},
372         {0x578c, 0x02},
373         {0x578e, 0x06},
374         {0x578f, 0x02},
375         {0x5790, 0x02},
376         {0x5791, 0xff},
377         {0x5842, 0x01},
378         {0x5843, 0x2b},
379         {0x5844, 0x01},
380         {0x5845, 0x92},
381         {0x5846, 0x01},
382         {0x5847, 0x8f},
383         {0x5848, 0x01},
384         {0x5849, 0x0c},
385         {0x5e00, 0x00},
386         {0x5e10, 0x0c},
387         {OV5693_TABLE_END, 0x0000}
388 };
389
390 static const struct ov5693_reg ov5693_1296x972_i2c[] = {
391         {OV5693_TABLE_RESET, 0},/* Including sw reset */
392         {0x3001, 0x0a},
393         {0x3002, 0x80},
394         {0x3006, 0x00},
395         {0x3011, 0x21},
396         {0x3012, 0x09},
397         {0x3013, 0x10},
398         {0x3014, 0x00},
399         {0x3015, 0x08},
400         {0x3016, 0xf0},
401         {0x3017, 0xf0},
402         {0x3018, 0xf0},
403         {0x301b, 0xb4},
404         {0x301d, 0x02},
405         {0x3021, 0x00},
406         {0x3022, 0x01},
407         {0x3028, 0x44},
408         {0x3098, 0x03},
409         {0x3099, 0x1e},
410         {0x309a, 0x02},
411         {0x309b, 0x01},
412         {0x309c, 0x00},
413         {0x30a0, 0xd2},
414         {0x30a2, 0x01},
415         {0x30b2, 0x00},
416         {0x30b3, 0x68},
417         {0x30b4, 0x03},
418         {0x30b5, 0x04},
419         {0x30b6, 0x01},
420         {0x3104, 0x21},
421         {0x3106, 0x00},
422         {0x3406, 0x01},
423         {0x3500, 0x00},
424         {0x3501, 0x7b},
425         {0x3502, 0x00},
426         {0x3503, 0x07},
427         {0x3504, 0x00},
428         {0x3505, 0x00},
429         {0x3506, 0x00},
430         {0x3507, 0x02},
431         {0x3508, 0x00},
432         {0x3509, 0x10},
433         {0x350a, 0x00},
434         {0x350b, 0x40},
435         {0x3601, 0x0a},
436         {0x3602, 0x38},
437         {0x3612, 0x80},
438         {0x3620, 0x54},
439         {0x3621, 0xc7},
440         {0x3622, 0x0f},
441         {0x3625, 0x10},
442         {0x3630, 0x55},
443         {0x3631, 0xf4},
444         {0x3632, 0x00},
445         {0x3633, 0x34},
446         {0x3634, 0x02},
447         {0x364d, 0x0d},
448         {0x364f, 0xdd},
449         {0x3660, 0x04},
450         {0x3662, 0x10},
451         {0x3663, 0xf1},
452         {0x3665, 0x00},
453         {0x3666, 0x20},
454         {0x3667, 0x00},
455         {0x366a, 0x80},
456         {0x3680, 0xe0},
457         {0x3681, 0x00},
458         {0x3700, 0x42},
459         {0x3701, 0x14},
460         {0x3702, 0xa0},
461         {0x3703, 0xd8},
462         {0x3704, 0x78},
463         {0x3705, 0x02},
464         {0x3708, 0xe6},
465         {0x3709, 0xc3},
466         {0x370a, 0x00},
467         {0x370b, 0x20},
468         {0x370c, 0x0c},
469         {0x370d, 0x11},
470         {0x370e, 0x00},
471         {0x370f, 0x40},
472         {0x3710, 0x00},
473         {0x371a, 0x1c},
474         {0x371b, 0x05},
475         {0x371c, 0x01},
476         {0x371e, 0xa1},
477         {0x371f, 0x0c},
478         {0x3721, 0x00},
479         {0x3724, 0x10},
480         {0x3726, 0x00},
481         {0x372a, 0x01},
482         {0x3730, 0x10},
483         {0x3738, 0x22},
484         {0x3739, 0xe5},
485         {0x373a, 0x50},
486         {0x373b, 0x02},
487         {0x373c, 0x41},
488         {0x373f, 0x02},
489         {0x3740, 0x42},
490         {0x3741, 0x02},
491         {0x3742, 0x18},
492         {0x3743, 0x01},
493         {0x3744, 0x02},
494         {0x3747, 0x10},
495         {0x374c, 0x04},
496         {0x3751, 0xf0},
497         {0x3752, 0x00},
498         {0x3753, 0x00},
499         {0x3754, 0xc0},
500         {0x3755, 0x00},
501         {0x3756, 0x1a},
502         {0x3758, 0x00},
503         {0x3759, 0x0f},
504         {0x376b, 0x44},
505         {0x375c, 0x04},
506         {0x3774, 0x10},
507         {0x3776, 0x00},
508         {0x377f, 0x08},
509         {0x3780, 0x22},
510         {0x3781, 0x0c},
511         {0x3784, 0x2c},
512         {0x3785, 0x1e},
513         {0x378f, 0xf5},
514         {0x3791, 0xb0},
515         {0x3795, 0x00},
516         {0x3796, 0x64},
517         {0x3797, 0x11},
518         {0x3798, 0x30},
519         {0x3799, 0x41},
520         {0x379a, 0x07},
521         {0x379b, 0xb0},
522         {0x379c, 0x0c},
523         {0x37c5, 0x00},
524         {0x37c6, 0x00},
525         {0x37c7, 0x00},
526         {0x37c9, 0x00},
527         {0x37ca, 0x00},
528         {0x37cb, 0x00},
529         {0x37de, 0x00},
530         {0x37df, 0x00},
531         {0x3800, 0x00},
532         {0x3801, 0x00},
533         {0x3802, 0x00},
534         {0x3803, 0x00},
535         {0x3804, 0x0a},
536         {0x3805, 0x3f},
537         {0x3806, 0x07},
538         {0x3807, 0xa3},
539         {0x3808, 0x05},
540         {0x3809, 0x10},
541         {0x380a, 0x03},
542         {0x380b, 0xcc},
543         {0x380c, 0x0a},
544         {0x380d, 0x80},
545         {0x380e, 0x07},
546         {0x380f, 0xc0},
547         {0x3810, 0x00},
548         {0x3811, 0x02},
549         {0x3812, 0x00},
550         {0x3813, 0x02},
551         {0x3814, 0x31},
552         {0x3815, 0x31},
553         {0x3820, 0x01},
554         {0x3821, 0x1f},
555         {0x3823, 0x00},
556         {0x3824, 0x00},
557         {0x3825, 0x00},
558         {0x3826, 0x00},
559         {0x3827, 0x00},
560         {0x382a, 0x04},
561         {0x3a04, 0x06},
562         {0x3a05, 0x14},
563         {0x3a06, 0x00},
564         {0x3a07, 0xfe},
565         {0x3b00, 0x00},
566         {0x3b02, 0x00},
567         {0x3b03, 0x00},
568         {0x3b04, 0x00},
569         {0x3b05, 0x00},
570         {0x3e07, 0x20},
571         {0x4000, 0x08},
572         {0x4001, 0x04},
573         {0x4002, 0x45},
574         {0x4004, 0x08},
575         {0x4005, 0x18},
576         {0x4006, 0x20},
577         {0x4008, 0x24},
578         {0x4009, 0x10},
579         {0x400c, 0x00},
580         {0x400d, 0x00},
581         {0x4058, 0x00},
582         {0x404e, 0x37},
583         {0x404f, 0x8f},
584         {0x4058, 0x00},
585         {0x4101, 0xb2},
586         {0x4303, 0x00},
587         {0x4304, 0x08},
588         {0x4307, 0x30},
589         {0x4311, 0x04},
590         {0x4315, 0x01},
591         {0x4511, 0x05},
592         {0x4512, 0x00},
593         {0x4800, 0x20}, /* dis-continuous */
594         {0x4806, 0x00},
595         {0x4816, 0x52},
596         {0x481f, 0x30},
597         {0x4826, 0x2c},
598         {0x4831, 0x64},
599         {0x4d00, 0x04},
600         {0x4d01, 0x71},
601         {0x4d02, 0xfd},
602         {0x4d03, 0xf5},
603         {0x4d04, 0x0c},
604         {0x4d05, 0xcc},
605         {0x4837, 0x0a},
606         {0x5000, 0x06},
607         {0x5001, 0x01},
608         {0x5002, 0x00},
609         {0x5003, 0x20},
610         {0x5046, 0x0a},
611         {0x5013, 0x00},
612         {0x5046, 0x0a},
613         {0x5780, 0x1c},
614         {0x5786, 0x20},
615         {0x5787, 0x10},
616         {0x5788, 0x18},
617         {0x578a, 0x04},
618         {0x578b, 0x02},
619         {0x578c, 0x02},
620         {0x578e, 0x06},
621         {0x578f, 0x02},
622         {0x5790, 0x02},
623         {0x5791, 0xff},
624         {0x5842, 0x01},
625         {0x5843, 0x2b},
626         {0x5844, 0x01},
627         {0x5845, 0x92},
628         {0x5846, 0x01},
629         {0x5847, 0x8f},
630         {0x5848, 0x01},
631         {0x5849, 0x0c},
632         {0x5e00, 0x00},
633         {0x5e10, 0x0c},
634         {OV5693_TABLE_END, 0x0000}
635 };
636
637 static const struct ov5693_reg ov5693_1920x1080_i2c[] = {
638         {OV5693_TABLE_RESET, 0x0},/*, 0xIncluding, 0xsw, 0xreset, 0x*/
639         {0x3001, 0x0a},
640         {0x3002, 0x80},
641         {0x3006, 0x00},
642         {0x3011, 0x21},
643         {0x3012, 0x09},
644         {0x3013, 0x10},
645         {0x3014, 0x00},
646         {0x3015, 0x08},
647         {0x3016, 0xf0},
648         {0x3017, 0xf0},
649         {0x3018, 0xf0},
650         {0x301b, 0xb4},
651         {0x301d, 0x02},
652         {0x3021, 0x00},
653         {0x3022, 0x01},
654         {0x3028, 0x44},
655         {0x3098, 0x03},
656         {0x3099, 0x1e},
657         {0x309a, 0x02},
658         {0x309b, 0x01},
659         {0x309c, 0x00},
660         {0x30a0, 0xd2},
661         {0x30a2, 0x01},
662         {0x30b2, 0x00},
663         {0x30b3, 0x68},
664         {0x30b4, 0x03},
665         {0x30b5, 0x04},
666         {0x30b6, 0x01},
667         {0x3104, 0x21},
668         {0x3106, 0x00},
669         {0x3406, 0x01},
670         {0x3500, 0x00},
671         {0x3501, 0x7b},
672         {0x3502, 0x00},
673         {0x3503, 0x07},
674         {0x3504, 0x00},
675         {0x3505, 0x00},
676         {0x3506, 0x00},
677         {0x3507, 0x02},
678         {0x3508, 0x00},
679         {0x3509, 0x10},
680         {0x350a, 0x00},
681         {0x350b, 0x40},
682         {0x3601, 0x0a},
683         {0x3602, 0x38},
684         {0x3612, 0x80},
685         {0x3620, 0x54},
686         {0x3621, 0xc7},
687         {0x3622, 0x0f},
688         {0x3625, 0x10},
689         {0x3630, 0x55},
690         {0x3631, 0xf4},
691         {0x3632, 0x00},
692         {0x3633, 0x34},
693         {0x3634, 0x02},
694         {0x364d, 0x0d},
695         {0x364f, 0xdd},
696         {0x3660, 0x04},
697         {0x3662, 0x10},
698         {0x3663, 0xf1},
699         {0x3665, 0x00},
700         {0x3666, 0x20},
701         {0x3667, 0x00},
702         {0x366a, 0x80},
703         {0x3680, 0xe0},
704         {0x3681, 0x00},
705         {0x3700, 0x42},
706         {0x3701, 0x14},
707         {0x3702, 0xa0},
708         {0x3703, 0xd8},
709         {0x3704, 0x78},
710         {0x3705, 0x02},
711         {0x3708, 0xe2},
712         {0x3709, 0xc3},
713         {0x370a, 0x00},
714         {0x370b, 0x20},
715         {0x370c, 0x0c},
716         {0x370d, 0x11},
717         {0x370e, 0x00},
718         {0x370f, 0x40},
719         {0x3710, 0x00},
720         {0x371a, 0x1c},
721         {0x371b, 0x05},
722         {0x371c, 0x01},
723         {0x371e, 0xa1},
724         {0x371f, 0x0c},
725         {0x3721, 0x00},
726         {0x3724, 0x10},
727         {0x3726, 0x00},
728         {0x372a, 0x01},
729         {0x3730, 0x10},
730         {0x3738, 0x22},
731         {0x3739, 0xe5},
732         {0x373a, 0x50},
733         {0x373b, 0x02},
734         {0x373c, 0x41},
735         {0x373f, 0x02},
736         {0x3740, 0x42},
737         {0x3741, 0x02},
738         {0x3742, 0x18},
739         {0x3743, 0x01},
740         {0x3744, 0x02},
741         {0x3747, 0x10},
742         {0x374c, 0x04},
743         {0x3751, 0xf0},
744         {0x3752, 0x00},
745         {0x3753, 0x00},
746         {0x3754, 0xc0},
747         {0x3755, 0x00},
748         {0x3756, 0x1a},
749         {0x3758, 0x00},
750         {0x3759, 0x0f},
751         {0x376b, 0x44},
752         {0x375c, 0x04},
753         {0x3774, 0x10},
754         {0x3776, 0x00},
755         {0x377f, 0x08},
756         {0x3780, 0x22},
757         {0x3781, 0x0c},
758         {0x3784, 0x2c},
759         {0x3785, 0x1e},
760         {0x378f, 0xf5},
761         {0x3791, 0xb0},
762         {0x3795, 0x00},
763         {0x3796, 0x64},
764         {0x3797, 0x11},
765         {0x3798, 0x30},
766         {0x3799, 0x41},
767         {0x379a, 0x07},
768         {0x379b, 0xb0},
769         {0x379c, 0x0c},
770         {0x37c5, 0x00},
771         {0x37c6, 0x00},
772         {0x37c7, 0x00},
773         {0x37c9, 0x00},
774         {0x37ca, 0x00},
775         {0x37cb, 0x00},
776         {0x37de, 0x00},
777         {0x37df, 0x00},
778         {0x3800, 0x00},
779         {0x3801, 0x00},
780         {0x3802, 0x00},
781         {0x3803, 0xf8},
782         {0x3804, 0x0a},
783         {0x3805, 0x3f},
784         {0x3806, 0x06},
785         {0x3807, 0xab},
786         {0x3808, 0x07},
787         {0x3809, 0x80},
788         {0x380a, 0x04},
789         {0x380b, 0x38},
790         {0x380c, 0x0a},
791         {0x380d, 0x80},
792         {0x380e, 0x07},
793         {0x380f, 0xc0},
794         {0x3810, 0x00},
795         {0x3811, 0x02},
796         {0x3812, 0x00},
797         {0x3813, 0x02},
798         {0x3814, 0x11},
799         {0x3815, 0x11},
800         {0x3820, 0x00},
801         {0x3821, 0x1e},
802         {0x3823, 0x00},
803         {0x3824, 0x00},
804         {0x3825, 0x00},
805         {0x3826, 0x00},
806         {0x3827, 0x00},
807         {0x382a, 0x04},
808         {0x3a04, 0x06},
809         {0x3a05, 0x14},
810         {0x3a06, 0x00},
811         {0x3a07, 0xfe},
812         {0x3b00, 0x00},
813         {0x3b02, 0x00},
814         {0x3b03, 0x00},
815         {0x3b04, 0x00},
816         {0x3b05, 0x00},
817         {0x3e07, 0x20},
818         {0x4000, 0x08},
819         {0x4001, 0x04},
820         {0x4002, 0x45},
821         {0x4004, 0x08},
822         {0x4005, 0x18},
823         {0x4006, 0x20},
824         {0x4008, 0x24},
825         {0x4009, 0x10},
826         {0x400c, 0x00},
827         {0x400d, 0x00},
828         {0x4058, 0x00},
829         {0x404e, 0x37},
830         {0x404f, 0x8f},
831         {0x4058, 0x00},
832         {0x4101, 0xb2},
833         {0x4303, 0x00},
834         {0x4304, 0x08},
835         {0x4307, 0x30},
836         {0x4311, 0x04},
837         {0x4315, 0x01},
838         {0x4511, 0x05},
839         {0x4512, 0x01},
840         {0x4800, 0x20}, /* dis-continuous */
841         {0x4806, 0x00},
842         {0x4816, 0x52},
843         {0x481f, 0x30},
844         {0x4826, 0x2c},
845         {0x4831, 0x64},
846         {0x4d00, 0x04},
847         {0x4d01, 0x71},
848         {0x4d02, 0xfd},
849         {0x4d03, 0xf5},
850         {0x4d04, 0x0c},
851         {0x4d05, 0xcc},
852         {0x4837, 0x0a},
853         {0x5000, 0x06},
854         {0x5001, 0x01},
855         {0x5002, 0x80},
856         {0x5003, 0x20},
857         {0x5046, 0x0a},
858         {0x5013, 0x00},
859         {0x5046, 0x0a},
860         {0x5780, 0x1c},
861         {0x5786, 0x20},
862         {0x5787, 0x10},
863         {0x5788, 0x18},
864         {0x578a, 0x04},
865         {0x578b, 0x02},
866         {0x578c, 0x02},
867         {0x578e, 0x06},
868         {0x578f, 0x02},
869         {0x5790, 0x02},
870         {0x5791, 0xff},
871         {0x5842, 0x01},
872         {0x5843, 0x2b},
873         {0x5844, 0x01},
874         {0x5845, 0x92},
875         {0x5846, 0x01},
876         {0x5847, 0x8f},
877         {0x5848, 0x01},
878         {0x5849, 0x0c},
879         {0x5e00, 0x00},
880         {0x5e10, 0x0c},
881         {OV5693_TABLE_END, 0x0000}
882 };
883
884
885 static const struct ov5693_reg ov5693_1280x720_120fps_i2c[] = {
886         {OV5693_TABLE_RESET, 0},/* Including sw reset */
887         {0x3001, 0x0a},
888         {0x3002, 0x80},
889         {0x3006, 0x00},
890         {0x3011, 0x21},
891         {0x3012, 0x09},
892         {0x3013, 0x10},
893         {0x3014, 0x00},
894         {0x3015, 0x08},
895         {0x3016, 0xf0},
896         {0x3017, 0xf0},
897         {0x3018, 0xf0},
898         {0x301b, 0xb4},
899         {0x301d, 0x02},
900         {0x3021, 0x00},
901         {0x3022, 0x01},
902         {0x3028, 0x44},
903         {0x3098, 0x03},
904         {0x3099, 0x1e},
905         {0x309a, 0x02},
906         {0x309b, 0x01},
907         {0x309c, 0x00},
908         {0x30a0, 0xd2},
909         {0x30a2, 0x01},
910         {0x30b2, 0x00},
911         {0x30b3, 0x68},
912         {0x30b4, 0x03},
913         {0x30b5, 0x04},
914         {0x30b6, 0x01},
915         {0x3104, 0x21},
916         {0x3106, 0x00},
917         {0x3406, 0x01},
918         {0x3500, 0x00},
919         {0x3501, 0x2e},
920         {0x3502, 0x80},
921         {0x3503, 0x07},
922         {0x3504, 0x00},
923         {0x3505, 0x00},
924         {0x3506, 0x00},
925         {0x3507, 0x02},
926         {0x3508, 0x00},
927         {0x3509, 0x10},
928         {0x350a, 0x00},
929         {0x350b, 0x40},
930         {0x3601, 0x0a},
931         {0x3602, 0x38},
932         {0x3612, 0x80},
933         {0x3620, 0x54},
934         {0x3621, 0xc7},
935         {0x3622, 0x0f},
936         {0x3625, 0x10},
937         {0x3630, 0x55},
938         {0x3631, 0xf4},
939         {0x3632, 0x00},
940         {0x3633, 0x34},
941         {0x3634, 0x02},
942         {0x364d, 0x0d},
943         {0x364f, 0xdd},
944         {0x3660, 0x04},
945         {0x3662, 0x10},
946         {0x3663, 0xf1},
947         {0x3665, 0x00},
948         {0x3666, 0x20},
949         {0x3667, 0x00},
950         {0x366a, 0x80},
951         {0x3680, 0xe0},
952         {0x3681, 0x00},
953         {0x3700, 0x42},
954         {0x3701, 0x14},
955         {0x3702, 0xa0},
956         {0x3703, 0xd8},
957         {0x3704, 0x78},
958         {0x3705, 0x02},
959         {0x3708, 0xe6},
960         {0x3709, 0xc7},
961         {0x370a, 0x00},
962         {0x370b, 0x20},
963         {0x370c, 0x0c},
964         {0x370d, 0x11},
965         {0x370e, 0x00},
966         {0x370f, 0x40},
967         {0x3710, 0x00},
968         {0x371a, 0x1c},
969         {0x371b, 0x05},
970         {0x371c, 0x01},
971         {0x371e, 0xa1},
972         {0x371f, 0x0c},
973         {0x3721, 0x00},
974         {0x3724, 0x10},
975         {0x3726, 0x00},
976         {0x372a, 0x01},
977         {0x3730, 0x10},
978         {0x3738, 0x22},
979         {0x3739, 0xe5},
980         {0x373a, 0x50},
981         {0x373b, 0x02},
982         {0x373c, 0x41},
983         {0x373f, 0x02},
984         {0x3740, 0x42},
985         {0x3741, 0x02},
986         {0x3742, 0x18},
987         {0x3743, 0x01},
988         {0x3744, 0x02},
989         {0x3747, 0x10},
990         {0x374c, 0x04},
991         {0x3751, 0xf0},
992         {0x3752, 0x00},
993         {0x3753, 0x00},
994         {0x3754, 0xc0},
995         {0x3755, 0x00},
996         {0x3756, 0x1a},
997         {0x3758, 0x00},
998         {0x3759, 0x0f},
999         {0x376b, 0x44},
1000         {0x375c, 0x04},
1001         {0x3774, 0x10},
1002         {0x3776, 0x00},
1003         {0x377f, 0x08},
1004         {0x3780, 0x22},
1005         {0x3781, 0x0c},
1006         {0x3784, 0x2c},
1007         {0x3785, 0x1e},
1008         {0x378f, 0xf5},
1009         {0x3791, 0xb0},
1010         {0x3795, 0x00},
1011         {0x3796, 0x64},
1012         {0x3797, 0x11},
1013         {0x3798, 0x30},
1014         {0x3799, 0x41},
1015         {0x379a, 0x07},
1016         {0x379b, 0xb0},
1017         {0x379c, 0x0c},
1018         {0x37c5, 0x00},
1019         {0x37c6, 0x00},
1020         {0x37c7, 0x00},
1021         {0x37c9, 0x00},
1022         {0x37ca, 0x00},
1023         {0x37cb, 0x00},
1024         {0x37de, 0x00},
1025         {0x37df, 0x00},
1026         {0x3800, 0x00},
1027         {0x3801, 0x00},
1028         {0x3802, 0x00},
1029         {0x3803, 0xf4},
1030         {0x3804, 0x0a},
1031         {0x3805, 0x3f},
1032         {0x3806, 0x06},
1033         {0x3807, 0xab},
1034         {0x3808, 0x05},
1035         {0x3809, 0x00},
1036         {0x380a, 0x02},
1037         {0x380b, 0xd0},
1038         {0x380c, 0x06},
1039         {0x380d, 0xd8},
1040         {0x380e, 0x02},
1041         {0x380f, 0xf8},
1042         {0x3810, 0x00},
1043         {0x3811, 0x02},
1044         {0x3812, 0x00},
1045         {0x3813, 0x02},
1046         {0x3814, 0x31},
1047         {0x3815, 0x31},
1048         {0x3820, 0x04},
1049         {0x3821, 0x1f},
1050         {0x3823, 0x00},
1051         {0x3824, 0x00},
1052         {0x3825, 0x00},
1053         {0x3826, 0x00},
1054         {0x3827, 0x00},
1055         {0x382a, 0x04},
1056         {0x3a04, 0x06},
1057         {0x3a05, 0x14},
1058         {0x3a06, 0x00},
1059         {0x3a07, 0xfe},
1060         {0x3b00, 0x00},
1061         {0x3b02, 0x00},
1062         {0x3b03, 0x00},
1063         {0x3b04, 0x00},
1064         {0x3b05, 0x00},
1065         {0x3e07, 0x20},
1066         {0x4000, 0x08},
1067         {0x4001, 0x04},
1068         {0x4002, 0x45},
1069         {0x4004, 0x08},
1070         {0x4005, 0x18},
1071         {0x4006, 0x20},
1072         {0x4008, 0x24},
1073         {0x4009, 0x10},
1074         {0x400c, 0x00},
1075         {0x400d, 0x00},
1076         {0x4058, 0x00},
1077         {0x404e, 0x37},
1078         {0x404f, 0x8f},
1079         {0x4058, 0x00},
1080         {0x4101, 0xb2},
1081         {0x4303, 0x00},
1082         {0x4304, 0x08},
1083         {0x4307, 0x30},
1084         {0x4311, 0x04},
1085         {0x4315, 0x01},
1086         {0x4511, 0x05},
1087         {0x4512, 0x00},
1088         {0x4800, 0x20}, /* dis-continuous */
1089         {0x4806, 0x00},
1090         {0x4816, 0x52},
1091         {0x481f, 0x30},
1092         {0x4826, 0x2c},
1093         {0x4831, 0x64},
1094         {0x4d00, 0x04},
1095         {0x4d01, 0x71},
1096         {0x4d02, 0xfd},
1097         {0x4d03, 0xf5},
1098         {0x4d04, 0x0c},
1099         {0x4d05, 0xcc},
1100         {0x4837, 0x0a},
1101         {0x5000, 0x06},
1102         {0x5001, 0x01},
1103         {0x5002, 0x00},
1104         {0x5003, 0x20},
1105         {0x5046, 0x0a},
1106         {0x5013, 0x00},
1107         {0x5046, 0x0a},
1108         {0x5780, 0x1c},
1109         {0x5786, 0x20},
1110         {0x5787, 0x10},
1111         {0x5788, 0x18},
1112         {0x578a, 0x04},
1113         {0x578b, 0x02},
1114         {0x578c, 0x02},
1115         {0x578e, 0x06},
1116         {0x578f, 0x02},
1117         {0x5790, 0x02},
1118         {0x5791, 0xff},
1119         {0x5842, 0x01},
1120         {0x5843, 0x2b},
1121         {0x5844, 0x01},
1122         {0x5845, 0x92},
1123         {0x5846, 0x01},
1124         {0x5847, 0x8f},
1125         {0x5848, 0x01},
1126         {0x5849, 0x0c},
1127         {0x5e00, 0x00},
1128         {0x5e10, 0x0c},
1129         {OV5693_TABLE_END, 0x0000}
1130 };
1131
1132 static const struct ov5693_reg ov5693_2592x1944_HDR_24fps_i2c[] = {
1133         {OV5693_TABLE_RESET, 0},/* Including sw reset */
1134         {0x0103, 0x01},
1135         {0x3001, 0x0a},
1136         {0x3002, 0x80},
1137         {0x3006, 0x00},
1138         {0x3011, 0x21},
1139         {0x3012, 0x09},
1140         {0x3013, 0x10},
1141         {0x3014, 0x00},
1142         {0x3015, 0x08},
1143         {0x3016, 0xf0},
1144         {0x3017, 0xf0},
1145         {0x3018, 0xf0},
1146         {0x301b, 0xb4},
1147         {0x301d, 0x02},
1148         {0x3021, 0x00},
1149         {0x3022, 0x01},
1150         {0x3028, 0x44},
1151         {0x3098, 0x02},
1152         {0x3099, 0x16},
1153         {0x309a, 0x02},
1154         {0x309b, 0x01},
1155         {0x309c, 0x00},
1156         {0x30b2, 0x00},
1157         {0x30b3, 0x6e},
1158         {0x30b4, 0x03},
1159         {0x30a0, 0xd2},
1160         {0x30a2, 0x01},
1161         {0x30b5, 0x04},
1162         {0x30b6, 0x01},
1163         {0x3104, 0x21},
1164         {0x3106, 0x00},
1165         {0x3406, 0x01},
1166         {0x3500, 0x00},
1167         {0x3501, 0x7b},
1168         {0x3502, 0x80},
1169         {0x3503, 0x07},
1170         {0x3504, 0x00},
1171         {0x3505, 0x00},
1172         {0x3506, 0x00},
1173         {0x3507, 0x01},
1174         {0x3508, 0x80},
1175         {0x3509, 0x10},
1176         {0x350a, 0x00},
1177         {0x350b, 0x40},
1178         {0x3601, 0x0a},
1179         {0x3602, 0x38},
1180         {0x3612, 0x80},
1181         {0x3620, 0x54},
1182         {0x3621, 0xc7},
1183         {0x3622, 0x05},
1184         {0x3625, 0x10},
1185         {0x3630, 0x55},
1186         {0x3631, 0xf4},
1187         {0x3632, 0x00},
1188         {0x3633, 0x34},
1189         {0x3634, 0x02},
1190         {0x364d, 0x0d},
1191         {0x364f, 0xdd},
1192         {0x3660, 0x04},
1193         {0x3662, 0x10},
1194         {0x3663, 0xf1},
1195         {0x3665, 0x00},
1196         {0x3666, 0x20},
1197         {0x3667, 0x00},
1198         {0x366a, 0x80},
1199         {0x3680, 0xe0},
1200         {0x3681, 0x00},
1201         {0x3700, 0x42},
1202         {0x3701, 0x14},
1203         {0x3702, 0xa0},
1204         {0x3703, 0xa8},
1205         {0x3704, 0x78},
1206         {0x3705, 0x02},
1207         {0x3708, 0xe2},
1208         {0x3709, 0xc3},
1209         {0x370a, 0x00},
1210         {0x370b, 0x20},
1211         {0x370c, 0x0c},
1212         {0x370d, 0x11},
1213         {0x370e, 0x00},
1214         {0x370f, 0x40},
1215         {0x3710, 0x00},
1216         {0x371a, 0x0c},
1217         {0x371b, 0x05},
1218         {0x371c, 0x01},
1219         {0x371e, 0xa1},
1220         {0x371f, 0x0c},
1221         {0x3721, 0x00},
1222         {0x3724, 0x10},
1223         {0x3726, 0x00},
1224         {0x372a, 0x01},
1225         {0x3730, 0x10},
1226         {0x3738, 0x22},
1227         {0x3739, 0xe5},
1228         {0x373a, 0x50},
1229         {0x373b, 0x02},
1230         {0x373c, 0x41},
1231         {0x373f, 0x02},
1232         {0x3740, 0x42},
1233         {0x3741, 0x02},
1234         {0x3742, 0x18},
1235         {0x3743, 0x01},
1236         {0x3744, 0x02},
1237         {0x3747, 0x10},
1238         {0x374c, 0x04},
1239         {0x3751, 0xf0},
1240         {0x3752, 0x00},
1241         {0x3753, 0x00},
1242         {0x3754, 0xc0},
1243         {0x3755, 0x00},
1244         {0x3756, 0x1a},
1245         {0x3758, 0x00},
1246         {0x3759, 0x0f},
1247         {0x376b, 0x44},
1248         {0x375c, 0x04},
1249         {0x3774, 0x10},
1250         {0x3776, 0x00},
1251         {0x377f, 0x08},
1252         {0x3780, 0x22},
1253         {0x3781, 0x0c},
1254         {0x3784, 0x2c},
1255         {0x3785, 0x1e},
1256         {0x378f, 0xf5},
1257         {0x3791, 0xb0},
1258         {0x3795, 0x00},
1259         {0x3796, 0x64},
1260         {0x3797, 0x11},
1261         {0x3798, 0x30},
1262         {0x3799, 0x41},
1263         {0x379a, 0x07},
1264         {0x379b, 0xb0},
1265         {0x379c, 0x0c},
1266         {0x37c5, 0x00},
1267         {0x37c6, 0x00},
1268         {0x37c7, 0x00},
1269         {0x37c9, 0x00},
1270         {0x37ca, 0x00},
1271         {0x37cb, 0x00},
1272         {0x37de, 0x00},
1273         {0x37df, 0x00},
1274         {0x3800, 0x00},
1275         {0x3801, 0x02},
1276         {0x3802, 0x00},
1277         {0x3803, 0x06},
1278         {0x3804, 0x0a},
1279         {0x3805, 0x41},
1280         {0x3806, 0x07},
1281         {0x3807, 0xa1},
1282         {0x3808, 0x0a},
1283         {0x3809, 0x20},
1284         {0x380a, 0x07},
1285         {0x380b, 0x98},
1286         {0x380c, 0x0e},
1287         {0x380d, 0x70},
1288         {0x380e, 0x07},
1289         {0x380f, 0xc0},
1290         {0x3810, 0x00},
1291         {0x3811, 0x10},
1292         {0x3812, 0x00},
1293         {0x3813, 0x02},
1294         {0x3814, 0x11},
1295         {0x3815, 0x11},
1296         {0x3820, 0x00},
1297         {0x3821, 0x9e},
1298         {0x3823, 0x00},
1299         {0x3824, 0x00},
1300         {0x3825, 0x00},
1301         {0x3826, 0x00},
1302         {0x3827, 0x00},
1303         {0x382a, 0x04},
1304         {0x3a04, 0x09},
1305         {0x3a05, 0xa9},
1306         {0x3a06, 0x00},
1307         {0x3a07, 0xfe},
1308         {0x3b00, 0x00},
1309         {0x3b02, 0x00},
1310         {0x3b03, 0x00},
1311         {0x3b04, 0x00},
1312         {0x3b05, 0x00},
1313         {0x3e07, 0x20},
1314         {0x4000, 0x08},
1315         {0x4001, 0x04},
1316         {0x4002, 0x45},
1317         {0x4004, 0x08},
1318         {0x4005, 0x18},
1319         {0x4006, 0x20},
1320         {0x4008, 0x24},
1321         {0x4009, 0x10},
1322         {0x400c, 0x00},
1323         {0x400d, 0x00},
1324         {0x4058, 0x00},
1325         {0x404e, 0x37},
1326         {0x404f, 0x8f},
1327         {0x4058, 0x00},
1328         {0x4101, 0xb2},
1329         {0x4303, 0x00},
1330         {0x4304, 0x08},
1331         {0x4307, 0x30},
1332         {0x4311, 0x04},
1333         {0x4315, 0x01},
1334         {0x4511, 0x05},
1335         {0x4512, 0x01},
1336         {0x4800, 0x20}, /* dis-continuous */
1337         {0x4806, 0x00},
1338         {0x4816, 0x52},
1339         {0x481f, 0x30},
1340         {0x4826, 0x2c},
1341         {0x4831, 0x64},
1342         {0x4d00, 0x04},
1343         {0x4d01, 0x71},
1344         {0x4d02, 0xfd},
1345         {0x4d03, 0xf5},
1346         {0x4d04, 0x0c},
1347         {0x4d05, 0xcc},
1348         {0x4837, 0x0a},
1349         {0x5000, 0x06},
1350         {0x5001, 0x01},
1351         {0x5002, 0x00},
1352         {0x5003, 0x20},
1353         {0x5046, 0x0a},
1354         {0x5013, 0x00},
1355         {0x5046, 0x0a},
1356         {0x5780, 0x1c},
1357         {0x5786, 0x20},
1358         {0x5787, 0x10},
1359         {0x5788, 0x18},
1360         {0x578a, 0x04},
1361         {0x578b, 0x02},
1362         {0x578c, 0x02},
1363         {0x578e, 0x06},
1364         {0x578f, 0x02},
1365         {0x5790, 0x02},
1366         {0x5791, 0xff},
1367         {0x5842, 0x01},
1368         {0x5843, 0x2b},
1369         {0x5844, 0x01},
1370         {0x5845, 0x92},
1371         {0x5846, 0x01},
1372         {0x5847, 0x8f},
1373         {0x5848, 0x01},
1374         {0x5849, 0x0c},
1375         {0x5e00, 0x00},
1376         {0x5e10, 0x0c},
1377         {OV5693_TABLE_END, 0x0000}
1378 };
1379
1380 static const struct ov5693_reg ov5693_1920x1080_HDR_30fps_i2c[] = {
1381         {OV5693_TABLE_RESET, 0},/* Including sw reset */
1382         {0x0103, 0x01},
1383         {0x3001, 0x0a},
1384         {0x3002, 0x80},
1385         {0x3006, 0x00},
1386         {0x3011, 0x21},
1387         {0x3012, 0x09},
1388         {0x3013, 0x10},
1389         {0x3014, 0x00},
1390         {0x3015, 0x08},
1391         {0x3016, 0xf0},
1392         {0x3017, 0xf0},
1393         {0x3018, 0xf0},
1394         {0x301b, 0xb4},
1395         {0x301d, 0x02},
1396         {0x3021, 0x00},
1397         {0x3022, 0x01},
1398         {0x3028, 0x44},
1399         {0x3098, 0x03},
1400         {0x3099, 0x1e},
1401         {0x309a, 0x02},
1402         {0x309b, 0x01},
1403         {0x309c, 0x00},
1404         {0x30a0, 0xd2},
1405         {0x30a2, 0x01},
1406         {0x30b2, 0x00},
1407         {0x30b3, 0x68},
1408         {0x30b4, 0x03},
1409         {0x30b5, 0x04},
1410         {0x30b6, 0x01},
1411         {0x3104, 0x21},
1412         {0x3106, 0x00},
1413         {0x3406, 0x01},
1414         {0x3500, 0x00},
1415         {0x3501, 0x72},
1416         {0x3502, 0x00},
1417         {0x3503, 0x07},
1418         {0x3504, 0x00},
1419         {0x3505, 0x00},
1420         {0x3506, 0x00},
1421         {0x3507, 0x01},
1422         {0x3508, 0x80},
1423         {0x3509, 0x10},
1424         {0x350a, 0x00},
1425         {0x350b, 0x40},
1426         {0x3601, 0x0a},
1427         {0x3602, 0x38},
1428         {0x3612, 0x80},
1429         {0x3620, 0x54},
1430         {0x3621, 0xc7},
1431         {0x3622, 0x0f},
1432         {0x3625, 0x10},
1433         {0x3630, 0x55},
1434         {0x3631, 0xf4},
1435         {0x3632, 0x00},
1436         {0x3633, 0x34},
1437         {0x3634, 0x02},
1438         {0x364d, 0x0d},
1439         {0x364f, 0xdd},
1440         {0x3660, 0x04},
1441         {0x3662, 0x10},
1442         {0x3663, 0xf1},
1443         {0x3665, 0x00},
1444         {0x3666, 0x20},
1445         {0x3667, 0x00},
1446         {0x366a, 0x80},
1447         {0x3680, 0xe0},
1448         {0x3681, 0x00},
1449         {0x3700, 0x42},
1450         {0x3701, 0x14},
1451         {0x3702, 0xa0},
1452         {0x3703, 0xd8},
1453         {0x3704, 0x78},
1454         {0x3705, 0x02},
1455         {0x3708, 0xe2},
1456         {0x3709, 0xc3},
1457         {0x370a, 0x00},
1458         {0x370b, 0x20},
1459         {0x370c, 0x0c},
1460         {0x370d, 0x11},
1461         {0x370e, 0x00},
1462         {0x370f, 0x40},
1463         {0x3710, 0x00},
1464         {0x371a, 0x1c},
1465         {0x371b, 0x05},
1466         {0x371c, 0x01},
1467         {0x371e, 0xa1},
1468         {0x371f, 0x0c},
1469         {0x3721, 0x00},
1470         {0x3724, 0x10},
1471         {0x3726, 0x00},
1472         {0x372a, 0x01},
1473         {0x3730, 0x10},
1474         {0x3738, 0x22},
1475         {0x3739, 0xe5},
1476         {0x373a, 0x50},
1477         {0x373b, 0x02},
1478         {0x373c, 0x41},
1479         {0x373f, 0x02},
1480         {0x3740, 0x42},
1481         {0x3741, 0x02},
1482         {0x3742, 0x18},
1483         {0x3743, 0x01},
1484         {0x3744, 0x02},
1485         {0x3747, 0x10},
1486         {0x374c, 0x04},
1487         {0x3751, 0xf0},
1488         {0x3752, 0x00},
1489         {0x3753, 0x00},
1490         {0x3754, 0xc0},
1491         {0x3755, 0x00},
1492         {0x3756, 0x1a},
1493         {0x3758, 0x00},
1494         {0x3759, 0x0f},
1495         {0x376b, 0x44},
1496         {0x375c, 0x04},
1497         {0x3774, 0x10},
1498         {0x3776, 0x00},
1499         {0x377f, 0x08},
1500         {0x3780, 0x22},
1501         {0x3781, 0x0c},
1502         {0x3784, 0x2c},
1503         {0x3785, 0x1e},
1504         {0x378f, 0xf5},
1505         {0x3791, 0xb0},
1506         {0x3795, 0x00},
1507         {0x3796, 0x64},
1508         {0x3797, 0x11},
1509         {0x3798, 0x30},
1510         {0x3799, 0x41},
1511         {0x379a, 0x07},
1512         {0x379b, 0xb0},
1513         {0x379c, 0x0c},
1514         {0x37c5, 0x00},
1515         {0x37c6, 0x00},
1516         {0x37c7, 0x00},
1517         {0x37c9, 0x00},
1518         {0x37ca, 0x00},
1519         {0x37cb, 0x00},
1520         {0x37de, 0x00},
1521         {0x37df, 0x00},
1522         {0x3800, 0x01},
1523         {0x3801, 0x70},
1524         {0x3802, 0x01},
1525         {0x3803, 0xbc},
1526         {0x3804, 0x09},
1527         {0x3805, 0x0f},
1528         {0x3806, 0x05},
1529         {0x3807, 0xff},
1530         {0x3808, 0x07},
1531         {0x3809, 0x80},
1532         {0x380a, 0x04},
1533         {0x380b, 0x38},
1534         {0x380c, 0x0b},
1535         {0x380d, 0x40},
1536         {0x380e, 0x07},
1537         {0x380f, 0x3a},
1538         {0x3810, 0x00},
1539         {0x3811, 0x02},
1540         {0x3812, 0x00},
1541         {0x3813, 0x02},
1542         {0x3814, 0x11},
1543         {0x3815, 0x11},
1544         {0x3820, 0x00},
1545         {0x3821, 0x9e},
1546         {0x3823, 0x00},
1547         {0x3824, 0x00},
1548         {0x3825, 0x00},
1549         {0x3826, 0x00},
1550         {0x3827, 0x00},
1551         {0x382a, 0x04},
1552         {0x3a04, 0x09},
1553         {0x3a05, 0xa9},
1554         {0x3a06, 0x00},
1555         {0x3a07, 0xfe},
1556         {0x3b00, 0x00},
1557         {0x3b02, 0x00},
1558         {0x3b03, 0x00},
1559         {0x3b04, 0x00},
1560         {0x3b05, 0x00},
1561         {0x3e07, 0x20},
1562         {0x4000, 0x08},
1563         {0x4001, 0x04},
1564         {0x4002, 0x45},
1565         {0x4004, 0x08},
1566         {0x4005, 0x18},
1567         {0x4006, 0x20},
1568         {0x4008, 0x24},
1569         {0x4009, 0x10},
1570         {0x400c, 0x00},
1571         {0x400d, 0x00},
1572         {0x4058, 0x00},
1573         {0x404e, 0x37},
1574         {0x404f, 0x8f},
1575         {0x4058, 0x00},
1576         {0x4101, 0xb2},
1577         {0x4303, 0x00},
1578         {0x4304, 0x08},
1579         {0x4307, 0x30},
1580         {0x4311, 0x04},
1581         {0x4315, 0x01},
1582         {0x4511, 0x05},
1583         {0x4512, 0x01},
1584         {0x4800, 0x20}, /* dis-continuous */
1585         {0x4806, 0x00},
1586         {0x4816, 0x52},
1587         {0x481f, 0x30},
1588         {0x4826, 0x2c},
1589         {0x4831, 0x64},
1590         {0x4d00, 0x04},
1591         {0x4d01, 0x71},
1592         {0x4d02, 0xfd},
1593         {0x4d03, 0xf5},
1594         {0x4d04, 0x0c},
1595         {0x4d05, 0xcc},
1596         {0x4837, 0x0a},
1597         {0x5000, 0x06},
1598         {0x5001, 0x01},
1599         {0x5002, 0x00},
1600         {0x5003, 0x20},
1601         {0x5046, 0x0a},
1602         {0x5013, 0x00},
1603         {0x5046, 0x0a},
1604         {0x5780, 0x1c},
1605         {0x5786, 0x20},
1606         {0x5787, 0x10},
1607         {0x5788, 0x18},
1608         {0x578a, 0x04},
1609         {0x578b, 0x02},
1610         {0x578c, 0x02},
1611         {0x578e, 0x06},
1612         {0x578f, 0x02},
1613         {0x5790, 0x02},
1614         {0x5791, 0xff},
1615         {0x5842, 0x01},
1616         {0x5843, 0x2b},
1617         {0x5844, 0x01},
1618         {0x5845, 0x92},
1619         {0x5846, 0x01},
1620         {0x5847, 0x8f},
1621         {0x5848, 0x01},
1622         {0x5849, 0x0c},
1623         {0x5e00, 0x00},
1624         {0x5e10, 0x0c},
1625         {OV5693_TABLE_END, 0x0000}
1626 };
1627
1628 static const struct ov5693_reg ov5693_1296x972_HDR_30fps_i2c[] = {
1629         {OV5693_TABLE_RESET, 0},/* Including sw reset */
1630         {0x0103, 0x01},
1631         {0x3001, 0x0a},
1632         {0x3002, 0x80},
1633         {0x3006, 0x00},
1634         {0x3011, 0x21},
1635         {0x3012, 0x09},
1636         {0x3013, 0x10},
1637         {0x3014, 0x00},
1638         {0x3015, 0x08},
1639         {0x3016, 0xf0},
1640         {0x3017, 0xf0},
1641         {0x3018, 0xf0},
1642         {0x301b, 0xb4},
1643         {0x301d, 0x02},
1644         {0x3021, 0x00},
1645         {0x3022, 0x01},
1646         {0x3028, 0x44},
1647         {0x3098, 0x03},
1648         {0x3099, 0x1e},
1649         {0x309a, 0x02},
1650         {0x309b, 0x01},
1651         {0x309c, 0x00},
1652         {0x30a0, 0xd2},
1653         {0x30a2, 0x01},
1654         {0x30b2, 0x00},
1655         {0x30b3, 0x68},
1656         {0x30b4, 0x03},
1657         {0x30b5, 0x04},
1658         {0x30b6, 0x01},
1659         {0x3104, 0x21},
1660         {0x3106, 0x00},
1661         {0x3406, 0x01},
1662         {0x3500, 0x00},
1663         {0x3501, 0x72},
1664         {0x3502, 0x00},
1665         {0x3503, 0x07},
1666         {0x3504, 0x00},
1667         {0x3505, 0x00},
1668         {0x3506, 0x00},
1669         {0x3507, 0x01},
1670         {0x3508, 0x80},
1671         {0x3509, 0x10},
1672         {0x350a, 0x00},
1673         {0x350b, 0x40},
1674         {0x3601, 0x0a},
1675         {0x3602, 0x38},
1676         {0x3612, 0x80},
1677         {0x3620, 0x54},
1678         {0x3621, 0xc7},
1679         {0x3622, 0x0f},
1680         {0x3625, 0x10},
1681         {0x3630, 0x55},
1682         {0x3631, 0xf4},
1683         {0x3632, 0x00},
1684         {0x3633, 0x34},
1685         {0x3634, 0x02},
1686         {0x364d, 0x0d},
1687         {0x364f, 0xdd},
1688         {0x3660, 0x04},
1689         {0x3662, 0x10},
1690         {0x3663, 0xf1},
1691         {0x3665, 0x00},
1692         {0x3666, 0x20},
1693         {0x3667, 0x00},
1694         {0x366a, 0x80},
1695         {0x3680, 0xe0},
1696         {0x3681, 0x00},
1697         {0x3700, 0x42},
1698         {0x3701, 0x14},
1699         {0x3702, 0xa0},
1700         {0x3703, 0xd8},
1701         {0x3704, 0x78},
1702         {0x3705, 0x02},
1703         {0x3708, 0xe2},
1704         {0x3709, 0xc3},
1705         {0x370a, 0x00},
1706         {0x370b, 0x20},
1707         {0x370c, 0x0c},
1708         {0x370d, 0x11},
1709         {0x370e, 0x00},
1710         {0x370f, 0x40},
1711         {0x3710, 0x00},
1712         {0x371a, 0x1c},
1713         {0x371b, 0x05},
1714         {0x371c, 0x01},
1715         {0x371e, 0xa1},
1716         {0x371f, 0x0c},
1717         {0x3721, 0x00},
1718         {0x3724, 0x10},
1719         {0x3726, 0x00},
1720         {0x372a, 0x01},
1721         {0x3730, 0x10},
1722         {0x3738, 0x22},
1723         {0x3739, 0xe5},
1724         {0x373a, 0x50},
1725         {0x373b, 0x02},
1726         {0x373c, 0x41},
1727         {0x373f, 0x02},
1728         {0x3740, 0x42},
1729         {0x3741, 0x02},
1730         {0x3742, 0x18},
1731         {0x3743, 0x01},
1732         {0x3744, 0x02},
1733         {0x3747, 0x10},
1734         {0x374c, 0x04},
1735         {0x3751, 0xf0},
1736         {0x3752, 0x00},
1737         {0x3753, 0x00},
1738         {0x3754, 0xc0},
1739         {0x3755, 0x00},
1740         {0x3756, 0x1a},
1741         {0x3758, 0x00},
1742         {0x3759, 0x0f},
1743         {0x376b, 0x44},
1744         {0x375c, 0x04},
1745         {0x3774, 0x10},
1746         {0x3776, 0x00},
1747         {0x377f, 0x08},
1748         {0x3780, 0x22},
1749         {0x3781, 0x0c},
1750         {0x3784, 0x2c},
1751         {0x3785, 0x1e},
1752         {0x378f, 0xf5},
1753         {0x3791, 0xb0},
1754         {0x3795, 0x00},
1755         {0x3796, 0x64},
1756         {0x3797, 0x11},
1757         {0x3798, 0x30},
1758         {0x3799, 0x41},
1759         {0x379a, 0x07},
1760         {0x379b, 0xb0},
1761         {0x379c, 0x0c},
1762         {0x37c5, 0x00},
1763         {0x37c6, 0x00},
1764         {0x37c7, 0x00},
1765         {0x37c9, 0x00},
1766         {0x37ca, 0x00},
1767         {0x37cb, 0x00},
1768         {0x37de, 0x00},
1769         {0x37df, 0x00},
1770         {0x3800, 0x02},
1771         {0x3801, 0xa0},
1772         {0x3802, 0x01},
1773         {0x3803, 0xe8},
1774         {0x3804, 0x07},
1775         {0x3805, 0xb7},
1776         {0x3806, 0x05},
1777         {0x3807, 0xb9},
1778         {0x3808, 0x05},
1779         {0x3809, 0x10},
1780         {0x380a, 0x03},
1781         {0x380b, 0xcc},
1782         {0x380c, 0x0b},
1783         {0x380d, 0x40},
1784         {0x380e, 0x07},
1785         {0x380f, 0x3a},
1786         {0x3810, 0x00},
1787         {0x3811, 0x02},
1788         {0x3812, 0x00},
1789         {0x3813, 0x02},
1790         {0x3814, 0x11},
1791         {0x3815, 0x11},
1792         {0x3820, 0x00},
1793         {0x3821, 0x9e},
1794         {0x3823, 0x00},
1795         {0x3824, 0x00},
1796         {0x3825, 0x00},
1797         {0x3826, 0x00},
1798         {0x3827, 0x00},
1799         {0x382a, 0x04},
1800         {0x3a04, 0x09},
1801         {0x3a05, 0xa9},
1802         {0x3a06, 0x00},
1803         {0x3a07, 0xfe},
1804         {0x3b00, 0x00},
1805         {0x3b02, 0x00},
1806         {0x3b03, 0x00},
1807         {0x3b04, 0x00},
1808         {0x3b05, 0x00},
1809         {0x3e07, 0x20},
1810         {0x4000, 0x08},
1811         {0x4001, 0x04},
1812         {0x4002, 0x45},
1813         {0x4004, 0x08},
1814         {0x4005, 0x18},
1815         {0x4006, 0x20},
1816         {0x4008, 0x24},
1817         {0x4009, 0x10},
1818         {0x400c, 0x00},
1819         {0x400d, 0x00},
1820         {0x4058, 0x00},
1821         {0x404e, 0x37},
1822         {0x404f, 0x8f},
1823         {0x4058, 0x00},
1824         {0x4101, 0xb2},
1825         {0x4303, 0x00},
1826         {0x4304, 0x08},
1827         {0x4307, 0x30},
1828         {0x4311, 0x04},
1829         {0x4315, 0x01},
1830         {0x4511, 0x05},
1831         {0x4512, 0x01},
1832         {0x4800, 0x20}, /* dis-continuous */
1833         {0x4806, 0x00},
1834         {0x4816, 0x52},
1835         {0x481f, 0x30},
1836         {0x4826, 0x2c},
1837         {0x4831, 0x64},
1838         {0x4d00, 0x04},
1839         {0x4d01, 0x71},
1840         {0x4d02, 0xfd},
1841         {0x4d03, 0xf5},
1842         {0x4d04, 0x0c},
1843         {0x4d05, 0xcc},
1844         {0x4837, 0x0a},
1845         {0x5000, 0x06},
1846         {0x5001, 0x01},
1847         {0x5002, 0x00},
1848         {0x5003, 0x20},
1849         {0x5046, 0x0a},
1850         {0x5013, 0x00},
1851         {0x5046, 0x0a},
1852         {0x5780, 0x1c},
1853         {0x5786, 0x20},
1854         {0x5787, 0x10},
1855         {0x5788, 0x18},
1856         {0x578a, 0x04},
1857         {0x578b, 0x02},
1858         {0x578c, 0x02},
1859         {0x578e, 0x06},
1860         {0x578f, 0x02},
1861         {0x5790, 0x02},
1862         {0x5791, 0xff},
1863         {0x5842, 0x01},
1864         {0x5843, 0x2b},
1865         {0x5844, 0x01},
1866         {0x5845, 0x92},
1867         {0x5846, 0x01},
1868         {0x5847, 0x8f},
1869         {0x5848, 0x01},
1870         {0x5849, 0x0c},
1871         {0x5e00, 0x00},
1872         {0x5e10, 0x0c},
1873         {OV5693_TABLE_END, 0x0000}
1874 };
1875
1876 static const struct ov5693_reg ov5693_1280x720_HDR_60fps_i2c[] = {
1877         {OV5693_TABLE_RESET, 0},/* Including sw reset */
1878         {0x0103, 0x01},
1879         {0x3001, 0x0a},
1880         {0x3002, 0x80},
1881         {0x3006, 0x00},
1882         {0x3011, 0x21},
1883         {0x3012, 0x09},
1884         {0x3013, 0x10},
1885         {0x3014, 0x00},
1886         {0x3015, 0x08},
1887         {0x3016, 0xf0},
1888         {0x3017, 0xf0},
1889         {0x3018, 0xf0},
1890         {0x301b, 0xb4},
1891         {0x301d, 0x02},
1892         {0x3021, 0x00},
1893         {0x3022, 0x01},
1894         {0x3028, 0x44},
1895         {0x3098, 0x03},
1896         {0x3099, 0x1e},
1897         {0x309a, 0x02},
1898         {0x309b, 0x01},
1899         {0x309c, 0x00},
1900         {0x30a0, 0xd2},
1901         {0x30a2, 0x01},
1902         {0x30b2, 0x00},
1903         {0x30b3, 0x68},
1904         {0x30b4, 0x03},
1905         {0x30b5, 0x04},
1906         {0x30b6, 0x01},
1907         {0x3104, 0x21},
1908         {0x3106, 0x00},
1909         {0x3406, 0x01},
1910         {0x3500, 0x00},
1911         {0x3501, 0x39},
1912         {0x3502, 0x00},
1913         {0x3503, 0x07},
1914         {0x3504, 0x00},
1915         {0x3505, 0x00},
1916         {0x3506, 0x00},
1917         {0x3507, 0x01},
1918         {0x3508, 0x80},
1919         {0x3509, 0x10},
1920         {0x350a, 0x00},
1921         {0x350b, 0x40},
1922         {0x3601, 0x0a},
1923         {0x3602, 0x38},
1924         {0x3612, 0x80},
1925         {0x3620, 0x54},
1926         {0x3621, 0xc7},
1927         {0x3622, 0x0f},
1928         {0x3625, 0x10},
1929         {0x3630, 0x55},
1930         {0x3631, 0xf4},
1931         {0x3632, 0x00},
1932         {0x3633, 0x34},
1933         {0x3634, 0x02},
1934         {0x364d, 0x0d},
1935         {0x364f, 0xdd},
1936         {0x3660, 0x04},
1937         {0x3662, 0x10},
1938         {0x3663, 0xf1},
1939         {0x3665, 0x00},
1940         {0x3666, 0x20},
1941         {0x3667, 0x00},
1942         {0x366a, 0x80},
1943         {0x3680, 0xe0},
1944         {0x3681, 0x00},
1945         {0x3700, 0x42},
1946         {0x3701, 0x14},
1947         {0x3702, 0xa0},
1948         {0x3703, 0xd8},
1949         {0x3704, 0x78},
1950         {0x3705, 0x02},
1951         {0x3708, 0xe2},
1952         {0x3709, 0xc3},
1953         {0x370a, 0x00},
1954         {0x370b, 0x20},
1955         {0x370c, 0x0c},
1956         {0x370d, 0x11},
1957         {0x370e, 0x00},
1958         {0x370f, 0x40},
1959         {0x3710, 0x00},
1960         {0x371a, 0x1c},
1961         {0x371b, 0x05},
1962         {0x371c, 0x01},
1963         {0x371e, 0xa1},
1964         {0x371f, 0x0c},
1965         {0x3721, 0x00},
1966         {0x3724, 0x10},
1967         {0x3726, 0x00},
1968         {0x372a, 0x01},
1969         {0x3730, 0x10},
1970         {0x3738, 0x22},
1971         {0x3739, 0xe5},
1972         {0x373a, 0x50},
1973         {0x373b, 0x02},
1974         {0x373c, 0x41},
1975         {0x373f, 0x02},
1976         {0x3740, 0x42},
1977         {0x3741, 0x02},
1978         {0x3742, 0x18},
1979         {0x3743, 0x01},
1980         {0x3744, 0x02},
1981         {0x3747, 0x10},
1982         {0x374c, 0x04},
1983         {0x3751, 0xf0},
1984         {0x3752, 0x00},
1985         {0x3753, 0x00},
1986         {0x3754, 0xc0},
1987         {0x3755, 0x00},
1988         {0x3756, 0x1a},
1989         {0x3758, 0x00},
1990         {0x3759, 0x0f},
1991         {0x376b, 0x44},
1992         {0x375c, 0x04},
1993         {0x3774, 0x10},
1994         {0x3776, 0x00},
1995         {0x377f, 0x08},
1996         {0x3780, 0x22},
1997         {0x3781, 0x0c},
1998         {0x3784, 0x2c},
1999         {0x3785, 0x1e},
2000         {0x378f, 0xf5},
2001         {0x3791, 0xb0},
2002         {0x3795, 0x00},
2003         {0x3796, 0x64},
2004         {0x3797, 0x11},
2005         {0x3798, 0x30},
2006         {0x3799, 0x41},
2007         {0x379a, 0x07},
2008         {0x379b, 0xb0},
2009         {0x379c, 0x0c},
2010         {0x37c5, 0x00},
2011         {0x37c6, 0x00},
2012         {0x37c7, 0x00},
2013         {0x37c9, 0x00},
2014         {0x37ca, 0x00},
2015         {0x37cb, 0x00},
2016         {0x37de, 0x00},
2017         {0x37df, 0x00},
2018         {0x3800, 0x02},
2019         {0x3801, 0xa8},
2020         {0x3802, 0x02},
2021         {0x3803, 0x68},
2022         {0x3804, 0x07},
2023         {0x3805, 0xb7},
2024         {0x3806, 0x05},
2025         {0x3807, 0x3b},
2026         {0x3808, 0x05},
2027         {0x3809, 0x00},
2028         {0x380a, 0x02},
2029         {0x380b, 0xd0},
2030         {0x380c, 0x0b},
2031         {0x380d, 0x40},
2032         {0x380e, 0x03},
2033         {0x380f, 0x9e},
2034         {0x3810, 0x00},
2035         {0x3811, 0x02},
2036         {0x3812, 0x00},
2037         {0x3813, 0x02},
2038         {0x3814, 0x11},
2039         {0x3815, 0x11},
2040         {0x3820, 0x00},
2041         {0x3821, 0x9e},
2042         {0x3823, 0x00},
2043         {0x3824, 0x00},
2044         {0x3825, 0x00},
2045         {0x3826, 0x00},
2046         {0x3827, 0x00},
2047         {0x382a, 0x04},
2048         {0x3a04, 0x09},
2049         {0x3a05, 0xa9},
2050         {0x3a06, 0x00},
2051         {0x3a07, 0xfe},
2052         {0x3b00, 0x00},
2053         {0x3b02, 0x00},
2054         {0x3b03, 0x00},
2055         {0x3b04, 0x00},
2056         {0x3b05, 0x00},
2057         {0x3e07, 0x20},
2058         {0x4000, 0x08},
2059         {0x4001, 0x04},
2060         {0x4002, 0x45},
2061         {0x4004, 0x08},
2062         {0x4005, 0x18},
2063         {0x4006, 0x20},
2064         {0x4008, 0x24},
2065         {0x4009, 0x10},
2066         {0x400c, 0x00},
2067         {0x400d, 0x00},
2068         {0x4058, 0x00},
2069         {0x404e, 0x37},
2070         {0x404f, 0x8f},
2071         {0x4058, 0x00},
2072         {0x4101, 0xb2},
2073         {0x4303, 0x00},
2074         {0x4304, 0x08},
2075         {0x4307, 0x30},
2076         {0x4311, 0x04},
2077         {0x4315, 0x01},
2078         {0x4511, 0x05},
2079         {0x4512, 0x01},
2080         {0x4800, 0x20}, /* dis-continuous */
2081         {0x4806, 0x00},
2082         {0x4816, 0x52},
2083         {0x481f, 0x30},
2084         {0x4826, 0x2c},
2085         {0x4831, 0x64},
2086         {0x4d00, 0x04},
2087         {0x4d01, 0x71},
2088         {0x4d02, 0xfd},
2089         {0x4d03, 0xf5},
2090         {0x4d04, 0x0c},
2091         {0x4d05, 0xcc},
2092         {0x4837, 0x0a},
2093         {0x5000, 0x06},
2094         {0x5001, 0x01},
2095         {0x5002, 0x00},
2096         {0x5003, 0x20},
2097         {0x5046, 0x0a},
2098         {0x5013, 0x00},
2099         {0x5046, 0x0a},
2100         {0x5780, 0x1c},
2101         {0x5786, 0x20},
2102         {0x5787, 0x10},
2103         {0x5788, 0x18},
2104         {0x578a, 0x04},
2105         {0x578b, 0x02},
2106         {0x578c, 0x02},
2107         {0x578e, 0x06},
2108         {0x578f, 0x02},
2109         {0x5790, 0x02},
2110         {0x5791, 0xff},
2111         {0x5842, 0x01},
2112         {0x5843, 0x2b},
2113         {0x5844, 0x01},
2114         {0x5845, 0x92},
2115         {0x5846, 0x01},
2116         {0x5847, 0x8f},
2117         {0x5848, 0x01},
2118         {0x5849, 0x0c},
2119         {0x5e00, 0x00},
2120         {0x5e10, 0x0c},
2121         {OV5693_TABLE_END, 0x0000}
2122 };
2123
2124 enum {
2125         OV5693_MODE_2592x1944 = 0,
2126         OV5693_MODE_1920x1080,
2127         OV5693_MODE_1296x972,
2128         OV5693_MODE_1280x720_120FPS,
2129         OV5693_MODE_2592x1944_HDR,
2130         OV5693_MODE_1920x1080_HDR,
2131         OV5693_MODE_1296x972_HDR,
2132         OV5693_MODE_1280x720_HDR_60FPS,
2133 };
2134
2135 static const struct ov5693_reg *mode_table[] = {
2136         [OV5693_MODE_2592x1944]         = ov5693_2592x1944_i2c,
2137         [OV5693_MODE_1920x1080]         = ov5693_1920x1080_i2c,
2138         [OV5693_MODE_1296x972]          = ov5693_1296x972_i2c,
2139         [OV5693_MODE_1280x720_120FPS]   = ov5693_1280x720_120fps_i2c,
2140         [OV5693_MODE_2592x1944_HDR]     = ov5693_2592x1944_HDR_24fps_i2c,
2141         [OV5693_MODE_1920x1080_HDR]     = ov5693_1920x1080_HDR_30fps_i2c,
2142         [OV5693_MODE_1296x972_HDR]      = ov5693_1296x972_HDR_30fps_i2c,
2143         [OV5693_MODE_1280x720_HDR_60FPS] = ov5693_1280x720_HDR_60fps_i2c,
2144 };
2145
2146 static int ov5693_i2c_wr_table(struct ov5693_info *info,
2147                                 const struct ov5693_reg table[])
2148 {
2149         int err;
2150         int buf_count = 0;
2151         const struct ov5693_reg *next, *n_next;
2152         u16 i2c_reg = 0;
2153         u8 i2c_buf[OV5693_SIZEOF_I2C_BUF];
2154
2155         u8 *b_ptr = i2c_buf;
2156
2157         for (next = table; next->addr != OV5693_TABLE_END; next++) {
2158                 if (next->addr == OV5693_TABLE_WAIT_MS) {
2159                         msleep(next->val);
2160                         continue;
2161                 } else if (next->addr == OV5693_TABLE_RESET) {
2162                         err = regmap_write(info->regmap, 0x0100, 0x00);
2163                         if (err)
2164                                 return err;
2165                         continue;
2166                 }
2167
2168                 if (buf_count == 0) {
2169                         b_ptr = i2c_buf;
2170                         i2c_reg = next->addr;
2171                 }
2172
2173                 *b_ptr++ = next->val;
2174                 buf_count++;
2175                 n_next = next + 1;
2176                 if (n_next->addr == next->addr + 1 &&
2177                         n_next->addr != OV5693_TABLE_WAIT_MS &&
2178                         buf_count < OV5693_SIZEOF_I2C_BUF &&
2179                         n_next->addr != OV5693_TABLE_RESET &&
2180                         n_next->addr != OV5693_TABLE_END)
2181                         continue;
2182
2183                 err = regmap_bulk_write(info->regmap, i2c_reg,
2184                                         i2c_buf, buf_count);
2185                 if (err)
2186                         return err;
2187
2188                 buf_count = 0;
2189         }
2190
2191         return 0;
2192 }
2193
2194
2195 static inline int ov5693_frame_length_reg(struct ov5693_reg *regs,
2196                                         u32 frame_length)
2197 {
2198         regs->addr = 0x380E;
2199         regs->val = (frame_length >> 8) & 0xff;
2200         (regs + 1)->addr = 0x380F;
2201         (regs + 1)->val = (frame_length) & 0xff;
2202
2203         return 2;
2204 }
2205
2206 static inline int ov5693_coarse_time_reg(struct ov5693_reg *regs,
2207                                         u32 coarse_time, u32 coarse_time_short)
2208 {
2209         int ret = 0;
2210
2211         regs->addr = 0x3500;
2212         regs->val = (coarse_time >> 12) & 0xff;
2213         (regs + 1)->addr = 0x3501;
2214         (regs + 1)->val = (coarse_time >> 4) & 0xff;
2215         (regs + 2)->addr = 0x3502;
2216         (regs + 2)->val = (coarse_time & 0xf) << 4;
2217
2218         ret += 3;
2219
2220         if (coarse_time_short != OV5693_INVALID_COARSE_TIME) {
2221                 (regs + 3)->addr = 0x3506;
2222                 (regs + 3)->val = (coarse_time_short >> 12) & 0xff;
2223                 (regs + 4)->addr = 0x3507;
2224                 (regs + 4)->val = (coarse_time_short >> 4) & 0xff;
2225                 (regs + 5)->addr = 0x3508;
2226                 (regs + 5)->val = (coarse_time_short & 0xf) << 4;
2227
2228                 ret += 3;
2229         }
2230
2231         return ret;
2232 }
2233
2234 #define OV5693_ENTER_GROUP_HOLD(group_hold) \
2235         do {    \
2236                 if (group_hold) {   \
2237                         reg_list[offset].addr = 0x3208; \
2238                         reg_list[offset].val = 0x01;\
2239                         offset++;  \
2240                 }   \
2241         } while (0)
2242
2243 #define OV5693_LEAVE_GROUP_HOLD(group_hold) \
2244         do {    \
2245                 if (group_hold) {   \
2246                         reg_list[offset].addr = 0x3208; \
2247                         reg_list[offset].val = 0x11;\
2248                         offset++;  \
2249                         reg_list[offset].addr = 0x3208; \
2250                         reg_list[offset].val = 0x61;\
2251                         offset++;  \
2252                 } \
2253         } while (0)
2254
2255 static int ov5693_set_frame_length(struct ov5693_info *info,
2256                                    u32 frame_length, bool group_hold)
2257 {
2258         struct ov5693_reg reg_list[9];
2259         int err = 0;
2260         int offset = 0;
2261
2262         OV5693_ENTER_GROUP_HOLD(group_hold);
2263         offset += ov5693_frame_length_reg(reg_list + offset, frame_length);
2264         OV5693_LEAVE_GROUP_HOLD(group_hold);
2265
2266         reg_list[offset].addr = OV5693_TABLE_END;
2267         offset++;
2268
2269         err = ov5693_i2c_wr_table(info, reg_list);
2270
2271         return err;
2272 }
2273
2274 static int ov5693_set_coarse_time(struct ov5693_info *info,
2275                                   u32 coarse_time, u32 coarse_time_short,
2276                                   bool group_hold)
2277 {
2278         struct ov5693_reg reg_list[16];
2279         int err = 0;
2280         int offset = 0;
2281
2282         OV5693_ENTER_GROUP_HOLD(group_hold);
2283         offset += ov5693_coarse_time_reg(reg_list + offset,
2284                                                 coarse_time,
2285                                                 coarse_time_short);
2286         OV5693_LEAVE_GROUP_HOLD(group_hold);
2287
2288         reg_list[offset].addr = OV5693_TABLE_END;
2289         offset++;
2290
2291         err = ov5693_i2c_wr_table(info, reg_list);
2292
2293         return err;
2294 }
2295
2296 static inline int ov5693_gain_reg(struct ov5693_reg *regs, u32 gain)
2297 {
2298         (regs)->addr = 0x350A;
2299         (regs)->val = gain >> 8;
2300
2301         (regs + 1)->addr = 0x350B;
2302         (regs + 1)->val = gain & 0x00FF;
2303
2304         return 2;
2305 }
2306
2307 static int ov5693_bin_wr(struct ov5693_info *info, u8 enable)
2308 {
2309         int err = 0;
2310
2311         if (enable == info->bin_en)
2312                 return 0;
2313
2314         if (!err)
2315                 info->bin_en = enable;
2316         dev_dbg(&info->i2c_client->dev, "%s bin_en=%x err=%d\n",
2317                 __func__, info->bin_en, err);
2318         return err;
2319 }
2320
2321 static int ov5693_exposure_wr(struct ov5693_info *info,
2322                                 struct ov5693_mode *mode)
2323 {
2324         struct ov5693_reg reg_list[16];
2325         int err = 0;
2326         int offset = 0;
2327         bool group_hold = true; /* To use GROUP_HOLD macros */
2328
2329         OV5693_ENTER_GROUP_HOLD(group_hold);
2330         offset += ov5693_coarse_time_reg(reg_list + offset,
2331                                                 mode->coarse_time,
2332                                                 mode->coarse_time_short);
2333         offset += ov5693_gain_reg(reg_list + offset, mode->gain);
2334         OV5693_LEAVE_GROUP_HOLD(group_hold);
2335
2336         reg_list[offset].addr = OV5693_TABLE_END;
2337         err = ov5693_i2c_wr_table(info, reg_list);
2338
2339         return err;
2340 }
2341
2342
2343 static int ov5693_set_gain(struct ov5693_info *info, u32 gain, bool group_hold)
2344 {
2345         struct ov5693_reg reg_list[9];
2346         int err = 0;
2347         int offset = 0;
2348
2349         OV5693_ENTER_GROUP_HOLD(group_hold);
2350         offset += ov5693_gain_reg(reg_list + offset, gain);
2351         OV5693_LEAVE_GROUP_HOLD(group_hold);
2352
2353         reg_list[offset].addr = OV5693_TABLE_END;
2354         offset++;
2355
2356         err = ov5693_i2c_wr_table(info, reg_list);
2357
2358         return err;
2359 }
2360
2361 static int ov5693_awb_wr(struct ov5693_info *info)
2362 {
2363         struct ov5693_reg reg_list[10];
2364         int rg, bg, rg_typical, bg_typical;
2365         int R_gain, G_gain, B_gain, G_gain_R, G_gain_B;
2366         int offset;
2367         int err;
2368
2369         if (info->cal.loaded == 0)
2370                 return 0;
2371
2372         /* update AWB calibration data to register lists */
2373         rg = info->cal.rg_ratio;
2374         bg = info->cal.bg_ratio;
2375         rg_typical = info->cal.rg_ratio_typical;
2376         bg_typical = info->cal.bg_ratio_typical;
2377
2378         if ((rg == 0) || (bg == 0) || (rg_typical == 0) || (bg_typical == 0))
2379                 return 0;
2380
2381         if (bg < bg_typical) {
2382                 if (rg < rg_typical) {
2383                         G_gain = 0x400;
2384                         B_gain = 0x400 * bg_typical / bg;
2385                         R_gain = 0x400 * rg_typical / rg;
2386                 } else {
2387                         R_gain = 0x400;
2388                         G_gain = 0x400 * rg / rg_typical;
2389                         B_gain = G_gain * bg_typical / bg;
2390                 }
2391         } else {
2392                 if (rg < rg_typical) {
2393                         B_gain = 0x400;
2394                         G_gain = 0x400 * bg / bg_typical;
2395                         R_gain = G_gain * rg_typical / rg;
2396                 } else {
2397                         G_gain_B = 0x400 * bg / bg_typical;
2398                         G_gain_R = 0x400 * rg / rg_typical;
2399                         if (G_gain_B > G_gain_R) {
2400                                 B_gain = 0x400;
2401                                 G_gain = G_gain_B;
2402                                 R_gain = G_gain * rg_typical / rg;
2403                         } else {
2404                                 R_gain = 0x400;
2405                                 G_gain = G_gain_R;
2406                                 B_gain = G_gain * bg_typical / bg;
2407                         }
2408                 }
2409         }
2410
2411         offset = 0;
2412         if (R_gain > 0x400) {
2413                 reg_list[offset].addr = 0x3400;
2414                 reg_list[offset].val  = R_gain >> 8;
2415                 offset++;
2416                 reg_list[offset].addr = 0x3401;
2417                 reg_list[offset].val  = R_gain & 0x00ff;
2418                 offset++;
2419         }
2420         if (G_gain > 0x400) {
2421                 reg_list[offset].addr = 0x3402;
2422                 reg_list[offset].val  = G_gain >> 8;
2423                 offset++;
2424                 reg_list[offset].addr = 0x3403;
2425                 reg_list[offset].val  = G_gain & 0x00ff;
2426                 offset++;
2427         }
2428         if (B_gain > 0x400) {
2429                 reg_list[offset].addr = 0x3404;
2430                 reg_list[offset].val  = B_gain >> 8;
2431                 offset++;
2432                 reg_list[offset].addr = 0x3405;
2433                 reg_list[offset].val  = B_gain & 0x00ff;
2434                 offset++;
2435         }
2436         reg_list[offset].addr = OV5693_TABLE_END;
2437         offset++;
2438
2439         err = ov5693_i2c_wr_table(info, reg_list);
2440
2441         return err;
2442 }
2443
2444 static int ov5693_lsc_wr(struct ov5693_info *info)
2445 {
2446         struct ov5693_reg reg_list[64];
2447         int offset;
2448         int err;
2449         int i;
2450
2451         if (info->cal.loaded == 0)
2452                 return 0;
2453
2454         offset = 0;
2455         reg_list[offset].addr = 0x5000;
2456         reg_list[offset].val  = 0x86;
2457         offset++;
2458         for (i = 0; i < 62; i++) {
2459                 reg_list[offset].addr = 0x5800 + i;
2460                 reg_list[offset].val  = info->cal.lenc[i];
2461                 offset++;
2462         }
2463         reg_list[offset].addr = OV5693_TABLE_END;
2464         offset++;
2465
2466         err = ov5693_i2c_wr_table(info, reg_list);
2467
2468         return err;
2469 }
2470
2471 static int ov5693_set_group_hold(struct ov5693_info *info,
2472                                 struct ov5693_ae *ae)
2473 {
2474         int err = 0;
2475         struct ov5693_reg reg_list[16];
2476         int offset = 0;
2477         bool group_hold = true; /* To use GROUP_HOLD macros */
2478
2479         OV5693_ENTER_GROUP_HOLD(group_hold);
2480         if (ae->gain_enable)
2481                 offset += ov5693_gain_reg(reg_list + offset,
2482                                           ae->gain);
2483         if (ae->frame_length_enable)
2484                 offset += ov5693_frame_length_reg(reg_list + offset,
2485                                                   ae->frame_length);
2486         if (ae->coarse_time_enable)
2487                 offset += ov5693_coarse_time_reg(reg_list + offset,
2488                         ae->coarse_time, ae->coarse_time_short);
2489         OV5693_LEAVE_GROUP_HOLD(group_hold);
2490
2491         reg_list[offset].addr = OV5693_TABLE_END;
2492         err |= ov5693_i2c_wr_table(info, reg_list);
2493
2494         return err;
2495 }
2496
2497 static int ov5693_gpio_rd(struct ov5693_info *info,
2498                         enum ov5693_gpio_type type)
2499 {
2500         int val = -EINVAL;
2501
2502         if (info->gpio[type].gpio) {
2503                 val = gpio_get_value_cansleep(info->gpio[type].gpio);
2504                 dev_dbg(&info->i2c_client->dev, "%s %u %d\n", __func__,
2505                        info->gpio[type].gpio, val);
2506                 if (!info->gpio[type].active_high)
2507                         val = !val;
2508                 val &= 1;
2509         }
2510         return val; /* return read value or error */
2511 }
2512
2513 static int ov5693_gpio_wr(struct ov5693_info *info,
2514                         enum ov5693_gpio_type type,
2515                         int val) /* val: 0=deassert, 1=assert */
2516 {
2517         int err = -EINVAL;
2518
2519         if (info->gpio[type].gpio) {
2520                 if (!info->gpio[type].active_high)
2521                         val = !val;
2522                 val &= 1;
2523                 err = val;
2524                 gpio_set_value_cansleep(info->gpio[type].gpio, val);
2525                 dev_dbg(&info->i2c_client->dev, "%s %u %d\n", __func__,
2526                        info->gpio[type].gpio, val);
2527         }
2528         return err; /* return value written or error */
2529 }
2530
2531 static void ov5693_gpio_pwrdn(struct ov5693_info *info, int val)
2532 {
2533         int prev_val;
2534
2535         prev_val = ov5693_gpio_rd(info, OV5693_GPIO_TYPE_PWRDN);
2536         if ((prev_val < 0) || (val == prev_val))
2537                 return;
2538
2539         ov5693_gpio_wr(info, OV5693_GPIO_TYPE_PWRDN, val);
2540         if (!val && prev_val)
2541                 /* if transition from assert to deassert then delay for I2C */
2542                 msleep(50);
2543 }
2544
2545 static void ov5693_gpio_exit(struct ov5693_info *info)
2546 {
2547         unsigned int i;
2548
2549         for (i = 0; i < ARRAY_SIZE(ov5693_gpio); i++) {
2550                 if (info->gpio[i].gpio && info->gpio[i].own)
2551                         gpio_free(info->gpio[i].gpio);
2552         }
2553 }
2554
2555 static void ov5693_gpio_init(struct ov5693_info *info)
2556 {
2557         char label[32];
2558         unsigned long flags;
2559         unsigned type;
2560         unsigned i;
2561         unsigned j;
2562         int err;
2563
2564         if (!info->pdata->gpio_count || !info->pdata->gpio)
2565                 return;
2566
2567         for (i = 0; i < ARRAY_SIZE(ov5693_gpio); i++) {
2568                 type = ov5693_gpio[i].gpio_type;
2569                 for (j = 0; j < info->pdata->gpio_count; j++) {
2570                         if (type == info->pdata->gpio[j].gpio_type)
2571                                 break;
2572                 }
2573                 if (j == info->pdata->gpio_count)
2574                         continue;
2575
2576                 info->gpio[type].gpio = info->pdata->gpio[j].gpio;
2577                 if (ov5693_gpio[i].use_flags) {
2578                         flags = ov5693_gpio[i].flags;
2579                         info->gpio[type].active_high =
2580                                                 ov5693_gpio[i].active_high;
2581                 } else {
2582                         info->gpio[type].active_high =
2583                                         info->pdata->gpio[j].active_high;
2584                         if (info->gpio[type].active_high)
2585                                 flags = GPIOF_OUT_INIT_LOW;
2586                         else
2587                                 flags = GPIOF_OUT_INIT_HIGH;
2588                 }
2589                 if (!info->pdata->gpio[j].init_en)
2590                         continue;
2591
2592                 snprintf(label, sizeof(label), "ov5693_%u_%s",
2593                          info->pdata->num, ov5693_gpio[i].label);
2594                 err = gpio_request_one(info->gpio[type].gpio, flags, label);
2595                 if (err) {
2596                         dev_err(&info->i2c_client->dev,
2597                                 "%s ERR %s %u\n", __func__, label,
2598                                 info->gpio[type].gpio);
2599                 } else {
2600                         info->gpio[type].own = true;
2601                         dev_dbg(&info->i2c_client->dev,
2602                                 "%s %s %u\n", __func__, label,
2603                                 info->gpio[type].gpio);
2604                 }
2605         }
2606 }
2607
2608 static void ov5693_mclk_disable(struct ov5693_info *info)
2609 {
2610         dev_dbg(&info->i2c_client->dev, "%s: disable MCLK\n", __func__);
2611         clk_disable_unprepare(info->mclk);
2612 }
2613
2614 static int ov5693_mclk_enable(struct ov5693_info *info)
2615 {
2616         int err;
2617         unsigned long mclk_init_rate = 24000000;
2618
2619         dev_dbg(&info->i2c_client->dev, "%s: enable MCLK with %lu Hz\n",
2620                 __func__, mclk_init_rate);
2621
2622         err = clk_set_rate(info->mclk, mclk_init_rate);
2623         if (!err)
2624                 err = clk_prepare_enable(info->mclk);
2625
2626         return err;
2627 }
2628
2629 static int ov5693_power_off(struct ov5693_info *info)
2630 {
2631         struct ov5693_power_rail *pw = &info->regulators;
2632         int err;
2633
2634         if (false == info->power_on)
2635                 return 0;
2636
2637         if (info->pdata && info->pdata->power_off) {
2638                 err = info->pdata->power_off(pw);
2639                 if (0 > err)
2640                         return err;
2641                 info->power_on = false;
2642                 ov5693_mclk_disable(info);
2643                 sysedp_set_state(info->sysedpc, 0);
2644         } else {
2645                 dev_err(&info->i2c_client->dev,
2646                         "%s ERR: has no power_off function\n", __func__);
2647                 err = -EINVAL;
2648         }
2649         return err;
2650 }
2651
2652 static int ov5693_power_on(struct ov5693_info *info, bool standby)
2653 {
2654         struct ov5693_power_rail *pw = &info->regulators;
2655         int err;
2656
2657         if (true == info->power_on)
2658                 return 0;
2659
2660         err = ov5693_mclk_enable(info);
2661         if (err)
2662                 return err;
2663
2664         if (info->pdata && info->pdata->power_on) {
2665                 err = info->pdata->power_on(pw);
2666                 if (err >= 0) {
2667                         info->power_on = true;
2668                         info->pwr_dev = NVC_PWR_ON;
2669                 }
2670         } else {
2671                 dev_err(&info->i2c_client->dev,
2672                         "%s ERR: has no power_on function\n", __func__);
2673                 err = -EINVAL;
2674         }
2675
2676         if (err < 0)
2677                 ov5693_mclk_disable(info);
2678
2679         return err;
2680 }
2681
2682 static int ov5693_pm_wr(struct ov5693_info *info, int pwr)
2683 {
2684         int err = 0;
2685
2686         if ((info->pdata->cfg & (NVC_CFG_OFF2STDBY | NVC_CFG_BOOT_INIT)) &&
2687                         (pwr == NVC_PWR_OFF ||
2688                          pwr == NVC_PWR_STDBY_OFF))
2689                 pwr = NVC_PWR_STDBY;
2690         if (pwr == info->pwr_dev)
2691                 return 0;
2692
2693         switch (pwr) {
2694         case NVC_PWR_OFF_FORCE:
2695         case NVC_PWR_OFF:
2696         case NVC_PWR_STDBY_OFF:
2697                 err = ov5693_power_off(info);
2698                 info->mode_valid = false;
2699                 info->bin_en = 0;
2700                 break;
2701
2702         case NVC_PWR_STDBY:
2703                 err = ov5693_power_on(info, true);
2704                 break;
2705
2706         case NVC_PWR_COMM:
2707         case NVC_PWR_ON:
2708                 err = ov5693_power_on(info, false);
2709                 break;
2710
2711         default:
2712                 err = -EINVAL;
2713                 break;
2714         }
2715
2716         if (err < 0) {
2717                 dev_err(&info->i2c_client->dev, "%s err %d\n", __func__, err);
2718                 pwr = NVC_PWR_ERR;
2719         }
2720         info->pwr_dev = pwr;
2721         dev_dbg(&info->i2c_client->dev, "%s pwr_dev=%d\n",
2722                 __func__, info->pwr_dev);
2723         if (err > 0)
2724                 return 0;
2725
2726         return err;
2727 }
2728
2729 static int ov5693_pm_dev_wr(struct ov5693_info *info, int pwr)
2730 {
2731         if (info->mode_enable)
2732                 pwr = NVC_PWR_ON;
2733         if (pwr < info->pwr_api)
2734                 pwr = info->pwr_api;
2735         return ov5693_pm_wr(info, pwr);
2736 }
2737
2738 static void ov5693_pm_exit(struct ov5693_info *info)
2739 {
2740         ov5693_pm_wr(info, NVC_PWR_OFF_FORCE);
2741
2742         ov5693_gpio_exit(info);
2743 }
2744
2745 static void ov5693_regulator_get(struct ov5693_info *info,
2746                                  struct regulator **vreg,
2747                                  const char vreg_name[])
2748 {
2749         struct regulator *reg = NULL;
2750         int err = 0;
2751
2752         reg = devm_regulator_get(&info->i2c_client->dev, vreg_name);
2753         if (IS_ERR(reg)) {
2754                 dev_err(&info->i2c_client->dev, "%s %s ERR: %d\n",
2755                         __func__, vreg_name, (int)reg);
2756                 err = PTR_ERR(reg);
2757         } else {
2758                 dev_dbg(&info->i2c_client->dev, "%s: %s\n",
2759                         __func__, vreg_name);
2760         }
2761
2762         *vreg = reg;
2763 }
2764
2765 static void ov5693_pm_init(struct ov5693_info *info)
2766 {
2767         struct ov5693_power_rail *pw = &info->regulators;
2768
2769         ov5693_gpio_init(info);
2770
2771         ov5693_regulator_get(info, &pw->avdd, info->pdata->regulators.avdd);
2772
2773         ov5693_regulator_get(info, &pw->dvdd, info->pdata->regulators.dvdd);
2774
2775         ov5693_regulator_get(info, &pw->dovdd, info->pdata->regulators.dovdd);
2776
2777         info->power_on = false;
2778 }
2779
2780 static int ov5693_mode_able(struct ov5693_info *info, bool mode_enable)
2781 {
2782         u8 val;
2783         int err;
2784
2785         if (mode_enable)
2786                 val = 0x01;
2787         else
2788                 val = 0x00;
2789         err = regmap_write(info->regmap, 0x0100, val);
2790         if (!err) {
2791                 info->mode_enable = mode_enable;
2792                 dev_dbg(&info->i2c_client->dev, "%s streaming=%x\n",
2793                         __func__, info->mode_enable);
2794                 if (!mode_enable)
2795                         ov5693_pm_dev_wr(info, NVC_PWR_STDBY);
2796         }
2797         return err;
2798 }
2799
2800 static int ov5693_mode_wr_full(struct ov5693_info *info, u32 mode_index)
2801 {
2802         int err;
2803
2804         ov5693_pm_dev_wr(info, NVC_PWR_ON);
2805         ov5693_bin_wr(info, 0);
2806         err = ov5693_i2c_wr_table(info, mode_table[mode_index]);
2807         if (!err) {
2808                 dev_dbg(&info->i2c_client->dev,
2809                         "init done(mode=%d)!!!\n", mode_index);
2810                 info->mode_index = mode_index;
2811                 info->mode_valid = true;
2812         } else {
2813                 dev_dbg(&info->i2c_client->dev,
2814                         "init error(mode=%d)!!!\n", mode_index);
2815                 info->mode_valid = false;
2816         }
2817         return err;
2818 }
2819
2820
2821 static int ov5693_set_mode(struct ov5693_info *info,
2822                 struct ov5693_mode *mode)
2823 {
2824         u32 mode_index = 0;
2825         int err = 0;
2826
2827         if (!mode->res_x && !mode->res_y) {
2828                 if (mode->frame_length || mode->coarse_time || mode->gain) {
2829                         /* write exposure only */
2830                         err = ov5693_exposure_wr(info, mode);
2831                         return err;
2832                 } else {
2833                         /* turn off streaming */
2834                         err = ov5693_mode_able(info, false);
2835                         return err;
2836                 }
2837         }
2838
2839         if (mode->hdr_en == true) {
2840                 if (mode->res_x == 2592 && mode->res_y == 1944)
2841                         mode_index = OV5693_MODE_2592x1944_HDR;
2842                 else if (mode->res_x == 1296 && mode->res_y == 972)
2843                         mode_index = OV5693_MODE_1296x972_HDR;
2844                 else if (mode->res_x == 1920 && mode->res_y == 1080)
2845                         mode_index = OV5693_MODE_1920x1080_HDR;
2846                 else if (mode->res_x == 1280 && mode->res_y == 720)
2847                         mode_index = OV5693_MODE_1280x720_HDR_60FPS;
2848         } else {
2849                 if (mode->res_x == 2592 && mode->res_y == 1944)
2850                         mode_index = OV5693_MODE_2592x1944;
2851                 else if (mode->res_x == 1296 && mode->res_y == 972)
2852                         mode_index = OV5693_MODE_1296x972;
2853                 else if (mode->res_x == 1920 && mode->res_y == 1080)
2854                         mode_index = OV5693_MODE_1920x1080;
2855                 else if (mode->res_x == 1280 && mode->res_y == 720)
2856                         mode_index = OV5693_MODE_1280x720_120FPS;
2857         }
2858
2859         /* request highest edp state */
2860         sysedp_set_state(info->sysedpc, 1);
2861
2862         if (!info->mode_valid || (info->mode_index != mode_index))
2863                 err = ov5693_mode_wr_full(info, mode_index);
2864         else
2865                 dev_dbg(&info->i2c_client->dev, "%s short mode\n", __func__);
2866         dev_dbg(&info->i2c_client->dev, "%s: mode #: %d\n",
2867                 __func__, mode_index);
2868         dev_dbg(&info->i2c_client->dev, "%s: AE: %d, %d, %d\n",
2869                 __func__, mode->frame_length,
2870                 mode->coarse_time, mode->gain);
2871         err |= ov5693_exposure_wr(info, mode);
2872         if (err < 0) {
2873                 info->mode_valid = false;
2874                 dev_err(&info->i2c_client->dev,
2875                         "%s set_mode error\n", __func__);
2876                 goto ov5693_mode_wr_err;
2877         }
2878         err = ov5693_awb_wr(info);
2879         if (err < 0) {
2880                 info->mode_valid = false;
2881                 dev_err(&info->i2c_client->dev,
2882                         "%s:%d awb cal write error\n", __func__, __LINE__);
2883                 goto ov5693_mode_wr_err;
2884         }
2885         err = ov5693_lsc_wr(info);
2886         if (err < 0) {
2887                 info->mode_valid = false;
2888                 dev_err(&info->i2c_client->dev,
2889                         "%s:%d lsc cal write error\n", __func__, __LINE__);
2890                 goto ov5693_mode_wr_err;
2891         }
2892         err = regmap_write(info->regmap, 0x0100, 0x01);
2893         if (err) {
2894                 info->mode_valid = false;
2895                 dev_err(&info->i2c_client->dev,
2896                         "%s:%d stream on failed\n", __func__, __LINE__);
2897                 goto ov5693_mode_wr_err;
2898         }
2899
2900         return 0;
2901
2902 ov5693_mode_wr_err:
2903         if (!info->mode_enable)
2904                 ov5693_pm_dev_wr(info, NVC_PWR_OFF);
2905         return err;
2906 }
2907
2908 static int ov5693_get_fuse_id(struct ov5693_info *info)
2909 {
2910         /* fuse stored at ov5693 bank 0 */
2911         int err;
2912         /* delay to ensure i2c is ready after poweron */
2913         usleep_range(150, 200);
2914         err = regmap_write(info->regmap, 0x0100, 0x01);
2915         if (err != 0) {
2916                 dev_err(&info->i2c_client->dev,
2917                         "%s ERR %d: cannot write stream mode\n", __func__,
2918                         err);
2919                 return err;
2920         }
2921         usleep_range(10000, 11000);
2922
2923         err = regmap_write(info->regmap, 0x3D84, 0xC0);
2924         if (err != 0) {
2925                 dev_err(&info->i2c_client->dev,
2926                         "%s ERR %d: cannot write bank index 0\n", __func__,
2927                         err);
2928                 return err;
2929         }
2930         usleep_range(10000, 11000);
2931
2932         err = regmap_write(info->regmap, 0x3D81, 0x01);
2933         if (err != 0) {
2934                 dev_err(&info->i2c_client->dev,
2935                         "%s ERR %d: cannot load OTP data\n", __func__, err);
2936                 return err;
2937         }
2938         usleep_range(10000, 11000);
2939
2940         err = regmap_bulk_read(info->regmap, 0x3D00,
2941                 info->fuseid.data, OV5693_FUSE_ID_SIZE);
2942         if (err != 0) {
2943                 dev_err(&info->i2c_client->dev,
2944                         "%s ERR %d: cannot read OTP buffer\n", __func__,
2945                         err);
2946                 return err;
2947         }
2948
2949         info->fuseid.size = OV5693_FUSE_ID_SIZE;
2950
2951         return 0;
2952 }
2953
2954 static int ov5693_read_otp_bank(struct ov5693_info *info,
2955                                 struct ov5693_otp_bank *bank)
2956 {
2957         int err;
2958
2959         err = regmap_write(info->regmap, 0x0100, 0x01);
2960         if (err != 0) {
2961                 dev_err(&info->i2c_client->dev,
2962                         "%s ERR %d: cannot write stream mode\n", __func__,
2963                         err);
2964                 return err;
2965         }
2966         err = regmap_write(info->regmap, 0x3d84, 0xc0 | bank->id);
2967         if (err != 0) {
2968                 dev_err(&info->i2c_client->dev,
2969                         "%s ERR %d: cannot write bank index %d\n", __func__,
2970                         err, bank->id);
2971                 return err;
2972         }
2973         err = regmap_write(info->regmap, 0x3d81, 0x01);
2974         if (err != 0) {
2975                 dev_err(&info->i2c_client->dev,
2976                         "%s ERR %d: cannot load OTP data\n", __func__, err);
2977                 return err;
2978         }
2979         usleep_range(1000, 11000);
2980         err = regmap_bulk_read(info->regmap, 0x3d00, bank->buf, 16);
2981         if (err != 0) {
2982                 dev_err(&info->i2c_client->dev,
2983                         "%s ERR %d: cannot read OTP buffer\n", __func__,
2984                         err);
2985                 return err;
2986         }
2987
2988         return err;
2989 }
2990
2991 static int
2992 ov5693_eeprom_device_release(struct ov5693_info *info)
2993 {
2994         int i;
2995
2996         for (i = 0; i < OV5693_EEPROM_NUM_BLOCKS; i++) {
2997                 if (info->eeprom[i].i2c_client != NULL) {
2998                         i2c_unregister_device(info->eeprom[i].i2c_client);
2999                         info->eeprom[i].i2c_client = NULL;
3000                 }
3001         }
3002
3003         return 0;
3004 }
3005
3006 static int
3007 ov5693_eeprom_device_init(struct ov5693_info *info)
3008 {
3009         char *dev_name = "eeprom_ov5693";
3010         static struct regmap_config eeprom_regmap_config = {
3011                 .reg_bits = 8,
3012                 .val_bits = 8,
3013         };
3014         int i;
3015         int err;
3016
3017         for (i = 0; i < OV5693_EEPROM_NUM_BLOCKS; i++)  {
3018                 info->eeprom[i].adap = i2c_get_adapter(
3019                                 info->i2c_client->adapter->nr);
3020                 memset(&info->eeprom[i].brd, 0, sizeof(info->eeprom[i].brd));
3021                 strncpy(info->eeprom[i].brd.type, dev_name,
3022                                 sizeof(info->eeprom[i].brd.type));
3023                 info->eeprom[i].brd.addr = OV5693_EEPROM_ADDRESS + i;
3024                 info->eeprom[i].i2c_client = i2c_new_device(
3025                                 info->eeprom[i].adap, &info->eeprom[i].brd);
3026
3027                 info->eeprom[i].regmap = devm_regmap_init_i2c(
3028                         info->eeprom[i].i2c_client, &eeprom_regmap_config);
3029                 if (IS_ERR(info->eeprom[i].regmap)) {
3030                         err = PTR_ERR(info->eeprom[i].regmap);
3031                         ov5693_eeprom_device_release(info);
3032                         return err;
3033                 }
3034         }
3035
3036         return 0;
3037 }
3038
3039 static int
3040 ov5693_read_eeprom(struct ov5693_info *info, u8 reg, u16 length, u8 *buf)
3041 {
3042         return regmap_raw_read(info->eeprom[0].regmap, reg, &buf[reg], length);
3043 }
3044
3045 static int
3046 ov5693_write_eeprom(struct ov5693_info *info, u16 addr, u8 val)
3047 {
3048         return regmap_write(info->eeprom[addr >> 8].regmap, addr & 0xFF, val);
3049 }
3050
3051 static long ov5693_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
3052 {
3053         struct ov5693_info *info = file->private_data;
3054         int err;
3055
3056         switch (_IOC_NR(cmd)) {
3057         case _IOC_NR(OV5693_IOCTL_SET_POWER):
3058         {
3059                 u32 powerlevel = (u32) arg;
3060
3061                 if (!info->pdata)
3062                         break;
3063                 if (powerlevel > NVC_PWR_ON) {
3064                         dev_err(&info->i2c_client->dev,
3065                                 "%s:Invalid power level.\n",
3066                         __func__);
3067                         return -EFAULT;
3068                 }
3069
3070                 err = ov5693_pm_wr(info, powerlevel);
3071                 return err;
3072         }
3073         case _IOC_NR(OV5693_IOCTL_GET_CAPS):
3074                 if (copy_to_user((void __user *)arg,
3075                                  info->pdata->cap,
3076                                  sizeof(struct nvc_imager_cap))) {
3077                         dev_err(&info->i2c_client->dev,
3078                                 "%s copy_to_user err line %d\n",
3079                                 __func__, __LINE__);
3080                         return -EFAULT;
3081                 }
3082                 return 0;
3083         case _IOC_NR(OV5693_IOCTL_SET_MODE):
3084         {
3085                 struct ov5693_mode mode;
3086                 if (copy_from_user(&mode,
3087                         (const void __user *)arg,
3088                         sizeof(struct ov5693_mode))) {
3089                         dev_err(&info->i2c_client->dev,
3090                                 "%s:Failed to get mode from user.\n",
3091                         __func__);
3092                         return -EFAULT;
3093                 }
3094                 return ov5693_set_mode(info, &mode);
3095         }
3096         case _IOC_NR(OV5693_IOCTL_GET_STATUS): {
3097                 u8 status = 0;
3098                 if (copy_to_user((void __user *)arg, &status, sizeof(status))) {
3099                         dev_err(&info->i2c_client->dev,
3100                                 "%s:Failed to copy status to user.\n",
3101                         __func__);
3102                         return -EFAULT;
3103                 }
3104                 return 0;
3105                 }
3106
3107         case _IOC_NR(OV5693_IOCTL_SET_GROUP_HOLD): {
3108                 struct ov5693_ae ae;
3109                 if (copy_from_user(&ae, (const void __user *)arg,
3110                                 sizeof(struct ov5693_ae))) {
3111                         dev_dbg(&info->i2c_client->dev,
3112                                 "%s:fail group hold\n", __func__);
3113                         return -EFAULT;
3114                 }
3115
3116                 return ov5693_set_group_hold(info, &ae);
3117                 }
3118
3119         case _IOC_NR(OV5693_IOCTL_SET_FRAME_LENGTH):
3120                 return ov5693_set_frame_length(info, (u32)arg, true);
3121
3122         case _IOC_NR(OV5693_IOCTL_SET_COARSE_TIME):
3123                 return ov5693_set_coarse_time(info, (u32)arg,
3124                                         OV5693_INVALID_COARSE_TIME, true);
3125
3126         case _IOC_NR(OV5693_IOCTL_SET_HDR_COARSE_TIME):
3127         {
3128                 struct ov5693_hdr *hdrcoarse = (struct ov5693_hdr *)arg;
3129                 int ret = ov5693_set_coarse_time(info,
3130                                 hdrcoarse->coarse_time_long,
3131                                 hdrcoarse->coarse_time_short,
3132                                 true);
3133                 return ret;
3134         }
3135
3136         case _IOC_NR(OV5693_IOCTL_SET_GAIN):
3137                 return ov5693_set_gain(info, (u32)arg, true);
3138
3139         case _IOC_NR(OV5693_IOCTL_GET_FUSEID):
3140         {
3141                 err = ov5693_get_fuse_id(info);
3142
3143                 if (err) {
3144                         dev_err(&info->i2c_client->dev, "%s:Failed to get fuse id info.\n",
3145                         __func__);
3146                         return err;
3147                 }
3148                 if (copy_to_user((void __user *)arg,
3149                                 &info->fuseid,
3150                                 sizeof(struct nvc_fuseid))) {
3151                         dev_dbg(&info->i2c_client->dev, "%s:Fail copy fuse id to user space\n",
3152                                 __func__);
3153                         return -EFAULT;
3154                 }
3155                 return 0;
3156         }
3157
3158         case _IOC_NR(OV5693_IOCTL_READ_OTP_BANK):
3159         {
3160                 struct ov5693_otp_bank bank;
3161                 if (copy_from_user(&bank,
3162                                    (const void __user *)arg,
3163                                    sizeof(bank))) {
3164                         dev_err(&info->i2c_client->dev,
3165                                 "%s %d copy_from_user err\n",
3166                                 __func__, __LINE__);
3167                         return -EINVAL;
3168                 }
3169
3170                 err = ov5693_read_otp_bank(info, &bank);
3171                 if (err != 0)
3172                         return err;
3173
3174                 if (copy_to_user((void __user *)arg,
3175                                  &bank,
3176                                  sizeof(bank))) {
3177                         dev_err(&info->i2c_client->dev,
3178                                 "%s %d copy_to_user err\n",
3179                                 __func__, __LINE__);
3180                         return -EFAULT;
3181                 }
3182                 return 0;
3183         }
3184
3185         case _IOC_NR(OV5693_IOCTL_SET_CAL_DATA):
3186         {
3187                 if (copy_from_user(&info->cal, (const void __user *)arg,
3188                                         sizeof(info->cal))) {
3189                         dev_err(&info->i2c_client->dev,
3190                                 "%s %d copy_from_user err\n",
3191                                 __func__, __LINE__);
3192                         return -EINVAL;
3193                 }
3194                 return 0;
3195         }
3196
3197         case _IOC_NR(OV5693_IOCTL_GET_EEPROM_DATA):
3198                 {
3199                         if (!info->pdata->has_eeprom)
3200                                 return -EFAULT;
3201
3202                         ov5693_read_eeprom(info,
3203                                 0,
3204                                 OV5693_EEPROM_SIZE,
3205                                 info->eeprom_buf);
3206
3207                         if (copy_to_user((void __user *)arg,
3208                                 info->eeprom_buf, OV5693_EEPROM_SIZE)) {
3209                                 dev_err(&info->i2c_client->dev,
3210                                         "%s:Failed to copy status to user\n",
3211                                         __func__);
3212                                 return -EFAULT;
3213                         }
3214                 }
3215                 return 0;
3216
3217         case _IOC_NR(OV5693_IOCTL_SET_EEPROM_DATA):
3218                 {
3219                         int i;
3220
3221                         if (!info->pdata->has_eeprom)
3222                                 return -EFAULT;
3223
3224                         if (copy_from_user(info->eeprom_buf,
3225                                 (const void __user *)arg, OV5693_EEPROM_SIZE)) {
3226                                 dev_err(&info->i2c_client->dev,
3227                                                 "%s:Failed to read from user buffer\n",
3228                                                 __func__);
3229                                 return -EFAULT;
3230                         }
3231                         for (i = 0; i < OV5693_EEPROM_SIZE; i++) {
3232                                 ov5693_write_eeprom(info,
3233                                         i,
3234                                         info->eeprom_buf[i]);
3235                                 msleep(20);
3236                         }
3237                 }
3238                 return 0;
3239
3240         default:
3241                 dev_err(&info->i2c_client->dev, "%s unsupported ioctl: %x\n",
3242                         __func__, cmd);
3243         }
3244         return -EINVAL;
3245 }
3246
3247 static void ov5693_sdata_init(struct ov5693_info *info)
3248 {
3249         memcpy(&info->sdata, &ov5693_dflt_sdata, sizeof(info->sdata));
3250         if (info->pdata->lens_focal_length)
3251                 info->sdata.focal_len = info->pdata->lens_focal_length;
3252         if (info->pdata->lens_max_aperture)
3253                 info->sdata.max_aperture = info->pdata->lens_max_aperture;
3254         if (info->pdata->lens_fnumber)
3255                 info->sdata.fnumber = info->pdata->lens_fnumber;
3256         if (info->pdata->lens_view_angle_h)
3257                 info->sdata.view_angle_h = info->pdata->lens_view_angle_h;
3258         if (info->pdata->lens_view_angle_v)
3259                 info->sdata.view_angle_v = info->pdata->lens_view_angle_v;
3260 }
3261
3262 static int ov5693_open(struct inode *inode, struct file *file)
3263 {
3264         int err;
3265         struct miscdevice *miscdev = file->private_data;
3266         struct ov5693_info *info = dev_get_drvdata(miscdev->parent);
3267
3268         if (atomic_xchg(&info->in_use, 1))
3269                 return -EBUSY;
3270
3271         file->private_data = info;
3272         dev_dbg(&info->i2c_client->dev, "%s\n", __func__);
3273
3274         err = ov5693_power_on(info, false);
3275         return err;
3276 }
3277
3278 static int ov5693_release(struct inode *inode, struct file *file)
3279 {
3280         struct ov5693_info *info = file->private_data;
3281
3282         dev_dbg(&info->i2c_client->dev, "%s\n", __func__);
3283         ov5693_pm_wr(info, NVC_PWR_OFF);
3284         file->private_data = NULL;
3285         WARN_ON(!atomic_xchg(&info->in_use, 0));
3286         return 0;
3287 }
3288
3289 static const struct file_operations ov5693_fileops = {
3290         .owner = THIS_MODULE,
3291         .open = ov5693_open,
3292         .unlocked_ioctl = ov5693_ioctl,
3293 #ifdef CONFIG_COMPAT
3294         .compat_ioctl = ov5693_ioctl,
3295 #endif
3296         .release = ov5693_release,
3297 };
3298
3299 static void ov5693_del(struct ov5693_info *info)
3300 {
3301         ov5693_pm_exit(info);
3302         synchronize_rcu();
3303 }
3304
3305 static int ov5693_remove(struct i2c_client *client)
3306 {
3307         struct ov5693_info *info = i2c_get_clientdata(client);
3308
3309         dev_dbg(&info->i2c_client->dev, "%s\n", __func__);
3310         misc_deregister(&info->miscdev);
3311         sysedp_free_consumer(info->sysedpc);
3312         if (info->pdata->has_eeprom)
3313                 ov5693_eeprom_device_release(info);
3314         ov5693_del(info);
3315         return 0;
3316 }
3317
3318 static struct of_device_id ov5693_of_match[] = {
3319         { .compatible = "nvidia,ov5693", },
3320         { },
3321 };
3322
3323 MODULE_DEVICE_TABLE(of, ov5693_of_match);
3324
3325 static int ov5693_platform_power_on(struct ov5693_power_rail *pw)
3326 {
3327         int err;
3328         struct ov5693_info *info = container_of(pw, struct ov5693_info,
3329                                                 regulators);
3330
3331         if (info->pdata->use_vcm_vdd) {
3332                 err = regulator_enable(info->ext_vcm_vdd);
3333                 if (unlikely(err))
3334                         goto ov5693_vcm_fail;
3335         }
3336
3337         ov5693_gpio_pwrdn(info, 0);
3338         usleep_range(10, 20);
3339
3340         err = regulator_enable(pw->avdd);
3341         if (err)
3342                 goto ov5693_avdd_fail;
3343
3344         err = regulator_enable(pw->dovdd);
3345         if (err)
3346                 goto ov5693_iovdd_fail;
3347
3348         usleep_range(1, 2);
3349         ov5693_gpio_pwrdn(info, 1);
3350
3351         usleep_range(300, 310);
3352
3353         return 0;
3354
3355 ov5693_iovdd_fail:
3356         regulator_disable(pw->avdd);
3357
3358 ov5693_avdd_fail:
3359         if (info->pdata->use_vcm_vdd)
3360                 regulator_disable(info->ext_vcm_vdd);
3361
3362 ov5693_vcm_fail:
3363         pr_err("%s FAILED\n", __func__);
3364         return err;
3365 }
3366
3367 static int ov5693_platform_power_off(struct ov5693_power_rail *pw)
3368 {
3369         struct ov5693_info *info = container_of(pw, struct ov5693_info,
3370                                                 regulators);
3371
3372         usleep_range(21, 25);
3373         ov5693_gpio_pwrdn(info, 0);
3374         usleep_range(1, 2);
3375
3376         regulator_disable(pw->dovdd);
3377         regulator_disable(pw->avdd);
3378         if (info->pdata->use_vcm_vdd)
3379                 regulator_disable(info->ext_vcm_vdd);
3380
3381         return 0;
3382 }
3383
3384 static int ov5693_parse_dt_gpio(struct device_node *np, const char *name,
3385                                 enum ov5693_gpio_type type,
3386                                 struct nvc_gpio_pdata *pdata)
3387 {
3388         enum of_gpio_flags gpio_flags;
3389
3390         if (of_find_property(np, name, NULL)) {
3391                 pdata->gpio = of_get_named_gpio_flags(np, name, 0, &gpio_flags);
3392                 pdata->gpio_type = type;
3393                 pdata->init_en = true;
3394                 pdata->active_high = !(gpio_flags & OF_GPIO_ACTIVE_LOW);
3395                 return 1;
3396         }
3397         return 0;
3398 }
3399
3400 static struct ov5693_platform_data *ov5693_parse_dt(struct i2c_client *client)
3401 {
3402         struct device_node *np = client->dev.of_node;
3403         struct ov5693_platform_data *pdata;
3404         struct nvc_gpio_pdata *gpio_pdata = NULL;
3405
3406         pdata = devm_kzalloc(&client->dev, sizeof(*pdata), GFP_KERNEL);
3407         if (!pdata) {
3408                 dev_err(&client->dev, "Failed to allocate pdata\n");
3409                 return ERR_PTR(-ENOMEM);
3410         }
3411
3412         gpio_pdata = devm_kzalloc(&client->dev,
3413                 sizeof(*gpio_pdata) * ARRAY_SIZE(ov5693_gpio), GFP_KERNEL);
3414         if (!gpio_pdata) {
3415                 dev_err(&client->dev, "cannot allocate gpio data memory\n");
3416                 return ERR_PTR(-ENOMEM);
3417         }
3418
3419         /* init with default platform data values */
3420         memcpy(pdata, &ov5693_dflt_pdata, sizeof(*pdata));
3421
3422         /* extra regulators info */
3423         pdata->use_vcm_vdd = of_property_read_bool(np, "nvidia,use-vcm-vdd");
3424
3425         /* generic info */
3426         of_property_read_u32(np, "nvidia,num", &pdata->num);
3427         of_property_read_string(np, "nvidia,dev-name", &pdata->dev_name);
3428
3429         /* ov5693 gpios */
3430         pdata->gpio_count = 0;
3431         pdata->gpio_count += ov5693_parse_dt_gpio(np,
3432                                 "reset-gpios", OV5693_GPIO_TYPE_PWRDN,
3433                                 &gpio_pdata[pdata->gpio_count]);
3434         pdata->gpio = gpio_pdata;
3435
3436         /* MCLK clock info */
3437         of_property_read_string(np, "nvidia,mclk_name",
3438                                 &pdata->mclk_name);
3439
3440         /* ov5693 power functions */
3441         pdata->power_on = ov5693_platform_power_on;
3442         pdata->power_off = ov5693_platform_power_off;
3443
3444         return pdata;
3445 }
3446
3447 static int ov5693_probe(
3448         struct i2c_client *client,
3449         const struct i2c_device_id *id)
3450 {
3451         struct ov5693_info *info;
3452         unsigned long clock_probe_rate;
3453         int err;
3454         const char *mclk_name;
3455         static struct regmap_config ov5693_regmap_config = {
3456                 .reg_bits = 16,
3457                 .val_bits = 8,
3458         };
3459
3460
3461         dev_dbg(&client->dev, "%s\n", __func__);
3462         info = devm_kzalloc(&client->dev, sizeof(*info), GFP_KERNEL);
3463         if (info == NULL) {
3464                 dev_err(&client->dev, "%s: kzalloc error\n", __func__);
3465                 return -ENOMEM;
3466         }
3467
3468         info->i2c_client = client;
3469         if (client->dev.of_node) {
3470                 info->pdata = ov5693_parse_dt(client);
3471                 if (IS_ERR(info->pdata)) {
3472                         err = PTR_ERR(info->pdata);
3473                         dev_err(&client->dev,
3474                                 "Failed to parse OF node: %d\n", err);
3475                         return err;
3476                 }
3477         } else if (client->dev.platform_data)
3478                 info->pdata = client->dev.platform_data;
3479         else {
3480                 info->pdata = &ov5693_dflt_pdata;
3481                 dev_dbg(&client->dev,
3482                         "%s No platform data. Using defaults.\n",
3483                         __func__);
3484         }
3485         if (info->pdata->use_vcm_vdd) {
3486                 info->ext_vcm_vdd = devm_regulator_get(&info->i2c_client->dev,
3487                                                         "ext_vcm_vdd");
3488                 if (WARN_ON(IS_ERR(info->ext_vcm_vdd))) {
3489                         err = PTR_ERR(info->ext_vcm_vdd);
3490                         dev_err(&client->dev,
3491                                 "ext_vcm_vdd get failed %d\n", err);
3492                         info->ext_vcm_vdd = NULL;
3493                         return err;
3494                 }
3495         }
3496
3497         info->regmap = devm_regmap_init_i2c(client, &ov5693_regmap_config);
3498         if (IS_ERR(info->regmap)) {
3499                 err = PTR_ERR(info->regmap);
3500                 dev_err(&client->dev,
3501                         "Failed to allocate register map: %d\n", err);
3502                 return err;
3503         }
3504
3505         if (info->pdata->has_eeprom) {
3506                 err = ov5693_eeprom_device_init(info);
3507                 if (err) {
3508                         dev_err(&client->dev,
3509                         "Failed to allocate eeprom register map: %d\n", err);
3510                         return err;
3511                 }
3512         }
3513
3514         mclk_name = info->pdata->mclk_name ?
3515                     info->pdata->mclk_name : "default_mclk";
3516         info->mclk = devm_clk_get(&client->dev, mclk_name);
3517         if (IS_ERR(info->mclk)) {
3518                 dev_err(&client->dev, "%s: unable to get clock %s\n",
3519                         __func__, mclk_name);
3520                 return PTR_ERR(info->mclk);
3521         }
3522
3523         i2c_set_clientdata(client, info);
3524         ov5693_pm_init(info);
3525         if (IS_ERR(info->regulators.avdd) || IS_ERR(info->regulators.dovdd))
3526                         return -EFAULT;
3527
3528         ov5693_sdata_init(info);
3529         if (info->pdata->cfg & (NVC_CFG_NODEV | NVC_CFG_BOOT_INIT)) {
3530                 if (info->pdata->probe_clock) {
3531                         clock_probe_rate = 6000;  /* initial_clcok*/
3532                         clock_probe_rate *= 1000;
3533                         info->pdata->probe_clock(clock_probe_rate);
3534                 }
3535                 ov5693_pm_dev_wr(info, NVC_PWR_COMM);
3536                 ov5693_pm_dev_wr(info, NVC_PWR_OFF);
3537                 if (info->pdata->probe_clock)
3538                         info->pdata->probe_clock(0);
3539         }
3540         if (info->pdata->dev_name != NULL)
3541                 strncpy(info->devname, info->pdata->dev_name,
3542                         sizeof(info->devname) - 1);
3543         else
3544                 strncpy(info->devname, "ov5693", sizeof(info->devname) - 1);
3545         if (info->pdata->num)
3546                 snprintf(info->devname, sizeof(info->devname), "%s.%u",
3547                          info->devname, info->pdata->num);
3548
3549         info->miscdev.name = info->devname;
3550         info->miscdev.fops = &ov5693_fileops;
3551         info->miscdev.minor = MISC_DYNAMIC_MINOR;
3552         info->miscdev.parent = &client->dev;
3553         if (misc_register(&info->miscdev)) {
3554                 dev_err(&client->dev, "%s unable to register misc device %s\n",
3555                         __func__, info->devname);
3556                 ov5693_del(info);
3557                 return -ENODEV;
3558         }
3559
3560         info->sysedpc = sysedp_create_consumer("ov5693", info->devname);
3561
3562         dev_dbg(&client->dev, "ov5693 sensor driver loading done\n");
3563         return 0;
3564 }
3565
3566 static const struct i2c_device_id ov5693_id[] = {
3567         { "ov5693", 0 },
3568         { "ov5693.1", 0 },
3569         { },
3570 };
3571
3572 MODULE_DEVICE_TABLE(i2c, ov5693_id);
3573
3574 static struct i2c_driver ov5693_i2c_driver = {
3575         .driver = {
3576                 .name = "ov5693",
3577                 .owner = THIS_MODULE,
3578                 .of_match_table = ov5693_of_match,
3579         },
3580         .id_table = ov5693_id,
3581         .probe = ov5693_probe,
3582         .remove = ov5693_remove,
3583 };
3584
3585 module_i2c_driver(ov5693_i2c_driver);
3586 MODULE_LICENSE("GPL v2");