2 * Copyright (C) 2005-2006 Micronas USA Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License (Version 2) as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
18 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/module.h>
21 #include <linux/kernel.h>
22 #include <linux/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/saa7115.h>
31 #include <media/tuner.h>
32 #include <media/uda1342.h>
34 #include "go7007-priv.h"
36 static unsigned int assume_endura
;
37 module_param(assume_endura
, int, 0644);
38 MODULE_PARM_DESC(assume_endura
,
39 "when probing fails, hardware is a Pelco Endura");
41 /* #define GO7007_I2C_DEBUG */ /* for debugging the EZ-USB I2C adapter */
43 #define HPI_STATUS_ADDR 0xFFF4
44 #define INT_PARAM_ADDR 0xFFF6
45 #define INT_INDEX_ADDR 0xFFF8
48 * Pipes on EZ-USB interface:
51 * 2 snd - Download firmware (control)
52 * 4 rcv - Read Interrupt (interrupt)
53 * 6 rcv - Read Video (bulk)
54 * 8 rcv - Read Audio (bulk)
57 #define GO7007_USB_EZUSB (1<<0)
58 #define GO7007_USB_EZUSB_I2C (1<<1)
60 struct go7007_usb_board
{
62 struct go7007_board_info main_info
;
66 const struct go7007_usb_board
*board
;
67 struct mutex i2c_lock
;
68 struct usb_device
*usbdev
;
69 struct urb
*video_urbs
[8];
70 struct urb
*audio_urbs
[8];
74 /*********************** Product specification data ***********************/
76 static const struct go7007_usb_board board_matrix_ii
= {
77 .flags
= GO7007_USB_EZUSB
,
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
|
90 GO7007_SENSOR_SAA7115
|
92 GO7007_SENSOR_SCALING
,
112 .video_config
= SAA7115_IDQ_IS_DEFAULT
,
116 static const struct go7007_usb_board board_matrix_reload
= {
117 .flags
= GO7007_USB_EZUSB
,
119 .flags
= GO7007_BOARD_HAS_AUDIO
|
120 GO7007_BOARD_USE_ONBOARD_I2C
,
121 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
122 GO7007_AUDIO_I2S_MASTER
|
123 GO7007_AUDIO_WORD_16
,
128 .sensor_flags
= GO7007_SENSOR_656
|
149 .video_config
= SAA7115_IDQ_IS_DEFAULT
,
153 static const struct go7007_usb_board board_star_trek
= {
154 .flags
= GO7007_USB_EZUSB
| GO7007_USB_EZUSB_I2C
,
156 .flags
= GO7007_BOARD_HAS_AUDIO
, /* |
157 GO7007_BOARD_HAS_TUNER, */
158 .sensor_flags
= GO7007_SENSOR_656
|
159 GO7007_SENSOR_VALID_ENABLE
|
161 GO7007_SENSOR_SAA7115
|
163 GO7007_SENSOR_SCALING
,
164 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
165 GO7007_AUDIO_WORD_16
,
181 * .audio_index = AUDIO_TUNER,
187 /* .audio_index = AUDIO_EXTERN, */
192 /* .audio_index = AUDIO_EXTERN, */
196 .video_config
= SAA7115_IDQ_IS_DEFAULT
,
200 static const struct go7007_usb_board board_px_tv402u
= {
201 .flags
= GO7007_USB_EZUSB
| GO7007_USB_EZUSB_I2C
,
203 .flags
= GO7007_BOARD_HAS_AUDIO
|
204 GO7007_BOARD_HAS_TUNER
,
205 .sensor_flags
= GO7007_SENSOR_656
|
206 GO7007_SENSOR_VALID_ENABLE
|
208 GO7007_SENSOR_SAA7115
|
210 GO7007_SENSOR_SCALING
,
211 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
212 GO7007_AUDIO_WORD_16
,
237 .type
= "sony-btf-mpx",
259 .video_config
= SAA7115_IDQ_IS_DEFAULT
,
263 .audio_input
= UDA1342_IN2
,
267 .audio_input
= UDA1342_IN1
,
274 static const struct go7007_usb_board board_xmen
= {
277 .flags
= GO7007_BOARD_USE_ONBOARD_I2C
,
279 .sensor_flags
= GO7007_SENSOR_VREF_POLAR
,
281 .sensor_height
= 240,
282 .sensor_framerate
= 30030,
283 .audio_flags
= GO7007_AUDIO_ONE_CHANNEL
|
284 GO7007_AUDIO_I2S_MODE_3
|
285 GO7007_AUDIO_WORD_14
|
286 GO7007_AUDIO_I2S_MASTER
|
287 GO7007_AUDIO_BCLK_POLAR
|
288 GO7007_AUDIO_OKI_MODE
,
290 .audio_bclk_div
= 48,
308 static const struct go7007_usb_board board_matrix_revolution
= {
309 .flags
= GO7007_USB_EZUSB
,
311 .flags
= GO7007_BOARD_HAS_AUDIO
|
312 GO7007_BOARD_USE_ONBOARD_I2C
,
313 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
314 GO7007_AUDIO_I2S_MASTER
|
315 GO7007_AUDIO_WORD_16
,
320 .sensor_flags
= GO7007_SENSOR_656
|
345 static const struct go7007_usb_board board_lifeview_lr192
= {
346 .flags
= GO7007_USB_EZUSB
,
348 .flags
= GO7007_BOARD_HAS_AUDIO
|
349 GO7007_BOARD_USE_ONBOARD_I2C
,
350 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
351 GO7007_AUDIO_WORD_16
,
356 .sensor_flags
= GO7007_SENSOR_656
|
357 GO7007_SENSOR_VALID_ENABLE
|
360 GO7007_SENSOR_SCALING
,
372 static const struct go7007_usb_board board_endura
= {
376 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
377 GO7007_AUDIO_I2S_MASTER
|
378 GO7007_AUDIO_WORD_16
,
380 .audio_bclk_div
= 48,
383 .sensor_flags
= GO7007_SENSOR_656
|
385 .sensor_h_offset
= 8,
396 static const struct go7007_usb_board board_adlink_mpg24
= {
399 .flags
= GO7007_BOARD_USE_ONBOARD_I2C
,
400 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
401 GO7007_AUDIO_I2S_MASTER
|
402 GO7007_AUDIO_WORD_16
,
407 .sensor_flags
= GO7007_SENSOR_656
|
414 .addr
= 0x00, /* yes, really */
415 .flags
= I2C_CLIENT_TEN
,
428 static const struct go7007_usb_board board_sensoray_2250
= {
429 .flags
= GO7007_USB_EZUSB
| GO7007_USB_EZUSB_I2C
,
431 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
432 GO7007_AUDIO_I2S_MASTER
|
433 GO7007_AUDIO_WORD_16
,
434 .flags
= GO7007_BOARD_HAS_AUDIO
,
439 .sensor_flags
= GO7007_SENSOR_656
|
479 static const struct go7007_usb_board board_ads_usbav_709
= {
480 .flags
= GO7007_USB_EZUSB
,
482 .flags
= GO7007_BOARD_HAS_AUDIO
|
483 GO7007_BOARD_USE_ONBOARD_I2C
,
484 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
485 GO7007_AUDIO_I2S_MASTER
|
486 GO7007_AUDIO_WORD_16
,
491 .sensor_flags
= GO7007_SENSOR_656
|
516 static const struct usb_device_id go7007_usb_id_table
[] = {
518 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
|
519 USB_DEVICE_ID_MATCH_INT_INFO
,
520 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
521 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
522 .bcdDevice_lo
= 0x200, /* Revision number of XMen */
523 .bcdDevice_hi
= 0x200,
524 .bInterfaceClass
= 255,
525 .bInterfaceSubClass
= 0,
526 .bInterfaceProtocol
= 255,
527 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_XMEN
,
530 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
531 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
532 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
533 .bcdDevice_lo
= 0x202, /* Revision number of Matrix II */
534 .bcdDevice_hi
= 0x202,
535 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_MATRIX_II
,
538 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
539 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
540 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
541 .bcdDevice_lo
= 0x204, /* Revision number of Matrix */
542 .bcdDevice_hi
= 0x204, /* Reloaded */
543 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_MATRIX_RELOAD
,
546 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
|
547 USB_DEVICE_ID_MATCH_INT_INFO
,
548 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
549 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
550 .bcdDevice_lo
= 0x205, /* Revision number of XMen-II */
551 .bcdDevice_hi
= 0x205,
552 .bInterfaceClass
= 255,
553 .bInterfaceSubClass
= 0,
554 .bInterfaceProtocol
= 255,
555 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_XMEN_II
,
558 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
559 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
560 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
561 .bcdDevice_lo
= 0x208, /* Revision number of Star Trek */
562 .bcdDevice_hi
= 0x208,
563 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_STAR_TREK
,
566 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
|
567 USB_DEVICE_ID_MATCH_INT_INFO
,
568 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
569 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
570 .bcdDevice_lo
= 0x209, /* Revision number of XMen-III */
571 .bcdDevice_hi
= 0x209,
572 .bInterfaceClass
= 255,
573 .bInterfaceSubClass
= 0,
574 .bInterfaceProtocol
= 255,
575 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_XMEN_III
,
578 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
579 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
580 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
581 .bcdDevice_lo
= 0x210, /* Revision number of Matrix */
582 .bcdDevice_hi
= 0x210, /* Revolution */
583 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_MATRIX_REV
,
586 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
587 .idVendor
= 0x093b, /* Vendor ID of Plextor */
588 .idProduct
= 0xa102, /* Product ID of M402U */
589 .bcdDevice_lo
= 0x1, /* revision number of Blueberry */
591 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_PX_M402U
,
594 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
595 .idVendor
= 0x093b, /* Vendor ID of Plextor */
596 .idProduct
= 0xa104, /* Product ID of TV402U */
599 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_PX_TV402U
,
602 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
603 .idVendor
= 0x10fd, /* Vendor ID of Anubis Electronics */
604 .idProduct
= 0xde00, /* Product ID of Lifeview LR192 */
607 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_LIFEVIEW_LR192
,
610 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
611 .idVendor
= 0x1943, /* Vendor ID Sensoray */
612 .idProduct
= 0x2250, /* Product ID of 2250/2251 */
615 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_SENSORAY_2250
,
618 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
619 .idVendor
= 0x06e1, /* Vendor ID of ADS Technologies */
620 .idProduct
= 0x0709, /* Product ID of DVD Xpress DX2 */
621 .bcdDevice_lo
= 0x204,
622 .bcdDevice_hi
= 0x204,
623 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_ADS_USBAV_709
,
625 { } /* Terminating entry */
628 MODULE_DEVICE_TABLE(usb
, go7007_usb_id_table
);
630 /********************* Driver for EZ-USB HPI interface *********************/
632 static int go7007_usb_vendor_request(struct go7007
*go
, int request
,
633 int value
, int index
, void *transfer_buffer
, int length
, int in
)
635 struct go7007_usb
*usb
= go
->hpi_context
;
639 return usb_control_msg(usb
->usbdev
,
640 usb_rcvctrlpipe(usb
->usbdev
, 0), request
,
641 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
642 value
, index
, transfer_buffer
, length
, timeout
);
644 return usb_control_msg(usb
->usbdev
,
645 usb_sndctrlpipe(usb
->usbdev
, 0), request
,
646 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
647 value
, index
, transfer_buffer
, length
, timeout
);
651 static int go7007_usb_interface_reset(struct go7007
*go
)
653 struct go7007_usb
*usb
= go
->hpi_context
;
654 u16 intr_val
, intr_data
;
656 if (go
->status
== STATUS_SHUTDOWN
)
659 if (go7007_write_interrupt(go
, 0x0001, 0x0001) < 0)
663 if (usb
->board
->flags
& GO7007_USB_EZUSB
) {
664 /* Reset buffer in EZ-USB */
665 pr_debug("resetting EZ-USB buffers\n");
666 if (go7007_usb_vendor_request(go
, 0x10, 0, 0, NULL
, 0, 0) < 0 ||
667 go7007_usb_vendor_request(go
, 0x10, 0, 0, NULL
, 0, 0) < 0)
670 /* Reset encoder again */
671 if (go7007_write_interrupt(go
, 0x0001, 0x0001) < 0)
676 /* Wait for an interrupt to indicate successful hardware reset */
677 if (go7007_read_interrupt(go
, &intr_val
, &intr_data
) < 0 ||
678 (intr_val
& ~0x1) != 0x55aa) {
679 dev_err(go
->dev
, "unable to reset the USB interface\n");
685 static int go7007_usb_ezusb_write_interrupt(struct go7007
*go
,
688 struct go7007_usb
*usb
= go
->hpi_context
;
693 pr_debug("WriteInterrupt: %04x %04x\n", addr
, data
);
695 for (i
= 0; i
< 100; ++i
) {
696 r
= usb_control_msg(usb
->usbdev
,
697 usb_rcvctrlpipe(usb
->usbdev
, 0), 0x14,
698 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
699 0, HPI_STATUS_ADDR
, go
->usb_buf
,
700 sizeof(status_reg
), timeout
);
703 status_reg
= le16_to_cpu(*((u16
*)go
->usb_buf
));
704 if (!(status_reg
& 0x0010))
709 goto write_int_error
;
711 dev_err(go
->dev
, "device is hung, status reg = 0x%04x\n", status_reg
);
714 r
= usb_control_msg(usb
->usbdev
, usb_sndctrlpipe(usb
->usbdev
, 0), 0x12,
715 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
, data
,
716 INT_PARAM_ADDR
, NULL
, 0, timeout
);
718 goto write_int_error
;
719 r
= usb_control_msg(usb
->usbdev
, usb_sndctrlpipe(usb
->usbdev
, 0),
720 0x12, USB_TYPE_VENDOR
| USB_RECIP_DEVICE
, addr
,
721 INT_INDEX_ADDR
, NULL
, 0, timeout
);
723 goto write_int_error
;
727 dev_err(go
->dev
, "error in WriteInterrupt: %d\n", r
);
731 static int go7007_usb_onboard_write_interrupt(struct go7007
*go
,
734 struct go7007_usb
*usb
= go
->hpi_context
;
738 pr_debug("WriteInterrupt: %04x %04x\n", addr
, data
);
740 go
->usb_buf
[0] = data
& 0xff;
741 go
->usb_buf
[1] = data
>> 8;
742 go
->usb_buf
[2] = addr
& 0xff;
743 go
->usb_buf
[3] = addr
>> 8;
744 go
->usb_buf
[4] = go
->usb_buf
[5] = go
->usb_buf
[6] = go
->usb_buf
[7] = 0;
745 r
= usb_control_msg(usb
->usbdev
, usb_sndctrlpipe(usb
->usbdev
, 2), 0x00,
746 USB_TYPE_VENDOR
| USB_RECIP_ENDPOINT
, 0x55aa,
747 0xf0f0, go
->usb_buf
, 8, timeout
);
749 dev_err(go
->dev
, "error in WriteInterrupt: %d\n", r
);
755 static void go7007_usb_readinterrupt_complete(struct urb
*urb
)
757 struct go7007
*go
= (struct go7007
*)urb
->context
;
758 u16
*regs
= (u16
*)urb
->transfer_buffer
;
759 int status
= urb
->status
;
762 if (status
!= -ESHUTDOWN
&&
763 go
->status
!= STATUS_SHUTDOWN
) {
764 dev_err(go
->dev
, "error in read interrupt: %d\n", urb
->status
);
766 wake_up(&go
->interrupt_waitq
);
769 } else if (urb
->actual_length
!= urb
->transfer_buffer_length
) {
770 dev_err(go
->dev
, "short read in interrupt pipe!\n");
772 go
->interrupt_available
= 1;
773 go
->interrupt_data
= __le16_to_cpu(regs
[0]);
774 go
->interrupt_value
= __le16_to_cpu(regs
[1]);
775 pr_debug("ReadInterrupt: %04x %04x\n",
776 go
->interrupt_value
, go
->interrupt_data
);
779 wake_up(&go
->interrupt_waitq
);
782 static int go7007_usb_read_interrupt(struct go7007
*go
)
784 struct go7007_usb
*usb
= go
->hpi_context
;
787 r
= usb_submit_urb(usb
->intr_urb
, GFP_KERNEL
);
789 dev_err(go
->dev
, "unable to submit interrupt urb: %d\n", r
);
795 static void go7007_usb_read_video_pipe_complete(struct urb
*urb
)
797 struct go7007
*go
= (struct go7007
*)urb
->context
;
798 int r
, status
= urb
->status
;
800 if (!vb2_is_streaming(&go
->vidq
)) {
801 wake_up_interruptible(&go
->frame_waitq
);
805 dev_err(go
->dev
, "error in video pipe: %d\n", status
);
808 if (urb
->actual_length
!= urb
->transfer_buffer_length
) {
809 dev_err(go
->dev
, "short read in video pipe!\n");
812 go7007_parse_video_stream(go
, urb
->transfer_buffer
, urb
->actual_length
);
813 r
= usb_submit_urb(urb
, GFP_ATOMIC
);
815 dev_err(go
->dev
, "error in video pipe: %d\n", r
);
818 static void go7007_usb_read_audio_pipe_complete(struct urb
*urb
)
820 struct go7007
*go
= (struct go7007
*)urb
->context
;
821 int r
, status
= urb
->status
;
823 if (!vb2_is_streaming(&go
->vidq
))
826 dev_err(go
->dev
, "error in audio pipe: %d\n",
830 if (urb
->actual_length
!= urb
->transfer_buffer_length
) {
831 dev_err(go
->dev
, "short read in audio pipe!\n");
834 if (go
->audio_deliver
!= NULL
)
835 go
->audio_deliver(go
, urb
->transfer_buffer
, urb
->actual_length
);
836 r
= usb_submit_urb(urb
, GFP_ATOMIC
);
838 dev_err(go
->dev
, "error in audio pipe: %d\n", r
);
841 static int go7007_usb_stream_start(struct go7007
*go
)
843 struct go7007_usb
*usb
= go
->hpi_context
;
846 for (i
= 0; i
< 8; ++i
) {
847 r
= usb_submit_urb(usb
->video_urbs
[i
], GFP_KERNEL
);
849 dev_err(go
->dev
, "error submitting video urb %d: %d\n", i
, r
);
850 goto video_submit_failed
;
853 if (!go
->audio_enabled
)
856 for (i
= 0; i
< 8; ++i
) {
857 r
= usb_submit_urb(usb
->audio_urbs
[i
], GFP_KERNEL
);
859 dev_err(go
->dev
, "error submitting audio urb %d: %d\n", i
, r
);
860 goto audio_submit_failed
;
866 for (i
= 0; i
< 7; ++i
)
867 usb_kill_urb(usb
->audio_urbs
[i
]);
869 for (i
= 0; i
< 8; ++i
)
870 usb_kill_urb(usb
->video_urbs
[i
]);
874 static int go7007_usb_stream_stop(struct go7007
*go
)
876 struct go7007_usb
*usb
= go
->hpi_context
;
879 if (go
->status
== STATUS_SHUTDOWN
)
881 for (i
= 0; i
< 8; ++i
)
882 usb_kill_urb(usb
->video_urbs
[i
]);
883 if (go
->audio_enabled
)
884 for (i
= 0; i
< 8; ++i
)
885 usb_kill_urb(usb
->audio_urbs
[i
]);
889 static int go7007_usb_send_firmware(struct go7007
*go
, u8
*data
, int len
)
891 struct go7007_usb
*usb
= go
->hpi_context
;
892 int transferred
, pipe
;
895 pr_debug("DownloadBuffer sending %d bytes\n", len
);
897 if (usb
->board
->flags
& GO7007_USB_EZUSB
)
898 pipe
= usb_sndbulkpipe(usb
->usbdev
, 2);
900 pipe
= usb_sndbulkpipe(usb
->usbdev
, 3);
902 return usb_bulk_msg(usb
->usbdev
, pipe
, data
, len
,
903 &transferred
, timeout
);
906 static void go7007_usb_release(struct go7007
*go
)
908 struct go7007_usb
*usb
= go
->hpi_context
;
909 struct urb
*vurb
, *aurb
;
913 usb_kill_urb(usb
->intr_urb
);
914 kfree(usb
->intr_urb
->transfer_buffer
);
915 usb_free_urb(usb
->intr_urb
);
918 /* Free USB-related structs */
919 for (i
= 0; i
< 8; ++i
) {
920 vurb
= usb
->video_urbs
[i
];
923 kfree(vurb
->transfer_buffer
);
926 aurb
= usb
->audio_urbs
[i
];
929 kfree(aurb
->transfer_buffer
);
934 kfree(go
->hpi_context
);
937 static struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops
= {
938 .interface_reset
= go7007_usb_interface_reset
,
939 .write_interrupt
= go7007_usb_ezusb_write_interrupt
,
940 .read_interrupt
= go7007_usb_read_interrupt
,
941 .stream_start
= go7007_usb_stream_start
,
942 .stream_stop
= go7007_usb_stream_stop
,
943 .send_firmware
= go7007_usb_send_firmware
,
944 .release
= go7007_usb_release
,
947 static struct go7007_hpi_ops go7007_usb_onboard_hpi_ops
= {
948 .interface_reset
= go7007_usb_interface_reset
,
949 .write_interrupt
= go7007_usb_onboard_write_interrupt
,
950 .read_interrupt
= go7007_usb_read_interrupt
,
951 .stream_start
= go7007_usb_stream_start
,
952 .stream_stop
= go7007_usb_stream_stop
,
953 .send_firmware
= go7007_usb_send_firmware
,
954 .release
= go7007_usb_release
,
957 /********************* Driver for EZ-USB I2C adapter *********************/
959 static int go7007_usb_i2c_master_xfer(struct i2c_adapter
*adapter
,
960 struct i2c_msg msgs
[], int num
)
962 struct go7007
*go
= i2c_get_adapdata(adapter
);
963 struct go7007_usb
*usb
= go
->hpi_context
;
964 u8
*buf
= go
->usb_buf
;
968 if (go
->status
== STATUS_SHUTDOWN
)
971 mutex_lock(&usb
->i2c_lock
);
973 for (i
= 0; i
< num
; ++i
) {
974 /* The hardware command is "write some bytes then read some
975 * bytes", so we try to coalesce a write followed by a read
976 * into a single USB transaction */
977 if (i
+ 1 < num
&& msgs
[i
].addr
== msgs
[i
+ 1].addr
&&
978 !(msgs
[i
].flags
& I2C_M_RD
) &&
979 (msgs
[i
+ 1].flags
& I2C_M_RD
)) {
980 #ifdef GO7007_I2C_DEBUG
981 pr_debug("i2c write/read %d/%d bytes on %02x\n",
982 msgs
[i
].len
, msgs
[i
+ 1].len
, msgs
[i
].addr
);
985 buf
[1] = msgs
[i
].len
+ 1;
986 buf
[2] = msgs
[i
].addr
<< 1;
987 memcpy(&buf
[3], msgs
[i
].buf
, msgs
[i
].len
);
988 buf_len
= msgs
[i
].len
+ 3;
989 buf
[buf_len
++] = msgs
[++i
].len
;
990 } else if (msgs
[i
].flags
& I2C_M_RD
) {
991 #ifdef GO7007_I2C_DEBUG
992 pr_debug("i2c read %d bytes on %02x\n",
993 msgs
[i
].len
, msgs
[i
].addr
);
997 buf
[2] = msgs
[i
].addr
<< 1;
998 buf
[3] = msgs
[i
].len
;
1001 #ifdef GO7007_I2C_DEBUG
1002 pr_debug("i2c write %d bytes on %02x\n",
1003 msgs
[i
].len
, msgs
[i
].addr
);
1006 buf
[1] = msgs
[i
].len
+ 1;
1007 buf
[2] = msgs
[i
].addr
<< 1;
1008 memcpy(&buf
[3], msgs
[i
].buf
, msgs
[i
].len
);
1009 buf_len
= msgs
[i
].len
+ 3;
1012 if (go7007_usb_vendor_request(go
, 0x24, 0, 0,
1013 buf
, buf_len
, 0) < 0)
1015 if (msgs
[i
].flags
& I2C_M_RD
) {
1016 memset(buf
, 0, msgs
[i
].len
+ 1);
1017 if (go7007_usb_vendor_request(go
, 0x25, 0, 0, buf
,
1018 msgs
[i
].len
+ 1, 1) < 0)
1020 memcpy(msgs
[i
].buf
, buf
+ 1, msgs
[i
].len
);
1026 mutex_unlock(&usb
->i2c_lock
);
1030 static u32
go7007_usb_functionality(struct i2c_adapter
*adapter
)
1032 /* No errors are reported by the hardware, so we don't bother
1033 * supporting quick writes to avoid confusing probing */
1034 return (I2C_FUNC_SMBUS_EMUL
) & ~I2C_FUNC_SMBUS_QUICK
;
1037 static struct i2c_algorithm go7007_usb_algo
= {
1038 .master_xfer
= go7007_usb_i2c_master_xfer
,
1039 .functionality
= go7007_usb_functionality
,
1042 static struct i2c_adapter go7007_usb_adap_templ
= {
1043 .owner
= THIS_MODULE
,
1044 .name
= "WIS GO7007SB EZ-USB",
1045 .algo
= &go7007_usb_algo
,
1048 /********************* USB add/remove functions *********************/
1050 static int go7007_usb_probe(struct usb_interface
*intf
,
1051 const struct usb_device_id
*id
)
1054 struct go7007_usb
*usb
;
1055 const struct go7007_usb_board
*board
;
1056 struct usb_device
*usbdev
= interface_to_usbdev(intf
);
1057 unsigned num_i2c_devs
;
1059 int video_pipe
, i
, v_urb_len
;
1061 pr_debug("probing new GO7007 USB board\n");
1063 switch (id
->driver_info
) {
1064 case GO7007_BOARDID_MATRIX_II
:
1065 name
= "WIS Matrix II or compatible";
1066 board
= &board_matrix_ii
;
1068 case GO7007_BOARDID_MATRIX_RELOAD
:
1069 name
= "WIS Matrix Reloaded or compatible";
1070 board
= &board_matrix_reload
;
1072 case GO7007_BOARDID_MATRIX_REV
:
1073 name
= "WIS Matrix Revolution or compatible";
1074 board
= &board_matrix_revolution
;
1076 case GO7007_BOARDID_STAR_TREK
:
1077 name
= "WIS Star Trek or compatible";
1078 board
= &board_star_trek
;
1080 case GO7007_BOARDID_XMEN
:
1081 name
= "WIS XMen or compatible";
1082 board
= &board_xmen
;
1084 case GO7007_BOARDID_XMEN_II
:
1085 name
= "WIS XMen II or compatible";
1086 board
= &board_xmen
;
1088 case GO7007_BOARDID_XMEN_III
:
1089 name
= "WIS XMen III or compatible";
1090 board
= &board_xmen
;
1092 case GO7007_BOARDID_PX_M402U
:
1093 name
= "Plextor PX-M402U";
1094 board
= &board_matrix_ii
;
1096 case GO7007_BOARDID_PX_TV402U
:
1097 name
= "Plextor PX-TV402U (unknown tuner)";
1098 board
= &board_px_tv402u
;
1100 case GO7007_BOARDID_LIFEVIEW_LR192
:
1101 dev_err(&intf
->dev
, "The Lifeview TV Walker Ultra is not supported. Sorry!\n");
1103 name
= "Lifeview TV Walker Ultra";
1104 board
= &board_lifeview_lr192
;
1106 case GO7007_BOARDID_SENSORAY_2250
:
1107 dev_info(&intf
->dev
, "Sensoray 2250 found\n");
1108 name
= "Sensoray 2250/2251";
1109 board
= &board_sensoray_2250
;
1111 case GO7007_BOARDID_ADS_USBAV_709
:
1112 name
= "ADS Tech DVD Xpress DX2";
1113 board
= &board_ads_usbav_709
;
1116 dev_err(&intf
->dev
, "unknown board ID %d!\n",
1117 (unsigned int)id
->driver_info
);
1121 go
= go7007_alloc(&board
->main_info
, &intf
->dev
);
1125 usb
= kzalloc(sizeof(struct go7007_usb
), GFP_KERNEL
);
1132 usb
->usbdev
= usbdev
;
1133 usb_make_path(usbdev
, go
->bus_info
, sizeof(go
->bus_info
));
1134 go
->board_id
= id
->driver_info
;
1135 strncpy(go
->name
, name
, sizeof(go
->name
));
1136 if (board
->flags
& GO7007_USB_EZUSB
)
1137 go
->hpi_ops
= &go7007_usb_ezusb_hpi_ops
;
1139 go
->hpi_ops
= &go7007_usb_onboard_hpi_ops
;
1140 go
->hpi_context
= usb
;
1142 /* Allocate the URB and buffer for receiving incoming interrupts */
1143 usb
->intr_urb
= usb_alloc_urb(0, GFP_KERNEL
);
1144 if (usb
->intr_urb
== NULL
)
1146 usb
->intr_urb
->transfer_buffer
= kmalloc(2*sizeof(u16
), GFP_KERNEL
);
1147 if (usb
->intr_urb
->transfer_buffer
== NULL
)
1150 if (go
->board_id
== GO7007_BOARDID_SENSORAY_2250
)
1151 usb_fill_bulk_urb(usb
->intr_urb
, usb
->usbdev
,
1152 usb_rcvbulkpipe(usb
->usbdev
, 4),
1153 usb
->intr_urb
->transfer_buffer
, 2*sizeof(u16
),
1154 go7007_usb_readinterrupt_complete
, go
);
1156 usb_fill_int_urb(usb
->intr_urb
, usb
->usbdev
,
1157 usb_rcvintpipe(usb
->usbdev
, 4),
1158 usb
->intr_urb
->transfer_buffer
, 2*sizeof(u16
),
1159 go7007_usb_readinterrupt_complete
, go
, 8);
1160 usb_set_intfdata(intf
, &go
->v4l2_dev
);
1162 /* Boot the GO7007 */
1163 if (go7007_boot_encoder(go
, go
->board_info
->flags
&
1164 GO7007_BOARD_USE_ONBOARD_I2C
) < 0)
1167 /* Register the EZ-USB I2C adapter, if we're using it */
1168 if (board
->flags
& GO7007_USB_EZUSB_I2C
) {
1169 memcpy(&go
->i2c_adapter
, &go7007_usb_adap_templ
,
1170 sizeof(go7007_usb_adap_templ
));
1171 mutex_init(&usb
->i2c_lock
);
1172 go
->i2c_adapter
.dev
.parent
= go
->dev
;
1173 i2c_set_adapdata(&go
->i2c_adapter
, go
);
1174 if (i2c_add_adapter(&go
->i2c_adapter
) < 0) {
1175 dev_err(go
->dev
, "error: i2c_add_adapter failed\n");
1178 go
->i2c_adapter_online
= 1;
1181 /* Pelco and Adlink reused the XMen and XMen-III vendor and product
1182 * IDs for their own incompatible designs. We can detect XMen boards
1183 * by probing the sensor, but there is no way to probe the sensors on
1184 * the Pelco and Adlink designs so we default to the Adlink. If it
1185 * is actually a Pelco, the user must set the assume_endura module
1187 if ((go
->board_id
== GO7007_BOARDID_XMEN
||
1188 go
->board_id
== GO7007_BOARDID_XMEN_III
) &&
1189 go
->i2c_adapter_online
) {
1190 union i2c_smbus_data data
;
1192 /* Check to see if register 0x0A is 0x76 */
1193 i2c_smbus_xfer(&go
->i2c_adapter
, 0x21, I2C_CLIENT_SCCB
,
1194 I2C_SMBUS_READ
, 0x0A, I2C_SMBUS_BYTE_DATA
, &data
);
1195 if (data
.byte
!= 0x76) {
1196 if (assume_endura
) {
1197 go
->board_id
= GO7007_BOARDID_ENDURA
;
1198 usb
->board
= board
= &board_endura
;
1199 go
->board_info
= &board
->main_info
;
1200 strncpy(go
->name
, "Pelco Endura",
1205 /* read channel number from GPIO[1:0] */
1206 go7007_read_addr(go
, 0x3c81, &channel
);
1208 go
->board_id
= GO7007_BOARDID_ADLINK_MPG24
;
1209 usb
->board
= board
= &board_adlink_mpg24
;
1210 go
->board_info
= &board
->main_info
;
1211 go
->channel_number
= channel
;
1212 snprintf(go
->name
, sizeof(go
->name
),
1213 "Adlink PCI-MPG24, channel #%d",
1216 go7007_update_board(go
);
1220 num_i2c_devs
= go
->board_info
->num_i2c_devs
;
1222 /* Probe the tuner model on the TV402U */
1223 if (go
->board_id
== GO7007_BOARDID_PX_TV402U
) {
1224 /* Board strapping indicates tuner model */
1225 if (go7007_usb_vendor_request(go
, 0x41, 0, 0, go
->usb_buf
, 3,
1227 dev_err(go
->dev
, "GPIO read failed!\n");
1230 switch (go
->usb_buf
[0] >> 6) {
1232 go
->tuner_type
= TUNER_SONY_BTF_PG472Z
;
1233 go
->std
= V4L2_STD_PAL
;
1234 strncpy(go
->name
, "Plextor PX-TV402U-EU",
1238 go
->tuner_type
= TUNER_SONY_BTF_PK467Z
;
1239 go
->std
= V4L2_STD_NTSC_M_JP
;
1241 strncpy(go
->name
, "Plextor PX-TV402U-JP",
1245 go
->tuner_type
= TUNER_SONY_BTF_PB463Z
;
1247 strncpy(go
->name
, "Plextor PX-TV402U-NA",
1251 pr_debug("unable to detect tuner type!\n");
1254 /* Configure tuner mode selection inputs connected
1255 * to the EZ-USB GPIO output pins */
1256 if (go7007_usb_vendor_request(go
, 0x40, 0x7f02, 0,
1258 dev_err(go
->dev
, "GPIO write failed!\n");
1263 /* Print a nasty message if the user attempts to use a USB2.0 device in
1264 * a USB1.1 port. There will be silent corruption of the stream. */
1265 if ((board
->flags
& GO7007_USB_EZUSB
) &&
1266 usbdev
->speed
!= USB_SPEED_HIGH
)
1267 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");
1269 /* Allocate the URBs and buffers for receiving the video stream */
1270 if (board
->flags
& GO7007_USB_EZUSB
) {
1272 video_pipe
= usb_rcvbulkpipe(usb
->usbdev
, 6);
1275 video_pipe
= usb_rcvbulkpipe(usb
->usbdev
, 1);
1277 for (i
= 0; i
< 8; ++i
) {
1278 usb
->video_urbs
[i
] = usb_alloc_urb(0, GFP_KERNEL
);
1279 if (usb
->video_urbs
[i
] == NULL
)
1281 usb
->video_urbs
[i
]->transfer_buffer
=
1282 kmalloc(v_urb_len
, GFP_KERNEL
);
1283 if (usb
->video_urbs
[i
]->transfer_buffer
== NULL
)
1285 usb_fill_bulk_urb(usb
->video_urbs
[i
], usb
->usbdev
, video_pipe
,
1286 usb
->video_urbs
[i
]->transfer_buffer
, v_urb_len
,
1287 go7007_usb_read_video_pipe_complete
, go
);
1290 /* Allocate the URBs and buffers for receiving the audio stream */
1291 if ((board
->flags
& GO7007_USB_EZUSB
) &&
1292 (board
->flags
& GO7007_BOARD_HAS_AUDIO
)) {
1293 for (i
= 0; i
< 8; ++i
) {
1294 usb
->audio_urbs
[i
] = usb_alloc_urb(0, GFP_KERNEL
);
1295 if (usb
->audio_urbs
[i
] == NULL
)
1297 usb
->audio_urbs
[i
]->transfer_buffer
= kmalloc(4096,
1299 if (usb
->audio_urbs
[i
]->transfer_buffer
== NULL
)
1301 usb_fill_bulk_urb(usb
->audio_urbs
[i
], usb
->usbdev
,
1302 usb_rcvbulkpipe(usb
->usbdev
, 8),
1303 usb
->audio_urbs
[i
]->transfer_buffer
, 4096,
1304 go7007_usb_read_audio_pipe_complete
, go
);
1308 /* Do any final GO7007 initialization, then register the
1309 * V4L2 and ALSA interfaces */
1310 if (go7007_register_encoder(go
, num_i2c_devs
) < 0)
1313 go
->status
= STATUS_ONLINE
;
1317 go7007_usb_release(go
);
1322 static void go7007_usb_disconnect(struct usb_interface
*intf
)
1324 struct go7007
*go
= to_go7007(usb_get_intfdata(intf
));
1326 mutex_lock(&go
->queue_lock
);
1327 mutex_lock(&go
->serialize_lock
);
1329 if (go
->audio_enabled
)
1330 go7007_snd_remove(go
);
1332 go
->status
= STATUS_SHUTDOWN
;
1333 v4l2_device_disconnect(&go
->v4l2_dev
);
1334 video_unregister_device(&go
->vdev
);
1335 mutex_unlock(&go
->serialize_lock
);
1336 mutex_unlock(&go
->queue_lock
);
1338 v4l2_device_put(&go
->v4l2_dev
);
1341 static struct usb_driver go7007_usb_driver
= {
1343 .probe
= go7007_usb_probe
,
1344 .disconnect
= go7007_usb_disconnect
,
1345 .id_table
= go7007_usb_id_table
,
1348 module_usb_driver(go7007_usb_driver
);
1349 MODULE_LICENSE("GPL v2");