blob: 4f0f60ebd6c7a5a8e745fd1643729fa3e43c0ea1 [file] [log] [blame]
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001/*
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -03002 * ov534 gspca driver
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03003 *
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03004 * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it>
Jim Paris0f7a50b2008-12-10 05:45:14 -03005 * Copyright (C) 2008 Jim Paris <jim@jtan.com>
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -03006 * Copyright (C) 2009 Jean-Francois Moine http://moinejf.free.fr
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03007 *
8 * Based on a prototype written by Mark Ferrell <majortrips@gmail.com>
9 * USB protocol reverse engineered by Jim Paris <jim@jtan.com>
10 * https://jim.sh/svn/jim/devl/playstation/ps3/eye/test/
11 *
Jean-Francois Moine189d92a2009-11-11 07:46:28 -030012 * PS3 Eye camera enhanced by Richard Kaswy http://kaswy.free.fr
Jean-Francois Moineb014f942009-11-11 14:28:53 -030013 * PS3 Eye camera, brightness, contrast, hue, AWB control added
14 * by Max Thrun <bear24rw@gmail.com>
Jean-Francois Moine189d92a2009-11-11 07:46:28 -030015 *
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -030016 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 */
30
31#define MODULE_NAME "ov534"
32
33#include "gspca.h"
34
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -030035#define OV534_REG_ADDRESS 0xf1 /* sensor address */
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -030036#define OV534_REG_SUBADDR 0xf2
37#define OV534_REG_WRITE 0xf3
38#define OV534_REG_READ 0xf4
39#define OV534_REG_OPERATION 0xf5
40#define OV534_REG_STATUS 0xf6
41
42#define OV534_OP_WRITE_3 0x37
43#define OV534_OP_WRITE_2 0x33
44#define OV534_OP_READ_2 0xf9
45
46#define CTRL_TIMEOUT 500
47
48MODULE_AUTHOR("Antonio Ospite <ospite@studenti.unina.it>");
49MODULE_DESCRIPTION("GSPCA/OV534 USB Camera Driver");
50MODULE_LICENSE("GPL");
51
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -030052/* specific webcam descriptor */
53struct sd {
54 struct gspca_dev gspca_dev; /* !! must be the first item */
Jean-Francois Moine8c252052008-12-04 05:06:08 -030055 __u32 last_pts;
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -030056 u16 last_fid;
57 u8 frame_rate;
Jean-Francois Moineb014f942009-11-11 14:28:53 -030058
59 u8 brightness;
60 u8 contrast;
Jean-Francois Moine189d92a2009-11-11 07:46:28 -030061 u8 gain;
62 u8 exposure;
63 u8 redblc;
64 u8 blueblc;
Jean-Francois Moineb014f942009-11-11 14:28:53 -030065 u8 hue;
Jean-Francois Moine189d92a2009-11-11 07:46:28 -030066 u8 autogain;
Jean-Francois Moineb014f942009-11-11 14:28:53 -030067 u8 awb;
Jean-Francois Moine189d92a2009-11-11 07:46:28 -030068 u8 sharpness;
69 u8 hflip;
70 u8 vflip;
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -030071
72 u8 sensor;
73#define SENSOR_OV772X 0
74#define SENSOR_OV965X 1
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -030075};
76
77/* V4L2 controls supported by the driver */
Jean-Francois Moine189d92a2009-11-11 07:46:28 -030078static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
79static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
80static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
81static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
82static int sd_setredblc(struct gspca_dev *gspca_dev, __s32 val);
83static int sd_getredblc(struct gspca_dev *gspca_dev, __s32 *val);
84static int sd_setblueblc(struct gspca_dev *gspca_dev, __s32 val);
85static int sd_getblueblc(struct gspca_dev *gspca_dev, __s32 *val);
86static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
87static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
88static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
89static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
90static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
91static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
92static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
93static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moineb014f942009-11-11 14:28:53 -030094static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val);
95static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val);
96static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val);
97static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val);
98static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
99static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
100static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
101static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300102
103static struct ctrl sd_ctrls_ov772x[] = {
Jean-Francois Moine2d19a2c2009-11-12 16:15:44 -0300104 { /* 0 */
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300105 {
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300106 .id = V4L2_CID_BRIGHTNESS,
107 .type = V4L2_CTRL_TYPE_INTEGER,
108 .name = "Brightness",
109 .minimum = 0,
110 .maximum = 255,
111 .step = 1,
112#define BRIGHTNESS_DEF 20
113 .default_value = BRIGHTNESS_DEF,
114 },
115 .set = sd_setbrightness,
116 .get = sd_getbrightness,
117 },
Jean-Francois Moine2d19a2c2009-11-12 16:15:44 -0300118 { /* 1 */
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300119 {
120 .id = V4L2_CID_CONTRAST,
121 .type = V4L2_CTRL_TYPE_INTEGER,
122 .name = "Contrast",
123 .minimum = 0,
124 .maximum = 255,
125 .step = 1,
126#define CONTRAST_DEF 37
127 .default_value = CONTRAST_DEF,
128 },
129 .set = sd_setcontrast,
130 .get = sd_getcontrast,
131 },
Jean-Francois Moine2d19a2c2009-11-12 16:15:44 -0300132 { /* 2 */
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300133 {
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300134 .id = V4L2_CID_GAIN,
135 .type = V4L2_CTRL_TYPE_INTEGER,
136 .name = "Main Gain",
137 .minimum = 0,
138 .maximum = 63,
139 .step = 1,
140#define GAIN_DEF 20
141 .default_value = GAIN_DEF,
142 },
143 .set = sd_setgain,
144 .get = sd_getgain,
145 },
Jean-Francois Moine2d19a2c2009-11-12 16:15:44 -0300146 { /* 3 */
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300147 {
148 .id = V4L2_CID_EXPOSURE,
149 .type = V4L2_CTRL_TYPE_INTEGER,
150 .name = "Exposure",
151 .minimum = 0,
152 .maximum = 255,
153 .step = 1,
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300154#define EXPO_DEF 120
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300155 .default_value = EXPO_DEF,
156 },
157 .set = sd_setexposure,
158 .get = sd_getexposure,
159 },
Jean-Francois Moine2d19a2c2009-11-12 16:15:44 -0300160 { /* 4 */
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300161 {
162 .id = V4L2_CID_RED_BALANCE,
163 .type = V4L2_CTRL_TYPE_INTEGER,
164 .name = "Red Balance",
165 .minimum = 0,
166 .maximum = 255,
167 .step = 1,
168#define RED_BALANCE_DEF 128
169 .default_value = RED_BALANCE_DEF,
170 },
171 .set = sd_setredblc,
172 .get = sd_getredblc,
173 },
Jean-Francois Moine2d19a2c2009-11-12 16:15:44 -0300174 { /* 5 */
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300175 {
176 .id = V4L2_CID_BLUE_BALANCE,
177 .type = V4L2_CTRL_TYPE_INTEGER,
178 .name = "Blue Balance",
179 .minimum = 0,
180 .maximum = 255,
181 .step = 1,
182#define BLUE_BALANCE_DEF 128
183 .default_value = BLUE_BALANCE_DEF,
184 },
185 .set = sd_setblueblc,
186 .get = sd_getblueblc,
187 },
Jean-Francois Moine2d19a2c2009-11-12 16:15:44 -0300188 { /* 6 */
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300189 {
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300190 .id = V4L2_CID_HUE,
191 .type = V4L2_CTRL_TYPE_INTEGER,
192 .name = "Hue",
193 .minimum = 0,
194 .maximum = 255,
195 .step = 1,
196#define HUE_DEF 143
197 .default_value = HUE_DEF,
198 },
199 .set = sd_sethue,
200 .get = sd_gethue,
201 },
Jean-Francois Moine2d19a2c2009-11-12 16:15:44 -0300202 { /* 7 */
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300203 {
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300204 .id = V4L2_CID_AUTOGAIN,
205 .type = V4L2_CTRL_TYPE_BOOLEAN,
206 .name = "Autogain",
207 .minimum = 0,
208 .maximum = 1,
209 .step = 1,
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300210#define AUTOGAIN_DEF 0
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300211 .default_value = AUTOGAIN_DEF,
212 },
213 .set = sd_setautogain,
214 .get = sd_getautogain,
215 },
Jean-Francois Moine2d19a2c2009-11-12 16:15:44 -0300216#define AWB_IDX 8
217 { /* 8 */
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300218 {
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300219 .id = V4L2_CID_AUTO_WHITE_BALANCE,
220 .type = V4L2_CTRL_TYPE_BOOLEAN,
221 .name = "Auto White Balance",
222 .minimum = 0,
223 .maximum = 1,
224 .step = 1,
225#define AWB_DEF 0
226 .default_value = AWB_DEF,
227 },
228 .set = sd_setawb,
229 .get = sd_getawb,
230 },
Jean-Francois Moine2d19a2c2009-11-12 16:15:44 -0300231 { /* 9 */
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300232 {
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300233 .id = V4L2_CID_SHARPNESS,
234 .type = V4L2_CTRL_TYPE_INTEGER,
235 .name = "Sharpness",
236 .minimum = 0,
237 .maximum = 63,
238 .step = 1,
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300239#define SHARPNESS_DEF 0
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300240 .default_value = SHARPNESS_DEF,
241 },
242 .set = sd_setsharpness,
243 .get = sd_getsharpness,
244 },
Jean-Francois Moine2d19a2c2009-11-12 16:15:44 -0300245 { /* 10 */
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300246 {
247 .id = V4L2_CID_HFLIP,
248 .type = V4L2_CTRL_TYPE_BOOLEAN,
249 .name = "HFlip",
250 .minimum = 0,
251 .maximum = 1,
252 .step = 1,
253#define HFLIP_DEF 0
254 .default_value = HFLIP_DEF,
255 },
256 .set = sd_sethflip,
257 .get = sd_gethflip,
258 },
Jean-Francois Moine2d19a2c2009-11-12 16:15:44 -0300259 { /* 11 */
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300260 {
261 .id = V4L2_CID_VFLIP,
262 .type = V4L2_CTRL_TYPE_BOOLEAN,
263 .name = "VFlip",
264 .minimum = 0,
265 .maximum = 1,
266 .step = 1,
267#define VFLIP_DEF 0
268 .default_value = VFLIP_DEF,
269 },
270 .set = sd_setvflip,
271 .get = sd_getvflip,
272 },
273};
274static struct ctrl sd_ctrls_ov965x[] = {
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -0300275};
276
Jean-Francois Moine569691a2009-11-14 09:45:38 -0300277static const struct v4l2_pix_format ov772x_mode[] = {
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300278 {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
279 .bytesperline = 320 * 2,
280 .sizeimage = 320 * 240 * 2,
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300281 .colorspace = V4L2_COLORSPACE_SRGB,
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300282 .priv = 1},
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -0300283 {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
284 .bytesperline = 640 * 2,
285 .sizeimage = 640 * 480 * 2,
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300286 .colorspace = V4L2_COLORSPACE_SRGB,
287 .priv = 0},
288};
289
Jean-Francois Moine569691a2009-11-14 09:45:38 -0300290static const struct v4l2_pix_format ov965x_mode[] = {
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300291 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
292 .bytesperline = 320,
293 .sizeimage = 320 * 240 * 3 / 8 + 590,
294 .colorspace = V4L2_COLORSPACE_JPEG,
Jean-Francois Moine569691a2009-11-14 09:45:38 -0300295 .priv = 4},
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300296 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
297 .bytesperline = 640,
298 .sizeimage = 640 * 480 * 3 / 8 + 590,
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -0300299 .colorspace = V4L2_COLORSPACE_JPEG,
Jean-Francois Moine569691a2009-11-14 09:45:38 -0300300 .priv = 3},
301 {800, 600, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
302 .bytesperline = 800,
303 .sizeimage = 800 * 600 * 3 / 8 + 590,
304 .colorspace = V4L2_COLORSPACE_JPEG,
305 .priv = 2},
306 {1024, 768, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
307 .bytesperline = 1024,
308 .sizeimage = 1024 * 768 * 3 / 8 + 590,
309 .colorspace = V4L2_COLORSPACE_JPEG,
310 .priv = 1},
311 {1280, 1024, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
312 .bytesperline = 1280,
313 .sizeimage = 1280 * 1024 * 3 / 8 + 590,
314 .colorspace = V4L2_COLORSPACE_JPEG,
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -0300315 .priv = 0},
316};
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300317static const u8 bridge_init_ov772x[][2] = {
Jim Paris47dfd212008-12-04 04:28:27 -0300318 { 0xc2, 0x0c },
319 { 0x88, 0xf8 },
320 { 0xc3, 0x69 },
321 { 0x89, 0xff },
322 { 0x76, 0x03 },
323 { 0x92, 0x01 },
324 { 0x93, 0x18 },
325 { 0x94, 0x10 },
326 { 0x95, 0x10 },
327 { 0xe2, 0x00 },
328 { 0xe7, 0x3e },
329
Jim Paris47dfd212008-12-04 04:28:27 -0300330 { 0x96, 0x00 },
331
332 { 0x97, 0x20 },
333 { 0x97, 0x20 },
334 { 0x97, 0x20 },
335 { 0x97, 0x0a },
336 { 0x97, 0x3f },
337 { 0x97, 0x4a },
338 { 0x97, 0x20 },
339 { 0x97, 0x15 },
340 { 0x97, 0x0b },
341
342 { 0x8e, 0x40 },
343 { 0x1f, 0x81 },
344 { 0x34, 0x05 },
345 { 0xe3, 0x04 },
346 { 0x88, 0x00 },
347 { 0x89, 0x00 },
348 { 0x76, 0x00 },
349 { 0xe7, 0x2e },
350 { 0x31, 0xf9 },
351 { 0x25, 0x42 },
352 { 0x21, 0xf0 },
353
354 { 0x1c, 0x00 },
355 { 0x1d, 0x40 },
Jim Paris0f7a50b2008-12-10 05:45:14 -0300356 { 0x1d, 0x02 }, /* payload size 0x0200 * 4 = 2048 bytes */
357 { 0x1d, 0x00 }, /* payload size */
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300358
Jim Paris5ea9c4d2008-12-04 04:36:14 -0300359 { 0x1d, 0x02 }, /* frame size 0x025800 * 4 = 614400 */
360 { 0x1d, 0x58 }, /* frame size */
361 { 0x1d, 0x00 }, /* frame size */
Jim Paris47dfd212008-12-04 04:28:27 -0300362
Jim Parisc06eb612008-12-10 05:47:44 -0300363 { 0x1c, 0x0a },
364 { 0x1d, 0x08 }, /* turn on UVC header */
365 { 0x1d, 0x0e }, /* .. */
366
Jim Paris47dfd212008-12-04 04:28:27 -0300367 { 0x8d, 0x1c },
368 { 0x8e, 0x80 },
369 { 0xe5, 0x04 },
370
371 { 0xc0, 0x50 },
372 { 0xc1, 0x3c },
373 { 0xc2, 0x0c },
374};
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300375static const u8 sensor_init_ov772x[][2] = {
Jim Paris47dfd212008-12-04 04:28:27 -0300376 { 0x12, 0x80 },
377 { 0x11, 0x01 },
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300378/*fixme: better have a delay?*/
379 { 0x11, 0x01 },
380 { 0x11, 0x01 },
381 { 0x11, 0x01 },
382 { 0x11, 0x01 },
383 { 0x11, 0x01 },
384 { 0x11, 0x01 },
385 { 0x11, 0x01 },
386 { 0x11, 0x01 },
387 { 0x11, 0x01 },
388 { 0x11, 0x01 },
Jim Paris47dfd212008-12-04 04:28:27 -0300389
390 { 0x3d, 0x03 },
391 { 0x17, 0x26 },
392 { 0x18, 0xa0 },
393 { 0x19, 0x07 },
394 { 0x1a, 0xf0 },
395 { 0x32, 0x00 },
396 { 0x29, 0xa0 },
397 { 0x2c, 0xf0 },
398 { 0x65, 0x20 },
399 { 0x11, 0x01 },
400 { 0x42, 0x7f },
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300401 { 0x63, 0xaa }, /* AWB - was e0 */
Jim Paris47dfd212008-12-04 04:28:27 -0300402 { 0x64, 0xff },
403 { 0x66, 0x00 },
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300404 { 0x13, 0xf0 }, /* com8 */
Jim Paris47dfd212008-12-04 04:28:27 -0300405 { 0x0d, 0x41 },
406 { 0x0f, 0xc5 },
407 { 0x14, 0x11 },
408
409 { 0x22, 0x7f },
410 { 0x23, 0x03 },
411 { 0x24, 0x40 },
412 { 0x25, 0x30 },
413 { 0x26, 0xa1 },
414 { 0x2a, 0x00 },
415 { 0x2b, 0x00 },
416 { 0x6b, 0xaa },
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300417 { 0x13, 0xff }, /* AWB */
Jim Paris47dfd212008-12-04 04:28:27 -0300418
419 { 0x90, 0x05 },
420 { 0x91, 0x01 },
421 { 0x92, 0x03 },
422 { 0x93, 0x00 },
423 { 0x94, 0x60 },
424 { 0x95, 0x3c },
425 { 0x96, 0x24 },
426 { 0x97, 0x1e },
427 { 0x98, 0x62 },
428 { 0x99, 0x80 },
429 { 0x9a, 0x1e },
430 { 0x9b, 0x08 },
431 { 0x9c, 0x20 },
432 { 0x9e, 0x81 },
433
434 { 0xa6, 0x04 },
435 { 0x7e, 0x0c },
436 { 0x7f, 0x16 },
437 { 0x80, 0x2a },
438 { 0x81, 0x4e },
439 { 0x82, 0x61 },
440 { 0x83, 0x6f },
441 { 0x84, 0x7b },
442 { 0x85, 0x86 },
443 { 0x86, 0x8e },
444 { 0x87, 0x97 },
445 { 0x88, 0xa4 },
446 { 0x89, 0xaf },
447 { 0x8a, 0xc5 },
448 { 0x8b, 0xd7 },
449 { 0x8c, 0xe8 },
450 { 0x8d, 0x20 },
451
452 { 0x0c, 0x90 },
453
454 { 0x2b, 0x00 },
455 { 0x22, 0x7f },
456 { 0x23, 0x03 },
457 { 0x11, 0x01 },
458 { 0x0c, 0xd0 },
459 { 0x64, 0xff },
460 { 0x0d, 0x41 },
461
462 { 0x14, 0x41 },
463 { 0x0e, 0xcd },
464 { 0xac, 0xbf },
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300465 { 0x8e, 0x00 }, /* De-noise threshold */
Jim Paris47dfd212008-12-04 04:28:27 -0300466 { 0x0c, 0xd0 }
467};
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300468static const u8 bridge_start_ov772x_vga[][2] = {
469 {0x1c, 0x00},
470 {0x1d, 0x40},
471 {0x1d, 0x02},
472 {0x1d, 0x00},
473 {0x1d, 0x02},
474 {0x1d, 0x58},
475 {0x1d, 0x00},
476 {0xc0, 0x50},
477 {0xc1, 0x3c},
478};
479static const u8 sensor_start_ov772x_vga[][2] = {
480 {0x12, 0x00},
481 {0x17, 0x26},
482 {0x18, 0xa0},
483 {0x19, 0x07},
484 {0x1a, 0xf0},
485 {0x29, 0xa0},
486 {0x2c, 0xf0},
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300487 {0x65, 0x20},
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300488};
489static const u8 bridge_start_ov772x_qvga[][2] = {
490 {0x1c, 0x00},
491 {0x1d, 0x40},
492 {0x1d, 0x02},
493 {0x1d, 0x00},
494 {0x1d, 0x01},
495 {0x1d, 0x4b},
496 {0x1d, 0x00},
497 {0xc0, 0x28},
498 {0xc1, 0x1e},
499};
500static const u8 sensor_start_ov772x_qvga[][2] = {
501 {0x12, 0x40},
502 {0x17, 0x3f},
503 {0x18, 0x50},
504 {0x19, 0x03},
505 {0x1a, 0x78},
506 {0x29, 0x50},
507 {0x2c, 0x78},
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300508 {0x65, 0x2f},
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300509};
Jim Paris47dfd212008-12-04 04:28:27 -0300510
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300511static const u8 bridge_init_ov965x[][2] = {
512 {0x88, 0xf8},
513 {0x89, 0xff},
514 {0x76, 0x03},
515 {0x92, 0x03},
516 {0x95, 0x10},
517 {0xe2, 0x00},
518 {0xe7, 0x3e},
519 {0x8d, 0x1c},
520 {0x8e, 0x00},
521 {0x8f, 0x00},
522 {0x1f, 0x00},
523 {0xc3, 0xf9},
524 {0x89, 0xff},
525 {0x88, 0xf8},
526 {0x76, 0x03},
527 {0x92, 0x01},
528 {0x93, 0x18},
529 {0x1c, 0x0a},
530 {0x1d, 0x48},
531 {0xc0, 0x50},
532 {0xc1, 0x3c},
533 {0x34, 0x05},
534 {0xc2, 0x0c},
535 {0xc3, 0xf9},
536 {0x34, 0x05},
537 {0xe7, 0x2e},
538 {0x31, 0xf9},
539 {0x35, 0x02},
540 {0xd9, 0x10},
541 {0x25, 0x42},
542 {0x94, 0x11},
543};
544
545static const u8 sensor_init_ov965x[][2] = {
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300546 {0x12, 0x80}, /* com7 - SSCB reset */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300547 {0x00, 0x00}, /* gain */
548 {0x01, 0x80}, /* blue */
549 {0x02, 0x80}, /* red */
550 {0x03, 0x1b}, /* vref */
551 {0x04, 0x03}, /* com1 - exposure low bits */
552 {0x0b, 0x57}, /* ver */
553 {0x0e, 0x61}, /* com5 */
554 {0x0f, 0x42}, /* com6 */
555 {0x11, 0x00}, /* clkrc */
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300556 {0x12, 0x02}, /* com7 - 15fps VGA YUYV */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300557 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
558 {0x14, 0x28}, /* com9 */
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300559 {0x16, 0x24}, /* reg16 */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300560 {0x17, 0x1d}, /* hstart*/
561 {0x18, 0xbd}, /* hstop */
562 {0x19, 0x01}, /* vstrt */
563 {0x1a, 0x81}, /* vstop*/
564 {0x1e, 0x04}, /* mvfp */
565 {0x24, 0x3c}, /* aew */
566 {0x25, 0x36}, /* aeb */
567 {0x26, 0x71}, /* vpt */
568 {0x27, 0x08}, /* bbias */
569 {0x28, 0x08}, /* gbbias */
570 {0x29, 0x15}, /* gr com */
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300571 {0x2a, 0x00}, /* exhch */
572 {0x2b, 0x00}, /* exhcl */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300573 {0x2c, 0x08}, /* rbias */
574 {0x32, 0xff}, /* href */
575 {0x33, 0x00}, /* chlf */
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300576 {0x34, 0x3f}, /* aref1 */
577 {0x35, 0x00}, /* aref2 */
578 {0x36, 0xf8}, /* aref3 */
579 {0x38, 0x72}, /* adc2 */
580 {0x39, 0x57}, /* aref4 */
581 {0x3a, 0x80}, /* tslb - yuyv */
582 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300583 {0x3d, 0x99}, /* com13 */
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300584 {0x3f, 0xc1}, /* edge */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300585 {0x40, 0xc0}, /* com15 */
586 {0x41, 0x40}, /* com16 */
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300587 {0x42, 0xc0}, /* com17 */
588 {0x43, 0x0a}, /* rsvd */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300589 {0x44, 0xf0},
590 {0x45, 0x46},
591 {0x46, 0x62},
592 {0x47, 0x2a},
593 {0x48, 0x3c},
594 {0x4a, 0xfc},
595 {0x4b, 0xfc},
596 {0x4c, 0x7f},
597 {0x4d, 0x7f},
598 {0x4e, 0x7f},
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300599 {0x4f, 0x98}, /* matrix */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300600 {0x50, 0x98},
601 {0x51, 0x00},
602 {0x52, 0x28},
603 {0x53, 0x70},
604 {0x54, 0x98},
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300605 {0x58, 0x1a}, /* matrix coef sign */
606 {0x59, 0x85}, /* AWB control */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300607 {0x5a, 0xa9},
608 {0x5b, 0x64},
609 {0x5c, 0x84},
610 {0x5d, 0x53},
611 {0x5e, 0x0e},
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300612 {0x5f, 0xf0}, /* AWB blue limit */
613 {0x60, 0xf0}, /* AWB red limit */
614 {0x61, 0xf0}, /* AWB green limit */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300615 {0x62, 0x00}, /* lcc1 */
616 {0x63, 0x00}, /* lcc2 */
617 {0x64, 0x02}, /* lcc3 */
618 {0x65, 0x16}, /* lcc4 */
619 {0x66, 0x01}, /* lcc5 */
620 {0x69, 0x02}, /* hv */
621 {0x6b, 0x5a}, /* dbvl */
622 {0x6c, 0x04},
623 {0x6d, 0x55},
624 {0x6e, 0x00},
625 {0x6f, 0x9d},
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300626 {0x70, 0x21}, /* dnsth */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300627 {0x71, 0x78},
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300628 {0x72, 0x00}, /* poidx */
629 {0x73, 0x01}, /* pckdv */
630 {0x74, 0x3a}, /* xindx */
631 {0x75, 0x35}, /* yindx */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300632 {0x76, 0x01},
633 {0x77, 0x02},
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300634 {0x7a, 0x12}, /* gamma curve */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300635 {0x7b, 0x08},
636 {0x7c, 0x16},
637 {0x7d, 0x30},
638 {0x7e, 0x5e},
639 {0x7f, 0x72},
640 {0x80, 0x82},
641 {0x81, 0x8e},
642 {0x82, 0x9a},
643 {0x83, 0xa4},
644 {0x84, 0xac},
645 {0x85, 0xb8},
646 {0x86, 0xc3},
647 {0x87, 0xd6},
648 {0x88, 0xe6},
649 {0x89, 0xf2},
650 {0x8a, 0x03},
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300651 {0x8c, 0x89}, /* com19 */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300652 {0x14, 0x28}, /* com9 */
653 {0x90, 0x7d},
654 {0x91, 0x7b},
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300655 {0x9d, 0x03}, /* lcc6 */
656 {0x9e, 0x04}, /* lcc7 */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300657 {0x9f, 0x7a},
658 {0xa0, 0x79},
659 {0xa1, 0x40}, /* aechm */
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300660 {0xa4, 0x50}, /* com21 */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300661 {0xa5, 0x68}, /* com26 */
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300662 {0xa6, 0x4a}, /* AWB green */
663 {0xa8, 0xc1}, /* refa8 */
664 {0xa9, 0xef}, /* refa9 */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300665 {0xaa, 0x92},
666 {0xab, 0x04},
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300667 {0xac, 0x80}, /* black level control */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300668 {0xad, 0x80},
669 {0xae, 0x80},
670 {0xaf, 0x80},
671 {0xb2, 0xf2},
672 {0xb3, 0x20},
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300673 {0xb4, 0x20}, /* ctrlb4 */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300674 {0xb5, 0x00},
675 {0xb6, 0xaf},
676 {0xbb, 0xae},
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300677 {0xbc, 0x7f}, /* ADC channel offsets */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300678 {0xdb, 0x7f},
679 {0xbe, 0x7f},
680 {0xbf, 0x7f},
681 {0xc0, 0xe2},
682 {0xc1, 0xc0},
683 {0xc2, 0x01},
684 {0xc3, 0x4e},
685 {0xc6, 0x85},
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300686 {0xc7, 0x80}, /* com24 */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300687 {0xc9, 0xe0},
688 {0xca, 0xe8},
689 {0xcb, 0xf0},
690 {0xcc, 0xd8},
691 {0xcd, 0xf1},
692 {0x4f, 0x98},
693 {0x50, 0x98},
694 {0x51, 0x00},
695 {0x52, 0x28},
696 {0x53, 0x70},
697 {0x54, 0x98},
698 {0x58, 0x1a},
699 {0xff, 0x41}, /* read 41, write ff 00 */
700 {0x41, 0x40}, /* com16 */
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300701 {0xc5, 0x03}, /* 60 Hz banding filter */
702 {0x6a, 0x02}, /* 50 Hz banding filter */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300703
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300704 {0x12, 0x62}, /* com7 - 30fps VGA YUV */
705 {0x36, 0xfa}, /* aref3 */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300706 {0x69, 0x0a}, /* hv */
707 {0x8c, 0x89}, /* com22 */
708 {0x14, 0x28}, /* com9 */
709 {0x3e, 0x0c},
710 {0x41, 0x40}, /* com16 */
711 {0x72, 0x00},
712 {0x73, 0x00},
713 {0x74, 0x3a},
714 {0x75, 0x35},
715 {0x76, 0x01},
716 {0xc7, 0x80},
717 {0x03, 0x12}, /* vref */
718 {0x17, 0x16}, /* hstart */
719 {0x18, 0x02}, /* hstop */
720 {0x19, 0x01}, /* vstrt */
721 {0x1a, 0x3d}, /* vstop */
722 {0x32, 0xff}, /* href */
723 {0xc0, 0xaa},
724};
725
726static const u8 bridge_init_ov965x_2[][2] = {
727 {0x94, 0xaa},
728 {0xf1, 0x60},
729 {0xe5, 0x04},
730 {0xc0, 0x50},
731 {0xc1, 0x3c},
732 {0x8c, 0x00},
733 {0x8d, 0x1c},
734 {0x34, 0x05},
735
736 {0xc2, 0x0c},
737 {0xc3, 0xf9},
738 {0xda, 0x01},
739 {0x50, 0x00},
740 {0x51, 0xa0},
741 {0x52, 0x3c},
742 {0x53, 0x00},
743 {0x54, 0x00},
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300744 {0x55, 0x00}, /* brightness */
745 {0x57, 0x00}, /* contrast 2 */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300746 {0x5c, 0x00},
747 {0x5a, 0xa0},
748 {0x5b, 0x78},
749 {0x35, 0x02},
750 {0xd9, 0x10},
751 {0x94, 0x11},
752};
753
754static const u8 sensor_init_ov965x_2[][2] = {
755 {0x3b, 0xc4},
756 {0x1e, 0x04}, /* mvfp */
757 {0x13, 0xe0}, /* com8 */
758 {0x00, 0x00}, /* gain */
759 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
760 {0x11, 0x03}, /* clkrc */
761 {0x6b, 0x5a}, /* dblv */
762 {0x6a, 0x05},
763 {0xc5, 0x07},
764 {0xa2, 0x4b},
765 {0xa3, 0x3e},
766 {0x2d, 0x00},
767 {0xff, 0x42}, /* read 42, write ff 00 */
768 {0x42, 0xc0},
769 {0x2d, 0x00},
770 {0xff, 0x42}, /* read 42, write ff 00 */
771 {0x42, 0xc1},
772 {0x3f, 0x01},
773 {0xff, 0x42}, /* read 42, write ff 00 */
774 {0x42, 0xc1},
775 {0x4f, 0x98},
776 {0x50, 0x98},
777 {0x51, 0x00},
778 {0x52, 0x28},
779 {0x53, 0x70},
780 {0x54, 0x98},
781 {0x58, 0x1a},
782 {0xff, 0x41}, /* read 41, write ff 00 */
783 {0x41, 0x40}, /* com16 */
784 {0x56, 0x40},
785 {0x55, 0x8f},
786 {0x10, 0x25}, /* aech - exposure high bits */
787 {0xff, 0x13}, /* read 13, write ff 00 */
788 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
789};
790
Jean-Francois Moine569691a2009-11-14 09:45:38 -0300791static const u8 sensor_start_ov965x_1_vga[][2] = { /* same for qvga */
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300792 {0x12, 0x62}, /* com7 - 30fps VGA YUV */
793 {0x36, 0xfa}, /* aref3 */
794 {0x69, 0x0a}, /* hv */
795 {0x8c, 0x89}, /* com22 */
796 {0x14, 0x28}, /* com9 */
797 {0x3e, 0x0c}, /* com14 */
798 {0x41, 0x40}, /* com16 */
799 {0x72, 0x00},
800 {0x73, 0x00},
801 {0x74, 0x3a},
802 {0x75, 0x35},
803 {0x76, 0x01},
804 {0xc7, 0x80}, /* com24 */
805 {0x03, 0x12}, /* vref */
806 {0x17, 0x16}, /* hstart */
807 {0x18, 0x02}, /* hstop */
808 {0x19, 0x01}, /* vstrt */
809 {0x1a, 0x3d}, /* vstop */
810 {0x32, 0xff}, /* href */
811 {0xc0, 0xaa},
812 {}
813};
814
Jean-Francois Moine569691a2009-11-14 09:45:38 -0300815static const u8 sensor_start_ov965x_1_svga[][2] = {
816 {0x12, 0x02}, /* com7 - YUYV - VGA 15 full resolution */
817 {0x36, 0xf8}, /* aref3 */
818 {0x69, 0x02}, /* hv */
819 {0x8c, 0x0d}, /* com22 */
820 {0x3e, 0x0c}, /* com14 */
821 {0x41, 0x40}, /* com16 */
822 {0x72, 0x00},
823 {0x73, 0x01},
824 {0x74, 0x3a},
825 {0x75, 0x35},
826 {0x76, 0x01},
827 {0xc7, 0x80}, /* com24 */
828 {0x03, 0x1b}, /* vref */
829 {0x17, 0x1d}, /* hstart */
830 {0x18, 0xbd}, /* hstop */
831 {0x19, 0x01}, /* vstrt */
832 {0x1a, 0x81}, /* vstop */
833 {0x32, 0xff}, /* href */
834 {0xc0, 0xe2},
835 {}
836};
837
838static const u8 sensor_start_ov965x_1_xga[][2] = {
839 {0x12, 0x02}, /* com7 */
840 {0x36, 0xf8}, /* aref3 */
841 {0x69, 0x02}, /* hv */
842 {0x8c, 0x89}, /* com22 */
843 {0x14, 0x28}, /* com9 */
844 {0x3e, 0x0c}, /* com14 */
845 {0x41, 0x40}, /* com16 */
846 {0x72, 0x00},
847 {0x73, 0x01},
848 {0x74, 0x3a},
849 {0x75, 0x35},
850 {0x76, 0x01},
851 {0xc7, 0x80}, /* com24 */
852 {0x03, 0x1b}, /* vref */
853 {0x17, 0x1d}, /* hstart */
854 {0x18, 0xbd}, /* hstop */
855 {0x19, 0x01}, /* vstrt */
856 {0x1a, 0x81}, /* vstop */
857 {0x32, 0xff}, /* href */
858 {0xc0, 0xe2},
859 {}
860};
861
862static const u8 sensor_start_ov965x_1_sxga[][2] = {
863 {0x12, 0x02}, /* com7 */
864 {0x36, 0xf8}, /* aref3 */
865 {0x69, 0x02}, /* hv */
866 {0x8c, 0x89}, /* com22 */
867 {0x14, 0x28}, /* com9 */
868 {0x3e, 0x0c}, /* com14 */
869 {0x41, 0x40}, /* com16 */
870 {0x72, 0x00},
871 {0x73, 0x01},
872 {0x74, 0x3a},
873 {0x75, 0x35},
874 {0x76, 0x01},
875 {0xc7, 0x80}, /* com24 */
876 {0x03, 0x1b}, /* vref */
877 {0x17, 0x1d}, /* hstart */
878 {0x18, 0x02}, /* hstop */
879 {0x19, 0x01}, /* vstrt */
880 {0x1a, 0x81}, /* vstop */
881 {0x32, 0xff}, /* href */
882 {0xc0, 0xe2},
883 {}
884};
885
886static const u8 bridge_start_ov965x_qvga[][2] = {
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300887 {0x94, 0xaa},
888 {0xf1, 0x60},
889 {0xe5, 0x04},
890 {0xc0, 0x50},
891 {0xc1, 0x3c},
892 {0x8c, 0x00},
893 {0x8d, 0x1c},
894 {0x34, 0x05},
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300895
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300896 {0xc2, 0x4c},
897 {0xc3, 0xf9},
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300898 {0xda, 0x00},
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300899 {0x50, 0x00},
900 {0x51, 0xa0},
901 {0x52, 0x78},
902 {0x53, 0x00},
903 {0x54, 0x00},
904 {0x55, 0x00},
905 {0x57, 0x00},
906 {0x5c, 0x00},
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300907 {0x5a, 0x50},
908 {0x5b, 0x3c},
909 {0x35, 0x02},
910 {0xd9, 0x10},
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300911 {0x94, 0x11},
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300912 {}
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300913};
914
Jean-Francois Moine569691a2009-11-14 09:45:38 -0300915static const u8 bridge_start_ov965x_vga[][2] = {
916 {0x94, 0xaa},
917 {0xf1, 0x60},
918 {0xe5, 0x04},
919 {0xc0, 0x50},
920 {0xc1, 0x3c},
921 {0x8c, 0x00},
922 {0x8d, 0x1c},
923 {0x34, 0x05},
924 {0xc2, 0x0c},
925 {0xc3, 0xf9},
926 {0xda, 0x01},
927 {0x50, 0x00},
928 {0x51, 0xa0},
929 {0x52, 0x3c},
930 {0x53, 0x00},
931 {0x54, 0x00},
932 {0x55, 0x00},
933 {0x57, 0x00},
934 {0x5c, 0x00},
935 {0x5a, 0xa0},
936 {0x5b, 0x78},
937 {0x35, 0x02},
938 {0xd9, 0x10},
939 {0x94, 0x11},
940 {}
941};
942
943static const u8 bridge_start_ov965x_svga[][2] = {
944 {0x94, 0xaa},
945 {0xf1, 0x60},
946 {0xe5, 0x04},
947 {0xc0, 0xa0},
948 {0xc1, 0x80},
949 {0x8c, 0x00},
950 {0x8d, 0x1c},
951 {0x34, 0x05},
952
953 {0xc2, 0x4c},
954 {0xc3, 0xf9},
955 {0x50, 0x00},
956 {0x51, 0x40},
957 {0x52, 0x00},
958 {0x53, 0x00},
959 {0x54, 0x00},
960 {0x55, 0x88},
961 {0x57, 0x00},
962 {0x5c, 0x00},
963 {0x5a, 0xc8},
964 {0x5b, 0x96},
965 {0x35, 0x02},
966 {0xd9, 0x10},
967 {0xda, 0x00},
968 {0x94, 0x11},
969 {}
970};
971
972static const u8 bridge_start_ov965x_xga[][2] = {
973 {0x94, 0xaa},
974 {0xf1, 0x60},
975 {0xe5, 0x04},
976 {0xc0, 0xa0},
977 {0xc1, 0x80},
978 {0x8c, 0x00},
979 {0x8d, 0x1c},
980 {0x34, 0x05},
981 {0xc2, 0x4c},
982 {0xc3, 0xf9},
983 {0x50, 0x00},
984 {0x51, 0x40},
985 {0x52, 0x00},
986 {0x53, 0x00},
987 {0x54, 0x00},
988 {0x55, 0x88},
989 {0x57, 0x00},
990 {0x5c, 0x01},
991 {0x5a, 0x00},
992 {0x5b, 0xc0},
993 {0x35, 0x02},
994 {0xd9, 0x10},
995 {0xda, 0x01},
996 {0x94, 0x11},
997 {}
998};
999
1000static const u8 bridge_start_ov965x_sxga[][2] = {
1001 {0x94, 0xaa},
1002 {0xf1, 0x60},
1003 {0xe5, 0x04},
1004 {0xc0, 0xa0},
1005 {0xc1, 0x80},
1006 {0x8c, 0x00},
1007 {0x8d, 0x1c},
1008 {0x34, 0x05},
1009 {0xc2, 0x0c},
1010 {0xc3, 0xf9},
1011 {0xda, 0x00},
1012 {0x35, 0x02},
1013 {0xd9, 0x10},
1014 {0x94, 0x11},
1015 {}
1016};
1017
1018static const u8 sensor_start_ov965x_2_qvga[][2] = {
1019 {0x3b, 0xe4}, /* com11 - night mode 1/4 frame rate */
1020 {0x1e, 0x04}, /* mvfp */
1021 {0x13, 0xe0}, /* com8 */
1022 {0x00, 0x00},
1023 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
1024 {0x11, 0x01}, /* clkrc */
1025 {0x6b, 0x5a}, /* dblv */
1026 {0x6a, 0x02}, /* 50 Hz banding filter */
1027 {0xc5, 0x03}, /* 60 Hz banding filter */
1028 {0xa2, 0x96}, /* bd50 */
1029 {0xa3, 0x7d}, /* bd60 */
1030
1031 {0xff, 0x13}, /* read 13, write ff 00 */
1032 {0x13, 0xe7},
1033 {0x3a, 0x80}, /* tslb - yuyv */
1034 {}
1035};
1036
1037static const u8 sensor_start_ov965x_2_vga[][2] = {
Jean-Francois Moine191d0e72009-05-22 04:16:42 -03001038 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
1039 {0x1e, 0x04}, /* mvfp */
1040 {0x13, 0xe0}, /* com8 */
1041 {0x00, 0x00},
1042 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
1043 {0x11, 0x03}, /* clkrc */
1044 {0x6b, 0x5a}, /* dblv */
1045 {0x6a, 0x05}, /* 50 Hz banding filter */
1046 {0xc5, 0x07}, /* 60 Hz banding filter */
1047 {0xa2, 0x4b}, /* bd50 */
1048 {0xa3, 0x3e}, /* bd60 */
1049
1050 {0x2d, 0x00}, /* advfl */
1051 {}
1052};
1053
Jean-Francois Moine569691a2009-11-14 09:45:38 -03001054static const u8 sensor_start_ov965x_2_svga[][2] = { /* same for xga */
1055 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -03001056 {0x1e, 0x04}, /* mvfp */
1057 {0x13, 0xe0}, /* com8 */
1058 {0x00, 0x00},
1059 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
1060 {0x11, 0x01}, /* clkrc */
1061 {0x6b, 0x5a}, /* dblv */
Jean-Francois Moine569691a2009-11-14 09:45:38 -03001062 {0x6a, 0x0c}, /* 50 Hz banding filter */
1063 {0xc5, 0x0f}, /* 60 Hz banding filter */
1064 {0xa2, 0x4e}, /* bd50 */
1065 {0xa3, 0x41}, /* bd60 */
1066 {0x2d, 0x00}, /* advfl */
1067 {}
1068};
Jean-Francois Moine191d0e72009-05-22 04:16:42 -03001069
Jean-Francois Moine569691a2009-11-14 09:45:38 -03001070static const u8 sensor_start_ov965x_2_sxga[][2] = {
1071 {0x13, 0xe0}, /* com8 */
1072 {0x00, 0x00},
1073 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
1074 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
1075 {0x1e, 0x04}, /* mvfp */
1076 {0x11, 0x01}, /* clkrc */
1077 {0x6b, 0x5a}, /* dblv */
1078 {0x6a, 0x0c}, /* 50 Hz banding filter */
1079 {0xc5, 0x0f}, /* 60 Hz banding filter */
1080 {0xa2, 0x4e}, /* bd50 */
1081 {0xa3, 0x41}, /* bd60 */
1082 {0x2d, 0x00}, /* advfl */
Jean-Francois Moine191d0e72009-05-22 04:16:42 -03001083 {}
1084};
1085
1086static const u8 sensor_start_ov965x_2[][2] = {
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -03001087 {0xff, 0x42}, /* read 42, write ff 00 */
Jean-Francois Moine191d0e72009-05-22 04:16:42 -03001088 {0x42, 0xc1}, /* com17 - 50 Hz filter */
1089 {}
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -03001090};
1091
1092
1093static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
1094{
1095 struct usb_device *udev = gspca_dev->dev;
1096 int ret;
1097
1098 PDEBUG(D_USBO, "reg=0x%04x, val=0%02x", reg, val);
1099 gspca_dev->usb_buf[0] = val;
1100 ret = usb_control_msg(udev,
1101 usb_sndctrlpipe(udev, 0),
1102 0x01,
1103 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1104 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
1105 if (ret < 0)
1106 PDEBUG(D_ERR, "write failed");
1107}
1108
1109static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg)
1110{
1111 struct usb_device *udev = gspca_dev->dev;
1112 int ret;
1113
1114 ret = usb_control_msg(udev,
1115 usb_rcvctrlpipe(udev, 0),
1116 0x01,
1117 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1118 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
1119 PDEBUG(D_USBI, "reg=0x%04x, data=0x%02x", reg, gspca_dev->usb_buf[0]);
1120 if (ret < 0)
1121 PDEBUG(D_ERR, "read failed");
1122 return gspca_dev->usb_buf[0];
1123}
1124
1125/* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
1126 * (direction and output)? */
1127static void ov534_set_led(struct gspca_dev *gspca_dev, int status)
1128{
1129 u8 data;
1130
1131 PDEBUG(D_CONF, "led status: %d", status);
1132
1133 data = ov534_reg_read(gspca_dev, 0x21);
1134 data |= 0x80;
1135 ov534_reg_write(gspca_dev, 0x21, data);
1136
1137 data = ov534_reg_read(gspca_dev, 0x23);
1138 if (status)
1139 data |= 0x80;
1140 else
1141 data &= ~0x80;
1142
1143 ov534_reg_write(gspca_dev, 0x23, data);
1144
1145 if (!status) {
1146 data = ov534_reg_read(gspca_dev, 0x21);
1147 data &= ~0x80;
1148 ov534_reg_write(gspca_dev, 0x21, data);
1149 }
1150}
1151
1152static int sccb_check_status(struct gspca_dev *gspca_dev)
1153{
1154 u8 data;
1155 int i;
1156
1157 for (i = 0; i < 5; i++) {
1158 data = ov534_reg_read(gspca_dev, OV534_REG_STATUS);
1159
1160 switch (data) {
1161 case 0x00:
1162 return 1;
1163 case 0x04:
1164 return 0;
1165 case 0x03:
1166 break;
1167 default:
1168 PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5",
1169 data, i + 1);
1170 }
1171 }
1172 return 0;
1173}
1174
1175static void sccb_reg_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
1176{
1177 PDEBUG(D_USBO, "reg: 0x%02x, val: 0x%02x", reg, val);
1178 ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
1179 ov534_reg_write(gspca_dev, OV534_REG_WRITE, val);
1180 ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
1181
1182 if (!sccb_check_status(gspca_dev))
1183 PDEBUG(D_ERR, "sccb_reg_write failed");
1184}
1185
1186static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg)
1187{
1188 ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
1189 ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
1190 if (!sccb_check_status(gspca_dev))
1191 PDEBUG(D_ERR, "sccb_reg_read failed 1");
1192
1193 ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
1194 if (!sccb_check_status(gspca_dev))
1195 PDEBUG(D_ERR, "sccb_reg_read failed 2");
1196
1197 return ov534_reg_read(gspca_dev, OV534_REG_READ);
1198}
1199
1200/* output a bridge sequence (reg - val) */
1201static void reg_w_array(struct gspca_dev *gspca_dev,
1202 const u8 (*data)[2], int len)
1203{
1204 while (--len >= 0) {
1205 ov534_reg_write(gspca_dev, (*data)[0], (*data)[1]);
1206 data++;
1207 }
1208}
1209
1210/* output a sensor sequence (reg - val) */
1211static void sccb_w_array(struct gspca_dev *gspca_dev,
1212 const u8 (*data)[2], int len)
1213{
1214 while (--len >= 0) {
1215 if ((*data)[0] != 0xff) {
1216 sccb_reg_write(gspca_dev, (*data)[0], (*data)[1]);
1217 } else {
1218 sccb_reg_read(gspca_dev, (*data)[1]);
1219 sccb_reg_write(gspca_dev, 0xff, 0x00);
1220 }
1221 data++;
1222 }
1223}
1224
Jean-Francois Moine69f1fe22009-11-12 06:10:36 -03001225/* ov772x specific controls */
1226static void set_frame_rate(struct gspca_dev *gspca_dev)
Jim Paris11d9f252008-12-10 06:06:20 -03001227{
1228 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001229 int i;
1230 struct rate_s {
1231 u8 fps;
1232 u8 r11;
1233 u8 r0d;
1234 u8 re5;
1235 };
1236 const struct rate_s *r;
1237 static const struct rate_s rate_0[] = { /* 640x480 */
1238 {60, 0x01, 0xc1, 0x04},
1239 {50, 0x01, 0x41, 0x02},
1240 {40, 0x02, 0xc1, 0x04},
1241 {30, 0x04, 0x81, 0x02},
1242 {15, 0x03, 0x41, 0x04},
1243 };
1244 static const struct rate_s rate_1[] = { /* 320x240 */
1245 {125, 0x02, 0x81, 0x02},
1246 {100, 0x02, 0xc1, 0x04},
1247 {75, 0x03, 0xc1, 0x04},
1248 {60, 0x04, 0xc1, 0x04},
1249 {50, 0x02, 0x41, 0x04},
1250 {40, 0x03, 0x41, 0x04},
1251 {30, 0x04, 0x41, 0x04},
1252 };
Jim Paris11d9f252008-12-10 06:06:20 -03001253
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001254 if (gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv == 0) {
1255 r = rate_0;
1256 i = ARRAY_SIZE(rate_0);
1257 } else {
1258 r = rate_1;
1259 i = ARRAY_SIZE(rate_1);
1260 }
1261 while (--i > 0) {
1262 if (sd->frame_rate >= r->fps)
1263 break;
1264 r++;
Jim Paris11d9f252008-12-10 06:06:20 -03001265 }
1266
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001267 sccb_reg_write(gspca_dev, 0x11, r->r11);
1268 sccb_reg_write(gspca_dev, 0x0d, r->r0d);
1269 ov534_reg_write(gspca_dev, 0xe5, r->re5);
1270
1271 PDEBUG(D_PROBE, "frame_rate: %d", r->fps);
1272}
1273
Jean-Francois Moineb014f942009-11-11 14:28:53 -03001274static void setbrightness(struct gspca_dev *gspca_dev)
1275{
1276 struct sd *sd = (struct sd *) gspca_dev;
1277
1278 sccb_reg_write(gspca_dev, 0x9B, sd->brightness);
1279}
1280
1281static void setcontrast(struct gspca_dev *gspca_dev)
1282{
1283 struct sd *sd = (struct sd *) gspca_dev;
1284
1285 sccb_reg_write(gspca_dev, 0x9C, sd->contrast);
1286}
1287
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001288static void setgain(struct gspca_dev *gspca_dev)
1289{
1290 struct sd *sd = (struct sd *) gspca_dev;
1291 u8 val;
1292
1293 val = sd->gain;
1294 switch (val & 0x30) {
1295 case 0x00:
1296 val &= 0x0f;
1297 break;
1298 case 0x10:
1299 val &= 0x0f;
1300 val |= 0x30;
1301 break;
1302 case 0x20:
1303 val &= 0x0f;
1304 val |= 0x70;
1305 break;
1306 default:
1307/* case 0x30: */
1308 val &= 0x0f;
1309 val |= 0xf0;
1310 break;
1311 }
1312 sccb_reg_write(gspca_dev, 0x00, val);
1313}
1314
1315static void setexposure(struct gspca_dev *gspca_dev)
1316{
1317 struct sd *sd = (struct sd *) gspca_dev;
1318 u8 val;
1319
1320 val = sd->exposure;
1321 sccb_reg_write(gspca_dev, 0x08, val >> 7);
1322 sccb_reg_write(gspca_dev, 0x10, val << 1);
1323}
1324
1325static void setredblc(struct gspca_dev *gspca_dev)
1326{
1327 struct sd *sd = (struct sd *) gspca_dev;
1328
1329 sccb_reg_write(gspca_dev, 0x43, sd->redblc);
1330}
1331
1332static void setblueblc(struct gspca_dev *gspca_dev)
1333{
1334 struct sd *sd = (struct sd *) gspca_dev;
1335
1336 sccb_reg_write(gspca_dev, 0x42, sd->blueblc);
1337}
1338
Jean-Francois Moineb014f942009-11-11 14:28:53 -03001339static void sethue(struct gspca_dev *gspca_dev)
1340{
1341 struct sd *sd = (struct sd *) gspca_dev;
1342
1343 sccb_reg_write(gspca_dev, 0x01, sd->hue);
1344}
1345
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001346static void setautogain(struct gspca_dev *gspca_dev)
1347{
1348 struct sd *sd = (struct sd *) gspca_dev;
1349
1350 if (sd->autogain) {
1351 sccb_reg_write(gspca_dev, 0x13, 0xf7); /* AGC,AEC,AWB ON */
1352 sccb_reg_write(gspca_dev, 0x64,
1353 sccb_reg_read(gspca_dev, 0x64) | 0x03);
1354 } else {
1355 sccb_reg_write(gspca_dev, 0x13, 0xf0); /* AGC,AEC,AWB OFF */
1356 sccb_reg_write(gspca_dev, 0x64,
1357 sccb_reg_read(gspca_dev, 0x64) & 0xfc);
1358 }
1359}
1360
Jean-Francois Moineb014f942009-11-11 14:28:53 -03001361static void setawb(struct gspca_dev *gspca_dev)
1362{
1363 struct sd *sd = (struct sd *) gspca_dev;
1364
1365 if (sd->awb)
1366 sccb_reg_write(gspca_dev, 0x63, 0xe0); /* AWB on */
1367 else
1368 sccb_reg_write(gspca_dev, 0x63, 0xaa); /* AWB off */
1369}
1370
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001371static void setsharpness(struct gspca_dev *gspca_dev)
1372{
1373 struct sd *sd = (struct sd *) gspca_dev;
1374 u8 val;
1375
1376 val = sd->sharpness;
1377 sccb_reg_write(gspca_dev, 0x91, val); /* vga noise */
1378 sccb_reg_write(gspca_dev, 0x8e, val); /* qvga noise */
1379}
1380
1381static void sethflip(struct gspca_dev *gspca_dev)
1382{
1383 struct sd *sd = (struct sd *) gspca_dev;
1384
1385 if (sd->hflip == 0)
1386 sccb_reg_write(gspca_dev, 0x0c,
1387 sccb_reg_read(gspca_dev, 0x0c) | 0x40);
1388 else
1389 sccb_reg_write(gspca_dev, 0x0c,
1390 sccb_reg_read(gspca_dev, 0x0c) & 0xbf);
1391}
1392
1393static void setvflip(struct gspca_dev *gspca_dev)
1394{
1395 struct sd *sd = (struct sd *) gspca_dev;
1396
1397 if (sd->vflip == 0)
1398 sccb_reg_write(gspca_dev, 0x0c,
1399 sccb_reg_read(gspca_dev, 0x0c) | 0x80);
1400 else
1401 sccb_reg_write(gspca_dev, 0x0c,
1402 sccb_reg_read(gspca_dev, 0x0c) & 0x7f);
Jim Paris11d9f252008-12-10 06:06:20 -03001403}
Jim Paris47dfd212008-12-04 04:28:27 -03001404
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001405/* this function is called at probe time */
1406static int sd_config(struct gspca_dev *gspca_dev,
1407 const struct usb_device_id *id)
1408{
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -03001409 struct sd *sd = (struct sd *) gspca_dev;
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001410 struct cam *cam;
1411
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -03001412 sd->sensor = id->driver_info;
1413
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001414 cam = &gspca_dev->cam;
1415
Jean-Francois Moine6929dc62009-04-21 13:45:56 -03001416 if (sd->sensor == SENSOR_OV772X) {
Jean-Francois Moine569691a2009-11-14 09:45:38 -03001417 cam->cam_mode = ov772x_mode;
1418 cam->nmodes = ARRAY_SIZE(ov772x_mode);
Jean-Francois Moine191d0e72009-05-22 04:16:42 -03001419
Jean-Francois Moine6929dc62009-04-21 13:45:56 -03001420 cam->bulk = 1;
1421 cam->bulk_size = 16384;
1422 cam->bulk_nurbs = 2;
Jean-Francois Moine191d0e72009-05-22 04:16:42 -03001423 } else { /* ov965x */
Jean-Francois Moine569691a2009-11-14 09:45:38 -03001424 cam->cam_mode = ov965x_mode;
1425 cam->nmodes = ARRAY_SIZE(ov965x_mode);
Jean-Francois Moine6929dc62009-04-21 13:45:56 -03001426 }
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001427
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001428 sd->frame_rate = 30;
Jean-Francois Moineb014f942009-11-11 14:28:53 -03001429
1430 sd->brightness = BRIGHTNESS_DEF;
1431 sd->contrast = CONTRAST_DEF;
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001432 sd->gain = GAIN_DEF;
1433 sd->exposure = EXPO_DEF;
1434 sd->redblc = RED_BALANCE_DEF;
1435 sd->blueblc = BLUE_BALANCE_DEF;
Jean-Francois Moineb014f942009-11-11 14:28:53 -03001436 sd->hue = HUE_DEF;
1437#if AUTOGAIN_DEF != 0
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001438 sd->autogain = AUTOGAIN_DEF;
Jean-Francois Moine2d19a2c2009-11-12 16:15:44 -03001439#else
1440 gspca_dev->ctrl_inac |= (1 << AWB_IDX);
Jean-Francois Moineb014f942009-11-11 14:28:53 -03001441#endif
1442#if AWB_DEF != 0
1443 sd->awb = AWB_DEF
1444#endif
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001445 sd->sharpness = SHARPNESS_DEF;
1446#if HFLIP_DEF != 0
1447 sd->hflip = HFLIP_DEF;
1448#endif
1449#if VFLIP_DEF != 0
1450 sd->vflip = VFLIP_DEF;
1451#endif
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001452 return 0;
1453}
1454
1455/* this function is called at probe and resume time */
1456static int sd_init(struct gspca_dev *gspca_dev)
1457{
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -03001458 struct sd *sd = (struct sd *) gspca_dev;
1459 u16 sensor_id;
1460 static const u8 sensor_addr[2] = {
1461 0x42, /* 0 SENSOR_OV772X */
1462 0x60, /* 1 SENSOR_OV965X */
1463 };
1464
1465 /* reset bridge */
1466 ov534_reg_write(gspca_dev, 0xe7, 0x3a);
1467 ov534_reg_write(gspca_dev, 0xe0, 0x08);
1468 msleep(100);
1469
1470 /* initialize the sensor address */
1471 ov534_reg_write(gspca_dev, OV534_REG_ADDRESS,
1472 sensor_addr[sd->sensor]);
1473
1474 /* reset sensor */
1475 sccb_reg_write(gspca_dev, 0x12, 0x80);
1476 msleep(10);
1477
1478 /* probe the sensor */
1479 sccb_reg_read(gspca_dev, 0x0a);
1480 sensor_id = sccb_reg_read(gspca_dev, 0x0a) << 8;
1481 sccb_reg_read(gspca_dev, 0x0b);
1482 sensor_id |= sccb_reg_read(gspca_dev, 0x0b);
1483 PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id);
1484
1485 /* initialize */
1486 switch (sd->sensor) {
1487 case SENSOR_OV772X:
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001488 reg_w_array(gspca_dev, bridge_init_ov772x,
1489 ARRAY_SIZE(bridge_init_ov772x));
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -03001490 ov534_set_led(gspca_dev, 1);
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001491 sccb_w_array(gspca_dev, sensor_init_ov772x,
1492 ARRAY_SIZE(sensor_init_ov772x));
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -03001493 ov534_reg_write(gspca_dev, 0xe0, 0x09);
1494 ov534_set_led(gspca_dev, 0);
Jean-Francois Moine69f1fe22009-11-12 06:10:36 -03001495 set_frame_rate(gspca_dev);
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -03001496 break;
1497 default:
1498/* case SENSOR_OV965X: */
1499 reg_w_array(gspca_dev, bridge_init_ov965x,
1500 ARRAY_SIZE(bridge_init_ov965x));
1501 sccb_w_array(gspca_dev, sensor_init_ov965x,
1502 ARRAY_SIZE(sensor_init_ov965x));
1503 reg_w_array(gspca_dev, bridge_init_ov965x_2,
1504 ARRAY_SIZE(bridge_init_ov965x_2));
1505 sccb_w_array(gspca_dev, sensor_init_ov965x_2,
1506 ARRAY_SIZE(sensor_init_ov965x_2));
1507 ov534_reg_write(gspca_dev, 0xe0, 0x00);
1508 ov534_reg_write(gspca_dev, 0xe0, 0x01);
1509 ov534_set_led(gspca_dev, 0);
1510 ov534_reg_write(gspca_dev, 0xe0, 0x00);
1511 }
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001512
1513 return 0;
1514}
1515
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001516static int sd_start_ov772x(struct gspca_dev *gspca_dev)
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001517{
Jean-Francois Moine191d0e72009-05-22 04:16:42 -03001518 int mode;
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001519
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001520 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
1521 if (mode != 0) { /* 320x240 */
1522 reg_w_array(gspca_dev, bridge_start_ov772x_qvga,
1523 ARRAY_SIZE(bridge_start_ov772x_qvga));
1524 sccb_w_array(gspca_dev, sensor_start_ov772x_qvga,
1525 ARRAY_SIZE(sensor_start_ov772x_qvga));
1526 } else { /* 640x480 */
1527 reg_w_array(gspca_dev, bridge_start_ov772x_vga,
1528 ARRAY_SIZE(bridge_start_ov772x_vga));
1529 sccb_w_array(gspca_dev, sensor_start_ov772x_vga,
1530 ARRAY_SIZE(sensor_start_ov772x_vga));
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -03001531 }
Jean-Francois Moine69f1fe22009-11-12 06:10:36 -03001532 set_frame_rate(gspca_dev);
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001533
1534 setautogain(gspca_dev);
Jean-Francois Moineb014f942009-11-11 14:28:53 -03001535 setawb(gspca_dev);
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001536 setgain(gspca_dev);
1537 setredblc(gspca_dev);
1538 setblueblc(gspca_dev);
Jean-Francois Moineb014f942009-11-11 14:28:53 -03001539 sethue(gspca_dev);
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001540 setexposure(gspca_dev);
Jean-Francois Moineb014f942009-11-11 14:28:53 -03001541 setbrightness(gspca_dev);
1542 setcontrast(gspca_dev);
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001543 setsharpness(gspca_dev);
1544 setvflip(gspca_dev);
1545 sethflip(gspca_dev);
1546
1547 ov534_set_led(gspca_dev, 1);
1548 ov534_reg_write(gspca_dev, 0xe0, 0x00);
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001549 return 0;
1550}
1551
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001552static int sd_start_ov965x(struct gspca_dev *gspca_dev)
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001553{
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001554 int mode;
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -03001555
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001556 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
Jean-Francois Moine569691a2009-11-14 09:45:38 -03001557 switch (mode) {
1558 default:
1559/* case 4: * 320x240 */
1560 sccb_w_array(gspca_dev, sensor_start_ov965x_1_vga,
1561 ARRAY_SIZE(sensor_start_ov965x_1_vga));
Jean-Francois Moinec76e6f12009-11-12 06:13:41 -03001562 reg_w_array(gspca_dev, bridge_start_ov965x_qvga,
1563 ARRAY_SIZE(bridge_start_ov965x_qvga));
Jean-Francois Moine569691a2009-11-14 09:45:38 -03001564 sccb_w_array(gspca_dev, sensor_start_ov965x_2_qvga,
1565 ARRAY_SIZE(sensor_start_ov965x_2_qvga));
1566 break;
1567 case 3: /* 640x480 */
1568 sccb_w_array(gspca_dev, sensor_start_ov965x_1_vga,
1569 ARRAY_SIZE(sensor_start_ov965x_1_vga));
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001570 reg_w_array(gspca_dev, bridge_start_ov965x_vga,
1571 ARRAY_SIZE(bridge_start_ov965x_vga));
Jean-Francois Moine569691a2009-11-14 09:45:38 -03001572 sccb_w_array(gspca_dev, sensor_start_ov965x_2_vga,
1573 ARRAY_SIZE(sensor_start_ov965x_2_vga));
1574 break;
1575 case 2: /* 800x600 */
1576 sccb_w_array(gspca_dev, sensor_start_ov965x_1_svga,
1577 ARRAY_SIZE(sensor_start_ov965x_1_svga));
1578 reg_w_array(gspca_dev, bridge_start_ov965x_svga,
1579 ARRAY_SIZE(bridge_start_ov965x_svga));
1580 sccb_w_array(gspca_dev, sensor_start_ov965x_2_svga,
1581 ARRAY_SIZE(sensor_start_ov965x_2_svga));
1582 break;
1583 case 1: /* 1024x768 */
1584 sccb_w_array(gspca_dev, sensor_start_ov965x_1_xga,
1585 ARRAY_SIZE(sensor_start_ov965x_1_xga));
1586 reg_w_array(gspca_dev, bridge_start_ov965x_xga,
1587 ARRAY_SIZE(bridge_start_ov965x_xga));
1588 sccb_w_array(gspca_dev, sensor_start_ov965x_2_svga,
1589 ARRAY_SIZE(sensor_start_ov965x_2_svga));
1590 break;
1591 case 0: /* 1280x1024 */
1592 sccb_w_array(gspca_dev, sensor_start_ov965x_1_sxga,
1593 ARRAY_SIZE(sensor_start_ov965x_1_sxga));
1594 reg_w_array(gspca_dev, bridge_start_ov965x_sxga,
1595 ARRAY_SIZE(bridge_start_ov965x_sxga));
1596 sccb_w_array(gspca_dev, sensor_start_ov965x_2_sxga,
1597 ARRAY_SIZE(sensor_start_ov965x_2_sxga));
1598 break;
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -03001599 }
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001600 sccb_w_array(gspca_dev, sensor_start_ov965x_2,
1601 ARRAY_SIZE(sensor_start_ov965x_2));
1602 ov534_reg_write(gspca_dev, 0xe0, 0x00);
1603 ov534_reg_write(gspca_dev, 0xe0, 0x00);
1604 ov534_set_led(gspca_dev, 1);
1605 return 0;
1606}
1607
1608static void sd_stopN_ov772x(struct gspca_dev *gspca_dev)
1609{
1610 ov534_reg_write(gspca_dev, 0xe0, 0x09);
1611 ov534_set_led(gspca_dev, 0);
1612}
1613
1614static void sd_stopN_ov965x(struct gspca_dev *gspca_dev)
1615{
1616 ov534_reg_write(gspca_dev, 0xe0, 0x01);
1617 ov534_set_led(gspca_dev, 0);
1618 ov534_reg_write(gspca_dev, 0xe0, 0x00);
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001619}
1620
Jim Parisfb139222008-12-04 04:52:40 -03001621/* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
1622#define UVC_STREAM_EOH (1 << 7)
1623#define UVC_STREAM_ERR (1 << 6)
1624#define UVC_STREAM_STI (1 << 5)
1625#define UVC_STREAM_RES (1 << 4)
1626#define UVC_STREAM_SCR (1 << 3)
1627#define UVC_STREAM_PTS (1 << 2)
1628#define UVC_STREAM_EOF (1 << 1)
1629#define UVC_STREAM_FID (1 << 0)
1630
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03001631static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1632 u8 *data, int len)
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001633{
Jean-Francois Moine8c252052008-12-04 05:06:08 -03001634 struct sd *sd = (struct sd *) gspca_dev;
Jim Parisfb139222008-12-04 04:52:40 -03001635 __u32 this_pts;
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001636 u16 this_fid;
Jim Paris0f7a50b2008-12-10 05:45:14 -03001637 int remaining_len = len;
Jean-Francois Moinec874f3a2009-06-12 03:20:46 -03001638 int payload_len;
Jim Paris0f7a50b2008-12-10 05:45:14 -03001639
Jean-Francois Moinec874f3a2009-06-12 03:20:46 -03001640 payload_len = gspca_dev->cam.bulk ? 2048 : 2040;
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001641 do {
Jean-Francois Moinec874f3a2009-06-12 03:20:46 -03001642 len = min(remaining_len, payload_len);
Jim Paris0f7a50b2008-12-10 05:45:14 -03001643
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001644 /* Payloads are prefixed with a UVC-style header. We
1645 consider a frame to start when the FID toggles, or the PTS
1646 changes. A frame ends when EOF is set, and we've received
1647 the correct number of bytes. */
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001648
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001649 /* Verify UVC header. Header length is always 12 */
1650 if (data[0] != 12 || len < 12) {
1651 PDEBUG(D_PACK, "bad header");
Jim Parisfb139222008-12-04 04:52:40 -03001652 goto discard;
1653 }
1654
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001655 /* Check errors */
1656 if (data[1] & UVC_STREAM_ERR) {
1657 PDEBUG(D_PACK, "payload error");
1658 goto discard;
Jean-Francois Moine3481c192009-03-19 06:05:06 -03001659 }
Jim Parisfb139222008-12-04 04:52:40 -03001660
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001661 /* Extract PTS and FID */
1662 if (!(data[1] & UVC_STREAM_PTS)) {
1663 PDEBUG(D_PACK, "PTS not present");
1664 goto discard;
1665 }
1666 this_pts = (data[5] << 24) | (data[4] << 16)
1667 | (data[3] << 8) | data[2];
1668 this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0;
1669
1670 /* If PTS or FID has changed, start a new frame. */
1671 if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
Jean-Francois Moineed471192009-04-23 13:52:27 -03001672 if (gspca_dev->last_packet_type == INTER_PACKET)
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03001673 gspca_frame_add(gspca_dev, LAST_PACKET,
1674 NULL, 0);
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001675 sd->last_pts = this_pts;
1676 sd->last_fid = this_fid;
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03001677 gspca_frame_add(gspca_dev, FIRST_PACKET,
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001678 data + 12, len - 12);
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001679 /* If this packet is marked as EOF, end the frame */
Jean-Francois Moineed471192009-04-23 13:52:27 -03001680 } else if (data[1] & UVC_STREAM_EOF) {
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001681 sd->last_pts = 0;
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03001682 gspca_frame_add(gspca_dev, LAST_PACKET,
1683 data + 12, len - 12);
Jean-Francois Moineed471192009-04-23 13:52:27 -03001684 } else {
1685
1686 /* Add the data from this payload */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03001687 gspca_frame_add(gspca_dev, INTER_PACKET,
1688 data + 12, len - 12);
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001689 }
1690
1691 /* Done this payload */
1692 goto scan_next;
Jim Parisfb139222008-12-04 04:52:40 -03001693
1694discard:
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001695 /* Discard data until a new frame starts. */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03001696 gspca_dev->last_packet_type = DISCARD_PACKET;
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001697
1698scan_next:
1699 remaining_len -= len;
1700 data += len;
1701 } while (remaining_len > 0);
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001702}
1703
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001704/* ov772x controls */
1705static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
1706{
1707 struct sd *sd = (struct sd *) gspca_dev;
1708
1709 sd->gain = val;
1710 if (gspca_dev->streaming)
1711 setgain(gspca_dev);
1712 return 0;
1713}
1714
1715static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
1716{
1717 struct sd *sd = (struct sd *) gspca_dev;
1718
1719 *val = sd->gain;
1720 return 0;
1721}
1722
1723static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
1724{
1725 struct sd *sd = (struct sd *) gspca_dev;
1726
1727 sd->exposure = val;
1728 if (gspca_dev->streaming)
1729 setexposure(gspca_dev);
1730 return 0;
1731}
1732
1733static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
1734{
1735 struct sd *sd = (struct sd *) gspca_dev;
1736
1737 *val = sd->exposure;
1738 return 0;
1739}
1740
Jean-Francois Moineb014f942009-11-11 14:28:53 -03001741static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
1742{
1743 struct sd *sd = (struct sd *) gspca_dev;
1744
1745 sd->brightness = val;
1746 if (gspca_dev->streaming)
Jean-Francois Moine69f1fe22009-11-12 06:10:36 -03001747 setbrightness(gspca_dev);
Jean-Francois Moineb014f942009-11-11 14:28:53 -03001748 return 0;
1749}
1750
1751static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
1752{
1753 struct sd *sd = (struct sd *) gspca_dev;
1754
1755 *val = sd->brightness;
1756 return 0;
1757}
1758
1759static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
1760{
1761 struct sd *sd = (struct sd *) gspca_dev;
1762
1763 sd->contrast = val;
1764 if (gspca_dev->streaming)
1765 setcontrast(gspca_dev);
1766 return 0;
1767}
1768
1769static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
1770{
1771 struct sd *sd = (struct sd *) gspca_dev;
1772
1773 *val = sd->contrast;
1774 return 0;
1775}
1776
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001777static int sd_setredblc(struct gspca_dev *gspca_dev, __s32 val)
1778{
1779 struct sd *sd = (struct sd *) gspca_dev;
1780
1781 sd->redblc = val;
1782 if (gspca_dev->streaming)
1783 setredblc(gspca_dev);
1784 return 0;
1785}
1786
1787static int sd_getredblc(struct gspca_dev *gspca_dev, __s32 *val)
1788{
1789 struct sd *sd = (struct sd *) gspca_dev;
1790
1791 *val = sd->redblc;
1792 return 0;
1793}
1794
1795static int sd_setblueblc(struct gspca_dev *gspca_dev, __s32 val)
1796{
1797 struct sd *sd = (struct sd *) gspca_dev;
1798
1799 sd->blueblc = val;
1800 if (gspca_dev->streaming)
1801 setblueblc(gspca_dev);
1802 return 0;
1803}
1804
1805static int sd_getblueblc(struct gspca_dev *gspca_dev, __s32 *val)
1806{
1807 struct sd *sd = (struct sd *) gspca_dev;
1808
1809 *val = sd->blueblc;
1810 return 0;
1811}
1812
Jean-Francois Moineb014f942009-11-11 14:28:53 -03001813static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
1814{
1815 struct sd *sd = (struct sd *) gspca_dev;
1816
1817 sd->hue = val;
1818 if (gspca_dev->streaming)
1819 sethue(gspca_dev);
1820 return 0;
1821}
1822
1823static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
1824{
1825 struct sd *sd = (struct sd *) gspca_dev;
1826
1827 *val = sd->hue;
1828 return 0;
1829}
1830
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001831static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
1832{
1833 struct sd *sd = (struct sd *) gspca_dev;
1834
1835 sd->autogain = val;
Jean-Francois Moine2d19a2c2009-11-12 16:15:44 -03001836
1837 /* the auto white balance control works only when auto gain is set */
1838 if (val)
1839 gspca_dev->ctrl_inac &= ~(1 << AWB_IDX);
1840 else
1841 gspca_dev->ctrl_inac |= (1 << AWB_IDX);
1842
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001843 if (gspca_dev->streaming)
1844 setautogain(gspca_dev);
1845 return 0;
1846}
1847
1848static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
1849{
1850 struct sd *sd = (struct sd *) gspca_dev;
1851
1852 *val = sd->autogain;
1853 return 0;
1854}
1855
Jean-Francois Moineb014f942009-11-11 14:28:53 -03001856static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val)
1857{
1858 struct sd *sd = (struct sd *) gspca_dev;
1859
1860 sd->awb = val;
1861 if (gspca_dev->streaming)
1862 setawb(gspca_dev);
1863 return 0;
1864}
1865
1866static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val)
1867{
1868 struct sd *sd = (struct sd *) gspca_dev;
1869
1870 *val = sd->awb;
1871 return 0;
1872}
1873
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001874static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
1875{
1876 struct sd *sd = (struct sd *) gspca_dev;
1877
1878 sd->sharpness = val;
1879 if (gspca_dev->streaming)
1880 setsharpness(gspca_dev);
1881 return 0;
1882}
1883
1884static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
1885{
1886 struct sd *sd = (struct sd *) gspca_dev;
1887
1888 *val = sd->sharpness;
1889 return 0;
1890}
1891
1892static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
1893{
1894 struct sd *sd = (struct sd *) gspca_dev;
1895
1896 sd->hflip = val;
1897 if (gspca_dev->streaming)
1898 sethflip(gspca_dev);
1899 return 0;
1900}
1901
1902static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
1903{
1904 struct sd *sd = (struct sd *) gspca_dev;
1905
1906 *val = sd->hflip;
1907 return 0;
1908}
1909
1910static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
1911{
1912 struct sd *sd = (struct sd *) gspca_dev;
1913
1914 sd->vflip = val;
1915 if (gspca_dev->streaming)
1916 setvflip(gspca_dev);
1917 return 0;
1918}
1919
1920static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
1921{
1922 struct sd *sd = (struct sd *) gspca_dev;
1923
1924 *val = sd->vflip;
1925 return 0;
1926}
1927
Jim Paris11d9f252008-12-10 06:06:20 -03001928/* get stream parameters (framerate) */
Jean-Francois Moine5c1a15a2008-12-21 15:02:54 -03001929static int sd_get_streamparm(struct gspca_dev *gspca_dev,
1930 struct v4l2_streamparm *parm)
Jim Paris11d9f252008-12-10 06:06:20 -03001931{
1932 struct v4l2_captureparm *cp = &parm->parm.capture;
1933 struct v4l2_fract *tpf = &cp->timeperframe;
1934 struct sd *sd = (struct sd *) gspca_dev;
1935
1936 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1937 return -EINVAL;
1938
1939 cp->capability |= V4L2_CAP_TIMEPERFRAME;
1940 tpf->numerator = 1;
1941 tpf->denominator = sd->frame_rate;
1942
1943 return 0;
1944}
1945
1946/* set stream parameters (framerate) */
Jean-Francois Moine5c1a15a2008-12-21 15:02:54 -03001947static int sd_set_streamparm(struct gspca_dev *gspca_dev,
1948 struct v4l2_streamparm *parm)
Jim Paris11d9f252008-12-10 06:06:20 -03001949{
1950 struct v4l2_captureparm *cp = &parm->parm.capture;
1951 struct v4l2_fract *tpf = &cp->timeperframe;
1952 struct sd *sd = (struct sd *) gspca_dev;
1953
1954 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1955 return -EINVAL;
1956
1957 /* Set requested framerate */
1958 sd->frame_rate = tpf->denominator / tpf->numerator;
Jean-Francois Moine69f1fe22009-11-12 06:10:36 -03001959 if (gspca_dev->streaming && sd->sensor == SENSOR_OV772X)
1960 set_frame_rate(gspca_dev);
Jim Paris11d9f252008-12-10 06:06:20 -03001961
1962 /* Return the actual framerate */
1963 tpf->numerator = 1;
1964 tpf->denominator = sd->frame_rate;
1965
1966 return 0;
1967}
1968
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001969/* sub-driver description */
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001970static const struct sd_desc sd_desc_ov772x = {
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001971 .name = MODULE_NAME,
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001972 .ctrls = sd_ctrls_ov772x,
1973 .nctrls = ARRAY_SIZE(sd_ctrls_ov772x),
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001974 .config = sd_config,
1975 .init = sd_init,
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001976 .start = sd_start_ov772x,
1977 .stopN = sd_stopN_ov772x,
1978 .pkt_scan = sd_pkt_scan,
1979 .get_streamparm = sd_get_streamparm,
1980 .set_streamparm = sd_set_streamparm,
1981};
1982
1983static const struct sd_desc sd_desc_ov965x = {
1984 .name = MODULE_NAME,
1985 .ctrls = sd_ctrls_ov965x,
1986 .nctrls = ARRAY_SIZE(sd_ctrls_ov965x),
1987 .config = sd_config,
1988 .init = sd_init,
1989 .start = sd_start_ov965x,
1990 .stopN = sd_stopN_ov965x,
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001991 .pkt_scan = sd_pkt_scan,
Jim Paris11d9f252008-12-10 06:06:20 -03001992 .get_streamparm = sd_get_streamparm,
1993 .set_streamparm = sd_set_streamparm,
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001994};
1995
1996/* -- module initialisation -- */
1997static const __devinitdata struct usb_device_id device_table[] = {
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -03001998 {USB_DEVICE(0x06f8, 0x3003), .driver_info = SENSOR_OV965X},
1999 {USB_DEVICE(0x1415, 0x2000), .driver_info = SENSOR_OV772X},
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03002000 {}
2001};
2002
2003MODULE_DEVICE_TABLE(usb, device_table);
2004
2005/* -- device connect -- */
2006static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
2007{
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03002008 return gspca_dev_probe(intf, id,
2009 id->driver_info == SENSOR_OV772X
2010 ? &sd_desc_ov772x
2011 : &sd_desc_ov965x,
2012 sizeof(struct sd),
2013 THIS_MODULE);
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03002014}
2015
2016static struct usb_driver sd_driver = {
2017 .name = MODULE_NAME,
2018 .id_table = device_table,
2019 .probe = sd_probe,
2020 .disconnect = gspca_disconnect,
2021#ifdef CONFIG_PM
2022 .suspend = gspca_suspend,
2023 .resume = gspca_resume,
2024#endif
2025};
2026
2027/* -- module insert / remove -- */
2028static int __init sd_mod_init(void)
2029{
Alexey Klimovf69e9522009-01-01 13:02:07 -03002030 int ret;
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03002031
Alexey Klimovf69e9522009-01-01 13:02:07 -03002032 ret = usb_register(&sd_driver);
2033 if (ret < 0)
Alexey Klimove6b14842009-01-01 13:04:58 -03002034 return ret;
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03002035 PDEBUG(D_PROBE, "registered");
2036 return 0;
2037}
2038
2039static void __exit sd_mod_exit(void)
2040{
2041 usb_deregister(&sd_driver);
2042 PDEBUG(D_PROBE, "deregistered");
2043}
2044
2045module_init(sd_mod_init);
2046module_exit(sd_mod_exit);