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 usb_device_id go7007_usb_id_table[] = {
403 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
404 USB_DEVICE_ID_MATCH_INT_INFO,
405 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
406 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
407 .bcdDevice_lo = 0x200, /* Revision number of XMen */
408 .bcdDevice_hi = 0x200,
409 .bInterfaceClass = 255,
410 .bInterfaceSubClass = 0,
411 .bInterfaceProtocol = 255,
412 .driver_info = (kernel_ulong_t)GO7007_BOARDID_XMEN,
415 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
416 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
417 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
418 .bcdDevice_lo = 0x202, /* Revision number of Matrix II */
419 .bcdDevice_hi = 0x202,
420 .driver_info = (kernel_ulong_t)GO7007_BOARDID_MATRIX_II,
423 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
424 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
425 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
426 .bcdDevice_lo = 0x204, /* Revision number of Matrix */
427 .bcdDevice_hi = 0x204, /* Reloaded */
428 .driver_info = (kernel_ulong_t)GO7007_BOARDID_MATRIX_RELOAD,
431 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
432 USB_DEVICE_ID_MATCH_INT_INFO,
433 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
434 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
435 .bcdDevice_lo = 0x205, /* Revision number of XMen-II */
436 .bcdDevice_hi = 0x205,
437 .bInterfaceClass = 255,
438 .bInterfaceSubClass = 0,
439 .bInterfaceProtocol = 255,
440 .driver_info = (kernel_ulong_t)GO7007_BOARDID_XMEN_II,
443 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
444 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
445 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
446 .bcdDevice_lo = 0x208, /* Revision number of Star Trek */
447 .bcdDevice_hi = 0x208,
448 .driver_info = (kernel_ulong_t)GO7007_BOARDID_STAR_TREK,
451 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
452 USB_DEVICE_ID_MATCH_INT_INFO,
453 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
454 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
455 .bcdDevice_lo = 0x209, /* Revision number of XMen-III */
456 .bcdDevice_hi = 0x209,
457 .bInterfaceClass = 255,
458 .bInterfaceSubClass = 0,
459 .bInterfaceProtocol = 255,
460 .driver_info = (kernel_ulong_t)GO7007_BOARDID_XMEN_III,
463 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
464 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
465 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
466 .bcdDevice_lo = 0x210, /* Revision number of Matrix */
467 .bcdDevice_hi = 0x210, /* Revolution */
468 .driver_info = (kernel_ulong_t)GO7007_BOARDID_MATRIX_REV,
471 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
472 .idVendor = 0x093b, /* Vendor ID of Plextor */
473 .idProduct = 0xa102, /* Product ID of M402U */
474 .bcdDevice_lo = 0x1, /* revision number of Blueberry */
476 .driver_info = (kernel_ulong_t)GO7007_BOARDID_PX_M402U,
479 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
480 .idVendor = 0x093b, /* Vendor ID of Plextor */
481 .idProduct = 0xa104, /* Product ID of TV402U */
484 .driver_info = (kernel_ulong_t)GO7007_BOARDID_PX_TV402U_ANY,
487 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
488 .idVendor = 0x10fd, /* Vendor ID of Anubis Electronics */
489 .idProduct = 0xde00, /* Product ID of Lifeview LR192 */
492 .driver_info = (kernel_ulong_t)GO7007_BOARDID_LIFEVIEW_LR192,
494 { } /* Terminating entry */
497 MODULE_DEVICE_TABLE(usb, go7007_usb_id_table);
499 /********************* Driver for EZ-USB HPI interface *********************/
501 static int go7007_usb_vendor_request(struct go7007 *go, int request,
502 int value, int index, void *transfer_buffer, int length, int in)
504 struct go7007_usb *usb = go->hpi_context;
508 return usb_control_msg(usb->usbdev,
509 usb_rcvctrlpipe(usb->usbdev, 0), request,
510 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
511 value, index, transfer_buffer, length, timeout);
513 return usb_control_msg(usb->usbdev,
514 usb_sndctrlpipe(usb->usbdev, 0), request,
515 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
516 value, index, transfer_buffer, length, timeout);
520 static int go7007_usb_interface_reset(struct go7007 *go)
522 struct go7007_usb *usb = go->hpi_context;
523 u16 intr_val, intr_data;
526 if (go7007_write_interrupt(go, 0x0001, 0x0001) < 0)
530 if (usb->board->flags & GO7007_USB_EZUSB) {
531 /* Reset buffer in EZ-USB */
532 #ifdef GO7007_USB_DEBUG
533 printk(KERN_DEBUG "go7007-usb: resetting EZ-USB buffers\n");
535 if (go7007_usb_vendor_request(go, 0x10, 0, 0, NULL, 0, 0) < 0 ||
536 go7007_usb_vendor_request(go, 0x10, 0, 0, NULL, 0, 0) < 0)
539 /* Reset encoder again */
540 if (go7007_write_interrupt(go, 0x0001, 0x0001) < 0)
545 /* Wait for an interrupt to indicate successful hardware reset */
546 if (go7007_read_interrupt(go, &intr_val, &intr_data) < 0 ||
547 (intr_val & ~0x1) != 0x55aa) {
549 "go7007-usb: unable to reset the USB interface\n");
555 static int go7007_usb_ezusb_write_interrupt(struct go7007 *go,
558 struct go7007_usb *usb = go->hpi_context;
563 #ifdef GO7007_USB_DEBUG
565 "go7007-usb: WriteInterrupt: %04x %04x\n", addr, data);
568 for (i = 0; i < 100; ++i) {
569 r = usb_control_msg(usb->usbdev,
570 usb_rcvctrlpipe(usb->usbdev, 0), 0x14,
571 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
572 0, HPI_STATUS_ADDR, &status_reg,
573 sizeof(status_reg), timeout);
575 goto write_int_error;
576 __le16_to_cpus(&status_reg);
577 if (!(status_reg & 0x0010))
583 "go7007-usb: device is hung, status reg = 0x%04x\n",
587 r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 0), 0x12,
588 USB_TYPE_VENDOR | USB_RECIP_DEVICE, data,
589 INT_PARAM_ADDR, NULL, 0, timeout);
591 goto write_int_error;
592 r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 0),
593 0x12, USB_TYPE_VENDOR | USB_RECIP_DEVICE, addr,
594 INT_INDEX_ADDR, NULL, 0, timeout);
596 goto write_int_error;
600 printk(KERN_ERR "go7007-usb: error in WriteInterrupt: %d\n", r);
604 static int go7007_usb_onboard_write_interrupt(struct go7007 *go,
607 struct go7007_usb *usb = go->hpi_context;
612 #ifdef GO7007_USB_DEBUG
614 "go7007-usb: WriteInterrupt: %04x %04x\n", addr, data);
617 tbuf = kmalloc(8, GFP_KERNEL);
621 tbuf[0] = data & 0xff;
623 tbuf[2] = addr & 0xff;
625 r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 2), 0x00,
626 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 0x55aa,
627 0xf0f0, tbuf, 8, timeout);
630 printk(KERN_ERR "go7007-usb: error in WriteInterrupt: %d\n", r);
636 static void go7007_usb_readinterrupt_complete(struct urb *urb)
638 struct go7007 *go = (struct go7007 *)urb->context;
639 u16 *regs = (u16 *)urb->transfer_buffer;
641 if (urb->status != 0) {
642 if (urb->status != -ESHUTDOWN &&
643 go->status != STATUS_SHUTDOWN) {
645 "go7007-usb: error in read interrupt: %d\n",
648 wake_up(&go->interrupt_waitq);
651 } else if (urb->actual_length != urb->transfer_buffer_length) {
652 printk(KERN_ERR "go7007-usb: short read in interrupt pipe!\n");
654 go->interrupt_available = 1;
655 go->interrupt_data = __le16_to_cpu(regs[0]);
656 go->interrupt_value = __le16_to_cpu(regs[1]);
657 #ifdef GO7007_USB_DEBUG
658 printk(KERN_DEBUG "go7007-usb: ReadInterrupt: %04x %04x\n",
659 go->interrupt_value, go->interrupt_data);
663 wake_up(&go->interrupt_waitq);
666 static int go7007_usb_read_interrupt(struct go7007 *go)
668 struct go7007_usb *usb = go->hpi_context;
671 r = usb_submit_urb(usb->intr_urb, GFP_KERNEL);
674 "go7007-usb: unable to submit interrupt urb: %d\n", r);
680 static void go7007_usb_read_video_pipe_complete(struct urb *urb)
682 struct go7007 *go = (struct go7007 *)urb->context;
685 if (!go->streaming) {
686 wake_up_interruptible(&go->frame_waitq);
689 if (urb->status != 0) {
690 printk(KERN_ERR "go7007-usb: error in video pipe: %d\n",
694 if (urb->actual_length != urb->transfer_buffer_length) {
695 printk(KERN_ERR "go7007-usb: short read in video pipe!\n");
698 go7007_parse_video_stream(go, urb->transfer_buffer, urb->actual_length);
699 r = usb_submit_urb(urb, GFP_ATOMIC);
701 printk(KERN_ERR "go7007-usb: error in video pipe: %d\n", r);
704 static void go7007_usb_read_audio_pipe_complete(struct urb *urb)
706 struct go7007 *go = (struct go7007 *)urb->context;
711 if (urb->status != 0) {
712 printk(KERN_ERR "go7007-usb: error in audio pipe: %d\n",
716 if (urb->actual_length != urb->transfer_buffer_length) {
717 printk(KERN_ERR "go7007-usb: short read in audio pipe!\n");
720 if (go->audio_deliver != NULL)
721 go->audio_deliver(go, urb->transfer_buffer, urb->actual_length);
722 r = usb_submit_urb(urb, GFP_ATOMIC);
724 printk(KERN_ERR "go7007-usb: error in audio pipe: %d\n", r);
727 static int go7007_usb_stream_start(struct go7007 *go)
729 struct go7007_usb *usb = go->hpi_context;
732 for (i = 0; i < 8; ++i) {
733 r = usb_submit_urb(usb->video_urbs[i], GFP_KERNEL);
735 printk(KERN_ERR "go7007-usb: error submitting video "
736 "urb %d: %d\n", i, r);
737 goto video_submit_failed;
740 if (!go->audio_enabled)
743 for (i = 0; i < 8; ++i) {
744 r = usb_submit_urb(usb->audio_urbs[i], GFP_KERNEL);
746 printk(KERN_ERR "go7007-usb: error submitting audio "
747 "urb %d: %d\n", i, r);
748 goto audio_submit_failed;
754 for (i = 0; i < 8; ++i)
755 usb_kill_urb(usb->audio_urbs[i]);
757 for (i = 0; i < 8; ++i)
758 usb_kill_urb(usb->video_urbs[i]);
762 static int go7007_usb_stream_stop(struct go7007 *go)
764 struct go7007_usb *usb = go->hpi_context;
767 if (go->status == STATUS_SHUTDOWN)
769 for (i = 0; i < 8; ++i)
770 usb_kill_urb(usb->video_urbs[i]);
771 if (go->audio_enabled)
772 for (i = 0; i < 8; ++i)
773 usb_kill_urb(usb->audio_urbs[i]);
777 static int go7007_usb_send_firmware(struct go7007 *go, u8 *data, int len)
779 struct go7007_usb *usb = go->hpi_context;
780 int transferred, pipe;
783 #ifdef GO7007_USB_DEBUG
784 printk(KERN_DEBUG "go7007-usb: DownloadBuffer sending %d bytes\n", len);
787 if (usb->board->flags & GO7007_USB_EZUSB)
788 pipe = usb_sndbulkpipe(usb->usbdev, 2);
790 pipe = usb_sndbulkpipe(usb->usbdev, 3);
792 return usb_bulk_msg(usb->usbdev, pipe, data, len,
793 &transferred, timeout);
796 static struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops = {
797 .interface_reset = go7007_usb_interface_reset,
798 .write_interrupt = go7007_usb_ezusb_write_interrupt,
799 .read_interrupt = go7007_usb_read_interrupt,
800 .stream_start = go7007_usb_stream_start,
801 .stream_stop = go7007_usb_stream_stop,
802 .send_firmware = go7007_usb_send_firmware,
805 static struct go7007_hpi_ops go7007_usb_onboard_hpi_ops = {
806 .interface_reset = go7007_usb_interface_reset,
807 .write_interrupt = go7007_usb_onboard_write_interrupt,
808 .read_interrupt = go7007_usb_read_interrupt,
809 .stream_start = go7007_usb_stream_start,
810 .stream_stop = go7007_usb_stream_stop,
811 .send_firmware = go7007_usb_send_firmware,
814 /********************* Driver for EZ-USB I2C adapter *********************/
816 static int go7007_usb_i2c_master_xfer(struct i2c_adapter *adapter,
817 struct i2c_msg msgs[], int num)
819 struct go7007 *go = i2c_get_adapdata(adapter);
820 struct go7007_usb *usb = go->hpi_context;
825 if (go->status == STATUS_SHUTDOWN)
828 down(&usb->i2c_lock);
830 for (i = 0; i < num; ++i) {
831 /* The hardware command is "write some bytes then read some
832 * bytes", so we try to coalesce a write followed by a read
833 * into a single USB transaction */
834 if (i + 1 < num && msgs[i].addr == msgs[i + 1].addr &&
835 !(msgs[i].flags & I2C_M_RD) &&
836 (msgs[i + 1].flags & I2C_M_RD)) {
837 #ifdef GO7007_I2C_DEBUG
838 printk(KERN_DEBUG "go7007-usb: i2c write/read %d/%d "
839 "bytes on %02x\n", msgs[i].len,
840 msgs[i + 1].len, msgs[i].addr);
843 buf[1] = msgs[i].len + 1;
844 buf[2] = msgs[i].addr << 1;
845 memcpy(&buf[3], msgs[i].buf, msgs[i].len);
846 buf_len = msgs[i].len + 3;
847 buf[buf_len++] = msgs[++i].len;
848 } else if (msgs[i].flags & I2C_M_RD) {
849 #ifdef GO7007_I2C_DEBUG
850 printk(KERN_DEBUG "go7007-usb: i2c read %d "
851 "bytes on %02x\n", msgs[i].len,
856 buf[2] = msgs[i].addr << 1;
857 buf[3] = msgs[i].len;
860 #ifdef GO7007_I2C_DEBUG
861 printk(KERN_DEBUG "go7007-usb: i2c write %d "
862 "bytes on %02x\n", msgs[i].len,
866 buf[1] = msgs[i].len + 1;
867 buf[2] = msgs[i].addr << 1;
868 memcpy(&buf[3], msgs[i].buf, msgs[i].len);
869 buf_len = msgs[i].len + 3;
872 if (go7007_usb_vendor_request(go, 0x24, 0, 0,
873 buf, buf_len, 0) < 0)
875 if (msgs[i].flags & I2C_M_RD) {
876 memset(buf, 0, sizeof(buf));
877 if (go7007_usb_vendor_request(go, 0x25, 0, 0, buf,
878 msgs[i].len + 1, 1) < 0)
880 memcpy(msgs[i].buf, buf + 1, msgs[i].len);
890 static u32 go7007_usb_functionality(struct i2c_adapter *adapter)
892 /* No errors are reported by the hardware, so we don't bother
893 * supporting quick writes to avoid confusing probing */
894 return (I2C_FUNC_SMBUS_EMUL) & ~I2C_FUNC_SMBUS_QUICK;
897 static struct i2c_algorithm go7007_usb_algo = {
898 .master_xfer = go7007_usb_i2c_master_xfer,
899 .functionality = go7007_usb_functionality,
902 static struct i2c_adapter go7007_usb_adap_templ = {
903 .owner = THIS_MODULE,
904 .class = I2C_CLASS_TV_ANALOG,
905 .name = "WIS GO7007SB EZ-USB",
906 .id = I2C_ALGO_GO7007_USB,
907 .algo = &go7007_usb_algo,
910 /********************* USB add/remove functions *********************/
912 static int go7007_usb_probe(struct usb_interface *intf,
913 const struct usb_device_id *id)
916 struct go7007_usb *usb;
917 struct go7007_usb_board *board;
918 struct usb_device *usbdev = interface_to_usbdev(intf);
920 int video_pipe, i, v_urb_len;
922 printk(KERN_DEBUG "go7007-usb: probing new GO7007 USB board\n");
924 switch (id->driver_info) {
925 case GO7007_BOARDID_MATRIX_II:
926 name = "WIS Matrix II or compatible";
927 board = &board_matrix_ii;
929 case GO7007_BOARDID_MATRIX_RELOAD:
930 name = "WIS Matrix Reloaded or compatible";
931 board = &board_matrix_reload;
933 case GO7007_BOARDID_MATRIX_REV:
934 name = "WIS Matrix Revolution or compatible";
935 board = &board_matrix_revolution;
937 case GO7007_BOARDID_STAR_TREK:
938 name = "WIS Star Trek or compatible";
939 board = &board_star_trek;
941 case GO7007_BOARDID_XMEN:
942 name = "WIS XMen or compatible";
945 case GO7007_BOARDID_XMEN_II:
946 name = "WIS XMen II or compatible";
949 case GO7007_BOARDID_XMEN_III:
950 name = "WIS XMen III or compatible";
953 case GO7007_BOARDID_PX_M402U:
954 name = "Plextor PX-M402U";
955 board = &board_matrix_ii;
957 case GO7007_BOARDID_PX_TV402U_ANY:
958 name = "Plextor PX-TV402U (unknown tuner)";
959 board = &board_px_tv402u;
961 case GO7007_BOARDID_LIFEVIEW_LR192:
962 printk(KERN_ERR "go7007-usb: The Lifeview TV Walker Ultra "
963 "is not supported. Sorry!\n");
965 name = "Lifeview TV Walker Ultra";
966 board = &board_lifeview_lr192;
969 printk(KERN_ERR "go7007-usb: unknown board ID %d!\n",
970 (unsigned int)id->driver_info);
974 usb = kmalloc(sizeof(struct go7007_usb), GFP_KERNEL);
977 memset(usb, 0, sizeof(struct go7007_usb));
979 /* Allocate the URB and buffer for receiving incoming interrupts */
980 usb->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
981 if (usb->intr_urb == NULL)
983 usb->intr_urb->transfer_buffer = kmalloc(2*sizeof(u16), GFP_KERNEL);
984 if (usb->intr_urb->transfer_buffer == NULL)
987 go = go7007_alloc(&board->main_info, &intf->dev);
991 usb->usbdev = usbdev;
992 go->board_id = id->driver_info;
993 strncpy(go->name, name, sizeof(go->name));
994 if (board->flags & GO7007_USB_EZUSB)
995 go->hpi_ops = &go7007_usb_ezusb_hpi_ops;
997 go->hpi_ops = &go7007_usb_onboard_hpi_ops;
998 go->hpi_context = usb;
999 usb_fill_int_urb(usb->intr_urb, usb->usbdev,
1000 usb_rcvintpipe(usb->usbdev, 4),
1001 usb->intr_urb->transfer_buffer, 2*sizeof(u16),
1002 go7007_usb_readinterrupt_complete, go, 8);
1003 usb_set_intfdata(intf, go);
1005 /* Boot the GO7007 */
1006 if (go7007_boot_encoder(go, go->board_info->flags &
1007 GO7007_BOARD_USE_ONBOARD_I2C) < 0)
1010 /* Register the EZ-USB I2C adapter, if we're using it */
1011 if (board->flags & GO7007_USB_EZUSB_I2C) {
1012 memcpy(&go->i2c_adapter, &go7007_usb_adap_templ,
1013 sizeof(go7007_usb_adap_templ));
1014 init_MUTEX(&usb->i2c_lock);
1015 go->i2c_adapter.dev.parent = go->dev;
1016 i2c_set_adapdata(&go->i2c_adapter, go);
1017 if (i2c_add_adapter(&go->i2c_adapter) < 0) {
1019 "go7007-usb: error: i2c_add_adapter failed\n");
1022 go->i2c_adapter_online = 1;
1025 /* Pelco and Adlink reused the XMen and XMen-III vendor and product
1026 * IDs for their own incompatible designs. We can detect XMen boards
1027 * by probing the sensor, but there is no way to probe the sensors on
1028 * the Pelco and Adlink designs so we default to the Adlink. If it
1029 * is actually a Pelco, the user must set the assume_endura module
1031 if ((go->board_id == GO7007_BOARDID_XMEN ||
1032 go->board_id == GO7007_BOARDID_XMEN_III) &&
1033 go->i2c_adapter_online) {
1034 union i2c_smbus_data data;
1036 /* Check to see if register 0x0A is 0x76 */
1037 i2c_smbus_xfer(&go->i2c_adapter, 0x21, I2C_CLIENT_SCCB,
1038 I2C_SMBUS_READ, 0x0A, I2C_SMBUS_BYTE_DATA, &data);
1039 if (data.byte != 0x76) {
1040 if (assume_endura) {
1041 go->board_id = GO7007_BOARDID_ENDURA;
1042 usb->board = board = &board_endura;
1043 go->board_info = &board->main_info;
1044 strncpy(go->name, "Pelco Endura",
1049 /* set GPIO5 to be an output, currently low */
1050 go7007_write_addr(go, 0x3c82, 0x0000);
1051 go7007_write_addr(go, 0x3c80, 0x00df);
1052 /* read channel number from GPIO[1:0] */
1053 go7007_read_addr(go, 0x3c81, &channel);
1055 go->board_id = GO7007_BOARDID_ADLINK_MPG24;
1056 usb->board = board = &board_adlink_mpg24;
1057 go->board_info = &board->main_info;
1058 go->channel_number = channel;
1059 snprintf(go->name, sizeof(go->name),
1060 "Adlink PCI-MPG24, channel #%d",
1066 /* Probe the tuner model on the TV402U */
1067 if (go->board_id == GO7007_BOARDID_PX_TV402U_ANY) {
1070 /* Board strapping indicates tuner model */
1071 if (go7007_usb_vendor_request(go, 0x41, 0, 0, data, 3, 1) < 0) {
1072 printk(KERN_ERR "go7007-usb: GPIO read failed!\n");
1075 switch (data[0] >> 6) {
1077 go->board_id = GO7007_BOARDID_PX_TV402U_EU;
1078 go->tuner_type = TUNER_SONY_BTF_PG472Z;
1079 strncpy(go->name, "Plextor PX-TV402U-EU",
1083 go->board_id = GO7007_BOARDID_PX_TV402U_JP;
1084 go->tuner_type = TUNER_SONY_BTF_PK467Z;
1085 strncpy(go->name, "Plextor PX-TV402U-JP",
1089 go->board_id = GO7007_BOARDID_PX_TV402U_NA;
1090 go->tuner_type = TUNER_SONY_BTF_PB463Z;
1091 strncpy(go->name, "Plextor PX-TV402U-NA",
1095 printk(KERN_DEBUG "go7007-usb: unable to detect "
1099 /* Configure tuner mode selection inputs connected
1100 * to the EZ-USB GPIO output pins */
1101 if (go7007_usb_vendor_request(go, 0x40, 0x7f02, 0,
1104 "go7007-usb: GPIO write failed!\n");
1109 /* Print a nasty message if the user attempts to use a USB2.0 device in
1110 * a USB1.1 port. There will be silent corruption of the stream. */
1111 if ((board->flags & GO7007_USB_EZUSB) &&
1112 usbdev->speed != USB_SPEED_HIGH)
1113 printk(KERN_ERR "go7007-usb: *** WARNING *** This device "
1114 "must be connected to a USB 2.0 port! "
1115 "Attempting to capture video through a USB 1.1 "
1116 "port will result in stream corruption, even "
1117 "at low bitrates!\n");
1119 /* Do any final GO7007 initialization, then register the
1120 * V4L2 and ALSA interfaces */
1121 if (go7007_register_encoder(go) < 0)
1124 /* Allocate the URBs and buffers for receiving the video stream */
1125 if (board->flags & GO7007_USB_EZUSB) {
1127 video_pipe = usb_rcvbulkpipe(usb->usbdev, 6);
1130 video_pipe = usb_rcvbulkpipe(usb->usbdev, 1);
1132 for (i = 0; i < 8; ++i) {
1133 usb->video_urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
1134 if (usb->video_urbs[i] == NULL)
1136 usb->video_urbs[i]->transfer_buffer =
1137 kmalloc(v_urb_len, GFP_KERNEL);
1138 if (usb->video_urbs[i]->transfer_buffer == NULL)
1140 usb_fill_bulk_urb(usb->video_urbs[i], usb->usbdev, video_pipe,
1141 usb->video_urbs[i]->transfer_buffer, v_urb_len,
1142 go7007_usb_read_video_pipe_complete, go);
1145 /* Allocate the URBs and buffers for receiving the audio stream */
1146 if ((board->flags & GO7007_USB_EZUSB) && go->audio_enabled)
1147 for (i = 0; i < 8; ++i) {
1148 usb->audio_urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
1149 if (usb->audio_urbs[i] == NULL)
1151 usb->audio_urbs[i]->transfer_buffer = kmalloc(4096,
1153 if (usb->audio_urbs[i]->transfer_buffer == NULL)
1155 usb_fill_bulk_urb(usb->audio_urbs[i], usb->usbdev,
1156 usb_rcvbulkpipe(usb->usbdev, 8),
1157 usb->audio_urbs[i]->transfer_buffer, 4096,
1158 go7007_usb_read_audio_pipe_complete, go);
1162 go->status = STATUS_ONLINE;
1166 go->status = STATUS_SHUTDOWN;
1170 if (usb->intr_urb) {
1171 kfree(usb->intr_urb->transfer_buffer);
1172 usb_free_urb(usb->intr_urb);
1178 static void go7007_usb_disconnect(struct usb_interface *intf)
1180 struct go7007 *go = usb_get_intfdata(intf);
1181 struct go7007_usb *usb = go->hpi_context;
1184 go->status = STATUS_SHUTDOWN;
1185 usb_kill_urb(usb->intr_urb);
1187 /* Free USB-related structs */
1188 for (i = 0; i < 8; ++i) {
1189 if (usb->video_urbs[i] != NULL) {
1190 if (usb->video_urbs[i]->transfer_buffer != NULL)
1191 kfree(usb->video_urbs[i]->transfer_buffer);
1192 usb_free_urb(usb->video_urbs[i]);
1194 if (usb->audio_urbs[i] != NULL) {
1195 if (usb->audio_urbs[i]->transfer_buffer != NULL)
1196 kfree(usb->audio_urbs[i]->transfer_buffer);
1197 usb_free_urb(usb->audio_urbs[i]);
1200 kfree(usb->intr_urb->transfer_buffer);
1201 usb_free_urb(usb->intr_urb);
1203 kfree(go->hpi_context);
1208 static struct usb_driver go7007_usb_driver = {
1210 .probe = go7007_usb_probe,
1211 .disconnect = go7007_usb_disconnect,
1212 .id_table = go7007_usb_id_table,
1215 static int __init go7007_usb_init(void)
1217 return usb_register(&go7007_usb_driver);
1220 static void __exit go7007_usb_cleanup(void)
1222 usb_deregister(&go7007_usb_driver);
1225 module_init(go7007_usb_init);
1226 module_exit(go7007_usb_cleanup);
1228 MODULE_LICENSE("GPL v2");