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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23 #define MODULE_NAME "spca508"
27 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
28 MODULE_DESCRIPTION("GSPCA/SPCA508 USB Camera Driver");
29 MODULE_LICENSE("GPL");
31 /* specific webcam descriptor */
33 struct gspca_dev gspca_dev
; /* !! must be the first item */
36 #define CreativeVista 0
37 #define HamaUSBSightcam 1
38 #define HamaUSBSightcam2 2
39 #define IntelEasyPCCamera 3
40 #define MicroInnovationIC200 4
41 #define ViewQuestVQ110 5
44 static const struct v4l2_pix_format sif_mode
[] = {
45 {160, 120, V4L2_PIX_FMT_SPCA508
, V4L2_FIELD_NONE
,
47 .sizeimage
= 160 * 120 * 3 / 2,
48 .colorspace
= V4L2_COLORSPACE_SRGB
,
50 {176, 144, V4L2_PIX_FMT_SPCA508
, V4L2_FIELD_NONE
,
52 .sizeimage
= 176 * 144 * 3 / 2,
53 .colorspace
= V4L2_COLORSPACE_SRGB
,
55 {320, 240, V4L2_PIX_FMT_SPCA508
, V4L2_FIELD_NONE
,
57 .sizeimage
= 320 * 240 * 3 / 2,
58 .colorspace
= V4L2_COLORSPACE_SRGB
,
60 {352, 288, V4L2_PIX_FMT_SPCA508
, V4L2_FIELD_NONE
,
62 .sizeimage
= 352 * 288 * 3 / 2,
63 .colorspace
= V4L2_COLORSPACE_SRGB
,
67 /* Frame packet header offsets for the spca508 */
68 #define SPCA508_OFFSET_DATA 37
71 * Initialization data: this is the first set-up data written to the
72 * device (before the open data).
74 static const u16 spca508_init_data
[][2] = {
77 {0x0020, 0x8112}, /* Video drop enable, ISO streaming disable */
78 {0x0003, 0x8111}, /* Reset compression & memory */
79 {0x0000, 0x8110}, /* Disable all outputs */
80 /* READ {0x0000, 0x8114} -> 0000: 00 */
81 {0x0000, 0x8114}, /* SW GPIO data */
82 {0x0008, 0x8110}, /* Enable charge pump output */
83 {0x0002, 0x8116}, /* 200 kHz pump clock */
84 /* UNKNOWN DIRECTION (URB_FUNCTION_SELECT_INTERFACE:) */
85 {0x0003, 0x8111}, /* Reset compression & memory */
86 {0x0000, 0x8111}, /* Normal mode (not reset) */
88 /* Enable charge pump output, sync.serial,external 2x clock */
89 {0x000d, 0x8114}, /* SW GPIO data */
90 {0x0002, 0x8116}, /* 200 kHz pump clock */
91 {0x0020, 0x8112}, /* Video drop enable, ISO streaming disable */
92 /* --------------------------------------- */
93 {0x000f, 0x8402}, /* memory bank */
94 {0x0000, 0x8403}, /* ... address */
95 /* --------------------------------------- */
96 /* 0x88__ is Synchronous Serial Interface. */
97 /* TBD: This table could be expressed more compactly */
98 /* using spca508_write_i2c_vector(). */
99 /* TBD: Should see if the values in spca50x_i2c_data */
100 /* would work with the VQ110 instead of the values */
102 {0x00c0, 0x8804}, /* SSI slave addr */
103 {0x0008, 0x8802}, /* 375 Khz SSI clock */
104 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
105 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
106 {0x0008, 0x8802}, /* 375 Khz SSI clock */
107 {0x0012, 0x8801}, /* SSI reg addr */
108 {0x0080, 0x8800}, /* SSI data to write */
109 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
110 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
111 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
112 {0x0008, 0x8802}, /* 375 Khz SSI clock */
113 {0x0012, 0x8801}, /* SSI reg addr */
114 {0x0000, 0x8800}, /* SSI data to write */
115 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
116 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
117 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
118 {0x0008, 0x8802}, /* 375 Khz SSI clock */
119 {0x0011, 0x8801}, /* SSI reg addr */
120 {0x0040, 0x8800}, /* SSI data to write */
121 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
122 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
123 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
127 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
128 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
129 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
133 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
134 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
135 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
139 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
140 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
141 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
145 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
146 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
147 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
151 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
152 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
153 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
157 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
158 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
159 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
163 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
164 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
165 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
169 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
170 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
171 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
175 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
176 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
177 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
181 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
182 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
183 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
187 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
188 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
189 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
193 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
194 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
195 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
199 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
200 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
201 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
205 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
206 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
207 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
211 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
212 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
213 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
217 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
218 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
219 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
223 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
224 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
225 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
229 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
230 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
231 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
235 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
236 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
237 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
241 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
242 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
243 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
247 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
248 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
249 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
253 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
254 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
255 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
259 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
260 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
261 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
265 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
266 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
267 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
271 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
272 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
273 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
277 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
278 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
279 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
283 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
284 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
285 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
289 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
290 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
291 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
295 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
296 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
297 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
301 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
302 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
303 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
307 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
308 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
309 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
313 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
314 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
315 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
319 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
320 /* --------------------------------------- */
321 {0x0012, 0x8700}, /* Clock speed 48Mhz/(2+2)/2= 6 Mhz */
322 {0x0000, 0x8701}, /* CKx1 clock delay adj */
323 {0x0000, 0x8701}, /* CKx1 clock delay adj */
324 {0x0001, 0x870c}, /* CKOx2 output */
325 /* --------------------------------------- */
326 {0x0080, 0x8600}, /* Line memory read counter (L) */
327 {0x0001, 0x8606}, /* reserved */
328 {0x0064, 0x8607}, /* Line memory read counter (H) 0x6480=25,728 */
329 {0x002a, 0x8601}, /* CDSP sharp interpolation mode,
330 * line sel for color sep, edge enhance enab */
331 {0x0000, 0x8602}, /* optical black level for user settng = 0 */
332 {0x0080, 0x8600}, /* Line memory read counter (L) */
333 {0x000a, 0x8603}, /* optical black level calc mode:
334 * auto; optical black offset = 10 */
335 {0x00df, 0x865b}, /* Horiz offset for valid pixels (L)=0xdf */
336 {0x0012, 0x865c}, /* Vert offset for valid lines (L)=0x12 */
338 /* The following two lines seem to be the "wrong" resolution. */
339 /* But perhaps these indicate the actual size of the sensor */
340 /* rather than the size of the current video mode. */
341 {0x0058, 0x865d}, /* Horiz valid pixels (*4) (L) = 352 */
342 {0x0048, 0x865e}, /* Vert valid lines (*4) (L) = 288 */
344 {0x0015, 0x8608}, /* A11 Coef ... */
353 {0x0001, 0x8611}, /* R offset for white balance ... */
357 {0x005b, 0x8651}, /* R gain for white balance ... */
362 {0x0001, 0x863f}, /* Fixed gamma correction enable, USB control,
363 * lum filter disable, lum noise clip disable */
364 {0x00a1, 0x8656}, /* Window1 size 256x256, Windows2 size 64x64,
365 * gamma look-up disable,
366 * new edge enhancement enable */
367 {0x0018, 0x8657}, /* Edge gain high thresh */
368 {0x0020, 0x8658}, /* Edge gain low thresh */
369 {0x000a, 0x8659}, /* Edge bandwidth high threshold */
370 {0x0005, 0x865a}, /* Edge bandwidth low threshold */
371 /* -------------------------------- */
372 {0x0030, 0x8112}, /* Video drop enable, ISO streaming enable */
373 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
374 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
376 {0x0034, 0x8801}, /* SSI reg addr */
378 /* SSI data to write */
379 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
380 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
381 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
385 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
387 /* ----- Read back coefs we wrote earlier. */
388 /* READ { 0x0000, 0x8608 } -> 0000: 15 */
389 /* READ { 0x0000, 0x8609 } -> 0000: 30 */
390 /* READ { 0x0000, 0x860a } -> 0000: fb */
391 /* READ { 0x0000, 0x860b } -> 0000: 3e */
392 /* READ { 0x0000, 0x860c } -> 0000: ce */
393 /* READ { 0x0000, 0x860d } -> 0000: f4 */
394 /* READ { 0x0000, 0x860e } -> 0000: eb */
395 /* READ { 0x0000, 0x860f } -> 0000: dc */
396 /* READ { 0x0000, 0x8610 } -> 0000: 39 */
397 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
398 /* READ { 0x0001, 0x8802 } -> 0000: 08 */
402 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
405 /* This chunk is seemingly redundant with */
406 /* earlier commands (A11 Coef...), but if I disable it, */
407 /* the image appears too dark. Maybe there was some kind of */
408 /* reset since the earlier commands, so this is necessary again. */
420 {0x0000, 0x8508}, /* Disable compression. */
421 /* Previous line was:
422 {0x0021, 0x8508}, * Enable compression. */
423 {0x0032, 0x850b}, /* compression stuff */
424 {0x0003, 0x8509}, /* compression stuff */
425 {0x0011, 0x850a}, /* compression stuff */
426 {0x0021, 0x850d}, /* compression stuff */
427 {0x0010, 0x850c}, /* compression stuff */
428 {0x0003, 0x8500}, /* *** Video mode: 160x120 */
429 {0x0001, 0x8501}, /* Hardware-dominated snap control */
430 {0x0061, 0x8656}, /* Window1 size 128x128, Windows2 size 128x128,
431 * gamma look-up disable,
432 * new edge enhancement enable */
433 {0x0018, 0x8617}, /* Window1 start X (*2) */
434 {0x0008, 0x8618}, /* Window1 start Y (*2) */
435 {0x0061, 0x8656}, /* Window1 size 128x128, Windows2 size 128x128,
436 * gamma look-up disable,
437 * new edge enhancement enable */
438 {0x0058, 0x8619}, /* Window2 start X (*2) */
439 {0x0008, 0x861a}, /* Window2 start Y (*2) */
440 {0x00ff, 0x8615}, /* High lum thresh for white balance */
441 {0x0000, 0x8616}, /* Low lum thresh for white balance */
442 {0x0012, 0x8700}, /* Clock speed 48Mhz/(2+2)/2= 6 Mhz */
443 {0x0012, 0x8700}, /* Clock speed 48Mhz/(2+2)/2= 6 Mhz */
444 /* READ { 0x0000, 0x8656 } -> 0000: 61 */
445 {0x0028, 0x8802}, /* 375 Khz SSI clock, SSI r/w sync with VSYNC */
446 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
447 /* READ { 0x0001, 0x8802 } -> 0000: 28 */
448 {0x1f28, 0x8802}, /* 375 Khz SSI clock, SSI r/w sync with VSYNC */
449 {0x0010, 0x8801}, /* SSI reg addr */
450 {0x003e, 0x8800}, /* SSI data to write */
451 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
453 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
454 /* READ { 0x0001, 0x8802 } -> 0000: 28 */
458 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
459 {0x0001, 0x8602}, /* optical black level for user settning = 1 */
462 {0x0023, 0x8700}, /* Clock speed 48Mhz/(3+2)/4= 2.4 Mhz */
463 {0x000f, 0x8602}, /* optical black level for user settning = 15 */
466 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
467 /* READ { 0x0001, 0x8802 } -> 0000: 28 */
471 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
472 {0x002f, 0x8651}, /* R gain for white balance ... */
474 /* READ { 0x0000, 0x8655 } -> 0000: 00 */
477 {0x0030, 0x8112}, /* Video drop enable, ISO streaming enable */
478 {0x0020, 0x8112}, /* Video drop enable, ISO streaming disable */
479 /* UNKNOWN DIRECTION (URB_FUNCTION_SELECT_INTERFACE: (ALT=0) ) */
484 * Initialization data for Intel EasyPC Camera CS110
486 static const u16 spca508cs110_init_data
[][2] = {
487 {0x0000, 0x870b}, /* Reset CTL3 */
488 {0x0003, 0x8111}, /* Soft Reset compression, memory, TG & CDSP */
489 {0x0000, 0x8111}, /* Normal operation on reset */
491 /* External Clock 2x & Synchronous Serial Interface Output */
492 {0x0020, 0x8112}, /* Video Drop packet enable */
493 {0x0000, 0x8114}, /* Software GPIO output data */
499 /* Initial sequence Synchronous Serial Interface */
500 {0x000f, 0x8402}, /* Memory bank Address */
501 {0x0000, 0x8403}, /* Memory bank Address */
502 {0x00ba, 0x8804}, /* SSI Slave address */
503 {0x0010, 0x8802}, /* 93.75kHz SSI Clock Two DataByte */
504 {0x0010, 0x8802}, /* 93.75kHz SSI Clock two DataByte */
507 {0x000a, 0x8805}, /* a - NWG: Dunno what this is about */
541 {0x0002, 0x8704}, /* External input CKIx1 */
542 {0x0001, 0x8606}, /* 1 Line memory Read Counter (H) Result: (d)410 */
543 {0x009a, 0x8600}, /* Line memory Read Counter (L) */
544 {0x0001, 0x865b}, /* 1 Horizontal Offset for Valid Pixel(L) */
545 {0x0003, 0x865c}, /* 3 Vertical Offset for Valid Lines(L) */
546 {0x0058, 0x865d}, /* 58 Horizontal Valid Pixel Window(L) */
548 {0x0006, 0x8660}, /* Nibble data + input order */
550 {0x000a, 0x8602}, /* Optical black level set to 0x0a */
551 {0x0000, 0x8603}, /* Optical black level Offset */
553 /* {0x0000, 0x8611}, * 0 R Offset for white Balance */
554 /* {0x0000, 0x8612}, * 1 Gr Offset for white Balance */
555 /* {0x0000, 0x8613}, * 1f B Offset for white Balance */
556 /* {0x0000, 0x8614}, * f0 Gb Offset for white Balance */
558 {0x0040, 0x8651}, /* 2b BLUE gain for white balance good at all 60 */
559 {0x0030, 0x8652}, /* 41 Gr Gain for white Balance (L) */
560 {0x0035, 0x8653}, /* 26 RED gain for white balance */
561 {0x0035, 0x8654}, /* 40Gb Gain for white Balance (L) */
563 /* Fixed Gamma correction enabled (makes colours look better) */
566 /* High bits for white balance*****brightness control*** */
570 static const u16 spca508_sightcam_init_data
[][2] = {
571 /* This line seems to setup the frame/canvas */
574 /* These 6 lines are needed to startup the webcam */
582 /* This part seems to make the pictures darker? (autobrightness?) */
597 /* This section is just needed, it probably
598 * does something like the previous section,
599 * but the cam won't start if it's not included.
612 /* Makes the picture darker - and the
613 * cam won't start if not included
622 /* seems to place the colors ontop of each other #1 */
628 /* if not included the pictures becomes _very_ dark */
633 /* seems to place the colors ontop of each other #2 */
639 /* webcam won't start if not included */
645 /* adjusts the colors */
653 static const u16 spca508_sightcam2_init_data
[][2] = {
990 /* This line starts it all, it is not needed here */
991 /* since it has been build into the driver */
992 /* jfm: don't start now */
993 /* {0x0030, 0x8112}, */
998 * Initialization data for Creative Webcam Vista
1000 static const u16 spca508_vista_init_data
[][2] = {
1001 {0x0008, 0x8200}, /* Clear register */
1002 {0x0000, 0x870b}, /* Reset CTL3 */
1003 {0x0020, 0x8112}, /* Video Drop packet enable */
1004 {0x0003, 0x8111}, /* Soft Reset compression, memory, TG & CDSP */
1005 {0x0000, 0x8110}, /* Disable everything */
1006 {0x0000, 0x8114}, /* Software GPIO output data */
1011 {0x0090, 0x8110}, /* Enable: SSI output, External 2X clock output */
1019 {0x000f, 0x8402}, /* Memory bank Address */
1020 {0x0000, 0x8403}, /* Memory bank Address */
1021 {0x00ba, 0x8804}, /* SSI Slave address */
1022 {0x0010, 0x8802}, /* 93.75kHz SSI Clock Two DataByte */
1024 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1025 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1026 {0x0010, 0x8802}, /* Will write 2 bytes (DATA1+DATA2) */
1027 {0x0020, 0x8801}, /* Register address for SSI read/write */
1028 {0x0044, 0x8805}, /* DATA2 */
1029 {0x0004, 0x8800}, /* DATA1 -> write triggered */
1030 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1032 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1033 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1038 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1040 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1041 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1046 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1048 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1049 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1054 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1056 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1057 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1062 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1064 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1065 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1070 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1072 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1073 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1078 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1080 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1081 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1086 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1088 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1089 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1094 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1096 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1097 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1102 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1104 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1105 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1110 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1112 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1113 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1118 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1120 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1121 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1126 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1128 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1129 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1134 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1136 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1137 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1142 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1144 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1145 /* READ { 0x0001, 0x8802 } -> 0000: 10 */
1150 /* READ { 0x0001, 0x8803 } -> 0000: 00 */
1153 {0x0002, 0x8704}, /* External input CKIx1 */
1154 {0x0001, 0x870c}, /* Select CKOx2 output */
1155 {0x009a, 0x8600}, /* Line memory Read Counter (L) */
1156 {0x0001, 0x8606}, /* 1 Line memory Read Counter (H) Result: (d)410 */
1161 {0x0001, 0x865b}, /* 1 Horizontal Offset for Valid Pixel(L) */
1162 {0x0003, 0x865c}, /* Vertical offset for valid lines (L) */
1163 {0x0058, 0x865d}, /* Horizontal valid pixels window (L) */
1164 {0x0048, 0x865e}, /* Vertical valid lines window (L) */
1168 /* Enable nibble data input, select nibble input order */
1170 {0x0013, 0x8608}, /* A11 Coeficients for color correction */
1172 /* Note: these values are confirmed at the end of array */
1173 {0x0005, 0x860a}, /* ... */
1179 {0x0025, 0x8610}, /* A33 Coef. */
1180 {0x00fc, 0x8611}, /* White balance offset: R */
1181 {0x0001, 0x8612}, /* White balance offset: Gr */
1182 {0x00fe, 0x8613}, /* White balance offset: B */
1183 {0x0000, 0x8614}, /* White balance offset: Gb */
1185 {0x0064, 0x8651}, /* R gain for white balance (L) */
1186 {0x0040, 0x8652}, /* Gr gain for white balance (L) */
1187 {0x0066, 0x8653}, /* B gain for white balance (L) */
1188 {0x0040, 0x8654}, /* Gb gain for white balance (L) */
1189 {0x0001, 0x863f}, /* Enable fixed gamma correction */
1191 {0x00a1, 0x8656}, /* Size - Window1: 256x256, Window2: 128x128,
1192 * UV division: UV no change,
1193 * Enable New edge enhancement */
1194 {0x0018, 0x8657}, /* Edge gain high threshold */
1195 {0x0020, 0x8658}, /* Edge gain low threshold */
1196 {0x000a, 0x8659}, /* Edge bandwidth high threshold */
1197 {0x0005, 0x865a}, /* Edge bandwidth low threshold */
1198 {0x0064, 0x8607}, /* UV filter enable */
1201 {0x0000, 0x86b0}, /* Bad pixels compensation address */
1202 {0x00dc, 0x86b1}, /* X coord for bad pixels compensation (L) */
1204 {0x0009, 0x86b3}, /* Y coord for bad pixels compensation (L) */
1232 /* READ { 0x0000, 0x8608 } -> 0000: 13 */
1233 /* READ { 0x0000, 0x8609 } -> 0000: 28 */
1234 /* READ { 0x0000, 0x8610 } -> 0000: 05 */
1235 /* READ { 0x0000, 0x8611 } -> 0000: 25 */
1236 /* READ { 0x0000, 0x8612 } -> 0000: e1 */
1237 /* READ { 0x0000, 0x8613 } -> 0000: fa */
1238 /* READ { 0x0000, 0x8614 } -> 0000: f4 */
1239 /* READ { 0x0000, 0x8615 } -> 0000: e8 */
1240 /* READ { 0x0000, 0x8616 } -> 0000: 25 */
1244 static int reg_write(struct gspca_dev
*gspca_dev
, u16 index
, u16 value
)
1247 struct usb_device
*dev
= gspca_dev
->dev
;
1249 ret
= usb_control_msg(dev
,
1250 usb_sndctrlpipe(dev
, 0),
1252 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
1253 value
, index
, NULL
, 0, 500);
1254 PDEBUG(D_USBO
, "reg write i:0x%04x = 0x%02x",
1257 pr_err("reg write: error %d\n", ret
);
1262 /* returns: negative is error, pos or zero is data */
1263 static int reg_read(struct gspca_dev
*gspca_dev
,
1264 u16 index
) /* wIndex */
1268 ret
= usb_control_msg(gspca_dev
->dev
,
1269 usb_rcvctrlpipe(gspca_dev
->dev
, 0),
1271 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
1274 gspca_dev
->usb_buf
, 1,
1276 PDEBUG(D_USBI
, "reg read i:%04x --> %02x",
1277 index
, gspca_dev
->usb_buf
[0]);
1279 pr_err("reg_read err %d\n", ret
);
1282 return gspca_dev
->usb_buf
[0];
1285 /* send 1 or 2 bytes to the sensor via the Synchronous Serial Interface */
1286 static int ssi_w(struct gspca_dev
*gspca_dev
,
1291 ret
= reg_write(gspca_dev
, 0x8802, reg
>> 8);
1294 ret
= reg_write(gspca_dev
, 0x8801, reg
& 0x00ff);
1297 if ((reg
& 0xff00) == 0x1000) { /* if 2 bytes */
1298 ret
= reg_write(gspca_dev
, 0x8805, val
& 0x00ff);
1303 ret
= reg_write(gspca_dev
, 0x8800, val
);
1307 /* poll until not busy */
1310 ret
= reg_read(gspca_dev
, 0x8803);
1313 if (gspca_dev
->usb_buf
[0] == 0)
1316 PERR("ssi_w busy %02x", gspca_dev
->usb_buf
[0]);
1327 static int write_vector(struct gspca_dev
*gspca_dev
,
1328 const u16 (*data
)[2])
1332 while ((*data
)[1] != 0) {
1333 if ((*data
)[1] & 0x8000) {
1334 if ((*data
)[1] == 0xdd00) /* delay */
1337 ret
= reg_write(gspca_dev
, (*data
)[1],
1340 ret
= ssi_w(gspca_dev
, (*data
)[1], (*data
)[0]);
1349 /* this function is called at probe time */
1350 static int sd_config(struct gspca_dev
*gspca_dev
,
1351 const struct usb_device_id
*id
)
1353 struct sd
*sd
= (struct sd
*) gspca_dev
;
1355 const u16 (*init_data
)[2];
1356 static const u16 (*(init_data_tb
[]))[2] = {
1357 spca508_vista_init_data
, /* CreativeVista 0 */
1358 spca508_sightcam_init_data
, /* HamaUSBSightcam 1 */
1359 spca508_sightcam2_init_data
, /* HamaUSBSightcam2 2 */
1360 spca508cs110_init_data
, /* IntelEasyPCCamera 3 */
1361 spca508cs110_init_data
, /* MicroInnovationIC200 4 */
1362 spca508_init_data
, /* ViewQuestVQ110 5 */
1366 /* Read from global register the USB product and vendor IDs, just to
1367 * prove that we can communicate with the device. This works, which
1368 * confirms at we are communicating properly and that the device
1370 data1
= reg_read(gspca_dev
, 0x8104);
1371 data2
= reg_read(gspca_dev
, 0x8105);
1372 PDEBUG(D_PROBE
, "Webcam Vendor ID: 0x%02x%02x", data2
, data1
);
1374 data1
= reg_read(gspca_dev
, 0x8106);
1375 data2
= reg_read(gspca_dev
, 0x8107);
1376 PDEBUG(D_PROBE
, "Webcam Product ID: 0x%02x%02x", data2
, data1
);
1378 data1
= reg_read(gspca_dev
, 0x8621);
1379 PDEBUG(D_PROBE
, "Window 1 average luminance: %d", data1
);
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
);