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