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