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/saa7115.h>
30 #include <media/tuner.h>
31 #include <media/uda1342.h>
33 #include "go7007-priv.h"
35 static unsigned int assume_endura
;
36 module_param(assume_endura
, int, 0644);
37 MODULE_PARM_DESC(assume_endura
,
38 "when probing fails, hardware is a Pelco Endura");
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 const struct go7007_usb_board
*board
;
66 struct mutex 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 const struct go7007_usb_board board_matrix_ii
= {
76 .flags
= GO7007_USB_EZUSB
,
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
|
89 GO7007_SENSOR_SAA7115
|
91 GO7007_SENSOR_SCALING
,
111 .video_config
= SAA7115_IDQ_IS_DEFAULT
,
115 static const struct go7007_usb_board board_matrix_reload
= {
116 .flags
= GO7007_USB_EZUSB
,
118 .flags
= GO7007_BOARD_HAS_AUDIO
|
119 GO7007_BOARD_USE_ONBOARD_I2C
,
120 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
121 GO7007_AUDIO_I2S_MASTER
|
122 GO7007_AUDIO_WORD_16
,
127 .sensor_flags
= GO7007_SENSOR_656
|
148 .video_config
= SAA7115_IDQ_IS_DEFAULT
,
152 static const struct go7007_usb_board board_star_trek
= {
153 .flags
= GO7007_USB_EZUSB
| GO7007_USB_EZUSB_I2C
,
155 .flags
= GO7007_BOARD_HAS_AUDIO
, /* |
156 GO7007_BOARD_HAS_TUNER, */
157 .sensor_flags
= GO7007_SENSOR_656
|
158 GO7007_SENSOR_VALID_ENABLE
|
160 GO7007_SENSOR_SAA7115
|
162 GO7007_SENSOR_SCALING
,
163 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
164 GO7007_AUDIO_WORD_16
,
180 * .audio_index = AUDIO_TUNER,
186 /* .audio_index = AUDIO_EXTERN, */
191 /* .audio_index = AUDIO_EXTERN, */
195 .video_config
= SAA7115_IDQ_IS_DEFAULT
,
199 static const struct go7007_usb_board board_px_tv402u
= {
200 .flags
= GO7007_USB_EZUSB
| GO7007_USB_EZUSB_I2C
,
202 .flags
= GO7007_BOARD_HAS_AUDIO
|
203 GO7007_BOARD_HAS_TUNER
,
204 .sensor_flags
= GO7007_SENSOR_656
|
205 GO7007_SENSOR_VALID_ENABLE
|
207 GO7007_SENSOR_SAA7115
|
209 GO7007_SENSOR_SCALING
,
210 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
211 GO7007_AUDIO_WORD_16
,
236 .type
= "sony-btf-mpx",
258 .video_config
= SAA7115_IDQ_IS_DEFAULT
,
262 .audio_input
= UDA1342_IN2
,
266 .audio_input
= UDA1342_IN1
,
273 static const struct go7007_usb_board board_xmen
= {
276 .flags
= GO7007_BOARD_USE_ONBOARD_I2C
,
278 .sensor_flags
= GO7007_SENSOR_VREF_POLAR
,
280 .sensor_height
= 240,
281 .sensor_framerate
= 30030,
282 .audio_flags
= GO7007_AUDIO_ONE_CHANNEL
|
283 GO7007_AUDIO_I2S_MODE_3
|
284 GO7007_AUDIO_WORD_14
|
285 GO7007_AUDIO_I2S_MASTER
|
286 GO7007_AUDIO_BCLK_POLAR
|
287 GO7007_AUDIO_OKI_MODE
,
289 .audio_bclk_div
= 48,
307 static const struct go7007_usb_board board_matrix_revolution
= {
308 .flags
= GO7007_USB_EZUSB
,
310 .flags
= GO7007_BOARD_HAS_AUDIO
|
311 GO7007_BOARD_USE_ONBOARD_I2C
,
312 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
313 GO7007_AUDIO_I2S_MASTER
|
314 GO7007_AUDIO_WORD_16
,
319 .sensor_flags
= GO7007_SENSOR_656
|
344 static const struct go7007_usb_board board_lifeview_lr192
= {
345 .flags
= GO7007_USB_EZUSB
,
347 .flags
= GO7007_BOARD_HAS_AUDIO
|
348 GO7007_BOARD_USE_ONBOARD_I2C
,
349 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
350 GO7007_AUDIO_WORD_16
,
355 .sensor_flags
= GO7007_SENSOR_656
|
356 GO7007_SENSOR_VALID_ENABLE
|
359 GO7007_SENSOR_SCALING
,
371 static const struct go7007_usb_board board_endura
= {
375 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
376 GO7007_AUDIO_I2S_MASTER
|
377 GO7007_AUDIO_WORD_16
,
379 .audio_bclk_div
= 48,
382 .sensor_flags
= GO7007_SENSOR_656
|
384 .sensor_h_offset
= 8,
395 static const struct go7007_usb_board board_adlink_mpg24
= {
398 .flags
= GO7007_BOARD_USE_ONBOARD_I2C
,
399 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
400 GO7007_AUDIO_I2S_MASTER
|
401 GO7007_AUDIO_WORD_16
,
406 .sensor_flags
= GO7007_SENSOR_656
|
413 .addr
= 0x00, /* yes, really */
414 .flags
= I2C_CLIENT_TEN
,
427 static const struct go7007_usb_board board_sensoray_2250
= {
428 .flags
= GO7007_USB_EZUSB
| GO7007_USB_EZUSB_I2C
,
430 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
431 GO7007_AUDIO_I2S_MASTER
|
432 GO7007_AUDIO_WORD_16
,
433 .flags
= GO7007_BOARD_HAS_AUDIO
,
438 .sensor_flags
= GO7007_SENSOR_656
|
478 static const struct go7007_usb_board board_ads_usbav_709
= {
479 .flags
= GO7007_USB_EZUSB
,
481 .flags
= GO7007_BOARD_HAS_AUDIO
|
482 GO7007_BOARD_USE_ONBOARD_I2C
,
483 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
484 GO7007_AUDIO_I2S_MASTER
|
485 GO7007_AUDIO_WORD_16
,
490 .sensor_flags
= GO7007_SENSOR_656
|
515 static const struct usb_device_id go7007_usb_id_table
[] = {
517 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
|
518 USB_DEVICE_ID_MATCH_INT_INFO
,
519 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
520 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
521 .bcdDevice_lo
= 0x200, /* Revision number of XMen */
522 .bcdDevice_hi
= 0x200,
523 .bInterfaceClass
= 255,
524 .bInterfaceSubClass
= 0,
525 .bInterfaceProtocol
= 255,
526 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_XMEN
,
529 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
530 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
531 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
532 .bcdDevice_lo
= 0x202, /* Revision number of Matrix II */
533 .bcdDevice_hi
= 0x202,
534 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_MATRIX_II
,
537 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
538 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
539 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
540 .bcdDevice_lo
= 0x204, /* Revision number of Matrix */
541 .bcdDevice_hi
= 0x204, /* Reloaded */
542 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_MATRIX_RELOAD
,
545 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
|
546 USB_DEVICE_ID_MATCH_INT_INFO
,
547 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
548 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
549 .bcdDevice_lo
= 0x205, /* Revision number of XMen-II */
550 .bcdDevice_hi
= 0x205,
551 .bInterfaceClass
= 255,
552 .bInterfaceSubClass
= 0,
553 .bInterfaceProtocol
= 255,
554 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_XMEN_II
,
557 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
558 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
559 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
560 .bcdDevice_lo
= 0x208, /* Revision number of Star Trek */
561 .bcdDevice_hi
= 0x208,
562 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_STAR_TREK
,
565 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
|
566 USB_DEVICE_ID_MATCH_INT_INFO
,
567 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
568 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
569 .bcdDevice_lo
= 0x209, /* Revision number of XMen-III */
570 .bcdDevice_hi
= 0x209,
571 .bInterfaceClass
= 255,
572 .bInterfaceSubClass
= 0,
573 .bInterfaceProtocol
= 255,
574 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_XMEN_III
,
577 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
578 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
579 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
580 .bcdDevice_lo
= 0x210, /* Revision number of Matrix */
581 .bcdDevice_hi
= 0x210, /* Revolution */
582 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_MATRIX_REV
,
585 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
586 .idVendor
= 0x093b, /* Vendor ID of Plextor */
587 .idProduct
= 0xa102, /* Product ID of M402U */
588 .bcdDevice_lo
= 0x1, /* revision number of Blueberry */
590 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_PX_M402U
,
593 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
594 .idVendor
= 0x093b, /* Vendor ID of Plextor */
595 .idProduct
= 0xa104, /* Product ID of TV402U */
598 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_PX_TV402U
,
601 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
602 .idVendor
= 0x10fd, /* Vendor ID of Anubis Electronics */
603 .idProduct
= 0xde00, /* Product ID of Lifeview LR192 */
606 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_LIFEVIEW_LR192
,
609 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
610 .idVendor
= 0x1943, /* Vendor ID Sensoray */
611 .idProduct
= 0x2250, /* Product ID of 2250/2251 */
614 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_SENSORAY_2250
,
617 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
618 .idVendor
= 0x06e1, /* Vendor ID of ADS Technologies */
619 .idProduct
= 0x0709, /* Product ID of DVD Xpress DX2 */
620 .bcdDevice_lo
= 0x204,
621 .bcdDevice_hi
= 0x204,
622 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_ADS_USBAV_709
,
624 { } /* Terminating entry */
627 MODULE_DEVICE_TABLE(usb
, go7007_usb_id_table
);
629 /********************* Driver for EZ-USB HPI interface *********************/
631 static int go7007_usb_vendor_request(struct go7007
*go
, int request
,
632 int value
, int index
, void *transfer_buffer
, int length
, int in
)
634 struct go7007_usb
*usb
= go
->hpi_context
;
638 return usb_control_msg(usb
->usbdev
,
639 usb_rcvctrlpipe(usb
->usbdev
, 0), request
,
640 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
641 value
, index
, transfer_buffer
, length
, timeout
);
643 return usb_control_msg(usb
->usbdev
,
644 usb_sndctrlpipe(usb
->usbdev
, 0), request
,
645 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
646 value
, index
, transfer_buffer
, length
, timeout
);
650 static int go7007_usb_interface_reset(struct go7007
*go
)
652 struct go7007_usb
*usb
= go
->hpi_context
;
653 u16 intr_val
, intr_data
;
655 if (go
->status
== STATUS_SHUTDOWN
)
658 if (go7007_write_interrupt(go
, 0x0001, 0x0001) < 0)
662 if (usb
->board
->flags
& GO7007_USB_EZUSB
) {
663 /* Reset buffer in EZ-USB */
664 dev_dbg(go
->dev
, "resetting EZ-USB buffers\n");
665 if (go7007_usb_vendor_request(go
, 0x10, 0, 0, NULL
, 0, 0) < 0 ||
666 go7007_usb_vendor_request(go
, 0x10, 0, 0, NULL
, 0, 0) < 0)
669 /* Reset encoder again */
670 if (go7007_write_interrupt(go
, 0x0001, 0x0001) < 0)
675 /* Wait for an interrupt to indicate successful hardware reset */
676 if (go7007_read_interrupt(go
, &intr_val
, &intr_data
) < 0 ||
677 (intr_val
& ~0x1) != 0x55aa) {
678 dev_err(go
->dev
, "unable to reset the USB interface\n");
684 static int go7007_usb_ezusb_write_interrupt(struct go7007
*go
,
687 struct go7007_usb
*usb
= go
->hpi_context
;
692 dev_dbg(go
->dev
, "WriteInterrupt: %04x %04x\n", addr
, data
);
694 for (i
= 0; i
< 100; ++i
) {
695 r
= usb_control_msg(usb
->usbdev
,
696 usb_rcvctrlpipe(usb
->usbdev
, 0), 0x14,
697 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
698 0, HPI_STATUS_ADDR
, go
->usb_buf
,
699 sizeof(status_reg
), timeout
);
702 status_reg
= le16_to_cpu(*((u16
*)go
->usb_buf
));
703 if (!(status_reg
& 0x0010))
708 goto write_int_error
;
710 dev_err(go
->dev
, "device is hung, status reg = 0x%04x\n", status_reg
);
713 r
= usb_control_msg(usb
->usbdev
, usb_sndctrlpipe(usb
->usbdev
, 0), 0x12,
714 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
, data
,
715 INT_PARAM_ADDR
, NULL
, 0, timeout
);
717 goto write_int_error
;
718 r
= usb_control_msg(usb
->usbdev
, usb_sndctrlpipe(usb
->usbdev
, 0),
719 0x12, USB_TYPE_VENDOR
| USB_RECIP_DEVICE
, addr
,
720 INT_INDEX_ADDR
, NULL
, 0, timeout
);
722 goto write_int_error
;
726 dev_err(go
->dev
, "error in WriteInterrupt: %d\n", r
);
730 static int go7007_usb_onboard_write_interrupt(struct go7007
*go
,
733 struct go7007_usb
*usb
= go
->hpi_context
;
737 dev_dbg(go
->dev
, "WriteInterrupt: %04x %04x\n", addr
, data
);
739 go
->usb_buf
[0] = data
& 0xff;
740 go
->usb_buf
[1] = data
>> 8;
741 go
->usb_buf
[2] = addr
& 0xff;
742 go
->usb_buf
[3] = addr
>> 8;
743 go
->usb_buf
[4] = go
->usb_buf
[5] = go
->usb_buf
[6] = go
->usb_buf
[7] = 0;
744 r
= usb_control_msg(usb
->usbdev
, usb_sndctrlpipe(usb
->usbdev
, 2), 0x00,
745 USB_TYPE_VENDOR
| USB_RECIP_ENDPOINT
, 0x55aa,
746 0xf0f0, go
->usb_buf
, 8, timeout
);
748 dev_err(go
->dev
, "error in WriteInterrupt: %d\n", r
);
754 static void go7007_usb_readinterrupt_complete(struct urb
*urb
)
756 struct go7007
*go
= (struct go7007
*)urb
->context
;
757 u16
*regs
= (u16
*)urb
->transfer_buffer
;
758 int status
= urb
->status
;
761 if (status
!= -ESHUTDOWN
&&
762 go
->status
!= STATUS_SHUTDOWN
) {
763 dev_err(go
->dev
, "error in read interrupt: %d\n", urb
->status
);
765 wake_up(&go
->interrupt_waitq
);
768 } else if (urb
->actual_length
!= urb
->transfer_buffer_length
) {
769 dev_err(go
->dev
, "short read in interrupt pipe!\n");
771 go
->interrupt_available
= 1;
772 go
->interrupt_data
= __le16_to_cpu(regs
[0]);
773 go
->interrupt_value
= __le16_to_cpu(regs
[1]);
774 dev_dbg(go
->dev
, "ReadInterrupt: %04x %04x\n",
775 go
->interrupt_value
, go
->interrupt_data
);
778 wake_up(&go
->interrupt_waitq
);
781 static int go7007_usb_read_interrupt(struct go7007
*go
)
783 struct go7007_usb
*usb
= go
->hpi_context
;
786 r
= usb_submit_urb(usb
->intr_urb
, GFP_KERNEL
);
788 dev_err(go
->dev
, "unable to submit interrupt urb: %d\n", r
);
794 static void go7007_usb_read_video_pipe_complete(struct urb
*urb
)
796 struct go7007
*go
= (struct go7007
*)urb
->context
;
797 int r
, status
= urb
->status
;
799 if (!vb2_is_streaming(&go
->vidq
)) {
800 wake_up_interruptible(&go
->frame_waitq
);
804 dev_err(go
->dev
, "error in video pipe: %d\n", status
);
807 if (urb
->actual_length
!= urb
->transfer_buffer_length
) {
808 dev_err(go
->dev
, "short read in video pipe!\n");
811 go7007_parse_video_stream(go
, urb
->transfer_buffer
, urb
->actual_length
);
812 r
= usb_submit_urb(urb
, GFP_ATOMIC
);
814 dev_err(go
->dev
, "error in video pipe: %d\n", r
);
817 static void go7007_usb_read_audio_pipe_complete(struct urb
*urb
)
819 struct go7007
*go
= (struct go7007
*)urb
->context
;
820 int r
, status
= urb
->status
;
822 if (!vb2_is_streaming(&go
->vidq
))
825 dev_err(go
->dev
, "error in audio pipe: %d\n",
829 if (urb
->actual_length
!= urb
->transfer_buffer_length
) {
830 dev_err(go
->dev
, "short read in audio pipe!\n");
833 if (go
->audio_deliver
!= NULL
)
834 go
->audio_deliver(go
, urb
->transfer_buffer
, urb
->actual_length
);
835 r
= usb_submit_urb(urb
, GFP_ATOMIC
);
837 dev_err(go
->dev
, "error in audio pipe: %d\n", r
);
840 static int go7007_usb_stream_start(struct go7007
*go
)
842 struct go7007_usb
*usb
= go
->hpi_context
;
845 for (i
= 0; i
< 8; ++i
) {
846 r
= usb_submit_urb(usb
->video_urbs
[i
], GFP_KERNEL
);
848 dev_err(go
->dev
, "error submitting video urb %d: %d\n", i
, r
);
849 goto video_submit_failed
;
852 if (!go
->audio_enabled
)
855 for (i
= 0; i
< 8; ++i
) {
856 r
= usb_submit_urb(usb
->audio_urbs
[i
], GFP_KERNEL
);
858 dev_err(go
->dev
, "error submitting audio urb %d: %d\n", i
, r
);
859 goto audio_submit_failed
;
865 for (i
= 0; i
< 7; ++i
)
866 usb_kill_urb(usb
->audio_urbs
[i
]);
868 for (i
= 0; i
< 8; ++i
)
869 usb_kill_urb(usb
->video_urbs
[i
]);
873 static int go7007_usb_stream_stop(struct go7007
*go
)
875 struct go7007_usb
*usb
= go
->hpi_context
;
878 if (go
->status
== STATUS_SHUTDOWN
)
880 for (i
= 0; i
< 8; ++i
)
881 usb_kill_urb(usb
->video_urbs
[i
]);
882 if (go
->audio_enabled
)
883 for (i
= 0; i
< 8; ++i
)
884 usb_kill_urb(usb
->audio_urbs
[i
]);
888 static int go7007_usb_send_firmware(struct go7007
*go
, u8
*data
, int len
)
890 struct go7007_usb
*usb
= go
->hpi_context
;
891 int transferred
, pipe
;
894 dev_dbg(go
->dev
, "DownloadBuffer sending %d bytes\n", len
);
896 if (usb
->board
->flags
& GO7007_USB_EZUSB
)
897 pipe
= usb_sndbulkpipe(usb
->usbdev
, 2);
899 pipe
= usb_sndbulkpipe(usb
->usbdev
, 3);
901 return usb_bulk_msg(usb
->usbdev
, pipe
, data
, len
,
902 &transferred
, timeout
);
905 static void go7007_usb_release(struct go7007
*go
)
907 struct go7007_usb
*usb
= go
->hpi_context
;
908 struct urb
*vurb
, *aurb
;
912 usb_kill_urb(usb
->intr_urb
);
913 kfree(usb
->intr_urb
->transfer_buffer
);
914 usb_free_urb(usb
->intr_urb
);
917 /* Free USB-related structs */
918 for (i
= 0; i
< 8; ++i
) {
919 vurb
= usb
->video_urbs
[i
];
922 kfree(vurb
->transfer_buffer
);
925 aurb
= usb
->audio_urbs
[i
];
928 kfree(aurb
->transfer_buffer
);
933 kfree(go
->hpi_context
);
936 static struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops
= {
937 .interface_reset
= go7007_usb_interface_reset
,
938 .write_interrupt
= go7007_usb_ezusb_write_interrupt
,
939 .read_interrupt
= go7007_usb_read_interrupt
,
940 .stream_start
= go7007_usb_stream_start
,
941 .stream_stop
= go7007_usb_stream_stop
,
942 .send_firmware
= go7007_usb_send_firmware
,
943 .release
= go7007_usb_release
,
946 static struct go7007_hpi_ops go7007_usb_onboard_hpi_ops
= {
947 .interface_reset
= go7007_usb_interface_reset
,
948 .write_interrupt
= go7007_usb_onboard_write_interrupt
,
949 .read_interrupt
= go7007_usb_read_interrupt
,
950 .stream_start
= go7007_usb_stream_start
,
951 .stream_stop
= go7007_usb_stream_stop
,
952 .send_firmware
= go7007_usb_send_firmware
,
953 .release
= go7007_usb_release
,
956 /********************* Driver for EZ-USB I2C adapter *********************/
958 static int go7007_usb_i2c_master_xfer(struct i2c_adapter
*adapter
,
959 struct i2c_msg msgs
[], int num
)
961 struct go7007
*go
= i2c_get_adapdata(adapter
);
962 struct go7007_usb
*usb
= go
->hpi_context
;
963 u8
*buf
= go
->usb_buf
;
967 if (go
->status
== STATUS_SHUTDOWN
)
970 mutex_lock(&usb
->i2c_lock
);
972 for (i
= 0; i
< num
; ++i
) {
973 /* The hardware command is "write some bytes then read some
974 * bytes", so we try to coalesce a write followed by a read
975 * into a single USB transaction */
976 if (i
+ 1 < num
&& msgs
[i
].addr
== msgs
[i
+ 1].addr
&&
977 !(msgs
[i
].flags
& I2C_M_RD
) &&
978 (msgs
[i
+ 1].flags
& I2C_M_RD
)) {
979 #ifdef GO7007_I2C_DEBUG
980 dev_dbg(go
->dev
, "i2c write/read %d/%d bytes on %02x\n",
981 msgs
[i
].len
, msgs
[i
+ 1].len
, msgs
[i
].addr
);
984 buf
[1] = msgs
[i
].len
+ 1;
985 buf
[2] = msgs
[i
].addr
<< 1;
986 memcpy(&buf
[3], msgs
[i
].buf
, msgs
[i
].len
);
987 buf_len
= msgs
[i
].len
+ 3;
988 buf
[buf_len
++] = msgs
[++i
].len
;
989 } else if (msgs
[i
].flags
& I2C_M_RD
) {
990 #ifdef GO7007_I2C_DEBUG
991 dev_dbg(go
->dev
, "i2c read %d bytes on %02x\n",
992 msgs
[i
].len
, msgs
[i
].addr
);
996 buf
[2] = msgs
[i
].addr
<< 1;
997 buf
[3] = msgs
[i
].len
;
1000 #ifdef GO7007_I2C_DEBUG
1001 dev_dbg(go
->dev
, "i2c write %d bytes on %02x\n",
1002 msgs
[i
].len
, msgs
[i
].addr
);
1005 buf
[1] = msgs
[i
].len
+ 1;
1006 buf
[2] = msgs
[i
].addr
<< 1;
1007 memcpy(&buf
[3], msgs
[i
].buf
, msgs
[i
].len
);
1008 buf_len
= msgs
[i
].len
+ 3;
1011 if (go7007_usb_vendor_request(go
, 0x24, 0, 0,
1012 buf
, buf_len
, 0) < 0)
1014 if (msgs
[i
].flags
& I2C_M_RD
) {
1015 memset(buf
, 0, msgs
[i
].len
+ 1);
1016 if (go7007_usb_vendor_request(go
, 0x25, 0, 0, buf
,
1017 msgs
[i
].len
+ 1, 1) < 0)
1019 memcpy(msgs
[i
].buf
, buf
+ 1, msgs
[i
].len
);
1025 mutex_unlock(&usb
->i2c_lock
);
1029 static u32
go7007_usb_functionality(struct i2c_adapter
*adapter
)
1031 /* No errors are reported by the hardware, so we don't bother
1032 * supporting quick writes to avoid confusing probing */
1033 return (I2C_FUNC_SMBUS_EMUL
) & ~I2C_FUNC_SMBUS_QUICK
;
1036 static struct i2c_algorithm go7007_usb_algo
= {
1037 .master_xfer
= go7007_usb_i2c_master_xfer
,
1038 .functionality
= go7007_usb_functionality
,
1041 static struct i2c_adapter go7007_usb_adap_templ
= {
1042 .owner
= THIS_MODULE
,
1043 .name
= "WIS GO7007SB EZ-USB",
1044 .algo
= &go7007_usb_algo
,
1047 /********************* USB add/remove functions *********************/
1049 static int go7007_usb_probe(struct usb_interface
*intf
,
1050 const struct usb_device_id
*id
)
1053 struct go7007_usb
*usb
;
1054 const struct go7007_usb_board
*board
;
1055 struct usb_device
*usbdev
= interface_to_usbdev(intf
);
1056 unsigned num_i2c_devs
;
1058 int video_pipe
, i
, v_urb_len
;
1060 dev_dbg(go
->dev
, "probing new GO7007 USB board\n");
1062 switch (id
->driver_info
) {
1063 case GO7007_BOARDID_MATRIX_II
:
1064 name
= "WIS Matrix II or compatible";
1065 board
= &board_matrix_ii
;
1067 case GO7007_BOARDID_MATRIX_RELOAD
:
1068 name
= "WIS Matrix Reloaded or compatible";
1069 board
= &board_matrix_reload
;
1071 case GO7007_BOARDID_MATRIX_REV
:
1072 name
= "WIS Matrix Revolution or compatible";
1073 board
= &board_matrix_revolution
;
1075 case GO7007_BOARDID_STAR_TREK
:
1076 name
= "WIS Star Trek or compatible";
1077 board
= &board_star_trek
;
1079 case GO7007_BOARDID_XMEN
:
1080 name
= "WIS XMen or compatible";
1081 board
= &board_xmen
;
1083 case GO7007_BOARDID_XMEN_II
:
1084 name
= "WIS XMen II or compatible";
1085 board
= &board_xmen
;
1087 case GO7007_BOARDID_XMEN_III
:
1088 name
= "WIS XMen III or compatible";
1089 board
= &board_xmen
;
1091 case GO7007_BOARDID_PX_M402U
:
1092 name
= "Plextor PX-M402U";
1093 board
= &board_matrix_ii
;
1095 case GO7007_BOARDID_PX_TV402U
:
1096 name
= "Plextor PX-TV402U (unknown tuner)";
1097 board
= &board_px_tv402u
;
1099 case GO7007_BOARDID_LIFEVIEW_LR192
:
1100 dev_err(go
->dev
, "The Lifeview TV Walker Ultra is not supported. Sorry!\n");
1102 name
= "Lifeview TV Walker Ultra";
1103 board
= &board_lifeview_lr192
;
1105 case GO7007_BOARDID_SENSORAY_2250
:
1106 dev_info(go
->dev
, "Sensoray 2250 found\n");
1107 name
= "Sensoray 2250/2251";
1108 board
= &board_sensoray_2250
;
1110 case GO7007_BOARDID_ADS_USBAV_709
:
1111 name
= "ADS Tech DVD Xpress DX2";
1112 board
= &board_ads_usbav_709
;
1115 dev_err(go
->dev
, "unknown board ID %d!\n",
1116 (unsigned int)id
->driver_info
);
1120 go
= go7007_alloc(&board
->main_info
, &intf
->dev
);
1124 usb
= kzalloc(sizeof(struct go7007_usb
), GFP_KERNEL
);
1131 usb
->usbdev
= usbdev
;
1132 usb_make_path(usbdev
, go
->bus_info
, sizeof(go
->bus_info
));
1133 go
->board_id
= id
->driver_info
;
1134 strncpy(go
->name
, name
, sizeof(go
->name
));
1135 if (board
->flags
& GO7007_USB_EZUSB
)
1136 go
->hpi_ops
= &go7007_usb_ezusb_hpi_ops
;
1138 go
->hpi_ops
= &go7007_usb_onboard_hpi_ops
;
1139 go
->hpi_context
= usb
;
1141 /* Allocate the URB and buffer for receiving incoming interrupts */
1142 usb
->intr_urb
= usb_alloc_urb(0, GFP_KERNEL
);
1143 if (usb
->intr_urb
== NULL
)
1145 usb
->intr_urb
->transfer_buffer
= kmalloc(2*sizeof(u16
), GFP_KERNEL
);
1146 if (usb
->intr_urb
->transfer_buffer
== NULL
)
1149 if (go
->board_id
== GO7007_BOARDID_SENSORAY_2250
)
1150 usb_fill_bulk_urb(usb
->intr_urb
, usb
->usbdev
,
1151 usb_rcvbulkpipe(usb
->usbdev
, 4),
1152 usb
->intr_urb
->transfer_buffer
, 2*sizeof(u16
),
1153 go7007_usb_readinterrupt_complete
, go
);
1155 usb_fill_int_urb(usb
->intr_urb
, usb
->usbdev
,
1156 usb_rcvintpipe(usb
->usbdev
, 4),
1157 usb
->intr_urb
->transfer_buffer
, 2*sizeof(u16
),
1158 go7007_usb_readinterrupt_complete
, go
, 8);
1159 usb_set_intfdata(intf
, &go
->v4l2_dev
);
1161 /* Boot the GO7007 */
1162 if (go7007_boot_encoder(go
, go
->board_info
->flags
&
1163 GO7007_BOARD_USE_ONBOARD_I2C
) < 0)
1166 /* Register the EZ-USB I2C adapter, if we're using it */
1167 if (board
->flags
& GO7007_USB_EZUSB_I2C
) {
1168 memcpy(&go
->i2c_adapter
, &go7007_usb_adap_templ
,
1169 sizeof(go7007_usb_adap_templ
));
1170 mutex_init(&usb
->i2c_lock
);
1171 go
->i2c_adapter
.dev
.parent
= go
->dev
;
1172 i2c_set_adapdata(&go
->i2c_adapter
, go
);
1173 if (i2c_add_adapter(&go
->i2c_adapter
) < 0) {
1174 dev_err(go
->dev
, "error: i2c_add_adapter failed\n");
1177 go
->i2c_adapter_online
= 1;
1180 /* Pelco and Adlink reused the XMen and XMen-III vendor and product
1181 * IDs for their own incompatible designs. We can detect XMen boards
1182 * by probing the sensor, but there is no way to probe the sensors on
1183 * the Pelco and Adlink designs so we default to the Adlink. If it
1184 * is actually a Pelco, the user must set the assume_endura module
1186 if ((go
->board_id
== GO7007_BOARDID_XMEN
||
1187 go
->board_id
== GO7007_BOARDID_XMEN_III
) &&
1188 go
->i2c_adapter_online
) {
1189 union i2c_smbus_data data
;
1191 /* Check to see if register 0x0A is 0x76 */
1192 i2c_smbus_xfer(&go
->i2c_adapter
, 0x21, I2C_CLIENT_SCCB
,
1193 I2C_SMBUS_READ
, 0x0A, I2C_SMBUS_BYTE_DATA
, &data
);
1194 if (data
.byte
!= 0x76) {
1195 if (assume_endura
) {
1196 go
->board_id
= GO7007_BOARDID_ENDURA
;
1197 usb
->board
= board
= &board_endura
;
1198 go
->board_info
= &board
->main_info
;
1199 strncpy(go
->name
, "Pelco Endura",
1204 /* read channel number from GPIO[1:0] */
1205 go7007_read_addr(go
, 0x3c81, &channel
);
1207 go
->board_id
= GO7007_BOARDID_ADLINK_MPG24
;
1208 usb
->board
= board
= &board_adlink_mpg24
;
1209 go
->board_info
= &board
->main_info
;
1210 go
->channel_number
= channel
;
1211 snprintf(go
->name
, sizeof(go
->name
),
1212 "Adlink PCI-MPG24, channel #%d",
1215 go7007_update_board(go
);
1219 num_i2c_devs
= go
->board_info
->num_i2c_devs
;
1221 /* Probe the tuner model on the TV402U */
1222 if (go
->board_id
== GO7007_BOARDID_PX_TV402U
) {
1223 /* Board strapping indicates tuner model */
1224 if (go7007_usb_vendor_request(go
, 0x41, 0, 0, go
->usb_buf
, 3,
1226 dev_err(go
->dev
, "GPIO read failed!\n");
1229 switch (go
->usb_buf
[0] >> 6) {
1231 go
->tuner_type
= TUNER_SONY_BTF_PG472Z
;
1232 go
->std
= V4L2_STD_PAL
;
1233 strncpy(go
->name
, "Plextor PX-TV402U-EU",
1237 go
->tuner_type
= TUNER_SONY_BTF_PK467Z
;
1238 go
->std
= V4L2_STD_NTSC_M_JP
;
1240 strncpy(go
->name
, "Plextor PX-TV402U-JP",
1244 go
->tuner_type
= TUNER_SONY_BTF_PB463Z
;
1246 strncpy(go
->name
, "Plextor PX-TV402U-NA",
1250 dev_dbg(go
->dev
, "unable to detect tuner type!\n");
1253 /* Configure tuner mode selection inputs connected
1254 * to the EZ-USB GPIO output pins */
1255 if (go7007_usb_vendor_request(go
, 0x40, 0x7f02, 0,
1257 dev_err(go
->dev
, "GPIO write failed!\n");
1262 /* Print a nasty message if the user attempts to use a USB2.0 device in
1263 * a USB1.1 port. There will be silent corruption of the stream. */
1264 if ((board
->flags
& GO7007_USB_EZUSB
) &&
1265 usbdev
->speed
!= USB_SPEED_HIGH
)
1266 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");
1268 /* Allocate the URBs and buffers for receiving the video stream */
1269 if (board
->flags
& GO7007_USB_EZUSB
) {
1271 video_pipe
= usb_rcvbulkpipe(usb
->usbdev
, 6);
1274 video_pipe
= usb_rcvbulkpipe(usb
->usbdev
, 1);
1276 for (i
= 0; i
< 8; ++i
) {
1277 usb
->video_urbs
[i
] = usb_alloc_urb(0, GFP_KERNEL
);
1278 if (usb
->video_urbs
[i
] == NULL
)
1280 usb
->video_urbs
[i
]->transfer_buffer
=
1281 kmalloc(v_urb_len
, GFP_KERNEL
);
1282 if (usb
->video_urbs
[i
]->transfer_buffer
== NULL
)
1284 usb_fill_bulk_urb(usb
->video_urbs
[i
], usb
->usbdev
, video_pipe
,
1285 usb
->video_urbs
[i
]->transfer_buffer
, v_urb_len
,
1286 go7007_usb_read_video_pipe_complete
, go
);
1289 /* Allocate the URBs and buffers for receiving the audio stream */
1290 if ((board
->flags
& GO7007_USB_EZUSB
) &&
1291 (board
->flags
& GO7007_BOARD_HAS_AUDIO
)) {
1292 for (i
= 0; i
< 8; ++i
) {
1293 usb
->audio_urbs
[i
] = usb_alloc_urb(0, GFP_KERNEL
);
1294 if (usb
->audio_urbs
[i
] == NULL
)
1296 usb
->audio_urbs
[i
]->transfer_buffer
= kmalloc(4096,
1298 if (usb
->audio_urbs
[i
]->transfer_buffer
== NULL
)
1300 usb_fill_bulk_urb(usb
->audio_urbs
[i
], usb
->usbdev
,
1301 usb_rcvbulkpipe(usb
->usbdev
, 8),
1302 usb
->audio_urbs
[i
]->transfer_buffer
, 4096,
1303 go7007_usb_read_audio_pipe_complete
, go
);
1307 /* Do any final GO7007 initialization, then register the
1308 * V4L2 and ALSA interfaces */
1309 if (go7007_register_encoder(go
, num_i2c_devs
) < 0)
1312 go
->status
= STATUS_ONLINE
;
1316 go7007_usb_release(go
);
1321 static void go7007_usb_disconnect(struct usb_interface
*intf
)
1323 struct go7007
*go
= to_go7007(usb_get_intfdata(intf
));
1325 mutex_lock(&go
->queue_lock
);
1326 mutex_lock(&go
->serialize_lock
);
1328 if (go
->audio_enabled
)
1329 go7007_snd_remove(go
);
1331 go
->status
= STATUS_SHUTDOWN
;
1332 v4l2_device_disconnect(&go
->v4l2_dev
);
1333 video_unregister_device(&go
->vdev
);
1334 mutex_unlock(&go
->serialize_lock
);
1335 mutex_unlock(&go
->queue_lock
);
1337 v4l2_device_put(&go
->v4l2_dev
);
1340 static struct usb_driver go7007_usb_driver
= {
1342 .probe
= go7007_usb_probe
,
1343 .disconnect
= go7007_usb_disconnect
,
1344 .id_table
= go7007_usb_id_table
,
1347 module_usb_driver(go7007_usb_driver
);
1348 MODULE_LICENSE("GPL v2");