blob: 016f8bb5c3754071c08312149c858d48e2f362e7 [file] [log] [blame]
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001/**
2 * OV519 driver
3 *
4 * Copyright (C) 2008 Jean-Francois Moine (http://moinejf.free.fr)
Hans de Goedeb46aaa02009-10-12 10:07:57 -03005 * Copyright (C) 2009 Hans de Goede <hdegoede@redhat.com>
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03006 *
Romain Beauxis2961e872008-12-05 06:25:26 -03007 * This module is adapted from the ov51x-jpeg package, which itself
8 * was adapted from the ov511 driver.
9 *
10 * Original copyright for the ov511 driver is:
11 *
Hans de Goedeb46aaa02009-10-12 10:07:57 -030012 * Copyright (c) 1999-2006 Mark W. McClelland
Romain Beauxis2961e872008-12-05 06:25:26 -030013 * Support for OV519, OV8610 Copyright (c) 2003 Joerg Heckenbach
Hans de Goedeb46aaa02009-10-12 10:07:57 -030014 * Many improvements by Bret Wallach <bwallac1@san.rr.com>
15 * Color fixes by by Orion Sky Lawlor <olawlor@acm.org> (2/26/2000)
16 * OV7620 fixes by Charl P. Botha <cpbotha@ieee.org>
17 * Changes by Claudio Matsuoka <claudio@conectiva.com>
Romain Beauxis2961e872008-12-05 06:25:26 -030018 *
19 * ov51x-jpeg original copyright is:
20 *
21 * Copyright (c) 2004-2007 Romain Beauxis <toots@rastageeks.org>
22 * Support for OV7670 sensors was contributed by Sam Skipsey <aoanla@yahoo.com>
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030023 *
24 * This program is free software; you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 2 of the License, or
27 * any later version.
28 *
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
33 *
34 * You should have received a copy of the GNU General Public License
35 * along with this program; if not, write to the Free Software
36 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37 *
38 */
39#define MODULE_NAME "ov519"
40
Hans de Goede417a4d22010-02-19 07:37:08 -030041#include <linux/input.h>
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030042#include "gspca.h"
43
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030044MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
45MODULE_DESCRIPTION("OV519 USB Camera Driver");
46MODULE_LICENSE("GPL");
47
48/* global parameters */
49static int frame_rate;
50
51/* Number of times to retry a failed I2C transaction. Increase this if you
52 * are getting "Failed to read sensor ID..." */
53static int i2c_detect_tries = 10;
54
55/* ov519 device descriptor */
56struct sd {
57 struct gspca_dev gspca_dev; /* !! must be the first item */
58
Hans de Goede92918a52009-06-14 06:21:35 -030059 __u8 packet_nr;
60
Hans de Goede49809d62009-06-07 12:10:39 -030061 char bridge;
62#define BRIDGE_OV511 0
63#define BRIDGE_OV511PLUS 1
64#define BRIDGE_OV518 2
65#define BRIDGE_OV518PLUS 3
66#define BRIDGE_OV519 4
Hans de Goede635118d2009-10-11 09:49:03 -030067#define BRIDGE_OVFX2 5
Hans de Goedea511ba92009-10-16 07:13:07 -030068#define BRIDGE_W9968CF 6
Hans de Goede9e4d8252009-06-14 06:25:06 -030069#define BRIDGE_MASK 7
70
71 char invert_led;
72#define BRIDGE_INVERT_LED 8
Hans de Goede49809d62009-06-07 12:10:39 -030073
Hans de Goede417a4d22010-02-19 07:37:08 -030074 char snapshot_pressed;
75 char snapshot_needs_reset;
76
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030077 /* Determined by sensor type */
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -030078 __u8 sif;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030079
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -030080 __u8 brightness;
81 __u8 contrast;
82 __u8 colors;
Jean-Francois Moine0cd67592008-07-29 05:25:28 -030083 __u8 hflip;
84 __u8 vflip;
Hans de Goede02ab18b2009-06-14 04:32:04 -030085 __u8 autobrightness;
86 __u8 freq;
Hans de Goede79b35902009-10-19 06:08:01 -030087 __u8 quality;
88#define QUALITY_MIN 50
89#define QUALITY_MAX 70
90#define QUALITY_DEF 50
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030091
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -030092 __u8 stopped; /* Streaming is temporarily paused */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030093
Hans de Goede1876bb92009-06-14 06:45:50 -030094 __u8 frame_rate; /* current Framerate */
95 __u8 clockdiv; /* clockdiv override */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -030096
97 char sensor; /* Type of image sensor chip (SEN_*) */
98#define SEN_UNKNOWN 0
Hans de Goede635118d2009-10-11 09:49:03 -030099#define SEN_OV2610 1
100#define SEN_OV3610 2
101#define SEN_OV6620 3
102#define SEN_OV6630 4
103#define SEN_OV66308AF 5
104#define SEN_OV7610 6
105#define SEN_OV7620 7
Hans de Goede859cc472010-01-07 15:42:35 -0300106#define SEN_OV7620AE 8
107#define SEN_OV7640 9
Hans de Goede035d3a32010-01-09 08:14:43 -0300108#define SEN_OV7648 10
109#define SEN_OV7670 11
110#define SEN_OV76BE 12
111#define SEN_OV8610 13
Hans de Goedea511ba92009-10-16 07:13:07 -0300112
113 u8 sensor_addr;
114 int sensor_width;
115 int sensor_height;
Hans de Goedefb1f9022009-10-16 07:42:53 -0300116 int sensor_reg_cache[256];
Hans de Goede79b35902009-10-19 06:08:01 -0300117
118 u8 *jpeg_hdr;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300119};
120
Hans de Goedea511ba92009-10-16 07:13:07 -0300121/* Note this is a bit of a hack, but the w9968cf driver needs the code for all
122 the ov sensors which is already present here. When we have the time we
123 really should move the sensor drivers to v4l2 sub drivers. */
124#include "w996Xcf.c"
125
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300126/* V4L2 controls supported by the driver */
127static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
128static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
129static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
130static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
131static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
132static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300133static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
134static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
135static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
136static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
Hans de Goede02ab18b2009-06-14 04:32:04 -0300137static int sd_setautobrightness(struct gspca_dev *gspca_dev, __s32 val);
138static int sd_getautobrightness(struct gspca_dev *gspca_dev, __s32 *val);
139static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
140static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
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);
Hans de Goede02ab18b2009-06-14 04:32:04 -0300144static void setautobrightness(struct sd *sd);
145static void setfreq(struct sd *sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300146
Hans de Goede02ab18b2009-06-14 04:32:04 -0300147static const struct ctrl sd_ctrls[] = {
Hans de Goeded02134d2010-01-09 19:22:34 -0300148#define BRIGHTNESS_IDX 0
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300149 {
150 {
151 .id = V4L2_CID_BRIGHTNESS,
152 .type = V4L2_CTRL_TYPE_INTEGER,
153 .name = "Brightness",
154 .minimum = 0,
155 .maximum = 255,
156 .step = 1,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300157#define BRIGHTNESS_DEF 127
158 .default_value = BRIGHTNESS_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300159 },
160 .set = sd_setbrightness,
161 .get = sd_getbrightness,
162 },
Hans de Goeded02134d2010-01-09 19:22:34 -0300163#define CONTRAST_IDX 1
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300164 {
165 {
166 .id = V4L2_CID_CONTRAST,
167 .type = V4L2_CTRL_TYPE_INTEGER,
168 .name = "Contrast",
169 .minimum = 0,
170 .maximum = 255,
171 .step = 1,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300172#define CONTRAST_DEF 127
173 .default_value = CONTRAST_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300174 },
175 .set = sd_setcontrast,
176 .get = sd_getcontrast,
177 },
Hans de Goeded02134d2010-01-09 19:22:34 -0300178#define COLOR_IDX 2
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300179 {
180 {
181 .id = V4L2_CID_SATURATION,
182 .type = V4L2_CTRL_TYPE_INTEGER,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300183 .name = "Color",
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300184 .minimum = 0,
185 .maximum = 255,
186 .step = 1,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300187#define COLOR_DEF 127
188 .default_value = COLOR_DEF,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300189 },
190 .set = sd_setcolors,
191 .get = sd_getcolors,
192 },
Hans de Goede02ab18b2009-06-14 04:32:04 -0300193/* The flip controls work with ov7670 only */
Jean-Francois Moinede004482008-09-03 17:12:16 -0300194#define HFLIP_IDX 3
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300195 {
196 {
197 .id = V4L2_CID_HFLIP,
198 .type = V4L2_CTRL_TYPE_BOOLEAN,
199 .name = "Mirror",
200 .minimum = 0,
201 .maximum = 1,
202 .step = 1,
203#define HFLIP_DEF 0
204 .default_value = HFLIP_DEF,
205 },
206 .set = sd_sethflip,
207 .get = sd_gethflip,
208 },
Jean-Francois Moinede004482008-09-03 17:12:16 -0300209#define VFLIP_IDX 4
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300210 {
211 {
212 .id = V4L2_CID_VFLIP,
213 .type = V4L2_CTRL_TYPE_BOOLEAN,
214 .name = "Vflip",
215 .minimum = 0,
216 .maximum = 1,
217 .step = 1,
218#define VFLIP_DEF 0
219 .default_value = VFLIP_DEF,
220 },
221 .set = sd_setvflip,
222 .get = sd_getvflip,
223 },
Hans de Goede02ab18b2009-06-14 04:32:04 -0300224#define AUTOBRIGHT_IDX 5
225 {
226 {
227 .id = V4L2_CID_AUTOBRIGHTNESS,
228 .type = V4L2_CTRL_TYPE_BOOLEAN,
229 .name = "Auto Brightness",
230 .minimum = 0,
231 .maximum = 1,
232 .step = 1,
233#define AUTOBRIGHT_DEF 1
234 .default_value = AUTOBRIGHT_DEF,
235 },
236 .set = sd_setautobrightness,
237 .get = sd_getautobrightness,
238 },
239#define FREQ_IDX 6
240 {
241 {
242 .id = V4L2_CID_POWER_LINE_FREQUENCY,
243 .type = V4L2_CTRL_TYPE_MENU,
244 .name = "Light frequency filter",
245 .minimum = 0,
246 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
247 .step = 1,
248#define FREQ_DEF 0
249 .default_value = FREQ_DEF,
250 },
251 .set = sd_setfreq,
252 .get = sd_getfreq,
253 },
254#define OV7670_FREQ_IDX 7
255 {
256 {
257 .id = V4L2_CID_POWER_LINE_FREQUENCY,
258 .type = V4L2_CTRL_TYPE_MENU,
259 .name = "Light frequency filter",
260 .minimum = 0,
261 .maximum = 3, /* 0: 0, 1: 50Hz, 2:60Hz 3: Auto Hz */
262 .step = 1,
263#define OV7670_FREQ_DEF 3
264 .default_value = OV7670_FREQ_DEF,
265 },
266 .set = sd_setfreq,
267 .get = sd_getfreq,
268 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300269};
270
Hans de Goede49809d62009-06-07 12:10:39 -0300271static const struct v4l2_pix_format ov519_vga_mode[] = {
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300272 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
273 .bytesperline = 320,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300274 .sizeimage = 320 * 240 * 3 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300275 .colorspace = V4L2_COLORSPACE_JPEG,
276 .priv = 1},
277 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
278 .bytesperline = 640,
279 .sizeimage = 640 * 480 * 3 / 8 + 590,
280 .colorspace = V4L2_COLORSPACE_JPEG,
281 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300282};
Hans de Goede49809d62009-06-07 12:10:39 -0300283static const struct v4l2_pix_format ov519_sif_mode[] = {
Hans de Goede124cc9c2009-06-14 05:48:00 -0300284 {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
285 .bytesperline = 160,
286 .sizeimage = 160 * 120 * 3 / 8 + 590,
287 .colorspace = V4L2_COLORSPACE_JPEG,
288 .priv = 3},
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300289 {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
290 .bytesperline = 176,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300291 .sizeimage = 176 * 144 * 3 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300292 .colorspace = V4L2_COLORSPACE_JPEG,
293 .priv = 1},
Hans de Goede124cc9c2009-06-14 05:48:00 -0300294 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
295 .bytesperline = 320,
296 .sizeimage = 320 * 240 * 3 / 8 + 590,
297 .colorspace = V4L2_COLORSPACE_JPEG,
298 .priv = 2},
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300299 {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
300 .bytesperline = 352,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -0300301 .sizeimage = 352 * 288 * 3 / 8 + 590,
Jean-Francois Moinec2446b32008-07-05 11:49:20 -0300302 .colorspace = V4L2_COLORSPACE_JPEG,
303 .priv = 0},
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300304};
305
Hans de Goedeb282d872009-06-14 19:10:40 -0300306/* Note some of the sizeimage values for the ov511 / ov518 may seem
307 larger then necessary, however they need to be this big as the ov511 /
308 ov518 always fills the entire isoc frame, using 0 padding bytes when
309 it doesn't have any data. So with low framerates the amount of data
310 transfered can become quite large (libv4l will remove all the 0 padding
311 in userspace). */
Hans de Goede49809d62009-06-07 12:10:39 -0300312static const struct v4l2_pix_format ov518_vga_mode[] = {
313 {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
314 .bytesperline = 320,
Hans de Goedeb282d872009-06-14 19:10:40 -0300315 .sizeimage = 320 * 240 * 3,
Hans de Goede49809d62009-06-07 12:10:39 -0300316 .colorspace = V4L2_COLORSPACE_JPEG,
317 .priv = 1},
318 {640, 480, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
319 .bytesperline = 640,
Hans de Goedeb282d872009-06-14 19:10:40 -0300320 .sizeimage = 640 * 480 * 2,
Hans de Goede49809d62009-06-07 12:10:39 -0300321 .colorspace = V4L2_COLORSPACE_JPEG,
322 .priv = 0},
323};
324static const struct v4l2_pix_format ov518_sif_mode[] = {
Hans de Goede124cc9c2009-06-14 05:48:00 -0300325 {160, 120, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
326 .bytesperline = 160,
Hans de Goedeb282d872009-06-14 19:10:40 -0300327 .sizeimage = 70000,
Hans de Goede124cc9c2009-06-14 05:48:00 -0300328 .colorspace = V4L2_COLORSPACE_JPEG,
329 .priv = 3},
Hans de Goede49809d62009-06-07 12:10:39 -0300330 {176, 144, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
331 .bytesperline = 176,
Hans de Goedeb282d872009-06-14 19:10:40 -0300332 .sizeimage = 70000,
Hans de Goede49809d62009-06-07 12:10:39 -0300333 .colorspace = V4L2_COLORSPACE_JPEG,
334 .priv = 1},
Hans de Goede124cc9c2009-06-14 05:48:00 -0300335 {320, 240, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
336 .bytesperline = 320,
Hans de Goedeb282d872009-06-14 19:10:40 -0300337 .sizeimage = 320 * 240 * 3,
Hans de Goede124cc9c2009-06-14 05:48:00 -0300338 .colorspace = V4L2_COLORSPACE_JPEG,
339 .priv = 2},
Hans de Goede49809d62009-06-07 12:10:39 -0300340 {352, 288, V4L2_PIX_FMT_OV518, V4L2_FIELD_NONE,
341 .bytesperline = 352,
Hans de Goedeb282d872009-06-14 19:10:40 -0300342 .sizeimage = 352 * 288 * 3,
Hans de Goede49809d62009-06-07 12:10:39 -0300343 .colorspace = V4L2_COLORSPACE_JPEG,
344 .priv = 0},
345};
346
Hans de Goede1876bb92009-06-14 06:45:50 -0300347static const struct v4l2_pix_format ov511_vga_mode[] = {
348 {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
349 .bytesperline = 320,
350 .sizeimage = 320 * 240 * 3,
351 .colorspace = V4L2_COLORSPACE_JPEG,
352 .priv = 1},
353 {640, 480, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
354 .bytesperline = 640,
355 .sizeimage = 640 * 480 * 2,
356 .colorspace = V4L2_COLORSPACE_JPEG,
357 .priv = 0},
358};
359static const struct v4l2_pix_format ov511_sif_mode[] = {
360 {160, 120, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
361 .bytesperline = 160,
Hans de Goedeb282d872009-06-14 19:10:40 -0300362 .sizeimage = 70000,
Hans de Goede1876bb92009-06-14 06:45:50 -0300363 .colorspace = V4L2_COLORSPACE_JPEG,
364 .priv = 3},
365 {176, 144, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
366 .bytesperline = 176,
Hans de Goedeb282d872009-06-14 19:10:40 -0300367 .sizeimage = 70000,
Hans de Goede1876bb92009-06-14 06:45:50 -0300368 .colorspace = V4L2_COLORSPACE_JPEG,
369 .priv = 1},
370 {320, 240, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
371 .bytesperline = 320,
372 .sizeimage = 320 * 240 * 3,
373 .colorspace = V4L2_COLORSPACE_JPEG,
374 .priv = 2},
375 {352, 288, V4L2_PIX_FMT_OV511, V4L2_FIELD_NONE,
376 .bytesperline = 352,
377 .sizeimage = 352 * 288 * 3,
378 .colorspace = V4L2_COLORSPACE_JPEG,
379 .priv = 0},
380};
Hans de Goede49809d62009-06-07 12:10:39 -0300381
Hans de Goede635118d2009-10-11 09:49:03 -0300382static const struct v4l2_pix_format ovfx2_vga_mode[] = {
383 {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
384 .bytesperline = 320,
385 .sizeimage = 320 * 240,
386 .colorspace = V4L2_COLORSPACE_SRGB,
387 .priv = 1},
388 {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
389 .bytesperline = 640,
390 .sizeimage = 640 * 480,
391 .colorspace = V4L2_COLORSPACE_SRGB,
392 .priv = 0},
393};
394static const struct v4l2_pix_format ovfx2_cif_mode[] = {
395 {160, 120, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
396 .bytesperline = 160,
397 .sizeimage = 160 * 120,
398 .colorspace = V4L2_COLORSPACE_SRGB,
399 .priv = 3},
400 {176, 144, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
401 .bytesperline = 176,
402 .sizeimage = 176 * 144,
403 .colorspace = V4L2_COLORSPACE_SRGB,
404 .priv = 1},
405 {320, 240, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
406 .bytesperline = 320,
407 .sizeimage = 320 * 240,
408 .colorspace = V4L2_COLORSPACE_SRGB,
409 .priv = 2},
410 {352, 288, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
411 .bytesperline = 352,
412 .sizeimage = 352 * 288,
413 .colorspace = V4L2_COLORSPACE_SRGB,
414 .priv = 0},
415};
416static const struct v4l2_pix_format ovfx2_ov2610_mode[] = {
417 {1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
418 .bytesperline = 1600,
419 .sizeimage = 1600 * 1200,
420 .colorspace = V4L2_COLORSPACE_SRGB},
421};
422static const struct v4l2_pix_format ovfx2_ov3610_mode[] = {
Hans de Goede635118d2009-10-11 09:49:03 -0300423 {640, 480, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
424 .bytesperline = 640,
425 .sizeimage = 640 * 480,
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300426 .colorspace = V4L2_COLORSPACE_SRGB,
427 .priv = 1},
428 {800, 600, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
429 .bytesperline = 800,
430 .sizeimage = 800 * 600,
431 .colorspace = V4L2_COLORSPACE_SRGB,
432 .priv = 1},
433 {1024, 768, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
434 .bytesperline = 1024,
435 .sizeimage = 1024 * 768,
436 .colorspace = V4L2_COLORSPACE_SRGB,
437 .priv = 1},
438 {1600, 1200, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
439 .bytesperline = 1600,
440 .sizeimage = 1600 * 1200,
441 .colorspace = V4L2_COLORSPACE_SRGB,
442 .priv = 0},
443 {2048, 1536, V4L2_PIX_FMT_SBGGR8, V4L2_FIELD_NONE,
444 .bytesperline = 2048,
445 .sizeimage = 2048 * 1536,
446 .colorspace = V4L2_COLORSPACE_SRGB,
447 .priv = 0},
Hans de Goede635118d2009-10-11 09:49:03 -0300448};
449
450
Hans de Goede49809d62009-06-07 12:10:39 -0300451/* Registers common to OV511 / OV518 */
Hans de Goede1876bb92009-06-14 06:45:50 -0300452#define R51x_FIFO_PSIZE 0x30 /* 2 bytes wide w/ OV518(+) */
Hans de Goede49809d62009-06-07 12:10:39 -0300453#define R51x_SYS_RESET 0x50
Hans de Goede1876bb92009-06-14 06:45:50 -0300454 /* Reset type flags */
455 #define OV511_RESET_OMNICE 0x08
Hans de Goede49809d62009-06-07 12:10:39 -0300456#define R51x_SYS_INIT 0x53
457#define R51x_SYS_SNAP 0x52
458#define R51x_SYS_CUST_ID 0x5F
459#define R51x_COMP_LUT_BEGIN 0x80
460
461/* OV511 Camera interface register numbers */
Hans de Goede1876bb92009-06-14 06:45:50 -0300462#define R511_CAM_DELAY 0x10
463#define R511_CAM_EDGE 0x11
464#define R511_CAM_PXCNT 0x12
465#define R511_CAM_LNCNT 0x13
466#define R511_CAM_PXDIV 0x14
467#define R511_CAM_LNDIV 0x15
468#define R511_CAM_UV_EN 0x16
469#define R511_CAM_LINE_MODE 0x17
470#define R511_CAM_OPTS 0x18
471
472#define R511_SNAP_FRAME 0x19
473#define R511_SNAP_PXCNT 0x1A
474#define R511_SNAP_LNCNT 0x1B
475#define R511_SNAP_PXDIV 0x1C
476#define R511_SNAP_LNDIV 0x1D
477#define R511_SNAP_UV_EN 0x1E
478#define R511_SNAP_UV_EN 0x1E
479#define R511_SNAP_OPTS 0x1F
480
481#define R511_DRAM_FLOW_CTL 0x20
482#define R511_FIFO_OPTS 0x31
483#define R511_I2C_CTL 0x40
Hans de Goede49809d62009-06-07 12:10:39 -0300484#define R511_SYS_LED_CTL 0x55 /* OV511+ only */
Hans de Goede1876bb92009-06-14 06:45:50 -0300485#define R511_COMP_EN 0x78
486#define R511_COMP_LUT_EN 0x79
Hans de Goede49809d62009-06-07 12:10:39 -0300487
488/* OV518 Camera interface register numbers */
489#define R518_GPIO_OUT 0x56 /* OV518(+) only */
490#define R518_GPIO_CTL 0x57 /* OV518(+) only */
491
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300492/* OV519 Camera interface register numbers */
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -0300493#define OV519_R10_H_SIZE 0x10
494#define OV519_R11_V_SIZE 0x11
495#define OV519_R12_X_OFFSETL 0x12
496#define OV519_R13_X_OFFSETH 0x13
497#define OV519_R14_Y_OFFSETL 0x14
498#define OV519_R15_Y_OFFSETH 0x15
499#define OV519_R16_DIVIDER 0x16
500#define OV519_R20_DFR 0x20
501#define OV519_R25_FORMAT 0x25
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300502
503/* OV519 System Controller register numbers */
504#define OV519_SYS_RESET1 0x51
505#define OV519_SYS_EN_CLK1 0x54
506
507#define OV519_GPIO_DATA_OUT0 0x71
508#define OV519_GPIO_IO_CTRL0 0x72
509
510#define OV511_ENDPOINT_ADDRESS 1 /* Isoc endpoint number */
511
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300512/*
513 * The FX2 chip does not give us a zero length read at end of frame.
514 * It does, however, give a short read at the end of a frame, if
515 * neccessary, rather than run two frames together.
516 *
517 * By choosing the right bulk transfer size, we are guaranteed to always
518 * get a short read for the last read of each frame. Frame sizes are
519 * always a composite number (width * height, or a multiple) so if we
520 * choose a prime number, we are guaranteed that the last read of a
521 * frame will be short.
522 *
523 * But it isn't that easy: the 2.6 kernel requires a multiple of 4KB,
524 * otherwise EOVERFLOW "babbling" errors occur. I have not been able
525 * to figure out why. [PMiller]
526 *
527 * The constant (13 * 4096) is the largest "prime enough" number less than 64KB.
528 *
529 * It isn't enough to know the number of bytes per frame, in case we
530 * have data dropouts or buffer overruns (even though the FX2 double
531 * buffers, there are some pretty strict real time constraints for
532 * isochronous transfer for larger frame sizes).
533 */
534#define OVFX2_BULK_SIZE (13 * 4096)
535
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300536/* I2C registers */
537#define R51x_I2C_W_SID 0x41
538#define R51x_I2C_SADDR_3 0x42
539#define R51x_I2C_SADDR_2 0x43
540#define R51x_I2C_R_SID 0x44
541#define R51x_I2C_DATA 0x45
542#define R518_I2C_CTL 0x47 /* OV518(+) only */
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300543#define OVFX2_I2C_ADDR 0x00
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300544
545/* I2C ADDRESSES */
546#define OV7xx0_SID 0x42
Hans de Goede229bb7d2009-10-11 07:41:46 -0300547#define OV_HIRES_SID 0x60 /* OV9xxx / OV2xxx / OV3xxx */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300548#define OV8xx0_SID 0xa0
549#define OV6xx0_SID 0xc0
550
551/* OV7610 registers */
552#define OV7610_REG_GAIN 0x00 /* gain setting (5:0) */
Hans de Goede49809d62009-06-07 12:10:39 -0300553#define OV7610_REG_BLUE 0x01 /* blue channel balance */
554#define OV7610_REG_RED 0x02 /* red channel balance */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300555#define OV7610_REG_SAT 0x03 /* saturation */
556#define OV8610_REG_HUE 0x04 /* 04 reserved */
557#define OV7610_REG_CNT 0x05 /* Y contrast */
558#define OV7610_REG_BRT 0x06 /* Y brightness */
559#define OV7610_REG_COM_C 0x14 /* misc common regs */
560#define OV7610_REG_ID_HIGH 0x1c /* manufacturer ID MSB */
561#define OV7610_REG_ID_LOW 0x1d /* manufacturer ID LSB */
562#define OV7610_REG_COM_I 0x29 /* misc settings */
563
564/* OV7670 registers */
565#define OV7670_REG_GAIN 0x00 /* Gain lower 8 bits (rest in vref) */
566#define OV7670_REG_BLUE 0x01 /* blue gain */
567#define OV7670_REG_RED 0x02 /* red gain */
568#define OV7670_REG_VREF 0x03 /* Pieces of GAIN, VSTART, VSTOP */
569#define OV7670_REG_COM1 0x04 /* Control 1 */
570#define OV7670_REG_AECHH 0x07 /* AEC MS 5 bits */
571#define OV7670_REG_COM3 0x0c /* Control 3 */
572#define OV7670_REG_COM4 0x0d /* Control 4 */
573#define OV7670_REG_COM5 0x0e /* All "reserved" */
574#define OV7670_REG_COM6 0x0f /* Control 6 */
575#define OV7670_REG_AECH 0x10 /* More bits of AEC value */
576#define OV7670_REG_CLKRC 0x11 /* Clock control */
577#define OV7670_REG_COM7 0x12 /* Control 7 */
578#define OV7670_COM7_FMT_VGA 0x00
579#define OV7670_COM7_YUV 0x00 /* YUV */
580#define OV7670_COM7_FMT_QVGA 0x10 /* QVGA format */
581#define OV7670_COM7_FMT_MASK 0x38
582#define OV7670_COM7_RESET 0x80 /* Register reset */
583#define OV7670_REG_COM8 0x13 /* Control 8 */
584#define OV7670_COM8_AEC 0x01 /* Auto exposure enable */
585#define OV7670_COM8_AWB 0x02 /* White balance enable */
586#define OV7670_COM8_AGC 0x04 /* Auto gain enable */
587#define OV7670_COM8_BFILT 0x20 /* Band filter enable */
588#define OV7670_COM8_AECSTEP 0x40 /* Unlimited AEC step size */
589#define OV7670_COM8_FASTAEC 0x80 /* Enable fast AGC/AEC */
590#define OV7670_REG_COM9 0x14 /* Control 9 - gain ceiling */
591#define OV7670_REG_COM10 0x15 /* Control 10 */
592#define OV7670_REG_HSTART 0x17 /* Horiz start high bits */
593#define OV7670_REG_HSTOP 0x18 /* Horiz stop high bits */
594#define OV7670_REG_VSTART 0x19 /* Vert start high bits */
595#define OV7670_REG_VSTOP 0x1a /* Vert stop high bits */
596#define OV7670_REG_MVFP 0x1e /* Mirror / vflip */
Jean-Francois Moine0cd67592008-07-29 05:25:28 -0300597#define OV7670_MVFP_VFLIP 0x10 /* vertical flip */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -0300598#define OV7670_MVFP_MIRROR 0x20 /* Mirror image */
599#define OV7670_REG_AEW 0x24 /* AGC upper limit */
600#define OV7670_REG_AEB 0x25 /* AGC lower limit */
601#define OV7670_REG_VPT 0x26 /* AGC/AEC fast mode op region */
602#define OV7670_REG_HREF 0x32 /* HREF pieces */
603#define OV7670_REG_TSLB 0x3a /* lots of stuff */
604#define OV7670_REG_COM11 0x3b /* Control 11 */
605#define OV7670_COM11_EXP 0x02
606#define OV7670_COM11_HZAUTO 0x10 /* Auto detect 50/60 Hz */
607#define OV7670_REG_COM12 0x3c /* Control 12 */
608#define OV7670_REG_COM13 0x3d /* Control 13 */
609#define OV7670_COM13_GAMMA 0x80 /* Gamma enable */
610#define OV7670_COM13_UVSAT 0x40 /* UV saturation auto adjustment */
611#define OV7670_REG_COM14 0x3e /* Control 14 */
612#define OV7670_REG_EDGE 0x3f /* Edge enhancement factor */
613#define OV7670_REG_COM15 0x40 /* Control 15 */
614#define OV7670_COM15_R00FF 0xc0 /* 00 to FF */
615#define OV7670_REG_COM16 0x41 /* Control 16 */
616#define OV7670_COM16_AWBGAIN 0x08 /* AWB gain enable */
617#define OV7670_REG_BRIGHT 0x55 /* Brightness */
618#define OV7670_REG_CONTRAS 0x56 /* Contrast control */
619#define OV7670_REG_GFIX 0x69 /* Fix gain control */
620#define OV7670_REG_RGB444 0x8c /* RGB 444 control */
621#define OV7670_REG_HAECC1 0x9f /* Hist AEC/AGC control 1 */
622#define OV7670_REG_HAECC2 0xa0 /* Hist AEC/AGC control 2 */
623#define OV7670_REG_BD50MAX 0xa5 /* 50hz banding step limit */
624#define OV7670_REG_HAECC3 0xa6 /* Hist AEC/AGC control 3 */
625#define OV7670_REG_HAECC4 0xa7 /* Hist AEC/AGC control 4 */
626#define OV7670_REG_HAECC5 0xa8 /* Hist AEC/AGC control 5 */
627#define OV7670_REG_HAECC6 0xa9 /* Hist AEC/AGC control 6 */
628#define OV7670_REG_HAECC7 0xaa /* Hist AEC/AGC control 7 */
629#define OV7670_REG_BD60MAX 0xab /* 60hz banding step limit */
630
Jean-Francois Moine4202f712008-09-03 17:12:15 -0300631struct ov_regvals {
632 __u8 reg;
633 __u8 val;
634};
635struct ov_i2c_regvals {
636 __u8 reg;
637 __u8 val;
638};
639
Hans de Goede635118d2009-10-11 09:49:03 -0300640/* Settings for OV2610 camera chip */
641static const struct ov_i2c_regvals norm_2610[] =
642{
Hans de Goedeb46aaa02009-10-12 10:07:57 -0300643 { 0x12, 0x80 }, /* reset */
Hans de Goede635118d2009-10-11 09:49:03 -0300644};
645
646static const struct ov_i2c_regvals norm_3620b[] =
647{
648 /*
649 * From the datasheet: "Note that after writing to register COMH
650 * (0x12) to change the sensor mode, registers related to the
651 * sensor’s cropping window will be reset back to their default
652 * values."
653 *
654 * "wait 4096 external clock ... to make sure the sensor is
655 * stable and ready to access registers" i.e. 160us at 24MHz
656 */
657
658 { 0x12, 0x80 }, /* COMH reset */
659 { 0x12, 0x00 }, /* QXGA, master */
660
661 /*
662 * 11 CLKRC "Clock Rate Control"
663 * [7] internal frequency doublers: on
664 * [6] video port mode: master
665 * [5:0] clock divider: 1
666 */
667 { 0x11, 0x80 },
668
669 /*
670 * 13 COMI "Common Control I"
671 * = 192 (0xC0) 11000000
672 * COMI[7] "AEC speed selection"
673 * = 1 (0x01) 1....... "Faster AEC correction"
674 * COMI[6] "AEC speed step selection"
675 * = 1 (0x01) .1...... "Big steps, fast"
676 * COMI[5] "Banding filter on off"
677 * = 0 (0x00) ..0..... "Off"
678 * COMI[4] "Banding filter option"
679 * = 0 (0x00) ...0.... "Main clock is 48 MHz and
680 * the PLL is ON"
681 * COMI[3] "Reserved"
682 * = 0 (0x00) ....0...
683 * COMI[2] "AGC auto manual control selection"
684 * = 0 (0x00) .....0.. "Manual"
685 * COMI[1] "AWB auto manual control selection"
686 * = 0 (0x00) ......0. "Manual"
687 * COMI[0] "Exposure control"
688 * = 0 (0x00) .......0 "Manual"
689 */
690 { 0x13, 0xC0 },
691
692 /*
693 * 09 COMC "Common Control C"
694 * = 8 (0x08) 00001000
695 * COMC[7:5] "Reserved"
696 * = 0 (0x00) 000.....
697 * COMC[4] "Sleep Mode Enable"
698 * = 0 (0x00) ...0.... "Normal mode"
699 * COMC[3:2] "Sensor sampling reset timing selection"
700 * = 2 (0x02) ....10.. "Longer reset time"
701 * COMC[1:0] "Output drive current select"
702 * = 0 (0x00) ......00 "Weakest"
703 */
704 { 0x09, 0x08 },
705
706 /*
707 * 0C COMD "Common Control D"
708 * = 8 (0x08) 00001000
709 * COMD[7] "Reserved"
710 * = 0 (0x00) 0.......
711 * COMD[6] "Swap MSB and LSB at the output port"
712 * = 0 (0x00) .0...... "False"
713 * COMD[5:3] "Reserved"
714 * = 1 (0x01) ..001...
715 * COMD[2] "Output Average On Off"
716 * = 0 (0x00) .....0.. "Output Normal"
717 * COMD[1] "Sensor precharge voltage selection"
718 * = 0 (0x00) ......0. "Selects internal
719 * reference precharge
720 * voltage"
721 * COMD[0] "Snapshot option"
722 * = 0 (0x00) .......0 "Enable live video output
723 * after snapshot sequence"
724 */
725 { 0x0c, 0x08 },
726
727 /*
728 * 0D COME "Common Control E"
729 * = 161 (0xA1) 10100001
730 * COME[7] "Output average option"
731 * = 1 (0x01) 1....... "Output average of 4 pixels"
732 * COME[6] "Anti-blooming control"
733 * = 0 (0x00) .0...... "Off"
734 * COME[5:3] "Reserved"
735 * = 4 (0x04) ..100...
736 * COME[2] "Clock output power down pin status"
737 * = 0 (0x00) .....0.. "Tri-state data output pin
738 * on power down"
739 * COME[1] "Data output pin status selection at power down"
740 * = 0 (0x00) ......0. "Tri-state VSYNC, PCLK,
741 * HREF, and CHSYNC pins on
742 * power down"
743 * COME[0] "Auto zero circuit select"
744 * = 1 (0x01) .......1 "On"
745 */
746 { 0x0d, 0xA1 },
747
748 /*
749 * 0E COMF "Common Control F"
750 * = 112 (0x70) 01110000
751 * COMF[7] "System clock selection"
752 * = 0 (0x00) 0....... "Use 24 MHz system clock"
753 * COMF[6:4] "Reserved"
754 * = 7 (0x07) .111....
755 * COMF[3] "Manual auto negative offset canceling selection"
756 * = 0 (0x00) ....0... "Auto detect negative
757 * offset and cancel it"
758 * COMF[2:0] "Reserved"
759 * = 0 (0x00) .....000
760 */
761 { 0x0e, 0x70 },
762
763 /*
764 * 0F COMG "Common Control G"
765 * = 66 (0x42) 01000010
766 * COMG[7] "Optical black output selection"
767 * = 0 (0x00) 0....... "Disable"
768 * COMG[6] "Black level calibrate selection"
769 * = 1 (0x01) .1...... "Use optical black pixels
770 * to calibrate"
771 * COMG[5:4] "Reserved"
772 * = 0 (0x00) ..00....
773 * COMG[3] "Channel offset adjustment"
774 * = 0 (0x00) ....0... "Disable offset adjustment"
775 * COMG[2] "ADC black level calibration option"
776 * = 0 (0x00) .....0.. "Use B/G line and G/R
777 * line to calibrate each
778 * channel's black level"
779 * COMG[1] "Reserved"
780 * = 1 (0x01) ......1.
781 * COMG[0] "ADC black level calibration enable"
782 * = 0 (0x00) .......0 "Disable"
783 */
784 { 0x0f, 0x42 },
785
786 /*
787 * 14 COMJ "Common Control J"
788 * = 198 (0xC6) 11000110
789 * COMJ[7:6] "AGC gain ceiling"
790 * = 3 (0x03) 11...... "8x"
791 * COMJ[5:4] "Reserved"
792 * = 0 (0x00) ..00....
793 * COMJ[3] "Auto banding filter"
794 * = 0 (0x00) ....0... "Banding filter is always
795 * on off depending on
796 * COMI[5] setting"
797 * COMJ[2] "VSYNC drop option"
798 * = 1 (0x01) .....1.. "SYNC is dropped if frame
799 * data is dropped"
800 * COMJ[1] "Frame data drop"
801 * = 1 (0x01) ......1. "Drop frame data if
802 * exposure is not within
803 * tolerance. In AEC mode,
804 * data is normally dropped
805 * when data is out of
806 * range."
807 * COMJ[0] "Reserved"
808 * = 0 (0x00) .......0
809 */
810 { 0x14, 0xC6 },
811
812 /*
813 * 15 COMK "Common Control K"
814 * = 2 (0x02) 00000010
815 * COMK[7] "CHSYNC pin output swap"
816 * = 0 (0x00) 0....... "CHSYNC"
817 * COMK[6] "HREF pin output swap"
818 * = 0 (0x00) .0...... "HREF"
819 * COMK[5] "PCLK output selection"
820 * = 0 (0x00) ..0..... "PCLK always output"
821 * COMK[4] "PCLK edge selection"
822 * = 0 (0x00) ...0.... "Data valid on falling edge"
823 * COMK[3] "HREF output polarity"
824 * = 0 (0x00) ....0... "positive"
825 * COMK[2] "Reserved"
826 * = 0 (0x00) .....0..
827 * COMK[1] "VSYNC polarity"
828 * = 1 (0x01) ......1. "negative"
829 * COMK[0] "HSYNC polarity"
830 * = 0 (0x00) .......0 "positive"
831 */
832 { 0x15, 0x02 },
833
834 /*
835 * 33 CHLF "Current Control"
836 * = 9 (0x09) 00001001
837 * CHLF[7:6] "Sensor current control"
838 * = 0 (0x00) 00......
839 * CHLF[5] "Sensor current range control"
840 * = 0 (0x00) ..0..... "normal range"
841 * CHLF[4] "Sensor current"
842 * = 0 (0x00) ...0.... "normal current"
843 * CHLF[3] "Sensor buffer current control"
844 * = 1 (0x01) ....1... "half current"
845 * CHLF[2] "Column buffer current control"
846 * = 0 (0x00) .....0.. "normal current"
847 * CHLF[1] "Analog DSP current control"
848 * = 0 (0x00) ......0. "normal current"
849 * CHLF[1] "ADC current control"
850 * = 0 (0x00) ......0. "normal current"
851 */
852 { 0x33, 0x09 },
853
854 /*
855 * 34 VBLM "Blooming Control"
856 * = 80 (0x50) 01010000
857 * VBLM[7] "Hard soft reset switch"
858 * = 0 (0x00) 0....... "Hard reset"
859 * VBLM[6:4] "Blooming voltage selection"
860 * = 5 (0x05) .101....
861 * VBLM[3:0] "Sensor current control"
862 * = 0 (0x00) ....0000
863 */
864 { 0x34, 0x50 },
865
866 /*
867 * 36 VCHG "Sensor Precharge Voltage Control"
868 * = 0 (0x00) 00000000
869 * VCHG[7] "Reserved"
870 * = 0 (0x00) 0.......
871 * VCHG[6:4] "Sensor precharge voltage control"
872 * = 0 (0x00) .000....
873 * VCHG[3:0] "Sensor array common reference"
874 * = 0 (0x00) ....0000
875 */
876 { 0x36, 0x00 },
877
878 /*
879 * 37 ADC "ADC Reference Control"
880 * = 4 (0x04) 00000100
881 * ADC[7:4] "Reserved"
882 * = 0 (0x00) 0000....
883 * ADC[3] "ADC input signal range"
884 * = 0 (0x00) ....0... "Input signal 1.0x"
885 * ADC[2:0] "ADC range control"
886 * = 4 (0x04) .....100
887 */
888 { 0x37, 0x04 },
889
890 /*
891 * 38 ACOM "Analog Common Ground"
892 * = 82 (0x52) 01010010
893 * ACOM[7] "Analog gain control"
894 * = 0 (0x00) 0....... "Gain 1x"
895 * ACOM[6] "Analog black level calibration"
896 * = 1 (0x01) .1...... "On"
897 * ACOM[5:0] "Reserved"
898 * = 18 (0x12) ..010010
899 */
900 { 0x38, 0x52 },
901
902 /*
903 * 3A FREFA "Internal Reference Adjustment"
904 * = 0 (0x00) 00000000
905 * FREFA[7:0] "Range"
906 * = 0 (0x00) 00000000
907 */
908 { 0x3a, 0x00 },
909
910 /*
911 * 3C FVOPT "Internal Reference Adjustment"
912 * = 31 (0x1F) 00011111
913 * FVOPT[7:0] "Range"
914 * = 31 (0x1F) 00011111
915 */
916 { 0x3c, 0x1F },
917
918 /*
919 * 44 Undocumented = 0 (0x00) 00000000
920 * 44[7:0] "It's a secret"
921 * = 0 (0x00) 00000000
922 */
923 { 0x44, 0x00 },
924
925 /*
926 * 40 Undocumented = 0 (0x00) 00000000
927 * 40[7:0] "It's a secret"
928 * = 0 (0x00) 00000000
929 */
930 { 0x40, 0x00 },
931
932 /*
933 * 41 Undocumented = 0 (0x00) 00000000
934 * 41[7:0] "It's a secret"
935 * = 0 (0x00) 00000000
936 */
937 { 0x41, 0x00 },
938
939 /*
940 * 42 Undocumented = 0 (0x00) 00000000
941 * 42[7:0] "It's a secret"
942 * = 0 (0x00) 00000000
943 */
944 { 0x42, 0x00 },
945
946 /*
947 * 43 Undocumented = 0 (0x00) 00000000
948 * 43[7:0] "It's a secret"
949 * = 0 (0x00) 00000000
950 */
951 { 0x43, 0x00 },
952
953 /*
954 * 45 Undocumented = 128 (0x80) 10000000
955 * 45[7:0] "It's a secret"
956 * = 128 (0x80) 10000000
957 */
958 { 0x45, 0x80 },
959
960 /*
961 * 48 Undocumented = 192 (0xC0) 11000000
962 * 48[7:0] "It's a secret"
963 * = 192 (0xC0) 11000000
964 */
965 { 0x48, 0xC0 },
966
967 /*
968 * 49 Undocumented = 25 (0x19) 00011001
969 * 49[7:0] "It's a secret"
970 * = 25 (0x19) 00011001
971 */
972 { 0x49, 0x19 },
973
974 /*
975 * 4B Undocumented = 128 (0x80) 10000000
976 * 4B[7:0] "It's a secret"
977 * = 128 (0x80) 10000000
978 */
979 { 0x4B, 0x80 },
980
981 /*
982 * 4D Undocumented = 196 (0xC4) 11000100
983 * 4D[7:0] "It's a secret"
984 * = 196 (0xC4) 11000100
985 */
986 { 0x4D, 0xC4 },
987
988 /*
989 * 35 VREF "Reference Voltage Control"
990 * = 76 (0x4C) 01001100
991 * VREF[7:5] "Column high reference control"
992 * = 2 (0x02) 010..... "higher voltage"
993 * VREF[4:2] "Column low reference control"
994 * = 3 (0x03) ...011.. "Highest voltage"
995 * VREF[1:0] "Reserved"
996 * = 0 (0x00) ......00
997 */
998 { 0x35, 0x4C },
999
1000 /*
1001 * 3D Undocumented = 0 (0x00) 00000000
1002 * 3D[7:0] "It's a secret"
1003 * = 0 (0x00) 00000000
1004 */
1005 { 0x3D, 0x00 },
1006
1007 /*
1008 * 3E Undocumented = 0 (0x00) 00000000
1009 * 3E[7:0] "It's a secret"
1010 * = 0 (0x00) 00000000
1011 */
1012 { 0x3E, 0x00 },
1013
1014 /*
1015 * 3B FREFB "Internal Reference Adjustment"
1016 * = 24 (0x18) 00011000
1017 * FREFB[7:0] "Range"
1018 * = 24 (0x18) 00011000
1019 */
1020 { 0x3b, 0x18 },
1021
1022 /*
1023 * 33 CHLF "Current Control"
1024 * = 25 (0x19) 00011001
1025 * CHLF[7:6] "Sensor current control"
1026 * = 0 (0x00) 00......
1027 * CHLF[5] "Sensor current range control"
1028 * = 0 (0x00) ..0..... "normal range"
1029 * CHLF[4] "Sensor current"
1030 * = 1 (0x01) ...1.... "double current"
1031 * CHLF[3] "Sensor buffer current control"
1032 * = 1 (0x01) ....1... "half current"
1033 * CHLF[2] "Column buffer current control"
1034 * = 0 (0x00) .....0.. "normal current"
1035 * CHLF[1] "Analog DSP current control"
1036 * = 0 (0x00) ......0. "normal current"
1037 * CHLF[1] "ADC current control"
1038 * = 0 (0x00) ......0. "normal current"
1039 */
1040 { 0x33, 0x19 },
1041
1042 /*
1043 * 34 VBLM "Blooming Control"
1044 * = 90 (0x5A) 01011010
1045 * VBLM[7] "Hard soft reset switch"
1046 * = 0 (0x00) 0....... "Hard reset"
1047 * VBLM[6:4] "Blooming voltage selection"
1048 * = 5 (0x05) .101....
1049 * VBLM[3:0] "Sensor current control"
1050 * = 10 (0x0A) ....1010
1051 */
1052 { 0x34, 0x5A },
1053
1054 /*
1055 * 3B FREFB "Internal Reference Adjustment"
1056 * = 0 (0x00) 00000000
1057 * FREFB[7:0] "Range"
1058 * = 0 (0x00) 00000000
1059 */
1060 { 0x3b, 0x00 },
1061
1062 /*
1063 * 33 CHLF "Current Control"
1064 * = 9 (0x09) 00001001
1065 * CHLF[7:6] "Sensor current control"
1066 * = 0 (0x00) 00......
1067 * CHLF[5] "Sensor current range control"
1068 * = 0 (0x00) ..0..... "normal range"
1069 * CHLF[4] "Sensor current"
1070 * = 0 (0x00) ...0.... "normal current"
1071 * CHLF[3] "Sensor buffer current control"
1072 * = 1 (0x01) ....1... "half current"
1073 * CHLF[2] "Column buffer current control"
1074 * = 0 (0x00) .....0.. "normal current"
1075 * CHLF[1] "Analog DSP current control"
1076 * = 0 (0x00) ......0. "normal current"
1077 * CHLF[1] "ADC current control"
1078 * = 0 (0x00) ......0. "normal current"
1079 */
1080 { 0x33, 0x09 },
1081
1082 /*
1083 * 34 VBLM "Blooming Control"
1084 * = 80 (0x50) 01010000
1085 * VBLM[7] "Hard soft reset switch"
1086 * = 0 (0x00) 0....... "Hard reset"
1087 * VBLM[6:4] "Blooming voltage selection"
1088 * = 5 (0x05) .101....
1089 * VBLM[3:0] "Sensor current control"
1090 * = 0 (0x00) ....0000
1091 */
1092 { 0x34, 0x50 },
1093
1094 /*
1095 * 12 COMH "Common Control H"
1096 * = 64 (0x40) 01000000
1097 * COMH[7] "SRST"
1098 * = 0 (0x00) 0....... "No-op"
1099 * COMH[6:4] "Resolution selection"
1100 * = 4 (0x04) .100.... "XGA"
1101 * COMH[3] "Master slave selection"
1102 * = 0 (0x00) ....0... "Master mode"
1103 * COMH[2] "Internal B/R channel option"
1104 * = 0 (0x00) .....0.. "B/R use same channel"
1105 * COMH[1] "Color bar test pattern"
1106 * = 0 (0x00) ......0. "Off"
1107 * COMH[0] "Reserved"
1108 * = 0 (0x00) .......0
1109 */
1110 { 0x12, 0x40 },
1111
1112 /*
1113 * 17 HREFST "Horizontal window start"
1114 * = 31 (0x1F) 00011111
1115 * HREFST[7:0] "Horizontal window start, 8 MSBs"
1116 * = 31 (0x1F) 00011111
1117 */
1118 { 0x17, 0x1F },
1119
1120 /*
1121 * 18 HREFEND "Horizontal window end"
1122 * = 95 (0x5F) 01011111
1123 * HREFEND[7:0] "Horizontal Window End, 8 MSBs"
1124 * = 95 (0x5F) 01011111
1125 */
1126 { 0x18, 0x5F },
1127
1128 /*
1129 * 19 VSTRT "Vertical window start"
1130 * = 0 (0x00) 00000000
1131 * VSTRT[7:0] "Vertical Window Start, 8 MSBs"
1132 * = 0 (0x00) 00000000
1133 */
1134 { 0x19, 0x00 },
1135
1136 /*
1137 * 1A VEND "Vertical window end"
1138 * = 96 (0x60) 01100000
1139 * VEND[7:0] "Vertical Window End, 8 MSBs"
1140 * = 96 (0x60) 01100000
1141 */
1142 { 0x1a, 0x60 },
1143
1144 /*
1145 * 32 COMM "Common Control M"
1146 * = 18 (0x12) 00010010
1147 * COMM[7:6] "Pixel clock divide option"
1148 * = 0 (0x00) 00...... "/1"
1149 * COMM[5:3] "Horizontal window end position, 3 LSBs"
1150 * = 2 (0x02) ..010...
1151 * COMM[2:0] "Horizontal window start position, 3 LSBs"
1152 * = 2 (0x02) .....010
1153 */
1154 { 0x32, 0x12 },
1155
1156 /*
1157 * 03 COMA "Common Control A"
1158 * = 74 (0x4A) 01001010
1159 * COMA[7:4] "AWB Update Threshold"
1160 * = 4 (0x04) 0100....
1161 * COMA[3:2] "Vertical window end line control 2 LSBs"
1162 * = 2 (0x02) ....10..
1163 * COMA[1:0] "Vertical window start line control 2 LSBs"
1164 * = 2 (0x02) ......10
1165 */
1166 { 0x03, 0x4A },
1167
1168 /*
1169 * 11 CLKRC "Clock Rate Control"
1170 * = 128 (0x80) 10000000
1171 * CLKRC[7] "Internal frequency doublers on off seclection"
1172 * = 1 (0x01) 1....... "On"
1173 * CLKRC[6] "Digital video master slave selection"
1174 * = 0 (0x00) .0...... "Master mode, sensor
1175 * provides PCLK"
1176 * CLKRC[5:0] "Clock divider { CLK = PCLK/(1+CLKRC[5:0]) }"
1177 * = 0 (0x00) ..000000
1178 */
1179 { 0x11, 0x80 },
1180
1181 /*
1182 * 12 COMH "Common Control H"
1183 * = 0 (0x00) 00000000
1184 * COMH[7] "SRST"
1185 * = 0 (0x00) 0....... "No-op"
1186 * COMH[6:4] "Resolution selection"
1187 * = 0 (0x00) .000.... "QXGA"
1188 * COMH[3] "Master slave selection"
1189 * = 0 (0x00) ....0... "Master mode"
1190 * COMH[2] "Internal B/R channel option"
1191 * = 0 (0x00) .....0.. "B/R use same channel"
1192 * COMH[1] "Color bar test pattern"
1193 * = 0 (0x00) ......0. "Off"
1194 * COMH[0] "Reserved"
1195 * = 0 (0x00) .......0
1196 */
1197 { 0x12, 0x00 },
1198
1199 /*
1200 * 12 COMH "Common Control H"
1201 * = 64 (0x40) 01000000
1202 * COMH[7] "SRST"
1203 * = 0 (0x00) 0....... "No-op"
1204 * COMH[6:4] "Resolution selection"
1205 * = 4 (0x04) .100.... "XGA"
1206 * COMH[3] "Master slave selection"
1207 * = 0 (0x00) ....0... "Master mode"
1208 * COMH[2] "Internal B/R channel option"
1209 * = 0 (0x00) .....0.. "B/R use same channel"
1210 * COMH[1] "Color bar test pattern"
1211 * = 0 (0x00) ......0. "Off"
1212 * COMH[0] "Reserved"
1213 * = 0 (0x00) .......0
1214 */
1215 { 0x12, 0x40 },
1216
1217 /*
1218 * 17 HREFST "Horizontal window start"
1219 * = 31 (0x1F) 00011111
1220 * HREFST[7:0] "Horizontal window start, 8 MSBs"
1221 * = 31 (0x1F) 00011111
1222 */
1223 { 0x17, 0x1F },
1224
1225 /*
1226 * 18 HREFEND "Horizontal window end"
1227 * = 95 (0x5F) 01011111
1228 * HREFEND[7:0] "Horizontal Window End, 8 MSBs"
1229 * = 95 (0x5F) 01011111
1230 */
1231 { 0x18, 0x5F },
1232
1233 /*
1234 * 19 VSTRT "Vertical window start"
1235 * = 0 (0x00) 00000000
1236 * VSTRT[7:0] "Vertical Window Start, 8 MSBs"
1237 * = 0 (0x00) 00000000
1238 */
1239 { 0x19, 0x00 },
1240
1241 /*
1242 * 1A VEND "Vertical window end"
1243 * = 96 (0x60) 01100000
1244 * VEND[7:0] "Vertical Window End, 8 MSBs"
1245 * = 96 (0x60) 01100000
1246 */
1247 { 0x1a, 0x60 },
1248
1249 /*
1250 * 32 COMM "Common Control M"
1251 * = 18 (0x12) 00010010
1252 * COMM[7:6] "Pixel clock divide option"
1253 * = 0 (0x00) 00...... "/1"
1254 * COMM[5:3] "Horizontal window end position, 3 LSBs"
1255 * = 2 (0x02) ..010...
1256 * COMM[2:0] "Horizontal window start position, 3 LSBs"
1257 * = 2 (0x02) .....010
1258 */
1259 { 0x32, 0x12 },
1260
1261 /*
1262 * 03 COMA "Common Control A"
1263 * = 74 (0x4A) 01001010
1264 * COMA[7:4] "AWB Update Threshold"
1265 * = 4 (0x04) 0100....
1266 * COMA[3:2] "Vertical window end line control 2 LSBs"
1267 * = 2 (0x02) ....10..
1268 * COMA[1:0] "Vertical window start line control 2 LSBs"
1269 * = 2 (0x02) ......10
1270 */
1271 { 0x03, 0x4A },
1272
1273 /*
1274 * 02 RED "Red Gain Control"
1275 * = 175 (0xAF) 10101111
1276 * RED[7] "Action"
1277 * = 1 (0x01) 1....... "gain = 1/(1+bitrev([6:0]))"
1278 * RED[6:0] "Value"
1279 * = 47 (0x2F) .0101111
1280 */
1281 { 0x02, 0xAF },
1282
1283 /*
1284 * 2D ADDVSL "VSYNC Pulse Width"
1285 * = 210 (0xD2) 11010010
1286 * ADDVSL[7:0] "VSYNC pulse width, LSB"
1287 * = 210 (0xD2) 11010010
1288 */
1289 { 0x2d, 0xD2 },
1290
1291 /*
1292 * 00 GAIN = 24 (0x18) 00011000
1293 * GAIN[7:6] "Reserved"
1294 * = 0 (0x00) 00......
1295 * GAIN[5] "Double"
1296 * = 0 (0x00) ..0..... "False"
1297 * GAIN[4] "Double"
1298 * = 1 (0x01) ...1.... "True"
1299 * GAIN[3:0] "Range"
1300 * = 8 (0x08) ....1000
1301 */
1302 { 0x00, 0x18 },
1303
1304 /*
1305 * 01 BLUE "Blue Gain Control"
1306 * = 240 (0xF0) 11110000
1307 * BLUE[7] "Action"
1308 * = 1 (0x01) 1....... "gain = 1/(1+bitrev([6:0]))"
1309 * BLUE[6:0] "Value"
1310 * = 112 (0x70) .1110000
1311 */
1312 { 0x01, 0xF0 },
1313
1314 /*
1315 * 10 AEC "Automatic Exposure Control"
1316 * = 10 (0x0A) 00001010
1317 * AEC[7:0] "Automatic Exposure Control, 8 MSBs"
1318 * = 10 (0x0A) 00001010
1319 */
1320 { 0x10, 0x0A },
1321
1322 { 0xE1, 0x67 },
1323 { 0xE3, 0x03 },
1324 { 0xE4, 0x26 },
1325 { 0xE5, 0x3E },
1326 { 0xF8, 0x01 },
1327 { 0xFF, 0x01 },
1328};
1329
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001330static const struct ov_i2c_regvals norm_6x20[] = {
1331 { 0x12, 0x80 }, /* reset */
1332 { 0x11, 0x01 },
1333 { 0x03, 0x60 },
1334 { 0x05, 0x7f }, /* For when autoadjust is off */
1335 { 0x07, 0xa8 },
1336 /* The ratio of 0x0c and 0x0d controls the white point */
1337 { 0x0c, 0x24 },
1338 { 0x0d, 0x24 },
1339 { 0x0f, 0x15 }, /* COMS */
1340 { 0x10, 0x75 }, /* AEC Exposure time */
1341 { 0x12, 0x24 }, /* Enable AGC */
1342 { 0x14, 0x04 },
1343 /* 0x16: 0x06 helps frame stability with moving objects */
1344 { 0x16, 0x06 },
1345/* { 0x20, 0x30 }, * Aperture correction enable */
1346 { 0x26, 0xb2 }, /* BLC enable */
1347 /* 0x28: 0x05 Selects RGB format if RGB on */
1348 { 0x28, 0x05 },
1349 { 0x2a, 0x04 }, /* Disable framerate adjust */
1350/* { 0x2b, 0xac }, * Framerate; Set 2a[7] first */
Hans de Goedeae49c402009-06-14 19:15:07 -03001351 { 0x2d, 0x85 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001352 { 0x33, 0xa0 }, /* Color Processing Parameter */
1353 { 0x34, 0xd2 }, /* Max A/D range */
1354 { 0x38, 0x8b },
1355 { 0x39, 0x40 },
1356
1357 { 0x3c, 0x39 }, /* Enable AEC mode changing */
1358 { 0x3c, 0x3c }, /* Change AEC mode */
1359 { 0x3c, 0x24 }, /* Disable AEC mode changing */
1360
1361 { 0x3d, 0x80 },
1362 /* These next two registers (0x4a, 0x4b) are undocumented.
1363 * They control the color balance */
1364 { 0x4a, 0x80 },
1365 { 0x4b, 0x80 },
1366 { 0x4d, 0xd2 }, /* This reduces noise a bit */
1367 { 0x4e, 0xc1 },
1368 { 0x4f, 0x04 },
1369/* Do 50-53 have any effect? */
1370/* Toggle 0x12[2] off and on here? */
1371};
1372
1373static const struct ov_i2c_regvals norm_6x30[] = {
1374 { 0x12, 0x80 }, /* Reset */
1375 { 0x00, 0x1f }, /* Gain */
1376 { 0x01, 0x99 }, /* Blue gain */
1377 { 0x02, 0x7c }, /* Red gain */
1378 { 0x03, 0xc0 }, /* Saturation */
1379 { 0x05, 0x0a }, /* Contrast */
1380 { 0x06, 0x95 }, /* Brightness */
1381 { 0x07, 0x2d }, /* Sharpness */
1382 { 0x0c, 0x20 },
1383 { 0x0d, 0x20 },
Hans de Goede02ab18b2009-06-14 04:32:04 -03001384 { 0x0e, 0xa0 }, /* Was 0x20, bit7 enables a 2x gain which we need */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001385 { 0x0f, 0x05 },
1386 { 0x10, 0x9a },
1387 { 0x11, 0x00 }, /* Pixel clock = fastest */
1388 { 0x12, 0x24 }, /* Enable AGC and AWB */
1389 { 0x13, 0x21 },
1390 { 0x14, 0x80 },
1391 { 0x15, 0x01 },
1392 { 0x16, 0x03 },
1393 { 0x17, 0x38 },
1394 { 0x18, 0xea },
1395 { 0x19, 0x04 },
1396 { 0x1a, 0x93 },
1397 { 0x1b, 0x00 },
1398 { 0x1e, 0xc4 },
1399 { 0x1f, 0x04 },
1400 { 0x20, 0x20 },
1401 { 0x21, 0x10 },
1402 { 0x22, 0x88 },
1403 { 0x23, 0xc0 }, /* Crystal circuit power level */
1404 { 0x25, 0x9a }, /* Increase AEC black ratio */
1405 { 0x26, 0xb2 }, /* BLC enable */
1406 { 0x27, 0xa2 },
1407 { 0x28, 0x00 },
1408 { 0x29, 0x00 },
1409 { 0x2a, 0x84 }, /* 60 Hz power */
1410 { 0x2b, 0xa8 }, /* 60 Hz power */
1411 { 0x2c, 0xa0 },
1412 { 0x2d, 0x95 }, /* Enable auto-brightness */
1413 { 0x2e, 0x88 },
1414 { 0x33, 0x26 },
1415 { 0x34, 0x03 },
1416 { 0x36, 0x8f },
1417 { 0x37, 0x80 },
1418 { 0x38, 0x83 },
1419 { 0x39, 0x80 },
1420 { 0x3a, 0x0f },
1421 { 0x3b, 0x3c },
1422 { 0x3c, 0x1a },
1423 { 0x3d, 0x80 },
1424 { 0x3e, 0x80 },
1425 { 0x3f, 0x0e },
1426 { 0x40, 0x00 }, /* White bal */
1427 { 0x41, 0x00 }, /* White bal */
1428 { 0x42, 0x80 },
1429 { 0x43, 0x3f }, /* White bal */
1430 { 0x44, 0x80 },
1431 { 0x45, 0x20 },
1432 { 0x46, 0x20 },
1433 { 0x47, 0x80 },
1434 { 0x48, 0x7f },
1435 { 0x49, 0x00 },
1436 { 0x4a, 0x00 },
1437 { 0x4b, 0x80 },
1438 { 0x4c, 0xd0 },
1439 { 0x4d, 0x10 }, /* U = 0.563u, V = 0.714v */
1440 { 0x4e, 0x40 },
1441 { 0x4f, 0x07 }, /* UV avg., col. killer: max */
1442 { 0x50, 0xff },
1443 { 0x54, 0x23 }, /* Max AGC gain: 18dB */
1444 { 0x55, 0xff },
1445 { 0x56, 0x12 },
1446 { 0x57, 0x81 },
1447 { 0x58, 0x75 },
1448 { 0x59, 0x01 }, /* AGC dark current comp.: +1 */
1449 { 0x5a, 0x2c },
1450 { 0x5b, 0x0f }, /* AWB chrominance levels */
1451 { 0x5c, 0x10 },
1452 { 0x3d, 0x80 },
1453 { 0x27, 0xa6 },
1454 { 0x12, 0x20 }, /* Toggle AWB */
1455 { 0x12, 0x24 },
1456};
1457
1458/* Lawrence Glaister <lg@jfm.bc.ca> reports:
1459 *
1460 * Register 0x0f in the 7610 has the following effects:
1461 *
1462 * 0x85 (AEC method 1): Best overall, good contrast range
1463 * 0x45 (AEC method 2): Very overexposed
1464 * 0xa5 (spec sheet default): Ok, but the black level is
1465 * shifted resulting in loss of contrast
1466 * 0x05 (old driver setting): very overexposed, too much
1467 * contrast
1468 */
1469static const struct ov_i2c_regvals norm_7610[] = {
1470 { 0x10, 0xff },
1471 { 0x16, 0x06 },
1472 { 0x28, 0x24 },
1473 { 0x2b, 0xac },
1474 { 0x12, 0x00 },
1475 { 0x38, 0x81 },
1476 { 0x28, 0x24 }, /* 0c */
1477 { 0x0f, 0x85 }, /* lg's setting */
1478 { 0x15, 0x01 },
1479 { 0x20, 0x1c },
1480 { 0x23, 0x2a },
1481 { 0x24, 0x10 },
1482 { 0x25, 0x8a },
1483 { 0x26, 0xa2 },
1484 { 0x27, 0xc2 },
1485 { 0x2a, 0x04 },
1486 { 0x2c, 0xfe },
1487 { 0x2d, 0x93 },
1488 { 0x30, 0x71 },
1489 { 0x31, 0x60 },
1490 { 0x32, 0x26 },
1491 { 0x33, 0x20 },
1492 { 0x34, 0x48 },
1493 { 0x12, 0x24 },
1494 { 0x11, 0x01 },
1495 { 0x0c, 0x24 },
1496 { 0x0d, 0x24 },
1497};
1498
1499static const struct ov_i2c_regvals norm_7620[] = {
Hans de Goedea511ba92009-10-16 07:13:07 -03001500 { 0x12, 0x80 }, /* reset */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001501 { 0x00, 0x00 }, /* gain */
1502 { 0x01, 0x80 }, /* blue gain */
1503 { 0x02, 0x80 }, /* red gain */
1504 { 0x03, 0xc0 }, /* OV7670_REG_VREF */
1505 { 0x06, 0x60 },
1506 { 0x07, 0x00 },
1507 { 0x0c, 0x24 },
1508 { 0x0c, 0x24 },
1509 { 0x0d, 0x24 },
1510 { 0x11, 0x01 },
1511 { 0x12, 0x24 },
1512 { 0x13, 0x01 },
1513 { 0x14, 0x84 },
1514 { 0x15, 0x01 },
1515 { 0x16, 0x03 },
1516 { 0x17, 0x2f },
1517 { 0x18, 0xcf },
1518 { 0x19, 0x06 },
1519 { 0x1a, 0xf5 },
1520 { 0x1b, 0x00 },
1521 { 0x20, 0x18 },
1522 { 0x21, 0x80 },
1523 { 0x22, 0x80 },
1524 { 0x23, 0x00 },
1525 { 0x26, 0xa2 },
1526 { 0x27, 0xea },
Hans de Goedeb282d872009-06-14 19:10:40 -03001527 { 0x28, 0x22 }, /* Was 0x20, bit1 enables a 2x gain which we need */
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001528 { 0x29, 0x00 },
1529 { 0x2a, 0x10 },
1530 { 0x2b, 0x00 },
1531 { 0x2c, 0x88 },
1532 { 0x2d, 0x91 },
1533 { 0x2e, 0x80 },
1534 { 0x2f, 0x44 },
1535 { 0x60, 0x27 },
1536 { 0x61, 0x02 },
1537 { 0x62, 0x5f },
1538 { 0x63, 0xd5 },
1539 { 0x64, 0x57 },
1540 { 0x65, 0x83 },
1541 { 0x66, 0x55 },
1542 { 0x67, 0x92 },
1543 { 0x68, 0xcf },
1544 { 0x69, 0x76 },
1545 { 0x6a, 0x22 },
1546 { 0x6b, 0x00 },
1547 { 0x6c, 0x02 },
1548 { 0x6d, 0x44 },
1549 { 0x6e, 0x80 },
1550 { 0x6f, 0x1d },
1551 { 0x70, 0x8b },
1552 { 0x71, 0x00 },
1553 { 0x72, 0x14 },
1554 { 0x73, 0x54 },
1555 { 0x74, 0x00 },
1556 { 0x75, 0x8e },
1557 { 0x76, 0x00 },
1558 { 0x77, 0xff },
1559 { 0x78, 0x80 },
1560 { 0x79, 0x80 },
1561 { 0x7a, 0x80 },
1562 { 0x7b, 0xe2 },
1563 { 0x7c, 0x00 },
1564};
1565
1566/* 7640 and 7648. The defaults should be OK for most registers. */
1567static const struct ov_i2c_regvals norm_7640[] = {
1568 { 0x12, 0x80 },
1569 { 0x12, 0x14 },
1570};
1571
1572/* 7670. Defaults taken from OmniVision provided data,
1573* as provided by Jonathan Corbet of OLPC */
1574static const struct ov_i2c_regvals norm_7670[] = {
1575 { OV7670_REG_COM7, OV7670_COM7_RESET },
1576 { OV7670_REG_TSLB, 0x04 }, /* OV */
1577 { OV7670_REG_COM7, OV7670_COM7_FMT_VGA }, /* VGA */
1578 { OV7670_REG_CLKRC, 0x01 },
1579/*
1580 * Set the hardware window. These values from OV don't entirely
1581 * make sense - hstop is less than hstart. But they work...
1582 */
1583 { OV7670_REG_HSTART, 0x13 },
1584 { OV7670_REG_HSTOP, 0x01 },
1585 { OV7670_REG_HREF, 0xb6 },
1586 { OV7670_REG_VSTART, 0x02 },
1587 { OV7670_REG_VSTOP, 0x7a },
1588 { OV7670_REG_VREF, 0x0a },
1589
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001590 { OV7670_REG_COM3, 0x00 },
1591 { OV7670_REG_COM14, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001592/* Mystery scaling numbers */
1593 { 0x70, 0x3a },
1594 { 0x71, 0x35 },
1595 { 0x72, 0x11 },
1596 { 0x73, 0xf0 },
1597 { 0xa2, 0x02 },
1598/* { OV7670_REG_COM10, 0x0 }, */
1599
1600/* Gamma curve values */
1601 { 0x7a, 0x20 },
1602 { 0x7b, 0x10 },
1603 { 0x7c, 0x1e },
1604 { 0x7d, 0x35 },
1605 { 0x7e, 0x5a },
1606 { 0x7f, 0x69 },
1607 { 0x80, 0x76 },
1608 { 0x81, 0x80 },
1609 { 0x82, 0x88 },
1610 { 0x83, 0x8f },
1611 { 0x84, 0x96 },
1612 { 0x85, 0xa3 },
1613 { 0x86, 0xaf },
1614 { 0x87, 0xc4 },
1615 { 0x88, 0xd7 },
1616 { 0x89, 0xe8 },
1617
1618/* AGC and AEC parameters. Note we start by disabling those features,
1619 then turn them only after tweaking the values. */
1620 { OV7670_REG_COM8, OV7670_COM8_FASTAEC
1621 | OV7670_COM8_AECSTEP
1622 | OV7670_COM8_BFILT },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001623 { OV7670_REG_GAIN, 0x00 },
1624 { OV7670_REG_AECH, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001625 { OV7670_REG_COM4, 0x40 }, /* magic reserved bit */
1626 { OV7670_REG_COM9, 0x18 }, /* 4x gain + magic rsvd bit */
1627 { OV7670_REG_BD50MAX, 0x05 },
1628 { OV7670_REG_BD60MAX, 0x07 },
1629 { OV7670_REG_AEW, 0x95 },
1630 { OV7670_REG_AEB, 0x33 },
1631 { OV7670_REG_VPT, 0xe3 },
1632 { OV7670_REG_HAECC1, 0x78 },
1633 { OV7670_REG_HAECC2, 0x68 },
1634 { 0xa1, 0x03 }, /* magic */
1635 { OV7670_REG_HAECC3, 0xd8 },
1636 { OV7670_REG_HAECC4, 0xd8 },
1637 { OV7670_REG_HAECC5, 0xf0 },
1638 { OV7670_REG_HAECC6, 0x90 },
1639 { OV7670_REG_HAECC7, 0x94 },
1640 { OV7670_REG_COM8, OV7670_COM8_FASTAEC
1641 | OV7670_COM8_AECSTEP
1642 | OV7670_COM8_BFILT
1643 | OV7670_COM8_AGC
1644 | OV7670_COM8_AEC },
1645
1646/* Almost all of these are magic "reserved" values. */
1647 { OV7670_REG_COM5, 0x61 },
1648 { OV7670_REG_COM6, 0x4b },
1649 { 0x16, 0x02 },
1650 { OV7670_REG_MVFP, 0x07 },
1651 { 0x21, 0x02 },
1652 { 0x22, 0x91 },
1653 { 0x29, 0x07 },
1654 { 0x33, 0x0b },
1655 { 0x35, 0x0b },
1656 { 0x37, 0x1d },
1657 { 0x38, 0x71 },
1658 { 0x39, 0x2a },
1659 { OV7670_REG_COM12, 0x78 },
1660 { 0x4d, 0x40 },
1661 { 0x4e, 0x20 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001662 { OV7670_REG_GFIX, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001663 { 0x6b, 0x4a },
1664 { 0x74, 0x10 },
1665 { 0x8d, 0x4f },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001666 { 0x8e, 0x00 },
1667 { 0x8f, 0x00 },
1668 { 0x90, 0x00 },
1669 { 0x91, 0x00 },
1670 { 0x96, 0x00 },
1671 { 0x9a, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001672 { 0xb0, 0x84 },
1673 { 0xb1, 0x0c },
1674 { 0xb2, 0x0e },
1675 { 0xb3, 0x82 },
1676 { 0xb8, 0x0a },
1677
1678/* More reserved magic, some of which tweaks white balance */
1679 { 0x43, 0x0a },
1680 { 0x44, 0xf0 },
1681 { 0x45, 0x34 },
1682 { 0x46, 0x58 },
1683 { 0x47, 0x28 },
1684 { 0x48, 0x3a },
1685 { 0x59, 0x88 },
1686 { 0x5a, 0x88 },
1687 { 0x5b, 0x44 },
1688 { 0x5c, 0x67 },
1689 { 0x5d, 0x49 },
1690 { 0x5e, 0x0e },
1691 { 0x6c, 0x0a },
1692 { 0x6d, 0x55 },
1693 { 0x6e, 0x11 },
1694 { 0x6f, 0x9f },
1695 /* "9e for advance AWB" */
1696 { 0x6a, 0x40 },
1697 { OV7670_REG_BLUE, 0x40 },
1698 { OV7670_REG_RED, 0x60 },
1699 { OV7670_REG_COM8, OV7670_COM8_FASTAEC
1700 | OV7670_COM8_AECSTEP
1701 | OV7670_COM8_BFILT
1702 | OV7670_COM8_AGC
1703 | OV7670_COM8_AEC
1704 | OV7670_COM8_AWB },
1705
1706/* Matrix coefficients */
1707 { 0x4f, 0x80 },
1708 { 0x50, 0x80 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001709 { 0x51, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001710 { 0x52, 0x22 },
1711 { 0x53, 0x5e },
1712 { 0x54, 0x80 },
1713 { 0x58, 0x9e },
1714
1715 { OV7670_REG_COM16, OV7670_COM16_AWBGAIN },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001716 { OV7670_REG_EDGE, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001717 { 0x75, 0x05 },
1718 { 0x76, 0xe1 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001719 { 0x4c, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001720 { 0x77, 0x01 },
1721 { OV7670_REG_COM13, OV7670_COM13_GAMMA
1722 | OV7670_COM13_UVSAT
1723 | 2}, /* was 3 */
1724 { 0x4b, 0x09 },
1725 { 0xc9, 0x60 },
1726 { OV7670_REG_COM16, 0x38 },
1727 { 0x56, 0x40 },
1728
1729 { 0x34, 0x11 },
1730 { OV7670_REG_COM11, OV7670_COM11_EXP|OV7670_COM11_HZAUTO },
1731 { 0xa4, 0x88 },
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03001732 { 0x96, 0x00 },
Jean-Francois Moine4202f712008-09-03 17:12:15 -03001733 { 0x97, 0x30 },
1734 { 0x98, 0x20 },
1735 { 0x99, 0x30 },
1736 { 0x9a, 0x84 },
1737 { 0x9b, 0x29 },
1738 { 0x9c, 0x03 },
1739 { 0x9d, 0x4c },
1740 { 0x9e, 0x3f },
1741 { 0x78, 0x04 },
1742
1743/* Extra-weird stuff. Some sort of multiplexor register */
1744 { 0x79, 0x01 },
1745 { 0xc8, 0xf0 },
1746 { 0x79, 0x0f },
1747 { 0xc8, 0x00 },
1748 { 0x79, 0x10 },
1749 { 0xc8, 0x7e },
1750 { 0x79, 0x0a },
1751 { 0xc8, 0x80 },
1752 { 0x79, 0x0b },
1753 { 0xc8, 0x01 },
1754 { 0x79, 0x0c },
1755 { 0xc8, 0x0f },
1756 { 0x79, 0x0d },
1757 { 0xc8, 0x20 },
1758 { 0x79, 0x09 },
1759 { 0xc8, 0x80 },
1760 { 0x79, 0x02 },
1761 { 0xc8, 0xc0 },
1762 { 0x79, 0x03 },
1763 { 0xc8, 0x40 },
1764 { 0x79, 0x05 },
1765 { 0xc8, 0x30 },
1766 { 0x79, 0x26 },
1767};
1768
1769static const struct ov_i2c_regvals norm_8610[] = {
1770 { 0x12, 0x80 },
1771 { 0x00, 0x00 },
1772 { 0x01, 0x80 },
1773 { 0x02, 0x80 },
1774 { 0x03, 0xc0 },
1775 { 0x04, 0x30 },
1776 { 0x05, 0x30 }, /* was 0x10, new from windrv 090403 */
1777 { 0x06, 0x70 }, /* was 0x80, new from windrv 090403 */
1778 { 0x0a, 0x86 },
1779 { 0x0b, 0xb0 },
1780 { 0x0c, 0x20 },
1781 { 0x0d, 0x20 },
1782 { 0x11, 0x01 },
1783 { 0x12, 0x25 },
1784 { 0x13, 0x01 },
1785 { 0x14, 0x04 },
1786 { 0x15, 0x01 }, /* Lin and Win think different about UV order */
1787 { 0x16, 0x03 },
1788 { 0x17, 0x38 }, /* was 0x2f, new from windrv 090403 */
1789 { 0x18, 0xea }, /* was 0xcf, new from windrv 090403 */
1790 { 0x19, 0x02 }, /* was 0x06, new from windrv 090403 */
1791 { 0x1a, 0xf5 },
1792 { 0x1b, 0x00 },
1793 { 0x20, 0xd0 }, /* was 0x90, new from windrv 090403 */
1794 { 0x23, 0xc0 }, /* was 0x00, new from windrv 090403 */
1795 { 0x24, 0x30 }, /* was 0x1d, new from windrv 090403 */
1796 { 0x25, 0x50 }, /* was 0x57, new from windrv 090403 */
1797 { 0x26, 0xa2 },
1798 { 0x27, 0xea },
1799 { 0x28, 0x00 },
1800 { 0x29, 0x00 },
1801 { 0x2a, 0x80 },
1802 { 0x2b, 0xc8 }, /* was 0xcc, new from windrv 090403 */
1803 { 0x2c, 0xac },
1804 { 0x2d, 0x45 }, /* was 0xd5, new from windrv 090403 */
1805 { 0x2e, 0x80 },
1806 { 0x2f, 0x14 }, /* was 0x01, new from windrv 090403 */
1807 { 0x4c, 0x00 },
1808 { 0x4d, 0x30 }, /* was 0x10, new from windrv 090403 */
1809 { 0x60, 0x02 }, /* was 0x01, new from windrv 090403 */
1810 { 0x61, 0x00 }, /* was 0x09, new from windrv 090403 */
1811 { 0x62, 0x5f }, /* was 0xd7, new from windrv 090403 */
1812 { 0x63, 0xff },
1813 { 0x64, 0x53 }, /* new windrv 090403 says 0x57,
1814 * maybe thats wrong */
1815 { 0x65, 0x00 },
1816 { 0x66, 0x55 },
1817 { 0x67, 0xb0 },
1818 { 0x68, 0xc0 }, /* was 0xaf, new from windrv 090403 */
1819 { 0x69, 0x02 },
1820 { 0x6a, 0x22 },
1821 { 0x6b, 0x00 },
1822 { 0x6c, 0x99 }, /* was 0x80, old windrv says 0x00, but
1823 * deleting bit7 colors the first images red */
1824 { 0x6d, 0x11 }, /* was 0x00, new from windrv 090403 */
1825 { 0x6e, 0x11 }, /* was 0x00, new from windrv 090403 */
1826 { 0x6f, 0x01 },
1827 { 0x70, 0x8b },
1828 { 0x71, 0x00 },
1829 { 0x72, 0x14 },
1830 { 0x73, 0x54 },
1831 { 0x74, 0x00 },/* 0x60? - was 0x00, new from windrv 090403 */
1832 { 0x75, 0x0e },
1833 { 0x76, 0x02 }, /* was 0x02, new from windrv 090403 */
1834 { 0x77, 0xff },
1835 { 0x78, 0x80 },
1836 { 0x79, 0x80 },
1837 { 0x7a, 0x80 },
1838 { 0x7b, 0x10 }, /* was 0x13, new from windrv 090403 */
1839 { 0x7c, 0x00 },
1840 { 0x7d, 0x08 }, /* was 0x09, new from windrv 090403 */
1841 { 0x7e, 0x08 }, /* was 0xc0, new from windrv 090403 */
1842 { 0x7f, 0xfb },
1843 { 0x80, 0x28 },
1844 { 0x81, 0x00 },
1845 { 0x82, 0x23 },
1846 { 0x83, 0x0b },
1847 { 0x84, 0x00 },
1848 { 0x85, 0x62 }, /* was 0x61, new from windrv 090403 */
1849 { 0x86, 0xc9 },
1850 { 0x87, 0x00 },
1851 { 0x88, 0x00 },
1852 { 0x89, 0x01 },
1853 { 0x12, 0x20 },
1854 { 0x12, 0x25 }, /* was 0x24, new from windrv 090403 */
1855};
1856
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001857static unsigned char ov7670_abs_to_sm(unsigned char v)
1858{
1859 if (v > 127)
1860 return v & 0x7f;
1861 return (128 - v) | 0x80;
1862}
1863
1864/* Write a OV519 register */
Hans de Goedea511ba92009-10-16 07:13:07 -03001865static int reg_w(struct sd *sd, __u16 index, __u16 value)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001866{
Hans de Goedea511ba92009-10-16 07:13:07 -03001867 int ret, req = 0;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001868
1869 switch (sd->bridge) {
1870 case BRIDGE_OV511:
1871 case BRIDGE_OV511PLUS:
1872 req = 2;
1873 break;
1874 case BRIDGE_OVFX2:
Hans de Goedea511ba92009-10-16 07:13:07 -03001875 req = 0x0a;
1876 /* fall through */
1877 case BRIDGE_W9968CF:
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001878 ret = usb_control_msg(sd->gspca_dev.dev,
1879 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
Hans de Goedea511ba92009-10-16 07:13:07 -03001880 req,
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001881 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Hans de Goedea511ba92009-10-16 07:13:07 -03001882 value, index, NULL, 0, 500);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001883 goto leave;
1884 default:
1885 req = 1;
1886 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001887
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001888 sd->gspca_dev.usb_buf[0] = value;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001889 ret = usb_control_msg(sd->gspca_dev.dev,
1890 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
Hans de Goede49809d62009-06-07 12:10:39 -03001891 req,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001892 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1893 0, index,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001894 sd->gspca_dev.usb_buf, 1, 500);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001895leave:
Hans de Goedea511ba92009-10-16 07:13:07 -03001896 if (ret < 0) {
1897 PDEBUG(D_ERR, "Write reg 0x%04x -> [0x%02x] failed",
1898 value, index);
1899 return ret;
1900 }
1901
1902 PDEBUG(D_USBO, "Write reg 0x%04x -> [0x%02x]", value, index);
1903 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001904}
1905
Hans de Goedea511ba92009-10-16 07:13:07 -03001906/* Read from a OV519 register, note not valid for the w9968cf!! */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001907/* returns: negative is error, pos or zero is data */
1908static int reg_r(struct sd *sd, __u16 index)
1909{
1910 int ret;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03001911 int req;
1912
1913 switch (sd->bridge) {
1914 case BRIDGE_OV511:
1915 case BRIDGE_OV511PLUS:
1916 req = 3;
1917 break;
1918 case BRIDGE_OVFX2:
1919 req = 0x0b;
1920 break;
1921 default:
1922 req = 1;
1923 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001924
1925 ret = usb_control_msg(sd->gspca_dev.dev,
1926 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
Hans de Goede49809d62009-06-07 12:10:39 -03001927 req,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001928 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001929 0, index, sd->gspca_dev.usb_buf, 1, 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001930
Hans de Goedea511ba92009-10-16 07:13:07 -03001931 if (ret >= 0) {
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001932 ret = sd->gspca_dev.usb_buf[0];
Hans de Goedea511ba92009-10-16 07:13:07 -03001933 PDEBUG(D_USBI, "Read reg [0x%02X] -> 0x%04X", index, ret);
1934 } else
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001935 PDEBUG(D_ERR, "Read reg [0x%02x] failed", index);
Hans de Goedea511ba92009-10-16 07:13:07 -03001936
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001937 return ret;
1938}
1939
1940/* Read 8 values from a OV519 register */
1941static int reg_r8(struct sd *sd,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03001942 __u16 index)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001943{
1944 int ret;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001945
1946 ret = usb_control_msg(sd->gspca_dev.dev,
1947 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
1948 1, /* REQ_IO */
1949 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001950 0, index, sd->gspca_dev.usb_buf, 8, 500);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001951
1952 if (ret >= 0)
Jean-Francois Moine739570b2008-07-14 09:38:29 -03001953 ret = sd->gspca_dev.usb_buf[0];
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001954 else
1955 PDEBUG(D_ERR, "Read reg 8 [0x%02x] failed", index);
Hans de Goedea511ba92009-10-16 07:13:07 -03001956
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03001957 return ret;
1958}
1959
1960/*
1961 * Writes bits at positions specified by mask to an OV51x reg. Bits that are in
1962 * the same position as 1's in "mask" are cleared and set to "value". Bits
1963 * that are in the same position as 0's in "mask" are preserved, regardless
1964 * of their respective state in "value".
1965 */
1966static int reg_w_mask(struct sd *sd,
1967 __u16 index,
1968 __u8 value,
1969 __u8 mask)
1970{
1971 int ret;
1972 __u8 oldval;
1973
1974 if (mask != 0xff) {
1975 value &= mask; /* Enforce mask on value */
1976 ret = reg_r(sd, index);
1977 if (ret < 0)
1978 return ret;
1979
1980 oldval = ret & ~mask; /* Clear the masked bits */
1981 value |= oldval; /* Set the desired bits */
1982 }
1983 return reg_w(sd, index, value);
1984}
1985
1986/*
Hans de Goede49809d62009-06-07 12:10:39 -03001987 * Writes multiple (n) byte value to a single register. Only valid with certain
1988 * registers (0x30 and 0xc4 - 0xce).
1989 */
1990static int ov518_reg_w32(struct sd *sd, __u16 index, u32 value, int n)
1991{
1992 int ret;
1993
Jean-Francois Moine83955552009-12-12 06:58:01 -03001994 *((__le32 *) sd->gspca_dev.usb_buf) = __cpu_to_le32(value);
Hans de Goede49809d62009-06-07 12:10:39 -03001995
1996 ret = usb_control_msg(sd->gspca_dev.dev,
1997 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
1998 1 /* REG_IO */,
1999 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2000 0, index,
2001 sd->gspca_dev.usb_buf, n, 500);
Hans de Goedea511ba92009-10-16 07:13:07 -03002002 if (ret < 0) {
Hans de Goede49809d62009-06-07 12:10:39 -03002003 PDEBUG(D_ERR, "Write reg32 [%02x] %08x failed", index, value);
Hans de Goedea511ba92009-10-16 07:13:07 -03002004 return ret;
2005 }
2006
2007 return 0;
Hans de Goede49809d62009-06-07 12:10:39 -03002008}
2009
Hans de Goede1876bb92009-06-14 06:45:50 -03002010static int ov511_i2c_w(struct sd *sd, __u8 reg, __u8 value)
2011{
2012 int rc, retries;
2013
2014 PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
2015
2016 /* Three byte write cycle */
2017 for (retries = 6; ; ) {
2018 /* Select camera register */
2019 rc = reg_w(sd, R51x_I2C_SADDR_3, reg);
2020 if (rc < 0)
2021 return rc;
2022
2023 /* Write "value" to I2C data port of OV511 */
2024 rc = reg_w(sd, R51x_I2C_DATA, value);
2025 if (rc < 0)
2026 return rc;
2027
2028 /* Initiate 3-byte write cycle */
2029 rc = reg_w(sd, R511_I2C_CTL, 0x01);
2030 if (rc < 0)
2031 return rc;
2032
Jean-Francois Moine83955552009-12-12 06:58:01 -03002033 do {
Hans de Goede1876bb92009-06-14 06:45:50 -03002034 rc = reg_r(sd, R511_I2C_CTL);
Jean-Francois Moine83955552009-12-12 06:58:01 -03002035 } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
Hans de Goede1876bb92009-06-14 06:45:50 -03002036
2037 if (rc < 0)
2038 return rc;
2039
2040 if ((rc & 2) == 0) /* Ack? */
2041 break;
2042 if (--retries < 0) {
2043 PDEBUG(D_USBO, "i2c write retries exhausted");
2044 return -1;
2045 }
2046 }
2047
2048 return 0;
2049}
2050
2051static int ov511_i2c_r(struct sd *sd, __u8 reg)
2052{
2053 int rc, value, retries;
2054
2055 /* Two byte write cycle */
2056 for (retries = 6; ; ) {
2057 /* Select camera register */
2058 rc = reg_w(sd, R51x_I2C_SADDR_2, reg);
2059 if (rc < 0)
2060 return rc;
2061
2062 /* Initiate 2-byte write cycle */
2063 rc = reg_w(sd, R511_I2C_CTL, 0x03);
2064 if (rc < 0)
2065 return rc;
2066
Jean-Francois Moine83955552009-12-12 06:58:01 -03002067 do {
Hans de Goede1876bb92009-06-14 06:45:50 -03002068 rc = reg_r(sd, R511_I2C_CTL);
Jean-Francois Moine83955552009-12-12 06:58:01 -03002069 } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
Hans de Goede1876bb92009-06-14 06:45:50 -03002070
2071 if (rc < 0)
2072 return rc;
2073
2074 if ((rc & 2) == 0) /* Ack? */
2075 break;
2076
2077 /* I2C abort */
2078 reg_w(sd, R511_I2C_CTL, 0x10);
2079
2080 if (--retries < 0) {
2081 PDEBUG(D_USBI, "i2c write retries exhausted");
2082 return -1;
2083 }
2084 }
2085
2086 /* Two byte read cycle */
2087 for (retries = 6; ; ) {
2088 /* Initiate 2-byte read cycle */
2089 rc = reg_w(sd, R511_I2C_CTL, 0x05);
2090 if (rc < 0)
2091 return rc;
2092
Jean-Francois Moine83955552009-12-12 06:58:01 -03002093 do {
Hans de Goede1876bb92009-06-14 06:45:50 -03002094 rc = reg_r(sd, R511_I2C_CTL);
Jean-Francois Moine83955552009-12-12 06:58:01 -03002095 } while (rc > 0 && ((rc & 1) == 0)); /* Retry until idle */
Hans de Goede1876bb92009-06-14 06:45:50 -03002096
2097 if (rc < 0)
2098 return rc;
2099
2100 if ((rc & 2) == 0) /* Ack? */
2101 break;
2102
2103 /* I2C abort */
2104 rc = reg_w(sd, R511_I2C_CTL, 0x10);
2105 if (rc < 0)
2106 return rc;
2107
2108 if (--retries < 0) {
2109 PDEBUG(D_USBI, "i2c read retries exhausted");
2110 return -1;
2111 }
2112 }
2113
2114 value = reg_r(sd, R51x_I2C_DATA);
2115
2116 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value);
2117
2118 /* This is needed to make i2c_w() work */
2119 rc = reg_w(sd, R511_I2C_CTL, 0x05);
2120 if (rc < 0)
2121 return rc;
2122
2123 return value;
2124}
Hans de Goede49809d62009-06-07 12:10:39 -03002125
2126/*
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002127 * The OV518 I2C I/O procedure is different, hence, this function.
2128 * This is normally only called from i2c_w(). Note that this function
2129 * always succeeds regardless of whether the sensor is present and working.
2130 */
Hans de Goede1876bb92009-06-14 06:45:50 -03002131static int ov518_i2c_w(struct sd *sd,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002132 __u8 reg,
2133 __u8 value)
2134{
2135 int rc;
2136
2137 PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
2138
2139 /* Select camera register */
2140 rc = reg_w(sd, R51x_I2C_SADDR_3, reg);
2141 if (rc < 0)
2142 return rc;
2143
2144 /* Write "value" to I2C data port of OV511 */
2145 rc = reg_w(sd, R51x_I2C_DATA, value);
2146 if (rc < 0)
2147 return rc;
2148
2149 /* Initiate 3-byte write cycle */
2150 rc = reg_w(sd, R518_I2C_CTL, 0x01);
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002151 if (rc < 0)
2152 return rc;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002153
2154 /* wait for write complete */
2155 msleep(4);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002156 return reg_r8(sd, R518_I2C_CTL);
2157}
2158
2159/*
2160 * returns: negative is error, pos or zero is data
2161 *
2162 * The OV518 I2C I/O procedure is different, hence, this function.
2163 * This is normally only called from i2c_r(). Note that this function
2164 * always succeeds regardless of whether the sensor is present and working.
2165 */
Hans de Goede1876bb92009-06-14 06:45:50 -03002166static int ov518_i2c_r(struct sd *sd, __u8 reg)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002167{
2168 int rc, value;
2169
2170 /* Select camera register */
2171 rc = reg_w(sd, R51x_I2C_SADDR_2, reg);
2172 if (rc < 0)
2173 return rc;
2174
2175 /* Initiate 2-byte write cycle */
2176 rc = reg_w(sd, R518_I2C_CTL, 0x03);
2177 if (rc < 0)
2178 return rc;
2179
2180 /* Initiate 2-byte read cycle */
2181 rc = reg_w(sd, R518_I2C_CTL, 0x05);
2182 if (rc < 0)
2183 return rc;
2184 value = reg_r(sd, R51x_I2C_DATA);
2185 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, value);
2186 return value;
2187}
2188
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002189static int ovfx2_i2c_w(struct sd *sd, __u8 reg, __u8 value)
2190{
2191 int ret;
2192
2193 ret = usb_control_msg(sd->gspca_dev.dev,
2194 usb_sndctrlpipe(sd->gspca_dev.dev, 0),
2195 0x02,
2196 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2197 (__u16)value, (__u16)reg, NULL, 0, 500);
2198
Hans de Goedea511ba92009-10-16 07:13:07 -03002199 if (ret < 0) {
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002200 PDEBUG(D_ERR, "i2c 0x%02x -> [0x%02x] failed", value, reg);
Hans de Goedea511ba92009-10-16 07:13:07 -03002201 return ret;
2202 }
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002203
Hans de Goedea511ba92009-10-16 07:13:07 -03002204 PDEBUG(D_USBO, "i2c 0x%02x -> [0x%02x]", value, reg);
2205 return 0;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002206}
2207
2208static int ovfx2_i2c_r(struct sd *sd, __u8 reg)
2209{
2210 int ret;
2211
2212 ret = usb_control_msg(sd->gspca_dev.dev,
2213 usb_rcvctrlpipe(sd->gspca_dev.dev, 0),
2214 0x03,
2215 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
2216 0, (__u16)reg, sd->gspca_dev.usb_buf, 1, 500);
2217
2218 if (ret >= 0) {
2219 ret = sd->gspca_dev.usb_buf[0];
2220 PDEBUG(D_USBI, "i2c [0x%02X] -> 0x%02X", reg, ret);
2221 } else
2222 PDEBUG(D_ERR, "i2c read [0x%02x] failed", reg);
2223
2224 return ret;
2225}
2226
Hans de Goede1876bb92009-06-14 06:45:50 -03002227static int i2c_w(struct sd *sd, __u8 reg, __u8 value)
2228{
Hans de Goedefb1f9022009-10-16 07:42:53 -03002229 int ret = -1;
2230
2231 if (sd->sensor_reg_cache[reg] == value)
2232 return 0;
2233
Hans de Goede1876bb92009-06-14 06:45:50 -03002234 switch (sd->bridge) {
2235 case BRIDGE_OV511:
2236 case BRIDGE_OV511PLUS:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002237 ret = ov511_i2c_w(sd, reg, value);
2238 break;
Hans de Goede1876bb92009-06-14 06:45:50 -03002239 case BRIDGE_OV518:
2240 case BRIDGE_OV518PLUS:
2241 case BRIDGE_OV519:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002242 ret = ov518_i2c_w(sd, reg, value);
2243 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002244 case BRIDGE_OVFX2:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002245 ret = ovfx2_i2c_w(sd, reg, value);
2246 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03002247 case BRIDGE_W9968CF:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002248 ret = w9968cf_i2c_w(sd, reg, value);
2249 break;
Hans de Goede1876bb92009-06-14 06:45:50 -03002250 }
Hans de Goedefb1f9022009-10-16 07:42:53 -03002251
2252 if (ret >= 0) {
2253 /* Up on sensor reset empty the register cache */
2254 if (reg == 0x12 && (value & 0x80))
2255 memset(sd->sensor_reg_cache, -1,
2256 sizeof(sd->sensor_reg_cache));
2257 else
2258 sd->sensor_reg_cache[reg] = value;
2259 }
2260
2261 return ret;
Hans de Goede1876bb92009-06-14 06:45:50 -03002262}
2263
2264static int i2c_r(struct sd *sd, __u8 reg)
2265{
Hans de Goede8394bcf2009-10-16 11:26:22 -03002266 int ret = -1;
Hans de Goedefb1f9022009-10-16 07:42:53 -03002267
2268 if (sd->sensor_reg_cache[reg] != -1)
2269 return sd->sensor_reg_cache[reg];
2270
Hans de Goede1876bb92009-06-14 06:45:50 -03002271 switch (sd->bridge) {
2272 case BRIDGE_OV511:
2273 case BRIDGE_OV511PLUS:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002274 ret = ov511_i2c_r(sd, reg);
2275 break;
Hans de Goede1876bb92009-06-14 06:45:50 -03002276 case BRIDGE_OV518:
2277 case BRIDGE_OV518PLUS:
2278 case BRIDGE_OV519:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002279 ret = ov518_i2c_r(sd, reg);
2280 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002281 case BRIDGE_OVFX2:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002282 ret = ovfx2_i2c_r(sd, reg);
2283 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03002284 case BRIDGE_W9968CF:
Hans de Goedefb1f9022009-10-16 07:42:53 -03002285 ret = w9968cf_i2c_r(sd, reg);
2286 break;
Hans de Goede1876bb92009-06-14 06:45:50 -03002287 }
Hans de Goedefb1f9022009-10-16 07:42:53 -03002288
2289 if (ret >= 0)
2290 sd->sensor_reg_cache[reg] = ret;
2291
2292 return ret;
Hans de Goede1876bb92009-06-14 06:45:50 -03002293}
2294
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002295/* Writes bits at positions specified by mask to an I2C reg. Bits that are in
2296 * the same position as 1's in "mask" are cleared and set to "value". Bits
2297 * that are in the same position as 0's in "mask" are preserved, regardless
2298 * of their respective state in "value".
2299 */
2300static int i2c_w_mask(struct sd *sd,
2301 __u8 reg,
2302 __u8 value,
2303 __u8 mask)
2304{
2305 int rc;
2306 __u8 oldval;
2307
2308 value &= mask; /* Enforce mask on value */
2309 rc = i2c_r(sd, reg);
2310 if (rc < 0)
2311 return rc;
2312 oldval = rc & ~mask; /* Clear the masked bits */
2313 value |= oldval; /* Set the desired bits */
2314 return i2c_w(sd, reg, value);
2315}
2316
2317/* Temporarily stops OV511 from functioning. Must do this before changing
2318 * registers while the camera is streaming */
2319static inline int ov51x_stop(struct sd *sd)
2320{
2321 PDEBUG(D_STREAM, "stopping");
2322 sd->stopped = 1;
Hans de Goede49809d62009-06-07 12:10:39 -03002323 switch (sd->bridge) {
2324 case BRIDGE_OV511:
2325 case BRIDGE_OV511PLUS:
2326 return reg_w(sd, R51x_SYS_RESET, 0x3d);
2327 case BRIDGE_OV518:
2328 case BRIDGE_OV518PLUS:
2329 return reg_w_mask(sd, R51x_SYS_RESET, 0x3a, 0x3a);
2330 case BRIDGE_OV519:
2331 return reg_w(sd, OV519_SYS_RESET1, 0x0f);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002332 case BRIDGE_OVFX2:
2333 return reg_w_mask(sd, 0x0f, 0x00, 0x02);
Hans de Goedea511ba92009-10-16 07:13:07 -03002334 case BRIDGE_W9968CF:
Hans de Goede79b35902009-10-19 06:08:01 -03002335 return reg_w(sd, 0x3c, 0x0a05); /* stop USB transfer */
Hans de Goede49809d62009-06-07 12:10:39 -03002336 }
2337
2338 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002339}
2340
2341/* Restarts OV511 after ov511_stop() is called. Has no effect if it is not
2342 * actually stopped (for performance). */
2343static inline int ov51x_restart(struct sd *sd)
2344{
Hans de Goede49809d62009-06-07 12:10:39 -03002345 int rc;
2346
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002347 PDEBUG(D_STREAM, "restarting");
2348 if (!sd->stopped)
2349 return 0;
2350 sd->stopped = 0;
2351
2352 /* Reinitialize the stream */
Hans de Goede49809d62009-06-07 12:10:39 -03002353 switch (sd->bridge) {
2354 case BRIDGE_OV511:
2355 case BRIDGE_OV511PLUS:
2356 return reg_w(sd, R51x_SYS_RESET, 0x00);
2357 case BRIDGE_OV518:
2358 case BRIDGE_OV518PLUS:
2359 rc = reg_w(sd, 0x2f, 0x80);
2360 if (rc < 0)
2361 return rc;
2362 return reg_w(sd, R51x_SYS_RESET, 0x00);
2363 case BRIDGE_OV519:
2364 return reg_w(sd, OV519_SYS_RESET1, 0x00);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002365 case BRIDGE_OVFX2:
2366 return reg_w_mask(sd, 0x0f, 0x02, 0x02);
Hans de Goedea511ba92009-10-16 07:13:07 -03002367 case BRIDGE_W9968CF:
2368 return reg_w(sd, 0x3c, 0x8a05); /* USB FIFO enable */
Hans de Goede49809d62009-06-07 12:10:39 -03002369 }
2370
2371 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002372}
2373
Hans de Goede229bb7d2009-10-11 07:41:46 -03002374static int ov51x_set_slave_ids(struct sd *sd, __u8 slave);
2375
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002376/* This does an initial reset of an OmniVision sensor and ensures that I2C
2377 * is synchronized. Returns <0 on failure.
2378 */
Hans de Goede229bb7d2009-10-11 07:41:46 -03002379static int init_ov_sensor(struct sd *sd, __u8 slave)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002380{
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002381 int i;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002382
Hans de Goede229bb7d2009-10-11 07:41:46 -03002383 if (ov51x_set_slave_ids(sd, slave) < 0)
2384 return -EIO;
2385
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002386 /* Reset the sensor */
2387 if (i2c_w(sd, 0x12, 0x80) < 0)
2388 return -EIO;
2389
2390 /* Wait for it to initialize */
2391 msleep(150);
2392
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002393 for (i = 0; i < i2c_detect_tries; i++) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002394 if (i2c_r(sd, OV7610_REG_ID_HIGH) == 0x7f &&
2395 i2c_r(sd, OV7610_REG_ID_LOW) == 0xa2) {
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002396 PDEBUG(D_PROBE, "I2C synced in %d attempt(s)", i);
2397 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002398 }
2399
2400 /* Reset the sensor */
2401 if (i2c_w(sd, 0x12, 0x80) < 0)
2402 return -EIO;
2403 /* Wait for it to initialize */
2404 msleep(150);
2405 /* Dummy read to sync I2C */
2406 if (i2c_r(sd, 0x00) < 0)
2407 return -EIO;
2408 }
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03002409 return -EIO;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002410}
2411
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002412/* Set the read and write slave IDs. The "slave" argument is the write slave,
2413 * and the read slave will be set to (slave + 1).
2414 * This should not be called from outside the i2c I/O functions.
2415 * Sets I2C read and write slave IDs. Returns <0 for error
2416 */
2417static int ov51x_set_slave_ids(struct sd *sd,
2418 __u8 slave)
2419{
2420 int rc;
2421
Hans de Goedea511ba92009-10-16 07:13:07 -03002422 switch (sd->bridge) {
2423 case BRIDGE_OVFX2:
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002424 return reg_w(sd, OVFX2_I2C_ADDR, slave);
Hans de Goedea511ba92009-10-16 07:13:07 -03002425 case BRIDGE_W9968CF:
2426 sd->sensor_addr = slave;
2427 return 0;
2428 }
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002429
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002430 rc = reg_w(sd, R51x_I2C_W_SID, slave);
2431 if (rc < 0)
2432 return rc;
2433 return reg_w(sd, R51x_I2C_R_SID, slave + 1);
2434}
2435
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002436static int write_regvals(struct sd *sd,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002437 const struct ov_regvals *regvals,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002438 int n)
2439{
2440 int rc;
2441
2442 while (--n >= 0) {
2443 rc = reg_w(sd, regvals->reg, regvals->val);
2444 if (rc < 0)
2445 return rc;
2446 regvals++;
2447 }
2448 return 0;
2449}
2450
2451static int write_i2c_regvals(struct sd *sd,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002452 const struct ov_i2c_regvals *regvals,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002453 int n)
2454{
2455 int rc;
2456
2457 while (--n >= 0) {
2458 rc = i2c_w(sd, regvals->reg, regvals->val);
2459 if (rc < 0)
2460 return rc;
2461 regvals++;
2462 }
2463 return 0;
2464}
2465
2466/****************************************************************************
2467 *
2468 * OV511 and sensor configuration
2469 *
2470 ***************************************************************************/
2471
Hans de Goede635118d2009-10-11 09:49:03 -03002472/* This initializes the OV2x10 / OV3610 / OV3620 */
2473static int ov_hires_configure(struct sd *sd)
2474{
2475 int high, low;
2476
2477 if (sd->bridge != BRIDGE_OVFX2) {
2478 PDEBUG(D_ERR, "error hires sensors only supported with ovfx2");
2479 return -1;
2480 }
2481
2482 PDEBUG(D_PROBE, "starting ov hires configuration");
2483
2484 /* Detect sensor (sub)type */
2485 high = i2c_r(sd, 0x0a);
2486 low = i2c_r(sd, 0x0b);
2487 /* info("%x, %x", high, low); */
2488 if (high == 0x96 && low == 0x40) {
2489 PDEBUG(D_PROBE, "Sensor is an OV2610");
2490 sd->sensor = SEN_OV2610;
2491 } else if (high == 0x36 && (low & 0x0f) == 0x00) {
2492 PDEBUG(D_PROBE, "Sensor is an OV3610");
2493 sd->sensor = SEN_OV3610;
2494 } else {
2495 PDEBUG(D_ERR, "Error unknown sensor type: 0x%02x%02x",
2496 high, low);
2497 return -1;
2498 }
2499
2500 /* Set sensor-specific vars */
2501 return 0;
2502}
2503
2504
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002505/* This initializes the OV8110, OV8610 sensor. The OV8110 uses
2506 * the same register settings as the OV8610, since they are very similar.
2507 */
2508static int ov8xx0_configure(struct sd *sd)
2509{
2510 int rc;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002511
2512 PDEBUG(D_PROBE, "starting ov8xx0 configuration");
2513
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002514 /* Detect sensor (sub)type */
2515 rc = i2c_r(sd, OV7610_REG_COM_I);
2516 if (rc < 0) {
2517 PDEBUG(D_ERR, "Error detecting sensor type");
2518 return -1;
2519 }
2520 if ((rc & 3) == 1) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002521 sd->sensor = SEN_OV8610;
2522 } else {
2523 PDEBUG(D_ERR, "Unknown image sensor version: %d", rc & 3);
2524 return -1;
2525 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002526
2527 /* Set sensor-specific vars */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002528 return 0;
2529}
2530
2531/* This initializes the OV7610, OV7620, or OV76BE sensor. The OV76BE uses
2532 * the same register settings as the OV7610, since they are very similar.
2533 */
2534static int ov7xx0_configure(struct sd *sd)
2535{
2536 int rc, high, low;
2537
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002538
2539 PDEBUG(D_PROBE, "starting OV7xx0 configuration");
2540
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002541 /* Detect sensor (sub)type */
2542 rc = i2c_r(sd, OV7610_REG_COM_I);
2543
2544 /* add OV7670 here
2545 * it appears to be wrongly detected as a 7610 by default */
2546 if (rc < 0) {
2547 PDEBUG(D_ERR, "Error detecting sensor type");
2548 return -1;
2549 }
2550 if ((rc & 3) == 3) {
2551 /* quick hack to make OV7670s work */
2552 high = i2c_r(sd, 0x0a);
2553 low = i2c_r(sd, 0x0b);
2554 /* info("%x, %x", high, low); */
2555 if (high == 0x76 && low == 0x73) {
2556 PDEBUG(D_PROBE, "Sensor is an OV7670");
2557 sd->sensor = SEN_OV7670;
2558 } else {
2559 PDEBUG(D_PROBE, "Sensor is an OV7610");
2560 sd->sensor = SEN_OV7610;
2561 }
2562 } else if ((rc & 3) == 1) {
2563 /* I don't know what's different about the 76BE yet. */
Hans de Goedeb282d872009-06-14 19:10:40 -03002564 if (i2c_r(sd, 0x15) & 1) {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002565 PDEBUG(D_PROBE, "Sensor is an OV7620AE");
Hans de Goede859cc472010-01-07 15:42:35 -03002566 sd->sensor = SEN_OV7620AE;
Hans de Goedeb282d872009-06-14 19:10:40 -03002567 } else {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002568 PDEBUG(D_PROBE, "Sensor is an OV76BE");
Hans de Goedeb282d872009-06-14 19:10:40 -03002569 sd->sensor = SEN_OV76BE;
2570 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002571 } else if ((rc & 3) == 0) {
2572 /* try to read product id registers */
2573 high = i2c_r(sd, 0x0a);
2574 if (high < 0) {
2575 PDEBUG(D_ERR, "Error detecting camera chip PID");
2576 return high;
2577 }
2578 low = i2c_r(sd, 0x0b);
2579 if (low < 0) {
2580 PDEBUG(D_ERR, "Error detecting camera chip VER");
2581 return low;
2582 }
2583 if (high == 0x76) {
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002584 switch (low) {
2585 case 0x30:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002586 PDEBUG(D_PROBE, "Sensor is an OV7630/OV7635");
Jean-Francois Moine4202f712008-09-03 17:12:15 -03002587 PDEBUG(D_ERR,
2588 "7630 is not supported by this driver");
2589 return -1;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002590 case 0x40:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002591 PDEBUG(D_PROBE, "Sensor is an OV7645");
2592 sd->sensor = SEN_OV7640; /* FIXME */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002593 break;
2594 case 0x45:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002595 PDEBUG(D_PROBE, "Sensor is an OV7645B");
2596 sd->sensor = SEN_OV7640; /* FIXME */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002597 break;
2598 case 0x48:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002599 PDEBUG(D_PROBE, "Sensor is an OV7648");
Hans de Goede035d3a32010-01-09 08:14:43 -03002600 sd->sensor = SEN_OV7648;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002601 break;
2602 default:
2603 PDEBUG(D_PROBE, "Unknown sensor: 0x76%x", low);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002604 return -1;
2605 }
2606 } else {
2607 PDEBUG(D_PROBE, "Sensor is an OV7620");
2608 sd->sensor = SEN_OV7620;
2609 }
2610 } else {
2611 PDEBUG(D_ERR, "Unknown image sensor version: %d", rc & 3);
2612 return -1;
2613 }
2614
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002615 /* Set sensor-specific vars */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002616 return 0;
2617}
2618
2619/* This initializes the OV6620, OV6630, OV6630AE, or OV6630AF sensor. */
2620static int ov6xx0_configure(struct sd *sd)
2621{
2622 int rc;
Jean-Francois Moine4202f712008-09-03 17:12:15 -03002623 PDEBUG(D_PROBE, "starting OV6xx0 configuration");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002624
2625 /* Detect sensor (sub)type */
2626 rc = i2c_r(sd, OV7610_REG_COM_I);
2627 if (rc < 0) {
2628 PDEBUG(D_ERR, "Error detecting sensor type");
2629 return -1;
2630 }
2631
2632 /* Ugh. The first two bits are the version bits, but
2633 * the entire register value must be used. I guess OVT
2634 * underestimated how many variants they would make. */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002635 switch (rc) {
2636 case 0x00:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002637 sd->sensor = SEN_OV6630;
2638 PDEBUG(D_ERR,
2639 "WARNING: Sensor is an OV66308. Your camera may have");
2640 PDEBUG(D_ERR, "been misdetected in previous driver versions.");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002641 break;
2642 case 0x01:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002643 sd->sensor = SEN_OV6620;
Hans de Goede7d971372009-06-14 05:28:17 -03002644 PDEBUG(D_PROBE, "Sensor is an OV6620");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002645 break;
2646 case 0x02:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002647 sd->sensor = SEN_OV6630;
2648 PDEBUG(D_PROBE, "Sensor is an OV66308AE");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002649 break;
2650 case 0x03:
Hans de Goede7d971372009-06-14 05:28:17 -03002651 sd->sensor = SEN_OV66308AF;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002652 PDEBUG(D_PROBE, "Sensor is an OV66308AF");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002653 break;
2654 case 0x90:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002655 sd->sensor = SEN_OV6630;
2656 PDEBUG(D_ERR,
2657 "WARNING: Sensor is an OV66307. Your camera may have");
2658 PDEBUG(D_ERR, "been misdetected in previous driver versions.");
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002659 break;
2660 default:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002661 PDEBUG(D_ERR, "FATAL: Unknown sensor version: 0x%02x", rc);
2662 return -1;
2663 }
2664
2665 /* Set sensor-specific vars */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03002666 sd->sif = 1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002667
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002668 return 0;
2669}
2670
2671/* Turns on or off the LED. Only has an effect with OV511+/OV518(+)/OV519 */
2672static void ov51x_led_control(struct sd *sd, int on)
2673{
Hans de Goede9e4d8252009-06-14 06:25:06 -03002674 if (sd->invert_led)
2675 on = !on;
2676
Hans de Goede49809d62009-06-07 12:10:39 -03002677 switch (sd->bridge) {
2678 /* OV511 has no LED control */
2679 case BRIDGE_OV511PLUS:
2680 reg_w(sd, R511_SYS_LED_CTL, on ? 1 : 0);
2681 break;
2682 case BRIDGE_OV518:
2683 case BRIDGE_OV518PLUS:
2684 reg_w_mask(sd, R518_GPIO_OUT, on ? 0x02 : 0x00, 0x02);
2685 break;
2686 case BRIDGE_OV519:
2687 reg_w_mask(sd, OV519_GPIO_DATA_OUT0, !on, 1); /* 0 / 1 */
2688 break;
2689 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002690}
2691
Hans de Goede417a4d22010-02-19 07:37:08 -03002692static void sd_reset_snapshot(struct gspca_dev *gspca_dev)
2693{
2694 struct sd *sd = (struct sd *) gspca_dev;
2695
2696 if (!sd->snapshot_needs_reset)
2697 return;
2698
2699 /* Note it is important that we clear sd->snapshot_needs_reset,
2700 before actually clearing the snapshot state in the bridge
2701 otherwise we might race with the pkt_scan interrupt handler */
2702 sd->snapshot_needs_reset = 0;
2703
2704 switch (sd->bridge) {
Hans de Goede92e232a2010-02-20 04:30:45 -03002705 case BRIDGE_OV518:
2706 case BRIDGE_OV518PLUS:
2707 reg_w(sd, R51x_SYS_SNAP, 0x02); /* Reset */
2708 reg_w(sd, R51x_SYS_SNAP, 0x01); /* Enable */
2709 break;
Hans de Goede417a4d22010-02-19 07:37:08 -03002710 case BRIDGE_OV519:
2711 reg_w(sd, R51x_SYS_RESET, 0x40);
2712 reg_w(sd, R51x_SYS_RESET, 0x00);
2713 break;
2714 }
2715}
2716
Hans de Goede1876bb92009-06-14 06:45:50 -03002717static int ov51x_upload_quan_tables(struct sd *sd)
Hans de Goede49809d62009-06-07 12:10:39 -03002718{
Hans de Goede1876bb92009-06-14 06:45:50 -03002719 const unsigned char yQuanTable511[] = {
2720 0, 1, 1, 2, 2, 3, 3, 4,
2721 1, 1, 1, 2, 2, 3, 4, 4,
2722 1, 1, 2, 2, 3, 4, 4, 4,
2723 2, 2, 2, 3, 4, 4, 4, 4,
2724 2, 2, 3, 4, 4, 5, 5, 5,
2725 3, 3, 4, 4, 5, 5, 5, 5,
2726 3, 4, 4, 4, 5, 5, 5, 5,
2727 4, 4, 4, 4, 5, 5, 5, 5
2728 };
2729
2730 const unsigned char uvQuanTable511[] = {
2731 0, 2, 2, 3, 4, 4, 4, 4,
2732 2, 2, 2, 4, 4, 4, 4, 4,
2733 2, 2, 3, 4, 4, 4, 4, 4,
2734 3, 4, 4, 4, 4, 4, 4, 4,
2735 4, 4, 4, 4, 4, 4, 4, 4,
2736 4, 4, 4, 4, 4, 4, 4, 4,
2737 4, 4, 4, 4, 4, 4, 4, 4,
2738 4, 4, 4, 4, 4, 4, 4, 4
2739 };
2740
2741 /* OV518 quantization tables are 8x4 (instead of 8x8) */
Hans de Goede49809d62009-06-07 12:10:39 -03002742 const unsigned char yQuanTable518[] = {
2743 5, 4, 5, 6, 6, 7, 7, 7,
2744 5, 5, 5, 5, 6, 7, 7, 7,
2745 6, 6, 6, 6, 7, 7, 7, 8,
2746 7, 7, 6, 7, 7, 7, 8, 8
2747 };
2748
2749 const unsigned char uvQuanTable518[] = {
2750 6, 6, 6, 7, 7, 7, 7, 7,
2751 6, 6, 6, 7, 7, 7, 7, 7,
2752 6, 6, 6, 7, 7, 7, 7, 8,
2753 7, 7, 7, 7, 7, 7, 8, 8
2754 };
2755
Hans de Goede1876bb92009-06-14 06:45:50 -03002756 const unsigned char *pYTable, *pUVTable;
Hans de Goede49809d62009-06-07 12:10:39 -03002757 unsigned char val0, val1;
Hans de Goede1876bb92009-06-14 06:45:50 -03002758 int i, size, rc, reg = R51x_COMP_LUT_BEGIN;
Hans de Goede49809d62009-06-07 12:10:39 -03002759
2760 PDEBUG(D_PROBE, "Uploading quantization tables");
2761
Hans de Goede1876bb92009-06-14 06:45:50 -03002762 if (sd->bridge == BRIDGE_OV511 || sd->bridge == BRIDGE_OV511PLUS) {
2763 pYTable = yQuanTable511;
2764 pUVTable = uvQuanTable511;
2765 size = 32;
2766 } else {
2767 pYTable = yQuanTable518;
2768 pUVTable = uvQuanTable518;
2769 size = 16;
2770 }
2771
2772 for (i = 0; i < size; i++) {
Hans de Goede49809d62009-06-07 12:10:39 -03002773 val0 = *pYTable++;
2774 val1 = *pYTable++;
2775 val0 &= 0x0f;
2776 val1 &= 0x0f;
2777 val0 |= val1 << 4;
2778 rc = reg_w(sd, reg, val0);
2779 if (rc < 0)
2780 return rc;
2781
2782 val0 = *pUVTable++;
2783 val1 = *pUVTable++;
2784 val0 &= 0x0f;
2785 val1 &= 0x0f;
2786 val0 |= val1 << 4;
Hans de Goede1876bb92009-06-14 06:45:50 -03002787 rc = reg_w(sd, reg + size, val0);
Hans de Goede49809d62009-06-07 12:10:39 -03002788 if (rc < 0)
2789 return rc;
2790
2791 reg++;
2792 }
2793
2794 return 0;
2795}
2796
Hans de Goede1876bb92009-06-14 06:45:50 -03002797/* This initializes the OV511/OV511+ and the sensor */
2798static int ov511_configure(struct gspca_dev *gspca_dev)
2799{
2800 struct sd *sd = (struct sd *) gspca_dev;
2801 int rc;
2802
2803 /* For 511 and 511+ */
2804 const struct ov_regvals init_511[] = {
2805 { R51x_SYS_RESET, 0x7f },
2806 { R51x_SYS_INIT, 0x01 },
2807 { R51x_SYS_RESET, 0x7f },
2808 { R51x_SYS_INIT, 0x01 },
2809 { R51x_SYS_RESET, 0x3f },
2810 { R51x_SYS_INIT, 0x01 },
2811 { R51x_SYS_RESET, 0x3d },
2812 };
2813
2814 const struct ov_regvals norm_511[] = {
2815 { R511_DRAM_FLOW_CTL, 0x01 },
2816 { R51x_SYS_SNAP, 0x00 },
2817 { R51x_SYS_SNAP, 0x02 },
2818 { R51x_SYS_SNAP, 0x00 },
2819 { R511_FIFO_OPTS, 0x1f },
2820 { R511_COMP_EN, 0x00 },
2821 { R511_COMP_LUT_EN, 0x03 },
2822 };
2823
2824 const struct ov_regvals norm_511_p[] = {
2825 { R511_DRAM_FLOW_CTL, 0xff },
2826 { R51x_SYS_SNAP, 0x00 },
2827 { R51x_SYS_SNAP, 0x02 },
2828 { R51x_SYS_SNAP, 0x00 },
2829 { R511_FIFO_OPTS, 0xff },
2830 { R511_COMP_EN, 0x00 },
2831 { R511_COMP_LUT_EN, 0x03 },
2832 };
2833
2834 const struct ov_regvals compress_511[] = {
2835 { 0x70, 0x1f },
2836 { 0x71, 0x05 },
2837 { 0x72, 0x06 },
2838 { 0x73, 0x06 },
2839 { 0x74, 0x14 },
2840 { 0x75, 0x03 },
2841 { 0x76, 0x04 },
2842 { 0x77, 0x04 },
2843 };
2844
2845 PDEBUG(D_PROBE, "Device custom id %x", reg_r(sd, R51x_SYS_CUST_ID));
2846
2847 rc = write_regvals(sd, init_511, ARRAY_SIZE(init_511));
2848 if (rc < 0)
2849 return rc;
2850
2851 switch (sd->bridge) {
2852 case BRIDGE_OV511:
2853 rc = write_regvals(sd, norm_511, ARRAY_SIZE(norm_511));
2854 if (rc < 0)
2855 return rc;
2856 break;
2857 case BRIDGE_OV511PLUS:
2858 rc = write_regvals(sd, norm_511_p, ARRAY_SIZE(norm_511_p));
2859 if (rc < 0)
2860 return rc;
2861 break;
2862 }
2863
2864 /* Init compression */
2865 rc = write_regvals(sd, compress_511, ARRAY_SIZE(compress_511));
2866 if (rc < 0)
2867 return rc;
2868
2869 rc = ov51x_upload_quan_tables(sd);
2870 if (rc < 0) {
2871 PDEBUG(D_ERR, "Error uploading quantization tables");
2872 return rc;
2873 }
2874
2875 return 0;
2876}
2877
Hans de Goede49809d62009-06-07 12:10:39 -03002878/* This initializes the OV518/OV518+ and the sensor */
2879static int ov518_configure(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002880{
2881 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede49809d62009-06-07 12:10:39 -03002882 int rc;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002883
Hans de Goede49809d62009-06-07 12:10:39 -03002884 /* For 518 and 518+ */
Hans de Goedee080fcd2009-06-18 05:03:16 -03002885 const struct ov_regvals init_518[] = {
Hans de Goede49809d62009-06-07 12:10:39 -03002886 { R51x_SYS_RESET, 0x40 },
2887 { R51x_SYS_INIT, 0xe1 },
2888 { R51x_SYS_RESET, 0x3e },
2889 { R51x_SYS_INIT, 0xe1 },
2890 { R51x_SYS_RESET, 0x00 },
2891 { R51x_SYS_INIT, 0xe1 },
2892 { 0x46, 0x00 },
2893 { 0x5d, 0x03 },
2894 };
2895
Hans de Goedee080fcd2009-06-18 05:03:16 -03002896 const struct ov_regvals norm_518[] = {
Hans de Goede49809d62009-06-07 12:10:39 -03002897 { R51x_SYS_SNAP, 0x02 }, /* Reset */
2898 { R51x_SYS_SNAP, 0x01 }, /* Enable */
2899 { 0x31, 0x0f },
2900 { 0x5d, 0x03 },
2901 { 0x24, 0x9f },
2902 { 0x25, 0x90 },
2903 { 0x20, 0x00 },
2904 { 0x51, 0x04 },
2905 { 0x71, 0x19 },
2906 { 0x2f, 0x80 },
2907 };
2908
Hans de Goedee080fcd2009-06-18 05:03:16 -03002909 const struct ov_regvals norm_518_p[] = {
Hans de Goede49809d62009-06-07 12:10:39 -03002910 { R51x_SYS_SNAP, 0x02 }, /* Reset */
2911 { R51x_SYS_SNAP, 0x01 }, /* Enable */
2912 { 0x31, 0x0f },
2913 { 0x5d, 0x03 },
2914 { 0x24, 0x9f },
2915 { 0x25, 0x90 },
2916 { 0x20, 0x60 },
2917 { 0x51, 0x02 },
2918 { 0x71, 0x19 },
2919 { 0x40, 0xff },
2920 { 0x41, 0x42 },
2921 { 0x46, 0x00 },
2922 { 0x33, 0x04 },
2923 { 0x21, 0x19 },
2924 { 0x3f, 0x10 },
2925 { 0x2f, 0x80 },
2926 };
2927
2928 /* First 5 bits of custom ID reg are a revision ID on OV518 */
2929 PDEBUG(D_PROBE, "Device revision %d",
2930 0x1F & reg_r(sd, R51x_SYS_CUST_ID));
2931
2932 rc = write_regvals(sd, init_518, ARRAY_SIZE(init_518));
2933 if (rc < 0)
2934 return rc;
2935
2936 /* Set LED GPIO pin to output mode */
2937 rc = reg_w_mask(sd, R518_GPIO_CTL, 0x00, 0x02);
2938 if (rc < 0)
2939 return rc;
2940
2941 switch (sd->bridge) {
2942 case BRIDGE_OV518:
2943 rc = write_regvals(sd, norm_518, ARRAY_SIZE(norm_518));
2944 if (rc < 0)
2945 return rc;
2946 break;
2947 case BRIDGE_OV518PLUS:
2948 rc = write_regvals(sd, norm_518_p, ARRAY_SIZE(norm_518_p));
2949 if (rc < 0)
2950 return rc;
2951 break;
2952 }
2953
Hans de Goede1876bb92009-06-14 06:45:50 -03002954 rc = ov51x_upload_quan_tables(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03002955 if (rc < 0) {
2956 PDEBUG(D_ERR, "Error uploading quantization tables");
2957 return rc;
2958 }
2959
2960 rc = reg_w(sd, 0x2f, 0x80);
2961 if (rc < 0)
2962 return rc;
2963
2964 return 0;
2965}
2966
2967static int ov519_configure(struct sd *sd)
2968{
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03002969 static const struct ov_regvals init_519[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002970 { 0x5a, 0x6d }, /* EnableSystem */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03002971 { 0x53, 0x9b },
2972 { 0x54, 0xff }, /* set bit2 to enable jpeg */
2973 { 0x5d, 0x03 },
2974 { 0x49, 0x01 },
2975 { 0x48, 0x00 },
2976 /* Set LED pin to output mode. Bit 4 must be cleared or sensor
2977 * detection will fail. This deserves further investigation. */
2978 { OV519_GPIO_IO_CTRL0, 0xee },
2979 { 0x51, 0x0f }, /* SetUsbInit */
2980 { 0x51, 0x00 },
2981 { 0x22, 0x00 },
2982 /* windows reads 0x55 at this point*/
2983 };
2984
Hans de Goede49809d62009-06-07 12:10:39 -03002985 return write_regvals(sd, init_519, ARRAY_SIZE(init_519));
2986}
2987
Hans de Goedeb46aaa02009-10-12 10:07:57 -03002988static int ovfx2_configure(struct sd *sd)
2989{
2990 static const struct ov_regvals init_fx2[] = {
2991 { 0x00, 0x60 },
2992 { 0x02, 0x01 },
2993 { 0x0f, 0x1d },
2994 { 0xe9, 0x82 },
2995 { 0xea, 0xc7 },
2996 { 0xeb, 0x10 },
2997 { 0xec, 0xf6 },
2998 };
2999
3000 sd->stopped = 1;
3001
3002 return write_regvals(sd, init_fx2, ARRAY_SIZE(init_fx2));
3003}
3004
Hans de Goede49809d62009-06-07 12:10:39 -03003005/* this function is called at probe time */
3006static int sd_config(struct gspca_dev *gspca_dev,
3007 const struct usb_device_id *id)
3008{
3009 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003010 struct cam *cam = &gspca_dev->cam;
Hans de Goede49809d62009-06-07 12:10:39 -03003011 int ret = 0;
3012
Hans de Goede9e4d8252009-06-14 06:25:06 -03003013 sd->bridge = id->driver_info & BRIDGE_MASK;
3014 sd->invert_led = id->driver_info & BRIDGE_INVERT_LED;
Hans de Goede49809d62009-06-07 12:10:39 -03003015
3016 switch (sd->bridge) {
Hans de Goede1876bb92009-06-14 06:45:50 -03003017 case BRIDGE_OV511:
3018 case BRIDGE_OV511PLUS:
3019 ret = ov511_configure(gspca_dev);
3020 break;
Hans de Goede49809d62009-06-07 12:10:39 -03003021 case BRIDGE_OV518:
3022 case BRIDGE_OV518PLUS:
3023 ret = ov518_configure(gspca_dev);
3024 break;
3025 case BRIDGE_OV519:
3026 ret = ov519_configure(sd);
3027 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003028 case BRIDGE_OVFX2:
3029 ret = ovfx2_configure(sd);
3030 cam->bulk_size = OVFX2_BULK_SIZE;
3031 cam->bulk_nurbs = MAX_NURBS;
3032 cam->bulk = 1;
3033 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03003034 case BRIDGE_W9968CF:
3035 ret = w9968cf_configure(sd);
3036 cam->reverse_alts = 1;
3037 break;
Hans de Goede49809d62009-06-07 12:10:39 -03003038 }
3039
3040 if (ret)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003041 goto error;
Hans de Goede49809d62009-06-07 12:10:39 -03003042
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003043 ov51x_led_control(sd, 0); /* turn LED off */
3044
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003045 /* The OV519 must be more aggressive about sensor detection since
3046 * I2C write will never fail if the sensor is not present. We have
3047 * to try to initialize the sensor to detect its presence */
Hans de Goede229bb7d2009-10-11 07:41:46 -03003048
3049 /* Test for 76xx */
3050 if (init_ov_sensor(sd, OV7xx0_SID) >= 0) {
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003051 if (ov7xx0_configure(sd) < 0) {
3052 PDEBUG(D_ERR, "Failed to configure OV7xx0");
3053 goto error;
3054 }
Hans de Goede229bb7d2009-10-11 07:41:46 -03003055 /* Test for 6xx0 */
3056 } else if (init_ov_sensor(sd, OV6xx0_SID) >= 0) {
3057 if (ov6xx0_configure(sd) < 0) {
3058 PDEBUG(D_ERR, "Failed to configure OV6xx0");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003059 goto error;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003060 }
Hans de Goede229bb7d2009-10-11 07:41:46 -03003061 /* Test for 8xx0 */
3062 } else if (init_ov_sensor(sd, OV8xx0_SID) >= 0) {
3063 if (ov8xx0_configure(sd) < 0) {
3064 PDEBUG(D_ERR, "Failed to configure OV8xx0");
3065 goto error;
3066 }
Hans de Goede635118d2009-10-11 09:49:03 -03003067 /* Test for 3xxx / 2xxx */
3068 } else if (init_ov_sensor(sd, OV_HIRES_SID) >= 0) {
3069 if (ov_hires_configure(sd) < 0) {
3070 PDEBUG(D_ERR, "Failed to configure high res OV");
3071 goto error;
3072 }
Hans de Goede229bb7d2009-10-11 07:41:46 -03003073 } else {
3074 PDEBUG(D_ERR, "Can't determine sensor slave IDs");
3075 goto error;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003076 }
3077
Hans de Goede49809d62009-06-07 12:10:39 -03003078 switch (sd->bridge) {
Hans de Goede1876bb92009-06-14 06:45:50 -03003079 case BRIDGE_OV511:
3080 case BRIDGE_OV511PLUS:
3081 if (!sd->sif) {
3082 cam->cam_mode = ov511_vga_mode;
3083 cam->nmodes = ARRAY_SIZE(ov511_vga_mode);
3084 } else {
3085 cam->cam_mode = ov511_sif_mode;
3086 cam->nmodes = ARRAY_SIZE(ov511_sif_mode);
3087 }
3088 break;
Hans de Goede49809d62009-06-07 12:10:39 -03003089 case BRIDGE_OV518:
3090 case BRIDGE_OV518PLUS:
3091 if (!sd->sif) {
3092 cam->cam_mode = ov518_vga_mode;
3093 cam->nmodes = ARRAY_SIZE(ov518_vga_mode);
3094 } else {
3095 cam->cam_mode = ov518_sif_mode;
3096 cam->nmodes = ARRAY_SIZE(ov518_sif_mode);
3097 }
3098 break;
3099 case BRIDGE_OV519:
3100 if (!sd->sif) {
3101 cam->cam_mode = ov519_vga_mode;
3102 cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
3103 } else {
3104 cam->cam_mode = ov519_sif_mode;
3105 cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
3106 }
3107 break;
Hans de Goede635118d2009-10-11 09:49:03 -03003108 case BRIDGE_OVFX2:
3109 if (sd->sensor == SEN_OV2610) {
3110 cam->cam_mode = ovfx2_ov2610_mode;
3111 cam->nmodes = ARRAY_SIZE(ovfx2_ov2610_mode);
3112 } else if (sd->sensor == SEN_OV3610) {
3113 cam->cam_mode = ovfx2_ov3610_mode;
3114 cam->nmodes = ARRAY_SIZE(ovfx2_ov3610_mode);
3115 } else if (!sd->sif) {
3116 cam->cam_mode = ov519_vga_mode;
3117 cam->nmodes = ARRAY_SIZE(ov519_vga_mode);
3118 } else {
3119 cam->cam_mode = ov519_sif_mode;
3120 cam->nmodes = ARRAY_SIZE(ov519_sif_mode);
3121 }
3122 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03003123 case BRIDGE_W9968CF:
3124 cam->cam_mode = w9968cf_vga_mode;
3125 cam->nmodes = ARRAY_SIZE(w9968cf_vga_mode);
Hans de Goede79b35902009-10-19 06:08:01 -03003126 if (sd->sif)
3127 cam->nmodes--;
Hans de Goedea511ba92009-10-16 07:13:07 -03003128
3129 /* w9968cf needs initialisation once the sensor is known */
3130 if (w9968cf_init(sd) < 0)
3131 goto error;
3132 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003133 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003134 sd->brightness = BRIGHTNESS_DEF;
Hans de Goedef5cee952009-06-14 06:32:52 -03003135 if (sd->sensor == SEN_OV6630 || sd->sensor == SEN_OV66308AF)
3136 sd->contrast = 200; /* The default is too low for the ov6630 */
3137 else
3138 sd->contrast = CONTRAST_DEF;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003139 sd->colors = COLOR_DEF;
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003140 sd->hflip = HFLIP_DEF;
3141 sd->vflip = VFLIP_DEF;
Hans de Goede02ab18b2009-06-14 04:32:04 -03003142 sd->autobrightness = AUTOBRIGHT_DEF;
3143 if (sd->sensor == SEN_OV7670) {
3144 sd->freq = OV7670_FREQ_DEF;
3145 gspca_dev->ctrl_dis = 1 << FREQ_IDX;
3146 } else {
3147 sd->freq = FREQ_DEF;
3148 gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX) |
3149 (1 << OV7670_FREQ_IDX);
3150 }
Hans de Goede79b35902009-10-19 06:08:01 -03003151 sd->quality = QUALITY_DEF;
Hans de Goede035d3a32010-01-09 08:14:43 -03003152 if (sd->sensor == SEN_OV7640 ||
Hans de Goeded02134d2010-01-09 19:22:34 -03003153 sd->sensor == SEN_OV7648)
3154 gspca_dev->ctrl_dis |= (1 << AUTOBRIGHT_IDX) |
3155 (1 << CONTRAST_IDX);
3156 if (sd->sensor == SEN_OV7670)
Hans de Goede02ab18b2009-06-14 04:32:04 -03003157 gspca_dev->ctrl_dis |= 1 << AUTOBRIGHT_IDX;
3158 /* OV8610 Frequency filter control should work but needs testing */
3159 if (sd->sensor == SEN_OV8610)
3160 gspca_dev->ctrl_dis |= 1 << FREQ_IDX;
Hans de Goede635118d2009-10-11 09:49:03 -03003161 /* No controls for the OV2610/OV3610 */
3162 if (sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610)
3163 gspca_dev->ctrl_dis |= 0xFF;
Hans de Goede02ab18b2009-06-14 04:32:04 -03003164
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003165 return 0;
3166error:
3167 PDEBUG(D_ERR, "OV519 Config failed");
3168 return -EBUSY;
3169}
3170
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03003171/* this function is called at probe and resume time */
3172static int sd_init(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003173{
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003174 struct sd *sd = (struct sd *) gspca_dev;
3175
3176 /* initialize the sensor */
3177 switch (sd->sensor) {
Hans de Goede635118d2009-10-11 09:49:03 -03003178 case SEN_OV2610:
3179 if (write_i2c_regvals(sd, norm_2610, ARRAY_SIZE(norm_2610)))
3180 return -EIO;
3181 /* Enable autogain, autoexpo, awb, bandfilter */
3182 if (i2c_w_mask(sd, 0x13, 0x27, 0x27) < 0)
3183 return -EIO;
3184 break;
3185 case SEN_OV3610:
3186 if (write_i2c_regvals(sd, norm_3620b, ARRAY_SIZE(norm_3620b)))
3187 return -EIO;
3188 /* Enable autogain, autoexpo, awb, bandfilter */
3189 if (i2c_w_mask(sd, 0x13, 0x27, 0x27) < 0)
3190 return -EIO;
3191 break;
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003192 case SEN_OV6620:
3193 if (write_i2c_regvals(sd, norm_6x20, ARRAY_SIZE(norm_6x20)))
3194 return -EIO;
3195 break;
3196 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03003197 case SEN_OV66308AF:
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003198 if (write_i2c_regvals(sd, norm_6x30, ARRAY_SIZE(norm_6x30)))
3199 return -EIO;
3200 break;
3201 default:
3202/* case SEN_OV7610: */
3203/* case SEN_OV76BE: */
3204 if (write_i2c_regvals(sd, norm_7610, ARRAY_SIZE(norm_7610)))
3205 return -EIO;
Hans de Goedeae49c402009-06-14 19:15:07 -03003206 if (i2c_w_mask(sd, 0x0e, 0x00, 0x40))
3207 return -EIO;
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003208 break;
3209 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03003210 case SEN_OV7620AE:
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003211 if (write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620)))
3212 return -EIO;
3213 break;
3214 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003215 case SEN_OV7648:
Jean-Francois Moine4202f712008-09-03 17:12:15 -03003216 if (write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640)))
3217 return -EIO;
3218 break;
3219 case SEN_OV7670:
3220 if (write_i2c_regvals(sd, norm_7670, ARRAY_SIZE(norm_7670)))
3221 return -EIO;
3222 break;
3223 case SEN_OV8610:
3224 if (write_i2c_regvals(sd, norm_8610, ARRAY_SIZE(norm_8610)))
3225 return -EIO;
3226 break;
3227 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003228 return 0;
3229}
3230
Hans de Goede1876bb92009-06-14 06:45:50 -03003231/* Set up the OV511/OV511+ with the given image parameters.
3232 *
3233 * Do not put any sensor-specific code in here (including I2C I/O functions)
3234 */
3235static int ov511_mode_init_regs(struct sd *sd)
3236{
3237 int hsegs, vsegs, packet_size, fps, needed;
3238 int interlaced = 0;
3239 struct usb_host_interface *alt;
3240 struct usb_interface *intf;
3241
3242 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
3243 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
3244 if (!alt) {
3245 PDEBUG(D_ERR, "Couldn't get altsetting");
3246 return -EIO;
3247 }
3248
3249 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
3250 reg_w(sd, R51x_FIFO_PSIZE, packet_size >> 5);
3251
3252 reg_w(sd, R511_CAM_UV_EN, 0x01);
3253 reg_w(sd, R511_SNAP_UV_EN, 0x01);
3254 reg_w(sd, R511_SNAP_OPTS, 0x03);
3255
3256 /* Here I'm assuming that snapshot size == image size.
3257 * I hope that's always true. --claudio
3258 */
3259 hsegs = (sd->gspca_dev.width >> 3) - 1;
3260 vsegs = (sd->gspca_dev.height >> 3) - 1;
3261
3262 reg_w(sd, R511_CAM_PXCNT, hsegs);
3263 reg_w(sd, R511_CAM_LNCNT, vsegs);
3264 reg_w(sd, R511_CAM_PXDIV, 0x00);
3265 reg_w(sd, R511_CAM_LNDIV, 0x00);
3266
3267 /* YUV420, low pass filter on */
3268 reg_w(sd, R511_CAM_OPTS, 0x03);
3269
3270 /* Snapshot additions */
3271 reg_w(sd, R511_SNAP_PXCNT, hsegs);
3272 reg_w(sd, R511_SNAP_LNCNT, vsegs);
3273 reg_w(sd, R511_SNAP_PXDIV, 0x00);
3274 reg_w(sd, R511_SNAP_LNDIV, 0x00);
3275
3276 /******** Set the framerate ********/
3277 if (frame_rate > 0)
3278 sd->frame_rate = frame_rate;
3279
3280 switch (sd->sensor) {
3281 case SEN_OV6620:
3282 /* No framerate control, doesn't like higher rates yet */
3283 sd->clockdiv = 3;
3284 break;
3285
3286 /* Note once the FIXME's in mode_init_ov_sensor_regs() are fixed
3287 for more sensors we need to do this for them too */
3288 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03003289 case SEN_OV7620AE:
Hans de Goede1876bb92009-06-14 06:45:50 -03003290 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003291 case SEN_OV7648:
Hans de Goedeb282d872009-06-14 19:10:40 -03003292 case SEN_OV76BE:
Hans de Goede1876bb92009-06-14 06:45:50 -03003293 if (sd->gspca_dev.width == 320)
3294 interlaced = 1;
3295 /* Fall through */
3296 case SEN_OV6630:
Hans de Goede1876bb92009-06-14 06:45:50 -03003297 case SEN_OV7610:
3298 case SEN_OV7670:
3299 switch (sd->frame_rate) {
3300 case 30:
3301 case 25:
3302 /* Not enough bandwidth to do 640x480 @ 30 fps */
3303 if (sd->gspca_dev.width != 640) {
3304 sd->clockdiv = 0;
3305 break;
3306 }
3307 /* Fall through for 640x480 case */
3308 default:
3309/* case 20: */
3310/* case 15: */
3311 sd->clockdiv = 1;
3312 break;
3313 case 10:
3314 sd->clockdiv = 2;
3315 break;
3316 case 5:
3317 sd->clockdiv = 5;
3318 break;
3319 }
3320 if (interlaced) {
3321 sd->clockdiv = (sd->clockdiv + 1) * 2 - 1;
3322 /* Higher then 10 does not work */
3323 if (sd->clockdiv > 10)
3324 sd->clockdiv = 10;
3325 }
3326 break;
3327
3328 case SEN_OV8610:
3329 /* No framerate control ?? */
3330 sd->clockdiv = 0;
3331 break;
3332 }
3333
3334 /* Check if we have enough bandwidth to disable compression */
3335 fps = (interlaced ? 60 : 30) / (sd->clockdiv + 1) + 1;
3336 needed = fps * sd->gspca_dev.width * sd->gspca_dev.height * 3 / 2;
3337 /* 1400 is a conservative estimate of the max nr of isoc packets/sec */
3338 if (needed > 1400 * packet_size) {
3339 /* Enable Y and UV quantization and compression */
3340 reg_w(sd, R511_COMP_EN, 0x07);
3341 reg_w(sd, R511_COMP_LUT_EN, 0x03);
3342 } else {
3343 reg_w(sd, R511_COMP_EN, 0x06);
3344 reg_w(sd, R511_COMP_LUT_EN, 0x00);
3345 }
3346
3347 reg_w(sd, R51x_SYS_RESET, OV511_RESET_OMNICE);
3348 reg_w(sd, R51x_SYS_RESET, 0);
3349
3350 return 0;
3351}
3352
Hans de Goede49809d62009-06-07 12:10:39 -03003353/* Sets up the OV518/OV518+ with the given image parameters
3354 *
3355 * OV518 needs a completely different approach, until we can figure out what
3356 * the individual registers do. Also, only 15 FPS is supported now.
3357 *
3358 * Do not put any sensor-specific code in here (including I2C I/O functions)
3359 */
3360static int ov518_mode_init_regs(struct sd *sd)
3361{
Hans de Goedeb282d872009-06-14 19:10:40 -03003362 int hsegs, vsegs, packet_size;
3363 struct usb_host_interface *alt;
3364 struct usb_interface *intf;
3365
3366 intf = usb_ifnum_to_if(sd->gspca_dev.dev, sd->gspca_dev.iface);
3367 alt = usb_altnum_to_altsetting(intf, sd->gspca_dev.alt);
3368 if (!alt) {
3369 PDEBUG(D_ERR, "Couldn't get altsetting");
3370 return -EIO;
3371 }
3372
3373 packet_size = le16_to_cpu(alt->endpoint[0].desc.wMaxPacketSize);
3374 ov518_reg_w32(sd, R51x_FIFO_PSIZE, packet_size & ~7, 2);
Hans de Goede49809d62009-06-07 12:10:39 -03003375
3376 /******** Set the mode ********/
3377
3378 reg_w(sd, 0x2b, 0);
3379 reg_w(sd, 0x2c, 0);
3380 reg_w(sd, 0x2d, 0);
3381 reg_w(sd, 0x2e, 0);
3382 reg_w(sd, 0x3b, 0);
3383 reg_w(sd, 0x3c, 0);
3384 reg_w(sd, 0x3d, 0);
3385 reg_w(sd, 0x3e, 0);
3386
3387 if (sd->bridge == BRIDGE_OV518) {
3388 /* Set 8-bit (YVYU) input format */
3389 reg_w_mask(sd, 0x20, 0x08, 0x08);
3390
3391 /* Set 12-bit (4:2:0) output format */
3392 reg_w_mask(sd, 0x28, 0x80, 0xf0);
3393 reg_w_mask(sd, 0x38, 0x80, 0xf0);
3394 } else {
3395 reg_w(sd, 0x28, 0x80);
3396 reg_w(sd, 0x38, 0x80);
3397 }
3398
3399 hsegs = sd->gspca_dev.width / 16;
3400 vsegs = sd->gspca_dev.height / 4;
3401
3402 reg_w(sd, 0x29, hsegs);
3403 reg_w(sd, 0x2a, vsegs);
3404
3405 reg_w(sd, 0x39, hsegs);
3406 reg_w(sd, 0x3a, vsegs);
3407
3408 /* Windows driver does this here; who knows why */
3409 reg_w(sd, 0x2f, 0x80);
3410
Hans de Goedeb282d872009-06-14 19:10:40 -03003411 /******** Set the framerate ********/
3412 sd->clockdiv = 1;
Hans de Goede49809d62009-06-07 12:10:39 -03003413
3414 /* Mode independent, but framerate dependent, regs */
Hans de Goedeb282d872009-06-14 19:10:40 -03003415 /* 0x51: Clock divider; Only works on some cams which use 2 crystals */
3416 reg_w(sd, 0x51, 0x04);
Hans de Goede49809d62009-06-07 12:10:39 -03003417 reg_w(sd, 0x22, 0x18);
3418 reg_w(sd, 0x23, 0xff);
3419
Hans de Goedeb282d872009-06-14 19:10:40 -03003420 if (sd->bridge == BRIDGE_OV518PLUS) {
3421 switch (sd->sensor) {
Hans de Goede859cc472010-01-07 15:42:35 -03003422 case SEN_OV7620AE:
Hans de Goedeb282d872009-06-14 19:10:40 -03003423 if (sd->gspca_dev.width == 320) {
3424 reg_w(sd, 0x20, 0x00);
3425 reg_w(sd, 0x21, 0x19);
3426 } else {
3427 reg_w(sd, 0x20, 0x60);
3428 reg_w(sd, 0x21, 0x1f);
3429 }
3430 break;
Hans de Goede859cc472010-01-07 15:42:35 -03003431 case SEN_OV7620:
3432 reg_w(sd, 0x20, 0x00);
3433 reg_w(sd, 0x21, 0x19);
3434 break;
Hans de Goedeb282d872009-06-14 19:10:40 -03003435 default:
3436 reg_w(sd, 0x21, 0x19);
3437 }
3438 } else
Hans de Goede49809d62009-06-07 12:10:39 -03003439 reg_w(sd, 0x71, 0x17); /* Compression-related? */
3440
3441 /* FIXME: Sensor-specific */
3442 /* Bit 5 is what matters here. Of course, it is "reserved" */
3443 i2c_w(sd, 0x54, 0x23);
3444
3445 reg_w(sd, 0x2f, 0x80);
3446
3447 if (sd->bridge == BRIDGE_OV518PLUS) {
3448 reg_w(sd, 0x24, 0x94);
3449 reg_w(sd, 0x25, 0x90);
3450 ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
3451 ov518_reg_w32(sd, 0xc6, 540, 2); /* 21ch */
3452 ov518_reg_w32(sd, 0xc7, 540, 2); /* 21ch */
3453 ov518_reg_w32(sd, 0xc8, 108, 2); /* 6ch */
3454 ov518_reg_w32(sd, 0xca, 131098, 3); /* 2001ah */
3455 ov518_reg_w32(sd, 0xcb, 532, 2); /* 214h */
3456 ov518_reg_w32(sd, 0xcc, 2400, 2); /* 960h */
3457 ov518_reg_w32(sd, 0xcd, 32, 2); /* 20h */
3458 ov518_reg_w32(sd, 0xce, 608, 2); /* 260h */
3459 } else {
3460 reg_w(sd, 0x24, 0x9f);
3461 reg_w(sd, 0x25, 0x90);
3462 ov518_reg_w32(sd, 0xc4, 400, 2); /* 190h */
3463 ov518_reg_w32(sd, 0xc6, 381, 2); /* 17dh */
3464 ov518_reg_w32(sd, 0xc7, 381, 2); /* 17dh */
3465 ov518_reg_w32(sd, 0xc8, 128, 2); /* 80h */
3466 ov518_reg_w32(sd, 0xca, 183331, 3); /* 2cc23h */
3467 ov518_reg_w32(sd, 0xcb, 746, 2); /* 2eah */
3468 ov518_reg_w32(sd, 0xcc, 1750, 2); /* 6d6h */
3469 ov518_reg_w32(sd, 0xcd, 45, 2); /* 2dh */
3470 ov518_reg_w32(sd, 0xce, 851, 2); /* 353h */
3471 }
3472
3473 reg_w(sd, 0x2f, 0x80);
3474
3475 return 0;
3476}
3477
3478
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003479/* Sets up the OV519 with the given image parameters
3480 *
3481 * OV519 needs a completely different approach, until we can figure out what
3482 * the individual registers do.
3483 *
3484 * Do not put any sensor-specific code in here (including I2C I/O functions)
3485 */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003486static int ov519_mode_init_regs(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003487{
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03003488 static const struct ov_regvals mode_init_519_ov7670[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003489 { 0x5d, 0x03 }, /* Turn off suspend mode */
3490 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
3491 { 0x54, 0x0f }, /* bit2 (jpeg enable) */
3492 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
3493 { 0xa3, 0x18 },
3494 { 0xa4, 0x04 },
3495 { 0xa5, 0x28 },
3496 { 0x37, 0x00 }, /* SetUsbInit */
3497 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
3498 /* Enable both fields, YUV Input, disable defect comp (why?) */
3499 { 0x20, 0x0c },
3500 { 0x21, 0x38 },
3501 { 0x22, 0x1d },
3502 { 0x17, 0x50 }, /* undocumented */
3503 { 0x37, 0x00 }, /* undocumented */
3504 { 0x40, 0xff }, /* I2C timeout counter */
3505 { 0x46, 0x00 }, /* I2C clock prescaler */
3506 { 0x59, 0x04 }, /* new from windrv 090403 */
3507 { 0xff, 0x00 }, /* undocumented */
3508 /* windows reads 0x55 at this point, why? */
3509 };
3510
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03003511 static const struct ov_regvals mode_init_519[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003512 { 0x5d, 0x03 }, /* Turn off suspend mode */
3513 { 0x53, 0x9f }, /* was 9b in 1.65-1.08 */
3514 { 0x54, 0x0f }, /* bit2 (jpeg enable) */
3515 { 0xa2, 0x20 }, /* a2-a5 are undocumented */
3516 { 0xa3, 0x18 },
3517 { 0xa4, 0x04 },
3518 { 0xa5, 0x28 },
3519 { 0x37, 0x00 }, /* SetUsbInit */
3520 { 0x55, 0x02 }, /* 4.096 Mhz audio clock */
3521 /* Enable both fields, YUV Input, disable defect comp (why?) */
3522 { 0x22, 0x1d },
3523 { 0x17, 0x50 }, /* undocumented */
3524 { 0x37, 0x00 }, /* undocumented */
3525 { 0x40, 0xff }, /* I2C timeout counter */
3526 { 0x46, 0x00 }, /* I2C clock prescaler */
3527 { 0x59, 0x04 }, /* new from windrv 090403 */
3528 { 0xff, 0x00 }, /* undocumented */
3529 /* windows reads 0x55 at this point, why? */
3530 };
3531
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003532 /******** Set the mode ********/
3533 if (sd->sensor != SEN_OV7670) {
3534 if (write_regvals(sd, mode_init_519,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03003535 ARRAY_SIZE(mode_init_519)))
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003536 return -EIO;
Hans de Goede035d3a32010-01-09 08:14:43 -03003537 if (sd->sensor == SEN_OV7640 ||
3538 sd->sensor == SEN_OV7648) {
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003539 /* Select 8-bit input mode */
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003540 reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10);
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003541 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003542 } else {
3543 if (write_regvals(sd, mode_init_519_ov7670,
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03003544 ARRAY_SIZE(mode_init_519_ov7670)))
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003545 return -EIO;
3546 }
3547
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003548 reg_w(sd, OV519_R10_H_SIZE, sd->gspca_dev.width >> 4);
3549 reg_w(sd, OV519_R11_V_SIZE, sd->gspca_dev.height >> 3);
Hans de Goede80142ef2009-06-14 06:26:49 -03003550 if (sd->sensor == SEN_OV7670 &&
3551 sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
3552 reg_w(sd, OV519_R12_X_OFFSETL, 0x04);
Hans de Goede035d3a32010-01-09 08:14:43 -03003553 else if (sd->sensor == SEN_OV7648 &&
3554 sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv)
3555 reg_w(sd, OV519_R12_X_OFFSETL, 0x01);
Hans de Goede80142ef2009-06-14 06:26:49 -03003556 else
3557 reg_w(sd, OV519_R12_X_OFFSETL, 0x00);
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003558 reg_w(sd, OV519_R13_X_OFFSETH, 0x00);
3559 reg_w(sd, OV519_R14_Y_OFFSETL, 0x00);
3560 reg_w(sd, OV519_R15_Y_OFFSETH, 0x00);
3561 reg_w(sd, OV519_R16_DIVIDER, 0x00);
3562 reg_w(sd, OV519_R25_FORMAT, 0x03); /* YUV422 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003563 reg_w(sd, 0x26, 0x00); /* Undocumented */
3564
3565 /******** Set the framerate ********/
3566 if (frame_rate > 0)
3567 sd->frame_rate = frame_rate;
3568
3569/* FIXME: These are only valid at the max resolution. */
3570 sd->clockdiv = 0;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003571 switch (sd->sensor) {
3572 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003573 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003574 switch (sd->frame_rate) {
Jean-Francois Moine53e74512008-11-08 06:10:19 -03003575 default:
3576/* case 30: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003577 reg_w(sd, 0xa4, 0x0c);
3578 reg_w(sd, 0x23, 0xff);
3579 break;
3580 case 25:
3581 reg_w(sd, 0xa4, 0x0c);
3582 reg_w(sd, 0x23, 0x1f);
3583 break;
3584 case 20:
3585 reg_w(sd, 0xa4, 0x0c);
3586 reg_w(sd, 0x23, 0x1b);
3587 break;
Jean-Francois Moine53e74512008-11-08 06:10:19 -03003588 case 15:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003589 reg_w(sd, 0xa4, 0x04);
3590 reg_w(sd, 0x23, 0xff);
3591 sd->clockdiv = 1;
3592 break;
3593 case 10:
3594 reg_w(sd, 0xa4, 0x04);
3595 reg_w(sd, 0x23, 0x1f);
3596 sd->clockdiv = 1;
3597 break;
3598 case 5:
3599 reg_w(sd, 0xa4, 0x04);
3600 reg_w(sd, 0x23, 0x1b);
3601 sd->clockdiv = 1;
3602 break;
3603 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003604 break;
3605 case SEN_OV8610:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003606 switch (sd->frame_rate) {
3607 default: /* 15 fps */
3608/* case 15: */
3609 reg_w(sd, 0xa4, 0x06);
3610 reg_w(sd, 0x23, 0xff);
3611 break;
3612 case 10:
3613 reg_w(sd, 0xa4, 0x06);
3614 reg_w(sd, 0x23, 0x1f);
3615 break;
3616 case 5:
3617 reg_w(sd, 0xa4, 0x06);
3618 reg_w(sd, 0x23, 0x1b);
3619 break;
3620 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003621 break;
3622 case SEN_OV7670: /* guesses, based on 7640 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003623 PDEBUG(D_STREAM, "Setting framerate to %d fps",
3624 (sd->frame_rate == 0) ? 15 : sd->frame_rate);
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003625 reg_w(sd, 0xa4, 0x10);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003626 switch (sd->frame_rate) {
3627 case 30:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003628 reg_w(sd, 0x23, 0xff);
3629 break;
3630 case 20:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003631 reg_w(sd, 0x23, 0x1b);
3632 break;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003633 default:
3634/* case 15: */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003635 reg_w(sd, 0x23, 0xff);
3636 sd->clockdiv = 1;
3637 break;
3638 }
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003639 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003640 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003641 return 0;
3642}
3643
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003644static int mode_init_ov_sensor_regs(struct sd *sd)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003645{
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003646 struct gspca_dev *gspca_dev;
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003647 int qvga, xstart, xend, ystart, yend;
3648 __u8 v;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003649
3650 gspca_dev = &sd->gspca_dev;
Hans de Goede124cc9c2009-06-14 05:48:00 -03003651 qvga = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 1;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003652
3653 /******** Mode (VGA/QVGA) and sensor specific regs ********/
3654 switch (sd->sensor) {
Hans de Goede635118d2009-10-11 09:49:03 -03003655 case SEN_OV2610:
3656 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3657 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
3658 i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
3659 i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
3660 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
3661 i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
3662 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
3663 return 0;
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003664 case SEN_OV3610:
Hans de Goede635118d2009-10-11 09:49:03 -03003665 if (qvga) {
3666 xstart = (1040 - gspca_dev->width) / 2 + (0x1f << 4);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003667 ystart = (776 - gspca_dev->height) / 2;
Hans de Goede635118d2009-10-11 09:49:03 -03003668 } else {
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003669 xstart = (2076 - gspca_dev->width) / 2 + (0x10 << 4);
Hans de Goede635118d2009-10-11 09:49:03 -03003670 ystart = (1544 - gspca_dev->height) / 2;
3671 }
3672 xend = xstart + gspca_dev->width;
3673 yend = ystart + gspca_dev->height;
3674 /* Writing to the COMH register resets the other windowing regs
3675 to their default values, so we must do this first. */
3676 i2c_w_mask(sd, 0x12, qvga ? 0x40 : 0x00, 0xf0);
3677 i2c_w_mask(sd, 0x32,
3678 (((xend >> 1) & 7) << 3) | ((xstart >> 1) & 7),
3679 0x3f);
3680 i2c_w_mask(sd, 0x03,
3681 (((yend >> 1) & 3) << 2) | ((ystart >> 1) & 3),
3682 0x0f);
3683 i2c_w(sd, 0x17, xstart >> 4);
3684 i2c_w(sd, 0x18, xend >> 4);
3685 i2c_w(sd, 0x19, ystart >> 3);
3686 i2c_w(sd, 0x1a, yend >> 3);
3687 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003688 case SEN_OV8610:
3689 /* For OV8610 qvga means qsvga */
3690 i2c_w_mask(sd, OV7610_REG_COM_C, qvga ? (1 << 5) : 0, 1 << 5);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003691 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3692 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3693 i2c_w_mask(sd, 0x2d, 0x00, 0x40); /* from windrv 090403 */
3694 i2c_w_mask(sd, 0x28, 0x20, 0x20); /* progressive mode on */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003695 break;
3696 case SEN_OV7610:
3697 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003698 i2c_w(sd, 0x35, qvga?0x1e:0x9e);
3699 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3700 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003701 break;
3702 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03003703 case SEN_OV7620AE:
Hans de Goedeb282d872009-06-14 19:10:40 -03003704 case SEN_OV76BE:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003705 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3706 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
3707 i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a);
3708 i2c_w(sd, 0x25, qvga ? 0x30 : 0x60);
3709 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
Hans de Goedeb282d872009-06-14 19:10:40 -03003710 i2c_w_mask(sd, 0x67, qvga ? 0xb0 : 0x90, 0xf0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003711 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003712 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3713 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3714 if (sd->sensor == SEN_OV76BE)
3715 i2c_w(sd, 0x35, qvga ? 0x1e : 0x9e);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003716 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003717 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003718 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003719 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3720 i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20);
Hans de Goede8d0082f2010-01-09 19:45:44 -03003721 /* Setting this undocumented bit in qvga mode removes a very
3722 annoying vertical shaking of the image */
Hans de Goede035d3a32010-01-09 08:14:43 -03003723 i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40);
Hans de Goede8d0082f2010-01-09 19:45:44 -03003724 /* Unknown */
Hans de Goede035d3a32010-01-09 08:14:43 -03003725 i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0);
Hans de Goede8d0082f2010-01-09 19:45:44 -03003726 /* Allow higher automatic gain (to allow higher framerates) */
Hans de Goede035d3a32010-01-09 08:14:43 -03003727 i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003728 i2c_w_mask(sd, 0x12, 0x04, 0x04); /* AWB: 1 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003729 break;
3730 case SEN_OV7670:
3731 /* set COM7_FMT_VGA or COM7_FMT_QVGA
3732 * do we need to set anything else?
3733 * HSTART etc are set in set_ov_sensor_window itself */
3734 i2c_w_mask(sd, OV7670_REG_COM7,
3735 qvga ? OV7670_COM7_FMT_QVGA : OV7670_COM7_FMT_VGA,
3736 OV7670_COM7_FMT_MASK);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003737 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3738 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_AWB,
3739 OV7670_COM8_AWB);
3740 if (qvga) { /* QVGA from ov7670.c by
3741 * Jonathan Corbet */
3742 xstart = 164;
3743 xend = 28;
3744 ystart = 14;
3745 yend = 494;
3746 } else { /* VGA */
3747 xstart = 158;
3748 xend = 14;
3749 ystart = 10;
3750 yend = 490;
3751 }
3752 /* OV7670 hardware window registers are split across
3753 * multiple locations */
3754 i2c_w(sd, OV7670_REG_HSTART, xstart >> 3);
3755 i2c_w(sd, OV7670_REG_HSTOP, xend >> 3);
3756 v = i2c_r(sd, OV7670_REG_HREF);
3757 v = (v & 0xc0) | ((xend & 0x7) << 3) | (xstart & 0x07);
3758 msleep(10); /* need to sleep between read and write to
3759 * same reg! */
3760 i2c_w(sd, OV7670_REG_HREF, v);
3761
3762 i2c_w(sd, OV7670_REG_VSTART, ystart >> 2);
3763 i2c_w(sd, OV7670_REG_VSTOP, yend >> 2);
3764 v = i2c_r(sd, OV7670_REG_VREF);
3765 v = (v & 0xc0) | ((yend & 0x3) << 2) | (ystart & 0x03);
3766 msleep(10); /* need to sleep between read and write to
3767 * same reg! */
3768 i2c_w(sd, OV7670_REG_VREF, v);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003769 break;
3770 case SEN_OV6620:
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003771 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
3772 i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */
3773 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
3774 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003775 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03003776 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003777 i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20);
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003778 i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003779 break;
3780 default:
3781 return -EINVAL;
3782 }
3783
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003784 /******** Clock programming ********/
Hans de Goedeae49c402009-06-14 19:15:07 -03003785 i2c_w(sd, 0x11, sd->clockdiv);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003786
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003787 return 0;
3788}
3789
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003790static void sethvflip(struct sd *sd)
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003791{
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003792 if (sd->sensor != SEN_OV7670)
3793 return;
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003794 if (sd->gspca_dev.streaming)
3795 ov51x_stop(sd);
3796 i2c_w_mask(sd, OV7670_REG_MVFP,
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003797 OV7670_MVFP_MIRROR * sd->hflip
3798 | OV7670_MVFP_VFLIP * sd->vflip,
3799 OV7670_MVFP_MIRROR | OV7670_MVFP_VFLIP);
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003800 if (sd->gspca_dev.streaming)
3801 ov51x_restart(sd);
3802}
3803
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003804static int set_ov_sensor_window(struct sd *sd)
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03003805{
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003806 struct gspca_dev *gspca_dev;
Hans de Goede124cc9c2009-06-14 05:48:00 -03003807 int qvga, crop;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003808 int hwsbase, hwebase, vwsbase, vwebase, hwscale, vwscale;
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003809 int ret;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003810
Hans de Goede635118d2009-10-11 09:49:03 -03003811 /* mode setup is fully handled in mode_init_ov_sensor_regs for these */
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003812 if (sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610 ||
3813 sd->sensor == SEN_OV7670)
Hans de Goede635118d2009-10-11 09:49:03 -03003814 return mode_init_ov_sensor_regs(sd);
3815
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003816 gspca_dev = &sd->gspca_dev;
Hans de Goede124cc9c2009-06-14 05:48:00 -03003817 qvga = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 1;
3818 crop = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv & 2;
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003819
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003820 /* The different sensor ICs handle setting up of window differently.
3821 * IF YOU SET IT WRONG, YOU WILL GET ALL ZERO ISOC DATA FROM OV51x!! */
3822 switch (sd->sensor) {
3823 case SEN_OV8610:
3824 hwsbase = 0x1e;
3825 hwebase = 0x1e;
3826 vwsbase = 0x02;
3827 vwebase = 0x02;
3828 break;
3829 case SEN_OV7610:
3830 case SEN_OV76BE:
3831 hwsbase = 0x38;
3832 hwebase = 0x3a;
3833 vwsbase = vwebase = 0x05;
3834 break;
3835 case SEN_OV6620:
3836 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03003837 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003838 hwsbase = 0x38;
3839 hwebase = 0x3a;
3840 vwsbase = 0x05;
3841 vwebase = 0x06;
Hans de Goede7d971372009-06-14 05:28:17 -03003842 if (sd->sensor == SEN_OV66308AF && qvga)
Hans de Goede49809d62009-06-07 12:10:39 -03003843 /* HDG: this fixes U and V getting swapped */
Hans de Goede7d971372009-06-14 05:28:17 -03003844 hwsbase++;
Hans de Goede124cc9c2009-06-14 05:48:00 -03003845 if (crop) {
3846 hwsbase += 8;
3847 hwebase += 8;
3848 vwsbase += 11;
3849 vwebase += 11;
3850 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003851 break;
3852 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03003853 case SEN_OV7620AE:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003854 hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */
3855 hwebase = 0x2f;
3856 vwsbase = vwebase = 0x05;
3857 break;
3858 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03003859 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003860 hwsbase = 0x1a;
3861 hwebase = 0x1a;
3862 vwsbase = vwebase = 0x03;
3863 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003864 default:
3865 return -EINVAL;
3866 }
3867
3868 switch (sd->sensor) {
3869 case SEN_OV6620:
3870 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03003871 case SEN_OV66308AF:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003872 if (qvga) { /* QCIF */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003873 hwscale = 0;
3874 vwscale = 0;
3875 } else { /* CIF */
3876 hwscale = 1;
3877 vwscale = 1; /* The datasheet says 0;
3878 * it's wrong */
3879 }
3880 break;
3881 case SEN_OV8610:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003882 if (qvga) { /* QSVGA */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003883 hwscale = 1;
3884 vwscale = 1;
3885 } else { /* SVGA */
3886 hwscale = 2;
3887 vwscale = 2;
3888 }
3889 break;
3890 default: /* SEN_OV7xx0 */
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003891 if (qvga) { /* QVGA */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003892 hwscale = 1;
3893 vwscale = 0;
3894 } else { /* VGA */
3895 hwscale = 2;
3896 vwscale = 1;
3897 }
3898 }
3899
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003900 ret = mode_init_ov_sensor_regs(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003901 if (ret < 0)
3902 return ret;
3903
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003904 i2c_w(sd, 0x17, hwsbase);
Hans de Goedea511ba92009-10-16 07:13:07 -03003905 i2c_w(sd, 0x18, hwebase + (sd->sensor_width >> hwscale));
Hans de Goedeebbb5c32009-10-12 11:32:44 -03003906 i2c_w(sd, 0x19, vwsbase);
Hans de Goedea511ba92009-10-16 07:13:07 -03003907 i2c_w(sd, 0x1a, vwebase + (sd->sensor_height >> vwscale));
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003908
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003909 return 0;
3910}
3911
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003912/* -- start the camera -- */
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03003913static int sd_start(struct gspca_dev *gspca_dev)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003914{
3915 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede49809d62009-06-07 12:10:39 -03003916 int ret = 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003917
Hans de Goedea511ba92009-10-16 07:13:07 -03003918 /* Default for most bridges, allow bridge_mode_init_regs to override */
3919 sd->sensor_width = sd->gspca_dev.width;
3920 sd->sensor_height = sd->gspca_dev.height;
3921
Hans de Goede49809d62009-06-07 12:10:39 -03003922 switch (sd->bridge) {
Hans de Goede1876bb92009-06-14 06:45:50 -03003923 case BRIDGE_OV511:
3924 case BRIDGE_OV511PLUS:
3925 ret = ov511_mode_init_regs(sd);
3926 break;
Hans de Goede49809d62009-06-07 12:10:39 -03003927 case BRIDGE_OV518:
3928 case BRIDGE_OV518PLUS:
3929 ret = ov518_mode_init_regs(sd);
3930 break;
3931 case BRIDGE_OV519:
3932 ret = ov519_mode_init_regs(sd);
3933 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03003934 /* case BRIDGE_OVFX2: nothing to do */
Hans de Goedea511ba92009-10-16 07:13:07 -03003935 case BRIDGE_W9968CF:
3936 ret = w9968cf_mode_init_regs(sd);
3937 break;
Hans de Goede49809d62009-06-07 12:10:39 -03003938 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003939 if (ret < 0)
3940 goto out;
Hans de Goede49809d62009-06-07 12:10:39 -03003941
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003942 ret = set_ov_sensor_window(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003943 if (ret < 0)
3944 goto out;
3945
Hans de Goede49809d62009-06-07 12:10:39 -03003946 setcontrast(gspca_dev);
3947 setbrightness(gspca_dev);
3948 setcolors(gspca_dev);
Hans de Goede02ab18b2009-06-14 04:32:04 -03003949 sethvflip(sd);
3950 setautobrightness(sd);
3951 setfreq(sd);
Hans de Goede49809d62009-06-07 12:10:39 -03003952
Hans de Goede417a4d22010-02-19 07:37:08 -03003953 /* Force clear snapshot state in case the snapshot button was
3954 pressed while we weren't streaming */
3955 sd->snapshot_needs_reset = 1;
3956 sd_reset_snapshot(gspca_dev);
3957 sd->snapshot_pressed = 0;
3958
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03003959 ret = ov51x_restart(sd);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003960 if (ret < 0)
3961 goto out;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003962 ov51x_led_control(sd, 1);
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03003963 return 0;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003964out:
3965 PDEBUG(D_ERR, "camera start error:%d", ret);
Jean-Francois Moine72ab97c2008-09-20 06:39:08 -03003966 return ret;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003967}
3968
3969static void sd_stopN(struct gspca_dev *gspca_dev)
3970{
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03003971 struct sd *sd = (struct sd *) gspca_dev;
3972
3973 ov51x_stop(sd);
3974 ov51x_led_control(sd, 0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03003975}
3976
Hans de Goede79b35902009-10-19 06:08:01 -03003977static void sd_stop0(struct gspca_dev *gspca_dev)
3978{
3979 struct sd *sd = (struct sd *) gspca_dev;
3980
3981 if (sd->bridge == BRIDGE_W9968CF)
3982 w9968cf_stop0(sd);
3983}
3984
Hans de Goede92e232a2010-02-20 04:30:45 -03003985static void ov51x_handle_button(struct gspca_dev *gspca_dev, u8 state)
3986{
3987 struct sd *sd = (struct sd *) gspca_dev;
3988
3989 if (sd->snapshot_pressed != state) {
3990#ifdef CONFIG_INPUT
3991 input_report_key(gspca_dev->input_dev, KEY_CAMERA, state);
3992 input_sync(gspca_dev->input_dev);
3993#endif
3994 if (state)
3995 sd->snapshot_needs_reset = 1;
3996
3997 sd->snapshot_pressed = state;
3998 } else {
3999 /* On the ov519 we need to reset the button state multiple
4000 times, as resetting does not work as long as the button
4001 stays pressed */
4002 if (sd->bridge == BRIDGE_OV519 && state)
4003 sd->snapshot_needs_reset = 1;
4004 }
4005}
4006
Hans de Goede1876bb92009-06-14 06:45:50 -03004007static void ov511_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004008 u8 *in, /* isoc packet */
4009 int len) /* iso packet length */
Hans de Goede1876bb92009-06-14 06:45:50 -03004010{
4011 struct sd *sd = (struct sd *) gspca_dev;
4012
4013 /* SOF/EOF packets have 1st to 8th bytes zeroed and the 9th
4014 * byte non-zero. The EOF packet has image width/height in the
4015 * 10th and 11th bytes. The 9th byte is given as follows:
4016 *
4017 * bit 7: EOF
4018 * 6: compression enabled
4019 * 5: 422/420/400 modes
4020 * 4: 422/420/400 modes
4021 * 3: 1
4022 * 2: snapshot button on
4023 * 1: snapshot frame
4024 * 0: even/odd field
4025 */
4026 if (!(in[0] | in[1] | in[2] | in[3] | in[4] | in[5] | in[6] | in[7]) &&
4027 (in[8] & 0x08)) {
4028 if (in[8] & 0x80) {
4029 /* Frame end */
4030 if ((in[9] + 1) * 8 != gspca_dev->width ||
4031 (in[10] + 1) * 8 != gspca_dev->height) {
4032 PDEBUG(D_ERR, "Invalid frame size, got: %dx%d,"
4033 " requested: %dx%d\n",
4034 (in[9] + 1) * 8, (in[10] + 1) * 8,
4035 gspca_dev->width, gspca_dev->height);
4036 gspca_dev->last_packet_type = DISCARD_PACKET;
4037 return;
4038 }
4039 /* Add 11 byte footer to frame, might be usefull */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004040 gspca_frame_add(gspca_dev, LAST_PACKET, in, 11);
Hans de Goede1876bb92009-06-14 06:45:50 -03004041 return;
4042 } else {
4043 /* Frame start */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004044 gspca_frame_add(gspca_dev, FIRST_PACKET, in, 0);
Hans de Goede1876bb92009-06-14 06:45:50 -03004045 sd->packet_nr = 0;
4046 }
4047 }
4048
4049 /* Ignore the packet number */
4050 len--;
4051
4052 /* intermediate packet */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004053 gspca_frame_add(gspca_dev, INTER_PACKET, in, len);
Hans de Goede1876bb92009-06-14 06:45:50 -03004054}
4055
Hans de Goede49809d62009-06-07 12:10:39 -03004056static void ov518_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004057 u8 *data, /* isoc packet */
Hans de Goede49809d62009-06-07 12:10:39 -03004058 int len) /* iso packet length */
4059{
Hans de Goede92918a52009-06-14 06:21:35 -03004060 struct sd *sd = (struct sd *) gspca_dev;
Hans de Goede49809d62009-06-07 12:10:39 -03004061
4062 /* A false positive here is likely, until OVT gives me
4063 * the definitive SOF/EOF format */
4064 if ((!(data[0] | data[1] | data[2] | data[3] | data[5])) && data[6]) {
Hans de Goede92e232a2010-02-20 04:30:45 -03004065 ov51x_handle_button(gspca_dev, (data[6] >> 1) & 1);
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004066 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
4067 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
Hans de Goede92918a52009-06-14 06:21:35 -03004068 sd->packet_nr = 0;
4069 }
4070
4071 if (gspca_dev->last_packet_type == DISCARD_PACKET)
4072 return;
4073
4074 /* Does this device use packet numbers ? */
4075 if (len & 7) {
4076 len--;
4077 if (sd->packet_nr == data[len])
4078 sd->packet_nr++;
4079 /* The last few packets of the frame (which are all 0's
4080 except that they may contain part of the footer), are
4081 numbered 0 */
4082 else if (sd->packet_nr == 0 || data[len]) {
4083 PDEBUG(D_ERR, "Invalid packet nr: %d (expect: %d)",
4084 (int)data[len], (int)sd->packet_nr);
4085 gspca_dev->last_packet_type = DISCARD_PACKET;
4086 return;
4087 }
Hans de Goede49809d62009-06-07 12:10:39 -03004088 }
4089
4090 /* intermediate packet */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004091 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03004092}
4093
4094static void ov519_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004095 u8 *data, /* isoc packet */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004096 int len) /* iso packet length */
4097{
4098 /* Header of ov519 is 16 bytes:
4099 * Byte Value Description
4100 * 0 0xff magic
4101 * 1 0xff magic
4102 * 2 0xff magic
4103 * 3 0xXX 0x50 = SOF, 0x51 = EOF
4104 * 9 0xXX 0x01 initial frame without data,
4105 * 0x00 standard frame with image
4106 * 14 Lo in EOF: length of image data / 8
4107 * 15 Hi
4108 */
4109
4110 if (data[0] == 0xff && data[1] == 0xff && data[2] == 0xff) {
4111 switch (data[3]) {
4112 case 0x50: /* start of frame */
Hans de Goede417a4d22010-02-19 07:37:08 -03004113 /* Don't check the button state here, as the state
4114 usually (always ?) changes at EOF and checking it
4115 here leads to unnecessary snapshot state resets. */
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004116#define HDRSZ 16
4117 data += HDRSZ;
4118 len -= HDRSZ;
4119#undef HDRSZ
4120 if (data[0] == 0xff || data[1] == 0xd8)
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004121 gspca_frame_add(gspca_dev, FIRST_PACKET,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004122 data, len);
4123 else
4124 gspca_dev->last_packet_type = DISCARD_PACKET;
4125 return;
4126 case 0x51: /* end of frame */
Hans de Goede92e232a2010-02-20 04:30:45 -03004127 ov51x_handle_button(gspca_dev, data[11] & 1);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004128 if (data[9] != 0)
4129 gspca_dev->last_packet_type = DISCARD_PACKET;
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004130 gspca_frame_add(gspca_dev, LAST_PACKET,
4131 NULL, 0);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004132 return;
4133 }
4134 }
4135
4136 /* intermediate packet */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004137 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004138}
4139
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004140static void ovfx2_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004141 u8 *data, /* isoc packet */
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004142 int len) /* iso packet length */
4143{
4144 /* A short read signals EOF */
4145 if (len < OVFX2_BULK_SIZE) {
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004146 gspca_frame_add(gspca_dev, LAST_PACKET, data, len);
4147 gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004148 return;
4149 }
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004150 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004151}
4152
Hans de Goede49809d62009-06-07 12:10:39 -03004153static void sd_pkt_scan(struct gspca_dev *gspca_dev,
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004154 u8 *data, /* isoc packet */
Hans de Goede49809d62009-06-07 12:10:39 -03004155 int len) /* iso packet length */
4156{
4157 struct sd *sd = (struct sd *) gspca_dev;
4158
4159 switch (sd->bridge) {
4160 case BRIDGE_OV511:
4161 case BRIDGE_OV511PLUS:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004162 ov511_pkt_scan(gspca_dev, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03004163 break;
4164 case BRIDGE_OV518:
4165 case BRIDGE_OV518PLUS:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004166 ov518_pkt_scan(gspca_dev, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03004167 break;
4168 case BRIDGE_OV519:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004169 ov519_pkt_scan(gspca_dev, data, len);
Hans de Goede49809d62009-06-07 12:10:39 -03004170 break;
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004171 case BRIDGE_OVFX2:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004172 ovfx2_pkt_scan(gspca_dev, data, len);
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004173 break;
Hans de Goedea511ba92009-10-16 07:13:07 -03004174 case BRIDGE_W9968CF:
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03004175 w9968cf_pkt_scan(gspca_dev, data, len);
Hans de Goedea511ba92009-10-16 07:13:07 -03004176 break;
Hans de Goede49809d62009-06-07 12:10:39 -03004177 }
4178}
4179
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004180/* -- management routines -- */
4181
4182static void setbrightness(struct gspca_dev *gspca_dev)
4183{
4184 struct sd *sd = (struct sd *) gspca_dev;
4185 int val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004186
4187 val = sd->brightness;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004188 switch (sd->sensor) {
4189 case SEN_OV8610:
4190 case SEN_OV7610:
4191 case SEN_OV76BE:
4192 case SEN_OV6620:
4193 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03004194 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004195 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03004196 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004197 i2c_w(sd, OV7610_REG_BRT, val);
4198 break;
4199 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03004200 case SEN_OV7620AE:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004201 /* 7620 doesn't like manual changes when in auto mode */
Hans de Goede02ab18b2009-06-14 04:32:04 -03004202 if (!sd->autobrightness)
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004203 i2c_w(sd, OV7610_REG_BRT, val);
4204 break;
4205 case SEN_OV7670:
Jean-Francois Moine594f5b82008-08-01 06:37:51 -03004206/*win trace
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004207 * i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_AEC); */
4208 i2c_w(sd, OV7670_REG_BRIGHT, ov7670_abs_to_sm(val));
4209 break;
4210 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004211}
4212
4213static void setcontrast(struct gspca_dev *gspca_dev)
4214{
4215 struct sd *sd = (struct sd *) gspca_dev;
4216 int val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004217
4218 val = sd->contrast;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004219 switch (sd->sensor) {
4220 case SEN_OV7610:
4221 case SEN_OV6620:
4222 i2c_w(sd, OV7610_REG_CNT, val);
4223 break;
4224 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03004225 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004226 i2c_w_mask(sd, OV7610_REG_CNT, val >> 4, 0x0f);
Hans de Goede49809d62009-06-07 12:10:39 -03004227 break;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004228 case SEN_OV8610: {
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03004229 static const __u8 ctab[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004230 0x03, 0x09, 0x0b, 0x0f, 0x53, 0x6f, 0x35, 0x7f
4231 };
4232
4233 /* Use Y gamma control instead. Bit 0 enables it. */
4234 i2c_w(sd, 0x64, ctab[val >> 5]);
4235 break;
4236 }
Hans de Goede859cc472010-01-07 15:42:35 -03004237 case SEN_OV7620:
4238 case SEN_OV7620AE: {
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03004239 static const __u8 ctab[] = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004240 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57,
4241 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff
4242 };
4243
4244 /* Use Y gamma control instead. Bit 0 enables it. */
4245 i2c_w(sd, 0x64, ctab[val >> 4]);
4246 break;
4247 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004248 case SEN_OV7670:
4249 /* check that this isn't just the same as ov7610 */
4250 i2c_w(sd, OV7670_REG_CONTRAS, val >> 1);
4251 break;
4252 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004253}
4254
4255static void setcolors(struct gspca_dev *gspca_dev)
4256{
4257 struct sd *sd = (struct sd *) gspca_dev;
4258 int val;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004259
4260 val = sd->colors;
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004261 switch (sd->sensor) {
4262 case SEN_OV8610:
4263 case SEN_OV7610:
4264 case SEN_OV76BE:
4265 case SEN_OV6620:
4266 case SEN_OV6630:
Hans de Goede7d971372009-06-14 05:28:17 -03004267 case SEN_OV66308AF:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004268 i2c_w(sd, OV7610_REG_SAT, val);
4269 break;
4270 case SEN_OV7620:
Hans de Goede859cc472010-01-07 15:42:35 -03004271 case SEN_OV7620AE:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004272 /* Use UV gamma control instead. Bits 0 & 7 are reserved. */
4273/* rc = ov_i2c_write(sd->dev, 0x62, (val >> 9) & 0x7e);
4274 if (rc < 0)
4275 goto out; */
4276 i2c_w(sd, OV7610_REG_SAT, val);
4277 break;
4278 case SEN_OV7640:
Hans de Goede035d3a32010-01-09 08:14:43 -03004279 case SEN_OV7648:
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004280 i2c_w(sd, OV7610_REG_SAT, val & 0xf0);
4281 break;
4282 case SEN_OV7670:
4283 /* supported later once I work out how to do it
4284 * transparently fail now! */
4285 /* set REG_COM13 values for UV sat auto mode */
4286 break;
4287 }
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004288}
4289
Hans de Goede02ab18b2009-06-14 04:32:04 -03004290static void setautobrightness(struct sd *sd)
4291{
Hans de Goede035d3a32010-01-09 08:14:43 -03004292 if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7648 ||
4293 sd->sensor == SEN_OV7670 ||
Hans de Goede635118d2009-10-11 09:49:03 -03004294 sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610)
Hans de Goede02ab18b2009-06-14 04:32:04 -03004295 return;
4296
4297 i2c_w_mask(sd, 0x2d, sd->autobrightness ? 0x10 : 0x00, 0x10);
4298}
4299
4300static void setfreq(struct sd *sd)
4301{
Hans de Goede635118d2009-10-11 09:49:03 -03004302 if (sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610)
4303 return;
4304
Hans de Goede02ab18b2009-06-14 04:32:04 -03004305 if (sd->sensor == SEN_OV7670) {
4306 switch (sd->freq) {
4307 case 0: /* Banding filter disabled */
4308 i2c_w_mask(sd, OV7670_REG_COM8, 0, OV7670_COM8_BFILT);
4309 break;
4310 case 1: /* 50 hz */
4311 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT,
4312 OV7670_COM8_BFILT);
4313 i2c_w_mask(sd, OV7670_REG_COM11, 0x08, 0x18);
4314 break;
4315 case 2: /* 60 hz */
4316 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT,
4317 OV7670_COM8_BFILT);
4318 i2c_w_mask(sd, OV7670_REG_COM11, 0x00, 0x18);
4319 break;
4320 case 3: /* Auto hz */
4321 i2c_w_mask(sd, OV7670_REG_COM8, OV7670_COM8_BFILT,
4322 OV7670_COM8_BFILT);
4323 i2c_w_mask(sd, OV7670_REG_COM11, OV7670_COM11_HZAUTO,
4324 0x18);
4325 break;
4326 }
4327 } else {
4328 switch (sd->freq) {
4329 case 0: /* Banding filter disabled */
4330 i2c_w_mask(sd, 0x2d, 0x00, 0x04);
4331 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
4332 break;
4333 case 1: /* 50 hz (filter on and framerate adj) */
4334 i2c_w_mask(sd, 0x2d, 0x04, 0x04);
4335 i2c_w_mask(sd, 0x2a, 0x80, 0x80);
4336 /* 20 fps -> 16.667 fps */
4337 if (sd->sensor == SEN_OV6620 ||
Hans de Goede7d971372009-06-14 05:28:17 -03004338 sd->sensor == SEN_OV6630 ||
4339 sd->sensor == SEN_OV66308AF)
Hans de Goede02ab18b2009-06-14 04:32:04 -03004340 i2c_w(sd, 0x2b, 0x5e);
4341 else
4342 i2c_w(sd, 0x2b, 0xac);
4343 break;
4344 case 2: /* 60 hz (filter on, ...) */
4345 i2c_w_mask(sd, 0x2d, 0x04, 0x04);
4346 if (sd->sensor == SEN_OV6620 ||
Hans de Goede7d971372009-06-14 05:28:17 -03004347 sd->sensor == SEN_OV6630 ||
4348 sd->sensor == SEN_OV66308AF) {
Hans de Goede02ab18b2009-06-14 04:32:04 -03004349 /* 20 fps -> 15 fps */
4350 i2c_w_mask(sd, 0x2a, 0x80, 0x80);
4351 i2c_w(sd, 0x2b, 0xa8);
4352 } else {
4353 /* no framerate adj. */
4354 i2c_w_mask(sd, 0x2a, 0x00, 0x80);
4355 }
4356 break;
4357 }
4358 }
4359}
4360
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004361static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
4362{
4363 struct sd *sd = (struct sd *) gspca_dev;
4364
4365 sd->brightness = val;
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03004366 if (gspca_dev->streaming)
4367 setbrightness(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004368 return 0;
4369}
4370
4371static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
4372{
4373 struct sd *sd = (struct sd *) gspca_dev;
4374
4375 *val = sd->brightness;
4376 return 0;
4377}
4378
4379static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
4380{
4381 struct sd *sd = (struct sd *) gspca_dev;
4382
4383 sd->contrast = val;
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03004384 if (gspca_dev->streaming)
4385 setcontrast(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004386 return 0;
4387}
4388
4389static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
4390{
4391 struct sd *sd = (struct sd *) gspca_dev;
4392
4393 *val = sd->contrast;
4394 return 0;
4395}
4396
4397static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val)
4398{
4399 struct sd *sd = (struct sd *) gspca_dev;
4400
4401 sd->colors = val;
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03004402 if (gspca_dev->streaming)
4403 setcolors(gspca_dev);
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004404 return 0;
4405}
4406
4407static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val)
4408{
4409 struct sd *sd = (struct sd *) gspca_dev;
4410
4411 *val = sd->colors;
4412 return 0;
4413}
4414
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03004415static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
4416{
4417 struct sd *sd = (struct sd *) gspca_dev;
4418
4419 sd->hflip = val;
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03004420 if (gspca_dev->streaming)
4421 sethvflip(sd);
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03004422 return 0;
4423}
4424
4425static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
4426{
4427 struct sd *sd = (struct sd *) gspca_dev;
4428
4429 *val = sd->hflip;
4430 return 0;
4431}
4432
4433static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
4434{
4435 struct sd *sd = (struct sd *) gspca_dev;
4436
4437 sd->vflip = val;
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03004438 if (gspca_dev->streaming)
4439 sethvflip(sd);
Jean-Francois Moine0cd67592008-07-29 05:25:28 -03004440 return 0;
4441}
4442
4443static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
4444{
4445 struct sd *sd = (struct sd *) gspca_dev;
4446
4447 *val = sd->vflip;
4448 return 0;
4449}
4450
Hans de Goede02ab18b2009-06-14 04:32:04 -03004451static int sd_setautobrightness(struct gspca_dev *gspca_dev, __s32 val)
4452{
4453 struct sd *sd = (struct sd *) gspca_dev;
4454
4455 sd->autobrightness = val;
4456 if (gspca_dev->streaming)
4457 setautobrightness(sd);
4458 return 0;
4459}
4460
4461static int sd_getautobrightness(struct gspca_dev *gspca_dev, __s32 *val)
4462{
4463 struct sd *sd = (struct sd *) gspca_dev;
4464
4465 *val = sd->autobrightness;
4466 return 0;
4467}
4468
4469static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
4470{
4471 struct sd *sd = (struct sd *) gspca_dev;
4472
4473 sd->freq = val;
Hans de Goedea511ba92009-10-16 07:13:07 -03004474 if (gspca_dev->streaming) {
Hans de Goede02ab18b2009-06-14 04:32:04 -03004475 setfreq(sd);
Hans de Goedea511ba92009-10-16 07:13:07 -03004476 /* Ugly but necessary */
4477 if (sd->bridge == BRIDGE_W9968CF)
4478 w9968cf_set_crop_window(sd);
4479 }
Hans de Goede02ab18b2009-06-14 04:32:04 -03004480 return 0;
4481}
4482
4483static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
4484{
4485 struct sd *sd = (struct sd *) gspca_dev;
4486
4487 *val = sd->freq;
4488 return 0;
4489}
4490
4491static int sd_querymenu(struct gspca_dev *gspca_dev,
4492 struct v4l2_querymenu *menu)
4493{
4494 struct sd *sd = (struct sd *) gspca_dev;
4495
4496 switch (menu->id) {
4497 case V4L2_CID_POWER_LINE_FREQUENCY:
4498 switch (menu->index) {
4499 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
4500 strcpy((char *) menu->name, "NoFliker");
4501 return 0;
4502 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
4503 strcpy((char *) menu->name, "50 Hz");
4504 return 0;
4505 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
4506 strcpy((char *) menu->name, "60 Hz");
4507 return 0;
4508 case 3:
4509 if (sd->sensor != SEN_OV7670)
4510 return -EINVAL;
4511
4512 strcpy((char *) menu->name, "Automatic");
4513 return 0;
4514 }
4515 break;
4516 }
4517 return -EINVAL;
4518}
4519
Hans de Goede79b35902009-10-19 06:08:01 -03004520static int sd_get_jcomp(struct gspca_dev *gspca_dev,
4521 struct v4l2_jpegcompression *jcomp)
4522{
4523 struct sd *sd = (struct sd *) gspca_dev;
4524
4525 if (sd->bridge != BRIDGE_W9968CF)
4526 return -EINVAL;
4527
4528 memset(jcomp, 0, sizeof *jcomp);
4529 jcomp->quality = sd->quality;
4530 jcomp->jpeg_markers = V4L2_JPEG_MARKER_DHT | V4L2_JPEG_MARKER_DQT |
4531 V4L2_JPEG_MARKER_DRI;
4532 return 0;
4533}
4534
4535static int sd_set_jcomp(struct gspca_dev *gspca_dev,
4536 struct v4l2_jpegcompression *jcomp)
4537{
4538 struct sd *sd = (struct sd *) gspca_dev;
4539
4540 if (sd->bridge != BRIDGE_W9968CF)
4541 return -EINVAL;
4542
4543 if (gspca_dev->streaming)
4544 return -EBUSY;
4545
4546 if (jcomp->quality < QUALITY_MIN)
4547 sd->quality = QUALITY_MIN;
4548 else if (jcomp->quality > QUALITY_MAX)
4549 sd->quality = QUALITY_MAX;
4550 else
4551 sd->quality = jcomp->quality;
4552
4553 /* Return resulting jcomp params to app */
4554 sd_get_jcomp(gspca_dev, jcomp);
4555
4556 return 0;
4557}
4558
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004559/* sub-driver description */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03004560static const struct sd_desc sd_desc = {
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004561 .name = MODULE_NAME,
4562 .ctrls = sd_ctrls,
4563 .nctrls = ARRAY_SIZE(sd_ctrls),
4564 .config = sd_config,
Jean-Francois Moine012d6b02008-09-03 17:12:16 -03004565 .init = sd_init,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004566 .start = sd_start,
4567 .stopN = sd_stopN,
Hans de Goede79b35902009-10-19 06:08:01 -03004568 .stop0 = sd_stop0,
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004569 .pkt_scan = sd_pkt_scan,
Hans de Goede417a4d22010-02-19 07:37:08 -03004570 .dq_callback = sd_reset_snapshot,
Hans de Goede02ab18b2009-06-14 04:32:04 -03004571 .querymenu = sd_querymenu,
Hans de Goede79b35902009-10-19 06:08:01 -03004572 .get_jcomp = sd_get_jcomp,
4573 .set_jcomp = sd_set_jcomp,
Hans de Goede417a4d22010-02-19 07:37:08 -03004574#ifdef CONFIG_INPUT
4575 .other_input = 1,
4576#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004577};
4578
4579/* -- module initialisation -- */
Jean-Francois Moinea5ae2062008-07-04 11:16:16 -03004580static const __devinitdata struct usb_device_id device_table[] = {
Hans de Goedea511ba92009-10-16 07:13:07 -03004581 {USB_DEVICE(0x041e, 0x4003), .driver_info = BRIDGE_W9968CF },
Hans de Goede49809d62009-06-07 12:10:39 -03004582 {USB_DEVICE(0x041e, 0x4052), .driver_info = BRIDGE_OV519 },
4583 {USB_DEVICE(0x041e, 0x405f), .driver_info = BRIDGE_OV519 },
4584 {USB_DEVICE(0x041e, 0x4060), .driver_info = BRIDGE_OV519 },
4585 {USB_DEVICE(0x041e, 0x4061), .driver_info = BRIDGE_OV519 },
Hans de Goede9e4d8252009-06-14 06:25:06 -03004586 {USB_DEVICE(0x041e, 0x4064),
4587 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
Rafal Milecki518c8df2009-10-02 03:54:44 -03004588 {USB_DEVICE(0x041e, 0x4067), .driver_info = BRIDGE_OV519 },
Hans de Goede9e4d8252009-06-14 06:25:06 -03004589 {USB_DEVICE(0x041e, 0x4068),
4590 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
Hans de Goede49809d62009-06-07 12:10:39 -03004591 {USB_DEVICE(0x045e, 0x028c), .driver_info = BRIDGE_OV519 },
4592 {USB_DEVICE(0x054c, 0x0154), .driver_info = BRIDGE_OV519 },
Hans de Goede98184f72010-01-07 12:06:00 -03004593 {USB_DEVICE(0x054c, 0x0155),
4594 .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED },
Hans de Goede1876bb92009-06-14 06:45:50 -03004595 {USB_DEVICE(0x05a9, 0x0511), .driver_info = BRIDGE_OV511 },
Hans de Goede49809d62009-06-07 12:10:39 -03004596 {USB_DEVICE(0x05a9, 0x0518), .driver_info = BRIDGE_OV518 },
4597 {USB_DEVICE(0x05a9, 0x0519), .driver_info = BRIDGE_OV519 },
4598 {USB_DEVICE(0x05a9, 0x0530), .driver_info = BRIDGE_OV519 },
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004599 {USB_DEVICE(0x05a9, 0x2800), .driver_info = BRIDGE_OVFX2 },
Hans de Goede49809d62009-06-07 12:10:39 -03004600 {USB_DEVICE(0x05a9, 0x4519), .driver_info = BRIDGE_OV519 },
4601 {USB_DEVICE(0x05a9, 0x8519), .driver_info = BRIDGE_OV519 },
Hans de Goede1876bb92009-06-14 06:45:50 -03004602 {USB_DEVICE(0x05a9, 0xa511), .driver_info = BRIDGE_OV511PLUS },
Hans de Goede49809d62009-06-07 12:10:39 -03004603 {USB_DEVICE(0x05a9, 0xa518), .driver_info = BRIDGE_OV518PLUS },
Hans de Goede1876bb92009-06-14 06:45:50 -03004604 {USB_DEVICE(0x0813, 0x0002), .driver_info = BRIDGE_OV511PLUS },
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004605 {USB_DEVICE(0x0b62, 0x0059), .driver_info = BRIDGE_OVFX2 },
4606 {USB_DEVICE(0x0e96, 0xc001), .driver_info = BRIDGE_OVFX2 },
Hans de Goedea511ba92009-10-16 07:13:07 -03004607 {USB_DEVICE(0x1046, 0x9967), .driver_info = BRIDGE_W9968CF },
Hans de Goedeb46aaa02009-10-12 10:07:57 -03004608 {USB_DEVICE(0x8020, 0xEF04), .driver_info = BRIDGE_OVFX2 },
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004609 {}
4610};
Jean-Francois Moineac40b1f2008-11-08 06:03:37 -03004611
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004612MODULE_DEVICE_TABLE(usb, device_table);
4613
4614/* -- device connect -- */
4615static int sd_probe(struct usb_interface *intf,
4616 const struct usb_device_id *id)
4617{
4618 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
4619 THIS_MODULE);
4620}
4621
4622static struct usb_driver sd_driver = {
4623 .name = MODULE_NAME,
4624 .id_table = device_table,
4625 .probe = sd_probe,
4626 .disconnect = gspca_disconnect,
Jean-Francois Moine6a709742008-09-03 16:48:10 -03004627#ifdef CONFIG_PM
4628 .suspend = gspca_suspend,
4629 .resume = gspca_resume,
4630#endif
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004631};
4632
4633/* -- module insert / remove -- */
4634static int __init sd_mod_init(void)
4635{
Alexey Klimovf69e9522009-01-01 13:02:07 -03004636 int ret;
4637 ret = usb_register(&sd_driver);
4638 if (ret < 0)
Alexey Klimove6b14842009-01-01 13:04:58 -03004639 return ret;
Jean-Francois Moine10b0e962008-07-22 05:35:10 -03004640 PDEBUG(D_PROBE, "registered");
Jean-Francois Moine6a7eba22008-06-30 15:50:11 -03004641 return 0;
4642}
4643static void __exit sd_mod_exit(void)
4644{
4645 usb_deregister(&sd_driver);
4646 PDEBUG(D_PROBE, "deregistered");
4647}
4648
4649module_init(sd_mod_init);
4650module_exit(sd_mod_exit);
4651
4652module_param(frame_rate, int, 0644);
4653MODULE_PARM_DESC(frame_rate, "Frame rate (5, 10, 15, 20 or 30 fps)");