blob: 282c707e5e812cea1bad5deb0af2076a60becb77 [file] [log] [blame]
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001/*
Jean-Francois Moine5b34e3e2009-11-02 10:00:48 -03002 * Sonix sn9c102p sn9c105 sn9c120 (jpeg) subdriver
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03003 *
Jean-Francois Moine5b34e3e2009-11-02 10:00:48 -03004 * Copyright (C) 2009 Jean-Francois Moine <http://moinejf.free.fr>
5 * Copyright (C) 2005 Michel Xhaard mxhaard@magic.fr
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22#define MODULE_NAME "sonixj"
23
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 */
Hans de Goede37c6dbe2009-06-18 07:35:36 -030049 u8 freq; /* ov76xx only */
Jean-Francois Moine71cb2762009-03-03 05:33:41 -030050 u8 quality; /* image quality */
Jean-Francois Moine77ac0ba2009-03-02 06:40:52 -030051#define QUALITY_MIN 60
52#define QUALITY_MAX 95
53#define QUALITY_DEF 80
Jean-Francois Moine71cb2762009-03-03 05:33:41 -030054 u8 jpegqual; /* webcam quality */
55
56 u8 reg18;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030057
Jean-Francois Moine98819182009-01-19 07:37:33 -030058 s8 ag_cnt;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030059#define AG_CNT_START 13
60
Jean-Francois Moine98819182009-01-19 07:37:33 -030061 u8 bridge;
Hans de Goede3647fea2008-07-15 05:36:30 -030062#define BRIDGE_SN9C102P 0
63#define BRIDGE_SN9C105 1
64#define BRIDGE_SN9C110 2
65#define BRIDGE_SN9C120 3
Jean-Francois Moine98819182009-01-19 07:37:33 -030066 u8 sensor; /* Type of image sensor chip */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030067#define SENSOR_HV7131R 0
68#define SENSOR_MI0360 1
69#define SENSOR_MO4000 2
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -030070#define SENSOR_MT9V111 3
71#define SENSOR_OM6802 4
72#define SENSOR_OV7630 5
73#define SENSOR_OV7648 6
74#define SENSOR_OV7660 7
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -030075#define SENSOR_SP80708 8
Jean-Francois Moined5aa3852009-11-07 06:10:08 -030076 u8 i2c_addr;
Jean-Francois Moine71cb2762009-03-03 05:33:41 -030077
78 u8 *jpeg_hdr;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030079};
80
81/* V4L2 controls supported by the driver */
82static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
83static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
84static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
85static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
86static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
87static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine403123d2008-11-26 04:46:15 -030088static int sd_setblue_balance(struct gspca_dev *gspca_dev, __s32 val);
89static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val);
90static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val);
91static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -030092static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val);
93static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030094static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
95static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine6c862742008-09-08 04:57:26 -030096static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
97static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine0cae8962008-10-17 07:48:24 -030098static int sd_setinfrared(struct gspca_dev *gspca_dev, __s32 val);
99static int sd_getinfrared(struct gspca_dev *gspca_dev, __s32 *val);
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300100static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
101static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300102
103static struct ctrl sd_ctrls[] = {
Hans de Goede97643982009-06-18 05:08:11 -0300104#define BRIGHTNESS_IDX 0
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300105 {
106 {
107 .id = V4L2_CID_BRIGHTNESS,
108 .type = V4L2_CTRL_TYPE_INTEGER,
109 .name = "Brightness",
110 .minimum = 0,
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300111#define BRIGHTNESS_MAX 0xffff
112 .maximum = BRIGHTNESS_MAX,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300113 .step = 1,
Jean-Francois Moineb1b056a2008-11-25 04:47:09 -0300114#define BRIGHTNESS_DEF 0x8000
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300115 .default_value = BRIGHTNESS_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300116 },
117 .set = sd_setbrightness,
118 .get = sd_getbrightness,
119 },
Hans de Goede97643982009-06-18 05:08:11 -0300120#define CONTRAST_IDX 1
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300121 {
122 {
123 .id = V4L2_CID_CONTRAST,
124 .type = V4L2_CTRL_TYPE_INTEGER,
125 .name = "Contrast",
126 .minimum = 0,
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300127#define CONTRAST_MAX 127
128 .maximum = CONTRAST_MAX,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300129 .step = 1,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300130#define CONTRAST_DEF 63
131 .default_value = CONTRAST_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300132 },
133 .set = sd_setcontrast,
134 .get = sd_getcontrast,
135 },
Hans de Goede97643982009-06-18 05:08:11 -0300136#define COLOR_IDX 2
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300137 {
138 {
139 .id = V4L2_CID_SATURATION,
140 .type = V4L2_CTRL_TYPE_INTEGER,
Hans de Goede3fb4a572009-06-18 14:31:36 -0300141 .name = "Saturation",
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300142 .minimum = 0,
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300143 .maximum = 40,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300144 .step = 1,
Hans de Goede3fb4a572009-06-18 14:31:36 -0300145#define COLOR_DEF 25
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300146 .default_value = COLOR_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300147 },
148 .set = sd_setcolors,
149 .get = sd_getcolors,
150 },
Hans de Goede97643982009-06-18 05:08:11 -0300151#define BLUE_BALANCE_IDX 3
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300152 {
153 {
154 .id = V4L2_CID_BLUE_BALANCE,
155 .type = V4L2_CTRL_TYPE_INTEGER,
156 .name = "Blue Balance",
157 .minimum = 24,
158 .maximum = 40,
159 .step = 1,
160#define BLUE_BALANCE_DEF 32
161 .default_value = BLUE_BALANCE_DEF,
162 },
163 .set = sd_setblue_balance,
164 .get = sd_getblue_balance,
165 },
Hans de Goede97643982009-06-18 05:08:11 -0300166#define RED_BALANCE_IDX 4
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300167 {
168 {
169 .id = V4L2_CID_RED_BALANCE,
170 .type = V4L2_CTRL_TYPE_INTEGER,
171 .name = "Red Balance",
172 .minimum = 24,
173 .maximum = 40,
174 .step = 1,
175#define RED_BALANCE_DEF 32
176 .default_value = RED_BALANCE_DEF,
177 },
178 .set = sd_setred_balance,
179 .get = sd_getred_balance,
180 },
Hans de Goede97643982009-06-18 05:08:11 -0300181#define GAMMA_IDX 5
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -0300182 {
183 {
184 .id = V4L2_CID_GAMMA,
185 .type = V4L2_CTRL_TYPE_INTEGER,
186 .name = "Gamma",
187 .minimum = 0,
188 .maximum = 40,
189 .step = 1,
190#define GAMMA_DEF 20
191 .default_value = GAMMA_DEF,
192 },
193 .set = sd_setgamma,
194 .get = sd_getgamma,
195 },
Hans de Goede97643982009-06-18 05:08:11 -0300196#define AUTOGAIN_IDX 6
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300197 {
198 {
199 .id = V4L2_CID_AUTOGAIN,
200 .type = V4L2_CTRL_TYPE_BOOLEAN,
201 .name = "Auto Gain",
202 .minimum = 0,
203 .maximum = 1,
204 .step = 1,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300205#define AUTOGAIN_DEF 1
206 .default_value = AUTOGAIN_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300207 },
208 .set = sd_setautogain,
209 .get = sd_getautogain,
210 },
Jean-Francois Moine2797ba22009-02-05 15:12:24 -0300211/* ov7630/ov7648 only */
Hans de Goede97643982009-06-18 05:08:11 -0300212#define VFLIP_IDX 7
Jean-Francois Moine6c862742008-09-08 04:57:26 -0300213 {
214 {
215 .id = V4L2_CID_VFLIP,
216 .type = V4L2_CTRL_TYPE_BOOLEAN,
217 .name = "Vflip",
218 .minimum = 0,
219 .maximum = 1,
220 .step = 1,
Hans de Goedef8009522009-06-18 14:29:20 -0300221#define VFLIP_DEF 0
Jean-Francois Moine6c862742008-09-08 04:57:26 -0300222 .default_value = VFLIP_DEF,
223 },
224 .set = sd_setvflip,
225 .get = sd_getvflip,
226 },
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300227/* mt9v111 only */
Hans de Goede97643982009-06-18 05:08:11 -0300228#define INFRARED_IDX 8
Jean-Francois Moine0cae8962008-10-17 07:48:24 -0300229 {
230 {
231 .id = V4L2_CID_INFRARED,
232 .type = V4L2_CTRL_TYPE_BOOLEAN,
233 .name = "Infrared",
234 .minimum = 0,
235 .maximum = 1,
236 .step = 1,
237#define INFRARED_DEF 0
238 .default_value = INFRARED_DEF,
239 },
240 .set = sd_setinfrared,
241 .get = sd_getinfrared,
242 },
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300243/* ov7630/ov7648/ov7660 only */
244#define FREQ_IDX 9
245 {
246 {
247 .id = V4L2_CID_POWER_LINE_FREQUENCY,
248 .type = V4L2_CTRL_TYPE_MENU,
249 .name = "Light frequency filter",
250 .minimum = 0,
251 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
252 .step = 1,
253#define FREQ_DEF 2
254 .default_value = FREQ_DEF,
255 },
256 .set = sd_setfreq,
257 .get = sd_getfreq,
258 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300259};
260
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300261/* table of the disabled controls */
262static __u32 ctrl_dis[] = {
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300263 (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300264 /* SENSOR_HV7131R 0 */
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300265 (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300266 /* SENSOR_MI0360 1 */
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300267 (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300268 /* SENSOR_MO4000 2 */
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300269 (1 << VFLIP_IDX) | (1 << FREQ_IDX),
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300270 /* SENSOR_MT9V111 3 */
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300271 (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300272 /* SENSOR_OM6802 4 */
Hans de Goede1fec7472009-06-18 06:05:07 -0300273 (1 << INFRARED_IDX),
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300274 /* SENSOR_OV7630 5 */
Jean-Francois Moine2797ba22009-02-05 15:12:24 -0300275 (1 << INFRARED_IDX),
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300276 /* SENSOR_OV7648 6 */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300277 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300278 /* SENSOR_OV7660 7 */
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300279 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX) |
280 (1 << FREQ_IDX), /* SENSOR_SP80708 8 */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300281};
282
Jean-Francois Moinecc611b82008-12-29 07:49:41 -0300283static const struct v4l2_pix_format vga_mode[] = {
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300284 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
285 .bytesperline = 160,
Jean-Francois Moine5d052942008-09-03 16:48:09 -0300286 .sizeimage = 160 * 120 * 4 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300287 .colorspace = V4L2_COLORSPACE_JPEG,
288 .priv = 2},
289 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
290 .bytesperline = 320,
291 .sizeimage = 320 * 240 * 3 / 8 + 590,
292 .colorspace = V4L2_COLORSPACE_JPEG,
293 .priv = 1},
294 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
295 .bytesperline = 640,
Hans de Goedea5d1cc32009-06-18 06:03:20 -0300296 /* Note 3 / 8 is not large enough, not even 5 / 8 is ?! */
297 .sizeimage = 640 * 480 * 3 / 4 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300298 .colorspace = V4L2_COLORSPACE_JPEG,
299 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300300};
301
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300302/*Data from sn9c102p+hv7131r */
303static const u8 sn_hv7131[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300304/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
305 0x00, 0x03, 0x64, 0x00, 0x1a, 0x20, 0x20, 0x20,
306/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300307 0x81, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300308/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
309 0x03, 0x00, 0x00, 0x01, 0x03, 0x28, 0x1e, 0x41,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300310/* reg18 reg19 reg1a reg1b */
311 0x0a, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300312};
313
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300314static const u8 sn_mi0360[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300315/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
316 0x00, 0x61, 0x44, 0x00, 0x1a, 0x20, 0x20, 0x20,
317/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300318 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300319/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
320 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x61,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300321/* reg18 reg19 reg1a reg1b */
322 0x06, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300323};
324
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300325static const u8 sn_mo4000[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300326/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300327 0x00, 0x23, 0x60, 0x00, 0x1a, 0x00, 0x20, 0x18,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300328/* reg8 reg9 rega regb regc regd rege regf */
329 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
330/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
331 0x03, 0x00, 0x0b, 0x0f, 0x14, 0x28, 0x1e, 0x40,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300332/* reg18 reg19 reg1a reg1b */
333 0x08, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300334};
335
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300336static const u8 sn_mt9v111[0x1c] = {
337/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
338 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
339/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300340 0x81, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300341/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
342 0x03, 0x00, 0x00, 0x02, 0x1c, 0x28, 0x1e, 0x40,
343/* reg18 reg19 reg1a reg1b */
344 0x06, 0x00, 0x00, 0x00
345};
346
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300347static const u8 sn_om6802[0x1c] = {
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300348/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Amauri Magagna46b4f2a2009-10-17 07:21:29 -0300349 0x00, 0x23, 0x72, 0x00, 0x1a, 0x20, 0x20, 0x19,
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300350/* reg8 reg9 rega regb regc regd rege regf */
351 0x80, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
352/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
353 0x03, 0x00, 0x51, 0x01, 0x00, 0x28, 0x1e, 0x40,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300354/* reg18 reg19 reg1a reg1b */
355 0x05, 0x00, 0x00, 0x00
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300356};
357
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300358static const u8 sn_ov7630[0x1c] = {
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300359/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
360 0x00, 0x21, 0x40, 0x00, 0x1a, 0x20, 0x1f, 0x20,
361/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300362 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300363/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
364 0x03, 0x00, 0x04, 0x01, 0x0a, 0x28, 0x1e, 0xc2,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300365/* reg18 reg19 reg1a reg1b */
366 0x0b, 0x00, 0x00, 0x00
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300367};
368
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300369static const u8 sn_ov7648[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300370/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Jean-Francois Moine62703302008-11-11 08:42:56 -0300371 0x00, 0x63, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300372/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300373 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300374/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
Jean-Francois Moine62703302008-11-11 08:42:56 -0300375 0x03, 0x00, 0x00, 0x01, 0x00, 0x28, 0x1e, 0x00,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300376/* reg18 reg19 reg1a reg1b */
377 0x0b, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300378};
379
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300380static const u8 sn_ov7660[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300381/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -0300382 0x00, 0x61, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300383/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -0300384 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300385/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
386 0x03, 0x00, 0x01, 0x01, 0x08, 0x28, 0x1e, 0x20,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300387/* reg18 reg19 reg1a reg1b */
388 0x07, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300389};
390
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -0300391static const u8 sn_sp80708[0x1c] = {
392/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
393 0x00, 0x63, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
394/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300395 0x81, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -0300396/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
397 0x03, 0x00, 0x00, 0x03, 0x04, 0x28, 0x1e, 0x00,
398/* reg18 reg19 reg1a reg1b */
399 0x07, 0x00, 0x00, 0x00
400};
401
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300402/* sequence specific to the sensors - !! index = SENSOR_xxx */
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300403static const u8 *sn_tb[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300404 sn_hv7131,
405 sn_mi0360,
406 sn_mo4000,
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300407 sn_mt9v111,
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300408 sn_om6802,
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300409 sn_ov7630,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300410 sn_ov7648,
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -0300411 sn_ov7660,
412 sn_sp80708
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300413};
414
Jean-Francois Moineb083b922009-02-01 14:20:07 -0300415/* default gamma table */
Jean-Francois Moine98819182009-01-19 07:37:33 -0300416static const u8 gamma_def[17] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300417 0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99,
418 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
419};
Jean-Francois Moineb083b922009-02-01 14:20:07 -0300420/* gamma for sensors HV7131R and MT9V111 */
421static const u8 gamma_spec_1[17] = {
422 0x08, 0x3a, 0x52, 0x65, 0x75, 0x83, 0x91, 0x9d,
423 0xa9, 0xb4, 0xbe, 0xc8, 0xd2, 0xdb, 0xe4, 0xed, 0xf5
424};
425/* gamma for sensor SP80708 */
426static const u8 gamma_spec_2[17] = {
427 0x0a, 0x2d, 0x4e, 0x68, 0x7d, 0x8f, 0x9f, 0xab,
428 0xb7, 0xc2, 0xcc, 0xd3, 0xd8, 0xde, 0xe2, 0xe5, 0xe6
429};
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -0300430
Jean-Francois Moine803f9cc2008-10-04 14:17:02 -0300431/* color matrix and offsets */
Jean-Francois Moine98819182009-01-19 07:37:33 -0300432static const u8 reg84[] = {
Jean-Francois Moine803f9cc2008-10-04 14:17:02 -0300433 0x14, 0x00, 0x27, 0x00, 0x07, 0x00, /* YR YG YB gains */
434 0xe8, 0x0f, 0xda, 0x0f, 0x40, 0x00, /* UR UG UB */
435 0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f, /* VR VG VB */
436 0x00, 0x00, 0x00 /* YUV offsets */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300437};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300438static const u8 hv7131r_sensor_init[][8] = {
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300439 {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
440 {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10},
441 {0xd1, 0x11, 0x40, 0xff, 0x7f, 0x7f, 0x7f, 0x10},
442/* {0x91, 0x11, 0x44, 0x00, 0x00, 0x00, 0x00, 0x10}, */
443 {0xd1, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
444 {0xd1, 0x11, 0x14, 0x01, 0xe2, 0x02, 0x82, 0x10},
445/* {0x91, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10}, */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300446
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300447 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
448 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
449 {0xc1, 0x11, 0x25, 0x00, 0x61, 0xa8, 0x00, 0x10},
450 {0xa1, 0x11, 0x30, 0x22, 0x00, 0x00, 0x00, 0x10},
451 {0xc1, 0x11, 0x31, 0x20, 0x2e, 0x20, 0x00, 0x10},
452 {0xc1, 0x11, 0x25, 0x00, 0xc3, 0x50, 0x00, 0x10},
453 {0xa1, 0x11, 0x30, 0x07, 0x00, 0x00, 0x00, 0x10}, /* gain14 */
454 {0xc1, 0x11, 0x31, 0x10, 0x10, 0x10, 0x00, 0x10}, /* r g b 101a10 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300455
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300456 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
457 {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -0300458 {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300459 {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
460 {0xa1, 0x11, 0x23, 0x09, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300461
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300462 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
463 {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
464 {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
465 {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
466 {0xa1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300467 {0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10},
468 /* set sensor clock */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300469 {}
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300470};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300471static const u8 mi0360_sensor_init[][8] = {
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300472 {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
Jean-Francois Moine98819182009-01-19 07:37:33 -0300473 {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300474 {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300475 {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
476 {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
477 {0xd1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x53, 0x10},
478 {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
479 {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
480 {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
481 {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
482 {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
483 {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
484 {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
485 {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
486 {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
487 {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
488 {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
489 {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
490 {0xd1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
491 {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
492 {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
493 {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
Jean-Francois Moine98819182009-01-19 07:37:33 -0300494 {0xd1, 0x5d, 0x2f, 0xf7, 0xB0, 0x00, 0x04, 0x10},
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300495 {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
496 {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
497 {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
498 {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
499 {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
500 {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
501 {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
502 {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
503 {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
504 {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300505
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300506 {0xb1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
507 {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
508 {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
509 {0xd1, 0x5d, 0x2b, 0x00, 0xa0, 0x00, 0xb0, 0x10},
510 {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0xa0, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300511
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300512 {0xb1, 0x5d, 0x0a, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor clck ?2 */
513 {0xb1, 0x5d, 0x06, 0x00, 0x30, 0x00, 0x00, 0x10},
514 {0xb1, 0x5d, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10},
515 {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300516
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300517 {0xd1, 0x5d, 0x2b, 0x00, 0xb9, 0x00, 0xe3, 0x10},
518 {0xd1, 0x5d, 0x2d, 0x00, 0x5f, 0x00, 0xb9, 0x10}, /* 42 */
519/* {0xb1, 0x5d, 0x35, 0x00, 0x67, 0x00, 0x00, 0x10}, * gain orig */
520/* {0xb1, 0x5d, 0x35, 0x00, 0x20, 0x00, 0x00, 0x10}, * gain */
521 {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
522 {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300523 {}
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300524};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300525static const u8 mo4000_sensor_init[][8] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300526 {0xa1, 0x21, 0x01, 0x02, 0x00, 0x00, 0x00, 0x10},
527 {0xa1, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10},
528 {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
529 {0xa1, 0x21, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
530 {0xa1, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
531 {0xa1, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x10},
532 {0xa1, 0x21, 0x06, 0x80, 0x00, 0x00, 0x00, 0x10},
533 {0xa1, 0x21, 0x06, 0x81, 0x00, 0x00, 0x00, 0x10},
534 {0xa1, 0x21, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
535 {0xa1, 0x21, 0x11, 0x00, 0x00, 0x00, 0x00, 0x10},
536 {0xa1, 0x21, 0x11, 0x20, 0x00, 0x00, 0x00, 0x10},
537 {0xa1, 0x21, 0x11, 0x30, 0x00, 0x00, 0x00, 0x10},
538 {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
539 {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
540 {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
541 {0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
542 {0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10},
543 {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10},
544 {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
545 {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300546 {}
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300547};
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300548static const u8 mt9v111_sensor_init[][8] = {
549 {0xb1, 0x5c, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10}, /* reset? */
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300550 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300551 {0xb1, 0x5c, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
552 {0xb1, 0x5c, 0x01, 0x00, 0x01, 0x00, 0x00, 0x10}, /* IFP select */
553 {0xb1, 0x5c, 0x08, 0x04, 0x80, 0x00, 0x00, 0x10}, /* output fmt ctrl */
554 {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10}, /* op mode ctrl */
Jean-Francois Moine2687a2f2009-02-01 14:48:55 -0300555 {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
556 {0xb1, 0x5c, 0x03, 0x01, 0xe1, 0x00, 0x00, 0x10},
557 {0xb1, 0x5c, 0x04, 0x02, 0x81, 0x00, 0x00, 0x10},
558 {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300559 {0xb1, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10}, /* sensor select */
Jean-Francois Moine2687a2f2009-02-01 14:48:55 -0300560 {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
561 {0xb1, 0x5c, 0x03, 0x01, 0xe6, 0x00, 0x00, 0x10},
562 {0xb1, 0x5c, 0x04, 0x02, 0x86, 0x00, 0x00, 0x10},
563 {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
564 {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300565 {0xb1, 0x5c, 0x08, 0x00, 0x08, 0x00, 0x00, 0x10}, /* row start */
Jean-Francois Moine2687a2f2009-02-01 14:48:55 -0300566 {0xb1, 0x5c, 0x0e, 0x00, 0x08, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300567 {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10}, /* col start */
568 {0xb1, 0x5c, 0x03, 0x01, 0xe7, 0x00, 0x00, 0x10}, /* window height */
569 {0xb1, 0x5c, 0x04, 0x02, 0x87, 0x00, 0x00, 0x10}, /* window width */
570 {0xb1, 0x5c, 0x07, 0x30, 0x02, 0x00, 0x00, 0x10}, /* output ctrl */
571 {0xb1, 0x5c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10}, /* shutter delay */
572 {0xb1, 0x5c, 0x12, 0x00, 0xb0, 0x00, 0x00, 0x10}, /* zoom col start */
573 {0xb1, 0x5c, 0x13, 0x00, 0x7c, 0x00, 0x00, 0x10}, /* zoom row start */
574 {0xb1, 0x5c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* digital zoom */
575 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10}, /* read mode */
576 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300577 {}
578};
579static const u8 mt9v111_sensor_param1[][8] = {
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300580 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
581 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine2687a2f2009-02-01 14:48:55 -0300582 {0xb1, 0x5c, 0x09, 0x01, 0x2c, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300583 {0xd1, 0x5c, 0x2b, 0x00, 0x33, 0x00, 0xa0, 0x10}, /* green1 gain */
584 {0xd1, 0x5c, 0x2d, 0x00, 0xa0, 0x00, 0x33, 0x10}, /* red gain */
585 /*******/
586 {0xb1, 0x5c, 0x06, 0x00, 0x1e, 0x00, 0x00, 0x10}, /* vert blanking */
587 {0xb1, 0x5c, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10}, /* horiz blanking */
588 {0xd1, 0x5c, 0x2c, 0x00, 0xad, 0x00, 0xad, 0x10}, /* blue gain */
589 {0xb1, 0x5c, 0x35, 0x01, 0xc0, 0x00, 0x00, 0x10}, /* global gain */
590 {}
591};
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300592static const u8 om6802_init0[2][8] = {
593/*fixme: variable*/
594 {0xa0, 0x34, 0x29, 0x0e, 0x00, 0x00, 0x00, 0x10},
595 {0xa0, 0x34, 0x23, 0xb0, 0x00, 0x00, 0x00, 0x10},
596};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300597static const u8 om6802_sensor_init[][8] = {
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300598 {0xa0, 0x34, 0xdf, 0x6d, 0x00, 0x00, 0x00, 0x10},
599 /* factory mode */
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300600 {0xa0, 0x34, 0xdd, 0x18, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moined5aa3852009-11-07 06:10:08 -0300601 /* output raw RGB */
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300602 {0xa0, 0x34, 0x5a, 0xc0, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300603/* {0xa0, 0x34, 0xfb, 0x11, 0x00, 0x00, 0x00, 0x10}, */
604 {0xa0, 0x34, 0xf0, 0x04, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moined5aa3852009-11-07 06:10:08 -0300605 /* auto-exposure speed (0) / white balance mode (auto RGB) */
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300606/* {0xa0, 0x34, 0xf1, 0x02, 0x00, 0x00, 0x00, 0x10},
607 * set color mode */
608/* {0xa0, 0x34, 0xfe, 0x5b, 0x00, 0x00, 0x00, 0x10},
609 * max AGC value in AE */
610/* {0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10},
611 * preset AGC */
612/* {0xa0, 0x34, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x10},
613 * preset brightness */
614/* {0xa0, 0x34, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x10},
615 * preset contrast */
616/* {0xa0, 0x34, 0xe8, 0x31, 0x00, 0x00, 0x00, 0x10},
617 * preset gamma */
618 {0xa0, 0x34, 0xe9, 0x0f, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moined5aa3852009-11-07 06:10:08 -0300619 /* luminance mode (0x4f -> AutoExpo on) */
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300620 {0xa0, 0x34, 0xe4, 0xff, 0x00, 0x00, 0x00, 0x10},
621 /* preset shutter */
622/* {0xa0, 0x34, 0xef, 0x00, 0x00, 0x00, 0x00, 0x10},
623 * auto frame rate */
624/* {0xa0, 0x34, 0xfb, 0xee, 0x00, 0x00, 0x00, 0x10}, */
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300625 {0xa0, 0x34, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
626 {}
627};
628static const u8 om6802_sensor_param1[][8] = {
629 {0xa0, 0x34, 0x71, 0x84, 0x00, 0x00, 0x00, 0x10},
630 {0xa0, 0x34, 0x72, 0x05, 0x00, 0x00, 0x00, 0x10},
631 {0xa0, 0x34, 0x68, 0x80, 0x00, 0x00, 0x00, 0x10},
632 {0xa0, 0x34, 0x69, 0x01, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300633 {}
634};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300635static const u8 ov7630_sensor_init[][8] = {
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300636 {0xa1, 0x21, 0x76, 0x01, 0x00, 0x00, 0x00, 0x10},
637 {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300638 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300639 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
640 {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300641 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300642 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300643/* win: i2c_r from 00 to 80 */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300644 {0xd1, 0x21, 0x03, 0x80, 0x10, 0x20, 0x80, 0x10},
645 {0xb1, 0x21, 0x0c, 0x20, 0x20, 0x00, 0x00, 0x10},
Hans de Goedecc7b5b52009-06-18 05:14:42 -0300646/* HDG: 0x11 was 0x00 change to 0x01 for better exposure (15 fps instead of 30)
647 0x13 was 0xc0 change to 0xc3 for auto gain and exposure */
648 {0xd1, 0x21, 0x11, 0x01, 0x48, 0xc3, 0x00, 0x10},
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300649 {0xb1, 0x21, 0x15, 0x80, 0x03, 0x00, 0x00, 0x10},
650 {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
651 {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
652 {0xd1, 0x21, 0x1f, 0x00, 0x80, 0x80, 0x80, 0x10},
653 {0xd1, 0x21, 0x23, 0xde, 0x10, 0x8a, 0xa0, 0x10},
654 {0xc1, 0x21, 0x27, 0xca, 0xa2, 0x74, 0x00, 0x10},
655 {0xd1, 0x21, 0x2a, 0x88, 0x00, 0x88, 0x01, 0x10},
656 {0xc1, 0x21, 0x2e, 0x80, 0x00, 0x18, 0x00, 0x10},
657 {0xa1, 0x21, 0x21, 0x08, 0x00, 0x00, 0x00, 0x10},
658 {0xa1, 0x21, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
659 {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
660 {0xb1, 0x21, 0x32, 0xc2, 0x08, 0x00, 0x00, 0x10},
661 {0xb1, 0x21, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x10},
662 {0xd1, 0x21, 0x60, 0x05, 0x40, 0x12, 0x57, 0x10},
663 {0xa1, 0x21, 0x64, 0x73, 0x00, 0x00, 0x00, 0x10},
664 {0xd1, 0x21, 0x65, 0x00, 0x55, 0x01, 0xac, 0x10},
665 {0xa1, 0x21, 0x69, 0x38, 0x00, 0x00, 0x00, 0x10},
666 {0xd1, 0x21, 0x6f, 0x1f, 0x01, 0x00, 0x10, 0x10},
667 {0xd1, 0x21, 0x73, 0x50, 0x20, 0x02, 0x01, 0x10},
668 {0xd1, 0x21, 0x77, 0xf3, 0x90, 0x98, 0x98, 0x10},
669 {0xc1, 0x21, 0x7b, 0x00, 0x4c, 0xf7, 0x00, 0x10},
670 {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
671 {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
672/* */
673 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
674 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
675/*fixme: + 0x12, 0x04*/
Jean-Francois Moine6c862742008-09-08 04:57:26 -0300676/* {0xa1, 0x21, 0x75, 0x82, 0x00, 0x00, 0x00, 0x10}, * COMN
677 * set by setvflip */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300678 {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
679 {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
680 {0xb1, 0x21, 0x01, 0x80, 0x80, 0x00, 0x00, 0x10},
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300681/* */
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300682/* {0xa1, 0x21, 0x2a, 0x88, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
683/* {0xa1, 0x21, 0x2b, 0x34, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300684/* */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300685 {0xa1, 0x21, 0x10, 0x83, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine91de65a2008-09-03 17:12:18 -0300686/* {0xb1, 0x21, 0x01, 0x88, 0x70, 0x00, 0x00, 0x10}, */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300687 {}
688};
Jean-Francois Moine62703302008-11-11 08:42:56 -0300689
Jean-Francois Moine98819182009-01-19 07:37:33 -0300690static const u8 ov7648_sensor_init[][8] = {
Jean-Francois Moine62703302008-11-11 08:42:56 -0300691 {0xa1, 0x21, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10},
692 {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300693 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moine62703302008-11-11 08:42:56 -0300694 {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
695 {0xd1, 0x21, 0x03, 0xa4, 0x30, 0x88, 0x00, 0x10},
696 {0xb1, 0x21, 0x11, 0x80, 0x08, 0x00, 0x00, 0x10},
697 {0xc1, 0x21, 0x13, 0xa0, 0x04, 0x84, 0x00, 0x10},
698 {0xd1, 0x21, 0x17, 0x1a, 0x02, 0xba, 0xf4, 0x10},
699 {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
700 {0xd1, 0x21, 0x1f, 0x41, 0xc0, 0x80, 0x80, 0x10},
701 {0xd1, 0x21, 0x23, 0xde, 0xa0, 0x80, 0x32, 0x10},
702 {0xd1, 0x21, 0x27, 0xfe, 0xa0, 0x00, 0x91, 0x10},
703 {0xd1, 0x21, 0x2b, 0x00, 0x88, 0x85, 0x80, 0x10},
704 {0xc1, 0x21, 0x2f, 0x9c, 0x00, 0xc4, 0x00, 0x10},
705 {0xd1, 0x21, 0x60, 0xa6, 0x60, 0x88, 0x12, 0x10},
706 {0xd1, 0x21, 0x64, 0x88, 0x00, 0x00, 0x94, 0x10},
707 {0xd1, 0x21, 0x68, 0x7a, 0x0c, 0x00, 0x00, 0x10},
708 {0xd1, 0x21, 0x6c, 0x11, 0x33, 0x22, 0x00, 0x10},
709 {0xd1, 0x21, 0x70, 0x11, 0x00, 0x10, 0x50, 0x10},
710 {0xd1, 0x21, 0x74, 0x20, 0x06, 0x00, 0xb5, 0x10},
711 {0xd1, 0x21, 0x78, 0x8a, 0x00, 0x00, 0x00, 0x10},
712 {0xb1, 0x21, 0x7c, 0x00, 0x43, 0x00, 0x00, 0x10},
713
714 {0xd1, 0x21, 0x21, 0x86, 0x00, 0xde, 0xa0, 0x10},
715/* {0xd1, 0x21, 0x25, 0x80, 0x32, 0xfe, 0xa0, 0x10}, jfm done */
716/* {0xd1, 0x21, 0x29, 0x00, 0x91, 0x00, 0x88, 0x10}, jfm done */
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300717/* {0xb1, 0x21, 0x2d, 0x85, 0x00, 0x00, 0x00, 0x10}, set by setfreq */
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300718 {}
719};
720static const u8 ov7648_sensor_param1[][8] = {
Jean-Francois Moine62703302008-11-11 08:42:56 -0300721/* {0xa1, 0x21, 0x12, 0x08, 0x00, 0x00, 0x00, 0x10}, jfm done */
Jean-Francois Moine2797ba22009-02-05 15:12:24 -0300722/* {0xa1, 0x21, 0x75, 0x06, 0x00, 0x00, 0x00, 0x10}, * COMN
723 * set by setvflip */
Jean-Francois Moine62703302008-11-11 08:42:56 -0300724 {0xa1, 0x21, 0x19, 0x02, 0x00, 0x00, 0x00, 0x10},
725 {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
726/* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
727/* {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}, * GAIN - def */
728/* {0xb1, 0x21, 0x01, 0x6c, 0x6c, 0x00, 0x00, 0x10}, * B R - def: 80 */
729/*...*/
730 {0xa1, 0x21, 0x11, 0x81, 0x00, 0x00, 0x00, 0x10}, /* CLKRC */
731/* {0xa1, 0x21, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
732/* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
733/* {0xa1, 0x21, 0x2a, 0x91, 0x00, 0x00, 0x00, 0x10}, jfm done */
734/* {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
735/* {0xb1, 0x21, 0x01, 0x64, 0x84, 0x00, 0x00, 0x10}, * B R - def: 80 */
736
737 {}
738};
739
Jean-Francois Moine98819182009-01-19 07:37:33 -0300740static const u8 ov7660_sensor_init[][8] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300741 {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300742 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300743 {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300744 /* Outformat = rawRGB */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300745 {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */
Jean-Francois Moined8f400e2009-07-08 06:33:44 -0300746 {0xd1, 0x21, 0x00, 0x01, 0x74, 0x92, 0x00, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300747 /* GAIN BLUE RED VREF */
748 {0xd1, 0x21, 0x04, 0x00, 0x7d, 0x62, 0x00, 0x10},
749 /* COM 1 BAVE GEAVE AECHH */
750 {0xb1, 0x21, 0x08, 0x83, 0x01, 0x00, 0x00, 0x10}, /* RAVE COM2 */
751 {0xd1, 0x21, 0x0c, 0x00, 0x08, 0x04, 0x4f, 0x10}, /* COM 3 4 5 6 */
Jean-Francois Moine47f7f6f2009-08-25 06:14:54 -0300752 {0xd1, 0x21, 0x10, 0x7f, 0x40, 0x05, 0xff, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300753 /* AECH CLKRC COM7 COM8 */
754 {0xc1, 0x21, 0x14, 0x2c, 0x00, 0x02, 0x00, 0x10}, /* COM9 COM10 */
755 {0xd1, 0x21, 0x17, 0x10, 0x60, 0x02, 0x7b, 0x10},
756 /* HSTART HSTOP VSTRT VSTOP */
757 {0xa1, 0x21, 0x1b, 0x02, 0x00, 0x00, 0x00, 0x10}, /* PSHFT */
758 {0xb1, 0x21, 0x1e, 0x01, 0x0e, 0x00, 0x00, 0x10}, /* MVFP LAEC */
759 {0xd1, 0x21, 0x20, 0x07, 0x07, 0x07, 0x07, 0x10},
760 /* BOS GBOS GROS ROS (BGGR offset) */
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300761/* {0xd1, 0x21, 0x24, 0x68, 0x58, 0xd4, 0x80, 0x10}, */
762 {0xd1, 0x21, 0x24, 0x78, 0x68, 0xd4, 0x80, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300763 /* AEW AEB VPT BBIAS */
764 {0xd1, 0x21, 0x28, 0x80, 0x30, 0x00, 0x00, 0x10},
765 /* GbBIAS RSVD EXHCH EXHCL */
766 {0xd1, 0x21, 0x2c, 0x80, 0x00, 0x00, 0x62, 0x10},
767 /* RBIAS ADVFL ASDVFH YAVE */
768 {0xc1, 0x21, 0x30, 0x08, 0x30, 0xb4, 0x00, 0x10},
769 /* HSYST HSYEN HREF */
770 {0xd1, 0x21, 0x33, 0x00, 0x07, 0x84, 0x00, 0x10}, /* reserved */
771 {0xd1, 0x21, 0x37, 0x0c, 0x02, 0x43, 0x00, 0x10},
772 /* ADC ACOM OFON TSLB */
773 {0xd1, 0x21, 0x3b, 0x02, 0x6c, 0x19, 0x0e, 0x10},
774 /* COM11 COM12 COM13 COM14 */
775 {0xd1, 0x21, 0x3f, 0x41, 0xc1, 0x22, 0x08, 0x10},
776 /* EDGE COM15 COM16 COM17 */
777 {0xd1, 0x21, 0x43, 0xf0, 0x10, 0x78, 0xa8, 0x10}, /* reserved */
778 {0xd1, 0x21, 0x47, 0x60, 0x80, 0x00, 0x00, 0x10}, /* reserved */
779 {0xd1, 0x21, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* reserved */
780 {0xd1, 0x21, 0x4f, 0x46, 0x36, 0x0f, 0x17, 0x10}, /* MTX 1 2 3 4 */
781 {0xd1, 0x21, 0x53, 0x7f, 0x96, 0x40, 0x40, 0x10}, /* MTX 5 6 7 8 */
782 {0xb1, 0x21, 0x57, 0x40, 0x0f, 0x00, 0x00, 0x10}, /* MTX9 MTXS */
783 {0xd1, 0x21, 0x59, 0xba, 0x9a, 0x22, 0xb9, 0x10}, /* reserved */
784 {0xd1, 0x21, 0x5d, 0x9b, 0x10, 0xf0, 0x05, 0x10}, /* reserved */
785 {0xa1, 0x21, 0x61, 0x60, 0x00, 0x00, 0x00, 0x10}, /* reserved */
786 {0xd1, 0x21, 0x62, 0x00, 0x00, 0x50, 0x30, 0x10},
787 /* LCC1 LCC2 LCC3 LCC4 */
788 {0xa1, 0x21, 0x66, 0x00, 0x00, 0x00, 0x00, 0x10}, /* LCC5 */
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300789 {0xd1, 0x21, 0x67, 0x80, 0x7a, 0x90, 0x80, 0x10}, /* MANU */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300790 {0xa1, 0x21, 0x6b, 0x0a, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300791 /* band gap reference [0:3] DBLV */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300792 {0xd1, 0x21, 0x6c, 0x30, 0x48, 0x80, 0x74, 0x10}, /* gamma curve */
793 {0xd1, 0x21, 0x70, 0x64, 0x60, 0x5c, 0x58, 0x10}, /* gamma curve */
794 {0xd1, 0x21, 0x74, 0x54, 0x4c, 0x40, 0x38, 0x10}, /* gamma curve */
795 {0xd1, 0x21, 0x78, 0x34, 0x30, 0x2f, 0x2b, 0x10}, /* gamma curve */
796 {0xd1, 0x21, 0x7c, 0x03, 0x07, 0x17, 0x34, 0x10}, /* gamma curve */
797 {0xd1, 0x21, 0x80, 0x41, 0x4d, 0x58, 0x63, 0x10}, /* gamma curve */
798 {0xd1, 0x21, 0x84, 0x6e, 0x77, 0x87, 0x95, 0x10}, /* gamma curve */
799 {0xc1, 0x21, 0x88, 0xaf, 0xc7, 0xdf, 0x00, 0x10}, /* gamma curve */
800 {0xc1, 0x21, 0x8b, 0x99, 0x99, 0xcf, 0x00, 0x10}, /* reserved */
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300801 {0xb1, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x10}, /* DM_LNL/H */
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300802/* not in all ms-win traces*/
Jean-Francois Moine47f7f6f2009-08-25 06:14:54 -0300803 {0xa1, 0x21, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300804 {}
805};
806static const u8 ov7660_sensor_param1[][8] = {
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300807 {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10}, /* MVFP */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300808 /* bits[3..0]reserved */
809 {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10},
810 {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
811 /* VREF vertical frame ctrl */
812 {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300813 {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10}, /* AECH 0x20 */
814 {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFL */
815 {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFH */
816 {0xa1, 0x21, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x10}, /* GAIN */
817/* {0xb1, 0x21, 0x01, 0x78, 0x78, 0x00, 0x00, 0x10}, * BLUE */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300818/****** (some exchanges in the win trace) ******/
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300819/*fixme:param2*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300820 {0xa1, 0x21, 0x93, 0x00, 0x00, 0x00, 0x00, 0x10},/* dummy line hight */
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300821 {0xa1, 0x21, 0x92, 0x25, 0x00, 0x00, 0x00, 0x10}, /* dummy line low */
822 {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCH */
823 {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCL */
824/* {0xa1, 0x21, 0x02, 0x90, 0x00, 0x00, 0x00, 0x10}, * RED */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300825/****** (some exchanges in the win trace) ******/
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300826/******!! startsensor KO if changed !!****/
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300827/*fixme: param3*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300828 {0xa1, 0x21, 0x93, 0x01, 0x00, 0x00, 0x00, 0x10},
829 {0xa1, 0x21, 0x92, 0xff, 0x00, 0x00, 0x00, 0x10},
830 {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10},
831 {0xa1, 0x21, 0x2b, 0xc3, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300832 {}
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300833};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300834
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -0300835static const u8 sp80708_sensor_init[][8] = {
836 {0xa1, 0x18, 0x06, 0xf9, 0x00, 0x00, 0x00, 0x10},
837 {0xa1, 0x18, 0x09, 0x1f, 0x00, 0x00, 0x00, 0x10},
838 {0xa1, 0x18, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
839 {0xa1, 0x18, 0x0d, 0xc0, 0x00, 0x00, 0x00, 0x10},
840 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
841 {0xa1, 0x18, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x10},
842 {0xa1, 0x18, 0x10, 0x40, 0x00, 0x00, 0x00, 0x10},
843 {0xa1, 0x18, 0x11, 0x4e, 0x00, 0x00, 0x00, 0x10},
844 {0xa1, 0x18, 0x12, 0x53, 0x00, 0x00, 0x00, 0x10},
845 {0xa1, 0x18, 0x15, 0x80, 0x00, 0x00, 0x00, 0x10},
846 {0xa1, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10},
847 {0xa1, 0x18, 0x19, 0x18, 0x00, 0x00, 0x00, 0x10},
848 {0xa1, 0x18, 0x1a, 0x10, 0x00, 0x00, 0x00, 0x10},
849 {0xa1, 0x18, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x10},
850 {0xa1, 0x18, 0x1c, 0x28, 0x00, 0x00, 0x00, 0x10},
851 {0xa1, 0x18, 0x1d, 0x02, 0x00, 0x00, 0x00, 0x10},
852 {0xa1, 0x18, 0x1e, 0x10, 0x00, 0x00, 0x00, 0x10},
853 {0xa1, 0x18, 0x26, 0x04, 0x00, 0x00, 0x00, 0x10},
854 {0xa1, 0x18, 0x27, 0x1e, 0x00, 0x00, 0x00, 0x10},
855 {0xa1, 0x18, 0x28, 0x5a, 0x00, 0x00, 0x00, 0x10},
856 {0xa1, 0x18, 0x29, 0x28, 0x00, 0x00, 0x00, 0x10},
857 {0xa1, 0x18, 0x2a, 0x78, 0x00, 0x00, 0x00, 0x10},
858 {0xa1, 0x18, 0x2b, 0x01, 0x00, 0x00, 0x00, 0x10},
859 {0xa1, 0x18, 0x2c, 0xf7, 0x00, 0x00, 0x00, 0x10},
860 {0xa1, 0x18, 0x2d, 0x2d, 0x00, 0x00, 0x00, 0x10},
861 {0xa1, 0x18, 0x2e, 0xd5, 0x00, 0x00, 0x00, 0x10},
862 {0xa1, 0x18, 0x39, 0x42, 0x00, 0x00, 0x00, 0x10},
863 {0xa1, 0x18, 0x3a, 0x67, 0x00, 0x00, 0x00, 0x10},
864 {0xa1, 0x18, 0x3b, 0x87, 0x00, 0x00, 0x00, 0x10},
865 {0xa1, 0x18, 0x3c, 0xa3, 0x00, 0x00, 0x00, 0x10},
866 {0xa1, 0x18, 0x3d, 0xb0, 0x00, 0x00, 0x00, 0x10},
867 {0xa1, 0x18, 0x3e, 0xbc, 0x00, 0x00, 0x00, 0x10},
868 {0xa1, 0x18, 0x3f, 0xc8, 0x00, 0x00, 0x00, 0x10},
869 {0xa1, 0x18, 0x40, 0xd4, 0x00, 0x00, 0x00, 0x10},
870 {0xa1, 0x18, 0x41, 0xdf, 0x00, 0x00, 0x00, 0x10},
871 {0xa1, 0x18, 0x42, 0xea, 0x00, 0x00, 0x00, 0x10},
872 {0xa1, 0x18, 0x43, 0xf5, 0x00, 0x00, 0x00, 0x10},
873 {0xa1, 0x18, 0x45, 0x80, 0x00, 0x00, 0x00, 0x10},
874 {0xa1, 0x18, 0x46, 0x60, 0x00, 0x00, 0x00, 0x10},
875 {0xa1, 0x18, 0x47, 0x50, 0x00, 0x00, 0x00, 0x10},
876 {0xa1, 0x18, 0x48, 0x30, 0x00, 0x00, 0x00, 0x10},
877 {0xa1, 0x18, 0x49, 0x01, 0x00, 0x00, 0x00, 0x10},
878 {0xa1, 0x18, 0x4d, 0xae, 0x00, 0x00, 0x00, 0x10},
879 {0xa1, 0x18, 0x4e, 0x03, 0x00, 0x00, 0x00, 0x10},
880 {0xa1, 0x18, 0x4f, 0x66, 0x00, 0x00, 0x00, 0x10},
881 {0xa1, 0x18, 0x50, 0x1c, 0x00, 0x00, 0x00, 0x10},
882 {0xa1, 0x18, 0x44, 0x10, 0x00, 0x00, 0x00, 0x10},
883 {0xa1, 0x18, 0x4a, 0x30, 0x00, 0x00, 0x00, 0x10},
884 {0xa1, 0x18, 0x51, 0x80, 0x00, 0x00, 0x00, 0x10},
885 {0xa1, 0x18, 0x52, 0x80, 0x00, 0x00, 0x00, 0x10},
886 {0xa1, 0x18, 0x53, 0x80, 0x00, 0x00, 0x00, 0x10},
887 {0xa1, 0x18, 0x54, 0x80, 0x00, 0x00, 0x00, 0x10},
888 {0xa1, 0x18, 0x55, 0x80, 0x00, 0x00, 0x00, 0x10},
889 {0xa1, 0x18, 0x56, 0x80, 0x00, 0x00, 0x00, 0x10},
890 {0xa1, 0x18, 0x57, 0xe0, 0x00, 0x00, 0x00, 0x10},
891 {0xa1, 0x18, 0x58, 0xc0, 0x00, 0x00, 0x00, 0x10},
892 {0xa1, 0x18, 0x59, 0xab, 0x00, 0x00, 0x00, 0x10},
893 {0xa1, 0x18, 0x5a, 0xa0, 0x00, 0x00, 0x00, 0x10},
894 {0xa1, 0x18, 0x5b, 0x99, 0x00, 0x00, 0x00, 0x10},
895 {0xa1, 0x18, 0x5c, 0x90, 0x00, 0x00, 0x00, 0x10},
896 {0xa1, 0x18, 0x5e, 0x24, 0x00, 0x00, 0x00, 0x10},
897 {0xa1, 0x18, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x10},
898 {0xa1, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00, 0x10},
899 {0xa1, 0x18, 0x61, 0x73, 0x00, 0x00, 0x00, 0x10},
900 {0xa1, 0x18, 0x63, 0x42, 0x00, 0x00, 0x00, 0x10},
901 {0xa1, 0x18, 0x64, 0x42, 0x00, 0x00, 0x00, 0x10},
902 {0xa1, 0x18, 0x65, 0x42, 0x00, 0x00, 0x00, 0x10},
903 {0xa1, 0x18, 0x66, 0x24, 0x00, 0x00, 0x00, 0x10},
904 {0xa1, 0x18, 0x67, 0x24, 0x00, 0x00, 0x00, 0x10},
905 {0xa1, 0x18, 0x68, 0x08, 0x00, 0x00, 0x00, 0x10},
906 {0xa1, 0x18, 0x2f, 0xc9, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300907 {}
908};
909static const u8 sp80708_sensor_param1[][8] = {
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -0300910 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
911 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
912 {0xa1, 0x18, 0x03, 0x01, 0x00, 0x00, 0x00, 0x10},
913 {0xa1, 0x18, 0x04, 0xa4, 0x00, 0x00, 0x00, 0x10},
914 {0xa1, 0x18, 0x14, 0x3f, 0x00, 0x00, 0x00, 0x10},
915 {0xa1, 0x18, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
916 {0xb1, 0x18, 0x11, 0x40, 0x40, 0x00, 0x00, 0x10},
917 {}
918};
919
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300920static const u8 (*sensor_init[9])[8] = {
921 hv7131r_sensor_init, /* HV7131R 0 */
922 mi0360_sensor_init, /* MI0360 1 */
923 mo4000_sensor_init, /* MO4000 2 */
924 mt9v111_sensor_init, /* MT9V111 3 */
925 om6802_sensor_init, /* OM6802 4 */
926 ov7630_sensor_init, /* OV7630 5 */
927 ov7648_sensor_init, /* OV7648 6 */
928 ov7660_sensor_init, /* OV7660 7 */
929 sp80708_sensor_init, /* SP80708 8 */
930};
931
Jean-Francois Moine8295d992008-09-03 17:12:19 -0300932/* read <len> bytes to gspca_dev->usb_buf */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300933static void reg_r(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -0300934 u16 value, int len)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300935{
Jean-Francois Moine8295d992008-09-03 17:12:19 -0300936#ifdef GSPCA_DEBUG
937 if (len > USB_BUF_SZ) {
938 err("reg_r: buffer overflow");
939 return;
940 }
941#endif
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300942 usb_control_msg(gspca_dev->dev,
943 usb_rcvctrlpipe(gspca_dev->dev, 0),
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300944 0,
945 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
946 value, 0,
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300947 gspca_dev->usb_buf, len,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300948 500);
Jean-Francois Moine60017612008-07-18 08:46:19 -0300949 PDEBUG(D_USBI, "reg_r [%02x] -> %02x", value, gspca_dev->usb_buf[0]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300950}
951
Jean-Francois Moine60017612008-07-18 08:46:19 -0300952static void reg_w1(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -0300953 u16 value,
954 u8 data)
Jean-Francois Moine60017612008-07-18 08:46:19 -0300955{
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300956 PDEBUG(D_USBO, "reg_w1 [%04x] = %02x", value, data);
Jean-Francois Moine60017612008-07-18 08:46:19 -0300957 gspca_dev->usb_buf[0] = data;
958 usb_control_msg(gspca_dev->dev,
959 usb_sndctrlpipe(gspca_dev->dev, 0),
960 0x08,
961 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
962 value,
963 0,
964 gspca_dev->usb_buf, 1,
965 500);
966}
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300967static void reg_w(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -0300968 u16 value,
969 const u8 *buffer,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300970 int len)
971{
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300972 PDEBUG(D_USBO, "reg_w [%04x] = %02x %02x ..",
Jean-Francois Moine60017612008-07-18 08:46:19 -0300973 value, buffer[0], buffer[1]);
Jean-Francois Moine8295d992008-09-03 17:12:19 -0300974#ifdef GSPCA_DEBUG
975 if (len > USB_BUF_SZ) {
976 err("reg_w: buffer overflow");
977 return;
Jean-Francois Moinebf7f0b92008-07-03 11:09:12 -0300978 }
Jean-Francois Moine8295d992008-09-03 17:12:19 -0300979#endif
980 memcpy(gspca_dev->usb_buf, buffer, len);
981 usb_control_msg(gspca_dev->dev,
982 usb_sndctrlpipe(gspca_dev->dev, 0),
983 0x08,
984 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
985 value, 0,
986 gspca_dev->usb_buf, len,
987 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300988}
989
Jean-Francois Moine60017612008-07-18 08:46:19 -0300990/* I2C write 1 byte */
Jean-Francois Moine98819182009-01-19 07:37:33 -0300991static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300992{
993 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300994
Jean-Francois Moine60017612008-07-18 08:46:19 -0300995 PDEBUG(D_USBO, "i2c_w2 [%02x] = %02x", reg, val);
Jean-Francois Moinea7826362009-11-02 09:21:06 -0300996 switch (sd->sensor) {
997 case SENSOR_OM6802: /* i2c command = a0 (100 kHz) */
998 gspca_dev->usb_buf[0] = 0x80 | (2 << 4);
999 break;
1000 default: /* i2c command = a1 (400 kHz) */
1001 gspca_dev->usb_buf[0] = 0x81 | (2 << 4);
1002 break;
1003 }
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001004 gspca_dev->usb_buf[1] = sd->i2c_addr;
Jean-Francois Moine60017612008-07-18 08:46:19 -03001005 gspca_dev->usb_buf[2] = reg;
1006 gspca_dev->usb_buf[3] = val;
1007 gspca_dev->usb_buf[4] = 0;
1008 gspca_dev->usb_buf[5] = 0;
1009 gspca_dev->usb_buf[6] = 0;
1010 gspca_dev->usb_buf[7] = 0x10;
1011 usb_control_msg(gspca_dev->dev,
1012 usb_sndctrlpipe(gspca_dev->dev, 0),
1013 0x08,
1014 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1015 0x08, /* value = i2c */
1016 0,
1017 gspca_dev->usb_buf, 8,
1018 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001019}
1020
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001021/* I2C write 8 bytes */
1022static void i2c_w8(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -03001023 const u8 *buffer)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001024{
Jean-Francois Moine60017612008-07-18 08:46:19 -03001025 memcpy(gspca_dev->usb_buf, buffer, 8);
1026 usb_control_msg(gspca_dev->dev,
1027 usb_sndctrlpipe(gspca_dev->dev, 0),
1028 0x08,
1029 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1030 0x08, 0, /* value, index */
1031 gspca_dev->usb_buf, 8,
1032 500);
Jean-Francois Moine8d768e12008-09-21 03:28:55 -03001033 msleep(2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001034}
1035
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001036/* read 5 bytes in gspca_dev->usb_buf */
Jean-Francois Moine98819182009-01-19 07:37:33 -03001037static void i2c_r5(struct gspca_dev *gspca_dev, u8 reg)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001038{
1039 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001040 u8 mode[8];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001041
Jean-Francois Moinea7826362009-11-02 09:21:06 -03001042 switch (sd->sensor) {
1043 case SENSOR_OM6802: /* i2c command = 90 (100 kHz) */
1044 mode[0] = 0x80 | 0x10;
1045 break;
1046 default: /* i2c command = 91 (400 kHz) */
1047 mode[0] = 0x81 | 0x10;
1048 break;
1049 }
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001050 mode[1] = sd->i2c_addr;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001051 mode[2] = reg;
1052 mode[3] = 0;
1053 mode[4] = 0;
1054 mode[5] = 0;
1055 mode[6] = 0;
1056 mode[7] = 0x10;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001057 i2c_w8(gspca_dev, mode);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001058 msleep(2);
Jean-Francois Moinea7826362009-11-02 09:21:06 -03001059 mode[0] = (mode[0] & 0x81) | (5 << 4) | 0x02;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001060 mode[2] = 0;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001061 i2c_w8(gspca_dev, mode);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001062 msleep(2);
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001063 reg_r(gspca_dev, 0x0a, 5);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001064}
1065
Jean-Francois Moine23a98272009-11-02 09:10:25 -03001066static void i2c_w_seq(struct gspca_dev *gspca_dev,
1067 const u8 (*data)[8])
1068{
1069 while ((*data)[0] != 0) {
1070 if ((*data)[0] != 0xdd)
1071 i2c_w8(gspca_dev, *data);
1072 else
1073 msleep((*data)[1]);
1074 data++;
1075 }
1076}
1077
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03001078static void hv7131r_probe(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001079{
Jean-Francois Moine60017612008-07-18 08:46:19 -03001080 i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001081 msleep(10);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001082 reg_w1(gspca_dev, 0x02, 0x66); /* Gpio on */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001083 msleep(10);
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001084 i2c_r5(gspca_dev, 0); /* read sensor id */
1085 if (gspca_dev->usb_buf[0] == 0x02
1086 && gspca_dev->usb_buf[1] == 0x09
1087 && gspca_dev->usb_buf[2] == 0x01
1088 && gspca_dev->usb_buf[3] == 0x00
1089 && gspca_dev->usb_buf[4] == 0x00) {
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03001090 PDEBUG(D_PROBE, "Sensor sn9c102P HV7131R found");
1091 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001092 }
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03001093 PDEBUG(D_PROBE, "Sensor 0x%02x 0x%02x 0x%02x - sn9c102P not found",
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001094 gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
1095 gspca_dev->usb_buf[2]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001096}
1097
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001098static void mi0360_probe(struct gspca_dev *gspca_dev)
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001099{
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001100 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001101 int i, j;
Jean-Francois Moine92e8c912009-02-02 16:25:38 -03001102 u16 val = 0;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001103 static const u8 probe_tb[][4][8] = {
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001104 { /* mi0360 */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001105 {0xb0, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
1106 {0x90, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1107 {0xa2, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1108 {0xb0, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10}
1109 },
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001110 { /* mt9v111 */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001111 {0xb0, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10},
1112 {0x90, 0x5c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x10},
1113 {0xa2, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1114 {}
1115 },
1116 };
1117
1118 for (i = 0; i < ARRAY_SIZE(probe_tb); i++) {
1119 reg_w1(gspca_dev, 0x17, 0x62);
1120 reg_w1(gspca_dev, 0x01, 0x08);
1121 for (j = 0; j < 3; j++)
1122 i2c_w8(gspca_dev, probe_tb[i][j]);
1123 msleep(2);
1124 reg_r(gspca_dev, 0x0a, 5);
1125 val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
1126 if (probe_tb[i][3][0] != 0)
1127 i2c_w8(gspca_dev, probe_tb[i][3]);
1128 reg_w1(gspca_dev, 0x01, 0x29);
1129 reg_w1(gspca_dev, 0x17, 0x42);
1130 if (val != 0xffff)
1131 break;
1132 }
1133 switch (val) {
1134 case 0x823a:
1135 PDEBUG(D_PROBE, "Sensor mt9v111");
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001136 sd->sensor = SENSOR_MT9V111;
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001137 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001138 case 0x8243:
1139 PDEBUG(D_PROBE, "Sensor mi0360");
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001140 break;
1141 default:
1142 PDEBUG(D_PROBE, "Unknown sensor %04x - forced to mi0360", val);
1143 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001144 }
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001145}
1146
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001147static void bridge_init(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -03001148 const u8 *sn9c1xx)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001149{
1150 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001151 const u8 *reg9a;
1152 static const u8 reg9a_def[] =
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03001153 {0x00, 0x40, 0x20, 0x00, 0x00, 0x00};
1154 static const u8 reg9a_spec[] =
1155 {0x00, 0x40, 0x38, 0x30, 0x00, 0x20};
Jean-Francois Moine98819182009-01-19 07:37:33 -03001156 static const u8 regd4[] = {0x60, 0x00, 0x00};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001157
Jean-Francois Moine60017612008-07-18 08:46:19 -03001158 reg_w1(gspca_dev, 0xf1, 0x00);
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001159 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001160
1161 /* configure gpio */
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001162 reg_w(gspca_dev, 0x01, &sn9c1xx[1], 2);
1163 reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001164 reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5);
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03001165 switch (sd->sensor) {
1166 case SENSOR_OV7660:
1167 case SENSOR_SP80708:
1168 reg9a = reg9a_spec;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001169 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001170 default:
1171 reg9a = reg9a_def;
1172 break;
1173 }
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001174 reg_w(gspca_dev, 0x9a, reg9a, 6);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001175
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001176 reg_w(gspca_dev, 0xd4, regd4, sizeof regd4);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001177
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001178 reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001179
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001180 switch (sd->sensor) {
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001181 case SENSOR_MT9V111:
1182 reg_w1(gspca_dev, 0x01, 0x61);
1183 reg_w1(gspca_dev, 0x17, 0x61);
1184 reg_w1(gspca_dev, 0x01, 0x60);
1185 reg_w1(gspca_dev, 0x01, 0x40);
1186 break;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001187 case SENSOR_OM6802:
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001188 msleep(10);
1189 reg_w1(gspca_dev, 0x02, 0x73);
1190 reg_w1(gspca_dev, 0x17, 0x60);
1191 reg_w1(gspca_dev, 0x01, 0x22);
1192 msleep(100);
1193 reg_w1(gspca_dev, 0x01, 0x62);
1194 reg_w1(gspca_dev, 0x17, 0x64);
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001195 reg_w1(gspca_dev, 0x17, 0x64);
1196 reg_w1(gspca_dev, 0x01, 0x42);
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001197 msleep(10);
1198 reg_w1(gspca_dev, 0x01, 0x42);
1199 i2c_w8(gspca_dev, om6802_init0[0]);
1200 i2c_w8(gspca_dev, om6802_init0[1]);
1201 msleep(15);
1202 reg_w1(gspca_dev, 0x02, 0x71);
1203 msleep(150);
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001204 break;
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001205 case SENSOR_OV7630:
1206 reg_w1(gspca_dev, 0x01, 0x61);
1207 reg_w1(gspca_dev, 0x17, 0xe2);
1208 reg_w1(gspca_dev, 0x01, 0x60);
1209 reg_w1(gspca_dev, 0x01, 0x40);
1210 break;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001211 case SENSOR_OV7648:
Jean-Francois Moine62703302008-11-11 08:42:56 -03001212 reg_w1(gspca_dev, 0x01, 0x63);
1213 reg_w1(gspca_dev, 0x17, 0x20);
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03001214 reg_w1(gspca_dev, 0x01, 0x62);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001215 reg_w1(gspca_dev, 0x01, 0x42);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001216 break;
Jean-Francois Moine91de65a2008-09-03 17:12:18 -03001217 case SENSOR_OV7660:
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001218 case SENSOR_SP80708:
1219 reg_w1(gspca_dev, 0x01, 0x63);
1220 reg_w1(gspca_dev, 0x17, 0x20);
1221 reg_w1(gspca_dev, 0x01, 0x62);
1222 reg_w1(gspca_dev, 0x01, 0x42);
Jean-Francois Moine1f78a972009-08-29 07:11:58 -03001223 msleep(100);
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001224 reg_w1(gspca_dev, 0x02, 0x62);
1225 break;
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001226 default:
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03001227/* case SENSOR_HV7131R: */
1228/* case SENSOR_MI0360: */
1229/* case SENSOR_MO4000: */
Jean-Francois Moine60017612008-07-18 08:46:19 -03001230 reg_w1(gspca_dev, 0x01, 0x43);
1231 reg_w1(gspca_dev, 0x17, 0x61);
1232 reg_w1(gspca_dev, 0x01, 0x42);
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001233 if (sd->sensor == SENSOR_HV7131R
1234 && sd->bridge == BRIDGE_SN9C102P)
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03001235 hv7131r_probe(gspca_dev);
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001236 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001237 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001238}
1239
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001240/* this function is called at probe time */
1241static int sd_config(struct gspca_dev *gspca_dev,
1242 const struct usb_device_id *id)
1243{
1244 struct sd *sd = (struct sd *) gspca_dev;
1245 struct cam *cam;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001246
1247 cam = &gspca_dev->cam;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001248 cam->cam_mode = vga_mode;
1249 cam->nmodes = ARRAY_SIZE(vga_mode);
Jean-Francois Moine49cb6b02009-04-25 13:29:01 -03001250 cam->npkt = 24; /* 24 packets per ISOC message */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001251
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03001252 sd->bridge = id->driver_info >> 16;
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001253 sd->sensor = id->driver_info;
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03001254
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001255 sd->brightness = BRIGHTNESS_DEF;
1256 sd->contrast = CONTRAST_DEF;
1257 sd->colors = COLOR_DEF;
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001258 sd->blue = BLUE_BALANCE_DEF;
1259 sd->red = RED_BALANCE_DEF;
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03001260 sd->gamma = GAMMA_DEF;
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001261 sd->autogain = AUTOGAIN_DEF;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001262 sd->ag_cnt = -1;
Hans de Goedef8009522009-06-18 14:29:20 -03001263 sd->vflip = VFLIP_DEF;
Jean-Francois Moine0cae8962008-10-17 07:48:24 -03001264 sd->infrared = INFRARED_DEF;
Hans de Goede37c6dbe2009-06-18 07:35:36 -03001265 sd->freq = FREQ_DEF;
Jean-Francois Moine77ac0ba2009-03-02 06:40:52 -03001266 sd->quality = QUALITY_DEF;
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03001267 sd->jpegqual = 80;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001268
Jean-Francois Moine577cbf42008-12-05 06:18:37 -03001269 gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001270 return 0;
1271}
1272
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03001273/* this function is called at probe and resume time */
1274static int sd_init(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001275{
1276 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001277 const u8 *sn9c1xx;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001278 u8 regGpio[] = { 0x29, 0x74 };
1279 u8 regF1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001280
Hans de Goede3647fea2008-07-15 05:36:30 -03001281 /* setup a selector by bridge */
Jean-Francois Moine60017612008-07-18 08:46:19 -03001282 reg_w1(gspca_dev, 0xf1, 0x01);
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001283 reg_r(gspca_dev, 0x00, 1);
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001284 reg_w1(gspca_dev, 0xf1, gspca_dev->usb_buf[0]);
1285 reg_r(gspca_dev, 0x00, 1); /* get sonix chip id */
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001286 regF1 = gspca_dev->usb_buf[0];
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001287 PDEBUG(D_PROBE, "Sonix chip id: %02x", regF1);
Hans de Goede3647fea2008-07-15 05:36:30 -03001288 switch (sd->bridge) {
1289 case BRIDGE_SN9C102P:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001290 if (regF1 != 0x11)
1291 return -ENODEV;
Jean-Francois Moine60017612008-07-18 08:46:19 -03001292 reg_w1(gspca_dev, 0x02, regGpio[1]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001293 break;
Hans de Goede3647fea2008-07-15 05:36:30 -03001294 case BRIDGE_SN9C105:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001295 if (regF1 != 0x11)
1296 return -ENODEV;
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001297 if (sd->sensor == SENSOR_MI0360)
1298 mi0360_probe(gspca_dev);
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001299 reg_w(gspca_dev, 0x01, regGpio, 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001300 break;
Hans de Goede3647fea2008-07-15 05:36:30 -03001301 case BRIDGE_SN9C120:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001302 if (regF1 != 0x12)
1303 return -ENODEV;
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001304 if (sd->sensor == SENSOR_MI0360)
1305 mi0360_probe(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001306 regGpio[1] = 0x70;
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001307 reg_w(gspca_dev, 0x01, regGpio, 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001308 break;
1309 default:
Jean-Francois Moine60017612008-07-18 08:46:19 -03001310/* case BRIDGE_SN9C110: */
Hans de Goede3647fea2008-07-15 05:36:30 -03001311/* case BRIDGE_SN9C325: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001312 if (regF1 != 0x12)
1313 return -ENODEV;
Jean-Francois Moine60017612008-07-18 08:46:19 -03001314 reg_w1(gspca_dev, 0x02, 0x62);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001315 break;
1316 }
1317
Jean-Francois Moine759aa3c2008-09-03 16:48:03 -03001318 reg_w1(gspca_dev, 0xf1, 0x01);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001319
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001320 /* set the i2c address */
1321 sn9c1xx = sn_tb[sd->sensor];
1322 sd->i2c_addr = sn9c1xx[9];
1323
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001324 return 0;
1325}
1326
Jean-Francois Moine98819182009-01-19 07:37:33 -03001327static u32 setexposure(struct gspca_dev *gspca_dev,
1328 u32 expo)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001329{
1330 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001331
1332 switch (sd->sensor) {
1333 case SENSOR_HV7131R: {
Jean-Francois Moine98819182009-01-19 07:37:33 -03001334 u8 Expodoit[] =
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001335 { 0xc1, 0x11, 0x25, 0x00, 0x00, 0x00, 0x00, 0x16 };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001336
1337 Expodoit[3] = expo >> 16;
1338 Expodoit[4] = expo >> 8;
1339 Expodoit[5] = expo;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001340 i2c_w8(gspca_dev, Expodoit);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001341 break;
1342 }
1343 case SENSOR_MI0360: {
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001344 u8 expoMi[] = /* exposure 0x0635 -> 4 fp/s 0x10 */
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001345 { 0xb1, 0x5d, 0x09, 0x00, 0x00, 0x00, 0x00, 0x16 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001346 static const u8 doit[] = /* update sensor */
1347 { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
1348 static const u8 sensorgo[] = /* sensor on */
1349 { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001350
1351 if (expo > 0x0635)
1352 expo = 0x0635;
1353 else if (expo < 0x0001)
1354 expo = 0x0001;
1355 expoMi[3] = expo >> 8;
1356 expoMi[4] = expo;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001357 i2c_w8(gspca_dev, expoMi);
1358 i2c_w8(gspca_dev, doit);
1359 i2c_w8(gspca_dev, sensorgo);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001360 break;
1361 }
1362 case SENSOR_MO4000: {
Jean-Francois Moine98819182009-01-19 07:37:33 -03001363 u8 expoMof[] =
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001364 { 0xa1, 0x21, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001365 u8 expoMo10[] =
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001366 { 0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001367 static const u8 gainMo[] =
1368 { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001369
1370 if (expo > 0x1fff)
1371 expo = 0x1fff;
1372 else if (expo < 0x0001)
1373 expo = 0x0001;
1374 expoMof[3] = (expo & 0x03fc) >> 2;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001375 i2c_w8(gspca_dev, expoMof);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001376 expoMo10[3] = ((expo & 0x1c00) >> 10)
1377 | ((expo & 0x0003) << 4);
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001378 i2c_w8(gspca_dev, expoMo10);
1379 i2c_w8(gspca_dev, gainMo);
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001380 PDEBUG(D_FRAM, "set exposure %d",
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001381 ((expoMo10[3] & 0x07) << 10)
1382 | (expoMof[3] << 2)
1383 | ((expoMo10[3] & 0x30) >> 4));
1384 break;
1385 }
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001386 case SENSOR_MT9V111: {
1387 u8 expo_c1[] =
1388 { 0xb1, 0x5c, 0x09, 0x00, 0x00, 0x00, 0x00, 0x10 };
1389
1390 if (expo > 0x0280)
1391 expo = 0x0280;
1392 else if (expo < 0x0040)
1393 expo = 0x0040;
1394 expo_c1[3] = expo >> 8;
1395 expo_c1[4] = expo;
1396 i2c_w8(gspca_dev, expo_c1);
1397 break;
1398 }
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001399 case SENSOR_OM6802: {
Jean-Francois Moine98819182009-01-19 07:37:33 -03001400 u8 gainOm[] =
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001401 { 0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001402 /* preset AGC - works when AutoExpo = off */
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001403
1404 if (expo > 0x03ff)
1405 expo = 0x03ff;
1406 if (expo < 0x0001)
1407 expo = 0x0001;
1408 gainOm[3] = expo >> 2;
1409 i2c_w8(gspca_dev, gainOm);
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001410 reg_w1(gspca_dev, 0x96, expo >> 5);
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001411 PDEBUG(D_FRAM, "set exposure %d", gainOm[3]);
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001412 break;
1413 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001414 }
1415 return expo;
1416}
1417
1418static void setbrightness(struct gspca_dev *gspca_dev)
1419{
1420 struct sd *sd = (struct sd *) gspca_dev;
1421 unsigned int expo;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001422 u8 k2;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001423
Jean-Francois Moineb1b056a2008-11-25 04:47:09 -03001424 k2 = ((int) sd->brightness - 0x8000) >> 10;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001425 switch (sd->sensor) {
1426 case SENSOR_HV7131R:
1427 expo = sd->brightness << 4;
1428 if (expo > 0x002dc6c0)
1429 expo = 0x002dc6c0;
1430 else if (expo < 0x02a0)
1431 expo = 0x02a0;
1432 sd->exposure = setexposure(gspca_dev, expo);
1433 break;
1434 case SENSOR_MI0360:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001435 case SENSOR_MO4000:
1436 expo = sd->brightness >> 4;
1437 sd->exposure = setexposure(gspca_dev, expo);
1438 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001439 case SENSOR_MT9V111:
1440 expo = sd->brightness >> 8;
1441 sd->exposure = setexposure(gspca_dev, expo);
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001442 return; /* don't set the Y offset */
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001443 case SENSOR_OM6802:
1444 expo = sd->brightness >> 6;
1445 sd->exposure = setexposure(gspca_dev, expo);
Jean-Francois Moineb1b056a2008-11-25 04:47:09 -03001446 k2 = sd->brightness >> 11;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001447 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001448 }
1449
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001450 reg_w1(gspca_dev, 0x96, k2); /* color matrix Y offset */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001451}
1452
1453static void setcontrast(struct gspca_dev *gspca_dev)
1454{
1455 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001456 u8 k2;
1457 u8 contrast[6];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001458
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03001459 k2 = sd->contrast * 0x30 / (CONTRAST_MAX + 1) + 0x10; /* 10..40 */
1460 contrast[0] = (k2 + 1) / 2; /* red */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -03001461 contrast[1] = 0;
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03001462 contrast[2] = k2; /* green */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -03001463 contrast[3] = 0;
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03001464 contrast[4] = (k2 + 1) / 5; /* blue */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -03001465 contrast[5] = 0;
1466 reg_w(gspca_dev, 0x84, contrast, sizeof contrast);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001467}
1468
1469static void setcolors(struct gspca_dev *gspca_dev)
1470{
1471 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001472 int i, v;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001473 u8 reg8a[12]; /* U & V gains */
1474 static s16 uv[6] = { /* same as reg84 in signed decimal */
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001475 -24, -38, 64, /* UR UG UB */
1476 62, -51, -9 /* VR VG VB */
1477 };
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001478
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001479 for (i = 0; i < 6; i++) {
1480 v = uv[i] * sd->colors / COLOR_DEF;
Jean-Francois Moinebd088832008-12-02 06:58:57 -03001481 reg8a[i * 2] = v;
1482 reg8a[i * 2 + 1] = (v >> 8) & 0x0f;
Jean-Francois Moined55b83d2008-09-03 16:48:01 -03001483 }
Jean-Francois Moinebd088832008-12-02 06:58:57 -03001484 reg_w(gspca_dev, 0x8a, reg8a, sizeof reg8a);
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001485}
1486
1487static void setredblue(struct gspca_dev *gspca_dev)
1488{
1489 struct sd *sd = (struct sd *) gspca_dev;
1490
1491 reg_w1(gspca_dev, 0x05, sd->red);
Jean-Francois Moine9c5f70f2008-09-03 16:48:04 -03001492/* reg_w1(gspca_dev, 0x07, 32); */
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001493 reg_w1(gspca_dev, 0x06, sd->blue);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001494}
1495
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03001496static void setgamma(struct gspca_dev *gspca_dev)
1497{
1498 struct sd *sd = (struct sd *) gspca_dev;
1499 int i;
1500 u8 gamma[17];
Jean-Francois Moineb083b922009-02-01 14:20:07 -03001501 const u8 *gamma_base;
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03001502 static const u8 delta[17] = {
1503 0x00, 0x14, 0x1c, 0x1c, 0x1c, 0x1c, 0x1b, 0x1a,
1504 0x18, 0x13, 0x10, 0x0e, 0x08, 0x07, 0x04, 0x02, 0x00
1505 };
1506
Jean-Francois Moineb083b922009-02-01 14:20:07 -03001507 switch (sd->sensor) {
1508 case SENSOR_HV7131R:
1509 case SENSOR_MT9V111:
1510 gamma_base = gamma_spec_1;
1511 break;
1512 case SENSOR_SP80708:
1513 gamma_base = gamma_spec_2;
1514 break;
1515 default:
1516 gamma_base = gamma_def;
1517 break;
1518 }
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001519
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03001520 for (i = 0; i < sizeof gamma; i++)
Jean-Francois Moineb083b922009-02-01 14:20:07 -03001521 gamma[i] = gamma_base[i]
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03001522 + delta[i] * (sd->gamma - GAMMA_DEF) / 32;
1523 reg_w(gspca_dev, 0x20, gamma, sizeof gamma);
1524}
1525
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001526static void setautogain(struct gspca_dev *gspca_dev)
1527{
1528 struct sd *sd = (struct sd *) gspca_dev;
1529
Jean-Francois Moinef50ba1b2008-09-03 17:12:14 -03001530 if (gspca_dev->ctrl_dis & (1 << AUTOGAIN_IDX))
1531 return;
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03001532 switch (sd->sensor) {
1533 case SENSOR_OV7630:
1534 case SENSOR_OV7648: {
1535 u8 comb;
1536
1537 if (sd->sensor == SENSOR_OV7630)
1538 comb = 0xc0;
1539 else
1540 comb = 0xa0;
1541 if (sd->autogain)
Hans de Goede1fec7472009-06-18 06:05:07 -03001542 comb |= 0x03;
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03001543 i2c_w1(&sd->gspca_dev, 0x13, comb);
1544 return;
1545 }
1546 }
Jean-Francois Moinef50ba1b2008-09-03 17:12:14 -03001547 if (sd->autogain)
1548 sd->ag_cnt = AG_CNT_START;
1549 else
1550 sd->ag_cnt = -1;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001551}
1552
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03001553/* ov7630/ov7648 only */
Jean-Francois Moine6c862742008-09-08 04:57:26 -03001554static void setvflip(struct sd *sd)
1555{
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03001556 u8 comn;
1557
Jean-Francois Moine0939e262009-11-02 09:58:49 -03001558 if (sd->gspca_dev.ctrl_dis & (1 << VFLIP_IDX))
1559 return;
Hans de Goedef8009522009-06-18 14:29:20 -03001560 if (sd->sensor == SENSOR_OV7630) {
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03001561 comn = 0x02;
Hans de Goedef8009522009-06-18 14:29:20 -03001562 if (!sd->vflip)
1563 comn |= 0x80;
1564 } else {
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03001565 comn = 0x06;
Hans de Goedef8009522009-06-18 14:29:20 -03001566 if (sd->vflip)
1567 comn |= 0x80;
1568 }
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03001569 i2c_w1(&sd->gspca_dev, 0x75, comn);
Jean-Francois Moine6c862742008-09-08 04:57:26 -03001570}
1571
Jean-Francois Moine0cae8962008-10-17 07:48:24 -03001572static void setinfrared(struct sd *sd)
1573{
Jean-Francois Moine47f7f6f2009-08-25 06:14:54 -03001574 if (sd->gspca_dev.ctrl_dis & (1 << INFRARED_IDX))
1575 return;
Jean-Francois Moine0cae8962008-10-17 07:48:24 -03001576/*fixme: different sequence for StarCam Clip and StarCam 370i */
1577/* Clip */
1578 i2c_w1(&sd->gspca_dev, 0x02, /* gpio */
1579 sd->infrared ? 0x66 : 0x64);
1580}
1581
Hans de Goede37c6dbe2009-06-18 07:35:36 -03001582static void setfreq(struct gspca_dev *gspca_dev)
1583{
1584 struct sd *sd = (struct sd *) gspca_dev;
1585
Jean-Francois Moine27954932009-07-08 05:21:50 -03001586 if (gspca_dev->ctrl_dis & (1 << FREQ_IDX))
1587 return;
Hans de Goede37c6dbe2009-06-18 07:35:36 -03001588 if (sd->sensor == SENSOR_OV7660) {
Jean-Francois Moined8f400e2009-07-08 06:33:44 -03001589 u8 com8;
1590
Jean-Francois Moine47f7f6f2009-08-25 06:14:54 -03001591 com8 = 0xdf; /* auto gain/wb/expo */
Hans de Goede37c6dbe2009-06-18 07:35:36 -03001592 switch (sd->freq) {
1593 case 0: /* Banding filter disabled */
Jean-Francois Moine47f7f6f2009-08-25 06:14:54 -03001594 i2c_w1(gspca_dev, 0x13, com8 | 0x20);
Hans de Goede37c6dbe2009-06-18 07:35:36 -03001595 break;
1596 case 1: /* 50 hz */
Jean-Francois Moined8f400e2009-07-08 06:33:44 -03001597 i2c_w1(gspca_dev, 0x13, com8);
Hans de Goede37c6dbe2009-06-18 07:35:36 -03001598 i2c_w1(gspca_dev, 0x3b, 0x0a);
1599 break;
1600 case 2: /* 60 hz */
Jean-Francois Moined8f400e2009-07-08 06:33:44 -03001601 i2c_w1(gspca_dev, 0x13, com8);
Hans de Goede37c6dbe2009-06-18 07:35:36 -03001602 i2c_w1(gspca_dev, 0x3b, 0x02);
1603 break;
1604 }
1605 } else {
1606 u8 reg2a = 0, reg2b = 0, reg2d = 0;
1607
1608 /* Get reg2a / reg2d base values */
1609 switch (sd->sensor) {
1610 case SENSOR_OV7630:
1611 reg2a = 0x08;
1612 reg2d = 0x01;
1613 break;
1614 case SENSOR_OV7648:
1615 reg2a = 0x11;
1616 reg2d = 0x81;
1617 break;
1618 }
1619
1620 switch (sd->freq) {
1621 case 0: /* Banding filter disabled */
1622 break;
1623 case 1: /* 50 hz (filter on and framerate adj) */
1624 reg2a |= 0x80;
1625 reg2b = 0xac;
1626 reg2d |= 0x04;
1627 break;
1628 case 2: /* 60 hz (filter on, no framerate adj) */
1629 reg2a |= 0x80;
1630 reg2d |= 0x04;
1631 break;
1632 }
1633 i2c_w1(gspca_dev, 0x2a, reg2a);
1634 i2c_w1(gspca_dev, 0x2b, reg2b);
1635 i2c_w1(gspca_dev, 0x2d, reg2d);
1636 }
1637}
1638
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03001639static void setjpegqual(struct gspca_dev *gspca_dev)
1640{
1641 struct sd *sd = (struct sd *) gspca_dev;
1642 int i, sc;
1643
1644 if (sd->jpegqual < 50)
1645 sc = 5000 / sd->jpegqual;
1646 else
1647 sc = 200 - sd->jpegqual * 2;
1648#if USB_BUF_SZ < 64
1649#error "No room enough in usb_buf for quantization table"
1650#endif
1651 for (i = 0; i < 64; i++)
1652 gspca_dev->usb_buf[i] =
1653 (jpeg_head[JPEG_QT0_OFFSET + i] * sc + 50) / 100;
1654 usb_control_msg(gspca_dev->dev,
1655 usb_sndctrlpipe(gspca_dev->dev, 0),
1656 0x08,
1657 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1658 0x0100, 0,
1659 gspca_dev->usb_buf, 64,
1660 500);
1661 for (i = 0; i < 64; i++)
1662 gspca_dev->usb_buf[i] =
1663 (jpeg_head[JPEG_QT1_OFFSET + i] * sc + 50) / 100;
1664 usb_control_msg(gspca_dev->dev,
1665 usb_sndctrlpipe(gspca_dev->dev, 0),
1666 0x08,
1667 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1668 0x0140, 0,
1669 gspca_dev->usb_buf, 64,
1670 500);
1671
1672 sd->reg18 ^= 0x40;
1673 reg_w1(gspca_dev, 0x18, sd->reg18);
1674}
1675
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001676/* -- start the camera -- */
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03001677static int sd_start(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001678{
1679 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001680 int i;
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001681 u8 reg1, reg2, reg17;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001682 const u8 *sn9c1xx;
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001683 const u8 (*init)[8];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001684 int mode;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001685 static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
1686 static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
1687 static const u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */
1688 static const u8 CE_ov76xx[] =
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001689 { 0x32, 0xdd, 0x32, 0xdd };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001690
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03001691 /* create the JPEG header */
1692 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
Julia Lawall3eb02372009-07-19 07:09:32 -03001693 if (!sd->jpeg_hdr)
1694 return -ENOMEM;
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03001695 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
1696 0x21); /* JPEG 422 */
1697 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
1698
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001699 /* initialize the bridge */
1700 sn9c1xx = sn_tb[sd->sensor];
1701 bridge_init(gspca_dev, sn9c1xx);
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001702
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001703 /* initialize the sensor */
1704 i2c_w_seq(gspca_dev, sensor_init[sd->sensor]);
1705
1706 switch (sd->sensor) {
1707 case SENSOR_OM6802:
1708 reg2 = 0x71;
1709 break;
1710 case SENSOR_SP80708:
1711 reg2 = 0x62;
1712 break;
1713 default:
1714 reg2 = 0x40;
1715 break;
1716 }
1717 reg_w1(gspca_dev, 0x02, reg2);
1718 reg_w1(gspca_dev, 0x02, reg2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001719
Jean-Francois Moine60017612008-07-18 08:46:19 -03001720 reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]);
1721 reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]);
1722 reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
1723 reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]);
1724 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
1725 reg_w1(gspca_dev, 0xd2, 0x6a); /* DC29 */
1726 reg_w1(gspca_dev, 0xd3, 0x50);
1727 reg_w1(gspca_dev, 0xc6, 0x00);
1728 reg_w1(gspca_dev, 0xc7, 0x00);
1729 reg_w1(gspca_dev, 0xc8, 0x50);
1730 reg_w1(gspca_dev, 0xc9, 0x3c);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001731 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001732 switch (sd->sensor) {
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001733 case SENSOR_MT9V111:
1734 reg17 = 0xe0;
1735 break;
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001736 case SENSOR_OV7630:
1737 reg17 = 0xe2;
1738 break;
1739 case SENSOR_OV7648:
Jean-Francois Moine62703302008-11-11 08:42:56 -03001740 reg17 = 0x20;
Jean-Francois Moine568788a2008-07-15 11:46:06 -03001741 break;
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001742 case SENSOR_OV7660:
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03001743 reg17 = 0xa0;
1744 break;
Jean-Francois Moine568788a2008-07-15 11:46:06 -03001745 default:
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001746 reg17 = 0x60;
Jean-Francois Moine568788a2008-07-15 11:46:06 -03001747 break;
1748 }
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001749 reg_w1(gspca_dev, 0x17, reg17);
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001750/* set reg1 was here */
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001751 reg_w1(gspca_dev, 0x05, sn9c1xx[5]); /* red */
1752 reg_w1(gspca_dev, 0x07, sn9c1xx[7]); /* green */
1753 reg_w1(gspca_dev, 0x06, sn9c1xx[6]); /* blue */
Jean-Francois Moine60017612008-07-18 08:46:19 -03001754 reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
Jean-Francois Moineb083b922009-02-01 14:20:07 -03001755
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001756 setgamma(gspca_dev);
1757
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001758 for (i = 0; i < 8; i++)
1759 reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001760 switch (sd->sensor) {
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001761 case SENSOR_MT9V111:
1762 reg_w1(gspca_dev, 0x9a, 0x07);
1763 reg_w1(gspca_dev, 0x99, 0x59);
1764 break;
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001765 case SENSOR_OM6802:
1766 reg_w1(gspca_dev, 0x9a, 0x08);
1767 reg_w1(gspca_dev, 0x99, 0x10);
1768 break;
Jean-Francois Moine62703302008-11-11 08:42:56 -03001769 case SENSOR_OV7648:
1770 reg_w1(gspca_dev, 0x9a, 0x0a);
1771 reg_w1(gspca_dev, 0x99, 0x60);
1772 break;
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03001773 case SENSOR_OV7660:
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001774 case SENSOR_SP80708:
1775 reg_w1(gspca_dev, 0x9a, 0x05);
1776 reg_w1(gspca_dev, 0x99, 0x59);
1777 break;
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001778 default:
Jean-Francois Moine60017612008-07-18 08:46:19 -03001779 reg_w1(gspca_dev, 0x9a, 0x08);
1780 reg_w1(gspca_dev, 0x99, 0x59);
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001781 break;
1782 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001783
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001784 reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
1785 reg_w1(gspca_dev, 0x05, sn9c1xx[5]); /* red */
1786 reg_w1(gspca_dev, 0x07, sn9c1xx[7]); /* green */
1787 reg_w1(gspca_dev, 0x06, sn9c1xx[6]); /* blue */
Jean-Francois Moine23a98272009-11-02 09:10:25 -03001788
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001789 init = NULL;
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001790 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
Jean-Francois Moine60017612008-07-18 08:46:19 -03001791 if (mode)
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001792 reg1 = 0x46; /* 320x240: clk 48Mhz, video trf enable */
Jean-Francois Moine60017612008-07-18 08:46:19 -03001793 else
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001794 reg1 = 0x06; /* 640x480: clk 24Mhz, video trf enable */
1795 reg17 = 0x61; /* 0x:20: enable sensor clock */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001796 switch (sd->sensor) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001797 case SENSOR_MO4000:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001798 if (mode) {
1799/* reg1 = 0x46; * 320 clk 48Mhz 60fp/s */
1800 reg1 = 0x06; /* clk 24Mz */
1801 } else {
1802 reg17 = 0x22; /* 640 MCKSIZE */
Jean-Francois Moine60017612008-07-18 08:46:19 -03001803/* reg1 = 0x06; * 640 clk 24Mz (done) */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001804 }
1805 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001806 case SENSOR_MT9V111:
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001807 init = mt9v111_sensor_param1;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001808 if (mode) {
1809 reg1 = 0x04; /* 320 clk 48Mhz */
1810 } else {
1811/* reg1 = 0x06; * 640 clk 24Mz (done) */
Jean-Francois Moine2687a2f2009-02-01 14:48:55 -03001812 reg17 = 0xc2;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001813 }
Jean-Francois Moine0fbe0572009-01-30 12:14:02 -03001814 break;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001815 case SENSOR_OM6802:
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001816 init = om6802_sensor_param1;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001817 reg17 = 0x64; /* 640 MCKSIZE */
1818 break;
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001819 case SENSOR_OV7630:
Jean-Francois Moine6c862742008-09-08 04:57:26 -03001820 setvflip(sd);
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001821 reg17 = 0xe2;
Jean-Francois Moine5b064da2008-09-03 16:48:08 -03001822 reg1 = 0x44;
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001823 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001824 case SENSOR_OV7648:
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001825 init = ov7648_sensor_param1;
Jean-Francois Moine62703302008-11-11 08:42:56 -03001826 reg17 = 0x21;
1827/* reg1 = 0x42; * 42 - 46? */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001828 break;
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001829 case SENSOR_OV7660:
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001830 init = ov7660_sensor_param1;
Jean-Francois Moinedaa5cb42008-12-02 15:00:57 -03001831 if (sd->bridge == BRIDGE_SN9C120) {
1832 if (mode) { /* 320x240 - 160x120 */
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001833 reg17 = 0xa2;
1834 reg1 = 0x44; /* 48 Mhz, video trf eneble */
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001835 }
Jean-Francois Moinedaa5cb42008-12-02 15:00:57 -03001836 } else {
1837 reg17 = 0x22;
1838 reg1 = 0x06; /* 24 Mhz, video trf eneble
1839 * inverse power down */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001840 }
1841 break;
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001842 default:
1843/* case SENSOR_SP80708: */
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001844 init = sp80708_sensor_param1;
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001845 if (mode) {
1846/*?? reg1 = 0x04; * 320 clk 48Mhz */
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001847 } else {
1848 reg1 = 0x46; /* 640 clk 48Mz */
1849 reg17 = 0xa2;
1850 }
1851 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001852 }
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001853
1854 /* more sensor initialization - param1 */
1855 if (init != NULL) {
1856 i2c_w_seq(gspca_dev, init);
1857/* init = NULL; */
1858 }
1859
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001860 reg_w(gspca_dev, 0xc0, C0, 6);
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001861 reg_w(gspca_dev, 0xca, CA, 4);
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001862 switch (sd->sensor) {
1863 case SENSOR_OV7630:
1864 case SENSOR_OV7648:
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001865 case SENSOR_OV7660:
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001866 reg_w(gspca_dev, 0xce, CE_ov76xx, 4);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001867 break;
1868 default:
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001869 reg_w(gspca_dev, 0xce, CE, 4);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001870 /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */
1871 break;
1872 }
1873
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001874
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001875 /* here change size mode 0 -> VGA; 1 -> CIF */
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03001876 sd->reg18 = sn9c1xx[0x18] | (mode << 4) | 0x40;
1877 reg_w1(gspca_dev, 0x18, sd->reg18);
1878 setjpegqual(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001879
Jean-Francois Moine60017612008-07-18 08:46:19 -03001880 reg_w1(gspca_dev, 0x17, reg17);
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001881 reg_w1(gspca_dev, 0x01, reg1);
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001882
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001883 switch (sd->sensor) {
Jean-Francois Moine79a90982008-10-05 04:21:24 -03001884 case SENSOR_OV7630:
1885 setvflip(sd);
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001886 break;
1887 }
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03001888 setbrightness(gspca_dev);
1889 setcontrast(gspca_dev);
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001890 setautogain(gspca_dev);
Hans de Goede37c6dbe2009-06-18 07:35:36 -03001891 setfreq(gspca_dev);
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03001892 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001893}
1894
1895static void sd_stopN(struct gspca_dev *gspca_dev)
1896{
1897 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001898 static const u8 stophv7131[] =
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001899 { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001900 static const u8 stopmi0360[] =
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001901 { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001902 static const u8 stopov7648[] =
Jean-Francois Moine62703302008-11-11 08:42:56 -03001903 { 0xa1, 0x21, 0x76, 0x20, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001904 u8 data;
1905 const u8 *sn9c1xx;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001906
1907 data = 0x0b;
1908 switch (sd->sensor) {
1909 case SENSOR_HV7131R:
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001910 i2c_w8(gspca_dev, stophv7131);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001911 data = 0x2b;
1912 break;
1913 case SENSOR_MI0360:
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001914 i2c_w8(gspca_dev, stopmi0360);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001915 data = 0x29;
1916 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001917 case SENSOR_OV7648:
Jean-Francois Moine62703302008-11-11 08:42:56 -03001918 i2c_w8(gspca_dev, stopov7648);
1919 /* fall thru */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001920 case SENSOR_MT9V111:
Jean-Francois Moine62703302008-11-11 08:42:56 -03001921 case SENSOR_OV7630:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001922 data = 0x29;
1923 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001924 }
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03001925 sn9c1xx = sn_tb[sd->sensor];
Jean-Francois Moine60017612008-07-18 08:46:19 -03001926 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
1927 reg_w1(gspca_dev, 0x17, sn9c1xx[0x17]);
1928 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
1929 reg_w1(gspca_dev, 0x01, data);
Jean-Francois Moine759aa3c2008-09-03 16:48:03 -03001930 reg_w1(gspca_dev, 0xf1, 0x00);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001931}
1932
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03001933static void sd_stop0(struct gspca_dev *gspca_dev)
1934{
1935 struct sd *sd = (struct sd *) gspca_dev;
1936
1937 kfree(sd->jpeg_hdr);
1938}
1939
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001940static void do_autogain(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001941{
1942 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001943 int delta;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001944 int expotimes;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001945 u8 luma_mean = 130;
1946 u8 luma_delta = 20;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001947
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001948 /* Thanks S., without your advice, autobright should not work :) */
1949 if (sd->ag_cnt < 0)
1950 return;
1951 if (--sd->ag_cnt >= 0)
1952 return;
1953 sd->ag_cnt = AG_CNT_START;
1954
1955 delta = atomic_read(&sd->avg_lum);
1956 PDEBUG(D_FRAM, "mean lum %d", delta);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001957 if (delta < luma_mean - luma_delta ||
1958 delta > luma_mean + luma_delta) {
1959 switch (sd->sensor) {
1960 case SENSOR_HV7131R:
1961 expotimes = sd->exposure >> 8;
1962 expotimes += (luma_mean - delta) >> 4;
1963 if (expotimes < 0)
1964 expotimes = 0;
1965 sd->exposure = setexposure(gspca_dev,
1966 (unsigned int) (expotimes << 8));
1967 break;
Amauri Magagna46b4f2a2009-10-17 07:21:29 -03001968 case SENSOR_OM6802:
1969 expotimes = sd->exposure;
1970 expotimes += (luma_mean - delta) >> 2;
1971 if (expotimes < 0)
1972 expotimes = 0;
1973 sd->exposure = setexposure(gspca_dev,
1974 (unsigned int) expotimes);
1975 setredblue(gspca_dev);
1976 break;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001977 default:
1978/* case SENSOR_MO4000: */
1979/* case SENSOR_MI0360: */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001980/* case SENSOR_MT9V111: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001981 expotimes = sd->exposure;
1982 expotimes += (luma_mean - delta) >> 6;
1983 if (expotimes < 0)
1984 expotimes = 0;
1985 sd->exposure = setexposure(gspca_dev,
1986 (unsigned int) expotimes);
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001987 setredblue(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001988 break;
1989 }
1990 }
1991}
1992
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001993/* scan the URB packets */
1994/* This function is run at interrupt level. */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001995static void sd_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -03001996 u8 *data, /* isoc packet */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001997 int len) /* iso packet length */
1998{
1999 struct sd *sd = (struct sd *) gspca_dev;
2000 int sof, avg_lum;
2001
2002 sof = len - 64;
2003 if (sof >= 0 && data[sof] == 0xff && data[sof + 1] == 0xd9) {
2004
2005 /* end of frame */
2006 gspca_frame_add(gspca_dev, LAST_PACKET,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03002007 data, sof + 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002008 if (sd->ag_cnt < 0)
2009 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002010/* w1 w2 w3 */
2011/* w4 w5 w6 */
2012/* w7 w8 */
2013/* w4 */
2014 avg_lum = ((data[sof + 29] << 8) | data[sof + 30]) >> 6;
2015/* w6 */
2016 avg_lum += ((data[sof + 33] << 8) | data[sof + 34]) >> 6;
2017/* w2 */
2018 avg_lum += ((data[sof + 25] << 8) | data[sof + 26]) >> 6;
2019/* w8 */
2020 avg_lum += ((data[sof + 37] << 8) | data[sof + 38]) >> 6;
2021/* w5 */
2022 avg_lum += ((data[sof + 31] << 8) | data[sof + 32]) >> 4;
2023 avg_lum >>= 4;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002024 atomic_set(&sd->avg_lum, avg_lum);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002025 return;
2026 }
2027 if (gspca_dev->last_packet_type == LAST_PACKET) {
2028
2029 /* put the JPEG 422 header */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03002030 gspca_frame_add(gspca_dev, FIRST_PACKET,
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03002031 sd->jpeg_hdr, JPEG_HDR_SZ);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002032 }
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03002033 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002034}
2035
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002036static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
2037{
2038 struct sd *sd = (struct sd *) gspca_dev;
2039
2040 sd->brightness = val;
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03002041 if (gspca_dev->streaming)
2042 setbrightness(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002043 return 0;
2044}
2045
2046static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
2047{
2048 struct sd *sd = (struct sd *) gspca_dev;
2049
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002050 *val = sd->brightness;
2051 return 0;
2052}
2053
2054static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
2055{
2056 struct sd *sd = (struct sd *) gspca_dev;
2057
2058 sd->contrast = val;
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03002059 if (gspca_dev->streaming)
2060 setcontrast(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002061 return 0;
2062}
2063
2064static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
2065{
2066 struct sd *sd = (struct sd *) gspca_dev;
2067
2068 *val = sd->contrast;
2069 return 0;
2070}
2071
2072static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
2073{
2074 struct sd *sd = (struct sd *) gspca_dev;
2075
2076 sd->colors = val;
2077 if (gspca_dev->streaming)
2078 setcolors(gspca_dev);
2079 return 0;
2080}
2081
2082static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
2083{
2084 struct sd *sd = (struct sd *) gspca_dev;
2085
2086 *val = sd->colors;
2087 return 0;
2088}
2089
Jean-Francois Moine403123d2008-11-26 04:46:15 -03002090static int sd_setblue_balance(struct gspca_dev *gspca_dev, __s32 val)
2091{
2092 struct sd *sd = (struct sd *) gspca_dev;
2093
2094 sd->blue = val;
2095 if (gspca_dev->streaming)
2096 setredblue(gspca_dev);
2097 return 0;
2098}
2099
2100static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val)
2101{
2102 struct sd *sd = (struct sd *) gspca_dev;
2103
2104 *val = sd->blue;
2105 return 0;
2106}
2107
2108static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val)
2109{
2110 struct sd *sd = (struct sd *) gspca_dev;
2111
2112 sd->red = val;
2113 if (gspca_dev->streaming)
2114 setredblue(gspca_dev);
2115 return 0;
2116}
2117
2118static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val)
2119{
2120 struct sd *sd = (struct sd *) gspca_dev;
2121
2122 *val = sd->red;
2123 return 0;
2124}
2125
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03002126static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val)
2127{
2128 struct sd *sd = (struct sd *) gspca_dev;
2129
2130 sd->gamma = val;
2131 if (gspca_dev->streaming)
2132 setgamma(gspca_dev);
2133 return 0;
2134}
2135
2136static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val)
2137{
2138 struct sd *sd = (struct sd *) gspca_dev;
2139
2140 *val = sd->gamma;
2141 return 0;
2142}
2143
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002144static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
2145{
2146 struct sd *sd = (struct sd *) gspca_dev;
2147
2148 sd->autogain = val;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002149 if (gspca_dev->streaming)
2150 setautogain(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002151 return 0;
2152}
2153
2154static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
2155{
2156 struct sd *sd = (struct sd *) gspca_dev;
2157
2158 *val = sd->autogain;
2159 return 0;
2160}
2161
Jean-Francois Moine6c862742008-09-08 04:57:26 -03002162static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
2163{
2164 struct sd *sd = (struct sd *) gspca_dev;
2165
2166 sd->vflip = val;
Jean-Francois Moine79a90982008-10-05 04:21:24 -03002167 if (gspca_dev->streaming)
2168 setvflip(sd);
Jean-Francois Moine6c862742008-09-08 04:57:26 -03002169 return 0;
2170}
2171
2172static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
2173{
2174 struct sd *sd = (struct sd *) gspca_dev;
2175
2176 *val = sd->vflip;
2177 return 0;
2178}
2179
Jean-Francois Moine0cae8962008-10-17 07:48:24 -03002180static int sd_setinfrared(struct gspca_dev *gspca_dev, __s32 val)
2181{
2182 struct sd *sd = (struct sd *) gspca_dev;
2183
2184 sd->infrared = val;
2185 if (gspca_dev->streaming)
2186 setinfrared(sd);
2187 return 0;
2188}
2189
2190static int sd_getinfrared(struct gspca_dev *gspca_dev, __s32 *val)
2191{
2192 struct sd *sd = (struct sd *) gspca_dev;
2193
2194 *val = sd->infrared;
2195 return 0;
2196}
2197
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002198static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
2199{
2200 struct sd *sd = (struct sd *) gspca_dev;
2201
2202 sd->freq = val;
2203 if (gspca_dev->streaming)
2204 setfreq(gspca_dev);
2205 return 0;
2206}
2207
2208static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
2209{
2210 struct sd *sd = (struct sd *) gspca_dev;
2211
2212 *val = sd->freq;
2213 return 0;
2214}
2215
Jean-Francois Moine77ac0ba2009-03-02 06:40:52 -03002216static int sd_set_jcomp(struct gspca_dev *gspca_dev,
2217 struct v4l2_jpegcompression *jcomp)
2218{
2219 struct sd *sd = (struct sd *) gspca_dev;
2220
2221 if (jcomp->quality < QUALITY_MIN)
2222 sd->quality = QUALITY_MIN;
2223 else if (jcomp->quality > QUALITY_MAX)
2224 sd->quality = QUALITY_MAX;
2225 else
2226 sd->quality = jcomp->quality;
2227 if (gspca_dev->streaming)
2228 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
2229 return 0;
2230}
2231
2232static int sd_get_jcomp(struct gspca_dev *gspca_dev,
2233 struct v4l2_jpegcompression *jcomp)
2234{
2235 struct sd *sd = (struct sd *) gspca_dev;
2236
2237 memset(jcomp, 0, sizeof *jcomp);
2238 jcomp->quality = sd->quality;
2239 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
2240 | V4L2_JPEG_MARKER_DQT;
2241 return 0;
2242}
2243
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002244static int sd_querymenu(struct gspca_dev *gspca_dev,
2245 struct v4l2_querymenu *menu)
2246{
2247 switch (menu->id) {
2248 case V4L2_CID_POWER_LINE_FREQUENCY:
2249 switch (menu->index) {
2250 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
2251 strcpy((char *) menu->name, "NoFliker");
2252 return 0;
2253 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
2254 strcpy((char *) menu->name, "50 Hz");
2255 return 0;
2256 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
2257 strcpy((char *) menu->name, "60 Hz");
2258 return 0;
2259 }
2260 break;
2261 }
2262 return -EINVAL;
2263}
2264
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002265/* sub-driver description */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002266static const struct sd_desc sd_desc = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002267 .name = MODULE_NAME,
2268 .ctrls = sd_ctrls,
2269 .nctrls = ARRAY_SIZE(sd_ctrls),
2270 .config = sd_config,
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03002271 .init = sd_init,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002272 .start = sd_start,
2273 .stopN = sd_stopN,
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03002274 .stop0 = sd_stop0,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002275 .pkt_scan = sd_pkt_scan,
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002276 .dq_callback = do_autogain,
Jean-Francois Moine77ac0ba2009-03-02 06:40:52 -03002277 .get_jcomp = sd_get_jcomp,
2278 .set_jcomp = sd_set_jcomp,
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002279 .querymenu = sd_querymenu,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002280};
2281
2282/* -- module initialisation -- */
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002283#define BS(bridge, sensor) \
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002284 .driver_info = (BRIDGE_ ## bridge << 16) \
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002285 | SENSOR_ ## sensor
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002286static const __devinitdata struct usb_device_id device_table[] = {
Hans de Goede222a07f2008-09-03 17:12:20 -03002287#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002288 {USB_DEVICE(0x0458, 0x7025), BS(SN9C120, MI0360)},
2289 {USB_DEVICE(0x0458, 0x702e), BS(SN9C120, OV7660)},
Jean-Francois Moinea08d81a2008-11-22 04:53:31 -03002290#endif
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002291 {USB_DEVICE(0x045e, 0x00f5), BS(SN9C105, OV7660)},
2292 {USB_DEVICE(0x045e, 0x00f7), BS(SN9C105, OV7660)},
2293 {USB_DEVICE(0x0471, 0x0327), BS(SN9C105, MI0360)},
2294 {USB_DEVICE(0x0471, 0x0328), BS(SN9C105, MI0360)},
2295 {USB_DEVICE(0x0471, 0x0330), BS(SN9C105, MI0360)},
2296 {USB_DEVICE(0x06f8, 0x3004), BS(SN9C105, OV7660)},
2297 {USB_DEVICE(0x06f8, 0x3008), BS(SN9C105, OV7660)},
2298/* {USB_DEVICE(0x0c45, 0x603a), BS(SN9C102P, OV7648)}, */
2299 {USB_DEVICE(0x0c45, 0x6040), BS(SN9C102P, HV7131R)},
2300/* {USB_DEVICE(0x0c45, 0x607a), BS(SN9C102P, OV7648)}, */
2301/* {USB_DEVICE(0x0c45, 0x607b), BS(SN9C102P, OV7660)}, */
2302 {USB_DEVICE(0x0c45, 0x607c), BS(SN9C102P, HV7131R)},
2303/* {USB_DEVICE(0x0c45, 0x607e), BS(SN9C102P, OV7630)}, */
2304 {USB_DEVICE(0x0c45, 0x60c0), BS(SN9C105, MI0360)},
2305/* {USB_DEVICE(0x0c45, 0x60c2), BS(SN9C105, P1030xC)}, */
2306/* {USB_DEVICE(0x0c45, 0x60c8), BS(SN9C105, OM6802)}, */
2307/* {USB_DEVICE(0x0c45, 0x60cc), BS(SN9C105, HV7131GP)}, */
2308 {USB_DEVICE(0x0c45, 0x60ec), BS(SN9C105, MO4000)},
2309/* {USB_DEVICE(0x0c45, 0x60ef), BS(SN9C105, ICM105C)}, */
2310/* {USB_DEVICE(0x0c45, 0x60fa), BS(SN9C105, OV7648)}, */
2311 {USB_DEVICE(0x0c45, 0x60fb), BS(SN9C105, OV7660)},
Jean-Francois Moine3c41cb72008-09-10 02:57:09 -03002312#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002313 {USB_DEVICE(0x0c45, 0x60fc), BS(SN9C105, HV7131R)},
2314 {USB_DEVICE(0x0c45, 0x60fe), BS(SN9C105, OV7630)},
Jean-Francois Moine3c41cb72008-09-10 02:57:09 -03002315#endif
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002316 {USB_DEVICE(0x0c45, 0x6100), BS(SN9C120, MI0360)}, /*sn9c128*/
2317/* {USB_DEVICE(0x0c45, 0x6102), BS(SN9C120, P1030xC)}, */
2318/* {USB_DEVICE(0x0c45, 0x6108), BS(SN9C120, OM6802)}, */
2319 {USB_DEVICE(0x0c45, 0x610a), BS(SN9C120, OV7648)}, /*sn9c128*/
2320 {USB_DEVICE(0x0c45, 0x610b), BS(SN9C120, OV7660)}, /*sn9c128*/
2321 {USB_DEVICE(0x0c45, 0x610c), BS(SN9C120, HV7131R)}, /*sn9c128*/
2322 {USB_DEVICE(0x0c45, 0x610e), BS(SN9C120, OV7630)}, /*sn9c128*/
2323/* {USB_DEVICE(0x0c45, 0x610f), BS(SN9C120, S5K53BEB)}, */
2324/* {USB_DEVICE(0x0c45, 0x6122), BS(SN9C110, ICM105C)}, */
2325/* {USB_DEVICE(0x0c45, 0x6123), BS(SN9C110, SanyoCCD)}, */
2326 {USB_DEVICE(0x0c45, 0x6128), BS(SN9C120, OM6802)}, /*sn9c325?*/
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03002327/*bw600.inf:*/
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002328 {USB_DEVICE(0x0c45, 0x612a), BS(SN9C120, OV7648)}, /*sn9c110?*/
2329 {USB_DEVICE(0x0c45, 0x612c), BS(SN9C110, MO4000)},
2330 {USB_DEVICE(0x0c45, 0x612e), BS(SN9C110, OV7630)},
2331/* {USB_DEVICE(0x0c45, 0x612f), BS(SN9C110, ICM105C)}, */
Hans de Goede222a07f2008-09-03 17:12:20 -03002332#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002333 {USB_DEVICE(0x0c45, 0x6130), BS(SN9C120, MI0360)},
Hans de Goede222a07f2008-09-03 17:12:20 -03002334#endif
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002335/* {USB_DEVICE(0x0c45, 0x6132), BS(SN9C120, OV7670)}, */
2336 {USB_DEVICE(0x0c45, 0x6138), BS(SN9C120, MO4000)},
2337 {USB_DEVICE(0x0c45, 0x613a), BS(SN9C120, OV7648)},
Hans de Goede222a07f2008-09-03 17:12:20 -03002338#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002339 {USB_DEVICE(0x0c45, 0x613b), BS(SN9C120, OV7660)},
Jean-Francois Moine8d977702009-02-19 15:34:48 -03002340#endif
Jean-Francois Moined5aa3852009-11-07 06:10:08 -03002341 {USB_DEVICE(0x0c45, 0x613c), BS(SN9C120, HV7131R)},
2342 {USB_DEVICE(0x0c45, 0x613e), BS(SN9C120, OV7630)},
2343/* {USB_DEVICE(0x0c45, 0x6142), BS(SN9C120, PO2030N)}, *sn9c120b*/
2344 {USB_DEVICE(0x0c45, 0x6143), BS(SN9C120, SP80708)}, /*sn9c120b*/
2345 {USB_DEVICE(0x0c45, 0x6148), BS(SN9C120, OM6802)}, /*sn9c120b*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002346 {}
2347};
2348MODULE_DEVICE_TABLE(usb, device_table);
2349
2350/* -- device connect -- */
2351static int sd_probe(struct usb_interface *intf,
2352 const struct usb_device_id *id)
2353{
2354 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
2355 THIS_MODULE);
2356}
2357
2358static struct usb_driver sd_driver = {
2359 .name = MODULE_NAME,
2360 .id_table = device_table,
2361 .probe = sd_probe,
2362 .disconnect = gspca_disconnect,
Jean-Francois Moine6a709742008-09-03 16:48:10 -03002363#ifdef CONFIG_PM
2364 .suspend = gspca_suspend,
2365 .resume = gspca_resume,
2366#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002367};
2368
2369/* -- module insert / remove -- */
2370static int __init sd_mod_init(void)
2371{
Alexey Klimovf69e9522009-01-01 13:02:07 -03002372 int ret;
2373 ret = usb_register(&sd_driver);
2374 if (ret < 0)
Alexey Klimove6b14842009-01-01 13:04:58 -03002375 return ret;
Jean-Francois Moine10b0e962008-07-22 05:35:10 -03002376 info("registered");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002377 return 0;
2378}
2379static void __exit sd_mod_exit(void)
2380{
2381 usb_deregister(&sd_driver);
2382 info("deregistered");
2383}
2384
2385module_init(sd_mod_init);
2386module_exit(sd_mod_exit);