[media] gspca: Use current logging styles
[deliverable/linux.git] / drivers / media / video / gspca / ov534_9.c
1 /*
2 * ov534-ov965x gspca driver
3 *
4 * Copyright (C) 2009-2010 Jean-Francois Moine http://moinejf.free.fr
5 * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it>
6 * Copyright (C) 2008 Jim Paris <jim@jtan.com>
7 *
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 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26
27 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28
29 #define MODULE_NAME "ov534_9"
30
31 #include "gspca.h"
32
33 #define OV534_REG_ADDRESS 0xf1 /* sensor address */
34 #define OV534_REG_SUBADDR 0xf2
35 #define OV534_REG_WRITE 0xf3
36 #define OV534_REG_READ 0xf4
37 #define OV534_REG_OPERATION 0xf5
38 #define OV534_REG_STATUS 0xf6
39
40 #define OV534_OP_WRITE_3 0x37
41 #define OV534_OP_WRITE_2 0x33
42 #define OV534_OP_READ_2 0xf9
43
44 #define CTRL_TIMEOUT 500
45
46 MODULE_AUTHOR("Jean-Francois Moine <moinejf@free.fr>");
47 MODULE_DESCRIPTION("GSPCA/OV534_9 USB Camera Driver");
48 MODULE_LICENSE("GPL");
49
50 /* specific webcam descriptor */
51 struct sd {
52 struct gspca_dev gspca_dev; /* !! must be the first item */
53 __u32 last_pts;
54 u8 last_fid;
55
56 u8 brightness;
57 u8 contrast;
58 u8 autogain;
59 u8 exposure;
60 s8 sharpness;
61 u8 satur;
62 u8 freq;
63 };
64
65 /* V4L2 controls supported by the driver */
66 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
67 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
68 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
69 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
70 static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
71 static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
72 static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
73 static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
74 static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
75 static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
76 static int sd_setsatur(struct gspca_dev *gspca_dev, __s32 val);
77 static int sd_getsatur(struct gspca_dev *gspca_dev, __s32 *val);
78 static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
79 static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
80
81 static const struct ctrl sd_ctrls[] = {
82 { /* 0 */
83 {
84 .id = V4L2_CID_BRIGHTNESS,
85 .type = V4L2_CTRL_TYPE_INTEGER,
86 .name = "Brightness",
87 .minimum = 0,
88 .maximum = 15,
89 .step = 1,
90 #define BRIGHTNESS_DEF 7
91 .default_value = BRIGHTNESS_DEF,
92 },
93 .set = sd_setbrightness,
94 .get = sd_getbrightness,
95 },
96 { /* 1 */
97 {
98 .id = V4L2_CID_CONTRAST,
99 .type = V4L2_CTRL_TYPE_INTEGER,
100 .name = "Contrast",
101 .minimum = 0,
102 .maximum = 15,
103 .step = 1,
104 #define CONTRAST_DEF 3
105 .default_value = CONTRAST_DEF,
106 },
107 .set = sd_setcontrast,
108 .get = sd_getcontrast,
109 },
110 { /* 2 */
111 {
112 .id = V4L2_CID_AUTOGAIN,
113 .type = V4L2_CTRL_TYPE_BOOLEAN,
114 .name = "Autogain",
115 .minimum = 0,
116 .maximum = 1,
117 .step = 1,
118 #define AUTOGAIN_DEF 1
119 .default_value = AUTOGAIN_DEF,
120 },
121 .set = sd_setautogain,
122 .get = sd_getautogain,
123 },
124 #define EXPO_IDX 3
125 { /* 3 */
126 {
127 .id = V4L2_CID_EXPOSURE,
128 .type = V4L2_CTRL_TYPE_INTEGER,
129 .name = "Exposure",
130 .minimum = 0,
131 .maximum = 3,
132 .step = 1,
133 #define EXPO_DEF 0
134 .default_value = EXPO_DEF,
135 },
136 .set = sd_setexposure,
137 .get = sd_getexposure,
138 },
139 { /* 4 */
140 {
141 .id = V4L2_CID_SHARPNESS,
142 .type = V4L2_CTRL_TYPE_INTEGER,
143 .name = "Sharpness",
144 .minimum = -1, /* -1 = auto */
145 .maximum = 4,
146 .step = 1,
147 #define SHARPNESS_DEF -1
148 .default_value = SHARPNESS_DEF,
149 },
150 .set = sd_setsharpness,
151 .get = sd_getsharpness,
152 },
153 { /* 5 */
154 {
155 .id = V4L2_CID_SATURATION,
156 .type = V4L2_CTRL_TYPE_INTEGER,
157 .name = "Saturation",
158 .minimum = 0,
159 .maximum = 4,
160 .step = 1,
161 #define SATUR_DEF 2
162 .default_value = SATUR_DEF,
163 },
164 .set = sd_setsatur,
165 .get = sd_getsatur,
166 },
167 {
168 {
169 .id = V4L2_CID_POWER_LINE_FREQUENCY,
170 .type = V4L2_CTRL_TYPE_MENU,
171 .name = "Light frequency filter",
172 .minimum = 0,
173 .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */
174 .step = 1,
175 #define FREQ_DEF 0
176 .default_value = FREQ_DEF,
177 },
178 .set = sd_setfreq,
179 .get = sd_getfreq,
180 },
181 };
182
183 static const struct v4l2_pix_format ov965x_mode[] = {
184 #define QVGA_MODE 0
185 {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
186 .bytesperline = 320,
187 .sizeimage = 320 * 240 * 3 / 8 + 590,
188 .colorspace = V4L2_COLORSPACE_JPEG},
189 #define VGA_MODE 1
190 {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
191 .bytesperline = 640,
192 .sizeimage = 640 * 480 * 3 / 8 + 590,
193 .colorspace = V4L2_COLORSPACE_JPEG},
194 #define SVGA_MODE 2
195 {800, 600, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
196 .bytesperline = 800,
197 .sizeimage = 800 * 600 * 3 / 8 + 590,
198 .colorspace = V4L2_COLORSPACE_JPEG},
199 #define XGA_MODE 3
200 {1024, 768, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
201 .bytesperline = 1024,
202 .sizeimage = 1024 * 768 * 3 / 8 + 590,
203 .colorspace = V4L2_COLORSPACE_JPEG},
204 #define SXGA_MODE 4
205 {1280, 1024, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
206 .bytesperline = 1280,
207 .sizeimage = 1280 * 1024 * 3 / 8 + 590,
208 .colorspace = V4L2_COLORSPACE_JPEG},
209 };
210
211 static const u8 bridge_init[][2] = {
212 {0x88, 0xf8},
213 {0x89, 0xff},
214 {0x76, 0x03},
215 {0x92, 0x03},
216 {0x95, 0x10},
217 {0xe2, 0x00},
218 {0xe7, 0x3e},
219 {0x8d, 0x1c},
220 {0x8e, 0x00},
221 {0x8f, 0x00},
222 {0x1f, 0x00},
223 {0xc3, 0xf9},
224 {0x89, 0xff},
225 {0x88, 0xf8},
226 {0x76, 0x03},
227 {0x92, 0x01},
228 {0x93, 0x18},
229 {0x1c, 0x0a},
230 {0x1d, 0x48},
231 {0xc0, 0x50},
232 {0xc1, 0x3c},
233 {0x34, 0x05},
234 {0xc2, 0x0c},
235 {0xc3, 0xf9},
236 {0x34, 0x05},
237 {0xe7, 0x2e},
238 {0x31, 0xf9},
239 {0x35, 0x02},
240 {0xd9, 0x10},
241 {0x25, 0x42},
242 {0x94, 0x11},
243 };
244
245 static const u8 sensor_init[][2] = {
246 {0x12, 0x80}, /* com7 - SSCB reset */
247 {0x00, 0x00}, /* gain */
248 {0x01, 0x80}, /* blue */
249 {0x02, 0x80}, /* red */
250 {0x03, 0x1b}, /* vref */
251 {0x04, 0x03}, /* com1 - exposure low bits */
252 {0x0b, 0x57}, /* ver */
253 {0x0e, 0x61}, /* com5 */
254 {0x0f, 0x42}, /* com6 */
255 {0x11, 0x00}, /* clkrc */
256 {0x12, 0x02}, /* com7 - 15fps VGA YUYV */
257 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
258 {0x14, 0x28}, /* com9 */
259 {0x16, 0x24}, /* reg16 */
260 {0x17, 0x1d}, /* hstart*/
261 {0x18, 0xbd}, /* hstop */
262 {0x19, 0x01}, /* vstrt */
263 {0x1a, 0x81}, /* vstop*/
264 {0x1e, 0x04}, /* mvfp */
265 {0x24, 0x3c}, /* aew */
266 {0x25, 0x36}, /* aeb */
267 {0x26, 0x71}, /* vpt */
268 {0x27, 0x08}, /* bbias */
269 {0x28, 0x08}, /* gbbias */
270 {0x29, 0x15}, /* gr com */
271 {0x2a, 0x00}, /* exhch */
272 {0x2b, 0x00}, /* exhcl */
273 {0x2c, 0x08}, /* rbias */
274 {0x32, 0xff}, /* href */
275 {0x33, 0x00}, /* chlf */
276 {0x34, 0x3f}, /* aref1 */
277 {0x35, 0x00}, /* aref2 */
278 {0x36, 0xf8}, /* aref3 */
279 {0x38, 0x72}, /* adc2 */
280 {0x39, 0x57}, /* aref4 */
281 {0x3a, 0x80}, /* tslb - yuyv */
282 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
283 {0x3d, 0x99}, /* com13 */
284 {0x3f, 0xc1}, /* edge */
285 {0x40, 0xc0}, /* com15 */
286 {0x41, 0x40}, /* com16 */
287 {0x42, 0xc0}, /* com17 */
288 {0x43, 0x0a}, /* rsvd */
289 {0x44, 0xf0},
290 {0x45, 0x46},
291 {0x46, 0x62},
292 {0x47, 0x2a},
293 {0x48, 0x3c},
294 {0x4a, 0xfc},
295 {0x4b, 0xfc},
296 {0x4c, 0x7f},
297 {0x4d, 0x7f},
298 {0x4e, 0x7f},
299 {0x4f, 0x98}, /* matrix */
300 {0x50, 0x98},
301 {0x51, 0x00},
302 {0x52, 0x28},
303 {0x53, 0x70},
304 {0x54, 0x98},
305 {0x58, 0x1a}, /* matrix coef sign */
306 {0x59, 0x85}, /* AWB control */
307 {0x5a, 0xa9},
308 {0x5b, 0x64},
309 {0x5c, 0x84},
310 {0x5d, 0x53},
311 {0x5e, 0x0e},
312 {0x5f, 0xf0}, /* AWB blue limit */
313 {0x60, 0xf0}, /* AWB red limit */
314 {0x61, 0xf0}, /* AWB green limit */
315 {0x62, 0x00}, /* lcc1 */
316 {0x63, 0x00}, /* lcc2 */
317 {0x64, 0x02}, /* lcc3 */
318 {0x65, 0x16}, /* lcc4 */
319 {0x66, 0x01}, /* lcc5 */
320 {0x69, 0x02}, /* hv */
321 {0x6b, 0x5a}, /* dbvl */
322 {0x6c, 0x04},
323 {0x6d, 0x55},
324 {0x6e, 0x00},
325 {0x6f, 0x9d},
326 {0x70, 0x21}, /* dnsth */
327 {0x71, 0x78},
328 {0x72, 0x00}, /* poidx */
329 {0x73, 0x01}, /* pckdv */
330 {0x74, 0x3a}, /* xindx */
331 {0x75, 0x35}, /* yindx */
332 {0x76, 0x01},
333 {0x77, 0x02},
334 {0x7a, 0x12}, /* gamma curve */
335 {0x7b, 0x08},
336 {0x7c, 0x16},
337 {0x7d, 0x30},
338 {0x7e, 0x5e},
339 {0x7f, 0x72},
340 {0x80, 0x82},
341 {0x81, 0x8e},
342 {0x82, 0x9a},
343 {0x83, 0xa4},
344 {0x84, 0xac},
345 {0x85, 0xb8},
346 {0x86, 0xc3},
347 {0x87, 0xd6},
348 {0x88, 0xe6},
349 {0x89, 0xf2},
350 {0x8a, 0x03},
351 {0x8c, 0x89}, /* com19 */
352 {0x14, 0x28}, /* com9 */
353 {0x90, 0x7d},
354 {0x91, 0x7b},
355 {0x9d, 0x03}, /* lcc6 */
356 {0x9e, 0x04}, /* lcc7 */
357 {0x9f, 0x7a},
358 {0xa0, 0x79},
359 {0xa1, 0x40}, /* aechm */
360 {0xa4, 0x50}, /* com21 */
361 {0xa5, 0x68}, /* com26 */
362 {0xa6, 0x4a}, /* AWB green */
363 {0xa8, 0xc1}, /* refa8 */
364 {0xa9, 0xef}, /* refa9 */
365 {0xaa, 0x92},
366 {0xab, 0x04},
367 {0xac, 0x80}, /* black level control */
368 {0xad, 0x80},
369 {0xae, 0x80},
370 {0xaf, 0x80},
371 {0xb2, 0xf2},
372 {0xb3, 0x20},
373 {0xb4, 0x20}, /* ctrlb4 */
374 {0xb5, 0x00},
375 {0xb6, 0xaf},
376 {0xbb, 0xae},
377 {0xbc, 0x7f}, /* ADC channel offsets */
378 {0xdb, 0x7f},
379 {0xbe, 0x7f},
380 {0xbf, 0x7f},
381 {0xc0, 0xe2},
382 {0xc1, 0xc0},
383 {0xc2, 0x01},
384 {0xc3, 0x4e},
385 {0xc6, 0x85},
386 {0xc7, 0x80}, /* com24 */
387 {0xc9, 0xe0},
388 {0xca, 0xe8},
389 {0xcb, 0xf0},
390 {0xcc, 0xd8},
391 {0xcd, 0xf1},
392 {0x4f, 0x98}, /* matrix */
393 {0x50, 0x98},
394 {0x51, 0x00},
395 {0x52, 0x28},
396 {0x53, 0x70},
397 {0x54, 0x98},
398 {0x58, 0x1a},
399 {0xff, 0x41}, /* read 41, write ff 00 */
400 {0x41, 0x40}, /* com16 */
401
402 {0xc5, 0x03}, /* 60 Hz banding filter */
403 {0x6a, 0x02}, /* 50 Hz banding filter */
404
405 {0x12, 0x62}, /* com7 - 30fps VGA YUV */
406 {0x36, 0xfa}, /* aref3 */
407 {0x69, 0x0a}, /* hv */
408 {0x8c, 0x89}, /* com22 */
409 {0x14, 0x28}, /* com9 */
410 {0x3e, 0x0c},
411 {0x41, 0x40}, /* com16 */
412 {0x72, 0x00},
413 {0x73, 0x00},
414 {0x74, 0x3a},
415 {0x75, 0x35},
416 {0x76, 0x01},
417 {0xc7, 0x80},
418 {0x03, 0x12}, /* vref */
419 {0x17, 0x16}, /* hstart */
420 {0x18, 0x02}, /* hstop */
421 {0x19, 0x01}, /* vstrt */
422 {0x1a, 0x3d}, /* vstop */
423 {0x32, 0xff}, /* href */
424 {0xc0, 0xaa},
425 };
426
427 static const u8 bridge_init_2[][2] = {
428 {0x94, 0xaa},
429 {0xf1, 0x60},
430 {0xe5, 0x04},
431 {0xc0, 0x50},
432 {0xc1, 0x3c},
433 {0x8c, 0x00},
434 {0x8d, 0x1c},
435 {0x34, 0x05},
436
437 {0xc2, 0x0c},
438 {0xc3, 0xf9},
439 {0xda, 0x01},
440 {0x50, 0x00},
441 {0x51, 0xa0},
442 {0x52, 0x3c},
443 {0x53, 0x00},
444 {0x54, 0x00},
445 {0x55, 0x00},
446 {0x57, 0x00},
447 {0x5c, 0x00},
448 {0x5a, 0xa0},
449 {0x5b, 0x78},
450 {0x35, 0x02},
451 {0xd9, 0x10},
452 {0x94, 0x11},
453 };
454
455 static const u8 sensor_init_2[][2] = {
456 {0x3b, 0xc4},
457 {0x1e, 0x04}, /* mvfp */
458 {0x13, 0xe0}, /* com8 */
459 {0x00, 0x00}, /* gain */
460 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
461 {0x11, 0x03}, /* clkrc */
462 {0x6b, 0x5a}, /* dblv */
463 {0x6a, 0x05},
464 {0xc5, 0x07},
465 {0xa2, 0x4b},
466 {0xa3, 0x3e},
467 {0x2d, 0x00},
468 {0xff, 0x42}, /* read 42, write ff 00 */
469 {0x42, 0xc0}, /* com17 */
470 {0x2d, 0x00},
471 {0xff, 0x42}, /* read 42, write ff 00 */
472 {0x42, 0xc1}, /* com17 */
473 /* sharpness */
474 {0x3f, 0x01},
475 {0xff, 0x42}, /* read 42, write ff 00 */
476 {0x42, 0xc1}, /* com17 */
477 /* saturation */
478 {0x4f, 0x98}, /* matrix */
479 {0x50, 0x98},
480 {0x51, 0x00},
481 {0x52, 0x28},
482 {0x53, 0x70},
483 {0x54, 0x98},
484 {0x58, 0x1a},
485 {0xff, 0x41}, /* read 41, write ff 00 */
486 {0x41, 0x40}, /* com16 */
487 /* contrast */
488 {0x56, 0x40},
489 /* brightness */
490 {0x55, 0x8f},
491 /* expo */
492 {0x10, 0x25}, /* aech - exposure high bits */
493 {0xff, 0x13}, /* read 13, write ff 00 */
494 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
495 };
496
497 static const u8 sensor_start_1_vga[][2] = { /* same for qvga */
498 {0x12, 0x62}, /* com7 - 30fps VGA YUV */
499 {0x36, 0xfa}, /* aref3 */
500 {0x69, 0x0a}, /* hv */
501 {0x8c, 0x89}, /* com22 */
502 {0x14, 0x28}, /* com9 */
503 {0x3e, 0x0c}, /* com14 */
504 {0x41, 0x40}, /* com16 */
505 {0x72, 0x00},
506 {0x73, 0x00},
507 {0x74, 0x3a},
508 {0x75, 0x35},
509 {0x76, 0x01},
510 {0xc7, 0x80}, /* com24 */
511 {0x03, 0x12}, /* vref */
512 {0x17, 0x16}, /* hstart */
513 {0x18, 0x02}, /* hstop */
514 {0x19, 0x01}, /* vstrt */
515 {0x1a, 0x3d}, /* vstop */
516 {0x32, 0xff}, /* href */
517 {0xc0, 0xaa},
518 };
519
520 static const u8 sensor_start_1_svga[][2] = {
521 {0x12, 0x02}, /* com7 - YUYV - VGA 15 full resolution */
522 {0x36, 0xf8}, /* aref3 */
523 {0x69, 0x02}, /* hv */
524 {0x8c, 0x0d}, /* com22 */
525 {0x3e, 0x0c}, /* com14 */
526 {0x41, 0x40}, /* com16 */
527 {0x72, 0x00},
528 {0x73, 0x01},
529 {0x74, 0x3a},
530 {0x75, 0x35},
531 {0x76, 0x01},
532 {0xc7, 0x80}, /* com24 */
533 {0x03, 0x1b}, /* vref */
534 {0x17, 0x1d}, /* hstart */
535 {0x18, 0xbd}, /* hstop */
536 {0x19, 0x01}, /* vstrt */
537 {0x1a, 0x81}, /* vstop */
538 {0x32, 0xff}, /* href */
539 {0xc0, 0xe2},
540 };
541
542 static const u8 sensor_start_1_xga[][2] = {
543 {0x12, 0x02}, /* com7 */
544 {0x36, 0xf8}, /* aref3 */
545 {0x69, 0x02}, /* hv */
546 {0x8c, 0x89}, /* com22 */
547 {0x14, 0x28}, /* com9 */
548 {0x3e, 0x0c}, /* com14 */
549 {0x41, 0x40}, /* com16 */
550 {0x72, 0x00},
551 {0x73, 0x01},
552 {0x74, 0x3a},
553 {0x75, 0x35},
554 {0x76, 0x01},
555 {0xc7, 0x80}, /* com24 */
556 {0x03, 0x1b}, /* vref */
557 {0x17, 0x1d}, /* hstart */
558 {0x18, 0xbd}, /* hstop */
559 {0x19, 0x01}, /* vstrt */
560 {0x1a, 0x81}, /* vstop */
561 {0x32, 0xff}, /* href */
562 {0xc0, 0xe2},
563 };
564
565 static const u8 sensor_start_1_sxga[][2] = {
566 {0x12, 0x02}, /* com7 */
567 {0x36, 0xf8}, /* aref3 */
568 {0x69, 0x02}, /* hv */
569 {0x8c, 0x89}, /* com22 */
570 {0x14, 0x28}, /* com9 */
571 {0x3e, 0x0c}, /* com14 */
572 {0x41, 0x40}, /* com16 */
573 {0x72, 0x00},
574 {0x73, 0x01},
575 {0x74, 0x3a},
576 {0x75, 0x35},
577 {0x76, 0x01},
578 {0xc7, 0x80}, /* com24 */
579 {0x03, 0x1b}, /* vref */
580 {0x17, 0x1d}, /* hstart */
581 {0x18, 0x02}, /* hstop */
582 {0x19, 0x01}, /* vstrt */
583 {0x1a, 0x81}, /* vstop */
584 {0x32, 0xff}, /* href */
585 {0xc0, 0xe2},
586 };
587
588 static const u8 bridge_start_qvga[][2] = {
589 {0x94, 0xaa},
590 {0xf1, 0x60},
591 {0xe5, 0x04},
592 {0xc0, 0x50},
593 {0xc1, 0x3c},
594 {0x8c, 0x00},
595 {0x8d, 0x1c},
596 {0x34, 0x05},
597
598 {0xc2, 0x4c},
599 {0xc3, 0xf9},
600 {0xda, 0x00},
601 {0x50, 0x00},
602 {0x51, 0xa0},
603 {0x52, 0x78},
604 {0x53, 0x00},
605 {0x54, 0x00},
606 {0x55, 0x00},
607 {0x57, 0x00},
608 {0x5c, 0x00},
609 {0x5a, 0x50},
610 {0x5b, 0x3c},
611 {0x35, 0x02},
612 {0xd9, 0x10},
613 {0x94, 0x11},
614 };
615
616 static const u8 bridge_start_vga[][2] = {
617 {0x94, 0xaa},
618 {0xf1, 0x60},
619 {0xe5, 0x04},
620 {0xc0, 0x50},
621 {0xc1, 0x3c},
622 {0x8c, 0x00},
623 {0x8d, 0x1c},
624 {0x34, 0x05},
625 {0xc2, 0x0c},
626 {0xc3, 0xf9},
627 {0xda, 0x01},
628 {0x50, 0x00},
629 {0x51, 0xa0},
630 {0x52, 0x3c},
631 {0x53, 0x00},
632 {0x54, 0x00},
633 {0x55, 0x00},
634 {0x57, 0x00},
635 {0x5c, 0x00},
636 {0x5a, 0xa0},
637 {0x5b, 0x78},
638 {0x35, 0x02},
639 {0xd9, 0x10},
640 {0x94, 0x11},
641 };
642
643 static const u8 bridge_start_svga[][2] = {
644 {0x94, 0xaa},
645 {0xf1, 0x60},
646 {0xe5, 0x04},
647 {0xc0, 0xa0},
648 {0xc1, 0x80},
649 {0x8c, 0x00},
650 {0x8d, 0x1c},
651 {0x34, 0x05},
652 {0xc2, 0x4c},
653 {0xc3, 0xf9},
654 {0x50, 0x00},
655 {0x51, 0x40},
656 {0x52, 0x00},
657 {0x53, 0x00},
658 {0x54, 0x00},
659 {0x55, 0x88},
660 {0x57, 0x00},
661 {0x5c, 0x00},
662 {0x5a, 0xc8},
663 {0x5b, 0x96},
664 {0x35, 0x02},
665 {0xd9, 0x10},
666 {0xda, 0x00},
667 {0x94, 0x11},
668 };
669
670 static const u8 bridge_start_xga[][2] = {
671 {0x94, 0xaa},
672 {0xf1, 0x60},
673 {0xe5, 0x04},
674 {0xc0, 0xa0},
675 {0xc1, 0x80},
676 {0x8c, 0x00},
677 {0x8d, 0x1c},
678 {0x34, 0x05},
679 {0xc2, 0x4c},
680 {0xc3, 0xf9},
681 {0x50, 0x00},
682 {0x51, 0x40},
683 {0x52, 0x00},
684 {0x53, 0x00},
685 {0x54, 0x00},
686 {0x55, 0x88},
687 {0x57, 0x00},
688 {0x5c, 0x01},
689 {0x5a, 0x00},
690 {0x5b, 0xc0},
691 {0x35, 0x02},
692 {0xd9, 0x10},
693 {0xda, 0x01},
694 {0x94, 0x11},
695 };
696
697 static const u8 bridge_start_sxga[][2] = {
698 {0x94, 0xaa},
699 {0xf1, 0x60},
700 {0xe5, 0x04},
701 {0xc0, 0xa0},
702 {0xc1, 0x80},
703 {0x8c, 0x00},
704 {0x8d, 0x1c},
705 {0x34, 0x05},
706 {0xc2, 0x0c},
707 {0xc3, 0xf9},
708 {0xda, 0x00},
709 {0x35, 0x02},
710 {0xd9, 0x10},
711 {0x94, 0x11},
712 };
713
714 static const u8 sensor_start_2_qvga[][2] = {
715 {0x3b, 0xe4}, /* com11 - night mode 1/4 frame rate */
716 {0x1e, 0x04}, /* mvfp */
717 {0x13, 0xe0}, /* com8 */
718 {0x00, 0x00},
719 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
720 {0x11, 0x01}, /* clkrc */
721 {0x6b, 0x5a}, /* dblv */
722 {0x6a, 0x02}, /* 50 Hz banding filter */
723 {0xc5, 0x03}, /* 60 Hz banding filter */
724 {0xa2, 0x96}, /* bd50 */
725 {0xa3, 0x7d}, /* bd60 */
726
727 {0xff, 0x13}, /* read 13, write ff 00 */
728 {0x13, 0xe7},
729 {0x3a, 0x80}, /* tslb - yuyv */
730 };
731
732 static const u8 sensor_start_2_vga[][2] = {
733 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
734 {0x1e, 0x04}, /* mvfp */
735 {0x13, 0xe0}, /* com8 */
736 {0x00, 0x00},
737 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
738 {0x11, 0x03}, /* clkrc */
739 {0x6b, 0x5a}, /* dblv */
740 {0x6a, 0x05}, /* 50 Hz banding filter */
741 {0xc5, 0x07}, /* 60 Hz banding filter */
742 {0xa2, 0x4b}, /* bd50 */
743 {0xa3, 0x3e}, /* bd60 */
744
745 {0x2d, 0x00}, /* advfl */
746 };
747
748 static const u8 sensor_start_2_svga[][2] = { /* same for xga */
749 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
750 {0x1e, 0x04}, /* mvfp */
751 {0x13, 0xe0}, /* com8 */
752 {0x00, 0x00},
753 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
754 {0x11, 0x01}, /* clkrc */
755 {0x6b, 0x5a}, /* dblv */
756 {0x6a, 0x0c}, /* 50 Hz banding filter */
757 {0xc5, 0x0f}, /* 60 Hz banding filter */
758 {0xa2, 0x4e}, /* bd50 */
759 {0xa3, 0x41}, /* bd60 */
760 };
761
762 static const u8 sensor_start_2_sxga[][2] = {
763 {0x13, 0xe0}, /* com8 */
764 {0x00, 0x00},
765 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
766 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
767 {0x1e, 0x04}, /* mvfp */
768 {0x11, 0x01}, /* clkrc */
769 {0x6b, 0x5a}, /* dblv */
770 {0x6a, 0x0c}, /* 50 Hz banding filter */
771 {0xc5, 0x0f}, /* 60 Hz banding filter */
772 {0xa2, 0x4e}, /* bd50 */
773 {0xa3, 0x41}, /* bd60 */
774 };
775
776 static void reg_w_i(struct gspca_dev *gspca_dev, u16 reg, u8 val)
777 {
778 struct usb_device *udev = gspca_dev->dev;
779 int ret;
780
781 if (gspca_dev->usb_err < 0)
782 return;
783 gspca_dev->usb_buf[0] = val;
784 ret = usb_control_msg(udev,
785 usb_sndctrlpipe(udev, 0),
786 0x01,
787 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
788 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
789 if (ret < 0) {
790 pr_err("reg_w failed %d\n", ret);
791 gspca_dev->usb_err = ret;
792 }
793 }
794
795 static void reg_w(struct gspca_dev *gspca_dev, u16 reg, u8 val)
796 {
797 PDEBUG(D_USBO, "reg_w [%04x] = %02x", reg, val);
798 reg_w_i(gspca_dev, reg, val);
799 }
800
801 static u8 reg_r(struct gspca_dev *gspca_dev, u16 reg)
802 {
803 struct usb_device *udev = gspca_dev->dev;
804 int ret;
805
806 if (gspca_dev->usb_err < 0)
807 return 0;
808 ret = usb_control_msg(udev,
809 usb_rcvctrlpipe(udev, 0),
810 0x01,
811 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
812 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
813 PDEBUG(D_USBI, "reg_r [%04x] -> %02x", reg, gspca_dev->usb_buf[0]);
814 if (ret < 0) {
815 pr_err("reg_r err %d\n", ret);
816 gspca_dev->usb_err = ret;
817 }
818 return gspca_dev->usb_buf[0];
819 }
820
821 static int sccb_check_status(struct gspca_dev *gspca_dev)
822 {
823 u8 data;
824 int i;
825
826 for (i = 0; i < 5; i++) {
827 data = reg_r(gspca_dev, OV534_REG_STATUS);
828
829 switch (data) {
830 case 0x00:
831 return 1;
832 case 0x04:
833 return 0;
834 case 0x03:
835 break;
836 default:
837 PDEBUG(D_USBI|D_USBO,
838 "sccb status 0x%02x, attempt %d/5",
839 data, i + 1);
840 }
841 }
842 return 0;
843 }
844
845 static void sccb_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
846 {
847 PDEBUG(D_USBO, "sccb_write [%02x] = %02x", reg, val);
848 reg_w_i(gspca_dev, OV534_REG_SUBADDR, reg);
849 reg_w_i(gspca_dev, OV534_REG_WRITE, val);
850 reg_w_i(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
851
852 if (!sccb_check_status(gspca_dev))
853 pr_err("sccb_write failed\n");
854 }
855
856 static u8 sccb_read(struct gspca_dev *gspca_dev, u16 reg)
857 {
858 reg_w(gspca_dev, OV534_REG_SUBADDR, reg);
859 reg_w(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
860 if (!sccb_check_status(gspca_dev))
861 pr_err("sccb_read failed 1\n");
862
863 reg_w(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
864 if (!sccb_check_status(gspca_dev))
865 pr_err("sccb_read failed 2\n");
866
867 return reg_r(gspca_dev, OV534_REG_READ);
868 }
869
870 /* output a bridge sequence (reg - val) */
871 static void reg_w_array(struct gspca_dev *gspca_dev,
872 const u8 (*data)[2], int len)
873 {
874 while (--len >= 0) {
875 reg_w(gspca_dev, (*data)[0], (*data)[1]);
876 data++;
877 }
878 }
879
880 /* output a sensor sequence (reg - val) */
881 static void sccb_w_array(struct gspca_dev *gspca_dev,
882 const u8 (*data)[2], int len)
883 {
884 while (--len >= 0) {
885 if ((*data)[0] != 0xff) {
886 sccb_write(gspca_dev, (*data)[0], (*data)[1]);
887 } else {
888 sccb_read(gspca_dev, (*data)[1]);
889 sccb_write(gspca_dev, 0xff, 0x00);
890 }
891 data++;
892 }
893 }
894
895 /* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
896 * (direction and output)? */
897 static void set_led(struct gspca_dev *gspca_dev, int status)
898 {
899 u8 data;
900
901 PDEBUG(D_CONF, "led status: %d", status);
902
903 data = reg_r(gspca_dev, 0x21);
904 data |= 0x80;
905 reg_w(gspca_dev, 0x21, data);
906
907 data = reg_r(gspca_dev, 0x23);
908 if (status)
909 data |= 0x80;
910 else
911 data &= ~0x80;
912
913 reg_w(gspca_dev, 0x23, data);
914
915 if (!status) {
916 data = reg_r(gspca_dev, 0x21);
917 data &= ~0x80;
918 reg_w(gspca_dev, 0x21, data);
919 }
920 }
921
922 static void setbrightness(struct gspca_dev *gspca_dev)
923 {
924 struct sd *sd = (struct sd *) gspca_dev;
925 u8 val;
926
927 val = sd->brightness;
928 if (val < 8)
929 val = 15 - val; /* f .. 8 */
930 else
931 val = val - 8; /* 0 .. 7 */
932 sccb_write(gspca_dev, 0x55, /* brtn - brightness adjustment */
933 0x0f | (val << 4));
934 }
935
936 static void setcontrast(struct gspca_dev *gspca_dev)
937 {
938 struct sd *sd = (struct sd *) gspca_dev;
939
940 sccb_write(gspca_dev, 0x56, /* cnst1 - contrast 1 ctrl coeff */
941 sd->contrast << 4);
942 }
943
944 static void setautogain(struct gspca_dev *gspca_dev)
945 {
946 struct sd *sd = (struct sd *) gspca_dev;
947 u8 val;
948
949 /*fixme: should adjust agc/awb/aec by different controls */
950 val = sccb_read(gspca_dev, 0x13); /* com8 */
951 sccb_write(gspca_dev, 0xff, 0x00);
952 if (sd->autogain)
953 val |= 0x05; /* agc & aec */
954 else
955 val &= 0xfa;
956 sccb_write(gspca_dev, 0x13, val);
957 }
958
959 static void setexposure(struct gspca_dev *gspca_dev)
960 {
961 struct sd *sd = (struct sd *) gspca_dev;
962 u8 val;
963 static const u8 expo[4] = {0x00, 0x25, 0x38, 0x5e};
964
965 sccb_write(gspca_dev, 0x10, /* aec[9:2] */
966 expo[sd->exposure]);
967
968 val = sccb_read(gspca_dev, 0x13); /* com8 */
969 sccb_write(gspca_dev, 0xff, 0x00);
970 sccb_write(gspca_dev, 0x13, val);
971
972 val = sccb_read(gspca_dev, 0xa1); /* aech */
973 sccb_write(gspca_dev, 0xff, 0x00);
974 sccb_write(gspca_dev, 0xa1, val & 0xe0); /* aec[15:10] = 0 */
975 }
976
977 static void setsharpness(struct gspca_dev *gspca_dev)
978 {
979 struct sd *sd = (struct sd *) gspca_dev;
980 s8 val;
981
982 val = sd->sharpness;
983 if (val < 0) { /* auto */
984 val = sccb_read(gspca_dev, 0x42); /* com17 */
985 sccb_write(gspca_dev, 0xff, 0x00);
986 sccb_write(gspca_dev, 0x42, val | 0x40);
987 /* Edge enhancement strength auto adjust */
988 return;
989 }
990 if (val != 0)
991 val = 1 << (val - 1);
992 sccb_write(gspca_dev, 0x3f, /* edge - edge enhance. factor */
993 val);
994 val = sccb_read(gspca_dev, 0x42); /* com17 */
995 sccb_write(gspca_dev, 0xff, 0x00);
996 sccb_write(gspca_dev, 0x42, val & 0xbf);
997 }
998
999 static void setsatur(struct gspca_dev *gspca_dev)
1000 {
1001 struct sd *sd = (struct sd *) gspca_dev;
1002 u8 val1, val2, val3;
1003 static const u8 matrix[5][2] = {
1004 {0x14, 0x38},
1005 {0x1e, 0x54},
1006 {0x28, 0x70},
1007 {0x32, 0x8c},
1008 {0x48, 0x90}
1009 };
1010
1011 val1 = matrix[sd->satur][0];
1012 val2 = matrix[sd->satur][1];
1013 val3 = val1 + val2;
1014 sccb_write(gspca_dev, 0x4f, val3); /* matrix coeff */
1015 sccb_write(gspca_dev, 0x50, val3);
1016 sccb_write(gspca_dev, 0x51, 0x00);
1017 sccb_write(gspca_dev, 0x52, val1);
1018 sccb_write(gspca_dev, 0x53, val2);
1019 sccb_write(gspca_dev, 0x54, val3);
1020 sccb_write(gspca_dev, 0x58, 0x1a); /* mtxs - coeff signs */
1021
1022 val1 = sccb_read(gspca_dev, 0x41); /* com16 */
1023 sccb_write(gspca_dev, 0xff, 0x00);
1024 sccb_write(gspca_dev, 0x41, val1);
1025 }
1026
1027 static void setfreq(struct gspca_dev *gspca_dev)
1028 {
1029 struct sd *sd = (struct sd *) gspca_dev;
1030 u8 val;
1031
1032 val = sccb_read(gspca_dev, 0x13); /* com8 */
1033 sccb_write(gspca_dev, 0xff, 0x00);
1034 if (sd->freq == 0) {
1035 sccb_write(gspca_dev, 0x13, val & 0xdf);
1036 return;
1037 }
1038 sccb_write(gspca_dev, 0x13, val | 0x20);
1039
1040 val = sccb_read(gspca_dev, 0x42); /* com17 */
1041 sccb_write(gspca_dev, 0xff, 0x00);
1042 if (sd->freq == 1)
1043 val |= 0x01;
1044 else
1045 val &= 0xfe;
1046 sccb_write(gspca_dev, 0x42, val);
1047 }
1048
1049 /* this function is called at probe time */
1050 static int sd_config(struct gspca_dev *gspca_dev,
1051 const struct usb_device_id *id)
1052 {
1053 struct sd *sd = (struct sd *) gspca_dev;
1054 struct cam *cam;
1055
1056 cam = &gspca_dev->cam;
1057
1058 cam->cam_mode = ov965x_mode;
1059 cam->nmodes = ARRAY_SIZE(ov965x_mode);
1060
1061 sd->brightness = BRIGHTNESS_DEF;
1062 sd->contrast = CONTRAST_DEF;
1063 #if AUTOGAIN_DEF != 0
1064 sd->autogain = AUTOGAIN_DEF;
1065 gspca_dev->ctrl_inac |= (1 << EXPO_IDX);
1066 #endif
1067 #if EXPO_DEF != 0
1068 sd->exposure = EXPO_DEF;
1069 #endif
1070 #if SHARPNESS_DEF != 0
1071 sd->sharpness = SHARPNESS_DEF;
1072 #endif
1073 sd->satur = SATUR_DEF;
1074 sd->freq = FREQ_DEF;
1075
1076 return 0;
1077 }
1078
1079 /* this function is called at probe and resume time */
1080 static int sd_init(struct gspca_dev *gspca_dev)
1081 {
1082 u16 sensor_id;
1083
1084 /* reset bridge */
1085 reg_w(gspca_dev, 0xe7, 0x3a);
1086 reg_w(gspca_dev, 0xe0, 0x08);
1087 msleep(100);
1088
1089 /* initialize the sensor address */
1090 reg_w(gspca_dev, OV534_REG_ADDRESS, 0x60);
1091
1092 /* reset sensor */
1093 sccb_write(gspca_dev, 0x12, 0x80);
1094 msleep(10);
1095
1096 /* probe the sensor */
1097 sccb_read(gspca_dev, 0x0a);
1098 sensor_id = sccb_read(gspca_dev, 0x0a) << 8;
1099 sccb_read(gspca_dev, 0x0b);
1100 sensor_id |= sccb_read(gspca_dev, 0x0b);
1101 PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id);
1102
1103 /* initialize */
1104 reg_w_array(gspca_dev, bridge_init,
1105 ARRAY_SIZE(bridge_init));
1106 sccb_w_array(gspca_dev, sensor_init,
1107 ARRAY_SIZE(sensor_init));
1108 reg_w_array(gspca_dev, bridge_init_2,
1109 ARRAY_SIZE(bridge_init_2));
1110 sccb_w_array(gspca_dev, sensor_init_2,
1111 ARRAY_SIZE(sensor_init_2));
1112 reg_w(gspca_dev, 0xe0, 0x00);
1113 reg_w(gspca_dev, 0xe0, 0x01);
1114 set_led(gspca_dev, 0);
1115 reg_w(gspca_dev, 0xe0, 0x00);
1116
1117 return gspca_dev->usb_err;
1118 }
1119
1120 static int sd_start(struct gspca_dev *gspca_dev)
1121 {
1122 switch (gspca_dev->curr_mode) {
1123 case QVGA_MODE: /* 320x240 */
1124 sccb_w_array(gspca_dev, sensor_start_1_vga,
1125 ARRAY_SIZE(sensor_start_1_vga));
1126 reg_w_array(gspca_dev, bridge_start_qvga,
1127 ARRAY_SIZE(bridge_start_qvga));
1128 sccb_w_array(gspca_dev, sensor_start_2_qvga,
1129 ARRAY_SIZE(sensor_start_2_qvga));
1130 break;
1131 case VGA_MODE: /* 640x480 */
1132 sccb_w_array(gspca_dev, sensor_start_1_vga,
1133 ARRAY_SIZE(sensor_start_1_vga));
1134 reg_w_array(gspca_dev, bridge_start_vga,
1135 ARRAY_SIZE(bridge_start_vga));
1136 sccb_w_array(gspca_dev, sensor_start_2_vga,
1137 ARRAY_SIZE(sensor_start_2_vga));
1138 break;
1139 case SVGA_MODE: /* 800x600 */
1140 sccb_w_array(gspca_dev, sensor_start_1_svga,
1141 ARRAY_SIZE(sensor_start_1_svga));
1142 reg_w_array(gspca_dev, bridge_start_svga,
1143 ARRAY_SIZE(bridge_start_svga));
1144 sccb_w_array(gspca_dev, sensor_start_2_svga,
1145 ARRAY_SIZE(sensor_start_2_svga));
1146 break;
1147 case XGA_MODE: /* 1024x768 */
1148 sccb_w_array(gspca_dev, sensor_start_1_xga,
1149 ARRAY_SIZE(sensor_start_1_xga));
1150 reg_w_array(gspca_dev, bridge_start_xga,
1151 ARRAY_SIZE(bridge_start_xga));
1152 sccb_w_array(gspca_dev, sensor_start_2_svga,
1153 ARRAY_SIZE(sensor_start_2_svga));
1154 break;
1155 default:
1156 /* case SXGA_MODE: * 1280x1024 */
1157 sccb_w_array(gspca_dev, sensor_start_1_sxga,
1158 ARRAY_SIZE(sensor_start_1_sxga));
1159 reg_w_array(gspca_dev, bridge_start_sxga,
1160 ARRAY_SIZE(bridge_start_sxga));
1161 sccb_w_array(gspca_dev, sensor_start_2_sxga,
1162 ARRAY_SIZE(sensor_start_2_sxga));
1163 break;
1164 }
1165 setfreq(gspca_dev);
1166 setautogain(gspca_dev);
1167 setbrightness(gspca_dev);
1168 setcontrast(gspca_dev);
1169 setexposure(gspca_dev);
1170 setsharpness(gspca_dev);
1171 setsatur(gspca_dev);
1172
1173 reg_w(gspca_dev, 0xe0, 0x00);
1174 reg_w(gspca_dev, 0xe0, 0x00);
1175 set_led(gspca_dev, 1);
1176 return gspca_dev->usb_err;
1177 }
1178
1179 static void sd_stopN(struct gspca_dev *gspca_dev)
1180 {
1181 reg_w(gspca_dev, 0xe0, 0x01);
1182 set_led(gspca_dev, 0);
1183 reg_w(gspca_dev, 0xe0, 0x00);
1184 }
1185
1186 /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
1187 #define UVC_STREAM_EOH (1 << 7)
1188 #define UVC_STREAM_ERR (1 << 6)
1189 #define UVC_STREAM_STI (1 << 5)
1190 #define UVC_STREAM_RES (1 << 4)
1191 #define UVC_STREAM_SCR (1 << 3)
1192 #define UVC_STREAM_PTS (1 << 2)
1193 #define UVC_STREAM_EOF (1 << 1)
1194 #define UVC_STREAM_FID (1 << 0)
1195
1196 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1197 u8 *data, int len)
1198 {
1199 struct sd *sd = (struct sd *) gspca_dev;
1200 __u32 this_pts;
1201 u8 this_fid;
1202 int remaining_len = len;
1203
1204 do {
1205 len = min(remaining_len, 2040);
1206
1207 /* Payloads are prefixed with a UVC-style header. We
1208 consider a frame to start when the FID toggles, or the PTS
1209 changes. A frame ends when EOF is set, and we've received
1210 the correct number of bytes. */
1211
1212 /* Verify UVC header. Header length is always 12 */
1213 if (data[0] != 12 || len < 12) {
1214 PDEBUG(D_PACK, "bad header");
1215 goto discard;
1216 }
1217
1218 /* Check errors */
1219 if (data[1] & UVC_STREAM_ERR) {
1220 PDEBUG(D_PACK, "payload error");
1221 goto discard;
1222 }
1223
1224 /* Extract PTS and FID */
1225 if (!(data[1] & UVC_STREAM_PTS)) {
1226 PDEBUG(D_PACK, "PTS not present");
1227 goto discard;
1228 }
1229 this_pts = (data[5] << 24) | (data[4] << 16)
1230 | (data[3] << 8) | data[2];
1231 this_fid = data[1] & UVC_STREAM_FID;
1232
1233 /* If PTS or FID has changed, start a new frame. */
1234 if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
1235 if (gspca_dev->last_packet_type == INTER_PACKET)
1236 gspca_frame_add(gspca_dev, LAST_PACKET,
1237 NULL, 0);
1238 sd->last_pts = this_pts;
1239 sd->last_fid = this_fid;
1240 gspca_frame_add(gspca_dev, FIRST_PACKET,
1241 data + 12, len - 12);
1242 /* If this packet is marked as EOF, end the frame */
1243 } else if (data[1] & UVC_STREAM_EOF) {
1244 sd->last_pts = 0;
1245 gspca_frame_add(gspca_dev, LAST_PACKET,
1246 data + 12, len - 12);
1247 } else {
1248
1249 /* Add the data from this payload */
1250 gspca_frame_add(gspca_dev, INTER_PACKET,
1251 data + 12, len - 12);
1252 }
1253
1254 /* Done this payload */
1255 goto scan_next;
1256
1257 discard:
1258 /* Discard data until a new frame starts. */
1259 gspca_dev->last_packet_type = DISCARD_PACKET;
1260
1261 scan_next:
1262 remaining_len -= len;
1263 data += len;
1264 } while (remaining_len > 0);
1265 }
1266
1267 /* controls */
1268 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
1269 {
1270 struct sd *sd = (struct sd *) gspca_dev;
1271
1272 sd->brightness = val;
1273 if (gspca_dev->streaming)
1274 setbrightness(gspca_dev);
1275 return gspca_dev->usb_err;
1276 }
1277
1278 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
1279 {
1280 struct sd *sd = (struct sd *) gspca_dev;
1281
1282 *val = sd->brightness;
1283 return 0;
1284 }
1285
1286 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
1287 {
1288 struct sd *sd = (struct sd *) gspca_dev;
1289
1290 sd->contrast = val;
1291 if (gspca_dev->streaming)
1292 setcontrast(gspca_dev);
1293 return gspca_dev->usb_err;
1294 }
1295
1296 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
1297 {
1298 struct sd *sd = (struct sd *) gspca_dev;
1299
1300 *val = sd->contrast;
1301 return 0;
1302 }
1303
1304 static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
1305 {
1306 struct sd *sd = (struct sd *) gspca_dev;
1307
1308 sd->autogain = val;
1309
1310 if (gspca_dev->streaming) {
1311 if (val)
1312 gspca_dev->ctrl_inac |= (1 << EXPO_IDX);
1313 else
1314 gspca_dev->ctrl_inac &= ~(1 << EXPO_IDX);
1315 setautogain(gspca_dev);
1316 }
1317 return gspca_dev->usb_err;
1318 }
1319
1320 static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
1321 {
1322 struct sd *sd = (struct sd *) gspca_dev;
1323
1324 *val = sd->autogain;
1325 return 0;
1326 }
1327
1328 static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
1329 {
1330 struct sd *sd = (struct sd *) gspca_dev;
1331
1332 sd->exposure = val;
1333 if (gspca_dev->streaming)
1334 setexposure(gspca_dev);
1335 return gspca_dev->usb_err;
1336 }
1337
1338 static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
1339 {
1340 struct sd *sd = (struct sd *) gspca_dev;
1341
1342 *val = sd->exposure;
1343 return 0;
1344 }
1345
1346 static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
1347 {
1348 struct sd *sd = (struct sd *) gspca_dev;
1349
1350 sd->sharpness = val;
1351 if (gspca_dev->streaming)
1352 setsharpness(gspca_dev);
1353 return gspca_dev->usb_err;
1354 }
1355
1356 static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
1357 {
1358 struct sd *sd = (struct sd *) gspca_dev;
1359
1360 *val = sd->sharpness;
1361 return 0;
1362 }
1363
1364 static int sd_setsatur(struct gspca_dev *gspca_dev, __s32 val)
1365 {
1366 struct sd *sd = (struct sd *) gspca_dev;
1367
1368 sd->satur = val;
1369 if (gspca_dev->streaming)
1370 setsatur(gspca_dev);
1371 return gspca_dev->usb_err;
1372 }
1373
1374 static int sd_getsatur(struct gspca_dev *gspca_dev, __s32 *val)
1375 {
1376 struct sd *sd = (struct sd *) gspca_dev;
1377
1378 *val = sd->satur;
1379 return 0;
1380 }
1381 static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val)
1382 {
1383 struct sd *sd = (struct sd *) gspca_dev;
1384
1385 sd->freq = val;
1386 if (gspca_dev->streaming)
1387 setfreq(gspca_dev);
1388 return gspca_dev->usb_err;
1389 }
1390
1391 static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
1392 {
1393 struct sd *sd = (struct sd *) gspca_dev;
1394
1395 *val = sd->freq;
1396 return 0;
1397 }
1398
1399 static int sd_querymenu(struct gspca_dev *gspca_dev,
1400 struct v4l2_querymenu *menu)
1401 {
1402 switch (menu->id) {
1403 case V4L2_CID_POWER_LINE_FREQUENCY:
1404 switch (menu->index) {
1405 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
1406 strcpy((char *) menu->name, "NoFliker");
1407 return 0;
1408 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
1409 strcpy((char *) menu->name, "50 Hz");
1410 return 0;
1411 case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */
1412 strcpy((char *) menu->name, "60 Hz");
1413 return 0;
1414 }
1415 break;
1416 }
1417 return -EINVAL;
1418 }
1419
1420 /* sub-driver description */
1421 static const struct sd_desc sd_desc = {
1422 .name = MODULE_NAME,
1423 .ctrls = sd_ctrls,
1424 .nctrls = ARRAY_SIZE(sd_ctrls),
1425 .config = sd_config,
1426 .init = sd_init,
1427 .start = sd_start,
1428 .stopN = sd_stopN,
1429 .pkt_scan = sd_pkt_scan,
1430 .querymenu = sd_querymenu,
1431 };
1432
1433 /* -- module initialisation -- */
1434 static const struct usb_device_id device_table[] = {
1435 {USB_DEVICE(0x06f8, 0x3003)},
1436 {}
1437 };
1438
1439 MODULE_DEVICE_TABLE(usb, device_table);
1440
1441 /* -- device connect -- */
1442 static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
1443 {
1444 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
1445 THIS_MODULE);
1446 }
1447
1448 static struct usb_driver sd_driver = {
1449 .name = MODULE_NAME,
1450 .id_table = device_table,
1451 .probe = sd_probe,
1452 .disconnect = gspca_disconnect,
1453 #ifdef CONFIG_PM
1454 .suspend = gspca_suspend,
1455 .resume = gspca_resume,
1456 #endif
1457 };
1458
1459 /* -- module insert / remove -- */
1460 static int __init sd_mod_init(void)
1461 {
1462 return usb_register(&sd_driver);
1463 }
1464
1465 static void __exit sd_mod_exit(void)
1466 {
1467 usb_deregister(&sd_driver);
1468 }
1469
1470 module_init(sd_mod_init);
1471 module_exit(sd_mod_exit);
This page took 0.065034 seconds and 5 git commands to generate.