blob: 0591ced5d02146c0a73c28f7633ce5f2ec1ceacc [file] [log] [blame]
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001/**
2 * OV519 driver
3 *
4 * Copyright (C) 2008 Jean-Francois Moine (http://moinejf.free.fr)
Hans de Goedeb46aaa02009-10-12 10:07:57 -03005 * Copyright (C) 2009 Hans de Goede <hdegoede@redhat.com>
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03006 *
Romain Beauxis2961e8752008-12-05 06:25:26 -03007 * This module is adapted from the ov51x-jpeg package, which itself
8 * was adapted from the ov511 driver.
9 *
10 * Original copyright for the ov511 driver is:
11 *
Hans de Goedeb46aaa02009-10-12 10:07:57 -030012 * Copyright (c) 1999-2006 Mark W. McClelland
Romain Beauxis2961e8752008-12-05 06:25:26 -030013 * Support for OV519, OV8610 Copyright (c) 2003 Joerg Heckenbach
Hans de Goedeb46aaa02009-10-12 10:07:57 -030014 * Many improvements by Bret Wallach <bwallac1@san.rr.com>
15 * Color fixes by by Orion Sky Lawlor <olawlor@acm.org> (2/26/2000)
16 * OV7620 fixes by Charl P. Botha <cpbotha@ieee.org>
17 * Changes by Claudio Matsuoka <claudio@conectiva.com>
Romain Beauxis2961e8752008-12-05 06:25:26 -030018 *
19 * ov51x-jpeg original copyright is:
20 *
21 * Copyright (c) 2004-2007 Romain Beauxis <toots@rastageeks.org>
22 * Support for OV7670 sensors was contributed by Sam Skipsey <aoanla@yahoo.com>
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030023 *
24 * This program is free software; you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 2 of the License, or
27 * any later version.
28 *
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
33 *
34 * You should have received a copy of the GNU General Public License
35 * along with this program; if not, write to the Free Software
36 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37 *
38 */
39#define MODULE_NAME "ov519"
40
Hans de Goede417a4d22010-02-19 07:37:08 -030041#include <linux/input.h>
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030042#include "gspca.h"
43
Jean-François Moine9a731a32010-06-04 05:26:42 -030044/* The jpeg_hdr is used by w996Xcf only */
45/* The CONEX_CAM define for jpeg.h needs renaming, now its used here too */
46#define CONEX_CAM
47#include "jpeg.h"
48
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030049MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
50MODULE_DESCRIPTION("OV519 USB Camera Driver");
51MODULE_LICENSE("GPL");
52
53/* global parameters */
54static int frame_rate;
55
56/* Number of times to retry a failed I2C transaction. Increase this if you
57 * are getting "Failed to read sensor ID..." */
58static int i2c_detect_tries = 10;
59
Jean-François Moine62833ac2010-10-02 04:27:02 -030060/* controls */
61enum e_ctrl {
62 BRIGHTNESS,
63 CONTRAST,
64 COLORS,
65 HFLIP,
66 VFLIP,
67 AUTOBRIGHT,
68 FREQ,
69 NCTRL /* number of controls */
70};
71
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030072/* ov519 device descriptor */
73struct sd {
74 struct gspca_dev gspca_dev; /* !! must be the first item */
75
Jean-François Moine62833ac2010-10-02 04:27:02 -030076 struct gspca_ctrl ctrls[NCTRL];
77
Jean-François Moine9d1593a2010-11-11 08:04:06 -030078 u8 packet_nr;
Hans de Goede92918a52009-06-14 06:21:35 -030079
Hans de Goede49809d62009-06-07 12:10:39 -030080 char bridge;
81#define BRIDGE_OV511 0
82#define BRIDGE_OV511PLUS 1
83#define BRIDGE_OV518 2
84#define BRIDGE_OV518PLUS 3
85#define BRIDGE_OV519 4
Hans de Goede635118d2009-10-11 09:49:03 -030086#define BRIDGE_OVFX2 5
Hans de Goedea511ba92009-10-16 07:13:07 -030087#define BRIDGE_W9968CF 6
Hans de Goede9e4d8252009-06-14 06:25:06 -030088#define BRIDGE_MASK 7
89
90 char invert_led;
91#define BRIDGE_INVERT_LED 8
Hans de Goede49809d62009-06-07 12:10:39 -030092
Hans de Goede417a4d22010-02-19 07:37:08 -030093 char snapshot_pressed;
94 char snapshot_needs_reset;
95
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030096 /* Determined by sensor type */
Jean-François Moine9d1593a2010-11-11 08:04:06 -030097 u8 sif;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030098
Jean-François Moine9d1593a2010-11-11 08:04:06 -030099 u8 quality;
Hans de Goede79b35902009-10-19 06:08:01 -0300100#define QUALITY_MIN 50
101#define QUALITY_MAX 70
102#define QUALITY_DEF 50
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300103
Jean-François Moine9d1593a2010-11-11 08:04:06 -0300104 u8 stopped; /* Streaming is temporarily paused */
105 u8 first_frame;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300106
Jean-François Moine9d1593a2010-11-11 08:04:06 -0300107 u8 frame_rate; /* current Framerate */
108 u8 clockdiv; /* clockdiv override */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300109
Jean-François Moine7bbe6b82010-11-11 08:27:24 -0300110 s8 sensor; /* Type of image sensor chip (SEN_*) */
Hans de Goedea511ba92009-10-16 07:13:07 -0300111
112 u8 sensor_addr;
Jean-François Moined6fa6632010-11-11 08:05:50 -0300113 u16 sensor_width;
114 u16 sensor_height;
115 s16 sensor_reg_cache[256];
Hans de Goede79b35902009-10-19 06:08:01 -0300116
Jean-François Moine9a731a32010-06-04 05:26:42 -0300117 u8 jpeg_hdr[JPEG_HDR_SZ];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300118};
Jean-François Moine7bbe6b82010-11-11 08:27:24 -0300119enum sensors {
120 SEN_OV2610,
121 SEN_OV3610,
122 SEN_OV6620,
123 SEN_OV6630,
124 SEN_OV66308AF,
125 SEN_OV7610,
126 SEN_OV7620,
127 SEN_OV7620AE,
128 SEN_OV7640,
129 SEN_OV7648,
130 SEN_OV7670,
131 SEN_OV76BE,
132 SEN_OV8610,
133};
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300134
Hans de Goedea511ba92009-10-16 07:13:07 -0300135/* Note this is a bit of a hack, but the w9968cf driver needs the code for all
136 the ov sensors which is already present here. When we have the time we
137 really should move the sensor drivers to v4l2 sub drivers. */
138#include "w996Xcf.c"
139
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300140/* V4L2 controls supported by the driver */
Hans de Goede49809d62009-06-07 12:10:39 -0300141static void setbrightness(struct gspca_dev *gspca_dev);
142static void setcontrast(struct gspca_dev *gspca_dev);
143static void setcolors(struct gspca_dev *gspca_dev);
Jean-François Moine62833ac2010-10-02 04:27:02 -0300144static void sethvflip(struct gspca_dev *gspca_dev);
145static void setautobright(struct gspca_dev *gspca_dev);
146static void setfreq(struct gspca_dev *gspca_dev);
147static void setfreq_i(struct sd *sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300148
Hans de Goede02ab18b2009-06-14 04:32:04 -0300149static const struct ctrl sd_ctrls[] = {
Jean-François Moine62833ac2010-10-02 04:27:02 -0300150[BRIGHTNESS] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300151 {
152 .id = V4L2_CID_BRIGHTNESS,
153 .type = V4L2_CTRL_TYPE_INTEGER,
154 .name = "Brightness",
155 .minimum = 0,
156 .maximum = 255,
157 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300158 .default_value = 127,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300159 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300160 .set_control = setbrightness,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300161 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300162[CONTRAST] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300163 {
164 .id = V4L2_CID_CONTRAST,
165 .type = V4L2_CTRL_TYPE_INTEGER,
166 .name = "Contrast",
167 .minimum = 0,
168 .maximum = 255,
169 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300170 .default_value = 127,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300171 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300172 .set_control = setcontrast,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300173 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300174[COLORS] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300175 {
176 .id = V4L2_CID_SATURATION,
177 .type = V4L2_CTRL_TYPE_INTEGER,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300178 .name = "Color",
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300179 .minimum = 0,
180 .maximum = 255,
181 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300182 .default_value = 127,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300183 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300184 .set_control = setcolors,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300185 },
Hans de Goede02ab18b2009-06-14 04:32:04 -0300186/* The flip controls work with ov7670 only */
Jean-François Moine62833ac2010-10-02 04:27:02 -0300187[HFLIP] = {
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300188 {
189 .id = V4L2_CID_HFLIP,
190 .type = V4L2_CTRL_TYPE_BOOLEAN,
191 .name = "Mirror",
192 .minimum = 0,
193 .maximum = 1,
194 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300195 .default_value = 0,
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300196 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300197 .set_control = sethvflip,
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300198 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300199[VFLIP] = {
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300200 {
201 .id = V4L2_CID_VFLIP,
202 .type = V4L2_CTRL_TYPE_BOOLEAN,
203 .name = "Vflip",
204 .minimum = 0,
205 .maximum = 1,
206 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300207 .default_value = 0,
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300208 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300209 .set_control = sethvflip,
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300210 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300211[AUTOBRIGHT] = {
Hans de Goede02ab18b2009-06-14 04:32:04 -0300212 {
213 .id = V4L2_CID_AUTOBRIGHTNESS,
214 .type = V4L2_CTRL_TYPE_BOOLEAN,
215 .name = "Auto Brightness",
216 .minimum = 0,
217 .maximum = 1,
218 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300219 .default_value = 1,
Hans de Goede02ab18b2009-06-14 04:32:04 -0300220 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300221 .set_control = setautobright,
Hans de Goede02ab18b2009-06-14 04:32:04 -0300222 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300223[FREQ] = {
Hans de Goede02ab18b2009-06-14 04:32:04 -0300224 {
225 .id = V4L2_CID_POWER_LINE_FREQUENCY,
226 .type = V4L2_CTRL_TYPE_MENU,
227 .name = "Light frequency filter",
228 .minimum = 0,
Jean-François Moine87bae742010-11-12 05:31:34 -0300229 .maximum = 2, /* 0: no flicker, 1: 50Hz, 2:60Hz, 3: auto */
Hans de Goede02ab18b2009-06-14 04:32:04 -0300230 .step = 1,
Jean-François Moine62833ac2010-10-02 04:27:02 -0300231 .default_value = 0,
Hans de Goede02ab18b2009-06-14 04:32:04 -0300232 },
Jean-François Moine62833ac2010-10-02 04:27:02 -0300233 .set_control = setfreq,
Hans de Goede02ab18b2009-06-14 04:32:04 -0300234 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300235};
236
Jean-François Moine83db7682010-11-12 07:14:08 -0300237/* table of the disabled controls */
238static const unsigned ctrl_dis[] = {
239[SEN_OV2610] = (1 << NCTRL) - 1, /* no control */
240
241[SEN_OV3610] = (1 << NCTRL) - 1, /* no control */
242
243[SEN_OV6620] = (1 << HFLIP) |
244 (1 << VFLIP),
245
246[SEN_OV6630] = (1 << HFLIP) |
247 (1 << VFLIP),
248
249[SEN_OV66308AF] = (1 << HFLIP) |
250 (1 << VFLIP),
251
252[SEN_OV7610] = (1 << HFLIP) |
253 (1 << VFLIP),
254
255[SEN_OV7620] = (1 << HFLIP) |
256 (1 << VFLIP),
257
258[SEN_OV7620AE] = (1 << HFLIP) |
259 (1 << VFLIP),
260
261[SEN_OV7640] = (1 << HFLIP) |
262 (1 << VFLIP) |
263 (1 << AUTOBRIGHT) |
264 (1 << CONTRAST),
265
266[SEN_OV7648] = (1 << HFLIP) |
267 (1 << VFLIP) |
268 (1 << AUTOBRIGHT) |
269 (1 << CONTRAST),
270
271[SEN_OV7670] = (1 << COLORS) |
272 (1 << AUTOBRIGHT),
273
274[SEN_OV76BE] = (1 << HFLIP) |
275 (1 << VFLIP),
276
277[SEN_OV8610] = (1 << HFLIP) |
278 (1 << VFLIP) |
279 (1 << FREQ),
280};
281
Hans de Goede49809d62009-06-07 12:10:39 -0300282static const struct v4l2_pix_format ov519_vga_mode[] = {
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300283 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
284 .bytesperline = 320,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300285 .sizeimage = 320 * 240 * 3 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300286 .colorspace = V4L2_COLORSPACE_JPEG,
287 .priv = 1},
288 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
289 .bytesperline = 640,
290 .sizeimage = 640 * 480 * 3 / 8 + 590,
291 .colorspace = V4L2_COLORSPACE_JPEG,
292 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300293};
Hans de Goede49809d62009-06-07 12:10:39 -0300294static const struct v4l2_pix_format ov519_sif_mode[] = {
Hans de Goede124cc9c2009-06-14 05:48:00 -0300295 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
296 .bytesperline = 160,
297 .sizeimage = 160 * 120 * 3 / 8 + 590,
298 .colorspace = V4L2_COLORSPACE_JPEG,
299 .priv = 3},
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300300 {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
301 .bytesperline = 176,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300302 .sizeimage = 176 * 144 * 3 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300303 .colorspace = V4L2_COLORSPACE_JPEG,
304 .priv = 1},
Hans de Goede124cc9c2009-06-14 05:48:00 -0300305 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
306 .bytesperline = 320,
307 .sizeimage = 320 * 240 * 3 / 8 + 590,
308 .colorspace = V4L2_COLORSPACE_JPEG,
309 .priv = 2},
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300310 {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
311 .bytesperline = 352,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300312 .sizeimage = 352 * 288 * 3 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300313 .colorspace = V4L2_COLORSPACE_JPEG,
314 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300315};
316
Hans de Goedeb282d872009-06-14 19:10:40 -0300317/* Note some of the sizeimage values for the ov511 / ov518 may seem
318 larger then necessary, however they need to be this big as the ov511 /
319 ov518 always fills the entire isoc frame, using 0 padding bytes when
320 it doesn't have any data. So with low framerates the amount of data
321 transfered can become quite large (libv4l will remove all the 0 padding
322 in userspace). */
Hans de Goede49809d62009-06-07 12:10:39 -0300323static const struct v4l2_pix_format ov518_vga_mode[] = {
324 {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
325 .bytesperline = 320,
Hans de Goedeb282d872009-06-14 19:10:40 -0300326 .sizeimage = 320 * 240 * 3,
Hans de Goede49809d62009-06-07 12:10:39 -0300327 .colorspace = V4L2_COLORSPACE_JPEG,
328 .priv = 1},
329 {640, 480, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
330 .bytesperline = 640,
Hans de Goedeb282d872009-06-14 19:10:40 -0300331 .sizeimage = 640 * 480 * 2,
Hans de Goede49809d62009-06-07 12:10:39 -0300332 .colorspace = V4L2_COLORSPACE_JPEG,
333 .priv = 0},
334};
335static const struct v4l2_pix_format ov518_sif_mode[] = {
Hans de Goede124cc9c2009-06-14 05:48:00 -0300336 {160, 120, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
337 .bytesperline = 160,
Hans de Goedeb282d872009-06-14 19:10:40 -0300338 .sizeimage = 70000,
Hans de Goede124cc9c2009-06-14 05:48:00 -0300339 .colorspace = V4L2_COLORSPACE_JPEG,
340 .priv = 3},
Hans de Goede49809d62009-06-07 12:10:39 -0300341 {176, 144, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
342 .bytesperline = 176,
Hans de Goedeb282d872009-06-14 19:10:40 -0300343 .sizeimage = 70000,
Hans de Goede49809d62009-06-07 12:10:39 -0300344 .colorspace = V4L2_COLORSPACE_JPEG,
345 .priv = 1},
Hans de Goede124cc9c2009-06-14 05:48:00 -0300346 {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
347 .bytesperline = 320,
Hans de Goedeb282d872009-06-14 19:10:40 -0300348 .sizeimage = 320 * 240 * 3,
Hans de Goede124cc9c2009-06-14 05:48:00 -0300349 .colorspace = V4L2_COLORSPACE_JPEG,
350 .priv = 2},
Hans de Goede49809d62009-06-07 12:10:39 -0300351 {352, 288, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
352 .bytesperline = 352,
Hans de Goedeb282d872009-06-14 19:10:40 -0300353 .sizeimage = 352 * 288 * 3,
Hans de Goede49809d62009-06-07 12:10:39 -0300354 .colorspace = V4L2_COLORSPACE_JPEG,
355 .priv = 0},
356};
357
Hans de Goede1876bb92009-06-14 06:45:50 -0300358static const struct v4l2_pix_format ov511_vga_mode[] = {
359 {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
360 .bytesperline = 320,
361 .sizeimage = 320 * 240 * 3,
362 .colorspace = V4L2_COLORSPACE_JPEG,
363 .priv = 1},
364 {640, 480, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
365 .bytesperline = 640,
366 .sizeimage = 640 * 480 * 2,
367 .colorspace = V4L2_COLORSPACE_JPEG,
368 .priv = 0},
369};
370static const struct v4l2_pix_format ov511_sif_mode[] = {
371 {160, 120, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
372 .bytesperline = 160,
Hans de Goedeb282d872009-06-14 19:10:40 -0300373 .sizeimage = 70000,
Hans de Goede1876bb92009-06-14 06:45:50 -0300374 .colorspace = V4L2_COLORSPACE_JPEG,
375 .priv = 3},
376 {176, 144, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
377 .bytesperline = 176,
Hans de Goedeb282d872009-06-14 19:10:40 -0300378 .sizeimage = 70000,
Hans de Goede1876bb92009-06-14 06:45:50 -0300379 .colorspace = V4L2_COLORSPACE_JPEG,
380 .priv = 1},
381 {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
382 .bytesperline = 320,
383 .sizeimage = 320 * 240 * 3,
384 .colorspace = V4L2_COLORSPACE_JPEG,
385 .priv = 2},
386 {352, 288, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
387 .bytesperline = 352,
388 .sizeimage = 352 * 288 * 3,
389 .colorspace = V4L2_COLORSPACE_JPEG,
390 .priv = 0},
391};
Hans de Goede49809d62009-06-07 12:10:39 -0300392
Hans de Goede635118d2009-10-11 09:49:03 -0300393static const struct v4l2_pix_format ovfx2_vga_mode[] = {
394 {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
395 .bytesperline = 320,
396 .sizeimage = 320 * 240,
397 .colorspace = V4L2_COLORSPACE_SRGB,
398 .priv = 1},
399 {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
400 .bytesperline = 640,
401 .sizeimage = 640 * 480,
402 .colorspace = V4L2_COLORSPACE_SRGB,
403 .priv = 0},
404};
405static const struct v4l2_pix_format ovfx2_cif_mode[] = {
406 {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
407 .bytesperline = 160,
408 .sizeimage = 160 * 120,
409 .colorspace = V4L2_COLORSPACE_SRGB,
410 .priv = 3},
411 {176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
412 .bytesperline = 176,
413 .sizeimage = 176 * 144,
414 .colorspace = V4L2_COLORSPACE_SRGB,
415 .priv = 1},
416 {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
417 .bytesperline = 320,
418 .sizeimage = 320 * 240,
419 .colorspace = V4L2_COLORSPACE_SRGB,
420 .priv = 2},
421 {352, 288, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
422 .bytesperline = 352,
423 .sizeimage = 352 * 288,
424 .colorspace = V4L2_COLORSPACE_SRGB,
425 .priv = 0},
426};
427static const struct v4l2_pix_format ovfx2_ov2610_mode[] = {
428 {1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
429 .bytesperline = 1600,
430 .sizeimage = 1600 * 1200,
431 .colorspace = V4L2_COLORSPACE_SRGB},
432};
433static const struct v4l2_pix_format ovfx2_ov3610_mode[] = {
Hans de Goede635118d2009-10-11 09:49:03 -0300434 {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
435 .bytesperline = 640,
436 .sizeimage = 640 * 480,
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300437 .colorspace = V4L2_COLORSPACE_SRGB,
438 .priv = 1},
439 {800, 600, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
440 .bytesperline = 800,
441 .sizeimage = 800 * 600,
442 .colorspace = V4L2_COLORSPACE_SRGB,
443 .priv = 1},
444 {1024, 768, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
445 .bytesperline = 1024,
446 .sizeimage = 1024 * 768,
447 .colorspace = V4L2_COLORSPACE_SRGB,
448 .priv = 1},
449 {1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
450 .bytesperline = 1600,
451 .sizeimage = 1600 * 1200,
452 .colorspace = V4L2_COLORSPACE_SRGB,
453 .priv = 0},
454 {2048, 1536, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
455 .bytesperline = 2048,
456 .sizeimage = 2048 * 1536,
457 .colorspace = V4L2_COLORSPACE_SRGB,
458 .priv = 0},
Hans de Goede635118d2009-10-11 09:49:03 -0300459};
460
Hans de Goede49809d62009-06-07 12:10:39 -0300461/* Registers common to OV511 / OV518 */
Hans de Goede1876bb92009-06-14 06:45:50 -0300462#define R51x_FIFO_PSIZE 0x30 /* 2 bytes wide w/ OV518(+) */
Jean-François Moine780e3122010-10-19 04:29:10 -0300463#define R51x_SYS_RESET 0x50
Hans de Goede1876bb92009-06-14 06:45:50 -0300464 /* Reset type flags */
465 #define OV511_RESET_OMNICE 0x08
Jean-François Moine780e3122010-10-19 04:29:10 -0300466#define R51x_SYS_INIT 0x53
Hans de Goede49809d62009-06-07 12:10:39 -0300467#define R51x_SYS_SNAP 0x52
Jean-François Moine87bae742010-11-12 05:31:34 -0300468#define R51x_SYS_CUST_ID 0x5f
Hans de Goede49809d62009-06-07 12:10:39 -0300469#define R51x_COMP_LUT_BEGIN 0x80
470
471/* OV511 Camera interface register numbers */
Hans de Goede1876bb92009-06-14 06:45:50 -0300472#define R511_CAM_DELAY 0x10
473#define R511_CAM_EDGE 0x11
474#define R511_CAM_PXCNT 0x12
475#define R511_CAM_LNCNT 0x13
476#define R511_CAM_PXDIV 0x14
477#define R511_CAM_LNDIV 0x15
478#define R511_CAM_UV_EN 0x16
479#define R511_CAM_LINE_MODE 0x17
480#define R511_CAM_OPTS 0x18
481
482#define R511_SNAP_FRAME 0x19
Jean-François Moine87bae742010-11-12 05:31:34 -0300483#define R511_SNAP_PXCNT 0x1a
484#define R511_SNAP_LNCNT 0x1b
485#define R511_SNAP_PXDIV 0x1c
486#define R511_SNAP_LNDIV 0x1d
487#define R511_SNAP_UV_EN 0x1e
488#define R511_SNAP_UV_EN 0x1e
489#define R511_SNAP_OPTS 0x1f
Hans de Goede1876bb92009-06-14 06:45:50 -0300490
491#define R511_DRAM_FLOW_CTL 0x20
492#define R511_FIFO_OPTS 0x31
493#define R511_I2C_CTL 0x40
Hans de Goede49809d62009-06-07 12:10:39 -0300494#define R511_SYS_LED_CTL 0x55 /* OV511+ only */
Hans de Goede1876bb92009-06-14 06:45:50 -0300495#define R511_COMP_EN 0x78
496#define R511_COMP_LUT_EN 0x79
Hans de Goede49809d62009-06-07 12:10:39 -0300497
498/* OV518 Camera interface register numbers */
499#define R518_GPIO_OUT 0x56 /* OV518(+) only */
500#define R518_GPIO_CTL 0x57 /* OV518(+) only */
501
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300502/* OV519 Camera interface register numbers */
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300503#define OV519_R10_H_SIZE 0x10
504#define OV519_R11_V_SIZE 0x11
505#define OV519_R12_X_OFFSETL 0x12
506#define OV519_R13_X_OFFSETH 0x13
507#define OV519_R14_Y_OFFSETL 0x14
508#define OV519_R15_Y_OFFSETH 0x15
509#define OV519_R16_DIVIDER 0x16
510#define OV519_R20_DFR 0x20
511#define OV519_R25_FORMAT 0x25
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300512
513/* OV519 System Controller register numbers */
Jean-François Moine21867802010-11-12 06:12:09 -0300514#define OV519_R51_RESET1 0x51
515#define OV519_R54_EN_CLK1 0x54
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300516
517#define OV519_GPIO_DATA_OUT0 0x71
518#define OV519_GPIO_IO_CTRL0 0x72
519
Jean-François Moine87bae742010-11-12 05:31:34 -0300520/*#define OV511_ENDPOINT_ADDRESS 1 * Isoc endpoint number */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300521
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300522/*
523 * The FX2 chip does not give us a zero length read at end of frame.
524 * It does, however, give a short read at the end of a frame, if
Daniel Mack3ad2f3f2010-02-03 08:01:28 +0800525 * necessary, rather than run two frames together.
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300526 *
527 * By choosing the right bulk transfer size, we are guaranteed to always
528 * get a short read for the last read of each frame. Frame sizes are
529 * always a composite number (width * height, or a multiple) so if we
530 * choose a prime number, we are guaranteed that the last read of a
531 * frame will be short.
532 *
533 * But it isn't that easy: the 2.6 kernel requires a multiple of 4KB,
534 * otherwise EOVERFLOW "babbling" errors occur. I have not been able
535 * to figure out why. [PMiller]
536 *
537 * The constant (13 * 4096) is the largest "prime enough" number less than 64KB.
538 *
539 * It isn't enough to know the number of bytes per frame, in case we
540 * have data dropouts or buffer overruns (even though the FX2 double
541 * buffers, there are some pretty strict real time constraints for
542 * isochronous transfer for larger frame sizes).
543 */
544#define OVFX2_BULK_SIZE (13 * 4096)
545
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300546/* I2C registers */
547#define R51x_I2C_W_SID 0x41
548#define R51x_I2C_SADDR_3 0x42
549#define R51x_I2C_SADDR_2 0x43
550#define R51x_I2C_R_SID 0x44
551#define R51x_I2C_DATA 0x45
552#define R518_I2C_CTL 0x47 /* OV518(+) only */
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300553#define OVFX2_I2C_ADDR 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300554
555/* I2C ADDRESSES */
556#define OV7xx0_SID 0x42
Hans de Goede229bb7d2009-10-11 07:41:46 -0300557#define OV_HIRES_SID 0x60 /* OV9xxx / OV2xxx / OV3xxx */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300558#define OV8xx0_SID 0xa0
559#define OV6xx0_SID 0xc0
560
561/* OV7610 registers */
562#define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */
Hans de Goede49809d62009-06-07 12:10:39 -0300563#define OV7610_REG_BLUE 0x01 /* blue channel balance */
564#define OV7610_REG_RED 0x02 /* red channel balance */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300565#define OV7610_REG_SAT 0x03 /* saturation */
566#define OV8610_REG_HUE 0x04 /* 04 reserved */
567#define OV7610_REG_CNT 0x05 /* Y contrast */
568#define OV7610_REG_BRT 0x06 /* Y brightness */
569#define OV7610_REG_COM_C 0x14 /* misc common regs */
570#define OV7610_REG_ID_HIGH 0x1c /* manufacturer ID MSB */
571#define OV7610_REG_ID_LOW 0x1d /* manufacturer ID LSB */
572#define OV7610_REG_COM_I 0x29 /* misc settings */
573
574/* OV7670 registers */
Jean-François Moine21867802010-11-12 06:12:09 -0300575#define OV7670_R00_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
576#define OV7670_R01_BLUE 0x01 /* blue gain */
577#define OV7670_R02_RED 0x02 /* red gain */
578#define OV7670_R03_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */
579#define OV7670_R04_COM1 0x04 /* Control 1 */
580/*#define OV7670_R07_AECHH 0x07 * AEC MS 5 bits */
581#define OV7670_R0C_COM3 0x0c /* Control 3 */
582#define OV7670_R0D_COM4 0x0d /* Control 4 */
583#define OV7670_R0E_COM5 0x0e /* All "reserved" */
584#define OV7670_R0F_COM6 0x0f /* Control 6 */
585#define OV7670_R10_AECH 0x10 /* More bits of AEC value */
586#define OV7670_R11_CLKRC 0x11 /* Clock control */
587#define OV7670_R12_COM7 0x12 /* Control 7 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300588#define OV7670_COM7_FMT_VGA 0x00
589/*#define OV7670_COM7_YUV 0x00 * YUV */
590#define OV7670_COM7_FMT_QVGA 0x10 /* QVGA format */
591#define OV7670_COM7_FMT_MASK 0x38
592#define OV7670_COM7_RESET 0x80 /* Register reset */
Jean-François Moine21867802010-11-12 06:12:09 -0300593#define OV7670_R13_COM8 0x13 /* Control 8 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300594#define OV7670_COM8_AEC 0x01 /* Auto exposure enable */
595#define OV7670_COM8_AWB 0x02 /* White balance enable */
596#define OV7670_COM8_AGC 0x04 /* Auto gain enable */
597#define OV7670_COM8_BFILT 0x20 /* Band filter enable */
598#define OV7670_COM8_AECSTEP 0x40 /* Unlimited AEC step size */
599#define OV7670_COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
Jean-François Moine21867802010-11-12 06:12:09 -0300600#define OV7670_R14_COM9 0x14 /* Control 9 - gain ceiling */
601#define OV7670_R15_COM10 0x15 /* Control 10 */
602#define OV7670_R17_HSTART 0x17 /* Horiz start high bits */
603#define OV7670_R18_HSTOP 0x18 /* Horiz stop high bits */
604#define OV7670_R19_VSTART 0x19 /* Vert start high bits */
605#define OV7670_R1A_VSTOP 0x1a /* Vert stop high bits */
606#define OV7670_R1E_MVFP 0x1e /* Mirror / vflip */
Jean-François Moine87bae742010-11-12 05:31:34 -0300607#define OV7670_MVFP_VFLIP 0x10 /* vertical flip */
608#define OV7670_MVFP_MIRROR 0x20 /* Mirror image */
Jean-François Moine21867802010-11-12 06:12:09 -0300609#define OV7670_R24_AEW 0x24 /* AGC upper limit */
610#define OV7670_R25_AEB 0x25 /* AGC lower limit */
611#define OV7670_R26_VPT 0x26 /* AGC/AEC fast mode op region */
612#define OV7670_R32_HREF 0x32 /* HREF pieces */
613#define OV7670_R3A_TSLB 0x3a /* lots of stuff */
614#define OV7670_R3B_COM11 0x3b /* Control 11 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300615#define OV7670_COM11_EXP 0x02
616#define OV7670_COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */
Jean-François Moine21867802010-11-12 06:12:09 -0300617#define OV7670_R3C_COM12 0x3c /* Control 12 */
618#define OV7670_R3D_COM13 0x3d /* Control 13 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300619#define OV7670_COM13_GAMMA 0x80 /* Gamma enable */
620#define OV7670_COM13_UVSAT 0x40 /* UV saturation auto adjustment */
Jean-François Moine21867802010-11-12 06:12:09 -0300621#define OV7670_R3E_COM14 0x3e /* Control 14 */
622#define OV7670_R3F_EDGE 0x3f /* Edge enhancement factor */
623#define OV7670_R40_COM15 0x40 /* Control 15 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300624/*#define OV7670_COM15_R00FF 0xc0 * 00 to FF */
Jean-François Moine21867802010-11-12 06:12:09 -0300625#define OV7670_R41_COM16 0x41 /* Control 16 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300626#define OV7670_COM16_AWBGAIN 0x08 /* AWB gain enable */
Jean-François Moine21867802010-11-12 06:12:09 -0300627#define OV7670_R55_BRIGHT 0x55 /* Brightness */
628#define OV7670_R56_CONTRAS 0x56 /* Contrast control */
629#define OV7670_R69_GFIX 0x69 /* Fix gain control */
630/*#define OV7670_R8C_RGB444 0x8c * RGB 444 control */
631#define OV7670_R9F_HAECC1 0x9f /* Hist AEC/AGC control 1 */
632#define OV7670_RA0_HAECC2 0xa0 /* Hist AEC/AGC control 2 */
633#define OV7670_RA5_BD50MAX 0xa5 /* 50hz banding step limit */
634#define OV7670_RA6_HAECC3 0xa6 /* Hist AEC/AGC control 3 */
635#define OV7670_RA7_HAECC4 0xa7 /* Hist AEC/AGC control 4 */
636#define OV7670_RA8_HAECC5 0xa8 /* Hist AEC/AGC control 5 */
637#define OV7670_RA9_HAECC6 0xa9 /* Hist AEC/AGC control 6 */
638#define OV7670_RAA_HAECC7 0xaa /* Hist AEC/AGC control 7 */
639#define OV7670_RAB_BD60MAX 0xab /* 60hz banding step limit */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300640
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300641struct ov_regvals {
Jean-François Moine9d1593a2010-11-11 08:04:06 -0300642 u8 reg;
643 u8 val;
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300644};
645struct ov_i2c_regvals {
Jean-François Moine9d1593a2010-11-11 08:04:06 -0300646 u8 reg;
647 u8 val;
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300648};
649
Hans de Goede635118d2009-10-11 09:49:03 -0300650/* Settings for OV2610 camera chip */
Jean-François Moine780e3122010-10-19 04:29:10 -0300651static const struct ov_i2c_regvals norm_2610[] = {
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300652 { 0x12, 0x80 }, /* reset */
Hans de Goede635118d2009-10-11 09:49:03 -0300653};
654
Jean-François Moine780e3122010-10-19 04:29:10 -0300655static const struct ov_i2c_regvals norm_3620b[] = {
Hans de Goede635118d2009-10-11 09:49:03 -0300656 /*
657 * From the datasheet: "Note that after writing to register COMH
658 * (0x12) to change the sensor mode, registers related to the
659 * sensor’s cropping window will be reset back to their default
660 * values."
661 *
662 * "wait 4096 external clock ... to make sure the sensor is
663 * stable and ready to access registers" i.e. 160us at 24MHz
664 */
Hans de Goede635118d2009-10-11 09:49:03 -0300665 { 0x12, 0x80 }, /* COMH reset */
666 { 0x12, 0x00 }, /* QXGA, master */
667
668 /*
669 * 11 CLKRC "Clock Rate Control"
670 * [7] internal frequency doublers: on
671 * [6] video port mode: master
672 * [5:0] clock divider: 1
673 */
674 { 0x11, 0x80 },
675
676 /*
677 * 13 COMI "Common Control I"
678 * = 192 (0xC0) 11000000
679 * COMI[7] "AEC speed selection"
680 * = 1 (0x01) 1....... "Faster AEC correction"
681 * COMI[6] "AEC speed step selection"
682 * = 1 (0x01) .1...... "Big steps, fast"
683 * COMI[5] "Banding filter on off"
684 * = 0 (0x00) ..0..... "Off"
685 * COMI[4] "Banding filter option"
686 * = 0 (0x00) ...0.... "Main clock is 48 MHz and
687 * the PLL is ON"
688 * COMI[3] "Reserved"
689 * = 0 (0x00) ....0...
690 * COMI[2] "AGC auto manual control selection"
691 * = 0 (0x00) .....0.. "Manual"
692 * COMI[1] "AWB auto manual control selection"
693 * = 0 (0x00) ......0. "Manual"
694 * COMI[0] "Exposure control"
695 * = 0 (0x00) .......0 "Manual"
696 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300697 { 0x13, 0xc0 },
Hans de Goede635118d2009-10-11 09:49:03 -0300698
699 /*
700 * 09 COMC "Common Control C"
701 * = 8 (0x08) 00001000
702 * COMC[7:5] "Reserved"
703 * = 0 (0x00) 000.....
704 * COMC[4] "Sleep Mode Enable"
705 * = 0 (0x00) ...0.... "Normal mode"
706 * COMC[3:2] "Sensor sampling reset timing selection"
707 * = 2 (0x02) ....10.. "Longer reset time"
708 * COMC[1:0] "Output drive current select"
709 * = 0 (0x00) ......00 "Weakest"
710 */
711 { 0x09, 0x08 },
712
713 /*
714 * 0C COMD "Common Control D"
715 * = 8 (0x08) 00001000
716 * COMD[7] "Reserved"
717 * = 0 (0x00) 0.......
718 * COMD[6] "Swap MSB and LSB at the output port"
719 * = 0 (0x00) .0...... "False"
720 * COMD[5:3] "Reserved"
721 * = 1 (0x01) ..001...
722 * COMD[2] "Output Average On Off"
723 * = 0 (0x00) .....0.. "Output Normal"
724 * COMD[1] "Sensor precharge voltage selection"
725 * = 0 (0x00) ......0. "Selects internal
726 * reference precharge
727 * voltage"
728 * COMD[0] "Snapshot option"
729 * = 0 (0x00) .......0 "Enable live video output
730 * after snapshot sequence"
731 */
732 { 0x0c, 0x08 },
733
734 /*
735 * 0D COME "Common Control E"
736 * = 161 (0xA1) 10100001
737 * COME[7] "Output average option"
738 * = 1 (0x01) 1....... "Output average of 4 pixels"
739 * COME[6] "Anti-blooming control"
740 * = 0 (0x00) .0...... "Off"
741 * COME[5:3] "Reserved"
742 * = 4 (0x04) ..100...
743 * COME[2] "Clock output power down pin status"
744 * = 0 (0x00) .....0.. "Tri-state data output pin
745 * on power down"
746 * COME[1] "Data output pin status selection at power down"
747 * = 0 (0x00) ......0. "Tri-state VSYNC, PCLK,
748 * HREF, and CHSYNC pins on
749 * power down"
750 * COME[0] "Auto zero circuit select"
751 * = 1 (0x01) .......1 "On"
752 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300753 { 0x0d, 0xa1 },
Hans de Goede635118d2009-10-11 09:49:03 -0300754
755 /*
756 * 0E COMF "Common Control F"
757 * = 112 (0x70) 01110000
758 * COMF[7] "System clock selection"
759 * = 0 (0x00) 0....... "Use 24 MHz system clock"
760 * COMF[6:4] "Reserved"
761 * = 7 (0x07) .111....
762 * COMF[3] "Manual auto negative offset canceling selection"
763 * = 0 (0x00) ....0... "Auto detect negative
764 * offset and cancel it"
765 * COMF[2:0] "Reserved"
766 * = 0 (0x00) .....000
767 */
768 { 0x0e, 0x70 },
769
770 /*
771 * 0F COMG "Common Control G"
772 * = 66 (0x42) 01000010
773 * COMG[7] "Optical black output selection"
774 * = 0 (0x00) 0....... "Disable"
775 * COMG[6] "Black level calibrate selection"
776 * = 1 (0x01) .1...... "Use optical black pixels
777 * to calibrate"
778 * COMG[5:4] "Reserved"
779 * = 0 (0x00) ..00....
780 * COMG[3] "Channel offset adjustment"
781 * = 0 (0x00) ....0... "Disable offset adjustment"
782 * COMG[2] "ADC black level calibration option"
783 * = 0 (0x00) .....0.. "Use B/G line and G/R
784 * line to calibrate each
785 * channel's black level"
786 * COMG[1] "Reserved"
787 * = 1 (0x01) ......1.
788 * COMG[0] "ADC black level calibration enable"
789 * = 0 (0x00) .......0 "Disable"
790 */
791 { 0x0f, 0x42 },
792
793 /*
794 * 14 COMJ "Common Control J"
795 * = 198 (0xC6) 11000110
796 * COMJ[7:6] "AGC gain ceiling"
797 * = 3 (0x03) 11...... "8x"
798 * COMJ[5:4] "Reserved"
799 * = 0 (0x00) ..00....
800 * COMJ[3] "Auto banding filter"
801 * = 0 (0x00) ....0... "Banding filter is always
802 * on off depending on
803 * COMI[5] setting"
804 * COMJ[2] "VSYNC drop option"
805 * = 1 (0x01) .....1.. "SYNC is dropped if frame
806 * data is dropped"
807 * COMJ[1] "Frame data drop"
808 * = 1 (0x01) ......1. "Drop frame data if
809 * exposure is not within
810 * tolerance. In AEC mode,
811 * data is normally dropped
812 * when data is out of
813 * range."
814 * COMJ[0] "Reserved"
815 * = 0 (0x00) .......0
816 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300817 { 0x14, 0xc6 },
Hans de Goede635118d2009-10-11 09:49:03 -0300818
819 /*
820 * 15 COMK "Common Control K"
821 * = 2 (0x02) 00000010
822 * COMK[7] "CHSYNC pin output swap"
823 * = 0 (0x00) 0....... "CHSYNC"
824 * COMK[6] "HREF pin output swap"
825 * = 0 (0x00) .0...... "HREF"
826 * COMK[5] "PCLK output selection"
827 * = 0 (0x00) ..0..... "PCLK always output"
828 * COMK[4] "PCLK edge selection"
829 * = 0 (0x00) ...0.... "Data valid on falling edge"
830 * COMK[3] "HREF output polarity"
831 * = 0 (0x00) ....0... "positive"
832 * COMK[2] "Reserved"
833 * = 0 (0x00) .....0..
834 * COMK[1] "VSYNC polarity"
835 * = 1 (0x01) ......1. "negative"
836 * COMK[0] "HSYNC polarity"
837 * = 0 (0x00) .......0 "positive"
838 */
839 { 0x15, 0x02 },
840
841 /*
842 * 33 CHLF "Current Control"
843 * = 9 (0x09) 00001001
844 * CHLF[7:6] "Sensor current control"
845 * = 0 (0x00) 00......
846 * CHLF[5] "Sensor current range control"
847 * = 0 (0x00) ..0..... "normal range"
848 * CHLF[4] "Sensor current"
849 * = 0 (0x00) ...0.... "normal current"
850 * CHLF[3] "Sensor buffer current control"
851 * = 1 (0x01) ....1... "half current"
852 * CHLF[2] "Column buffer current control"
853 * = 0 (0x00) .....0.. "normal current"
854 * CHLF[1] "Analog DSP current control"
855 * = 0 (0x00) ......0. "normal current"
856 * CHLF[1] "ADC current control"
857 * = 0 (0x00) ......0. "normal current"
858 */
859 { 0x33, 0x09 },
860
861 /*
862 * 34 VBLM "Blooming Control"
863 * = 80 (0x50) 01010000
864 * VBLM[7] "Hard soft reset switch"
865 * = 0 (0x00) 0....... "Hard reset"
866 * VBLM[6:4] "Blooming voltage selection"
867 * = 5 (0x05) .101....
868 * VBLM[3:0] "Sensor current control"
869 * = 0 (0x00) ....0000
870 */
871 { 0x34, 0x50 },
872
873 /*
874 * 36 VCHG "Sensor Precharge Voltage Control"
875 * = 0 (0x00) 00000000
876 * VCHG[7] "Reserved"
877 * = 0 (0x00) 0.......
878 * VCHG[6:4] "Sensor precharge voltage control"
879 * = 0 (0x00) .000....
880 * VCHG[3:0] "Sensor array common reference"
881 * = 0 (0x00) ....0000
882 */
883 { 0x36, 0x00 },
884
885 /*
886 * 37 ADC "ADC Reference Control"
887 * = 4 (0x04) 00000100
888 * ADC[7:4] "Reserved"
889 * = 0 (0x00) 0000....
890 * ADC[3] "ADC input signal range"
891 * = 0 (0x00) ....0... "Input signal 1.0x"
892 * ADC[2:0] "ADC range control"
893 * = 4 (0x04) .....100
894 */
895 { 0x37, 0x04 },
896
897 /*
898 * 38 ACOM "Analog Common Ground"
899 * = 82 (0x52) 01010010
900 * ACOM[7] "Analog gain control"
901 * = 0 (0x00) 0....... "Gain 1x"
902 * ACOM[6] "Analog black level calibration"
903 * = 1 (0x01) .1...... "On"
904 * ACOM[5:0] "Reserved"
905 * = 18 (0x12) ..010010
906 */
907 { 0x38, 0x52 },
908
909 /*
910 * 3A FREFA "Internal Reference Adjustment"
911 * = 0 (0x00) 00000000
912 * FREFA[7:0] "Range"
913 * = 0 (0x00) 00000000
914 */
915 { 0x3a, 0x00 },
916
917 /*
918 * 3C FVOPT "Internal Reference Adjustment"
919 * = 31 (0x1F) 00011111
920 * FVOPT[7:0] "Range"
921 * = 31 (0x1F) 00011111
922 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300923 { 0x3c, 0x1f },
Hans de Goede635118d2009-10-11 09:49:03 -0300924
925 /*
926 * 44 Undocumented = 0 (0x00) 00000000
927 * 44[7:0] "It's a secret"
928 * = 0 (0x00) 00000000
929 */
930 { 0x44, 0x00 },
931
932 /*
933 * 40 Undocumented = 0 (0x00) 00000000
934 * 40[7:0] "It's a secret"
935 * = 0 (0x00) 00000000
936 */
937 { 0x40, 0x00 },
938
939 /*
940 * 41 Undocumented = 0 (0x00) 00000000
941 * 41[7:0] "It's a secret"
942 * = 0 (0x00) 00000000
943 */
944 { 0x41, 0x00 },
945
946 /*
947 * 42 Undocumented = 0 (0x00) 00000000
948 * 42[7:0] "It's a secret"
949 * = 0 (0x00) 00000000
950 */
951 { 0x42, 0x00 },
952
953 /*
954 * 43 Undocumented = 0 (0x00) 00000000
955 * 43[7:0] "It's a secret"
956 * = 0 (0x00) 00000000
957 */
958 { 0x43, 0x00 },
959
960 /*
961 * 45 Undocumented = 128 (0x80) 10000000
962 * 45[7:0] "It's a secret"
963 * = 128 (0x80) 10000000
964 */
965 { 0x45, 0x80 },
966
967 /*
968 * 48 Undocumented = 192 (0xC0) 11000000
969 * 48[7:0] "It's a secret"
970 * = 192 (0xC0) 11000000
971 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300972 { 0x48, 0xc0 },
Hans de Goede635118d2009-10-11 09:49:03 -0300973
974 /*
975 * 49 Undocumented = 25 (0x19) 00011001
976 * 49[7:0] "It's a secret"
977 * = 25 (0x19) 00011001
978 */
979 { 0x49, 0x19 },
980
981 /*
982 * 4B Undocumented = 128 (0x80) 10000000
983 * 4B[7:0] "It's a secret"
984 * = 128 (0x80) 10000000
985 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300986 { 0x4b, 0x80 },
Hans de Goede635118d2009-10-11 09:49:03 -0300987
988 /*
989 * 4D Undocumented = 196 (0xC4) 11000100
990 * 4D[7:0] "It's a secret"
991 * = 196 (0xC4) 11000100
992 */
Jean-François Moine87bae742010-11-12 05:31:34 -0300993 { 0x4d, 0xc4 },
Hans de Goede635118d2009-10-11 09:49:03 -0300994
995 /*
996 * 35 VREF "Reference Voltage Control"
Jean-François Moine87bae742010-11-12 05:31:34 -0300997 * = 76 (0x4c) 01001100
Hans de Goede635118d2009-10-11 09:49:03 -0300998 * VREF[7:5] "Column high reference control"
999 * = 2 (0x02) 010..... "higher voltage"
1000 * VREF[4:2] "Column low reference control"
1001 * = 3 (0x03) ...011.. "Highest voltage"
1002 * VREF[1:0] "Reserved"
1003 * = 0 (0x00) ......00
1004 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001005 { 0x35, 0x4c },
Hans de Goede635118d2009-10-11 09:49:03 -03001006
1007 /*
1008 * 3D Undocumented = 0 (0x00) 00000000
1009 * 3D[7:0] "It's a secret"
1010 * = 0 (0x00) 00000000
1011 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001012 { 0x3d, 0x00 },
Hans de Goede635118d2009-10-11 09:49:03 -03001013
1014 /*
1015 * 3E Undocumented = 0 (0x00) 00000000
1016 * 3E[7:0] "It's a secret"
1017 * = 0 (0x00) 00000000
1018 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001019 { 0x3e, 0x00 },
Hans de Goede635118d2009-10-11 09:49:03 -03001020
1021 /*
1022 * 3B FREFB "Internal Reference Adjustment"
1023 * = 24 (0x18) 00011000
1024 * FREFB[7:0] "Range"
1025 * = 24 (0x18) 00011000
1026 */
1027 { 0x3b, 0x18 },
1028
1029 /*
1030 * 33 CHLF "Current Control"
1031 * = 25 (0x19) 00011001
1032 * CHLF[7:6] "Sensor current control"
1033 * = 0 (0x00) 00......
1034 * CHLF[5] "Sensor current range control"
1035 * = 0 (0x00) ..0..... "normal range"
1036 * CHLF[4] "Sensor current"
1037 * = 1 (0x01) ...1.... "double current"
1038 * CHLF[3] "Sensor buffer current control"
1039 * = 1 (0x01) ....1... "half current"
1040 * CHLF[2] "Column buffer current control"
1041 * = 0 (0x00) .....0.. "normal current"
1042 * CHLF[1] "Analog DSP current control"
1043 * = 0 (0x00) ......0. "normal current"
1044 * CHLF[1] "ADC current control"
1045 * = 0 (0x00) ......0. "normal current"
1046 */
1047 { 0x33, 0x19 },
1048
1049 /*
1050 * 34 VBLM "Blooming Control"
1051 * = 90 (0x5A) 01011010
1052 * VBLM[7] "Hard soft reset switch"
1053 * = 0 (0x00) 0....... "Hard reset"
1054 * VBLM[6:4] "Blooming voltage selection"
1055 * = 5 (0x05) .101....
1056 * VBLM[3:0] "Sensor current control"
1057 * = 10 (0x0A) ....1010
1058 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001059 { 0x34, 0x5a },
Hans de Goede635118d2009-10-11 09:49:03 -03001060
1061 /*
1062 * 3B FREFB "Internal Reference Adjustment"
1063 * = 0 (0x00) 00000000
1064 * FREFB[7:0] "Range"
1065 * = 0 (0x00) 00000000
1066 */
1067 { 0x3b, 0x00 },
1068
1069 /*
1070 * 33 CHLF "Current Control"
1071 * = 9 (0x09) 00001001
1072 * CHLF[7:6] "Sensor current control"
1073 * = 0 (0x00) 00......
1074 * CHLF[5] "Sensor current range control"
1075 * = 0 (0x00) ..0..... "normal range"
1076 * CHLF[4] "Sensor current"
1077 * = 0 (0x00) ...0.... "normal current"
1078 * CHLF[3] "Sensor buffer current control"
1079 * = 1 (0x01) ....1... "half current"
1080 * CHLF[2] "Column buffer current control"
1081 * = 0 (0x00) .....0.. "normal current"
1082 * CHLF[1] "Analog DSP current control"
1083 * = 0 (0x00) ......0. "normal current"
1084 * CHLF[1] "ADC current control"
1085 * = 0 (0x00) ......0. "normal current"
1086 */
1087 { 0x33, 0x09 },
1088
1089 /*
1090 * 34 VBLM "Blooming Control"
1091 * = 80 (0x50) 01010000
1092 * VBLM[7] "Hard soft reset switch"
1093 * = 0 (0x00) 0....... "Hard reset"
1094 * VBLM[6:4] "Blooming voltage selection"
1095 * = 5 (0x05) .101....
1096 * VBLM[3:0] "Sensor current control"
1097 * = 0 (0x00) ....0000
1098 */
1099 { 0x34, 0x50 },
1100
1101 /*
1102 * 12 COMH "Common Control H"
1103 * = 64 (0x40) 01000000
1104 * COMH[7] "SRST"
1105 * = 0 (0x00) 0....... "No-op"
1106 * COMH[6:4] "Resolution selection"
1107 * = 4 (0x04) .100.... "XGA"
1108 * COMH[3] "Master slave selection"
1109 * = 0 (0x00) ....0... "Master mode"
1110 * COMH[2] "Internal B/R channel option"
1111 * = 0 (0x00) .....0.. "B/R use same channel"
1112 * COMH[1] "Color bar test pattern"
1113 * = 0 (0x00) ......0. "Off"
1114 * COMH[0] "Reserved"
1115 * = 0 (0x00) .......0
1116 */
1117 { 0x12, 0x40 },
1118
1119 /*
1120 * 17 HREFST "Horizontal window start"
1121 * = 31 (0x1F) 00011111
1122 * HREFST[7:0] "Horizontal window start, 8 MSBs"
1123 * = 31 (0x1F) 00011111
1124 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001125 { 0x17, 0x1f },
Hans de Goede635118d2009-10-11 09:49:03 -03001126
1127 /*
1128 * 18 HREFEND "Horizontal window end"
1129 * = 95 (0x5F) 01011111
1130 * HREFEND[7:0] "Horizontal Window End, 8 MSBs"
1131 * = 95 (0x5F) 01011111
1132 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001133 { 0x18, 0x5f },
Hans de Goede635118d2009-10-11 09:49:03 -03001134
1135 /*
1136 * 19 VSTRT "Vertical window start"
1137 * = 0 (0x00) 00000000
1138 * VSTRT[7:0] "Vertical Window Start, 8 MSBs"
1139 * = 0 (0x00) 00000000
1140 */
1141 { 0x19, 0x00 },
1142
1143 /*
1144 * 1A VEND "Vertical window end"
1145 * = 96 (0x60) 01100000
1146 * VEND[7:0] "Vertical Window End, 8 MSBs"
1147 * = 96 (0x60) 01100000
1148 */
1149 { 0x1a, 0x60 },
1150
1151 /*
1152 * 32 COMM "Common Control M"
1153 * = 18 (0x12) 00010010
1154 * COMM[7:6] "Pixel clock divide option"
1155 * = 0 (0x00) 00...... "/1"
1156 * COMM[5:3] "Horizontal window end position, 3 LSBs"
1157 * = 2 (0x02) ..010...
1158 * COMM[2:0] "Horizontal window start position, 3 LSBs"
1159 * = 2 (0x02) .....010
1160 */
1161 { 0x32, 0x12 },
1162
1163 /*
1164 * 03 COMA "Common Control A"
1165 * = 74 (0x4A) 01001010
1166 * COMA[7:4] "AWB Update Threshold"
1167 * = 4 (0x04) 0100....
1168 * COMA[3:2] "Vertical window end line control 2 LSBs"
1169 * = 2 (0x02) ....10..
1170 * COMA[1:0] "Vertical window start line control 2 LSBs"
1171 * = 2 (0x02) ......10
1172 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001173 { 0x03, 0x4a },
Hans de Goede635118d2009-10-11 09:49:03 -03001174
1175 /*
1176 * 11 CLKRC "Clock Rate Control"
1177 * = 128 (0x80) 10000000
1178 * CLKRC[7] "Internal frequency doublers on off seclection"
1179 * = 1 (0x01) 1....... "On"
1180 * CLKRC[6] "Digital video master slave selection"
1181 * = 0 (0x00) .0...... "Master mode, sensor
1182 * provides PCLK"
1183 * CLKRC[5:0] "Clock divider { CLK = PCLK/(1+CLKRC[5:0]) }"
1184 * = 0 (0x00) ..000000
1185 */
1186 { 0x11, 0x80 },
1187
1188 /*
1189 * 12 COMH "Common Control H"
1190 * = 0 (0x00) 00000000
1191 * COMH[7] "SRST"
1192 * = 0 (0x00) 0....... "No-op"
1193 * COMH[6:4] "Resolution selection"
1194 * = 0 (0x00) .000.... "QXGA"
1195 * COMH[3] "Master slave selection"
1196 * = 0 (0x00) ....0... "Master mode"
1197 * COMH[2] "Internal B/R channel option"
1198 * = 0 (0x00) .....0.. "B/R use same channel"
1199 * COMH[1] "Color bar test pattern"
1200 * = 0 (0x00) ......0. "Off"
1201 * COMH[0] "Reserved"
1202 * = 0 (0x00) .......0
1203 */
1204 { 0x12, 0x00 },
1205
1206 /*
1207 * 12 COMH "Common Control H"
1208 * = 64 (0x40) 01000000
1209 * COMH[7] "SRST"
1210 * = 0 (0x00) 0....... "No-op"
1211 * COMH[6:4] "Resolution selection"
1212 * = 4 (0x04) .100.... "XGA"
1213 * COMH[3] "Master slave selection"
1214 * = 0 (0x00) ....0... "Master mode"
1215 * COMH[2] "Internal B/R channel option"
1216 * = 0 (0x00) .....0.. "B/R use same channel"
1217 * COMH[1] "Color bar test pattern"
1218 * = 0 (0x00) ......0. "Off"
1219 * COMH[0] "Reserved"
1220 * = 0 (0x00) .......0
1221 */
1222 { 0x12, 0x40 },
1223
1224 /*
1225 * 17 HREFST "Horizontal window start"
1226 * = 31 (0x1F) 00011111
1227 * HREFST[7:0] "Horizontal window start, 8 MSBs"
1228 * = 31 (0x1F) 00011111
1229 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001230 { 0x17, 0x1f },
Hans de Goede635118d2009-10-11 09:49:03 -03001231
1232 /*
1233 * 18 HREFEND "Horizontal window end"
1234 * = 95 (0x5F) 01011111
1235 * HREFEND[7:0] "Horizontal Window End, 8 MSBs"
1236 * = 95 (0x5F) 01011111
1237 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001238 { 0x18, 0x5f },
Hans de Goede635118d2009-10-11 09:49:03 -03001239
1240 /*
1241 * 19 VSTRT "Vertical window start"
1242 * = 0 (0x00) 00000000
1243 * VSTRT[7:0] "Vertical Window Start, 8 MSBs"
1244 * = 0 (0x00) 00000000
1245 */
1246 { 0x19, 0x00 },
1247
1248 /*
1249 * 1A VEND "Vertical window end"
1250 * = 96 (0x60) 01100000
1251 * VEND[7:0] "Vertical Window End, 8 MSBs"
1252 * = 96 (0x60) 01100000
1253 */
1254 { 0x1a, 0x60 },
1255
1256 /*
1257 * 32 COMM "Common Control M"
1258 * = 18 (0x12) 00010010
1259 * COMM[7:6] "Pixel clock divide option"
1260 * = 0 (0x00) 00...... "/1"
1261 * COMM[5:3] "Horizontal window end position, 3 LSBs"
1262 * = 2 (0x02) ..010...
1263 * COMM[2:0] "Horizontal window start position, 3 LSBs"
1264 * = 2 (0x02) .....010
1265 */
1266 { 0x32, 0x12 },
1267
1268 /*
1269 * 03 COMA "Common Control A"
1270 * = 74 (0x4A) 01001010
1271 * COMA[7:4] "AWB Update Threshold"
1272 * = 4 (0x04) 0100....
1273 * COMA[3:2] "Vertical window end line control 2 LSBs"
1274 * = 2 (0x02) ....10..
1275 * COMA[1:0] "Vertical window start line control 2 LSBs"
1276 * = 2 (0x02) ......10
1277 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001278 { 0x03, 0x4a },
Hans de Goede635118d2009-10-11 09:49:03 -03001279
1280 /*
1281 * 02 RED "Red Gain Control"
1282 * = 175 (0xAF) 10101111
1283 * RED[7] "Action"
1284 * = 1 (0x01) 1....... "gain = 1/(1+bitrev([6:0]))"
1285 * RED[6:0] "Value"
1286 * = 47 (0x2F) .0101111
1287 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001288 { 0x02, 0xaf },
Hans de Goede635118d2009-10-11 09:49:03 -03001289
1290 /*
1291 * 2D ADDVSL "VSYNC Pulse Width"
1292 * = 210 (0xD2) 11010010
1293 * ADDVSL[7:0] "VSYNC pulse width, LSB"
1294 * = 210 (0xD2) 11010010
1295 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001296 { 0x2d, 0xd2 },
Hans de Goede635118d2009-10-11 09:49:03 -03001297
1298 /*
1299 * 00 GAIN = 24 (0x18) 00011000
1300 * GAIN[7:6] "Reserved"
1301 * = 0 (0x00) 00......
1302 * GAIN[5] "Double"
1303 * = 0 (0x00) ..0..... "False"
1304 * GAIN[4] "Double"
1305 * = 1 (0x01) ...1.... "True"
1306 * GAIN[3:0] "Range"
1307 * = 8 (0x08) ....1000
1308 */
1309 { 0x00, 0x18 },
1310
1311 /*
1312 * 01 BLUE "Blue Gain Control"
1313 * = 240 (0xF0) 11110000
1314 * BLUE[7] "Action"
1315 * = 1 (0x01) 1....... "gain = 1/(1+bitrev([6:0]))"
1316 * BLUE[6:0] "Value"
1317 * = 112 (0x70) .1110000
1318 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001319 { 0x01, 0xf0 },
Hans de Goede635118d2009-10-11 09:49:03 -03001320
1321 /*
1322 * 10 AEC "Automatic Exposure Control"
1323 * = 10 (0x0A) 00001010
1324 * AEC[7:0] "Automatic Exposure Control, 8 MSBs"
1325 * = 10 (0x0A) 00001010
1326 */
Jean-François Moine87bae742010-11-12 05:31:34 -03001327 { 0x10, 0x0a },
Hans de Goede635118d2009-10-11 09:49:03 -03001328
Jean-François Moine87bae742010-11-12 05:31:34 -03001329 { 0xe1, 0x67 },
1330 { 0xe3, 0x03 },
1331 { 0xe4, 0x26 },
1332 { 0xe5, 0x3e },
1333 { 0xf8, 0x01 },
1334 { 0xff, 0x01 },
Hans de Goede635118d2009-10-11 09:49:03 -03001335};
1336
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001337static const struct ov_i2c_regvals norm_6x20[] = {
1338 { 0x12, 0x80 }, /* reset */
1339 { 0x11, 0x01 },
1340 { 0x03, 0x60 },
1341 { 0x05, 0x7f }, /* For when autoadjust is off */
1342 { 0x07, 0xa8 },
Jean-François Moine87bae742010-11-12 05:31:34 -03001343 /* The ratio of 0x0c and 0x0d controls the white point */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001344 { 0x0c, 0x24 },
1345 { 0x0d, 0x24 },
1346 { 0x0f, 0x15 }, /* COMS */
1347 { 0x10, 0x75 }, /* AEC Exposure time */
1348 { 0x12, 0x24 }, /* Enable AGC */
1349 { 0x14, 0x04 },
1350 /* 0x16: 0x06 helps frame stability with moving objects */
1351 { 0x16, 0x06 },
1352/* { 0x20, 0x30 }, * Aperture correction enable */
1353 { 0x26, 0xb2 }, /* BLC enable */
1354 /* 0x28: 0x05 Selects RGB format if RGB on */
1355 { 0x28, 0x05 },
1356 { 0x2a, 0x04 }, /* Disable framerate adjust */
1357/* { 0x2b, 0xac }, * Framerate; Set 2a[7] first */
Hans de Goedeae49c402009-06-14 19:15:07 -03001358 { 0x2d, 0x85 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001359 { 0x33, 0xa0 }, /* Color Processing Parameter */
1360 { 0x34, 0xd2 }, /* Max A/D range */
1361 { 0x38, 0x8b },
1362 { 0x39, 0x40 },
1363
1364 { 0x3c, 0x39 }, /* Enable AEC mode changing */
1365 { 0x3c, 0x3c }, /* Change AEC mode */
1366 { 0x3c, 0x24 }, /* Disable AEC mode changing */
1367
1368 { 0x3d, 0x80 },
1369 /* These next two registers (0x4a, 0x4b) are undocumented.
1370 * They control the color balance */
1371 { 0x4a, 0x80 },
1372 { 0x4b, 0x80 },
1373 { 0x4d, 0xd2 }, /* This reduces noise a bit */
1374 { 0x4e, 0xc1 },
1375 { 0x4f, 0x04 },
1376/* Do 50-53 have any effect? */
1377/* Toggle 0x12[2] off and on here? */
1378};
1379
1380static const struct ov_i2c_regvals norm_6x30[] = {
1381 { 0x12, 0x80 }, /* Reset */
1382 { 0x00, 0x1f }, /* Gain */
1383 { 0x01, 0x99 }, /* Blue gain */
1384 { 0x02, 0x7c }, /* Red gain */
1385 { 0x03, 0xc0 }, /* Saturation */
1386 { 0x05, 0x0a }, /* Contrast */
1387 { 0x06, 0x95 }, /* Brightness */
1388 { 0x07, 0x2d }, /* Sharpness */
1389 { 0x0c, 0x20 },
1390 { 0x0d, 0x20 },
Hans de Goede02ab18b2009-06-14 04:32:04 -03001391 { 0x0e, 0xa0 }, /* Was 0x20, bit7 enables a 2x gain which we need */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001392 { 0x0f, 0x05 },
1393 { 0x10, 0x9a },
1394 { 0x11, 0x00 }, /* Pixel clock = fastest */
1395 { 0x12, 0x24 }, /* Enable AGC and AWB */
1396 { 0x13, 0x21 },
1397 { 0x14, 0x80 },
1398 { 0x15, 0x01 },
1399 { 0x16, 0x03 },
1400 { 0x17, 0x38 },
1401 { 0x18, 0xea },
1402 { 0x19, 0x04 },
1403 { 0x1a, 0x93 },
1404 { 0x1b, 0x00 },
1405 { 0x1e, 0xc4 },
1406 { 0x1f, 0x04 },
1407 { 0x20, 0x20 },
1408 { 0x21, 0x10 },
1409 { 0x22, 0x88 },
1410 { 0x23, 0xc0 }, /* Crystal circuit power level */
1411 { 0x25, 0x9a }, /* Increase AEC black ratio */
1412 { 0x26, 0xb2 }, /* BLC enable */
1413 { 0x27, 0xa2 },
1414 { 0x28, 0x00 },
1415 { 0x29, 0x00 },
1416 { 0x2a, 0x84 }, /* 60 Hz power */
1417 { 0x2b, 0xa8 }, /* 60 Hz power */
1418 { 0x2c, 0xa0 },
1419 { 0x2d, 0x95 }, /* Enable auto-brightness */
1420 { 0x2e, 0x88 },
1421 { 0x33, 0x26 },
1422 { 0x34, 0x03 },
1423 { 0x36, 0x8f },
1424 { 0x37, 0x80 },
1425 { 0x38, 0x83 },
1426 { 0x39, 0x80 },
1427 { 0x3a, 0x0f },
1428 { 0x3b, 0x3c },
1429 { 0x3c, 0x1a },
1430 { 0x3d, 0x80 },
1431 { 0x3e, 0x80 },
1432 { 0x3f, 0x0e },
1433 { 0x40, 0x00 }, /* White bal */
1434 { 0x41, 0x00 }, /* White bal */
1435 { 0x42, 0x80 },
1436 { 0x43, 0x3f }, /* White bal */
1437 { 0x44, 0x80 },
1438 { 0x45, 0x20 },
1439 { 0x46, 0x20 },
1440 { 0x47, 0x80 },
1441 { 0x48, 0x7f },
1442 { 0x49, 0x00 },
1443 { 0x4a, 0x00 },
1444 { 0x4b, 0x80 },
1445 { 0x4c, 0xd0 },
1446 { 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
1447 { 0x4e, 0x40 },
1448 { 0x4f, 0x07 }, /* UV avg., col. killer: max */
1449 { 0x50, 0xff },
1450 { 0x54, 0x23 }, /* Max AGC gain: 18dB */
1451 { 0x55, 0xff },
1452 { 0x56, 0x12 },
1453 { 0x57, 0x81 },
1454 { 0x58, 0x75 },
1455 { 0x59, 0x01 }, /* AGC dark current comp.: +1 */
1456 { 0x5a, 0x2c },
1457 { 0x5b, 0x0f }, /* AWB chrominance levels */
1458 { 0x5c, 0x10 },
1459 { 0x3d, 0x80 },
1460 { 0x27, 0xa6 },
1461 { 0x12, 0x20 }, /* Toggle AWB */
1462 { 0x12, 0x24 },
1463};
1464
1465/* Lawrence Glaister <lg@jfm.bc.ca> reports:
1466 *
1467 * Register 0x0f in the 7610 has the following effects:
1468 *
1469 * 0x85 (AEC method 1): Best overall, good contrast range
1470 * 0x45 (AEC method 2): Very overexposed
1471 * 0xa5 (spec sheet default): Ok, but the black level is
1472 * shifted resulting in loss of contrast
1473 * 0x05 (old driver setting): very overexposed, too much
1474 * contrast
1475 */
1476static const struct ov_i2c_regvals norm_7610[] = {
1477 { 0x10, 0xff },
1478 { 0x16, 0x06 },
1479 { 0x28, 0x24 },
1480 { 0x2b, 0xac },
1481 { 0x12, 0x00 },
1482 { 0x38, 0x81 },
1483 { 0x28, 0x24 }, /* 0c */
1484 { 0x0f, 0x85 }, /* lg's setting */
1485 { 0x15, 0x01 },
1486 { 0x20, 0x1c },
1487 { 0x23, 0x2a },
1488 { 0x24, 0x10 },
1489 { 0x25, 0x8a },
1490 { 0x26, 0xa2 },
1491 { 0x27, 0xc2 },
1492 { 0x2a, 0x04 },
1493 { 0x2c, 0xfe },
1494 { 0x2d, 0x93 },
1495 { 0x30, 0x71 },
1496 { 0x31, 0x60 },
1497 { 0x32, 0x26 },
1498 { 0x33, 0x20 },
1499 { 0x34, 0x48 },
1500 { 0x12, 0x24 },
1501 { 0x11, 0x01 },
1502 { 0x0c, 0x24 },
1503 { 0x0d, 0x24 },
1504};
1505
1506static const struct ov_i2c_regvals norm_7620[] = {
Hans de Goedea511ba92009-10-16 07:13:07 -03001507 { 0x12, 0x80 }, /* reset */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001508 { 0x00, 0x00 }, /* gain */
1509 { 0x01, 0x80 }, /* blue gain */
1510 { 0x02, 0x80 }, /* red gain */
Jean-François Moine21867802010-11-12 06:12:09 -03001511 { 0x03, 0xc0 }, /* OV7670_R03_VREF */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001512 { 0x06, 0x60 },
1513 { 0x07, 0x00 },
1514 { 0x0c, 0x24 },
1515 { 0x0c, 0x24 },
1516 { 0x0d, 0x24 },
1517 { 0x11, 0x01 },
1518 { 0x12, 0x24 },
1519 { 0x13, 0x01 },
1520 { 0x14, 0x84 },
1521 { 0x15, 0x01 },
1522 { 0x16, 0x03 },
1523 { 0x17, 0x2f },
1524 { 0x18, 0xcf },
1525 { 0x19, 0x06 },
1526 { 0x1a, 0xf5 },
1527 { 0x1b, 0x00 },
1528 { 0x20, 0x18 },
1529 { 0x21, 0x80 },
1530 { 0x22, 0x80 },
1531 { 0x23, 0x00 },
1532 { 0x26, 0xa2 },
1533 { 0x27, 0xea },
Hans de Goedeb282d872009-06-14 19:10:40 -03001534 { 0x28, 0x22 }, /* Was 0x20, bit1 enables a 2x gain which we need */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001535 { 0x29, 0x00 },
1536 { 0x2a, 0x10 },
1537 { 0x2b, 0x00 },
1538 { 0x2c, 0x88 },
1539 { 0x2d, 0x91 },
1540 { 0x2e, 0x80 },
1541 { 0x2f, 0x44 },
1542 { 0x60, 0x27 },
1543 { 0x61, 0x02 },
1544 { 0x62, 0x5f },
1545 { 0x63, 0xd5 },
1546 { 0x64, 0x57 },
1547 { 0x65, 0x83 },
1548 { 0x66, 0x55 },
1549 { 0x67, 0x92 },
1550 { 0x68, 0xcf },
1551 { 0x69, 0x76 },
1552 { 0x6a, 0x22 },
1553 { 0x6b, 0x00 },
1554 { 0x6c, 0x02 },
1555 { 0x6d, 0x44 },
1556 { 0x6e, 0x80 },
1557 { 0x6f, 0x1d },
1558 { 0x70, 0x8b },
1559 { 0x71, 0x00 },
1560 { 0x72, 0x14 },
1561 { 0x73, 0x54 },
1562 { 0x74, 0x00 },
1563 { 0x75, 0x8e },
1564 { 0x76, 0x00 },
1565 { 0x77, 0xff },
1566 { 0x78, 0x80 },
1567 { 0x79, 0x80 },
1568 { 0x7a, 0x80 },
1569 { 0x7b, 0xe2 },
1570 { 0x7c, 0x00 },
1571};
1572
1573/* 7640 and 7648. The defaults should be OK for most registers. */
1574static const struct ov_i2c_regvals norm_7640[] = {
1575 { 0x12, 0x80 },
1576 { 0x12, 0x14 },
1577};
1578
1579/* 7670. Defaults taken from OmniVision provided data,
1580* as provided by Jonathan Corbet of OLPC */
1581static const struct ov_i2c_regvals norm_7670[] = {
Jean-François Moine21867802010-11-12 06:12:09 -03001582 { OV7670_R12_COM7, OV7670_COM7_RESET },
1583 { OV7670_R3A_TSLB, 0x04 }, /* OV */
1584 { OV7670_R12_COM7, OV7670_COM7_FMT_VGA }, /* VGA */
1585 { OV7670_R11_CLKRC, 0x01 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001586/*
1587 * Set the hardware window. These values from OV don't entirely
1588 * make sense - hstop is less than hstart. But they work...
1589 */
Jean-François Moine21867802010-11-12 06:12:09 -03001590 { OV7670_R17_HSTART, 0x13 },
1591 { OV7670_R18_HSTOP, 0x01 },
1592 { OV7670_R32_HREF, 0xb6 },
1593 { OV7670_R19_VSTART, 0x02 },
1594 { OV7670_R1A_VSTOP, 0x7a },
1595 { OV7670_R03_VREF, 0x0a },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001596
Jean-François Moine21867802010-11-12 06:12:09 -03001597 { OV7670_R0C_COM3, 0x00 },
1598 { OV7670_R3E_COM14, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001599/* Mystery scaling numbers */
1600 { 0x70, 0x3a },
1601 { 0x71, 0x35 },
1602 { 0x72, 0x11 },
1603 { 0x73, 0xf0 },
1604 { 0xa2, 0x02 },
Jean-François Moine21867802010-11-12 06:12:09 -03001605/* { OV7670_R15_COM10, 0x0 }, */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001606
1607/* Gamma curve values */
1608 { 0x7a, 0x20 },
1609 { 0x7b, 0x10 },
1610 { 0x7c, 0x1e },
1611 { 0x7d, 0x35 },
1612 { 0x7e, 0x5a },
1613 { 0x7f, 0x69 },
1614 { 0x80, 0x76 },
1615 { 0x81, 0x80 },
1616 { 0x82, 0x88 },
1617 { 0x83, 0x8f },
1618 { 0x84, 0x96 },
1619 { 0x85, 0xa3 },
1620 { 0x86, 0xaf },
1621 { 0x87, 0xc4 },
1622 { 0x88, 0xd7 },
1623 { 0x89, 0xe8 },
1624
1625/* AGC and AEC parameters. Note we start by disabling those features,
1626 then turn them only after tweaking the values. */
Jean-François Moine21867802010-11-12 06:12:09 -03001627 { OV7670_R13_COM8, OV7670_COM8_FASTAEC
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001628 | OV7670_COM8_AECSTEP
1629 | OV7670_COM8_BFILT },
Jean-François Moine21867802010-11-12 06:12:09 -03001630 { OV7670_R00_GAIN, 0x00 },
1631 { OV7670_R10_AECH, 0x00 },
1632 { OV7670_R0D_COM4, 0x40 }, /* magic reserved bit */
1633 { OV7670_R14_COM9, 0x18 }, /* 4x gain + magic rsvd bit */
1634 { OV7670_RA5_BD50MAX, 0x05 },
1635 { OV7670_RAB_BD60MAX, 0x07 },
1636 { OV7670_R24_AEW, 0x95 },
1637 { OV7670_R25_AEB, 0x33 },
1638 { OV7670_R26_VPT, 0xe3 },
1639 { OV7670_R9F_HAECC1, 0x78 },
1640 { OV7670_RA0_HAECC2, 0x68 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001641 { 0xa1, 0x03 }, /* magic */
Jean-François Moine21867802010-11-12 06:12:09 -03001642 { OV7670_RA6_HAECC3, 0xd8 },
1643 { OV7670_RA7_HAECC4, 0xd8 },
1644 { OV7670_RA8_HAECC5, 0xf0 },
1645 { OV7670_RA9_HAECC6, 0x90 },
1646 { OV7670_RAA_HAECC7, 0x94 },
1647 { OV7670_R13_COM8, OV7670_COM8_FASTAEC
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001648 | OV7670_COM8_AECSTEP
1649 | OV7670_COM8_BFILT
1650 | OV7670_COM8_AGC
1651 | OV7670_COM8_AEC },
1652
1653/* Almost all of these are magic "reserved" values. */
Jean-François Moine21867802010-11-12 06:12:09 -03001654 { OV7670_R0E_COM5, 0x61 },
1655 { OV7670_R0F_COM6, 0x4b },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001656 { 0x16, 0x02 },
Jean-François Moine21867802010-11-12 06:12:09 -03001657 { OV7670_R1E_MVFP, 0x07 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001658 { 0x21, 0x02 },
1659 { 0x22, 0x91 },
1660 { 0x29, 0x07 },
1661 { 0x33, 0x0b },
1662 { 0x35, 0x0b },
1663 { 0x37, 0x1d },
1664 { 0x38, 0x71 },
1665 { 0x39, 0x2a },
Jean-François Moine21867802010-11-12 06:12:09 -03001666 { OV7670_R3C_COM12, 0x78 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001667 { 0x4d, 0x40 },
1668 { 0x4e, 0x20 },
Jean-François Moine21867802010-11-12 06:12:09 -03001669 { OV7670_R69_GFIX, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001670 { 0x6b, 0x4a },
1671 { 0x74, 0x10 },
1672 { 0x8d, 0x4f },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001673 { 0x8e, 0x00 },
1674 { 0x8f, 0x00 },
1675 { 0x90, 0x00 },
1676 { 0x91, 0x00 },
1677 { 0x96, 0x00 },
1678 { 0x9a, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001679 { 0xb0, 0x84 },
1680 { 0xb1, 0x0c },
1681 { 0xb2, 0x0e },
1682 { 0xb3, 0x82 },
1683 { 0xb8, 0x0a },
1684
1685/* More reserved magic, some of which tweaks white balance */
1686 { 0x43, 0x0a },
1687 { 0x44, 0xf0 },
1688 { 0x45, 0x34 },
1689 { 0x46, 0x58 },
1690 { 0x47, 0x28 },
1691 { 0x48, 0x3a },
1692 { 0x59, 0x88 },
1693 { 0x5a, 0x88 },
1694 { 0x5b, 0x44 },
1695 { 0x5c, 0x67 },
1696 { 0x5d, 0x49 },
1697 { 0x5e, 0x0e },
1698 { 0x6c, 0x0a },
1699 { 0x6d, 0x55 },
1700 { 0x6e, 0x11 },
1701 { 0x6f, 0x9f },
1702 /* "9e for advance AWB" */
1703 { 0x6a, 0x40 },
Jean-François Moine21867802010-11-12 06:12:09 -03001704 { OV7670_R01_BLUE, 0x40 },
1705 { OV7670_R02_RED, 0x60 },
1706 { OV7670_R13_COM8, OV7670_COM8_FASTAEC
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001707 | OV7670_COM8_AECSTEP
1708 | OV7670_COM8_BFILT
1709 | OV7670_COM8_AGC
1710 | OV7670_COM8_AEC
1711 | OV7670_COM8_AWB },
1712
1713/* Matrix coefficients */
1714 { 0x4f, 0x80 },
1715 { 0x50, 0x80 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001716 { 0x51, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001717 { 0x52, 0x22 },
1718 { 0x53, 0x5e },
1719 { 0x54, 0x80 },
1720 { 0x58, 0x9e },
1721
Jean-François Moine21867802010-11-12 06:12:09 -03001722 { OV7670_R41_COM16, OV7670_COM16_AWBGAIN },
1723 { OV7670_R3F_EDGE, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001724 { 0x75, 0x05 },
1725 { 0x76, 0xe1 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001726 { 0x4c, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001727 { 0x77, 0x01 },
Jean-François Moine21867802010-11-12 06:12:09 -03001728 { OV7670_R3D_COM13, OV7670_COM13_GAMMA
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001729 | OV7670_COM13_UVSAT
1730 | 2}, /* was 3 */
1731 { 0x4b, 0x09 },
1732 { 0xc9, 0x60 },
Jean-François Moine21867802010-11-12 06:12:09 -03001733 { OV7670_R41_COM16, 0x38 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001734 { 0x56, 0x40 },
1735
1736 { 0x34, 0x11 },
Jean-François Moine21867802010-11-12 06:12:09 -03001737 { OV7670_R3B_COM11, OV7670_COM11_EXP|OV7670_COM11_HZAUTO },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001738 { 0xa4, 0x88 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001739 { 0x96, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001740 { 0x97, 0x30 },
1741 { 0x98, 0x20 },
1742 { 0x99, 0x30 },
1743 { 0x9a, 0x84 },
1744 { 0x9b, 0x29 },
1745 { 0x9c, 0x03 },
1746 { 0x9d, 0x4c },
1747 { 0x9e, 0x3f },
1748 { 0x78, 0x04 },
1749
1750/* Extra-weird stuff. Some sort of multiplexor register */
1751 { 0x79, 0x01 },
1752 { 0xc8, 0xf0 },
1753 { 0x79, 0x0f },
1754 { 0xc8, 0x00 },
1755 { 0x79, 0x10 },
1756 { 0xc8, 0x7e },
1757 { 0x79, 0x0a },
1758 { 0xc8, 0x80 },
1759 { 0x79, 0x0b },
1760 { 0xc8, 0x01 },
1761 { 0x79, 0x0c },
1762 { 0xc8, 0x0f },
1763 { 0x79, 0x0d },
1764 { 0xc8, 0x20 },
1765 { 0x79, 0x09 },
1766 { 0xc8, 0x80 },
1767 { 0x79, 0x02 },
1768 { 0xc8, 0xc0 },
1769 { 0x79, 0x03 },
1770 { 0xc8, 0x40 },
1771 { 0x79, 0x05 },
1772 { 0xc8, 0x30 },
1773 { 0x79, 0x26 },
1774};
1775
1776static const struct ov_i2c_regvals norm_8610[] = {
1777 { 0x12, 0x80 },
1778 { 0x00, 0x00 },
1779 { 0x01, 0x80 },
1780 { 0x02, 0x80 },
1781 { 0x03, 0xc0 },
1782 { 0x04, 0x30 },
1783 { 0x05, 0x30 }, /* was 0x10, new from windrv 090403 */
1784 { 0x06, 0x70 }, /* was 0x80, new from windrv 090403 */
1785 { 0x0a, 0x86 },
1786 { 0x0b, 0xb0 },
1787 { 0x0c, 0x20 },
1788 { 0x0d, 0x20 },
1789 { 0x11, 0x01 },
1790 { 0x12, 0x25 },
1791 { 0x13, 0x01 },
1792 { 0x14, 0x04 },
1793 { 0x15, 0x01 }, /* Lin and Win think different about UV order */
1794 { 0x16, 0x03 },
1795 { 0x17, 0x38 }, /* was 0x2f, new from windrv 090403 */
1796 { 0x18, 0xea }, /* was 0xcf, new from windrv 090403 */
1797 { 0x19, 0x02 }, /* was 0x06, new from windrv 090403 */
1798 { 0x1a, 0xf5 },
1799 { 0x1b, 0x00 },
1800 { 0x20, 0xd0 }, /* was 0x90, new from windrv 090403 */
1801 { 0x23, 0xc0 }, /* was 0x00, new from windrv 090403 */
1802 { 0x24, 0x30 }, /* was 0x1d, new from windrv 090403 */
1803 { 0x25, 0x50 }, /* was 0x57, new from windrv 090403 */
1804 { 0x26, 0xa2 },
1805 { 0x27, 0xea },
1806 { 0x28, 0x00 },
1807 { 0x29, 0x00 },
1808 { 0x2a, 0x80 },
1809 { 0x2b, 0xc8 }, /* was 0xcc, new from windrv 090403 */
1810 { 0x2c, 0xac },
1811 { 0x2d, 0x45 }, /* was 0xd5, new from windrv 090403 */
1812 { 0x2e, 0x80 },
1813 { 0x2f, 0x14 }, /* was 0x01, new from windrv 090403 */
1814 { 0x4c, 0x00 },
1815 { 0x4d, 0x30 }, /* was 0x10, new from windrv 090403 */
1816 { 0x60, 0x02 }, /* was 0x01, new from windrv 090403 */
1817 { 0x61, 0x00 }, /* was 0x09, new from windrv 090403 */
1818 { 0x62, 0x5f }, /* was 0xd7, new from windrv 090403 */
1819 { 0x63, 0xff },
1820 { 0x64, 0x53 }, /* new windrv 090403 says 0x57,
1821 * maybe thats wrong */
1822 { 0x65, 0x00 },
1823 { 0x66, 0x55 },
1824 { 0x67, 0xb0 },
1825 { 0x68, 0xc0 }, /* was 0xaf, new from windrv 090403 */
1826 { 0x69, 0x02 },
1827 { 0x6a, 0x22 },
1828 { 0x6b, 0x00 },
1829 { 0x6c, 0x99 }, /* was 0x80, old windrv says 0x00, but
1830 * deleting bit7 colors the first images red */
1831 { 0x6d, 0x11 }, /* was 0x00, new from windrv 090403 */
1832 { 0x6e, 0x11 }, /* was 0x00, new from windrv 090403 */
1833 { 0x6f, 0x01 },
1834 { 0x70, 0x8b },
1835 { 0x71, 0x00 },
1836 { 0x72, 0x14 },
1837 { 0x73, 0x54 },
1838 { 0x74, 0x00 },/* 0x60? - was 0x00, new from windrv 090403 */
1839 { 0x75, 0x0e },
1840 { 0x76, 0x02 }, /* was 0x02, new from windrv 090403 */
1841 { 0x77, 0xff },
1842 { 0x78, 0x80 },
1843 { 0x79, 0x80 },
1844 { 0x7a, 0x80 },
1845 { 0x7b, 0x10 }, /* was 0x13, new from windrv 090403 */
1846 { 0x7c, 0x00 },
1847 { 0x7d, 0x08 }, /* was 0x09, new from windrv 090403 */
1848 { 0x7e, 0x08 }, /* was 0xc0, new from windrv 090403 */
1849 { 0x7f, 0xfb },
1850 { 0x80, 0x28 },
1851 { 0x81, 0x00 },
1852 { 0x82, 0x23 },
1853 { 0x83, 0x0b },
1854 { 0x84, 0x00 },
1855 { 0x85, 0x62 }, /* was 0x61, new from windrv 090403 */
1856 { 0x86, 0xc9 },
1857 { 0x87, 0x00 },
1858 { 0x88, 0x00 },
1859 { 0x89, 0x01 },
1860 { 0x12, 0x20 },
1861 { 0x12, 0x25 }, /* was 0x24, new from windrv 090403 */
1862};
1863
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001864static unsigned char ov7670_abs_to_sm(unsigned char v)
1865{
1866 if (v > 127)
1867 return v & 0x7f;
1868 return (128 - v) | 0x80;
1869}
1870
1871/* Write a OV519 register */
Jean-François Moinef8f20182010-11-12 07:54:02 -03001872static void reg_w(struct sd *sd, u16 index, u16 value)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001873{
Hans de Goedea511ba92009-10-16 07:13:07 -03001874 int ret, req = 0;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001875
Jean-François Moinef8f20182010-11-12 07:54:02 -03001876 if (sd->gspca_dev.usb_err < 0)
1877 return;
1878
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001879 switch (sd->bridge) {
1880 case BRIDGE_OV511:
1881 case BRIDGE_OV511PLUS:
1882 req = 2;
1883 break;
1884 case BRIDGE_OVFX2:
Hans de Goedea511ba92009-10-16 07:13:07 -03001885 req = 0x0a;
1886 /* fall through */
1887 case BRIDGE_W9968CF:
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001888 ret = usb_control_msg(sd->gspca_dev.dev,
1889 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
Hans de Goedea511ba92009-10-16 07:13:07 -03001890 req,
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001891 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Hans de Goedea511ba92009-10-16 07:13:07 -03001892 value, index, NULL, 0, 500);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001893 goto leave;
1894 default:
1895 req = 1;
1896 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001897
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001898 sd->gspca_dev.usb_buf[0] = value;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001899 ret = usb_control_msg(sd->gspca_dev.dev,
1900 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
Hans de Goede49809d62009-06-07 12:10:39 -03001901 req,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001902 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1903 0, index,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001904 sd->gspca_dev.usb_buf, 1, 500);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001905leave:
Hans de Goedea511ba92009-10-16 07:13:07 -03001906 if (ret < 0) {
Jean-François Moine0b656322010-09-13 05:19:58 -03001907 err("Write reg 0x%04x -> [0x%02x] failed",
Hans de Goedea511ba92009-10-16 07:13:07 -03001908 value, index);
Jean-François Moinef8f20182010-11-12 07:54:02 -03001909 sd->gspca_dev.usb_err = ret;
1910 return;
Hans de Goedea511ba92009-10-16 07:13:07 -03001911 }
1912
1913 PDEBUG(D_USBO, "Write reg 0x%04x -> [0x%02x]", value, index);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001914}
1915
Hans de Goedea511ba92009-10-16 07:13:07 -03001916/* Read from a OV519 register, note not valid for the w9968cf!! */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001917/* returns: negative is error, pos or zero is data */
Jean-François Moine9d1593a2010-11-11 08:04:06 -03001918static int reg_r(struct sd *sd, u16 index)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001919{
1920 int ret;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001921 int req;
1922
Jean-François Moinef8f20182010-11-12 07:54:02 -03001923 if (sd->gspca_dev.usb_err < 0)
1924 return -1;
1925
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001926 switch (sd->bridge) {
1927 case BRIDGE_OV511:
1928 case BRIDGE_OV511PLUS:
1929 req = 3;
1930 break;
1931 case BRIDGE_OVFX2:
1932 req = 0x0b;
1933 break;
1934 default:
1935 req = 1;
1936 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001937
1938 ret = usb_control_msg(sd->gspca_dev.dev,
1939 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
Hans de Goede49809d62009-06-07 12:10:39 -03001940 req,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001941 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001942 0, index, sd->gspca_dev.usb_buf, 1, 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001943
Hans de Goedea511ba92009-10-16 07:13:07 -03001944 if (ret >= 0) {
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001945 ret = sd->gspca_dev.usb_buf[0];
Hans de Goedea511ba92009-10-16 07:13:07 -03001946 PDEBUG(D_USBI, "Read reg [0x%02X] -> 0x%04X", index, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03001947 } else {
Jean-François Moine0b656322010-09-13 05:19:58 -03001948 err("Read reg [0x%02x] failed", index);
Jean-François Moinef8f20182010-11-12 07:54:02 -03001949 sd->gspca_dev.usb_err = ret;
1950 }
Hans de Goedea511ba92009-10-16 07:13:07 -03001951
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001952 return ret;
1953}
1954
1955/* Read 8 values from a OV519 register */
1956static int reg_r8(struct sd *sd,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03001957 u16 index)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001958{
1959 int ret;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001960
Jean-François Moinef8f20182010-11-12 07:54:02 -03001961 if (sd->gspca_dev.usb_err < 0)
1962 return -1;
1963
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001964 ret = usb_control_msg(sd->gspca_dev.dev,
1965 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
1966 1, /* REQ_IO */
1967 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001968 0, index, sd->gspca_dev.usb_buf, 8, 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001969
Jean-François Moinef8f20182010-11-12 07:54:02 -03001970 if (ret >= 0) {
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001971 ret = sd->gspca_dev.usb_buf[0];
Jean-François Moinef8f20182010-11-12 07:54:02 -03001972 } else {
Jean-François Moine0b656322010-09-13 05:19:58 -03001973 err("Read reg 8 [0x%02x] failed", index);
Jean-François Moinef8f20182010-11-12 07:54:02 -03001974 sd->gspca_dev.usb_err = ret;
1975 }
Hans de Goedea511ba92009-10-16 07:13:07 -03001976
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001977 return ret;
1978}
1979
1980/*
1981 * Writes bits at positions specified by mask to an OV51x reg. Bits that are in
1982 * the same position as 1's in "mask" are cleared and set to "value". Bits
1983 * that are in the same position as 0's in "mask" are preserved, regardless
1984 * of their respective state in "value".
1985 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03001986static void reg_w_mask(struct sd *sd,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03001987 u16 index,
1988 u8 value,
1989 u8 mask)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001990{
1991 int ret;
Jean-François Moine9d1593a2010-11-11 08:04:06 -03001992 u8 oldval;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001993
1994 if (mask != 0xff) {
1995 value &= mask; /* Enforce mask on value */
1996 ret = reg_r(sd, index);
1997 if (ret < 0)
Jean-François Moinef8f20182010-11-12 07:54:02 -03001998 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001999
2000 oldval = ret & ~mask; /* Clear the masked bits */
2001 value |= oldval; /* Set the desired bits */
2002 }
Jean-François Moinef8f20182010-11-12 07:54:02 -03002003 reg_w(sd, index, value);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002004}
2005
2006/*
Hans de Goede49809d62009-06-07 12:10:39 -03002007 * Writes multiple (n) byte value to a single register. Only valid with certain
2008 * registers (0x30 and 0xc4 - 0xce).
2009 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002010static void ov518_reg_w32(struct sd *sd, u16 index, u32 value, int n)
Hans de Goede49809d62009-06-07 12:10:39 -03002011{
2012 int ret;
2013
Jean-François Moinef8f20182010-11-12 07:54:02 -03002014 if (sd->gspca_dev.usb_err < 0)
2015 return;
2016
Jean-Francois Moine83955552009-12-12 06:58:01 -03002017 *((__le32 *) sd->gspca_dev.usb_buf) = __cpu_to_le32(value);
Hans de Goede49809d62009-06-07 12:10:39 -03002018
2019 ret = usb_control_msg(sd->gspca_dev.dev,
2020 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
2021 1 /* REG_IO */,
2022 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2023 0, index,
2024 sd->gspca_dev.usb_buf, n, 500);
Hans de Goedea511ba92009-10-16 07:13:07 -03002025 if (ret < 0) {
Jean-François Moine0b656322010-09-13 05:19:58 -03002026 err("Write reg32 [%02x] %08x failed", index, value);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002027 sd->gspca_dev.usb_err = ret;
Hans de Goedea511ba92009-10-16 07:13:07 -03002028 }
Hans de Goede49809d62009-06-07 12:10:39 -03002029}
2030
Jean-François Moinef8f20182010-11-12 07:54:02 -03002031static void ov511_i2c_w(struct sd *sd, u8 reg, u8 value)
Hans de Goede1876bb92009-06-14 06:45:50 -03002032{
2033 int rc, retries;
2034
2035 PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
2036
2037 /* Three byte write cycle */
2038 for (retries = 6; ; ) {
2039 /* Select camera register */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002040 reg_w(sd, R51x_I2C_SADDR_3, reg);
Hans de Goede1876bb92009-06-14 06:45:50 -03002041
2042 /* Write "value" to I2C data port of OV511 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002043 reg_w(sd, R51x_I2C_DATA, value);
Hans de Goede1876bb92009-06-14 06:45:50 -03002044
2045 /* Initiate 3-byte write cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002046 reg_w(sd, R511_I2C_CTL, 0x01);
Hans de Goede1876bb92009-06-14 06:45:50 -03002047
Jean-Francois Moine83955552009-12-12 06:58:01 -03002048 do {
Hans de Goede1876bb92009-06-14 06:45:50 -03002049 rc = reg_r(sd, R511_I2C_CTL);
Jean-Francois Moine83955552009-12-12 06:58:01 -03002050 } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
Hans de Goede1876bb92009-06-14 06:45:50 -03002051
2052 if (rc < 0)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002053 return;
Hans de Goede1876bb92009-06-14 06:45:50 -03002054
2055 if ((rc & 2) == 0) /* Ack? */
2056 break;
2057 if (--retries < 0) {
2058 PDEBUG(D_USBO, "i2c write retries exhausted");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002059 return;
Hans de Goede1876bb92009-06-14 06:45:50 -03002060 }
2061 }
Hans de Goede1876bb92009-06-14 06:45:50 -03002062}
2063
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002064static int ov511_i2c_r(struct sd *sd, u8 reg)
Hans de Goede1876bb92009-06-14 06:45:50 -03002065{
2066 int rc, value, retries;
2067
2068 /* Two byte write cycle */
2069 for (retries = 6; ; ) {
2070 /* Select camera register */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002071 reg_w(sd, R51x_I2C_SADDR_2, reg);
Hans de Goede1876bb92009-06-14 06:45:50 -03002072
2073 /* Initiate 2-byte write cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002074 reg_w(sd, R511_I2C_CTL, 0x03);
Hans de Goede1876bb92009-06-14 06:45:50 -03002075
Jean-Francois Moine83955552009-12-12 06:58:01 -03002076 do {
Hans de Goede1876bb92009-06-14 06:45:50 -03002077 rc = reg_r(sd, R511_I2C_CTL);
Jean-Francois Moine83955552009-12-12 06:58:01 -03002078 } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
Hans de Goede1876bb92009-06-14 06:45:50 -03002079
2080 if (rc < 0)
2081 return rc;
2082
2083 if ((rc & 2) == 0) /* Ack? */
2084 break;
2085
2086 /* I2C abort */
2087 reg_w(sd, R511_I2C_CTL, 0x10);
2088
2089 if (--retries < 0) {
2090 PDEBUG(D_USBI, "i2c write retries exhausted");
2091 return -1;
2092 }
2093 }
2094
2095 /* Two byte read cycle */
2096 for (retries = 6; ; ) {
2097 /* Initiate 2-byte read cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002098 reg_w(sd, R511_I2C_CTL, 0x05);
Hans de Goede1876bb92009-06-14 06:45:50 -03002099
Jean-Francois Moine83955552009-12-12 06:58:01 -03002100 do {
Hans de Goede1876bb92009-06-14 06:45:50 -03002101 rc = reg_r(sd, R511_I2C_CTL);
Jean-Francois Moine83955552009-12-12 06:58:01 -03002102 } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
Hans de Goede1876bb92009-06-14 06:45:50 -03002103
2104 if (rc < 0)
2105 return rc;
2106
2107 if ((rc & 2) == 0) /* Ack? */
2108 break;
2109
2110 /* I2C abort */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002111 reg_w(sd, R511_I2C_CTL, 0x10);
Hans de Goede1876bb92009-06-14 06:45:50 -03002112
2113 if (--retries < 0) {
2114 PDEBUG(D_USBI, "i2c read retries exhausted");
2115 return -1;
2116 }
2117 }
2118
2119 value = reg_r(sd, R51x_I2C_DATA);
2120
2121 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value);
2122
2123 /* This is needed to make i2c_w() work */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002124 reg_w(sd, R511_I2C_CTL, 0x05);
Hans de Goede1876bb92009-06-14 06:45:50 -03002125
2126 return value;
2127}
Hans de Goede49809d62009-06-07 12:10:39 -03002128
2129/*
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002130 * The OV518 I2C I/O procedure is different, hence, this function.
2131 * This is normally only called from i2c_w(). Note that this function
2132 * always succeeds regardless of whether the sensor is present and working.
2133 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002134static void ov518_i2c_w(struct sd *sd,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002135 u8 reg,
2136 u8 value)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002137{
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002138 PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
2139
2140 /* Select camera register */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002141 reg_w(sd, R51x_I2C_SADDR_3, reg);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002142
2143 /* Write "value" to I2C data port of OV511 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002144 reg_w(sd, R51x_I2C_DATA, value);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002145
2146 /* Initiate 3-byte write cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002147 reg_w(sd, R518_I2C_CTL, 0x01);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002148
2149 /* wait for write complete */
2150 msleep(4);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002151 reg_r8(sd, R518_I2C_CTL);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002152}
2153
2154/*
2155 * returns: negative is error, pos or zero is data
2156 *
2157 * The OV518 I2C I/O procedure is different, hence, this function.
2158 * This is normally only called from i2c_r(). Note that this function
2159 * always succeeds regardless of whether the sensor is present and working.
2160 */
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002161static int ov518_i2c_r(struct sd *sd, u8 reg)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002162{
Jean-François Moinef8f20182010-11-12 07:54:02 -03002163 int value;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002164
2165 /* Select camera register */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002166 reg_w(sd, R51x_I2C_SADDR_2, reg);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002167
2168 /* Initiate 2-byte write cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002169 reg_w(sd, R518_I2C_CTL, 0x03);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002170
2171 /* Initiate 2-byte read cycle */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002172 reg_w(sd, R518_I2C_CTL, 0x05);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002173 value = reg_r(sd, R51x_I2C_DATA);
2174 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value);
2175 return value;
2176}
2177
Jean-François Moinef8f20182010-11-12 07:54:02 -03002178static void ovfx2_i2c_w(struct sd *sd, u8 reg, u8 value)
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002179{
2180 int ret;
2181
Jean-François Moinef8f20182010-11-12 07:54:02 -03002182 if (sd->gspca_dev.usb_err < 0)
2183 return;
2184
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002185 ret = usb_control_msg(sd->gspca_dev.dev,
2186 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
2187 0x02,
2188 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002189 (u16) value, (u16) reg, NULL, 0, 500);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002190
Hans de Goedea511ba92009-10-16 07:13:07 -03002191 if (ret < 0) {
Jean-François Moine0b656322010-09-13 05:19:58 -03002192 err("i2c 0x%02x -> [0x%02x] failed", value, reg);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002193 sd->gspca_dev.usb_err = ret;
Hans de Goedea511ba92009-10-16 07:13:07 -03002194 }
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002195
Hans de Goedea511ba92009-10-16 07:13:07 -03002196 PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002197}
2198
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002199static int ovfx2_i2c_r(struct sd *sd, u8 reg)
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002200{
2201 int ret;
2202
Jean-François Moinef8f20182010-11-12 07:54:02 -03002203 if (sd->gspca_dev.usb_err < 0)
2204 return -1;
2205
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002206 ret = usb_control_msg(sd->gspca_dev.dev,
2207 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
2208 0x03,
2209 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002210 0, (u16) reg, sd->gspca_dev.usb_buf, 1, 500);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002211
2212 if (ret >= 0) {
2213 ret = sd->gspca_dev.usb_buf[0];
2214 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, ret);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002215 } else {
Jean-François Moine0b656322010-09-13 05:19:58 -03002216 err("i2c read [0x%02x] failed", reg);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002217 sd->gspca_dev.usb_err = ret;
2218 }
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002219
2220 return ret;
2221}
2222
Jean-François Moinef8f20182010-11-12 07:54:02 -03002223static void i2c_w(struct sd *sd, u8 reg, u8 value)
Hans de Goede1876bb92009-06-14 06:45:50 -03002224{
Hans de Goedefb1f9022009-10-16 07:42:53 -03002225 if (sd->sensor_reg_cache[reg] == value)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002226 return;
Hans de Goedefb1f9022009-10-16 07:42:53 -03002227
Hans de Goede1876bb92009-06-14 06:45:50 -03002228 switch (sd->bridge) {
2229 case BRIDGE_OV511:
2230 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002231 ov511_i2c_w(sd, reg, value);
Hans de Goedefb1f9022009-10-16 07:42:53 -03002232 break;
Hans de Goede1876bb92009-06-14 06:45:50 -03002233 case BRIDGE_OV518:
2234 case BRIDGE_OV518PLUS:
2235 case BRIDGE_OV519:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002236 ov518_i2c_w(sd, reg, value);
Hans de Goedefb1f9022009-10-16 07:42:53 -03002237 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002238 case BRIDGE_OVFX2:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002239 ovfx2_i2c_w(sd, reg, value);
Hans de Goedefb1f9022009-10-16 07:42:53 -03002240 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03002241 case BRIDGE_W9968CF:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002242 w9968cf_i2c_w(sd, reg, value);
Hans de Goedefb1f9022009-10-16 07:42:53 -03002243 break;
Hans de Goede1876bb92009-06-14 06:45:50 -03002244 }
Hans de Goedefb1f9022009-10-16 07:42:53 -03002245
Jean-François Moinef8f20182010-11-12 07:54:02 -03002246 if (sd->gspca_dev.usb_err >= 0) {
Hans de Goedefb1f9022009-10-16 07:42:53 -03002247 /* Up on sensor reset empty the register cache */
2248 if (reg == 0x12 && (value & 0x80))
2249 memset(sd->sensor_reg_cache, -1,
Jean-François Moine87bae742010-11-12 05:31:34 -03002250 sizeof(sd->sensor_reg_cache));
Hans de Goedefb1f9022009-10-16 07:42:53 -03002251 else
2252 sd->sensor_reg_cache[reg] = value;
2253 }
Hans de Goede1876bb92009-06-14 06:45:50 -03002254}
2255
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002256static int i2c_r(struct sd *sd, u8 reg)
Hans de Goede1876bb92009-06-14 06:45:50 -03002257{
Hans de Goede8394bcf2009-10-16 11:26:22 -03002258 int ret = -1;
Hans de Goedefb1f9022009-10-16 07:42:53 -03002259
2260 if (sd->sensor_reg_cache[reg] != -1)
2261 return sd->sensor_reg_cache[reg];
2262
Hans de Goede1876bb92009-06-14 06:45:50 -03002263 switch (sd->bridge) {
2264 case BRIDGE_OV511:
2265 case BRIDGE_OV511PLUS:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002266 ret = ov511_i2c_r(sd, reg);
2267 break;
Hans de Goede1876bb92009-06-14 06:45:50 -03002268 case BRIDGE_OV518:
2269 case BRIDGE_OV518PLUS:
2270 case BRIDGE_OV519:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002271 ret = ov518_i2c_r(sd, reg);
2272 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002273 case BRIDGE_OVFX2:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002274 ret = ovfx2_i2c_r(sd, reg);
2275 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03002276 case BRIDGE_W9968CF:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002277 ret = w9968cf_i2c_r(sd, reg);
2278 break;
Hans de Goede1876bb92009-06-14 06:45:50 -03002279 }
Hans de Goedefb1f9022009-10-16 07:42:53 -03002280
2281 if (ret >= 0)
2282 sd->sensor_reg_cache[reg] = ret;
2283
2284 return ret;
Hans de Goede1876bb92009-06-14 06:45:50 -03002285}
2286
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002287/* Writes bits at positions specified by mask to an I2C reg. Bits that are in
2288 * the same position as 1's in "mask" are cleared and set to "value". Bits
2289 * that are in the same position as 0's in "mask" are preserved, regardless
2290 * of their respective state in "value".
2291 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002292static void i2c_w_mask(struct sd *sd,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002293 u8 reg,
2294 u8 value,
2295 u8 mask)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002296{
2297 int rc;
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002298 u8 oldval;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002299
2300 value &= mask; /* Enforce mask on value */
2301 rc = i2c_r(sd, reg);
2302 if (rc < 0)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002303 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002304 oldval = rc & ~mask; /* Clear the masked bits */
2305 value |= oldval; /* Set the desired bits */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002306 i2c_w(sd, reg, value);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002307}
2308
2309/* Temporarily stops OV511 from functioning. Must do this before changing
2310 * registers while the camera is streaming */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002311static inline void ov51x_stop(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002312{
2313 PDEBUG(D_STREAM, "stopping");
2314 sd->stopped = 1;
Hans de Goede49809d62009-06-07 12:10:39 -03002315 switch (sd->bridge) {
2316 case BRIDGE_OV511:
2317 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002318 reg_w(sd, R51x_SYS_RESET, 0x3d);
2319 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002320 case BRIDGE_OV518:
2321 case BRIDGE_OV518PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002322 reg_w_mask(sd, R51x_SYS_RESET, 0x3a, 0x3a);
2323 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002324 case BRIDGE_OV519:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002325 reg_w(sd, OV519_R51_RESET1, 0x0f);
2326 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002327 case BRIDGE_OVFX2:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002328 reg_w_mask(sd, 0x0f, 0x00, 0x02);
2329 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03002330 case BRIDGE_W9968CF:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002331 reg_w(sd, 0x3c, 0x0a05); /* stop USB transfer */
2332 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002333 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002334}
2335
2336/* Restarts OV511 after ov511_stop() is called. Has no effect if it is not
2337 * actually stopped (for performance). */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002338static inline void ov51x_restart(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002339{
2340 PDEBUG(D_STREAM, "restarting");
2341 if (!sd->stopped)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002342 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002343 sd->stopped = 0;
2344
2345 /* Reinitialize the stream */
Hans de Goede49809d62009-06-07 12:10:39 -03002346 switch (sd->bridge) {
2347 case BRIDGE_OV511:
2348 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002349 reg_w(sd, R51x_SYS_RESET, 0x00);
2350 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002351 case BRIDGE_OV518:
2352 case BRIDGE_OV518PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002353 reg_w(sd, 0x2f, 0x80);
2354 reg_w(sd, R51x_SYS_RESET, 0x00);
2355 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002356 case BRIDGE_OV519:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002357 reg_w(sd, OV519_R51_RESET1, 0x00);
2358 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002359 case BRIDGE_OVFX2:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002360 reg_w_mask(sd, 0x0f, 0x02, 0x02);
2361 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03002362 case BRIDGE_W9968CF:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002363 reg_w(sd, 0x3c, 0x8a05); /* USB FIFO enable */
2364 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002365 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002366}
2367
Jean-François Moinef8f20182010-11-12 07:54:02 -03002368static void ov51x_set_slave_ids(struct sd *sd, u8 slave);
Hans de Goede229bb7d2009-10-11 07:41:46 -03002369
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002370/* This does an initial reset of an OmniVision sensor and ensures that I2C
2371 * is synchronized. Returns <0 on failure.
2372 */
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002373static int init_ov_sensor(struct sd *sd, u8 slave)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002374{
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002375 int i;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002376
Jean-François Moinef8f20182010-11-12 07:54:02 -03002377 ov51x_set_slave_ids(sd, slave);
Hans de Goede229bb7d2009-10-11 07:41:46 -03002378
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002379 /* Reset the sensor */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002380 i2c_w(sd, 0x12, 0x80);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002381
2382 /* Wait for it to initialize */
2383 msleep(150);
2384
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002385 for (i = 0; i < i2c_detect_tries; i++) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002386 if (i2c_r(sd, OV7610_REG_ID_HIGH) == 0x7f &&
2387 i2c_r(sd, OV7610_REG_ID_LOW) == 0xa2) {
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002388 PDEBUG(D_PROBE, "I2C synced in %d attempt(s)", i);
2389 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002390 }
2391
2392 /* Reset the sensor */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002393 i2c_w(sd, 0x12, 0x80);
2394
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002395 /* Wait for it to initialize */
2396 msleep(150);
Jean-François Moine87bae742010-11-12 05:31:34 -03002397
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002398 /* Dummy read to sync I2C */
2399 if (i2c_r(sd, 0x00) < 0)
Jean-François Moinef8f20182010-11-12 07:54:02 -03002400 return -1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002401 }
Jean-François Moinef8f20182010-11-12 07:54:02 -03002402 return -1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002403}
2404
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002405/* Set the read and write slave IDs. The "slave" argument is the write slave,
2406 * and the read slave will be set to (slave + 1).
2407 * This should not be called from outside the i2c I/O functions.
2408 * Sets I2C read and write slave IDs. Returns <0 for error
2409 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002410static void ov51x_set_slave_ids(struct sd *sd,
Jean-François Moine9d1593a2010-11-11 08:04:06 -03002411 u8 slave)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002412{
Hans de Goedea511ba92009-10-16 07:13:07 -03002413 switch (sd->bridge) {
2414 case BRIDGE_OVFX2:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002415 reg_w(sd, OVFX2_I2C_ADDR, slave);
2416 return;
Hans de Goedea511ba92009-10-16 07:13:07 -03002417 case BRIDGE_W9968CF:
2418 sd->sensor_addr = slave;
Jean-François Moinef8f20182010-11-12 07:54:02 -03002419 return;
Hans de Goedea511ba92009-10-16 07:13:07 -03002420 }
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002421
Jean-François Moinef8f20182010-11-12 07:54:02 -03002422 reg_w(sd, R51x_I2C_W_SID, slave);
2423 reg_w(sd, R51x_I2C_R_SID, slave + 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002424}
2425
Jean-François Moinef8f20182010-11-12 07:54:02 -03002426static void write_regvals(struct sd *sd,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002427 const struct ov_regvals *regvals,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002428 int n)
2429{
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002430 while (--n >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03002431 reg_w(sd, regvals->reg, regvals->val);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002432 regvals++;
2433 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002434}
2435
Jean-François Moinef8f20182010-11-12 07:54:02 -03002436static void write_i2c_regvals(struct sd *sd,
2437 const struct ov_i2c_regvals *regvals,
2438 int n)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002439{
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002440 while (--n >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03002441 i2c_w(sd, regvals->reg, regvals->val);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002442 regvals++;
2443 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002444}
2445
2446/****************************************************************************
2447 *
2448 * OV511 and sensor configuration
2449 *
2450 ***************************************************************************/
2451
Hans de Goede635118d2009-10-11 09:49:03 -03002452/* This initializes the OV2x10 / OV3610 / OV3620 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002453static void ov_hires_configure(struct sd *sd)
Hans de Goede635118d2009-10-11 09:49:03 -03002454{
2455 int high, low;
2456
2457 if (sd->bridge != BRIDGE_OVFX2) {
Jean-François Moine0b656322010-09-13 05:19:58 -03002458 err("error hires sensors only supported with ovfx2");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002459 return;
Hans de Goede635118d2009-10-11 09:49:03 -03002460 }
2461
2462 PDEBUG(D_PROBE, "starting ov hires configuration");
2463
2464 /* Detect sensor (sub)type */
2465 high = i2c_r(sd, 0x0a);
2466 low = i2c_r(sd, 0x0b);
2467 /* info("%x, %x", high, low); */
2468 if (high == 0x96 && low == 0x40) {
2469 PDEBUG(D_PROBE, "Sensor is an OV2610");
2470 sd->sensor = SEN_OV2610;
2471 } else if (high == 0x36 && (low & 0x0f) == 0x00) {
2472 PDEBUG(D_PROBE, "Sensor is an OV3610");
2473 sd->sensor = SEN_OV3610;
2474 } else {
Jean-François Moine0b656322010-09-13 05:19:58 -03002475 err("Error unknown sensor type: 0x%02x%02x",
Jean-François Moine87bae742010-11-12 05:31:34 -03002476 high, low);
Hans de Goede635118d2009-10-11 09:49:03 -03002477 }
Hans de Goede635118d2009-10-11 09:49:03 -03002478}
2479
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002480/* This initializes the OV8110, OV8610 sensor. The OV8110 uses
2481 * the same register settings as the OV8610, since they are very similar.
2482 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002483static void ov8xx0_configure(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002484{
2485 int rc;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002486
2487 PDEBUG(D_PROBE, "starting ov8xx0 configuration");
2488
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002489 /* Detect sensor (sub)type */
2490 rc = i2c_r(sd, OV7610_REG_COM_I);
2491 if (rc < 0) {
2492 PDEBUG(D_ERR, "Error detecting sensor type");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002493 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002494 }
Jean-François Moinef8f20182010-11-12 07:54:02 -03002495 if ((rc & 3) == 1)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002496 sd->sensor = SEN_OV8610;
Jean-François Moinef8f20182010-11-12 07:54:02 -03002497 else
Jean-François Moine0b656322010-09-13 05:19:58 -03002498 err("Unknown image sensor version: %d", rc & 3);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002499}
2500
2501/* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
2502 * the same register settings as the OV7610, since they are very similar.
2503 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002504static void ov7xx0_configure(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002505{
2506 int rc, high, low;
2507
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002508 PDEBUG(D_PROBE, "starting OV7xx0 configuration");
2509
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002510 /* Detect sensor (sub)type */
2511 rc = i2c_r(sd, OV7610_REG_COM_I);
2512
2513 /* add OV7670 here
2514 * it appears to be wrongly detected as a 7610 by default */
2515 if (rc < 0) {
2516 PDEBUG(D_ERR, "Error detecting sensor type");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002517 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002518 }
2519 if ((rc & 3) == 3) {
2520 /* quick hack to make OV7670s work */
2521 high = i2c_r(sd, 0x0a);
2522 low = i2c_r(sd, 0x0b);
2523 /* info("%x, %x", high, low); */
2524 if (high == 0x76 && low == 0x73) {
2525 PDEBUG(D_PROBE, "Sensor is an OV7670");
2526 sd->sensor = SEN_OV7670;
2527 } else {
2528 PDEBUG(D_PROBE, "Sensor is an OV7610");
2529 sd->sensor = SEN_OV7610;
2530 }
2531 } else if ((rc & 3) == 1) {
2532 /* I don't know what's different about the 76BE yet. */
Hans de Goedeb282d872009-06-14 19:10:40 -03002533 if (i2c_r(sd, 0x15) & 1) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002534 PDEBUG(D_PROBE, "Sensor is an OV7620AE");
Hans de Goede859cc472010-01-07 15:42:35 -03002535 sd->sensor = SEN_OV7620AE;
Hans de Goedeb282d872009-06-14 19:10:40 -03002536 } else {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002537 PDEBUG(D_PROBE, "Sensor is an OV76BE");
Hans de Goedeb282d872009-06-14 19:10:40 -03002538 sd->sensor = SEN_OV76BE;
2539 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002540 } else if ((rc & 3) == 0) {
2541 /* try to read product id registers */
2542 high = i2c_r(sd, 0x0a);
2543 if (high < 0) {
2544 PDEBUG(D_ERR, "Error detecting camera chip PID");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002545 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002546 }
2547 low = i2c_r(sd, 0x0b);
2548 if (low < 0) {
2549 PDEBUG(D_ERR, "Error detecting camera chip VER");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002550 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002551 }
2552 if (high == 0x76) {
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002553 switch (low) {
2554 case 0x30:
Jean-François Moine0b656322010-09-13 05:19:58 -03002555 err("Sensor is an OV7630/OV7635");
2556 err("7630 is not supported by this driver");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002557 return;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002558 case 0x40:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002559 PDEBUG(D_PROBE, "Sensor is an OV7645");
2560 sd->sensor = SEN_OV7640; /* FIXME */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002561 break;
2562 case 0x45:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002563 PDEBUG(D_PROBE, "Sensor is an OV7645B");
2564 sd->sensor = SEN_OV7640; /* FIXME */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002565 break;
2566 case 0x48:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002567 PDEBUG(D_PROBE, "Sensor is an OV7648");
Hans de Goede035d3a32010-01-09 08:14:43 -03002568 sd->sensor = SEN_OV7648;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002569 break;
2570 default:
2571 PDEBUG(D_PROBE, "Unknown sensor: 0x76%x", low);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002572 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002573 }
2574 } else {
2575 PDEBUG(D_PROBE, "Sensor is an OV7620");
2576 sd->sensor = SEN_OV7620;
2577 }
2578 } else {
Jean-François Moine0b656322010-09-13 05:19:58 -03002579 err("Unknown image sensor version: %d", rc & 3);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002580 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002581}
2582
2583/* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002584static void ov6xx0_configure(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002585{
2586 int rc;
Jean-Francois Moine4202f712008-09-03 17:12:15 -03002587 PDEBUG(D_PROBE, "starting OV6xx0 configuration");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002588
2589 /* Detect sensor (sub)type */
2590 rc = i2c_r(sd, OV7610_REG_COM_I);
2591 if (rc < 0) {
2592 PDEBUG(D_ERR, "Error detecting sensor type");
Jean-François Moinef8f20182010-11-12 07:54:02 -03002593 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002594 }
2595
2596 /* Ugh. The first two bits are the version bits, but
2597 * the entire register value must be used. I guess OVT
2598 * underestimated how many variants they would make. */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002599 switch (rc) {
2600 case 0x00:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002601 sd->sensor = SEN_OV6630;
Jean-François Moine0b656322010-09-13 05:19:58 -03002602 warn("WARNING: Sensor is an OV66308. Your camera may have");
2603 warn("been misdetected in previous driver versions.");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002604 break;
2605 case 0x01:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002606 sd->sensor = SEN_OV6620;
Hans de Goede7d971372009-06-14 05:28:17 -03002607 PDEBUG(D_PROBE, "Sensor is an OV6620");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002608 break;
2609 case 0x02:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002610 sd->sensor = SEN_OV6630;
2611 PDEBUG(D_PROBE, "Sensor is an OV66308AE");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002612 break;
2613 case 0x03:
Hans de Goede7d971372009-06-14 05:28:17 -03002614 sd->sensor = SEN_OV66308AF;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002615 PDEBUG(D_PROBE, "Sensor is an OV66308AF");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002616 break;
2617 case 0x90:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002618 sd->sensor = SEN_OV6630;
Jean-François Moine0b656322010-09-13 05:19:58 -03002619 warn("WARNING: Sensor is an OV66307. Your camera may have");
2620 warn("been misdetected in previous driver versions.");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002621 break;
2622 default:
Jean-François Moine0b656322010-09-13 05:19:58 -03002623 err("FATAL: Unknown sensor version: 0x%02x", rc);
Jean-François Moinef8f20182010-11-12 07:54:02 -03002624 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002625 }
2626
2627 /* Set sensor-specific vars */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002628 sd->sif = 1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002629}
2630
2631/* Turns on or off the LED. Only has an effect with OV511+/OV518(+)/OV519 */
2632static void ov51x_led_control(struct sd *sd, int on)
2633{
Hans de Goede9e4d8252009-06-14 06:25:06 -03002634 if (sd->invert_led)
2635 on = !on;
2636
Hans de Goede49809d62009-06-07 12:10:39 -03002637 switch (sd->bridge) {
2638 /* OV511 has no LED control */
2639 case BRIDGE_OV511PLUS:
2640 reg_w(sd, R511_SYS_LED_CTL, on ? 1 : 0);
2641 break;
2642 case BRIDGE_OV518:
2643 case BRIDGE_OV518PLUS:
2644 reg_w_mask(sd, R518_GPIO_OUT, on ? 0x02 : 0x00, 0x02);
2645 break;
2646 case BRIDGE_OV519:
2647 reg_w_mask(sd, OV519_GPIO_DATA_OUT0, !on, 1); /* 0 / 1 */
2648 break;
2649 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002650}
2651
Hans de Goede417a4d22010-02-19 07:37:08 -03002652static void sd_reset_snapshot(struct gspca_dev *gspca_dev)
2653{
2654 struct sd *sd = (struct sd *) gspca_dev;
2655
2656 if (!sd->snapshot_needs_reset)
2657 return;
2658
2659 /* Note it is important that we clear sd->snapshot_needs_reset,
2660 before actually clearing the snapshot state in the bridge
2661 otherwise we might race with the pkt_scan interrupt handler */
2662 sd->snapshot_needs_reset = 0;
2663
2664 switch (sd->bridge) {
Hans de Goede88e8d202010-02-20 04:45:49 -03002665 case BRIDGE_OV511:
2666 case BRIDGE_OV511PLUS:
2667 reg_w(sd, R51x_SYS_SNAP, 0x02);
2668 reg_w(sd, R51x_SYS_SNAP, 0x00);
2669 break;
Hans de Goede92e232a2010-02-20 04:30:45 -03002670 case BRIDGE_OV518:
2671 case BRIDGE_OV518PLUS:
2672 reg_w(sd, R51x_SYS_SNAP, 0x02); /* Reset */
2673 reg_w(sd, R51x_SYS_SNAP, 0x01); /* Enable */
2674 break;
Hans de Goede417a4d22010-02-19 07:37:08 -03002675 case BRIDGE_OV519:
2676 reg_w(sd, R51x_SYS_RESET, 0x40);
2677 reg_w(sd, R51x_SYS_RESET, 0x00);
2678 break;
2679 }
2680}
2681
Jean-François Moinef8f20182010-11-12 07:54:02 -03002682static void ov51x_upload_quan_tables(struct sd *sd)
Hans de Goede49809d62009-06-07 12:10:39 -03002683{
Hans de Goede1876bb92009-06-14 06:45:50 -03002684 const unsigned char yQuanTable511[] = {
2685 0, 1, 1, 2, 2, 3, 3, 4,
2686 1, 1, 1, 2, 2, 3, 4, 4,
2687 1, 1, 2, 2, 3, 4, 4, 4,
2688 2, 2, 2, 3, 4, 4, 4, 4,
2689 2, 2, 3, 4, 4, 5, 5, 5,
2690 3, 3, 4, 4, 5, 5, 5, 5,
2691 3, 4, 4, 4, 5, 5, 5, 5,
2692 4, 4, 4, 4, 5, 5, 5, 5
2693 };
2694
2695 const unsigned char uvQuanTable511[] = {
2696 0, 2, 2, 3, 4, 4, 4, 4,
2697 2, 2, 2, 4, 4, 4, 4, 4,
2698 2, 2, 3, 4, 4, 4, 4, 4,
2699 3, 4, 4, 4, 4, 4, 4, 4,
2700 4, 4, 4, 4, 4, 4, 4, 4,
2701 4, 4, 4, 4, 4, 4, 4, 4,
2702 4, 4, 4, 4, 4, 4, 4, 4,
2703 4, 4, 4, 4, 4, 4, 4, 4
2704 };
2705
2706 /* OV518 quantization tables are 8x4 (instead of 8x8) */
Hans de Goede49809d62009-06-07 12:10:39 -03002707 const unsigned char yQuanTable518[] = {
2708 5, 4, 5, 6, 6, 7, 7, 7,
2709 5, 5, 5, 5, 6, 7, 7, 7,
2710 6, 6, 6, 6, 7, 7, 7, 8,
2711 7, 7, 6, 7, 7, 7, 8, 8
2712 };
Hans de Goede49809d62009-06-07 12:10:39 -03002713 const unsigned char uvQuanTable518[] = {
2714 6, 6, 6, 7, 7, 7, 7, 7,
2715 6, 6, 6, 7, 7, 7, 7, 7,
2716 6, 6, 6, 7, 7, 7, 7, 8,
2717 7, 7, 7, 7, 7, 7, 8, 8
2718 };
2719
Hans de Goede1876bb92009-06-14 06:45:50 -03002720 const unsigned char *pYTable, *pUVTable;
Hans de Goede49809d62009-06-07 12:10:39 -03002721 unsigned char val0, val1;
Jean-François Moinef8f20182010-11-12 07:54:02 -03002722 int i, size, reg = R51x_COMP_LUT_BEGIN;
Hans de Goede49809d62009-06-07 12:10:39 -03002723
2724 PDEBUG(D_PROBE, "Uploading quantization tables");
2725
Hans de Goede1876bb92009-06-14 06:45:50 -03002726 if (sd->bridge == BRIDGE_OV511 || sd->bridge == BRIDGE_OV511PLUS) {
2727 pYTable = yQuanTable511;
2728 pUVTable = uvQuanTable511;
Jean-François Moine87bae742010-11-12 05:31:34 -03002729 size = 32;
Hans de Goede1876bb92009-06-14 06:45:50 -03002730 } else {
2731 pYTable = yQuanTable518;
2732 pUVTable = uvQuanTable518;
Jean-François Moine87bae742010-11-12 05:31:34 -03002733 size = 16;
Hans de Goede1876bb92009-06-14 06:45:50 -03002734 }
2735
2736 for (i = 0; i < size; i++) {
Hans de Goede49809d62009-06-07 12:10:39 -03002737 val0 = *pYTable++;
2738 val1 = *pYTable++;
2739 val0 &= 0x0f;
2740 val1 &= 0x0f;
2741 val0 |= val1 << 4;
Jean-François Moinef8f20182010-11-12 07:54:02 -03002742 reg_w(sd, reg, val0);
Hans de Goede49809d62009-06-07 12:10:39 -03002743
2744 val0 = *pUVTable++;
2745 val1 = *pUVTable++;
2746 val0 &= 0x0f;
2747 val1 &= 0x0f;
2748 val0 |= val1 << 4;
Jean-François Moinef8f20182010-11-12 07:54:02 -03002749 reg_w(sd, reg + size, val0);
Hans de Goede49809d62009-06-07 12:10:39 -03002750
2751 reg++;
2752 }
Hans de Goede49809d62009-06-07 12:10:39 -03002753}
2754
Hans de Goede1876bb92009-06-14 06:45:50 -03002755/* This initializes the OV511/OV511+ and the sensor */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002756static void ov511_configure(struct gspca_dev *gspca_dev)
Hans de Goede1876bb92009-06-14 06:45:50 -03002757{
2758 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede1876bb92009-06-14 06:45:50 -03002759
2760 /* For 511 and 511+ */
2761 const struct ov_regvals init_511[] = {
2762 { R51x_SYS_RESET, 0x7f },
2763 { R51x_SYS_INIT, 0x01 },
2764 { R51x_SYS_RESET, 0x7f },
2765 { R51x_SYS_INIT, 0x01 },
2766 { R51x_SYS_RESET, 0x3f },
2767 { R51x_SYS_INIT, 0x01 },
2768 { R51x_SYS_RESET, 0x3d },
2769 };
2770
2771 const struct ov_regvals norm_511[] = {
Jean-François Moine780e3122010-10-19 04:29:10 -03002772 { R511_DRAM_FLOW_CTL, 0x01 },
Hans de Goede1876bb92009-06-14 06:45:50 -03002773 { R51x_SYS_SNAP, 0x00 },
2774 { R51x_SYS_SNAP, 0x02 },
2775 { R51x_SYS_SNAP, 0x00 },
2776 { R511_FIFO_OPTS, 0x1f },
2777 { R511_COMP_EN, 0x00 },
2778 { R511_COMP_LUT_EN, 0x03 },
2779 };
2780
2781 const struct ov_regvals norm_511_p[] = {
2782 { R511_DRAM_FLOW_CTL, 0xff },
2783 { R51x_SYS_SNAP, 0x00 },
2784 { R51x_SYS_SNAP, 0x02 },
2785 { R51x_SYS_SNAP, 0x00 },
2786 { R511_FIFO_OPTS, 0xff },
2787 { R511_COMP_EN, 0x00 },
2788 { R511_COMP_LUT_EN, 0x03 },
2789 };
2790
2791 const struct ov_regvals compress_511[] = {
2792 { 0x70, 0x1f },
2793 { 0x71, 0x05 },
2794 { 0x72, 0x06 },
2795 { 0x73, 0x06 },
2796 { 0x74, 0x14 },
2797 { 0x75, 0x03 },
2798 { 0x76, 0x04 },
2799 { 0x77, 0x04 },
2800 };
2801
2802 PDEBUG(D_PROBE, "Device custom id %x", reg_r(sd, R51x_SYS_CUST_ID));
2803
Jean-François Moinef8f20182010-11-12 07:54:02 -03002804 write_regvals(sd, init_511, ARRAY_SIZE(init_511));
Hans de Goede1876bb92009-06-14 06:45:50 -03002805
2806 switch (sd->bridge) {
2807 case BRIDGE_OV511:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002808 write_regvals(sd, norm_511, ARRAY_SIZE(norm_511));
Hans de Goede1876bb92009-06-14 06:45:50 -03002809 break;
2810 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002811 write_regvals(sd, norm_511_p, ARRAY_SIZE(norm_511_p));
Hans de Goede1876bb92009-06-14 06:45:50 -03002812 break;
2813 }
2814
2815 /* Init compression */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002816 write_regvals(sd, compress_511, ARRAY_SIZE(compress_511));
Hans de Goede1876bb92009-06-14 06:45:50 -03002817
Jean-François Moinef8f20182010-11-12 07:54:02 -03002818 ov51x_upload_quan_tables(sd);
Hans de Goede1876bb92009-06-14 06:45:50 -03002819}
2820
Hans de Goede49809d62009-06-07 12:10:39 -03002821/* This initializes the OV518/OV518+ and the sensor */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002822static void ov518_configure(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002823{
2824 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002825
Hans de Goede49809d62009-06-07 12:10:39 -03002826 /* For 518 and 518+ */
Hans de Goedee080fcd2009-06-18 05:03:16 -03002827 const struct ov_regvals init_518[] = {
Hans de Goede49809d62009-06-07 12:10:39 -03002828 { R51x_SYS_RESET, 0x40 },
2829 { R51x_SYS_INIT, 0xe1 },
2830 { R51x_SYS_RESET, 0x3e },
2831 { R51x_SYS_INIT, 0xe1 },
2832 { R51x_SYS_RESET, 0x00 },
2833 { R51x_SYS_INIT, 0xe1 },
2834 { 0x46, 0x00 },
2835 { 0x5d, 0x03 },
2836 };
2837
Hans de Goedee080fcd2009-06-18 05:03:16 -03002838 const struct ov_regvals norm_518[] = {
Hans de Goede49809d62009-06-07 12:10:39 -03002839 { R51x_SYS_SNAP, 0x02 }, /* Reset */
2840 { R51x_SYS_SNAP, 0x01 }, /* Enable */
Jean-François Moine780e3122010-10-19 04:29:10 -03002841 { 0x31, 0x0f },
Hans de Goede49809d62009-06-07 12:10:39 -03002842 { 0x5d, 0x03 },
2843 { 0x24, 0x9f },
2844 { 0x25, 0x90 },
2845 { 0x20, 0x00 },
2846 { 0x51, 0x04 },
2847 { 0x71, 0x19 },
2848 { 0x2f, 0x80 },
2849 };
2850
Hans de Goedee080fcd2009-06-18 05:03:16 -03002851 const struct ov_regvals norm_518_p[] = {
Hans de Goede49809d62009-06-07 12:10:39 -03002852 { R51x_SYS_SNAP, 0x02 }, /* Reset */
2853 { R51x_SYS_SNAP, 0x01 }, /* Enable */
Jean-François Moine780e3122010-10-19 04:29:10 -03002854 { 0x31, 0x0f },
Hans de Goede49809d62009-06-07 12:10:39 -03002855 { 0x5d, 0x03 },
2856 { 0x24, 0x9f },
2857 { 0x25, 0x90 },
2858 { 0x20, 0x60 },
2859 { 0x51, 0x02 },
2860 { 0x71, 0x19 },
2861 { 0x40, 0xff },
2862 { 0x41, 0x42 },
2863 { 0x46, 0x00 },
2864 { 0x33, 0x04 },
2865 { 0x21, 0x19 },
2866 { 0x3f, 0x10 },
2867 { 0x2f, 0x80 },
2868 };
2869
2870 /* First 5 bits of custom ID reg are a revision ID on OV518 */
2871 PDEBUG(D_PROBE, "Device revision %d",
Jean-François Moine87bae742010-11-12 05:31:34 -03002872 0x1f & reg_r(sd, R51x_SYS_CUST_ID));
Hans de Goede49809d62009-06-07 12:10:39 -03002873
Jean-François Moinef8f20182010-11-12 07:54:02 -03002874 write_regvals(sd, init_518, ARRAY_SIZE(init_518));
Hans de Goede49809d62009-06-07 12:10:39 -03002875
2876 /* Set LED GPIO pin to output mode */
Jean-François Moinef8f20182010-11-12 07:54:02 -03002877 reg_w_mask(sd, R518_GPIO_CTL, 0x00, 0x02);
Hans de Goede49809d62009-06-07 12:10:39 -03002878
2879 switch (sd->bridge) {
2880 case BRIDGE_OV518:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002881 write_regvals(sd, norm_518, ARRAY_SIZE(norm_518));
Hans de Goede49809d62009-06-07 12:10:39 -03002882 break;
2883 case BRIDGE_OV518PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002884 write_regvals(sd, norm_518_p, ARRAY_SIZE(norm_518_p));
Hans de Goede49809d62009-06-07 12:10:39 -03002885 break;
2886 }
2887
Jean-François Moinef8f20182010-11-12 07:54:02 -03002888 ov51x_upload_quan_tables(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03002889
Jean-François Moinef8f20182010-11-12 07:54:02 -03002890 reg_w(sd, 0x2f, 0x80);
Hans de Goede49809d62009-06-07 12:10:39 -03002891}
2892
Jean-François Moinef8f20182010-11-12 07:54:02 -03002893static void ov519_configure(struct sd *sd)
Hans de Goede49809d62009-06-07 12:10:39 -03002894{
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002895 static const struct ov_regvals init_519[] = {
Jean-François Moine87bae742010-11-12 05:31:34 -03002896 { 0x5a, 0x6d }, /* EnableSystem */
2897 { 0x53, 0x9b },
Jean-François Moine21867802010-11-12 06:12:09 -03002898 { OV519_R54_EN_CLK1, 0xff }, /* set bit2 to enable jpeg */
Jean-François Moine87bae742010-11-12 05:31:34 -03002899 { 0x5d, 0x03 },
2900 { 0x49, 0x01 },
2901 { 0x48, 0x00 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002902 /* Set LED pin to output mode. Bit 4 must be cleared or sensor
2903 * detection will fail. This deserves further investigation. */
2904 { OV519_GPIO_IO_CTRL0, 0xee },
Jean-François Moine21867802010-11-12 06:12:09 -03002905 { OV519_R51_RESET1, 0x0f },
2906 { OV519_R51_RESET1, 0x00 },
Jean-François Moine87bae742010-11-12 05:31:34 -03002907 { 0x22, 0x00 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002908 /* windows reads 0x55 at this point*/
2909 };
2910
Jean-François Moinef8f20182010-11-12 07:54:02 -03002911 write_regvals(sd, init_519, ARRAY_SIZE(init_519));
Hans de Goede49809d62009-06-07 12:10:39 -03002912}
2913
Jean-François Moinef8f20182010-11-12 07:54:02 -03002914static void ovfx2_configure(struct sd *sd)
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002915{
2916 static const struct ov_regvals init_fx2[] = {
2917 { 0x00, 0x60 },
2918 { 0x02, 0x01 },
2919 { 0x0f, 0x1d },
2920 { 0xe9, 0x82 },
2921 { 0xea, 0xc7 },
2922 { 0xeb, 0x10 },
2923 { 0xec, 0xf6 },
2924 };
2925
2926 sd->stopped = 1;
2927
Jean-François Moinef8f20182010-11-12 07:54:02 -03002928 write_regvals(sd, init_fx2, ARRAY_SIZE(init_fx2));
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002929}
2930
Hans de Goede49809d62009-06-07 12:10:39 -03002931/* this function is called at probe time */
2932static int sd_config(struct gspca_dev *gspca_dev,
2933 const struct usb_device_id *id)
2934{
2935 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002936 struct cam *cam = &gspca_dev->cam;
Hans de Goede49809d62009-06-07 12:10:39 -03002937
Hans de Goede9e4d8252009-06-14 06:25:06 -03002938 sd->bridge = id->driver_info & BRIDGE_MASK;
2939 sd->invert_led = id->driver_info & BRIDGE_INVERT_LED;
Hans de Goede49809d62009-06-07 12:10:39 -03002940
2941 switch (sd->bridge) {
Hans de Goede1876bb92009-06-14 06:45:50 -03002942 case BRIDGE_OV511:
2943 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002944 ov511_configure(gspca_dev);
Hans de Goede1876bb92009-06-14 06:45:50 -03002945 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002946 case BRIDGE_OV518:
2947 case BRIDGE_OV518PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002948 ov518_configure(gspca_dev);
Hans de Goede49809d62009-06-07 12:10:39 -03002949 break;
2950 case BRIDGE_OV519:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002951 ov519_configure(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03002952 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002953 case BRIDGE_OVFX2:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002954 ovfx2_configure(sd);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002955 cam->bulk_size = OVFX2_BULK_SIZE;
2956 cam->bulk_nurbs = MAX_NURBS;
2957 cam->bulk = 1;
2958 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03002959 case BRIDGE_W9968CF:
Jean-François Moinef8f20182010-11-12 07:54:02 -03002960 w9968cf_configure(sd);
Hans de Goedea511ba92009-10-16 07:13:07 -03002961 cam->reverse_alts = 1;
2962 break;
Hans de Goede49809d62009-06-07 12:10:39 -03002963 }
2964
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002965 ov51x_led_control(sd, 0); /* turn LED off */
2966
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002967 /* The OV519 must be more aggressive about sensor detection since
2968 * I2C write will never fail if the sensor is not present. We have
2969 * to try to initialize the sensor to detect its presence */
Jean-François Moine7bbe6b82010-11-11 08:27:24 -03002970 sd->sensor = -1;
Hans de Goede229bb7d2009-10-11 07:41:46 -03002971
2972 /* Test for 76xx */
2973 if (init_ov_sensor(sd, OV7xx0_SID) >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03002974 ov7xx0_configure(sd);
2975
Hans de Goede229bb7d2009-10-11 07:41:46 -03002976 /* Test for 6xx0 */
2977 } else if (init_ov_sensor(sd, OV6xx0_SID) >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03002978 ov6xx0_configure(sd);
2979
Hans de Goede229bb7d2009-10-11 07:41:46 -03002980 /* Test for 8xx0 */
2981 } else if (init_ov_sensor(sd, OV8xx0_SID) >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03002982 ov8xx0_configure(sd);
2983
Hans de Goede635118d2009-10-11 09:49:03 -03002984 /* Test for 3xxx / 2xxx */
2985 } else if (init_ov_sensor(sd, OV_HIRES_SID) >= 0) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03002986 ov_hires_configure(sd);
Hans de Goede229bb7d2009-10-11 07:41:46 -03002987 } else {
Jean-François Moine0b656322010-09-13 05:19:58 -03002988 err("Can't determine sensor slave IDs");
Hans de Goede229bb7d2009-10-11 07:41:46 -03002989 goto error;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002990 }
2991
Jean-François Moine7bbe6b82010-11-11 08:27:24 -03002992 if (sd->sensor < 0)
2993 goto error;
2994
Hans de Goede49809d62009-06-07 12:10:39 -03002995 switch (sd->bridge) {
Hans de Goede1876bb92009-06-14 06:45:50 -03002996 case BRIDGE_OV511:
2997 case BRIDGE_OV511PLUS:
2998 if (!sd->sif) {
2999 cam->cam_mode = ov511_vga_mode;
3000 cam->nmodes = ARRAY_SIZE(ov511_vga_mode);
3001 } else {
3002 cam->cam_mode = ov511_sif_mode;
3003 cam->nmodes = ARRAY_SIZE(ov511_sif_mode);
3004 }
3005 break;
Hans de Goede49809d62009-06-07 12:10:39 -03003006 case BRIDGE_OV518:
3007 case BRIDGE_OV518PLUS:
3008 if (!sd->sif) {
3009 cam->cam_mode = ov518_vga_mode;
3010 cam->nmodes = ARRAY_SIZE(ov518_vga_mode);
3011 } else {
3012 cam->cam_mode = ov518_sif_mode;
3013 cam->nmodes = ARRAY_SIZE(ov518_sif_mode);
3014 }
3015 break;
3016 case BRIDGE_OV519:
3017 if (!sd->sif) {
3018 cam->cam_mode = ov519_vga_mode;
3019 cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
3020 } else {
3021 cam->cam_mode = ov519_sif_mode;
3022 cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
3023 }
3024 break;
Hans de Goede635118d2009-10-11 09:49:03 -03003025 case BRIDGE_OVFX2:
3026 if (sd->sensor == SEN_OV2610) {
3027 cam->cam_mode = ovfx2_ov2610_mode;
3028 cam->nmodes = ARRAY_SIZE(ovfx2_ov2610_mode);
3029 } else if (sd->sensor == SEN_OV3610) {
3030 cam->cam_mode = ovfx2_ov3610_mode;
3031 cam->nmodes = ARRAY_SIZE(ovfx2_ov3610_mode);
3032 } else if (!sd->sif) {
3033 cam->cam_mode = ov519_vga_mode;
3034 cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
3035 } else {
3036 cam->cam_mode = ov519_sif_mode;
3037 cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
3038 }
3039 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03003040 case BRIDGE_W9968CF:
3041 cam->cam_mode = w9968cf_vga_mode;
3042 cam->nmodes = ARRAY_SIZE(w9968cf_vga_mode);
Hans de Goede79b35902009-10-19 06:08:01 -03003043 if (sd->sif)
3044 cam->nmodes--;
Hans de Goedea511ba92009-10-16 07:13:07 -03003045
3046 /* w9968cf needs initialisation once the sensor is known */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003047 w9968cf_init(sd);
Hans de Goedea511ba92009-10-16 07:13:07 -03003048 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003049 }
Jean-François Moine62833ac2010-10-02 04:27:02 -03003050 gspca_dev->cam.ctrls = sd->ctrls;
Hans de Goede79b35902009-10-19 06:08:01 -03003051 sd->quality = QUALITY_DEF;
Jean-François Moine83db7682010-11-12 07:14:08 -03003052
3053 gspca_dev->ctrl_dis = ctrl_dis[sd->sensor];
Hans de Goede02ab18b2009-06-14 04:32:04 -03003054
Jean-François Moinef8f20182010-11-12 07:54:02 -03003055 return gspca_dev->usb_err;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003056error:
3057 PDEBUG(D_ERR, "OV519 Config failed");
Jean-François Moine7bbe6b82010-11-11 08:27:24 -03003058 return -EINVAL;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003059}
3060
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03003061/* this function is called at probe and resume time */
3062static int sd_init(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003063{
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003064 struct sd *sd = (struct sd *) gspca_dev;
3065
3066 /* initialize the sensor */
3067 switch (sd->sensor) {
Hans de Goede635118d2009-10-11 09:49:03 -03003068 case SEN_OV2610:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003069 write_i2c_regvals(sd, norm_2610, ARRAY_SIZE(norm_2610));
3070
Hans de Goede635118d2009-10-11 09:49:03 -03003071 /* Enable autogain, autoexpo, awb, bandfilter */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003072 i2c_w_mask(sd, 0x13, 0x27, 0x27);
Hans de Goede635118d2009-10-11 09:49:03 -03003073 break;
3074 case SEN_OV3610:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003075 write_i2c_regvals(sd, norm_3620b, ARRAY_SIZE(norm_3620b));
3076
Hans de Goede635118d2009-10-11 09:49:03 -03003077 /* Enable autogain, autoexpo, awb, bandfilter */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003078 i2c_w_mask(sd, 0x13, 0x27, 0x27);
Hans de Goede635118d2009-10-11 09:49:03 -03003079 break;
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003080 case SEN_OV6620:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003081 write_i2c_regvals(sd, norm_6x20, ARRAY_SIZE(norm_6x20));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003082 break;
3083 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03003084 case SEN_OV66308AF:
Jean-François Moine62833ac2010-10-02 04:27:02 -03003085 sd->ctrls[CONTRAST].def = 200;
3086 /* The default is too low for the ov6630 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003087 write_i2c_regvals(sd, norm_6x30, ARRAY_SIZE(norm_6x30));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003088 break;
3089 default:
3090/* case SEN_OV7610: */
3091/* case SEN_OV76BE: */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003092 write_i2c_regvals(sd, norm_7610, ARRAY_SIZE(norm_7610));
3093 i2c_w_mask(sd, 0x0e, 0x00, 0x40);
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003094 break;
3095 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03003096 case SEN_OV7620AE:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003097 write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003098 break;
3099 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003100 case SEN_OV7648:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003101 write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003102 break;
3103 case SEN_OV7670:
Jean-François Moine62833ac2010-10-02 04:27:02 -03003104 sd->ctrls[FREQ].max = 3; /* auto */
3105 sd->ctrls[FREQ].def = 3;
Jean-François Moinef8f20182010-11-12 07:54:02 -03003106 write_i2c_regvals(sd, norm_7670, ARRAY_SIZE(norm_7670));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003107 break;
3108 case SEN_OV8610:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003109 write_i2c_regvals(sd, norm_8610, ARRAY_SIZE(norm_8610));
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003110 break;
3111 }
Jean-François Moinef8f20182010-11-12 07:54:02 -03003112 return gspca_dev->usb_err;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003113}
3114
Hans de Goede1876bb92009-06-14 06:45:50 -03003115/* Set up the OV511/OV511+ with the given image parameters.
3116 *
3117 * Do not put any sensor-specific code in here (including I2C I/O functions)
3118 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003119static void ov511_mode_init_regs(struct sd *sd)
Hans de Goede1876bb92009-06-14 06:45:50 -03003120{
3121 int hsegs, vsegs, packet_size, fps, needed;
3122 int interlaced = 0;
3123 struct usb_host_interface *alt;
3124 struct usb_interface *intf;
3125
3126 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
3127 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
3128 if (!alt) {
Jean-François Moine0b656322010-09-13 05:19:58 -03003129 err("Couldn't get altsetting");
Jean-François Moinef8f20182010-11-12 07:54:02 -03003130 sd->gspca_dev.usb_err = -EIO;
3131 return;
Hans de Goede1876bb92009-06-14 06:45:50 -03003132 }
3133
3134 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
3135 reg_w(sd, R51x_FIFO_PSIZE, packet_size >> 5);
3136
3137 reg_w(sd, R511_CAM_UV_EN, 0x01);
3138 reg_w(sd, R511_SNAP_UV_EN, 0x01);
3139 reg_w(sd, R511_SNAP_OPTS, 0x03);
3140
3141 /* Here I'm assuming that snapshot size == image size.
3142 * I hope that's always true. --claudio
3143 */
3144 hsegs = (sd->gspca_dev.width >> 3) - 1;
3145 vsegs = (sd->gspca_dev.height >> 3) - 1;
3146
3147 reg_w(sd, R511_CAM_PXCNT, hsegs);
3148 reg_w(sd, R511_CAM_LNCNT, vsegs);
3149 reg_w(sd, R511_CAM_PXDIV, 0x00);
3150 reg_w(sd, R511_CAM_LNDIV, 0x00);
3151
3152 /* YUV420, low pass filter on */
3153 reg_w(sd, R511_CAM_OPTS, 0x03);
3154
3155 /* Snapshot additions */
3156 reg_w(sd, R511_SNAP_PXCNT, hsegs);
3157 reg_w(sd, R511_SNAP_LNCNT, vsegs);
3158 reg_w(sd, R511_SNAP_PXDIV, 0x00);
3159 reg_w(sd, R511_SNAP_LNDIV, 0x00);
3160
3161 /******** Set the framerate ********/
3162 if (frame_rate > 0)
3163 sd->frame_rate = frame_rate;
3164
3165 switch (sd->sensor) {
3166 case SEN_OV6620:
3167 /* No framerate control, doesn't like higher rates yet */
3168 sd->clockdiv = 3;
3169 break;
3170
3171 /* Note once the FIXME's in mode_init_ov_sensor_regs() are fixed
3172 for more sensors we need to do this for them too */
3173 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03003174 case SEN_OV7620AE:
Hans de Goede1876bb92009-06-14 06:45:50 -03003175 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003176 case SEN_OV7648:
Hans de Goedeb282d872009-06-14 19:10:40 -03003177 case SEN_OV76BE:
Hans de Goede1876bb92009-06-14 06:45:50 -03003178 if (sd->gspca_dev.width == 320)
3179 interlaced = 1;
3180 /* Fall through */
3181 case SEN_OV6630:
Hans de Goede1876bb92009-06-14 06:45:50 -03003182 case SEN_OV7610:
3183 case SEN_OV7670:
3184 switch (sd->frame_rate) {
3185 case 30:
3186 case 25:
3187 /* Not enough bandwidth to do 640x480 @ 30 fps */
3188 if (sd->gspca_dev.width != 640) {
3189 sd->clockdiv = 0;
3190 break;
3191 }
3192 /* Fall through for 640x480 case */
3193 default:
3194/* case 20: */
3195/* case 15: */
3196 sd->clockdiv = 1;
3197 break;
3198 case 10:
3199 sd->clockdiv = 2;
3200 break;
3201 case 5:
3202 sd->clockdiv = 5;
3203 break;
3204 }
3205 if (interlaced) {
3206 sd->clockdiv = (sd->clockdiv + 1) * 2 - 1;
3207 /* Higher then 10 does not work */
3208 if (sd->clockdiv > 10)
3209 sd->clockdiv = 10;
3210 }
3211 break;
3212
3213 case SEN_OV8610:
3214 /* No framerate control ?? */
3215 sd->clockdiv = 0;
3216 break;
3217 }
3218
3219 /* Check if we have enough bandwidth to disable compression */
3220 fps = (interlaced ? 60 : 30) / (sd->clockdiv + 1) + 1;
3221 needed = fps * sd->gspca_dev.width * sd->gspca_dev.height * 3 / 2;
3222 /* 1400 is a conservative estimate of the max nr of isoc packets/sec */
3223 if (needed > 1400 * packet_size) {
3224 /* Enable Y and UV quantization and compression */
3225 reg_w(sd, R511_COMP_EN, 0x07);
3226 reg_w(sd, R511_COMP_LUT_EN, 0x03);
3227 } else {
3228 reg_w(sd, R511_COMP_EN, 0x06);
3229 reg_w(sd, R511_COMP_LUT_EN, 0x00);
3230 }
3231
3232 reg_w(sd, R51x_SYS_RESET, OV511_RESET_OMNICE);
3233 reg_w(sd, R51x_SYS_RESET, 0);
Hans de Goede1876bb92009-06-14 06:45:50 -03003234}
3235
Hans de Goede49809d62009-06-07 12:10:39 -03003236/* Sets up the OV518/OV518+ with the given image parameters
3237 *
3238 * OV518 needs a completely different approach, until we can figure out what
3239 * the individual registers do. Also, only 15 FPS is supported now.
3240 *
3241 * Do not put any sensor-specific code in here (including I2C I/O functions)
3242 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003243static void ov518_mode_init_regs(struct sd *sd)
Hans de Goede49809d62009-06-07 12:10:39 -03003244{
Hans de Goedeb282d872009-06-14 19:10:40 -03003245 int hsegs, vsegs, packet_size;
3246 struct usb_host_interface *alt;
3247 struct usb_interface *intf;
3248
3249 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
3250 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
3251 if (!alt) {
Jean-François Moine0b656322010-09-13 05:19:58 -03003252 err("Couldn't get altsetting");
Jean-François Moinef8f20182010-11-12 07:54:02 -03003253 sd->gspca_dev.usb_err = -EIO;
3254 return;
Hans de Goedeb282d872009-06-14 19:10:40 -03003255 }
3256
3257 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
3258 ov518_reg_w32(sd, R51x_FIFO_PSIZE, packet_size & ~7, 2);
Hans de Goede49809d62009-06-07 12:10:39 -03003259
3260 /******** Set the mode ********/
Hans de Goede49809d62009-06-07 12:10:39 -03003261 reg_w(sd, 0x2b, 0);
3262 reg_w(sd, 0x2c, 0);
3263 reg_w(sd, 0x2d, 0);
3264 reg_w(sd, 0x2e, 0);
3265 reg_w(sd, 0x3b, 0);
3266 reg_w(sd, 0x3c, 0);
3267 reg_w(sd, 0x3d, 0);
3268 reg_w(sd, 0x3e, 0);
3269
3270 if (sd->bridge == BRIDGE_OV518) {
3271 /* Set 8-bit (YVYU) input format */
3272 reg_w_mask(sd, 0x20, 0x08, 0x08);
3273
3274 /* Set 12-bit (4:2:0) output format */
3275 reg_w_mask(sd, 0x28, 0x80, 0xf0);
3276 reg_w_mask(sd, 0x38, 0x80, 0xf0);
3277 } else {
3278 reg_w(sd, 0x28, 0x80);
3279 reg_w(sd, 0x38, 0x80);
3280 }
3281
3282 hsegs = sd->gspca_dev.width / 16;
3283 vsegs = sd->gspca_dev.height / 4;
3284
3285 reg_w(sd, 0x29, hsegs);
3286 reg_w(sd, 0x2a, vsegs);
3287
3288 reg_w(sd, 0x39, hsegs);
3289 reg_w(sd, 0x3a, vsegs);
3290
3291 /* Windows driver does this here; who knows why */
3292 reg_w(sd, 0x2f, 0x80);
3293
Jean-François Moine87bae742010-11-12 05:31:34 -03003294 /******** Set the framerate ********/
Hans de Goedeb282d872009-06-14 19:10:40 -03003295 sd->clockdiv = 1;
Hans de Goede49809d62009-06-07 12:10:39 -03003296
3297 /* Mode independent, but framerate dependent, regs */
Hans de Goedeb282d872009-06-14 19:10:40 -03003298 /* 0x51: Clock divider; Only works on some cams which use 2 crystals */
3299 reg_w(sd, 0x51, 0x04);
Hans de Goede49809d62009-06-07 12:10:39 -03003300 reg_w(sd, 0x22, 0x18);
3301 reg_w(sd, 0x23, 0xff);
3302
Hans de Goedeb282d872009-06-14 19:10:40 -03003303 if (sd->bridge == BRIDGE_OV518PLUS) {
3304 switch (sd->sensor) {
Hans de Goede859cc472010-01-07 15:42:35 -03003305 case SEN_OV7620AE:
Hans de Goedeb282d872009-06-14 19:10:40 -03003306 if (sd->gspca_dev.width == 320) {
3307 reg_w(sd, 0x20, 0x00);
3308 reg_w(sd, 0x21, 0x19);
3309 } else {
3310 reg_w(sd, 0x20, 0x60);
3311 reg_w(sd, 0x21, 0x1f);
3312 }
3313 break;
Hans de Goede859cc472010-01-07 15:42:35 -03003314 case SEN_OV7620:
3315 reg_w(sd, 0x20, 0x00);
3316 reg_w(sd, 0x21, 0x19);
3317 break;
Hans de Goedeb282d872009-06-14 19:10:40 -03003318 default:
3319 reg_w(sd, 0x21, 0x19);
3320 }
3321 } else
Hans de Goede49809d62009-06-07 12:10:39 -03003322 reg_w(sd, 0x71, 0x17); /* Compression-related? */
3323
3324 /* FIXME: Sensor-specific */
3325 /* Bit 5 is what matters here. Of course, it is "reserved" */
3326 i2c_w(sd, 0x54, 0x23);
3327
3328 reg_w(sd, 0x2f, 0x80);
3329
3330 if (sd->bridge == BRIDGE_OV518PLUS) {
3331 reg_w(sd, 0x24, 0x94);
3332 reg_w(sd, 0x25, 0x90);
3333 ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
3334 ov518_reg_w32(sd, 0xc6, 540, 2); /* 21ch */
3335 ov518_reg_w32(sd, 0xc7, 540, 2); /* 21ch */
3336 ov518_reg_w32(sd, 0xc8, 108, 2); /* 6ch */
3337 ov518_reg_w32(sd, 0xca, 131098, 3); /* 2001ah */
3338 ov518_reg_w32(sd, 0xcb, 532, 2); /* 214h */
3339 ov518_reg_w32(sd, 0xcc, 2400, 2); /* 960h */
3340 ov518_reg_w32(sd, 0xcd, 32, 2); /* 20h */
3341 ov518_reg_w32(sd, 0xce, 608, 2); /* 260h */
3342 } else {
3343 reg_w(sd, 0x24, 0x9f);
3344 reg_w(sd, 0x25, 0x90);
3345 ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
3346 ov518_reg_w32(sd, 0xc6, 381, 2); /* 17dh */
3347 ov518_reg_w32(sd, 0xc7, 381, 2); /* 17dh */
3348 ov518_reg_w32(sd, 0xc8, 128, 2); /* 80h */
3349 ov518_reg_w32(sd, 0xca, 183331, 3); /* 2cc23h */
3350 ov518_reg_w32(sd, 0xcb, 746, 2); /* 2eah */
3351 ov518_reg_w32(sd, 0xcc, 1750, 2); /* 6d6h */
3352 ov518_reg_w32(sd, 0xcd, 45, 2); /* 2dh */
3353 ov518_reg_w32(sd, 0xce, 851, 2); /* 353h */
3354 }
3355
3356 reg_w(sd, 0x2f, 0x80);
Hans de Goede49809d62009-06-07 12:10:39 -03003357}
3358
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003359/* Sets up the OV519 with the given image parameters
3360 *
3361 * OV519 needs a completely different approach, until we can figure out what
3362 * the individual registers do.
3363 *
3364 * Do not put any sensor-specific code in here (including I2C I/O functions)
3365 */
Jean-François Moinef8f20182010-11-12 07:54:02 -03003366static void ov519_mode_init_regs(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003367{
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03003368 static const struct ov_regvals mode_init_519_ov7670[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003369 { 0x5d, 0x03 }, /* Turn off suspend mode */
3370 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
Jean-François Moine21867802010-11-12 06:12:09 -03003371 { OV519_R54_EN_CLK1, 0x0f }, /* bit2 (jpeg enable) */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003372 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
3373 { 0xa3, 0x18 },
3374 { 0xa4, 0x04 },
3375 { 0xa5, 0x28 },
3376 { 0x37, 0x00 }, /* SetUsbInit */
3377 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
3378 /* Enable both fields, YUV Input, disable defect comp (why?) */
3379 { 0x20, 0x0c },
3380 { 0x21, 0x38 },
3381 { 0x22, 0x1d },
3382 { 0x17, 0x50 }, /* undocumented */
3383 { 0x37, 0x00 }, /* undocumented */
3384 { 0x40, 0xff }, /* I2C timeout counter */
3385 { 0x46, 0x00 }, /* I2C clock prescaler */
3386 { 0x59, 0x04 }, /* new from windrv 090403 */
3387 { 0xff, 0x00 }, /* undocumented */
3388 /* windows reads 0x55 at this point, why? */
3389 };
3390
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03003391 static const struct ov_regvals mode_init_519[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003392 { 0x5d, 0x03 }, /* Turn off suspend mode */
3393 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
Jean-François Moine21867802010-11-12 06:12:09 -03003394 { OV519_R54_EN_CLK1, 0x0f }, /* bit2 (jpeg enable) */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003395 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
3396 { 0xa3, 0x18 },
3397 { 0xa4, 0x04 },
3398 { 0xa5, 0x28 },
3399 { 0x37, 0x00 }, /* SetUsbInit */
3400 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
3401 /* Enable both fields, YUV Input, disable defect comp (why?) */
3402 { 0x22, 0x1d },
3403 { 0x17, 0x50 }, /* undocumented */
3404 { 0x37, 0x00 }, /* undocumented */
3405 { 0x40, 0xff }, /* I2C timeout counter */
3406 { 0x46, 0x00 }, /* I2C clock prescaler */
3407 { 0x59, 0x04 }, /* new from windrv 090403 */
3408 { 0xff, 0x00 }, /* undocumented */
3409 /* windows reads 0x55 at this point, why? */
3410 };
3411
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003412 /******** Set the mode ********/
3413 if (sd->sensor != SEN_OV7670) {
Jean-François Moinef8f20182010-11-12 07:54:02 -03003414 write_regvals(sd, mode_init_519, ARRAY_SIZE(mode_init_519));
Hans de Goede035d3a32010-01-09 08:14:43 -03003415 if (sd->sensor == SEN_OV7640 ||
3416 sd->sensor == SEN_OV7648) {
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003417 /* Select 8-bit input mode */
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003418 reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10);
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003419 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003420 } else {
Jean-François Moinef8f20182010-11-12 07:54:02 -03003421 write_regvals(sd, mode_init_519_ov7670,
3422 ARRAY_SIZE(mode_init_519_ov7670));
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003423 }
3424
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003425 reg_w(sd, OV519_R10_H_SIZE, sd->gspca_dev.width >> 4);
3426 reg_w(sd, OV519_R11_V_SIZE, sd->gspca_dev.height >> 3);
Hans de Goede80142ef2009-06-14 06:26:49 -03003427 if (sd->sensor == SEN_OV7670 &&
3428 sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
3429 reg_w(sd, OV519_R12_X_OFFSETL, 0x04);
Hans de Goede035d3a32010-01-09 08:14:43 -03003430 else if (sd->sensor == SEN_OV7648 &&
3431 sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
3432 reg_w(sd, OV519_R12_X_OFFSETL, 0x01);
Hans de Goede80142ef2009-06-14 06:26:49 -03003433 else
3434 reg_w(sd, OV519_R12_X_OFFSETL, 0x00);
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003435 reg_w(sd, OV519_R13_X_OFFSETH, 0x00);
3436 reg_w(sd, OV519_R14_Y_OFFSETL, 0x00);
3437 reg_w(sd, OV519_R15_Y_OFFSETH, 0x00);
3438 reg_w(sd, OV519_R16_DIVIDER, 0x00);
3439 reg_w(sd, OV519_R25_FORMAT, 0x03); /* YUV422 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003440 reg_w(sd, 0x26, 0x00); /* Undocumented */
3441
3442 /******** Set the framerate ********/
3443 if (frame_rate > 0)
3444 sd->frame_rate = frame_rate;
3445
3446/* FIXME: These are only valid at the max resolution. */
3447 sd->clockdiv = 0;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003448 switch (sd->sensor) {
3449 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003450 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003451 switch (sd->frame_rate) {
Jean-Francois Moine53e74512008-11-08 06:10:19 -03003452 default:
3453/* case 30: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003454 reg_w(sd, 0xa4, 0x0c);
3455 reg_w(sd, 0x23, 0xff);
3456 break;
3457 case 25:
3458 reg_w(sd, 0xa4, 0x0c);
3459 reg_w(sd, 0x23, 0x1f);
3460 break;
3461 case 20:
3462 reg_w(sd, 0xa4, 0x0c);
3463 reg_w(sd, 0x23, 0x1b);
3464 break;
Jean-Francois Moine53e74512008-11-08 06:10:19 -03003465 case 15:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003466 reg_w(sd, 0xa4, 0x04);
3467 reg_w(sd, 0x23, 0xff);
3468 sd->clockdiv = 1;
3469 break;
3470 case 10:
3471 reg_w(sd, 0xa4, 0x04);
3472 reg_w(sd, 0x23, 0x1f);
3473 sd->clockdiv = 1;
3474 break;
3475 case 5:
3476 reg_w(sd, 0xa4, 0x04);
3477 reg_w(sd, 0x23, 0x1b);
3478 sd->clockdiv = 1;
3479 break;
3480 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003481 break;
3482 case SEN_OV8610:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003483 switch (sd->frame_rate) {
3484 default: /* 15 fps */
3485/* case 15: */
3486 reg_w(sd, 0xa4, 0x06);
3487 reg_w(sd, 0x23, 0xff);
3488 break;
3489 case 10:
3490 reg_w(sd, 0xa4, 0x06);
3491 reg_w(sd, 0x23, 0x1f);
3492 break;
3493 case 5:
3494 reg_w(sd, 0xa4, 0x06);
3495 reg_w(sd, 0x23, 0x1b);
3496 break;
3497 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003498 break;
3499 case SEN_OV7670: /* guesses, based on 7640 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003500 PDEBUG(D_STREAM, "Setting framerate to %d fps",
3501 (sd->frame_rate == 0) ? 15 : sd->frame_rate);
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003502 reg_w(sd, 0xa4, 0x10);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003503 switch (sd->frame_rate) {
3504 case 30:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003505 reg_w(sd, 0x23, 0xff);
3506 break;
3507 case 20:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003508 reg_w(sd, 0x23, 0x1b);
3509 break;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003510 default:
3511/* case 15: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003512 reg_w(sd, 0x23, 0xff);
3513 sd->clockdiv = 1;
3514 break;
3515 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003516 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003517 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003518}
3519
Jean-François Moinef8f20182010-11-12 07:54:02 -03003520static void mode_init_ov_sensor_regs(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003521{
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003522 struct gspca_dev *gspca_dev;
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003523 int qvga, xstart, xend, ystart, yend;
Jean-François Moine9d1593a2010-11-11 08:04:06 -03003524 u8 v;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003525
3526 gspca_dev = &sd->gspca_dev;
Jean-François Moine87bae742010-11-12 05:31:34 -03003527 qvga = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003528
3529 /******** Mode (VGA/QVGA) and sensor specific regs ********/
3530 switch (sd->sensor) {
Hans de Goede635118d2009-10-11 09:49:03 -03003531 case SEN_OV2610:
3532 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3533 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
3534 i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
3535 i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
3536 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
3537 i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
3538 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
Jean-François Moinef8f20182010-11-12 07:54:02 -03003539 return;
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003540 case SEN_OV3610:
Hans de Goede635118d2009-10-11 09:49:03 -03003541 if (qvga) {
3542 xstart = (1040 - gspca_dev->width) / 2 + (0x1f << 4);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003543 ystart = (776 - gspca_dev->height) / 2;
Hans de Goede635118d2009-10-11 09:49:03 -03003544 } else {
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003545 xstart = (2076 - gspca_dev->width) / 2 + (0x10 << 4);
Hans de Goede635118d2009-10-11 09:49:03 -03003546 ystart = (1544 - gspca_dev->height) / 2;
3547 }
3548 xend = xstart + gspca_dev->width;
3549 yend = ystart + gspca_dev->height;
3550 /* Writing to the COMH register resets the other windowing regs
3551 to their default values, so we must do this first. */
3552 i2c_w_mask(sd, 0x12, qvga ? 0x40 : 0x00, 0xf0);
3553 i2c_w_mask(sd, 0x32,
3554 (((xend >> 1) & 7) << 3) | ((xstart >> 1) & 7),
3555 0x3f);
3556 i2c_w_mask(sd, 0x03,
3557 (((yend >> 1) & 3) << 2) | ((ystart >> 1) & 3),
3558 0x0f);
3559 i2c_w(sd, 0x17, xstart >> 4);
3560 i2c_w(sd, 0x18, xend >> 4);
3561 i2c_w(sd, 0x19, ystart >> 3);
3562 i2c_w(sd, 0x1a, yend >> 3);
Jean-François Moinef8f20182010-11-12 07:54:02 -03003563 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003564 case SEN_OV8610:
3565 /* For OV8610 qvga means qsvga */
3566 i2c_w_mask(sd, OV7610_REG_COM_C, qvga ? (1 << 5) : 0, 1 << 5);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003567 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3568 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3569 i2c_w_mask(sd, 0x2d, 0x00, 0x40); /* from windrv 090403 */
3570 i2c_w_mask(sd, 0x28, 0x20, 0x20); /* progressive mode on */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003571 break;
3572 case SEN_OV7610:
3573 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
Jean-François Moine780e3122010-10-19 04:29:10 -03003574 i2c_w(sd, 0x35, qvga ? 0x1e : 0x9e);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003575 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3576 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003577 break;
3578 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03003579 case SEN_OV7620AE:
Hans de Goedeb282d872009-06-14 19:10:40 -03003580 case SEN_OV76BE:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003581 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3582 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
3583 i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
3584 i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
3585 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
Hans de Goedeb282d872009-06-14 19:10:40 -03003586 i2c_w_mask(sd, 0x67, qvga ? 0xb0 : 0x90, 0xf0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003587 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003588 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3589 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3590 if (sd->sensor == SEN_OV76BE)
3591 i2c_w(sd, 0x35, qvga ? 0x1e : 0x9e);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003592 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003593 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003594 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003595 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3596 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
Hans de Goede8d0082f2010-01-09 19:45:44 -03003597 /* Setting this undocumented bit in qvga mode removes a very
3598 annoying vertical shaking of the image */
Hans de Goede035d3a32010-01-09 08:14:43 -03003599 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
Hans de Goede8d0082f2010-01-09 19:45:44 -03003600 /* Unknown */
Hans de Goede035d3a32010-01-09 08:14:43 -03003601 i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
Hans de Goede8d0082f2010-01-09 19:45:44 -03003602 /* Allow higher automatic gain (to allow higher framerates) */
Hans de Goede035d3a32010-01-09 08:14:43 -03003603 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003604 i2c_w_mask(sd, 0x12, 0x04, 0x04); /* AWB: 1 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003605 break;
3606 case SEN_OV7670:
3607 /* set COM7_FMT_VGA or COM7_FMT_QVGA
3608 * do we need to set anything else?
3609 * HSTART etc are set in set_ov_sensor_window itself */
Jean-François Moine21867802010-11-12 06:12:09 -03003610 i2c_w_mask(sd, OV7670_R12_COM7,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003611 qvga ? OV7670_COM7_FMT_QVGA : OV7670_COM7_FMT_VGA,
3612 OV7670_COM7_FMT_MASK);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003613 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
Jean-François Moine21867802010-11-12 06:12:09 -03003614 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_AWB,
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003615 OV7670_COM8_AWB);
3616 if (qvga) { /* QVGA from ov7670.c by
3617 * Jonathan Corbet */
3618 xstart = 164;
3619 xend = 28;
3620 ystart = 14;
3621 yend = 494;
3622 } else { /* VGA */
3623 xstart = 158;
3624 xend = 14;
3625 ystart = 10;
3626 yend = 490;
3627 }
3628 /* OV7670 hardware window registers are split across
3629 * multiple locations */
Jean-François Moine21867802010-11-12 06:12:09 -03003630 i2c_w(sd, OV7670_R17_HSTART, xstart >> 3);
3631 i2c_w(sd, OV7670_R18_HSTOP, xend >> 3);
3632 v = i2c_r(sd, OV7670_R32_HREF);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003633 v = (v & 0xc0) | ((xend & 0x7) << 3) | (xstart & 0x07);
3634 msleep(10); /* need to sleep between read and write to
3635 * same reg! */
Jean-François Moine21867802010-11-12 06:12:09 -03003636 i2c_w(sd, OV7670_R32_HREF, v);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003637
Jean-François Moine21867802010-11-12 06:12:09 -03003638 i2c_w(sd, OV7670_R19_VSTART, ystart >> 2);
3639 i2c_w(sd, OV7670_R1A_VSTOP, yend >> 2);
3640 v = i2c_r(sd, OV7670_R03_VREF);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003641 v = (v & 0xc0) | ((yend & 0x3) << 2) | (ystart & 0x03);
3642 msleep(10); /* need to sleep between read and write to
3643 * same reg! */
Jean-François Moine21867802010-11-12 06:12:09 -03003644 i2c_w(sd, OV7670_R03_VREF, v);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003645 break;
3646 case SEN_OV6620:
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003647 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3648 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3649 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3650 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003651 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03003652 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003653 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003654 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003655 break;
3656 default:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003657 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003658 }
3659
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003660 /******** Clock programming ********/
Hans de Goedeae49c402009-06-14 19:15:07 -03003661 i2c_w(sd, 0x11, sd->clockdiv);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003662}
3663
Jean-François Moine62833ac2010-10-02 04:27:02 -03003664static void sethvflip(struct gspca_dev *gspca_dev)
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003665{
Jean-François Moine62833ac2010-10-02 04:27:02 -03003666 struct sd *sd = (struct sd *) gspca_dev;
3667
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003668 if (sd->sensor != SEN_OV7670)
3669 return;
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003670 if (sd->gspca_dev.streaming)
3671 ov51x_stop(sd);
Jean-François Moine21867802010-11-12 06:12:09 -03003672 i2c_w_mask(sd, OV7670_R1E_MVFP,
Jean-François Moine62833ac2010-10-02 04:27:02 -03003673 OV7670_MVFP_MIRROR * sd->ctrls[HFLIP].val
3674 | OV7670_MVFP_VFLIP * sd->ctrls[VFLIP].val,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003675 OV7670_MVFP_MIRROR | OV7670_MVFP_VFLIP);
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003676 if (sd->gspca_dev.streaming)
3677 ov51x_restart(sd);
3678}
3679
Jean-François Moinef8f20182010-11-12 07:54:02 -03003680static void set_ov_sensor_window(struct sd *sd)
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003681{
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003682 struct gspca_dev *gspca_dev;
Hans de Goede124cc9c2009-06-14 05:48:00 -03003683 int qvga, crop;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003684 int hwsbase, hwebase, vwsbase, vwebase, hwscale, vwscale;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003685
Hans de Goede635118d2009-10-11 09:49:03 -03003686 /* mode setup is fully handled in mode_init_ov_sensor_regs for these */
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003687 if (sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610 ||
Jean-François Moinef8f20182010-11-12 07:54:02 -03003688 sd->sensor == SEN_OV7670) {
3689 mode_init_ov_sensor_regs(sd);
3690 return;
3691 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003692 gspca_dev = &sd->gspca_dev;
Jean-François Moine87bae742010-11-12 05:31:34 -03003693 qvga = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 1;
3694 crop = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv & 2;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003695
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003696 /* The different sensor ICs handle setting up of window differently.
3697 * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!! */
3698 switch (sd->sensor) {
3699 case SEN_OV8610:
3700 hwsbase = 0x1e;
3701 hwebase = 0x1e;
3702 vwsbase = 0x02;
3703 vwebase = 0x02;
3704 break;
3705 case SEN_OV7610:
3706 case SEN_OV76BE:
3707 hwsbase = 0x38;
3708 hwebase = 0x3a;
3709 vwsbase = vwebase = 0x05;
3710 break;
3711 case SEN_OV6620:
3712 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03003713 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003714 hwsbase = 0x38;
3715 hwebase = 0x3a;
3716 vwsbase = 0x05;
3717 vwebase = 0x06;
Hans de Goede7d971372009-06-14 05:28:17 -03003718 if (sd->sensor == SEN_OV66308AF && qvga)
Hans de Goede49809d62009-06-07 12:10:39 -03003719 /* HDG: this fixes U and V getting swapped */
Hans de Goede7d971372009-06-14 05:28:17 -03003720 hwsbase++;
Hans de Goede124cc9c2009-06-14 05:48:00 -03003721 if (crop) {
3722 hwsbase += 8;
3723 hwebase += 8;
3724 vwsbase += 11;
3725 vwebase += 11;
3726 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003727 break;
3728 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03003729 case SEN_OV7620AE:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003730 hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */
3731 hwebase = 0x2f;
3732 vwsbase = vwebase = 0x05;
3733 break;
3734 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003735 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003736 hwsbase = 0x1a;
3737 hwebase = 0x1a;
3738 vwsbase = vwebase = 0x03;
3739 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003740 default:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003741 return;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003742 }
3743
3744 switch (sd->sensor) {
3745 case SEN_OV6620:
3746 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03003747 case SEN_OV66308AF:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003748 if (qvga) { /* QCIF */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003749 hwscale = 0;
3750 vwscale = 0;
3751 } else { /* CIF */
3752 hwscale = 1;
3753 vwscale = 1; /* The datasheet says 0;
3754 * it's wrong */
3755 }
3756 break;
3757 case SEN_OV8610:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003758 if (qvga) { /* QSVGA */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003759 hwscale = 1;
3760 vwscale = 1;
3761 } else { /* SVGA */
3762 hwscale = 2;
3763 vwscale = 2;
3764 }
3765 break;
3766 default: /* SEN_OV7xx0 */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003767 if (qvga) { /* QVGA */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003768 hwscale = 1;
3769 vwscale = 0;
3770 } else { /* VGA */
3771 hwscale = 2;
3772 vwscale = 1;
3773 }
3774 }
3775
Jean-François Moinef8f20182010-11-12 07:54:02 -03003776 mode_init_ov_sensor_regs(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003777
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003778 i2c_w(sd, 0x17, hwsbase);
Hans de Goedea511ba92009-10-16 07:13:07 -03003779 i2c_w(sd, 0x18, hwebase + (sd->sensor_width >> hwscale));
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003780 i2c_w(sd, 0x19, vwsbase);
Hans de Goedea511ba92009-10-16 07:13:07 -03003781 i2c_w(sd, 0x1a, vwebase + (sd->sensor_height >> vwscale));
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003782}
3783
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003784/* -- start the camera -- */
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03003785static int sd_start(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003786{
3787 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003788
Hans de Goedea511ba92009-10-16 07:13:07 -03003789 /* Default for most bridges, allow bridge_mode_init_regs to override */
3790 sd->sensor_width = sd->gspca_dev.width;
3791 sd->sensor_height = sd->gspca_dev.height;
3792
Hans de Goede49809d62009-06-07 12:10:39 -03003793 switch (sd->bridge) {
Hans de Goede1876bb92009-06-14 06:45:50 -03003794 case BRIDGE_OV511:
3795 case BRIDGE_OV511PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003796 ov511_mode_init_regs(sd);
Hans de Goede1876bb92009-06-14 06:45:50 -03003797 break;
Hans de Goede49809d62009-06-07 12:10:39 -03003798 case BRIDGE_OV518:
3799 case BRIDGE_OV518PLUS:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003800 ov518_mode_init_regs(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03003801 break;
3802 case BRIDGE_OV519:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003803 ov519_mode_init_regs(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03003804 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003805 /* case BRIDGE_OVFX2: nothing to do */
Hans de Goedea511ba92009-10-16 07:13:07 -03003806 case BRIDGE_W9968CF:
Jean-François Moinef8f20182010-11-12 07:54:02 -03003807 w9968cf_mode_init_regs(sd);
Hans de Goedea511ba92009-10-16 07:13:07 -03003808 break;
Hans de Goede49809d62009-06-07 12:10:39 -03003809 }
Hans de Goede49809d62009-06-07 12:10:39 -03003810
Jean-François Moinef8f20182010-11-12 07:54:02 -03003811 set_ov_sensor_window(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003812
Hans de Goede49809d62009-06-07 12:10:39 -03003813 setcontrast(gspca_dev);
3814 setbrightness(gspca_dev);
3815 setcolors(gspca_dev);
Jean-François Moine62833ac2010-10-02 04:27:02 -03003816 sethvflip(gspca_dev);
3817 setautobright(gspca_dev);
3818 setfreq_i(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03003819
Hans de Goede417a4d22010-02-19 07:37:08 -03003820 /* Force clear snapshot state in case the snapshot button was
3821 pressed while we weren't streaming */
3822 sd->snapshot_needs_reset = 1;
3823 sd_reset_snapshot(gspca_dev);
Hans de Goede417a4d22010-02-19 07:37:08 -03003824
Hans de Goeded6b6d7a2010-05-08 08:55:42 -03003825 sd->first_frame = 3;
3826
Jean-François Moinef8f20182010-11-12 07:54:02 -03003827 ov51x_restart(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003828 ov51x_led_control(sd, 1);
Jean-François Moinef8f20182010-11-12 07:54:02 -03003829 return gspca_dev->usb_err;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003830}
3831
3832static void sd_stopN(struct gspca_dev *gspca_dev)
3833{
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003834 struct sd *sd = (struct sd *) gspca_dev;
3835
3836 ov51x_stop(sd);
3837 ov51x_led_control(sd, 0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003838}
3839
Hans de Goede79b35902009-10-19 06:08:01 -03003840static void sd_stop0(struct gspca_dev *gspca_dev)
3841{
3842 struct sd *sd = (struct sd *) gspca_dev;
3843
Jean-François Moined65174c2010-11-11 06:20:42 -03003844 if (!sd->gspca_dev.present)
3845 return;
Hans de Goede79b35902009-10-19 06:08:01 -03003846 if (sd->bridge == BRIDGE_W9968CF)
3847 w9968cf_stop0(sd);
Hans de Goede614d0692010-10-27 07:42:28 -03003848
Jean-François Moine14653e62010-11-11 06:17:01 -03003849#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
Hans de Goede614d0692010-10-27 07:42:28 -03003850 /* If the last button state is pressed, release it now! */
3851 if (sd->snapshot_pressed) {
3852 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
3853 input_sync(gspca_dev->input_dev);
3854 sd->snapshot_pressed = 0;
3855 }
3856#endif
Hans de Goede79b35902009-10-19 06:08:01 -03003857}
3858
Hans de Goede92e232a2010-02-20 04:30:45 -03003859static void ov51x_handle_button(struct gspca_dev *gspca_dev, u8 state)
3860{
3861 struct sd *sd = (struct sd *) gspca_dev;
3862
3863 if (sd->snapshot_pressed != state) {
Jean-François Moine28566432010-10-01 07:33:26 -03003864#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
Hans de Goede92e232a2010-02-20 04:30:45 -03003865 input_report_key(gspca_dev->input_dev, KEY_CAMERA, state);
3866 input_sync(gspca_dev->input_dev);
3867#endif
3868 if (state)
3869 sd->snapshot_needs_reset = 1;
3870
3871 sd->snapshot_pressed = state;
3872 } else {
Hans de Goede88e8d202010-02-20 04:45:49 -03003873 /* On the ov511 / ov519 we need to reset the button state
3874 multiple times, as resetting does not work as long as the
3875 button stays pressed */
3876 switch (sd->bridge) {
3877 case BRIDGE_OV511:
3878 case BRIDGE_OV511PLUS:
3879 case BRIDGE_OV519:
3880 if (state)
3881 sd->snapshot_needs_reset = 1;
3882 break;
3883 }
Hans de Goede92e232a2010-02-20 04:30:45 -03003884 }
3885}
3886
Hans de Goede1876bb92009-06-14 06:45:50 -03003887static void ov511_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003888 u8 *in, /* isoc packet */
3889 int len) /* iso packet length */
Hans de Goede1876bb92009-06-14 06:45:50 -03003890{
3891 struct sd *sd = (struct sd *) gspca_dev;
3892
3893 /* SOF/EOF packets have 1st to 8th bytes zeroed and the 9th
3894 * byte non-zero. The EOF packet has image width/height in the
3895 * 10th and 11th bytes. The 9th byte is given as follows:
3896 *
3897 * bit 7: EOF
3898 * 6: compression enabled
3899 * 5: 422/420/400 modes
3900 * 4: 422/420/400 modes
3901 * 3: 1
3902 * 2: snapshot button on
3903 * 1: snapshot frame
3904 * 0: even/odd field
3905 */
3906 if (!(in[0] | in[1] | in[2] | in[3] | in[4] | in[5] | in[6] | in[7]) &&
3907 (in[8] & 0x08)) {
Hans de Goede88e8d202010-02-20 04:45:49 -03003908 ov51x_handle_button(gspca_dev, (in[8] >> 2) & 1);
Hans de Goede1876bb92009-06-14 06:45:50 -03003909 if (in[8] & 0x80) {
3910 /* Frame end */
3911 if ((in[9] + 1) * 8 != gspca_dev->width ||
3912 (in[10] + 1) * 8 != gspca_dev->height) {
3913 PDEBUG(D_ERR, "Invalid frame size, got: %dx%d,"
3914 " requested: %dx%d\n",
3915 (in[9] + 1) * 8, (in[10] + 1) * 8,
3916 gspca_dev->width, gspca_dev->height);
3917 gspca_dev->last_packet_type = DISCARD_PACKET;
3918 return;
3919 }
3920 /* Add 11 byte footer to frame, might be usefull */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003921 gspca_frame_add(gspca_dev, LAST_PACKET, in, 11);
Hans de Goede1876bb92009-06-14 06:45:50 -03003922 return;
3923 } else {
3924 /* Frame start */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003925 gspca_frame_add(gspca_dev, FIRST_PACKET, in, 0);
Hans de Goede1876bb92009-06-14 06:45:50 -03003926 sd->packet_nr = 0;
3927 }
3928 }
3929
3930 /* Ignore the packet number */
3931 len--;
3932
3933 /* intermediate packet */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003934 gspca_frame_add(gspca_dev, INTER_PACKET, in, len);
Hans de Goede1876bb92009-06-14 06:45:50 -03003935}
3936
Hans de Goede49809d62009-06-07 12:10:39 -03003937static void ov518_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003938 u8 *data, /* isoc packet */
Hans de Goede49809d62009-06-07 12:10:39 -03003939 int len) /* iso packet length */
3940{
Hans de Goede92918a52009-06-14 06:21:35 -03003941 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede49809d62009-06-07 12:10:39 -03003942
3943 /* A false positive here is likely, until OVT gives me
3944 * the definitive SOF/EOF format */
3945 if ((!(data[0] | data[1] | data[2] | data[3] | data[5])) && data[6]) {
Hans de Goede92e232a2010-02-20 04:30:45 -03003946 ov51x_handle_button(gspca_dev, (data[6] >> 1) & 1);
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003947 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
3948 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
Hans de Goede92918a52009-06-14 06:21:35 -03003949 sd->packet_nr = 0;
3950 }
3951
3952 if (gspca_dev->last_packet_type == DISCARD_PACKET)
3953 return;
3954
3955 /* Does this device use packet numbers ? */
3956 if (len & 7) {
3957 len--;
3958 if (sd->packet_nr == data[len])
3959 sd->packet_nr++;
3960 /* The last few packets of the frame (which are all 0's
3961 except that they may contain part of the footer), are
3962 numbered 0 */
3963 else if (sd->packet_nr == 0 || data[len]) {
3964 PDEBUG(D_ERR, "Invalid packet nr: %d (expect: %d)",
3965 (int)data[len], (int)sd->packet_nr);
3966 gspca_dev->last_packet_type = DISCARD_PACKET;
3967 return;
3968 }
Hans de Goede49809d62009-06-07 12:10:39 -03003969 }
3970
3971 /* intermediate packet */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003972 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03003973}
3974
3975static void ov519_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03003976 u8 *data, /* isoc packet */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003977 int len) /* iso packet length */
3978{
3979 /* Header of ov519 is 16 bytes:
3980 * Byte Value Description
3981 * 0 0xff magic
3982 * 1 0xff magic
3983 * 2 0xff magic
3984 * 3 0xXX 0x50 = SOF, 0x51 = EOF
3985 * 9 0xXX 0x01 initial frame without data,
3986 * 0x00 standard frame with image
3987 * 14 Lo in EOF: length of image data / 8
3988 * 15 Hi
3989 */
3990
3991 if (data[0] == 0xff && data[1] == 0xff && data[2] == 0xff) {
3992 switch (data[3]) {
3993 case 0x50: /* start of frame */
Hans de Goede417a4d22010-02-19 07:37:08 -03003994 /* Don't check the button state here, as the state
3995 usually (always ?) changes at EOF and checking it
3996 here leads to unnecessary snapshot state resets. */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003997#define HDRSZ 16
3998 data += HDRSZ;
3999 len -= HDRSZ;
4000#undef HDRSZ
4001 if (data[0] == 0xff || data[1] == 0xd8)
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004002 gspca_frame_add(gspca_dev, FIRST_PACKET,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004003 data, len);
4004 else
4005 gspca_dev->last_packet_type = DISCARD_PACKET;
4006 return;
4007 case 0x51: /* end of frame */
Hans de Goede92e232a2010-02-20 04:30:45 -03004008 ov51x_handle_button(gspca_dev, data[11] & 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004009 if (data[9] != 0)
4010 gspca_dev->last_packet_type = DISCARD_PACKET;
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004011 gspca_frame_add(gspca_dev, LAST_PACKET,
4012 NULL, 0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004013 return;
4014 }
4015 }
4016
4017 /* intermediate packet */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004018 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004019}
4020
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004021static void ovfx2_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004022 u8 *data, /* isoc packet */
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004023 int len) /* iso packet length */
4024{
Hans de Goeded6b6d7a2010-05-08 08:55:42 -03004025 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goeded6b6d7a2010-05-08 08:55:42 -03004026
4027 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
4028
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004029 /* A short read signals EOF */
4030 if (len < OVFX2_BULK_SIZE) {
Hans de Goeded6b6d7a2010-05-08 08:55:42 -03004031 /* If the frame is short, and it is one of the first ones
4032 the sensor and bridge are still syncing, so drop it. */
4033 if (sd->first_frame) {
4034 sd->first_frame--;
Jean-François Moineb192ca92010-06-27 03:08:19 -03004035 if (gspca_dev->image_len <
4036 sd->gspca_dev.width * sd->gspca_dev.height)
Hans de Goeded6b6d7a2010-05-08 08:55:42 -03004037 gspca_dev->last_packet_type = DISCARD_PACKET;
4038 }
4039 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004040 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004041 }
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004042}
4043
Hans de Goede49809d62009-06-07 12:10:39 -03004044static void sd_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004045 u8 *data, /* isoc packet */
Hans de Goede49809d62009-06-07 12:10:39 -03004046 int len) /* iso packet length */
4047{
4048 struct sd *sd = (struct sd *) gspca_dev;
4049
4050 switch (sd->bridge) {
4051 case BRIDGE_OV511:
4052 case BRIDGE_OV511PLUS:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004053 ov511_pkt_scan(gspca_dev, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03004054 break;
4055 case BRIDGE_OV518:
4056 case BRIDGE_OV518PLUS:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004057 ov518_pkt_scan(gspca_dev, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03004058 break;
4059 case BRIDGE_OV519:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004060 ov519_pkt_scan(gspca_dev, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03004061 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004062 case BRIDGE_OVFX2:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004063 ovfx2_pkt_scan(gspca_dev, data, len);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004064 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03004065 case BRIDGE_W9968CF:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004066 w9968cf_pkt_scan(gspca_dev, data, len);
Hans de Goedea511ba92009-10-16 07:13:07 -03004067 break;
Hans de Goede49809d62009-06-07 12:10:39 -03004068 }
4069}
4070
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004071/* -- management routines -- */
4072
4073static void setbrightness(struct gspca_dev *gspca_dev)
4074{
4075 struct sd *sd = (struct sd *) gspca_dev;
4076 int val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004077
Jean-François Moine62833ac2010-10-02 04:27:02 -03004078 val = sd->ctrls[BRIGHTNESS].val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004079 switch (sd->sensor) {
4080 case SEN_OV8610:
4081 case SEN_OV7610:
4082 case SEN_OV76BE:
4083 case SEN_OV6620:
4084 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03004085 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004086 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03004087 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004088 i2c_w(sd, OV7610_REG_BRT, val);
4089 break;
4090 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03004091 case SEN_OV7620AE:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004092 /* 7620 doesn't like manual changes when in auto mode */
Jean-François Moine62833ac2010-10-02 04:27:02 -03004093 if (!sd->ctrls[AUTOBRIGHT].val)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004094 i2c_w(sd, OV7610_REG_BRT, val);
4095 break;
4096 case SEN_OV7670:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03004097/*win trace
Jean-François Moine21867802010-11-12 06:12:09 -03004098 * i2c_w_mask(sd, OV7670_R13_COM8, 0, OV7670_COM8_AEC); */
4099 i2c_w(sd, OV7670_R55_BRIGHT, ov7670_abs_to_sm(val));
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004100 break;
4101 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004102}
4103
4104static void setcontrast(struct gspca_dev *gspca_dev)
4105{
4106 struct sd *sd = (struct sd *) gspca_dev;
4107 int val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004108
Jean-François Moine62833ac2010-10-02 04:27:02 -03004109 val = sd->ctrls[CONTRAST].val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004110 switch (sd->sensor) {
4111 case SEN_OV7610:
4112 case SEN_OV6620:
4113 i2c_w(sd, OV7610_REG_CNT, val);
4114 break;
4115 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03004116 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004117 i2c_w_mask(sd, OV7610_REG_CNT, val >> 4, 0x0f);
Hans de Goede49809d62009-06-07 12:10:39 -03004118 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004119 case SEN_OV8610: {
Jean-François Moine9d1593a2010-11-11 08:04:06 -03004120 static const u8 ctab[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004121 0x03, 0x09, 0x0b, 0x0f, 0x53, 0x6f, 0x35, 0x7f
4122 };
4123
4124 /* Use Y gamma control instead. Bit 0 enables it. */
4125 i2c_w(sd, 0x64, ctab[val >> 5]);
4126 break;
4127 }
Hans de Goede859cc472010-01-07 15:42:35 -03004128 case SEN_OV7620:
4129 case SEN_OV7620AE: {
Jean-François Moine9d1593a2010-11-11 08:04:06 -03004130 static const u8 ctab[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004131 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
4132 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
4133 };
4134
4135 /* Use Y gamma control instead. Bit 0 enables it. */
4136 i2c_w(sd, 0x64, ctab[val >> 4]);
4137 break;
4138 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004139 case SEN_OV7670:
4140 /* check that this isn't just the same as ov7610 */
Jean-François Moine21867802010-11-12 06:12:09 -03004141 i2c_w(sd, OV7670_R56_CONTRAS, val >> 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004142 break;
4143 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004144}
4145
4146static void setcolors(struct gspca_dev *gspca_dev)
4147{
4148 struct sd *sd = (struct sd *) gspca_dev;
4149 int val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004150
Jean-François Moine62833ac2010-10-02 04:27:02 -03004151 val = sd->ctrls[COLORS].val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004152 switch (sd->sensor) {
4153 case SEN_OV8610:
4154 case SEN_OV7610:
4155 case SEN_OV76BE:
4156 case SEN_OV6620:
4157 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03004158 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004159 i2c_w(sd, OV7610_REG_SAT, val);
4160 break;
4161 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03004162 case SEN_OV7620AE:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004163 /* Use UV gamma control instead. Bits 0 & 7 are reserved. */
4164/* rc = ov_i2c_write(sd->dev, 0x62, (val >> 9) & 0x7e);
4165 if (rc < 0)
4166 goto out; */
4167 i2c_w(sd, OV7610_REG_SAT, val);
4168 break;
4169 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03004170 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004171 i2c_w(sd, OV7610_REG_SAT, val & 0xf0);
4172 break;
4173 case SEN_OV7670:
4174 /* supported later once I work out how to do it
4175 * transparently fail now! */
4176 /* set REG_COM13 values for UV sat auto mode */
4177 break;
4178 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004179}
4180
Jean-François Moine62833ac2010-10-02 04:27:02 -03004181static void setautobright(struct gspca_dev *gspca_dev)
Hans de Goede02ab18b2009-06-14 04:32:04 -03004182{
Jean-François Moine62833ac2010-10-02 04:27:02 -03004183 struct sd *sd = (struct sd *) gspca_dev;
4184
Hans de Goede035d3a32010-01-09 08:14:43 -03004185 if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7648 ||
4186 sd->sensor == SEN_OV7670 ||
Hans de Goede635118d2009-10-11 09:49:03 -03004187 sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610)
Hans de Goede02ab18b2009-06-14 04:32:04 -03004188 return;
4189
Jean-François Moine62833ac2010-10-02 04:27:02 -03004190 i2c_w_mask(sd, 0x2d, sd->ctrls[AUTOBRIGHT].val ? 0x10 : 0x00, 0x10);
Hans de Goede02ab18b2009-06-14 04:32:04 -03004191}
4192
Jean-François Moine62833ac2010-10-02 04:27:02 -03004193static void setfreq_i(struct sd *sd)
Hans de Goede02ab18b2009-06-14 04:32:04 -03004194{
Hans de Goede635118d2009-10-11 09:49:03 -03004195 if (sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610)
4196 return;
4197
Hans de Goede02ab18b2009-06-14 04:32:04 -03004198 if (sd->sensor == SEN_OV7670) {
Jean-François Moine62833ac2010-10-02 04:27:02 -03004199 switch (sd->ctrls[FREQ].val) {
Hans de Goede02ab18b2009-06-14 04:32:04 -03004200 case 0: /* Banding filter disabled */
Jean-François Moine21867802010-11-12 06:12:09 -03004201 i2c_w_mask(sd, OV7670_R13_COM8, 0, OV7670_COM8_BFILT);
Hans de Goede02ab18b2009-06-14 04:32:04 -03004202 break;
4203 case 1: /* 50 hz */
Jean-François Moine21867802010-11-12 06:12:09 -03004204 i2c_w_mask(sd, OV7670_R13_COM8, OV7670_COM8_BFILT,
Hans de Goede02ab18b2009-06-14 04:32:04 -03004205 OV7670_COM8_BFILT);
Jean-François Moine21867802010-11-12 06:12:09 -03004206 i2c_w_mask(sd, OV7670_R3B_COM11, 0x08, 0x18);
Hans de Goede02ab18b2009-06-14 04:32:04 -03004207 break;
4208 case 2: /* 60 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, 0x00, 0x18);
Hans de Goede02ab18b2009-06-14 04:32:04 -03004212 break;
Jean-François Moine21867802010-11-12 06:12:09 -03004213 case 3: /* Auto hz - ov7670 only */
4214 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, OV7670_COM11_HZAUTO,
Hans de Goede02ab18b2009-06-14 04:32:04 -03004217 0x18);
4218 break;
4219 }
4220 } else {
Jean-François Moine62833ac2010-10-02 04:27:02 -03004221 switch (sd->ctrls[FREQ].val) {
Hans de Goede02ab18b2009-06-14 04:32:04 -03004222 case 0: /* Banding filter disabled */
4223 i2c_w_mask(sd, 0x2d, 0x00, 0x04);
4224 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
4225 break;
4226 case 1: /* 50 hz (filter on and framerate adj) */
4227 i2c_w_mask(sd, 0x2d, 0x04, 0x04);
4228 i2c_w_mask(sd, 0x2a, 0x80, 0x80);
4229 /* 20 fps -> 16.667 fps */
4230 if (sd->sensor == SEN_OV6620 ||
Hans de Goede7d971372009-06-14 05:28:17 -03004231 sd->sensor == SEN_OV6630 ||
4232 sd->sensor == SEN_OV66308AF)
Hans de Goede02ab18b2009-06-14 04:32:04 -03004233 i2c_w(sd, 0x2b, 0x5e);
4234 else
4235 i2c_w(sd, 0x2b, 0xac);
4236 break;
4237 case 2: /* 60 hz (filter on, ...) */
4238 i2c_w_mask(sd, 0x2d, 0x04, 0x04);
4239 if (sd->sensor == SEN_OV6620 ||
Hans de Goede7d971372009-06-14 05:28:17 -03004240 sd->sensor == SEN_OV6630 ||
4241 sd->sensor == SEN_OV66308AF) {
Hans de Goede02ab18b2009-06-14 04:32:04 -03004242 /* 20 fps -> 15 fps */
4243 i2c_w_mask(sd, 0x2a, 0x80, 0x80);
4244 i2c_w(sd, 0x2b, 0xa8);
4245 } else {
4246 /* no framerate adj. */
4247 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
4248 }
4249 break;
4250 }
4251 }
4252}
Jean-François Moine62833ac2010-10-02 04:27:02 -03004253static void setfreq(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004254{
4255 struct sd *sd = (struct sd *) gspca_dev;
4256
Jean-François Moine62833ac2010-10-02 04:27:02 -03004257 setfreq_i(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004258
Jean-François Moine62833ac2010-10-02 04:27:02 -03004259 /* Ugly but necessary */
4260 if (sd->bridge == BRIDGE_W9968CF)
4261 w9968cf_set_crop_window(sd);
Hans de Goede02ab18b2009-06-14 04:32:04 -03004262}
4263
4264static int sd_querymenu(struct gspca_dev *gspca_dev,
4265 struct v4l2_querymenu *menu)
4266{
4267 struct sd *sd = (struct sd *) gspca_dev;
4268
4269 switch (menu->id) {
4270 case V4L2_CID_POWER_LINE_FREQUENCY:
4271 switch (menu->index) {
4272 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
4273 strcpy((char *) menu->name, "NoFliker");
4274 return 0;
4275 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
4276 strcpy((char *) menu->name, "50 Hz");
4277 return 0;
4278 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
4279 strcpy((char *) menu->name, "60 Hz");
4280 return 0;
4281 case 3:
4282 if (sd->sensor != SEN_OV7670)
4283 return -EINVAL;
4284
4285 strcpy((char *) menu->name, "Automatic");
4286 return 0;
4287 }
4288 break;
4289 }
4290 return -EINVAL;
4291}
4292
Hans de Goede79b35902009-10-19 06:08:01 -03004293static int sd_get_jcomp(struct gspca_dev *gspca_dev,
4294 struct v4l2_jpegcompression *jcomp)
4295{
4296 struct sd *sd = (struct sd *) gspca_dev;
4297
4298 if (sd->bridge != BRIDGE_W9968CF)
4299 return -EINVAL;
4300
4301 memset(jcomp, 0, sizeof *jcomp);
4302 jcomp->quality = sd->quality;
4303 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT | V4L2_JPEG_MARKER_DQT |
4304 V4L2_JPEG_MARKER_DRI;
4305 return 0;
4306}
4307
4308static int sd_set_jcomp(struct gspca_dev *gspca_dev,
4309 struct v4l2_jpegcompression *jcomp)
4310{
4311 struct sd *sd = (struct sd *) gspca_dev;
4312
4313 if (sd->bridge != BRIDGE_W9968CF)
4314 return -EINVAL;
4315
4316 if (gspca_dev->streaming)
4317 return -EBUSY;
4318
4319 if (jcomp->quality < QUALITY_MIN)
4320 sd->quality = QUALITY_MIN;
4321 else if (jcomp->quality > QUALITY_MAX)
4322 sd->quality = QUALITY_MAX;
4323 else
4324 sd->quality = jcomp->quality;
4325
4326 /* Return resulting jcomp params to app */
4327 sd_get_jcomp(gspca_dev, jcomp);
4328
4329 return 0;
4330}
4331
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004332/* sub-driver description */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03004333static const struct sd_desc sd_desc = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004334 .name = MODULE_NAME,
4335 .ctrls = sd_ctrls,
4336 .nctrls = ARRAY_SIZE(sd_ctrls),
4337 .config = sd_config,
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03004338 .init = sd_init,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004339 .start = sd_start,
4340 .stopN = sd_stopN,
Hans de Goede79b35902009-10-19 06:08:01 -03004341 .stop0 = sd_stop0,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004342 .pkt_scan = sd_pkt_scan,
Hans de Goede417a4d22010-02-19 07:37:08 -03004343 .dq_callback = sd_reset_snapshot,
Hans de Goede02ab18b2009-06-14 04:32:04 -03004344 .querymenu = sd_querymenu,
Hans de Goede79b35902009-10-19 06:08:01 -03004345 .get_jcomp = sd_get_jcomp,
4346 .set_jcomp = sd_set_jcomp,
Jean-François Moine28566432010-10-01 07:33:26 -03004347#if defined(CONFIG_INPUT) || defined(CONFIG_INPUT_MODULE)
Hans de Goede417a4d22010-02-19 07:37:08 -03004348 .other_input = 1,
4349#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004350};
4351
4352/* -- module initialisation -- */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03004353static const __devinitdata struct usb_device_id device_table[] = {
Hans de Goedea511ba92009-10-16 07:13:07 -03004354 {USB_DEVICE(0x041e, 0x4003), .driver_info = BRIDGE_W9968CF },
Hans de Goede49809d62009-06-07 12:10:39 -03004355 {USB_DEVICE(0x041e, 0x4052), .driver_info = BRIDGE_OV519 },
4356 {USB_DEVICE(0x041e, 0x405f), .driver_info = BRIDGE_OV519 },
4357 {USB_DEVICE(0x041e, 0x4060), .driver_info = BRIDGE_OV519 },
4358 {USB_DEVICE(0x041e, 0x4061), .driver_info = BRIDGE_OV519 },
Hans de Goede9e4d8252009-06-14 06:25:06 -03004359 {USB_DEVICE(0x041e, 0x4064),
Jean-François Moine87bae742010-11-12 05:31:34 -03004360 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
Rafal Milecki518c8df2009-10-02 03:54:44 -03004361 {USB_DEVICE(0x041e, 0x4067), .driver_info = BRIDGE_OV519 },
Hans de Goede9e4d8252009-06-14 06:25:06 -03004362 {USB_DEVICE(0x041e, 0x4068),
Jean-François Moine87bae742010-11-12 05:31:34 -03004363 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
Hans de Goede49809d62009-06-07 12:10:39 -03004364 {USB_DEVICE(0x045e, 0x028c), .driver_info = BRIDGE_OV519 },
4365 {USB_DEVICE(0x054c, 0x0154), .driver_info = BRIDGE_OV519 },
Hans de Goede98184f72010-01-07 12:06:00 -03004366 {USB_DEVICE(0x054c, 0x0155),
Jean-François Moine87bae742010-11-12 05:31:34 -03004367 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
Hans de Goede1876bb92009-06-14 06:45:50 -03004368 {USB_DEVICE(0x05a9, 0x0511), .driver_info = BRIDGE_OV511 },
Hans de Goede49809d62009-06-07 12:10:39 -03004369 {USB_DEVICE(0x05a9, 0x0518), .driver_info = BRIDGE_OV518 },
4370 {USB_DEVICE(0x05a9, 0x0519), .driver_info = BRIDGE_OV519 },
4371 {USB_DEVICE(0x05a9, 0x0530), .driver_info = BRIDGE_OV519 },
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004372 {USB_DEVICE(0x05a9, 0x2800), .driver_info = BRIDGE_OVFX2 },
Hans de Goede49809d62009-06-07 12:10:39 -03004373 {USB_DEVICE(0x05a9, 0x4519), .driver_info = BRIDGE_OV519 },
4374 {USB_DEVICE(0x05a9, 0x8519), .driver_info = BRIDGE_OV519 },
Hans de Goede1876bb92009-06-14 06:45:50 -03004375 {USB_DEVICE(0x05a9, 0xa511), .driver_info = BRIDGE_OV511PLUS },
Hans de Goede49809d62009-06-07 12:10:39 -03004376 {USB_DEVICE(0x05a9, 0xa518), .driver_info = BRIDGE_OV518PLUS },
Hans de Goede1876bb92009-06-14 06:45:50 -03004377 {USB_DEVICE(0x0813, 0x0002), .driver_info = BRIDGE_OV511PLUS },
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004378 {USB_DEVICE(0x0b62, 0x0059), .driver_info = BRIDGE_OVFX2 },
4379 {USB_DEVICE(0x0e96, 0xc001), .driver_info = BRIDGE_OVFX2 },
Hans de Goedea511ba92009-10-16 07:13:07 -03004380 {USB_DEVICE(0x1046, 0x9967), .driver_info = BRIDGE_W9968CF },
Jean-François Moine87bae742010-11-12 05:31:34 -03004381 {USB_DEVICE(0x8020, 0xef04), .driver_info = BRIDGE_OVFX2 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004382 {}
4383};
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03004384
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004385MODULE_DEVICE_TABLE(usb, device_table);
4386
4387/* -- device connect -- */
4388static int sd_probe(struct usb_interface *intf,
4389 const struct usb_device_id *id)
4390{
4391 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
4392 THIS_MODULE);
4393}
4394
4395static struct usb_driver sd_driver = {
4396 .name = MODULE_NAME,
4397 .id_table = device_table,
4398 .probe = sd_probe,
4399 .disconnect = gspca_disconnect,
Jean-Francois Moine6a709742008-09-03 16:48:10 -03004400#ifdef CONFIG_PM
4401 .suspend = gspca_suspend,
4402 .resume = gspca_resume,
4403#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004404};
4405
4406/* -- module insert / remove -- */
4407static int __init sd_mod_init(void)
4408{
Jean-François Moine54826432010-09-13 04:53:03 -03004409 return usb_register(&sd_driver);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004410}
4411static void __exit sd_mod_exit(void)
4412{
4413 usb_deregister(&sd_driver);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004414}
4415
4416module_init(sd_mod_init);
4417module_exit(sd_mod_exit);
4418
4419module_param(frame_rate, int, 0644);
4420MODULE_PARM_DESC(frame_rate, "Frame rate (5, 10, 15, 20 or 30 fps)");