blob: 08f07c3488d86ca4b63b2f9cd607771c357bf6cb [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)
Hans de Goedeb46aaa02009-10-12 10:07:57 -03005 * Copyright (C) 2009 Hans de Goede <hdegoede@redhat.com>
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03006 *
Romain Beauxis2961e8752008-12-05 06:25:26 -03007 * This module is adapted from the ov51x-jpeg package, which itself
8 * was adapted from the ov511 driver.
9 *
10 * Original copyright for the ov511 driver is:
11 *
Hans de Goedeb46aaa02009-10-12 10:07:57 -030012 * Copyright (c) 1999-2006 Mark W. McClelland
Romain Beauxis2961e8752008-12-05 06:25:26 -030013 * Support for OV519, OV8610 Copyright (c) 2003 Joerg Heckenbach
Hans de Goedeb46aaa02009-10-12 10:07:57 -030014 * Many improvements by Bret Wallach <bwallac1@san.rr.com>
15 * Color fixes by by Orion Sky Lawlor <olawlor@acm.org> (2/26/2000)
16 * OV7620 fixes by Charl P. Botha <cpbotha@ieee.org>
17 * Changes by Claudio Matsuoka <claudio@conectiva.com>
Romain Beauxis2961e8752008-12-05 06:25:26 -030018 *
19 * ov51x-jpeg original copyright is:
20 *
21 * Copyright (c) 2004-2007 Romain Beauxis <toots@rastageeks.org>
22 * Support for OV7670 sensors was contributed by Sam Skipsey <aoanla@yahoo.com>
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030023 *
24 * This program is free software; you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 2 of the License, or
27 * any later version.
28 *
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
33 *
34 * You should have received a copy of the GNU General Public License
35 * along with this program; if not, write to the Free Software
36 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37 *
38 */
39#define MODULE_NAME "ov519"
40
Hans de Goede417a4d22010-02-19 07:37:08 -030041#include <linux/input.h>
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030042#include "gspca.h"
43
Jean-François Moine9a731a32010-06-04 05:26:42 -030044/* The jpeg_hdr is used by w996Xcf only */
45/* The CONEX_CAM define for jpeg.h needs renaming, now its used here too */
46#define CONEX_CAM
47#include "jpeg.h"
48
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030049MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
50MODULE_DESCRIPTION("OV519 USB Camera Driver");
51MODULE_LICENSE("GPL");
52
53/* global parameters */
54static int frame_rate;
55
56/* Number of times to retry a failed I2C transaction. Increase this if you
57 * are getting "Failed to read sensor ID..." */
58static int i2c_detect_tries = 10;
59
Jean-François Moine62833ac2010-10-02 04:27:02 -030060/* controls */
61enum e_ctrl {
62 BRIGHTNESS,
63 CONTRAST,
64 COLORS,
65 HFLIP,
66 VFLIP,
67 AUTOBRIGHT,
68 FREQ,
69 NCTRL /* number of controls */
70};
71
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030072/* ov519 device descriptor */
73struct sd {
74 struct gspca_dev gspca_dev; /* !! must be the first item */
75
Jean-François Moine62833ac2010-10-02 04:27:02 -030076 struct gspca_ctrl ctrls[NCTRL];
77
Jean-François Moine9d1593a2010-11-11 08:04:06 -030078 u8 packet_nr;
Hans de Goede92918a52009-06-14 06:21:35 -030079
Hans de Goede49809d62009-06-07 12:10:39 -030080 char bridge;
81#define BRIDGE_OV511 0
82#define BRIDGE_OV511PLUS 1
83#define BRIDGE_OV518 2
84#define BRIDGE_OV518PLUS 3
85#define BRIDGE_OV519 4
Hans de Goede635118d2009-10-11 09:49:03 -030086#define BRIDGE_OVFX2 5
Hans de Goedea511ba92009-10-16 07:13:07 -030087#define BRIDGE_W9968CF 6
Hans de Goede9e4d8252009-06-14 06:25:06 -030088#define BRIDGE_MASK 7
89
90 char invert_led;
91#define BRIDGE_INVERT_LED 8
Hans de Goede49809d62009-06-07 12:10:39 -030092
Hans de Goede417a4d22010-02-19 07:37:08 -030093 char snapshot_pressed;
94 char snapshot_needs_reset;
95
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030096 /* Determined by sensor type */
Jean-François Moine9d1593a2010-11-11 08:04:06 -030097 u8 sif;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030098
Jean-François Moine9d1593a2010-11-11 08:04:06 -030099 u8 quality;
Hans de Goede79b35902009-10-19 06:08:01 -0300100#define QUALITY_MIN 50
101#define QUALITY_MAX 70
102#define QUALITY_DEF 50
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300103
Jean-François Moine9d1593a2010-11-11 08:04:06 -0300104 u8 stopped; /* Streaming is temporarily paused */
105 u8 first_frame;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300106
Jean-François Moine9d1593a2010-11-11 08:04:06 -0300107 u8 frame_rate; /* current Framerate */
108 u8 clockdiv; /* clockdiv override */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300109
Jean-François Moine7bbe6b82010-11-11 08:27:24 -0300110 s8 sensor; /* Type of image sensor chip (SEN_*) */
Hans de Goedea511ba92009-10-16 07:13:07 -0300111
112 u8 sensor_addr;
Jean-François Moined6fa6632010-11-11 08:05:50 -0300113 u16 sensor_width;
114 u16 sensor_height;
115 s16 sensor_reg_cache[256];
Hans de Goede79b35902009-10-19 06:08:01 -0300116
Jean-François Moine9a731a32010-06-04 05:26:42 -0300117 u8 jpeg_hdr[JPEG_HDR_SZ];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300118};
Jean-François Moine7bbe6b82010-11-11 08:27:24 -0300119enum sensors {
120 SEN_OV2610,
121 SEN_OV3610,
122 SEN_OV6620,
123 SEN_OV6630,
124 SEN_OV66308AF,
125 SEN_OV7610,
126 SEN_OV7620,
127 SEN_OV7620AE,
128 SEN_OV7640,
129 SEN_OV7648,
130 SEN_OV7670,
131 SEN_OV76BE,
132 SEN_OV8610,
133};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300134
Hans de Goedea511ba92009-10-16 07:13:07 -0300135/* Note this is a bit of a hack, but the w9968cf driver needs the code for all
136 the ov sensors which is already present here. When we have the time we
137 really should move the sensor drivers to v4l2 sub drivers. */
138#include "w996Xcf.c"
139
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300140/* V4L2 controls supported by the driver */
Hans de Goede49809d62009-06-07 12:10:39 -0300141static void setbrightness(struct gspca_dev *gspca_dev);
142static void setcontrast(struct gspca_dev *gspca_dev);
143static void setcolors(struct gspca_dev *gspca_dev);
Jean-François Moine62833ac2010-10-02 04:27:02 -0300144static void sethvflip(struct gspca_dev *gspca_dev);
145static void setautobright(struct gspca_dev *gspca_dev);
146static void setfreq(struct gspca_dev *gspca_dev);
147static void setfreq_i(struct sd *sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300148
Hans de Goede02ab18b2009-06-14 04:32:04 -0300149static const struct ctrl sd_ctrls[] = {
Jean-François Moine62833ac2010-10-02 04:27:02 -0300150[BRIGHTNESS] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300151 {
152 .id = V4L2_CID_BRIGHTNESS,
153 .type = V4L2_CTRL_TYPE_INTEGER,
154 .name = "Brightness",
155 .minimum = 0,
156 .maximum = 255,
157 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300158 .default_value = 127,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300159 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300160 .set_control = setbrightness,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300161 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300162[CONTRAST] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300163 {
164 .id = V4L2_CID_CONTRAST,
165 .type = V4L2_CTRL_TYPE_INTEGER,
166 .name = "Contrast",
167 .minimum = 0,
168 .maximum = 255,
169 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300170 .default_value = 127,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300171 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300172 .set_control = setcontrast,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300173 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300174[COLORS] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300175 {
176 .id = V4L2_CID_SATURATION,
177 .type = V4L2_CTRL_TYPE_INTEGER,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300178 .name = "Color",
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300179 .minimum = 0,
180 .maximum = 255,
181 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300182 .default_value = 127,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300183 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300184 .set_control = setcolors,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300185 },
Hans de Goede02ab18b2009-06-14 04:32:04 -0300186/* The flip controls work with ov7670 only */
Jean-François Moine62833ac2010-10-02 04:27:02 -0300187[HFLIP] = {
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300188 {
189 .id = V4L2_CID_HFLIP,
190 .type = V4L2_CTRL_TYPE_BOOLEAN,
191 .name = "Mirror",
192 .minimum = 0,
193 .maximum = 1,
194 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300195 .default_value = 0,
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300196 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300197 .set_control = sethvflip,
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300198 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300199[VFLIP] = {
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300200 {
201 .id = V4L2_CID_VFLIP,
202 .type = V4L2_CTRL_TYPE_BOOLEAN,
203 .name = "Vflip",
204 .minimum = 0,
205 .maximum = 1,
206 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300207 .default_value = 0,
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300208 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300209 .set_control = sethvflip,
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300210 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300211[AUTOBRIGHT] = {
Hans de Goede02ab18b2009-06-14 04:32:04 -0300212 {
213 .id = V4L2_CID_AUTOBRIGHTNESS,
214 .type = V4L2_CTRL_TYPE_BOOLEAN,
215 .name = "Auto Brightness",
216 .minimum = 0,
217 .maximum = 1,
218 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300219 .default_value = 1,
Hans de Goede02ab18b2009-06-14 04:32:04 -0300220 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300221 .set_control = setautobright,
Hans de Goede02ab18b2009-06-14 04:32:04 -0300222 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300223[FREQ] = {
Hans de Goede02ab18b2009-06-14 04:32:04 -0300224 {
225 .id = V4L2_CID_POWER_LINE_FREQUENCY,
226 .type = V4L2_CTRL_TYPE_MENU,
227 .name = "Light frequency filter",
228 .minimum = 0,
Jean-François Moine87bae742010-11-12 05:31:34 -0300229 .maximum = 2, /* 0: no flicker, 1: 50Hz, 2:60Hz, 3: auto */
Hans de Goede02ab18b2009-06-14 04:32:04 -0300230 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300231 .default_value = 0,
Hans de Goede02ab18b2009-06-14 04:32:04 -0300232 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300233 .set_control = setfreq,
Hans de Goede02ab18b2009-06-14 04:32:04 -0300234 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300235};
236
Jean-François Moine83db7682010-11-12 07:14:08 -0300237/* table of the disabled controls */
238static const unsigned ctrl_dis[] = {
239[SEN_OV2610] = (1 << NCTRL) - 1, /* no control */
240
241[SEN_OV3610] = (1 << NCTRL) - 1, /* no control */
242
243[SEN_OV6620] = (1 << HFLIP) |
244 (1 << VFLIP),
245
246[SEN_OV6630] = (1 << HFLIP) |
247 (1 << VFLIP),
248
249[SEN_OV66308AF] = (1 << HFLIP) |
250 (1 << VFLIP),
251
252[SEN_OV7610] = (1 << HFLIP) |
253 (1 << VFLIP),
254
255[SEN_OV7620] = (1 << HFLIP) |
256 (1 << VFLIP),
257
258[SEN_OV7620AE] = (1 << HFLIP) |
259 (1 << VFLIP),
260
261[SEN_OV7640] = (1 << HFLIP) |
262 (1 << VFLIP) |
263 (1 << AUTOBRIGHT) |
264 (1 << CONTRAST),
265
266[SEN_OV7648] = (1 << HFLIP) |
267 (1 << VFLIP) |
268 (1 << AUTOBRIGHT) |
269 (1 << CONTRAST),
270
271[SEN_OV7670] = (1 << COLORS) |
272 (1 << AUTOBRIGHT),
273
274[SEN_OV76BE] = (1 << HFLIP) |
275 (1 << VFLIP),
276
277[SEN_OV8610] = (1 << HFLIP) |
278 (1 << VFLIP) |
279 (1 << FREQ),
280};
281
Hans de Goede49809d62009-06-07 12:10:39 -0300282static const struct v4l2_pix_format ov519_vga_mode[] = {
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300283 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
284 .bytesperline = 320,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300285 .sizeimage = 320 * 240 * 3 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300286 .colorspace = V4L2_COLORSPACE_JPEG,
287 .priv = 1},
288 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
289 .bytesperline = 640,
290 .sizeimage = 640 * 480 * 3 / 8 + 590,
291 .colorspace = V4L2_COLORSPACE_JPEG,
292 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300293};
Hans de Goede49809d62009-06-07 12:10:39 -0300294static const struct v4l2_pix_format ov519_sif_mode[] = {
Hans de Goede124cc9c2009-06-14 05:48:00 -0300295 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
296 .bytesperline = 160,
297 .sizeimage = 160 * 120 * 3 / 8 + 590,
298 .colorspace = V4L2_COLORSPACE_JPEG,
299 .priv = 3},
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300300 {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
301 .bytesperline = 176,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300302 .sizeimage = 176 * 144 * 3 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300303 .colorspace = V4L2_COLORSPACE_JPEG,
304 .priv = 1},
Hans de Goede124cc9c2009-06-14 05:48:00 -0300305 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
306 .bytesperline = 320,
307 .sizeimage = 320 * 240 * 3 / 8 + 590,
308 .colorspace = V4L2_COLORSPACE_JPEG,
309 .priv = 2},
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300310 {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
311 .bytesperline = 352,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300312 .sizeimage = 352 * 288 * 3 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300313 .colorspace = V4L2_COLORSPACE_JPEG,
314 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300315};
316
Hans de Goedeb282d872009-06-14 19:10:40 -0300317/* Note some of the sizeimage values for the ov511 / ov518 may seem
318 larger then necessary, however they need to be this big as the ov511 /
319 ov518 always fills the entire isoc frame, using 0 padding bytes when
320 it doesn't have any data. So with low framerates the amount of data
321 transfered can become quite large (libv4l will remove all the 0 padding
322 in userspace). */
Hans de Goede49809d62009-06-07 12:10:39 -0300323static const struct v4l2_pix_format ov518_vga_mode[] = {
324 {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
325 .bytesperline = 320,
Hans de Goedeb282d872009-06-14 19:10:40 -0300326 .sizeimage = 320 * 240 * 3,
Hans de Goede49809d62009-06-07 12:10:39 -0300327 .colorspace = V4L2_COLORSPACE_JPEG,
328 .priv = 1},
329 {640, 480, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
330 .bytesperline = 640,
Hans de Goedeb282d872009-06-14 19:10:40 -0300331 .sizeimage = 640 * 480 * 2,
Hans de Goede49809d62009-06-07 12:10:39 -0300332 .colorspace = V4L2_COLORSPACE_JPEG,
333 .priv = 0},
334};
335static const struct v4l2_pix_format ov518_sif_mode[] = {
Hans de Goede124cc9c2009-06-14 05:48:00 -0300336 {160, 120, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
337 .bytesperline = 160,
Hans de Goedeb282d872009-06-14 19:10:40 -0300338 .sizeimage = 70000,
Hans de Goede124cc9c2009-06-14 05:48:00 -0300339 .colorspace = V4L2_COLORSPACE_JPEG,
340 .priv = 3},
Hans de Goede49809d62009-06-07 12:10:39 -0300341 {176, 144, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
342 .bytesperline = 176,
Hans de Goedeb282d872009-06-14 19:10:40 -0300343 .sizeimage = 70000,
Hans de Goede49809d62009-06-07 12:10:39 -0300344 .colorspace = V4L2_COLORSPACE_JPEG,
345 .priv = 1},
Hans de Goede124cc9c2009-06-14 05:48:00 -0300346 {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
347 .bytesperline = 320,
Hans de Goedeb282d872009-06-14 19:10:40 -0300348 .sizeimage = 320 * 240 * 3,
Hans de Goede124cc9c2009-06-14 05:48:00 -0300349 .colorspace = V4L2_COLORSPACE_JPEG,
350 .priv = 2},
Hans de Goede49809d62009-06-07 12:10:39 -0300351 {352, 288, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
352 .bytesperline = 352,
Hans de Goedeb282d872009-06-14 19:10:40 -0300353 .sizeimage = 352 * 288 * 3,
Hans de Goede49809d62009-06-07 12:10:39 -0300354 .colorspace = V4L2_COLORSPACE_JPEG,
355 .priv = 0},
356};
357
Hans de Goede1876bb92009-06-14 06:45:50 -0300358static const struct v4l2_pix_format ov511_vga_mode[] = {
359 {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
360 .bytesperline = 320,
361 .sizeimage = 320 * 240 * 3,
362 .colorspace = V4L2_COLORSPACE_JPEG,
363 .priv = 1},
364 {640, 480, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
365 .bytesperline = 640,
366 .sizeimage = 640 * 480 * 2,
367 .colorspace = V4L2_COLORSPACE_JPEG,
368 .priv = 0},
369};
370static const struct v4l2_pix_format ov511_sif_mode[] = {
371 {160, 120, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
372 .bytesperline = 160,
Hans de Goedeb282d872009-06-14 19:10:40 -0300373 .sizeimage = 70000,
Hans de Goede1876bb92009-06-14 06:45:50 -0300374 .colorspace = V4L2_COLORSPACE_JPEG,
375 .priv = 3},
376 {176, 144, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
377 .bytesperline = 176,
Hans de Goedeb282d872009-06-14 19:10:40 -0300378 .sizeimage = 70000,
Hans de Goede1876bb92009-06-14 06:45:50 -0300379 .colorspace = V4L2_COLORSPACE_JPEG,
380 .priv = 1},
381 {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
382 .bytesperline = 320,
383 .sizeimage = 320 * 240 * 3,
384 .colorspace = V4L2_COLORSPACE_JPEG,
385 .priv = 2},
386 {352, 288, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
387 .bytesperline = 352,
388 .sizeimage = 352 * 288 * 3,
389 .colorspace = V4L2_COLORSPACE_JPEG,
390 .priv = 0},
391};
Hans de Goede49809d62009-06-07 12:10:39 -0300392
Hans de Goede635118d2009-10-11 09:49:03 -0300393static const struct v4l2_pix_format ovfx2_vga_mode[] = {
394 {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
395 .bytesperline = 320,
396 .sizeimage = 320 * 240,
397 .colorspace = V4L2_COLORSPACE_SRGB,
398 .priv = 1},
399 {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
400 .bytesperline = 640,
401 .sizeimage = 640 * 480,
402 .colorspace = V4L2_COLORSPACE_SRGB,
403 .priv = 0},
404};
405static const struct v4l2_pix_format ovfx2_cif_mode[] = {
406 {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
407 .bytesperline = 160,
408 .sizeimage = 160 * 120,
409 .colorspace = V4L2_COLORSPACE_SRGB,
410 .priv = 3},
411 {176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
412 .bytesperline = 176,
413 .sizeimage = 176 * 144,
414 .colorspace = V4L2_COLORSPACE_SRGB,
415 .priv = 1},
416 {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
417 .bytesperline = 320,
418 .sizeimage = 320 * 240,
419 .colorspace = V4L2_COLORSPACE_SRGB,
420 .priv = 2},
421 {352, 288, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
422 .bytesperline = 352,
423 .sizeimage = 352 * 288,
424 .colorspace = V4L2_COLORSPACE_SRGB,
425 .priv = 0},
426};
427static const struct v4l2_pix_format ovfx2_ov2610_mode[] = {
428 {1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
429 .bytesperline = 1600,
430 .sizeimage = 1600 * 1200,
431 .colorspace = V4L2_COLORSPACE_SRGB},
432};
433static const struct v4l2_pix_format ovfx2_ov3610_mode[] = {
Hans de Goede635118d2009-10-11 09:49:03 -0300434 {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
435 .bytesperline = 640,
436 .sizeimage = 640 * 480,
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300437 .colorspace = V4L2_COLORSPACE_SRGB,
438 .priv = 1},
439 {800, 600, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
440 .bytesperline = 800,
441 .sizeimage = 800 * 600,
442 .colorspace = V4L2_COLORSPACE_SRGB,
443 .priv = 1},
444 {1024, 768, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
445 .bytesperline = 1024,
446 .sizeimage = 1024 * 768,
447 .colorspace = V4L2_COLORSPACE_SRGB,
448 .priv = 1},
449 {1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
450 .bytesperline = 1600,
451 .sizeimage = 1600 * 1200,
452 .colorspace = V4L2_COLORSPACE_SRGB,
453 .priv = 0},
454 {2048, 1536, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
455 .bytesperline = 2048,
456 .sizeimage = 2048 * 1536,
457 .colorspace = V4L2_COLORSPACE_SRGB,
458 .priv = 0},
Hans de Goede635118d2009-10-11 09:49:03 -0300459};
460
Hans de Goede49809d62009-06-07 12:10:39 -0300461/* Registers common to OV511 / OV518 */
Hans de Goede1876bb92009-06-14 06:45:50 -0300462#define R51x_FIFO_PSIZE 0x30 /* 2 bytes wide w/ OV518(+) */
Jean-François Moine780e3122010-10-19 04:29:10 -0300463#define R51x_SYS_RESET 0x50
Hans de Goede1876bb92009-06-14 06:45:50 -0300464 /* Reset type flags */
465 #define OV511_RESET_OMNICE 0x08
Jean-François Moine780e3122010-10-19 04:29:10 -0300466#define R51x_SYS_INIT 0x53
Hans de Goede49809d62009-06-07 12:10:39 -0300467#define R51x_SYS_SNAP 0x52
Jean-François Moine87bae742010-11-12 05:31:34 -0300468#define R51x_SYS_CUST_ID 0x5f
Hans de Goede49809d62009-06-07 12:10:39 -0300469#define R51x_COMP_LUT_BEGIN 0x80
470
471/* OV511 Camera interface register numbers */
Hans de Goede1876bb92009-06-14 06:45:50 -0300472#define R511_CAM_DELAY 0x10
473#define R511_CAM_EDGE 0x11
474#define R511_CAM_PXCNT 0x12
475#define R511_CAM_LNCNT 0x13
476#define R511_CAM_PXDIV 0x14
477#define R511_CAM_LNDIV 0x15
478#define R511_CAM_UV_EN 0x16
479#define R511_CAM_LINE_MODE 0x17
480#define R511_CAM_OPTS 0x18
481
482#define R511_SNAP_FRAME 0x19
Jean-François Moine87bae742010-11-12 05:31:34 -0300483#define R511_SNAP_PXCNT 0x1a
484#define R511_SNAP_LNCNT 0x1b
485#define R511_SNAP_PXDIV 0x1c
486#define R511_SNAP_LNDIV 0x1d
487#define R511_SNAP_UV_EN 0x1e
488#define R511_SNAP_UV_EN 0x1e
489#define R511_SNAP_OPTS 0x1f
Hans de Goede1876bb92009-06-14 06:45:50 -0300490
491#define R511_DRAM_FLOW_CTL 0x20
492#define R511_FIFO_OPTS 0x31
493#define R511_I2C_CTL 0x40
Hans de Goede49809d62009-06-07 12:10:39 -0300494#define R511_SYS_LED_CTL 0x55 /* OV511+ only */
Hans de Goede1876bb92009-06-14 06:45:50 -0300495#define R511_COMP_EN 0x78
496#define R511_COMP_LUT_EN 0x79
Hans de Goede49809d62009-06-07 12:10:39 -0300497
498/* OV518 Camera interface register numbers */
499#define R518_GPIO_OUT 0x56 /* OV518(+) only */
500#define R518_GPIO_CTL 0x57 /* OV518(+) only */
501
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300502/* OV519 Camera interface register numbers */
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300503#define OV519_R10_H_SIZE 0x10
504#define OV519_R11_V_SIZE 0x11
505#define OV519_R12_X_OFFSETL 0x12
506#define OV519_R13_X_OFFSETH 0x13
507#define OV519_R14_Y_OFFSETL 0x14
508#define OV519_R15_Y_OFFSETH 0x15
509#define OV519_R16_DIVIDER 0x16
510#define OV519_R20_DFR 0x20
511#define OV519_R25_FORMAT 0x25
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300512
513/* OV519 System Controller register numbers */
Jean-François Moine21867802010-11-12 06:12:09 -0300514#define OV519_R51_RESET1 0x51
515#define OV519_R54_EN_CLK1 0x54
Jean-François Moineb4e96ea2010-11-12 16:13:17 -0300516#define OV519_R57_SNAPSHOT 0x57
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300517
518#define OV519_GPIO_DATA_OUT0 0x71
519#define OV519_GPIO_IO_CTRL0 0x72
520
Jean-François Moine87bae742010-11-12 05:31:34 -0300521/*#define OV511_ENDPOINT_ADDRESS 1 * Isoc endpoint number */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300522
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300523/*
524 * The FX2 chip does not give us a zero length read at end of frame.
525 * It does, however, give a short read at the end of a frame, if
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800526 * necessary, rather than run two frames together.
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300527 *
528 * By choosing the right bulk transfer size, we are guaranteed to always
529 * get a short read for the last read of each frame. Frame sizes are
530 * always a composite number (width * height, or a multiple) so if we
531 * choose a prime number, we are guaranteed that the last read of a
532 * frame will be short.
533 *
534 * But it isn't that easy: the 2.6 kernel requires a multiple of 4KB,
535 * otherwise EOVERFLOW "babbling" errors occur. I have not been able
536 * to figure out why. [PMiller]
537 *
538 * The constant (13 * 4096) is the largest "prime enough" number less than 64KB.
539 *
540 * It isn't enough to know the number of bytes per frame, in case we
541 * have data dropouts or buffer overruns (even though the FX2 double
542 * buffers, there are some pretty strict real time constraints for
543 * isochronous transfer for larger frame sizes).
544 */
545#define OVFX2_BULK_SIZE (13 * 4096)
546
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300547/* I2C registers */
548#define R51x_I2C_W_SID 0x41
549#define R51x_I2C_SADDR_3 0x42
550#define R51x_I2C_SADDR_2 0x43
551#define R51x_I2C_R_SID 0x44
552#define R51x_I2C_DATA 0x45
553#define R518_I2C_CTL 0x47 /* OV518(+) only */
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300554#define OVFX2_I2C_ADDR 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300555
556/* I2C ADDRESSES */
557#define OV7xx0_SID 0x42
Hans de Goede229bb7d2009-10-11 07:41:46 -0300558#define OV_HIRES_SID 0x60 /* OV9xxx / OV2xxx / OV3xxx */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300559#define OV8xx0_SID 0xa0
560#define OV6xx0_SID 0xc0
561
562/* OV7610 registers */
563#define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */
Hans de Goede49809d62009-06-07 12:10:39 -0300564#define OV7610_REG_BLUE 0x01 /* blue channel balance */
565#define OV7610_REG_RED 0x02 /* red channel balance */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300566#define OV7610_REG_SAT 0x03 /* saturation */
567#define OV8610_REG_HUE 0x04 /* 04 reserved */
568#define OV7610_REG_CNT 0x05 /* Y contrast */
569#define OV7610_REG_BRT 0x06 /* Y brightness */
570#define OV7610_REG_COM_C 0x14 /* misc common regs */
571#define OV7610_REG_ID_HIGH 0x1c /* manufacturer ID MSB */
572#define OV7610_REG_ID_LOW 0x1d /* manufacturer ID LSB */
573#define OV7610_REG_COM_I 0x29 /* misc settings */
574
575/* OV7670 registers */
Jean-François Moine21867802010-11-12 06:12:09 -0300576#define OV7670_R00_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
577#define OV7670_R01_BLUE 0x01 /* blue gain */
578#define OV7670_R02_RED 0x02 /* red gain */
579#define OV7670_R03_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */
580#define OV7670_R04_COM1 0x04 /* Control 1 */
581/*#define OV7670_R07_AECHH 0x07 * AEC MS 5 bits */
582#define OV7670_R0C_COM3 0x0c /* Control 3 */
583#define OV7670_R0D_COM4 0x0d /* Control 4 */
584#define OV7670_R0E_COM5 0x0e /* All "reserved" */
585#define OV7670_R0F_COM6 0x0f /* Control 6 */
586#define OV7670_R10_AECH 0x10 /* More bits of AEC value */
587#define OV7670_R11_CLKRC 0x11 /* Clock control */
588#define OV7670_R12_COM7 0x12 /* Control 7 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300589#define OV7670_COM7_FMT_VGA 0x00
590/*#define OV7670_COM7_YUV 0x00 * YUV */
591#define OV7670_COM7_FMT_QVGA 0x10 /* QVGA format */
592#define OV7670_COM7_FMT_MASK 0x38
593#define OV7670_COM7_RESET 0x80 /* Register reset */
Jean-François Moine21867802010-11-12 06:12:09 -0300594#define OV7670_R13_COM8 0x13 /* Control 8 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300595#define OV7670_COM8_AEC 0x01 /* Auto exposure enable */
596#define OV7670_COM8_AWB 0x02 /* White balance enable */
597#define OV7670_COM8_AGC 0x04 /* Auto gain enable */
598#define OV7670_COM8_BFILT 0x20 /* Band filter enable */
599#define OV7670_COM8_AECSTEP 0x40 /* Unlimited AEC step size */
600#define OV7670_COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
Jean-François Moine21867802010-11-12 06:12:09 -0300601#define OV7670_R14_COM9 0x14 /* Control 9 - gain ceiling */
602#define OV7670_R15_COM10 0x15 /* Control 10 */
603#define OV7670_R17_HSTART 0x17 /* Horiz start high bits */
604#define OV7670_R18_HSTOP 0x18 /* Horiz stop high bits */
605#define OV7670_R19_VSTART 0x19 /* Vert start high bits */
606#define OV7670_R1A_VSTOP 0x1a /* Vert stop high bits */
607#define OV7670_R1E_MVFP 0x1e /* Mirror / vflip */
Jean-François Moine87bae742010-11-12 05:31:34 -0300608#define OV7670_MVFP_VFLIP 0x10 /* vertical flip */
609#define OV7670_MVFP_MIRROR 0x20 /* Mirror image */
Jean-François Moine21867802010-11-12 06:12:09 -0300610#define OV7670_R24_AEW 0x24 /* AGC upper limit */
611#define OV7670_R25_AEB 0x25 /* AGC lower limit */
612#define OV7670_R26_VPT 0x26 /* AGC/AEC fast mode op region */
613#define OV7670_R32_HREF 0x32 /* HREF pieces */
614#define OV7670_R3A_TSLB 0x3a /* lots of stuff */
615#define OV7670_R3B_COM11 0x3b /* Control 11 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300616#define OV7670_COM11_EXP 0x02
617#define OV7670_COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */
Jean-François Moine21867802010-11-12 06:12:09 -0300618#define OV7670_R3C_COM12 0x3c /* Control 12 */
619#define OV7670_R3D_COM13 0x3d /* Control 13 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300620#define OV7670_COM13_GAMMA 0x80 /* Gamma enable */
621#define OV7670_COM13_UVSAT 0x40 /* UV saturation auto adjustment */
Jean-François Moine21867802010-11-12 06:12:09 -0300622#define OV7670_R3E_COM14 0x3e /* Control 14 */
623#define OV7670_R3F_EDGE 0x3f /* Edge enhancement factor */
624#define OV7670_R40_COM15 0x40 /* Control 15 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300625/*#define OV7670_COM15_R00FF 0xc0 * 00 to FF */
Jean-François Moine21867802010-11-12 06:12:09 -0300626#define OV7670_R41_COM16 0x41 /* Control 16 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300627#define OV7670_COM16_AWBGAIN 0x08 /* AWB gain enable */
Jean-François Moine21867802010-11-12 06:12:09 -0300628#define OV7670_R55_BRIGHT 0x55 /* Brightness */
629#define OV7670_R56_CONTRAS 0x56 /* Contrast control */
630#define OV7670_R69_GFIX 0x69 /* Fix gain control */
631/*#define OV7670_R8C_RGB444 0x8c * RGB 444 control */
632#define OV7670_R9F_HAECC1 0x9f /* Hist AEC/AGC control 1 */
633#define OV7670_RA0_HAECC2 0xa0 /* Hist AEC/AGC control 2 */
634#define OV7670_RA5_BD50MAX 0xa5 /* 50hz banding step limit */
635#define OV7670_RA6_HAECC3 0xa6 /* Hist AEC/AGC control 3 */
636#define OV7670_RA7_HAECC4 0xa7 /* Hist AEC/AGC control 4 */
637#define OV7670_RA8_HAECC5 0xa8 /* Hist AEC/AGC control 5 */
638#define OV7670_RA9_HAECC6 0xa9 /* Hist AEC/AGC control 6 */
639#define OV7670_RAA_HAECC7 0xaa /* Hist AEC/AGC control 7 */
640#define OV7670_RAB_BD60MAX 0xab /* 60hz banding step limit */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300641
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300642struct ov_regvals {
Jean-François Moine9d1593a2010-11-11 08:04:06 -0300643 u8 reg;
644 u8 val;
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300645};
646struct ov_i2c_regvals {
Jean-François Moine9d1593a2010-11-11 08:04:06 -0300647 u8 reg;
648 u8 val;
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300649};
650
Hans de Goede635118d2009-10-11 09:49:03 -0300651/* Settings for OV2610 camera chip */
Jean-François Moine780e3122010-10-19 04:29:10 -0300652static const struct ov_i2c_regvals norm_2610[] = {
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300653 { 0x12, 0x80 }, /* reset */
Hans de Goede635118d2009-10-11 09:49:03 -0300654};
655
Jean-François Moine780e3122010-10-19 04:29:10 -0300656static const struct ov_i2c_regvals norm_3620b[] = {
Hans de Goede635118d2009-10-11 09:49:03 -0300657 /*
658 * From the datasheet: "Note that after writing to register COMH
659 * (0x12) to change the sensor mode, registers related to the
660 * sensor’s cropping window will be reset back to their default
661 * values."
662 *
663 * "wait 4096 external clock ... to make sure the sensor is
664 * stable and ready to access registers" i.e. 160us at 24MHz
665 */
Hans de Goede635118d2009-10-11 09:49:03 -0300666 { 0x12, 0x80 }, /* COMH reset */
667 { 0x12, 0x00 }, /* QXGA, master */
668
669 /*
670 * 11 CLKRC "Clock Rate Control"
671 * [7] internal frequency doublers: on
672 * [6] video port mode: master
673 * [5:0] clock divider: 1
674 */
675 { 0x11, 0x80 },
676
677 /*
678 * 13 COMI "Common Control I"
679 * = 192 (0xC0) 11000000
680 * COMI[7] "AEC speed selection"
681 * = 1 (0x01) 1....... "Faster AEC correction"
682 * COMI[6] "AEC speed step selection"
683 * = 1 (0x01) .1...... "Big steps, fast"
684 * COMI[5] "Banding filter on off"
685 * = 0 (0x00) ..0..... "Off"
686 * COMI[4] "Banding filter option"
687 * = 0 (0x00) ...0.... "Main clock is 48 MHz and
688 * the PLL is ON"
689 * COMI[3] "Reserved"
690 * = 0 (0x00) ....0...
691 * COMI[2] "AGC auto manual control selection"
692 * = 0 (0x00) .....0.. "Manual"
693 * COMI[1] "AWB auto manual control selection"
694 * = 0 (0x00) ......0. "Manual"
695 * COMI[0] "Exposure control"
696 * = 0 (0x00) .......0 "Manual"
697 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300698 { 0x13, 0xc0 },
Hans de Goede635118d2009-10-11 09:49:03 -0300699
700 /*
701 * 09 COMC "Common Control C"
702 * = 8 (0x08) 00001000
703 * COMC[7:5] "Reserved"
704 * = 0 (0x00) 000.....
705 * COMC[4] "Sleep Mode Enable"
706 * = 0 (0x00) ...0.... "Normal mode"
707 * COMC[3:2] "Sensor sampling reset timing selection"
708 * = 2 (0x02) ....10.. "Longer reset time"
709 * COMC[1:0] "Output drive current select"
710 * = 0 (0x00) ......00 "Weakest"
711 */
712 { 0x09, 0x08 },
713
714 /*
715 * 0C COMD "Common Control D"
716 * = 8 (0x08) 00001000
717 * COMD[7] "Reserved"
718 * = 0 (0x00) 0.......
719 * COMD[6] "Swap MSB and LSB at the output port"
720 * = 0 (0x00) .0...... "False"
721 * COMD[5:3] "Reserved"
722 * = 1 (0x01) ..001...
723 * COMD[2] "Output Average On Off"
724 * = 0 (0x00) .....0.. "Output Normal"
725 * COMD[1] "Sensor precharge voltage selection"
726 * = 0 (0x00) ......0. "Selects internal
727 * reference precharge
728 * voltage"
729 * COMD[0] "Snapshot option"
730 * = 0 (0x00) .......0 "Enable live video output
731 * after snapshot sequence"
732 */
733 { 0x0c, 0x08 },
734
735 /*
736 * 0D COME "Common Control E"
737 * = 161 (0xA1) 10100001
738 * COME[7] "Output average option"
739 * = 1 (0x01) 1....... "Output average of 4 pixels"
740 * COME[6] "Anti-blooming control"
741 * = 0 (0x00) .0...... "Off"
742 * COME[5:3] "Reserved"
743 * = 4 (0x04) ..100...
744 * COME[2] "Clock output power down pin status"
745 * = 0 (0x00) .....0.. "Tri-state data output pin
746 * on power down"
747 * COME[1] "Data output pin status selection at power down"
748 * = 0 (0x00) ......0. "Tri-state VSYNC, PCLK,
749 * HREF, and CHSYNC pins on
750 * power down"
751 * COME[0] "Auto zero circuit select"
752 * = 1 (0x01) .......1 "On"
753 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300754 { 0x0d, 0xa1 },
Hans de Goede635118d2009-10-11 09:49:03 -0300755
756 /*
757 * 0E COMF "Common Control F"
758 * = 112 (0x70) 01110000
759 * COMF[7] "System clock selection"
760 * = 0 (0x00) 0....... "Use 24 MHz system clock"
761 * COMF[6:4] "Reserved"
762 * = 7 (0x07) .111....
763 * COMF[3] "Manual auto negative offset canceling selection"
764 * = 0 (0x00) ....0... "Auto detect negative
765 * offset and cancel it"
766 * COMF[2:0] "Reserved"
767 * = 0 (0x00) .....000
768 */
769 { 0x0e, 0x70 },
770
771 /*
772 * 0F COMG "Common Control G"
773 * = 66 (0x42) 01000010
774 * COMG[7] "Optical black output selection"
775 * = 0 (0x00) 0....... "Disable"
776 * COMG[6] "Black level calibrate selection"
777 * = 1 (0x01) .1...... "Use optical black pixels
778 * to calibrate"
779 * COMG[5:4] "Reserved"
780 * = 0 (0x00) ..00....
781 * COMG[3] "Channel offset adjustment"
782 * = 0 (0x00) ....0... "Disable offset adjustment"
783 * COMG[2] "ADC black level calibration option"
784 * = 0 (0x00) .....0.. "Use B/G line and G/R
785 * line to calibrate each
786 * channel's black level"
787 * COMG[1] "Reserved"
788 * = 1 (0x01) ......1.
789 * COMG[0] "ADC black level calibration enable"
790 * = 0 (0x00) .......0 "Disable"
791 */
792 { 0x0f, 0x42 },
793
794 /*
795 * 14 COMJ "Common Control J"
796 * = 198 (0xC6) 11000110
797 * COMJ[7:6] "AGC gain ceiling"
798 * = 3 (0x03) 11...... "8x"
799 * COMJ[5:4] "Reserved"
800 * = 0 (0x00) ..00....
801 * COMJ[3] "Auto banding filter"
802 * = 0 (0x00) ....0... "Banding filter is always
803 * on off depending on
804 * COMI[5] setting"
805 * COMJ[2] "VSYNC drop option"
806 * = 1 (0x01) .....1.. "SYNC is dropped if frame
807 * data is dropped"
808 * COMJ[1] "Frame data drop"
809 * = 1 (0x01) ......1. "Drop frame data if
810 * exposure is not within
811 * tolerance. In AEC mode,
812 * data is normally dropped
813 * when data is out of
814 * range."
815 * COMJ[0] "Reserved"
816 * = 0 (0x00) .......0
817 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300818 { 0x14, 0xc6 },
Hans de Goede635118d2009-10-11 09:49:03 -0300819
820 /*
821 * 15 COMK "Common Control K"
822 * = 2 (0x02) 00000010
823 * COMK[7] "CHSYNC pin output swap"
824 * = 0 (0x00) 0....... "CHSYNC"
825 * COMK[6] "HREF pin output swap"
826 * = 0 (0x00) .0...... "HREF"
827 * COMK[5] "PCLK output selection"
828 * = 0 (0x00) ..0..... "PCLK always output"
829 * COMK[4] "PCLK edge selection"
830 * = 0 (0x00) ...0.... "Data valid on falling edge"
831 * COMK[3] "HREF output polarity"
832 * = 0 (0x00) ....0... "positive"
833 * COMK[2] "Reserved"
834 * = 0 (0x00) .....0..
835 * COMK[1] "VSYNC polarity"
836 * = 1 (0x01) ......1. "negative"
837 * COMK[0] "HSYNC polarity"
838 * = 0 (0x00) .......0 "positive"
839 */
840 { 0x15, 0x02 },
841
842 /*
843 * 33 CHLF "Current Control"
844 * = 9 (0x09) 00001001
845 * CHLF[7:6] "Sensor current control"
846 * = 0 (0x00) 00......
847 * CHLF[5] "Sensor current range control"
848 * = 0 (0x00) ..0..... "normal range"
849 * CHLF[4] "Sensor current"
850 * = 0 (0x00) ...0.... "normal current"
851 * CHLF[3] "Sensor buffer current control"
852 * = 1 (0x01) ....1... "half current"
853 * CHLF[2] "Column buffer current control"
854 * = 0 (0x00) .....0.. "normal current"
855 * CHLF[1] "Analog DSP current control"
856 * = 0 (0x00) ......0. "normal current"
857 * CHLF[1] "ADC current control"
858 * = 0 (0x00) ......0. "normal current"
859 */
860 { 0x33, 0x09 },
861
862 /*
863 * 34 VBLM "Blooming Control"
864 * = 80 (0x50) 01010000
865 * VBLM[7] "Hard soft reset switch"
866 * = 0 (0x00) 0....... "Hard reset"
867 * VBLM[6:4] "Blooming voltage selection"
868 * = 5 (0x05) .101....
869 * VBLM[3:0] "Sensor current control"
870 * = 0 (0x00) ....0000
871 */
872 { 0x34, 0x50 },
873
874 /*
875 * 36 VCHG "Sensor Precharge Voltage Control"
876 * = 0 (0x00) 00000000
877 * VCHG[7] "Reserved"
878 * = 0 (0x00) 0.......
879 * VCHG[6:4] "Sensor precharge voltage control"
880 * = 0 (0x00) .000....
881 * VCHG[3:0] "Sensor array common reference"
882 * = 0 (0x00) ....0000
883 */
884 { 0x36, 0x00 },
885
886 /*
887 * 37 ADC "ADC Reference Control"
888 * = 4 (0x04) 00000100
889 * ADC[7:4] "Reserved"
890 * = 0 (0x00) 0000....
891 * ADC[3] "ADC input signal range"
892 * = 0 (0x00) ....0... "Input signal 1.0x"
893 * ADC[2:0] "ADC range control"
894 * = 4 (0x04) .....100
895 */
896 { 0x37, 0x04 },
897
898 /*
899 * 38 ACOM "Analog Common Ground"
900 * = 82 (0x52) 01010010
901 * ACOM[7] "Analog gain control"
902 * = 0 (0x00) 0....... "Gain 1x"
903 * ACOM[6] "Analog black level calibration"
904 * = 1 (0x01) .1...... "On"
905 * ACOM[5:0] "Reserved"
906 * = 18 (0x12) ..010010
907 */
908 { 0x38, 0x52 },
909
910 /*
911 * 3A FREFA "Internal Reference Adjustment"
912 * = 0 (0x00) 00000000
913 * FREFA[7:0] "Range"
914 * = 0 (0x00) 00000000
915 */
916 { 0x3a, 0x00 },
917
918 /*
919 * 3C FVOPT "Internal Reference Adjustment"
920 * = 31 (0x1F) 00011111
921 * FVOPT[7:0] "Range"
922 * = 31 (0x1F) 00011111
923 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300924 { 0x3c, 0x1f },
Hans de Goede635118d2009-10-11 09:49:03 -0300925
926 /*
927 * 44 Undocumented = 0 (0x00) 00000000
928 * 44[7:0] "It's a secret"
929 * = 0 (0x00) 00000000
930 */
931 { 0x44, 0x00 },
932
933 /*
934 * 40 Undocumented = 0 (0x00) 00000000
935 * 40[7:0] "It's a secret"
936 * = 0 (0x00) 00000000
937 */
938 { 0x40, 0x00 },
939
940 /*
941 * 41 Undocumented = 0 (0x00) 00000000
942 * 41[7:0] "It's a secret"
943 * = 0 (0x00) 00000000
944 */
945 { 0x41, 0x00 },
946
947 /*
948 * 42 Undocumented = 0 (0x00) 00000000
949 * 42[7:0] "It's a secret"
950 * = 0 (0x00) 00000000
951 */
952 { 0x42, 0x00 },
953
954 /*
955 * 43 Undocumented = 0 (0x00) 00000000
956 * 43[7:0] "It's a secret"
957 * = 0 (0x00) 00000000
958 */
959 { 0x43, 0x00 },
960
961 /*
962 * 45 Undocumented = 128 (0x80) 10000000
963 * 45[7:0] "It's a secret"
964 * = 128 (0x80) 10000000
965 */
966 { 0x45, 0x80 },
967
968 /*
969 * 48 Undocumented = 192 (0xC0) 11000000
970 * 48[7:0] "It's a secret"
971 * = 192 (0xC0) 11000000
972 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300973 { 0x48, 0xc0 },
Hans de Goede635118d2009-10-11 09:49:03 -0300974
975 /*
976 * 49 Undocumented = 25 (0x19) 00011001
977 * 49[7:0] "It's a secret"
978 * = 25 (0x19) 00011001
979 */
980 { 0x49, 0x19 },
981
982 /*
983 * 4B Undocumented = 128 (0x80) 10000000
984 * 4B[7:0] "It's a secret"
985 * = 128 (0x80) 10000000
986 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300987 { 0x4b, 0x80 },
Hans de Goede635118d2009-10-11 09:49:03 -0300988
989 /*
990 * 4D Undocumented = 196 (0xC4) 11000100
991 * 4D[7:0] "It's a secret"
992 * = 196 (0xC4) 11000100
993 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300994 { 0x4d, 0xc4 },
Hans de Goede635118d2009-10-11 09:49:03 -0300995
996 /*
997 * 35 VREF "Reference Voltage Control"
Jean-François Moine87bae742010-11-12 05:31:34 -0300998 * = 76 (0x4c) 01001100
Hans de Goede635118d2009-10-11 09:49:03 -0300999 * VREF[7:5] "Column high reference control"
1000 * = 2 (0x02) 010..... "higher voltage"
1001 * VREF[4:2] "Column low reference control"
1002 * = 3 (0x03) ...011.. "Highest voltage"
1003 * VREF[1:0] "Reserved"
1004 * = 0 (0x00) ......00
1005 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001006 { 0x35, 0x4c },
Hans de Goede635118d2009-10-11 09:49:03 -03001007
1008 /*
1009 * 3D Undocumented = 0 (0x00) 00000000
1010 * 3D[7:0] "It's a secret"
1011 * = 0 (0x00) 00000000
1012 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001013 { 0x3d, 0x00 },
Hans de Goede635118d2009-10-11 09:49:03 -03001014
1015 /*
1016 * 3E Undocumented = 0 (0x00) 00000000
1017 * 3E[7:0] "It's a secret"
1018 * = 0 (0x00) 00000000
1019 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001020 { 0x3e, 0x00 },
Hans de Goede635118d2009-10-11 09:49:03 -03001021
1022 /*
1023 * 3B FREFB "Internal Reference Adjustment"
1024 * = 24 (0x18) 00011000
1025 * FREFB[7:0] "Range"
1026 * = 24 (0x18) 00011000
1027 */
1028 { 0x3b, 0x18 },
1029
1030 /*
1031 * 33 CHLF "Current Control"
1032 * = 25 (0x19) 00011001
1033 * CHLF[7:6] "Sensor current control"
1034 * = 0 (0x00) 00......
1035 * CHLF[5] "Sensor current range control"
1036 * = 0 (0x00) ..0..... "normal range"
1037 * CHLF[4] "Sensor current"
1038 * = 1 (0x01) ...1.... "double current"
1039 * CHLF[3] "Sensor buffer current control"
1040 * = 1 (0x01) ....1... "half current"
1041 * CHLF[2] "Column buffer current control"
1042 * = 0 (0x00) .....0.. "normal current"
1043 * CHLF[1] "Analog DSP current control"
1044 * = 0 (0x00) ......0. "normal current"
1045 * CHLF[1] "ADC current control"
1046 * = 0 (0x00) ......0. "normal current"
1047 */
1048 { 0x33, 0x19 },
1049
1050 /*
1051 * 34 VBLM "Blooming Control"
1052 * = 90 (0x5A) 01011010
1053 * VBLM[7] "Hard soft reset switch"
1054 * = 0 (0x00) 0....... "Hard reset"
1055 * VBLM[6:4] "Blooming voltage selection"
1056 * = 5 (0x05) .101....
1057 * VBLM[3:0] "Sensor current control"
1058 * = 10 (0x0A) ....1010
1059 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001060 { 0x34, 0x5a },
Hans de Goede635118d2009-10-11 09:49:03 -03001061
1062 /*
1063 * 3B FREFB "Internal Reference Adjustment"
1064 * = 0 (0x00) 00000000
1065 * FREFB[7:0] "Range"
1066 * = 0 (0x00) 00000000
1067 */
1068 { 0x3b, 0x00 },
1069
1070 /*
1071 * 33 CHLF "Current Control"
1072 * = 9 (0x09) 00001001
1073 * CHLF[7:6] "Sensor current control"
1074 * = 0 (0x00) 00......
1075 * CHLF[5] "Sensor current range control"
1076 * = 0 (0x00) ..0..... "normal range"
1077 * CHLF[4] "Sensor current"
1078 * = 0 (0x00) ...0.... "normal current"
1079 * CHLF[3] "Sensor buffer current control"
1080 * = 1 (0x01) ....1... "half current"
1081 * CHLF[2] "Column buffer current control"
1082 * = 0 (0x00) .....0.. "normal current"
1083 * CHLF[1] "Analog DSP current control"
1084 * = 0 (0x00) ......0. "normal current"
1085 * CHLF[1] "ADC current control"
1086 * = 0 (0x00) ......0. "normal current"
1087 */
1088 { 0x33, 0x09 },
1089
1090 /*
1091 * 34 VBLM "Blooming Control"
1092 * = 80 (0x50) 01010000
1093 * VBLM[7] "Hard soft reset switch"
1094 * = 0 (0x00) 0....... "Hard reset"
1095 * VBLM[6:4] "Blooming voltage selection"
1096 * = 5 (0x05) .101....
1097 * VBLM[3:0] "Sensor current control"
1098 * = 0 (0x00) ....0000
1099 */
1100 { 0x34, 0x50 },
1101
1102 /*
1103 * 12 COMH "Common Control H"
1104 * = 64 (0x40) 01000000
1105 * COMH[7] "SRST"
1106 * = 0 (0x00) 0....... "No-op"
1107 * COMH[6:4] "Resolution selection"
1108 * = 4 (0x04) .100.... "XGA"
1109 * COMH[3] "Master slave selection"
1110 * = 0 (0x00) ....0... "Master mode"
1111 * COMH[2] "Internal B/R channel option"
1112 * = 0 (0x00) .....0.. "B/R use same channel"
1113 * COMH[1] "Color bar test pattern"
1114 * = 0 (0x00) ......0. "Off"
1115 * COMH[0] "Reserved"
1116 * = 0 (0x00) .......0
1117 */
1118 { 0x12, 0x40 },
1119
1120 /*
1121 * 17 HREFST "Horizontal window start"
1122 * = 31 (0x1F) 00011111
1123 * HREFST[7:0] "Horizontal window start, 8 MSBs"
1124 * = 31 (0x1F) 00011111
1125 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001126 { 0x17, 0x1f },
Hans de Goede635118d2009-10-11 09:49:03 -03001127
1128 /*
1129 * 18 HREFEND "Horizontal window end"
1130 * = 95 (0x5F) 01011111
1131 * HREFEND[7:0] "Horizontal Window End, 8 MSBs"
1132 * = 95 (0x5F) 01011111
1133 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001134 { 0x18, 0x5f },
Hans de Goede635118d2009-10-11 09:49:03 -03001135
1136 /*
1137 * 19 VSTRT "Vertical window start"
1138 * = 0 (0x00) 00000000
1139 * VSTRT[7:0] "Vertical Window Start, 8 MSBs"
1140 * = 0 (0x00) 00000000
1141 */
1142 { 0x19, 0x00 },
1143
1144 /*
1145 * 1A VEND "Vertical window end"
1146 * = 96 (0x60) 01100000
1147 * VEND[7:0] "Vertical Window End, 8 MSBs"
1148 * = 96 (0x60) 01100000
1149 */
1150 { 0x1a, 0x60 },
1151
1152 /*
1153 * 32 COMM "Common Control M"
1154 * = 18 (0x12) 00010010
1155 * COMM[7:6] "Pixel clock divide option"
1156 * = 0 (0x00) 00...... "/1"
1157 * COMM[5:3] "Horizontal window end position, 3 LSBs"
1158 * = 2 (0x02) ..010...
1159 * COMM[2:0] "Horizontal window start position, 3 LSBs"
1160 * = 2 (0x02) .....010
1161 */
1162 { 0x32, 0x12 },
1163
1164 /*
1165 * 03 COMA "Common Control A"
1166 * = 74 (0x4A) 01001010
1167 * COMA[7:4] "AWB Update Threshold"
1168 * = 4 (0x04) 0100....
1169 * COMA[3:2] "Vertical window end line control 2 LSBs"
1170 * = 2 (0x02) ....10..
1171 * COMA[1:0] "Vertical window start line control 2 LSBs"
1172 * = 2 (0x02) ......10
1173 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001174 { 0x03, 0x4a },
Hans de Goede635118d2009-10-11 09:49:03 -03001175
1176 /*
1177 * 11 CLKRC "Clock Rate Control"
1178 * = 128 (0x80) 10000000
1179 * CLKRC[7] "Internal frequency doublers on off seclection"
1180 * = 1 (0x01) 1....... "On"
1181 * CLKRC[6] "Digital video master slave selection"
1182 * = 0 (0x00) .0...... "Master mode, sensor
1183 * provides PCLK"
1184 * CLKRC[5:0] "Clock divider { CLK = PCLK/(1+CLKRC[5:0]) }"
1185 * = 0 (0x00) ..000000
1186 */
1187 { 0x11, 0x80 },
1188
1189 /*
1190 * 12 COMH "Common Control H"
1191 * = 0 (0x00) 00000000
1192 * COMH[7] "SRST"
1193 * = 0 (0x00) 0....... "No-op"
1194 * COMH[6:4] "Resolution selection"
1195 * = 0 (0x00) .000.... "QXGA"
1196 * COMH[3] "Master slave selection"
1197 * = 0 (0x00) ....0... "Master mode"
1198 * COMH[2] "Internal B/R channel option"
1199 * = 0 (0x00) .....0.. "B/R use same channel"
1200 * COMH[1] "Color bar test pattern"
1201 * = 0 (0x00) ......0. "Off"
1202 * COMH[0] "Reserved"
1203 * = 0 (0x00) .......0
1204 */
1205 { 0x12, 0x00 },
1206
1207 /*
1208 * 12 COMH "Common Control H"
1209 * = 64 (0x40) 01000000
1210 * COMH[7] "SRST"
1211 * = 0 (0x00) 0....... "No-op"
1212 * COMH[6:4] "Resolution selection"
1213 * = 4 (0x04) .100.... "XGA"
1214 * COMH[3] "Master slave selection"
1215 * = 0 (0x00) ....0... "Master mode"
1216 * COMH[2] "Internal B/R channel option"
1217 * = 0 (0x00) .....0.. "B/R use same channel"
1218 * COMH[1] "Color bar test pattern"
1219 * = 0 (0x00) ......0. "Off"
1220 * COMH[0] "Reserved"
1221 * = 0 (0x00) .......0
1222 */
1223 { 0x12, 0x40 },
1224
1225 /*
1226 * 17 HREFST "Horizontal window start"
1227 * = 31 (0x1F) 00011111
1228 * HREFST[7:0] "Horizontal window start, 8 MSBs"
1229 * = 31 (0x1F) 00011111
1230 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001231 { 0x17, 0x1f },
Hans de Goede635118d2009-10-11 09:49:03 -03001232
1233 /*
1234 * 18 HREFEND "Horizontal window end"
1235 * = 95 (0x5F) 01011111
1236 * HREFEND[7:0] "Horizontal Window End, 8 MSBs"
1237 * = 95 (0x5F) 01011111
1238 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001239 { 0x18, 0x5f },
Hans de Goede635118d2009-10-11 09:49:03 -03001240
1241 /*
1242 * 19 VSTRT "Vertical window start"
1243 * = 0 (0x00) 00000000
1244 * VSTRT[7:0] "Vertical Window Start, 8 MSBs"
1245 * = 0 (0x00) 00000000
1246 */
1247 { 0x19, 0x00 },
1248
1249 /*
1250 * 1A VEND "Vertical window end"
1251 * = 96 (0x60) 01100000
1252 * VEND[7:0] "Vertical Window End, 8 MSBs"
1253 * = 96 (0x60) 01100000
1254 */
1255 { 0x1a, 0x60 },
1256
1257 /*
1258 * 32 COMM "Common Control M"
1259 * = 18 (0x12) 00010010
1260 * COMM[7:6] "Pixel clock divide option"
1261 * = 0 (0x00) 00...... "/1"
1262 * COMM[5:3] "Horizontal window end position, 3 LSBs"
1263 * = 2 (0x02) ..010...
1264 * COMM[2:0] "Horizontal window start position, 3 LSBs"
1265 * = 2 (0x02) .....010
1266 */
1267 { 0x32, 0x12 },
1268
1269 /*
1270 * 03 COMA "Common Control A"
1271 * = 74 (0x4A) 01001010
1272 * COMA[7:4] "AWB Update Threshold"
1273 * = 4 (0x04) 0100....
1274 * COMA[3:2] "Vertical window end line control 2 LSBs"
1275 * = 2 (0x02) ....10..
1276 * COMA[1:0] "Vertical window start line control 2 LSBs"
1277 * = 2 (0x02) ......10
1278 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001279 { 0x03, 0x4a },
Hans de Goede635118d2009-10-11 09:49:03 -03001280
1281 /*
1282 * 02 RED "Red Gain Control"
1283 * = 175 (0xAF) 10101111
1284 * RED[7] "Action"
1285 * = 1 (0x01) 1....... "gain = 1/(1+bitrev([6:0]))"
1286 * RED[6:0] "Value"
1287 * = 47 (0x2F) .0101111
1288 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001289 { 0x02, 0xaf },
Hans de Goede635118d2009-10-11 09:49:03 -03001290
1291 /*
1292 * 2D ADDVSL "VSYNC Pulse Width"
1293 * = 210 (0xD2) 11010010
1294 * ADDVSL[7:0] "VSYNC pulse width, LSB"
1295 * = 210 (0xD2) 11010010
1296 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001297 { 0x2d, 0xd2 },
Hans de Goede635118d2009-10-11 09:49:03 -03001298
1299 /*
1300 * 00 GAIN = 24 (0x18) 00011000
1301 * GAIN[7:6] "Reserved"
1302 * = 0 (0x00) 00......
1303 * GAIN[5] "Double"
1304 * = 0 (0x00) ..0..... "False"
1305 * GAIN[4] "Double"
1306 * = 1 (0x01) ...1.... "True"
1307 * GAIN[3:0] "Range"
1308 * = 8 (0x08) ....1000
1309 */
1310 { 0x00, 0x18 },
1311
1312 /*
1313 * 01 BLUE "Blue Gain Control"
1314 * = 240 (0xF0) 11110000
1315 * BLUE[7] "Action"
1316 * = 1 (0x01) 1....... "gain = 1/(1+bitrev([6:0]))"
1317 * BLUE[6:0] "Value"
1318 * = 112 (0x70) .1110000
1319 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001320 { 0x01, 0xf0 },
Hans de Goede635118d2009-10-11 09:49:03 -03001321
1322 /*
1323 * 10 AEC "Automatic Exposure Control"
1324 * = 10 (0x0A) 00001010
1325 * AEC[7:0] "Automatic Exposure Control, 8 MSBs"
1326 * = 10 (0x0A) 00001010
1327 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001328 { 0x10, 0x0a },
Hans de Goede635118d2009-10-11 09:49:03 -03001329
Jean-François Moine87bae742010-11-12 05:31:34 -03001330 { 0xe1, 0x67 },
1331 { 0xe3, 0x03 },
1332 { 0xe4, 0x26 },
1333 { 0xe5, 0x3e },
1334 { 0xf8, 0x01 },
1335 { 0xff, 0x01 },
Hans de Goede635118d2009-10-11 09:49:03 -03001336};
1337
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001338static const struct ov_i2c_regvals norm_6x20[] = {
1339 { 0x12, 0x80 }, /* reset */
1340 { 0x11, 0x01 },
1341 { 0x03, 0x60 },
1342 { 0x05, 0x7f }, /* For when autoadjust is off */
1343 { 0x07, 0xa8 },
Jean-François Moine87bae742010-11-12 05:31:34 -03001344 /* The ratio of 0x0c and 0x0d controls the white point */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001345 { 0x0c, 0x24 },
1346 { 0x0d, 0x24 },
1347 { 0x0f, 0x15 }, /* COMS */
1348 { 0x10, 0x75 }, /* AEC Exposure time */
1349 { 0x12, 0x24 }, /* Enable AGC */
1350 { 0x14, 0x04 },
1351 /* 0x16: 0x06 helps frame stability with moving objects */
1352 { 0x16, 0x06 },
1353/* { 0x20, 0x30 }, * Aperture correction enable */
1354 { 0x26, 0xb2 }, /* BLC enable */
1355 /* 0x28: 0x05 Selects RGB format if RGB on */
1356 { 0x28, 0x05 },
1357 { 0x2a, 0x04 }, /* Disable framerate adjust */
1358/* { 0x2b, 0xac }, * Framerate; Set 2a[7] first */
Hans de Goedeae49c402009-06-14 19:15:07 -03001359 { 0x2d, 0x85 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001360 { 0x33, 0xa0 }, /* Color Processing Parameter */
1361 { 0x34, 0xd2 }, /* Max A/D range */
1362 { 0x38, 0x8b },
1363 { 0x39, 0x40 },
1364
1365 { 0x3c, 0x39 }, /* Enable AEC mode changing */
1366 { 0x3c, 0x3c }, /* Change AEC mode */
1367 { 0x3c, 0x24 }, /* Disable AEC mode changing */
1368
1369 { 0x3d, 0x80 },
1370 /* These next two registers (0x4a, 0x4b) are undocumented.
1371 * They control the color balance */
1372 { 0x4a, 0x80 },
1373 { 0x4b, 0x80 },
1374 { 0x4d, 0xd2 }, /* This reduces noise a bit */
1375 { 0x4e, 0xc1 },
1376 { 0x4f, 0x04 },
1377/* Do 50-53 have any effect? */
1378/* Toggle 0x12[2] off and on here? */
1379};
1380
1381static const struct ov_i2c_regvals norm_6x30[] = {
1382 { 0x12, 0x80 }, /* Reset */
1383 { 0x00, 0x1f }, /* Gain */
1384 { 0x01, 0x99 }, /* Blue gain */
1385 { 0x02, 0x7c }, /* Red gain */
1386 { 0x03, 0xc0 }, /* Saturation */
1387 { 0x05, 0x0a }, /* Contrast */
1388 { 0x06, 0x95 }, /* Brightness */
1389 { 0x07, 0x2d }, /* Sharpness */
1390 { 0x0c, 0x20 },
1391 { 0x0d, 0x20 },
Hans de Goede02ab18b2009-06-14 04:32:04 -03001392 { 0x0e, 0xa0 }, /* Was 0x20, bit7 enables a 2x gain which we need */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001393 { 0x0f, 0x05 },
1394 { 0x10, 0x9a },
1395 { 0x11, 0x00 }, /* Pixel clock = fastest */
1396 { 0x12, 0x24 }, /* Enable AGC and AWB */
1397 { 0x13, 0x21 },
1398 { 0x14, 0x80 },
1399 { 0x15, 0x01 },
1400 { 0x16, 0x03 },
1401 { 0x17, 0x38 },
1402 { 0x18, 0xea },
1403 { 0x19, 0x04 },
1404 { 0x1a, 0x93 },
1405 { 0x1b, 0x00 },
1406 { 0x1e, 0xc4 },
1407 { 0x1f, 0x04 },
1408 { 0x20, 0x20 },
1409 { 0x21, 0x10 },
1410 { 0x22, 0x88 },
1411 { 0x23, 0xc0 }, /* Crystal circuit power level */
1412 { 0x25, 0x9a }, /* Increase AEC black ratio */
1413 { 0x26, 0xb2 }, /* BLC enable */
1414 { 0x27, 0xa2 },
1415 { 0x28, 0x00 },
1416 { 0x29, 0x00 },
1417 { 0x2a, 0x84 }, /* 60 Hz power */
1418 { 0x2b, 0xa8 }, /* 60 Hz power */
1419 { 0x2c, 0xa0 },
1420 { 0x2d, 0x95 }, /* Enable auto-brightness */
1421 { 0x2e, 0x88 },
1422 { 0x33, 0x26 },
1423 { 0x34, 0x03 },
1424 { 0x36, 0x8f },
1425 { 0x37, 0x80 },
1426 { 0x38, 0x83 },
1427 { 0x39, 0x80 },
1428 { 0x3a, 0x0f },
1429 { 0x3b, 0x3c },
1430 { 0x3c, 0x1a },
1431 { 0x3d, 0x80 },
1432 { 0x3e, 0x80 },
1433 { 0x3f, 0x0e },
1434 { 0x40, 0x00 }, /* White bal */
1435 { 0x41, 0x00 }, /* White bal */
1436 { 0x42, 0x80 },
1437 { 0x43, 0x3f }, /* White bal */
1438 { 0x44, 0x80 },
1439 { 0x45, 0x20 },
1440 { 0x46, 0x20 },
1441 { 0x47, 0x80 },
1442 { 0x48, 0x7f },
1443 { 0x49, 0x00 },
1444 { 0x4a, 0x00 },
1445 { 0x4b, 0x80 },
1446 { 0x4c, 0xd0 },
1447 { 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
1448 { 0x4e, 0x40 },
1449 { 0x4f, 0x07 }, /* UV avg., col. killer: max */
1450 { 0x50, 0xff },
1451 { 0x54, 0x23 }, /* Max AGC gain: 18dB */
1452 { 0x55, 0xff },
1453 { 0x56, 0x12 },
1454 { 0x57, 0x81 },
1455 { 0x58, 0x75 },
1456 { 0x59, 0x01 }, /* AGC dark current comp.: +1 */
1457 { 0x5a, 0x2c },
1458 { 0x5b, 0x0f }, /* AWB chrominance levels */
1459 { 0x5c, 0x10 },
1460 { 0x3d, 0x80 },
1461 { 0x27, 0xa6 },
1462 { 0x12, 0x20 }, /* Toggle AWB */
1463 { 0x12, 0x24 },
1464};
1465
1466/* Lawrence Glaister <lg@jfm.bc.ca> reports:
1467 *
1468 * Register 0x0f in the 7610 has the following effects:
1469 *
1470 * 0x85 (AEC method 1): Best overall, good contrast range
1471 * 0x45 (AEC method 2): Very overexposed
1472 * 0xa5 (spec sheet default): Ok, but the black level is
1473 * shifted resulting in loss of contrast
1474 * 0x05 (old driver setting): very overexposed, too much
1475 * contrast
1476 */
1477static const struct ov_i2c_regvals norm_7610[] = {
1478 { 0x10, 0xff },
1479 { 0x16, 0x06 },
1480 { 0x28, 0x24 },
1481 { 0x2b, 0xac },
1482 { 0x12, 0x00 },
1483 { 0x38, 0x81 },
1484 { 0x28, 0x24 }, /* 0c */
1485 { 0x0f, 0x85 }, /* lg's setting */
1486 { 0x15, 0x01 },
1487 { 0x20, 0x1c },
1488 { 0x23, 0x2a },
1489 { 0x24, 0x10 },
1490 { 0x25, 0x8a },
1491 { 0x26, 0xa2 },
1492 { 0x27, 0xc2 },
1493 { 0x2a, 0x04 },
1494 { 0x2c, 0xfe },
1495 { 0x2d, 0x93 },
1496 { 0x30, 0x71 },
1497 { 0x31, 0x60 },
1498 { 0x32, 0x26 },
1499 { 0x33, 0x20 },
1500 { 0x34, 0x48 },
1501 { 0x12, 0x24 },
1502 { 0x11, 0x01 },
1503 { 0x0c, 0x24 },
1504 { 0x0d, 0x24 },
1505};
1506
1507static const struct ov_i2c_regvals norm_7620[] = {
Hans de Goedea511ba92009-10-16 07:13:07 -03001508 { 0x12, 0x80 }, /* reset */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001509 { 0x00, 0x00 }, /* gain */
1510 { 0x01, 0x80 }, /* blue gain */
1511 { 0x02, 0x80 }, /* red gain */
Jean-François Moine21867802010-11-12 06:12:09 -03001512 { 0x03, 0xc0 }, /* OV7670_R03_VREF */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001513 { 0x06, 0x60 },
1514 { 0x07, 0x00 },
1515 { 0x0c, 0x24 },
1516 { 0x0c, 0x24 },
1517 { 0x0d, 0x24 },
1518 { 0x11, 0x01 },
1519 { 0x12, 0x24 },
1520 { 0x13, 0x01 },
1521 { 0x14, 0x84 },
1522 { 0x15, 0x01 },
1523 { 0x16, 0x03 },
1524 { 0x17, 0x2f },
1525 { 0x18, 0xcf },
1526 { 0x19, 0x06 },
1527 { 0x1a, 0xf5 },
1528 { 0x1b, 0x00 },
1529 { 0x20, 0x18 },
1530 { 0x21, 0x80 },
1531 { 0x22, 0x80 },
1532 { 0x23, 0x00 },
1533 { 0x26, 0xa2 },
1534 { 0x27, 0xea },
Hans de Goedeb282d872009-06-14 19:10:40 -03001535 { 0x28, 0x22 }, /* Was 0x20, bit1 enables a 2x gain which we need */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001536 { 0x29, 0x00 },
1537 { 0x2a, 0x10 },
1538 { 0x2b, 0x00 },
1539 { 0x2c, 0x88 },
1540 { 0x2d, 0x91 },
1541 { 0x2e, 0x80 },
1542 { 0x2f, 0x44 },
1543 { 0x60, 0x27 },
1544 { 0x61, 0x02 },
1545 { 0x62, 0x5f },
1546 { 0x63, 0xd5 },
1547 { 0x64, 0x57 },
1548 { 0x65, 0x83 },
1549 { 0x66, 0x55 },
1550 { 0x67, 0x92 },
1551 { 0x68, 0xcf },
1552 { 0x69, 0x76 },
1553 { 0x6a, 0x22 },
1554 { 0x6b, 0x00 },
1555 { 0x6c, 0x02 },
1556 { 0x6d, 0x44 },
1557 { 0x6e, 0x80 },
1558 { 0x6f, 0x1d },
1559 { 0x70, 0x8b },
1560 { 0x71, 0x00 },
1561 { 0x72, 0x14 },
1562 { 0x73, 0x54 },
1563 { 0x74, 0x00 },
1564 { 0x75, 0x8e },
1565 { 0x76, 0x00 },
1566 { 0x77, 0xff },
1567 { 0x78, 0x80 },
1568 { 0x79, 0x80 },
1569 { 0x7a, 0x80 },
1570 { 0x7b, 0xe2 },
1571 { 0x7c, 0x00 },
1572};
1573
1574/* 7640 and 7648. The defaults should be OK for most registers. */
1575static const struct ov_i2c_regvals norm_7640[] = {
1576 { 0x12, 0x80 },
1577 { 0x12, 0x14 },
1578};
1579
1580/* 7670. Defaults taken from OmniVision provided data,
1581* as provided by Jonathan Corbet of OLPC */
1582static const struct ov_i2c_regvals norm_7670[] = {
Jean-François Moine21867802010-11-12 06:12:09 -03001583 { OV7670_R12_COM7, OV7670_COM7_RESET },
1584 { OV7670_R3A_TSLB, 0x04 }, /* OV */
1585 { OV7670_R12_COM7, OV7670_COM7_FMT_VGA }, /* VGA */
1586 { OV7670_R11_CLKRC, 0x01 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001587/*
1588 * Set the hardware window. These values from OV don't entirely
1589 * make sense - hstop is less than hstart. But they work...
1590 */
Jean-François Moine21867802010-11-12 06:12:09 -03001591 { OV7670_R17_HSTART, 0x13 },
1592 { OV7670_R18_HSTOP, 0x01 },
1593 { OV7670_R32_HREF, 0xb6 },
1594 { OV7670_R19_VSTART, 0x02 },
1595 { OV7670_R1A_VSTOP, 0x7a },
1596 { OV7670_R03_VREF, 0x0a },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001597
Jean-François Moine21867802010-11-12 06:12:09 -03001598 { OV7670_R0C_COM3, 0x00 },
1599 { OV7670_R3E_COM14, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001600/* Mystery scaling numbers */
1601 { 0x70, 0x3a },
1602 { 0x71, 0x35 },
1603 { 0x72, 0x11 },
1604 { 0x73, 0xf0 },
1605 { 0xa2, 0x02 },
Jean-François Moine21867802010-11-12 06:12:09 -03001606/* { OV7670_R15_COM10, 0x0 }, */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001607
1608/* Gamma curve values */
1609 { 0x7a, 0x20 },
1610 { 0x7b, 0x10 },
1611 { 0x7c, 0x1e },
1612 { 0x7d, 0x35 },
1613 { 0x7e, 0x5a },
1614 { 0x7f, 0x69 },
1615 { 0x80, 0x76 },
1616 { 0x81, 0x80 },
1617 { 0x82, 0x88 },
1618 { 0x83, 0x8f },
1619 { 0x84, 0x96 },
1620 { 0x85, 0xa3 },
1621 { 0x86, 0xaf },
1622 { 0x87, 0xc4 },
1623 { 0x88, 0xd7 },
1624 { 0x89, 0xe8 },
1625
1626/* AGC and AEC parameters. Note we start by disabling those features,
1627 then turn them only after tweaking the values. */
Jean-François Moine21867802010-11-12 06:12:09 -03001628 { OV7670_R13_COM8, OV7670_COM8_FASTAEC
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001629 | OV7670_COM8_AECSTEP
1630 | OV7670_COM8_BFILT },
Jean-François Moine21867802010-11-12 06:12:09 -03001631 { OV7670_R00_GAIN, 0x00 },
1632 { OV7670_R10_AECH, 0x00 },
1633 { OV7670_R0D_COM4, 0x40 }, /* magic reserved bit */
1634 { OV7670_R14_COM9, 0x18 }, /* 4x gain + magic rsvd bit */
1635 { OV7670_RA5_BD50MAX, 0x05 },
1636 { OV7670_RAB_BD60MAX, 0x07 },
1637 { OV7670_R24_AEW, 0x95 },
1638 { OV7670_R25_AEB, 0x33 },
1639 { OV7670_R26_VPT, 0xe3 },
1640 { OV7670_R9F_HAECC1, 0x78 },
1641 { OV7670_RA0_HAECC2, 0x68 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001642 { 0xa1, 0x03 }, /* magic */
Jean-François Moine21867802010-11-12 06:12:09 -03001643 { OV7670_RA6_HAECC3, 0xd8 },
1644 { OV7670_RA7_HAECC4, 0xd8 },
1645 { OV7670_RA8_HAECC5, 0xf0 },
1646 { OV7670_RA9_HAECC6, 0x90 },
1647 { OV7670_RAA_HAECC7, 0x94 },
1648 { OV7670_R13_COM8, OV7670_COM8_FASTAEC
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001649 | OV7670_COM8_AECSTEP
1650 | OV7670_COM8_BFILT
1651 | OV7670_COM8_AGC
1652 | OV7670_COM8_AEC },
1653
1654/* Almost all of these are magic "reserved" values. */
Jean-François Moine21867802010-11-12 06:12:09 -03001655 { OV7670_R0E_COM5, 0x61 },
1656 { OV7670_R0F_COM6, 0x4b },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001657 { 0x16, 0x02 },
Jean-François Moine21867802010-11-12 06:12:09 -03001658 { OV7670_R1E_MVFP, 0x07 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001659 { 0x21, 0x02 },
1660 { 0x22, 0x91 },
1661 { 0x29, 0x07 },
1662 { 0x33, 0x0b },
1663 { 0x35, 0x0b },
1664 { 0x37, 0x1d },
1665 { 0x38, 0x71 },
1666 { 0x39, 0x2a },
Jean-François Moine21867802010-11-12 06:12:09 -03001667 { OV7670_R3C_COM12, 0x78 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001668 { 0x4d, 0x40 },
1669 { 0x4e, 0x20 },
Jean-François Moine21867802010-11-12 06:12:09 -03001670 { OV7670_R69_GFIX, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001671 { 0x6b, 0x4a },
1672 { 0x74, 0x10 },
1673 { 0x8d, 0x4f },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001674 { 0x8e, 0x00 },
1675 { 0x8f, 0x00 },
1676 { 0x90, 0x00 },
1677 { 0x91, 0x00 },
1678 { 0x96, 0x00 },
1679 { 0x9a, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001680 { 0xb0, 0x84 },
1681 { 0xb1, 0x0c },
1682 { 0xb2, 0x0e },
1683 { 0xb3, 0x82 },
1684 { 0xb8, 0x0a },
1685
1686/* More reserved magic, some of which tweaks white balance */
1687 { 0x43, 0x0a },
1688 { 0x44, 0xf0 },
1689 { 0x45, 0x34 },
1690 { 0x46, 0x58 },
1691 { 0x47, 0x28 },
1692 { 0x48, 0x3a },
1693 { 0x59, 0x88 },
1694 { 0x5a, 0x88 },
1695 { 0x5b, 0x44 },
1696 { 0x5c, 0x67 },
1697 { 0x5d, 0x49 },
1698 { 0x5e, 0x0e },
1699 { 0x6c, 0x0a },
1700 { 0x6d, 0x55 },
1701 { 0x6e, 0x11 },
1702 { 0x6f, 0x9f },
1703 /* "9e for advance AWB" */
1704 { 0x6a, 0x40 },
Jean-François Moine21867802010-11-12 06:12:09 -03001705 { OV7670_R01_BLUE, 0x40 },
1706 { OV7670_R02_RED, 0x60 },
1707 { OV7670_R13_COM8, OV7670_COM8_FASTAEC
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001708 | OV7670_COM8_AECSTEP
1709 | OV7670_COM8_BFILT
1710 | OV7670_COM8_AGC
1711 | OV7670_COM8_AEC
1712 | OV7670_COM8_AWB },
1713
1714/* Matrix coefficients */
1715 { 0x4f, 0x80 },
1716 { 0x50, 0x80 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001717 { 0x51, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001718 { 0x52, 0x22 },
1719 { 0x53, 0x5e },
1720 { 0x54, 0x80 },
1721 { 0x58, 0x9e },
1722
Jean-François Moine21867802010-11-12 06:12:09 -03001723 { OV7670_R41_COM16, OV7670_COM16_AWBGAIN },
1724 { OV7670_R3F_EDGE, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001725 { 0x75, 0x05 },
1726 { 0x76, 0xe1 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001727 { 0x4c, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001728 { 0x77, 0x01 },
Jean-François Moine21867802010-11-12 06:12:09 -03001729 { OV7670_R3D_COM13, OV7670_COM13_GAMMA
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001730 | OV7670_COM13_UVSAT
1731 | 2}, /* was 3 */
1732 { 0x4b, 0x09 },
1733 { 0xc9, 0x60 },
Jean-François Moine21867802010-11-12 06:12:09 -03001734 { OV7670_R41_COM16, 0x38 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001735 { 0x56, 0x40 },
1736
1737 { 0x34, 0x11 },
Jean-François Moine21867802010-11-12 06:12:09 -03001738 { OV7670_R3B_COM11, OV7670_COM11_EXP|OV7670_COM11_HZAUTO },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001739 { 0xa4, 0x88 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001740 { 0x96, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001741 { 0x97, 0x30 },
1742 { 0x98, 0x20 },
1743 { 0x99, 0x30 },
1744 { 0x9a, 0x84 },
1745 { 0x9b, 0x29 },
1746 { 0x9c, 0x03 },
1747 { 0x9d, 0x4c },
1748 { 0x9e, 0x3f },
1749 { 0x78, 0x04 },
1750
1751/* Extra-weird stuff. Some sort of multiplexor register */
1752 { 0x79, 0x01 },
1753 { 0xc8, 0xf0 },
1754 { 0x79, 0x0f },
1755 { 0xc8, 0x00 },
1756 { 0x79, 0x10 },
1757 { 0xc8, 0x7e },
1758 { 0x79, 0x0a },
1759 { 0xc8, 0x80 },
1760 { 0x79, 0x0b },
1761 { 0xc8, 0x01 },
1762 { 0x79, 0x0c },
1763 { 0xc8, 0x0f },
1764 { 0x79, 0x0d },
1765 { 0xc8, 0x20 },
1766 { 0x79, 0x09 },
1767 { 0xc8, 0x80 },
1768 { 0x79, 0x02 },
1769 { 0xc8, 0xc0 },
1770 { 0x79, 0x03 },
1771 { 0xc8, 0x40 },
1772 { 0x79, 0x05 },
1773 { 0xc8, 0x30 },
1774 { 0x79, 0x26 },
1775};
1776
1777static const struct ov_i2c_regvals norm_8610[] = {
1778 { 0x12, 0x80 },
1779 { 0x00, 0x00 },
1780 { 0x01, 0x80 },
1781 { 0x02, 0x80 },
1782 { 0x03, 0xc0 },
1783 { 0x04, 0x30 },
1784 { 0x05, 0x30 }, /* was 0x10, new from windrv 090403 */
1785 { 0x06, 0x70 }, /* was 0x80, new from windrv 090403 */
1786 { 0x0a, 0x86 },
1787 { 0x0b, 0xb0 },
1788 { 0x0c, 0x20 },
1789 { 0x0d, 0x20 },
1790 { 0x11, 0x01 },
1791 { 0x12, 0x25 },
1792 { 0x13, 0x01 },
1793 { 0x14, 0x04 },
1794 { 0x15, 0x01 }, /* Lin and Win think different about UV order */
1795 { 0x16, 0x03 },
1796 { 0x17, 0x38 }, /* was 0x2f, new from windrv 090403 */
1797 { 0x18, 0xea }, /* was 0xcf, new from windrv 090403 */
1798 { 0x19, 0x02 }, /* was 0x06, new from windrv 090403 */
1799 { 0x1a, 0xf5 },
1800 { 0x1b, 0x00 },
1801 { 0x20, 0xd0 }, /* was 0x90, new from windrv 090403 */
1802 { 0x23, 0xc0 }, /* was 0x00, new from windrv 090403 */
1803 { 0x24, 0x30 }, /* was 0x1d, new from windrv 090403 */
1804 { 0x25, 0x50 }, /* was 0x57, new from windrv 090403 */
1805 { 0x26, 0xa2 },
1806 { 0x27, 0xea },
1807 { 0x28, 0x00 },
1808 { 0x29, 0x00 },
1809 { 0x2a, 0x80 },
1810 { 0x2b, 0xc8 }, /* was 0xcc, new from windrv 090403 */
1811 { 0x2c, 0xac },
1812 { 0x2d, 0x45 }, /* was 0xd5, new from windrv 090403 */
1813 { 0x2e, 0x80 },
1814 { 0x2f, 0x14 }, /* was 0x01, new from windrv 090403 */
1815 { 0x4c, 0x00 },
1816 { 0x4d, 0x30 }, /* was 0x10, new from windrv 090403 */
1817 { 0x60, 0x02 }, /* was 0x01, new from windrv 090403 */
1818 { 0x61, 0x00 }, /* was 0x09, new from windrv 090403 */
1819 { 0x62, 0x5f }, /* was 0xd7, new from windrv 090403 */
1820 { 0x63, 0xff },
1821 { 0x64, 0x53 }, /* new windrv 090403 says 0x57,
1822 * maybe thats wrong */
1823 { 0x65, 0x00 },
1824 { 0x66, 0x55 },
1825 { 0x67, 0xb0 },
1826 { 0x68, 0xc0 }, /* was 0xaf, new from windrv 090403 */
1827 { 0x69, 0x02 },
1828 { 0x6a, 0x22 },
1829 { 0x6b, 0x00 },
1830 { 0x6c, 0x99 }, /* was 0x80, old windrv says 0x00, but
1831 * deleting bit7 colors the first images red */
1832 { 0x6d, 0x11 }, /* was 0x00, new from windrv 090403 */
1833 { 0x6e, 0x11 }, /* was 0x00, new from windrv 090403 */
1834 { 0x6f, 0x01 },
1835 { 0x70, 0x8b },
1836 { 0x71, 0x00 },
1837 { 0x72, 0x14 },
1838 { 0x73, 0x54 },
1839 { 0x74, 0x00 },/* 0x60? - was 0x00, new from windrv 090403 */
1840 { 0x75, 0x0e },
1841 { 0x76, 0x02 }, /* was 0x02, new from windrv 090403 */
1842 { 0x77, 0xff },
1843 { 0x78, 0x80 },
1844 { 0x79, 0x80 },
1845 { 0x7a, 0x80 },
1846 { 0x7b, 0x10 }, /* was 0x13, new from windrv 090403 */
1847 { 0x7c, 0x00 },
1848 { 0x7d, 0x08 }, /* was 0x09, new from windrv 090403 */
1849 { 0x7e, 0x08 }, /* was 0xc0, new from windrv 090403 */
1850 { 0x7f, 0xfb },
1851 { 0x80, 0x28 },
1852 { 0x81, 0x00 },
1853 { 0x82, 0x23 },
1854 { 0x83, 0x0b },
1855 { 0x84, 0x00 },
1856 { 0x85, 0x62 }, /* was 0x61, new from windrv 090403 */
1857 { 0x86, 0xc9 },
1858 { 0x87, 0x00 },
1859 { 0x88, 0x00 },
1860 { 0x89, 0x01 },
1861 { 0x12, 0x20 },
1862 { 0x12, 0x25 }, /* was 0x24, new from windrv 090403 */
1863};
1864
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001865static unsigned char ov7670_abs_to_sm(unsigned char v)
1866{
1867 if (v > 127)
1868 return v & 0x7f;
1869 return (128 - v) | 0x80;
1870}
1871
1872/* Write a OV519 register */
Jean-François Moinef8f20182010-11-12 07:54:02 -03001873static void reg_w(struct sd *sd, u16 index, u16 value)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001874{
Hans de Goedea511ba92009-10-16 07:13:07 -03001875 int ret, req = 0;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001876
Jean-François Moinef8f20182010-11-12 07:54:02 -03001877 if (sd->gspca_dev.usb_err < 0)
1878 return;
1879
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001880 switch (sd->bridge) {
1881 case BRIDGE_OV511:
1882 case BRIDGE_OV511PLUS:
1883 req = 2;
1884 break;
1885 case BRIDGE_OVFX2:
Hans de Goedea511ba92009-10-16 07:13:07 -03001886 req = 0x0a;
1887 /* fall through */
1888 case BRIDGE_W9968CF:
Jean-François Moine858ea5e2010-11-12 13:53:10 -03001889 PDEBUG(D_USBO, "SET %02x %04x %04x",
1890 req, value, index);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001891 ret = usb_control_msg(sd->gspca_dev.dev,
1892 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
Hans de Goedea511ba92009-10-16 07:13:07 -03001893 req,
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001894 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Hans de Goedea511ba92009-10-16 07:13:07 -03001895 value, index, NULL, 0, 500);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001896 goto leave;
1897 default:
1898 req = 1;
1899 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001900
Jean-François Moine858ea5e2010-11-12 13:53:10 -03001901 PDEBUG(D_USBO, "SET %02x 0000 %04x %02x",
1902 req, index, value);
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001903 sd->gspca_dev.usb_buf[0] = value;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001904 ret = usb_control_msg(sd->gspca_dev.dev,
1905 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
Hans de Goede49809d62009-06-07 12:10:39 -03001906 req,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001907 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1908 0, index,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001909 sd->gspca_dev.usb_buf, 1, 500);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001910leave:
Hans de Goedea511ba92009-10-16 07:13:07 -03001911 if (ret < 0) {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03001912 err("reg_w %02x failed %d", index, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03001913 sd->gspca_dev.usb_err = ret;
1914 return;
Hans de Goedea511ba92009-10-16 07:13:07 -03001915 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001916}
1917
Hans de Goedea511ba92009-10-16 07:13:07 -03001918/* Read from a OV519 register, note not valid for the w9968cf!! */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001919/* returns: negative is error, pos or zero is data */
Jean-François Moine9d1593a2010-11-11 08:04:06 -03001920static int reg_r(struct sd *sd, u16 index)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001921{
1922 int ret;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001923 int req;
1924
Jean-François Moinef8f20182010-11-12 07:54:02 -03001925 if (sd->gspca_dev.usb_err < 0)
1926 return -1;
1927
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001928 switch (sd->bridge) {
1929 case BRIDGE_OV511:
1930 case BRIDGE_OV511PLUS:
1931 req = 3;
1932 break;
1933 case BRIDGE_OVFX2:
1934 req = 0x0b;
1935 break;
1936 default:
1937 req = 1;
1938 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001939
1940 ret = usb_control_msg(sd->gspca_dev.dev,
1941 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
Hans de Goede49809d62009-06-07 12:10:39 -03001942 req,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001943 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001944 0, index, sd->gspca_dev.usb_buf, 1, 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001945
Hans de Goedea511ba92009-10-16 07:13:07 -03001946 if (ret >= 0) {
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001947 ret = sd->gspca_dev.usb_buf[0];
Jean-François Moine858ea5e2010-11-12 13:53:10 -03001948 PDEBUG(D_USBI, "GET %02x 0000 %04x %02x",
1949 req, index, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03001950 } else {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03001951 err("reg_r %02x failed %d", index, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03001952 sd->gspca_dev.usb_err = ret;
1953 }
Hans de Goedea511ba92009-10-16 07:13:07 -03001954
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001955 return ret;
1956}
1957
1958/* Read 8 values from a OV519 register */
1959static int reg_r8(struct sd *sd,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03001960 u16 index)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001961{
1962 int ret;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001963
Jean-François Moinef8f20182010-11-12 07:54:02 -03001964 if (sd->gspca_dev.usb_err < 0)
1965 return -1;
1966
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001967 ret = usb_control_msg(sd->gspca_dev.dev,
1968 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
1969 1, /* REQ_IO */
1970 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001971 0, index, sd->gspca_dev.usb_buf, 8, 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001972
Jean-François Moinef8f20182010-11-12 07:54:02 -03001973 if (ret >= 0) {
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001974 ret = sd->gspca_dev.usb_buf[0];
Jean-François Moinef8f20182010-11-12 07:54:02 -03001975 } else {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03001976 err("reg_r8 %02x failed %d", index, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03001977 sd->gspca_dev.usb_err = ret;
1978 }
Hans de Goedea511ba92009-10-16 07:13:07 -03001979
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001980 return ret;
1981}
1982
1983/*
1984 * Writes bits at positions specified by mask to an OV51x reg. Bits that are in
1985 * the same position as 1's in "mask" are cleared and set to "value". Bits
1986 * that are in the same position as 0's in "mask" are preserved, regardless
1987 * of their respective state in "value".
1988 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03001989static void reg_w_mask(struct sd *sd,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03001990 u16 index,
1991 u8 value,
1992 u8 mask)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001993{
1994 int ret;
Jean-François Moine9d1593a2010-11-11 08:04:06 -03001995 u8 oldval;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001996
1997 if (mask != 0xff) {
1998 value &= mask; /* Enforce mask on value */
1999 ret = reg_r(sd, index);
2000 if (ret < 0)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002001 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002002
2003 oldval = ret & ~mask; /* Clear the masked bits */
2004 value |= oldval; /* Set the desired bits */
2005 }
Jean-François Moinef8f20182010-11-12 07:54:02 -03002006 reg_w(sd, index, value);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002007}
2008
2009/*
Hans de Goede49809d62009-06-07 12:10:39 -03002010 * Writes multiple (n) byte value to a single register. Only valid with certain
2011 * registers (0x30 and 0xc4 - 0xce).
2012 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002013static void ov518_reg_w32(struct sd *sd, u16 index, u32 value, int n)
Hans de Goede49809d62009-06-07 12:10:39 -03002014{
2015 int ret;
2016
Jean-François Moinef8f20182010-11-12 07:54:02 -03002017 if (sd->gspca_dev.usb_err < 0)
2018 return;
2019
Jean-Francois Moine83955552009-12-12 06:58:01 -03002020 *((__le32 *) sd->gspca_dev.usb_buf) = __cpu_to_le32(value);
Hans de Goede49809d62009-06-07 12:10:39 -03002021
2022 ret = usb_control_msg(sd->gspca_dev.dev,
2023 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
2024 1 /* REG_IO */,
2025 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2026 0, index,
2027 sd->gspca_dev.usb_buf, n, 500);
Hans de Goedea511ba92009-10-16 07:13:07 -03002028 if (ret < 0) {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002029 err("reg_w32 %02x failed %d", index, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002030 sd->gspca_dev.usb_err = ret;
Hans de Goedea511ba92009-10-16 07:13:07 -03002031 }
Hans de Goede49809d62009-06-07 12:10:39 -03002032}
2033
Jean-François Moinef8f20182010-11-12 07:54:02 -03002034static void ov511_i2c_w(struct sd *sd, u8 reg, u8 value)
Hans de Goede1876bb92009-06-14 06:45:50 -03002035{
2036 int rc, retries;
2037
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002038 PDEBUG(D_USBO, "ov511_i2c_w %02x %02x", reg, value);
Hans de Goede1876bb92009-06-14 06:45:50 -03002039
2040 /* Three byte write cycle */
2041 for (retries = 6; ; ) {
2042 /* Select camera register */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002043 reg_w(sd, R51x_I2C_SADDR_3, reg);
Hans de Goede1876bb92009-06-14 06:45:50 -03002044
2045 /* Write "value" to I2C data port of OV511 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002046 reg_w(sd, R51x_I2C_DATA, value);
Hans de Goede1876bb92009-06-14 06:45:50 -03002047
2048 /* Initiate 3-byte write cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002049 reg_w(sd, R511_I2C_CTL, 0x01);
Hans de Goede1876bb92009-06-14 06:45:50 -03002050
Jean-Francois Moine83955552009-12-12 06:58:01 -03002051 do {
Hans de Goede1876bb92009-06-14 06:45:50 -03002052 rc = reg_r(sd, R511_I2C_CTL);
Jean-Francois Moine83955552009-12-12 06:58:01 -03002053 } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
Hans de Goede1876bb92009-06-14 06:45:50 -03002054
2055 if (rc < 0)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002056 return;
Hans de Goede1876bb92009-06-14 06:45:50 -03002057
2058 if ((rc & 2) == 0) /* Ack? */
2059 break;
2060 if (--retries < 0) {
2061 PDEBUG(D_USBO, "i2c write retries exhausted");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002062 return;
Hans de Goede1876bb92009-06-14 06:45:50 -03002063 }
2064 }
Hans de Goede1876bb92009-06-14 06:45:50 -03002065}
2066
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002067static int ov511_i2c_r(struct sd *sd, u8 reg)
Hans de Goede1876bb92009-06-14 06:45:50 -03002068{
2069 int rc, value, retries;
2070
2071 /* Two byte write cycle */
2072 for (retries = 6; ; ) {
2073 /* Select camera register */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002074 reg_w(sd, R51x_I2C_SADDR_2, reg);
Hans de Goede1876bb92009-06-14 06:45:50 -03002075
2076 /* Initiate 2-byte write cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002077 reg_w(sd, R511_I2C_CTL, 0x03);
Hans de Goede1876bb92009-06-14 06:45:50 -03002078
Jean-Francois Moine83955552009-12-12 06:58:01 -03002079 do {
Hans de Goede1876bb92009-06-14 06:45:50 -03002080 rc = reg_r(sd, R511_I2C_CTL);
Jean-Francois Moine83955552009-12-12 06:58:01 -03002081 } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
Hans de Goede1876bb92009-06-14 06:45:50 -03002082
2083 if (rc < 0)
2084 return rc;
2085
2086 if ((rc & 2) == 0) /* Ack? */
2087 break;
2088
2089 /* I2C abort */
2090 reg_w(sd, R511_I2C_CTL, 0x10);
2091
2092 if (--retries < 0) {
2093 PDEBUG(D_USBI, "i2c write retries exhausted");
2094 return -1;
2095 }
2096 }
2097
2098 /* Two byte read cycle */
2099 for (retries = 6; ; ) {
2100 /* Initiate 2-byte read cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002101 reg_w(sd, R511_I2C_CTL, 0x05);
Hans de Goede1876bb92009-06-14 06:45:50 -03002102
Jean-Francois Moine83955552009-12-12 06:58:01 -03002103 do {
Hans de Goede1876bb92009-06-14 06:45:50 -03002104 rc = reg_r(sd, R511_I2C_CTL);
Jean-Francois Moine83955552009-12-12 06:58:01 -03002105 } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
Hans de Goede1876bb92009-06-14 06:45:50 -03002106
2107 if (rc < 0)
2108 return rc;
2109
2110 if ((rc & 2) == 0) /* Ack? */
2111 break;
2112
2113 /* I2C abort */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002114 reg_w(sd, R511_I2C_CTL, 0x10);
Hans de Goede1876bb92009-06-14 06:45:50 -03002115
2116 if (--retries < 0) {
2117 PDEBUG(D_USBI, "i2c read retries exhausted");
2118 return -1;
2119 }
2120 }
2121
2122 value = reg_r(sd, R51x_I2C_DATA);
2123
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002124 PDEBUG(D_USBI, "ov511_i2c_r %02x %02x", reg, value);
Hans de Goede1876bb92009-06-14 06:45:50 -03002125
2126 /* This is needed to make i2c_w() work */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002127 reg_w(sd, R511_I2C_CTL, 0x05);
Hans de Goede1876bb92009-06-14 06:45:50 -03002128
2129 return value;
2130}
Hans de Goede49809d62009-06-07 12:10:39 -03002131
2132/*
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002133 * The OV518 I2C I/O procedure is different, hence, this function.
2134 * This is normally only called from i2c_w(). Note that this function
2135 * always succeeds regardless of whether the sensor is present and working.
2136 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002137static void ov518_i2c_w(struct sd *sd,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002138 u8 reg,
2139 u8 value)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002140{
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002141 PDEBUG(D_USBO, "ov518_i2c_w %02x %02x", reg, value);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002142
2143 /* Select camera register */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002144 reg_w(sd, R51x_I2C_SADDR_3, reg);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002145
2146 /* Write "value" to I2C data port of OV511 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002147 reg_w(sd, R51x_I2C_DATA, value);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002148
2149 /* Initiate 3-byte write cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002150 reg_w(sd, R518_I2C_CTL, 0x01);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002151
2152 /* wait for write complete */
2153 msleep(4);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002154 reg_r8(sd, R518_I2C_CTL);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002155}
2156
2157/*
2158 * returns: negative is error, pos or zero is data
2159 *
2160 * The OV518 I2C I/O procedure is different, hence, this function.
2161 * This is normally only called from i2c_r(). Note that this function
2162 * always succeeds regardless of whether the sensor is present and working.
2163 */
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002164static int ov518_i2c_r(struct sd *sd, u8 reg)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002165{
Jean-François Moinef8f20182010-11-12 07:54:02 -03002166 int value;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002167
2168 /* Select camera register */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002169 reg_w(sd, R51x_I2C_SADDR_2, reg);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002170
2171 /* Initiate 2-byte write cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002172 reg_w(sd, R518_I2C_CTL, 0x03);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002173
2174 /* Initiate 2-byte read cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002175 reg_w(sd, R518_I2C_CTL, 0x05);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002176 value = reg_r(sd, R51x_I2C_DATA);
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002177 PDEBUG(D_USBI, "ov518_i2c_r %02x %02x", reg, value);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002178 return value;
2179}
2180
Jean-François Moinef8f20182010-11-12 07:54:02 -03002181static void ovfx2_i2c_w(struct sd *sd, u8 reg, u8 value)
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002182{
2183 int ret;
2184
Jean-François Moinef8f20182010-11-12 07:54:02 -03002185 if (sd->gspca_dev.usb_err < 0)
2186 return;
2187
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002188 ret = usb_control_msg(sd->gspca_dev.dev,
2189 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
2190 0x02,
2191 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002192 (u16) value, (u16) reg, NULL, 0, 500);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002193
Hans de Goedea511ba92009-10-16 07:13:07 -03002194 if (ret < 0) {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002195 err("ovfx2_i2c_w %02x failed %d", reg, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002196 sd->gspca_dev.usb_err = ret;
Hans de Goedea511ba92009-10-16 07:13:07 -03002197 }
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002198
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002199 PDEBUG(D_USBO, "ovfx2_i2c_w %02x %02x", reg, value);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002200}
2201
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002202static int ovfx2_i2c_r(struct sd *sd, u8 reg)
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002203{
2204 int ret;
2205
Jean-François Moinef8f20182010-11-12 07:54:02 -03002206 if (sd->gspca_dev.usb_err < 0)
2207 return -1;
2208
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002209 ret = usb_control_msg(sd->gspca_dev.dev,
2210 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
2211 0x03,
2212 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002213 0, (u16) reg, sd->gspca_dev.usb_buf, 1, 500);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002214
2215 if (ret >= 0) {
2216 ret = sd->gspca_dev.usb_buf[0];
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002217 PDEBUG(D_USBI, "ovfx2_i2c_r %02x %02x", reg, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002218 } else {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002219 err("ovfx2_i2c_r %02x failed %d", reg, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002220 sd->gspca_dev.usb_err = ret;
2221 }
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002222
2223 return ret;
2224}
2225
Jean-François Moinef8f20182010-11-12 07:54:02 -03002226static void i2c_w(struct sd *sd, u8 reg, u8 value)
Hans de Goede1876bb92009-06-14 06:45:50 -03002227{
Hans de Goedefb1f9022009-10-16 07:42:53 -03002228 if (sd->sensor_reg_cache[reg] == value)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002229 return;
Hans de Goedefb1f9022009-10-16 07:42:53 -03002230
Hans de Goede1876bb92009-06-14 06:45:50 -03002231 switch (sd->bridge) {
2232 case BRIDGE_OV511:
2233 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002234 ov511_i2c_w(sd, reg, value);
Hans de Goedefb1f9022009-10-16 07:42:53 -03002235 break;
Hans de Goede1876bb92009-06-14 06:45:50 -03002236 case BRIDGE_OV518:
2237 case BRIDGE_OV518PLUS:
2238 case BRIDGE_OV519:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002239 ov518_i2c_w(sd, reg, value);
Hans de Goedefb1f9022009-10-16 07:42:53 -03002240 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002241 case BRIDGE_OVFX2:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002242 ovfx2_i2c_w(sd, reg, value);
Hans de Goedefb1f9022009-10-16 07:42:53 -03002243 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03002244 case BRIDGE_W9968CF:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002245 w9968cf_i2c_w(sd, reg, value);
Hans de Goedefb1f9022009-10-16 07:42:53 -03002246 break;
Hans de Goede1876bb92009-06-14 06:45:50 -03002247 }
Hans de Goedefb1f9022009-10-16 07:42:53 -03002248
Jean-François Moinef8f20182010-11-12 07:54:02 -03002249 if (sd->gspca_dev.usb_err >= 0) {
Hans de Goedefb1f9022009-10-16 07:42:53 -03002250 /* Up on sensor reset empty the register cache */
2251 if (reg == 0x12 && (value & 0x80))
2252 memset(sd->sensor_reg_cache, -1,
Jean-François Moine87bae742010-11-12 05:31:34 -03002253 sizeof(sd->sensor_reg_cache));
Hans de Goedefb1f9022009-10-16 07:42:53 -03002254 else
2255 sd->sensor_reg_cache[reg] = value;
2256 }
Hans de Goede1876bb92009-06-14 06:45:50 -03002257}
2258
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002259static int i2c_r(struct sd *sd, u8 reg)
Hans de Goede1876bb92009-06-14 06:45:50 -03002260{
Hans de Goede8394bcf2009-10-16 11:26:22 -03002261 int ret = -1;
Hans de Goedefb1f9022009-10-16 07:42:53 -03002262
2263 if (sd->sensor_reg_cache[reg] != -1)
2264 return sd->sensor_reg_cache[reg];
2265
Hans de Goede1876bb92009-06-14 06:45:50 -03002266 switch (sd->bridge) {
2267 case BRIDGE_OV511:
2268 case BRIDGE_OV511PLUS:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002269 ret = ov511_i2c_r(sd, reg);
2270 break;
Hans de Goede1876bb92009-06-14 06:45:50 -03002271 case BRIDGE_OV518:
2272 case BRIDGE_OV518PLUS:
2273 case BRIDGE_OV519:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002274 ret = ov518_i2c_r(sd, reg);
2275 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002276 case BRIDGE_OVFX2:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002277 ret = ovfx2_i2c_r(sd, reg);
2278 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03002279 case BRIDGE_W9968CF:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002280 ret = w9968cf_i2c_r(sd, reg);
2281 break;
Hans de Goede1876bb92009-06-14 06:45:50 -03002282 }
Hans de Goedefb1f9022009-10-16 07:42:53 -03002283
2284 if (ret >= 0)
2285 sd->sensor_reg_cache[reg] = ret;
2286
2287 return ret;
Hans de Goede1876bb92009-06-14 06:45:50 -03002288}
2289
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002290/* Writes bits at positions specified by mask to an I2C reg. Bits that are in
2291 * the same position as 1's in "mask" are cleared and set to "value". Bits
2292 * that are in the same position as 0's in "mask" are preserved, regardless
2293 * of their respective state in "value".
2294 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002295static void i2c_w_mask(struct sd *sd,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002296 u8 reg,
2297 u8 value,
2298 u8 mask)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002299{
2300 int rc;
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002301 u8 oldval;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002302
2303 value &= mask; /* Enforce mask on value */
2304 rc = i2c_r(sd, reg);
2305 if (rc < 0)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002306 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002307 oldval = rc & ~mask; /* Clear the masked bits */
2308 value |= oldval; /* Set the desired bits */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002309 i2c_w(sd, reg, value);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002310}
2311
2312/* Temporarily stops OV511 from functioning. Must do this before changing
2313 * registers while the camera is streaming */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002314static inline void ov51x_stop(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002315{
2316 PDEBUG(D_STREAM, "stopping");
2317 sd->stopped = 1;
Hans de Goede49809d62009-06-07 12:10:39 -03002318 switch (sd->bridge) {
2319 case BRIDGE_OV511:
2320 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002321 reg_w(sd, R51x_SYS_RESET, 0x3d);
2322 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002323 case BRIDGE_OV518:
2324 case BRIDGE_OV518PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002325 reg_w_mask(sd, R51x_SYS_RESET, 0x3a, 0x3a);
2326 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002327 case BRIDGE_OV519:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002328 reg_w(sd, OV519_R51_RESET1, 0x0f);
Jean-François Moine5927abc2010-11-12 15:32:29 -03002329 reg_w(sd, OV519_R51_RESET1, 0x00);
2330 reg_w(sd, 0x22, 0x00); /* FRAR */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002331 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002332 case BRIDGE_OVFX2:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002333 reg_w_mask(sd, 0x0f, 0x00, 0x02);
2334 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03002335 case BRIDGE_W9968CF:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002336 reg_w(sd, 0x3c, 0x0a05); /* stop USB transfer */
2337 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002338 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002339}
2340
2341/* Restarts OV511 after ov511_stop() is called. Has no effect if it is not
2342 * actually stopped (for performance). */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002343static inline void ov51x_restart(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002344{
2345 PDEBUG(D_STREAM, "restarting");
2346 if (!sd->stopped)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002347 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002348 sd->stopped = 0;
2349
2350 /* Reinitialize the stream */
Hans de Goede49809d62009-06-07 12:10:39 -03002351 switch (sd->bridge) {
2352 case BRIDGE_OV511:
2353 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002354 reg_w(sd, R51x_SYS_RESET, 0x00);
2355 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002356 case BRIDGE_OV518:
2357 case BRIDGE_OV518PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002358 reg_w(sd, 0x2f, 0x80);
2359 reg_w(sd, R51x_SYS_RESET, 0x00);
2360 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002361 case BRIDGE_OV519:
Jean-François Moine5927abc2010-11-12 15:32:29 -03002362 reg_w(sd, OV519_R51_RESET1, 0x0f);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002363 reg_w(sd, OV519_R51_RESET1, 0x00);
Jean-François Moine5927abc2010-11-12 15:32:29 -03002364 reg_w(sd, 0x22, 0x1d); /* FRAR */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002365 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002366 case BRIDGE_OVFX2:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002367 reg_w_mask(sd, 0x0f, 0x02, 0x02);
2368 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03002369 case BRIDGE_W9968CF:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002370 reg_w(sd, 0x3c, 0x8a05); /* USB FIFO enable */
2371 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002372 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002373}
2374
Jean-François Moinef8f20182010-11-12 07:54:02 -03002375static void ov51x_set_slave_ids(struct sd *sd, u8 slave);
Hans de Goede229bb7d2009-10-11 07:41:46 -03002376
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002377/* This does an initial reset of an OmniVision sensor and ensures that I2C
2378 * is synchronized. Returns <0 on failure.
2379 */
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002380static int init_ov_sensor(struct sd *sd, u8 slave)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002381{
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002382 int i;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002383
Jean-François Moinef8f20182010-11-12 07:54:02 -03002384 ov51x_set_slave_ids(sd, slave);
Hans de Goede229bb7d2009-10-11 07:41:46 -03002385
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002386 /* Reset the sensor */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002387 i2c_w(sd, 0x12, 0x80);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002388
2389 /* Wait for it to initialize */
2390 msleep(150);
2391
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002392 for (i = 0; i < i2c_detect_tries; i++) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002393 if (i2c_r(sd, OV7610_REG_ID_HIGH) == 0x7f &&
2394 i2c_r(sd, OV7610_REG_ID_LOW) == 0xa2) {
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002395 PDEBUG(D_PROBE, "I2C synced in %d attempt(s)", i);
2396 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002397 }
2398
2399 /* Reset the sensor */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002400 i2c_w(sd, 0x12, 0x80);
2401
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002402 /* Wait for it to initialize */
2403 msleep(150);
Jean-François Moine87bae742010-11-12 05:31:34 -03002404
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002405 /* Dummy read to sync I2C */
2406 if (i2c_r(sd, 0x00) < 0)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002407 return -1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002408 }
Jean-François Moinef8f20182010-11-12 07:54:02 -03002409 return -1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002410}
2411
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002412/* Set the read and write slave IDs. The "slave" argument is the write slave,
2413 * and the read slave will be set to (slave + 1).
2414 * This should not be called from outside the i2c I/O functions.
2415 * Sets I2C read and write slave IDs. Returns <0 for error
2416 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002417static void ov51x_set_slave_ids(struct sd *sd,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002418 u8 slave)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002419{
Hans de Goedea511ba92009-10-16 07:13:07 -03002420 switch (sd->bridge) {
2421 case BRIDGE_OVFX2:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002422 reg_w(sd, OVFX2_I2C_ADDR, slave);
2423 return;
Hans de Goedea511ba92009-10-16 07:13:07 -03002424 case BRIDGE_W9968CF:
2425 sd->sensor_addr = slave;
Jean-François Moinef8f20182010-11-12 07:54:02 -03002426 return;
Hans de Goedea511ba92009-10-16 07:13:07 -03002427 }
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002428
Jean-François Moinef8f20182010-11-12 07:54:02 -03002429 reg_w(sd, R51x_I2C_W_SID, slave);
2430 reg_w(sd, R51x_I2C_R_SID, slave + 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002431}
2432
Jean-François Moinef8f20182010-11-12 07:54:02 -03002433static void write_regvals(struct sd *sd,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002434 const struct ov_regvals *regvals,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002435 int n)
2436{
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002437 while (--n >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03002438 reg_w(sd, regvals->reg, regvals->val);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002439 regvals++;
2440 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002441}
2442
Jean-François Moinef8f20182010-11-12 07:54:02 -03002443static void write_i2c_regvals(struct sd *sd,
2444 const struct ov_i2c_regvals *regvals,
2445 int n)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002446{
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002447 while (--n >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03002448 i2c_w(sd, regvals->reg, regvals->val);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002449 regvals++;
2450 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002451}
2452
2453/****************************************************************************
2454 *
2455 * OV511 and sensor configuration
2456 *
2457 ***************************************************************************/
2458
Hans de Goede635118d2009-10-11 09:49:03 -03002459/* This initializes the OV2x10 / OV3610 / OV3620 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002460static void ov_hires_configure(struct sd *sd)
Hans de Goede635118d2009-10-11 09:49:03 -03002461{
2462 int high, low;
2463
2464 if (sd->bridge != BRIDGE_OVFX2) {
Jean-François Moine0b656322010-09-13 05:19:58 -03002465 err("error hires sensors only supported with ovfx2");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002466 return;
Hans de Goede635118d2009-10-11 09:49:03 -03002467 }
2468
2469 PDEBUG(D_PROBE, "starting ov hires configuration");
2470
2471 /* Detect sensor (sub)type */
2472 high = i2c_r(sd, 0x0a);
2473 low = i2c_r(sd, 0x0b);
2474 /* info("%x, %x", high, low); */
2475 if (high == 0x96 && low == 0x40) {
2476 PDEBUG(D_PROBE, "Sensor is an OV2610");
2477 sd->sensor = SEN_OV2610;
2478 } else if (high == 0x36 && (low & 0x0f) == 0x00) {
2479 PDEBUG(D_PROBE, "Sensor is an OV3610");
2480 sd->sensor = SEN_OV3610;
2481 } else {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002482 err("Error unknown sensor type: %02x%02x",
Jean-François Moine87bae742010-11-12 05:31:34 -03002483 high, low);
Hans de Goede635118d2009-10-11 09:49:03 -03002484 }
Hans de Goede635118d2009-10-11 09:49:03 -03002485}
2486
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002487/* This initializes the OV8110, OV8610 sensor. The OV8110 uses
2488 * the same register settings as the OV8610, since they are very similar.
2489 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002490static void ov8xx0_configure(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002491{
2492 int rc;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002493
2494 PDEBUG(D_PROBE, "starting ov8xx0 configuration");
2495
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002496 /* Detect sensor (sub)type */
2497 rc = i2c_r(sd, OV7610_REG_COM_I);
2498 if (rc < 0) {
2499 PDEBUG(D_ERR, "Error detecting sensor type");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002500 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002501 }
Jean-François Moinef8f20182010-11-12 07:54:02 -03002502 if ((rc & 3) == 1)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002503 sd->sensor = SEN_OV8610;
Jean-François Moinef8f20182010-11-12 07:54:02 -03002504 else
Jean-François Moine0b656322010-09-13 05:19:58 -03002505 err("Unknown image sensor version: %d", rc & 3);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002506}
2507
2508/* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
2509 * the same register settings as the OV7610, since they are very similar.
2510 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002511static void ov7xx0_configure(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002512{
2513 int rc, high, low;
2514
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002515 PDEBUG(D_PROBE, "starting OV7xx0 configuration");
2516
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002517 /* Detect sensor (sub)type */
2518 rc = i2c_r(sd, OV7610_REG_COM_I);
2519
2520 /* add OV7670 here
2521 * it appears to be wrongly detected as a 7610 by default */
2522 if (rc < 0) {
2523 PDEBUG(D_ERR, "Error detecting sensor type");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002524 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002525 }
2526 if ((rc & 3) == 3) {
2527 /* quick hack to make OV7670s work */
2528 high = i2c_r(sd, 0x0a);
2529 low = i2c_r(sd, 0x0b);
2530 /* info("%x, %x", high, low); */
2531 if (high == 0x76 && low == 0x73) {
2532 PDEBUG(D_PROBE, "Sensor is an OV7670");
2533 sd->sensor = SEN_OV7670;
2534 } else {
2535 PDEBUG(D_PROBE, "Sensor is an OV7610");
2536 sd->sensor = SEN_OV7610;
2537 }
2538 } else if ((rc & 3) == 1) {
2539 /* I don't know what's different about the 76BE yet. */
Hans de Goedeb282d872009-06-14 19:10:40 -03002540 if (i2c_r(sd, 0x15) & 1) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002541 PDEBUG(D_PROBE, "Sensor is an OV7620AE");
Hans de Goede859cc472010-01-07 15:42:35 -03002542 sd->sensor = SEN_OV7620AE;
Hans de Goedeb282d872009-06-14 19:10:40 -03002543 } else {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002544 PDEBUG(D_PROBE, "Sensor is an OV76BE");
Hans de Goedeb282d872009-06-14 19:10:40 -03002545 sd->sensor = SEN_OV76BE;
2546 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002547 } else if ((rc & 3) == 0) {
2548 /* try to read product id registers */
2549 high = i2c_r(sd, 0x0a);
2550 if (high < 0) {
2551 PDEBUG(D_ERR, "Error detecting camera chip PID");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002552 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002553 }
2554 low = i2c_r(sd, 0x0b);
2555 if (low < 0) {
2556 PDEBUG(D_ERR, "Error detecting camera chip VER");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002557 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002558 }
2559 if (high == 0x76) {
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002560 switch (low) {
2561 case 0x30:
Jean-François Moine0b656322010-09-13 05:19:58 -03002562 err("Sensor is an OV7630/OV7635");
2563 err("7630 is not supported by this driver");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002564 return;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002565 case 0x40:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002566 PDEBUG(D_PROBE, "Sensor is an OV7645");
2567 sd->sensor = SEN_OV7640; /* FIXME */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002568 break;
2569 case 0x45:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002570 PDEBUG(D_PROBE, "Sensor is an OV7645B");
2571 sd->sensor = SEN_OV7640; /* FIXME */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002572 break;
2573 case 0x48:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002574 PDEBUG(D_PROBE, "Sensor is an OV7648");
Hans de Goede035d3a32010-01-09 08:14:43 -03002575 sd->sensor = SEN_OV7648;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002576 break;
2577 default:
2578 PDEBUG(D_PROBE, "Unknown sensor: 0x76%x", low);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002579 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002580 }
2581 } else {
2582 PDEBUG(D_PROBE, "Sensor is an OV7620");
2583 sd->sensor = SEN_OV7620;
2584 }
2585 } else {
Jean-François Moine0b656322010-09-13 05:19:58 -03002586 err("Unknown image sensor version: %d", rc & 3);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002587 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002588}
2589
2590/* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002591static void ov6xx0_configure(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002592{
2593 int rc;
Jean-Francois Moine4202f712008-09-03 17:12:15 -03002594 PDEBUG(D_PROBE, "starting OV6xx0 configuration");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002595
2596 /* Detect sensor (sub)type */
2597 rc = i2c_r(sd, OV7610_REG_COM_I);
2598 if (rc < 0) {
2599 PDEBUG(D_ERR, "Error detecting sensor type");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002600 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002601 }
2602
2603 /* Ugh. The first two bits are the version bits, but
2604 * the entire register value must be used. I guess OVT
2605 * underestimated how many variants they would make. */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002606 switch (rc) {
2607 case 0x00:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002608 sd->sensor = SEN_OV6630;
Jean-François Moine0b656322010-09-13 05:19:58 -03002609 warn("WARNING: Sensor is an OV66308. Your camera may have");
2610 warn("been misdetected in previous driver versions.");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002611 break;
2612 case 0x01:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002613 sd->sensor = SEN_OV6620;
Hans de Goede7d971372009-06-14 05:28:17 -03002614 PDEBUG(D_PROBE, "Sensor is an OV6620");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002615 break;
2616 case 0x02:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002617 sd->sensor = SEN_OV6630;
2618 PDEBUG(D_PROBE, "Sensor is an OV66308AE");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002619 break;
2620 case 0x03:
Hans de Goede7d971372009-06-14 05:28:17 -03002621 sd->sensor = SEN_OV66308AF;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002622 PDEBUG(D_PROBE, "Sensor is an OV66308AF");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002623 break;
2624 case 0x90:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002625 sd->sensor = SEN_OV6630;
Jean-François Moine0b656322010-09-13 05:19:58 -03002626 warn("WARNING: Sensor is an OV66307. Your camera may have");
2627 warn("been misdetected in previous driver versions.");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002628 break;
2629 default:
Jean-François Moine0b656322010-09-13 05:19:58 -03002630 err("FATAL: Unknown sensor version: 0x%02x", rc);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002631 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002632 }
2633
2634 /* Set sensor-specific vars */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002635 sd->sif = 1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002636}
2637
2638/* Turns on or off the LED. Only has an effect with OV511+/OV518(+)/OV519 */
2639static void ov51x_led_control(struct sd *sd, int on)
2640{
Hans de Goede9e4d8252009-06-14 06:25:06 -03002641 if (sd->invert_led)
2642 on = !on;
2643
Hans de Goede49809d62009-06-07 12:10:39 -03002644 switch (sd->bridge) {
2645 /* OV511 has no LED control */
2646 case BRIDGE_OV511PLUS:
Jean-François Moinea23acec42010-11-12 15:07:35 -03002647 reg_w(sd, R511_SYS_LED_CTL, on);
Hans de Goede49809d62009-06-07 12:10:39 -03002648 break;
2649 case BRIDGE_OV518:
2650 case BRIDGE_OV518PLUS:
Jean-François Moinea23acec42010-11-12 15:07:35 -03002651 reg_w_mask(sd, R518_GPIO_OUT, 0x02 * on, 0x02);
Hans de Goede49809d62009-06-07 12:10:39 -03002652 break;
2653 case BRIDGE_OV519:
Jean-François Moinea23acec42010-11-12 15:07:35 -03002654 reg_w_mask(sd, OV519_GPIO_DATA_OUT0, on, 1);
Hans de Goede49809d62009-06-07 12:10:39 -03002655 break;
2656 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002657}
2658
Hans de Goede417a4d22010-02-19 07:37:08 -03002659static void sd_reset_snapshot(struct gspca_dev *gspca_dev)
2660{
2661 struct sd *sd = (struct sd *) gspca_dev;
2662
2663 if (!sd->snapshot_needs_reset)
2664 return;
2665
2666 /* Note it is important that we clear sd->snapshot_needs_reset,
2667 before actually clearing the snapshot state in the bridge
2668 otherwise we might race with the pkt_scan interrupt handler */
2669 sd->snapshot_needs_reset = 0;
2670
2671 switch (sd->bridge) {
Hans de Goede88e8d202010-02-20 04:45:49 -03002672 case BRIDGE_OV511:
2673 case BRIDGE_OV511PLUS:
2674 reg_w(sd, R51x_SYS_SNAP, 0x02);
2675 reg_w(sd, R51x_SYS_SNAP, 0x00);
2676 break;
Hans de Goede92e232a2010-02-20 04:30:45 -03002677 case BRIDGE_OV518:
2678 case BRIDGE_OV518PLUS:
2679 reg_w(sd, R51x_SYS_SNAP, 0x02); /* Reset */
2680 reg_w(sd, R51x_SYS_SNAP, 0x01); /* Enable */
2681 break;
Hans de Goede417a4d22010-02-19 07:37:08 -03002682 case BRIDGE_OV519:
2683 reg_w(sd, R51x_SYS_RESET, 0x40);
2684 reg_w(sd, R51x_SYS_RESET, 0x00);
2685 break;
2686 }
2687}
2688
Jean-François Moinef8f20182010-11-12 07:54:02 -03002689static void ov51x_upload_quan_tables(struct sd *sd)
Hans de Goede49809d62009-06-07 12:10:39 -03002690{
Hans de Goede1876bb92009-06-14 06:45:50 -03002691 const unsigned char yQuanTable511[] = {
2692 0, 1, 1, 2, 2, 3, 3, 4,
2693 1, 1, 1, 2, 2, 3, 4, 4,
2694 1, 1, 2, 2, 3, 4, 4, 4,
2695 2, 2, 2, 3, 4, 4, 4, 4,
2696 2, 2, 3, 4, 4, 5, 5, 5,
2697 3, 3, 4, 4, 5, 5, 5, 5,
2698 3, 4, 4, 4, 5, 5, 5, 5,
2699 4, 4, 4, 4, 5, 5, 5, 5
2700 };
2701
2702 const unsigned char uvQuanTable511[] = {
2703 0, 2, 2, 3, 4, 4, 4, 4,
2704 2, 2, 2, 4, 4, 4, 4, 4,
2705 2, 2, 3, 4, 4, 4, 4, 4,
2706 3, 4, 4, 4, 4, 4, 4, 4,
2707 4, 4, 4, 4, 4, 4, 4, 4,
2708 4, 4, 4, 4, 4, 4, 4, 4,
2709 4, 4, 4, 4, 4, 4, 4, 4,
2710 4, 4, 4, 4, 4, 4, 4, 4
2711 };
2712
2713 /* OV518 quantization tables are 8x4 (instead of 8x8) */
Hans de Goede49809d62009-06-07 12:10:39 -03002714 const unsigned char yQuanTable518[] = {
2715 5, 4, 5, 6, 6, 7, 7, 7,
2716 5, 5, 5, 5, 6, 7, 7, 7,
2717 6, 6, 6, 6, 7, 7, 7, 8,
2718 7, 7, 6, 7, 7, 7, 8, 8
2719 };
Hans de Goede49809d62009-06-07 12:10:39 -03002720 const unsigned char uvQuanTable518[] = {
2721 6, 6, 6, 7, 7, 7, 7, 7,
2722 6, 6, 6, 7, 7, 7, 7, 7,
2723 6, 6, 6, 7, 7, 7, 7, 8,
2724 7, 7, 7, 7, 7, 7, 8, 8
2725 };
2726
Hans de Goede1876bb92009-06-14 06:45:50 -03002727 const unsigned char *pYTable, *pUVTable;
Hans de Goede49809d62009-06-07 12:10:39 -03002728 unsigned char val0, val1;
Jean-François Moinef8f20182010-11-12 07:54:02 -03002729 int i, size, reg = R51x_COMP_LUT_BEGIN;
Hans de Goede49809d62009-06-07 12:10:39 -03002730
2731 PDEBUG(D_PROBE, "Uploading quantization tables");
2732
Hans de Goede1876bb92009-06-14 06:45:50 -03002733 if (sd->bridge == BRIDGE_OV511 || sd->bridge == BRIDGE_OV511PLUS) {
2734 pYTable = yQuanTable511;
2735 pUVTable = uvQuanTable511;
Jean-François Moine87bae742010-11-12 05:31:34 -03002736 size = 32;
Hans de Goede1876bb92009-06-14 06:45:50 -03002737 } else {
2738 pYTable = yQuanTable518;
2739 pUVTable = uvQuanTable518;
Jean-François Moine87bae742010-11-12 05:31:34 -03002740 size = 16;
Hans de Goede1876bb92009-06-14 06:45:50 -03002741 }
2742
2743 for (i = 0; i < size; i++) {
Hans de Goede49809d62009-06-07 12:10:39 -03002744 val0 = *pYTable++;
2745 val1 = *pYTable++;
2746 val0 &= 0x0f;
2747 val1 &= 0x0f;
2748 val0 |= val1 << 4;
Jean-François Moinef8f20182010-11-12 07:54:02 -03002749 reg_w(sd, reg, val0);
Hans de Goede49809d62009-06-07 12:10:39 -03002750
2751 val0 = *pUVTable++;
2752 val1 = *pUVTable++;
2753 val0 &= 0x0f;
2754 val1 &= 0x0f;
2755 val0 |= val1 << 4;
Jean-François Moinef8f20182010-11-12 07:54:02 -03002756 reg_w(sd, reg + size, val0);
Hans de Goede49809d62009-06-07 12:10:39 -03002757
2758 reg++;
2759 }
Hans de Goede49809d62009-06-07 12:10:39 -03002760}
2761
Hans de Goede1876bb92009-06-14 06:45:50 -03002762/* This initializes the OV511/OV511+ and the sensor */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002763static void ov511_configure(struct gspca_dev *gspca_dev)
Hans de Goede1876bb92009-06-14 06:45:50 -03002764{
2765 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede1876bb92009-06-14 06:45:50 -03002766
2767 /* For 511 and 511+ */
2768 const struct ov_regvals init_511[] = {
2769 { R51x_SYS_RESET, 0x7f },
2770 { R51x_SYS_INIT, 0x01 },
2771 { R51x_SYS_RESET, 0x7f },
2772 { R51x_SYS_INIT, 0x01 },
2773 { R51x_SYS_RESET, 0x3f },
2774 { R51x_SYS_INIT, 0x01 },
2775 { R51x_SYS_RESET, 0x3d },
2776 };
2777
2778 const struct ov_regvals norm_511[] = {
Jean-François Moine780e3122010-10-19 04:29:10 -03002779 { R511_DRAM_FLOW_CTL, 0x01 },
Hans de Goede1876bb92009-06-14 06:45:50 -03002780 { R51x_SYS_SNAP, 0x00 },
2781 { R51x_SYS_SNAP, 0x02 },
2782 { R51x_SYS_SNAP, 0x00 },
2783 { R511_FIFO_OPTS, 0x1f },
2784 { R511_COMP_EN, 0x00 },
2785 { R511_COMP_LUT_EN, 0x03 },
2786 };
2787
2788 const struct ov_regvals norm_511_p[] = {
2789 { R511_DRAM_FLOW_CTL, 0xff },
2790 { R51x_SYS_SNAP, 0x00 },
2791 { R51x_SYS_SNAP, 0x02 },
2792 { R51x_SYS_SNAP, 0x00 },
2793 { R511_FIFO_OPTS, 0xff },
2794 { R511_COMP_EN, 0x00 },
2795 { R511_COMP_LUT_EN, 0x03 },
2796 };
2797
2798 const struct ov_regvals compress_511[] = {
2799 { 0x70, 0x1f },
2800 { 0x71, 0x05 },
2801 { 0x72, 0x06 },
2802 { 0x73, 0x06 },
2803 { 0x74, 0x14 },
2804 { 0x75, 0x03 },
2805 { 0x76, 0x04 },
2806 { 0x77, 0x04 },
2807 };
2808
2809 PDEBUG(D_PROBE, "Device custom id %x", reg_r(sd, R51x_SYS_CUST_ID));
2810
Jean-François Moinef8f20182010-11-12 07:54:02 -03002811 write_regvals(sd, init_511, ARRAY_SIZE(init_511));
Hans de Goede1876bb92009-06-14 06:45:50 -03002812
2813 switch (sd->bridge) {
2814 case BRIDGE_OV511:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002815 write_regvals(sd, norm_511, ARRAY_SIZE(norm_511));
Hans de Goede1876bb92009-06-14 06:45:50 -03002816 break;
2817 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002818 write_regvals(sd, norm_511_p, ARRAY_SIZE(norm_511_p));
Hans de Goede1876bb92009-06-14 06:45:50 -03002819 break;
2820 }
2821
2822 /* Init compression */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002823 write_regvals(sd, compress_511, ARRAY_SIZE(compress_511));
Hans de Goede1876bb92009-06-14 06:45:50 -03002824
Jean-François Moinef8f20182010-11-12 07:54:02 -03002825 ov51x_upload_quan_tables(sd);
Hans de Goede1876bb92009-06-14 06:45:50 -03002826}
2827
Hans de Goede49809d62009-06-07 12:10:39 -03002828/* This initializes the OV518/OV518+ and the sensor */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002829static void ov518_configure(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002830{
2831 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002832
Hans de Goede49809d62009-06-07 12:10:39 -03002833 /* For 518 and 518+ */
Hans de Goedee080fcd2009-06-18 05:03:16 -03002834 const struct ov_regvals init_518[] = {
Hans de Goede49809d62009-06-07 12:10:39 -03002835 { R51x_SYS_RESET, 0x40 },
2836 { R51x_SYS_INIT, 0xe1 },
2837 { R51x_SYS_RESET, 0x3e },
2838 { R51x_SYS_INIT, 0xe1 },
2839 { R51x_SYS_RESET, 0x00 },
2840 { R51x_SYS_INIT, 0xe1 },
2841 { 0x46, 0x00 },
2842 { 0x5d, 0x03 },
2843 };
2844
Hans de Goedee080fcd2009-06-18 05:03:16 -03002845 const struct ov_regvals norm_518[] = {
Hans de Goede49809d62009-06-07 12:10:39 -03002846 { R51x_SYS_SNAP, 0x02 }, /* Reset */
2847 { R51x_SYS_SNAP, 0x01 }, /* Enable */
Jean-François Moine780e3122010-10-19 04:29:10 -03002848 { 0x31, 0x0f },
Hans de Goede49809d62009-06-07 12:10:39 -03002849 { 0x5d, 0x03 },
2850 { 0x24, 0x9f },
2851 { 0x25, 0x90 },
2852 { 0x20, 0x00 },
2853 { 0x51, 0x04 },
2854 { 0x71, 0x19 },
2855 { 0x2f, 0x80 },
2856 };
2857
Hans de Goedee080fcd2009-06-18 05:03:16 -03002858 const struct ov_regvals norm_518_p[] = {
Hans de Goede49809d62009-06-07 12:10:39 -03002859 { R51x_SYS_SNAP, 0x02 }, /* Reset */
2860 { R51x_SYS_SNAP, 0x01 }, /* Enable */
Jean-François Moine780e3122010-10-19 04:29:10 -03002861 { 0x31, 0x0f },
Hans de Goede49809d62009-06-07 12:10:39 -03002862 { 0x5d, 0x03 },
2863 { 0x24, 0x9f },
2864 { 0x25, 0x90 },
2865 { 0x20, 0x60 },
2866 { 0x51, 0x02 },
2867 { 0x71, 0x19 },
2868 { 0x40, 0xff },
2869 { 0x41, 0x42 },
2870 { 0x46, 0x00 },
2871 { 0x33, 0x04 },
2872 { 0x21, 0x19 },
2873 { 0x3f, 0x10 },
2874 { 0x2f, 0x80 },
2875 };
2876
2877 /* First 5 bits of custom ID reg are a revision ID on OV518 */
2878 PDEBUG(D_PROBE, "Device revision %d",
Jean-François Moine87bae742010-11-12 05:31:34 -03002879 0x1f & reg_r(sd, R51x_SYS_CUST_ID));
Hans de Goede49809d62009-06-07 12:10:39 -03002880
Jean-François Moinef8f20182010-11-12 07:54:02 -03002881 write_regvals(sd, init_518, ARRAY_SIZE(init_518));
Hans de Goede49809d62009-06-07 12:10:39 -03002882
2883 /* Set LED GPIO pin to output mode */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002884 reg_w_mask(sd, R518_GPIO_CTL, 0x00, 0x02);
Hans de Goede49809d62009-06-07 12:10:39 -03002885
2886 switch (sd->bridge) {
2887 case BRIDGE_OV518:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002888 write_regvals(sd, norm_518, ARRAY_SIZE(norm_518));
Hans de Goede49809d62009-06-07 12:10:39 -03002889 break;
2890 case BRIDGE_OV518PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002891 write_regvals(sd, norm_518_p, ARRAY_SIZE(norm_518_p));
Hans de Goede49809d62009-06-07 12:10:39 -03002892 break;
2893 }
2894
Jean-François Moinef8f20182010-11-12 07:54:02 -03002895 ov51x_upload_quan_tables(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03002896
Jean-François Moinef8f20182010-11-12 07:54:02 -03002897 reg_w(sd, 0x2f, 0x80);
Hans de Goede49809d62009-06-07 12:10:39 -03002898}
2899
Jean-François Moinef8f20182010-11-12 07:54:02 -03002900static void ov519_configure(struct sd *sd)
Hans de Goede49809d62009-06-07 12:10:39 -03002901{
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002902 static const struct ov_regvals init_519[] = {
Jean-François Moine87bae742010-11-12 05:31:34 -03002903 { 0x5a, 0x6d }, /* EnableSystem */
2904 { 0x53, 0x9b },
Jean-François Moine21867802010-11-12 06:12:09 -03002905 { OV519_R54_EN_CLK1, 0xff }, /* set bit2 to enable jpeg */
Jean-François Moine87bae742010-11-12 05:31:34 -03002906 { 0x5d, 0x03 },
2907 { 0x49, 0x01 },
2908 { 0x48, 0x00 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002909 /* Set LED pin to output mode. Bit 4 must be cleared or sensor
2910 * detection will fail. This deserves further investigation. */
2911 { OV519_GPIO_IO_CTRL0, 0xee },
Jean-François Moine21867802010-11-12 06:12:09 -03002912 { OV519_R51_RESET1, 0x0f },
2913 { OV519_R51_RESET1, 0x00 },
Jean-François Moine87bae742010-11-12 05:31:34 -03002914 { 0x22, 0x00 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002915 /* windows reads 0x55 at this point*/
2916 };
2917
Jean-François Moinef8f20182010-11-12 07:54:02 -03002918 write_regvals(sd, init_519, ARRAY_SIZE(init_519));
Hans de Goede49809d62009-06-07 12:10:39 -03002919}
2920
Jean-François Moinef8f20182010-11-12 07:54:02 -03002921static void ovfx2_configure(struct sd *sd)
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002922{
2923 static const struct ov_regvals init_fx2[] = {
2924 { 0x00, 0x60 },
2925 { 0x02, 0x01 },
2926 { 0x0f, 0x1d },
2927 { 0xe9, 0x82 },
2928 { 0xea, 0xc7 },
2929 { 0xeb, 0x10 },
2930 { 0xec, 0xf6 },
2931 };
2932
2933 sd->stopped = 1;
2934
Jean-François Moinef8f20182010-11-12 07:54:02 -03002935 write_regvals(sd, init_fx2, ARRAY_SIZE(init_fx2));
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002936}
2937
Hans de Goede49809d62009-06-07 12:10:39 -03002938/* this function is called at probe time */
2939static int sd_config(struct gspca_dev *gspca_dev,
2940 const struct usb_device_id *id)
2941{
2942 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002943 struct cam *cam = &gspca_dev->cam;
Hans de Goede49809d62009-06-07 12:10:39 -03002944
Hans de Goede9e4d8252009-06-14 06:25:06 -03002945 sd->bridge = id->driver_info & BRIDGE_MASK;
Jean-François Moinea23acec42010-11-12 15:07:35 -03002946 sd->invert_led = (id->driver_info & BRIDGE_INVERT_LED) != 0;
Hans de Goede49809d62009-06-07 12:10:39 -03002947
2948 switch (sd->bridge) {
Hans de Goede1876bb92009-06-14 06:45:50 -03002949 case BRIDGE_OV511:
2950 case BRIDGE_OV511PLUS:
Jean-François Moine7491f782010-11-13 03:56:41 -03002951 cam->cam_mode = ov511_vga_mode;
2952 cam->nmodes = ARRAY_SIZE(ov511_vga_mode);
2953 break;
2954 case BRIDGE_OV518:
2955 case BRIDGE_OV518PLUS:
2956 cam->cam_mode = ov518_vga_mode;
2957 cam->nmodes = ARRAY_SIZE(ov518_vga_mode);
2958 break;
2959 case BRIDGE_OV519:
2960 cam->cam_mode = ov519_vga_mode;
2961 cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
2962 sd->invert_led = !sd->invert_led;
2963 break;
2964 case BRIDGE_OVFX2:
2965 cam->cam_mode = ov519_vga_mode;
2966 cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
2967 cam->bulk_size = OVFX2_BULK_SIZE;
2968 cam->bulk_nurbs = MAX_NURBS;
2969 cam->bulk = 1;
2970 break;
2971 case BRIDGE_W9968CF:
2972 cam->cam_mode = w9968cf_vga_mode;
2973 cam->nmodes = ARRAY_SIZE(w9968cf_vga_mode);
2974 cam->reverse_alts = 1;
2975 break;
2976 }
2977
2978 gspca_dev->cam.ctrls = sd->ctrls;
2979 sd->quality = QUALITY_DEF;
2980
2981 return 0;
2982}
2983
2984/* this function is called at probe and resume time */
2985static int sd_init(struct gspca_dev *gspca_dev)
2986{
2987 struct sd *sd = (struct sd *) gspca_dev;
2988 struct cam *cam = &gspca_dev->cam;
2989
2990 switch (sd->bridge) {
2991 case BRIDGE_OV511:
2992 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002993 ov511_configure(gspca_dev);
Hans de Goede1876bb92009-06-14 06:45:50 -03002994 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002995 case BRIDGE_OV518:
2996 case BRIDGE_OV518PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002997 ov518_configure(gspca_dev);
Hans de Goede49809d62009-06-07 12:10:39 -03002998 break;
2999 case BRIDGE_OV519:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003000 ov519_configure(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03003001 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003002 case BRIDGE_OVFX2:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003003 ovfx2_configure(sd);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003004 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03003005 case BRIDGE_W9968CF:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003006 w9968cf_configure(sd);
Hans de Goedea511ba92009-10-16 07:13:07 -03003007 break;
Hans de Goede49809d62009-06-07 12:10:39 -03003008 }
3009
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003010 /* The OV519 must be more aggressive about sensor detection since
3011 * I2C write will never fail if the sensor is not present. We have
3012 * to try to initialize the sensor to detect its presence */
Jean-François Moine7bbe6b82010-11-11 08:27:24 -03003013 sd->sensor = -1;
Hans de Goede229bb7d2009-10-11 07:41:46 -03003014
3015 /* Test for 76xx */
3016 if (init_ov_sensor(sd, OV7xx0_SID) >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03003017 ov7xx0_configure(sd);
3018
Hans de Goede229bb7d2009-10-11 07:41:46 -03003019 /* Test for 6xx0 */
3020 } else if (init_ov_sensor(sd, OV6xx0_SID) >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03003021 ov6xx0_configure(sd);
3022
Hans de Goede229bb7d2009-10-11 07:41:46 -03003023 /* Test for 8xx0 */
3024 } else if (init_ov_sensor(sd, OV8xx0_SID) >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03003025 ov8xx0_configure(sd);
3026
Hans de Goede635118d2009-10-11 09:49:03 -03003027 /* Test for 3xxx / 2xxx */
3028 } else if (init_ov_sensor(sd, OV_HIRES_SID) >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03003029 ov_hires_configure(sd);
Hans de Goede229bb7d2009-10-11 07:41:46 -03003030 } else {
Jean-François Moine0b656322010-09-13 05:19:58 -03003031 err("Can't determine sensor slave IDs");
Hans de Goede229bb7d2009-10-11 07:41:46 -03003032 goto error;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003033 }
3034
Jean-François Moine7bbe6b82010-11-11 08:27:24 -03003035 if (sd->sensor < 0)
3036 goto error;
3037
Jean-François Moine7491f782010-11-13 03:56:41 -03003038 ov51x_led_control(sd, 0); /* turn LED off */
3039
Hans de Goede49809d62009-06-07 12:10:39 -03003040 switch (sd->bridge) {
Hans de Goede1876bb92009-06-14 06:45:50 -03003041 case BRIDGE_OV511:
3042 case BRIDGE_OV511PLUS:
Jean-François Moine7491f782010-11-13 03:56:41 -03003043 if (sd->sif) {
Hans de Goede1876bb92009-06-14 06:45:50 -03003044 cam->cam_mode = ov511_sif_mode;
3045 cam->nmodes = ARRAY_SIZE(ov511_sif_mode);
3046 }
3047 break;
Hans de Goede49809d62009-06-07 12:10:39 -03003048 case BRIDGE_OV518:
3049 case BRIDGE_OV518PLUS:
Jean-François Moine7491f782010-11-13 03:56:41 -03003050 if (sd->sif) {
Hans de Goede49809d62009-06-07 12:10:39 -03003051 cam->cam_mode = ov518_sif_mode;
3052 cam->nmodes = ARRAY_SIZE(ov518_sif_mode);
3053 }
3054 break;
3055 case BRIDGE_OV519:
Jean-François Moine7491f782010-11-13 03:56:41 -03003056 if (sd->sif) {
Hans de Goede49809d62009-06-07 12:10:39 -03003057 cam->cam_mode = ov519_sif_mode;
3058 cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
3059 }
3060 break;
Hans de Goede635118d2009-10-11 09:49:03 -03003061 case BRIDGE_OVFX2:
3062 if (sd->sensor == SEN_OV2610) {
3063 cam->cam_mode = ovfx2_ov2610_mode;
3064 cam->nmodes = ARRAY_SIZE(ovfx2_ov2610_mode);
3065 } else if (sd->sensor == SEN_OV3610) {
3066 cam->cam_mode = ovfx2_ov3610_mode;
3067 cam->nmodes = ARRAY_SIZE(ovfx2_ov3610_mode);
Jean-François Moine7491f782010-11-13 03:56:41 -03003068 } else if (sd->sif) {
Hans de Goede635118d2009-10-11 09:49:03 -03003069 cam->cam_mode = ov519_sif_mode;
3070 cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
3071 }
3072 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03003073 case BRIDGE_W9968CF:
Hans de Goede79b35902009-10-19 06:08:01 -03003074 if (sd->sif)
Jean-François Moine7491f782010-11-13 03:56:41 -03003075 cam->nmodes = ARRAY_SIZE(w9968cf_vga_mode) - 1;
Hans de Goedea511ba92009-10-16 07:13:07 -03003076
3077 /* w9968cf needs initialisation once the sensor is known */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003078 w9968cf_init(sd);
Hans de Goedea511ba92009-10-16 07:13:07 -03003079 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003080 }
Jean-François Moine83db7682010-11-12 07:14:08 -03003081
3082 gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
Hans de Goede02ab18b2009-06-14 04:32:04 -03003083
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003084 /* initialize the sensor */
3085 switch (sd->sensor) {
Hans de Goede635118d2009-10-11 09:49:03 -03003086 case SEN_OV2610:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003087 write_i2c_regvals(sd, norm_2610, ARRAY_SIZE(norm_2610));
3088
Hans de Goede635118d2009-10-11 09:49:03 -03003089 /* Enable autogain, autoexpo, awb, bandfilter */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003090 i2c_w_mask(sd, 0x13, 0x27, 0x27);
Hans de Goede635118d2009-10-11 09:49:03 -03003091 break;
3092 case SEN_OV3610:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003093 write_i2c_regvals(sd, norm_3620b, ARRAY_SIZE(norm_3620b));
3094
Hans de Goede635118d2009-10-11 09:49:03 -03003095 /* Enable autogain, autoexpo, awb, bandfilter */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003096 i2c_w_mask(sd, 0x13, 0x27, 0x27);
Hans de Goede635118d2009-10-11 09:49:03 -03003097 break;
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003098 case SEN_OV6620:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003099 write_i2c_regvals(sd, norm_6x20, ARRAY_SIZE(norm_6x20));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003100 break;
3101 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03003102 case SEN_OV66308AF:
Jean-François Moine62833ac2010-10-02 04:27:02 -03003103 sd->ctrls[CONTRAST].def = 200;
3104 /* The default is too low for the ov6630 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003105 write_i2c_regvals(sd, norm_6x30, ARRAY_SIZE(norm_6x30));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003106 break;
3107 default:
3108/* case SEN_OV7610: */
3109/* case SEN_OV76BE: */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003110 write_i2c_regvals(sd, norm_7610, ARRAY_SIZE(norm_7610));
3111 i2c_w_mask(sd, 0x0e, 0x00, 0x40);
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003112 break;
3113 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03003114 case SEN_OV7620AE:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003115 write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003116 break;
3117 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003118 case SEN_OV7648:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003119 write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003120 break;
3121 case SEN_OV7670:
Jean-François Moine62833ac2010-10-02 04:27:02 -03003122 sd->ctrls[FREQ].max = 3; /* auto */
3123 sd->ctrls[FREQ].def = 3;
Jean-François Moinef8f20182010-11-12 07:54:02 -03003124 write_i2c_regvals(sd, norm_7670, ARRAY_SIZE(norm_7670));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003125 break;
3126 case SEN_OV8610:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003127 write_i2c_regvals(sd, norm_8610, ARRAY_SIZE(norm_8610));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003128 break;
3129 }
Jean-François Moinef8f20182010-11-12 07:54:02 -03003130 return gspca_dev->usb_err;
Jean-François Moine7491f782010-11-13 03:56:41 -03003131error:
3132 PDEBUG(D_ERR, "OV519 Config failed");
3133 return -EINVAL;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003134}
3135
Hans de Goede1876bb92009-06-14 06:45:50 -03003136/* Set up the OV511/OV511+ with the given image parameters.
3137 *
3138 * Do not put any sensor-specific code in here (including I2C I/O functions)
3139 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003140static void ov511_mode_init_regs(struct sd *sd)
Hans de Goede1876bb92009-06-14 06:45:50 -03003141{
3142 int hsegs, vsegs, packet_size, fps, needed;
3143 int interlaced = 0;
3144 struct usb_host_interface *alt;
3145 struct usb_interface *intf;
3146
3147 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
3148 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
3149 if (!alt) {
Jean-François Moine0b656322010-09-13 05:19:58 -03003150 err("Couldn't get altsetting");
Jean-François Moinef8f20182010-11-12 07:54:02 -03003151 sd->gspca_dev.usb_err = -EIO;
3152 return;
Hans de Goede1876bb92009-06-14 06:45:50 -03003153 }
3154
3155 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
3156 reg_w(sd, R51x_FIFO_PSIZE, packet_size >> 5);
3157
3158 reg_w(sd, R511_CAM_UV_EN, 0x01);
3159 reg_w(sd, R511_SNAP_UV_EN, 0x01);
3160 reg_w(sd, R511_SNAP_OPTS, 0x03);
3161
3162 /* Here I'm assuming that snapshot size == image size.
3163 * I hope that's always true. --claudio
3164 */
3165 hsegs = (sd->gspca_dev.width >> 3) - 1;
3166 vsegs = (sd->gspca_dev.height >> 3) - 1;
3167
3168 reg_w(sd, R511_CAM_PXCNT, hsegs);
3169 reg_w(sd, R511_CAM_LNCNT, vsegs);
3170 reg_w(sd, R511_CAM_PXDIV, 0x00);
3171 reg_w(sd, R511_CAM_LNDIV, 0x00);
3172
3173 /* YUV420, low pass filter on */
3174 reg_w(sd, R511_CAM_OPTS, 0x03);
3175
3176 /* Snapshot additions */
3177 reg_w(sd, R511_SNAP_PXCNT, hsegs);
3178 reg_w(sd, R511_SNAP_LNCNT, vsegs);
3179 reg_w(sd, R511_SNAP_PXDIV, 0x00);
3180 reg_w(sd, R511_SNAP_LNDIV, 0x00);
3181
3182 /******** Set the framerate ********/
3183 if (frame_rate > 0)
3184 sd->frame_rate = frame_rate;
3185
3186 switch (sd->sensor) {
3187 case SEN_OV6620:
3188 /* No framerate control, doesn't like higher rates yet */
3189 sd->clockdiv = 3;
3190 break;
3191
3192 /* Note once the FIXME's in mode_init_ov_sensor_regs() are fixed
3193 for more sensors we need to do this for them too */
3194 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03003195 case SEN_OV7620AE:
Hans de Goede1876bb92009-06-14 06:45:50 -03003196 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003197 case SEN_OV7648:
Hans de Goedeb282d872009-06-14 19:10:40 -03003198 case SEN_OV76BE:
Hans de Goede1876bb92009-06-14 06:45:50 -03003199 if (sd->gspca_dev.width == 320)
3200 interlaced = 1;
3201 /* Fall through */
3202 case SEN_OV6630:
Hans de Goede1876bb92009-06-14 06:45:50 -03003203 case SEN_OV7610:
3204 case SEN_OV7670:
3205 switch (sd->frame_rate) {
3206 case 30:
3207 case 25:
3208 /* Not enough bandwidth to do 640x480 @ 30 fps */
3209 if (sd->gspca_dev.width != 640) {
3210 sd->clockdiv = 0;
3211 break;
3212 }
3213 /* Fall through for 640x480 case */
3214 default:
3215/* case 20: */
3216/* case 15: */
3217 sd->clockdiv = 1;
3218 break;
3219 case 10:
3220 sd->clockdiv = 2;
3221 break;
3222 case 5:
3223 sd->clockdiv = 5;
3224 break;
3225 }
3226 if (interlaced) {
3227 sd->clockdiv = (sd->clockdiv + 1) * 2 - 1;
3228 /* Higher then 10 does not work */
3229 if (sd->clockdiv > 10)
3230 sd->clockdiv = 10;
3231 }
3232 break;
3233
3234 case SEN_OV8610:
3235 /* No framerate control ?? */
3236 sd->clockdiv = 0;
3237 break;
3238 }
3239
3240 /* Check if we have enough bandwidth to disable compression */
3241 fps = (interlaced ? 60 : 30) / (sd->clockdiv + 1) + 1;
3242 needed = fps * sd->gspca_dev.width * sd->gspca_dev.height * 3 / 2;
3243 /* 1400 is a conservative estimate of the max nr of isoc packets/sec */
3244 if (needed > 1400 * packet_size) {
3245 /* Enable Y and UV quantization and compression */
3246 reg_w(sd, R511_COMP_EN, 0x07);
3247 reg_w(sd, R511_COMP_LUT_EN, 0x03);
3248 } else {
3249 reg_w(sd, R511_COMP_EN, 0x06);
3250 reg_w(sd, R511_COMP_LUT_EN, 0x00);
3251 }
3252
3253 reg_w(sd, R51x_SYS_RESET, OV511_RESET_OMNICE);
3254 reg_w(sd, R51x_SYS_RESET, 0);
Hans de Goede1876bb92009-06-14 06:45:50 -03003255}
3256
Hans de Goede49809d62009-06-07 12:10:39 -03003257/* Sets up the OV518/OV518+ with the given image parameters
3258 *
3259 * OV518 needs a completely different approach, until we can figure out what
3260 * the individual registers do. Also, only 15 FPS is supported now.
3261 *
3262 * Do not put any sensor-specific code in here (including I2C I/O functions)
3263 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003264static void ov518_mode_init_regs(struct sd *sd)
Hans de Goede49809d62009-06-07 12:10:39 -03003265{
Hans de Goedeb282d872009-06-14 19:10:40 -03003266 int hsegs, vsegs, packet_size;
3267 struct usb_host_interface *alt;
3268 struct usb_interface *intf;
3269
3270 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
3271 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
3272 if (!alt) {
Jean-François Moine0b656322010-09-13 05:19:58 -03003273 err("Couldn't get altsetting");
Jean-François Moinef8f20182010-11-12 07:54:02 -03003274 sd->gspca_dev.usb_err = -EIO;
3275 return;
Hans de Goedeb282d872009-06-14 19:10:40 -03003276 }
3277
3278 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
3279 ov518_reg_w32(sd, R51x_FIFO_PSIZE, packet_size & ~7, 2);
Hans de Goede49809d62009-06-07 12:10:39 -03003280
3281 /******** Set the mode ********/
Hans de Goede49809d62009-06-07 12:10:39 -03003282 reg_w(sd, 0x2b, 0);
3283 reg_w(sd, 0x2c, 0);
3284 reg_w(sd, 0x2d, 0);
3285 reg_w(sd, 0x2e, 0);
3286 reg_w(sd, 0x3b, 0);
3287 reg_w(sd, 0x3c, 0);
3288 reg_w(sd, 0x3d, 0);
3289 reg_w(sd, 0x3e, 0);
3290
3291 if (sd->bridge == BRIDGE_OV518) {
3292 /* Set 8-bit (YVYU) input format */
3293 reg_w_mask(sd, 0x20, 0x08, 0x08);
3294
3295 /* Set 12-bit (4:2:0) output format */
3296 reg_w_mask(sd, 0x28, 0x80, 0xf0);
3297 reg_w_mask(sd, 0x38, 0x80, 0xf0);
3298 } else {
3299 reg_w(sd, 0x28, 0x80);
3300 reg_w(sd, 0x38, 0x80);
3301 }
3302
3303 hsegs = sd->gspca_dev.width / 16;
3304 vsegs = sd->gspca_dev.height / 4;
3305
3306 reg_w(sd, 0x29, hsegs);
3307 reg_w(sd, 0x2a, vsegs);
3308
3309 reg_w(sd, 0x39, hsegs);
3310 reg_w(sd, 0x3a, vsegs);
3311
3312 /* Windows driver does this here; who knows why */
3313 reg_w(sd, 0x2f, 0x80);
3314
Jean-François Moine87bae742010-11-12 05:31:34 -03003315 /******** Set the framerate ********/
Hans de Goedeb282d872009-06-14 19:10:40 -03003316 sd->clockdiv = 1;
Hans de Goede49809d62009-06-07 12:10:39 -03003317
3318 /* Mode independent, but framerate dependent, regs */
Hans de Goedeb282d872009-06-14 19:10:40 -03003319 /* 0x51: Clock divider; Only works on some cams which use 2 crystals */
3320 reg_w(sd, 0x51, 0x04);
Hans de Goede49809d62009-06-07 12:10:39 -03003321 reg_w(sd, 0x22, 0x18);
3322 reg_w(sd, 0x23, 0xff);
3323
Hans de Goedeb282d872009-06-14 19:10:40 -03003324 if (sd->bridge == BRIDGE_OV518PLUS) {
3325 switch (sd->sensor) {
Hans de Goede859cc472010-01-07 15:42:35 -03003326 case SEN_OV7620AE:
Hans de Goedeb282d872009-06-14 19:10:40 -03003327 if (sd->gspca_dev.width == 320) {
3328 reg_w(sd, 0x20, 0x00);
3329 reg_w(sd, 0x21, 0x19);
3330 } else {
3331 reg_w(sd, 0x20, 0x60);
3332 reg_w(sd, 0x21, 0x1f);
3333 }
3334 break;
Hans de Goede859cc472010-01-07 15:42:35 -03003335 case SEN_OV7620:
3336 reg_w(sd, 0x20, 0x00);
3337 reg_w(sd, 0x21, 0x19);
3338 break;
Hans de Goedeb282d872009-06-14 19:10:40 -03003339 default:
3340 reg_w(sd, 0x21, 0x19);
3341 }
3342 } else
Hans de Goede49809d62009-06-07 12:10:39 -03003343 reg_w(sd, 0x71, 0x17); /* Compression-related? */
3344
3345 /* FIXME: Sensor-specific */
3346 /* Bit 5 is what matters here. Of course, it is "reserved" */
3347 i2c_w(sd, 0x54, 0x23);
3348
3349 reg_w(sd, 0x2f, 0x80);
3350
3351 if (sd->bridge == BRIDGE_OV518PLUS) {
3352 reg_w(sd, 0x24, 0x94);
3353 reg_w(sd, 0x25, 0x90);
3354 ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
3355 ov518_reg_w32(sd, 0xc6, 540, 2); /* 21ch */
3356 ov518_reg_w32(sd, 0xc7, 540, 2); /* 21ch */
3357 ov518_reg_w32(sd, 0xc8, 108, 2); /* 6ch */
3358 ov518_reg_w32(sd, 0xca, 131098, 3); /* 2001ah */
3359 ov518_reg_w32(sd, 0xcb, 532, 2); /* 214h */
3360 ov518_reg_w32(sd, 0xcc, 2400, 2); /* 960h */
3361 ov518_reg_w32(sd, 0xcd, 32, 2); /* 20h */
3362 ov518_reg_w32(sd, 0xce, 608, 2); /* 260h */
3363 } else {
3364 reg_w(sd, 0x24, 0x9f);
3365 reg_w(sd, 0x25, 0x90);
3366 ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
3367 ov518_reg_w32(sd, 0xc6, 381, 2); /* 17dh */
3368 ov518_reg_w32(sd, 0xc7, 381, 2); /* 17dh */
3369 ov518_reg_w32(sd, 0xc8, 128, 2); /* 80h */
3370 ov518_reg_w32(sd, 0xca, 183331, 3); /* 2cc23h */
3371 ov518_reg_w32(sd, 0xcb, 746, 2); /* 2eah */
3372 ov518_reg_w32(sd, 0xcc, 1750, 2); /* 6d6h */
3373 ov518_reg_w32(sd, 0xcd, 45, 2); /* 2dh */
3374 ov518_reg_w32(sd, 0xce, 851, 2); /* 353h */
3375 }
3376
3377 reg_w(sd, 0x2f, 0x80);
Hans de Goede49809d62009-06-07 12:10:39 -03003378}
3379
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003380/* Sets up the OV519 with the given image parameters
3381 *
3382 * OV519 needs a completely different approach, until we can figure out what
3383 * the individual registers do.
3384 *
3385 * Do not put any sensor-specific code in here (including I2C I/O functions)
3386 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003387static void ov519_mode_init_regs(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003388{
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03003389 static const struct ov_regvals mode_init_519_ov7670[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003390 { 0x5d, 0x03 }, /* Turn off suspend mode */
3391 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
Jean-François Moine21867802010-11-12 06:12:09 -03003392 { OV519_R54_EN_CLK1, 0x0f }, /* bit2 (jpeg enable) */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003393 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
3394 { 0xa3, 0x18 },
3395 { 0xa4, 0x04 },
3396 { 0xa5, 0x28 },
3397 { 0x37, 0x00 }, /* SetUsbInit */
3398 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
3399 /* Enable both fields, YUV Input, disable defect comp (why?) */
3400 { 0x20, 0x0c },
3401 { 0x21, 0x38 },
3402 { 0x22, 0x1d },
3403 { 0x17, 0x50 }, /* undocumented */
3404 { 0x37, 0x00 }, /* undocumented */
3405 { 0x40, 0xff }, /* I2C timeout counter */
3406 { 0x46, 0x00 }, /* I2C clock prescaler */
3407 { 0x59, 0x04 }, /* new from windrv 090403 */
3408 { 0xff, 0x00 }, /* undocumented */
3409 /* windows reads 0x55 at this point, why? */
3410 };
3411
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03003412 static const struct ov_regvals mode_init_519[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003413 { 0x5d, 0x03 }, /* Turn off suspend mode */
3414 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
Jean-François Moine21867802010-11-12 06:12:09 -03003415 { OV519_R54_EN_CLK1, 0x0f }, /* bit2 (jpeg enable) */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003416 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
3417 { 0xa3, 0x18 },
3418 { 0xa4, 0x04 },
3419 { 0xa5, 0x28 },
3420 { 0x37, 0x00 }, /* SetUsbInit */
3421 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
3422 /* Enable both fields, YUV Input, disable defect comp (why?) */
3423 { 0x22, 0x1d },
3424 { 0x17, 0x50 }, /* undocumented */
3425 { 0x37, 0x00 }, /* undocumented */
3426 { 0x40, 0xff }, /* I2C timeout counter */
3427 { 0x46, 0x00 }, /* I2C clock prescaler */
3428 { 0x59, 0x04 }, /* new from windrv 090403 */
3429 { 0xff, 0x00 }, /* undocumented */
3430 /* windows reads 0x55 at this point, why? */
3431 };
3432
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003433 /******** Set the mode ********/
3434 if (sd->sensor != SEN_OV7670) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03003435 write_regvals(sd, mode_init_519, ARRAY_SIZE(mode_init_519));
Hans de Goede035d3a32010-01-09 08:14:43 -03003436 if (sd->sensor == SEN_OV7640 ||
3437 sd->sensor == SEN_OV7648) {
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003438 /* Select 8-bit input mode */
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003439 reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10);
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003440 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003441 } else {
Jean-François Moinef8f20182010-11-12 07:54:02 -03003442 write_regvals(sd, mode_init_519_ov7670,
3443 ARRAY_SIZE(mode_init_519_ov7670));
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003444 }
3445
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003446 reg_w(sd, OV519_R10_H_SIZE, sd->gspca_dev.width >> 4);
3447 reg_w(sd, OV519_R11_V_SIZE, sd->gspca_dev.height >> 3);
Hans de Goede80142ef2009-06-14 06:26:49 -03003448 if (sd->sensor == SEN_OV7670 &&
3449 sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
3450 reg_w(sd, OV519_R12_X_OFFSETL, 0x04);
Hans de Goede035d3a32010-01-09 08:14:43 -03003451 else if (sd->sensor == SEN_OV7648 &&
3452 sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
3453 reg_w(sd, OV519_R12_X_OFFSETL, 0x01);
Hans de Goede80142ef2009-06-14 06:26:49 -03003454 else
3455 reg_w(sd, OV519_R12_X_OFFSETL, 0x00);
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003456 reg_w(sd, OV519_R13_X_OFFSETH, 0x00);
3457 reg_w(sd, OV519_R14_Y_OFFSETL, 0x00);
3458 reg_w(sd, OV519_R15_Y_OFFSETH, 0x00);
3459 reg_w(sd, OV519_R16_DIVIDER, 0x00);
3460 reg_w(sd, OV519_R25_FORMAT, 0x03); /* YUV422 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003461 reg_w(sd, 0x26, 0x00); /* Undocumented */
3462
3463 /******** Set the framerate ********/
3464 if (frame_rate > 0)
3465 sd->frame_rate = frame_rate;
3466
3467/* FIXME: These are only valid at the max resolution. */
3468 sd->clockdiv = 0;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003469 switch (sd->sensor) {
3470 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003471 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003472 switch (sd->frame_rate) {
Jean-Francois Moine53e74512008-11-08 06:10:19 -03003473 default:
3474/* case 30: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003475 reg_w(sd, 0xa4, 0x0c);
3476 reg_w(sd, 0x23, 0xff);
3477 break;
3478 case 25:
3479 reg_w(sd, 0xa4, 0x0c);
3480 reg_w(sd, 0x23, 0x1f);
3481 break;
3482 case 20:
3483 reg_w(sd, 0xa4, 0x0c);
3484 reg_w(sd, 0x23, 0x1b);
3485 break;
Jean-Francois Moine53e74512008-11-08 06:10:19 -03003486 case 15:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003487 reg_w(sd, 0xa4, 0x04);
3488 reg_w(sd, 0x23, 0xff);
3489 sd->clockdiv = 1;
3490 break;
3491 case 10:
3492 reg_w(sd, 0xa4, 0x04);
3493 reg_w(sd, 0x23, 0x1f);
3494 sd->clockdiv = 1;
3495 break;
3496 case 5:
3497 reg_w(sd, 0xa4, 0x04);
3498 reg_w(sd, 0x23, 0x1b);
3499 sd->clockdiv = 1;
3500 break;
3501 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003502 break;
3503 case SEN_OV8610:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003504 switch (sd->frame_rate) {
3505 default: /* 15 fps */
3506/* case 15: */
3507 reg_w(sd, 0xa4, 0x06);
3508 reg_w(sd, 0x23, 0xff);
3509 break;
3510 case 10:
3511 reg_w(sd, 0xa4, 0x06);
3512 reg_w(sd, 0x23, 0x1f);
3513 break;
3514 case 5:
3515 reg_w(sd, 0xa4, 0x06);
3516 reg_w(sd, 0x23, 0x1b);
3517 break;
3518 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003519 break;
3520 case SEN_OV7670: /* guesses, based on 7640 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003521 PDEBUG(D_STREAM, "Setting framerate to %d fps",
3522 (sd->frame_rate == 0) ? 15 : sd->frame_rate);
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003523 reg_w(sd, 0xa4, 0x10);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003524 switch (sd->frame_rate) {
3525 case 30:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003526 reg_w(sd, 0x23, 0xff);
3527 break;
3528 case 20:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003529 reg_w(sd, 0x23, 0x1b);
3530 break;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003531 default:
3532/* case 15: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003533 reg_w(sd, 0x23, 0xff);
3534 sd->clockdiv = 1;
3535 break;
3536 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003537 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003538 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003539}
3540
Jean-François Moinef8f20182010-11-12 07:54:02 -03003541static void mode_init_ov_sensor_regs(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003542{
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003543 struct gspca_dev *gspca_dev;
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003544 int qvga, xstart, xend, ystart, yend;
Jean-François Moine9d1593a2010-11-11 08:04:06 -03003545 u8 v;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003546
3547 gspca_dev = &sd->gspca_dev;
Jean-François Moine87bae742010-11-12 05:31:34 -03003548 qvga = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003549
3550 /******** Mode (VGA/QVGA) and sensor specific regs ********/
3551 switch (sd->sensor) {
Hans de Goede635118d2009-10-11 09:49:03 -03003552 case SEN_OV2610:
3553 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3554 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
3555 i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
3556 i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
3557 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
3558 i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
3559 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
Jean-François Moinef8f20182010-11-12 07:54:02 -03003560 return;
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003561 case SEN_OV3610:
Hans de Goede635118d2009-10-11 09:49:03 -03003562 if (qvga) {
3563 xstart = (1040 - gspca_dev->width) / 2 + (0x1f << 4);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003564 ystart = (776 - gspca_dev->height) / 2;
Hans de Goede635118d2009-10-11 09:49:03 -03003565 } else {
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003566 xstart = (2076 - gspca_dev->width) / 2 + (0x10 << 4);
Hans de Goede635118d2009-10-11 09:49:03 -03003567 ystart = (1544 - gspca_dev->height) / 2;
3568 }
3569 xend = xstart + gspca_dev->width;
3570 yend = ystart + gspca_dev->height;
3571 /* Writing to the COMH register resets the other windowing regs
3572 to their default values, so we must do this first. */
3573 i2c_w_mask(sd, 0x12, qvga ? 0x40 : 0x00, 0xf0);
3574 i2c_w_mask(sd, 0x32,
3575 (((xend >> 1) & 7) << 3) | ((xstart >> 1) & 7),
3576 0x3f);
3577 i2c_w_mask(sd, 0x03,
3578 (((yend >> 1) & 3) << 2) | ((ystart >> 1) & 3),
3579 0x0f);
3580 i2c_w(sd, 0x17, xstart >> 4);
3581 i2c_w(sd, 0x18, xend >> 4);
3582 i2c_w(sd, 0x19, ystart >> 3);
3583 i2c_w(sd, 0x1a, yend >> 3);
Jean-François Moinef8f20182010-11-12 07:54:02 -03003584 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003585 case SEN_OV8610:
3586 /* For OV8610 qvga means qsvga */
3587 i2c_w_mask(sd, OV7610_REG_COM_C, qvga ? (1 << 5) : 0, 1 << 5);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003588 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3589 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3590 i2c_w_mask(sd, 0x2d, 0x00, 0x40); /* from windrv 090403 */
3591 i2c_w_mask(sd, 0x28, 0x20, 0x20); /* progressive mode on */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003592 break;
3593 case SEN_OV7610:
3594 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
Jean-François Moine780e3122010-10-19 04:29:10 -03003595 i2c_w(sd, 0x35, qvga ? 0x1e : 0x9e);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003596 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3597 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003598 break;
3599 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03003600 case SEN_OV7620AE:
Hans de Goedeb282d872009-06-14 19:10:40 -03003601 case SEN_OV76BE:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003602 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3603 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
3604 i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
3605 i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
3606 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
Hans de Goedeb282d872009-06-14 19:10:40 -03003607 i2c_w_mask(sd, 0x67, qvga ? 0xb0 : 0x90, 0xf0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003608 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003609 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3610 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3611 if (sd->sensor == SEN_OV76BE)
3612 i2c_w(sd, 0x35, qvga ? 0x1e : 0x9e);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003613 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003614 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003615 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003616 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3617 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
Hans de Goede8d0082f2010-01-09 19:45:44 -03003618 /* Setting this undocumented bit in qvga mode removes a very
3619 annoying vertical shaking of the image */
Hans de Goede035d3a32010-01-09 08:14:43 -03003620 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
Hans de Goede8d0082f2010-01-09 19:45:44 -03003621 /* Unknown */
Hans de Goede035d3a32010-01-09 08:14:43 -03003622 i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
Hans de Goede8d0082f2010-01-09 19:45:44 -03003623 /* Allow higher automatic gain (to allow higher framerates) */
Hans de Goede035d3a32010-01-09 08:14:43 -03003624 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003625 i2c_w_mask(sd, 0x12, 0x04, 0x04); /* AWB: 1 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003626 break;
3627 case SEN_OV7670:
3628 /* set COM7_FMT_VGA or COM7_FMT_QVGA
3629 * do we need to set anything else?
3630 * HSTART etc are set in set_ov_sensor_window itself */
Jean-François Moine21867802010-11-12 06:12:09 -03003631 i2c_w_mask(sd, OV7670_R12_COM7,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003632 qvga ? OV7670_COM7_FMT_QVGA : OV7670_COM7_FMT_VGA,
3633 OV7670_COM7_FMT_MASK);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003634 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
Jean-François Moine21867802010-11-12 06:12:09 -03003635 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_AWB,
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003636 OV7670_COM8_AWB);
3637 if (qvga) { /* QVGA from ov7670.c by
3638 * Jonathan Corbet */
3639 xstart = 164;
3640 xend = 28;
3641 ystart = 14;
3642 yend = 494;
3643 } else { /* VGA */
3644 xstart = 158;
3645 xend = 14;
3646 ystart = 10;
3647 yend = 490;
3648 }
3649 /* OV7670 hardware window registers are split across
3650 * multiple locations */
Jean-François Moine21867802010-11-12 06:12:09 -03003651 i2c_w(sd, OV7670_R17_HSTART, xstart >> 3);
3652 i2c_w(sd, OV7670_R18_HSTOP, xend >> 3);
3653 v = i2c_r(sd, OV7670_R32_HREF);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003654 v = (v & 0xc0) | ((xend & 0x7) << 3) | (xstart & 0x07);
3655 msleep(10); /* need to sleep between read and write to
3656 * same reg! */
Jean-François Moine21867802010-11-12 06:12:09 -03003657 i2c_w(sd, OV7670_R32_HREF, v);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003658
Jean-François Moine21867802010-11-12 06:12:09 -03003659 i2c_w(sd, OV7670_R19_VSTART, ystart >> 2);
3660 i2c_w(sd, OV7670_R1A_VSTOP, yend >> 2);
3661 v = i2c_r(sd, OV7670_R03_VREF);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003662 v = (v & 0xc0) | ((yend & 0x3) << 2) | (ystart & 0x03);
3663 msleep(10); /* need to sleep between read and write to
3664 * same reg! */
Jean-François Moine21867802010-11-12 06:12:09 -03003665 i2c_w(sd, OV7670_R03_VREF, v);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003666 break;
3667 case SEN_OV6620:
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003668 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3669 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3670 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3671 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003672 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03003673 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003674 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003675 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003676 break;
3677 default:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003678 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003679 }
3680
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003681 /******** Clock programming ********/
Hans de Goedeae49c402009-06-14 19:15:07 -03003682 i2c_w(sd, 0x11, sd->clockdiv);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003683}
3684
Jean-François Moine62833ac2010-10-02 04:27:02 -03003685static void sethvflip(struct gspca_dev *gspca_dev)
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003686{
Jean-François Moine62833ac2010-10-02 04:27:02 -03003687 struct sd *sd = (struct sd *) gspca_dev;
3688
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003689 if (sd->gspca_dev.streaming)
Jean-François Moine5927abc2010-11-12 15:32:29 -03003690 reg_w(sd, OV519_R51_RESET1, 0x0f); /* block stream */
Jean-François Moine21867802010-11-12 06:12:09 -03003691 i2c_w_mask(sd, OV7670_R1E_MVFP,
Jean-François Moine62833ac2010-10-02 04:27:02 -03003692 OV7670_MVFP_MIRROR * sd->ctrls[HFLIP].val
3693 | OV7670_MVFP_VFLIP * sd->ctrls[VFLIP].val,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003694 OV7670_MVFP_MIRROR | OV7670_MVFP_VFLIP);
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003695 if (sd->gspca_dev.streaming)
Jean-François Moine5927abc2010-11-12 15:32:29 -03003696 reg_w(sd, OV519_R51_RESET1, 0x00); /* restart stream */
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003697}
3698
Jean-François Moinef8f20182010-11-12 07:54:02 -03003699static void set_ov_sensor_window(struct sd *sd)
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003700{
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003701 struct gspca_dev *gspca_dev;
Hans de Goede124cc9c2009-06-14 05:48:00 -03003702 int qvga, crop;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003703 int hwsbase, hwebase, vwsbase, vwebase, hwscale, vwscale;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003704
Hans de Goede635118d2009-10-11 09:49:03 -03003705 /* mode setup is fully handled in mode_init_ov_sensor_regs for these */
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003706 if (sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610 ||
Jean-François Moinef8f20182010-11-12 07:54:02 -03003707 sd->sensor == SEN_OV7670) {
3708 mode_init_ov_sensor_regs(sd);
3709 return;
3710 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003711 gspca_dev = &sd->gspca_dev;
Jean-François Moine87bae742010-11-12 05:31:34 -03003712 qvga = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 1;
3713 crop = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 2;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003714
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003715 /* The different sensor ICs handle setting up of window differently.
3716 * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!! */
3717 switch (sd->sensor) {
3718 case SEN_OV8610:
3719 hwsbase = 0x1e;
3720 hwebase = 0x1e;
3721 vwsbase = 0x02;
3722 vwebase = 0x02;
3723 break;
3724 case SEN_OV7610:
3725 case SEN_OV76BE:
3726 hwsbase = 0x38;
3727 hwebase = 0x3a;
3728 vwsbase = vwebase = 0x05;
3729 break;
3730 case SEN_OV6620:
3731 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03003732 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003733 hwsbase = 0x38;
3734 hwebase = 0x3a;
3735 vwsbase = 0x05;
3736 vwebase = 0x06;
Hans de Goede7d971372009-06-14 05:28:17 -03003737 if (sd->sensor == SEN_OV66308AF && qvga)
Hans de Goede49809d62009-06-07 12:10:39 -03003738 /* HDG: this fixes U and V getting swapped */
Hans de Goede7d971372009-06-14 05:28:17 -03003739 hwsbase++;
Hans de Goede124cc9c2009-06-14 05:48:00 -03003740 if (crop) {
3741 hwsbase += 8;
3742 hwebase += 8;
3743 vwsbase += 11;
3744 vwebase += 11;
3745 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003746 break;
3747 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03003748 case SEN_OV7620AE:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003749 hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */
3750 hwebase = 0x2f;
3751 vwsbase = vwebase = 0x05;
3752 break;
3753 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003754 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003755 hwsbase = 0x1a;
3756 hwebase = 0x1a;
3757 vwsbase = vwebase = 0x03;
3758 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003759 default:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003760 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003761 }
3762
3763 switch (sd->sensor) {
3764 case SEN_OV6620:
3765 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03003766 case SEN_OV66308AF:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003767 if (qvga) { /* QCIF */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003768 hwscale = 0;
3769 vwscale = 0;
3770 } else { /* CIF */
3771 hwscale = 1;
3772 vwscale = 1; /* The datasheet says 0;
3773 * it's wrong */
3774 }
3775 break;
3776 case SEN_OV8610:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003777 if (qvga) { /* QSVGA */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003778 hwscale = 1;
3779 vwscale = 1;
3780 } else { /* SVGA */
3781 hwscale = 2;
3782 vwscale = 2;
3783 }
3784 break;
3785 default: /* SEN_OV7xx0 */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003786 if (qvga) { /* QVGA */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003787 hwscale = 1;
3788 vwscale = 0;
3789 } else { /* VGA */
3790 hwscale = 2;
3791 vwscale = 1;
3792 }
3793 }
3794
Jean-François Moinef8f20182010-11-12 07:54:02 -03003795 mode_init_ov_sensor_regs(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003796
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003797 i2c_w(sd, 0x17, hwsbase);
Hans de Goedea511ba92009-10-16 07:13:07 -03003798 i2c_w(sd, 0x18, hwebase + (sd->sensor_width >> hwscale));
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003799 i2c_w(sd, 0x19, vwsbase);
Hans de Goedea511ba92009-10-16 07:13:07 -03003800 i2c_w(sd, 0x1a, vwebase + (sd->sensor_height >> vwscale));
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003801}
3802
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003803/* -- start the camera -- */
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03003804static int sd_start(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003805{
3806 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003807
Hans de Goedea511ba92009-10-16 07:13:07 -03003808 /* Default for most bridges, allow bridge_mode_init_regs to override */
3809 sd->sensor_width = sd->gspca_dev.width;
3810 sd->sensor_height = sd->gspca_dev.height;
3811
Hans de Goede49809d62009-06-07 12:10:39 -03003812 switch (sd->bridge) {
Hans de Goede1876bb92009-06-14 06:45:50 -03003813 case BRIDGE_OV511:
3814 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003815 ov511_mode_init_regs(sd);
Hans de Goede1876bb92009-06-14 06:45:50 -03003816 break;
Hans de Goede49809d62009-06-07 12:10:39 -03003817 case BRIDGE_OV518:
3818 case BRIDGE_OV518PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003819 ov518_mode_init_regs(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03003820 break;
3821 case BRIDGE_OV519:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003822 ov519_mode_init_regs(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03003823 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003824 /* case BRIDGE_OVFX2: nothing to do */
Hans de Goedea511ba92009-10-16 07:13:07 -03003825 case BRIDGE_W9968CF:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003826 w9968cf_mode_init_regs(sd);
Hans de Goedea511ba92009-10-16 07:13:07 -03003827 break;
Hans de Goede49809d62009-06-07 12:10:39 -03003828 }
Hans de Goede49809d62009-06-07 12:10:39 -03003829
Jean-François Moinef8f20182010-11-12 07:54:02 -03003830 set_ov_sensor_window(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003831
Jean-François Moinee2817022010-11-12 13:59:48 -03003832 if (!(sd->gspca_dev.ctrl_dis & (1 << CONTRAST)))
3833 setcontrast(gspca_dev);
3834 if (!(sd->gspca_dev.ctrl_dis & (1 << BRIGHTNESS)))
3835 setbrightness(gspca_dev);
3836 if (!(sd->gspca_dev.ctrl_dis & (1 << COLORS)))
3837 setcolors(gspca_dev);
3838 if (!(sd->gspca_dev.ctrl_dis & ((1 << HFLIP) | (1 << VFLIP))))
3839 sethvflip(gspca_dev);
3840 if (!(sd->gspca_dev.ctrl_dis & (1 << AUTOBRIGHT)))
3841 setautobright(gspca_dev);
3842 if (!(sd->gspca_dev.ctrl_dis & (1 << FREQ)))
3843 setfreq_i(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03003844
Hans de Goede417a4d22010-02-19 07:37:08 -03003845 /* Force clear snapshot state in case the snapshot button was
3846 pressed while we weren't streaming */
3847 sd->snapshot_needs_reset = 1;
3848 sd_reset_snapshot(gspca_dev);
Hans de Goede417a4d22010-02-19 07:37:08 -03003849
Hans de Goeded6b6d7a2010-05-08 08:55:42 -03003850 sd->first_frame = 3;
3851
Jean-François Moinef8f20182010-11-12 07:54:02 -03003852 ov51x_restart(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003853 ov51x_led_control(sd, 1);
Jean-François Moinef8f20182010-11-12 07:54:02 -03003854 return gspca_dev->usb_err;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003855}
3856
3857static void sd_stopN(struct gspca_dev *gspca_dev)
3858{
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003859 struct sd *sd = (struct sd *) gspca_dev;
3860
3861 ov51x_stop(sd);
3862 ov51x_led_control(sd, 0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003863}
3864
Hans de Goede79b35902009-10-19 06:08:01 -03003865static void sd_stop0(struct gspca_dev *gspca_dev)
3866{
3867 struct sd *sd = (struct sd *) gspca_dev;
3868
Jean-François Moined65174c2010-11-11 06:20:42 -03003869 if (!sd->gspca_dev.present)
3870 return;
Hans de Goede79b35902009-10-19 06:08:01 -03003871 if (sd->bridge == BRIDGE_W9968CF)
3872 w9968cf_stop0(sd);
Hans de Goede614d0692010-10-27 07:42:28 -03003873
Jean-François Moine14653e62010-11-11 06:17:01 -03003874#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
Hans de Goede614d0692010-10-27 07:42:28 -03003875 /* If the last button state is pressed, release it now! */
3876 if (sd->snapshot_pressed) {
3877 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
3878 input_sync(gspca_dev->input_dev);
3879 sd->snapshot_pressed = 0;
3880 }
3881#endif
Jean-François Moineb4e96ea2010-11-12 16:13:17 -03003882 if (sd->bridge == BRIDGE_OV519)
3883 reg_w(sd, OV519_R57_SNAPSHOT, 0x23);
Hans de Goede79b35902009-10-19 06:08:01 -03003884}
3885
Hans de Goede92e232a2010-02-20 04:30:45 -03003886static void ov51x_handle_button(struct gspca_dev *gspca_dev, u8 state)
3887{
3888 struct sd *sd = (struct sd *) gspca_dev;
3889
3890 if (sd->snapshot_pressed != state) {
Jean-François Moine28566432010-10-01 07:33:26 -03003891#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
Hans de Goede92e232a2010-02-20 04:30:45 -03003892 input_report_key(gspca_dev->input_dev, KEY_CAMERA, state);
3893 input_sync(gspca_dev->input_dev);
3894#endif
3895 if (state)
3896 sd->snapshot_needs_reset = 1;
3897
3898 sd->snapshot_pressed = state;
3899 } else {
Hans de Goede88e8d202010-02-20 04:45:49 -03003900 /* On the ov511 / ov519 we need to reset the button state
3901 multiple times, as resetting does not work as long as the
3902 button stays pressed */
3903 switch (sd->bridge) {
3904 case BRIDGE_OV511:
3905 case BRIDGE_OV511PLUS:
3906 case BRIDGE_OV519:
3907 if (state)
3908 sd->snapshot_needs_reset = 1;
3909 break;
3910 }
Hans de Goede92e232a2010-02-20 04:30:45 -03003911 }
3912}
3913
Hans de Goede1876bb92009-06-14 06:45:50 -03003914static void ov511_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003915 u8 *in, /* isoc packet */
3916 int len) /* iso packet length */
Hans de Goede1876bb92009-06-14 06:45:50 -03003917{
3918 struct sd *sd = (struct sd *) gspca_dev;
3919
3920 /* SOF/EOF packets have 1st to 8th bytes zeroed and the 9th
3921 * byte non-zero. The EOF packet has image width/height in the
3922 * 10th and 11th bytes. The 9th byte is given as follows:
3923 *
3924 * bit 7: EOF
3925 * 6: compression enabled
3926 * 5: 422/420/400 modes
3927 * 4: 422/420/400 modes
3928 * 3: 1
3929 * 2: snapshot button on
3930 * 1: snapshot frame
3931 * 0: even/odd field
3932 */
3933 if (!(in[0] | in[1] | in[2] | in[3] | in[4] | in[5] | in[6] | in[7]) &&
3934 (in[8] & 0x08)) {
Hans de Goede88e8d202010-02-20 04:45:49 -03003935 ov51x_handle_button(gspca_dev, (in[8] >> 2) & 1);
Hans de Goede1876bb92009-06-14 06:45:50 -03003936 if (in[8] & 0x80) {
3937 /* Frame end */
3938 if ((in[9] + 1) * 8 != gspca_dev->width ||
3939 (in[10] + 1) * 8 != gspca_dev->height) {
3940 PDEBUG(D_ERR, "Invalid frame size, got: %dx%d,"
3941 " requested: %dx%d\n",
3942 (in[9] + 1) * 8, (in[10] + 1) * 8,
3943 gspca_dev->width, gspca_dev->height);
3944 gspca_dev->last_packet_type = DISCARD_PACKET;
3945 return;
3946 }
3947 /* Add 11 byte footer to frame, might be usefull */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003948 gspca_frame_add(gspca_dev, LAST_PACKET, in, 11);
Hans de Goede1876bb92009-06-14 06:45:50 -03003949 return;
3950 } else {
3951 /* Frame start */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003952 gspca_frame_add(gspca_dev, FIRST_PACKET, in, 0);
Hans de Goede1876bb92009-06-14 06:45:50 -03003953 sd->packet_nr = 0;
3954 }
3955 }
3956
3957 /* Ignore the packet number */
3958 len--;
3959
3960 /* intermediate packet */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003961 gspca_frame_add(gspca_dev, INTER_PACKET, in, len);
Hans de Goede1876bb92009-06-14 06:45:50 -03003962}
3963
Hans de Goede49809d62009-06-07 12:10:39 -03003964static void ov518_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003965 u8 *data, /* isoc packet */
Hans de Goede49809d62009-06-07 12:10:39 -03003966 int len) /* iso packet length */
3967{
Hans de Goede92918a52009-06-14 06:21:35 -03003968 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede49809d62009-06-07 12:10:39 -03003969
3970 /* A false positive here is likely, until OVT gives me
3971 * the definitive SOF/EOF format */
3972 if ((!(data[0] | data[1] | data[2] | data[3] | data[5])) && data[6]) {
Hans de Goede92e232a2010-02-20 04:30:45 -03003973 ov51x_handle_button(gspca_dev, (data[6] >> 1) & 1);
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003974 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
3975 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
Hans de Goede92918a52009-06-14 06:21:35 -03003976 sd->packet_nr = 0;
3977 }
3978
3979 if (gspca_dev->last_packet_type == DISCARD_PACKET)
3980 return;
3981
3982 /* Does this device use packet numbers ? */
3983 if (len & 7) {
3984 len--;
3985 if (sd->packet_nr == data[len])
3986 sd->packet_nr++;
3987 /* The last few packets of the frame (which are all 0's
3988 except that they may contain part of the footer), are
3989 numbered 0 */
3990 else if (sd->packet_nr == 0 || data[len]) {
3991 PDEBUG(D_ERR, "Invalid packet nr: %d (expect: %d)",
3992 (int)data[len], (int)sd->packet_nr);
3993 gspca_dev->last_packet_type = DISCARD_PACKET;
3994 return;
3995 }
Hans de Goede49809d62009-06-07 12:10:39 -03003996 }
3997
3998 /* intermediate packet */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003999 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03004000}
4001
4002static void ov519_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004003 u8 *data, /* isoc packet */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004004 int len) /* iso packet length */
4005{
4006 /* Header of ov519 is 16 bytes:
4007 * Byte Value Description
4008 * 0 0xff magic
4009 * 1 0xff magic
4010 * 2 0xff magic
4011 * 3 0xXX 0x50 = SOF, 0x51 = EOF
4012 * 9 0xXX 0x01 initial frame without data,
4013 * 0x00 standard frame with image
4014 * 14 Lo in EOF: length of image data / 8
4015 * 15 Hi
4016 */
4017
4018 if (data[0] == 0xff && data[1] == 0xff && data[2] == 0xff) {
4019 switch (data[3]) {
4020 case 0x50: /* start of frame */
Hans de Goede417a4d22010-02-19 07:37:08 -03004021 /* Don't check the button state here, as the state
4022 usually (always ?) changes at EOF and checking it
4023 here leads to unnecessary snapshot state resets. */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004024#define HDRSZ 16
4025 data += HDRSZ;
4026 len -= HDRSZ;
4027#undef HDRSZ
4028 if (data[0] == 0xff || data[1] == 0xd8)
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004029 gspca_frame_add(gspca_dev, FIRST_PACKET,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004030 data, len);
4031 else
4032 gspca_dev->last_packet_type = DISCARD_PACKET;
4033 return;
4034 case 0x51: /* end of frame */
Hans de Goede92e232a2010-02-20 04:30:45 -03004035 ov51x_handle_button(gspca_dev, data[11] & 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004036 if (data[9] != 0)
4037 gspca_dev->last_packet_type = DISCARD_PACKET;
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004038 gspca_frame_add(gspca_dev, LAST_PACKET,
4039 NULL, 0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004040 return;
4041 }
4042 }
4043
4044 /* intermediate packet */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004045 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004046}
4047
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004048static void ovfx2_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004049 u8 *data, /* isoc packet */
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004050 int len) /* iso packet length */
4051{
Hans de Goeded6b6d7a2010-05-08 08:55:42 -03004052 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goeded6b6d7a2010-05-08 08:55:42 -03004053
4054 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
4055
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004056 /* A short read signals EOF */
4057 if (len < OVFX2_BULK_SIZE) {
Hans de Goeded6b6d7a2010-05-08 08:55:42 -03004058 /* If the frame is short, and it is one of the first ones
4059 the sensor and bridge are still syncing, so drop it. */
4060 if (sd->first_frame) {
4061 sd->first_frame--;
Jean-François Moineb192ca92010-06-27 03:08:19 -03004062 if (gspca_dev->image_len <
4063 sd->gspca_dev.width * sd->gspca_dev.height)
Hans de Goeded6b6d7a2010-05-08 08:55:42 -03004064 gspca_dev->last_packet_type = DISCARD_PACKET;
4065 }
4066 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004067 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004068 }
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004069}
4070
Hans de Goede49809d62009-06-07 12:10:39 -03004071static void sd_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004072 u8 *data, /* isoc packet */
Hans de Goede49809d62009-06-07 12:10:39 -03004073 int len) /* iso packet length */
4074{
4075 struct sd *sd = (struct sd *) gspca_dev;
4076
4077 switch (sd->bridge) {
4078 case BRIDGE_OV511:
4079 case BRIDGE_OV511PLUS:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004080 ov511_pkt_scan(gspca_dev, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03004081 break;
4082 case BRIDGE_OV518:
4083 case BRIDGE_OV518PLUS:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004084 ov518_pkt_scan(gspca_dev, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03004085 break;
4086 case BRIDGE_OV519:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004087 ov519_pkt_scan(gspca_dev, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03004088 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004089 case BRIDGE_OVFX2:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004090 ovfx2_pkt_scan(gspca_dev, data, len);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004091 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03004092 case BRIDGE_W9968CF:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004093 w9968cf_pkt_scan(gspca_dev, data, len);
Hans de Goedea511ba92009-10-16 07:13:07 -03004094 break;
Hans de Goede49809d62009-06-07 12:10:39 -03004095 }
4096}
4097
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004098/* -- management routines -- */
4099
4100static void setbrightness(struct gspca_dev *gspca_dev)
4101{
4102 struct sd *sd = (struct sd *) gspca_dev;
4103 int val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004104
Jean-François Moine62833ac2010-10-02 04:27:02 -03004105 val = sd->ctrls[BRIGHTNESS].val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004106 switch (sd->sensor) {
4107 case SEN_OV8610:
4108 case SEN_OV7610:
4109 case SEN_OV76BE:
4110 case SEN_OV6620:
4111 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03004112 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004113 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03004114 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004115 i2c_w(sd, OV7610_REG_BRT, val);
4116 break;
4117 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03004118 case SEN_OV7620AE:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004119 /* 7620 doesn't like manual changes when in auto mode */
Jean-François Moine62833ac2010-10-02 04:27:02 -03004120 if (!sd->ctrls[AUTOBRIGHT].val)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004121 i2c_w(sd, OV7610_REG_BRT, val);
4122 break;
4123 case SEN_OV7670:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03004124/*win trace
Jean-François Moine21867802010-11-12 06:12:09 -03004125 * i2c_w_mask(sd, OV7670_R13_COM8, 0, OV7670_COM8_AEC); */
4126 i2c_w(sd, OV7670_R55_BRIGHT, ov7670_abs_to_sm(val));
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004127 break;
4128 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004129}
4130
4131static void setcontrast(struct gspca_dev *gspca_dev)
4132{
4133 struct sd *sd = (struct sd *) gspca_dev;
4134 int val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004135
Jean-François Moine62833ac2010-10-02 04:27:02 -03004136 val = sd->ctrls[CONTRAST].val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004137 switch (sd->sensor) {
4138 case SEN_OV7610:
4139 case SEN_OV6620:
4140 i2c_w(sd, OV7610_REG_CNT, val);
4141 break;
4142 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03004143 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004144 i2c_w_mask(sd, OV7610_REG_CNT, val >> 4, 0x0f);
Hans de Goede49809d62009-06-07 12:10:39 -03004145 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004146 case SEN_OV8610: {
Jean-François Moine9d1593a2010-11-11 08:04:06 -03004147 static const u8 ctab[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004148 0x03, 0x09, 0x0b, 0x0f, 0x53, 0x6f, 0x35, 0x7f
4149 };
4150
4151 /* Use Y gamma control instead. Bit 0 enables it. */
4152 i2c_w(sd, 0x64, ctab[val >> 5]);
4153 break;
4154 }
Hans de Goede859cc472010-01-07 15:42:35 -03004155 case SEN_OV7620:
4156 case SEN_OV7620AE: {
Jean-François Moine9d1593a2010-11-11 08:04:06 -03004157 static const u8 ctab[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004158 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
4159 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
4160 };
4161
4162 /* Use Y gamma control instead. Bit 0 enables it. */
4163 i2c_w(sd, 0x64, ctab[val >> 4]);
4164 break;
4165 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004166 case SEN_OV7670:
4167 /* check that this isn't just the same as ov7610 */
Jean-François Moine21867802010-11-12 06:12:09 -03004168 i2c_w(sd, OV7670_R56_CONTRAS, val >> 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004169 break;
4170 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004171}
4172
4173static void setcolors(struct gspca_dev *gspca_dev)
4174{
4175 struct sd *sd = (struct sd *) gspca_dev;
4176 int val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004177
Jean-François Moine62833ac2010-10-02 04:27:02 -03004178 val = sd->ctrls[COLORS].val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004179 switch (sd->sensor) {
4180 case SEN_OV8610:
4181 case SEN_OV7610:
4182 case SEN_OV76BE:
4183 case SEN_OV6620:
4184 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03004185 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004186 i2c_w(sd, OV7610_REG_SAT, val);
4187 break;
4188 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03004189 case SEN_OV7620AE:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004190 /* Use UV gamma control instead. Bits 0 & 7 are reserved. */
4191/* rc = ov_i2c_write(sd->dev, 0x62, (val >> 9) & 0x7e);
4192 if (rc < 0)
4193 goto out; */
4194 i2c_w(sd, OV7610_REG_SAT, val);
4195 break;
4196 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03004197 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004198 i2c_w(sd, OV7610_REG_SAT, val & 0xf0);
4199 break;
4200 case SEN_OV7670:
4201 /* supported later once I work out how to do it
4202 * transparently fail now! */
4203 /* set REG_COM13 values for UV sat auto mode */
4204 break;
4205 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004206}
4207
Jean-François Moine62833ac2010-10-02 04:27:02 -03004208static void setautobright(struct gspca_dev *gspca_dev)
Hans de Goede02ab18b2009-06-14 04:32:04 -03004209{
Jean-François Moine62833ac2010-10-02 04:27:02 -03004210 struct sd *sd = (struct sd *) gspca_dev;
4211
Jean-François Moine62833ac2010-10-02 04:27:02 -03004212 i2c_w_mask(sd, 0x2d, sd->ctrls[AUTOBRIGHT].val ? 0x10 : 0x00, 0x10);
Hans de Goede02ab18b2009-06-14 04:32:04 -03004213}
4214
Jean-François Moine62833ac2010-10-02 04:27:02 -03004215static void setfreq_i(struct sd *sd)
Hans de Goede02ab18b2009-06-14 04:32:04 -03004216{
4217 if (sd->sensor == SEN_OV7670) {
Jean-François Moine62833ac2010-10-02 04:27:02 -03004218 switch (sd->ctrls[FREQ].val) {
Hans de Goede02ab18b2009-06-14 04:32:04 -03004219 case 0: /* Banding filter disabled */
Jean-François Moine21867802010-11-12 06:12:09 -03004220 i2c_w_mask(sd, OV7670_R13_COM8, 0, OV7670_COM8_BFILT);
Hans de Goede02ab18b2009-06-14 04:32:04 -03004221 break;
4222 case 1: /* 50 hz */
Jean-François Moine21867802010-11-12 06:12:09 -03004223 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT,
Hans de Goede02ab18b2009-06-14 04:32:04 -03004224 OV7670_COM8_BFILT);
Jean-François Moine21867802010-11-12 06:12:09 -03004225 i2c_w_mask(sd, OV7670_R3B_COM11, 0x08, 0x18);
Hans de Goede02ab18b2009-06-14 04:32:04 -03004226 break;
4227 case 2: /* 60 hz */
Jean-François Moine21867802010-11-12 06:12:09 -03004228 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT,
Hans de Goede02ab18b2009-06-14 04:32:04 -03004229 OV7670_COM8_BFILT);
Jean-François Moine21867802010-11-12 06:12:09 -03004230 i2c_w_mask(sd, OV7670_R3B_COM11, 0x00, 0x18);
Hans de Goede02ab18b2009-06-14 04:32:04 -03004231 break;
Jean-François Moine21867802010-11-12 06:12:09 -03004232 case 3: /* Auto hz - ov7670 only */
4233 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT,
Hans de Goede02ab18b2009-06-14 04:32:04 -03004234 OV7670_COM8_BFILT);
Jean-François Moine21867802010-11-12 06:12:09 -03004235 i2c_w_mask(sd, OV7670_R3B_COM11, OV7670_COM11_HZAUTO,
Hans de Goede02ab18b2009-06-14 04:32:04 -03004236 0x18);
4237 break;
4238 }
4239 } else {
Jean-François Moine62833ac2010-10-02 04:27:02 -03004240 switch (sd->ctrls[FREQ].val) {
Hans de Goede02ab18b2009-06-14 04:32:04 -03004241 case 0: /* Banding filter disabled */
4242 i2c_w_mask(sd, 0x2d, 0x00, 0x04);
4243 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
4244 break;
4245 case 1: /* 50 hz (filter on and framerate adj) */
4246 i2c_w_mask(sd, 0x2d, 0x04, 0x04);
4247 i2c_w_mask(sd, 0x2a, 0x80, 0x80);
4248 /* 20 fps -> 16.667 fps */
4249 if (sd->sensor == SEN_OV6620 ||
Hans de Goede7d971372009-06-14 05:28:17 -03004250 sd->sensor == SEN_OV6630 ||
4251 sd->sensor == SEN_OV66308AF)
Hans de Goede02ab18b2009-06-14 04:32:04 -03004252 i2c_w(sd, 0x2b, 0x5e);
4253 else
4254 i2c_w(sd, 0x2b, 0xac);
4255 break;
4256 case 2: /* 60 hz (filter on, ...) */
4257 i2c_w_mask(sd, 0x2d, 0x04, 0x04);
4258 if (sd->sensor == SEN_OV6620 ||
Hans de Goede7d971372009-06-14 05:28:17 -03004259 sd->sensor == SEN_OV6630 ||
4260 sd->sensor == SEN_OV66308AF) {
Hans de Goede02ab18b2009-06-14 04:32:04 -03004261 /* 20 fps -> 15 fps */
4262 i2c_w_mask(sd, 0x2a, 0x80, 0x80);
4263 i2c_w(sd, 0x2b, 0xa8);
4264 } else {
4265 /* no framerate adj. */
4266 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
4267 }
4268 break;
4269 }
4270 }
4271}
Jean-François Moine62833ac2010-10-02 04:27:02 -03004272static void setfreq(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004273{
4274 struct sd *sd = (struct sd *) gspca_dev;
4275
Jean-François Moine62833ac2010-10-02 04:27:02 -03004276 setfreq_i(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004277
Jean-François Moine62833ac2010-10-02 04:27:02 -03004278 /* Ugly but necessary */
4279 if (sd->bridge == BRIDGE_W9968CF)
4280 w9968cf_set_crop_window(sd);
Hans de Goede02ab18b2009-06-14 04:32:04 -03004281}
4282
4283static int sd_querymenu(struct gspca_dev *gspca_dev,
4284 struct v4l2_querymenu *menu)
4285{
4286 struct sd *sd = (struct sd *) gspca_dev;
4287
4288 switch (menu->id) {
4289 case V4L2_CID_POWER_LINE_FREQUENCY:
4290 switch (menu->index) {
4291 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
4292 strcpy((char *) menu->name, "NoFliker");
4293 return 0;
4294 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
4295 strcpy((char *) menu->name, "50 Hz");
4296 return 0;
4297 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
4298 strcpy((char *) menu->name, "60 Hz");
4299 return 0;
4300 case 3:
4301 if (sd->sensor != SEN_OV7670)
4302 return -EINVAL;
4303
4304 strcpy((char *) menu->name, "Automatic");
4305 return 0;
4306 }
4307 break;
4308 }
4309 return -EINVAL;
4310}
4311
Hans de Goede79b35902009-10-19 06:08:01 -03004312static int sd_get_jcomp(struct gspca_dev *gspca_dev,
4313 struct v4l2_jpegcompression *jcomp)
4314{
4315 struct sd *sd = (struct sd *) gspca_dev;
4316
4317 if (sd->bridge != BRIDGE_W9968CF)
4318 return -EINVAL;
4319
4320 memset(jcomp, 0, sizeof *jcomp);
4321 jcomp->quality = sd->quality;
4322 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT | V4L2_JPEG_MARKER_DQT |
4323 V4L2_JPEG_MARKER_DRI;
4324 return 0;
4325}
4326
4327static int sd_set_jcomp(struct gspca_dev *gspca_dev,
4328 struct v4l2_jpegcompression *jcomp)
4329{
4330 struct sd *sd = (struct sd *) gspca_dev;
4331
4332 if (sd->bridge != BRIDGE_W9968CF)
4333 return -EINVAL;
4334
4335 if (gspca_dev->streaming)
4336 return -EBUSY;
4337
4338 if (jcomp->quality < QUALITY_MIN)
4339 sd->quality = QUALITY_MIN;
4340 else if (jcomp->quality > QUALITY_MAX)
4341 sd->quality = QUALITY_MAX;
4342 else
4343 sd->quality = jcomp->quality;
4344
4345 /* Return resulting jcomp params to app */
4346 sd_get_jcomp(gspca_dev, jcomp);
4347
4348 return 0;
4349}
4350
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004351/* sub-driver description */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03004352static const struct sd_desc sd_desc = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004353 .name = MODULE_NAME,
4354 .ctrls = sd_ctrls,
4355 .nctrls = ARRAY_SIZE(sd_ctrls),
4356 .config = sd_config,
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03004357 .init = sd_init,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004358 .start = sd_start,
4359 .stopN = sd_stopN,
Hans de Goede79b35902009-10-19 06:08:01 -03004360 .stop0 = sd_stop0,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004361 .pkt_scan = sd_pkt_scan,
Hans de Goede417a4d22010-02-19 07:37:08 -03004362 .dq_callback = sd_reset_snapshot,
Hans de Goede02ab18b2009-06-14 04:32:04 -03004363 .querymenu = sd_querymenu,
Hans de Goede79b35902009-10-19 06:08:01 -03004364 .get_jcomp = sd_get_jcomp,
4365 .set_jcomp = sd_set_jcomp,
Jean-François Moine28566432010-10-01 07:33:26 -03004366#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
Hans de Goede417a4d22010-02-19 07:37:08 -03004367 .other_input = 1,
4368#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004369};
4370
4371/* -- module initialisation -- */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03004372static const __devinitdata struct usb_device_id device_table[] = {
Hans de Goedea511ba92009-10-16 07:13:07 -03004373 {USB_DEVICE(0x041e, 0x4003), .driver_info = BRIDGE_W9968CF },
Hans de Goede49809d62009-06-07 12:10:39 -03004374 {USB_DEVICE(0x041e, 0x4052), .driver_info = BRIDGE_OV519 },
4375 {USB_DEVICE(0x041e, 0x405f), .driver_info = BRIDGE_OV519 },
4376 {USB_DEVICE(0x041e, 0x4060), .driver_info = BRIDGE_OV519 },
4377 {USB_DEVICE(0x041e, 0x4061), .driver_info = BRIDGE_OV519 },
Hans de Goede9e4d8252009-06-14 06:25:06 -03004378 {USB_DEVICE(0x041e, 0x4064),
Jean-François Moine87bae742010-11-12 05:31:34 -03004379 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
Rafal Milecki518c8df2009-10-02 03:54:44 -03004380 {USB_DEVICE(0x041e, 0x4067), .driver_info = BRIDGE_OV519 },
Hans de Goede9e4d8252009-06-14 06:25:06 -03004381 {USB_DEVICE(0x041e, 0x4068),
Jean-François Moine87bae742010-11-12 05:31:34 -03004382 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
Hans de Goede49809d62009-06-07 12:10:39 -03004383 {USB_DEVICE(0x045e, 0x028c), .driver_info = BRIDGE_OV519 },
4384 {USB_DEVICE(0x054c, 0x0154), .driver_info = BRIDGE_OV519 },
Hans de Goede98184f72010-01-07 12:06:00 -03004385 {USB_DEVICE(0x054c, 0x0155),
Jean-François Moine87bae742010-11-12 05:31:34 -03004386 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
Hans de Goede1876bb92009-06-14 06:45:50 -03004387 {USB_DEVICE(0x05a9, 0x0511), .driver_info = BRIDGE_OV511 },
Hans de Goede49809d62009-06-07 12:10:39 -03004388 {USB_DEVICE(0x05a9, 0x0518), .driver_info = BRIDGE_OV518 },
4389 {USB_DEVICE(0x05a9, 0x0519), .driver_info = BRIDGE_OV519 },
4390 {USB_DEVICE(0x05a9, 0x0530), .driver_info = BRIDGE_OV519 },
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004391 {USB_DEVICE(0x05a9, 0x2800), .driver_info = BRIDGE_OVFX2 },
Hans de Goede49809d62009-06-07 12:10:39 -03004392 {USB_DEVICE(0x05a9, 0x4519), .driver_info = BRIDGE_OV519 },
4393 {USB_DEVICE(0x05a9, 0x8519), .driver_info = BRIDGE_OV519 },
Hans de Goede1876bb92009-06-14 06:45:50 -03004394 {USB_DEVICE(0x05a9, 0xa511), .driver_info = BRIDGE_OV511PLUS },
Hans de Goede49809d62009-06-07 12:10:39 -03004395 {USB_DEVICE(0x05a9, 0xa518), .driver_info = BRIDGE_OV518PLUS },
Hans de Goede1876bb92009-06-14 06:45:50 -03004396 {USB_DEVICE(0x0813, 0x0002), .driver_info = BRIDGE_OV511PLUS },
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004397 {USB_DEVICE(0x0b62, 0x0059), .driver_info = BRIDGE_OVFX2 },
4398 {USB_DEVICE(0x0e96, 0xc001), .driver_info = BRIDGE_OVFX2 },
Hans de Goedea511ba92009-10-16 07:13:07 -03004399 {USB_DEVICE(0x1046, 0x9967), .driver_info = BRIDGE_W9968CF },
Jean-François Moine87bae742010-11-12 05:31:34 -03004400 {USB_DEVICE(0x8020, 0xef04), .driver_info = BRIDGE_OVFX2 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004401 {}
4402};
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03004403
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004404MODULE_DEVICE_TABLE(usb, device_table);
4405
4406/* -- device connect -- */
4407static int sd_probe(struct usb_interface *intf,
4408 const struct usb_device_id *id)
4409{
4410 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
4411 THIS_MODULE);
4412}
4413
4414static struct usb_driver sd_driver = {
4415 .name = MODULE_NAME,
4416 .id_table = device_table,
4417 .probe = sd_probe,
4418 .disconnect = gspca_disconnect,
Jean-Francois Moine6a709742008-09-03 16:48:10 -03004419#ifdef CONFIG_PM
4420 .suspend = gspca_suspend,
4421 .resume = gspca_resume,
4422#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004423};
4424
4425/* -- module insert / remove -- */
4426static int __init sd_mod_init(void)
4427{
Jean-François Moine54826432010-09-13 04:53:03 -03004428 return usb_register(&sd_driver);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004429}
4430static void __exit sd_mod_exit(void)
4431{
4432 usb_deregister(&sd_driver);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004433}
4434
4435module_init(sd_mod_init);
4436module_exit(sd_mod_exit);
4437
4438module_param(frame_rate, int, 0644);
4439MODULE_PARM_DESC(frame_rate, "Frame rate (5, 10, 15, 20 or 30 fps)");