blob: a9643a0f78d5d98cf5c111b951490c8b40e307dd [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
3 * Copyright (C) 2009 Jean-Francois Moine <http://moinejf.free.fr>
4 * Copyright (C) 2005 Michel Xhaard mxhaard@magic.fr
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#define MODULE_NAME "sonixj"
22
23#include "gspca.h"
24#include "jpeg.h"
25
Jean-Francois Moine0cae8962008-10-17 07:48:24 -030026#define V4L2_CID_INFRARED (V4L2_CID_PRIVATE_BASE + 0)
27
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030028MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
29MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
30MODULE_LICENSE("GPL");
31
32/* specific webcam descriptor */
33struct sd {
34 struct gspca_dev gspca_dev; /* !! must be the first item */
35
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -030036 atomic_t avg_lum;
Jean-Francois Moine98819182009-01-19 07:37:33 -030037 u32 exposure;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030038
Jean-Francois Moine98819182009-01-19 07:37:33 -030039 u16 brightness;
40 u8 contrast;
41 u8 colors;
42 u8 autogain;
43 u8 blue;
44 u8 red;
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -030045 u8 gamma;
Jean-Francois Moine2797ba22009-02-05 15:12:24 -030046 u8 vflip; /* ov7630/ov7648 only */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -030047 u8 infrared; /* mt9v111 only */
Hans de Goede37c6dbe2009-06-18 07:35:36 -030048 u8 freq; /* ov76xx only */
Jean-Francois Moine71cb2762009-03-03 05:33:41 -030049 u8 quality; /* image quality */
Jean-Francois Moine77ac0ba2009-03-02 06:40:52 -030050#define QUALITY_MIN 60
51#define QUALITY_MAX 95
52#define QUALITY_DEF 80
Jean-Francois Moine71cb2762009-03-03 05:33:41 -030053 u8 jpegqual; /* webcam quality */
54
55 u8 reg18;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030056
Jean-Francois Moine98819182009-01-19 07:37:33 -030057 s8 ag_cnt;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030058#define AG_CNT_START 13
59
Jean-Francois Moine98819182009-01-19 07:37:33 -030060 u8 bridge;
Hans de Goede3647fea2008-07-15 05:36:30 -030061#define BRIDGE_SN9C102P 0
62#define BRIDGE_SN9C105 1
63#define BRIDGE_SN9C110 2
64#define BRIDGE_SN9C120 3
Jean-Francois Moine98819182009-01-19 07:37:33 -030065 u8 sensor; /* Type of image sensor chip */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030066#define SENSOR_HV7131R 0
67#define SENSOR_MI0360 1
68#define SENSOR_MO4000 2
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -030069#define SENSOR_MT9V111 3
70#define SENSOR_OM6802 4
71#define SENSOR_OV7630 5
72#define SENSOR_OV7648 6
73#define SENSOR_OV7660 7
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -030074#define SENSOR_SP80708 8
Jean-Francois Moine98819182009-01-19 07:37:33 -030075 u8 i2c_base;
Jean-Francois Moine71cb2762009-03-03 05:33:41 -030076
77 u8 *jpeg_hdr;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030078};
79
80/* V4L2 controls supported by the driver */
81static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
82static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
83static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
84static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
85static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
86static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine403123d2008-11-26 04:46:15 -030087static int sd_setblue_balance(struct gspca_dev *gspca_dev, __s32 val);
88static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val);
89static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val);
90static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -030091static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val);
92static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030093static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
94static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine6c862742008-09-08 04:57:26 -030095static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
96static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine0cae8962008-10-17 07:48:24 -030097static int sd_setinfrared(struct gspca_dev *gspca_dev, __s32 val);
98static int sd_getinfrared(struct gspca_dev *gspca_dev, __s32 *val);
Hans de Goede37c6dbe2009-06-18 07:35:36 -030099static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
100static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300101
102static struct ctrl sd_ctrls[] = {
Hans de Goede97643982009-06-18 05:08:11 -0300103#define BRIGHTNESS_IDX 0
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300104 {
105 {
106 .id = V4L2_CID_BRIGHTNESS,
107 .type = V4L2_CTRL_TYPE_INTEGER,
108 .name = "Brightness",
109 .minimum = 0,
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300110#define BRIGHTNESS_MAX 0xffff
111 .maximum = BRIGHTNESS_MAX,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300112 .step = 1,
Jean-Francois Moineb1b056a2008-11-25 04:47:09 -0300113#define BRIGHTNESS_DEF 0x8000
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300114 .default_value = BRIGHTNESS_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300115 },
116 .set = sd_setbrightness,
117 .get = sd_getbrightness,
118 },
Hans de Goede97643982009-06-18 05:08:11 -0300119#define CONTRAST_IDX 1
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300120 {
121 {
122 .id = V4L2_CID_CONTRAST,
123 .type = V4L2_CTRL_TYPE_INTEGER,
124 .name = "Contrast",
125 .minimum = 0,
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300126#define CONTRAST_MAX 127
127 .maximum = CONTRAST_MAX,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300128 .step = 1,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300129#define CONTRAST_DEF 63
130 .default_value = CONTRAST_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300131 },
132 .set = sd_setcontrast,
133 .get = sd_getcontrast,
134 },
Hans de Goede97643982009-06-18 05:08:11 -0300135#define COLOR_IDX 2
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300136 {
137 {
138 .id = V4L2_CID_SATURATION,
139 .type = V4L2_CTRL_TYPE_INTEGER,
Hans de Goede3fb4a572009-06-18 14:31:36 -0300140 .name = "Saturation",
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300141 .minimum = 0,
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300142 .maximum = 40,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300143 .step = 1,
Hans de Goede3fb4a572009-06-18 14:31:36 -0300144#define COLOR_DEF 25
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300145 .default_value = COLOR_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300146 },
147 .set = sd_setcolors,
148 .get = sd_getcolors,
149 },
Hans de Goede97643982009-06-18 05:08:11 -0300150#define BLUE_BALANCE_IDX 3
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300151 {
152 {
153 .id = V4L2_CID_BLUE_BALANCE,
154 .type = V4L2_CTRL_TYPE_INTEGER,
155 .name = "Blue Balance",
156 .minimum = 24,
157 .maximum = 40,
158 .step = 1,
159#define BLUE_BALANCE_DEF 32
160 .default_value = BLUE_BALANCE_DEF,
161 },
162 .set = sd_setblue_balance,
163 .get = sd_getblue_balance,
164 },
Hans de Goede97643982009-06-18 05:08:11 -0300165#define RED_BALANCE_IDX 4
Jean-Francois Moine403123d2008-11-26 04:46:15 -0300166 {
167 {
168 .id = V4L2_CID_RED_BALANCE,
169 .type = V4L2_CTRL_TYPE_INTEGER,
170 .name = "Red Balance",
171 .minimum = 24,
172 .maximum = 40,
173 .step = 1,
174#define RED_BALANCE_DEF 32
175 .default_value = RED_BALANCE_DEF,
176 },
177 .set = sd_setred_balance,
178 .get = sd_getred_balance,
179 },
Hans de Goede97643982009-06-18 05:08:11 -0300180#define GAMMA_IDX 5
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -0300181 {
182 {
183 .id = V4L2_CID_GAMMA,
184 .type = V4L2_CTRL_TYPE_INTEGER,
185 .name = "Gamma",
186 .minimum = 0,
187 .maximum = 40,
188 .step = 1,
189#define GAMMA_DEF 20
190 .default_value = GAMMA_DEF,
191 },
192 .set = sd_setgamma,
193 .get = sd_getgamma,
194 },
Hans de Goede97643982009-06-18 05:08:11 -0300195#define AUTOGAIN_IDX 6
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300196 {
197 {
198 .id = V4L2_CID_AUTOGAIN,
199 .type = V4L2_CTRL_TYPE_BOOLEAN,
200 .name = "Auto Gain",
201 .minimum = 0,
202 .maximum = 1,
203 .step = 1,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300204#define AUTOGAIN_DEF 1
205 .default_value = AUTOGAIN_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300206 },
207 .set = sd_setautogain,
208 .get = sd_getautogain,
209 },
Jean-Francois Moine2797ba22009-02-05 15:12:24 -0300210/* ov7630/ov7648 only */
Hans de Goede97643982009-06-18 05:08:11 -0300211#define VFLIP_IDX 7
Jean-Francois Moine6c862742008-09-08 04:57:26 -0300212 {
213 {
214 .id = V4L2_CID_VFLIP,
215 .type = V4L2_CTRL_TYPE_BOOLEAN,
216 .name = "Vflip",
217 .minimum = 0,
218 .maximum = 1,
219 .step = 1,
Hans de Goedef8009522009-06-18 14:29:20 -0300220#define VFLIP_DEF 0
Jean-Francois Moine6c862742008-09-08 04:57:26 -0300221 .default_value = VFLIP_DEF,
222 },
223 .set = sd_setvflip,
224 .get = sd_getvflip,
225 },
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300226/* mt9v111 only */
Hans de Goede97643982009-06-18 05:08:11 -0300227#define INFRARED_IDX 8
Jean-Francois Moine0cae8962008-10-17 07:48:24 -0300228 {
229 {
230 .id = V4L2_CID_INFRARED,
231 .type = V4L2_CTRL_TYPE_BOOLEAN,
232 .name = "Infrared",
233 .minimum = 0,
234 .maximum = 1,
235 .step = 1,
236#define INFRARED_DEF 0
237 .default_value = INFRARED_DEF,
238 },
239 .set = sd_setinfrared,
240 .get = sd_getinfrared,
241 },
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300242/* ov7630/ov7648/ov7660 only */
243#define FREQ_IDX 9
244 {
245 {
246 .id = V4L2_CID_POWER_LINE_FREQUENCY,
247 .type = V4L2_CTRL_TYPE_MENU,
248 .name = "Light frequency filter",
249 .minimum = 0,
250 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
251 .step = 1,
252#define FREQ_DEF 2
253 .default_value = FREQ_DEF,
254 },
255 .set = sd_setfreq,
256 .get = sd_getfreq,
257 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300258};
259
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300260/* table of the disabled controls */
261static __u32 ctrl_dis[] = {
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300262 (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300263 /* SENSOR_HV7131R 0 */
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300264 (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300265 /* SENSOR_MI0360 1 */
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300266 (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300267 /* SENSOR_MO4000 2 */
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300268 (1 << VFLIP_IDX) | (1 << FREQ_IDX),
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300269 /* SENSOR_MT9V111 3 */
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300270 (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX),
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300271 /* SENSOR_OM6802 4 */
Hans de Goede1fec7472009-06-18 06:05:07 -0300272 (1 << INFRARED_IDX),
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300273 /* SENSOR_OV7630 5 */
Jean-Francois Moine2797ba22009-02-05 15:12:24 -0300274 (1 << INFRARED_IDX),
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300275 /* SENSOR_OV7648 6 */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300276 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX),
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300277 /* SENSOR_OV7660 7 */
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300278 (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX) |
279 (1 << FREQ_IDX), /* SENSOR_SP80708 8 */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -0300280};
281
Jean-Francois Moinecc611b82008-12-29 07:49:41 -0300282static const struct v4l2_pix_format vga_mode[] = {
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300283 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
284 .bytesperline = 160,
Jean-Francois Moine5d052942008-09-03 16:48:09 -0300285 .sizeimage = 160 * 120 * 4 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300286 .colorspace = V4L2_COLORSPACE_JPEG,
287 .priv = 2},
288 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
289 .bytesperline = 320,
290 .sizeimage = 320 * 240 * 3 / 8 + 590,
291 .colorspace = V4L2_COLORSPACE_JPEG,
292 .priv = 1},
293 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
294 .bytesperline = 640,
Hans de Goedea5d1cc32009-06-18 06:03:20 -0300295 /* Note 3 / 8 is not large enough, not even 5 / 8 is ?! */
296 .sizeimage = 640 * 480 * 3 / 4 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300297 .colorspace = V4L2_COLORSPACE_JPEG,
298 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300299};
300
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300301/*Data from sn9c102p+hv7131r */
302static const u8 sn_hv7131[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300303/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
304 0x00, 0x03, 0x64, 0x00, 0x1a, 0x20, 0x20, 0x20,
305/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300306 0x81, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300307/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
308 0x03, 0x00, 0x00, 0x01, 0x03, 0x28, 0x1e, 0x41,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300309/* reg18 reg19 reg1a reg1b */
310 0x0a, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300311};
312
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300313static const u8 sn_mi0360[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300314/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
315 0x00, 0x61, 0x44, 0x00, 0x1a, 0x20, 0x20, 0x20,
316/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300317 0x81, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300318/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
319 0x03, 0x00, 0x00, 0x02, 0x0a, 0x28, 0x1e, 0x61,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300320/* reg18 reg19 reg1a reg1b */
321 0x06, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300322};
323
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300324static const u8 sn_mo4000[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300325/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300326 0x00, 0x23, 0x60, 0x00, 0x1a, 0x00, 0x20, 0x18,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300327/* reg8 reg9 rega regb regc regd rege regf */
328 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
329/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
330 0x03, 0x00, 0x0b, 0x0f, 0x14, 0x28, 0x1e, 0x40,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300331/* reg18 reg19 reg1a reg1b */
332 0x08, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300333};
334
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300335static const u8 sn_mt9v111[0x1c] = {
336/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
337 0x00, 0x61, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
338/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300339 0x81, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300340/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
341 0x03, 0x00, 0x00, 0x02, 0x1c, 0x28, 0x1e, 0x40,
342/* reg18 reg19 reg1a reg1b */
343 0x06, 0x00, 0x00, 0x00
344};
345
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300346static const u8 sn_om6802[0x1c] = {
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300347/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Amauri Magagna46b4f2a2009-10-17 07:21:29 -0300348 0x00, 0x23, 0x72, 0x00, 0x1a, 0x20, 0x20, 0x19,
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300349/* reg8 reg9 rega regb regc regd rege regf */
350 0x80, 0x34, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
351/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
352 0x03, 0x00, 0x51, 0x01, 0x00, 0x28, 0x1e, 0x40,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300353/* reg18 reg19 reg1a reg1b */
354 0x05, 0x00, 0x00, 0x00
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300355};
356
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300357static const u8 sn_ov7630[0x1c] = {
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300358/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
359 0x00, 0x21, 0x40, 0x00, 0x1a, 0x20, 0x1f, 0x20,
360/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300361 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300362/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
363 0x03, 0x00, 0x04, 0x01, 0x0a, 0x28, 0x1e, 0xc2,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300364/* reg18 reg19 reg1a reg1b */
365 0x0b, 0x00, 0x00, 0x00
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300366};
367
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300368static const u8 sn_ov7648[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300369/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Jean-Francois Moine62703302008-11-11 08:42:56 -0300370 0x00, 0x63, 0x40, 0x00, 0x1a, 0x20, 0x20, 0x20,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300371/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300372 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300373/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
Jean-Francois Moine62703302008-11-11 08:42:56 -0300374 0x03, 0x00, 0x00, 0x01, 0x00, 0x28, 0x1e, 0x00,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300375/* reg18 reg19 reg1a reg1b */
376 0x0b, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300377};
378
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300379static const u8 sn_ov7660[0x1c] = {
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300380/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -0300381 0x00, 0x61, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300382/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -0300383 0x81, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -0300384/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
385 0x03, 0x00, 0x01, 0x01, 0x08, 0x28, 0x1e, 0x20,
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300386/* reg18 reg19 reg1a reg1b */
387 0x07, 0x00, 0x00, 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300388};
389
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -0300390static const u8 sn_sp80708[0x1c] = {
391/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */
392 0x00, 0x63, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20,
393/* reg8 reg9 rega regb regc regd rege regf */
Jean-Francois Moine98941e42009-11-02 09:56:59 -0300394 0x81, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -0300395/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */
396 0x03, 0x00, 0x00, 0x03, 0x04, 0x28, 0x1e, 0x00,
397/* reg18 reg19 reg1a reg1b */
398 0x07, 0x00, 0x00, 0x00
399};
400
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300401/* sequence specific to the sensors - !! index = SENSOR_xxx */
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300402static const u8 *sn_tb[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300403 sn_hv7131,
404 sn_mi0360,
405 sn_mo4000,
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300406 sn_mt9v111,
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300407 sn_om6802,
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300408 sn_ov7630,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300409 sn_ov7648,
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -0300410 sn_ov7660,
411 sn_sp80708
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300412};
413
Jean-Francois Moineb083b922009-02-01 14:20:07 -0300414/* default gamma table */
Jean-Francois Moine98819182009-01-19 07:37:33 -0300415static const u8 gamma_def[17] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300416 0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99,
417 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
418};
Jean-Francois Moineb083b922009-02-01 14:20:07 -0300419/* gamma for sensors HV7131R and MT9V111 */
420static const u8 gamma_spec_1[17] = {
421 0x08, 0x3a, 0x52, 0x65, 0x75, 0x83, 0x91, 0x9d,
422 0xa9, 0xb4, 0xbe, 0xc8, 0xd2, 0xdb, 0xe4, 0xed, 0xf5
423};
424/* gamma for sensor SP80708 */
425static const u8 gamma_spec_2[17] = {
426 0x0a, 0x2d, 0x4e, 0x68, 0x7d, 0x8f, 0x9f, 0xab,
427 0xb7, 0xc2, 0xcc, 0xd3, 0xd8, 0xde, 0xe2, 0xe5, 0xe6
428};
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -0300429
Jean-Francois Moine803f9cc2008-10-04 14:17:02 -0300430/* color matrix and offsets */
Jean-Francois Moine98819182009-01-19 07:37:33 -0300431static const u8 reg84[] = {
Jean-Francois Moine803f9cc2008-10-04 14:17:02 -0300432 0x14, 0x00, 0x27, 0x00, 0x07, 0x00, /* YR YG YB gains */
433 0xe8, 0x0f, 0xda, 0x0f, 0x40, 0x00, /* UR UG UB */
434 0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f, /* VR VG VB */
435 0x00, 0x00, 0x00 /* YUV offsets */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300436};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300437static const u8 hv7131r_sensor_init[][8] = {
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300438 {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
439 {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10},
440 {0xd1, 0x11, 0x40, 0xff, 0x7f, 0x7f, 0x7f, 0x10},
441/* {0x91, 0x11, 0x44, 0x00, 0x00, 0x00, 0x00, 0x10}, */
442 {0xd1, 0x11, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
443 {0xd1, 0x11, 0x14, 0x01, 0xe2, 0x02, 0x82, 0x10},
444/* {0x91, 0x11, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10}, */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300445
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300446 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
447 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
448 {0xc1, 0x11, 0x25, 0x00, 0x61, 0xa8, 0x00, 0x10},
449 {0xa1, 0x11, 0x30, 0x22, 0x00, 0x00, 0x00, 0x10},
450 {0xc1, 0x11, 0x31, 0x20, 0x2e, 0x20, 0x00, 0x10},
451 {0xc1, 0x11, 0x25, 0x00, 0xc3, 0x50, 0x00, 0x10},
452 {0xa1, 0x11, 0x30, 0x07, 0x00, 0x00, 0x00, 0x10}, /* gain14 */
453 {0xc1, 0x11, 0x31, 0x10, 0x10, 0x10, 0x00, 0x10}, /* r g b 101a10 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300454
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300455 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
456 {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -0300457 {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300458 {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
459 {0xa1, 0x11, 0x23, 0x09, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300460
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300461 {0xa1, 0x11, 0x01, 0x08, 0x00, 0x00, 0x00, 0x10},
462 {0xa1, 0x11, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
463 {0xa1, 0x11, 0x21, 0xd0, 0x00, 0x00, 0x00, 0x10},
464 {0xa1, 0x11, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
465 {0xa1, 0x11, 0x23, 0x10, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300466 {0xa1, 0x11, 0x01, 0x18, 0x00, 0x00, 0x00, 0x10},
467 /* set sensor clock */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300468 {}
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300469};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300470static const u8 mi0360_sensor_init[][8] = {
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300471 {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
Jean-Francois Moine98819182009-01-19 07:37:33 -0300472 {0xb1, 0x5d, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300473 {0xb1, 0x5d, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300474 {0xd1, 0x5d, 0x01, 0x00, 0x08, 0x00, 0x16, 0x10},
475 {0xd1, 0x5d, 0x03, 0x01, 0xe2, 0x02, 0x82, 0x10},
476 {0xd1, 0x5d, 0x05, 0x00, 0x09, 0x00, 0x53, 0x10},
477 {0xb1, 0x5d, 0x0d, 0x00, 0x02, 0x00, 0x00, 0x10},
478 {0xd1, 0x5d, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
479 {0xd1, 0x5d, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10},
480 {0xd1, 0x5d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
481 {0xd1, 0x5d, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
482 {0xd1, 0x5d, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
483 {0xd1, 0x5d, 0x14, 0x00, 0x00, 0x00, 0x00, 0x10},
484 {0xd1, 0x5d, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10},
485 {0xd1, 0x5d, 0x18, 0x00, 0x00, 0x00, 0x00, 0x10},
486 {0xd1, 0x5d, 0x1a, 0x00, 0x00, 0x00, 0x00, 0x10},
487 {0xd1, 0x5d, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10},
488 {0xb1, 0x5d, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10},
489 {0xd1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
490 {0xd1, 0x5d, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
491 {0xd1, 0x5d, 0x24, 0x00, 0x00, 0x00, 0x00, 0x10},
492 {0xd1, 0x5d, 0x26, 0x00, 0x00, 0x00, 0x24, 0x10},
Jean-Francois Moine98819182009-01-19 07:37:33 -0300493 {0xd1, 0x5d, 0x2f, 0xf7, 0xB0, 0x00, 0x04, 0x10},
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300494 {0xd1, 0x5d, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10},
495 {0xd1, 0x5d, 0x33, 0x00, 0x00, 0x01, 0x00, 0x10},
496 {0xb1, 0x5d, 0x3d, 0x06, 0x8f, 0x00, 0x00, 0x10},
497 {0xd1, 0x5d, 0x40, 0x01, 0xe0, 0x00, 0xd1, 0x10},
498 {0xb1, 0x5d, 0x44, 0x00, 0x82, 0x00, 0x00, 0x10},
499 {0xd1, 0x5d, 0x58, 0x00, 0x78, 0x00, 0x43, 0x10},
500 {0xd1, 0x5d, 0x5a, 0x00, 0x00, 0x00, 0x00, 0x10},
501 {0xd1, 0x5d, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x10},
502 {0xd1, 0x5d, 0x5e, 0x00, 0x00, 0xa3, 0x1d, 0x10},
503 {0xb1, 0x5d, 0x62, 0x04, 0x11, 0x00, 0x00, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300504
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300505 {0xb1, 0x5d, 0x20, 0x91, 0x01, 0x00, 0x00, 0x10},
506 {0xb1, 0x5d, 0x20, 0x11, 0x01, 0x00, 0x00, 0x10},
507 {0xb1, 0x5d, 0x09, 0x00, 0x64, 0x00, 0x00, 0x10},
508 {0xd1, 0x5d, 0x2b, 0x00, 0xa0, 0x00, 0xb0, 0x10},
509 {0xd1, 0x5d, 0x2d, 0x00, 0xa0, 0x00, 0xa0, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300510
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300511 {0xb1, 0x5d, 0x0a, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor clck ?2 */
512 {0xb1, 0x5d, 0x06, 0x00, 0x30, 0x00, 0x00, 0x10},
513 {0xb1, 0x5d, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10},
514 {0xb1, 0x5d, 0x09, 0x02, 0x35, 0x00, 0x00, 0x10}, /* exposure 2 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300515
Jean-Francois Moine8c2ba442009-01-13 05:55:40 -0300516 {0xd1, 0x5d, 0x2b, 0x00, 0xb9, 0x00, 0xe3, 0x10},
517 {0xd1, 0x5d, 0x2d, 0x00, 0x5f, 0x00, 0xb9, 0x10}, /* 42 */
518/* {0xb1, 0x5d, 0x35, 0x00, 0x67, 0x00, 0x00, 0x10}, * gain orig */
519/* {0xb1, 0x5d, 0x35, 0x00, 0x20, 0x00, 0x00, 0x10}, * gain */
520 {0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10}, /* update */
521 {0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10}, /* sensor on */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300522 {}
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300523};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300524static const u8 mo4000_sensor_init[][8] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300525 {0xa1, 0x21, 0x01, 0x02, 0x00, 0x00, 0x00, 0x10},
526 {0xa1, 0x21, 0x02, 0x00, 0x00, 0x00, 0x00, 0x10},
527 {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
528 {0xa1, 0x21, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10},
529 {0xa1, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10},
530 {0xa1, 0x21, 0x05, 0x04, 0x00, 0x00, 0x00, 0x10},
531 {0xa1, 0x21, 0x06, 0x80, 0x00, 0x00, 0x00, 0x10},
532 {0xa1, 0x21, 0x06, 0x81, 0x00, 0x00, 0x00, 0x10},
533 {0xa1, 0x21, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x10},
534 {0xa1, 0x21, 0x11, 0x00, 0x00, 0x00, 0x00, 0x10},
535 {0xa1, 0x21, 0x11, 0x20, 0x00, 0x00, 0x00, 0x10},
536 {0xa1, 0x21, 0x11, 0x30, 0x00, 0x00, 0x00, 0x10},
537 {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
538 {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
539 {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
540 {0xa1, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10},
541 {0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10},
542 {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10},
543 {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
544 {0xa1, 0x21, 0x11, 0x38, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300545 {}
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300546};
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300547static const u8 mt9v111_sensor_init[][8] = {
548 {0xb1, 0x5c, 0x0d, 0x00, 0x01, 0x00, 0x00, 0x10}, /* reset? */
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300549 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300550 {0xb1, 0x5c, 0x0d, 0x00, 0x00, 0x00, 0x00, 0x10},
551 {0xb1, 0x5c, 0x01, 0x00, 0x01, 0x00, 0x00, 0x10}, /* IFP select */
552 {0xb1, 0x5c, 0x08, 0x04, 0x80, 0x00, 0x00, 0x10}, /* output fmt ctrl */
553 {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10}, /* op mode ctrl */
Jean-Francois Moine2687a2f2009-02-01 14:48:55 -0300554 {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
555 {0xb1, 0x5c, 0x03, 0x01, 0xe1, 0x00, 0x00, 0x10},
556 {0xb1, 0x5c, 0x04, 0x02, 0x81, 0x00, 0x00, 0x10},
557 {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300558 {0xb1, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10}, /* sensor select */
Jean-Francois Moine2687a2f2009-02-01 14:48:55 -0300559 {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10},
560 {0xb1, 0x5c, 0x03, 0x01, 0xe6, 0x00, 0x00, 0x10},
561 {0xb1, 0x5c, 0x04, 0x02, 0x86, 0x00, 0x00, 0x10},
562 {0xb1, 0x5c, 0x05, 0x00, 0x04, 0x00, 0x00, 0x10},
563 {0xb1, 0x5c, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300564 {0xb1, 0x5c, 0x08, 0x00, 0x08, 0x00, 0x00, 0x10}, /* row start */
Jean-Francois Moine2687a2f2009-02-01 14:48:55 -0300565 {0xb1, 0x5c, 0x0e, 0x00, 0x08, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300566 {0xb1, 0x5c, 0x02, 0x00, 0x16, 0x00, 0x00, 0x10}, /* col start */
567 {0xb1, 0x5c, 0x03, 0x01, 0xe7, 0x00, 0x00, 0x10}, /* window height */
568 {0xb1, 0x5c, 0x04, 0x02, 0x87, 0x00, 0x00, 0x10}, /* window width */
569 {0xb1, 0x5c, 0x07, 0x30, 0x02, 0x00, 0x00, 0x10}, /* output ctrl */
570 {0xb1, 0x5c, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x10}, /* shutter delay */
571 {0xb1, 0x5c, 0x12, 0x00, 0xb0, 0x00, 0x00, 0x10}, /* zoom col start */
572 {0xb1, 0x5c, 0x13, 0x00, 0x7c, 0x00, 0x00, 0x10}, /* zoom row start */
573 {0xb1, 0x5c, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* digital zoom */
574 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10}, /* read mode */
575 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300576 {}
577};
578static const u8 mt9v111_sensor_param1[][8] = {
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300579 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
580 {0xb1, 0x5c, 0x20, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine2687a2f2009-02-01 14:48:55 -0300581 {0xb1, 0x5c, 0x09, 0x01, 0x2c, 0x00, 0x00, 0x10},
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300582 {0xd1, 0x5c, 0x2b, 0x00, 0x33, 0x00, 0xa0, 0x10}, /* green1 gain */
583 {0xd1, 0x5c, 0x2d, 0x00, 0xa0, 0x00, 0x33, 0x10}, /* red gain */
584 /*******/
585 {0xb1, 0x5c, 0x06, 0x00, 0x1e, 0x00, 0x00, 0x10}, /* vert blanking */
586 {0xb1, 0x5c, 0x05, 0x00, 0x0a, 0x00, 0x00, 0x10}, /* horiz blanking */
587 {0xd1, 0x5c, 0x2c, 0x00, 0xad, 0x00, 0xad, 0x10}, /* blue gain */
588 {0xb1, 0x5c, 0x35, 0x01, 0xc0, 0x00, 0x00, 0x10}, /* global gain */
589 {}
590};
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300591static const u8 om6802_init0[2][8] = {
592/*fixme: variable*/
593 {0xa0, 0x34, 0x29, 0x0e, 0x00, 0x00, 0x00, 0x10},
594 {0xa0, 0x34, 0x23, 0xb0, 0x00, 0x00, 0x00, 0x10},
595};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300596static const u8 om6802_sensor_init[][8] = {
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300597 {0xa0, 0x34, 0xdf, 0x6d, 0x00, 0x00, 0x00, 0x10},
598 /* factory mode */
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300599 {0xa0, 0x34, 0xdd, 0x18, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300600 {0xa0, 0x34, 0x5a, 0xc0, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300601/* {0xa0, 0x34, 0xfb, 0x11, 0x00, 0x00, 0x00, 0x10}, */
602 {0xa0, 0x34, 0xf0, 0x04, 0x00, 0x00, 0x00, 0x10},
603 /* white balance & auto-exposure */
604/* {0xa0, 0x34, 0xf1, 0x02, 0x00, 0x00, 0x00, 0x10},
605 * set color mode */
606/* {0xa0, 0x34, 0xfe, 0x5b, 0x00, 0x00, 0x00, 0x10},
607 * max AGC value in AE */
608/* {0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10},
609 * preset AGC */
610/* {0xa0, 0x34, 0xe6, 0x00, 0x00, 0x00, 0x00, 0x10},
611 * preset brightness */
612/* {0xa0, 0x34, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x10},
613 * preset contrast */
614/* {0xa0, 0x34, 0xe8, 0x31, 0x00, 0x00, 0x00, 0x10},
615 * preset gamma */
616 {0xa0, 0x34, 0xe9, 0x0f, 0x00, 0x00, 0x00, 0x10},
617 /* luminance mode (0x4f = AE) */
618 {0xa0, 0x34, 0xe4, 0xff, 0x00, 0x00, 0x00, 0x10},
619 /* preset shutter */
620/* {0xa0, 0x34, 0xef, 0x00, 0x00, 0x00, 0x00, 0x10},
621 * auto frame rate */
622/* {0xa0, 0x34, 0xfb, 0xee, 0x00, 0x00, 0x00, 0x10}, */
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300623 {0xa0, 0x34, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
624 {}
625};
626static const u8 om6802_sensor_param1[][8] = {
627 {0xa0, 0x34, 0x71, 0x84, 0x00, 0x00, 0x00, 0x10},
628 {0xa0, 0x34, 0x72, 0x05, 0x00, 0x00, 0x00, 0x10},
629 {0xa0, 0x34, 0x68, 0x80, 0x00, 0x00, 0x00, 0x10},
630 {0xa0, 0x34, 0x69, 0x01, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moined2d16e92008-09-03 16:47:23 -0300631 {}
632};
Jean-Francois Moine98819182009-01-19 07:37:33 -0300633static const u8 ov7630_sensor_init[][8] = {
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300634 {0xa1, 0x21, 0x76, 0x01, 0x00, 0x00, 0x00, 0x10},
635 {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300636 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300637 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
638 {0xa1, 0x21, 0x12, 0xc8, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300639 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300640 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300641/* win: i2c_r from 00 to 80 */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300642 {0xd1, 0x21, 0x03, 0x80, 0x10, 0x20, 0x80, 0x10},
643 {0xb1, 0x21, 0x0c, 0x20, 0x20, 0x00, 0x00, 0x10},
Hans de Goedecc7b5b52009-06-18 05:14:42 -0300644/* HDG: 0x11 was 0x00 change to 0x01 for better exposure (15 fps instead of 30)
645 0x13 was 0xc0 change to 0xc3 for auto gain and exposure */
646 {0xd1, 0x21, 0x11, 0x01, 0x48, 0xc3, 0x00, 0x10},
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300647 {0xb1, 0x21, 0x15, 0x80, 0x03, 0x00, 0x00, 0x10},
648 {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
649 {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
650 {0xd1, 0x21, 0x1f, 0x00, 0x80, 0x80, 0x80, 0x10},
651 {0xd1, 0x21, 0x23, 0xde, 0x10, 0x8a, 0xa0, 0x10},
652 {0xc1, 0x21, 0x27, 0xca, 0xa2, 0x74, 0x00, 0x10},
653 {0xd1, 0x21, 0x2a, 0x88, 0x00, 0x88, 0x01, 0x10},
654 {0xc1, 0x21, 0x2e, 0x80, 0x00, 0x18, 0x00, 0x10},
655 {0xa1, 0x21, 0x21, 0x08, 0x00, 0x00, 0x00, 0x10},
656 {0xa1, 0x21, 0x22, 0x00, 0x00, 0x00, 0x00, 0x10},
657 {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10},
658 {0xb1, 0x21, 0x32, 0xc2, 0x08, 0x00, 0x00, 0x10},
659 {0xb1, 0x21, 0x4c, 0x00, 0x00, 0x00, 0x00, 0x10},
660 {0xd1, 0x21, 0x60, 0x05, 0x40, 0x12, 0x57, 0x10},
661 {0xa1, 0x21, 0x64, 0x73, 0x00, 0x00, 0x00, 0x10},
662 {0xd1, 0x21, 0x65, 0x00, 0x55, 0x01, 0xac, 0x10},
663 {0xa1, 0x21, 0x69, 0x38, 0x00, 0x00, 0x00, 0x10},
664 {0xd1, 0x21, 0x6f, 0x1f, 0x01, 0x00, 0x10, 0x10},
665 {0xd1, 0x21, 0x73, 0x50, 0x20, 0x02, 0x01, 0x10},
666 {0xd1, 0x21, 0x77, 0xf3, 0x90, 0x98, 0x98, 0x10},
667 {0xc1, 0x21, 0x7b, 0x00, 0x4c, 0xf7, 0x00, 0x10},
668 {0xd1, 0x21, 0x17, 0x1b, 0xbd, 0x05, 0xf6, 0x10},
669 {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
670/* */
671 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
672 {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
673/*fixme: + 0x12, 0x04*/
Jean-Francois Moine6c862742008-09-08 04:57:26 -0300674/* {0xa1, 0x21, 0x75, 0x82, 0x00, 0x00, 0x00, 0x10}, * COMN
675 * set by setvflip */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300676 {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
677 {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
678 {0xb1, 0x21, 0x01, 0x80, 0x80, 0x00, 0x00, 0x10},
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300679/* */
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300680/* {0xa1, 0x21, 0x2a, 0x88, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
681/* {0xa1, 0x21, 0x2b, 0x34, 0x00, 0x00, 0x00, 0x10}, * set by setfreq */
Jean-Francois Moine05b809c2008-09-03 16:47:59 -0300682/* */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300683 {0xa1, 0x21, 0x10, 0x83, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine91de65a2008-09-03 17:12:18 -0300684/* {0xb1, 0x21, 0x01, 0x88, 0x70, 0x00, 0x00, 0x10}, */
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -0300685 {}
686};
Jean-Francois Moine62703302008-11-11 08:42:56 -0300687
Jean-Francois Moine98819182009-01-19 07:37:33 -0300688static const u8 ov7648_sensor_init[][8] = {
Jean-Francois Moine62703302008-11-11 08:42:56 -0300689 {0xa1, 0x21, 0x76, 0x00, 0x00, 0x00, 0x00, 0x10},
690 {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset */
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300691 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moine62703302008-11-11 08:42:56 -0300692 {0xa1, 0x21, 0x12, 0x00, 0x00, 0x00, 0x00, 0x10},
693 {0xd1, 0x21, 0x03, 0xa4, 0x30, 0x88, 0x00, 0x10},
694 {0xb1, 0x21, 0x11, 0x80, 0x08, 0x00, 0x00, 0x10},
695 {0xc1, 0x21, 0x13, 0xa0, 0x04, 0x84, 0x00, 0x10},
696 {0xd1, 0x21, 0x17, 0x1a, 0x02, 0xba, 0xf4, 0x10},
697 {0xa1, 0x21, 0x1b, 0x04, 0x00, 0x00, 0x00, 0x10},
698 {0xd1, 0x21, 0x1f, 0x41, 0xc0, 0x80, 0x80, 0x10},
699 {0xd1, 0x21, 0x23, 0xde, 0xa0, 0x80, 0x32, 0x10},
700 {0xd1, 0x21, 0x27, 0xfe, 0xa0, 0x00, 0x91, 0x10},
701 {0xd1, 0x21, 0x2b, 0x00, 0x88, 0x85, 0x80, 0x10},
702 {0xc1, 0x21, 0x2f, 0x9c, 0x00, 0xc4, 0x00, 0x10},
703 {0xd1, 0x21, 0x60, 0xa6, 0x60, 0x88, 0x12, 0x10},
704 {0xd1, 0x21, 0x64, 0x88, 0x00, 0x00, 0x94, 0x10},
705 {0xd1, 0x21, 0x68, 0x7a, 0x0c, 0x00, 0x00, 0x10},
706 {0xd1, 0x21, 0x6c, 0x11, 0x33, 0x22, 0x00, 0x10},
707 {0xd1, 0x21, 0x70, 0x11, 0x00, 0x10, 0x50, 0x10},
708 {0xd1, 0x21, 0x74, 0x20, 0x06, 0x00, 0xb5, 0x10},
709 {0xd1, 0x21, 0x78, 0x8a, 0x00, 0x00, 0x00, 0x10},
710 {0xb1, 0x21, 0x7c, 0x00, 0x43, 0x00, 0x00, 0x10},
711
712 {0xd1, 0x21, 0x21, 0x86, 0x00, 0xde, 0xa0, 0x10},
713/* {0xd1, 0x21, 0x25, 0x80, 0x32, 0xfe, 0xa0, 0x10}, jfm done */
714/* {0xd1, 0x21, 0x29, 0x00, 0x91, 0x00, 0x88, 0x10}, jfm done */
Hans de Goede37c6dbe2009-06-18 07:35:36 -0300715/* {0xb1, 0x21, 0x2d, 0x85, 0x00, 0x00, 0x00, 0x10}, set by setfreq */
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300716 {}
717};
718static const u8 ov7648_sensor_param1[][8] = {
Jean-Francois Moine62703302008-11-11 08:42:56 -0300719/* {0xa1, 0x21, 0x12, 0x08, 0x00, 0x00, 0x00, 0x10}, jfm done */
Jean-Francois Moine2797ba22009-02-05 15:12:24 -0300720/* {0xa1, 0x21, 0x75, 0x06, 0x00, 0x00, 0x00, 0x10}, * COMN
721 * set by setvflip */
Jean-Francois Moine62703302008-11-11 08:42:56 -0300722 {0xa1, 0x21, 0x19, 0x02, 0x00, 0x00, 0x00, 0x10},
723 {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
724/* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
725/* {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}, * GAIN - def */
726/* {0xb1, 0x21, 0x01, 0x6c, 0x6c, 0x00, 0x00, 0x10}, * B R - def: 80 */
727/*...*/
728 {0xa1, 0x21, 0x11, 0x81, 0x00, 0x00, 0x00, 0x10}, /* CLKRC */
729/* {0xa1, 0x21, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
730/* {0xa1, 0x21, 0x16, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
731/* {0xa1, 0x21, 0x2a, 0x91, 0x00, 0x00, 0x00, 0x10}, jfm done */
732/* {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, jfm done */
733/* {0xb1, 0x21, 0x01, 0x64, 0x84, 0x00, 0x00, 0x10}, * B R - def: 80 */
734
735 {}
736};
737
Jean-Francois Moine98819182009-01-19 07:37:33 -0300738static const u8 ov7660_sensor_init[][8] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300739 {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300740 {0xdd, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 20ms */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300741 {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300742 /* Outformat = rawRGB */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300743 {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */
Jean-Francois Moined8f400e2009-07-08 06:33:44 -0300744 {0xd1, 0x21, 0x00, 0x01, 0x74, 0x92, 0x00, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300745 /* GAIN BLUE RED VREF */
746 {0xd1, 0x21, 0x04, 0x00, 0x7d, 0x62, 0x00, 0x10},
747 /* COM 1 BAVE GEAVE AECHH */
748 {0xb1, 0x21, 0x08, 0x83, 0x01, 0x00, 0x00, 0x10}, /* RAVE COM2 */
749 {0xd1, 0x21, 0x0c, 0x00, 0x08, 0x04, 0x4f, 0x10}, /* COM 3 4 5 6 */
Jean-Francois Moine47f7f6f2009-08-25 06:14:54 -0300750 {0xd1, 0x21, 0x10, 0x7f, 0x40, 0x05, 0xff, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300751 /* AECH CLKRC COM7 COM8 */
752 {0xc1, 0x21, 0x14, 0x2c, 0x00, 0x02, 0x00, 0x10}, /* COM9 COM10 */
753 {0xd1, 0x21, 0x17, 0x10, 0x60, 0x02, 0x7b, 0x10},
754 /* HSTART HSTOP VSTRT VSTOP */
755 {0xa1, 0x21, 0x1b, 0x02, 0x00, 0x00, 0x00, 0x10}, /* PSHFT */
756 {0xb1, 0x21, 0x1e, 0x01, 0x0e, 0x00, 0x00, 0x10}, /* MVFP LAEC */
757 {0xd1, 0x21, 0x20, 0x07, 0x07, 0x07, 0x07, 0x10},
758 /* BOS GBOS GROS ROS (BGGR offset) */
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300759/* {0xd1, 0x21, 0x24, 0x68, 0x58, 0xd4, 0x80, 0x10}, */
760 {0xd1, 0x21, 0x24, 0x78, 0x68, 0xd4, 0x80, 0x10},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300761 /* AEW AEB VPT BBIAS */
762 {0xd1, 0x21, 0x28, 0x80, 0x30, 0x00, 0x00, 0x10},
763 /* GbBIAS RSVD EXHCH EXHCL */
764 {0xd1, 0x21, 0x2c, 0x80, 0x00, 0x00, 0x62, 0x10},
765 /* RBIAS ADVFL ASDVFH YAVE */
766 {0xc1, 0x21, 0x30, 0x08, 0x30, 0xb4, 0x00, 0x10},
767 /* HSYST HSYEN HREF */
768 {0xd1, 0x21, 0x33, 0x00, 0x07, 0x84, 0x00, 0x10}, /* reserved */
769 {0xd1, 0x21, 0x37, 0x0c, 0x02, 0x43, 0x00, 0x10},
770 /* ADC ACOM OFON TSLB */
771 {0xd1, 0x21, 0x3b, 0x02, 0x6c, 0x19, 0x0e, 0x10},
772 /* COM11 COM12 COM13 COM14 */
773 {0xd1, 0x21, 0x3f, 0x41, 0xc1, 0x22, 0x08, 0x10},
774 /* EDGE COM15 COM16 COM17 */
775 {0xd1, 0x21, 0x43, 0xf0, 0x10, 0x78, 0xa8, 0x10}, /* reserved */
776 {0xd1, 0x21, 0x47, 0x60, 0x80, 0x00, 0x00, 0x10}, /* reserved */
777 {0xd1, 0x21, 0x4b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* reserved */
778 {0xd1, 0x21, 0x4f, 0x46, 0x36, 0x0f, 0x17, 0x10}, /* MTX 1 2 3 4 */
779 {0xd1, 0x21, 0x53, 0x7f, 0x96, 0x40, 0x40, 0x10}, /* MTX 5 6 7 8 */
780 {0xb1, 0x21, 0x57, 0x40, 0x0f, 0x00, 0x00, 0x10}, /* MTX9 MTXS */
781 {0xd1, 0x21, 0x59, 0xba, 0x9a, 0x22, 0xb9, 0x10}, /* reserved */
782 {0xd1, 0x21, 0x5d, 0x9b, 0x10, 0xf0, 0x05, 0x10}, /* reserved */
783 {0xa1, 0x21, 0x61, 0x60, 0x00, 0x00, 0x00, 0x10}, /* reserved */
784 {0xd1, 0x21, 0x62, 0x00, 0x00, 0x50, 0x30, 0x10},
785 /* LCC1 LCC2 LCC3 LCC4 */
786 {0xa1, 0x21, 0x66, 0x00, 0x00, 0x00, 0x00, 0x10}, /* LCC5 */
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300787 {0xd1, 0x21, 0x67, 0x80, 0x7a, 0x90, 0x80, 0x10}, /* MANU */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300788 {0xa1, 0x21, 0x6b, 0x0a, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300789 /* band gap reference [0:3] DBLV */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300790 {0xd1, 0x21, 0x6c, 0x30, 0x48, 0x80, 0x74, 0x10}, /* gamma curve */
791 {0xd1, 0x21, 0x70, 0x64, 0x60, 0x5c, 0x58, 0x10}, /* gamma curve */
792 {0xd1, 0x21, 0x74, 0x54, 0x4c, 0x40, 0x38, 0x10}, /* gamma curve */
793 {0xd1, 0x21, 0x78, 0x34, 0x30, 0x2f, 0x2b, 0x10}, /* gamma curve */
794 {0xd1, 0x21, 0x7c, 0x03, 0x07, 0x17, 0x34, 0x10}, /* gamma curve */
795 {0xd1, 0x21, 0x80, 0x41, 0x4d, 0x58, 0x63, 0x10}, /* gamma curve */
796 {0xd1, 0x21, 0x84, 0x6e, 0x77, 0x87, 0x95, 0x10}, /* gamma curve */
797 {0xc1, 0x21, 0x88, 0xaf, 0xc7, 0xdf, 0x00, 0x10}, /* gamma curve */
798 {0xc1, 0x21, 0x8b, 0x99, 0x99, 0xcf, 0x00, 0x10}, /* reserved */
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300799 {0xb1, 0x21, 0x92, 0x00, 0x00, 0x00, 0x00, 0x10}, /* DM_LNL/H */
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300800/* not in all ms-win traces*/
Jean-Francois Moine47f7f6f2009-08-25 06:14:54 -0300801 {0xa1, 0x21, 0xa1, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300802 {}
803};
804static const u8 ov7660_sensor_param1[][8] = {
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300805 {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10}, /* MVFP */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300806 /* bits[3..0]reserved */
807 {0xa1, 0x21, 0x1e, 0x01, 0x00, 0x00, 0x00, 0x10},
808 {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
809 /* VREF vertical frame ctrl */
810 {0xa1, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300811 {0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10}, /* AECH 0x20 */
812 {0xa1, 0x21, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFL */
813 {0xa1, 0x21, 0x2e, 0x00, 0x00, 0x00, 0x00, 0x10}, /* ADVFH */
814 {0xa1, 0x21, 0x00, 0x1f, 0x00, 0x00, 0x00, 0x10}, /* GAIN */
815/* {0xb1, 0x21, 0x01, 0x78, 0x78, 0x00, 0x00, 0x10}, * BLUE */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300816/****** (some exchanges in the win trace) ******/
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300817/*fixme:param2*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300818 {0xa1, 0x21, 0x93, 0x00, 0x00, 0x00, 0x00, 0x10},/* dummy line hight */
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300819 {0xa1, 0x21, 0x92, 0x25, 0x00, 0x00, 0x00, 0x10}, /* dummy line low */
820 {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCH */
821 {0xa1, 0x21, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}, /* EXHCL */
822/* {0xa1, 0x21, 0x02, 0x90, 0x00, 0x00, 0x00, 0x10}, * RED */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300823/****** (some exchanges in the win trace) ******/
Jean-Francois Moine738608a2008-07-28 06:41:51 -0300824/******!! startsensor KO if changed !!****/
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300825/*fixme: param3*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300826 {0xa1, 0x21, 0x93, 0x01, 0x00, 0x00, 0x00, 0x10},
827 {0xa1, 0x21, 0x92, 0xff, 0x00, 0x00, 0x00, 0x10},
828 {0xa1, 0x21, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x10},
829 {0xa1, 0x21, 0x2b, 0xc3, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -0300830 {}
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300831};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300832
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -0300833static const u8 sp80708_sensor_init[][8] = {
834 {0xa1, 0x18, 0x06, 0xf9, 0x00, 0x00, 0x00, 0x10},
835 {0xa1, 0x18, 0x09, 0x1f, 0x00, 0x00, 0x00, 0x10},
836 {0xa1, 0x18, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x10},
837 {0xa1, 0x18, 0x0d, 0xc0, 0x00, 0x00, 0x00, 0x10},
838 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
839 {0xa1, 0x18, 0x0f, 0x0f, 0x00, 0x00, 0x00, 0x10},
840 {0xa1, 0x18, 0x10, 0x40, 0x00, 0x00, 0x00, 0x10},
841 {0xa1, 0x18, 0x11, 0x4e, 0x00, 0x00, 0x00, 0x10},
842 {0xa1, 0x18, 0x12, 0x53, 0x00, 0x00, 0x00, 0x10},
843 {0xa1, 0x18, 0x15, 0x80, 0x00, 0x00, 0x00, 0x10},
844 {0xa1, 0x18, 0x18, 0x18, 0x00, 0x00, 0x00, 0x10},
845 {0xa1, 0x18, 0x19, 0x18, 0x00, 0x00, 0x00, 0x10},
846 {0xa1, 0x18, 0x1a, 0x10, 0x00, 0x00, 0x00, 0x10},
847 {0xa1, 0x18, 0x1b, 0x10, 0x00, 0x00, 0x00, 0x10},
848 {0xa1, 0x18, 0x1c, 0x28, 0x00, 0x00, 0x00, 0x10},
849 {0xa1, 0x18, 0x1d, 0x02, 0x00, 0x00, 0x00, 0x10},
850 {0xa1, 0x18, 0x1e, 0x10, 0x00, 0x00, 0x00, 0x10},
851 {0xa1, 0x18, 0x26, 0x04, 0x00, 0x00, 0x00, 0x10},
852 {0xa1, 0x18, 0x27, 0x1e, 0x00, 0x00, 0x00, 0x10},
853 {0xa1, 0x18, 0x28, 0x5a, 0x00, 0x00, 0x00, 0x10},
854 {0xa1, 0x18, 0x29, 0x28, 0x00, 0x00, 0x00, 0x10},
855 {0xa1, 0x18, 0x2a, 0x78, 0x00, 0x00, 0x00, 0x10},
856 {0xa1, 0x18, 0x2b, 0x01, 0x00, 0x00, 0x00, 0x10},
857 {0xa1, 0x18, 0x2c, 0xf7, 0x00, 0x00, 0x00, 0x10},
858 {0xa1, 0x18, 0x2d, 0x2d, 0x00, 0x00, 0x00, 0x10},
859 {0xa1, 0x18, 0x2e, 0xd5, 0x00, 0x00, 0x00, 0x10},
860 {0xa1, 0x18, 0x39, 0x42, 0x00, 0x00, 0x00, 0x10},
861 {0xa1, 0x18, 0x3a, 0x67, 0x00, 0x00, 0x00, 0x10},
862 {0xa1, 0x18, 0x3b, 0x87, 0x00, 0x00, 0x00, 0x10},
863 {0xa1, 0x18, 0x3c, 0xa3, 0x00, 0x00, 0x00, 0x10},
864 {0xa1, 0x18, 0x3d, 0xb0, 0x00, 0x00, 0x00, 0x10},
865 {0xa1, 0x18, 0x3e, 0xbc, 0x00, 0x00, 0x00, 0x10},
866 {0xa1, 0x18, 0x3f, 0xc8, 0x00, 0x00, 0x00, 0x10},
867 {0xa1, 0x18, 0x40, 0xd4, 0x00, 0x00, 0x00, 0x10},
868 {0xa1, 0x18, 0x41, 0xdf, 0x00, 0x00, 0x00, 0x10},
869 {0xa1, 0x18, 0x42, 0xea, 0x00, 0x00, 0x00, 0x10},
870 {0xa1, 0x18, 0x43, 0xf5, 0x00, 0x00, 0x00, 0x10},
871 {0xa1, 0x18, 0x45, 0x80, 0x00, 0x00, 0x00, 0x10},
872 {0xa1, 0x18, 0x46, 0x60, 0x00, 0x00, 0x00, 0x10},
873 {0xa1, 0x18, 0x47, 0x50, 0x00, 0x00, 0x00, 0x10},
874 {0xa1, 0x18, 0x48, 0x30, 0x00, 0x00, 0x00, 0x10},
875 {0xa1, 0x18, 0x49, 0x01, 0x00, 0x00, 0x00, 0x10},
876 {0xa1, 0x18, 0x4d, 0xae, 0x00, 0x00, 0x00, 0x10},
877 {0xa1, 0x18, 0x4e, 0x03, 0x00, 0x00, 0x00, 0x10},
878 {0xa1, 0x18, 0x4f, 0x66, 0x00, 0x00, 0x00, 0x10},
879 {0xa1, 0x18, 0x50, 0x1c, 0x00, 0x00, 0x00, 0x10},
880 {0xa1, 0x18, 0x44, 0x10, 0x00, 0x00, 0x00, 0x10},
881 {0xa1, 0x18, 0x4a, 0x30, 0x00, 0x00, 0x00, 0x10},
882 {0xa1, 0x18, 0x51, 0x80, 0x00, 0x00, 0x00, 0x10},
883 {0xa1, 0x18, 0x52, 0x80, 0x00, 0x00, 0x00, 0x10},
884 {0xa1, 0x18, 0x53, 0x80, 0x00, 0x00, 0x00, 0x10},
885 {0xa1, 0x18, 0x54, 0x80, 0x00, 0x00, 0x00, 0x10},
886 {0xa1, 0x18, 0x55, 0x80, 0x00, 0x00, 0x00, 0x10},
887 {0xa1, 0x18, 0x56, 0x80, 0x00, 0x00, 0x00, 0x10},
888 {0xa1, 0x18, 0x57, 0xe0, 0x00, 0x00, 0x00, 0x10},
889 {0xa1, 0x18, 0x58, 0xc0, 0x00, 0x00, 0x00, 0x10},
890 {0xa1, 0x18, 0x59, 0xab, 0x00, 0x00, 0x00, 0x10},
891 {0xa1, 0x18, 0x5a, 0xa0, 0x00, 0x00, 0x00, 0x10},
892 {0xa1, 0x18, 0x5b, 0x99, 0x00, 0x00, 0x00, 0x10},
893 {0xa1, 0x18, 0x5c, 0x90, 0x00, 0x00, 0x00, 0x10},
894 {0xa1, 0x18, 0x5e, 0x24, 0x00, 0x00, 0x00, 0x10},
895 {0xa1, 0x18, 0x5f, 0x00, 0x00, 0x00, 0x00, 0x10},
896 {0xa1, 0x18, 0x60, 0x00, 0x00, 0x00, 0x00, 0x10},
897 {0xa1, 0x18, 0x61, 0x73, 0x00, 0x00, 0x00, 0x10},
898 {0xa1, 0x18, 0x63, 0x42, 0x00, 0x00, 0x00, 0x10},
899 {0xa1, 0x18, 0x64, 0x42, 0x00, 0x00, 0x00, 0x10},
900 {0xa1, 0x18, 0x65, 0x42, 0x00, 0x00, 0x00, 0x10},
901 {0xa1, 0x18, 0x66, 0x24, 0x00, 0x00, 0x00, 0x10},
902 {0xa1, 0x18, 0x67, 0x24, 0x00, 0x00, 0x00, 0x10},
903 {0xa1, 0x18, 0x68, 0x08, 0x00, 0x00, 0x00, 0x10},
904 {0xa1, 0x18, 0x2f, 0xc9, 0x00, 0x00, 0x00, 0x10},
Jean-Francois Moine3fccb772009-11-02 09:54:04 -0300905 {}
906};
907static const u8 sp80708_sensor_param1[][8] = {
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -0300908 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
909 {0xa1, 0x18, 0x0c, 0x04, 0x00, 0x00, 0x00, 0x10},
910 {0xa1, 0x18, 0x03, 0x01, 0x00, 0x00, 0x00, 0x10},
911 {0xa1, 0x18, 0x04, 0xa4, 0x00, 0x00, 0x00, 0x10},
912 {0xa1, 0x18, 0x14, 0x3f, 0x00, 0x00, 0x00, 0x10},
913 {0xa1, 0x18, 0x5d, 0x80, 0x00, 0x00, 0x00, 0x10},
914 {0xb1, 0x18, 0x11, 0x40, 0x40, 0x00, 0x00, 0x10},
915 {}
916};
917
Jean-Francois Moine23a98272009-11-02 09:10:25 -0300918static const u8 (*sensor_init[9])[8] = {
919 hv7131r_sensor_init, /* HV7131R 0 */
920 mi0360_sensor_init, /* MI0360 1 */
921 mo4000_sensor_init, /* MO4000 2 */
922 mt9v111_sensor_init, /* MT9V111 3 */
923 om6802_sensor_init, /* OM6802 4 */
924 ov7630_sensor_init, /* OV7630 5 */
925 ov7648_sensor_init, /* OV7648 6 */
926 ov7660_sensor_init, /* OV7660 7 */
927 sp80708_sensor_init, /* SP80708 8 */
928};
929
Jean-Francois Moine8295d992008-09-03 17:12:19 -0300930/* read <len> bytes to gspca_dev->usb_buf */
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300931static void reg_r(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -0300932 u16 value, int len)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300933{
Jean-Francois Moine8295d992008-09-03 17:12:19 -0300934#ifdef GSPCA_DEBUG
935 if (len > USB_BUF_SZ) {
936 err("reg_r: buffer overflow");
937 return;
938 }
939#endif
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300940 usb_control_msg(gspca_dev->dev,
941 usb_rcvctrlpipe(gspca_dev->dev, 0),
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300942 0,
943 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
944 value, 0,
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300945 gspca_dev->usb_buf, len,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300946 500);
Jean-Francois Moine60017612008-07-18 08:46:19 -0300947 PDEBUG(D_USBI, "reg_r [%02x] -> %02x", value, gspca_dev->usb_buf[0]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300948}
949
Jean-Francois Moine60017612008-07-18 08:46:19 -0300950static void reg_w1(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -0300951 u16 value,
952 u8 data)
Jean-Francois Moine60017612008-07-18 08:46:19 -0300953{
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300954 PDEBUG(D_USBO, "reg_w1 [%04x] = %02x", value, data);
Jean-Francois Moine60017612008-07-18 08:46:19 -0300955 gspca_dev->usb_buf[0] = data;
956 usb_control_msg(gspca_dev->dev,
957 usb_sndctrlpipe(gspca_dev->dev, 0),
958 0x08,
959 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
960 value,
961 0,
962 gspca_dev->usb_buf, 1,
963 500);
964}
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300965static void reg_w(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -0300966 u16 value,
967 const u8 *buffer,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300968 int len)
969{
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -0300970 PDEBUG(D_USBO, "reg_w [%04x] = %02x %02x ..",
Jean-Francois Moine60017612008-07-18 08:46:19 -0300971 value, buffer[0], buffer[1]);
Jean-Francois Moine8295d992008-09-03 17:12:19 -0300972#ifdef GSPCA_DEBUG
973 if (len > USB_BUF_SZ) {
974 err("reg_w: buffer overflow");
975 return;
Jean-Francois Moinebf7f0b92008-07-03 11:09:12 -0300976 }
Jean-Francois Moine8295d992008-09-03 17:12:19 -0300977#endif
978 memcpy(gspca_dev->usb_buf, buffer, len);
979 usb_control_msg(gspca_dev->dev,
980 usb_sndctrlpipe(gspca_dev->dev, 0),
981 0x08,
982 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
983 value, 0,
984 gspca_dev->usb_buf, len,
985 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300986}
987
Jean-Francois Moine60017612008-07-18 08:46:19 -0300988/* I2C write 1 byte */
Jean-Francois Moine98819182009-01-19 07:37:33 -0300989static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300990{
991 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300992
Jean-Francois Moine60017612008-07-18 08:46:19 -0300993 PDEBUG(D_USBO, "i2c_w2 [%02x] = %02x", reg, val);
Jean-Francois Moinea7826362009-11-02 09:21:06 -0300994 switch (sd->sensor) {
995 case SENSOR_OM6802: /* i2c command = a0 (100 kHz) */
996 gspca_dev->usb_buf[0] = 0x80 | (2 << 4);
997 break;
998 default: /* i2c command = a1 (400 kHz) */
999 gspca_dev->usb_buf[0] = 0x81 | (2 << 4);
1000 break;
1001 }
Jean-Francois Moine60017612008-07-18 08:46:19 -03001002 gspca_dev->usb_buf[1] = sd->i2c_base;
1003 gspca_dev->usb_buf[2] = reg;
1004 gspca_dev->usb_buf[3] = val;
1005 gspca_dev->usb_buf[4] = 0;
1006 gspca_dev->usb_buf[5] = 0;
1007 gspca_dev->usb_buf[6] = 0;
1008 gspca_dev->usb_buf[7] = 0x10;
1009 usb_control_msg(gspca_dev->dev,
1010 usb_sndctrlpipe(gspca_dev->dev, 0),
1011 0x08,
1012 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1013 0x08, /* value = i2c */
1014 0,
1015 gspca_dev->usb_buf, 8,
1016 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001017}
1018
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001019/* I2C write 8 bytes */
1020static void i2c_w8(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -03001021 const u8 *buffer)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001022{
Jean-Francois Moine60017612008-07-18 08:46:19 -03001023 memcpy(gspca_dev->usb_buf, buffer, 8);
1024 usb_control_msg(gspca_dev->dev,
1025 usb_sndctrlpipe(gspca_dev->dev, 0),
1026 0x08,
1027 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1028 0x08, 0, /* value, index */
1029 gspca_dev->usb_buf, 8,
1030 500);
Jean-Francois Moine8d768e12008-09-21 03:28:55 -03001031 msleep(2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001032}
1033
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001034/* read 5 bytes in gspca_dev->usb_buf */
Jean-Francois Moine98819182009-01-19 07:37:33 -03001035static void i2c_r5(struct gspca_dev *gspca_dev, u8 reg)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001036{
1037 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001038 u8 mode[8];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001039
Jean-Francois Moinea7826362009-11-02 09:21:06 -03001040 switch (sd->sensor) {
1041 case SENSOR_OM6802: /* i2c command = 90 (100 kHz) */
1042 mode[0] = 0x80 | 0x10;
1043 break;
1044 default: /* i2c command = 91 (400 kHz) */
1045 mode[0] = 0x81 | 0x10;
1046 break;
1047 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001048 mode[1] = sd->i2c_base;
1049 mode[2] = reg;
1050 mode[3] = 0;
1051 mode[4] = 0;
1052 mode[5] = 0;
1053 mode[6] = 0;
1054 mode[7] = 0x10;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001055 i2c_w8(gspca_dev, mode);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001056 msleep(2);
Jean-Francois Moinea7826362009-11-02 09:21:06 -03001057 mode[0] = (mode[0] & 0x81) | (5 << 4) | 0x02;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001058 mode[2] = 0;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001059 i2c_w8(gspca_dev, mode);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001060 msleep(2);
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001061 reg_r(gspca_dev, 0x0a, 5);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001062}
1063
Jean-Francois Moine23a98272009-11-02 09:10:25 -03001064static void i2c_w_seq(struct gspca_dev *gspca_dev,
1065 const u8 (*data)[8])
1066{
1067 while ((*data)[0] != 0) {
1068 if ((*data)[0] != 0xdd)
1069 i2c_w8(gspca_dev, *data);
1070 else
1071 msleep((*data)[1]);
1072 data++;
1073 }
1074}
1075
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03001076static void hv7131r_probe(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001077{
Jean-Francois Moine60017612008-07-18 08:46:19 -03001078 i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001079 msleep(10);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001080 reg_w1(gspca_dev, 0x02, 0x66); /* Gpio on */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001081 msleep(10);
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001082 i2c_r5(gspca_dev, 0); /* read sensor id */
1083 if (gspca_dev->usb_buf[0] == 0x02
1084 && gspca_dev->usb_buf[1] == 0x09
1085 && gspca_dev->usb_buf[2] == 0x01
1086 && gspca_dev->usb_buf[3] == 0x00
1087 && gspca_dev->usb_buf[4] == 0x00) {
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03001088 PDEBUG(D_PROBE, "Sensor sn9c102P HV7131R found");
1089 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001090 }
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03001091 PDEBUG(D_PROBE, "Sensor 0x%02x 0x%02x 0x%02x - sn9c102P not found",
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001092 gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
1093 gspca_dev->usb_buf[2]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001094}
1095
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001096static void mi0360_probe(struct gspca_dev *gspca_dev)
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001097{
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001098 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001099 int i, j;
Jean-Francois Moine92e8c912009-02-02 16:25:38 -03001100 u16 val = 0;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001101 static const u8 probe_tb[][4][8] = {
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001102 { /* mi0360 */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001103 {0xb0, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10},
1104 {0x90, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1105 {0xa2, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1106 {0xb0, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10}
1107 },
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001108 { /* mt9v111 */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001109 {0xb0, 0x5c, 0x01, 0x00, 0x04, 0x00, 0x00, 0x10},
1110 {0x90, 0x5c, 0x36, 0x00, 0x00, 0x00, 0x00, 0x10},
1111 {0xa2, 0x5c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
1112 {}
1113 },
1114 };
1115
1116 for (i = 0; i < ARRAY_SIZE(probe_tb); i++) {
1117 reg_w1(gspca_dev, 0x17, 0x62);
1118 reg_w1(gspca_dev, 0x01, 0x08);
1119 for (j = 0; j < 3; j++)
1120 i2c_w8(gspca_dev, probe_tb[i][j]);
1121 msleep(2);
1122 reg_r(gspca_dev, 0x0a, 5);
1123 val = (gspca_dev->usb_buf[3] << 8) | gspca_dev->usb_buf[4];
1124 if (probe_tb[i][3][0] != 0)
1125 i2c_w8(gspca_dev, probe_tb[i][3]);
1126 reg_w1(gspca_dev, 0x01, 0x29);
1127 reg_w1(gspca_dev, 0x17, 0x42);
1128 if (val != 0xffff)
1129 break;
1130 }
1131 switch (val) {
1132 case 0x823a:
1133 PDEBUG(D_PROBE, "Sensor mt9v111");
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001134 sd->sensor = SENSOR_MT9V111;
1135 sd->i2c_base = 0x5c;
1136 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001137 case 0x8243:
1138 PDEBUG(D_PROBE, "Sensor mi0360");
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001139 break;
1140 default:
1141 PDEBUG(D_PROBE, "Unknown sensor %04x - forced to mi0360", val);
1142 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001143 }
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001144}
1145
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001146static void bridge_init(struct gspca_dev *gspca_dev,
Jean-Francois Moine98819182009-01-19 07:37:33 -03001147 const u8 *sn9c1xx)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001148{
1149 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001150 const u8 *reg9a;
1151 static const u8 reg9a_def[] =
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03001152 {0x00, 0x40, 0x20, 0x00, 0x00, 0x00};
1153 static const u8 reg9a_spec[] =
1154 {0x00, 0x40, 0x38, 0x30, 0x00, 0x20};
Jean-Francois Moine98819182009-01-19 07:37:33 -03001155 static const u8 regd4[] = {0x60, 0x00, 0x00};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001156
Jean-Francois Moine60017612008-07-18 08:46:19 -03001157 reg_w1(gspca_dev, 0xf1, 0x00);
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001158 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001159
1160 /* configure gpio */
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001161 reg_w(gspca_dev, 0x01, &sn9c1xx[1], 2);
1162 reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001163 reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5); /* jfm len was 3 */
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03001164 switch (sd->sensor) {
1165 case SENSOR_OV7660:
1166 case SENSOR_SP80708:
1167 reg9a = reg9a_spec;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001168 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001169 default:
1170 reg9a = reg9a_def;
1171 break;
1172 }
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001173 reg_w(gspca_dev, 0x9a, reg9a, 6);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001174
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001175 reg_w(gspca_dev, 0xd4, regd4, sizeof regd4); /*fixme:jfm was 60 only*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001176
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001177 reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001178
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001179 switch (sd->sensor) {
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001180 case SENSOR_MT9V111:
1181 reg_w1(gspca_dev, 0x01, 0x61);
1182 reg_w1(gspca_dev, 0x17, 0x61);
1183 reg_w1(gspca_dev, 0x01, 0x60);
1184 reg_w1(gspca_dev, 0x01, 0x40);
1185 break;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001186 case SENSOR_OM6802:
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001187 msleep(10);
1188 reg_w1(gspca_dev, 0x02, 0x73);
1189 reg_w1(gspca_dev, 0x17, 0x60);
1190 reg_w1(gspca_dev, 0x01, 0x22);
1191 msleep(100);
1192 reg_w1(gspca_dev, 0x01, 0x62);
1193 reg_w1(gspca_dev, 0x17, 0x64);
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001194 reg_w1(gspca_dev, 0x17, 0x64);
1195 reg_w1(gspca_dev, 0x01, 0x42);
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001196 msleep(10);
1197 reg_w1(gspca_dev, 0x01, 0x42);
1198 i2c_w8(gspca_dev, om6802_init0[0]);
1199 i2c_w8(gspca_dev, om6802_init0[1]);
1200 msleep(15);
1201 reg_w1(gspca_dev, 0x02, 0x71);
1202 msleep(150);
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001203 break;
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001204 case SENSOR_OV7630:
1205 reg_w1(gspca_dev, 0x01, 0x61);
1206 reg_w1(gspca_dev, 0x17, 0xe2);
1207 reg_w1(gspca_dev, 0x01, 0x60);
1208 reg_w1(gspca_dev, 0x01, 0x40);
1209 break;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001210 case SENSOR_OV7648:
Jean-Francois Moine62703302008-11-11 08:42:56 -03001211 reg_w1(gspca_dev, 0x01, 0x63);
1212 reg_w1(gspca_dev, 0x17, 0x20);
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03001213 reg_w1(gspca_dev, 0x01, 0x62);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001214 reg_w1(gspca_dev, 0x01, 0x42);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001215 break;
Jean-Francois Moine91de65a2008-09-03 17:12:18 -03001216 case SENSOR_OV7660:
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001217 case SENSOR_SP80708:
1218 reg_w1(gspca_dev, 0x01, 0x63);
1219 reg_w1(gspca_dev, 0x17, 0x20);
1220 reg_w1(gspca_dev, 0x01, 0x62);
1221 reg_w1(gspca_dev, 0x01, 0x42);
Jean-Francois Moine1f78a972009-08-29 07:11:58 -03001222 msleep(100);
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001223 reg_w1(gspca_dev, 0x02, 0x62);
1224 break;
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03001225/* case SENSOR_HV7131R: */
1226/* case SENSOR_MI0360: */
1227/* case SENSOR_MO4000: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001228 default:
Jean-Francois Moine60017612008-07-18 08:46:19 -03001229 reg_w1(gspca_dev, 0x01, 0x43);
1230 reg_w1(gspca_dev, 0x17, 0x61);
1231 reg_w1(gspca_dev, 0x01, 0x42);
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03001232 if (sd->sensor == SENSOR_HV7131R)
1233 hv7131r_probe(gspca_dev);
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001234 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001235 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001236}
1237
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001238/* this function is called at probe time */
1239static int sd_config(struct gspca_dev *gspca_dev,
1240 const struct usb_device_id *id)
1241{
1242 struct sd *sd = (struct sd *) gspca_dev;
1243 struct cam *cam;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001244
1245 cam = &gspca_dev->cam;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001246 cam->cam_mode = vga_mode;
1247 cam->nmodes = ARRAY_SIZE(vga_mode);
Jean-Francois Moine49cb6b02009-04-25 13:29:01 -03001248 cam->npkt = 24; /* 24 packets per ISOC message */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001249
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03001250 sd->bridge = id->driver_info >> 16;
1251 sd->sensor = id->driver_info >> 8;
1252 sd->i2c_base = id->driver_info;
1253
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001254 sd->brightness = BRIGHTNESS_DEF;
1255 sd->contrast = CONTRAST_DEF;
1256 sd->colors = COLOR_DEF;
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001257 sd->blue = BLUE_BALANCE_DEF;
1258 sd->red = RED_BALANCE_DEF;
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03001259 sd->gamma = GAMMA_DEF;
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001260 sd->autogain = AUTOGAIN_DEF;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001261 sd->ag_cnt = -1;
Hans de Goedef8009522009-06-18 14:29:20 -03001262 sd->vflip = VFLIP_DEF;
Jean-Francois Moine0cae8962008-10-17 07:48:24 -03001263 sd->infrared = INFRARED_DEF;
Hans de Goede37c6dbe2009-06-18 07:35:36 -03001264 sd->freq = FREQ_DEF;
Jean-Francois Moine77ac0ba2009-03-02 06:40:52 -03001265 sd->quality = QUALITY_DEF;
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03001266 sd->jpegqual = 80;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001267
Jean-Francois Moine577cbf42008-12-05 06:18:37 -03001268 gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001269 return 0;
1270}
1271
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03001272/* this function is called at probe and resume time */
1273static int sd_init(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001274{
1275 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001276 u8 regGpio[] = { 0x29, 0x74 };
1277 u8 regF1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001278
Hans de Goede3647fea2008-07-15 05:36:30 -03001279 /* setup a selector by bridge */
Jean-Francois Moine60017612008-07-18 08:46:19 -03001280 reg_w1(gspca_dev, 0xf1, 0x01);
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001281 reg_r(gspca_dev, 0x00, 1);
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001282 reg_w1(gspca_dev, 0xf1, gspca_dev->usb_buf[0]);
1283 reg_r(gspca_dev, 0x00, 1); /* get sonix chip id */
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001284 regF1 = gspca_dev->usb_buf[0];
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001285 PDEBUG(D_PROBE, "Sonix chip id: %02x", regF1);
Hans de Goede3647fea2008-07-15 05:36:30 -03001286 switch (sd->bridge) {
1287 case BRIDGE_SN9C102P:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001288 if (regF1 != 0x11)
1289 return -ENODEV;
Jean-Francois Moine60017612008-07-18 08:46:19 -03001290 reg_w1(gspca_dev, 0x02, regGpio[1]);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001291 break;
Hans de Goede3647fea2008-07-15 05:36:30 -03001292 case BRIDGE_SN9C105:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001293 if (regF1 != 0x11)
1294 return -ENODEV;
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001295 if (sd->sensor == SENSOR_MI0360)
1296 mi0360_probe(gspca_dev);
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001297 reg_w(gspca_dev, 0x01, regGpio, 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001298 break;
Hans de Goede3647fea2008-07-15 05:36:30 -03001299 case BRIDGE_SN9C120:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001300 if (regF1 != 0x12)
1301 return -ENODEV;
Jean-Francois Moine65c52592009-02-01 14:26:51 -03001302 if (sd->sensor == SENSOR_MI0360)
1303 mi0360_probe(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001304 regGpio[1] = 0x70;
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001305 reg_w(gspca_dev, 0x01, regGpio, 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001306 break;
1307 default:
Jean-Francois Moine60017612008-07-18 08:46:19 -03001308/* case BRIDGE_SN9C110: */
Hans de Goede3647fea2008-07-15 05:36:30 -03001309/* case BRIDGE_SN9C325: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001310 if (regF1 != 0x12)
1311 return -ENODEV;
Jean-Francois Moine60017612008-07-18 08:46:19 -03001312 reg_w1(gspca_dev, 0x02, 0x62);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001313 break;
1314 }
1315
Jean-Francois Moine759aa3c2008-09-03 16:48:03 -03001316 reg_w1(gspca_dev, 0xf1, 0x01);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001317
1318 return 0;
1319}
1320
Jean-Francois Moine98819182009-01-19 07:37:33 -03001321static u32 setexposure(struct gspca_dev *gspca_dev,
1322 u32 expo)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001323{
1324 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001325
1326 switch (sd->sensor) {
1327 case SENSOR_HV7131R: {
Jean-Francois Moine98819182009-01-19 07:37:33 -03001328 u8 Expodoit[] =
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001329 { 0xc1, 0x11, 0x25, 0x07, 0x27, 0xc0, 0x00, 0x16 };
1330
1331 Expodoit[3] = expo >> 16;
1332 Expodoit[4] = expo >> 8;
1333 Expodoit[5] = expo;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001334 i2c_w8(gspca_dev, Expodoit);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001335 break;
1336 }
1337 case SENSOR_MI0360: {
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001338 u8 expoMi[] = /* exposure 0x0635 -> 4 fp/s 0x10 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001339 { 0xb1, 0x5d, 0x09, 0x06, 0x35, 0x00, 0x00, 0x16 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001340 static const u8 doit[] = /* update sensor */
1341 { 0xb1, 0x5d, 0x07, 0x00, 0x03, 0x00, 0x00, 0x10 };
1342 static const u8 sensorgo[] = /* sensor on */
1343 { 0xb1, 0x5d, 0x07, 0x00, 0x02, 0x00, 0x00, 0x10 };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001344
1345 if (expo > 0x0635)
1346 expo = 0x0635;
1347 else if (expo < 0x0001)
1348 expo = 0x0001;
1349 expoMi[3] = expo >> 8;
1350 expoMi[4] = expo;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001351 i2c_w8(gspca_dev, expoMi);
1352 i2c_w8(gspca_dev, doit);
1353 i2c_w8(gspca_dev, sensorgo);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001354 break;
1355 }
1356 case SENSOR_MO4000: {
Jean-Francois Moine98819182009-01-19 07:37:33 -03001357 u8 expoMof[] =
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001358 { 0xa1, 0x21, 0x0f, 0x20, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001359 u8 expoMo10[] =
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001360 { 0xa1, 0x21, 0x10, 0x20, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001361 static const u8 gainMo[] =
1362 { 0xa1, 0x21, 0x00, 0x10, 0x00, 0x00, 0x00, 0x1d };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001363
1364 if (expo > 0x1fff)
1365 expo = 0x1fff;
1366 else if (expo < 0x0001)
1367 expo = 0x0001;
1368 expoMof[3] = (expo & 0x03fc) >> 2;
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001369 i2c_w8(gspca_dev, expoMof);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001370 expoMo10[3] = ((expo & 0x1c00) >> 10)
1371 | ((expo & 0x0003) << 4);
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001372 i2c_w8(gspca_dev, expoMo10);
1373 i2c_w8(gspca_dev, gainMo);
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001374 PDEBUG(D_FRAM, "set exposure %d",
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001375 ((expoMo10[3] & 0x07) << 10)
1376 | (expoMof[3] << 2)
1377 | ((expoMo10[3] & 0x30) >> 4));
1378 break;
1379 }
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001380 case SENSOR_MT9V111: {
1381 u8 expo_c1[] =
1382 { 0xb1, 0x5c, 0x09, 0x00, 0x00, 0x00, 0x00, 0x10 };
1383
1384 if (expo > 0x0280)
1385 expo = 0x0280;
1386 else if (expo < 0x0040)
1387 expo = 0x0040;
1388 expo_c1[3] = expo >> 8;
1389 expo_c1[4] = expo;
1390 i2c_w8(gspca_dev, expo_c1);
1391 break;
1392 }
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001393 case SENSOR_OM6802: {
Jean-Francois Moine98819182009-01-19 07:37:33 -03001394 u8 gainOm[] =
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001395 { 0xa0, 0x34, 0xe5, 0x00, 0x00, 0x00, 0x00, 0x10 };
1396
1397 if (expo > 0x03ff)
1398 expo = 0x03ff;
1399 if (expo < 0x0001)
1400 expo = 0x0001;
1401 gainOm[3] = expo >> 2;
1402 i2c_w8(gspca_dev, gainOm);
Jean-Francois Moined55b83d2008-09-03 16:48:01 -03001403 reg_w1(gspca_dev, 0x96, (expo >> 5) & 0x1f);
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001404 PDEBUG(D_FRAM, "set exposure %d", gainOm[3]);
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001405 break;
1406 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001407 }
1408 return expo;
1409}
1410
1411static void setbrightness(struct gspca_dev *gspca_dev)
1412{
1413 struct sd *sd = (struct sd *) gspca_dev;
1414 unsigned int expo;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001415 u8 k2;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001416
Jean-Francois Moineb1b056a2008-11-25 04:47:09 -03001417 k2 = ((int) sd->brightness - 0x8000) >> 10;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001418 switch (sd->sensor) {
1419 case SENSOR_HV7131R:
1420 expo = sd->brightness << 4;
1421 if (expo > 0x002dc6c0)
1422 expo = 0x002dc6c0;
1423 else if (expo < 0x02a0)
1424 expo = 0x02a0;
1425 sd->exposure = setexposure(gspca_dev, expo);
1426 break;
1427 case SENSOR_MI0360:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001428 case SENSOR_MO4000:
1429 expo = sd->brightness >> 4;
1430 sd->exposure = setexposure(gspca_dev, expo);
1431 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001432 case SENSOR_MT9V111:
1433 expo = sd->brightness >> 8;
1434 sd->exposure = setexposure(gspca_dev, expo);
1435 break;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001436 case SENSOR_OM6802:
1437 expo = sd->brightness >> 6;
1438 sd->exposure = setexposure(gspca_dev, expo);
Jean-Francois Moineb1b056a2008-11-25 04:47:09 -03001439 k2 = sd->brightness >> 11;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001440 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001441 }
1442
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001443 if (sd->sensor != SENSOR_MT9V111)
1444 reg_w1(gspca_dev, 0x96, k2); /* color matrix Y offset */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001445}
1446
1447static void setcontrast(struct gspca_dev *gspca_dev)
1448{
1449 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001450 u8 k2;
1451 u8 contrast[6];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001452
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03001453 k2 = sd->contrast * 0x30 / (CONTRAST_MAX + 1) + 0x10; /* 10..40 */
1454 contrast[0] = (k2 + 1) / 2; /* red */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -03001455 contrast[1] = 0;
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03001456 contrast[2] = k2; /* green */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -03001457 contrast[3] = 0;
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03001458 contrast[4] = (k2 + 1) / 5; /* blue */
Jean-Francois Moine577cbf42008-12-05 06:18:37 -03001459 contrast[5] = 0;
1460 reg_w(gspca_dev, 0x84, contrast, sizeof contrast);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001461}
1462
1463static void setcolors(struct gspca_dev *gspca_dev)
1464{
1465 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001466 int i, v;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001467 u8 reg8a[12]; /* U & V gains */
1468 static s16 uv[6] = { /* same as reg84 in signed decimal */
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001469 -24, -38, 64, /* UR UG UB */
1470 62, -51, -9 /* VR VG VB */
1471 };
1472 for (i = 0; i < 6; i++) {
1473 v = uv[i] * sd->colors / COLOR_DEF;
Jean-Francois Moinebd088832008-12-02 06:58:57 -03001474 reg8a[i * 2] = v;
1475 reg8a[i * 2 + 1] = (v >> 8) & 0x0f;
Jean-Francois Moined55b83d2008-09-03 16:48:01 -03001476 }
Jean-Francois Moinebd088832008-12-02 06:58:57 -03001477 reg_w(gspca_dev, 0x8a, reg8a, sizeof reg8a);
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001478}
1479
1480static void setredblue(struct gspca_dev *gspca_dev)
1481{
1482 struct sd *sd = (struct sd *) gspca_dev;
1483
1484 reg_w1(gspca_dev, 0x05, sd->red);
Jean-Francois Moine9c5f70f2008-09-03 16:48:04 -03001485/* reg_w1(gspca_dev, 0x07, 32); */
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001486 reg_w1(gspca_dev, 0x06, sd->blue);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001487}
1488
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03001489static void setgamma(struct gspca_dev *gspca_dev)
1490{
1491 struct sd *sd = (struct sd *) gspca_dev;
1492 int i;
1493 u8 gamma[17];
Jean-Francois Moineb083b922009-02-01 14:20:07 -03001494 const u8 *gamma_base;
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03001495 static const u8 delta[17] = {
1496 0x00, 0x14, 0x1c, 0x1c, 0x1c, 0x1c, 0x1b, 0x1a,
1497 0x18, 0x13, 0x10, 0x0e, 0x08, 0x07, 0x04, 0x02, 0x00
1498 };
1499
Jean-Francois Moineb083b922009-02-01 14:20:07 -03001500 switch (sd->sensor) {
1501 case SENSOR_HV7131R:
1502 case SENSOR_MT9V111:
1503 gamma_base = gamma_spec_1;
1504 break;
1505 case SENSOR_SP80708:
1506 gamma_base = gamma_spec_2;
1507 break;
1508 default:
1509 gamma_base = gamma_def;
1510 break;
1511 }
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001512
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03001513 for (i = 0; i < sizeof gamma; i++)
Jean-Francois Moineb083b922009-02-01 14:20:07 -03001514 gamma[i] = gamma_base[i]
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03001515 + delta[i] * (sd->gamma - GAMMA_DEF) / 32;
1516 reg_w(gspca_dev, 0x20, gamma, sizeof gamma);
1517}
1518
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001519static void setautogain(struct gspca_dev *gspca_dev)
1520{
1521 struct sd *sd = (struct sd *) gspca_dev;
1522
Jean-Francois Moinef50ba1b2008-09-03 17:12:14 -03001523 if (gspca_dev->ctrl_dis & (1 << AUTOGAIN_IDX))
1524 return;
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03001525 switch (sd->sensor) {
1526 case SENSOR_OV7630:
1527 case SENSOR_OV7648: {
1528 u8 comb;
1529
1530 if (sd->sensor == SENSOR_OV7630)
1531 comb = 0xc0;
1532 else
1533 comb = 0xa0;
1534 if (sd->autogain)
Hans de Goede1fec7472009-06-18 06:05:07 -03001535 comb |= 0x03;
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03001536 i2c_w1(&sd->gspca_dev, 0x13, comb);
1537 return;
1538 }
1539 }
Jean-Francois Moinef50ba1b2008-09-03 17:12:14 -03001540 if (sd->autogain)
1541 sd->ag_cnt = AG_CNT_START;
1542 else
1543 sd->ag_cnt = -1;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001544}
1545
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03001546/* ov7630/ov7648 only */
Jean-Francois Moine6c862742008-09-08 04:57:26 -03001547static void setvflip(struct sd *sd)
1548{
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03001549 u8 comn;
1550
Jean-Francois Moine0939e262009-11-02 09:58:49 -03001551 if (sd->gspca_dev.ctrl_dis & (1 << VFLIP_IDX))
1552 return;
Hans de Goedef8009522009-06-18 14:29:20 -03001553 if (sd->sensor == SENSOR_OV7630) {
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03001554 comn = 0x02;
Hans de Goedef8009522009-06-18 14:29:20 -03001555 if (!sd->vflip)
1556 comn |= 0x80;
1557 } else {
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03001558 comn = 0x06;
Hans de Goedef8009522009-06-18 14:29:20 -03001559 if (sd->vflip)
1560 comn |= 0x80;
1561 }
Jean-Francois Moine2797ba22009-02-05 15:12:24 -03001562 i2c_w1(&sd->gspca_dev, 0x75, comn);
Jean-Francois Moine6c862742008-09-08 04:57:26 -03001563}
1564
Jean-Francois Moine0cae8962008-10-17 07:48:24 -03001565static void setinfrared(struct sd *sd)
1566{
Jean-Francois Moine47f7f6f2009-08-25 06:14:54 -03001567 if (sd->gspca_dev.ctrl_dis & (1 << INFRARED_IDX))
1568 return;
Jean-Francois Moine0cae8962008-10-17 07:48:24 -03001569/*fixme: different sequence for StarCam Clip and StarCam 370i */
1570/* Clip */
1571 i2c_w1(&sd->gspca_dev, 0x02, /* gpio */
1572 sd->infrared ? 0x66 : 0x64);
1573}
1574
Hans de Goede37c6dbe2009-06-18 07:35:36 -03001575static void setfreq(struct gspca_dev *gspca_dev)
1576{
1577 struct sd *sd = (struct sd *) gspca_dev;
1578
Jean-Francois Moine27954932009-07-08 05:21:50 -03001579 if (gspca_dev->ctrl_dis & (1 << FREQ_IDX))
1580 return;
Hans de Goede37c6dbe2009-06-18 07:35:36 -03001581 if (sd->sensor == SENSOR_OV7660) {
Jean-Francois Moined8f400e2009-07-08 06:33:44 -03001582 u8 com8;
1583
Jean-Francois Moine47f7f6f2009-08-25 06:14:54 -03001584 com8 = 0xdf; /* auto gain/wb/expo */
Hans de Goede37c6dbe2009-06-18 07:35:36 -03001585 switch (sd->freq) {
1586 case 0: /* Banding filter disabled */
Jean-Francois Moine47f7f6f2009-08-25 06:14:54 -03001587 i2c_w1(gspca_dev, 0x13, com8 | 0x20);
Hans de Goede37c6dbe2009-06-18 07:35:36 -03001588 break;
1589 case 1: /* 50 hz */
Jean-Francois Moined8f400e2009-07-08 06:33:44 -03001590 i2c_w1(gspca_dev, 0x13, com8);
Hans de Goede37c6dbe2009-06-18 07:35:36 -03001591 i2c_w1(gspca_dev, 0x3b, 0x0a);
1592 break;
1593 case 2: /* 60 hz */
Jean-Francois Moined8f400e2009-07-08 06:33:44 -03001594 i2c_w1(gspca_dev, 0x13, com8);
Hans de Goede37c6dbe2009-06-18 07:35:36 -03001595 i2c_w1(gspca_dev, 0x3b, 0x02);
1596 break;
1597 }
1598 } else {
1599 u8 reg2a = 0, reg2b = 0, reg2d = 0;
1600
1601 /* Get reg2a / reg2d base values */
1602 switch (sd->sensor) {
1603 case SENSOR_OV7630:
1604 reg2a = 0x08;
1605 reg2d = 0x01;
1606 break;
1607 case SENSOR_OV7648:
1608 reg2a = 0x11;
1609 reg2d = 0x81;
1610 break;
1611 }
1612
1613 switch (sd->freq) {
1614 case 0: /* Banding filter disabled */
1615 break;
1616 case 1: /* 50 hz (filter on and framerate adj) */
1617 reg2a |= 0x80;
1618 reg2b = 0xac;
1619 reg2d |= 0x04;
1620 break;
1621 case 2: /* 60 hz (filter on, no framerate adj) */
1622 reg2a |= 0x80;
1623 reg2d |= 0x04;
1624 break;
1625 }
1626 i2c_w1(gspca_dev, 0x2a, reg2a);
1627 i2c_w1(gspca_dev, 0x2b, reg2b);
1628 i2c_w1(gspca_dev, 0x2d, reg2d);
1629 }
1630}
1631
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03001632static void setjpegqual(struct gspca_dev *gspca_dev)
1633{
1634 struct sd *sd = (struct sd *) gspca_dev;
1635 int i, sc;
1636
1637 if (sd->jpegqual < 50)
1638 sc = 5000 / sd->jpegqual;
1639 else
1640 sc = 200 - sd->jpegqual * 2;
1641#if USB_BUF_SZ < 64
1642#error "No room enough in usb_buf for quantization table"
1643#endif
1644 for (i = 0; i < 64; i++)
1645 gspca_dev->usb_buf[i] =
1646 (jpeg_head[JPEG_QT0_OFFSET + i] * sc + 50) / 100;
1647 usb_control_msg(gspca_dev->dev,
1648 usb_sndctrlpipe(gspca_dev->dev, 0),
1649 0x08,
1650 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1651 0x0100, 0,
1652 gspca_dev->usb_buf, 64,
1653 500);
1654 for (i = 0; i < 64; i++)
1655 gspca_dev->usb_buf[i] =
1656 (jpeg_head[JPEG_QT1_OFFSET + i] * sc + 50) / 100;
1657 usb_control_msg(gspca_dev->dev,
1658 usb_sndctrlpipe(gspca_dev->dev, 0),
1659 0x08,
1660 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
1661 0x0140, 0,
1662 gspca_dev->usb_buf, 64,
1663 500);
1664
1665 sd->reg18 ^= 0x40;
1666 reg_w1(gspca_dev, 0x18, sd->reg18);
1667}
1668
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001669/* -- start the camera -- */
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03001670static int sd_start(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001671{
1672 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001673 int i;
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001674 u8 reg1, reg2, reg17;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001675 const u8 *sn9c1xx;
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001676 const u8 (*init)[8];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001677 int mode;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001678 static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
1679 static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
1680 static const u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */
1681 static const u8 CE_ov76xx[] =
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001682 { 0x32, 0xdd, 0x32, 0xdd };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001683
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03001684 /* create the JPEG header */
1685 sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL);
Julia Lawall3eb02372009-07-19 07:09:32 -03001686 if (!sd->jpeg_hdr)
1687 return -ENOMEM;
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03001688 jpeg_define(sd->jpeg_hdr, gspca_dev->height, gspca_dev->width,
1689 0x21); /* JPEG 422 */
1690 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
1691
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001692 /* initialize the bridge */
1693 sn9c1xx = sn_tb[sd->sensor];
1694 bridge_init(gspca_dev, sn9c1xx);
1695 /* initialize the sensor */
1696 i2c_w_seq(gspca_dev, sensor_init[sd->sensor]);
1697
1698 switch (sd->sensor) {
1699 case SENSOR_OM6802:
1700 reg2 = 0x71;
1701 break;
1702 case SENSOR_SP80708:
1703 reg2 = 0x62;
1704 break;
1705 default:
1706 reg2 = 0x40;
1707 break;
1708 }
1709 reg_w1(gspca_dev, 0x02, reg2);
1710 reg_w1(gspca_dev, 0x02, reg2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001711
Jean-Francois Moine60017612008-07-18 08:46:19 -03001712 reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]);
1713 reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]);
1714 reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
1715 reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]);
1716 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
1717 reg_w1(gspca_dev, 0xd2, 0x6a); /* DC29 */
1718 reg_w1(gspca_dev, 0xd3, 0x50);
1719 reg_w1(gspca_dev, 0xc6, 0x00);
1720 reg_w1(gspca_dev, 0xc7, 0x00);
1721 reg_w1(gspca_dev, 0xc8, 0x50);
1722 reg_w1(gspca_dev, 0xc9, 0x3c);
Jean-Francois Moine60017612008-07-18 08:46:19 -03001723 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001724 switch (sd->sensor) {
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001725 case SENSOR_MT9V111:
1726 reg17 = 0xe0;
1727 break;
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001728 case SENSOR_OV7630:
1729 reg17 = 0xe2;
1730 break;
1731 case SENSOR_OV7648:
Jean-Francois Moine62703302008-11-11 08:42:56 -03001732 reg17 = 0x20;
Jean-Francois Moine568788a2008-07-15 11:46:06 -03001733 break;
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001734 case SENSOR_OV7660:
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03001735 reg17 = 0xa0;
1736 break;
Jean-Francois Moine568788a2008-07-15 11:46:06 -03001737 default:
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001738 reg17 = 0x60;
Jean-Francois Moine568788a2008-07-15 11:46:06 -03001739 break;
1740 }
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001741 reg_w1(gspca_dev, 0x17, reg17);
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001742/* set reg1 was here */
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001743 reg_w1(gspca_dev, 0x05, sn9c1xx[5]); /* red */
1744 reg_w1(gspca_dev, 0x07, sn9c1xx[7]); /* green */
1745 reg_w1(gspca_dev, 0x06, sn9c1xx[6]); /* blue */
Jean-Francois Moine60017612008-07-18 08:46:19 -03001746 reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
Jean-Francois Moineb083b922009-02-01 14:20:07 -03001747
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001748 setgamma(gspca_dev);
1749
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001750 for (i = 0; i < 8; i++)
1751 reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001752 switch (sd->sensor) {
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001753 case SENSOR_MT9V111:
1754 reg_w1(gspca_dev, 0x9a, 0x07);
1755 reg_w1(gspca_dev, 0x99, 0x59);
1756 break;
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001757 case SENSOR_OM6802:
1758 reg_w1(gspca_dev, 0x9a, 0x08);
1759 reg_w1(gspca_dev, 0x99, 0x10);
1760 break;
Jean-Francois Moine62703302008-11-11 08:42:56 -03001761 case SENSOR_OV7648:
1762 reg_w1(gspca_dev, 0x9a, 0x0a);
1763 reg_w1(gspca_dev, 0x99, 0x60);
1764 break;
Jean-Francois Moinec8b9b2ca2009-04-26 14:46:12 -03001765 case SENSOR_OV7660:
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001766 case SENSOR_SP80708:
1767 reg_w1(gspca_dev, 0x9a, 0x05);
1768 reg_w1(gspca_dev, 0x99, 0x59);
1769 break;
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001770 default:
Jean-Francois Moine60017612008-07-18 08:46:19 -03001771 reg_w1(gspca_dev, 0x9a, 0x08);
1772 reg_w1(gspca_dev, 0x99, 0x59);
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001773 break;
1774 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001775
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001776 reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
1777 reg_w1(gspca_dev, 0x05, sn9c1xx[5]); /* red */
1778 reg_w1(gspca_dev, 0x07, sn9c1xx[7]); /* green */
1779 reg_w1(gspca_dev, 0x06, sn9c1xx[6]); /* blue */
Jean-Francois Moine23a98272009-11-02 09:10:25 -03001780
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001781 init = NULL;
Jean-Francois Moinec2446b32008-07-05 11:49:20 -03001782 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
Jean-Francois Moine60017612008-07-18 08:46:19 -03001783 if (mode)
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001784 reg1 = 0x46; /* 320x240: clk 48Mhz, video trf enable */
Jean-Francois Moine60017612008-07-18 08:46:19 -03001785 else
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001786 reg1 = 0x06; /* 640x480: clk 24Mhz, video trf enable */
1787 reg17 = 0x61; /* 0x:20: enable sensor clock */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001788 switch (sd->sensor) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001789 case SENSOR_MO4000:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001790 if (mode) {
1791/* reg1 = 0x46; * 320 clk 48Mhz 60fp/s */
1792 reg1 = 0x06; /* clk 24Mz */
1793 } else {
1794 reg17 = 0x22; /* 640 MCKSIZE */
Jean-Francois Moine60017612008-07-18 08:46:19 -03001795/* reg1 = 0x06; * 640 clk 24Mz (done) */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001796 }
1797 break;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001798 case SENSOR_MT9V111:
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001799 init = mt9v111_sensor_param1;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001800 if (mode) {
1801 reg1 = 0x04; /* 320 clk 48Mhz */
1802 } else {
1803/* reg1 = 0x06; * 640 clk 24Mz (done) */
Jean-Francois Moine2687a2f2009-02-01 14:48:55 -03001804 reg17 = 0xc2;
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001805 }
Jean-Francois Moine0fbe0572009-01-30 12:14:02 -03001806 break;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001807 case SENSOR_OM6802:
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001808 init = om6802_sensor_param1;
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03001809 reg17 = 0x64; /* 640 MCKSIZE */
1810 break;
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001811 case SENSOR_OV7630:
Jean-Francois Moine6c862742008-09-08 04:57:26 -03001812 setvflip(sd);
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001813 reg17 = 0xe2;
Jean-Francois Moine5b064da2008-09-03 16:48:08 -03001814 reg1 = 0x44;
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001815 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001816 case SENSOR_OV7648:
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001817 init = ov7648_sensor_param1;
Jean-Francois Moine62703302008-11-11 08:42:56 -03001818 reg17 = 0x21;
1819/* reg1 = 0x42; * 42 - 46? */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001820 break;
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001821 case SENSOR_OV7660:
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001822 init = ov7660_sensor_param1;
Jean-Francois Moinedaa5cb42008-12-02 15:00:57 -03001823 if (sd->bridge == BRIDGE_SN9C120) {
1824 if (mode) { /* 320x240 - 160x120 */
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001825 reg17 = 0xa2;
1826 reg1 = 0x44; /* 48 Mhz, video trf eneble */
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001827 }
Jean-Francois Moinedaa5cb42008-12-02 15:00:57 -03001828 } else {
1829 reg17 = 0x22;
1830 reg1 = 0x06; /* 24 Mhz, video trf eneble
1831 * inverse power down */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001832 }
1833 break;
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001834 default:
1835/* case SENSOR_SP80708: */
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001836 init = sp80708_sensor_param1;
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001837 if (mode) {
1838/*?? reg1 = 0x04; * 320 clk 48Mhz */
Jean-Francois Moine5e31dc82009-02-01 13:59:42 -03001839 } else {
1840 reg1 = 0x46; /* 640 clk 48Mz */
1841 reg17 = 0xa2;
1842 }
1843 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001844 }
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001845
1846 /* more sensor initialization - param1 */
1847 if (init != NULL) {
1848 i2c_w_seq(gspca_dev, init);
1849/* init = NULL; */
1850 }
1851
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001852 reg_w(gspca_dev, 0xc0, C0, 6);
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001853 reg_w(gspca_dev, 0xca, CA, 4);
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001854 switch (sd->sensor) {
1855 case SENSOR_OV7630:
1856 case SENSOR_OV7648:
Jean-Francois Moine674cbc62008-10-02 08:06:59 -03001857 case SENSOR_OV7660:
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03001858 reg_w(gspca_dev, 0xce, CE_ov76xx, 4);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001859 break;
1860 default:
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001861 reg_w(gspca_dev, 0xce, CE, 4);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001862 /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */
1863 break;
1864 }
1865
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001866
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001867 /* here change size mode 0 -> VGA; 1 -> CIF */
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03001868 sd->reg18 = sn9c1xx[0x18] | (mode << 4) | 0x40;
1869 reg_w1(gspca_dev, 0x18, sd->reg18);
1870 setjpegqual(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001871
Jean-Francois Moine60017612008-07-18 08:46:19 -03001872 reg_w1(gspca_dev, 0x17, reg17);
Jean-Francois Moine1432f302008-11-21 04:34:15 -03001873 reg_w1(gspca_dev, 0x01, reg1);
Jean-Francois Moine3fccb772009-11-02 09:54:04 -03001874
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001875 switch (sd->sensor) {
Jean-Francois Moine79a90982008-10-05 04:21:24 -03001876 case SENSOR_OV7630:
1877 setvflip(sd);
Jean-Francois Moine05b809c2008-09-03 16:47:59 -03001878 break;
1879 }
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03001880 setbrightness(gspca_dev);
1881 setcontrast(gspca_dev);
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001882 setautogain(gspca_dev);
Hans de Goede37c6dbe2009-06-18 07:35:36 -03001883 setfreq(gspca_dev);
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03001884 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001885}
1886
1887static void sd_stopN(struct gspca_dev *gspca_dev)
1888{
1889 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001890 static const u8 stophv7131[] =
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001891 { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001892 static const u8 stopmi0360[] =
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001893 { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001894 static const u8 stopov7648[] =
Jean-Francois Moine62703302008-11-11 08:42:56 -03001895 { 0xa1, 0x21, 0x76, 0x20, 0x00, 0x00, 0x00, 0x10 };
Jean-Francois Moine98819182009-01-19 07:37:33 -03001896 u8 data;
1897 const u8 *sn9c1xx;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001898
1899 data = 0x0b;
1900 switch (sd->sensor) {
1901 case SENSOR_HV7131R:
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001902 i2c_w8(gspca_dev, stophv7131);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001903 data = 0x2b;
1904 break;
1905 case SENSOR_MI0360:
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001906 i2c_w8(gspca_dev, stopmi0360);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001907 data = 0x29;
1908 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001909 case SENSOR_OV7648:
Jean-Francois Moine62703302008-11-11 08:42:56 -03001910 i2c_w8(gspca_dev, stopov7648);
1911 /* fall thru */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001912 case SENSOR_MT9V111:
Jean-Francois Moine62703302008-11-11 08:42:56 -03001913 case SENSOR_OV7630:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001914 data = 0x29;
1915 break;
1916 default:
Jean-Francois Moine8f47a3c2008-07-29 14:14:04 -03001917/* case SENSOR_MO4000: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001918/* case SENSOR_OV7660: */
1919 break;
1920 }
1921 sn9c1xx = sn_tb[(int) sd->sensor];
Jean-Francois Moine60017612008-07-18 08:46:19 -03001922 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
1923 reg_w1(gspca_dev, 0x17, sn9c1xx[0x17]);
1924 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
1925 reg_w1(gspca_dev, 0x01, data);
Jean-Francois Moine759aa3c2008-09-03 16:48:03 -03001926 reg_w1(gspca_dev, 0xf1, 0x00);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001927}
1928
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03001929static void sd_stop0(struct gspca_dev *gspca_dev)
1930{
1931 struct sd *sd = (struct sd *) gspca_dev;
1932
1933 kfree(sd->jpeg_hdr);
1934}
1935
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001936static void do_autogain(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001937{
1938 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001939 int delta;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001940 int expotimes;
Jean-Francois Moine98819182009-01-19 07:37:33 -03001941 u8 luma_mean = 130;
1942 u8 luma_delta = 20;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001943
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001944 /* Thanks S., without your advice, autobright should not work :) */
1945 if (sd->ag_cnt < 0)
1946 return;
1947 if (--sd->ag_cnt >= 0)
1948 return;
1949 sd->ag_cnt = AG_CNT_START;
1950
1951 delta = atomic_read(&sd->avg_lum);
1952 PDEBUG(D_FRAM, "mean lum %d", delta);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001953 if (delta < luma_mean - luma_delta ||
1954 delta > luma_mean + luma_delta) {
1955 switch (sd->sensor) {
1956 case SENSOR_HV7131R:
1957 expotimes = sd->exposure >> 8;
1958 expotimes += (luma_mean - delta) >> 4;
1959 if (expotimes < 0)
1960 expotimes = 0;
1961 sd->exposure = setexposure(gspca_dev,
1962 (unsigned int) (expotimes << 8));
1963 break;
Amauri Magagna46b4f2a2009-10-17 07:21:29 -03001964 case SENSOR_OM6802:
1965 expotimes = sd->exposure;
1966 expotimes += (luma_mean - delta) >> 2;
1967 if (expotimes < 0)
1968 expotimes = 0;
1969 sd->exposure = setexposure(gspca_dev,
1970 (unsigned int) expotimes);
1971 setredblue(gspca_dev);
1972 break;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001973 default:
1974/* case SENSOR_MO4000: */
1975/* case SENSOR_MI0360: */
Jean-Francois Moine3ef2c5b2009-01-29 04:59:45 -03001976/* case SENSOR_MT9V111: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001977 expotimes = sd->exposure;
1978 expotimes += (luma_mean - delta) >> 6;
1979 if (expotimes < 0)
1980 expotimes = 0;
1981 sd->exposure = setexposure(gspca_dev,
1982 (unsigned int) expotimes);
Jean-Francois Moine403123d2008-11-26 04:46:15 -03001983 setredblue(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001984 break;
1985 }
1986 }
1987}
1988
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03001989/* scan the URB packets */
1990/* This function is run at interrupt level. */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001991static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1992 struct gspca_frame *frame, /* target */
Jean-Francois Moine98819182009-01-19 07:37:33 -03001993 u8 *data, /* isoc packet */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001994 int len) /* iso packet length */
1995{
1996 struct sd *sd = (struct sd *) gspca_dev;
1997 int sof, avg_lum;
1998
1999 sof = len - 64;
2000 if (sof >= 0 && data[sof] == 0xff && data[sof + 1] == 0xd9) {
2001
2002 /* end of frame */
2003 gspca_frame_add(gspca_dev, LAST_PACKET,
2004 frame, data, sof + 2);
2005 if (sd->ag_cnt < 0)
2006 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002007/* w1 w2 w3 */
2008/* w4 w5 w6 */
2009/* w7 w8 */
2010/* w4 */
2011 avg_lum = ((data[sof + 29] << 8) | data[sof + 30]) >> 6;
2012/* w6 */
2013 avg_lum += ((data[sof + 33] << 8) | data[sof + 34]) >> 6;
2014/* w2 */
2015 avg_lum += ((data[sof + 25] << 8) | data[sof + 26]) >> 6;
2016/* w8 */
2017 avg_lum += ((data[sof + 37] << 8) | data[sof + 38]) >> 6;
2018/* w5 */
2019 avg_lum += ((data[sof + 31] << 8) | data[sof + 32]) >> 4;
2020 avg_lum >>= 4;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002021 atomic_set(&sd->avg_lum, avg_lum);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002022 return;
2023 }
2024 if (gspca_dev->last_packet_type == LAST_PACKET) {
2025
2026 /* put the JPEG 422 header */
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03002027 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
2028 sd->jpeg_hdr, JPEG_HDR_SZ);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002029 }
2030 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
2031}
2032
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002033static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
2034{
2035 struct sd *sd = (struct sd *) gspca_dev;
2036
2037 sd->brightness = val;
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03002038 if (gspca_dev->streaming)
2039 setbrightness(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002040 return 0;
2041}
2042
2043static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
2044{
2045 struct sd *sd = (struct sd *) gspca_dev;
2046
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002047 *val = sd->brightness;
2048 return 0;
2049}
2050
2051static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
2052{
2053 struct sd *sd = (struct sd *) gspca_dev;
2054
2055 sd->contrast = val;
Jean-Francois Moine91bd3412008-11-23 14:47:50 -03002056 if (gspca_dev->streaming)
2057 setcontrast(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002058 return 0;
2059}
2060
2061static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
2062{
2063 struct sd *sd = (struct sd *) gspca_dev;
2064
2065 *val = sd->contrast;
2066 return 0;
2067}
2068
2069static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
2070{
2071 struct sd *sd = (struct sd *) gspca_dev;
2072
2073 sd->colors = val;
2074 if (gspca_dev->streaming)
2075 setcolors(gspca_dev);
2076 return 0;
2077}
2078
2079static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
2080{
2081 struct sd *sd = (struct sd *) gspca_dev;
2082
2083 *val = sd->colors;
2084 return 0;
2085}
2086
Jean-Francois Moine403123d2008-11-26 04:46:15 -03002087static int sd_setblue_balance(struct gspca_dev *gspca_dev, __s32 val)
2088{
2089 struct sd *sd = (struct sd *) gspca_dev;
2090
2091 sd->blue = val;
2092 if (gspca_dev->streaming)
2093 setredblue(gspca_dev);
2094 return 0;
2095}
2096
2097static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val)
2098{
2099 struct sd *sd = (struct sd *) gspca_dev;
2100
2101 *val = sd->blue;
2102 return 0;
2103}
2104
2105static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val)
2106{
2107 struct sd *sd = (struct sd *) gspca_dev;
2108
2109 sd->red = val;
2110 if (gspca_dev->streaming)
2111 setredblue(gspca_dev);
2112 return 0;
2113}
2114
2115static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val)
2116{
2117 struct sd *sd = (struct sd *) gspca_dev;
2118
2119 *val = sd->red;
2120 return 0;
2121}
2122
Jean-Francois Moine592f4eb2009-01-15 08:01:32 -03002123static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val)
2124{
2125 struct sd *sd = (struct sd *) gspca_dev;
2126
2127 sd->gamma = val;
2128 if (gspca_dev->streaming)
2129 setgamma(gspca_dev);
2130 return 0;
2131}
2132
2133static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val)
2134{
2135 struct sd *sd = (struct sd *) gspca_dev;
2136
2137 *val = sd->gamma;
2138 return 0;
2139}
2140
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002141static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
2142{
2143 struct sd *sd = (struct sd *) gspca_dev;
2144
2145 sd->autogain = val;
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002146 if (gspca_dev->streaming)
2147 setautogain(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002148 return 0;
2149}
2150
2151static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
2152{
2153 struct sd *sd = (struct sd *) gspca_dev;
2154
2155 *val = sd->autogain;
2156 return 0;
2157}
2158
Jean-Francois Moine6c862742008-09-08 04:57:26 -03002159static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
2160{
2161 struct sd *sd = (struct sd *) gspca_dev;
2162
2163 sd->vflip = val;
Jean-Francois Moine79a90982008-10-05 04:21:24 -03002164 if (gspca_dev->streaming)
2165 setvflip(sd);
Jean-Francois Moine6c862742008-09-08 04:57:26 -03002166 return 0;
2167}
2168
2169static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
2170{
2171 struct sd *sd = (struct sd *) gspca_dev;
2172
2173 *val = sd->vflip;
2174 return 0;
2175}
2176
Jean-Francois Moine0cae8962008-10-17 07:48:24 -03002177static int sd_setinfrared(struct gspca_dev *gspca_dev, __s32 val)
2178{
2179 struct sd *sd = (struct sd *) gspca_dev;
2180
2181 sd->infrared = val;
2182 if (gspca_dev->streaming)
2183 setinfrared(sd);
2184 return 0;
2185}
2186
2187static int sd_getinfrared(struct gspca_dev *gspca_dev, __s32 *val)
2188{
2189 struct sd *sd = (struct sd *) gspca_dev;
2190
2191 *val = sd->infrared;
2192 return 0;
2193}
2194
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002195static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
2196{
2197 struct sd *sd = (struct sd *) gspca_dev;
2198
2199 sd->freq = val;
2200 if (gspca_dev->streaming)
2201 setfreq(gspca_dev);
2202 return 0;
2203}
2204
2205static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
2206{
2207 struct sd *sd = (struct sd *) gspca_dev;
2208
2209 *val = sd->freq;
2210 return 0;
2211}
2212
Jean-Francois Moine77ac0ba2009-03-02 06:40:52 -03002213static int sd_set_jcomp(struct gspca_dev *gspca_dev,
2214 struct v4l2_jpegcompression *jcomp)
2215{
2216 struct sd *sd = (struct sd *) gspca_dev;
2217
2218 if (jcomp->quality < QUALITY_MIN)
2219 sd->quality = QUALITY_MIN;
2220 else if (jcomp->quality > QUALITY_MAX)
2221 sd->quality = QUALITY_MAX;
2222 else
2223 sd->quality = jcomp->quality;
2224 if (gspca_dev->streaming)
2225 jpeg_set_qual(sd->jpeg_hdr, sd->quality);
2226 return 0;
2227}
2228
2229static int sd_get_jcomp(struct gspca_dev *gspca_dev,
2230 struct v4l2_jpegcompression *jcomp)
2231{
2232 struct sd *sd = (struct sd *) gspca_dev;
2233
2234 memset(jcomp, 0, sizeof *jcomp);
2235 jcomp->quality = sd->quality;
2236 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT
2237 | V4L2_JPEG_MARKER_DQT;
2238 return 0;
2239}
2240
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002241static int sd_querymenu(struct gspca_dev *gspca_dev,
2242 struct v4l2_querymenu *menu)
2243{
2244 switch (menu->id) {
2245 case V4L2_CID_POWER_LINE_FREQUENCY:
2246 switch (menu->index) {
2247 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
2248 strcpy((char *) menu->name, "NoFliker");
2249 return 0;
2250 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
2251 strcpy((char *) menu->name, "50 Hz");
2252 return 0;
2253 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
2254 strcpy((char *) menu->name, "60 Hz");
2255 return 0;
2256 }
2257 break;
2258 }
2259 return -EINVAL;
2260}
2261
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002262/* sub-driver description */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002263static const struct sd_desc sd_desc = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002264 .name = MODULE_NAME,
2265 .ctrls = sd_ctrls,
2266 .nctrls = ARRAY_SIZE(sd_ctrls),
2267 .config = sd_config,
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03002268 .init = sd_init,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002269 .start = sd_start,
2270 .stopN = sd_stopN,
Jean-Francois Moine71cb2762009-03-03 05:33:41 -03002271 .stop0 = sd_stop0,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002272 .pkt_scan = sd_pkt_scan,
Jean-Francois Moinecebf3b62008-08-03 07:52:53 -03002273 .dq_callback = do_autogain,
Jean-Francois Moine77ac0ba2009-03-02 06:40:52 -03002274 .get_jcomp = sd_get_jcomp,
2275 .set_jcomp = sd_set_jcomp,
Hans de Goede37c6dbe2009-06-18 07:35:36 -03002276 .querymenu = sd_querymenu,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002277};
2278
2279/* -- module initialisation -- */
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002280#define BSI(bridge, sensor, i2c_addr) \
2281 .driver_info = (BRIDGE_ ## bridge << 16) \
2282 | (SENSOR_ ## sensor << 8) \
2283 | (i2c_addr)
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002284static const __devinitdata struct usb_device_id device_table[] = {
Hans de Goede222a07f2008-09-03 17:12:20 -03002285#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002286 {USB_DEVICE(0x0458, 0x7025), BSI(SN9C120, MI0360, 0x5d)},
Jean-Francois Moine7b537392008-09-07 11:56:49 -03002287 {USB_DEVICE(0x0458, 0x702e), BSI(SN9C120, OV7660, 0x21)},
Jean-Francois Moinea08d81a2008-11-22 04:53:31 -03002288#endif
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002289 {USB_DEVICE(0x045e, 0x00f5), BSI(SN9C105, OV7660, 0x21)},
2290 {USB_DEVICE(0x045e, 0x00f7), BSI(SN9C105, OV7660, 0x21)},
2291 {USB_DEVICE(0x0471, 0x0327), BSI(SN9C105, MI0360, 0x5d)},
Jean-Francois Moine7e21fda2008-11-10 04:45:51 -03002292 {USB_DEVICE(0x0471, 0x0328), BSI(SN9C105, MI0360, 0x5d)},
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002293 {USB_DEVICE(0x0471, 0x0330), BSI(SN9C105, MI0360, 0x5d)},
Jean-Francois Moine3319dc92008-12-01 14:44:02 -03002294 {USB_DEVICE(0x06f8, 0x3004), BSI(SN9C105, OV7660, 0x21)},
Jani Monosesf8eaaf4f2009-05-07 03:32:27 -03002295 {USB_DEVICE(0x06f8, 0x3008), BSI(SN9C105, OV7660, 0x21)},
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03002296/* {USB_DEVICE(0x0c45, 0x603a), BSI(SN9C102P, OV7648, 0x21)}, */
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002297 {USB_DEVICE(0x0c45, 0x6040), BSI(SN9C102P, HV7131R, 0x11)},
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03002298/* {USB_DEVICE(0x0c45, 0x607a), BSI(SN9C102P, OV7648, 0x21)}, */
2299/* {USB_DEVICE(0x0c45, 0x607b), BSI(SN9C102P, OV7660, 0x21)}, */
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002300 {USB_DEVICE(0x0c45, 0x607c), BSI(SN9C102P, HV7131R, 0x11)},
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03002301/* {USB_DEVICE(0x0c45, 0x607e), BSI(SN9C102P, OV7630, 0x21)}, */
Jean-Francois Moine661ab252009-01-29 16:03:19 -03002302 {USB_DEVICE(0x0c45, 0x60c0), BSI(SN9C105, MI0360, 0x5d)},
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03002303/* {USB_DEVICE(0x0c45, 0x60c2), BSI(SN9C105, P1030xC, 0x??)}, */
Jean-Francois Moinea7826362009-11-02 09:21:06 -03002304/* {USB_DEVICE(0x0c45, 0x60c8), BSI(SN9C105, OM6802, 0x34)}, */
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002305/* {USB_DEVICE(0x0c45, 0x60cc), BSI(SN9C105, HV7131GP, 0x??)}, */
2306 {USB_DEVICE(0x0c45, 0x60ec), BSI(SN9C105, MO4000, 0x21)},
2307/* {USB_DEVICE(0x0c45, 0x60ef), BSI(SN9C105, ICM105C, 0x??)}, */
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03002308/* {USB_DEVICE(0x0c45, 0x60fa), BSI(SN9C105, OV7648, 0x21)}, */
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002309 {USB_DEVICE(0x0c45, 0x60fb), BSI(SN9C105, OV7660, 0x21)},
Jean-Francois Moine3c41cb72008-09-10 02:57:09 -03002310#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
Jean-Francois Moinef077b0a2009-09-01 14:52:04 -03002311 {USB_DEVICE(0x0c45, 0x60fc), BSI(SN9C105, HV7131R, 0x11)},
Jean-Francois Moine3c41cb72008-09-10 02:57:09 -03002312 {USB_DEVICE(0x0c45, 0x60fe), BSI(SN9C105, OV7630, 0x21)},
2313#endif
Jean-Francois Moineceec80e2009-05-09 06:21:35 -03002314 {USB_DEVICE(0x0c45, 0x6100), BSI(SN9C120, MI0360, 0x5d)}, /*sn9c128*/
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03002315/* {USB_DEVICE(0x0c45, 0x6102), BSI(SN9C120, P1030xC, ??)}, */
Jean-Francois Moinea7826362009-11-02 09:21:06 -03002316/* {USB_DEVICE(0x0c45, 0x6108), BSI(SN9C120, OM6802, 0x34)}, */
Jean-Francois Moineceec80e2009-05-09 06:21:35 -03002317 {USB_DEVICE(0x0c45, 0x610a), BSI(SN9C120, OV7648, 0x21)}, /*sn9c128*/
2318 {USB_DEVICE(0x0c45, 0x610b), BSI(SN9C120, OV7660, 0x21)}, /*sn9c128*/
2319 {USB_DEVICE(0x0c45, 0x610c), BSI(SN9C120, HV7131R, 0x11)}, /*sn9c128*/
2320 {USB_DEVICE(0x0c45, 0x610e), BSI(SN9C120, OV7630, 0x21)}, /*sn9c128*/
Jean-Francois Moine7fb101a2009-10-22 06:27:14 -03002321/* {USB_DEVICE(0x0c45, 0x610f), BSI(SN9C120, S5K53BEB, 0x??)}, */
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002322/* {USB_DEVICE(0x0c45, 0x6122), BSI(SN9C110, ICM105C, 0x??)}, */
2323/* {USB_DEVICE(0x0c45, 0x6123), BSI(SN9C110, SanyoCCD, 0x??)}, */
Jean-Francois Moinea7826362009-11-02 09:21:06 -03002324 {USB_DEVICE(0x0c45, 0x6128), BSI(SN9C120, OM6802, 0x34)}, /*sn9c325?*/
Jean-Francois Moined2d16e92008-09-03 16:47:23 -03002325/*bw600.inf:*/
Jean-Francois Moine62703302008-11-11 08:42:56 -03002326 {USB_DEVICE(0x0c45, 0x612a), BSI(SN9C120, OV7648, 0x21)}, /*sn9c110?*/
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002327 {USB_DEVICE(0x0c45, 0x612c), BSI(SN9C110, MO4000, 0x21)},
Jean-Francois Moine6ab0b172008-09-03 16:47:34 -03002328 {USB_DEVICE(0x0c45, 0x612e), BSI(SN9C110, OV7630, 0x21)},
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002329/* {USB_DEVICE(0x0c45, 0x612f), BSI(SN9C110, ICM105C, 0x??)}, */
Hans de Goede222a07f2008-09-03 17:12:20 -03002330#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002331 {USB_DEVICE(0x0c45, 0x6130), BSI(SN9C120, MI0360, 0x5d)},
Hans de Goede222a07f2008-09-03 17:12:20 -03002332#endif
Denis Loginov6baefab2009-07-28 03:39:10 -03002333/* {USB_DEVICE(0x0c45, 0x6132), BSI(SN9C120, OV7670, 0x21)}, */
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002334 {USB_DEVICE(0x0c45, 0x6138), BSI(SN9C120, MO4000, 0x21)},
Jean-Francois Moine821ced22008-11-11 07:10:11 -03002335 {USB_DEVICE(0x0c45, 0x613a), BSI(SN9C120, OV7648, 0x21)},
Hans de Goede222a07f2008-09-03 17:12:20 -03002336#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002337 {USB_DEVICE(0x0c45, 0x613b), BSI(SN9C120, OV7660, 0x21)},
Jean-Francois Moine8d977702009-02-19 15:34:48 -03002338#endif
Jean-Francois Moine9d64fdb2008-07-25 08:53:03 -03002339 {USB_DEVICE(0x0c45, 0x613c), BSI(SN9C120, HV7131R, 0x11)},
Hans de Goedecc7b5b52009-06-18 05:14:42 -03002340 {USB_DEVICE(0x0c45, 0x613e), BSI(SN9C120, OV7630, 0x21)},
Denis Loginov6baefab2009-07-28 03:39:10 -03002341/* {USB_DEVICE(0x0c45, 0x6142), BSI(SN9C120, PO2030N, ??)}, *sn9c120b*/
2342 {USB_DEVICE(0x0c45, 0x6143), BSI(SN9C120, SP80708, 0x18)}, /*sn9c120b*/
Jean-Francois Moinea7826362009-11-02 09:21:06 -03002343 {USB_DEVICE(0x0c45, 0x6148), BSI(SN9C120, OM6802, 0x34)}, /*sn9c120b*/
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002344 {}
2345};
2346MODULE_DEVICE_TABLE(usb, device_table);
2347
2348/* -- device connect -- */
2349static int sd_probe(struct usb_interface *intf,
2350 const struct usb_device_id *id)
2351{
2352 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
2353 THIS_MODULE);
2354}
2355
2356static struct usb_driver sd_driver = {
2357 .name = MODULE_NAME,
2358 .id_table = device_table,
2359 .probe = sd_probe,
2360 .disconnect = gspca_disconnect,
Jean-Francois Moine6a709742008-09-03 16:48:10 -03002361#ifdef CONFIG_PM
2362 .suspend = gspca_suspend,
2363 .resume = gspca_resume,
2364#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002365};
2366
2367/* -- module insert / remove -- */
2368static int __init sd_mod_init(void)
2369{
Alexey Klimovf69e9522009-01-01 13:02:07 -03002370 int ret;
2371 ret = usb_register(&sd_driver);
2372 if (ret < 0)
Alexey Klimove6b14842009-01-01 13:04:58 -03002373 return ret;
Jean-Francois Moine10b0e962008-07-22 05:35:10 -03002374 info("registered");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002375 return 0;
2376}
2377static void __exit sd_mod_exit(void)
2378{
2379 usb_deregister(&sd_driver);
2380 info("deregistered");
2381}
2382
2383module_init(sd_mod_init);
2384module_exit(sd_mod_exit);