blob: 363c0fa39d9ed2efd73cad83636f98b7afbedfc9 [file] [log] [blame]
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001/*
2 * Sonix sn9c102p sn9c105 sn9c120 (jpeg) library
3 * Copyright (C) 2005 Michel Xhaard mxhaard@magic.fr
4 *
5 * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#define MODULE_NAME "sonixj"
23
24#include "gspca.h"
25#include "jpeg.h"
26
Jean-Francois Moine0cae8962008-10-17 07:48:24 -030027#define V4L2_CID_INFRARED (V4L2_CID_PRIVATE_BASE + 0)
28
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030029MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
30MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
31MODULE_LICENSE("GPL");
32
33/* specific webcam descriptor */
34struct sd {
35 struct gspca_dev gspca_dev; /* !! must be the first item */
36
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -030037 atomic_t avg_lum;
Jean-Francois Moine98819182009-01-19 07:37:33 -030038 u32 exposure;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030039
Jean-Francois Moine98819182009-01-19 07:37:33 -030040 u16 brightness;
41 u8 contrast;
42 u8 colors;
43 u8 autogain;
44 u8 blue;
45 u8 red;
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -030046 u8 gamma;
Jean-Francois Moine2797ba22009-02-05 15:12:24 -030047 u8 vflip; /* ov7630/ov7648 only */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -030048 u8 infrared; /* mt9v111 only */
Jean-Francois Moine71cb2762009-03-03 05:33:41 -030049 u8 quality; /* image quality */
50 u8 jpegqual; /* webcam quality */
51
52 u8 reg18;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030053
Jean-Francois Moine98819182009-01-19 07:37:33 -030054 s8 ag_cnt;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030055#define AG_CNT_START 13
56
Jean-Francois Moine98819182009-01-19 07:37:33 -030057 u8 bridge;
Hans de Goede3647fea2008-07-15 05:36:30 -030058#define BRIDGE_SN9C102P 0
59#define BRIDGE_SN9C105 1
60#define BRIDGE_SN9C110 2
61#define BRIDGE_SN9C120 3
62#define BRIDGE_SN9C325 4
Jean-Francois Moine98819182009-01-19 07:37:33 -030063 u8 sensor; /* Type of image sensor chip */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030064#define SENSOR_HV7131R 0
65#define SENSOR_MI0360 1
66#define SENSOR_MO4000 2
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -030067#define SENSOR_MT9V111 3
68#define SENSOR_OM6802 4
69#define SENSOR_OV7630 5
70#define SENSOR_OV7648 6
71#define SENSOR_OV7660 7
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -030072#define SENSOR_SP80708 8
Jean-Francois Moine98819182009-01-19 07:37:33 -030073 u8 i2c_base;
Jean-Francois Moine71cb2762009-03-03 05:33:41 -030074
75 u8 *jpeg_hdr;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030076};
77
78/* V4L2 controls supported by the driver */
79static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
80static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
81static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
82static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
83static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
84static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine403123d2008-11-26 04:46:15 -030085static int sd_setblue_balance(struct gspca_dev *gspca_dev, __s32 val);
86static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val);
87static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val);
88static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -030089static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val);
90static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030091static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
92static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine6c862742008-09-08 04:57:26 -030093static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
94static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine0cae8962008-10-17 07:48:24 -030095static int sd_setinfrared(struct gspca_dev *gspca_dev, __s32 val);
96static int sd_getinfrared(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030097
98static struct ctrl sd_ctrls[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030099 {
100 {
101 .id = V4L2_CID_BRIGHTNESS,
102 .type = V4L2_CTRL_TYPE_INTEGER,
103 .name = "Brightness",
104 .minimum = 0,
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300105#define BRIGHTNESS_MAX 0xffff
106 .maximum = BRIGHTNESS_MAX,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300107 .step = 1,
Jean-Francois Moineb1b056a2008-11-25 04:47:09 -0300108#define BRIGHTNESS_DEF 0x8000
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300109 .default_value = BRIGHTNESS_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300110 },
111 .set = sd_setbrightness,
112 .get = sd_getbrightness,
113 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300114 {
115 {
116 .id = V4L2_CID_CONTRAST,
117 .type = V4L2_CTRL_TYPE_INTEGER,
118 .name = "Contrast",
119 .minimum = 0,
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300120#define CONTRAST_MAX 127
121 .maximum = CONTRAST_MAX,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300122 .step = 1,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300123#define CONTRAST_DEF 63
124 .default_value = CONTRAST_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300125 },
126 .set = sd_setcontrast,
127 .get = sd_getcontrast,
128 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300129 {
130 {
131 .id = V4L2_CID_SATURATION,
132 .type = V4L2_CTRL_TYPE_INTEGER,
133 .name = "Color",
134 .minimum = 0,
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300135 .maximum = 40,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300136 .step = 1,
Jean-Francois Moine9c5f70f2008-09-03 16:48:04 -0300137#define COLOR_DEF 32
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300138 .default_value = COLOR_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300139 },
140 .set = sd_setcolors,
141 .get = sd_getcolors,
142 },
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300143 {
144 {
145 .id = V4L2_CID_BLUE_BALANCE,
146 .type = V4L2_CTRL_TYPE_INTEGER,
147 .name = "Blue Balance",
148 .minimum = 24,
149 .maximum = 40,
150 .step = 1,
151#define BLUE_BALANCE_DEF 32
152 .default_value = BLUE_BALANCE_DEF,
153 },
154 .set = sd_setblue_balance,
155 .get = sd_getblue_balance,
156 },
157 {
158 {
159 .id = V4L2_CID_RED_BALANCE,
160 .type = V4L2_CTRL_TYPE_INTEGER,
161 .name = "Red Balance",
162 .minimum = 24,
163 .maximum = 40,
164 .step = 1,
165#define RED_BALANCE_DEF 32
166 .default_value = RED_BALANCE_DEF,
167 },
168 .set = sd_setred_balance,
169 .get = sd_getred_balance,
170 },
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -0300171 {
172 {
173 .id = V4L2_CID_GAMMA,
174 .type = V4L2_CTRL_TYPE_INTEGER,
175 .name = "Gamma",
176 .minimum = 0,
177 .maximum = 40,
178 .step = 1,
179#define GAMMA_DEF 20
180 .default_value = GAMMA_DEF,
181 },
182 .set = sd_setgamma,
183 .get = sd_getgamma,
184 },
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300185#define AUTOGAIN_IDX 5
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300186 {
187 {
188 .id = V4L2_CID_AUTOGAIN,
189 .type = V4L2_CTRL_TYPE_BOOLEAN,
190 .name = "Auto Gain",
191 .minimum = 0,
192 .maximum = 1,
193 .step = 1,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300194#define AUTOGAIN_DEF 1
195 .default_value = AUTOGAIN_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300196 },
197 .set = sd_setautogain,
198 .get = sd_getautogain,
199 },
Jean-Francois Moine2797ba22009-02-05 15:12:24 -0300200/* ov7630/ov7648 only */
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300201#define VFLIP_IDX 6
Jean-Francois Moine6c862742008-09-08 04:57:26 -0300202 {
203 {
204 .id = V4L2_CID_VFLIP,
205 .type = V4L2_CTRL_TYPE_BOOLEAN,
206 .name = "Vflip",
207 .minimum = 0,
208 .maximum = 1,
209 .step = 1,
Jean-Francois Moine2797ba22009-02-05 15:12:24 -0300210#define VFLIP_DEF 0 /* vflip def = 1 for ov7630 */
Jean-Francois Moine6c862742008-09-08 04:57:26 -0300211 .default_value = VFLIP_DEF,
212 },
213 .set = sd_setvflip,
214 .get = sd_getvflip,
215 },
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300216/* mt9v111 only */
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300217#define INFRARED_IDX 7
Jean-Francois Moine0cae8962008-10-17 07:48:24 -0300218 {
219 {
220 .id = V4L2_CID_INFRARED,
221 .type = V4L2_CTRL_TYPE_BOOLEAN,
222 .name = "Infrared",
223 .minimum = 0,
224 .maximum = 1,
225 .step = 1,
226#define INFRARED_DEF 0
227 .default_value = INFRARED_DEF,
228 },
229 .set = sd_setinfrared,
230 .get = sd_getinfrared,
231 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300232};
233
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300234/* table of the disabled controls */
235static __u32 ctrl_dis[] = {
236 (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
237 /* SENSOR_HV7131R 0 */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300238 (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300239 /* SENSOR_MI0360 1 */
240 (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
241 /* SENSOR_MO4000 2 */
Jean-Francois Moinec33c02e2009-02-05 15:04:33 -0300242 (1 << VFLIP_IDX),
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300243 /* SENSOR_MT9V111 3 */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300244 (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300245 /* SENSOR_OM6802 4 */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300246 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX),
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300247 /* SENSOR_OV7630 5 */
Jean-Francois Moine2797ba22009-02-05 15:12:24 -0300248 (1 << INFRARED_IDX),
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300249 /* SENSOR_OV7648 6 */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300250 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300251 /* SENSOR_OV7660 7 */
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -0300252 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
253 /* SENSOR_SP80708 8 */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300254};
255
Jean-Francois Moinecc611b82008-12-29 07:49:41 -0300256static const struct v4l2_pix_format vga_mode[] = {
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300257 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
258 .bytesperline = 160,
Jean-Francois Moine5d052942008-09-03 16:48:09 -0300259 .sizeimage = 160 * 120 * 4 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300260 .colorspace = V4L2_COLORSPACE_JPEG,
261 .priv = 2},
262 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
263 .bytesperline = 320,
264 .sizeimage = 320 * 240 * 3 / 8 + 590,
265 .colorspace = V4L2_COLORSPACE_JPEG,
266 .priv = 1},
267 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
268 .bytesperline = 640,
269 .sizeimage = 640 * 480 * 3 / 8 + 590,
270 .colorspace = V4L2_COLORSPACE_JPEG,
271 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300272};
273
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300274/*Data from sn9c102p+hv7131r */
275static const u8 sn_hv7131[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300276/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
277 0x00, 0x03, 0x64, 0x00, 0x1a, 0x20, 0x20, 0x20,
278/* reg8 reg9 rega regb regc regd rege regf */
279 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10,
280/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
281 0x03, 0x00, 0x00, 0x01, 0x03, 0x28, 0x1e, 0x41,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300282/* reg18 reg19 reg1a reg1b */
283 0x0a, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300284};
285
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300286static const u8 sn_mi0360[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300287/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
288 0x00, 0x61, 0x44, 0x00, 0x1a, 0x20, 0x20, 0x20,
289/* reg8 reg9 rega regb regc regd rege regf */
290 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10,
291/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
292 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x61,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300293/* reg18 reg19 reg1a reg1b */
294 0x06, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300295};
296
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300297static const u8 sn_mo4000[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300298/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300299 0x00, 0x23, 0x60, 0x00, 0x1a, 0x00, 0x20, 0x18,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300300/* reg8 reg9 rega regb regc regd rege regf */
301 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
302/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
303 0x03, 0x00, 0x0b, 0x0f, 0x14, 0x28, 0x1e, 0x40,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300304/* reg18 reg19 reg1a reg1b */
305 0x08, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300306};
307
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300308static const u8 sn_mt9v111[0x1c] = {
309/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
310 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
311/* reg8 reg9 rega regb regc regd rege regf */
312 0x81, 0x5c, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
313/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
314 0x03, 0x00, 0x00, 0x02, 0x1c, 0x28, 0x1e, 0x40,
315/* reg18 reg19 reg1a reg1b */
316 0x06, 0x00, 0x00, 0x00
317};
318
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300319static const u8 sn_om6802[0x1c] = {
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300320/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
321 0x00, 0x23, 0x72, 0x00, 0x1a, 0x34, 0x27, 0x20,
322/* reg8 reg9 rega regb regc regd rege regf */
323 0x80, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
324/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
325 0x03, 0x00, 0x51, 0x01, 0x00, 0x28, 0x1e, 0x40,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300326/* reg18 reg19 reg1a reg1b */
327 0x05, 0x00, 0x00, 0x00
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300328};
329
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300330static const u8 sn_ov7630[0x1c] = {
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300331/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
332 0x00, 0x21, 0x40, 0x00, 0x1a, 0x20, 0x1f, 0x20,
333/* reg8 reg9 rega regb regc regd rege regf */
334 0xa1, 0x21, 0x76, 0x21, 0x00, 0x00, 0x00, 0x10,
335/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
336 0x03, 0x00, 0x04, 0x01, 0x0a, 0x28, 0x1e, 0xc2,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300337/* reg18 reg19 reg1a reg1b */
338 0x0b, 0x00, 0x00, 0x00
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300339};
340
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300341static const u8 sn_ov7648[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300342/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Jean-Francois Moine62703302008-11-11 08:42:56 -0300343 0x00, 0x63, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300344/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine62703302008-11-11 08:42:56 -0300345 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300346/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
Jean-Francois Moine62703302008-11-11 08:42:56 -0300347 0x03, 0x00, 0x00, 0x01, 0x00, 0x28, 0x1e, 0x00,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300348/* reg18 reg19 reg1a reg1b */
349 0x0b, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300350};
351
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300352static const u8 sn_ov7660[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300353/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
354 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
355/* reg8 reg9 rega regb regc regd rege regf */
356 0x81, 0x21, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10,
357/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
358 0x03, 0x00, 0x01, 0x01, 0x08, 0x28, 0x1e, 0x20,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300359/* reg18 reg19 reg1a reg1b */
360 0x07, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300361};
362
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -0300363static const u8 sn_sp80708[0x1c] = {
364/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
365 0x00, 0x63, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
366/* reg8 reg9 rega regb regc regd rege regf */
367 0x81, 0x18, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00,
368/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
369 0x03, 0x00, 0x00, 0x03, 0x04, 0x28, 0x1e, 0x00,
370/* reg18 reg19 reg1a reg1b */
371 0x07, 0x00, 0x00, 0x00
372};
373
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300374/* sequence specific to the sensors - !! index = SENSOR_xxx */
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300375static const u8 *sn_tb[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300376 sn_hv7131,
377 sn_mi0360,
378 sn_mo4000,
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300379 sn_mt9v111,
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300380 sn_om6802,
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300381 sn_ov7630,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300382 sn_ov7648,
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -0300383 sn_ov7660,
384 sn_sp80708
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300385};
386
Jean-Francois Moineb083b922009-02-01 14:20:07 -0300387/* default gamma table */
Jean-Francois Moine98819182009-01-19 07:37:33 -0300388static const u8 gamma_def[17] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300389 0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99,
390 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
391};
Jean-Francois Moineb083b922009-02-01 14:20:07 -0300392/* gamma for sensors HV7131R and MT9V111 */
393static const u8 gamma_spec_1[17] = {
394 0x08, 0x3a, 0x52, 0x65, 0x75, 0x83, 0x91, 0x9d,
395 0xa9, 0xb4, 0xbe, 0xc8, 0xd2, 0xdb, 0xe4, 0xed, 0xf5
396};
397/* gamma for sensor SP80708 */
398static const u8 gamma_spec_2[17] = {
399 0x0a, 0x2d, 0x4e, 0x68, 0x7d, 0x8f, 0x9f, 0xab,
400 0xb7, 0xc2, 0xcc, 0xd3, 0xd8, 0xde, 0xe2, 0xe5, 0xe6
401};
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -0300402
Jean-Francois Moine803f9cc2008-10-04 14:17:02 -0300403/* color matrix and offsets */
Jean-Francois Moine98819182009-01-19 07:37:33 -0300404static const u8 reg84[] = {
Jean-Francois Moine803f9cc2008-10-04 14:17:02 -0300405 0x14, 0x00, 0x27, 0x00, 0x07, 0x00, /* YR YG YB gains */
406 0xe8, 0x0f, 0xda, 0x0f, 0x40, 0x00, /* UR UG UB */
407 0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f, /* VR VG VB */
408 0x00, 0x00, 0x00 /* YUV offsets */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300409};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300410static const u8 hv7131r_sensor_init[][8] = {
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300411 {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
412 {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10},
413 {0xd1, 0x11, 0x40, 0xff, 0x7f, 0x7f, 0x7f, 0x10},
414/* {0x91, 0x11, 0x44, 0x00, 0x00, 0x00, 0x00, 0x10}, */
415 {0xd1, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
416 {0xd1, 0x11, 0x14, 0x01, 0xe2, 0x02, 0x82, 0x10},
417/* {0x91, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10}, */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300418
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300419 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
420 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
421 {0xc1, 0x11, 0x25, 0x00, 0x61, 0xa8, 0x00, 0x10},
422 {0xa1, 0x11, 0x30, 0x22, 0x00, 0x00, 0x00, 0x10},
423 {0xc1, 0x11, 0x31, 0x20, 0x2e, 0x20, 0x00, 0x10},
424 {0xc1, 0x11, 0x25, 0x00, 0xc3, 0x50, 0x00, 0x10},
425 {0xa1, 0x11, 0x30, 0x07, 0x00, 0x00, 0x00, 0x10}, /* gain14 */
426 {0xc1, 0x11, 0x31, 0x10, 0x10, 0x10, 0x00, 0x10}, /* r g b 101a10 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300427
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300428 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
429 {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
430 {0xa1, 0x11, 0x21, 0xD0, 0x00, 0x00, 0x00, 0x10},
431 {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
432 {0xa1, 0x11, 0x23, 0x09, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300433
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300434 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
435 {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
436 {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
437 {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
438 {0xa1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300439 {}
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300440};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300441static const u8 mi0360_sensor_init[][8] = {
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300442 {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
Jean-Francois Moine98819182009-01-19 07:37:33 -0300443 {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300444 {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300445 {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
446 {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
447 {0xd1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x53, 0x10},
448 {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
449 {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
450 {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
451 {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
452 {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
453 {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
454 {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
455 {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
456 {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
457 {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
458 {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
459 {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
460 {0xd1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
461 {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
462 {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
463 {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
Jean-Francois Moine98819182009-01-19 07:37:33 -0300464 {0xd1, 0x5d, 0x2f, 0xf7, 0xB0, 0x00, 0x04, 0x10},
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300465 {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
466 {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
467 {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
468 {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
469 {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
470 {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
471 {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
472 {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
473 {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
474 {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300475
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300476 {0xb1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
477 {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
478 {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
479 {0xd1, 0x5d, 0x2b, 0x00, 0xa0, 0x00, 0xb0, 0x10},
480 {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0xa0, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300481
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300482 {0xb1, 0x5d, 0x0a, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor clck ?2 */
483 {0xb1, 0x5d, 0x06, 0x00, 0x30, 0x00, 0x00, 0x10},
484 {0xb1, 0x5d, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10},
485 {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300486
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300487 {0xd1, 0x5d, 0x2b, 0x00, 0xb9, 0x00, 0xe3, 0x10},
488 {0xd1, 0x5d, 0x2d, 0x00, 0x5f, 0x00, 0xb9, 0x10}, /* 42 */
489/* {0xb1, 0x5d, 0x35, 0x00, 0x67, 0x00, 0x00, 0x10}, * gain orig */
490/* {0xb1, 0x5d, 0x35, 0x00, 0x20, 0x00, 0x00, 0x10}, * gain */
491 {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
492 {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300493 {}
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300494};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300495static const u8 mo4000_sensor_init[][8] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300496 {0xa1, 0x21, 0x01, 0x02, 0x00, 0x00, 0x00, 0x10},
497 {0xa1, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10},
498 {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
499 {0xa1, 0x21, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
500 {0xa1, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
501 {0xa1, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x10},
502 {0xa1, 0x21, 0x06, 0x80, 0x00, 0x00, 0x00, 0x10},
503 {0xa1, 0x21, 0x06, 0x81, 0x00, 0x00, 0x00, 0x10},
504 {0xa1, 0x21, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
505 {0xa1, 0x21, 0x11, 0x00, 0x00, 0x00, 0x00, 0x10},
506 {0xa1, 0x21, 0x11, 0x20, 0x00, 0x00, 0x00, 0x10},
507 {0xa1, 0x21, 0x11, 0x30, 0x00, 0x00, 0x00, 0x10},
508 {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
509 {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
510 {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
511 {0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
512 {0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10},
513 {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10},
514 {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
515 {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300516 {}
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300517};
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300518static const u8 mt9v111_sensor_init[][8] = {
519 {0xb1, 0x5c, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10}, /* reset? */
520 /* delay 20 ms */
521 {0xb1, 0x5c, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
522 {0xb1, 0x5c, 0x01, 0x00, 0x01, 0x00, 0x00, 0x10}, /* IFP select */
523 {0xb1, 0x5c, 0x08, 0x04, 0x80, 0x00, 0x00, 0x10}, /* output fmt ctrl */
524 {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10}, /* op mode ctrl */
Jean-Francois Moine2687a2f2009-02-01 14:48:55 -0300525 {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
526 {0xb1, 0x5c, 0x03, 0x01, 0xe1, 0x00, 0x00, 0x10},
527 {0xb1, 0x5c, 0x04, 0x02, 0x81, 0x00, 0x00, 0x10},
528 {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300529 {0xb1, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10}, /* sensor select */
Jean-Francois Moine2687a2f2009-02-01 14:48:55 -0300530 {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
531 {0xb1, 0x5c, 0x03, 0x01, 0xe6, 0x00, 0x00, 0x10},
532 {0xb1, 0x5c, 0x04, 0x02, 0x86, 0x00, 0x00, 0x10},
533 {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
534 {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300535 {0xb1, 0x5c, 0x08, 0x00, 0x08, 0x00, 0x00, 0x10}, /* row start */
Jean-Francois Moine2687a2f2009-02-01 14:48:55 -0300536 {0xb1, 0x5c, 0x0e, 0x00, 0x08, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300537 {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10}, /* col start */
538 {0xb1, 0x5c, 0x03, 0x01, 0xe7, 0x00, 0x00, 0x10}, /* window height */
539 {0xb1, 0x5c, 0x04, 0x02, 0x87, 0x00, 0x00, 0x10}, /* window width */
540 {0xb1, 0x5c, 0x07, 0x30, 0x02, 0x00, 0x00, 0x10}, /* output ctrl */
541 {0xb1, 0x5c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10}, /* shutter delay */
542 {0xb1, 0x5c, 0x12, 0x00, 0xb0, 0x00, 0x00, 0x10}, /* zoom col start */
543 {0xb1, 0x5c, 0x13, 0x00, 0x7c, 0x00, 0x00, 0x10}, /* zoom row start */
544 {0xb1, 0x5c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* digital zoom */
545 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10}, /* read mode */
546 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
547 /*******/
548 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
549 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine2687a2f2009-02-01 14:48:55 -0300550 {0xb1, 0x5c, 0x09, 0x01, 0x2c, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300551 {0xd1, 0x5c, 0x2b, 0x00, 0x33, 0x00, 0xa0, 0x10}, /* green1 gain */
552 {0xd1, 0x5c, 0x2d, 0x00, 0xa0, 0x00, 0x33, 0x10}, /* red gain */
553 /*******/
554 {0xb1, 0x5c, 0x06, 0x00, 0x1e, 0x00, 0x00, 0x10}, /* vert blanking */
555 {0xb1, 0x5c, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10}, /* horiz blanking */
556 {0xd1, 0x5c, 0x2c, 0x00, 0xad, 0x00, 0xad, 0x10}, /* blue gain */
557 {0xb1, 0x5c, 0x35, 0x01, 0xc0, 0x00, 0x00, 0x10}, /* global gain */
558 {}
559};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300560static const u8 om6802_sensor_init[][8] = {
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300561 {0xa0, 0x34, 0x90, 0x05, 0x00, 0x00, 0x00, 0x10},
562 {0xa0, 0x34, 0x49, 0x85, 0x00, 0x00, 0x00, 0x10},
563 {0xa0, 0x34, 0x5a, 0xc0, 0x00, 0x00, 0x00, 0x10},
564 {0xa0, 0x34, 0xdd, 0x18, 0x00, 0x00, 0x00, 0x10},
565/* {0xa0, 0x34, 0xfb, 0x11, 0x00, 0x00, 0x00, 0x10}, */
566 {0xa0, 0x34, 0xf0, 0x04, 0x00, 0x00, 0x00, 0x10},
567 /* white balance & auto-exposure */
568/* {0xa0, 0x34, 0xf1, 0x02, 0x00, 0x00, 0x00, 0x10},
569 * set color mode */
570/* {0xa0, 0x34, 0xfe, 0x5b, 0x00, 0x00, 0x00, 0x10},
571 * max AGC value in AE */
572/* {0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10},
573 * preset AGC */
574/* {0xa0, 0x34, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x10},
575 * preset brightness */
576/* {0xa0, 0x34, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x10},
577 * preset contrast */
578/* {0xa0, 0x34, 0xe8, 0x31, 0x00, 0x00, 0x00, 0x10},
579 * preset gamma */
580 {0xa0, 0x34, 0xe9, 0x0f, 0x00, 0x00, 0x00, 0x10},
581 /* luminance mode (0x4f = AE) */
582 {0xa0, 0x34, 0xe4, 0xff, 0x00, 0x00, 0x00, 0x10},
583 /* preset shutter */
584/* {0xa0, 0x34, 0xef, 0x00, 0x00, 0x00, 0x00, 0x10},
585 * auto frame rate */
586/* {0xa0, 0x34, 0xfb, 0xee, 0x00, 0x00, 0x00, 0x10}, */
587
588/* {0xa0, 0x34, 0x71, 0x84, 0x00, 0x00, 0x00, 0x10}, */
589/* {0xa0, 0x34, 0x72, 0x05, 0x00, 0x00, 0x00, 0x10}, */
590/* {0xa0, 0x34, 0x68, 0x80, 0x00, 0x00, 0x00, 0x10}, */
591/* {0xa0, 0x34, 0x69, 0x01, 0x00, 0x00, 0x00, 0x10}, */
592 {}
593};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300594static const u8 ov7630_sensor_init[][8] = {
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300595 {0xa1, 0x21, 0x76, 0x01, 0x00, 0x00, 0x00, 0x10},
596 {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
597/* win: delay 20ms */
598 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
599 {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
600/* win: delay 20ms */
601 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300602/* win: i2c_r from 00 to 80 */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300603 {0xd1, 0x21, 0x03, 0x80, 0x10, 0x20, 0x80, 0x10},
604 {0xb1, 0x21, 0x0c, 0x20, 0x20, 0x00, 0x00, 0x10},
605 {0xd1, 0x21, 0x11, 0x00, 0x48, 0xc0, 0x00, 0x10},
606 {0xb1, 0x21, 0x15, 0x80, 0x03, 0x00, 0x00, 0x10},
607 {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
608 {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
609 {0xd1, 0x21, 0x1f, 0x00, 0x80, 0x80, 0x80, 0x10},
610 {0xd1, 0x21, 0x23, 0xde, 0x10, 0x8a, 0xa0, 0x10},
611 {0xc1, 0x21, 0x27, 0xca, 0xa2, 0x74, 0x00, 0x10},
612 {0xd1, 0x21, 0x2a, 0x88, 0x00, 0x88, 0x01, 0x10},
613 {0xc1, 0x21, 0x2e, 0x80, 0x00, 0x18, 0x00, 0x10},
614 {0xa1, 0x21, 0x21, 0x08, 0x00, 0x00, 0x00, 0x10},
615 {0xa1, 0x21, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
616 {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
617 {0xb1, 0x21, 0x32, 0xc2, 0x08, 0x00, 0x00, 0x10},
618 {0xb1, 0x21, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x10},
619 {0xd1, 0x21, 0x60, 0x05, 0x40, 0x12, 0x57, 0x10},
620 {0xa1, 0x21, 0x64, 0x73, 0x00, 0x00, 0x00, 0x10},
621 {0xd1, 0x21, 0x65, 0x00, 0x55, 0x01, 0xac, 0x10},
622 {0xa1, 0x21, 0x69, 0x38, 0x00, 0x00, 0x00, 0x10},
623 {0xd1, 0x21, 0x6f, 0x1f, 0x01, 0x00, 0x10, 0x10},
624 {0xd1, 0x21, 0x73, 0x50, 0x20, 0x02, 0x01, 0x10},
625 {0xd1, 0x21, 0x77, 0xf3, 0x90, 0x98, 0x98, 0x10},
626 {0xc1, 0x21, 0x7b, 0x00, 0x4c, 0xf7, 0x00, 0x10},
627 {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
628 {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
629/* */
630 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
631 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
632/*fixme: + 0x12, 0x04*/
Jean-Francois Moine6c862742008-09-08 04:57:26 -0300633/* {0xa1, 0x21, 0x75, 0x82, 0x00, 0x00, 0x00, 0x10}, * COMN
634 * set by setvflip */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300635 {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
636 {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
637 {0xb1, 0x21, 0x01, 0x80, 0x80, 0x00, 0x00, 0x10},
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300638/* */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300639 {0xa1, 0x21, 0x11, 0x00, 0x00, 0x00, 0x00, 0x10},
640 {0xa1, 0x21, 0x2a, 0x88, 0x00, 0x00, 0x00, 0x10},
641 {0xa1, 0x21, 0x2b, 0x34, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300642/* */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300643 {0xa1, 0x21, 0x10, 0x83, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine91de65a2008-09-03 17:12:18 -0300644/* {0xb1, 0x21, 0x01, 0x88, 0x70, 0x00, 0x00, 0x10}, */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300645 {}
646};
Jean-Francois Moine62703302008-11-11 08:42:56 -0300647
Jean-Francois Moine98819182009-01-19 07:37:33 -0300648static const u8 ov7648_sensor_init[][8] = {
Jean-Francois Moine62703302008-11-11 08:42:56 -0300649 {0xa1, 0x21, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10},
650 {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
651 {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
652 {0xd1, 0x21, 0x03, 0xa4, 0x30, 0x88, 0x00, 0x10},
653 {0xb1, 0x21, 0x11, 0x80, 0x08, 0x00, 0x00, 0x10},
654 {0xc1, 0x21, 0x13, 0xa0, 0x04, 0x84, 0x00, 0x10},
655 {0xd1, 0x21, 0x17, 0x1a, 0x02, 0xba, 0xf4, 0x10},
656 {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
657 {0xd1, 0x21, 0x1f, 0x41, 0xc0, 0x80, 0x80, 0x10},
658 {0xd1, 0x21, 0x23, 0xde, 0xa0, 0x80, 0x32, 0x10},
659 {0xd1, 0x21, 0x27, 0xfe, 0xa0, 0x00, 0x91, 0x10},
660 {0xd1, 0x21, 0x2b, 0x00, 0x88, 0x85, 0x80, 0x10},
661 {0xc1, 0x21, 0x2f, 0x9c, 0x00, 0xc4, 0x00, 0x10},
662 {0xd1, 0x21, 0x60, 0xa6, 0x60, 0x88, 0x12, 0x10},
663 {0xd1, 0x21, 0x64, 0x88, 0x00, 0x00, 0x94, 0x10},
664 {0xd1, 0x21, 0x68, 0x7a, 0x0c, 0x00, 0x00, 0x10},
665 {0xd1, 0x21, 0x6c, 0x11, 0x33, 0x22, 0x00, 0x10},
666 {0xd1, 0x21, 0x70, 0x11, 0x00, 0x10, 0x50, 0x10},
667 {0xd1, 0x21, 0x74, 0x20, 0x06, 0x00, 0xb5, 0x10},
668 {0xd1, 0x21, 0x78, 0x8a, 0x00, 0x00, 0x00, 0x10},
669 {0xb1, 0x21, 0x7c, 0x00, 0x43, 0x00, 0x00, 0x10},
670
671 {0xd1, 0x21, 0x21, 0x86, 0x00, 0xde, 0xa0, 0x10},
672/* {0xd1, 0x21, 0x25, 0x80, 0x32, 0xfe, 0xa0, 0x10}, jfm done */
673/* {0xd1, 0x21, 0x29, 0x00, 0x91, 0x00, 0x88, 0x10}, jfm done */
674 {0xb1, 0x21, 0x2d, 0x85, 0x00, 0x00, 0x00, 0x10},
675/*...*/
676/* {0xa1, 0x21, 0x12, 0x08, 0x00, 0x00, 0x00, 0x10}, jfm done */
Jean-Francois Moine2797ba22009-02-05 15:12:24 -0300677/* {0xa1, 0x21, 0x75, 0x06, 0x00, 0x00, 0x00, 0x10}, * COMN
678 * set by setvflip */
Jean-Francois Moine62703302008-11-11 08:42:56 -0300679 {0xa1, 0x21, 0x19, 0x02, 0x00, 0x00, 0x00, 0x10},
680 {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
681/* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
682/* {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}, * GAIN - def */
683/* {0xb1, 0x21, 0x01, 0x6c, 0x6c, 0x00, 0x00, 0x10}, * B R - def: 80 */
684/*...*/
685 {0xa1, 0x21, 0x11, 0x81, 0x00, 0x00, 0x00, 0x10}, /* CLKRC */
686/* {0xa1, 0x21, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
687/* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
688/* {0xa1, 0x21, 0x2a, 0x91, 0x00, 0x00, 0x00, 0x10}, jfm done */
689/* {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
690/* {0xb1, 0x21, 0x01, 0x64, 0x84, 0x00, 0x00, 0x10}, * B R - def: 80 */
691
692 {}
693};
694
Jean-Francois Moine98819182009-01-19 07:37:33 -0300695static const u8 ov7660_sensor_init[][8] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300696 {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */
Jean-Francois Moine60017612008-07-18 08:46:19 -0300697/* (delay 20ms) */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300698 {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300699 /* Outformat = rawRGB */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300700 {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300701 {0xd1, 0x21, 0x00, 0x01, 0x74, 0x74, 0x00, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300702 /* GAIN BLUE RED VREF */
703 {0xd1, 0x21, 0x04, 0x00, 0x7d, 0x62, 0x00, 0x10},
704 /* COM 1 BAVE GEAVE AECHH */
705 {0xb1, 0x21, 0x08, 0x83, 0x01, 0x00, 0x00, 0x10}, /* RAVE COM2 */
706 {0xd1, 0x21, 0x0c, 0x00, 0x08, 0x04, 0x4f, 0x10}, /* COM 3 4 5 6 */
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300707 {0xd1, 0x21, 0x10, 0x7f, 0x40, 0x05, 0xff, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300708 /* AECH CLKRC COM7 COM8 */
709 {0xc1, 0x21, 0x14, 0x2c, 0x00, 0x02, 0x00, 0x10}, /* COM9 COM10 */
710 {0xd1, 0x21, 0x17, 0x10, 0x60, 0x02, 0x7b, 0x10},
711 /* HSTART HSTOP VSTRT VSTOP */
712 {0xa1, 0x21, 0x1b, 0x02, 0x00, 0x00, 0x00, 0x10}, /* PSHFT */
713 {0xb1, 0x21, 0x1e, 0x01, 0x0e, 0x00, 0x00, 0x10}, /* MVFP LAEC */
714 {0xd1, 0x21, 0x20, 0x07, 0x07, 0x07, 0x07, 0x10},
715 /* BOS GBOS GROS ROS (BGGR offset) */
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300716/* {0xd1, 0x21, 0x24, 0x68, 0x58, 0xd4, 0x80, 0x10}, */
717 {0xd1, 0x21, 0x24, 0x78, 0x68, 0xd4, 0x80, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300718 /* AEW AEB VPT BBIAS */
719 {0xd1, 0x21, 0x28, 0x80, 0x30, 0x00, 0x00, 0x10},
720 /* GbBIAS RSVD EXHCH EXHCL */
721 {0xd1, 0x21, 0x2c, 0x80, 0x00, 0x00, 0x62, 0x10},
722 /* RBIAS ADVFL ASDVFH YAVE */
723 {0xc1, 0x21, 0x30, 0x08, 0x30, 0xb4, 0x00, 0x10},
724 /* HSYST HSYEN HREF */
725 {0xd1, 0x21, 0x33, 0x00, 0x07, 0x84, 0x00, 0x10}, /* reserved */
726 {0xd1, 0x21, 0x37, 0x0c, 0x02, 0x43, 0x00, 0x10},
727 /* ADC ACOM OFON TSLB */
728 {0xd1, 0x21, 0x3b, 0x02, 0x6c, 0x19, 0x0e, 0x10},
729 /* COM11 COM12 COM13 COM14 */
730 {0xd1, 0x21, 0x3f, 0x41, 0xc1, 0x22, 0x08, 0x10},
731 /* EDGE COM15 COM16 COM17 */
732 {0xd1, 0x21, 0x43, 0xf0, 0x10, 0x78, 0xa8, 0x10}, /* reserved */
733 {0xd1, 0x21, 0x47, 0x60, 0x80, 0x00, 0x00, 0x10}, /* reserved */
734 {0xd1, 0x21, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* reserved */
735 {0xd1, 0x21, 0x4f, 0x46, 0x36, 0x0f, 0x17, 0x10}, /* MTX 1 2 3 4 */
736 {0xd1, 0x21, 0x53, 0x7f, 0x96, 0x40, 0x40, 0x10}, /* MTX 5 6 7 8 */
737 {0xb1, 0x21, 0x57, 0x40, 0x0f, 0x00, 0x00, 0x10}, /* MTX9 MTXS */
738 {0xd1, 0x21, 0x59, 0xba, 0x9a, 0x22, 0xb9, 0x10}, /* reserved */
739 {0xd1, 0x21, 0x5d, 0x9b, 0x10, 0xf0, 0x05, 0x10}, /* reserved */
740 {0xa1, 0x21, 0x61, 0x60, 0x00, 0x00, 0x00, 0x10}, /* reserved */
741 {0xd1, 0x21, 0x62, 0x00, 0x00, 0x50, 0x30, 0x10},
742 /* LCC1 LCC2 LCC3 LCC4 */
743 {0xa1, 0x21, 0x66, 0x00, 0x00, 0x00, 0x00, 0x10}, /* LCC5 */
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300744 {0xd1, 0x21, 0x67, 0x80, 0x7a, 0x90, 0x80, 0x10}, /* MANU */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300745 {0xa1, 0x21, 0x6b, 0x0a, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300746 /* band gap reference [0:3] DBLV */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300747 {0xd1, 0x21, 0x6c, 0x30, 0x48, 0x80, 0x74, 0x10}, /* gamma curve */
748 {0xd1, 0x21, 0x70, 0x64, 0x60, 0x5c, 0x58, 0x10}, /* gamma curve */
749 {0xd1, 0x21, 0x74, 0x54, 0x4c, 0x40, 0x38, 0x10}, /* gamma curve */
750 {0xd1, 0x21, 0x78, 0x34, 0x30, 0x2f, 0x2b, 0x10}, /* gamma curve */
751 {0xd1, 0x21, 0x7c, 0x03, 0x07, 0x17, 0x34, 0x10}, /* gamma curve */
752 {0xd1, 0x21, 0x80, 0x41, 0x4d, 0x58, 0x63, 0x10}, /* gamma curve */
753 {0xd1, 0x21, 0x84, 0x6e, 0x77, 0x87, 0x95, 0x10}, /* gamma curve */
754 {0xc1, 0x21, 0x88, 0xaf, 0xc7, 0xdf, 0x00, 0x10}, /* gamma curve */
755 {0xc1, 0x21, 0x8b, 0x99, 0x99, 0xcf, 0x00, 0x10}, /* reserved */
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300756 {0xb1, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x10}, /* DM_LNL/H */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300757/****** (some exchanges in the win trace) ******/
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300758 {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10}, /* MVFP */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300759 /* bits[3..0]reserved */
760 {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10},
761 {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
762 /* VREF vertical frame ctrl */
763 {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300764 {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10}, /* AECH 0x20 */
765 {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFL */
766 {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFH */
767 {0xa1, 0x21, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x10}, /* GAIN */
768/* {0xb1, 0x21, 0x01, 0x78, 0x78, 0x00, 0x00, 0x10}, * BLUE */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300769/****** (some exchanges in the win trace) ******/
770 {0xa1, 0x21, 0x93, 0x00, 0x00, 0x00, 0x00, 0x10},/* dummy line hight */
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300771 {0xa1, 0x21, 0x92, 0x25, 0x00, 0x00, 0x00, 0x10}, /* dummy line low */
772 {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCH */
773 {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCL */
774/* {0xa1, 0x21, 0x02, 0x90, 0x00, 0x00, 0x00, 0x10}, * RED */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300775/****** (some exchanges in the win trace) ******/
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300776/******!! startsensor KO if changed !!****/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300777 {0xa1, 0x21, 0x93, 0x01, 0x00, 0x00, 0x00, 0x10},
778 {0xa1, 0x21, 0x92, 0xff, 0x00, 0x00, 0x00, 0x10},
779 {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10},
780 {0xa1, 0x21, 0x2b, 0xc3, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300781 {}
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300782};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300783
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -0300784static const u8 sp80708_sensor_init[][8] = {
785 {0xa1, 0x18, 0x06, 0xf9, 0x00, 0x00, 0x00, 0x10},
786 {0xa1, 0x18, 0x09, 0x1f, 0x00, 0x00, 0x00, 0x10},
787 {0xa1, 0x18, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
788 {0xa1, 0x18, 0x0d, 0xc0, 0x00, 0x00, 0x00, 0x10},
789 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
790 {0xa1, 0x18, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x10},
791 {0xa1, 0x18, 0x10, 0x40, 0x00, 0x00, 0x00, 0x10},
792 {0xa1, 0x18, 0x11, 0x4e, 0x00, 0x00, 0x00, 0x10},
793 {0xa1, 0x18, 0x12, 0x53, 0x00, 0x00, 0x00, 0x10},
794 {0xa1, 0x18, 0x15, 0x80, 0x00, 0x00, 0x00, 0x10},
795 {0xa1, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10},
796 {0xa1, 0x18, 0x19, 0x18, 0x00, 0x00, 0x00, 0x10},
797 {0xa1, 0x18, 0x1a, 0x10, 0x00, 0x00, 0x00, 0x10},
798 {0xa1, 0x18, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x10},
799 {0xa1, 0x18, 0x1c, 0x28, 0x00, 0x00, 0x00, 0x10},
800 {0xa1, 0x18, 0x1d, 0x02, 0x00, 0x00, 0x00, 0x10},
801 {0xa1, 0x18, 0x1e, 0x10, 0x00, 0x00, 0x00, 0x10},
802 {0xa1, 0x18, 0x26, 0x04, 0x00, 0x00, 0x00, 0x10},
803 {0xa1, 0x18, 0x27, 0x1e, 0x00, 0x00, 0x00, 0x10},
804 {0xa1, 0x18, 0x28, 0x5a, 0x00, 0x00, 0x00, 0x10},
805 {0xa1, 0x18, 0x29, 0x28, 0x00, 0x00, 0x00, 0x10},
806 {0xa1, 0x18, 0x2a, 0x78, 0x00, 0x00, 0x00, 0x10},
807 {0xa1, 0x18, 0x2b, 0x01, 0x00, 0x00, 0x00, 0x10},
808 {0xa1, 0x18, 0x2c, 0xf7, 0x00, 0x00, 0x00, 0x10},
809 {0xa1, 0x18, 0x2d, 0x2d, 0x00, 0x00, 0x00, 0x10},
810 {0xa1, 0x18, 0x2e, 0xd5, 0x00, 0x00, 0x00, 0x10},
811 {0xa1, 0x18, 0x39, 0x42, 0x00, 0x00, 0x00, 0x10},
812 {0xa1, 0x18, 0x3a, 0x67, 0x00, 0x00, 0x00, 0x10},
813 {0xa1, 0x18, 0x3b, 0x87, 0x00, 0x00, 0x00, 0x10},
814 {0xa1, 0x18, 0x3c, 0xa3, 0x00, 0x00, 0x00, 0x10},
815 {0xa1, 0x18, 0x3d, 0xb0, 0x00, 0x00, 0x00, 0x10},
816 {0xa1, 0x18, 0x3e, 0xbc, 0x00, 0x00, 0x00, 0x10},
817 {0xa1, 0x18, 0x3f, 0xc8, 0x00, 0x00, 0x00, 0x10},
818 {0xa1, 0x18, 0x40, 0xd4, 0x00, 0x00, 0x00, 0x10},
819 {0xa1, 0x18, 0x41, 0xdf, 0x00, 0x00, 0x00, 0x10},
820 {0xa1, 0x18, 0x42, 0xea, 0x00, 0x00, 0x00, 0x10},
821 {0xa1, 0x18, 0x43, 0xf5, 0x00, 0x00, 0x00, 0x10},
822 {0xa1, 0x18, 0x45, 0x80, 0x00, 0x00, 0x00, 0x10},
823 {0xa1, 0x18, 0x46, 0x60, 0x00, 0x00, 0x00, 0x10},
824 {0xa1, 0x18, 0x47, 0x50, 0x00, 0x00, 0x00, 0x10},
825 {0xa1, 0x18, 0x48, 0x30, 0x00, 0x00, 0x00, 0x10},
826 {0xa1, 0x18, 0x49, 0x01, 0x00, 0x00, 0x00, 0x10},
827 {0xa1, 0x18, 0x4d, 0xae, 0x00, 0x00, 0x00, 0x10},
828 {0xa1, 0x18, 0x4e, 0x03, 0x00, 0x00, 0x00, 0x10},
829 {0xa1, 0x18, 0x4f, 0x66, 0x00, 0x00, 0x00, 0x10},
830 {0xa1, 0x18, 0x50, 0x1c, 0x00, 0x00, 0x00, 0x10},
831 {0xa1, 0x18, 0x44, 0x10, 0x00, 0x00, 0x00, 0x10},
832 {0xa1, 0x18, 0x4a, 0x30, 0x00, 0x00, 0x00, 0x10},
833 {0xa1, 0x18, 0x51, 0x80, 0x00, 0x00, 0x00, 0x10},
834 {0xa1, 0x18, 0x52, 0x80, 0x00, 0x00, 0x00, 0x10},
835 {0xa1, 0x18, 0x53, 0x80, 0x00, 0x00, 0x00, 0x10},
836 {0xa1, 0x18, 0x54, 0x80, 0x00, 0x00, 0x00, 0x10},
837 {0xa1, 0x18, 0x55, 0x80, 0x00, 0x00, 0x00, 0x10},
838 {0xa1, 0x18, 0x56, 0x80, 0x00, 0x00, 0x00, 0x10},
839 {0xa1, 0x18, 0x57, 0xe0, 0x00, 0x00, 0x00, 0x10},
840 {0xa1, 0x18, 0x58, 0xc0, 0x00, 0x00, 0x00, 0x10},
841 {0xa1, 0x18, 0x59, 0xab, 0x00, 0x00, 0x00, 0x10},
842 {0xa1, 0x18, 0x5a, 0xa0, 0x00, 0x00, 0x00, 0x10},
843 {0xa1, 0x18, 0x5b, 0x99, 0x00, 0x00, 0x00, 0x10},
844 {0xa1, 0x18, 0x5c, 0x90, 0x00, 0x00, 0x00, 0x10},
845 {0xa1, 0x18, 0x5e, 0x24, 0x00, 0x00, 0x00, 0x10},
846 {0xa1, 0x18, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x10},
847 {0xa1, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00, 0x10},
848 {0xa1, 0x18, 0x61, 0x73, 0x00, 0x00, 0x00, 0x10},
849 {0xa1, 0x18, 0x63, 0x42, 0x00, 0x00, 0x00, 0x10},
850 {0xa1, 0x18, 0x64, 0x42, 0x00, 0x00, 0x00, 0x10},
851 {0xa1, 0x18, 0x65, 0x42, 0x00, 0x00, 0x00, 0x10},
852 {0xa1, 0x18, 0x66, 0x24, 0x00, 0x00, 0x00, 0x10},
853 {0xa1, 0x18, 0x67, 0x24, 0x00, 0x00, 0x00, 0x10},
854 {0xa1, 0x18, 0x68, 0x08, 0x00, 0x00, 0x00, 0x10},
855 {0xa1, 0x18, 0x2f, 0xc9, 0x00, 0x00, 0x00, 0x10},
856 /********/
857 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
858 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
859 {0xa1, 0x18, 0x03, 0x01, 0x00, 0x00, 0x00, 0x10},
860 {0xa1, 0x18, 0x04, 0xa4, 0x00, 0x00, 0x00, 0x10},
861 {0xa1, 0x18, 0x14, 0x3f, 0x00, 0x00, 0x00, 0x10},
862 {0xa1, 0x18, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
863 {0xb1, 0x18, 0x11, 0x40, 0x40, 0x00, 0x00, 0x10},
864 {}
865};
866
Jean-Francois Moine8295d992008-09-03 17:12:19 -0300867/* read <len> bytes to gspca_dev->usb_buf */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300868static void reg_r(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -0300869 u16 value, int len)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300870{
Jean-Francois Moine8295d992008-09-03 17:12:19 -0300871#ifdef GSPCA_DEBUG
872 if (len > USB_BUF_SZ) {
873 err("reg_r: buffer overflow");
874 return;
875 }
876#endif
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300877 usb_control_msg(gspca_dev->dev,
878 usb_rcvctrlpipe(gspca_dev->dev, 0),
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300879 0,
880 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
881 value, 0,
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300882 gspca_dev->usb_buf, len,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300883 500);
Jean-Francois Moine60017612008-07-18 08:46:19 -0300884 PDEBUG(D_USBI, "reg_r [%02x] -> %02x", value, gspca_dev->usb_buf[0]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300885}
886
Jean-Francois Moine60017612008-07-18 08:46:19 -0300887static void reg_w1(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -0300888 u16 value,
889 u8 data)
Jean-Francois Moine60017612008-07-18 08:46:19 -0300890{
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300891 PDEBUG(D_USBO, "reg_w1 [%04x] = %02x", value, data);
Jean-Francois Moine60017612008-07-18 08:46:19 -0300892 gspca_dev->usb_buf[0] = data;
893 usb_control_msg(gspca_dev->dev,
894 usb_sndctrlpipe(gspca_dev->dev, 0),
895 0x08,
896 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
897 value,
898 0,
899 gspca_dev->usb_buf, 1,
900 500);
901}
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300902static void reg_w(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -0300903 u16 value,
904 const u8 *buffer,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300905 int len)
906{
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300907 PDEBUG(D_USBO, "reg_w [%04x] = %02x %02x ..",
Jean-Francois Moine60017612008-07-18 08:46:19 -0300908 value, buffer[0], buffer[1]);
Jean-Francois Moine8295d992008-09-03 17:12:19 -0300909#ifdef GSPCA_DEBUG
910 if (len > USB_BUF_SZ) {
911 err("reg_w: buffer overflow");
912 return;
Jean-Francois Moinebf7f0b92008-07-03 11:09:12 -0300913 }
Jean-Francois Moine8295d992008-09-03 17:12:19 -0300914#endif
915 memcpy(gspca_dev->usb_buf, buffer, len);
916 usb_control_msg(gspca_dev->dev,
917 usb_sndctrlpipe(gspca_dev->dev, 0),
918 0x08,
919 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
920 value, 0,
921 gspca_dev->usb_buf, len,
922 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300923}
924
Jean-Francois Moine60017612008-07-18 08:46:19 -0300925/* I2C write 1 byte */
Jean-Francois Moine98819182009-01-19 07:37:33 -0300926static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300927{
928 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300929
Jean-Francois Moine60017612008-07-18 08:46:19 -0300930 PDEBUG(D_USBO, "i2c_w2 [%02x] = %02x", reg, val);
931 gspca_dev->usb_buf[0] = 0x81 | (2 << 4); /* = a1 */
932 gspca_dev->usb_buf[1] = sd->i2c_base;
933 gspca_dev->usb_buf[2] = reg;
934 gspca_dev->usb_buf[3] = val;
935 gspca_dev->usb_buf[4] = 0;
936 gspca_dev->usb_buf[5] = 0;
937 gspca_dev->usb_buf[6] = 0;
938 gspca_dev->usb_buf[7] = 0x10;
939 usb_control_msg(gspca_dev->dev,
940 usb_sndctrlpipe(gspca_dev->dev, 0),
941 0x08,
942 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
943 0x08, /* value = i2c */
944 0,
945 gspca_dev->usb_buf, 8,
946 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300947}
948
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300949/* I2C write 8 bytes */
950static void i2c_w8(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -0300951 const u8 *buffer)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300952{
Jean-Francois Moine60017612008-07-18 08:46:19 -0300953 memcpy(gspca_dev->usb_buf, buffer, 8);
954 usb_control_msg(gspca_dev->dev,
955 usb_sndctrlpipe(gspca_dev->dev, 0),
956 0x08,
957 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
958 0x08, 0, /* value, index */
959 gspca_dev->usb_buf, 8,
960 500);
Jean-Francois Moine8d768e12008-09-21 03:28:55 -0300961 msleep(2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300962}
963
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300964/* read 5 bytes in gspca_dev->usb_buf */
Jean-Francois Moine98819182009-01-19 07:37:33 -0300965static void i2c_r5(struct gspca_dev *gspca_dev, u8 reg)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300966{
967 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -0300968 u8 mode[8];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300969
Hans de Goede3647fea2008-07-15 05:36:30 -0300970 mode[0] = 0x81 | 0x10;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300971 mode[1] = sd->i2c_base;
972 mode[2] = reg;
973 mode[3] = 0;
974 mode[4] = 0;
975 mode[5] = 0;
976 mode[6] = 0;
977 mode[7] = 0x10;
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300978 i2c_w8(gspca_dev, mode);
Jean-Francois Moine60017612008-07-18 08:46:19 -0300979 msleep(2);
Hans de Goede3647fea2008-07-15 05:36:30 -0300980 mode[0] = 0x81 | (5 << 4) | 0x02;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300981 mode[2] = 0;
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300982 i2c_w8(gspca_dev, mode);
Jean-Francois Moine60017612008-07-18 08:46:19 -0300983 msleep(2);
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300984 reg_r(gspca_dev, 0x0a, 5);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300985}
986
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300987static int hv7131r_probe(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300988{
Jean-Francois Moine60017612008-07-18 08:46:19 -0300989 i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300990 msleep(10);
Jean-Francois Moine60017612008-07-18 08:46:19 -0300991 reg_w1(gspca_dev, 0x02, 0x66); /* Gpio on */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300992 msleep(10);
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300993 i2c_r5(gspca_dev, 0); /* read sensor id */
994 if (gspca_dev->usb_buf[0] == 0x02
995 && gspca_dev->usb_buf[1] == 0x09
996 && gspca_dev->usb_buf[2] == 0x01
997 && gspca_dev->usb_buf[3] == 0x00
998 && gspca_dev->usb_buf[4] == 0x00) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300999 PDEBUG(D_PROBE, "Find Sensor sn9c102P HV7131R");
Jean-Francois Moine577cbf42008-12-05 06:18:37 -03001000 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001001 }
Jean-Francois Moine60017612008-07-18 08:46:19 -03001002 PDEBUG(D_PROBE, "Find Sensor 0x%02x 0x%02x 0x%02x",
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001003 gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
1004 gspca_dev->usb_buf[2]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001005 PDEBUG(D_PROBE, "Sensor sn9c102P Not found");
1006 return -ENODEV;
1007}
1008
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001009static void mi0360_probe(struct gspca_dev *gspca_dev)
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001010{
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001011 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001012 int i, j;
Jean-Francois Moine92e8c912009-02-02 16:25:38 -03001013 u16 val = 0;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001014 static const u8 probe_tb[][4][8] = {
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001015 { /* mi0360 */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001016 {0xb0, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
1017 {0x90, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1018 {0xa2, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1019 {0xb0, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10}
1020 },
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001021 { /* mt9v111 */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001022 {0xb0, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10},
1023 {0x90, 0x5c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x10},
1024 {0xa2, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1025 {}
1026 },
1027 };
1028
1029 for (i = 0; i < ARRAY_SIZE(probe_tb); i++) {
1030 reg_w1(gspca_dev, 0x17, 0x62);
1031 reg_w1(gspca_dev, 0x01, 0x08);
1032 for (j = 0; j < 3; j++)
1033 i2c_w8(gspca_dev, probe_tb[i][j]);
1034 msleep(2);
1035 reg_r(gspca_dev, 0x0a, 5);
1036 val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
1037 if (probe_tb[i][3][0] != 0)
1038 i2c_w8(gspca_dev, probe_tb[i][3]);
1039 reg_w1(gspca_dev, 0x01, 0x29);
1040 reg_w1(gspca_dev, 0x17, 0x42);
1041 if (val != 0xffff)
1042 break;
1043 }
1044 switch (val) {
1045 case 0x823a:
1046 PDEBUG(D_PROBE, "Sensor mt9v111");
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001047 sd->sensor = SENSOR_MT9V111;
1048 sd->i2c_base = 0x5c;
1049 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001050 case 0x8243:
1051 PDEBUG(D_PROBE, "Sensor mi0360");
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001052 break;
1053 default:
1054 PDEBUG(D_PROBE, "Unknown sensor %04x - forced to mi0360", val);
1055 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001056 }
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001057}
1058
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001059static int configure_gpio(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -03001060 const u8 *sn9c1xx)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001061{
1062 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001063 const u8 *reg9a;
1064 static const u8 reg9a_def[] =
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001065 {0x08, 0x40, 0x20, 0x10, 0x00, 0x04};
Jean-Francois Moine98819182009-01-19 07:37:33 -03001066 static const u8 reg9a_sn9c325[] =
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001067 {0x0a, 0x40, 0x38, 0x30, 0x00, 0x20};
Jean-Francois Moine98819182009-01-19 07:37:33 -03001068 static const u8 regd4[] = {0x60, 0x00, 0x00};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001069
Jean-Francois Moine60017612008-07-18 08:46:19 -03001070 reg_w1(gspca_dev, 0xf1, 0x00);
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001071 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001072
1073 /* configure gpio */
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001074 reg_w(gspca_dev, 0x01, &sn9c1xx[1], 2);
1075 reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001076 reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5); /* jfm len was 3 */
Hans de Goede3647fea2008-07-15 05:36:30 -03001077 switch (sd->bridge) {
1078 case BRIDGE_SN9C325:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001079 reg9a = reg9a_sn9c325;
1080 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001081 default:
1082 reg9a = reg9a_def;
1083 break;
1084 }
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001085 reg_w(gspca_dev, 0x9a, reg9a, 6);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001086
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001087 reg_w(gspca_dev, 0xd4, regd4, sizeof regd4); /*fixme:jfm was 60 only*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001088
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001089 reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001090
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001091 switch (sd->sensor) {
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001092 case SENSOR_MT9V111:
1093 reg_w1(gspca_dev, 0x01, 0x61);
1094 reg_w1(gspca_dev, 0x17, 0x61);
1095 reg_w1(gspca_dev, 0x01, 0x60);
1096 reg_w1(gspca_dev, 0x01, 0x40);
1097 break;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001098 case SENSOR_OM6802:
Jean-Francois Moine4f30f6c2008-09-03 16:48:05 -03001099 reg_w1(gspca_dev, 0x02, 0x71);
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001100 reg_w1(gspca_dev, 0x01, 0x42);
1101 reg_w1(gspca_dev, 0x17, 0x64);
1102 reg_w1(gspca_dev, 0x01, 0x42);
1103 break;
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001104/*jfm: from win trace */
1105 case SENSOR_OV7630:
1106 reg_w1(gspca_dev, 0x01, 0x61);
1107 reg_w1(gspca_dev, 0x17, 0xe2);
1108 reg_w1(gspca_dev, 0x01, 0x60);
1109 reg_w1(gspca_dev, 0x01, 0x40);
1110 break;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001111 case SENSOR_OV7648:
Jean-Francois Moine62703302008-11-11 08:42:56 -03001112 reg_w1(gspca_dev, 0x01, 0x63);
1113 reg_w1(gspca_dev, 0x17, 0x20);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001114 reg_w1(gspca_dev, 0x01, 0x42);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001115 break;
Jean-Francois Moine91de65a2008-09-03 17:12:18 -03001116/*jfm: from win trace */
1117 case SENSOR_OV7660:
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001118 if (sd->bridge == BRIDGE_SN9C120) {
1119 reg_w1(gspca_dev, 0x01, 0x61);
1120 reg_w1(gspca_dev, 0x17, 0x20);
1121 reg_w1(gspca_dev, 0x01, 0x60);
1122 reg_w1(gspca_dev, 0x01, 0x40);
1123 break;
1124 }
1125 /* fall thru */
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001126 case SENSOR_SP80708:
1127 reg_w1(gspca_dev, 0x01, 0x63);
1128 reg_w1(gspca_dev, 0x17, 0x20);
1129 reg_w1(gspca_dev, 0x01, 0x62);
1130 reg_w1(gspca_dev, 0x01, 0x42);
1131 mdelay(100);
1132 reg_w1(gspca_dev, 0x02, 0x62);
1133 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001134 default:
Jean-Francois Moine60017612008-07-18 08:46:19 -03001135 reg_w1(gspca_dev, 0x01, 0x43);
1136 reg_w1(gspca_dev, 0x17, 0x61);
1137 reg_w1(gspca_dev, 0x01, 0x42);
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001138 if (sd->sensor == SENSOR_HV7131R) {
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001139 if (hv7131r_probe(gspca_dev) < 0)
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001140 return -ENODEV;
1141 }
1142 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001143 }
1144 return 0;
1145}
1146
1147static void hv7131R_InitSensor(struct gspca_dev *gspca_dev)
1148{
1149 int i = 0;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001150 static const u8 SetSensorClk[] = /* 0x08 Mclk */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001151 { 0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10 };
1152
1153 while (hv7131r_sensor_init[i][0]) {
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001154 i2c_w8(gspca_dev, hv7131r_sensor_init[i]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001155 i++;
1156 }
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001157 i2c_w8(gspca_dev, SetSensorClk);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001158}
1159
1160static void mi0360_InitSensor(struct gspca_dev *gspca_dev)
1161{
1162 int i = 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001163
1164 while (mi0360_sensor_init[i][0]) {
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001165 i2c_w8(gspca_dev, mi0360_sensor_init[i]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001166 i++;
1167 }
1168}
1169
1170static void mo4000_InitSensor(struct gspca_dev *gspca_dev)
1171{
1172 int i = 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001173
1174 while (mo4000_sensor_init[i][0]) {
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001175 i2c_w8(gspca_dev, mo4000_sensor_init[i]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001176 i++;
1177 }
1178}
1179
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001180static void mt9v111_InitSensor(struct gspca_dev *gspca_dev)
1181{
1182 int i = 0;
1183
1184 i2c_w8(gspca_dev, mt9v111_sensor_init[i]);
1185 i++;
1186 msleep(20);
1187 while (mt9v111_sensor_init[i][0]) {
1188 i2c_w8(gspca_dev, mt9v111_sensor_init[i]);
1189 i++;
1190 }
1191}
1192
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001193static void om6802_InitSensor(struct gspca_dev *gspca_dev)
1194{
1195 int i = 0;
1196
1197 while (om6802_sensor_init[i][0]) {
1198 i2c_w8(gspca_dev, om6802_sensor_init[i]);
1199 i++;
1200 }
1201}
1202
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001203static void ov7630_InitSensor(struct gspca_dev *gspca_dev)
1204{
1205 int i = 0;
1206
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001207 i2c_w8(gspca_dev, ov7630_sensor_init[i]); /* 76 01 */
1208 i++;
1209 i2c_w8(gspca_dev, ov7630_sensor_init[i]); /* 12 c8 (RGB+SRST) */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001210 i++;
1211 msleep(20);
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001212 i2c_w8(gspca_dev, ov7630_sensor_init[i]); /* 12 48 */
1213 i++;
1214 i2c_w8(gspca_dev, ov7630_sensor_init[i]); /* 12 c8 */
1215 i++;
1216 msleep(20);
1217 i2c_w8(gspca_dev, ov7630_sensor_init[i]); /* 12 48 */
1218 i++;
1219/*jfm:win i2c_r from 00 to 80*/
1220
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001221 while (ov7630_sensor_init[i][0]) {
1222 i2c_w8(gspca_dev, ov7630_sensor_init[i]);
1223 i++;
1224 }
1225}
1226
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001227static void ov7648_InitSensor(struct gspca_dev *gspca_dev)
1228{
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001229 int i = 0;
1230
Jean-Francois Moine62703302008-11-11 08:42:56 -03001231 i2c_w8(gspca_dev, ov7648_sensor_init[i]);
1232 i++;
1233/* win: dble reset */
1234 i2c_w8(gspca_dev, ov7648_sensor_init[i]); /* reset */
1235 i++;
1236 msleep(20);
1237/* win: i2c reg read 00..7f */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001238 while (ov7648_sensor_init[i][0]) {
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001239 i2c_w8(gspca_dev, ov7648_sensor_init[i]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001240 i++;
1241 }
1242}
1243
1244static void ov7660_InitSensor(struct gspca_dev *gspca_dev)
1245{
1246 int i = 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001247
Jean-Francois Moine60017612008-07-18 08:46:19 -03001248 i2c_w8(gspca_dev, ov7660_sensor_init[i]); /* reset SCCB */
1249 i++;
1250 msleep(20);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001251 while (ov7660_sensor_init[i][0]) {
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001252 i2c_w8(gspca_dev, ov7660_sensor_init[i]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001253 i++;
1254 }
1255}
1256
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001257static void sp80708_InitSensor(struct gspca_dev *gspca_dev)
1258{
1259 int i = 0;
1260
1261 i2c_w8(gspca_dev, sp80708_sensor_init[i]); /* reset SCCB */
1262 i++;
1263 msleep(20);
1264 while (sp80708_sensor_init[i][0]) {
1265 i2c_w8(gspca_dev, sp80708_sensor_init[i]);
1266 i++;
1267 }
1268}
1269
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001270/* this function is called at probe time */
1271static int sd_config(struct gspca_dev *gspca_dev,
1272 const struct usb_device_id *id)
1273{
1274 struct sd *sd = (struct sd *) gspca_dev;
1275 struct cam *cam;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001276
1277 cam = &gspca_dev->cam;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001278 cam->cam_mode = vga_mode;
1279 cam->nmodes = ARRAY_SIZE(vga_mode);
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001280
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03001281 sd->bridge = id->driver_info >> 16;
1282 sd->sensor = id->driver_info >> 8;
1283 sd->i2c_base = id->driver_info;
1284
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001285 sd->brightness = BRIGHTNESS_DEF;
1286 sd->contrast = CONTRAST_DEF;
1287 sd->colors = COLOR_DEF;
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001288 sd->blue = BLUE_BALANCE_DEF;
1289 sd->red = RED_BALANCE_DEF;
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03001290 sd->gamma = GAMMA_DEF;
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001291 sd->autogain = AUTOGAIN_DEF;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001292 sd->ag_cnt = -1;
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03001293 if (sd->sensor != SENSOR_OV7630)
1294 sd->vflip = 0;
1295 else
1296 sd->vflip = 1;
Jean-Francois Moine0cae8962008-10-17 07:48:24 -03001297 sd->infrared = INFRARED_DEF;
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03001298 sd->quality = 80;
1299 sd->jpegqual = 80;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001300
Jean-Francois Moine577cbf42008-12-05 06:18:37 -03001301 gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001302 return 0;
1303}
1304
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03001305/* this function is called at probe and resume time */
1306static int sd_init(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001307{
1308 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001309 u8 regGpio[] = { 0x29, 0x74 };
1310 u8 regF1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001311
Hans de Goede3647fea2008-07-15 05:36:30 -03001312 /* setup a selector by bridge */
Jean-Francois Moine60017612008-07-18 08:46:19 -03001313 reg_w1(gspca_dev, 0xf1, 0x01);
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001314 reg_r(gspca_dev, 0x00, 1);
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001315 reg_w1(gspca_dev, 0xf1, gspca_dev->usb_buf[0]);
1316 reg_r(gspca_dev, 0x00, 1); /* get sonix chip id */
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001317 regF1 = gspca_dev->usb_buf[0];
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001318 PDEBUG(D_PROBE, "Sonix chip id: %02x", regF1);
Hans de Goede3647fea2008-07-15 05:36:30 -03001319 switch (sd->bridge) {
1320 case BRIDGE_SN9C102P:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001321 if (regF1 != 0x11)
1322 return -ENODEV;
Jean-Francois Moine60017612008-07-18 08:46:19 -03001323 reg_w1(gspca_dev, 0x02, regGpio[1]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001324 break;
Hans de Goede3647fea2008-07-15 05:36:30 -03001325 case BRIDGE_SN9C105:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001326 if (regF1 != 0x11)
1327 return -ENODEV;
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001328 if (sd->sensor == SENSOR_MI0360)
1329 mi0360_probe(gspca_dev);
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001330 reg_w(gspca_dev, 0x01, regGpio, 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001331 break;
Hans de Goede3647fea2008-07-15 05:36:30 -03001332 case BRIDGE_SN9C120:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001333 if (regF1 != 0x12)
1334 return -ENODEV;
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001335 if (sd->sensor == SENSOR_MI0360)
1336 mi0360_probe(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001337 regGpio[1] = 0x70;
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001338 reg_w(gspca_dev, 0x01, regGpio, 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001339 break;
1340 default:
Jean-Francois Moine60017612008-07-18 08:46:19 -03001341/* case BRIDGE_SN9C110: */
Hans de Goede3647fea2008-07-15 05:36:30 -03001342/* case BRIDGE_SN9C325: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001343 if (regF1 != 0x12)
1344 return -ENODEV;
Jean-Francois Moine60017612008-07-18 08:46:19 -03001345 reg_w1(gspca_dev, 0x02, 0x62);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001346 break;
1347 }
1348
Jean-Francois Moine759aa3c2008-09-03 16:48:03 -03001349 reg_w1(gspca_dev, 0xf1, 0x01);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001350
1351 return 0;
1352}
1353
Jean-Francois Moine98819182009-01-19 07:37:33 -03001354static u32 setexposure(struct gspca_dev *gspca_dev,
1355 u32 expo)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001356{
1357 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001358
1359 switch (sd->sensor) {
1360 case SENSOR_HV7131R: {
Jean-Francois Moine98819182009-01-19 07:37:33 -03001361 u8 Expodoit[] =
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001362 { 0xc1, 0x11, 0x25, 0x07, 0x27, 0xc0, 0x00, 0x16 };
1363
1364 Expodoit[3] = expo >> 16;
1365 Expodoit[4] = expo >> 8;
1366 Expodoit[5] = expo;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001367 i2c_w8(gspca_dev, Expodoit);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001368 break;
1369 }
1370 case SENSOR_MI0360: {
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001371 u8 expoMi[] = /* exposure 0x0635 -> 4 fp/s 0x10 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001372 { 0xb1, 0x5d, 0x09, 0x06, 0x35, 0x00, 0x00, 0x16 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001373 static const u8 doit[] = /* update sensor */
1374 { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
1375 static const u8 sensorgo[] = /* sensor on */
1376 { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001377
1378 if (expo > 0x0635)
1379 expo = 0x0635;
1380 else if (expo < 0x0001)
1381 expo = 0x0001;
1382 expoMi[3] = expo >> 8;
1383 expoMi[4] = expo;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001384 i2c_w8(gspca_dev, expoMi);
1385 i2c_w8(gspca_dev, doit);
1386 i2c_w8(gspca_dev, sensorgo);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001387 break;
1388 }
1389 case SENSOR_MO4000: {
Jean-Francois Moine98819182009-01-19 07:37:33 -03001390 u8 expoMof[] =
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001391 { 0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001392 u8 expoMo10[] =
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001393 { 0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001394 static const u8 gainMo[] =
1395 { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001396
1397 if (expo > 0x1fff)
1398 expo = 0x1fff;
1399 else if (expo < 0x0001)
1400 expo = 0x0001;
1401 expoMof[3] = (expo & 0x03fc) >> 2;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001402 i2c_w8(gspca_dev, expoMof);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001403 expoMo10[3] = ((expo & 0x1c00) >> 10)
1404 | ((expo & 0x0003) << 4);
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001405 i2c_w8(gspca_dev, expoMo10);
1406 i2c_w8(gspca_dev, gainMo);
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001407 PDEBUG(D_FRAM, "set exposure %d",
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001408 ((expoMo10[3] & 0x07) << 10)
1409 | (expoMof[3] << 2)
1410 | ((expoMo10[3] & 0x30) >> 4));
1411 break;
1412 }
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001413 case SENSOR_MT9V111: {
1414 u8 expo_c1[] =
1415 { 0xb1, 0x5c, 0x09, 0x00, 0x00, 0x00, 0x00, 0x10 };
1416
1417 if (expo > 0x0280)
1418 expo = 0x0280;
1419 else if (expo < 0x0040)
1420 expo = 0x0040;
1421 expo_c1[3] = expo >> 8;
1422 expo_c1[4] = expo;
1423 i2c_w8(gspca_dev, expo_c1);
1424 break;
1425 }
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001426 case SENSOR_OM6802: {
Jean-Francois Moine98819182009-01-19 07:37:33 -03001427 u8 gainOm[] =
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001428 { 0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10 };
1429
1430 if (expo > 0x03ff)
1431 expo = 0x03ff;
1432 if (expo < 0x0001)
1433 expo = 0x0001;
1434 gainOm[3] = expo >> 2;
1435 i2c_w8(gspca_dev, gainOm);
Jean-Francois Moined55b83d2008-09-03 16:48:01 -03001436 reg_w1(gspca_dev, 0x96, (expo >> 5) & 0x1f);
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001437 PDEBUG(D_FRAM, "set exposure %d", gainOm[3]);
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001438 break;
1439 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001440 }
1441 return expo;
1442}
1443
1444static void setbrightness(struct gspca_dev *gspca_dev)
1445{
1446 struct sd *sd = (struct sd *) gspca_dev;
1447 unsigned int expo;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001448 u8 k2;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001449
Jean-Francois Moineb1b056a2008-11-25 04:47:09 -03001450 k2 = ((int) sd->brightness - 0x8000) >> 10;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001451 switch (sd->sensor) {
1452 case SENSOR_HV7131R:
1453 expo = sd->brightness << 4;
1454 if (expo > 0x002dc6c0)
1455 expo = 0x002dc6c0;
1456 else if (expo < 0x02a0)
1457 expo = 0x02a0;
1458 sd->exposure = setexposure(gspca_dev, expo);
1459 break;
1460 case SENSOR_MI0360:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001461 case SENSOR_MO4000:
1462 expo = sd->brightness >> 4;
1463 sd->exposure = setexposure(gspca_dev, expo);
1464 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001465 case SENSOR_MT9V111:
1466 expo = sd->brightness >> 8;
1467 sd->exposure = setexposure(gspca_dev, expo);
1468 break;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001469 case SENSOR_OM6802:
1470 expo = sd->brightness >> 6;
1471 sd->exposure = setexposure(gspca_dev, expo);
Jean-Francois Moineb1b056a2008-11-25 04:47:09 -03001472 k2 = sd->brightness >> 11;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001473 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001474 }
1475
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001476 if (sd->sensor != SENSOR_MT9V111)
1477 reg_w1(gspca_dev, 0x96, k2); /* color matrix Y offset */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001478}
1479
1480static void setcontrast(struct gspca_dev *gspca_dev)
1481{
1482 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001483 u8 k2;
1484 u8 contrast[6];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001485
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03001486 k2 = sd->contrast * 0x30 / (CONTRAST_MAX + 1) + 0x10; /* 10..40 */
1487 contrast[0] = (k2 + 1) / 2; /* red */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -03001488 contrast[1] = 0;
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03001489 contrast[2] = k2; /* green */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -03001490 contrast[3] = 0;
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03001491 contrast[4] = (k2 + 1) / 5; /* blue */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -03001492 contrast[5] = 0;
1493 reg_w(gspca_dev, 0x84, contrast, sizeof contrast);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001494}
1495
1496static void setcolors(struct gspca_dev *gspca_dev)
1497{
1498 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001499 int i, v;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001500 u8 reg8a[12]; /* U & V gains */
1501 static s16 uv[6] = { /* same as reg84 in signed decimal */
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001502 -24, -38, 64, /* UR UG UB */
1503 62, -51, -9 /* VR VG VB */
1504 };
1505 for (i = 0; i < 6; i++) {
1506 v = uv[i] * sd->colors / COLOR_DEF;
Jean-Francois Moinebd088832008-12-02 06:58:57 -03001507 reg8a[i * 2] = v;
1508 reg8a[i * 2 + 1] = (v >> 8) & 0x0f;
Jean-Francois Moined55b83d2008-09-03 16:48:01 -03001509 }
Jean-Francois Moinebd088832008-12-02 06:58:57 -03001510 reg_w(gspca_dev, 0x8a, reg8a, sizeof reg8a);
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001511}
1512
1513static void setredblue(struct gspca_dev *gspca_dev)
1514{
1515 struct sd *sd = (struct sd *) gspca_dev;
1516
1517 reg_w1(gspca_dev, 0x05, sd->red);
Jean-Francois Moine9c5f70f2008-09-03 16:48:04 -03001518/* reg_w1(gspca_dev, 0x07, 32); */
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001519 reg_w1(gspca_dev, 0x06, sd->blue);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001520}
1521
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03001522static void setgamma(struct gspca_dev *gspca_dev)
1523{
1524 struct sd *sd = (struct sd *) gspca_dev;
1525 int i;
1526 u8 gamma[17];
Jean-Francois Moineb083b922009-02-01 14:20:07 -03001527 const u8 *gamma_base;
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03001528 static const u8 delta[17] = {
1529 0x00, 0x14, 0x1c, 0x1c, 0x1c, 0x1c, 0x1b, 0x1a,
1530 0x18, 0x13, 0x10, 0x0e, 0x08, 0x07, 0x04, 0x02, 0x00
1531 };
1532
Jean-Francois Moineb083b922009-02-01 14:20:07 -03001533 switch (sd->sensor) {
1534 case SENSOR_HV7131R:
1535 case SENSOR_MT9V111:
1536 gamma_base = gamma_spec_1;
1537 break;
1538 case SENSOR_SP80708:
1539 gamma_base = gamma_spec_2;
1540 break;
1541 default:
1542 gamma_base = gamma_def;
1543 break;
1544 }
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001545
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03001546 for (i = 0; i < sizeof gamma; i++)
Jean-Francois Moineb083b922009-02-01 14:20:07 -03001547 gamma[i] = gamma_base[i]
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03001548 + delta[i] * (sd->gamma - GAMMA_DEF) / 32;
1549 reg_w(gspca_dev, 0x20, gamma, sizeof gamma);
1550}
1551
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001552static void setautogain(struct gspca_dev *gspca_dev)
1553{
1554 struct sd *sd = (struct sd *) gspca_dev;
1555
Jean-Francois Moinef50ba1b2008-09-03 17:12:14 -03001556 if (gspca_dev->ctrl_dis & (1 << AUTOGAIN_IDX))
1557 return;
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03001558 switch (sd->sensor) {
1559 case SENSOR_OV7630:
1560 case SENSOR_OV7648: {
1561 u8 comb;
1562
1563 if (sd->sensor == SENSOR_OV7630)
1564 comb = 0xc0;
1565 else
1566 comb = 0xa0;
1567 if (sd->autogain)
1568 comb |= 0x02;
1569 i2c_w1(&sd->gspca_dev, 0x13, comb);
1570 return;
1571 }
1572 }
Jean-Francois Moinef50ba1b2008-09-03 17:12:14 -03001573 if (sd->autogain)
1574 sd->ag_cnt = AG_CNT_START;
1575 else
1576 sd->ag_cnt = -1;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001577}
1578
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03001579/* ov7630/ov7648 only */
Jean-Francois Moine6c862742008-09-08 04:57:26 -03001580static void setvflip(struct sd *sd)
1581{
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03001582 u8 comn;
1583
1584 if (sd->sensor == SENSOR_OV7630)
1585 comn = 0x02;
1586 else
1587 comn = 0x06;
1588 if (sd->vflip)
1589 comn |= 0x80;
1590 i2c_w1(&sd->gspca_dev, 0x75, comn);
Jean-Francois Moine6c862742008-09-08 04:57:26 -03001591}
1592
Jean-Francois Moine0cae8962008-10-17 07:48:24 -03001593static void setinfrared(struct sd *sd)
1594{
1595/*fixme: different sequence for StarCam Clip and StarCam 370i */
1596/* Clip */
1597 i2c_w1(&sd->gspca_dev, 0x02, /* gpio */
1598 sd->infrared ? 0x66 : 0x64);
1599}
1600
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03001601static void setjpegqual(struct gspca_dev *gspca_dev)
1602{
1603 struct sd *sd = (struct sd *) gspca_dev;
1604 int i, sc;
1605
1606 if (sd->jpegqual < 50)
1607 sc = 5000 / sd->jpegqual;
1608 else
1609 sc = 200 - sd->jpegqual * 2;
1610#if USB_BUF_SZ < 64
1611#error "No room enough in usb_buf for quantization table"
1612#endif
1613 for (i = 0; i < 64; i++)
1614 gspca_dev->usb_buf[i] =
1615 (jpeg_head[JPEG_QT0_OFFSET + i] * sc + 50) / 100;
1616 usb_control_msg(gspca_dev->dev,
1617 usb_sndctrlpipe(gspca_dev->dev, 0),
1618 0x08,
1619 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1620 0x0100, 0,
1621 gspca_dev->usb_buf, 64,
1622 500);
1623 for (i = 0; i < 64; i++)
1624 gspca_dev->usb_buf[i] =
1625 (jpeg_head[JPEG_QT1_OFFSET + i] * sc + 50) / 100;
1626 usb_control_msg(gspca_dev->dev,
1627 usb_sndctrlpipe(gspca_dev->dev, 0),
1628 0x08,
1629 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1630 0x0140, 0,
1631 gspca_dev->usb_buf, 64,
1632 500);
1633
1634 sd->reg18 ^= 0x40;
1635 reg_w1(gspca_dev, 0x18, sd->reg18);
1636}
1637
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001638/* -- start the camera -- */
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03001639static int sd_start(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001640{
1641 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001642 int i;
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03001643 u8 reg1, reg17;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001644 const u8 *sn9c1xx;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001645 int mode;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001646 static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
1647 static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
1648 static const u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */
1649 static const u8 CE_ov76xx[] =
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001650 { 0x32, 0xdd, 0x32, 0xdd };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001651
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03001652 /* create the JPEG header */
1653 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
1654 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
1655 0x21); /* JPEG 422 */
1656 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
1657
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001658 sn9c1xx = sn_tb[(int) sd->sensor];
1659 configure_gpio(gspca_dev, sn9c1xx);
1660
Jean-Francois Moine60017612008-07-18 08:46:19 -03001661 reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]);
1662 reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]);
1663 reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
1664 reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]);
1665 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
1666 reg_w1(gspca_dev, 0xd2, 0x6a); /* DC29 */
1667 reg_w1(gspca_dev, 0xd3, 0x50);
1668 reg_w1(gspca_dev, 0xc6, 0x00);
1669 reg_w1(gspca_dev, 0xc7, 0x00);
1670 reg_w1(gspca_dev, 0xc8, 0x50);
1671 reg_w1(gspca_dev, 0xc9, 0x3c);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001672 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001673 switch (sd->sensor) {
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001674 case SENSOR_MT9V111:
1675 reg17 = 0xe0;
1676 break;
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001677 case SENSOR_OV7630:
1678 reg17 = 0xe2;
1679 break;
1680 case SENSOR_OV7648:
Jean-Francois Moine62703302008-11-11 08:42:56 -03001681 reg17 = 0x20;
Jean-Francois Moine568788a2008-07-15 11:46:06 -03001682 break;
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001683/*jfm: from win trace */
1684 case SENSOR_OV7660:
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001685 if (sd->bridge == BRIDGE_SN9C120) {
1686 reg17 = 0xa0;
1687 break;
1688 }
1689 /* fall thru */
Jean-Francois Moine568788a2008-07-15 11:46:06 -03001690 default:
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001691 reg17 = 0x60;
Jean-Francois Moine568788a2008-07-15 11:46:06 -03001692 break;
1693 }
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001694 reg_w1(gspca_dev, 0x17, reg17);
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001695/* set reg1 was here */
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001696 reg_w1(gspca_dev, 0x05, sn9c1xx[5]); /* red */
1697 reg_w1(gspca_dev, 0x07, sn9c1xx[7]); /* green */
1698 reg_w1(gspca_dev, 0x06, sn9c1xx[6]); /* blue */
Jean-Francois Moine60017612008-07-18 08:46:19 -03001699 reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
Jean-Francois Moineb083b922009-02-01 14:20:07 -03001700
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001701 setgamma(gspca_dev);
1702
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001703 for (i = 0; i < 8; i++)
1704 reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001705 switch (sd->sensor) {
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001706 case SENSOR_MT9V111:
1707 reg_w1(gspca_dev, 0x9a, 0x07);
1708 reg_w1(gspca_dev, 0x99, 0x59);
1709 break;
Jean-Francois Moine62703302008-11-11 08:42:56 -03001710 case SENSOR_OV7648:
1711 reg_w1(gspca_dev, 0x9a, 0x0a);
1712 reg_w1(gspca_dev, 0x99, 0x60);
1713 break;
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001714 case SENSOR_SP80708:
1715 reg_w1(gspca_dev, 0x9a, 0x05);
1716 reg_w1(gspca_dev, 0x99, 0x59);
1717 break;
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001718 case SENSOR_OV7660:
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001719 if (sd->bridge == BRIDGE_SN9C120) {
1720 reg_w1(gspca_dev, 0x9a, 0x05);
1721 break;
1722 }
1723 /* fall thru */
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001724 default:
Jean-Francois Moine60017612008-07-18 08:46:19 -03001725 reg_w1(gspca_dev, 0x9a, 0x08);
1726 reg_w1(gspca_dev, 0x99, 0x59);
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001727 break;
1728 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001729
Jean-Francois Moinec2446b32008-07-05 11:49:20 -03001730 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
Jean-Francois Moine60017612008-07-18 08:46:19 -03001731 if (mode)
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001732 reg1 = 0x46; /* 320x240: clk 48Mhz, video trf enable */
Jean-Francois Moine60017612008-07-18 08:46:19 -03001733 else
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001734 reg1 = 0x06; /* 640x480: clk 24Mhz, video trf enable */
1735 reg17 = 0x61; /* 0x:20: enable sensor clock */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001736 switch (sd->sensor) {
1737 case SENSOR_HV7131R:
1738 hv7131R_InitSensor(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001739 break;
1740 case SENSOR_MI0360:
1741 mi0360_InitSensor(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001742 break;
1743 case SENSOR_MO4000:
1744 mo4000_InitSensor(gspca_dev);
1745 if (mode) {
1746/* reg1 = 0x46; * 320 clk 48Mhz 60fp/s */
1747 reg1 = 0x06; /* clk 24Mz */
1748 } else {
1749 reg17 = 0x22; /* 640 MCKSIZE */
Jean-Francois Moine60017612008-07-18 08:46:19 -03001750/* reg1 = 0x06; * 640 clk 24Mz (done) */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001751 }
1752 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001753 case SENSOR_MT9V111:
1754 mt9v111_InitSensor(gspca_dev);
1755 if (mode) {
1756 reg1 = 0x04; /* 320 clk 48Mhz */
1757 } else {
1758/* reg1 = 0x06; * 640 clk 24Mz (done) */
Jean-Francois Moine2687a2f2009-02-01 14:48:55 -03001759 reg17 = 0xc2;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001760 }
Jean-Francois Moine0fbe0572009-01-30 12:14:02 -03001761 break;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001762 case SENSOR_OM6802:
1763 om6802_InitSensor(gspca_dev);
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001764 reg17 = 0x64; /* 640 MCKSIZE */
1765 break;
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001766 case SENSOR_OV7630:
1767 ov7630_InitSensor(gspca_dev);
Jean-Francois Moine6c862742008-09-08 04:57:26 -03001768 setvflip(sd);
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001769 reg17 = 0xe2;
Jean-Francois Moine5b064da2008-09-03 16:48:08 -03001770 reg1 = 0x44;
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001771 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001772 case SENSOR_OV7648:
Jean-Francois Moine60017612008-07-18 08:46:19 -03001773 ov7648_InitSensor(gspca_dev);
Jean-Francois Moine62703302008-11-11 08:42:56 -03001774 reg17 = 0x21;
1775/* reg1 = 0x42; * 42 - 46? */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001776 break;
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001777 case SENSOR_OV7660:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001778 ov7660_InitSensor(gspca_dev);
Jean-Francois Moinedaa5cb42008-12-02 15:00:57 -03001779 if (sd->bridge == BRIDGE_SN9C120) {
1780 if (mode) { /* 320x240 - 160x120 */
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001781 reg17 = 0xa2;
1782 reg1 = 0x44; /* 48 Mhz, video trf eneble */
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001783 }
Jean-Francois Moinedaa5cb42008-12-02 15:00:57 -03001784 } else {
1785 reg17 = 0x22;
1786 reg1 = 0x06; /* 24 Mhz, video trf eneble
1787 * inverse power down */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001788 }
1789 break;
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001790 default:
1791/* case SENSOR_SP80708: */
1792 sp80708_InitSensor(gspca_dev);
1793 if (mode) {
1794/*?? reg1 = 0x04; * 320 clk 48Mhz */
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001795 } else {
1796 reg1 = 0x46; /* 640 clk 48Mz */
1797 reg17 = 0xa2;
1798 }
1799 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001800 }
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001801 reg_w(gspca_dev, 0xc0, C0, 6);
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001802 reg_w(gspca_dev, 0xca, CA, 4);
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001803 switch (sd->sensor) {
1804 case SENSOR_OV7630:
1805 case SENSOR_OV7648:
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001806 case SENSOR_OV7660:
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001807 reg_w(gspca_dev, 0xce, CE_ov76xx, 4);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001808 break;
1809 default:
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001810 reg_w(gspca_dev, 0xce, CE, 4);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001811 /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */
1812 break;
1813 }
1814
1815 /* here change size mode 0 -> VGA; 1 -> CIF */
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03001816 sd->reg18 = sn9c1xx[0x18] | (mode << 4) | 0x40;
1817 reg_w1(gspca_dev, 0x18, sd->reg18);
1818 setjpegqual(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001819
Jean-Francois Moine60017612008-07-18 08:46:19 -03001820 reg_w1(gspca_dev, 0x17, reg17);
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001821 reg_w1(gspca_dev, 0x01, reg1);
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001822 switch (sd->sensor) {
Jean-Francois Moine79a90982008-10-05 04:21:24 -03001823 case SENSOR_OV7630:
1824 setvflip(sd);
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001825 break;
1826 }
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03001827 setbrightness(gspca_dev);
1828 setcontrast(gspca_dev);
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001829 setautogain(gspca_dev);
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03001830 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001831}
1832
1833static void sd_stopN(struct gspca_dev *gspca_dev)
1834{
1835 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001836 static const u8 stophv7131[] =
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001837 { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001838 static const u8 stopmi0360[] =
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001839 { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001840 static const u8 stopov7648[] =
Jean-Francois Moine62703302008-11-11 08:42:56 -03001841 { 0xa1, 0x21, 0x76, 0x20, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001842 u8 data;
1843 const u8 *sn9c1xx;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001844
1845 data = 0x0b;
1846 switch (sd->sensor) {
1847 case SENSOR_HV7131R:
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001848 i2c_w8(gspca_dev, stophv7131);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001849 data = 0x2b;
1850 break;
1851 case SENSOR_MI0360:
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001852 i2c_w8(gspca_dev, stopmi0360);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001853 data = 0x29;
1854 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001855 case SENSOR_OV7648:
Jean-Francois Moine62703302008-11-11 08:42:56 -03001856 i2c_w8(gspca_dev, stopov7648);
1857 /* fall thru */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001858 case SENSOR_MT9V111:
Jean-Francois Moine62703302008-11-11 08:42:56 -03001859 case SENSOR_OV7630:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001860 data = 0x29;
1861 break;
1862 default:
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001863/* case SENSOR_MO4000: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001864/* case SENSOR_OV7660: */
1865 break;
1866 }
1867 sn9c1xx = sn_tb[(int) sd->sensor];
Jean-Francois Moine60017612008-07-18 08:46:19 -03001868 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
1869 reg_w1(gspca_dev, 0x17, sn9c1xx[0x17]);
1870 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
1871 reg_w1(gspca_dev, 0x01, data);
Jean-Francois Moine759aa3c2008-09-03 16:48:03 -03001872 reg_w1(gspca_dev, 0xf1, 0x00);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001873}
1874
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03001875static void sd_stop0(struct gspca_dev *gspca_dev)
1876{
1877 struct sd *sd = (struct sd *) gspca_dev;
1878
1879 kfree(sd->jpeg_hdr);
1880}
1881
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001882static void do_autogain(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001883{
1884 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001885 int delta;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001886 int expotimes;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001887 u8 luma_mean = 130;
1888 u8 luma_delta = 20;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001889
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001890 /* Thanks S., without your advice, autobright should not work :) */
1891 if (sd->ag_cnt < 0)
1892 return;
1893 if (--sd->ag_cnt >= 0)
1894 return;
1895 sd->ag_cnt = AG_CNT_START;
1896
1897 delta = atomic_read(&sd->avg_lum);
1898 PDEBUG(D_FRAM, "mean lum %d", delta);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001899 if (delta < luma_mean - luma_delta ||
1900 delta > luma_mean + luma_delta) {
1901 switch (sd->sensor) {
1902 case SENSOR_HV7131R:
1903 expotimes = sd->exposure >> 8;
1904 expotimes += (luma_mean - delta) >> 4;
1905 if (expotimes < 0)
1906 expotimes = 0;
1907 sd->exposure = setexposure(gspca_dev,
1908 (unsigned int) (expotimes << 8));
1909 break;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001910 default:
1911/* case SENSOR_MO4000: */
1912/* case SENSOR_MI0360: */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001913/* case SENSOR_MT9V111: */
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001914/* case SENSOR_OM6802: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001915 expotimes = sd->exposure;
1916 expotimes += (luma_mean - delta) >> 6;
1917 if (expotimes < 0)
1918 expotimes = 0;
1919 sd->exposure = setexposure(gspca_dev,
1920 (unsigned int) expotimes);
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001921 setredblue(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001922 break;
1923 }
1924 }
1925}
1926
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001927/* scan the URB packets */
1928/* This function is run at interrupt level. */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001929static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1930 struct gspca_frame *frame, /* target */
Jean-Francois Moine98819182009-01-19 07:37:33 -03001931 u8 *data, /* isoc packet */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001932 int len) /* iso packet length */
1933{
1934 struct sd *sd = (struct sd *) gspca_dev;
1935 int sof, avg_lum;
1936
1937 sof = len - 64;
1938 if (sof >= 0 && data[sof] == 0xff && data[sof + 1] == 0xd9) {
1939
1940 /* end of frame */
1941 gspca_frame_add(gspca_dev, LAST_PACKET,
1942 frame, data, sof + 2);
1943 if (sd->ag_cnt < 0)
1944 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001945/* w1 w2 w3 */
1946/* w4 w5 w6 */
1947/* w7 w8 */
1948/* w4 */
1949 avg_lum = ((data[sof + 29] << 8) | data[sof + 30]) >> 6;
1950/* w6 */
1951 avg_lum += ((data[sof + 33] << 8) | data[sof + 34]) >> 6;
1952/* w2 */
1953 avg_lum += ((data[sof + 25] << 8) | data[sof + 26]) >> 6;
1954/* w8 */
1955 avg_lum += ((data[sof + 37] << 8) | data[sof + 38]) >> 6;
1956/* w5 */
1957 avg_lum += ((data[sof + 31] << 8) | data[sof + 32]) >> 4;
1958 avg_lum >>= 4;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001959 atomic_set(&sd->avg_lum, avg_lum);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001960 return;
1961 }
1962 if (gspca_dev->last_packet_type == LAST_PACKET) {
1963
1964 /* put the JPEG 422 header */
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03001965 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
1966 sd->jpeg_hdr, JPEG_HDR_SZ);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001967 }
1968 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
1969}
1970
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001971static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
1972{
1973 struct sd *sd = (struct sd *) gspca_dev;
1974
1975 sd->brightness = val;
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03001976 if (gspca_dev->streaming)
1977 setbrightness(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001978 return 0;
1979}
1980
1981static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
1982{
1983 struct sd *sd = (struct sd *) gspca_dev;
1984
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001985 *val = sd->brightness;
1986 return 0;
1987}
1988
1989static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
1990{
1991 struct sd *sd = (struct sd *) gspca_dev;
1992
1993 sd->contrast = val;
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03001994 if (gspca_dev->streaming)
1995 setcontrast(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001996 return 0;
1997}
1998
1999static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
2000{
2001 struct sd *sd = (struct sd *) gspca_dev;
2002
2003 *val = sd->contrast;
2004 return 0;
2005}
2006
2007static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
2008{
2009 struct sd *sd = (struct sd *) gspca_dev;
2010
2011 sd->colors = val;
2012 if (gspca_dev->streaming)
2013 setcolors(gspca_dev);
2014 return 0;
2015}
2016
2017static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
2018{
2019 struct sd *sd = (struct sd *) gspca_dev;
2020
2021 *val = sd->colors;
2022 return 0;
2023}
2024
Jean-Francois Moine403123d2008-11-26 04:46:15 -03002025static int sd_setblue_balance(struct gspca_dev *gspca_dev, __s32 val)
2026{
2027 struct sd *sd = (struct sd *) gspca_dev;
2028
2029 sd->blue = val;
2030 if (gspca_dev->streaming)
2031 setredblue(gspca_dev);
2032 return 0;
2033}
2034
2035static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val)
2036{
2037 struct sd *sd = (struct sd *) gspca_dev;
2038
2039 *val = sd->blue;
2040 return 0;
2041}
2042
2043static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val)
2044{
2045 struct sd *sd = (struct sd *) gspca_dev;
2046
2047 sd->red = val;
2048 if (gspca_dev->streaming)
2049 setredblue(gspca_dev);
2050 return 0;
2051}
2052
2053static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val)
2054{
2055 struct sd *sd = (struct sd *) gspca_dev;
2056
2057 *val = sd->red;
2058 return 0;
2059}
2060
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03002061static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val)
2062{
2063 struct sd *sd = (struct sd *) gspca_dev;
2064
2065 sd->gamma = val;
2066 if (gspca_dev->streaming)
2067 setgamma(gspca_dev);
2068 return 0;
2069}
2070
2071static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val)
2072{
2073 struct sd *sd = (struct sd *) gspca_dev;
2074
2075 *val = sd->gamma;
2076 return 0;
2077}
2078
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002079static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
2080{
2081 struct sd *sd = (struct sd *) gspca_dev;
2082
2083 sd->autogain = val;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002084 if (gspca_dev->streaming)
2085 setautogain(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002086 return 0;
2087}
2088
2089static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
2090{
2091 struct sd *sd = (struct sd *) gspca_dev;
2092
2093 *val = sd->autogain;
2094 return 0;
2095}
2096
Jean-Francois Moine6c862742008-09-08 04:57:26 -03002097static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
2098{
2099 struct sd *sd = (struct sd *) gspca_dev;
2100
2101 sd->vflip = val;
Jean-Francois Moine79a90982008-10-05 04:21:24 -03002102 if (gspca_dev->streaming)
2103 setvflip(sd);
Jean-Francois Moine6c862742008-09-08 04:57:26 -03002104 return 0;
2105}
2106
2107static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
2108{
2109 struct sd *sd = (struct sd *) gspca_dev;
2110
2111 *val = sd->vflip;
2112 return 0;
2113}
2114
Jean-Francois Moine0cae8962008-10-17 07:48:24 -03002115static int sd_setinfrared(struct gspca_dev *gspca_dev, __s32 val)
2116{
2117 struct sd *sd = (struct sd *) gspca_dev;
2118
2119 sd->infrared = val;
2120 if (gspca_dev->streaming)
2121 setinfrared(sd);
2122 return 0;
2123}
2124
2125static int sd_getinfrared(struct gspca_dev *gspca_dev, __s32 *val)
2126{
2127 struct sd *sd = (struct sd *) gspca_dev;
2128
2129 *val = sd->infrared;
2130 return 0;
2131}
2132
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002133/* sub-driver description */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002134static const struct sd_desc sd_desc = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002135 .name = MODULE_NAME,
2136 .ctrls = sd_ctrls,
2137 .nctrls = ARRAY_SIZE(sd_ctrls),
2138 .config = sd_config,
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03002139 .init = sd_init,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002140 .start = sd_start,
2141 .stopN = sd_stopN,
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03002142 .stop0 = sd_stop0,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002143 .pkt_scan = sd_pkt_scan,
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002144 .dq_callback = do_autogain,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002145};
2146
2147/* -- module initialisation -- */
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002148#define BSI(bridge, sensor, i2c_addr) \
2149 .driver_info = (BRIDGE_ ## bridge << 16) \
2150 | (SENSOR_ ## sensor << 8) \
2151 | (i2c_addr)
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002152static const __devinitdata struct usb_device_id device_table[] = {
Hans de Goede222a07f2008-09-03 17:12:20 -03002153#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002154 {USB_DEVICE(0x0458, 0x7025), BSI(SN9C120, MI0360, 0x5d)},
Jean-Francois Moine7b537392008-09-07 11:56:49 -03002155 {USB_DEVICE(0x0458, 0x702e), BSI(SN9C120, OV7660, 0x21)},
Jean-Francois Moinea08d81a2008-11-22 04:53:31 -03002156#endif
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002157 {USB_DEVICE(0x045e, 0x00f5), BSI(SN9C105, OV7660, 0x21)},
2158 {USB_DEVICE(0x045e, 0x00f7), BSI(SN9C105, OV7660, 0x21)},
Jean-Francois Moinea08d81a2008-11-22 04:53:31 -03002159#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002160 {USB_DEVICE(0x0471, 0x0327), BSI(SN9C105, MI0360, 0x5d)},
Jean-Francois Moinec41492c2008-07-07 08:31:16 -03002161#endif
Jean-Francois Moine7e21fda2008-11-10 04:45:51 -03002162 {USB_DEVICE(0x0471, 0x0328), BSI(SN9C105, MI0360, 0x5d)},
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002163 {USB_DEVICE(0x0471, 0x0330), BSI(SN9C105, MI0360, 0x5d)},
Jean-Francois Moine3319dc92008-12-01 14:44:02 -03002164 {USB_DEVICE(0x06f8, 0x3004), BSI(SN9C105, OV7660, 0x21)},
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002165 {USB_DEVICE(0x0c45, 0x6040), BSI(SN9C102P, HV7131R, 0x11)},
2166/* bw600.inf:
2167 {USB_DEVICE(0x0c45, 0x6040), BSI(SN9C102P, MI0360, 0x5d)}, */
2168/* {USB_DEVICE(0x0c45, 0x603a), BSI(SN9C102P, OV7648, 0x??)}, */
2169/* {USB_DEVICE(0x0c45, 0x607a), BSI(SN9C102P, OV7648, 0x??)}, */
2170 {USB_DEVICE(0x0c45, 0x607c), BSI(SN9C102P, HV7131R, 0x11)},
2171/* {USB_DEVICE(0x0c45, 0x607e), BSI(SN9C102P, OV7630, 0x??)}, */
Jean-Francois Moine661ab252009-01-29 16:03:19 -03002172 {USB_DEVICE(0x0c45, 0x60c0), BSI(SN9C105, MI0360, 0x5d)},
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002173/* {USB_DEVICE(0x0c45, 0x60c8), BSI(SN9C105, OM6801, 0x??)}, */
2174/* {USB_DEVICE(0x0c45, 0x60cc), BSI(SN9C105, HV7131GP, 0x??)}, */
2175 {USB_DEVICE(0x0c45, 0x60ec), BSI(SN9C105, MO4000, 0x21)},
2176/* {USB_DEVICE(0x0c45, 0x60ef), BSI(SN9C105, ICM105C, 0x??)}, */
2177/* {USB_DEVICE(0x0c45, 0x60fa), BSI(SN9C105, OV7648, 0x??)}, */
2178 {USB_DEVICE(0x0c45, 0x60fb), BSI(SN9C105, OV7660, 0x21)},
2179 {USB_DEVICE(0x0c45, 0x60fc), BSI(SN9C105, HV7131R, 0x11)},
Jean-Francois Moine3c41cb72008-09-10 02:57:09 -03002180#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
2181 {USB_DEVICE(0x0c45, 0x60fe), BSI(SN9C105, OV7630, 0x21)},
2182#endif
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002183/* {USB_DEVICE(0x0c45, 0x6108), BSI(SN9C120, OM6801, 0x??)}, */
2184/* {USB_DEVICE(0x0c45, 0x6122), BSI(SN9C110, ICM105C, 0x??)}, */
2185/* {USB_DEVICE(0x0c45, 0x6123), BSI(SN9C110, SanyoCCD, 0x??)}, */
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03002186 {USB_DEVICE(0x0c45, 0x6128), BSI(SN9C110, OM6802, 0x21)}, /*sn9c325?*/
2187/*bw600.inf:*/
Jean-Francois Moine62703302008-11-11 08:42:56 -03002188 {USB_DEVICE(0x0c45, 0x612a), BSI(SN9C120, OV7648, 0x21)}, /*sn9c110?*/
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002189 {USB_DEVICE(0x0c45, 0x612c), BSI(SN9C110, MO4000, 0x21)},
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03002190 {USB_DEVICE(0x0c45, 0x612e), BSI(SN9C110, OV7630, 0x21)},
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002191/* {USB_DEVICE(0x0c45, 0x612f), BSI(SN9C110, ICM105C, 0x??)}, */
Hans de Goede222a07f2008-09-03 17:12:20 -03002192#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002193 {USB_DEVICE(0x0c45, 0x6130), BSI(SN9C120, MI0360, 0x5d)},
Hans de Goede222a07f2008-09-03 17:12:20 -03002194#endif
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002195 {USB_DEVICE(0x0c45, 0x6138), BSI(SN9C120, MO4000, 0x21)},
Jean-Francois Moine821ced22008-11-11 07:10:11 -03002196 {USB_DEVICE(0x0c45, 0x613a), BSI(SN9C120, OV7648, 0x21)},
Hans de Goede222a07f2008-09-03 17:12:20 -03002197#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002198 {USB_DEVICE(0x0c45, 0x613b), BSI(SN9C120, OV7660, 0x21)},
Jean-Francois Moine8d977702009-02-19 15:34:48 -03002199#endif
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002200 {USB_DEVICE(0x0c45, 0x613c), BSI(SN9C120, HV7131R, 0x11)},
2201/* {USB_DEVICE(0x0c45, 0x613e), BSI(SN9C120, OV7630, 0x??)}, */
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03002202 {USB_DEVICE(0x0c45, 0x6143), BSI(SN9C120, SP80708, 0x18)},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002203 {}
2204};
2205MODULE_DEVICE_TABLE(usb, device_table);
2206
2207/* -- device connect -- */
2208static int sd_probe(struct usb_interface *intf,
2209 const struct usb_device_id *id)
2210{
2211 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
2212 THIS_MODULE);
2213}
2214
2215static struct usb_driver sd_driver = {
2216 .name = MODULE_NAME,
2217 .id_table = device_table,
2218 .probe = sd_probe,
2219 .disconnect = gspca_disconnect,
Jean-Francois Moine6a709742008-09-03 16:48:10 -03002220#ifdef CONFIG_PM
2221 .suspend = gspca_suspend,
2222 .resume = gspca_resume,
2223#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002224};
2225
2226/* -- module insert / remove -- */
2227static int __init sd_mod_init(void)
2228{
Alexey Klimovf69e9522009-01-01 13:02:07 -03002229 int ret;
2230 ret = usb_register(&sd_driver);
2231 if (ret < 0)
Alexey Klimove6b14842009-01-01 13:04:58 -03002232 return ret;
Jean-Francois Moine10b0e962008-07-22 05:35:10 -03002233 info("registered");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002234 return 0;
2235}
2236static void __exit sd_mod_exit(void)
2237{
2238 usb_deregister(&sd_driver);
2239 info("deregistered");
2240}
2241
2242module_init(sd_mod_init);
2243module_exit(sd_mod_exit);