blob: 42670ec7ef3b1d46c9c8006071493fee4724201d [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 Beauxis2961e872008-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 Beauxis2961e872008-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 Beauxis2961e872008-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
Jean-François Moine42e142f2010-11-13 05:10:27 -030085#define BRIDGE_OV519 4 /* = ov530 */
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,
Jean-François Moine07c6c9c2011-02-10 13:32:22 -0300121 SEN_OV2610AE,
Jean-François Moine7bbe6b82010-11-11 08:27:24 -0300122 SEN_OV3610,
123 SEN_OV6620,
124 SEN_OV6630,
125 SEN_OV66308AF,
126 SEN_OV7610,
127 SEN_OV7620,
128 SEN_OV7620AE,
129 SEN_OV7640,
130 SEN_OV7648,
Jean-François Moine42e142f2010-11-13 05:10:27 -0300131 SEN_OV7660,
Jean-François Moine7bbe6b82010-11-11 08:27:24 -0300132 SEN_OV7670,
133 SEN_OV76BE,
134 SEN_OV8610,
135};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300136
Hans de Goedea511ba92009-10-16 07:13:07 -0300137/* Note this is a bit of a hack, but the w9968cf driver needs the code for all
138 the ov sensors which is already present here. When we have the time we
139 really should move the sensor drivers to v4l2 sub drivers. */
140#include "w996Xcf.c"
141
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300142/* V4L2 controls supported by the driver */
Hans de Goede49809d62009-06-07 12:10:39 -0300143static void setbrightness(struct gspca_dev *gspca_dev);
144static void setcontrast(struct gspca_dev *gspca_dev);
145static void setcolors(struct gspca_dev *gspca_dev);
Jean-François Moine62833ac2010-10-02 04:27:02 -0300146static void sethvflip(struct gspca_dev *gspca_dev);
147static void setautobright(struct gspca_dev *gspca_dev);
148static void setfreq(struct gspca_dev *gspca_dev);
149static void setfreq_i(struct sd *sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300150
Hans de Goede02ab18b2009-06-14 04:32:04 -0300151static const struct ctrl sd_ctrls[] = {
Jean-François Moine62833ac2010-10-02 04:27:02 -0300152[BRIGHTNESS] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300153 {
154 .id = V4L2_CID_BRIGHTNESS,
155 .type = V4L2_CTRL_TYPE_INTEGER,
156 .name = "Brightness",
157 .minimum = 0,
158 .maximum = 255,
159 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300160 .default_value = 127,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300161 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300162 .set_control = setbrightness,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300163 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300164[CONTRAST] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300165 {
166 .id = V4L2_CID_CONTRAST,
167 .type = V4L2_CTRL_TYPE_INTEGER,
168 .name = "Contrast",
169 .minimum = 0,
170 .maximum = 255,
171 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300172 .default_value = 127,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300173 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300174 .set_control = setcontrast,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300175 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300176[COLORS] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300177 {
178 .id = V4L2_CID_SATURATION,
179 .type = V4L2_CTRL_TYPE_INTEGER,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300180 .name = "Color",
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300181 .minimum = 0,
182 .maximum = 255,
183 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300184 .default_value = 127,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300185 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300186 .set_control = setcolors,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300187 },
Jean-François Moine42e142f2010-11-13 05:10:27 -0300188/* The flip controls work for sensors ov7660 and ov7670 only */
Jean-François Moine62833ac2010-10-02 04:27:02 -0300189[HFLIP] = {
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300190 {
191 .id = V4L2_CID_HFLIP,
192 .type = V4L2_CTRL_TYPE_BOOLEAN,
193 .name = "Mirror",
194 .minimum = 0,
195 .maximum = 1,
196 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300197 .default_value = 0,
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300198 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300199 .set_control = sethvflip,
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300200 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300201[VFLIP] = {
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300202 {
203 .id = V4L2_CID_VFLIP,
204 .type = V4L2_CTRL_TYPE_BOOLEAN,
205 .name = "Vflip",
206 .minimum = 0,
207 .maximum = 1,
208 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300209 .default_value = 0,
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300210 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300211 .set_control = sethvflip,
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300212 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300213[AUTOBRIGHT] = {
Hans de Goede02ab18b2009-06-14 04:32:04 -0300214 {
215 .id = V4L2_CID_AUTOBRIGHTNESS,
216 .type = V4L2_CTRL_TYPE_BOOLEAN,
217 .name = "Auto Brightness",
218 .minimum = 0,
219 .maximum = 1,
220 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300221 .default_value = 1,
Hans de Goede02ab18b2009-06-14 04:32:04 -0300222 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300223 .set_control = setautobright,
Hans de Goede02ab18b2009-06-14 04:32:04 -0300224 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300225[FREQ] = {
Hans de Goede02ab18b2009-06-14 04:32:04 -0300226 {
227 .id = V4L2_CID_POWER_LINE_FREQUENCY,
228 .type = V4L2_CTRL_TYPE_MENU,
229 .name = "Light frequency filter",
230 .minimum = 0,
Jean-François Moine87bae742010-11-12 05:31:34 -0300231 .maximum = 2, /* 0: no flicker, 1: 50Hz, 2:60Hz, 3: auto */
Hans de Goede02ab18b2009-06-14 04:32:04 -0300232 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300233 .default_value = 0,
Hans de Goede02ab18b2009-06-14 04:32:04 -0300234 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300235 .set_control = setfreq,
Hans de Goede02ab18b2009-06-14 04:32:04 -0300236 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300237};
238
Jean-François Moine83db7682010-11-12 07:14:08 -0300239/* table of the disabled controls */
240static const unsigned ctrl_dis[] = {
241[SEN_OV2610] = (1 << NCTRL) - 1, /* no control */
242
Jean-François Moine07c6c9c2011-02-10 13:32:22 -0300243[SEN_OV2610AE] = (1 << NCTRL) - 1, /* no control */
244
Jean-François Moine83db7682010-11-12 07:14:08 -0300245[SEN_OV3610] = (1 << NCTRL) - 1, /* no control */
246
247[SEN_OV6620] = (1 << HFLIP) |
248 (1 << VFLIP),
249
250[SEN_OV6630] = (1 << HFLIP) |
251 (1 << VFLIP),
252
253[SEN_OV66308AF] = (1 << HFLIP) |
254 (1 << VFLIP),
255
256[SEN_OV7610] = (1 << HFLIP) |
257 (1 << VFLIP),
258
259[SEN_OV7620] = (1 << HFLIP) |
260 (1 << VFLIP),
261
262[SEN_OV7620AE] = (1 << HFLIP) |
263 (1 << VFLIP),
264
265[SEN_OV7640] = (1 << HFLIP) |
266 (1 << VFLIP) |
267 (1 << AUTOBRIGHT) |
268 (1 << CONTRAST),
269
270[SEN_OV7648] = (1 << HFLIP) |
271 (1 << VFLIP) |
272 (1 << AUTOBRIGHT) |
273 (1 << CONTRAST),
274
Jean-François Moine42e142f2010-11-13 05:10:27 -0300275[SEN_OV7660] = (1 << AUTOBRIGHT),
276
Jean-François Moine83db7682010-11-12 07:14:08 -0300277[SEN_OV7670] = (1 << COLORS) |
278 (1 << AUTOBRIGHT),
279
280[SEN_OV76BE] = (1 << HFLIP) |
281 (1 << VFLIP),
282
283[SEN_OV8610] = (1 << HFLIP) |
284 (1 << VFLIP) |
285 (1 << FREQ),
286};
287
Hans de Goede49809d62009-06-07 12:10:39 -0300288static const struct v4l2_pix_format ov519_vga_mode[] = {
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300289 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
290 .bytesperline = 320,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300291 .sizeimage = 320 * 240 * 3 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300292 .colorspace = V4L2_COLORSPACE_JPEG,
293 .priv = 1},
294 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
295 .bytesperline = 640,
296 .sizeimage = 640 * 480 * 3 / 8 + 590,
297 .colorspace = V4L2_COLORSPACE_JPEG,
298 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300299};
Hans de Goede49809d62009-06-07 12:10:39 -0300300static const struct v4l2_pix_format ov519_sif_mode[] = {
Hans de Goede124cc9c2009-06-14 05:48:00 -0300301 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
302 .bytesperline = 160,
303 .sizeimage = 160 * 120 * 3 / 8 + 590,
304 .colorspace = V4L2_COLORSPACE_JPEG,
305 .priv = 3},
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300306 {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
307 .bytesperline = 176,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300308 .sizeimage = 176 * 144 * 3 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300309 .colorspace = V4L2_COLORSPACE_JPEG,
310 .priv = 1},
Hans de Goede124cc9c2009-06-14 05:48:00 -0300311 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
312 .bytesperline = 320,
313 .sizeimage = 320 * 240 * 3 / 8 + 590,
314 .colorspace = V4L2_COLORSPACE_JPEG,
315 .priv = 2},
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300316 {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
317 .bytesperline = 352,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300318 .sizeimage = 352 * 288 * 3 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300319 .colorspace = V4L2_COLORSPACE_JPEG,
320 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300321};
322
Hans de Goedeb282d872009-06-14 19:10:40 -0300323/* Note some of the sizeimage values for the ov511 / ov518 may seem
324 larger then necessary, however they need to be this big as the ov511 /
325 ov518 always fills the entire isoc frame, using 0 padding bytes when
326 it doesn't have any data. So with low framerates the amount of data
327 transfered can become quite large (libv4l will remove all the 0 padding
328 in userspace). */
Hans de Goede49809d62009-06-07 12:10:39 -0300329static const struct v4l2_pix_format ov518_vga_mode[] = {
330 {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
331 .bytesperline = 320,
Hans de Goedeb282d872009-06-14 19:10:40 -0300332 .sizeimage = 320 * 240 * 3,
Hans de Goede49809d62009-06-07 12:10:39 -0300333 .colorspace = V4L2_COLORSPACE_JPEG,
334 .priv = 1},
335 {640, 480, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
336 .bytesperline = 640,
Hans de Goedeb282d872009-06-14 19:10:40 -0300337 .sizeimage = 640 * 480 * 2,
Hans de Goede49809d62009-06-07 12:10:39 -0300338 .colorspace = V4L2_COLORSPACE_JPEG,
339 .priv = 0},
340};
341static const struct v4l2_pix_format ov518_sif_mode[] = {
Hans de Goede124cc9c2009-06-14 05:48:00 -0300342 {160, 120, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
343 .bytesperline = 160,
Hans de Goedeb282d872009-06-14 19:10:40 -0300344 .sizeimage = 70000,
Hans de Goede124cc9c2009-06-14 05:48:00 -0300345 .colorspace = V4L2_COLORSPACE_JPEG,
346 .priv = 3},
Hans de Goede49809d62009-06-07 12:10:39 -0300347 {176, 144, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
348 .bytesperline = 176,
Hans de Goedeb282d872009-06-14 19:10:40 -0300349 .sizeimage = 70000,
Hans de Goede49809d62009-06-07 12:10:39 -0300350 .colorspace = V4L2_COLORSPACE_JPEG,
351 .priv = 1},
Hans de Goede124cc9c2009-06-14 05:48:00 -0300352 {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
353 .bytesperline = 320,
Hans de Goedeb282d872009-06-14 19:10:40 -0300354 .sizeimage = 320 * 240 * 3,
Hans de Goede124cc9c2009-06-14 05:48:00 -0300355 .colorspace = V4L2_COLORSPACE_JPEG,
356 .priv = 2},
Hans de Goede49809d62009-06-07 12:10:39 -0300357 {352, 288, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
358 .bytesperline = 352,
Hans de Goedeb282d872009-06-14 19:10:40 -0300359 .sizeimage = 352 * 288 * 3,
Hans de Goede49809d62009-06-07 12:10:39 -0300360 .colorspace = V4L2_COLORSPACE_JPEG,
361 .priv = 0},
362};
363
Hans de Goede1876bb92009-06-14 06:45:50 -0300364static const struct v4l2_pix_format ov511_vga_mode[] = {
365 {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
366 .bytesperline = 320,
367 .sizeimage = 320 * 240 * 3,
368 .colorspace = V4L2_COLORSPACE_JPEG,
369 .priv = 1},
370 {640, 480, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
371 .bytesperline = 640,
372 .sizeimage = 640 * 480 * 2,
373 .colorspace = V4L2_COLORSPACE_JPEG,
374 .priv = 0},
375};
376static const struct v4l2_pix_format ov511_sif_mode[] = {
377 {160, 120, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
378 .bytesperline = 160,
Hans de Goedeb282d872009-06-14 19:10:40 -0300379 .sizeimage = 70000,
Hans de Goede1876bb92009-06-14 06:45:50 -0300380 .colorspace = V4L2_COLORSPACE_JPEG,
381 .priv = 3},
382 {176, 144, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
383 .bytesperline = 176,
Hans de Goedeb282d872009-06-14 19:10:40 -0300384 .sizeimage = 70000,
Hans de Goede1876bb92009-06-14 06:45:50 -0300385 .colorspace = V4L2_COLORSPACE_JPEG,
386 .priv = 1},
387 {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
388 .bytesperline = 320,
389 .sizeimage = 320 * 240 * 3,
390 .colorspace = V4L2_COLORSPACE_JPEG,
391 .priv = 2},
392 {352, 288, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
393 .bytesperline = 352,
394 .sizeimage = 352 * 288 * 3,
395 .colorspace = V4L2_COLORSPACE_JPEG,
396 .priv = 0},
397};
Hans de Goede49809d62009-06-07 12:10:39 -0300398
Hans de Goede635118d2009-10-11 09:49:03 -0300399static const struct v4l2_pix_format ovfx2_vga_mode[] = {
400 {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
401 .bytesperline = 320,
402 .sizeimage = 320 * 240,
403 .colorspace = V4L2_COLORSPACE_SRGB,
404 .priv = 1},
405 {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
406 .bytesperline = 640,
407 .sizeimage = 640 * 480,
408 .colorspace = V4L2_COLORSPACE_SRGB,
409 .priv = 0},
410};
411static const struct v4l2_pix_format ovfx2_cif_mode[] = {
412 {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
413 .bytesperline = 160,
414 .sizeimage = 160 * 120,
415 .colorspace = V4L2_COLORSPACE_SRGB,
416 .priv = 3},
417 {176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
418 .bytesperline = 176,
419 .sizeimage = 176 * 144,
420 .colorspace = V4L2_COLORSPACE_SRGB,
421 .priv = 1},
422 {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
423 .bytesperline = 320,
424 .sizeimage = 320 * 240,
425 .colorspace = V4L2_COLORSPACE_SRGB,
426 .priv = 2},
427 {352, 288, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
428 .bytesperline = 352,
429 .sizeimage = 352 * 288,
430 .colorspace = V4L2_COLORSPACE_SRGB,
431 .priv = 0},
432};
433static const struct v4l2_pix_format ovfx2_ov2610_mode[] = {
Jean-François Moinec42cedb2011-02-10 13:37:48 -0300434 {800, 600, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
435 .bytesperline = 800,
436 .sizeimage = 800 * 600,
437 .colorspace = V4L2_COLORSPACE_SRGB,
438 .priv = 1},
Hans de Goede635118d2009-10-11 09:49:03 -0300439 {1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
440 .bytesperline = 1600,
441 .sizeimage = 1600 * 1200,
442 .colorspace = V4L2_COLORSPACE_SRGB},
443};
444static const struct v4l2_pix_format ovfx2_ov3610_mode[] = {
Hans de Goede635118d2009-10-11 09:49:03 -0300445 {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
446 .bytesperline = 640,
447 .sizeimage = 640 * 480,
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300448 .colorspace = V4L2_COLORSPACE_SRGB,
449 .priv = 1},
450 {800, 600, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
451 .bytesperline = 800,
452 .sizeimage = 800 * 600,
453 .colorspace = V4L2_COLORSPACE_SRGB,
454 .priv = 1},
455 {1024, 768, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
456 .bytesperline = 1024,
457 .sizeimage = 1024 * 768,
458 .colorspace = V4L2_COLORSPACE_SRGB,
459 .priv = 1},
460 {1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
461 .bytesperline = 1600,
462 .sizeimage = 1600 * 1200,
463 .colorspace = V4L2_COLORSPACE_SRGB,
464 .priv = 0},
465 {2048, 1536, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
466 .bytesperline = 2048,
467 .sizeimage = 2048 * 1536,
468 .colorspace = V4L2_COLORSPACE_SRGB,
469 .priv = 0},
Hans de Goede635118d2009-10-11 09:49:03 -0300470};
471
Hans de Goede49809d62009-06-07 12:10:39 -0300472/* Registers common to OV511 / OV518 */
Hans de Goede1876bb92009-06-14 06:45:50 -0300473#define R51x_FIFO_PSIZE 0x30 /* 2 bytes wide w/ OV518(+) */
Jean-François Moine780e3122010-10-19 04:29:10 -0300474#define R51x_SYS_RESET 0x50
Hans de Goede1876bb92009-06-14 06:45:50 -0300475 /* Reset type flags */
476 #define OV511_RESET_OMNICE 0x08
Jean-François Moine780e3122010-10-19 04:29:10 -0300477#define R51x_SYS_INIT 0x53
Hans de Goede49809d62009-06-07 12:10:39 -0300478#define R51x_SYS_SNAP 0x52
Jean-François Moine87bae742010-11-12 05:31:34 -0300479#define R51x_SYS_CUST_ID 0x5f
Hans de Goede49809d62009-06-07 12:10:39 -0300480#define R51x_COMP_LUT_BEGIN 0x80
481
482/* OV511 Camera interface register numbers */
Hans de Goede1876bb92009-06-14 06:45:50 -0300483#define R511_CAM_DELAY 0x10
484#define R511_CAM_EDGE 0x11
485#define R511_CAM_PXCNT 0x12
486#define R511_CAM_LNCNT 0x13
487#define R511_CAM_PXDIV 0x14
488#define R511_CAM_LNDIV 0x15
489#define R511_CAM_UV_EN 0x16
490#define R511_CAM_LINE_MODE 0x17
491#define R511_CAM_OPTS 0x18
492
493#define R511_SNAP_FRAME 0x19
Jean-François Moine87bae742010-11-12 05:31:34 -0300494#define R511_SNAP_PXCNT 0x1a
495#define R511_SNAP_LNCNT 0x1b
496#define R511_SNAP_PXDIV 0x1c
497#define R511_SNAP_LNDIV 0x1d
498#define R511_SNAP_UV_EN 0x1e
Jean-François Moine87bae742010-11-12 05:31:34 -0300499#define R511_SNAP_OPTS 0x1f
Hans de Goede1876bb92009-06-14 06:45:50 -0300500
501#define R511_DRAM_FLOW_CTL 0x20
502#define R511_FIFO_OPTS 0x31
503#define R511_I2C_CTL 0x40
Hans de Goede49809d62009-06-07 12:10:39 -0300504#define R511_SYS_LED_CTL 0x55 /* OV511+ only */
Hans de Goede1876bb92009-06-14 06:45:50 -0300505#define R511_COMP_EN 0x78
506#define R511_COMP_LUT_EN 0x79
Hans de Goede49809d62009-06-07 12:10:39 -0300507
508/* OV518 Camera interface register numbers */
509#define R518_GPIO_OUT 0x56 /* OV518(+) only */
510#define R518_GPIO_CTL 0x57 /* OV518(+) only */
511
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300512/* OV519 Camera interface register numbers */
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300513#define OV519_R10_H_SIZE 0x10
514#define OV519_R11_V_SIZE 0x11
515#define OV519_R12_X_OFFSETL 0x12
516#define OV519_R13_X_OFFSETH 0x13
517#define OV519_R14_Y_OFFSETL 0x14
518#define OV519_R15_Y_OFFSETH 0x15
519#define OV519_R16_DIVIDER 0x16
520#define OV519_R20_DFR 0x20
521#define OV519_R25_FORMAT 0x25
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300522
523/* OV519 System Controller register numbers */
Jean-François Moine21867802010-11-12 06:12:09 -0300524#define OV519_R51_RESET1 0x51
525#define OV519_R54_EN_CLK1 0x54
Jean-François Moineb4e96ea2010-11-12 16:13:17 -0300526#define OV519_R57_SNAPSHOT 0x57
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300527
528#define OV519_GPIO_DATA_OUT0 0x71
529#define OV519_GPIO_IO_CTRL0 0x72
530
Jean-François Moine87bae742010-11-12 05:31:34 -0300531/*#define OV511_ENDPOINT_ADDRESS 1 * Isoc endpoint number */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300532
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300533/*
534 * The FX2 chip does not give us a zero length read at end of frame.
535 * It does, however, give a short read at the end of a frame, if
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800536 * necessary, rather than run two frames together.
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300537 *
538 * By choosing the right bulk transfer size, we are guaranteed to always
539 * get a short read for the last read of each frame. Frame sizes are
540 * always a composite number (width * height, or a multiple) so if we
541 * choose a prime number, we are guaranteed that the last read of a
542 * frame will be short.
543 *
544 * But it isn't that easy: the 2.6 kernel requires a multiple of 4KB,
545 * otherwise EOVERFLOW "babbling" errors occur. I have not been able
546 * to figure out why. [PMiller]
547 *
548 * The constant (13 * 4096) is the largest "prime enough" number less than 64KB.
549 *
550 * It isn't enough to know the number of bytes per frame, in case we
551 * have data dropouts or buffer overruns (even though the FX2 double
552 * buffers, there are some pretty strict real time constraints for
553 * isochronous transfer for larger frame sizes).
554 */
Jean-François Moinec42cedb2011-02-10 13:37:48 -0300555/*jfm: this value works well for 1600x1200, but not 800x600 - see isoc_init */
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300556#define OVFX2_BULK_SIZE (13 * 4096)
557
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300558/* I2C registers */
559#define R51x_I2C_W_SID 0x41
560#define R51x_I2C_SADDR_3 0x42
561#define R51x_I2C_SADDR_2 0x43
562#define R51x_I2C_R_SID 0x44
563#define R51x_I2C_DATA 0x45
564#define R518_I2C_CTL 0x47 /* OV518(+) only */
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300565#define OVFX2_I2C_ADDR 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300566
567/* I2C ADDRESSES */
568#define OV7xx0_SID 0x42
Hans de Goede229bb7d2009-10-11 07:41:46 -0300569#define OV_HIRES_SID 0x60 /* OV9xxx / OV2xxx / OV3xxx */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300570#define OV8xx0_SID 0xa0
571#define OV6xx0_SID 0xc0
572
573/* OV7610 registers */
574#define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */
Hans de Goede49809d62009-06-07 12:10:39 -0300575#define OV7610_REG_BLUE 0x01 /* blue channel balance */
576#define OV7610_REG_RED 0x02 /* red channel balance */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300577#define OV7610_REG_SAT 0x03 /* saturation */
578#define OV8610_REG_HUE 0x04 /* 04 reserved */
579#define OV7610_REG_CNT 0x05 /* Y contrast */
580#define OV7610_REG_BRT 0x06 /* Y brightness */
581#define OV7610_REG_COM_C 0x14 /* misc common regs */
582#define OV7610_REG_ID_HIGH 0x1c /* manufacturer ID MSB */
583#define OV7610_REG_ID_LOW 0x1d /* manufacturer ID LSB */
584#define OV7610_REG_COM_I 0x29 /* misc settings */
585
Jean-François Moine42e142f2010-11-13 05:10:27 -0300586/* OV7660 and OV7670 registers */
Jean-François Moine21867802010-11-12 06:12:09 -0300587#define OV7670_R00_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
588#define OV7670_R01_BLUE 0x01 /* blue gain */
589#define OV7670_R02_RED 0x02 /* red gain */
590#define OV7670_R03_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */
591#define OV7670_R04_COM1 0x04 /* Control 1 */
592/*#define OV7670_R07_AECHH 0x07 * AEC MS 5 bits */
593#define OV7670_R0C_COM3 0x0c /* Control 3 */
594#define OV7670_R0D_COM4 0x0d /* Control 4 */
595#define OV7670_R0E_COM5 0x0e /* All "reserved" */
596#define OV7670_R0F_COM6 0x0f /* Control 6 */
597#define OV7670_R10_AECH 0x10 /* More bits of AEC value */
598#define OV7670_R11_CLKRC 0x11 /* Clock control */
599#define OV7670_R12_COM7 0x12 /* Control 7 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300600#define OV7670_COM7_FMT_VGA 0x00
601/*#define OV7670_COM7_YUV 0x00 * YUV */
602#define OV7670_COM7_FMT_QVGA 0x10 /* QVGA format */
603#define OV7670_COM7_FMT_MASK 0x38
604#define OV7670_COM7_RESET 0x80 /* Register reset */
Jean-François Moine21867802010-11-12 06:12:09 -0300605#define OV7670_R13_COM8 0x13 /* Control 8 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300606#define OV7670_COM8_AEC 0x01 /* Auto exposure enable */
607#define OV7670_COM8_AWB 0x02 /* White balance enable */
608#define OV7670_COM8_AGC 0x04 /* Auto gain enable */
609#define OV7670_COM8_BFILT 0x20 /* Band filter enable */
610#define OV7670_COM8_AECSTEP 0x40 /* Unlimited AEC step size */
611#define OV7670_COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
Jean-François Moine21867802010-11-12 06:12:09 -0300612#define OV7670_R14_COM9 0x14 /* Control 9 - gain ceiling */
613#define OV7670_R15_COM10 0x15 /* Control 10 */
614#define OV7670_R17_HSTART 0x17 /* Horiz start high bits */
615#define OV7670_R18_HSTOP 0x18 /* Horiz stop high bits */
616#define OV7670_R19_VSTART 0x19 /* Vert start high bits */
617#define OV7670_R1A_VSTOP 0x1a /* Vert stop high bits */
618#define OV7670_R1E_MVFP 0x1e /* Mirror / vflip */
Jean-François Moine87bae742010-11-12 05:31:34 -0300619#define OV7670_MVFP_VFLIP 0x10 /* vertical flip */
620#define OV7670_MVFP_MIRROR 0x20 /* Mirror image */
Jean-François Moine21867802010-11-12 06:12:09 -0300621#define OV7670_R24_AEW 0x24 /* AGC upper limit */
622#define OV7670_R25_AEB 0x25 /* AGC lower limit */
623#define OV7670_R26_VPT 0x26 /* AGC/AEC fast mode op region */
624#define OV7670_R32_HREF 0x32 /* HREF pieces */
625#define OV7670_R3A_TSLB 0x3a /* lots of stuff */
626#define OV7670_R3B_COM11 0x3b /* Control 11 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300627#define OV7670_COM11_EXP 0x02
628#define OV7670_COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */
Jean-François Moine21867802010-11-12 06:12:09 -0300629#define OV7670_R3C_COM12 0x3c /* Control 12 */
630#define OV7670_R3D_COM13 0x3d /* Control 13 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300631#define OV7670_COM13_GAMMA 0x80 /* Gamma enable */
632#define OV7670_COM13_UVSAT 0x40 /* UV saturation auto adjustment */
Jean-François Moine21867802010-11-12 06:12:09 -0300633#define OV7670_R3E_COM14 0x3e /* Control 14 */
634#define OV7670_R3F_EDGE 0x3f /* Edge enhancement factor */
635#define OV7670_R40_COM15 0x40 /* Control 15 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300636/*#define OV7670_COM15_R00FF 0xc0 * 00 to FF */
Jean-François Moine21867802010-11-12 06:12:09 -0300637#define OV7670_R41_COM16 0x41 /* Control 16 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300638#define OV7670_COM16_AWBGAIN 0x08 /* AWB gain enable */
Jean-François Moine42e142f2010-11-13 05:10:27 -0300639/* end of ov7660 common registers */
Jean-François Moine21867802010-11-12 06:12:09 -0300640#define OV7670_R55_BRIGHT 0x55 /* Brightness */
641#define OV7670_R56_CONTRAS 0x56 /* Contrast control */
642#define OV7670_R69_GFIX 0x69 /* Fix gain control */
643/*#define OV7670_R8C_RGB444 0x8c * RGB 444 control */
644#define OV7670_R9F_HAECC1 0x9f /* Hist AEC/AGC control 1 */
645#define OV7670_RA0_HAECC2 0xa0 /* Hist AEC/AGC control 2 */
646#define OV7670_RA5_BD50MAX 0xa5 /* 50hz banding step limit */
647#define OV7670_RA6_HAECC3 0xa6 /* Hist AEC/AGC control 3 */
648#define OV7670_RA7_HAECC4 0xa7 /* Hist AEC/AGC control 4 */
649#define OV7670_RA8_HAECC5 0xa8 /* Hist AEC/AGC control 5 */
650#define OV7670_RA9_HAECC6 0xa9 /* Hist AEC/AGC control 6 */
651#define OV7670_RAA_HAECC7 0xaa /* Hist AEC/AGC control 7 */
652#define OV7670_RAB_BD60MAX 0xab /* 60hz banding step limit */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300653
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300654struct ov_regvals {
Jean-François Moine9d1593a2010-11-11 08:04:06 -0300655 u8 reg;
656 u8 val;
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300657};
658struct ov_i2c_regvals {
Jean-François Moine9d1593a2010-11-11 08:04:06 -0300659 u8 reg;
660 u8 val;
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300661};
662
Hans de Goede635118d2009-10-11 09:49:03 -0300663/* Settings for OV2610 camera chip */
Jean-François Moine780e3122010-10-19 04:29:10 -0300664static const struct ov_i2c_regvals norm_2610[] = {
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300665 { 0x12, 0x80 }, /* reset */
Hans de Goede635118d2009-10-11 09:49:03 -0300666};
667
Jean-François Moine07c6c9c2011-02-10 13:32:22 -0300668static const struct ov_i2c_regvals norm_2610ae[] = {
669 {0x12, 0x80}, /* reset */
670 {0x13, 0xcd},
671 {0x09, 0x01},
672 {0x0d, 0x00},
673 {0x11, 0x80},
674 {0x12, 0x20}, /* 1600x1200 */
675 {0x33, 0x0c},
676 {0x35, 0x90},
677 {0x36, 0x37},
678/* ms-win traces */
679 {0x11, 0x83}, /* clock / 3 ? */
680 {0x2d, 0x00}, /* 60 Hz filter */
681 {0x24, 0xb0}, /* normal colors */
682 {0x25, 0x90},
683 {0x10, 0x43},
684};
685
Jean-François Moine780e3122010-10-19 04:29:10 -0300686static const struct ov_i2c_regvals norm_3620b[] = {
Hans de Goede635118d2009-10-11 09:49:03 -0300687 /*
688 * From the datasheet: "Note that after writing to register COMH
689 * (0x12) to change the sensor mode, registers related to the
690 * sensor’s cropping window will be reset back to their default
691 * values."
692 *
693 * "wait 4096 external clock ... to make sure the sensor is
694 * stable and ready to access registers" i.e. 160us at 24MHz
695 */
Hans de Goede635118d2009-10-11 09:49:03 -0300696 { 0x12, 0x80 }, /* COMH reset */
697 { 0x12, 0x00 }, /* QXGA, master */
698
699 /*
700 * 11 CLKRC "Clock Rate Control"
701 * [7] internal frequency doublers: on
702 * [6] video port mode: master
703 * [5:0] clock divider: 1
704 */
705 { 0x11, 0x80 },
706
707 /*
708 * 13 COMI "Common Control I"
709 * = 192 (0xC0) 11000000
710 * COMI[7] "AEC speed selection"
711 * = 1 (0x01) 1....... "Faster AEC correction"
712 * COMI[6] "AEC speed step selection"
713 * = 1 (0x01) .1...... "Big steps, fast"
714 * COMI[5] "Banding filter on off"
715 * = 0 (0x00) ..0..... "Off"
716 * COMI[4] "Banding filter option"
717 * = 0 (0x00) ...0.... "Main clock is 48 MHz and
718 * the PLL is ON"
719 * COMI[3] "Reserved"
720 * = 0 (0x00) ....0...
721 * COMI[2] "AGC auto manual control selection"
722 * = 0 (0x00) .....0.. "Manual"
723 * COMI[1] "AWB auto manual control selection"
724 * = 0 (0x00) ......0. "Manual"
725 * COMI[0] "Exposure control"
726 * = 0 (0x00) .......0 "Manual"
727 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300728 { 0x13, 0xc0 },
Hans de Goede635118d2009-10-11 09:49:03 -0300729
730 /*
731 * 09 COMC "Common Control C"
732 * = 8 (0x08) 00001000
733 * COMC[7:5] "Reserved"
734 * = 0 (0x00) 000.....
735 * COMC[4] "Sleep Mode Enable"
736 * = 0 (0x00) ...0.... "Normal mode"
737 * COMC[3:2] "Sensor sampling reset timing selection"
738 * = 2 (0x02) ....10.. "Longer reset time"
739 * COMC[1:0] "Output drive current select"
740 * = 0 (0x00) ......00 "Weakest"
741 */
742 { 0x09, 0x08 },
743
744 /*
745 * 0C COMD "Common Control D"
746 * = 8 (0x08) 00001000
747 * COMD[7] "Reserved"
748 * = 0 (0x00) 0.......
749 * COMD[6] "Swap MSB and LSB at the output port"
750 * = 0 (0x00) .0...... "False"
751 * COMD[5:3] "Reserved"
752 * = 1 (0x01) ..001...
753 * COMD[2] "Output Average On Off"
754 * = 0 (0x00) .....0.. "Output Normal"
755 * COMD[1] "Sensor precharge voltage selection"
756 * = 0 (0x00) ......0. "Selects internal
757 * reference precharge
758 * voltage"
759 * COMD[0] "Snapshot option"
760 * = 0 (0x00) .......0 "Enable live video output
761 * after snapshot sequence"
762 */
763 { 0x0c, 0x08 },
764
765 /*
766 * 0D COME "Common Control E"
767 * = 161 (0xA1) 10100001
768 * COME[7] "Output average option"
769 * = 1 (0x01) 1....... "Output average of 4 pixels"
770 * COME[6] "Anti-blooming control"
771 * = 0 (0x00) .0...... "Off"
772 * COME[5:3] "Reserved"
773 * = 4 (0x04) ..100...
774 * COME[2] "Clock output power down pin status"
775 * = 0 (0x00) .....0.. "Tri-state data output pin
776 * on power down"
777 * COME[1] "Data output pin status selection at power down"
778 * = 0 (0x00) ......0. "Tri-state VSYNC, PCLK,
779 * HREF, and CHSYNC pins on
780 * power down"
781 * COME[0] "Auto zero circuit select"
782 * = 1 (0x01) .......1 "On"
783 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300784 { 0x0d, 0xa1 },
Hans de Goede635118d2009-10-11 09:49:03 -0300785
786 /*
787 * 0E COMF "Common Control F"
788 * = 112 (0x70) 01110000
789 * COMF[7] "System clock selection"
790 * = 0 (0x00) 0....... "Use 24 MHz system clock"
791 * COMF[6:4] "Reserved"
792 * = 7 (0x07) .111....
793 * COMF[3] "Manual auto negative offset canceling selection"
794 * = 0 (0x00) ....0... "Auto detect negative
795 * offset and cancel it"
796 * COMF[2:0] "Reserved"
797 * = 0 (0x00) .....000
798 */
799 { 0x0e, 0x70 },
800
801 /*
802 * 0F COMG "Common Control G"
803 * = 66 (0x42) 01000010
804 * COMG[7] "Optical black output selection"
805 * = 0 (0x00) 0....... "Disable"
806 * COMG[6] "Black level calibrate selection"
807 * = 1 (0x01) .1...... "Use optical black pixels
808 * to calibrate"
809 * COMG[5:4] "Reserved"
810 * = 0 (0x00) ..00....
811 * COMG[3] "Channel offset adjustment"
812 * = 0 (0x00) ....0... "Disable offset adjustment"
813 * COMG[2] "ADC black level calibration option"
814 * = 0 (0x00) .....0.. "Use B/G line and G/R
815 * line to calibrate each
816 * channel's black level"
817 * COMG[1] "Reserved"
818 * = 1 (0x01) ......1.
819 * COMG[0] "ADC black level calibration enable"
820 * = 0 (0x00) .......0 "Disable"
821 */
822 { 0x0f, 0x42 },
823
824 /*
825 * 14 COMJ "Common Control J"
826 * = 198 (0xC6) 11000110
827 * COMJ[7:6] "AGC gain ceiling"
828 * = 3 (0x03) 11...... "8x"
829 * COMJ[5:4] "Reserved"
830 * = 0 (0x00) ..00....
831 * COMJ[3] "Auto banding filter"
832 * = 0 (0x00) ....0... "Banding filter is always
833 * on off depending on
834 * COMI[5] setting"
835 * COMJ[2] "VSYNC drop option"
836 * = 1 (0x01) .....1.. "SYNC is dropped if frame
837 * data is dropped"
838 * COMJ[1] "Frame data drop"
839 * = 1 (0x01) ......1. "Drop frame data if
840 * exposure is not within
841 * tolerance. In AEC mode,
842 * data is normally dropped
843 * when data is out of
844 * range."
845 * COMJ[0] "Reserved"
846 * = 0 (0x00) .......0
847 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300848 { 0x14, 0xc6 },
Hans de Goede635118d2009-10-11 09:49:03 -0300849
850 /*
851 * 15 COMK "Common Control K"
852 * = 2 (0x02) 00000010
853 * COMK[7] "CHSYNC pin output swap"
854 * = 0 (0x00) 0....... "CHSYNC"
855 * COMK[6] "HREF pin output swap"
856 * = 0 (0x00) .0...... "HREF"
857 * COMK[5] "PCLK output selection"
858 * = 0 (0x00) ..0..... "PCLK always output"
859 * COMK[4] "PCLK edge selection"
860 * = 0 (0x00) ...0.... "Data valid on falling edge"
861 * COMK[3] "HREF output polarity"
862 * = 0 (0x00) ....0... "positive"
863 * COMK[2] "Reserved"
864 * = 0 (0x00) .....0..
865 * COMK[1] "VSYNC polarity"
866 * = 1 (0x01) ......1. "negative"
867 * COMK[0] "HSYNC polarity"
868 * = 0 (0x00) .......0 "positive"
869 */
870 { 0x15, 0x02 },
871
872 /*
873 * 33 CHLF "Current Control"
874 * = 9 (0x09) 00001001
875 * CHLF[7:6] "Sensor current control"
876 * = 0 (0x00) 00......
877 * CHLF[5] "Sensor current range control"
878 * = 0 (0x00) ..0..... "normal range"
879 * CHLF[4] "Sensor current"
880 * = 0 (0x00) ...0.... "normal current"
881 * CHLF[3] "Sensor buffer current control"
882 * = 1 (0x01) ....1... "half current"
883 * CHLF[2] "Column buffer current control"
884 * = 0 (0x00) .....0.. "normal current"
885 * CHLF[1] "Analog DSP current control"
886 * = 0 (0x00) ......0. "normal current"
887 * CHLF[1] "ADC current control"
888 * = 0 (0x00) ......0. "normal current"
889 */
890 { 0x33, 0x09 },
891
892 /*
893 * 34 VBLM "Blooming Control"
894 * = 80 (0x50) 01010000
895 * VBLM[7] "Hard soft reset switch"
896 * = 0 (0x00) 0....... "Hard reset"
897 * VBLM[6:4] "Blooming voltage selection"
898 * = 5 (0x05) .101....
899 * VBLM[3:0] "Sensor current control"
900 * = 0 (0x00) ....0000
901 */
902 { 0x34, 0x50 },
903
904 /*
905 * 36 VCHG "Sensor Precharge Voltage Control"
906 * = 0 (0x00) 00000000
907 * VCHG[7] "Reserved"
908 * = 0 (0x00) 0.......
909 * VCHG[6:4] "Sensor precharge voltage control"
910 * = 0 (0x00) .000....
911 * VCHG[3:0] "Sensor array common reference"
912 * = 0 (0x00) ....0000
913 */
914 { 0x36, 0x00 },
915
916 /*
917 * 37 ADC "ADC Reference Control"
918 * = 4 (0x04) 00000100
919 * ADC[7:4] "Reserved"
920 * = 0 (0x00) 0000....
921 * ADC[3] "ADC input signal range"
922 * = 0 (0x00) ....0... "Input signal 1.0x"
923 * ADC[2:0] "ADC range control"
924 * = 4 (0x04) .....100
925 */
926 { 0x37, 0x04 },
927
928 /*
929 * 38 ACOM "Analog Common Ground"
930 * = 82 (0x52) 01010010
931 * ACOM[7] "Analog gain control"
932 * = 0 (0x00) 0....... "Gain 1x"
933 * ACOM[6] "Analog black level calibration"
934 * = 1 (0x01) .1...... "On"
935 * ACOM[5:0] "Reserved"
936 * = 18 (0x12) ..010010
937 */
938 { 0x38, 0x52 },
939
940 /*
941 * 3A FREFA "Internal Reference Adjustment"
942 * = 0 (0x00) 00000000
943 * FREFA[7:0] "Range"
944 * = 0 (0x00) 00000000
945 */
946 { 0x3a, 0x00 },
947
948 /*
949 * 3C FVOPT "Internal Reference Adjustment"
950 * = 31 (0x1F) 00011111
951 * FVOPT[7:0] "Range"
952 * = 31 (0x1F) 00011111
953 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300954 { 0x3c, 0x1f },
Hans de Goede635118d2009-10-11 09:49:03 -0300955
956 /*
957 * 44 Undocumented = 0 (0x00) 00000000
958 * 44[7:0] "It's a secret"
959 * = 0 (0x00) 00000000
960 */
961 { 0x44, 0x00 },
962
963 /*
964 * 40 Undocumented = 0 (0x00) 00000000
965 * 40[7:0] "It's a secret"
966 * = 0 (0x00) 00000000
967 */
968 { 0x40, 0x00 },
969
970 /*
971 * 41 Undocumented = 0 (0x00) 00000000
972 * 41[7:0] "It's a secret"
973 * = 0 (0x00) 00000000
974 */
975 { 0x41, 0x00 },
976
977 /*
978 * 42 Undocumented = 0 (0x00) 00000000
979 * 42[7:0] "It's a secret"
980 * = 0 (0x00) 00000000
981 */
982 { 0x42, 0x00 },
983
984 /*
985 * 43 Undocumented = 0 (0x00) 00000000
986 * 43[7:0] "It's a secret"
987 * = 0 (0x00) 00000000
988 */
989 { 0x43, 0x00 },
990
991 /*
992 * 45 Undocumented = 128 (0x80) 10000000
993 * 45[7:0] "It's a secret"
994 * = 128 (0x80) 10000000
995 */
996 { 0x45, 0x80 },
997
998 /*
999 * 48 Undocumented = 192 (0xC0) 11000000
1000 * 48[7:0] "It's a secret"
1001 * = 192 (0xC0) 11000000
1002 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001003 { 0x48, 0xc0 },
Hans de Goede635118d2009-10-11 09:49:03 -03001004
1005 /*
1006 * 49 Undocumented = 25 (0x19) 00011001
1007 * 49[7:0] "It's a secret"
1008 * = 25 (0x19) 00011001
1009 */
1010 { 0x49, 0x19 },
1011
1012 /*
1013 * 4B Undocumented = 128 (0x80) 10000000
1014 * 4B[7:0] "It's a secret"
1015 * = 128 (0x80) 10000000
1016 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001017 { 0x4b, 0x80 },
Hans de Goede635118d2009-10-11 09:49:03 -03001018
1019 /*
1020 * 4D Undocumented = 196 (0xC4) 11000100
1021 * 4D[7:0] "It's a secret"
1022 * = 196 (0xC4) 11000100
1023 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001024 { 0x4d, 0xc4 },
Hans de Goede635118d2009-10-11 09:49:03 -03001025
1026 /*
1027 * 35 VREF "Reference Voltage Control"
Jean-François Moine87bae742010-11-12 05:31:34 -03001028 * = 76 (0x4c) 01001100
Hans de Goede635118d2009-10-11 09:49:03 -03001029 * VREF[7:5] "Column high reference control"
1030 * = 2 (0x02) 010..... "higher voltage"
1031 * VREF[4:2] "Column low reference control"
1032 * = 3 (0x03) ...011.. "Highest voltage"
1033 * VREF[1:0] "Reserved"
1034 * = 0 (0x00) ......00
1035 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001036 { 0x35, 0x4c },
Hans de Goede635118d2009-10-11 09:49:03 -03001037
1038 /*
1039 * 3D Undocumented = 0 (0x00) 00000000
1040 * 3D[7:0] "It's a secret"
1041 * = 0 (0x00) 00000000
1042 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001043 { 0x3d, 0x00 },
Hans de Goede635118d2009-10-11 09:49:03 -03001044
1045 /*
1046 * 3E Undocumented = 0 (0x00) 00000000
1047 * 3E[7:0] "It's a secret"
1048 * = 0 (0x00) 00000000
1049 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001050 { 0x3e, 0x00 },
Hans de Goede635118d2009-10-11 09:49:03 -03001051
1052 /*
1053 * 3B FREFB "Internal Reference Adjustment"
1054 * = 24 (0x18) 00011000
1055 * FREFB[7:0] "Range"
1056 * = 24 (0x18) 00011000
1057 */
1058 { 0x3b, 0x18 },
1059
1060 /*
1061 * 33 CHLF "Current Control"
1062 * = 25 (0x19) 00011001
1063 * CHLF[7:6] "Sensor current control"
1064 * = 0 (0x00) 00......
1065 * CHLF[5] "Sensor current range control"
1066 * = 0 (0x00) ..0..... "normal range"
1067 * CHLF[4] "Sensor current"
1068 * = 1 (0x01) ...1.... "double current"
1069 * CHLF[3] "Sensor buffer current control"
1070 * = 1 (0x01) ....1... "half current"
1071 * CHLF[2] "Column buffer current control"
1072 * = 0 (0x00) .....0.. "normal current"
1073 * CHLF[1] "Analog DSP current control"
1074 * = 0 (0x00) ......0. "normal current"
1075 * CHLF[1] "ADC current control"
1076 * = 0 (0x00) ......0. "normal current"
1077 */
1078 { 0x33, 0x19 },
1079
1080 /*
1081 * 34 VBLM "Blooming Control"
1082 * = 90 (0x5A) 01011010
1083 * VBLM[7] "Hard soft reset switch"
1084 * = 0 (0x00) 0....... "Hard reset"
1085 * VBLM[6:4] "Blooming voltage selection"
1086 * = 5 (0x05) .101....
1087 * VBLM[3:0] "Sensor current control"
1088 * = 10 (0x0A) ....1010
1089 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001090 { 0x34, 0x5a },
Hans de Goede635118d2009-10-11 09:49:03 -03001091
1092 /*
1093 * 3B FREFB "Internal Reference Adjustment"
1094 * = 0 (0x00) 00000000
1095 * FREFB[7:0] "Range"
1096 * = 0 (0x00) 00000000
1097 */
1098 { 0x3b, 0x00 },
1099
1100 /*
1101 * 33 CHLF "Current Control"
1102 * = 9 (0x09) 00001001
1103 * CHLF[7:6] "Sensor current control"
1104 * = 0 (0x00) 00......
1105 * CHLF[5] "Sensor current range control"
1106 * = 0 (0x00) ..0..... "normal range"
1107 * CHLF[4] "Sensor current"
1108 * = 0 (0x00) ...0.... "normal current"
1109 * CHLF[3] "Sensor buffer current control"
1110 * = 1 (0x01) ....1... "half current"
1111 * CHLF[2] "Column buffer current control"
1112 * = 0 (0x00) .....0.. "normal current"
1113 * CHLF[1] "Analog DSP current control"
1114 * = 0 (0x00) ......0. "normal current"
1115 * CHLF[1] "ADC current control"
1116 * = 0 (0x00) ......0. "normal current"
1117 */
1118 { 0x33, 0x09 },
1119
1120 /*
1121 * 34 VBLM "Blooming Control"
1122 * = 80 (0x50) 01010000
1123 * VBLM[7] "Hard soft reset switch"
1124 * = 0 (0x00) 0....... "Hard reset"
1125 * VBLM[6:4] "Blooming voltage selection"
1126 * = 5 (0x05) .101....
1127 * VBLM[3:0] "Sensor current control"
1128 * = 0 (0x00) ....0000
1129 */
1130 { 0x34, 0x50 },
1131
1132 /*
1133 * 12 COMH "Common Control H"
1134 * = 64 (0x40) 01000000
1135 * COMH[7] "SRST"
1136 * = 0 (0x00) 0....... "No-op"
1137 * COMH[6:4] "Resolution selection"
1138 * = 4 (0x04) .100.... "XGA"
1139 * COMH[3] "Master slave selection"
1140 * = 0 (0x00) ....0... "Master mode"
1141 * COMH[2] "Internal B/R channel option"
1142 * = 0 (0x00) .....0.. "B/R use same channel"
1143 * COMH[1] "Color bar test pattern"
1144 * = 0 (0x00) ......0. "Off"
1145 * COMH[0] "Reserved"
1146 * = 0 (0x00) .......0
1147 */
1148 { 0x12, 0x40 },
1149
1150 /*
1151 * 17 HREFST "Horizontal window start"
1152 * = 31 (0x1F) 00011111
1153 * HREFST[7:0] "Horizontal window start, 8 MSBs"
1154 * = 31 (0x1F) 00011111
1155 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001156 { 0x17, 0x1f },
Hans de Goede635118d2009-10-11 09:49:03 -03001157
1158 /*
1159 * 18 HREFEND "Horizontal window end"
1160 * = 95 (0x5F) 01011111
1161 * HREFEND[7:0] "Horizontal Window End, 8 MSBs"
1162 * = 95 (0x5F) 01011111
1163 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001164 { 0x18, 0x5f },
Hans de Goede635118d2009-10-11 09:49:03 -03001165
1166 /*
1167 * 19 VSTRT "Vertical window start"
1168 * = 0 (0x00) 00000000
1169 * VSTRT[7:0] "Vertical Window Start, 8 MSBs"
1170 * = 0 (0x00) 00000000
1171 */
1172 { 0x19, 0x00 },
1173
1174 /*
1175 * 1A VEND "Vertical window end"
1176 * = 96 (0x60) 01100000
1177 * VEND[7:0] "Vertical Window End, 8 MSBs"
1178 * = 96 (0x60) 01100000
1179 */
1180 { 0x1a, 0x60 },
1181
1182 /*
1183 * 32 COMM "Common Control M"
1184 * = 18 (0x12) 00010010
1185 * COMM[7:6] "Pixel clock divide option"
1186 * = 0 (0x00) 00...... "/1"
1187 * COMM[5:3] "Horizontal window end position, 3 LSBs"
1188 * = 2 (0x02) ..010...
1189 * COMM[2:0] "Horizontal window start position, 3 LSBs"
1190 * = 2 (0x02) .....010
1191 */
1192 { 0x32, 0x12 },
1193
1194 /*
1195 * 03 COMA "Common Control A"
1196 * = 74 (0x4A) 01001010
1197 * COMA[7:4] "AWB Update Threshold"
1198 * = 4 (0x04) 0100....
1199 * COMA[3:2] "Vertical window end line control 2 LSBs"
1200 * = 2 (0x02) ....10..
1201 * COMA[1:0] "Vertical window start line control 2 LSBs"
1202 * = 2 (0x02) ......10
1203 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001204 { 0x03, 0x4a },
Hans de Goede635118d2009-10-11 09:49:03 -03001205
1206 /*
1207 * 11 CLKRC "Clock Rate Control"
1208 * = 128 (0x80) 10000000
1209 * CLKRC[7] "Internal frequency doublers on off seclection"
1210 * = 1 (0x01) 1....... "On"
1211 * CLKRC[6] "Digital video master slave selection"
1212 * = 0 (0x00) .0...... "Master mode, sensor
1213 * provides PCLK"
1214 * CLKRC[5:0] "Clock divider { CLK = PCLK/(1+CLKRC[5:0]) }"
1215 * = 0 (0x00) ..000000
1216 */
1217 { 0x11, 0x80 },
1218
1219 /*
1220 * 12 COMH "Common Control H"
1221 * = 0 (0x00) 00000000
1222 * COMH[7] "SRST"
1223 * = 0 (0x00) 0....... "No-op"
1224 * COMH[6:4] "Resolution selection"
1225 * = 0 (0x00) .000.... "QXGA"
1226 * COMH[3] "Master slave selection"
1227 * = 0 (0x00) ....0... "Master mode"
1228 * COMH[2] "Internal B/R channel option"
1229 * = 0 (0x00) .....0.. "B/R use same channel"
1230 * COMH[1] "Color bar test pattern"
1231 * = 0 (0x00) ......0. "Off"
1232 * COMH[0] "Reserved"
1233 * = 0 (0x00) .......0
1234 */
1235 { 0x12, 0x00 },
1236
1237 /*
1238 * 12 COMH "Common Control H"
1239 * = 64 (0x40) 01000000
1240 * COMH[7] "SRST"
1241 * = 0 (0x00) 0....... "No-op"
1242 * COMH[6:4] "Resolution selection"
1243 * = 4 (0x04) .100.... "XGA"
1244 * COMH[3] "Master slave selection"
1245 * = 0 (0x00) ....0... "Master mode"
1246 * COMH[2] "Internal B/R channel option"
1247 * = 0 (0x00) .....0.. "B/R use same channel"
1248 * COMH[1] "Color bar test pattern"
1249 * = 0 (0x00) ......0. "Off"
1250 * COMH[0] "Reserved"
1251 * = 0 (0x00) .......0
1252 */
1253 { 0x12, 0x40 },
1254
1255 /*
1256 * 17 HREFST "Horizontal window start"
1257 * = 31 (0x1F) 00011111
1258 * HREFST[7:0] "Horizontal window start, 8 MSBs"
1259 * = 31 (0x1F) 00011111
1260 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001261 { 0x17, 0x1f },
Hans de Goede635118d2009-10-11 09:49:03 -03001262
1263 /*
1264 * 18 HREFEND "Horizontal window end"
1265 * = 95 (0x5F) 01011111
1266 * HREFEND[7:0] "Horizontal Window End, 8 MSBs"
1267 * = 95 (0x5F) 01011111
1268 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001269 { 0x18, 0x5f },
Hans de Goede635118d2009-10-11 09:49:03 -03001270
1271 /*
1272 * 19 VSTRT "Vertical window start"
1273 * = 0 (0x00) 00000000
1274 * VSTRT[7:0] "Vertical Window Start, 8 MSBs"
1275 * = 0 (0x00) 00000000
1276 */
1277 { 0x19, 0x00 },
1278
1279 /*
1280 * 1A VEND "Vertical window end"
1281 * = 96 (0x60) 01100000
1282 * VEND[7:0] "Vertical Window End, 8 MSBs"
1283 * = 96 (0x60) 01100000
1284 */
1285 { 0x1a, 0x60 },
1286
1287 /*
1288 * 32 COMM "Common Control M"
1289 * = 18 (0x12) 00010010
1290 * COMM[7:6] "Pixel clock divide option"
1291 * = 0 (0x00) 00...... "/1"
1292 * COMM[5:3] "Horizontal window end position, 3 LSBs"
1293 * = 2 (0x02) ..010...
1294 * COMM[2:0] "Horizontal window start position, 3 LSBs"
1295 * = 2 (0x02) .....010
1296 */
1297 { 0x32, 0x12 },
1298
1299 /*
1300 * 03 COMA "Common Control A"
1301 * = 74 (0x4A) 01001010
1302 * COMA[7:4] "AWB Update Threshold"
1303 * = 4 (0x04) 0100....
1304 * COMA[3:2] "Vertical window end line control 2 LSBs"
1305 * = 2 (0x02) ....10..
1306 * COMA[1:0] "Vertical window start line control 2 LSBs"
1307 * = 2 (0x02) ......10
1308 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001309 { 0x03, 0x4a },
Hans de Goede635118d2009-10-11 09:49:03 -03001310
1311 /*
1312 * 02 RED "Red Gain Control"
1313 * = 175 (0xAF) 10101111
1314 * RED[7] "Action"
1315 * = 1 (0x01) 1....... "gain = 1/(1+bitrev([6:0]))"
1316 * RED[6:0] "Value"
1317 * = 47 (0x2F) .0101111
1318 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001319 { 0x02, 0xaf },
Hans de Goede635118d2009-10-11 09:49:03 -03001320
1321 /*
1322 * 2D ADDVSL "VSYNC Pulse Width"
1323 * = 210 (0xD2) 11010010
1324 * ADDVSL[7:0] "VSYNC pulse width, LSB"
1325 * = 210 (0xD2) 11010010
1326 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001327 { 0x2d, 0xd2 },
Hans de Goede635118d2009-10-11 09:49:03 -03001328
1329 /*
1330 * 00 GAIN = 24 (0x18) 00011000
1331 * GAIN[7:6] "Reserved"
1332 * = 0 (0x00) 00......
1333 * GAIN[5] "Double"
1334 * = 0 (0x00) ..0..... "False"
1335 * GAIN[4] "Double"
1336 * = 1 (0x01) ...1.... "True"
1337 * GAIN[3:0] "Range"
1338 * = 8 (0x08) ....1000
1339 */
1340 { 0x00, 0x18 },
1341
1342 /*
1343 * 01 BLUE "Blue Gain Control"
1344 * = 240 (0xF0) 11110000
1345 * BLUE[7] "Action"
1346 * = 1 (0x01) 1....... "gain = 1/(1+bitrev([6:0]))"
1347 * BLUE[6:0] "Value"
1348 * = 112 (0x70) .1110000
1349 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001350 { 0x01, 0xf0 },
Hans de Goede635118d2009-10-11 09:49:03 -03001351
1352 /*
1353 * 10 AEC "Automatic Exposure Control"
1354 * = 10 (0x0A) 00001010
1355 * AEC[7:0] "Automatic Exposure Control, 8 MSBs"
1356 * = 10 (0x0A) 00001010
1357 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001358 { 0x10, 0x0a },
Hans de Goede635118d2009-10-11 09:49:03 -03001359
Jean-François Moine87bae742010-11-12 05:31:34 -03001360 { 0xe1, 0x67 },
1361 { 0xe3, 0x03 },
1362 { 0xe4, 0x26 },
1363 { 0xe5, 0x3e },
1364 { 0xf8, 0x01 },
1365 { 0xff, 0x01 },
Hans de Goede635118d2009-10-11 09:49:03 -03001366};
1367
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001368static const struct ov_i2c_regvals norm_6x20[] = {
1369 { 0x12, 0x80 }, /* reset */
1370 { 0x11, 0x01 },
1371 { 0x03, 0x60 },
1372 { 0x05, 0x7f }, /* For when autoadjust is off */
1373 { 0x07, 0xa8 },
Jean-François Moine87bae742010-11-12 05:31:34 -03001374 /* The ratio of 0x0c and 0x0d controls the white point */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001375 { 0x0c, 0x24 },
1376 { 0x0d, 0x24 },
1377 { 0x0f, 0x15 }, /* COMS */
1378 { 0x10, 0x75 }, /* AEC Exposure time */
1379 { 0x12, 0x24 }, /* Enable AGC */
1380 { 0x14, 0x04 },
1381 /* 0x16: 0x06 helps frame stability with moving objects */
1382 { 0x16, 0x06 },
1383/* { 0x20, 0x30 }, * Aperture correction enable */
1384 { 0x26, 0xb2 }, /* BLC enable */
1385 /* 0x28: 0x05 Selects RGB format if RGB on */
1386 { 0x28, 0x05 },
1387 { 0x2a, 0x04 }, /* Disable framerate adjust */
1388/* { 0x2b, 0xac }, * Framerate; Set 2a[7] first */
Hans de Goedeae49c402009-06-14 19:15:07 -03001389 { 0x2d, 0x85 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001390 { 0x33, 0xa0 }, /* Color Processing Parameter */
1391 { 0x34, 0xd2 }, /* Max A/D range */
1392 { 0x38, 0x8b },
1393 { 0x39, 0x40 },
1394
1395 { 0x3c, 0x39 }, /* Enable AEC mode changing */
1396 { 0x3c, 0x3c }, /* Change AEC mode */
1397 { 0x3c, 0x24 }, /* Disable AEC mode changing */
1398
1399 { 0x3d, 0x80 },
1400 /* These next two registers (0x4a, 0x4b) are undocumented.
1401 * They control the color balance */
1402 { 0x4a, 0x80 },
1403 { 0x4b, 0x80 },
1404 { 0x4d, 0xd2 }, /* This reduces noise a bit */
1405 { 0x4e, 0xc1 },
1406 { 0x4f, 0x04 },
1407/* Do 50-53 have any effect? */
1408/* Toggle 0x12[2] off and on here? */
1409};
1410
1411static const struct ov_i2c_regvals norm_6x30[] = {
1412 { 0x12, 0x80 }, /* Reset */
1413 { 0x00, 0x1f }, /* Gain */
1414 { 0x01, 0x99 }, /* Blue gain */
1415 { 0x02, 0x7c }, /* Red gain */
1416 { 0x03, 0xc0 }, /* Saturation */
1417 { 0x05, 0x0a }, /* Contrast */
1418 { 0x06, 0x95 }, /* Brightness */
1419 { 0x07, 0x2d }, /* Sharpness */
1420 { 0x0c, 0x20 },
1421 { 0x0d, 0x20 },
Hans de Goede02ab18b2009-06-14 04:32:04 -03001422 { 0x0e, 0xa0 }, /* Was 0x20, bit7 enables a 2x gain which we need */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001423 { 0x0f, 0x05 },
1424 { 0x10, 0x9a },
1425 { 0x11, 0x00 }, /* Pixel clock = fastest */
1426 { 0x12, 0x24 }, /* Enable AGC and AWB */
1427 { 0x13, 0x21 },
1428 { 0x14, 0x80 },
1429 { 0x15, 0x01 },
1430 { 0x16, 0x03 },
1431 { 0x17, 0x38 },
1432 { 0x18, 0xea },
1433 { 0x19, 0x04 },
1434 { 0x1a, 0x93 },
1435 { 0x1b, 0x00 },
1436 { 0x1e, 0xc4 },
1437 { 0x1f, 0x04 },
1438 { 0x20, 0x20 },
1439 { 0x21, 0x10 },
1440 { 0x22, 0x88 },
1441 { 0x23, 0xc0 }, /* Crystal circuit power level */
1442 { 0x25, 0x9a }, /* Increase AEC black ratio */
1443 { 0x26, 0xb2 }, /* BLC enable */
1444 { 0x27, 0xa2 },
1445 { 0x28, 0x00 },
1446 { 0x29, 0x00 },
1447 { 0x2a, 0x84 }, /* 60 Hz power */
1448 { 0x2b, 0xa8 }, /* 60 Hz power */
1449 { 0x2c, 0xa0 },
1450 { 0x2d, 0x95 }, /* Enable auto-brightness */
1451 { 0x2e, 0x88 },
1452 { 0x33, 0x26 },
1453 { 0x34, 0x03 },
1454 { 0x36, 0x8f },
1455 { 0x37, 0x80 },
1456 { 0x38, 0x83 },
1457 { 0x39, 0x80 },
1458 { 0x3a, 0x0f },
1459 { 0x3b, 0x3c },
1460 { 0x3c, 0x1a },
1461 { 0x3d, 0x80 },
1462 { 0x3e, 0x80 },
1463 { 0x3f, 0x0e },
1464 { 0x40, 0x00 }, /* White bal */
1465 { 0x41, 0x00 }, /* White bal */
1466 { 0x42, 0x80 },
1467 { 0x43, 0x3f }, /* White bal */
1468 { 0x44, 0x80 },
1469 { 0x45, 0x20 },
1470 { 0x46, 0x20 },
1471 { 0x47, 0x80 },
1472 { 0x48, 0x7f },
1473 { 0x49, 0x00 },
1474 { 0x4a, 0x00 },
1475 { 0x4b, 0x80 },
1476 { 0x4c, 0xd0 },
1477 { 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
1478 { 0x4e, 0x40 },
1479 { 0x4f, 0x07 }, /* UV avg., col. killer: max */
1480 { 0x50, 0xff },
1481 { 0x54, 0x23 }, /* Max AGC gain: 18dB */
1482 { 0x55, 0xff },
1483 { 0x56, 0x12 },
1484 { 0x57, 0x81 },
1485 { 0x58, 0x75 },
1486 { 0x59, 0x01 }, /* AGC dark current comp.: +1 */
1487 { 0x5a, 0x2c },
1488 { 0x5b, 0x0f }, /* AWB chrominance levels */
1489 { 0x5c, 0x10 },
1490 { 0x3d, 0x80 },
1491 { 0x27, 0xa6 },
1492 { 0x12, 0x20 }, /* Toggle AWB */
1493 { 0x12, 0x24 },
1494};
1495
1496/* Lawrence Glaister <lg@jfm.bc.ca> reports:
1497 *
1498 * Register 0x0f in the 7610 has the following effects:
1499 *
1500 * 0x85 (AEC method 1): Best overall, good contrast range
1501 * 0x45 (AEC method 2): Very overexposed
1502 * 0xa5 (spec sheet default): Ok, but the black level is
1503 * shifted resulting in loss of contrast
1504 * 0x05 (old driver setting): very overexposed, too much
1505 * contrast
1506 */
1507static const struct ov_i2c_regvals norm_7610[] = {
1508 { 0x10, 0xff },
1509 { 0x16, 0x06 },
1510 { 0x28, 0x24 },
1511 { 0x2b, 0xac },
1512 { 0x12, 0x00 },
1513 { 0x38, 0x81 },
1514 { 0x28, 0x24 }, /* 0c */
1515 { 0x0f, 0x85 }, /* lg's setting */
1516 { 0x15, 0x01 },
1517 { 0x20, 0x1c },
1518 { 0x23, 0x2a },
1519 { 0x24, 0x10 },
1520 { 0x25, 0x8a },
1521 { 0x26, 0xa2 },
1522 { 0x27, 0xc2 },
1523 { 0x2a, 0x04 },
1524 { 0x2c, 0xfe },
1525 { 0x2d, 0x93 },
1526 { 0x30, 0x71 },
1527 { 0x31, 0x60 },
1528 { 0x32, 0x26 },
1529 { 0x33, 0x20 },
1530 { 0x34, 0x48 },
1531 { 0x12, 0x24 },
1532 { 0x11, 0x01 },
1533 { 0x0c, 0x24 },
1534 { 0x0d, 0x24 },
1535};
1536
1537static const struct ov_i2c_regvals norm_7620[] = {
Hans de Goedea511ba92009-10-16 07:13:07 -03001538 { 0x12, 0x80 }, /* reset */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001539 { 0x00, 0x00 }, /* gain */
1540 { 0x01, 0x80 }, /* blue gain */
1541 { 0x02, 0x80 }, /* red gain */
Jean-François Moine21867802010-11-12 06:12:09 -03001542 { 0x03, 0xc0 }, /* OV7670_R03_VREF */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001543 { 0x06, 0x60 },
1544 { 0x07, 0x00 },
1545 { 0x0c, 0x24 },
1546 { 0x0c, 0x24 },
1547 { 0x0d, 0x24 },
1548 { 0x11, 0x01 },
1549 { 0x12, 0x24 },
1550 { 0x13, 0x01 },
1551 { 0x14, 0x84 },
1552 { 0x15, 0x01 },
1553 { 0x16, 0x03 },
1554 { 0x17, 0x2f },
1555 { 0x18, 0xcf },
1556 { 0x19, 0x06 },
1557 { 0x1a, 0xf5 },
1558 { 0x1b, 0x00 },
1559 { 0x20, 0x18 },
1560 { 0x21, 0x80 },
1561 { 0x22, 0x80 },
1562 { 0x23, 0x00 },
1563 { 0x26, 0xa2 },
1564 { 0x27, 0xea },
Hans de Goedeb282d872009-06-14 19:10:40 -03001565 { 0x28, 0x22 }, /* Was 0x20, bit1 enables a 2x gain which we need */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001566 { 0x29, 0x00 },
1567 { 0x2a, 0x10 },
1568 { 0x2b, 0x00 },
1569 { 0x2c, 0x88 },
1570 { 0x2d, 0x91 },
1571 { 0x2e, 0x80 },
1572 { 0x2f, 0x44 },
1573 { 0x60, 0x27 },
1574 { 0x61, 0x02 },
1575 { 0x62, 0x5f },
1576 { 0x63, 0xd5 },
1577 { 0x64, 0x57 },
1578 { 0x65, 0x83 },
1579 { 0x66, 0x55 },
1580 { 0x67, 0x92 },
1581 { 0x68, 0xcf },
1582 { 0x69, 0x76 },
1583 { 0x6a, 0x22 },
1584 { 0x6b, 0x00 },
1585 { 0x6c, 0x02 },
1586 { 0x6d, 0x44 },
1587 { 0x6e, 0x80 },
1588 { 0x6f, 0x1d },
1589 { 0x70, 0x8b },
1590 { 0x71, 0x00 },
1591 { 0x72, 0x14 },
1592 { 0x73, 0x54 },
1593 { 0x74, 0x00 },
1594 { 0x75, 0x8e },
1595 { 0x76, 0x00 },
1596 { 0x77, 0xff },
1597 { 0x78, 0x80 },
1598 { 0x79, 0x80 },
1599 { 0x7a, 0x80 },
1600 { 0x7b, 0xe2 },
1601 { 0x7c, 0x00 },
1602};
1603
1604/* 7640 and 7648. The defaults should be OK for most registers. */
1605static const struct ov_i2c_regvals norm_7640[] = {
1606 { 0x12, 0x80 },
1607 { 0x12, 0x14 },
1608};
1609
Jean-François Moine42e142f2010-11-13 05:10:27 -03001610static const struct ov_regvals init_519_ov7660[] = {
1611 { 0x5d, 0x03 }, /* Turn off suspend mode */
1612 { 0x53, 0x9b }, /* 0x9f enables the (unused) microcontroller */
1613 { 0x54, 0x0f }, /* bit2 (jpeg enable) */
1614 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
1615 { 0xa3, 0x18 },
1616 { 0xa4, 0x04 },
1617 { 0xa5, 0x28 },
1618 { 0x37, 0x00 }, /* SetUsbInit */
1619 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
1620 /* Enable both fields, YUV Input, disable defect comp (why?) */
1621 { 0x20, 0x0c }, /* 0x0d does U <-> V swap */
1622 { 0x21, 0x38 },
1623 { 0x22, 0x1d },
1624 { 0x17, 0x50 }, /* undocumented */
1625 { 0x37, 0x00 }, /* undocumented */
1626 { 0x40, 0xff }, /* I2C timeout counter */
1627 { 0x46, 0x00 }, /* I2C clock prescaler */
1628};
1629static const struct ov_i2c_regvals norm_7660[] = {
1630 {OV7670_R12_COM7, OV7670_COM7_RESET},
1631 {OV7670_R11_CLKRC, 0x81},
1632 {0x92, 0x00}, /* DM_LNL */
1633 {0x93, 0x00}, /* DM_LNH */
1634 {0x9d, 0x4c}, /* BD50ST */
1635 {0x9e, 0x3f}, /* BD60ST */
1636 {OV7670_R3B_COM11, 0x02},
1637 {OV7670_R13_COM8, 0xf5},
1638 {OV7670_R10_AECH, 0x00},
1639 {OV7670_R00_GAIN, 0x00},
1640 {OV7670_R01_BLUE, 0x7c},
1641 {OV7670_R02_RED, 0x9d},
1642 {OV7670_R12_COM7, 0x00},
1643 {OV7670_R04_COM1, 00},
1644 {OV7670_R18_HSTOP, 0x01},
1645 {OV7670_R17_HSTART, 0x13},
1646 {OV7670_R32_HREF, 0x92},
1647 {OV7670_R19_VSTART, 0x02},
1648 {OV7670_R1A_VSTOP, 0x7a},
1649 {OV7670_R03_VREF, 0x00},
1650 {OV7670_R0E_COM5, 0x04},
1651 {OV7670_R0F_COM6, 0x62},
1652 {OV7670_R15_COM10, 0x00},
1653 {0x16, 0x02}, /* RSVD */
1654 {0x1b, 0x00}, /* PSHFT */
1655 {OV7670_R1E_MVFP, 0x01},
1656 {0x29, 0x3c}, /* RSVD */
1657 {0x33, 0x00}, /* CHLF */
1658 {0x34, 0x07}, /* ARBLM */
1659 {0x35, 0x84}, /* RSVD */
1660 {0x36, 0x00}, /* RSVD */
1661 {0x37, 0x04}, /* ADC */
1662 {0x39, 0x43}, /* OFON */
1663 {OV7670_R3A_TSLB, 0x00},
1664 {OV7670_R3C_COM12, 0x6c},
1665 {OV7670_R3D_COM13, 0x98},
1666 {OV7670_R3F_EDGE, 0x23},
1667 {OV7670_R40_COM15, 0xc1},
1668 {OV7670_R41_COM16, 0x22},
1669 {0x6b, 0x0a}, /* DBLV */
1670 {0xa1, 0x08}, /* RSVD */
1671 {0x69, 0x80}, /* HV */
1672 {0x43, 0xf0}, /* RSVD.. */
1673 {0x44, 0x10},
1674 {0x45, 0x78},
1675 {0x46, 0xa8},
1676 {0x47, 0x60},
1677 {0x48, 0x80},
1678 {0x59, 0xba},
1679 {0x5a, 0x9a},
1680 {0x5b, 0x22},
1681 {0x5c, 0xb9},
1682 {0x5d, 0x9b},
1683 {0x5e, 0x10},
1684 {0x5f, 0xe0},
1685 {0x60, 0x85},
1686 {0x61, 0x60},
1687 {0x9f, 0x9d}, /* RSVD */
1688 {0xa0, 0xa0}, /* DSPC2 */
1689 {0x4f, 0x60}, /* matrix */
1690 {0x50, 0x64},
1691 {0x51, 0x04},
1692 {0x52, 0x18},
1693 {0x53, 0x3c},
1694 {0x54, 0x54},
1695 {0x55, 0x40},
1696 {0x56, 0x40},
1697 {0x57, 0x40},
1698 {0x58, 0x0d}, /* matrix sign */
1699 {0x8b, 0xcc}, /* RSVD */
1700 {0x8c, 0xcc},
1701 {0x8d, 0xcf},
1702 {0x6c, 0x40}, /* gamma curve */
1703 {0x6d, 0xe0},
1704 {0x6e, 0xa0},
1705 {0x6f, 0x80},
1706 {0x70, 0x70},
1707 {0x71, 0x80},
1708 {0x72, 0x60},
1709 {0x73, 0x60},
1710 {0x74, 0x50},
1711 {0x75, 0x40},
1712 {0x76, 0x38},
1713 {0x77, 0x3c},
1714 {0x78, 0x32},
1715 {0x79, 0x1a},
1716 {0x7a, 0x28},
1717 {0x7b, 0x24},
1718 {0x7c, 0x04}, /* gamma curve */
1719 {0x7d, 0x12},
1720 {0x7e, 0x26},
1721 {0x7f, 0x46},
1722 {0x80, 0x54},
1723 {0x81, 0x64},
1724 {0x82, 0x70},
1725 {0x83, 0x7c},
1726 {0x84, 0x86},
1727 {0x85, 0x8e},
1728 {0x86, 0x9c},
1729 {0x87, 0xab},
1730 {0x88, 0xc4},
1731 {0x89, 0xd1},
1732 {0x8a, 0xe5},
1733 {OV7670_R14_COM9, 0x1e},
1734 {OV7670_R24_AEW, 0x80},
1735 {OV7670_R25_AEB, 0x72},
1736 {OV7670_R26_VPT, 0xb3},
1737 {0x62, 0x80}, /* LCC1 */
1738 {0x63, 0x80}, /* LCC2 */
1739 {0x64, 0x06}, /* LCC3 */
1740 {0x65, 0x00}, /* LCC4 */
1741 {0x66, 0x01}, /* LCC5 */
1742 {0x94, 0x0e}, /* RSVD.. */
1743 {0x95, 0x14},
1744 {OV7670_R13_COM8, OV7670_COM8_FASTAEC
1745 | OV7670_COM8_AECSTEP
1746 | OV7670_COM8_BFILT
1747 | 0x10
1748 | OV7670_COM8_AGC
1749 | OV7670_COM8_AWB
1750 | OV7670_COM8_AEC},
1751 {0xa1, 0xc8}
1752};
1753
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001754/* 7670. Defaults taken from OmniVision provided data,
1755* as provided by Jonathan Corbet of OLPC */
1756static const struct ov_i2c_regvals norm_7670[] = {
Jean-François Moine21867802010-11-12 06:12:09 -03001757 { OV7670_R12_COM7, OV7670_COM7_RESET },
1758 { OV7670_R3A_TSLB, 0x04 }, /* OV */
1759 { OV7670_R12_COM7, OV7670_COM7_FMT_VGA }, /* VGA */
1760 { OV7670_R11_CLKRC, 0x01 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001761/*
1762 * Set the hardware window. These values from OV don't entirely
1763 * make sense - hstop is less than hstart. But they work...
1764 */
Jean-François Moine21867802010-11-12 06:12:09 -03001765 { OV7670_R17_HSTART, 0x13 },
1766 { OV7670_R18_HSTOP, 0x01 },
1767 { OV7670_R32_HREF, 0xb6 },
1768 { OV7670_R19_VSTART, 0x02 },
1769 { OV7670_R1A_VSTOP, 0x7a },
1770 { OV7670_R03_VREF, 0x0a },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001771
Jean-François Moine21867802010-11-12 06:12:09 -03001772 { OV7670_R0C_COM3, 0x00 },
1773 { OV7670_R3E_COM14, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001774/* Mystery scaling numbers */
1775 { 0x70, 0x3a },
1776 { 0x71, 0x35 },
1777 { 0x72, 0x11 },
1778 { 0x73, 0xf0 },
1779 { 0xa2, 0x02 },
Jean-François Moine21867802010-11-12 06:12:09 -03001780/* { OV7670_R15_COM10, 0x0 }, */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001781
1782/* Gamma curve values */
1783 { 0x7a, 0x20 },
1784 { 0x7b, 0x10 },
1785 { 0x7c, 0x1e },
1786 { 0x7d, 0x35 },
1787 { 0x7e, 0x5a },
1788 { 0x7f, 0x69 },
1789 { 0x80, 0x76 },
1790 { 0x81, 0x80 },
1791 { 0x82, 0x88 },
1792 { 0x83, 0x8f },
1793 { 0x84, 0x96 },
1794 { 0x85, 0xa3 },
1795 { 0x86, 0xaf },
1796 { 0x87, 0xc4 },
1797 { 0x88, 0xd7 },
1798 { 0x89, 0xe8 },
1799
1800/* AGC and AEC parameters. Note we start by disabling those features,
1801 then turn them only after tweaking the values. */
Jean-François Moine21867802010-11-12 06:12:09 -03001802 { OV7670_R13_COM8, OV7670_COM8_FASTAEC
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001803 | OV7670_COM8_AECSTEP
1804 | OV7670_COM8_BFILT },
Jean-François Moine21867802010-11-12 06:12:09 -03001805 { OV7670_R00_GAIN, 0x00 },
1806 { OV7670_R10_AECH, 0x00 },
1807 { OV7670_R0D_COM4, 0x40 }, /* magic reserved bit */
1808 { OV7670_R14_COM9, 0x18 }, /* 4x gain + magic rsvd bit */
1809 { OV7670_RA5_BD50MAX, 0x05 },
1810 { OV7670_RAB_BD60MAX, 0x07 },
1811 { OV7670_R24_AEW, 0x95 },
1812 { OV7670_R25_AEB, 0x33 },
1813 { OV7670_R26_VPT, 0xe3 },
1814 { OV7670_R9F_HAECC1, 0x78 },
1815 { OV7670_RA0_HAECC2, 0x68 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001816 { 0xa1, 0x03 }, /* magic */
Jean-François Moine21867802010-11-12 06:12:09 -03001817 { OV7670_RA6_HAECC3, 0xd8 },
1818 { OV7670_RA7_HAECC4, 0xd8 },
1819 { OV7670_RA8_HAECC5, 0xf0 },
1820 { OV7670_RA9_HAECC6, 0x90 },
1821 { OV7670_RAA_HAECC7, 0x94 },
1822 { OV7670_R13_COM8, OV7670_COM8_FASTAEC
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001823 | OV7670_COM8_AECSTEP
1824 | OV7670_COM8_BFILT
1825 | OV7670_COM8_AGC
1826 | OV7670_COM8_AEC },
1827
1828/* Almost all of these are magic "reserved" values. */
Jean-François Moine21867802010-11-12 06:12:09 -03001829 { OV7670_R0E_COM5, 0x61 },
1830 { OV7670_R0F_COM6, 0x4b },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001831 { 0x16, 0x02 },
Jean-François Moine21867802010-11-12 06:12:09 -03001832 { OV7670_R1E_MVFP, 0x07 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001833 { 0x21, 0x02 },
1834 { 0x22, 0x91 },
1835 { 0x29, 0x07 },
1836 { 0x33, 0x0b },
1837 { 0x35, 0x0b },
1838 { 0x37, 0x1d },
1839 { 0x38, 0x71 },
1840 { 0x39, 0x2a },
Jean-François Moine21867802010-11-12 06:12:09 -03001841 { OV7670_R3C_COM12, 0x78 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001842 { 0x4d, 0x40 },
1843 { 0x4e, 0x20 },
Jean-François Moine21867802010-11-12 06:12:09 -03001844 { OV7670_R69_GFIX, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001845 { 0x6b, 0x4a },
1846 { 0x74, 0x10 },
1847 { 0x8d, 0x4f },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001848 { 0x8e, 0x00 },
1849 { 0x8f, 0x00 },
1850 { 0x90, 0x00 },
1851 { 0x91, 0x00 },
1852 { 0x96, 0x00 },
1853 { 0x9a, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001854 { 0xb0, 0x84 },
1855 { 0xb1, 0x0c },
1856 { 0xb2, 0x0e },
1857 { 0xb3, 0x82 },
1858 { 0xb8, 0x0a },
1859
1860/* More reserved magic, some of which tweaks white balance */
1861 { 0x43, 0x0a },
1862 { 0x44, 0xf0 },
1863 { 0x45, 0x34 },
1864 { 0x46, 0x58 },
1865 { 0x47, 0x28 },
1866 { 0x48, 0x3a },
1867 { 0x59, 0x88 },
1868 { 0x5a, 0x88 },
1869 { 0x5b, 0x44 },
1870 { 0x5c, 0x67 },
1871 { 0x5d, 0x49 },
1872 { 0x5e, 0x0e },
1873 { 0x6c, 0x0a },
1874 { 0x6d, 0x55 },
1875 { 0x6e, 0x11 },
Jean-François Moinefc63de882011-01-13 05:35:18 -03001876 { 0x6f, 0x9f }, /* "9e for advance AWB" */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001877 { 0x6a, 0x40 },
Jean-François Moine21867802010-11-12 06:12:09 -03001878 { OV7670_R01_BLUE, 0x40 },
1879 { OV7670_R02_RED, 0x60 },
1880 { OV7670_R13_COM8, OV7670_COM8_FASTAEC
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001881 | OV7670_COM8_AECSTEP
1882 | OV7670_COM8_BFILT
1883 | OV7670_COM8_AGC
1884 | OV7670_COM8_AEC
1885 | OV7670_COM8_AWB },
1886
1887/* Matrix coefficients */
1888 { 0x4f, 0x80 },
1889 { 0x50, 0x80 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001890 { 0x51, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001891 { 0x52, 0x22 },
1892 { 0x53, 0x5e },
1893 { 0x54, 0x80 },
1894 { 0x58, 0x9e },
1895
Jean-François Moine21867802010-11-12 06:12:09 -03001896 { OV7670_R41_COM16, OV7670_COM16_AWBGAIN },
1897 { OV7670_R3F_EDGE, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001898 { 0x75, 0x05 },
1899 { 0x76, 0xe1 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001900 { 0x4c, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001901 { 0x77, 0x01 },
Jean-François Moine21867802010-11-12 06:12:09 -03001902 { OV7670_R3D_COM13, OV7670_COM13_GAMMA
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001903 | OV7670_COM13_UVSAT
1904 | 2}, /* was 3 */
1905 { 0x4b, 0x09 },
1906 { 0xc9, 0x60 },
Jean-François Moine21867802010-11-12 06:12:09 -03001907 { OV7670_R41_COM16, 0x38 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001908 { 0x56, 0x40 },
1909
1910 { 0x34, 0x11 },
Jean-François Moine21867802010-11-12 06:12:09 -03001911 { OV7670_R3B_COM11, OV7670_COM11_EXP|OV7670_COM11_HZAUTO },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001912 { 0xa4, 0x88 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001913 { 0x96, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001914 { 0x97, 0x30 },
1915 { 0x98, 0x20 },
1916 { 0x99, 0x30 },
1917 { 0x9a, 0x84 },
1918 { 0x9b, 0x29 },
1919 { 0x9c, 0x03 },
1920 { 0x9d, 0x4c },
1921 { 0x9e, 0x3f },
1922 { 0x78, 0x04 },
1923
1924/* Extra-weird stuff. Some sort of multiplexor register */
1925 { 0x79, 0x01 },
1926 { 0xc8, 0xf0 },
1927 { 0x79, 0x0f },
1928 { 0xc8, 0x00 },
1929 { 0x79, 0x10 },
1930 { 0xc8, 0x7e },
1931 { 0x79, 0x0a },
1932 { 0xc8, 0x80 },
1933 { 0x79, 0x0b },
1934 { 0xc8, 0x01 },
1935 { 0x79, 0x0c },
1936 { 0xc8, 0x0f },
1937 { 0x79, 0x0d },
1938 { 0xc8, 0x20 },
1939 { 0x79, 0x09 },
1940 { 0xc8, 0x80 },
1941 { 0x79, 0x02 },
1942 { 0xc8, 0xc0 },
1943 { 0x79, 0x03 },
1944 { 0xc8, 0x40 },
1945 { 0x79, 0x05 },
1946 { 0xc8, 0x30 },
1947 { 0x79, 0x26 },
1948};
1949
1950static const struct ov_i2c_regvals norm_8610[] = {
1951 { 0x12, 0x80 },
1952 { 0x00, 0x00 },
1953 { 0x01, 0x80 },
1954 { 0x02, 0x80 },
1955 { 0x03, 0xc0 },
1956 { 0x04, 0x30 },
1957 { 0x05, 0x30 }, /* was 0x10, new from windrv 090403 */
1958 { 0x06, 0x70 }, /* was 0x80, new from windrv 090403 */
1959 { 0x0a, 0x86 },
1960 { 0x0b, 0xb0 },
1961 { 0x0c, 0x20 },
1962 { 0x0d, 0x20 },
1963 { 0x11, 0x01 },
1964 { 0x12, 0x25 },
1965 { 0x13, 0x01 },
1966 { 0x14, 0x04 },
1967 { 0x15, 0x01 }, /* Lin and Win think different about UV order */
1968 { 0x16, 0x03 },
1969 { 0x17, 0x38 }, /* was 0x2f, new from windrv 090403 */
1970 { 0x18, 0xea }, /* was 0xcf, new from windrv 090403 */
1971 { 0x19, 0x02 }, /* was 0x06, new from windrv 090403 */
1972 { 0x1a, 0xf5 },
1973 { 0x1b, 0x00 },
1974 { 0x20, 0xd0 }, /* was 0x90, new from windrv 090403 */
1975 { 0x23, 0xc0 }, /* was 0x00, new from windrv 090403 */
1976 { 0x24, 0x30 }, /* was 0x1d, new from windrv 090403 */
1977 { 0x25, 0x50 }, /* was 0x57, new from windrv 090403 */
1978 { 0x26, 0xa2 },
1979 { 0x27, 0xea },
1980 { 0x28, 0x00 },
1981 { 0x29, 0x00 },
1982 { 0x2a, 0x80 },
1983 { 0x2b, 0xc8 }, /* was 0xcc, new from windrv 090403 */
1984 { 0x2c, 0xac },
1985 { 0x2d, 0x45 }, /* was 0xd5, new from windrv 090403 */
1986 { 0x2e, 0x80 },
1987 { 0x2f, 0x14 }, /* was 0x01, new from windrv 090403 */
1988 { 0x4c, 0x00 },
1989 { 0x4d, 0x30 }, /* was 0x10, new from windrv 090403 */
1990 { 0x60, 0x02 }, /* was 0x01, new from windrv 090403 */
1991 { 0x61, 0x00 }, /* was 0x09, new from windrv 090403 */
1992 { 0x62, 0x5f }, /* was 0xd7, new from windrv 090403 */
1993 { 0x63, 0xff },
1994 { 0x64, 0x53 }, /* new windrv 090403 says 0x57,
1995 * maybe thats wrong */
1996 { 0x65, 0x00 },
1997 { 0x66, 0x55 },
1998 { 0x67, 0xb0 },
1999 { 0x68, 0xc0 }, /* was 0xaf, new from windrv 090403 */
2000 { 0x69, 0x02 },
2001 { 0x6a, 0x22 },
2002 { 0x6b, 0x00 },
2003 { 0x6c, 0x99 }, /* was 0x80, old windrv says 0x00, but
2004 * deleting bit7 colors the first images red */
2005 { 0x6d, 0x11 }, /* was 0x00, new from windrv 090403 */
2006 { 0x6e, 0x11 }, /* was 0x00, new from windrv 090403 */
2007 { 0x6f, 0x01 },
2008 { 0x70, 0x8b },
2009 { 0x71, 0x00 },
2010 { 0x72, 0x14 },
2011 { 0x73, 0x54 },
2012 { 0x74, 0x00 },/* 0x60? - was 0x00, new from windrv 090403 */
2013 { 0x75, 0x0e },
2014 { 0x76, 0x02 }, /* was 0x02, new from windrv 090403 */
2015 { 0x77, 0xff },
2016 { 0x78, 0x80 },
2017 { 0x79, 0x80 },
2018 { 0x7a, 0x80 },
2019 { 0x7b, 0x10 }, /* was 0x13, new from windrv 090403 */
2020 { 0x7c, 0x00 },
2021 { 0x7d, 0x08 }, /* was 0x09, new from windrv 090403 */
2022 { 0x7e, 0x08 }, /* was 0xc0, new from windrv 090403 */
2023 { 0x7f, 0xfb },
2024 { 0x80, 0x28 },
2025 { 0x81, 0x00 },
2026 { 0x82, 0x23 },
2027 { 0x83, 0x0b },
2028 { 0x84, 0x00 },
2029 { 0x85, 0x62 }, /* was 0x61, new from windrv 090403 */
2030 { 0x86, 0xc9 },
2031 { 0x87, 0x00 },
2032 { 0x88, 0x00 },
2033 { 0x89, 0x01 },
2034 { 0x12, 0x20 },
2035 { 0x12, 0x25 }, /* was 0x24, new from windrv 090403 */
2036};
2037
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002038static unsigned char ov7670_abs_to_sm(unsigned char v)
2039{
2040 if (v > 127)
2041 return v & 0x7f;
2042 return (128 - v) | 0x80;
2043}
2044
2045/* Write a OV519 register */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002046static void reg_w(struct sd *sd, u16 index, u16 value)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002047{
Hans de Goedea511ba92009-10-16 07:13:07 -03002048 int ret, req = 0;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002049
Jean-François Moinef8f20182010-11-12 07:54:02 -03002050 if (sd->gspca_dev.usb_err < 0)
2051 return;
2052
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002053 switch (sd->bridge) {
2054 case BRIDGE_OV511:
2055 case BRIDGE_OV511PLUS:
2056 req = 2;
2057 break;
2058 case BRIDGE_OVFX2:
Hans de Goedea511ba92009-10-16 07:13:07 -03002059 req = 0x0a;
2060 /* fall through */
2061 case BRIDGE_W9968CF:
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002062 PDEBUG(D_USBO, "SET %02x %04x %04x",
2063 req, value, index);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002064 ret = usb_control_msg(sd->gspca_dev.dev,
2065 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
Hans de Goedea511ba92009-10-16 07:13:07 -03002066 req,
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002067 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Hans de Goedea511ba92009-10-16 07:13:07 -03002068 value, index, NULL, 0, 500);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002069 goto leave;
2070 default:
2071 req = 1;
2072 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002073
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002074 PDEBUG(D_USBO, "SET %02x 0000 %04x %02x",
2075 req, index, value);
Jean-Francois Moine739570b2008-07-14 09:38:29 -03002076 sd->gspca_dev.usb_buf[0] = value;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002077 ret = usb_control_msg(sd->gspca_dev.dev,
2078 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
Hans de Goede49809d62009-06-07 12:10:39 -03002079 req,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002080 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2081 0, index,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03002082 sd->gspca_dev.usb_buf, 1, 500);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002083leave:
Hans de Goedea511ba92009-10-16 07:13:07 -03002084 if (ret < 0) {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002085 err("reg_w %02x failed %d", index, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002086 sd->gspca_dev.usb_err = ret;
2087 return;
Hans de Goedea511ba92009-10-16 07:13:07 -03002088 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002089}
2090
Hans de Goedea511ba92009-10-16 07:13:07 -03002091/* Read from a OV519 register, note not valid for the w9968cf!! */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002092/* returns: negative is error, pos or zero is data */
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002093static int reg_r(struct sd *sd, u16 index)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002094{
2095 int ret;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002096 int req;
2097
Jean-François Moinef8f20182010-11-12 07:54:02 -03002098 if (sd->gspca_dev.usb_err < 0)
2099 return -1;
2100
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002101 switch (sd->bridge) {
2102 case BRIDGE_OV511:
2103 case BRIDGE_OV511PLUS:
2104 req = 3;
2105 break;
2106 case BRIDGE_OVFX2:
2107 req = 0x0b;
2108 break;
2109 default:
2110 req = 1;
2111 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002112
2113 ret = usb_control_msg(sd->gspca_dev.dev,
2114 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
Hans de Goede49809d62009-06-07 12:10:39 -03002115 req,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002116 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03002117 0, index, sd->gspca_dev.usb_buf, 1, 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002118
Hans de Goedea511ba92009-10-16 07:13:07 -03002119 if (ret >= 0) {
Jean-Francois Moine739570b2008-07-14 09:38:29 -03002120 ret = sd->gspca_dev.usb_buf[0];
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002121 PDEBUG(D_USBI, "GET %02x 0000 %04x %02x",
2122 req, index, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002123 } else {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002124 err("reg_r %02x failed %d", index, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002125 sd->gspca_dev.usb_err = ret;
2126 }
Hans de Goedea511ba92009-10-16 07:13:07 -03002127
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002128 return ret;
2129}
2130
2131/* Read 8 values from a OV519 register */
2132static int reg_r8(struct sd *sd,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002133 u16 index)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002134{
2135 int ret;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002136
Jean-François Moinef8f20182010-11-12 07:54:02 -03002137 if (sd->gspca_dev.usb_err < 0)
2138 return -1;
2139
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002140 ret = usb_control_msg(sd->gspca_dev.dev,
2141 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
2142 1, /* REQ_IO */
2143 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03002144 0, index, sd->gspca_dev.usb_buf, 8, 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002145
Jean-François Moinef8f20182010-11-12 07:54:02 -03002146 if (ret >= 0) {
Jean-Francois Moine739570b2008-07-14 09:38:29 -03002147 ret = sd->gspca_dev.usb_buf[0];
Jean-François Moinef8f20182010-11-12 07:54:02 -03002148 } else {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002149 err("reg_r8 %02x failed %d", index, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002150 sd->gspca_dev.usb_err = ret;
2151 }
Hans de Goedea511ba92009-10-16 07:13:07 -03002152
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002153 return ret;
2154}
2155
2156/*
2157 * Writes bits at positions specified by mask to an OV51x reg. Bits that are in
2158 * the same position as 1's in "mask" are cleared and set to "value". Bits
2159 * that are in the same position as 0's in "mask" are preserved, regardless
2160 * of their respective state in "value".
2161 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002162static void reg_w_mask(struct sd *sd,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002163 u16 index,
2164 u8 value,
2165 u8 mask)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002166{
2167 int ret;
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002168 u8 oldval;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002169
2170 if (mask != 0xff) {
2171 value &= mask; /* Enforce mask on value */
2172 ret = reg_r(sd, index);
2173 if (ret < 0)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002174 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002175
2176 oldval = ret & ~mask; /* Clear the masked bits */
2177 value |= oldval; /* Set the desired bits */
2178 }
Jean-François Moinef8f20182010-11-12 07:54:02 -03002179 reg_w(sd, index, value);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002180}
2181
2182/*
Hans de Goede49809d62009-06-07 12:10:39 -03002183 * Writes multiple (n) byte value to a single register. Only valid with certain
2184 * registers (0x30 and 0xc4 - 0xce).
2185 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002186static void ov518_reg_w32(struct sd *sd, u16 index, u32 value, int n)
Hans de Goede49809d62009-06-07 12:10:39 -03002187{
2188 int ret;
2189
Jean-François Moinef8f20182010-11-12 07:54:02 -03002190 if (sd->gspca_dev.usb_err < 0)
2191 return;
2192
Jean-Francois Moine83955552009-12-12 06:58:01 -03002193 *((__le32 *) sd->gspca_dev.usb_buf) = __cpu_to_le32(value);
Hans de Goede49809d62009-06-07 12:10:39 -03002194
2195 ret = usb_control_msg(sd->gspca_dev.dev,
2196 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
2197 1 /* REG_IO */,
2198 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2199 0, index,
2200 sd->gspca_dev.usb_buf, n, 500);
Hans de Goedea511ba92009-10-16 07:13:07 -03002201 if (ret < 0) {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002202 err("reg_w32 %02x failed %d", index, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002203 sd->gspca_dev.usb_err = ret;
Hans de Goedea511ba92009-10-16 07:13:07 -03002204 }
Hans de Goede49809d62009-06-07 12:10:39 -03002205}
2206
Jean-François Moinef8f20182010-11-12 07:54:02 -03002207static void ov511_i2c_w(struct sd *sd, u8 reg, u8 value)
Hans de Goede1876bb92009-06-14 06:45:50 -03002208{
2209 int rc, retries;
2210
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002211 PDEBUG(D_USBO, "ov511_i2c_w %02x %02x", reg, value);
Hans de Goede1876bb92009-06-14 06:45:50 -03002212
2213 /* Three byte write cycle */
2214 for (retries = 6; ; ) {
2215 /* Select camera register */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002216 reg_w(sd, R51x_I2C_SADDR_3, reg);
Hans de Goede1876bb92009-06-14 06:45:50 -03002217
2218 /* Write "value" to I2C data port of OV511 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002219 reg_w(sd, R51x_I2C_DATA, value);
Hans de Goede1876bb92009-06-14 06:45:50 -03002220
2221 /* Initiate 3-byte write cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002222 reg_w(sd, R511_I2C_CTL, 0x01);
Hans de Goede1876bb92009-06-14 06:45:50 -03002223
Jean-Francois Moine83955552009-12-12 06:58:01 -03002224 do {
Hans de Goede1876bb92009-06-14 06:45:50 -03002225 rc = reg_r(sd, R511_I2C_CTL);
Jean-Francois Moine83955552009-12-12 06:58:01 -03002226 } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
Hans de Goede1876bb92009-06-14 06:45:50 -03002227
2228 if (rc < 0)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002229 return;
Hans de Goede1876bb92009-06-14 06:45:50 -03002230
2231 if ((rc & 2) == 0) /* Ack? */
2232 break;
2233 if (--retries < 0) {
2234 PDEBUG(D_USBO, "i2c write retries exhausted");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002235 return;
Hans de Goede1876bb92009-06-14 06:45:50 -03002236 }
2237 }
Hans de Goede1876bb92009-06-14 06:45:50 -03002238}
2239
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002240static int ov511_i2c_r(struct sd *sd, u8 reg)
Hans de Goede1876bb92009-06-14 06:45:50 -03002241{
2242 int rc, value, retries;
2243
2244 /* Two byte write cycle */
2245 for (retries = 6; ; ) {
2246 /* Select camera register */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002247 reg_w(sd, R51x_I2C_SADDR_2, reg);
Hans de Goede1876bb92009-06-14 06:45:50 -03002248
2249 /* Initiate 2-byte write cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002250 reg_w(sd, R511_I2C_CTL, 0x03);
Hans de Goede1876bb92009-06-14 06:45:50 -03002251
Jean-Francois Moine83955552009-12-12 06:58:01 -03002252 do {
Hans de Goede1876bb92009-06-14 06:45:50 -03002253 rc = reg_r(sd, R511_I2C_CTL);
Jean-Francois Moine83955552009-12-12 06:58:01 -03002254 } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
Hans de Goede1876bb92009-06-14 06:45:50 -03002255
2256 if (rc < 0)
2257 return rc;
2258
2259 if ((rc & 2) == 0) /* Ack? */
2260 break;
2261
2262 /* I2C abort */
2263 reg_w(sd, R511_I2C_CTL, 0x10);
2264
2265 if (--retries < 0) {
2266 PDEBUG(D_USBI, "i2c write retries exhausted");
2267 return -1;
2268 }
2269 }
2270
2271 /* Two byte read cycle */
2272 for (retries = 6; ; ) {
2273 /* Initiate 2-byte read cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002274 reg_w(sd, R511_I2C_CTL, 0x05);
Hans de Goede1876bb92009-06-14 06:45:50 -03002275
Jean-Francois Moine83955552009-12-12 06:58:01 -03002276 do {
Hans de Goede1876bb92009-06-14 06:45:50 -03002277 rc = reg_r(sd, R511_I2C_CTL);
Jean-Francois Moine83955552009-12-12 06:58:01 -03002278 } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
Hans de Goede1876bb92009-06-14 06:45:50 -03002279
2280 if (rc < 0)
2281 return rc;
2282
2283 if ((rc & 2) == 0) /* Ack? */
2284 break;
2285
2286 /* I2C abort */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002287 reg_w(sd, R511_I2C_CTL, 0x10);
Hans de Goede1876bb92009-06-14 06:45:50 -03002288
2289 if (--retries < 0) {
2290 PDEBUG(D_USBI, "i2c read retries exhausted");
2291 return -1;
2292 }
2293 }
2294
2295 value = reg_r(sd, R51x_I2C_DATA);
2296
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002297 PDEBUG(D_USBI, "ov511_i2c_r %02x %02x", reg, value);
Hans de Goede1876bb92009-06-14 06:45:50 -03002298
2299 /* This is needed to make i2c_w() work */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002300 reg_w(sd, R511_I2C_CTL, 0x05);
Hans de Goede1876bb92009-06-14 06:45:50 -03002301
2302 return value;
2303}
Hans de Goede49809d62009-06-07 12:10:39 -03002304
2305/*
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002306 * The OV518 I2C I/O procedure is different, hence, this function.
2307 * This is normally only called from i2c_w(). Note that this function
2308 * always succeeds regardless of whether the sensor is present and working.
2309 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002310static void ov518_i2c_w(struct sd *sd,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002311 u8 reg,
2312 u8 value)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002313{
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002314 PDEBUG(D_USBO, "ov518_i2c_w %02x %02x", reg, value);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002315
2316 /* Select camera register */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002317 reg_w(sd, R51x_I2C_SADDR_3, reg);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002318
2319 /* Write "value" to I2C data port of OV511 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002320 reg_w(sd, R51x_I2C_DATA, value);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002321
2322 /* Initiate 3-byte write cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002323 reg_w(sd, R518_I2C_CTL, 0x01);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002324
2325 /* wait for write complete */
2326 msleep(4);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002327 reg_r8(sd, R518_I2C_CTL);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002328}
2329
2330/*
2331 * returns: negative is error, pos or zero is data
2332 *
2333 * The OV518 I2C I/O procedure is different, hence, this function.
2334 * This is normally only called from i2c_r(). Note that this function
2335 * always succeeds regardless of whether the sensor is present and working.
2336 */
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002337static int ov518_i2c_r(struct sd *sd, u8 reg)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002338{
Jean-François Moinef8f20182010-11-12 07:54:02 -03002339 int value;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002340
2341 /* Select camera register */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002342 reg_w(sd, R51x_I2C_SADDR_2, reg);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002343
2344 /* Initiate 2-byte write cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002345 reg_w(sd, R518_I2C_CTL, 0x03);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002346
2347 /* Initiate 2-byte read cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002348 reg_w(sd, R518_I2C_CTL, 0x05);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002349 value = reg_r(sd, R51x_I2C_DATA);
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002350 PDEBUG(D_USBI, "ov518_i2c_r %02x %02x", reg, value);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002351 return value;
2352}
2353
Jean-François Moinef8f20182010-11-12 07:54:02 -03002354static void ovfx2_i2c_w(struct sd *sd, u8 reg, u8 value)
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002355{
2356 int ret;
2357
Jean-François Moinef8f20182010-11-12 07:54:02 -03002358 if (sd->gspca_dev.usb_err < 0)
2359 return;
2360
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002361 ret = usb_control_msg(sd->gspca_dev.dev,
2362 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
2363 0x02,
2364 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002365 (u16) value, (u16) reg, NULL, 0, 500);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002366
Hans de Goedea511ba92009-10-16 07:13:07 -03002367 if (ret < 0) {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002368 err("ovfx2_i2c_w %02x failed %d", reg, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002369 sd->gspca_dev.usb_err = ret;
Hans de Goedea511ba92009-10-16 07:13:07 -03002370 }
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002371
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002372 PDEBUG(D_USBO, "ovfx2_i2c_w %02x %02x", reg, value);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002373}
2374
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002375static int ovfx2_i2c_r(struct sd *sd, u8 reg)
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002376{
2377 int ret;
2378
Jean-François Moinef8f20182010-11-12 07:54:02 -03002379 if (sd->gspca_dev.usb_err < 0)
2380 return -1;
2381
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002382 ret = usb_control_msg(sd->gspca_dev.dev,
2383 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
2384 0x03,
2385 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002386 0, (u16) reg, sd->gspca_dev.usb_buf, 1, 500);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002387
2388 if (ret >= 0) {
2389 ret = sd->gspca_dev.usb_buf[0];
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002390 PDEBUG(D_USBI, "ovfx2_i2c_r %02x %02x", reg, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002391 } else {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002392 err("ovfx2_i2c_r %02x failed %d", reg, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002393 sd->gspca_dev.usb_err = ret;
2394 }
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002395
2396 return ret;
2397}
2398
Jean-François Moinef8f20182010-11-12 07:54:02 -03002399static void i2c_w(struct sd *sd, u8 reg, u8 value)
Hans de Goede1876bb92009-06-14 06:45:50 -03002400{
Hans de Goedefb1f9022009-10-16 07:42:53 -03002401 if (sd->sensor_reg_cache[reg] == value)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002402 return;
Hans de Goedefb1f9022009-10-16 07:42:53 -03002403
Hans de Goede1876bb92009-06-14 06:45:50 -03002404 switch (sd->bridge) {
2405 case BRIDGE_OV511:
2406 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002407 ov511_i2c_w(sd, reg, value);
Hans de Goedefb1f9022009-10-16 07:42:53 -03002408 break;
Hans de Goede1876bb92009-06-14 06:45:50 -03002409 case BRIDGE_OV518:
2410 case BRIDGE_OV518PLUS:
2411 case BRIDGE_OV519:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002412 ov518_i2c_w(sd, reg, value);
Hans de Goedefb1f9022009-10-16 07:42:53 -03002413 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002414 case BRIDGE_OVFX2:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002415 ovfx2_i2c_w(sd, reg, value);
Hans de Goedefb1f9022009-10-16 07:42:53 -03002416 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03002417 case BRIDGE_W9968CF:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002418 w9968cf_i2c_w(sd, reg, value);
Hans de Goedefb1f9022009-10-16 07:42:53 -03002419 break;
Hans de Goede1876bb92009-06-14 06:45:50 -03002420 }
Hans de Goedefb1f9022009-10-16 07:42:53 -03002421
Jean-François Moinef8f20182010-11-12 07:54:02 -03002422 if (sd->gspca_dev.usb_err >= 0) {
Hans de Goedefb1f9022009-10-16 07:42:53 -03002423 /* Up on sensor reset empty the register cache */
2424 if (reg == 0x12 && (value & 0x80))
2425 memset(sd->sensor_reg_cache, -1,
Jean-François Moine87bae742010-11-12 05:31:34 -03002426 sizeof(sd->sensor_reg_cache));
Hans de Goedefb1f9022009-10-16 07:42:53 -03002427 else
2428 sd->sensor_reg_cache[reg] = value;
2429 }
Hans de Goede1876bb92009-06-14 06:45:50 -03002430}
2431
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002432static int i2c_r(struct sd *sd, u8 reg)
Hans de Goede1876bb92009-06-14 06:45:50 -03002433{
Hans de Goede8394bcf2009-10-16 11:26:22 -03002434 int ret = -1;
Hans de Goedefb1f9022009-10-16 07:42:53 -03002435
2436 if (sd->sensor_reg_cache[reg] != -1)
2437 return sd->sensor_reg_cache[reg];
2438
Hans de Goede1876bb92009-06-14 06:45:50 -03002439 switch (sd->bridge) {
2440 case BRIDGE_OV511:
2441 case BRIDGE_OV511PLUS:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002442 ret = ov511_i2c_r(sd, reg);
2443 break;
Hans de Goede1876bb92009-06-14 06:45:50 -03002444 case BRIDGE_OV518:
2445 case BRIDGE_OV518PLUS:
2446 case BRIDGE_OV519:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002447 ret = ov518_i2c_r(sd, reg);
2448 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002449 case BRIDGE_OVFX2:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002450 ret = ovfx2_i2c_r(sd, reg);
2451 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03002452 case BRIDGE_W9968CF:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002453 ret = w9968cf_i2c_r(sd, reg);
2454 break;
Hans de Goede1876bb92009-06-14 06:45:50 -03002455 }
Hans de Goedefb1f9022009-10-16 07:42:53 -03002456
2457 if (ret >= 0)
2458 sd->sensor_reg_cache[reg] = ret;
2459
2460 return ret;
Hans de Goede1876bb92009-06-14 06:45:50 -03002461}
2462
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002463/* Writes bits at positions specified by mask to an I2C reg. Bits that are in
2464 * the same position as 1's in "mask" are cleared and set to "value". Bits
2465 * that are in the same position as 0's in "mask" are preserved, regardless
2466 * of their respective state in "value".
2467 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002468static void i2c_w_mask(struct sd *sd,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002469 u8 reg,
2470 u8 value,
2471 u8 mask)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002472{
2473 int rc;
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002474 u8 oldval;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002475
2476 value &= mask; /* Enforce mask on value */
2477 rc = i2c_r(sd, reg);
2478 if (rc < 0)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002479 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002480 oldval = rc & ~mask; /* Clear the masked bits */
2481 value |= oldval; /* Set the desired bits */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002482 i2c_w(sd, reg, value);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002483}
2484
2485/* Temporarily stops OV511 from functioning. Must do this before changing
2486 * registers while the camera is streaming */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002487static inline void ov51x_stop(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002488{
2489 PDEBUG(D_STREAM, "stopping");
2490 sd->stopped = 1;
Hans de Goede49809d62009-06-07 12:10:39 -03002491 switch (sd->bridge) {
2492 case BRIDGE_OV511:
2493 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002494 reg_w(sd, R51x_SYS_RESET, 0x3d);
2495 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002496 case BRIDGE_OV518:
2497 case BRIDGE_OV518PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002498 reg_w_mask(sd, R51x_SYS_RESET, 0x3a, 0x3a);
2499 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002500 case BRIDGE_OV519:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002501 reg_w(sd, OV519_R51_RESET1, 0x0f);
Jean-François Moine5927abc2010-11-12 15:32:29 -03002502 reg_w(sd, OV519_R51_RESET1, 0x00);
2503 reg_w(sd, 0x22, 0x00); /* FRAR */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002504 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002505 case BRIDGE_OVFX2:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002506 reg_w_mask(sd, 0x0f, 0x00, 0x02);
2507 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03002508 case BRIDGE_W9968CF:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002509 reg_w(sd, 0x3c, 0x0a05); /* stop USB transfer */
2510 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002511 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002512}
2513
2514/* Restarts OV511 after ov511_stop() is called. Has no effect if it is not
2515 * actually stopped (for performance). */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002516static inline void ov51x_restart(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002517{
2518 PDEBUG(D_STREAM, "restarting");
2519 if (!sd->stopped)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002520 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002521 sd->stopped = 0;
2522
2523 /* Reinitialize the stream */
Hans de Goede49809d62009-06-07 12:10:39 -03002524 switch (sd->bridge) {
2525 case BRIDGE_OV511:
2526 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002527 reg_w(sd, R51x_SYS_RESET, 0x00);
2528 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002529 case BRIDGE_OV518:
2530 case BRIDGE_OV518PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002531 reg_w(sd, 0x2f, 0x80);
2532 reg_w(sd, R51x_SYS_RESET, 0x00);
2533 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002534 case BRIDGE_OV519:
Jean-François Moine5927abc2010-11-12 15:32:29 -03002535 reg_w(sd, OV519_R51_RESET1, 0x0f);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002536 reg_w(sd, OV519_R51_RESET1, 0x00);
Jean-François Moine5927abc2010-11-12 15:32:29 -03002537 reg_w(sd, 0x22, 0x1d); /* FRAR */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002538 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002539 case BRIDGE_OVFX2:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002540 reg_w_mask(sd, 0x0f, 0x02, 0x02);
2541 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03002542 case BRIDGE_W9968CF:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002543 reg_w(sd, 0x3c, 0x8a05); /* USB FIFO enable */
2544 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002545 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002546}
2547
Jean-François Moinef8f20182010-11-12 07:54:02 -03002548static void ov51x_set_slave_ids(struct sd *sd, u8 slave);
Hans de Goede229bb7d2009-10-11 07:41:46 -03002549
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002550/* This does an initial reset of an OmniVision sensor and ensures that I2C
2551 * is synchronized. Returns <0 on failure.
2552 */
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002553static int init_ov_sensor(struct sd *sd, u8 slave)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002554{
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002555 int i;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002556
Jean-François Moinef8f20182010-11-12 07:54:02 -03002557 ov51x_set_slave_ids(sd, slave);
Hans de Goede229bb7d2009-10-11 07:41:46 -03002558
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002559 /* Reset the sensor */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002560 i2c_w(sd, 0x12, 0x80);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002561
2562 /* Wait for it to initialize */
2563 msleep(150);
2564
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002565 for (i = 0; i < i2c_detect_tries; i++) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002566 if (i2c_r(sd, OV7610_REG_ID_HIGH) == 0x7f &&
2567 i2c_r(sd, OV7610_REG_ID_LOW) == 0xa2) {
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002568 PDEBUG(D_PROBE, "I2C synced in %d attempt(s)", i);
2569 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002570 }
2571
2572 /* Reset the sensor */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002573 i2c_w(sd, 0x12, 0x80);
2574
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002575 /* Wait for it to initialize */
2576 msleep(150);
Jean-François Moine87bae742010-11-12 05:31:34 -03002577
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002578 /* Dummy read to sync I2C */
2579 if (i2c_r(sd, 0x00) < 0)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002580 return -1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002581 }
Jean-François Moinef8f20182010-11-12 07:54:02 -03002582 return -1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002583}
2584
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002585/* Set the read and write slave IDs. The "slave" argument is the write slave,
2586 * and the read slave will be set to (slave + 1).
2587 * This should not be called from outside the i2c I/O functions.
2588 * Sets I2C read and write slave IDs. Returns <0 for error
2589 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002590static void ov51x_set_slave_ids(struct sd *sd,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002591 u8 slave)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002592{
Hans de Goedea511ba92009-10-16 07:13:07 -03002593 switch (sd->bridge) {
2594 case BRIDGE_OVFX2:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002595 reg_w(sd, OVFX2_I2C_ADDR, slave);
2596 return;
Hans de Goedea511ba92009-10-16 07:13:07 -03002597 case BRIDGE_W9968CF:
2598 sd->sensor_addr = slave;
Jean-François Moinef8f20182010-11-12 07:54:02 -03002599 return;
Hans de Goedea511ba92009-10-16 07:13:07 -03002600 }
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002601
Jean-François Moinef8f20182010-11-12 07:54:02 -03002602 reg_w(sd, R51x_I2C_W_SID, slave);
2603 reg_w(sd, R51x_I2C_R_SID, slave + 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002604}
2605
Jean-François Moinef8f20182010-11-12 07:54:02 -03002606static void write_regvals(struct sd *sd,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002607 const struct ov_regvals *regvals,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002608 int n)
2609{
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002610 while (--n >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03002611 reg_w(sd, regvals->reg, regvals->val);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002612 regvals++;
2613 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002614}
2615
Jean-François Moinef8f20182010-11-12 07:54:02 -03002616static void write_i2c_regvals(struct sd *sd,
2617 const struct ov_i2c_regvals *regvals,
2618 int n)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002619{
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002620 while (--n >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03002621 i2c_w(sd, regvals->reg, regvals->val);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002622 regvals++;
2623 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002624}
2625
2626/****************************************************************************
2627 *
2628 * OV511 and sensor configuration
2629 *
2630 ***************************************************************************/
2631
Hans de Goede635118d2009-10-11 09:49:03 -03002632/* This initializes the OV2x10 / OV3610 / OV3620 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002633static void ov_hires_configure(struct sd *sd)
Hans de Goede635118d2009-10-11 09:49:03 -03002634{
2635 int high, low;
2636
2637 if (sd->bridge != BRIDGE_OVFX2) {
Jean-François Moine0b656322010-09-13 05:19:58 -03002638 err("error hires sensors only supported with ovfx2");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002639 return;
Hans de Goede635118d2009-10-11 09:49:03 -03002640 }
2641
2642 PDEBUG(D_PROBE, "starting ov hires configuration");
2643
2644 /* Detect sensor (sub)type */
2645 high = i2c_r(sd, 0x0a);
2646 low = i2c_r(sd, 0x0b);
2647 /* info("%x, %x", high, low); */
2648 if (high == 0x96 && low == 0x40) {
2649 PDEBUG(D_PROBE, "Sensor is an OV2610");
2650 sd->sensor = SEN_OV2610;
Jean-François Moine07c6c9c2011-02-10 13:32:22 -03002651 } else if (high == 0x96 && low == 0x41) {
2652 PDEBUG(D_PROBE, "Sensor is an OV2610AE");
2653 sd->sensor = SEN_OV2610AE;
Hans de Goede635118d2009-10-11 09:49:03 -03002654 } else if (high == 0x36 && (low & 0x0f) == 0x00) {
2655 PDEBUG(D_PROBE, "Sensor is an OV3610");
2656 sd->sensor = SEN_OV3610;
2657 } else {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002658 err("Error unknown sensor type: %02x%02x",
Jean-François Moine87bae742010-11-12 05:31:34 -03002659 high, low);
Hans de Goede635118d2009-10-11 09:49:03 -03002660 }
Hans de Goede635118d2009-10-11 09:49:03 -03002661}
2662
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002663/* This initializes the OV8110, OV8610 sensor. The OV8110 uses
2664 * the same register settings as the OV8610, since they are very similar.
2665 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002666static void ov8xx0_configure(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002667{
2668 int rc;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002669
2670 PDEBUG(D_PROBE, "starting ov8xx0 configuration");
2671
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002672 /* Detect sensor (sub)type */
2673 rc = i2c_r(sd, OV7610_REG_COM_I);
2674 if (rc < 0) {
2675 PDEBUG(D_ERR, "Error detecting sensor type");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002676 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002677 }
Jean-François Moinef8f20182010-11-12 07:54:02 -03002678 if ((rc & 3) == 1)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002679 sd->sensor = SEN_OV8610;
Jean-François Moinef8f20182010-11-12 07:54:02 -03002680 else
Jean-François Moine0b656322010-09-13 05:19:58 -03002681 err("Unknown image sensor version: %d", rc & 3);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002682}
2683
2684/* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
2685 * the same register settings as the OV7610, since they are very similar.
2686 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002687static void ov7xx0_configure(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002688{
2689 int rc, high, low;
2690
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002691 PDEBUG(D_PROBE, "starting OV7xx0 configuration");
2692
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002693 /* Detect sensor (sub)type */
2694 rc = i2c_r(sd, OV7610_REG_COM_I);
2695
2696 /* add OV7670 here
2697 * it appears to be wrongly detected as a 7610 by default */
2698 if (rc < 0) {
2699 PDEBUG(D_ERR, "Error detecting sensor type");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002700 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002701 }
2702 if ((rc & 3) == 3) {
2703 /* quick hack to make OV7670s work */
2704 high = i2c_r(sd, 0x0a);
2705 low = i2c_r(sd, 0x0b);
2706 /* info("%x, %x", high, low); */
Jean-François Moine7a5a4142010-12-25 13:58:45 -03002707 if (high == 0x76 && (low & 0xf0) == 0x70) {
2708 PDEBUG(D_PROBE, "Sensor is an OV76%02x", low);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002709 sd->sensor = SEN_OV7670;
2710 } else {
2711 PDEBUG(D_PROBE, "Sensor is an OV7610");
2712 sd->sensor = SEN_OV7610;
2713 }
2714 } else if ((rc & 3) == 1) {
2715 /* I don't know what's different about the 76BE yet. */
Hans de Goedeb282d872009-06-14 19:10:40 -03002716 if (i2c_r(sd, 0x15) & 1) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002717 PDEBUG(D_PROBE, "Sensor is an OV7620AE");
Hans de Goede859cc472010-01-07 15:42:35 -03002718 sd->sensor = SEN_OV7620AE;
Hans de Goedeb282d872009-06-14 19:10:40 -03002719 } else {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002720 PDEBUG(D_PROBE, "Sensor is an OV76BE");
Hans de Goedeb282d872009-06-14 19:10:40 -03002721 sd->sensor = SEN_OV76BE;
2722 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002723 } else if ((rc & 3) == 0) {
2724 /* try to read product id registers */
2725 high = i2c_r(sd, 0x0a);
2726 if (high < 0) {
2727 PDEBUG(D_ERR, "Error detecting camera chip PID");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002728 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002729 }
2730 low = i2c_r(sd, 0x0b);
2731 if (low < 0) {
2732 PDEBUG(D_ERR, "Error detecting camera chip VER");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002733 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002734 }
2735 if (high == 0x76) {
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002736 switch (low) {
2737 case 0x30:
Jean-François Moine0b656322010-09-13 05:19:58 -03002738 err("Sensor is an OV7630/OV7635");
2739 err("7630 is not supported by this driver");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002740 return;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002741 case 0x40:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002742 PDEBUG(D_PROBE, "Sensor is an OV7645");
2743 sd->sensor = SEN_OV7640; /* FIXME */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002744 break;
2745 case 0x45:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002746 PDEBUG(D_PROBE, "Sensor is an OV7645B");
2747 sd->sensor = SEN_OV7640; /* FIXME */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002748 break;
2749 case 0x48:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002750 PDEBUG(D_PROBE, "Sensor is an OV7648");
Hans de Goede035d3a32010-01-09 08:14:43 -03002751 sd->sensor = SEN_OV7648;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002752 break;
Jean-François Moine42e142f2010-11-13 05:10:27 -03002753 case 0x60:
2754 PDEBUG(D_PROBE, "Sensor is a OV7660");
2755 sd->sensor = SEN_OV7660;
2756 sd->invert_led = 0;
2757 break;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002758 default:
2759 PDEBUG(D_PROBE, "Unknown sensor: 0x76%x", low);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002760 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002761 }
2762 } else {
2763 PDEBUG(D_PROBE, "Sensor is an OV7620");
2764 sd->sensor = SEN_OV7620;
2765 }
2766 } else {
Jean-François Moine0b656322010-09-13 05:19:58 -03002767 err("Unknown image sensor version: %d", rc & 3);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002768 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002769}
2770
2771/* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002772static void ov6xx0_configure(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002773{
2774 int rc;
Jean-Francois Moine4202f712008-09-03 17:12:15 -03002775 PDEBUG(D_PROBE, "starting OV6xx0 configuration");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002776
2777 /* Detect sensor (sub)type */
2778 rc = i2c_r(sd, OV7610_REG_COM_I);
2779 if (rc < 0) {
2780 PDEBUG(D_ERR, "Error detecting sensor type");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002781 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002782 }
2783
2784 /* Ugh. The first two bits are the version bits, but
2785 * the entire register value must be used. I guess OVT
2786 * underestimated how many variants they would make. */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002787 switch (rc) {
2788 case 0x00:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002789 sd->sensor = SEN_OV6630;
Jean-François Moine0b656322010-09-13 05:19:58 -03002790 warn("WARNING: Sensor is an OV66308. Your camera may have");
2791 warn("been misdetected in previous driver versions.");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002792 break;
2793 case 0x01:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002794 sd->sensor = SEN_OV6620;
Hans de Goede7d971372009-06-14 05:28:17 -03002795 PDEBUG(D_PROBE, "Sensor is an OV6620");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002796 break;
2797 case 0x02:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002798 sd->sensor = SEN_OV6630;
2799 PDEBUG(D_PROBE, "Sensor is an OV66308AE");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002800 break;
2801 case 0x03:
Hans de Goede7d971372009-06-14 05:28:17 -03002802 sd->sensor = SEN_OV66308AF;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002803 PDEBUG(D_PROBE, "Sensor is an OV66308AF");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002804 break;
2805 case 0x90:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002806 sd->sensor = SEN_OV6630;
Jean-François Moine0b656322010-09-13 05:19:58 -03002807 warn("WARNING: Sensor is an OV66307. Your camera may have");
2808 warn("been misdetected in previous driver versions.");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002809 break;
2810 default:
Jean-François Moine0b656322010-09-13 05:19:58 -03002811 err("FATAL: Unknown sensor version: 0x%02x", rc);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002812 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002813 }
2814
2815 /* Set sensor-specific vars */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002816 sd->sif = 1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002817}
2818
2819/* Turns on or off the LED. Only has an effect with OV511+/OV518(+)/OV519 */
2820static void ov51x_led_control(struct sd *sd, int on)
2821{
Hans de Goede9e4d8252009-06-14 06:25:06 -03002822 if (sd->invert_led)
2823 on = !on;
2824
Hans de Goede49809d62009-06-07 12:10:39 -03002825 switch (sd->bridge) {
2826 /* OV511 has no LED control */
2827 case BRIDGE_OV511PLUS:
Jean-François Moinea23acec2010-11-12 15:07:35 -03002828 reg_w(sd, R511_SYS_LED_CTL, on);
Hans de Goede49809d62009-06-07 12:10:39 -03002829 break;
2830 case BRIDGE_OV518:
2831 case BRIDGE_OV518PLUS:
Jean-François Moinea23acec2010-11-12 15:07:35 -03002832 reg_w_mask(sd, R518_GPIO_OUT, 0x02 * on, 0x02);
Hans de Goede49809d62009-06-07 12:10:39 -03002833 break;
2834 case BRIDGE_OV519:
Jean-François Moinea23acec2010-11-12 15:07:35 -03002835 reg_w_mask(sd, OV519_GPIO_DATA_OUT0, on, 1);
Hans de Goede49809d62009-06-07 12:10:39 -03002836 break;
2837 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002838}
2839
Hans de Goede417a4d22010-02-19 07:37:08 -03002840static void sd_reset_snapshot(struct gspca_dev *gspca_dev)
2841{
2842 struct sd *sd = (struct sd *) gspca_dev;
2843
2844 if (!sd->snapshot_needs_reset)
2845 return;
2846
2847 /* Note it is important that we clear sd->snapshot_needs_reset,
2848 before actually clearing the snapshot state in the bridge
2849 otherwise we might race with the pkt_scan interrupt handler */
2850 sd->snapshot_needs_reset = 0;
2851
2852 switch (sd->bridge) {
Hans de Goede88e8d202010-02-20 04:45:49 -03002853 case BRIDGE_OV511:
2854 case BRIDGE_OV511PLUS:
2855 reg_w(sd, R51x_SYS_SNAP, 0x02);
2856 reg_w(sd, R51x_SYS_SNAP, 0x00);
2857 break;
Hans de Goede92e232a2010-02-20 04:30:45 -03002858 case BRIDGE_OV518:
2859 case BRIDGE_OV518PLUS:
2860 reg_w(sd, R51x_SYS_SNAP, 0x02); /* Reset */
2861 reg_w(sd, R51x_SYS_SNAP, 0x01); /* Enable */
2862 break;
Hans de Goede417a4d22010-02-19 07:37:08 -03002863 case BRIDGE_OV519:
2864 reg_w(sd, R51x_SYS_RESET, 0x40);
2865 reg_w(sd, R51x_SYS_RESET, 0x00);
2866 break;
2867 }
2868}
2869
Jean-François Moinef8f20182010-11-12 07:54:02 -03002870static void ov51x_upload_quan_tables(struct sd *sd)
Hans de Goede49809d62009-06-07 12:10:39 -03002871{
Hans de Goede1876bb92009-06-14 06:45:50 -03002872 const unsigned char yQuanTable511[] = {
2873 0, 1, 1, 2, 2, 3, 3, 4,
2874 1, 1, 1, 2, 2, 3, 4, 4,
2875 1, 1, 2, 2, 3, 4, 4, 4,
2876 2, 2, 2, 3, 4, 4, 4, 4,
2877 2, 2, 3, 4, 4, 5, 5, 5,
2878 3, 3, 4, 4, 5, 5, 5, 5,
2879 3, 4, 4, 4, 5, 5, 5, 5,
2880 4, 4, 4, 4, 5, 5, 5, 5
2881 };
2882
2883 const unsigned char uvQuanTable511[] = {
2884 0, 2, 2, 3, 4, 4, 4, 4,
2885 2, 2, 2, 4, 4, 4, 4, 4,
2886 2, 2, 3, 4, 4, 4, 4, 4,
2887 3, 4, 4, 4, 4, 4, 4, 4,
2888 4, 4, 4, 4, 4, 4, 4, 4,
2889 4, 4, 4, 4, 4, 4, 4, 4,
2890 4, 4, 4, 4, 4, 4, 4, 4,
2891 4, 4, 4, 4, 4, 4, 4, 4
2892 };
2893
2894 /* OV518 quantization tables are 8x4 (instead of 8x8) */
Hans de Goede49809d62009-06-07 12:10:39 -03002895 const unsigned char yQuanTable518[] = {
2896 5, 4, 5, 6, 6, 7, 7, 7,
2897 5, 5, 5, 5, 6, 7, 7, 7,
2898 6, 6, 6, 6, 7, 7, 7, 8,
2899 7, 7, 6, 7, 7, 7, 8, 8
2900 };
Hans de Goede49809d62009-06-07 12:10:39 -03002901 const unsigned char uvQuanTable518[] = {
2902 6, 6, 6, 7, 7, 7, 7, 7,
2903 6, 6, 6, 7, 7, 7, 7, 7,
2904 6, 6, 6, 7, 7, 7, 7, 8,
2905 7, 7, 7, 7, 7, 7, 8, 8
2906 };
2907
Hans de Goede1876bb92009-06-14 06:45:50 -03002908 const unsigned char *pYTable, *pUVTable;
Hans de Goede49809d62009-06-07 12:10:39 -03002909 unsigned char val0, val1;
Jean-François Moinef8f20182010-11-12 07:54:02 -03002910 int i, size, reg = R51x_COMP_LUT_BEGIN;
Hans de Goede49809d62009-06-07 12:10:39 -03002911
2912 PDEBUG(D_PROBE, "Uploading quantization tables");
2913
Hans de Goede1876bb92009-06-14 06:45:50 -03002914 if (sd->bridge == BRIDGE_OV511 || sd->bridge == BRIDGE_OV511PLUS) {
2915 pYTable = yQuanTable511;
2916 pUVTable = uvQuanTable511;
Jean-François Moine87bae742010-11-12 05:31:34 -03002917 size = 32;
Hans de Goede1876bb92009-06-14 06:45:50 -03002918 } else {
2919 pYTable = yQuanTable518;
2920 pUVTable = uvQuanTable518;
Jean-François Moine87bae742010-11-12 05:31:34 -03002921 size = 16;
Hans de Goede1876bb92009-06-14 06:45:50 -03002922 }
2923
2924 for (i = 0; i < size; i++) {
Hans de Goede49809d62009-06-07 12:10:39 -03002925 val0 = *pYTable++;
2926 val1 = *pYTable++;
2927 val0 &= 0x0f;
2928 val1 &= 0x0f;
2929 val0 |= val1 << 4;
Jean-François Moinef8f20182010-11-12 07:54:02 -03002930 reg_w(sd, reg, val0);
Hans de Goede49809d62009-06-07 12:10:39 -03002931
2932 val0 = *pUVTable++;
2933 val1 = *pUVTable++;
2934 val0 &= 0x0f;
2935 val1 &= 0x0f;
2936 val0 |= val1 << 4;
Jean-François Moinef8f20182010-11-12 07:54:02 -03002937 reg_w(sd, reg + size, val0);
Hans de Goede49809d62009-06-07 12:10:39 -03002938
2939 reg++;
2940 }
Hans de Goede49809d62009-06-07 12:10:39 -03002941}
2942
Hans de Goede1876bb92009-06-14 06:45:50 -03002943/* This initializes the OV511/OV511+ and the sensor */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002944static void ov511_configure(struct gspca_dev *gspca_dev)
Hans de Goede1876bb92009-06-14 06:45:50 -03002945{
2946 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede1876bb92009-06-14 06:45:50 -03002947
2948 /* For 511 and 511+ */
2949 const struct ov_regvals init_511[] = {
2950 { R51x_SYS_RESET, 0x7f },
2951 { R51x_SYS_INIT, 0x01 },
2952 { R51x_SYS_RESET, 0x7f },
2953 { R51x_SYS_INIT, 0x01 },
2954 { R51x_SYS_RESET, 0x3f },
2955 { R51x_SYS_INIT, 0x01 },
2956 { R51x_SYS_RESET, 0x3d },
2957 };
2958
2959 const struct ov_regvals norm_511[] = {
Jean-François Moine780e3122010-10-19 04:29:10 -03002960 { R511_DRAM_FLOW_CTL, 0x01 },
Hans de Goede1876bb92009-06-14 06:45:50 -03002961 { R51x_SYS_SNAP, 0x00 },
2962 { R51x_SYS_SNAP, 0x02 },
2963 { R51x_SYS_SNAP, 0x00 },
2964 { R511_FIFO_OPTS, 0x1f },
2965 { R511_COMP_EN, 0x00 },
2966 { R511_COMP_LUT_EN, 0x03 },
2967 };
2968
2969 const struct ov_regvals norm_511_p[] = {
2970 { R511_DRAM_FLOW_CTL, 0xff },
2971 { R51x_SYS_SNAP, 0x00 },
2972 { R51x_SYS_SNAP, 0x02 },
2973 { R51x_SYS_SNAP, 0x00 },
2974 { R511_FIFO_OPTS, 0xff },
2975 { R511_COMP_EN, 0x00 },
2976 { R511_COMP_LUT_EN, 0x03 },
2977 };
2978
2979 const struct ov_regvals compress_511[] = {
2980 { 0x70, 0x1f },
2981 { 0x71, 0x05 },
2982 { 0x72, 0x06 },
2983 { 0x73, 0x06 },
2984 { 0x74, 0x14 },
2985 { 0x75, 0x03 },
2986 { 0x76, 0x04 },
2987 { 0x77, 0x04 },
2988 };
2989
2990 PDEBUG(D_PROBE, "Device custom id %x", reg_r(sd, R51x_SYS_CUST_ID));
2991
Jean-François Moinef8f20182010-11-12 07:54:02 -03002992 write_regvals(sd, init_511, ARRAY_SIZE(init_511));
Hans de Goede1876bb92009-06-14 06:45:50 -03002993
2994 switch (sd->bridge) {
2995 case BRIDGE_OV511:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002996 write_regvals(sd, norm_511, ARRAY_SIZE(norm_511));
Hans de Goede1876bb92009-06-14 06:45:50 -03002997 break;
2998 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002999 write_regvals(sd, norm_511_p, ARRAY_SIZE(norm_511_p));
Hans de Goede1876bb92009-06-14 06:45:50 -03003000 break;
3001 }
3002
3003 /* Init compression */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003004 write_regvals(sd, compress_511, ARRAY_SIZE(compress_511));
Hans de Goede1876bb92009-06-14 06:45:50 -03003005
Jean-François Moinef8f20182010-11-12 07:54:02 -03003006 ov51x_upload_quan_tables(sd);
Hans de Goede1876bb92009-06-14 06:45:50 -03003007}
3008
Hans de Goede49809d62009-06-07 12:10:39 -03003009/* This initializes the OV518/OV518+ and the sensor */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003010static void ov518_configure(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003011{
3012 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003013
Hans de Goede49809d62009-06-07 12:10:39 -03003014 /* For 518 and 518+ */
Hans de Goedee080fcd2009-06-18 05:03:16 -03003015 const struct ov_regvals init_518[] = {
Hans de Goede49809d62009-06-07 12:10:39 -03003016 { R51x_SYS_RESET, 0x40 },
3017 { R51x_SYS_INIT, 0xe1 },
3018 { R51x_SYS_RESET, 0x3e },
3019 { R51x_SYS_INIT, 0xe1 },
3020 { R51x_SYS_RESET, 0x00 },
3021 { R51x_SYS_INIT, 0xe1 },
3022 { 0x46, 0x00 },
3023 { 0x5d, 0x03 },
3024 };
3025
Hans de Goedee080fcd2009-06-18 05:03:16 -03003026 const struct ov_regvals norm_518[] = {
Hans de Goede49809d62009-06-07 12:10:39 -03003027 { R51x_SYS_SNAP, 0x02 }, /* Reset */
3028 { R51x_SYS_SNAP, 0x01 }, /* Enable */
Jean-François Moine780e3122010-10-19 04:29:10 -03003029 { 0x31, 0x0f },
Hans de Goede49809d62009-06-07 12:10:39 -03003030 { 0x5d, 0x03 },
3031 { 0x24, 0x9f },
3032 { 0x25, 0x90 },
3033 { 0x20, 0x00 },
3034 { 0x51, 0x04 },
3035 { 0x71, 0x19 },
3036 { 0x2f, 0x80 },
3037 };
3038
Hans de Goedee080fcd2009-06-18 05:03:16 -03003039 const struct ov_regvals norm_518_p[] = {
Hans de Goede49809d62009-06-07 12:10:39 -03003040 { R51x_SYS_SNAP, 0x02 }, /* Reset */
3041 { R51x_SYS_SNAP, 0x01 }, /* Enable */
Jean-François Moine780e3122010-10-19 04:29:10 -03003042 { 0x31, 0x0f },
Hans de Goede49809d62009-06-07 12:10:39 -03003043 { 0x5d, 0x03 },
3044 { 0x24, 0x9f },
3045 { 0x25, 0x90 },
3046 { 0x20, 0x60 },
3047 { 0x51, 0x02 },
3048 { 0x71, 0x19 },
3049 { 0x40, 0xff },
3050 { 0x41, 0x42 },
3051 { 0x46, 0x00 },
3052 { 0x33, 0x04 },
3053 { 0x21, 0x19 },
3054 { 0x3f, 0x10 },
3055 { 0x2f, 0x80 },
3056 };
3057
3058 /* First 5 bits of custom ID reg are a revision ID on OV518 */
3059 PDEBUG(D_PROBE, "Device revision %d",
Jean-François Moine87bae742010-11-12 05:31:34 -03003060 0x1f & reg_r(sd, R51x_SYS_CUST_ID));
Hans de Goede49809d62009-06-07 12:10:39 -03003061
Jean-François Moinef8f20182010-11-12 07:54:02 -03003062 write_regvals(sd, init_518, ARRAY_SIZE(init_518));
Hans de Goede49809d62009-06-07 12:10:39 -03003063
3064 /* Set LED GPIO pin to output mode */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003065 reg_w_mask(sd, R518_GPIO_CTL, 0x00, 0x02);
Hans de Goede49809d62009-06-07 12:10:39 -03003066
3067 switch (sd->bridge) {
3068 case BRIDGE_OV518:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003069 write_regvals(sd, norm_518, ARRAY_SIZE(norm_518));
Hans de Goede49809d62009-06-07 12:10:39 -03003070 break;
3071 case BRIDGE_OV518PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003072 write_regvals(sd, norm_518_p, ARRAY_SIZE(norm_518_p));
Hans de Goede49809d62009-06-07 12:10:39 -03003073 break;
3074 }
3075
Jean-François Moinef8f20182010-11-12 07:54:02 -03003076 ov51x_upload_quan_tables(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03003077
Jean-François Moinef8f20182010-11-12 07:54:02 -03003078 reg_w(sd, 0x2f, 0x80);
Hans de Goede49809d62009-06-07 12:10:39 -03003079}
3080
Jean-François Moinef8f20182010-11-12 07:54:02 -03003081static void ov519_configure(struct sd *sd)
Hans de Goede49809d62009-06-07 12:10:39 -03003082{
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03003083 static const struct ov_regvals init_519[] = {
Jean-François Moine87bae742010-11-12 05:31:34 -03003084 { 0x5a, 0x6d }, /* EnableSystem */
Jean-François Moinefc63de882011-01-13 05:35:18 -03003085 { 0x53, 0x9b }, /* don't enable the microcontroller */
Jean-François Moine21867802010-11-12 06:12:09 -03003086 { OV519_R54_EN_CLK1, 0xff }, /* set bit2 to enable jpeg */
Jean-François Moine87bae742010-11-12 05:31:34 -03003087 { 0x5d, 0x03 },
3088 { 0x49, 0x01 },
3089 { 0x48, 0x00 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003090 /* Set LED pin to output mode. Bit 4 must be cleared or sensor
3091 * detection will fail. This deserves further investigation. */
3092 { OV519_GPIO_IO_CTRL0, 0xee },
Jean-François Moine21867802010-11-12 06:12:09 -03003093 { OV519_R51_RESET1, 0x0f },
3094 { OV519_R51_RESET1, 0x00 },
Jean-François Moine87bae742010-11-12 05:31:34 -03003095 { 0x22, 0x00 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003096 /* windows reads 0x55 at this point*/
3097 };
3098
Jean-François Moinef8f20182010-11-12 07:54:02 -03003099 write_regvals(sd, init_519, ARRAY_SIZE(init_519));
Hans de Goede49809d62009-06-07 12:10:39 -03003100}
3101
Jean-François Moinef8f20182010-11-12 07:54:02 -03003102static void ovfx2_configure(struct sd *sd)
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003103{
3104 static const struct ov_regvals init_fx2[] = {
3105 { 0x00, 0x60 },
3106 { 0x02, 0x01 },
3107 { 0x0f, 0x1d },
3108 { 0xe9, 0x82 },
3109 { 0xea, 0xc7 },
3110 { 0xeb, 0x10 },
3111 { 0xec, 0xf6 },
3112 };
3113
3114 sd->stopped = 1;
3115
Jean-François Moinef8f20182010-11-12 07:54:02 -03003116 write_regvals(sd, init_fx2, ARRAY_SIZE(init_fx2));
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003117}
3118
Jean-François Moine42e142f2010-11-13 05:10:27 -03003119/* set the mode */
3120/* This function works for ov7660 only */
3121static void ov519_set_mode(struct sd *sd)
3122{
3123 static const struct ov_regvals bridge_ov7660[2][10] = {
3124 {{0x10, 0x14}, {0x11, 0x1e}, {0x12, 0x00}, {0x13, 0x00},
3125 {0x14, 0x00}, {0x15, 0x00}, {0x16, 0x00}, {0x20, 0x0c},
3126 {0x25, 0x01}, {0x26, 0x00}},
3127 {{0x10, 0x28}, {0x11, 0x3c}, {0x12, 0x00}, {0x13, 0x00},
3128 {0x14, 0x00}, {0x15, 0x00}, {0x16, 0x00}, {0x20, 0x0c},
3129 {0x25, 0x03}, {0x26, 0x00}}
3130 };
3131 static const struct ov_i2c_regvals sensor_ov7660[2][3] = {
3132 {{0x12, 0x00}, {0x24, 0x00}, {0x0c, 0x0c}},
3133 {{0x12, 0x00}, {0x04, 0x00}, {0x0c, 0x00}}
3134 };
3135 static const struct ov_i2c_regvals sensor_ov7660_2[] = {
3136 {OV7670_R17_HSTART, 0x13},
3137 {OV7670_R18_HSTOP, 0x01},
3138 {OV7670_R32_HREF, 0x92},
3139 {OV7670_R19_VSTART, 0x02},
3140 {OV7670_R1A_VSTOP, 0x7a},
3141 {OV7670_R03_VREF, 0x00},
3142/* {0x33, 0x00}, */
3143/* {0x34, 0x07}, */
3144/* {0x36, 0x00}, */
3145/* {0x6b, 0x0a}, */
3146 };
3147
3148 write_regvals(sd, bridge_ov7660[sd->gspca_dev.curr_mode],
3149 ARRAY_SIZE(bridge_ov7660[0]));
3150 write_i2c_regvals(sd, sensor_ov7660[sd->gspca_dev.curr_mode],
3151 ARRAY_SIZE(sensor_ov7660[0]));
3152 write_i2c_regvals(sd, sensor_ov7660_2,
3153 ARRAY_SIZE(sensor_ov7660_2));
3154}
3155
3156/* set the frame rate */
3157/* This function works for sensors ov7640, ov7648 ov7660 and ov7670 only */
3158static void ov519_set_fr(struct sd *sd)
3159{
3160 int fr;
3161 u8 clock;
3162 /* frame rate table with indices:
3163 * - mode = 0: 320x240, 1: 640x480
3164 * - fr rate = 0: 30, 1: 25, 2: 20, 3: 15, 4: 10, 5: 5
3165 * - reg = 0: bridge a4, 1: bridge 23, 2: sensor 11 (clock)
3166 */
3167 static const u8 fr_tb[2][6][3] = {
3168 {{0x04, 0xff, 0x00},
3169 {0x04, 0x1f, 0x00},
3170 {0x04, 0x1b, 0x00},
3171 {0x04, 0x15, 0x00},
3172 {0x04, 0x09, 0x00},
3173 {0x04, 0x01, 0x00}},
3174 {{0x0c, 0xff, 0x00},
3175 {0x0c, 0x1f, 0x00},
3176 {0x0c, 0x1b, 0x00},
3177 {0x04, 0xff, 0x01},
3178 {0x04, 0x1f, 0x01},
3179 {0x04, 0x1b, 0x01}},
3180 };
3181
3182 if (frame_rate > 0)
3183 sd->frame_rate = frame_rate;
3184 if (sd->frame_rate >= 30)
3185 fr = 0;
3186 else if (sd->frame_rate >= 25)
3187 fr = 1;
3188 else if (sd->frame_rate >= 20)
3189 fr = 2;
3190 else if (sd->frame_rate >= 15)
3191 fr = 3;
3192 else if (sd->frame_rate >= 10)
3193 fr = 4;
3194 else
3195 fr = 5;
3196 reg_w(sd, 0xa4, fr_tb[sd->gspca_dev.curr_mode][fr][0]);
3197 reg_w(sd, 0x23, fr_tb[sd->gspca_dev.curr_mode][fr][1]);
3198 clock = fr_tb[sd->gspca_dev.curr_mode][fr][2];
3199 if (sd->sensor == SEN_OV7660)
3200 clock |= 0x80; /* enable double clock */
3201 ov518_i2c_w(sd, OV7670_R11_CLKRC, clock);
3202}
3203
Hans de Goede49809d62009-06-07 12:10:39 -03003204/* this function is called at probe time */
3205static int sd_config(struct gspca_dev *gspca_dev,
3206 const struct usb_device_id *id)
3207{
3208 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003209 struct cam *cam = &gspca_dev->cam;
Hans de Goede49809d62009-06-07 12:10:39 -03003210
Hans de Goede9e4d8252009-06-14 06:25:06 -03003211 sd->bridge = id->driver_info & BRIDGE_MASK;
Jean-François Moinea23acec2010-11-12 15:07:35 -03003212 sd->invert_led = (id->driver_info & BRIDGE_INVERT_LED) != 0;
Hans de Goede49809d62009-06-07 12:10:39 -03003213
3214 switch (sd->bridge) {
Hans de Goede1876bb92009-06-14 06:45:50 -03003215 case BRIDGE_OV511:
3216 case BRIDGE_OV511PLUS:
Jean-François Moine7491f782010-11-13 03:56:41 -03003217 cam->cam_mode = ov511_vga_mode;
3218 cam->nmodes = ARRAY_SIZE(ov511_vga_mode);
3219 break;
3220 case BRIDGE_OV518:
3221 case BRIDGE_OV518PLUS:
3222 cam->cam_mode = ov518_vga_mode;
3223 cam->nmodes = ARRAY_SIZE(ov518_vga_mode);
3224 break;
3225 case BRIDGE_OV519:
3226 cam->cam_mode = ov519_vga_mode;
3227 cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
3228 sd->invert_led = !sd->invert_led;
3229 break;
3230 case BRIDGE_OVFX2:
3231 cam->cam_mode = ov519_vga_mode;
3232 cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
3233 cam->bulk_size = OVFX2_BULK_SIZE;
3234 cam->bulk_nurbs = MAX_NURBS;
3235 cam->bulk = 1;
3236 break;
3237 case BRIDGE_W9968CF:
3238 cam->cam_mode = w9968cf_vga_mode;
3239 cam->nmodes = ARRAY_SIZE(w9968cf_vga_mode);
3240 cam->reverse_alts = 1;
3241 break;
3242 }
3243
3244 gspca_dev->cam.ctrls = sd->ctrls;
3245 sd->quality = QUALITY_DEF;
3246
3247 return 0;
3248}
3249
3250/* this function is called at probe and resume time */
3251static int sd_init(struct gspca_dev *gspca_dev)
3252{
3253 struct sd *sd = (struct sd *) gspca_dev;
3254 struct cam *cam = &gspca_dev->cam;
3255
3256 switch (sd->bridge) {
3257 case BRIDGE_OV511:
3258 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003259 ov511_configure(gspca_dev);
Hans de Goede1876bb92009-06-14 06:45:50 -03003260 break;
Hans de Goede49809d62009-06-07 12:10:39 -03003261 case BRIDGE_OV518:
3262 case BRIDGE_OV518PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003263 ov518_configure(gspca_dev);
Hans de Goede49809d62009-06-07 12:10:39 -03003264 break;
3265 case BRIDGE_OV519:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003266 ov519_configure(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03003267 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003268 case BRIDGE_OVFX2:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003269 ovfx2_configure(sd);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003270 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03003271 case BRIDGE_W9968CF:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003272 w9968cf_configure(sd);
Hans de Goedea511ba92009-10-16 07:13:07 -03003273 break;
Hans de Goede49809d62009-06-07 12:10:39 -03003274 }
3275
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003276 /* The OV519 must be more aggressive about sensor detection since
3277 * I2C write will never fail if the sensor is not present. We have
3278 * to try to initialize the sensor to detect its presence */
Jean-François Moine7bbe6b82010-11-11 08:27:24 -03003279 sd->sensor = -1;
Hans de Goede229bb7d2009-10-11 07:41:46 -03003280
3281 /* Test for 76xx */
3282 if (init_ov_sensor(sd, OV7xx0_SID) >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03003283 ov7xx0_configure(sd);
3284
Hans de Goede229bb7d2009-10-11 07:41:46 -03003285 /* Test for 6xx0 */
3286 } else if (init_ov_sensor(sd, OV6xx0_SID) >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03003287 ov6xx0_configure(sd);
3288
Hans de Goede229bb7d2009-10-11 07:41:46 -03003289 /* Test for 8xx0 */
3290 } else if (init_ov_sensor(sd, OV8xx0_SID) >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03003291 ov8xx0_configure(sd);
3292
Hans de Goede635118d2009-10-11 09:49:03 -03003293 /* Test for 3xxx / 2xxx */
3294 } else if (init_ov_sensor(sd, OV_HIRES_SID) >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03003295 ov_hires_configure(sd);
Hans de Goede229bb7d2009-10-11 07:41:46 -03003296 } else {
Jean-François Moine0b656322010-09-13 05:19:58 -03003297 err("Can't determine sensor slave IDs");
Hans de Goede229bb7d2009-10-11 07:41:46 -03003298 goto error;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003299 }
3300
Jean-François Moine7bbe6b82010-11-11 08:27:24 -03003301 if (sd->sensor < 0)
3302 goto error;
3303
Jean-François Moine7491f782010-11-13 03:56:41 -03003304 ov51x_led_control(sd, 0); /* turn LED off */
3305
Hans de Goede49809d62009-06-07 12:10:39 -03003306 switch (sd->bridge) {
Hans de Goede1876bb92009-06-14 06:45:50 -03003307 case BRIDGE_OV511:
3308 case BRIDGE_OV511PLUS:
Jean-François Moine7491f782010-11-13 03:56:41 -03003309 if (sd->sif) {
Hans de Goede1876bb92009-06-14 06:45:50 -03003310 cam->cam_mode = ov511_sif_mode;
3311 cam->nmodes = ARRAY_SIZE(ov511_sif_mode);
3312 }
3313 break;
Hans de Goede49809d62009-06-07 12:10:39 -03003314 case BRIDGE_OV518:
3315 case BRIDGE_OV518PLUS:
Jean-François Moine7491f782010-11-13 03:56:41 -03003316 if (sd->sif) {
Hans de Goede49809d62009-06-07 12:10:39 -03003317 cam->cam_mode = ov518_sif_mode;
3318 cam->nmodes = ARRAY_SIZE(ov518_sif_mode);
3319 }
3320 break;
3321 case BRIDGE_OV519:
Jean-François Moine7491f782010-11-13 03:56:41 -03003322 if (sd->sif) {
Hans de Goede49809d62009-06-07 12:10:39 -03003323 cam->cam_mode = ov519_sif_mode;
3324 cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
3325 }
3326 break;
Hans de Goede635118d2009-10-11 09:49:03 -03003327 case BRIDGE_OVFX2:
Jean-François Moine07c6c9c2011-02-10 13:32:22 -03003328 switch (sd->sensor) {
3329 case SEN_OV2610:
3330 case SEN_OV2610AE:
Hans de Goede635118d2009-10-11 09:49:03 -03003331 cam->cam_mode = ovfx2_ov2610_mode;
3332 cam->nmodes = ARRAY_SIZE(ovfx2_ov2610_mode);
Jean-François Moine07c6c9c2011-02-10 13:32:22 -03003333 break;
3334 case SEN_OV3610:
Hans de Goede635118d2009-10-11 09:49:03 -03003335 cam->cam_mode = ovfx2_ov3610_mode;
3336 cam->nmodes = ARRAY_SIZE(ovfx2_ov3610_mode);
Jean-François Moine07c6c9c2011-02-10 13:32:22 -03003337 break;
3338 default:
3339 if (sd->sif) {
3340 cam->cam_mode = ov519_sif_mode;
3341 cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
3342 }
3343 break;
Hans de Goede635118d2009-10-11 09:49:03 -03003344 }
3345 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03003346 case BRIDGE_W9968CF:
Hans de Goede79b35902009-10-19 06:08:01 -03003347 if (sd->sif)
Jean-François Moine7491f782010-11-13 03:56:41 -03003348 cam->nmodes = ARRAY_SIZE(w9968cf_vga_mode) - 1;
Hans de Goedea511ba92009-10-16 07:13:07 -03003349
3350 /* w9968cf needs initialisation once the sensor is known */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003351 w9968cf_init(sd);
Hans de Goedea511ba92009-10-16 07:13:07 -03003352 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003353 }
Jean-François Moine83db7682010-11-12 07:14:08 -03003354
3355 gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
Hans de Goede02ab18b2009-06-14 04:32:04 -03003356
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003357 /* initialize the sensor */
3358 switch (sd->sensor) {
Hans de Goede635118d2009-10-11 09:49:03 -03003359 case SEN_OV2610:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003360 write_i2c_regvals(sd, norm_2610, ARRAY_SIZE(norm_2610));
3361
Hans de Goede635118d2009-10-11 09:49:03 -03003362 /* Enable autogain, autoexpo, awb, bandfilter */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003363 i2c_w_mask(sd, 0x13, 0x27, 0x27);
Hans de Goede635118d2009-10-11 09:49:03 -03003364 break;
Jean-François Moine07c6c9c2011-02-10 13:32:22 -03003365 case SEN_OV2610AE:
3366 write_i2c_regvals(sd, norm_2610ae, ARRAY_SIZE(norm_2610ae));
3367
3368 /* enable autoexpo */
3369 i2c_w_mask(sd, 0x13, 0x05, 0x05);
3370 break;
Hans de Goede635118d2009-10-11 09:49:03 -03003371 case SEN_OV3610:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003372 write_i2c_regvals(sd, norm_3620b, ARRAY_SIZE(norm_3620b));
3373
Hans de Goede635118d2009-10-11 09:49:03 -03003374 /* Enable autogain, autoexpo, awb, bandfilter */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003375 i2c_w_mask(sd, 0x13, 0x27, 0x27);
Hans de Goede635118d2009-10-11 09:49:03 -03003376 break;
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003377 case SEN_OV6620:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003378 write_i2c_regvals(sd, norm_6x20, ARRAY_SIZE(norm_6x20));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003379 break;
3380 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03003381 case SEN_OV66308AF:
Jean-François Moine62833ac2010-10-02 04:27:02 -03003382 sd->ctrls[CONTRAST].def = 200;
3383 /* The default is too low for the ov6630 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003384 write_i2c_regvals(sd, norm_6x30, ARRAY_SIZE(norm_6x30));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003385 break;
3386 default:
3387/* case SEN_OV7610: */
3388/* case SEN_OV76BE: */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003389 write_i2c_regvals(sd, norm_7610, ARRAY_SIZE(norm_7610));
3390 i2c_w_mask(sd, 0x0e, 0x00, 0x40);
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003391 break;
3392 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03003393 case SEN_OV7620AE:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003394 write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003395 break;
3396 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003397 case SEN_OV7648:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003398 write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003399 break;
Jean-François Moine42e142f2010-11-13 05:10:27 -03003400 case SEN_OV7660:
3401 i2c_w(sd, OV7670_R12_COM7, OV7670_COM7_RESET);
3402 msleep(14);
3403 reg_w(sd, OV519_R57_SNAPSHOT, 0x23);
3404 write_regvals(sd, init_519_ov7660,
3405 ARRAY_SIZE(init_519_ov7660));
3406 write_i2c_regvals(sd, norm_7660, ARRAY_SIZE(norm_7660));
3407 sd->gspca_dev.curr_mode = 1; /* 640x480 */
3408 sd->frame_rate = 15;
3409 ov519_set_mode(sd);
3410 ov519_set_fr(sd);
3411 sd->ctrls[COLORS].max = 4; /* 0..4 */
3412 sd->ctrls[COLORS].val =
3413 sd->ctrls[COLORS].def = 2;
3414 setcolors(gspca_dev);
3415 sd->ctrls[CONTRAST].max = 6; /* 0..6 */
3416 sd->ctrls[CONTRAST].val =
3417 sd->ctrls[CONTRAST].def = 3;
3418 setcontrast(gspca_dev);
3419 sd->ctrls[BRIGHTNESS].max = 6; /* 0..6 */
3420 sd->ctrls[BRIGHTNESS].val =
3421 sd->ctrls[BRIGHTNESS].def = 3;
3422 setbrightness(gspca_dev);
3423 sd_reset_snapshot(gspca_dev);
3424 ov51x_restart(sd);
3425 ov51x_stop(sd); /* not in win traces */
3426 ov51x_led_control(sd, 0);
3427 break;
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003428 case SEN_OV7670:
Jean-François Moine62833ac2010-10-02 04:27:02 -03003429 sd->ctrls[FREQ].max = 3; /* auto */
3430 sd->ctrls[FREQ].def = 3;
Jean-François Moinef8f20182010-11-12 07:54:02 -03003431 write_i2c_regvals(sd, norm_7670, ARRAY_SIZE(norm_7670));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003432 break;
3433 case SEN_OV8610:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003434 write_i2c_regvals(sd, norm_8610, ARRAY_SIZE(norm_8610));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003435 break;
3436 }
Jean-François Moinef8f20182010-11-12 07:54:02 -03003437 return gspca_dev->usb_err;
Jean-François Moine7491f782010-11-13 03:56:41 -03003438error:
3439 PDEBUG(D_ERR, "OV519 Config failed");
3440 return -EINVAL;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003441}
3442
Jean-François Moinec42cedb2011-02-10 13:37:48 -03003443/* function called at start time before URB creation */
3444static int sd_isoc_init(struct gspca_dev *gspca_dev)
3445{
3446 struct sd *sd = (struct sd *) gspca_dev;
3447
3448 switch (sd->bridge) {
3449 case BRIDGE_OVFX2:
3450 if (gspca_dev->width == 1600)
3451 gspca_dev->cam.bulk_size = OVFX2_BULK_SIZE;
3452 else
3453 gspca_dev->cam.bulk_size = 7 * 4096;
3454 break;
3455 }
3456 return 0;
3457}
3458
Hans de Goede1876bb92009-06-14 06:45:50 -03003459/* Set up the OV511/OV511+ with the given image parameters.
3460 *
3461 * Do not put any sensor-specific code in here (including I2C I/O functions)
3462 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003463static void ov511_mode_init_regs(struct sd *sd)
Hans de Goede1876bb92009-06-14 06:45:50 -03003464{
3465 int hsegs, vsegs, packet_size, fps, needed;
3466 int interlaced = 0;
3467 struct usb_host_interface *alt;
3468 struct usb_interface *intf;
3469
3470 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
3471 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
3472 if (!alt) {
Jean-François Moine0b656322010-09-13 05:19:58 -03003473 err("Couldn't get altsetting");
Jean-François Moinef8f20182010-11-12 07:54:02 -03003474 sd->gspca_dev.usb_err = -EIO;
3475 return;
Hans de Goede1876bb92009-06-14 06:45:50 -03003476 }
3477
3478 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
3479 reg_w(sd, R51x_FIFO_PSIZE, packet_size >> 5);
3480
3481 reg_w(sd, R511_CAM_UV_EN, 0x01);
3482 reg_w(sd, R511_SNAP_UV_EN, 0x01);
3483 reg_w(sd, R511_SNAP_OPTS, 0x03);
3484
3485 /* Here I'm assuming that snapshot size == image size.
3486 * I hope that's always true. --claudio
3487 */
3488 hsegs = (sd->gspca_dev.width >> 3) - 1;
3489 vsegs = (sd->gspca_dev.height >> 3) - 1;
3490
3491 reg_w(sd, R511_CAM_PXCNT, hsegs);
3492 reg_w(sd, R511_CAM_LNCNT, vsegs);
3493 reg_w(sd, R511_CAM_PXDIV, 0x00);
3494 reg_w(sd, R511_CAM_LNDIV, 0x00);
3495
3496 /* YUV420, low pass filter on */
3497 reg_w(sd, R511_CAM_OPTS, 0x03);
3498
3499 /* Snapshot additions */
3500 reg_w(sd, R511_SNAP_PXCNT, hsegs);
3501 reg_w(sd, R511_SNAP_LNCNT, vsegs);
3502 reg_w(sd, R511_SNAP_PXDIV, 0x00);
3503 reg_w(sd, R511_SNAP_LNDIV, 0x00);
3504
3505 /******** Set the framerate ********/
3506 if (frame_rate > 0)
3507 sd->frame_rate = frame_rate;
3508
3509 switch (sd->sensor) {
3510 case SEN_OV6620:
3511 /* No framerate control, doesn't like higher rates yet */
3512 sd->clockdiv = 3;
3513 break;
3514
3515 /* Note once the FIXME's in mode_init_ov_sensor_regs() are fixed
3516 for more sensors we need to do this for them too */
3517 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03003518 case SEN_OV7620AE:
Hans de Goede1876bb92009-06-14 06:45:50 -03003519 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003520 case SEN_OV7648:
Hans de Goedeb282d872009-06-14 19:10:40 -03003521 case SEN_OV76BE:
Hans de Goede1876bb92009-06-14 06:45:50 -03003522 if (sd->gspca_dev.width == 320)
3523 interlaced = 1;
3524 /* Fall through */
3525 case SEN_OV6630:
Hans de Goede1876bb92009-06-14 06:45:50 -03003526 case SEN_OV7610:
3527 case SEN_OV7670:
3528 switch (sd->frame_rate) {
3529 case 30:
3530 case 25:
3531 /* Not enough bandwidth to do 640x480 @ 30 fps */
3532 if (sd->gspca_dev.width != 640) {
3533 sd->clockdiv = 0;
3534 break;
3535 }
3536 /* Fall through for 640x480 case */
3537 default:
3538/* case 20: */
3539/* case 15: */
3540 sd->clockdiv = 1;
3541 break;
3542 case 10:
3543 sd->clockdiv = 2;
3544 break;
3545 case 5:
3546 sd->clockdiv = 5;
3547 break;
3548 }
3549 if (interlaced) {
3550 sd->clockdiv = (sd->clockdiv + 1) * 2 - 1;
3551 /* Higher then 10 does not work */
3552 if (sd->clockdiv > 10)
3553 sd->clockdiv = 10;
3554 }
3555 break;
3556
3557 case SEN_OV8610:
3558 /* No framerate control ?? */
3559 sd->clockdiv = 0;
3560 break;
3561 }
3562
3563 /* Check if we have enough bandwidth to disable compression */
3564 fps = (interlaced ? 60 : 30) / (sd->clockdiv + 1) + 1;
3565 needed = fps * sd->gspca_dev.width * sd->gspca_dev.height * 3 / 2;
3566 /* 1400 is a conservative estimate of the max nr of isoc packets/sec */
3567 if (needed > 1400 * packet_size) {
3568 /* Enable Y and UV quantization and compression */
3569 reg_w(sd, R511_COMP_EN, 0x07);
3570 reg_w(sd, R511_COMP_LUT_EN, 0x03);
3571 } else {
3572 reg_w(sd, R511_COMP_EN, 0x06);
3573 reg_w(sd, R511_COMP_LUT_EN, 0x00);
3574 }
3575
3576 reg_w(sd, R51x_SYS_RESET, OV511_RESET_OMNICE);
3577 reg_w(sd, R51x_SYS_RESET, 0);
Hans de Goede1876bb92009-06-14 06:45:50 -03003578}
3579
Hans de Goede49809d62009-06-07 12:10:39 -03003580/* Sets up the OV518/OV518+ with the given image parameters
3581 *
3582 * OV518 needs a completely different approach, until we can figure out what
3583 * the individual registers do. Also, only 15 FPS is supported now.
3584 *
3585 * Do not put any sensor-specific code in here (including I2C I/O functions)
3586 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003587static void ov518_mode_init_regs(struct sd *sd)
Hans de Goede49809d62009-06-07 12:10:39 -03003588{
Hans de Goedeb282d872009-06-14 19:10:40 -03003589 int hsegs, vsegs, packet_size;
3590 struct usb_host_interface *alt;
3591 struct usb_interface *intf;
3592
3593 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
3594 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
3595 if (!alt) {
Jean-François Moine0b656322010-09-13 05:19:58 -03003596 err("Couldn't get altsetting");
Jean-François Moinef8f20182010-11-12 07:54:02 -03003597 sd->gspca_dev.usb_err = -EIO;
3598 return;
Hans de Goedeb282d872009-06-14 19:10:40 -03003599 }
3600
3601 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
3602 ov518_reg_w32(sd, R51x_FIFO_PSIZE, packet_size & ~7, 2);
Hans de Goede49809d62009-06-07 12:10:39 -03003603
3604 /******** Set the mode ********/
Hans de Goede49809d62009-06-07 12:10:39 -03003605 reg_w(sd, 0x2b, 0);
3606 reg_w(sd, 0x2c, 0);
3607 reg_w(sd, 0x2d, 0);
3608 reg_w(sd, 0x2e, 0);
3609 reg_w(sd, 0x3b, 0);
3610 reg_w(sd, 0x3c, 0);
3611 reg_w(sd, 0x3d, 0);
3612 reg_w(sd, 0x3e, 0);
3613
3614 if (sd->bridge == BRIDGE_OV518) {
3615 /* Set 8-bit (YVYU) input format */
3616 reg_w_mask(sd, 0x20, 0x08, 0x08);
3617
3618 /* Set 12-bit (4:2:0) output format */
3619 reg_w_mask(sd, 0x28, 0x80, 0xf0);
3620 reg_w_mask(sd, 0x38, 0x80, 0xf0);
3621 } else {
3622 reg_w(sd, 0x28, 0x80);
3623 reg_w(sd, 0x38, 0x80);
3624 }
3625
3626 hsegs = sd->gspca_dev.width / 16;
3627 vsegs = sd->gspca_dev.height / 4;
3628
3629 reg_w(sd, 0x29, hsegs);
3630 reg_w(sd, 0x2a, vsegs);
3631
3632 reg_w(sd, 0x39, hsegs);
3633 reg_w(sd, 0x3a, vsegs);
3634
3635 /* Windows driver does this here; who knows why */
3636 reg_w(sd, 0x2f, 0x80);
3637
Jean-François Moine87bae742010-11-12 05:31:34 -03003638 /******** Set the framerate ********/
Hans de Goedeb282d872009-06-14 19:10:40 -03003639 sd->clockdiv = 1;
Hans de Goede49809d62009-06-07 12:10:39 -03003640
3641 /* Mode independent, but framerate dependent, regs */
Hans de Goedeb282d872009-06-14 19:10:40 -03003642 /* 0x51: Clock divider; Only works on some cams which use 2 crystals */
3643 reg_w(sd, 0x51, 0x04);
Hans de Goede49809d62009-06-07 12:10:39 -03003644 reg_w(sd, 0x22, 0x18);
3645 reg_w(sd, 0x23, 0xff);
3646
Hans de Goedeb282d872009-06-14 19:10:40 -03003647 if (sd->bridge == BRIDGE_OV518PLUS) {
3648 switch (sd->sensor) {
Hans de Goede859cc472010-01-07 15:42:35 -03003649 case SEN_OV7620AE:
Hans de Goedeb282d872009-06-14 19:10:40 -03003650 if (sd->gspca_dev.width == 320) {
3651 reg_w(sd, 0x20, 0x00);
3652 reg_w(sd, 0x21, 0x19);
3653 } else {
3654 reg_w(sd, 0x20, 0x60);
3655 reg_w(sd, 0x21, 0x1f);
3656 }
3657 break;
Hans de Goede859cc472010-01-07 15:42:35 -03003658 case SEN_OV7620:
3659 reg_w(sd, 0x20, 0x00);
3660 reg_w(sd, 0x21, 0x19);
3661 break;
Hans de Goedeb282d872009-06-14 19:10:40 -03003662 default:
3663 reg_w(sd, 0x21, 0x19);
3664 }
3665 } else
Hans de Goede49809d62009-06-07 12:10:39 -03003666 reg_w(sd, 0x71, 0x17); /* Compression-related? */
3667
3668 /* FIXME: Sensor-specific */
3669 /* Bit 5 is what matters here. Of course, it is "reserved" */
3670 i2c_w(sd, 0x54, 0x23);
3671
3672 reg_w(sd, 0x2f, 0x80);
3673
3674 if (sd->bridge == BRIDGE_OV518PLUS) {
3675 reg_w(sd, 0x24, 0x94);
3676 reg_w(sd, 0x25, 0x90);
3677 ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
3678 ov518_reg_w32(sd, 0xc6, 540, 2); /* 21ch */
3679 ov518_reg_w32(sd, 0xc7, 540, 2); /* 21ch */
3680 ov518_reg_w32(sd, 0xc8, 108, 2); /* 6ch */
3681 ov518_reg_w32(sd, 0xca, 131098, 3); /* 2001ah */
3682 ov518_reg_w32(sd, 0xcb, 532, 2); /* 214h */
3683 ov518_reg_w32(sd, 0xcc, 2400, 2); /* 960h */
3684 ov518_reg_w32(sd, 0xcd, 32, 2); /* 20h */
3685 ov518_reg_w32(sd, 0xce, 608, 2); /* 260h */
3686 } else {
3687 reg_w(sd, 0x24, 0x9f);
3688 reg_w(sd, 0x25, 0x90);
3689 ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
3690 ov518_reg_w32(sd, 0xc6, 381, 2); /* 17dh */
3691 ov518_reg_w32(sd, 0xc7, 381, 2); /* 17dh */
3692 ov518_reg_w32(sd, 0xc8, 128, 2); /* 80h */
3693 ov518_reg_w32(sd, 0xca, 183331, 3); /* 2cc23h */
3694 ov518_reg_w32(sd, 0xcb, 746, 2); /* 2eah */
3695 ov518_reg_w32(sd, 0xcc, 1750, 2); /* 6d6h */
3696 ov518_reg_w32(sd, 0xcd, 45, 2); /* 2dh */
3697 ov518_reg_w32(sd, 0xce, 851, 2); /* 353h */
3698 }
3699
3700 reg_w(sd, 0x2f, 0x80);
Hans de Goede49809d62009-06-07 12:10:39 -03003701}
3702
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003703/* Sets up the OV519 with the given image parameters
3704 *
3705 * OV519 needs a completely different approach, until we can figure out what
3706 * the individual registers do.
3707 *
3708 * Do not put any sensor-specific code in here (including I2C I/O functions)
3709 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003710static void ov519_mode_init_regs(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003711{
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03003712 static const struct ov_regvals mode_init_519_ov7670[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003713 { 0x5d, 0x03 }, /* Turn off suspend mode */
3714 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
Jean-François Moine21867802010-11-12 06:12:09 -03003715 { OV519_R54_EN_CLK1, 0x0f }, /* bit2 (jpeg enable) */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003716 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
3717 { 0xa3, 0x18 },
3718 { 0xa4, 0x04 },
3719 { 0xa5, 0x28 },
3720 { 0x37, 0x00 }, /* SetUsbInit */
3721 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
3722 /* Enable both fields, YUV Input, disable defect comp (why?) */
3723 { 0x20, 0x0c },
3724 { 0x21, 0x38 },
3725 { 0x22, 0x1d },
3726 { 0x17, 0x50 }, /* undocumented */
3727 { 0x37, 0x00 }, /* undocumented */
3728 { 0x40, 0xff }, /* I2C timeout counter */
3729 { 0x46, 0x00 }, /* I2C clock prescaler */
3730 { 0x59, 0x04 }, /* new from windrv 090403 */
3731 { 0xff, 0x00 }, /* undocumented */
3732 /* windows reads 0x55 at this point, why? */
3733 };
3734
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03003735 static const struct ov_regvals mode_init_519[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003736 { 0x5d, 0x03 }, /* Turn off suspend mode */
3737 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
Jean-François Moine21867802010-11-12 06:12:09 -03003738 { OV519_R54_EN_CLK1, 0x0f }, /* bit2 (jpeg enable) */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003739 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
3740 { 0xa3, 0x18 },
3741 { 0xa4, 0x04 },
3742 { 0xa5, 0x28 },
3743 { 0x37, 0x00 }, /* SetUsbInit */
3744 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
3745 /* Enable both fields, YUV Input, disable defect comp (why?) */
3746 { 0x22, 0x1d },
3747 { 0x17, 0x50 }, /* undocumented */
3748 { 0x37, 0x00 }, /* undocumented */
3749 { 0x40, 0xff }, /* I2C timeout counter */
3750 { 0x46, 0x00 }, /* I2C clock prescaler */
3751 { 0x59, 0x04 }, /* new from windrv 090403 */
3752 { 0xff, 0x00 }, /* undocumented */
3753 /* windows reads 0x55 at this point, why? */
3754 };
3755
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003756 /******** Set the mode ********/
Jean-François Moine42e142f2010-11-13 05:10:27 -03003757 switch (sd->sensor) {
3758 default:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003759 write_regvals(sd, mode_init_519, ARRAY_SIZE(mode_init_519));
Hans de Goede035d3a32010-01-09 08:14:43 -03003760 if (sd->sensor == SEN_OV7640 ||
3761 sd->sensor == SEN_OV7648) {
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003762 /* Select 8-bit input mode */
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003763 reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10);
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003764 }
Jean-François Moine42e142f2010-11-13 05:10:27 -03003765 break;
3766 case SEN_OV7660:
3767 return; /* done by ov519_set_mode/fr() */
3768 case SEN_OV7670:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003769 write_regvals(sd, mode_init_519_ov7670,
3770 ARRAY_SIZE(mode_init_519_ov7670));
Jean-François Moine42e142f2010-11-13 05:10:27 -03003771 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003772 }
3773
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003774 reg_w(sd, OV519_R10_H_SIZE, sd->gspca_dev.width >> 4);
3775 reg_w(sd, OV519_R11_V_SIZE, sd->gspca_dev.height >> 3);
Hans de Goede80142ef2009-06-14 06:26:49 -03003776 if (sd->sensor == SEN_OV7670 &&
3777 sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
3778 reg_w(sd, OV519_R12_X_OFFSETL, 0x04);
Hans de Goede035d3a32010-01-09 08:14:43 -03003779 else if (sd->sensor == SEN_OV7648 &&
3780 sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
3781 reg_w(sd, OV519_R12_X_OFFSETL, 0x01);
Hans de Goede80142ef2009-06-14 06:26:49 -03003782 else
3783 reg_w(sd, OV519_R12_X_OFFSETL, 0x00);
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003784 reg_w(sd, OV519_R13_X_OFFSETH, 0x00);
3785 reg_w(sd, OV519_R14_Y_OFFSETL, 0x00);
3786 reg_w(sd, OV519_R15_Y_OFFSETH, 0x00);
3787 reg_w(sd, OV519_R16_DIVIDER, 0x00);
3788 reg_w(sd, OV519_R25_FORMAT, 0x03); /* YUV422 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003789 reg_w(sd, 0x26, 0x00); /* Undocumented */
3790
3791 /******** Set the framerate ********/
3792 if (frame_rate > 0)
3793 sd->frame_rate = frame_rate;
3794
3795/* FIXME: These are only valid at the max resolution. */
3796 sd->clockdiv = 0;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003797 switch (sd->sensor) {
3798 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003799 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003800 switch (sd->frame_rate) {
Jean-Francois Moine53e74512008-11-08 06:10:19 -03003801 default:
3802/* case 30: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003803 reg_w(sd, 0xa4, 0x0c);
3804 reg_w(sd, 0x23, 0xff);
3805 break;
3806 case 25:
3807 reg_w(sd, 0xa4, 0x0c);
3808 reg_w(sd, 0x23, 0x1f);
3809 break;
3810 case 20:
3811 reg_w(sd, 0xa4, 0x0c);
3812 reg_w(sd, 0x23, 0x1b);
3813 break;
Jean-Francois Moine53e74512008-11-08 06:10:19 -03003814 case 15:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003815 reg_w(sd, 0xa4, 0x04);
3816 reg_w(sd, 0x23, 0xff);
3817 sd->clockdiv = 1;
3818 break;
3819 case 10:
3820 reg_w(sd, 0xa4, 0x04);
3821 reg_w(sd, 0x23, 0x1f);
3822 sd->clockdiv = 1;
3823 break;
3824 case 5:
3825 reg_w(sd, 0xa4, 0x04);
3826 reg_w(sd, 0x23, 0x1b);
3827 sd->clockdiv = 1;
3828 break;
3829 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003830 break;
3831 case SEN_OV8610:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003832 switch (sd->frame_rate) {
3833 default: /* 15 fps */
3834/* case 15: */
3835 reg_w(sd, 0xa4, 0x06);
3836 reg_w(sd, 0x23, 0xff);
3837 break;
3838 case 10:
3839 reg_w(sd, 0xa4, 0x06);
3840 reg_w(sd, 0x23, 0x1f);
3841 break;
3842 case 5:
3843 reg_w(sd, 0xa4, 0x06);
3844 reg_w(sd, 0x23, 0x1b);
3845 break;
3846 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003847 break;
3848 case SEN_OV7670: /* guesses, based on 7640 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003849 PDEBUG(D_STREAM, "Setting framerate to %d fps",
3850 (sd->frame_rate == 0) ? 15 : sd->frame_rate);
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003851 reg_w(sd, 0xa4, 0x10);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003852 switch (sd->frame_rate) {
3853 case 30:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003854 reg_w(sd, 0x23, 0xff);
3855 break;
3856 case 20:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003857 reg_w(sd, 0x23, 0x1b);
3858 break;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003859 default:
3860/* case 15: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003861 reg_w(sd, 0x23, 0xff);
3862 sd->clockdiv = 1;
3863 break;
3864 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003865 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003866 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003867}
3868
Jean-François Moinef8f20182010-11-12 07:54:02 -03003869static void mode_init_ov_sensor_regs(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003870{
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003871 struct gspca_dev *gspca_dev;
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003872 int qvga, xstart, xend, ystart, yend;
Jean-François Moine9d1593a2010-11-11 08:04:06 -03003873 u8 v;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003874
3875 gspca_dev = &sd->gspca_dev;
Jean-François Moine87bae742010-11-12 05:31:34 -03003876 qvga = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003877
3878 /******** Mode (VGA/QVGA) and sensor specific regs ********/
3879 switch (sd->sensor) {
Hans de Goede635118d2009-10-11 09:49:03 -03003880 case SEN_OV2610:
3881 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3882 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
3883 i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
3884 i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
3885 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
3886 i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
3887 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
Jean-François Moinef8f20182010-11-12 07:54:02 -03003888 return;
Jean-François Moine07c6c9c2011-02-10 13:32:22 -03003889 case SEN_OV2610AE: {
3890 u8 v;
3891
3892 /* frame rates:
3893 * 10fps / 5 fps for 1600x1200
3894 * 40fps / 20fps for 800x600
3895 */
3896 v = 80;
3897 if (qvga) {
3898 if (sd->frame_rate < 25)
3899 v = 0x81;
3900 } else {
3901 if (sd->frame_rate < 10)
3902 v = 0x81;
3903 }
3904 i2c_w(sd, 0x11, v);
3905 i2c_w(sd, 0x12, qvga ? 0x60 : 0x20);
3906 return;
3907 }
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003908 case SEN_OV3610:
Hans de Goede635118d2009-10-11 09:49:03 -03003909 if (qvga) {
3910 xstart = (1040 - gspca_dev->width) / 2 + (0x1f << 4);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003911 ystart = (776 - gspca_dev->height) / 2;
Hans de Goede635118d2009-10-11 09:49:03 -03003912 } else {
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003913 xstart = (2076 - gspca_dev->width) / 2 + (0x10 << 4);
Hans de Goede635118d2009-10-11 09:49:03 -03003914 ystart = (1544 - gspca_dev->height) / 2;
3915 }
3916 xend = xstart + gspca_dev->width;
3917 yend = ystart + gspca_dev->height;
3918 /* Writing to the COMH register resets the other windowing regs
3919 to their default values, so we must do this first. */
3920 i2c_w_mask(sd, 0x12, qvga ? 0x40 : 0x00, 0xf0);
3921 i2c_w_mask(sd, 0x32,
3922 (((xend >> 1) & 7) << 3) | ((xstart >> 1) & 7),
3923 0x3f);
3924 i2c_w_mask(sd, 0x03,
3925 (((yend >> 1) & 3) << 2) | ((ystart >> 1) & 3),
3926 0x0f);
3927 i2c_w(sd, 0x17, xstart >> 4);
3928 i2c_w(sd, 0x18, xend >> 4);
3929 i2c_w(sd, 0x19, ystart >> 3);
3930 i2c_w(sd, 0x1a, yend >> 3);
Jean-François Moinef8f20182010-11-12 07:54:02 -03003931 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003932 case SEN_OV8610:
3933 /* For OV8610 qvga means qsvga */
3934 i2c_w_mask(sd, OV7610_REG_COM_C, qvga ? (1 << 5) : 0, 1 << 5);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003935 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3936 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3937 i2c_w_mask(sd, 0x2d, 0x00, 0x40); /* from windrv 090403 */
3938 i2c_w_mask(sd, 0x28, 0x20, 0x20); /* progressive mode on */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003939 break;
3940 case SEN_OV7610:
3941 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
Jean-François Moine780e3122010-10-19 04:29:10 -03003942 i2c_w(sd, 0x35, qvga ? 0x1e : 0x9e);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003943 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3944 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003945 break;
3946 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03003947 case SEN_OV7620AE:
Hans de Goedeb282d872009-06-14 19:10:40 -03003948 case SEN_OV76BE:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003949 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3950 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
3951 i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
3952 i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
3953 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
Hans de Goedeb282d872009-06-14 19:10:40 -03003954 i2c_w_mask(sd, 0x67, qvga ? 0xb0 : 0x90, 0xf0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003955 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003956 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3957 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3958 if (sd->sensor == SEN_OV76BE)
3959 i2c_w(sd, 0x35, qvga ? 0x1e : 0x9e);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003960 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003961 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003962 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003963 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3964 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
Hans de Goede8d0082f2010-01-09 19:45:44 -03003965 /* Setting this undocumented bit in qvga mode removes a very
3966 annoying vertical shaking of the image */
Hans de Goede035d3a32010-01-09 08:14:43 -03003967 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
Hans de Goede8d0082f2010-01-09 19:45:44 -03003968 /* Unknown */
Hans de Goede035d3a32010-01-09 08:14:43 -03003969 i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
Hans de Goede8d0082f2010-01-09 19:45:44 -03003970 /* Allow higher automatic gain (to allow higher framerates) */
Hans de Goede035d3a32010-01-09 08:14:43 -03003971 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003972 i2c_w_mask(sd, 0x12, 0x04, 0x04); /* AWB: 1 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003973 break;
3974 case SEN_OV7670:
3975 /* set COM7_FMT_VGA or COM7_FMT_QVGA
3976 * do we need to set anything else?
3977 * HSTART etc are set in set_ov_sensor_window itself */
Jean-François Moine21867802010-11-12 06:12:09 -03003978 i2c_w_mask(sd, OV7670_R12_COM7,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003979 qvga ? OV7670_COM7_FMT_QVGA : OV7670_COM7_FMT_VGA,
3980 OV7670_COM7_FMT_MASK);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003981 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
Jean-François Moine21867802010-11-12 06:12:09 -03003982 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_AWB,
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003983 OV7670_COM8_AWB);
3984 if (qvga) { /* QVGA from ov7670.c by
3985 * Jonathan Corbet */
3986 xstart = 164;
3987 xend = 28;
3988 ystart = 14;
3989 yend = 494;
3990 } else { /* VGA */
3991 xstart = 158;
3992 xend = 14;
3993 ystart = 10;
3994 yend = 490;
3995 }
3996 /* OV7670 hardware window registers are split across
3997 * multiple locations */
Jean-François Moine21867802010-11-12 06:12:09 -03003998 i2c_w(sd, OV7670_R17_HSTART, xstart >> 3);
3999 i2c_w(sd, OV7670_R18_HSTOP, xend >> 3);
4000 v = i2c_r(sd, OV7670_R32_HREF);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03004001 v = (v & 0xc0) | ((xend & 0x7) << 3) | (xstart & 0x07);
4002 msleep(10); /* need to sleep between read and write to
4003 * same reg! */
Jean-François Moine21867802010-11-12 06:12:09 -03004004 i2c_w(sd, OV7670_R32_HREF, v);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03004005
Jean-François Moine21867802010-11-12 06:12:09 -03004006 i2c_w(sd, OV7670_R19_VSTART, ystart >> 2);
4007 i2c_w(sd, OV7670_R1A_VSTOP, yend >> 2);
4008 v = i2c_r(sd, OV7670_R03_VREF);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03004009 v = (v & 0xc0) | ((yend & 0x3) << 2) | (ystart & 0x03);
4010 msleep(10); /* need to sleep between read and write to
4011 * same reg! */
Jean-François Moine21867802010-11-12 06:12:09 -03004012 i2c_w(sd, OV7670_R03_VREF, v);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004013 break;
4014 case SEN_OV6620:
Hans de Goedeebbb5c32009-10-12 11:32:44 -03004015 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
4016 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
4017 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
4018 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004019 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03004020 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004021 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03004022 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004023 break;
4024 default:
Jean-François Moinef8f20182010-11-12 07:54:02 -03004025 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004026 }
4027
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004028 /******** Clock programming ********/
Hans de Goedeae49c402009-06-14 19:15:07 -03004029 i2c_w(sd, 0x11, sd->clockdiv);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004030}
4031
Jean-François Moine42e142f2010-11-13 05:10:27 -03004032/* this function works for bridge ov519 and sensors ov7660 and ov7670 only */
Jean-François Moine62833ac2010-10-02 04:27:02 -03004033static void sethvflip(struct gspca_dev *gspca_dev)
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03004034{
Jean-François Moine62833ac2010-10-02 04:27:02 -03004035 struct sd *sd = (struct sd *) gspca_dev;
4036
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03004037 if (sd->gspca_dev.streaming)
Jean-François Moine5927abc2010-11-12 15:32:29 -03004038 reg_w(sd, OV519_R51_RESET1, 0x0f); /* block stream */
Jean-François Moine21867802010-11-12 06:12:09 -03004039 i2c_w_mask(sd, OV7670_R1E_MVFP,
Jean-François Moine62833ac2010-10-02 04:27:02 -03004040 OV7670_MVFP_MIRROR * sd->ctrls[HFLIP].val
4041 | OV7670_MVFP_VFLIP * sd->ctrls[VFLIP].val,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03004042 OV7670_MVFP_MIRROR | OV7670_MVFP_VFLIP);
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03004043 if (sd->gspca_dev.streaming)
Jean-François Moine5927abc2010-11-12 15:32:29 -03004044 reg_w(sd, OV519_R51_RESET1, 0x00); /* restart stream */
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03004045}
4046
Jean-François Moinef8f20182010-11-12 07:54:02 -03004047static void set_ov_sensor_window(struct sd *sd)
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03004048{
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03004049 struct gspca_dev *gspca_dev;
Hans de Goede124cc9c2009-06-14 05:48:00 -03004050 int qvga, crop;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004051 int hwsbase, hwebase, vwsbase, vwebase, hwscale, vwscale;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004052
Hans de Goede635118d2009-10-11 09:49:03 -03004053 /* mode setup is fully handled in mode_init_ov_sensor_regs for these */
Jean-François Moine42e142f2010-11-13 05:10:27 -03004054 switch (sd->sensor) {
4055 case SEN_OV2610:
Jean-François Moine07c6c9c2011-02-10 13:32:22 -03004056 case SEN_OV2610AE:
Jean-François Moine42e142f2010-11-13 05:10:27 -03004057 case SEN_OV3610:
4058 case SEN_OV7670:
Jean-François Moinef8f20182010-11-12 07:54:02 -03004059 mode_init_ov_sensor_regs(sd);
4060 return;
Jean-François Moine42e142f2010-11-13 05:10:27 -03004061 case SEN_OV7660:
4062 ov519_set_mode(sd);
4063 ov519_set_fr(sd);
4064 return;
Jean-François Moinef8f20182010-11-12 07:54:02 -03004065 }
Jean-François Moine42e142f2010-11-13 05:10:27 -03004066
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03004067 gspca_dev = &sd->gspca_dev;
Jean-François Moine87bae742010-11-12 05:31:34 -03004068 qvga = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 1;
4069 crop = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 2;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03004070
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004071 /* The different sensor ICs handle setting up of window differently.
4072 * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!! */
4073 switch (sd->sensor) {
4074 case SEN_OV8610:
4075 hwsbase = 0x1e;
4076 hwebase = 0x1e;
4077 vwsbase = 0x02;
4078 vwebase = 0x02;
4079 break;
4080 case SEN_OV7610:
4081 case SEN_OV76BE:
4082 hwsbase = 0x38;
4083 hwebase = 0x3a;
4084 vwsbase = vwebase = 0x05;
4085 break;
4086 case SEN_OV6620:
4087 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03004088 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004089 hwsbase = 0x38;
4090 hwebase = 0x3a;
4091 vwsbase = 0x05;
4092 vwebase = 0x06;
Hans de Goede7d971372009-06-14 05:28:17 -03004093 if (sd->sensor == SEN_OV66308AF && qvga)
Hans de Goede49809d62009-06-07 12:10:39 -03004094 /* HDG: this fixes U and V getting swapped */
Hans de Goede7d971372009-06-14 05:28:17 -03004095 hwsbase++;
Hans de Goede124cc9c2009-06-14 05:48:00 -03004096 if (crop) {
4097 hwsbase += 8;
4098 hwebase += 8;
4099 vwsbase += 11;
4100 vwebase += 11;
4101 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004102 break;
4103 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03004104 case SEN_OV7620AE:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004105 hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */
4106 hwebase = 0x2f;
4107 vwsbase = vwebase = 0x05;
4108 break;
4109 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03004110 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004111 hwsbase = 0x1a;
4112 hwebase = 0x1a;
4113 vwsbase = vwebase = 0x03;
4114 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004115 default:
Jean-François Moinef8f20182010-11-12 07:54:02 -03004116 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004117 }
4118
4119 switch (sd->sensor) {
4120 case SEN_OV6620:
4121 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03004122 case SEN_OV66308AF:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03004123 if (qvga) { /* QCIF */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004124 hwscale = 0;
4125 vwscale = 0;
4126 } else { /* CIF */
4127 hwscale = 1;
4128 vwscale = 1; /* The datasheet says 0;
4129 * it's wrong */
4130 }
4131 break;
4132 case SEN_OV8610:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03004133 if (qvga) { /* QSVGA */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004134 hwscale = 1;
4135 vwscale = 1;
4136 } else { /* SVGA */
4137 hwscale = 2;
4138 vwscale = 2;
4139 }
4140 break;
4141 default: /* SEN_OV7xx0 */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03004142 if (qvga) { /* QVGA */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004143 hwscale = 1;
4144 vwscale = 0;
4145 } else { /* VGA */
4146 hwscale = 2;
4147 vwscale = 1;
4148 }
4149 }
4150
Jean-François Moinef8f20182010-11-12 07:54:02 -03004151 mode_init_ov_sensor_regs(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004152
Hans de Goedeebbb5c32009-10-12 11:32:44 -03004153 i2c_w(sd, 0x17, hwsbase);
Hans de Goedea511ba92009-10-16 07:13:07 -03004154 i2c_w(sd, 0x18, hwebase + (sd->sensor_width >> hwscale));
Hans de Goedeebbb5c32009-10-12 11:32:44 -03004155 i2c_w(sd, 0x19, vwsbase);
Hans de Goedea511ba92009-10-16 07:13:07 -03004156 i2c_w(sd, 0x1a, vwebase + (sd->sensor_height >> vwscale));
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004157}
4158
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004159/* -- start the camera -- */
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03004160static int sd_start(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004161{
4162 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004163
Hans de Goedea511ba92009-10-16 07:13:07 -03004164 /* Default for most bridges, allow bridge_mode_init_regs to override */
4165 sd->sensor_width = sd->gspca_dev.width;
4166 sd->sensor_height = sd->gspca_dev.height;
4167
Hans de Goede49809d62009-06-07 12:10:39 -03004168 switch (sd->bridge) {
Hans de Goede1876bb92009-06-14 06:45:50 -03004169 case BRIDGE_OV511:
4170 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03004171 ov511_mode_init_regs(sd);
Hans de Goede1876bb92009-06-14 06:45:50 -03004172 break;
Hans de Goede49809d62009-06-07 12:10:39 -03004173 case BRIDGE_OV518:
4174 case BRIDGE_OV518PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03004175 ov518_mode_init_regs(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03004176 break;
4177 case BRIDGE_OV519:
Jean-François Moinef8f20182010-11-12 07:54:02 -03004178 ov519_mode_init_regs(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03004179 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004180 /* case BRIDGE_OVFX2: nothing to do */
Hans de Goedea511ba92009-10-16 07:13:07 -03004181 case BRIDGE_W9968CF:
Jean-François Moinef8f20182010-11-12 07:54:02 -03004182 w9968cf_mode_init_regs(sd);
Hans de Goedea511ba92009-10-16 07:13:07 -03004183 break;
Hans de Goede49809d62009-06-07 12:10:39 -03004184 }
Hans de Goede49809d62009-06-07 12:10:39 -03004185
Jean-François Moinef8f20182010-11-12 07:54:02 -03004186 set_ov_sensor_window(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004187
Jean-François Moinee2817022010-11-12 13:59:48 -03004188 if (!(sd->gspca_dev.ctrl_dis & (1 << CONTRAST)))
4189 setcontrast(gspca_dev);
4190 if (!(sd->gspca_dev.ctrl_dis & (1 << BRIGHTNESS)))
4191 setbrightness(gspca_dev);
4192 if (!(sd->gspca_dev.ctrl_dis & (1 << COLORS)))
4193 setcolors(gspca_dev);
4194 if (!(sd->gspca_dev.ctrl_dis & ((1 << HFLIP) | (1 << VFLIP))))
4195 sethvflip(gspca_dev);
4196 if (!(sd->gspca_dev.ctrl_dis & (1 << AUTOBRIGHT)))
4197 setautobright(gspca_dev);
4198 if (!(sd->gspca_dev.ctrl_dis & (1 << FREQ)))
4199 setfreq_i(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03004200
Hans de Goede417a4d22010-02-19 07:37:08 -03004201 /* Force clear snapshot state in case the snapshot button was
4202 pressed while we weren't streaming */
4203 sd->snapshot_needs_reset = 1;
4204 sd_reset_snapshot(gspca_dev);
Hans de Goede417a4d22010-02-19 07:37:08 -03004205
Hans de Goeded6b6d7a2010-05-08 08:55:42 -03004206 sd->first_frame = 3;
4207
Jean-François Moinef8f20182010-11-12 07:54:02 -03004208 ov51x_restart(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004209 ov51x_led_control(sd, 1);
Jean-François Moinef8f20182010-11-12 07:54:02 -03004210 return gspca_dev->usb_err;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004211}
4212
4213static void sd_stopN(struct gspca_dev *gspca_dev)
4214{
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03004215 struct sd *sd = (struct sd *) gspca_dev;
4216
4217 ov51x_stop(sd);
4218 ov51x_led_control(sd, 0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004219}
4220
Hans de Goede79b35902009-10-19 06:08:01 -03004221static void sd_stop0(struct gspca_dev *gspca_dev)
4222{
4223 struct sd *sd = (struct sd *) gspca_dev;
4224
Jean-François Moined65174c2010-11-11 06:20:42 -03004225 if (!sd->gspca_dev.present)
4226 return;
Hans de Goede79b35902009-10-19 06:08:01 -03004227 if (sd->bridge == BRIDGE_W9968CF)
4228 w9968cf_stop0(sd);
Hans de Goede614d0692010-10-27 07:42:28 -03004229
Jean-François Moine14653e62010-11-11 06:17:01 -03004230#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
Hans de Goede614d0692010-10-27 07:42:28 -03004231 /* If the last button state is pressed, release it now! */
4232 if (sd->snapshot_pressed) {
4233 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
4234 input_sync(gspca_dev->input_dev);
4235 sd->snapshot_pressed = 0;
4236 }
4237#endif
Jean-François Moineb4e96ea2010-11-12 16:13:17 -03004238 if (sd->bridge == BRIDGE_OV519)
4239 reg_w(sd, OV519_R57_SNAPSHOT, 0x23);
Hans de Goede79b35902009-10-19 06:08:01 -03004240}
4241
Hans de Goede92e232a2010-02-20 04:30:45 -03004242static void ov51x_handle_button(struct gspca_dev *gspca_dev, u8 state)
4243{
4244 struct sd *sd = (struct sd *) gspca_dev;
4245
4246 if (sd->snapshot_pressed != state) {
Jean-François Moine28566432010-10-01 07:33:26 -03004247#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
Hans de Goede92e232a2010-02-20 04:30:45 -03004248 input_report_key(gspca_dev->input_dev, KEY_CAMERA, state);
4249 input_sync(gspca_dev->input_dev);
4250#endif
4251 if (state)
4252 sd->snapshot_needs_reset = 1;
4253
4254 sd->snapshot_pressed = state;
4255 } else {
Hans de Goede88e8d202010-02-20 04:45:49 -03004256 /* On the ov511 / ov519 we need to reset the button state
4257 multiple times, as resetting does not work as long as the
4258 button stays pressed */
4259 switch (sd->bridge) {
4260 case BRIDGE_OV511:
4261 case BRIDGE_OV511PLUS:
4262 case BRIDGE_OV519:
4263 if (state)
4264 sd->snapshot_needs_reset = 1;
4265 break;
4266 }
Hans de Goede92e232a2010-02-20 04:30:45 -03004267 }
4268}
4269
Hans de Goede1876bb92009-06-14 06:45:50 -03004270static void ov511_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004271 u8 *in, /* isoc packet */
4272 int len) /* iso packet length */
Hans de Goede1876bb92009-06-14 06:45:50 -03004273{
4274 struct sd *sd = (struct sd *) gspca_dev;
4275
4276 /* SOF/EOF packets have 1st to 8th bytes zeroed and the 9th
4277 * byte non-zero. The EOF packet has image width/height in the
4278 * 10th and 11th bytes. The 9th byte is given as follows:
4279 *
4280 * bit 7: EOF
4281 * 6: compression enabled
4282 * 5: 422/420/400 modes
4283 * 4: 422/420/400 modes
4284 * 3: 1
4285 * 2: snapshot button on
4286 * 1: snapshot frame
4287 * 0: even/odd field
4288 */
4289 if (!(in[0] | in[1] | in[2] | in[3] | in[4] | in[5] | in[6] | in[7]) &&
4290 (in[8] & 0x08)) {
Hans de Goede88e8d202010-02-20 04:45:49 -03004291 ov51x_handle_button(gspca_dev, (in[8] >> 2) & 1);
Hans de Goede1876bb92009-06-14 06:45:50 -03004292 if (in[8] & 0x80) {
4293 /* Frame end */
4294 if ((in[9] + 1) * 8 != gspca_dev->width ||
4295 (in[10] + 1) * 8 != gspca_dev->height) {
4296 PDEBUG(D_ERR, "Invalid frame size, got: %dx%d,"
4297 " requested: %dx%d\n",
4298 (in[9] + 1) * 8, (in[10] + 1) * 8,
4299 gspca_dev->width, gspca_dev->height);
4300 gspca_dev->last_packet_type = DISCARD_PACKET;
4301 return;
4302 }
4303 /* Add 11 byte footer to frame, might be usefull */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004304 gspca_frame_add(gspca_dev, LAST_PACKET, in, 11);
Hans de Goede1876bb92009-06-14 06:45:50 -03004305 return;
4306 } else {
4307 /* Frame start */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004308 gspca_frame_add(gspca_dev, FIRST_PACKET, in, 0);
Hans de Goede1876bb92009-06-14 06:45:50 -03004309 sd->packet_nr = 0;
4310 }
4311 }
4312
4313 /* Ignore the packet number */
4314 len--;
4315
4316 /* intermediate packet */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004317 gspca_frame_add(gspca_dev, INTER_PACKET, in, len);
Hans de Goede1876bb92009-06-14 06:45:50 -03004318}
4319
Hans de Goede49809d62009-06-07 12:10:39 -03004320static void ov518_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004321 u8 *data, /* isoc packet */
Hans de Goede49809d62009-06-07 12:10:39 -03004322 int len) /* iso packet length */
4323{
Hans de Goede92918a52009-06-14 06:21:35 -03004324 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede49809d62009-06-07 12:10:39 -03004325
4326 /* A false positive here is likely, until OVT gives me
4327 * the definitive SOF/EOF format */
4328 if ((!(data[0] | data[1] | data[2] | data[3] | data[5])) && data[6]) {
Hans de Goede92e232a2010-02-20 04:30:45 -03004329 ov51x_handle_button(gspca_dev, (data[6] >> 1) & 1);
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004330 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
4331 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
Hans de Goede92918a52009-06-14 06:21:35 -03004332 sd->packet_nr = 0;
4333 }
4334
4335 if (gspca_dev->last_packet_type == DISCARD_PACKET)
4336 return;
4337
4338 /* Does this device use packet numbers ? */
4339 if (len & 7) {
4340 len--;
4341 if (sd->packet_nr == data[len])
4342 sd->packet_nr++;
4343 /* The last few packets of the frame (which are all 0's
4344 except that they may contain part of the footer), are
4345 numbered 0 */
4346 else if (sd->packet_nr == 0 || data[len]) {
4347 PDEBUG(D_ERR, "Invalid packet nr: %d (expect: %d)",
4348 (int)data[len], (int)sd->packet_nr);
4349 gspca_dev->last_packet_type = DISCARD_PACKET;
4350 return;
4351 }
Hans de Goede49809d62009-06-07 12:10:39 -03004352 }
4353
4354 /* intermediate packet */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004355 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03004356}
4357
4358static void ov519_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004359 u8 *data, /* isoc packet */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004360 int len) /* iso packet length */
4361{
4362 /* Header of ov519 is 16 bytes:
4363 * Byte Value Description
4364 * 0 0xff magic
4365 * 1 0xff magic
4366 * 2 0xff magic
4367 * 3 0xXX 0x50 = SOF, 0x51 = EOF
4368 * 9 0xXX 0x01 initial frame without data,
4369 * 0x00 standard frame with image
4370 * 14 Lo in EOF: length of image data / 8
4371 * 15 Hi
4372 */
4373
4374 if (data[0] == 0xff && data[1] == 0xff && data[2] == 0xff) {
4375 switch (data[3]) {
4376 case 0x50: /* start of frame */
Hans de Goede417a4d22010-02-19 07:37:08 -03004377 /* Don't check the button state here, as the state
4378 usually (always ?) changes at EOF and checking it
4379 here leads to unnecessary snapshot state resets. */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004380#define HDRSZ 16
4381 data += HDRSZ;
4382 len -= HDRSZ;
4383#undef HDRSZ
4384 if (data[0] == 0xff || data[1] == 0xd8)
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004385 gspca_frame_add(gspca_dev, FIRST_PACKET,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004386 data, len);
4387 else
4388 gspca_dev->last_packet_type = DISCARD_PACKET;
4389 return;
4390 case 0x51: /* end of frame */
Hans de Goede92e232a2010-02-20 04:30:45 -03004391 ov51x_handle_button(gspca_dev, data[11] & 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004392 if (data[9] != 0)
4393 gspca_dev->last_packet_type = DISCARD_PACKET;
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004394 gspca_frame_add(gspca_dev, LAST_PACKET,
4395 NULL, 0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004396 return;
4397 }
4398 }
4399
4400 /* intermediate packet */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004401 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004402}
4403
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004404static void ovfx2_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004405 u8 *data, /* isoc packet */
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004406 int len) /* iso packet length */
4407{
Hans de Goeded6b6d7a2010-05-08 08:55:42 -03004408 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goeded6b6d7a2010-05-08 08:55:42 -03004409
4410 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
4411
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004412 /* A short read signals EOF */
4413 if (len < OVFX2_BULK_SIZE) {
Hans de Goeded6b6d7a2010-05-08 08:55:42 -03004414 /* If the frame is short, and it is one of the first ones
4415 the sensor and bridge are still syncing, so drop it. */
4416 if (sd->first_frame) {
4417 sd->first_frame--;
Jean-François Moineb192ca92010-06-27 03:08:19 -03004418 if (gspca_dev->image_len <
4419 sd->gspca_dev.width * sd->gspca_dev.height)
Hans de Goeded6b6d7a2010-05-08 08:55:42 -03004420 gspca_dev->last_packet_type = DISCARD_PACKET;
4421 }
4422 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004423 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004424 }
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004425}
4426
Hans de Goede49809d62009-06-07 12:10:39 -03004427static void sd_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004428 u8 *data, /* isoc packet */
Hans de Goede49809d62009-06-07 12:10:39 -03004429 int len) /* iso packet length */
4430{
4431 struct sd *sd = (struct sd *) gspca_dev;
4432
4433 switch (sd->bridge) {
4434 case BRIDGE_OV511:
4435 case BRIDGE_OV511PLUS:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004436 ov511_pkt_scan(gspca_dev, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03004437 break;
4438 case BRIDGE_OV518:
4439 case BRIDGE_OV518PLUS:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004440 ov518_pkt_scan(gspca_dev, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03004441 break;
4442 case BRIDGE_OV519:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004443 ov519_pkt_scan(gspca_dev, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03004444 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004445 case BRIDGE_OVFX2:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004446 ovfx2_pkt_scan(gspca_dev, data, len);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004447 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03004448 case BRIDGE_W9968CF:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004449 w9968cf_pkt_scan(gspca_dev, data, len);
Hans de Goedea511ba92009-10-16 07:13:07 -03004450 break;
Hans de Goede49809d62009-06-07 12:10:39 -03004451 }
4452}
4453
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004454/* -- management routines -- */
4455
4456static void setbrightness(struct gspca_dev *gspca_dev)
4457{
4458 struct sd *sd = (struct sd *) gspca_dev;
4459 int val;
Jean-François Moine42e142f2010-11-13 05:10:27 -03004460 static const struct ov_i2c_regvals brit_7660[][7] = {
4461 {{0x0f, 0x6a}, {0x24, 0x40}, {0x25, 0x2b}, {0x26, 0x90},
4462 {0x27, 0xe0}, {0x28, 0xe0}, {0x2c, 0xe0}},
4463 {{0x0f, 0x6a}, {0x24, 0x50}, {0x25, 0x40}, {0x26, 0xa1},
4464 {0x27, 0xc0}, {0x28, 0xc0}, {0x2c, 0xc0}},
4465 {{0x0f, 0x6a}, {0x24, 0x68}, {0x25, 0x58}, {0x26, 0xc2},
4466 {0x27, 0xa0}, {0x28, 0xa0}, {0x2c, 0xa0}},
4467 {{0x0f, 0x6a}, {0x24, 0x70}, {0x25, 0x68}, {0x26, 0xd3},
4468 {0x27, 0x80}, {0x28, 0x80}, {0x2c, 0x80}},
4469 {{0x0f, 0x6a}, {0x24, 0x80}, {0x25, 0x70}, {0x26, 0xd3},
4470 {0x27, 0x20}, {0x28, 0x20}, {0x2c, 0x20}},
4471 {{0x0f, 0x6a}, {0x24, 0x88}, {0x25, 0x78}, {0x26, 0xd3},
4472 {0x27, 0x40}, {0x28, 0x40}, {0x2c, 0x40}},
4473 {{0x0f, 0x6a}, {0x24, 0x90}, {0x25, 0x80}, {0x26, 0xd4},
4474 {0x27, 0x60}, {0x28, 0x60}, {0x2c, 0x60}}
4475 };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004476
Jean-François Moine62833ac2010-10-02 04:27:02 -03004477 val = sd->ctrls[BRIGHTNESS].val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004478 switch (sd->sensor) {
4479 case SEN_OV8610:
4480 case SEN_OV7610:
4481 case SEN_OV76BE:
4482 case SEN_OV6620:
4483 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03004484 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004485 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03004486 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004487 i2c_w(sd, OV7610_REG_BRT, val);
4488 break;
4489 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03004490 case SEN_OV7620AE:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004491 /* 7620 doesn't like manual changes when in auto mode */
Jean-François Moine62833ac2010-10-02 04:27:02 -03004492 if (!sd->ctrls[AUTOBRIGHT].val)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004493 i2c_w(sd, OV7610_REG_BRT, val);
4494 break;
Jean-François Moine42e142f2010-11-13 05:10:27 -03004495 case SEN_OV7660:
4496 write_i2c_regvals(sd, brit_7660[val],
4497 ARRAY_SIZE(brit_7660[0]));
4498 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004499 case SEN_OV7670:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03004500/*win trace
Jean-François Moine21867802010-11-12 06:12:09 -03004501 * i2c_w_mask(sd, OV7670_R13_COM8, 0, OV7670_COM8_AEC); */
4502 i2c_w(sd, OV7670_R55_BRIGHT, ov7670_abs_to_sm(val));
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004503 break;
4504 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004505}
4506
4507static void setcontrast(struct gspca_dev *gspca_dev)
4508{
4509 struct sd *sd = (struct sd *) gspca_dev;
4510 int val;
Jean-François Moine42e142f2010-11-13 05:10:27 -03004511 static const struct ov_i2c_regvals contrast_7660[][31] = {
4512 {{0x6c, 0xf0}, {0x6d, 0xf0}, {0x6e, 0xf8}, {0x6f, 0xa0},
4513 {0x70, 0x58}, {0x71, 0x38}, {0x72, 0x30}, {0x73, 0x30},
4514 {0x74, 0x28}, {0x75, 0x28}, {0x76, 0x24}, {0x77, 0x24},
4515 {0x78, 0x22}, {0x79, 0x28}, {0x7a, 0x2a}, {0x7b, 0x34},
4516 {0x7c, 0x0f}, {0x7d, 0x1e}, {0x7e, 0x3d}, {0x7f, 0x65},
4517 {0x80, 0x70}, {0x81, 0x77}, {0x82, 0x7d}, {0x83, 0x83},
4518 {0x84, 0x88}, {0x85, 0x8d}, {0x86, 0x96}, {0x87, 0x9f},
4519 {0x88, 0xb0}, {0x89, 0xc4}, {0x8a, 0xd9}},
4520 {{0x6c, 0xf0}, {0x6d, 0xf0}, {0x6e, 0xf8}, {0x6f, 0x94},
4521 {0x70, 0x58}, {0x71, 0x40}, {0x72, 0x30}, {0x73, 0x30},
4522 {0x74, 0x30}, {0x75, 0x30}, {0x76, 0x2c}, {0x77, 0x24},
4523 {0x78, 0x22}, {0x79, 0x28}, {0x7a, 0x2a}, {0x7b, 0x31},
4524 {0x7c, 0x0f}, {0x7d, 0x1e}, {0x7e, 0x3d}, {0x7f, 0x62},
4525 {0x80, 0x6d}, {0x81, 0x75}, {0x82, 0x7b}, {0x83, 0x81},
4526 {0x84, 0x87}, {0x85, 0x8d}, {0x86, 0x98}, {0x87, 0xa1},
4527 {0x88, 0xb2}, {0x89, 0xc6}, {0x8a, 0xdb}},
4528 {{0x6c, 0xf0}, {0x6d, 0xf0}, {0x6e, 0xf0}, {0x6f, 0x84},
4529 {0x70, 0x58}, {0x71, 0x48}, {0x72, 0x40}, {0x73, 0x40},
4530 {0x74, 0x28}, {0x75, 0x28}, {0x76, 0x28}, {0x77, 0x24},
4531 {0x78, 0x26}, {0x79, 0x28}, {0x7a, 0x28}, {0x7b, 0x34},
4532 {0x7c, 0x0f}, {0x7d, 0x1e}, {0x7e, 0x3c}, {0x7f, 0x5d},
4533 {0x80, 0x68}, {0x81, 0x71}, {0x82, 0x79}, {0x83, 0x81},
4534 {0x84, 0x86}, {0x85, 0x8b}, {0x86, 0x95}, {0x87, 0x9e},
4535 {0x88, 0xb1}, {0x89, 0xc5}, {0x8a, 0xd9}},
4536 {{0x6c, 0xf0}, {0x6d, 0xf0}, {0x6e, 0xf0}, {0x6f, 0x70},
4537 {0x70, 0x58}, {0x71, 0x58}, {0x72, 0x48}, {0x73, 0x48},
4538 {0x74, 0x38}, {0x75, 0x40}, {0x76, 0x34}, {0x77, 0x34},
4539 {0x78, 0x2e}, {0x79, 0x28}, {0x7a, 0x24}, {0x7b, 0x22},
4540 {0x7c, 0x0f}, {0x7d, 0x1e}, {0x7e, 0x3c}, {0x7f, 0x58},
4541 {0x80, 0x63}, {0x81, 0x6e}, {0x82, 0x77}, {0x83, 0x80},
4542 {0x84, 0x87}, {0x85, 0x8f}, {0x86, 0x9c}, {0x87, 0xa9},
4543 {0x88, 0xc0}, {0x89, 0xd4}, {0x8a, 0xe6}},
4544 {{0x6c, 0xa0}, {0x6d, 0xf0}, {0x6e, 0x90}, {0x6f, 0x80},
4545 {0x70, 0x70}, {0x71, 0x80}, {0x72, 0x60}, {0x73, 0x60},
4546 {0x74, 0x58}, {0x75, 0x60}, {0x76, 0x4c}, {0x77, 0x38},
4547 {0x78, 0x38}, {0x79, 0x2a}, {0x7a, 0x20}, {0x7b, 0x0e},
4548 {0x7c, 0x0a}, {0x7d, 0x14}, {0x7e, 0x26}, {0x7f, 0x46},
4549 {0x80, 0x54}, {0x81, 0x64}, {0x82, 0x70}, {0x83, 0x7c},
4550 {0x84, 0x87}, {0x85, 0x93}, {0x86, 0xa6}, {0x87, 0xb4},
4551 {0x88, 0xd0}, {0x89, 0xe5}, {0x8a, 0xf5}},
4552 {{0x6c, 0x60}, {0x6d, 0x80}, {0x6e, 0x60}, {0x6f, 0x80},
4553 {0x70, 0x80}, {0x71, 0x80}, {0x72, 0x88}, {0x73, 0x30},
4554 {0x74, 0x70}, {0x75, 0x68}, {0x76, 0x64}, {0x77, 0x50},
4555 {0x78, 0x3c}, {0x79, 0x22}, {0x7a, 0x10}, {0x7b, 0x08},
4556 {0x7c, 0x06}, {0x7d, 0x0e}, {0x7e, 0x1a}, {0x7f, 0x3a},
4557 {0x80, 0x4a}, {0x81, 0x5a}, {0x82, 0x6b}, {0x83, 0x7b},
4558 {0x84, 0x89}, {0x85, 0x96}, {0x86, 0xaf}, {0x87, 0xc3},
4559 {0x88, 0xe1}, {0x89, 0xf2}, {0x8a, 0xfa}},
4560 {{0x6c, 0x20}, {0x6d, 0x40}, {0x6e, 0x20}, {0x6f, 0x60},
4561 {0x70, 0x88}, {0x71, 0xc8}, {0x72, 0xc0}, {0x73, 0xb8},
4562 {0x74, 0xa8}, {0x75, 0xb8}, {0x76, 0x80}, {0x77, 0x5c},
4563 {0x78, 0x26}, {0x79, 0x10}, {0x7a, 0x08}, {0x7b, 0x04},
4564 {0x7c, 0x02}, {0x7d, 0x06}, {0x7e, 0x0a}, {0x7f, 0x22},
4565 {0x80, 0x33}, {0x81, 0x4c}, {0x82, 0x64}, {0x83, 0x7b},
4566 {0x84, 0x90}, {0x85, 0xa7}, {0x86, 0xc7}, {0x87, 0xde},
4567 {0x88, 0xf1}, {0x89, 0xf9}, {0x8a, 0xfd}},
4568 };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004569
Jean-François Moine62833ac2010-10-02 04:27:02 -03004570 val = sd->ctrls[CONTRAST].val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004571 switch (sd->sensor) {
4572 case SEN_OV7610:
4573 case SEN_OV6620:
4574 i2c_w(sd, OV7610_REG_CNT, val);
4575 break;
4576 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03004577 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004578 i2c_w_mask(sd, OV7610_REG_CNT, val >> 4, 0x0f);
Hans de Goede49809d62009-06-07 12:10:39 -03004579 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004580 case SEN_OV8610: {
Jean-François Moine9d1593a2010-11-11 08:04:06 -03004581 static const u8 ctab[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004582 0x03, 0x09, 0x0b, 0x0f, 0x53, 0x6f, 0x35, 0x7f
4583 };
4584
4585 /* Use Y gamma control instead. Bit 0 enables it. */
4586 i2c_w(sd, 0x64, ctab[val >> 5]);
4587 break;
4588 }
Hans de Goede859cc472010-01-07 15:42:35 -03004589 case SEN_OV7620:
4590 case SEN_OV7620AE: {
Jean-François Moine9d1593a2010-11-11 08:04:06 -03004591 static const u8 ctab[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004592 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
4593 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
4594 };
4595
4596 /* Use Y gamma control instead. Bit 0 enables it. */
4597 i2c_w(sd, 0x64, ctab[val >> 4]);
4598 break;
4599 }
Jean-François Moine42e142f2010-11-13 05:10:27 -03004600 case SEN_OV7660:
4601 write_i2c_regvals(sd, contrast_7660[val],
4602 ARRAY_SIZE(contrast_7660[0]));
4603 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004604 case SEN_OV7670:
4605 /* check that this isn't just the same as ov7610 */
Jean-François Moine21867802010-11-12 06:12:09 -03004606 i2c_w(sd, OV7670_R56_CONTRAS, val >> 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004607 break;
4608 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004609}
4610
4611static void setcolors(struct gspca_dev *gspca_dev)
4612{
4613 struct sd *sd = (struct sd *) gspca_dev;
4614 int val;
Jean-François Moine42e142f2010-11-13 05:10:27 -03004615 static const struct ov_i2c_regvals colors_7660[][6] = {
4616 {{0x4f, 0x28}, {0x50, 0x2a}, {0x51, 0x02}, {0x52, 0x0a},
4617 {0x53, 0x19}, {0x54, 0x23}},
4618 {{0x4f, 0x47}, {0x50, 0x4a}, {0x51, 0x03}, {0x52, 0x11},
4619 {0x53, 0x2c}, {0x54, 0x3e}},
4620 {{0x4f, 0x66}, {0x50, 0x6b}, {0x51, 0x05}, {0x52, 0x19},
4621 {0x53, 0x40}, {0x54, 0x59}},
4622 {{0x4f, 0x84}, {0x50, 0x8b}, {0x51, 0x06}, {0x52, 0x20},
4623 {0x53, 0x53}, {0x54, 0x73}},
4624 {{0x4f, 0xa3}, {0x50, 0xab}, {0x51, 0x08}, {0x52, 0x28},
4625 {0x53, 0x66}, {0x54, 0x8e}},
4626 };
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004627
Jean-François Moine62833ac2010-10-02 04:27:02 -03004628 val = sd->ctrls[COLORS].val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004629 switch (sd->sensor) {
4630 case SEN_OV8610:
4631 case SEN_OV7610:
4632 case SEN_OV76BE:
4633 case SEN_OV6620:
4634 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03004635 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004636 i2c_w(sd, OV7610_REG_SAT, val);
4637 break;
4638 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03004639 case SEN_OV7620AE:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004640 /* Use UV gamma control instead. Bits 0 & 7 are reserved. */
4641/* rc = ov_i2c_write(sd->dev, 0x62, (val >> 9) & 0x7e);
4642 if (rc < 0)
4643 goto out; */
4644 i2c_w(sd, OV7610_REG_SAT, val);
4645 break;
4646 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03004647 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004648 i2c_w(sd, OV7610_REG_SAT, val & 0xf0);
4649 break;
Jean-François Moine42e142f2010-11-13 05:10:27 -03004650 case SEN_OV7660:
4651 write_i2c_regvals(sd, colors_7660[val],
4652 ARRAY_SIZE(colors_7660[0]));
4653 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004654 case SEN_OV7670:
4655 /* supported later once I work out how to do it
4656 * transparently fail now! */
4657 /* set REG_COM13 values for UV sat auto mode */
4658 break;
4659 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004660}
4661
Jean-François Moine62833ac2010-10-02 04:27:02 -03004662static void setautobright(struct gspca_dev *gspca_dev)
Hans de Goede02ab18b2009-06-14 04:32:04 -03004663{
Jean-François Moine62833ac2010-10-02 04:27:02 -03004664 struct sd *sd = (struct sd *) gspca_dev;
4665
Jean-François Moine62833ac2010-10-02 04:27:02 -03004666 i2c_w_mask(sd, 0x2d, sd->ctrls[AUTOBRIGHT].val ? 0x10 : 0x00, 0x10);
Hans de Goede02ab18b2009-06-14 04:32:04 -03004667}
4668
Jean-François Moine62833ac2010-10-02 04:27:02 -03004669static void setfreq_i(struct sd *sd)
Hans de Goede02ab18b2009-06-14 04:32:04 -03004670{
Jean-François Moine42e142f2010-11-13 05:10:27 -03004671 if (sd->sensor == SEN_OV7660
4672 || sd->sensor == SEN_OV7670) {
Jean-François Moine62833ac2010-10-02 04:27:02 -03004673 switch (sd->ctrls[FREQ].val) {
Hans de Goede02ab18b2009-06-14 04:32:04 -03004674 case 0: /* Banding filter disabled */
Jean-François Moine21867802010-11-12 06:12:09 -03004675 i2c_w_mask(sd, OV7670_R13_COM8, 0, OV7670_COM8_BFILT);
Hans de Goede02ab18b2009-06-14 04:32:04 -03004676 break;
4677 case 1: /* 50 hz */
Jean-François Moine21867802010-11-12 06:12:09 -03004678 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT,
Hans de Goede02ab18b2009-06-14 04:32:04 -03004679 OV7670_COM8_BFILT);
Jean-François Moine21867802010-11-12 06:12:09 -03004680 i2c_w_mask(sd, OV7670_R3B_COM11, 0x08, 0x18);
Hans de Goede02ab18b2009-06-14 04:32:04 -03004681 break;
4682 case 2: /* 60 hz */
Jean-François Moine21867802010-11-12 06:12:09 -03004683 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT,
Hans de Goede02ab18b2009-06-14 04:32:04 -03004684 OV7670_COM8_BFILT);
Jean-François Moine21867802010-11-12 06:12:09 -03004685 i2c_w_mask(sd, OV7670_R3B_COM11, 0x00, 0x18);
Hans de Goede02ab18b2009-06-14 04:32:04 -03004686 break;
Jean-François Moine21867802010-11-12 06:12:09 -03004687 case 3: /* Auto hz - ov7670 only */
4688 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT,
Hans de Goede02ab18b2009-06-14 04:32:04 -03004689 OV7670_COM8_BFILT);
Jean-François Moine21867802010-11-12 06:12:09 -03004690 i2c_w_mask(sd, OV7670_R3B_COM11, OV7670_COM11_HZAUTO,
Hans de Goede02ab18b2009-06-14 04:32:04 -03004691 0x18);
4692 break;
4693 }
4694 } else {
Jean-François Moine62833ac2010-10-02 04:27:02 -03004695 switch (sd->ctrls[FREQ].val) {
Hans de Goede02ab18b2009-06-14 04:32:04 -03004696 case 0: /* Banding filter disabled */
4697 i2c_w_mask(sd, 0x2d, 0x00, 0x04);
4698 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
4699 break;
4700 case 1: /* 50 hz (filter on and framerate adj) */
4701 i2c_w_mask(sd, 0x2d, 0x04, 0x04);
4702 i2c_w_mask(sd, 0x2a, 0x80, 0x80);
4703 /* 20 fps -> 16.667 fps */
4704 if (sd->sensor == SEN_OV6620 ||
Hans de Goede7d971372009-06-14 05:28:17 -03004705 sd->sensor == SEN_OV6630 ||
4706 sd->sensor == SEN_OV66308AF)
Hans de Goede02ab18b2009-06-14 04:32:04 -03004707 i2c_w(sd, 0x2b, 0x5e);
4708 else
4709 i2c_w(sd, 0x2b, 0xac);
4710 break;
4711 case 2: /* 60 hz (filter on, ...) */
4712 i2c_w_mask(sd, 0x2d, 0x04, 0x04);
4713 if (sd->sensor == SEN_OV6620 ||
Hans de Goede7d971372009-06-14 05:28:17 -03004714 sd->sensor == SEN_OV6630 ||
4715 sd->sensor == SEN_OV66308AF) {
Hans de Goede02ab18b2009-06-14 04:32:04 -03004716 /* 20 fps -> 15 fps */
4717 i2c_w_mask(sd, 0x2a, 0x80, 0x80);
4718 i2c_w(sd, 0x2b, 0xa8);
4719 } else {
4720 /* no framerate adj. */
4721 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
4722 }
4723 break;
4724 }
4725 }
4726}
Jean-François Moine62833ac2010-10-02 04:27:02 -03004727static void setfreq(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004728{
4729 struct sd *sd = (struct sd *) gspca_dev;
4730
Jean-François Moine62833ac2010-10-02 04:27:02 -03004731 setfreq_i(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004732
Jean-François Moine62833ac2010-10-02 04:27:02 -03004733 /* Ugly but necessary */
4734 if (sd->bridge == BRIDGE_W9968CF)
4735 w9968cf_set_crop_window(sd);
Hans de Goede02ab18b2009-06-14 04:32:04 -03004736}
4737
4738static int sd_querymenu(struct gspca_dev *gspca_dev,
4739 struct v4l2_querymenu *menu)
4740{
4741 struct sd *sd = (struct sd *) gspca_dev;
4742
4743 switch (menu->id) {
4744 case V4L2_CID_POWER_LINE_FREQUENCY:
4745 switch (menu->index) {
4746 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
4747 strcpy((char *) menu->name, "NoFliker");
4748 return 0;
4749 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
4750 strcpy((char *) menu->name, "50 Hz");
4751 return 0;
4752 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
4753 strcpy((char *) menu->name, "60 Hz");
4754 return 0;
4755 case 3:
4756 if (sd->sensor != SEN_OV7670)
4757 return -EINVAL;
4758
4759 strcpy((char *) menu->name, "Automatic");
4760 return 0;
4761 }
4762 break;
4763 }
4764 return -EINVAL;
4765}
4766
Hans de Goede79b35902009-10-19 06:08:01 -03004767static int sd_get_jcomp(struct gspca_dev *gspca_dev,
4768 struct v4l2_jpegcompression *jcomp)
4769{
4770 struct sd *sd = (struct sd *) gspca_dev;
4771
4772 if (sd->bridge != BRIDGE_W9968CF)
4773 return -EINVAL;
4774
4775 memset(jcomp, 0, sizeof *jcomp);
4776 jcomp->quality = sd->quality;
4777 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT | V4L2_JPEG_MARKER_DQT |
4778 V4L2_JPEG_MARKER_DRI;
4779 return 0;
4780}
4781
4782static int sd_set_jcomp(struct gspca_dev *gspca_dev,
4783 struct v4l2_jpegcompression *jcomp)
4784{
4785 struct sd *sd = (struct sd *) gspca_dev;
4786
4787 if (sd->bridge != BRIDGE_W9968CF)
4788 return -EINVAL;
4789
4790 if (gspca_dev->streaming)
4791 return -EBUSY;
4792
4793 if (jcomp->quality < QUALITY_MIN)
4794 sd->quality = QUALITY_MIN;
4795 else if (jcomp->quality > QUALITY_MAX)
4796 sd->quality = QUALITY_MAX;
4797 else
4798 sd->quality = jcomp->quality;
4799
4800 /* Return resulting jcomp params to app */
4801 sd_get_jcomp(gspca_dev, jcomp);
4802
4803 return 0;
4804}
4805
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004806/* sub-driver description */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03004807static const struct sd_desc sd_desc = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004808 .name = MODULE_NAME,
4809 .ctrls = sd_ctrls,
4810 .nctrls = ARRAY_SIZE(sd_ctrls),
4811 .config = sd_config,
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03004812 .init = sd_init,
Jean-François Moinec42cedb2011-02-10 13:37:48 -03004813 .isoc_init = sd_isoc_init,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004814 .start = sd_start,
4815 .stopN = sd_stopN,
Hans de Goede79b35902009-10-19 06:08:01 -03004816 .stop0 = sd_stop0,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004817 .pkt_scan = sd_pkt_scan,
Hans de Goede417a4d22010-02-19 07:37:08 -03004818 .dq_callback = sd_reset_snapshot,
Hans de Goede02ab18b2009-06-14 04:32:04 -03004819 .querymenu = sd_querymenu,
Hans de Goede79b35902009-10-19 06:08:01 -03004820 .get_jcomp = sd_get_jcomp,
4821 .set_jcomp = sd_set_jcomp,
Jean-François Moine28566432010-10-01 07:33:26 -03004822#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
Hans de Goede417a4d22010-02-19 07:37:08 -03004823 .other_input = 1,
4824#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004825};
4826
4827/* -- module initialisation -- */
Jean-François Moine95c967c2011-01-13 05:20:29 -03004828static const struct usb_device_id device_table[] = {
Hans de Goedea511ba92009-10-16 07:13:07 -03004829 {USB_DEVICE(0x041e, 0x4003), .driver_info = BRIDGE_W9968CF },
Hans de Goede49809d62009-06-07 12:10:39 -03004830 {USB_DEVICE(0x041e, 0x4052), .driver_info = BRIDGE_OV519 },
4831 {USB_DEVICE(0x041e, 0x405f), .driver_info = BRIDGE_OV519 },
4832 {USB_DEVICE(0x041e, 0x4060), .driver_info = BRIDGE_OV519 },
4833 {USB_DEVICE(0x041e, 0x4061), .driver_info = BRIDGE_OV519 },
Hans de Goede9e4d8252009-06-14 06:25:06 -03004834 {USB_DEVICE(0x041e, 0x4064),
Jean-François Moine87bae742010-11-12 05:31:34 -03004835 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
Rafal Milecki518c8df2009-10-02 03:54:44 -03004836 {USB_DEVICE(0x041e, 0x4067), .driver_info = BRIDGE_OV519 },
Hans de Goede9e4d8252009-06-14 06:25:06 -03004837 {USB_DEVICE(0x041e, 0x4068),
Jean-François Moine87bae742010-11-12 05:31:34 -03004838 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
Hans de Goede49809d62009-06-07 12:10:39 -03004839 {USB_DEVICE(0x045e, 0x028c), .driver_info = BRIDGE_OV519 },
4840 {USB_DEVICE(0x054c, 0x0154), .driver_info = BRIDGE_OV519 },
Hans de Goede98184f72010-01-07 12:06:00 -03004841 {USB_DEVICE(0x054c, 0x0155),
Jean-François Moine87bae742010-11-12 05:31:34 -03004842 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
Hans de Goede1876bb92009-06-14 06:45:50 -03004843 {USB_DEVICE(0x05a9, 0x0511), .driver_info = BRIDGE_OV511 },
Hans de Goede49809d62009-06-07 12:10:39 -03004844 {USB_DEVICE(0x05a9, 0x0518), .driver_info = BRIDGE_OV518 },
4845 {USB_DEVICE(0x05a9, 0x0519), .driver_info = BRIDGE_OV519 },
4846 {USB_DEVICE(0x05a9, 0x0530), .driver_info = BRIDGE_OV519 },
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004847 {USB_DEVICE(0x05a9, 0x2800), .driver_info = BRIDGE_OVFX2 },
Hans de Goede49809d62009-06-07 12:10:39 -03004848 {USB_DEVICE(0x05a9, 0x4519), .driver_info = BRIDGE_OV519 },
4849 {USB_DEVICE(0x05a9, 0x8519), .driver_info = BRIDGE_OV519 },
Hans de Goede1876bb92009-06-14 06:45:50 -03004850 {USB_DEVICE(0x05a9, 0xa511), .driver_info = BRIDGE_OV511PLUS },
Hans de Goede49809d62009-06-07 12:10:39 -03004851 {USB_DEVICE(0x05a9, 0xa518), .driver_info = BRIDGE_OV518PLUS },
Hans de Goede1876bb92009-06-14 06:45:50 -03004852 {USB_DEVICE(0x0813, 0x0002), .driver_info = BRIDGE_OV511PLUS },
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004853 {USB_DEVICE(0x0b62, 0x0059), .driver_info = BRIDGE_OVFX2 },
4854 {USB_DEVICE(0x0e96, 0xc001), .driver_info = BRIDGE_OVFX2 },
Hans de Goedea511ba92009-10-16 07:13:07 -03004855 {USB_DEVICE(0x1046, 0x9967), .driver_info = BRIDGE_W9968CF },
Jean-François Moine87bae742010-11-12 05:31:34 -03004856 {USB_DEVICE(0x8020, 0xef04), .driver_info = BRIDGE_OVFX2 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004857 {}
4858};
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03004859
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004860MODULE_DEVICE_TABLE(usb, device_table);
4861
4862/* -- device connect -- */
4863static int sd_probe(struct usb_interface *intf,
4864 const struct usb_device_id *id)
4865{
4866 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
4867 THIS_MODULE);
4868}
4869
4870static struct usb_driver sd_driver = {
4871 .name = MODULE_NAME,
4872 .id_table = device_table,
4873 .probe = sd_probe,
4874 .disconnect = gspca_disconnect,
Jean-Francois Moine6a709742008-09-03 16:48:10 -03004875#ifdef CONFIG_PM
4876 .suspend = gspca_suspend,
4877 .resume = gspca_resume,
4878#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004879};
4880
4881/* -- module insert / remove -- */
4882static int __init sd_mod_init(void)
4883{
Jean-François Moine54826432010-09-13 04:53:03 -03004884 return usb_register(&sd_driver);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004885}
4886static void __exit sd_mod_exit(void)
4887{
4888 usb_deregister(&sd_driver);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004889}
4890
4891module_init(sd_mod_init);
4892module_exit(sd_mod_exit);
4893
4894module_param(frame_rate, int, 0644);
4895MODULE_PARM_DESC(frame_rate, "Frame rate (5, 10, 15, 20 or 30 fps)");