18 #include <linux/module.h>
19 #include <linux/kernel.h>
21 #include <linux/wait.h>
22 #include <linux/list.h>
23 #include <linux/slab.h>
24 #include <linux/time.h>
27 #include <linux/i2c.h>
28 #include <asm/byteorder.h>
34 static unsigned int assume_endura;
37 "hardware is a Pelco Endura");
42 #define HPI_STATUS_ADDR 0xFFF4
43 #define INT_PARAM_ADDR 0xFFF6
44 #define INT_INDEX_ADDR 0xFFF8
56 #define GO7007_USB_EZUSB (1<<0)
57 #define GO7007_USB_EZUSB_I2C (1<<1)
78 .firmware =
"go7007tv.bin",
95 .type =
"wis_saa7115",
117 .firmware =
"go7007tv.bin",
132 .type =
"wis_saa7113",
154 .firmware =
"go7007tv.bin",
170 .type =
"wis_saa7115",
200 .firmware =
"go7007tv.bin",
216 .type =
"wis_saa7115",
221 .type =
"wis_uda1342",
226 .type =
"wis_sony_tuner",
255 .firmware =
"go7007tv.bin",
260 .sensor_height = 240,
261 .sensor_framerate = 30030,
269 .audio_bclk_div = 48,
274 .type =
"wis_ov7640",
291 .firmware =
"go7007tv.bin",
307 .type =
"wis_tw9903",
329 .firmware =
"go7007tv.bin",
357 .firmware =
"go7007tv.bin",
363 .audio_bclk_div = 48,
368 .sensor_h_offset = 8,
382 .firmware =
"go7007tv.bin",
397 .type =
"wis_tw2804",
414 .firmware =
"go7007tv.bin",
451 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
452 USB_DEVICE_ID_MATCH_INT_INFO,
455 .bcdDevice_lo = 0x200,
456 .bcdDevice_hi = 0x200,
457 .bInterfaceClass = 255,
458 .bInterfaceSubClass = 0,
459 .bInterfaceProtocol = 255,
463 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
466 .bcdDevice_lo = 0x202,
467 .bcdDevice_hi = 0x202,
471 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
474 .bcdDevice_lo = 0x204,
475 .bcdDevice_hi = 0x204,
479 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
480 USB_DEVICE_ID_MATCH_INT_INFO,
483 .bcdDevice_lo = 0x205,
484 .bcdDevice_hi = 0x205,
485 .bInterfaceClass = 255,
486 .bInterfaceSubClass = 0,
487 .bInterfaceProtocol = 255,
491 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
494 .bcdDevice_lo = 0x208,
495 .bcdDevice_hi = 0x208,
499 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
500 USB_DEVICE_ID_MATCH_INT_INFO,
503 .bcdDevice_lo = 0x209,
504 .bcdDevice_hi = 0x209,
505 .bInterfaceClass = 255,
506 .bInterfaceSubClass = 0,
507 .bInterfaceProtocol = 255,
511 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
514 .bcdDevice_lo = 0x210,
515 .bcdDevice_hi = 0x210,
519 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
527 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
535 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
543 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
565 usb_rcvctrlpipe(usb->
usbdev, 0), request,
567 value, index, transfer_buffer, length, timeout);
570 usb_sndctrlpipe(usb->
usbdev, 0), request,
572 value, index, transfer_buffer, length, timeout);
576 static int go7007_usb_interface_reset(
struct go7007 *go)
579 u16 intr_val, intr_data;
588 #ifdef GO7007_USB_DEBUG
591 if (go7007_usb_vendor_request(go, 0x10, 0, 0,
NULL, 0, 0) < 0 ||
592 go7007_usb_vendor_request(go, 0x10, 0, 0,
NULL, 0, 0) < 0)
603 (intr_val & ~0x1) != 0x55aa) {
605 "go7007-usb: unable to reset the USB interface\n");
611 static int go7007_usb_ezusb_write_interrupt(
struct go7007 *go,
619 #ifdef GO7007_USB_DEBUG
621 "go7007-usb: WriteInterrupt: %04x %04x\n", addr, data);
624 for (i = 0; i < 100; ++
i) {
626 usb_rcvctrlpipe(usb->
usbdev, 0), 0x14,
629 sizeof(status_reg), timeout);
631 goto write_int_error;
633 if (!(status_reg & 0x0010))
639 "go7007-usb: device is hung, status reg = 0x%04x\n",
647 goto write_int_error;
652 goto write_int_error;
660 static int go7007_usb_onboard_write_interrupt(
struct go7007 *go,
668 #ifdef GO7007_USB_DEBUG
670 "go7007-usb: WriteInterrupt: %04x %04x\n", addr, data);
676 tbuf[0] = data & 0xff;
678 tbuf[2] = addr & 0xff;
682 0xf0f0, tbuf, 8, timeout);
691 static void go7007_usb_readinterrupt_complete(
struct urb *
urb)
701 "go7007-usb: error in read interrupt: %d\n",
707 }
else if (urb->actual_length != urb->transfer_buffer_length) {
713 #ifdef GO7007_USB_DEBUG
722 static int go7007_usb_read_interrupt(
struct go7007 *go)
730 "go7007-usb: unable to submit interrupt urb: %d\n", r);
736 static void go7007_usb_read_video_pipe_complete(
struct urb *urb)
739 int r, status = urb->
status;
750 if (urb->actual_length != urb->transfer_buffer_length) {
760 static void go7007_usb_read_audio_pipe_complete(
struct urb *urb)
763 int r, status = urb->
status;
772 if (urb->actual_length != urb->transfer_buffer_length) {
777 go->
audio_deliver(go, urb->transfer_buffer, urb->actual_length);
783 static int go7007_usb_stream_start(
struct go7007 *go)
788 for (i = 0; i < 8; ++
i) {
792 "urb %d: %d\n", i, r);
793 goto video_submit_failed;
799 for (i = 0; i < 8; ++
i) {
803 "urb %d: %d\n", i, r);
804 goto audio_submit_failed;
810 for (i = 0; i < 7; ++
i)
813 for (i = 0; i < 8; ++
i)
818 static int go7007_usb_stream_stop(
struct go7007 *go)
823 if (go->
status == STATUS_SHUTDOWN)
825 for (i = 0; i < 8; ++
i)
828 for (i = 0; i < 8; ++
i)
833 static int go7007_usb_send_firmware(
struct go7007 *go,
u8 *data,
int len)
836 int transferred,
pipe;
839 #ifdef GO7007_USB_DEBUG
844 pipe = usb_sndbulkpipe(usb->
usbdev, 2);
846 pipe = usb_sndbulkpipe(usb->
usbdev, 3);
849 &transferred, timeout);
853 .interface_reset = go7007_usb_interface_reset,
854 .write_interrupt = go7007_usb_ezusb_write_interrupt,
855 .read_interrupt = go7007_usb_read_interrupt,
856 .stream_start = go7007_usb_stream_start,
857 .stream_stop = go7007_usb_stream_stop,
858 .send_firmware = go7007_usb_send_firmware,
862 .interface_reset = go7007_usb_interface_reset,
863 .write_interrupt = go7007_usb_onboard_write_interrupt,
864 .read_interrupt = go7007_usb_read_interrupt,
865 .stream_start = go7007_usb_stream_start,
866 .stream_stop = go7007_usb_stream_stop,
867 .send_firmware = go7007_usb_send_firmware,
873 struct i2c_msg msgs[],
int num)
875 struct go7007 *go = i2c_get_adapdata(adapter);
881 if (go->
status == STATUS_SHUTDOWN)
886 for (i = 0; i < num; ++
i) {
890 if (i + 1 < num && msgs[i].addr == msgs[i + 1].addr &&
892 (msgs[i + 1].
flags & I2C_M_RD)) {
893 #ifdef GO7007_I2C_DEBUG
895 "bytes on %02x\n", msgs[i].len,
896 msgs[i + 1].len, msgs[i].addr);
899 buf[1] = msgs[
i].
len + 1;
900 buf[2] = msgs[
i].
addr << 1;
901 memcpy(&buf[3], msgs[i].buf, msgs[i].len);
902 buf_len = msgs[
i].
len + 3;
903 buf[buf_len++] = msgs[++
i].
len;
904 }
else if (msgs[i].
flags & I2C_M_RD) {
905 #ifdef GO7007_I2C_DEBUG
907 "bytes on %02x\n", msgs[i].len,
912 buf[2] = msgs[
i].
addr << 1;
913 buf[3] = msgs[
i].
len;
916 #ifdef GO7007_I2C_DEBUG
918 "bytes on %02x\n", msgs[i].len,
922 buf[1] = msgs[
i].
len + 1;
923 buf[2] = msgs[
i].
addr << 1;
924 memcpy(&buf[3], msgs[i].buf, msgs[i].len);
925 buf_len = msgs[
i].
len + 3;
928 if (go7007_usb_vendor_request(go, 0x24, 0, 0,
929 buf, buf_len, 0) < 0)
931 if (msgs[i].
flags & I2C_M_RD) {
932 memset(buf, 0,
sizeof(buf));
933 if (go7007_usb_vendor_request(go, 0x25, 0, 0, buf,
934 msgs[i].len + 1, 1) < 0)
936 memcpy(msgs[i].buf, buf + 1, msgs[i].len);
954 .master_xfer = go7007_usb_i2c_master_xfer,
955 .functionality = go7007_usb_functionality,
958 static struct i2c_adapter go7007_usb_adap_templ = {
960 .name =
"WIS GO7007SB EZ-USB",
961 .algo = &go7007_usb_algo,
972 struct usb_device *usbdev = interface_to_usbdev(intf);
974 int video_pipe,
i, v_urb_len;
978 switch (id->driver_info) {
980 name =
"WIS Matrix II or compatible";
981 board = &board_matrix_ii;
984 name =
"WIS Matrix Reloaded or compatible";
985 board = &board_matrix_reload;
988 name =
"WIS Matrix Revolution or compatible";
989 board = &board_matrix_revolution;
992 name =
"WIS Star Trek or compatible";
993 board = &board_star_trek;
996 name =
"WIS XMen or compatible";
1000 name =
"WIS XMen II or compatible";
1001 board = &board_xmen;
1004 name =
"WIS XMen III or compatible";
1005 board = &board_xmen;
1008 name =
"Plextor PX-M402U";
1009 board = &board_matrix_ii;
1012 name =
"Plextor PX-TV402U (unknown tuner)";
1013 board = &board_px_tv402u;
1017 "is not supported. Sorry!\n");
1019 name =
"Lifeview TV Walker Ultra";
1020 board = &board_lifeview_lr192;
1024 name =
"Sensoray 2250/2251";
1025 board = &board_sensoray_2250;
1029 (
unsigned int)id->driver_info);
1053 go->
hpi_ops = &go7007_usb_ezusb_hpi_ops;
1055 go->
hpi_ops = &go7007_usb_onboard_hpi_ops;
1059 usb_rcvbulkpipe(usb->
usbdev, 4),
1061 go7007_usb_readinterrupt_complete, go);
1064 usb_rcvintpipe(usb->
usbdev, 4),
1066 go7007_usb_readinterrupt_complete, go, 8);
1067 usb_set_intfdata(intf, &go->
v4l2_dev);
1077 sizeof(go7007_usb_adap_templ));
1083 "go7007-usb: error: i2c_add_adapter failed\n");
1103 if (data.byte != 0x76) {
1104 if (assume_endura) {
1106 usb->
board = board = &board_endura;
1120 usb->
board = board = &board_adlink_mpg24;
1124 "Adlink PCI-MPG24, channel #%d",
1135 if (go7007_usb_vendor_request(go, 0x41, 0, 0, data, 3, 1) < 0) {
1139 switch (data[0] >> 6) {
1165 if (go7007_usb_vendor_request(go, 0x40, 0x7f02, 0,
1177 "must be connected to a USB 2.0 port! "
1178 "Attempting to capture video through a USB 1.1 "
1179 "port will result in stream corruption, even "
1180 "at low bitrates!\n");
1190 video_pipe = usb_rcvbulkpipe(usb->
usbdev, 6);
1193 video_pipe = usb_rcvbulkpipe(usb->
usbdev, 1);
1195 for (i = 0; i < 8; ++
i) {
1204 usb->
video_urbs[i]->transfer_buffer, v_urb_len,
1205 go7007_usb_read_video_pipe_complete, go);
1210 for (i = 0; i < 8; ++
i) {
1219 usb_rcvbulkpipe(usb->
usbdev, 8),
1221 go7007_usb_read_audio_pipe_complete, go);
1225 go->
status = STATUS_ONLINE;
1229 go->
status = STATUS_SHUTDOWN;
1241 static void go7007_usb_disconnect(
struct usb_interface *intf)
1243 struct go7007 *go = to_go7007(usb_get_intfdata(intf));
1245 struct urb *vurb, *aurb;
1248 go->
status = STATUS_SHUTDOWN;
1252 for (i = 0; i < 8; ++
i) {
1256 kfree(vurb->transfer_buffer);
1262 kfree(aurb->transfer_buffer);
1274 static struct usb_driver go7007_usb_driver = {
1276 .probe = go7007_usb_probe,
1277 .disconnect = go7007_usb_disconnect,
1278 .id_table = go7007_usb_id_table,