2 * Sunplus spca561 subdriver
4 * Copyright (C) 2004 Michel Xhaard mxhaard@magic.fr
6 * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #define MODULE_NAME "spca561"
27 #define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
28 static const char version
[] = "2.1.7";
30 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
31 MODULE_DESCRIPTION("GSPCA/SPCA561 USB Camera Driver");
32 MODULE_LICENSE("GPL");
34 /* specific webcam descriptor */
36 struct gspca_dev gspca_dev
; /* !! must be the first item */
38 unsigned short contrast
;
44 #define AG_CNT_START 13
47 /* V4L2 controls supported by the driver */
48 static int sd_setbrightness(struct gspca_dev
*gspca_dev
, __s32 val
);
49 static int sd_getbrightness(struct gspca_dev
*gspca_dev
, __s32
*val
);
50 static int sd_setcontrast(struct gspca_dev
*gspca_dev
, __s32 val
);
51 static int sd_getcontrast(struct gspca_dev
*gspca_dev
, __s32
*val
);
52 static int sd_setautogain(struct gspca_dev
*gspca_dev
, __s32 val
);
53 static int sd_getautogain(struct gspca_dev
*gspca_dev
, __s32
*val
);
55 static struct ctrl sd_ctrls
[] = {
56 #define SD_BRIGHTNESS 0
59 .id
= V4L2_CID_BRIGHTNESS
,
60 .type
= V4L2_CTRL_TYPE_INTEGER
,
67 .set
= sd_setbrightness
,
68 .get
= sd_getbrightness
,
73 .id
= V4L2_CID_CONTRAST
,
74 .type
= V4L2_CTRL_TYPE_INTEGER
,
79 .default_value
= 0x2000,
81 .set
= sd_setcontrast
,
82 .get
= sd_getcontrast
,
87 .id
= V4L2_CID_AUTOGAIN
,
88 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
95 .set
= sd_setautogain
,
96 .get
= sd_getautogain
,
100 static struct v4l2_pix_format sif_mode
[] = {
101 {160, 120, V4L2_PIX_FMT_SGBRG8
, V4L2_FIELD_NONE
,
103 .sizeimage
= 160 * 120,
104 .colorspace
= V4L2_COLORSPACE_SRGB
,
106 {176, 144, V4L2_PIX_FMT_SGBRG8
, V4L2_FIELD_NONE
,
108 .sizeimage
= 176 * 144,
109 .colorspace
= V4L2_COLORSPACE_SRGB
,
111 {320, 240, V4L2_PIX_FMT_SPCA561
, V4L2_FIELD_NONE
,
113 .sizeimage
= 320 * 240 * 4 / 8,
114 .colorspace
= V4L2_COLORSPACE_SRGB
,
116 {352, 288, V4L2_PIX_FMT_SPCA561
, V4L2_FIELD_NONE
,
118 .sizeimage
= 352 * 288 * 4 / 8,
119 .colorspace
= V4L2_COLORSPACE_SRGB
,
124 * Initialization data
125 * I'm not very sure how to split initialization from open data
126 * chunks. For now, we'll consider everything as initialization
128 /* Frame packet header offsets for the spca561 */
129 #define SPCA561_OFFSET_SNAP 1
130 #define SPCA561_OFFSET_TYPE 2
131 #define SPCA561_OFFSET_COMPRESS 3
132 #define SPCA561_OFFSET_FRAMSEQ 4
133 #define SPCA561_OFFSET_GPIO 5
134 #define SPCA561_OFFSET_USBBUFF 6
135 #define SPCA561_OFFSET_WIN2GRAVE 7
136 #define SPCA561_OFFSET_WIN2RAVE 8
137 #define SPCA561_OFFSET_WIN2BAVE 9
138 #define SPCA561_OFFSET_WIN2GBAVE 10
139 #define SPCA561_OFFSET_WIN1GRAVE 11
140 #define SPCA561_OFFSET_WIN1RAVE 12
141 #define SPCA561_OFFSET_WIN1BAVE 13
142 #define SPCA561_OFFSET_WIN1GBAVE 14
143 #define SPCA561_OFFSET_FREQ 15
144 #define SPCA561_OFFSET_VSYNC 16
145 #define SPCA561_OFFSET_DATA 1
146 #define SPCA561_INDEX_I2C_BASE 0x8800
147 #define SPCA561_SNAPBIT 0x20
148 #define SPCA561_SNAPCTRL 0x40
154 static void reg_w_val(struct usb_device
*dev
, __u16 index
, __u16 value
)
158 ret
= usb_control_msg(dev
, usb_sndctrlpipe(dev
, 0),
160 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
161 value
, index
, NULL
, 0, 500);
162 PDEBUG(D_USBO
, "reg write: 0x%02x:0x%02x", index
, value
);
164 PDEBUG(D_ERR
, "reg write: error %d", ret
);
167 static void write_vector(struct gspca_dev
*gspca_dev
,
168 const __u16 data
[][2])
170 struct usb_device
*dev
= gspca_dev
->dev
;
174 while (data
[i
][1] != 0) {
175 reg_w_val(dev
, data
[i
][1], data
[i
][0]);
180 /* read 'len' bytes to gspca_dev->usb_buf */
181 static void reg_r(struct gspca_dev
*gspca_dev
,
182 __u16 index
, __u16 length
)
184 usb_control_msg(gspca_dev
->dev
,
185 usb_rcvctrlpipe(gspca_dev
->dev
, 0),
187 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
189 index
, gspca_dev
->usb_buf
, length
, 500);
192 static void reg_w_buf(struct gspca_dev
*gspca_dev
,
193 __u16 index
, const __u8
*buffer
, __u16 len
)
195 memcpy(gspca_dev
->usb_buf
, buffer
, len
);
196 usb_control_msg(gspca_dev
->dev
,
197 usb_sndctrlpipe(gspca_dev
->dev
, 0),
199 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
201 index
, gspca_dev
->usb_buf
, len
, 500);
204 static void i2c_init(struct gspca_dev
*gspca_dev
, __u8 mode
)
206 reg_w_val(gspca_dev
->dev
, 0x92, 0x8804);
207 reg_w_val(gspca_dev
->dev
, mode
, 0x8802);
210 static void i2c_write(struct gspca_dev
*gspca_dev
, __u16 valeur
, __u16 reg
)
217 DataHight
= valeur
>> 8;
218 reg_w_val(gspca_dev
->dev
, reg
, 0x8801);
219 reg_w_val(gspca_dev
->dev
, DataLow
, 0x8805);
220 reg_w_val(gspca_dev
->dev
, DataHight
, 0x8800);
222 reg_r(gspca_dev
, 0x8803, 1);
223 if (!gspca_dev
->usb_buf
[0])
228 static int i2c_read(struct gspca_dev
*gspca_dev
, __u16 reg
, __u8 mode
)
234 reg_w_val(gspca_dev
->dev
, 0x92, 0x8804);
235 reg_w_val(gspca_dev
->dev
, reg
, 0x8801);
236 reg_w_val(gspca_dev
->dev
, (mode
| 0x01), 0x8802);
238 reg_r(gspca_dev
, 0x8803, 1);
239 if (!gspca_dev
->usb_buf
)
244 reg_r(gspca_dev
, 0x8800, 1);
245 value
= gspca_dev
->usb_buf
[0];
246 reg_r(gspca_dev
, 0x8805, 1);
247 vallsb
= gspca_dev
->usb_buf
[0];
248 return ((int) value
<< 8) | vallsb
;
251 static const __u16 spca561_init_data
[][2] = {
252 {0x0000, 0x8114}, /* Software GPIO output data */
253 {0x0001, 0x8114}, /* Software GPIO output data */
254 {0x0000, 0x8112}, /* Some kind of reset */
255 {0x0003, 0x8701}, /* PCLK clock delay adjustment */
256 {0x0001, 0x8703}, /* HSYNC from cmos inverted */
257 {0x0011, 0x8118}, /* Enable and conf sensor */
258 {0x0001, 0x8118}, /* Conf sensor */
259 {0x0092, 0x8804}, /* I know nothing about these */
260 {0x0010, 0x8802}, /* 0x88xx registers, so I won't */
262 {0x000d, 0x8805}, /* sensor default setting */
263 {0x0001, 0x8801}, /* 1 <- 0x0d */
266 {0x0002, 0x8801}, /* 2 <- 0x18 */
269 {0x0004, 0x8801}, /* 4 <- 0x01 0x65 */
272 {0x0005, 0x8801}, /* 5 <- 0x21 */
275 {0x0007, 0x8801}, /* 7 <- 0xaa */
278 {0x0020, 0x8801}, /* 0x20 <- 0x15 0x04 */
281 {0x0039, 0x8801}, /* 0x39 <- 0x02 */
284 {0x0035, 0x8801}, /* 0x35 <- 0x10 */
287 {0x0009, 0x8801}, /* 0x09 <- 0x10 0x49 */
290 {0x0028, 0x8801}, /* 0x28 <- 0x0b */
293 {0x003b, 0x8801}, /* 0x3b <- 0x0f */
296 {0x003c, 0x8801}, /* 0x3c <- 0x00 */
299 {0x0018, 0x8601}, /* Pixel/line selection for color separation */
300 {0x0000, 0x8602}, /* Optical black level for user setting */
301 {0x0060, 0x8604}, /* Optical black horizontal offset */
302 {0x0002, 0x8605}, /* Optical black vertical offset */
303 {0x0000, 0x8603}, /* Non-automatic optical black level */
304 {0x0002, 0x865b}, /* Horizontal offset for valid pixels */
305 {0x0000, 0x865f}, /* Vertical valid pixels window (x2) */
306 {0x00b0, 0x865d}, /* Horizontal valid pixels window (x2) */
307 {0x0090, 0x865e}, /* Vertical valid lines window (x2) */
308 {0x00e0, 0x8406}, /* Memory buffer threshold */
309 {0x0000, 0x8660}, /* Compensation memory stuff */
310 {0x0002, 0x8201}, /* Output address for r/w serial EEPROM */
311 {0x0008, 0x8200}, /* Clear valid bit for serial EEPROM */
312 {0x0001, 0x8200}, /* OprMode to be executed by hardware */
313 {0x0007, 0x8201}, /* Output address for r/w serial EEPROM */
314 {0x0008, 0x8200}, /* Clear valid bit for serial EEPROM */
315 {0x0001, 0x8200}, /* OprMode to be executed by hardware */
316 {0x0010, 0x8660}, /* Compensation memory stuff */
317 {0x0018, 0x8660}, /* Compensation memory stuff */
319 {0x0004, 0x8611}, /* R offset for white balance */
320 {0x0004, 0x8612}, /* Gr offset for white balance */
321 {0x0007, 0x8613}, /* B offset for white balance */
322 {0x0000, 0x8614}, /* Gb offset for white balance */
323 {0x008c, 0x8651}, /* R gain for white balance */
324 {0x008c, 0x8652}, /* Gr gain for white balance */
325 {0x00b5, 0x8653}, /* B gain for white balance */
326 {0x008c, 0x8654}, /* Gb gain for white balance */
327 {0x0002, 0x8502}, /* Maximum average bit rate stuff */
330 {0x0087, 0x8700}, /* Set master clock (96Mhz????) */
331 {0x0081, 0x8702}, /* Master clock output enable */
333 {0x0000, 0x8500}, /* Set image type (352x288 no compression) */
334 /* Originally was 0x0010 (352x288 compression) */
336 {0x0002, 0x865b}, /* Horizontal offset for valid pixels */
337 {0x0003, 0x865c}, /* Vertical offset for valid lines */
338 /***************//* sensor active */
339 {0x0003, 0x8801}, /* 0x03 <- 0x01 0x21 //289 */
342 {0x0004, 0x8801}, /* 0x04 <- 0x01 0x65 //357 */
345 {0x0005, 0x8801}, /* 0x05 <- 0x2f */
348 {0x0006, 0x8801}, /* 0x06 <- 0 */
351 {0x000a, 0x8801}, /* 0x0a <- 2 */
354 {0x0009, 0x8801}, /* 0x09 <- 0x1061 */
357 {0x0035, 0x8801}, /* 0x35 <-0x14 */
360 {0x0030, 0x8112}, /* ISO and drop packet enable */
361 {0x0000, 0x8112}, /* Some kind of reset ???? */
362 {0x0009, 0x8118}, /* Enable sensor and set standby */
363 {0x0000, 0x8114}, /* Software GPIO output data */
364 {0x0000, 0x8114}, /* Software GPIO output data */
365 {0x0001, 0x8114}, /* Software GPIO output data */
366 {0x0000, 0x8112}, /* Some kind of reset ??? */
387 {0x0007, 0x8801}, /* mode 0xaa */
391 {0x0015, 0x8800}, /* mode 0x0415 */
415 {0x0087, 0x8700}, /* overwrite by start */
418 /* {0x0010, 0x8500}, -- Previous line was this */
422 {0x0003, 0x8801}, /* 0x121-> 289 */
425 {0x0004, 0x8801}, /* 0x165 -> 357 */
428 {0x0005, 0x8801}, /* 0x2f //blanking control colonne */
431 {0x0006, 0x8801}, /* 0x00 //blanking mode row */
434 {0x000a, 0x8801}, /* 0x01 //0x02 */
437 {0x0009, 0x8801}, /* 0x1061 - setexposure times && pixel clock
438 * 0001 0 | 000 0110 0001 */
439 {0x0061, 0x8805}, /* 61 31 */
440 {0x0008, 0x8800}, /* 08 */
441 {0x0035, 0x8801}, /* 0x14 - set gain general */
442 {0x001f, 0x8805}, /* 0x14 */
448 static void sensor_reset(struct gspca_dev
*gspca_dev
)
450 reg_w_val(gspca_dev
->dev
, 0x8631, 0xc8);
451 reg_w_val(gspca_dev
->dev
, 0x8634, 0xc8);
452 reg_w_val(gspca_dev
->dev
, 0x8112, 0x00);
453 reg_w_val(gspca_dev
->dev
, 0x8114, 0x00);
454 reg_w_val(gspca_dev
->dev
, 0x8118, 0x21);
455 i2c_init(gspca_dev
, 0x14);
456 i2c_write(gspca_dev
, 1, 0x0d);
457 i2c_write(gspca_dev
, 0, 0x0d);
460 /******************** QC Express etch2 stuff ********************/
461 static const __u16 Pb100_1map8300
[][2] = {
465 {0x8303, 0x0125}, /* image area */
476 static const __u16 Pb100_2map8300
[][2] = {
483 static const __u16 spca561_161rev12A_data1
[][2] = {
488 {0x04, 0x8802}, /* windows uses 08 */
491 static const __u16 spca561_161rev12A_data2
[][2] = {
499 {0x07, 0x8201}, /* windows uses 02 */
504 {0x01, 0x8114}, /* windows uses 00 */
511 {0x00, 0x8610}, /* *red */
512 {0x00, 0x8611}, /* 3f *green */
513 {0x00, 0x8612}, /* green *blue */
514 {0x00, 0x8613}, /* blue *green */
515 {0x35, 0x8614}, /* green *red */
516 {0x35, 0x8615}, /* 40 *green */
517 {0x35, 0x8616}, /* 7a *blue */
518 {0x35, 0x8617}, /* 40 *green */
520 {0x0c, 0x8620}, /* 0c */
521 {0xc8, 0x8631}, /* c8 */
522 {0xc8, 0x8634}, /* c8 */
523 {0x23, 0x8635}, /* 23 */
524 {0x1f, 0x8636}, /* 1f */
525 {0xdd, 0x8637}, /* dd */
526 {0xe1, 0x8638}, /* e1 */
527 {0x1d, 0x8639}, /* 1d */
528 {0x21, 0x863a}, /* 21 */
529 {0xe3, 0x863b}, /* e3 */
530 {0xdf, 0x863c}, /* df */
536 static void sensor_mapwrite(struct gspca_dev
*gspca_dev
,
537 const __u16 sensormap
[][2])
542 while (sensormap
[i
][0]) {
543 usbval
[0] = sensormap
[i
][1];
544 usbval
[1] = sensormap
[i
][1] >> 8;
545 reg_w_buf(gspca_dev
, sensormap
[i
][0], usbval
, 2);
549 static void init_161rev12A(struct gspca_dev
*gspca_dev
)
551 sensor_reset(gspca_dev
);
552 write_vector(gspca_dev
, spca561_161rev12A_data1
);
553 sensor_mapwrite(gspca_dev
, Pb100_1map8300
);
554 write_vector(gspca_dev
, spca561_161rev12A_data2
);
555 sensor_mapwrite(gspca_dev
, Pb100_2map8300
);
558 /* this function is called at probe time */
559 static int sd_config(struct gspca_dev
*gspca_dev
,
560 const struct usb_device_id
*id
)
562 struct sd
*sd
= (struct sd
*) gspca_dev
;
564 __u16 vendor
, product
;
567 /* Read frm global register the USB product and vendor IDs, just to
568 * prove that we can communicate with the device. This works, which
569 * confirms at we are communicating properly and that the device
571 reg_r(gspca_dev
, 0x8104, 1);
572 data1
= gspca_dev
->usb_buf
[0];
573 reg_r(gspca_dev
, 0x8105, 1);
574 data2
= gspca_dev
->usb_buf
[0];
575 vendor
= (data2
<< 8) | data1
;
576 reg_r(gspca_dev
, 0x8106, 1);
577 data1
= gspca_dev
->usb_buf
[0];
578 reg_r(gspca_dev
, 0x8107, 1);
579 data2
= gspca_dev
->usb_buf
[0];
580 product
= (data2
<< 8) | data1
;
581 if (vendor
!= id
->idVendor
|| product
!= id
->idProduct
) {
582 PDEBUG(D_PROBE
, "Bad vendor / product from device");
595 sd
->chip_revision
= Rev012A
;
599 case 0x0815: * ?? in spca508.c
605 sd
->chip_revision
= Rev072A
;
608 cam
= &gspca_dev
->cam
;
609 cam
->dev_name
= (char *) id
->driver_info
;
611 gspca_dev
->nbalt
= 7 + 1; /* choose alternate 7 first */
612 cam
->cam_mode
= sif_mode
;
613 cam
->nmodes
= sizeof sif_mode
/ sizeof sif_mode
[0];
614 sd
->brightness
= sd_ctrls
[SD_BRIGHTNESS
].qctrl
.default_value
;
615 sd
->contrast
= sd_ctrls
[SD_CONTRAST
].qctrl
.default_value
;
616 sd
->autogain
= sd_ctrls
[SD_AUTOGAIN
].qctrl
.default_value
;
620 /* this function is called at open time */
621 static int sd_open(struct gspca_dev
*gspca_dev
)
623 struct sd
*sd
= (struct sd
*) gspca_dev
;
625 switch (sd
->chip_revision
) {
627 PDEBUG(D_STREAM
, "Chip revision id: 072a");
628 write_vector(gspca_dev
, spca561_init_data
);
632 PDEBUG(D_STREAM
, "Chip revision id: 012a");
633 init_161rev12A(gspca_dev
);
639 static void setcontrast(struct gspca_dev
*gspca_dev
)
641 struct sd
*sd
= (struct sd
*) gspca_dev
;
642 struct usb_device
*dev
= gspca_dev
->dev
;
646 switch (sd
->chip_revision
) {
648 lowb
= sd
->contrast
>> 8;
649 reg_w_val(dev
, lowb
, 0x8651);
650 reg_w_val(dev
, lowb
, 0x8652);
651 reg_w_val(dev
, lowb
, 0x8653);
652 reg_w_val(dev
, lowb
, 0x8654);
656 { 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00 };
658 /* Write camera sensor settings */
659 expotimes
= (sd
->contrast
>> 5) & 0x07ff;
660 Reg8391
[0] = expotimes
& 0xff; /* exposure */
661 Reg8391
[1] = 0x18 | (expotimes
>> 8);
662 Reg8391
[2] = sd
->brightness
; /* gain */
663 reg_w_buf(gspca_dev
, 0x8391, Reg8391
, 8);
664 reg_w_buf(gspca_dev
, 0x8390, Reg8391
, 8);
670 static void sd_start(struct gspca_dev
*gspca_dev
)
672 struct sd
*sd
= (struct sd
*) gspca_dev
;
673 struct usb_device
*dev
= gspca_dev
->dev
;
675 __u8 Reg8307
[] = { 0xaa, 0x00 };
678 mode
= gspca_dev
->cam
.cam_mode
[(int) gspca_dev
->curr_mode
].priv
;
679 switch (sd
->chip_revision
) {
694 reg_w_val(dev
, 0x8500, mode
); /* mode */
695 reg_w_val(dev
, 0x8700, Clck
); /* 0x27 clock */
696 reg_w_val(dev
, 0x8112, 0x10 | 0x20);
713 /* Use compression on 320x240 and above */
714 reg_w_val(dev
, 0x8500, 0x10 | mode
);
716 /* I couldn't get the compression to work below 320x240
717 * Fortunately at these resolutions the bandwidth
718 * is sufficient to push raw frames at ~20fps */
719 reg_w_val(dev
, 0x8500, mode
);
720 } /* -- qq@kuku.eu.org */
721 reg_w_buf(gspca_dev
, 0x8307, Reg8307
, 2);
722 reg_w_val(gspca_dev
->dev
, 0x8700, Clck
);
723 /* 0x8f 0x85 0x27 clock */
724 reg_w_val(gspca_dev
->dev
, 0x8112, 0x1e | 0x20);
725 reg_w_val(gspca_dev
->dev
, 0x850b, 0x03);
726 setcontrast(gspca_dev
);
731 static void sd_stopN(struct gspca_dev
*gspca_dev
)
733 reg_w_val(gspca_dev
->dev
, 0x8112, 0x20);
736 static void sd_stop0(struct gspca_dev
*gspca_dev
)
740 /* this function is called at close time */
741 static void sd_close(struct gspca_dev
*gspca_dev
)
743 reg_w_val(gspca_dev
->dev
, 0x8114, 0);
746 static void setautogain(struct gspca_dev
*gspca_dev
)
748 struct sd
*sd
= (struct sd
*) gspca_dev
;
754 __u8 luma_mean
= 110;
755 __u8 luma_delta
= 20;
758 switch (sd
->chip_revision
) {
760 reg_r(gspca_dev
, 0x8621, 1);
761 Gr
= gspca_dev
->usb_buf
[0];
762 reg_r(gspca_dev
, 0x8622, 1);
763 R
= gspca_dev
->usb_buf
[0];
764 reg_r(gspca_dev
, 0x8623, 1);
765 B
= gspca_dev
->usb_buf
[0];
766 reg_r(gspca_dev
, 0x8624, 1);
767 Gb
= gspca_dev
->usb_buf
[0];
768 y
= (77 * R
+ 75 * (Gr
+ Gb
) + 29 * B
) >> 8;
769 /* u= (128*B-(43*(Gr+Gb+R))) >> 8; */
770 /* v= (128*R-(53*(Gr+Gb))-21*B) >> 8; */
771 /* PDEBUG(D_CONF,"reading Y %d U %d V %d ",y,u,v); */
773 if (y
< luma_mean
- luma_delta
||
774 y
> luma_mean
+ luma_delta
) {
775 expotimes
= i2c_read(gspca_dev
, 0x09, 0x10);
777 expotimes
= expotimes
& 0x07ff;
779 "Exposition Times 0x%03X Clock 0x%04X ",
780 expotimes,pixelclk); */
781 gainG
= i2c_read(gspca_dev
, 0x35, 0x10);
783 "reading Gain register %d", gainG); */
785 expotimes
+= (luma_mean
- y
) >> spring
;
786 gainG
+= (luma_mean
- y
) / 50;
788 "compute expotimes %d gain %d",
795 i2c_write(gspca_dev
, gainG
, 0x35);
797 if (expotimes
>= 0x0256)
799 else if (expotimes
< 4)
801 i2c_write(gspca_dev
, expotimes
| pixelclk
, 0x09);
805 /* sensor registers is access and memory mapped to 0x8300 */
806 /* readind all 0x83xx block the sensor */
808 * The data from the header seem wrong where is the luma
809 * and chroma mean value
810 * at the moment set exposure in contrast set
816 static void sd_pkt_scan(struct gspca_dev
*gspca_dev
,
817 struct gspca_frame
*frame
, /* target */
818 __u8
*data
, /* isoc packet */
819 int len
) /* iso packet length */
821 struct sd
*sd
= (struct sd
*) gspca_dev
;
824 case 0: /* start of frame */
825 frame
= gspca_frame_add(gspca_dev
, LAST_PACKET
, frame
,
827 if (sd
->ag_cnt
>= 0) {
828 if (--sd
->ag_cnt
< 0) {
829 sd
->ag_cnt
= AG_CNT_START
;
830 setautogain(gspca_dev
);
833 data
+= SPCA561_OFFSET_DATA
;
834 len
-= SPCA561_OFFSET_DATA
;
835 if (data
[1] & 0x10) {
836 /* compressed bayer */
837 gspca_frame_add(gspca_dev
, FIRST_PACKET
,
840 /* raw bayer (with a header, which we skip) */
843 gspca_frame_add(gspca_dev
, FIRST_PACKET
,
847 case 0xff: /* drop */
848 /* gspca_dev->last_packet_type = DISCARD_PACKET; */
853 gspca_frame_add(gspca_dev
, INTER_PACKET
, frame
, data
, len
);
856 static void setbrightness(struct gspca_dev
*gspca_dev
)
858 struct sd
*sd
= (struct sd
*) gspca_dev
;
861 switch (sd
->chip_revision
) {
863 value
= sd
->brightness
;
864 reg_w_val(gspca_dev
->dev
, value
, 0x8611);
865 reg_w_val(gspca_dev
->dev
, value
, 0x8612);
866 reg_w_val(gspca_dev
->dev
, value
, 0x8613);
867 reg_w_val(gspca_dev
->dev
, value
, 0x8614);
871 setcontrast(gspca_dev
);
876 static void getbrightness(struct gspca_dev
*gspca_dev
)
878 struct sd
*sd
= (struct sd
*) gspca_dev
;
881 switch (sd
->chip_revision
) {
884 reg_r(gspca_dev
, 0x8611, 1);
885 tot
+= gspca_dev
->usb_buf
[0];
886 reg_r(gspca_dev
, 0x8612, 1);
887 tot
+= gspca_dev
->usb_buf
[0];
888 reg_r(gspca_dev
, 0x8613, 1);
889 tot
+= gspca_dev
->usb_buf
[0];
890 reg_r(gspca_dev
, 0x8614, 1);
891 tot
+= gspca_dev
->usb_buf
[0];
892 sd
->brightness
= tot
>> 2;
896 /* no way to read sensor settings */
901 static void getcontrast(struct gspca_dev
*gspca_dev
)
903 struct sd
*sd
= (struct sd
*) gspca_dev
;
906 switch (sd
->chip_revision
) {
909 reg_r(gspca_dev
, 0x8651, 1);
910 tot
+= gspca_dev
->usb_buf
[0];
911 reg_r(gspca_dev
, 0x8652, 1);
912 tot
+= gspca_dev
->usb_buf
[0];
913 reg_r(gspca_dev
, 0x8653, 1);
914 tot
+= gspca_dev
->usb_buf
[0];
915 reg_r(gspca_dev
, 0x8654, 1);
916 tot
+= gspca_dev
->usb_buf
[0];
917 sd
->contrast
= tot
<< 6;
921 /* no way to read sensor settings */
924 PDEBUG(D_CONF
, "get contrast %d", sd
->contrast
);
927 static int sd_setbrightness(struct gspca_dev
*gspca_dev
, __s32 val
)
929 struct sd
*sd
= (struct sd
*) gspca_dev
;
931 sd
->brightness
= val
;
932 if (gspca_dev
->streaming
)
933 setbrightness(gspca_dev
);
937 static int sd_getbrightness(struct gspca_dev
*gspca_dev
, __s32
*val
)
939 struct sd
*sd
= (struct sd
*) gspca_dev
;
941 getbrightness(gspca_dev
);
942 *val
= sd
->brightness
;
946 static int sd_setcontrast(struct gspca_dev
*gspca_dev
, __s32 val
)
948 struct sd
*sd
= (struct sd
*) gspca_dev
;
951 if (gspca_dev
->streaming
)
952 setcontrast(gspca_dev
);
956 static int sd_getcontrast(struct gspca_dev
*gspca_dev
, __s32
*val
)
958 struct sd
*sd
= (struct sd
*) gspca_dev
;
960 getcontrast(gspca_dev
);
965 static int sd_setautogain(struct gspca_dev
*gspca_dev
, __s32 val
)
967 struct sd
*sd
= (struct sd
*) gspca_dev
;
971 sd
->ag_cnt
= AG_CNT_START
;
977 static int sd_getautogain(struct gspca_dev
*gspca_dev
, __s32
*val
)
979 struct sd
*sd
= (struct sd
*) gspca_dev
;
985 /* sub-driver description */
986 static const struct sd_desc sd_desc
= {
989 .nctrls
= ARRAY_SIZE(sd_ctrls
),
996 .pkt_scan
= sd_pkt_scan
,
999 /* -- module initialisation -- */
1000 #define DVNM(name) .driver_info = (kernel_ulong_t) name
1001 static const __devinitdata
struct usb_device_id device_table
[] = {
1002 {USB_DEVICE(0x041e, 0x401a), DVNM("Creative Webcam Vista (PD1100)")},
1003 {USB_DEVICE(0x041e, 0x403b), DVNM("Creative Webcam Vista (VF0010)")},
1004 {USB_DEVICE(0x0458, 0x7004), DVNM("Genius VideoCAM Express V2")},
1005 {USB_DEVICE(0x046d, 0x0928), DVNM("Logitech QC Express Etch2")},
1006 {USB_DEVICE(0x046d, 0x0929), DVNM("Labtec Webcam Elch2")},
1007 {USB_DEVICE(0x046d, 0x092a), DVNM("Logitech QC for Notebook")},
1008 {USB_DEVICE(0x046d, 0x092b), DVNM("Labtec Webcam Plus")},
1009 {USB_DEVICE(0x046d, 0x092c), DVNM("Logitech QC chat Elch2")},
1010 {USB_DEVICE(0x046d, 0x092d), DVNM("Logitech QC Elch2")},
1011 {USB_DEVICE(0x046d, 0x092e), DVNM("Logitech QC Elch2")},
1012 {USB_DEVICE(0x046d, 0x092f), DVNM("Logitech QC Elch2")},
1013 {USB_DEVICE(0x04fc, 0x0561), DVNM("Flexcam 100")},
1014 {USB_DEVICE(0x060b, 0xa001), DVNM("Maxell Compact Pc PM3")},
1015 {USB_DEVICE(0x10fd, 0x7e50), DVNM("FlyCam Usb 100")},
1016 {USB_DEVICE(0xabcd, 0xcdee), DVNM("Petcam")},
1020 MODULE_DEVICE_TABLE(usb
, device_table
);
1022 /* -- device connect -- */
1023 static int sd_probe(struct usb_interface
*intf
,
1024 const struct usb_device_id
*id
)
1026 return gspca_dev_probe(intf
, id
, &sd_desc
, sizeof(struct sd
),
1030 static struct usb_driver sd_driver
= {
1031 .name
= MODULE_NAME
,
1032 .id_table
= device_table
,
1034 .disconnect
= gspca_disconnect
,
1037 /* -- module insert / remove -- */
1038 static int __init
sd_mod_init(void)
1040 if (usb_register(&sd_driver
) < 0)
1042 PDEBUG(D_PROBE
, "v%s registered", version
);
1045 static void __exit
sd_mod_exit(void)
1047 usb_deregister(&sd_driver
);
1048 PDEBUG(D_PROBE
, "deregistered");
1051 module_init(sd_mod_init
);
1052 module_exit(sd_mod_exit
);