blob: 9d4b69dbf96656d8106c1c2fcb24be98068698f6 [file] [log] [blame]
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001/**
2 * OV519 driver
3 *
4 * Copyright (C) 2008 Jean-Francois Moine (http://moinejf.free.fr)
5 *
Romain Beauxis2961e8752008-12-05 06:25:26 -03006 * This module is adapted from the ov51x-jpeg package, which itself
7 * was adapted from the ov511 driver.
8 *
9 * Original copyright for the ov511 driver is:
10 *
11 * Copyright (c) 1999-2004 Mark W. McClelland
12 * Support for OV519, OV8610 Copyright (c) 2003 Joerg Heckenbach
13 *
14 * ov51x-jpeg original copyright is:
15 *
16 * Copyright (c) 2004-2007 Romain Beauxis <toots@rastageeks.org>
17 * Support for OV7670 sensors was contributed by Sam Skipsey <aoanla@yahoo.com>
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030018 *
19 * This program is free software; you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation; either version 2 of the License, or
22 * any later version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with this program; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 *
33 */
34#define MODULE_NAME "ov519"
35
36#include "gspca.h"
37
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030038MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
39MODULE_DESCRIPTION("OV519 USB Camera Driver");
40MODULE_LICENSE("GPL");
41
42/* global parameters */
43static int frame_rate;
44
45/* Number of times to retry a failed I2C transaction. Increase this if you
46 * are getting "Failed to read sensor ID..." */
47static int i2c_detect_tries = 10;
48
49/* ov519 device descriptor */
50struct sd {
51 struct gspca_dev gspca_dev; /* !! must be the first item */
52
Hans de Goede92918a52009-06-14 06:21:35 -030053 __u8 packet_nr;
54
Hans de Goede49809d62009-06-07 12:10:39 -030055 char bridge;
56#define BRIDGE_OV511 0
57#define BRIDGE_OV511PLUS 1
58#define BRIDGE_OV518 2
59#define BRIDGE_OV518PLUS 3
60#define BRIDGE_OV519 4
Hans de Goede9e4d8252009-06-14 06:25:06 -030061#define BRIDGE_MASK 7
62
63 char invert_led;
64#define BRIDGE_INVERT_LED 8
Hans de Goede49809d62009-06-07 12:10:39 -030065
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030066 /* Determined by sensor type */
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -030067 __u8 sif;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030068
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -030069 __u8 brightness;
70 __u8 contrast;
71 __u8 colors;
Jean-Francois Moine0cd67592008-07-29 05:25:28 -030072 __u8 hflip;
73 __u8 vflip;
Hans de Goede02ab18b2009-06-14 04:32:04 -030074 __u8 autobrightness;
75 __u8 freq;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030076
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -030077 __u8 stopped; /* Streaming is temporarily paused */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030078
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -030079 __u8 frame_rate; /* current Framerate (OV519 only) */
80 __u8 clockdiv; /* clockdiv override for OV519 only */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030081
82 char sensor; /* Type of image sensor chip (SEN_*) */
83#define SEN_UNKNOWN 0
84#define SEN_OV6620 1
85#define SEN_OV6630 2
Hans de Goede7d971372009-06-14 05:28:17 -030086#define SEN_OV66308AF 3
87#define SEN_OV7610 4
88#define SEN_OV7620 5
89#define SEN_OV7640 6
90#define SEN_OV7670 7
91#define SEN_OV76BE 8
92#define SEN_OV8610 9
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030093};
94
95/* V4L2 controls supported by the driver */
96static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
97static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
98static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
99static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
100static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
101static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300102static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
103static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
104static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
105static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
Hans de Goede02ab18b2009-06-14 04:32:04 -0300106static int sd_setautobrightness(struct gspca_dev *gspca_dev, __s32 val);
107static int sd_getautobrightness(struct gspca_dev *gspca_dev, __s32 *val);
108static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
109static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
Hans de Goede49809d62009-06-07 12:10:39 -0300110static void setbrightness(struct gspca_dev *gspca_dev);
111static void setcontrast(struct gspca_dev *gspca_dev);
112static void setcolors(struct gspca_dev *gspca_dev);
Hans de Goede02ab18b2009-06-14 04:32:04 -0300113static void setautobrightness(struct sd *sd);
114static void setfreq(struct sd *sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300115
Hans de Goede02ab18b2009-06-14 04:32:04 -0300116static const struct ctrl sd_ctrls[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300117 {
118 {
119 .id = V4L2_CID_BRIGHTNESS,
120 .type = V4L2_CTRL_TYPE_INTEGER,
121 .name = "Brightness",
122 .minimum = 0,
123 .maximum = 255,
124 .step = 1,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300125#define BRIGHTNESS_DEF 127
126 .default_value = BRIGHTNESS_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300127 },
128 .set = sd_setbrightness,
129 .get = sd_getbrightness,
130 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300131 {
132 {
133 .id = V4L2_CID_CONTRAST,
134 .type = V4L2_CTRL_TYPE_INTEGER,
135 .name = "Contrast",
136 .minimum = 0,
137 .maximum = 255,
138 .step = 1,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300139#define CONTRAST_DEF 127
140 .default_value = CONTRAST_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300141 },
142 .set = sd_setcontrast,
143 .get = sd_getcontrast,
144 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300145 {
146 {
147 .id = V4L2_CID_SATURATION,
148 .type = V4L2_CTRL_TYPE_INTEGER,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300149 .name = "Color",
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300150 .minimum = 0,
151 .maximum = 255,
152 .step = 1,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300153#define COLOR_DEF 127
154 .default_value = COLOR_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300155 },
156 .set = sd_setcolors,
157 .get = sd_getcolors,
158 },
Hans de Goede02ab18b2009-06-14 04:32:04 -0300159/* The flip controls work with ov7670 only */
Jean-Francois Moinede004482008-09-03 17:12:16 -0300160#define HFLIP_IDX 3
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300161 {
162 {
163 .id = V4L2_CID_HFLIP,
164 .type = V4L2_CTRL_TYPE_BOOLEAN,
165 .name = "Mirror",
166 .minimum = 0,
167 .maximum = 1,
168 .step = 1,
169#define HFLIP_DEF 0
170 .default_value = HFLIP_DEF,
171 },
172 .set = sd_sethflip,
173 .get = sd_gethflip,
174 },
Jean-Francois Moinede004482008-09-03 17:12:16 -0300175#define VFLIP_IDX 4
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300176 {
177 {
178 .id = V4L2_CID_VFLIP,
179 .type = V4L2_CTRL_TYPE_BOOLEAN,
180 .name = "Vflip",
181 .minimum = 0,
182 .maximum = 1,
183 .step = 1,
184#define VFLIP_DEF 0
185 .default_value = VFLIP_DEF,
186 },
187 .set = sd_setvflip,
188 .get = sd_getvflip,
189 },
Hans de Goede02ab18b2009-06-14 04:32:04 -0300190#define AUTOBRIGHT_IDX 5
191 {
192 {
193 .id = V4L2_CID_AUTOBRIGHTNESS,
194 .type = V4L2_CTRL_TYPE_BOOLEAN,
195 .name = "Auto Brightness",
196 .minimum = 0,
197 .maximum = 1,
198 .step = 1,
199#define AUTOBRIGHT_DEF 1
200 .default_value = AUTOBRIGHT_DEF,
201 },
202 .set = sd_setautobrightness,
203 .get = sd_getautobrightness,
204 },
205#define FREQ_IDX 6
206 {
207 {
208 .id = V4L2_CID_POWER_LINE_FREQUENCY,
209 .type = V4L2_CTRL_TYPE_MENU,
210 .name = "Light frequency filter",
211 .minimum = 0,
212 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
213 .step = 1,
214#define FREQ_DEF 0
215 .default_value = FREQ_DEF,
216 },
217 .set = sd_setfreq,
218 .get = sd_getfreq,
219 },
220#define OV7670_FREQ_IDX 7
221 {
222 {
223 .id = V4L2_CID_POWER_LINE_FREQUENCY,
224 .type = V4L2_CTRL_TYPE_MENU,
225 .name = "Light frequency filter",
226 .minimum = 0,
227 .maximum = 3, /* 0: 0, 1: 50Hz, 2:60Hz 3: Auto Hz */
228 .step = 1,
229#define OV7670_FREQ_DEF 3
230 .default_value = OV7670_FREQ_DEF,
231 },
232 .set = sd_setfreq,
233 .get = sd_getfreq,
234 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300235};
236
Hans de Goede49809d62009-06-07 12:10:39 -0300237static const struct v4l2_pix_format ov519_vga_mode[] = {
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300238 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
239 .bytesperline = 320,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300240 .sizeimage = 320 * 240 * 3 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300241 .colorspace = V4L2_COLORSPACE_JPEG,
242 .priv = 1},
243 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
244 .bytesperline = 640,
245 .sizeimage = 640 * 480 * 3 / 8 + 590,
246 .colorspace = V4L2_COLORSPACE_JPEG,
247 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300248};
Hans de Goede49809d62009-06-07 12:10:39 -0300249static const struct v4l2_pix_format ov519_sif_mode[] = {
Hans de Goede124cc9c2009-06-14 05:48:00 -0300250 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
251 .bytesperline = 160,
252 .sizeimage = 160 * 120 * 3 / 8 + 590,
253 .colorspace = V4L2_COLORSPACE_JPEG,
254 .priv = 3},
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300255 {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
256 .bytesperline = 176,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300257 .sizeimage = 176 * 144 * 3 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300258 .colorspace = V4L2_COLORSPACE_JPEG,
259 .priv = 1},
Hans de Goede124cc9c2009-06-14 05:48:00 -0300260 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
261 .bytesperline = 320,
262 .sizeimage = 320 * 240 * 3 / 8 + 590,
263 .colorspace = V4L2_COLORSPACE_JPEG,
264 .priv = 2},
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300265 {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
266 .bytesperline = 352,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300267 .sizeimage = 352 * 288 * 3 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300268 .colorspace = V4L2_COLORSPACE_JPEG,
269 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300270};
271
Hans de Goede49809d62009-06-07 12:10:39 -0300272static const struct v4l2_pix_format ov518_vga_mode[] = {
273 {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
274 .bytesperline = 320,
275 .sizeimage = 320 * 240 * 3 / 8 + 590,
276 .colorspace = V4L2_COLORSPACE_JPEG,
277 .priv = 1},
278 {640, 480, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
279 .bytesperline = 640,
280 .sizeimage = 640 * 480 * 3 / 8 + 590,
281 .colorspace = V4L2_COLORSPACE_JPEG,
282 .priv = 0},
283};
284static const struct v4l2_pix_format ov518_sif_mode[] = {
Hans de Goede124cc9c2009-06-14 05:48:00 -0300285 {160, 120, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
286 .bytesperline = 160,
287 .sizeimage = 40000,
288 .colorspace = V4L2_COLORSPACE_JPEG,
289 .priv = 3},
Hans de Goede49809d62009-06-07 12:10:39 -0300290 {176, 144, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
291 .bytesperline = 176,
292 .sizeimage = 40000,
293 .colorspace = V4L2_COLORSPACE_JPEG,
294 .priv = 1},
Hans de Goede124cc9c2009-06-14 05:48:00 -0300295 {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
296 .bytesperline = 320,
297 .sizeimage = 320 * 240 * 3 / 8 + 590,
298 .colorspace = V4L2_COLORSPACE_JPEG,
299 .priv = 2},
Hans de Goede49809d62009-06-07 12:10:39 -0300300 {352, 288, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
301 .bytesperline = 352,
302 .sizeimage = 352 * 288 * 3 / 8 + 590,
303 .colorspace = V4L2_COLORSPACE_JPEG,
304 .priv = 0},
305};
306
307
308/* Registers common to OV511 / OV518 */
309#define R51x_SYS_RESET 0x50
310#define R51x_SYS_INIT 0x53
311#define R51x_SYS_SNAP 0x52
312#define R51x_SYS_CUST_ID 0x5F
313#define R51x_COMP_LUT_BEGIN 0x80
314
315/* OV511 Camera interface register numbers */
316#define R511_SYS_LED_CTL 0x55 /* OV511+ only */
317#define OV511_RESET_NOREGS 0x3F /* All but OV511 & regs */
318
319/* OV518 Camera interface register numbers */
320#define R518_GPIO_OUT 0x56 /* OV518(+) only */
321#define R518_GPIO_CTL 0x57 /* OV518(+) only */
322
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300323/* OV519 Camera interface register numbers */
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300324#define OV519_R10_H_SIZE 0x10
325#define OV519_R11_V_SIZE 0x11
326#define OV519_R12_X_OFFSETL 0x12
327#define OV519_R13_X_OFFSETH 0x13
328#define OV519_R14_Y_OFFSETL 0x14
329#define OV519_R15_Y_OFFSETH 0x15
330#define OV519_R16_DIVIDER 0x16
331#define OV519_R20_DFR 0x20
332#define OV519_R25_FORMAT 0x25
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300333
334/* OV519 System Controller register numbers */
335#define OV519_SYS_RESET1 0x51
336#define OV519_SYS_EN_CLK1 0x54
337
338#define OV519_GPIO_DATA_OUT0 0x71
339#define OV519_GPIO_IO_CTRL0 0x72
340
341#define OV511_ENDPOINT_ADDRESS 1 /* Isoc endpoint number */
342
343/* I2C registers */
344#define R51x_I2C_W_SID 0x41
345#define R51x_I2C_SADDR_3 0x42
346#define R51x_I2C_SADDR_2 0x43
347#define R51x_I2C_R_SID 0x44
348#define R51x_I2C_DATA 0x45
349#define R518_I2C_CTL 0x47 /* OV518(+) only */
350
351/* I2C ADDRESSES */
352#define OV7xx0_SID 0x42
353#define OV8xx0_SID 0xa0
354#define OV6xx0_SID 0xc0
355
356/* OV7610 registers */
357#define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */
Hans de Goede49809d62009-06-07 12:10:39 -0300358#define OV7610_REG_BLUE 0x01 /* blue channel balance */
359#define OV7610_REG_RED 0x02 /* red channel balance */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300360#define OV7610_REG_SAT 0x03 /* saturation */
361#define OV8610_REG_HUE 0x04 /* 04 reserved */
362#define OV7610_REG_CNT 0x05 /* Y contrast */
363#define OV7610_REG_BRT 0x06 /* Y brightness */
364#define OV7610_REG_COM_C 0x14 /* misc common regs */
365#define OV7610_REG_ID_HIGH 0x1c /* manufacturer ID MSB */
366#define OV7610_REG_ID_LOW 0x1d /* manufacturer ID LSB */
367#define OV7610_REG_COM_I 0x29 /* misc settings */
368
369/* OV7670 registers */
370#define OV7670_REG_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
371#define OV7670_REG_BLUE 0x01 /* blue gain */
372#define OV7670_REG_RED 0x02 /* red gain */
373#define OV7670_REG_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */
374#define OV7670_REG_COM1 0x04 /* Control 1 */
375#define OV7670_REG_AECHH 0x07 /* AEC MS 5 bits */
376#define OV7670_REG_COM3 0x0c /* Control 3 */
377#define OV7670_REG_COM4 0x0d /* Control 4 */
378#define OV7670_REG_COM5 0x0e /* All "reserved" */
379#define OV7670_REG_COM6 0x0f /* Control 6 */
380#define OV7670_REG_AECH 0x10 /* More bits of AEC value */
381#define OV7670_REG_CLKRC 0x11 /* Clock control */
382#define OV7670_REG_COM7 0x12 /* Control 7 */
383#define OV7670_COM7_FMT_VGA 0x00
384#define OV7670_COM7_YUV 0x00 /* YUV */
385#define OV7670_COM7_FMT_QVGA 0x10 /* QVGA format */
386#define OV7670_COM7_FMT_MASK 0x38
387#define OV7670_COM7_RESET 0x80 /* Register reset */
388#define OV7670_REG_COM8 0x13 /* Control 8 */
389#define OV7670_COM8_AEC 0x01 /* Auto exposure enable */
390#define OV7670_COM8_AWB 0x02 /* White balance enable */
391#define OV7670_COM8_AGC 0x04 /* Auto gain enable */
392#define OV7670_COM8_BFILT 0x20 /* Band filter enable */
393#define OV7670_COM8_AECSTEP 0x40 /* Unlimited AEC step size */
394#define OV7670_COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
395#define OV7670_REG_COM9 0x14 /* Control 9 - gain ceiling */
396#define OV7670_REG_COM10 0x15 /* Control 10 */
397#define OV7670_REG_HSTART 0x17 /* Horiz start high bits */
398#define OV7670_REG_HSTOP 0x18 /* Horiz stop high bits */
399#define OV7670_REG_VSTART 0x19 /* Vert start high bits */
400#define OV7670_REG_VSTOP 0x1a /* Vert stop high bits */
401#define OV7670_REG_MVFP 0x1e /* Mirror / vflip */
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300402#define OV7670_MVFP_VFLIP 0x10 /* vertical flip */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300403#define OV7670_MVFP_MIRROR 0x20 /* Mirror image */
404#define OV7670_REG_AEW 0x24 /* AGC upper limit */
405#define OV7670_REG_AEB 0x25 /* AGC lower limit */
406#define OV7670_REG_VPT 0x26 /* AGC/AEC fast mode op region */
407#define OV7670_REG_HREF 0x32 /* HREF pieces */
408#define OV7670_REG_TSLB 0x3a /* lots of stuff */
409#define OV7670_REG_COM11 0x3b /* Control 11 */
410#define OV7670_COM11_EXP 0x02
411#define OV7670_COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */
412#define OV7670_REG_COM12 0x3c /* Control 12 */
413#define OV7670_REG_COM13 0x3d /* Control 13 */
414#define OV7670_COM13_GAMMA 0x80 /* Gamma enable */
415#define OV7670_COM13_UVSAT 0x40 /* UV saturation auto adjustment */
416#define OV7670_REG_COM14 0x3e /* Control 14 */
417#define OV7670_REG_EDGE 0x3f /* Edge enhancement factor */
418#define OV7670_REG_COM15 0x40 /* Control 15 */
419#define OV7670_COM15_R00FF 0xc0 /* 00 to FF */
420#define OV7670_REG_COM16 0x41 /* Control 16 */
421#define OV7670_COM16_AWBGAIN 0x08 /* AWB gain enable */
422#define OV7670_REG_BRIGHT 0x55 /* Brightness */
423#define OV7670_REG_CONTRAS 0x56 /* Contrast control */
424#define OV7670_REG_GFIX 0x69 /* Fix gain control */
425#define OV7670_REG_RGB444 0x8c /* RGB 444 control */
426#define OV7670_REG_HAECC1 0x9f /* Hist AEC/AGC control 1 */
427#define OV7670_REG_HAECC2 0xa0 /* Hist AEC/AGC control 2 */
428#define OV7670_REG_BD50MAX 0xa5 /* 50hz banding step limit */
429#define OV7670_REG_HAECC3 0xa6 /* Hist AEC/AGC control 3 */
430#define OV7670_REG_HAECC4 0xa7 /* Hist AEC/AGC control 4 */
431#define OV7670_REG_HAECC5 0xa8 /* Hist AEC/AGC control 5 */
432#define OV7670_REG_HAECC6 0xa9 /* Hist AEC/AGC control 6 */
433#define OV7670_REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */
434#define OV7670_REG_BD60MAX 0xab /* 60hz banding step limit */
435
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300436struct ov_regvals {
437 __u8 reg;
438 __u8 val;
439};
440struct ov_i2c_regvals {
441 __u8 reg;
442 __u8 val;
443};
444
445static const struct ov_i2c_regvals norm_6x20[] = {
446 { 0x12, 0x80 }, /* reset */
447 { 0x11, 0x01 },
448 { 0x03, 0x60 },
449 { 0x05, 0x7f }, /* For when autoadjust is off */
450 { 0x07, 0xa8 },
451 /* The ratio of 0x0c and 0x0d controls the white point */
452 { 0x0c, 0x24 },
453 { 0x0d, 0x24 },
454 { 0x0f, 0x15 }, /* COMS */
455 { 0x10, 0x75 }, /* AEC Exposure time */
456 { 0x12, 0x24 }, /* Enable AGC */
457 { 0x14, 0x04 },
458 /* 0x16: 0x06 helps frame stability with moving objects */
459 { 0x16, 0x06 },
460/* { 0x20, 0x30 }, * Aperture correction enable */
461 { 0x26, 0xb2 }, /* BLC enable */
462 /* 0x28: 0x05 Selects RGB format if RGB on */
463 { 0x28, 0x05 },
464 { 0x2a, 0x04 }, /* Disable framerate adjust */
465/* { 0x2b, 0xac }, * Framerate; Set 2a[7] first */
466 { 0x2d, 0x99 },
467 { 0x33, 0xa0 }, /* Color Processing Parameter */
468 { 0x34, 0xd2 }, /* Max A/D range */
469 { 0x38, 0x8b },
470 { 0x39, 0x40 },
471
472 { 0x3c, 0x39 }, /* Enable AEC mode changing */
473 { 0x3c, 0x3c }, /* Change AEC mode */
474 { 0x3c, 0x24 }, /* Disable AEC mode changing */
475
476 { 0x3d, 0x80 },
477 /* These next two registers (0x4a, 0x4b) are undocumented.
478 * They control the color balance */
479 { 0x4a, 0x80 },
480 { 0x4b, 0x80 },
481 { 0x4d, 0xd2 }, /* This reduces noise a bit */
482 { 0x4e, 0xc1 },
483 { 0x4f, 0x04 },
484/* Do 50-53 have any effect? */
485/* Toggle 0x12[2] off and on here? */
486};
487
488static const struct ov_i2c_regvals norm_6x30[] = {
489 { 0x12, 0x80 }, /* Reset */
490 { 0x00, 0x1f }, /* Gain */
491 { 0x01, 0x99 }, /* Blue gain */
492 { 0x02, 0x7c }, /* Red gain */
493 { 0x03, 0xc0 }, /* Saturation */
494 { 0x05, 0x0a }, /* Contrast */
495 { 0x06, 0x95 }, /* Brightness */
496 { 0x07, 0x2d }, /* Sharpness */
497 { 0x0c, 0x20 },
498 { 0x0d, 0x20 },
Hans de Goede02ab18b2009-06-14 04:32:04 -0300499 { 0x0e, 0xa0 }, /* Was 0x20, bit7 enables a 2x gain which we need */
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300500 { 0x0f, 0x05 },
501 { 0x10, 0x9a },
502 { 0x11, 0x00 }, /* Pixel clock = fastest */
503 { 0x12, 0x24 }, /* Enable AGC and AWB */
504 { 0x13, 0x21 },
505 { 0x14, 0x80 },
506 { 0x15, 0x01 },
507 { 0x16, 0x03 },
508 { 0x17, 0x38 },
509 { 0x18, 0xea },
510 { 0x19, 0x04 },
511 { 0x1a, 0x93 },
512 { 0x1b, 0x00 },
513 { 0x1e, 0xc4 },
514 { 0x1f, 0x04 },
515 { 0x20, 0x20 },
516 { 0x21, 0x10 },
517 { 0x22, 0x88 },
518 { 0x23, 0xc0 }, /* Crystal circuit power level */
519 { 0x25, 0x9a }, /* Increase AEC black ratio */
520 { 0x26, 0xb2 }, /* BLC enable */
521 { 0x27, 0xa2 },
522 { 0x28, 0x00 },
523 { 0x29, 0x00 },
524 { 0x2a, 0x84 }, /* 60 Hz power */
525 { 0x2b, 0xa8 }, /* 60 Hz power */
526 { 0x2c, 0xa0 },
527 { 0x2d, 0x95 }, /* Enable auto-brightness */
528 { 0x2e, 0x88 },
529 { 0x33, 0x26 },
530 { 0x34, 0x03 },
531 { 0x36, 0x8f },
532 { 0x37, 0x80 },
533 { 0x38, 0x83 },
534 { 0x39, 0x80 },
535 { 0x3a, 0x0f },
536 { 0x3b, 0x3c },
537 { 0x3c, 0x1a },
538 { 0x3d, 0x80 },
539 { 0x3e, 0x80 },
540 { 0x3f, 0x0e },
541 { 0x40, 0x00 }, /* White bal */
542 { 0x41, 0x00 }, /* White bal */
543 { 0x42, 0x80 },
544 { 0x43, 0x3f }, /* White bal */
545 { 0x44, 0x80 },
546 { 0x45, 0x20 },
547 { 0x46, 0x20 },
548 { 0x47, 0x80 },
549 { 0x48, 0x7f },
550 { 0x49, 0x00 },
551 { 0x4a, 0x00 },
552 { 0x4b, 0x80 },
553 { 0x4c, 0xd0 },
554 { 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
555 { 0x4e, 0x40 },
556 { 0x4f, 0x07 }, /* UV avg., col. killer: max */
557 { 0x50, 0xff },
558 { 0x54, 0x23 }, /* Max AGC gain: 18dB */
559 { 0x55, 0xff },
560 { 0x56, 0x12 },
561 { 0x57, 0x81 },
562 { 0x58, 0x75 },
563 { 0x59, 0x01 }, /* AGC dark current comp.: +1 */
564 { 0x5a, 0x2c },
565 { 0x5b, 0x0f }, /* AWB chrominance levels */
566 { 0x5c, 0x10 },
567 { 0x3d, 0x80 },
568 { 0x27, 0xa6 },
569 { 0x12, 0x20 }, /* Toggle AWB */
570 { 0x12, 0x24 },
571};
572
573/* Lawrence Glaister <lg@jfm.bc.ca> reports:
574 *
575 * Register 0x0f in the 7610 has the following effects:
576 *
577 * 0x85 (AEC method 1): Best overall, good contrast range
578 * 0x45 (AEC method 2): Very overexposed
579 * 0xa5 (spec sheet default): Ok, but the black level is
580 * shifted resulting in loss of contrast
581 * 0x05 (old driver setting): very overexposed, too much
582 * contrast
583 */
584static const struct ov_i2c_regvals norm_7610[] = {
585 { 0x10, 0xff },
586 { 0x16, 0x06 },
587 { 0x28, 0x24 },
588 { 0x2b, 0xac },
589 { 0x12, 0x00 },
590 { 0x38, 0x81 },
591 { 0x28, 0x24 }, /* 0c */
592 { 0x0f, 0x85 }, /* lg's setting */
593 { 0x15, 0x01 },
594 { 0x20, 0x1c },
595 { 0x23, 0x2a },
596 { 0x24, 0x10 },
597 { 0x25, 0x8a },
598 { 0x26, 0xa2 },
599 { 0x27, 0xc2 },
600 { 0x2a, 0x04 },
601 { 0x2c, 0xfe },
602 { 0x2d, 0x93 },
603 { 0x30, 0x71 },
604 { 0x31, 0x60 },
605 { 0x32, 0x26 },
606 { 0x33, 0x20 },
607 { 0x34, 0x48 },
608 { 0x12, 0x24 },
609 { 0x11, 0x01 },
610 { 0x0c, 0x24 },
611 { 0x0d, 0x24 },
612};
613
614static const struct ov_i2c_regvals norm_7620[] = {
615 { 0x00, 0x00 }, /* gain */
616 { 0x01, 0x80 }, /* blue gain */
617 { 0x02, 0x80 }, /* red gain */
618 { 0x03, 0xc0 }, /* OV7670_REG_VREF */
619 { 0x06, 0x60 },
620 { 0x07, 0x00 },
621 { 0x0c, 0x24 },
622 { 0x0c, 0x24 },
623 { 0x0d, 0x24 },
624 { 0x11, 0x01 },
625 { 0x12, 0x24 },
626 { 0x13, 0x01 },
627 { 0x14, 0x84 },
628 { 0x15, 0x01 },
629 { 0x16, 0x03 },
630 { 0x17, 0x2f },
631 { 0x18, 0xcf },
632 { 0x19, 0x06 },
633 { 0x1a, 0xf5 },
634 { 0x1b, 0x00 },
635 { 0x20, 0x18 },
636 { 0x21, 0x80 },
637 { 0x22, 0x80 },
638 { 0x23, 0x00 },
639 { 0x26, 0xa2 },
640 { 0x27, 0xea },
641 { 0x28, 0x20 },
642 { 0x29, 0x00 },
643 { 0x2a, 0x10 },
644 { 0x2b, 0x00 },
645 { 0x2c, 0x88 },
646 { 0x2d, 0x91 },
647 { 0x2e, 0x80 },
648 { 0x2f, 0x44 },
649 { 0x60, 0x27 },
650 { 0x61, 0x02 },
651 { 0x62, 0x5f },
652 { 0x63, 0xd5 },
653 { 0x64, 0x57 },
654 { 0x65, 0x83 },
655 { 0x66, 0x55 },
656 { 0x67, 0x92 },
657 { 0x68, 0xcf },
658 { 0x69, 0x76 },
659 { 0x6a, 0x22 },
660 { 0x6b, 0x00 },
661 { 0x6c, 0x02 },
662 { 0x6d, 0x44 },
663 { 0x6e, 0x80 },
664 { 0x6f, 0x1d },
665 { 0x70, 0x8b },
666 { 0x71, 0x00 },
667 { 0x72, 0x14 },
668 { 0x73, 0x54 },
669 { 0x74, 0x00 },
670 { 0x75, 0x8e },
671 { 0x76, 0x00 },
672 { 0x77, 0xff },
673 { 0x78, 0x80 },
674 { 0x79, 0x80 },
675 { 0x7a, 0x80 },
676 { 0x7b, 0xe2 },
677 { 0x7c, 0x00 },
678};
679
680/* 7640 and 7648. The defaults should be OK for most registers. */
681static const struct ov_i2c_regvals norm_7640[] = {
682 { 0x12, 0x80 },
683 { 0x12, 0x14 },
684};
685
686/* 7670. Defaults taken from OmniVision provided data,
687* as provided by Jonathan Corbet of OLPC */
688static const struct ov_i2c_regvals norm_7670[] = {
689 { OV7670_REG_COM7, OV7670_COM7_RESET },
690 { OV7670_REG_TSLB, 0x04 }, /* OV */
691 { OV7670_REG_COM7, OV7670_COM7_FMT_VGA }, /* VGA */
692 { OV7670_REG_CLKRC, 0x01 },
693/*
694 * Set the hardware window. These values from OV don't entirely
695 * make sense - hstop is less than hstart. But they work...
696 */
697 { OV7670_REG_HSTART, 0x13 },
698 { OV7670_REG_HSTOP, 0x01 },
699 { OV7670_REG_HREF, 0xb6 },
700 { OV7670_REG_VSTART, 0x02 },
701 { OV7670_REG_VSTOP, 0x7a },
702 { OV7670_REG_VREF, 0x0a },
703
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300704 { OV7670_REG_COM3, 0x00 },
705 { OV7670_REG_COM14, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300706/* Mystery scaling numbers */
707 { 0x70, 0x3a },
708 { 0x71, 0x35 },
709 { 0x72, 0x11 },
710 { 0x73, 0xf0 },
711 { 0xa2, 0x02 },
712/* { OV7670_REG_COM10, 0x0 }, */
713
714/* Gamma curve values */
715 { 0x7a, 0x20 },
716 { 0x7b, 0x10 },
717 { 0x7c, 0x1e },
718 { 0x7d, 0x35 },
719 { 0x7e, 0x5a },
720 { 0x7f, 0x69 },
721 { 0x80, 0x76 },
722 { 0x81, 0x80 },
723 { 0x82, 0x88 },
724 { 0x83, 0x8f },
725 { 0x84, 0x96 },
726 { 0x85, 0xa3 },
727 { 0x86, 0xaf },
728 { 0x87, 0xc4 },
729 { 0x88, 0xd7 },
730 { 0x89, 0xe8 },
731
732/* AGC and AEC parameters. Note we start by disabling those features,
733 then turn them only after tweaking the values. */
734 { OV7670_REG_COM8, OV7670_COM8_FASTAEC
735 | OV7670_COM8_AECSTEP
736 | OV7670_COM8_BFILT },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300737 { OV7670_REG_GAIN, 0x00 },
738 { OV7670_REG_AECH, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300739 { OV7670_REG_COM4, 0x40 }, /* magic reserved bit */
740 { OV7670_REG_COM9, 0x18 }, /* 4x gain + magic rsvd bit */
741 { OV7670_REG_BD50MAX, 0x05 },
742 { OV7670_REG_BD60MAX, 0x07 },
743 { OV7670_REG_AEW, 0x95 },
744 { OV7670_REG_AEB, 0x33 },
745 { OV7670_REG_VPT, 0xe3 },
746 { OV7670_REG_HAECC1, 0x78 },
747 { OV7670_REG_HAECC2, 0x68 },
748 { 0xa1, 0x03 }, /* magic */
749 { OV7670_REG_HAECC3, 0xd8 },
750 { OV7670_REG_HAECC4, 0xd8 },
751 { OV7670_REG_HAECC5, 0xf0 },
752 { OV7670_REG_HAECC6, 0x90 },
753 { OV7670_REG_HAECC7, 0x94 },
754 { OV7670_REG_COM8, OV7670_COM8_FASTAEC
755 | OV7670_COM8_AECSTEP
756 | OV7670_COM8_BFILT
757 | OV7670_COM8_AGC
758 | OV7670_COM8_AEC },
759
760/* Almost all of these are magic "reserved" values. */
761 { OV7670_REG_COM5, 0x61 },
762 { OV7670_REG_COM6, 0x4b },
763 { 0x16, 0x02 },
764 { OV7670_REG_MVFP, 0x07 },
765 { 0x21, 0x02 },
766 { 0x22, 0x91 },
767 { 0x29, 0x07 },
768 { 0x33, 0x0b },
769 { 0x35, 0x0b },
770 { 0x37, 0x1d },
771 { 0x38, 0x71 },
772 { 0x39, 0x2a },
773 { OV7670_REG_COM12, 0x78 },
774 { 0x4d, 0x40 },
775 { 0x4e, 0x20 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300776 { OV7670_REG_GFIX, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300777 { 0x6b, 0x4a },
778 { 0x74, 0x10 },
779 { 0x8d, 0x4f },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300780 { 0x8e, 0x00 },
781 { 0x8f, 0x00 },
782 { 0x90, 0x00 },
783 { 0x91, 0x00 },
784 { 0x96, 0x00 },
785 { 0x9a, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300786 { 0xb0, 0x84 },
787 { 0xb1, 0x0c },
788 { 0xb2, 0x0e },
789 { 0xb3, 0x82 },
790 { 0xb8, 0x0a },
791
792/* More reserved magic, some of which tweaks white balance */
793 { 0x43, 0x0a },
794 { 0x44, 0xf0 },
795 { 0x45, 0x34 },
796 { 0x46, 0x58 },
797 { 0x47, 0x28 },
798 { 0x48, 0x3a },
799 { 0x59, 0x88 },
800 { 0x5a, 0x88 },
801 { 0x5b, 0x44 },
802 { 0x5c, 0x67 },
803 { 0x5d, 0x49 },
804 { 0x5e, 0x0e },
805 { 0x6c, 0x0a },
806 { 0x6d, 0x55 },
807 { 0x6e, 0x11 },
808 { 0x6f, 0x9f },
809 /* "9e for advance AWB" */
810 { 0x6a, 0x40 },
811 { OV7670_REG_BLUE, 0x40 },
812 { OV7670_REG_RED, 0x60 },
813 { OV7670_REG_COM8, OV7670_COM8_FASTAEC
814 | OV7670_COM8_AECSTEP
815 | OV7670_COM8_BFILT
816 | OV7670_COM8_AGC
817 | OV7670_COM8_AEC
818 | OV7670_COM8_AWB },
819
820/* Matrix coefficients */
821 { 0x4f, 0x80 },
822 { 0x50, 0x80 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300823 { 0x51, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300824 { 0x52, 0x22 },
825 { 0x53, 0x5e },
826 { 0x54, 0x80 },
827 { 0x58, 0x9e },
828
829 { OV7670_REG_COM16, OV7670_COM16_AWBGAIN },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300830 { OV7670_REG_EDGE, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300831 { 0x75, 0x05 },
832 { 0x76, 0xe1 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300833 { 0x4c, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300834 { 0x77, 0x01 },
835 { OV7670_REG_COM13, OV7670_COM13_GAMMA
836 | OV7670_COM13_UVSAT
837 | 2}, /* was 3 */
838 { 0x4b, 0x09 },
839 { 0xc9, 0x60 },
840 { OV7670_REG_COM16, 0x38 },
841 { 0x56, 0x40 },
842
843 { 0x34, 0x11 },
844 { OV7670_REG_COM11, OV7670_COM11_EXP|OV7670_COM11_HZAUTO },
845 { 0xa4, 0x88 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300846 { 0x96, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300847 { 0x97, 0x30 },
848 { 0x98, 0x20 },
849 { 0x99, 0x30 },
850 { 0x9a, 0x84 },
851 { 0x9b, 0x29 },
852 { 0x9c, 0x03 },
853 { 0x9d, 0x4c },
854 { 0x9e, 0x3f },
855 { 0x78, 0x04 },
856
857/* Extra-weird stuff. Some sort of multiplexor register */
858 { 0x79, 0x01 },
859 { 0xc8, 0xf0 },
860 { 0x79, 0x0f },
861 { 0xc8, 0x00 },
862 { 0x79, 0x10 },
863 { 0xc8, 0x7e },
864 { 0x79, 0x0a },
865 { 0xc8, 0x80 },
866 { 0x79, 0x0b },
867 { 0xc8, 0x01 },
868 { 0x79, 0x0c },
869 { 0xc8, 0x0f },
870 { 0x79, 0x0d },
871 { 0xc8, 0x20 },
872 { 0x79, 0x09 },
873 { 0xc8, 0x80 },
874 { 0x79, 0x02 },
875 { 0xc8, 0xc0 },
876 { 0x79, 0x03 },
877 { 0xc8, 0x40 },
878 { 0x79, 0x05 },
879 { 0xc8, 0x30 },
880 { 0x79, 0x26 },
881};
882
883static const struct ov_i2c_regvals norm_8610[] = {
884 { 0x12, 0x80 },
885 { 0x00, 0x00 },
886 { 0x01, 0x80 },
887 { 0x02, 0x80 },
888 { 0x03, 0xc0 },
889 { 0x04, 0x30 },
890 { 0x05, 0x30 }, /* was 0x10, new from windrv 090403 */
891 { 0x06, 0x70 }, /* was 0x80, new from windrv 090403 */
892 { 0x0a, 0x86 },
893 { 0x0b, 0xb0 },
894 { 0x0c, 0x20 },
895 { 0x0d, 0x20 },
896 { 0x11, 0x01 },
897 { 0x12, 0x25 },
898 { 0x13, 0x01 },
899 { 0x14, 0x04 },
900 { 0x15, 0x01 }, /* Lin and Win think different about UV order */
901 { 0x16, 0x03 },
902 { 0x17, 0x38 }, /* was 0x2f, new from windrv 090403 */
903 { 0x18, 0xea }, /* was 0xcf, new from windrv 090403 */
904 { 0x19, 0x02 }, /* was 0x06, new from windrv 090403 */
905 { 0x1a, 0xf5 },
906 { 0x1b, 0x00 },
907 { 0x20, 0xd0 }, /* was 0x90, new from windrv 090403 */
908 { 0x23, 0xc0 }, /* was 0x00, new from windrv 090403 */
909 { 0x24, 0x30 }, /* was 0x1d, new from windrv 090403 */
910 { 0x25, 0x50 }, /* was 0x57, new from windrv 090403 */
911 { 0x26, 0xa2 },
912 { 0x27, 0xea },
913 { 0x28, 0x00 },
914 { 0x29, 0x00 },
915 { 0x2a, 0x80 },
916 { 0x2b, 0xc8 }, /* was 0xcc, new from windrv 090403 */
917 { 0x2c, 0xac },
918 { 0x2d, 0x45 }, /* was 0xd5, new from windrv 090403 */
919 { 0x2e, 0x80 },
920 { 0x2f, 0x14 }, /* was 0x01, new from windrv 090403 */
921 { 0x4c, 0x00 },
922 { 0x4d, 0x30 }, /* was 0x10, new from windrv 090403 */
923 { 0x60, 0x02 }, /* was 0x01, new from windrv 090403 */
924 { 0x61, 0x00 }, /* was 0x09, new from windrv 090403 */
925 { 0x62, 0x5f }, /* was 0xd7, new from windrv 090403 */
926 { 0x63, 0xff },
927 { 0x64, 0x53 }, /* new windrv 090403 says 0x57,
928 * maybe thats wrong */
929 { 0x65, 0x00 },
930 { 0x66, 0x55 },
931 { 0x67, 0xb0 },
932 { 0x68, 0xc0 }, /* was 0xaf, new from windrv 090403 */
933 { 0x69, 0x02 },
934 { 0x6a, 0x22 },
935 { 0x6b, 0x00 },
936 { 0x6c, 0x99 }, /* was 0x80, old windrv says 0x00, but
937 * deleting bit7 colors the first images red */
938 { 0x6d, 0x11 }, /* was 0x00, new from windrv 090403 */
939 { 0x6e, 0x11 }, /* was 0x00, new from windrv 090403 */
940 { 0x6f, 0x01 },
941 { 0x70, 0x8b },
942 { 0x71, 0x00 },
943 { 0x72, 0x14 },
944 { 0x73, 0x54 },
945 { 0x74, 0x00 },/* 0x60? - was 0x00, new from windrv 090403 */
946 { 0x75, 0x0e },
947 { 0x76, 0x02 }, /* was 0x02, new from windrv 090403 */
948 { 0x77, 0xff },
949 { 0x78, 0x80 },
950 { 0x79, 0x80 },
951 { 0x7a, 0x80 },
952 { 0x7b, 0x10 }, /* was 0x13, new from windrv 090403 */
953 { 0x7c, 0x00 },
954 { 0x7d, 0x08 }, /* was 0x09, new from windrv 090403 */
955 { 0x7e, 0x08 }, /* was 0xc0, new from windrv 090403 */
956 { 0x7f, 0xfb },
957 { 0x80, 0x28 },
958 { 0x81, 0x00 },
959 { 0x82, 0x23 },
960 { 0x83, 0x0b },
961 { 0x84, 0x00 },
962 { 0x85, 0x62 }, /* was 0x61, new from windrv 090403 */
963 { 0x86, 0xc9 },
964 { 0x87, 0x00 },
965 { 0x88, 0x00 },
966 { 0x89, 0x01 },
967 { 0x12, 0x20 },
968 { 0x12, 0x25 }, /* was 0x24, new from windrv 090403 */
969};
970
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300971static unsigned char ov7670_abs_to_sm(unsigned char v)
972{
973 if (v > 127)
974 return v & 0x7f;
975 return (128 - v) | 0x80;
976}
977
978/* Write a OV519 register */
979static int reg_w(struct sd *sd, __u16 index, __u8 value)
980{
981 int ret;
Hans de Goede49809d62009-06-07 12:10:39 -0300982 int req = (sd->bridge <= BRIDGE_OV511PLUS) ? 2 : 1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300983
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300984 sd->gspca_dev.usb_buf[0] = value;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300985 ret = usb_control_msg(sd->gspca_dev.dev,
986 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
Hans de Goede49809d62009-06-07 12:10:39 -0300987 req,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300988 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
989 0, index,
Jean-Francois Moine739570b2008-07-14 09:38:29 -0300990 sd->gspca_dev.usb_buf, 1, 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300991 if (ret < 0)
992 PDEBUG(D_ERR, "Write reg [%02x] %02x failed", index, value);
993 return ret;
994}
995
996/* Read from a OV519 register */
997/* returns: negative is error, pos or zero is data */
998static int reg_r(struct sd *sd, __u16 index)
999{
1000 int ret;
Hans de Goede49809d62009-06-07 12:10:39 -03001001 int req = (sd->bridge <= BRIDGE_OV511PLUS) ? 3 : 1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001002
1003 ret = usb_control_msg(sd->gspca_dev.dev,
1004 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
Hans de Goede49809d62009-06-07 12:10:39 -03001005 req,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001006 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001007 0, index, sd->gspca_dev.usb_buf, 1, 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001008
1009 if (ret >= 0)
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001010 ret = sd->gspca_dev.usb_buf[0];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001011 else
1012 PDEBUG(D_ERR, "Read reg [0x%02x] failed", index);
1013 return ret;
1014}
1015
1016/* Read 8 values from a OV519 register */
1017static int reg_r8(struct sd *sd,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001018 __u16 index)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001019{
1020 int ret;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001021
1022 ret = usb_control_msg(sd->gspca_dev.dev,
1023 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
1024 1, /* REQ_IO */
1025 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001026 0, index, sd->gspca_dev.usb_buf, 8, 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001027
1028 if (ret >= 0)
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001029 ret = sd->gspca_dev.usb_buf[0];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001030 else
1031 PDEBUG(D_ERR, "Read reg 8 [0x%02x] failed", index);
1032 return ret;
1033}
1034
1035/*
1036 * Writes bits at positions specified by mask to an OV51x reg. Bits that are in
1037 * the same position as 1's in "mask" are cleared and set to "value". Bits
1038 * that are in the same position as 0's in "mask" are preserved, regardless
1039 * of their respective state in "value".
1040 */
1041static int reg_w_mask(struct sd *sd,
1042 __u16 index,
1043 __u8 value,
1044 __u8 mask)
1045{
1046 int ret;
1047 __u8 oldval;
1048
1049 if (mask != 0xff) {
1050 value &= mask; /* Enforce mask on value */
1051 ret = reg_r(sd, index);
1052 if (ret < 0)
1053 return ret;
1054
1055 oldval = ret & ~mask; /* Clear the masked bits */
1056 value |= oldval; /* Set the desired bits */
1057 }
1058 return reg_w(sd, index, value);
1059}
1060
1061/*
Hans de Goede49809d62009-06-07 12:10:39 -03001062 * Writes multiple (n) byte value to a single register. Only valid with certain
1063 * registers (0x30 and 0xc4 - 0xce).
1064 */
1065static int ov518_reg_w32(struct sd *sd, __u16 index, u32 value, int n)
1066{
1067 int ret;
1068
1069 *((u32 *)sd->gspca_dev.usb_buf) = __cpu_to_le32(value);
1070
1071 ret = usb_control_msg(sd->gspca_dev.dev,
1072 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
1073 1 /* REG_IO */,
1074 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1075 0, index,
1076 sd->gspca_dev.usb_buf, n, 500);
1077 if (ret < 0)
1078 PDEBUG(D_ERR, "Write reg32 [%02x] %08x failed", index, value);
1079 return ret;
1080}
1081
1082
1083/*
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001084 * The OV518 I2C I/O procedure is different, hence, this function.
1085 * This is normally only called from i2c_w(). Note that this function
1086 * always succeeds regardless of whether the sensor is present and working.
1087 */
1088static int i2c_w(struct sd *sd,
1089 __u8 reg,
1090 __u8 value)
1091{
1092 int rc;
1093
1094 PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
1095
1096 /* Select camera register */
1097 rc = reg_w(sd, R51x_I2C_SADDR_3, reg);
1098 if (rc < 0)
1099 return rc;
1100
1101 /* Write "value" to I2C data port of OV511 */
1102 rc = reg_w(sd, R51x_I2C_DATA, value);
1103 if (rc < 0)
1104 return rc;
1105
1106 /* Initiate 3-byte write cycle */
1107 rc = reg_w(sd, R518_I2C_CTL, 0x01);
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001108 if (rc < 0)
1109 return rc;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001110
1111 /* wait for write complete */
1112 msleep(4);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001113 return reg_r8(sd, R518_I2C_CTL);
1114}
1115
1116/*
1117 * returns: negative is error, pos or zero is data
1118 *
1119 * The OV518 I2C I/O procedure is different, hence, this function.
1120 * This is normally only called from i2c_r(). Note that this function
1121 * always succeeds regardless of whether the sensor is present and working.
1122 */
1123static int i2c_r(struct sd *sd, __u8 reg)
1124{
1125 int rc, value;
1126
1127 /* Select camera register */
1128 rc = reg_w(sd, R51x_I2C_SADDR_2, reg);
1129 if (rc < 0)
1130 return rc;
1131
1132 /* Initiate 2-byte write cycle */
1133 rc = reg_w(sd, R518_I2C_CTL, 0x03);
1134 if (rc < 0)
1135 return rc;
1136
1137 /* Initiate 2-byte read cycle */
1138 rc = reg_w(sd, R518_I2C_CTL, 0x05);
1139 if (rc < 0)
1140 return rc;
1141 value = reg_r(sd, R51x_I2C_DATA);
1142 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value);
1143 return value;
1144}
1145
1146/* Writes bits at positions specified by mask to an I2C reg. Bits that are in
1147 * the same position as 1's in "mask" are cleared and set to "value". Bits
1148 * that are in the same position as 0's in "mask" are preserved, regardless
1149 * of their respective state in "value".
1150 */
1151static int i2c_w_mask(struct sd *sd,
1152 __u8 reg,
1153 __u8 value,
1154 __u8 mask)
1155{
1156 int rc;
1157 __u8 oldval;
1158
1159 value &= mask; /* Enforce mask on value */
1160 rc = i2c_r(sd, reg);
1161 if (rc < 0)
1162 return rc;
1163 oldval = rc & ~mask; /* Clear the masked bits */
1164 value |= oldval; /* Set the desired bits */
1165 return i2c_w(sd, reg, value);
1166}
1167
1168/* Temporarily stops OV511 from functioning. Must do this before changing
1169 * registers while the camera is streaming */
1170static inline int ov51x_stop(struct sd *sd)
1171{
1172 PDEBUG(D_STREAM, "stopping");
1173 sd->stopped = 1;
Hans de Goede49809d62009-06-07 12:10:39 -03001174 switch (sd->bridge) {
1175 case BRIDGE_OV511:
1176 case BRIDGE_OV511PLUS:
1177 return reg_w(sd, R51x_SYS_RESET, 0x3d);
1178 case BRIDGE_OV518:
1179 case BRIDGE_OV518PLUS:
1180 return reg_w_mask(sd, R51x_SYS_RESET, 0x3a, 0x3a);
1181 case BRIDGE_OV519:
1182 return reg_w(sd, OV519_SYS_RESET1, 0x0f);
1183 }
1184
1185 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001186}
1187
1188/* Restarts OV511 after ov511_stop() is called. Has no effect if it is not
1189 * actually stopped (for performance). */
1190static inline int ov51x_restart(struct sd *sd)
1191{
Hans de Goede49809d62009-06-07 12:10:39 -03001192 int rc;
1193
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001194 PDEBUG(D_STREAM, "restarting");
1195 if (!sd->stopped)
1196 return 0;
1197 sd->stopped = 0;
1198
1199 /* Reinitialize the stream */
Hans de Goede49809d62009-06-07 12:10:39 -03001200 switch (sd->bridge) {
1201 case BRIDGE_OV511:
1202 case BRIDGE_OV511PLUS:
1203 return reg_w(sd, R51x_SYS_RESET, 0x00);
1204 case BRIDGE_OV518:
1205 case BRIDGE_OV518PLUS:
1206 rc = reg_w(sd, 0x2f, 0x80);
1207 if (rc < 0)
1208 return rc;
1209 return reg_w(sd, R51x_SYS_RESET, 0x00);
1210 case BRIDGE_OV519:
1211 return reg_w(sd, OV519_SYS_RESET1, 0x00);
1212 }
1213
1214 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001215}
1216
1217/* This does an initial reset of an OmniVision sensor and ensures that I2C
1218 * is synchronized. Returns <0 on failure.
1219 */
1220static int init_ov_sensor(struct sd *sd)
1221{
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001222 int i;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001223
1224 /* Reset the sensor */
1225 if (i2c_w(sd, 0x12, 0x80) < 0)
1226 return -EIO;
1227
1228 /* Wait for it to initialize */
1229 msleep(150);
1230
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001231 for (i = 0; i < i2c_detect_tries; i++) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001232 if (i2c_r(sd, OV7610_REG_ID_HIGH) == 0x7f &&
1233 i2c_r(sd, OV7610_REG_ID_LOW) == 0xa2) {
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001234 PDEBUG(D_PROBE, "I2C synced in %d attempt(s)", i);
1235 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001236 }
1237
1238 /* Reset the sensor */
1239 if (i2c_w(sd, 0x12, 0x80) < 0)
1240 return -EIO;
1241 /* Wait for it to initialize */
1242 msleep(150);
1243 /* Dummy read to sync I2C */
1244 if (i2c_r(sd, 0x00) < 0)
1245 return -EIO;
1246 }
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001247 return -EIO;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001248}
1249
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001250/* Set the read and write slave IDs. The "slave" argument is the write slave,
1251 * and the read slave will be set to (slave + 1).
1252 * This should not be called from outside the i2c I/O functions.
1253 * Sets I2C read and write slave IDs. Returns <0 for error
1254 */
1255static int ov51x_set_slave_ids(struct sd *sd,
1256 __u8 slave)
1257{
1258 int rc;
1259
1260 rc = reg_w(sd, R51x_I2C_W_SID, slave);
1261 if (rc < 0)
1262 return rc;
1263 return reg_w(sd, R51x_I2C_R_SID, slave + 1);
1264}
1265
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001266static int write_regvals(struct sd *sd,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001267 const struct ov_regvals *regvals,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001268 int n)
1269{
1270 int rc;
1271
1272 while (--n >= 0) {
1273 rc = reg_w(sd, regvals->reg, regvals->val);
1274 if (rc < 0)
1275 return rc;
1276 regvals++;
1277 }
1278 return 0;
1279}
1280
1281static int write_i2c_regvals(struct sd *sd,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001282 const struct ov_i2c_regvals *regvals,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001283 int n)
1284{
1285 int rc;
1286
1287 while (--n >= 0) {
1288 rc = i2c_w(sd, regvals->reg, regvals->val);
1289 if (rc < 0)
1290 return rc;
1291 regvals++;
1292 }
1293 return 0;
1294}
1295
1296/****************************************************************************
1297 *
1298 * OV511 and sensor configuration
1299 *
1300 ***************************************************************************/
1301
1302/* This initializes the OV8110, OV8610 sensor. The OV8110 uses
1303 * the same register settings as the OV8610, since they are very similar.
1304 */
1305static int ov8xx0_configure(struct sd *sd)
1306{
1307 int rc;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001308
1309 PDEBUG(D_PROBE, "starting ov8xx0 configuration");
1310
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001311 /* Detect sensor (sub)type */
1312 rc = i2c_r(sd, OV7610_REG_COM_I);
1313 if (rc < 0) {
1314 PDEBUG(D_ERR, "Error detecting sensor type");
1315 return -1;
1316 }
1317 if ((rc & 3) == 1) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001318 sd->sensor = SEN_OV8610;
1319 } else {
1320 PDEBUG(D_ERR, "Unknown image sensor version: %d", rc & 3);
1321 return -1;
1322 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001323
1324 /* Set sensor-specific vars */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001325/* sd->sif = 0; already done */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001326 return 0;
1327}
1328
1329/* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
1330 * the same register settings as the OV7610, since they are very similar.
1331 */
1332static int ov7xx0_configure(struct sd *sd)
1333{
1334 int rc, high, low;
1335
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001336
1337 PDEBUG(D_PROBE, "starting OV7xx0 configuration");
1338
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001339 /* Detect sensor (sub)type */
1340 rc = i2c_r(sd, OV7610_REG_COM_I);
1341
1342 /* add OV7670 here
1343 * it appears to be wrongly detected as a 7610 by default */
1344 if (rc < 0) {
1345 PDEBUG(D_ERR, "Error detecting sensor type");
1346 return -1;
1347 }
1348 if ((rc & 3) == 3) {
1349 /* quick hack to make OV7670s work */
1350 high = i2c_r(sd, 0x0a);
1351 low = i2c_r(sd, 0x0b);
1352 /* info("%x, %x", high, low); */
1353 if (high == 0x76 && low == 0x73) {
1354 PDEBUG(D_PROBE, "Sensor is an OV7670");
1355 sd->sensor = SEN_OV7670;
1356 } else {
1357 PDEBUG(D_PROBE, "Sensor is an OV7610");
1358 sd->sensor = SEN_OV7610;
1359 }
1360 } else if ((rc & 3) == 1) {
1361 /* I don't know what's different about the 76BE yet. */
1362 if (i2c_r(sd, 0x15) & 1)
1363 PDEBUG(D_PROBE, "Sensor is an OV7620AE");
1364 else
1365 PDEBUG(D_PROBE, "Sensor is an OV76BE");
1366
1367 /* OV511+ will return all zero isoc data unless we
1368 * configure the sensor as a 7620. Someone needs to
1369 * find the exact reg. setting that causes this. */
1370 sd->sensor = SEN_OV76BE;
1371 } else if ((rc & 3) == 0) {
1372 /* try to read product id registers */
1373 high = i2c_r(sd, 0x0a);
1374 if (high < 0) {
1375 PDEBUG(D_ERR, "Error detecting camera chip PID");
1376 return high;
1377 }
1378 low = i2c_r(sd, 0x0b);
1379 if (low < 0) {
1380 PDEBUG(D_ERR, "Error detecting camera chip VER");
1381 return low;
1382 }
1383 if (high == 0x76) {
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001384 switch (low) {
1385 case 0x30:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001386 PDEBUG(D_PROBE, "Sensor is an OV7630/OV7635");
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001387 PDEBUG(D_ERR,
1388 "7630 is not supported by this driver");
1389 return -1;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001390 case 0x40:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001391 PDEBUG(D_PROBE, "Sensor is an OV7645");
1392 sd->sensor = SEN_OV7640; /* FIXME */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001393 break;
1394 case 0x45:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001395 PDEBUG(D_PROBE, "Sensor is an OV7645B");
1396 sd->sensor = SEN_OV7640; /* FIXME */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001397 break;
1398 case 0x48:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001399 PDEBUG(D_PROBE, "Sensor is an OV7648");
1400 sd->sensor = SEN_OV7640; /* FIXME */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001401 break;
1402 default:
1403 PDEBUG(D_PROBE, "Unknown sensor: 0x76%x", low);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001404 return -1;
1405 }
1406 } else {
1407 PDEBUG(D_PROBE, "Sensor is an OV7620");
1408 sd->sensor = SEN_OV7620;
1409 }
1410 } else {
1411 PDEBUG(D_ERR, "Unknown image sensor version: %d", rc & 3);
1412 return -1;
1413 }
1414
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001415 /* Set sensor-specific vars */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001416/* sd->sif = 0; already done */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001417 return 0;
1418}
1419
1420/* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
1421static int ov6xx0_configure(struct sd *sd)
1422{
1423 int rc;
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001424 PDEBUG(D_PROBE, "starting OV6xx0 configuration");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001425
1426 /* Detect sensor (sub)type */
1427 rc = i2c_r(sd, OV7610_REG_COM_I);
1428 if (rc < 0) {
1429 PDEBUG(D_ERR, "Error detecting sensor type");
1430 return -1;
1431 }
1432
1433 /* Ugh. The first two bits are the version bits, but
1434 * the entire register value must be used. I guess OVT
1435 * underestimated how many variants they would make. */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001436 switch (rc) {
1437 case 0x00:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001438 sd->sensor = SEN_OV6630;
1439 PDEBUG(D_ERR,
1440 "WARNING: Sensor is an OV66308. Your camera may have");
1441 PDEBUG(D_ERR, "been misdetected in previous driver versions.");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001442 break;
1443 case 0x01:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001444 sd->sensor = SEN_OV6620;
Hans de Goede7d971372009-06-14 05:28:17 -03001445 PDEBUG(D_PROBE, "Sensor is an OV6620");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001446 break;
1447 case 0x02:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001448 sd->sensor = SEN_OV6630;
1449 PDEBUG(D_PROBE, "Sensor is an OV66308AE");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001450 break;
1451 case 0x03:
Hans de Goede7d971372009-06-14 05:28:17 -03001452 sd->sensor = SEN_OV66308AF;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001453 PDEBUG(D_PROBE, "Sensor is an OV66308AF");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001454 break;
1455 case 0x90:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001456 sd->sensor = SEN_OV6630;
1457 PDEBUG(D_ERR,
1458 "WARNING: Sensor is an OV66307. Your camera may have");
1459 PDEBUG(D_ERR, "been misdetected in previous driver versions.");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001460 break;
1461 default:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001462 PDEBUG(D_ERR, "FATAL: Unknown sensor version: 0x%02x", rc);
1463 return -1;
1464 }
1465
1466 /* Set sensor-specific vars */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001467 sd->sif = 1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001468
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001469 return 0;
1470}
1471
1472/* Turns on or off the LED. Only has an effect with OV511+/OV518(+)/OV519 */
1473static void ov51x_led_control(struct sd *sd, int on)
1474{
Hans de Goede9e4d8252009-06-14 06:25:06 -03001475 if (sd->invert_led)
1476 on = !on;
1477
Hans de Goede49809d62009-06-07 12:10:39 -03001478 switch (sd->bridge) {
1479 /* OV511 has no LED control */
1480 case BRIDGE_OV511PLUS:
1481 reg_w(sd, R511_SYS_LED_CTL, on ? 1 : 0);
1482 break;
1483 case BRIDGE_OV518:
1484 case BRIDGE_OV518PLUS:
1485 reg_w_mask(sd, R518_GPIO_OUT, on ? 0x02 : 0x00, 0x02);
1486 break;
1487 case BRIDGE_OV519:
1488 reg_w_mask(sd, OV519_GPIO_DATA_OUT0, !on, 1); /* 0 / 1 */
1489 break;
1490 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001491}
1492
Hans de Goede49809d62009-06-07 12:10:39 -03001493/* OV518 quantization tables are 8x4 (instead of 8x8) */
1494static int ov518_upload_quan_tables(struct sd *sd)
1495{
1496 const unsigned char yQuanTable518[] = {
1497 5, 4, 5, 6, 6, 7, 7, 7,
1498 5, 5, 5, 5, 6, 7, 7, 7,
1499 6, 6, 6, 6, 7, 7, 7, 8,
1500 7, 7, 6, 7, 7, 7, 8, 8
1501 };
1502
1503 const unsigned char uvQuanTable518[] = {
1504 6, 6, 6, 7, 7, 7, 7, 7,
1505 6, 6, 6, 7, 7, 7, 7, 7,
1506 6, 6, 6, 7, 7, 7, 7, 8,
1507 7, 7, 7, 7, 7, 7, 8, 8
1508 };
1509
1510 const unsigned char *pYTable = yQuanTable518;
1511 const unsigned char *pUVTable = uvQuanTable518;
1512 unsigned char val0, val1;
1513 int i, rc, reg = R51x_COMP_LUT_BEGIN;
1514
1515 PDEBUG(D_PROBE, "Uploading quantization tables");
1516
1517 for (i = 0; i < 16; i++) {
1518 val0 = *pYTable++;
1519 val1 = *pYTable++;
1520 val0 &= 0x0f;
1521 val1 &= 0x0f;
1522 val0 |= val1 << 4;
1523 rc = reg_w(sd, reg, val0);
1524 if (rc < 0)
1525 return rc;
1526
1527 val0 = *pUVTable++;
1528 val1 = *pUVTable++;
1529 val0 &= 0x0f;
1530 val1 &= 0x0f;
1531 val0 |= val1 << 4;
1532 rc = reg_w(sd, reg + 16, val0);
1533 if (rc < 0)
1534 return rc;
1535
1536 reg++;
1537 }
1538
1539 return 0;
1540}
1541
1542/* This initializes the OV518/OV518+ and the sensor */
1543static int ov518_configure(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001544{
1545 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede49809d62009-06-07 12:10:39 -03001546 int rc;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001547
Hans de Goede49809d62009-06-07 12:10:39 -03001548 /* For 518 and 518+ */
1549 static struct ov_regvals init_518[] = {
1550 { R51x_SYS_RESET, 0x40 },
1551 { R51x_SYS_INIT, 0xe1 },
1552 { R51x_SYS_RESET, 0x3e },
1553 { R51x_SYS_INIT, 0xe1 },
1554 { R51x_SYS_RESET, 0x00 },
1555 { R51x_SYS_INIT, 0xe1 },
1556 { 0x46, 0x00 },
1557 { 0x5d, 0x03 },
1558 };
1559
1560 static struct ov_regvals norm_518[] = {
1561 { R51x_SYS_SNAP, 0x02 }, /* Reset */
1562 { R51x_SYS_SNAP, 0x01 }, /* Enable */
1563 { 0x31, 0x0f },
1564 { 0x5d, 0x03 },
1565 { 0x24, 0x9f },
1566 { 0x25, 0x90 },
1567 { 0x20, 0x00 },
1568 { 0x51, 0x04 },
1569 { 0x71, 0x19 },
1570 { 0x2f, 0x80 },
1571 };
1572
1573 static struct ov_regvals norm_518_p[] = {
1574 { R51x_SYS_SNAP, 0x02 }, /* Reset */
1575 { R51x_SYS_SNAP, 0x01 }, /* Enable */
1576 { 0x31, 0x0f },
1577 { 0x5d, 0x03 },
1578 { 0x24, 0x9f },
1579 { 0x25, 0x90 },
1580 { 0x20, 0x60 },
1581 { 0x51, 0x02 },
1582 { 0x71, 0x19 },
1583 { 0x40, 0xff },
1584 { 0x41, 0x42 },
1585 { 0x46, 0x00 },
1586 { 0x33, 0x04 },
1587 { 0x21, 0x19 },
1588 { 0x3f, 0x10 },
1589 { 0x2f, 0x80 },
1590 };
1591
1592 /* First 5 bits of custom ID reg are a revision ID on OV518 */
1593 PDEBUG(D_PROBE, "Device revision %d",
1594 0x1F & reg_r(sd, R51x_SYS_CUST_ID));
1595
1596 rc = write_regvals(sd, init_518, ARRAY_SIZE(init_518));
1597 if (rc < 0)
1598 return rc;
1599
1600 /* Set LED GPIO pin to output mode */
1601 rc = reg_w_mask(sd, R518_GPIO_CTL, 0x00, 0x02);
1602 if (rc < 0)
1603 return rc;
1604
1605 switch (sd->bridge) {
1606 case BRIDGE_OV518:
1607 rc = write_regvals(sd, norm_518, ARRAY_SIZE(norm_518));
1608 if (rc < 0)
1609 return rc;
1610 break;
1611 case BRIDGE_OV518PLUS:
1612 rc = write_regvals(sd, norm_518_p, ARRAY_SIZE(norm_518_p));
1613 if (rc < 0)
1614 return rc;
1615 break;
1616 }
1617
1618 rc = ov518_upload_quan_tables(sd);
1619 if (rc < 0) {
1620 PDEBUG(D_ERR, "Error uploading quantization tables");
1621 return rc;
1622 }
1623
1624 rc = reg_w(sd, 0x2f, 0x80);
1625 if (rc < 0)
1626 return rc;
1627
1628 return 0;
1629}
1630
1631static int ov519_configure(struct sd *sd)
1632{
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001633 static const struct ov_regvals init_519[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001634 { 0x5a, 0x6d }, /* EnableSystem */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001635 { 0x53, 0x9b },
1636 { 0x54, 0xff }, /* set bit2 to enable jpeg */
1637 { 0x5d, 0x03 },
1638 { 0x49, 0x01 },
1639 { 0x48, 0x00 },
1640 /* Set LED pin to output mode. Bit 4 must be cleared or sensor
1641 * detection will fail. This deserves further investigation. */
1642 { OV519_GPIO_IO_CTRL0, 0xee },
1643 { 0x51, 0x0f }, /* SetUsbInit */
1644 { 0x51, 0x00 },
1645 { 0x22, 0x00 },
1646 /* windows reads 0x55 at this point*/
1647 };
1648
Hans de Goede49809d62009-06-07 12:10:39 -03001649 return write_regvals(sd, init_519, ARRAY_SIZE(init_519));
1650}
1651
1652/* this function is called at probe time */
1653static int sd_config(struct gspca_dev *gspca_dev,
1654 const struct usb_device_id *id)
1655{
1656 struct sd *sd = (struct sd *) gspca_dev;
1657 struct cam *cam;
1658 int ret = 0;
1659
Hans de Goede9e4d8252009-06-14 06:25:06 -03001660 sd->bridge = id->driver_info & BRIDGE_MASK;
1661 sd->invert_led = id->driver_info & BRIDGE_INVERT_LED;
Hans de Goede49809d62009-06-07 12:10:39 -03001662
1663 switch (sd->bridge) {
1664 case BRIDGE_OV518:
1665 case BRIDGE_OV518PLUS:
1666 ret = ov518_configure(gspca_dev);
1667 break;
1668 case BRIDGE_OV519:
1669 ret = ov519_configure(sd);
1670 break;
1671 }
1672
1673 if (ret)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001674 goto error;
Hans de Goede49809d62009-06-07 12:10:39 -03001675
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001676 ov51x_led_control(sd, 0); /* turn LED off */
1677
1678 /* Test for 76xx */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001679 if (ov51x_set_slave_ids(sd, OV7xx0_SID) < 0)
1680 goto error;
1681
1682 /* The OV519 must be more aggressive about sensor detection since
1683 * I2C write will never fail if the sensor is not present. We have
1684 * to try to initialize the sensor to detect its presence */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001685 if (init_ov_sensor(sd) >= 0) {
1686 if (ov7xx0_configure(sd) < 0) {
1687 PDEBUG(D_ERR, "Failed to configure OV7xx0");
1688 goto error;
1689 }
1690 } else {
1691
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001692 /* Test for 6xx0 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001693 if (ov51x_set_slave_ids(sd, OV6xx0_SID) < 0)
1694 goto error;
1695
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001696 if (init_ov_sensor(sd) >= 0) {
1697 if (ov6xx0_configure(sd) < 0) {
1698 PDEBUG(D_ERR, "Failed to configure OV6xx0");
1699 goto error;
1700 }
1701 } else {
1702
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001703 /* Test for 8xx0 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001704 if (ov51x_set_slave_ids(sd, OV8xx0_SID) < 0)
1705 goto error;
1706
1707 if (init_ov_sensor(sd) < 0) {
1708 PDEBUG(D_ERR,
1709 "Can't determine sensor slave IDs");
1710 goto error;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001711 }
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001712 if (ov8xx0_configure(sd) < 0) {
1713 PDEBUG(D_ERR,
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001714 "Failed to configure OV8xx0 sensor");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001715 goto error;
1716 }
1717 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001718 }
1719
1720 cam = &gspca_dev->cam;
Hans de Goede49809d62009-06-07 12:10:39 -03001721 switch (sd->bridge) {
1722 case BRIDGE_OV518:
1723 case BRIDGE_OV518PLUS:
1724 if (!sd->sif) {
1725 cam->cam_mode = ov518_vga_mode;
1726 cam->nmodes = ARRAY_SIZE(ov518_vga_mode);
1727 } else {
1728 cam->cam_mode = ov518_sif_mode;
1729 cam->nmodes = ARRAY_SIZE(ov518_sif_mode);
1730 }
1731 break;
1732 case BRIDGE_OV519:
1733 if (!sd->sif) {
1734 cam->cam_mode = ov519_vga_mode;
1735 cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
1736 } else {
1737 cam->cam_mode = ov519_sif_mode;
1738 cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
1739 }
1740 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001741 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001742 sd->brightness = BRIGHTNESS_DEF;
Hans de Goedef5cee952009-06-14 06:32:52 -03001743 if (sd->sensor == SEN_OV6630 || sd->sensor == SEN_OV66308AF)
1744 sd->contrast = 200; /* The default is too low for the ov6630 */
1745 else
1746 sd->contrast = CONTRAST_DEF;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001747 sd->colors = COLOR_DEF;
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03001748 sd->hflip = HFLIP_DEF;
1749 sd->vflip = VFLIP_DEF;
Hans de Goede02ab18b2009-06-14 04:32:04 -03001750 sd->autobrightness = AUTOBRIGHT_DEF;
1751 if (sd->sensor == SEN_OV7670) {
1752 sd->freq = OV7670_FREQ_DEF;
1753 gspca_dev->ctrl_dis = 1 << FREQ_IDX;
1754 } else {
1755 sd->freq = FREQ_DEF;
1756 gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX) |
1757 (1 << OV7670_FREQ_IDX);
1758 }
1759 if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7670)
1760 gspca_dev->ctrl_dis |= 1 << AUTOBRIGHT_IDX;
1761 /* OV8610 Frequency filter control should work but needs testing */
1762 if (sd->sensor == SEN_OV8610)
1763 gspca_dev->ctrl_dis |= 1 << FREQ_IDX;
1764
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001765 return 0;
1766error:
1767 PDEBUG(D_ERR, "OV519 Config failed");
1768 return -EBUSY;
1769}
1770
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03001771/* this function is called at probe and resume time */
1772static int sd_init(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001773{
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001774 struct sd *sd = (struct sd *) gspca_dev;
1775
1776 /* initialize the sensor */
1777 switch (sd->sensor) {
1778 case SEN_OV6620:
1779 if (write_i2c_regvals(sd, norm_6x20, ARRAY_SIZE(norm_6x20)))
1780 return -EIO;
1781 break;
1782 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03001783 case SEN_OV66308AF:
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001784 if (write_i2c_regvals(sd, norm_6x30, ARRAY_SIZE(norm_6x30)))
1785 return -EIO;
1786 break;
1787 default:
1788/* case SEN_OV7610: */
1789/* case SEN_OV76BE: */
1790 if (write_i2c_regvals(sd, norm_7610, ARRAY_SIZE(norm_7610)))
1791 return -EIO;
1792 break;
1793 case SEN_OV7620:
1794 if (write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620)))
1795 return -EIO;
1796 break;
1797 case SEN_OV7640:
1798 if (write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640)))
1799 return -EIO;
1800 break;
1801 case SEN_OV7670:
1802 if (write_i2c_regvals(sd, norm_7670, ARRAY_SIZE(norm_7670)))
1803 return -EIO;
1804 break;
1805 case SEN_OV8610:
1806 if (write_i2c_regvals(sd, norm_8610, ARRAY_SIZE(norm_8610)))
1807 return -EIO;
1808 break;
1809 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001810 return 0;
1811}
1812
Hans de Goede49809d62009-06-07 12:10:39 -03001813/* Sets up the OV518/OV518+ with the given image parameters
1814 *
1815 * OV518 needs a completely different approach, until we can figure out what
1816 * the individual registers do. Also, only 15 FPS is supported now.
1817 *
1818 * Do not put any sensor-specific code in here (including I2C I/O functions)
1819 */
1820static int ov518_mode_init_regs(struct sd *sd)
1821{
1822 int hsegs, vsegs;
1823
1824 /******** Set the mode ********/
1825
1826 reg_w(sd, 0x2b, 0);
1827 reg_w(sd, 0x2c, 0);
1828 reg_w(sd, 0x2d, 0);
1829 reg_w(sd, 0x2e, 0);
1830 reg_w(sd, 0x3b, 0);
1831 reg_w(sd, 0x3c, 0);
1832 reg_w(sd, 0x3d, 0);
1833 reg_w(sd, 0x3e, 0);
1834
1835 if (sd->bridge == BRIDGE_OV518) {
1836 /* Set 8-bit (YVYU) input format */
1837 reg_w_mask(sd, 0x20, 0x08, 0x08);
1838
1839 /* Set 12-bit (4:2:0) output format */
1840 reg_w_mask(sd, 0x28, 0x80, 0xf0);
1841 reg_w_mask(sd, 0x38, 0x80, 0xf0);
1842 } else {
1843 reg_w(sd, 0x28, 0x80);
1844 reg_w(sd, 0x38, 0x80);
1845 }
1846
1847 hsegs = sd->gspca_dev.width / 16;
1848 vsegs = sd->gspca_dev.height / 4;
1849
1850 reg_w(sd, 0x29, hsegs);
1851 reg_w(sd, 0x2a, vsegs);
1852
1853 reg_w(sd, 0x39, hsegs);
1854 reg_w(sd, 0x3a, vsegs);
1855
1856 /* Windows driver does this here; who knows why */
1857 reg_w(sd, 0x2f, 0x80);
1858
1859 /******** Set the framerate (to 30 FPS) ********/
1860 if (sd->bridge == BRIDGE_OV518PLUS)
1861 sd->clockdiv = 1;
1862 else
1863 sd->clockdiv = 0;
1864
1865 /* Mode independent, but framerate dependent, regs */
1866 reg_w(sd, 0x51, 0x04); /* Clock divider; lower==faster */
1867 reg_w(sd, 0x22, 0x18);
1868 reg_w(sd, 0x23, 0xff);
1869
1870 if (sd->bridge == BRIDGE_OV518PLUS)
1871 reg_w(sd, 0x21, 0x19);
1872 else
1873 reg_w(sd, 0x71, 0x17); /* Compression-related? */
1874
1875 /* FIXME: Sensor-specific */
1876 /* Bit 5 is what matters here. Of course, it is "reserved" */
1877 i2c_w(sd, 0x54, 0x23);
1878
1879 reg_w(sd, 0x2f, 0x80);
1880
1881 if (sd->bridge == BRIDGE_OV518PLUS) {
1882 reg_w(sd, 0x24, 0x94);
1883 reg_w(sd, 0x25, 0x90);
1884 ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
1885 ov518_reg_w32(sd, 0xc6, 540, 2); /* 21ch */
1886 ov518_reg_w32(sd, 0xc7, 540, 2); /* 21ch */
1887 ov518_reg_w32(sd, 0xc8, 108, 2); /* 6ch */
1888 ov518_reg_w32(sd, 0xca, 131098, 3); /* 2001ah */
1889 ov518_reg_w32(sd, 0xcb, 532, 2); /* 214h */
1890 ov518_reg_w32(sd, 0xcc, 2400, 2); /* 960h */
1891 ov518_reg_w32(sd, 0xcd, 32, 2); /* 20h */
1892 ov518_reg_w32(sd, 0xce, 608, 2); /* 260h */
1893 } else {
1894 reg_w(sd, 0x24, 0x9f);
1895 reg_w(sd, 0x25, 0x90);
1896 ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
1897 ov518_reg_w32(sd, 0xc6, 381, 2); /* 17dh */
1898 ov518_reg_w32(sd, 0xc7, 381, 2); /* 17dh */
1899 ov518_reg_w32(sd, 0xc8, 128, 2); /* 80h */
1900 ov518_reg_w32(sd, 0xca, 183331, 3); /* 2cc23h */
1901 ov518_reg_w32(sd, 0xcb, 746, 2); /* 2eah */
1902 ov518_reg_w32(sd, 0xcc, 1750, 2); /* 6d6h */
1903 ov518_reg_w32(sd, 0xcd, 45, 2); /* 2dh */
1904 ov518_reg_w32(sd, 0xce, 851, 2); /* 353h */
1905 }
1906
1907 reg_w(sd, 0x2f, 0x80);
1908
1909 return 0;
1910}
1911
1912
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001913/* Sets up the OV519 with the given image parameters
1914 *
1915 * OV519 needs a completely different approach, until we can figure out what
1916 * the individual registers do.
1917 *
1918 * Do not put any sensor-specific code in here (including I2C I/O functions)
1919 */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001920static int ov519_mode_init_regs(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001921{
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001922 static const struct ov_regvals mode_init_519_ov7670[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001923 { 0x5d, 0x03 }, /* Turn off suspend mode */
1924 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
1925 { 0x54, 0x0f }, /* bit2 (jpeg enable) */
1926 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
1927 { 0xa3, 0x18 },
1928 { 0xa4, 0x04 },
1929 { 0xa5, 0x28 },
1930 { 0x37, 0x00 }, /* SetUsbInit */
1931 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
1932 /* Enable both fields, YUV Input, disable defect comp (why?) */
1933 { 0x20, 0x0c },
1934 { 0x21, 0x38 },
1935 { 0x22, 0x1d },
1936 { 0x17, 0x50 }, /* undocumented */
1937 { 0x37, 0x00 }, /* undocumented */
1938 { 0x40, 0xff }, /* I2C timeout counter */
1939 { 0x46, 0x00 }, /* I2C clock prescaler */
1940 { 0x59, 0x04 }, /* new from windrv 090403 */
1941 { 0xff, 0x00 }, /* undocumented */
1942 /* windows reads 0x55 at this point, why? */
1943 };
1944
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001945 static const struct ov_regvals mode_init_519[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001946 { 0x5d, 0x03 }, /* Turn off suspend mode */
1947 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
1948 { 0x54, 0x0f }, /* bit2 (jpeg enable) */
1949 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
1950 { 0xa3, 0x18 },
1951 { 0xa4, 0x04 },
1952 { 0xa5, 0x28 },
1953 { 0x37, 0x00 }, /* SetUsbInit */
1954 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
1955 /* Enable both fields, YUV Input, disable defect comp (why?) */
1956 { 0x22, 0x1d },
1957 { 0x17, 0x50 }, /* undocumented */
1958 { 0x37, 0x00 }, /* undocumented */
1959 { 0x40, 0xff }, /* I2C timeout counter */
1960 { 0x46, 0x00 }, /* I2C clock prescaler */
1961 { 0x59, 0x04 }, /* new from windrv 090403 */
1962 { 0xff, 0x00 }, /* undocumented */
1963 /* windows reads 0x55 at this point, why? */
1964 };
1965
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001966 /******** Set the mode ********/
1967 if (sd->sensor != SEN_OV7670) {
1968 if (write_regvals(sd, mode_init_519,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001969 ARRAY_SIZE(mode_init_519)))
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001970 return -EIO;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001971 if (sd->sensor == SEN_OV7640) {
1972 /* Select 8-bit input mode */
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001973 reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10);
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001974 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001975 } else {
1976 if (write_regvals(sd, mode_init_519_ov7670,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001977 ARRAY_SIZE(mode_init_519_ov7670)))
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001978 return -EIO;
1979 }
1980
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001981 reg_w(sd, OV519_R10_H_SIZE, sd->gspca_dev.width >> 4);
1982 reg_w(sd, OV519_R11_V_SIZE, sd->gspca_dev.height >> 3);
Hans de Goede80142ef2009-06-14 06:26:49 -03001983 if (sd->sensor == SEN_OV7670 &&
1984 sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
1985 reg_w(sd, OV519_R12_X_OFFSETL, 0x04);
1986 else
1987 reg_w(sd, OV519_R12_X_OFFSETL, 0x00);
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001988 reg_w(sd, OV519_R13_X_OFFSETH, 0x00);
1989 reg_w(sd, OV519_R14_Y_OFFSETL, 0x00);
1990 reg_w(sd, OV519_R15_Y_OFFSETH, 0x00);
1991 reg_w(sd, OV519_R16_DIVIDER, 0x00);
1992 reg_w(sd, OV519_R25_FORMAT, 0x03); /* YUV422 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001993 reg_w(sd, 0x26, 0x00); /* Undocumented */
1994
1995 /******** Set the framerate ********/
1996 if (frame_rate > 0)
1997 sd->frame_rate = frame_rate;
1998
1999/* FIXME: These are only valid at the max resolution. */
2000 sd->clockdiv = 0;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002001 switch (sd->sensor) {
2002 case SEN_OV7640:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002003 switch (sd->frame_rate) {
Jean-Francois Moine53e74512008-11-08 06:10:19 -03002004 default:
2005/* case 30: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002006 reg_w(sd, 0xa4, 0x0c);
2007 reg_w(sd, 0x23, 0xff);
2008 break;
2009 case 25:
2010 reg_w(sd, 0xa4, 0x0c);
2011 reg_w(sd, 0x23, 0x1f);
2012 break;
2013 case 20:
2014 reg_w(sd, 0xa4, 0x0c);
2015 reg_w(sd, 0x23, 0x1b);
2016 break;
Jean-Francois Moine53e74512008-11-08 06:10:19 -03002017 case 15:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002018 reg_w(sd, 0xa4, 0x04);
2019 reg_w(sd, 0x23, 0xff);
2020 sd->clockdiv = 1;
2021 break;
2022 case 10:
2023 reg_w(sd, 0xa4, 0x04);
2024 reg_w(sd, 0x23, 0x1f);
2025 sd->clockdiv = 1;
2026 break;
2027 case 5:
2028 reg_w(sd, 0xa4, 0x04);
2029 reg_w(sd, 0x23, 0x1b);
2030 sd->clockdiv = 1;
2031 break;
2032 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002033 break;
2034 case SEN_OV8610:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002035 switch (sd->frame_rate) {
2036 default: /* 15 fps */
2037/* case 15: */
2038 reg_w(sd, 0xa4, 0x06);
2039 reg_w(sd, 0x23, 0xff);
2040 break;
2041 case 10:
2042 reg_w(sd, 0xa4, 0x06);
2043 reg_w(sd, 0x23, 0x1f);
2044 break;
2045 case 5:
2046 reg_w(sd, 0xa4, 0x06);
2047 reg_w(sd, 0x23, 0x1b);
2048 break;
2049 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002050 break;
2051 case SEN_OV7670: /* guesses, based on 7640 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002052 PDEBUG(D_STREAM, "Setting framerate to %d fps",
2053 (sd->frame_rate == 0) ? 15 : sd->frame_rate);
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002054 reg_w(sd, 0xa4, 0x10);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002055 switch (sd->frame_rate) {
2056 case 30:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002057 reg_w(sd, 0x23, 0xff);
2058 break;
2059 case 20:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002060 reg_w(sd, 0x23, 0x1b);
2061 break;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002062 default:
2063/* case 15: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002064 reg_w(sd, 0x23, 0xff);
2065 sd->clockdiv = 1;
2066 break;
2067 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002068 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002069 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002070 return 0;
2071}
2072
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002073static int mode_init_ov_sensor_regs(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002074{
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002075 struct gspca_dev *gspca_dev;
2076 int qvga;
2077
2078 gspca_dev = &sd->gspca_dev;
Hans de Goede124cc9c2009-06-14 05:48:00 -03002079 qvga = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002080
2081 /******** Mode (VGA/QVGA) and sensor specific regs ********/
2082 switch (sd->sensor) {
2083 case SEN_OV8610:
2084 /* For OV8610 qvga means qsvga */
2085 i2c_w_mask(sd, OV7610_REG_COM_C, qvga ? (1 << 5) : 0, 1 << 5);
2086 break;
2087 case SEN_OV7610:
2088 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
2089 break;
2090 case SEN_OV7620:
2091/* i2c_w(sd, 0x2b, 0x00); */
2092 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
2093 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
2094 i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
2095 i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
2096 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
2097 i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
2098 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
2099 break;
2100 case SEN_OV76BE:
2101/* i2c_w(sd, 0x2b, 0x00); */
2102 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
2103 break;
2104 case SEN_OV7640:
2105/* i2c_w(sd, 0x2b, 0x00); */
2106 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
2107 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
2108/* i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a); */
2109/* i2c_w(sd, 0x25, qvga ? 0x30 : 0x60); */
2110/* i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40); */
2111/* i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0); */
2112/* i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20); */
2113 break;
2114 case SEN_OV7670:
2115 /* set COM7_FMT_VGA or COM7_FMT_QVGA
2116 * do we need to set anything else?
2117 * HSTART etc are set in set_ov_sensor_window itself */
2118 i2c_w_mask(sd, OV7670_REG_COM7,
2119 qvga ? OV7670_COM7_FMT_QVGA : OV7670_COM7_FMT_VGA,
2120 OV7670_COM7_FMT_MASK);
2121 break;
2122 case SEN_OV6620:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002123 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03002124 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002125 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
2126 break;
2127 default:
2128 return -EINVAL;
2129 }
2130
2131 /******** Palette-specific regs ********/
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002132 if (sd->sensor == SEN_OV7610 || sd->sensor == SEN_OV76BE) {
2133 /* not valid on the OV6620/OV7620/6630? */
2134 i2c_w_mask(sd, 0x0e, 0x00, 0x40);
2135 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002136
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002137 /* The OV518 needs special treatment. Although both the OV518
2138 * and the OV6630 support a 16-bit video bus, only the 8 bit Y
2139 * bus is actually used. The UV bus is tied to ground.
2140 * Therefore, the OV6630 needs to be in 8-bit multiplexed
2141 * output mode */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002142
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002143 /* OV7640 is 8-bit only */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002144
Hans de Goede7d971372009-06-14 05:28:17 -03002145 if (sd->sensor != SEN_OV6630 && sd->sensor != SEN_OV66308AF &&
2146 sd->sensor != SEN_OV7640)
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002147 i2c_w_mask(sd, 0x13, 0x00, 0x20);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002148
2149 /******** Clock programming ********/
2150 /* The OV6620 needs special handling. This prevents the
2151 * severe banding that normally occurs */
2152 if (sd->sensor == SEN_OV6620) {
2153
2154 /* Clock down */
2155 i2c_w(sd, 0x2a, 0x04);
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002156 i2c_w(sd, 0x11, sd->clockdiv);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002157 i2c_w(sd, 0x2a, 0x84);
2158 /* This next setting is critical. It seems to improve
2159 * the gain or the contrast. The "reserved" bits seem
2160 * to have some effect in this case. */
2161 i2c_w(sd, 0x2d, 0x85);
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002162 } else {
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002163 i2c_w(sd, 0x11, sd->clockdiv);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002164 }
2165
2166 /******** Special Features ********/
2167/* no evidence this is possible with OV7670, either */
2168 /* Test Pattern */
2169 if (sd->sensor != SEN_OV7640 && sd->sensor != SEN_OV7670)
2170 i2c_w_mask(sd, 0x12, 0x00, 0x02);
2171
2172 /* Enable auto white balance */
2173 if (sd->sensor == SEN_OV7670)
2174 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_AWB,
2175 OV7670_COM8_AWB);
2176 else
2177 i2c_w_mask(sd, 0x12, 0x04, 0x04);
2178
2179 /* This will go away as soon as ov51x_mode_init_sensor_regs() */
2180 /* is fully tested. */
2181 /* 7620/6620/6630? don't have register 0x35, so play it safe */
2182 if (sd->sensor == SEN_OV7610 || sd->sensor == SEN_OV76BE) {
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002183 if (!qvga)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002184 i2c_w(sd, 0x35, 0x9e);
2185 else
2186 i2c_w(sd, 0x35, 0x1e);
2187 }
2188 return 0;
2189}
2190
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002191static void sethvflip(struct sd *sd)
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03002192{
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002193 if (sd->sensor != SEN_OV7670)
2194 return;
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03002195 if (sd->gspca_dev.streaming)
2196 ov51x_stop(sd);
2197 i2c_w_mask(sd, OV7670_REG_MVFP,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002198 OV7670_MVFP_MIRROR * sd->hflip
2199 | OV7670_MVFP_VFLIP * sd->vflip,
2200 OV7670_MVFP_MIRROR | OV7670_MVFP_VFLIP);
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03002201 if (sd->gspca_dev.streaming)
2202 ov51x_restart(sd);
2203}
2204
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002205static int set_ov_sensor_window(struct sd *sd)
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03002206{
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002207 struct gspca_dev *gspca_dev;
Hans de Goede124cc9c2009-06-14 05:48:00 -03002208 int qvga, crop;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002209 int hwsbase, hwebase, vwsbase, vwebase, hwscale, vwscale;
2210 int ret, hstart, hstop, vstop, vstart;
2211 __u8 v;
2212
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002213 gspca_dev = &sd->gspca_dev;
Hans de Goede124cc9c2009-06-14 05:48:00 -03002214 qvga = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 1;
2215 crop = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 2;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002216
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002217 /* The different sensor ICs handle setting up of window differently.
2218 * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!! */
2219 switch (sd->sensor) {
2220 case SEN_OV8610:
2221 hwsbase = 0x1e;
2222 hwebase = 0x1e;
2223 vwsbase = 0x02;
2224 vwebase = 0x02;
2225 break;
2226 case SEN_OV7610:
2227 case SEN_OV76BE:
2228 hwsbase = 0x38;
2229 hwebase = 0x3a;
2230 vwsbase = vwebase = 0x05;
2231 break;
2232 case SEN_OV6620:
2233 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03002234 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002235 hwsbase = 0x38;
2236 hwebase = 0x3a;
2237 vwsbase = 0x05;
2238 vwebase = 0x06;
Hans de Goede7d971372009-06-14 05:28:17 -03002239 if (sd->sensor == SEN_OV66308AF && qvga)
Hans de Goede49809d62009-06-07 12:10:39 -03002240 /* HDG: this fixes U and V getting swapped */
Hans de Goede7d971372009-06-14 05:28:17 -03002241 hwsbase++;
Hans de Goede124cc9c2009-06-14 05:48:00 -03002242 if (crop) {
2243 hwsbase += 8;
2244 hwebase += 8;
2245 vwsbase += 11;
2246 vwebase += 11;
2247 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002248 break;
2249 case SEN_OV7620:
2250 hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */
2251 hwebase = 0x2f;
2252 vwsbase = vwebase = 0x05;
2253 break;
2254 case SEN_OV7640:
2255 hwsbase = 0x1a;
2256 hwebase = 0x1a;
2257 vwsbase = vwebase = 0x03;
2258 break;
2259 case SEN_OV7670:
2260 /*handling of OV7670 hardware sensor start and stop values
2261 * is very odd, compared to the other OV sensors */
2262 vwsbase = vwebase = hwebase = hwsbase = 0x00;
2263 break;
2264 default:
2265 return -EINVAL;
2266 }
2267
2268 switch (sd->sensor) {
2269 case SEN_OV6620:
2270 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03002271 case SEN_OV66308AF:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002272 if (qvga) { /* QCIF */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002273 hwscale = 0;
2274 vwscale = 0;
2275 } else { /* CIF */
2276 hwscale = 1;
2277 vwscale = 1; /* The datasheet says 0;
2278 * it's wrong */
2279 }
2280 break;
2281 case SEN_OV8610:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002282 if (qvga) { /* QSVGA */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002283 hwscale = 1;
2284 vwscale = 1;
2285 } else { /* SVGA */
2286 hwscale = 2;
2287 vwscale = 2;
2288 }
2289 break;
2290 default: /* SEN_OV7xx0 */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002291 if (qvga) { /* QVGA */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002292 hwscale = 1;
2293 vwscale = 0;
2294 } else { /* VGA */
2295 hwscale = 2;
2296 vwscale = 1;
2297 }
2298 }
2299
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002300 ret = mode_init_ov_sensor_regs(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002301 if (ret < 0)
2302 return ret;
2303
2304 if (sd->sensor == SEN_OV8610) {
2305 i2c_w_mask(sd, 0x2d, 0x05, 0x40);
2306 /* old 0x95, new 0x05 from windrv 090403 */
2307 /* bits 5-7: reserved */
2308 i2c_w_mask(sd, 0x28, 0x20, 0x20);
2309 /* bit 5: progressive mode on */
2310 }
2311
2312 /* The below is wrong for OV7670s because their window registers
2313 * only store the high bits in 0x17 to 0x1a */
2314
2315 /* SRH Use sd->max values instead of requested win values */
2316 /* SCS Since we're sticking with only the max hardware widths
2317 * for a given mode */
2318 /* I can hard code this for OV7670s */
2319 /* Yes, these numbers do look odd, but they're tested and work! */
2320 if (sd->sensor == SEN_OV7670) {
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002321 if (qvga) { /* QVGA from ov7670.c by
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002322 * Jonathan Corbet */
2323 hstart = 164;
Hans de Goede80142ef2009-06-14 06:26:49 -03002324 hstop = 28;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002325 vstart = 14;
2326 vstop = 494;
2327 } else { /* VGA */
2328 hstart = 158;
2329 hstop = 14;
2330 vstart = 10;
2331 vstop = 490;
2332 }
2333 /* OV7670 hardware window registers are split across
2334 * multiple locations */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002335 i2c_w(sd, OV7670_REG_HSTART, hstart >> 3);
2336 i2c_w(sd, OV7670_REG_HSTOP, hstop >> 3);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002337 v = i2c_r(sd, OV7670_REG_HREF);
2338 v = (v & 0xc0) | ((hstop & 0x7) << 3) | (hstart & 0x07);
2339 msleep(10); /* need to sleep between read and write to
2340 * same reg! */
2341 i2c_w(sd, OV7670_REG_HREF, v);
2342
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002343 i2c_w(sd, OV7670_REG_VSTART, vstart >> 2);
2344 i2c_w(sd, OV7670_REG_VSTOP, vstop >> 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002345 v = i2c_r(sd, OV7670_REG_VREF);
2346 v = (v & 0xc0) | ((vstop & 0x3) << 2) | (vstart & 0x03);
2347 msleep(10); /* need to sleep between read and write to
2348 * same reg! */
2349 i2c_w(sd, OV7670_REG_VREF, v);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002350 } else {
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002351 i2c_w(sd, 0x17, hwsbase);
2352 i2c_w(sd, 0x18, hwebase + (sd->gspca_dev.width >> hwscale));
2353 i2c_w(sd, 0x19, vwsbase);
2354 i2c_w(sd, 0x1a, vwebase + (sd->gspca_dev.height >> vwscale));
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002355 }
2356 return 0;
2357}
2358
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002359/* -- start the camera -- */
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03002360static int sd_start(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002361{
2362 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede49809d62009-06-07 12:10:39 -03002363 int ret = 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002364
Hans de Goede49809d62009-06-07 12:10:39 -03002365 switch (sd->bridge) {
2366 case BRIDGE_OV518:
2367 case BRIDGE_OV518PLUS:
2368 ret = ov518_mode_init_regs(sd);
2369 break;
2370 case BRIDGE_OV519:
2371 ret = ov519_mode_init_regs(sd);
2372 break;
2373 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002374 if (ret < 0)
2375 goto out;
Hans de Goede49809d62009-06-07 12:10:39 -03002376
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002377 ret = set_ov_sensor_window(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002378 if (ret < 0)
2379 goto out;
2380
Hans de Goede49809d62009-06-07 12:10:39 -03002381 setcontrast(gspca_dev);
2382 setbrightness(gspca_dev);
2383 setcolors(gspca_dev);
Hans de Goede02ab18b2009-06-14 04:32:04 -03002384 sethvflip(sd);
2385 setautobrightness(sd);
2386 setfreq(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03002387
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002388 ret = ov51x_restart(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002389 if (ret < 0)
2390 goto out;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002391 ov51x_led_control(sd, 1);
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03002392 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002393out:
2394 PDEBUG(D_ERR, "camera start error:%d", ret);
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03002395 return ret;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002396}
2397
2398static void sd_stopN(struct gspca_dev *gspca_dev)
2399{
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002400 struct sd *sd = (struct sd *) gspca_dev;
2401
2402 ov51x_stop(sd);
2403 ov51x_led_control(sd, 0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002404}
2405
Hans de Goede49809d62009-06-07 12:10:39 -03002406static void ov518_pkt_scan(struct gspca_dev *gspca_dev,
2407 struct gspca_frame *frame, /* target */
2408 __u8 *data, /* isoc packet */
2409 int len) /* iso packet length */
2410{
Hans de Goede92918a52009-06-14 06:21:35 -03002411 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede49809d62009-06-07 12:10:39 -03002412
2413 /* A false positive here is likely, until OVT gives me
2414 * the definitive SOF/EOF format */
2415 if ((!(data[0] | data[1] | data[2] | data[3] | data[5])) && data[6]) {
2416 gspca_frame_add(gspca_dev, LAST_PACKET, frame, data, 0);
2417 gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, 0);
Hans de Goede92918a52009-06-14 06:21:35 -03002418 sd->packet_nr = 0;
2419 }
2420
2421 if (gspca_dev->last_packet_type == DISCARD_PACKET)
2422 return;
2423
2424 /* Does this device use packet numbers ? */
2425 if (len & 7) {
2426 len--;
2427 if (sd->packet_nr == data[len])
2428 sd->packet_nr++;
2429 /* The last few packets of the frame (which are all 0's
2430 except that they may contain part of the footer), are
2431 numbered 0 */
2432 else if (sd->packet_nr == 0 || data[len]) {
2433 PDEBUG(D_ERR, "Invalid packet nr: %d (expect: %d)",
2434 (int)data[len], (int)sd->packet_nr);
2435 gspca_dev->last_packet_type = DISCARD_PACKET;
2436 return;
2437 }
Hans de Goede49809d62009-06-07 12:10:39 -03002438 }
2439
2440 /* intermediate packet */
2441 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
2442}
2443
2444static void ov519_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002445 struct gspca_frame *frame, /* target */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002446 __u8 *data, /* isoc packet */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002447 int len) /* iso packet length */
2448{
2449 /* Header of ov519 is 16 bytes:
2450 * Byte Value Description
2451 * 0 0xff magic
2452 * 1 0xff magic
2453 * 2 0xff magic
2454 * 3 0xXX 0x50 = SOF, 0x51 = EOF
2455 * 9 0xXX 0x01 initial frame without data,
2456 * 0x00 standard frame with image
2457 * 14 Lo in EOF: length of image data / 8
2458 * 15 Hi
2459 */
2460
2461 if (data[0] == 0xff && data[1] == 0xff && data[2] == 0xff) {
2462 switch (data[3]) {
2463 case 0x50: /* start of frame */
2464#define HDRSZ 16
2465 data += HDRSZ;
2466 len -= HDRSZ;
2467#undef HDRSZ
2468 if (data[0] == 0xff || data[1] == 0xd8)
2469 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
2470 data, len);
2471 else
2472 gspca_dev->last_packet_type = DISCARD_PACKET;
2473 return;
2474 case 0x51: /* end of frame */
2475 if (data[9] != 0)
2476 gspca_dev->last_packet_type = DISCARD_PACKET;
2477 gspca_frame_add(gspca_dev, LAST_PACKET, frame,
2478 data, 0);
2479 return;
2480 }
2481 }
2482
2483 /* intermediate packet */
2484 gspca_frame_add(gspca_dev, INTER_PACKET, frame,
2485 data, len);
2486}
2487
Hans de Goede49809d62009-06-07 12:10:39 -03002488static void sd_pkt_scan(struct gspca_dev *gspca_dev,
2489 struct gspca_frame *frame, /* target */
2490 __u8 *data, /* isoc packet */
2491 int len) /* iso packet length */
2492{
2493 struct sd *sd = (struct sd *) gspca_dev;
2494
2495 switch (sd->bridge) {
2496 case BRIDGE_OV511:
2497 case BRIDGE_OV511PLUS:
2498 break;
2499 case BRIDGE_OV518:
2500 case BRIDGE_OV518PLUS:
2501 ov518_pkt_scan(gspca_dev, frame, data, len);
2502 break;
2503 case BRIDGE_OV519:
2504 ov519_pkt_scan(gspca_dev, frame, data, len);
2505 break;
2506 }
2507}
2508
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002509/* -- management routines -- */
2510
2511static void setbrightness(struct gspca_dev *gspca_dev)
2512{
2513 struct sd *sd = (struct sd *) gspca_dev;
2514 int val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002515
2516 val = sd->brightness;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002517 switch (sd->sensor) {
2518 case SEN_OV8610:
2519 case SEN_OV7610:
2520 case SEN_OV76BE:
2521 case SEN_OV6620:
2522 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03002523 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002524 case SEN_OV7640:
2525 i2c_w(sd, OV7610_REG_BRT, val);
2526 break;
2527 case SEN_OV7620:
2528 /* 7620 doesn't like manual changes when in auto mode */
Hans de Goede02ab18b2009-06-14 04:32:04 -03002529 if (!sd->autobrightness)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002530 i2c_w(sd, OV7610_REG_BRT, val);
2531 break;
2532 case SEN_OV7670:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002533/*win trace
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002534 * i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_AEC); */
2535 i2c_w(sd, OV7670_REG_BRIGHT, ov7670_abs_to_sm(val));
2536 break;
2537 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002538}
2539
2540static void setcontrast(struct gspca_dev *gspca_dev)
2541{
2542 struct sd *sd = (struct sd *) gspca_dev;
2543 int val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002544
2545 val = sd->contrast;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002546 switch (sd->sensor) {
2547 case SEN_OV7610:
2548 case SEN_OV6620:
2549 i2c_w(sd, OV7610_REG_CNT, val);
2550 break;
2551 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03002552 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002553 i2c_w_mask(sd, OV7610_REG_CNT, val >> 4, 0x0f);
Hans de Goede49809d62009-06-07 12:10:39 -03002554 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002555 case SEN_OV8610: {
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002556 static const __u8 ctab[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002557 0x03, 0x09, 0x0b, 0x0f, 0x53, 0x6f, 0x35, 0x7f
2558 };
2559
2560 /* Use Y gamma control instead. Bit 0 enables it. */
2561 i2c_w(sd, 0x64, ctab[val >> 5]);
2562 break;
2563 }
2564 case SEN_OV7620: {
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002565 static const __u8 ctab[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002566 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
2567 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
2568 };
2569
2570 /* Use Y gamma control instead. Bit 0 enables it. */
2571 i2c_w(sd, 0x64, ctab[val >> 4]);
2572 break;
2573 }
2574 case SEN_OV7640:
2575 /* Use gain control instead. */
2576 i2c_w(sd, OV7610_REG_GAIN, val >> 2);
2577 break;
2578 case SEN_OV7670:
2579 /* check that this isn't just the same as ov7610 */
2580 i2c_w(sd, OV7670_REG_CONTRAS, val >> 1);
2581 break;
2582 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002583}
2584
2585static void setcolors(struct gspca_dev *gspca_dev)
2586{
2587 struct sd *sd = (struct sd *) gspca_dev;
2588 int val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002589
2590 val = sd->colors;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002591 switch (sd->sensor) {
2592 case SEN_OV8610:
2593 case SEN_OV7610:
2594 case SEN_OV76BE:
2595 case SEN_OV6620:
2596 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03002597 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002598 i2c_w(sd, OV7610_REG_SAT, val);
2599 break;
2600 case SEN_OV7620:
2601 /* Use UV gamma control instead. Bits 0 & 7 are reserved. */
2602/* rc = ov_i2c_write(sd->dev, 0x62, (val >> 9) & 0x7e);
2603 if (rc < 0)
2604 goto out; */
2605 i2c_w(sd, OV7610_REG_SAT, val);
2606 break;
2607 case SEN_OV7640:
2608 i2c_w(sd, OV7610_REG_SAT, val & 0xf0);
2609 break;
2610 case SEN_OV7670:
2611 /* supported later once I work out how to do it
2612 * transparently fail now! */
2613 /* set REG_COM13 values for UV sat auto mode */
2614 break;
2615 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002616}
2617
Hans de Goede02ab18b2009-06-14 04:32:04 -03002618static void setautobrightness(struct sd *sd)
2619{
2620 if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7670)
2621 return;
2622
2623 i2c_w_mask(sd, 0x2d, sd->autobrightness ? 0x10 : 0x00, 0x10);
2624}
2625
2626static void setfreq(struct sd *sd)
2627{
2628 if (sd->sensor == SEN_OV7670) {
2629 switch (sd->freq) {
2630 case 0: /* Banding filter disabled */
2631 i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_BFILT);
2632 break;
2633 case 1: /* 50 hz */
2634 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT,
2635 OV7670_COM8_BFILT);
2636 i2c_w_mask(sd, OV7670_REG_COM11, 0x08, 0x18);
2637 break;
2638 case 2: /* 60 hz */
2639 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT,
2640 OV7670_COM8_BFILT);
2641 i2c_w_mask(sd, OV7670_REG_COM11, 0x00, 0x18);
2642 break;
2643 case 3: /* Auto hz */
2644 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT,
2645 OV7670_COM8_BFILT);
2646 i2c_w_mask(sd, OV7670_REG_COM11, OV7670_COM11_HZAUTO,
2647 0x18);
2648 break;
2649 }
2650 } else {
2651 switch (sd->freq) {
2652 case 0: /* Banding filter disabled */
2653 i2c_w_mask(sd, 0x2d, 0x00, 0x04);
2654 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
2655 break;
2656 case 1: /* 50 hz (filter on and framerate adj) */
2657 i2c_w_mask(sd, 0x2d, 0x04, 0x04);
2658 i2c_w_mask(sd, 0x2a, 0x80, 0x80);
2659 /* 20 fps -> 16.667 fps */
2660 if (sd->sensor == SEN_OV6620 ||
Hans de Goede7d971372009-06-14 05:28:17 -03002661 sd->sensor == SEN_OV6630 ||
2662 sd->sensor == SEN_OV66308AF)
Hans de Goede02ab18b2009-06-14 04:32:04 -03002663 i2c_w(sd, 0x2b, 0x5e);
2664 else
2665 i2c_w(sd, 0x2b, 0xac);
2666 break;
2667 case 2: /* 60 hz (filter on, ...) */
2668 i2c_w_mask(sd, 0x2d, 0x04, 0x04);
2669 if (sd->sensor == SEN_OV6620 ||
Hans de Goede7d971372009-06-14 05:28:17 -03002670 sd->sensor == SEN_OV6630 ||
2671 sd->sensor == SEN_OV66308AF) {
Hans de Goede02ab18b2009-06-14 04:32:04 -03002672 /* 20 fps -> 15 fps */
2673 i2c_w_mask(sd, 0x2a, 0x80, 0x80);
2674 i2c_w(sd, 0x2b, 0xa8);
2675 } else {
2676 /* no framerate adj. */
2677 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
2678 }
2679 break;
2680 }
2681 }
2682}
2683
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002684static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
2685{
2686 struct sd *sd = (struct sd *) gspca_dev;
2687
2688 sd->brightness = val;
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002689 if (gspca_dev->streaming)
2690 setbrightness(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002691 return 0;
2692}
2693
2694static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
2695{
2696 struct sd *sd = (struct sd *) gspca_dev;
2697
2698 *val = sd->brightness;
2699 return 0;
2700}
2701
2702static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
2703{
2704 struct sd *sd = (struct sd *) gspca_dev;
2705
2706 sd->contrast = val;
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002707 if (gspca_dev->streaming)
2708 setcontrast(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002709 return 0;
2710}
2711
2712static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
2713{
2714 struct sd *sd = (struct sd *) gspca_dev;
2715
2716 *val = sd->contrast;
2717 return 0;
2718}
2719
2720static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
2721{
2722 struct sd *sd = (struct sd *) gspca_dev;
2723
2724 sd->colors = val;
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002725 if (gspca_dev->streaming)
2726 setcolors(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002727 return 0;
2728}
2729
2730static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
2731{
2732 struct sd *sd = (struct sd *) gspca_dev;
2733
2734 *val = sd->colors;
2735 return 0;
2736}
2737
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03002738static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
2739{
2740 struct sd *sd = (struct sd *) gspca_dev;
2741
2742 sd->hflip = val;
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002743 if (gspca_dev->streaming)
2744 sethvflip(sd);
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03002745 return 0;
2746}
2747
2748static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
2749{
2750 struct sd *sd = (struct sd *) gspca_dev;
2751
2752 *val = sd->hflip;
2753 return 0;
2754}
2755
2756static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
2757{
2758 struct sd *sd = (struct sd *) gspca_dev;
2759
2760 sd->vflip = val;
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002761 if (gspca_dev->streaming)
2762 sethvflip(sd);
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03002763 return 0;
2764}
2765
2766static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
2767{
2768 struct sd *sd = (struct sd *) gspca_dev;
2769
2770 *val = sd->vflip;
2771 return 0;
2772}
2773
Hans de Goede02ab18b2009-06-14 04:32:04 -03002774static int sd_setautobrightness(struct gspca_dev *gspca_dev, __s32 val)
2775{
2776 struct sd *sd = (struct sd *) gspca_dev;
2777
2778 sd->autobrightness = val;
2779 if (gspca_dev->streaming)
2780 setautobrightness(sd);
2781 return 0;
2782}
2783
2784static int sd_getautobrightness(struct gspca_dev *gspca_dev, __s32 *val)
2785{
2786 struct sd *sd = (struct sd *) gspca_dev;
2787
2788 *val = sd->autobrightness;
2789 return 0;
2790}
2791
2792static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
2793{
2794 struct sd *sd = (struct sd *) gspca_dev;
2795
2796 sd->freq = val;
2797 if (gspca_dev->streaming)
2798 setfreq(sd);
2799 return 0;
2800}
2801
2802static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
2803{
2804 struct sd *sd = (struct sd *) gspca_dev;
2805
2806 *val = sd->freq;
2807 return 0;
2808}
2809
2810static int sd_querymenu(struct gspca_dev *gspca_dev,
2811 struct v4l2_querymenu *menu)
2812{
2813 struct sd *sd = (struct sd *) gspca_dev;
2814
2815 switch (menu->id) {
2816 case V4L2_CID_POWER_LINE_FREQUENCY:
2817 switch (menu->index) {
2818 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
2819 strcpy((char *) menu->name, "NoFliker");
2820 return 0;
2821 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
2822 strcpy((char *) menu->name, "50 Hz");
2823 return 0;
2824 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
2825 strcpy((char *) menu->name, "60 Hz");
2826 return 0;
2827 case 3:
2828 if (sd->sensor != SEN_OV7670)
2829 return -EINVAL;
2830
2831 strcpy((char *) menu->name, "Automatic");
2832 return 0;
2833 }
2834 break;
2835 }
2836 return -EINVAL;
2837}
2838
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002839/* sub-driver description */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002840static const struct sd_desc sd_desc = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002841 .name = MODULE_NAME,
2842 .ctrls = sd_ctrls,
2843 .nctrls = ARRAY_SIZE(sd_ctrls),
2844 .config = sd_config,
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03002845 .init = sd_init,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002846 .start = sd_start,
2847 .stopN = sd_stopN,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002848 .pkt_scan = sd_pkt_scan,
Hans de Goede02ab18b2009-06-14 04:32:04 -03002849 .querymenu = sd_querymenu,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002850};
2851
2852/* -- module initialisation -- */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002853static const __devinitdata struct usb_device_id device_table[] = {
Hans de Goede49809d62009-06-07 12:10:39 -03002854 {USB_DEVICE(0x041e, 0x4052), .driver_info = BRIDGE_OV519 },
2855 {USB_DEVICE(0x041e, 0x405f), .driver_info = BRIDGE_OV519 },
2856 {USB_DEVICE(0x041e, 0x4060), .driver_info = BRIDGE_OV519 },
2857 {USB_DEVICE(0x041e, 0x4061), .driver_info = BRIDGE_OV519 },
Hans de Goede9e4d8252009-06-14 06:25:06 -03002858 {USB_DEVICE(0x041e, 0x4064),
2859 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
2860 {USB_DEVICE(0x041e, 0x4068),
2861 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
Hans de Goede49809d62009-06-07 12:10:39 -03002862 {USB_DEVICE(0x045e, 0x028c), .driver_info = BRIDGE_OV519 },
2863 {USB_DEVICE(0x054c, 0x0154), .driver_info = BRIDGE_OV519 },
2864 {USB_DEVICE(0x054c, 0x0155), .driver_info = BRIDGE_OV519 },
2865 {USB_DEVICE(0x05a9, 0x0518), .driver_info = BRIDGE_OV518 },
2866 {USB_DEVICE(0x05a9, 0x0519), .driver_info = BRIDGE_OV519 },
2867 {USB_DEVICE(0x05a9, 0x0530), .driver_info = BRIDGE_OV519 },
2868 {USB_DEVICE(0x05a9, 0x4519), .driver_info = BRIDGE_OV519 },
2869 {USB_DEVICE(0x05a9, 0x8519), .driver_info = BRIDGE_OV519 },
2870 {USB_DEVICE(0x05a9, 0xa518), .driver_info = BRIDGE_OV518PLUS },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002871 {}
2872};
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002873
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002874MODULE_DEVICE_TABLE(usb, device_table);
2875
2876/* -- device connect -- */
2877static int sd_probe(struct usb_interface *intf,
2878 const struct usb_device_id *id)
2879{
2880 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
2881 THIS_MODULE);
2882}
2883
2884static struct usb_driver sd_driver = {
2885 .name = MODULE_NAME,
2886 .id_table = device_table,
2887 .probe = sd_probe,
2888 .disconnect = gspca_disconnect,
Jean-Francois Moine6a709742008-09-03 16:48:10 -03002889#ifdef CONFIG_PM
2890 .suspend = gspca_suspend,
2891 .resume = gspca_resume,
2892#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002893};
2894
2895/* -- module insert / remove -- */
2896static int __init sd_mod_init(void)
2897{
Alexey Klimovf69e9522009-01-01 13:02:07 -03002898 int ret;
2899 ret = usb_register(&sd_driver);
2900 if (ret < 0)
Alexey Klimove6b14842009-01-01 13:04:58 -03002901 return ret;
Jean-Francois Moine10b0e962008-07-22 05:35:10 -03002902 PDEBUG(D_PROBE, "registered");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002903 return 0;
2904}
2905static void __exit sd_mod_exit(void)
2906{
2907 usb_deregister(&sd_driver);
2908 PDEBUG(D_PROBE, "deregistered");
2909}
2910
2911module_init(sd_mod_init);
2912module_exit(sd_mod_exit);
2913
2914module_param(frame_rate, int, 0644);
2915MODULE_PARM_DESC(frame_rate, "Frame rate (5, 10, 15, 20 or 30 fps)");