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 MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
28 MODULE_DESCRIPTION("GSPCA/SPCA561 USB Camera Driver");
29 MODULE_LICENSE("GPL");
31 /* specific webcam descriptor */
33 struct gspca_dev gspca_dev; /* !! must be the first item */
35 __u16 contrast; /* rev72a only */
36 #define CONTRAST_MIN 0x0000
37 #define CONTRAST_DEF 0x2000
38 #define CONTRAST_MAX 0x3fff
40 __u16 exposure; /* rev12a only */
41 #define EXPOSURE_MIN 0
42 #define EXPOSURE_DEF 200
43 #define EXPOSURE_MAX 762
45 __u8 brightness; /* rev72a only */
46 #define BRIGHTNESS_MIN 0
47 #define BRIGHTNESS_DEF 32
48 #define BRIGHTNESS_MAX 63
50 __u8 white; /* rev12a only */
52 #define WHITE_DEF 0x40
53 #define WHITE_MAX 0x7f
56 #define AUTOGAIN_MIN 0
57 #define AUTOGAIN_DEF 1
58 #define AUTOGAIN_MAX 1
60 __u8 gain; /* rev12a only */
66 __u8 expo12a; /* expo/gain? for rev 12a */
73 #define AG_CNT_START 13
76 static struct v4l2_pix_format sif_mode[] = {
77 {160, 120, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE,
79 .sizeimage = 160 * 120,
80 .colorspace = V4L2_COLORSPACE_SRGB,
82 {176, 144, V4L2_PIX_FMT_SGBRG8, V4L2_FIELD_NONE,
84 .sizeimage = 176 * 144,
85 .colorspace = V4L2_COLORSPACE_SRGB,
87 {320, 240, V4L2_PIX_FMT_SPCA561, V4L2_FIELD_NONE,
89 .sizeimage = 320 * 240 * 4 / 8,
90 .colorspace = V4L2_COLORSPACE_SRGB,
92 {352, 288, V4L2_PIX_FMT_SPCA561, V4L2_FIELD_NONE,
94 .sizeimage = 352 * 288 * 4 / 8,
95 .colorspace = V4L2_COLORSPACE_SRGB,
100 * Initialization data
101 * I'm not very sure how to split initialization from open data
102 * chunks. For now, we'll consider everything as initialization
104 /* Frame packet header offsets for the spca561 */
105 #define SPCA561_OFFSET_SNAP 1
106 #define SPCA561_OFFSET_TYPE 2
107 #define SPCA561_OFFSET_COMPRESS 3
108 #define SPCA561_OFFSET_FRAMSEQ 4
109 #define SPCA561_OFFSET_GPIO 5
110 #define SPCA561_OFFSET_USBBUFF 6
111 #define SPCA561_OFFSET_WIN2GRAVE 7
112 #define SPCA561_OFFSET_WIN2RAVE 8
113 #define SPCA561_OFFSET_WIN2BAVE 9
114 #define SPCA561_OFFSET_WIN2GBAVE 10
115 #define SPCA561_OFFSET_WIN1GRAVE 11
116 #define SPCA561_OFFSET_WIN1RAVE 12
117 #define SPCA561_OFFSET_WIN1BAVE 13
118 #define SPCA561_OFFSET_WIN1GBAVE 14
119 #define SPCA561_OFFSET_FREQ 15
120 #define SPCA561_OFFSET_VSYNC 16
121 #define SPCA561_OFFSET_DATA 1
122 #define SPCA561_INDEX_I2C_BASE 0x8800
123 #define SPCA561_SNAPBIT 0x20
124 #define SPCA561_SNAPCTRL 0x40
126 static void reg_w_val(struct usb_device *dev, __u16 index, __u8 value)
130 ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
132 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
133 value, index, NULL, 0, 500);
134 PDEBUG(D_USBO, "reg write: 0x%02x:0x%02x", index, value);
136 PDEBUG(D_ERR, "reg write: error %d", ret);
139 static void write_vector(struct gspca_dev *gspca_dev,
140 const __u16 data[][2])
142 struct usb_device *dev = gspca_dev->dev;
146 while (data[i][1] != 0) {
147 reg_w_val(dev, data[i][1], data[i][0]);
152 /* read 'len' bytes to gspca_dev->usb_buf */
153 static void reg_r(struct gspca_dev *gspca_dev,
154 __u16 index, __u16 length)
156 usb_control_msg(gspca_dev->dev,
157 usb_rcvctrlpipe(gspca_dev->dev, 0),
159 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
161 index, gspca_dev->usb_buf, length, 500);
164 static void reg_w_buf(struct gspca_dev *gspca_dev,
165 __u16 index, const __u8 *buffer, __u16 len)
167 memcpy(gspca_dev->usb_buf, buffer, len);
168 usb_control_msg(gspca_dev->dev,
169 usb_sndctrlpipe(gspca_dev->dev, 0),
171 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
173 index, gspca_dev->usb_buf, len, 500);
176 static void i2c_write(struct gspca_dev *gspca_dev, __u16 valeur, __u16 reg)
183 DataHight = valeur >> 8;
184 reg_w_val(gspca_dev->dev, 0x8801, reg);
185 reg_w_val(gspca_dev->dev, 0x8805, DataLow);
186 reg_w_val(gspca_dev->dev, 0x8800, DataHight);
188 reg_r(gspca_dev, 0x8803, 1);
189 if (!gspca_dev->usb_buf[0])
194 static int i2c_read(struct gspca_dev *gspca_dev, __u16 reg, __u8 mode)
200 reg_w_val(gspca_dev->dev, 0x8804, 0x92);
201 reg_w_val(gspca_dev->dev, 0x8801, reg);
202 reg_w_val(gspca_dev->dev, 0x8802, (mode | 0x01));
204 reg_r(gspca_dev, 0x8803, 1);
205 if (!gspca_dev->usb_buf)
210 reg_r(gspca_dev, 0x8800, 1);
211 value = gspca_dev->usb_buf[0];
212 reg_r(gspca_dev, 0x8805, 1);
213 vallsb = gspca_dev->usb_buf[0];
214 return ((int) value << 8) | vallsb;
217 static const __u16 spca561_init_data[][2] = {
218 {0x0000, 0x8114}, /* Software GPIO output data */
219 {0x0001, 0x8114}, /* Software GPIO output data */
220 {0x0000, 0x8112}, /* Some kind of reset */
221 {0x0003, 0x8701}, /* PCLK clock delay adjustment */
222 {0x0001, 0x8703}, /* HSYNC from cmos inverted */
223 {0x0011, 0x8118}, /* Enable and conf sensor */
224 {0x0001, 0x8118}, /* Conf sensor */
225 {0x0092, 0x8804}, /* I know nothing about these */
226 {0x0010, 0x8802}, /* 0x88xx registers, so I won't */
228 {0x000d, 0x8805}, /* sensor default setting */
229 {0x0001, 0x8801}, /* 1 <- 0x0d */
232 {0x0002, 0x8801}, /* 2 <- 0x18 */
235 {0x0004, 0x8801}, /* 4 <- 0x01 0x65 */
238 {0x0005, 0x8801}, /* 5 <- 0x21 */
241 {0x0007, 0x8801}, /* 7 <- 0xaa */
244 {0x0020, 0x8801}, /* 0x20 <- 0x15 0x04 */
247 {0x0039, 0x8801}, /* 0x39 <- 0x02 */
250 {0x0035, 0x8801}, /* 0x35 <- 0x10 */
253 {0x0009, 0x8801}, /* 0x09 <- 0x10 0x49 */
256 {0x0028, 0x8801}, /* 0x28 <- 0x0b */
259 {0x003b, 0x8801}, /* 0x3b <- 0x0f */
262 {0x003c, 0x8801}, /* 0x3c <- 0x00 */
265 {0x0018, 0x8601}, /* Pixel/line selection for color separation */
266 {0x0000, 0x8602}, /* Optical black level for user setting */
267 {0x0060, 0x8604}, /* Optical black horizontal offset */
268 {0x0002, 0x8605}, /* Optical black vertical offset */
269 {0x0000, 0x8603}, /* Non-automatic optical black level */
270 {0x0002, 0x865b}, /* Horizontal offset for valid pixels */
271 {0x0000, 0x865f}, /* Vertical valid pixels window (x2) */
272 {0x00b0, 0x865d}, /* Horizontal valid pixels window (x2) */
273 {0x0090, 0x865e}, /* Vertical valid lines window (x2) */
274 {0x00e0, 0x8406}, /* Memory buffer threshold */
275 {0x0000, 0x8660}, /* Compensation memory stuff */
276 {0x0002, 0x8201}, /* Output address for r/w serial EEPROM */
277 {0x0008, 0x8200}, /* Clear valid bit for serial EEPROM */
278 {0x0001, 0x8200}, /* OprMode to be executed by hardware */
279 {0x0007, 0x8201}, /* Output address for r/w serial EEPROM */
280 {0x0008, 0x8200}, /* Clear valid bit for serial EEPROM */
281 {0x0001, 0x8200}, /* OprMode to be executed by hardware */
282 {0x0010, 0x8660}, /* Compensation memory stuff */
283 {0x0018, 0x8660}, /* Compensation memory stuff */
285 {0x0004, 0x8611}, /* R offset for white balance */
286 {0x0004, 0x8612}, /* Gr offset for white balance */
287 {0x0007, 0x8613}, /* B offset for white balance */
288 {0x0000, 0x8614}, /* Gb offset for white balance */
289 {0x008c, 0x8651}, /* R gain for white balance */
290 {0x008c, 0x8652}, /* Gr gain for white balance */
291 {0x00b5, 0x8653}, /* B gain for white balance */
292 {0x008c, 0x8654}, /* Gb gain for white balance */
293 {0x0002, 0x8502}, /* Maximum average bit rate stuff */
296 {0x0087, 0x8700}, /* Set master clock (96Mhz????) */
297 {0x0081, 0x8702}, /* Master clock output enable */
299 {0x0000, 0x8500}, /* Set image type (352x288 no compression) */
300 /* Originally was 0x0010 (352x288 compression) */
302 {0x0002, 0x865b}, /* Horizontal offset for valid pixels */
303 {0x0003, 0x865c}, /* Vertical offset for valid lines */
304 /***************//* sensor active */
305 {0x0003, 0x8801}, /* 0x03 <- 0x01 0x21 //289 */
308 {0x0004, 0x8801}, /* 0x04 <- 0x01 0x65 //357 */
311 {0x0005, 0x8801}, /* 0x05 <- 0x2f */
314 {0x0006, 0x8801}, /* 0x06 <- 0 */
317 {0x000a, 0x8801}, /* 0x0a <- 2 */
320 {0x0009, 0x8801}, /* 0x09 <- 0x1061 */
323 {0x0035, 0x8801}, /* 0x35 <-0x14 */
326 {0x0030, 0x8112}, /* ISO and drop packet enable */
327 {0x0000, 0x8112}, /* Some kind of reset ???? */
328 {0x0009, 0x8118}, /* Enable sensor and set standby */
329 {0x0000, 0x8114}, /* Software GPIO output data */
330 {0x0000, 0x8114}, /* Software GPIO output data */
331 {0x0001, 0x8114}, /* Software GPIO output data */
332 {0x0000, 0x8112}, /* Some kind of reset ??? */
353 {0x0007, 0x8801}, /* mode 0xaa */
357 {0x0015, 0x8800}, /* mode 0x0415 */
381 {0x0087, 0x8700}, /* overwrite by start */
384 /* {0x0010, 0x8500}, -- Previous line was this */
388 {0x0003, 0x8801}, /* 0x121-> 289 */
391 {0x0004, 0x8801}, /* 0x165 -> 357 */
394 {0x0005, 0x8801}, /* 0x2f //blanking control colonne */
397 {0x0006, 0x8801}, /* 0x00 //blanking mode row */
400 {0x000a, 0x8801}, /* 0x01 //0x02 */
403 {0x0009, 0x8801}, /* 0x1061 - setexposure times && pixel clock
404 * 0001 0 | 000 0110 0001 */
405 {0x0061, 0x8805}, /* 61 31 */
406 {0x0008, 0x8800}, /* 08 */
407 {0x0035, 0x8801}, /* 0x14 - set gain general */
408 {0x001f, 0x8805}, /* 0x14 */
410 {0x000e, 0x8112}, /* white balance - was 30 */
415 /******************** QC Express etch2 stuff ********************/
416 static const __u16 Pb100_1map8300[][2] = {
420 {0x8303, 0x0125}, /* image area */
423 {0x833c, 0x0001}, /*fixme: win:07*/
425 {0x832f, 0x1904}, /*fixme: was 0419*/
431 static const __u16 Pb100_2map8300[][2] = {
438 static const __u16 spca561_161rev12A_data1[][2] = {
439 {0x29, 0x8118}, /* white balance - was 21 */
440 {0x08, 0x8114}, /* white balance - was 01 */
441 {0x0e, 0x8112}, /* white balance - was 00 */
442 {0x00, 0x8102}, /* white balance - new */
444 {0x04, 0x8802}, /* windows uses 08 */
447 static const __u16 spca561_161rev12A_data2[][2] = {
455 {0x07, 0x8201}, /* windows uses 02 */
460 {0x01, 0x8114}, /* windows uses 00 */
467 {0x07, 0x8601}, /* white balance - new */
468 {0x07, 0x8602}, /* white balance - new */
469 {0x00, 0x8610}, /* *red */
470 {0x00, 0x8611}, /* 3f *green */
471 {0x00, 0x8612}, /* green *blue */
472 {0x00, 0x8613}, /* blue *green */
473 {0x43, 0x8614}, /* green *red - white balance - was 0x35 */
474 {0x40, 0x8615}, /* 40 *green - white balance - was 0x35 */
475 {0x71, 0x8616}, /* 7a *blue - white balance - was 0x35 */
476 {0x40, 0x8617}, /* 40 *green - white balance - was 0x35 */
478 {0x0c, 0x8620}, /* 0c */
479 {0xc8, 0x8631}, /* c8 */
480 {0xc8, 0x8634}, /* c8 */
481 {0x23, 0x8635}, /* 23 */
482 {0x1f, 0x8636}, /* 1f */
483 {0xdd, 0x8637}, /* dd */
484 {0xe1, 0x8638}, /* e1 */
485 {0x1d, 0x8639}, /* 1d */
486 {0x21, 0x863a}, /* 21 */
487 {0xe3, 0x863b}, /* e3 */
488 {0xdf, 0x863c}, /* df */
491 /* {0x99, 0x8700}, * - white balance - new (removed) */
495 static void sensor_mapwrite(struct gspca_dev *gspca_dev,
496 const __u16 sensormap[][2])
501 while (sensormap[i][0]) {
502 usbval[0] = sensormap[i][1];
503 usbval[1] = sensormap[i][1] >> 8;
504 reg_w_buf(gspca_dev, sensormap[i][0], usbval, 2);
508 static void init_161rev12A(struct gspca_dev *gspca_dev)
510 /* sensor_reset(gspca_dev); (not in win) */
511 write_vector(gspca_dev, spca561_161rev12A_data1);
512 sensor_mapwrite(gspca_dev, Pb100_1map8300);
513 /*fixme: should be in sd_start*/
514 write_vector(gspca_dev, spca561_161rev12A_data2);
515 sensor_mapwrite(gspca_dev, Pb100_2map8300);
518 /* this function is called at probe time */
519 static int sd_config(struct gspca_dev *gspca_dev,
520 const struct usb_device_id *id)
522 struct sd *sd = (struct sd *) gspca_dev;
524 __u16 vendor, product;
527 /* Read frm global register the USB product and vendor IDs, just to
528 * prove that we can communicate with the device. This works, which
529 * confirms at we are communicating properly and that the device
531 reg_r(gspca_dev, 0x8104, 1);
532 data1 = gspca_dev->usb_buf[0];
533 reg_r(gspca_dev, 0x8105, 1);
534 data2 = gspca_dev->usb_buf[0];
535 vendor = (data2 << 8) | data1;
536 reg_r(gspca_dev, 0x8106, 1);
537 data1 = gspca_dev->usb_buf[0];
538 reg_r(gspca_dev, 0x8107, 1);
539 data2 = gspca_dev->usb_buf[0];
540 product = (data2 << 8) | data1;
541 if (vendor != id->idVendor || product != id->idProduct) {
542 PDEBUG(D_PROBE, "Bad vendor / product from device");
546 cam = &gspca_dev->cam;
548 gspca_dev->nbalt = 7 + 1; /* choose alternate 7 first */
549 cam->cam_mode = sif_mode;
550 cam->nmodes = ARRAY_SIZE(sif_mode);
552 sd->chip_revision = id->driver_info;
553 sd->brightness = BRIGHTNESS_DEF;
554 sd->contrast = CONTRAST_DEF;
555 sd->white = WHITE_DEF;
556 sd->exposure = EXPOSURE_DEF;
557 sd->autogain = AUTOGAIN_DEF;
559 sd->expo12a = EXPO12A_DEF;
563 /* this function is called at probe and resume time */
564 static int sd_init_12a(struct gspca_dev *gspca_dev)
566 PDEBUG(D_STREAM, "Chip revision: 012a");
567 init_161rev12A(gspca_dev);
570 static int sd_init_72a(struct gspca_dev *gspca_dev)
572 PDEBUG(D_STREAM, "Chip revision: 072a");
573 write_vector(gspca_dev, spca561_init_data);
577 static void setcontrast(struct gspca_dev *gspca_dev)
579 struct sd *sd = (struct sd *) gspca_dev;
580 struct usb_device *dev = gspca_dev->dev;
583 switch (sd->chip_revision) {
585 lowb = sd->contrast >> 8;
586 reg_w_val(dev, 0x8651, lowb);
587 reg_w_val(dev, 0x8652, lowb);
588 reg_w_val(dev, 0x8653, lowb);
589 reg_w_val(dev, 0x8654, lowb);
592 /* case Rev012A: { */
593 static const __u8 Reg8391[] =
594 { 0x92, 0x30, 0x20, 0x00, 0x0c, 0x00, 0x00, 0x00 };
596 reg_w_buf(gspca_dev, 0x8391, Reg8391, 8);
597 reg_w_buf(gspca_dev, 0x8390, Reg8391, 8);
604 static void setwhite(struct gspca_dev *gspca_dev)
606 struct sd *sd = (struct sd *) gspca_dev;
608 __u8 reg8614, reg8616;
611 /* try to emulate MS-win as possible */
612 reg8616 = 0x90 - white * 5 / 8;
613 reg_w_val(gspca_dev->dev, 0x8616, reg8616);
614 reg8614 = 0x20 + white * 3 / 8;
615 reg_w_val(gspca_dev->dev, 0x8614, reg8614);
619 static void setexposure(struct gspca_dev *gspca_dev)
621 struct sd *sd = (struct sd *) gspca_dev;
625 expo = sd->exposure + 0x20a8; /* from test */
628 reg_w_buf(gspca_dev, 0x8309, data, 2);
632 static void setgain(struct gspca_dev *gspca_dev)
634 struct sd *sd = (struct sd *) gspca_dev;
639 reg_w_buf(gspca_dev, 0x8335, data, 2);
642 static void setautogain(struct gspca_dev *gspca_dev)
644 struct sd *sd = (struct sd *) gspca_dev;
647 sd->ag_cnt = AG_CNT_START;
652 static void sd_start_12a(struct gspca_dev *gspca_dev)
654 struct usb_device *dev = gspca_dev->dev;
656 __u8 Reg8307[] = { 0xaa, 0x00 };
659 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
673 /* Use compression on 320x240 and above */
674 reg_w_val(dev, 0x8500, 0x10 | mode);
676 /* I couldn't get the compression to work below 320x240
677 * Fortunately at these resolutions the bandwidth
678 * is sufficient to push raw frames at ~20fps */
679 reg_w_val(dev, 0x8500, mode);
680 } /* -- qq@kuku.eu.org */
681 reg_w_buf(gspca_dev, 0x8307, Reg8307, 2);
682 reg_w_val(gspca_dev->dev, 0x8700, Clck);
683 /* 0x8f 0x85 0x27 clock */
684 reg_w_val(gspca_dev->dev, 0x8112, 0x1e | 0x20);
685 reg_w_val(gspca_dev->dev, 0x850b, 0x03);
686 setcontrast(gspca_dev);
688 setautogain(gspca_dev);
690 static void sd_start_72a(struct gspca_dev *gspca_dev)
692 struct usb_device *dev = gspca_dev->dev;
696 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
710 reg_w_val(dev, 0x8500, mode); /* mode */
711 reg_w_val(dev, 0x8700, Clck); /* 0x27 clock */
712 reg_w_val(dev, 0x8112, 0x10 | 0x20);
713 setautogain(gspca_dev);
716 static void sd_stopN(struct gspca_dev *gspca_dev)
718 struct sd *sd = (struct sd *) gspca_dev;
720 if (sd->chip_revision == Rev012A) {
721 reg_w_val(gspca_dev->dev, 0x8112, 0x0e);
723 reg_w_val(gspca_dev->dev, 0x8112, 0x20);
724 /* reg_w_val(gspca_dev->dev, 0x8102, 0x00); ?? */
728 static void sd_stop0(struct gspca_dev *gspca_dev)
730 struct sd *sd = (struct sd *) gspca_dev;
732 if (sd->chip_revision == Rev012A) {
733 reg_w_val(gspca_dev->dev, 0x8118, 0x29);
734 reg_w_val(gspca_dev->dev, 0x8114, 0x08);
736 /* reg_w_val(gspca_dev->dev, 0x8114, 0); */
739 static void do_autogain(struct gspca_dev *gspca_dev)
741 struct sd *sd = (struct sd *) gspca_dev;
747 __u8 luma_mean = 110;
748 __u8 luma_delta = 20;
754 if (--sd->ag_cnt >= 0)
756 sd->ag_cnt = AG_CNT_START;
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 reg_r(gspca_dev, 0x8330, 2);
806 if (gspca_dev->usb_buf[1] > 0x08) {
807 reg8339[0] = ++sd->expo12a;
809 reg_w_buf(gspca_dev, 0x8339, reg8339, 2);
810 } else if (gspca_dev->usb_buf[1] < 0x02) {
811 reg8339[0] = --sd->expo12a;
813 reg_w_buf(gspca_dev, 0x8339, reg8339, 2);
819 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
820 struct gspca_frame *frame, /* target */
821 __u8 *data, /* isoc packet */
822 int len) /* iso packet length */
825 case 0: /* start of frame */
826 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
828 data += SPCA561_OFFSET_DATA;
829 len -= SPCA561_OFFSET_DATA;
830 if (data[1] & 0x10) {
831 /* compressed bayer */
832 gspca_frame_add(gspca_dev, FIRST_PACKET,
835 /* raw bayer (with a header, which we skip) */
838 gspca_frame_add(gspca_dev, FIRST_PACKET,
842 case 0xff: /* drop */
843 /* gspca_dev->last_packet_type = DISCARD_PACKET; */
848 gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
852 static void setbrightness(struct gspca_dev *gspca_dev)
854 struct sd *sd = (struct sd *) gspca_dev;
857 value = sd->brightness;
858 reg_w_val(gspca_dev->dev, 0x8611, value);
859 reg_w_val(gspca_dev->dev, 0x8612, value);
860 reg_w_val(gspca_dev->dev, 0x8613, value);
861 reg_w_val(gspca_dev->dev, 0x8614, value);
864 static void getbrightness(struct gspca_dev *gspca_dev)
866 struct sd *sd = (struct sd *) gspca_dev;
870 reg_r(gspca_dev, 0x8611, 1);
871 tot += gspca_dev->usb_buf[0];
872 reg_r(gspca_dev, 0x8612, 1);
873 tot += gspca_dev->usb_buf[0];
874 reg_r(gspca_dev, 0x8613, 1);
875 tot += gspca_dev->usb_buf[0];
876 reg_r(gspca_dev, 0x8614, 1);
877 tot += gspca_dev->usb_buf[0];
878 sd->brightness = tot >> 2;
882 static void getcontrast(struct gspca_dev *gspca_dev)
884 struct sd *sd = (struct sd *) gspca_dev;
888 reg_r(gspca_dev, 0x8651, 1);
889 tot += gspca_dev->usb_buf[0];
890 reg_r(gspca_dev, 0x8652, 1);
891 tot += gspca_dev->usb_buf[0];
892 reg_r(gspca_dev, 0x8653, 1);
893 tot += gspca_dev->usb_buf[0];
894 reg_r(gspca_dev, 0x8654, 1);
895 tot += gspca_dev->usb_buf[0];
896 sd->contrast = tot << 6;
897 PDEBUG(D_CONF, "get contrast %d", sd->contrast);
901 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
903 struct sd *sd = (struct sd *) gspca_dev;
905 sd->brightness = val;
906 if (gspca_dev->streaming)
907 setbrightness(gspca_dev);
911 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
913 struct sd *sd = (struct sd *) gspca_dev;
915 getbrightness(gspca_dev);
916 *val = sd->brightness;
921 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
923 struct sd *sd = (struct sd *) gspca_dev;
926 if (gspca_dev->streaming)
927 setcontrast(gspca_dev);
931 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
933 struct sd *sd = (struct sd *) gspca_dev;
935 getcontrast(gspca_dev);
940 static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val)
942 struct sd *sd = (struct sd *) gspca_dev;
945 if (gspca_dev->streaming)
946 setautogain(gspca_dev);
950 static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
952 struct sd *sd = (struct sd *) gspca_dev;
959 static int sd_setwhite(struct gspca_dev *gspca_dev, __s32 val)
961 struct sd *sd = (struct sd *) gspca_dev;
964 if (gspca_dev->streaming)
969 static int sd_getwhite(struct gspca_dev *gspca_dev, __s32 *val)
971 struct sd *sd = (struct sd *) gspca_dev;
978 static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
980 struct sd *sd = (struct sd *) gspca_dev;
983 if (gspca_dev->streaming)
984 setexposure(gspca_dev);
988 static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
990 struct sd *sd = (struct sd *) gspca_dev;
997 static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
999 struct sd *sd = (struct sd *) gspca_dev;
1002 if (gspca_dev->streaming)
1007 static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
1009 struct sd *sd = (struct sd *) gspca_dev;
1015 /* control tables */
1016 static struct ctrl sd_ctrls_12a[] = {
1019 .id = V4L2_CID_DO_WHITE_BALANCE,
1020 .type = V4L2_CTRL_TYPE_INTEGER,
1021 .name = "While Balance",
1022 .minimum = WHITE_MIN,
1023 .maximum = WHITE_MAX,
1025 .default_value = WHITE_DEF,
1032 .id = V4L2_CID_EXPOSURE,
1033 .type = V4L2_CTRL_TYPE_INTEGER,
1035 .minimum = EXPOSURE_MIN,
1036 .maximum = EXPOSURE_MAX,
1038 .default_value = EXPOSURE_DEF,
1040 .set = sd_setexposure,
1041 .get = sd_getexposure,
1045 .id = V4L2_CID_AUTOGAIN,
1046 .type = V4L2_CTRL_TYPE_BOOLEAN,
1047 .name = "Auto Gain",
1048 .minimum = AUTOGAIN_MIN,
1049 .maximum = AUTOGAIN_MAX,
1051 .default_value = AUTOGAIN_DEF,
1053 .set = sd_setautogain,
1054 .get = sd_getautogain,
1058 .id = V4L2_CID_GAIN,
1059 .type = V4L2_CTRL_TYPE_INTEGER,
1061 .minimum = GAIN_MIN,
1062 .maximum = GAIN_MAX,
1064 .default_value = GAIN_DEF,
1071 static struct ctrl sd_ctrls_72a[] = {
1074 .id = V4L2_CID_BRIGHTNESS,
1075 .type = V4L2_CTRL_TYPE_INTEGER,
1076 .name = "Brightness",
1077 .minimum = BRIGHTNESS_MIN,
1078 .maximum = BRIGHTNESS_MAX,
1080 .default_value = BRIGHTNESS_DEF,
1082 .set = sd_setbrightness,
1083 .get = sd_getbrightness,
1087 .id = V4L2_CID_CONTRAST,
1088 .type = V4L2_CTRL_TYPE_INTEGER,
1090 .minimum = CONTRAST_MIN,
1091 .maximum = CONTRAST_MAX,
1093 .default_value = CONTRAST_DEF,
1095 .set = sd_setcontrast,
1096 .get = sd_getcontrast,
1100 .id = V4L2_CID_AUTOGAIN,
1101 .type = V4L2_CTRL_TYPE_BOOLEAN,
1102 .name = "Auto Gain",
1103 .minimum = AUTOGAIN_MIN,
1104 .maximum = AUTOGAIN_MAX,
1106 .default_value = AUTOGAIN_DEF,
1108 .set = sd_setautogain,
1109 .get = sd_getautogain,
1113 /* sub-driver description */
1114 static const struct sd_desc sd_desc_12a = {
1115 .name = MODULE_NAME,
1116 .ctrls = sd_ctrls_12a,
1117 .nctrls = ARRAY_SIZE(sd_ctrls_12a),
1118 .config = sd_config,
1119 .init = sd_init_12a,
1120 .start = sd_start_12a,
1123 .pkt_scan = sd_pkt_scan,
1124 /* .dq_callback = do_autogain, * fixme */
1126 static const struct sd_desc sd_desc_72a = {
1127 .name = MODULE_NAME,
1128 .ctrls = sd_ctrls_72a,
1129 .nctrls = ARRAY_SIZE(sd_ctrls_72a),
1130 .config = sd_config,
1131 .init = sd_init_72a,
1132 .start = sd_start_72a,
1135 .pkt_scan = sd_pkt_scan,
1136 .dq_callback = do_autogain,
1138 static const struct sd_desc *sd_desc[2] = {
1143 /* -- module initialisation -- */
1144 static const __devinitdata struct usb_device_id device_table[] = {
1145 {USB_DEVICE(0x041e, 0x401a), .driver_info = Rev072A},
1146 {USB_DEVICE(0x041e, 0x403b), .driver_info = Rev012A},
1147 {USB_DEVICE(0x0458, 0x7004), .driver_info = Rev072A},
1148 {USB_DEVICE(0x046d, 0x0928), .driver_info = Rev012A},
1149 {USB_DEVICE(0x046d, 0x0929), .driver_info = Rev012A},
1150 {USB_DEVICE(0x046d, 0x092a), .driver_info = Rev012A},
1151 {USB_DEVICE(0x046d, 0x092b), .driver_info = Rev012A},
1152 {USB_DEVICE(0x046d, 0x092c), .driver_info = Rev012A},
1153 {USB_DEVICE(0x046d, 0x092d), .driver_info = Rev012A},
1154 {USB_DEVICE(0x046d, 0x092e), .driver_info = Rev012A},
1155 {USB_DEVICE(0x046d, 0x092f), .driver_info = Rev012A},
1156 {USB_DEVICE(0x04fc, 0x0561), .driver_info = Rev072A},
1157 {USB_DEVICE(0x060b, 0xa001), .driver_info = Rev072A},
1158 {USB_DEVICE(0x10fd, 0x7e50), .driver_info = Rev072A},
1159 {USB_DEVICE(0xabcd, 0xcdee), .driver_info = Rev072A},
1163 MODULE_DEVICE_TABLE(usb, device_table);
1165 /* -- device connect -- */
1166 static int sd_probe(struct usb_interface *intf,
1167 const struct usb_device_id *id)
1169 return gspca_dev_probe(intf, id,
1170 sd_desc[id->driver_info],
1175 static struct usb_driver sd_driver = {
1176 .name = MODULE_NAME,
1177 .id_table = device_table,
1179 .disconnect = gspca_disconnect,
1181 .suspend = gspca_suspend,
1182 .resume = gspca_resume,
1186 /* -- module insert / remove -- */
1187 static int __init sd_mod_init(void)
1189 if (usb_register(&sd_driver) < 0)
1191 PDEBUG(D_PROBE, "registered");
1194 static void __exit sd_mod_exit(void)
1196 usb_deregister(&sd_driver);
1197 PDEBUG(D_PROBE, "deregistered");
1200 module_init(sd_mod_init);
1201 module_exit(sd_mod_exit);