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