V4L/DVB (12086): gspca_sonixj: Fix control index numbering
[linux-2.6] / drivers / media / video / gspca / sonixj.c
1 /*
2  *              Sonix sn9c102p sn9c105 sn9c120 (jpeg) library
3  *              Copyright (C) 2005 Michel Xhaard mxhaard@magic.fr
4  *
5  * V4L2 by Jean-Francois Moine <http://moinejf.free.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 "gspca.h"
25 #include "jpeg.h"
26
27 #define V4L2_CID_INFRARED (V4L2_CID_PRIVATE_BASE + 0)
28
29 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
30 MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
31 MODULE_LICENSE("GPL");
32
33 /* specific webcam descriptor */
34 struct sd {
35         struct gspca_dev gspca_dev;     /* !! must be the first item */
36
37         atomic_t avg_lum;
38         u32 exposure;
39
40         u16 brightness;
41         u8 contrast;
42         u8 colors;
43         u8 autogain;
44         u8 blue;
45         u8 red;
46         u8 gamma;
47         u8 vflip;                       /* ov7630/ov7648 only */
48         u8 infrared;                    /* mt9v111 only */
49         u8 quality;                     /* image quality */
50 #define QUALITY_MIN 60
51 #define QUALITY_MAX 95
52 #define QUALITY_DEF 80
53         u8 jpegqual;                    /* webcam quality */
54
55         u8 reg18;
56
57         s8 ag_cnt;
58 #define AG_CNT_START 13
59
60         u8 bridge;
61 #define BRIDGE_SN9C102P 0
62 #define BRIDGE_SN9C105 1
63 #define BRIDGE_SN9C110 2
64 #define BRIDGE_SN9C120 3
65         u8 sensor;                      /* Type of image sensor chip */
66 #define SENSOR_HV7131R 0
67 #define SENSOR_MI0360 1
68 #define SENSOR_MO4000 2
69 #define SENSOR_MT9V111 3
70 #define SENSOR_OM6802 4
71 #define SENSOR_OV7630 5
72 #define SENSOR_OV7648 6
73 #define SENSOR_OV7660 7
74 #define SENSOR_SP80708 8
75         u8 i2c_base;
76
77         u8 *jpeg_hdr;
78 };
79
80 /* V4L2 controls supported by the driver */
81 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
82 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
83 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
84 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
85 static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
86 static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
87 static int sd_setblue_balance(struct gspca_dev *gspca_dev, __s32 val);
88 static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val);
89 static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val);
90 static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val);
91 static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val);
92 static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val);
93 static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
94 static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
95 static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
96 static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
97 static int sd_setinfrared(struct gspca_dev *gspca_dev, __s32 val);
98 static int sd_getinfrared(struct gspca_dev *gspca_dev, __s32 *val);
99
100 static struct ctrl sd_ctrls[] = {
101 #define BRIGHTNESS_IDX 0
102         {
103             {
104                 .id      = V4L2_CID_BRIGHTNESS,
105                 .type    = V4L2_CTRL_TYPE_INTEGER,
106                 .name    = "Brightness",
107                 .minimum = 0,
108 #define BRIGHTNESS_MAX 0xffff
109                 .maximum = BRIGHTNESS_MAX,
110                 .step    = 1,
111 #define BRIGHTNESS_DEF 0x8000
112                 .default_value = BRIGHTNESS_DEF,
113             },
114             .set = sd_setbrightness,
115             .get = sd_getbrightness,
116         },
117 #define CONTRAST_IDX 1
118         {
119             {
120                 .id      = V4L2_CID_CONTRAST,
121                 .type    = V4L2_CTRL_TYPE_INTEGER,
122                 .name    = "Contrast",
123                 .minimum = 0,
124 #define CONTRAST_MAX 127
125                 .maximum = CONTRAST_MAX,
126                 .step    = 1,
127 #define CONTRAST_DEF 63
128                 .default_value = CONTRAST_DEF,
129             },
130             .set = sd_setcontrast,
131             .get = sd_getcontrast,
132         },
133 #define COLOR_IDX 2
134         {
135             {
136                 .id      = V4L2_CID_SATURATION,
137                 .type    = V4L2_CTRL_TYPE_INTEGER,
138                 .name    = "Color",
139                 .minimum = 0,
140                 .maximum = 40,
141                 .step    = 1,
142 #define COLOR_DEF 32
143                 .default_value = COLOR_DEF,
144             },
145             .set = sd_setcolors,
146             .get = sd_getcolors,
147         },
148 #define BLUE_BALANCE_IDX 3
149         {
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 #define BLUE_BALANCE_DEF 32
158                 .default_value = BLUE_BALANCE_DEF,
159             },
160             .set = sd_setblue_balance,
161             .get = sd_getblue_balance,
162         },
163 #define RED_BALANCE_IDX 4
164         {
165             {
166                 .id      = V4L2_CID_RED_BALANCE,
167                 .type    = V4L2_CTRL_TYPE_INTEGER,
168                 .name    = "Red Balance",
169                 .minimum = 24,
170                 .maximum = 40,
171                 .step    = 1,
172 #define RED_BALANCE_DEF 32
173                 .default_value = RED_BALANCE_DEF,
174             },
175             .set = sd_setred_balance,
176             .get = sd_getred_balance,
177         },
178 #define GAMMA_IDX 5
179         {
180             {
181                 .id      = V4L2_CID_GAMMA,
182                 .type    = V4L2_CTRL_TYPE_INTEGER,
183                 .name    = "Gamma",
184                 .minimum = 0,
185                 .maximum = 40,
186                 .step    = 1,
187 #define GAMMA_DEF 20
188                 .default_value = GAMMA_DEF,
189             },
190             .set = sd_setgamma,
191             .get = sd_getgamma,
192         },
193 #define AUTOGAIN_IDX 6
194         {
195             {
196                 .id      = V4L2_CID_AUTOGAIN,
197                 .type    = V4L2_CTRL_TYPE_BOOLEAN,
198                 .name    = "Auto Gain",
199                 .minimum = 0,
200                 .maximum = 1,
201                 .step    = 1,
202 #define AUTOGAIN_DEF 1
203                 .default_value = AUTOGAIN_DEF,
204             },
205             .set = sd_setautogain,
206             .get = sd_getautogain,
207         },
208 /* ov7630/ov7648 only */
209 #define VFLIP_IDX 7
210         {
211             {
212                 .id      = V4L2_CID_VFLIP,
213                 .type    = V4L2_CTRL_TYPE_BOOLEAN,
214                 .name    = "Vflip",
215                 .minimum = 0,
216                 .maximum = 1,
217                 .step    = 1,
218 #define VFLIP_DEF 0                     /* vflip def = 1 for ov7630 */
219                 .default_value = VFLIP_DEF,
220             },
221             .set = sd_setvflip,
222             .get = sd_getvflip,
223         },
224 /* mt9v111 only */
225 #define INFRARED_IDX 8
226         {
227             {
228                 .id      = V4L2_CID_INFRARED,
229                 .type    = V4L2_CTRL_TYPE_BOOLEAN,
230                 .name    = "Infrared",
231                 .minimum = 0,
232                 .maximum = 1,
233                 .step    = 1,
234 #define INFRARED_DEF 0
235                 .default_value = INFRARED_DEF,
236             },
237             .set = sd_setinfrared,
238             .get = sd_getinfrared,
239         },
240 };
241
242 /* table of the disabled controls */
243 static __u32 ctrl_dis[] = {
244         (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
245                                                 /* SENSOR_HV7131R 0 */
246         (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
247                                                 /* SENSOR_MI0360 1 */
248         (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
249                                                 /* SENSOR_MO4000 2 */
250         (1 << VFLIP_IDX),
251                                                 /* SENSOR_MT9V111 3 */
252         (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
253                                                 /* SENSOR_OM6802 4 */
254         (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX),
255                                                 /* SENSOR_OV7630 5 */
256         (1 << INFRARED_IDX),
257                                                 /* SENSOR_OV7648 6 */
258         (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
259                                                 /* SENSOR_OV7660 7 */
260         (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
261                                                 /* SENSOR_SP80708 8 */
262 };
263
264 static const struct v4l2_pix_format vga_mode[] = {
265         {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
266                 .bytesperline = 160,
267                 .sizeimage = 160 * 120 * 4 / 8 + 590,
268                 .colorspace = V4L2_COLORSPACE_JPEG,
269                 .priv = 2},
270         {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
271                 .bytesperline = 320,
272                 .sizeimage = 320 * 240 * 3 / 8 + 590,
273                 .colorspace = V4L2_COLORSPACE_JPEG,
274                 .priv = 1},
275         {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
276                 .bytesperline = 640,
277                 .sizeimage = 640 * 480 * 3 / 8 + 590,
278                 .colorspace = V4L2_COLORSPACE_JPEG,
279                 .priv = 0},
280 };
281
282 /*Data from sn9c102p+hv7131r */
283 static const u8 sn_hv7131[0x1c] = {
284 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
285         0x00,   0x03,   0x64,   0x00,   0x1a,   0x20,   0x20,   0x20,
286 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
287         0xa1,   0x11,   0x02,   0x09,   0x00,   0x00,   0x00,   0x10,
288 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
289         0x03,   0x00,   0x00,   0x01,   0x03,   0x28,   0x1e,   0x41,
290 /*      reg18   reg19   reg1a   reg1b */
291         0x0a,   0x00,   0x00,   0x00
292 };
293
294 static const u8 sn_mi0360[0x1c] = {
295 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
296         0x00,   0x61,   0x44,   0x00,   0x1a,   0x20,   0x20,   0x20,
297 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
298         0xb1,   0x5d,   0x07,   0x00,   0x00,   0x00,   0x00,   0x10,
299 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
300         0x03,   0x00,   0x00,   0x02,   0x0a,   0x28,   0x1e,   0x61,
301 /*      reg18   reg19   reg1a   reg1b */
302         0x06,   0x00,   0x00,   0x00
303 };
304
305 static const u8 sn_mo4000[0x1c] = {
306 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
307         0x00,   0x23,   0x60,   0x00,   0x1a,   0x00,   0x20,   0x18,
308 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
309         0x81,   0x21,   0x00,   0x00,   0x00,   0x00,   0x00,   0x00,
310 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
311         0x03,    0x00,  0x0b,   0x0f,   0x14,   0x28,   0x1e,   0x40,
312 /*      reg18   reg19   reg1a   reg1b */
313         0x08,   0x00,   0x00,   0x00
314 };
315
316 static const u8 sn_mt9v111[0x1c] = {
317 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
318         0x00,   0x61,   0x40,   0x00,   0x1a,   0x20,   0x20,   0x20,
319 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
320         0x81,   0x5c,   0x07,   0x00,   0x00,   0x00,   0x00,   0x00,
321 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
322         0x03,   0x00,   0x00,   0x02,   0x1c,   0x28,   0x1e,   0x40,
323 /*      reg18   reg19   reg1a   reg1b */
324         0x06,   0x00,   0x00,   0x00
325 };
326
327 static const u8 sn_om6802[0x1c] = {
328 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
329         0x00,   0x23,   0x72,   0x00,   0x1a,   0x34,   0x27,   0x20,
330 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
331         0x80,   0x34,   0x00,   0x00,   0x00,   0x00,   0x00,   0x00,
332 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
333         0x03,   0x00,   0x51,   0x01,   0x00,   0x28,   0x1e,   0x40,
334 /*      reg18   reg19   reg1a   reg1b */
335         0x05,   0x00,   0x00,   0x00
336 };
337
338 static const u8 sn_ov7630[0x1c] = {
339 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
340         0x00,   0x21,   0x40,   0x00,   0x1a,   0x20,   0x1f,   0x20,
341 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
342         0xa1,   0x21,   0x76,   0x21,   0x00,   0x00,   0x00,   0x10,
343 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
344         0x03,   0x00,   0x04,   0x01,   0x0a,   0x28,   0x1e,   0xc2,
345 /*      reg18   reg19   reg1a   reg1b */
346         0x0b,   0x00,   0x00,   0x00
347 };
348
349 static const u8 sn_ov7648[0x1c] = {
350 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
351         0x00,   0x63,   0x40,   0x00,   0x1a,   0x20,   0x20,   0x20,
352 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
353         0x81,   0x21,   0x00,   0x00,   0x00,   0x00,   0x00,   0x10,
354 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
355         0x03,   0x00,   0x00,   0x01,   0x00,   0x28,   0x1e,   0x00,
356 /*      reg18   reg19   reg1a   reg1b */
357         0x0b,   0x00,   0x00,   0x00
358 };
359
360 static const u8 sn_ov7660[0x1c] = {
361 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
362         0x00,   0x61,   0x40,   0x00,   0x1a,   0x00,   0x00,   0x00,
363 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
364         0x81,   0x21,   0x00,   0x00,   0x00,   0x00,   0x00,   0x00,
365 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
366         0x03,   0x00,   0x01,   0x01,   0x08,   0x28,   0x1e,   0x20,
367 /*      reg18   reg19   reg1a   reg1b */
368         0x07,   0x00,   0x00,   0x00
369 };
370
371 static const u8 sn_sp80708[0x1c] = {
372 /*      reg0    reg1    reg2    reg3    reg4    reg5    reg6    reg7 */
373         0x00,   0x63,   0x60,   0x00,   0x1a,   0x20,   0x20,   0x20,
374 /*      reg8    reg9    rega    regb    regc    regd    rege    regf */
375         0x81,   0x18,   0x07,   0x00,   0x00,   0x00,   0x00,   0x00,
376 /*      reg10   reg11   reg12   reg13   reg14   reg15   reg16   reg17 */
377         0x03,   0x00,   0x00,   0x03,   0x04,   0x28,   0x1e,   0x00,
378 /*      reg18   reg19   reg1a   reg1b */
379         0x07,   0x00,   0x00,   0x00
380 };
381
382 /* sequence specific to the sensors - !! index = SENSOR_xxx */
383 static const u8 *sn_tb[] = {
384         sn_hv7131,
385         sn_mi0360,
386         sn_mo4000,
387         sn_mt9v111,
388         sn_om6802,
389         sn_ov7630,
390         sn_ov7648,
391         sn_ov7660,
392         sn_sp80708
393 };
394
395 /* default gamma table */
396 static const u8 gamma_def[17] = {
397         0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99,
398         0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
399 };
400 /* gamma for sensors HV7131R and MT9V111 */
401 static const u8 gamma_spec_1[17] = {
402         0x08, 0x3a, 0x52, 0x65, 0x75, 0x83, 0x91, 0x9d,
403         0xa9, 0xb4, 0xbe, 0xc8, 0xd2, 0xdb, 0xe4, 0xed, 0xf5
404 };
405 /* gamma for sensor SP80708 */
406 static const u8 gamma_spec_2[17] = {
407         0x0a, 0x2d, 0x4e, 0x68, 0x7d, 0x8f, 0x9f, 0xab,
408         0xb7, 0xc2, 0xcc, 0xd3, 0xd8, 0xde, 0xe2, 0xe5, 0xe6
409 };
410
411 /* color matrix and offsets */
412 static const u8 reg84[] = {
413         0x14, 0x00, 0x27, 0x00, 0x07, 0x00,     /* YR YG YB gains */
414         0xe8, 0x0f, 0xda, 0x0f, 0x40, 0x00,     /* UR UG UB */
415         0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f,     /* VR VG VB */
416         0x00, 0x00, 0x00                        /* YUV offsets */
417 };
418 static const u8 hv7131r_sensor_init[][8] = {
419         {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
420         {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10},
421         {0xd1, 0x11, 0x40, 0xff, 0x7f, 0x7f, 0x7f, 0x10},
422 /*      {0x91, 0x11, 0x44, 0x00, 0x00, 0x00, 0x00, 0x10}, */
423         {0xd1, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
424         {0xd1, 0x11, 0x14, 0x01, 0xe2, 0x02, 0x82, 0x10},
425 /*      {0x91, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10}, */
426
427         {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
428         {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
429         {0xc1, 0x11, 0x25, 0x00, 0x61, 0xa8, 0x00, 0x10},
430         {0xa1, 0x11, 0x30, 0x22, 0x00, 0x00, 0x00, 0x10},
431         {0xc1, 0x11, 0x31, 0x20, 0x2e, 0x20, 0x00, 0x10},
432         {0xc1, 0x11, 0x25, 0x00, 0xc3, 0x50, 0x00, 0x10},
433         {0xa1, 0x11, 0x30, 0x07, 0x00, 0x00, 0x00, 0x10}, /* gain14 */
434         {0xc1, 0x11, 0x31, 0x10, 0x10, 0x10, 0x00, 0x10}, /* r g b 101a10 */
435
436         {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
437         {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
438         {0xa1, 0x11, 0x21, 0xD0, 0x00, 0x00, 0x00, 0x10},
439         {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
440         {0xa1, 0x11, 0x23, 0x09, 0x00, 0x00, 0x00, 0x10},
441
442         {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
443         {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
444         {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
445         {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
446         {0xa1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10},
447         {}
448 };
449 static const u8 mi0360_sensor_init[][8] = {
450         {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
451         {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
452         {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
453         {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
454         {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
455         {0xd1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x53, 0x10},
456         {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
457         {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
458         {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
459         {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
460         {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
461         {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
462         {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
463         {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
464         {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
465         {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
466         {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
467         {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
468         {0xd1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
469         {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
470         {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
471         {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
472         {0xd1, 0x5d, 0x2f, 0xf7, 0xB0, 0x00, 0x04, 0x10},
473         {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
474         {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
475         {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
476         {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
477         {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
478         {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
479         {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
480         {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
481         {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
482         {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
483
484         {0xb1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
485         {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
486         {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
487         {0xd1, 0x5d, 0x2b, 0x00, 0xa0, 0x00, 0xb0, 0x10},
488         {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0xa0, 0x10},
489
490         {0xb1, 0x5d, 0x0a, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor clck ?2 */
491         {0xb1, 0x5d, 0x06, 0x00, 0x30, 0x00, 0x00, 0x10},
492         {0xb1, 0x5d, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10},
493         {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
494
495         {0xd1, 0x5d, 0x2b, 0x00, 0xb9, 0x00, 0xe3, 0x10},
496         {0xd1, 0x5d, 0x2d, 0x00, 0x5f, 0x00, 0xb9, 0x10}, /* 42 */
497 /*      {0xb1, 0x5d, 0x35, 0x00, 0x67, 0x00, 0x00, 0x10}, * gain orig */
498 /*      {0xb1, 0x5d, 0x35, 0x00, 0x20, 0x00, 0x00, 0x10}, * gain */
499         {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
500         {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
501         {}
502 };
503 static const u8 mo4000_sensor_init[][8] = {
504         {0xa1, 0x21, 0x01, 0x02, 0x00, 0x00, 0x00, 0x10},
505         {0xa1, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10},
506         {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
507         {0xa1, 0x21, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
508         {0xa1, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
509         {0xa1, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x10},
510         {0xa1, 0x21, 0x06, 0x80, 0x00, 0x00, 0x00, 0x10},
511         {0xa1, 0x21, 0x06, 0x81, 0x00, 0x00, 0x00, 0x10},
512         {0xa1, 0x21, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
513         {0xa1, 0x21, 0x11, 0x00, 0x00, 0x00, 0x00, 0x10},
514         {0xa1, 0x21, 0x11, 0x20, 0x00, 0x00, 0x00, 0x10},
515         {0xa1, 0x21, 0x11, 0x30, 0x00, 0x00, 0x00, 0x10},
516         {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
517         {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
518         {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
519         {0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
520         {0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10},
521         {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10},
522         {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
523         {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
524         {}
525 };
526 static const u8 mt9v111_sensor_init[][8] = {
527         {0xb1, 0x5c, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10}, /* reset? */
528         /* delay 20 ms */
529         {0xb1, 0x5c, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
530         {0xb1, 0x5c, 0x01, 0x00, 0x01, 0x00, 0x00, 0x10}, /* IFP select */
531         {0xb1, 0x5c, 0x08, 0x04, 0x80, 0x00, 0x00, 0x10}, /* output fmt ctrl */
532         {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10}, /* op mode ctrl */
533         {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
534         {0xb1, 0x5c, 0x03, 0x01, 0xe1, 0x00, 0x00, 0x10},
535         {0xb1, 0x5c, 0x04, 0x02, 0x81, 0x00, 0x00, 0x10},
536         {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
537         {0xb1, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10}, /* sensor select */
538         {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
539         {0xb1, 0x5c, 0x03, 0x01, 0xe6, 0x00, 0x00, 0x10},
540         {0xb1, 0x5c, 0x04, 0x02, 0x86, 0x00, 0x00, 0x10},
541         {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
542         {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10},
543         {0xb1, 0x5c, 0x08, 0x00, 0x08, 0x00, 0x00, 0x10}, /* row start */
544         {0xb1, 0x5c, 0x0e, 0x00, 0x08, 0x00, 0x00, 0x10},
545         {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10}, /* col start */
546         {0xb1, 0x5c, 0x03, 0x01, 0xe7, 0x00, 0x00, 0x10}, /* window height */
547         {0xb1, 0x5c, 0x04, 0x02, 0x87, 0x00, 0x00, 0x10}, /* window width */
548         {0xb1, 0x5c, 0x07, 0x30, 0x02, 0x00, 0x00, 0x10}, /* output ctrl */
549         {0xb1, 0x5c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10}, /* shutter delay */
550         {0xb1, 0x5c, 0x12, 0x00, 0xb0, 0x00, 0x00, 0x10}, /* zoom col start */
551         {0xb1, 0x5c, 0x13, 0x00, 0x7c, 0x00, 0x00, 0x10}, /* zoom row start */
552         {0xb1, 0x5c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* digital zoom */
553         {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10}, /* read mode */
554         {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
555         /*******/
556         {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
557         {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
558         {0xb1, 0x5c, 0x09, 0x01, 0x2c, 0x00, 0x00, 0x10},
559         {0xd1, 0x5c, 0x2b, 0x00, 0x33, 0x00, 0xa0, 0x10}, /* green1 gain */
560         {0xd1, 0x5c, 0x2d, 0x00, 0xa0, 0x00, 0x33, 0x10}, /* red gain */
561         /*******/
562         {0xb1, 0x5c, 0x06, 0x00, 0x1e, 0x00, 0x00, 0x10}, /* vert blanking */
563         {0xb1, 0x5c, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10}, /* horiz blanking */
564         {0xd1, 0x5c, 0x2c, 0x00, 0xad, 0x00, 0xad, 0x10}, /* blue gain */
565         {0xb1, 0x5c, 0x35, 0x01, 0xc0, 0x00, 0x00, 0x10}, /* global gain */
566         {}
567 };
568 static const u8 om6802_sensor_init[][8] = {
569         {0xa0, 0x34, 0x90, 0x05, 0x00, 0x00, 0x00, 0x10},
570         {0xa0, 0x34, 0x49, 0x85, 0x00, 0x00, 0x00, 0x10},
571         {0xa0, 0x34, 0x5a, 0xc0, 0x00, 0x00, 0x00, 0x10},
572         {0xa0, 0x34, 0xdd, 0x18, 0x00, 0x00, 0x00, 0x10},
573 /*      {0xa0, 0x34, 0xfb, 0x11, 0x00, 0x00, 0x00, 0x10}, */
574         {0xa0, 0x34, 0xf0, 0x04, 0x00, 0x00, 0x00, 0x10},
575                                         /* white balance & auto-exposure */
576 /*      {0xa0, 0x34, 0xf1, 0x02, 0x00, 0x00, 0x00, 0x10},
577                                                          * set color mode */
578 /*      {0xa0, 0x34, 0xfe, 0x5b, 0x00, 0x00, 0x00, 0x10},
579                                                  * max AGC value in AE */
580 /*      {0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10},
581                                                          * preset AGC */
582 /*      {0xa0, 0x34, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x10},
583                                                  * preset brightness */
584 /*      {0xa0, 0x34, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x10},
585                                                          * preset contrast */
586 /*      {0xa0, 0x34, 0xe8, 0x31, 0x00, 0x00, 0x00, 0x10},
587                                                          * preset gamma */
588         {0xa0, 0x34, 0xe9, 0x0f, 0x00, 0x00, 0x00, 0x10},
589                                         /* luminance mode (0x4f = AE) */
590         {0xa0, 0x34, 0xe4, 0xff, 0x00, 0x00, 0x00, 0x10},
591                                                         /* preset shutter */
592 /*      {0xa0, 0x34, 0xef, 0x00, 0x00, 0x00, 0x00, 0x10},
593                                                          * auto frame rate */
594 /*      {0xa0, 0x34, 0xfb, 0xee, 0x00, 0x00, 0x00, 0x10}, */
595
596 /*      {0xa0, 0x34, 0x71, 0x84, 0x00, 0x00, 0x00, 0x10}, */
597 /*      {0xa0, 0x34, 0x72, 0x05, 0x00, 0x00, 0x00, 0x10}, */
598 /*      {0xa0, 0x34, 0x68, 0x80, 0x00, 0x00, 0x00, 0x10}, */
599 /*      {0xa0, 0x34, 0x69, 0x01, 0x00, 0x00, 0x00, 0x10}, */
600         {}
601 };
602 static const u8 ov7630_sensor_init[][8] = {
603         {0xa1, 0x21, 0x76, 0x01, 0x00, 0x00, 0x00, 0x10},
604         {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
605 /* win: delay 20ms */
606         {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
607         {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
608 /* win: delay 20ms */
609         {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
610 /* win: i2c_r from 00 to 80 */
611         {0xd1, 0x21, 0x03, 0x80, 0x10, 0x20, 0x80, 0x10},
612         {0xb1, 0x21, 0x0c, 0x20, 0x20, 0x00, 0x00, 0x10},
613         {0xd1, 0x21, 0x11, 0x00, 0x48, 0xc0, 0x00, 0x10},
614         {0xb1, 0x21, 0x15, 0x80, 0x03, 0x00, 0x00, 0x10},
615         {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
616         {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
617         {0xd1, 0x21, 0x1f, 0x00, 0x80, 0x80, 0x80, 0x10},
618         {0xd1, 0x21, 0x23, 0xde, 0x10, 0x8a, 0xa0, 0x10},
619         {0xc1, 0x21, 0x27, 0xca, 0xa2, 0x74, 0x00, 0x10},
620         {0xd1, 0x21, 0x2a, 0x88, 0x00, 0x88, 0x01, 0x10},
621         {0xc1, 0x21, 0x2e, 0x80, 0x00, 0x18, 0x00, 0x10},
622         {0xa1, 0x21, 0x21, 0x08, 0x00, 0x00, 0x00, 0x10},
623         {0xa1, 0x21, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
624         {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
625         {0xb1, 0x21, 0x32, 0xc2, 0x08, 0x00, 0x00, 0x10},
626         {0xb1, 0x21, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x10},
627         {0xd1, 0x21, 0x60, 0x05, 0x40, 0x12, 0x57, 0x10},
628         {0xa1, 0x21, 0x64, 0x73, 0x00, 0x00, 0x00, 0x10},
629         {0xd1, 0x21, 0x65, 0x00, 0x55, 0x01, 0xac, 0x10},
630         {0xa1, 0x21, 0x69, 0x38, 0x00, 0x00, 0x00, 0x10},
631         {0xd1, 0x21, 0x6f, 0x1f, 0x01, 0x00, 0x10, 0x10},
632         {0xd1, 0x21, 0x73, 0x50, 0x20, 0x02, 0x01, 0x10},
633         {0xd1, 0x21, 0x77, 0xf3, 0x90, 0x98, 0x98, 0x10},
634         {0xc1, 0x21, 0x7b, 0x00, 0x4c, 0xf7, 0x00, 0x10},
635         {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
636         {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
637 /* */
638         {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
639         {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
640 /*fixme: + 0x12, 0x04*/
641 /*      {0xa1, 0x21, 0x75, 0x82, 0x00, 0x00, 0x00, 0x10},  * COMN
642                                                          * set by setvflip */
643         {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
644         {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
645         {0xb1, 0x21, 0x01, 0x80, 0x80, 0x00, 0x00, 0x10},
646 /* */
647         {0xa1, 0x21, 0x11, 0x00, 0x00, 0x00, 0x00, 0x10},
648         {0xa1, 0x21, 0x2a, 0x88, 0x00, 0x00, 0x00, 0x10},
649         {0xa1, 0x21, 0x2b, 0x34, 0x00, 0x00, 0x00, 0x10},
650 /* */
651         {0xa1, 0x21, 0x10, 0x83, 0x00, 0x00, 0x00, 0x10},
652 /*      {0xb1, 0x21, 0x01, 0x88, 0x70, 0x00, 0x00, 0x10}, */
653         {}
654 };
655
656 static const u8 ov7648_sensor_init[][8] = {
657         {0xa1, 0x21, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10},
658         {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10},       /* reset */
659         {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
660         {0xd1, 0x21, 0x03, 0xa4, 0x30, 0x88, 0x00, 0x10},
661         {0xb1, 0x21, 0x11, 0x80, 0x08, 0x00, 0x00, 0x10},
662         {0xc1, 0x21, 0x13, 0xa0, 0x04, 0x84, 0x00, 0x10},
663         {0xd1, 0x21, 0x17, 0x1a, 0x02, 0xba, 0xf4, 0x10},
664         {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
665         {0xd1, 0x21, 0x1f, 0x41, 0xc0, 0x80, 0x80, 0x10},
666         {0xd1, 0x21, 0x23, 0xde, 0xa0, 0x80, 0x32, 0x10},
667         {0xd1, 0x21, 0x27, 0xfe, 0xa0, 0x00, 0x91, 0x10},
668         {0xd1, 0x21, 0x2b, 0x00, 0x88, 0x85, 0x80, 0x10},
669         {0xc1, 0x21, 0x2f, 0x9c, 0x00, 0xc4, 0x00, 0x10},
670         {0xd1, 0x21, 0x60, 0xa6, 0x60, 0x88, 0x12, 0x10},
671         {0xd1, 0x21, 0x64, 0x88, 0x00, 0x00, 0x94, 0x10},
672         {0xd1, 0x21, 0x68, 0x7a, 0x0c, 0x00, 0x00, 0x10},
673         {0xd1, 0x21, 0x6c, 0x11, 0x33, 0x22, 0x00, 0x10},
674         {0xd1, 0x21, 0x70, 0x11, 0x00, 0x10, 0x50, 0x10},
675         {0xd1, 0x21, 0x74, 0x20, 0x06, 0x00, 0xb5, 0x10},
676         {0xd1, 0x21, 0x78, 0x8a, 0x00, 0x00, 0x00, 0x10},
677         {0xb1, 0x21, 0x7c, 0x00, 0x43, 0x00, 0x00, 0x10},
678
679         {0xd1, 0x21, 0x21, 0x86, 0x00, 0xde, 0xa0, 0x10},
680 /*      {0xd1, 0x21, 0x25, 0x80, 0x32, 0xfe, 0xa0, 0x10}, jfm done */
681 /*      {0xd1, 0x21, 0x29, 0x00, 0x91, 0x00, 0x88, 0x10}, jfm done */
682         {0xb1, 0x21, 0x2d, 0x85, 0x00, 0x00, 0x00, 0x10},
683 /*...*/
684 /*      {0xa1, 0x21, 0x12, 0x08, 0x00, 0x00, 0x00, 0x10}, jfm done */
685 /*      {0xa1, 0x21, 0x75, 0x06, 0x00, 0x00, 0x00, 0x10},   * COMN
686                                                          * set by setvflip */
687         {0xa1, 0x21, 0x19, 0x02, 0x00, 0x00, 0x00, 0x10},
688         {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
689 /*      {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
690 /*      {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},  * GAIN - def */
691 /*      {0xb1, 0x21, 0x01, 0x6c, 0x6c, 0x00, 0x00, 0x10},  * B R - def: 80 */
692 /*...*/
693         {0xa1, 0x21, 0x11, 0x81, 0x00, 0x00, 0x00, 0x10}, /* CLKRC */
694 /*      {0xa1, 0x21, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
695 /*      {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
696 /*      {0xa1, 0x21, 0x2a, 0x91, 0x00, 0x00, 0x00, 0x10}, jfm done */
697 /*      {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
698 /*      {0xb1, 0x21, 0x01, 0x64, 0x84, 0x00, 0x00, 0x10},  * B R - def: 80 */
699
700         {}
701 };
702
703 static const u8 ov7660_sensor_init[][8] = {
704         {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */
705 /*              (delay 20ms) */
706         {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
707                                                 /* Outformat = rawRGB */
708         {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */
709         {0xd1, 0x21, 0x00, 0x01, 0x74, 0x74, 0x00, 0x10},
710                                                 /* GAIN BLUE RED VREF */
711         {0xd1, 0x21, 0x04, 0x00, 0x7d, 0x62, 0x00, 0x10},
712                                                 /* COM 1 BAVE GEAVE AECHH */
713         {0xb1, 0x21, 0x08, 0x83, 0x01, 0x00, 0x00, 0x10}, /* RAVE COM2 */
714         {0xd1, 0x21, 0x0c, 0x00, 0x08, 0x04, 0x4f, 0x10}, /* COM 3 4 5 6 */
715         {0xd1, 0x21, 0x10, 0x7f, 0x40, 0x05, 0xff, 0x10},
716                                                 /* AECH CLKRC COM7 COM8 */
717         {0xc1, 0x21, 0x14, 0x2c, 0x00, 0x02, 0x00, 0x10}, /* COM9 COM10 */
718         {0xd1, 0x21, 0x17, 0x10, 0x60, 0x02, 0x7b, 0x10},
719                                                 /* HSTART HSTOP VSTRT VSTOP */
720         {0xa1, 0x21, 0x1b, 0x02, 0x00, 0x00, 0x00, 0x10}, /* PSHFT */
721         {0xb1, 0x21, 0x1e, 0x01, 0x0e, 0x00, 0x00, 0x10}, /* MVFP LAEC */
722         {0xd1, 0x21, 0x20, 0x07, 0x07, 0x07, 0x07, 0x10},
723                                         /* BOS GBOS GROS ROS (BGGR offset) */
724 /*      {0xd1, 0x21, 0x24, 0x68, 0x58, 0xd4, 0x80, 0x10}, */
725         {0xd1, 0x21, 0x24, 0x78, 0x68, 0xd4, 0x80, 0x10},
726                                                 /* AEW AEB VPT BBIAS */
727         {0xd1, 0x21, 0x28, 0x80, 0x30, 0x00, 0x00, 0x10},
728                                                 /* GbBIAS RSVD EXHCH EXHCL */
729         {0xd1, 0x21, 0x2c, 0x80, 0x00, 0x00, 0x62, 0x10},
730                                                 /* RBIAS ADVFL ASDVFH YAVE */
731         {0xc1, 0x21, 0x30, 0x08, 0x30, 0xb4, 0x00, 0x10},
732                                                 /* HSYST HSYEN HREF */
733         {0xd1, 0x21, 0x33, 0x00, 0x07, 0x84, 0x00, 0x10}, /* reserved */
734         {0xd1, 0x21, 0x37, 0x0c, 0x02, 0x43, 0x00, 0x10},
735                                                 /* ADC ACOM OFON TSLB */
736         {0xd1, 0x21, 0x3b, 0x02, 0x6c, 0x19, 0x0e, 0x10},
737                                                 /* COM11 COM12 COM13 COM14 */
738         {0xd1, 0x21, 0x3f, 0x41, 0xc1, 0x22, 0x08, 0x10},
739                                                 /* EDGE COM15 COM16 COM17 */
740         {0xd1, 0x21, 0x43, 0xf0, 0x10, 0x78, 0xa8, 0x10}, /* reserved */
741         {0xd1, 0x21, 0x47, 0x60, 0x80, 0x00, 0x00, 0x10}, /* reserved */
742         {0xd1, 0x21, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* reserved */
743         {0xd1, 0x21, 0x4f, 0x46, 0x36, 0x0f, 0x17, 0x10}, /* MTX 1 2 3 4 */
744         {0xd1, 0x21, 0x53, 0x7f, 0x96, 0x40, 0x40, 0x10}, /* MTX 5 6 7 8 */
745         {0xb1, 0x21, 0x57, 0x40, 0x0f, 0x00, 0x00, 0x10}, /* MTX9 MTXS */
746         {0xd1, 0x21, 0x59, 0xba, 0x9a, 0x22, 0xb9, 0x10}, /* reserved */
747         {0xd1, 0x21, 0x5d, 0x9b, 0x10, 0xf0, 0x05, 0x10}, /* reserved */
748         {0xa1, 0x21, 0x61, 0x60, 0x00, 0x00, 0x00, 0x10}, /* reserved */
749         {0xd1, 0x21, 0x62, 0x00, 0x00, 0x50, 0x30, 0x10},
750                                                 /* LCC1 LCC2 LCC3 LCC4 */
751         {0xa1, 0x21, 0x66, 0x00, 0x00, 0x00, 0x00, 0x10}, /* LCC5 */
752         {0xd1, 0x21, 0x67, 0x80, 0x7a, 0x90, 0x80, 0x10}, /* MANU */
753         {0xa1, 0x21, 0x6b, 0x0a, 0x00, 0x00, 0x00, 0x10},
754                                         /* band gap reference [0:3] DBLV */
755         {0xd1, 0x21, 0x6c, 0x30, 0x48, 0x80, 0x74, 0x10}, /* gamma curve */
756         {0xd1, 0x21, 0x70, 0x64, 0x60, 0x5c, 0x58, 0x10}, /* gamma curve */
757         {0xd1, 0x21, 0x74, 0x54, 0x4c, 0x40, 0x38, 0x10}, /* gamma curve */
758         {0xd1, 0x21, 0x78, 0x34, 0x30, 0x2f, 0x2b, 0x10}, /* gamma curve */
759         {0xd1, 0x21, 0x7c, 0x03, 0x07, 0x17, 0x34, 0x10}, /* gamma curve */
760         {0xd1, 0x21, 0x80, 0x41, 0x4d, 0x58, 0x63, 0x10}, /* gamma curve */
761         {0xd1, 0x21, 0x84, 0x6e, 0x77, 0x87, 0x95, 0x10}, /* gamma curve */
762         {0xc1, 0x21, 0x88, 0xaf, 0xc7, 0xdf, 0x00, 0x10}, /* gamma curve */
763         {0xc1, 0x21, 0x8b, 0x99, 0x99, 0xcf, 0x00, 0x10}, /* reserved */
764         {0xb1, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x10}, /* DM_LNL/H */
765         {0xb1, 0x21, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x10},
766 /****** (some exchanges in the win trace) ******/
767         {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10}, /* MVFP */
768                                                 /* bits[3..0]reserved */
769         {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10},
770         {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
771                                                 /* VREF vertical frame ctrl */
772         {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
773         {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10}, /* AECH 0x20 */
774         {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFL */
775         {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFH */
776         {0xa1, 0x21, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x10}, /* GAIN */
777 /*      {0xb1, 0x21, 0x01, 0x78, 0x78, 0x00, 0x00, 0x10}, * BLUE */
778 /****** (some exchanges in the win trace) ******/
779         {0xa1, 0x21, 0x93, 0x00, 0x00, 0x00, 0x00, 0x10},/* dummy line hight */
780         {0xa1, 0x21, 0x92, 0x25, 0x00, 0x00, 0x00, 0x10}, /* dummy line low */
781         {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCH */
782         {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCL */
783 /*      {0xa1, 0x21, 0x02, 0x90, 0x00, 0x00, 0x00, 0x10},  * RED */
784 /****** (some exchanges in the win trace) ******/
785 /******!! startsensor KO if changed !!****/
786         {0xa1, 0x21, 0x93, 0x01, 0x00, 0x00, 0x00, 0x10},
787         {0xa1, 0x21, 0x92, 0xff, 0x00, 0x00, 0x00, 0x10},
788         {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10},
789         {0xa1, 0x21, 0x2b, 0xc3, 0x00, 0x00, 0x00, 0x10},
790         {}
791 };
792
793 static const u8 sp80708_sensor_init[][8] = {
794         {0xa1, 0x18, 0x06, 0xf9, 0x00, 0x00, 0x00, 0x10},
795         {0xa1, 0x18, 0x09, 0x1f, 0x00, 0x00, 0x00, 0x10},
796         {0xa1, 0x18, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
797         {0xa1, 0x18, 0x0d, 0xc0, 0x00, 0x00, 0x00, 0x10},
798         {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
799         {0xa1, 0x18, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x10},
800         {0xa1, 0x18, 0x10, 0x40, 0x00, 0x00, 0x00, 0x10},
801         {0xa1, 0x18, 0x11, 0x4e, 0x00, 0x00, 0x00, 0x10},
802         {0xa1, 0x18, 0x12, 0x53, 0x00, 0x00, 0x00, 0x10},
803         {0xa1, 0x18, 0x15, 0x80, 0x00, 0x00, 0x00, 0x10},
804         {0xa1, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10},
805         {0xa1, 0x18, 0x19, 0x18, 0x00, 0x00, 0x00, 0x10},
806         {0xa1, 0x18, 0x1a, 0x10, 0x00, 0x00, 0x00, 0x10},
807         {0xa1, 0x18, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x10},
808         {0xa1, 0x18, 0x1c, 0x28, 0x00, 0x00, 0x00, 0x10},
809         {0xa1, 0x18, 0x1d, 0x02, 0x00, 0x00, 0x00, 0x10},
810         {0xa1, 0x18, 0x1e, 0x10, 0x00, 0x00, 0x00, 0x10},
811         {0xa1, 0x18, 0x26, 0x04, 0x00, 0x00, 0x00, 0x10},
812         {0xa1, 0x18, 0x27, 0x1e, 0x00, 0x00, 0x00, 0x10},
813         {0xa1, 0x18, 0x28, 0x5a, 0x00, 0x00, 0x00, 0x10},
814         {0xa1, 0x18, 0x29, 0x28, 0x00, 0x00, 0x00, 0x10},
815         {0xa1, 0x18, 0x2a, 0x78, 0x00, 0x00, 0x00, 0x10},
816         {0xa1, 0x18, 0x2b, 0x01, 0x00, 0x00, 0x00, 0x10},
817         {0xa1, 0x18, 0x2c, 0xf7, 0x00, 0x00, 0x00, 0x10},
818         {0xa1, 0x18, 0x2d, 0x2d, 0x00, 0x00, 0x00, 0x10},
819         {0xa1, 0x18, 0x2e, 0xd5, 0x00, 0x00, 0x00, 0x10},
820         {0xa1, 0x18, 0x39, 0x42, 0x00, 0x00, 0x00, 0x10},
821         {0xa1, 0x18, 0x3a, 0x67, 0x00, 0x00, 0x00, 0x10},
822         {0xa1, 0x18, 0x3b, 0x87, 0x00, 0x00, 0x00, 0x10},
823         {0xa1, 0x18, 0x3c, 0xa3, 0x00, 0x00, 0x00, 0x10},
824         {0xa1, 0x18, 0x3d, 0xb0, 0x00, 0x00, 0x00, 0x10},
825         {0xa1, 0x18, 0x3e, 0xbc, 0x00, 0x00, 0x00, 0x10},
826         {0xa1, 0x18, 0x3f, 0xc8, 0x00, 0x00, 0x00, 0x10},
827         {0xa1, 0x18, 0x40, 0xd4, 0x00, 0x00, 0x00, 0x10},
828         {0xa1, 0x18, 0x41, 0xdf, 0x00, 0x00, 0x00, 0x10},
829         {0xa1, 0x18, 0x42, 0xea, 0x00, 0x00, 0x00, 0x10},
830         {0xa1, 0x18, 0x43, 0xf5, 0x00, 0x00, 0x00, 0x10},
831         {0xa1, 0x18, 0x45, 0x80, 0x00, 0x00, 0x00, 0x10},
832         {0xa1, 0x18, 0x46, 0x60, 0x00, 0x00, 0x00, 0x10},
833         {0xa1, 0x18, 0x47, 0x50, 0x00, 0x00, 0x00, 0x10},
834         {0xa1, 0x18, 0x48, 0x30, 0x00, 0x00, 0x00, 0x10},
835         {0xa1, 0x18, 0x49, 0x01, 0x00, 0x00, 0x00, 0x10},
836         {0xa1, 0x18, 0x4d, 0xae, 0x00, 0x00, 0x00, 0x10},
837         {0xa1, 0x18, 0x4e, 0x03, 0x00, 0x00, 0x00, 0x10},
838         {0xa1, 0x18, 0x4f, 0x66, 0x00, 0x00, 0x00, 0x10},
839         {0xa1, 0x18, 0x50, 0x1c, 0x00, 0x00, 0x00, 0x10},
840         {0xa1, 0x18, 0x44, 0x10, 0x00, 0x00, 0x00, 0x10},
841         {0xa1, 0x18, 0x4a, 0x30, 0x00, 0x00, 0x00, 0x10},
842         {0xa1, 0x18, 0x51, 0x80, 0x00, 0x00, 0x00, 0x10},
843         {0xa1, 0x18, 0x52, 0x80, 0x00, 0x00, 0x00, 0x10},
844         {0xa1, 0x18, 0x53, 0x80, 0x00, 0x00, 0x00, 0x10},
845         {0xa1, 0x18, 0x54, 0x80, 0x00, 0x00, 0x00, 0x10},
846         {0xa1, 0x18, 0x55, 0x80, 0x00, 0x00, 0x00, 0x10},
847         {0xa1, 0x18, 0x56, 0x80, 0x00, 0x00, 0x00, 0x10},
848         {0xa1, 0x18, 0x57, 0xe0, 0x00, 0x00, 0x00, 0x10},
849         {0xa1, 0x18, 0x58, 0xc0, 0x00, 0x00, 0x00, 0x10},
850         {0xa1, 0x18, 0x59, 0xab, 0x00, 0x00, 0x00, 0x10},
851         {0xa1, 0x18, 0x5a, 0xa0, 0x00, 0x00, 0x00, 0x10},
852         {0xa1, 0x18, 0x5b, 0x99, 0x00, 0x00, 0x00, 0x10},
853         {0xa1, 0x18, 0x5c, 0x90, 0x00, 0x00, 0x00, 0x10},
854         {0xa1, 0x18, 0x5e, 0x24, 0x00, 0x00, 0x00, 0x10},
855         {0xa1, 0x18, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x10},
856         {0xa1, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00, 0x10},
857         {0xa1, 0x18, 0x61, 0x73, 0x00, 0x00, 0x00, 0x10},
858         {0xa1, 0x18, 0x63, 0x42, 0x00, 0x00, 0x00, 0x10},
859         {0xa1, 0x18, 0x64, 0x42, 0x00, 0x00, 0x00, 0x10},
860         {0xa1, 0x18, 0x65, 0x42, 0x00, 0x00, 0x00, 0x10},
861         {0xa1, 0x18, 0x66, 0x24, 0x00, 0x00, 0x00, 0x10},
862         {0xa1, 0x18, 0x67, 0x24, 0x00, 0x00, 0x00, 0x10},
863         {0xa1, 0x18, 0x68, 0x08, 0x00, 0x00, 0x00, 0x10},
864         {0xa1, 0x18, 0x2f, 0xc9, 0x00, 0x00, 0x00, 0x10},
865         /********/
866         {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
867         {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
868         {0xa1, 0x18, 0x03, 0x01, 0x00, 0x00, 0x00, 0x10},
869         {0xa1, 0x18, 0x04, 0xa4, 0x00, 0x00, 0x00, 0x10},
870         {0xa1, 0x18, 0x14, 0x3f, 0x00, 0x00, 0x00, 0x10},
871         {0xa1, 0x18, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
872         {0xb1, 0x18, 0x11, 0x40, 0x40, 0x00, 0x00, 0x10},
873         {}
874 };
875
876 /* read <len> bytes to gspca_dev->usb_buf */
877 static void reg_r(struct gspca_dev *gspca_dev,
878                   u16 value, int len)
879 {
880 #ifdef GSPCA_DEBUG
881         if (len > USB_BUF_SZ) {
882                 err("reg_r: buffer overflow");
883                 return;
884         }
885 #endif
886         usb_control_msg(gspca_dev->dev,
887                         usb_rcvctrlpipe(gspca_dev->dev, 0),
888                         0,
889                         USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
890                         value, 0,
891                         gspca_dev->usb_buf, len,
892                         500);
893         PDEBUG(D_USBI, "reg_r [%02x] -> %02x", value, gspca_dev->usb_buf[0]);
894 }
895
896 static void reg_w1(struct gspca_dev *gspca_dev,
897                    u16 value,
898                    u8 data)
899 {
900         PDEBUG(D_USBO, "reg_w1 [%04x] = %02x", value, data);
901         gspca_dev->usb_buf[0] = data;
902         usb_control_msg(gspca_dev->dev,
903                         usb_sndctrlpipe(gspca_dev->dev, 0),
904                         0x08,
905                         USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
906                         value,
907                         0,
908                         gspca_dev->usb_buf, 1,
909                         500);
910 }
911 static void reg_w(struct gspca_dev *gspca_dev,
912                           u16 value,
913                           const u8 *buffer,
914                           int len)
915 {
916         PDEBUG(D_USBO, "reg_w [%04x] = %02x %02x ..",
917                 value, buffer[0], buffer[1]);
918 #ifdef GSPCA_DEBUG
919         if (len > USB_BUF_SZ) {
920                 err("reg_w: buffer overflow");
921                 return;
922         }
923 #endif
924         memcpy(gspca_dev->usb_buf, buffer, len);
925         usb_control_msg(gspca_dev->dev,
926                         usb_sndctrlpipe(gspca_dev->dev, 0),
927                         0x08,
928                         USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
929                         value, 0,
930                         gspca_dev->usb_buf, len,
931                         500);
932 }
933
934 /* I2C write 1 byte */
935 static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
936 {
937         struct sd *sd = (struct sd *) gspca_dev;
938
939         PDEBUG(D_USBO, "i2c_w2 [%02x] = %02x", reg, val);
940         gspca_dev->usb_buf[0] = 0x81 | (2 << 4);        /* = a1 */
941         gspca_dev->usb_buf[1] = sd->i2c_base;
942         gspca_dev->usb_buf[2] = reg;
943         gspca_dev->usb_buf[3] = val;
944         gspca_dev->usb_buf[4] = 0;
945         gspca_dev->usb_buf[5] = 0;
946         gspca_dev->usb_buf[6] = 0;
947         gspca_dev->usb_buf[7] = 0x10;
948         usb_control_msg(gspca_dev->dev,
949                         usb_sndctrlpipe(gspca_dev->dev, 0),
950                         0x08,
951                         USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
952                         0x08,                   /* value = i2c */
953                         0,
954                         gspca_dev->usb_buf, 8,
955                         500);
956 }
957
958 /* I2C write 8 bytes */
959 static void i2c_w8(struct gspca_dev *gspca_dev,
960                    const u8 *buffer)
961 {
962         memcpy(gspca_dev->usb_buf, buffer, 8);
963         usb_control_msg(gspca_dev->dev,
964                         usb_sndctrlpipe(gspca_dev->dev, 0),
965                         0x08,
966                         USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
967                         0x08, 0,                /* value, index */
968                         gspca_dev->usb_buf, 8,
969                         500);
970         msleep(2);
971 }
972
973 /* read 5 bytes in gspca_dev->usb_buf */
974 static void i2c_r5(struct gspca_dev *gspca_dev, u8 reg)
975 {
976         struct sd *sd = (struct sd *) gspca_dev;
977         u8 mode[8];
978
979         mode[0] = 0x81 | 0x10;
980         mode[1] = sd->i2c_base;
981         mode[2] = reg;
982         mode[3] = 0;
983         mode[4] = 0;
984         mode[5] = 0;
985         mode[6] = 0;
986         mode[7] = 0x10;
987         i2c_w8(gspca_dev, mode);
988         msleep(2);
989         mode[0] = 0x81 | (5 << 4) | 0x02;
990         mode[2] = 0;
991         i2c_w8(gspca_dev, mode);
992         msleep(2);
993         reg_r(gspca_dev, 0x0a, 5);
994 }
995
996 static int hv7131r_probe(struct gspca_dev *gspca_dev)
997 {
998         i2c_w1(gspca_dev, 0x02, 0);                     /* sensor wakeup */
999         msleep(10);
1000         reg_w1(gspca_dev, 0x02, 0x66);                  /* Gpio on */
1001         msleep(10);
1002         i2c_r5(gspca_dev, 0);                           /* read sensor id */
1003         if (gspca_dev->usb_buf[0] == 0x02
1004             && gspca_dev->usb_buf[1] == 0x09
1005             && gspca_dev->usb_buf[2] == 0x01
1006             && gspca_dev->usb_buf[3] == 0x00
1007             && gspca_dev->usb_buf[4] == 0x00) {
1008                 PDEBUG(D_PROBE, "Find Sensor sn9c102P HV7131R");
1009                 return 0;
1010         }
1011         PDEBUG(D_PROBE, "Find Sensor 0x%02x 0x%02x 0x%02x",
1012                 gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
1013                 gspca_dev->usb_buf[2]);
1014         PDEBUG(D_PROBE, "Sensor sn9c102P Not found");
1015         return -ENODEV;
1016 }
1017
1018 static void mi0360_probe(struct gspca_dev *gspca_dev)
1019 {
1020         struct sd *sd = (struct sd *) gspca_dev;
1021         int i, j;
1022         u16 val = 0;
1023         static const u8 probe_tb[][4][8] = {
1024             {                                   /* mi0360 */
1025                 {0xb0, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
1026                 {0x90, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1027                 {0xa2, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1028                 {0xb0, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10}
1029             },
1030             {                                   /* mt9v111 */
1031                 {0xb0, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10},
1032                 {0x90, 0x5c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x10},
1033                 {0xa2, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1034                 {}
1035             },
1036         };
1037
1038         for (i = 0; i < ARRAY_SIZE(probe_tb); i++) {
1039                 reg_w1(gspca_dev, 0x17, 0x62);
1040                 reg_w1(gspca_dev, 0x01, 0x08);
1041                 for (j = 0; j < 3; j++)
1042                         i2c_w8(gspca_dev, probe_tb[i][j]);
1043                 msleep(2);
1044                 reg_r(gspca_dev, 0x0a, 5);
1045                 val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
1046                 if (probe_tb[i][3][0] != 0)
1047                         i2c_w8(gspca_dev, probe_tb[i][3]);
1048                 reg_w1(gspca_dev, 0x01, 0x29);
1049                 reg_w1(gspca_dev, 0x17, 0x42);
1050                 if (val != 0xffff)
1051                         break;
1052         }
1053         switch (val) {
1054         case 0x823a:
1055                 PDEBUG(D_PROBE, "Sensor mt9v111");
1056                 sd->sensor = SENSOR_MT9V111;
1057                 sd->i2c_base = 0x5c;
1058                 break;
1059         case 0x8243:
1060                 PDEBUG(D_PROBE, "Sensor mi0360");
1061                 break;
1062         default:
1063                 PDEBUG(D_PROBE, "Unknown sensor %04x - forced to mi0360", val);
1064                 break;
1065         }
1066 }
1067
1068 static int configure_gpio(struct gspca_dev *gspca_dev,
1069                           const u8 *sn9c1xx)
1070 {
1071         struct sd *sd = (struct sd *) gspca_dev;
1072         const u8 *reg9a;
1073         static const u8 reg9a_def[] =
1074                 {0x00, 0x40, 0x20, 0x00, 0x00, 0x00};
1075         static const u8 reg9a_spec[] =
1076                 {0x00, 0x40, 0x38, 0x30, 0x00, 0x20};
1077         static const u8 regd4[] = {0x60, 0x00, 0x00};
1078
1079         reg_w1(gspca_dev, 0xf1, 0x00);
1080         reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
1081
1082         /* configure gpio */
1083         reg_w(gspca_dev, 0x01, &sn9c1xx[1], 2);
1084         reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
1085         reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5);      /* jfm len was 3 */
1086         switch (sd->sensor) {
1087         case SENSOR_OV7660:
1088         case SENSOR_SP80708:
1089                 reg9a = reg9a_spec;
1090                 break;
1091         default:
1092                 reg9a = reg9a_def;
1093                 break;
1094         }
1095         reg_w(gspca_dev, 0x9a, reg9a, 6);
1096
1097         reg_w(gspca_dev, 0xd4, regd4, sizeof regd4); /*fixme:jfm was 60 only*/
1098
1099         reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
1100
1101         switch (sd->sensor) {
1102         case SENSOR_MT9V111:
1103                 reg_w1(gspca_dev, 0x01, 0x61);
1104                 reg_w1(gspca_dev, 0x17, 0x61);
1105                 reg_w1(gspca_dev, 0x01, 0x60);
1106                 reg_w1(gspca_dev, 0x01, 0x40);
1107                 break;
1108         case SENSOR_OM6802:
1109                 reg_w1(gspca_dev, 0x02, 0x71);
1110                 reg_w1(gspca_dev, 0x01, 0x42);
1111                 reg_w1(gspca_dev, 0x17, 0x64);
1112                 reg_w1(gspca_dev, 0x01, 0x42);
1113                 break;
1114         case SENSOR_OV7630:
1115                 reg_w1(gspca_dev, 0x01, 0x61);
1116                 reg_w1(gspca_dev, 0x17, 0xe2);
1117                 reg_w1(gspca_dev, 0x01, 0x60);
1118                 reg_w1(gspca_dev, 0x01, 0x40);
1119                 break;
1120         case SENSOR_OV7648:
1121                 reg_w1(gspca_dev, 0x01, 0x63);
1122                 reg_w1(gspca_dev, 0x17, 0x20);
1123                 reg_w1(gspca_dev, 0x01, 0x62);
1124                 reg_w1(gspca_dev, 0x01, 0x42);
1125                 break;
1126         case SENSOR_OV7660:
1127                 reg_w1(gspca_dev, 0x01, 0x61);
1128                 reg_w1(gspca_dev, 0x17, 0x20);
1129                 reg_w1(gspca_dev, 0x01, 0x60);
1130                 reg_w1(gspca_dev, 0x01, 0x40);
1131                 break;
1132         case SENSOR_SP80708:
1133                 reg_w1(gspca_dev, 0x01, 0x63);
1134                 reg_w1(gspca_dev, 0x17, 0x20);
1135                 reg_w1(gspca_dev, 0x01, 0x62);
1136                 reg_w1(gspca_dev, 0x01, 0x42);
1137                 mdelay(100);
1138                 reg_w1(gspca_dev, 0x02, 0x62);
1139                 break;
1140 /*      case SENSOR_HV7131R: */
1141 /*      case SENSOR_MI0360: */
1142 /*      case SENSOR_MO4000: */
1143         default:
1144                 reg_w1(gspca_dev, 0x01, 0x43);
1145                 reg_w1(gspca_dev, 0x17, 0x61);
1146                 reg_w1(gspca_dev, 0x01, 0x42);
1147                 if (sd->sensor == SENSOR_HV7131R) {
1148                         if (hv7131r_probe(gspca_dev) < 0)
1149                                 return -ENODEV;
1150                 }
1151                 break;
1152         }
1153         return 0;
1154 }
1155
1156 static void hv7131R_InitSensor(struct gspca_dev *gspca_dev)
1157 {
1158         int i = 0;
1159         static const u8 SetSensorClk[] =        /* 0x08 Mclk */
1160                 { 0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10 };
1161
1162         while (hv7131r_sensor_init[i][0]) {
1163                 i2c_w8(gspca_dev, hv7131r_sensor_init[i]);
1164                 i++;
1165         }
1166         i2c_w8(gspca_dev, SetSensorClk);
1167 }
1168
1169 static void mi0360_InitSensor(struct gspca_dev *gspca_dev)
1170 {
1171         int i = 0;
1172
1173         while (mi0360_sensor_init[i][0]) {
1174                 i2c_w8(gspca_dev, mi0360_sensor_init[i]);
1175                 i++;
1176         }
1177 }
1178
1179 static void mo4000_InitSensor(struct gspca_dev *gspca_dev)
1180 {
1181         int i = 0;
1182
1183         while (mo4000_sensor_init[i][0]) {
1184                 i2c_w8(gspca_dev, mo4000_sensor_init[i]);
1185                 i++;
1186         }
1187 }
1188
1189 static void mt9v111_InitSensor(struct gspca_dev *gspca_dev)
1190 {
1191         int i = 0;
1192
1193         i2c_w8(gspca_dev, mt9v111_sensor_init[i]);
1194         i++;
1195         msleep(20);
1196         while (mt9v111_sensor_init[i][0]) {
1197                 i2c_w8(gspca_dev, mt9v111_sensor_init[i]);
1198                 i++;
1199         }
1200 }
1201
1202 static void om6802_InitSensor(struct gspca_dev *gspca_dev)
1203 {
1204         int i = 0;
1205
1206         while (om6802_sensor_init[i][0]) {
1207                 i2c_w8(gspca_dev, om6802_sensor_init[i]);
1208                 i++;
1209         }
1210 }
1211
1212 static void ov7630_InitSensor(struct gspca_dev *gspca_dev)
1213 {
1214         int i = 0;
1215
1216         i2c_w8(gspca_dev, ov7630_sensor_init[i]);       /* 76 01 */
1217         i++;
1218         i2c_w8(gspca_dev, ov7630_sensor_init[i]);       /* 12 c8 (RGB+SRST) */
1219         i++;
1220         msleep(20);
1221         i2c_w8(gspca_dev, ov7630_sensor_init[i]);       /* 12 48 */
1222         i++;
1223         i2c_w8(gspca_dev, ov7630_sensor_init[i]);       /* 12 c8 */
1224         i++;
1225         msleep(20);
1226         i2c_w8(gspca_dev, ov7630_sensor_init[i]);       /* 12 48 */
1227         i++;
1228 /*jfm:win i2c_r from 00 to 80*/
1229
1230         while (ov7630_sensor_init[i][0]) {
1231                 i2c_w8(gspca_dev, ov7630_sensor_init[i]);
1232                 i++;
1233         }
1234 }
1235
1236 static void ov7648_InitSensor(struct gspca_dev *gspca_dev)
1237 {
1238         int i = 0;
1239
1240         i2c_w8(gspca_dev, ov7648_sensor_init[i]);
1241         i++;
1242 /* win: dble reset */
1243         i2c_w8(gspca_dev, ov7648_sensor_init[i]);       /* reset */
1244         i++;
1245         msleep(20);
1246 /* win: i2c reg read 00..7f */
1247         while (ov7648_sensor_init[i][0]) {
1248                 i2c_w8(gspca_dev, ov7648_sensor_init[i]);
1249                 i++;
1250         }
1251 }
1252
1253 static void ov7660_InitSensor(struct gspca_dev *gspca_dev)
1254 {
1255         int i = 0;
1256
1257         i2c_w8(gspca_dev, ov7660_sensor_init[i]);       /* reset SCCB */
1258         i++;
1259         msleep(20);
1260         while (ov7660_sensor_init[i][0]) {
1261                 i2c_w8(gspca_dev, ov7660_sensor_init[i]);
1262                 i++;
1263         }
1264 }
1265
1266 static void sp80708_InitSensor(struct gspca_dev *gspca_dev)
1267 {
1268         int i = 0;
1269
1270         i2c_w8(gspca_dev, sp80708_sensor_init[i]);      /* reset SCCB */
1271         i++;
1272         msleep(20);
1273         while (sp80708_sensor_init[i][0]) {
1274                 i2c_w8(gspca_dev, sp80708_sensor_init[i]);
1275                 i++;
1276         }
1277 }
1278
1279 /* this function is called at probe time */
1280 static int sd_config(struct gspca_dev *gspca_dev,
1281                         const struct usb_device_id *id)
1282 {
1283         struct sd *sd = (struct sd *) gspca_dev;
1284         struct cam *cam;
1285
1286         cam = &gspca_dev->cam;
1287         cam->cam_mode = vga_mode;
1288         cam->nmodes = ARRAY_SIZE(vga_mode);
1289         cam->npkt = 24;                 /* 24 packets per ISOC message */
1290
1291         sd->bridge = id->driver_info >> 16;
1292         sd->sensor = id->driver_info >> 8;
1293         sd->i2c_base = id->driver_info;
1294
1295         sd->brightness = BRIGHTNESS_DEF;
1296         sd->contrast = CONTRAST_DEF;
1297         sd->colors = COLOR_DEF;
1298         sd->blue = BLUE_BALANCE_DEF;
1299         sd->red = RED_BALANCE_DEF;
1300         sd->gamma = GAMMA_DEF;
1301         sd->autogain = AUTOGAIN_DEF;
1302         sd->ag_cnt = -1;
1303         if (sd->sensor != SENSOR_OV7630)
1304                 sd->vflip = 0;
1305         else
1306                 sd->vflip = 1;
1307         sd->infrared = INFRARED_DEF;
1308         sd->quality = QUALITY_DEF;
1309         sd->jpegqual = 80;
1310
1311         gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
1312         return 0;
1313 }
1314
1315 /* this function is called at probe and resume time */
1316 static int sd_init(struct gspca_dev *gspca_dev)
1317 {
1318         struct sd *sd = (struct sd *) gspca_dev;
1319         u8 regGpio[] = { 0x29, 0x74 };
1320         u8 regF1;
1321
1322         /* setup a selector by bridge */
1323         reg_w1(gspca_dev, 0xf1, 0x01);
1324         reg_r(gspca_dev, 0x00, 1);
1325         reg_w1(gspca_dev, 0xf1, gspca_dev->usb_buf[0]);
1326         reg_r(gspca_dev, 0x00, 1);              /* get sonix chip id */
1327         regF1 = gspca_dev->usb_buf[0];
1328         PDEBUG(D_PROBE, "Sonix chip id: %02x", regF1);
1329         switch (sd->bridge) {
1330         case BRIDGE_SN9C102P:
1331                 if (regF1 != 0x11)
1332                         return -ENODEV;
1333                 reg_w1(gspca_dev, 0x02, regGpio[1]);
1334                 break;
1335         case BRIDGE_SN9C105:
1336                 if (regF1 != 0x11)
1337                         return -ENODEV;
1338                 if (sd->sensor == SENSOR_MI0360)
1339                         mi0360_probe(gspca_dev);
1340                 reg_w(gspca_dev, 0x01, regGpio, 2);
1341                 break;
1342         case BRIDGE_SN9C120:
1343                 if (regF1 != 0x12)
1344                         return -ENODEV;
1345                 if (sd->sensor == SENSOR_MI0360)
1346                         mi0360_probe(gspca_dev);
1347                 regGpio[1] = 0x70;
1348                 reg_w(gspca_dev, 0x01, regGpio, 2);
1349                 break;
1350         default:
1351 /*      case BRIDGE_SN9C110: */
1352 /*      case BRIDGE_SN9C325: */
1353                 if (regF1 != 0x12)
1354                         return -ENODEV;
1355                 reg_w1(gspca_dev, 0x02, 0x62);
1356                 break;
1357         }
1358
1359         reg_w1(gspca_dev, 0xf1, 0x01);
1360
1361         return 0;
1362 }
1363
1364 static u32 setexposure(struct gspca_dev *gspca_dev,
1365                         u32 expo)
1366 {
1367         struct sd *sd = (struct sd *) gspca_dev;
1368
1369         switch (sd->sensor) {
1370         case SENSOR_HV7131R: {
1371                 u8 Expodoit[] =
1372                         { 0xc1, 0x11, 0x25, 0x07, 0x27, 0xc0, 0x00, 0x16 };
1373
1374                 Expodoit[3] = expo >> 16;
1375                 Expodoit[4] = expo >> 8;
1376                 Expodoit[5] = expo;
1377                 i2c_w8(gspca_dev, Expodoit);
1378                 break;
1379             }
1380         case SENSOR_MI0360: {
1381                 u8 expoMi[] =           /* exposure 0x0635 -> 4 fp/s 0x10 */
1382                         { 0xb1, 0x5d, 0x09, 0x06, 0x35, 0x00, 0x00, 0x16 };
1383                 static const u8 doit[] =                /* update sensor */
1384                         { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
1385                 static const u8 sensorgo[] =            /* sensor on */
1386                         { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
1387
1388                 if (expo > 0x0635)
1389                         expo = 0x0635;
1390                 else if (expo < 0x0001)
1391                         expo = 0x0001;
1392                 expoMi[3] = expo >> 8;
1393                 expoMi[4] = expo;
1394                 i2c_w8(gspca_dev, expoMi);
1395                 i2c_w8(gspca_dev, doit);
1396                 i2c_w8(gspca_dev, sensorgo);
1397                 break;
1398             }
1399         case SENSOR_MO4000: {
1400                 u8 expoMof[] =
1401                         { 0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10 };
1402                 u8 expoMo10[] =
1403                         { 0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10 };
1404                 static const u8 gainMo[] =
1405                         { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
1406
1407                 if (expo > 0x1fff)
1408                         expo = 0x1fff;
1409                 else if (expo < 0x0001)
1410                         expo = 0x0001;
1411                 expoMof[3] = (expo & 0x03fc) >> 2;
1412                 i2c_w8(gspca_dev, expoMof);
1413                 expoMo10[3] = ((expo & 0x1c00) >> 10)
1414                                 | ((expo & 0x0003) << 4);
1415                 i2c_w8(gspca_dev, expoMo10);
1416                 i2c_w8(gspca_dev, gainMo);
1417                 PDEBUG(D_FRAM, "set exposure %d",
1418                         ((expoMo10[3] & 0x07) << 10)
1419                         | (expoMof[3] << 2)
1420                         | ((expoMo10[3] & 0x30) >> 4));
1421                 break;
1422             }
1423         case SENSOR_MT9V111: {
1424                 u8 expo_c1[] =
1425                         { 0xb1, 0x5c, 0x09, 0x00, 0x00, 0x00, 0x00, 0x10 };
1426
1427                 if (expo > 0x0280)
1428                         expo = 0x0280;
1429                 else if (expo < 0x0040)
1430                         expo = 0x0040;
1431                 expo_c1[3] = expo >> 8;
1432                 expo_c1[4] = expo;
1433                 i2c_w8(gspca_dev, expo_c1);
1434                 break;
1435             }
1436         case SENSOR_OM6802: {
1437                 u8 gainOm[] =
1438                         { 0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10 };
1439
1440                 if (expo > 0x03ff)
1441                         expo = 0x03ff;
1442                  if (expo < 0x0001)
1443                         expo = 0x0001;
1444                 gainOm[3] = expo >> 2;
1445                 i2c_w8(gspca_dev, gainOm);
1446                 reg_w1(gspca_dev, 0x96, (expo >> 5) & 0x1f);
1447                 PDEBUG(D_FRAM, "set exposure %d", gainOm[3]);
1448                 break;
1449             }
1450         }
1451         return expo;
1452 }
1453
1454 static void setbrightness(struct gspca_dev *gspca_dev)
1455 {
1456         struct sd *sd = (struct sd *) gspca_dev;
1457         unsigned int expo;
1458         u8 k2;
1459
1460         k2 = ((int) sd->brightness - 0x8000) >> 10;
1461         switch (sd->sensor) {
1462         case SENSOR_HV7131R:
1463                 expo = sd->brightness << 4;
1464                 if (expo > 0x002dc6c0)
1465                         expo = 0x002dc6c0;
1466                 else if (expo < 0x02a0)
1467                         expo = 0x02a0;
1468                 sd->exposure = setexposure(gspca_dev, expo);
1469                 break;
1470         case SENSOR_MI0360:
1471         case SENSOR_MO4000:
1472                 expo = sd->brightness >> 4;
1473                 sd->exposure = setexposure(gspca_dev, expo);
1474                 break;
1475         case SENSOR_MT9V111:
1476                 expo = sd->brightness >> 8;
1477                 sd->exposure = setexposure(gspca_dev, expo);
1478                 break;
1479         case SENSOR_OM6802:
1480                 expo = sd->brightness >> 6;
1481                 sd->exposure = setexposure(gspca_dev, expo);
1482                 k2 = sd->brightness >> 11;
1483                 break;
1484         }
1485
1486         if (sd->sensor != SENSOR_MT9V111)
1487                 reg_w1(gspca_dev, 0x96, k2);    /* color matrix Y offset */
1488 }
1489
1490 static void setcontrast(struct gspca_dev *gspca_dev)
1491 {
1492         struct sd *sd = (struct sd *) gspca_dev;
1493         u8 k2;
1494         u8 contrast[6];
1495
1496         k2 = sd->contrast * 0x30 / (CONTRAST_MAX + 1) + 0x10;   /* 10..40 */
1497         contrast[0] = (k2 + 1) / 2;             /* red */
1498         contrast[1] = 0;
1499         contrast[2] = k2;                       /* green */
1500         contrast[3] = 0;
1501         contrast[4] = (k2 + 1) / 5;             /* blue */
1502         contrast[5] = 0;
1503         reg_w(gspca_dev, 0x84, contrast, sizeof contrast);
1504 }
1505
1506 static void setcolors(struct gspca_dev *gspca_dev)
1507 {
1508         struct sd *sd = (struct sd *) gspca_dev;
1509         int i, v;
1510         u8 reg8a[12];                   /* U & V gains */
1511         static s16 uv[6] = {            /* same as reg84 in signed decimal */
1512                 -24, -38, 64,           /* UR UG UB */
1513                  62, -51, -9            /* VR VG VB */
1514         };
1515         for (i = 0; i < 6; i++) {
1516                 v = uv[i] * sd->colors / COLOR_DEF;
1517                 reg8a[i * 2] = v;
1518                 reg8a[i * 2 + 1] = (v >> 8) & 0x0f;
1519         }
1520         reg_w(gspca_dev, 0x8a, reg8a, sizeof reg8a);
1521 }
1522
1523 static void setredblue(struct gspca_dev *gspca_dev)
1524 {
1525         struct sd *sd = (struct sd *) gspca_dev;
1526
1527         reg_w1(gspca_dev, 0x05, sd->red);
1528 /*      reg_w1(gspca_dev, 0x07, 32); */
1529         reg_w1(gspca_dev, 0x06, sd->blue);
1530 }
1531
1532 static void setgamma(struct gspca_dev *gspca_dev)
1533 {
1534         struct sd *sd = (struct sd *) gspca_dev;
1535         int i;
1536         u8 gamma[17];
1537         const u8 *gamma_base;
1538         static const u8 delta[17] = {
1539                 0x00, 0x14, 0x1c, 0x1c, 0x1c, 0x1c, 0x1b, 0x1a,
1540                 0x18, 0x13, 0x10, 0x0e, 0x08, 0x07, 0x04, 0x02, 0x00
1541         };
1542
1543         switch (sd->sensor) {
1544         case SENSOR_HV7131R:
1545         case SENSOR_MT9V111:
1546                 gamma_base = gamma_spec_1;
1547                 break;
1548         case SENSOR_SP80708:
1549                 gamma_base = gamma_spec_2;
1550                 break;
1551         default:
1552                 gamma_base = gamma_def;
1553                 break;
1554         }
1555
1556         for (i = 0; i < sizeof gamma; i++)
1557                 gamma[i] = gamma_base[i]
1558                         + delta[i] * (sd->gamma - GAMMA_DEF) / 32;
1559         reg_w(gspca_dev, 0x20, gamma, sizeof gamma);
1560 }
1561
1562 static void setautogain(struct gspca_dev *gspca_dev)
1563 {
1564         struct sd *sd = (struct sd *) gspca_dev;
1565
1566         if (gspca_dev->ctrl_dis & (1 << AUTOGAIN_IDX))
1567                 return;
1568         switch (sd->sensor) {
1569         case SENSOR_OV7630:
1570         case SENSOR_OV7648: {
1571                 u8 comb;
1572
1573                 if (sd->sensor == SENSOR_OV7630)
1574                         comb = 0xc0;
1575                 else
1576                         comb = 0xa0;
1577                 if (sd->autogain)
1578                         comb |= 0x02;
1579                 i2c_w1(&sd->gspca_dev, 0x13, comb);
1580                 return;
1581             }
1582         }
1583         if (sd->autogain)
1584                 sd->ag_cnt = AG_CNT_START;
1585         else
1586                 sd->ag_cnt = -1;
1587 }
1588
1589 /* ov7630/ov7648 only */
1590 static void setvflip(struct sd *sd)
1591 {
1592         u8 comn;
1593
1594         if (sd->sensor == SENSOR_OV7630)
1595                 comn = 0x02;
1596         else
1597                 comn = 0x06;
1598         if (sd->vflip)
1599                 comn |= 0x80;
1600         i2c_w1(&sd->gspca_dev, 0x75, comn);
1601 }
1602
1603 static void setinfrared(struct sd *sd)
1604 {
1605 /*fixme: different sequence for StarCam Clip and StarCam 370i */
1606 /* Clip */
1607         i2c_w1(&sd->gspca_dev, 0x02,                    /* gpio */
1608                 sd->infrared ? 0x66 : 0x64);
1609 }
1610
1611 static void setjpegqual(struct gspca_dev *gspca_dev)
1612 {
1613         struct sd *sd = (struct sd *) gspca_dev;
1614         int i, sc;
1615
1616         if (sd->jpegqual < 50)
1617                 sc = 5000 / sd->jpegqual;
1618         else
1619                 sc = 200 - sd->jpegqual * 2;
1620 #if USB_BUF_SZ < 64
1621 #error "No room enough in usb_buf for quantization table"
1622 #endif
1623         for (i = 0; i < 64; i++)
1624                 gspca_dev->usb_buf[i] =
1625                         (jpeg_head[JPEG_QT0_OFFSET + i] * sc + 50) / 100;
1626         usb_control_msg(gspca_dev->dev,
1627                         usb_sndctrlpipe(gspca_dev->dev, 0),
1628                         0x08,
1629                         USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1630                         0x0100, 0,
1631                         gspca_dev->usb_buf, 64,
1632                         500);
1633         for (i = 0; i < 64; i++)
1634                 gspca_dev->usb_buf[i] =
1635                         (jpeg_head[JPEG_QT1_OFFSET + i] * sc + 50) / 100;
1636         usb_control_msg(gspca_dev->dev,
1637                         usb_sndctrlpipe(gspca_dev->dev, 0),
1638                         0x08,
1639                         USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1640                         0x0140, 0,
1641                         gspca_dev->usb_buf, 64,
1642                         500);
1643
1644         sd->reg18 ^= 0x40;
1645         reg_w1(gspca_dev, 0x18, sd->reg18);
1646 }
1647
1648 /* -- start the camera -- */
1649 static int sd_start(struct gspca_dev *gspca_dev)
1650 {
1651         struct sd *sd = (struct sd *) gspca_dev;
1652         int i;
1653         u8 reg1, reg17;
1654         const u8 *sn9c1xx;
1655         int mode;
1656         static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
1657         static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
1658         static const u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd };      /* MI0360 */
1659         static const u8 CE_ov76xx[] =
1660                                 { 0x32, 0xdd, 0x32, 0xdd };
1661
1662         /* create the JPEG header */
1663         sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
1664         jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
1665                         0x21);          /* JPEG 422 */
1666         jpeg_set_qual(sd->jpeg_hdr, sd->quality);
1667
1668         sn9c1xx = sn_tb[(int) sd->sensor];
1669         configure_gpio(gspca_dev, sn9c1xx);
1670
1671         reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]);
1672         reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]);
1673         reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
1674         reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]);
1675         reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
1676         reg_w1(gspca_dev, 0xd2, 0x6a);          /* DC29 */
1677         reg_w1(gspca_dev, 0xd3, 0x50);
1678         reg_w1(gspca_dev, 0xc6, 0x00);
1679         reg_w1(gspca_dev, 0xc7, 0x00);
1680         reg_w1(gspca_dev, 0xc8, 0x50);
1681         reg_w1(gspca_dev, 0xc9, 0x3c);
1682         reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
1683         switch (sd->sensor) {
1684         case SENSOR_MT9V111:
1685                 reg17 = 0xe0;
1686                 break;
1687         case SENSOR_OV7630:
1688                 reg17 = 0xe2;
1689                 break;
1690         case SENSOR_OV7648:
1691                 reg17 = 0x20;
1692                 break;
1693         case SENSOR_OV7660:
1694                 reg17 = 0xa0;
1695                 break;
1696         default:
1697                 reg17 = 0x60;
1698                 break;
1699         }
1700         reg_w1(gspca_dev, 0x17, reg17);
1701 /* set reg1 was here */
1702         reg_w1(gspca_dev, 0x05, sn9c1xx[5]);    /* red */
1703         reg_w1(gspca_dev, 0x07, sn9c1xx[7]);    /* green */
1704         reg_w1(gspca_dev, 0x06, sn9c1xx[6]);    /* blue */
1705         reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
1706
1707         setgamma(gspca_dev);
1708
1709         for (i = 0; i < 8; i++)
1710                 reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
1711         switch (sd->sensor) {
1712         case SENSOR_MT9V111:
1713                 reg_w1(gspca_dev, 0x9a, 0x07);
1714                 reg_w1(gspca_dev, 0x99, 0x59);
1715                 break;
1716         case SENSOR_OV7648:
1717                 reg_w1(gspca_dev, 0x9a, 0x0a);
1718                 reg_w1(gspca_dev, 0x99, 0x60);
1719                 break;
1720         case SENSOR_OV7660:
1721                 reg_w1(gspca_dev, 0x9a, 0x05);
1722                 if (sd->bridge == BRIDGE_SN9C105)
1723                         reg_w1(gspca_dev, 0x99, 0xff);
1724                 else
1725                         reg_w1(gspca_dev, 0x99, 0x5b);
1726                 break;
1727         case SENSOR_SP80708:
1728                 reg_w1(gspca_dev, 0x9a, 0x05);
1729                 reg_w1(gspca_dev, 0x99, 0x59);
1730                 break;
1731         default:
1732                 reg_w1(gspca_dev, 0x9a, 0x08);
1733                 reg_w1(gspca_dev, 0x99, 0x59);
1734                 break;
1735         }
1736
1737         mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
1738         if (mode)
1739                 reg1 = 0x46;    /* 320x240: clk 48Mhz, video trf enable */
1740         else
1741                 reg1 = 0x06;    /* 640x480: clk 24Mhz, video trf enable */
1742         reg17 = 0x61;           /* 0x:20: enable sensor clock */
1743         switch (sd->sensor) {
1744         case SENSOR_HV7131R:
1745                 hv7131R_InitSensor(gspca_dev);
1746                 break;
1747         case SENSOR_MI0360:
1748                 mi0360_InitSensor(gspca_dev);
1749                 break;
1750         case SENSOR_MO4000:
1751                 mo4000_InitSensor(gspca_dev);
1752                 if (mode) {
1753 /*                      reg1 = 0x46;     * 320 clk 48Mhz 60fp/s */
1754                         reg1 = 0x06;    /* clk 24Mz */
1755                 } else {
1756                         reg17 = 0x22;   /* 640 MCKSIZE */
1757 /*                      reg1 = 0x06;     * 640 clk 24Mz (done) */
1758                 }
1759                 break;
1760         case SENSOR_MT9V111:
1761                 mt9v111_InitSensor(gspca_dev);
1762                 if (mode) {
1763                         reg1 = 0x04;    /* 320 clk 48Mhz */
1764                 } else {
1765 /*                      reg1 = 0x06;     * 640 clk 24Mz (done) */
1766                         reg17 = 0xc2;
1767                 }
1768                 break;
1769         case SENSOR_OM6802:
1770                 om6802_InitSensor(gspca_dev);
1771                 reg17 = 0x64;           /* 640 MCKSIZE */
1772                 break;
1773         case SENSOR_OV7630:
1774                 ov7630_InitSensor(gspca_dev);
1775                 setvflip(sd);
1776                 reg17 = 0xe2;
1777                 reg1 = 0x44;
1778                 break;
1779         case SENSOR_OV7648:
1780                 ov7648_InitSensor(gspca_dev);
1781                 reg17 = 0x21;
1782 /*              reg1 = 0x42;             * 42 - 46? */
1783                 break;
1784         case SENSOR_OV7660:
1785                 ov7660_InitSensor(gspca_dev);
1786                 if (sd->bridge == BRIDGE_SN9C120) {
1787                         if (mode) {             /* 320x240 - 160x120 */
1788                                 reg17 = 0xa2;
1789                                 reg1 = 0x44;    /* 48 Mhz, video trf eneble */
1790                         }
1791                 } else {
1792                         reg17 = 0x22;
1793                         reg1 = 0x06;    /* 24 Mhz, video trf eneble
1794                                          * inverse power down */
1795                 }
1796                 break;
1797         default:
1798 /*      case SENSOR_SP80708: */
1799                 sp80708_InitSensor(gspca_dev);
1800                 if (mode) {
1801 /*??                    reg1 = 0x04;     * 320 clk 48Mhz */
1802                 } else {
1803                         reg1 = 0x46;     /* 640 clk 48Mz */
1804                         reg17 = 0xa2;
1805                 }
1806                 break;
1807         }
1808         reg_w(gspca_dev, 0xc0, C0, 6);
1809         reg_w(gspca_dev, 0xca, CA, 4);
1810         switch (sd->sensor) {
1811         case SENSOR_OV7630:
1812         case SENSOR_OV7648:
1813         case SENSOR_OV7660:
1814                 reg_w(gspca_dev, 0xce, CE_ov76xx, 4);
1815                 break;
1816         default:
1817                 reg_w(gspca_dev, 0xce, CE, 4);
1818                                         /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */
1819                 break;
1820         }
1821
1822         /* here change size mode 0 -> VGA; 1 -> CIF */
1823         sd->reg18 = sn9c1xx[0x18] | (mode << 4) | 0x40;
1824         reg_w1(gspca_dev, 0x18, sd->reg18);
1825         setjpegqual(gspca_dev);
1826
1827         reg_w1(gspca_dev, 0x17, reg17);
1828         reg_w1(gspca_dev, 0x01, reg1);
1829         switch (sd->sensor) {
1830         case SENSOR_OV7630:
1831                 setvflip(sd);
1832                 break;
1833         }
1834         setbrightness(gspca_dev);
1835         setcontrast(gspca_dev);
1836         setautogain(gspca_dev);
1837         return 0;
1838 }
1839
1840 static void sd_stopN(struct gspca_dev *gspca_dev)
1841 {
1842         struct sd *sd = (struct sd *) gspca_dev;
1843         static const u8 stophv7131[] =
1844                 { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
1845         static const u8 stopmi0360[] =
1846                 { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
1847         static const u8 stopov7648[] =
1848                 { 0xa1, 0x21, 0x76, 0x20, 0x00, 0x00, 0x00, 0x10 };
1849         u8 data;
1850         const u8 *sn9c1xx;
1851
1852         data = 0x0b;
1853         switch (sd->sensor) {
1854         case SENSOR_HV7131R:
1855                 i2c_w8(gspca_dev, stophv7131);
1856                 data = 0x2b;
1857                 break;
1858         case SENSOR_MI0360:
1859                 i2c_w8(gspca_dev, stopmi0360);
1860                 data = 0x29;
1861                 break;
1862         case SENSOR_OV7648:
1863                 i2c_w8(gspca_dev, stopov7648);
1864                 /* fall thru */
1865         case SENSOR_MT9V111:
1866         case SENSOR_OV7630:
1867                 data = 0x29;
1868                 break;
1869         default:
1870 /*      case SENSOR_MO4000: */
1871 /*      case SENSOR_OV7660: */
1872                 break;
1873         }
1874         sn9c1xx = sn_tb[(int) sd->sensor];
1875         reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
1876         reg_w1(gspca_dev, 0x17, sn9c1xx[0x17]);
1877         reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
1878         reg_w1(gspca_dev, 0x01, data);
1879         reg_w1(gspca_dev, 0xf1, 0x00);
1880 }
1881
1882 static void sd_stop0(struct gspca_dev *gspca_dev)
1883 {
1884         struct sd *sd = (struct sd *) gspca_dev;
1885
1886         kfree(sd->jpeg_hdr);
1887 }
1888
1889 static void do_autogain(struct gspca_dev *gspca_dev)
1890 {
1891         struct sd *sd = (struct sd *) gspca_dev;
1892         int delta;
1893         int expotimes;
1894         u8 luma_mean = 130;
1895         u8 luma_delta = 20;
1896
1897         /* Thanks S., without your advice, autobright should not work :) */
1898         if (sd->ag_cnt < 0)
1899                 return;
1900         if (--sd->ag_cnt >= 0)
1901                 return;
1902         sd->ag_cnt = AG_CNT_START;
1903
1904         delta = atomic_read(&sd->avg_lum);
1905         PDEBUG(D_FRAM, "mean lum %d", delta);
1906         if (delta < luma_mean - luma_delta ||
1907             delta > luma_mean + luma_delta) {
1908                 switch (sd->sensor) {
1909                 case SENSOR_HV7131R:
1910                         expotimes = sd->exposure >> 8;
1911                         expotimes += (luma_mean - delta) >> 4;
1912                         if (expotimes < 0)
1913                                 expotimes = 0;
1914                         sd->exposure = setexposure(gspca_dev,
1915                                         (unsigned int) (expotimes << 8));
1916                         break;
1917                 default:
1918 /*              case SENSOR_MO4000: */
1919 /*              case SENSOR_MI0360: */
1920 /*              case SENSOR_MT9V111: */
1921 /*              case SENSOR_OM6802: */
1922                         expotimes = sd->exposure;
1923                         expotimes += (luma_mean - delta) >> 6;
1924                         if (expotimes < 0)
1925                                 expotimes = 0;
1926                         sd->exposure = setexposure(gspca_dev,
1927                                                    (unsigned int) expotimes);
1928                         setredblue(gspca_dev);
1929                         break;
1930                 }
1931         }
1932 }
1933
1934 /* scan the URB packets */
1935 /* This function is run at interrupt level. */
1936 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1937                         struct gspca_frame *frame,      /* target */
1938                         u8 *data,                       /* isoc packet */
1939                         int len)                        /* iso packet length */
1940 {
1941         struct sd *sd = (struct sd *) gspca_dev;
1942         int sof, avg_lum;
1943
1944         sof = len - 64;
1945         if (sof >= 0 && data[sof] == 0xff && data[sof + 1] == 0xd9) {
1946
1947                 /* end of frame */
1948                 gspca_frame_add(gspca_dev, LAST_PACKET,
1949                                 frame, data, sof + 2);
1950                 if (sd->ag_cnt < 0)
1951                         return;
1952 /* w1 w2 w3 */
1953 /* w4 w5 w6 */
1954 /* w7 w8 */
1955 /* w4 */
1956                 avg_lum = ((data[sof + 29] << 8) | data[sof + 30]) >> 6;
1957 /* w6 */
1958                 avg_lum += ((data[sof + 33] << 8) | data[sof + 34]) >> 6;
1959 /* w2 */
1960                 avg_lum += ((data[sof + 25] << 8) | data[sof + 26]) >> 6;
1961 /* w8 */
1962                 avg_lum += ((data[sof + 37] << 8) | data[sof + 38]) >> 6;
1963 /* w5 */
1964                 avg_lum += ((data[sof + 31] << 8) | data[sof + 32]) >> 4;
1965                 avg_lum >>= 4;
1966                 atomic_set(&sd->avg_lum, avg_lum);
1967                 return;
1968         }
1969         if (gspca_dev->last_packet_type == LAST_PACKET) {
1970
1971                 /* put the JPEG 422 header */
1972                 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
1973                         sd->jpeg_hdr, JPEG_HDR_SZ);
1974         }
1975         gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
1976 }
1977
1978 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
1979 {
1980         struct sd *sd = (struct sd *) gspca_dev;
1981
1982         sd->brightness = val;
1983         if (gspca_dev->streaming)
1984                 setbrightness(gspca_dev);
1985         return 0;
1986 }
1987
1988 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
1989 {
1990         struct sd *sd = (struct sd *) gspca_dev;
1991
1992         *val = sd->brightness;
1993         return 0;
1994 }
1995
1996 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
1997 {
1998         struct sd *sd = (struct sd *) gspca_dev;
1999
2000         sd->contrast = val;
2001         if (gspca_dev->streaming)
2002                 setcontrast(gspca_dev);
2003         return 0;
2004 }
2005
2006 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
2007 {
2008         struct sd *sd = (struct sd *) gspca_dev;
2009
2010         *val = sd->contrast;
2011         return 0;
2012 }
2013
2014 static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
2015 {
2016         struct sd *sd = (struct sd *) gspca_dev;
2017
2018         sd->colors = val;
2019         if (gspca_dev->streaming)
2020                 setcolors(gspca_dev);
2021         return 0;
2022 }
2023
2024 static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
2025 {
2026         struct sd *sd = (struct sd *) gspca_dev;
2027
2028         *val = sd->colors;
2029         return 0;
2030 }
2031
2032 static int sd_setblue_balance(struct gspca_dev *gspca_dev, __s32 val)
2033 {
2034         struct sd *sd = (struct sd *) gspca_dev;
2035
2036         sd->blue = val;
2037         if (gspca_dev->streaming)
2038                 setredblue(gspca_dev);
2039         return 0;
2040 }
2041
2042 static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val)
2043 {
2044         struct sd *sd = (struct sd *) gspca_dev;
2045
2046         *val = sd->blue;
2047         return 0;
2048 }
2049
2050 static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val)
2051 {
2052         struct sd *sd = (struct sd *) gspca_dev;
2053
2054         sd->red = val;
2055         if (gspca_dev->streaming)
2056                 setredblue(gspca_dev);
2057         return 0;
2058 }
2059
2060 static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val)
2061 {
2062         struct sd *sd = (struct sd *) gspca_dev;
2063
2064         *val = sd->red;
2065         return 0;
2066 }
2067
2068 static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val)
2069 {
2070         struct sd *sd = (struct sd *) gspca_dev;
2071
2072         sd->gamma = val;
2073         if (gspca_dev->streaming)
2074                 setgamma(gspca_dev);
2075         return 0;
2076 }
2077
2078 static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val)
2079 {
2080         struct sd *sd = (struct sd *) gspca_dev;
2081
2082         *val = sd->gamma;
2083         return 0;
2084 }
2085
2086 static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
2087 {
2088         struct sd *sd = (struct sd *) gspca_dev;
2089
2090         sd->autogain = val;
2091         if (gspca_dev->streaming)
2092                 setautogain(gspca_dev);
2093         return 0;
2094 }
2095
2096 static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
2097 {
2098         struct sd *sd = (struct sd *) gspca_dev;
2099
2100         *val = sd->autogain;
2101         return 0;
2102 }
2103
2104 static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
2105 {
2106         struct sd *sd = (struct sd *) gspca_dev;
2107
2108         sd->vflip = val;
2109         if (gspca_dev->streaming)
2110                 setvflip(sd);
2111         return 0;
2112 }
2113
2114 static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
2115 {
2116         struct sd *sd = (struct sd *) gspca_dev;
2117
2118         *val = sd->vflip;
2119         return 0;
2120 }
2121
2122 static int sd_setinfrared(struct gspca_dev *gspca_dev, __s32 val)
2123 {
2124         struct sd *sd = (struct sd *) gspca_dev;
2125
2126         sd->infrared = val;
2127         if (gspca_dev->streaming)
2128                 setinfrared(sd);
2129         return 0;
2130 }
2131
2132 static int sd_getinfrared(struct gspca_dev *gspca_dev, __s32 *val)
2133 {
2134         struct sd *sd = (struct sd *) gspca_dev;
2135
2136         *val = sd->infrared;
2137         return 0;
2138 }
2139
2140 static int sd_set_jcomp(struct gspca_dev *gspca_dev,
2141                         struct v4l2_jpegcompression *jcomp)
2142 {
2143         struct sd *sd = (struct sd *) gspca_dev;
2144
2145         if (jcomp->quality < QUALITY_MIN)
2146                 sd->quality = QUALITY_MIN;
2147         else if (jcomp->quality > QUALITY_MAX)
2148                 sd->quality = QUALITY_MAX;
2149         else
2150                 sd->quality = jcomp->quality;
2151         if (gspca_dev->streaming)
2152                 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
2153         return 0;
2154 }
2155
2156 static int sd_get_jcomp(struct gspca_dev *gspca_dev,
2157                         struct v4l2_jpegcompression *jcomp)
2158 {
2159         struct sd *sd = (struct sd *) gspca_dev;
2160
2161         memset(jcomp, 0, sizeof *jcomp);
2162         jcomp->quality = sd->quality;
2163         jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
2164                         | V4L2_JPEG_MARKER_DQT;
2165         return 0;
2166 }
2167
2168 /* sub-driver description */
2169 static const struct sd_desc sd_desc = {
2170         .name = MODULE_NAME,
2171         .ctrls = sd_ctrls,
2172         .nctrls = ARRAY_SIZE(sd_ctrls),
2173         .config = sd_config,
2174         .init = sd_init,
2175         .start = sd_start,
2176         .stopN = sd_stopN,
2177         .stop0 = sd_stop0,
2178         .pkt_scan = sd_pkt_scan,
2179         .dq_callback = do_autogain,
2180         .get_jcomp = sd_get_jcomp,
2181         .set_jcomp = sd_set_jcomp,
2182 };
2183
2184 /* -- module initialisation -- */
2185 #define BSI(bridge, sensor, i2c_addr) \
2186         .driver_info = (BRIDGE_ ## bridge << 16) \
2187                         | (SENSOR_ ## sensor << 8) \
2188                         | (i2c_addr)
2189 static const __devinitdata struct usb_device_id device_table[] = {
2190 #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
2191         {USB_DEVICE(0x0458, 0x7025), BSI(SN9C120, MI0360, 0x5d)},
2192         {USB_DEVICE(0x0458, 0x702e), BSI(SN9C120, OV7660, 0x21)},
2193 #endif
2194         {USB_DEVICE(0x045e, 0x00f5), BSI(SN9C105, OV7660, 0x21)},
2195         {USB_DEVICE(0x045e, 0x00f7), BSI(SN9C105, OV7660, 0x21)},
2196         {USB_DEVICE(0x0471, 0x0327), BSI(SN9C105, MI0360, 0x5d)},
2197         {USB_DEVICE(0x0471, 0x0328), BSI(SN9C105, MI0360, 0x5d)},
2198         {USB_DEVICE(0x0471, 0x0330), BSI(SN9C105, MI0360, 0x5d)},
2199         {USB_DEVICE(0x06f8, 0x3004), BSI(SN9C105, OV7660, 0x21)},
2200         {USB_DEVICE(0x06f8, 0x3008), BSI(SN9C105, OV7660, 0x21)},
2201         {USB_DEVICE(0x0c45, 0x6040), BSI(SN9C102P, HV7131R, 0x11)},
2202 /* bw600.inf:
2203         {USB_DEVICE(0x0c45, 0x6040), BSI(SN9C102P, MI0360, 0x5d)}, */
2204 /*      {USB_DEVICE(0x0c45, 0x603a), BSI(SN9C102P, OV7648, 0x??)}, */
2205 /*      {USB_DEVICE(0x0c45, 0x607a), BSI(SN9C102P, OV7648, 0x??)}, */
2206         {USB_DEVICE(0x0c45, 0x607c), BSI(SN9C102P, HV7131R, 0x11)},
2207 /*      {USB_DEVICE(0x0c45, 0x607e), BSI(SN9C102P, OV7630, 0x??)}, */
2208         {USB_DEVICE(0x0c45, 0x60c0), BSI(SN9C105, MI0360, 0x5d)},
2209 /*      {USB_DEVICE(0x0c45, 0x60c8), BSI(SN9C105, OM6801, 0x??)}, */
2210 /*      {USB_DEVICE(0x0c45, 0x60cc), BSI(SN9C105, HV7131GP, 0x??)}, */
2211         {USB_DEVICE(0x0c45, 0x60ec), BSI(SN9C105, MO4000, 0x21)},
2212 /*      {USB_DEVICE(0x0c45, 0x60ef), BSI(SN9C105, ICM105C, 0x??)}, */
2213 /*      {USB_DEVICE(0x0c45, 0x60fa), BSI(SN9C105, OV7648, 0x??)}, */
2214         {USB_DEVICE(0x0c45, 0x60fb), BSI(SN9C105, OV7660, 0x21)},
2215         {USB_DEVICE(0x0c45, 0x60fc), BSI(SN9C105, HV7131R, 0x11)},
2216 #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
2217         {USB_DEVICE(0x0c45, 0x60fe), BSI(SN9C105, OV7630, 0x21)},
2218 #endif
2219         {USB_DEVICE(0x0c45, 0x6100), BSI(SN9C120, MI0360, 0x5d)}, /*sn9c128*/
2220 /*      {USB_DEVICE(0x0c45, 0x6108), BSI(SN9C120, OM6801, 0x??)}, */
2221         {USB_DEVICE(0x0c45, 0x610a), BSI(SN9C120, OV7648, 0x21)}, /*sn9c128*/
2222         {USB_DEVICE(0x0c45, 0x610b), BSI(SN9C120, OV7660, 0x21)}, /*sn9c128*/
2223         {USB_DEVICE(0x0c45, 0x610c), BSI(SN9C120, HV7131R, 0x11)}, /*sn9c128*/
2224         {USB_DEVICE(0x0c45, 0x610e), BSI(SN9C120, OV7630, 0x21)}, /*sn9c128*/
2225 /*      {USB_DEVICE(0x0c45, 0x6122), BSI(SN9C110, ICM105C, 0x??)}, */
2226 /*      {USB_DEVICE(0x0c45, 0x6123), BSI(SN9C110, SanyoCCD, 0x??)}, */
2227         {USB_DEVICE(0x0c45, 0x6128), BSI(SN9C110, OM6802, 0x21)}, /*sn9c325?*/
2228 /*bw600.inf:*/
2229         {USB_DEVICE(0x0c45, 0x612a), BSI(SN9C120, OV7648, 0x21)}, /*sn9c110?*/
2230         {USB_DEVICE(0x0c45, 0x612c), BSI(SN9C110, MO4000, 0x21)},
2231         {USB_DEVICE(0x0c45, 0x612e), BSI(SN9C110, OV7630, 0x21)},
2232 /*      {USB_DEVICE(0x0c45, 0x612f), BSI(SN9C110, ICM105C, 0x??)}, */
2233 #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
2234         {USB_DEVICE(0x0c45, 0x6130), BSI(SN9C120, MI0360, 0x5d)},
2235 #endif
2236         {USB_DEVICE(0x0c45, 0x6138), BSI(SN9C120, MO4000, 0x21)},
2237         {USB_DEVICE(0x0c45, 0x613a), BSI(SN9C120, OV7648, 0x21)},
2238 #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
2239         {USB_DEVICE(0x0c45, 0x613b), BSI(SN9C120, OV7660, 0x21)},
2240 #endif
2241         {USB_DEVICE(0x0c45, 0x613c), BSI(SN9C120, HV7131R, 0x11)},
2242 /*      {USB_DEVICE(0x0c45, 0x613e), BSI(SN9C120, OV7630, 0x??)}, */
2243         {USB_DEVICE(0x0c45, 0x6143), BSI(SN9C120, SP80708, 0x18)},
2244         {}
2245 };
2246 MODULE_DEVICE_TABLE(usb, device_table);
2247
2248 /* -- device connect -- */
2249 static int sd_probe(struct usb_interface *intf,
2250                     const struct usb_device_id *id)
2251 {
2252         return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
2253                                 THIS_MODULE);
2254 }
2255
2256 static struct usb_driver sd_driver = {
2257         .name = MODULE_NAME,
2258         .id_table = device_table,
2259         .probe = sd_probe,
2260         .disconnect = gspca_disconnect,
2261 #ifdef CONFIG_PM
2262         .suspend = gspca_suspend,
2263         .resume = gspca_resume,
2264 #endif
2265 };
2266
2267 /* -- module insert / remove -- */
2268 static int __init sd_mod_init(void)
2269 {
2270         int ret;
2271         ret = usb_register(&sd_driver);
2272         if (ret < 0)
2273                 return ret;
2274         info("registered");
2275         return 0;
2276 }
2277 static void __exit sd_mod_exit(void)
2278 {
2279         usb_deregister(&sd_driver);
2280         info("deregistered");
2281 }
2282
2283 module_init(sd_mod_init);
2284 module_exit(sd_mod_exit);