2 * Copyright (C) 2005-2006 Micronas USA Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/wait.h>
24 #include <linux/list.h>
25 #include <linux/slab.h>
26 #include <linux/time.h>
28 #include <linux/usb.h>
29 #include <linux/i2c.h>
30 #include <asm/byteorder.h>
31 #include <media/saa7115.h>
32 #include <media/tuner.h>
33 #include <media/uda1342.h>
35 #include "go7007-priv.h"
37 static unsigned int assume_endura;
38 module_param(assume_endura, int, 0644);
39 MODULE_PARM_DESC(assume_endura,
40 "when probing fails, hardware is a Pelco Endura");
42 /* #define GO7007_I2C_DEBUG */ /* for debugging the EZ-USB I2C adapter */
44 #define HPI_STATUS_ADDR 0xFFF4
45 #define INT_PARAM_ADDR 0xFFF6
46 #define INT_INDEX_ADDR 0xFFF8
49 * Pipes on EZ-USB interface:
52 * 2 snd - Download firmware (control)
53 * 4 rcv - Read Interrupt (interrupt)
54 * 6 rcv - Read Video (bulk)
55 * 8 rcv - Read Audio (bulk)
58 #define GO7007_USB_EZUSB (1<<0)
59 #define GO7007_USB_EZUSB_I2C (1<<1)
61 struct go7007_usb_board {
63 struct go7007_board_info main_info;
67 const struct go7007_usb_board *board;
68 struct mutex i2c_lock;
69 struct usb_device *usbdev;
70 struct urb *video_urbs[8];
71 struct urb *audio_urbs[8];
75 /*********************** Product specification data ***********************/
77 static const struct go7007_usb_board board_matrix_ii = {
78 .flags = GO7007_USB_EZUSB,
80 .flags = GO7007_BOARD_HAS_AUDIO |
81 GO7007_BOARD_USE_ONBOARD_I2C,
82 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
88 .sensor_flags = GO7007_SENSOR_656 |
89 GO7007_SENSOR_VALID_ENABLE |
91 GO7007_SENSOR_SAA7115 |
93 GO7007_SENSOR_SCALING,
113 .video_config = SAA7115_IDQ_IS_DEFAULT,
117 static const struct go7007_usb_board board_matrix_reload = {
118 .flags = GO7007_USB_EZUSB,
120 .flags = GO7007_BOARD_HAS_AUDIO |
121 GO7007_BOARD_USE_ONBOARD_I2C,
122 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
123 GO7007_AUDIO_I2S_MASTER |
124 GO7007_AUDIO_WORD_16,
129 .sensor_flags = GO7007_SENSOR_656 |
150 .video_config = SAA7115_IDQ_IS_DEFAULT,
154 static const struct go7007_usb_board board_star_trek = {
155 .flags = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
157 .flags = GO7007_BOARD_HAS_AUDIO, /* |
158 GO7007_BOARD_HAS_TUNER, */
159 .sensor_flags = GO7007_SENSOR_656 |
160 GO7007_SENSOR_VALID_ENABLE |
162 GO7007_SENSOR_SAA7115 |
164 GO7007_SENSOR_SCALING,
165 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
166 GO7007_AUDIO_WORD_16,
182 * .audio_index = AUDIO_TUNER,
188 /* .audio_index = AUDIO_EXTERN, */
193 /* .audio_index = AUDIO_EXTERN, */
197 .video_config = SAA7115_IDQ_IS_DEFAULT,
201 static const struct go7007_usb_board board_px_tv402u = {
202 .flags = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
204 .flags = GO7007_BOARD_HAS_AUDIO |
205 GO7007_BOARD_HAS_TUNER,
206 .sensor_flags = GO7007_SENSOR_656 |
207 GO7007_SENSOR_VALID_ENABLE |
209 GO7007_SENSOR_SAA7115 |
211 GO7007_SENSOR_SCALING,
212 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
213 GO7007_AUDIO_WORD_16,
238 .type = "sony-btf-mpx",
260 .video_config = SAA7115_IDQ_IS_DEFAULT,
264 .audio_input = UDA1342_IN2,
268 .audio_input = UDA1342_IN1,
275 static const struct go7007_usb_board board_xmen = {
278 .flags = GO7007_BOARD_USE_ONBOARD_I2C,
280 .sensor_flags = GO7007_SENSOR_VREF_POLAR,
282 .sensor_height = 240,
283 .sensor_framerate = 30030,
284 .audio_flags = GO7007_AUDIO_ONE_CHANNEL |
285 GO7007_AUDIO_I2S_MODE_3 |
286 GO7007_AUDIO_WORD_14 |
287 GO7007_AUDIO_I2S_MASTER |
288 GO7007_AUDIO_BCLK_POLAR |
289 GO7007_AUDIO_OKI_MODE,
291 .audio_bclk_div = 48,
309 static const struct go7007_usb_board board_matrix_revolution = {
310 .flags = GO7007_USB_EZUSB,
312 .flags = GO7007_BOARD_HAS_AUDIO |
313 GO7007_BOARD_USE_ONBOARD_I2C,
314 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
315 GO7007_AUDIO_I2S_MASTER |
316 GO7007_AUDIO_WORD_16,
321 .sensor_flags = GO7007_SENSOR_656 |
346 static const struct go7007_usb_board board_lifeview_lr192 = {
347 .flags = GO7007_USB_EZUSB,
349 .flags = GO7007_BOARD_HAS_AUDIO |
350 GO7007_BOARD_USE_ONBOARD_I2C,
351 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
352 GO7007_AUDIO_WORD_16,
357 .sensor_flags = GO7007_SENSOR_656 |
358 GO7007_SENSOR_VALID_ENABLE |
361 GO7007_SENSOR_SCALING,
373 static const struct go7007_usb_board board_endura = {
377 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
378 GO7007_AUDIO_I2S_MASTER |
379 GO7007_AUDIO_WORD_16,
381 .audio_bclk_div = 48,
384 .sensor_flags = GO7007_SENSOR_656 |
386 .sensor_h_offset = 8,
397 static const struct go7007_usb_board board_adlink_mpg24 = {
400 .flags = GO7007_BOARD_USE_ONBOARD_I2C,
401 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
402 GO7007_AUDIO_I2S_MASTER |
403 GO7007_AUDIO_WORD_16,
408 .sensor_flags = GO7007_SENSOR_656 |
415 .addr = 0x00, /* yes, really */
416 .flags = I2C_CLIENT_TEN,
429 static const struct go7007_usb_board board_sensoray_2250 = {
430 .flags = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
432 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
433 GO7007_AUDIO_I2S_MASTER |
434 GO7007_AUDIO_WORD_16,
435 .flags = GO7007_BOARD_HAS_AUDIO,
440 .sensor_flags = GO7007_SENSOR_656 |
480 static const struct go7007_usb_board board_ads_usbav_709 = {
481 .flags = GO7007_USB_EZUSB,
483 .flags = GO7007_BOARD_HAS_AUDIO |
484 GO7007_BOARD_USE_ONBOARD_I2C,
485 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
486 GO7007_AUDIO_I2S_MASTER |
487 GO7007_AUDIO_WORD_16,
492 .sensor_flags = GO7007_SENSOR_656 |
517 static const struct usb_device_id go7007_usb_id_table[] = {
519 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
520 USB_DEVICE_ID_MATCH_INT_INFO,
521 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
522 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
523 .bcdDevice_lo = 0x200, /* Revision number of XMen */
524 .bcdDevice_hi = 0x200,
525 .bInterfaceClass = 255,
526 .bInterfaceSubClass = 0,
527 .bInterfaceProtocol = 255,
528 .driver_info = (kernel_ulong_t)GO7007_BOARDID_XMEN,
531 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
532 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
533 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
534 .bcdDevice_lo = 0x202, /* Revision number of Matrix II */
535 .bcdDevice_hi = 0x202,
536 .driver_info = (kernel_ulong_t)GO7007_BOARDID_MATRIX_II,
539 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
540 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
541 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
542 .bcdDevice_lo = 0x204, /* Revision number of Matrix */
543 .bcdDevice_hi = 0x204, /* Reloaded */
544 .driver_info = (kernel_ulong_t)GO7007_BOARDID_MATRIX_RELOAD,
547 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
548 USB_DEVICE_ID_MATCH_INT_INFO,
549 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
550 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
551 .bcdDevice_lo = 0x205, /* Revision number of XMen-II */
552 .bcdDevice_hi = 0x205,
553 .bInterfaceClass = 255,
554 .bInterfaceSubClass = 0,
555 .bInterfaceProtocol = 255,
556 .driver_info = (kernel_ulong_t)GO7007_BOARDID_XMEN_II,
559 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
560 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
561 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
562 .bcdDevice_lo = 0x208, /* Revision number of Star Trek */
563 .bcdDevice_hi = 0x208,
564 .driver_info = (kernel_ulong_t)GO7007_BOARDID_STAR_TREK,
567 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
568 USB_DEVICE_ID_MATCH_INT_INFO,
569 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
570 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
571 .bcdDevice_lo = 0x209, /* Revision number of XMen-III */
572 .bcdDevice_hi = 0x209,
573 .bInterfaceClass = 255,
574 .bInterfaceSubClass = 0,
575 .bInterfaceProtocol = 255,
576 .driver_info = (kernel_ulong_t)GO7007_BOARDID_XMEN_III,
579 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
580 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
581 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
582 .bcdDevice_lo = 0x210, /* Revision number of Matrix */
583 .bcdDevice_hi = 0x210, /* Revolution */
584 .driver_info = (kernel_ulong_t)GO7007_BOARDID_MATRIX_REV,
587 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
588 .idVendor = 0x093b, /* Vendor ID of Plextor */
589 .idProduct = 0xa102, /* Product ID of M402U */
590 .bcdDevice_lo = 0x1, /* revision number of Blueberry */
592 .driver_info = (kernel_ulong_t)GO7007_BOARDID_PX_M402U,
595 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
596 .idVendor = 0x093b, /* Vendor ID of Plextor */
597 .idProduct = 0xa104, /* Product ID of TV402U */
600 .driver_info = (kernel_ulong_t)GO7007_BOARDID_PX_TV402U,
603 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
604 .idVendor = 0x10fd, /* Vendor ID of Anubis Electronics */
605 .idProduct = 0xde00, /* Product ID of Lifeview LR192 */
608 .driver_info = (kernel_ulong_t)GO7007_BOARDID_LIFEVIEW_LR192,
611 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
612 .idVendor = 0x1943, /* Vendor ID Sensoray */
613 .idProduct = 0x2250, /* Product ID of 2250/2251 */
616 .driver_info = (kernel_ulong_t)GO7007_BOARDID_SENSORAY_2250,
619 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
620 .idVendor = 0x06e1, /* Vendor ID of ADS Technologies */
621 .idProduct = 0x0709, /* Product ID of DVD Xpress DX2 */
622 .bcdDevice_lo = 0x204,
623 .bcdDevice_hi = 0x204,
624 .driver_info = (kernel_ulong_t)GO7007_BOARDID_ADS_USBAV_709,
626 { } /* Terminating entry */
629 MODULE_DEVICE_TABLE(usb, go7007_usb_id_table);
631 /********************* Driver for EZ-USB HPI interface *********************/
633 static int go7007_usb_vendor_request(struct go7007 *go, int request,
634 int value, int index, void *transfer_buffer, int length, int in)
636 struct go7007_usb *usb = go->hpi_context;
640 return usb_control_msg(usb->usbdev,
641 usb_rcvctrlpipe(usb->usbdev, 0), request,
642 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
643 value, index, transfer_buffer, length, timeout);
645 return usb_control_msg(usb->usbdev,
646 usb_sndctrlpipe(usb->usbdev, 0), request,
647 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
648 value, index, transfer_buffer, length, timeout);
652 static int go7007_usb_interface_reset(struct go7007 *go)
654 struct go7007_usb *usb = go->hpi_context;
655 u16 intr_val, intr_data;
657 if (go->status == STATUS_SHUTDOWN)
660 if (go7007_write_interrupt(go, 0x0001, 0x0001) < 0)
664 if (usb->board->flags & GO7007_USB_EZUSB) {
665 /* Reset buffer in EZ-USB */
666 pr_debug("resetting EZ-USB buffers\n");
667 if (go7007_usb_vendor_request(go, 0x10, 0, 0, NULL, 0, 0) < 0 ||
668 go7007_usb_vendor_request(go, 0x10, 0, 0, NULL, 0, 0) < 0)
671 /* Reset encoder again */
672 if (go7007_write_interrupt(go, 0x0001, 0x0001) < 0)
677 /* Wait for an interrupt to indicate successful hardware reset */
678 if (go7007_read_interrupt(go, &intr_val, &intr_data) < 0 ||
679 (intr_val & ~0x1) != 0x55aa) {
680 dev_err(go->dev, "unable to reset the USB interface\n");
686 static int go7007_usb_ezusb_write_interrupt(struct go7007 *go,
689 struct go7007_usb *usb = go->hpi_context;
694 pr_debug("WriteInterrupt: %04x %04x\n", addr, data);
696 for (i = 0; i < 100; ++i) {
697 r = usb_control_msg(usb->usbdev,
698 usb_rcvctrlpipe(usb->usbdev, 0), 0x14,
699 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
700 0, HPI_STATUS_ADDR, go->usb_buf,
701 sizeof(status_reg), timeout);
704 status_reg = le16_to_cpu(*((u16 *)go->usb_buf));
705 if (!(status_reg & 0x0010))
710 goto write_int_error;
712 dev_err(go->dev, "device is hung, status reg = 0x%04x\n", status_reg);
715 r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 0), 0x12,
716 USB_TYPE_VENDOR | USB_RECIP_DEVICE, data,
717 INT_PARAM_ADDR, NULL, 0, timeout);
719 goto write_int_error;
720 r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 0),
721 0x12, USB_TYPE_VENDOR | USB_RECIP_DEVICE, addr,
722 INT_INDEX_ADDR, NULL, 0, timeout);
724 goto write_int_error;
728 dev_err(go->dev, "error in WriteInterrupt: %d\n", r);
732 static int go7007_usb_onboard_write_interrupt(struct go7007 *go,
735 struct go7007_usb *usb = go->hpi_context;
739 pr_debug("WriteInterrupt: %04x %04x\n", addr, data);
741 go->usb_buf[0] = data & 0xff;
742 go->usb_buf[1] = data >> 8;
743 go->usb_buf[2] = addr & 0xff;
744 go->usb_buf[3] = addr >> 8;
745 go->usb_buf[4] = go->usb_buf[5] = go->usb_buf[6] = go->usb_buf[7] = 0;
746 r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 2), 0x00,
747 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 0x55aa,
748 0xf0f0, go->usb_buf, 8, timeout);
750 dev_err(go->dev, "error in WriteInterrupt: %d\n", r);
756 static void go7007_usb_readinterrupt_complete(struct urb *urb)
758 struct go7007 *go = (struct go7007 *)urb->context;
759 u16 *regs = (u16 *)urb->transfer_buffer;
760 int status = urb->status;
763 if (status != -ESHUTDOWN &&
764 go->status != STATUS_SHUTDOWN) {
765 dev_err(go->dev, "error in read interrupt: %d\n", urb->status);
767 wake_up(&go->interrupt_waitq);
770 } else if (urb->actual_length != urb->transfer_buffer_length) {
771 dev_err(go->dev, "short read in interrupt pipe!\n");
773 go->interrupt_available = 1;
774 go->interrupt_data = __le16_to_cpu(regs[0]);
775 go->interrupt_value = __le16_to_cpu(regs[1]);
776 pr_debug("ReadInterrupt: %04x %04x\n",
777 go->interrupt_value, go->interrupt_data);
780 wake_up(&go->interrupt_waitq);
783 static int go7007_usb_read_interrupt(struct go7007 *go)
785 struct go7007_usb *usb = go->hpi_context;
788 r = usb_submit_urb(usb->intr_urb, GFP_KERNEL);
790 dev_err(go->dev, "unable to submit interrupt urb: %d\n", r);
796 static void go7007_usb_read_video_pipe_complete(struct urb *urb)
798 struct go7007 *go = (struct go7007 *)urb->context;
799 int r, status = urb->status;
801 if (!vb2_is_streaming(&go->vidq)) {
802 wake_up_interruptible(&go->frame_waitq);
806 dev_err(go->dev, "error in video pipe: %d\n", status);
809 if (urb->actual_length != urb->transfer_buffer_length) {
810 dev_err(go->dev, "short read in video pipe!\n");
813 go7007_parse_video_stream(go, urb->transfer_buffer, urb->actual_length);
814 r = usb_submit_urb(urb, GFP_ATOMIC);
816 dev_err(go->dev, "error in video pipe: %d\n", r);
819 static void go7007_usb_read_audio_pipe_complete(struct urb *urb)
821 struct go7007 *go = (struct go7007 *)urb->context;
822 int r, status = urb->status;
824 if (!vb2_is_streaming(&go->vidq))
827 dev_err(go->dev, "error in audio pipe: %d\n",
831 if (urb->actual_length != urb->transfer_buffer_length) {
832 dev_err(go->dev, "short read in audio pipe!\n");
835 if (go->audio_deliver != NULL)
836 go->audio_deliver(go, urb->transfer_buffer, urb->actual_length);
837 r = usb_submit_urb(urb, GFP_ATOMIC);
839 dev_err(go->dev, "error in audio pipe: %d\n", r);
842 static int go7007_usb_stream_start(struct go7007 *go)
844 struct go7007_usb *usb = go->hpi_context;
847 for (i = 0; i < 8; ++i) {
848 r = usb_submit_urb(usb->video_urbs[i], GFP_KERNEL);
850 dev_err(go->dev, "error submitting video urb %d: %d\n", i, r);
851 goto video_submit_failed;
854 if (!go->audio_enabled)
857 for (i = 0; i < 8; ++i) {
858 r = usb_submit_urb(usb->audio_urbs[i], GFP_KERNEL);
860 dev_err(go->dev, "error submitting audio urb %d: %d\n", i, r);
861 goto audio_submit_failed;
867 for (i = 0; i < 7; ++i)
868 usb_kill_urb(usb->audio_urbs[i]);
870 for (i = 0; i < 8; ++i)
871 usb_kill_urb(usb->video_urbs[i]);
875 static int go7007_usb_stream_stop(struct go7007 *go)
877 struct go7007_usb *usb = go->hpi_context;
880 if (go->status == STATUS_SHUTDOWN)
882 for (i = 0; i < 8; ++i)
883 usb_kill_urb(usb->video_urbs[i]);
884 if (go->audio_enabled)
885 for (i = 0; i < 8; ++i)
886 usb_kill_urb(usb->audio_urbs[i]);
890 static int go7007_usb_send_firmware(struct go7007 *go, u8 *data, int len)
892 struct go7007_usb *usb = go->hpi_context;
893 int transferred, pipe;
896 pr_debug("DownloadBuffer sending %d bytes\n", len);
898 if (usb->board->flags & GO7007_USB_EZUSB)
899 pipe = usb_sndbulkpipe(usb->usbdev, 2);
901 pipe = usb_sndbulkpipe(usb->usbdev, 3);
903 return usb_bulk_msg(usb->usbdev, pipe, data, len,
904 &transferred, timeout);
907 static void go7007_usb_release(struct go7007 *go)
909 struct go7007_usb *usb = go->hpi_context;
910 struct urb *vurb, *aurb;
914 usb_kill_urb(usb->intr_urb);
915 kfree(usb->intr_urb->transfer_buffer);
916 usb_free_urb(usb->intr_urb);
919 /* Free USB-related structs */
920 for (i = 0; i < 8; ++i) {
921 vurb = usb->video_urbs[i];
924 kfree(vurb->transfer_buffer);
927 aurb = usb->audio_urbs[i];
930 kfree(aurb->transfer_buffer);
935 kfree(go->hpi_context);
938 static struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops = {
939 .interface_reset = go7007_usb_interface_reset,
940 .write_interrupt = go7007_usb_ezusb_write_interrupt,
941 .read_interrupt = go7007_usb_read_interrupt,
942 .stream_start = go7007_usb_stream_start,
943 .stream_stop = go7007_usb_stream_stop,
944 .send_firmware = go7007_usb_send_firmware,
945 .release = go7007_usb_release,
948 static struct go7007_hpi_ops go7007_usb_onboard_hpi_ops = {
949 .interface_reset = go7007_usb_interface_reset,
950 .write_interrupt = go7007_usb_onboard_write_interrupt,
951 .read_interrupt = go7007_usb_read_interrupt,
952 .stream_start = go7007_usb_stream_start,
953 .stream_stop = go7007_usb_stream_stop,
954 .send_firmware = go7007_usb_send_firmware,
955 .release = go7007_usb_release,
958 /********************* Driver for EZ-USB I2C adapter *********************/
960 static int go7007_usb_i2c_master_xfer(struct i2c_adapter *adapter,
961 struct i2c_msg msgs[], int num)
963 struct go7007 *go = i2c_get_adapdata(adapter);
964 struct go7007_usb *usb = go->hpi_context;
965 u8 *buf = go->usb_buf;
969 if (go->status == STATUS_SHUTDOWN)
972 mutex_lock(&usb->i2c_lock);
974 for (i = 0; i < num; ++i) {
975 /* The hardware command is "write some bytes then read some
976 * bytes", so we try to coalesce a write followed by a read
977 * into a single USB transaction */
978 if (i + 1 < num && msgs[i].addr == msgs[i + 1].addr &&
979 !(msgs[i].flags & I2C_M_RD) &&
980 (msgs[i + 1].flags & I2C_M_RD)) {
981 #ifdef GO7007_I2C_DEBUG
982 pr_debug("i2c write/read %d/%d bytes on %02x\n",
983 msgs[i].len, msgs[i + 1].len, msgs[i].addr);
986 buf[1] = msgs[i].len + 1;
987 buf[2] = msgs[i].addr << 1;
988 memcpy(&buf[3], msgs[i].buf, msgs[i].len);
989 buf_len = msgs[i].len + 3;
990 buf[buf_len++] = msgs[++i].len;
991 } else if (msgs[i].flags & I2C_M_RD) {
992 #ifdef GO7007_I2C_DEBUG
993 pr_debug("i2c read %d bytes on %02x\n",
994 msgs[i].len, msgs[i].addr);
998 buf[2] = msgs[i].addr << 1;
999 buf[3] = msgs[i].len;
1002 #ifdef GO7007_I2C_DEBUG
1003 pr_debug("i2c write %d bytes on %02x\n",
1004 msgs[i].len, msgs[i].addr);
1007 buf[1] = msgs[i].len + 1;
1008 buf[2] = msgs[i].addr << 1;
1009 memcpy(&buf[3], msgs[i].buf, msgs[i].len);
1010 buf_len = msgs[i].len + 3;
1013 if (go7007_usb_vendor_request(go, 0x24, 0, 0,
1014 buf, buf_len, 0) < 0)
1016 if (msgs[i].flags & I2C_M_RD) {
1017 memset(buf, 0, msgs[i].len + 1);
1018 if (go7007_usb_vendor_request(go, 0x25, 0, 0, buf,
1019 msgs[i].len + 1, 1) < 0)
1021 memcpy(msgs[i].buf, buf + 1, msgs[i].len);
1027 mutex_unlock(&usb->i2c_lock);
1031 static u32 go7007_usb_functionality(struct i2c_adapter *adapter)
1033 /* No errors are reported by the hardware, so we don't bother
1034 * supporting quick writes to avoid confusing probing */
1035 return (I2C_FUNC_SMBUS_EMUL) & ~I2C_FUNC_SMBUS_QUICK;
1038 static struct i2c_algorithm go7007_usb_algo = {
1039 .master_xfer = go7007_usb_i2c_master_xfer,
1040 .functionality = go7007_usb_functionality,
1043 static struct i2c_adapter go7007_usb_adap_templ = {
1044 .owner = THIS_MODULE,
1045 .name = "WIS GO7007SB EZ-USB",
1046 .algo = &go7007_usb_algo,
1049 /********************* USB add/remove functions *********************/
1051 static int go7007_usb_probe(struct usb_interface *intf,
1052 const struct usb_device_id *id)
1055 struct go7007_usb *usb;
1056 const struct go7007_usb_board *board;
1057 struct usb_device *usbdev = interface_to_usbdev(intf);
1058 unsigned num_i2c_devs;
1060 int video_pipe, i, v_urb_len;
1062 pr_debug("probing new GO7007 USB board\n");
1064 switch (id->driver_info) {
1065 case GO7007_BOARDID_MATRIX_II:
1066 name = "WIS Matrix II or compatible";
1067 board = &board_matrix_ii;
1069 case GO7007_BOARDID_MATRIX_RELOAD:
1070 name = "WIS Matrix Reloaded or compatible";
1071 board = &board_matrix_reload;
1073 case GO7007_BOARDID_MATRIX_REV:
1074 name = "WIS Matrix Revolution or compatible";
1075 board = &board_matrix_revolution;
1077 case GO7007_BOARDID_STAR_TREK:
1078 name = "WIS Star Trek or compatible";
1079 board = &board_star_trek;
1081 case GO7007_BOARDID_XMEN:
1082 name = "WIS XMen or compatible";
1083 board = &board_xmen;
1085 case GO7007_BOARDID_XMEN_II:
1086 name = "WIS XMen II or compatible";
1087 board = &board_xmen;
1089 case GO7007_BOARDID_XMEN_III:
1090 name = "WIS XMen III or compatible";
1091 board = &board_xmen;
1093 case GO7007_BOARDID_PX_M402U:
1094 name = "Plextor PX-M402U";
1095 board = &board_matrix_ii;
1097 case GO7007_BOARDID_PX_TV402U:
1098 name = "Plextor PX-TV402U (unknown tuner)";
1099 board = &board_px_tv402u;
1101 case GO7007_BOARDID_LIFEVIEW_LR192:
1102 dev_err(&intf->dev, "The Lifeview TV Walker Ultra is not supported. Sorry!\n");
1104 name = "Lifeview TV Walker Ultra";
1105 board = &board_lifeview_lr192;
1107 case GO7007_BOARDID_SENSORAY_2250:
1108 dev_info(&intf->dev, "Sensoray 2250 found\n");
1109 name = "Sensoray 2250/2251";
1110 board = &board_sensoray_2250;
1112 case GO7007_BOARDID_ADS_USBAV_709:
1113 name = "ADS Tech DVD Xpress DX2";
1114 board = &board_ads_usbav_709;
1117 dev_err(&intf->dev, "unknown board ID %d!\n",
1118 (unsigned int)id->driver_info);
1122 go = go7007_alloc(&board->main_info, &intf->dev);
1126 usb = kzalloc(sizeof(struct go7007_usb), GFP_KERNEL);
1133 usb->usbdev = usbdev;
1134 usb_make_path(usbdev, go->bus_info, sizeof(go->bus_info));
1135 go->board_id = id->driver_info;
1136 strncpy(go->name, name, sizeof(go->name));
1137 if (board->flags & GO7007_USB_EZUSB)
1138 go->hpi_ops = &go7007_usb_ezusb_hpi_ops;
1140 go->hpi_ops = &go7007_usb_onboard_hpi_ops;
1141 go->hpi_context = usb;
1143 /* Allocate the URB and buffer for receiving incoming interrupts */
1144 usb->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
1145 if (usb->intr_urb == NULL)
1147 usb->intr_urb->transfer_buffer = kmalloc(2*sizeof(u16), GFP_KERNEL);
1148 if (usb->intr_urb->transfer_buffer == NULL)
1151 if (go->board_id == GO7007_BOARDID_SENSORAY_2250)
1152 usb_fill_bulk_urb(usb->intr_urb, usb->usbdev,
1153 usb_rcvbulkpipe(usb->usbdev, 4),
1154 usb->intr_urb->transfer_buffer, 2*sizeof(u16),
1155 go7007_usb_readinterrupt_complete, go);
1157 usb_fill_int_urb(usb->intr_urb, usb->usbdev,
1158 usb_rcvintpipe(usb->usbdev, 4),
1159 usb->intr_urb->transfer_buffer, 2*sizeof(u16),
1160 go7007_usb_readinterrupt_complete, go, 8);
1161 usb_set_intfdata(intf, &go->v4l2_dev);
1163 /* Boot the GO7007 */
1164 if (go7007_boot_encoder(go, go->board_info->flags &
1165 GO7007_BOARD_USE_ONBOARD_I2C) < 0)
1168 /* Register the EZ-USB I2C adapter, if we're using it */
1169 if (board->flags & GO7007_USB_EZUSB_I2C) {
1170 memcpy(&go->i2c_adapter, &go7007_usb_adap_templ,
1171 sizeof(go7007_usb_adap_templ));
1172 mutex_init(&usb->i2c_lock);
1173 go->i2c_adapter.dev.parent = go->dev;
1174 i2c_set_adapdata(&go->i2c_adapter, go);
1175 if (i2c_add_adapter(&go->i2c_adapter) < 0) {
1176 dev_err(go->dev, "error: i2c_add_adapter failed\n");
1179 go->i2c_adapter_online = 1;
1182 /* Pelco and Adlink reused the XMen and XMen-III vendor and product
1183 * IDs for their own incompatible designs. We can detect XMen boards
1184 * by probing the sensor, but there is no way to probe the sensors on
1185 * the Pelco and Adlink designs so we default to the Adlink. If it
1186 * is actually a Pelco, the user must set the assume_endura module
1188 if ((go->board_id == GO7007_BOARDID_XMEN ||
1189 go->board_id == GO7007_BOARDID_XMEN_III) &&
1190 go->i2c_adapter_online) {
1191 union i2c_smbus_data data;
1193 /* Check to see if register 0x0A is 0x76 */
1194 i2c_smbus_xfer(&go->i2c_adapter, 0x21, I2C_CLIENT_SCCB,
1195 I2C_SMBUS_READ, 0x0A, I2C_SMBUS_BYTE_DATA, &data);
1196 if (data.byte != 0x76) {
1197 if (assume_endura) {
1198 go->board_id = GO7007_BOARDID_ENDURA;
1199 usb->board = board = &board_endura;
1200 go->board_info = &board->main_info;
1201 strncpy(go->name, "Pelco Endura",
1206 /* read channel number from GPIO[1:0] */
1207 go7007_read_addr(go, 0x3c81, &channel);
1209 go->board_id = GO7007_BOARDID_ADLINK_MPG24;
1210 usb->board = board = &board_adlink_mpg24;
1211 go->board_info = &board->main_info;
1212 go->channel_number = channel;
1213 snprintf(go->name, sizeof(go->name),
1214 "Adlink PCI-MPG24, channel #%d",
1217 go7007_update_board(go);
1221 num_i2c_devs = go->board_info->num_i2c_devs;
1223 /* Probe the tuner model on the TV402U */
1224 if (go->board_id == GO7007_BOARDID_PX_TV402U) {
1225 /* Board strapping indicates tuner model */
1226 if (go7007_usb_vendor_request(go, 0x41, 0, 0, go->usb_buf, 3,
1228 dev_err(go->dev, "GPIO read failed!\n");
1231 switch (go->usb_buf[0] >> 6) {
1233 go->tuner_type = TUNER_SONY_BTF_PG472Z;
1234 go->std = V4L2_STD_PAL;
1235 strncpy(go->name, "Plextor PX-TV402U-EU",
1239 go->tuner_type = TUNER_SONY_BTF_PK467Z;
1240 go->std = V4L2_STD_NTSC_M_JP;
1242 strncpy(go->name, "Plextor PX-TV402U-JP",
1246 go->tuner_type = TUNER_SONY_BTF_PB463Z;
1248 strncpy(go->name, "Plextor PX-TV402U-NA",
1252 pr_debug("unable to detect tuner type!\n");
1255 /* Configure tuner mode selection inputs connected
1256 * to the EZ-USB GPIO output pins */
1257 if (go7007_usb_vendor_request(go, 0x40, 0x7f02, 0,
1259 dev_err(go->dev, "GPIO write failed!\n");
1264 /* Print a nasty message if the user attempts to use a USB2.0 device in
1265 * a USB1.1 port. There will be silent corruption of the stream. */
1266 if ((board->flags & GO7007_USB_EZUSB) &&
1267 usbdev->speed != USB_SPEED_HIGH)
1268 dev_err(go->dev, "*** WARNING *** This device must be connected to a USB 2.0 port! Attempting to capture video through a USB 1.1 port will result in stream corruption, even at low bitrates!\n");
1270 /* Allocate the URBs and buffers for receiving the video stream */
1271 if (board->flags & GO7007_USB_EZUSB) {
1273 video_pipe = usb_rcvbulkpipe(usb->usbdev, 6);
1276 video_pipe = usb_rcvbulkpipe(usb->usbdev, 1);
1278 for (i = 0; i < 8; ++i) {
1279 usb->video_urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
1280 if (usb->video_urbs[i] == NULL)
1282 usb->video_urbs[i]->transfer_buffer =
1283 kmalloc(v_urb_len, GFP_KERNEL);
1284 if (usb->video_urbs[i]->transfer_buffer == NULL)
1286 usb_fill_bulk_urb(usb->video_urbs[i], usb->usbdev, video_pipe,
1287 usb->video_urbs[i]->transfer_buffer, v_urb_len,
1288 go7007_usb_read_video_pipe_complete, go);
1291 /* Allocate the URBs and buffers for receiving the audio stream */
1292 if ((board->flags & GO7007_USB_EZUSB) &&
1293 (board->flags & GO7007_BOARD_HAS_AUDIO)) {
1294 for (i = 0; i < 8; ++i) {
1295 usb->audio_urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
1296 if (usb->audio_urbs[i] == NULL)
1298 usb->audio_urbs[i]->transfer_buffer = kmalloc(4096,
1300 if (usb->audio_urbs[i]->transfer_buffer == NULL)
1302 usb_fill_bulk_urb(usb->audio_urbs[i], usb->usbdev,
1303 usb_rcvbulkpipe(usb->usbdev, 8),
1304 usb->audio_urbs[i]->transfer_buffer, 4096,
1305 go7007_usb_read_audio_pipe_complete, go);
1309 /* Do any final GO7007 initialization, then register the
1310 * V4L2 and ALSA interfaces */
1311 if (go7007_register_encoder(go, num_i2c_devs) < 0)
1314 go->status = STATUS_ONLINE;
1318 go7007_usb_release(go);
1323 static void go7007_usb_disconnect(struct usb_interface *intf)
1325 struct go7007 *go = to_go7007(usb_get_intfdata(intf));
1327 mutex_lock(&go->queue_lock);
1328 mutex_lock(&go->serialize_lock);
1330 if (go->audio_enabled)
1331 go7007_snd_remove(go);
1333 go->status = STATUS_SHUTDOWN;
1334 v4l2_device_disconnect(&go->v4l2_dev);
1335 video_unregister_device(&go->vdev);
1336 mutex_unlock(&go->serialize_lock);
1337 mutex_unlock(&go->queue_lock);
1339 v4l2_device_put(&go->v4l2_dev);
1342 static struct usb_driver go7007_usb_driver = {
1344 .probe = go7007_usb_probe,
1345 .disconnect = go7007_usb_disconnect,
1346 .id_table = go7007_usb_id_table,
1349 module_usb_driver(go7007_usb_driver);
1350 MODULE_LICENSE("GPL v2");