1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * SPCA508 chip based cameras subdriver
5 * Copyright (C) 2009 Jean-Francois Moine <http://moinejf.free.fr>
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #define MODULE_NAME "spca508"
14 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
15 MODULE_DESCRIPTION("GSPCA/SPCA508 USB Camera Driver");
16 MODULE_LICENSE("GPL");
18 /* specific webcam descriptor */
20 struct gspca_dev gspca_dev; /* !! must be the first item */
23 #define CreativeVista 0
24 #define HamaUSBSightcam 1
25 #define HamaUSBSightcam2 2
26 #define IntelEasyPCCamera 3
27 #define MicroInnovationIC200 4
28 #define ViewQuestVQ110 5
31 static const struct v4l2_pix_format sif_mode[] = {
32 {160, 120, V4L2_PIX_FMT_SPCA508, V4L2_FIELD_NONE,
34 .sizeimage = 160 * 120 * 3 / 2,
35 .colorspace = V4L2_COLORSPACE_SRGB,
37 {176, 144, V4L2_PIX_FMT_SPCA508, V4L2_FIELD_NONE,
39 .sizeimage = 176 * 144 * 3 / 2,
40 .colorspace = V4L2_COLORSPACE_SRGB,
42 {320, 240, V4L2_PIX_FMT_SPCA508, V4L2_FIELD_NONE,
44 .sizeimage = 320 * 240 * 3 / 2,
45 .colorspace = V4L2_COLORSPACE_SRGB,
47 {352, 288, V4L2_PIX_FMT_SPCA508, V4L2_FIELD_NONE,
49 .sizeimage = 352 * 288 * 3 / 2,
50 .colorspace = V4L2_COLORSPACE_SRGB,
54 /* Frame packet header offsets for the spca508 */
55 #define SPCA508_OFFSET_DATA 37
58 * Initialization data: this is the first set-up data written to the
59 * device (before the open data).
61 static const u16 spca508_init_data[][2] = {
64 {0x0020, 0x8112}, /* Video drop enable, ISO streaming disable */
65 {0x0003, 0x8111}, /* Reset compression & memory */
66 {0x0000, 0x8110}, /* Disable all outputs */
67 /* READ {0x0000, 0x8114} -> 0000: 00 */
68 {0x0000, 0x8114}, /* SW GPIO data */
69 {0x0008, 0x8110}, /* Enable charge pump output */
70 {0x0002, 0x8116}, /* 200 kHz pump clock */
71 /* UNKNOWN DIRECTION (URB_FUNCTION_SELECT_INTERFACE:) */
72 {0x0003, 0x8111}, /* Reset compression & memory */
73 {0x0000, 0x8111}, /* Normal mode (not reset) */
75 /* Enable charge pump output, sync.serial,external 2x clock */
76 {0x000d, 0x8114}, /* SW GPIO data */
77 {0x0002, 0x8116}, /* 200 kHz pump clock */
78 {0x0020, 0x8112}, /* Video drop enable, ISO streaming disable */
79 /* --------------------------------------- */
80 {0x000f, 0x8402}, /* memory bank */
81 {0x0000, 0x8403}, /* ... address */
82 /* --------------------------------------- */
83 /* 0x88__ is Synchronous Serial Interface. */
84 /* TBD: This table could be expressed more compactly */
85 /* using spca508_write_i2c_vector(). */
86 /* TBD: Should see if the values in spca50x_i2c_data */
87 /* would work with the VQ110 instead of the values */
89 {0x00c0, 0x8804}, /* SSI slave addr */
90 {0x0008, 0x8802}, /* 375 Khz SSI clock */
91 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
92 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
93 {0x0008, 0x8802}, /* 375 Khz SSI clock */
94 {0x0012, 0x8801}, /* SSI reg addr */
95 {0x0080, 0x8800}, /* SSI data to write */
96 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
97 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
98 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
99 {0x0008, 0x8802}, /* 375 Khz SSI clock */
100 {0x0012, 0x8801}, /* SSI reg addr */
101 {0x0000, 0x8800}, /* SSI data to write */
102 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
103 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
104 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
105 {0x0008, 0x8802}, /* 375 Khz SSI clock */
106 {0x0011, 0x8801}, /* SSI reg addr */
107 {0x0040, 0x8800}, /* SSI data to write */
108 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
109 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
110 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
114 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
115 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
116 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
120 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
121 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
122 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
126 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
127 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
128 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
132 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
133 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
134 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
138 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
139 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
140 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
144 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
145 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
146 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
150 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
151 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
152 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
156 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
157 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
158 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
162 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
163 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
164 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
168 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
169 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
170 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
174 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
175 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
176 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
180 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
181 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
182 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
186 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
187 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
188 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
192 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
193 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
194 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
198 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
199 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
200 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
204 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
205 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
206 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
210 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
211 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
212 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
216 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
217 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
218 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
222 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
223 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
224 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
228 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
229 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
230 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
234 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
235 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
236 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
240 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
241 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
242 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
246 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
247 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
248 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
252 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
253 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
254 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
258 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
259 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
260 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
264 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
265 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
266 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
270 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
271 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
272 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
276 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
277 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
278 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
282 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
283 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
284 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
288 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
289 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
290 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
294 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
295 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
296 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
300 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
301 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
302 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
306 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
307 /* --------------------------------------- */
308 {0x0012, 0x8700}, /* Clock speed 48Mhz/(2+2)/2= 6 Mhz */
309 {0x0000, 0x8701}, /* CKx1 clock delay adj */
310 {0x0000, 0x8701}, /* CKx1 clock delay adj */
311 {0x0001, 0x870c}, /* CKOx2 output */
312 /* --------------------------------------- */
313 {0x0080, 0x8600}, /* Line memory read counter (L) */
314 {0x0001, 0x8606}, /* reserved */
315 {0x0064, 0x8607}, /* Line memory read counter (H) 0x6480=25,728 */
316 {0x002a, 0x8601}, /* CDSP sharp interpolation mode,
317 * line sel for color sep, edge enhance enab */
318 {0x0000, 0x8602}, /* optical black level for user settng = 0 */
319 {0x0080, 0x8600}, /* Line memory read counter (L) */
320 {0x000a, 0x8603}, /* optical black level calc mode:
321 * auto; optical black offset = 10 */
322 {0x00df, 0x865b}, /* Horiz offset for valid pixels (L)=0xdf */
323 {0x0012, 0x865c}, /* Vert offset for valid lines (L)=0x12 */
325 /* The following two lines seem to be the "wrong" resolution. */
326 /* But perhaps these indicate the actual size of the sensor */
327 /* rather than the size of the current video mode. */
328 {0x0058, 0x865d}, /* Horiz valid pixels (*4) (L) = 352 */
329 {0x0048, 0x865e}, /* Vert valid lines (*4) (L) = 288 */
331 {0x0015, 0x8608}, /* A11 Coef ... */
340 {0x0001, 0x8611}, /* R offset for white balance ... */
344 {0x005b, 0x8651}, /* R gain for white balance ... */
349 {0x0001, 0x863f}, /* Fixed gamma correction enable, USB control,
350 * lum filter disable, lum noise clip disable */
351 {0x00a1, 0x8656}, /* Window1 size 256x256, Windows2 size 64x64,
352 * gamma look-up disable,
353 * new edge enhancement enable */
354 {0x0018, 0x8657}, /* Edge gain high thresh */
355 {0x0020, 0x8658}, /* Edge gain low thresh */
356 {0x000a, 0x8659}, /* Edge bandwidth high threshold */
357 {0x0005, 0x865a}, /* Edge bandwidth low threshold */
358 /* -------------------------------- */
359 {0x0030, 0x8112}, /* Video drop enable, ISO streaming enable */
360 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
361 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
363 {0x0034, 0x8801}, /* SSI reg addr */
365 /* SSI data to write */
366 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
367 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
368 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
372 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
374 /* ----- Read back coefs we wrote earlier. */
375 /* READ { 0x0000, 0x8608 } -> 0000: 15 */
376 /* READ { 0x0000, 0x8609 } -> 0000: 30 */
377 /* READ { 0x0000, 0x860a } -> 0000: fb */
378 /* READ { 0x0000, 0x860b } -> 0000: 3e */
379 /* READ { 0x0000, 0x860c } -> 0000: ce */
380 /* READ { 0x0000, 0x860d } -> 0000: f4 */
381 /* READ { 0x0000, 0x860e } -> 0000: eb */
382 /* READ { 0x0000, 0x860f } -> 0000: dc */
383 /* READ { 0x0000, 0x8610 } -> 0000: 39 */
384 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
385 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
389 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
392 /* This chunk is seemingly redundant with */
393 /* earlier commands (A11 Coef...), but if I disable it, */
394 /* the image appears too dark. Maybe there was some kind of */
395 /* reset since the earlier commands, so this is necessary again. */
407 {0x0000, 0x8508}, /* Disable compression. */
408 /* Previous line was:
409 {0x0021, 0x8508}, * Enable compression. */
410 {0x0032, 0x850b}, /* compression stuff */
411 {0x0003, 0x8509}, /* compression stuff */
412 {0x0011, 0x850a}, /* compression stuff */
413 {0x0021, 0x850d}, /* compression stuff */
414 {0x0010, 0x850c}, /* compression stuff */
415 {0x0003, 0x8500}, /* *** Video mode: 160x120 */
416 {0x0001, 0x8501}, /* Hardware-dominated snap control */
417 {0x0061, 0x8656}, /* Window1 size 128x128, Windows2 size 128x128,
418 * gamma look-up disable,
419 * new edge enhancement enable */
420 {0x0018, 0x8617}, /* Window1 start X (*2) */
421 {0x0008, 0x8618}, /* Window1 start Y (*2) */
422 {0x0061, 0x8656}, /* Window1 size 128x128, Windows2 size 128x128,
423 * gamma look-up disable,
424 * new edge enhancement enable */
425 {0x0058, 0x8619}, /* Window2 start X (*2) */
426 {0x0008, 0x861a}, /* Window2 start Y (*2) */
427 {0x00ff, 0x8615}, /* High lum thresh for white balance */
428 {0x0000, 0x8616}, /* Low lum thresh for white balance */
429 {0x0012, 0x8700}, /* Clock speed 48Mhz/(2+2)/2= 6 Mhz */
430 {0x0012, 0x8700}, /* Clock speed 48Mhz/(2+2)/2= 6 Mhz */
431 /* READ { 0x0000, 0x8656 } -> 0000: 61 */
432 {0x0028, 0x8802}, /* 375 Khz SSI clock, SSI r/w sync with VSYNC */
433 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
434 /* READ { 0x0001, 0x8802 } -> 0000: 28 */
435 {0x1f28, 0x8802}, /* 375 Khz SSI clock, SSI r/w sync with VSYNC */
436 {0x0010, 0x8801}, /* SSI reg addr */
437 {0x003e, 0x8800}, /* SSI data to write */
438 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
440 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
441 /* READ { 0x0001, 0x8802 } -> 0000: 28 */
445 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
446 {0x0001, 0x8602}, /* optical black level for user settning = 1 */
449 {0x0023, 0x8700}, /* Clock speed 48Mhz/(3+2)/4= 2.4 Mhz */
450 {0x000f, 0x8602}, /* optical black level for user settning = 15 */
453 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
454 /* READ { 0x0001, 0x8802 } -> 0000: 28 */
458 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
459 {0x002f, 0x8651}, /* R gain for white balance ... */
461 /* READ { 0x0000, 0x8655 } -> 0000: 00 */
464 {0x0030, 0x8112}, /* Video drop enable, ISO streaming enable */
465 {0x0020, 0x8112}, /* Video drop enable, ISO streaming disable */
466 /* UNKNOWN DIRECTION (URB_FUNCTION_SELECT_INTERFACE: (ALT=0) ) */
471 * Initialization data for Intel EasyPC Camera CS110
473 static const u16 spca508cs110_init_data[][2] = {
474 {0x0000, 0x870b}, /* Reset CTL3 */
475 {0x0003, 0x8111}, /* Soft Reset compression, memory, TG & CDSP */
476 {0x0000, 0x8111}, /* Normal operation on reset */
478 /* External Clock 2x & Synchronous Serial Interface Output */
479 {0x0020, 0x8112}, /* Video Drop packet enable */
480 {0x0000, 0x8114}, /* Software GPIO output data */
486 /* Initial sequence Synchronous Serial Interface */
487 {0x000f, 0x8402}, /* Memory bank Address */
488 {0x0000, 0x8403}, /* Memory bank Address */
489 {0x00ba, 0x8804}, /* SSI Slave address */
490 {0x0010, 0x8802}, /* 93.75kHz SSI Clock Two DataByte */
491 {0x0010, 0x8802}, /* 93.75kHz SSI Clock two DataByte */
494 {0x000a, 0x8805}, /* a - NWG: Dunno what this is about */
528 {0x0002, 0x8704}, /* External input CKIx1 */
529 {0x0001, 0x8606}, /* 1 Line memory Read Counter (H) Result: (d)410 */
530 {0x009a, 0x8600}, /* Line memory Read Counter (L) */
531 {0x0001, 0x865b}, /* 1 Horizontal Offset for Valid Pixel(L) */
532 {0x0003, 0x865c}, /* 3 Vertical Offset for Valid Lines(L) */
533 {0x0058, 0x865d}, /* 58 Horizontal Valid Pixel Window(L) */
535 {0x0006, 0x8660}, /* Nibble data + input order */
537 {0x000a, 0x8602}, /* Optical black level set to 0x0a */
538 {0x0000, 0x8603}, /* Optical black level Offset */
540 /* {0x0000, 0x8611}, * 0 R Offset for white Balance */
541 /* {0x0000, 0x8612}, * 1 Gr Offset for white Balance */
542 /* {0x0000, 0x8613}, * 1f B Offset for white Balance */
543 /* {0x0000, 0x8614}, * f0 Gb Offset for white Balance */
545 {0x0040, 0x8651}, /* 2b BLUE gain for white balance good at all 60 */
546 {0x0030, 0x8652}, /* 41 Gr Gain for white Balance (L) */
547 {0x0035, 0x8653}, /* 26 RED gain for white balance */
548 {0x0035, 0x8654}, /* 40Gb Gain for white Balance (L) */
550 /* Fixed Gamma correction enabled (makes colours look better) */
553 /* High bits for white balance*****brightness control*** */
557 static const u16 spca508_sightcam_init_data[][2] = {
558 /* This line seems to setup the frame/canvas */
561 /* These 6 lines are needed to startup the webcam */
569 /* This part seems to make the pictures darker? (autobrightness?) */
584 /* This section is just needed, it probably
585 * does something like the previous section,
586 * but the cam won't start if it's not included.
599 /* Makes the picture darker - and the
600 * cam won't start if not included
609 /* seems to place the colors ontop of each other #1 */
615 /* if not included the pictures becomes _very_ dark */
620 /* seems to place the colors ontop of each other #2 */
626 /* webcam won't start if not included */
632 /* adjusts the colors */
640 static const u16 spca508_sightcam2_init_data[][2] = {
977 /* This line starts it all, it is not needed here */
978 /* since it has been build into the driver */
979 /* jfm: don't start now */
980 /* {0x0030, 0x8112}, */
985 * Initialization data for Creative Webcam Vista
987 static const u16 spca508_vista_init_data[][2] = {
988 {0x0008, 0x8200}, /* Clear register */
989 {0x0000, 0x870b}, /* Reset CTL3 */
990 {0x0020, 0x8112}, /* Video Drop packet enable */
991 {0x0003, 0x8111}, /* Soft Reset compression, memory, TG & CDSP */
992 {0x0000, 0x8110}, /* Disable everything */
993 {0x0000, 0x8114}, /* Software GPIO output data */
998 {0x0090, 0x8110}, /* Enable: SSI output, External 2X clock output */
1006 {0x000f, 0x8402}, /* Memory bank Address */
1007 {0x0000, 0x8403}, /* Memory bank Address */
1008 {0x00ba, 0x8804}, /* SSI Slave address */
1009 {0x0010, 0x8802}, /* 93.75kHz SSI Clock Two DataByte */
1011 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1012 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1013 {0x0010, 0x8802}, /* Will write 2 bytes (DATA1+DATA2) */
1014 {0x0020, 0x8801}, /* Register address for SSI read/write */
1015 {0x0044, 0x8805}, /* DATA2 */
1016 {0x0004, 0x8800}, /* DATA1 -> write triggered */
1017 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1019 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1020 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1025 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1027 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1028 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1033 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1035 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1036 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1041 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1043 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1044 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1049 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1051 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1052 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1057 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1059 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1060 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1065 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1067 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1068 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1073 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1075 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1076 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1081 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1083 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1084 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1089 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1091 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1092 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1097 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1099 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1100 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1105 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1107 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1108 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1113 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1115 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1116 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1121 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1123 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1124 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1129 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1131 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1132 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1137 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1140 {0x0002, 0x8704}, /* External input CKIx1 */
1141 {0x0001, 0x870c}, /* Select CKOx2 output */
1142 {0x009a, 0x8600}, /* Line memory Read Counter (L) */
1143 {0x0001, 0x8606}, /* 1 Line memory Read Counter (H) Result: (d)410 */
1148 {0x0001, 0x865b}, /* 1 Horizontal Offset for Valid Pixel(L) */
1149 {0x0003, 0x865c}, /* Vertical offset for valid lines (L) */
1150 {0x0058, 0x865d}, /* Horizontal valid pixels window (L) */
1151 {0x0048, 0x865e}, /* Vertical valid lines window (L) */
1155 /* Enable nibble data input, select nibble input order */
1157 {0x0013, 0x8608}, /* A11 Coeficients for color correction */
1159 /* Note: these values are confirmed at the end of array */
1160 {0x0005, 0x860a}, /* ... */
1166 {0x0025, 0x8610}, /* A33 Coef. */
1167 {0x00fc, 0x8611}, /* White balance offset: R */
1168 {0x0001, 0x8612}, /* White balance offset: Gr */
1169 {0x00fe, 0x8613}, /* White balance offset: B */
1170 {0x0000, 0x8614}, /* White balance offset: Gb */
1172 {0x0064, 0x8651}, /* R gain for white balance (L) */
1173 {0x0040, 0x8652}, /* Gr gain for white balance (L) */
1174 {0x0066, 0x8653}, /* B gain for white balance (L) */
1175 {0x0040, 0x8654}, /* Gb gain for white balance (L) */
1176 {0x0001, 0x863f}, /* Enable fixed gamma correction */
1178 {0x00a1, 0x8656}, /* Size - Window1: 256x256, Window2: 128x128,
1179 * UV division: UV no change,
1180 * Enable New edge enhancement */
1181 {0x0018, 0x8657}, /* Edge gain high threshold */
1182 {0x0020, 0x8658}, /* Edge gain low threshold */
1183 {0x000a, 0x8659}, /* Edge bandwidth high threshold */
1184 {0x0005, 0x865a}, /* Edge bandwidth low threshold */
1185 {0x0064, 0x8607}, /* UV filter enable */
1188 {0x0000, 0x86b0}, /* Bad pixels compensation address */
1189 {0x00dc, 0x86b1}, /* X coord for bad pixels compensation (L) */
1191 {0x0009, 0x86b3}, /* Y coord for bad pixels compensation (L) */
1219 /* READ { 0x0000, 0x8608 } -> 0000: 13 */
1220 /* READ { 0x0000, 0x8609 } -> 0000: 28 */
1221 /* READ { 0x0000, 0x8610 } -> 0000: 05 */
1222 /* READ { 0x0000, 0x8611 } -> 0000: 25 */
1223 /* READ { 0x0000, 0x8612 } -> 0000: e1 */
1224 /* READ { 0x0000, 0x8613 } -> 0000: fa */
1225 /* READ { 0x0000, 0x8614 } -> 0000: f4 */
1226 /* READ { 0x0000, 0x8615 } -> 0000: e8 */
1227 /* READ { 0x0000, 0x8616 } -> 0000: 25 */
1231 static int reg_write(struct gspca_dev *gspca_dev, u16 index, u16 value)
1234 struct usb_device *dev = gspca_dev->dev;
1236 ret = usb_control_msg(dev,
1237 usb_sndctrlpipe(dev, 0),
1239 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1240 value, index, NULL, 0, 500);
1241 gspca_dbg(gspca_dev, D_USBO, "reg write i:0x%04x = 0x%02x\n",
1244 pr_err("reg write: error %d\n", ret);
1249 /* returns: negative is error, pos or zero is data */
1250 static int reg_read(struct gspca_dev *gspca_dev,
1251 u16 index) /* wIndex */
1255 ret = usb_control_msg(gspca_dev->dev,
1256 usb_rcvctrlpipe(gspca_dev->dev, 0),
1258 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1261 gspca_dev->usb_buf, 1,
1263 gspca_dbg(gspca_dev, D_USBI, "reg read i:%04x --> %02x\n",
1264 index, gspca_dev->usb_buf[0]);
1266 pr_err("reg_read err %d\n", ret);
1269 return gspca_dev->usb_buf[0];
1272 /* send 1 or 2 bytes to the sensor via the Synchronous Serial Interface */
1273 static int ssi_w(struct gspca_dev *gspca_dev,
1278 ret = reg_write(gspca_dev, 0x8802, reg >> 8);
1281 ret = reg_write(gspca_dev, 0x8801, reg & 0x00ff);
1284 if ((reg & 0xff00) == 0x1000) { /* if 2 bytes */
1285 ret = reg_write(gspca_dev, 0x8805, val & 0x00ff);
1290 ret = reg_write(gspca_dev, 0x8800, val);
1294 /* poll until not busy */
1297 ret = reg_read(gspca_dev, 0x8803);
1300 if (gspca_dev->usb_buf[0] == 0)
1303 gspca_err(gspca_dev, "ssi_w busy %02x\n",
1304 gspca_dev->usb_buf[0]);
1315 static int write_vector(struct gspca_dev *gspca_dev,
1316 const u16 (*data)[2])
1320 while ((*data)[1] != 0) {
1321 if ((*data)[1] & 0x8000) {
1322 if ((*data)[1] == 0xdd00) /* delay */
1325 ret = reg_write(gspca_dev, (*data)[1],
1328 ret = ssi_w(gspca_dev, (*data)[1], (*data)[0]);
1337 /* this function is called at probe time */
1338 static int sd_config(struct gspca_dev *gspca_dev,
1339 const struct usb_device_id *id)
1341 struct sd *sd = (struct sd *) gspca_dev;
1343 const u16 (*init_data)[2];
1344 static const u16 (*(init_data_tb[]))[2] = {
1345 spca508_vista_init_data, /* CreativeVista 0 */
1346 spca508_sightcam_init_data, /* HamaUSBSightcam 1 */
1347 spca508_sightcam2_init_data, /* HamaUSBSightcam2 2 */
1348 spca508cs110_init_data, /* IntelEasyPCCamera 3 */
1349 spca508cs110_init_data, /* MicroInnovationIC200 4 */
1350 spca508_init_data, /* ViewQuestVQ110 5 */
1354 /* Read from global register the USB product and vendor IDs, just to
1355 * prove that we can communicate with the device. This works, which
1356 * confirms at we are communicating properly and that the device
1358 data1 = reg_read(gspca_dev, 0x8104);
1359 data2 = reg_read(gspca_dev, 0x8105);
1360 gspca_dbg(gspca_dev, D_PROBE, "Webcam Vendor ID: 0x%02x%02x\n",
1363 data1 = reg_read(gspca_dev, 0x8106);
1364 data2 = reg_read(gspca_dev, 0x8107);
1365 gspca_dbg(gspca_dev, D_PROBE, "Webcam Product ID: 0x%02x%02x\n",
1368 data1 = reg_read(gspca_dev, 0x8621);
1369 gspca_dbg(gspca_dev, D_PROBE, "Window 1 average luminance: %d\n",
1372 cam = &gspca_dev->cam;
1373 cam->cam_mode = sif_mode;
1374 cam->nmodes = ARRAY_SIZE(sif_mode);
1376 sd->subtype = id->driver_info;
1378 init_data = init_data_tb[sd->subtype];
1379 return write_vector(gspca_dev, init_data);
1382 /* this function is called at probe and resume time */
1383 static int sd_init(struct gspca_dev *gspca_dev)
1388 static int sd_start(struct gspca_dev *gspca_dev)
1392 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
1393 reg_write(gspca_dev, 0x8500, mode);
1397 reg_write(gspca_dev, 0x8700, 0x28); /* clock */
1402 reg_write(gspca_dev, 0x8700, 0x23); /* clock */
1405 reg_write(gspca_dev, 0x8112, 0x10 | 0x20);
1409 static void sd_stopN(struct gspca_dev *gspca_dev)
1411 /* Video ISO disable, Video Drop Packet enable: */
1412 reg_write(gspca_dev, 0x8112, 0x20);
1415 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1416 u8 *data, /* isoc packet */
1417 int len) /* iso packet length */
1420 case 0: /* start of frame */
1421 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
1422 data += SPCA508_OFFSET_DATA;
1423 len -= SPCA508_OFFSET_DATA;
1424 gspca_frame_add(gspca_dev, FIRST_PACKET, data, len);
1426 case 0xff: /* drop */
1431 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
1436 static void setbrightness(struct gspca_dev *gspca_dev, s32 brightness)
1438 /* MX seem contrast */
1439 reg_write(gspca_dev, 0x8651, brightness);
1440 reg_write(gspca_dev, 0x8652, brightness);
1441 reg_write(gspca_dev, 0x8653, brightness);
1442 reg_write(gspca_dev, 0x8654, brightness);
1445 static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
1447 struct gspca_dev *gspca_dev =
1448 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
1450 gspca_dev->usb_err = 0;
1452 if (!gspca_dev->streaming)
1456 case V4L2_CID_BRIGHTNESS:
1457 setbrightness(gspca_dev, ctrl->val);
1460 return gspca_dev->usb_err;
1463 static const struct v4l2_ctrl_ops sd_ctrl_ops = {
1464 .s_ctrl = sd_s_ctrl,
1467 static int sd_init_controls(struct gspca_dev *gspca_dev)
1469 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
1471 gspca_dev->vdev.ctrl_handler = hdl;
1472 v4l2_ctrl_handler_init(hdl, 5);
1473 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1474 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
1477 pr_err("Could not initialize controls\n");
1483 /* sub-driver description */
1484 static const struct sd_desc sd_desc = {
1485 .name = MODULE_NAME,
1486 .config = sd_config,
1488 .init_controls = sd_init_controls,
1491 .pkt_scan = sd_pkt_scan,
1494 /* -- module initialisation -- */
1495 static const struct usb_device_id device_table[] = {
1496 {USB_DEVICE(0x0130, 0x0130), .driver_info = HamaUSBSightcam},
1497 {USB_DEVICE(0x041e, 0x4018), .driver_info = CreativeVista},
1498 {USB_DEVICE(0x0733, 0x0110), .driver_info = ViewQuestVQ110},
1499 {USB_DEVICE(0x0af9, 0x0010), .driver_info = HamaUSBSightcam},
1500 {USB_DEVICE(0x0af9, 0x0011), .driver_info = HamaUSBSightcam2},
1501 {USB_DEVICE(0x8086, 0x0110), .driver_info = IntelEasyPCCamera},
1504 MODULE_DEVICE_TABLE(usb, device_table);
1506 /* -- device connect -- */
1507 static int sd_probe(struct usb_interface *intf,
1508 const struct usb_device_id *id)
1510 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
1514 static struct usb_driver sd_driver = {
1515 .name = MODULE_NAME,
1516 .id_table = device_table,
1518 .disconnect = gspca_disconnect,
1520 .suspend = gspca_suspend,
1521 .resume = gspca_resume,
1522 .reset_resume = gspca_resume,
1526 module_usb_driver(sd_driver);