blob: 01c4a20b787393590f9cfe32c0142354936a058c [file] [log] [blame]
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001/*
Jean-Francois Moine5b34e3e2009-11-02 10:00:48 -03002 * Sonix sn9c102p sn9c105 sn9c120 (jpeg) subdriver
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03003 *
Jean-François Moine27c6f9e2010-04-02 06:59:13 -03004 * Copyright (C) 2009-2010 Jean-François Moine <http://moinejf.free.fr>
Jean-Francois Moine5b34e3e2009-11-02 10:00:48 -03005 * Copyright (C) 2005 Michel Xhaard mxhaard@magic.fr
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#define MODULE_NAME "sonixj"
23
Hans de Goede9712a8b2010-01-31 12:54:29 -030024#include <linux/input.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030026#include "gspca.h"
27#include "jpeg.h"
28
Jean-Francois Moine0cae8962008-10-17 07:48:24 -030029#define V4L2_CID_INFRARED (V4L2_CID_PRIVATE_BASE + 0)
30
Jean-François Moine27c6f9e2010-04-02 06:59:13 -030031MODULE_AUTHOR("Jean-François Moine <http://moinejf.free.fr>");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030032MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
33MODULE_LICENSE("GPL");
34
35/* specific webcam descriptor */
36struct sd {
37 struct gspca_dev gspca_dev; /* !! must be the first item */
38
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -030039 atomic_t avg_lum;
Jean-Francois Moine98819182009-01-19 07:37:33 -030040 u32 exposure;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030041
Jean-Francois Moine98819182009-01-19 07:37:33 -030042 u16 brightness;
43 u8 contrast;
44 u8 colors;
45 u8 autogain;
46 u8 blue;
47 u8 red;
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -030048 u8 gamma;
Jean-Francois Moine2797ba22009-02-05 15:12:24 -030049 u8 vflip; /* ov7630/ov7648 only */
Jean-Francois Moine878b35a2009-12-30 04:53:07 -030050 u8 sharpness;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -030051 u8 infrared; /* mt9v111 only */
Hans de Goede37c6dbe2009-06-18 07:35:36 -030052 u8 freq; /* ov76xx only */
Jean-Francois Moine71cb2762009-03-03 05:33:41 -030053 u8 quality; /* image quality */
Jean-Francois Moine77ac0ba2009-03-02 06:40:52 -030054#define QUALITY_MIN 60
55#define QUALITY_MAX 95
56#define QUALITY_DEF 80
Jean-Francois Moine71cb2762009-03-03 05:33:41 -030057 u8 jpegqual; /* webcam quality */
58
59 u8 reg18;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030060
Jean-Francois Moine98819182009-01-19 07:37:33 -030061 s8 ag_cnt;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030062#define AG_CNT_START 13
63
Jean-Francois Moine98819182009-01-19 07:37:33 -030064 u8 bridge;
Hans de Goede3647fea2008-07-15 05:36:30 -030065#define BRIDGE_SN9C102P 0
66#define BRIDGE_SN9C105 1
67#define BRIDGE_SN9C110 2
68#define BRIDGE_SN9C120 3
Jean-Francois Moine98819182009-01-19 07:37:33 -030069 u8 sensor; /* Type of image sensor chip */
Jean-François Moine9c33afc2010-03-17 15:25:32 -030070enum {
71 SENSOR_ADCM1700,
Jean-François Moinead98c0f2010-03-18 05:15:30 -030072 SENSOR_GC0307,
Jean-François Moine9c33afc2010-03-17 15:25:32 -030073 SENSOR_HV7131R,
74 SENSOR_MI0360,
75 SENSOR_MO4000,
76 SENSOR_MT9V111,
77 SENSOR_OM6802,
78 SENSOR_OV7630,
79 SENSOR_OV7648,
80 SENSOR_OV7660,
81 SENSOR_PO1030,
Jean-François Moinead98c0f2010-03-18 05:15:30 -030082 SENSOR_PO2030N,
Jean-François Moine9c33afc2010-03-17 15:25:32 -030083 SENSOR_SP80708,
84} sensors;
Jean-Francois Moined5aa3852009-11-07 06:10:08 -030085 u8 i2c_addr;
Jean-Francois Moine71cb2762009-03-03 05:33:41 -030086
Jean-François Moine73e49342010-04-02 07:05:59 -030087 u8 jpeg_hdr[JPEG_HDR_SZ];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030088};
89
90/* V4L2 controls supported by the driver */
91static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
92static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
93static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
94static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
95static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
96static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine403123d2008-11-26 04:46:15 -030097static int sd_setblue_balance(struct gspca_dev *gspca_dev, __s32 val);
98static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val);
99static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val);
100static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -0300101static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val);
102static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300103static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
104static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine6c862742008-09-08 04:57:26 -0300105static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
106static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine878b35a2009-12-30 04:53:07 -0300107static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
108static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine0cae8962008-10-17 07:48:24 -0300109static int sd_setinfrared(struct gspca_dev *gspca_dev, __s32 val);
110static int sd_getinfrared(struct gspca_dev *gspca_dev, __s32 *val);
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300111static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
112static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300113
Marton Nemeth7e64dc42009-12-30 09:12:41 -0300114static const struct ctrl sd_ctrls[] = {
Hans de Goede97643982009-06-18 05:08:11 -0300115#define BRIGHTNESS_IDX 0
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300116 {
117 {
118 .id = V4L2_CID_BRIGHTNESS,
119 .type = V4L2_CTRL_TYPE_INTEGER,
120 .name = "Brightness",
121 .minimum = 0,
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300122#define BRIGHTNESS_MAX 0xffff
123 .maximum = BRIGHTNESS_MAX,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300124 .step = 1,
Jean-Francois Moineb1b056a2008-11-25 04:47:09 -0300125#define BRIGHTNESS_DEF 0x8000
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300126 .default_value = BRIGHTNESS_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300127 },
128 .set = sd_setbrightness,
129 .get = sd_getbrightness,
130 },
Hans de Goede97643982009-06-18 05:08:11 -0300131#define CONTRAST_IDX 1
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300132 {
133 {
134 .id = V4L2_CID_CONTRAST,
135 .type = V4L2_CTRL_TYPE_INTEGER,
136 .name = "Contrast",
137 .minimum = 0,
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300138#define CONTRAST_MAX 127
139 .maximum = CONTRAST_MAX,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300140 .step = 1,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300141#define CONTRAST_DEF 63
142 .default_value = CONTRAST_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300143 },
144 .set = sd_setcontrast,
145 .get = sd_getcontrast,
146 },
Hans de Goede97643982009-06-18 05:08:11 -0300147#define COLOR_IDX 2
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300148 {
149 {
150 .id = V4L2_CID_SATURATION,
151 .type = V4L2_CTRL_TYPE_INTEGER,
Hans de Goede3fb4a572009-06-18 14:31:36 -0300152 .name = "Saturation",
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300153 .minimum = 0,
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300154 .maximum = 40,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300155 .step = 1,
Hans de Goede3fb4a572009-06-18 14:31:36 -0300156#define COLOR_DEF 25
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300157 .default_value = COLOR_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300158 },
159 .set = sd_setcolors,
160 .get = sd_getcolors,
161 },
Hans de Goede97643982009-06-18 05:08:11 -0300162#define BLUE_BALANCE_IDX 3
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300163 {
164 {
165 .id = V4L2_CID_BLUE_BALANCE,
166 .type = V4L2_CTRL_TYPE_INTEGER,
167 .name = "Blue Balance",
168 .minimum = 24,
169 .maximum = 40,
170 .step = 1,
171#define BLUE_BALANCE_DEF 32
172 .default_value = BLUE_BALANCE_DEF,
173 },
174 .set = sd_setblue_balance,
175 .get = sd_getblue_balance,
176 },
Hans de Goede97643982009-06-18 05:08:11 -0300177#define RED_BALANCE_IDX 4
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300178 {
179 {
180 .id = V4L2_CID_RED_BALANCE,
181 .type = V4L2_CTRL_TYPE_INTEGER,
182 .name = "Red Balance",
183 .minimum = 24,
184 .maximum = 40,
185 .step = 1,
186#define RED_BALANCE_DEF 32
187 .default_value = RED_BALANCE_DEF,
188 },
189 .set = sd_setred_balance,
190 .get = sd_getred_balance,
191 },
Hans de Goede97643982009-06-18 05:08:11 -0300192#define GAMMA_IDX 5
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -0300193 {
194 {
195 .id = V4L2_CID_GAMMA,
196 .type = V4L2_CTRL_TYPE_INTEGER,
197 .name = "Gamma",
198 .minimum = 0,
199 .maximum = 40,
200 .step = 1,
201#define GAMMA_DEF 20
202 .default_value = GAMMA_DEF,
203 },
204 .set = sd_setgamma,
205 .get = sd_getgamma,
206 },
Hans de Goede97643982009-06-18 05:08:11 -0300207#define AUTOGAIN_IDX 6
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300208 {
209 {
210 .id = V4L2_CID_AUTOGAIN,
211 .type = V4L2_CTRL_TYPE_BOOLEAN,
212 .name = "Auto Gain",
213 .minimum = 0,
214 .maximum = 1,
215 .step = 1,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300216#define AUTOGAIN_DEF 1
217 .default_value = AUTOGAIN_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300218 },
219 .set = sd_setautogain,
220 .get = sd_getautogain,
221 },
Jean-Francois Moine2797ba22009-02-05 15:12:24 -0300222/* ov7630/ov7648 only */
Hans de Goede97643982009-06-18 05:08:11 -0300223#define VFLIP_IDX 7
Jean-Francois Moine6c862742008-09-08 04:57:26 -0300224 {
225 {
226 .id = V4L2_CID_VFLIP,
227 .type = V4L2_CTRL_TYPE_BOOLEAN,
228 .name = "Vflip",
229 .minimum = 0,
230 .maximum = 1,
231 .step = 1,
Hans de Goedef8009522009-06-18 14:29:20 -0300232#define VFLIP_DEF 0
Jean-Francois Moine6c862742008-09-08 04:57:26 -0300233 .default_value = VFLIP_DEF,
234 },
235 .set = sd_setvflip,
236 .get = sd_getvflip,
237 },
Jean-Francois Moine878b35a2009-12-30 04:53:07 -0300238#define SHARPNESS_IDX 8
239 {
240 {
241 .id = V4L2_CID_SHARPNESS,
242 .type = V4L2_CTRL_TYPE_INTEGER,
243 .name = "Sharpness",
244 .minimum = 0,
245 .maximum = 255,
246 .step = 1,
247#define SHARPNESS_DEF 90
248 .default_value = SHARPNESS_DEF,
249 },
250 .set = sd_setsharpness,
251 .get = sd_getsharpness,
252 },
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300253/* mt9v111 only */
Jean-Francois Moine878b35a2009-12-30 04:53:07 -0300254#define INFRARED_IDX 9
Jean-Francois Moine0cae8962008-10-17 07:48:24 -0300255 {
256 {
257 .id = V4L2_CID_INFRARED,
258 .type = V4L2_CTRL_TYPE_BOOLEAN,
259 .name = "Infrared",
260 .minimum = 0,
261 .maximum = 1,
262 .step = 1,
263#define INFRARED_DEF 0
264 .default_value = INFRARED_DEF,
265 },
266 .set = sd_setinfrared,
267 .get = sd_getinfrared,
268 },
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300269/* ov7630/ov7648/ov7660 only */
Jean-Francois Moine878b35a2009-12-30 04:53:07 -0300270#define FREQ_IDX 10
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300271 {
272 {
273 .id = V4L2_CID_POWER_LINE_FREQUENCY,
274 .type = V4L2_CTRL_TYPE_MENU,
275 .name = "Light frequency filter",
276 .minimum = 0,
277 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
278 .step = 1,
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -0300279#define FREQ_DEF 1
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300280 .default_value = FREQ_DEF,
281 },
282 .set = sd_setfreq,
283 .get = sd_getfreq,
284 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300285};
286
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300287/* table of the disabled controls */
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300288static const __u32 ctrl_dis[] = {
289[SENSOR_ADCM1700] = (1 << AUTOGAIN_IDX) |
290 (1 << INFRARED_IDX) |
291 (1 << VFLIP_IDX) |
292 (1 << FREQ_IDX),
293
Jean-François Moinec26b12d2010-04-02 07:08:39 -0300294[SENSOR_GC0307] = (1 << INFRARED_IDX) |
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300295 (1 << VFLIP_IDX) |
296 (1 << FREQ_IDX),
297
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300298[SENSOR_HV7131R] = (1 << INFRARED_IDX) |
299 (1 << FREQ_IDX),
300
301[SENSOR_MI0360] = (1 << INFRARED_IDX) |
302 (1 << VFLIP_IDX) |
303 (1 << FREQ_IDX),
304
305[SENSOR_MO4000] = (1 << INFRARED_IDX) |
306 (1 << VFLIP_IDX) |
307 (1 << FREQ_IDX),
308
309[SENSOR_MT9V111] = (1 << VFLIP_IDX) |
310 (1 << FREQ_IDX),
311
312[SENSOR_OM6802] = (1 << INFRARED_IDX) |
313 (1 << VFLIP_IDX) |
314 (1 << FREQ_IDX),
315
316[SENSOR_OV7630] = (1 << INFRARED_IDX),
317
318[SENSOR_OV7648] = (1 << INFRARED_IDX),
319
320[SENSOR_OV7660] = (1 << AUTOGAIN_IDX) |
321 (1 << INFRARED_IDX) |
322 (1 << VFLIP_IDX),
323
324[SENSOR_PO1030] = (1 << AUTOGAIN_IDX) |
325 (1 << INFRARED_IDX) |
326 (1 << VFLIP_IDX) |
327 (1 << FREQ_IDX),
328
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300329[SENSOR_PO2030N] = (1 << AUTOGAIN_IDX) |
330 (1 << INFRARED_IDX) |
331 (1 << VFLIP_IDX) |
332 (1 << FREQ_IDX),
333
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300334[SENSOR_SP80708] = (1 << AUTOGAIN_IDX) |
335 (1 << INFRARED_IDX) |
336 (1 << VFLIP_IDX) |
337 (1 << FREQ_IDX),
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300338};
339
Jean-Francois Moine64677572009-12-20 12:31:28 -0300340static const struct v4l2_pix_format cif_mode[] = {
341 {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
342 .bytesperline = 352,
343 .sizeimage = 352 * 288 * 4 / 8 + 590,
344 .colorspace = V4L2_COLORSPACE_JPEG,
345 .priv = 0},
346};
Jean-Francois Moinecc611b82008-12-29 07:49:41 -0300347static const struct v4l2_pix_format vga_mode[] = {
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300348 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
349 .bytesperline = 160,
Jean-Francois Moine5d052942008-09-03 16:48:09 -0300350 .sizeimage = 160 * 120 * 4 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300351 .colorspace = V4L2_COLORSPACE_JPEG,
352 .priv = 2},
353 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
354 .bytesperline = 320,
355 .sizeimage = 320 * 240 * 3 / 8 + 590,
356 .colorspace = V4L2_COLORSPACE_JPEG,
357 .priv = 1},
358 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
359 .bytesperline = 640,
Hans de Goedea5d1cc32009-06-18 06:03:20 -0300360 /* Note 3 / 8 is not large enough, not even 5 / 8 is ?! */
361 .sizeimage = 640 * 480 * 3 / 4 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300362 .colorspace = V4L2_COLORSPACE_JPEG,
363 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300364};
365
Jean-Francois Moine64677572009-12-20 12:31:28 -0300366static const u8 sn_adcm1700[0x1c] = {
367/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Jean-Francois Moine878b35a2009-12-30 04:53:07 -0300368 0x00, 0x43, 0x60, 0x00, 0x1a, 0x00, 0x00, 0x00,
Jean-Francois Moine64677572009-12-20 12:31:28 -0300369/* reg8 reg9 rega regb regc regd rege regf */
370 0x80, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
371/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
372 0x03, 0x00, 0x05, 0x01, 0x05, 0x16, 0x12, 0x42,
373/* reg18 reg19 reg1a reg1b */
374 0x06, 0x00, 0x00, 0x00
375};
376
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300377static const u8 sn_gc0307[0x1c] = {
378/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
379 0x00, 0x61, 0x62, 0x00, 0x1a, 0x00, 0x00, 0x00,
380/* reg8 reg9 rega regb regc regd rege regf */
381 0x80, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
382/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
383 0x03, 0x00, 0x03, 0x01, 0x08, 0x28, 0x1e, 0x02,
384/* reg18 reg19 reg1a reg1b */
385 0x06, 0x00, 0x00, 0x00
386};
387
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300388static const u8 sn_hv7131[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300389/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
390 0x00, 0x03, 0x64, 0x00, 0x1a, 0x20, 0x20, 0x20,
391/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300392 0x81, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300393/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
394 0x03, 0x00, 0x00, 0x01, 0x03, 0x28, 0x1e, 0x41,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300395/* reg18 reg19 reg1a reg1b */
396 0x0a, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300397};
398
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300399static const u8 sn_mi0360[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300400/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
401 0x00, 0x61, 0x44, 0x00, 0x1a, 0x20, 0x20, 0x20,
402/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300403 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300404/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
405 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x61,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300406/* reg18 reg19 reg1a reg1b */
407 0x06, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300408};
409
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300410static const u8 sn_mo4000[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300411/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300412 0x00, 0x23, 0x60, 0x00, 0x1a, 0x00, 0x20, 0x18,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300413/* reg8 reg9 rega regb regc regd rege regf */
414 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
415/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
416 0x03, 0x00, 0x0b, 0x0f, 0x14, 0x28, 0x1e, 0x40,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300417/* reg18 reg19 reg1a reg1b */
418 0x08, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300419};
420
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300421static const u8 sn_mt9v111[0x1c] = {
422/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
423 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
424/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300425 0x81, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300426/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
427 0x03, 0x00, 0x00, 0x02, 0x1c, 0x28, 0x1e, 0x40,
428/* reg18 reg19 reg1a reg1b */
429 0x06, 0x00, 0x00, 0x00
430};
431
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300432static const u8 sn_om6802[0x1c] = {
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300433/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Amauri Magagna46b4f2a2009-10-17 07:21:29 -0300434 0x00, 0x23, 0x72, 0x00, 0x1a, 0x20, 0x20, 0x19,
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300435/* reg8 reg9 rega regb regc regd rege regf */
436 0x80, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
437/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
438 0x03, 0x00, 0x51, 0x01, 0x00, 0x28, 0x1e, 0x40,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300439/* reg18 reg19 reg1a reg1b */
440 0x05, 0x00, 0x00, 0x00
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300441};
442
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300443static const u8 sn_ov7630[0x1c] = {
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300444/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
445 0x00, 0x21, 0x40, 0x00, 0x1a, 0x20, 0x1f, 0x20,
446/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300447 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300448/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
449 0x03, 0x00, 0x04, 0x01, 0x0a, 0x28, 0x1e, 0xc2,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300450/* reg18 reg19 reg1a reg1b */
451 0x0b, 0x00, 0x00, 0x00
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300452};
453
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300454static const u8 sn_ov7648[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300455/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Jean-Francois Moine62703302008-11-11 08:42:56 -0300456 0x00, 0x63, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300457/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300458 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300459/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
Jean-Francois Moine62703302008-11-11 08:42:56 -0300460 0x03, 0x00, 0x00, 0x01, 0x00, 0x28, 0x1e, 0x00,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300461/* reg18 reg19 reg1a reg1b */
462 0x0b, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300463};
464
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300465static const u8 sn_ov7660[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300466/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -0300467 0x00, 0x61, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300468/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -0300469 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300470/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
471 0x03, 0x00, 0x01, 0x01, 0x08, 0x28, 0x1e, 0x20,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300472/* reg18 reg19 reg1a reg1b */
473 0x07, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300474};
475
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -0300476static const u8 sn_po1030[0x1c] = {
477/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
478 0x00, 0x21, 0x62, 0x00, 0x1a, 0x20, 0x20, 0x20,
479/* reg8 reg9 rega regb regc regd rege regf */
480 0x81, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
481/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
482 0x03, 0x00, 0x00, 0x06, 0x06, 0x28, 0x1e, 0x00,
483/* reg18 reg19 reg1a reg1b */
484 0x07, 0x00, 0x00, 0x00
485};
486
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300487static const u8 sn_po2030n[0x1c] = {
488/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
489 0x00, 0x63, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
490/* reg8 reg9 rega regb regc regd rege regf */
491 0x81, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
492/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
493 0x03, 0x00, 0x00, 0x01, 0x14, 0x28, 0x1e, 0x00,
494/* reg18 reg19 reg1a reg1b */
495 0x07, 0x00, 0x00, 0x00
496};
497
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -0300498static const u8 sn_sp80708[0x1c] = {
499/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
500 0x00, 0x63, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
501/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300502 0x81, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -0300503/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
504 0x03, 0x00, 0x00, 0x03, 0x04, 0x28, 0x1e, 0x00,
505/* reg18 reg19 reg1a reg1b */
506 0x07, 0x00, 0x00, 0x00
507};
508
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300509/* sequence specific to the sensors - !! index = SENSOR_xxx */
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300510static const u8 *sn_tb[] = {
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300511[SENSOR_ADCM1700] = sn_adcm1700,
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300512[SENSOR_GC0307] = sn_gc0307,
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300513[SENSOR_HV7131R] = sn_hv7131,
514[SENSOR_MI0360] = sn_mi0360,
515[SENSOR_MO4000] = sn_mo4000,
516[SENSOR_MT9V111] = sn_mt9v111,
517[SENSOR_OM6802] = sn_om6802,
518[SENSOR_OV7630] = sn_ov7630,
519[SENSOR_OV7648] = sn_ov7648,
520[SENSOR_OV7660] = sn_ov7660,
521[SENSOR_PO1030] = sn_po1030,
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300522[SENSOR_PO2030N] = sn_po2030n,
Jean-François Moine9c33afc2010-03-17 15:25:32 -0300523[SENSOR_SP80708] = sn_sp80708
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300524};
525
Jean-Francois Moineb083b922009-02-01 14:20:07 -0300526/* default gamma table */
Jean-Francois Moine98819182009-01-19 07:37:33 -0300527static const u8 gamma_def[17] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300528 0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99,
529 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
530};
Jean-Francois Moine64677572009-12-20 12:31:28 -0300531/* gamma for sensor ADCM1700 */
532static const u8 gamma_spec_0[17] = {
533 0x0f, 0x39, 0x5a, 0x74, 0x86, 0x95, 0xa6, 0xb4,
534 0xbd, 0xc4, 0xcc, 0xd4, 0xd5, 0xde, 0xe4, 0xed, 0xf5
535};
Jean-Francois Moineb083b922009-02-01 14:20:07 -0300536/* gamma for sensors HV7131R and MT9V111 */
537static const u8 gamma_spec_1[17] = {
538 0x08, 0x3a, 0x52, 0x65, 0x75, 0x83, 0x91, 0x9d,
539 0xa9, 0xb4, 0xbe, 0xc8, 0xd2, 0xdb, 0xe4, 0xed, 0xf5
540};
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300541/* gamma for sensor GC0307 */
Jean-Francois Moineb083b922009-02-01 14:20:07 -0300542static const u8 gamma_spec_2[17] = {
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300543 0x14, 0x37, 0x50, 0x6a, 0x7c, 0x8d, 0x9d, 0xab,
544 0xb5, 0xbf, 0xc2, 0xcb, 0xd1, 0xd6, 0xdb, 0xe1, 0xeb
545};
546/* gamma for sensor SP80708 */
547static const u8 gamma_spec_3[17] = {
Jean-Francois Moineb083b922009-02-01 14:20:07 -0300548 0x0a, 0x2d, 0x4e, 0x68, 0x7d, 0x8f, 0x9f, 0xab,
549 0xb7, 0xc2, 0xcc, 0xd3, 0xd8, 0xde, 0xe2, 0xe5, 0xe6
550};
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -0300551
Jean-Francois Moine803f9cc2008-10-04 14:17:02 -0300552/* color matrix and offsets */
Jean-Francois Moine98819182009-01-19 07:37:33 -0300553static const u8 reg84[] = {
Jean-Francois Moine803f9cc2008-10-04 14:17:02 -0300554 0x14, 0x00, 0x27, 0x00, 0x07, 0x00, /* YR YG YB gains */
555 0xe8, 0x0f, 0xda, 0x0f, 0x40, 0x00, /* UR UG UB */
556 0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f, /* VR VG VB */
557 0x00, 0x00, 0x00 /* YUV offsets */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300558};
Jean-Francois Moine64677572009-12-20 12:31:28 -0300559static const u8 adcm1700_sensor_init[][8] = {
560 {0xa0, 0x51, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine878b35a2009-12-30 04:53:07 -0300561 {0xb0, 0x51, 0x04, 0x08, 0x00, 0x00, 0x00, 0x10}, /* reset */
Jean-Francois Moine64677572009-12-20 12:31:28 -0300562 {0xdd, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
563 {0xb0, 0x51, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
564 {0xdd, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
565 {0xb0, 0x51, 0x0c, 0xe0, 0x2e, 0x00, 0x00, 0x10},
566 {0xb0, 0x51, 0x10, 0x02, 0x02, 0x00, 0x00, 0x10},
567 {0xb0, 0x51, 0x14, 0x0e, 0x0e, 0x00, 0x00, 0x10},
568 {0xb0, 0x51, 0x1c, 0x00, 0x80, 0x00, 0x00, 0x10},
569 {0xb0, 0x51, 0x20, 0x01, 0x00, 0x00, 0x00, 0x10},
570 {0xdd, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
571 {0xb0, 0x51, 0x04, 0x04, 0x00, 0x00, 0x00, 0x10},
572 {0xdd, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
573 {0xb0, 0x51, 0x04, 0x01, 0x00, 0x00, 0x00, 0x10},
574 {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
575 {0xb0, 0x51, 0x14, 0x01, 0x00, 0x00, 0x00, 0x10},
576 {0xb0, 0x51, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
577 {}
578};
579static const u8 adcm1700_sensor_param1[][8] = {
Jean-Francois Moine878b35a2009-12-30 04:53:07 -0300580 {0xb0, 0x51, 0x26, 0xf9, 0x01, 0x00, 0x00, 0x10}, /* exposure? */
Jean-Francois Moine64677572009-12-20 12:31:28 -0300581 {0xd0, 0x51, 0x1e, 0x8e, 0x8e, 0x8e, 0x8e, 0x10},
582
583 {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10},
584 {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10},
585 {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
586 {0xb0, 0x51, 0x32, 0x00, 0x72, 0x00, 0x00, 0x10},
Jean-Francois Moine878b35a2009-12-30 04:53:07 -0300587 {0xd0, 0x51, 0x1e, 0xbe, 0xd7, 0xe8, 0xbe, 0x10}, /* exposure? */
Jean-Francois Moine64677572009-12-20 12:31:28 -0300588
Jean-Francois Moine878b35a2009-12-30 04:53:07 -0300589 {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10},
590 {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10},
591 {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10},
592 {0xb0, 0x51, 0x32, 0x00, 0xa2, 0x00, 0x00, 0x10},
Jean-Francois Moine64677572009-12-20 12:31:28 -0300593 {}
594};
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300595static const u8 gc0307_sensor_init[][8] = {
596 {0xa0, 0x21, 0x43, 0x00, 0x00, 0x00, 0x00, 0x10},
597 {0xa0, 0x21, 0x44, 0xa2, 0x00, 0x00, 0x00, 0x10},
598 {0xa0, 0x21, 0x01, 0x6a, 0x00, 0x00, 0x00, 0x10},
599 {0xa0, 0x21, 0x02, 0x70, 0x00, 0x00, 0x00, 0x10},
600 {0xa0, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
601 {0xa0, 0x21, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
602 {0xa0, 0x21, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x10},
603 {0xa0, 0x21, 0x11, 0x05, 0x00, 0x00, 0x00, 0x10},
604 {0xa0, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
605 {0xa0, 0x21, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10},
606 {0xa0, 0x21, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10},
607 {0xa0, 0x21, 0x08, 0x02, 0x00, 0x00, 0x00, 0x10},
608 {0xa0, 0x21, 0x09, 0x01, 0x00, 0x00, 0x00, 0x10},
609 {0xa0, 0x21, 0x0a, 0xe8, 0x00, 0x00, 0x00, 0x10},
610 {0xa0, 0x21, 0x0b, 0x02, 0x00, 0x00, 0x00, 0x10},
611 {0xa0, 0x21, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x10},
612 {0xa0, 0x21, 0x0d, 0x22, 0x00, 0x00, 0x00, 0x10},
613 {0xa0, 0x21, 0x0e, 0x02, 0x00, 0x00, 0x00, 0x10},
614 {0xa0, 0x21, 0x0f, 0xb2, 0x00, 0x00, 0x00, 0x10},
615 {0xa0, 0x21, 0x12, 0x70, 0x00, 0x00, 0x00, 0x10},
616 {0xdd, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 10ms*/
617 {0xa0, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10},
618 {0xa0, 0x21, 0x15, 0xb8, 0x00, 0x00, 0x00, 0x10},
619 {0xa0, 0x21, 0x16, 0x13, 0x00, 0x00, 0x00, 0x10},
620 {0xa0, 0x21, 0x17, 0x52, 0x00, 0x00, 0x00, 0x10},
621 {0xa0, 0x21, 0x18, 0x50, 0x00, 0x00, 0x00, 0x10},
622 {0xa0, 0x21, 0x1e, 0x0d, 0x00, 0x00, 0x00, 0x10},
623 {0xa0, 0x21, 0x1f, 0x32, 0x00, 0x00, 0x00, 0x10},
624 {0xa0, 0x21, 0x61, 0x90, 0x00, 0x00, 0x00, 0x10},
625 {0xa0, 0x21, 0x63, 0x70, 0x00, 0x00, 0x00, 0x10},
626 {0xa0, 0x21, 0x65, 0x98, 0x00, 0x00, 0x00, 0x10},
627 {0xa0, 0x21, 0x67, 0x90, 0x00, 0x00, 0x00, 0x10},
628 {0xa0, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
629 {0xa0, 0x21, 0x04, 0x96, 0x00, 0x00, 0x00, 0x10},
630 {0xa0, 0x21, 0x45, 0x27, 0x00, 0x00, 0x00, 0x10},
631 {0xa0, 0x21, 0x47, 0x2c, 0x00, 0x00, 0x00, 0x10},
632 {0xa0, 0x21, 0x43, 0x47, 0x00, 0x00, 0x00, 0x10},
633 {0xa0, 0x21, 0x44, 0xd8, 0x00, 0x00, 0x00, 0x10},
634 {}
635};
636static const u8 gc0307_sensor_param1[][8] = {
637 {0xa0, 0x21, 0x68, 0x13, 0x00, 0x00, 0x00, 0x10},
638 {0xd0, 0x21, 0x61, 0x80, 0x00, 0x80, 0x00, 0x10},
639 {0xc0, 0x21, 0x65, 0x80, 0x00, 0x80, 0x00, 0x10},
640 {0xc0, 0x21, 0x63, 0xa0, 0x00, 0xa6, 0x00, 0x10},
641/*param3*/
642 {0xa0, 0x21, 0x01, 0x6e, 0x00, 0x00, 0x00, 0x10},
643 {0xa0, 0x21, 0x02, 0x88, 0x00, 0x00, 0x00, 0x10},
Jean-François Moinead98c0f2010-03-18 05:15:30 -0300644 {}
645};
646
Jean-Francois Moine98819182009-01-19 07:37:33 -0300647static const u8 hv7131r_sensor_init[][8] = {
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300648 {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
649 {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10},
650 {0xd1, 0x11, 0x40, 0xff, 0x7f, 0x7f, 0x7f, 0x10},
651/* {0x91, 0x11, 0x44, 0x00, 0x00, 0x00, 0x00, 0x10}, */
652 {0xd1, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
653 {0xd1, 0x11, 0x14, 0x01, 0xe2, 0x02, 0x82, 0x10},
654/* {0x91, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10}, */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300655
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300656 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
657 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
658 {0xc1, 0x11, 0x25, 0x00, 0x61, 0xa8, 0x00, 0x10},
659 {0xa1, 0x11, 0x30, 0x22, 0x00, 0x00, 0x00, 0x10},
660 {0xc1, 0x11, 0x31, 0x20, 0x2e, 0x20, 0x00, 0x10},
661 {0xc1, 0x11, 0x25, 0x00, 0xc3, 0x50, 0x00, 0x10},
662 {0xa1, 0x11, 0x30, 0x07, 0x00, 0x00, 0x00, 0x10}, /* gain14 */
663 {0xc1, 0x11, 0x31, 0x10, 0x10, 0x10, 0x00, 0x10}, /* r g b 101a10 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300664
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300665 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
666 {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -0300667 {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300668 {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
669 {0xa1, 0x11, 0x23, 0x09, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300670
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300671 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
672 {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
673 {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
674 {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
675 {0xa1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300676 {0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10},
677 /* set sensor clock */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300678 {}
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300679};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300680static const u8 mi0360_sensor_init[][8] = {
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300681 {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
Jean-Francois Moine98819182009-01-19 07:37:33 -0300682 {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300683 {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300684 {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
685 {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
686 {0xd1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x53, 0x10},
687 {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
688 {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
689 {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
690 {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
691 {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
692 {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
693 {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
694 {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
695 {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
696 {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
697 {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
698 {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
699 {0xd1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
700 {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
701 {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
702 {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
Jean-Francois Moine98819182009-01-19 07:37:33 -0300703 {0xd1, 0x5d, 0x2f, 0xf7, 0xB0, 0x00, 0x04, 0x10},
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300704 {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
705 {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
706 {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
707 {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
708 {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
709 {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
710 {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
711 {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
712 {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
713 {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300714
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300715 {0xb1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
716 {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
717 {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
718 {0xd1, 0x5d, 0x2b, 0x00, 0xa0, 0x00, 0xb0, 0x10},
719 {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0xa0, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300720
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300721 {0xb1, 0x5d, 0x0a, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor clck ?2 */
722 {0xb1, 0x5d, 0x06, 0x00, 0x30, 0x00, 0x00, 0x10},
723 {0xb1, 0x5d, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10},
724 {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300725
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300726 {0xd1, 0x5d, 0x2b, 0x00, 0xb9, 0x00, 0xe3, 0x10},
727 {0xd1, 0x5d, 0x2d, 0x00, 0x5f, 0x00, 0xb9, 0x10}, /* 42 */
728/* {0xb1, 0x5d, 0x35, 0x00, 0x67, 0x00, 0x00, 0x10}, * gain orig */
729/* {0xb1, 0x5d, 0x35, 0x00, 0x20, 0x00, 0x00, 0x10}, * gain */
730 {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
731 {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300732 {}
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300733};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300734static const u8 mo4000_sensor_init[][8] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300735 {0xa1, 0x21, 0x01, 0x02, 0x00, 0x00, 0x00, 0x10},
736 {0xa1, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10},
737 {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
738 {0xa1, 0x21, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
739 {0xa1, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
740 {0xa1, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x10},
741 {0xa1, 0x21, 0x06, 0x80, 0x00, 0x00, 0x00, 0x10},
742 {0xa1, 0x21, 0x06, 0x81, 0x00, 0x00, 0x00, 0x10},
743 {0xa1, 0x21, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
744 {0xa1, 0x21, 0x11, 0x00, 0x00, 0x00, 0x00, 0x10},
745 {0xa1, 0x21, 0x11, 0x20, 0x00, 0x00, 0x00, 0x10},
746 {0xa1, 0x21, 0x11, 0x30, 0x00, 0x00, 0x00, 0x10},
747 {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
748 {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
749 {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
750 {0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
751 {0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10},
752 {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10},
753 {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
754 {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300755 {}
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300756};
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300757static const u8 mt9v111_sensor_init[][8] = {
758 {0xb1, 0x5c, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10}, /* reset? */
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300759 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300760 {0xb1, 0x5c, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
761 {0xb1, 0x5c, 0x01, 0x00, 0x01, 0x00, 0x00, 0x10}, /* IFP select */
762 {0xb1, 0x5c, 0x08, 0x04, 0x80, 0x00, 0x00, 0x10}, /* output fmt ctrl */
763 {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10}, /* op mode ctrl */
Jean-Francois Moine2687a2f2009-02-01 14:48:55 -0300764 {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
765 {0xb1, 0x5c, 0x03, 0x01, 0xe1, 0x00, 0x00, 0x10},
766 {0xb1, 0x5c, 0x04, 0x02, 0x81, 0x00, 0x00, 0x10},
767 {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300768 {0xb1, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10}, /* sensor select */
Jean-Francois Moine2687a2f2009-02-01 14:48:55 -0300769 {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
770 {0xb1, 0x5c, 0x03, 0x01, 0xe6, 0x00, 0x00, 0x10},
771 {0xb1, 0x5c, 0x04, 0x02, 0x86, 0x00, 0x00, 0x10},
772 {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
773 {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300774 {0xb1, 0x5c, 0x08, 0x00, 0x08, 0x00, 0x00, 0x10}, /* row start */
Jean-Francois Moine2687a2f2009-02-01 14:48:55 -0300775 {0xb1, 0x5c, 0x0e, 0x00, 0x08, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300776 {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10}, /* col start */
777 {0xb1, 0x5c, 0x03, 0x01, 0xe7, 0x00, 0x00, 0x10}, /* window height */
778 {0xb1, 0x5c, 0x04, 0x02, 0x87, 0x00, 0x00, 0x10}, /* window width */
779 {0xb1, 0x5c, 0x07, 0x30, 0x02, 0x00, 0x00, 0x10}, /* output ctrl */
780 {0xb1, 0x5c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10}, /* shutter delay */
781 {0xb1, 0x5c, 0x12, 0x00, 0xb0, 0x00, 0x00, 0x10}, /* zoom col start */
782 {0xb1, 0x5c, 0x13, 0x00, 0x7c, 0x00, 0x00, 0x10}, /* zoom row start */
783 {0xb1, 0x5c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* digital zoom */
784 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10}, /* read mode */
785 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300786 {}
787};
788static const u8 mt9v111_sensor_param1[][8] = {
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300789 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
790 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine2687a2f2009-02-01 14:48:55 -0300791 {0xb1, 0x5c, 0x09, 0x01, 0x2c, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300792 {0xd1, 0x5c, 0x2b, 0x00, 0x33, 0x00, 0xa0, 0x10}, /* green1 gain */
793 {0xd1, 0x5c, 0x2d, 0x00, 0xa0, 0x00, 0x33, 0x10}, /* red gain */
794 /*******/
795 {0xb1, 0x5c, 0x06, 0x00, 0x1e, 0x00, 0x00, 0x10}, /* vert blanking */
796 {0xb1, 0x5c, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10}, /* horiz blanking */
797 {0xd1, 0x5c, 0x2c, 0x00, 0xad, 0x00, 0xad, 0x10}, /* blue gain */
798 {0xb1, 0x5c, 0x35, 0x01, 0xc0, 0x00, 0x00, 0x10}, /* global gain */
799 {}
800};
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300801static const u8 om6802_init0[2][8] = {
802/*fixme: variable*/
803 {0xa0, 0x34, 0x29, 0x0e, 0x00, 0x00, 0x00, 0x10},
804 {0xa0, 0x34, 0x23, 0xb0, 0x00, 0x00, 0x00, 0x10},
805};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300806static const u8 om6802_sensor_init[][8] = {
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300807 {0xa0, 0x34, 0xdf, 0x6d, 0x00, 0x00, 0x00, 0x10},
808 /* factory mode */
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300809 {0xa0, 0x34, 0xdd, 0x18, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moined5aa3852009-11-07 06:10:08 -0300810 /* output raw RGB */
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300811 {0xa0, 0x34, 0x5a, 0xc0, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300812/* {0xa0, 0x34, 0xfb, 0x11, 0x00, 0x00, 0x00, 0x10}, */
813 {0xa0, 0x34, 0xf0, 0x04, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moined5aa3852009-11-07 06:10:08 -0300814 /* auto-exposure speed (0) / white balance mode (auto RGB) */
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300815/* {0xa0, 0x34, 0xf1, 0x02, 0x00, 0x00, 0x00, 0x10},
816 * set color mode */
817/* {0xa0, 0x34, 0xfe, 0x5b, 0x00, 0x00, 0x00, 0x10},
818 * max AGC value in AE */
819/* {0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10},
820 * preset AGC */
821/* {0xa0, 0x34, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x10},
822 * preset brightness */
823/* {0xa0, 0x34, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x10},
824 * preset contrast */
825/* {0xa0, 0x34, 0xe8, 0x31, 0x00, 0x00, 0x00, 0x10},
826 * preset gamma */
827 {0xa0, 0x34, 0xe9, 0x0f, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moined5aa3852009-11-07 06:10:08 -0300828 /* luminance mode (0x4f -> AutoExpo on) */
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300829 {0xa0, 0x34, 0xe4, 0xff, 0x00, 0x00, 0x00, 0x10},
830 /* preset shutter */
831/* {0xa0, 0x34, 0xef, 0x00, 0x00, 0x00, 0x00, 0x10},
832 * auto frame rate */
833/* {0xa0, 0x34, 0xfb, 0xee, 0x00, 0x00, 0x00, 0x10}, */
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300834 {0xa0, 0x34, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
835 {}
836};
837static const u8 om6802_sensor_param1[][8] = {
838 {0xa0, 0x34, 0x71, 0x84, 0x00, 0x00, 0x00, 0x10},
839 {0xa0, 0x34, 0x72, 0x05, 0x00, 0x00, 0x00, 0x10},
840 {0xa0, 0x34, 0x68, 0x80, 0x00, 0x00, 0x00, 0x10},
841 {0xa0, 0x34, 0x69, 0x01, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300842 {}
843};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300844static const u8 ov7630_sensor_init[][8] = {
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300845 {0xa1, 0x21, 0x76, 0x01, 0x00, 0x00, 0x00, 0x10},
846 {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300847 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300848 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
849 {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300850 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300851 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300852/* win: i2c_r from 00 to 80 */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300853 {0xd1, 0x21, 0x03, 0x80, 0x10, 0x20, 0x80, 0x10},
854 {0xb1, 0x21, 0x0c, 0x20, 0x20, 0x00, 0x00, 0x10},
Hans de Goedecc7b5b52009-06-18 05:14:42 -0300855/* HDG: 0x11 was 0x00 change to 0x01 for better exposure (15 fps instead of 30)
856 0x13 was 0xc0 change to 0xc3 for auto gain and exposure */
857 {0xd1, 0x21, 0x11, 0x01, 0x48, 0xc3, 0x00, 0x10},
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300858 {0xb1, 0x21, 0x15, 0x80, 0x03, 0x00, 0x00, 0x10},
859 {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
860 {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
861 {0xd1, 0x21, 0x1f, 0x00, 0x80, 0x80, 0x80, 0x10},
862 {0xd1, 0x21, 0x23, 0xde, 0x10, 0x8a, 0xa0, 0x10},
863 {0xc1, 0x21, 0x27, 0xca, 0xa2, 0x74, 0x00, 0x10},
864 {0xd1, 0x21, 0x2a, 0x88, 0x00, 0x88, 0x01, 0x10},
865 {0xc1, 0x21, 0x2e, 0x80, 0x00, 0x18, 0x00, 0x10},
866 {0xa1, 0x21, 0x21, 0x08, 0x00, 0x00, 0x00, 0x10},
867 {0xa1, 0x21, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
868 {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
869 {0xb1, 0x21, 0x32, 0xc2, 0x08, 0x00, 0x00, 0x10},
870 {0xb1, 0x21, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x10},
871 {0xd1, 0x21, 0x60, 0x05, 0x40, 0x12, 0x57, 0x10},
872 {0xa1, 0x21, 0x64, 0x73, 0x00, 0x00, 0x00, 0x10},
873 {0xd1, 0x21, 0x65, 0x00, 0x55, 0x01, 0xac, 0x10},
874 {0xa1, 0x21, 0x69, 0x38, 0x00, 0x00, 0x00, 0x10},
875 {0xd1, 0x21, 0x6f, 0x1f, 0x01, 0x00, 0x10, 0x10},
876 {0xd1, 0x21, 0x73, 0x50, 0x20, 0x02, 0x01, 0x10},
877 {0xd1, 0x21, 0x77, 0xf3, 0x90, 0x98, 0x98, 0x10},
878 {0xc1, 0x21, 0x7b, 0x00, 0x4c, 0xf7, 0x00, 0x10},
879 {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
880 {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
Jean-François Moinebdd2b932010-04-25 14:23:39 -0300881 {}
882};
883static const u8 ov7630_sensor_param1[][8] = {
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300884 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
885 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
886/*fixme: + 0x12, 0x04*/
Jean-Francois Moine6c862742008-09-08 04:57:26 -0300887/* {0xa1, 0x21, 0x75, 0x82, 0x00, 0x00, 0x00, 0x10}, * COMN
888 * set by setvflip */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300889 {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
890 {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
891 {0xb1, 0x21, 0x01, 0x80, 0x80, 0x00, 0x00, 0x10},
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300892/* */
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300893/* {0xa1, 0x21, 0x2a, 0x88, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
894/* {0xa1, 0x21, 0x2b, 0x34, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300895/* */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300896 {0xa1, 0x21, 0x10, 0x83, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine91de65a2008-09-03 17:12:18 -0300897/* {0xb1, 0x21, 0x01, 0x88, 0x70, 0x00, 0x00, 0x10}, */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300898 {}
899};
Jean-Francois Moine62703302008-11-11 08:42:56 -0300900
Jean-Francois Moine98819182009-01-19 07:37:33 -0300901static const u8 ov7648_sensor_init[][8] = {
Jean-Francois Moine62703302008-11-11 08:42:56 -0300902 {0xa1, 0x21, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10},
903 {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300904 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moine62703302008-11-11 08:42:56 -0300905 {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
906 {0xd1, 0x21, 0x03, 0xa4, 0x30, 0x88, 0x00, 0x10},
907 {0xb1, 0x21, 0x11, 0x80, 0x08, 0x00, 0x00, 0x10},
908 {0xc1, 0x21, 0x13, 0xa0, 0x04, 0x84, 0x00, 0x10},
909 {0xd1, 0x21, 0x17, 0x1a, 0x02, 0xba, 0xf4, 0x10},
910 {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
911 {0xd1, 0x21, 0x1f, 0x41, 0xc0, 0x80, 0x80, 0x10},
912 {0xd1, 0x21, 0x23, 0xde, 0xa0, 0x80, 0x32, 0x10},
913 {0xd1, 0x21, 0x27, 0xfe, 0xa0, 0x00, 0x91, 0x10},
914 {0xd1, 0x21, 0x2b, 0x00, 0x88, 0x85, 0x80, 0x10},
915 {0xc1, 0x21, 0x2f, 0x9c, 0x00, 0xc4, 0x00, 0x10},
916 {0xd1, 0x21, 0x60, 0xa6, 0x60, 0x88, 0x12, 0x10},
917 {0xd1, 0x21, 0x64, 0x88, 0x00, 0x00, 0x94, 0x10},
918 {0xd1, 0x21, 0x68, 0x7a, 0x0c, 0x00, 0x00, 0x10},
919 {0xd1, 0x21, 0x6c, 0x11, 0x33, 0x22, 0x00, 0x10},
920 {0xd1, 0x21, 0x70, 0x11, 0x00, 0x10, 0x50, 0x10},
921 {0xd1, 0x21, 0x74, 0x20, 0x06, 0x00, 0xb5, 0x10},
922 {0xd1, 0x21, 0x78, 0x8a, 0x00, 0x00, 0x00, 0x10},
923 {0xb1, 0x21, 0x7c, 0x00, 0x43, 0x00, 0x00, 0x10},
924
925 {0xd1, 0x21, 0x21, 0x86, 0x00, 0xde, 0xa0, 0x10},
926/* {0xd1, 0x21, 0x25, 0x80, 0x32, 0xfe, 0xa0, 0x10}, jfm done */
927/* {0xd1, 0x21, 0x29, 0x00, 0x91, 0x00, 0x88, 0x10}, jfm done */
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300928/* {0xb1, 0x21, 0x2d, 0x85, 0x00, 0x00, 0x00, 0x10}, set by setfreq */
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300929 {}
930};
931static const u8 ov7648_sensor_param1[][8] = {
Jean-Francois Moine62703302008-11-11 08:42:56 -0300932/* {0xa1, 0x21, 0x12, 0x08, 0x00, 0x00, 0x00, 0x10}, jfm done */
Jean-Francois Moine2797ba22009-02-05 15:12:24 -0300933/* {0xa1, 0x21, 0x75, 0x06, 0x00, 0x00, 0x00, 0x10}, * COMN
934 * set by setvflip */
Jean-Francois Moine62703302008-11-11 08:42:56 -0300935 {0xa1, 0x21, 0x19, 0x02, 0x00, 0x00, 0x00, 0x10},
936 {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
937/* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
938/* {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}, * GAIN - def */
939/* {0xb1, 0x21, 0x01, 0x6c, 0x6c, 0x00, 0x00, 0x10}, * B R - def: 80 */
940/*...*/
941 {0xa1, 0x21, 0x11, 0x81, 0x00, 0x00, 0x00, 0x10}, /* CLKRC */
942/* {0xa1, 0x21, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
943/* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
944/* {0xa1, 0x21, 0x2a, 0x91, 0x00, 0x00, 0x00, 0x10}, jfm done */
945/* {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
946/* {0xb1, 0x21, 0x01, 0x64, 0x84, 0x00, 0x00, 0x10}, * B R - def: 80 */
947
948 {}
949};
950
Jean-Francois Moine98819182009-01-19 07:37:33 -0300951static const u8 ov7660_sensor_init[][8] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300952 {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300953 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300954 {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300955 /* Outformat = rawRGB */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300956 {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */
Jean-Francois Moined8f400e2009-07-08 06:33:44 -0300957 {0xd1, 0x21, 0x00, 0x01, 0x74, 0x92, 0x00, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300958 /* GAIN BLUE RED VREF */
959 {0xd1, 0x21, 0x04, 0x00, 0x7d, 0x62, 0x00, 0x10},
960 /* COM 1 BAVE GEAVE AECHH */
961 {0xb1, 0x21, 0x08, 0x83, 0x01, 0x00, 0x00, 0x10}, /* RAVE COM2 */
962 {0xd1, 0x21, 0x0c, 0x00, 0x08, 0x04, 0x4f, 0x10}, /* COM 3 4 5 6 */
Jean-Francois Moine47f7f6f2009-08-25 06:14:54 -0300963 {0xd1, 0x21, 0x10, 0x7f, 0x40, 0x05, 0xff, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300964 /* AECH CLKRC COM7 COM8 */
965 {0xc1, 0x21, 0x14, 0x2c, 0x00, 0x02, 0x00, 0x10}, /* COM9 COM10 */
966 {0xd1, 0x21, 0x17, 0x10, 0x60, 0x02, 0x7b, 0x10},
967 /* HSTART HSTOP VSTRT VSTOP */
968 {0xa1, 0x21, 0x1b, 0x02, 0x00, 0x00, 0x00, 0x10}, /* PSHFT */
969 {0xb1, 0x21, 0x1e, 0x01, 0x0e, 0x00, 0x00, 0x10}, /* MVFP LAEC */
970 {0xd1, 0x21, 0x20, 0x07, 0x07, 0x07, 0x07, 0x10},
971 /* BOS GBOS GROS ROS (BGGR offset) */
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300972/* {0xd1, 0x21, 0x24, 0x68, 0x58, 0xd4, 0x80, 0x10}, */
973 {0xd1, 0x21, 0x24, 0x78, 0x68, 0xd4, 0x80, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300974 /* AEW AEB VPT BBIAS */
975 {0xd1, 0x21, 0x28, 0x80, 0x30, 0x00, 0x00, 0x10},
976 /* GbBIAS RSVD EXHCH EXHCL */
977 {0xd1, 0x21, 0x2c, 0x80, 0x00, 0x00, 0x62, 0x10},
978 /* RBIAS ADVFL ASDVFH YAVE */
979 {0xc1, 0x21, 0x30, 0x08, 0x30, 0xb4, 0x00, 0x10},
980 /* HSYST HSYEN HREF */
981 {0xd1, 0x21, 0x33, 0x00, 0x07, 0x84, 0x00, 0x10}, /* reserved */
982 {0xd1, 0x21, 0x37, 0x0c, 0x02, 0x43, 0x00, 0x10},
983 /* ADC ACOM OFON TSLB */
984 {0xd1, 0x21, 0x3b, 0x02, 0x6c, 0x19, 0x0e, 0x10},
985 /* COM11 COM12 COM13 COM14 */
986 {0xd1, 0x21, 0x3f, 0x41, 0xc1, 0x22, 0x08, 0x10},
987 /* EDGE COM15 COM16 COM17 */
988 {0xd1, 0x21, 0x43, 0xf0, 0x10, 0x78, 0xa8, 0x10}, /* reserved */
989 {0xd1, 0x21, 0x47, 0x60, 0x80, 0x00, 0x00, 0x10}, /* reserved */
990 {0xd1, 0x21, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* reserved */
991 {0xd1, 0x21, 0x4f, 0x46, 0x36, 0x0f, 0x17, 0x10}, /* MTX 1 2 3 4 */
992 {0xd1, 0x21, 0x53, 0x7f, 0x96, 0x40, 0x40, 0x10}, /* MTX 5 6 7 8 */
993 {0xb1, 0x21, 0x57, 0x40, 0x0f, 0x00, 0x00, 0x10}, /* MTX9 MTXS */
994 {0xd1, 0x21, 0x59, 0xba, 0x9a, 0x22, 0xb9, 0x10}, /* reserved */
995 {0xd1, 0x21, 0x5d, 0x9b, 0x10, 0xf0, 0x05, 0x10}, /* reserved */
996 {0xa1, 0x21, 0x61, 0x60, 0x00, 0x00, 0x00, 0x10}, /* reserved */
997 {0xd1, 0x21, 0x62, 0x00, 0x00, 0x50, 0x30, 0x10},
998 /* LCC1 LCC2 LCC3 LCC4 */
999 {0xa1, 0x21, 0x66, 0x00, 0x00, 0x00, 0x00, 0x10}, /* LCC5 */
Jean-Francois Moine738608a2008-07-28 06:41:51 -03001000 {0xd1, 0x21, 0x67, 0x80, 0x7a, 0x90, 0x80, 0x10}, /* MANU */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001001 {0xa1, 0x21, 0x6b, 0x0a, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine738608a2008-07-28 06:41:51 -03001002 /* band gap reference [0:3] DBLV */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001003 {0xd1, 0x21, 0x6c, 0x30, 0x48, 0x80, 0x74, 0x10}, /* gamma curve */
1004 {0xd1, 0x21, 0x70, 0x64, 0x60, 0x5c, 0x58, 0x10}, /* gamma curve */
1005 {0xd1, 0x21, 0x74, 0x54, 0x4c, 0x40, 0x38, 0x10}, /* gamma curve */
1006 {0xd1, 0x21, 0x78, 0x34, 0x30, 0x2f, 0x2b, 0x10}, /* gamma curve */
1007 {0xd1, 0x21, 0x7c, 0x03, 0x07, 0x17, 0x34, 0x10}, /* gamma curve */
1008 {0xd1, 0x21, 0x80, 0x41, 0x4d, 0x58, 0x63, 0x10}, /* gamma curve */
1009 {0xd1, 0x21, 0x84, 0x6e, 0x77, 0x87, 0x95, 0x10}, /* gamma curve */
1010 {0xc1, 0x21, 0x88, 0xaf, 0xc7, 0xdf, 0x00, 0x10}, /* gamma curve */
1011 {0xc1, 0x21, 0x8b, 0x99, 0x99, 0xcf, 0x00, 0x10}, /* reserved */
Jean-Francois Moine738608a2008-07-28 06:41:51 -03001012 {0xb1, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x10}, /* DM_LNL/H */
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001013/* not in all ms-win traces*/
Jean-Francois Moine47f7f6f2009-08-25 06:14:54 -03001014 {0xa1, 0x21, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001015 {}
1016};
1017static const u8 ov7660_sensor_param1[][8] = {
Jean-Francois Moine738608a2008-07-28 06:41:51 -03001018 {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10}, /* MVFP */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001019 /* bits[3..0]reserved */
1020 {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10},
1021 {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
1022 /* VREF vertical frame ctrl */
1023 {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine738608a2008-07-28 06:41:51 -03001024 {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10}, /* AECH 0x20 */
1025 {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFL */
1026 {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFH */
1027 {0xa1, 0x21, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x10}, /* GAIN */
1028/* {0xb1, 0x21, 0x01, 0x78, 0x78, 0x00, 0x00, 0x10}, * BLUE */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001029/****** (some exchanges in the win trace) ******/
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001030/*fixme:param2*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001031 {0xa1, 0x21, 0x93, 0x00, 0x00, 0x00, 0x00, 0x10},/* dummy line hight */
Jean-Francois Moine738608a2008-07-28 06:41:51 -03001032 {0xa1, 0x21, 0x92, 0x25, 0x00, 0x00, 0x00, 0x10}, /* dummy line low */
1033 {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCH */
1034 {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCL */
1035/* {0xa1, 0x21, 0x02, 0x90, 0x00, 0x00, 0x00, 0x10}, * RED */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001036/****** (some exchanges in the win trace) ******/
Jean-Francois Moine738608a2008-07-28 06:41:51 -03001037/******!! startsensor KO if changed !!****/
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001038/*fixme: param3*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001039 {0xa1, 0x21, 0x93, 0x01, 0x00, 0x00, 0x00, 0x10},
1040 {0xa1, 0x21, 0x92, 0xff, 0x00, 0x00, 0x00, 0x10},
1041 {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10},
1042 {0xa1, 0x21, 0x2b, 0xc3, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001043 {}
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001044};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001045
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001046static const u8 po1030_sensor_init[][8] = {
1047/* the sensor registers are described in m5602/m5602_po1030.h */
1048 {0xa1, 0x6e, 0x3f, 0x20, 0x00, 0x00, 0x00, 0x10}, /* sensor reset */
1049 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
1050 {0xa1, 0x6e, 0x3f, 0x00, 0x00, 0x00, 0x00, 0x10},
1051 {0xa1, 0x6e, 0x3e, 0x00, 0x00, 0x00, 0x00, 0x10},
1052 {0xd1, 0x6e, 0x04, 0x02, 0xb1, 0x02, 0x39, 0x10},
1053 {0xd1, 0x6e, 0x08, 0x00, 0x01, 0x00, 0x00, 0x10},
1054 {0xd1, 0x6e, 0x0c, 0x02, 0x7f, 0x01, 0xe0, 0x10},
1055 {0xd1, 0x6e, 0x12, 0x03, 0x02, 0x00, 0x03, 0x10},
1056 {0xd1, 0x6e, 0x16, 0x85, 0x40, 0x4a, 0x40, 0x10}, /* r/g1/b/g2 gains */
1057 {0xc1, 0x6e, 0x1a, 0x00, 0x80, 0x00, 0x00, 0x10},
1058 {0xd1, 0x6e, 0x1d, 0x08, 0x03, 0x00, 0x00, 0x10},
1059 {0xd1, 0x6e, 0x23, 0x00, 0xb0, 0x00, 0x94, 0x10},
1060 {0xd1, 0x6e, 0x27, 0x58, 0x00, 0x00, 0x00, 0x10},
1061 {0xb1, 0x6e, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10},
1062 {0xd1, 0x6e, 0x2d, 0x14, 0x35, 0x61, 0x84, 0x10}, /* gamma corr */
1063 {0xd1, 0x6e, 0x31, 0xa2, 0xbd, 0xd8, 0xff, 0x10},
1064 {0xd1, 0x6e, 0x35, 0x06, 0x1e, 0x12, 0x02, 0x10}, /* color matrix */
1065 {0xd1, 0x6e, 0x39, 0xaa, 0x53, 0x37, 0xd5, 0x10},
1066 {0xa1, 0x6e, 0x3d, 0xf2, 0x00, 0x00, 0x00, 0x10},
1067 {0xd1, 0x6e, 0x3e, 0x00, 0x00, 0x80, 0x03, 0x10},
1068 {0xd1, 0x6e, 0x42, 0x03, 0x00, 0x00, 0x00, 0x10},
1069 {0xc1, 0x6e, 0x46, 0x00, 0x80, 0x80, 0x00, 0x10},
1070 {0xd1, 0x6e, 0x4b, 0x02, 0xef, 0x08, 0xcd, 0x10},
1071 {0xd1, 0x6e, 0x4f, 0x00, 0xd0, 0x00, 0xa0, 0x10},
1072 {0xd1, 0x6e, 0x53, 0x01, 0xaa, 0x01, 0x40, 0x10},
1073 {0xd1, 0x6e, 0x5a, 0x50, 0x04, 0x30, 0x03, 0x10}, /* raw rgb bayer */
1074 {0xa1, 0x6e, 0x5e, 0x00, 0x00, 0x00, 0x00, 0x10},
1075 {0xd1, 0x6e, 0x5f, 0x10, 0x40, 0xff, 0x00, 0x10},
1076
1077 {0xd1, 0x6e, 0x63, 0x40, 0x40, 0x00, 0x00, 0x10},
1078 {0xd1, 0x6e, 0x67, 0x00, 0x00, 0x00, 0x00, 0x10},
1079 {0xd1, 0x6e, 0x6b, 0x00, 0x00, 0x00, 0x00, 0x10},
1080 {0xd1, 0x6e, 0x6f, 0x00, 0x00, 0x00, 0x00, 0x10},
1081 {0xc1, 0x6e, 0x73, 0x10, 0x80, 0xeb, 0x00, 0x10},
1082 {}
1083};
1084static const u8 po1030_sensor_param1[][8] = {
1085/* from ms-win traces - these values change with auto gain/expo/wb.. */
1086 {0xa1, 0x6e, 0x1e, 0x03, 0x00, 0x00, 0x00, 0x10},
1087 {0xa1, 0x6e, 0x1e, 0x03, 0x00, 0x00, 0x00, 0x10},
1088/* mean values */
1089 {0xc1, 0x6e, 0x1a, 0x02, 0xd4, 0xa4, 0x00, 0x10}, /* integlines */
1090 {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10}, /* global gain */
1091 {0xc1, 0x6e, 0x16, 0x40, 0x40, 0x40, 0x00, 0x10}, /* r/g1/b gains */
1092
1093 {0xa1, 0x6e, 0x1d, 0x08, 0x00, 0x00, 0x00, 0x10}, /* control1 */
1094 {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10}, /* frameheight */
1095 {0xa1, 0x6e, 0x07, 0xd5, 0x00, 0x00, 0x00, 0x10},
1096/* {0xc1, 0x6e, 0x16, 0x49, 0x40, 0x45, 0x00, 0x10}, */
1097 {}
1098};
1099
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001100static const u8 po2030n_sensor_init[][8] = {
1101 {0xa1, 0x6e, 0x1e, 0x1a, 0x00, 0x00, 0x00, 0x10},
1102 {0xa1, 0x6e, 0x1f, 0x99, 0x00, 0x00, 0x00, 0x10},
1103 {0xdd, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 10ms */
1104 {0xa1, 0x6e, 0x1e, 0x0a, 0x00, 0x00, 0x00, 0x10},
1105 {0xa1, 0x6e, 0x1f, 0x19, 0x00, 0x00, 0x00, 0x10},
1106 {0xdd, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 10ms */
1107 {0xa1, 0x6e, 0x20, 0x44, 0x00, 0x00, 0x00, 0x10},
1108 {0xa1, 0x6e, 0x04, 0x03, 0x00, 0x00, 0x00, 0x10},
1109 {0xa1, 0x6e, 0x05, 0x70, 0x00, 0x00, 0x00, 0x10},
1110 {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10},
1111 {0xa1, 0x6e, 0x07, 0x25, 0x00, 0x00, 0x00, 0x10},
1112 {0xd1, 0x6e, 0x08, 0x00, 0xd0, 0x00, 0x08, 0x10},
1113 {0xd1, 0x6e, 0x0c, 0x03, 0x50, 0x01, 0xe8, 0x10},
1114 {0xd1, 0x6e, 0x1d, 0x20, 0x0a, 0x19, 0x44, 0x10},
1115 {0xd1, 0x6e, 0x21, 0x00, 0x00, 0x00, 0x00, 0x10},
1116 {0xd1, 0x6e, 0x25, 0x00, 0x00, 0x00, 0x00, 0x10},
1117 {0xd1, 0x6e, 0x29, 0x00, 0x00, 0x00, 0x00, 0x10},
1118 {0xd1, 0x6e, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10},
1119 {0xd1, 0x6e, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
1120 {0xd1, 0x6e, 0x35, 0x00, 0x00, 0x00, 0x00, 0x10},
1121 {0xd1, 0x6e, 0x39, 0x00, 0x00, 0x00, 0x00, 0x10},
1122 {0xd1, 0x6e, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x10},
1123 {0xd1, 0x6e, 0x41, 0x00, 0x00, 0x00, 0x00, 0x10},
1124 {0xd1, 0x6e, 0x45, 0x00, 0x00, 0x00, 0x00, 0x10},
1125 {0xd1, 0x6e, 0x49, 0x00, 0x00, 0x00, 0x00, 0x10},
1126 {0xd1, 0x6e, 0x4d, 0x00, 0x00, 0x00, 0xed, 0x10},
1127 {0xd1, 0x6e, 0x51, 0x17, 0x4a, 0x2f, 0xc0, 0x10},
1128 {0xd1, 0x6e, 0x55, 0x00, 0x00, 0x00, 0x00, 0x10},
1129 {0xd1, 0x6e, 0x59, 0x00, 0x00, 0x00, 0x00, 0x10},
1130 {0xd1, 0x6e, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x10},
1131 {0xd1, 0x6e, 0x61, 0x00, 0x00, 0x00, 0x00, 0x10},
1132 {0xd1, 0x6e, 0x65, 0x00, 0x00, 0x00, 0x00, 0x10},
1133 {0xd1, 0x6e, 0x69, 0x00, 0x00, 0x00, 0x00, 0x10},
1134 {0xd1, 0x6e, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x10},
1135 {0xd1, 0x6e, 0x71, 0x00, 0x00, 0x00, 0x00, 0x10},
1136 {0xd1, 0x6e, 0x75, 0x00, 0x00, 0x00, 0x00, 0x10},
1137 {0xd1, 0x6e, 0x79, 0x00, 0x00, 0x00, 0x00, 0x10},
1138 {0xd1, 0x6e, 0x7d, 0x00, 0x00, 0x00, 0x00, 0x10},
1139 {0xd1, 0x6e, 0x81, 0x00, 0x00, 0x00, 0x00, 0x10},
1140 {0xd1, 0x6e, 0x85, 0x00, 0x00, 0x00, 0x08, 0x10},
1141 {0xd1, 0x6e, 0x89, 0x01, 0xe8, 0x00, 0x01, 0x10},
1142 {0xa1, 0x6e, 0x8d, 0x00, 0x00, 0x00, 0x00, 0x10},
1143 {0xd1, 0x6e, 0x21, 0x00, 0x00, 0x00, 0x00, 0x10},
1144 {0xd1, 0x6e, 0x25, 0x00, 0x00, 0x00, 0x01, 0x10},
1145 {0xd1, 0x6e, 0x29, 0xe6, 0x00, 0xbd, 0x03, 0x10},
1146 {0xd1, 0x6e, 0x2d, 0x41, 0x38, 0x68, 0x40, 0x10},
1147 {0xd1, 0x6e, 0x31, 0x2b, 0x00, 0x36, 0x00, 0x10},
1148 {0xd1, 0x6e, 0x35, 0x30, 0x30, 0x08, 0x00, 0x10},
1149 {0xd1, 0x6e, 0x39, 0x00, 0x00, 0x33, 0x06, 0x10},
1150 {0xb1, 0x6e, 0x3d, 0x06, 0x02, 0x00, 0x00, 0x10},
1151 {}
1152};
1153static const u8 po2030n_sensor_param1[][8] = {
1154 {0xa1, 0x6e, 0x1a, 0x01, 0x00, 0x00, 0x00, 0x10},
1155 {0xdd, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 8ms */
1156 {0xa1, 0x6e, 0x1b, 0xf4, 0x00, 0x00, 0x00, 0x10},
1157 {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10},
1158 {0xd1, 0x6e, 0x16, 0x50, 0x40, 0x49, 0x40, 0x10},
1159/*param2*/
1160 {0xa1, 0x6e, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x10},
1161 {0xa1, 0x6e, 0x04, 0x03, 0x00, 0x00, 0x00, 0x10},
1162 {0xa1, 0x6e, 0x05, 0x6f, 0x00, 0x00, 0x00, 0x10},
1163 {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10},
1164 {0xa1, 0x6e, 0x07, 0x25, 0x00, 0x00, 0x00, 0x10},
1165 {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10},
1166 {0xc1, 0x6e, 0x16, 0x52, 0x40, 0x48, 0x00, 0x10},
1167/*after start*/
1168 {0xa1, 0x6e, 0x15, 0x0f, 0x00, 0x00, 0x00, 0x10},
1169 {0xdd, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 5ms */
1170 {0xa1, 0x6e, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x10},
1171 {0xdd, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 5ms */
1172 {0xa1, 0x6e, 0x1b, 0x53, 0x00, 0x00, 0x00, 0x10},
1173 {}
1174};
1175
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001176static const u8 sp80708_sensor_init[][8] = {
1177 {0xa1, 0x18, 0x06, 0xf9, 0x00, 0x00, 0x00, 0x10},
1178 {0xa1, 0x18, 0x09, 0x1f, 0x00, 0x00, 0x00, 0x10},
1179 {0xa1, 0x18, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
1180 {0xa1, 0x18, 0x0d, 0xc0, 0x00, 0x00, 0x00, 0x10},
1181 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
1182 {0xa1, 0x18, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x10},
1183 {0xa1, 0x18, 0x10, 0x40, 0x00, 0x00, 0x00, 0x10},
1184 {0xa1, 0x18, 0x11, 0x4e, 0x00, 0x00, 0x00, 0x10},
1185 {0xa1, 0x18, 0x12, 0x53, 0x00, 0x00, 0x00, 0x10},
1186 {0xa1, 0x18, 0x15, 0x80, 0x00, 0x00, 0x00, 0x10},
1187 {0xa1, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10},
1188 {0xa1, 0x18, 0x19, 0x18, 0x00, 0x00, 0x00, 0x10},
1189 {0xa1, 0x18, 0x1a, 0x10, 0x00, 0x00, 0x00, 0x10},
1190 {0xa1, 0x18, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x10},
1191 {0xa1, 0x18, 0x1c, 0x28, 0x00, 0x00, 0x00, 0x10},
1192 {0xa1, 0x18, 0x1d, 0x02, 0x00, 0x00, 0x00, 0x10},
1193 {0xa1, 0x18, 0x1e, 0x10, 0x00, 0x00, 0x00, 0x10},
1194 {0xa1, 0x18, 0x26, 0x04, 0x00, 0x00, 0x00, 0x10},
1195 {0xa1, 0x18, 0x27, 0x1e, 0x00, 0x00, 0x00, 0x10},
1196 {0xa1, 0x18, 0x28, 0x5a, 0x00, 0x00, 0x00, 0x10},
1197 {0xa1, 0x18, 0x29, 0x28, 0x00, 0x00, 0x00, 0x10},
1198 {0xa1, 0x18, 0x2a, 0x78, 0x00, 0x00, 0x00, 0x10},
1199 {0xa1, 0x18, 0x2b, 0x01, 0x00, 0x00, 0x00, 0x10},
1200 {0xa1, 0x18, 0x2c, 0xf7, 0x00, 0x00, 0x00, 0x10},
1201 {0xa1, 0x18, 0x2d, 0x2d, 0x00, 0x00, 0x00, 0x10},
1202 {0xa1, 0x18, 0x2e, 0xd5, 0x00, 0x00, 0x00, 0x10},
1203 {0xa1, 0x18, 0x39, 0x42, 0x00, 0x00, 0x00, 0x10},
1204 {0xa1, 0x18, 0x3a, 0x67, 0x00, 0x00, 0x00, 0x10},
1205 {0xa1, 0x18, 0x3b, 0x87, 0x00, 0x00, 0x00, 0x10},
1206 {0xa1, 0x18, 0x3c, 0xa3, 0x00, 0x00, 0x00, 0x10},
1207 {0xa1, 0x18, 0x3d, 0xb0, 0x00, 0x00, 0x00, 0x10},
1208 {0xa1, 0x18, 0x3e, 0xbc, 0x00, 0x00, 0x00, 0x10},
1209 {0xa1, 0x18, 0x3f, 0xc8, 0x00, 0x00, 0x00, 0x10},
1210 {0xa1, 0x18, 0x40, 0xd4, 0x00, 0x00, 0x00, 0x10},
1211 {0xa1, 0x18, 0x41, 0xdf, 0x00, 0x00, 0x00, 0x10},
1212 {0xa1, 0x18, 0x42, 0xea, 0x00, 0x00, 0x00, 0x10},
1213 {0xa1, 0x18, 0x43, 0xf5, 0x00, 0x00, 0x00, 0x10},
1214 {0xa1, 0x18, 0x45, 0x80, 0x00, 0x00, 0x00, 0x10},
1215 {0xa1, 0x18, 0x46, 0x60, 0x00, 0x00, 0x00, 0x10},
1216 {0xa1, 0x18, 0x47, 0x50, 0x00, 0x00, 0x00, 0x10},
1217 {0xa1, 0x18, 0x48, 0x30, 0x00, 0x00, 0x00, 0x10},
1218 {0xa1, 0x18, 0x49, 0x01, 0x00, 0x00, 0x00, 0x10},
1219 {0xa1, 0x18, 0x4d, 0xae, 0x00, 0x00, 0x00, 0x10},
1220 {0xa1, 0x18, 0x4e, 0x03, 0x00, 0x00, 0x00, 0x10},
1221 {0xa1, 0x18, 0x4f, 0x66, 0x00, 0x00, 0x00, 0x10},
1222 {0xa1, 0x18, 0x50, 0x1c, 0x00, 0x00, 0x00, 0x10},
1223 {0xa1, 0x18, 0x44, 0x10, 0x00, 0x00, 0x00, 0x10},
1224 {0xa1, 0x18, 0x4a, 0x30, 0x00, 0x00, 0x00, 0x10},
1225 {0xa1, 0x18, 0x51, 0x80, 0x00, 0x00, 0x00, 0x10},
1226 {0xa1, 0x18, 0x52, 0x80, 0x00, 0x00, 0x00, 0x10},
1227 {0xa1, 0x18, 0x53, 0x80, 0x00, 0x00, 0x00, 0x10},
1228 {0xa1, 0x18, 0x54, 0x80, 0x00, 0x00, 0x00, 0x10},
1229 {0xa1, 0x18, 0x55, 0x80, 0x00, 0x00, 0x00, 0x10},
1230 {0xa1, 0x18, 0x56, 0x80, 0x00, 0x00, 0x00, 0x10},
1231 {0xa1, 0x18, 0x57, 0xe0, 0x00, 0x00, 0x00, 0x10},
1232 {0xa1, 0x18, 0x58, 0xc0, 0x00, 0x00, 0x00, 0x10},
1233 {0xa1, 0x18, 0x59, 0xab, 0x00, 0x00, 0x00, 0x10},
1234 {0xa1, 0x18, 0x5a, 0xa0, 0x00, 0x00, 0x00, 0x10},
1235 {0xa1, 0x18, 0x5b, 0x99, 0x00, 0x00, 0x00, 0x10},
1236 {0xa1, 0x18, 0x5c, 0x90, 0x00, 0x00, 0x00, 0x10},
1237 {0xa1, 0x18, 0x5e, 0x24, 0x00, 0x00, 0x00, 0x10},
1238 {0xa1, 0x18, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x10},
1239 {0xa1, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00, 0x10},
1240 {0xa1, 0x18, 0x61, 0x73, 0x00, 0x00, 0x00, 0x10},
1241 {0xa1, 0x18, 0x63, 0x42, 0x00, 0x00, 0x00, 0x10},
1242 {0xa1, 0x18, 0x64, 0x42, 0x00, 0x00, 0x00, 0x10},
1243 {0xa1, 0x18, 0x65, 0x42, 0x00, 0x00, 0x00, 0x10},
1244 {0xa1, 0x18, 0x66, 0x24, 0x00, 0x00, 0x00, 0x10},
1245 {0xa1, 0x18, 0x67, 0x24, 0x00, 0x00, 0x00, 0x10},
1246 {0xa1, 0x18, 0x68, 0x08, 0x00, 0x00, 0x00, 0x10},
1247 {0xa1, 0x18, 0x2f, 0xc9, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001248 {}
1249};
1250static const u8 sp80708_sensor_param1[][8] = {
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001251 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
1252 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
1253 {0xa1, 0x18, 0x03, 0x01, 0x00, 0x00, 0x00, 0x10},
1254 {0xa1, 0x18, 0x04, 0xa4, 0x00, 0x00, 0x00, 0x10},
1255 {0xa1, 0x18, 0x14, 0x3f, 0x00, 0x00, 0x00, 0x10},
1256 {0xa1, 0x18, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
1257 {0xb1, 0x18, 0x11, 0x40, 0x40, 0x00, 0x00, 0x10},
1258 {}
1259};
1260
Jean-François Moine9c33afc2010-03-17 15:25:32 -03001261static const u8 (*sensor_init[])[8] = {
1262[SENSOR_ADCM1700] = adcm1700_sensor_init,
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001263[SENSOR_GC0307] = gc0307_sensor_init,
Jean-François Moine9c33afc2010-03-17 15:25:32 -03001264[SENSOR_HV7131R] = hv7131r_sensor_init,
1265[SENSOR_MI0360] = mi0360_sensor_init,
1266[SENSOR_MO4000] = mo4000_sensor_init,
1267[SENSOR_MT9V111] = mt9v111_sensor_init,
1268[SENSOR_OM6802] = om6802_sensor_init,
1269[SENSOR_OV7630] = ov7630_sensor_init,
1270[SENSOR_OV7648] = ov7648_sensor_init,
1271[SENSOR_OV7660] = ov7660_sensor_init,
1272[SENSOR_PO1030] = po1030_sensor_init,
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001273[SENSOR_PO2030N] = po2030n_sensor_init,
Jean-François Moine9c33afc2010-03-17 15:25:32 -03001274[SENSOR_SP80708] = sp80708_sensor_init,
Jean-Francois Moine23a98272009-11-02 09:10:25 -03001275};
1276
Jean-Francois Moine8295d992008-09-03 17:12:19 -03001277/* read <len> bytes to gspca_dev->usb_buf */
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001278static void reg_r(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -03001279 u16 value, int len)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001280{
Jean-Francois Moine8295d992008-09-03 17:12:19 -03001281#ifdef GSPCA_DEBUG
1282 if (len > USB_BUF_SZ) {
1283 err("reg_r: buffer overflow");
1284 return;
1285 }
1286#endif
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001287 usb_control_msg(gspca_dev->dev,
1288 usb_rcvctrlpipe(gspca_dev->dev, 0),
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001289 0,
1290 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1291 value, 0,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001292 gspca_dev->usb_buf, len,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001293 500);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001294 PDEBUG(D_USBI, "reg_r [%02x] -> %02x", value, gspca_dev->usb_buf[0]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001295}
1296
Jean-Francois Moine60017612008-07-18 08:46:19 -03001297static void reg_w1(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -03001298 u16 value,
1299 u8 data)
Jean-Francois Moine60017612008-07-18 08:46:19 -03001300{
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001301 PDEBUG(D_USBO, "reg_w1 [%04x] = %02x", value, data);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001302 gspca_dev->usb_buf[0] = data;
1303 usb_control_msg(gspca_dev->dev,
1304 usb_sndctrlpipe(gspca_dev->dev, 0),
1305 0x08,
1306 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1307 value,
1308 0,
1309 gspca_dev->usb_buf, 1,
1310 500);
1311}
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001312static void reg_w(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -03001313 u16 value,
1314 const u8 *buffer,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001315 int len)
1316{
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001317 PDEBUG(D_USBO, "reg_w [%04x] = %02x %02x ..",
Jean-Francois Moine60017612008-07-18 08:46:19 -03001318 value, buffer[0], buffer[1]);
Jean-Francois Moine8295d992008-09-03 17:12:19 -03001319#ifdef GSPCA_DEBUG
1320 if (len > USB_BUF_SZ) {
1321 err("reg_w: buffer overflow");
1322 return;
Jean-Francois Moinebf7f0b92008-07-03 11:09:12 -03001323 }
Jean-Francois Moine8295d992008-09-03 17:12:19 -03001324#endif
1325 memcpy(gspca_dev->usb_buf, buffer, len);
1326 usb_control_msg(gspca_dev->dev,
1327 usb_sndctrlpipe(gspca_dev->dev, 0),
1328 0x08,
1329 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1330 value, 0,
1331 gspca_dev->usb_buf, len,
1332 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001333}
1334
Jean-Francois Moine60017612008-07-18 08:46:19 -03001335/* I2C write 1 byte */
Jean-Francois Moine98819182009-01-19 07:37:33 -03001336static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001337{
1338 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001339
Jean-Francois Moine60017612008-07-18 08:46:19 -03001340 PDEBUG(D_USBO, "i2c_w2 [%02x] = %02x", reg, val);
Jean-Francois Moinea7826362009-11-02 09:21:06 -03001341 switch (sd->sensor) {
Jean-Francois Moine64677572009-12-20 12:31:28 -03001342 case SENSOR_ADCM1700:
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001343 case SENSOR_OM6802:
1344 case SENSOR_GC0307: /* i2c command = a0 (100 kHz) */
Jean-Francois Moinea7826362009-11-02 09:21:06 -03001345 gspca_dev->usb_buf[0] = 0x80 | (2 << 4);
1346 break;
1347 default: /* i2c command = a1 (400 kHz) */
1348 gspca_dev->usb_buf[0] = 0x81 | (2 << 4);
1349 break;
1350 }
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001351 gspca_dev->usb_buf[1] = sd->i2c_addr;
Jean-Francois Moine60017612008-07-18 08:46:19 -03001352 gspca_dev->usb_buf[2] = reg;
1353 gspca_dev->usb_buf[3] = val;
1354 gspca_dev->usb_buf[4] = 0;
1355 gspca_dev->usb_buf[5] = 0;
1356 gspca_dev->usb_buf[6] = 0;
1357 gspca_dev->usb_buf[7] = 0x10;
1358 usb_control_msg(gspca_dev->dev,
1359 usb_sndctrlpipe(gspca_dev->dev, 0),
1360 0x08,
1361 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1362 0x08, /* value = i2c */
1363 0,
1364 gspca_dev->usb_buf, 8,
1365 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001366}
1367
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001368/* I2C write 8 bytes */
1369static void i2c_w8(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -03001370 const u8 *buffer)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001371{
Jean-Francois Moine60017612008-07-18 08:46:19 -03001372 memcpy(gspca_dev->usb_buf, buffer, 8);
1373 usb_control_msg(gspca_dev->dev,
1374 usb_sndctrlpipe(gspca_dev->dev, 0),
1375 0x08,
1376 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1377 0x08, 0, /* value, index */
1378 gspca_dev->usb_buf, 8,
1379 500);
Jean-Francois Moine8d768e12008-09-21 03:28:55 -03001380 msleep(2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001381}
1382
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001383/* sensor read 'len' (1..5) bytes in gspca_dev->usb_buf */
1384static void i2c_r(struct gspca_dev *gspca_dev, u8 reg, int len)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001385{
1386 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001387 u8 mode[8];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001388
Jean-Francois Moinea7826362009-11-02 09:21:06 -03001389 switch (sd->sensor) {
Jean-Francois Moine64677572009-12-20 12:31:28 -03001390 case SENSOR_ADCM1700:
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001391 case SENSOR_OM6802:
1392 case SENSOR_GC0307: /* i2c command = a0 (100 kHz) */
Jean-Francois Moinea7826362009-11-02 09:21:06 -03001393 mode[0] = 0x80 | 0x10;
1394 break;
1395 default: /* i2c command = 91 (400 kHz) */
1396 mode[0] = 0x81 | 0x10;
1397 break;
1398 }
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001399 mode[1] = sd->i2c_addr;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001400 mode[2] = reg;
1401 mode[3] = 0;
1402 mode[4] = 0;
1403 mode[5] = 0;
1404 mode[6] = 0;
1405 mode[7] = 0x10;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001406 i2c_w8(gspca_dev, mode);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001407 msleep(2);
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001408 mode[0] = (mode[0] & 0x81) | (len << 4) | 0x02;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001409 mode[2] = 0;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001410 i2c_w8(gspca_dev, mode);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001411 msleep(2);
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001412 reg_r(gspca_dev, 0x0a, 5);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001413}
1414
Jean-Francois Moine23a98272009-11-02 09:10:25 -03001415static void i2c_w_seq(struct gspca_dev *gspca_dev,
1416 const u8 (*data)[8])
1417{
1418 while ((*data)[0] != 0) {
1419 if ((*data)[0] != 0xdd)
1420 i2c_w8(gspca_dev, *data);
1421 else
1422 msleep((*data)[1]);
1423 data++;
1424 }
1425}
1426
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03001427static void hv7131r_probe(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001428{
Jean-Francois Moine60017612008-07-18 08:46:19 -03001429 i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001430 msleep(10);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001431 reg_w1(gspca_dev, 0x02, 0x66); /* Gpio on */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001432 msleep(10);
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001433 i2c_r(gspca_dev, 0, 5); /* read sensor id */
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001434 if (gspca_dev->usb_buf[0] == 0x02
1435 && gspca_dev->usb_buf[1] == 0x09
1436 && gspca_dev->usb_buf[2] == 0x01
1437 && gspca_dev->usb_buf[3] == 0x00
1438 && gspca_dev->usb_buf[4] == 0x00) {
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03001439 PDEBUG(D_PROBE, "Sensor sn9c102P HV7131R found");
1440 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001441 }
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03001442 PDEBUG(D_PROBE, "Sensor 0x%02x 0x%02x 0x%02x - sn9c102P not found",
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001443 gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
1444 gspca_dev->usb_buf[2]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001445}
1446
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001447static void mi0360_probe(struct gspca_dev *gspca_dev)
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001448{
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001449 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001450 int i, j;
Jean-Francois Moine92e8c912009-02-02 16:25:38 -03001451 u16 val = 0;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001452 static const u8 probe_tb[][4][8] = {
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001453 { /* mi0360 */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001454 {0xb0, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
1455 {0x90, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1456 {0xa2, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1457 {0xb0, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10}
1458 },
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001459 { /* mt9v111 */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001460 {0xb0, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10},
1461 {0x90, 0x5c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x10},
1462 {0xa2, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1463 {}
1464 },
1465 };
1466
1467 for (i = 0; i < ARRAY_SIZE(probe_tb); i++) {
1468 reg_w1(gspca_dev, 0x17, 0x62);
1469 reg_w1(gspca_dev, 0x01, 0x08);
1470 for (j = 0; j < 3; j++)
1471 i2c_w8(gspca_dev, probe_tb[i][j]);
1472 msleep(2);
1473 reg_r(gspca_dev, 0x0a, 5);
1474 val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
1475 if (probe_tb[i][3][0] != 0)
1476 i2c_w8(gspca_dev, probe_tb[i][3]);
1477 reg_w1(gspca_dev, 0x01, 0x29);
1478 reg_w1(gspca_dev, 0x17, 0x42);
1479 if (val != 0xffff)
1480 break;
1481 }
1482 switch (val) {
1483 case 0x823a:
1484 PDEBUG(D_PROBE, "Sensor mt9v111");
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001485 sd->sensor = SENSOR_MT9V111;
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001486 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001487 case 0x8243:
1488 PDEBUG(D_PROBE, "Sensor mi0360");
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001489 break;
1490 default:
1491 PDEBUG(D_PROBE, "Unknown sensor %04x - forced to mi0360", val);
1492 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001493 }
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001494}
1495
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001496static void ov7648_probe(struct gspca_dev *gspca_dev)
1497{
1498 struct sd *sd = (struct sd *) gspca_dev;
1499
1500 /* check ov76xx */
1501 reg_w1(gspca_dev, 0x17, 0x62);
1502 reg_w1(gspca_dev, 0x01, 0x08);
1503 sd->i2c_addr = 0x21;
1504 i2c_r(gspca_dev, 0x0a, 2);
1505 if (gspca_dev->usb_buf[3] == 0x76) { /* ov76xx */
1506 PDEBUG(D_PROBE, "Sensor ov%02x%02x",
1507 gspca_dev->usb_buf[3], gspca_dev->usb_buf[4]);
1508 return;
1509 }
1510
1511 /* reset */
1512 reg_w1(gspca_dev, 0x01, 0x29);
1513 reg_w1(gspca_dev, 0x17, 0x42);
1514
1515 /* check po1030 */
1516 reg_w1(gspca_dev, 0x17, 0x62);
1517 reg_w1(gspca_dev, 0x01, 0x08);
1518 sd->i2c_addr = 0x6e;
1519 i2c_r(gspca_dev, 0x00, 2);
1520 if (gspca_dev->usb_buf[3] == 0x10 /* po1030 */
1521 && gspca_dev->usb_buf[4] == 0x30) {
1522 PDEBUG(D_PROBE, "Sensor po1030");
1523 sd->sensor = SENSOR_PO1030;
1524 return;
1525 }
1526
1527 PDEBUG(D_PROBE, "Unknown sensor %02x%02x",
1528 gspca_dev->usb_buf[3], gspca_dev->usb_buf[4]);
1529}
1530
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001531/* 0c45:6142 sensor may be po2030n, gc0305 or gc0307 */
1532static void po2030n_probe(struct gspca_dev *gspca_dev)
1533{
1534 struct sd *sd = (struct sd *) gspca_dev;
1535
1536 /* check gc0307 */
1537 reg_w1(gspca_dev, 0x17, 0x62);
1538 reg_w1(gspca_dev, 0x01, 0x08);
1539 reg_w1(gspca_dev, 0x02, 0x22);
1540 sd->i2c_addr = 0x21;
1541 i2c_r(gspca_dev, 0x00, 1);
1542
1543 reg_w1(gspca_dev, 0x01, 0x29); /* reset */
1544 reg_w1(gspca_dev, 0x17, 0x42);
1545
1546 if (gspca_dev->usb_buf[4] == 0x99) { /* gc0307 (?) */
1547 PDEBUG(D_PROBE, "Sensor gc0307");
1548 sd->sensor = SENSOR_GC0307;
1549 return;
1550 }
1551
1552 /* check po2030n */
1553 reg_w1(gspca_dev, 0x17, 0x62);
1554 reg_w1(gspca_dev, 0x01, 0x0a);
1555 sd->i2c_addr = 0x6e;
1556 i2c_r(gspca_dev, 0x00, 2);
1557
1558 reg_w1(gspca_dev, 0x01, 0x29);
1559 reg_w1(gspca_dev, 0x17, 0x42);
1560
1561 if (gspca_dev->usb_buf[3] == 0x20
1562 && gspca_dev->usb_buf[4] == 0x30)
1563 PDEBUG(D_PROBE, "Sensor po2030n");
1564/* sd->sensor = SENSOR_PO2030N; */
1565 else
1566 PDEBUG(D_PROBE, "Unknown sensor ID %02x%02x",
1567 gspca_dev->usb_buf[3],
1568 gspca_dev->usb_buf[4]);
1569}
1570
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001571static void bridge_init(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -03001572 const u8 *sn9c1xx)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001573{
1574 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001575 const u8 *reg9a;
1576 static const u8 reg9a_def[] =
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03001577 {0x00, 0x40, 0x20, 0x00, 0x00, 0x00};
1578 static const u8 reg9a_spec[] =
1579 {0x00, 0x40, 0x38, 0x30, 0x00, 0x20};
Jean-Francois Moine98819182009-01-19 07:37:33 -03001580 static const u8 regd4[] = {0x60, 0x00, 0x00};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001581
Hans de Goede9712a8b2010-01-31 12:54:29 -03001582 /* sensor clock already enabled in sd_init */
1583 /* reg_w1(gspca_dev, 0xf1, 0x00); */
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001584 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001585
1586 /* configure gpio */
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001587 reg_w(gspca_dev, 0x01, &sn9c1xx[1], 2);
1588 reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001589 reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5);
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03001590 switch (sd->sensor) {
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001591 case SENSOR_GC0307:
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03001592 case SENSOR_OV7660:
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001593 case SENSOR_PO1030:
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001594 case SENSOR_PO2030N:
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03001595 case SENSOR_SP80708:
1596 reg9a = reg9a_spec;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001597 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001598 default:
1599 reg9a = reg9a_def;
1600 break;
1601 }
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001602 reg_w(gspca_dev, 0x9a, reg9a, 6);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001603
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001604 reg_w(gspca_dev, 0xd4, regd4, sizeof regd4);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001605
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001606 reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001607
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001608 switch (sd->sensor) {
Jean-Francois Moine64677572009-12-20 12:31:28 -03001609 case SENSOR_ADCM1700:
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03001610 reg_w1(gspca_dev, 0x01, 0x43);
Jean-Francois Moine64677572009-12-20 12:31:28 -03001611 reg_w1(gspca_dev, 0x17, 0x62);
1612 reg_w1(gspca_dev, 0x01, 0x42);
1613 reg_w1(gspca_dev, 0x01, 0x42);
1614 break;
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001615 case SENSOR_GC0307:
1616 msleep(50);
1617 reg_w1(gspca_dev, 0x01, 0x61);
1618 reg_w1(gspca_dev, 0x17, 0x22);
1619 reg_w1(gspca_dev, 0x01, 0x60);
1620 reg_w1(gspca_dev, 0x01, 0x40);
1621 msleep(50);
1622 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001623 case SENSOR_MT9V111:
1624 reg_w1(gspca_dev, 0x01, 0x61);
1625 reg_w1(gspca_dev, 0x17, 0x61);
1626 reg_w1(gspca_dev, 0x01, 0x60);
1627 reg_w1(gspca_dev, 0x01, 0x40);
1628 break;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001629 case SENSOR_OM6802:
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001630 msleep(10);
1631 reg_w1(gspca_dev, 0x02, 0x73);
1632 reg_w1(gspca_dev, 0x17, 0x60);
1633 reg_w1(gspca_dev, 0x01, 0x22);
1634 msleep(100);
1635 reg_w1(gspca_dev, 0x01, 0x62);
1636 reg_w1(gspca_dev, 0x17, 0x64);
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001637 reg_w1(gspca_dev, 0x17, 0x64);
1638 reg_w1(gspca_dev, 0x01, 0x42);
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001639 msleep(10);
1640 reg_w1(gspca_dev, 0x01, 0x42);
1641 i2c_w8(gspca_dev, om6802_init0[0]);
1642 i2c_w8(gspca_dev, om6802_init0[1]);
1643 msleep(15);
1644 reg_w1(gspca_dev, 0x02, 0x71);
1645 msleep(150);
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001646 break;
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001647 case SENSOR_OV7630:
1648 reg_w1(gspca_dev, 0x01, 0x61);
1649 reg_w1(gspca_dev, 0x17, 0xe2);
1650 reg_w1(gspca_dev, 0x01, 0x60);
1651 reg_w1(gspca_dev, 0x01, 0x40);
1652 break;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001653 case SENSOR_OV7648:
Jean-Francois Moine62703302008-11-11 08:42:56 -03001654 reg_w1(gspca_dev, 0x01, 0x63);
1655 reg_w1(gspca_dev, 0x17, 0x20);
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03001656 reg_w1(gspca_dev, 0x01, 0x62);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001657 reg_w1(gspca_dev, 0x01, 0x42);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001658 break;
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001659 case SENSOR_PO1030:
1660 reg_w1(gspca_dev, 0x01, 0x61);
1661 reg_w1(gspca_dev, 0x17, 0x20);
1662 reg_w1(gspca_dev, 0x01, 0x60);
1663 reg_w1(gspca_dev, 0x01, 0x40);
1664 break;
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001665 case SENSOR_PO2030N:
1666 reg_w1(gspca_dev, 0x01, 0x63);
1667 reg_w1(gspca_dev, 0x17, 0x20);
1668 reg_w1(gspca_dev, 0x01, 0x62);
1669 reg_w1(gspca_dev, 0x01, 0x42);
1670 break;
Jean-Francois Moine91de65a2008-09-03 17:12:18 -03001671 case SENSOR_OV7660:
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001672 /* fall thru */
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001673 case SENSOR_SP80708:
1674 reg_w1(gspca_dev, 0x01, 0x63);
1675 reg_w1(gspca_dev, 0x17, 0x20);
1676 reg_w1(gspca_dev, 0x01, 0x62);
1677 reg_w1(gspca_dev, 0x01, 0x42);
Jean-Francois Moine1f78a972009-08-29 07:11:58 -03001678 msleep(100);
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001679 reg_w1(gspca_dev, 0x02, 0x62);
1680 break;
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001681 default:
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03001682/* case SENSOR_HV7131R: */
1683/* case SENSOR_MI0360: */
1684/* case SENSOR_MO4000: */
Jean-Francois Moine60017612008-07-18 08:46:19 -03001685 reg_w1(gspca_dev, 0x01, 0x43);
1686 reg_w1(gspca_dev, 0x17, 0x61);
1687 reg_w1(gspca_dev, 0x01, 0x42);
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001688 if (sd->sensor == SENSOR_HV7131R
1689 && sd->bridge == BRIDGE_SN9C102P)
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03001690 hv7131r_probe(gspca_dev);
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001691 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001692 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001693}
1694
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001695/* this function is called at probe time */
1696static int sd_config(struct gspca_dev *gspca_dev,
1697 const struct usb_device_id *id)
1698{
1699 struct sd *sd = (struct sd *) gspca_dev;
1700 struct cam *cam;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001701
Jean-Francois Moineeac8f5f2010-01-12 07:12:43 -03001702 sd->bridge = id->driver_info >> 16;
1703 sd->sensor = id->driver_info;
1704
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001705 cam = &gspca_dev->cam;
Jean-Francois Moine64677572009-12-20 12:31:28 -03001706 if (sd->sensor == SENSOR_ADCM1700) {
1707 cam->cam_mode = cif_mode;
1708 cam->nmodes = ARRAY_SIZE(cif_mode);
1709 } else {
1710 cam->cam_mode = vga_mode;
1711 cam->nmodes = ARRAY_SIZE(vga_mode);
1712 }
Jean-Francois Moine49cb6b02009-04-25 13:29:01 -03001713 cam->npkt = 24; /* 24 packets per ISOC message */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001714
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001715 sd->brightness = BRIGHTNESS_DEF;
1716 sd->contrast = CONTRAST_DEF;
1717 sd->colors = COLOR_DEF;
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001718 sd->blue = BLUE_BALANCE_DEF;
1719 sd->red = RED_BALANCE_DEF;
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03001720 sd->gamma = GAMMA_DEF;
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001721 sd->autogain = AUTOGAIN_DEF;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001722 sd->ag_cnt = -1;
Hans de Goedef8009522009-06-18 14:29:20 -03001723 sd->vflip = VFLIP_DEF;
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03001724 switch (sd->sensor) {
1725 case SENSOR_OM6802:
1726 sd->sharpness = 0x10;
1727 break;
1728 default:
1729 sd->sharpness = SHARPNESS_DEF;
1730 break;
1731 }
Jean-Francois Moine0cae8962008-10-17 07:48:24 -03001732 sd->infrared = INFRARED_DEF;
Hans de Goede37c6dbe2009-06-18 07:35:36 -03001733 sd->freq = FREQ_DEF;
Jean-Francois Moine77ac0ba2009-03-02 06:40:52 -03001734 sd->quality = QUALITY_DEF;
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03001735 sd->jpegqual = 80;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001736
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001737 return 0;
1738}
1739
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03001740/* this function is called at probe and resume time */
1741static int sd_init(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001742{
1743 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001744 const u8 *sn9c1xx;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001745 u8 regGpio[] = { 0x29, 0x74 };
1746 u8 regF1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001747
Hans de Goede3647fea2008-07-15 05:36:30 -03001748 /* setup a selector by bridge */
Jean-Francois Moine60017612008-07-18 08:46:19 -03001749 reg_w1(gspca_dev, 0xf1, 0x01);
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001750 reg_r(gspca_dev, 0x00, 1);
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001751 reg_w1(gspca_dev, 0xf1, gspca_dev->usb_buf[0]);
1752 reg_r(gspca_dev, 0x00, 1); /* get sonix chip id */
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001753 regF1 = gspca_dev->usb_buf[0];
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001754 PDEBUG(D_PROBE, "Sonix chip id: %02x", regF1);
Hans de Goede3647fea2008-07-15 05:36:30 -03001755 switch (sd->bridge) {
1756 case BRIDGE_SN9C102P:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001757 if (regF1 != 0x11)
1758 return -ENODEV;
Jean-Francois Moine60017612008-07-18 08:46:19 -03001759 reg_w1(gspca_dev, 0x02, regGpio[1]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001760 break;
Hans de Goede3647fea2008-07-15 05:36:30 -03001761 case BRIDGE_SN9C105:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001762 if (regF1 != 0x11)
1763 return -ENODEV;
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001764 if (sd->sensor == SENSOR_MI0360)
1765 mi0360_probe(gspca_dev);
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001766 reg_w(gspca_dev, 0x01, regGpio, 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001767 break;
Hans de Goede3647fea2008-07-15 05:36:30 -03001768 case BRIDGE_SN9C120:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001769 if (regF1 != 0x12)
1770 return -ENODEV;
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001771 switch (sd->sensor) {
1772 case SENSOR_MI0360:
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001773 mi0360_probe(gspca_dev);
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001774 break;
1775 case SENSOR_OV7648:
1776 ov7648_probe(gspca_dev);
1777 break;
Jean-François Moinead98c0f2010-03-18 05:15:30 -03001778 case SENSOR_PO2030N:
1779 po2030n_probe(gspca_dev);
1780 break;
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001781 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001782 regGpio[1] = 0x70;
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001783 reg_w(gspca_dev, 0x01, regGpio, 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001784 break;
1785 default:
Jean-Francois Moine60017612008-07-18 08:46:19 -03001786/* case BRIDGE_SN9C110: */
Hans de Goede3647fea2008-07-15 05:36:30 -03001787/* case BRIDGE_SN9C325: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001788 if (regF1 != 0x12)
1789 return -ENODEV;
Jean-Francois Moine60017612008-07-18 08:46:19 -03001790 reg_w1(gspca_dev, 0x02, 0x62);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001791 break;
1792 }
1793
Hans de Goede9712a8b2010-01-31 12:54:29 -03001794 /* Note we do not disable the sensor clock here (power saving mode),
1795 as that also disables the button on the cam. */
1796 reg_w1(gspca_dev, 0xf1, 0x00);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001797
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001798 /* set the i2c address */
1799 sn9c1xx = sn_tb[sd->sensor];
1800 sd->i2c_addr = sn9c1xx[9];
1801
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03001802 gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
1803
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001804 return 0;
1805}
1806
Jean-Francois Moine98819182009-01-19 07:37:33 -03001807static u32 setexposure(struct gspca_dev *gspca_dev,
1808 u32 expo)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001809{
1810 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001811
1812 switch (sd->sensor) {
Jean-François Moinec26b12d2010-04-02 07:08:39 -03001813 case SENSOR_GC0307: {
1814 int a, b;
1815
1816 /* expo = 0..255 -> a = 19..43 */
1817 a = 19 + expo * 25 / 256;
1818 i2c_w1(gspca_dev, 0x68, a);
1819 a -= 12;
1820 b = a * a * 4; /* heuristic */
1821 i2c_w1(gspca_dev, 0x03, b >> 8);
1822 i2c_w1(gspca_dev, 0x04, b);
1823 break;
1824 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001825 case SENSOR_HV7131R: {
Jean-Francois Moine98819182009-01-19 07:37:33 -03001826 u8 Expodoit[] =
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001827 { 0xc1, 0x11, 0x25, 0x00, 0x00, 0x00, 0x00, 0x16 };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001828
1829 Expodoit[3] = expo >> 16;
1830 Expodoit[4] = expo >> 8;
1831 Expodoit[5] = expo;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001832 i2c_w8(gspca_dev, Expodoit);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001833 break;
1834 }
1835 case SENSOR_MI0360: {
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001836 u8 expoMi[] = /* exposure 0x0635 -> 4 fp/s 0x10 */
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001837 { 0xb1, 0x5d, 0x09, 0x00, 0x00, 0x00, 0x00, 0x16 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001838 static const u8 doit[] = /* update sensor */
1839 { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
1840 static const u8 sensorgo[] = /* sensor on */
1841 { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001842
1843 if (expo > 0x0635)
1844 expo = 0x0635;
1845 else if (expo < 0x0001)
1846 expo = 0x0001;
1847 expoMi[3] = expo >> 8;
1848 expoMi[4] = expo;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001849 i2c_w8(gspca_dev, expoMi);
1850 i2c_w8(gspca_dev, doit);
1851 i2c_w8(gspca_dev, sensorgo);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001852 break;
1853 }
1854 case SENSOR_MO4000: {
Jean-Francois Moine98819182009-01-19 07:37:33 -03001855 u8 expoMof[] =
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001856 { 0xa1, 0x21, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001857 u8 expoMo10[] =
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001858 { 0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001859 static const u8 gainMo[] =
1860 { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001861
1862 if (expo > 0x1fff)
1863 expo = 0x1fff;
1864 else if (expo < 0x0001)
1865 expo = 0x0001;
1866 expoMof[3] = (expo & 0x03fc) >> 2;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001867 i2c_w8(gspca_dev, expoMof);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001868 expoMo10[3] = ((expo & 0x1c00) >> 10)
1869 | ((expo & 0x0003) << 4);
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001870 i2c_w8(gspca_dev, expoMo10);
1871 i2c_w8(gspca_dev, gainMo);
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001872 PDEBUG(D_FRAM, "set exposure %d",
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001873 ((expoMo10[3] & 0x07) << 10)
1874 | (expoMof[3] << 2)
1875 | ((expoMo10[3] & 0x30) >> 4));
1876 break;
1877 }
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001878 case SENSOR_MT9V111: {
1879 u8 expo_c1[] =
1880 { 0xb1, 0x5c, 0x09, 0x00, 0x00, 0x00, 0x00, 0x10 };
1881
1882 if (expo > 0x0280)
1883 expo = 0x0280;
1884 else if (expo < 0x0040)
1885 expo = 0x0040;
1886 expo_c1[3] = expo >> 8;
1887 expo_c1[4] = expo;
1888 i2c_w8(gspca_dev, expo_c1);
1889 break;
1890 }
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001891 case SENSOR_OM6802: {
Jean-Francois Moine98819182009-01-19 07:37:33 -03001892 u8 gainOm[] =
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001893 { 0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001894 /* preset AGC - works when AutoExpo = off */
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001895
1896 if (expo > 0x03ff)
1897 expo = 0x03ff;
1898 if (expo < 0x0001)
1899 expo = 0x0001;
1900 gainOm[3] = expo >> 2;
1901 i2c_w8(gspca_dev, gainOm);
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001902 reg_w1(gspca_dev, 0x96, expo >> 5);
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001903 PDEBUG(D_FRAM, "set exposure %d", gainOm[3]);
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001904 break;
1905 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001906 }
1907 return expo;
1908}
1909
1910static void setbrightness(struct gspca_dev *gspca_dev)
1911{
1912 struct sd *sd = (struct sd *) gspca_dev;
1913 unsigned int expo;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001914 u8 k2;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001915
Jean-Francois Moineb1b056a2008-11-25 04:47:09 -03001916 k2 = ((int) sd->brightness - 0x8000) >> 10;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001917 switch (sd->sensor) {
Jean-Francois Moine64677572009-12-20 12:31:28 -03001918 case SENSOR_ADCM1700:
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03001919 if (k2 > 0x1f)
1920 k2 = 0; /* only positive Y offset */
1921 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001922 case SENSOR_HV7131R:
1923 expo = sd->brightness << 4;
1924 if (expo > 0x002dc6c0)
1925 expo = 0x002dc6c0;
1926 else if (expo < 0x02a0)
1927 expo = 0x02a0;
1928 sd->exposure = setexposure(gspca_dev, expo);
1929 break;
1930 case SENSOR_MI0360:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001931 case SENSOR_MO4000:
1932 expo = sd->brightness >> 4;
1933 sd->exposure = setexposure(gspca_dev, expo);
1934 break;
Jean-François Moinec26b12d2010-04-02 07:08:39 -03001935 case SENSOR_GC0307:
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001936 case SENSOR_MT9V111:
1937 expo = sd->brightness >> 8;
1938 sd->exposure = setexposure(gspca_dev, expo);
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001939 return; /* don't set the Y offset */
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001940 case SENSOR_OM6802:
1941 expo = sd->brightness >> 6;
1942 sd->exposure = setexposure(gspca_dev, expo);
Jean-Francois Moineb1b056a2008-11-25 04:47:09 -03001943 k2 = sd->brightness >> 11;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001944 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001945 }
1946
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001947 reg_w1(gspca_dev, 0x96, k2); /* color matrix Y offset */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001948}
1949
1950static void setcontrast(struct gspca_dev *gspca_dev)
1951{
1952 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001953 u8 k2;
1954 u8 contrast[6];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001955
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03001956 k2 = sd->contrast * 0x30 / (CONTRAST_MAX + 1) + 0x10; /* 10..40 */
1957 contrast[0] = (k2 + 1) / 2; /* red */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -03001958 contrast[1] = 0;
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03001959 contrast[2] = k2; /* green */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -03001960 contrast[3] = 0;
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03001961 contrast[4] = (k2 + 1) / 5; /* blue */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -03001962 contrast[5] = 0;
1963 reg_w(gspca_dev, 0x84, contrast, sizeof contrast);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001964}
1965
1966static void setcolors(struct gspca_dev *gspca_dev)
1967{
1968 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001969 int i, v;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001970 u8 reg8a[12]; /* U & V gains */
Jean-François Moine9c33afc2010-03-17 15:25:32 -03001971 static const s16 uv[6] = { /* same as reg84 in signed decimal */
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001972 -24, -38, 64, /* UR UG UB */
1973 62, -51, -9 /* VR VG VB */
1974 };
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001975
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001976 for (i = 0; i < 6; i++) {
1977 v = uv[i] * sd->colors / COLOR_DEF;
Jean-Francois Moinebd088832008-12-02 06:58:57 -03001978 reg8a[i * 2] = v;
1979 reg8a[i * 2 + 1] = (v >> 8) & 0x0f;
Jean-Francois Moined55b83d2008-09-03 16:48:01 -03001980 }
Jean-Francois Moinebd088832008-12-02 06:58:57 -03001981 reg_w(gspca_dev, 0x8a, reg8a, sizeof reg8a);
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001982}
1983
1984static void setredblue(struct gspca_dev *gspca_dev)
1985{
1986 struct sd *sd = (struct sd *) gspca_dev;
1987
1988 reg_w1(gspca_dev, 0x05, sd->red);
Jean-Francois Moine9c5f70f2008-09-03 16:48:04 -03001989/* reg_w1(gspca_dev, 0x07, 32); */
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001990 reg_w1(gspca_dev, 0x06, sd->blue);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001991}
1992
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03001993static void setgamma(struct gspca_dev *gspca_dev)
1994{
1995 struct sd *sd = (struct sd *) gspca_dev;
1996 int i;
1997 u8 gamma[17];
Jean-Francois Moineb083b922009-02-01 14:20:07 -03001998 const u8 *gamma_base;
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03001999 static const u8 delta[17] = {
2000 0x00, 0x14, 0x1c, 0x1c, 0x1c, 0x1c, 0x1b, 0x1a,
2001 0x18, 0x13, 0x10, 0x0e, 0x08, 0x07, 0x04, 0x02, 0x00
2002 };
2003
Jean-Francois Moineb083b922009-02-01 14:20:07 -03002004 switch (sd->sensor) {
Jean-Francois Moine64677572009-12-20 12:31:28 -03002005 case SENSOR_ADCM1700:
2006 gamma_base = gamma_spec_0;
2007 break;
Jean-Francois Moineb083b922009-02-01 14:20:07 -03002008 case SENSOR_HV7131R:
2009 case SENSOR_MT9V111:
2010 gamma_base = gamma_spec_1;
2011 break;
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002012 case SENSOR_GC0307:
Jean-Francois Moineb083b922009-02-01 14:20:07 -03002013 gamma_base = gamma_spec_2;
2014 break;
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002015 case SENSOR_SP80708:
2016 gamma_base = gamma_spec_3;
2017 break;
Jean-Francois Moineb083b922009-02-01 14:20:07 -03002018 default:
2019 gamma_base = gamma_def;
2020 break;
2021 }
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03002022
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03002023 for (i = 0; i < sizeof gamma; i++)
Jean-Francois Moineb083b922009-02-01 14:20:07 -03002024 gamma[i] = gamma_base[i]
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03002025 + delta[i] * (sd->gamma - GAMMA_DEF) / 32;
2026 reg_w(gspca_dev, 0x20, gamma, sizeof gamma);
2027}
2028
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002029static void setautogain(struct gspca_dev *gspca_dev)
2030{
2031 struct sd *sd = (struct sd *) gspca_dev;
2032
Jean-Francois Moinef50ba1b2008-09-03 17:12:14 -03002033 if (gspca_dev->ctrl_dis & (1 << AUTOGAIN_IDX))
2034 return;
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03002035 switch (sd->sensor) {
2036 case SENSOR_OV7630:
2037 case SENSOR_OV7648: {
2038 u8 comb;
2039
2040 if (sd->sensor == SENSOR_OV7630)
2041 comb = 0xc0;
2042 else
2043 comb = 0xa0;
2044 if (sd->autogain)
Hans de Goede1fec7472009-06-18 06:05:07 -03002045 comb |= 0x03;
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03002046 i2c_w1(&sd->gspca_dev, 0x13, comb);
2047 return;
2048 }
2049 }
Jean-Francois Moinef50ba1b2008-09-03 17:12:14 -03002050 if (sd->autogain)
2051 sd->ag_cnt = AG_CNT_START;
2052 else
2053 sd->ag_cnt = -1;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002054}
2055
Jean-François Moinef6b22e52010-02-18 04:12:06 -03002056/* hv7131r/ov7630/ov7648 only */
Jean-Francois Moine6c862742008-09-08 04:57:26 -03002057static void setvflip(struct sd *sd)
2058{
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03002059 u8 comn;
2060
Jean-Francois Moine0939e262009-11-02 09:58:49 -03002061 if (sd->gspca_dev.ctrl_dis & (1 << VFLIP_IDX))
2062 return;
Jean-François Moinef6b22e52010-02-18 04:12:06 -03002063 switch (sd->sensor) {
2064 case SENSOR_HV7131R:
2065 comn = 0x18; /* clkdiv = 1, ablcen = 1 */
2066 if (sd->vflip)
2067 comn |= 0x01;
2068 i2c_w1(&sd->gspca_dev, 0x01, comn); /* sctra */
2069 break;
2070 case SENSOR_OV7630:
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03002071 comn = 0x02;
Hans de Goedef8009522009-06-18 14:29:20 -03002072 if (!sd->vflip)
2073 comn |= 0x80;
Jean-François Moinef6b22e52010-02-18 04:12:06 -03002074 i2c_w1(&sd->gspca_dev, 0x75, comn);
2075 break;
2076 default:
2077/* case SENSOR_OV7648: */
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03002078 comn = 0x06;
Hans de Goedef8009522009-06-18 14:29:20 -03002079 if (sd->vflip)
2080 comn |= 0x80;
Jean-François Moinef6b22e52010-02-18 04:12:06 -03002081 i2c_w1(&sd->gspca_dev, 0x75, comn);
2082 break;
Hans de Goedef8009522009-06-18 14:29:20 -03002083 }
Jean-Francois Moine6c862742008-09-08 04:57:26 -03002084}
2085
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002086static void setsharpness(struct sd *sd)
2087{
2088 reg_w1(&sd->gspca_dev, 0x99, sd->sharpness);
2089}
2090
Jean-Francois Moine0cae8962008-10-17 07:48:24 -03002091static void setinfrared(struct sd *sd)
2092{
Jean-Francois Moine47f7f6f2009-08-25 06:14:54 -03002093 if (sd->gspca_dev.ctrl_dis & (1 << INFRARED_IDX))
2094 return;
Jean-Francois Moine0cae8962008-10-17 07:48:24 -03002095/*fixme: different sequence for StarCam Clip and StarCam 370i */
2096/* Clip */
2097 i2c_w1(&sd->gspca_dev, 0x02, /* gpio */
2098 sd->infrared ? 0x66 : 0x64);
2099}
2100
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002101static void setfreq(struct gspca_dev *gspca_dev)
2102{
2103 struct sd *sd = (struct sd *) gspca_dev;
2104
Jean-Francois Moine27954932009-07-08 05:21:50 -03002105 if (gspca_dev->ctrl_dis & (1 << FREQ_IDX))
2106 return;
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002107 if (sd->sensor == SENSOR_OV7660) {
Jean-Francois Moined8f400e2009-07-08 06:33:44 -03002108 u8 com8;
2109
Jean-Francois Moine47f7f6f2009-08-25 06:14:54 -03002110 com8 = 0xdf; /* auto gain/wb/expo */
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002111 switch (sd->freq) {
2112 case 0: /* Banding filter disabled */
Jean-Francois Moine47f7f6f2009-08-25 06:14:54 -03002113 i2c_w1(gspca_dev, 0x13, com8 | 0x20);
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002114 break;
2115 case 1: /* 50 hz */
Jean-Francois Moined8f400e2009-07-08 06:33:44 -03002116 i2c_w1(gspca_dev, 0x13, com8);
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002117 i2c_w1(gspca_dev, 0x3b, 0x0a);
2118 break;
2119 case 2: /* 60 hz */
Jean-Francois Moined8f400e2009-07-08 06:33:44 -03002120 i2c_w1(gspca_dev, 0x13, com8);
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002121 i2c_w1(gspca_dev, 0x3b, 0x02);
2122 break;
2123 }
2124 } else {
2125 u8 reg2a = 0, reg2b = 0, reg2d = 0;
2126
2127 /* Get reg2a / reg2d base values */
2128 switch (sd->sensor) {
2129 case SENSOR_OV7630:
2130 reg2a = 0x08;
2131 reg2d = 0x01;
2132 break;
2133 case SENSOR_OV7648:
2134 reg2a = 0x11;
2135 reg2d = 0x81;
2136 break;
2137 }
2138
2139 switch (sd->freq) {
2140 case 0: /* Banding filter disabled */
2141 break;
2142 case 1: /* 50 hz (filter on and framerate adj) */
2143 reg2a |= 0x80;
2144 reg2b = 0xac;
2145 reg2d |= 0x04;
2146 break;
2147 case 2: /* 60 hz (filter on, no framerate adj) */
2148 reg2a |= 0x80;
2149 reg2d |= 0x04;
2150 break;
2151 }
2152 i2c_w1(gspca_dev, 0x2a, reg2a);
2153 i2c_w1(gspca_dev, 0x2b, reg2b);
2154 i2c_w1(gspca_dev, 0x2d, reg2d);
2155 }
2156}
2157
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03002158static void setjpegqual(struct gspca_dev *gspca_dev)
2159{
2160 struct sd *sd = (struct sd *) gspca_dev;
2161 int i, sc;
2162
2163 if (sd->jpegqual < 50)
2164 sc = 5000 / sd->jpegqual;
2165 else
2166 sc = 200 - sd->jpegqual * 2;
2167#if USB_BUF_SZ < 64
2168#error "No room enough in usb_buf for quantization table"
2169#endif
2170 for (i = 0; i < 64; i++)
2171 gspca_dev->usb_buf[i] =
2172 (jpeg_head[JPEG_QT0_OFFSET + i] * sc + 50) / 100;
2173 usb_control_msg(gspca_dev->dev,
2174 usb_sndctrlpipe(gspca_dev->dev, 0),
2175 0x08,
2176 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
2177 0x0100, 0,
2178 gspca_dev->usb_buf, 64,
2179 500);
2180 for (i = 0; i < 64; i++)
2181 gspca_dev->usb_buf[i] =
2182 (jpeg_head[JPEG_QT1_OFFSET + i] * sc + 50) / 100;
2183 usb_control_msg(gspca_dev->dev,
2184 usb_sndctrlpipe(gspca_dev->dev, 0),
2185 0x08,
2186 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
2187 0x0140, 0,
2188 gspca_dev->usb_buf, 64,
2189 500);
2190
2191 sd->reg18 ^= 0x40;
2192 reg_w1(gspca_dev, 0x18, sd->reg18);
2193}
2194
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002195/* -- start the camera -- */
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03002196static int sd_start(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002197{
2198 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002199 int i;
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002200 u8 reg1, reg2, reg17;
Jean-Francois Moine98819182009-01-19 07:37:33 -03002201 const u8 *sn9c1xx;
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002202 const u8 (*init)[8];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002203 int mode;
Jean-Francois Moine98819182009-01-19 07:37:33 -03002204 static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
2205 static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
Jean-Francois Moine64677572009-12-20 12:31:28 -03002206 static const u8 CA_adcm1700[] =
2207 { 0x14, 0xec, 0x0a, 0xf6 };
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002208 static const u8 CA_po2030n[] =
2209 { 0x1e, 0xe2, 0x14, 0xec };
Jean-Francois Moine98819182009-01-19 07:37:33 -03002210 static const u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002211 static const u8 CE_gc0307[] =
2212 { 0x32, 0xce, 0x2d, 0xd3 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03002213 static const u8 CE_ov76xx[] =
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03002214 { 0x32, 0xdd, 0x32, 0xdd };
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002215 static const u8 CE_po2030n[] =
2216 { 0x14, 0xe7, 0x1e, 0xdd };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002217
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03002218 /* create the JPEG header */
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03002219 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
2220 0x21); /* JPEG 422 */
2221 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
2222
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002223 /* initialize the bridge */
2224 sn9c1xx = sn_tb[sd->sensor];
2225 bridge_init(gspca_dev, sn9c1xx);
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002226
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002227 /* initialize the sensor */
2228 i2c_w_seq(gspca_dev, sensor_init[sd->sensor]);
2229
2230 switch (sd->sensor) {
Jean-Francois Moine64677572009-12-20 12:31:28 -03002231 case SENSOR_ADCM1700:
2232 reg2 = 0x60;
2233 break;
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002234 case SENSOR_OM6802:
2235 reg2 = 0x71;
2236 break;
2237 case SENSOR_SP80708:
2238 reg2 = 0x62;
2239 break;
2240 default:
2241 reg2 = 0x40;
2242 break;
2243 }
2244 reg_w1(gspca_dev, 0x02, reg2);
2245 reg_w1(gspca_dev, 0x02, reg2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002246
Jean-Francois Moine60017612008-07-18 08:46:19 -03002247 reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]);
2248 reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]);
2249 reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
2250 reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]);
2251 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
Jean-Francois Moine64677572009-12-20 12:31:28 -03002252 if (sd->sensor == SENSOR_ADCM1700) {
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002253 reg_w1(gspca_dev, 0xd2, 0x3a); /* AE_H_SIZE = 116 */
2254 reg_w1(gspca_dev, 0xd3, 0x30); /* AE_V_SIZE = 96 */
Jean-Francois Moine64677572009-12-20 12:31:28 -03002255 } else {
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002256 reg_w1(gspca_dev, 0xd2, 0x6a); /* AE_H_SIZE = 212 */
2257 reg_w1(gspca_dev, 0xd3, 0x50); /* AE_V_SIZE = 160 */
Jean-Francois Moine64677572009-12-20 12:31:28 -03002258 }
Jean-Francois Moine60017612008-07-18 08:46:19 -03002259 reg_w1(gspca_dev, 0xc6, 0x00);
2260 reg_w1(gspca_dev, 0xc7, 0x00);
Jean-Francois Moine64677572009-12-20 12:31:28 -03002261 if (sd->sensor == SENSOR_ADCM1700) {
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002262 reg_w1(gspca_dev, 0xc8, 0x2c); /* AW_H_STOP = 352 */
2263 reg_w1(gspca_dev, 0xc9, 0x24); /* AW_V_STOP = 288 */
Jean-Francois Moine64677572009-12-20 12:31:28 -03002264 } else {
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002265 reg_w1(gspca_dev, 0xc8, 0x50); /* AW_H_STOP = 640 */
2266 reg_w1(gspca_dev, 0xc9, 0x3c); /* AW_V_STOP = 480 */
Jean-Francois Moine64677572009-12-20 12:31:28 -03002267 }
Jean-Francois Moine60017612008-07-18 08:46:19 -03002268 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03002269 switch (sd->sensor) {
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002270 case SENSOR_GC0307:
2271 reg17 = 0xa2;
2272 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03002273 case SENSOR_MT9V111:
2274 reg17 = 0xe0;
2275 break;
Jean-Francois Moine64677572009-12-20 12:31:28 -03002276 case SENSOR_ADCM1700:
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03002277 case SENSOR_OV7630:
2278 reg17 = 0xe2;
2279 break;
2280 case SENSOR_OV7648:
Jean-Francois Moine62703302008-11-11 08:42:56 -03002281 reg17 = 0x20;
Jean-Francois Moine568788a2008-07-15 11:46:06 -03002282 break;
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03002283 case SENSOR_OV7660:
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03002284 reg17 = 0xa0;
2285 break;
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03002286 case SENSOR_PO1030:
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002287 case SENSOR_PO2030N:
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03002288 reg17 = 0xa0;
2289 break;
Jean-Francois Moine568788a2008-07-15 11:46:06 -03002290 default:
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03002291 reg17 = 0x60;
Jean-Francois Moine568788a2008-07-15 11:46:06 -03002292 break;
2293 }
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03002294 reg_w1(gspca_dev, 0x17, reg17);
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002295
2296 reg_w1(gspca_dev, 0x05, 0x00); /* red */
2297 reg_w1(gspca_dev, 0x07, 0x00); /* green */
2298 reg_w1(gspca_dev, 0x06, 0x00); /* blue */
Jean-Francois Moine60017612008-07-18 08:46:19 -03002299 reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
Jean-Francois Moineb083b922009-02-01 14:20:07 -03002300
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03002301 setgamma(gspca_dev);
2302
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002303/*fixme: 8 times with all zeroes and 1 or 2 times with normal values */
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03002304 for (i = 0; i < 8; i++)
2305 reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03002306 switch (sd->sensor) {
Jean-Francois Moine64677572009-12-20 12:31:28 -03002307 case SENSOR_ADCM1700:
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03002308 case SENSOR_OV7660:
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03002309 case SENSOR_SP80708:
2310 reg_w1(gspca_dev, 0x9a, 0x05);
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002311 break;
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002312 case SENSOR_GC0307:
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002313 case SENSOR_MT9V111:
2314 reg_w1(gspca_dev, 0x9a, 0x07);
2315 break;
2316 case SENSOR_OV7648:
2317 reg_w1(gspca_dev, 0x9a, 0x0a);
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03002318 break;
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002319 case SENSOR_PO2030N:
2320 reg_w1(gspca_dev, 0x9a, 0x06);
2321 break;
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03002322 default:
Jean-Francois Moine60017612008-07-18 08:46:19 -03002323 reg_w1(gspca_dev, 0x9a, 0x08);
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03002324 break;
2325 }
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002326 setsharpness(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002327
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002328 reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002329 reg_w1(gspca_dev, 0x05, 0x20); /* red */
2330 reg_w1(gspca_dev, 0x07, 0x20); /* green */
2331 reg_w1(gspca_dev, 0x06, 0x20); /* blue */
Jean-Francois Moine23a98272009-11-02 09:10:25 -03002332
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002333 init = NULL;
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002334 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
Jean-Francois Moine60017612008-07-18 08:46:19 -03002335 if (mode)
Jean-Francois Moine1432f302008-11-21 04:34:15 -03002336 reg1 = 0x46; /* 320x240: clk 48Mhz, video trf enable */
Jean-Francois Moine60017612008-07-18 08:46:19 -03002337 else
Jean-Francois Moine1432f302008-11-21 04:34:15 -03002338 reg1 = 0x06; /* 640x480: clk 24Mhz, video trf enable */
2339 reg17 = 0x61; /* 0x:20: enable sensor clock */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002340 switch (sd->sensor) {
Jean-Francois Moine64677572009-12-20 12:31:28 -03002341 case SENSOR_ADCM1700:
2342 init = adcm1700_sensor_param1;
2343 reg1 = 0x46;
2344 reg17 = 0xe2;
2345 break;
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002346 case SENSOR_GC0307:
2347 init = gc0307_sensor_param1;
2348 reg17 = 0xa2;
2349 reg1 = 0x44;
2350 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002351 case SENSOR_MO4000:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002352 if (mode) {
2353/* reg1 = 0x46; * 320 clk 48Mhz 60fp/s */
2354 reg1 = 0x06; /* clk 24Mz */
2355 } else {
2356 reg17 = 0x22; /* 640 MCKSIZE */
Jean-Francois Moine60017612008-07-18 08:46:19 -03002357/* reg1 = 0x06; * 640 clk 24Mz (done) */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002358 }
2359 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03002360 case SENSOR_MT9V111:
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002361 init = mt9v111_sensor_param1;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03002362 if (mode) {
2363 reg1 = 0x04; /* 320 clk 48Mhz */
2364 } else {
2365/* reg1 = 0x06; * 640 clk 24Mz (done) */
Jean-Francois Moine2687a2f2009-02-01 14:48:55 -03002366 reg17 = 0xc2;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03002367 }
Jean-Francois Moine0fbe0572009-01-30 12:14:02 -03002368 break;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03002369 case SENSOR_OM6802:
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002370 init = om6802_sensor_param1;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03002371 reg17 = 0x64; /* 640 MCKSIZE */
2372 break;
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03002373 case SENSOR_OV7630:
Jean-François Moinebdd2b932010-04-25 14:23:39 -03002374 init = ov7630_sensor_param1;
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03002375 reg17 = 0xe2;
Jean-Francois Moine5b064da2008-09-03 16:48:08 -03002376 reg1 = 0x44;
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03002377 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002378 case SENSOR_OV7648:
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002379 init = ov7648_sensor_param1;
Jean-Francois Moine62703302008-11-11 08:42:56 -03002380 reg17 = 0x21;
2381/* reg1 = 0x42; * 42 - 46? */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002382 break;
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03002383 case SENSOR_OV7660:
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002384 init = ov7660_sensor_param1;
Jean-Francois Moinedaa5cb42008-12-02 15:00:57 -03002385 if (sd->bridge == BRIDGE_SN9C120) {
2386 if (mode) { /* 320x240 - 160x120 */
Jean-Francois Moine1432f302008-11-21 04:34:15 -03002387 reg17 = 0xa2;
2388 reg1 = 0x44; /* 48 Mhz, video trf eneble */
Jean-Francois Moine1432f302008-11-21 04:34:15 -03002389 }
Jean-Francois Moinedaa5cb42008-12-02 15:00:57 -03002390 } else {
2391 reg17 = 0x22;
2392 reg1 = 0x06; /* 24 Mhz, video trf eneble
2393 * inverse power down */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002394 }
2395 break;
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03002396 case SENSOR_PO1030:
2397 init = po1030_sensor_param1;
2398 reg17 = 0xa2;
2399 reg1 = 0x44;
2400 break;
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002401 case SENSOR_PO2030N:
2402 init = po2030n_sensor_param1;
2403 reg1 = 0x46;
2404 reg17 = 0xa2;
2405 break;
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03002406 default:
2407/* case SENSOR_SP80708: */
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002408 init = sp80708_sensor_param1;
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03002409 if (mode) {
2410/*?? reg1 = 0x04; * 320 clk 48Mhz */
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03002411 } else {
2412 reg1 = 0x46; /* 640 clk 48Mz */
2413 reg17 = 0xa2;
2414 }
2415 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002416 }
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002417
2418 /* more sensor initialization - param1 */
2419 if (init != NULL) {
2420 i2c_w_seq(gspca_dev, init);
2421/* init = NULL; */
2422 }
2423
Jean-Francois Moine739570b2008-07-14 09:38:29 -03002424 reg_w(gspca_dev, 0xc0, C0, 6);
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002425 switch (sd->sensor) {
2426 case SENSOR_ADCM1700:
2427 case SENSOR_GC0307:
Jean-Francois Moine64677572009-12-20 12:31:28 -03002428 reg_w(gspca_dev, 0xca, CA_adcm1700, 4);
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002429 break;
2430 case SENSOR_PO2030N:
2431 reg_w(gspca_dev, 0xca, CA_po2030n, 4);
2432 break;
2433 default:
Jean-Francois Moine64677572009-12-20 12:31:28 -03002434 reg_w(gspca_dev, 0xca, CA, 4);
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002435 break;
2436 }
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03002437 switch (sd->sensor) {
Jean-Francois Moine64677572009-12-20 12:31:28 -03002438 case SENSOR_ADCM1700:
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03002439 case SENSOR_OV7630:
2440 case SENSOR_OV7648:
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03002441 case SENSOR_OV7660:
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03002442 reg_w(gspca_dev, 0xce, CE_ov76xx, 4);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002443 break;
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002444 case SENSOR_GC0307:
2445 reg_w(gspca_dev, 0xce, CE_gc0307, 4);
2446 break;
2447 case SENSOR_PO2030N:
2448 reg_w(gspca_dev, 0xce, CE_po2030n, 4);
2449 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002450 default:
Jean-Francois Moine739570b2008-07-14 09:38:29 -03002451 reg_w(gspca_dev, 0xce, CE, 4);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002452 /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */
2453 break;
2454 }
2455
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002456
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002457 /* here change size mode 0 -> VGA; 1 -> CIF */
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03002458 sd->reg18 = sn9c1xx[0x18] | (mode << 4) | 0x40;
2459 reg_w1(gspca_dev, 0x18, sd->reg18);
2460 setjpegqual(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002461
Jean-Francois Moine60017612008-07-18 08:46:19 -03002462 reg_w1(gspca_dev, 0x17, reg17);
Jean-Francois Moine1432f302008-11-21 04:34:15 -03002463 reg_w1(gspca_dev, 0x01, reg1);
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03002464
Jean-François Moine1e5eb112010-02-18 14:56:33 -03002465 setvflip(sd);
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03002466 setbrightness(gspca_dev);
2467 setcontrast(gspca_dev);
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002468 setautogain(gspca_dev);
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002469 setfreq(gspca_dev);
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03002470 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002471}
2472
2473static void sd_stopN(struct gspca_dev *gspca_dev)
2474{
2475 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -03002476 static const u8 stophv7131[] =
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002477 { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03002478 static const u8 stopmi0360[] =
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002479 { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03002480 static const u8 stopov7648[] =
Jean-Francois Moine62703302008-11-11 08:42:56 -03002481 { 0xa1, 0x21, 0x76, 0x20, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03002482 u8 data;
2483 const u8 *sn9c1xx;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002484
2485 data = 0x0b;
2486 switch (sd->sensor) {
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002487 case SENSOR_GC0307:
2488 data = 0x29;
2489 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002490 case SENSOR_HV7131R:
Jean-Francois Moine739570b2008-07-14 09:38:29 -03002491 i2c_w8(gspca_dev, stophv7131);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002492 data = 0x2b;
2493 break;
2494 case SENSOR_MI0360:
Jean-Francois Moine739570b2008-07-14 09:38:29 -03002495 i2c_w8(gspca_dev, stopmi0360);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002496 data = 0x29;
2497 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002498 case SENSOR_OV7648:
Jean-Francois Moine62703302008-11-11 08:42:56 -03002499 i2c_w8(gspca_dev, stopov7648);
2500 /* fall thru */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03002501 case SENSOR_MT9V111:
Jean-Francois Moine62703302008-11-11 08:42:56 -03002502 case SENSOR_OV7630:
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03002503 case SENSOR_PO1030:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002504 data = 0x29;
2505 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002506 }
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002507 sn9c1xx = sn_tb[sd->sensor];
Jean-Francois Moine60017612008-07-18 08:46:19 -03002508 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
2509 reg_w1(gspca_dev, 0x17, sn9c1xx[0x17]);
2510 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
2511 reg_w1(gspca_dev, 0x01, data);
Hans de Goede9712a8b2010-01-31 12:54:29 -03002512 /* Don't disable sensor clock as that disables the button on the cam */
2513 /* reg_w1(gspca_dev, 0xf1, 0x01); */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002514}
2515
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002516static void do_autogain(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002517{
2518 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002519 int delta;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002520 int expotimes;
Jean-Francois Moine98819182009-01-19 07:37:33 -03002521 u8 luma_mean = 130;
2522 u8 luma_delta = 20;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002523
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002524 /* Thanks S., without your advice, autobright should not work :) */
2525 if (sd->ag_cnt < 0)
2526 return;
2527 if (--sd->ag_cnt >= 0)
2528 return;
2529 sd->ag_cnt = AG_CNT_START;
2530
2531 delta = atomic_read(&sd->avg_lum);
2532 PDEBUG(D_FRAM, "mean lum %d", delta);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002533 if (delta < luma_mean - luma_delta ||
2534 delta > luma_mean + luma_delta) {
2535 switch (sd->sensor) {
Jean-François Moinec26b12d2010-04-02 07:08:39 -03002536 case SENSOR_GC0307:
2537 expotimes = sd->exposure;
2538 expotimes += (luma_mean - delta) >> 6;
2539 if (expotimes < 0)
2540 expotimes = 0;
2541 sd->exposure = setexposure(gspca_dev,
2542 (unsigned int) expotimes);
2543 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002544 case SENSOR_HV7131R:
2545 expotimes = sd->exposure >> 8;
2546 expotimes += (luma_mean - delta) >> 4;
2547 if (expotimes < 0)
2548 expotimes = 0;
2549 sd->exposure = setexposure(gspca_dev,
2550 (unsigned int) (expotimes << 8));
2551 break;
Amauri Magagna46b4f2a2009-10-17 07:21:29 -03002552 case SENSOR_OM6802:
2553 expotimes = sd->exposure;
2554 expotimes += (luma_mean - delta) >> 2;
2555 if (expotimes < 0)
2556 expotimes = 0;
2557 sd->exposure = setexposure(gspca_dev,
2558 (unsigned int) expotimes);
2559 setredblue(gspca_dev);
2560 break;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002561 default:
2562/* case SENSOR_MO4000: */
2563/* case SENSOR_MI0360: */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03002564/* case SENSOR_MT9V111: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002565 expotimes = sd->exposure;
2566 expotimes += (luma_mean - delta) >> 6;
2567 if (expotimes < 0)
2568 expotimes = 0;
2569 sd->exposure = setexposure(gspca_dev,
2570 (unsigned int) expotimes);
Jean-Francois Moine403123d2008-11-26 04:46:15 -03002571 setredblue(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002572 break;
2573 }
2574 }
2575}
2576
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002577/* scan the URB packets */
2578/* This function is run at interrupt level. */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002579static void sd_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -03002580 u8 *data, /* isoc packet */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002581 int len) /* iso packet length */
2582{
2583 struct sd *sd = (struct sd *) gspca_dev;
2584 int sof, avg_lum;
2585
2586 sof = len - 64;
2587 if (sof >= 0 && data[sof] == 0xff && data[sof + 1] == 0xd9) {
2588
2589 /* end of frame */
2590 gspca_frame_add(gspca_dev, LAST_PACKET,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03002591 data, sof + 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002592 if (sd->ag_cnt < 0)
2593 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002594/* w1 w2 w3 */
2595/* w4 w5 w6 */
2596/* w7 w8 */
2597/* w4 */
2598 avg_lum = ((data[sof + 29] << 8) | data[sof + 30]) >> 6;
2599/* w6 */
2600 avg_lum += ((data[sof + 33] << 8) | data[sof + 34]) >> 6;
2601/* w2 */
2602 avg_lum += ((data[sof + 25] << 8) | data[sof + 26]) >> 6;
2603/* w8 */
2604 avg_lum += ((data[sof + 37] << 8) | data[sof + 38]) >> 6;
2605/* w5 */
2606 avg_lum += ((data[sof + 31] << 8) | data[sof + 32]) >> 4;
2607 avg_lum >>= 4;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002608 atomic_set(&sd->avg_lum, avg_lum);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002609 return;
2610 }
2611 if (gspca_dev->last_packet_type == LAST_PACKET) {
2612
2613 /* put the JPEG 422 header */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03002614 gspca_frame_add(gspca_dev, FIRST_PACKET,
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03002615 sd->jpeg_hdr, JPEG_HDR_SZ);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002616 }
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03002617 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002618}
2619
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002620static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
2621{
2622 struct sd *sd = (struct sd *) gspca_dev;
2623
2624 sd->brightness = val;
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03002625 if (gspca_dev->streaming)
2626 setbrightness(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002627 return 0;
2628}
2629
2630static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
2631{
2632 struct sd *sd = (struct sd *) gspca_dev;
2633
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002634 *val = sd->brightness;
2635 return 0;
2636}
2637
2638static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
2639{
2640 struct sd *sd = (struct sd *) gspca_dev;
2641
2642 sd->contrast = val;
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03002643 if (gspca_dev->streaming)
2644 setcontrast(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002645 return 0;
2646}
2647
2648static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
2649{
2650 struct sd *sd = (struct sd *) gspca_dev;
2651
2652 *val = sd->contrast;
2653 return 0;
2654}
2655
2656static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
2657{
2658 struct sd *sd = (struct sd *) gspca_dev;
2659
2660 sd->colors = val;
2661 if (gspca_dev->streaming)
2662 setcolors(gspca_dev);
2663 return 0;
2664}
2665
2666static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
2667{
2668 struct sd *sd = (struct sd *) gspca_dev;
2669
2670 *val = sd->colors;
2671 return 0;
2672}
2673
Jean-Francois Moine403123d2008-11-26 04:46:15 -03002674static int sd_setblue_balance(struct gspca_dev *gspca_dev, __s32 val)
2675{
2676 struct sd *sd = (struct sd *) gspca_dev;
2677
2678 sd->blue = val;
2679 if (gspca_dev->streaming)
2680 setredblue(gspca_dev);
2681 return 0;
2682}
2683
2684static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val)
2685{
2686 struct sd *sd = (struct sd *) gspca_dev;
2687
2688 *val = sd->blue;
2689 return 0;
2690}
2691
2692static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val)
2693{
2694 struct sd *sd = (struct sd *) gspca_dev;
2695
2696 sd->red = val;
2697 if (gspca_dev->streaming)
2698 setredblue(gspca_dev);
2699 return 0;
2700}
2701
2702static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val)
2703{
2704 struct sd *sd = (struct sd *) gspca_dev;
2705
2706 *val = sd->red;
2707 return 0;
2708}
2709
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03002710static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val)
2711{
2712 struct sd *sd = (struct sd *) gspca_dev;
2713
2714 sd->gamma = val;
2715 if (gspca_dev->streaming)
2716 setgamma(gspca_dev);
2717 return 0;
2718}
2719
2720static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val)
2721{
2722 struct sd *sd = (struct sd *) gspca_dev;
2723
2724 *val = sd->gamma;
2725 return 0;
2726}
2727
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002728static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
2729{
2730 struct sd *sd = (struct sd *) gspca_dev;
2731
2732 sd->autogain = val;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002733 if (gspca_dev->streaming)
2734 setautogain(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002735 return 0;
2736}
2737
2738static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
2739{
2740 struct sd *sd = (struct sd *) gspca_dev;
2741
2742 *val = sd->autogain;
2743 return 0;
2744}
2745
Jean-Francois Moine878b35a2009-12-30 04:53:07 -03002746static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
2747{
2748 struct sd *sd = (struct sd *) gspca_dev;
2749
2750 sd->sharpness = val;
2751 if (gspca_dev->streaming)
2752 setsharpness(sd);
2753 return 0;
2754}
2755
2756static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
2757{
2758 struct sd *sd = (struct sd *) gspca_dev;
2759
2760 *val = sd->sharpness;
2761 return 0;
2762}
2763
Jean-Francois Moine6c862742008-09-08 04:57:26 -03002764static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
2765{
2766 struct sd *sd = (struct sd *) gspca_dev;
2767
2768 sd->vflip = val;
Jean-Francois Moine79a90982008-10-05 04:21:24 -03002769 if (gspca_dev->streaming)
2770 setvflip(sd);
Jean-Francois Moine6c862742008-09-08 04:57:26 -03002771 return 0;
2772}
2773
2774static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
2775{
2776 struct sd *sd = (struct sd *) gspca_dev;
2777
2778 *val = sd->vflip;
2779 return 0;
2780}
2781
Jean-Francois Moine0cae8962008-10-17 07:48:24 -03002782static int sd_setinfrared(struct gspca_dev *gspca_dev, __s32 val)
2783{
2784 struct sd *sd = (struct sd *) gspca_dev;
2785
2786 sd->infrared = val;
2787 if (gspca_dev->streaming)
2788 setinfrared(sd);
2789 return 0;
2790}
2791
2792static int sd_getinfrared(struct gspca_dev *gspca_dev, __s32 *val)
2793{
2794 struct sd *sd = (struct sd *) gspca_dev;
2795
2796 *val = sd->infrared;
2797 return 0;
2798}
2799
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002800static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
2801{
2802 struct sd *sd = (struct sd *) gspca_dev;
2803
2804 sd->freq = val;
2805 if (gspca_dev->streaming)
2806 setfreq(gspca_dev);
2807 return 0;
2808}
2809
2810static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
2811{
2812 struct sd *sd = (struct sd *) gspca_dev;
2813
2814 *val = sd->freq;
2815 return 0;
2816}
2817
Jean-Francois Moine77ac0ba2009-03-02 06:40:52 -03002818static int sd_set_jcomp(struct gspca_dev *gspca_dev,
2819 struct v4l2_jpegcompression *jcomp)
2820{
2821 struct sd *sd = (struct sd *) gspca_dev;
2822
2823 if (jcomp->quality < QUALITY_MIN)
2824 sd->quality = QUALITY_MIN;
2825 else if (jcomp->quality > QUALITY_MAX)
2826 sd->quality = QUALITY_MAX;
2827 else
2828 sd->quality = jcomp->quality;
2829 if (gspca_dev->streaming)
2830 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
2831 return 0;
2832}
2833
2834static int sd_get_jcomp(struct gspca_dev *gspca_dev,
2835 struct v4l2_jpegcompression *jcomp)
2836{
2837 struct sd *sd = (struct sd *) gspca_dev;
2838
2839 memset(jcomp, 0, sizeof *jcomp);
2840 jcomp->quality = sd->quality;
2841 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
2842 | V4L2_JPEG_MARKER_DQT;
2843 return 0;
2844}
2845
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002846static int sd_querymenu(struct gspca_dev *gspca_dev,
2847 struct v4l2_querymenu *menu)
2848{
2849 switch (menu->id) {
2850 case V4L2_CID_POWER_LINE_FREQUENCY:
2851 switch (menu->index) {
2852 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
2853 strcpy((char *) menu->name, "NoFliker");
2854 return 0;
2855 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
2856 strcpy((char *) menu->name, "50 Hz");
2857 return 0;
2858 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
2859 strcpy((char *) menu->name, "60 Hz");
2860 return 0;
2861 }
2862 break;
2863 }
2864 return -EINVAL;
2865}
2866
Hans de Goede9712a8b2010-01-31 12:54:29 -03002867#ifdef CONFIG_INPUT
2868static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
2869 u8 *data, /* interrupt packet data */
2870 int len) /* interrupt packet length */
2871{
2872 int ret = -EINVAL;
2873
2874 if (len == 1 && data[0] == 1) {
2875 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
2876 input_sync(gspca_dev->input_dev);
2877 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
2878 input_sync(gspca_dev->input_dev);
2879 ret = 0;
2880 }
2881
2882 return ret;
2883}
2884#endif
2885
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002886/* sub-driver description */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002887static const struct sd_desc sd_desc = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002888 .name = MODULE_NAME,
2889 .ctrls = sd_ctrls,
2890 .nctrls = ARRAY_SIZE(sd_ctrls),
2891 .config = sd_config,
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03002892 .init = sd_init,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002893 .start = sd_start,
2894 .stopN = sd_stopN,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002895 .pkt_scan = sd_pkt_scan,
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002896 .dq_callback = do_autogain,
Jean-Francois Moine77ac0ba2009-03-02 06:40:52 -03002897 .get_jcomp = sd_get_jcomp,
2898 .set_jcomp = sd_set_jcomp,
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002899 .querymenu = sd_querymenu,
Hans de Goede9712a8b2010-01-31 12:54:29 -03002900#ifdef CONFIG_INPUT
2901 .int_pkt_scan = sd_int_pkt_scan,
2902#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002903};
2904
2905/* -- module initialisation -- */
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002906#define BS(bridge, sensor) \
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002907 .driver_info = (BRIDGE_ ## bridge << 16) \
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002908 | SENSOR_ ## sensor
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002909static const __devinitdata struct usb_device_id device_table[] = {
Hans de Goede222a07f2008-09-03 17:12:20 -03002910#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002911 {USB_DEVICE(0x0458, 0x7025), BS(SN9C120, MI0360)},
2912 {USB_DEVICE(0x0458, 0x702e), BS(SN9C120, OV7660)},
Jean-Francois Moinea08d81a2008-11-22 04:53:31 -03002913#endif
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002914 {USB_DEVICE(0x045e, 0x00f5), BS(SN9C105, OV7660)},
2915 {USB_DEVICE(0x045e, 0x00f7), BS(SN9C105, OV7660)},
2916 {USB_DEVICE(0x0471, 0x0327), BS(SN9C105, MI0360)},
2917 {USB_DEVICE(0x0471, 0x0328), BS(SN9C105, MI0360)},
2918 {USB_DEVICE(0x0471, 0x0330), BS(SN9C105, MI0360)},
2919 {USB_DEVICE(0x06f8, 0x3004), BS(SN9C105, OV7660)},
2920 {USB_DEVICE(0x06f8, 0x3008), BS(SN9C105, OV7660)},
2921/* {USB_DEVICE(0x0c45, 0x603a), BS(SN9C102P, OV7648)}, */
2922 {USB_DEVICE(0x0c45, 0x6040), BS(SN9C102P, HV7131R)},
2923/* {USB_DEVICE(0x0c45, 0x607a), BS(SN9C102P, OV7648)}, */
2924/* {USB_DEVICE(0x0c45, 0x607b), BS(SN9C102P, OV7660)}, */
2925 {USB_DEVICE(0x0c45, 0x607c), BS(SN9C102P, HV7131R)},
2926/* {USB_DEVICE(0x0c45, 0x607e), BS(SN9C102P, OV7630)}, */
2927 {USB_DEVICE(0x0c45, 0x60c0), BS(SN9C105, MI0360)},
2928/* {USB_DEVICE(0x0c45, 0x60c2), BS(SN9C105, P1030xC)}, */
2929/* {USB_DEVICE(0x0c45, 0x60c8), BS(SN9C105, OM6802)}, */
2930/* {USB_DEVICE(0x0c45, 0x60cc), BS(SN9C105, HV7131GP)}, */
2931 {USB_DEVICE(0x0c45, 0x60ec), BS(SN9C105, MO4000)},
2932/* {USB_DEVICE(0x0c45, 0x60ef), BS(SN9C105, ICM105C)}, */
2933/* {USB_DEVICE(0x0c45, 0x60fa), BS(SN9C105, OV7648)}, */
2934 {USB_DEVICE(0x0c45, 0x60fb), BS(SN9C105, OV7660)},
Jean-Francois Moine3c41cb72008-09-10 02:57:09 -03002935#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002936 {USB_DEVICE(0x0c45, 0x60fc), BS(SN9C105, HV7131R)},
2937 {USB_DEVICE(0x0c45, 0x60fe), BS(SN9C105, OV7630)},
Jean-Francois Moine3c41cb72008-09-10 02:57:09 -03002938#endif
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002939 {USB_DEVICE(0x0c45, 0x6100), BS(SN9C120, MI0360)}, /*sn9c128*/
2940/* {USB_DEVICE(0x0c45, 0x6102), BS(SN9C120, P1030xC)}, */
2941/* {USB_DEVICE(0x0c45, 0x6108), BS(SN9C120, OM6802)}, */
2942 {USB_DEVICE(0x0c45, 0x610a), BS(SN9C120, OV7648)}, /*sn9c128*/
2943 {USB_DEVICE(0x0c45, 0x610b), BS(SN9C120, OV7660)}, /*sn9c128*/
2944 {USB_DEVICE(0x0c45, 0x610c), BS(SN9C120, HV7131R)}, /*sn9c128*/
2945 {USB_DEVICE(0x0c45, 0x610e), BS(SN9C120, OV7630)}, /*sn9c128*/
2946/* {USB_DEVICE(0x0c45, 0x610f), BS(SN9C120, S5K53BEB)}, */
2947/* {USB_DEVICE(0x0c45, 0x6122), BS(SN9C110, ICM105C)}, */
2948/* {USB_DEVICE(0x0c45, 0x6123), BS(SN9C110, SanyoCCD)}, */
2949 {USB_DEVICE(0x0c45, 0x6128), BS(SN9C120, OM6802)}, /*sn9c325?*/
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03002950/*bw600.inf:*/
Jean-Francois Moineb8c8a5b2009-11-23 06:46:35 -03002951 {USB_DEVICE(0x0c45, 0x612a), BS(SN9C120, OV7648)}, /*sn9c325?*/
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002952 {USB_DEVICE(0x0c45, 0x612c), BS(SN9C110, MO4000)},
2953 {USB_DEVICE(0x0c45, 0x612e), BS(SN9C110, OV7630)},
2954/* {USB_DEVICE(0x0c45, 0x612f), BS(SN9C110, ICM105C)}, */
Hans de Goede222a07f2008-09-03 17:12:20 -03002955#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002956 {USB_DEVICE(0x0c45, 0x6130), BS(SN9C120, MI0360)},
Hans de Goede222a07f2008-09-03 17:12:20 -03002957#endif
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002958/* {USB_DEVICE(0x0c45, 0x6132), BS(SN9C120, OV7670)}, */
2959 {USB_DEVICE(0x0c45, 0x6138), BS(SN9C120, MO4000)},
2960 {USB_DEVICE(0x0c45, 0x613a), BS(SN9C120, OV7648)},
Hans de Goede222a07f2008-09-03 17:12:20 -03002961#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002962 {USB_DEVICE(0x0c45, 0x613b), BS(SN9C120, OV7660)},
Jean-Francois Moine8d977702009-02-19 15:34:48 -03002963#endif
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002964 {USB_DEVICE(0x0c45, 0x613c), BS(SN9C120, HV7131R)},
2965 {USB_DEVICE(0x0c45, 0x613e), BS(SN9C120, OV7630)},
Jean-François Moinead98c0f2010-03-18 05:15:30 -03002966 {USB_DEVICE(0x0c45, 0x6142), BS(SN9C120, PO2030N)}, /*sn9c120b*/
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002967 {USB_DEVICE(0x0c45, 0x6143), BS(SN9C120, SP80708)}, /*sn9c120b*/
2968 {USB_DEVICE(0x0c45, 0x6148), BS(SN9C120, OM6802)}, /*sn9c120b*/
Jean-Francois Moine64677572009-12-20 12:31:28 -03002969 {USB_DEVICE(0x0c45, 0x614a), BS(SN9C120, ADCM1700)}, /*sn9c120b*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002970 {}
2971};
2972MODULE_DEVICE_TABLE(usb, device_table);
2973
2974/* -- device connect -- */
2975static int sd_probe(struct usb_interface *intf,
2976 const struct usb_device_id *id)
2977{
2978 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
2979 THIS_MODULE);
2980}
2981
2982static struct usb_driver sd_driver = {
2983 .name = MODULE_NAME,
2984 .id_table = device_table,
2985 .probe = sd_probe,
2986 .disconnect = gspca_disconnect,
Jean-Francois Moine6a709742008-09-03 16:48:10 -03002987#ifdef CONFIG_PM
2988 .suspend = gspca_suspend,
2989 .resume = gspca_resume,
2990#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002991};
2992
2993/* -- module insert / remove -- */
2994static int __init sd_mod_init(void)
2995{
Alexey Klimovf69e9522009-01-01 13:02:07 -03002996 int ret;
2997 ret = usb_register(&sd_driver);
2998 if (ret < 0)
Alexey Klimove6b14842009-01-01 13:04:58 -03002999 return ret;
Jean-Francois Moine10b0e962008-07-22 05:35:10 -03003000 info("registered");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003001 return 0;
3002}
3003static void __exit sd_mod_exit(void)
3004{
3005 usb_deregister(&sd_driver);
3006 info("deregistered");
3007}
3008
3009module_init(sd_mod_init);
3010module_exit(sd_mod_exit);