blob: 3aebc744368db37194ee61927f6a4eb9b4d903fd [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 Beauxis2961e872008-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
Hans de Goede1876bb92009-06-14 06:45:50 -030079 __u8 frame_rate; /* current Framerate */
80 __u8 clockdiv; /* clockdiv override */
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 Goedeb282d872009-06-14 19:10:40 -0300272/* Note some of the sizeimage values for the ov511 / ov518 may seem
273 larger then necessary, however they need to be this big as the ov511 /
274 ov518 always fills the entire isoc frame, using 0 padding bytes when
275 it doesn't have any data. So with low framerates the amount of data
276 transfered can become quite large (libv4l will remove all the 0 padding
277 in userspace). */
Hans de Goede49809d62009-06-07 12:10:39 -0300278static const struct v4l2_pix_format ov518_vga_mode[] = {
279 {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
280 .bytesperline = 320,
Hans de Goedeb282d872009-06-14 19:10:40 -0300281 .sizeimage = 320 * 240 * 3,
Hans de Goede49809d62009-06-07 12:10:39 -0300282 .colorspace = V4L2_COLORSPACE_JPEG,
283 .priv = 1},
284 {640, 480, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
285 .bytesperline = 640,
Hans de Goedeb282d872009-06-14 19:10:40 -0300286 .sizeimage = 640 * 480 * 2,
Hans de Goede49809d62009-06-07 12:10:39 -0300287 .colorspace = V4L2_COLORSPACE_JPEG,
288 .priv = 0},
289};
290static const struct v4l2_pix_format ov518_sif_mode[] = {
Hans de Goede124cc9c2009-06-14 05:48:00 -0300291 {160, 120, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
292 .bytesperline = 160,
Hans de Goedeb282d872009-06-14 19:10:40 -0300293 .sizeimage = 70000,
Hans de Goede124cc9c2009-06-14 05:48:00 -0300294 .colorspace = V4L2_COLORSPACE_JPEG,
295 .priv = 3},
Hans de Goede49809d62009-06-07 12:10:39 -0300296 {176, 144, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
297 .bytesperline = 176,
Hans de Goedeb282d872009-06-14 19:10:40 -0300298 .sizeimage = 70000,
Hans de Goede49809d62009-06-07 12:10:39 -0300299 .colorspace = V4L2_COLORSPACE_JPEG,
300 .priv = 1},
Hans de Goede124cc9c2009-06-14 05:48:00 -0300301 {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
302 .bytesperline = 320,
Hans de Goedeb282d872009-06-14 19:10:40 -0300303 .sizeimage = 320 * 240 * 3,
Hans de Goede124cc9c2009-06-14 05:48:00 -0300304 .colorspace = V4L2_COLORSPACE_JPEG,
305 .priv = 2},
Hans de Goede49809d62009-06-07 12:10:39 -0300306 {352, 288, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
307 .bytesperline = 352,
Hans de Goedeb282d872009-06-14 19:10:40 -0300308 .sizeimage = 352 * 288 * 3,
Hans de Goede49809d62009-06-07 12:10:39 -0300309 .colorspace = V4L2_COLORSPACE_JPEG,
310 .priv = 0},
311};
312
Hans de Goede1876bb92009-06-14 06:45:50 -0300313static const struct v4l2_pix_format ov511_vga_mode[] = {
314 {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
315 .bytesperline = 320,
316 .sizeimage = 320 * 240 * 3,
317 .colorspace = V4L2_COLORSPACE_JPEG,
318 .priv = 1},
319 {640, 480, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
320 .bytesperline = 640,
321 .sizeimage = 640 * 480 * 2,
322 .colorspace = V4L2_COLORSPACE_JPEG,
323 .priv = 0},
324};
325static const struct v4l2_pix_format ov511_sif_mode[] = {
326 {160, 120, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
327 .bytesperline = 160,
Hans de Goedeb282d872009-06-14 19:10:40 -0300328 .sizeimage = 70000,
Hans de Goede1876bb92009-06-14 06:45:50 -0300329 .colorspace = V4L2_COLORSPACE_JPEG,
330 .priv = 3},
331 {176, 144, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
332 .bytesperline = 176,
Hans de Goedeb282d872009-06-14 19:10:40 -0300333 .sizeimage = 70000,
Hans de Goede1876bb92009-06-14 06:45:50 -0300334 .colorspace = V4L2_COLORSPACE_JPEG,
335 .priv = 1},
336 {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
337 .bytesperline = 320,
338 .sizeimage = 320 * 240 * 3,
339 .colorspace = V4L2_COLORSPACE_JPEG,
340 .priv = 2},
341 {352, 288, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
342 .bytesperline = 352,
343 .sizeimage = 352 * 288 * 3,
344 .colorspace = V4L2_COLORSPACE_JPEG,
345 .priv = 0},
346};
Hans de Goede49809d62009-06-07 12:10:39 -0300347
348/* Registers common to OV511 / OV518 */
Hans de Goede1876bb92009-06-14 06:45:50 -0300349#define R51x_FIFO_PSIZE 0x30 /* 2 bytes wide w/ OV518(+) */
Hans de Goede49809d62009-06-07 12:10:39 -0300350#define R51x_SYS_RESET 0x50
Hans de Goede1876bb92009-06-14 06:45:50 -0300351 /* Reset type flags */
352 #define OV511_RESET_OMNICE 0x08
Hans de Goede49809d62009-06-07 12:10:39 -0300353#define R51x_SYS_INIT 0x53
354#define R51x_SYS_SNAP 0x52
355#define R51x_SYS_CUST_ID 0x5F
356#define R51x_COMP_LUT_BEGIN 0x80
357
358/* OV511 Camera interface register numbers */
Hans de Goede1876bb92009-06-14 06:45:50 -0300359#define R511_CAM_DELAY 0x10
360#define R511_CAM_EDGE 0x11
361#define R511_CAM_PXCNT 0x12
362#define R511_CAM_LNCNT 0x13
363#define R511_CAM_PXDIV 0x14
364#define R511_CAM_LNDIV 0x15
365#define R511_CAM_UV_EN 0x16
366#define R511_CAM_LINE_MODE 0x17
367#define R511_CAM_OPTS 0x18
368
369#define R511_SNAP_FRAME 0x19
370#define R511_SNAP_PXCNT 0x1A
371#define R511_SNAP_LNCNT 0x1B
372#define R511_SNAP_PXDIV 0x1C
373#define R511_SNAP_LNDIV 0x1D
374#define R511_SNAP_UV_EN 0x1E
375#define R511_SNAP_UV_EN 0x1E
376#define R511_SNAP_OPTS 0x1F
377
378#define R511_DRAM_FLOW_CTL 0x20
379#define R511_FIFO_OPTS 0x31
380#define R511_I2C_CTL 0x40
Hans de Goede49809d62009-06-07 12:10:39 -0300381#define R511_SYS_LED_CTL 0x55 /* OV511+ only */
Hans de Goede1876bb92009-06-14 06:45:50 -0300382#define R511_COMP_EN 0x78
383#define R511_COMP_LUT_EN 0x79
Hans de Goede49809d62009-06-07 12:10:39 -0300384
385/* OV518 Camera interface register numbers */
386#define R518_GPIO_OUT 0x56 /* OV518(+) only */
387#define R518_GPIO_CTL 0x57 /* OV518(+) only */
388
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300389/* OV519 Camera interface register numbers */
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300390#define OV519_R10_H_SIZE 0x10
391#define OV519_R11_V_SIZE 0x11
392#define OV519_R12_X_OFFSETL 0x12
393#define OV519_R13_X_OFFSETH 0x13
394#define OV519_R14_Y_OFFSETL 0x14
395#define OV519_R15_Y_OFFSETH 0x15
396#define OV519_R16_DIVIDER 0x16
397#define OV519_R20_DFR 0x20
398#define OV519_R25_FORMAT 0x25
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300399
400/* OV519 System Controller register numbers */
401#define OV519_SYS_RESET1 0x51
402#define OV519_SYS_EN_CLK1 0x54
403
404#define OV519_GPIO_DATA_OUT0 0x71
405#define OV519_GPIO_IO_CTRL0 0x72
406
407#define OV511_ENDPOINT_ADDRESS 1 /* Isoc endpoint number */
408
409/* I2C registers */
410#define R51x_I2C_W_SID 0x41
411#define R51x_I2C_SADDR_3 0x42
412#define R51x_I2C_SADDR_2 0x43
413#define R51x_I2C_R_SID 0x44
414#define R51x_I2C_DATA 0x45
415#define R518_I2C_CTL 0x47 /* OV518(+) only */
416
417/* I2C ADDRESSES */
418#define OV7xx0_SID 0x42
419#define OV8xx0_SID 0xa0
420#define OV6xx0_SID 0xc0
421
422/* OV7610 registers */
423#define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */
Hans de Goede49809d62009-06-07 12:10:39 -0300424#define OV7610_REG_BLUE 0x01 /* blue channel balance */
425#define OV7610_REG_RED 0x02 /* red channel balance */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300426#define OV7610_REG_SAT 0x03 /* saturation */
427#define OV8610_REG_HUE 0x04 /* 04 reserved */
428#define OV7610_REG_CNT 0x05 /* Y contrast */
429#define OV7610_REG_BRT 0x06 /* Y brightness */
430#define OV7610_REG_COM_C 0x14 /* misc common regs */
431#define OV7610_REG_ID_HIGH 0x1c /* manufacturer ID MSB */
432#define OV7610_REG_ID_LOW 0x1d /* manufacturer ID LSB */
433#define OV7610_REG_COM_I 0x29 /* misc settings */
434
435/* OV7670 registers */
436#define OV7670_REG_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
437#define OV7670_REG_BLUE 0x01 /* blue gain */
438#define OV7670_REG_RED 0x02 /* red gain */
439#define OV7670_REG_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */
440#define OV7670_REG_COM1 0x04 /* Control 1 */
441#define OV7670_REG_AECHH 0x07 /* AEC MS 5 bits */
442#define OV7670_REG_COM3 0x0c /* Control 3 */
443#define OV7670_REG_COM4 0x0d /* Control 4 */
444#define OV7670_REG_COM5 0x0e /* All "reserved" */
445#define OV7670_REG_COM6 0x0f /* Control 6 */
446#define OV7670_REG_AECH 0x10 /* More bits of AEC value */
447#define OV7670_REG_CLKRC 0x11 /* Clock control */
448#define OV7670_REG_COM7 0x12 /* Control 7 */
449#define OV7670_COM7_FMT_VGA 0x00
450#define OV7670_COM7_YUV 0x00 /* YUV */
451#define OV7670_COM7_FMT_QVGA 0x10 /* QVGA format */
452#define OV7670_COM7_FMT_MASK 0x38
453#define OV7670_COM7_RESET 0x80 /* Register reset */
454#define OV7670_REG_COM8 0x13 /* Control 8 */
455#define OV7670_COM8_AEC 0x01 /* Auto exposure enable */
456#define OV7670_COM8_AWB 0x02 /* White balance enable */
457#define OV7670_COM8_AGC 0x04 /* Auto gain enable */
458#define OV7670_COM8_BFILT 0x20 /* Band filter enable */
459#define OV7670_COM8_AECSTEP 0x40 /* Unlimited AEC step size */
460#define OV7670_COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
461#define OV7670_REG_COM9 0x14 /* Control 9 - gain ceiling */
462#define OV7670_REG_COM10 0x15 /* Control 10 */
463#define OV7670_REG_HSTART 0x17 /* Horiz start high bits */
464#define OV7670_REG_HSTOP 0x18 /* Horiz stop high bits */
465#define OV7670_REG_VSTART 0x19 /* Vert start high bits */
466#define OV7670_REG_VSTOP 0x1a /* Vert stop high bits */
467#define OV7670_REG_MVFP 0x1e /* Mirror / vflip */
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300468#define OV7670_MVFP_VFLIP 0x10 /* vertical flip */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300469#define OV7670_MVFP_MIRROR 0x20 /* Mirror image */
470#define OV7670_REG_AEW 0x24 /* AGC upper limit */
471#define OV7670_REG_AEB 0x25 /* AGC lower limit */
472#define OV7670_REG_VPT 0x26 /* AGC/AEC fast mode op region */
473#define OV7670_REG_HREF 0x32 /* HREF pieces */
474#define OV7670_REG_TSLB 0x3a /* lots of stuff */
475#define OV7670_REG_COM11 0x3b /* Control 11 */
476#define OV7670_COM11_EXP 0x02
477#define OV7670_COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */
478#define OV7670_REG_COM12 0x3c /* Control 12 */
479#define OV7670_REG_COM13 0x3d /* Control 13 */
480#define OV7670_COM13_GAMMA 0x80 /* Gamma enable */
481#define OV7670_COM13_UVSAT 0x40 /* UV saturation auto adjustment */
482#define OV7670_REG_COM14 0x3e /* Control 14 */
483#define OV7670_REG_EDGE 0x3f /* Edge enhancement factor */
484#define OV7670_REG_COM15 0x40 /* Control 15 */
485#define OV7670_COM15_R00FF 0xc0 /* 00 to FF */
486#define OV7670_REG_COM16 0x41 /* Control 16 */
487#define OV7670_COM16_AWBGAIN 0x08 /* AWB gain enable */
488#define OV7670_REG_BRIGHT 0x55 /* Brightness */
489#define OV7670_REG_CONTRAS 0x56 /* Contrast control */
490#define OV7670_REG_GFIX 0x69 /* Fix gain control */
491#define OV7670_REG_RGB444 0x8c /* RGB 444 control */
492#define OV7670_REG_HAECC1 0x9f /* Hist AEC/AGC control 1 */
493#define OV7670_REG_HAECC2 0xa0 /* Hist AEC/AGC control 2 */
494#define OV7670_REG_BD50MAX 0xa5 /* 50hz banding step limit */
495#define OV7670_REG_HAECC3 0xa6 /* Hist AEC/AGC control 3 */
496#define OV7670_REG_HAECC4 0xa7 /* Hist AEC/AGC control 4 */
497#define OV7670_REG_HAECC5 0xa8 /* Hist AEC/AGC control 5 */
498#define OV7670_REG_HAECC6 0xa9 /* Hist AEC/AGC control 6 */
499#define OV7670_REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */
500#define OV7670_REG_BD60MAX 0xab /* 60hz banding step limit */
501
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300502struct ov_regvals {
503 __u8 reg;
504 __u8 val;
505};
506struct ov_i2c_regvals {
507 __u8 reg;
508 __u8 val;
509};
510
511static const struct ov_i2c_regvals norm_6x20[] = {
512 { 0x12, 0x80 }, /* reset */
513 { 0x11, 0x01 },
514 { 0x03, 0x60 },
515 { 0x05, 0x7f }, /* For when autoadjust is off */
516 { 0x07, 0xa8 },
517 /* The ratio of 0x0c and 0x0d controls the white point */
518 { 0x0c, 0x24 },
519 { 0x0d, 0x24 },
520 { 0x0f, 0x15 }, /* COMS */
521 { 0x10, 0x75 }, /* AEC Exposure time */
522 { 0x12, 0x24 }, /* Enable AGC */
523 { 0x14, 0x04 },
524 /* 0x16: 0x06 helps frame stability with moving objects */
525 { 0x16, 0x06 },
526/* { 0x20, 0x30 }, * Aperture correction enable */
527 { 0x26, 0xb2 }, /* BLC enable */
528 /* 0x28: 0x05 Selects RGB format if RGB on */
529 { 0x28, 0x05 },
530 { 0x2a, 0x04 }, /* Disable framerate adjust */
531/* { 0x2b, 0xac }, * Framerate; Set 2a[7] first */
532 { 0x2d, 0x99 },
533 { 0x33, 0xa0 }, /* Color Processing Parameter */
534 { 0x34, 0xd2 }, /* Max A/D range */
535 { 0x38, 0x8b },
536 { 0x39, 0x40 },
537
538 { 0x3c, 0x39 }, /* Enable AEC mode changing */
539 { 0x3c, 0x3c }, /* Change AEC mode */
540 { 0x3c, 0x24 }, /* Disable AEC mode changing */
541
542 { 0x3d, 0x80 },
543 /* These next two registers (0x4a, 0x4b) are undocumented.
544 * They control the color balance */
545 { 0x4a, 0x80 },
546 { 0x4b, 0x80 },
547 { 0x4d, 0xd2 }, /* This reduces noise a bit */
548 { 0x4e, 0xc1 },
549 { 0x4f, 0x04 },
550/* Do 50-53 have any effect? */
551/* Toggle 0x12[2] off and on here? */
552};
553
554static const struct ov_i2c_regvals norm_6x30[] = {
555 { 0x12, 0x80 }, /* Reset */
556 { 0x00, 0x1f }, /* Gain */
557 { 0x01, 0x99 }, /* Blue gain */
558 { 0x02, 0x7c }, /* Red gain */
559 { 0x03, 0xc0 }, /* Saturation */
560 { 0x05, 0x0a }, /* Contrast */
561 { 0x06, 0x95 }, /* Brightness */
562 { 0x07, 0x2d }, /* Sharpness */
563 { 0x0c, 0x20 },
564 { 0x0d, 0x20 },
Hans de Goede02ab18b2009-06-14 04:32:04 -0300565 { 0x0e, 0xa0 }, /* Was 0x20, bit7 enables a 2x gain which we need */
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300566 { 0x0f, 0x05 },
567 { 0x10, 0x9a },
568 { 0x11, 0x00 }, /* Pixel clock = fastest */
569 { 0x12, 0x24 }, /* Enable AGC and AWB */
570 { 0x13, 0x21 },
571 { 0x14, 0x80 },
572 { 0x15, 0x01 },
573 { 0x16, 0x03 },
574 { 0x17, 0x38 },
575 { 0x18, 0xea },
576 { 0x19, 0x04 },
577 { 0x1a, 0x93 },
578 { 0x1b, 0x00 },
579 { 0x1e, 0xc4 },
580 { 0x1f, 0x04 },
581 { 0x20, 0x20 },
582 { 0x21, 0x10 },
583 { 0x22, 0x88 },
584 { 0x23, 0xc0 }, /* Crystal circuit power level */
585 { 0x25, 0x9a }, /* Increase AEC black ratio */
586 { 0x26, 0xb2 }, /* BLC enable */
587 { 0x27, 0xa2 },
588 { 0x28, 0x00 },
589 { 0x29, 0x00 },
590 { 0x2a, 0x84 }, /* 60 Hz power */
591 { 0x2b, 0xa8 }, /* 60 Hz power */
592 { 0x2c, 0xa0 },
593 { 0x2d, 0x95 }, /* Enable auto-brightness */
594 { 0x2e, 0x88 },
595 { 0x33, 0x26 },
596 { 0x34, 0x03 },
597 { 0x36, 0x8f },
598 { 0x37, 0x80 },
599 { 0x38, 0x83 },
600 { 0x39, 0x80 },
601 { 0x3a, 0x0f },
602 { 0x3b, 0x3c },
603 { 0x3c, 0x1a },
604 { 0x3d, 0x80 },
605 { 0x3e, 0x80 },
606 { 0x3f, 0x0e },
607 { 0x40, 0x00 }, /* White bal */
608 { 0x41, 0x00 }, /* White bal */
609 { 0x42, 0x80 },
610 { 0x43, 0x3f }, /* White bal */
611 { 0x44, 0x80 },
612 { 0x45, 0x20 },
613 { 0x46, 0x20 },
614 { 0x47, 0x80 },
615 { 0x48, 0x7f },
616 { 0x49, 0x00 },
617 { 0x4a, 0x00 },
618 { 0x4b, 0x80 },
619 { 0x4c, 0xd0 },
620 { 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
621 { 0x4e, 0x40 },
622 { 0x4f, 0x07 }, /* UV avg., col. killer: max */
623 { 0x50, 0xff },
624 { 0x54, 0x23 }, /* Max AGC gain: 18dB */
625 { 0x55, 0xff },
626 { 0x56, 0x12 },
627 { 0x57, 0x81 },
628 { 0x58, 0x75 },
629 { 0x59, 0x01 }, /* AGC dark current comp.: +1 */
630 { 0x5a, 0x2c },
631 { 0x5b, 0x0f }, /* AWB chrominance levels */
632 { 0x5c, 0x10 },
633 { 0x3d, 0x80 },
634 { 0x27, 0xa6 },
635 { 0x12, 0x20 }, /* Toggle AWB */
636 { 0x12, 0x24 },
637};
638
639/* Lawrence Glaister <lg@jfm.bc.ca> reports:
640 *
641 * Register 0x0f in the 7610 has the following effects:
642 *
643 * 0x85 (AEC method 1): Best overall, good contrast range
644 * 0x45 (AEC method 2): Very overexposed
645 * 0xa5 (spec sheet default): Ok, but the black level is
646 * shifted resulting in loss of contrast
647 * 0x05 (old driver setting): very overexposed, too much
648 * contrast
649 */
650static const struct ov_i2c_regvals norm_7610[] = {
651 { 0x10, 0xff },
652 { 0x16, 0x06 },
653 { 0x28, 0x24 },
654 { 0x2b, 0xac },
655 { 0x12, 0x00 },
656 { 0x38, 0x81 },
657 { 0x28, 0x24 }, /* 0c */
658 { 0x0f, 0x85 }, /* lg's setting */
659 { 0x15, 0x01 },
660 { 0x20, 0x1c },
661 { 0x23, 0x2a },
662 { 0x24, 0x10 },
663 { 0x25, 0x8a },
664 { 0x26, 0xa2 },
665 { 0x27, 0xc2 },
666 { 0x2a, 0x04 },
667 { 0x2c, 0xfe },
668 { 0x2d, 0x93 },
669 { 0x30, 0x71 },
670 { 0x31, 0x60 },
671 { 0x32, 0x26 },
672 { 0x33, 0x20 },
673 { 0x34, 0x48 },
674 { 0x12, 0x24 },
675 { 0x11, 0x01 },
676 { 0x0c, 0x24 },
677 { 0x0d, 0x24 },
678};
679
680static const struct ov_i2c_regvals norm_7620[] = {
681 { 0x00, 0x00 }, /* gain */
682 { 0x01, 0x80 }, /* blue gain */
683 { 0x02, 0x80 }, /* red gain */
684 { 0x03, 0xc0 }, /* OV7670_REG_VREF */
685 { 0x06, 0x60 },
686 { 0x07, 0x00 },
687 { 0x0c, 0x24 },
688 { 0x0c, 0x24 },
689 { 0x0d, 0x24 },
690 { 0x11, 0x01 },
691 { 0x12, 0x24 },
692 { 0x13, 0x01 },
693 { 0x14, 0x84 },
694 { 0x15, 0x01 },
695 { 0x16, 0x03 },
696 { 0x17, 0x2f },
697 { 0x18, 0xcf },
698 { 0x19, 0x06 },
699 { 0x1a, 0xf5 },
700 { 0x1b, 0x00 },
701 { 0x20, 0x18 },
702 { 0x21, 0x80 },
703 { 0x22, 0x80 },
704 { 0x23, 0x00 },
705 { 0x26, 0xa2 },
706 { 0x27, 0xea },
Hans de Goedeb282d872009-06-14 19:10:40 -0300707 { 0x28, 0x22 }, /* Was 0x20, bit1 enables a 2x gain which we need */
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300708 { 0x29, 0x00 },
709 { 0x2a, 0x10 },
710 { 0x2b, 0x00 },
711 { 0x2c, 0x88 },
712 { 0x2d, 0x91 },
713 { 0x2e, 0x80 },
714 { 0x2f, 0x44 },
715 { 0x60, 0x27 },
716 { 0x61, 0x02 },
717 { 0x62, 0x5f },
718 { 0x63, 0xd5 },
719 { 0x64, 0x57 },
720 { 0x65, 0x83 },
721 { 0x66, 0x55 },
722 { 0x67, 0x92 },
723 { 0x68, 0xcf },
724 { 0x69, 0x76 },
725 { 0x6a, 0x22 },
726 { 0x6b, 0x00 },
727 { 0x6c, 0x02 },
728 { 0x6d, 0x44 },
729 { 0x6e, 0x80 },
730 { 0x6f, 0x1d },
731 { 0x70, 0x8b },
732 { 0x71, 0x00 },
733 { 0x72, 0x14 },
734 { 0x73, 0x54 },
735 { 0x74, 0x00 },
736 { 0x75, 0x8e },
737 { 0x76, 0x00 },
738 { 0x77, 0xff },
739 { 0x78, 0x80 },
740 { 0x79, 0x80 },
741 { 0x7a, 0x80 },
742 { 0x7b, 0xe2 },
743 { 0x7c, 0x00 },
744};
745
746/* 7640 and 7648. The defaults should be OK for most registers. */
747static const struct ov_i2c_regvals norm_7640[] = {
748 { 0x12, 0x80 },
749 { 0x12, 0x14 },
750};
751
752/* 7670. Defaults taken from OmniVision provided data,
753* as provided by Jonathan Corbet of OLPC */
754static const struct ov_i2c_regvals norm_7670[] = {
755 { OV7670_REG_COM7, OV7670_COM7_RESET },
756 { OV7670_REG_TSLB, 0x04 }, /* OV */
757 { OV7670_REG_COM7, OV7670_COM7_FMT_VGA }, /* VGA */
758 { OV7670_REG_CLKRC, 0x01 },
759/*
760 * Set the hardware window. These values from OV don't entirely
761 * make sense - hstop is less than hstart. But they work...
762 */
763 { OV7670_REG_HSTART, 0x13 },
764 { OV7670_REG_HSTOP, 0x01 },
765 { OV7670_REG_HREF, 0xb6 },
766 { OV7670_REG_VSTART, 0x02 },
767 { OV7670_REG_VSTOP, 0x7a },
768 { OV7670_REG_VREF, 0x0a },
769
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300770 { OV7670_REG_COM3, 0x00 },
771 { OV7670_REG_COM14, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300772/* Mystery scaling numbers */
773 { 0x70, 0x3a },
774 { 0x71, 0x35 },
775 { 0x72, 0x11 },
776 { 0x73, 0xf0 },
777 { 0xa2, 0x02 },
778/* { OV7670_REG_COM10, 0x0 }, */
779
780/* Gamma curve values */
781 { 0x7a, 0x20 },
782 { 0x7b, 0x10 },
783 { 0x7c, 0x1e },
784 { 0x7d, 0x35 },
785 { 0x7e, 0x5a },
786 { 0x7f, 0x69 },
787 { 0x80, 0x76 },
788 { 0x81, 0x80 },
789 { 0x82, 0x88 },
790 { 0x83, 0x8f },
791 { 0x84, 0x96 },
792 { 0x85, 0xa3 },
793 { 0x86, 0xaf },
794 { 0x87, 0xc4 },
795 { 0x88, 0xd7 },
796 { 0x89, 0xe8 },
797
798/* AGC and AEC parameters. Note we start by disabling those features,
799 then turn them only after tweaking the values. */
800 { OV7670_REG_COM8, OV7670_COM8_FASTAEC
801 | OV7670_COM8_AECSTEP
802 | OV7670_COM8_BFILT },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300803 { OV7670_REG_GAIN, 0x00 },
804 { OV7670_REG_AECH, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300805 { OV7670_REG_COM4, 0x40 }, /* magic reserved bit */
806 { OV7670_REG_COM9, 0x18 }, /* 4x gain + magic rsvd bit */
807 { OV7670_REG_BD50MAX, 0x05 },
808 { OV7670_REG_BD60MAX, 0x07 },
809 { OV7670_REG_AEW, 0x95 },
810 { OV7670_REG_AEB, 0x33 },
811 { OV7670_REG_VPT, 0xe3 },
812 { OV7670_REG_HAECC1, 0x78 },
813 { OV7670_REG_HAECC2, 0x68 },
814 { 0xa1, 0x03 }, /* magic */
815 { OV7670_REG_HAECC3, 0xd8 },
816 { OV7670_REG_HAECC4, 0xd8 },
817 { OV7670_REG_HAECC5, 0xf0 },
818 { OV7670_REG_HAECC6, 0x90 },
819 { OV7670_REG_HAECC7, 0x94 },
820 { OV7670_REG_COM8, OV7670_COM8_FASTAEC
821 | OV7670_COM8_AECSTEP
822 | OV7670_COM8_BFILT
823 | OV7670_COM8_AGC
824 | OV7670_COM8_AEC },
825
826/* Almost all of these are magic "reserved" values. */
827 { OV7670_REG_COM5, 0x61 },
828 { OV7670_REG_COM6, 0x4b },
829 { 0x16, 0x02 },
830 { OV7670_REG_MVFP, 0x07 },
831 { 0x21, 0x02 },
832 { 0x22, 0x91 },
833 { 0x29, 0x07 },
834 { 0x33, 0x0b },
835 { 0x35, 0x0b },
836 { 0x37, 0x1d },
837 { 0x38, 0x71 },
838 { 0x39, 0x2a },
839 { OV7670_REG_COM12, 0x78 },
840 { 0x4d, 0x40 },
841 { 0x4e, 0x20 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300842 { OV7670_REG_GFIX, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300843 { 0x6b, 0x4a },
844 { 0x74, 0x10 },
845 { 0x8d, 0x4f },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300846 { 0x8e, 0x00 },
847 { 0x8f, 0x00 },
848 { 0x90, 0x00 },
849 { 0x91, 0x00 },
850 { 0x96, 0x00 },
851 { 0x9a, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300852 { 0xb0, 0x84 },
853 { 0xb1, 0x0c },
854 { 0xb2, 0x0e },
855 { 0xb3, 0x82 },
856 { 0xb8, 0x0a },
857
858/* More reserved magic, some of which tweaks white balance */
859 { 0x43, 0x0a },
860 { 0x44, 0xf0 },
861 { 0x45, 0x34 },
862 { 0x46, 0x58 },
863 { 0x47, 0x28 },
864 { 0x48, 0x3a },
865 { 0x59, 0x88 },
866 { 0x5a, 0x88 },
867 { 0x5b, 0x44 },
868 { 0x5c, 0x67 },
869 { 0x5d, 0x49 },
870 { 0x5e, 0x0e },
871 { 0x6c, 0x0a },
872 { 0x6d, 0x55 },
873 { 0x6e, 0x11 },
874 { 0x6f, 0x9f },
875 /* "9e for advance AWB" */
876 { 0x6a, 0x40 },
877 { OV7670_REG_BLUE, 0x40 },
878 { OV7670_REG_RED, 0x60 },
879 { OV7670_REG_COM8, OV7670_COM8_FASTAEC
880 | OV7670_COM8_AECSTEP
881 | OV7670_COM8_BFILT
882 | OV7670_COM8_AGC
883 | OV7670_COM8_AEC
884 | OV7670_COM8_AWB },
885
886/* Matrix coefficients */
887 { 0x4f, 0x80 },
888 { 0x50, 0x80 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300889 { 0x51, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300890 { 0x52, 0x22 },
891 { 0x53, 0x5e },
892 { 0x54, 0x80 },
893 { 0x58, 0x9e },
894
895 { OV7670_REG_COM16, OV7670_COM16_AWBGAIN },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300896 { OV7670_REG_EDGE, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300897 { 0x75, 0x05 },
898 { 0x76, 0xe1 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300899 { 0x4c, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300900 { 0x77, 0x01 },
901 { OV7670_REG_COM13, OV7670_COM13_GAMMA
902 | OV7670_COM13_UVSAT
903 | 2}, /* was 3 */
904 { 0x4b, 0x09 },
905 { 0xc9, 0x60 },
906 { OV7670_REG_COM16, 0x38 },
907 { 0x56, 0x40 },
908
909 { 0x34, 0x11 },
910 { OV7670_REG_COM11, OV7670_COM11_EXP|OV7670_COM11_HZAUTO },
911 { 0xa4, 0x88 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300912 { 0x96, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300913 { 0x97, 0x30 },
914 { 0x98, 0x20 },
915 { 0x99, 0x30 },
916 { 0x9a, 0x84 },
917 { 0x9b, 0x29 },
918 { 0x9c, 0x03 },
919 { 0x9d, 0x4c },
920 { 0x9e, 0x3f },
921 { 0x78, 0x04 },
922
923/* Extra-weird stuff. Some sort of multiplexor register */
924 { 0x79, 0x01 },
925 { 0xc8, 0xf0 },
926 { 0x79, 0x0f },
927 { 0xc8, 0x00 },
928 { 0x79, 0x10 },
929 { 0xc8, 0x7e },
930 { 0x79, 0x0a },
931 { 0xc8, 0x80 },
932 { 0x79, 0x0b },
933 { 0xc8, 0x01 },
934 { 0x79, 0x0c },
935 { 0xc8, 0x0f },
936 { 0x79, 0x0d },
937 { 0xc8, 0x20 },
938 { 0x79, 0x09 },
939 { 0xc8, 0x80 },
940 { 0x79, 0x02 },
941 { 0xc8, 0xc0 },
942 { 0x79, 0x03 },
943 { 0xc8, 0x40 },
944 { 0x79, 0x05 },
945 { 0xc8, 0x30 },
946 { 0x79, 0x26 },
947};
948
949static const struct ov_i2c_regvals norm_8610[] = {
950 { 0x12, 0x80 },
951 { 0x00, 0x00 },
952 { 0x01, 0x80 },
953 { 0x02, 0x80 },
954 { 0x03, 0xc0 },
955 { 0x04, 0x30 },
956 { 0x05, 0x30 }, /* was 0x10, new from windrv 090403 */
957 { 0x06, 0x70 }, /* was 0x80, new from windrv 090403 */
958 { 0x0a, 0x86 },
959 { 0x0b, 0xb0 },
960 { 0x0c, 0x20 },
961 { 0x0d, 0x20 },
962 { 0x11, 0x01 },
963 { 0x12, 0x25 },
964 { 0x13, 0x01 },
965 { 0x14, 0x04 },
966 { 0x15, 0x01 }, /* Lin and Win think different about UV order */
967 { 0x16, 0x03 },
968 { 0x17, 0x38 }, /* was 0x2f, new from windrv 090403 */
969 { 0x18, 0xea }, /* was 0xcf, new from windrv 090403 */
970 { 0x19, 0x02 }, /* was 0x06, new from windrv 090403 */
971 { 0x1a, 0xf5 },
972 { 0x1b, 0x00 },
973 { 0x20, 0xd0 }, /* was 0x90, new from windrv 090403 */
974 { 0x23, 0xc0 }, /* was 0x00, new from windrv 090403 */
975 { 0x24, 0x30 }, /* was 0x1d, new from windrv 090403 */
976 { 0x25, 0x50 }, /* was 0x57, new from windrv 090403 */
977 { 0x26, 0xa2 },
978 { 0x27, 0xea },
979 { 0x28, 0x00 },
980 { 0x29, 0x00 },
981 { 0x2a, 0x80 },
982 { 0x2b, 0xc8 }, /* was 0xcc, new from windrv 090403 */
983 { 0x2c, 0xac },
984 { 0x2d, 0x45 }, /* was 0xd5, new from windrv 090403 */
985 { 0x2e, 0x80 },
986 { 0x2f, 0x14 }, /* was 0x01, new from windrv 090403 */
987 { 0x4c, 0x00 },
988 { 0x4d, 0x30 }, /* was 0x10, new from windrv 090403 */
989 { 0x60, 0x02 }, /* was 0x01, new from windrv 090403 */
990 { 0x61, 0x00 }, /* was 0x09, new from windrv 090403 */
991 { 0x62, 0x5f }, /* was 0xd7, new from windrv 090403 */
992 { 0x63, 0xff },
993 { 0x64, 0x53 }, /* new windrv 090403 says 0x57,
994 * maybe thats wrong */
995 { 0x65, 0x00 },
996 { 0x66, 0x55 },
997 { 0x67, 0xb0 },
998 { 0x68, 0xc0 }, /* was 0xaf, new from windrv 090403 */
999 { 0x69, 0x02 },
1000 { 0x6a, 0x22 },
1001 { 0x6b, 0x00 },
1002 { 0x6c, 0x99 }, /* was 0x80, old windrv says 0x00, but
1003 * deleting bit7 colors the first images red */
1004 { 0x6d, 0x11 }, /* was 0x00, new from windrv 090403 */
1005 { 0x6e, 0x11 }, /* was 0x00, new from windrv 090403 */
1006 { 0x6f, 0x01 },
1007 { 0x70, 0x8b },
1008 { 0x71, 0x00 },
1009 { 0x72, 0x14 },
1010 { 0x73, 0x54 },
1011 { 0x74, 0x00 },/* 0x60? - was 0x00, new from windrv 090403 */
1012 { 0x75, 0x0e },
1013 { 0x76, 0x02 }, /* was 0x02, new from windrv 090403 */
1014 { 0x77, 0xff },
1015 { 0x78, 0x80 },
1016 { 0x79, 0x80 },
1017 { 0x7a, 0x80 },
1018 { 0x7b, 0x10 }, /* was 0x13, new from windrv 090403 */
1019 { 0x7c, 0x00 },
1020 { 0x7d, 0x08 }, /* was 0x09, new from windrv 090403 */
1021 { 0x7e, 0x08 }, /* was 0xc0, new from windrv 090403 */
1022 { 0x7f, 0xfb },
1023 { 0x80, 0x28 },
1024 { 0x81, 0x00 },
1025 { 0x82, 0x23 },
1026 { 0x83, 0x0b },
1027 { 0x84, 0x00 },
1028 { 0x85, 0x62 }, /* was 0x61, new from windrv 090403 */
1029 { 0x86, 0xc9 },
1030 { 0x87, 0x00 },
1031 { 0x88, 0x00 },
1032 { 0x89, 0x01 },
1033 { 0x12, 0x20 },
1034 { 0x12, 0x25 }, /* was 0x24, new from windrv 090403 */
1035};
1036
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001037static unsigned char ov7670_abs_to_sm(unsigned char v)
1038{
1039 if (v > 127)
1040 return v & 0x7f;
1041 return (128 - v) | 0x80;
1042}
1043
1044/* Write a OV519 register */
1045static int reg_w(struct sd *sd, __u16 index, __u8 value)
1046{
1047 int ret;
Hans de Goede49809d62009-06-07 12:10:39 -03001048 int req = (sd->bridge <= BRIDGE_OV511PLUS) ? 2 : 1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001049
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001050 sd->gspca_dev.usb_buf[0] = value;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001051 ret = usb_control_msg(sd->gspca_dev.dev,
1052 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
Hans de Goede49809d62009-06-07 12:10:39 -03001053 req,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001054 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1055 0, index,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001056 sd->gspca_dev.usb_buf, 1, 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001057 if (ret < 0)
1058 PDEBUG(D_ERR, "Write reg [%02x] %02x failed", index, value);
1059 return ret;
1060}
1061
1062/* Read from a OV519 register */
1063/* returns: negative is error, pos or zero is data */
1064static int reg_r(struct sd *sd, __u16 index)
1065{
1066 int ret;
Hans de Goede49809d62009-06-07 12:10:39 -03001067 int req = (sd->bridge <= BRIDGE_OV511PLUS) ? 3 : 1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001068
1069 ret = usb_control_msg(sd->gspca_dev.dev,
1070 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
Hans de Goede49809d62009-06-07 12:10:39 -03001071 req,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001072 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001073 0, index, sd->gspca_dev.usb_buf, 1, 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001074
1075 if (ret >= 0)
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001076 ret = sd->gspca_dev.usb_buf[0];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001077 else
1078 PDEBUG(D_ERR, "Read reg [0x%02x] failed", index);
1079 return ret;
1080}
1081
1082/* Read 8 values from a OV519 register */
1083static int reg_r8(struct sd *sd,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001084 __u16 index)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001085{
1086 int ret;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001087
1088 ret = usb_control_msg(sd->gspca_dev.dev,
1089 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
1090 1, /* REQ_IO */
1091 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001092 0, index, sd->gspca_dev.usb_buf, 8, 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001093
1094 if (ret >= 0)
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001095 ret = sd->gspca_dev.usb_buf[0];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001096 else
1097 PDEBUG(D_ERR, "Read reg 8 [0x%02x] failed", index);
1098 return ret;
1099}
1100
1101/*
1102 * Writes bits at positions specified by mask to an OV51x reg. Bits that are in
1103 * the same position as 1's in "mask" are cleared and set to "value". Bits
1104 * that are in the same position as 0's in "mask" are preserved, regardless
1105 * of their respective state in "value".
1106 */
1107static int reg_w_mask(struct sd *sd,
1108 __u16 index,
1109 __u8 value,
1110 __u8 mask)
1111{
1112 int ret;
1113 __u8 oldval;
1114
1115 if (mask != 0xff) {
1116 value &= mask; /* Enforce mask on value */
1117 ret = reg_r(sd, index);
1118 if (ret < 0)
1119 return ret;
1120
1121 oldval = ret & ~mask; /* Clear the masked bits */
1122 value |= oldval; /* Set the desired bits */
1123 }
1124 return reg_w(sd, index, value);
1125}
1126
1127/*
Hans de Goede49809d62009-06-07 12:10:39 -03001128 * Writes multiple (n) byte value to a single register. Only valid with certain
1129 * registers (0x30 and 0xc4 - 0xce).
1130 */
1131static int ov518_reg_w32(struct sd *sd, __u16 index, u32 value, int n)
1132{
1133 int ret;
1134
1135 *((u32 *)sd->gspca_dev.usb_buf) = __cpu_to_le32(value);
1136
1137 ret = usb_control_msg(sd->gspca_dev.dev,
1138 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
1139 1 /* REG_IO */,
1140 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1141 0, index,
1142 sd->gspca_dev.usb_buf, n, 500);
1143 if (ret < 0)
1144 PDEBUG(D_ERR, "Write reg32 [%02x] %08x failed", index, value);
1145 return ret;
1146}
1147
Hans de Goede1876bb92009-06-14 06:45:50 -03001148static int ov511_i2c_w(struct sd *sd, __u8 reg, __u8 value)
1149{
1150 int rc, retries;
1151
1152 PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
1153
1154 /* Three byte write cycle */
1155 for (retries = 6; ; ) {
1156 /* Select camera register */
1157 rc = reg_w(sd, R51x_I2C_SADDR_3, reg);
1158 if (rc < 0)
1159 return rc;
1160
1161 /* Write "value" to I2C data port of OV511 */
1162 rc = reg_w(sd, R51x_I2C_DATA, value);
1163 if (rc < 0)
1164 return rc;
1165
1166 /* Initiate 3-byte write cycle */
1167 rc = reg_w(sd, R511_I2C_CTL, 0x01);
1168 if (rc < 0)
1169 return rc;
1170
1171 do
1172 rc = reg_r(sd, R511_I2C_CTL);
1173 while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
1174
1175 if (rc < 0)
1176 return rc;
1177
1178 if ((rc & 2) == 0) /* Ack? */
1179 break;
1180 if (--retries < 0) {
1181 PDEBUG(D_USBO, "i2c write retries exhausted");
1182 return -1;
1183 }
1184 }
1185
1186 return 0;
1187}
1188
1189static int ov511_i2c_r(struct sd *sd, __u8 reg)
1190{
1191 int rc, value, retries;
1192
1193 /* Two byte write cycle */
1194 for (retries = 6; ; ) {
1195 /* Select camera register */
1196 rc = reg_w(sd, R51x_I2C_SADDR_2, reg);
1197 if (rc < 0)
1198 return rc;
1199
1200 /* Initiate 2-byte write cycle */
1201 rc = reg_w(sd, R511_I2C_CTL, 0x03);
1202 if (rc < 0)
1203 return rc;
1204
1205 do
1206 rc = reg_r(sd, R511_I2C_CTL);
1207 while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
1208
1209 if (rc < 0)
1210 return rc;
1211
1212 if ((rc & 2) == 0) /* Ack? */
1213 break;
1214
1215 /* I2C abort */
1216 reg_w(sd, R511_I2C_CTL, 0x10);
1217
1218 if (--retries < 0) {
1219 PDEBUG(D_USBI, "i2c write retries exhausted");
1220 return -1;
1221 }
1222 }
1223
1224 /* Two byte read cycle */
1225 for (retries = 6; ; ) {
1226 /* Initiate 2-byte read cycle */
1227 rc = reg_w(sd, R511_I2C_CTL, 0x05);
1228 if (rc < 0)
1229 return rc;
1230
1231 do
1232 rc = reg_r(sd, R511_I2C_CTL);
1233 while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
1234
1235 if (rc < 0)
1236 return rc;
1237
1238 if ((rc & 2) == 0) /* Ack? */
1239 break;
1240
1241 /* I2C abort */
1242 rc = reg_w(sd, R511_I2C_CTL, 0x10);
1243 if (rc < 0)
1244 return rc;
1245
1246 if (--retries < 0) {
1247 PDEBUG(D_USBI, "i2c read retries exhausted");
1248 return -1;
1249 }
1250 }
1251
1252 value = reg_r(sd, R51x_I2C_DATA);
1253
1254 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value);
1255
1256 /* This is needed to make i2c_w() work */
1257 rc = reg_w(sd, R511_I2C_CTL, 0x05);
1258 if (rc < 0)
1259 return rc;
1260
1261 return value;
1262}
Hans de Goede49809d62009-06-07 12:10:39 -03001263
1264/*
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001265 * The OV518 I2C I/O procedure is different, hence, this function.
1266 * This is normally only called from i2c_w(). Note that this function
1267 * always succeeds regardless of whether the sensor is present and working.
1268 */
Hans de Goede1876bb92009-06-14 06:45:50 -03001269static int ov518_i2c_w(struct sd *sd,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001270 __u8 reg,
1271 __u8 value)
1272{
1273 int rc;
1274
1275 PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
1276
1277 /* Select camera register */
1278 rc = reg_w(sd, R51x_I2C_SADDR_3, reg);
1279 if (rc < 0)
1280 return rc;
1281
1282 /* Write "value" to I2C data port of OV511 */
1283 rc = reg_w(sd, R51x_I2C_DATA, value);
1284 if (rc < 0)
1285 return rc;
1286
1287 /* Initiate 3-byte write cycle */
1288 rc = reg_w(sd, R518_I2C_CTL, 0x01);
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001289 if (rc < 0)
1290 return rc;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001291
1292 /* wait for write complete */
1293 msleep(4);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001294 return reg_r8(sd, R518_I2C_CTL);
1295}
1296
1297/*
1298 * returns: negative is error, pos or zero is data
1299 *
1300 * The OV518 I2C I/O procedure is different, hence, this function.
1301 * This is normally only called from i2c_r(). Note that this function
1302 * always succeeds regardless of whether the sensor is present and working.
1303 */
Hans de Goede1876bb92009-06-14 06:45:50 -03001304static int ov518_i2c_r(struct sd *sd, __u8 reg)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001305{
1306 int rc, value;
1307
1308 /* Select camera register */
1309 rc = reg_w(sd, R51x_I2C_SADDR_2, reg);
1310 if (rc < 0)
1311 return rc;
1312
1313 /* Initiate 2-byte write cycle */
1314 rc = reg_w(sd, R518_I2C_CTL, 0x03);
1315 if (rc < 0)
1316 return rc;
1317
1318 /* Initiate 2-byte read cycle */
1319 rc = reg_w(sd, R518_I2C_CTL, 0x05);
1320 if (rc < 0)
1321 return rc;
1322 value = reg_r(sd, R51x_I2C_DATA);
1323 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value);
1324 return value;
1325}
1326
Hans de Goede1876bb92009-06-14 06:45:50 -03001327static int i2c_w(struct sd *sd, __u8 reg, __u8 value)
1328{
1329 switch (sd->bridge) {
1330 case BRIDGE_OV511:
1331 case BRIDGE_OV511PLUS:
1332 return ov511_i2c_w(sd, reg, value);
1333 case BRIDGE_OV518:
1334 case BRIDGE_OV518PLUS:
1335 case BRIDGE_OV519:
1336 return ov518_i2c_w(sd, reg, value);
1337 }
1338 return -1; /* Should never happen */
1339}
1340
1341static int i2c_r(struct sd *sd, __u8 reg)
1342{
1343 switch (sd->bridge) {
1344 case BRIDGE_OV511:
1345 case BRIDGE_OV511PLUS:
1346 return ov511_i2c_r(sd, reg);
1347 case BRIDGE_OV518:
1348 case BRIDGE_OV518PLUS:
1349 case BRIDGE_OV519:
1350 return ov518_i2c_r(sd, reg);
1351 }
1352 return -1; /* Should never happen */
1353}
1354
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001355/* Writes bits at positions specified by mask to an I2C reg. Bits that are in
1356 * the same position as 1's in "mask" are cleared and set to "value". Bits
1357 * that are in the same position as 0's in "mask" are preserved, regardless
1358 * of their respective state in "value".
1359 */
1360static int i2c_w_mask(struct sd *sd,
1361 __u8 reg,
1362 __u8 value,
1363 __u8 mask)
1364{
1365 int rc;
1366 __u8 oldval;
1367
1368 value &= mask; /* Enforce mask on value */
1369 rc = i2c_r(sd, reg);
1370 if (rc < 0)
1371 return rc;
1372 oldval = rc & ~mask; /* Clear the masked bits */
1373 value |= oldval; /* Set the desired bits */
1374 return i2c_w(sd, reg, value);
1375}
1376
1377/* Temporarily stops OV511 from functioning. Must do this before changing
1378 * registers while the camera is streaming */
1379static inline int ov51x_stop(struct sd *sd)
1380{
1381 PDEBUG(D_STREAM, "stopping");
1382 sd->stopped = 1;
Hans de Goede49809d62009-06-07 12:10:39 -03001383 switch (sd->bridge) {
1384 case BRIDGE_OV511:
1385 case BRIDGE_OV511PLUS:
1386 return reg_w(sd, R51x_SYS_RESET, 0x3d);
1387 case BRIDGE_OV518:
1388 case BRIDGE_OV518PLUS:
1389 return reg_w_mask(sd, R51x_SYS_RESET, 0x3a, 0x3a);
1390 case BRIDGE_OV519:
1391 return reg_w(sd, OV519_SYS_RESET1, 0x0f);
1392 }
1393
1394 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001395}
1396
1397/* Restarts OV511 after ov511_stop() is called. Has no effect if it is not
1398 * actually stopped (for performance). */
1399static inline int ov51x_restart(struct sd *sd)
1400{
Hans de Goede49809d62009-06-07 12:10:39 -03001401 int rc;
1402
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001403 PDEBUG(D_STREAM, "restarting");
1404 if (!sd->stopped)
1405 return 0;
1406 sd->stopped = 0;
1407
1408 /* Reinitialize the stream */
Hans de Goede49809d62009-06-07 12:10:39 -03001409 switch (sd->bridge) {
1410 case BRIDGE_OV511:
1411 case BRIDGE_OV511PLUS:
1412 return reg_w(sd, R51x_SYS_RESET, 0x00);
1413 case BRIDGE_OV518:
1414 case BRIDGE_OV518PLUS:
1415 rc = reg_w(sd, 0x2f, 0x80);
1416 if (rc < 0)
1417 return rc;
1418 return reg_w(sd, R51x_SYS_RESET, 0x00);
1419 case BRIDGE_OV519:
1420 return reg_w(sd, OV519_SYS_RESET1, 0x00);
1421 }
1422
1423 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001424}
1425
1426/* This does an initial reset of an OmniVision sensor and ensures that I2C
1427 * is synchronized. Returns <0 on failure.
1428 */
1429static int init_ov_sensor(struct sd *sd)
1430{
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001431 int i;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001432
1433 /* Reset the sensor */
1434 if (i2c_w(sd, 0x12, 0x80) < 0)
1435 return -EIO;
1436
1437 /* Wait for it to initialize */
1438 msleep(150);
1439
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001440 for (i = 0; i < i2c_detect_tries; i++) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001441 if (i2c_r(sd, OV7610_REG_ID_HIGH) == 0x7f &&
1442 i2c_r(sd, OV7610_REG_ID_LOW) == 0xa2) {
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001443 PDEBUG(D_PROBE, "I2C synced in %d attempt(s)", i);
1444 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001445 }
1446
1447 /* Reset the sensor */
1448 if (i2c_w(sd, 0x12, 0x80) < 0)
1449 return -EIO;
1450 /* Wait for it to initialize */
1451 msleep(150);
1452 /* Dummy read to sync I2C */
1453 if (i2c_r(sd, 0x00) < 0)
1454 return -EIO;
1455 }
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001456 return -EIO;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001457}
1458
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001459/* Set the read and write slave IDs. The "slave" argument is the write slave,
1460 * and the read slave will be set to (slave + 1).
1461 * This should not be called from outside the i2c I/O functions.
1462 * Sets I2C read and write slave IDs. Returns <0 for error
1463 */
1464static int ov51x_set_slave_ids(struct sd *sd,
1465 __u8 slave)
1466{
1467 int rc;
1468
1469 rc = reg_w(sd, R51x_I2C_W_SID, slave);
1470 if (rc < 0)
1471 return rc;
1472 return reg_w(sd, R51x_I2C_R_SID, slave + 1);
1473}
1474
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001475static int write_regvals(struct sd *sd,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001476 const struct ov_regvals *regvals,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001477 int n)
1478{
1479 int rc;
1480
1481 while (--n >= 0) {
1482 rc = reg_w(sd, regvals->reg, regvals->val);
1483 if (rc < 0)
1484 return rc;
1485 regvals++;
1486 }
1487 return 0;
1488}
1489
1490static int write_i2c_regvals(struct sd *sd,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001491 const struct ov_i2c_regvals *regvals,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001492 int n)
1493{
1494 int rc;
1495
1496 while (--n >= 0) {
1497 rc = i2c_w(sd, regvals->reg, regvals->val);
1498 if (rc < 0)
1499 return rc;
1500 regvals++;
1501 }
1502 return 0;
1503}
1504
1505/****************************************************************************
1506 *
1507 * OV511 and sensor configuration
1508 *
1509 ***************************************************************************/
1510
1511/* This initializes the OV8110, OV8610 sensor. The OV8110 uses
1512 * the same register settings as the OV8610, since they are very similar.
1513 */
1514static int ov8xx0_configure(struct sd *sd)
1515{
1516 int rc;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001517
1518 PDEBUG(D_PROBE, "starting ov8xx0 configuration");
1519
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001520 /* Detect sensor (sub)type */
1521 rc = i2c_r(sd, OV7610_REG_COM_I);
1522 if (rc < 0) {
1523 PDEBUG(D_ERR, "Error detecting sensor type");
1524 return -1;
1525 }
1526 if ((rc & 3) == 1) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001527 sd->sensor = SEN_OV8610;
1528 } else {
1529 PDEBUG(D_ERR, "Unknown image sensor version: %d", rc & 3);
1530 return -1;
1531 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001532
1533 /* Set sensor-specific vars */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001534 return 0;
1535}
1536
1537/* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
1538 * the same register settings as the OV7610, since they are very similar.
1539 */
1540static int ov7xx0_configure(struct sd *sd)
1541{
1542 int rc, high, low;
1543
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001544
1545 PDEBUG(D_PROBE, "starting OV7xx0 configuration");
1546
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001547 /* Detect sensor (sub)type */
1548 rc = i2c_r(sd, OV7610_REG_COM_I);
1549
1550 /* add OV7670 here
1551 * it appears to be wrongly detected as a 7610 by default */
1552 if (rc < 0) {
1553 PDEBUG(D_ERR, "Error detecting sensor type");
1554 return -1;
1555 }
1556 if ((rc & 3) == 3) {
1557 /* quick hack to make OV7670s work */
1558 high = i2c_r(sd, 0x0a);
1559 low = i2c_r(sd, 0x0b);
1560 /* info("%x, %x", high, low); */
1561 if (high == 0x76 && low == 0x73) {
1562 PDEBUG(D_PROBE, "Sensor is an OV7670");
1563 sd->sensor = SEN_OV7670;
1564 } else {
1565 PDEBUG(D_PROBE, "Sensor is an OV7610");
1566 sd->sensor = SEN_OV7610;
1567 }
1568 } else if ((rc & 3) == 1) {
1569 /* I don't know what's different about the 76BE yet. */
Hans de Goedeb282d872009-06-14 19:10:40 -03001570 if (i2c_r(sd, 0x15) & 1) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001571 PDEBUG(D_PROBE, "Sensor is an OV7620AE");
Hans de Goedeb282d872009-06-14 19:10:40 -03001572 sd->sensor = SEN_OV7620;
1573 } else {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001574 PDEBUG(D_PROBE, "Sensor is an OV76BE");
Hans de Goedeb282d872009-06-14 19:10:40 -03001575 sd->sensor = SEN_OV76BE;
1576 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001577 } else if ((rc & 3) == 0) {
1578 /* try to read product id registers */
1579 high = i2c_r(sd, 0x0a);
1580 if (high < 0) {
1581 PDEBUG(D_ERR, "Error detecting camera chip PID");
1582 return high;
1583 }
1584 low = i2c_r(sd, 0x0b);
1585 if (low < 0) {
1586 PDEBUG(D_ERR, "Error detecting camera chip VER");
1587 return low;
1588 }
1589 if (high == 0x76) {
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001590 switch (low) {
1591 case 0x30:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001592 PDEBUG(D_PROBE, "Sensor is an OV7630/OV7635");
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001593 PDEBUG(D_ERR,
1594 "7630 is not supported by this driver");
1595 return -1;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001596 case 0x40:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001597 PDEBUG(D_PROBE, "Sensor is an OV7645");
1598 sd->sensor = SEN_OV7640; /* FIXME */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001599 break;
1600 case 0x45:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001601 PDEBUG(D_PROBE, "Sensor is an OV7645B");
1602 sd->sensor = SEN_OV7640; /* FIXME */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001603 break;
1604 case 0x48:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001605 PDEBUG(D_PROBE, "Sensor is an OV7648");
1606 sd->sensor = SEN_OV7640; /* FIXME */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001607 break;
1608 default:
1609 PDEBUG(D_PROBE, "Unknown sensor: 0x76%x", low);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001610 return -1;
1611 }
1612 } else {
1613 PDEBUG(D_PROBE, "Sensor is an OV7620");
1614 sd->sensor = SEN_OV7620;
1615 }
1616 } else {
1617 PDEBUG(D_ERR, "Unknown image sensor version: %d", rc & 3);
1618 return -1;
1619 }
1620
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001621 /* Set sensor-specific vars */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001622 return 0;
1623}
1624
1625/* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
1626static int ov6xx0_configure(struct sd *sd)
1627{
1628 int rc;
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001629 PDEBUG(D_PROBE, "starting OV6xx0 configuration");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001630
1631 /* Detect sensor (sub)type */
1632 rc = i2c_r(sd, OV7610_REG_COM_I);
1633 if (rc < 0) {
1634 PDEBUG(D_ERR, "Error detecting sensor type");
1635 return -1;
1636 }
1637
1638 /* Ugh. The first two bits are the version bits, but
1639 * the entire register value must be used. I guess OVT
1640 * underestimated how many variants they would make. */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001641 switch (rc) {
1642 case 0x00:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001643 sd->sensor = SEN_OV6630;
1644 PDEBUG(D_ERR,
1645 "WARNING: Sensor is an OV66308. Your camera may have");
1646 PDEBUG(D_ERR, "been misdetected in previous driver versions.");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001647 break;
1648 case 0x01:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001649 sd->sensor = SEN_OV6620;
Hans de Goede7d971372009-06-14 05:28:17 -03001650 PDEBUG(D_PROBE, "Sensor is an OV6620");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001651 break;
1652 case 0x02:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001653 sd->sensor = SEN_OV6630;
1654 PDEBUG(D_PROBE, "Sensor is an OV66308AE");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001655 break;
1656 case 0x03:
Hans de Goede7d971372009-06-14 05:28:17 -03001657 sd->sensor = SEN_OV66308AF;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001658 PDEBUG(D_PROBE, "Sensor is an OV66308AF");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001659 break;
1660 case 0x90:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001661 sd->sensor = SEN_OV6630;
1662 PDEBUG(D_ERR,
1663 "WARNING: Sensor is an OV66307. Your camera may have");
1664 PDEBUG(D_ERR, "been misdetected in previous driver versions.");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001665 break;
1666 default:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001667 PDEBUG(D_ERR, "FATAL: Unknown sensor version: 0x%02x", rc);
1668 return -1;
1669 }
1670
1671 /* Set sensor-specific vars */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03001672 sd->sif = 1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001673
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001674 return 0;
1675}
1676
1677/* Turns on or off the LED. Only has an effect with OV511+/OV518(+)/OV519 */
1678static void ov51x_led_control(struct sd *sd, int on)
1679{
Hans de Goede9e4d8252009-06-14 06:25:06 -03001680 if (sd->invert_led)
1681 on = !on;
1682
Hans de Goede49809d62009-06-07 12:10:39 -03001683 switch (sd->bridge) {
1684 /* OV511 has no LED control */
1685 case BRIDGE_OV511PLUS:
1686 reg_w(sd, R511_SYS_LED_CTL, on ? 1 : 0);
1687 break;
1688 case BRIDGE_OV518:
1689 case BRIDGE_OV518PLUS:
1690 reg_w_mask(sd, R518_GPIO_OUT, on ? 0x02 : 0x00, 0x02);
1691 break;
1692 case BRIDGE_OV519:
1693 reg_w_mask(sd, OV519_GPIO_DATA_OUT0, !on, 1); /* 0 / 1 */
1694 break;
1695 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001696}
1697
Hans de Goede1876bb92009-06-14 06:45:50 -03001698static int ov51x_upload_quan_tables(struct sd *sd)
Hans de Goede49809d62009-06-07 12:10:39 -03001699{
Hans de Goede1876bb92009-06-14 06:45:50 -03001700 const unsigned char yQuanTable511[] = {
1701 0, 1, 1, 2, 2, 3, 3, 4,
1702 1, 1, 1, 2, 2, 3, 4, 4,
1703 1, 1, 2, 2, 3, 4, 4, 4,
1704 2, 2, 2, 3, 4, 4, 4, 4,
1705 2, 2, 3, 4, 4, 5, 5, 5,
1706 3, 3, 4, 4, 5, 5, 5, 5,
1707 3, 4, 4, 4, 5, 5, 5, 5,
1708 4, 4, 4, 4, 5, 5, 5, 5
1709 };
1710
1711 const unsigned char uvQuanTable511[] = {
1712 0, 2, 2, 3, 4, 4, 4, 4,
1713 2, 2, 2, 4, 4, 4, 4, 4,
1714 2, 2, 3, 4, 4, 4, 4, 4,
1715 3, 4, 4, 4, 4, 4, 4, 4,
1716 4, 4, 4, 4, 4, 4, 4, 4,
1717 4, 4, 4, 4, 4, 4, 4, 4,
1718 4, 4, 4, 4, 4, 4, 4, 4,
1719 4, 4, 4, 4, 4, 4, 4, 4
1720 };
1721
1722 /* OV518 quantization tables are 8x4 (instead of 8x8) */
Hans de Goede49809d62009-06-07 12:10:39 -03001723 const unsigned char yQuanTable518[] = {
1724 5, 4, 5, 6, 6, 7, 7, 7,
1725 5, 5, 5, 5, 6, 7, 7, 7,
1726 6, 6, 6, 6, 7, 7, 7, 8,
1727 7, 7, 6, 7, 7, 7, 8, 8
1728 };
1729
1730 const unsigned char uvQuanTable518[] = {
1731 6, 6, 6, 7, 7, 7, 7, 7,
1732 6, 6, 6, 7, 7, 7, 7, 7,
1733 6, 6, 6, 7, 7, 7, 7, 8,
1734 7, 7, 7, 7, 7, 7, 8, 8
1735 };
1736
Hans de Goede1876bb92009-06-14 06:45:50 -03001737 const unsigned char *pYTable, *pUVTable;
Hans de Goede49809d62009-06-07 12:10:39 -03001738 unsigned char val0, val1;
Hans de Goede1876bb92009-06-14 06:45:50 -03001739 int i, size, rc, reg = R51x_COMP_LUT_BEGIN;
Hans de Goede49809d62009-06-07 12:10:39 -03001740
1741 PDEBUG(D_PROBE, "Uploading quantization tables");
1742
Hans de Goede1876bb92009-06-14 06:45:50 -03001743 if (sd->bridge == BRIDGE_OV511 || sd->bridge == BRIDGE_OV511PLUS) {
1744 pYTable = yQuanTable511;
1745 pUVTable = uvQuanTable511;
1746 size = 32;
1747 } else {
1748 pYTable = yQuanTable518;
1749 pUVTable = uvQuanTable518;
1750 size = 16;
1751 }
1752
1753 for (i = 0; i < size; i++) {
Hans de Goede49809d62009-06-07 12:10:39 -03001754 val0 = *pYTable++;
1755 val1 = *pYTable++;
1756 val0 &= 0x0f;
1757 val1 &= 0x0f;
1758 val0 |= val1 << 4;
1759 rc = reg_w(sd, reg, val0);
1760 if (rc < 0)
1761 return rc;
1762
1763 val0 = *pUVTable++;
1764 val1 = *pUVTable++;
1765 val0 &= 0x0f;
1766 val1 &= 0x0f;
1767 val0 |= val1 << 4;
Hans de Goede1876bb92009-06-14 06:45:50 -03001768 rc = reg_w(sd, reg + size, val0);
Hans de Goede49809d62009-06-07 12:10:39 -03001769 if (rc < 0)
1770 return rc;
1771
1772 reg++;
1773 }
1774
1775 return 0;
1776}
1777
Hans de Goede1876bb92009-06-14 06:45:50 -03001778/* This initializes the OV511/OV511+ and the sensor */
1779static int ov511_configure(struct gspca_dev *gspca_dev)
1780{
1781 struct sd *sd = (struct sd *) gspca_dev;
1782 int rc;
1783
1784 /* For 511 and 511+ */
1785 const struct ov_regvals init_511[] = {
1786 { R51x_SYS_RESET, 0x7f },
1787 { R51x_SYS_INIT, 0x01 },
1788 { R51x_SYS_RESET, 0x7f },
1789 { R51x_SYS_INIT, 0x01 },
1790 { R51x_SYS_RESET, 0x3f },
1791 { R51x_SYS_INIT, 0x01 },
1792 { R51x_SYS_RESET, 0x3d },
1793 };
1794
1795 const struct ov_regvals norm_511[] = {
1796 { R511_DRAM_FLOW_CTL, 0x01 },
1797 { R51x_SYS_SNAP, 0x00 },
1798 { R51x_SYS_SNAP, 0x02 },
1799 { R51x_SYS_SNAP, 0x00 },
1800 { R511_FIFO_OPTS, 0x1f },
1801 { R511_COMP_EN, 0x00 },
1802 { R511_COMP_LUT_EN, 0x03 },
1803 };
1804
1805 const struct ov_regvals norm_511_p[] = {
1806 { R511_DRAM_FLOW_CTL, 0xff },
1807 { R51x_SYS_SNAP, 0x00 },
1808 { R51x_SYS_SNAP, 0x02 },
1809 { R51x_SYS_SNAP, 0x00 },
1810 { R511_FIFO_OPTS, 0xff },
1811 { R511_COMP_EN, 0x00 },
1812 { R511_COMP_LUT_EN, 0x03 },
1813 };
1814
1815 const struct ov_regvals compress_511[] = {
1816 { 0x70, 0x1f },
1817 { 0x71, 0x05 },
1818 { 0x72, 0x06 },
1819 { 0x73, 0x06 },
1820 { 0x74, 0x14 },
1821 { 0x75, 0x03 },
1822 { 0x76, 0x04 },
1823 { 0x77, 0x04 },
1824 };
1825
1826 PDEBUG(D_PROBE, "Device custom id %x", reg_r(sd, R51x_SYS_CUST_ID));
1827
1828 rc = write_regvals(sd, init_511, ARRAY_SIZE(init_511));
1829 if (rc < 0)
1830 return rc;
1831
1832 switch (sd->bridge) {
1833 case BRIDGE_OV511:
1834 rc = write_regvals(sd, norm_511, ARRAY_SIZE(norm_511));
1835 if (rc < 0)
1836 return rc;
1837 break;
1838 case BRIDGE_OV511PLUS:
1839 rc = write_regvals(sd, norm_511_p, ARRAY_SIZE(norm_511_p));
1840 if (rc < 0)
1841 return rc;
1842 break;
1843 }
1844
1845 /* Init compression */
1846 rc = write_regvals(sd, compress_511, ARRAY_SIZE(compress_511));
1847 if (rc < 0)
1848 return rc;
1849
1850 rc = ov51x_upload_quan_tables(sd);
1851 if (rc < 0) {
1852 PDEBUG(D_ERR, "Error uploading quantization tables");
1853 return rc;
1854 }
1855
1856 return 0;
1857}
1858
Hans de Goede49809d62009-06-07 12:10:39 -03001859/* This initializes the OV518/OV518+ and the sensor */
1860static int ov518_configure(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001861{
1862 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede49809d62009-06-07 12:10:39 -03001863 int rc;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001864
Hans de Goede49809d62009-06-07 12:10:39 -03001865 /* For 518 and 518+ */
1866 static struct ov_regvals init_518[] = {
1867 { R51x_SYS_RESET, 0x40 },
1868 { R51x_SYS_INIT, 0xe1 },
1869 { R51x_SYS_RESET, 0x3e },
1870 { R51x_SYS_INIT, 0xe1 },
1871 { R51x_SYS_RESET, 0x00 },
1872 { R51x_SYS_INIT, 0xe1 },
1873 { 0x46, 0x00 },
1874 { 0x5d, 0x03 },
1875 };
1876
1877 static struct ov_regvals norm_518[] = {
1878 { R51x_SYS_SNAP, 0x02 }, /* Reset */
1879 { R51x_SYS_SNAP, 0x01 }, /* Enable */
1880 { 0x31, 0x0f },
1881 { 0x5d, 0x03 },
1882 { 0x24, 0x9f },
1883 { 0x25, 0x90 },
1884 { 0x20, 0x00 },
1885 { 0x51, 0x04 },
1886 { 0x71, 0x19 },
1887 { 0x2f, 0x80 },
1888 };
1889
1890 static struct ov_regvals norm_518_p[] = {
1891 { R51x_SYS_SNAP, 0x02 }, /* Reset */
1892 { R51x_SYS_SNAP, 0x01 }, /* Enable */
1893 { 0x31, 0x0f },
1894 { 0x5d, 0x03 },
1895 { 0x24, 0x9f },
1896 { 0x25, 0x90 },
1897 { 0x20, 0x60 },
1898 { 0x51, 0x02 },
1899 { 0x71, 0x19 },
1900 { 0x40, 0xff },
1901 { 0x41, 0x42 },
1902 { 0x46, 0x00 },
1903 { 0x33, 0x04 },
1904 { 0x21, 0x19 },
1905 { 0x3f, 0x10 },
1906 { 0x2f, 0x80 },
1907 };
1908
1909 /* First 5 bits of custom ID reg are a revision ID on OV518 */
1910 PDEBUG(D_PROBE, "Device revision %d",
1911 0x1F & reg_r(sd, R51x_SYS_CUST_ID));
1912
1913 rc = write_regvals(sd, init_518, ARRAY_SIZE(init_518));
1914 if (rc < 0)
1915 return rc;
1916
1917 /* Set LED GPIO pin to output mode */
1918 rc = reg_w_mask(sd, R518_GPIO_CTL, 0x00, 0x02);
1919 if (rc < 0)
1920 return rc;
1921
1922 switch (sd->bridge) {
1923 case BRIDGE_OV518:
1924 rc = write_regvals(sd, norm_518, ARRAY_SIZE(norm_518));
1925 if (rc < 0)
1926 return rc;
1927 break;
1928 case BRIDGE_OV518PLUS:
1929 rc = write_regvals(sd, norm_518_p, ARRAY_SIZE(norm_518_p));
1930 if (rc < 0)
1931 return rc;
1932 break;
1933 }
1934
Hans de Goede1876bb92009-06-14 06:45:50 -03001935 rc = ov51x_upload_quan_tables(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03001936 if (rc < 0) {
1937 PDEBUG(D_ERR, "Error uploading quantization tables");
1938 return rc;
1939 }
1940
1941 rc = reg_w(sd, 0x2f, 0x80);
1942 if (rc < 0)
1943 return rc;
1944
1945 return 0;
1946}
1947
1948static int ov519_configure(struct sd *sd)
1949{
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001950 static const struct ov_regvals init_519[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001951 { 0x5a, 0x6d }, /* EnableSystem */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001952 { 0x53, 0x9b },
1953 { 0x54, 0xff }, /* set bit2 to enable jpeg */
1954 { 0x5d, 0x03 },
1955 { 0x49, 0x01 },
1956 { 0x48, 0x00 },
1957 /* Set LED pin to output mode. Bit 4 must be cleared or sensor
1958 * detection will fail. This deserves further investigation. */
1959 { OV519_GPIO_IO_CTRL0, 0xee },
1960 { 0x51, 0x0f }, /* SetUsbInit */
1961 { 0x51, 0x00 },
1962 { 0x22, 0x00 },
1963 /* windows reads 0x55 at this point*/
1964 };
1965
Hans de Goede49809d62009-06-07 12:10:39 -03001966 return write_regvals(sd, init_519, ARRAY_SIZE(init_519));
1967}
1968
1969/* this function is called at probe time */
1970static int sd_config(struct gspca_dev *gspca_dev,
1971 const struct usb_device_id *id)
1972{
1973 struct sd *sd = (struct sd *) gspca_dev;
1974 struct cam *cam;
1975 int ret = 0;
1976
Hans de Goede9e4d8252009-06-14 06:25:06 -03001977 sd->bridge = id->driver_info & BRIDGE_MASK;
1978 sd->invert_led = id->driver_info & BRIDGE_INVERT_LED;
Hans de Goede49809d62009-06-07 12:10:39 -03001979
1980 switch (sd->bridge) {
Hans de Goede1876bb92009-06-14 06:45:50 -03001981 case BRIDGE_OV511:
1982 case BRIDGE_OV511PLUS:
1983 ret = ov511_configure(gspca_dev);
1984 break;
Hans de Goede49809d62009-06-07 12:10:39 -03001985 case BRIDGE_OV518:
1986 case BRIDGE_OV518PLUS:
1987 ret = ov518_configure(gspca_dev);
1988 break;
1989 case BRIDGE_OV519:
1990 ret = ov519_configure(sd);
1991 break;
1992 }
1993
1994 if (ret)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001995 goto error;
Hans de Goede49809d62009-06-07 12:10:39 -03001996
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001997 ov51x_led_control(sd, 0); /* turn LED off */
1998
1999 /* Test for 76xx */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002000 if (ov51x_set_slave_ids(sd, OV7xx0_SID) < 0)
2001 goto error;
2002
2003 /* The OV519 must be more aggressive about sensor detection since
2004 * I2C write will never fail if the sensor is not present. We have
2005 * to try to initialize the sensor to detect its presence */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03002006 if (init_ov_sensor(sd) >= 0) {
2007 if (ov7xx0_configure(sd) < 0) {
2008 PDEBUG(D_ERR, "Failed to configure OV7xx0");
2009 goto error;
2010 }
2011 } else {
2012
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002013 /* Test for 6xx0 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002014 if (ov51x_set_slave_ids(sd, OV6xx0_SID) < 0)
2015 goto error;
2016
Jean-Francois Moine4202f712008-09-03 17:12:15 -03002017 if (init_ov_sensor(sd) >= 0) {
2018 if (ov6xx0_configure(sd) < 0) {
2019 PDEBUG(D_ERR, "Failed to configure OV6xx0");
2020 goto error;
2021 }
2022 } else {
2023
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002024 /* Test for 8xx0 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002025 if (ov51x_set_slave_ids(sd, OV8xx0_SID) < 0)
2026 goto error;
2027
2028 if (init_ov_sensor(sd) < 0) {
2029 PDEBUG(D_ERR,
2030 "Can't determine sensor slave IDs");
2031 goto error;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002032 }
Jean-Francois Moine4202f712008-09-03 17:12:15 -03002033 if (ov8xx0_configure(sd) < 0) {
2034 PDEBUG(D_ERR,
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002035 "Failed to configure OV8xx0 sensor");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002036 goto error;
2037 }
2038 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002039 }
2040
2041 cam = &gspca_dev->cam;
Hans de Goede49809d62009-06-07 12:10:39 -03002042 switch (sd->bridge) {
Hans de Goede1876bb92009-06-14 06:45:50 -03002043 case BRIDGE_OV511:
2044 case BRIDGE_OV511PLUS:
2045 if (!sd->sif) {
2046 cam->cam_mode = ov511_vga_mode;
2047 cam->nmodes = ARRAY_SIZE(ov511_vga_mode);
2048 } else {
2049 cam->cam_mode = ov511_sif_mode;
2050 cam->nmodes = ARRAY_SIZE(ov511_sif_mode);
2051 }
2052 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002053 case BRIDGE_OV518:
2054 case BRIDGE_OV518PLUS:
2055 if (!sd->sif) {
2056 cam->cam_mode = ov518_vga_mode;
2057 cam->nmodes = ARRAY_SIZE(ov518_vga_mode);
2058 } else {
2059 cam->cam_mode = ov518_sif_mode;
2060 cam->nmodes = ARRAY_SIZE(ov518_sif_mode);
2061 }
2062 break;
2063 case BRIDGE_OV519:
2064 if (!sd->sif) {
2065 cam->cam_mode = ov519_vga_mode;
2066 cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
2067 } else {
2068 cam->cam_mode = ov519_sif_mode;
2069 cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
2070 }
2071 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002072 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002073 sd->brightness = BRIGHTNESS_DEF;
Hans de Goedef5cee952009-06-14 06:32:52 -03002074 if (sd->sensor == SEN_OV6630 || sd->sensor == SEN_OV66308AF)
2075 sd->contrast = 200; /* The default is too low for the ov6630 */
2076 else
2077 sd->contrast = CONTRAST_DEF;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002078 sd->colors = COLOR_DEF;
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03002079 sd->hflip = HFLIP_DEF;
2080 sd->vflip = VFLIP_DEF;
Hans de Goede02ab18b2009-06-14 04:32:04 -03002081 sd->autobrightness = AUTOBRIGHT_DEF;
2082 if (sd->sensor == SEN_OV7670) {
2083 sd->freq = OV7670_FREQ_DEF;
2084 gspca_dev->ctrl_dis = 1 << FREQ_IDX;
2085 } else {
2086 sd->freq = FREQ_DEF;
2087 gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX) |
2088 (1 << OV7670_FREQ_IDX);
2089 }
2090 if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7670)
2091 gspca_dev->ctrl_dis |= 1 << AUTOBRIGHT_IDX;
2092 /* OV8610 Frequency filter control should work but needs testing */
2093 if (sd->sensor == SEN_OV8610)
2094 gspca_dev->ctrl_dis |= 1 << FREQ_IDX;
2095
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002096 return 0;
2097error:
2098 PDEBUG(D_ERR, "OV519 Config failed");
2099 return -EBUSY;
2100}
2101
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03002102/* this function is called at probe and resume time */
2103static int sd_init(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002104{
Jean-Francois Moine4202f712008-09-03 17:12:15 -03002105 struct sd *sd = (struct sd *) gspca_dev;
2106
2107 /* initialize the sensor */
2108 switch (sd->sensor) {
2109 case SEN_OV6620:
2110 if (write_i2c_regvals(sd, norm_6x20, ARRAY_SIZE(norm_6x20)))
2111 return -EIO;
2112 break;
2113 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03002114 case SEN_OV66308AF:
Jean-Francois Moine4202f712008-09-03 17:12:15 -03002115 if (write_i2c_regvals(sd, norm_6x30, ARRAY_SIZE(norm_6x30)))
2116 return -EIO;
2117 break;
2118 default:
2119/* case SEN_OV7610: */
2120/* case SEN_OV76BE: */
2121 if (write_i2c_regvals(sd, norm_7610, ARRAY_SIZE(norm_7610)))
2122 return -EIO;
2123 break;
2124 case SEN_OV7620:
2125 if (write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620)))
2126 return -EIO;
2127 break;
2128 case SEN_OV7640:
2129 if (write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640)))
2130 return -EIO;
2131 break;
2132 case SEN_OV7670:
2133 if (write_i2c_regvals(sd, norm_7670, ARRAY_SIZE(norm_7670)))
2134 return -EIO;
2135 break;
2136 case SEN_OV8610:
2137 if (write_i2c_regvals(sd, norm_8610, ARRAY_SIZE(norm_8610)))
2138 return -EIO;
2139 break;
2140 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002141 return 0;
2142}
2143
Hans de Goede1876bb92009-06-14 06:45:50 -03002144/* Set up the OV511/OV511+ with the given image parameters.
2145 *
2146 * Do not put any sensor-specific code in here (including I2C I/O functions)
2147 */
2148static int ov511_mode_init_regs(struct sd *sd)
2149{
2150 int hsegs, vsegs, packet_size, fps, needed;
2151 int interlaced = 0;
2152 struct usb_host_interface *alt;
2153 struct usb_interface *intf;
2154
2155 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
2156 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
2157 if (!alt) {
2158 PDEBUG(D_ERR, "Couldn't get altsetting");
2159 return -EIO;
2160 }
2161
2162 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
2163 reg_w(sd, R51x_FIFO_PSIZE, packet_size >> 5);
2164
2165 reg_w(sd, R511_CAM_UV_EN, 0x01);
2166 reg_w(sd, R511_SNAP_UV_EN, 0x01);
2167 reg_w(sd, R511_SNAP_OPTS, 0x03);
2168
2169 /* Here I'm assuming that snapshot size == image size.
2170 * I hope that's always true. --claudio
2171 */
2172 hsegs = (sd->gspca_dev.width >> 3) - 1;
2173 vsegs = (sd->gspca_dev.height >> 3) - 1;
2174
2175 reg_w(sd, R511_CAM_PXCNT, hsegs);
2176 reg_w(sd, R511_CAM_LNCNT, vsegs);
2177 reg_w(sd, R511_CAM_PXDIV, 0x00);
2178 reg_w(sd, R511_CAM_LNDIV, 0x00);
2179
2180 /* YUV420, low pass filter on */
2181 reg_w(sd, R511_CAM_OPTS, 0x03);
2182
2183 /* Snapshot additions */
2184 reg_w(sd, R511_SNAP_PXCNT, hsegs);
2185 reg_w(sd, R511_SNAP_LNCNT, vsegs);
2186 reg_w(sd, R511_SNAP_PXDIV, 0x00);
2187 reg_w(sd, R511_SNAP_LNDIV, 0x00);
2188
2189 /******** Set the framerate ********/
2190 if (frame_rate > 0)
2191 sd->frame_rate = frame_rate;
2192
2193 switch (sd->sensor) {
2194 case SEN_OV6620:
2195 /* No framerate control, doesn't like higher rates yet */
2196 sd->clockdiv = 3;
2197 break;
2198
2199 /* Note once the FIXME's in mode_init_ov_sensor_regs() are fixed
2200 for more sensors we need to do this for them too */
2201 case SEN_OV7620:
2202 case SEN_OV7640:
Hans de Goedeb282d872009-06-14 19:10:40 -03002203 case SEN_OV76BE:
Hans de Goede1876bb92009-06-14 06:45:50 -03002204 if (sd->gspca_dev.width == 320)
2205 interlaced = 1;
2206 /* Fall through */
2207 case SEN_OV6630:
Hans de Goede1876bb92009-06-14 06:45:50 -03002208 case SEN_OV7610:
2209 case SEN_OV7670:
2210 switch (sd->frame_rate) {
2211 case 30:
2212 case 25:
2213 /* Not enough bandwidth to do 640x480 @ 30 fps */
2214 if (sd->gspca_dev.width != 640) {
2215 sd->clockdiv = 0;
2216 break;
2217 }
2218 /* Fall through for 640x480 case */
2219 default:
2220/* case 20: */
2221/* case 15: */
2222 sd->clockdiv = 1;
2223 break;
2224 case 10:
2225 sd->clockdiv = 2;
2226 break;
2227 case 5:
2228 sd->clockdiv = 5;
2229 break;
2230 }
2231 if (interlaced) {
2232 sd->clockdiv = (sd->clockdiv + 1) * 2 - 1;
2233 /* Higher then 10 does not work */
2234 if (sd->clockdiv > 10)
2235 sd->clockdiv = 10;
2236 }
2237 break;
2238
2239 case SEN_OV8610:
2240 /* No framerate control ?? */
2241 sd->clockdiv = 0;
2242 break;
2243 }
2244
2245 /* Check if we have enough bandwidth to disable compression */
2246 fps = (interlaced ? 60 : 30) / (sd->clockdiv + 1) + 1;
2247 needed = fps * sd->gspca_dev.width * sd->gspca_dev.height * 3 / 2;
2248 /* 1400 is a conservative estimate of the max nr of isoc packets/sec */
2249 if (needed > 1400 * packet_size) {
2250 /* Enable Y and UV quantization and compression */
2251 reg_w(sd, R511_COMP_EN, 0x07);
2252 reg_w(sd, R511_COMP_LUT_EN, 0x03);
2253 } else {
2254 reg_w(sd, R511_COMP_EN, 0x06);
2255 reg_w(sd, R511_COMP_LUT_EN, 0x00);
2256 }
2257
2258 reg_w(sd, R51x_SYS_RESET, OV511_RESET_OMNICE);
2259 reg_w(sd, R51x_SYS_RESET, 0);
2260
2261 return 0;
2262}
2263
Hans de Goede49809d62009-06-07 12:10:39 -03002264/* Sets up the OV518/OV518+ with the given image parameters
2265 *
2266 * OV518 needs a completely different approach, until we can figure out what
2267 * the individual registers do. Also, only 15 FPS is supported now.
2268 *
2269 * Do not put any sensor-specific code in here (including I2C I/O functions)
2270 */
2271static int ov518_mode_init_regs(struct sd *sd)
2272{
Hans de Goedeb282d872009-06-14 19:10:40 -03002273 int hsegs, vsegs, packet_size;
2274 struct usb_host_interface *alt;
2275 struct usb_interface *intf;
2276
2277 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
2278 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
2279 if (!alt) {
2280 PDEBUG(D_ERR, "Couldn't get altsetting");
2281 return -EIO;
2282 }
2283
2284 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
2285 ov518_reg_w32(sd, R51x_FIFO_PSIZE, packet_size & ~7, 2);
Hans de Goede49809d62009-06-07 12:10:39 -03002286
2287 /******** Set the mode ********/
2288
2289 reg_w(sd, 0x2b, 0);
2290 reg_w(sd, 0x2c, 0);
2291 reg_w(sd, 0x2d, 0);
2292 reg_w(sd, 0x2e, 0);
2293 reg_w(sd, 0x3b, 0);
2294 reg_w(sd, 0x3c, 0);
2295 reg_w(sd, 0x3d, 0);
2296 reg_w(sd, 0x3e, 0);
2297
2298 if (sd->bridge == BRIDGE_OV518) {
2299 /* Set 8-bit (YVYU) input format */
2300 reg_w_mask(sd, 0x20, 0x08, 0x08);
2301
2302 /* Set 12-bit (4:2:0) output format */
2303 reg_w_mask(sd, 0x28, 0x80, 0xf0);
2304 reg_w_mask(sd, 0x38, 0x80, 0xf0);
2305 } else {
2306 reg_w(sd, 0x28, 0x80);
2307 reg_w(sd, 0x38, 0x80);
2308 }
2309
2310 hsegs = sd->gspca_dev.width / 16;
2311 vsegs = sd->gspca_dev.height / 4;
2312
2313 reg_w(sd, 0x29, hsegs);
2314 reg_w(sd, 0x2a, vsegs);
2315
2316 reg_w(sd, 0x39, hsegs);
2317 reg_w(sd, 0x3a, vsegs);
2318
2319 /* Windows driver does this here; who knows why */
2320 reg_w(sd, 0x2f, 0x80);
2321
Hans de Goedeb282d872009-06-14 19:10:40 -03002322 /******** Set the framerate ********/
2323 sd->clockdiv = 1;
Hans de Goede49809d62009-06-07 12:10:39 -03002324
2325 /* Mode independent, but framerate dependent, regs */
Hans de Goedeb282d872009-06-14 19:10:40 -03002326 /* 0x51: Clock divider; Only works on some cams which use 2 crystals */
2327 reg_w(sd, 0x51, 0x04);
Hans de Goede49809d62009-06-07 12:10:39 -03002328 reg_w(sd, 0x22, 0x18);
2329 reg_w(sd, 0x23, 0xff);
2330
Hans de Goedeb282d872009-06-14 19:10:40 -03002331 if (sd->bridge == BRIDGE_OV518PLUS) {
2332 switch (sd->sensor) {
2333 case SEN_OV7620:
2334 if (sd->gspca_dev.width == 320) {
2335 reg_w(sd, 0x20, 0x00);
2336 reg_w(sd, 0x21, 0x19);
2337 } else {
2338 reg_w(sd, 0x20, 0x60);
2339 reg_w(sd, 0x21, 0x1f);
2340 }
2341 break;
2342 default:
2343 reg_w(sd, 0x21, 0x19);
2344 }
2345 } else
Hans de Goede49809d62009-06-07 12:10:39 -03002346 reg_w(sd, 0x71, 0x17); /* Compression-related? */
2347
2348 /* FIXME: Sensor-specific */
2349 /* Bit 5 is what matters here. Of course, it is "reserved" */
2350 i2c_w(sd, 0x54, 0x23);
2351
2352 reg_w(sd, 0x2f, 0x80);
2353
2354 if (sd->bridge == BRIDGE_OV518PLUS) {
2355 reg_w(sd, 0x24, 0x94);
2356 reg_w(sd, 0x25, 0x90);
2357 ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
2358 ov518_reg_w32(sd, 0xc6, 540, 2); /* 21ch */
2359 ov518_reg_w32(sd, 0xc7, 540, 2); /* 21ch */
2360 ov518_reg_w32(sd, 0xc8, 108, 2); /* 6ch */
2361 ov518_reg_w32(sd, 0xca, 131098, 3); /* 2001ah */
2362 ov518_reg_w32(sd, 0xcb, 532, 2); /* 214h */
2363 ov518_reg_w32(sd, 0xcc, 2400, 2); /* 960h */
2364 ov518_reg_w32(sd, 0xcd, 32, 2); /* 20h */
2365 ov518_reg_w32(sd, 0xce, 608, 2); /* 260h */
2366 } else {
2367 reg_w(sd, 0x24, 0x9f);
2368 reg_w(sd, 0x25, 0x90);
2369 ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
2370 ov518_reg_w32(sd, 0xc6, 381, 2); /* 17dh */
2371 ov518_reg_w32(sd, 0xc7, 381, 2); /* 17dh */
2372 ov518_reg_w32(sd, 0xc8, 128, 2); /* 80h */
2373 ov518_reg_w32(sd, 0xca, 183331, 3); /* 2cc23h */
2374 ov518_reg_w32(sd, 0xcb, 746, 2); /* 2eah */
2375 ov518_reg_w32(sd, 0xcc, 1750, 2); /* 6d6h */
2376 ov518_reg_w32(sd, 0xcd, 45, 2); /* 2dh */
2377 ov518_reg_w32(sd, 0xce, 851, 2); /* 353h */
2378 }
2379
2380 reg_w(sd, 0x2f, 0x80);
2381
2382 return 0;
2383}
2384
2385
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002386/* Sets up the OV519 with the given image parameters
2387 *
2388 * OV519 needs a completely different approach, until we can figure out what
2389 * the individual registers do.
2390 *
2391 * Do not put any sensor-specific code in here (including I2C I/O functions)
2392 */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002393static int ov519_mode_init_regs(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002394{
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002395 static const struct ov_regvals mode_init_519_ov7670[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002396 { 0x5d, 0x03 }, /* Turn off suspend mode */
2397 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
2398 { 0x54, 0x0f }, /* bit2 (jpeg enable) */
2399 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
2400 { 0xa3, 0x18 },
2401 { 0xa4, 0x04 },
2402 { 0xa5, 0x28 },
2403 { 0x37, 0x00 }, /* SetUsbInit */
2404 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
2405 /* Enable both fields, YUV Input, disable defect comp (why?) */
2406 { 0x20, 0x0c },
2407 { 0x21, 0x38 },
2408 { 0x22, 0x1d },
2409 { 0x17, 0x50 }, /* undocumented */
2410 { 0x37, 0x00 }, /* undocumented */
2411 { 0x40, 0xff }, /* I2C timeout counter */
2412 { 0x46, 0x00 }, /* I2C clock prescaler */
2413 { 0x59, 0x04 }, /* new from windrv 090403 */
2414 { 0xff, 0x00 }, /* undocumented */
2415 /* windows reads 0x55 at this point, why? */
2416 };
2417
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002418 static const struct ov_regvals mode_init_519[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002419 { 0x5d, 0x03 }, /* Turn off suspend mode */
2420 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
2421 { 0x54, 0x0f }, /* bit2 (jpeg enable) */
2422 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
2423 { 0xa3, 0x18 },
2424 { 0xa4, 0x04 },
2425 { 0xa5, 0x28 },
2426 { 0x37, 0x00 }, /* SetUsbInit */
2427 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
2428 /* Enable both fields, YUV Input, disable defect comp (why?) */
2429 { 0x22, 0x1d },
2430 { 0x17, 0x50 }, /* undocumented */
2431 { 0x37, 0x00 }, /* undocumented */
2432 { 0x40, 0xff }, /* I2C timeout counter */
2433 { 0x46, 0x00 }, /* I2C clock prescaler */
2434 { 0x59, 0x04 }, /* new from windrv 090403 */
2435 { 0xff, 0x00 }, /* undocumented */
2436 /* windows reads 0x55 at this point, why? */
2437 };
2438
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002439 /******** Set the mode ********/
2440 if (sd->sensor != SEN_OV7670) {
2441 if (write_regvals(sd, mode_init_519,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002442 ARRAY_SIZE(mode_init_519)))
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002443 return -EIO;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002444 if (sd->sensor == SEN_OV7640) {
2445 /* Select 8-bit input mode */
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002446 reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10);
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002447 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002448 } else {
2449 if (write_regvals(sd, mode_init_519_ov7670,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002450 ARRAY_SIZE(mode_init_519_ov7670)))
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002451 return -EIO;
2452 }
2453
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002454 reg_w(sd, OV519_R10_H_SIZE, sd->gspca_dev.width >> 4);
2455 reg_w(sd, OV519_R11_V_SIZE, sd->gspca_dev.height >> 3);
Hans de Goede80142ef2009-06-14 06:26:49 -03002456 if (sd->sensor == SEN_OV7670 &&
2457 sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
2458 reg_w(sd, OV519_R12_X_OFFSETL, 0x04);
2459 else
2460 reg_w(sd, OV519_R12_X_OFFSETL, 0x00);
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002461 reg_w(sd, OV519_R13_X_OFFSETH, 0x00);
2462 reg_w(sd, OV519_R14_Y_OFFSETL, 0x00);
2463 reg_w(sd, OV519_R15_Y_OFFSETH, 0x00);
2464 reg_w(sd, OV519_R16_DIVIDER, 0x00);
2465 reg_w(sd, OV519_R25_FORMAT, 0x03); /* YUV422 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002466 reg_w(sd, 0x26, 0x00); /* Undocumented */
2467
2468 /******** Set the framerate ********/
2469 if (frame_rate > 0)
2470 sd->frame_rate = frame_rate;
2471
2472/* FIXME: These are only valid at the max resolution. */
2473 sd->clockdiv = 0;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002474 switch (sd->sensor) {
2475 case SEN_OV7640:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002476 switch (sd->frame_rate) {
Jean-Francois Moine53e74512008-11-08 06:10:19 -03002477 default:
2478/* case 30: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002479 reg_w(sd, 0xa4, 0x0c);
2480 reg_w(sd, 0x23, 0xff);
2481 break;
2482 case 25:
2483 reg_w(sd, 0xa4, 0x0c);
2484 reg_w(sd, 0x23, 0x1f);
2485 break;
2486 case 20:
2487 reg_w(sd, 0xa4, 0x0c);
2488 reg_w(sd, 0x23, 0x1b);
2489 break;
Jean-Francois Moine53e74512008-11-08 06:10:19 -03002490 case 15:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002491 reg_w(sd, 0xa4, 0x04);
2492 reg_w(sd, 0x23, 0xff);
2493 sd->clockdiv = 1;
2494 break;
2495 case 10:
2496 reg_w(sd, 0xa4, 0x04);
2497 reg_w(sd, 0x23, 0x1f);
2498 sd->clockdiv = 1;
2499 break;
2500 case 5:
2501 reg_w(sd, 0xa4, 0x04);
2502 reg_w(sd, 0x23, 0x1b);
2503 sd->clockdiv = 1;
2504 break;
2505 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002506 break;
2507 case SEN_OV8610:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002508 switch (sd->frame_rate) {
2509 default: /* 15 fps */
2510/* case 15: */
2511 reg_w(sd, 0xa4, 0x06);
2512 reg_w(sd, 0x23, 0xff);
2513 break;
2514 case 10:
2515 reg_w(sd, 0xa4, 0x06);
2516 reg_w(sd, 0x23, 0x1f);
2517 break;
2518 case 5:
2519 reg_w(sd, 0xa4, 0x06);
2520 reg_w(sd, 0x23, 0x1b);
2521 break;
2522 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002523 break;
2524 case SEN_OV7670: /* guesses, based on 7640 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002525 PDEBUG(D_STREAM, "Setting framerate to %d fps",
2526 (sd->frame_rate == 0) ? 15 : sd->frame_rate);
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002527 reg_w(sd, 0xa4, 0x10);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002528 switch (sd->frame_rate) {
2529 case 30:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002530 reg_w(sd, 0x23, 0xff);
2531 break;
2532 case 20:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002533 reg_w(sd, 0x23, 0x1b);
2534 break;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002535 default:
2536/* case 15: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002537 reg_w(sd, 0x23, 0xff);
2538 sd->clockdiv = 1;
2539 break;
2540 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002541 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002542 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002543 return 0;
2544}
2545
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002546static int mode_init_ov_sensor_regs(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002547{
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002548 struct gspca_dev *gspca_dev;
2549 int qvga;
2550
2551 gspca_dev = &sd->gspca_dev;
Hans de Goede124cc9c2009-06-14 05:48:00 -03002552 qvga = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002553
2554 /******** Mode (VGA/QVGA) and sensor specific regs ********/
2555 switch (sd->sensor) {
2556 case SEN_OV8610:
2557 /* For OV8610 qvga means qsvga */
2558 i2c_w_mask(sd, OV7610_REG_COM_C, qvga ? (1 << 5) : 0, 1 << 5);
2559 break;
2560 case SEN_OV7610:
2561 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
2562 break;
2563 case SEN_OV7620:
Hans de Goedeb282d872009-06-14 19:10:40 -03002564 case SEN_OV76BE:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002565 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
2566 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
2567 i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
2568 i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
2569 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
Hans de Goedeb282d872009-06-14 19:10:40 -03002570 i2c_w_mask(sd, 0x67, qvga ? 0xb0 : 0x90, 0xf0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002571 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
2572 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002573 case SEN_OV7640:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002574 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
2575 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
2576/* i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a); */
2577/* i2c_w(sd, 0x25, qvga ? 0x30 : 0x60); */
2578/* i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40); */
2579/* i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0); */
2580/* i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20); */
2581 break;
2582 case SEN_OV7670:
2583 /* set COM7_FMT_VGA or COM7_FMT_QVGA
2584 * do we need to set anything else?
2585 * HSTART etc are set in set_ov_sensor_window itself */
2586 i2c_w_mask(sd, OV7670_REG_COM7,
2587 qvga ? OV7670_COM7_FMT_QVGA : OV7670_COM7_FMT_VGA,
2588 OV7670_COM7_FMT_MASK);
2589 break;
2590 case SEN_OV6620:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002591 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03002592 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002593 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
2594 break;
2595 default:
2596 return -EINVAL;
2597 }
2598
2599 /******** Palette-specific regs ********/
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002600 if (sd->sensor == SEN_OV7610 || sd->sensor == SEN_OV76BE) {
2601 /* not valid on the OV6620/OV7620/6630? */
2602 i2c_w_mask(sd, 0x0e, 0x00, 0x40);
2603 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002604
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002605 /* The OV518 needs special treatment. Although both the OV518
2606 * and the OV6630 support a 16-bit video bus, only the 8 bit Y
2607 * bus is actually used. The UV bus is tied to ground.
2608 * Therefore, the OV6630 needs to be in 8-bit multiplexed
2609 * output mode */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002610
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002611 /* OV7640 is 8-bit only */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002612
Hans de Goede7d971372009-06-14 05:28:17 -03002613 if (sd->sensor != SEN_OV6630 && sd->sensor != SEN_OV66308AF &&
2614 sd->sensor != SEN_OV7640)
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002615 i2c_w_mask(sd, 0x13, 0x00, 0x20);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002616
2617 /******** Clock programming ********/
2618 /* The OV6620 needs special handling. This prevents the
2619 * severe banding that normally occurs */
2620 if (sd->sensor == SEN_OV6620) {
2621
2622 /* Clock down */
2623 i2c_w(sd, 0x2a, 0x04);
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002624 i2c_w(sd, 0x11, sd->clockdiv);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002625 i2c_w(sd, 0x2a, 0x84);
2626 /* This next setting is critical. It seems to improve
2627 * the gain or the contrast. The "reserved" bits seem
2628 * to have some effect in this case. */
2629 i2c_w(sd, 0x2d, 0x85);
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002630 } else {
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002631 i2c_w(sd, 0x11, sd->clockdiv);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002632 }
2633
2634 /******** Special Features ********/
2635/* no evidence this is possible with OV7670, either */
2636 /* Test Pattern */
2637 if (sd->sensor != SEN_OV7640 && sd->sensor != SEN_OV7670)
2638 i2c_w_mask(sd, 0x12, 0x00, 0x02);
2639
2640 /* Enable auto white balance */
2641 if (sd->sensor == SEN_OV7670)
2642 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_AWB,
2643 OV7670_COM8_AWB);
2644 else
2645 i2c_w_mask(sd, 0x12, 0x04, 0x04);
2646
2647 /* This will go away as soon as ov51x_mode_init_sensor_regs() */
2648 /* is fully tested. */
2649 /* 7620/6620/6630? don't have register 0x35, so play it safe */
2650 if (sd->sensor == SEN_OV7610 || sd->sensor == SEN_OV76BE) {
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002651 if (!qvga)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002652 i2c_w(sd, 0x35, 0x9e);
2653 else
2654 i2c_w(sd, 0x35, 0x1e);
2655 }
2656 return 0;
2657}
2658
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002659static void sethvflip(struct sd *sd)
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03002660{
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002661 if (sd->sensor != SEN_OV7670)
2662 return;
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03002663 if (sd->gspca_dev.streaming)
2664 ov51x_stop(sd);
2665 i2c_w_mask(sd, OV7670_REG_MVFP,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002666 OV7670_MVFP_MIRROR * sd->hflip
2667 | OV7670_MVFP_VFLIP * sd->vflip,
2668 OV7670_MVFP_MIRROR | OV7670_MVFP_VFLIP);
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03002669 if (sd->gspca_dev.streaming)
2670 ov51x_restart(sd);
2671}
2672
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002673static int set_ov_sensor_window(struct sd *sd)
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03002674{
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002675 struct gspca_dev *gspca_dev;
Hans de Goede124cc9c2009-06-14 05:48:00 -03002676 int qvga, crop;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002677 int hwsbase, hwebase, vwsbase, vwebase, hwscale, vwscale;
2678 int ret, hstart, hstop, vstop, vstart;
2679 __u8 v;
2680
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002681 gspca_dev = &sd->gspca_dev;
Hans de Goede124cc9c2009-06-14 05:48:00 -03002682 qvga = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 1;
2683 crop = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 2;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002684
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002685 /* The different sensor ICs handle setting up of window differently.
2686 * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!! */
2687 switch (sd->sensor) {
2688 case SEN_OV8610:
2689 hwsbase = 0x1e;
2690 hwebase = 0x1e;
2691 vwsbase = 0x02;
2692 vwebase = 0x02;
2693 break;
2694 case SEN_OV7610:
2695 case SEN_OV76BE:
2696 hwsbase = 0x38;
2697 hwebase = 0x3a;
2698 vwsbase = vwebase = 0x05;
2699 break;
2700 case SEN_OV6620:
2701 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03002702 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002703 hwsbase = 0x38;
2704 hwebase = 0x3a;
2705 vwsbase = 0x05;
2706 vwebase = 0x06;
Hans de Goede7d971372009-06-14 05:28:17 -03002707 if (sd->sensor == SEN_OV66308AF && qvga)
Hans de Goede49809d62009-06-07 12:10:39 -03002708 /* HDG: this fixes U and V getting swapped */
Hans de Goede7d971372009-06-14 05:28:17 -03002709 hwsbase++;
Hans de Goede124cc9c2009-06-14 05:48:00 -03002710 if (crop) {
2711 hwsbase += 8;
2712 hwebase += 8;
2713 vwsbase += 11;
2714 vwebase += 11;
2715 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002716 break;
2717 case SEN_OV7620:
2718 hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */
2719 hwebase = 0x2f;
2720 vwsbase = vwebase = 0x05;
2721 break;
2722 case SEN_OV7640:
2723 hwsbase = 0x1a;
2724 hwebase = 0x1a;
2725 vwsbase = vwebase = 0x03;
2726 break;
2727 case SEN_OV7670:
2728 /*handling of OV7670 hardware sensor start and stop values
2729 * is very odd, compared to the other OV sensors */
2730 vwsbase = vwebase = hwebase = hwsbase = 0x00;
2731 break;
2732 default:
2733 return -EINVAL;
2734 }
2735
2736 switch (sd->sensor) {
2737 case SEN_OV6620:
2738 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03002739 case SEN_OV66308AF:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002740 if (qvga) { /* QCIF */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002741 hwscale = 0;
2742 vwscale = 0;
2743 } else { /* CIF */
2744 hwscale = 1;
2745 vwscale = 1; /* The datasheet says 0;
2746 * it's wrong */
2747 }
2748 break;
2749 case SEN_OV8610:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002750 if (qvga) { /* QSVGA */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002751 hwscale = 1;
2752 vwscale = 1;
2753 } else { /* SVGA */
2754 hwscale = 2;
2755 vwscale = 2;
2756 }
2757 break;
2758 default: /* SEN_OV7xx0 */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002759 if (qvga) { /* QVGA */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002760 hwscale = 1;
2761 vwscale = 0;
2762 } else { /* VGA */
2763 hwscale = 2;
2764 vwscale = 1;
2765 }
2766 }
2767
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002768 ret = mode_init_ov_sensor_regs(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002769 if (ret < 0)
2770 return ret;
2771
2772 if (sd->sensor == SEN_OV8610) {
2773 i2c_w_mask(sd, 0x2d, 0x05, 0x40);
2774 /* old 0x95, new 0x05 from windrv 090403 */
2775 /* bits 5-7: reserved */
2776 i2c_w_mask(sd, 0x28, 0x20, 0x20);
2777 /* bit 5: progressive mode on */
2778 }
2779
2780 /* The below is wrong for OV7670s because their window registers
2781 * only store the high bits in 0x17 to 0x1a */
2782
2783 /* SRH Use sd->max values instead of requested win values */
2784 /* SCS Since we're sticking with only the max hardware widths
2785 * for a given mode */
2786 /* I can hard code this for OV7670s */
2787 /* Yes, these numbers do look odd, but they're tested and work! */
2788 if (sd->sensor == SEN_OV7670) {
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002789 if (qvga) { /* QVGA from ov7670.c by
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002790 * Jonathan Corbet */
2791 hstart = 164;
Hans de Goede80142ef2009-06-14 06:26:49 -03002792 hstop = 28;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002793 vstart = 14;
2794 vstop = 494;
2795 } else { /* VGA */
2796 hstart = 158;
2797 hstop = 14;
2798 vstart = 10;
2799 vstop = 490;
2800 }
2801 /* OV7670 hardware window registers are split across
2802 * multiple locations */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002803 i2c_w(sd, OV7670_REG_HSTART, hstart >> 3);
2804 i2c_w(sd, OV7670_REG_HSTOP, hstop >> 3);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002805 v = i2c_r(sd, OV7670_REG_HREF);
2806 v = (v & 0xc0) | ((hstop & 0x7) << 3) | (hstart & 0x07);
2807 msleep(10); /* need to sleep between read and write to
2808 * same reg! */
2809 i2c_w(sd, OV7670_REG_HREF, v);
2810
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002811 i2c_w(sd, OV7670_REG_VSTART, vstart >> 2);
2812 i2c_w(sd, OV7670_REG_VSTOP, vstop >> 2);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002813 v = i2c_r(sd, OV7670_REG_VREF);
2814 v = (v & 0xc0) | ((vstop & 0x3) << 2) | (vstart & 0x03);
2815 msleep(10); /* need to sleep between read and write to
2816 * same reg! */
2817 i2c_w(sd, OV7670_REG_VREF, v);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002818 } else {
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002819 i2c_w(sd, 0x17, hwsbase);
2820 i2c_w(sd, 0x18, hwebase + (sd->gspca_dev.width >> hwscale));
2821 i2c_w(sd, 0x19, vwsbase);
2822 i2c_w(sd, 0x1a, vwebase + (sd->gspca_dev.height >> vwscale));
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002823 }
2824 return 0;
2825}
2826
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002827/* -- start the camera -- */
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03002828static int sd_start(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002829{
2830 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede49809d62009-06-07 12:10:39 -03002831 int ret = 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002832
Hans de Goede49809d62009-06-07 12:10:39 -03002833 switch (sd->bridge) {
Hans de Goede1876bb92009-06-14 06:45:50 -03002834 case BRIDGE_OV511:
2835 case BRIDGE_OV511PLUS:
2836 ret = ov511_mode_init_regs(sd);
2837 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002838 case BRIDGE_OV518:
2839 case BRIDGE_OV518PLUS:
2840 ret = ov518_mode_init_regs(sd);
2841 break;
2842 case BRIDGE_OV519:
2843 ret = ov519_mode_init_regs(sd);
2844 break;
2845 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002846 if (ret < 0)
2847 goto out;
Hans de Goede49809d62009-06-07 12:10:39 -03002848
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002849 ret = set_ov_sensor_window(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002850 if (ret < 0)
2851 goto out;
2852
Hans de Goede49809d62009-06-07 12:10:39 -03002853 setcontrast(gspca_dev);
2854 setbrightness(gspca_dev);
2855 setcolors(gspca_dev);
Hans de Goede02ab18b2009-06-14 04:32:04 -03002856 sethvflip(sd);
2857 setautobrightness(sd);
2858 setfreq(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03002859
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002860 ret = ov51x_restart(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002861 if (ret < 0)
2862 goto out;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002863 ov51x_led_control(sd, 1);
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03002864 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002865out:
2866 PDEBUG(D_ERR, "camera start error:%d", ret);
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03002867 return ret;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002868}
2869
2870static void sd_stopN(struct gspca_dev *gspca_dev)
2871{
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002872 struct sd *sd = (struct sd *) gspca_dev;
2873
2874 ov51x_stop(sd);
2875 ov51x_led_control(sd, 0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002876}
2877
Hans de Goede1876bb92009-06-14 06:45:50 -03002878static void ov511_pkt_scan(struct gspca_dev *gspca_dev,
2879 struct gspca_frame *frame, /* target */
2880 __u8 *in, /* isoc packet */
2881 int len) /* iso packet length */
2882{
2883 struct sd *sd = (struct sd *) gspca_dev;
2884
2885 /* SOF/EOF packets have 1st to 8th bytes zeroed and the 9th
2886 * byte non-zero. The EOF packet has image width/height in the
2887 * 10th and 11th bytes. The 9th byte is given as follows:
2888 *
2889 * bit 7: EOF
2890 * 6: compression enabled
2891 * 5: 422/420/400 modes
2892 * 4: 422/420/400 modes
2893 * 3: 1
2894 * 2: snapshot button on
2895 * 1: snapshot frame
2896 * 0: even/odd field
2897 */
2898 if (!(in[0] | in[1] | in[2] | in[3] | in[4] | in[5] | in[6] | in[7]) &&
2899 (in[8] & 0x08)) {
2900 if (in[8] & 0x80) {
2901 /* Frame end */
2902 if ((in[9] + 1) * 8 != gspca_dev->width ||
2903 (in[10] + 1) * 8 != gspca_dev->height) {
2904 PDEBUG(D_ERR, "Invalid frame size, got: %dx%d,"
2905 " requested: %dx%d\n",
2906 (in[9] + 1) * 8, (in[10] + 1) * 8,
2907 gspca_dev->width, gspca_dev->height);
2908 gspca_dev->last_packet_type = DISCARD_PACKET;
2909 return;
2910 }
2911 /* Add 11 byte footer to frame, might be usefull */
2912 gspca_frame_add(gspca_dev, LAST_PACKET, frame, in, 11);
2913 return;
2914 } else {
2915 /* Frame start */
2916 gspca_frame_add(gspca_dev, FIRST_PACKET, frame, in, 0);
2917 sd->packet_nr = 0;
2918 }
2919 }
2920
2921 /* Ignore the packet number */
2922 len--;
2923
2924 /* intermediate packet */
2925 gspca_frame_add(gspca_dev, INTER_PACKET, frame, in, len);
2926}
2927
Hans de Goede49809d62009-06-07 12:10:39 -03002928static void ov518_pkt_scan(struct gspca_dev *gspca_dev,
2929 struct gspca_frame *frame, /* target */
2930 __u8 *data, /* isoc packet */
2931 int len) /* iso packet length */
2932{
Hans de Goede92918a52009-06-14 06:21:35 -03002933 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede49809d62009-06-07 12:10:39 -03002934
2935 /* A false positive here is likely, until OVT gives me
2936 * the definitive SOF/EOF format */
2937 if ((!(data[0] | data[1] | data[2] | data[3] | data[5])) && data[6]) {
2938 gspca_frame_add(gspca_dev, LAST_PACKET, frame, data, 0);
2939 gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, 0);
Hans de Goede92918a52009-06-14 06:21:35 -03002940 sd->packet_nr = 0;
2941 }
2942
2943 if (gspca_dev->last_packet_type == DISCARD_PACKET)
2944 return;
2945
2946 /* Does this device use packet numbers ? */
2947 if (len & 7) {
2948 len--;
2949 if (sd->packet_nr == data[len])
2950 sd->packet_nr++;
2951 /* The last few packets of the frame (which are all 0's
2952 except that they may contain part of the footer), are
2953 numbered 0 */
2954 else if (sd->packet_nr == 0 || data[len]) {
2955 PDEBUG(D_ERR, "Invalid packet nr: %d (expect: %d)",
2956 (int)data[len], (int)sd->packet_nr);
2957 gspca_dev->last_packet_type = DISCARD_PACKET;
2958 return;
2959 }
Hans de Goede49809d62009-06-07 12:10:39 -03002960 }
2961
2962 /* intermediate packet */
2963 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
2964}
2965
2966static void ov519_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002967 struct gspca_frame *frame, /* target */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002968 __u8 *data, /* isoc packet */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002969 int len) /* iso packet length */
2970{
2971 /* Header of ov519 is 16 bytes:
2972 * Byte Value Description
2973 * 0 0xff magic
2974 * 1 0xff magic
2975 * 2 0xff magic
2976 * 3 0xXX 0x50 = SOF, 0x51 = EOF
2977 * 9 0xXX 0x01 initial frame without data,
2978 * 0x00 standard frame with image
2979 * 14 Lo in EOF: length of image data / 8
2980 * 15 Hi
2981 */
2982
2983 if (data[0] == 0xff && data[1] == 0xff && data[2] == 0xff) {
2984 switch (data[3]) {
2985 case 0x50: /* start of frame */
2986#define HDRSZ 16
2987 data += HDRSZ;
2988 len -= HDRSZ;
2989#undef HDRSZ
2990 if (data[0] == 0xff || data[1] == 0xd8)
2991 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
2992 data, len);
2993 else
2994 gspca_dev->last_packet_type = DISCARD_PACKET;
2995 return;
2996 case 0x51: /* end of frame */
2997 if (data[9] != 0)
2998 gspca_dev->last_packet_type = DISCARD_PACKET;
2999 gspca_frame_add(gspca_dev, LAST_PACKET, frame,
3000 data, 0);
3001 return;
3002 }
3003 }
3004
3005 /* intermediate packet */
3006 gspca_frame_add(gspca_dev, INTER_PACKET, frame,
3007 data, len);
3008}
3009
Hans de Goede49809d62009-06-07 12:10:39 -03003010static void sd_pkt_scan(struct gspca_dev *gspca_dev,
3011 struct gspca_frame *frame, /* target */
3012 __u8 *data, /* isoc packet */
3013 int len) /* iso packet length */
3014{
3015 struct sd *sd = (struct sd *) gspca_dev;
3016
3017 switch (sd->bridge) {
3018 case BRIDGE_OV511:
3019 case BRIDGE_OV511PLUS:
Hans de Goede1876bb92009-06-14 06:45:50 -03003020 ov511_pkt_scan(gspca_dev, frame, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03003021 break;
3022 case BRIDGE_OV518:
3023 case BRIDGE_OV518PLUS:
3024 ov518_pkt_scan(gspca_dev, frame, data, len);
3025 break;
3026 case BRIDGE_OV519:
3027 ov519_pkt_scan(gspca_dev, frame, data, len);
3028 break;
3029 }
3030}
3031
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003032/* -- management routines -- */
3033
3034static void setbrightness(struct gspca_dev *gspca_dev)
3035{
3036 struct sd *sd = (struct sd *) gspca_dev;
3037 int val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003038
3039 val = sd->brightness;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003040 switch (sd->sensor) {
3041 case SEN_OV8610:
3042 case SEN_OV7610:
3043 case SEN_OV76BE:
3044 case SEN_OV6620:
3045 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03003046 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003047 case SEN_OV7640:
3048 i2c_w(sd, OV7610_REG_BRT, val);
3049 break;
3050 case SEN_OV7620:
3051 /* 7620 doesn't like manual changes when in auto mode */
Hans de Goede02ab18b2009-06-14 04:32:04 -03003052 if (!sd->autobrightness)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003053 i2c_w(sd, OV7610_REG_BRT, val);
3054 break;
3055 case SEN_OV7670:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003056/*win trace
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003057 * i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_AEC); */
3058 i2c_w(sd, OV7670_REG_BRIGHT, ov7670_abs_to_sm(val));
3059 break;
3060 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003061}
3062
3063static void setcontrast(struct gspca_dev *gspca_dev)
3064{
3065 struct sd *sd = (struct sd *) gspca_dev;
3066 int val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003067
3068 val = sd->contrast;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003069 switch (sd->sensor) {
3070 case SEN_OV7610:
3071 case SEN_OV6620:
3072 i2c_w(sd, OV7610_REG_CNT, val);
3073 break;
3074 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03003075 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003076 i2c_w_mask(sd, OV7610_REG_CNT, val >> 4, 0x0f);
Hans de Goede49809d62009-06-07 12:10:39 -03003077 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003078 case SEN_OV8610: {
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03003079 static const __u8 ctab[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003080 0x03, 0x09, 0x0b, 0x0f, 0x53, 0x6f, 0x35, 0x7f
3081 };
3082
3083 /* Use Y gamma control instead. Bit 0 enables it. */
3084 i2c_w(sd, 0x64, ctab[val >> 5]);
3085 break;
3086 }
3087 case SEN_OV7620: {
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03003088 static const __u8 ctab[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003089 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
3090 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
3091 };
3092
3093 /* Use Y gamma control instead. Bit 0 enables it. */
3094 i2c_w(sd, 0x64, ctab[val >> 4]);
3095 break;
3096 }
3097 case SEN_OV7640:
3098 /* Use gain control instead. */
3099 i2c_w(sd, OV7610_REG_GAIN, val >> 2);
3100 break;
3101 case SEN_OV7670:
3102 /* check that this isn't just the same as ov7610 */
3103 i2c_w(sd, OV7670_REG_CONTRAS, val >> 1);
3104 break;
3105 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003106}
3107
3108static void setcolors(struct gspca_dev *gspca_dev)
3109{
3110 struct sd *sd = (struct sd *) gspca_dev;
3111 int val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003112
3113 val = sd->colors;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003114 switch (sd->sensor) {
3115 case SEN_OV8610:
3116 case SEN_OV7610:
3117 case SEN_OV76BE:
3118 case SEN_OV6620:
3119 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03003120 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003121 i2c_w(sd, OV7610_REG_SAT, val);
3122 break;
3123 case SEN_OV7620:
3124 /* Use UV gamma control instead. Bits 0 & 7 are reserved. */
3125/* rc = ov_i2c_write(sd->dev, 0x62, (val >> 9) & 0x7e);
3126 if (rc < 0)
3127 goto out; */
3128 i2c_w(sd, OV7610_REG_SAT, val);
3129 break;
3130 case SEN_OV7640:
3131 i2c_w(sd, OV7610_REG_SAT, val & 0xf0);
3132 break;
3133 case SEN_OV7670:
3134 /* supported later once I work out how to do it
3135 * transparently fail now! */
3136 /* set REG_COM13 values for UV sat auto mode */
3137 break;
3138 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003139}
3140
Hans de Goede02ab18b2009-06-14 04:32:04 -03003141static void setautobrightness(struct sd *sd)
3142{
3143 if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7670)
3144 return;
3145
3146 i2c_w_mask(sd, 0x2d, sd->autobrightness ? 0x10 : 0x00, 0x10);
3147}
3148
3149static void setfreq(struct sd *sd)
3150{
3151 if (sd->sensor == SEN_OV7670) {
3152 switch (sd->freq) {
3153 case 0: /* Banding filter disabled */
3154 i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_BFILT);
3155 break;
3156 case 1: /* 50 hz */
3157 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT,
3158 OV7670_COM8_BFILT);
3159 i2c_w_mask(sd, OV7670_REG_COM11, 0x08, 0x18);
3160 break;
3161 case 2: /* 60 hz */
3162 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT,
3163 OV7670_COM8_BFILT);
3164 i2c_w_mask(sd, OV7670_REG_COM11, 0x00, 0x18);
3165 break;
3166 case 3: /* Auto hz */
3167 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT,
3168 OV7670_COM8_BFILT);
3169 i2c_w_mask(sd, OV7670_REG_COM11, OV7670_COM11_HZAUTO,
3170 0x18);
3171 break;
3172 }
3173 } else {
3174 switch (sd->freq) {
3175 case 0: /* Banding filter disabled */
3176 i2c_w_mask(sd, 0x2d, 0x00, 0x04);
3177 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
3178 break;
3179 case 1: /* 50 hz (filter on and framerate adj) */
3180 i2c_w_mask(sd, 0x2d, 0x04, 0x04);
3181 i2c_w_mask(sd, 0x2a, 0x80, 0x80);
3182 /* 20 fps -> 16.667 fps */
3183 if (sd->sensor == SEN_OV6620 ||
Hans de Goede7d971372009-06-14 05:28:17 -03003184 sd->sensor == SEN_OV6630 ||
3185 sd->sensor == SEN_OV66308AF)
Hans de Goede02ab18b2009-06-14 04:32:04 -03003186 i2c_w(sd, 0x2b, 0x5e);
3187 else
3188 i2c_w(sd, 0x2b, 0xac);
3189 break;
3190 case 2: /* 60 hz (filter on, ...) */
3191 i2c_w_mask(sd, 0x2d, 0x04, 0x04);
3192 if (sd->sensor == SEN_OV6620 ||
Hans de Goede7d971372009-06-14 05:28:17 -03003193 sd->sensor == SEN_OV6630 ||
3194 sd->sensor == SEN_OV66308AF) {
Hans de Goede02ab18b2009-06-14 04:32:04 -03003195 /* 20 fps -> 15 fps */
3196 i2c_w_mask(sd, 0x2a, 0x80, 0x80);
3197 i2c_w(sd, 0x2b, 0xa8);
3198 } else {
3199 /* no framerate adj. */
3200 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
3201 }
3202 break;
3203 }
3204 }
3205}
3206
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003207static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
3208{
3209 struct sd *sd = (struct sd *) gspca_dev;
3210
3211 sd->brightness = val;
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003212 if (gspca_dev->streaming)
3213 setbrightness(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003214 return 0;
3215}
3216
3217static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
3218{
3219 struct sd *sd = (struct sd *) gspca_dev;
3220
3221 *val = sd->brightness;
3222 return 0;
3223}
3224
3225static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
3226{
3227 struct sd *sd = (struct sd *) gspca_dev;
3228
3229 sd->contrast = val;
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003230 if (gspca_dev->streaming)
3231 setcontrast(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003232 return 0;
3233}
3234
3235static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
3236{
3237 struct sd *sd = (struct sd *) gspca_dev;
3238
3239 *val = sd->contrast;
3240 return 0;
3241}
3242
3243static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
3244{
3245 struct sd *sd = (struct sd *) gspca_dev;
3246
3247 sd->colors = val;
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003248 if (gspca_dev->streaming)
3249 setcolors(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003250 return 0;
3251}
3252
3253static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
3254{
3255 struct sd *sd = (struct sd *) gspca_dev;
3256
3257 *val = sd->colors;
3258 return 0;
3259}
3260
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003261static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
3262{
3263 struct sd *sd = (struct sd *) gspca_dev;
3264
3265 sd->hflip = val;
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003266 if (gspca_dev->streaming)
3267 sethvflip(sd);
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003268 return 0;
3269}
3270
3271static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
3272{
3273 struct sd *sd = (struct sd *) gspca_dev;
3274
3275 *val = sd->hflip;
3276 return 0;
3277}
3278
3279static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
3280{
3281 struct sd *sd = (struct sd *) gspca_dev;
3282
3283 sd->vflip = val;
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003284 if (gspca_dev->streaming)
3285 sethvflip(sd);
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003286 return 0;
3287}
3288
3289static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
3290{
3291 struct sd *sd = (struct sd *) gspca_dev;
3292
3293 *val = sd->vflip;
3294 return 0;
3295}
3296
Hans de Goede02ab18b2009-06-14 04:32:04 -03003297static int sd_setautobrightness(struct gspca_dev *gspca_dev, __s32 val)
3298{
3299 struct sd *sd = (struct sd *) gspca_dev;
3300
3301 sd->autobrightness = val;
3302 if (gspca_dev->streaming)
3303 setautobrightness(sd);
3304 return 0;
3305}
3306
3307static int sd_getautobrightness(struct gspca_dev *gspca_dev, __s32 *val)
3308{
3309 struct sd *sd = (struct sd *) gspca_dev;
3310
3311 *val = sd->autobrightness;
3312 return 0;
3313}
3314
3315static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
3316{
3317 struct sd *sd = (struct sd *) gspca_dev;
3318
3319 sd->freq = val;
3320 if (gspca_dev->streaming)
3321 setfreq(sd);
3322 return 0;
3323}
3324
3325static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
3326{
3327 struct sd *sd = (struct sd *) gspca_dev;
3328
3329 *val = sd->freq;
3330 return 0;
3331}
3332
3333static int sd_querymenu(struct gspca_dev *gspca_dev,
3334 struct v4l2_querymenu *menu)
3335{
3336 struct sd *sd = (struct sd *) gspca_dev;
3337
3338 switch (menu->id) {
3339 case V4L2_CID_POWER_LINE_FREQUENCY:
3340 switch (menu->index) {
3341 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
3342 strcpy((char *) menu->name, "NoFliker");
3343 return 0;
3344 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
3345 strcpy((char *) menu->name, "50 Hz");
3346 return 0;
3347 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
3348 strcpy((char *) menu->name, "60 Hz");
3349 return 0;
3350 case 3:
3351 if (sd->sensor != SEN_OV7670)
3352 return -EINVAL;
3353
3354 strcpy((char *) menu->name, "Automatic");
3355 return 0;
3356 }
3357 break;
3358 }
3359 return -EINVAL;
3360}
3361
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003362/* sub-driver description */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03003363static const struct sd_desc sd_desc = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003364 .name = MODULE_NAME,
3365 .ctrls = sd_ctrls,
3366 .nctrls = ARRAY_SIZE(sd_ctrls),
3367 .config = sd_config,
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03003368 .init = sd_init,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003369 .start = sd_start,
3370 .stopN = sd_stopN,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003371 .pkt_scan = sd_pkt_scan,
Hans de Goede02ab18b2009-06-14 04:32:04 -03003372 .querymenu = sd_querymenu,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003373};
3374
3375/* -- module initialisation -- */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03003376static const __devinitdata struct usb_device_id device_table[] = {
Hans de Goede49809d62009-06-07 12:10:39 -03003377 {USB_DEVICE(0x041e, 0x4052), .driver_info = BRIDGE_OV519 },
3378 {USB_DEVICE(0x041e, 0x405f), .driver_info = BRIDGE_OV519 },
3379 {USB_DEVICE(0x041e, 0x4060), .driver_info = BRIDGE_OV519 },
3380 {USB_DEVICE(0x041e, 0x4061), .driver_info = BRIDGE_OV519 },
Hans de Goede9e4d8252009-06-14 06:25:06 -03003381 {USB_DEVICE(0x041e, 0x4064),
3382 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
3383 {USB_DEVICE(0x041e, 0x4068),
3384 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
Hans de Goede49809d62009-06-07 12:10:39 -03003385 {USB_DEVICE(0x045e, 0x028c), .driver_info = BRIDGE_OV519 },
3386 {USB_DEVICE(0x054c, 0x0154), .driver_info = BRIDGE_OV519 },
3387 {USB_DEVICE(0x054c, 0x0155), .driver_info = BRIDGE_OV519 },
Hans de Goede1876bb92009-06-14 06:45:50 -03003388 {USB_DEVICE(0x05a9, 0x0511), .driver_info = BRIDGE_OV511 },
Hans de Goede49809d62009-06-07 12:10:39 -03003389 {USB_DEVICE(0x05a9, 0x0518), .driver_info = BRIDGE_OV518 },
3390 {USB_DEVICE(0x05a9, 0x0519), .driver_info = BRIDGE_OV519 },
3391 {USB_DEVICE(0x05a9, 0x0530), .driver_info = BRIDGE_OV519 },
3392 {USB_DEVICE(0x05a9, 0x4519), .driver_info = BRIDGE_OV519 },
3393 {USB_DEVICE(0x05a9, 0x8519), .driver_info = BRIDGE_OV519 },
Hans de Goede1876bb92009-06-14 06:45:50 -03003394 {USB_DEVICE(0x05a9, 0xa511), .driver_info = BRIDGE_OV511PLUS },
Hans de Goede49809d62009-06-07 12:10:39 -03003395 {USB_DEVICE(0x05a9, 0xa518), .driver_info = BRIDGE_OV518PLUS },
Hans de Goede1876bb92009-06-14 06:45:50 -03003396 {USB_DEVICE(0x0813, 0x0002), .driver_info = BRIDGE_OV511PLUS },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003397 {}
3398};
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003399
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003400MODULE_DEVICE_TABLE(usb, device_table);
3401
3402/* -- device connect -- */
3403static int sd_probe(struct usb_interface *intf,
3404 const struct usb_device_id *id)
3405{
3406 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
3407 THIS_MODULE);
3408}
3409
3410static struct usb_driver sd_driver = {
3411 .name = MODULE_NAME,
3412 .id_table = device_table,
3413 .probe = sd_probe,
3414 .disconnect = gspca_disconnect,
Jean-Francois Moine6a709742008-09-03 16:48:10 -03003415#ifdef CONFIG_PM
3416 .suspend = gspca_suspend,
3417 .resume = gspca_resume,
3418#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003419};
3420
3421/* -- module insert / remove -- */
3422static int __init sd_mod_init(void)
3423{
Alexey Klimovf69e9522009-01-01 13:02:07 -03003424 int ret;
3425 ret = usb_register(&sd_driver);
3426 if (ret < 0)
Alexey Klimove6b14842009-01-01 13:04:58 -03003427 return ret;
Jean-Francois Moine10b0e962008-07-22 05:35:10 -03003428 PDEBUG(D_PROBE, "registered");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003429 return 0;
3430}
3431static void __exit sd_mod_exit(void)
3432{
3433 usb_deregister(&sd_driver);
3434 PDEBUG(D_PROBE, "deregistered");
3435}
3436
3437module_init(sd_mod_init);
3438module_exit(sd_mod_exit);
3439
3440module_param(frame_rate, int, 0644);
3441MODULE_PARM_DESC(frame_rate, "Frame rate (5, 10, 15, 20 or 30 fps)");