3 * Copyright (C) 2008 Antonio Ospite <ospite@studenti.unina.it>
4 * Copyright (C) 2008 Jim Paris <jim@jtan.com>
5 * Copyright (C) 2009 Jean-Francois Moine http://moinejf.free.fr
7 * Based on a prototype written by Mark Ferrell <majortrips@gmail.com>
8 * USB protocol reverse engineered by Jim Paris <jim@jtan.com>
9 * https://jim.sh/svn/jim/devl/playstation/ps3/eye/test/
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #define MODULE_NAME "ov534"
30 #define OV534_REG_ADDRESS 0xf1 /* sensor address */
31 #define OV534_REG_SUBADDR 0xf2
32 #define OV534_REG_WRITE 0xf3
33 #define OV534_REG_READ 0xf4
34 #define OV534_REG_OPERATION 0xf5
35 #define OV534_REG_STATUS 0xf6
37 #define OV534_OP_WRITE_3 0x37
38 #define OV534_OP_WRITE_2 0x33
39 #define OV534_OP_READ_2 0xf9
41 #define CTRL_TIMEOUT 500
43 MODULE_AUTHOR("Antonio Ospite <ospite@studenti.unina.it>");
44 MODULE_DESCRIPTION("GSPCA/OV534 USB Camera Driver");
45 MODULE_LICENSE("GPL");
47 /* specific webcam descriptor */
49 struct gspca_dev gspca_dev
; /* !! must be the first item */
55 #define SENSOR_OV772X 0
56 #define SENSOR_OV965X 1
59 /* V4L2 controls supported by the driver */
60 static struct ctrl sd_ctrls
[] = {
63 static const struct v4l2_pix_format vga_yuyv_mode
[] = {
64 {640, 480, V4L2_PIX_FMT_YUYV
, V4L2_FIELD_NONE
,
65 .bytesperline
= 640 * 2,
66 .sizeimage
= 640 * 480 * 2,
67 .colorspace
= V4L2_COLORSPACE_SRGB
,
71 static const struct v4l2_pix_format vga_jpeg_mode
[] = {
72 {320, 240, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
74 .sizeimage
= 320 * 240 * 3 / 8 + 590,
75 .colorspace
= V4L2_COLORSPACE_JPEG
,
77 {640, 480, V4L2_PIX_FMT_JPEG
, V4L2_FIELD_NONE
,
79 .sizeimage
= 640 * 480 * 3 / 8 + 590,
80 .colorspace
= V4L2_COLORSPACE_JPEG
,
84 static const u8 bridge_init_ov722x
[][2] = {
123 { 0x1d, 0x02 }, /* payload size 0x0200 * 4 = 2048 bytes */
124 { 0x1d, 0x00 }, /* payload size */
125 { 0x1d, 0x02 }, /* frame size 0x025800 * 4 = 614400 */
126 { 0x1d, 0x58 }, /* frame size */
127 { 0x1d, 0x00 }, /* frame size */
130 { 0x1d, 0x08 }, /* turn on UVC header */
131 { 0x1d, 0x0e }, /* .. */
142 static const u8 sensor_init_ov722x
[][2] = {
225 static const u8 bridge_init_ov965x
[][2] = {
259 static const u8 sensor_init_ov965x
[][2] = {
260 {0x12, 0x80}, /* com7 - SSCB reset */
261 {0x00, 0x00}, /* gain */
262 {0x01, 0x80}, /* blue */
263 {0x02, 0x80}, /* red */
264 {0x03, 0x1b}, /* vref */
265 {0x04, 0x03}, /* com1 - exposure low bits */
266 {0x0b, 0x57}, /* ver */
267 {0x0e, 0x61}, /* com5 */
268 {0x0f, 0x42}, /* com6 */
269 {0x11, 0x00}, /* clkrc */
270 {0x12, 0x02}, /* com7 - 15fps VGA YUYV */
271 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
272 {0x14, 0x28}, /* com9 */
273 {0x16, 0x24}, /* reg16 */
274 {0x17, 0x1d}, /* hstart*/
275 {0x18, 0xbd}, /* hstop */
276 {0x19, 0x01}, /* vstrt */
277 {0x1a, 0x81}, /* vstop*/
278 {0x1e, 0x04}, /* mvfp */
279 {0x24, 0x3c}, /* aew */
280 {0x25, 0x36}, /* aeb */
281 {0x26, 0x71}, /* vpt */
282 {0x27, 0x08}, /* bbias */
283 {0x28, 0x08}, /* gbbias */
284 {0x29, 0x15}, /* gr com */
285 {0x2a, 0x00}, /* exhch */
286 {0x2b, 0x00}, /* exhcl */
287 {0x2c, 0x08}, /* rbias */
288 {0x32, 0xff}, /* href */
289 {0x33, 0x00}, /* chlf */
290 {0x34, 0x3f}, /* aref1 */
291 {0x35, 0x00}, /* aref2 */
292 {0x36, 0xf8}, /* aref3 */
293 {0x38, 0x72}, /* adc2 */
294 {0x39, 0x57}, /* aref4 */
295 {0x3a, 0x80}, /* tslb - yuyv */
296 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
297 {0x3d, 0x99}, /* com13 */
298 {0x3f, 0xc1}, /* edge */
299 {0x40, 0xc0}, /* com15 */
300 {0x41, 0x40}, /* com16 */
301 {0x42, 0xc0}, /* com17 */
302 {0x43, 0x0a}, /* rsvd */
313 {0x4f, 0x98}, /* matrix */
319 {0x58, 0x1a}, /* matrix coef sign */
320 {0x59, 0x85}, /* AWB control */
326 {0x5f, 0xf0}, /* AWB blue limit */
327 {0x60, 0xf0}, /* AWB red limit */
328 {0x61, 0xf0}, /* AWB green limit */
329 {0x62, 0x00}, /* lcc1 */
330 {0x63, 0x00}, /* lcc2 */
331 {0x64, 0x02}, /* lcc3 */
332 {0x65, 0x16}, /* lcc4 */
333 {0x66, 0x01}, /* lcc5 */
334 {0x69, 0x02}, /* hv */
335 {0x6b, 0x5a}, /* dbvl */
340 {0x70, 0x21}, /* dnsth */
342 {0x72, 0x00}, /* poidx */
343 {0x73, 0x01}, /* pckdv */
344 {0x74, 0x3a}, /* xindx */
345 {0x75, 0x35}, /* yindx */
348 {0x7a, 0x12}, /* gamma curve */
365 {0x8c, 0x89}, /* com19 */
366 {0x14, 0x28}, /* com9 */
369 {0x9d, 0x03}, /* lcc6 */
370 {0x9e, 0x04}, /* lcc7 */
373 {0xa1, 0x40}, /* aechm */
374 {0xa4, 0x50}, /* com21 */
375 {0xa5, 0x68}, /* com26 */
376 {0xa6, 0x4a}, /* AWB green */
377 {0xa8, 0xc1}, /* refa8 */
378 {0xa9, 0xef}, /* refa9 */
381 {0xac, 0x80}, /* black level control */
387 {0xb4, 0x20}, /* ctrlb4 */
391 {0xbc, 0x7f}, /* ADC channel offsets */
400 {0xc7, 0x80}, /* com24 */
413 {0xff, 0x41}, /* read 41, write ff 00 */
414 {0x41, 0x40}, /* com16 */
415 {0xc5, 0x03}, /* 60 Hz banding filter */
416 {0x6a, 0x02}, /* 50 Hz banding filter */
418 {0x12, 0x62}, /* com7 - 30fps VGA YUV */
419 {0x36, 0xfa}, /* aref3 */
420 {0x69, 0x0a}, /* hv */
421 {0x8c, 0x89}, /* com22 */
422 {0x14, 0x28}, /* com9 */
424 {0x41, 0x40}, /* com16 */
431 {0x03, 0x12}, /* vref */
432 {0x17, 0x16}, /* hstart */
433 {0x18, 0x02}, /* hstop */
434 {0x19, 0x01}, /* vstrt */
435 {0x1a, 0x3d}, /* vstop */
436 {0x32, 0xff}, /* href */
440 static const u8 bridge_init_ov965x_2
[][2] = {
458 {0x55, 0x00}, /* brightness */
459 {0x57, 0x00}, /* contrast 2 */
468 static const u8 sensor_init_ov965x_2
[][2] = {
470 {0x1e, 0x04}, /* mvfp */
471 {0x13, 0xe0}, /* com8 */
472 {0x00, 0x00}, /* gain */
473 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
474 {0x11, 0x03}, /* clkrc */
475 {0x6b, 0x5a}, /* dblv */
481 {0xff, 0x42}, /* read 42, write ff 00 */
484 {0xff, 0x42}, /* read 42, write ff 00 */
487 {0xff, 0x42}, /* read 42, write ff 00 */
496 {0xff, 0x41}, /* read 41, write ff 00 */
497 {0x41, 0x40}, /* com16 */
500 {0x10, 0x25}, /* aech - exposure high bits */
501 {0xff, 0x13}, /* read 13, write ff 00 */
502 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
505 static const u8 sensor_start_ov965x
[][2] = {
506 {0x12, 0x62}, /* com7 - 30fps VGA YUV */
507 {0x36, 0xfa}, /* aref3 */
508 {0x69, 0x0a}, /* hv */
509 {0x8c, 0x89}, /* com22 */
510 {0x14, 0x28}, /* com9 */
511 {0x3e, 0x0c}, /* com14 */
512 {0x41, 0x40}, /* com16 */
518 {0xc7, 0x80}, /* com24 */
519 {0x03, 0x12}, /* vref */
520 {0x17, 0x16}, /* hstart */
521 {0x18, 0x02}, /* hstop */
522 {0x19, 0x01}, /* vstrt */
523 {0x1a, 0x3d}, /* vstop */
524 {0x32, 0xff}, /* href */
529 static const u8 bridge_start_ov965x
[][2] = {
541 static const u8 bridge_start_ov965x_vga
[][2] = {
561 static const u8 bridge_start_ov965x_cif
[][2] = {
581 static const u8 sensor_start_ov965x_vga
[][2] = {
582 {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */
583 {0x1e, 0x04}, /* mvfp */
584 {0x13, 0xe0}, /* com8 */
586 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
587 {0x11, 0x03}, /* clkrc */
588 {0x6b, 0x5a}, /* dblv */
589 {0x6a, 0x05}, /* 50 Hz banding filter */
590 {0xc5, 0x07}, /* 60 Hz banding filter */
591 {0xa2, 0x4b}, /* bd50 */
592 {0xa3, 0x3e}, /* bd60 */
594 {0x2d, 0x00}, /* advfl */
598 static const u8 sensor_start_ov965x_cif
[][2] = {
599 {0x3b, 0xe4}, /* com11 - night mode 1/4 frame rate */
600 {0x1e, 0x04}, /* mvfp */
601 {0x13, 0xe0}, /* com8 */
603 {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */
604 {0x11, 0x01}, /* clkrc */
605 {0x6b, 0x5a}, /* dblv */
606 {0x6a, 0x02}, /* 50 Hz banding filter */
607 {0xc5, 0x03}, /* 60 Hz banding filter */
608 {0xa2, 0x96}, /* bd50 */
609 {0xa3, 0x7d}, /* bd60 */
611 {0xff, 0x13}, /* read 13, write ff 00 */
613 {0x3a, 0x80}, /* tslb - yuyv */
617 static const u8 sensor_start_ov965x_2
[][2] = {
618 {0xff, 0x42}, /* read 42, write ff 00 */
619 {0x42, 0xc1}, /* com17 - 50 Hz filter */
624 static void ov534_reg_write(struct gspca_dev
*gspca_dev
, u16 reg
, u8 val
)
626 struct usb_device
*udev
= gspca_dev
->dev
;
629 PDEBUG(D_USBO
, "reg=0x%04x, val=0%02x", reg
, val
);
630 gspca_dev
->usb_buf
[0] = val
;
631 ret
= usb_control_msg(udev
,
632 usb_sndctrlpipe(udev
, 0),
634 USB_DIR_OUT
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
635 0x00, reg
, gspca_dev
->usb_buf
, 1, CTRL_TIMEOUT
);
637 PDEBUG(D_ERR
, "write failed");
640 static u8
ov534_reg_read(struct gspca_dev
*gspca_dev
, u16 reg
)
642 struct usb_device
*udev
= gspca_dev
->dev
;
645 ret
= usb_control_msg(udev
,
646 usb_rcvctrlpipe(udev
, 0),
648 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
649 0x00, reg
, gspca_dev
->usb_buf
, 1, CTRL_TIMEOUT
);
650 PDEBUG(D_USBI
, "reg=0x%04x, data=0x%02x", reg
, gspca_dev
->usb_buf
[0]);
652 PDEBUG(D_ERR
, "read failed");
653 return gspca_dev
->usb_buf
[0];
656 /* Two bits control LED: 0x21 bit 7 and 0x23 bit 7.
657 * (direction and output)? */
658 static void ov534_set_led(struct gspca_dev
*gspca_dev
, int status
)
662 PDEBUG(D_CONF
, "led status: %d", status
);
664 data
= ov534_reg_read(gspca_dev
, 0x21);
666 ov534_reg_write(gspca_dev
, 0x21, data
);
668 data
= ov534_reg_read(gspca_dev
, 0x23);
674 ov534_reg_write(gspca_dev
, 0x23, data
);
677 data
= ov534_reg_read(gspca_dev
, 0x21);
679 ov534_reg_write(gspca_dev
, 0x21, data
);
683 static int sccb_check_status(struct gspca_dev
*gspca_dev
)
688 for (i
= 0; i
< 5; i
++) {
689 data
= ov534_reg_read(gspca_dev
, OV534_REG_STATUS
);
699 PDEBUG(D_ERR
, "sccb status 0x%02x, attempt %d/5",
706 static void sccb_reg_write(struct gspca_dev
*gspca_dev
, u8 reg
, u8 val
)
708 PDEBUG(D_USBO
, "reg: 0x%02x, val: 0x%02x", reg
, val
);
709 ov534_reg_write(gspca_dev
, OV534_REG_SUBADDR
, reg
);
710 ov534_reg_write(gspca_dev
, OV534_REG_WRITE
, val
);
711 ov534_reg_write(gspca_dev
, OV534_REG_OPERATION
, OV534_OP_WRITE_3
);
713 if (!sccb_check_status(gspca_dev
))
714 PDEBUG(D_ERR
, "sccb_reg_write failed");
717 static u8
sccb_reg_read(struct gspca_dev
*gspca_dev
, u16 reg
)
719 ov534_reg_write(gspca_dev
, OV534_REG_SUBADDR
, reg
);
720 ov534_reg_write(gspca_dev
, OV534_REG_OPERATION
, OV534_OP_WRITE_2
);
721 if (!sccb_check_status(gspca_dev
))
722 PDEBUG(D_ERR
, "sccb_reg_read failed 1");
724 ov534_reg_write(gspca_dev
, OV534_REG_OPERATION
, OV534_OP_READ_2
);
725 if (!sccb_check_status(gspca_dev
))
726 PDEBUG(D_ERR
, "sccb_reg_read failed 2");
728 return ov534_reg_read(gspca_dev
, OV534_REG_READ
);
731 /* output a bridge sequence (reg - val) */
732 static void reg_w_array(struct gspca_dev
*gspca_dev
,
733 const u8 (*data
)[2], int len
)
736 ov534_reg_write(gspca_dev
, (*data
)[0], (*data
)[1]);
741 /* output a sensor sequence (reg - val) */
742 static void sccb_w_array(struct gspca_dev
*gspca_dev
,
743 const u8 (*data
)[2], int len
)
746 if ((*data
)[0] != 0xff) {
747 sccb_reg_write(gspca_dev
, (*data
)[0], (*data
)[1]);
749 sccb_reg_read(gspca_dev
, (*data
)[1]);
750 sccb_reg_write(gspca_dev
, 0xff, 0x00);
757 static void ov534_set_frame_rate(struct gspca_dev
*gspca_dev
)
759 struct sd
*sd
= (struct sd
*) gspca_dev
;
760 int fr
= sd
->frame_rate
;
764 sccb_reg_write(gspca_dev
, 0x11, 0x01);
765 sccb_reg_write(gspca_dev
, 0x0d, 0x41);
766 ov534_reg_write(gspca_dev
, 0xe5, 0x02);
769 sccb_reg_write(gspca_dev
, 0x11, 0x02);
770 sccb_reg_write(gspca_dev
, 0x0d, 0xc1);
771 ov534_reg_write(gspca_dev
, 0xe5, 0x04);
776 sccb_reg_write(gspca_dev
, 0x11, 0x04);
777 sccb_reg_write(gspca_dev
, 0x0d, 0x81);
778 ov534_reg_write(gspca_dev
, 0xe5, 0x02);
781 sccb_reg_write(gspca_dev
, 0x11, 0x03);
782 sccb_reg_write(gspca_dev
, 0x0d, 0x41);
783 ov534_reg_write(gspca_dev
, 0xe5, 0x04);
788 PDEBUG(D_PROBE
, "frame_rate: %d", fr
);
791 /* this function is called at probe time */
792 static int sd_config(struct gspca_dev
*gspca_dev
,
793 const struct usb_device_id
*id
)
795 struct sd
*sd
= (struct sd
*) gspca_dev
;
798 sd
->sensor
= id
->driver_info
;
800 cam
= &gspca_dev
->cam
;
802 if (sd
->sensor
== SENSOR_OV772X
) {
803 cam
->cam_mode
= vga_yuyv_mode
;
804 cam
->nmodes
= ARRAY_SIZE(vga_yuyv_mode
);
807 cam
->bulk_size
= 16384;
809 } else { /* ov965x */
810 cam
->cam_mode
= vga_jpeg_mode
;
811 cam
->nmodes
= ARRAY_SIZE(vga_jpeg_mode
);
817 /* this function is called at probe and resume time */
818 static int sd_init(struct gspca_dev
*gspca_dev
)
820 struct sd
*sd
= (struct sd
*) gspca_dev
;
822 static const u8 sensor_addr
[2] = {
823 0x42, /* 0 SENSOR_OV772X */
824 0x60, /* 1 SENSOR_OV965X */
828 ov534_reg_write(gspca_dev
, 0xe7, 0x3a);
829 ov534_reg_write(gspca_dev
, 0xe0, 0x08);
832 /* initialize the sensor address */
833 ov534_reg_write(gspca_dev
, OV534_REG_ADDRESS
,
834 sensor_addr
[sd
->sensor
]);
837 sccb_reg_write(gspca_dev
, 0x12, 0x80);
840 /* probe the sensor */
841 sccb_reg_read(gspca_dev
, 0x0a);
842 sensor_id
= sccb_reg_read(gspca_dev
, 0x0a) << 8;
843 sccb_reg_read(gspca_dev
, 0x0b);
844 sensor_id
|= sccb_reg_read(gspca_dev
, 0x0b);
845 PDEBUG(D_PROBE
, "Sensor ID: %04x", sensor_id
);
848 switch (sd
->sensor
) {
850 reg_w_array(gspca_dev
, bridge_init_ov722x
,
851 ARRAY_SIZE(bridge_init_ov722x
));
852 ov534_set_led(gspca_dev
, 1);
853 sccb_w_array(gspca_dev
, sensor_init_ov722x
,
854 ARRAY_SIZE(sensor_init_ov722x
));
855 ov534_reg_write(gspca_dev
, 0xe0, 0x09);
856 ov534_set_led(gspca_dev
, 0);
857 ov534_set_frame_rate(gspca_dev
);
860 /* case SENSOR_OV965X: */
861 reg_w_array(gspca_dev
, bridge_init_ov965x
,
862 ARRAY_SIZE(bridge_init_ov965x
));
863 sccb_w_array(gspca_dev
, sensor_init_ov965x
,
864 ARRAY_SIZE(sensor_init_ov965x
));
865 reg_w_array(gspca_dev
, bridge_init_ov965x_2
,
866 ARRAY_SIZE(bridge_init_ov965x_2
));
867 sccb_w_array(gspca_dev
, sensor_init_ov965x_2
,
868 ARRAY_SIZE(sensor_init_ov965x_2
));
869 ov534_reg_write(gspca_dev
, 0xe0, 0x00);
870 ov534_reg_write(gspca_dev
, 0xe0, 0x01);
871 ov534_set_led(gspca_dev
, 0);
872 ov534_reg_write(gspca_dev
, 0xe0, 0x00);
878 static int sd_start(struct gspca_dev
*gspca_dev
)
880 struct sd
*sd
= (struct sd
*) gspca_dev
;
883 switch (sd
->sensor
) {
885 ov534_set_led(gspca_dev
, 1);
886 ov534_reg_write(gspca_dev
, 0xe0, 0x00);
889 /* case SENSOR_OV965X: */
891 sccb_w_array(gspca_dev
, sensor_start_ov965x
,
892 ARRAY_SIZE(sensor_start_ov965x
));
893 reg_w_array(gspca_dev
, bridge_start_ov965x
,
894 ARRAY_SIZE(bridge_start_ov965x
));
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_ov965x_cif
,
898 ARRAY_SIZE(bridge_start_ov965x_cif
));
899 sccb_w_array(gspca_dev
, sensor_start_ov965x_cif
,
900 ARRAY_SIZE(sensor_start_ov965x_cif
));
901 } else { /* 640x480 */
902 reg_w_array(gspca_dev
, bridge_start_ov965x_vga
,
903 ARRAY_SIZE(bridge_start_ov965x_vga
));
904 sccb_w_array(gspca_dev
, sensor_start_ov965x_vga
,
905 ARRAY_SIZE(sensor_start_ov965x_vga
));
907 sccb_w_array(gspca_dev
, sensor_start_ov965x_2
,
908 ARRAY_SIZE(sensor_start_ov965x_2
));
909 ov534_reg_write(gspca_dev
, 0xe0, 0x00);
910 ov534_reg_write(gspca_dev
, 0xe0, 0x00);
911 ov534_set_led(gspca_dev
, 1);
916 static void sd_stopN(struct gspca_dev
*gspca_dev
)
918 struct sd
*sd
= (struct sd
*) gspca_dev
;
920 switch (sd
->sensor
) {
922 ov534_reg_write(gspca_dev
, 0xe0, 0x09);
923 ov534_set_led(gspca_dev
, 0);
926 /* case SENSOR_OV965X: */
927 ov534_reg_write(gspca_dev
, 0xe0, 0x01);
928 ov534_set_led(gspca_dev
, 0);
929 ov534_reg_write(gspca_dev
, 0xe0, 0x00);
934 /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */
935 #define UVC_STREAM_EOH (1 << 7)
936 #define UVC_STREAM_ERR (1 << 6)
937 #define UVC_STREAM_STI (1 << 5)
938 #define UVC_STREAM_RES (1 << 4)
939 #define UVC_STREAM_SCR (1 << 3)
940 #define UVC_STREAM_PTS (1 << 2)
941 #define UVC_STREAM_EOF (1 << 1)
942 #define UVC_STREAM_FID (1 << 0)
944 static void sd_pkt_scan(struct gspca_dev
*gspca_dev
, struct gspca_frame
*frame
,
947 struct sd
*sd
= (struct sd
*) gspca_dev
;
950 int remaining_len
= len
;
953 payload_len
= gspca_dev
->cam
.bulk
? 2048 : 2040;
955 len
= min(remaining_len
, payload_len
);
957 /* Payloads are prefixed with a UVC-style header. We
958 consider a frame to start when the FID toggles, or the PTS
959 changes. A frame ends when EOF is set, and we've received
960 the correct number of bytes. */
962 /* Verify UVC header. Header length is always 12 */
963 if (data
[0] != 12 || len
< 12) {
964 PDEBUG(D_PACK
, "bad header");
969 if (data
[1] & UVC_STREAM_ERR
) {
970 PDEBUG(D_PACK
, "payload error");
974 /* Extract PTS and FID */
975 if (!(data
[1] & UVC_STREAM_PTS
)) {
976 PDEBUG(D_PACK
, "PTS not present");
979 this_pts
= (data
[5] << 24) | (data
[4] << 16)
980 | (data
[3] << 8) | data
[2];
981 this_fid
= (data
[1] & UVC_STREAM_FID
) ? 1 : 0;
983 /* If PTS or FID has changed, start a new frame. */
984 if (this_pts
!= sd
->last_pts
|| this_fid
!= sd
->last_fid
) {
985 if (gspca_dev
->last_packet_type
== INTER_PACKET
)
986 frame
= gspca_frame_add(gspca_dev
,
989 sd
->last_pts
= this_pts
;
990 sd
->last_fid
= this_fid
;
991 gspca_frame_add(gspca_dev
, FIRST_PACKET
, frame
,
992 data
+ 12, len
- 12);
993 /* If this packet is marked as EOF, end the frame */
994 } else if (data
[1] & UVC_STREAM_EOF
) {
996 frame
= gspca_frame_add(gspca_dev
, LAST_PACKET
, frame
,
997 data
+ 12, len
- 12);
1000 /* Add the data from this payload */
1001 gspca_frame_add(gspca_dev
, INTER_PACKET
, frame
,
1002 data
+ 12, len
- 12);
1006 /* Done this payload */
1010 /* Discard data until a new frame starts. */
1011 gspca_frame_add(gspca_dev
, DISCARD_PACKET
, frame
, NULL
, 0);
1014 remaining_len
-= len
;
1016 } while (remaining_len
> 0);
1019 /* get stream parameters (framerate) */
1020 static int sd_get_streamparm(struct gspca_dev
*gspca_dev
,
1021 struct v4l2_streamparm
*parm
)
1023 struct v4l2_captureparm
*cp
= &parm
->parm
.capture
;
1024 struct v4l2_fract
*tpf
= &cp
->timeperframe
;
1025 struct sd
*sd
= (struct sd
*) gspca_dev
;
1027 if (parm
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1030 cp
->capability
|= V4L2_CAP_TIMEPERFRAME
;
1032 tpf
->denominator
= sd
->frame_rate
;
1037 /* set stream parameters (framerate) */
1038 static int sd_set_streamparm(struct gspca_dev
*gspca_dev
,
1039 struct v4l2_streamparm
*parm
)
1041 struct v4l2_captureparm
*cp
= &parm
->parm
.capture
;
1042 struct v4l2_fract
*tpf
= &cp
->timeperframe
;
1043 struct sd
*sd
= (struct sd
*) gspca_dev
;
1045 if (parm
->type
!= V4L2_BUF_TYPE_VIDEO_CAPTURE
)
1048 /* Set requested framerate */
1049 sd
->frame_rate
= tpf
->denominator
/ tpf
->numerator
;
1050 ov534_set_frame_rate(gspca_dev
);
1052 /* Return the actual framerate */
1054 tpf
->denominator
= sd
->frame_rate
;
1059 /* sub-driver description */
1060 static const struct sd_desc sd_desc
= {
1061 .name
= MODULE_NAME
,
1063 .nctrls
= ARRAY_SIZE(sd_ctrls
),
1064 .config
= sd_config
,
1068 .pkt_scan
= sd_pkt_scan
,
1069 .get_streamparm
= sd_get_streamparm
,
1070 .set_streamparm
= sd_set_streamparm
,
1073 /* -- module initialisation -- */
1074 static const __devinitdata
struct usb_device_id device_table
[] = {
1075 {USB_DEVICE(0x06f8, 0x3003), .driver_info
= SENSOR_OV965X
},
1076 {USB_DEVICE(0x1415, 0x2000), .driver_info
= SENSOR_OV772X
},
1080 MODULE_DEVICE_TABLE(usb
, device_table
);
1082 /* -- device connect -- */
1083 static int sd_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1085 return gspca_dev_probe(intf
, id
, &sd_desc
, sizeof(struct sd
),
1089 static struct usb_driver sd_driver
= {
1090 .name
= MODULE_NAME
,
1091 .id_table
= device_table
,
1093 .disconnect
= gspca_disconnect
,
1095 .suspend
= gspca_suspend
,
1096 .resume
= gspca_resume
,
1100 /* -- module insert / remove -- */
1101 static int __init
sd_mod_init(void)
1104 ret
= usb_register(&sd_driver
);
1107 PDEBUG(D_PROBE
, "registered");
1111 static void __exit
sd_mod_exit(void)
1113 usb_deregister(&sd_driver
);
1114 PDEBUG(D_PROBE
, "deregistered");
1117 module_init(sd_mod_init
);
1118 module_exit(sd_mod_exit
);