2 * SPCA508 chip based cameras subdriver
4 * Copyright (C) 2009 Jean-Francois Moine <http://moinejf.free.fr>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19 #define MODULE_NAME "spca508"
23 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
24 MODULE_DESCRIPTION("GSPCA/SPCA508 USB Camera Driver");
25 MODULE_LICENSE("GPL");
27 /* specific webcam descriptor */
29 struct gspca_dev gspca_dev; /* !! must be the first item */
32 #define CreativeVista 0
33 #define HamaUSBSightcam 1
34 #define HamaUSBSightcam2 2
35 #define IntelEasyPCCamera 3
36 #define MicroInnovationIC200 4
37 #define ViewQuestVQ110 5
40 static const struct v4l2_pix_format sif_mode[] = {
41 {160, 120, V4L2_PIX_FMT_SPCA508, V4L2_FIELD_NONE,
43 .sizeimage = 160 * 120 * 3 / 2,
44 .colorspace = V4L2_COLORSPACE_SRGB,
46 {176, 144, V4L2_PIX_FMT_SPCA508, V4L2_FIELD_NONE,
48 .sizeimage = 176 * 144 * 3 / 2,
49 .colorspace = V4L2_COLORSPACE_SRGB,
51 {320, 240, V4L2_PIX_FMT_SPCA508, V4L2_FIELD_NONE,
53 .sizeimage = 320 * 240 * 3 / 2,
54 .colorspace = V4L2_COLORSPACE_SRGB,
56 {352, 288, V4L2_PIX_FMT_SPCA508, V4L2_FIELD_NONE,
58 .sizeimage = 352 * 288 * 3 / 2,
59 .colorspace = V4L2_COLORSPACE_SRGB,
63 /* Frame packet header offsets for the spca508 */
64 #define SPCA508_OFFSET_DATA 37
67 * Initialization data: this is the first set-up data written to the
68 * device (before the open data).
70 static const u16 spca508_init_data[][2] = {
73 {0x0020, 0x8112}, /* Video drop enable, ISO streaming disable */
74 {0x0003, 0x8111}, /* Reset compression & memory */
75 {0x0000, 0x8110}, /* Disable all outputs */
76 /* READ {0x0000, 0x8114} -> 0000: 00 */
77 {0x0000, 0x8114}, /* SW GPIO data */
78 {0x0008, 0x8110}, /* Enable charge pump output */
79 {0x0002, 0x8116}, /* 200 kHz pump clock */
80 /* UNKNOWN DIRECTION (URB_FUNCTION_SELECT_INTERFACE:) */
81 {0x0003, 0x8111}, /* Reset compression & memory */
82 {0x0000, 0x8111}, /* Normal mode (not reset) */
84 /* Enable charge pump output, sync.serial,external 2x clock */
85 {0x000d, 0x8114}, /* SW GPIO data */
86 {0x0002, 0x8116}, /* 200 kHz pump clock */
87 {0x0020, 0x8112}, /* Video drop enable, ISO streaming disable */
88 /* --------------------------------------- */
89 {0x000f, 0x8402}, /* memory bank */
90 {0x0000, 0x8403}, /* ... address */
91 /* --------------------------------------- */
92 /* 0x88__ is Synchronous Serial Interface. */
93 /* TBD: This table could be expressed more compactly */
94 /* using spca508_write_i2c_vector(). */
95 /* TBD: Should see if the values in spca50x_i2c_data */
96 /* would work with the VQ110 instead of the values */
98 {0x00c0, 0x8804}, /* SSI slave addr */
99 {0x0008, 0x8802}, /* 375 Khz SSI clock */
100 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
101 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
102 {0x0008, 0x8802}, /* 375 Khz SSI clock */
103 {0x0012, 0x8801}, /* SSI reg addr */
104 {0x0080, 0x8800}, /* SSI data to write */
105 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
106 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
107 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
108 {0x0008, 0x8802}, /* 375 Khz SSI clock */
109 {0x0012, 0x8801}, /* SSI reg addr */
110 {0x0000, 0x8800}, /* SSI data to write */
111 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
112 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
113 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
114 {0x0008, 0x8802}, /* 375 Khz SSI clock */
115 {0x0011, 0x8801}, /* SSI reg addr */
116 {0x0040, 0x8800}, /* SSI data to write */
117 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
118 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
119 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
123 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
124 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
125 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
129 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
130 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
131 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
135 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
136 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
137 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
141 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
142 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
143 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
147 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
148 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
149 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
153 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
154 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
155 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
159 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
160 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
161 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
165 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
166 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
167 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
171 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
172 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
173 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
177 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
178 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
179 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
183 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
184 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
185 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
189 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
190 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
191 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
195 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
196 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
197 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
201 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
202 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
203 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
207 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
208 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
209 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
213 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
214 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
215 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
219 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
220 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
221 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
225 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
226 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
227 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
231 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
232 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
233 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
237 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
238 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
239 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
243 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
244 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
245 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
249 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
250 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
251 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
255 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
256 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
257 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
261 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
262 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
263 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
267 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
268 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
269 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
273 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
274 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
275 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
279 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
280 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
281 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
285 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
286 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
287 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
291 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
292 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
293 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
297 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
298 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
299 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
303 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
304 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
305 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
309 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
310 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
311 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
315 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
316 /* --------------------------------------- */
317 {0x0012, 0x8700}, /* Clock speed 48Mhz/(2+2)/2= 6 Mhz */
318 {0x0000, 0x8701}, /* CKx1 clock delay adj */
319 {0x0000, 0x8701}, /* CKx1 clock delay adj */
320 {0x0001, 0x870c}, /* CKOx2 output */
321 /* --------------------------------------- */
322 {0x0080, 0x8600}, /* Line memory read counter (L) */
323 {0x0001, 0x8606}, /* reserved */
324 {0x0064, 0x8607}, /* Line memory read counter (H) 0x6480=25,728 */
325 {0x002a, 0x8601}, /* CDSP sharp interpolation mode,
326 * line sel for color sep, edge enhance enab */
327 {0x0000, 0x8602}, /* optical black level for user settng = 0 */
328 {0x0080, 0x8600}, /* Line memory read counter (L) */
329 {0x000a, 0x8603}, /* optical black level calc mode:
330 * auto; optical black offset = 10 */
331 {0x00df, 0x865b}, /* Horiz offset for valid pixels (L)=0xdf */
332 {0x0012, 0x865c}, /* Vert offset for valid lines (L)=0x12 */
334 /* The following two lines seem to be the "wrong" resolution. */
335 /* But perhaps these indicate the actual size of the sensor */
336 /* rather than the size of the current video mode. */
337 {0x0058, 0x865d}, /* Horiz valid pixels (*4) (L) = 352 */
338 {0x0048, 0x865e}, /* Vert valid lines (*4) (L) = 288 */
340 {0x0015, 0x8608}, /* A11 Coef ... */
349 {0x0001, 0x8611}, /* R offset for white balance ... */
353 {0x005b, 0x8651}, /* R gain for white balance ... */
358 {0x0001, 0x863f}, /* Fixed gamma correction enable, USB control,
359 * lum filter disable, lum noise clip disable */
360 {0x00a1, 0x8656}, /* Window1 size 256x256, Windows2 size 64x64,
361 * gamma look-up disable,
362 * new edge enhancement enable */
363 {0x0018, 0x8657}, /* Edge gain high thresh */
364 {0x0020, 0x8658}, /* Edge gain low thresh */
365 {0x000a, 0x8659}, /* Edge bandwidth high threshold */
366 {0x0005, 0x865a}, /* Edge bandwidth low threshold */
367 /* -------------------------------- */
368 {0x0030, 0x8112}, /* Video drop enable, ISO streaming enable */
369 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
370 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
372 {0x0034, 0x8801}, /* SSI reg addr */
374 /* SSI data to write */
375 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
376 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
377 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
381 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
383 /* ----- Read back coefs we wrote earlier. */
384 /* READ { 0x0000, 0x8608 } -> 0000: 15 */
385 /* READ { 0x0000, 0x8609 } -> 0000: 30 */
386 /* READ { 0x0000, 0x860a } -> 0000: fb */
387 /* READ { 0x0000, 0x860b } -> 0000: 3e */
388 /* READ { 0x0000, 0x860c } -> 0000: ce */
389 /* READ { 0x0000, 0x860d } -> 0000: f4 */
390 /* READ { 0x0000, 0x860e } -> 0000: eb */
391 /* READ { 0x0000, 0x860f } -> 0000: dc */
392 /* READ { 0x0000, 0x8610 } -> 0000: 39 */
393 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
394 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
398 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
401 /* This chunk is seemingly redundant with */
402 /* earlier commands (A11 Coef...), but if I disable it, */
403 /* the image appears too dark. Maybe there was some kind of */
404 /* reset since the earlier commands, so this is necessary again. */
416 {0x0000, 0x8508}, /* Disable compression. */
417 /* Previous line was:
418 {0x0021, 0x8508}, * Enable compression. */
419 {0x0032, 0x850b}, /* compression stuff */
420 {0x0003, 0x8509}, /* compression stuff */
421 {0x0011, 0x850a}, /* compression stuff */
422 {0x0021, 0x850d}, /* compression stuff */
423 {0x0010, 0x850c}, /* compression stuff */
424 {0x0003, 0x8500}, /* *** Video mode: 160x120 */
425 {0x0001, 0x8501}, /* Hardware-dominated snap control */
426 {0x0061, 0x8656}, /* Window1 size 128x128, Windows2 size 128x128,
427 * gamma look-up disable,
428 * new edge enhancement enable */
429 {0x0018, 0x8617}, /* Window1 start X (*2) */
430 {0x0008, 0x8618}, /* Window1 start Y (*2) */
431 {0x0061, 0x8656}, /* Window1 size 128x128, Windows2 size 128x128,
432 * gamma look-up disable,
433 * new edge enhancement enable */
434 {0x0058, 0x8619}, /* Window2 start X (*2) */
435 {0x0008, 0x861a}, /* Window2 start Y (*2) */
436 {0x00ff, 0x8615}, /* High lum thresh for white balance */
437 {0x0000, 0x8616}, /* Low lum thresh for white balance */
438 {0x0012, 0x8700}, /* Clock speed 48Mhz/(2+2)/2= 6 Mhz */
439 {0x0012, 0x8700}, /* Clock speed 48Mhz/(2+2)/2= 6 Mhz */
440 /* READ { 0x0000, 0x8656 } -> 0000: 61 */
441 {0x0028, 0x8802}, /* 375 Khz SSI clock, SSI r/w sync with VSYNC */
442 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
443 /* READ { 0x0001, 0x8802 } -> 0000: 28 */
444 {0x1f28, 0x8802}, /* 375 Khz SSI clock, SSI r/w sync with VSYNC */
445 {0x0010, 0x8801}, /* SSI reg addr */
446 {0x003e, 0x8800}, /* SSI data to write */
447 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
449 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
450 /* READ { 0x0001, 0x8802 } -> 0000: 28 */
454 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
455 {0x0001, 0x8602}, /* optical black level for user settning = 1 */
458 {0x0023, 0x8700}, /* Clock speed 48Mhz/(3+2)/4= 2.4 Mhz */
459 {0x000f, 0x8602}, /* optical black level for user settning = 15 */
462 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
463 /* READ { 0x0001, 0x8802 } -> 0000: 28 */
467 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
468 {0x002f, 0x8651}, /* R gain for white balance ... */
470 /* READ { 0x0000, 0x8655 } -> 0000: 00 */
473 {0x0030, 0x8112}, /* Video drop enable, ISO streaming enable */
474 {0x0020, 0x8112}, /* Video drop enable, ISO streaming disable */
475 /* UNKNOWN DIRECTION (URB_FUNCTION_SELECT_INTERFACE: (ALT=0) ) */
480 * Initialization data for Intel EasyPC Camera CS110
482 static const u16 spca508cs110_init_data[][2] = {
483 {0x0000, 0x870b}, /* Reset CTL3 */
484 {0x0003, 0x8111}, /* Soft Reset compression, memory, TG & CDSP */
485 {0x0000, 0x8111}, /* Normal operation on reset */
487 /* External Clock 2x & Synchronous Serial Interface Output */
488 {0x0020, 0x8112}, /* Video Drop packet enable */
489 {0x0000, 0x8114}, /* Software GPIO output data */
495 /* Initial sequence Synchronous Serial Interface */
496 {0x000f, 0x8402}, /* Memory bank Address */
497 {0x0000, 0x8403}, /* Memory bank Address */
498 {0x00ba, 0x8804}, /* SSI Slave address */
499 {0x0010, 0x8802}, /* 93.75kHz SSI Clock Two DataByte */
500 {0x0010, 0x8802}, /* 93.75kHz SSI Clock two DataByte */
503 {0x000a, 0x8805}, /* a - NWG: Dunno what this is about */
537 {0x0002, 0x8704}, /* External input CKIx1 */
538 {0x0001, 0x8606}, /* 1 Line memory Read Counter (H) Result: (d)410 */
539 {0x009a, 0x8600}, /* Line memory Read Counter (L) */
540 {0x0001, 0x865b}, /* 1 Horizontal Offset for Valid Pixel(L) */
541 {0x0003, 0x865c}, /* 3 Vertical Offset for Valid Lines(L) */
542 {0x0058, 0x865d}, /* 58 Horizontal Valid Pixel Window(L) */
544 {0x0006, 0x8660}, /* Nibble data + input order */
546 {0x000a, 0x8602}, /* Optical black level set to 0x0a */
547 {0x0000, 0x8603}, /* Optical black level Offset */
549 /* {0x0000, 0x8611}, * 0 R Offset for white Balance */
550 /* {0x0000, 0x8612}, * 1 Gr Offset for white Balance */
551 /* {0x0000, 0x8613}, * 1f B Offset for white Balance */
552 /* {0x0000, 0x8614}, * f0 Gb Offset for white Balance */
554 {0x0040, 0x8651}, /* 2b BLUE gain for white balance good at all 60 */
555 {0x0030, 0x8652}, /* 41 Gr Gain for white Balance (L) */
556 {0x0035, 0x8653}, /* 26 RED gain for white balance */
557 {0x0035, 0x8654}, /* 40Gb Gain for white Balance (L) */
559 /* Fixed Gamma correction enabled (makes colours look better) */
562 /* High bits for white balance*****brightness control*** */
566 static const u16 spca508_sightcam_init_data[][2] = {
567 /* This line seems to setup the frame/canvas */
570 /* These 6 lines are needed to startup the webcam */
578 /* This part seems to make the pictures darker? (autobrightness?) */
593 /* This section is just needed, it probably
594 * does something like the previous section,
595 * but the cam won't start if it's not included.
608 /* Makes the picture darker - and the
609 * cam won't start if not included
618 /* seems to place the colors ontop of each other #1 */
624 /* if not included the pictures becomes _very_ dark */
629 /* seems to place the colors ontop of each other #2 */
635 /* webcam won't start if not included */
641 /* adjusts the colors */
649 static const u16 spca508_sightcam2_init_data[][2] = {
986 /* This line starts it all, it is not needed here */
987 /* since it has been build into the driver */
988 /* jfm: don't start now */
989 /* {0x0030, 0x8112}, */
994 * Initialization data for Creative Webcam Vista
996 static const u16 spca508_vista_init_data[][2] = {
997 {0x0008, 0x8200}, /* Clear register */
998 {0x0000, 0x870b}, /* Reset CTL3 */
999 {0x0020, 0x8112}, /* Video Drop packet enable */
1000 {0x0003, 0x8111}, /* Soft Reset compression, memory, TG & CDSP */
1001 {0x0000, 0x8110}, /* Disable everything */
1002 {0x0000, 0x8114}, /* Software GPIO output data */
1007 {0x0090, 0x8110}, /* Enable: SSI output, External 2X clock output */
1015 {0x000f, 0x8402}, /* Memory bank Address */
1016 {0x0000, 0x8403}, /* Memory bank Address */
1017 {0x00ba, 0x8804}, /* SSI Slave address */
1018 {0x0010, 0x8802}, /* 93.75kHz SSI Clock Two DataByte */
1020 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1021 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1022 {0x0010, 0x8802}, /* Will write 2 bytes (DATA1+DATA2) */
1023 {0x0020, 0x8801}, /* Register address for SSI read/write */
1024 {0x0044, 0x8805}, /* DATA2 */
1025 {0x0004, 0x8800}, /* DATA1 -> write triggered */
1026 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1028 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1029 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1034 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1036 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1037 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1042 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1044 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1045 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1050 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1052 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1053 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1058 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1060 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1061 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1066 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1068 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1069 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1074 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1076 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1077 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1082 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1084 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1085 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1090 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1092 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1093 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1098 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1100 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1101 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1106 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1108 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1109 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1114 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1116 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1117 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1122 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1124 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1125 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1130 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1132 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1133 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1138 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1140 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1141 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1146 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1149 {0x0002, 0x8704}, /* External input CKIx1 */
1150 {0x0001, 0x870c}, /* Select CKOx2 output */
1151 {0x009a, 0x8600}, /* Line memory Read Counter (L) */
1152 {0x0001, 0x8606}, /* 1 Line memory Read Counter (H) Result: (d)410 */
1157 {0x0001, 0x865b}, /* 1 Horizontal Offset for Valid Pixel(L) */
1158 {0x0003, 0x865c}, /* Vertical offset for valid lines (L) */
1159 {0x0058, 0x865d}, /* Horizontal valid pixels window (L) */
1160 {0x0048, 0x865e}, /* Vertical valid lines window (L) */
1164 /* Enable nibble data input, select nibble input order */
1166 {0x0013, 0x8608}, /* A11 Coeficients for color correction */
1168 /* Note: these values are confirmed at the end of array */
1169 {0x0005, 0x860a}, /* ... */
1175 {0x0025, 0x8610}, /* A33 Coef. */
1176 {0x00fc, 0x8611}, /* White balance offset: R */
1177 {0x0001, 0x8612}, /* White balance offset: Gr */
1178 {0x00fe, 0x8613}, /* White balance offset: B */
1179 {0x0000, 0x8614}, /* White balance offset: Gb */
1181 {0x0064, 0x8651}, /* R gain for white balance (L) */
1182 {0x0040, 0x8652}, /* Gr gain for white balance (L) */
1183 {0x0066, 0x8653}, /* B gain for white balance (L) */
1184 {0x0040, 0x8654}, /* Gb gain for white balance (L) */
1185 {0x0001, 0x863f}, /* Enable fixed gamma correction */
1187 {0x00a1, 0x8656}, /* Size - Window1: 256x256, Window2: 128x128,
1188 * UV division: UV no change,
1189 * Enable New edge enhancement */
1190 {0x0018, 0x8657}, /* Edge gain high threshold */
1191 {0x0020, 0x8658}, /* Edge gain low threshold */
1192 {0x000a, 0x8659}, /* Edge bandwidth high threshold */
1193 {0x0005, 0x865a}, /* Edge bandwidth low threshold */
1194 {0x0064, 0x8607}, /* UV filter enable */
1197 {0x0000, 0x86b0}, /* Bad pixels compensation address */
1198 {0x00dc, 0x86b1}, /* X coord for bad pixels compensation (L) */
1200 {0x0009, 0x86b3}, /* Y coord for bad pixels compensation (L) */
1228 /* READ { 0x0000, 0x8608 } -> 0000: 13 */
1229 /* READ { 0x0000, 0x8609 } -> 0000: 28 */
1230 /* READ { 0x0000, 0x8610 } -> 0000: 05 */
1231 /* READ { 0x0000, 0x8611 } -> 0000: 25 */
1232 /* READ { 0x0000, 0x8612 } -> 0000: e1 */
1233 /* READ { 0x0000, 0x8613 } -> 0000: fa */
1234 /* READ { 0x0000, 0x8614 } -> 0000: f4 */
1235 /* READ { 0x0000, 0x8615 } -> 0000: e8 */
1236 /* READ { 0x0000, 0x8616 } -> 0000: 25 */
1240 static int reg_write(struct gspca_dev *gspca_dev, u16 index, u16 value)
1243 struct usb_device *dev = gspca_dev->dev;
1245 ret = usb_control_msg(dev,
1246 usb_sndctrlpipe(dev, 0),
1248 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1249 value, index, NULL, 0, 500);
1250 gspca_dbg(gspca_dev, D_USBO, "reg write i:0x%04x = 0x%02x\n",
1253 pr_err("reg write: error %d\n", ret);
1258 /* returns: negative is error, pos or zero is data */
1259 static int reg_read(struct gspca_dev *gspca_dev,
1260 u16 index) /* wIndex */
1264 ret = usb_control_msg(gspca_dev->dev,
1265 usb_rcvctrlpipe(gspca_dev->dev, 0),
1267 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
1270 gspca_dev->usb_buf, 1,
1272 gspca_dbg(gspca_dev, D_USBI, "reg read i:%04x --> %02x\n",
1273 index, gspca_dev->usb_buf[0]);
1275 pr_err("reg_read err %d\n", ret);
1278 return gspca_dev->usb_buf[0];
1281 /* send 1 or 2 bytes to the sensor via the Synchronous Serial Interface */
1282 static int ssi_w(struct gspca_dev *gspca_dev,
1287 ret = reg_write(gspca_dev, 0x8802, reg >> 8);
1290 ret = reg_write(gspca_dev, 0x8801, reg & 0x00ff);
1293 if ((reg & 0xff00) == 0x1000) { /* if 2 bytes */
1294 ret = reg_write(gspca_dev, 0x8805, val & 0x00ff);
1299 ret = reg_write(gspca_dev, 0x8800, val);
1303 /* poll until not busy */
1306 ret = reg_read(gspca_dev, 0x8803);
1309 if (gspca_dev->usb_buf[0] == 0)
1312 gspca_err(gspca_dev, "ssi_w busy %02x\n",
1313 gspca_dev->usb_buf[0]);
1324 static int write_vector(struct gspca_dev *gspca_dev,
1325 const u16 (*data)[2])
1329 while ((*data)[1] != 0) {
1330 if ((*data)[1] & 0x8000) {
1331 if ((*data)[1] == 0xdd00) /* delay */
1334 ret = reg_write(gspca_dev, (*data)[1],
1337 ret = ssi_w(gspca_dev, (*data)[1], (*data)[0]);
1346 /* this function is called at probe time */
1347 static int sd_config(struct gspca_dev *gspca_dev,
1348 const struct usb_device_id *id)
1350 struct sd *sd = (struct sd *) gspca_dev;
1352 const u16 (*init_data)[2];
1353 static const u16 (*(init_data_tb[]))[2] = {
1354 spca508_vista_init_data, /* CreativeVista 0 */
1355 spca508_sightcam_init_data, /* HamaUSBSightcam 1 */
1356 spca508_sightcam2_init_data, /* HamaUSBSightcam2 2 */
1357 spca508cs110_init_data, /* IntelEasyPCCamera 3 */
1358 spca508cs110_init_data, /* MicroInnovationIC200 4 */
1359 spca508_init_data, /* ViewQuestVQ110 5 */
1363 /* Read from global register the USB product and vendor IDs, just to
1364 * prove that we can communicate with the device. This works, which
1365 * confirms at we are communicating properly and that the device
1367 data1 = reg_read(gspca_dev, 0x8104);
1368 data2 = reg_read(gspca_dev, 0x8105);
1369 gspca_dbg(gspca_dev, D_PROBE, "Webcam Vendor ID: 0x%02x%02x\n",
1372 data1 = reg_read(gspca_dev, 0x8106);
1373 data2 = reg_read(gspca_dev, 0x8107);
1374 gspca_dbg(gspca_dev, D_PROBE, "Webcam Product ID: 0x%02x%02x\n",
1377 data1 = reg_read(gspca_dev, 0x8621);
1378 gspca_dbg(gspca_dev, D_PROBE, "Window 1 average luminance: %d\n",
1381 cam = &gspca_dev->cam;
1382 cam->cam_mode = sif_mode;
1383 cam->nmodes = ARRAY_SIZE(sif_mode);
1385 sd->subtype = id->driver_info;
1387 init_data = init_data_tb[sd->subtype];
1388 return write_vector(gspca_dev, init_data);
1391 /* this function is called at probe and resume time */
1392 static int sd_init(struct gspca_dev *gspca_dev)
1397 static int sd_start(struct gspca_dev *gspca_dev)
1401 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
1402 reg_write(gspca_dev, 0x8500, mode);
1406 reg_write(gspca_dev, 0x8700, 0x28); /* clock */
1411 reg_write(gspca_dev, 0x8700, 0x23); /* clock */
1414 reg_write(gspca_dev, 0x8112, 0x10 | 0x20);
1418 static void sd_stopN(struct gspca_dev *gspca_dev)
1420 /* Video ISO disable, Video Drop Packet enable: */
1421 reg_write(gspca_dev, 0x8112, 0x20);
1424 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1425 u8 *data, /* isoc packet */
1426 int len) /* iso packet length */
1429 case 0: /* start of frame */
1430 gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0);
1431 data += SPCA508_OFFSET_DATA;
1432 len -= SPCA508_OFFSET_DATA;
1433 gspca_frame_add(gspca_dev, FIRST_PACKET, data, len);
1435 case 0xff: /* drop */
1440 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
1445 static void setbrightness(struct gspca_dev *gspca_dev, s32 brightness)
1447 /* MX seem contrast */
1448 reg_write(gspca_dev, 0x8651, brightness);
1449 reg_write(gspca_dev, 0x8652, brightness);
1450 reg_write(gspca_dev, 0x8653, brightness);
1451 reg_write(gspca_dev, 0x8654, brightness);
1454 static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
1456 struct gspca_dev *gspca_dev =
1457 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
1459 gspca_dev->usb_err = 0;
1461 if (!gspca_dev->streaming)
1465 case V4L2_CID_BRIGHTNESS:
1466 setbrightness(gspca_dev, ctrl->val);
1469 return gspca_dev->usb_err;
1472 static const struct v4l2_ctrl_ops sd_ctrl_ops = {
1473 .s_ctrl = sd_s_ctrl,
1476 static int sd_init_controls(struct gspca_dev *gspca_dev)
1478 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
1480 gspca_dev->vdev.ctrl_handler = hdl;
1481 v4l2_ctrl_handler_init(hdl, 5);
1482 v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
1483 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
1486 pr_err("Could not initialize controls\n");
1492 /* sub-driver description */
1493 static const struct sd_desc sd_desc = {
1494 .name = MODULE_NAME,
1495 .config = sd_config,
1497 .init_controls = sd_init_controls,
1500 .pkt_scan = sd_pkt_scan,
1503 /* -- module initialisation -- */
1504 static const struct usb_device_id device_table[] = {
1505 {USB_DEVICE(0x0130, 0x0130), .driver_info = HamaUSBSightcam},
1506 {USB_DEVICE(0x041e, 0x4018), .driver_info = CreativeVista},
1507 {USB_DEVICE(0x0733, 0x0110), .driver_info = ViewQuestVQ110},
1508 {USB_DEVICE(0x0af9, 0x0010), .driver_info = HamaUSBSightcam},
1509 {USB_DEVICE(0x0af9, 0x0011), .driver_info = HamaUSBSightcam2},
1510 {USB_DEVICE(0x8086, 0x0110), .driver_info = IntelEasyPCCamera},
1513 MODULE_DEVICE_TABLE(usb, device_table);
1515 /* -- device connect -- */
1516 static int sd_probe(struct usb_interface *intf,
1517 const struct usb_device_id *id)
1519 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
1523 static struct usb_driver sd_driver = {
1524 .name = MODULE_NAME,
1525 .id_table = device_table,
1527 .disconnect = gspca_disconnect,
1529 .suspend = gspca_suspend,
1530 .resume = gspca_resume,
1531 .reset_resume = gspca_resume,
1535 module_usb_driver(sd_driver);