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