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 #include <linux/module.h>
19 #include <linux/kernel.h>
20 #include <linux/init.h>
21 #include <linux/wait.h>
22 #include <linux/list.h>
23 #include <linux/slab.h>
24 #include <linux/time.h>
26 #include <linux/usb.h>
27 #include <linux/i2c.h>
28 #include <asm/byteorder.h>
29 #include <media/tvaudio.h>
31 #include "go7007-priv.h"
34 static unsigned int assume_endura;
35 module_param(assume_endura, int, 0644);
36 MODULE_PARM_DESC(assume_endura, "when probing fails, hardware is a Pelco Endura");
38 /* #define GO7007_USB_DEBUG */
39 /* #define GO7007_I2C_DEBUG */ /* for debugging the EZ-USB I2C adapter */
41 #define HPI_STATUS_ADDR 0xFFF4
42 #define INT_PARAM_ADDR 0xFFF6
43 #define INT_INDEX_ADDR 0xFFF8
46 * Pipes on EZ-USB interface:
49 * 2 snd - Download firmware (control)
50 * 4 rcv - Read Interrupt (interrupt)
51 * 6 rcv - Read Video (bulk)
52 * 8 rcv - Read Audio (bulk)
55 #define GO7007_USB_EZUSB (1<<0)
56 #define GO7007_USB_EZUSB_I2C (1<<1)
58 struct go7007_usb_board {
60 struct go7007_board_info main_info;
64 struct go7007_usb_board *board;
65 struct semaphore i2c_lock;
66 struct usb_device *usbdev;
67 struct urb *video_urbs[8];
68 struct urb *audio_urbs[8];
72 /*********************** Product specification data ***********************/
74 static struct go7007_usb_board board_matrix_ii = {
75 .flags = GO7007_USB_EZUSB,
77 .firmware = "go7007tv.bin",
78 .flags = GO7007_BOARD_HAS_AUDIO |
79 GO7007_BOARD_USE_ONBOARD_I2C,
80 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
86 .sensor_flags = GO7007_SENSOR_656 |
87 GO7007_SENSOR_VALID_ENABLE |
90 GO7007_SENSOR_SCALING,
94 .id = I2C_DRIVERID_WIS_SAA7115,
112 static struct go7007_usb_board board_matrix_reload = {
113 .flags = GO7007_USB_EZUSB,
115 .firmware = "go7007tv.bin",
116 .flags = GO7007_BOARD_HAS_AUDIO |
117 GO7007_BOARD_USE_ONBOARD_I2C,
118 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
119 GO7007_AUDIO_I2S_MASTER |
120 GO7007_AUDIO_WORD_16,
125 .sensor_flags = GO7007_SENSOR_656 |
130 .id = I2C_DRIVERID_WIS_SAA7113,
148 static struct go7007_usb_board board_star_trek = {
149 .flags = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
151 .firmware = "go7007tv.bin",
152 .flags = GO7007_BOARD_HAS_AUDIO, /* |
153 GO7007_BOARD_HAS_TUNER, */
154 .sensor_flags = GO7007_SENSOR_656 |
155 GO7007_SENSOR_VALID_ENABLE |
158 GO7007_SENSOR_SCALING,
159 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
160 GO7007_AUDIO_WORD_16,
167 .id = I2C_DRIVERID_WIS_SAA7115,
175 /* .audio_input = AUDIO_EXTERN, */
180 /* .audio_input = AUDIO_EXTERN, */
185 * .audio_input = AUDIO_TUNER,
193 static struct go7007_usb_board board_px_tv402u = {
194 .flags = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
196 .firmware = "go7007tv.bin",
197 .flags = GO7007_BOARD_HAS_AUDIO |
198 GO7007_BOARD_HAS_TUNER,
199 .sensor_flags = GO7007_SENSOR_656 |
200 GO7007_SENSOR_VALID_ENABLE |
203 GO7007_SENSOR_SCALING,
204 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
205 GO7007_AUDIO_WORD_16,
212 .id = I2C_DRIVERID_WIS_SAA7115,
216 .id = I2C_DRIVERID_WIS_UDA1342,
220 .id = I2C_DRIVERID_WIS_SONY_TUNER,
228 .audio_input = TVAUDIO_INPUT_EXTERN,
233 .audio_input = TVAUDIO_INPUT_EXTERN,
238 .audio_input = TVAUDIO_INPUT_TUNER,
245 static struct go7007_usb_board board_xmen = {
248 .firmware = "go7007tv.bin",
249 .flags = GO7007_BOARD_USE_ONBOARD_I2C,
251 .sensor_flags = GO7007_SENSOR_VREF_POLAR,
253 .sensor_height = 240,
254 .sensor_framerate = 30030,
255 .audio_flags = GO7007_AUDIO_ONE_CHANNEL |
256 GO7007_AUDIO_I2S_MODE_3 |
257 GO7007_AUDIO_WORD_14 |
258 GO7007_AUDIO_I2S_MASTER |
259 GO7007_AUDIO_BCLK_POLAR |
260 GO7007_AUDIO_OKI_MODE,
262 .audio_bclk_div = 48,
267 .id = I2C_DRIVERID_WIS_OV7640,
280 static struct go7007_usb_board board_matrix_revolution = {
281 .flags = GO7007_USB_EZUSB,
283 .firmware = "go7007tv.bin",
284 .flags = GO7007_BOARD_HAS_AUDIO |
285 GO7007_BOARD_USE_ONBOARD_I2C,
286 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
287 GO7007_AUDIO_I2S_MASTER |
288 GO7007_AUDIO_WORD_16,
293 .sensor_flags = GO7007_SENSOR_656 |
299 .id = I2C_DRIVERID_WIS_TW9903,
317 static struct go7007_usb_board board_lifeview_lr192 = {
318 .flags = GO7007_USB_EZUSB,
320 .firmware = "go7007tv.bin",
321 .flags = GO7007_BOARD_HAS_AUDIO |
322 GO7007_BOARD_USE_ONBOARD_I2C,
323 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
324 GO7007_AUDIO_WORD_16,
329 .sensor_flags = GO7007_SENSOR_656 |
330 GO7007_SENSOR_VALID_ENABLE |
333 GO7007_SENSOR_SCALING,
345 static struct go7007_usb_board board_endura = {
348 .firmware = "go7007tv.bin",
350 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
351 GO7007_AUDIO_I2S_MASTER |
352 GO7007_AUDIO_WORD_16,
354 .audio_bclk_div = 48,
357 .sensor_flags = GO7007_SENSOR_656 |
359 .sensor_h_offset = 8,
370 static struct go7007_usb_board board_adlink_mpg24 = {
373 .firmware = "go7007tv.bin",
374 .flags = GO7007_BOARD_USE_ONBOARD_I2C,
375 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
376 GO7007_AUDIO_I2S_MASTER |
377 GO7007_AUDIO_WORD_16,
382 .sensor_flags = GO7007_SENSOR_656 |
388 .id = I2C_DRIVERID_WIS_TW2804,
389 .addr = 0x00, /* yes, really */
401 static struct go7007_usb_board board_sensoray_2250 = {
402 .flags = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
404 .firmware = "go7007tv.bin",
405 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
406 GO7007_AUDIO_I2S_MASTER |
407 GO7007_AUDIO_WORD_16,
408 .flags = GO7007_BOARD_HAS_AUDIO,
413 .sensor_flags = GO7007_SENSOR_656 |
418 .id = I2C_DRIVERID_S2250,
436 static struct usb_device_id go7007_usb_id_table[] = {
438 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
439 USB_DEVICE_ID_MATCH_INT_INFO,
440 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
441 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
442 .bcdDevice_lo = 0x200, /* Revision number of XMen */
443 .bcdDevice_hi = 0x200,
444 .bInterfaceClass = 255,
445 .bInterfaceSubClass = 0,
446 .bInterfaceProtocol = 255,
447 .driver_info = (kernel_ulong_t)GO7007_BOARDID_XMEN,
450 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
451 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
452 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
453 .bcdDevice_lo = 0x202, /* Revision number of Matrix II */
454 .bcdDevice_hi = 0x202,
455 .driver_info = (kernel_ulong_t)GO7007_BOARDID_MATRIX_II,
458 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
459 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
460 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
461 .bcdDevice_lo = 0x204, /* Revision number of Matrix */
462 .bcdDevice_hi = 0x204, /* Reloaded */
463 .driver_info = (kernel_ulong_t)GO7007_BOARDID_MATRIX_RELOAD,
466 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
467 USB_DEVICE_ID_MATCH_INT_INFO,
468 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
469 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
470 .bcdDevice_lo = 0x205, /* Revision number of XMen-II */
471 .bcdDevice_hi = 0x205,
472 .bInterfaceClass = 255,
473 .bInterfaceSubClass = 0,
474 .bInterfaceProtocol = 255,
475 .driver_info = (kernel_ulong_t)GO7007_BOARDID_XMEN_II,
478 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
479 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
480 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
481 .bcdDevice_lo = 0x208, /* Revision number of Star Trek */
482 .bcdDevice_hi = 0x208,
483 .driver_info = (kernel_ulong_t)GO7007_BOARDID_STAR_TREK,
486 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
487 USB_DEVICE_ID_MATCH_INT_INFO,
488 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
489 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
490 .bcdDevice_lo = 0x209, /* Revision number of XMen-III */
491 .bcdDevice_hi = 0x209,
492 .bInterfaceClass = 255,
493 .bInterfaceSubClass = 0,
494 .bInterfaceProtocol = 255,
495 .driver_info = (kernel_ulong_t)GO7007_BOARDID_XMEN_III,
498 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
499 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
500 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
501 .bcdDevice_lo = 0x210, /* Revision number of Matrix */
502 .bcdDevice_hi = 0x210, /* Revolution */
503 .driver_info = (kernel_ulong_t)GO7007_BOARDID_MATRIX_REV,
506 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
507 .idVendor = 0x093b, /* Vendor ID of Plextor */
508 .idProduct = 0xa102, /* Product ID of M402U */
509 .bcdDevice_lo = 0x1, /* revision number of Blueberry */
511 .driver_info = (kernel_ulong_t)GO7007_BOARDID_PX_M402U,
514 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
515 .idVendor = 0x093b, /* Vendor ID of Plextor */
516 .idProduct = 0xa104, /* Product ID of TV402U */
519 .driver_info = (kernel_ulong_t)GO7007_BOARDID_PX_TV402U_ANY,
522 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
523 .idVendor = 0x10fd, /* Vendor ID of Anubis Electronics */
524 .idProduct = 0xde00, /* Product ID of Lifeview LR192 */
527 .driver_info = (kernel_ulong_t)GO7007_BOARDID_LIFEVIEW_LR192,
530 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
531 .idVendor = 0x1943, /* Vendor ID Sensoray */
532 .idProduct = 0x2250, /* Product ID of 2250/2251 */
535 .driver_info = (kernel_ulong_t)GO7007_BOARDID_SENSORAY_2250,
537 { } /* Terminating entry */
540 MODULE_DEVICE_TABLE(usb, go7007_usb_id_table);
542 /********************* Driver for EZ-USB HPI interface *********************/
544 static int go7007_usb_vendor_request(struct go7007 *go, int request,
545 int value, int index, void *transfer_buffer, int length, int in)
547 struct go7007_usb *usb = go->hpi_context;
551 return usb_control_msg(usb->usbdev,
552 usb_rcvctrlpipe(usb->usbdev, 0), request,
553 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
554 value, index, transfer_buffer, length, timeout);
556 return usb_control_msg(usb->usbdev,
557 usb_sndctrlpipe(usb->usbdev, 0), request,
558 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
559 value, index, transfer_buffer, length, timeout);
563 static int go7007_usb_interface_reset(struct go7007 *go)
565 struct go7007_usb *usb = go->hpi_context;
566 u16 intr_val, intr_data;
569 if (go7007_write_interrupt(go, 0x0001, 0x0001) < 0)
573 if (usb->board->flags & GO7007_USB_EZUSB) {
574 /* Reset buffer in EZ-USB */
575 #ifdef GO7007_USB_DEBUG
576 printk(KERN_DEBUG "go7007-usb: resetting EZ-USB buffers\n");
578 if (go7007_usb_vendor_request(go, 0x10, 0, 0, NULL, 0, 0) < 0 ||
579 go7007_usb_vendor_request(go, 0x10, 0, 0, NULL, 0, 0) < 0)
582 /* Reset encoder again */
583 if (go7007_write_interrupt(go, 0x0001, 0x0001) < 0)
588 /* Wait for an interrupt to indicate successful hardware reset */
589 if (go7007_read_interrupt(go, &intr_val, &intr_data) < 0 ||
590 (intr_val & ~0x1) != 0x55aa) {
592 "go7007-usb: unable to reset the USB interface\n");
598 static int go7007_usb_ezusb_write_interrupt(struct go7007 *go,
601 struct go7007_usb *usb = go->hpi_context;
606 #ifdef GO7007_USB_DEBUG
608 "go7007-usb: WriteInterrupt: %04x %04x\n", addr, data);
611 for (i = 0; i < 100; ++i) {
612 r = usb_control_msg(usb->usbdev,
613 usb_rcvctrlpipe(usb->usbdev, 0), 0x14,
614 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
615 0, HPI_STATUS_ADDR, &status_reg,
616 sizeof(status_reg), timeout);
618 goto write_int_error;
619 __le16_to_cpus(&status_reg);
620 if (!(status_reg & 0x0010))
626 "go7007-usb: device is hung, status reg = 0x%04x\n",
630 r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 0), 0x12,
631 USB_TYPE_VENDOR | USB_RECIP_DEVICE, data,
632 INT_PARAM_ADDR, NULL, 0, timeout);
634 goto write_int_error;
635 r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 0),
636 0x12, USB_TYPE_VENDOR | USB_RECIP_DEVICE, addr,
637 INT_INDEX_ADDR, NULL, 0, timeout);
639 goto write_int_error;
643 printk(KERN_ERR "go7007-usb: error in WriteInterrupt: %d\n", r);
647 static int go7007_usb_onboard_write_interrupt(struct go7007 *go,
650 struct go7007_usb *usb = go->hpi_context;
655 #ifdef GO7007_USB_DEBUG
657 "go7007-usb: WriteInterrupt: %04x %04x\n", addr, data);
660 tbuf = kmalloc(8, GFP_KERNEL);
664 tbuf[0] = data & 0xff;
666 tbuf[2] = addr & 0xff;
668 r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 2), 0x00,
669 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 0x55aa,
670 0xf0f0, tbuf, 8, timeout);
673 printk(KERN_ERR "go7007-usb: error in WriteInterrupt: %d\n", r);
679 static void go7007_usb_readinterrupt_complete(struct urb *urb)
681 struct go7007 *go = (struct go7007 *)urb->context;
682 u16 *regs = (u16 *)urb->transfer_buffer;
683 int status = urb->status;
686 if (status != -ESHUTDOWN &&
687 go->status != STATUS_SHUTDOWN) {
689 "go7007-usb: error in read interrupt: %d\n",
692 wake_up(&go->interrupt_waitq);
695 } else if (urb->actual_length != urb->transfer_buffer_length) {
696 printk(KERN_ERR "go7007-usb: short read in interrupt pipe!\n");
698 go->interrupt_available = 1;
699 go->interrupt_data = __le16_to_cpu(regs[0]);
700 go->interrupt_value = __le16_to_cpu(regs[1]);
701 #ifdef GO7007_USB_DEBUG
702 printk(KERN_DEBUG "go7007-usb: ReadInterrupt: %04x %04x\n",
703 go->interrupt_value, go->interrupt_data);
707 wake_up(&go->interrupt_waitq);
710 static int go7007_usb_read_interrupt(struct go7007 *go)
712 struct go7007_usb *usb = go->hpi_context;
715 r = usb_submit_urb(usb->intr_urb, GFP_KERNEL);
718 "go7007-usb: unable to submit interrupt urb: %d\n", r);
724 static void go7007_usb_read_video_pipe_complete(struct urb *urb)
726 struct go7007 *go = (struct go7007 *)urb->context;
727 int r, status = urb-> status;
729 if (!go->streaming) {
730 wake_up_interruptible(&go->frame_waitq);
734 printk(KERN_ERR "go7007-usb: error in video pipe: %d\n", status);
737 if (urb->actual_length != urb->transfer_buffer_length) {
738 printk(KERN_ERR "go7007-usb: short read in video pipe!\n");
741 go7007_parse_video_stream(go, urb->transfer_buffer, urb->actual_length);
742 r = usb_submit_urb(urb, GFP_ATOMIC);
744 printk(KERN_ERR "go7007-usb: error in video pipe: %d\n", r);
747 static void go7007_usb_read_audio_pipe_complete(struct urb *urb)
749 struct go7007 *go = (struct go7007 *)urb->context;
750 int r, status = urb->status;
755 printk(KERN_ERR "go7007-usb: error in audio pipe: %d\n", status);
758 if (urb->actual_length != urb->transfer_buffer_length) {
759 printk(KERN_ERR "go7007-usb: short read in audio pipe!\n");
762 if (go->audio_deliver != NULL)
763 go->audio_deliver(go, urb->transfer_buffer, urb->actual_length);
764 r = usb_submit_urb(urb, GFP_ATOMIC);
766 printk(KERN_ERR "go7007-usb: error in audio pipe: %d\n", r);
769 static int go7007_usb_stream_start(struct go7007 *go)
771 struct go7007_usb *usb = go->hpi_context;
774 for (i = 0; i < 8; ++i) {
775 r = usb_submit_urb(usb->video_urbs[i], GFP_KERNEL);
777 printk(KERN_ERR "go7007-usb: error submitting video "
778 "urb %d: %d\n", i, r);
779 goto video_submit_failed;
782 if (!go->audio_enabled)
785 for (i = 0; i < 8; ++i) {
786 r = usb_submit_urb(usb->audio_urbs[i], GFP_KERNEL);
788 printk(KERN_ERR "go7007-usb: error submitting audio "
789 "urb %d: %d\n", i, r);
790 goto audio_submit_failed;
796 for (i = 0; i < 7; ++i)
797 usb_kill_urb(usb->audio_urbs[i]);
799 for (i = 0; i < 8; ++i)
800 usb_kill_urb(usb->video_urbs[i]);
804 static int go7007_usb_stream_stop(struct go7007 *go)
806 struct go7007_usb *usb = go->hpi_context;
809 if (go->status == STATUS_SHUTDOWN)
811 for (i = 0; i < 8; ++i)
812 usb_kill_urb(usb->video_urbs[i]);
813 if (go->audio_enabled)
814 for (i = 0; i < 8; ++i)
815 usb_kill_urb(usb->audio_urbs[i]);
819 static int go7007_usb_send_firmware(struct go7007 *go, u8 *data, int len)
821 struct go7007_usb *usb = go->hpi_context;
822 int transferred, pipe;
825 #ifdef GO7007_USB_DEBUG
826 printk(KERN_DEBUG "go7007-usb: DownloadBuffer sending %d bytes\n", len);
829 if (usb->board->flags & GO7007_USB_EZUSB)
830 pipe = usb_sndbulkpipe(usb->usbdev, 2);
832 pipe = usb_sndbulkpipe(usb->usbdev, 3);
834 return usb_bulk_msg(usb->usbdev, pipe, data, len,
835 &transferred, timeout);
838 static struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops = {
839 .interface_reset = go7007_usb_interface_reset,
840 .write_interrupt = go7007_usb_ezusb_write_interrupt,
841 .read_interrupt = go7007_usb_read_interrupt,
842 .stream_start = go7007_usb_stream_start,
843 .stream_stop = go7007_usb_stream_stop,
844 .send_firmware = go7007_usb_send_firmware,
847 static struct go7007_hpi_ops go7007_usb_onboard_hpi_ops = {
848 .interface_reset = go7007_usb_interface_reset,
849 .write_interrupt = go7007_usb_onboard_write_interrupt,
850 .read_interrupt = go7007_usb_read_interrupt,
851 .stream_start = go7007_usb_stream_start,
852 .stream_stop = go7007_usb_stream_stop,
853 .send_firmware = go7007_usb_send_firmware,
856 /********************* Driver for EZ-USB I2C adapter *********************/
858 static int go7007_usb_i2c_master_xfer(struct i2c_adapter *adapter,
859 struct i2c_msg msgs[], int num)
861 struct go7007 *go = i2c_get_adapdata(adapter);
862 struct go7007_usb *usb = go->hpi_context;
867 if (go->status == STATUS_SHUTDOWN)
870 down(&usb->i2c_lock);
872 for (i = 0; i < num; ++i) {
873 /* The hardware command is "write some bytes then read some
874 * bytes", so we try to coalesce a write followed by a read
875 * into a single USB transaction */
876 if (i + 1 < num && msgs[i].addr == msgs[i + 1].addr &&
877 !(msgs[i].flags & I2C_M_RD) &&
878 (msgs[i + 1].flags & I2C_M_RD)) {
879 #ifdef GO7007_I2C_DEBUG
880 printk(KERN_DEBUG "go7007-usb: i2c write/read %d/%d "
881 "bytes on %02x\n", msgs[i].len,
882 msgs[i + 1].len, msgs[i].addr);
885 buf[1] = msgs[i].len + 1;
886 buf[2] = msgs[i].addr << 1;
887 memcpy(&buf[3], msgs[i].buf, msgs[i].len);
888 buf_len = msgs[i].len + 3;
889 buf[buf_len++] = msgs[++i].len;
890 } else if (msgs[i].flags & I2C_M_RD) {
891 #ifdef GO7007_I2C_DEBUG
892 printk(KERN_DEBUG "go7007-usb: i2c read %d "
893 "bytes on %02x\n", msgs[i].len,
898 buf[2] = msgs[i].addr << 1;
899 buf[3] = msgs[i].len;
902 #ifdef GO7007_I2C_DEBUG
903 printk(KERN_DEBUG "go7007-usb: i2c write %d "
904 "bytes on %02x\n", msgs[i].len,
908 buf[1] = msgs[i].len + 1;
909 buf[2] = msgs[i].addr << 1;
910 memcpy(&buf[3], msgs[i].buf, msgs[i].len);
911 buf_len = msgs[i].len + 3;
914 if (go7007_usb_vendor_request(go, 0x24, 0, 0,
915 buf, buf_len, 0) < 0)
917 if (msgs[i].flags & I2C_M_RD) {
918 memset(buf, 0, sizeof(buf));
919 if (go7007_usb_vendor_request(go, 0x25, 0, 0, buf,
920 msgs[i].len + 1, 1) < 0)
922 memcpy(msgs[i].buf, buf + 1, msgs[i].len);
932 static u32 go7007_usb_functionality(struct i2c_adapter *adapter)
934 /* No errors are reported by the hardware, so we don't bother
935 * supporting quick writes to avoid confusing probing */
936 return (I2C_FUNC_SMBUS_EMUL) & ~I2C_FUNC_SMBUS_QUICK;
939 static struct i2c_algorithm go7007_usb_algo = {
940 .master_xfer = go7007_usb_i2c_master_xfer,
941 .functionality = go7007_usb_functionality,
944 static struct i2c_adapter go7007_usb_adap_templ = {
945 .owner = THIS_MODULE,
946 .class = I2C_CLASS_TV_ANALOG,
947 .name = "WIS GO7007SB EZ-USB",
948 .id = I2C_ALGO_GO7007_USB,
949 .algo = &go7007_usb_algo,
952 /********************* USB add/remove functions *********************/
954 static int go7007_usb_probe(struct usb_interface *intf,
955 const struct usb_device_id *id)
958 struct go7007_usb *usb;
959 struct go7007_usb_board *board;
960 struct usb_device *usbdev = interface_to_usbdev(intf);
962 int video_pipe, i, v_urb_len;
964 printk(KERN_DEBUG "go7007-usb: probing new GO7007 USB board\n");
966 switch (id->driver_info) {
967 case GO7007_BOARDID_MATRIX_II:
968 name = "WIS Matrix II or compatible";
969 board = &board_matrix_ii;
971 case GO7007_BOARDID_MATRIX_RELOAD:
972 name = "WIS Matrix Reloaded or compatible";
973 board = &board_matrix_reload;
975 case GO7007_BOARDID_MATRIX_REV:
976 name = "WIS Matrix Revolution or compatible";
977 board = &board_matrix_revolution;
979 case GO7007_BOARDID_STAR_TREK:
980 name = "WIS Star Trek or compatible";
981 board = &board_star_trek;
983 case GO7007_BOARDID_XMEN:
984 name = "WIS XMen or compatible";
987 case GO7007_BOARDID_XMEN_II:
988 name = "WIS XMen II or compatible";
991 case GO7007_BOARDID_XMEN_III:
992 name = "WIS XMen III or compatible";
995 case GO7007_BOARDID_PX_M402U:
996 name = "Plextor PX-M402U";
997 board = &board_matrix_ii;
999 case GO7007_BOARDID_PX_TV402U_ANY:
1000 name = "Plextor PX-TV402U (unknown tuner)";
1001 board = &board_px_tv402u;
1003 case GO7007_BOARDID_LIFEVIEW_LR192:
1004 printk(KERN_ERR "go7007-usb: The Lifeview TV Walker Ultra "
1005 "is not supported. Sorry!\n");
1007 name = "Lifeview TV Walker Ultra";
1008 board = &board_lifeview_lr192;
1010 case GO7007_BOARDID_SENSORAY_2250:
1011 printk(KERN_INFO "Sensoray 2250 found\n");
1012 name = "Sensoray 2250/2251\n";
1013 board = &board_sensoray_2250;
1016 printk(KERN_ERR "go7007-usb: unknown board ID %d!\n",
1017 (unsigned int)id->driver_info);
1021 usb = kzalloc(sizeof(struct go7007_usb), GFP_KERNEL);
1025 /* Allocate the URB and buffer for receiving incoming interrupts */
1026 usb->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
1027 if (usb->intr_urb == NULL)
1029 usb->intr_urb->transfer_buffer = kmalloc(2*sizeof(u16), GFP_KERNEL);
1030 if (usb->intr_urb->transfer_buffer == NULL)
1033 go = go7007_alloc(&board->main_info, &intf->dev);
1037 usb->usbdev = usbdev;
1038 go->board_id = id->driver_info;
1039 strncpy(go->name, name, sizeof(go->name));
1040 if (board->flags & GO7007_USB_EZUSB)
1041 go->hpi_ops = &go7007_usb_ezusb_hpi_ops;
1043 go->hpi_ops = &go7007_usb_onboard_hpi_ops;
1044 go->hpi_context = usb;
1045 usb_fill_int_urb(usb->intr_urb, usb->usbdev,
1046 usb_rcvintpipe(usb->usbdev, 4),
1047 usb->intr_urb->transfer_buffer, 2*sizeof(u16),
1048 go7007_usb_readinterrupt_complete, go, 8);
1049 usb_set_intfdata(intf, go);
1051 /* Boot the GO7007 */
1052 if (go7007_boot_encoder(go, go->board_info->flags &
1053 GO7007_BOARD_USE_ONBOARD_I2C) < 0)
1056 /* Register the EZ-USB I2C adapter, if we're using it */
1057 if (board->flags & GO7007_USB_EZUSB_I2C) {
1058 memcpy(&go->i2c_adapter, &go7007_usb_adap_templ,
1059 sizeof(go7007_usb_adap_templ));
1060 init_MUTEX(&usb->i2c_lock);
1061 go->i2c_adapter.dev.parent = go->dev;
1062 i2c_set_adapdata(&go->i2c_adapter, go);
1063 if (i2c_add_adapter(&go->i2c_adapter) < 0) {
1065 "go7007-usb: error: i2c_add_adapter failed\n");
1068 go->i2c_adapter_online = 1;
1071 /* Pelco and Adlink reused the XMen and XMen-III vendor and product
1072 * IDs for their own incompatible designs. We can detect XMen boards
1073 * by probing the sensor, but there is no way to probe the sensors on
1074 * the Pelco and Adlink designs so we default to the Adlink. If it
1075 * is actually a Pelco, the user must set the assume_endura module
1077 if ((go->board_id == GO7007_BOARDID_XMEN ||
1078 go->board_id == GO7007_BOARDID_XMEN_III) &&
1079 go->i2c_adapter_online) {
1080 union i2c_smbus_data data;
1082 /* Check to see if register 0x0A is 0x76 */
1083 i2c_smbus_xfer(&go->i2c_adapter, 0x21, I2C_CLIENT_SCCB,
1084 I2C_SMBUS_READ, 0x0A, I2C_SMBUS_BYTE_DATA, &data);
1085 if (data.byte != 0x76) {
1086 if (assume_endura) {
1087 go->board_id = GO7007_BOARDID_ENDURA;
1088 usb->board = board = &board_endura;
1089 go->board_info = &board->main_info;
1090 strncpy(go->name, "Pelco Endura",
1095 /* set GPIO5 to be an output, currently low */
1096 go7007_write_addr(go, 0x3c82, 0x0000);
1097 go7007_write_addr(go, 0x3c80, 0x00df);
1098 /* read channel number from GPIO[1:0] */
1099 go7007_read_addr(go, 0x3c81, &channel);
1101 go->board_id = GO7007_BOARDID_ADLINK_MPG24;
1102 usb->board = board = &board_adlink_mpg24;
1103 go->board_info = &board->main_info;
1104 go->channel_number = channel;
1105 snprintf(go->name, sizeof(go->name),
1106 "Adlink PCI-MPG24, channel #%d",
1112 /* Probe the tuner model on the TV402U */
1113 if (go->board_id == GO7007_BOARDID_PX_TV402U_ANY) {
1116 /* Board strapping indicates tuner model */
1117 if (go7007_usb_vendor_request(go, 0x41, 0, 0, data, 3, 1) < 0) {
1118 printk(KERN_ERR "go7007-usb: GPIO read failed!\n");
1121 switch (data[0] >> 6) {
1123 go->board_id = GO7007_BOARDID_PX_TV402U_EU;
1124 go->tuner_type = TUNER_SONY_BTF_PG472Z;
1125 strncpy(go->name, "Plextor PX-TV402U-EU",
1129 go->board_id = GO7007_BOARDID_PX_TV402U_JP;
1130 go->tuner_type = TUNER_SONY_BTF_PK467Z;
1131 strncpy(go->name, "Plextor PX-TV402U-JP",
1135 go->board_id = GO7007_BOARDID_PX_TV402U_NA;
1136 go->tuner_type = TUNER_SONY_BTF_PB463Z;
1137 strncpy(go->name, "Plextor PX-TV402U-NA",
1141 printk(KERN_DEBUG "go7007-usb: unable to detect "
1145 /* Configure tuner mode selection inputs connected
1146 * to the EZ-USB GPIO output pins */
1147 if (go7007_usb_vendor_request(go, 0x40, 0x7f02, 0,
1150 "go7007-usb: GPIO write failed!\n");
1155 /* Print a nasty message if the user attempts to use a USB2.0 device in
1156 * a USB1.1 port. There will be silent corruption of the stream. */
1157 if ((board->flags & GO7007_USB_EZUSB) &&
1158 usbdev->speed != USB_SPEED_HIGH)
1159 printk(KERN_ERR "go7007-usb: *** WARNING *** This device "
1160 "must be connected to a USB 2.0 port! "
1161 "Attempting to capture video through a USB 1.1 "
1162 "port will result in stream corruption, even "
1163 "at low bitrates!\n");
1165 /* Do any final GO7007 initialization, then register the
1166 * V4L2 and ALSA interfaces */
1167 if (go7007_register_encoder(go) < 0)
1170 /* Allocate the URBs and buffers for receiving the video stream */
1171 if (board->flags & GO7007_USB_EZUSB) {
1173 video_pipe = usb_rcvbulkpipe(usb->usbdev, 6);
1176 video_pipe = usb_rcvbulkpipe(usb->usbdev, 1);
1178 for (i = 0; i < 8; ++i) {
1179 usb->video_urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
1180 if (usb->video_urbs[i] == NULL)
1182 usb->video_urbs[i]->transfer_buffer =
1183 kmalloc(v_urb_len, GFP_KERNEL);
1184 if (usb->video_urbs[i]->transfer_buffer == NULL)
1186 usb_fill_bulk_urb(usb->video_urbs[i], usb->usbdev, video_pipe,
1187 usb->video_urbs[i]->transfer_buffer, v_urb_len,
1188 go7007_usb_read_video_pipe_complete, go);
1191 /* Allocate the URBs and buffers for receiving the audio stream */
1192 if ((board->flags & GO7007_USB_EZUSB) && go->audio_enabled)
1193 for (i = 0; i < 8; ++i) {
1194 usb->audio_urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
1195 if (usb->audio_urbs[i] == NULL)
1197 usb->audio_urbs[i]->transfer_buffer = kmalloc(4096,
1199 if (usb->audio_urbs[i]->transfer_buffer == NULL)
1201 usb_fill_bulk_urb(usb->audio_urbs[i], usb->usbdev,
1202 usb_rcvbulkpipe(usb->usbdev, 8),
1203 usb->audio_urbs[i]->transfer_buffer, 4096,
1204 go7007_usb_read_audio_pipe_complete, go);
1208 go->status = STATUS_ONLINE;
1212 go->status = STATUS_SHUTDOWN;
1216 if (usb->intr_urb) {
1217 kfree(usb->intr_urb->transfer_buffer);
1218 usb_free_urb(usb->intr_urb);
1224 static void go7007_usb_disconnect(struct usb_interface *intf)
1226 struct go7007 *go = usb_get_intfdata(intf);
1227 struct go7007_usb *usb = go->hpi_context;
1228 struct urb *vurb, *aurb;
1231 go->status = STATUS_SHUTDOWN;
1232 usb_kill_urb(usb->intr_urb);
1234 /* Free USB-related structs */
1235 for (i = 0; i < 8; ++i) {
1236 vurb = usb->video_urbs[i];
1239 if (vurb->transfer_buffer)
1240 kfree(vurb->transfer_buffer);
1243 aurb = usb->audio_urbs[i];
1246 if (aurb->transfer_buffer)
1247 kfree(aurb->transfer_buffer);
1251 kfree(usb->intr_urb->transfer_buffer);
1252 usb_free_urb(usb->intr_urb);
1254 kfree(go->hpi_context);
1259 static struct usb_driver go7007_usb_driver = {
1261 .probe = go7007_usb_probe,
1262 .disconnect = go7007_usb_disconnect,
1263 .id_table = go7007_usb_id_table,
1266 static int __init go7007_usb_init(void)
1268 return usb_register(&go7007_usb_driver);
1271 static void __exit go7007_usb_cleanup(void)
1273 usb_deregister(&go7007_usb_driver);
1276 module_init(go7007_usb_init);
1277 module_exit(go7007_usb_cleanup);
1279 MODULE_LICENSE("GPL v2");