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