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 */
74 /* V4L2 controls supported by the driver */
75 static int sd_setgain(struct gspca_dev
*gspca_dev
, __s32 val
);
76 static int sd_getgain(struct gspca_dev
*gspca_dev
, __s32
*val
);
77 static int sd_setexposure(struct gspca_dev
*gspca_dev
, __s32 val
);
78 static int sd_getexposure(struct gspca_dev
*gspca_dev
, __s32
*val
);
79 static int sd_setredblc(struct gspca_dev
*gspca_dev
, __s32 val
);
80 static int sd_getredblc(struct gspca_dev
*gspca_dev
, __s32
*val
);
81 static int sd_setblueblc(struct gspca_dev
*gspca_dev
, __s32 val
);
82 static int sd_getblueblc(struct gspca_dev
*gspca_dev
, __s32
*val
);
83 static int sd_setautogain(struct gspca_dev
*gspca_dev
, __s32 val
);
84 static int sd_getautogain(struct gspca_dev
*gspca_dev
, __s32
*val
);
85 static int sd_setsharpness(struct gspca_dev
*gspca_dev
, __s32 val
);
86 static int sd_getsharpness(struct gspca_dev
*gspca_dev
, __s32
*val
);
87 static int sd_sethflip(struct gspca_dev
*gspca_dev
, __s32 val
);
88 static int sd_gethflip(struct gspca_dev
*gspca_dev
, __s32
*val
);
89 static int sd_setvflip(struct gspca_dev
*gspca_dev
, __s32 val
);
90 static int sd_getvflip(struct gspca_dev
*gspca_dev
, __s32
*val
);
91 static int sd_sethue(struct gspca_dev
*gspca_dev
, __s32 val
);
92 static int sd_gethue(struct gspca_dev
*gspca_dev
, __s32
*val
);
93 static int sd_setawb(struct gspca_dev
*gspca_dev
, __s32 val
);
94 static int sd_getawb(struct gspca_dev
*gspca_dev
, __s32
*val
);
95 static int sd_setbrightness(struct gspca_dev
*gspca_dev
, __s32 val
);
96 static int sd_getbrightness(struct gspca_dev
*gspca_dev
, __s32
*val
);
97 static int sd_setcontrast(struct gspca_dev
*gspca_dev
, __s32 val
);
98 static int sd_getcontrast(struct gspca_dev
*gspca_dev
, __s32
*val
);
100 static const struct ctrl sd_ctrls
[] = {
103 .id
= V4L2_CID_BRIGHTNESS
,
104 .type
= V4L2_CTRL_TYPE_INTEGER
,
105 .name
= "Brightness",
109 #define BRIGHTNESS_DEF 20
110 .default_value
= BRIGHTNESS_DEF
,
112 .set
= sd_setbrightness
,
113 .get
= sd_getbrightness
,
117 .id
= V4L2_CID_CONTRAST
,
118 .type
= V4L2_CTRL_TYPE_INTEGER
,
123 #define CONTRAST_DEF 37
124 .default_value
= CONTRAST_DEF
,
126 .set
= sd_setcontrast
,
127 .get
= sd_getcontrast
,
132 .type
= V4L2_CTRL_TYPE_INTEGER
,
138 .default_value
= GAIN_DEF
,
145 .id
= V4L2_CID_EXPOSURE
,
146 .type
= V4L2_CTRL_TYPE_INTEGER
,
152 .default_value
= EXPO_DEF
,
154 .set
= sd_setexposure
,
155 .get
= sd_getexposure
,
159 .id
= V4L2_CID_RED_BALANCE
,
160 .type
= V4L2_CTRL_TYPE_INTEGER
,
161 .name
= "Red Balance",
165 #define RED_BALANCE_DEF 128
166 .default_value
= RED_BALANCE_DEF
,
173 .id
= V4L2_CID_BLUE_BALANCE
,
174 .type
= V4L2_CTRL_TYPE_INTEGER
,
175 .name
= "Blue Balance",
179 #define BLUE_BALANCE_DEF 128
180 .default_value
= BLUE_BALANCE_DEF
,
182 .set
= sd_setblueblc
,
183 .get
= sd_getblueblc
,
188 .type
= V4L2_CTRL_TYPE_INTEGER
,
194 .default_value
= HUE_DEF
,
201 .id
= V4L2_CID_AUTOGAIN
,
202 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
207 #define AUTOGAIN_DEF 0
208 .default_value
= AUTOGAIN_DEF
,
210 .set
= sd_setautogain
,
211 .get
= sd_getautogain
,
216 .id
= V4L2_CID_AUTO_WHITE_BALANCE
,
217 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
218 .name
= "Auto White Balance",
223 .default_value
= AWB_DEF
,
230 .id
= V4L2_CID_SHARPNESS
,
231 .type
= V4L2_CTRL_TYPE_INTEGER
,
236 #define SHARPNESS_DEF 0
237 .default_value
= SHARPNESS_DEF
,
239 .set
= sd_setsharpness
,
240 .get
= sd_getsharpness
,
244 .id
= V4L2_CID_HFLIP
,
245 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
251 .default_value
= HFLIP_DEF
,
258 .id
= V4L2_CID_VFLIP
,
259 .type
= V4L2_CTRL_TYPE_BOOLEAN
,
265 .default_value
= VFLIP_DEF
,
272 static const struct v4l2_pix_format ov772x_mode
[] = {
273 {320, 240, V4L2_PIX_FMT_YUYV
, V4L2_FIELD_NONE
,
274 .bytesperline
= 320 * 2,
275 .sizeimage
= 320 * 240 * 2,
276 .colorspace
= V4L2_COLORSPACE_SRGB
,
278 {640, 480, V4L2_PIX_FMT_YUYV
, V4L2_FIELD_NONE
,
279 .bytesperline
= 640 * 2,
280 .sizeimage
= 640 * 480 * 2,
281 .colorspace
= V4L2_COLORSPACE_SRGB
,
285 static const u8 qvga_rates
[] = {125, 100, 75, 60, 50, 40, 30};
286 static const u8 vga_rates
[] = {60, 50, 40, 30, 15};
288 static const struct framerates ov772x_framerates
[] = {
291 .nrates
= ARRAY_SIZE(qvga_rates
),
295 .nrates
= ARRAY_SIZE(vga_rates
),
299 static const u8 bridge_init
[][2] = {
338 { 0x1d, 0x02 }, /* payload size 0x0200 * 4 = 2048 bytes */
339 { 0x1d, 0x00 }, /* payload size */
341 { 0x1d, 0x02 }, /* frame size 0x025800 * 4 = 614400 */
342 { 0x1d, 0x58 }, /* frame size */
343 { 0x1d, 0x00 }, /* frame size */
346 { 0x1d, 0x08 }, /* turn on UVC header */
347 { 0x1d, 0x0e }, /* .. */
357 static const u8 sensor_init
[][2] = {
360 /*fixme: better have a delay?*/
383 { 0x63, 0xaa }, /* AWB - was e0 */
386 { 0x13, 0xf0 }, /* com8 */
399 { 0x13, 0xff }, /* AWB */
447 { 0x8e, 0x00 }, /* De-noise threshold */
450 static const u8 bridge_start_vga
[][2] = {
461 static const u8 sensor_start_vga
[][2] = {
471 static const u8 bridge_start_qvga
[][2] = {
482 static const u8 sensor_start_qvga
[][2] = {
493 static void ov534_reg_write(struct gspca_dev
*gspca_dev
, u16 reg
, u8 val
)
495 struct usb_device
*udev
= gspca_dev
->dev
;
498 PDEBUG(D_USBO
, "reg=0x%04x, val=0%02x", reg
, val
);
499 gspca_dev
->usb_buf
[0] = val
;
500 ret
= usb_control_msg(udev
,
501 usb_sndctrlpipe(udev
, 0),
503 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
504 0x00, reg
, gspca_dev
->usb_buf
, 1, CTRL_TIMEOUT
);
506 PDEBUG(D_ERR
, "write failed");
509 static u8
ov534_reg_read(struct gspca_dev
*gspca_dev
, u16 reg
)
511 struct usb_device
*udev
= gspca_dev
->dev
;
514 ret
= usb_control_msg(udev
,
515 usb_rcvctrlpipe(udev
, 0),
517 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
518 0x00, reg
, gspca_dev
->usb_buf
, 1, CTRL_TIMEOUT
);
519 PDEBUG(D_USBI
, "reg=0x%04x, data=0x%02x", reg
, gspca_dev
->usb_buf
[0]);
521 PDEBUG(D_ERR
, "read failed");
522 return gspca_dev
->usb_buf
[0];
525 /* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
526 * (direction and output)? */
527 static void ov534_set_led(struct gspca_dev
*gspca_dev
, int status
)
531 PDEBUG(D_CONF
, "led status: %d", status
);
533 data
= ov534_reg_read(gspca_dev
, 0x21);
535 ov534_reg_write(gspca_dev
, 0x21, data
);
537 data
= ov534_reg_read(gspca_dev
, 0x23);
543 ov534_reg_write(gspca_dev
, 0x23, data
);
546 data
= ov534_reg_read(gspca_dev
, 0x21);
548 ov534_reg_write(gspca_dev
, 0x21, data
);
552 static int sccb_check_status(struct gspca_dev
*gspca_dev
)
557 for (i
= 0; i
< 5; i
++) {
558 data
= ov534_reg_read(gspca_dev
, OV534_REG_STATUS
);
568 PDEBUG(D_ERR
, "sccb status 0x%02x, attempt %d/5",
575 static void sccb_reg_write(struct gspca_dev
*gspca_dev
, u8 reg
, u8 val
)
577 PDEBUG(D_USBO
, "reg: 0x%02x, val: 0x%02x", reg
, val
);
578 ov534_reg_write(gspca_dev
, OV534_REG_SUBADDR
, reg
);
579 ov534_reg_write(gspca_dev
, OV534_REG_WRITE
, val
);
580 ov534_reg_write(gspca_dev
, OV534_REG_OPERATION
, OV534_OP_WRITE_3
);
582 if (!sccb_check_status(gspca_dev
))
583 PDEBUG(D_ERR
, "sccb_reg_write failed");
586 static u8
sccb_reg_read(struct gspca_dev
*gspca_dev
, u16 reg
)
588 ov534_reg_write(gspca_dev
, OV534_REG_SUBADDR
, reg
);
589 ov534_reg_write(gspca_dev
, OV534_REG_OPERATION
, OV534_OP_WRITE_2
);
590 if (!sccb_check_status(gspca_dev
))
591 PDEBUG(D_ERR
, "sccb_reg_read failed 1");
593 ov534_reg_write(gspca_dev
, OV534_REG_OPERATION
, OV534_OP_READ_2
);
594 if (!sccb_check_status(gspca_dev
))
595 PDEBUG(D_ERR
, "sccb_reg_read failed 2");
597 return ov534_reg_read(gspca_dev
, OV534_REG_READ
);
600 /* output a bridge sequence (reg - val) */
601 static void reg_w_array(struct gspca_dev
*gspca_dev
,
602 const u8 (*data
)[2], int len
)
605 ov534_reg_write(gspca_dev
, (*data
)[0], (*data
)[1]);
610 /* output a sensor sequence (reg - val) */
611 static void sccb_w_array(struct gspca_dev
*gspca_dev
,
612 const u8 (*data
)[2], int len
)
615 if ((*data
)[0] != 0xff) {
616 sccb_reg_write(gspca_dev
, (*data
)[0], (*data
)[1]);
618 sccb_reg_read(gspca_dev
, (*data
)[1]);
619 sccb_reg_write(gspca_dev
, 0xff, 0x00);
625 /* ov772x specific controls */
626 static void set_frame_rate(struct gspca_dev
*gspca_dev
)
628 struct sd
*sd
= (struct sd
*) gspca_dev
;
636 const struct rate_s
*r
;
637 static const struct rate_s rate_0
[] = { /* 640x480 */
638 {60, 0x01, 0xc1, 0x04},
639 {50, 0x01, 0x41, 0x02},
640 {40, 0x02, 0xc1, 0x04},
641 {30, 0x04, 0x81, 0x02},
642 {15, 0x03, 0x41, 0x04},
644 static const struct rate_s rate_1
[] = { /* 320x240 */
645 {125, 0x02, 0x81, 0x02},
646 {100, 0x02, 0xc1, 0x04},
647 {75, 0x03, 0xc1, 0x04},
648 {60, 0x04, 0xc1, 0x04},
649 {50, 0x02, 0x41, 0x04},
650 {40, 0x03, 0x41, 0x04},
651 {30, 0x04, 0x41, 0x04},
654 if (gspca_dev
->cam
.cam_mode
[gspca_dev
->curr_mode
].priv
== 0) {
656 i
= ARRAY_SIZE(rate_0
);
659 i
= ARRAY_SIZE(rate_1
);
662 if (sd
->frame_rate
>= r
->fps
)
667 sccb_reg_write(gspca_dev
, 0x11, r
->r11
);
668 sccb_reg_write(gspca_dev
, 0x0d, r
->r0d
);
669 ov534_reg_write(gspca_dev
, 0xe5, r
->re5
);
671 PDEBUG(D_PROBE
, "frame_rate: %d", r
->fps
);
674 static void setbrightness(struct gspca_dev
*gspca_dev
)
676 struct sd
*sd
= (struct sd
*) gspca_dev
;
678 sccb_reg_write(gspca_dev
, 0x9B, sd
->brightness
);
681 static void setcontrast(struct gspca_dev
*gspca_dev
)
683 struct sd
*sd
= (struct sd
*) gspca_dev
;
685 sccb_reg_write(gspca_dev
, 0x9C, sd
->contrast
);
688 static void setgain(struct gspca_dev
*gspca_dev
)
690 struct sd
*sd
= (struct sd
*) gspca_dev
;
694 switch (val
& 0x30) {
712 sccb_reg_write(gspca_dev
, 0x00, val
);
715 static void setexposure(struct gspca_dev
*gspca_dev
)
717 struct sd
*sd
= (struct sd
*) gspca_dev
;
721 sccb_reg_write(gspca_dev
, 0x08, val
>> 7);
722 sccb_reg_write(gspca_dev
, 0x10, val
<< 1);
725 static void setredblc(struct gspca_dev
*gspca_dev
)
727 struct sd
*sd
= (struct sd
*) gspca_dev
;
729 sccb_reg_write(gspca_dev
, 0x43, sd
->redblc
);
732 static void setblueblc(struct gspca_dev
*gspca_dev
)
734 struct sd
*sd
= (struct sd
*) gspca_dev
;
736 sccb_reg_write(gspca_dev
, 0x42, sd
->blueblc
);
739 static void sethue(struct gspca_dev
*gspca_dev
)
741 struct sd
*sd
= (struct sd
*) gspca_dev
;
743 sccb_reg_write(gspca_dev
, 0x01, sd
->hue
);
746 static void setautogain(struct gspca_dev
*gspca_dev
)
748 struct sd
*sd
= (struct sd
*) gspca_dev
;
751 sccb_reg_write(gspca_dev
, 0x13, 0xf7); /* AGC,AEC,AWB ON */
752 sccb_reg_write(gspca_dev
, 0x64,
753 sccb_reg_read(gspca_dev
, 0x64) | 0x03);
755 sccb_reg_write(gspca_dev
, 0x13, 0xf0); /* AGC,AEC,AWB OFF */
756 sccb_reg_write(gspca_dev
, 0x64,
757 sccb_reg_read(gspca_dev
, 0x64) & 0xfc);
761 static void setawb(struct gspca_dev
*gspca_dev
)
763 struct sd
*sd
= (struct sd
*) gspca_dev
;
766 sccb_reg_write(gspca_dev
, 0x63, 0xe0); /* AWB on */
768 sccb_reg_write(gspca_dev
, 0x63, 0xaa); /* AWB off */
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
); /* vga noise */
778 sccb_reg_write(gspca_dev
, 0x8e, val
); /* qvga noise */
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) & 0xbf);
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) & 0x7f);
805 /* this function is called at probe time */
806 static int sd_config(struct gspca_dev
*gspca_dev
,
807 const struct usb_device_id
*id
)
809 struct sd
*sd
= (struct sd
*) gspca_dev
;
812 cam
= &gspca_dev
->cam
;
814 cam
->cam_mode
= ov772x_mode
;
815 cam
->nmodes
= ARRAY_SIZE(ov772x_mode
);
816 cam
->mode_framerates
= ov772x_framerates
;
819 cam
->bulk_size
= 16384;
824 sd
->brightness
= BRIGHTNESS_DEF
;
825 sd
->contrast
= CONTRAST_DEF
;
827 sd
->exposure
= EXPO_DEF
;
828 sd
->redblc
= RED_BALANCE_DEF
;
829 sd
->blueblc
= BLUE_BALANCE_DEF
;
831 #if AUTOGAIN_DEF != 0
832 sd
->autogain
= AUTOGAIN_DEF
;
834 gspca_dev
->ctrl_inac
|= (1 << AWB_IDX
);
839 #if SHARPNESS_DEF != 0
840 sd
->sharpness
= SHARPNESS_DEF
;
843 sd
->hflip
= HFLIP_DEF
;
846 sd
->vflip
= VFLIP_DEF
;
852 /* this function is called at probe and resume time */
853 static int sd_init(struct gspca_dev
*gspca_dev
)
858 ov534_reg_write(gspca_dev
, 0xe7, 0x3a);
859 ov534_reg_write(gspca_dev
, 0xe0, 0x08);
862 /* initialize the sensor address */
863 ov534_reg_write(gspca_dev
, OV534_REG_ADDRESS
, 0x42);
866 sccb_reg_write(gspca_dev
, 0x12, 0x80);
869 /* probe the sensor */
870 sccb_reg_read(gspca_dev
, 0x0a);
871 sensor_id
= sccb_reg_read(gspca_dev
, 0x0a) << 8;
872 sccb_reg_read(gspca_dev
, 0x0b);
873 sensor_id
|= sccb_reg_read(gspca_dev
, 0x0b);
874 PDEBUG(D_PROBE
, "Sensor ID: %04x", sensor_id
);
877 reg_w_array(gspca_dev
, bridge_init
,
878 ARRAY_SIZE(bridge_init
));
879 ov534_set_led(gspca_dev
, 1);
880 sccb_w_array(gspca_dev
, sensor_init
,
881 ARRAY_SIZE(sensor_init
));
882 ov534_reg_write(gspca_dev
, 0xe0, 0x09);
883 ov534_set_led(gspca_dev
, 0);
884 set_frame_rate(gspca_dev
);
889 static int sd_start(struct gspca_dev
*gspca_dev
)
893 mode
= gspca_dev
->cam
.cam_mode
[gspca_dev
->curr_mode
].priv
;
894 if (mode
!= 0) { /* 320x240 */
895 reg_w_array(gspca_dev
, bridge_start_qvga
,
896 ARRAY_SIZE(bridge_start_qvga
));
897 sccb_w_array(gspca_dev
, sensor_start_qvga
,
898 ARRAY_SIZE(sensor_start_qvga
));
899 } else { /* 640x480 */
900 reg_w_array(gspca_dev
, bridge_start_vga
,
901 ARRAY_SIZE(bridge_start_vga
));
902 sccb_w_array(gspca_dev
, sensor_start_vga
,
903 ARRAY_SIZE(sensor_start_vga
));
905 set_frame_rate(gspca_dev
);
907 setautogain(gspca_dev
);
910 setredblc(gspca_dev
);
911 setblueblc(gspca_dev
);
913 setexposure(gspca_dev
);
914 setbrightness(gspca_dev
);
915 setcontrast(gspca_dev
);
916 setsharpness(gspca_dev
);
920 ov534_set_led(gspca_dev
, 1);
921 ov534_reg_write(gspca_dev
, 0xe0, 0x00);
925 static void sd_stopN(struct gspca_dev
*gspca_dev
)
927 ov534_reg_write(gspca_dev
, 0xe0, 0x09);
928 ov534_set_led(gspca_dev
, 0);
931 /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
932 #define UVC_STREAM_EOH (1 << 7)
933 #define UVC_STREAM_ERR (1 << 6)
934 #define UVC_STREAM_STI (1 << 5)
935 #define UVC_STREAM_RES (1 << 4)
936 #define UVC_STREAM_SCR (1 << 3)
937 #define UVC_STREAM_PTS (1 << 2)
938 #define UVC_STREAM_EOF (1 << 1)
939 #define UVC_STREAM_FID (1 << 0)
941 static void sd_pkt_scan(struct gspca_dev
*gspca_dev
,
944 struct sd
*sd
= (struct sd
*) gspca_dev
;
947 int remaining_len
= len
;
950 len
= min(remaining_len
, 2048);
952 /* Payloads are prefixed with a UVC-style header. We
953 consider a frame to start when the FID toggles, or the PTS
954 changes. A frame ends when EOF is set, and we've received
955 the correct number of bytes. */
957 /* Verify UVC header. Header length is always 12 */
958 if (data
[0] != 12 || len
< 12) {
959 PDEBUG(D_PACK
, "bad header");
964 if (data
[1] & UVC_STREAM_ERR
) {
965 PDEBUG(D_PACK
, "payload error");
969 /* Extract PTS and FID */
970 if (!(data
[1] & UVC_STREAM_PTS
)) {
971 PDEBUG(D_PACK
, "PTS not present");
974 this_pts
= (data
[5] << 24) | (data
[4] << 16)
975 | (data
[3] << 8) | data
[2];
976 this_fid
= (data
[1] & UVC_STREAM_FID
) ? 1 : 0;
978 /* If PTS or FID has changed, start a new frame. */
979 if (this_pts
!= sd
->last_pts
|| this_fid
!= sd
->last_fid
) {
980 if (gspca_dev
->last_packet_type
== INTER_PACKET
)
981 gspca_frame_add(gspca_dev
, LAST_PACKET
,
983 sd
->last_pts
= this_pts
;
984 sd
->last_fid
= this_fid
;
985 gspca_frame_add(gspca_dev
, FIRST_PACKET
,
986 data
+ 12, len
- 12);
987 /* If this packet is marked as EOF, end the frame */
988 } else if (data
[1] & UVC_STREAM_EOF
) {
989 struct gspca_frame
*frame
;
992 frame
= gspca_get_i_frame(gspca_dev
);
995 if (frame
->data_end
- frame
->data
+ (len
- 12) !=
996 gspca_dev
->width
* gspca_dev
->height
* 2) {
997 PDEBUG(D_PACK
, "wrong sized frame");
1000 gspca_frame_add(gspca_dev
, LAST_PACKET
,
1001 data
+ 12, len
- 12);
1004 /* Add the data from this payload */
1005 gspca_frame_add(gspca_dev
, INTER_PACKET
,
1006 data
+ 12, len
- 12);
1009 /* Done this payload */
1013 /* Discard data until a new frame starts. */
1014 gspca_dev
->last_packet_type
= DISCARD_PACKET
;
1017 remaining_len
-= len
;
1019 } while (remaining_len
> 0);
1023 static int sd_setgain(struct gspca_dev
*gspca_dev
, __s32 val
)
1025 struct sd
*sd
= (struct sd
*) gspca_dev
;
1028 if (gspca_dev
->streaming
)
1033 static int sd_getgain(struct gspca_dev
*gspca_dev
, __s32
*val
)
1035 struct sd
*sd
= (struct sd
*) gspca_dev
;
1041 static int sd_setexposure(struct gspca_dev
*gspca_dev
, __s32 val
)
1043 struct sd
*sd
= (struct sd
*) gspca_dev
;
1046 if (gspca_dev
->streaming
)
1047 setexposure(gspca_dev
);
1051 static int sd_getexposure(struct gspca_dev
*gspca_dev
, __s32
*val
)
1053 struct sd
*sd
= (struct sd
*) gspca_dev
;
1055 *val
= sd
->exposure
;
1059 static int sd_setbrightness(struct gspca_dev
*gspca_dev
, __s32 val
)
1061 struct sd
*sd
= (struct sd
*) gspca_dev
;
1063 sd
->brightness
= val
;
1064 if (gspca_dev
->streaming
)
1065 setbrightness(gspca_dev
);
1069 static int sd_getbrightness(struct gspca_dev
*gspca_dev
, __s32
*val
)
1071 struct sd
*sd
= (struct sd
*) gspca_dev
;
1073 *val
= sd
->brightness
;
1077 static int sd_setcontrast(struct gspca_dev
*gspca_dev
, __s32 val
)
1079 struct sd
*sd
= (struct sd
*) gspca_dev
;
1082 if (gspca_dev
->streaming
)
1083 setcontrast(gspca_dev
);
1087 static int sd_getcontrast(struct gspca_dev
*gspca_dev
, __s32
*val
)
1089 struct sd
*sd
= (struct sd
*) gspca_dev
;
1091 *val
= sd
->contrast
;
1095 static int sd_setredblc(struct gspca_dev
*gspca_dev
, __s32 val
)
1097 struct sd
*sd
= (struct sd
*) gspca_dev
;
1100 if (gspca_dev
->streaming
)
1101 setredblc(gspca_dev
);
1105 static int sd_getredblc(struct gspca_dev
*gspca_dev
, __s32
*val
)
1107 struct sd
*sd
= (struct sd
*) gspca_dev
;
1113 static int sd_setblueblc(struct gspca_dev
*gspca_dev
, __s32 val
)
1115 struct sd
*sd
= (struct sd
*) gspca_dev
;
1118 if (gspca_dev
->streaming
)
1119 setblueblc(gspca_dev
);
1123 static int sd_getblueblc(struct gspca_dev
*gspca_dev
, __s32
*val
)
1125 struct sd
*sd
= (struct sd
*) gspca_dev
;
1131 static int sd_sethue(struct gspca_dev
*gspca_dev
, __s32 val
)
1133 struct sd
*sd
= (struct sd
*) gspca_dev
;
1136 if (gspca_dev
->streaming
)
1141 static int sd_gethue(struct gspca_dev
*gspca_dev
, __s32
*val
)
1143 struct sd
*sd
= (struct sd
*) gspca_dev
;
1149 static int sd_setautogain(struct gspca_dev
*gspca_dev
, __s32 val
)
1151 struct sd
*sd
= (struct sd
*) gspca_dev
;
1155 if (gspca_dev
->streaming
) {
1157 /* the auto white balance control works only
1158 * when auto gain is set */
1160 gspca_dev
->ctrl_inac
&= ~(1 << AWB_IDX
);
1162 gspca_dev
->ctrl_inac
|= (1 << AWB_IDX
);
1163 setautogain(gspca_dev
);
1168 static int sd_getautogain(struct gspca_dev
*gspca_dev
, __s32
*val
)
1170 struct sd
*sd
= (struct sd
*) gspca_dev
;
1172 *val
= sd
->autogain
;
1176 static int sd_setawb(struct gspca_dev
*gspca_dev
, __s32 val
)
1178 struct sd
*sd
= (struct sd
*) gspca_dev
;
1181 if (gspca_dev
->streaming
)
1186 static int sd_getawb(struct gspca_dev
*gspca_dev
, __s32
*val
)
1188 struct sd
*sd
= (struct sd
*) gspca_dev
;
1194 static int sd_setsharpness(struct gspca_dev
*gspca_dev
, __s32 val
)
1196 struct sd
*sd
= (struct sd
*) gspca_dev
;
1198 sd
->sharpness
= val
;
1199 if (gspca_dev
->streaming
)
1200 setsharpness(gspca_dev
);
1204 static int sd_getsharpness(struct gspca_dev
*gspca_dev
, __s32
*val
)
1206 struct sd
*sd
= (struct sd
*) gspca_dev
;
1208 *val
= sd
->sharpness
;
1212 static int sd_sethflip(struct gspca_dev
*gspca_dev
, __s32 val
)
1214 struct sd
*sd
= (struct sd
*) gspca_dev
;
1217 if (gspca_dev
->streaming
)
1218 sethflip(gspca_dev
);
1222 static int sd_gethflip(struct gspca_dev
*gspca_dev
, __s32
*val
)
1224 struct sd
*sd
= (struct sd
*) gspca_dev
;
1230 static int sd_setvflip(struct gspca_dev
*gspca_dev
, __s32 val
)
1232 struct sd
*sd
= (struct sd
*) gspca_dev
;
1235 if (gspca_dev
->streaming
)
1236 setvflip(gspca_dev
);
1240 static int sd_getvflip(struct gspca_dev
*gspca_dev
, __s32
*val
)
1242 struct sd
*sd
= (struct sd
*) gspca_dev
;
1248 /* get stream parameters (framerate) */
1249 static int sd_get_streamparm(struct gspca_dev
*gspca_dev
,
1250 struct v4l2_streamparm
*parm
)
1252 struct v4l2_captureparm
*cp
= &parm
->parm
.capture
;
1253 struct v4l2_fract
*tpf
= &cp
->timeperframe
;
1254 struct sd
*sd
= (struct sd
*) gspca_dev
;
1256 if (parm
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1259 cp
->capability
|= V4L2_CAP_TIMEPERFRAME
;
1261 tpf
->denominator
= sd
->frame_rate
;
1266 /* set stream parameters (framerate) */
1267 static int sd_set_streamparm(struct gspca_dev
*gspca_dev
,
1268 struct v4l2_streamparm
*parm
)
1270 struct v4l2_captureparm
*cp
= &parm
->parm
.capture
;
1271 struct v4l2_fract
*tpf
= &cp
->timeperframe
;
1272 struct sd
*sd
= (struct sd
*) gspca_dev
;
1274 if (parm
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1277 /* Set requested framerate */
1278 sd
->frame_rate
= tpf
->denominator
/ tpf
->numerator
;
1279 if (gspca_dev
->streaming
)
1280 set_frame_rate(gspca_dev
);
1282 /* Return the actual framerate */
1284 tpf
->denominator
= sd
->frame_rate
;
1289 /* sub-driver description */
1290 static const struct sd_desc sd_desc
= {
1291 .name
= MODULE_NAME
,
1293 .nctrls
= ARRAY_SIZE(sd_ctrls
),
1294 .config
= sd_config
,
1298 .pkt_scan
= sd_pkt_scan
,
1299 .get_streamparm
= sd_get_streamparm
,
1300 .set_streamparm
= sd_set_streamparm
,
1303 /* -- module initialisation -- */
1304 static const __devinitdata
struct usb_device_id device_table
[] = {
1305 {USB_DEVICE(0x1415, 0x2000)},
1309 MODULE_DEVICE_TABLE(usb
, device_table
);
1311 /* -- device connect -- */
1312 static int sd_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1314 return gspca_dev_probe(intf
, id
, &sd_desc
, sizeof(struct sd
),
1318 static struct usb_driver sd_driver
= {
1319 .name
= MODULE_NAME
,
1320 .id_table
= device_table
,
1322 .disconnect
= gspca_disconnect
,
1324 .suspend
= gspca_suspend
,
1325 .resume
= gspca_resume
,
1329 /* -- module insert / remove -- */
1330 static int __init
sd_mod_init(void)
1334 ret
= usb_register(&sd_driver
);
1337 PDEBUG(D_PROBE
, "registered");
1341 static void __exit
sd_mod_exit(void)
1343 usb_deregister(&sd_driver
);
1344 PDEBUG(D_PROBE
, "deregistered");
1347 module_init(sd_mod_init
);
1348 module_exit(sd_mod_exit
);