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/version.h>
20 #include <linux/kernel.h>
21 #include <linux/init.h>
22 #include <linux/wait.h>
23 #include <linux/list.h>
24 #include <linux/slab.h>
25 #include <linux/time.h>
27 #include <linux/usb.h>
28 #include <linux/i2c.h>
29 #include <asm/byteorder.h>
30 #include <media/tvaudio.h>
32 #include "go7007-priv.h"
35 static unsigned int assume_endura;
36 module_param(assume_endura, int, 0644);
37 MODULE_PARM_DESC(assume_endura, "when probing fails, hardware is a Pelco Endura");
39 /* #define GO7007_USB_DEBUG */
40 /* #define GO7007_I2C_DEBUG */ /* for debugging the EZ-USB I2C adapter */
42 #define HPI_STATUS_ADDR 0xFFF4
43 #define INT_PARAM_ADDR 0xFFF6
44 #define INT_INDEX_ADDR 0xFFF8
47 * Pipes on EZ-USB interface:
50 * 2 snd - Download firmware (control)
51 * 4 rcv - Read Interrupt (interrupt)
52 * 6 rcv - Read Video (bulk)
53 * 8 rcv - Read Audio (bulk)
56 #define GO7007_USB_EZUSB (1<<0)
57 #define GO7007_USB_EZUSB_I2C (1<<1)
59 struct go7007_usb_board {
61 struct go7007_board_info main_info;
65 struct go7007_usb_board *board;
66 struct semaphore i2c_lock;
67 struct usb_device *usbdev;
68 struct urb *video_urbs[8];
69 struct urb *audio_urbs[8];
73 /*********************** Product specification data ***********************/
75 static struct go7007_usb_board board_matrix_ii = {
76 .flags = GO7007_USB_EZUSB,
78 .firmware = "go7007tv.bin",
79 .flags = GO7007_BOARD_HAS_AUDIO |
80 GO7007_BOARD_USE_ONBOARD_I2C,
81 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
87 .sensor_flags = GO7007_SENSOR_656 |
88 GO7007_SENSOR_VALID_ENABLE |
91 GO7007_SENSOR_SCALING,
95 .id = I2C_DRIVERID_WIS_SAA7115,
113 static struct go7007_usb_board board_matrix_reload = {
114 .flags = GO7007_USB_EZUSB,
116 .firmware = "go7007tv.bin",
117 .flags = GO7007_BOARD_HAS_AUDIO |
118 GO7007_BOARD_USE_ONBOARD_I2C,
119 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
120 GO7007_AUDIO_I2S_MASTER |
121 GO7007_AUDIO_WORD_16,
126 .sensor_flags = GO7007_SENSOR_656 |
131 .id = I2C_DRIVERID_WIS_SAA7113,
149 static struct go7007_usb_board board_star_trek = {
150 .flags = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
152 .firmware = "go7007tv.bin",
153 .flags = GO7007_BOARD_HAS_AUDIO, /* |
154 GO7007_BOARD_HAS_TUNER, */
155 .sensor_flags = GO7007_SENSOR_656 |
156 GO7007_SENSOR_VALID_ENABLE |
159 GO7007_SENSOR_SCALING,
160 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
161 GO7007_AUDIO_WORD_16,
168 .id = I2C_DRIVERID_WIS_SAA7115,
176 /* .audio_input = AUDIO_EXTERN, */
181 /* .audio_input = AUDIO_EXTERN, */
186 * .audio_input = AUDIO_TUNER,
194 static struct go7007_usb_board board_px_tv402u = {
195 .flags = GO7007_USB_EZUSB | GO7007_USB_EZUSB_I2C,
197 .firmware = "go7007tv.bin",
198 .flags = GO7007_BOARD_HAS_AUDIO |
199 GO7007_BOARD_HAS_TUNER,
200 .sensor_flags = GO7007_SENSOR_656 |
201 GO7007_SENSOR_VALID_ENABLE |
204 GO7007_SENSOR_SCALING,
205 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
206 GO7007_AUDIO_WORD_16,
213 .id = I2C_DRIVERID_WIS_SAA7115,
217 .id = I2C_DRIVERID_WIS_UDA1342,
221 .id = I2C_DRIVERID_WIS_SONY_TUNER,
229 .audio_input = TVAUDIO_INPUT_EXTERN,
234 .audio_input = TVAUDIO_INPUT_EXTERN,
239 .audio_input = TVAUDIO_INPUT_TUNER,
246 static struct go7007_usb_board board_xmen = {
249 .firmware = "go7007tv.bin",
250 .flags = GO7007_BOARD_USE_ONBOARD_I2C,
252 .sensor_flags = GO7007_SENSOR_VREF_POLAR,
254 .sensor_height = 240,
255 .sensor_framerate = 30030,
256 .audio_flags = GO7007_AUDIO_ONE_CHANNEL |
257 GO7007_AUDIO_I2S_MODE_3 |
258 GO7007_AUDIO_WORD_14 |
259 GO7007_AUDIO_I2S_MASTER |
260 GO7007_AUDIO_BCLK_POLAR |
261 GO7007_AUDIO_OKI_MODE,
263 .audio_bclk_div = 48,
268 .id = I2C_DRIVERID_WIS_OV7640,
281 static struct go7007_usb_board board_matrix_revolution = {
282 .flags = GO7007_USB_EZUSB,
284 .firmware = "go7007tv.bin",
285 .flags = GO7007_BOARD_HAS_AUDIO |
286 GO7007_BOARD_USE_ONBOARD_I2C,
287 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
288 GO7007_AUDIO_I2S_MASTER |
289 GO7007_AUDIO_WORD_16,
294 .sensor_flags = GO7007_SENSOR_656 |
300 .id = I2C_DRIVERID_WIS_TW9903,
318 static struct go7007_usb_board board_lifeview_lr192 = {
319 .flags = GO7007_USB_EZUSB,
321 .firmware = "go7007tv.bin",
322 .flags = GO7007_BOARD_HAS_AUDIO |
323 GO7007_BOARD_USE_ONBOARD_I2C,
324 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
325 GO7007_AUDIO_WORD_16,
330 .sensor_flags = GO7007_SENSOR_656 |
331 GO7007_SENSOR_VALID_ENABLE |
334 GO7007_SENSOR_SCALING,
346 static struct go7007_usb_board board_endura = {
349 .firmware = "go7007tv.bin",
351 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
352 GO7007_AUDIO_I2S_MASTER |
353 GO7007_AUDIO_WORD_16,
355 .audio_bclk_div = 48,
358 .sensor_flags = GO7007_SENSOR_656 |
360 .sensor_h_offset = 8,
371 static struct go7007_usb_board board_adlink_mpg24 = {
374 .firmware = "go7007tv.bin",
375 .flags = GO7007_BOARD_USE_ONBOARD_I2C,
376 .audio_flags = GO7007_AUDIO_I2S_MODE_1 |
377 GO7007_AUDIO_I2S_MASTER |
378 GO7007_AUDIO_WORD_16,
383 .sensor_flags = GO7007_SENSOR_656 |
389 .id = I2C_DRIVERID_WIS_TW2804,
390 .addr = 0x00, /* yes, really */
402 static struct usb_device_id go7007_usb_id_table[] = {
404 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
405 USB_DEVICE_ID_MATCH_INT_INFO,
406 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
407 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
408 .bcdDevice_lo = 0x200, /* Revision number of XMen */
409 .bcdDevice_hi = 0x200,
410 .bInterfaceClass = 255,
411 .bInterfaceSubClass = 0,
412 .bInterfaceProtocol = 255,
413 .driver_info = (kernel_ulong_t)GO7007_BOARDID_XMEN,
416 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
417 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
418 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
419 .bcdDevice_lo = 0x202, /* Revision number of Matrix II */
420 .bcdDevice_hi = 0x202,
421 .driver_info = (kernel_ulong_t)GO7007_BOARDID_MATRIX_II,
424 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
425 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
426 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
427 .bcdDevice_lo = 0x204, /* Revision number of Matrix */
428 .bcdDevice_hi = 0x204, /* Reloaded */
429 .driver_info = (kernel_ulong_t)GO7007_BOARDID_MATRIX_RELOAD,
432 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
433 USB_DEVICE_ID_MATCH_INT_INFO,
434 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
435 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
436 .bcdDevice_lo = 0x205, /* Revision number of XMen-II */
437 .bcdDevice_hi = 0x205,
438 .bInterfaceClass = 255,
439 .bInterfaceSubClass = 0,
440 .bInterfaceProtocol = 255,
441 .driver_info = (kernel_ulong_t)GO7007_BOARDID_XMEN_II,
444 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
445 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
446 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
447 .bcdDevice_lo = 0x208, /* Revision number of Star Trek */
448 .bcdDevice_hi = 0x208,
449 .driver_info = (kernel_ulong_t)GO7007_BOARDID_STAR_TREK,
452 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION |
453 USB_DEVICE_ID_MATCH_INT_INFO,
454 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
455 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
456 .bcdDevice_lo = 0x209, /* Revision number of XMen-III */
457 .bcdDevice_hi = 0x209,
458 .bInterfaceClass = 255,
459 .bInterfaceSubClass = 0,
460 .bInterfaceProtocol = 255,
461 .driver_info = (kernel_ulong_t)GO7007_BOARDID_XMEN_III,
464 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
465 .idVendor = 0x0eb1, /* Vendor ID of WIS Technologies */
466 .idProduct = 0x7007, /* Product ID of GO7007SB chip */
467 .bcdDevice_lo = 0x210, /* Revision number of Matrix */
468 .bcdDevice_hi = 0x210, /* Revolution */
469 .driver_info = (kernel_ulong_t)GO7007_BOARDID_MATRIX_REV,
472 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
473 .idVendor = 0x093b, /* Vendor ID of Plextor */
474 .idProduct = 0xa102, /* Product ID of M402U */
475 .bcdDevice_lo = 0x1, /* revision number of Blueberry */
477 .driver_info = (kernel_ulong_t)GO7007_BOARDID_PX_M402U,
480 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
481 .idVendor = 0x093b, /* Vendor ID of Plextor */
482 .idProduct = 0xa104, /* Product ID of TV402U */
485 .driver_info = (kernel_ulong_t)GO7007_BOARDID_PX_TV402U_ANY,
488 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION,
489 .idVendor = 0x10fd, /* Vendor ID of Anubis Electronics */
490 .idProduct = 0xde00, /* Product ID of Lifeview LR192 */
493 .driver_info = (kernel_ulong_t)GO7007_BOARDID_LIFEVIEW_LR192,
495 { } /* Terminating entry */
498 MODULE_DEVICE_TABLE(usb, go7007_usb_id_table);
500 /********************* Driver for EZ-USB HPI interface *********************/
502 static int go7007_usb_vendor_request(struct go7007 *go, int request,
503 int value, int index, void *transfer_buffer, int length, int in)
505 struct go7007_usb *usb = go->hpi_context;
509 return usb_control_msg(usb->usbdev,
510 usb_rcvctrlpipe(usb->usbdev, 0), request,
511 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
512 value, index, transfer_buffer, length, timeout);
514 return usb_control_msg(usb->usbdev,
515 usb_sndctrlpipe(usb->usbdev, 0), request,
516 USB_TYPE_VENDOR | USB_RECIP_DEVICE,
517 value, index, transfer_buffer, length, timeout);
521 static int go7007_usb_interface_reset(struct go7007 *go)
523 struct go7007_usb *usb = go->hpi_context;
524 u16 intr_val, intr_data;
527 if (go7007_write_interrupt(go, 0x0001, 0x0001) < 0)
531 if (usb->board->flags & GO7007_USB_EZUSB) {
532 /* Reset buffer in EZ-USB */
533 #ifdef GO7007_USB_DEBUG
534 printk(KERN_DEBUG "go7007-usb: resetting EZ-USB buffers\n");
536 if (go7007_usb_vendor_request(go, 0x10, 0, 0, NULL, 0, 0) < 0 ||
537 go7007_usb_vendor_request(go, 0x10, 0, 0, NULL, 0, 0) < 0)
540 /* Reset encoder again */
541 if (go7007_write_interrupt(go, 0x0001, 0x0001) < 0)
546 /* Wait for an interrupt to indicate successful hardware reset */
547 if (go7007_read_interrupt(go, &intr_val, &intr_data) < 0 ||
548 (intr_val & ~0x1) != 0x55aa) {
550 "go7007-usb: unable to reset the USB interface\n");
556 static int go7007_usb_ezusb_write_interrupt(struct go7007 *go,
559 struct go7007_usb *usb = go->hpi_context;
564 #ifdef GO7007_USB_DEBUG
566 "go7007-usb: WriteInterrupt: %04x %04x\n", addr, data);
569 for (i = 0; i < 100; ++i) {
570 r = usb_control_msg(usb->usbdev,
571 usb_rcvctrlpipe(usb->usbdev, 0), 0x14,
572 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
573 0, HPI_STATUS_ADDR, &status_reg,
574 sizeof(status_reg), timeout);
576 goto write_int_error;
577 __le16_to_cpus(&status_reg);
578 if (!(status_reg & 0x0010))
584 "go7007-usb: device is hung, status reg = 0x%04x\n",
588 r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 0), 0x12,
589 USB_TYPE_VENDOR | USB_RECIP_DEVICE, data,
590 INT_PARAM_ADDR, NULL, 0, timeout);
592 goto write_int_error;
593 r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 0),
594 0x12, USB_TYPE_VENDOR | USB_RECIP_DEVICE, addr,
595 INT_INDEX_ADDR, NULL, 0, timeout);
597 goto write_int_error;
601 printk(KERN_ERR "go7007-usb: error in WriteInterrupt: %d\n", r);
605 static int go7007_usb_onboard_write_interrupt(struct go7007 *go,
608 struct go7007_usb *usb = go->hpi_context;
613 #ifdef GO7007_USB_DEBUG
615 "go7007-usb: WriteInterrupt: %04x %04x\n", addr, data);
618 tbuf = kmalloc(8, GFP_KERNEL);
622 tbuf[0] = data & 0xff;
624 tbuf[2] = addr & 0xff;
626 r = usb_control_msg(usb->usbdev, usb_sndctrlpipe(usb->usbdev, 2), 0x00,
627 USB_TYPE_VENDOR | USB_RECIP_ENDPOINT, 0x55aa,
628 0xf0f0, tbuf, 8, timeout);
631 printk(KERN_ERR "go7007-usb: error in WriteInterrupt: %d\n", r);
637 static void go7007_usb_readinterrupt_complete(struct urb *urb)
639 struct go7007 *go = (struct go7007 *)urb->context;
640 u16 *regs = (u16 *)urb->transfer_buffer;
642 if (urb->status != 0) {
643 if (urb->status != -ESHUTDOWN &&
644 go->status != STATUS_SHUTDOWN) {
646 "go7007-usb: error in read interrupt: %d\n",
649 wake_up(&go->interrupt_waitq);
652 } else if (urb->actual_length != urb->transfer_buffer_length) {
653 printk(KERN_ERR "go7007-usb: short read in interrupt pipe!\n");
655 go->interrupt_available = 1;
656 go->interrupt_data = __le16_to_cpu(regs[0]);
657 go->interrupt_value = __le16_to_cpu(regs[1]);
658 #ifdef GO7007_USB_DEBUG
659 printk(KERN_DEBUG "go7007-usb: ReadInterrupt: %04x %04x\n",
660 go->interrupt_value, go->interrupt_data);
664 wake_up(&go->interrupt_waitq);
667 static int go7007_usb_read_interrupt(struct go7007 *go)
669 struct go7007_usb *usb = go->hpi_context;
672 r = usb_submit_urb(usb->intr_urb, GFP_KERNEL);
675 "go7007-usb: unable to submit interrupt urb: %d\n", r);
681 static void go7007_usb_read_video_pipe_complete(struct urb *urb)
683 struct go7007 *go = (struct go7007 *)urb->context;
686 if (!go->streaming) {
687 wake_up_interruptible(&go->frame_waitq);
690 if (urb->status != 0) {
691 printk(KERN_ERR "go7007-usb: error in video pipe: %d\n",
695 if (urb->actual_length != urb->transfer_buffer_length) {
696 printk(KERN_ERR "go7007-usb: short read in video pipe!\n");
699 go7007_parse_video_stream(go, urb->transfer_buffer, urb->actual_length);
700 r = usb_submit_urb(urb, GFP_ATOMIC);
702 printk(KERN_ERR "go7007-usb: error in video pipe: %d\n", r);
705 static void go7007_usb_read_audio_pipe_complete(struct urb *urb)
707 struct go7007 *go = (struct go7007 *)urb->context;
712 if (urb->status != 0) {
713 printk(KERN_ERR "go7007-usb: error in audio pipe: %d\n",
717 if (urb->actual_length != urb->transfer_buffer_length) {
718 printk(KERN_ERR "go7007-usb: short read in audio pipe!\n");
721 if (go->audio_deliver != NULL)
722 go->audio_deliver(go, urb->transfer_buffer, urb->actual_length);
723 r = usb_submit_urb(urb, GFP_ATOMIC);
725 printk(KERN_ERR "go7007-usb: error in audio pipe: %d\n", r);
728 static int go7007_usb_stream_start(struct go7007 *go)
730 struct go7007_usb *usb = go->hpi_context;
733 for (i = 0; i < 8; ++i) {
734 r = usb_submit_urb(usb->video_urbs[i], GFP_KERNEL);
736 printk(KERN_ERR "go7007-usb: error submitting video "
737 "urb %d: %d\n", i, r);
738 goto video_submit_failed;
741 if (!go->audio_enabled)
744 for (i = 0; i < 8; ++i) {
745 r = usb_submit_urb(usb->audio_urbs[i], GFP_KERNEL);
747 printk(KERN_ERR "go7007-usb: error submitting audio "
748 "urb %d: %d\n", i, r);
749 goto audio_submit_failed;
755 for (i = 0; i < 8; ++i)
756 usb_kill_urb(usb->audio_urbs[i]);
758 for (i = 0; i < 8; ++i)
759 usb_kill_urb(usb->video_urbs[i]);
763 static int go7007_usb_stream_stop(struct go7007 *go)
765 struct go7007_usb *usb = go->hpi_context;
768 if (go->status == STATUS_SHUTDOWN)
770 for (i = 0; i < 8; ++i)
771 usb_kill_urb(usb->video_urbs[i]);
772 if (go->audio_enabled)
773 for (i = 0; i < 8; ++i)
774 usb_kill_urb(usb->audio_urbs[i]);
778 static int go7007_usb_send_firmware(struct go7007 *go, u8 *data, int len)
780 struct go7007_usb *usb = go->hpi_context;
781 int transferred, pipe;
784 #ifdef GO7007_USB_DEBUG
785 printk(KERN_DEBUG "go7007-usb: DownloadBuffer sending %d bytes\n", len);
788 if (usb->board->flags & GO7007_USB_EZUSB)
789 pipe = usb_sndbulkpipe(usb->usbdev, 2);
791 pipe = usb_sndbulkpipe(usb->usbdev, 3);
793 return usb_bulk_msg(usb->usbdev, pipe, data, len,
794 &transferred, timeout);
797 static struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops = {
798 .interface_reset = go7007_usb_interface_reset,
799 .write_interrupt = go7007_usb_ezusb_write_interrupt,
800 .read_interrupt = go7007_usb_read_interrupt,
801 .stream_start = go7007_usb_stream_start,
802 .stream_stop = go7007_usb_stream_stop,
803 .send_firmware = go7007_usb_send_firmware,
806 static struct go7007_hpi_ops go7007_usb_onboard_hpi_ops = {
807 .interface_reset = go7007_usb_interface_reset,
808 .write_interrupt = go7007_usb_onboard_write_interrupt,
809 .read_interrupt = go7007_usb_read_interrupt,
810 .stream_start = go7007_usb_stream_start,
811 .stream_stop = go7007_usb_stream_stop,
812 .send_firmware = go7007_usb_send_firmware,
815 /********************* Driver for EZ-USB I2C adapter *********************/
817 static int go7007_usb_i2c_master_xfer(struct i2c_adapter *adapter,
818 struct i2c_msg msgs[], int num)
820 struct go7007 *go = i2c_get_adapdata(adapter);
821 struct go7007_usb *usb = go->hpi_context;
826 if (go->status == STATUS_SHUTDOWN)
829 down(&usb->i2c_lock);
831 for (i = 0; i < num; ++i) {
832 /* The hardware command is "write some bytes then read some
833 * bytes", so we try to coalesce a write followed by a read
834 * into a single USB transaction */
835 if (i + 1 < num && msgs[i].addr == msgs[i + 1].addr &&
836 !(msgs[i].flags & I2C_M_RD) &&
837 (msgs[i + 1].flags & I2C_M_RD)) {
838 #ifdef GO7007_I2C_DEBUG
839 printk(KERN_DEBUG "go7007-usb: i2c write/read %d/%d "
840 "bytes on %02x\n", msgs[i].len,
841 msgs[i + 1].len, msgs[i].addr);
844 buf[1] = msgs[i].len + 1;
845 buf[2] = msgs[i].addr << 1;
846 memcpy(&buf[3], msgs[i].buf, msgs[i].len);
847 buf_len = msgs[i].len + 3;
848 buf[buf_len++] = msgs[++i].len;
849 } else if (msgs[i].flags & I2C_M_RD) {
850 #ifdef GO7007_I2C_DEBUG
851 printk(KERN_DEBUG "go7007-usb: i2c read %d "
852 "bytes on %02x\n", msgs[i].len,
857 buf[2] = msgs[i].addr << 1;
858 buf[3] = msgs[i].len;
861 #ifdef GO7007_I2C_DEBUG
862 printk(KERN_DEBUG "go7007-usb: i2c write %d "
863 "bytes on %02x\n", msgs[i].len,
867 buf[1] = msgs[i].len + 1;
868 buf[2] = msgs[i].addr << 1;
869 memcpy(&buf[3], msgs[i].buf, msgs[i].len);
870 buf_len = msgs[i].len + 3;
873 if (go7007_usb_vendor_request(go, 0x24, 0, 0,
874 buf, buf_len, 0) < 0)
876 if (msgs[i].flags & I2C_M_RD) {
877 memset(buf, 0, sizeof(buf));
878 if (go7007_usb_vendor_request(go, 0x25, 0, 0, buf,
879 msgs[i].len + 1, 1) < 0)
881 memcpy(msgs[i].buf, buf + 1, msgs[i].len);
891 static u32 go7007_usb_functionality(struct i2c_adapter *adapter)
893 /* No errors are reported by the hardware, so we don't bother
894 * supporting quick writes to avoid confusing probing */
895 return (I2C_FUNC_SMBUS_EMUL) & ~I2C_FUNC_SMBUS_QUICK;
898 static struct i2c_algorithm go7007_usb_algo = {
899 .master_xfer = go7007_usb_i2c_master_xfer,
900 .functionality = go7007_usb_functionality,
903 static struct i2c_adapter go7007_usb_adap_templ = {
904 .owner = THIS_MODULE,
905 .class = I2C_CLASS_TV_ANALOG,
906 .name = "WIS GO7007SB EZ-USB",
907 .id = I2C_ALGO_GO7007_USB,
908 .algo = &go7007_usb_algo,
911 /********************* USB add/remove functions *********************/
913 static int go7007_usb_probe(struct usb_interface *intf,
914 const struct usb_device_id *id)
917 struct go7007_usb *usb;
918 struct go7007_usb_board *board;
919 struct usb_device *usbdev = interface_to_usbdev(intf);
921 int video_pipe, i, v_urb_len;
923 printk(KERN_DEBUG "go7007-usb: probing new GO7007 USB board\n");
925 switch (id->driver_info) {
926 case GO7007_BOARDID_MATRIX_II:
927 name = "WIS Matrix II or compatible";
928 board = &board_matrix_ii;
930 case GO7007_BOARDID_MATRIX_RELOAD:
931 name = "WIS Matrix Reloaded or compatible";
932 board = &board_matrix_reload;
934 case GO7007_BOARDID_MATRIX_REV:
935 name = "WIS Matrix Revolution or compatible";
936 board = &board_matrix_revolution;
938 case GO7007_BOARDID_STAR_TREK:
939 name = "WIS Star Trek or compatible";
940 board = &board_star_trek;
942 case GO7007_BOARDID_XMEN:
943 name = "WIS XMen or compatible";
946 case GO7007_BOARDID_XMEN_II:
947 name = "WIS XMen II or compatible";
950 case GO7007_BOARDID_XMEN_III:
951 name = "WIS XMen III or compatible";
954 case GO7007_BOARDID_PX_M402U:
955 name = "Plextor PX-M402U";
956 board = &board_matrix_ii;
958 case GO7007_BOARDID_PX_TV402U_ANY:
959 name = "Plextor PX-TV402U (unknown tuner)";
960 board = &board_px_tv402u;
962 case GO7007_BOARDID_LIFEVIEW_LR192:
963 printk(KERN_ERR "go7007-usb: The Lifeview TV Walker Ultra "
964 "is not supported. Sorry!\n");
966 name = "Lifeview TV Walker Ultra";
967 board = &board_lifeview_lr192;
970 printk(KERN_ERR "go7007-usb: unknown board ID %d!\n",
971 (unsigned int)id->driver_info);
975 usb = kmalloc(sizeof(struct go7007_usb), GFP_KERNEL);
978 memset(usb, 0, sizeof(struct go7007_usb));
980 /* Allocate the URB and buffer for receiving incoming interrupts */
981 usb->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
982 if (usb->intr_urb == NULL)
984 usb->intr_urb->transfer_buffer = kmalloc(2*sizeof(u16), GFP_KERNEL);
985 if (usb->intr_urb->transfer_buffer == NULL)
988 go = go7007_alloc(&board->main_info, &intf->dev);
992 usb->usbdev = usbdev;
993 go->board_id = id->driver_info;
994 strncpy(go->name, name, sizeof(go->name));
995 if (board->flags & GO7007_USB_EZUSB)
996 go->hpi_ops = &go7007_usb_ezusb_hpi_ops;
998 go->hpi_ops = &go7007_usb_onboard_hpi_ops;
999 go->hpi_context = usb;
1000 usb_fill_int_urb(usb->intr_urb, usb->usbdev,
1001 usb_rcvintpipe(usb->usbdev, 4),
1002 usb->intr_urb->transfer_buffer, 2*sizeof(u16),
1003 go7007_usb_readinterrupt_complete, go, 8);
1004 usb_set_intfdata(intf, go);
1006 /* Boot the GO7007 */
1007 if (go7007_boot_encoder(go, go->board_info->flags &
1008 GO7007_BOARD_USE_ONBOARD_I2C) < 0)
1011 /* Register the EZ-USB I2C adapter, if we're using it */
1012 if (board->flags & GO7007_USB_EZUSB_I2C) {
1013 memcpy(&go->i2c_adapter, &go7007_usb_adap_templ,
1014 sizeof(go7007_usb_adap_templ));
1015 init_MUTEX(&usb->i2c_lock);
1016 go->i2c_adapter.dev.parent = go->dev;
1017 i2c_set_adapdata(&go->i2c_adapter, go);
1018 if (i2c_add_adapter(&go->i2c_adapter) < 0) {
1020 "go7007-usb: error: i2c_add_adapter failed\n");
1023 go->i2c_adapter_online = 1;
1026 /* Pelco and Adlink reused the XMen and XMen-III vendor and product
1027 * IDs for their own incompatible designs. We can detect XMen boards
1028 * by probing the sensor, but there is no way to probe the sensors on
1029 * the Pelco and Adlink designs so we default to the Adlink. If it
1030 * is actually a Pelco, the user must set the assume_endura module
1032 if ((go->board_id == GO7007_BOARDID_XMEN ||
1033 go->board_id == GO7007_BOARDID_XMEN_III) &&
1034 go->i2c_adapter_online) {
1035 union i2c_smbus_data data;
1037 /* Check to see if register 0x0A is 0x76 */
1038 i2c_smbus_xfer(&go->i2c_adapter, 0x21, I2C_CLIENT_SCCB,
1039 I2C_SMBUS_READ, 0x0A, I2C_SMBUS_BYTE_DATA, &data);
1040 if (data.byte != 0x76) {
1041 if (assume_endura) {
1042 go->board_id = GO7007_BOARDID_ENDURA;
1043 usb->board = board = &board_endura;
1044 go->board_info = &board->main_info;
1045 strncpy(go->name, "Pelco Endura",
1050 /* set GPIO5 to be an output, currently low */
1051 go7007_write_addr(go, 0x3c82, 0x0000);
1052 go7007_write_addr(go, 0x3c80, 0x00df);
1053 /* read channel number from GPIO[1:0] */
1054 go7007_read_addr(go, 0x3c81, &channel);
1056 go->board_id = GO7007_BOARDID_ADLINK_MPG24;
1057 usb->board = board = &board_adlink_mpg24;
1058 go->board_info = &board->main_info;
1059 go->channel_number = channel;
1060 snprintf(go->name, sizeof(go->name),
1061 "Adlink PCI-MPG24, channel #%d",
1067 /* Probe the tuner model on the TV402U */
1068 if (go->board_id == GO7007_BOARDID_PX_TV402U_ANY) {
1071 /* Board strapping indicates tuner model */
1072 if (go7007_usb_vendor_request(go, 0x41, 0, 0, data, 3, 1) < 0) {
1073 printk(KERN_ERR "go7007-usb: GPIO read failed!\n");
1076 switch (data[0] >> 6) {
1078 go->board_id = GO7007_BOARDID_PX_TV402U_EU;
1079 go->tuner_type = TUNER_SONY_BTF_PG472Z;
1080 strncpy(go->name, "Plextor PX-TV402U-EU",
1084 go->board_id = GO7007_BOARDID_PX_TV402U_JP;
1085 go->tuner_type = TUNER_SONY_BTF_PK467Z;
1086 strncpy(go->name, "Plextor PX-TV402U-JP",
1090 go->board_id = GO7007_BOARDID_PX_TV402U_NA;
1091 go->tuner_type = TUNER_SONY_BTF_PB463Z;
1092 strncpy(go->name, "Plextor PX-TV402U-NA",
1096 printk(KERN_DEBUG "go7007-usb: unable to detect "
1100 /* Configure tuner mode selection inputs connected
1101 * to the EZ-USB GPIO output pins */
1102 if (go7007_usb_vendor_request(go, 0x40, 0x7f02, 0,
1105 "go7007-usb: GPIO write failed!\n");
1110 /* Print a nasty message if the user attempts to use a USB2.0 device in
1111 * a USB1.1 port. There will be silent corruption of the stream. */
1112 if ((board->flags & GO7007_USB_EZUSB) &&
1113 usbdev->speed != USB_SPEED_HIGH)
1114 printk(KERN_ERR "go7007-usb: *** WARNING *** This device "
1115 "must be connected to a USB 2.0 port! "
1116 "Attempting to capture video through a USB 1.1 "
1117 "port will result in stream corruption, even "
1118 "at low bitrates!\n");
1120 /* Do any final GO7007 initialization, then register the
1121 * V4L2 and ALSA interfaces */
1122 if (go7007_register_encoder(go) < 0)
1125 /* Allocate the URBs and buffers for receiving the video stream */
1126 if (board->flags & GO7007_USB_EZUSB) {
1128 video_pipe = usb_rcvbulkpipe(usb->usbdev, 6);
1131 video_pipe = usb_rcvbulkpipe(usb->usbdev, 1);
1133 for (i = 0; i < 8; ++i) {
1134 usb->video_urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
1135 if (usb->video_urbs[i] == NULL)
1137 usb->video_urbs[i]->transfer_buffer =
1138 kmalloc(v_urb_len, GFP_KERNEL);
1139 if (usb->video_urbs[i]->transfer_buffer == NULL)
1141 usb_fill_bulk_urb(usb->video_urbs[i], usb->usbdev, video_pipe,
1142 usb->video_urbs[i]->transfer_buffer, v_urb_len,
1143 go7007_usb_read_video_pipe_complete, go);
1146 /* Allocate the URBs and buffers for receiving the audio stream */
1147 if ((board->flags & GO7007_USB_EZUSB) && go->audio_enabled)
1148 for (i = 0; i < 8; ++i) {
1149 usb->audio_urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
1150 if (usb->audio_urbs[i] == NULL)
1152 usb->audio_urbs[i]->transfer_buffer = kmalloc(4096,
1154 if (usb->audio_urbs[i]->transfer_buffer == NULL)
1156 usb_fill_bulk_urb(usb->audio_urbs[i], usb->usbdev,
1157 usb_rcvbulkpipe(usb->usbdev, 8),
1158 usb->audio_urbs[i]->transfer_buffer, 4096,
1159 go7007_usb_read_audio_pipe_complete, go);
1163 go->status = STATUS_ONLINE;
1167 go->status = STATUS_SHUTDOWN;
1171 if (usb->intr_urb) {
1172 kfree(usb->intr_urb->transfer_buffer);
1173 usb_free_urb(usb->intr_urb);
1179 static void go7007_usb_disconnect(struct usb_interface *intf)
1181 struct go7007 *go = usb_get_intfdata(intf);
1182 struct go7007_usb *usb = go->hpi_context;
1185 go->status = STATUS_SHUTDOWN;
1186 usb_kill_urb(usb->intr_urb);
1188 /* Free USB-related structs */
1189 for (i = 0; i < 8; ++i) {
1190 if (usb->video_urbs[i] != NULL) {
1191 if (usb->video_urbs[i]->transfer_buffer != NULL)
1192 kfree(usb->video_urbs[i]->transfer_buffer);
1193 usb_free_urb(usb->video_urbs[i]);
1195 if (usb->audio_urbs[i] != NULL) {
1196 if (usb->audio_urbs[i]->transfer_buffer != NULL)
1197 kfree(usb->audio_urbs[i]->transfer_buffer);
1198 usb_free_urb(usb->audio_urbs[i]);
1201 kfree(usb->intr_urb->transfer_buffer);
1202 usb_free_urb(usb->intr_urb);
1204 kfree(go->hpi_context);
1209 static struct usb_driver go7007_usb_driver = {
1211 .probe = go7007_usb_probe,
1212 .disconnect = go7007_usb_disconnect,
1213 .id_table = go7007_usb_id_table,
1216 static int __init go7007_usb_init(void)
1218 return usb_register(&go7007_usb_driver);
1221 static void __exit go7007_usb_cleanup(void)
1223 usb_deregister(&go7007_usb_driver);
1226 module_init(go7007_usb_init);
1227 module_exit(go7007_usb_cleanup);
1229 MODULE_LICENSE("GPL v2");