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