[media] gspca - sonixj: Add a flag in the driver_info table
[pandora-kernel.git] / drivers / media / video / gspca / sonixj.c
1 /*
2  * Sonix sn9c102p sn9c105 sn9c120 (jpeg) subdriver
3  *
4  * Copyright (C) 2009-2010 Jean-François Moine <http://moinejf.free.fr>
5  * Copyright (C) 2005 Michel Xhaard mxhaard@magic.fr
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  */
21
22 #define MODULE_NAME "sonixj"
23
24 #include <linux/input.h>
25 #include "gspca.h"
26 #include "jpeg.h"
27
28 #define V4L2_CID_INFRARED (V4L2_CID_PRIVATE_BASE + 0)
29
30 MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
31 MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
32 MODULE_LICENSE("GPL");
33
34 /* controls */
35 enum e_ctrl {
36         BRIGHTNESS,
37         CONTRAST,
38         COLORS,
39         BLUE,
40         RED,
41         GAMMA,
42         AUTOGAIN,
43         HFLIP,
44         VFLIP,
45         SHARPNESS,
46         INFRARED,
47         FREQ,
48         NCTRLS          /* number of controls */
49 };
50
51 /* specific webcam descriptor */
52 struct sd {
53         struct gspca_dev gspca_dev;     /* !! must be the first item */
54
55         struct gspca_ctrl ctrls[NCTRLS];
56
57         atomic_t avg_lum;
58         u32 exposure;
59
60         u8 quality;                     /* image quality */
61 #define QUALITY_MIN 60
62 #define QUALITY_MAX 95
63 #define QUALITY_DEF 80
64         u8 jpegqual;                    /* webcam quality */
65
66         u8 reg18;
67         u8 flags;
68
69         s8 ag_cnt;
70 #define AG_CNT_START 13
71
72         u8 bridge;
73 #define BRIDGE_SN9C102P 0
74 #define BRIDGE_SN9C105 1
75 #define BRIDGE_SN9C110 2
76 #define BRIDGE_SN9C120 3
77         u8 sensor;                      /* Type of image sensor chip */
78         u8 i2c_addr;
79
80         u8 jpeg_hdr[JPEG_HDR_SZ];
81 };
82 enum sensors {
83         SENSOR_ADCM1700,
84         SENSOR_GC0307,
85         SENSOR_HV7131R,
86         SENSOR_MI0360,
87         SENSOR_MI0360B,
88         SENSOR_MO4000,
89         SENSOR_MT9V111,
90         SENSOR_OM6802,
91         SENSOR_OV7630,
92         SENSOR_OV7648,
93         SENSOR_OV7660,
94         SENSOR_PO1030,
95         SENSOR_PO2030N,
96         SENSOR_SOI768,
97         SENSOR_SP80708,
98 };
99
100 /* V4L2 controls supported by the driver */
101 static void setbrightness(struct gspca_dev *gspca_dev);
102 static void setcontrast(struct gspca_dev *gspca_dev);
103 static void setcolors(struct gspca_dev *gspca_dev);
104 static void setredblue(struct gspca_dev *gspca_dev);
105 static void setgamma(struct gspca_dev *gspca_dev);
106 static void setautogain(struct gspca_dev *gspca_dev);
107 static void sethvflip(struct gspca_dev *gspca_dev);
108 static void setsharpness(struct gspca_dev *gspca_dev);
109 static void setinfrared(struct gspca_dev *gspca_dev);
110 static void setfreq(struct gspca_dev *gspca_dev);
111
112 static const struct ctrl sd_ctrls[NCTRLS] = {
113 [BRIGHTNESS] =  {
114             {
115                 .id      = V4L2_CID_BRIGHTNESS,
116                 .type    = V4L2_CTRL_TYPE_INTEGER,
117                 .name    = "Brightness",
118                 .minimum = 0,
119                 .maximum = 0xff,
120                 .step    = 1,
121                 .default_value = 0x80,
122             },
123             .set_control = setbrightness
124         },
125 [CONTRAST] = {
126             {
127                 .id      = V4L2_CID_CONTRAST,
128                 .type    = V4L2_CTRL_TYPE_INTEGER,
129                 .name    = "Contrast",
130                 .minimum = 0,
131 #define CONTRAST_MAX 127
132                 .maximum = CONTRAST_MAX,
133                 .step    = 1,
134                 .default_value = 63,
135             },
136             .set_control = setcontrast
137         },
138 [COLORS] = {
139             {
140                 .id      = V4L2_CID_SATURATION,
141                 .type    = V4L2_CTRL_TYPE_INTEGER,
142                 .name    = "Saturation",
143                 .minimum = 0,
144                 .maximum = 40,
145                 .step    = 1,
146 #define COLORS_DEF 25
147                 .default_value = COLORS_DEF,
148             },
149             .set_control = setcolors
150         },
151 [BLUE] = {
152             {
153                 .id      = V4L2_CID_BLUE_BALANCE,
154                 .type    = V4L2_CTRL_TYPE_INTEGER,
155                 .name    = "Blue Balance",
156                 .minimum = 24,
157                 .maximum = 40,
158                 .step    = 1,
159                 .default_value = 32,
160             },
161             .set_control = setredblue
162         },
163 [RED] = {
164             {
165                 .id      = V4L2_CID_RED_BALANCE,
166                 .type    = V4L2_CTRL_TYPE_INTEGER,
167                 .name    = "Red Balance",
168                 .minimum = 24,
169                 .maximum = 40,
170                 .step    = 1,
171                 .default_value = 32,
172             },
173             .set_control = setredblue
174         },
175 [GAMMA] = {
176             {
177                 .id      = V4L2_CID_GAMMA,
178                 .type    = V4L2_CTRL_TYPE_INTEGER,
179                 .name    = "Gamma",
180                 .minimum = 0,
181                 .maximum = 40,
182                 .step    = 1,
183 #define GAMMA_DEF 20
184                 .default_value = GAMMA_DEF,
185             },
186             .set_control = setgamma
187         },
188 [AUTOGAIN] = {
189             {
190                 .id      = V4L2_CID_AUTOGAIN,
191                 .type    = V4L2_CTRL_TYPE_BOOLEAN,
192                 .name    = "Auto Gain",
193                 .minimum = 0,
194                 .maximum = 1,
195                 .step    = 1,
196                 .default_value = 1
197             },
198             .set_control = setautogain
199         },
200 [HFLIP] = {
201             {
202                 .id      = V4L2_CID_HFLIP,
203                 .type    = V4L2_CTRL_TYPE_BOOLEAN,
204                 .name    = "Mirror",
205                 .minimum = 0,
206                 .maximum = 1,
207                 .step    = 1,
208                 .default_value = 0,
209             },
210             .set_control = sethvflip
211         },
212 [VFLIP] = {
213             {
214                 .id      = V4L2_CID_VFLIP,
215                 .type    = V4L2_CTRL_TYPE_BOOLEAN,
216                 .name    = "Vflip",
217                 .minimum = 0,
218                 .maximum = 1,
219                 .step    = 1,
220                 .default_value = 0,
221             },
222             .set_control = sethvflip
223         },
224 [SHARPNESS] = {
225             {
226                 .id      = V4L2_CID_SHARPNESS,
227                 .type    = V4L2_CTRL_TYPE_INTEGER,
228                 .name    = "Sharpness",
229                 .minimum = 0,
230                 .maximum = 255,
231                 .step    = 1,
232                 .default_value = 90,
233             },
234             .set_control = setsharpness
235         },
236 /* mt9v111 only */
237 [INFRARED] = {
238             {
239                 .id      = V4L2_CID_INFRARED,
240                 .type    = V4L2_CTRL_TYPE_BOOLEAN,
241                 .name    = "Infrared",
242                 .minimum = 0,
243                 .maximum = 1,
244                 .step    = 1,
245                 .default_value = 0,
246             },
247             .set_control = setinfrared
248         },
249 /* ov7630/ov7648/ov7660 only */
250 [FREQ] = {
251             {
252                 .id      = V4L2_CID_POWER_LINE_FREQUENCY,
253                 .type    = V4L2_CTRL_TYPE_MENU,
254                 .name    = "Light frequency filter",
255                 .minimum = 0,
256                 .maximum = 2,   /* 0: 0, 1: 50Hz, 2:60Hz */
257                 .step    = 1,
258                 .default_value = 1,
259             },
260             .set_control = setfreq
261         },
262 };
263
264 /* table of the disabled controls */
265 static const __u32 ctrl_dis[] = {
266 [SENSOR_ADCM1700] =     (1 << AUTOGAIN) |
267                         (1 << INFRARED) |
268                         (1 << HFLIP) |
269                         (1 << VFLIP) |
270                         (1 << FREQ),
271
272 [SENSOR_GC0307] =       (1 << INFRARED) |
273                         (1 << HFLIP) |
274                         (1 << VFLIP) |
275                         (1 << FREQ),
276
277 [SENSOR_HV7131R] =      (1 << INFRARED) |
278                         (1 << HFLIP) |
279                         (1 << FREQ),
280
281 [SENSOR_MI0360] =       (1 << INFRARED) |
282                         (1 << HFLIP) |
283                         (1 << VFLIP) |
284                         (1 << FREQ),
285
286 [SENSOR_MI0360B] =      (1 << INFRARED) |
287                         (1 << HFLIP) |
288                         (1 << VFLIP) |
289                         (1 << FREQ),
290
291 [SENSOR_MO4000] =       (1 << INFRARED) |
292                         (1 << HFLIP) |
293                         (1 << VFLIP) |
294                         (1 << FREQ),
295
296 [SENSOR_MT9V111] =      (1 << HFLIP) |
297                         (1 << VFLIP) |
298                         (1 << FREQ),
299
300 [SENSOR_OM6802] =       (1 << INFRARED) |
301                         (1 << HFLIP) |
302                         (1 << VFLIP) |
303                         (1 << FREQ),
304
305 [SENSOR_OV7630] =       (1 << INFRARED) |
306                         (1 << HFLIP),
307
308 [SENSOR_OV7648] =       (1 << INFRARED) |
309                         (1 << HFLIP),
310
311 [SENSOR_OV7660] =       (1 << AUTOGAIN) |
312                         (1 << INFRARED) |
313                         (1 << HFLIP) |
314                         (1 << VFLIP),
315
316 [SENSOR_PO1030] =       (1 << AUTOGAIN) |
317                         (1 << INFRARED) |
318                         (1 << HFLIP) |
319                         (1 << VFLIP) |
320                         (1 << FREQ),
321
322 [SENSOR_PO2030N] =      (1 << AUTOGAIN) |
323                         (1 << INFRARED) |
324                         (1 << FREQ),
325
326 [SENSOR_SOI768] =       (1 << AUTOGAIN) |
327                         (1 << INFRARED) |
328                         (1 << HFLIP) |
329                         (1 << VFLIP) |
330                         (1 << FREQ),
331
332 [SENSOR_SP80708] =      (1 << AUTOGAIN) |
333                         (1 << INFRARED) |
334                         (1 << HFLIP) |
335                         (1 << VFLIP) |
336                         (1 << FREQ),
337 };
338
339 static const struct v4l2_pix_format cif_mode[] = {
340         {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
341                 .bytesperline = 352,
342                 .sizeimage = 352 * 288 * 4 / 8 + 590,
343                 .colorspace = V4L2_COLORSPACE_JPEG,
344                 .priv = 0},
345 };
346 static const struct v4l2_pix_format vga_mode[] = {
347         {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
348                 .bytesperline = 160,
349                 .sizeimage = 160 * 120 * 4 / 8 + 590,
350                 .colorspace = V4L2_COLORSPACE_JPEG,
351                 .priv = 2},
352         {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
353                 .bytesperline = 320,
354                 .sizeimage = 320 * 240 * 3 / 8 + 590,
355                 .colorspace = V4L2_COLORSPACE_JPEG,
356                 .priv = 1},
357         {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
358                 .bytesperline = 640,
359                 /* Note 3 / 8 is not large enough, not even 5 / 8 is ?! */
360                 .sizeimage = 640 * 480 * 3 / 4 + 590,
361                 .colorspace = V4L2_COLORSPACE_JPEG,
362                 .priv = 0},
363 };
364
365 static const u8 sn_adcm1700[0x1c] = {
366 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
367         0x00,   0x43,   0x60,   0x00,   0x1a,   0x00,   0x00,   0x00,
368 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
369         0x80,   0x51,   0x00,   0x00,   0x00,   0x00,   0x00,   0x00,
370 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
371         0x03,   0x00,   0x05,   0x01,   0x05,   0x16,   0x12,   0x42,
372 /*      reg18   reg19   reg1a   reg1b */
373         0x06,   0x00,   0x00,   0x00
374 };
375
376 static const u8 sn_gc0307[0x1c] = {
377 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
378         0x00,   0x61,   0x62,   0x00,   0x1a,   0x00,   0x00,   0x00,
379 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
380         0x80,   0x21,   0x00,   0x00,   0x00,   0x00,   0x00,   0x00,
381 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
382         0x03,   0x00,   0x03,   0x01,   0x08,   0x28,   0x1e,   0x02,
383 /*      reg18   reg19   reg1a   reg1b */
384         0x06,   0x00,   0x00,   0x00
385 };
386
387 static const u8 sn_hv7131[0x1c] = {
388 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
389         0x00,   0x03,   0x60,   0x00,   0x1a,   0x20,   0x20,   0x20,
390 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
391         0x81,   0x11,   0x00,   0x00,   0x00,   0x00,   0x00,   0x00,
392 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
393         0x03,   0x00,   0x00,   0x01,   0x03,   0x28,   0x1e,   0x41,
394 /*      reg18   reg19   reg1a   reg1b */
395         0x0a,   0x00,   0x00,   0x00
396 };
397
398 static const u8 sn_mi0360[0x1c] = {
399 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
400         0x00,   0x61,   0x40,   0x00,   0x1a,   0x20,   0x20,   0x20,
401 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
402         0x81,   0x5d,   0x00,   0x00,   0x00,   0x00,   0x00,   0x00,
403 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
404         0x03,   0x00,   0x00,   0x02,   0x0a,   0x28,   0x1e,   0x61,
405 /*      reg18   reg19   reg1a   reg1b */
406         0x06,   0x00,   0x00,   0x00
407 };
408
409 static const u8 sn_mi0360b[0x1c] = {
410 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
411         0x00,   0x61,   0x40,   0x00,   0x1a,   0x00,   0x00,   0x00,
412 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
413         0x81,   0x5d,   0x00,   0x00,   0x00,   0x00,   0x00,   0x00,
414 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
415         0x03,   0x00,   0x00,   0x02,   0x0a,   0x28,   0x1e,   0x40,
416 /*      reg18   reg19   reg1a   reg1b */
417         0x06,   0x00,   0x00,   0x00
418 };
419
420 static const u8 sn_mo4000[0x1c] = {
421 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
422         0x00,   0x23,   0x60,   0x00,   0x1a,   0x00,   0x20,   0x18,
423 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
424         0x81,   0x21,   0x00,   0x00,   0x00,   0x00,   0x00,   0x00,
425 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
426         0x03,    0x00,  0x0b,   0x0f,   0x14,   0x28,   0x1e,   0x40,
427 /*      reg18   reg19   reg1a   reg1b */
428         0x08,   0x00,   0x00,   0x00
429 };
430
431 static const u8 sn_mt9v111[0x1c] = {
432 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
433         0x00,   0x61,   0x40,   0x00,   0x1a,   0x20,   0x20,   0x20,
434 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
435         0x81,   0x5c,   0x00,   0x00,   0x00,   0x00,   0x00,   0x00,
436 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
437         0x03,   0x00,   0x00,   0x02,   0x1c,   0x28,   0x1e,   0x40,
438 /*      reg18   reg19   reg1a   reg1b */
439         0x06,   0x00,   0x00,   0x00
440 };
441
442 static const u8 sn_om6802[0x1c] = {
443 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
444         0x00,   0x23,   0x72,   0x00,   0x1a,   0x20,   0x20,   0x19,
445 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
446         0x80,   0x34,   0x00,   0x00,   0x00,   0x00,   0x00,   0x00,
447 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
448         0x03,   0x00,   0x51,   0x01,   0x00,   0x28,   0x1e,   0x40,
449 /*      reg18   reg19   reg1a   reg1b */
450         0x05,   0x00,   0x00,   0x00
451 };
452
453 static const u8 sn_ov7630[0x1c] = {
454 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
455         0x00,   0x21,   0x40,   0x00,   0x1a,   0x00,   0x00,   0x00,
456 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
457         0x81,   0x21,   0x00,   0x00,   0x00,   0x00,   0x00,   0x00,
458 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
459         0x03,   0x00,   0x04,   0x01,   0x0a,   0x28,   0x1e,   0xc2,
460 /*      reg18   reg19   reg1a   reg1b */
461         0x0b,   0x00,   0x00,   0x00
462 };
463
464 static const u8 sn_ov7648[0x1c] = {
465 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
466         0x00,   0x63,   0x40,   0x00,   0x1a,   0x20,   0x20,   0x20,
467 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
468         0x81,   0x21,   0x00,   0x00,   0x00,   0x00,   0x00,   0x00,
469 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
470         0x03,   0x00,   0x00,   0x01,   0x00,   0x28,   0x1e,   0x00,
471 /*      reg18   reg19   reg1a   reg1b */
472         0x0b,   0x00,   0x00,   0x00
473 };
474
475 static const u8 sn_ov7660[0x1c] = {
476 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
477         0x00,   0x61,   0x40,   0x00,   0x1a,   0x00,   0x00,   0x00,
478 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
479         0x81,   0x21,   0x00,   0x00,   0x00,   0x00,   0x00,   0x00,
480 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
481         0x03,   0x00,   0x01,   0x01,   0x08,   0x28,   0x1e,   0x20,
482 /*      reg18   reg19   reg1a   reg1b */
483         0x07,   0x00,   0x00,   0x00
484 };
485
486 static const u8 sn_po1030[0x1c] = {
487 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
488         0x00,   0x21,   0x62,   0x00,   0x1a,   0x20,   0x20,   0x20,
489 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
490         0x81,   0x6e,   0x00,   0x00,   0x00,   0x00,   0x00,   0x00,
491 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
492         0x03,   0x00,   0x00,   0x06,   0x06,   0x28,   0x1e,   0x00,
493 /*      reg18   reg19   reg1a   reg1b */
494         0x07,   0x00,   0x00,   0x00
495 };
496
497 static const u8 sn_po2030n[0x1c] = {
498 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
499         0x00,   0x63,   0x40,   0x00,   0x1a,   0x00,   0x00,   0x00,
500 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
501         0x81,   0x6e,   0x00,   0x00,   0x00,   0x00,   0x00,   0x00,
502 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
503         0x03,   0x00,   0x00,   0x01,   0x14,   0x28,   0x1e,   0x00,
504 /*      reg18   reg19   reg1a   reg1b */
505         0x07,   0x00,   0x00,   0x00
506 };
507
508 static const u8 sn_soi768[0x1c] = {
509 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
510         0x00,   0x21,   0x40,   0x00,   0x1a,   0x00,   0x00,   0x00,
511 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
512         0x81,   0x21,   0x00,   0x00,   0x00,   0x00,   0x00,   0x00,
513 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
514         0x03,   0x00,   0x00,   0x01,   0x08,   0x28,   0x1e,   0x00,
515 /*      reg18   reg19   reg1a   reg1b */
516         0x07,   0x00,   0x00,   0x00
517 };
518
519 static const u8 sn_sp80708[0x1c] = {
520 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
521         0x00,   0x63,   0x60,   0x00,   0x1a,   0x20,   0x20,   0x20,
522 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
523         0x81,   0x18,   0x00,   0x00,   0x00,   0x00,   0x00,   0x00,
524 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
525         0x03,   0x00,   0x00,   0x03,   0x04,   0x28,   0x1e,   0x00,
526 /*      reg18   reg19   reg1a   reg1b */
527         0x07,   0x00,   0x00,   0x00
528 };
529
530 /* sequence specific to the sensors - !! index = SENSOR_xxx */
531 static const u8 *sn_tb[] = {
532 [SENSOR_ADCM1700] =     sn_adcm1700,
533 [SENSOR_GC0307] =       sn_gc0307,
534 [SENSOR_HV7131R] =      sn_hv7131,
535 [SENSOR_MI0360] =       sn_mi0360,
536 [SENSOR_MI0360B] =      sn_mi0360b,
537 [SENSOR_MO4000] =       sn_mo4000,
538 [SENSOR_MT9V111] =      sn_mt9v111,
539 [SENSOR_OM6802] =       sn_om6802,
540 [SENSOR_OV7630] =       sn_ov7630,
541 [SENSOR_OV7648] =       sn_ov7648,
542 [SENSOR_OV7660] =       sn_ov7660,
543 [SENSOR_PO1030] =       sn_po1030,
544 [SENSOR_PO2030N] =      sn_po2030n,
545 [SENSOR_SOI768] =       sn_soi768,
546 [SENSOR_SP80708] =      sn_sp80708,
547 };
548
549 /* default gamma table */
550 static const u8 gamma_def[17] = {
551         0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99,
552         0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
553 };
554 /* gamma for sensor ADCM1700 */
555 static const u8 gamma_spec_0[17] = {
556         0x0f, 0x39, 0x5a, 0x74, 0x86, 0x95, 0xa6, 0xb4,
557         0xbd, 0xc4, 0xcc, 0xd4, 0xd5, 0xde, 0xe4, 0xed, 0xf5
558 };
559 /* gamma for sensors HV7131R and MT9V111 */
560 static const u8 gamma_spec_1[17] = {
561         0x08, 0x3a, 0x52, 0x65, 0x75, 0x83, 0x91, 0x9d,
562         0xa9, 0xb4, 0xbe, 0xc8, 0xd2, 0xdb, 0xe4, 0xed, 0xf5
563 };
564 /* gamma for sensor GC0307 */
565 static const u8 gamma_spec_2[17] = {
566         0x14, 0x37, 0x50, 0x6a, 0x7c, 0x8d, 0x9d, 0xab,
567         0xb5, 0xbf, 0xc2, 0xcb, 0xd1, 0xd6, 0xdb, 0xe1, 0xeb
568 };
569 /* gamma for sensor SP80708 */
570 static const u8 gamma_spec_3[17] = {
571         0x0a, 0x2d, 0x4e, 0x68, 0x7d, 0x8f, 0x9f, 0xab,
572         0xb7, 0xc2, 0xcc, 0xd3, 0xd8, 0xde, 0xe2, 0xe5, 0xe6
573 };
574
575 /* color matrix and offsets */
576 static const u8 reg84[] = {
577         0x14, 0x00, 0x27, 0x00, 0x07, 0x00,     /* YR YG YB gains */
578         0xe8, 0x0f, 0xda, 0x0f, 0x40, 0x00,     /* UR UG UB */
579         0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f,     /* VR VG VB */
580         0x00, 0x00, 0x00                        /* YUV offsets */
581 };
582
583 #define DELAY   0xdd
584
585 static const u8 adcm1700_sensor_init[][8] = {
586         {0xa0, 0x51, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x10},
587         {0xb0, 0x51, 0x04, 0x08, 0x00, 0x00, 0x00, 0x10},       /* reset */
588         {DELAY, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
589         {0xb0, 0x51, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
590         {DELAY, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
591         {0xb0, 0x51, 0x0c, 0xe0, 0x2e, 0x00, 0x00, 0x10},
592         {0xb0, 0x51, 0x10, 0x02, 0x02, 0x00, 0x00, 0x10},
593         {0xb0, 0x51, 0x14, 0x0e, 0x0e, 0x00, 0x00, 0x10},
594         {0xb0, 0x51, 0x1c, 0x00, 0x80, 0x00, 0x00, 0x10},
595         {0xb0, 0x51, 0x20, 0x01, 0x00, 0x00, 0x00, 0x10},
596         {DELAY, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
597         {0xb0, 0x51, 0x04, 0x04, 0x00, 0x00, 0x00, 0x10},
598         {DELAY, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
599         {0xb0, 0x51, 0x04, 0x01, 0x00, 0x00, 0x00, 0x10},
600         {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
601         {0xb0, 0x51, 0x14, 0x01, 0x00, 0x00, 0x00, 0x10},
602         {0xb0, 0x51, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
603         {}
604 };
605 static const u8 adcm1700_sensor_param1[][8] = {
606         {0xb0, 0x51, 0x26, 0xf9, 0x01, 0x00, 0x00, 0x10},       /* exposure? */
607         {0xd0, 0x51, 0x1e, 0x8e, 0x8e, 0x8e, 0x8e, 0x10},
608
609         {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10},
610         {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10},
611         {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
612         {0xb0, 0x51, 0x32, 0x00, 0x72, 0x00, 0x00, 0x10},
613         {0xd0, 0x51, 0x1e, 0xbe, 0xd7, 0xe8, 0xbe, 0x10},       /* exposure? */
614
615         {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10},
616         {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10},
617         {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
618         {0xb0, 0x51, 0x32, 0x00, 0xa2, 0x00, 0x00, 0x10},
619         {}
620 };
621 static const u8 gc0307_sensor_init[][8] = {
622         {0xa0, 0x21, 0x43, 0x00, 0x00, 0x00, 0x00, 0x10},
623         {0xa0, 0x21, 0x44, 0xa2, 0x00, 0x00, 0x00, 0x10},
624         {0xa0, 0x21, 0x01, 0x6a, 0x00, 0x00, 0x00, 0x10},
625         {0xa0, 0x21, 0x02, 0x70, 0x00, 0x00, 0x00, 0x10},
626         {0xa0, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
627         {0xa0, 0x21, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
628         {0xa0, 0x21, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x10},
629         {0xa0, 0x21, 0x11, 0x05, 0x00, 0x00, 0x00, 0x10},
630         {0xa0, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
631         {0xa0, 0x21, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10},
632         {0xa0, 0x21, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10},
633         {0xa0, 0x21, 0x08, 0x02, 0x00, 0x00, 0x00, 0x10},
634         {0xa0, 0x21, 0x09, 0x01, 0x00, 0x00, 0x00, 0x10},
635         {0xa0, 0x21, 0x0a, 0xe8, 0x00, 0x00, 0x00, 0x10},
636         {0xa0, 0x21, 0x0b, 0x02, 0x00, 0x00, 0x00, 0x10},
637         {0xa0, 0x21, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x10},
638         {0xa0, 0x21, 0x0d, 0x22, 0x00, 0x00, 0x00, 0x10},
639         {0xa0, 0x21, 0x0e, 0x02, 0x00, 0x00, 0x00, 0x10},
640         {0xa0, 0x21, 0x0f, 0xb2, 0x00, 0x00, 0x00, 0x10},
641         {0xa0, 0x21, 0x12, 0x70, 0x00, 0x00, 0x00, 0x10},
642         {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 10ms*/
643         {0xa0, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10},
644         {0xa0, 0x21, 0x15, 0xb8, 0x00, 0x00, 0x00, 0x10},
645         {0xa0, 0x21, 0x16, 0x13, 0x00, 0x00, 0x00, 0x10},
646         {0xa0, 0x21, 0x17, 0x52, 0x00, 0x00, 0x00, 0x10},
647         {0xa0, 0x21, 0x18, 0x50, 0x00, 0x00, 0x00, 0x10},
648         {0xa0, 0x21, 0x1e, 0x0d, 0x00, 0x00, 0x00, 0x10},
649         {0xa0, 0x21, 0x1f, 0x32, 0x00, 0x00, 0x00, 0x10},
650         {0xa0, 0x21, 0x61, 0x90, 0x00, 0x00, 0x00, 0x10},
651         {0xa0, 0x21, 0x63, 0x70, 0x00, 0x00, 0x00, 0x10},
652         {0xa0, 0x21, 0x65, 0x98, 0x00, 0x00, 0x00, 0x10},
653         {0xa0, 0x21, 0x67, 0x90, 0x00, 0x00, 0x00, 0x10},
654         {0xa0, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
655         {0xa0, 0x21, 0x04, 0x96, 0x00, 0x00, 0x00, 0x10},
656         {0xa0, 0x21, 0x45, 0x27, 0x00, 0x00, 0x00, 0x10},
657         {0xa0, 0x21, 0x47, 0x2c, 0x00, 0x00, 0x00, 0x10},
658         {0xa0, 0x21, 0x43, 0x47, 0x00, 0x00, 0x00, 0x10},
659         {0xa0, 0x21, 0x44, 0xd8, 0x00, 0x00, 0x00, 0x10},
660         {}
661 };
662 static const u8 gc0307_sensor_param1[][8] = {
663         {0xa0, 0x21, 0x68, 0x13, 0x00, 0x00, 0x00, 0x10},
664         {0xd0, 0x21, 0x61, 0x80, 0x00, 0x80, 0x00, 0x10},
665         {0xc0, 0x21, 0x65, 0x80, 0x00, 0x80, 0x00, 0x10},
666         {0xc0, 0x21, 0x63, 0xa0, 0x00, 0xa6, 0x00, 0x10},
667 /*param3*/
668         {0xa0, 0x21, 0x01, 0x6e, 0x00, 0x00, 0x00, 0x10},
669         {0xa0, 0x21, 0x02, 0x88, 0x00, 0x00, 0x00, 0x10},
670         {}
671 };
672
673 static const u8 hv7131r_sensor_init[][8] = {
674         {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
675         {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10},
676         {0xd1, 0x11, 0x40, 0xff, 0x7f, 0x7f, 0x7f, 0x10},
677 /*      {0x91, 0x11, 0x44, 0x00, 0x00, 0x00, 0x00, 0x10}, */
678         {0xd1, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
679         {0xd1, 0x11, 0x14, 0x01, 0xe2, 0x02, 0x82, 0x10},
680 /*      {0x91, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10}, */
681
682         {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
683         {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
684         {0xc1, 0x11, 0x25, 0x00, 0x61, 0xa8, 0x00, 0x10},
685         {0xa1, 0x11, 0x30, 0x22, 0x00, 0x00, 0x00, 0x10},
686         {0xc1, 0x11, 0x31, 0x20, 0x2e, 0x20, 0x00, 0x10},
687         {0xc1, 0x11, 0x25, 0x00, 0xc3, 0x50, 0x00, 0x10},
688         {0xa1, 0x11, 0x30, 0x07, 0x00, 0x00, 0x00, 0x10}, /* gain14 */
689         {0xc1, 0x11, 0x31, 0x10, 0x10, 0x10, 0x00, 0x10}, /* r g b 101a10 */
690
691         {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
692         {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
693         {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
694         {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
695         {0xa1, 0x11, 0x23, 0x09, 0x00, 0x00, 0x00, 0x10},
696
697         {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
698         {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
699         {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
700         {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
701         {0xa1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10},
702         {0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10},
703                                                         /* set sensor clock */
704         {}
705 };
706 static const u8 mi0360_sensor_init[][8] = {
707         {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
708         {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
709         {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
710         {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
711         {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
712         {0xd1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x53, 0x10},
713         {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
714         {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
715         {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
716         {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
717         {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
718         {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
719         {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
720         {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
721         {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
722         {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
723         {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
724         {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
725         {0xd1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
726         {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
727         {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
728         {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
729         {0xd1, 0x5d, 0x2f, 0xf7, 0xB0, 0x00, 0x04, 0x10},
730         {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
731         {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
732         {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
733         {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
734         {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
735         {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
736         {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
737         {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
738         {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
739         {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
740
741         {0xb1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
742         {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
743         {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
744         {0xd1, 0x5d, 0x2b, 0x00, 0xa0, 0x00, 0xb0, 0x10},
745         {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0xa0, 0x10},
746
747         {0xb1, 0x5d, 0x0a, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor clck ?2 */
748         {0xb1, 0x5d, 0x06, 0x00, 0x30, 0x00, 0x00, 0x10},
749         {0xb1, 0x5d, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10},
750         {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
751
752         {0xd1, 0x5d, 0x2b, 0x00, 0xb9, 0x00, 0xe3, 0x10},
753         {0xd1, 0x5d, 0x2d, 0x00, 0x5f, 0x00, 0xb9, 0x10}, /* 42 */
754 /*      {0xb1, 0x5d, 0x35, 0x00, 0x67, 0x00, 0x00, 0x10}, * gain orig */
755 /*      {0xb1, 0x5d, 0x35, 0x00, 0x20, 0x00, 0x00, 0x10}, * gain */
756         {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
757         {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
758         {}
759 };
760 static const u8 mi0360b_sensor_init[][8] = {
761         {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
762         {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
763         {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 20ms*/
764         {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
765         {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 20ms*/
766         {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
767         {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
768         {0xd1, 0x5d, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
769         {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
770         {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
771         {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
772         {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
773         {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
774         {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
775         {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
776         {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
777         {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
778         {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
779         {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
780         {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
781         {0xd1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
782         {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
783         {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
784         {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
785         {0xd1, 0x5d, 0x2f, 0xf7, 0xb0, 0x00, 0x04, 0x10},
786         {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
787         {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
788         {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
789         {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
790         {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
791         {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
792         {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
793         {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
794         {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
795         {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
796
797         {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
798         {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
799         {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
800         {0xd1, 0x5d, 0x2b, 0x00, 0x33, 0x00, 0xa0, 0x10},
801         {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0x33, 0x10},
802         {}
803 };
804 static const u8 mi0360b_sensor_param1[][8] = {
805         {0xb1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
806         {0xb1, 0x5d, 0x06, 0x00, 0x53, 0x00, 0x00, 0x10},
807         {0xb1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x00, 0x10},
808         {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
809
810         {0xd1, 0x5d, 0x2b, 0x00, 0xd1, 0x01, 0xc9, 0x10},
811         {0xd1, 0x5d, 0x2d, 0x00, 0xed, 0x00, 0xd1, 0x10},
812         {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
813         {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
814         {}
815 };
816 static const u8 mo4000_sensor_init[][8] = {
817         {0xa1, 0x21, 0x01, 0x02, 0x00, 0x00, 0x00, 0x10},
818         {0xa1, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10},
819         {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
820         {0xa1, 0x21, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
821         {0xa1, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
822         {0xa1, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x10},
823         {0xa1, 0x21, 0x06, 0x80, 0x00, 0x00, 0x00, 0x10},
824         {0xa1, 0x21, 0x06, 0x81, 0x00, 0x00, 0x00, 0x10},
825         {0xa1, 0x21, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
826         {0xa1, 0x21, 0x11, 0x00, 0x00, 0x00, 0x00, 0x10},
827         {0xa1, 0x21, 0x11, 0x20, 0x00, 0x00, 0x00, 0x10},
828         {0xa1, 0x21, 0x11, 0x30, 0x00, 0x00, 0x00, 0x10},
829         {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
830         {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
831         {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
832         {0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
833         {0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10},
834         {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10},
835         {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
836         {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
837         {}
838 };
839 static const u8 mt9v111_sensor_init[][8] = {
840         {0xb1, 0x5c, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10}, /* reset? */
841         {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
842         {0xb1, 0x5c, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
843         {0xb1, 0x5c, 0x01, 0x00, 0x01, 0x00, 0x00, 0x10}, /* IFP select */
844         {0xb1, 0x5c, 0x08, 0x04, 0x80, 0x00, 0x00, 0x10}, /* output fmt ctrl */
845         {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10}, /* op mode ctrl */
846         {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
847         {0xb1, 0x5c, 0x03, 0x01, 0xe1, 0x00, 0x00, 0x10},
848         {0xb1, 0x5c, 0x04, 0x02, 0x81, 0x00, 0x00, 0x10},
849         {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
850         {0xb1, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10}, /* sensor select */
851         {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
852         {0xb1, 0x5c, 0x03, 0x01, 0xe6, 0x00, 0x00, 0x10},
853         {0xb1, 0x5c, 0x04, 0x02, 0x86, 0x00, 0x00, 0x10},
854         {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
855         {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10},
856         {0xb1, 0x5c, 0x08, 0x00, 0x08, 0x00, 0x00, 0x10}, /* row start */
857         {0xb1, 0x5c, 0x0e, 0x00, 0x08, 0x00, 0x00, 0x10},
858         {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10}, /* col start */
859         {0xb1, 0x5c, 0x03, 0x01, 0xe7, 0x00, 0x00, 0x10}, /* window height */
860         {0xb1, 0x5c, 0x04, 0x02, 0x87, 0x00, 0x00, 0x10}, /* window width */
861         {0xb1, 0x5c, 0x07, 0x30, 0x02, 0x00, 0x00, 0x10}, /* output ctrl */
862         {0xb1, 0x5c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10}, /* shutter delay */
863         {0xb1, 0x5c, 0x12, 0x00, 0xb0, 0x00, 0x00, 0x10}, /* zoom col start */
864         {0xb1, 0x5c, 0x13, 0x00, 0x7c, 0x00, 0x00, 0x10}, /* zoom row start */
865         {0xb1, 0x5c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* digital zoom */
866         {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10}, /* read mode */
867         {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
868         {}
869 };
870 static const u8 mt9v111_sensor_param1[][8] = {
871         {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
872         {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
873         {0xb1, 0x5c, 0x09, 0x01, 0x2c, 0x00, 0x00, 0x10},
874         {0xd1, 0x5c, 0x2b, 0x00, 0x33, 0x00, 0xa0, 0x10}, /* green1 gain */
875         {0xd1, 0x5c, 0x2d, 0x00, 0xa0, 0x00, 0x33, 0x10}, /* red gain */
876         /*******/
877         {0xb1, 0x5c, 0x06, 0x00, 0x1e, 0x00, 0x00, 0x10}, /* vert blanking */
878         {0xb1, 0x5c, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10}, /* horiz blanking */
879         {0xd1, 0x5c, 0x2c, 0x00, 0xad, 0x00, 0xad, 0x10}, /* blue gain */
880         {0xb1, 0x5c, 0x35, 0x01, 0xc0, 0x00, 0x00, 0x10}, /* global gain */
881         {}
882 };
883 static const u8 om6802_init0[2][8] = {
884 /*fixme: variable*/
885         {0xa0, 0x34, 0x29, 0x0e, 0x00, 0x00, 0x00, 0x10},
886         {0xa0, 0x34, 0x23, 0xb0, 0x00, 0x00, 0x00, 0x10},
887 };
888 static const u8 om6802_sensor_init[][8] = {
889         {0xa0, 0x34, 0xdf, 0x6d, 0x00, 0x00, 0x00, 0x10},
890                                                 /* factory mode */
891         {0xa0, 0x34, 0xdd, 0x18, 0x00, 0x00, 0x00, 0x10},
892                                                 /* output raw RGB */
893         {0xa0, 0x34, 0x5a, 0xc0, 0x00, 0x00, 0x00, 0x10},
894 /*      {0xa0, 0x34, 0xfb, 0x11, 0x00, 0x00, 0x00, 0x10}, */
895         {0xa0, 0x34, 0xf0, 0x04, 0x00, 0x00, 0x00, 0x10},
896                 /* auto-exposure speed (0) / white balance mode (auto RGB) */
897 /*      {0xa0, 0x34, 0xf1, 0x02, 0x00, 0x00, 0x00, 0x10},
898                                                          * set color mode */
899 /*      {0xa0, 0x34, 0xfe, 0x5b, 0x00, 0x00, 0x00, 0x10},
900                                                  * max AGC value in AE */
901 /*      {0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10},
902                                                          * preset AGC */
903 /*      {0xa0, 0x34, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x10},
904                                                  * preset brightness */
905 /*      {0xa0, 0x34, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x10},
906                                                          * preset contrast */
907 /*      {0xa0, 0x34, 0xe8, 0x31, 0x00, 0x00, 0x00, 0x10},
908                                                          * preset gamma */
909         {0xa0, 0x34, 0xe9, 0x0f, 0x00, 0x00, 0x00, 0x10},
910                                 /* luminance mode (0x4f -> AutoExpo on) */
911         {0xa0, 0x34, 0xe4, 0xff, 0x00, 0x00, 0x00, 0x10},
912                                                         /* preset shutter */
913 /*      {0xa0, 0x34, 0xef, 0x00, 0x00, 0x00, 0x00, 0x10},
914                                                          * auto frame rate */
915 /*      {0xa0, 0x34, 0xfb, 0xee, 0x00, 0x00, 0x00, 0x10}, */
916         {0xa0, 0x34, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
917         {}
918 };
919 static const u8 om6802_sensor_param1[][8] = {
920         {0xa0, 0x34, 0x71, 0x84, 0x00, 0x00, 0x00, 0x10},
921         {0xa0, 0x34, 0x72, 0x05, 0x00, 0x00, 0x00, 0x10},
922         {0xa0, 0x34, 0x68, 0x80, 0x00, 0x00, 0x00, 0x10},
923         {0xa0, 0x34, 0x69, 0x01, 0x00, 0x00, 0x00, 0x10},
924         {}
925 };
926 static const u8 ov7630_sensor_init[][8] = {
927         {0xa1, 0x21, 0x76, 0x01, 0x00, 0x00, 0x00, 0x10},
928         {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
929         {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
930         {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
931         {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
932         {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
933         {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
934 /* win: i2c_r from 00 to 80 */
935         {0xd1, 0x21, 0x03, 0x80, 0x10, 0x20, 0x80, 0x10},
936         {0xb1, 0x21, 0x0c, 0x20, 0x20, 0x00, 0x00, 0x10},
937 /* HDG: 0x11 was 0x00 change to 0x01 for better exposure (15 fps instead of 30)
938         0x13 was 0xc0 change to 0xc3 for auto gain and exposure */
939         {0xd1, 0x21, 0x11, 0x01, 0x48, 0xc3, 0x00, 0x10},
940         {0xb1, 0x21, 0x15, 0x80, 0x03, 0x00, 0x00, 0x10},
941         {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
942         {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
943         {0xd1, 0x21, 0x1f, 0x00, 0x80, 0x80, 0x80, 0x10},
944         {0xd1, 0x21, 0x23, 0xde, 0x10, 0x8a, 0xa0, 0x10},
945         {0xc1, 0x21, 0x27, 0xca, 0xa2, 0x74, 0x00, 0x10},
946         {0xd1, 0x21, 0x2a, 0x88, 0x00, 0x88, 0x01, 0x10},
947         {0xc1, 0x21, 0x2e, 0x80, 0x00, 0x18, 0x00, 0x10},
948         {0xa1, 0x21, 0x21, 0x08, 0x00, 0x00, 0x00, 0x10},
949         {0xa1, 0x21, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
950         {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
951         {0xb1, 0x21, 0x32, 0xc2, 0x08, 0x00, 0x00, 0x10},
952         {0xb1, 0x21, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x10},
953         {0xd1, 0x21, 0x60, 0x05, 0x40, 0x12, 0x57, 0x10},
954         {0xa1, 0x21, 0x64, 0x73, 0x00, 0x00, 0x00, 0x10},
955         {0xd1, 0x21, 0x65, 0x00, 0x55, 0x01, 0xac, 0x10},
956         {0xa1, 0x21, 0x69, 0x38, 0x00, 0x00, 0x00, 0x10},
957         {0xd1, 0x21, 0x6f, 0x1f, 0x01, 0x00, 0x10, 0x10},
958         {0xd1, 0x21, 0x73, 0x50, 0x20, 0x02, 0x01, 0x10},
959         {0xd1, 0x21, 0x77, 0xf3, 0x90, 0x98, 0x98, 0x10},
960         {0xc1, 0x21, 0x7b, 0x00, 0x4c, 0xf7, 0x00, 0x10},
961         {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
962         {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
963         {}
964 };
965 static const u8 ov7630_sensor_param1[][8] = {
966         {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
967         {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
968 /*fixme: + 0x12, 0x04*/
969 /*      {0xa1, 0x21, 0x75, 0x82, 0x00, 0x00, 0x00, 0x10},  * COMN
970                                                          * set by setvflip */
971         {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
972         {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
973         {0xb1, 0x21, 0x01, 0x80, 0x80, 0x00, 0x00, 0x10},
974 /* */
975 /*      {0xa1, 0x21, 0x2a, 0x88, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
976 /*      {0xa1, 0x21, 0x2b, 0x34, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
977 /* */
978         {0xa1, 0x21, 0x10, 0x83, 0x00, 0x00, 0x00, 0x10},
979 /*      {0xb1, 0x21, 0x01, 0x88, 0x70, 0x00, 0x00, 0x10}, */
980         {}
981 };
982
983 static const u8 ov7648_sensor_init[][8] = {
984         {0xa1, 0x21, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10},
985         {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10},       /* reset */
986         {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
987         {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
988         {0xd1, 0x21, 0x03, 0xa4, 0x30, 0x88, 0x00, 0x10},
989         {0xb1, 0x21, 0x11, 0x80, 0x08, 0x00, 0x00, 0x10},
990         {0xc1, 0x21, 0x13, 0xa0, 0x04, 0x84, 0x00, 0x10},
991         {0xd1, 0x21, 0x17, 0x1a, 0x02, 0xba, 0xf4, 0x10},
992         {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
993         {0xd1, 0x21, 0x1f, 0x41, 0xc0, 0x80, 0x80, 0x10},
994         {0xd1, 0x21, 0x23, 0xde, 0xa0, 0x80, 0x32, 0x10},
995         {0xd1, 0x21, 0x27, 0xfe, 0xa0, 0x00, 0x91, 0x10},
996         {0xd1, 0x21, 0x2b, 0x00, 0x88, 0x85, 0x80, 0x10},
997         {0xc1, 0x21, 0x2f, 0x9c, 0x00, 0xc4, 0x00, 0x10},
998         {0xd1, 0x21, 0x60, 0xa6, 0x60, 0x88, 0x12, 0x10},
999         {0xd1, 0x21, 0x64, 0x88, 0x00, 0x00, 0x94, 0x10},
1000         {0xd1, 0x21, 0x68, 0x7a, 0x0c, 0x00, 0x00, 0x10},
1001         {0xd1, 0x21, 0x6c, 0x11, 0x33, 0x22, 0x00, 0x10},
1002         {0xd1, 0x21, 0x70, 0x11, 0x00, 0x10, 0x50, 0x10},
1003         {0xd1, 0x21, 0x74, 0x20, 0x06, 0x00, 0xb5, 0x10},
1004         {0xd1, 0x21, 0x78, 0x8a, 0x00, 0x00, 0x00, 0x10},
1005         {0xb1, 0x21, 0x7c, 0x00, 0x43, 0x00, 0x00, 0x10},
1006
1007         {0xd1, 0x21, 0x21, 0x86, 0x00, 0xde, 0xa0, 0x10},
1008 /*      {0xd1, 0x21, 0x25, 0x80, 0x32, 0xfe, 0xa0, 0x10}, jfm done */
1009 /*      {0xd1, 0x21, 0x29, 0x00, 0x91, 0x00, 0x88, 0x10}, jfm done */
1010 /*      {0xb1, 0x21, 0x2d, 0x85, 0x00, 0x00, 0x00, 0x10}, set by setfreq */
1011         {}
1012 };
1013 static const u8 ov7648_sensor_param1[][8] = {
1014 /*      {0xa1, 0x21, 0x12, 0x08, 0x00, 0x00, 0x00, 0x10}, jfm done */
1015 /*      {0xa1, 0x21, 0x75, 0x06, 0x00, 0x00, 0x00, 0x10},   * COMN
1016                                                          * set by setvflip */
1017         {0xa1, 0x21, 0x19, 0x02, 0x00, 0x00, 0x00, 0x10},
1018         {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
1019 /*      {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
1020 /*      {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},  * GAIN - def */
1021 /*      {0xb1, 0x21, 0x01, 0x6c, 0x6c, 0x00, 0x00, 0x10},  * B R - def: 80 */
1022 /*...*/
1023         {0xa1, 0x21, 0x11, 0x81, 0x00, 0x00, 0x00, 0x10}, /* CLKRC */
1024 /*      {0xa1, 0x21, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
1025 /*      {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
1026 /*      {0xa1, 0x21, 0x2a, 0x91, 0x00, 0x00, 0x00, 0x10}, jfm done */
1027 /*      {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
1028 /*      {0xb1, 0x21, 0x01, 0x64, 0x84, 0x00, 0x00, 0x10},  * B R - def: 80 */
1029
1030         {}
1031 };
1032
1033 static const u8 ov7660_sensor_init[][8] = {
1034         {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */
1035         {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
1036         {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
1037                                                 /* Outformat = rawRGB */
1038         {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */
1039         {0xd1, 0x21, 0x00, 0x01, 0x74, 0x92, 0x00, 0x10},
1040                                                 /* GAIN BLUE RED VREF */
1041         {0xd1, 0x21, 0x04, 0x00, 0x7d, 0x62, 0x00, 0x10},
1042                                                 /* COM 1 BAVE GEAVE AECHH */
1043         {0xb1, 0x21, 0x08, 0x83, 0x01, 0x00, 0x00, 0x10}, /* RAVE COM2 */
1044         {0xd1, 0x21, 0x0c, 0x00, 0x08, 0x04, 0x4f, 0x10}, /* COM 3 4 5 6 */
1045         {0xd1, 0x21, 0x10, 0x7f, 0x40, 0x05, 0xff, 0x10},
1046                                                 /* AECH CLKRC COM7 COM8 */
1047         {0xc1, 0x21, 0x14, 0x2c, 0x00, 0x02, 0x00, 0x10}, /* COM9 COM10 */
1048         {0xd1, 0x21, 0x17, 0x10, 0x60, 0x02, 0x7b, 0x10},
1049                                                 /* HSTART HSTOP VSTRT VSTOP */
1050         {0xa1, 0x21, 0x1b, 0x02, 0x00, 0x00, 0x00, 0x10}, /* PSHFT */
1051         {0xb1, 0x21, 0x1e, 0x01, 0x0e, 0x00, 0x00, 0x10}, /* MVFP LAEC */
1052         {0xd1, 0x21, 0x20, 0x07, 0x07, 0x07, 0x07, 0x10},
1053                                         /* BOS GBOS GROS ROS (BGGR offset) */
1054 /*      {0xd1, 0x21, 0x24, 0x68, 0x58, 0xd4, 0x80, 0x10}, */
1055         {0xd1, 0x21, 0x24, 0x78, 0x68, 0xd4, 0x80, 0x10},
1056                                                 /* AEW AEB VPT BBIAS */
1057         {0xd1, 0x21, 0x28, 0x80, 0x30, 0x00, 0x00, 0x10},
1058                                                 /* GbBIAS RSVD EXHCH EXHCL */
1059         {0xd1, 0x21, 0x2c, 0x80, 0x00, 0x00, 0x62, 0x10},
1060                                                 /* RBIAS ADVFL ASDVFH YAVE */
1061         {0xc1, 0x21, 0x30, 0x08, 0x30, 0xb4, 0x00, 0x10},
1062                                                 /* HSYST HSYEN HREF */
1063         {0xd1, 0x21, 0x33, 0x00, 0x07, 0x84, 0x00, 0x10}, /* reserved */
1064         {0xd1, 0x21, 0x37, 0x0c, 0x02, 0x43, 0x00, 0x10},
1065                                                 /* ADC ACOM OFON TSLB */
1066         {0xd1, 0x21, 0x3b, 0x02, 0x6c, 0x19, 0x0e, 0x10},
1067                                                 /* COM11 COM12 COM13 COM14 */
1068         {0xd1, 0x21, 0x3f, 0x41, 0xc1, 0x22, 0x08, 0x10},
1069                                                 /* EDGE COM15 COM16 COM17 */
1070         {0xd1, 0x21, 0x43, 0xf0, 0x10, 0x78, 0xa8, 0x10}, /* reserved */
1071         {0xd1, 0x21, 0x47, 0x60, 0x80, 0x00, 0x00, 0x10}, /* reserved */
1072         {0xd1, 0x21, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* reserved */
1073         {0xd1, 0x21, 0x4f, 0x46, 0x36, 0x0f, 0x17, 0x10}, /* MTX 1 2 3 4 */
1074         {0xd1, 0x21, 0x53, 0x7f, 0x96, 0x40, 0x40, 0x10}, /* MTX 5 6 7 8 */
1075         {0xb1, 0x21, 0x57, 0x40, 0x0f, 0x00, 0x00, 0x10}, /* MTX9 MTXS */
1076         {0xd1, 0x21, 0x59, 0xba, 0x9a, 0x22, 0xb9, 0x10}, /* reserved */
1077         {0xd1, 0x21, 0x5d, 0x9b, 0x10, 0xf0, 0x05, 0x10}, /* reserved */
1078         {0xa1, 0x21, 0x61, 0x60, 0x00, 0x00, 0x00, 0x10}, /* reserved */
1079         {0xd1, 0x21, 0x62, 0x00, 0x00, 0x50, 0x30, 0x10},
1080                                                 /* LCC1 LCC2 LCC3 LCC4 */
1081         {0xa1, 0x21, 0x66, 0x00, 0x00, 0x00, 0x00, 0x10}, /* LCC5 */
1082         {0xd1, 0x21, 0x67, 0x80, 0x7a, 0x90, 0x80, 0x10}, /* MANU */
1083         {0xa1, 0x21, 0x6b, 0x0a, 0x00, 0x00, 0x00, 0x10},
1084                                         /* band gap reference [0:3] DBLV */
1085         {0xd1, 0x21, 0x6c, 0x30, 0x48, 0x80, 0x74, 0x10}, /* gamma curve */
1086         {0xd1, 0x21, 0x70, 0x64, 0x60, 0x5c, 0x58, 0x10}, /* gamma curve */
1087         {0xd1, 0x21, 0x74, 0x54, 0x4c, 0x40, 0x38, 0x10}, /* gamma curve */
1088         {0xd1, 0x21, 0x78, 0x34, 0x30, 0x2f, 0x2b, 0x10}, /* gamma curve */
1089         {0xd1, 0x21, 0x7c, 0x03, 0x07, 0x17, 0x34, 0x10}, /* gamma curve */
1090         {0xd1, 0x21, 0x80, 0x41, 0x4d, 0x58, 0x63, 0x10}, /* gamma curve */
1091         {0xd1, 0x21, 0x84, 0x6e, 0x77, 0x87, 0x95, 0x10}, /* gamma curve */
1092         {0xc1, 0x21, 0x88, 0xaf, 0xc7, 0xdf, 0x00, 0x10}, /* gamma curve */
1093         {0xc1, 0x21, 0x8b, 0x99, 0x99, 0xcf, 0x00, 0x10}, /* reserved */
1094         {0xb1, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x10}, /* DM_LNL/H */
1095 /* not in all ms-win traces*/
1096         {0xa1, 0x21, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x10},
1097         {}
1098 };
1099 static const u8 ov7660_sensor_param1[][8] = {
1100         {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10}, /* MVFP */
1101                                                 /* bits[3..0]reserved */
1102         {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10},
1103         {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
1104                                                 /* VREF vertical frame ctrl */
1105         {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
1106         {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10}, /* AECH 0x20 */
1107         {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFL */
1108         {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFH */
1109         {0xa1, 0x21, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x10}, /* GAIN */
1110 /*      {0xb1, 0x21, 0x01, 0x78, 0x78, 0x00, 0x00, 0x10}, * BLUE */
1111 /****** (some exchanges in the win trace) ******/
1112 /*fixme:param2*/
1113         {0xa1, 0x21, 0x93, 0x00, 0x00, 0x00, 0x00, 0x10},/* dummy line hight */
1114         {0xa1, 0x21, 0x92, 0x25, 0x00, 0x00, 0x00, 0x10}, /* dummy line low */
1115         {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCH */
1116         {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCL */
1117 /*      {0xa1, 0x21, 0x02, 0x90, 0x00, 0x00, 0x00, 0x10},  * RED */
1118 /****** (some exchanges in the win trace) ******/
1119 /******!! startsensor KO if changed !!****/
1120 /*fixme: param3*/
1121         {0xa1, 0x21, 0x93, 0x01, 0x00, 0x00, 0x00, 0x10},
1122         {0xa1, 0x21, 0x92, 0xff, 0x00, 0x00, 0x00, 0x10},
1123         {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10},
1124         {0xa1, 0x21, 0x2b, 0xc3, 0x00, 0x00, 0x00, 0x10},
1125         {}
1126 };
1127
1128 static const u8 po1030_sensor_init[][8] = {
1129 /* the sensor registers are described in m5602/m5602_po1030.h */
1130         {0xa1, 0x6e, 0x3f, 0x20, 0x00, 0x00, 0x00, 0x10}, /* sensor reset */
1131         {DELAY, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
1132         {0xa1, 0x6e, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x10},
1133         {0xa1, 0x6e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x10},
1134         {0xd1, 0x6e, 0x04, 0x02, 0xb1, 0x02, 0x39, 0x10},
1135         {0xd1, 0x6e, 0x08, 0x00, 0x01, 0x00, 0x00, 0x10},
1136         {0xd1, 0x6e, 0x0c, 0x02, 0x7f, 0x01, 0xe0, 0x10},
1137         {0xd1, 0x6e, 0x12, 0x03, 0x02, 0x00, 0x03, 0x10},
1138         {0xd1, 0x6e, 0x16, 0x85, 0x40, 0x4a, 0x40, 0x10}, /* r/g1/b/g2 gains */
1139         {0xc1, 0x6e, 0x1a, 0x00, 0x80, 0x00, 0x00, 0x10},
1140         {0xd1, 0x6e, 0x1d, 0x08, 0x03, 0x00, 0x00, 0x10},
1141         {0xd1, 0x6e, 0x23, 0x00, 0xb0, 0x00, 0x94, 0x10},
1142         {0xd1, 0x6e, 0x27, 0x58, 0x00, 0x00, 0x00, 0x10},
1143         {0xb1, 0x6e, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10},
1144         {0xd1, 0x6e, 0x2d, 0x14, 0x35, 0x61, 0x84, 0x10}, /* gamma corr */
1145         {0xd1, 0x6e, 0x31, 0xa2, 0xbd, 0xd8, 0xff, 0x10},
1146         {0xd1, 0x6e, 0x35, 0x06, 0x1e, 0x12, 0x02, 0x10}, /* color matrix */
1147         {0xd1, 0x6e, 0x39, 0xaa, 0x53, 0x37, 0xd5, 0x10},
1148         {0xa1, 0x6e, 0x3d, 0xf2, 0x00, 0x00, 0x00, 0x10},
1149         {0xd1, 0x6e, 0x3e, 0x00, 0x00, 0x80, 0x03, 0x10},
1150         {0xd1, 0x6e, 0x42, 0x03, 0x00, 0x00, 0x00, 0x10},
1151         {0xc1, 0x6e, 0x46, 0x00, 0x80, 0x80, 0x00, 0x10},
1152         {0xd1, 0x6e, 0x4b, 0x02, 0xef, 0x08, 0xcd, 0x10},
1153         {0xd1, 0x6e, 0x4f, 0x00, 0xd0, 0x00, 0xa0, 0x10},
1154         {0xd1, 0x6e, 0x53, 0x01, 0xaa, 0x01, 0x40, 0x10},
1155         {0xd1, 0x6e, 0x5a, 0x50, 0x04, 0x30, 0x03, 0x10}, /* raw rgb bayer */
1156         {0xa1, 0x6e, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x10},
1157         {0xd1, 0x6e, 0x5f, 0x10, 0x40, 0xff, 0x00, 0x10},
1158
1159         {0xd1, 0x6e, 0x63, 0x40, 0x40, 0x00, 0x00, 0x10},
1160         {0xd1, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x00, 0x10},
1161         {0xd1, 0x6e, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x10},
1162         {0xd1, 0x6e, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x10},
1163         {0xc1, 0x6e, 0x73, 0x10, 0x80, 0xeb, 0x00, 0x10},
1164         {}
1165 };
1166 static const u8 po1030_sensor_param1[][8] = {
1167 /* from ms-win traces - these values change with auto gain/expo/wb.. */
1168         {0xa1, 0x6e, 0x1e, 0x03, 0x00, 0x00, 0x00, 0x10},
1169         {0xa1, 0x6e, 0x1e, 0x03, 0x00, 0x00, 0x00, 0x10},
1170 /* mean values */
1171         {0xc1, 0x6e, 0x1a, 0x02, 0xd4, 0xa4, 0x00, 0x10}, /* integlines */
1172         {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10}, /* global gain */
1173         {0xc1, 0x6e, 0x16, 0x40, 0x40, 0x40, 0x00, 0x10}, /* r/g1/b gains */
1174
1175         {0xa1, 0x6e, 0x1d, 0x08, 0x00, 0x00, 0x00, 0x10}, /* control1 */
1176         {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10}, /* frameheight */
1177         {0xa1, 0x6e, 0x07, 0xd5, 0x00, 0x00, 0x00, 0x10},
1178 /*      {0xc1, 0x6e, 0x16, 0x49, 0x40, 0x45, 0x00, 0x10}, */
1179         {}
1180 };
1181
1182 static const u8 po2030n_sensor_init[][8] = {
1183         {0xa1, 0x6e, 0x1e, 0x1a, 0x00, 0x00, 0x00, 0x10},
1184         {0xa1, 0x6e, 0x1f, 0x99, 0x00, 0x00, 0x00, 0x10},
1185         {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 10ms */
1186         {0xa1, 0x6e, 0x1e, 0x0a, 0x00, 0x00, 0x00, 0x10},
1187         {0xa1, 0x6e, 0x1f, 0x19, 0x00, 0x00, 0x00, 0x10},
1188         {DELAY, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 10ms */
1189         {0xa1, 0x6e, 0x20, 0x44, 0x00, 0x00, 0x00, 0x10},
1190         {0xa1, 0x6e, 0x04, 0x03, 0x00, 0x00, 0x00, 0x10},
1191         {0xa1, 0x6e, 0x05, 0x70, 0x00, 0x00, 0x00, 0x10},
1192         {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10},
1193         {0xa1, 0x6e, 0x07, 0x25, 0x00, 0x00, 0x00, 0x10},
1194         {0xd1, 0x6e, 0x08, 0x00, 0xd0, 0x00, 0x08, 0x10},
1195         {0xd1, 0x6e, 0x0c, 0x03, 0x50, 0x01, 0xe8, 0x10},
1196         {0xd1, 0x6e, 0x1d, 0x20, 0x0a, 0x19, 0x44, 0x10},
1197         {0xd1, 0x6e, 0x21, 0x00, 0x00, 0x00, 0x00, 0x10},
1198         {0xd1, 0x6e, 0x25, 0x00, 0x00, 0x00, 0x00, 0x10},
1199         {0xd1, 0x6e, 0x29, 0x00, 0x00, 0x00, 0x00, 0x10},
1200         {0xd1, 0x6e, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10},
1201         {0xd1, 0x6e, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
1202         {0xd1, 0x6e, 0x35, 0x00, 0x00, 0x00, 0x00, 0x10},
1203         {0xd1, 0x6e, 0x39, 0x00, 0x00, 0x00, 0x00, 0x10},
1204         {0xd1, 0x6e, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x10},
1205         {0xd1, 0x6e, 0x41, 0x00, 0x00, 0x00, 0x00, 0x10},
1206         {0xd1, 0x6e, 0x45, 0x00, 0x00, 0x00, 0x00, 0x10},
1207         {0xd1, 0x6e, 0x49, 0x00, 0x00, 0x00, 0x00, 0x10},
1208         {0xd1, 0x6e, 0x4d, 0x00, 0x00, 0x00, 0xed, 0x10},
1209         {0xd1, 0x6e, 0x51, 0x17, 0x4a, 0x2f, 0xc0, 0x10},
1210         {0xd1, 0x6e, 0x55, 0x00, 0x00, 0x00, 0x00, 0x10},
1211         {0xd1, 0x6e, 0x59, 0x00, 0x00, 0x00, 0x00, 0x10},
1212         {0xd1, 0x6e, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x10},
1213         {0xd1, 0x6e, 0x61, 0x00, 0x00, 0x00, 0x00, 0x10},
1214         {0xd1, 0x6e, 0x65, 0x00, 0x00, 0x00, 0x00, 0x10},
1215         {0xd1, 0x6e, 0x69, 0x00, 0x00, 0x00, 0x00, 0x10},
1216         {0xd1, 0x6e, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x10},
1217         {0xd1, 0x6e, 0x71, 0x00, 0x00, 0x00, 0x00, 0x10},
1218         {0xd1, 0x6e, 0x75, 0x00, 0x00, 0x00, 0x00, 0x10},
1219         {0xd1, 0x6e, 0x79, 0x00, 0x00, 0x00, 0x00, 0x10},
1220         {0xd1, 0x6e, 0x7d, 0x00, 0x00, 0x00, 0x00, 0x10},
1221         {0xd1, 0x6e, 0x81, 0x00, 0x00, 0x00, 0x00, 0x10},
1222         {0xd1, 0x6e, 0x85, 0x00, 0x00, 0x00, 0x08, 0x10},
1223         {0xd1, 0x6e, 0x89, 0x01, 0xe8, 0x00, 0x01, 0x10},
1224         {0xa1, 0x6e, 0x8d, 0x00, 0x00, 0x00, 0x00, 0x10},
1225         {0xd1, 0x6e, 0x21, 0x00, 0x00, 0x00, 0x00, 0x10},
1226         {0xd1, 0x6e, 0x25, 0x00, 0x00, 0x00, 0x01, 0x10},
1227         {0xd1, 0x6e, 0x29, 0xe6, 0x00, 0xbd, 0x03, 0x10},
1228         {0xd1, 0x6e, 0x2d, 0x41, 0x38, 0x68, 0x40, 0x10},
1229         {0xd1, 0x6e, 0x31, 0x2b, 0x00, 0x36, 0x00, 0x10},
1230         {0xd1, 0x6e, 0x35, 0x30, 0x30, 0x08, 0x00, 0x10},
1231         {0xd1, 0x6e, 0x39, 0x00, 0x00, 0x33, 0x06, 0x10},
1232         {0xb1, 0x6e, 0x3d, 0x06, 0x02, 0x00, 0x00, 0x10},
1233         {}
1234 };
1235 static const u8 po2030n_sensor_param1[][8] = {
1236         {0xa1, 0x6e, 0x1a, 0x01, 0x00, 0x00, 0x00, 0x10},
1237         {DELAY, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 8ms */
1238         {0xa1, 0x6e, 0x1b, 0xf4, 0x00, 0x00, 0x00, 0x10},
1239         {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10},
1240         {0xd1, 0x6e, 0x16, 0x50, 0x40, 0x49, 0x40, 0x10},
1241 /*param2*/
1242         {0xa1, 0x6e, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x10},
1243         {0xa1, 0x6e, 0x04, 0x03, 0x00, 0x00, 0x00, 0x10},
1244         {0xa1, 0x6e, 0x05, 0x6f, 0x00, 0x00, 0x00, 0x10},
1245         {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10},
1246         {0xa1, 0x6e, 0x07, 0x25, 0x00, 0x00, 0x00, 0x10},
1247         {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10},
1248         {0xc1, 0x6e, 0x16, 0x52, 0x40, 0x48, 0x00, 0x10},
1249 /*after start*/
1250         {0xa1, 0x6e, 0x15, 0x0f, 0x00, 0x00, 0x00, 0x10},
1251         {DELAY, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 5ms */
1252         {0xa1, 0x6e, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x10},
1253         {DELAY, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 5ms */
1254         {0xa1, 0x6e, 0x1b, 0x53, 0x00, 0x00, 0x00, 0x10},
1255         {}
1256 };
1257
1258 static const u8 soi768_sensor_init[][8] = {
1259         {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
1260         {DELAY, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 96ms */
1261         {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
1262         {0xa1, 0x21, 0x13, 0x80, 0x00, 0x00, 0x00, 0x10},
1263         {0xa1, 0x21, 0x0f, 0x03, 0x00, 0x00, 0x00, 0x10},
1264         {0xa1, 0x21, 0x19, 0x00, 0x00, 0x00, 0x00, 0x10},
1265         {}
1266 };
1267 static const u8 soi768_sensor_param1[][8] = {
1268         {0xa1, 0x21, 0x10, 0x10, 0x00, 0x00, 0x00, 0x10},
1269         {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10},
1270         {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
1271         {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1272         {0xb1, 0x21, 0x01, 0x7f, 0x7f, 0x00, 0x00, 0x10},
1273 /* */
1274 /*      {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, */
1275 /*      {0xa1, 0x21, 0x2d, 0x25, 0x00, 0x00, 0x00, 0x10}, */
1276         {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10},
1277 /*      {0xb1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, */
1278         {0xa1, 0x21, 0x02, 0x8d, 0x00, 0x00, 0x00, 0x10},
1279 /* the next sequence should be used for auto gain */
1280         {0xa1, 0x21, 0x00, 0x07, 0x00, 0x00, 0x00, 0x10},
1281                         /* global gain ? : 07 - change with 0x15 at the end */
1282         {0xa1, 0x21, 0x10, 0x3f, 0x00, 0x00, 0x00, 0x10}, /* ???? : 063f */
1283         {0xa1, 0x21, 0x04, 0x06, 0x00, 0x00, 0x00, 0x10},
1284         {0xb1, 0x21, 0x2d, 0x00, 0x02, 0x00, 0x00, 0x10},
1285                         /* exposure ? : 0200 - change with 0x1e at the end */
1286         {}
1287 };
1288
1289 static const u8 sp80708_sensor_init[][8] = {
1290         {0xa1, 0x18, 0x06, 0xf9, 0x00, 0x00, 0x00, 0x10},
1291         {0xa1, 0x18, 0x09, 0x1f, 0x00, 0x00, 0x00, 0x10},
1292         {0xa1, 0x18, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
1293         {0xa1, 0x18, 0x0d, 0xc0, 0x00, 0x00, 0x00, 0x10},
1294         {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
1295         {0xa1, 0x18, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x10},
1296         {0xa1, 0x18, 0x10, 0x40, 0x00, 0x00, 0x00, 0x10},
1297         {0xa1, 0x18, 0x11, 0x4e, 0x00, 0x00, 0x00, 0x10},
1298         {0xa1, 0x18, 0x12, 0x53, 0x00, 0x00, 0x00, 0x10},
1299         {0xa1, 0x18, 0x15, 0x80, 0x00, 0x00, 0x00, 0x10},
1300         {0xa1, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10},
1301         {0xa1, 0x18, 0x19, 0x18, 0x00, 0x00, 0x00, 0x10},
1302         {0xa1, 0x18, 0x1a, 0x10, 0x00, 0x00, 0x00, 0x10},
1303         {0xa1, 0x18, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x10},
1304         {0xa1, 0x18, 0x1c, 0x28, 0x00, 0x00, 0x00, 0x10},
1305         {0xa1, 0x18, 0x1d, 0x02, 0x00, 0x00, 0x00, 0x10},
1306         {0xa1, 0x18, 0x1e, 0x10, 0x00, 0x00, 0x00, 0x10},
1307         {0xa1, 0x18, 0x26, 0x04, 0x00, 0x00, 0x00, 0x10},
1308         {0xa1, 0x18, 0x27, 0x1e, 0x00, 0x00, 0x00, 0x10},
1309         {0xa1, 0x18, 0x28, 0x5a, 0x00, 0x00, 0x00, 0x10},
1310         {0xa1, 0x18, 0x29, 0x28, 0x00, 0x00, 0x00, 0x10},
1311         {0xa1, 0x18, 0x2a, 0x78, 0x00, 0x00, 0x00, 0x10},
1312         {0xa1, 0x18, 0x2b, 0x01, 0x00, 0x00, 0x00, 0x10},
1313         {0xa1, 0x18, 0x2c, 0xf7, 0x00, 0x00, 0x00, 0x10},
1314         {0xa1, 0x18, 0x2d, 0x2d, 0x00, 0x00, 0x00, 0x10},
1315         {0xa1, 0x18, 0x2e, 0xd5, 0x00, 0x00, 0x00, 0x10},
1316         {0xa1, 0x18, 0x39, 0x42, 0x00, 0x00, 0x00, 0x10},
1317         {0xa1, 0x18, 0x3a, 0x67, 0x00, 0x00, 0x00, 0x10},
1318         {0xa1, 0x18, 0x3b, 0x87, 0x00, 0x00, 0x00, 0x10},
1319         {0xa1, 0x18, 0x3c, 0xa3, 0x00, 0x00, 0x00, 0x10},
1320         {0xa1, 0x18, 0x3d, 0xb0, 0x00, 0x00, 0x00, 0x10},
1321         {0xa1, 0x18, 0x3e, 0xbc, 0x00, 0x00, 0x00, 0x10},
1322         {0xa1, 0x18, 0x3f, 0xc8, 0x00, 0x00, 0x00, 0x10},
1323         {0xa1, 0x18, 0x40, 0xd4, 0x00, 0x00, 0x00, 0x10},
1324         {0xa1, 0x18, 0x41, 0xdf, 0x00, 0x00, 0x00, 0x10},
1325         {0xa1, 0x18, 0x42, 0xea, 0x00, 0x00, 0x00, 0x10},
1326         {0xa1, 0x18, 0x43, 0xf5, 0x00, 0x00, 0x00, 0x10},
1327         {0xa1, 0x18, 0x45, 0x80, 0x00, 0x00, 0x00, 0x10},
1328         {0xa1, 0x18, 0x46, 0x60, 0x00, 0x00, 0x00, 0x10},
1329         {0xa1, 0x18, 0x47, 0x50, 0x00, 0x00, 0x00, 0x10},
1330         {0xa1, 0x18, 0x48, 0x30, 0x00, 0x00, 0x00, 0x10},
1331         {0xa1, 0x18, 0x49, 0x01, 0x00, 0x00, 0x00, 0x10},
1332         {0xa1, 0x18, 0x4d, 0xae, 0x00, 0x00, 0x00, 0x10},
1333         {0xa1, 0x18, 0x4e, 0x03, 0x00, 0x00, 0x00, 0x10},
1334         {0xa1, 0x18, 0x4f, 0x66, 0x00, 0x00, 0x00, 0x10},
1335         {0xa1, 0x18, 0x50, 0x1c, 0x00, 0x00, 0x00, 0x10},
1336         {0xa1, 0x18, 0x44, 0x10, 0x00, 0x00, 0x00, 0x10},
1337         {0xa1, 0x18, 0x4a, 0x30, 0x00, 0x00, 0x00, 0x10},
1338         {0xa1, 0x18, 0x51, 0x80, 0x00, 0x00, 0x00, 0x10},
1339         {0xa1, 0x18, 0x52, 0x80, 0x00, 0x00, 0x00, 0x10},
1340         {0xa1, 0x18, 0x53, 0x80, 0x00, 0x00, 0x00, 0x10},
1341         {0xa1, 0x18, 0x54, 0x80, 0x00, 0x00, 0x00, 0x10},
1342         {0xa1, 0x18, 0x55, 0x80, 0x00, 0x00, 0x00, 0x10},
1343         {0xa1, 0x18, 0x56, 0x80, 0x00, 0x00, 0x00, 0x10},
1344         {0xa1, 0x18, 0x57, 0xe0, 0x00, 0x00, 0x00, 0x10},
1345         {0xa1, 0x18, 0x58, 0xc0, 0x00, 0x00, 0x00, 0x10},
1346         {0xa1, 0x18, 0x59, 0xab, 0x00, 0x00, 0x00, 0x10},
1347         {0xa1, 0x18, 0x5a, 0xa0, 0x00, 0x00, 0x00, 0x10},
1348         {0xa1, 0x18, 0x5b, 0x99, 0x00, 0x00, 0x00, 0x10},
1349         {0xa1, 0x18, 0x5c, 0x90, 0x00, 0x00, 0x00, 0x10},
1350         {0xa1, 0x18, 0x5e, 0x24, 0x00, 0x00, 0x00, 0x10},
1351         {0xa1, 0x18, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x10},
1352         {0xa1, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00, 0x10},
1353         {0xa1, 0x18, 0x61, 0x73, 0x00, 0x00, 0x00, 0x10},
1354         {0xa1, 0x18, 0x63, 0x42, 0x00, 0x00, 0x00, 0x10},
1355         {0xa1, 0x18, 0x64, 0x42, 0x00, 0x00, 0x00, 0x10},
1356         {0xa1, 0x18, 0x65, 0x42, 0x00, 0x00, 0x00, 0x10},
1357         {0xa1, 0x18, 0x66, 0x24, 0x00, 0x00, 0x00, 0x10},
1358         {0xa1, 0x18, 0x67, 0x24, 0x00, 0x00, 0x00, 0x10},
1359         {0xa1, 0x18, 0x68, 0x08, 0x00, 0x00, 0x00, 0x10},
1360         {0xa1, 0x18, 0x2f, 0xc9, 0x00, 0x00, 0x00, 0x10},
1361         {}
1362 };
1363 static const u8 sp80708_sensor_param1[][8] = {
1364         {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
1365         {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
1366         {0xa1, 0x18, 0x03, 0x01, 0x00, 0x00, 0x00, 0x10},
1367         {0xa1, 0x18, 0x04, 0xa4, 0x00, 0x00, 0x00, 0x10},
1368         {0xa1, 0x18, 0x14, 0x3f, 0x00, 0x00, 0x00, 0x10},
1369         {0xa1, 0x18, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
1370         {0xb1, 0x18, 0x11, 0x40, 0x40, 0x00, 0x00, 0x10},
1371         {}
1372 };
1373
1374 static const u8 (*sensor_init[])[8] = {
1375 [SENSOR_ADCM1700] =     adcm1700_sensor_init,
1376 [SENSOR_GC0307] =       gc0307_sensor_init,
1377 [SENSOR_HV7131R] =      hv7131r_sensor_init,
1378 [SENSOR_MI0360] =       mi0360_sensor_init,
1379 [SENSOR_MI0360B] =      mi0360b_sensor_init,
1380 [SENSOR_MO4000] =       mo4000_sensor_init,
1381 [SENSOR_MT9V111] =      mt9v111_sensor_init,
1382 [SENSOR_OM6802] =       om6802_sensor_init,
1383 [SENSOR_OV7630] =       ov7630_sensor_init,
1384 [SENSOR_OV7648] =       ov7648_sensor_init,
1385 [SENSOR_OV7660] =       ov7660_sensor_init,
1386 [SENSOR_PO1030] =       po1030_sensor_init,
1387 [SENSOR_PO2030N] =      po2030n_sensor_init,
1388 [SENSOR_SOI768] =       soi768_sensor_init,
1389 [SENSOR_SP80708] =      sp80708_sensor_init,
1390 };
1391
1392 /* read <len> bytes to gspca_dev->usb_buf */
1393 static void reg_r(struct gspca_dev *gspca_dev,
1394                   u16 value, int len)
1395 {
1396         int ret;
1397
1398         if (gspca_dev->usb_err < 0)
1399                 return;
1400 #ifdef GSPCA_DEBUG
1401         if (len > USB_BUF_SZ) {
1402                 err("reg_r: buffer overflow");
1403                 return;
1404         }
1405 #endif
1406         ret = usb_control_msg(gspca_dev->dev,
1407                         usb_rcvctrlpipe(gspca_dev->dev, 0),
1408                         0,
1409                         USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1410                         value, 0,
1411                         gspca_dev->usb_buf, len,
1412                         500);
1413         PDEBUG(D_USBI, "reg_r [%02x] -> %02x", value, gspca_dev->usb_buf[0]);
1414         if (ret < 0) {
1415                 err("reg_r err %d", ret);
1416                 gspca_dev->usb_err = ret;
1417         }
1418 }
1419
1420 static void reg_w1(struct gspca_dev *gspca_dev,
1421                    u16 value,
1422                    u8 data)
1423 {
1424         int ret;
1425
1426         if (gspca_dev->usb_err < 0)
1427                 return;
1428         PDEBUG(D_USBO, "reg_w1 [%04x] = %02x", value, data);
1429         gspca_dev->usb_buf[0] = data;
1430         ret = usb_control_msg(gspca_dev->dev,
1431                         usb_sndctrlpipe(gspca_dev->dev, 0),
1432                         0x08,
1433                         USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1434                         value,
1435                         0,
1436                         gspca_dev->usb_buf, 1,
1437                         500);
1438         if (ret < 0) {
1439                 err("reg_w1 err %d", ret);
1440                 gspca_dev->usb_err = ret;
1441         }
1442 }
1443 static void reg_w(struct gspca_dev *gspca_dev,
1444                           u16 value,
1445                           const u8 *buffer,
1446                           int len)
1447 {
1448         int ret;
1449
1450         if (gspca_dev->usb_err < 0)
1451                 return;
1452         PDEBUG(D_USBO, "reg_w [%04x] = %02x %02x ..",
1453                 value, buffer[0], buffer[1]);
1454 #ifdef GSPCA_DEBUG
1455         if (len > USB_BUF_SZ) {
1456                 err("reg_w: buffer overflow");
1457                 return;
1458         }
1459 #endif
1460         memcpy(gspca_dev->usb_buf, buffer, len);
1461         ret = usb_control_msg(gspca_dev->dev,
1462                         usb_sndctrlpipe(gspca_dev->dev, 0),
1463                         0x08,
1464                         USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1465                         value, 0,
1466                         gspca_dev->usb_buf, len,
1467                         500);
1468         if (ret < 0) {
1469                 err("reg_w err %d", ret);
1470                 gspca_dev->usb_err = ret;
1471         }
1472 }
1473
1474 /* I2C write 1 byte */
1475 static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
1476 {
1477         struct sd *sd = (struct sd *) gspca_dev;
1478         int ret;
1479
1480         if (gspca_dev->usb_err < 0)
1481                 return;
1482         PDEBUG(D_USBO, "i2c_w1 [%02x] = %02x", reg, val);
1483         switch (sd->sensor) {
1484         case SENSOR_ADCM1700:
1485         case SENSOR_OM6802:
1486         case SENSOR_GC0307:             /* i2c command = a0 (100 kHz) */
1487                 gspca_dev->usb_buf[0] = 0x80 | (2 << 4);
1488                 break;
1489         default:                        /* i2c command = a1 (400 kHz) */
1490                 gspca_dev->usb_buf[0] = 0x81 | (2 << 4);
1491                 break;
1492         }
1493         gspca_dev->usb_buf[1] = sd->i2c_addr;
1494         gspca_dev->usb_buf[2] = reg;
1495         gspca_dev->usb_buf[3] = val;
1496         gspca_dev->usb_buf[4] = 0;
1497         gspca_dev->usb_buf[5] = 0;
1498         gspca_dev->usb_buf[6] = 0;
1499         gspca_dev->usb_buf[7] = 0x10;
1500         ret = usb_control_msg(gspca_dev->dev,
1501                         usb_sndctrlpipe(gspca_dev->dev, 0),
1502                         0x08,
1503                         USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1504                         0x08,                   /* value = i2c */
1505                         0,
1506                         gspca_dev->usb_buf, 8,
1507                         500);
1508         if (ret < 0) {
1509                 err("i2c_w1 err %d", ret);
1510                 gspca_dev->usb_err = ret;
1511         }
1512 }
1513
1514 /* I2C write 8 bytes */
1515 static void i2c_w8(struct gspca_dev *gspca_dev,
1516                    const u8 *buffer)
1517 {
1518         int ret;
1519
1520         if (gspca_dev->usb_err < 0)
1521                 return;
1522         PDEBUG(D_USBO, "i2c_w8 [%02x] = %02x ..",
1523                 buffer[2], buffer[3]);
1524         memcpy(gspca_dev->usb_buf, buffer, 8);
1525         ret = usb_control_msg(gspca_dev->dev,
1526                         usb_sndctrlpipe(gspca_dev->dev, 0),
1527                         0x08,
1528                         USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1529                         0x08, 0,                /* value, index */
1530                         gspca_dev->usb_buf, 8,
1531                         500);
1532         msleep(2);
1533         if (ret < 0) {
1534                 err("i2c_w8 err %d", ret);
1535                 gspca_dev->usb_err = ret;
1536         }
1537 }
1538
1539 /* sensor read 'len' (1..5) bytes in gspca_dev->usb_buf */
1540 static void i2c_r(struct gspca_dev *gspca_dev, u8 reg, int len)
1541 {
1542         struct sd *sd = (struct sd *) gspca_dev;
1543         u8 mode[8];
1544
1545         switch (sd->sensor) {
1546         case SENSOR_ADCM1700:
1547         case SENSOR_OM6802:
1548         case SENSOR_GC0307:             /* i2c command = a0 (100 kHz) */
1549                 mode[0] = 0x80 | 0x10;
1550                 break;
1551         default:                        /* i2c command = 91 (400 kHz) */
1552                 mode[0] = 0x81 | 0x10;
1553                 break;
1554         }
1555         mode[1] = sd->i2c_addr;
1556         mode[2] = reg;
1557         mode[3] = 0;
1558         mode[4] = 0;
1559         mode[5] = 0;
1560         mode[6] = 0;
1561         mode[7] = 0x10;
1562         i2c_w8(gspca_dev, mode);
1563         msleep(2);
1564         mode[0] = (mode[0] & 0x81) | (len << 4) | 0x02;
1565         mode[2] = 0;
1566         i2c_w8(gspca_dev, mode);
1567         msleep(2);
1568         reg_r(gspca_dev, 0x0a, 5);
1569 }
1570
1571 static void i2c_w_seq(struct gspca_dev *gspca_dev,
1572                         const u8 (*data)[8])
1573 {
1574         while ((*data)[0] != 0) {
1575                 if ((*data)[0] != DELAY)
1576                         i2c_w8(gspca_dev, *data);
1577                 else
1578                         msleep((*data)[1]);
1579                 data++;
1580         }
1581 }
1582
1583 static void hv7131r_probe(struct gspca_dev *gspca_dev)
1584 {
1585         i2c_w1(gspca_dev, 0x02, 0);                     /* sensor wakeup */
1586         msleep(10);
1587         reg_w1(gspca_dev, 0x02, 0x66);                  /* Gpio on */
1588         msleep(10);
1589         i2c_r(gspca_dev, 0, 5);                         /* read sensor id */
1590         if (gspca_dev->usb_buf[0] == 0x02
1591             && gspca_dev->usb_buf[1] == 0x09
1592             && gspca_dev->usb_buf[2] == 0x01
1593             && gspca_dev->usb_buf[3] == 0x00
1594             && gspca_dev->usb_buf[4] == 0x00) {
1595                 PDEBUG(D_PROBE, "Sensor sn9c102P HV7131R found");
1596                 return;
1597         }
1598         PDEBUG(D_PROBE, "Sensor 0x%02x 0x%02x 0x%02x - sn9c102P not found",
1599                 gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
1600                 gspca_dev->usb_buf[2]);
1601 }
1602
1603 static void mi0360_probe(struct gspca_dev *gspca_dev)
1604 {
1605         struct sd *sd = (struct sd *) gspca_dev;
1606         int i, j;
1607         u16 val = 0;
1608         static const u8 probe_tb[][4][8] = {
1609             {                                   /* mi0360 */
1610                 {0xb0, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
1611                 {0x90, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1612                 {0xa2, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1613                 {0xb0, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10}
1614             },
1615             {                                   /* mt9v111 */
1616                 {0xb0, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10},
1617                 {0x90, 0x5c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x10},
1618                 {0xa2, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1619                 {}
1620             },
1621         };
1622
1623         for (i = 0; i < ARRAY_SIZE(probe_tb); i++) {
1624                 reg_w1(gspca_dev, 0x17, 0x62);
1625                 reg_w1(gspca_dev, 0x01, 0x08);
1626                 for (j = 0; j < 3; j++)
1627                         i2c_w8(gspca_dev, probe_tb[i][j]);
1628                 msleep(2);
1629                 reg_r(gspca_dev, 0x0a, 5);
1630                 val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
1631                 if (probe_tb[i][3][0] != 0)
1632                         i2c_w8(gspca_dev, probe_tb[i][3]);
1633                 reg_w1(gspca_dev, 0x01, 0x29);
1634                 reg_w1(gspca_dev, 0x17, 0x42);
1635                 if (val != 0xffff)
1636                         break;
1637         }
1638         if (gspca_dev->usb_err < 0)
1639                 return;
1640         switch (val) {
1641         case 0x8221:
1642                 PDEBUG(D_PROBE, "Sensor mi0360b");
1643                 sd->sensor = SENSOR_MI0360B;
1644                 break;
1645         case 0x823a:
1646                 PDEBUG(D_PROBE, "Sensor mt9v111");
1647                 sd->sensor = SENSOR_MT9V111;
1648                 break;
1649         case 0x8243:
1650                 PDEBUG(D_PROBE, "Sensor mi0360");
1651                 break;
1652         default:
1653                 PDEBUG(D_PROBE, "Unknown sensor %04x - forced to mi0360", val);
1654                 break;
1655         }
1656 }
1657
1658 static void ov7630_probe(struct gspca_dev *gspca_dev)
1659 {
1660         struct sd *sd = (struct sd *) gspca_dev;
1661         u16 val;
1662
1663         /* check ov76xx */
1664         reg_w1(gspca_dev, 0x17, 0x62);
1665         reg_w1(gspca_dev, 0x01, 0x08);
1666         sd->i2c_addr = 0x21;
1667         i2c_r(gspca_dev, 0x0a, 2);
1668         val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
1669         reg_w1(gspca_dev, 0x01, 0x29);
1670         reg_w1(gspca_dev, 0x17, 0x42);
1671         if (gspca_dev->usb_err < 0)
1672                 return;
1673         if (val == 0x7628) {                    /* soi768 */
1674                 sd->sensor = SENSOR_SOI768;
1675 /*fixme: only valid for 0c45:613e?*/
1676                 gspca_dev->cam.input_flags =
1677                                 V4L2_IN_ST_VFLIP | V4L2_IN_ST_HFLIP;
1678                 PDEBUG(D_PROBE, "Sensor soi768");
1679                 return;
1680         }
1681         PDEBUG(D_PROBE, "Sensor ov%04x", val);
1682 }
1683
1684 static void ov7648_probe(struct gspca_dev *gspca_dev)
1685 {
1686         struct sd *sd = (struct sd *) gspca_dev;
1687         u16 val;
1688
1689         /* check ov76xx */
1690         reg_w1(gspca_dev, 0x17, 0x62);
1691         reg_w1(gspca_dev, 0x01, 0x08);
1692         sd->i2c_addr = 0x21;
1693         i2c_r(gspca_dev, 0x0a, 2);
1694         val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
1695         reg_w1(gspca_dev, 0x01, 0x29);
1696         reg_w1(gspca_dev, 0x17, 0x42);
1697         if ((val & 0xff00) == 0x7600) {         /* ov76xx */
1698                 PDEBUG(D_PROBE, "Sensor ov%04x", val);
1699                 return;
1700         }
1701
1702         /* check po1030 */
1703         reg_w1(gspca_dev, 0x17, 0x62);
1704         reg_w1(gspca_dev, 0x01, 0x08);
1705         sd->i2c_addr = 0x6e;
1706         i2c_r(gspca_dev, 0x00, 2);
1707         val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
1708         reg_w1(gspca_dev, 0x01, 0x29);
1709         reg_w1(gspca_dev, 0x17, 0x42);
1710         if (gspca_dev->usb_err < 0)
1711                 return;
1712         if (val == 0x1030) {                    /* po1030 */
1713                 PDEBUG(D_PROBE, "Sensor po1030");
1714                 sd->sensor = SENSOR_PO1030;
1715                 return;
1716         }
1717         err("Unknown sensor %04x", val);
1718 }
1719
1720 /* 0c45:6142 sensor may be po2030n, gc0305 or gc0307 */
1721 static void po2030n_probe(struct gspca_dev *gspca_dev)
1722 {
1723         struct sd *sd = (struct sd *) gspca_dev;
1724         u16 val;
1725
1726         /* check gc0307 */
1727         reg_w1(gspca_dev, 0x17, 0x62);
1728         reg_w1(gspca_dev, 0x01, 0x08);
1729         reg_w1(gspca_dev, 0x02, 0x22);
1730         sd->i2c_addr = 0x21;
1731         i2c_r(gspca_dev, 0x00, 1);
1732         val = gspca_dev->usb_buf[4];
1733         reg_w1(gspca_dev, 0x01, 0x29);          /* reset */
1734         reg_w1(gspca_dev, 0x17, 0x42);
1735         if (val == 0x99) {                      /* gc0307 (?) */
1736                 PDEBUG(D_PROBE, "Sensor gc0307");
1737                 sd->sensor = SENSOR_GC0307;
1738                 return;
1739         }
1740
1741         /* check po2030n */
1742         reg_w1(gspca_dev, 0x17, 0x62);
1743         reg_w1(gspca_dev, 0x01, 0x0a);
1744         sd->i2c_addr = 0x6e;
1745         i2c_r(gspca_dev, 0x00, 2);
1746         val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
1747         reg_w1(gspca_dev, 0x01, 0x29);
1748         reg_w1(gspca_dev, 0x17, 0x42);
1749         if (gspca_dev->usb_err < 0)
1750                 return;
1751         if (val == 0x2030) {
1752                 PDEBUG(D_PROBE, "Sensor po2030n");
1753 /*              sd->sensor = SENSOR_PO2030N; */
1754         } else {
1755                 err("Unknown sensor ID %04x", val);
1756         }
1757 }
1758
1759 /* this function is called at probe time */
1760 static int sd_config(struct gspca_dev *gspca_dev,
1761                         const struct usb_device_id *id)
1762 {
1763         struct sd *sd = (struct sd *) gspca_dev;
1764         struct cam *cam;
1765
1766         sd->bridge = id->driver_info >> 16;
1767         sd->sensor = id->driver_info >> 8;
1768         sd->flags = id->driver_info;
1769
1770         cam = &gspca_dev->cam;
1771         if (sd->sensor == SENSOR_ADCM1700) {
1772                 cam->cam_mode = cif_mode;
1773                 cam->nmodes = ARRAY_SIZE(cif_mode);
1774         } else {
1775                 cam->cam_mode = vga_mode;
1776                 cam->nmodes = ARRAY_SIZE(vga_mode);
1777         }
1778         cam->npkt = 24;                 /* 24 packets per ISOC message */
1779         cam->ctrls = sd->ctrls;
1780
1781         sd->ag_cnt = -1;
1782         sd->quality = QUALITY_DEF;
1783         sd->jpegqual = 80;
1784
1785         return 0;
1786 }
1787
1788 /* this function is called at probe and resume time */
1789 static int sd_init(struct gspca_dev *gspca_dev)
1790 {
1791         struct sd *sd = (struct sd *) gspca_dev;
1792         const u8 *sn9c1xx;
1793         u8 regGpio[] = { 0x29, 0x74 };          /* with audio */
1794         u8 regF1;
1795
1796         /* setup a selector by bridge */
1797         reg_w1(gspca_dev, 0xf1, 0x01);
1798         reg_r(gspca_dev, 0x00, 1);
1799         reg_w1(gspca_dev, 0xf1, 0x00);
1800         reg_r(gspca_dev, 0x00, 1);              /* get sonix chip id */
1801         regF1 = gspca_dev->usb_buf[0];
1802         if (gspca_dev->usb_err < 0)
1803                 return gspca_dev->usb_err;
1804         PDEBUG(D_PROBE, "Sonix chip id: %02x", regF1);
1805         switch (sd->bridge) {
1806         case BRIDGE_SN9C102P:
1807                 if (regF1 != 0x11)
1808                         return -ENODEV;
1809                 reg_w1(gspca_dev, 0x02, regGpio[1]);
1810                 break;
1811         case BRIDGE_SN9C105:
1812                 if (regF1 != 0x11)
1813                         return -ENODEV;
1814                 if (sd->sensor == SENSOR_MI0360)
1815                         mi0360_probe(gspca_dev);
1816                 reg_w(gspca_dev, 0x01, regGpio, 2);
1817                 break;
1818         case BRIDGE_SN9C120:
1819                 if (regF1 != 0x12)
1820                         return -ENODEV;
1821                 switch (sd->sensor) {
1822                 case SENSOR_MI0360:
1823                         mi0360_probe(gspca_dev);
1824                         break;
1825                 case SENSOR_OV7630:
1826                         ov7630_probe(gspca_dev);
1827                         break;
1828                 case SENSOR_OV7648:
1829                         ov7648_probe(gspca_dev);
1830                         break;
1831                 case SENSOR_PO2030N:
1832                         po2030n_probe(gspca_dev);
1833                         break;
1834                 }
1835                 regGpio[1] = 0x70;              /* no audio */
1836                 reg_w(gspca_dev, 0x01, regGpio, 2);
1837                 break;
1838         default:
1839 /*      case BRIDGE_SN9C110: */
1840 /*      case BRIDGE_SN9C325: */
1841                 if (regF1 != 0x12)
1842                         return -ENODEV;
1843                 reg_w1(gspca_dev, 0x02, 0x62);
1844                 break;
1845         }
1846
1847         if (sd->sensor == SENSOR_OM6802)
1848                 sd->ctrls[SHARPNESS].def = 0x10;
1849
1850         /* Note we do not disable the sensor clock here (power saving mode),
1851            as that also disables the button on the cam. */
1852         reg_w1(gspca_dev, 0xf1, 0x00);
1853
1854         /* set the i2c address */
1855         sn9c1xx = sn_tb[sd->sensor];
1856         sd->i2c_addr = sn9c1xx[9];
1857
1858         gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
1859
1860         return gspca_dev->usb_err;
1861 }
1862
1863 static u32 setexposure(struct gspca_dev *gspca_dev,
1864                         u32 expo)
1865 {
1866         struct sd *sd = (struct sd *) gspca_dev;
1867
1868         switch (sd->sensor) {
1869         case SENSOR_GC0307: {
1870                 int a, b;
1871
1872                 /* expo = 0..255 -> a = 19..43 */
1873                 a = 19 + expo * 25 / 256;
1874                 i2c_w1(gspca_dev, 0x68, a);
1875                 a -= 12;
1876                 b = a * a * 4;                  /* heuristic */
1877                 i2c_w1(gspca_dev, 0x03, b >> 8);
1878                 i2c_w1(gspca_dev, 0x04, b);
1879                 break;
1880             }
1881         case SENSOR_HV7131R: {
1882                 u8 Expodoit[] =
1883                         { 0xc1, 0x11, 0x25, 0x00, 0x00, 0x00, 0x00, 0x16 };
1884
1885                 Expodoit[3] = expo >> 16;
1886                 Expodoit[4] = expo >> 8;
1887                 Expodoit[5] = expo;
1888                 i2c_w8(gspca_dev, Expodoit);
1889                 break;
1890             }
1891         case SENSOR_MI0360:
1892         case SENSOR_MI0360B: {
1893                 u8 expoMi[] =           /* exposure 0x0635 -> 4 fp/s 0x10 */
1894                         { 0xb1, 0x5d, 0x09, 0x00, 0x00, 0x00, 0x00, 0x16 };
1895                 static const u8 doit[] =                /* update sensor */
1896                         { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
1897                 static const u8 sensorgo[] =            /* sensor on */
1898                         { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
1899
1900                 if (expo > 0x0635)
1901                         expo = 0x0635;
1902                 else if (expo < 0x0001)
1903                         expo = 0x0001;
1904                 expoMi[3] = expo >> 8;
1905                 expoMi[4] = expo;
1906                 i2c_w8(gspca_dev, expoMi);
1907                 i2c_w8(gspca_dev, doit);
1908                 i2c_w8(gspca_dev, sensorgo);
1909                 break;
1910             }
1911         case SENSOR_MO4000: {
1912                 u8 expoMof[] =
1913                         { 0xa1, 0x21, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x10 };
1914                 u8 expoMo10[] =
1915                         { 0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10 };
1916                 static const u8 gainMo[] =
1917                         { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
1918
1919                 if (expo > 0x1fff)
1920                         expo = 0x1fff;
1921                 else if (expo < 0x0001)
1922                         expo = 0x0001;
1923                 expoMof[3] = (expo & 0x03fc) >> 2;
1924                 i2c_w8(gspca_dev, expoMof);
1925                 expoMo10[3] = ((expo & 0x1c00) >> 10)
1926                                 | ((expo & 0x0003) << 4);
1927                 i2c_w8(gspca_dev, expoMo10);
1928                 i2c_w8(gspca_dev, gainMo);
1929                 PDEBUG(D_FRAM, "set exposure %d",
1930                         ((expoMo10[3] & 0x07) << 10)
1931                         | (expoMof[3] << 2)
1932                         | ((expoMo10[3] & 0x30) >> 4));
1933                 break;
1934             }
1935         case SENSOR_MT9V111: {
1936                 u8 expo_c1[] =
1937                         { 0xb1, 0x5c, 0x09, 0x00, 0x00, 0x00, 0x00, 0x10 };
1938
1939                 if (expo > 0x0280)
1940                         expo = 0x0280;
1941                 else if (expo < 0x0040)
1942                         expo = 0x0040;
1943                 expo_c1[3] = expo >> 8;
1944                 expo_c1[4] = expo;
1945                 i2c_w8(gspca_dev, expo_c1);
1946                 break;
1947             }
1948         case SENSOR_OM6802: {
1949                 u8 gainOm[] =
1950                         { 0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10 };
1951                                 /* preset AGC - works when AutoExpo = off */
1952
1953                 if (expo > 0x03ff)
1954                         expo = 0x03ff;
1955                  if (expo < 0x0001)
1956                         expo = 0x0001;
1957                 gainOm[3] = expo >> 2;
1958                 i2c_w8(gspca_dev, gainOm);
1959                 reg_w1(gspca_dev, 0x96, expo >> 5);
1960                 PDEBUG(D_FRAM, "set exposure %d", gainOm[3]);
1961                 break;
1962             }
1963         }
1964         return expo;
1965 }
1966
1967 static void setbrightness(struct gspca_dev *gspca_dev)
1968 {
1969         struct sd *sd = (struct sd *) gspca_dev;
1970         unsigned int expo;
1971         int brightness;
1972         u8 k2;
1973
1974         brightness = sd->ctrls[BRIGHTNESS].val;
1975         k2 = (brightness - 0x80) >> 2;
1976         switch (sd->sensor) {
1977         case SENSOR_ADCM1700:
1978                 if (k2 > 0x1f)
1979                         k2 = 0;         /* only positive Y offset */
1980                 break;
1981         case SENSOR_HV7131R:
1982                 expo = brightness << 12;
1983                 if (expo > 0x002dc6c0)
1984                         expo = 0x002dc6c0;
1985                 else if (expo < 0x02a0)
1986                         expo = 0x02a0;
1987                 sd->exposure = setexposure(gspca_dev, expo);
1988                 break;
1989         case SENSOR_MI0360:
1990         case SENSOR_MO4000:
1991                 expo = brightness << 4;
1992                 sd->exposure = setexposure(gspca_dev, expo);
1993                 break;
1994         case SENSOR_MI0360B:
1995                 expo = brightness << 2;
1996                 sd->exposure = setexposure(gspca_dev, expo);
1997                 break;
1998         case SENSOR_GC0307:
1999         case SENSOR_MT9V111:
2000                 expo = brightness;
2001                 sd->exposure = setexposure(gspca_dev, expo);
2002                 return;                 /* don't set the Y offset */
2003         case SENSOR_OM6802:
2004                 expo = brightness << 2;
2005                 sd->exposure = setexposure(gspca_dev, expo);
2006                 k2 = brightness >> 3;
2007                 break;
2008         }
2009
2010         reg_w1(gspca_dev, 0x96, k2);    /* color matrix Y offset */
2011 }
2012
2013 static void setcontrast(struct gspca_dev *gspca_dev)
2014 {
2015         struct sd *sd = (struct sd *) gspca_dev;
2016         u8 k2;
2017         u8 contrast[6];
2018
2019         k2 = sd->ctrls[CONTRAST].val * 0x30 / (CONTRAST_MAX + 1)
2020                                 + 0x10;         /* 10..40 */
2021         contrast[0] = (k2 + 1) / 2;             /* red */
2022         contrast[1] = 0;
2023         contrast[2] = k2;                       /* green */
2024         contrast[3] = 0;
2025         contrast[4] = (k2 + 1) / 5;             /* blue */
2026         contrast[5] = 0;
2027         reg_w(gspca_dev, 0x84, contrast, sizeof contrast);
2028 }
2029
2030 static void setcolors(struct gspca_dev *gspca_dev)
2031 {
2032         struct sd *sd = (struct sd *) gspca_dev;
2033         int i, v, colors;
2034         const s16 *uv;
2035         u8 reg8a[12];                   /* U & V gains */
2036         static const s16 uv_com[6] = {  /* same as reg84 in signed decimal */
2037                 -24, -38, 64,           /* UR UG UB */
2038                  62, -51, -9            /* VR VG VB */
2039         };
2040         static const s16 uv_mi0360b[6] = {
2041                 -20, -38, 64,           /* UR UG UB */
2042                  60, -51, -9            /* VR VG VB */
2043         };
2044
2045         colors = sd->ctrls[COLORS].val;
2046         if (sd->sensor == SENSOR_MI0360B)
2047                 uv = uv_mi0360b;
2048         else
2049                 uv = uv_com;
2050         for (i = 0; i < 6; i++) {
2051                 v = uv[i] * colors / COLORS_DEF;
2052                 reg8a[i * 2] = v;
2053                 reg8a[i * 2 + 1] = (v >> 8) & 0x0f;
2054         }
2055         reg_w(gspca_dev, 0x8a, reg8a, sizeof reg8a);
2056 }
2057
2058 static void setredblue(struct gspca_dev *gspca_dev)
2059 {
2060         struct sd *sd = (struct sd *) gspca_dev;
2061
2062         reg_w1(gspca_dev, 0x05, sd->ctrls[RED].val);
2063 /*      reg_w1(gspca_dev, 0x07, 32); */
2064         reg_w1(gspca_dev, 0x06, sd->ctrls[BLUE].val);
2065 }
2066
2067 static void setgamma(struct gspca_dev *gspca_dev)
2068 {
2069         struct sd *sd = (struct sd *) gspca_dev;
2070         int i, val;
2071         u8 gamma[17];
2072         const u8 *gamma_base;
2073         static const u8 delta[17] = {
2074                 0x00, 0x14, 0x1c, 0x1c, 0x1c, 0x1c, 0x1b, 0x1a,
2075                 0x18, 0x13, 0x10, 0x0e, 0x08, 0x07, 0x04, 0x02, 0x00
2076         };
2077
2078         switch (sd->sensor) {
2079         case SENSOR_ADCM1700:
2080                 gamma_base = gamma_spec_0;
2081                 break;
2082         case SENSOR_HV7131R:
2083         case SENSOR_MI0360B:
2084         case SENSOR_MT9V111:
2085                 gamma_base = gamma_spec_1;
2086                 break;
2087         case SENSOR_GC0307:
2088                 gamma_base = gamma_spec_2;
2089                 break;
2090         case SENSOR_SP80708:
2091                 gamma_base = gamma_spec_3;
2092                 break;
2093         default:
2094                 gamma_base = gamma_def;
2095                 break;
2096         }
2097
2098         val = sd->ctrls[GAMMA].val;
2099         for (i = 0; i < sizeof gamma; i++)
2100                 gamma[i] = gamma_base[i]
2101                         + delta[i] * (val - GAMMA_DEF) / 32;
2102         reg_w(gspca_dev, 0x20, gamma, sizeof gamma);
2103 }
2104
2105 static void setautogain(struct gspca_dev *gspca_dev)
2106 {
2107         struct sd *sd = (struct sd *) gspca_dev;
2108
2109         if (gspca_dev->ctrl_dis & (1 << AUTOGAIN))
2110                 return;
2111         switch (sd->sensor) {
2112         case SENSOR_OV7630:
2113         case SENSOR_OV7648: {
2114                 u8 comb;
2115
2116                 if (sd->sensor == SENSOR_OV7630)
2117                         comb = 0xc0;
2118                 else
2119                         comb = 0xa0;
2120                 if (sd->ctrls[AUTOGAIN].val)
2121                         comb |= 0x03;
2122                 i2c_w1(&sd->gspca_dev, 0x13, comb);
2123                 return;
2124             }
2125         }
2126         if (sd->ctrls[AUTOGAIN].val)
2127                 sd->ag_cnt = AG_CNT_START;
2128         else
2129                 sd->ag_cnt = -1;
2130 }
2131
2132 static void sethvflip(struct gspca_dev *gspca_dev)
2133 {
2134         struct sd *sd = (struct sd *) gspca_dev;
2135         u8 comn;
2136
2137         switch (sd->sensor) {
2138         case SENSOR_HV7131R:
2139                 comn = 0x18;                    /* clkdiv = 1, ablcen = 1 */
2140                 if (sd->ctrls[VFLIP].val)
2141                         comn |= 0x01;
2142                 i2c_w1(gspca_dev, 0x01, comn);  /* sctra */
2143                 break;
2144         case SENSOR_OV7630:
2145                 comn = 0x02;
2146                 if (!sd->ctrls[VFLIP].val)
2147                         comn |= 0x80;
2148                 i2c_w1(gspca_dev, 0x75, comn);
2149                 break;
2150         case SENSOR_OV7648:
2151                 comn = 0x06;
2152                 if (sd->ctrls[VFLIP].val)
2153                         comn |= 0x80;
2154                 i2c_w1(gspca_dev, 0x75, comn);
2155                 break;
2156         case SENSOR_PO2030N:
2157                 /* Reg. 0x1E: Timing Generator Control Register 2 (Tgcontrol2)
2158                  * (reset value: 0x0A)
2159                  * bit7: HM: Horizontal Mirror: 0: disable, 1: enable
2160                  * bit6: VM: Vertical Mirror: 0: disable, 1: enable
2161                  * bit5: ST: Shutter Selection: 0: electrical, 1: mechanical
2162                  * bit4: FT: Single Frame Transfer: 0: disable, 1: enable
2163                  * bit3-0: X
2164                  */
2165                 comn = 0x0a;
2166                 if (sd->ctrls[HFLIP].val)
2167                         comn |= 0x80;
2168                 if (sd->ctrls[VFLIP].val)
2169                         comn |= 0x40;
2170                 i2c_w1(&sd->gspca_dev, 0x1e, comn);
2171                 break;
2172         }
2173 }
2174
2175 static void setsharpness(struct gspca_dev *gspca_dev)
2176 {
2177         struct sd *sd = (struct sd *) gspca_dev;
2178
2179         reg_w1(gspca_dev, 0x99, sd->ctrls[SHARPNESS].val);
2180 }
2181
2182 static void setinfrared(struct gspca_dev *gspca_dev)
2183 {
2184         struct sd *sd = (struct sd *) gspca_dev;
2185
2186         if (gspca_dev->ctrl_dis & (1 << INFRARED))
2187                 return;
2188 /*fixme: different sequence for StarCam Clip and StarCam 370i */
2189 /* Clip */
2190         i2c_w1(gspca_dev, 0x02,                         /* gpio */
2191                 sd->ctrls[INFRARED].val ? 0x66 : 0x64);
2192 }
2193
2194 static void setfreq(struct gspca_dev *gspca_dev)
2195 {
2196         struct sd *sd = (struct sd *) gspca_dev;
2197
2198         if (gspca_dev->ctrl_dis & (1 << FREQ))
2199                 return;
2200         if (sd->sensor == SENSOR_OV7660) {
2201                 u8 com8;
2202
2203                 com8 = 0xdf;            /* auto gain/wb/expo */
2204                 switch (sd->ctrls[FREQ].val) {
2205                 case 0: /* Banding filter disabled */
2206                         i2c_w1(gspca_dev, 0x13, com8 | 0x20);
2207                         break;
2208                 case 1: /* 50 hz */
2209                         i2c_w1(gspca_dev, 0x13, com8);
2210                         i2c_w1(gspca_dev, 0x3b, 0x0a);
2211                         break;
2212                 case 2: /* 60 hz */
2213                         i2c_w1(gspca_dev, 0x13, com8);
2214                         i2c_w1(gspca_dev, 0x3b, 0x02);
2215                         break;
2216                 }
2217         } else {
2218                 u8 reg2a = 0, reg2b = 0, reg2d = 0;
2219
2220                 /* Get reg2a / reg2d base values */
2221                 switch (sd->sensor) {
2222                 case SENSOR_OV7630:
2223                         reg2a = 0x08;
2224                         reg2d = 0x01;
2225                         break;
2226                 case SENSOR_OV7648:
2227                         reg2a = 0x11;
2228                         reg2d = 0x81;
2229                         break;
2230                 }
2231
2232                 switch (sd->ctrls[FREQ].val) {
2233                 case 0: /* Banding filter disabled */
2234                         break;
2235                 case 1: /* 50 hz (filter on and framerate adj) */
2236                         reg2a |= 0x80;
2237                         reg2b = 0xac;
2238                         reg2d |= 0x04;
2239                         break;
2240                 case 2: /* 60 hz (filter on, no framerate adj) */
2241                         reg2a |= 0x80;
2242                         reg2d |= 0x04;
2243                         break;
2244                 }
2245                 i2c_w1(gspca_dev, 0x2a, reg2a);
2246                 i2c_w1(gspca_dev, 0x2b, reg2b);
2247                 i2c_w1(gspca_dev, 0x2d, reg2d);
2248         }
2249 }
2250
2251 static void setjpegqual(struct gspca_dev *gspca_dev)
2252 {
2253         struct sd *sd = (struct sd *) gspca_dev;
2254         int i, sc;
2255
2256         if (sd->jpegqual < 50)
2257                 sc = 5000 / sd->jpegqual;
2258         else
2259                 sc = 200 - sd->jpegqual * 2;
2260 #if USB_BUF_SZ < 64
2261 #error "No room enough in usb_buf for quantization table"
2262 #endif
2263         for (i = 0; i < 64; i++)
2264                 gspca_dev->usb_buf[i] =
2265                         (jpeg_head[JPEG_QT0_OFFSET + i] * sc + 50) / 100;
2266         usb_control_msg(gspca_dev->dev,
2267                         usb_sndctrlpipe(gspca_dev->dev, 0),
2268                         0x08,
2269                         USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
2270                         0x0100, 0,
2271                         gspca_dev->usb_buf, 64,
2272                         500);
2273         for (i = 0; i < 64; i++)
2274                 gspca_dev->usb_buf[i] =
2275                         (jpeg_head[JPEG_QT1_OFFSET + i] * sc + 50) / 100;
2276         usb_control_msg(gspca_dev->dev,
2277                         usb_sndctrlpipe(gspca_dev->dev, 0),
2278                         0x08,
2279                         USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
2280                         0x0140, 0,
2281                         gspca_dev->usb_buf, 64,
2282                         500);
2283
2284         sd->reg18 ^= 0x40;
2285         reg_w1(gspca_dev, 0x18, sd->reg18);
2286 }
2287
2288 /* -- start the camera -- */
2289 static int sd_start(struct gspca_dev *gspca_dev)
2290 {
2291         struct sd *sd = (struct sd *) gspca_dev;
2292         int i;
2293         u8 reg0102[2];
2294         u8 reg1, reg17;
2295         const u8 *sn9c1xx;
2296         const u8 (*init)[8];
2297         const u8 *reg9a;
2298         int mode;
2299         static const u8 reg9a_def[] =
2300                 {0x00, 0x40, 0x20, 0x00, 0x00, 0x00};
2301         static const u8 reg9a_spec[] =
2302                 {0x00, 0x40, 0x38, 0x30, 0x00, 0x20};
2303         static const u8 regd4[] = {0x60, 0x00, 0x00};
2304         static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
2305         static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
2306         static const u8 CA_adcm1700[] =
2307                                 { 0x14, 0xec, 0x0a, 0xf6 };
2308         static const u8 CA_po2030n[] =
2309                                 { 0x1e, 0xe2, 0x14, 0xec };
2310         static const u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd };      /* MI0360 */
2311         static const u8 CE_gc0307[] =
2312                                 { 0x32, 0xce, 0x2d, 0xd3 };
2313         static const u8 CE_ov76xx[] =
2314                                 { 0x32, 0xdd, 0x32, 0xdd };
2315         static const u8 CE_po2030n[] =
2316                                 { 0x14, 0xe7, 0x1e, 0xdd };
2317
2318         /* create the JPEG header */
2319         jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
2320                         0x21);          /* JPEG 422 */
2321         jpeg_set_qual(sd->jpeg_hdr, sd->quality);
2322
2323         /* initialize the bridge */
2324         sn9c1xx = sn_tb[sd->sensor];
2325
2326         /* sensor clock already enabled in sd_init */
2327         /* reg_w1(gspca_dev, 0xf1, 0x00); */
2328         reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
2329
2330         /* configure gpio */
2331         reg0102[0] = sn9c1xx[1];
2332         reg0102[1] = sn9c1xx[2];
2333         if (gspca_dev->audio)
2334                 reg0102[1] |= 0x04;     /* keep the audio connection */
2335         reg_w(gspca_dev, 0x01, reg0102, 2);
2336         reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
2337         reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5);
2338         switch (sd->sensor) {
2339         case SENSOR_GC0307:
2340         case SENSOR_OV7660:
2341         case SENSOR_PO1030:
2342         case SENSOR_PO2030N:
2343         case SENSOR_SOI768:
2344         case SENSOR_SP80708:
2345                 reg9a = reg9a_spec;
2346                 break;
2347         default:
2348                 reg9a = reg9a_def;
2349                 break;
2350         }
2351         reg_w(gspca_dev, 0x9a, reg9a, 6);
2352
2353         reg_w(gspca_dev, 0xd4, regd4, sizeof regd4);
2354
2355         reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
2356
2357         switch (sd->sensor) {
2358         case SENSOR_ADCM1700:
2359                 reg_w1(gspca_dev, 0x01, 0x43);
2360                 reg_w1(gspca_dev, 0x17, 0x62);
2361                 reg_w1(gspca_dev, 0x01, 0x42);
2362                 reg_w1(gspca_dev, 0x01, 0x42);
2363                 break;
2364         case SENSOR_GC0307:
2365                 msleep(50);
2366                 reg_w1(gspca_dev, 0x01, 0x61);
2367                 reg_w1(gspca_dev, 0x17, 0x22);
2368                 reg_w1(gspca_dev, 0x01, 0x60);
2369                 reg_w1(gspca_dev, 0x01, 0x40);
2370                 msleep(50);
2371                 break;
2372         case SENSOR_MI0360B:
2373                 reg_w1(gspca_dev, 0x01, 0x61);
2374                 reg_w1(gspca_dev, 0x17, 0x60);
2375                 reg_w1(gspca_dev, 0x01, 0x60);
2376                 reg_w1(gspca_dev, 0x01, 0x40);
2377                 break;
2378         case SENSOR_MT9V111:
2379                 reg_w1(gspca_dev, 0x01, 0x61);
2380                 reg_w1(gspca_dev, 0x17, 0x61);
2381                 reg_w1(gspca_dev, 0x01, 0x60);
2382                 reg_w1(gspca_dev, 0x01, 0x40);
2383                 break;
2384         case SENSOR_OM6802:
2385                 msleep(10);
2386                 reg_w1(gspca_dev, 0x02, 0x73);
2387                 reg_w1(gspca_dev, 0x17, 0x60);
2388                 reg_w1(gspca_dev, 0x01, 0x22);
2389                 msleep(100);
2390                 reg_w1(gspca_dev, 0x01, 0x62);
2391                 reg_w1(gspca_dev, 0x17, 0x64);
2392                 reg_w1(gspca_dev, 0x17, 0x64);
2393                 reg_w1(gspca_dev, 0x01, 0x42);
2394                 msleep(10);
2395                 reg_w1(gspca_dev, 0x01, 0x42);
2396                 i2c_w8(gspca_dev, om6802_init0[0]);
2397                 i2c_w8(gspca_dev, om6802_init0[1]);
2398                 msleep(15);
2399                 reg_w1(gspca_dev, 0x02, 0x71);
2400                 msleep(150);
2401                 break;
2402         case SENSOR_OV7630:
2403                 reg_w1(gspca_dev, 0x01, 0x61);
2404                 reg_w1(gspca_dev, 0x17, 0xe2);
2405                 reg_w1(gspca_dev, 0x01, 0x60);
2406                 reg_w1(gspca_dev, 0x01, 0x40);
2407                 break;
2408         case SENSOR_OV7648:
2409                 reg_w1(gspca_dev, 0x01, 0x63);
2410                 reg_w1(gspca_dev, 0x17, 0x20);
2411                 reg_w1(gspca_dev, 0x01, 0x62);
2412                 reg_w1(gspca_dev, 0x01, 0x42);
2413                 break;
2414         case SENSOR_PO1030:
2415         case SENSOR_SOI768:
2416                 reg_w1(gspca_dev, 0x01, 0x61);
2417                 reg_w1(gspca_dev, 0x17, 0x20);
2418                 reg_w1(gspca_dev, 0x01, 0x60);
2419                 reg_w1(gspca_dev, 0x01, 0x40);
2420                 break;
2421         case SENSOR_PO2030N:
2422         case SENSOR_OV7660:
2423                 reg_w1(gspca_dev, 0x01, 0x63);
2424                 reg_w1(gspca_dev, 0x17, 0x20);
2425                 reg_w1(gspca_dev, 0x01, 0x62);
2426                 reg_w1(gspca_dev, 0x01, 0x42);
2427                 break;
2428         case SENSOR_SP80708:
2429                 reg_w1(gspca_dev, 0x01, 0x63);
2430                 reg_w1(gspca_dev, 0x17, 0x20);
2431                 reg_w1(gspca_dev, 0x01, 0x62);
2432                 reg_w1(gspca_dev, 0x01, 0x42);
2433                 msleep(100);
2434                 reg_w1(gspca_dev, 0x02, 0x62);
2435                 break;
2436         default:
2437 /*      case SENSOR_HV7131R: */
2438 /*      case SENSOR_MI0360: */
2439 /*      case SENSOR_MO4000: */
2440                 reg_w1(gspca_dev, 0x01, 0x43);
2441                 reg_w1(gspca_dev, 0x17, 0x61);
2442                 reg_w1(gspca_dev, 0x01, 0x42);
2443                 if (sd->sensor == SENSOR_HV7131R)
2444                         hv7131r_probe(gspca_dev);
2445                 break;
2446         }
2447
2448         /* initialize the sensor */
2449         i2c_w_seq(gspca_dev, sensor_init[sd->sensor]);
2450
2451         reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]);
2452         reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]);
2453         reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
2454         reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]);
2455         reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
2456         if (sd->sensor == SENSOR_ADCM1700) {
2457                 reg_w1(gspca_dev, 0xd2, 0x3a);  /* AE_H_SIZE = 116 */
2458                 reg_w1(gspca_dev, 0xd3, 0x30);  /* AE_V_SIZE = 96 */
2459         } else {
2460                 reg_w1(gspca_dev, 0xd2, 0x6a);  /* AE_H_SIZE = 212 */
2461                 reg_w1(gspca_dev, 0xd3, 0x50);  /* AE_V_SIZE = 160 */
2462         }
2463         reg_w1(gspca_dev, 0xc6, 0x00);
2464         reg_w1(gspca_dev, 0xc7, 0x00);
2465         if (sd->sensor == SENSOR_ADCM1700) {
2466                 reg_w1(gspca_dev, 0xc8, 0x2c);  /* AW_H_STOP = 352 */
2467                 reg_w1(gspca_dev, 0xc9, 0x24);  /* AW_V_STOP = 288 */
2468         } else {
2469                 reg_w1(gspca_dev, 0xc8, 0x50);  /* AW_H_STOP = 640 */
2470                 reg_w1(gspca_dev, 0xc9, 0x3c);  /* AW_V_STOP = 480 */
2471         }
2472         reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
2473         switch (sd->sensor) {
2474         case SENSOR_GC0307:
2475                 reg17 = 0xa2;
2476                 break;
2477         case SENSOR_MT9V111:
2478         case SENSOR_MI0360B:
2479                 reg17 = 0xe0;
2480                 break;
2481         case SENSOR_ADCM1700:
2482         case SENSOR_OV7630:
2483                 reg17 = 0xe2;
2484                 break;
2485         case SENSOR_OV7648:
2486                 reg17 = 0x20;
2487                 break;
2488         case SENSOR_OV7660:
2489         case SENSOR_SOI768:
2490                 reg17 = 0xa0;
2491                 break;
2492         case SENSOR_PO1030:
2493         case SENSOR_PO2030N:
2494                 reg17 = 0xa0;
2495                 break;
2496         default:
2497                 reg17 = 0x60;
2498                 break;
2499         }
2500         reg_w1(gspca_dev, 0x17, reg17);
2501
2502         reg_w1(gspca_dev, 0x05, 0x00);          /* red */
2503         reg_w1(gspca_dev, 0x07, 0x00);          /* green */
2504         reg_w1(gspca_dev, 0x06, 0x00);          /* blue */
2505         reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
2506
2507         setgamma(gspca_dev);
2508
2509 /*fixme: 8 times with all zeroes and 1 or 2 times with normal values */
2510         for (i = 0; i < 8; i++)
2511                 reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
2512         switch (sd->sensor) {
2513         case SENSOR_ADCM1700:
2514         case SENSOR_OV7660:
2515         case SENSOR_SP80708:
2516                 reg_w1(gspca_dev, 0x9a, 0x05);
2517                 break;
2518         case SENSOR_GC0307:
2519         case SENSOR_MT9V111:
2520         case SENSOR_MI0360B:
2521                 reg_w1(gspca_dev, 0x9a, 0x07);
2522                 break;
2523         case SENSOR_OV7630:
2524         case SENSOR_OV7648:
2525                 reg_w1(gspca_dev, 0x9a, 0x0a);
2526                 break;
2527         case SENSOR_PO2030N:
2528         case SENSOR_SOI768:
2529                 reg_w1(gspca_dev, 0x9a, 0x06);
2530                 break;
2531         default:
2532                 reg_w1(gspca_dev, 0x9a, 0x08);
2533                 break;
2534         }
2535         setsharpness(gspca_dev);
2536
2537         reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
2538         reg_w1(gspca_dev, 0x05, 0x20);          /* red */
2539         reg_w1(gspca_dev, 0x07, 0x20);          /* green */
2540         reg_w1(gspca_dev, 0x06, 0x20);          /* blue */
2541
2542         init = NULL;
2543         mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
2544         if (mode)
2545                 reg1 = 0x46;    /* 320x240: clk 48Mhz, video trf enable */
2546         else
2547                 reg1 = 0x06;    /* 640x480: clk 24Mhz, video trf enable */
2548         reg17 = 0x61;           /* 0x:20: enable sensor clock */
2549         switch (sd->sensor) {
2550         case SENSOR_ADCM1700:
2551                 init = adcm1700_sensor_param1;
2552                 reg1 = 0x46;
2553                 reg17 = 0xe2;
2554                 break;
2555         case SENSOR_GC0307:
2556                 init = gc0307_sensor_param1;
2557                 reg17 = 0xa2;
2558                 reg1 = 0x44;
2559                 break;
2560         case SENSOR_MI0360B:
2561                 init = mi0360b_sensor_param1;
2562                 reg1 &= ~0x02;          /* don't inverse pin S_PWR_DN */
2563                 reg17 = 0xe2;
2564                 break;
2565         case SENSOR_MO4000:
2566                 if (mode) {
2567 /*                      reg1 = 0x46;     * 320 clk 48Mhz 60fp/s */
2568                         reg1 = 0x06;    /* clk 24Mz */
2569                 } else {
2570                         reg17 = 0x22;   /* 640 MCKSIZE */
2571 /*                      reg1 = 0x06;     * 640 clk 24Mz (done) */
2572                 }
2573                 break;
2574         case SENSOR_MT9V111:
2575                 init = mt9v111_sensor_param1;
2576                 if (mode) {
2577                         reg1 = 0x04;    /* 320 clk 48Mhz */
2578                 } else {
2579 /*                      reg1 = 0x06;     * 640 clk 24Mz (done) */
2580                         reg17 = 0xc2;
2581                 }
2582                 break;
2583         case SENSOR_OM6802:
2584                 init = om6802_sensor_param1;
2585                 reg17 = 0x64;           /* 640 MCKSIZE */
2586                 break;
2587         case SENSOR_OV7630:
2588                 init = ov7630_sensor_param1;
2589                 reg17 = 0xe2;
2590                 reg1 = 0x44;
2591                 break;
2592         case SENSOR_OV7648:
2593                 init = ov7648_sensor_param1;
2594                 reg17 = 0x21;
2595 /*              reg1 = 0x42;             * 42 - 46? */
2596                 break;
2597         case SENSOR_OV7660:
2598                 init = ov7660_sensor_param1;
2599                 if (sd->bridge == BRIDGE_SN9C120) {
2600                         if (mode) {             /* 320x240 - 160x120 */
2601                                 reg17 = 0xa2;
2602                                 reg1 = 0x44;    /* 48 Mhz, video trf eneble */
2603                         }
2604                 } else {
2605                         reg17 = 0x22;
2606                         reg1 = 0x06;    /* 24 Mhz, video trf eneble
2607                                          * inverse power down */
2608                 }
2609                 break;
2610         case SENSOR_PO1030:
2611                 init = po1030_sensor_param1;
2612                 reg17 = 0xa2;
2613                 reg1 = 0x44;
2614                 break;
2615         case SENSOR_PO2030N:
2616                 init = po2030n_sensor_param1;
2617                 reg1 = 0x46;
2618                 reg17 = 0xa2;
2619                 break;
2620         case SENSOR_SOI768:
2621                 init = soi768_sensor_param1;
2622                 reg1 = 0x44;
2623                 reg17 = 0xa2;
2624                 break;
2625         case SENSOR_SP80708:
2626                 init = sp80708_sensor_param1;
2627                 if (mode) {
2628 /*??                    reg1 = 0x04;     * 320 clk 48Mhz */
2629                 } else {
2630                         reg1 = 0x46;     /* 640 clk 48Mz */
2631                         reg17 = 0xa2;
2632                 }
2633                 break;
2634         }
2635
2636         /* more sensor initialization - param1 */
2637         if (init != NULL) {
2638                 i2c_w_seq(gspca_dev, init);
2639 /*              init = NULL; */
2640         }
2641
2642         reg_w(gspca_dev, 0xc0, C0, 6);
2643         switch (sd->sensor) {
2644         case SENSOR_ADCM1700:
2645         case SENSOR_GC0307:
2646         case SENSOR_SOI768:
2647                 reg_w(gspca_dev, 0xca, CA_adcm1700, 4);
2648                 break;
2649         case SENSOR_PO2030N:
2650                 reg_w(gspca_dev, 0xca, CA_po2030n, 4);
2651                 break;
2652         default:
2653                 reg_w(gspca_dev, 0xca, CA, 4);
2654                 break;
2655         }
2656         switch (sd->sensor) {
2657         case SENSOR_ADCM1700:
2658         case SENSOR_OV7630:
2659         case SENSOR_OV7648:
2660         case SENSOR_OV7660:
2661         case SENSOR_SOI768:
2662                 reg_w(gspca_dev, 0xce, CE_ov76xx, 4);
2663                 break;
2664         case SENSOR_GC0307:
2665                 reg_w(gspca_dev, 0xce, CE_gc0307, 4);
2666                 break;
2667         case SENSOR_PO2030N:
2668                 reg_w(gspca_dev, 0xce, CE_po2030n, 4);
2669                 break;
2670         default:
2671                 reg_w(gspca_dev, 0xce, CE, 4);
2672                                         /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */
2673                 break;
2674         }
2675
2676         /* here change size mode 0 -> VGA; 1 -> CIF */
2677         sd->reg18 = sn9c1xx[0x18] | (mode << 4) | 0x40;
2678         reg_w1(gspca_dev, 0x18, sd->reg18);
2679         setjpegqual(gspca_dev);
2680
2681         reg_w1(gspca_dev, 0x17, reg17);
2682         reg_w1(gspca_dev, 0x01, reg1);
2683
2684         sethvflip(gspca_dev);
2685         setbrightness(gspca_dev);
2686         setcontrast(gspca_dev);
2687         setcolors(gspca_dev);
2688         setautogain(gspca_dev);
2689         setfreq(gspca_dev);
2690         return gspca_dev->usb_err;
2691 }
2692
2693 static void sd_stopN(struct gspca_dev *gspca_dev)
2694 {
2695         struct sd *sd = (struct sd *) gspca_dev;
2696         static const u8 stophv7131[] =
2697                 { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
2698         static const u8 stopmi0360[] =
2699                 { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
2700         static const u8 stopov7648[] =
2701                 { 0xa1, 0x21, 0x76, 0x20, 0x00, 0x00, 0x00, 0x10 };
2702         static const u8 stopsoi768[] =
2703                 { 0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10 };
2704         u8 data;
2705         const u8 *sn9c1xx;
2706
2707         data = 0x0b;
2708         switch (sd->sensor) {
2709         case SENSOR_GC0307:
2710                 data = 0x29;
2711                 break;
2712         case SENSOR_HV7131R:
2713                 i2c_w8(gspca_dev, stophv7131);
2714                 data = 0x2b;
2715                 break;
2716         case SENSOR_MI0360:
2717         case SENSOR_MI0360B:
2718                 i2c_w8(gspca_dev, stopmi0360);
2719                 data = 0x29;
2720                 break;
2721         case SENSOR_OV7648:
2722                 i2c_w8(gspca_dev, stopov7648);
2723                 /* fall thru */
2724         case SENSOR_MT9V111:
2725         case SENSOR_OV7630:
2726         case SENSOR_PO1030:
2727                 data = 0x29;
2728                 break;
2729         case SENSOR_SOI768:
2730                 i2c_w8(gspca_dev, stopsoi768);
2731                 data = 0x29;
2732                 break;
2733         }
2734         sn9c1xx = sn_tb[sd->sensor];
2735         reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
2736         reg_w1(gspca_dev, 0x17, sn9c1xx[0x17]);
2737         reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
2738         reg_w1(gspca_dev, 0x01, data);
2739         /* Don't disable sensor clock as that disables the button on the cam */
2740         /* reg_w1(gspca_dev, 0xf1, 0x01); */
2741 }
2742
2743 static void do_autogain(struct gspca_dev *gspca_dev)
2744 {
2745         struct sd *sd = (struct sd *) gspca_dev;
2746         int delta;
2747         int expotimes;
2748         u8 luma_mean = 130;
2749         u8 luma_delta = 20;
2750
2751         /* Thanks S., without your advice, autobright should not work :) */
2752         if (sd->ag_cnt < 0)
2753                 return;
2754         if (--sd->ag_cnt >= 0)
2755                 return;
2756         sd->ag_cnt = AG_CNT_START;
2757
2758         delta = atomic_read(&sd->avg_lum);
2759         PDEBUG(D_FRAM, "mean lum %d", delta);
2760         if (delta < luma_mean - luma_delta ||
2761             delta > luma_mean + luma_delta) {
2762                 switch (sd->sensor) {
2763                 case SENSOR_GC0307:
2764                         expotimes = sd->exposure;
2765                         expotimes += (luma_mean - delta) >> 6;
2766                         if (expotimes < 0)
2767                                 expotimes = 0;
2768                         sd->exposure = setexposure(gspca_dev,
2769                                                    (unsigned int) expotimes);
2770                         break;
2771                 case SENSOR_HV7131R:
2772                         expotimes = sd->exposure >> 8;
2773                         expotimes += (luma_mean - delta) >> 4;
2774                         if (expotimes < 0)
2775                                 expotimes = 0;
2776                         sd->exposure = setexposure(gspca_dev,
2777                                         (unsigned int) (expotimes << 8));
2778                         break;
2779                 case SENSOR_OM6802:
2780                         expotimes = sd->exposure;
2781                         expotimes += (luma_mean - delta) >> 2;
2782                         if (expotimes < 0)
2783                                 expotimes = 0;
2784                         sd->exposure = setexposure(gspca_dev,
2785                                                    (unsigned int) expotimes);
2786                         setredblue(gspca_dev);
2787                         break;
2788                 default:
2789 /*              case SENSOR_MO4000: */
2790 /*              case SENSOR_MI0360: */
2791 /*              case SENSOR_MI0360B: */
2792 /*              case SENSOR_MT9V111: */
2793                         expotimes = sd->exposure;
2794                         expotimes += (luma_mean - delta) >> 6;
2795                         if (expotimes < 0)
2796                                 expotimes = 0;
2797                         sd->exposure = setexposure(gspca_dev,
2798                                                    (unsigned int) expotimes);
2799                         setredblue(gspca_dev);
2800                         break;
2801                 }
2802         }
2803 }
2804
2805 /* scan the URB packets */
2806 /* This function is run at interrupt level. */
2807 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
2808                         u8 *data,                       /* isoc packet */
2809                         int len)                        /* iso packet length */
2810 {
2811         struct sd *sd = (struct sd *) gspca_dev;
2812         int sof, avg_lum;
2813
2814         /* the image ends on a 64 bytes block starting with
2815          *      ff d9 ff ff 00 c4 c4 96
2816          * and followed by various information including luminosity */
2817         /* this block may be splitted between two packets */
2818         /* a new image always starts in a new packet */
2819         switch (gspca_dev->last_packet_type) {
2820         case DISCARD_PACKET:            /* restart image building */
2821                 sof = len - 64;
2822                 if (sof >= 0 && data[sof] == 0xff && data[sof + 1] == 0xd9)
2823                         gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
2824                 return;
2825         case LAST_PACKET:               /* put the JPEG 422 header */
2826                 gspca_frame_add(gspca_dev, FIRST_PACKET,
2827                                 sd->jpeg_hdr, JPEG_HDR_SZ);
2828                 break;
2829         }
2830         gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
2831
2832         data = gspca_dev->image;
2833         if (data == NULL)
2834                 return;
2835         sof = gspca_dev->image_len - 64;
2836         if (data[sof] != 0xff
2837          || data[sof + 1] != 0xd9)
2838                 return;
2839
2840         /* end of image found - remove the trailing data */
2841         gspca_dev->image_len = sof + 2;
2842         gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
2843         if (sd->ag_cnt < 0)
2844                 return;
2845 /* w1 w2 w3 */
2846 /* w4 w5 w6 */
2847 /* w7 w8 */
2848 /* w4 */
2849         avg_lum = ((data[sof + 29] << 8) | data[sof + 30]) >> 6;
2850 /* w6 */
2851         avg_lum += ((data[sof + 33] << 8) | data[sof + 34]) >> 6;
2852 /* w2 */
2853         avg_lum += ((data[sof + 25] << 8) | data[sof + 26]) >> 6;
2854 /* w8 */
2855         avg_lum += ((data[sof + 37] << 8) | data[sof + 38]) >> 6;
2856 /* w5 */
2857         avg_lum += ((data[sof + 31] << 8) | data[sof + 32]) >> 4;
2858         avg_lum >>= 4;
2859         atomic_set(&sd->avg_lum, avg_lum);
2860 }
2861
2862 static int sd_set_jcomp(struct gspca_dev *gspca_dev,
2863                         struct v4l2_jpegcompression *jcomp)
2864 {
2865         struct sd *sd = (struct sd *) gspca_dev;
2866
2867         if (jcomp->quality < QUALITY_MIN)
2868                 sd->quality = QUALITY_MIN;
2869         else if (jcomp->quality > QUALITY_MAX)
2870                 sd->quality = QUALITY_MAX;
2871         else
2872                 sd->quality = jcomp->quality;
2873         if (gspca_dev->streaming)
2874                 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
2875         return 0;
2876 }
2877
2878 static int sd_get_jcomp(struct gspca_dev *gspca_dev,
2879                         struct v4l2_jpegcompression *jcomp)
2880 {
2881         struct sd *sd = (struct sd *) gspca_dev;
2882
2883         memset(jcomp, 0, sizeof *jcomp);
2884         jcomp->quality = sd->quality;
2885         jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
2886                         | V4L2_JPEG_MARKER_DQT;
2887         return 0;
2888 }
2889
2890 static int sd_querymenu(struct gspca_dev *gspca_dev,
2891                         struct v4l2_querymenu *menu)
2892 {
2893         switch (menu->id) {
2894         case V4L2_CID_POWER_LINE_FREQUENCY:
2895                 switch (menu->index) {
2896                 case 0:         /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
2897                         strcpy((char *) menu->name, "NoFliker");
2898                         return 0;
2899                 case 1:         /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
2900                         strcpy((char *) menu->name, "50 Hz");
2901                         return 0;
2902                 case 2:         /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
2903                         strcpy((char *) menu->name, "60 Hz");
2904                         return 0;
2905                 }
2906                 break;
2907         }
2908         return -EINVAL;
2909 }
2910
2911 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
2912 static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
2913                         u8 *data,               /* interrupt packet data */
2914                         int len)                /* interrupt packet length */
2915 {
2916         int ret = -EINVAL;
2917
2918         if (len == 1 && data[0] == 1) {
2919                 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
2920                 input_sync(gspca_dev->input_dev);
2921                 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
2922                 input_sync(gspca_dev->input_dev);
2923                 ret = 0;
2924         }
2925
2926         return ret;
2927 }
2928 #endif
2929
2930 /* sub-driver description */
2931 static const struct sd_desc sd_desc = {
2932         .name = MODULE_NAME,
2933         .ctrls = sd_ctrls,
2934         .nctrls = NCTRLS,
2935         .config = sd_config,
2936         .init = sd_init,
2937         .start = sd_start,
2938         .stopN = sd_stopN,
2939         .pkt_scan = sd_pkt_scan,
2940         .dq_callback = do_autogain,
2941         .get_jcomp = sd_get_jcomp,
2942         .set_jcomp = sd_set_jcomp,
2943         .querymenu = sd_querymenu,
2944 #if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
2945         .int_pkt_scan = sd_int_pkt_scan,
2946 #endif
2947 };
2948
2949 /* -- module initialisation -- */
2950 #define BS(bridge, sensor) \
2951         .driver_info = (BRIDGE_ ## bridge << 16) \
2952                         | (SENSOR_ ## sensor << 8)
2953 #define BSF(bridge, sensor, flags) \
2954         .driver_info = (BRIDGE_ ## bridge << 16) \
2955                         | (SENSOR_ ## sensor << 8) \
2956                         | (flags)
2957 static const __devinitdata struct usb_device_id device_table[] = {
2958 #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
2959         {USB_DEVICE(0x0458, 0x7025), BS(SN9C120, MI0360)},
2960         {USB_DEVICE(0x0458, 0x702e), BS(SN9C120, OV7660)},
2961 #endif
2962         {USB_DEVICE(0x045e, 0x00f5), BS(SN9C105, OV7660)},
2963         {USB_DEVICE(0x045e, 0x00f7), BS(SN9C105, OV7660)},
2964         {USB_DEVICE(0x0471, 0x0327), BS(SN9C105, MI0360)},
2965         {USB_DEVICE(0x0471, 0x0328), BS(SN9C105, MI0360)},
2966         {USB_DEVICE(0x0471, 0x0330), BS(SN9C105, MI0360)},
2967         {USB_DEVICE(0x06f8, 0x3004), BS(SN9C105, OV7660)},
2968         {USB_DEVICE(0x06f8, 0x3008), BS(SN9C105, OV7660)},
2969 /*      {USB_DEVICE(0x0c45, 0x603a), BS(SN9C102P, OV7648)}, */
2970         {USB_DEVICE(0x0c45, 0x6040), BS(SN9C102P, HV7131R)},
2971 /*      {USB_DEVICE(0x0c45, 0x607a), BS(SN9C102P, OV7648)}, */
2972 /*      {USB_DEVICE(0x0c45, 0x607b), BS(SN9C102P, OV7660)}, */
2973         {USB_DEVICE(0x0c45, 0x607c), BS(SN9C102P, HV7131R)},
2974 /*      {USB_DEVICE(0x0c45, 0x607e), BS(SN9C102P, OV7630)}, */
2975         {USB_DEVICE(0x0c45, 0x60c0), BS(SN9C105, MI0360)},
2976                                                 /* or MT9V111 */
2977 /*      {USB_DEVICE(0x0c45, 0x60c2), BS(SN9C105, P1030xC)}, */
2978 /*      {USB_DEVICE(0x0c45, 0x60c8), BS(SN9C105, OM6802)}, */
2979 /*      {USB_DEVICE(0x0c45, 0x60cc), BS(SN9C105, HV7131GP)}, */
2980         {USB_DEVICE(0x0c45, 0x60ce), BS(SN9C105, SP80708)},
2981         {USB_DEVICE(0x0c45, 0x60ec), BS(SN9C105, MO4000)},
2982 /*      {USB_DEVICE(0x0c45, 0x60ef), BS(SN9C105, ICM105C)}, */
2983 /*      {USB_DEVICE(0x0c45, 0x60fa), BS(SN9C105, OV7648)}, */
2984 /*      {USB_DEVICE(0x0c45, 0x60f2), BS(SN9C105, OV7660)}, */
2985         {USB_DEVICE(0x0c45, 0x60fb), BS(SN9C105, OV7660)},
2986 #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
2987         {USB_DEVICE(0x0c45, 0x60fc), BS(SN9C105, HV7131R)},
2988         {USB_DEVICE(0x0c45, 0x60fe), BS(SN9C105, OV7630)},
2989 #endif
2990         {USB_DEVICE(0x0c45, 0x6100), BS(SN9C120, MI0360)},      /*sn9c128*/
2991         {USB_DEVICE(0x0c45, 0x6102), BS(SN9C120, PO2030N)},     /* /GC0305*/
2992 /*      {USB_DEVICE(0x0c45, 0x6108), BS(SN9C120, OM6802)}, */
2993         {USB_DEVICE(0x0c45, 0x610a), BS(SN9C120, OV7648)},      /*sn9c128*/
2994         {USB_DEVICE(0x0c45, 0x610b), BS(SN9C120, OV7660)},      /*sn9c128*/
2995         {USB_DEVICE(0x0c45, 0x610c), BS(SN9C120, HV7131R)},     /*sn9c128*/
2996         {USB_DEVICE(0x0c45, 0x610e), BS(SN9C120, OV7630)},      /*sn9c128*/
2997 /*      {USB_DEVICE(0x0c45, 0x610f), BS(SN9C120, S5K53BEB)}, */
2998 /*      {USB_DEVICE(0x0c45, 0x6122), BS(SN9C110, ICM105C)}, */
2999 /*      {USB_DEVICE(0x0c45, 0x6123), BS(SN9C110, SanyoCCD)}, */
3000         {USB_DEVICE(0x0c45, 0x6128), BS(SN9C120, OM6802)},      /*sn9c325?*/
3001 /*bw600.inf:*/
3002         {USB_DEVICE(0x0c45, 0x612a), BS(SN9C120, OV7648)},      /*sn9c325?*/
3003         {USB_DEVICE(0x0c45, 0x612b), BS(SN9C110, ADCM1700)},
3004         {USB_DEVICE(0x0c45, 0x612c), BS(SN9C110, MO4000)},
3005         {USB_DEVICE(0x0c45, 0x612e), BS(SN9C110, OV7630)},
3006 /*      {USB_DEVICE(0x0c45, 0x612f), BS(SN9C110, ICM105C)}, */
3007         {USB_DEVICE(0x0c45, 0x6130), BS(SN9C120, MI0360)},
3008                                                 /* or MT9V111 / MI0360B */
3009 /*      {USB_DEVICE(0x0c45, 0x6132), BS(SN9C120, OV7670)}, */
3010         {USB_DEVICE(0x0c45, 0x6138), BS(SN9C120, MO4000)},
3011         {USB_DEVICE(0x0c45, 0x613a), BS(SN9C120, OV7648)},
3012 #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
3013         {USB_DEVICE(0x0c45, 0x613b), BS(SN9C120, OV7660)},
3014 #endif
3015         {USB_DEVICE(0x0c45, 0x613c), BS(SN9C120, HV7131R)},
3016         {USB_DEVICE(0x0c45, 0x613e), BS(SN9C120, OV7630)},
3017         {USB_DEVICE(0x0c45, 0x6142), BS(SN9C120, PO2030N)},     /*sn9c120b*/
3018                                                 /* or GC0305 / GC0307 */
3019         {USB_DEVICE(0x0c45, 0x6143), BS(SN9C120, SP80708)},     /*sn9c120b*/
3020         {USB_DEVICE(0x0c45, 0x6148), BS(SN9C120, OM6802)},      /*sn9c120b*/
3021         {USB_DEVICE(0x0c45, 0x614a), BS(SN9C120, ADCM1700)},    /*sn9c120b*/
3022         {}
3023 };
3024 MODULE_DEVICE_TABLE(usb, device_table);
3025
3026 /* -- device connect -- */
3027 static int sd_probe(struct usb_interface *intf,
3028                     const struct usb_device_id *id)
3029 {
3030         return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
3031                                 THIS_MODULE);
3032 }
3033
3034 static struct usb_driver sd_driver = {
3035         .name = MODULE_NAME,
3036         .id_table = device_table,
3037         .probe = sd_probe,
3038         .disconnect = gspca_disconnect,
3039 #ifdef CONFIG_PM
3040         .suspend = gspca_suspend,
3041         .resume = gspca_resume,
3042 #endif
3043 };
3044
3045 /* -- module insert / remove -- */
3046 static int __init sd_mod_init(void)
3047 {
3048         return usb_register(&sd_driver);
3049 }
3050 static void __exit sd_mod_exit(void)
3051 {
3052         usb_deregister(&sd_driver);
3053 }
3054
3055 module_init(sd_mod_init);
3056 module_exit(sd_mod_exit);