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