2 * ov534-ov772x gspca driver
4 * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it>
5 * Copyright (C) 2008 Jim Paris <jim@jtan.com>
6 * Copyright (C) 2009 Jean-Francois Moine http://moinejf.free.fr
8 * Based on a prototype written by Mark Ferrell <majortrips@gmail.com>
9 * USB protocol reverse engineered by Jim Paris <jim@jtan.com>
10 * https://jim.sh/svn/jim/devl/playstation/ps3/eye/test/
12 * PS3 Eye camera enhanced by Richard Kaswy http://kaswy.free.fr
13 * PS3 Eye camera - brightness, contrast, awb, agc, aec controls
14 * added by Max Thrun <bear24rw@gmail.com>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #define MODULE_NAME "ov534"
35 #define OV534_REG_ADDRESS 0xf1 /* sensor address */
36 #define OV534_REG_SUBADDR 0xf2
37 #define OV534_REG_WRITE 0xf3
38 #define OV534_REG_READ 0xf4
39 #define OV534_REG_OPERATION 0xf5
40 #define OV534_REG_STATUS 0xf6
42 #define OV534_OP_WRITE_3 0x37
43 #define OV534_OP_WRITE_2 0x33
44 #define OV534_OP_READ_2 0xf9
46 #define CTRL_TIMEOUT 500
48 MODULE_AUTHOR("Antonio Ospite <ospite@studenti.unina.it>");
49 MODULE_DESCRIPTION("GSPCA/OV534 USB Camera Driver");
50 MODULE_LICENSE("GPL");
52 /* specific webcam descriptor */
54 struct gspca_dev gspca_dev; /* !! must be the first item */
72 /* V4L2 controls supported by the driver */
73 static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val);
74 static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val);
75 static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val);
76 static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val);
77 static int sd_setagc(struct gspca_dev *gspca_dev, __s32 val);
78 static int sd_getagc(struct gspca_dev *gspca_dev, __s32 *val);
79 static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val);
80 static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val);
81 static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val);
82 static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val);
83 static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
84 static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
85 static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val);
86 static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val);
87 static int sd_setaec(struct gspca_dev *gspca_dev, __s32 val);
88 static int sd_getaec(struct gspca_dev *gspca_dev, __s32 *val);
89 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val);
90 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val);
91 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
92 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
93 static int sd_setfreqfltr(struct gspca_dev *gspca_dev, __s32 val);
94 static int sd_getfreqfltr(struct gspca_dev *gspca_dev, __s32 *val);
95 static int sd_querymenu(struct gspca_dev *gspca_dev,
96 struct v4l2_querymenu *menu);
98 static const struct ctrl sd_ctrls[] = {
101 .id = V4L2_CID_BRIGHTNESS,
102 .type = V4L2_CTRL_TYPE_INTEGER,
103 .name = "Brightness",
107 #define BRIGHTNESS_DEF 0
108 .default_value = BRIGHTNESS_DEF,
110 .set = sd_setbrightness,
111 .get = sd_getbrightness,
115 .id = V4L2_CID_CONTRAST,
116 .type = V4L2_CTRL_TYPE_INTEGER,
121 #define CONTRAST_DEF 32
122 .default_value = CONTRAST_DEF,
124 .set = sd_setcontrast,
125 .get = sd_getcontrast,
130 .type = V4L2_CTRL_TYPE_INTEGER,
136 .default_value = GAIN_DEF,
143 .id = V4L2_CID_EXPOSURE,
144 .type = V4L2_CTRL_TYPE_INTEGER,
150 .default_value = EXPO_DEF,
152 .set = sd_setexposure,
153 .get = sd_getexposure,
157 .id = V4L2_CID_AUTOGAIN,
158 .type = V4L2_CTRL_TYPE_BOOLEAN,
164 .default_value = AGC_DEF,
172 .id = V4L2_CID_AUTO_WHITE_BALANCE,
173 .type = V4L2_CTRL_TYPE_BOOLEAN,
174 .name = "Auto White Balance",
179 .default_value = AWB_DEF,
186 .id = V4L2_CID_EXPOSURE_AUTO,
187 .type = V4L2_CTRL_TYPE_BOOLEAN,
188 .name = "Auto Exposure",
193 .default_value = AEC_DEF,
200 .id = V4L2_CID_SHARPNESS,
201 .type = V4L2_CTRL_TYPE_INTEGER,
206 #define SHARPNESS_DEF 0
207 .default_value = SHARPNESS_DEF,
209 .set = sd_setsharpness,
210 .get = sd_getsharpness,
214 .id = V4L2_CID_HFLIP,
215 .type = V4L2_CTRL_TYPE_BOOLEAN,
221 .default_value = HFLIP_DEF,
228 .id = V4L2_CID_VFLIP,
229 .type = V4L2_CTRL_TYPE_BOOLEAN,
235 .default_value = VFLIP_DEF,
242 .id = V4L2_CID_POWER_LINE_FREQUENCY,
243 .type = V4L2_CTRL_TYPE_MENU,
244 .name = "Light Frequency Filter",
248 #define FREQFLTR_DEF 0
249 .default_value = FREQFLTR_DEF,
251 .set = sd_setfreqfltr,
252 .get = sd_getfreqfltr,
256 static const struct v4l2_pix_format ov772x_mode[] = {
257 {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
258 .bytesperline = 320 * 2,
259 .sizeimage = 320 * 240 * 2,
260 .colorspace = V4L2_COLORSPACE_SRGB,
262 {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
263 .bytesperline = 640 * 2,
264 .sizeimage = 640 * 480 * 2,
265 .colorspace = V4L2_COLORSPACE_SRGB,
269 static const u8 qvga_rates[] = {125, 100, 75, 60, 50, 40, 30};
270 static const u8 vga_rates[] = {60, 50, 40, 30, 15};
272 static const struct framerates ov772x_framerates[] = {
275 .nrates = ARRAY_SIZE(qvga_rates),
279 .nrates = ARRAY_SIZE(vga_rates),
283 static const u8 bridge_init[][2] = {
322 { 0x1d, 0x02 }, /* payload size 0x0200 * 4 = 2048 bytes */
323 { 0x1d, 0x00 }, /* payload size */
325 { 0x1d, 0x02 }, /* frame size 0x025800 * 4 = 614400 */
326 { 0x1d, 0x58 }, /* frame size */
327 { 0x1d, 0x00 }, /* frame size */
330 { 0x1d, 0x08 }, /* turn on UVC header */
331 { 0x1d, 0x0e }, /* .. */
341 static const u8 sensor_init[][2] = {
344 /*fixme: better have a delay?*/
367 { 0x63, 0xaa }, /* AWB - was e0 */
370 { 0x13, 0xf0 }, /* com8 */
383 { 0x13, 0xff }, /* AWB */
431 { 0x8e, 0x00 }, /* De-noise threshold */
434 static const u8 bridge_start_vga[][2] = {
445 static const u8 sensor_start_vga[][2] = {
455 static const u8 bridge_start_qvga[][2] = {
466 static const u8 sensor_start_qvga[][2] = {
477 static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
479 struct usb_device *udev = gspca_dev->dev;
482 PDEBUG(D_USBO, "reg=0x%04x, val=0%02x", reg, val);
483 gspca_dev->usb_buf[0] = val;
484 ret = usb_control_msg(udev,
485 usb_sndctrlpipe(udev, 0),
487 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
488 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
490 err("write failed %d", ret);
493 static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg)
495 struct usb_device *udev = gspca_dev->dev;
498 ret = usb_control_msg(udev,
499 usb_rcvctrlpipe(udev, 0),
501 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
502 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
503 PDEBUG(D_USBI, "reg=0x%04x, data=0x%02x", reg, gspca_dev->usb_buf[0]);
505 err("read failed %d", ret);
506 return gspca_dev->usb_buf[0];
509 /* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
510 * (direction and output)? */
511 static void ov534_set_led(struct gspca_dev *gspca_dev, int status)
515 PDEBUG(D_CONF, "led status: %d", status);
517 data = ov534_reg_read(gspca_dev, 0x21);
519 ov534_reg_write(gspca_dev, 0x21, data);
521 data = ov534_reg_read(gspca_dev, 0x23);
527 ov534_reg_write(gspca_dev, 0x23, data);
530 data = ov534_reg_read(gspca_dev, 0x21);
532 ov534_reg_write(gspca_dev, 0x21, data);
536 static int sccb_check_status(struct gspca_dev *gspca_dev)
541 for (i = 0; i < 5; i++) {
542 data = ov534_reg_read(gspca_dev, OV534_REG_STATUS);
552 PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5",
559 static void sccb_reg_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
561 PDEBUG(D_USBO, "reg: 0x%02x, val: 0x%02x", reg, val);
562 ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
563 ov534_reg_write(gspca_dev, OV534_REG_WRITE, val);
564 ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
566 if (!sccb_check_status(gspca_dev))
567 err("sccb_reg_write failed");
570 static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg)
572 ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
573 ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
574 if (!sccb_check_status(gspca_dev))
575 err("sccb_reg_read failed 1");
577 ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
578 if (!sccb_check_status(gspca_dev))
579 err("sccb_reg_read failed 2");
581 return ov534_reg_read(gspca_dev, OV534_REG_READ);
584 /* output a bridge sequence (reg - val) */
585 static void reg_w_array(struct gspca_dev *gspca_dev,
586 const u8 (*data)[2], int len)
589 ov534_reg_write(gspca_dev, (*data)[0], (*data)[1]);
594 /* output a sensor sequence (reg - val) */
595 static void sccb_w_array(struct gspca_dev *gspca_dev,
596 const u8 (*data)[2], int len)
599 if ((*data)[0] != 0xff) {
600 sccb_reg_write(gspca_dev, (*data)[0], (*data)[1]);
602 sccb_reg_read(gspca_dev, (*data)[1]);
603 sccb_reg_write(gspca_dev, 0xff, 0x00);
609 /* ov772x specific controls */
610 static void set_frame_rate(struct gspca_dev *gspca_dev)
612 struct sd *sd = (struct sd *) gspca_dev;
620 const struct rate_s *r;
621 static const struct rate_s rate_0[] = { /* 640x480 */
622 {60, 0x01, 0xc1, 0x04},
623 {50, 0x01, 0x41, 0x02},
624 {40, 0x02, 0xc1, 0x04},
625 {30, 0x04, 0x81, 0x02},
626 {15, 0x03, 0x41, 0x04},
628 static const struct rate_s rate_1[] = { /* 320x240 */
629 {125, 0x02, 0x81, 0x02},
630 {100, 0x02, 0xc1, 0x04},
631 {75, 0x03, 0xc1, 0x04},
632 {60, 0x04, 0xc1, 0x04},
633 {50, 0x02, 0x41, 0x04},
634 {40, 0x03, 0x41, 0x04},
635 {30, 0x04, 0x41, 0x04},
638 if (gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv == 0) {
640 i = ARRAY_SIZE(rate_0);
643 i = ARRAY_SIZE(rate_1);
646 if (sd->frame_rate >= r->fps)
651 sccb_reg_write(gspca_dev, 0x11, r->r11);
652 sccb_reg_write(gspca_dev, 0x0d, r->r0d);
653 ov534_reg_write(gspca_dev, 0xe5, r->re5);
655 PDEBUG(D_PROBE, "frame_rate: %d", r->fps);
658 static void setbrightness(struct gspca_dev *gspca_dev)
660 struct sd *sd = (struct sd *) gspca_dev;
662 sccb_reg_write(gspca_dev, 0x9b, sd->brightness);
665 static void setcontrast(struct gspca_dev *gspca_dev)
667 struct sd *sd = (struct sd *) gspca_dev;
669 sccb_reg_write(gspca_dev, 0x9c, sd->contrast);
672 static void setgain(struct gspca_dev *gspca_dev)
674 struct sd *sd = (struct sd *) gspca_dev;
681 switch (val & 0x30) {
699 sccb_reg_write(gspca_dev, 0x00, val);
702 static void setexposure(struct gspca_dev *gspca_dev)
704 struct sd *sd = (struct sd *) gspca_dev;
710 /* 'val' is one byte and represents half of the exposure value we are
711 * going to set into registers, a two bytes value:
713 * MSB: ((u16) val << 1) >> 8 == val >> 7
714 * LSB: ((u16) val << 1) & 0xff == val << 1
717 sccb_reg_write(gspca_dev, 0x08, val >> 7);
718 sccb_reg_write(gspca_dev, 0x10, val << 1);
721 static void setagc(struct gspca_dev *gspca_dev)
723 struct sd *sd = (struct sd *) gspca_dev;
726 sccb_reg_write(gspca_dev, 0x13,
727 sccb_reg_read(gspca_dev, 0x13) | 0x04);
728 sccb_reg_write(gspca_dev, 0x64,
729 sccb_reg_read(gspca_dev, 0x64) | 0x03);
731 sccb_reg_write(gspca_dev, 0x13,
732 sccb_reg_read(gspca_dev, 0x13) & ~0x04);
733 sccb_reg_write(gspca_dev, 0x64,
734 sccb_reg_read(gspca_dev, 0x64) & ~0x03);
740 static void setawb(struct gspca_dev *gspca_dev)
742 struct sd *sd = (struct sd *) gspca_dev;
745 sccb_reg_write(gspca_dev, 0x13,
746 sccb_reg_read(gspca_dev, 0x13) | 0x02);
747 sccb_reg_write(gspca_dev, 0x63,
748 sccb_reg_read(gspca_dev, 0x63) | 0xc0);
750 sccb_reg_write(gspca_dev, 0x13,
751 sccb_reg_read(gspca_dev, 0x13) & ~0x02);
752 sccb_reg_write(gspca_dev, 0x63,
753 sccb_reg_read(gspca_dev, 0x63) & ~0xc0);
757 static void setaec(struct gspca_dev *gspca_dev)
759 struct sd *sd = (struct sd *) gspca_dev;
762 sccb_reg_write(gspca_dev, 0x13,
763 sccb_reg_read(gspca_dev, 0x13) | 0x01);
765 sccb_reg_write(gspca_dev, 0x13,
766 sccb_reg_read(gspca_dev, 0x13) & ~0x01);
767 setexposure(gspca_dev);
771 static void setsharpness(struct gspca_dev *gspca_dev)
773 struct sd *sd = (struct sd *) gspca_dev;
777 sccb_reg_write(gspca_dev, 0x91, val); /* Auto de-noise threshold */
778 sccb_reg_write(gspca_dev, 0x8e, val); /* De-noise threshold */
781 static void sethflip(struct gspca_dev *gspca_dev)
783 struct sd *sd = (struct sd *) gspca_dev;
786 sccb_reg_write(gspca_dev, 0x0c,
787 sccb_reg_read(gspca_dev, 0x0c) | 0x40);
789 sccb_reg_write(gspca_dev, 0x0c,
790 sccb_reg_read(gspca_dev, 0x0c) & ~0x40);
793 static void setvflip(struct gspca_dev *gspca_dev)
795 struct sd *sd = (struct sd *) gspca_dev;
798 sccb_reg_write(gspca_dev, 0x0c,
799 sccb_reg_read(gspca_dev, 0x0c) | 0x80);
801 sccb_reg_write(gspca_dev, 0x0c,
802 sccb_reg_read(gspca_dev, 0x0c) & ~0x80);
805 static void setfreqfltr(struct gspca_dev *gspca_dev)
807 struct sd *sd = (struct sd *) gspca_dev;
809 if (sd->freqfltr == 0)
810 sccb_reg_write(gspca_dev, 0x2b, 0x00);
812 sccb_reg_write(gspca_dev, 0x2b, 0x9e);
816 /* this function is called at probe time */
817 static int sd_config(struct gspca_dev *gspca_dev,
818 const struct usb_device_id *id)
820 struct sd *sd = (struct sd *) gspca_dev;
823 cam = &gspca_dev->cam;
825 cam->cam_mode = ov772x_mode;
826 cam->nmodes = ARRAY_SIZE(ov772x_mode);
827 cam->mode_framerates = ov772x_framerates;
830 cam->bulk_size = 16384;
835 sd->brightness = BRIGHTNESS_DEF;
836 sd->contrast = CONTRAST_DEF;
838 sd->exposure = EXPO_DEF;
842 gspca_dev->ctrl_inac |= (1 << AWB_IDX);
846 sd->sharpness = SHARPNESS_DEF;
847 sd->hflip = HFLIP_DEF;
848 sd->vflip = VFLIP_DEF;
849 sd->freqfltr = FREQFLTR_DEF;
854 /* this function is called at probe and resume time */
855 static int sd_init(struct gspca_dev *gspca_dev)
860 ov534_reg_write(gspca_dev, 0xe7, 0x3a);
861 ov534_reg_write(gspca_dev, 0xe0, 0x08);
864 /* initialize the sensor address */
865 ov534_reg_write(gspca_dev, OV534_REG_ADDRESS, 0x42);
868 sccb_reg_write(gspca_dev, 0x12, 0x80);
871 /* probe the sensor */
872 sccb_reg_read(gspca_dev, 0x0a);
873 sensor_id = sccb_reg_read(gspca_dev, 0x0a) << 8;
874 sccb_reg_read(gspca_dev, 0x0b);
875 sensor_id |= sccb_reg_read(gspca_dev, 0x0b);
876 PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id);
879 reg_w_array(gspca_dev, bridge_init,
880 ARRAY_SIZE(bridge_init));
881 ov534_set_led(gspca_dev, 1);
882 sccb_w_array(gspca_dev, sensor_init,
883 ARRAY_SIZE(sensor_init));
884 ov534_reg_write(gspca_dev, 0xe0, 0x09);
885 ov534_set_led(gspca_dev, 0);
886 set_frame_rate(gspca_dev);
891 static int sd_start(struct gspca_dev *gspca_dev)
895 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
896 if (mode != 0) { /* 320x240 */
897 reg_w_array(gspca_dev, bridge_start_qvga,
898 ARRAY_SIZE(bridge_start_qvga));
899 sccb_w_array(gspca_dev, sensor_start_qvga,
900 ARRAY_SIZE(sensor_start_qvga));
901 } else { /* 640x480 */
902 reg_w_array(gspca_dev, bridge_start_vga,
903 ARRAY_SIZE(bridge_start_vga));
904 sccb_w_array(gspca_dev, sensor_start_vga,
905 ARRAY_SIZE(sensor_start_vga));
907 set_frame_rate(gspca_dev);
913 setexposure(gspca_dev);
914 setbrightness(gspca_dev);
915 setcontrast(gspca_dev);
916 setsharpness(gspca_dev);
919 setfreqfltr(gspca_dev);
921 ov534_set_led(gspca_dev, 1);
922 ov534_reg_write(gspca_dev, 0xe0, 0x00);
926 static void sd_stopN(struct gspca_dev *gspca_dev)
928 ov534_reg_write(gspca_dev, 0xe0, 0x09);
929 ov534_set_led(gspca_dev, 0);
932 /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
933 #define UVC_STREAM_EOH (1 << 7)
934 #define UVC_STREAM_ERR (1 << 6)
935 #define UVC_STREAM_STI (1 << 5)
936 #define UVC_STREAM_RES (1 << 4)
937 #define UVC_STREAM_SCR (1 << 3)
938 #define UVC_STREAM_PTS (1 << 2)
939 #define UVC_STREAM_EOF (1 << 1)
940 #define UVC_STREAM_FID (1 << 0)
942 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
945 struct sd *sd = (struct sd *) gspca_dev;
948 int remaining_len = len;
951 len = min(remaining_len, 2048);
953 /* Payloads are prefixed with a UVC-style header. We
954 consider a frame to start when the FID toggles, or the PTS
955 changes. A frame ends when EOF is set, and we've received
956 the correct number of bytes. */
958 /* Verify UVC header. Header length is always 12 */
959 if (data[0] != 12 || len < 12) {
960 PDEBUG(D_PACK, "bad header");
965 if (data[1] & UVC_STREAM_ERR) {
966 PDEBUG(D_PACK, "payload error");
970 /* Extract PTS and FID */
971 if (!(data[1] & UVC_STREAM_PTS)) {
972 PDEBUG(D_PACK, "PTS not present");
975 this_pts = (data[5] << 24) | (data[4] << 16)
976 | (data[3] << 8) | data[2];
977 this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0;
979 /* If PTS or FID has changed, start a new frame. */
980 if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
981 if (gspca_dev->last_packet_type == INTER_PACKET)
982 gspca_frame_add(gspca_dev, LAST_PACKET,
984 sd->last_pts = this_pts;
985 sd->last_fid = this_fid;
986 gspca_frame_add(gspca_dev, FIRST_PACKET,
987 data + 12, len - 12);
988 /* If this packet is marked as EOF, end the frame */
989 } else if (data[1] & UVC_STREAM_EOF) {
991 if (gspca_dev->image_len + len - 12 !=
992 gspca_dev->width * gspca_dev->height * 2) {
993 PDEBUG(D_PACK, "wrong sized frame");
996 gspca_frame_add(gspca_dev, LAST_PACKET,
997 data + 12, len - 12);
1000 /* Add the data from this payload */
1001 gspca_frame_add(gspca_dev, INTER_PACKET,
1002 data + 12, len - 12);
1005 /* Done this payload */
1009 /* Discard data until a new frame starts. */
1010 gspca_dev->last_packet_type = DISCARD_PACKET;
1013 remaining_len -= len;
1015 } while (remaining_len > 0);
1019 static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
1021 struct sd *sd = (struct sd *) gspca_dev;
1024 if (gspca_dev->streaming)
1029 static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
1031 struct sd *sd = (struct sd *) gspca_dev;
1037 static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
1039 struct sd *sd = (struct sd *) gspca_dev;
1042 if (gspca_dev->streaming)
1043 setexposure(gspca_dev);
1047 static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
1049 struct sd *sd = (struct sd *) gspca_dev;
1051 *val = sd->exposure;
1055 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
1057 struct sd *sd = (struct sd *) gspca_dev;
1059 sd->brightness = val;
1060 if (gspca_dev->streaming)
1061 setbrightness(gspca_dev);
1065 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
1067 struct sd *sd = (struct sd *) gspca_dev;
1069 *val = sd->brightness;
1073 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
1075 struct sd *sd = (struct sd *) gspca_dev;
1078 if (gspca_dev->streaming)
1079 setcontrast(gspca_dev);
1083 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
1085 struct sd *sd = (struct sd *) gspca_dev;
1087 *val = sd->contrast;
1091 static int sd_setagc(struct gspca_dev *gspca_dev, __s32 val)
1093 struct sd *sd = (struct sd *) gspca_dev;
1097 if (gspca_dev->streaming) {
1099 /* the auto white balance control works only
1100 * when auto gain is set */
1102 gspca_dev->ctrl_inac &= ~(1 << AWB_IDX);
1104 gspca_dev->ctrl_inac |= (1 << AWB_IDX);
1110 static int sd_getagc(struct gspca_dev *gspca_dev, __s32 *val)
1112 struct sd *sd = (struct sd *) gspca_dev;
1118 static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val)
1120 struct sd *sd = (struct sd *) gspca_dev;
1123 if (gspca_dev->streaming)
1128 static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val)
1130 struct sd *sd = (struct sd *) gspca_dev;
1136 static int sd_setaec(struct gspca_dev *gspca_dev, __s32 val)
1138 struct sd *sd = (struct sd *) gspca_dev;
1141 if (gspca_dev->streaming)
1146 static int sd_getaec(struct gspca_dev *gspca_dev, __s32 *val)
1148 struct sd *sd = (struct sd *) gspca_dev;
1154 static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
1156 struct sd *sd = (struct sd *) gspca_dev;
1158 sd->sharpness = val;
1159 if (gspca_dev->streaming)
1160 setsharpness(gspca_dev);
1164 static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
1166 struct sd *sd = (struct sd *) gspca_dev;
1168 *val = sd->sharpness;
1172 static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
1174 struct sd *sd = (struct sd *) gspca_dev;
1177 if (gspca_dev->streaming)
1178 sethflip(gspca_dev);
1182 static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
1184 struct sd *sd = (struct sd *) gspca_dev;
1190 static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
1192 struct sd *sd = (struct sd *) gspca_dev;
1195 if (gspca_dev->streaming)
1196 setvflip(gspca_dev);
1200 static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
1202 struct sd *sd = (struct sd *) gspca_dev;
1208 static int sd_setfreqfltr(struct gspca_dev *gspca_dev, __s32 val)
1210 struct sd *sd = (struct sd *) gspca_dev;
1213 if (gspca_dev->streaming)
1214 setfreqfltr(gspca_dev);
1218 static int sd_getfreqfltr(struct gspca_dev *gspca_dev, __s32 *val)
1220 struct sd *sd = (struct sd *) gspca_dev;
1222 *val = sd->freqfltr;
1226 static int sd_querymenu(struct gspca_dev *gspca_dev,
1227 struct v4l2_querymenu *menu)
1230 case V4L2_CID_POWER_LINE_FREQUENCY:
1231 switch (menu->index) {
1232 case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */
1233 strcpy((char *) menu->name, "Disabled");
1235 case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */
1236 strcpy((char *) menu->name, "50 Hz");
1245 /* get stream parameters (framerate) */
1246 static void sd_get_streamparm(struct gspca_dev *gspca_dev,
1247 struct v4l2_streamparm *parm)
1249 struct v4l2_captureparm *cp = &parm->parm.capture;
1250 struct v4l2_fract *tpf = &cp->timeperframe;
1251 struct sd *sd = (struct sd *) gspca_dev;
1253 cp->capability |= V4L2_CAP_TIMEPERFRAME;
1255 tpf->denominator = sd->frame_rate;
1258 /* set stream parameters (framerate) */
1259 static void sd_set_streamparm(struct gspca_dev *gspca_dev,
1260 struct v4l2_streamparm *parm)
1262 struct v4l2_captureparm *cp = &parm->parm.capture;
1263 struct v4l2_fract *tpf = &cp->timeperframe;
1264 struct sd *sd = (struct sd *) gspca_dev;
1266 /* Set requested framerate */
1267 sd->frame_rate = tpf->denominator / tpf->numerator;
1268 if (gspca_dev->streaming)
1269 set_frame_rate(gspca_dev);
1271 /* Return the actual framerate */
1273 tpf->denominator = sd->frame_rate;
1276 /* sub-driver description */
1277 static const struct sd_desc sd_desc = {
1278 .name = MODULE_NAME,
1280 .nctrls = ARRAY_SIZE(sd_ctrls),
1281 .config = sd_config,
1285 .pkt_scan = sd_pkt_scan,
1286 .querymenu = sd_querymenu,
1287 .get_streamparm = sd_get_streamparm,
1288 .set_streamparm = sd_set_streamparm,
1291 /* -- module initialisation -- */
1292 static const __devinitdata struct usb_device_id device_table[] = {
1293 {USB_DEVICE(0x1415, 0x2000)},
1297 MODULE_DEVICE_TABLE(usb, device_table);
1299 /* -- device connect -- */
1300 static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
1302 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
1306 static struct usb_driver sd_driver = {
1307 .name = MODULE_NAME,
1308 .id_table = device_table,
1310 .disconnect = gspca_disconnect,
1312 .suspend = gspca_suspend,
1313 .resume = gspca_resume,
1317 /* -- module insert / remove -- */
1318 static int __init sd_mod_init(void)
1320 return usb_register(&sd_driver);
1323 static void __exit sd_mod_exit(void)
1325 usb_deregister(&sd_driver);
1328 module_init(sd_mod_init);
1329 module_exit(sd_mod_exit);