blob: 1d0fb4d91db42ab3ec9314198908fedbf1e566c2 [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
85#define BRIDGE_OV519 4
Hans de Goede635118d2009-10-11 09:49:03 -030086#define BRIDGE_OVFX2 5
Hans de Goedea511ba92009-10-16 07:13:07 -030087#define BRIDGE_W9968CF 6
Hans de Goede9e4d8252009-06-14 06:25:06 -030088#define BRIDGE_MASK 7
89
90 char invert_led;
91#define BRIDGE_INVERT_LED 8
Hans de Goede49809d62009-06-07 12:10:39 -030092
Hans de Goede417a4d22010-02-19 07:37:08 -030093 char snapshot_pressed;
94 char snapshot_needs_reset;
95
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030096 /* Determined by sensor type */
Jean-François Moine9d1593a2010-11-11 08:04:06 -030097 u8 sif;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030098
Jean-François Moine9d1593a2010-11-11 08:04:06 -030099 u8 quality;
Hans de Goede79b35902009-10-19 06:08:01 -0300100#define QUALITY_MIN 50
101#define QUALITY_MAX 70
102#define QUALITY_DEF 50
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300103
Jean-François Moine9d1593a2010-11-11 08:04:06 -0300104 u8 stopped; /* Streaming is temporarily paused */
105 u8 first_frame;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300106
Jean-François Moine9d1593a2010-11-11 08:04:06 -0300107 u8 frame_rate; /* current Framerate */
108 u8 clockdiv; /* clockdiv override */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300109
Jean-François Moine7bbe6b82010-11-11 08:27:24 -0300110 s8 sensor; /* Type of image sensor chip (SEN_*) */
Hans de Goedea511ba92009-10-16 07:13:07 -0300111
112 u8 sensor_addr;
Jean-François Moined6fa6632010-11-11 08:05:50 -0300113 u16 sensor_width;
114 u16 sensor_height;
115 s16 sensor_reg_cache[256];
Hans de Goede79b35902009-10-19 06:08:01 -0300116
Jean-François Moine9a731a32010-06-04 05:26:42 -0300117 u8 jpeg_hdr[JPEG_HDR_SZ];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300118};
Jean-François Moine7bbe6b82010-11-11 08:27:24 -0300119enum sensors {
120 SEN_OV2610,
121 SEN_OV3610,
122 SEN_OV6620,
123 SEN_OV6630,
124 SEN_OV66308AF,
125 SEN_OV7610,
126 SEN_OV7620,
127 SEN_OV7620AE,
128 SEN_OV7640,
129 SEN_OV7648,
130 SEN_OV7670,
131 SEN_OV76BE,
132 SEN_OV8610,
133};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300134
Hans de Goedea511ba92009-10-16 07:13:07 -0300135/* Note this is a bit of a hack, but the w9968cf driver needs the code for all
136 the ov sensors which is already present here. When we have the time we
137 really should move the sensor drivers to v4l2 sub drivers. */
138#include "w996Xcf.c"
139
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300140/* V4L2 controls supported by the driver */
Hans de Goede49809d62009-06-07 12:10:39 -0300141static void setbrightness(struct gspca_dev *gspca_dev);
142static void setcontrast(struct gspca_dev *gspca_dev);
143static void setcolors(struct gspca_dev *gspca_dev);
Jean-François Moine62833ac2010-10-02 04:27:02 -0300144static void sethvflip(struct gspca_dev *gspca_dev);
145static void setautobright(struct gspca_dev *gspca_dev);
146static void setfreq(struct gspca_dev *gspca_dev);
147static void setfreq_i(struct sd *sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300148
Hans de Goede02ab18b2009-06-14 04:32:04 -0300149static const struct ctrl sd_ctrls[] = {
Jean-François Moine62833ac2010-10-02 04:27:02 -0300150[BRIGHTNESS] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300151 {
152 .id = V4L2_CID_BRIGHTNESS,
153 .type = V4L2_CTRL_TYPE_INTEGER,
154 .name = "Brightness",
155 .minimum = 0,
156 .maximum = 255,
157 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300158 .default_value = 127,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300159 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300160 .set_control = setbrightness,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300161 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300162[CONTRAST] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300163 {
164 .id = V4L2_CID_CONTRAST,
165 .type = V4L2_CTRL_TYPE_INTEGER,
166 .name = "Contrast",
167 .minimum = 0,
168 .maximum = 255,
169 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300170 .default_value = 127,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300171 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300172 .set_control = setcontrast,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300173 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300174[COLORS] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300175 {
176 .id = V4L2_CID_SATURATION,
177 .type = V4L2_CTRL_TYPE_INTEGER,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300178 .name = "Color",
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300179 .minimum = 0,
180 .maximum = 255,
181 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300182 .default_value = 127,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300183 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300184 .set_control = setcolors,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300185 },
Hans de Goede02ab18b2009-06-14 04:32:04 -0300186/* The flip controls work with ov7670 only */
Jean-François Moine62833ac2010-10-02 04:27:02 -0300187[HFLIP] = {
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300188 {
189 .id = V4L2_CID_HFLIP,
190 .type = V4L2_CTRL_TYPE_BOOLEAN,
191 .name = "Mirror",
192 .minimum = 0,
193 .maximum = 1,
194 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300195 .default_value = 0,
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300196 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300197 .set_control = sethvflip,
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300198 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300199[VFLIP] = {
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300200 {
201 .id = V4L2_CID_VFLIP,
202 .type = V4L2_CTRL_TYPE_BOOLEAN,
203 .name = "Vflip",
204 .minimum = 0,
205 .maximum = 1,
206 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300207 .default_value = 0,
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300208 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300209 .set_control = sethvflip,
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300210 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300211[AUTOBRIGHT] = {
Hans de Goede02ab18b2009-06-14 04:32:04 -0300212 {
213 .id = V4L2_CID_AUTOBRIGHTNESS,
214 .type = V4L2_CTRL_TYPE_BOOLEAN,
215 .name = "Auto Brightness",
216 .minimum = 0,
217 .maximum = 1,
218 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300219 .default_value = 1,
Hans de Goede02ab18b2009-06-14 04:32:04 -0300220 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300221 .set_control = setautobright,
Hans de Goede02ab18b2009-06-14 04:32:04 -0300222 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300223[FREQ] = {
Hans de Goede02ab18b2009-06-14 04:32:04 -0300224 {
225 .id = V4L2_CID_POWER_LINE_FREQUENCY,
226 .type = V4L2_CTRL_TYPE_MENU,
227 .name = "Light frequency filter",
228 .minimum = 0,
Jean-François Moine87bae742010-11-12 05:31:34 -0300229 .maximum = 2, /* 0: no flicker, 1: 50Hz, 2:60Hz, 3: auto */
Hans de Goede02ab18b2009-06-14 04:32:04 -0300230 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300231 .default_value = 0,
Hans de Goede02ab18b2009-06-14 04:32:04 -0300232 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300233 .set_control = setfreq,
Hans de Goede02ab18b2009-06-14 04:32:04 -0300234 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300235};
236
Jean-François Moine83db7682010-11-12 07:14:08 -0300237/* table of the disabled controls */
238static const unsigned ctrl_dis[] = {
239[SEN_OV2610] = (1 << NCTRL) - 1, /* no control */
240
241[SEN_OV3610] = (1 << NCTRL) - 1, /* no control */
242
243[SEN_OV6620] = (1 << HFLIP) |
244 (1 << VFLIP),
245
246[SEN_OV6630] = (1 << HFLIP) |
247 (1 << VFLIP),
248
249[SEN_OV66308AF] = (1 << HFLIP) |
250 (1 << VFLIP),
251
252[SEN_OV7610] = (1 << HFLIP) |
253 (1 << VFLIP),
254
255[SEN_OV7620] = (1 << HFLIP) |
256 (1 << VFLIP),
257
258[SEN_OV7620AE] = (1 << HFLIP) |
259 (1 << VFLIP),
260
261[SEN_OV7640] = (1 << HFLIP) |
262 (1 << VFLIP) |
263 (1 << AUTOBRIGHT) |
264 (1 << CONTRAST),
265
266[SEN_OV7648] = (1 << HFLIP) |
267 (1 << VFLIP) |
268 (1 << AUTOBRIGHT) |
269 (1 << CONTRAST),
270
271[SEN_OV7670] = (1 << COLORS) |
272 (1 << AUTOBRIGHT),
273
274[SEN_OV76BE] = (1 << HFLIP) |
275 (1 << VFLIP),
276
277[SEN_OV8610] = (1 << HFLIP) |
278 (1 << VFLIP) |
279 (1 << FREQ),
280};
281
Hans de Goede49809d62009-06-07 12:10:39 -0300282static const struct v4l2_pix_format ov519_vga_mode[] = {
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300283 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
284 .bytesperline = 320,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300285 .sizeimage = 320 * 240 * 3 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300286 .colorspace = V4L2_COLORSPACE_JPEG,
287 .priv = 1},
288 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
289 .bytesperline = 640,
290 .sizeimage = 640 * 480 * 3 / 8 + 590,
291 .colorspace = V4L2_COLORSPACE_JPEG,
292 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300293};
Hans de Goede49809d62009-06-07 12:10:39 -0300294static const struct v4l2_pix_format ov519_sif_mode[] = {
Hans de Goede124cc9c2009-06-14 05:48:00 -0300295 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
296 .bytesperline = 160,
297 .sizeimage = 160 * 120 * 3 / 8 + 590,
298 .colorspace = V4L2_COLORSPACE_JPEG,
299 .priv = 3},
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300300 {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
301 .bytesperline = 176,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300302 .sizeimage = 176 * 144 * 3 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300303 .colorspace = V4L2_COLORSPACE_JPEG,
304 .priv = 1},
Hans de Goede124cc9c2009-06-14 05:48:00 -0300305 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
306 .bytesperline = 320,
307 .sizeimage = 320 * 240 * 3 / 8 + 590,
308 .colorspace = V4L2_COLORSPACE_JPEG,
309 .priv = 2},
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300310 {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
311 .bytesperline = 352,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300312 .sizeimage = 352 * 288 * 3 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300313 .colorspace = V4L2_COLORSPACE_JPEG,
314 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300315};
316
Hans de Goedeb282d872009-06-14 19:10:40 -0300317/* Note some of the sizeimage values for the ov511 / ov518 may seem
318 larger then necessary, however they need to be this big as the ov511 /
319 ov518 always fills the entire isoc frame, using 0 padding bytes when
320 it doesn't have any data. So with low framerates the amount of data
321 transfered can become quite large (libv4l will remove all the 0 padding
322 in userspace). */
Hans de Goede49809d62009-06-07 12:10:39 -0300323static const struct v4l2_pix_format ov518_vga_mode[] = {
324 {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
325 .bytesperline = 320,
Hans de Goedeb282d872009-06-14 19:10:40 -0300326 .sizeimage = 320 * 240 * 3,
Hans de Goede49809d62009-06-07 12:10:39 -0300327 .colorspace = V4L2_COLORSPACE_JPEG,
328 .priv = 1},
329 {640, 480, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
330 .bytesperline = 640,
Hans de Goedeb282d872009-06-14 19:10:40 -0300331 .sizeimage = 640 * 480 * 2,
Hans de Goede49809d62009-06-07 12:10:39 -0300332 .colorspace = V4L2_COLORSPACE_JPEG,
333 .priv = 0},
334};
335static const struct v4l2_pix_format ov518_sif_mode[] = {
Hans de Goede124cc9c2009-06-14 05:48:00 -0300336 {160, 120, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
337 .bytesperline = 160,
Hans de Goedeb282d872009-06-14 19:10:40 -0300338 .sizeimage = 70000,
Hans de Goede124cc9c2009-06-14 05:48:00 -0300339 .colorspace = V4L2_COLORSPACE_JPEG,
340 .priv = 3},
Hans de Goede49809d62009-06-07 12:10:39 -0300341 {176, 144, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
342 .bytesperline = 176,
Hans de Goedeb282d872009-06-14 19:10:40 -0300343 .sizeimage = 70000,
Hans de Goede49809d62009-06-07 12:10:39 -0300344 .colorspace = V4L2_COLORSPACE_JPEG,
345 .priv = 1},
Hans de Goede124cc9c2009-06-14 05:48:00 -0300346 {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
347 .bytesperline = 320,
Hans de Goedeb282d872009-06-14 19:10:40 -0300348 .sizeimage = 320 * 240 * 3,
Hans de Goede124cc9c2009-06-14 05:48:00 -0300349 .colorspace = V4L2_COLORSPACE_JPEG,
350 .priv = 2},
Hans de Goede49809d62009-06-07 12:10:39 -0300351 {352, 288, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
352 .bytesperline = 352,
Hans de Goedeb282d872009-06-14 19:10:40 -0300353 .sizeimage = 352 * 288 * 3,
Hans de Goede49809d62009-06-07 12:10:39 -0300354 .colorspace = V4L2_COLORSPACE_JPEG,
355 .priv = 0},
356};
357
Hans de Goede1876bb92009-06-14 06:45:50 -0300358static const struct v4l2_pix_format ov511_vga_mode[] = {
359 {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
360 .bytesperline = 320,
361 .sizeimage = 320 * 240 * 3,
362 .colorspace = V4L2_COLORSPACE_JPEG,
363 .priv = 1},
364 {640, 480, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
365 .bytesperline = 640,
366 .sizeimage = 640 * 480 * 2,
367 .colorspace = V4L2_COLORSPACE_JPEG,
368 .priv = 0},
369};
370static const struct v4l2_pix_format ov511_sif_mode[] = {
371 {160, 120, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
372 .bytesperline = 160,
Hans de Goedeb282d872009-06-14 19:10:40 -0300373 .sizeimage = 70000,
Hans de Goede1876bb92009-06-14 06:45:50 -0300374 .colorspace = V4L2_COLORSPACE_JPEG,
375 .priv = 3},
376 {176, 144, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
377 .bytesperline = 176,
Hans de Goedeb282d872009-06-14 19:10:40 -0300378 .sizeimage = 70000,
Hans de Goede1876bb92009-06-14 06:45:50 -0300379 .colorspace = V4L2_COLORSPACE_JPEG,
380 .priv = 1},
381 {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
382 .bytesperline = 320,
383 .sizeimage = 320 * 240 * 3,
384 .colorspace = V4L2_COLORSPACE_JPEG,
385 .priv = 2},
386 {352, 288, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
387 .bytesperline = 352,
388 .sizeimage = 352 * 288 * 3,
389 .colorspace = V4L2_COLORSPACE_JPEG,
390 .priv = 0},
391};
Hans de Goede49809d62009-06-07 12:10:39 -0300392
Hans de Goede635118d2009-10-11 09:49:03 -0300393static const struct v4l2_pix_format ovfx2_vga_mode[] = {
394 {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
395 .bytesperline = 320,
396 .sizeimage = 320 * 240,
397 .colorspace = V4L2_COLORSPACE_SRGB,
398 .priv = 1},
399 {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
400 .bytesperline = 640,
401 .sizeimage = 640 * 480,
402 .colorspace = V4L2_COLORSPACE_SRGB,
403 .priv = 0},
404};
405static const struct v4l2_pix_format ovfx2_cif_mode[] = {
406 {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
407 .bytesperline = 160,
408 .sizeimage = 160 * 120,
409 .colorspace = V4L2_COLORSPACE_SRGB,
410 .priv = 3},
411 {176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
412 .bytesperline = 176,
413 .sizeimage = 176 * 144,
414 .colorspace = V4L2_COLORSPACE_SRGB,
415 .priv = 1},
416 {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
417 .bytesperline = 320,
418 .sizeimage = 320 * 240,
419 .colorspace = V4L2_COLORSPACE_SRGB,
420 .priv = 2},
421 {352, 288, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
422 .bytesperline = 352,
423 .sizeimage = 352 * 288,
424 .colorspace = V4L2_COLORSPACE_SRGB,
425 .priv = 0},
426};
427static const struct v4l2_pix_format ovfx2_ov2610_mode[] = {
428 {1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
429 .bytesperline = 1600,
430 .sizeimage = 1600 * 1200,
431 .colorspace = V4L2_COLORSPACE_SRGB},
432};
433static const struct v4l2_pix_format ovfx2_ov3610_mode[] = {
Hans de Goede635118d2009-10-11 09:49:03 -0300434 {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
435 .bytesperline = 640,
436 .sizeimage = 640 * 480,
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300437 .colorspace = V4L2_COLORSPACE_SRGB,
438 .priv = 1},
439 {800, 600, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
440 .bytesperline = 800,
441 .sizeimage = 800 * 600,
442 .colorspace = V4L2_COLORSPACE_SRGB,
443 .priv = 1},
444 {1024, 768, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
445 .bytesperline = 1024,
446 .sizeimage = 1024 * 768,
447 .colorspace = V4L2_COLORSPACE_SRGB,
448 .priv = 1},
449 {1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
450 .bytesperline = 1600,
451 .sizeimage = 1600 * 1200,
452 .colorspace = V4L2_COLORSPACE_SRGB,
453 .priv = 0},
454 {2048, 1536, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
455 .bytesperline = 2048,
456 .sizeimage = 2048 * 1536,
457 .colorspace = V4L2_COLORSPACE_SRGB,
458 .priv = 0},
Hans de Goede635118d2009-10-11 09:49:03 -0300459};
460
Hans de Goede49809d62009-06-07 12:10:39 -0300461/* Registers common to OV511 / OV518 */
Hans de Goede1876bb92009-06-14 06:45:50 -0300462#define R51x_FIFO_PSIZE 0x30 /* 2 bytes wide w/ OV518(+) */
Jean-François Moine780e3122010-10-19 04:29:10 -0300463#define R51x_SYS_RESET 0x50
Hans de Goede1876bb92009-06-14 06:45:50 -0300464 /* Reset type flags */
465 #define OV511_RESET_OMNICE 0x08
Jean-François Moine780e3122010-10-19 04:29:10 -0300466#define R51x_SYS_INIT 0x53
Hans de Goede49809d62009-06-07 12:10:39 -0300467#define R51x_SYS_SNAP 0x52
Jean-François Moine87bae742010-11-12 05:31:34 -0300468#define R51x_SYS_CUST_ID 0x5f
Hans de Goede49809d62009-06-07 12:10:39 -0300469#define R51x_COMP_LUT_BEGIN 0x80
470
471/* OV511 Camera interface register numbers */
Hans de Goede1876bb92009-06-14 06:45:50 -0300472#define R511_CAM_DELAY 0x10
473#define R511_CAM_EDGE 0x11
474#define R511_CAM_PXCNT 0x12
475#define R511_CAM_LNCNT 0x13
476#define R511_CAM_PXDIV 0x14
477#define R511_CAM_LNDIV 0x15
478#define R511_CAM_UV_EN 0x16
479#define R511_CAM_LINE_MODE 0x17
480#define R511_CAM_OPTS 0x18
481
482#define R511_SNAP_FRAME 0x19
Jean-François Moine87bae742010-11-12 05:31:34 -0300483#define R511_SNAP_PXCNT 0x1a
484#define R511_SNAP_LNCNT 0x1b
485#define R511_SNAP_PXDIV 0x1c
486#define R511_SNAP_LNDIV 0x1d
487#define R511_SNAP_UV_EN 0x1e
488#define R511_SNAP_UV_EN 0x1e
489#define R511_SNAP_OPTS 0x1f
Hans de Goede1876bb92009-06-14 06:45:50 -0300490
491#define R511_DRAM_FLOW_CTL 0x20
492#define R511_FIFO_OPTS 0x31
493#define R511_I2C_CTL 0x40
Hans de Goede49809d62009-06-07 12:10:39 -0300494#define R511_SYS_LED_CTL 0x55 /* OV511+ only */
Hans de Goede1876bb92009-06-14 06:45:50 -0300495#define R511_COMP_EN 0x78
496#define R511_COMP_LUT_EN 0x79
Hans de Goede49809d62009-06-07 12:10:39 -0300497
498/* OV518 Camera interface register numbers */
499#define R518_GPIO_OUT 0x56 /* OV518(+) only */
500#define R518_GPIO_CTL 0x57 /* OV518(+) only */
501
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300502/* OV519 Camera interface register numbers */
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300503#define OV519_R10_H_SIZE 0x10
504#define OV519_R11_V_SIZE 0x11
505#define OV519_R12_X_OFFSETL 0x12
506#define OV519_R13_X_OFFSETH 0x13
507#define OV519_R14_Y_OFFSETL 0x14
508#define OV519_R15_Y_OFFSETH 0x15
509#define OV519_R16_DIVIDER 0x16
510#define OV519_R20_DFR 0x20
511#define OV519_R25_FORMAT 0x25
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300512
513/* OV519 System Controller register numbers */
Jean-François Moine21867802010-11-12 06:12:09 -0300514#define OV519_R51_RESET1 0x51
515#define OV519_R54_EN_CLK1 0x54
Jean-François Moineb4e96ea2010-11-12 16:13:17 -0300516#define OV519_R57_SNAPSHOT 0x57
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300517
518#define OV519_GPIO_DATA_OUT0 0x71
519#define OV519_GPIO_IO_CTRL0 0x72
520
Jean-François Moine87bae742010-11-12 05:31:34 -0300521/*#define OV511_ENDPOINT_ADDRESS 1 * Isoc endpoint number */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300522
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300523/*
524 * The FX2 chip does not give us a zero length read at end of frame.
525 * It does, however, give a short read at the end of a frame, if
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800526 * necessary, rather than run two frames together.
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300527 *
528 * By choosing the right bulk transfer size, we are guaranteed to always
529 * get a short read for the last read of each frame. Frame sizes are
530 * always a composite number (width * height, or a multiple) so if we
531 * choose a prime number, we are guaranteed that the last read of a
532 * frame will be short.
533 *
534 * But it isn't that easy: the 2.6 kernel requires a multiple of 4KB,
535 * otherwise EOVERFLOW "babbling" errors occur. I have not been able
536 * to figure out why. [PMiller]
537 *
538 * The constant (13 * 4096) is the largest "prime enough" number less than 64KB.
539 *
540 * It isn't enough to know the number of bytes per frame, in case we
541 * have data dropouts or buffer overruns (even though the FX2 double
542 * buffers, there are some pretty strict real time constraints for
543 * isochronous transfer for larger frame sizes).
544 */
545#define OVFX2_BULK_SIZE (13 * 4096)
546
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300547/* I2C registers */
548#define R51x_I2C_W_SID 0x41
549#define R51x_I2C_SADDR_3 0x42
550#define R51x_I2C_SADDR_2 0x43
551#define R51x_I2C_R_SID 0x44
552#define R51x_I2C_DATA 0x45
553#define R518_I2C_CTL 0x47 /* OV518(+) only */
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300554#define OVFX2_I2C_ADDR 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300555
556/* I2C ADDRESSES */
557#define OV7xx0_SID 0x42
Hans de Goede229bb7d2009-10-11 07:41:46 -0300558#define OV_HIRES_SID 0x60 /* OV9xxx / OV2xxx / OV3xxx */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300559#define OV8xx0_SID 0xa0
560#define OV6xx0_SID 0xc0
561
562/* OV7610 registers */
563#define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */
Hans de Goede49809d62009-06-07 12:10:39 -0300564#define OV7610_REG_BLUE 0x01 /* blue channel balance */
565#define OV7610_REG_RED 0x02 /* red channel balance */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300566#define OV7610_REG_SAT 0x03 /* saturation */
567#define OV8610_REG_HUE 0x04 /* 04 reserved */
568#define OV7610_REG_CNT 0x05 /* Y contrast */
569#define OV7610_REG_BRT 0x06 /* Y brightness */
570#define OV7610_REG_COM_C 0x14 /* misc common regs */
571#define OV7610_REG_ID_HIGH 0x1c /* manufacturer ID MSB */
572#define OV7610_REG_ID_LOW 0x1d /* manufacturer ID LSB */
573#define OV7610_REG_COM_I 0x29 /* misc settings */
574
575/* OV7670 registers */
Jean-François Moine21867802010-11-12 06:12:09 -0300576#define OV7670_R00_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
577#define OV7670_R01_BLUE 0x01 /* blue gain */
578#define OV7670_R02_RED 0x02 /* red gain */
579#define OV7670_R03_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */
580#define OV7670_R04_COM1 0x04 /* Control 1 */
581/*#define OV7670_R07_AECHH 0x07 * AEC MS 5 bits */
582#define OV7670_R0C_COM3 0x0c /* Control 3 */
583#define OV7670_R0D_COM4 0x0d /* Control 4 */
584#define OV7670_R0E_COM5 0x0e /* All "reserved" */
585#define OV7670_R0F_COM6 0x0f /* Control 6 */
586#define OV7670_R10_AECH 0x10 /* More bits of AEC value */
587#define OV7670_R11_CLKRC 0x11 /* Clock control */
588#define OV7670_R12_COM7 0x12 /* Control 7 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300589#define OV7670_COM7_FMT_VGA 0x00
590/*#define OV7670_COM7_YUV 0x00 * YUV */
591#define OV7670_COM7_FMT_QVGA 0x10 /* QVGA format */
592#define OV7670_COM7_FMT_MASK 0x38
593#define OV7670_COM7_RESET 0x80 /* Register reset */
Jean-François Moine21867802010-11-12 06:12:09 -0300594#define OV7670_R13_COM8 0x13 /* Control 8 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300595#define OV7670_COM8_AEC 0x01 /* Auto exposure enable */
596#define OV7670_COM8_AWB 0x02 /* White balance enable */
597#define OV7670_COM8_AGC 0x04 /* Auto gain enable */
598#define OV7670_COM8_BFILT 0x20 /* Band filter enable */
599#define OV7670_COM8_AECSTEP 0x40 /* Unlimited AEC step size */
600#define OV7670_COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
Jean-François Moine21867802010-11-12 06:12:09 -0300601#define OV7670_R14_COM9 0x14 /* Control 9 - gain ceiling */
602#define OV7670_R15_COM10 0x15 /* Control 10 */
603#define OV7670_R17_HSTART 0x17 /* Horiz start high bits */
604#define OV7670_R18_HSTOP 0x18 /* Horiz stop high bits */
605#define OV7670_R19_VSTART 0x19 /* Vert start high bits */
606#define OV7670_R1A_VSTOP 0x1a /* Vert stop high bits */
607#define OV7670_R1E_MVFP 0x1e /* Mirror / vflip */
Jean-François Moine87bae742010-11-12 05:31:34 -0300608#define OV7670_MVFP_VFLIP 0x10 /* vertical flip */
609#define OV7670_MVFP_MIRROR 0x20 /* Mirror image */
Jean-François Moine21867802010-11-12 06:12:09 -0300610#define OV7670_R24_AEW 0x24 /* AGC upper limit */
611#define OV7670_R25_AEB 0x25 /* AGC lower limit */
612#define OV7670_R26_VPT 0x26 /* AGC/AEC fast mode op region */
613#define OV7670_R32_HREF 0x32 /* HREF pieces */
614#define OV7670_R3A_TSLB 0x3a /* lots of stuff */
615#define OV7670_R3B_COM11 0x3b /* Control 11 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300616#define OV7670_COM11_EXP 0x02
617#define OV7670_COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */
Jean-François Moine21867802010-11-12 06:12:09 -0300618#define OV7670_R3C_COM12 0x3c /* Control 12 */
619#define OV7670_R3D_COM13 0x3d /* Control 13 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300620#define OV7670_COM13_GAMMA 0x80 /* Gamma enable */
621#define OV7670_COM13_UVSAT 0x40 /* UV saturation auto adjustment */
Jean-François Moine21867802010-11-12 06:12:09 -0300622#define OV7670_R3E_COM14 0x3e /* Control 14 */
623#define OV7670_R3F_EDGE 0x3f /* Edge enhancement factor */
624#define OV7670_R40_COM15 0x40 /* Control 15 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300625/*#define OV7670_COM15_R00FF 0xc0 * 00 to FF */
Jean-François Moine21867802010-11-12 06:12:09 -0300626#define OV7670_R41_COM16 0x41 /* Control 16 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300627#define OV7670_COM16_AWBGAIN 0x08 /* AWB gain enable */
Jean-François Moine21867802010-11-12 06:12:09 -0300628#define OV7670_R55_BRIGHT 0x55 /* Brightness */
629#define OV7670_R56_CONTRAS 0x56 /* Contrast control */
630#define OV7670_R69_GFIX 0x69 /* Fix gain control */
631/*#define OV7670_R8C_RGB444 0x8c * RGB 444 control */
632#define OV7670_R9F_HAECC1 0x9f /* Hist AEC/AGC control 1 */
633#define OV7670_RA0_HAECC2 0xa0 /* Hist AEC/AGC control 2 */
634#define OV7670_RA5_BD50MAX 0xa5 /* 50hz banding step limit */
635#define OV7670_RA6_HAECC3 0xa6 /* Hist AEC/AGC control 3 */
636#define OV7670_RA7_HAECC4 0xa7 /* Hist AEC/AGC control 4 */
637#define OV7670_RA8_HAECC5 0xa8 /* Hist AEC/AGC control 5 */
638#define OV7670_RA9_HAECC6 0xa9 /* Hist AEC/AGC control 6 */
639#define OV7670_RAA_HAECC7 0xaa /* Hist AEC/AGC control 7 */
640#define OV7670_RAB_BD60MAX 0xab /* 60hz banding step limit */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300641
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300642struct ov_regvals {
Jean-François Moine9d1593a2010-11-11 08:04:06 -0300643 u8 reg;
644 u8 val;
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300645};
646struct ov_i2c_regvals {
Jean-François Moine9d1593a2010-11-11 08:04:06 -0300647 u8 reg;
648 u8 val;
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300649};
650
Hans de Goede635118d2009-10-11 09:49:03 -0300651/* Settings for OV2610 camera chip */
Jean-François Moine780e3122010-10-19 04:29:10 -0300652static const struct ov_i2c_regvals norm_2610[] = {
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300653 { 0x12, 0x80 }, /* reset */
Hans de Goede635118d2009-10-11 09:49:03 -0300654};
655
Jean-François Moine780e3122010-10-19 04:29:10 -0300656static const struct ov_i2c_regvals norm_3620b[] = {
Hans de Goede635118d2009-10-11 09:49:03 -0300657 /*
658 * From the datasheet: "Note that after writing to register COMH
659 * (0x12) to change the sensor mode, registers related to the
660 * sensor’s cropping window will be reset back to their default
661 * values."
662 *
663 * "wait 4096 external clock ... to make sure the sensor is
664 * stable and ready to access registers" i.e. 160us at 24MHz
665 */
Hans de Goede635118d2009-10-11 09:49:03 -0300666 { 0x12, 0x80 }, /* COMH reset */
667 { 0x12, 0x00 }, /* QXGA, master */
668
669 /*
670 * 11 CLKRC "Clock Rate Control"
671 * [7] internal frequency doublers: on
672 * [6] video port mode: master
673 * [5:0] clock divider: 1
674 */
675 { 0x11, 0x80 },
676
677 /*
678 * 13 COMI "Common Control I"
679 * = 192 (0xC0) 11000000
680 * COMI[7] "AEC speed selection"
681 * = 1 (0x01) 1....... "Faster AEC correction"
682 * COMI[6] "AEC speed step selection"
683 * = 1 (0x01) .1...... "Big steps, fast"
684 * COMI[5] "Banding filter on off"
685 * = 0 (0x00) ..0..... "Off"
686 * COMI[4] "Banding filter option"
687 * = 0 (0x00) ...0.... "Main clock is 48 MHz and
688 * the PLL is ON"
689 * COMI[3] "Reserved"
690 * = 0 (0x00) ....0...
691 * COMI[2] "AGC auto manual control selection"
692 * = 0 (0x00) .....0.. "Manual"
693 * COMI[1] "AWB auto manual control selection"
694 * = 0 (0x00) ......0. "Manual"
695 * COMI[0] "Exposure control"
696 * = 0 (0x00) .......0 "Manual"
697 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300698 { 0x13, 0xc0 },
Hans de Goede635118d2009-10-11 09:49:03 -0300699
700 /*
701 * 09 COMC "Common Control C"
702 * = 8 (0x08) 00001000
703 * COMC[7:5] "Reserved"
704 * = 0 (0x00) 000.....
705 * COMC[4] "Sleep Mode Enable"
706 * = 0 (0x00) ...0.... "Normal mode"
707 * COMC[3:2] "Sensor sampling reset timing selection"
708 * = 2 (0x02) ....10.. "Longer reset time"
709 * COMC[1:0] "Output drive current select"
710 * = 0 (0x00) ......00 "Weakest"
711 */
712 { 0x09, 0x08 },
713
714 /*
715 * 0C COMD "Common Control D"
716 * = 8 (0x08) 00001000
717 * COMD[7] "Reserved"
718 * = 0 (0x00) 0.......
719 * COMD[6] "Swap MSB and LSB at the output port"
720 * = 0 (0x00) .0...... "False"
721 * COMD[5:3] "Reserved"
722 * = 1 (0x01) ..001...
723 * COMD[2] "Output Average On Off"
724 * = 0 (0x00) .....0.. "Output Normal"
725 * COMD[1] "Sensor precharge voltage selection"
726 * = 0 (0x00) ......0. "Selects internal
727 * reference precharge
728 * voltage"
729 * COMD[0] "Snapshot option"
730 * = 0 (0x00) .......0 "Enable live video output
731 * after snapshot sequence"
732 */
733 { 0x0c, 0x08 },
734
735 /*
736 * 0D COME "Common Control E"
737 * = 161 (0xA1) 10100001
738 * COME[7] "Output average option"
739 * = 1 (0x01) 1....... "Output average of 4 pixels"
740 * COME[6] "Anti-blooming control"
741 * = 0 (0x00) .0...... "Off"
742 * COME[5:3] "Reserved"
743 * = 4 (0x04) ..100...
744 * COME[2] "Clock output power down pin status"
745 * = 0 (0x00) .....0.. "Tri-state data output pin
746 * on power down"
747 * COME[1] "Data output pin status selection at power down"
748 * = 0 (0x00) ......0. "Tri-state VSYNC, PCLK,
749 * HREF, and CHSYNC pins on
750 * power down"
751 * COME[0] "Auto zero circuit select"
752 * = 1 (0x01) .......1 "On"
753 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300754 { 0x0d, 0xa1 },
Hans de Goede635118d2009-10-11 09:49:03 -0300755
756 /*
757 * 0E COMF "Common Control F"
758 * = 112 (0x70) 01110000
759 * COMF[7] "System clock selection"
760 * = 0 (0x00) 0....... "Use 24 MHz system clock"
761 * COMF[6:4] "Reserved"
762 * = 7 (0x07) .111....
763 * COMF[3] "Manual auto negative offset canceling selection"
764 * = 0 (0x00) ....0... "Auto detect negative
765 * offset and cancel it"
766 * COMF[2:0] "Reserved"
767 * = 0 (0x00) .....000
768 */
769 { 0x0e, 0x70 },
770
771 /*
772 * 0F COMG "Common Control G"
773 * = 66 (0x42) 01000010
774 * COMG[7] "Optical black output selection"
775 * = 0 (0x00) 0....... "Disable"
776 * COMG[6] "Black level calibrate selection"
777 * = 1 (0x01) .1...... "Use optical black pixels
778 * to calibrate"
779 * COMG[5:4] "Reserved"
780 * = 0 (0x00) ..00....
781 * COMG[3] "Channel offset adjustment"
782 * = 0 (0x00) ....0... "Disable offset adjustment"
783 * COMG[2] "ADC black level calibration option"
784 * = 0 (0x00) .....0.. "Use B/G line and G/R
785 * line to calibrate each
786 * channel's black level"
787 * COMG[1] "Reserved"
788 * = 1 (0x01) ......1.
789 * COMG[0] "ADC black level calibration enable"
790 * = 0 (0x00) .......0 "Disable"
791 */
792 { 0x0f, 0x42 },
793
794 /*
795 * 14 COMJ "Common Control J"
796 * = 198 (0xC6) 11000110
797 * COMJ[7:6] "AGC gain ceiling"
798 * = 3 (0x03) 11...... "8x"
799 * COMJ[5:4] "Reserved"
800 * = 0 (0x00) ..00....
801 * COMJ[3] "Auto banding filter"
802 * = 0 (0x00) ....0... "Banding filter is always
803 * on off depending on
804 * COMI[5] setting"
805 * COMJ[2] "VSYNC drop option"
806 * = 1 (0x01) .....1.. "SYNC is dropped if frame
807 * data is dropped"
808 * COMJ[1] "Frame data drop"
809 * = 1 (0x01) ......1. "Drop frame data if
810 * exposure is not within
811 * tolerance. In AEC mode,
812 * data is normally dropped
813 * when data is out of
814 * range."
815 * COMJ[0] "Reserved"
816 * = 0 (0x00) .......0
817 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300818 { 0x14, 0xc6 },
Hans de Goede635118d2009-10-11 09:49:03 -0300819
820 /*
821 * 15 COMK "Common Control K"
822 * = 2 (0x02) 00000010
823 * COMK[7] "CHSYNC pin output swap"
824 * = 0 (0x00) 0....... "CHSYNC"
825 * COMK[6] "HREF pin output swap"
826 * = 0 (0x00) .0...... "HREF"
827 * COMK[5] "PCLK output selection"
828 * = 0 (0x00) ..0..... "PCLK always output"
829 * COMK[4] "PCLK edge selection"
830 * = 0 (0x00) ...0.... "Data valid on falling edge"
831 * COMK[3] "HREF output polarity"
832 * = 0 (0x00) ....0... "positive"
833 * COMK[2] "Reserved"
834 * = 0 (0x00) .....0..
835 * COMK[1] "VSYNC polarity"
836 * = 1 (0x01) ......1. "negative"
837 * COMK[0] "HSYNC polarity"
838 * = 0 (0x00) .......0 "positive"
839 */
840 { 0x15, 0x02 },
841
842 /*
843 * 33 CHLF "Current Control"
844 * = 9 (0x09) 00001001
845 * CHLF[7:6] "Sensor current control"
846 * = 0 (0x00) 00......
847 * CHLF[5] "Sensor current range control"
848 * = 0 (0x00) ..0..... "normal range"
849 * CHLF[4] "Sensor current"
850 * = 0 (0x00) ...0.... "normal current"
851 * CHLF[3] "Sensor buffer current control"
852 * = 1 (0x01) ....1... "half current"
853 * CHLF[2] "Column buffer current control"
854 * = 0 (0x00) .....0.. "normal current"
855 * CHLF[1] "Analog DSP current control"
856 * = 0 (0x00) ......0. "normal current"
857 * CHLF[1] "ADC current control"
858 * = 0 (0x00) ......0. "normal current"
859 */
860 { 0x33, 0x09 },
861
862 /*
863 * 34 VBLM "Blooming Control"
864 * = 80 (0x50) 01010000
865 * VBLM[7] "Hard soft reset switch"
866 * = 0 (0x00) 0....... "Hard reset"
867 * VBLM[6:4] "Blooming voltage selection"
868 * = 5 (0x05) .101....
869 * VBLM[3:0] "Sensor current control"
870 * = 0 (0x00) ....0000
871 */
872 { 0x34, 0x50 },
873
874 /*
875 * 36 VCHG "Sensor Precharge Voltage Control"
876 * = 0 (0x00) 00000000
877 * VCHG[7] "Reserved"
878 * = 0 (0x00) 0.......
879 * VCHG[6:4] "Sensor precharge voltage control"
880 * = 0 (0x00) .000....
881 * VCHG[3:0] "Sensor array common reference"
882 * = 0 (0x00) ....0000
883 */
884 { 0x36, 0x00 },
885
886 /*
887 * 37 ADC "ADC Reference Control"
888 * = 4 (0x04) 00000100
889 * ADC[7:4] "Reserved"
890 * = 0 (0x00) 0000....
891 * ADC[3] "ADC input signal range"
892 * = 0 (0x00) ....0... "Input signal 1.0x"
893 * ADC[2:0] "ADC range control"
894 * = 4 (0x04) .....100
895 */
896 { 0x37, 0x04 },
897
898 /*
899 * 38 ACOM "Analog Common Ground"
900 * = 82 (0x52) 01010010
901 * ACOM[7] "Analog gain control"
902 * = 0 (0x00) 0....... "Gain 1x"
903 * ACOM[6] "Analog black level calibration"
904 * = 1 (0x01) .1...... "On"
905 * ACOM[5:0] "Reserved"
906 * = 18 (0x12) ..010010
907 */
908 { 0x38, 0x52 },
909
910 /*
911 * 3A FREFA "Internal Reference Adjustment"
912 * = 0 (0x00) 00000000
913 * FREFA[7:0] "Range"
914 * = 0 (0x00) 00000000
915 */
916 { 0x3a, 0x00 },
917
918 /*
919 * 3C FVOPT "Internal Reference Adjustment"
920 * = 31 (0x1F) 00011111
921 * FVOPT[7:0] "Range"
922 * = 31 (0x1F) 00011111
923 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300924 { 0x3c, 0x1f },
Hans de Goede635118d2009-10-11 09:49:03 -0300925
926 /*
927 * 44 Undocumented = 0 (0x00) 00000000
928 * 44[7:0] "It's a secret"
929 * = 0 (0x00) 00000000
930 */
931 { 0x44, 0x00 },
932
933 /*
934 * 40 Undocumented = 0 (0x00) 00000000
935 * 40[7:0] "It's a secret"
936 * = 0 (0x00) 00000000
937 */
938 { 0x40, 0x00 },
939
940 /*
941 * 41 Undocumented = 0 (0x00) 00000000
942 * 41[7:0] "It's a secret"
943 * = 0 (0x00) 00000000
944 */
945 { 0x41, 0x00 },
946
947 /*
948 * 42 Undocumented = 0 (0x00) 00000000
949 * 42[7:0] "It's a secret"
950 * = 0 (0x00) 00000000
951 */
952 { 0x42, 0x00 },
953
954 /*
955 * 43 Undocumented = 0 (0x00) 00000000
956 * 43[7:0] "It's a secret"
957 * = 0 (0x00) 00000000
958 */
959 { 0x43, 0x00 },
960
961 /*
962 * 45 Undocumented = 128 (0x80) 10000000
963 * 45[7:0] "It's a secret"
964 * = 128 (0x80) 10000000
965 */
966 { 0x45, 0x80 },
967
968 /*
969 * 48 Undocumented = 192 (0xC0) 11000000
970 * 48[7:0] "It's a secret"
971 * = 192 (0xC0) 11000000
972 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300973 { 0x48, 0xc0 },
Hans de Goede635118d2009-10-11 09:49:03 -0300974
975 /*
976 * 49 Undocumented = 25 (0x19) 00011001
977 * 49[7:0] "It's a secret"
978 * = 25 (0x19) 00011001
979 */
980 { 0x49, 0x19 },
981
982 /*
983 * 4B Undocumented = 128 (0x80) 10000000
984 * 4B[7:0] "It's a secret"
985 * = 128 (0x80) 10000000
986 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300987 { 0x4b, 0x80 },
Hans de Goede635118d2009-10-11 09:49:03 -0300988
989 /*
990 * 4D Undocumented = 196 (0xC4) 11000100
991 * 4D[7:0] "It's a secret"
992 * = 196 (0xC4) 11000100
993 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300994 { 0x4d, 0xc4 },
Hans de Goede635118d2009-10-11 09:49:03 -0300995
996 /*
997 * 35 VREF "Reference Voltage Control"
Jean-François Moine87bae742010-11-12 05:31:34 -0300998 * = 76 (0x4c) 01001100
Hans de Goede635118d2009-10-11 09:49:03 -0300999 * VREF[7:5] "Column high reference control"
1000 * = 2 (0x02) 010..... "higher voltage"
1001 * VREF[4:2] "Column low reference control"
1002 * = 3 (0x03) ...011.. "Highest voltage"
1003 * VREF[1:0] "Reserved"
1004 * = 0 (0x00) ......00
1005 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001006 { 0x35, 0x4c },
Hans de Goede635118d2009-10-11 09:49:03 -03001007
1008 /*
1009 * 3D Undocumented = 0 (0x00) 00000000
1010 * 3D[7:0] "It's a secret"
1011 * = 0 (0x00) 00000000
1012 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001013 { 0x3d, 0x00 },
Hans de Goede635118d2009-10-11 09:49:03 -03001014
1015 /*
1016 * 3E Undocumented = 0 (0x00) 00000000
1017 * 3E[7:0] "It's a secret"
1018 * = 0 (0x00) 00000000
1019 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001020 { 0x3e, 0x00 },
Hans de Goede635118d2009-10-11 09:49:03 -03001021
1022 /*
1023 * 3B FREFB "Internal Reference Adjustment"
1024 * = 24 (0x18) 00011000
1025 * FREFB[7:0] "Range"
1026 * = 24 (0x18) 00011000
1027 */
1028 { 0x3b, 0x18 },
1029
1030 /*
1031 * 33 CHLF "Current Control"
1032 * = 25 (0x19) 00011001
1033 * CHLF[7:6] "Sensor current control"
1034 * = 0 (0x00) 00......
1035 * CHLF[5] "Sensor current range control"
1036 * = 0 (0x00) ..0..... "normal range"
1037 * CHLF[4] "Sensor current"
1038 * = 1 (0x01) ...1.... "double current"
1039 * CHLF[3] "Sensor buffer current control"
1040 * = 1 (0x01) ....1... "half current"
1041 * CHLF[2] "Column buffer current control"
1042 * = 0 (0x00) .....0.. "normal current"
1043 * CHLF[1] "Analog DSP current control"
1044 * = 0 (0x00) ......0. "normal current"
1045 * CHLF[1] "ADC current control"
1046 * = 0 (0x00) ......0. "normal current"
1047 */
1048 { 0x33, 0x19 },
1049
1050 /*
1051 * 34 VBLM "Blooming Control"
1052 * = 90 (0x5A) 01011010
1053 * VBLM[7] "Hard soft reset switch"
1054 * = 0 (0x00) 0....... "Hard reset"
1055 * VBLM[6:4] "Blooming voltage selection"
1056 * = 5 (0x05) .101....
1057 * VBLM[3:0] "Sensor current control"
1058 * = 10 (0x0A) ....1010
1059 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001060 { 0x34, 0x5a },
Hans de Goede635118d2009-10-11 09:49:03 -03001061
1062 /*
1063 * 3B FREFB "Internal Reference Adjustment"
1064 * = 0 (0x00) 00000000
1065 * FREFB[7:0] "Range"
1066 * = 0 (0x00) 00000000
1067 */
1068 { 0x3b, 0x00 },
1069
1070 /*
1071 * 33 CHLF "Current Control"
1072 * = 9 (0x09) 00001001
1073 * CHLF[7:6] "Sensor current control"
1074 * = 0 (0x00) 00......
1075 * CHLF[5] "Sensor current range control"
1076 * = 0 (0x00) ..0..... "normal range"
1077 * CHLF[4] "Sensor current"
1078 * = 0 (0x00) ...0.... "normal current"
1079 * CHLF[3] "Sensor buffer current control"
1080 * = 1 (0x01) ....1... "half current"
1081 * CHLF[2] "Column buffer current control"
1082 * = 0 (0x00) .....0.. "normal current"
1083 * CHLF[1] "Analog DSP current control"
1084 * = 0 (0x00) ......0. "normal current"
1085 * CHLF[1] "ADC current control"
1086 * = 0 (0x00) ......0. "normal current"
1087 */
1088 { 0x33, 0x09 },
1089
1090 /*
1091 * 34 VBLM "Blooming Control"
1092 * = 80 (0x50) 01010000
1093 * VBLM[7] "Hard soft reset switch"
1094 * = 0 (0x00) 0....... "Hard reset"
1095 * VBLM[6:4] "Blooming voltage selection"
1096 * = 5 (0x05) .101....
1097 * VBLM[3:0] "Sensor current control"
1098 * = 0 (0x00) ....0000
1099 */
1100 { 0x34, 0x50 },
1101
1102 /*
1103 * 12 COMH "Common Control H"
1104 * = 64 (0x40) 01000000
1105 * COMH[7] "SRST"
1106 * = 0 (0x00) 0....... "No-op"
1107 * COMH[6:4] "Resolution selection"
1108 * = 4 (0x04) .100.... "XGA"
1109 * COMH[3] "Master slave selection"
1110 * = 0 (0x00) ....0... "Master mode"
1111 * COMH[2] "Internal B/R channel option"
1112 * = 0 (0x00) .....0.. "B/R use same channel"
1113 * COMH[1] "Color bar test pattern"
1114 * = 0 (0x00) ......0. "Off"
1115 * COMH[0] "Reserved"
1116 * = 0 (0x00) .......0
1117 */
1118 { 0x12, 0x40 },
1119
1120 /*
1121 * 17 HREFST "Horizontal window start"
1122 * = 31 (0x1F) 00011111
1123 * HREFST[7:0] "Horizontal window start, 8 MSBs"
1124 * = 31 (0x1F) 00011111
1125 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001126 { 0x17, 0x1f },
Hans de Goede635118d2009-10-11 09:49:03 -03001127
1128 /*
1129 * 18 HREFEND "Horizontal window end"
1130 * = 95 (0x5F) 01011111
1131 * HREFEND[7:0] "Horizontal Window End, 8 MSBs"
1132 * = 95 (0x5F) 01011111
1133 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001134 { 0x18, 0x5f },
Hans de Goede635118d2009-10-11 09:49:03 -03001135
1136 /*
1137 * 19 VSTRT "Vertical window start"
1138 * = 0 (0x00) 00000000
1139 * VSTRT[7:0] "Vertical Window Start, 8 MSBs"
1140 * = 0 (0x00) 00000000
1141 */
1142 { 0x19, 0x00 },
1143
1144 /*
1145 * 1A VEND "Vertical window end"
1146 * = 96 (0x60) 01100000
1147 * VEND[7:0] "Vertical Window End, 8 MSBs"
1148 * = 96 (0x60) 01100000
1149 */
1150 { 0x1a, 0x60 },
1151
1152 /*
1153 * 32 COMM "Common Control M"
1154 * = 18 (0x12) 00010010
1155 * COMM[7:6] "Pixel clock divide option"
1156 * = 0 (0x00) 00...... "/1"
1157 * COMM[5:3] "Horizontal window end position, 3 LSBs"
1158 * = 2 (0x02) ..010...
1159 * COMM[2:0] "Horizontal window start position, 3 LSBs"
1160 * = 2 (0x02) .....010
1161 */
1162 { 0x32, 0x12 },
1163
1164 /*
1165 * 03 COMA "Common Control A"
1166 * = 74 (0x4A) 01001010
1167 * COMA[7:4] "AWB Update Threshold"
1168 * = 4 (0x04) 0100....
1169 * COMA[3:2] "Vertical window end line control 2 LSBs"
1170 * = 2 (0x02) ....10..
1171 * COMA[1:0] "Vertical window start line control 2 LSBs"
1172 * = 2 (0x02) ......10
1173 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001174 { 0x03, 0x4a },
Hans de Goede635118d2009-10-11 09:49:03 -03001175
1176 /*
1177 * 11 CLKRC "Clock Rate Control"
1178 * = 128 (0x80) 10000000
1179 * CLKRC[7] "Internal frequency doublers on off seclection"
1180 * = 1 (0x01) 1....... "On"
1181 * CLKRC[6] "Digital video master slave selection"
1182 * = 0 (0x00) .0...... "Master mode, sensor
1183 * provides PCLK"
1184 * CLKRC[5:0] "Clock divider { CLK = PCLK/(1+CLKRC[5:0]) }"
1185 * = 0 (0x00) ..000000
1186 */
1187 { 0x11, 0x80 },
1188
1189 /*
1190 * 12 COMH "Common Control H"
1191 * = 0 (0x00) 00000000
1192 * COMH[7] "SRST"
1193 * = 0 (0x00) 0....... "No-op"
1194 * COMH[6:4] "Resolution selection"
1195 * = 0 (0x00) .000.... "QXGA"
1196 * COMH[3] "Master slave selection"
1197 * = 0 (0x00) ....0... "Master mode"
1198 * COMH[2] "Internal B/R channel option"
1199 * = 0 (0x00) .....0.. "B/R use same channel"
1200 * COMH[1] "Color bar test pattern"
1201 * = 0 (0x00) ......0. "Off"
1202 * COMH[0] "Reserved"
1203 * = 0 (0x00) .......0
1204 */
1205 { 0x12, 0x00 },
1206
1207 /*
1208 * 12 COMH "Common Control H"
1209 * = 64 (0x40) 01000000
1210 * COMH[7] "SRST"
1211 * = 0 (0x00) 0....... "No-op"
1212 * COMH[6:4] "Resolution selection"
1213 * = 4 (0x04) .100.... "XGA"
1214 * COMH[3] "Master slave selection"
1215 * = 0 (0x00) ....0... "Master mode"
1216 * COMH[2] "Internal B/R channel option"
1217 * = 0 (0x00) .....0.. "B/R use same channel"
1218 * COMH[1] "Color bar test pattern"
1219 * = 0 (0x00) ......0. "Off"
1220 * COMH[0] "Reserved"
1221 * = 0 (0x00) .......0
1222 */
1223 { 0x12, 0x40 },
1224
1225 /*
1226 * 17 HREFST "Horizontal window start"
1227 * = 31 (0x1F) 00011111
1228 * HREFST[7:0] "Horizontal window start, 8 MSBs"
1229 * = 31 (0x1F) 00011111
1230 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001231 { 0x17, 0x1f },
Hans de Goede635118d2009-10-11 09:49:03 -03001232
1233 /*
1234 * 18 HREFEND "Horizontal window end"
1235 * = 95 (0x5F) 01011111
1236 * HREFEND[7:0] "Horizontal Window End, 8 MSBs"
1237 * = 95 (0x5F) 01011111
1238 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001239 { 0x18, 0x5f },
Hans de Goede635118d2009-10-11 09:49:03 -03001240
1241 /*
1242 * 19 VSTRT "Vertical window start"
1243 * = 0 (0x00) 00000000
1244 * VSTRT[7:0] "Vertical Window Start, 8 MSBs"
1245 * = 0 (0x00) 00000000
1246 */
1247 { 0x19, 0x00 },
1248
1249 /*
1250 * 1A VEND "Vertical window end"
1251 * = 96 (0x60) 01100000
1252 * VEND[7:0] "Vertical Window End, 8 MSBs"
1253 * = 96 (0x60) 01100000
1254 */
1255 { 0x1a, 0x60 },
1256
1257 /*
1258 * 32 COMM "Common Control M"
1259 * = 18 (0x12) 00010010
1260 * COMM[7:6] "Pixel clock divide option"
1261 * = 0 (0x00) 00...... "/1"
1262 * COMM[5:3] "Horizontal window end position, 3 LSBs"
1263 * = 2 (0x02) ..010...
1264 * COMM[2:0] "Horizontal window start position, 3 LSBs"
1265 * = 2 (0x02) .....010
1266 */
1267 { 0x32, 0x12 },
1268
1269 /*
1270 * 03 COMA "Common Control A"
1271 * = 74 (0x4A) 01001010
1272 * COMA[7:4] "AWB Update Threshold"
1273 * = 4 (0x04) 0100....
1274 * COMA[3:2] "Vertical window end line control 2 LSBs"
1275 * = 2 (0x02) ....10..
1276 * COMA[1:0] "Vertical window start line control 2 LSBs"
1277 * = 2 (0x02) ......10
1278 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001279 { 0x03, 0x4a },
Hans de Goede635118d2009-10-11 09:49:03 -03001280
1281 /*
1282 * 02 RED "Red Gain Control"
1283 * = 175 (0xAF) 10101111
1284 * RED[7] "Action"
1285 * = 1 (0x01) 1....... "gain = 1/(1+bitrev([6:0]))"
1286 * RED[6:0] "Value"
1287 * = 47 (0x2F) .0101111
1288 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001289 { 0x02, 0xaf },
Hans de Goede635118d2009-10-11 09:49:03 -03001290
1291 /*
1292 * 2D ADDVSL "VSYNC Pulse Width"
1293 * = 210 (0xD2) 11010010
1294 * ADDVSL[7:0] "VSYNC pulse width, LSB"
1295 * = 210 (0xD2) 11010010
1296 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001297 { 0x2d, 0xd2 },
Hans de Goede635118d2009-10-11 09:49:03 -03001298
1299 /*
1300 * 00 GAIN = 24 (0x18) 00011000
1301 * GAIN[7:6] "Reserved"
1302 * = 0 (0x00) 00......
1303 * GAIN[5] "Double"
1304 * = 0 (0x00) ..0..... "False"
1305 * GAIN[4] "Double"
1306 * = 1 (0x01) ...1.... "True"
1307 * GAIN[3:0] "Range"
1308 * = 8 (0x08) ....1000
1309 */
1310 { 0x00, 0x18 },
1311
1312 /*
1313 * 01 BLUE "Blue Gain Control"
1314 * = 240 (0xF0) 11110000
1315 * BLUE[7] "Action"
1316 * = 1 (0x01) 1....... "gain = 1/(1+bitrev([6:0]))"
1317 * BLUE[6:0] "Value"
1318 * = 112 (0x70) .1110000
1319 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001320 { 0x01, 0xf0 },
Hans de Goede635118d2009-10-11 09:49:03 -03001321
1322 /*
1323 * 10 AEC "Automatic Exposure Control"
1324 * = 10 (0x0A) 00001010
1325 * AEC[7:0] "Automatic Exposure Control, 8 MSBs"
1326 * = 10 (0x0A) 00001010
1327 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001328 { 0x10, 0x0a },
Hans de Goede635118d2009-10-11 09:49:03 -03001329
Jean-François Moine87bae742010-11-12 05:31:34 -03001330 { 0xe1, 0x67 },
1331 { 0xe3, 0x03 },
1332 { 0xe4, 0x26 },
1333 { 0xe5, 0x3e },
1334 { 0xf8, 0x01 },
1335 { 0xff, 0x01 },
Hans de Goede635118d2009-10-11 09:49:03 -03001336};
1337
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001338static const struct ov_i2c_regvals norm_6x20[] = {
1339 { 0x12, 0x80 }, /* reset */
1340 { 0x11, 0x01 },
1341 { 0x03, 0x60 },
1342 { 0x05, 0x7f }, /* For when autoadjust is off */
1343 { 0x07, 0xa8 },
Jean-François Moine87bae742010-11-12 05:31:34 -03001344 /* The ratio of 0x0c and 0x0d controls the white point */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001345 { 0x0c, 0x24 },
1346 { 0x0d, 0x24 },
1347 { 0x0f, 0x15 }, /* COMS */
1348 { 0x10, 0x75 }, /* AEC Exposure time */
1349 { 0x12, 0x24 }, /* Enable AGC */
1350 { 0x14, 0x04 },
1351 /* 0x16: 0x06 helps frame stability with moving objects */
1352 { 0x16, 0x06 },
1353/* { 0x20, 0x30 }, * Aperture correction enable */
1354 { 0x26, 0xb2 }, /* BLC enable */
1355 /* 0x28: 0x05 Selects RGB format if RGB on */
1356 { 0x28, 0x05 },
1357 { 0x2a, 0x04 }, /* Disable framerate adjust */
1358/* { 0x2b, 0xac }, * Framerate; Set 2a[7] first */
Hans de Goedeae49c402009-06-14 19:15:07 -03001359 { 0x2d, 0x85 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001360 { 0x33, 0xa0 }, /* Color Processing Parameter */
1361 { 0x34, 0xd2 }, /* Max A/D range */
1362 { 0x38, 0x8b },
1363 { 0x39, 0x40 },
1364
1365 { 0x3c, 0x39 }, /* Enable AEC mode changing */
1366 { 0x3c, 0x3c }, /* Change AEC mode */
1367 { 0x3c, 0x24 }, /* Disable AEC mode changing */
1368
1369 { 0x3d, 0x80 },
1370 /* These next two registers (0x4a, 0x4b) are undocumented.
1371 * They control the color balance */
1372 { 0x4a, 0x80 },
1373 { 0x4b, 0x80 },
1374 { 0x4d, 0xd2 }, /* This reduces noise a bit */
1375 { 0x4e, 0xc1 },
1376 { 0x4f, 0x04 },
1377/* Do 50-53 have any effect? */
1378/* Toggle 0x12[2] off and on here? */
1379};
1380
1381static const struct ov_i2c_regvals norm_6x30[] = {
1382 { 0x12, 0x80 }, /* Reset */
1383 { 0x00, 0x1f }, /* Gain */
1384 { 0x01, 0x99 }, /* Blue gain */
1385 { 0x02, 0x7c }, /* Red gain */
1386 { 0x03, 0xc0 }, /* Saturation */
1387 { 0x05, 0x0a }, /* Contrast */
1388 { 0x06, 0x95 }, /* Brightness */
1389 { 0x07, 0x2d }, /* Sharpness */
1390 { 0x0c, 0x20 },
1391 { 0x0d, 0x20 },
Hans de Goede02ab18b2009-06-14 04:32:04 -03001392 { 0x0e, 0xa0 }, /* Was 0x20, bit7 enables a 2x gain which we need */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001393 { 0x0f, 0x05 },
1394 { 0x10, 0x9a },
1395 { 0x11, 0x00 }, /* Pixel clock = fastest */
1396 { 0x12, 0x24 }, /* Enable AGC and AWB */
1397 { 0x13, 0x21 },
1398 { 0x14, 0x80 },
1399 { 0x15, 0x01 },
1400 { 0x16, 0x03 },
1401 { 0x17, 0x38 },
1402 { 0x18, 0xea },
1403 { 0x19, 0x04 },
1404 { 0x1a, 0x93 },
1405 { 0x1b, 0x00 },
1406 { 0x1e, 0xc4 },
1407 { 0x1f, 0x04 },
1408 { 0x20, 0x20 },
1409 { 0x21, 0x10 },
1410 { 0x22, 0x88 },
1411 { 0x23, 0xc0 }, /* Crystal circuit power level */
1412 { 0x25, 0x9a }, /* Increase AEC black ratio */
1413 { 0x26, 0xb2 }, /* BLC enable */
1414 { 0x27, 0xa2 },
1415 { 0x28, 0x00 },
1416 { 0x29, 0x00 },
1417 { 0x2a, 0x84 }, /* 60 Hz power */
1418 { 0x2b, 0xa8 }, /* 60 Hz power */
1419 { 0x2c, 0xa0 },
1420 { 0x2d, 0x95 }, /* Enable auto-brightness */
1421 { 0x2e, 0x88 },
1422 { 0x33, 0x26 },
1423 { 0x34, 0x03 },
1424 { 0x36, 0x8f },
1425 { 0x37, 0x80 },
1426 { 0x38, 0x83 },
1427 { 0x39, 0x80 },
1428 { 0x3a, 0x0f },
1429 { 0x3b, 0x3c },
1430 { 0x3c, 0x1a },
1431 { 0x3d, 0x80 },
1432 { 0x3e, 0x80 },
1433 { 0x3f, 0x0e },
1434 { 0x40, 0x00 }, /* White bal */
1435 { 0x41, 0x00 }, /* White bal */
1436 { 0x42, 0x80 },
1437 { 0x43, 0x3f }, /* White bal */
1438 { 0x44, 0x80 },
1439 { 0x45, 0x20 },
1440 { 0x46, 0x20 },
1441 { 0x47, 0x80 },
1442 { 0x48, 0x7f },
1443 { 0x49, 0x00 },
1444 { 0x4a, 0x00 },
1445 { 0x4b, 0x80 },
1446 { 0x4c, 0xd0 },
1447 { 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
1448 { 0x4e, 0x40 },
1449 { 0x4f, 0x07 }, /* UV avg., col. killer: max */
1450 { 0x50, 0xff },
1451 { 0x54, 0x23 }, /* Max AGC gain: 18dB */
1452 { 0x55, 0xff },
1453 { 0x56, 0x12 },
1454 { 0x57, 0x81 },
1455 { 0x58, 0x75 },
1456 { 0x59, 0x01 }, /* AGC dark current comp.: +1 */
1457 { 0x5a, 0x2c },
1458 { 0x5b, 0x0f }, /* AWB chrominance levels */
1459 { 0x5c, 0x10 },
1460 { 0x3d, 0x80 },
1461 { 0x27, 0xa6 },
1462 { 0x12, 0x20 }, /* Toggle AWB */
1463 { 0x12, 0x24 },
1464};
1465
1466/* Lawrence Glaister <lg@jfm.bc.ca> reports:
1467 *
1468 * Register 0x0f in the 7610 has the following effects:
1469 *
1470 * 0x85 (AEC method 1): Best overall, good contrast range
1471 * 0x45 (AEC method 2): Very overexposed
1472 * 0xa5 (spec sheet default): Ok, but the black level is
1473 * shifted resulting in loss of contrast
1474 * 0x05 (old driver setting): very overexposed, too much
1475 * contrast
1476 */
1477static const struct ov_i2c_regvals norm_7610[] = {
1478 { 0x10, 0xff },
1479 { 0x16, 0x06 },
1480 { 0x28, 0x24 },
1481 { 0x2b, 0xac },
1482 { 0x12, 0x00 },
1483 { 0x38, 0x81 },
1484 { 0x28, 0x24 }, /* 0c */
1485 { 0x0f, 0x85 }, /* lg's setting */
1486 { 0x15, 0x01 },
1487 { 0x20, 0x1c },
1488 { 0x23, 0x2a },
1489 { 0x24, 0x10 },
1490 { 0x25, 0x8a },
1491 { 0x26, 0xa2 },
1492 { 0x27, 0xc2 },
1493 { 0x2a, 0x04 },
1494 { 0x2c, 0xfe },
1495 { 0x2d, 0x93 },
1496 { 0x30, 0x71 },
1497 { 0x31, 0x60 },
1498 { 0x32, 0x26 },
1499 { 0x33, 0x20 },
1500 { 0x34, 0x48 },
1501 { 0x12, 0x24 },
1502 { 0x11, 0x01 },
1503 { 0x0c, 0x24 },
1504 { 0x0d, 0x24 },
1505};
1506
1507static const struct ov_i2c_regvals norm_7620[] = {
Hans de Goedea511ba92009-10-16 07:13:07 -03001508 { 0x12, 0x80 }, /* reset */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001509 { 0x00, 0x00 }, /* gain */
1510 { 0x01, 0x80 }, /* blue gain */
1511 { 0x02, 0x80 }, /* red gain */
Jean-François Moine21867802010-11-12 06:12:09 -03001512 { 0x03, 0xc0 }, /* OV7670_R03_VREF */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001513 { 0x06, 0x60 },
1514 { 0x07, 0x00 },
1515 { 0x0c, 0x24 },
1516 { 0x0c, 0x24 },
1517 { 0x0d, 0x24 },
1518 { 0x11, 0x01 },
1519 { 0x12, 0x24 },
1520 { 0x13, 0x01 },
1521 { 0x14, 0x84 },
1522 { 0x15, 0x01 },
1523 { 0x16, 0x03 },
1524 { 0x17, 0x2f },
1525 { 0x18, 0xcf },
1526 { 0x19, 0x06 },
1527 { 0x1a, 0xf5 },
1528 { 0x1b, 0x00 },
1529 { 0x20, 0x18 },
1530 { 0x21, 0x80 },
1531 { 0x22, 0x80 },
1532 { 0x23, 0x00 },
1533 { 0x26, 0xa2 },
1534 { 0x27, 0xea },
Hans de Goedeb282d872009-06-14 19:10:40 -03001535 { 0x28, 0x22 }, /* Was 0x20, bit1 enables a 2x gain which we need */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001536 { 0x29, 0x00 },
1537 { 0x2a, 0x10 },
1538 { 0x2b, 0x00 },
1539 { 0x2c, 0x88 },
1540 { 0x2d, 0x91 },
1541 { 0x2e, 0x80 },
1542 { 0x2f, 0x44 },
1543 { 0x60, 0x27 },
1544 { 0x61, 0x02 },
1545 { 0x62, 0x5f },
1546 { 0x63, 0xd5 },
1547 { 0x64, 0x57 },
1548 { 0x65, 0x83 },
1549 { 0x66, 0x55 },
1550 { 0x67, 0x92 },
1551 { 0x68, 0xcf },
1552 { 0x69, 0x76 },
1553 { 0x6a, 0x22 },
1554 { 0x6b, 0x00 },
1555 { 0x6c, 0x02 },
1556 { 0x6d, 0x44 },
1557 { 0x6e, 0x80 },
1558 { 0x6f, 0x1d },
1559 { 0x70, 0x8b },
1560 { 0x71, 0x00 },
1561 { 0x72, 0x14 },
1562 { 0x73, 0x54 },
1563 { 0x74, 0x00 },
1564 { 0x75, 0x8e },
1565 { 0x76, 0x00 },
1566 { 0x77, 0xff },
1567 { 0x78, 0x80 },
1568 { 0x79, 0x80 },
1569 { 0x7a, 0x80 },
1570 { 0x7b, 0xe2 },
1571 { 0x7c, 0x00 },
1572};
1573
1574/* 7640 and 7648. The defaults should be OK for most registers. */
1575static const struct ov_i2c_regvals norm_7640[] = {
1576 { 0x12, 0x80 },
1577 { 0x12, 0x14 },
1578};
1579
1580/* 7670. Defaults taken from OmniVision provided data,
1581* as provided by Jonathan Corbet of OLPC */
1582static const struct ov_i2c_regvals norm_7670[] = {
Jean-François Moine21867802010-11-12 06:12:09 -03001583 { OV7670_R12_COM7, OV7670_COM7_RESET },
1584 { OV7670_R3A_TSLB, 0x04 }, /* OV */
1585 { OV7670_R12_COM7, OV7670_COM7_FMT_VGA }, /* VGA */
1586 { OV7670_R11_CLKRC, 0x01 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001587/*
1588 * Set the hardware window. These values from OV don't entirely
1589 * make sense - hstop is less than hstart. But they work...
1590 */
Jean-François Moine21867802010-11-12 06:12:09 -03001591 { OV7670_R17_HSTART, 0x13 },
1592 { OV7670_R18_HSTOP, 0x01 },
1593 { OV7670_R32_HREF, 0xb6 },
1594 { OV7670_R19_VSTART, 0x02 },
1595 { OV7670_R1A_VSTOP, 0x7a },
1596 { OV7670_R03_VREF, 0x0a },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001597
Jean-François Moine21867802010-11-12 06:12:09 -03001598 { OV7670_R0C_COM3, 0x00 },
1599 { OV7670_R3E_COM14, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001600/* Mystery scaling numbers */
1601 { 0x70, 0x3a },
1602 { 0x71, 0x35 },
1603 { 0x72, 0x11 },
1604 { 0x73, 0xf0 },
1605 { 0xa2, 0x02 },
Jean-François Moine21867802010-11-12 06:12:09 -03001606/* { OV7670_R15_COM10, 0x0 }, */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001607
1608/* Gamma curve values */
1609 { 0x7a, 0x20 },
1610 { 0x7b, 0x10 },
1611 { 0x7c, 0x1e },
1612 { 0x7d, 0x35 },
1613 { 0x7e, 0x5a },
1614 { 0x7f, 0x69 },
1615 { 0x80, 0x76 },
1616 { 0x81, 0x80 },
1617 { 0x82, 0x88 },
1618 { 0x83, 0x8f },
1619 { 0x84, 0x96 },
1620 { 0x85, 0xa3 },
1621 { 0x86, 0xaf },
1622 { 0x87, 0xc4 },
1623 { 0x88, 0xd7 },
1624 { 0x89, 0xe8 },
1625
1626/* AGC and AEC parameters. Note we start by disabling those features,
1627 then turn them only after tweaking the values. */
Jean-François Moine21867802010-11-12 06:12:09 -03001628 { OV7670_R13_COM8, OV7670_COM8_FASTAEC
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001629 | OV7670_COM8_AECSTEP
1630 | OV7670_COM8_BFILT },
Jean-François Moine21867802010-11-12 06:12:09 -03001631 { OV7670_R00_GAIN, 0x00 },
1632 { OV7670_R10_AECH, 0x00 },
1633 { OV7670_R0D_COM4, 0x40 }, /* magic reserved bit */
1634 { OV7670_R14_COM9, 0x18 }, /* 4x gain + magic rsvd bit */
1635 { OV7670_RA5_BD50MAX, 0x05 },
1636 { OV7670_RAB_BD60MAX, 0x07 },
1637 { OV7670_R24_AEW, 0x95 },
1638 { OV7670_R25_AEB, 0x33 },
1639 { OV7670_R26_VPT, 0xe3 },
1640 { OV7670_R9F_HAECC1, 0x78 },
1641 { OV7670_RA0_HAECC2, 0x68 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001642 { 0xa1, 0x03 }, /* magic */
Jean-François Moine21867802010-11-12 06:12:09 -03001643 { OV7670_RA6_HAECC3, 0xd8 },
1644 { OV7670_RA7_HAECC4, 0xd8 },
1645 { OV7670_RA8_HAECC5, 0xf0 },
1646 { OV7670_RA9_HAECC6, 0x90 },
1647 { OV7670_RAA_HAECC7, 0x94 },
1648 { OV7670_R13_COM8, OV7670_COM8_FASTAEC
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001649 | OV7670_COM8_AECSTEP
1650 | OV7670_COM8_BFILT
1651 | OV7670_COM8_AGC
1652 | OV7670_COM8_AEC },
1653
1654/* Almost all of these are magic "reserved" values. */
Jean-François Moine21867802010-11-12 06:12:09 -03001655 { OV7670_R0E_COM5, 0x61 },
1656 { OV7670_R0F_COM6, 0x4b },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001657 { 0x16, 0x02 },
Jean-François Moine21867802010-11-12 06:12:09 -03001658 { OV7670_R1E_MVFP, 0x07 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001659 { 0x21, 0x02 },
1660 { 0x22, 0x91 },
1661 { 0x29, 0x07 },
1662 { 0x33, 0x0b },
1663 { 0x35, 0x0b },
1664 { 0x37, 0x1d },
1665 { 0x38, 0x71 },
1666 { 0x39, 0x2a },
Jean-François Moine21867802010-11-12 06:12:09 -03001667 { OV7670_R3C_COM12, 0x78 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001668 { 0x4d, 0x40 },
1669 { 0x4e, 0x20 },
Jean-François Moine21867802010-11-12 06:12:09 -03001670 { OV7670_R69_GFIX, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001671 { 0x6b, 0x4a },
1672 { 0x74, 0x10 },
1673 { 0x8d, 0x4f },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001674 { 0x8e, 0x00 },
1675 { 0x8f, 0x00 },
1676 { 0x90, 0x00 },
1677 { 0x91, 0x00 },
1678 { 0x96, 0x00 },
1679 { 0x9a, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001680 { 0xb0, 0x84 },
1681 { 0xb1, 0x0c },
1682 { 0xb2, 0x0e },
1683 { 0xb3, 0x82 },
1684 { 0xb8, 0x0a },
1685
1686/* More reserved magic, some of which tweaks white balance */
1687 { 0x43, 0x0a },
1688 { 0x44, 0xf0 },
1689 { 0x45, 0x34 },
1690 { 0x46, 0x58 },
1691 { 0x47, 0x28 },
1692 { 0x48, 0x3a },
1693 { 0x59, 0x88 },
1694 { 0x5a, 0x88 },
1695 { 0x5b, 0x44 },
1696 { 0x5c, 0x67 },
1697 { 0x5d, 0x49 },
1698 { 0x5e, 0x0e },
1699 { 0x6c, 0x0a },
1700 { 0x6d, 0x55 },
1701 { 0x6e, 0x11 },
1702 { 0x6f, 0x9f },
1703 /* "9e for advance AWB" */
1704 { 0x6a, 0x40 },
Jean-François Moine21867802010-11-12 06:12:09 -03001705 { OV7670_R01_BLUE, 0x40 },
1706 { OV7670_R02_RED, 0x60 },
1707 { OV7670_R13_COM8, OV7670_COM8_FASTAEC
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001708 | OV7670_COM8_AECSTEP
1709 | OV7670_COM8_BFILT
1710 | OV7670_COM8_AGC
1711 | OV7670_COM8_AEC
1712 | OV7670_COM8_AWB },
1713
1714/* Matrix coefficients */
1715 { 0x4f, 0x80 },
1716 { 0x50, 0x80 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001717 { 0x51, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001718 { 0x52, 0x22 },
1719 { 0x53, 0x5e },
1720 { 0x54, 0x80 },
1721 { 0x58, 0x9e },
1722
Jean-François Moine21867802010-11-12 06:12:09 -03001723 { OV7670_R41_COM16, OV7670_COM16_AWBGAIN },
1724 { OV7670_R3F_EDGE, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001725 { 0x75, 0x05 },
1726 { 0x76, 0xe1 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001727 { 0x4c, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001728 { 0x77, 0x01 },
Jean-François Moine21867802010-11-12 06:12:09 -03001729 { OV7670_R3D_COM13, OV7670_COM13_GAMMA
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001730 | OV7670_COM13_UVSAT
1731 | 2}, /* was 3 */
1732 { 0x4b, 0x09 },
1733 { 0xc9, 0x60 },
Jean-François Moine21867802010-11-12 06:12:09 -03001734 { OV7670_R41_COM16, 0x38 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001735 { 0x56, 0x40 },
1736
1737 { 0x34, 0x11 },
Jean-François Moine21867802010-11-12 06:12:09 -03001738 { OV7670_R3B_COM11, OV7670_COM11_EXP|OV7670_COM11_HZAUTO },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001739 { 0xa4, 0x88 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001740 { 0x96, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001741 { 0x97, 0x30 },
1742 { 0x98, 0x20 },
1743 { 0x99, 0x30 },
1744 { 0x9a, 0x84 },
1745 { 0x9b, 0x29 },
1746 { 0x9c, 0x03 },
1747 { 0x9d, 0x4c },
1748 { 0x9e, 0x3f },
1749 { 0x78, 0x04 },
1750
1751/* Extra-weird stuff. Some sort of multiplexor register */
1752 { 0x79, 0x01 },
1753 { 0xc8, 0xf0 },
1754 { 0x79, 0x0f },
1755 { 0xc8, 0x00 },
1756 { 0x79, 0x10 },
1757 { 0xc8, 0x7e },
1758 { 0x79, 0x0a },
1759 { 0xc8, 0x80 },
1760 { 0x79, 0x0b },
1761 { 0xc8, 0x01 },
1762 { 0x79, 0x0c },
1763 { 0xc8, 0x0f },
1764 { 0x79, 0x0d },
1765 { 0xc8, 0x20 },
1766 { 0x79, 0x09 },
1767 { 0xc8, 0x80 },
1768 { 0x79, 0x02 },
1769 { 0xc8, 0xc0 },
1770 { 0x79, 0x03 },
1771 { 0xc8, 0x40 },
1772 { 0x79, 0x05 },
1773 { 0xc8, 0x30 },
1774 { 0x79, 0x26 },
1775};
1776
1777static const struct ov_i2c_regvals norm_8610[] = {
1778 { 0x12, 0x80 },
1779 { 0x00, 0x00 },
1780 { 0x01, 0x80 },
1781 { 0x02, 0x80 },
1782 { 0x03, 0xc0 },
1783 { 0x04, 0x30 },
1784 { 0x05, 0x30 }, /* was 0x10, new from windrv 090403 */
1785 { 0x06, 0x70 }, /* was 0x80, new from windrv 090403 */
1786 { 0x0a, 0x86 },
1787 { 0x0b, 0xb0 },
1788 { 0x0c, 0x20 },
1789 { 0x0d, 0x20 },
1790 { 0x11, 0x01 },
1791 { 0x12, 0x25 },
1792 { 0x13, 0x01 },
1793 { 0x14, 0x04 },
1794 { 0x15, 0x01 }, /* Lin and Win think different about UV order */
1795 { 0x16, 0x03 },
1796 { 0x17, 0x38 }, /* was 0x2f, new from windrv 090403 */
1797 { 0x18, 0xea }, /* was 0xcf, new from windrv 090403 */
1798 { 0x19, 0x02 }, /* was 0x06, new from windrv 090403 */
1799 { 0x1a, 0xf5 },
1800 { 0x1b, 0x00 },
1801 { 0x20, 0xd0 }, /* was 0x90, new from windrv 090403 */
1802 { 0x23, 0xc0 }, /* was 0x00, new from windrv 090403 */
1803 { 0x24, 0x30 }, /* was 0x1d, new from windrv 090403 */
1804 { 0x25, 0x50 }, /* was 0x57, new from windrv 090403 */
1805 { 0x26, 0xa2 },
1806 { 0x27, 0xea },
1807 { 0x28, 0x00 },
1808 { 0x29, 0x00 },
1809 { 0x2a, 0x80 },
1810 { 0x2b, 0xc8 }, /* was 0xcc, new from windrv 090403 */
1811 { 0x2c, 0xac },
1812 { 0x2d, 0x45 }, /* was 0xd5, new from windrv 090403 */
1813 { 0x2e, 0x80 },
1814 { 0x2f, 0x14 }, /* was 0x01, new from windrv 090403 */
1815 { 0x4c, 0x00 },
1816 { 0x4d, 0x30 }, /* was 0x10, new from windrv 090403 */
1817 { 0x60, 0x02 }, /* was 0x01, new from windrv 090403 */
1818 { 0x61, 0x00 }, /* was 0x09, new from windrv 090403 */
1819 { 0x62, 0x5f }, /* was 0xd7, new from windrv 090403 */
1820 { 0x63, 0xff },
1821 { 0x64, 0x53 }, /* new windrv 090403 says 0x57,
1822 * maybe thats wrong */
1823 { 0x65, 0x00 },
1824 { 0x66, 0x55 },
1825 { 0x67, 0xb0 },
1826 { 0x68, 0xc0 }, /* was 0xaf, new from windrv 090403 */
1827 { 0x69, 0x02 },
1828 { 0x6a, 0x22 },
1829 { 0x6b, 0x00 },
1830 { 0x6c, 0x99 }, /* was 0x80, old windrv says 0x00, but
1831 * deleting bit7 colors the first images red */
1832 { 0x6d, 0x11 }, /* was 0x00, new from windrv 090403 */
1833 { 0x6e, 0x11 }, /* was 0x00, new from windrv 090403 */
1834 { 0x6f, 0x01 },
1835 { 0x70, 0x8b },
1836 { 0x71, 0x00 },
1837 { 0x72, 0x14 },
1838 { 0x73, 0x54 },
1839 { 0x74, 0x00 },/* 0x60? - was 0x00, new from windrv 090403 */
1840 { 0x75, 0x0e },
1841 { 0x76, 0x02 }, /* was 0x02, new from windrv 090403 */
1842 { 0x77, 0xff },
1843 { 0x78, 0x80 },
1844 { 0x79, 0x80 },
1845 { 0x7a, 0x80 },
1846 { 0x7b, 0x10 }, /* was 0x13, new from windrv 090403 */
1847 { 0x7c, 0x00 },
1848 { 0x7d, 0x08 }, /* was 0x09, new from windrv 090403 */
1849 { 0x7e, 0x08 }, /* was 0xc0, new from windrv 090403 */
1850 { 0x7f, 0xfb },
1851 { 0x80, 0x28 },
1852 { 0x81, 0x00 },
1853 { 0x82, 0x23 },
1854 { 0x83, 0x0b },
1855 { 0x84, 0x00 },
1856 { 0x85, 0x62 }, /* was 0x61, new from windrv 090403 */
1857 { 0x86, 0xc9 },
1858 { 0x87, 0x00 },
1859 { 0x88, 0x00 },
1860 { 0x89, 0x01 },
1861 { 0x12, 0x20 },
1862 { 0x12, 0x25 }, /* was 0x24, new from windrv 090403 */
1863};
1864
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001865static unsigned char ov7670_abs_to_sm(unsigned char v)
1866{
1867 if (v > 127)
1868 return v & 0x7f;
1869 return (128 - v) | 0x80;
1870}
1871
1872/* Write a OV519 register */
Jean-François Moinef8f20182010-11-12 07:54:02 -03001873static void reg_w(struct sd *sd, u16 index, u16 value)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001874{
Hans de Goedea511ba92009-10-16 07:13:07 -03001875 int ret, req = 0;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001876
Jean-François Moinef8f20182010-11-12 07:54:02 -03001877 if (sd->gspca_dev.usb_err < 0)
1878 return;
1879
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001880 switch (sd->bridge) {
1881 case BRIDGE_OV511:
1882 case BRIDGE_OV511PLUS:
1883 req = 2;
1884 break;
1885 case BRIDGE_OVFX2:
Hans de Goedea511ba92009-10-16 07:13:07 -03001886 req = 0x0a;
1887 /* fall through */
1888 case BRIDGE_W9968CF:
Jean-François Moine858ea5e2010-11-12 13:53:10 -03001889 PDEBUG(D_USBO, "SET %02x %04x %04x",
1890 req, value, index);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001891 ret = usb_control_msg(sd->gspca_dev.dev,
1892 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
Hans de Goedea511ba92009-10-16 07:13:07 -03001893 req,
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001894 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Hans de Goedea511ba92009-10-16 07:13:07 -03001895 value, index, NULL, 0, 500);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001896 goto leave;
1897 default:
1898 req = 1;
1899 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001900
Jean-François Moine858ea5e2010-11-12 13:53:10 -03001901 PDEBUG(D_USBO, "SET %02x 0000 %04x %02x",
1902 req, index, value);
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001903 sd->gspca_dev.usb_buf[0] = value;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001904 ret = usb_control_msg(sd->gspca_dev.dev,
1905 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
Hans de Goede49809d62009-06-07 12:10:39 -03001906 req,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001907 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1908 0, index,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001909 sd->gspca_dev.usb_buf, 1, 500);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001910leave:
Hans de Goedea511ba92009-10-16 07:13:07 -03001911 if (ret < 0) {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03001912 err("reg_w %02x failed %d", index, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03001913 sd->gspca_dev.usb_err = ret;
1914 return;
Hans de Goedea511ba92009-10-16 07:13:07 -03001915 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001916}
1917
Hans de Goedea511ba92009-10-16 07:13:07 -03001918/* Read from a OV519 register, note not valid for the w9968cf!! */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001919/* returns: negative is error, pos or zero is data */
Jean-François Moine9d1593a2010-11-11 08:04:06 -03001920static int reg_r(struct sd *sd, u16 index)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001921{
1922 int ret;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001923 int req;
1924
Jean-François Moinef8f20182010-11-12 07:54:02 -03001925 if (sd->gspca_dev.usb_err < 0)
1926 return -1;
1927
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001928 switch (sd->bridge) {
1929 case BRIDGE_OV511:
1930 case BRIDGE_OV511PLUS:
1931 req = 3;
1932 break;
1933 case BRIDGE_OVFX2:
1934 req = 0x0b;
1935 break;
1936 default:
1937 req = 1;
1938 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001939
1940 ret = usb_control_msg(sd->gspca_dev.dev,
1941 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
Hans de Goede49809d62009-06-07 12:10:39 -03001942 req,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001943 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001944 0, index, sd->gspca_dev.usb_buf, 1, 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001945
Hans de Goedea511ba92009-10-16 07:13:07 -03001946 if (ret >= 0) {
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001947 ret = sd->gspca_dev.usb_buf[0];
Jean-François Moine858ea5e2010-11-12 13:53:10 -03001948 PDEBUG(D_USBI, "GET %02x 0000 %04x %02x",
1949 req, index, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03001950 } else {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03001951 err("reg_r %02x failed %d", index, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03001952 sd->gspca_dev.usb_err = ret;
1953 }
Hans de Goedea511ba92009-10-16 07:13:07 -03001954
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001955 return ret;
1956}
1957
1958/* Read 8 values from a OV519 register */
1959static int reg_r8(struct sd *sd,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03001960 u16 index)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001961{
1962 int ret;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001963
Jean-François Moinef8f20182010-11-12 07:54:02 -03001964 if (sd->gspca_dev.usb_err < 0)
1965 return -1;
1966
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001967 ret = usb_control_msg(sd->gspca_dev.dev,
1968 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
1969 1, /* REQ_IO */
1970 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001971 0, index, sd->gspca_dev.usb_buf, 8, 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001972
Jean-François Moinef8f20182010-11-12 07:54:02 -03001973 if (ret >= 0) {
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001974 ret = sd->gspca_dev.usb_buf[0];
Jean-François Moinef8f20182010-11-12 07:54:02 -03001975 } else {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03001976 err("reg_r8 %02x failed %d", index, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03001977 sd->gspca_dev.usb_err = ret;
1978 }
Hans de Goedea511ba92009-10-16 07:13:07 -03001979
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001980 return ret;
1981}
1982
1983/*
1984 * Writes bits at positions specified by mask to an OV51x reg. Bits that are in
1985 * the same position as 1's in "mask" are cleared and set to "value". Bits
1986 * that are in the same position as 0's in "mask" are preserved, regardless
1987 * of their respective state in "value".
1988 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03001989static void reg_w_mask(struct sd *sd,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03001990 u16 index,
1991 u8 value,
1992 u8 mask)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001993{
1994 int ret;
Jean-François Moine9d1593a2010-11-11 08:04:06 -03001995 u8 oldval;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001996
1997 if (mask != 0xff) {
1998 value &= mask; /* Enforce mask on value */
1999 ret = reg_r(sd, index);
2000 if (ret < 0)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002001 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002002
2003 oldval = ret & ~mask; /* Clear the masked bits */
2004 value |= oldval; /* Set the desired bits */
2005 }
Jean-François Moinef8f20182010-11-12 07:54:02 -03002006 reg_w(sd, index, value);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002007}
2008
2009/*
Hans de Goede49809d62009-06-07 12:10:39 -03002010 * Writes multiple (n) byte value to a single register. Only valid with certain
2011 * registers (0x30 and 0xc4 - 0xce).
2012 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002013static void ov518_reg_w32(struct sd *sd, u16 index, u32 value, int n)
Hans de Goede49809d62009-06-07 12:10:39 -03002014{
2015 int ret;
2016
Jean-François Moinef8f20182010-11-12 07:54:02 -03002017 if (sd->gspca_dev.usb_err < 0)
2018 return;
2019
Jean-Francois Moine83955552009-12-12 06:58:01 -03002020 *((__le32 *) sd->gspca_dev.usb_buf) = __cpu_to_le32(value);
Hans de Goede49809d62009-06-07 12:10:39 -03002021
2022 ret = usb_control_msg(sd->gspca_dev.dev,
2023 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
2024 1 /* REG_IO */,
2025 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2026 0, index,
2027 sd->gspca_dev.usb_buf, n, 500);
Hans de Goedea511ba92009-10-16 07:13:07 -03002028 if (ret < 0) {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002029 err("reg_w32 %02x failed %d", index, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002030 sd->gspca_dev.usb_err = ret;
Hans de Goedea511ba92009-10-16 07:13:07 -03002031 }
Hans de Goede49809d62009-06-07 12:10:39 -03002032}
2033
Jean-François Moinef8f20182010-11-12 07:54:02 -03002034static void ov511_i2c_w(struct sd *sd, u8 reg, u8 value)
Hans de Goede1876bb92009-06-14 06:45:50 -03002035{
2036 int rc, retries;
2037
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002038 PDEBUG(D_USBO, "ov511_i2c_w %02x %02x", reg, value);
Hans de Goede1876bb92009-06-14 06:45:50 -03002039
2040 /* Three byte write cycle */
2041 for (retries = 6; ; ) {
2042 /* Select camera register */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002043 reg_w(sd, R51x_I2C_SADDR_3, reg);
Hans de Goede1876bb92009-06-14 06:45:50 -03002044
2045 /* Write "value" to I2C data port of OV511 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002046 reg_w(sd, R51x_I2C_DATA, value);
Hans de Goede1876bb92009-06-14 06:45:50 -03002047
2048 /* Initiate 3-byte write cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002049 reg_w(sd, R511_I2C_CTL, 0x01);
Hans de Goede1876bb92009-06-14 06:45:50 -03002050
Jean-Francois Moine83955552009-12-12 06:58:01 -03002051 do {
Hans de Goede1876bb92009-06-14 06:45:50 -03002052 rc = reg_r(sd, R511_I2C_CTL);
Jean-Francois Moine83955552009-12-12 06:58:01 -03002053 } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
Hans de Goede1876bb92009-06-14 06:45:50 -03002054
2055 if (rc < 0)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002056 return;
Hans de Goede1876bb92009-06-14 06:45:50 -03002057
2058 if ((rc & 2) == 0) /* Ack? */
2059 break;
2060 if (--retries < 0) {
2061 PDEBUG(D_USBO, "i2c write retries exhausted");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002062 return;
Hans de Goede1876bb92009-06-14 06:45:50 -03002063 }
2064 }
Hans de Goede1876bb92009-06-14 06:45:50 -03002065}
2066
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002067static int ov511_i2c_r(struct sd *sd, u8 reg)
Hans de Goede1876bb92009-06-14 06:45:50 -03002068{
2069 int rc, value, retries;
2070
2071 /* Two byte write cycle */
2072 for (retries = 6; ; ) {
2073 /* Select camera register */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002074 reg_w(sd, R51x_I2C_SADDR_2, reg);
Hans de Goede1876bb92009-06-14 06:45:50 -03002075
2076 /* Initiate 2-byte write cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002077 reg_w(sd, R511_I2C_CTL, 0x03);
Hans de Goede1876bb92009-06-14 06:45:50 -03002078
Jean-Francois Moine83955552009-12-12 06:58:01 -03002079 do {
Hans de Goede1876bb92009-06-14 06:45:50 -03002080 rc = reg_r(sd, R511_I2C_CTL);
Jean-Francois Moine83955552009-12-12 06:58:01 -03002081 } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
Hans de Goede1876bb92009-06-14 06:45:50 -03002082
2083 if (rc < 0)
2084 return rc;
2085
2086 if ((rc & 2) == 0) /* Ack? */
2087 break;
2088
2089 /* I2C abort */
2090 reg_w(sd, R511_I2C_CTL, 0x10);
2091
2092 if (--retries < 0) {
2093 PDEBUG(D_USBI, "i2c write retries exhausted");
2094 return -1;
2095 }
2096 }
2097
2098 /* Two byte read cycle */
2099 for (retries = 6; ; ) {
2100 /* Initiate 2-byte read cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002101 reg_w(sd, R511_I2C_CTL, 0x05);
Hans de Goede1876bb92009-06-14 06:45:50 -03002102
Jean-Francois Moine83955552009-12-12 06:58:01 -03002103 do {
Hans de Goede1876bb92009-06-14 06:45:50 -03002104 rc = reg_r(sd, R511_I2C_CTL);
Jean-Francois Moine83955552009-12-12 06:58:01 -03002105 } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
Hans de Goede1876bb92009-06-14 06:45:50 -03002106
2107 if (rc < 0)
2108 return rc;
2109
2110 if ((rc & 2) == 0) /* Ack? */
2111 break;
2112
2113 /* I2C abort */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002114 reg_w(sd, R511_I2C_CTL, 0x10);
Hans de Goede1876bb92009-06-14 06:45:50 -03002115
2116 if (--retries < 0) {
2117 PDEBUG(D_USBI, "i2c read retries exhausted");
2118 return -1;
2119 }
2120 }
2121
2122 value = reg_r(sd, R51x_I2C_DATA);
2123
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002124 PDEBUG(D_USBI, "ov511_i2c_r %02x %02x", reg, value);
Hans de Goede1876bb92009-06-14 06:45:50 -03002125
2126 /* This is needed to make i2c_w() work */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002127 reg_w(sd, R511_I2C_CTL, 0x05);
Hans de Goede1876bb92009-06-14 06:45:50 -03002128
2129 return value;
2130}
Hans de Goede49809d62009-06-07 12:10:39 -03002131
2132/*
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002133 * The OV518 I2C I/O procedure is different, hence, this function.
2134 * This is normally only called from i2c_w(). Note that this function
2135 * always succeeds regardless of whether the sensor is present and working.
2136 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002137static void ov518_i2c_w(struct sd *sd,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002138 u8 reg,
2139 u8 value)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002140{
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002141 PDEBUG(D_USBO, "ov518_i2c_w %02x %02x", reg, value);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002142
2143 /* Select camera register */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002144 reg_w(sd, R51x_I2C_SADDR_3, reg);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002145
2146 /* Write "value" to I2C data port of OV511 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002147 reg_w(sd, R51x_I2C_DATA, value);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002148
2149 /* Initiate 3-byte write cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002150 reg_w(sd, R518_I2C_CTL, 0x01);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002151
2152 /* wait for write complete */
2153 msleep(4);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002154 reg_r8(sd, R518_I2C_CTL);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002155}
2156
2157/*
2158 * returns: negative is error, pos or zero is data
2159 *
2160 * The OV518 I2C I/O procedure is different, hence, this function.
2161 * This is normally only called from i2c_r(). Note that this function
2162 * always succeeds regardless of whether the sensor is present and working.
2163 */
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002164static int ov518_i2c_r(struct sd *sd, u8 reg)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002165{
Jean-François Moinef8f20182010-11-12 07:54:02 -03002166 int value;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002167
2168 /* Select camera register */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002169 reg_w(sd, R51x_I2C_SADDR_2, reg);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002170
2171 /* Initiate 2-byte write cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002172 reg_w(sd, R518_I2C_CTL, 0x03);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002173
2174 /* Initiate 2-byte read cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002175 reg_w(sd, R518_I2C_CTL, 0x05);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002176 value = reg_r(sd, R51x_I2C_DATA);
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002177 PDEBUG(D_USBI, "ov518_i2c_r %02x %02x", reg, value);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002178 return value;
2179}
2180
Jean-François Moinef8f20182010-11-12 07:54:02 -03002181static void ovfx2_i2c_w(struct sd *sd, u8 reg, u8 value)
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002182{
2183 int ret;
2184
Jean-François Moinef8f20182010-11-12 07:54:02 -03002185 if (sd->gspca_dev.usb_err < 0)
2186 return;
2187
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002188 ret = usb_control_msg(sd->gspca_dev.dev,
2189 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
2190 0x02,
2191 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002192 (u16) value, (u16) reg, NULL, 0, 500);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002193
Hans de Goedea511ba92009-10-16 07:13:07 -03002194 if (ret < 0) {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002195 err("ovfx2_i2c_w %02x failed %d", reg, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002196 sd->gspca_dev.usb_err = ret;
Hans de Goedea511ba92009-10-16 07:13:07 -03002197 }
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002198
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002199 PDEBUG(D_USBO, "ovfx2_i2c_w %02x %02x", reg, value);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002200}
2201
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002202static int ovfx2_i2c_r(struct sd *sd, u8 reg)
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002203{
2204 int ret;
2205
Jean-François Moinef8f20182010-11-12 07:54:02 -03002206 if (sd->gspca_dev.usb_err < 0)
2207 return -1;
2208
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002209 ret = usb_control_msg(sd->gspca_dev.dev,
2210 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
2211 0x03,
2212 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002213 0, (u16) reg, sd->gspca_dev.usb_buf, 1, 500);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002214
2215 if (ret >= 0) {
2216 ret = sd->gspca_dev.usb_buf[0];
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002217 PDEBUG(D_USBI, "ovfx2_i2c_r %02x %02x", reg, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002218 } else {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002219 err("ovfx2_i2c_r %02x failed %d", reg, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002220 sd->gspca_dev.usb_err = ret;
2221 }
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002222
2223 return ret;
2224}
2225
Jean-François Moinef8f20182010-11-12 07:54:02 -03002226static void i2c_w(struct sd *sd, u8 reg, u8 value)
Hans de Goede1876bb92009-06-14 06:45:50 -03002227{
Hans de Goedefb1f9022009-10-16 07:42:53 -03002228 if (sd->sensor_reg_cache[reg] == value)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002229 return;
Hans de Goedefb1f9022009-10-16 07:42:53 -03002230
Hans de Goede1876bb92009-06-14 06:45:50 -03002231 switch (sd->bridge) {
2232 case BRIDGE_OV511:
2233 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002234 ov511_i2c_w(sd, reg, value);
Hans de Goedefb1f9022009-10-16 07:42:53 -03002235 break;
Hans de Goede1876bb92009-06-14 06:45:50 -03002236 case BRIDGE_OV518:
2237 case BRIDGE_OV518PLUS:
2238 case BRIDGE_OV519:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002239 ov518_i2c_w(sd, reg, value);
Hans de Goedefb1f9022009-10-16 07:42:53 -03002240 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002241 case BRIDGE_OVFX2:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002242 ovfx2_i2c_w(sd, reg, value);
Hans de Goedefb1f9022009-10-16 07:42:53 -03002243 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03002244 case BRIDGE_W9968CF:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002245 w9968cf_i2c_w(sd, reg, value);
Hans de Goedefb1f9022009-10-16 07:42:53 -03002246 break;
Hans de Goede1876bb92009-06-14 06:45:50 -03002247 }
Hans de Goedefb1f9022009-10-16 07:42:53 -03002248
Jean-François Moinef8f20182010-11-12 07:54:02 -03002249 if (sd->gspca_dev.usb_err >= 0) {
Hans de Goedefb1f9022009-10-16 07:42:53 -03002250 /* Up on sensor reset empty the register cache */
2251 if (reg == 0x12 && (value & 0x80))
2252 memset(sd->sensor_reg_cache, -1,
Jean-François Moine87bae742010-11-12 05:31:34 -03002253 sizeof(sd->sensor_reg_cache));
Hans de Goedefb1f9022009-10-16 07:42:53 -03002254 else
2255 sd->sensor_reg_cache[reg] = value;
2256 }
Hans de Goede1876bb92009-06-14 06:45:50 -03002257}
2258
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002259static int i2c_r(struct sd *sd, u8 reg)
Hans de Goede1876bb92009-06-14 06:45:50 -03002260{
Hans de Goede8394bcf2009-10-16 11:26:22 -03002261 int ret = -1;
Hans de Goedefb1f9022009-10-16 07:42:53 -03002262
2263 if (sd->sensor_reg_cache[reg] != -1)
2264 return sd->sensor_reg_cache[reg];
2265
Hans de Goede1876bb92009-06-14 06:45:50 -03002266 switch (sd->bridge) {
2267 case BRIDGE_OV511:
2268 case BRIDGE_OV511PLUS:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002269 ret = ov511_i2c_r(sd, reg);
2270 break;
Hans de Goede1876bb92009-06-14 06:45:50 -03002271 case BRIDGE_OV518:
2272 case BRIDGE_OV518PLUS:
2273 case BRIDGE_OV519:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002274 ret = ov518_i2c_r(sd, reg);
2275 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002276 case BRIDGE_OVFX2:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002277 ret = ovfx2_i2c_r(sd, reg);
2278 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03002279 case BRIDGE_W9968CF:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002280 ret = w9968cf_i2c_r(sd, reg);
2281 break;
Hans de Goede1876bb92009-06-14 06:45:50 -03002282 }
Hans de Goedefb1f9022009-10-16 07:42:53 -03002283
2284 if (ret >= 0)
2285 sd->sensor_reg_cache[reg] = ret;
2286
2287 return ret;
Hans de Goede1876bb92009-06-14 06:45:50 -03002288}
2289
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002290/* Writes bits at positions specified by mask to an I2C reg. Bits that are in
2291 * the same position as 1's in "mask" are cleared and set to "value". Bits
2292 * that are in the same position as 0's in "mask" are preserved, regardless
2293 * of their respective state in "value".
2294 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002295static void i2c_w_mask(struct sd *sd,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002296 u8 reg,
2297 u8 value,
2298 u8 mask)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002299{
2300 int rc;
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002301 u8 oldval;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002302
2303 value &= mask; /* Enforce mask on value */
2304 rc = i2c_r(sd, reg);
2305 if (rc < 0)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002306 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002307 oldval = rc & ~mask; /* Clear the masked bits */
2308 value |= oldval; /* Set the desired bits */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002309 i2c_w(sd, reg, value);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002310}
2311
2312/* Temporarily stops OV511 from functioning. Must do this before changing
2313 * registers while the camera is streaming */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002314static inline void ov51x_stop(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002315{
2316 PDEBUG(D_STREAM, "stopping");
2317 sd->stopped = 1;
Hans de Goede49809d62009-06-07 12:10:39 -03002318 switch (sd->bridge) {
2319 case BRIDGE_OV511:
2320 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002321 reg_w(sd, R51x_SYS_RESET, 0x3d);
2322 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002323 case BRIDGE_OV518:
2324 case BRIDGE_OV518PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002325 reg_w_mask(sd, R51x_SYS_RESET, 0x3a, 0x3a);
2326 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002327 case BRIDGE_OV519:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002328 reg_w(sd, OV519_R51_RESET1, 0x0f);
Jean-François Moine5927abc2010-11-12 15:32:29 -03002329 reg_w(sd, OV519_R51_RESET1, 0x00);
2330 reg_w(sd, 0x22, 0x00); /* FRAR */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002331 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002332 case BRIDGE_OVFX2:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002333 reg_w_mask(sd, 0x0f, 0x00, 0x02);
2334 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03002335 case BRIDGE_W9968CF:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002336 reg_w(sd, 0x3c, 0x0a05); /* stop USB transfer */
2337 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002338 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002339}
2340
2341/* Restarts OV511 after ov511_stop() is called. Has no effect if it is not
2342 * actually stopped (for performance). */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002343static inline void ov51x_restart(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002344{
2345 PDEBUG(D_STREAM, "restarting");
2346 if (!sd->stopped)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002347 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002348 sd->stopped = 0;
2349
2350 /* Reinitialize the stream */
Hans de Goede49809d62009-06-07 12:10:39 -03002351 switch (sd->bridge) {
2352 case BRIDGE_OV511:
2353 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002354 reg_w(sd, R51x_SYS_RESET, 0x00);
2355 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002356 case BRIDGE_OV518:
2357 case BRIDGE_OV518PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002358 reg_w(sd, 0x2f, 0x80);
2359 reg_w(sd, R51x_SYS_RESET, 0x00);
2360 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002361 case BRIDGE_OV519:
Jean-François Moine5927abc2010-11-12 15:32:29 -03002362 reg_w(sd, OV519_R51_RESET1, 0x0f);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002363 reg_w(sd, OV519_R51_RESET1, 0x00);
Jean-François Moine5927abc2010-11-12 15:32:29 -03002364 reg_w(sd, 0x22, 0x1d); /* FRAR */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002365 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002366 case BRIDGE_OVFX2:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002367 reg_w_mask(sd, 0x0f, 0x02, 0x02);
2368 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03002369 case BRIDGE_W9968CF:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002370 reg_w(sd, 0x3c, 0x8a05); /* USB FIFO enable */
2371 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002372 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002373}
2374
Jean-François Moinef8f20182010-11-12 07:54:02 -03002375static void ov51x_set_slave_ids(struct sd *sd, u8 slave);
Hans de Goede229bb7d2009-10-11 07:41:46 -03002376
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002377/* This does an initial reset of an OmniVision sensor and ensures that I2C
2378 * is synchronized. Returns <0 on failure.
2379 */
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002380static int init_ov_sensor(struct sd *sd, u8 slave)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002381{
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002382 int i;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002383
Jean-François Moinef8f20182010-11-12 07:54:02 -03002384 ov51x_set_slave_ids(sd, slave);
Hans de Goede229bb7d2009-10-11 07:41:46 -03002385
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002386 /* Reset the sensor */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002387 i2c_w(sd, 0x12, 0x80);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002388
2389 /* Wait for it to initialize */
2390 msleep(150);
2391
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002392 for (i = 0; i < i2c_detect_tries; i++) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002393 if (i2c_r(sd, OV7610_REG_ID_HIGH) == 0x7f &&
2394 i2c_r(sd, OV7610_REG_ID_LOW) == 0xa2) {
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002395 PDEBUG(D_PROBE, "I2C synced in %d attempt(s)", i);
2396 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002397 }
2398
2399 /* Reset the sensor */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002400 i2c_w(sd, 0x12, 0x80);
2401
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002402 /* Wait for it to initialize */
2403 msleep(150);
Jean-François Moine87bae742010-11-12 05:31:34 -03002404
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002405 /* Dummy read to sync I2C */
2406 if (i2c_r(sd, 0x00) < 0)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002407 return -1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002408 }
Jean-François Moinef8f20182010-11-12 07:54:02 -03002409 return -1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002410}
2411
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002412/* Set the read and write slave IDs. The "slave" argument is the write slave,
2413 * and the read slave will be set to (slave + 1).
2414 * This should not be called from outside the i2c I/O functions.
2415 * Sets I2C read and write slave IDs. Returns <0 for error
2416 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002417static void ov51x_set_slave_ids(struct sd *sd,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002418 u8 slave)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002419{
Hans de Goedea511ba92009-10-16 07:13:07 -03002420 switch (sd->bridge) {
2421 case BRIDGE_OVFX2:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002422 reg_w(sd, OVFX2_I2C_ADDR, slave);
2423 return;
Hans de Goedea511ba92009-10-16 07:13:07 -03002424 case BRIDGE_W9968CF:
2425 sd->sensor_addr = slave;
Jean-François Moinef8f20182010-11-12 07:54:02 -03002426 return;
Hans de Goedea511ba92009-10-16 07:13:07 -03002427 }
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002428
Jean-François Moinef8f20182010-11-12 07:54:02 -03002429 reg_w(sd, R51x_I2C_W_SID, slave);
2430 reg_w(sd, R51x_I2C_R_SID, slave + 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002431}
2432
Jean-François Moinef8f20182010-11-12 07:54:02 -03002433static void write_regvals(struct sd *sd,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002434 const struct ov_regvals *regvals,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002435 int n)
2436{
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002437 while (--n >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03002438 reg_w(sd, regvals->reg, regvals->val);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002439 regvals++;
2440 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002441}
2442
Jean-François Moinef8f20182010-11-12 07:54:02 -03002443static void write_i2c_regvals(struct sd *sd,
2444 const struct ov_i2c_regvals *regvals,
2445 int n)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002446{
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002447 while (--n >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03002448 i2c_w(sd, regvals->reg, regvals->val);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002449 regvals++;
2450 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002451}
2452
2453/****************************************************************************
2454 *
2455 * OV511 and sensor configuration
2456 *
2457 ***************************************************************************/
2458
Hans de Goede635118d2009-10-11 09:49:03 -03002459/* This initializes the OV2x10 / OV3610 / OV3620 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002460static void ov_hires_configure(struct sd *sd)
Hans de Goede635118d2009-10-11 09:49:03 -03002461{
2462 int high, low;
2463
2464 if (sd->bridge != BRIDGE_OVFX2) {
Jean-François Moine0b656322010-09-13 05:19:58 -03002465 err("error hires sensors only supported with ovfx2");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002466 return;
Hans de Goede635118d2009-10-11 09:49:03 -03002467 }
2468
2469 PDEBUG(D_PROBE, "starting ov hires configuration");
2470
2471 /* Detect sensor (sub)type */
2472 high = i2c_r(sd, 0x0a);
2473 low = i2c_r(sd, 0x0b);
2474 /* info("%x, %x", high, low); */
2475 if (high == 0x96 && low == 0x40) {
2476 PDEBUG(D_PROBE, "Sensor is an OV2610");
2477 sd->sensor = SEN_OV2610;
2478 } else if (high == 0x36 && (low & 0x0f) == 0x00) {
2479 PDEBUG(D_PROBE, "Sensor is an OV3610");
2480 sd->sensor = SEN_OV3610;
2481 } else {
Jean-François Moine858ea5e2010-11-12 13:53:10 -03002482 err("Error unknown sensor type: %02x%02x",
Jean-François Moine87bae742010-11-12 05:31:34 -03002483 high, low);
Hans de Goede635118d2009-10-11 09:49:03 -03002484 }
Hans de Goede635118d2009-10-11 09:49:03 -03002485}
2486
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002487/* This initializes the OV8110, OV8610 sensor. The OV8110 uses
2488 * the same register settings as the OV8610, since they are very similar.
2489 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002490static void ov8xx0_configure(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002491{
2492 int rc;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002493
2494 PDEBUG(D_PROBE, "starting ov8xx0 configuration");
2495
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002496 /* Detect sensor (sub)type */
2497 rc = i2c_r(sd, OV7610_REG_COM_I);
2498 if (rc < 0) {
2499 PDEBUG(D_ERR, "Error detecting sensor type");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002500 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002501 }
Jean-François Moinef8f20182010-11-12 07:54:02 -03002502 if ((rc & 3) == 1)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002503 sd->sensor = SEN_OV8610;
Jean-François Moinef8f20182010-11-12 07:54:02 -03002504 else
Jean-François Moine0b656322010-09-13 05:19:58 -03002505 err("Unknown image sensor version: %d", rc & 3);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002506}
2507
2508/* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
2509 * the same register settings as the OV7610, since they are very similar.
2510 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002511static void ov7xx0_configure(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002512{
2513 int rc, high, low;
2514
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002515 PDEBUG(D_PROBE, "starting OV7xx0 configuration");
2516
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002517 /* Detect sensor (sub)type */
2518 rc = i2c_r(sd, OV7610_REG_COM_I);
2519
2520 /* add OV7670 here
2521 * it appears to be wrongly detected as a 7610 by default */
2522 if (rc < 0) {
2523 PDEBUG(D_ERR, "Error detecting sensor type");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002524 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002525 }
2526 if ((rc & 3) == 3) {
2527 /* quick hack to make OV7670s work */
2528 high = i2c_r(sd, 0x0a);
2529 low = i2c_r(sd, 0x0b);
2530 /* info("%x, %x", high, low); */
2531 if (high == 0x76 && low == 0x73) {
2532 PDEBUG(D_PROBE, "Sensor is an OV7670");
2533 sd->sensor = SEN_OV7670;
2534 } else {
2535 PDEBUG(D_PROBE, "Sensor is an OV7610");
2536 sd->sensor = SEN_OV7610;
2537 }
2538 } else if ((rc & 3) == 1) {
2539 /* I don't know what's different about the 76BE yet. */
Hans de Goedeb282d872009-06-14 19:10:40 -03002540 if (i2c_r(sd, 0x15) & 1) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002541 PDEBUG(D_PROBE, "Sensor is an OV7620AE");
Hans de Goede859cc472010-01-07 15:42:35 -03002542 sd->sensor = SEN_OV7620AE;
Hans de Goedeb282d872009-06-14 19:10:40 -03002543 } else {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002544 PDEBUG(D_PROBE, "Sensor is an OV76BE");
Hans de Goedeb282d872009-06-14 19:10:40 -03002545 sd->sensor = SEN_OV76BE;
2546 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002547 } else if ((rc & 3) == 0) {
2548 /* try to read product id registers */
2549 high = i2c_r(sd, 0x0a);
2550 if (high < 0) {
2551 PDEBUG(D_ERR, "Error detecting camera chip PID");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002552 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002553 }
2554 low = i2c_r(sd, 0x0b);
2555 if (low < 0) {
2556 PDEBUG(D_ERR, "Error detecting camera chip VER");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002557 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002558 }
2559 if (high == 0x76) {
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002560 switch (low) {
2561 case 0x30:
Jean-François Moine0b656322010-09-13 05:19:58 -03002562 err("Sensor is an OV7630/OV7635");
2563 err("7630 is not supported by this driver");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002564 return;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002565 case 0x40:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002566 PDEBUG(D_PROBE, "Sensor is an OV7645");
2567 sd->sensor = SEN_OV7640; /* FIXME */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002568 break;
2569 case 0x45:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002570 PDEBUG(D_PROBE, "Sensor is an OV7645B");
2571 sd->sensor = SEN_OV7640; /* FIXME */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002572 break;
2573 case 0x48:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002574 PDEBUG(D_PROBE, "Sensor is an OV7648");
Hans de Goede035d3a32010-01-09 08:14:43 -03002575 sd->sensor = SEN_OV7648;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002576 break;
2577 default:
2578 PDEBUG(D_PROBE, "Unknown sensor: 0x76%x", low);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002579 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002580 }
2581 } else {
2582 PDEBUG(D_PROBE, "Sensor is an OV7620");
2583 sd->sensor = SEN_OV7620;
2584 }
2585 } else {
Jean-François Moine0b656322010-09-13 05:19:58 -03002586 err("Unknown image sensor version: %d", rc & 3);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002587 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002588}
2589
2590/* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002591static void ov6xx0_configure(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002592{
2593 int rc;
Jean-Francois Moine4202f712008-09-03 17:12:15 -03002594 PDEBUG(D_PROBE, "starting OV6xx0 configuration");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002595
2596 /* Detect sensor (sub)type */
2597 rc = i2c_r(sd, OV7610_REG_COM_I);
2598 if (rc < 0) {
2599 PDEBUG(D_ERR, "Error detecting sensor type");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002600 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002601 }
2602
2603 /* Ugh. The first two bits are the version bits, but
2604 * the entire register value must be used. I guess OVT
2605 * underestimated how many variants they would make. */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002606 switch (rc) {
2607 case 0x00:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002608 sd->sensor = SEN_OV6630;
Jean-François Moine0b656322010-09-13 05:19:58 -03002609 warn("WARNING: Sensor is an OV66308. Your camera may have");
2610 warn("been misdetected in previous driver versions.");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002611 break;
2612 case 0x01:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002613 sd->sensor = SEN_OV6620;
Hans de Goede7d971372009-06-14 05:28:17 -03002614 PDEBUG(D_PROBE, "Sensor is an OV6620");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002615 break;
2616 case 0x02:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002617 sd->sensor = SEN_OV6630;
2618 PDEBUG(D_PROBE, "Sensor is an OV66308AE");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002619 break;
2620 case 0x03:
Hans de Goede7d971372009-06-14 05:28:17 -03002621 sd->sensor = SEN_OV66308AF;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002622 PDEBUG(D_PROBE, "Sensor is an OV66308AF");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002623 break;
2624 case 0x90:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002625 sd->sensor = SEN_OV6630;
Jean-François Moine0b656322010-09-13 05:19:58 -03002626 warn("WARNING: Sensor is an OV66307. Your camera may have");
2627 warn("been misdetected in previous driver versions.");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002628 break;
2629 default:
Jean-François Moine0b656322010-09-13 05:19:58 -03002630 err("FATAL: Unknown sensor version: 0x%02x", rc);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002631 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002632 }
2633
2634 /* Set sensor-specific vars */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002635 sd->sif = 1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002636}
2637
2638/* Turns on or off the LED. Only has an effect with OV511+/OV518(+)/OV519 */
2639static void ov51x_led_control(struct sd *sd, int on)
2640{
Hans de Goede9e4d8252009-06-14 06:25:06 -03002641 if (sd->invert_led)
2642 on = !on;
2643
Hans de Goede49809d62009-06-07 12:10:39 -03002644 switch (sd->bridge) {
2645 /* OV511 has no LED control */
2646 case BRIDGE_OV511PLUS:
Jean-François Moinea23acec2010-11-12 15:07:35 -03002647 reg_w(sd, R511_SYS_LED_CTL, on);
Hans de Goede49809d62009-06-07 12:10:39 -03002648 break;
2649 case BRIDGE_OV518:
2650 case BRIDGE_OV518PLUS:
Jean-François Moinea23acec2010-11-12 15:07:35 -03002651 reg_w_mask(sd, R518_GPIO_OUT, 0x02 * on, 0x02);
Hans de Goede49809d62009-06-07 12:10:39 -03002652 break;
2653 case BRIDGE_OV519:
Jean-François Moinea23acec2010-11-12 15:07:35 -03002654 reg_w_mask(sd, OV519_GPIO_DATA_OUT0, on, 1);
Hans de Goede49809d62009-06-07 12:10:39 -03002655 break;
2656 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002657}
2658
Hans de Goede417a4d22010-02-19 07:37:08 -03002659static void sd_reset_snapshot(struct gspca_dev *gspca_dev)
2660{
2661 struct sd *sd = (struct sd *) gspca_dev;
2662
2663 if (!sd->snapshot_needs_reset)
2664 return;
2665
2666 /* Note it is important that we clear sd->snapshot_needs_reset,
2667 before actually clearing the snapshot state in the bridge
2668 otherwise we might race with the pkt_scan interrupt handler */
2669 sd->snapshot_needs_reset = 0;
2670
2671 switch (sd->bridge) {
Hans de Goede88e8d202010-02-20 04:45:49 -03002672 case BRIDGE_OV511:
2673 case BRIDGE_OV511PLUS:
2674 reg_w(sd, R51x_SYS_SNAP, 0x02);
2675 reg_w(sd, R51x_SYS_SNAP, 0x00);
2676 break;
Hans de Goede92e232a2010-02-20 04:30:45 -03002677 case BRIDGE_OV518:
2678 case BRIDGE_OV518PLUS:
2679 reg_w(sd, R51x_SYS_SNAP, 0x02); /* Reset */
2680 reg_w(sd, R51x_SYS_SNAP, 0x01); /* Enable */
2681 break;
Hans de Goede417a4d22010-02-19 07:37:08 -03002682 case BRIDGE_OV519:
2683 reg_w(sd, R51x_SYS_RESET, 0x40);
2684 reg_w(sd, R51x_SYS_RESET, 0x00);
2685 break;
2686 }
2687}
2688
Jean-François Moinef8f20182010-11-12 07:54:02 -03002689static void ov51x_upload_quan_tables(struct sd *sd)
Hans de Goede49809d62009-06-07 12:10:39 -03002690{
Hans de Goede1876bb92009-06-14 06:45:50 -03002691 const unsigned char yQuanTable511[] = {
2692 0, 1, 1, 2, 2, 3, 3, 4,
2693 1, 1, 1, 2, 2, 3, 4, 4,
2694 1, 1, 2, 2, 3, 4, 4, 4,
2695 2, 2, 2, 3, 4, 4, 4, 4,
2696 2, 2, 3, 4, 4, 5, 5, 5,
2697 3, 3, 4, 4, 5, 5, 5, 5,
2698 3, 4, 4, 4, 5, 5, 5, 5,
2699 4, 4, 4, 4, 5, 5, 5, 5
2700 };
2701
2702 const unsigned char uvQuanTable511[] = {
2703 0, 2, 2, 3, 4, 4, 4, 4,
2704 2, 2, 2, 4, 4, 4, 4, 4,
2705 2, 2, 3, 4, 4, 4, 4, 4,
2706 3, 4, 4, 4, 4, 4, 4, 4,
2707 4, 4, 4, 4, 4, 4, 4, 4,
2708 4, 4, 4, 4, 4, 4, 4, 4,
2709 4, 4, 4, 4, 4, 4, 4, 4,
2710 4, 4, 4, 4, 4, 4, 4, 4
2711 };
2712
2713 /* OV518 quantization tables are 8x4 (instead of 8x8) */
Hans de Goede49809d62009-06-07 12:10:39 -03002714 const unsigned char yQuanTable518[] = {
2715 5, 4, 5, 6, 6, 7, 7, 7,
2716 5, 5, 5, 5, 6, 7, 7, 7,
2717 6, 6, 6, 6, 7, 7, 7, 8,
2718 7, 7, 6, 7, 7, 7, 8, 8
2719 };
Hans de Goede49809d62009-06-07 12:10:39 -03002720 const unsigned char uvQuanTable518[] = {
2721 6, 6, 6, 7, 7, 7, 7, 7,
2722 6, 6, 6, 7, 7, 7, 7, 7,
2723 6, 6, 6, 7, 7, 7, 7, 8,
2724 7, 7, 7, 7, 7, 7, 8, 8
2725 };
2726
Hans de Goede1876bb92009-06-14 06:45:50 -03002727 const unsigned char *pYTable, *pUVTable;
Hans de Goede49809d62009-06-07 12:10:39 -03002728 unsigned char val0, val1;
Jean-François Moinef8f20182010-11-12 07:54:02 -03002729 int i, size, reg = R51x_COMP_LUT_BEGIN;
Hans de Goede49809d62009-06-07 12:10:39 -03002730
2731 PDEBUG(D_PROBE, "Uploading quantization tables");
2732
Hans de Goede1876bb92009-06-14 06:45:50 -03002733 if (sd->bridge == BRIDGE_OV511 || sd->bridge == BRIDGE_OV511PLUS) {
2734 pYTable = yQuanTable511;
2735 pUVTable = uvQuanTable511;
Jean-François Moine87bae742010-11-12 05:31:34 -03002736 size = 32;
Hans de Goede1876bb92009-06-14 06:45:50 -03002737 } else {
2738 pYTable = yQuanTable518;
2739 pUVTable = uvQuanTable518;
Jean-François Moine87bae742010-11-12 05:31:34 -03002740 size = 16;
Hans de Goede1876bb92009-06-14 06:45:50 -03002741 }
2742
2743 for (i = 0; i < size; i++) {
Hans de Goede49809d62009-06-07 12:10:39 -03002744 val0 = *pYTable++;
2745 val1 = *pYTable++;
2746 val0 &= 0x0f;
2747 val1 &= 0x0f;
2748 val0 |= val1 << 4;
Jean-François Moinef8f20182010-11-12 07:54:02 -03002749 reg_w(sd, reg, val0);
Hans de Goede49809d62009-06-07 12:10:39 -03002750
2751 val0 = *pUVTable++;
2752 val1 = *pUVTable++;
2753 val0 &= 0x0f;
2754 val1 &= 0x0f;
2755 val0 |= val1 << 4;
Jean-François Moinef8f20182010-11-12 07:54:02 -03002756 reg_w(sd, reg + size, val0);
Hans de Goede49809d62009-06-07 12:10:39 -03002757
2758 reg++;
2759 }
Hans de Goede49809d62009-06-07 12:10:39 -03002760}
2761
Hans de Goede1876bb92009-06-14 06:45:50 -03002762/* This initializes the OV511/OV511+ and the sensor */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002763static void ov511_configure(struct gspca_dev *gspca_dev)
Hans de Goede1876bb92009-06-14 06:45:50 -03002764{
2765 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede1876bb92009-06-14 06:45:50 -03002766
2767 /* For 511 and 511+ */
2768 const struct ov_regvals init_511[] = {
2769 { R51x_SYS_RESET, 0x7f },
2770 { R51x_SYS_INIT, 0x01 },
2771 { R51x_SYS_RESET, 0x7f },
2772 { R51x_SYS_INIT, 0x01 },
2773 { R51x_SYS_RESET, 0x3f },
2774 { R51x_SYS_INIT, 0x01 },
2775 { R51x_SYS_RESET, 0x3d },
2776 };
2777
2778 const struct ov_regvals norm_511[] = {
Jean-François Moine780e3122010-10-19 04:29:10 -03002779 { R511_DRAM_FLOW_CTL, 0x01 },
Hans de Goede1876bb92009-06-14 06:45:50 -03002780 { R51x_SYS_SNAP, 0x00 },
2781 { R51x_SYS_SNAP, 0x02 },
2782 { R51x_SYS_SNAP, 0x00 },
2783 { R511_FIFO_OPTS, 0x1f },
2784 { R511_COMP_EN, 0x00 },
2785 { R511_COMP_LUT_EN, 0x03 },
2786 };
2787
2788 const struct ov_regvals norm_511_p[] = {
2789 { R511_DRAM_FLOW_CTL, 0xff },
2790 { R51x_SYS_SNAP, 0x00 },
2791 { R51x_SYS_SNAP, 0x02 },
2792 { R51x_SYS_SNAP, 0x00 },
2793 { R511_FIFO_OPTS, 0xff },
2794 { R511_COMP_EN, 0x00 },
2795 { R511_COMP_LUT_EN, 0x03 },
2796 };
2797
2798 const struct ov_regvals compress_511[] = {
2799 { 0x70, 0x1f },
2800 { 0x71, 0x05 },
2801 { 0x72, 0x06 },
2802 { 0x73, 0x06 },
2803 { 0x74, 0x14 },
2804 { 0x75, 0x03 },
2805 { 0x76, 0x04 },
2806 { 0x77, 0x04 },
2807 };
2808
2809 PDEBUG(D_PROBE, "Device custom id %x", reg_r(sd, R51x_SYS_CUST_ID));
2810
Jean-François Moinef8f20182010-11-12 07:54:02 -03002811 write_regvals(sd, init_511, ARRAY_SIZE(init_511));
Hans de Goede1876bb92009-06-14 06:45:50 -03002812
2813 switch (sd->bridge) {
2814 case BRIDGE_OV511:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002815 write_regvals(sd, norm_511, ARRAY_SIZE(norm_511));
Hans de Goede1876bb92009-06-14 06:45:50 -03002816 break;
2817 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002818 write_regvals(sd, norm_511_p, ARRAY_SIZE(norm_511_p));
Hans de Goede1876bb92009-06-14 06:45:50 -03002819 break;
2820 }
2821
2822 /* Init compression */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002823 write_regvals(sd, compress_511, ARRAY_SIZE(compress_511));
Hans de Goede1876bb92009-06-14 06:45:50 -03002824
Jean-François Moinef8f20182010-11-12 07:54:02 -03002825 ov51x_upload_quan_tables(sd);
Hans de Goede1876bb92009-06-14 06:45:50 -03002826}
2827
Hans de Goede49809d62009-06-07 12:10:39 -03002828/* This initializes the OV518/OV518+ and the sensor */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002829static void ov518_configure(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002830{
2831 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002832
Hans de Goede49809d62009-06-07 12:10:39 -03002833 /* For 518 and 518+ */
Hans de Goedee080fcd2009-06-18 05:03:16 -03002834 const struct ov_regvals init_518[] = {
Hans de Goede49809d62009-06-07 12:10:39 -03002835 { R51x_SYS_RESET, 0x40 },
2836 { R51x_SYS_INIT, 0xe1 },
2837 { R51x_SYS_RESET, 0x3e },
2838 { R51x_SYS_INIT, 0xe1 },
2839 { R51x_SYS_RESET, 0x00 },
2840 { R51x_SYS_INIT, 0xe1 },
2841 { 0x46, 0x00 },
2842 { 0x5d, 0x03 },
2843 };
2844
Hans de Goedee080fcd2009-06-18 05:03:16 -03002845 const struct ov_regvals norm_518[] = {
Hans de Goede49809d62009-06-07 12:10:39 -03002846 { R51x_SYS_SNAP, 0x02 }, /* Reset */
2847 { R51x_SYS_SNAP, 0x01 }, /* Enable */
Jean-François Moine780e3122010-10-19 04:29:10 -03002848 { 0x31, 0x0f },
Hans de Goede49809d62009-06-07 12:10:39 -03002849 { 0x5d, 0x03 },
2850 { 0x24, 0x9f },
2851 { 0x25, 0x90 },
2852 { 0x20, 0x00 },
2853 { 0x51, 0x04 },
2854 { 0x71, 0x19 },
2855 { 0x2f, 0x80 },
2856 };
2857
Hans de Goedee080fcd2009-06-18 05:03:16 -03002858 const struct ov_regvals norm_518_p[] = {
Hans de Goede49809d62009-06-07 12:10:39 -03002859 { R51x_SYS_SNAP, 0x02 }, /* Reset */
2860 { R51x_SYS_SNAP, 0x01 }, /* Enable */
Jean-François Moine780e3122010-10-19 04:29:10 -03002861 { 0x31, 0x0f },
Hans de Goede49809d62009-06-07 12:10:39 -03002862 { 0x5d, 0x03 },
2863 { 0x24, 0x9f },
2864 { 0x25, 0x90 },
2865 { 0x20, 0x60 },
2866 { 0x51, 0x02 },
2867 { 0x71, 0x19 },
2868 { 0x40, 0xff },
2869 { 0x41, 0x42 },
2870 { 0x46, 0x00 },
2871 { 0x33, 0x04 },
2872 { 0x21, 0x19 },
2873 { 0x3f, 0x10 },
2874 { 0x2f, 0x80 },
2875 };
2876
2877 /* First 5 bits of custom ID reg are a revision ID on OV518 */
2878 PDEBUG(D_PROBE, "Device revision %d",
Jean-François Moine87bae742010-11-12 05:31:34 -03002879 0x1f & reg_r(sd, R51x_SYS_CUST_ID));
Hans de Goede49809d62009-06-07 12:10:39 -03002880
Jean-François Moinef8f20182010-11-12 07:54:02 -03002881 write_regvals(sd, init_518, ARRAY_SIZE(init_518));
Hans de Goede49809d62009-06-07 12:10:39 -03002882
2883 /* Set LED GPIO pin to output mode */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002884 reg_w_mask(sd, R518_GPIO_CTL, 0x00, 0x02);
Hans de Goede49809d62009-06-07 12:10:39 -03002885
2886 switch (sd->bridge) {
2887 case BRIDGE_OV518:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002888 write_regvals(sd, norm_518, ARRAY_SIZE(norm_518));
Hans de Goede49809d62009-06-07 12:10:39 -03002889 break;
2890 case BRIDGE_OV518PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002891 write_regvals(sd, norm_518_p, ARRAY_SIZE(norm_518_p));
Hans de Goede49809d62009-06-07 12:10:39 -03002892 break;
2893 }
2894
Jean-François Moinef8f20182010-11-12 07:54:02 -03002895 ov51x_upload_quan_tables(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03002896
Jean-François Moinef8f20182010-11-12 07:54:02 -03002897 reg_w(sd, 0x2f, 0x80);
Hans de Goede49809d62009-06-07 12:10:39 -03002898}
2899
Jean-François Moinef8f20182010-11-12 07:54:02 -03002900static void ov519_configure(struct sd *sd)
Hans de Goede49809d62009-06-07 12:10:39 -03002901{
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002902 static const struct ov_regvals init_519[] = {
Jean-François Moine87bae742010-11-12 05:31:34 -03002903 { 0x5a, 0x6d }, /* EnableSystem */
2904 { 0x53, 0x9b },
Jean-François Moine21867802010-11-12 06:12:09 -03002905 { OV519_R54_EN_CLK1, 0xff }, /* set bit2 to enable jpeg */
Jean-François Moine87bae742010-11-12 05:31:34 -03002906 { 0x5d, 0x03 },
2907 { 0x49, 0x01 },
2908 { 0x48, 0x00 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002909 /* Set LED pin to output mode. Bit 4 must be cleared or sensor
2910 * detection will fail. This deserves further investigation. */
2911 { OV519_GPIO_IO_CTRL0, 0xee },
Jean-François Moine21867802010-11-12 06:12:09 -03002912 { OV519_R51_RESET1, 0x0f },
2913 { OV519_R51_RESET1, 0x00 },
Jean-François Moine87bae742010-11-12 05:31:34 -03002914 { 0x22, 0x00 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002915 /* windows reads 0x55 at this point*/
2916 };
2917
Jean-François Moinef8f20182010-11-12 07:54:02 -03002918 write_regvals(sd, init_519, ARRAY_SIZE(init_519));
Hans de Goede49809d62009-06-07 12:10:39 -03002919}
2920
Jean-François Moinef8f20182010-11-12 07:54:02 -03002921static void ovfx2_configure(struct sd *sd)
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002922{
2923 static const struct ov_regvals init_fx2[] = {
2924 { 0x00, 0x60 },
2925 { 0x02, 0x01 },
2926 { 0x0f, 0x1d },
2927 { 0xe9, 0x82 },
2928 { 0xea, 0xc7 },
2929 { 0xeb, 0x10 },
2930 { 0xec, 0xf6 },
2931 };
2932
2933 sd->stopped = 1;
2934
Jean-François Moinef8f20182010-11-12 07:54:02 -03002935 write_regvals(sd, init_fx2, ARRAY_SIZE(init_fx2));
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002936}
2937
Hans de Goede49809d62009-06-07 12:10:39 -03002938/* this function is called at probe time */
2939static int sd_config(struct gspca_dev *gspca_dev,
2940 const struct usb_device_id *id)
2941{
2942 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002943 struct cam *cam = &gspca_dev->cam;
Hans de Goede49809d62009-06-07 12:10:39 -03002944
Hans de Goede9e4d8252009-06-14 06:25:06 -03002945 sd->bridge = id->driver_info & BRIDGE_MASK;
Jean-François Moinea23acec2010-11-12 15:07:35 -03002946 sd->invert_led = (id->driver_info & BRIDGE_INVERT_LED) != 0;
Hans de Goede49809d62009-06-07 12:10:39 -03002947
2948 switch (sd->bridge) {
Hans de Goede1876bb92009-06-14 06:45:50 -03002949 case BRIDGE_OV511:
2950 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002951 ov511_configure(gspca_dev);
Hans de Goede1876bb92009-06-14 06:45:50 -03002952 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002953 case BRIDGE_OV518:
2954 case BRIDGE_OV518PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002955 ov518_configure(gspca_dev);
Hans de Goede49809d62009-06-07 12:10:39 -03002956 break;
2957 case BRIDGE_OV519:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002958 ov519_configure(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03002959 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002960 case BRIDGE_OVFX2:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002961 ovfx2_configure(sd);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002962 cam->bulk_size = OVFX2_BULK_SIZE;
2963 cam->bulk_nurbs = MAX_NURBS;
2964 cam->bulk = 1;
2965 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03002966 case BRIDGE_W9968CF:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002967 w9968cf_configure(sd);
Hans de Goedea511ba92009-10-16 07:13:07 -03002968 cam->reverse_alts = 1;
2969 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002970 }
2971
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002972 ov51x_led_control(sd, 0); /* turn LED off */
2973
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002974 /* The OV519 must be more aggressive about sensor detection since
2975 * I2C write will never fail if the sensor is not present. We have
2976 * to try to initialize the sensor to detect its presence */
Jean-François Moine7bbe6b82010-11-11 08:27:24 -03002977 sd->sensor = -1;
Hans de Goede229bb7d2009-10-11 07:41:46 -03002978
2979 /* Test for 76xx */
2980 if (init_ov_sensor(sd, OV7xx0_SID) >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03002981 ov7xx0_configure(sd);
2982
Hans de Goede229bb7d2009-10-11 07:41:46 -03002983 /* Test for 6xx0 */
2984 } else if (init_ov_sensor(sd, OV6xx0_SID) >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03002985 ov6xx0_configure(sd);
2986
Hans de Goede229bb7d2009-10-11 07:41:46 -03002987 /* Test for 8xx0 */
2988 } else if (init_ov_sensor(sd, OV8xx0_SID) >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03002989 ov8xx0_configure(sd);
2990
Hans de Goede635118d2009-10-11 09:49:03 -03002991 /* Test for 3xxx / 2xxx */
2992 } else if (init_ov_sensor(sd, OV_HIRES_SID) >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03002993 ov_hires_configure(sd);
Hans de Goede229bb7d2009-10-11 07:41:46 -03002994 } else {
Jean-François Moine0b656322010-09-13 05:19:58 -03002995 err("Can't determine sensor slave IDs");
Hans de Goede229bb7d2009-10-11 07:41:46 -03002996 goto error;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002997 }
2998
Jean-François Moine7bbe6b82010-11-11 08:27:24 -03002999 if (sd->sensor < 0)
3000 goto error;
3001
Hans de Goede49809d62009-06-07 12:10:39 -03003002 switch (sd->bridge) {
Hans de Goede1876bb92009-06-14 06:45:50 -03003003 case BRIDGE_OV511:
3004 case BRIDGE_OV511PLUS:
3005 if (!sd->sif) {
3006 cam->cam_mode = ov511_vga_mode;
3007 cam->nmodes = ARRAY_SIZE(ov511_vga_mode);
3008 } else {
3009 cam->cam_mode = ov511_sif_mode;
3010 cam->nmodes = ARRAY_SIZE(ov511_sif_mode);
3011 }
3012 break;
Hans de Goede49809d62009-06-07 12:10:39 -03003013 case BRIDGE_OV518:
3014 case BRIDGE_OV518PLUS:
3015 if (!sd->sif) {
3016 cam->cam_mode = ov518_vga_mode;
3017 cam->nmodes = ARRAY_SIZE(ov518_vga_mode);
3018 } else {
3019 cam->cam_mode = ov518_sif_mode;
3020 cam->nmodes = ARRAY_SIZE(ov518_sif_mode);
3021 }
3022 break;
3023 case BRIDGE_OV519:
3024 if (!sd->sif) {
3025 cam->cam_mode = ov519_vga_mode;
3026 cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
3027 } else {
3028 cam->cam_mode = ov519_sif_mode;
3029 cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
3030 }
3031 break;
Hans de Goede635118d2009-10-11 09:49:03 -03003032 case BRIDGE_OVFX2:
3033 if (sd->sensor == SEN_OV2610) {
3034 cam->cam_mode = ovfx2_ov2610_mode;
3035 cam->nmodes = ARRAY_SIZE(ovfx2_ov2610_mode);
3036 } else if (sd->sensor == SEN_OV3610) {
3037 cam->cam_mode = ovfx2_ov3610_mode;
3038 cam->nmodes = ARRAY_SIZE(ovfx2_ov3610_mode);
3039 } else if (!sd->sif) {
3040 cam->cam_mode = ov519_vga_mode;
3041 cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
3042 } else {
3043 cam->cam_mode = ov519_sif_mode;
3044 cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
3045 }
3046 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03003047 case BRIDGE_W9968CF:
3048 cam->cam_mode = w9968cf_vga_mode;
3049 cam->nmodes = ARRAY_SIZE(w9968cf_vga_mode);
Hans de Goede79b35902009-10-19 06:08:01 -03003050 if (sd->sif)
3051 cam->nmodes--;
Hans de Goedea511ba92009-10-16 07:13:07 -03003052
3053 /* w9968cf needs initialisation once the sensor is known */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003054 w9968cf_init(sd);
Hans de Goedea511ba92009-10-16 07:13:07 -03003055 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003056 }
Jean-François Moine62833ac2010-10-02 04:27:02 -03003057 gspca_dev->cam.ctrls = sd->ctrls;
Hans de Goede79b35902009-10-19 06:08:01 -03003058 sd->quality = QUALITY_DEF;
Jean-François Moine83db7682010-11-12 07:14:08 -03003059
3060 gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
Hans de Goede02ab18b2009-06-14 04:32:04 -03003061
Jean-François Moinef8f20182010-11-12 07:54:02 -03003062 return gspca_dev->usb_err;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003063error:
3064 PDEBUG(D_ERR, "OV519 Config failed");
Jean-François Moine7bbe6b82010-11-11 08:27:24 -03003065 return -EINVAL;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003066}
3067
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03003068/* this function is called at probe and resume time */
3069static int sd_init(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003070{
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003071 struct sd *sd = (struct sd *) gspca_dev;
3072
3073 /* initialize the sensor */
3074 switch (sd->sensor) {
Hans de Goede635118d2009-10-11 09:49:03 -03003075 case SEN_OV2610:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003076 write_i2c_regvals(sd, norm_2610, ARRAY_SIZE(norm_2610));
3077
Hans de Goede635118d2009-10-11 09:49:03 -03003078 /* Enable autogain, autoexpo, awb, bandfilter */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003079 i2c_w_mask(sd, 0x13, 0x27, 0x27);
Hans de Goede635118d2009-10-11 09:49:03 -03003080 break;
3081 case SEN_OV3610:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003082 write_i2c_regvals(sd, norm_3620b, ARRAY_SIZE(norm_3620b));
3083
Hans de Goede635118d2009-10-11 09:49:03 -03003084 /* Enable autogain, autoexpo, awb, bandfilter */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003085 i2c_w_mask(sd, 0x13, 0x27, 0x27);
Hans de Goede635118d2009-10-11 09:49:03 -03003086 break;
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003087 case SEN_OV6620:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003088 write_i2c_regvals(sd, norm_6x20, ARRAY_SIZE(norm_6x20));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003089 break;
3090 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03003091 case SEN_OV66308AF:
Jean-François Moine62833ac2010-10-02 04:27:02 -03003092 sd->ctrls[CONTRAST].def = 200;
3093 /* The default is too low for the ov6630 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003094 write_i2c_regvals(sd, norm_6x30, ARRAY_SIZE(norm_6x30));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003095 break;
3096 default:
3097/* case SEN_OV7610: */
3098/* case SEN_OV76BE: */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003099 write_i2c_regvals(sd, norm_7610, ARRAY_SIZE(norm_7610));
3100 i2c_w_mask(sd, 0x0e, 0x00, 0x40);
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003101 break;
3102 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03003103 case SEN_OV7620AE:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003104 write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003105 break;
3106 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003107 case SEN_OV7648:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003108 write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003109 break;
3110 case SEN_OV7670:
Jean-François Moine62833ac2010-10-02 04:27:02 -03003111 sd->ctrls[FREQ].max = 3; /* auto */
3112 sd->ctrls[FREQ].def = 3;
Jean-François Moinef8f20182010-11-12 07:54:02 -03003113 write_i2c_regvals(sd, norm_7670, ARRAY_SIZE(norm_7670));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003114 break;
3115 case SEN_OV8610:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003116 write_i2c_regvals(sd, norm_8610, ARRAY_SIZE(norm_8610));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003117 break;
3118 }
Jean-François Moinef8f20182010-11-12 07:54:02 -03003119 return gspca_dev->usb_err;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003120}
3121
Hans de Goede1876bb92009-06-14 06:45:50 -03003122/* Set up the OV511/OV511+ with the given image parameters.
3123 *
3124 * Do not put any sensor-specific code in here (including I2C I/O functions)
3125 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003126static void ov511_mode_init_regs(struct sd *sd)
Hans de Goede1876bb92009-06-14 06:45:50 -03003127{
3128 int hsegs, vsegs, packet_size, fps, needed;
3129 int interlaced = 0;
3130 struct usb_host_interface *alt;
3131 struct usb_interface *intf;
3132
3133 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
3134 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
3135 if (!alt) {
Jean-François Moine0b656322010-09-13 05:19:58 -03003136 err("Couldn't get altsetting");
Jean-François Moinef8f20182010-11-12 07:54:02 -03003137 sd->gspca_dev.usb_err = -EIO;
3138 return;
Hans de Goede1876bb92009-06-14 06:45:50 -03003139 }
3140
3141 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
3142 reg_w(sd, R51x_FIFO_PSIZE, packet_size >> 5);
3143
3144 reg_w(sd, R511_CAM_UV_EN, 0x01);
3145 reg_w(sd, R511_SNAP_UV_EN, 0x01);
3146 reg_w(sd, R511_SNAP_OPTS, 0x03);
3147
3148 /* Here I'm assuming that snapshot size == image size.
3149 * I hope that's always true. --claudio
3150 */
3151 hsegs = (sd->gspca_dev.width >> 3) - 1;
3152 vsegs = (sd->gspca_dev.height >> 3) - 1;
3153
3154 reg_w(sd, R511_CAM_PXCNT, hsegs);
3155 reg_w(sd, R511_CAM_LNCNT, vsegs);
3156 reg_w(sd, R511_CAM_PXDIV, 0x00);
3157 reg_w(sd, R511_CAM_LNDIV, 0x00);
3158
3159 /* YUV420, low pass filter on */
3160 reg_w(sd, R511_CAM_OPTS, 0x03);
3161
3162 /* Snapshot additions */
3163 reg_w(sd, R511_SNAP_PXCNT, hsegs);
3164 reg_w(sd, R511_SNAP_LNCNT, vsegs);
3165 reg_w(sd, R511_SNAP_PXDIV, 0x00);
3166 reg_w(sd, R511_SNAP_LNDIV, 0x00);
3167
3168 /******** Set the framerate ********/
3169 if (frame_rate > 0)
3170 sd->frame_rate = frame_rate;
3171
3172 switch (sd->sensor) {
3173 case SEN_OV6620:
3174 /* No framerate control, doesn't like higher rates yet */
3175 sd->clockdiv = 3;
3176 break;
3177
3178 /* Note once the FIXME's in mode_init_ov_sensor_regs() are fixed
3179 for more sensors we need to do this for them too */
3180 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03003181 case SEN_OV7620AE:
Hans de Goede1876bb92009-06-14 06:45:50 -03003182 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003183 case SEN_OV7648:
Hans de Goedeb282d872009-06-14 19:10:40 -03003184 case SEN_OV76BE:
Hans de Goede1876bb92009-06-14 06:45:50 -03003185 if (sd->gspca_dev.width == 320)
3186 interlaced = 1;
3187 /* Fall through */
3188 case SEN_OV6630:
Hans de Goede1876bb92009-06-14 06:45:50 -03003189 case SEN_OV7610:
3190 case SEN_OV7670:
3191 switch (sd->frame_rate) {
3192 case 30:
3193 case 25:
3194 /* Not enough bandwidth to do 640x480 @ 30 fps */
3195 if (sd->gspca_dev.width != 640) {
3196 sd->clockdiv = 0;
3197 break;
3198 }
3199 /* Fall through for 640x480 case */
3200 default:
3201/* case 20: */
3202/* case 15: */
3203 sd->clockdiv = 1;
3204 break;
3205 case 10:
3206 sd->clockdiv = 2;
3207 break;
3208 case 5:
3209 sd->clockdiv = 5;
3210 break;
3211 }
3212 if (interlaced) {
3213 sd->clockdiv = (sd->clockdiv + 1) * 2 - 1;
3214 /* Higher then 10 does not work */
3215 if (sd->clockdiv > 10)
3216 sd->clockdiv = 10;
3217 }
3218 break;
3219
3220 case SEN_OV8610:
3221 /* No framerate control ?? */
3222 sd->clockdiv = 0;
3223 break;
3224 }
3225
3226 /* Check if we have enough bandwidth to disable compression */
3227 fps = (interlaced ? 60 : 30) / (sd->clockdiv + 1) + 1;
3228 needed = fps * sd->gspca_dev.width * sd->gspca_dev.height * 3 / 2;
3229 /* 1400 is a conservative estimate of the max nr of isoc packets/sec */
3230 if (needed > 1400 * packet_size) {
3231 /* Enable Y and UV quantization and compression */
3232 reg_w(sd, R511_COMP_EN, 0x07);
3233 reg_w(sd, R511_COMP_LUT_EN, 0x03);
3234 } else {
3235 reg_w(sd, R511_COMP_EN, 0x06);
3236 reg_w(sd, R511_COMP_LUT_EN, 0x00);
3237 }
3238
3239 reg_w(sd, R51x_SYS_RESET, OV511_RESET_OMNICE);
3240 reg_w(sd, R51x_SYS_RESET, 0);
Hans de Goede1876bb92009-06-14 06:45:50 -03003241}
3242
Hans de Goede49809d62009-06-07 12:10:39 -03003243/* Sets up the OV518/OV518+ with the given image parameters
3244 *
3245 * OV518 needs a completely different approach, until we can figure out what
3246 * the individual registers do. Also, only 15 FPS is supported now.
3247 *
3248 * Do not put any sensor-specific code in here (including I2C I/O functions)
3249 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003250static void ov518_mode_init_regs(struct sd *sd)
Hans de Goede49809d62009-06-07 12:10:39 -03003251{
Hans de Goedeb282d872009-06-14 19:10:40 -03003252 int hsegs, vsegs, packet_size;
3253 struct usb_host_interface *alt;
3254 struct usb_interface *intf;
3255
3256 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
3257 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
3258 if (!alt) {
Jean-François Moine0b656322010-09-13 05:19:58 -03003259 err("Couldn't get altsetting");
Jean-François Moinef8f20182010-11-12 07:54:02 -03003260 sd->gspca_dev.usb_err = -EIO;
3261 return;
Hans de Goedeb282d872009-06-14 19:10:40 -03003262 }
3263
3264 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
3265 ov518_reg_w32(sd, R51x_FIFO_PSIZE, packet_size & ~7, 2);
Hans de Goede49809d62009-06-07 12:10:39 -03003266
3267 /******** Set the mode ********/
Hans de Goede49809d62009-06-07 12:10:39 -03003268 reg_w(sd, 0x2b, 0);
3269 reg_w(sd, 0x2c, 0);
3270 reg_w(sd, 0x2d, 0);
3271 reg_w(sd, 0x2e, 0);
3272 reg_w(sd, 0x3b, 0);
3273 reg_w(sd, 0x3c, 0);
3274 reg_w(sd, 0x3d, 0);
3275 reg_w(sd, 0x3e, 0);
3276
3277 if (sd->bridge == BRIDGE_OV518) {
3278 /* Set 8-bit (YVYU) input format */
3279 reg_w_mask(sd, 0x20, 0x08, 0x08);
3280
3281 /* Set 12-bit (4:2:0) output format */
3282 reg_w_mask(sd, 0x28, 0x80, 0xf0);
3283 reg_w_mask(sd, 0x38, 0x80, 0xf0);
3284 } else {
3285 reg_w(sd, 0x28, 0x80);
3286 reg_w(sd, 0x38, 0x80);
3287 }
3288
3289 hsegs = sd->gspca_dev.width / 16;
3290 vsegs = sd->gspca_dev.height / 4;
3291
3292 reg_w(sd, 0x29, hsegs);
3293 reg_w(sd, 0x2a, vsegs);
3294
3295 reg_w(sd, 0x39, hsegs);
3296 reg_w(sd, 0x3a, vsegs);
3297
3298 /* Windows driver does this here; who knows why */
3299 reg_w(sd, 0x2f, 0x80);
3300
Jean-François Moine87bae742010-11-12 05:31:34 -03003301 /******** Set the framerate ********/
Hans de Goedeb282d872009-06-14 19:10:40 -03003302 sd->clockdiv = 1;
Hans de Goede49809d62009-06-07 12:10:39 -03003303
3304 /* Mode independent, but framerate dependent, regs */
Hans de Goedeb282d872009-06-14 19:10:40 -03003305 /* 0x51: Clock divider; Only works on some cams which use 2 crystals */
3306 reg_w(sd, 0x51, 0x04);
Hans de Goede49809d62009-06-07 12:10:39 -03003307 reg_w(sd, 0x22, 0x18);
3308 reg_w(sd, 0x23, 0xff);
3309
Hans de Goedeb282d872009-06-14 19:10:40 -03003310 if (sd->bridge == BRIDGE_OV518PLUS) {
3311 switch (sd->sensor) {
Hans de Goede859cc472010-01-07 15:42:35 -03003312 case SEN_OV7620AE:
Hans de Goedeb282d872009-06-14 19:10:40 -03003313 if (sd->gspca_dev.width == 320) {
3314 reg_w(sd, 0x20, 0x00);
3315 reg_w(sd, 0x21, 0x19);
3316 } else {
3317 reg_w(sd, 0x20, 0x60);
3318 reg_w(sd, 0x21, 0x1f);
3319 }
3320 break;
Hans de Goede859cc472010-01-07 15:42:35 -03003321 case SEN_OV7620:
3322 reg_w(sd, 0x20, 0x00);
3323 reg_w(sd, 0x21, 0x19);
3324 break;
Hans de Goedeb282d872009-06-14 19:10:40 -03003325 default:
3326 reg_w(sd, 0x21, 0x19);
3327 }
3328 } else
Hans de Goede49809d62009-06-07 12:10:39 -03003329 reg_w(sd, 0x71, 0x17); /* Compression-related? */
3330
3331 /* FIXME: Sensor-specific */
3332 /* Bit 5 is what matters here. Of course, it is "reserved" */
3333 i2c_w(sd, 0x54, 0x23);
3334
3335 reg_w(sd, 0x2f, 0x80);
3336
3337 if (sd->bridge == BRIDGE_OV518PLUS) {
3338 reg_w(sd, 0x24, 0x94);
3339 reg_w(sd, 0x25, 0x90);
3340 ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
3341 ov518_reg_w32(sd, 0xc6, 540, 2); /* 21ch */
3342 ov518_reg_w32(sd, 0xc7, 540, 2); /* 21ch */
3343 ov518_reg_w32(sd, 0xc8, 108, 2); /* 6ch */
3344 ov518_reg_w32(sd, 0xca, 131098, 3); /* 2001ah */
3345 ov518_reg_w32(sd, 0xcb, 532, 2); /* 214h */
3346 ov518_reg_w32(sd, 0xcc, 2400, 2); /* 960h */
3347 ov518_reg_w32(sd, 0xcd, 32, 2); /* 20h */
3348 ov518_reg_w32(sd, 0xce, 608, 2); /* 260h */
3349 } else {
3350 reg_w(sd, 0x24, 0x9f);
3351 reg_w(sd, 0x25, 0x90);
3352 ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
3353 ov518_reg_w32(sd, 0xc6, 381, 2); /* 17dh */
3354 ov518_reg_w32(sd, 0xc7, 381, 2); /* 17dh */
3355 ov518_reg_w32(sd, 0xc8, 128, 2); /* 80h */
3356 ov518_reg_w32(sd, 0xca, 183331, 3); /* 2cc23h */
3357 ov518_reg_w32(sd, 0xcb, 746, 2); /* 2eah */
3358 ov518_reg_w32(sd, 0xcc, 1750, 2); /* 6d6h */
3359 ov518_reg_w32(sd, 0xcd, 45, 2); /* 2dh */
3360 ov518_reg_w32(sd, 0xce, 851, 2); /* 353h */
3361 }
3362
3363 reg_w(sd, 0x2f, 0x80);
Hans de Goede49809d62009-06-07 12:10:39 -03003364}
3365
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003366/* Sets up the OV519 with the given image parameters
3367 *
3368 * OV519 needs a completely different approach, until we can figure out what
3369 * the individual registers do.
3370 *
3371 * Do not put any sensor-specific code in here (including I2C I/O functions)
3372 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003373static void ov519_mode_init_regs(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003374{
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03003375 static const struct ov_regvals mode_init_519_ov7670[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003376 { 0x5d, 0x03 }, /* Turn off suspend mode */
3377 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
Jean-François Moine21867802010-11-12 06:12:09 -03003378 { OV519_R54_EN_CLK1, 0x0f }, /* bit2 (jpeg enable) */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003379 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
3380 { 0xa3, 0x18 },
3381 { 0xa4, 0x04 },
3382 { 0xa5, 0x28 },
3383 { 0x37, 0x00 }, /* SetUsbInit */
3384 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
3385 /* Enable both fields, YUV Input, disable defect comp (why?) */
3386 { 0x20, 0x0c },
3387 { 0x21, 0x38 },
3388 { 0x22, 0x1d },
3389 { 0x17, 0x50 }, /* undocumented */
3390 { 0x37, 0x00 }, /* undocumented */
3391 { 0x40, 0xff }, /* I2C timeout counter */
3392 { 0x46, 0x00 }, /* I2C clock prescaler */
3393 { 0x59, 0x04 }, /* new from windrv 090403 */
3394 { 0xff, 0x00 }, /* undocumented */
3395 /* windows reads 0x55 at this point, why? */
3396 };
3397
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03003398 static const struct ov_regvals mode_init_519[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003399 { 0x5d, 0x03 }, /* Turn off suspend mode */
3400 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
Jean-François Moine21867802010-11-12 06:12:09 -03003401 { OV519_R54_EN_CLK1, 0x0f }, /* bit2 (jpeg enable) */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003402 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
3403 { 0xa3, 0x18 },
3404 { 0xa4, 0x04 },
3405 { 0xa5, 0x28 },
3406 { 0x37, 0x00 }, /* SetUsbInit */
3407 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
3408 /* Enable both fields, YUV Input, disable defect comp (why?) */
3409 { 0x22, 0x1d },
3410 { 0x17, 0x50 }, /* undocumented */
3411 { 0x37, 0x00 }, /* undocumented */
3412 { 0x40, 0xff }, /* I2C timeout counter */
3413 { 0x46, 0x00 }, /* I2C clock prescaler */
3414 { 0x59, 0x04 }, /* new from windrv 090403 */
3415 { 0xff, 0x00 }, /* undocumented */
3416 /* windows reads 0x55 at this point, why? */
3417 };
3418
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003419 /******** Set the mode ********/
3420 if (sd->sensor != SEN_OV7670) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03003421 write_regvals(sd, mode_init_519, ARRAY_SIZE(mode_init_519));
Hans de Goede035d3a32010-01-09 08:14:43 -03003422 if (sd->sensor == SEN_OV7640 ||
3423 sd->sensor == SEN_OV7648) {
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003424 /* Select 8-bit input mode */
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003425 reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10);
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003426 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003427 } else {
Jean-François Moinef8f20182010-11-12 07:54:02 -03003428 write_regvals(sd, mode_init_519_ov7670,
3429 ARRAY_SIZE(mode_init_519_ov7670));
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003430 }
3431
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003432 reg_w(sd, OV519_R10_H_SIZE, sd->gspca_dev.width >> 4);
3433 reg_w(sd, OV519_R11_V_SIZE, sd->gspca_dev.height >> 3);
Hans de Goede80142ef2009-06-14 06:26:49 -03003434 if (sd->sensor == SEN_OV7670 &&
3435 sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
3436 reg_w(sd, OV519_R12_X_OFFSETL, 0x04);
Hans de Goede035d3a32010-01-09 08:14:43 -03003437 else if (sd->sensor == SEN_OV7648 &&
3438 sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
3439 reg_w(sd, OV519_R12_X_OFFSETL, 0x01);
Hans de Goede80142ef2009-06-14 06:26:49 -03003440 else
3441 reg_w(sd, OV519_R12_X_OFFSETL, 0x00);
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003442 reg_w(sd, OV519_R13_X_OFFSETH, 0x00);
3443 reg_w(sd, OV519_R14_Y_OFFSETL, 0x00);
3444 reg_w(sd, OV519_R15_Y_OFFSETH, 0x00);
3445 reg_w(sd, OV519_R16_DIVIDER, 0x00);
3446 reg_w(sd, OV519_R25_FORMAT, 0x03); /* YUV422 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003447 reg_w(sd, 0x26, 0x00); /* Undocumented */
3448
3449 /******** Set the framerate ********/
3450 if (frame_rate > 0)
3451 sd->frame_rate = frame_rate;
3452
3453/* FIXME: These are only valid at the max resolution. */
3454 sd->clockdiv = 0;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003455 switch (sd->sensor) {
3456 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003457 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003458 switch (sd->frame_rate) {
Jean-Francois Moine53e74512008-11-08 06:10:19 -03003459 default:
3460/* case 30: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003461 reg_w(sd, 0xa4, 0x0c);
3462 reg_w(sd, 0x23, 0xff);
3463 break;
3464 case 25:
3465 reg_w(sd, 0xa4, 0x0c);
3466 reg_w(sd, 0x23, 0x1f);
3467 break;
3468 case 20:
3469 reg_w(sd, 0xa4, 0x0c);
3470 reg_w(sd, 0x23, 0x1b);
3471 break;
Jean-Francois Moine53e74512008-11-08 06:10:19 -03003472 case 15:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003473 reg_w(sd, 0xa4, 0x04);
3474 reg_w(sd, 0x23, 0xff);
3475 sd->clockdiv = 1;
3476 break;
3477 case 10:
3478 reg_w(sd, 0xa4, 0x04);
3479 reg_w(sd, 0x23, 0x1f);
3480 sd->clockdiv = 1;
3481 break;
3482 case 5:
3483 reg_w(sd, 0xa4, 0x04);
3484 reg_w(sd, 0x23, 0x1b);
3485 sd->clockdiv = 1;
3486 break;
3487 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003488 break;
3489 case SEN_OV8610:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003490 switch (sd->frame_rate) {
3491 default: /* 15 fps */
3492/* case 15: */
3493 reg_w(sd, 0xa4, 0x06);
3494 reg_w(sd, 0x23, 0xff);
3495 break;
3496 case 10:
3497 reg_w(sd, 0xa4, 0x06);
3498 reg_w(sd, 0x23, 0x1f);
3499 break;
3500 case 5:
3501 reg_w(sd, 0xa4, 0x06);
3502 reg_w(sd, 0x23, 0x1b);
3503 break;
3504 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003505 break;
3506 case SEN_OV7670: /* guesses, based on 7640 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003507 PDEBUG(D_STREAM, "Setting framerate to %d fps",
3508 (sd->frame_rate == 0) ? 15 : sd->frame_rate);
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003509 reg_w(sd, 0xa4, 0x10);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003510 switch (sd->frame_rate) {
3511 case 30:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003512 reg_w(sd, 0x23, 0xff);
3513 break;
3514 case 20:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003515 reg_w(sd, 0x23, 0x1b);
3516 break;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003517 default:
3518/* case 15: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003519 reg_w(sd, 0x23, 0xff);
3520 sd->clockdiv = 1;
3521 break;
3522 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003523 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003524 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003525}
3526
Jean-François Moinef8f20182010-11-12 07:54:02 -03003527static void mode_init_ov_sensor_regs(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003528{
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003529 struct gspca_dev *gspca_dev;
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003530 int qvga, xstart, xend, ystart, yend;
Jean-François Moine9d1593a2010-11-11 08:04:06 -03003531 u8 v;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003532
3533 gspca_dev = &sd->gspca_dev;
Jean-François Moine87bae742010-11-12 05:31:34 -03003534 qvga = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003535
3536 /******** Mode (VGA/QVGA) and sensor specific regs ********/
3537 switch (sd->sensor) {
Hans de Goede635118d2009-10-11 09:49:03 -03003538 case SEN_OV2610:
3539 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3540 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
3541 i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
3542 i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
3543 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
3544 i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
3545 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
Jean-François Moinef8f20182010-11-12 07:54:02 -03003546 return;
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003547 case SEN_OV3610:
Hans de Goede635118d2009-10-11 09:49:03 -03003548 if (qvga) {
3549 xstart = (1040 - gspca_dev->width) / 2 + (0x1f << 4);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003550 ystart = (776 - gspca_dev->height) / 2;
Hans de Goede635118d2009-10-11 09:49:03 -03003551 } else {
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003552 xstart = (2076 - gspca_dev->width) / 2 + (0x10 << 4);
Hans de Goede635118d2009-10-11 09:49:03 -03003553 ystart = (1544 - gspca_dev->height) / 2;
3554 }
3555 xend = xstart + gspca_dev->width;
3556 yend = ystart + gspca_dev->height;
3557 /* Writing to the COMH register resets the other windowing regs
3558 to their default values, so we must do this first. */
3559 i2c_w_mask(sd, 0x12, qvga ? 0x40 : 0x00, 0xf0);
3560 i2c_w_mask(sd, 0x32,
3561 (((xend >> 1) & 7) << 3) | ((xstart >> 1) & 7),
3562 0x3f);
3563 i2c_w_mask(sd, 0x03,
3564 (((yend >> 1) & 3) << 2) | ((ystart >> 1) & 3),
3565 0x0f);
3566 i2c_w(sd, 0x17, xstart >> 4);
3567 i2c_w(sd, 0x18, xend >> 4);
3568 i2c_w(sd, 0x19, ystart >> 3);
3569 i2c_w(sd, 0x1a, yend >> 3);
Jean-François Moinef8f20182010-11-12 07:54:02 -03003570 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003571 case SEN_OV8610:
3572 /* For OV8610 qvga means qsvga */
3573 i2c_w_mask(sd, OV7610_REG_COM_C, qvga ? (1 << 5) : 0, 1 << 5);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003574 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3575 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3576 i2c_w_mask(sd, 0x2d, 0x00, 0x40); /* from windrv 090403 */
3577 i2c_w_mask(sd, 0x28, 0x20, 0x20); /* progressive mode on */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003578 break;
3579 case SEN_OV7610:
3580 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
Jean-François Moine780e3122010-10-19 04:29:10 -03003581 i2c_w(sd, 0x35, qvga ? 0x1e : 0x9e);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003582 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3583 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003584 break;
3585 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03003586 case SEN_OV7620AE:
Hans de Goedeb282d872009-06-14 19:10:40 -03003587 case SEN_OV76BE:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003588 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3589 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
3590 i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
3591 i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
3592 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
Hans de Goedeb282d872009-06-14 19:10:40 -03003593 i2c_w_mask(sd, 0x67, qvga ? 0xb0 : 0x90, 0xf0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003594 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003595 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3596 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3597 if (sd->sensor == SEN_OV76BE)
3598 i2c_w(sd, 0x35, qvga ? 0x1e : 0x9e);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003599 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003600 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003601 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003602 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3603 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
Hans de Goede8d0082f2010-01-09 19:45:44 -03003604 /* Setting this undocumented bit in qvga mode removes a very
3605 annoying vertical shaking of the image */
Hans de Goede035d3a32010-01-09 08:14:43 -03003606 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
Hans de Goede8d0082f2010-01-09 19:45:44 -03003607 /* Unknown */
Hans de Goede035d3a32010-01-09 08:14:43 -03003608 i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
Hans de Goede8d0082f2010-01-09 19:45:44 -03003609 /* Allow higher automatic gain (to allow higher framerates) */
Hans de Goede035d3a32010-01-09 08:14:43 -03003610 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003611 i2c_w_mask(sd, 0x12, 0x04, 0x04); /* AWB: 1 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003612 break;
3613 case SEN_OV7670:
3614 /* set COM7_FMT_VGA or COM7_FMT_QVGA
3615 * do we need to set anything else?
3616 * HSTART etc are set in set_ov_sensor_window itself */
Jean-François Moine21867802010-11-12 06:12:09 -03003617 i2c_w_mask(sd, OV7670_R12_COM7,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003618 qvga ? OV7670_COM7_FMT_QVGA : OV7670_COM7_FMT_VGA,
3619 OV7670_COM7_FMT_MASK);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003620 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
Jean-François Moine21867802010-11-12 06:12:09 -03003621 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_AWB,
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003622 OV7670_COM8_AWB);
3623 if (qvga) { /* QVGA from ov7670.c by
3624 * Jonathan Corbet */
3625 xstart = 164;
3626 xend = 28;
3627 ystart = 14;
3628 yend = 494;
3629 } else { /* VGA */
3630 xstart = 158;
3631 xend = 14;
3632 ystart = 10;
3633 yend = 490;
3634 }
3635 /* OV7670 hardware window registers are split across
3636 * multiple locations */
Jean-François Moine21867802010-11-12 06:12:09 -03003637 i2c_w(sd, OV7670_R17_HSTART, xstart >> 3);
3638 i2c_w(sd, OV7670_R18_HSTOP, xend >> 3);
3639 v = i2c_r(sd, OV7670_R32_HREF);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003640 v = (v & 0xc0) | ((xend & 0x7) << 3) | (xstart & 0x07);
3641 msleep(10); /* need to sleep between read and write to
3642 * same reg! */
Jean-François Moine21867802010-11-12 06:12:09 -03003643 i2c_w(sd, OV7670_R32_HREF, v);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003644
Jean-François Moine21867802010-11-12 06:12:09 -03003645 i2c_w(sd, OV7670_R19_VSTART, ystart >> 2);
3646 i2c_w(sd, OV7670_R1A_VSTOP, yend >> 2);
3647 v = i2c_r(sd, OV7670_R03_VREF);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003648 v = (v & 0xc0) | ((yend & 0x3) << 2) | (ystart & 0x03);
3649 msleep(10); /* need to sleep between read and write to
3650 * same reg! */
Jean-François Moine21867802010-11-12 06:12:09 -03003651 i2c_w(sd, OV7670_R03_VREF, v);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003652 break;
3653 case SEN_OV6620:
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003654 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3655 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3656 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3657 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003658 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03003659 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003660 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003661 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003662 break;
3663 default:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003664 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003665 }
3666
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003667 /******** Clock programming ********/
Hans de Goedeae49c402009-06-14 19:15:07 -03003668 i2c_w(sd, 0x11, sd->clockdiv);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003669}
3670
Jean-François Moine62833ac2010-10-02 04:27:02 -03003671static void sethvflip(struct gspca_dev *gspca_dev)
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003672{
Jean-François Moine62833ac2010-10-02 04:27:02 -03003673 struct sd *sd = (struct sd *) gspca_dev;
3674
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003675 if (sd->gspca_dev.streaming)
Jean-François Moine5927abc2010-11-12 15:32:29 -03003676 reg_w(sd, OV519_R51_RESET1, 0x0f); /* block stream */
Jean-François Moine21867802010-11-12 06:12:09 -03003677 i2c_w_mask(sd, OV7670_R1E_MVFP,
Jean-François Moine62833ac2010-10-02 04:27:02 -03003678 OV7670_MVFP_MIRROR * sd->ctrls[HFLIP].val
3679 | OV7670_MVFP_VFLIP * sd->ctrls[VFLIP].val,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003680 OV7670_MVFP_MIRROR | OV7670_MVFP_VFLIP);
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003681 if (sd->gspca_dev.streaming)
Jean-François Moine5927abc2010-11-12 15:32:29 -03003682 reg_w(sd, OV519_R51_RESET1, 0x00); /* restart stream */
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003683}
3684
Jean-François Moinef8f20182010-11-12 07:54:02 -03003685static void set_ov_sensor_window(struct sd *sd)
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003686{
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003687 struct gspca_dev *gspca_dev;
Hans de Goede124cc9c2009-06-14 05:48:00 -03003688 int qvga, crop;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003689 int hwsbase, hwebase, vwsbase, vwebase, hwscale, vwscale;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003690
Hans de Goede635118d2009-10-11 09:49:03 -03003691 /* mode setup is fully handled in mode_init_ov_sensor_regs for these */
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003692 if (sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610 ||
Jean-François Moinef8f20182010-11-12 07:54:02 -03003693 sd->sensor == SEN_OV7670) {
3694 mode_init_ov_sensor_regs(sd);
3695 return;
3696 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003697 gspca_dev = &sd->gspca_dev;
Jean-François Moine87bae742010-11-12 05:31:34 -03003698 qvga = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 1;
3699 crop = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 2;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003700
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003701 /* The different sensor ICs handle setting up of window differently.
3702 * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!! */
3703 switch (sd->sensor) {
3704 case SEN_OV8610:
3705 hwsbase = 0x1e;
3706 hwebase = 0x1e;
3707 vwsbase = 0x02;
3708 vwebase = 0x02;
3709 break;
3710 case SEN_OV7610:
3711 case SEN_OV76BE:
3712 hwsbase = 0x38;
3713 hwebase = 0x3a;
3714 vwsbase = vwebase = 0x05;
3715 break;
3716 case SEN_OV6620:
3717 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03003718 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003719 hwsbase = 0x38;
3720 hwebase = 0x3a;
3721 vwsbase = 0x05;
3722 vwebase = 0x06;
Hans de Goede7d971372009-06-14 05:28:17 -03003723 if (sd->sensor == SEN_OV66308AF && qvga)
Hans de Goede49809d62009-06-07 12:10:39 -03003724 /* HDG: this fixes U and V getting swapped */
Hans de Goede7d971372009-06-14 05:28:17 -03003725 hwsbase++;
Hans de Goede124cc9c2009-06-14 05:48:00 -03003726 if (crop) {
3727 hwsbase += 8;
3728 hwebase += 8;
3729 vwsbase += 11;
3730 vwebase += 11;
3731 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003732 break;
3733 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03003734 case SEN_OV7620AE:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003735 hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */
3736 hwebase = 0x2f;
3737 vwsbase = vwebase = 0x05;
3738 break;
3739 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003740 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003741 hwsbase = 0x1a;
3742 hwebase = 0x1a;
3743 vwsbase = vwebase = 0x03;
3744 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003745 default:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003746 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003747 }
3748
3749 switch (sd->sensor) {
3750 case SEN_OV6620:
3751 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03003752 case SEN_OV66308AF:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003753 if (qvga) { /* QCIF */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003754 hwscale = 0;
3755 vwscale = 0;
3756 } else { /* CIF */
3757 hwscale = 1;
3758 vwscale = 1; /* The datasheet says 0;
3759 * it's wrong */
3760 }
3761 break;
3762 case SEN_OV8610:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003763 if (qvga) { /* QSVGA */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003764 hwscale = 1;
3765 vwscale = 1;
3766 } else { /* SVGA */
3767 hwscale = 2;
3768 vwscale = 2;
3769 }
3770 break;
3771 default: /* SEN_OV7xx0 */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003772 if (qvga) { /* QVGA */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003773 hwscale = 1;
3774 vwscale = 0;
3775 } else { /* VGA */
3776 hwscale = 2;
3777 vwscale = 1;
3778 }
3779 }
3780
Jean-François Moinef8f20182010-11-12 07:54:02 -03003781 mode_init_ov_sensor_regs(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003782
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003783 i2c_w(sd, 0x17, hwsbase);
Hans de Goedea511ba92009-10-16 07:13:07 -03003784 i2c_w(sd, 0x18, hwebase + (sd->sensor_width >> hwscale));
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003785 i2c_w(sd, 0x19, vwsbase);
Hans de Goedea511ba92009-10-16 07:13:07 -03003786 i2c_w(sd, 0x1a, vwebase + (sd->sensor_height >> vwscale));
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003787}
3788
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003789/* -- start the camera -- */
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03003790static int sd_start(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003791{
3792 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003793
Hans de Goedea511ba92009-10-16 07:13:07 -03003794 /* Default for most bridges, allow bridge_mode_init_regs to override */
3795 sd->sensor_width = sd->gspca_dev.width;
3796 sd->sensor_height = sd->gspca_dev.height;
3797
Hans de Goede49809d62009-06-07 12:10:39 -03003798 switch (sd->bridge) {
Hans de Goede1876bb92009-06-14 06:45:50 -03003799 case BRIDGE_OV511:
3800 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003801 ov511_mode_init_regs(sd);
Hans de Goede1876bb92009-06-14 06:45:50 -03003802 break;
Hans de Goede49809d62009-06-07 12:10:39 -03003803 case BRIDGE_OV518:
3804 case BRIDGE_OV518PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003805 ov518_mode_init_regs(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03003806 break;
3807 case BRIDGE_OV519:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003808 ov519_mode_init_regs(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03003809 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003810 /* case BRIDGE_OVFX2: nothing to do */
Hans de Goedea511ba92009-10-16 07:13:07 -03003811 case BRIDGE_W9968CF:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003812 w9968cf_mode_init_regs(sd);
Hans de Goedea511ba92009-10-16 07:13:07 -03003813 break;
Hans de Goede49809d62009-06-07 12:10:39 -03003814 }
Hans de Goede49809d62009-06-07 12:10:39 -03003815
Jean-François Moinef8f20182010-11-12 07:54:02 -03003816 set_ov_sensor_window(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003817
Jean-François Moinee2817022010-11-12 13:59:48 -03003818 if (!(sd->gspca_dev.ctrl_dis & (1 << CONTRAST)))
3819 setcontrast(gspca_dev);
3820 if (!(sd->gspca_dev.ctrl_dis & (1 << BRIGHTNESS)))
3821 setbrightness(gspca_dev);
3822 if (!(sd->gspca_dev.ctrl_dis & (1 << COLORS)))
3823 setcolors(gspca_dev);
3824 if (!(sd->gspca_dev.ctrl_dis & ((1 << HFLIP) | (1 << VFLIP))))
3825 sethvflip(gspca_dev);
3826 if (!(sd->gspca_dev.ctrl_dis & (1 << AUTOBRIGHT)))
3827 setautobright(gspca_dev);
3828 if (!(sd->gspca_dev.ctrl_dis & (1 << FREQ)))
3829 setfreq_i(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03003830
Hans de Goede417a4d22010-02-19 07:37:08 -03003831 /* Force clear snapshot state in case the snapshot button was
3832 pressed while we weren't streaming */
3833 sd->snapshot_needs_reset = 1;
3834 sd_reset_snapshot(gspca_dev);
Hans de Goede417a4d22010-02-19 07:37:08 -03003835
Hans de Goeded6b6d7a2010-05-08 08:55:42 -03003836 sd->first_frame = 3;
3837
Jean-François Moinef8f20182010-11-12 07:54:02 -03003838 ov51x_restart(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003839 ov51x_led_control(sd, 1);
Jean-François Moinef8f20182010-11-12 07:54:02 -03003840 return gspca_dev->usb_err;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003841}
3842
3843static void sd_stopN(struct gspca_dev *gspca_dev)
3844{
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003845 struct sd *sd = (struct sd *) gspca_dev;
3846
3847 ov51x_stop(sd);
3848 ov51x_led_control(sd, 0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003849}
3850
Hans de Goede79b35902009-10-19 06:08:01 -03003851static void sd_stop0(struct gspca_dev *gspca_dev)
3852{
3853 struct sd *sd = (struct sd *) gspca_dev;
3854
Jean-François Moined65174c2010-11-11 06:20:42 -03003855 if (!sd->gspca_dev.present)
3856 return;
Hans de Goede79b35902009-10-19 06:08:01 -03003857 if (sd->bridge == BRIDGE_W9968CF)
3858 w9968cf_stop0(sd);
Hans de Goede614d0692010-10-27 07:42:28 -03003859
Jean-François Moine14653e62010-11-11 06:17:01 -03003860#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
Hans de Goede614d0692010-10-27 07:42:28 -03003861 /* If the last button state is pressed, release it now! */
3862 if (sd->snapshot_pressed) {
3863 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
3864 input_sync(gspca_dev->input_dev);
3865 sd->snapshot_pressed = 0;
3866 }
3867#endif
Jean-François Moineb4e96ea2010-11-12 16:13:17 -03003868 if (sd->bridge == BRIDGE_OV519)
3869 reg_w(sd, OV519_R57_SNAPSHOT, 0x23);
Hans de Goede79b35902009-10-19 06:08:01 -03003870}
3871
Hans de Goede92e232a2010-02-20 04:30:45 -03003872static void ov51x_handle_button(struct gspca_dev *gspca_dev, u8 state)
3873{
3874 struct sd *sd = (struct sd *) gspca_dev;
3875
3876 if (sd->snapshot_pressed != state) {
Jean-François Moine28566432010-10-01 07:33:26 -03003877#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
Hans de Goede92e232a2010-02-20 04:30:45 -03003878 input_report_key(gspca_dev->input_dev, KEY_CAMERA, state);
3879 input_sync(gspca_dev->input_dev);
3880#endif
3881 if (state)
3882 sd->snapshot_needs_reset = 1;
3883
3884 sd->snapshot_pressed = state;
3885 } else {
Hans de Goede88e8d202010-02-20 04:45:49 -03003886 /* On the ov511 / ov519 we need to reset the button state
3887 multiple times, as resetting does not work as long as the
3888 button stays pressed */
3889 switch (sd->bridge) {
3890 case BRIDGE_OV511:
3891 case BRIDGE_OV511PLUS:
3892 case BRIDGE_OV519:
3893 if (state)
3894 sd->snapshot_needs_reset = 1;
3895 break;
3896 }
Hans de Goede92e232a2010-02-20 04:30:45 -03003897 }
3898}
3899
Hans de Goede1876bb92009-06-14 06:45:50 -03003900static void ov511_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003901 u8 *in, /* isoc packet */
3902 int len) /* iso packet length */
Hans de Goede1876bb92009-06-14 06:45:50 -03003903{
3904 struct sd *sd = (struct sd *) gspca_dev;
3905
3906 /* SOF/EOF packets have 1st to 8th bytes zeroed and the 9th
3907 * byte non-zero. The EOF packet has image width/height in the
3908 * 10th and 11th bytes. The 9th byte is given as follows:
3909 *
3910 * bit 7: EOF
3911 * 6: compression enabled
3912 * 5: 422/420/400 modes
3913 * 4: 422/420/400 modes
3914 * 3: 1
3915 * 2: snapshot button on
3916 * 1: snapshot frame
3917 * 0: even/odd field
3918 */
3919 if (!(in[0] | in[1] | in[2] | in[3] | in[4] | in[5] | in[6] | in[7]) &&
3920 (in[8] & 0x08)) {
Hans de Goede88e8d202010-02-20 04:45:49 -03003921 ov51x_handle_button(gspca_dev, (in[8] >> 2) & 1);
Hans de Goede1876bb92009-06-14 06:45:50 -03003922 if (in[8] & 0x80) {
3923 /* Frame end */
3924 if ((in[9] + 1) * 8 != gspca_dev->width ||
3925 (in[10] + 1) * 8 != gspca_dev->height) {
3926 PDEBUG(D_ERR, "Invalid frame size, got: %dx%d,"
3927 " requested: %dx%d\n",
3928 (in[9] + 1) * 8, (in[10] + 1) * 8,
3929 gspca_dev->width, gspca_dev->height);
3930 gspca_dev->last_packet_type = DISCARD_PACKET;
3931 return;
3932 }
3933 /* Add 11 byte footer to frame, might be usefull */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003934 gspca_frame_add(gspca_dev, LAST_PACKET, in, 11);
Hans de Goede1876bb92009-06-14 06:45:50 -03003935 return;
3936 } else {
3937 /* Frame start */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003938 gspca_frame_add(gspca_dev, FIRST_PACKET, in, 0);
Hans de Goede1876bb92009-06-14 06:45:50 -03003939 sd->packet_nr = 0;
3940 }
3941 }
3942
3943 /* Ignore the packet number */
3944 len--;
3945
3946 /* intermediate packet */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003947 gspca_frame_add(gspca_dev, INTER_PACKET, in, len);
Hans de Goede1876bb92009-06-14 06:45:50 -03003948}
3949
Hans de Goede49809d62009-06-07 12:10:39 -03003950static void ov518_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003951 u8 *data, /* isoc packet */
Hans de Goede49809d62009-06-07 12:10:39 -03003952 int len) /* iso packet length */
3953{
Hans de Goede92918a52009-06-14 06:21:35 -03003954 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede49809d62009-06-07 12:10:39 -03003955
3956 /* A false positive here is likely, until OVT gives me
3957 * the definitive SOF/EOF format */
3958 if ((!(data[0] | data[1] | data[2] | data[3] | data[5])) && data[6]) {
Hans de Goede92e232a2010-02-20 04:30:45 -03003959 ov51x_handle_button(gspca_dev, (data[6] >> 1) & 1);
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003960 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
3961 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
Hans de Goede92918a52009-06-14 06:21:35 -03003962 sd->packet_nr = 0;
3963 }
3964
3965 if (gspca_dev->last_packet_type == DISCARD_PACKET)
3966 return;
3967
3968 /* Does this device use packet numbers ? */
3969 if (len & 7) {
3970 len--;
3971 if (sd->packet_nr == data[len])
3972 sd->packet_nr++;
3973 /* The last few packets of the frame (which are all 0's
3974 except that they may contain part of the footer), are
3975 numbered 0 */
3976 else if (sd->packet_nr == 0 || data[len]) {
3977 PDEBUG(D_ERR, "Invalid packet nr: %d (expect: %d)",
3978 (int)data[len], (int)sd->packet_nr);
3979 gspca_dev->last_packet_type = DISCARD_PACKET;
3980 return;
3981 }
Hans de Goede49809d62009-06-07 12:10:39 -03003982 }
3983
3984 /* intermediate packet */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003985 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03003986}
3987
3988static void ov519_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003989 u8 *data, /* isoc packet */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003990 int len) /* iso packet length */
3991{
3992 /* Header of ov519 is 16 bytes:
3993 * Byte Value Description
3994 * 0 0xff magic
3995 * 1 0xff magic
3996 * 2 0xff magic
3997 * 3 0xXX 0x50 = SOF, 0x51 = EOF
3998 * 9 0xXX 0x01 initial frame without data,
3999 * 0x00 standard frame with image
4000 * 14 Lo in EOF: length of image data / 8
4001 * 15 Hi
4002 */
4003
4004 if (data[0] == 0xff && data[1] == 0xff && data[2] == 0xff) {
4005 switch (data[3]) {
4006 case 0x50: /* start of frame */
Hans de Goede417a4d22010-02-19 07:37:08 -03004007 /* Don't check the button state here, as the state
4008 usually (always ?) changes at EOF and checking it
4009 here leads to unnecessary snapshot state resets. */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004010#define HDRSZ 16
4011 data += HDRSZ;
4012 len -= HDRSZ;
4013#undef HDRSZ
4014 if (data[0] == 0xff || data[1] == 0xd8)
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004015 gspca_frame_add(gspca_dev, FIRST_PACKET,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004016 data, len);
4017 else
4018 gspca_dev->last_packet_type = DISCARD_PACKET;
4019 return;
4020 case 0x51: /* end of frame */
Hans de Goede92e232a2010-02-20 04:30:45 -03004021 ov51x_handle_button(gspca_dev, data[11] & 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004022 if (data[9] != 0)
4023 gspca_dev->last_packet_type = DISCARD_PACKET;
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004024 gspca_frame_add(gspca_dev, LAST_PACKET,
4025 NULL, 0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004026 return;
4027 }
4028 }
4029
4030 /* intermediate packet */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004031 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004032}
4033
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004034static void ovfx2_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004035 u8 *data, /* isoc packet */
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004036 int len) /* iso packet length */
4037{
Hans de Goeded6b6d7a2010-05-08 08:55:42 -03004038 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goeded6b6d7a2010-05-08 08:55:42 -03004039
4040 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
4041
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004042 /* A short read signals EOF */
4043 if (len < OVFX2_BULK_SIZE) {
Hans de Goeded6b6d7a2010-05-08 08:55:42 -03004044 /* If the frame is short, and it is one of the first ones
4045 the sensor and bridge are still syncing, so drop it. */
4046 if (sd->first_frame) {
4047 sd->first_frame--;
Jean-François Moineb192ca92010-06-27 03:08:19 -03004048 if (gspca_dev->image_len <
4049 sd->gspca_dev.width * sd->gspca_dev.height)
Hans de Goeded6b6d7a2010-05-08 08:55:42 -03004050 gspca_dev->last_packet_type = DISCARD_PACKET;
4051 }
4052 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004053 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004054 }
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004055}
4056
Hans de Goede49809d62009-06-07 12:10:39 -03004057static void sd_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004058 u8 *data, /* isoc packet */
Hans de Goede49809d62009-06-07 12:10:39 -03004059 int len) /* iso packet length */
4060{
4061 struct sd *sd = (struct sd *) gspca_dev;
4062
4063 switch (sd->bridge) {
4064 case BRIDGE_OV511:
4065 case BRIDGE_OV511PLUS:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004066 ov511_pkt_scan(gspca_dev, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03004067 break;
4068 case BRIDGE_OV518:
4069 case BRIDGE_OV518PLUS:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004070 ov518_pkt_scan(gspca_dev, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03004071 break;
4072 case BRIDGE_OV519:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004073 ov519_pkt_scan(gspca_dev, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03004074 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004075 case BRIDGE_OVFX2:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004076 ovfx2_pkt_scan(gspca_dev, data, len);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004077 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03004078 case BRIDGE_W9968CF:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004079 w9968cf_pkt_scan(gspca_dev, data, len);
Hans de Goedea511ba92009-10-16 07:13:07 -03004080 break;
Hans de Goede49809d62009-06-07 12:10:39 -03004081 }
4082}
4083
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004084/* -- management routines -- */
4085
4086static void setbrightness(struct gspca_dev *gspca_dev)
4087{
4088 struct sd *sd = (struct sd *) gspca_dev;
4089 int val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004090
Jean-François Moine62833ac2010-10-02 04:27:02 -03004091 val = sd->ctrls[BRIGHTNESS].val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004092 switch (sd->sensor) {
4093 case SEN_OV8610:
4094 case SEN_OV7610:
4095 case SEN_OV76BE:
4096 case SEN_OV6620:
4097 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03004098 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004099 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03004100 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004101 i2c_w(sd, OV7610_REG_BRT, val);
4102 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 /* 7620 doesn't like manual changes when in auto mode */
Jean-François Moine62833ac2010-10-02 04:27:02 -03004106 if (!sd->ctrls[AUTOBRIGHT].val)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004107 i2c_w(sd, OV7610_REG_BRT, val);
4108 break;
4109 case SEN_OV7670:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03004110/*win trace
Jean-François Moine21867802010-11-12 06:12:09 -03004111 * i2c_w_mask(sd, OV7670_R13_COM8, 0, OV7670_COM8_AEC); */
4112 i2c_w(sd, OV7670_R55_BRIGHT, ov7670_abs_to_sm(val));
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004113 break;
4114 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004115}
4116
4117static void setcontrast(struct gspca_dev *gspca_dev)
4118{
4119 struct sd *sd = (struct sd *) gspca_dev;
4120 int val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004121
Jean-François Moine62833ac2010-10-02 04:27:02 -03004122 val = sd->ctrls[CONTRAST].val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004123 switch (sd->sensor) {
4124 case SEN_OV7610:
4125 case SEN_OV6620:
4126 i2c_w(sd, OV7610_REG_CNT, val);
4127 break;
4128 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03004129 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004130 i2c_w_mask(sd, OV7610_REG_CNT, val >> 4, 0x0f);
Hans de Goede49809d62009-06-07 12:10:39 -03004131 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004132 case SEN_OV8610: {
Jean-François Moine9d1593a2010-11-11 08:04:06 -03004133 static const u8 ctab[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004134 0x03, 0x09, 0x0b, 0x0f, 0x53, 0x6f, 0x35, 0x7f
4135 };
4136
4137 /* Use Y gamma control instead. Bit 0 enables it. */
4138 i2c_w(sd, 0x64, ctab[val >> 5]);
4139 break;
4140 }
Hans de Goede859cc472010-01-07 15:42:35 -03004141 case SEN_OV7620:
4142 case SEN_OV7620AE: {
Jean-François Moine9d1593a2010-11-11 08:04:06 -03004143 static const u8 ctab[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004144 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
4145 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
4146 };
4147
4148 /* Use Y gamma control instead. Bit 0 enables it. */
4149 i2c_w(sd, 0x64, ctab[val >> 4]);
4150 break;
4151 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004152 case SEN_OV7670:
4153 /* check that this isn't just the same as ov7610 */
Jean-François Moine21867802010-11-12 06:12:09 -03004154 i2c_w(sd, OV7670_R56_CONTRAS, val >> 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004155 break;
4156 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004157}
4158
4159static void setcolors(struct gspca_dev *gspca_dev)
4160{
4161 struct sd *sd = (struct sd *) gspca_dev;
4162 int val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004163
Jean-François Moine62833ac2010-10-02 04:27:02 -03004164 val = sd->ctrls[COLORS].val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004165 switch (sd->sensor) {
4166 case SEN_OV8610:
4167 case SEN_OV7610:
4168 case SEN_OV76BE:
4169 case SEN_OV6620:
4170 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03004171 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004172 i2c_w(sd, OV7610_REG_SAT, val);
4173 break;
4174 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03004175 case SEN_OV7620AE:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004176 /* Use UV gamma control instead. Bits 0 & 7 are reserved. */
4177/* rc = ov_i2c_write(sd->dev, 0x62, (val >> 9) & 0x7e);
4178 if (rc < 0)
4179 goto out; */
4180 i2c_w(sd, OV7610_REG_SAT, val);
4181 break;
4182 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03004183 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004184 i2c_w(sd, OV7610_REG_SAT, val & 0xf0);
4185 break;
4186 case SEN_OV7670:
4187 /* supported later once I work out how to do it
4188 * transparently fail now! */
4189 /* set REG_COM13 values for UV sat auto mode */
4190 break;
4191 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004192}
4193
Jean-François Moine62833ac2010-10-02 04:27:02 -03004194static void setautobright(struct gspca_dev *gspca_dev)
Hans de Goede02ab18b2009-06-14 04:32:04 -03004195{
Jean-François Moine62833ac2010-10-02 04:27:02 -03004196 struct sd *sd = (struct sd *) gspca_dev;
4197
Jean-François Moine62833ac2010-10-02 04:27:02 -03004198 i2c_w_mask(sd, 0x2d, sd->ctrls[AUTOBRIGHT].val ? 0x10 : 0x00, 0x10);
Hans de Goede02ab18b2009-06-14 04:32:04 -03004199}
4200
Jean-François Moine62833ac2010-10-02 04:27:02 -03004201static void setfreq_i(struct sd *sd)
Hans de Goede02ab18b2009-06-14 04:32:04 -03004202{
4203 if (sd->sensor == SEN_OV7670) {
Jean-François Moine62833ac2010-10-02 04:27:02 -03004204 switch (sd->ctrls[FREQ].val) {
Hans de Goede02ab18b2009-06-14 04:32:04 -03004205 case 0: /* Banding filter disabled */
Jean-François Moine21867802010-11-12 06:12:09 -03004206 i2c_w_mask(sd, OV7670_R13_COM8, 0, OV7670_COM8_BFILT);
Hans de Goede02ab18b2009-06-14 04:32:04 -03004207 break;
4208 case 1: /* 50 hz */
Jean-François Moine21867802010-11-12 06:12:09 -03004209 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT,
Hans de Goede02ab18b2009-06-14 04:32:04 -03004210 OV7670_COM8_BFILT);
Jean-François Moine21867802010-11-12 06:12:09 -03004211 i2c_w_mask(sd, OV7670_R3B_COM11, 0x08, 0x18);
Hans de Goede02ab18b2009-06-14 04:32:04 -03004212 break;
4213 case 2: /* 60 hz */
Jean-François Moine21867802010-11-12 06:12:09 -03004214 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT,
Hans de Goede02ab18b2009-06-14 04:32:04 -03004215 OV7670_COM8_BFILT);
Jean-François Moine21867802010-11-12 06:12:09 -03004216 i2c_w_mask(sd, OV7670_R3B_COM11, 0x00, 0x18);
Hans de Goede02ab18b2009-06-14 04:32:04 -03004217 break;
Jean-François Moine21867802010-11-12 06:12:09 -03004218 case 3: /* Auto hz - ov7670 only */
4219 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT,
Hans de Goede02ab18b2009-06-14 04:32:04 -03004220 OV7670_COM8_BFILT);
Jean-François Moine21867802010-11-12 06:12:09 -03004221 i2c_w_mask(sd, OV7670_R3B_COM11, OV7670_COM11_HZAUTO,
Hans de Goede02ab18b2009-06-14 04:32:04 -03004222 0x18);
4223 break;
4224 }
4225 } else {
Jean-François Moine62833ac2010-10-02 04:27:02 -03004226 switch (sd->ctrls[FREQ].val) {
Hans de Goede02ab18b2009-06-14 04:32:04 -03004227 case 0: /* Banding filter disabled */
4228 i2c_w_mask(sd, 0x2d, 0x00, 0x04);
4229 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
4230 break;
4231 case 1: /* 50 hz (filter on and framerate adj) */
4232 i2c_w_mask(sd, 0x2d, 0x04, 0x04);
4233 i2c_w_mask(sd, 0x2a, 0x80, 0x80);
4234 /* 20 fps -> 16.667 fps */
4235 if (sd->sensor == SEN_OV6620 ||
Hans de Goede7d971372009-06-14 05:28:17 -03004236 sd->sensor == SEN_OV6630 ||
4237 sd->sensor == SEN_OV66308AF)
Hans de Goede02ab18b2009-06-14 04:32:04 -03004238 i2c_w(sd, 0x2b, 0x5e);
4239 else
4240 i2c_w(sd, 0x2b, 0xac);
4241 break;
4242 case 2: /* 60 hz (filter on, ...) */
4243 i2c_w_mask(sd, 0x2d, 0x04, 0x04);
4244 if (sd->sensor == SEN_OV6620 ||
Hans de Goede7d971372009-06-14 05:28:17 -03004245 sd->sensor == SEN_OV6630 ||
4246 sd->sensor == SEN_OV66308AF) {
Hans de Goede02ab18b2009-06-14 04:32:04 -03004247 /* 20 fps -> 15 fps */
4248 i2c_w_mask(sd, 0x2a, 0x80, 0x80);
4249 i2c_w(sd, 0x2b, 0xa8);
4250 } else {
4251 /* no framerate adj. */
4252 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
4253 }
4254 break;
4255 }
4256 }
4257}
Jean-François Moine62833ac2010-10-02 04:27:02 -03004258static void setfreq(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004259{
4260 struct sd *sd = (struct sd *) gspca_dev;
4261
Jean-François Moine62833ac2010-10-02 04:27:02 -03004262 setfreq_i(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004263
Jean-François Moine62833ac2010-10-02 04:27:02 -03004264 /* Ugly but necessary */
4265 if (sd->bridge == BRIDGE_W9968CF)
4266 w9968cf_set_crop_window(sd);
Hans de Goede02ab18b2009-06-14 04:32:04 -03004267}
4268
4269static int sd_querymenu(struct gspca_dev *gspca_dev,
4270 struct v4l2_querymenu *menu)
4271{
4272 struct sd *sd = (struct sd *) gspca_dev;
4273
4274 switch (menu->id) {
4275 case V4L2_CID_POWER_LINE_FREQUENCY:
4276 switch (menu->index) {
4277 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
4278 strcpy((char *) menu->name, "NoFliker");
4279 return 0;
4280 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
4281 strcpy((char *) menu->name, "50 Hz");
4282 return 0;
4283 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
4284 strcpy((char *) menu->name, "60 Hz");
4285 return 0;
4286 case 3:
4287 if (sd->sensor != SEN_OV7670)
4288 return -EINVAL;
4289
4290 strcpy((char *) menu->name, "Automatic");
4291 return 0;
4292 }
4293 break;
4294 }
4295 return -EINVAL;
4296}
4297
Hans de Goede79b35902009-10-19 06:08:01 -03004298static int sd_get_jcomp(struct gspca_dev *gspca_dev,
4299 struct v4l2_jpegcompression *jcomp)
4300{
4301 struct sd *sd = (struct sd *) gspca_dev;
4302
4303 if (sd->bridge != BRIDGE_W9968CF)
4304 return -EINVAL;
4305
4306 memset(jcomp, 0, sizeof *jcomp);
4307 jcomp->quality = sd->quality;
4308 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT | V4L2_JPEG_MARKER_DQT |
4309 V4L2_JPEG_MARKER_DRI;
4310 return 0;
4311}
4312
4313static int sd_set_jcomp(struct gspca_dev *gspca_dev,
4314 struct v4l2_jpegcompression *jcomp)
4315{
4316 struct sd *sd = (struct sd *) gspca_dev;
4317
4318 if (sd->bridge != BRIDGE_W9968CF)
4319 return -EINVAL;
4320
4321 if (gspca_dev->streaming)
4322 return -EBUSY;
4323
4324 if (jcomp->quality < QUALITY_MIN)
4325 sd->quality = QUALITY_MIN;
4326 else if (jcomp->quality > QUALITY_MAX)
4327 sd->quality = QUALITY_MAX;
4328 else
4329 sd->quality = jcomp->quality;
4330
4331 /* Return resulting jcomp params to app */
4332 sd_get_jcomp(gspca_dev, jcomp);
4333
4334 return 0;
4335}
4336
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004337/* sub-driver description */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03004338static const struct sd_desc sd_desc = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004339 .name = MODULE_NAME,
4340 .ctrls = sd_ctrls,
4341 .nctrls = ARRAY_SIZE(sd_ctrls),
4342 .config = sd_config,
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03004343 .init = sd_init,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004344 .start = sd_start,
4345 .stopN = sd_stopN,
Hans de Goede79b35902009-10-19 06:08:01 -03004346 .stop0 = sd_stop0,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004347 .pkt_scan = sd_pkt_scan,
Hans de Goede417a4d22010-02-19 07:37:08 -03004348 .dq_callback = sd_reset_snapshot,
Hans de Goede02ab18b2009-06-14 04:32:04 -03004349 .querymenu = sd_querymenu,
Hans de Goede79b35902009-10-19 06:08:01 -03004350 .get_jcomp = sd_get_jcomp,
4351 .set_jcomp = sd_set_jcomp,
Jean-François Moine28566432010-10-01 07:33:26 -03004352#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
Hans de Goede417a4d22010-02-19 07:37:08 -03004353 .other_input = 1,
4354#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004355};
4356
4357/* -- module initialisation -- */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03004358static const __devinitdata struct usb_device_id device_table[] = {
Hans de Goedea511ba92009-10-16 07:13:07 -03004359 {USB_DEVICE(0x041e, 0x4003), .driver_info = BRIDGE_W9968CF },
Hans de Goede49809d62009-06-07 12:10:39 -03004360 {USB_DEVICE(0x041e, 0x4052), .driver_info = BRIDGE_OV519 },
4361 {USB_DEVICE(0x041e, 0x405f), .driver_info = BRIDGE_OV519 },
4362 {USB_DEVICE(0x041e, 0x4060), .driver_info = BRIDGE_OV519 },
4363 {USB_DEVICE(0x041e, 0x4061), .driver_info = BRIDGE_OV519 },
Hans de Goede9e4d8252009-06-14 06:25:06 -03004364 {USB_DEVICE(0x041e, 0x4064),
Jean-François Moine87bae742010-11-12 05:31:34 -03004365 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
Rafal Milecki518c8df2009-10-02 03:54:44 -03004366 {USB_DEVICE(0x041e, 0x4067), .driver_info = BRIDGE_OV519 },
Hans de Goede9e4d8252009-06-14 06:25:06 -03004367 {USB_DEVICE(0x041e, 0x4068),
Jean-François Moine87bae742010-11-12 05:31:34 -03004368 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
Hans de Goede49809d62009-06-07 12:10:39 -03004369 {USB_DEVICE(0x045e, 0x028c), .driver_info = BRIDGE_OV519 },
4370 {USB_DEVICE(0x054c, 0x0154), .driver_info = BRIDGE_OV519 },
Hans de Goede98184f72010-01-07 12:06:00 -03004371 {USB_DEVICE(0x054c, 0x0155),
Jean-François Moine87bae742010-11-12 05:31:34 -03004372 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
Hans de Goede1876bb92009-06-14 06:45:50 -03004373 {USB_DEVICE(0x05a9, 0x0511), .driver_info = BRIDGE_OV511 },
Hans de Goede49809d62009-06-07 12:10:39 -03004374 {USB_DEVICE(0x05a9, 0x0518), .driver_info = BRIDGE_OV518 },
4375 {USB_DEVICE(0x05a9, 0x0519), .driver_info = BRIDGE_OV519 },
4376 {USB_DEVICE(0x05a9, 0x0530), .driver_info = BRIDGE_OV519 },
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004377 {USB_DEVICE(0x05a9, 0x2800), .driver_info = BRIDGE_OVFX2 },
Hans de Goede49809d62009-06-07 12:10:39 -03004378 {USB_DEVICE(0x05a9, 0x4519), .driver_info = BRIDGE_OV519 },
4379 {USB_DEVICE(0x05a9, 0x8519), .driver_info = BRIDGE_OV519 },
Hans de Goede1876bb92009-06-14 06:45:50 -03004380 {USB_DEVICE(0x05a9, 0xa511), .driver_info = BRIDGE_OV511PLUS },
Hans de Goede49809d62009-06-07 12:10:39 -03004381 {USB_DEVICE(0x05a9, 0xa518), .driver_info = BRIDGE_OV518PLUS },
Hans de Goede1876bb92009-06-14 06:45:50 -03004382 {USB_DEVICE(0x0813, 0x0002), .driver_info = BRIDGE_OV511PLUS },
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004383 {USB_DEVICE(0x0b62, 0x0059), .driver_info = BRIDGE_OVFX2 },
4384 {USB_DEVICE(0x0e96, 0xc001), .driver_info = BRIDGE_OVFX2 },
Hans de Goedea511ba92009-10-16 07:13:07 -03004385 {USB_DEVICE(0x1046, 0x9967), .driver_info = BRIDGE_W9968CF },
Jean-François Moine87bae742010-11-12 05:31:34 -03004386 {USB_DEVICE(0x8020, 0xef04), .driver_info = BRIDGE_OVFX2 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004387 {}
4388};
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03004389
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004390MODULE_DEVICE_TABLE(usb, device_table);
4391
4392/* -- device connect -- */
4393static int sd_probe(struct usb_interface *intf,
4394 const struct usb_device_id *id)
4395{
4396 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
4397 THIS_MODULE);
4398}
4399
4400static struct usb_driver sd_driver = {
4401 .name = MODULE_NAME,
4402 .id_table = device_table,
4403 .probe = sd_probe,
4404 .disconnect = gspca_disconnect,
Jean-Francois Moine6a709742008-09-03 16:48:10 -03004405#ifdef CONFIG_PM
4406 .suspend = gspca_suspend,
4407 .resume = gspca_resume,
4408#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004409};
4410
4411/* -- module insert / remove -- */
4412static int __init sd_mod_init(void)
4413{
Jean-François Moine54826432010-09-13 04:53:03 -03004414 return usb_register(&sd_driver);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004415}
4416static void __exit sd_mod_exit(void)
4417{
4418 usb_deregister(&sd_driver);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004419}
4420
4421module_init(sd_mod_init);
4422module_exit(sd_mod_exit);
4423
4424module_param(frame_rate, int, 0644);
4425MODULE_PARM_DESC(frame_rate, "Frame rate (5, 10, 15, 20 or 30 fps)");