blob: 8dada2b745bc39bab4a53d4d74ae0ae5eab953da [file] [log] [blame]
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001/*
Jean-François Moine458efe22011-02-10 10:11:04 -03002 * ov534-ov7xxx 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
Max Thrun6721b512010-02-27 17:20:28 -030013 * PS3 Eye camera - brightness, contrast, awb, agc, aec controls
14 * added 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
Jean-François Moine228dd262011-02-10 09:34:57 -030052/* controls */
53enum e_ctrl {
54 BRIGHTNESS,
55 CONTRAST,
56 GAIN,
57 EXPOSURE,
58 AGC,
59 AWB,
60 AEC,
61 SHARPNESS,
62 HFLIP,
63 VFLIP,
64 LIGHTFREQ,
65 NCTRLS /* number of controls */
66};
67
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -030068/* specific webcam descriptor */
69struct sd {
70 struct gspca_dev gspca_dev; /* !! must be the first item */
Jean-François Moine228dd262011-02-10 09:34:57 -030071
72 struct gspca_ctrl ctrls[NCTRLS];
73
Jean-Francois Moine8c252052008-12-04 05:06:08 -030074 __u32 last_pts;
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -030075 u16 last_fid;
76 u8 frame_rate;
Jean-Francois Moineb014f942009-11-11 14:28:53 -030077
Jean-François Moine458efe22011-02-10 10:11:04 -030078 u8 sensor;
79};
80enum sensors {
81 SENSOR_OV767x,
82 SENSOR_OV772x,
83 NSENSORS
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -030084};
85
86/* V4L2 controls supported by the driver */
Jean-François Moine228dd262011-02-10 09:34:57 -030087static void setbrightness(struct gspca_dev *gspca_dev);
88static void setcontrast(struct gspca_dev *gspca_dev);
89static void setgain(struct gspca_dev *gspca_dev);
90static void setexposure(struct gspca_dev *gspca_dev);
Max Thrun8b7fbda2010-02-27 17:20:20 -030091static int sd_setagc(struct gspca_dev *gspca_dev, __s32 val);
Jean-François Moine228dd262011-02-10 09:34:57 -030092static void setawb(struct gspca_dev *gspca_dev);
93static void setaec(struct gspca_dev *gspca_dev);
94static void setsharpness(struct gspca_dev *gspca_dev);
95static void sethvflip(struct gspca_dev *gspca_dev);
96static void setlightfreq(struct gspca_dev *gspca_dev);
97
98static int sd_start(struct gspca_dev *gspca_dev);
99static void sd_stopN(struct gspca_dev *gspca_dev);
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300100
Jean-Francois Moinec52af792010-01-07 05:18:16 -0300101static const struct ctrl sd_ctrls[] = {
Jean-François Moine228dd262011-02-10 09:34:57 -0300102[BRIGHTNESS] = {
Antonio Ospite7f9e9e82010-03-01 08:54:33 -0300103 {
104 .id = V4L2_CID_BRIGHTNESS,
105 .type = V4L2_CTRL_TYPE_INTEGER,
106 .name = "Brightness",
107 .minimum = 0,
108 .maximum = 255,
109 .step = 1,
Jean-François Moine228dd262011-02-10 09:34:57 -0300110 .default_value = 0,
Antonio Ospite7f9e9e82010-03-01 08:54:33 -0300111 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300112 .set_control = setbrightness
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300113 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300114[CONTRAST] = {
Antonio Ospite7f9e9e82010-03-01 08:54:33 -0300115 {
116 .id = V4L2_CID_CONTRAST,
117 .type = V4L2_CTRL_TYPE_INTEGER,
118 .name = "Contrast",
119 .minimum = 0,
120 .maximum = 255,
121 .step = 1,
Jean-François Moine228dd262011-02-10 09:34:57 -0300122 .default_value = 32,
Antonio Ospite7f9e9e82010-03-01 08:54:33 -0300123 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300124 .set_control = setcontrast
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300125 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300126[GAIN] = {
Antonio Ospite7f9e9e82010-03-01 08:54:33 -0300127 {
128 .id = V4L2_CID_GAIN,
129 .type = V4L2_CTRL_TYPE_INTEGER,
130 .name = "Main Gain",
131 .minimum = 0,
132 .maximum = 63,
133 .step = 1,
Jean-François Moine228dd262011-02-10 09:34:57 -0300134 .default_value = 20,
Antonio Ospite7f9e9e82010-03-01 08:54:33 -0300135 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300136 .set_control = setgain
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300137 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300138[EXPOSURE] = {
Antonio Ospite7f9e9e82010-03-01 08:54:33 -0300139 {
140 .id = V4L2_CID_EXPOSURE,
141 .type = V4L2_CTRL_TYPE_INTEGER,
142 .name = "Exposure",
143 .minimum = 0,
144 .maximum = 255,
145 .step = 1,
Jean-François Moine228dd262011-02-10 09:34:57 -0300146 .default_value = 120,
Antonio Ospite7f9e9e82010-03-01 08:54:33 -0300147 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300148 .set_control = setexposure
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300149 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300150[AGC] = {
Antonio Ospite7f9e9e82010-03-01 08:54:33 -0300151 {
152 .id = V4L2_CID_AUTOGAIN,
153 .type = V4L2_CTRL_TYPE_BOOLEAN,
154 .name = "Auto Gain",
155 .minimum = 0,
156 .maximum = 1,
157 .step = 1,
Jean-François Moine228dd262011-02-10 09:34:57 -0300158 .default_value = 1,
Antonio Ospite7f9e9e82010-03-01 08:54:33 -0300159 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300160 .set = sd_setagc
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300161 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300162[AWB] = {
Antonio Ospite7f9e9e82010-03-01 08:54:33 -0300163 {
164 .id = V4L2_CID_AUTO_WHITE_BALANCE,
165 .type = V4L2_CTRL_TYPE_BOOLEAN,
166 .name = "Auto White Balance",
167 .minimum = 0,
168 .maximum = 1,
169 .step = 1,
Jean-François Moine228dd262011-02-10 09:34:57 -0300170 .default_value = 1,
Antonio Ospite7f9e9e82010-03-01 08:54:33 -0300171 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300172 .set_control = setawb
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300173 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300174[AEC] = {
Antonio Ospite7f9e9e82010-03-01 08:54:33 -0300175 {
176 .id = V4L2_CID_EXPOSURE_AUTO,
177 .type = V4L2_CTRL_TYPE_BOOLEAN,
178 .name = "Auto Exposure",
179 .minimum = 0,
180 .maximum = 1,
181 .step = 1,
Jean-François Moine228dd262011-02-10 09:34:57 -0300182 .default_value = 1,
Antonio Ospite7f9e9e82010-03-01 08:54:33 -0300183 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300184 .set_control = setaec
Max Thrunf2938822010-02-27 17:20:21 -0300185 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300186[SHARPNESS] = {
Antonio Ospite7f9e9e82010-03-01 08:54:33 -0300187 {
188 .id = V4L2_CID_SHARPNESS,
189 .type = V4L2_CTRL_TYPE_INTEGER,
190 .name = "Sharpness",
191 .minimum = 0,
192 .maximum = 63,
193 .step = 1,
Jean-François Moine228dd262011-02-10 09:34:57 -0300194 .default_value = 0,
Antonio Ospite7f9e9e82010-03-01 08:54:33 -0300195 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300196 .set_control = setsharpness
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300197 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300198[HFLIP] = {
Antonio Ospite7f9e9e82010-03-01 08:54:33 -0300199 {
200 .id = V4L2_CID_HFLIP,
201 .type = V4L2_CTRL_TYPE_BOOLEAN,
202 .name = "HFlip",
203 .minimum = 0,
204 .maximum = 1,
205 .step = 1,
Jean-François Moine228dd262011-02-10 09:34:57 -0300206 .default_value = 0,
Antonio Ospite7f9e9e82010-03-01 08:54:33 -0300207 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300208 .set_control = sethvflip
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300209 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300210[VFLIP] = {
Antonio Ospite7f9e9e82010-03-01 08:54:33 -0300211 {
212 .id = V4L2_CID_VFLIP,
213 .type = V4L2_CTRL_TYPE_BOOLEAN,
214 .name = "VFlip",
215 .minimum = 0,
216 .maximum = 1,
217 .step = 1,
Jean-François Moine228dd262011-02-10 09:34:57 -0300218 .default_value = 0,
Antonio Ospite7f9e9e82010-03-01 08:54:33 -0300219 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300220 .set_control = sethvflip
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300221 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300222[LIGHTFREQ] = {
Mosalam Ebrahimi4b787542010-03-08 13:52:17 -0300223 {
224 .id = V4L2_CID_POWER_LINE_FREQUENCY,
225 .type = V4L2_CTRL_TYPE_MENU,
226 .name = "Light Frequency Filter",
227 .minimum = 0,
228 .maximum = 1,
229 .step = 1,
Jean-François Moine228dd262011-02-10 09:34:57 -0300230 .default_value = 0,
Mosalam Ebrahimi4b787542010-03-08 13:52:17 -0300231 },
Jean-François Moine228dd262011-02-10 09:34:57 -0300232 .set_control = setlightfreq
Mosalam Ebrahimi4b787542010-03-08 13:52:17 -0300233 },
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300234};
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -0300235
Jean-Francois Moine569691a2009-11-14 09:45:38 -0300236static const struct v4l2_pix_format ov772x_mode[] = {
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300237 {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
238 .bytesperline = 320 * 2,
239 .sizeimage = 320 * 240 * 2,
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300240 .colorspace = V4L2_COLORSPACE_SRGB,
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300241 .priv = 1},
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -0300242 {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
243 .bytesperline = 640 * 2,
244 .sizeimage = 640 * 480 * 2,
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300245 .colorspace = V4L2_COLORSPACE_SRGB,
246 .priv = 0},
247};
Jean-François Moine458efe22011-02-10 10:11:04 -0300248static const struct v4l2_pix_format ov767x_mode[] = {
249 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
250 .bytesperline = 320,
251 .sizeimage = 320 * 240 * 3 / 8 + 590,
252 .colorspace = V4L2_COLORSPACE_JPEG},
253 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
254 .bytesperline = 640,
255 .sizeimage = 640 * 480 * 3 / 8 + 590,
256 .colorspace = V4L2_COLORSPACE_JPEG},
257};
Jean-Francois Moine191d0e72009-05-22 04:16:42 -0300258
Antonio Ospite29b87f02010-01-17 03:27:04 -0300259static const u8 qvga_rates[] = {125, 100, 75, 60, 50, 40, 30};
260static const u8 vga_rates[] = {60, 50, 40, 30, 15};
261
262static const struct framerates ov772x_framerates[] = {
263 { /* 320x240 */
264 .rates = qvga_rates,
265 .nrates = ARRAY_SIZE(qvga_rates),
266 },
267 { /* 640x480 */
268 .rates = vga_rates,
269 .nrates = ARRAY_SIZE(vga_rates),
270 },
271};
272
Jean-François Moine458efe22011-02-10 10:11:04 -0300273struct reg_array {
274 const u8 (*val)[2];
275 int len;
276};
277
278static const u8 bridge_init_767x[][2] = {
279/* comments from the ms-win file apollo7670.set */
280/* str1 */
281 {0xf1, 0x42},
282 {0x88, 0xf8},
283 {0x89, 0xff},
284 {0x76, 0x03},
285 {0x92, 0x03},
286 {0x95, 0x10},
287 {0xe2, 0x00},
288 {0xe7, 0x3e},
289 {0x8d, 0x1c},
290 {0x8e, 0x00},
291 {0x8f, 0x00},
292 {0x1f, 0x00},
293 {0xc3, 0xf9},
294 {0x89, 0xff},
295 {0x88, 0xf8},
296 {0x76, 0x03},
297 {0x92, 0x01},
298 {0x93, 0x18},
299 {0x1c, 0x00},
300 {0x1d, 0x48},
301 {0x1d, 0x00},
302 {0x1d, 0xff},
303 {0x1d, 0x02},
304 {0x1d, 0x58},
305 {0x1d, 0x00},
306 {0x1c, 0x0a},
307 {0x1d, 0x0a},
308 {0x1d, 0x0e},
309 {0xc0, 0x50}, /* HSize 640 */
310 {0xc1, 0x3c}, /* VSize 480 */
311 {0x34, 0x05}, /* enable Audio Suspend mode */
312 {0xc2, 0x0c}, /* Input YUV */
313 {0xc3, 0xf9}, /* enable PRE */
314 {0x34, 0x05}, /* enable Audio Suspend mode */
315 {0xe7, 0x2e}, /* this solves failure of "SuspendResumeTest" */
316 {0x31, 0xf9}, /* enable 1.8V Suspend */
317 {0x35, 0x02}, /* turn on JPEG */
318 {0xd9, 0x10},
319 {0x25, 0x42}, /* GPIO[8]:Input */
320 {0x94, 0x11}, /* If the default setting is loaded when
321 * system boots up, this flag is closed here */
322};
323static const u8 sensor_init_767x[][2] = {
324 {0x12, 0x80},
325 {0x11, 0x03},
326 {0x3a, 0x04},
327 {0x12, 0x00},
328 {0x17, 0x13},
329 {0x18, 0x01},
330 {0x32, 0xb6},
331 {0x19, 0x02},
332 {0x1a, 0x7a},
333 {0x03, 0x0a},
334 {0x0c, 0x00},
335 {0x3e, 0x00},
336 {0x70, 0x3a},
337 {0x71, 0x35},
338 {0x72, 0x11},
339 {0x73, 0xf0},
340 {0xa2, 0x02},
341 {0x7a, 0x2a}, /* set Gamma=1.6 below */
342 {0x7b, 0x12},
343 {0x7c, 0x1d},
344 {0x7d, 0x2d},
345 {0x7e, 0x45},
346 {0x7f, 0x50},
347 {0x80, 0x59},
348 {0x81, 0x62},
349 {0x82, 0x6b},
350 {0x83, 0x73},
351 {0x84, 0x7b},
352 {0x85, 0x8a},
353 {0x86, 0x98},
354 {0x87, 0xb2},
355 {0x88, 0xca},
356 {0x89, 0xe0},
357 {0x13, 0xe0},
358 {0x00, 0x00},
359 {0x10, 0x00},
360 {0x0d, 0x40},
361 {0x14, 0x38}, /* gain max 16x */
362 {0xa5, 0x05},
363 {0xab, 0x07},
364 {0x24, 0x95},
365 {0x25, 0x33},
366 {0x26, 0xe3},
367 {0x9f, 0x78},
368 {0xa0, 0x68},
369 {0xa1, 0x03},
370 {0xa6, 0xd8},
371 {0xa7, 0xd8},
372 {0xa8, 0xf0},
373 {0xa9, 0x90},
374 {0xaa, 0x94},
375 {0x13, 0xe5},
376 {0x0e, 0x61},
377 {0x0f, 0x4b},
378 {0x16, 0x02},
379 {0x21, 0x02},
380 {0x22, 0x91},
381 {0x29, 0x07},
382 {0x33, 0x0b},
383 {0x35, 0x0b},
384 {0x37, 0x1d},
385 {0x38, 0x71},
386 {0x39, 0x2a},
387 {0x3c, 0x78},
388 {0x4d, 0x40},
389 {0x4e, 0x20},
390 {0x69, 0x00},
391 {0x6b, 0x4a},
392 {0x74, 0x10},
393 {0x8d, 0x4f},
394 {0x8e, 0x00},
395 {0x8f, 0x00},
396 {0x90, 0x00},
397 {0x91, 0x00},
398 {0x96, 0x00},
399 {0x9a, 0x80},
400 {0xb0, 0x84},
401 {0xb1, 0x0c},
402 {0xb2, 0x0e},
403 {0xb3, 0x82},
404 {0xb8, 0x0a},
405 {0x43, 0x0a},
406 {0x44, 0xf0},
407 {0x45, 0x34},
408 {0x46, 0x58},
409 {0x47, 0x28},
410 {0x48, 0x3a},
411 {0x59, 0x88},
412 {0x5a, 0x88},
413 {0x5b, 0x44},
414 {0x5c, 0x67},
415 {0x5d, 0x49},
416 {0x5e, 0x0e},
417 {0x6c, 0x0a},
418 {0x6d, 0x55},
419 {0x6e, 0x11},
420 {0x6f, 0x9f},
421 {0x6a, 0x40},
422 {0x01, 0x40},
423 {0x02, 0x40},
424 {0x13, 0xe7},
425 {0x4f, 0x80},
426 {0x50, 0x80},
427 {0x51, 0x00},
428 {0x52, 0x22},
429 {0x53, 0x5e},
430 {0x54, 0x80},
431 {0x58, 0x9e},
432 {0x41, 0x08},
433 {0x3f, 0x00},
434 {0x75, 0x04},
435 {0x76, 0xe1},
436 {0x4c, 0x00},
437 {0x77, 0x01},
438 {0x3d, 0xc2},
439 {0x4b, 0x09},
440 {0xc9, 0x60},
441 {0x41, 0x38}, /* jfm: auto sharpness + auto de-noise */
442 {0x56, 0x40},
443 {0x34, 0x11},
444 {0x3b, 0xc2},
445 {0xa4, 0x8a}, /* Night mode trigger point */
446 {0x96, 0x00},
447 {0x97, 0x30},
448 {0x98, 0x20},
449 {0x99, 0x20},
450 {0x9a, 0x84},
451 {0x9b, 0x29},
452 {0x9c, 0x03},
453 {0x9d, 0x4c},
454 {0x9e, 0x3f},
455 {0x78, 0x04},
456 {0x79, 0x01},
457 {0xc8, 0xf0},
458 {0x79, 0x0f},
459 {0xc8, 0x00},
460 {0x79, 0x10},
461 {0xc8, 0x7e},
462 {0x79, 0x0a},
463 {0xc8, 0x80},
464 {0x79, 0x0b},
465 {0xc8, 0x01},
466 {0x79, 0x0c},
467 {0xc8, 0x0f},
468 {0x79, 0x0d},
469 {0xc8, 0x20},
470 {0x79, 0x09},
471 {0xc8, 0x80},
472 {0x79, 0x02},
473 {0xc8, 0xc0},
474 {0x79, 0x03},
475 {0xc8, 0x20},
476 {0x79, 0x26},
477};
478static const u8 bridge_start_vga_767x[][2] = {
479/* str59 JPG */
480 {0x94, 0xaa},
481 {0xf1, 0x42},
482 {0xe5, 0x04},
483 {0xc0, 0x50},
484 {0xc1, 0x3c},
485 {0xc2, 0x0c},
486 {0x35, 0x02}, /* turn on JPEG */
487 {0xd9, 0x10},
488 {0xda, 0x00}, /* for higher clock rate(30fps) */
489 {0x34, 0x05}, /* enable Audio Suspend mode */
490 {0xc3, 0xf9}, /* enable PRE */
491 {0x8c, 0x00}, /* CIF VSize LSB[2:0] */
492 {0x8d, 0x1c}, /* output YUV */
493/* {0x34, 0x05}, * enable Audio Suspend mode (?) */
494 {0x50, 0x00}, /* H/V divider=0 */
495 {0x51, 0xa0}, /* input H=640/4 */
496 {0x52, 0x3c}, /* input V=480/4 */
497 {0x53, 0x00}, /* offset X=0 */
498 {0x54, 0x00}, /* offset Y=0 */
499 {0x55, 0x00}, /* H/V size[8]=0 */
500 {0x57, 0x00}, /* H-size[9]=0 */
501 {0x5c, 0x00}, /* output size[9:8]=0 */
502 {0x5a, 0xa0}, /* output H=640/4 */
503 {0x5b, 0x78}, /* output V=480/4 */
504 {0x1c, 0x0a},
505 {0x1d, 0x0a},
506 {0x94, 0x11},
507};
508static const u8 sensor_start_vga_767x[][2] = {
509 {0x11, 0x01},
510 {0x1e, 0x04},
511 {0x19, 0x02},
512 {0x1a, 0x7a},
513};
514static const u8 bridge_start_qvga_767x[][2] = {
515/* str86 JPG */
516 {0x94, 0xaa},
517 {0xf1, 0x42},
518 {0xe5, 0x04},
519 {0xc0, 0x80},
520 {0xc1, 0x60},
521 {0xc2, 0x0c},
522 {0x35, 0x02}, /* turn on JPEG */
523 {0xd9, 0x10},
524 {0xc0, 0x50}, /* CIF HSize 640 */
525 {0xc1, 0x3c}, /* CIF VSize 480 */
526 {0x8c, 0x00}, /* CIF VSize LSB[2:0] */
527 {0x8d, 0x1c}, /* output YUV */
528 {0x34, 0x05}, /* enable Audio Suspend mode */
529 {0xc2, 0x4c}, /* output YUV and Enable DCW */
530 {0xc3, 0xf9}, /* enable PRE */
531 {0x1c, 0x00}, /* indirect addressing */
532 {0x1d, 0x48}, /* output YUV422 */
533 {0x50, 0x89}, /* H/V divider=/2; plus DCW AVG */
534 {0x51, 0xa0}, /* DCW input H=640/4 */
535 {0x52, 0x78}, /* DCW input V=480/4 */
536 {0x53, 0x00}, /* offset X=0 */
537 {0x54, 0x00}, /* offset Y=0 */
538 {0x55, 0x00}, /* H/V size[8]=0 */
539 {0x57, 0x00}, /* H-size[9]=0 */
540 {0x5c, 0x00}, /* DCW output size[9:8]=0 */
541 {0x5a, 0x50}, /* DCW output H=320/4 */
542 {0x5b, 0x3c}, /* DCW output V=240/4 */
543 {0x1c, 0x0a},
544 {0x1d, 0x0a},
545 {0x94, 0x11},
546};
547static const u8 sensor_start_qvga_767x[][2] = {
548 {0x11, 0x01},
549 {0x1e, 0x04},
550 {0x19, 0x02},
551 {0x1a, 0x7a},
552};
553
554static const u8 bridge_init_772x[][2] = {
Jim Paris47dfd212008-12-04 04:28:27 -0300555 { 0xc2, 0x0c },
556 { 0x88, 0xf8 },
557 { 0xc3, 0x69 },
558 { 0x89, 0xff },
559 { 0x76, 0x03 },
560 { 0x92, 0x01 },
561 { 0x93, 0x18 },
562 { 0x94, 0x10 },
563 { 0x95, 0x10 },
564 { 0xe2, 0x00 },
565 { 0xe7, 0x3e },
566
Jim Paris47dfd212008-12-04 04:28:27 -0300567 { 0x96, 0x00 },
568
569 { 0x97, 0x20 },
570 { 0x97, 0x20 },
571 { 0x97, 0x20 },
572 { 0x97, 0x0a },
573 { 0x97, 0x3f },
574 { 0x97, 0x4a },
575 { 0x97, 0x20 },
576 { 0x97, 0x15 },
577 { 0x97, 0x0b },
578
579 { 0x8e, 0x40 },
580 { 0x1f, 0x81 },
581 { 0x34, 0x05 },
582 { 0xe3, 0x04 },
583 { 0x88, 0x00 },
584 { 0x89, 0x00 },
585 { 0x76, 0x00 },
586 { 0xe7, 0x2e },
587 { 0x31, 0xf9 },
588 { 0x25, 0x42 },
589 { 0x21, 0xf0 },
590
591 { 0x1c, 0x00 },
592 { 0x1d, 0x40 },
Jim Paris0f7a50b2008-12-10 05:45:14 -0300593 { 0x1d, 0x02 }, /* payload size 0x0200 * 4 = 2048 bytes */
594 { 0x1d, 0x00 }, /* payload size */
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300595
Jim Paris5ea9c4d2008-12-04 04:36:14 -0300596 { 0x1d, 0x02 }, /* frame size 0x025800 * 4 = 614400 */
597 { 0x1d, 0x58 }, /* frame size */
598 { 0x1d, 0x00 }, /* frame size */
Jim Paris47dfd212008-12-04 04:28:27 -0300599
Jim Parisc06eb612008-12-10 05:47:44 -0300600 { 0x1c, 0x0a },
601 { 0x1d, 0x08 }, /* turn on UVC header */
602 { 0x1d, 0x0e }, /* .. */
603
Jim Paris47dfd212008-12-04 04:28:27 -0300604 { 0x8d, 0x1c },
605 { 0x8e, 0x80 },
606 { 0xe5, 0x04 },
607
608 { 0xc0, 0x50 },
609 { 0xc1, 0x3c },
610 { 0xc2, 0x0c },
611};
Jean-François Moine458efe22011-02-10 10:11:04 -0300612static const u8 sensor_init_772x[][2] = {
Jim Paris47dfd212008-12-04 04:28:27 -0300613 { 0x12, 0x80 },
614 { 0x11, 0x01 },
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300615/*fixme: better have a delay?*/
616 { 0x11, 0x01 },
617 { 0x11, 0x01 },
618 { 0x11, 0x01 },
619 { 0x11, 0x01 },
620 { 0x11, 0x01 },
621 { 0x11, 0x01 },
622 { 0x11, 0x01 },
623 { 0x11, 0x01 },
624 { 0x11, 0x01 },
625 { 0x11, 0x01 },
Jim Paris47dfd212008-12-04 04:28:27 -0300626
627 { 0x3d, 0x03 },
628 { 0x17, 0x26 },
629 { 0x18, 0xa0 },
630 { 0x19, 0x07 },
631 { 0x1a, 0xf0 },
632 { 0x32, 0x00 },
633 { 0x29, 0xa0 },
634 { 0x2c, 0xf0 },
635 { 0x65, 0x20 },
636 { 0x11, 0x01 },
637 { 0x42, 0x7f },
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300638 { 0x63, 0xaa }, /* AWB - was e0 */
Jim Paris47dfd212008-12-04 04:28:27 -0300639 { 0x64, 0xff },
640 { 0x66, 0x00 },
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300641 { 0x13, 0xf0 }, /* com8 */
Jim Paris47dfd212008-12-04 04:28:27 -0300642 { 0x0d, 0x41 },
643 { 0x0f, 0xc5 },
644 { 0x14, 0x11 },
645
646 { 0x22, 0x7f },
647 { 0x23, 0x03 },
648 { 0x24, 0x40 },
649 { 0x25, 0x30 },
650 { 0x26, 0xa1 },
651 { 0x2a, 0x00 },
652 { 0x2b, 0x00 },
653 { 0x6b, 0xaa },
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300654 { 0x13, 0xff }, /* AWB */
Jim Paris47dfd212008-12-04 04:28:27 -0300655
656 { 0x90, 0x05 },
657 { 0x91, 0x01 },
658 { 0x92, 0x03 },
659 { 0x93, 0x00 },
660 { 0x94, 0x60 },
661 { 0x95, 0x3c },
662 { 0x96, 0x24 },
663 { 0x97, 0x1e },
664 { 0x98, 0x62 },
665 { 0x99, 0x80 },
666 { 0x9a, 0x1e },
667 { 0x9b, 0x08 },
668 { 0x9c, 0x20 },
669 { 0x9e, 0x81 },
670
671 { 0xa6, 0x04 },
672 { 0x7e, 0x0c },
673 { 0x7f, 0x16 },
674 { 0x80, 0x2a },
675 { 0x81, 0x4e },
676 { 0x82, 0x61 },
677 { 0x83, 0x6f },
678 { 0x84, 0x7b },
679 { 0x85, 0x86 },
680 { 0x86, 0x8e },
681 { 0x87, 0x97 },
682 { 0x88, 0xa4 },
683 { 0x89, 0xaf },
684 { 0x8a, 0xc5 },
685 { 0x8b, 0xd7 },
686 { 0x8c, 0xe8 },
687 { 0x8d, 0x20 },
688
689 { 0x0c, 0x90 },
690
691 { 0x2b, 0x00 },
692 { 0x22, 0x7f },
693 { 0x23, 0x03 },
694 { 0x11, 0x01 },
695 { 0x0c, 0xd0 },
696 { 0x64, 0xff },
697 { 0x0d, 0x41 },
698
699 { 0x14, 0x41 },
700 { 0x0e, 0xcd },
701 { 0xac, 0xbf },
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300702 { 0x8e, 0x00 }, /* De-noise threshold */
Jim Paris47dfd212008-12-04 04:28:27 -0300703 { 0x0c, 0xd0 }
704};
Jean-François Moine458efe22011-02-10 10:11:04 -0300705static const u8 bridge_start_vga_772x[][2] = {
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300706 {0x1c, 0x00},
707 {0x1d, 0x40},
708 {0x1d, 0x02},
709 {0x1d, 0x00},
710 {0x1d, 0x02},
711 {0x1d, 0x58},
712 {0x1d, 0x00},
713 {0xc0, 0x50},
714 {0xc1, 0x3c},
715};
Jean-François Moine458efe22011-02-10 10:11:04 -0300716static const u8 sensor_start_vga_772x[][2] = {
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300717 {0x12, 0x00},
718 {0x17, 0x26},
719 {0x18, 0xa0},
720 {0x19, 0x07},
721 {0x1a, 0xf0},
722 {0x29, 0xa0},
723 {0x2c, 0xf0},
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300724 {0x65, 0x20},
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300725};
Jean-François Moine458efe22011-02-10 10:11:04 -0300726static const u8 bridge_start_qvga_772x[][2] = {
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300727 {0x1c, 0x00},
728 {0x1d, 0x40},
729 {0x1d, 0x02},
730 {0x1d, 0x00},
731 {0x1d, 0x01},
732 {0x1d, 0x4b},
733 {0x1d, 0x00},
734 {0xc0, 0x28},
735 {0xc1, 0x1e},
736};
Jean-François Moine458efe22011-02-10 10:11:04 -0300737static const u8 sensor_start_qvga_772x[][2] = {
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300738 {0x12, 0x40},
739 {0x17, 0x3f},
740 {0x18, 0x50},
741 {0x19, 0x03},
742 {0x1a, 0x78},
743 {0x29, 0x50},
744 {0x2c, 0x78},
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300745 {0x65, 0x2f},
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300746};
Jim Paris47dfd212008-12-04 04:28:27 -0300747
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300748static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
749{
750 struct usb_device *udev = gspca_dev->dev;
751 int ret;
752
Jean-François Moine14b67c22011-01-13 05:58:04 -0300753 if (gspca_dev->usb_err < 0)
754 return;
755
Jean-François Moineddffa492011-01-13 05:49:47 -0300756 PDEBUG(D_USBO, "SET 01 0000 %04x %02x", reg, val);
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300757 gspca_dev->usb_buf[0] = val;
758 ret = usb_control_msg(udev,
759 usb_sndctrlpipe(udev, 0),
760 0x01,
761 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
762 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
Jean-François Moine14b67c22011-01-13 05:58:04 -0300763 if (ret < 0) {
Jean-François Moine0b656322010-09-13 05:19:58 -0300764 err("write failed %d", ret);
Jean-François Moine14b67c22011-01-13 05:58:04 -0300765 gspca_dev->usb_err = ret;
766 }
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300767}
768
769static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg)
770{
771 struct usb_device *udev = gspca_dev->dev;
772 int ret;
773
Jean-François Moine14b67c22011-01-13 05:58:04 -0300774 if (gspca_dev->usb_err < 0)
775 return 0;
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300776 ret = usb_control_msg(udev,
777 usb_rcvctrlpipe(udev, 0),
778 0x01,
779 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
780 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
Jean-François Moineddffa492011-01-13 05:49:47 -0300781 PDEBUG(D_USBI, "GET 01 0000 %04x %02x", reg, gspca_dev->usb_buf[0]);
Jean-François Moine14b67c22011-01-13 05:58:04 -0300782 if (ret < 0) {
Jean-François Moine0b656322010-09-13 05:19:58 -0300783 err("read failed %d", ret);
Jean-François Moine14b67c22011-01-13 05:58:04 -0300784 gspca_dev->usb_err = ret;
785 }
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300786 return gspca_dev->usb_buf[0];
787}
788
789/* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
790 * (direction and output)? */
791static void ov534_set_led(struct gspca_dev *gspca_dev, int status)
792{
793 u8 data;
794
795 PDEBUG(D_CONF, "led status: %d", status);
796
797 data = ov534_reg_read(gspca_dev, 0x21);
798 data |= 0x80;
799 ov534_reg_write(gspca_dev, 0x21, data);
800
801 data = ov534_reg_read(gspca_dev, 0x23);
802 if (status)
803 data |= 0x80;
804 else
805 data &= ~0x80;
806
807 ov534_reg_write(gspca_dev, 0x23, data);
808
809 if (!status) {
810 data = ov534_reg_read(gspca_dev, 0x21);
811 data &= ~0x80;
812 ov534_reg_write(gspca_dev, 0x21, data);
813 }
814}
815
816static int sccb_check_status(struct gspca_dev *gspca_dev)
817{
818 u8 data;
819 int i;
820
821 for (i = 0; i < 5; i++) {
822 data = ov534_reg_read(gspca_dev, OV534_REG_STATUS);
823
824 switch (data) {
825 case 0x00:
826 return 1;
827 case 0x04:
828 return 0;
829 case 0x03:
830 break;
831 default:
832 PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5",
833 data, i + 1);
834 }
835 }
836 return 0;
837}
838
839static void sccb_reg_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
840{
Jean-François Moineddffa492011-01-13 05:49:47 -0300841 PDEBUG(D_USBO, "sccb write: %02x %02x", reg, val);
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300842 ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
843 ov534_reg_write(gspca_dev, OV534_REG_WRITE, val);
844 ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
845
Jean-François Moine14b67c22011-01-13 05:58:04 -0300846 if (!sccb_check_status(gspca_dev)) {
Jean-François Moine0b656322010-09-13 05:19:58 -0300847 err("sccb_reg_write failed");
Jean-François Moine14b67c22011-01-13 05:58:04 -0300848 gspca_dev->usb_err = -EIO;
849 }
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300850}
851
852static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg)
853{
854 ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
855 ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
856 if (!sccb_check_status(gspca_dev))
Jean-François Moine0b656322010-09-13 05:19:58 -0300857 err("sccb_reg_read failed 1");
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300858
859 ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
860 if (!sccb_check_status(gspca_dev))
Jean-François Moine0b656322010-09-13 05:19:58 -0300861 err("sccb_reg_read failed 2");
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -0300862
863 return ov534_reg_read(gspca_dev, OV534_REG_READ);
864}
865
866/* output a bridge sequence (reg - val) */
867static void reg_w_array(struct gspca_dev *gspca_dev,
868 const u8 (*data)[2], int len)
869{
870 while (--len >= 0) {
871 ov534_reg_write(gspca_dev, (*data)[0], (*data)[1]);
872 data++;
873 }
874}
875
876/* output a sensor sequence (reg - val) */
877static void sccb_w_array(struct gspca_dev *gspca_dev,
878 const u8 (*data)[2], int len)
879{
880 while (--len >= 0) {
881 if ((*data)[0] != 0xff) {
882 sccb_reg_write(gspca_dev, (*data)[0], (*data)[1]);
883 } else {
884 sccb_reg_read(gspca_dev, (*data)[1]);
885 sccb_reg_write(gspca_dev, 0xff, 0x00);
886 }
887 data++;
888 }
889}
890
Jean-Francois Moine69f1fe22009-11-12 06:10:36 -0300891/* ov772x specific controls */
892static void set_frame_rate(struct gspca_dev *gspca_dev)
Jim Paris11d9f252008-12-10 06:06:20 -0300893{
894 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300895 int i;
896 struct rate_s {
897 u8 fps;
898 u8 r11;
899 u8 r0d;
900 u8 re5;
901 };
902 const struct rate_s *r;
903 static const struct rate_s rate_0[] = { /* 640x480 */
904 {60, 0x01, 0xc1, 0x04},
905 {50, 0x01, 0x41, 0x02},
906 {40, 0x02, 0xc1, 0x04},
907 {30, 0x04, 0x81, 0x02},
908 {15, 0x03, 0x41, 0x04},
909 };
910 static const struct rate_s rate_1[] = { /* 320x240 */
911 {125, 0x02, 0x81, 0x02},
912 {100, 0x02, 0xc1, 0x04},
913 {75, 0x03, 0xc1, 0x04},
914 {60, 0x04, 0xc1, 0x04},
915 {50, 0x02, 0x41, 0x04},
916 {40, 0x03, 0x41, 0x04},
917 {30, 0x04, 0x41, 0x04},
918 };
Jim Paris11d9f252008-12-10 06:06:20 -0300919
Jean-François Moine458efe22011-02-10 10:11:04 -0300920 if (sd->sensor != SENSOR_OV772x)
921 return;
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300922 if (gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv == 0) {
923 r = rate_0;
924 i = ARRAY_SIZE(rate_0);
925 } else {
926 r = rate_1;
927 i = ARRAY_SIZE(rate_1);
928 }
929 while (--i > 0) {
930 if (sd->frame_rate >= r->fps)
931 break;
932 r++;
Jim Paris11d9f252008-12-10 06:06:20 -0300933 }
934
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300935 sccb_reg_write(gspca_dev, 0x11, r->r11);
936 sccb_reg_write(gspca_dev, 0x0d, r->r0d);
937 ov534_reg_write(gspca_dev, 0xe5, r->re5);
938
939 PDEBUG(D_PROBE, "frame_rate: %d", r->fps);
940}
941
Jean-Francois Moinec52af792010-01-07 05:18:16 -0300942static void setbrightness(struct gspca_dev *gspca_dev)
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300943{
944 struct sd *sd = (struct sd *) gspca_dev;
Jean-François Moine458efe22011-02-10 10:11:04 -0300945 int val;
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300946
Jean-François Moine458efe22011-02-10 10:11:04 -0300947 val = sd->ctrls[BRIGHTNESS].val;
948 if (sd->sensor == SENSOR_OV767x) {
949 if (val < 0)
950 val = 0x80 - val;
951 sccb_reg_write(gspca_dev, 0x55, val); /* bright */
952 } else {
953 sccb_reg_write(gspca_dev, 0x9b, val);
954 }
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300955}
956
Jean-Francois Moinec52af792010-01-07 05:18:16 -0300957static void setcontrast(struct gspca_dev *gspca_dev)
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300958{
959 struct sd *sd = (struct sd *) gspca_dev;
Jean-François Moine458efe22011-02-10 10:11:04 -0300960 u8 val;
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300961
Jean-François Moine458efe22011-02-10 10:11:04 -0300962 val = sd->ctrls[CONTRAST].val;
963 if (sd->sensor == SENSOR_OV767x)
964 sccb_reg_write(gspca_dev, 0x56, val); /* contras */
965 else
966 sccb_reg_write(gspca_dev, 0x9c, val);
Jean-Francois Moineb014f942009-11-11 14:28:53 -0300967}
968
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300969static void setgain(struct gspca_dev *gspca_dev)
970{
971 struct sd *sd = (struct sd *) gspca_dev;
972 u8 val;
973
Jean-François Moine228dd262011-02-10 09:34:57 -0300974 if (sd->ctrls[AGC].val)
Max Thrun8b7fbda2010-02-27 17:20:20 -0300975 return;
976
Jean-François Moine228dd262011-02-10 09:34:57 -0300977 val = sd->ctrls[GAIN].val;
Jean-Francois Moine189d92a2009-11-11 07:46:28 -0300978 switch (val & 0x30) {
979 case 0x00:
980 val &= 0x0f;
981 break;
982 case 0x10:
983 val &= 0x0f;
984 val |= 0x30;
985 break;
986 case 0x20:
987 val &= 0x0f;
988 val |= 0x70;
989 break;
990 default:
991/* case 0x30: */
992 val &= 0x0f;
993 val |= 0xf0;
994 break;
995 }
996 sccb_reg_write(gspca_dev, 0x00, val);
997}
998
Jean-Francois Moinec52af792010-01-07 05:18:16 -0300999static void setexposure(struct gspca_dev *gspca_dev)
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001000{
1001 struct sd *sd = (struct sd *) gspca_dev;
1002 u8 val;
1003
Jean-François Moine228dd262011-02-10 09:34:57 -03001004 if (sd->ctrls[AEC].val)
Antonio Ospite18cf8c92010-03-01 08:53:34 -03001005 return;
1006
Jean-François Moine228dd262011-02-10 09:34:57 -03001007 val = sd->ctrls[EXPOSURE].val;
Jean-François Moine458efe22011-02-10 10:11:04 -03001008 if (sd->sensor == SENSOR_OV767x) {
1009
1010 /* set only aec[9:2] */
1011 sccb_reg_write(gspca_dev, 0x10, val); /* aech */
1012 } else {
1013
1014 /* 'val' is one byte and represents half of the exposure value
1015 * we are going to set into registers, a two bytes value:
1016 *
1017 * MSB: ((u16) val << 1) >> 8 == val >> 7
1018 * LSB: ((u16) val << 1) & 0xff == val << 1
1019 */
1020 sccb_reg_write(gspca_dev, 0x08, val >> 7);
1021 sccb_reg_write(gspca_dev, 0x10, val << 1);
1022 }
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001023}
1024
Max Thrun8b7fbda2010-02-27 17:20:20 -03001025static void setagc(struct gspca_dev *gspca_dev)
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001026{
1027 struct sd *sd = (struct sd *) gspca_dev;
1028
Jean-François Moine228dd262011-02-10 09:34:57 -03001029 if (sd->ctrls[AGC].val) {
Max Thrun8b7fbda2010-02-27 17:20:20 -03001030 sccb_reg_write(gspca_dev, 0x13,
1031 sccb_reg_read(gspca_dev, 0x13) | 0x04);
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001032 sccb_reg_write(gspca_dev, 0x64,
1033 sccb_reg_read(gspca_dev, 0x64) | 0x03);
1034 } else {
Max Thrun8b7fbda2010-02-27 17:20:20 -03001035 sccb_reg_write(gspca_dev, 0x13,
1036 sccb_reg_read(gspca_dev, 0x13) & ~0x04);
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001037 sccb_reg_write(gspca_dev, 0x64,
Max Thrun8b7fbda2010-02-27 17:20:20 -03001038 sccb_reg_read(gspca_dev, 0x64) & ~0x03);
1039
1040 setgain(gspca_dev);
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001041 }
1042}
1043
Jean-Francois Moineb014f942009-11-11 14:28:53 -03001044static void setawb(struct gspca_dev *gspca_dev)
1045{
1046 struct sd *sd = (struct sd *) gspca_dev;
1047
Jean-François Moine228dd262011-02-10 09:34:57 -03001048 if (sd->ctrls[AWB].val) {
Max Thrun8fef9d92010-02-27 17:20:23 -03001049 sccb_reg_write(gspca_dev, 0x13,
1050 sccb_reg_read(gspca_dev, 0x13) | 0x02);
Jean-François Moine458efe22011-02-10 10:11:04 -03001051 if (sd->sensor == SENSOR_OV772x)
1052 sccb_reg_write(gspca_dev, 0x63,
Max Thrun8fef9d92010-02-27 17:20:23 -03001053 sccb_reg_read(gspca_dev, 0x63) | 0xc0);
1054 } else {
1055 sccb_reg_write(gspca_dev, 0x13,
1056 sccb_reg_read(gspca_dev, 0x13) & ~0x02);
Jean-François Moine458efe22011-02-10 10:11:04 -03001057 if (sd->sensor == SENSOR_OV772x)
1058 sccb_reg_write(gspca_dev, 0x63,
Max Thrun8fef9d92010-02-27 17:20:23 -03001059 sccb_reg_read(gspca_dev, 0x63) & ~0xc0);
1060 }
Jean-Francois Moineb014f942009-11-11 14:28:53 -03001061}
1062
Max Thrunf2938822010-02-27 17:20:21 -03001063static void setaec(struct gspca_dev *gspca_dev)
1064{
1065 struct sd *sd = (struct sd *) gspca_dev;
Jean-François Moine458efe22011-02-10 10:11:04 -03001066 u8 data;
Max Thrunf2938822010-02-27 17:20:21 -03001067
Jean-François Moine458efe22011-02-10 10:11:04 -03001068 data = sd->sensor == SENSOR_OV767x ?
1069 0x05 : /* agc + aec */
1070 0x01; /* agc */
Jean-François Moine228dd262011-02-10 09:34:57 -03001071 if (sd->ctrls[AEC].val)
Max Thrunf2938822010-02-27 17:20:21 -03001072 sccb_reg_write(gspca_dev, 0x13,
Jean-François Moine458efe22011-02-10 10:11:04 -03001073 sccb_reg_read(gspca_dev, 0x13) | data);
Max Thrunf2938822010-02-27 17:20:21 -03001074 else {
1075 sccb_reg_write(gspca_dev, 0x13,
Jean-François Moine458efe22011-02-10 10:11:04 -03001076 sccb_reg_read(gspca_dev, 0x13) & ~data);
1077 if (sd->sensor == SENSOR_OV767x)
1078 sd->ctrls[EXPOSURE].val =
1079 sccb_reg_read(gspca_dev, 10); /* aech */
1080 else
1081 setexposure(gspca_dev);
Max Thrunf2938822010-02-27 17:20:21 -03001082 }
1083}
1084
Jean-Francois Moinec52af792010-01-07 05:18:16 -03001085static void setsharpness(struct gspca_dev *gspca_dev)
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001086{
1087 struct sd *sd = (struct sd *) gspca_dev;
1088 u8 val;
1089
Jean-François Moine228dd262011-02-10 09:34:57 -03001090 val = sd->ctrls[SHARPNESS].val;
Max Thrun3149cfb2010-02-27 17:20:24 -03001091 sccb_reg_write(gspca_dev, 0x91, val); /* Auto de-noise threshold */
1092 sccb_reg_write(gspca_dev, 0x8e, val); /* De-noise threshold */
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001093}
1094
Jean-François Moine228dd262011-02-10 09:34:57 -03001095static void sethvflip(struct gspca_dev *gspca_dev)
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001096{
1097 struct sd *sd = (struct sd *) gspca_dev;
Jean-François Moine228dd262011-02-10 09:34:57 -03001098 u8 val;
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001099
Jean-François Moine458efe22011-02-10 10:11:04 -03001100 if (sd->sensor == SENSOR_OV767x) {
1101 val = sccb_reg_read(gspca_dev, 0x1e); /* mvfp */
1102 val &= ~0x30;
1103 if (sd->ctrls[HFLIP].val)
1104 val |= 0x20;
1105 if (sd->ctrls[VFLIP].val)
1106 val |= 0x10;
1107 sccb_reg_write(gspca_dev, 0x1e, val);
1108 } else {
1109 val = sccb_reg_read(gspca_dev, 0x0c);
1110 val &= ~0xc0;
1111 if (sd->ctrls[HFLIP].val == 0)
1112 val |= 0x40;
1113 if (sd->ctrls[VFLIP].val == 0)
1114 val |= 0x80;
1115 sccb_reg_write(gspca_dev, 0x0c, val);
1116 }
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001117}
1118
Jean-François Moine228dd262011-02-10 09:34:57 -03001119static void setlightfreq(struct gspca_dev *gspca_dev)
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001120{
1121 struct sd *sd = (struct sd *) gspca_dev;
Jean-François Moine458efe22011-02-10 10:11:04 -03001122 u8 val;
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001123
Jean-François Moine458efe22011-02-10 10:11:04 -03001124 val = sd->ctrls[LIGHTFREQ].val ? 0x9e : 0x00;
1125 if (sd->sensor == SENSOR_OV767x) {
1126 sccb_reg_write(gspca_dev, 0x2a, 0x00);
1127 if (val)
1128 val = 0x9d; /* insert dummy to 25fps for 50Hz */
1129 }
1130 sccb_reg_write(gspca_dev, 0x2b, val);
Mosalam Ebrahimi4b787542010-03-08 13:52:17 -03001131}
1132
1133
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001134/* this function is called at probe time */
1135static int sd_config(struct gspca_dev *gspca_dev,
1136 const struct usb_device_id *id)
1137{
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -03001138 struct sd *sd = (struct sd *) gspca_dev;
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001139 struct cam *cam;
1140
1141 cam = &gspca_dev->cam;
1142
Jean-François Moine228dd262011-02-10 09:34:57 -03001143 cam->ctrls = sd->ctrls;
1144
1145 /* the auto white balance control works only when auto gain is set */
1146 if (sd_ctrls[AGC].qctrl.default_value == 0)
1147 gspca_dev->ctrl_inac |= (1 << AWB);
1148
Jean-Francois Moinec52af792010-01-07 05:18:16 -03001149 cam->cam_mode = ov772x_mode;
1150 cam->nmodes = ARRAY_SIZE(ov772x_mode);
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001151
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001152 sd->frame_rate = 30;
Jean-Francois Moineb014f942009-11-11 14:28:53 -03001153
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001154 return 0;
1155}
1156
1157/* this function is called at probe and resume time */
1158static int sd_init(struct gspca_dev *gspca_dev)
1159{
Jean-François Moine458efe22011-02-10 10:11:04 -03001160 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -03001161 u16 sensor_id;
Jean-François Moine458efe22011-02-10 10:11:04 -03001162 static const struct reg_array bridge_init[NSENSORS] = {
1163 [SENSOR_OV767x] = {bridge_init_767x, ARRAY_SIZE(bridge_init_767x)},
1164 [SENSOR_OV772x] = {bridge_init_772x, ARRAY_SIZE(bridge_init_772x)},
1165 };
1166 static const struct reg_array sensor_init[NSENSORS] = {
1167 [SENSOR_OV767x] = {sensor_init_767x, ARRAY_SIZE(sensor_init_767x)},
1168 [SENSOR_OV772x] = {sensor_init_772x, ARRAY_SIZE(sensor_init_772x)},
1169 };
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -03001170
1171 /* reset bridge */
1172 ov534_reg_write(gspca_dev, 0xe7, 0x3a);
1173 ov534_reg_write(gspca_dev, 0xe0, 0x08);
1174 msleep(100);
1175
1176 /* initialize the sensor address */
Jean-Francois Moinec52af792010-01-07 05:18:16 -03001177 ov534_reg_write(gspca_dev, OV534_REG_ADDRESS, 0x42);
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -03001178
1179 /* reset sensor */
1180 sccb_reg_write(gspca_dev, 0x12, 0x80);
1181 msleep(10);
1182
1183 /* probe the sensor */
1184 sccb_reg_read(gspca_dev, 0x0a);
1185 sensor_id = sccb_reg_read(gspca_dev, 0x0a) << 8;
1186 sccb_reg_read(gspca_dev, 0x0b);
1187 sensor_id |= sccb_reg_read(gspca_dev, 0x0b);
1188 PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id);
1189
Jean-François Moine458efe22011-02-10 10:11:04 -03001190 if ((sensor_id & 0xfff0) == 0x7670) {
1191 sd->sensor = SENSOR_OV767x;
1192 gspca_dev->ctrl_dis = (1 << GAIN) |
1193 (1 << AGC) |
1194 (1 << SHARPNESS); /* auto */
1195 sd->ctrls[BRIGHTNESS].min = -127;
1196 sd->ctrls[BRIGHTNESS].max = 127;
1197 sd->ctrls[BRIGHTNESS].def = 0;
1198 sd->ctrls[CONTRAST].max = 0x80;
1199 sd->ctrls[CONTRAST].def = 0x40;
1200 sd->ctrls[EXPOSURE].min = 0x08;
1201 sd->ctrls[EXPOSURE].max = 0x60;
1202 sd->ctrls[EXPOSURE].def = 0x13;
1203 sd->ctrls[SHARPNESS].max = 9;
1204 sd->ctrls[SHARPNESS].def = 4;
1205 sd->ctrls[HFLIP].def = 1;
1206 gspca_dev->cam.cam_mode = ov767x_mode;
1207 gspca_dev->cam.nmodes = ARRAY_SIZE(ov767x_mode);
1208 } else {
1209 sd->sensor = SENSOR_OV772x;
1210 gspca_dev->cam.bulk = 1;
1211 gspca_dev->cam.bulk_size = 16384;
1212 gspca_dev->cam.bulk_nurbs = 2;
1213 gspca_dev->cam.mode_framerates = ov772x_framerates;
1214 }
1215
Jean-Francois Moine2ce949e2009-03-19 06:15:21 -03001216 /* initialize */
Jean-François Moine458efe22011-02-10 10:11:04 -03001217 reg_w_array(gspca_dev, bridge_init[sd->sensor].val,
1218 bridge_init[sd->sensor].len);
Jean-Francois Moinec52af792010-01-07 05:18:16 -03001219 ov534_set_led(gspca_dev, 1);
Jean-François Moine458efe22011-02-10 10:11:04 -03001220 sccb_w_array(gspca_dev, sensor_init[sd->sensor].val,
1221 sensor_init[sd->sensor].len);
1222 if (sd->sensor == SENSOR_OV767x)
1223 sd_start(gspca_dev);
1224 sd_stopN(gspca_dev);
1225/* set_frame_rate(gspca_dev); */
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001226
Jean-François Moine14b67c22011-01-13 05:58:04 -03001227 return gspca_dev->usb_err;
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001228}
1229
Jean-Francois Moinec52af792010-01-07 05:18:16 -03001230static int sd_start(struct gspca_dev *gspca_dev)
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001231{
Jean-François Moine458efe22011-02-10 10:11:04 -03001232 struct sd *sd = (struct sd *) gspca_dev;
Jean-Francois Moine191d0e72009-05-22 04:16:42 -03001233 int mode;
Jean-François Moine458efe22011-02-10 10:11:04 -03001234 static const struct reg_array bridge_start[NSENSORS][2] = {
1235 [SENSOR_OV767x] = {{bridge_start_qvga_767x,
1236 ARRAY_SIZE(bridge_start_qvga_767x)},
1237 {bridge_start_vga_767x,
1238 ARRAY_SIZE(bridge_start_vga_767x)}},
1239 [SENSOR_OV772x] = {{bridge_start_qvga_772x,
1240 ARRAY_SIZE(bridge_start_qvga_772x)},
1241 {bridge_start_vga_772x,
1242 ARRAY_SIZE(bridge_start_vga_772x)}},
1243 };
1244 static const struct reg_array sensor_start[NSENSORS][2] = {
1245 [SENSOR_OV767x] = {{sensor_start_qvga_767x,
1246 ARRAY_SIZE(sensor_start_qvga_767x)},
1247 {sensor_start_vga_767x,
1248 ARRAY_SIZE(sensor_start_vga_767x)}},
1249 [SENSOR_OV772x] = {{sensor_start_qvga_772x,
1250 ARRAY_SIZE(sensor_start_qvga_772x)},
1251 {sensor_start_vga_772x,
1252 ARRAY_SIZE(sensor_start_vga_772x)}},
1253 };
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001254
Jean-François Moine458efe22011-02-10 10:11:04 -03001255 /* (from ms-win trace) */
1256 if (sd->sensor == SENSOR_OV767x)
1257 sccb_reg_write(gspca_dev, 0x1e, 0x04);
1258 /* black sun enable ? */
1259
1260 mode = gspca_dev->curr_mode; /* 0: 320x240, 1: 640x480 */
1261 reg_w_array(gspca_dev, bridge_start[sd->sensor][mode].val,
1262 bridge_start[sd->sensor][mode].len);
1263 sccb_w_array(gspca_dev, sensor_start[sd->sensor][mode].val,
1264 sensor_start[sd->sensor][mode].len);
1265
Jean-Francois Moine69f1fe22009-11-12 06:10:36 -03001266 set_frame_rate(gspca_dev);
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001267
Jean-François Moine228dd262011-02-10 09:34:57 -03001268 if (!(gspca_dev->ctrl_dis & (1 << AGC)))
1269 setagc(gspca_dev);
Jean-Francois Moineb014f942009-11-11 14:28:53 -03001270 setawb(gspca_dev);
Max Thrunf2938822010-02-27 17:20:21 -03001271 setaec(gspca_dev);
Jean-François Moine228dd262011-02-10 09:34:57 -03001272 if (!(gspca_dev->ctrl_dis & (1 << GAIN)))
1273 setgain(gspca_dev);
Jean-Francois Moinec52af792010-01-07 05:18:16 -03001274 setexposure(gspca_dev);
1275 setbrightness(gspca_dev);
1276 setcontrast(gspca_dev);
Jean-François Moine228dd262011-02-10 09:34:57 -03001277 if (!(gspca_dev->ctrl_dis & (1 << SHARPNESS)))
1278 setsharpness(gspca_dev);
1279 sethvflip(gspca_dev);
1280 setlightfreq(gspca_dev);
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001281
1282 ov534_set_led(gspca_dev, 1);
1283 ov534_reg_write(gspca_dev, 0xe0, 0x00);
Jean-François Moine14b67c22011-01-13 05:58:04 -03001284 return gspca_dev->usb_err;
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001285}
1286
Jean-Francois Moinec52af792010-01-07 05:18:16 -03001287static void sd_stopN(struct gspca_dev *gspca_dev)
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001288{
1289 ov534_reg_write(gspca_dev, 0xe0, 0x09);
1290 ov534_set_led(gspca_dev, 0);
1291}
1292
Jim Parisfb139222008-12-04 04:52:40 -03001293/* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
1294#define UVC_STREAM_EOH (1 << 7)
1295#define UVC_STREAM_ERR (1 << 6)
1296#define UVC_STREAM_STI (1 << 5)
1297#define UVC_STREAM_RES (1 << 4)
1298#define UVC_STREAM_SCR (1 << 3)
1299#define UVC_STREAM_PTS (1 << 2)
1300#define UVC_STREAM_EOF (1 << 1)
1301#define UVC_STREAM_FID (1 << 0)
1302
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03001303static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1304 u8 *data, int len)
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001305{
Jean-Francois Moine8c252052008-12-04 05:06:08 -03001306 struct sd *sd = (struct sd *) gspca_dev;
Jim Parisfb139222008-12-04 04:52:40 -03001307 __u32 this_pts;
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001308 u16 this_fid;
Jim Paris0f7a50b2008-12-10 05:45:14 -03001309 int remaining_len = len;
Jean-François Moine458efe22011-02-10 10:11:04 -03001310 int payload_len;
Jim Paris0f7a50b2008-12-10 05:45:14 -03001311
Jean-François Moine458efe22011-02-10 10:11:04 -03001312 payload_len = gspca_dev->cam.bulk ? 2048 : 2040;
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001313 do {
Jean-François Moine458efe22011-02-10 10:11:04 -03001314 len = min(remaining_len, payload_len);
Jim Paris0f7a50b2008-12-10 05:45:14 -03001315
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001316 /* Payloads are prefixed with a UVC-style header. We
1317 consider a frame to start when the FID toggles, or the PTS
1318 changes. A frame ends when EOF is set, and we've received
1319 the correct number of bytes. */
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001320
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001321 /* Verify UVC header. Header length is always 12 */
1322 if (data[0] != 12 || len < 12) {
1323 PDEBUG(D_PACK, "bad header");
Jim Parisfb139222008-12-04 04:52:40 -03001324 goto discard;
1325 }
1326
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001327 /* Check errors */
1328 if (data[1] & UVC_STREAM_ERR) {
1329 PDEBUG(D_PACK, "payload error");
1330 goto discard;
Jean-Francois Moine3481c192009-03-19 06:05:06 -03001331 }
Jim Parisfb139222008-12-04 04:52:40 -03001332
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001333 /* Extract PTS and FID */
1334 if (!(data[1] & UVC_STREAM_PTS)) {
1335 PDEBUG(D_PACK, "PTS not present");
1336 goto discard;
1337 }
1338 this_pts = (data[5] << 24) | (data[4] << 16)
1339 | (data[3] << 8) | data[2];
1340 this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0;
1341
1342 /* If PTS or FID has changed, start a new frame. */
1343 if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
Jean-Francois Moineed471192009-04-23 13:52:27 -03001344 if (gspca_dev->last_packet_type == INTER_PACKET)
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03001345 gspca_frame_add(gspca_dev, LAST_PACKET,
1346 NULL, 0);
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001347 sd->last_pts = this_pts;
1348 sd->last_fid = this_fid;
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03001349 gspca_frame_add(gspca_dev, FIRST_PACKET,
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001350 data + 12, len - 12);
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001351 /* If this packet is marked as EOF, end the frame */
Jean-Francois Moineed471192009-04-23 13:52:27 -03001352 } else if (data[1] & UVC_STREAM_EOF) {
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001353 sd->last_pts = 0;
Jean-François Moine458efe22011-02-10 10:11:04 -03001354 if (gspca_dev->pixfmt == V4L2_PIX_FMT_YUYV
1355 && gspca_dev->image_len + len - 12 !=
1356 gspca_dev->width * gspca_dev->height * 2) {
Antonio Ospite11edebc2010-01-17 03:42:14 -03001357 PDEBUG(D_PACK, "wrong sized frame");
Jean-Francois Moinec52af792010-01-07 05:18:16 -03001358 goto discard;
1359 }
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03001360 gspca_frame_add(gspca_dev, LAST_PACKET,
1361 data + 12, len - 12);
Jean-Francois Moineed471192009-04-23 13:52:27 -03001362 } else {
1363
1364 /* Add the data from this payload */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03001365 gspca_frame_add(gspca_dev, INTER_PACKET,
1366 data + 12, len - 12);
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001367 }
1368
1369 /* Done this payload */
1370 goto scan_next;
Jim Parisfb139222008-12-04 04:52:40 -03001371
1372discard:
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001373 /* Discard data until a new frame starts. */
Jean-Francois Moine76dd2722009-11-13 09:21:03 -03001374 gspca_dev->last_packet_type = DISCARD_PACKET;
Jean-Francois Moine84fbdf82009-03-19 06:12:59 -03001375
1376scan_next:
1377 remaining_len -= len;
1378 data += len;
1379 } while (remaining_len > 0);
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001380}
1381
Max Thrun8b7fbda2010-02-27 17:20:20 -03001382static int sd_setagc(struct gspca_dev *gspca_dev, __s32 val)
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001383{
1384 struct sd *sd = (struct sd *) gspca_dev;
1385
Jean-François Moine228dd262011-02-10 09:34:57 -03001386 sd->ctrls[AGC].val = val;
Jean-Francois Moine2d19a2c2009-11-12 16:15:44 -03001387
Jean-François Moine228dd262011-02-10 09:34:57 -03001388 /* the auto white balance control works only
1389 * when auto gain is set */
1390 if (val) {
1391 gspca_dev->ctrl_inac &= ~(1 << AWB);
1392 } else {
1393 gspca_dev->ctrl_inac |= (1 << AWB);
1394 if (sd->ctrls[AWB].val) {
1395 sd->ctrls[AWB].val = 0;
1396 if (gspca_dev->streaming)
1397 setawb(gspca_dev);
1398 }
Jean-Francois Moinec22c4a22009-11-24 05:22:05 -03001399 }
Jean-Francois Moineb014f942009-11-11 14:28:53 -03001400 if (gspca_dev->streaming)
Jean-François Moine228dd262011-02-10 09:34:57 -03001401 setagc(gspca_dev);
1402 return gspca_dev->usb_err;
Mosalam Ebrahimi4b787542010-03-08 13:52:17 -03001403}
1404
1405static int sd_querymenu(struct gspca_dev *gspca_dev,
1406 struct v4l2_querymenu *menu)
1407{
1408 switch (menu->id) {
1409 case V4L2_CID_POWER_LINE_FREQUENCY:
1410 switch (menu->index) {
1411 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
1412 strcpy((char *) menu->name, "Disabled");
1413 return 0;
1414 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
1415 strcpy((char *) menu->name, "50 Hz");
1416 return 0;
1417 }
1418 break;
1419 }
1420
1421 return -EINVAL;
1422}
1423
Jim Paris11d9f252008-12-10 06:06:20 -03001424/* get stream parameters (framerate) */
Jean-François Moine668f44a2010-12-25 13:46:14 -03001425static void sd_get_streamparm(struct gspca_dev *gspca_dev,
Jean-Francois Moine5c1a15a2008-12-21 15:02:54 -03001426 struct v4l2_streamparm *parm)
Jim Paris11d9f252008-12-10 06:06:20 -03001427{
1428 struct v4l2_captureparm *cp = &parm->parm.capture;
1429 struct v4l2_fract *tpf = &cp->timeperframe;
1430 struct sd *sd = (struct sd *) gspca_dev;
1431
Jim Paris11d9f252008-12-10 06:06:20 -03001432 cp->capability |= V4L2_CAP_TIMEPERFRAME;
1433 tpf->numerator = 1;
1434 tpf->denominator = sd->frame_rate;
Jim Paris11d9f252008-12-10 06:06:20 -03001435}
1436
1437/* set stream parameters (framerate) */
Jean-François Moine668f44a2010-12-25 13:46:14 -03001438static void sd_set_streamparm(struct gspca_dev *gspca_dev,
Jean-Francois Moine5c1a15a2008-12-21 15:02:54 -03001439 struct v4l2_streamparm *parm)
Jim Paris11d9f252008-12-10 06:06:20 -03001440{
1441 struct v4l2_captureparm *cp = &parm->parm.capture;
1442 struct v4l2_fract *tpf = &cp->timeperframe;
1443 struct sd *sd = (struct sd *) gspca_dev;
1444
Jim Paris11d9f252008-12-10 06:06:20 -03001445 /* Set requested framerate */
1446 sd->frame_rate = tpf->denominator / tpf->numerator;
Jean-Francois Moinec52af792010-01-07 05:18:16 -03001447 if (gspca_dev->streaming)
Jean-Francois Moine69f1fe22009-11-12 06:10:36 -03001448 set_frame_rate(gspca_dev);
Jim Paris11d9f252008-12-10 06:06:20 -03001449
1450 /* Return the actual framerate */
1451 tpf->numerator = 1;
1452 tpf->denominator = sd->frame_rate;
Jim Paris11d9f252008-12-10 06:06:20 -03001453}
1454
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001455/* sub-driver description */
Jean-Francois Moinec52af792010-01-07 05:18:16 -03001456static const struct sd_desc sd_desc = {
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001457 .name = MODULE_NAME,
Jean-Francois Moinec52af792010-01-07 05:18:16 -03001458 .ctrls = sd_ctrls,
1459 .nctrls = ARRAY_SIZE(sd_ctrls),
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001460 .config = sd_config,
1461 .init = sd_init,
Jean-Francois Moinec52af792010-01-07 05:18:16 -03001462 .start = sd_start,
1463 .stopN = sd_stopN,
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001464 .pkt_scan = sd_pkt_scan,
Mosalam Ebrahimi4b787542010-03-08 13:52:17 -03001465 .querymenu = sd_querymenu,
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001466 .get_streamparm = sd_get_streamparm,
1467 .set_streamparm = sd_set_streamparm,
1468};
1469
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001470/* -- module initialisation -- */
Jean-François Moine95c967c2011-01-13 05:20:29 -03001471static const struct usb_device_id device_table[] = {
Jean-Francois Moinec52af792010-01-07 05:18:16 -03001472 {USB_DEVICE(0x1415, 0x2000)},
Jean-François Moine458efe22011-02-10 10:11:04 -03001473 {USB_DEVICE(0x06f8, 0x3002)},
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001474 {}
1475};
1476
1477MODULE_DEVICE_TABLE(usb, device_table);
1478
1479/* -- device connect -- */
1480static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
1481{
Jean-Francois Moinec52af792010-01-07 05:18:16 -03001482 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
Jean-Francois Moine189d92a2009-11-11 07:46:28 -03001483 THIS_MODULE);
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001484}
1485
1486static struct usb_driver sd_driver = {
1487 .name = MODULE_NAME,
1488 .id_table = device_table,
1489 .probe = sd_probe,
1490 .disconnect = gspca_disconnect,
1491#ifdef CONFIG_PM
1492 .suspend = gspca_suspend,
1493 .resume = gspca_resume,
1494#endif
1495};
1496
1497/* -- module insert / remove -- */
1498static int __init sd_mod_init(void)
1499{
Jean-François Moine54826432010-09-13 04:53:03 -03001500 return usb_register(&sd_driver);
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001501}
1502
1503static void __exit sd_mod_exit(void)
1504{
1505 usb_deregister(&sd_driver);
Antonio Ospitefbb4c6d2008-11-22 05:23:39 -03001506}
1507
1508module_init(sd_mod_init);
1509module_exit(sd_mod_exit);