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, hue, AWB control added
14 * 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);
94 static const struct ctrl sd_ctrls[] = {
97 .id = V4L2_CID_BRIGHTNESS,
98 .type = V4L2_CTRL_TYPE_INTEGER,
103 #define BRIGHTNESS_DEF 0
104 .default_value = BRIGHTNESS_DEF,
106 .set = sd_setbrightness,
107 .get = sd_getbrightness,
111 .id = V4L2_CID_CONTRAST,
112 .type = V4L2_CTRL_TYPE_INTEGER,
117 #define CONTRAST_DEF 32
118 .default_value = CONTRAST_DEF,
120 .set = sd_setcontrast,
121 .get = sd_getcontrast,
126 .type = V4L2_CTRL_TYPE_INTEGER,
132 .default_value = GAIN_DEF,
139 .id = V4L2_CID_EXPOSURE,
140 .type = V4L2_CTRL_TYPE_INTEGER,
146 .default_value = EXPO_DEF,
148 .set = sd_setexposure,
149 .get = sd_getexposure,
153 .id = V4L2_CID_AUTOGAIN,
154 .type = V4L2_CTRL_TYPE_BOOLEAN,
160 .default_value = AGC_DEF,
168 .id = V4L2_CID_AUTO_WHITE_BALANCE,
169 .type = V4L2_CTRL_TYPE_BOOLEAN,
170 .name = "Auto White Balance",
175 .default_value = AWB_DEF,
182 .id = V4L2_CID_EXPOSURE_AUTO,
183 .type = V4L2_CTRL_TYPE_BOOLEAN,
184 .name = "Auto Exposure",
189 .default_value = AEC_DEF,
196 .id = V4L2_CID_SHARPNESS,
197 .type = V4L2_CTRL_TYPE_INTEGER,
202 #define SHARPNESS_DEF 0
203 .default_value = SHARPNESS_DEF,
205 .set = sd_setsharpness,
206 .get = sd_getsharpness,
210 .id = V4L2_CID_HFLIP,
211 .type = V4L2_CTRL_TYPE_BOOLEAN,
217 .default_value = HFLIP_DEF,
224 .id = V4L2_CID_VFLIP,
225 .type = V4L2_CTRL_TYPE_BOOLEAN,
231 .default_value = VFLIP_DEF,
238 static const struct v4l2_pix_format ov772x_mode[] = {
239 {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
240 .bytesperline = 320 * 2,
241 .sizeimage = 320 * 240 * 2,
242 .colorspace = V4L2_COLORSPACE_SRGB,
244 {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
245 .bytesperline = 640 * 2,
246 .sizeimage = 640 * 480 * 2,
247 .colorspace = V4L2_COLORSPACE_SRGB,
251 static const u8 qvga_rates[] = {125, 100, 75, 60, 50, 40, 30};
252 static const u8 vga_rates[] = {60, 50, 40, 30, 15};
254 static const struct framerates ov772x_framerates[] = {
257 .nrates = ARRAY_SIZE(qvga_rates),
261 .nrates = ARRAY_SIZE(vga_rates),
265 static const u8 bridge_init[][2] = {
304 { 0x1d, 0x02 }, /* payload size 0x0200 * 4 = 2048 bytes */
305 { 0x1d, 0x00 }, /* payload size */
307 { 0x1d, 0x02 }, /* frame size 0x025800 * 4 = 614400 */
308 { 0x1d, 0x58 }, /* frame size */
309 { 0x1d, 0x00 }, /* frame size */
312 { 0x1d, 0x08 }, /* turn on UVC header */
313 { 0x1d, 0x0e }, /* .. */
323 static const u8 sensor_init[][2] = {
326 /*fixme: better have a delay?*/
349 { 0x63, 0xaa }, /* AWB - was e0 */
352 { 0x13, 0xf0 }, /* com8 */
365 { 0x13, 0xff }, /* AWB */
413 { 0x8e, 0x00 }, /* De-noise threshold */
416 static const u8 bridge_start_vga[][2] = {
427 static const u8 sensor_start_vga[][2] = {
437 static const u8 bridge_start_qvga[][2] = {
448 static const u8 sensor_start_qvga[][2] = {
459 static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val)
461 struct usb_device *udev = gspca_dev->dev;
464 PDEBUG(D_USBO, "reg=0x%04x, val=0%02x", reg, val);
465 gspca_dev->usb_buf[0] = val;
466 ret = usb_control_msg(udev,
467 usb_sndctrlpipe(udev, 0),
469 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
470 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
472 PDEBUG(D_ERR, "write failed");
475 static u8 ov534_reg_read(struct gspca_dev *gspca_dev, u16 reg)
477 struct usb_device *udev = gspca_dev->dev;
480 ret = usb_control_msg(udev,
481 usb_rcvctrlpipe(udev, 0),
483 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
484 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT);
485 PDEBUG(D_USBI, "reg=0x%04x, data=0x%02x", reg, gspca_dev->usb_buf[0]);
487 PDEBUG(D_ERR, "read failed");
488 return gspca_dev->usb_buf[0];
491 /* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
492 * (direction and output)? */
493 static void ov534_set_led(struct gspca_dev *gspca_dev, int status)
497 PDEBUG(D_CONF, "led status: %d", status);
499 data = ov534_reg_read(gspca_dev, 0x21);
501 ov534_reg_write(gspca_dev, 0x21, data);
503 data = ov534_reg_read(gspca_dev, 0x23);
509 ov534_reg_write(gspca_dev, 0x23, data);
512 data = ov534_reg_read(gspca_dev, 0x21);
514 ov534_reg_write(gspca_dev, 0x21, data);
518 static int sccb_check_status(struct gspca_dev *gspca_dev)
523 for (i = 0; i < 5; i++) {
524 data = ov534_reg_read(gspca_dev, OV534_REG_STATUS);
534 PDEBUG(D_ERR, "sccb status 0x%02x, attempt %d/5",
541 static void sccb_reg_write(struct gspca_dev *gspca_dev, u8 reg, u8 val)
543 PDEBUG(D_USBO, "reg: 0x%02x, val: 0x%02x", reg, val);
544 ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
545 ov534_reg_write(gspca_dev, OV534_REG_WRITE, val);
546 ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3);
548 if (!sccb_check_status(gspca_dev))
549 PDEBUG(D_ERR, "sccb_reg_write failed");
552 static u8 sccb_reg_read(struct gspca_dev *gspca_dev, u16 reg)
554 ov534_reg_write(gspca_dev, OV534_REG_SUBADDR, reg);
555 ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2);
556 if (!sccb_check_status(gspca_dev))
557 PDEBUG(D_ERR, "sccb_reg_read failed 1");
559 ov534_reg_write(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2);
560 if (!sccb_check_status(gspca_dev))
561 PDEBUG(D_ERR, "sccb_reg_read failed 2");
563 return ov534_reg_read(gspca_dev, OV534_REG_READ);
566 /* output a bridge sequence (reg - val) */
567 static void reg_w_array(struct gspca_dev *gspca_dev,
568 const u8 (*data)[2], int len)
571 ov534_reg_write(gspca_dev, (*data)[0], (*data)[1]);
576 /* output a sensor sequence (reg - val) */
577 static void sccb_w_array(struct gspca_dev *gspca_dev,
578 const u8 (*data)[2], int len)
581 if ((*data)[0] != 0xff) {
582 sccb_reg_write(gspca_dev, (*data)[0], (*data)[1]);
584 sccb_reg_read(gspca_dev, (*data)[1]);
585 sccb_reg_write(gspca_dev, 0xff, 0x00);
591 /* ov772x specific controls */
592 static void set_frame_rate(struct gspca_dev *gspca_dev)
594 struct sd *sd = (struct sd *) gspca_dev;
602 const struct rate_s *r;
603 static const struct rate_s rate_0[] = { /* 640x480 */
604 {60, 0x01, 0xc1, 0x04},
605 {50, 0x01, 0x41, 0x02},
606 {40, 0x02, 0xc1, 0x04},
607 {30, 0x04, 0x81, 0x02},
608 {15, 0x03, 0x41, 0x04},
610 static const struct rate_s rate_1[] = { /* 320x240 */
611 {125, 0x02, 0x81, 0x02},
612 {100, 0x02, 0xc1, 0x04},
613 {75, 0x03, 0xc1, 0x04},
614 {60, 0x04, 0xc1, 0x04},
615 {50, 0x02, 0x41, 0x04},
616 {40, 0x03, 0x41, 0x04},
617 {30, 0x04, 0x41, 0x04},
620 if (gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv == 0) {
622 i = ARRAY_SIZE(rate_0);
625 i = ARRAY_SIZE(rate_1);
628 if (sd->frame_rate >= r->fps)
633 sccb_reg_write(gspca_dev, 0x11, r->r11);
634 sccb_reg_write(gspca_dev, 0x0d, r->r0d);
635 ov534_reg_write(gspca_dev, 0xe5, r->re5);
637 PDEBUG(D_PROBE, "frame_rate: %d", r->fps);
640 static void setbrightness(struct gspca_dev *gspca_dev)
642 struct sd *sd = (struct sd *) gspca_dev;
644 sccb_reg_write(gspca_dev, 0x9b, sd->brightness);
647 static void setcontrast(struct gspca_dev *gspca_dev)
649 struct sd *sd = (struct sd *) gspca_dev;
651 sccb_reg_write(gspca_dev, 0x9c, sd->contrast);
654 static void setgain(struct gspca_dev *gspca_dev)
656 struct sd *sd = (struct sd *) gspca_dev;
663 switch (val & 0x30) {
681 sccb_reg_write(gspca_dev, 0x00, val);
684 static void setexposure(struct gspca_dev *gspca_dev)
686 struct sd *sd = (struct sd *) gspca_dev;
692 /* 'val' is one byte and represents half of the exposure value we are
693 * going to set into registers, a two bytes value:
695 * MSB: ((u16) val << 1) >> 8 == val >> 7
696 * LSB: ((u16) val << 1) & 0xff == val << 1
699 sccb_reg_write(gspca_dev, 0x08, val >> 7);
700 sccb_reg_write(gspca_dev, 0x10, val << 1);
703 static void setagc(struct gspca_dev *gspca_dev)
705 struct sd *sd = (struct sd *) gspca_dev;
708 sccb_reg_write(gspca_dev, 0x13,
709 sccb_reg_read(gspca_dev, 0x13) | 0x04);
710 sccb_reg_write(gspca_dev, 0x64,
711 sccb_reg_read(gspca_dev, 0x64) | 0x03);
713 sccb_reg_write(gspca_dev, 0x13,
714 sccb_reg_read(gspca_dev, 0x13) & ~0x04);
715 sccb_reg_write(gspca_dev, 0x64,
716 sccb_reg_read(gspca_dev, 0x64) & ~0x03);
722 static void setawb(struct gspca_dev *gspca_dev)
724 struct sd *sd = (struct sd *) gspca_dev;
727 sccb_reg_write(gspca_dev, 0x13,
728 sccb_reg_read(gspca_dev, 0x13) | 0x02);
729 sccb_reg_write(gspca_dev, 0x63,
730 sccb_reg_read(gspca_dev, 0x63) | 0xc0);
732 sccb_reg_write(gspca_dev, 0x13,
733 sccb_reg_read(gspca_dev, 0x13) & ~0x02);
734 sccb_reg_write(gspca_dev, 0x63,
735 sccb_reg_read(gspca_dev, 0x63) & ~0xc0);
739 static void setaec(struct gspca_dev *gspca_dev)
741 struct sd *sd = (struct sd *) gspca_dev;
744 sccb_reg_write(gspca_dev, 0x13,
745 sccb_reg_read(gspca_dev, 0x13) | 0x01);
747 sccb_reg_write(gspca_dev, 0x13,
748 sccb_reg_read(gspca_dev, 0x13) & ~0x01);
749 setexposure(gspca_dev);
753 static void setsharpness(struct gspca_dev *gspca_dev)
755 struct sd *sd = (struct sd *) gspca_dev;
759 sccb_reg_write(gspca_dev, 0x91, val); /* Auto de-noise threshold */
760 sccb_reg_write(gspca_dev, 0x8e, val); /* De-noise threshold */
763 static void sethflip(struct gspca_dev *gspca_dev)
765 struct sd *sd = (struct sd *) gspca_dev;
768 sccb_reg_write(gspca_dev, 0x0c,
769 sccb_reg_read(gspca_dev, 0x0c) | 0x40);
771 sccb_reg_write(gspca_dev, 0x0c,
772 sccb_reg_read(gspca_dev, 0x0c) & ~0x40);
775 static void setvflip(struct gspca_dev *gspca_dev)
777 struct sd *sd = (struct sd *) gspca_dev;
780 sccb_reg_write(gspca_dev, 0x0c,
781 sccb_reg_read(gspca_dev, 0x0c) | 0x80);
783 sccb_reg_write(gspca_dev, 0x0c,
784 sccb_reg_read(gspca_dev, 0x0c) & ~0x80);
787 /* this function is called at probe time */
788 static int sd_config(struct gspca_dev *gspca_dev,
789 const struct usb_device_id *id)
791 struct sd *sd = (struct sd *) gspca_dev;
794 cam = &gspca_dev->cam;
796 cam->cam_mode = ov772x_mode;
797 cam->nmodes = ARRAY_SIZE(ov772x_mode);
798 cam->mode_framerates = ov772x_framerates;
801 cam->bulk_size = 16384;
806 sd->brightness = BRIGHTNESS_DEF;
807 sd->contrast = CONTRAST_DEF;
809 sd->exposure = EXPO_DEF;
813 gspca_dev->ctrl_inac |= (1 << AWB_IDX);
817 sd->sharpness = SHARPNESS_DEF;
818 sd->hflip = HFLIP_DEF;
819 sd->vflip = VFLIP_DEF;
824 /* this function is called at probe and resume time */
825 static int sd_init(struct gspca_dev *gspca_dev)
830 ov534_reg_write(gspca_dev, 0xe7, 0x3a);
831 ov534_reg_write(gspca_dev, 0xe0, 0x08);
834 /* initialize the sensor address */
835 ov534_reg_write(gspca_dev, OV534_REG_ADDRESS, 0x42);
838 sccb_reg_write(gspca_dev, 0x12, 0x80);
841 /* probe the sensor */
842 sccb_reg_read(gspca_dev, 0x0a);
843 sensor_id = sccb_reg_read(gspca_dev, 0x0a) << 8;
844 sccb_reg_read(gspca_dev, 0x0b);
845 sensor_id |= sccb_reg_read(gspca_dev, 0x0b);
846 PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id);
849 reg_w_array(gspca_dev, bridge_init,
850 ARRAY_SIZE(bridge_init));
851 ov534_set_led(gspca_dev, 1);
852 sccb_w_array(gspca_dev, sensor_init,
853 ARRAY_SIZE(sensor_init));
854 ov534_reg_write(gspca_dev, 0xe0, 0x09);
855 ov534_set_led(gspca_dev, 0);
856 set_frame_rate(gspca_dev);
861 static int sd_start(struct gspca_dev *gspca_dev)
865 mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv;
866 if (mode != 0) { /* 320x240 */
867 reg_w_array(gspca_dev, bridge_start_qvga,
868 ARRAY_SIZE(bridge_start_qvga));
869 sccb_w_array(gspca_dev, sensor_start_qvga,
870 ARRAY_SIZE(sensor_start_qvga));
871 } else { /* 640x480 */
872 reg_w_array(gspca_dev, bridge_start_vga,
873 ARRAY_SIZE(bridge_start_vga));
874 sccb_w_array(gspca_dev, sensor_start_vga,
875 ARRAY_SIZE(sensor_start_vga));
877 set_frame_rate(gspca_dev);
883 setexposure(gspca_dev);
884 setbrightness(gspca_dev);
885 setcontrast(gspca_dev);
886 setsharpness(gspca_dev);
890 ov534_set_led(gspca_dev, 1);
891 ov534_reg_write(gspca_dev, 0xe0, 0x00);
895 static void sd_stopN(struct gspca_dev *gspca_dev)
897 ov534_reg_write(gspca_dev, 0xe0, 0x09);
898 ov534_set_led(gspca_dev, 0);
901 /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
902 #define UVC_STREAM_EOH (1 << 7)
903 #define UVC_STREAM_ERR (1 << 6)
904 #define UVC_STREAM_STI (1 << 5)
905 #define UVC_STREAM_RES (1 << 4)
906 #define UVC_STREAM_SCR (1 << 3)
907 #define UVC_STREAM_PTS (1 << 2)
908 #define UVC_STREAM_EOF (1 << 1)
909 #define UVC_STREAM_FID (1 << 0)
911 static void sd_pkt_scan(struct gspca_dev *gspca_dev,
914 struct sd *sd = (struct sd *) gspca_dev;
917 int remaining_len = len;
920 len = min(remaining_len, 2048);
922 /* Payloads are prefixed with a UVC-style header. We
923 consider a frame to start when the FID toggles, or the PTS
924 changes. A frame ends when EOF is set, and we've received
925 the correct number of bytes. */
927 /* Verify UVC header. Header length is always 12 */
928 if (data[0] != 12 || len < 12) {
929 PDEBUG(D_PACK, "bad header");
934 if (data[1] & UVC_STREAM_ERR) {
935 PDEBUG(D_PACK, "payload error");
939 /* Extract PTS and FID */
940 if (!(data[1] & UVC_STREAM_PTS)) {
941 PDEBUG(D_PACK, "PTS not present");
944 this_pts = (data[5] << 24) | (data[4] << 16)
945 | (data[3] << 8) | data[2];
946 this_fid = (data[1] & UVC_STREAM_FID) ? 1 : 0;
948 /* If PTS or FID has changed, start a new frame. */
949 if (this_pts != sd->last_pts || this_fid != sd->last_fid) {
950 if (gspca_dev->last_packet_type == INTER_PACKET)
951 gspca_frame_add(gspca_dev, LAST_PACKET,
953 sd->last_pts = this_pts;
954 sd->last_fid = this_fid;
955 gspca_frame_add(gspca_dev, FIRST_PACKET,
956 data + 12, len - 12);
957 /* If this packet is marked as EOF, end the frame */
958 } else if (data[1] & UVC_STREAM_EOF) {
959 struct gspca_frame *frame;
962 frame = gspca_get_i_frame(gspca_dev);
965 if (frame->data_end - frame->data + (len - 12) !=
966 gspca_dev->width * gspca_dev->height * 2) {
967 PDEBUG(D_PACK, "wrong sized frame");
970 gspca_frame_add(gspca_dev, LAST_PACKET,
971 data + 12, len - 12);
974 /* Add the data from this payload */
975 gspca_frame_add(gspca_dev, INTER_PACKET,
976 data + 12, len - 12);
979 /* Done this payload */
983 /* Discard data until a new frame starts. */
984 gspca_dev->last_packet_type = DISCARD_PACKET;
987 remaining_len -= len;
989 } while (remaining_len > 0);
993 static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val)
995 struct sd *sd = (struct sd *) gspca_dev;
998 if (gspca_dev->streaming)
1003 static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val)
1005 struct sd *sd = (struct sd *) gspca_dev;
1011 static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val)
1013 struct sd *sd = (struct sd *) gspca_dev;
1016 if (gspca_dev->streaming)
1017 setexposure(gspca_dev);
1021 static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val)
1023 struct sd *sd = (struct sd *) gspca_dev;
1025 *val = sd->exposure;
1029 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
1031 struct sd *sd = (struct sd *) gspca_dev;
1033 sd->brightness = val;
1034 if (gspca_dev->streaming)
1035 setbrightness(gspca_dev);
1039 static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val)
1041 struct sd *sd = (struct sd *) gspca_dev;
1043 *val = sd->brightness;
1047 static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
1049 struct sd *sd = (struct sd *) gspca_dev;
1052 if (gspca_dev->streaming)
1053 setcontrast(gspca_dev);
1057 static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
1059 struct sd *sd = (struct sd *) gspca_dev;
1061 *val = sd->contrast;
1065 static int sd_setagc(struct gspca_dev *gspca_dev, __s32 val)
1067 struct sd *sd = (struct sd *) gspca_dev;
1071 if (gspca_dev->streaming) {
1073 /* the auto white balance control works only
1074 * when auto gain is set */
1076 gspca_dev->ctrl_inac &= ~(1 << AWB_IDX);
1078 gspca_dev->ctrl_inac |= (1 << AWB_IDX);
1084 static int sd_getagc(struct gspca_dev *gspca_dev, __s32 *val)
1086 struct sd *sd = (struct sd *) gspca_dev;
1092 static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val)
1094 struct sd *sd = (struct sd *) gspca_dev;
1097 if (gspca_dev->streaming)
1102 static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val)
1104 struct sd *sd = (struct sd *) gspca_dev;
1110 static int sd_setaec(struct gspca_dev *gspca_dev, __s32 val)
1112 struct sd *sd = (struct sd *) gspca_dev;
1115 if (gspca_dev->streaming)
1120 static int sd_getaec(struct gspca_dev *gspca_dev, __s32 *val)
1122 struct sd *sd = (struct sd *) gspca_dev;
1128 static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val)
1130 struct sd *sd = (struct sd *) gspca_dev;
1132 sd->sharpness = val;
1133 if (gspca_dev->streaming)
1134 setsharpness(gspca_dev);
1138 static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val)
1140 struct sd *sd = (struct sd *) gspca_dev;
1142 *val = sd->sharpness;
1146 static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val)
1148 struct sd *sd = (struct sd *) gspca_dev;
1151 if (gspca_dev->streaming)
1152 sethflip(gspca_dev);
1156 static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val)
1158 struct sd *sd = (struct sd *) gspca_dev;
1164 static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
1166 struct sd *sd = (struct sd *) gspca_dev;
1169 if (gspca_dev->streaming)
1170 setvflip(gspca_dev);
1174 static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
1176 struct sd *sd = (struct sd *) gspca_dev;
1182 /* get stream parameters (framerate) */
1183 static int sd_get_streamparm(struct gspca_dev *gspca_dev,
1184 struct v4l2_streamparm *parm)
1186 struct v4l2_captureparm *cp = &parm->parm.capture;
1187 struct v4l2_fract *tpf = &cp->timeperframe;
1188 struct sd *sd = (struct sd *) gspca_dev;
1190 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1193 cp->capability |= V4L2_CAP_TIMEPERFRAME;
1195 tpf->denominator = sd->frame_rate;
1200 /* set stream parameters (framerate) */
1201 static int sd_set_streamparm(struct gspca_dev *gspca_dev,
1202 struct v4l2_streamparm *parm)
1204 struct v4l2_captureparm *cp = &parm->parm.capture;
1205 struct v4l2_fract *tpf = &cp->timeperframe;
1206 struct sd *sd = (struct sd *) gspca_dev;
1208 if (parm->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1211 /* Set requested framerate */
1212 sd->frame_rate = tpf->denominator / tpf->numerator;
1213 if (gspca_dev->streaming)
1214 set_frame_rate(gspca_dev);
1216 /* Return the actual framerate */
1218 tpf->denominator = sd->frame_rate;
1223 /* sub-driver description */
1224 static const struct sd_desc sd_desc = {
1225 .name = MODULE_NAME,
1227 .nctrls = ARRAY_SIZE(sd_ctrls),
1228 .config = sd_config,
1232 .pkt_scan = sd_pkt_scan,
1233 .get_streamparm = sd_get_streamparm,
1234 .set_streamparm = sd_set_streamparm,
1237 /* -- module initialisation -- */
1238 static const __devinitdata struct usb_device_id device_table[] = {
1239 {USB_DEVICE(0x1415, 0x2000)},
1243 MODULE_DEVICE_TABLE(usb, device_table);
1245 /* -- device connect -- */
1246 static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id)
1248 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
1252 static struct usb_driver sd_driver = {
1253 .name = MODULE_NAME,
1254 .id_table = device_table,
1256 .disconnect = gspca_disconnect,
1258 .suspend = gspca_suspend,
1259 .resume = gspca_resume,
1263 /* -- module insert / remove -- */
1264 static int __init sd_mod_init(void)
1268 ret = usb_register(&sd_driver);
1271 PDEBUG(D_PROBE, "registered");
1275 static void __exit sd_mod_exit(void)
1277 usb_deregister(&sd_driver);
1278 PDEBUG(D_PROBE, "deregistered");
1281 module_init(sd_mod_init);
1282 module_exit(sd_mod_exit);