1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2005-2006 Micronas USA Inc.
6 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
8 #include <linux/module.h>
9 #include <linux/kernel.h>
10 #include <linux/wait.h>
11 #include <linux/list.h>
12 #include <linux/slab.h>
13 #include <linux/time.h>
15 #include <linux/usb.h>
16 #include <linux/i2c.h>
17 #include <asm/byteorder.h>
18 #include <media/i2c/saa7115.h>
19 #include <media/tuner.h>
20 #include <media/i2c/uda1342.h>
22 #include "go7007-priv.h"
24 static unsigned int assume_endura
;
25 module_param(assume_endura
, int, 0644);
26 MODULE_PARM_DESC(assume_endura
,
27 "when probing fails, hardware is a Pelco Endura");
29 /* #define GO7007_I2C_DEBUG */ /* for debugging the EZ-USB I2C adapter */
31 #define HPI_STATUS_ADDR 0xFFF4
32 #define INT_PARAM_ADDR 0xFFF6
33 #define INT_INDEX_ADDR 0xFFF8
36 * Pipes on EZ-USB interface:
39 * 2 snd - Download firmware (control)
40 * 4 rcv - Read Interrupt (interrupt)
41 * 6 rcv - Read Video (bulk)
42 * 8 rcv - Read Audio (bulk)
45 #define GO7007_USB_EZUSB (1<<0)
46 #define GO7007_USB_EZUSB_I2C (1<<1)
48 struct go7007_usb_board
{
50 struct go7007_board_info main_info
;
54 const struct go7007_usb_board
*board
;
55 struct mutex i2c_lock
;
56 struct usb_device
*usbdev
;
57 struct urb
*video_urbs
[8];
58 struct urb
*audio_urbs
[8];
62 /*********************** Product specification data ***********************/
64 static const struct go7007_usb_board board_matrix_ii
= {
65 .flags
= GO7007_USB_EZUSB
,
67 .flags
= GO7007_BOARD_HAS_AUDIO
|
68 GO7007_BOARD_USE_ONBOARD_I2C
,
69 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
75 .sensor_flags
= GO7007_SENSOR_656
|
76 GO7007_SENSOR_VALID_ENABLE
|
78 GO7007_SENSOR_SAA7115
|
80 GO7007_SENSOR_SCALING
,
100 .video_config
= SAA7115_IDQ_IS_DEFAULT
,
104 static const struct go7007_usb_board board_matrix_reload
= {
105 .flags
= GO7007_USB_EZUSB
,
107 .flags
= GO7007_BOARD_HAS_AUDIO
|
108 GO7007_BOARD_USE_ONBOARD_I2C
,
109 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
110 GO7007_AUDIO_I2S_MASTER
|
111 GO7007_AUDIO_WORD_16
,
116 .sensor_flags
= GO7007_SENSOR_656
|
137 .video_config
= SAA7115_IDQ_IS_DEFAULT
,
141 static const struct go7007_usb_board board_star_trek
= {
142 .flags
= GO7007_USB_EZUSB
| GO7007_USB_EZUSB_I2C
,
144 .flags
= GO7007_BOARD_HAS_AUDIO
, /* |
145 GO7007_BOARD_HAS_TUNER, */
146 .sensor_flags
= GO7007_SENSOR_656
|
147 GO7007_SENSOR_VALID_ENABLE
|
149 GO7007_SENSOR_SAA7115
|
151 GO7007_SENSOR_SCALING
,
152 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
153 GO7007_AUDIO_WORD_16
,
169 * .audio_index = AUDIO_TUNER,
175 /* .audio_index = AUDIO_EXTERN, */
180 /* .audio_index = AUDIO_EXTERN, */
184 .video_config
= SAA7115_IDQ_IS_DEFAULT
,
188 static const struct go7007_usb_board board_px_tv402u
= {
189 .flags
= GO7007_USB_EZUSB
| GO7007_USB_EZUSB_I2C
,
191 .flags
= GO7007_BOARD_HAS_AUDIO
|
192 GO7007_BOARD_HAS_TUNER
,
193 .sensor_flags
= GO7007_SENSOR_656
|
194 GO7007_SENSOR_VALID_ENABLE
|
196 GO7007_SENSOR_SAA7115
|
198 GO7007_SENSOR_SCALING
,
199 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
200 GO7007_AUDIO_WORD_16
,
225 .type
= "sony-btf-mpx",
247 .video_config
= SAA7115_IDQ_IS_DEFAULT
,
251 .audio_input
= UDA1342_IN2
,
255 .audio_input
= UDA1342_IN1
,
262 static const struct go7007_usb_board board_xmen
= {
265 .flags
= GO7007_BOARD_USE_ONBOARD_I2C
,
267 .sensor_flags
= GO7007_SENSOR_VREF_POLAR
,
269 .sensor_height
= 240,
270 .sensor_framerate
= 30030,
271 .audio_flags
= GO7007_AUDIO_ONE_CHANNEL
|
272 GO7007_AUDIO_I2S_MODE_3
|
273 GO7007_AUDIO_WORD_14
|
274 GO7007_AUDIO_I2S_MASTER
|
275 GO7007_AUDIO_BCLK_POLAR
|
276 GO7007_AUDIO_OKI_MODE
,
278 .audio_bclk_div
= 48,
296 static const struct go7007_usb_board board_matrix_revolution
= {
297 .flags
= GO7007_USB_EZUSB
,
299 .flags
= GO7007_BOARD_HAS_AUDIO
|
300 GO7007_BOARD_USE_ONBOARD_I2C
,
301 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
302 GO7007_AUDIO_I2S_MASTER
|
303 GO7007_AUDIO_WORD_16
,
308 .sensor_flags
= GO7007_SENSOR_656
|
334 static const struct go7007_usb_board board_lifeview_lr192
= {
335 .flags
= GO7007_USB_EZUSB
,
337 .flags
= GO7007_BOARD_HAS_AUDIO
|
338 GO7007_BOARD_USE_ONBOARD_I2C
,
339 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
340 GO7007_AUDIO_WORD_16
,
345 .sensor_flags
= GO7007_SENSOR_656
|
346 GO7007_SENSOR_VALID_ENABLE
|
349 GO7007_SENSOR_SCALING
,
362 static const struct go7007_usb_board board_endura
= {
366 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
367 GO7007_AUDIO_I2S_MASTER
|
368 GO7007_AUDIO_WORD_16
,
370 .audio_bclk_div
= 48,
373 .sensor_flags
= GO7007_SENSOR_656
|
375 .sensor_h_offset
= 8,
386 static const struct go7007_usb_board board_adlink_mpg24
= {
389 .flags
= GO7007_BOARD_USE_ONBOARD_I2C
,
390 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
391 GO7007_AUDIO_I2S_MASTER
|
392 GO7007_AUDIO_WORD_16
,
397 .sensor_flags
= GO7007_SENSOR_656
|
404 .addr
= 0x00, /* yes, really */
405 .flags
= I2C_CLIENT_TEN
,
418 static const struct go7007_usb_board board_sensoray_2250
= {
419 .flags
= GO7007_USB_EZUSB
| GO7007_USB_EZUSB_I2C
,
421 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
422 GO7007_AUDIO_I2S_MASTER
|
423 GO7007_AUDIO_WORD_16
,
424 .flags
= GO7007_BOARD_HAS_AUDIO
,
429 .sensor_flags
= GO7007_SENSOR_656
|
469 static const struct go7007_usb_board board_ads_usbav_709
= {
470 .flags
= GO7007_USB_EZUSB
,
472 .flags
= GO7007_BOARD_HAS_AUDIO
|
473 GO7007_BOARD_USE_ONBOARD_I2C
,
474 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
475 GO7007_AUDIO_I2S_MASTER
|
476 GO7007_AUDIO_WORD_16
,
481 .sensor_flags
= GO7007_SENSOR_656
|
506 static const struct usb_device_id go7007_usb_id_table
[] = {
508 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
|
509 USB_DEVICE_ID_MATCH_INT_INFO
,
510 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
511 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
512 .bcdDevice_lo
= 0x200, /* Revision number of XMen */
513 .bcdDevice_hi
= 0x200,
514 .bInterfaceClass
= 255,
515 .bInterfaceSubClass
= 0,
516 .bInterfaceProtocol
= 255,
517 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_XMEN
,
520 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
521 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
522 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
523 .bcdDevice_lo
= 0x202, /* Revision number of Matrix II */
524 .bcdDevice_hi
= 0x202,
525 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_MATRIX_II
,
528 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
529 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
530 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
531 .bcdDevice_lo
= 0x204, /* Revision number of Matrix */
532 .bcdDevice_hi
= 0x204, /* Reloaded */
533 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_MATRIX_RELOAD
,
536 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
|
537 USB_DEVICE_ID_MATCH_INT_INFO
,
538 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
539 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
540 .bcdDevice_lo
= 0x205, /* Revision number of XMen-II */
541 .bcdDevice_hi
= 0x205,
542 .bInterfaceClass
= 255,
543 .bInterfaceSubClass
= 0,
544 .bInterfaceProtocol
= 255,
545 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_XMEN_II
,
548 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
549 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
550 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
551 .bcdDevice_lo
= 0x208, /* Revision number of Star Trek */
552 .bcdDevice_hi
= 0x208,
553 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_STAR_TREK
,
556 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
|
557 USB_DEVICE_ID_MATCH_INT_INFO
,
558 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
559 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
560 .bcdDevice_lo
= 0x209, /* Revision number of XMen-III */
561 .bcdDevice_hi
= 0x209,
562 .bInterfaceClass
= 255,
563 .bInterfaceSubClass
= 0,
564 .bInterfaceProtocol
= 255,
565 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_XMEN_III
,
568 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
569 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
570 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
571 .bcdDevice_lo
= 0x210, /* Revision number of Matrix */
572 .bcdDevice_hi
= 0x210, /* Revolution */
573 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_MATRIX_REV
,
576 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
577 .idVendor
= 0x093b, /* Vendor ID of Plextor */
578 .idProduct
= 0xa102, /* Product ID of M402U */
579 .bcdDevice_lo
= 0x1, /* revision number of Blueberry */
581 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_PX_M402U
,
584 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
585 .idVendor
= 0x093b, /* Vendor ID of Plextor */
586 .idProduct
= 0xa104, /* Product ID of TV402U */
589 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_PX_TV402U
,
592 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
593 .idVendor
= 0x10fd, /* Vendor ID of Anubis Electronics */
594 .idProduct
= 0xde00, /* Product ID of Lifeview LR192 */
597 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_LIFEVIEW_LR192
,
600 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
601 .idVendor
= 0x1943, /* Vendor ID Sensoray */
602 .idProduct
= 0x2250, /* Product ID of 2250/2251 */
605 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_SENSORAY_2250
,
608 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
609 .idVendor
= 0x06e1, /* Vendor ID of ADS Technologies */
610 .idProduct
= 0x0709, /* Product ID of DVD Xpress DX2 */
611 .bcdDevice_lo
= 0x204,
612 .bcdDevice_hi
= 0x204,
613 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_ADS_USBAV_709
,
615 { } /* Terminating entry */
618 MODULE_DEVICE_TABLE(usb
, go7007_usb_id_table
);
620 /********************* Driver for EZ-USB HPI interface *********************/
622 static int go7007_usb_vendor_request(struct go7007
*go
, int request
,
623 int value
, int index
, void *transfer_buffer
, int length
, int in
)
625 struct go7007_usb
*usb
= go
->hpi_context
;
629 return usb_control_msg(usb
->usbdev
,
630 usb_rcvctrlpipe(usb
->usbdev
, 0), request
,
631 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
632 value
, index
, transfer_buffer
, length
, timeout
);
634 return usb_control_msg(usb
->usbdev
,
635 usb_sndctrlpipe(usb
->usbdev
, 0), request
,
636 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
637 value
, index
, transfer_buffer
, length
, timeout
);
641 static int go7007_usb_interface_reset(struct go7007
*go
)
643 struct go7007_usb
*usb
= go
->hpi_context
;
644 u16 intr_val
, intr_data
;
646 if (go
->status
== STATUS_SHUTDOWN
)
649 if (go7007_write_interrupt(go
, 0x0001, 0x0001) < 0)
653 if (usb
->board
->flags
& GO7007_USB_EZUSB
) {
654 /* Reset buffer in EZ-USB */
655 pr_debug("resetting EZ-USB buffers\n");
656 if (go7007_usb_vendor_request(go
, 0x10, 0, 0, NULL
, 0, 0) < 0 ||
657 go7007_usb_vendor_request(go
, 0x10, 0, 0, NULL
, 0, 0) < 0)
660 /* Reset encoder again */
661 if (go7007_write_interrupt(go
, 0x0001, 0x0001) < 0)
666 /* Wait for an interrupt to indicate successful hardware reset */
667 if (go7007_read_interrupt(go
, &intr_val
, &intr_data
) < 0 ||
668 (intr_val
& ~0x1) != 0x55aa) {
669 dev_err(go
->dev
, "unable to reset the USB interface\n");
675 static int go7007_usb_ezusb_write_interrupt(struct go7007
*go
,
678 struct go7007_usb
*usb
= go
->hpi_context
;
683 pr_debug("WriteInterrupt: %04x %04x\n", addr
, data
);
685 for (i
= 0; i
< 100; ++i
) {
686 r
= usb_control_msg(usb
->usbdev
,
687 usb_rcvctrlpipe(usb
->usbdev
, 0), 0x14,
688 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
689 0, HPI_STATUS_ADDR
, go
->usb_buf
,
690 sizeof(status_reg
), timeout
);
693 status_reg
= le16_to_cpu(*((__le16
*)go
->usb_buf
));
694 if (!(status_reg
& 0x0010))
699 goto write_int_error
;
701 dev_err(go
->dev
, "device is hung, status reg = 0x%04x\n", status_reg
);
704 r
= usb_control_msg(usb
->usbdev
, usb_sndctrlpipe(usb
->usbdev
, 0), 0x12,
705 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
, data
,
706 INT_PARAM_ADDR
, NULL
, 0, timeout
);
708 goto write_int_error
;
709 r
= usb_control_msg(usb
->usbdev
, usb_sndctrlpipe(usb
->usbdev
, 0),
710 0x12, USB_TYPE_VENDOR
| USB_RECIP_DEVICE
, addr
,
711 INT_INDEX_ADDR
, NULL
, 0, timeout
);
713 goto write_int_error
;
717 dev_err(go
->dev
, "error in WriteInterrupt: %d\n", r
);
721 static int go7007_usb_onboard_write_interrupt(struct go7007
*go
,
724 struct go7007_usb
*usb
= go
->hpi_context
;
728 pr_debug("WriteInterrupt: %04x %04x\n", addr
, data
);
730 go
->usb_buf
[0] = data
& 0xff;
731 go
->usb_buf
[1] = data
>> 8;
732 go
->usb_buf
[2] = addr
& 0xff;
733 go
->usb_buf
[3] = addr
>> 8;
734 go
->usb_buf
[4] = go
->usb_buf
[5] = go
->usb_buf
[6] = go
->usb_buf
[7] = 0;
735 r
= usb_control_msg(usb
->usbdev
, usb_sndctrlpipe(usb
->usbdev
, 2), 0x00,
736 USB_TYPE_VENDOR
| USB_RECIP_ENDPOINT
, 0x55aa,
737 0xf0f0, go
->usb_buf
, 8, timeout
);
739 dev_err(go
->dev
, "error in WriteInterrupt: %d\n", r
);
745 static void go7007_usb_readinterrupt_complete(struct urb
*urb
)
747 struct go7007
*go
= (struct go7007
*)urb
->context
;
748 __le16
*regs
= (__le16
*)urb
->transfer_buffer
;
749 int status
= urb
->status
;
752 if (status
!= -ESHUTDOWN
&&
753 go
->status
!= STATUS_SHUTDOWN
) {
754 dev_err(go
->dev
, "error in read interrupt: %d\n", urb
->status
);
756 wake_up(&go
->interrupt_waitq
);
759 } else if (urb
->actual_length
!= urb
->transfer_buffer_length
) {
760 dev_err(go
->dev
, "short read in interrupt pipe!\n");
762 go
->interrupt_available
= 1;
763 go
->interrupt_data
= __le16_to_cpu(regs
[0]);
764 go
->interrupt_value
= __le16_to_cpu(regs
[1]);
765 pr_debug("ReadInterrupt: %04x %04x\n",
766 go
->interrupt_value
, go
->interrupt_data
);
769 wake_up(&go
->interrupt_waitq
);
772 static int go7007_usb_read_interrupt(struct go7007
*go
)
774 struct go7007_usb
*usb
= go
->hpi_context
;
777 r
= usb_submit_urb(usb
->intr_urb
, GFP_KERNEL
);
779 dev_err(go
->dev
, "unable to submit interrupt urb: %d\n", r
);
785 static void go7007_usb_read_video_pipe_complete(struct urb
*urb
)
787 struct go7007
*go
= (struct go7007
*)urb
->context
;
788 int r
, status
= urb
->status
;
790 if (!vb2_is_streaming(&go
->vidq
)) {
791 wake_up_interruptible(&go
->frame_waitq
);
795 dev_err(go
->dev
, "error in video pipe: %d\n", status
);
798 if (urb
->actual_length
!= urb
->transfer_buffer_length
) {
799 dev_err(go
->dev
, "short read in video pipe!\n");
802 go7007_parse_video_stream(go
, urb
->transfer_buffer
, urb
->actual_length
);
803 r
= usb_submit_urb(urb
, GFP_ATOMIC
);
805 dev_err(go
->dev
, "error in video pipe: %d\n", r
);
808 static void go7007_usb_read_audio_pipe_complete(struct urb
*urb
)
810 struct go7007
*go
= (struct go7007
*)urb
->context
;
811 int r
, status
= urb
->status
;
813 if (!vb2_is_streaming(&go
->vidq
))
816 dev_err(go
->dev
, "error in audio pipe: %d\n",
820 if (urb
->actual_length
!= urb
->transfer_buffer_length
) {
821 dev_err(go
->dev
, "short read in audio pipe!\n");
824 if (go
->audio_deliver
!= NULL
)
825 go
->audio_deliver(go
, urb
->transfer_buffer
, urb
->actual_length
);
826 r
= usb_submit_urb(urb
, GFP_ATOMIC
);
828 dev_err(go
->dev
, "error in audio pipe: %d\n", r
);
831 static int go7007_usb_stream_start(struct go7007
*go
)
833 struct go7007_usb
*usb
= go
->hpi_context
;
836 for (i
= 0; i
< 8; ++i
) {
837 r
= usb_submit_urb(usb
->video_urbs
[i
], GFP_KERNEL
);
839 dev_err(go
->dev
, "error submitting video urb %d: %d\n", i
, r
);
840 goto video_submit_failed
;
843 if (!go
->audio_enabled
)
846 for (i
= 0; i
< 8; ++i
) {
847 r
= usb_submit_urb(usb
->audio_urbs
[i
], GFP_KERNEL
);
849 dev_err(go
->dev
, "error submitting audio urb %d: %d\n", i
, r
);
850 goto audio_submit_failed
;
856 for (i
= 0; i
< 7; ++i
)
857 usb_kill_urb(usb
->audio_urbs
[i
]);
859 for (i
= 0; i
< 8; ++i
)
860 usb_kill_urb(usb
->video_urbs
[i
]);
864 static int go7007_usb_stream_stop(struct go7007
*go
)
866 struct go7007_usb
*usb
= go
->hpi_context
;
869 if (go
->status
== STATUS_SHUTDOWN
)
871 for (i
= 0; i
< 8; ++i
)
872 usb_kill_urb(usb
->video_urbs
[i
]);
873 if (go
->audio_enabled
)
874 for (i
= 0; i
< 8; ++i
)
875 usb_kill_urb(usb
->audio_urbs
[i
]);
879 static int go7007_usb_send_firmware(struct go7007
*go
, u8
*data
, int len
)
881 struct go7007_usb
*usb
= go
->hpi_context
;
882 int transferred
, pipe
;
885 pr_debug("DownloadBuffer sending %d bytes\n", len
);
887 if (usb
->board
->flags
& GO7007_USB_EZUSB
)
888 pipe
= usb_sndbulkpipe(usb
->usbdev
, 2);
890 pipe
= usb_sndbulkpipe(usb
->usbdev
, 3);
892 return usb_bulk_msg(usb
->usbdev
, pipe
, data
, len
,
893 &transferred
, timeout
);
896 static void go7007_usb_release(struct go7007
*go
)
898 struct go7007_usb
*usb
= go
->hpi_context
;
899 struct urb
*vurb
, *aurb
;
903 usb_kill_urb(usb
->intr_urb
);
904 kfree(usb
->intr_urb
->transfer_buffer
);
905 usb_free_urb(usb
->intr_urb
);
908 /* Free USB-related structs */
909 for (i
= 0; i
< 8; ++i
) {
910 vurb
= usb
->video_urbs
[i
];
913 kfree(vurb
->transfer_buffer
);
916 aurb
= usb
->audio_urbs
[i
];
919 kfree(aurb
->transfer_buffer
);
924 kfree(go
->hpi_context
);
927 static const struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops
= {
928 .interface_reset
= go7007_usb_interface_reset
,
929 .write_interrupt
= go7007_usb_ezusb_write_interrupt
,
930 .read_interrupt
= go7007_usb_read_interrupt
,
931 .stream_start
= go7007_usb_stream_start
,
932 .stream_stop
= go7007_usb_stream_stop
,
933 .send_firmware
= go7007_usb_send_firmware
,
934 .release
= go7007_usb_release
,
937 static const struct go7007_hpi_ops go7007_usb_onboard_hpi_ops
= {
938 .interface_reset
= go7007_usb_interface_reset
,
939 .write_interrupt
= go7007_usb_onboard_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 /********************* Driver for EZ-USB I2C adapter *********************/
949 static int go7007_usb_i2c_master_xfer(struct i2c_adapter
*adapter
,
950 struct i2c_msg msgs
[], int num
)
952 struct go7007
*go
= i2c_get_adapdata(adapter
);
953 struct go7007_usb
*usb
= go
->hpi_context
;
954 u8
*buf
= go
->usb_buf
;
958 if (go
->status
== STATUS_SHUTDOWN
)
961 mutex_lock(&usb
->i2c_lock
);
963 for (i
= 0; i
< num
; ++i
) {
964 /* The hardware command is "write some bytes then read some
965 * bytes", so we try to coalesce a write followed by a read
966 * into a single USB transaction */
967 if (i
+ 1 < num
&& msgs
[i
].addr
== msgs
[i
+ 1].addr
&&
968 !(msgs
[i
].flags
& I2C_M_RD
) &&
969 (msgs
[i
+ 1].flags
& I2C_M_RD
)) {
970 #ifdef GO7007_I2C_DEBUG
971 pr_debug("i2c write/read %d/%d bytes on %02x\n",
972 msgs
[i
].len
, msgs
[i
+ 1].len
, msgs
[i
].addr
);
975 buf
[1] = msgs
[i
].len
+ 1;
976 buf
[2] = msgs
[i
].addr
<< 1;
977 memcpy(&buf
[3], msgs
[i
].buf
, msgs
[i
].len
);
978 buf_len
= msgs
[i
].len
+ 3;
979 buf
[buf_len
++] = msgs
[++i
].len
;
980 } else if (msgs
[i
].flags
& I2C_M_RD
) {
981 #ifdef GO7007_I2C_DEBUG
982 pr_debug("i2c read %d bytes on %02x\n",
983 msgs
[i
].len
, msgs
[i
].addr
);
987 buf
[2] = msgs
[i
].addr
<< 1;
988 buf
[3] = msgs
[i
].len
;
991 #ifdef GO7007_I2C_DEBUG
992 pr_debug("i2c write %d bytes on %02x\n",
993 msgs
[i
].len
, msgs
[i
].addr
);
996 buf
[1] = msgs
[i
].len
+ 1;
997 buf
[2] = msgs
[i
].addr
<< 1;
998 memcpy(&buf
[3], msgs
[i
].buf
, msgs
[i
].len
);
999 buf_len
= msgs
[i
].len
+ 3;
1002 if (go7007_usb_vendor_request(go
, 0x24, 0, 0,
1003 buf
, buf_len
, 0) < 0)
1005 if (msgs
[i
].flags
& I2C_M_RD
) {
1006 memset(buf
, 0, msgs
[i
].len
+ 1);
1007 if (go7007_usb_vendor_request(go
, 0x25, 0, 0, buf
,
1008 msgs
[i
].len
+ 1, 1) < 0)
1010 memcpy(msgs
[i
].buf
, buf
+ 1, msgs
[i
].len
);
1016 mutex_unlock(&usb
->i2c_lock
);
1020 static u32
go7007_usb_functionality(struct i2c_adapter
*adapter
)
1022 /* No errors are reported by the hardware, so we don't bother
1023 * supporting quick writes to avoid confusing probing */
1024 return (I2C_FUNC_SMBUS_EMUL
) & ~I2C_FUNC_SMBUS_QUICK
;
1027 static const struct i2c_algorithm go7007_usb_algo
= {
1028 .master_xfer
= go7007_usb_i2c_master_xfer
,
1029 .functionality
= go7007_usb_functionality
,
1032 static struct i2c_adapter go7007_usb_adap_templ
= {
1033 .owner
= THIS_MODULE
,
1034 .name
= "WIS GO7007SB EZ-USB",
1035 .algo
= &go7007_usb_algo
,
1038 /********************* USB add/remove functions *********************/
1040 static int go7007_usb_probe(struct usb_interface
*intf
,
1041 const struct usb_device_id
*id
)
1044 struct go7007_usb
*usb
;
1045 const struct go7007_usb_board
*board
;
1046 struct usb_device
*usbdev
= interface_to_usbdev(intf
);
1047 struct usb_host_endpoint
*ep
;
1048 unsigned num_i2c_devs
;
1050 int video_pipe
, i
, v_urb_len
;
1052 pr_debug("probing new GO7007 USB board\n");
1054 switch (id
->driver_info
) {
1055 case GO7007_BOARDID_MATRIX_II
:
1056 name
= "WIS Matrix II or compatible";
1057 board
= &board_matrix_ii
;
1059 case GO7007_BOARDID_MATRIX_RELOAD
:
1060 name
= "WIS Matrix Reloaded or compatible";
1061 board
= &board_matrix_reload
;
1063 case GO7007_BOARDID_MATRIX_REV
:
1064 name
= "WIS Matrix Revolution or compatible";
1065 board
= &board_matrix_revolution
;
1067 case GO7007_BOARDID_STAR_TREK
:
1068 name
= "WIS Star Trek or compatible";
1069 board
= &board_star_trek
;
1071 case GO7007_BOARDID_XMEN
:
1072 name
= "WIS XMen or compatible";
1073 board
= &board_xmen
;
1075 case GO7007_BOARDID_XMEN_II
:
1076 name
= "WIS XMen II or compatible";
1077 board
= &board_xmen
;
1079 case GO7007_BOARDID_XMEN_III
:
1080 name
= "WIS XMen III or compatible";
1081 board
= &board_xmen
;
1083 case GO7007_BOARDID_PX_M402U
:
1084 name
= "Plextor PX-M402U";
1085 board
= &board_matrix_ii
;
1087 case GO7007_BOARDID_PX_TV402U
:
1088 name
= "Plextor PX-TV402U (unknown tuner)";
1089 board
= &board_px_tv402u
;
1091 case GO7007_BOARDID_LIFEVIEW_LR192
:
1092 dev_err(&intf
->dev
, "The Lifeview TV Walker Ultra is not supported. Sorry!\n");
1095 name
= "Lifeview TV Walker Ultra";
1096 board
= &board_lifeview_lr192
;
1099 case GO7007_BOARDID_SENSORAY_2250
:
1100 dev_info(&intf
->dev
, "Sensoray 2250 found\n");
1101 name
= "Sensoray 2250/2251";
1102 board
= &board_sensoray_2250
;
1104 case GO7007_BOARDID_ADS_USBAV_709
:
1105 name
= "ADS Tech DVD Xpress DX2";
1106 board
= &board_ads_usbav_709
;
1109 dev_err(&intf
->dev
, "unknown board ID %d!\n",
1110 (unsigned int)id
->driver_info
);
1114 go
= go7007_alloc(&board
->main_info
, &intf
->dev
);
1118 usb
= kzalloc(sizeof(struct go7007_usb
), GFP_KERNEL
);
1125 usb
->usbdev
= usbdev
;
1126 usb_make_path(usbdev
, go
->bus_info
, sizeof(go
->bus_info
));
1127 go
->board_id
= id
->driver_info
;
1128 strscpy(go
->name
, name
, sizeof(go
->name
));
1129 if (board
->flags
& GO7007_USB_EZUSB
)
1130 go
->hpi_ops
= &go7007_usb_ezusb_hpi_ops
;
1132 go
->hpi_ops
= &go7007_usb_onboard_hpi_ops
;
1133 go
->hpi_context
= usb
;
1135 ep
= usb
->usbdev
->ep_in
[4];
1139 /* Allocate the URB and buffer for receiving incoming interrupts */
1140 usb
->intr_urb
= usb_alloc_urb(0, GFP_KERNEL
);
1141 if (usb
->intr_urb
== NULL
)
1143 usb
->intr_urb
->transfer_buffer
= kmalloc_array(2, sizeof(u16
),
1145 if (usb
->intr_urb
->transfer_buffer
== NULL
)
1148 if (usb_endpoint_type(&ep
->desc
) == USB_ENDPOINT_XFER_BULK
)
1149 usb_fill_bulk_urb(usb
->intr_urb
, usb
->usbdev
,
1150 usb_rcvbulkpipe(usb
->usbdev
, 4),
1151 usb
->intr_urb
->transfer_buffer
, 2*sizeof(u16
),
1152 go7007_usb_readinterrupt_complete
, go
);
1154 usb_fill_int_urb(usb
->intr_urb
, usb
->usbdev
,
1155 usb_rcvintpipe(usb
->usbdev
, 4),
1156 usb
->intr_urb
->transfer_buffer
, 2*sizeof(u16
),
1157 go7007_usb_readinterrupt_complete
, go
, 8);
1158 usb_set_intfdata(intf
, &go
->v4l2_dev
);
1160 /* Boot the GO7007 */
1161 if (go7007_boot_encoder(go
, go
->board_info
->flags
&
1162 GO7007_BOARD_USE_ONBOARD_I2C
) < 0)
1165 /* Register the EZ-USB I2C adapter, if we're using it */
1166 if (board
->flags
& GO7007_USB_EZUSB_I2C
) {
1167 memcpy(&go
->i2c_adapter
, &go7007_usb_adap_templ
,
1168 sizeof(go7007_usb_adap_templ
));
1169 mutex_init(&usb
->i2c_lock
);
1170 go
->i2c_adapter
.dev
.parent
= go
->dev
;
1171 i2c_set_adapdata(&go
->i2c_adapter
, go
);
1172 if (i2c_add_adapter(&go
->i2c_adapter
) < 0) {
1173 dev_err(go
->dev
, "error: i2c_add_adapter failed\n");
1176 go
->i2c_adapter_online
= 1;
1179 /* Pelco and Adlink reused the XMen and XMen-III vendor and product
1180 * IDs for their own incompatible designs. We can detect XMen boards
1181 * by probing the sensor, but there is no way to probe the sensors on
1182 * the Pelco and Adlink designs so we default to the Adlink. If it
1183 * is actually a Pelco, the user must set the assume_endura module
1185 if ((go
->board_id
== GO7007_BOARDID_XMEN
||
1186 go
->board_id
== GO7007_BOARDID_XMEN_III
) &&
1187 go
->i2c_adapter_online
) {
1188 union i2c_smbus_data data
;
1190 /* Check to see if register 0x0A is 0x76 */
1191 i2c_smbus_xfer(&go
->i2c_adapter
, 0x21, I2C_CLIENT_SCCB
,
1192 I2C_SMBUS_READ
, 0x0A, I2C_SMBUS_BYTE_DATA
, &data
);
1193 if (data
.byte
!= 0x76) {
1194 if (assume_endura
) {
1195 go
->board_id
= GO7007_BOARDID_ENDURA
;
1196 usb
->board
= board
= &board_endura
;
1197 go
->board_info
= &board
->main_info
;
1198 strscpy(go
->name
, "Pelco Endura",
1203 /* read channel number from GPIO[1:0] */
1204 go7007_read_addr(go
, 0x3c81, &channel
);
1206 go
->board_id
= GO7007_BOARDID_ADLINK_MPG24
;
1207 usb
->board
= board
= &board_adlink_mpg24
;
1208 go
->board_info
= &board
->main_info
;
1209 go
->channel_number
= channel
;
1210 snprintf(go
->name
, sizeof(go
->name
),
1211 "Adlink PCI-MPG24, channel #%d",
1214 go7007_update_board(go
);
1218 num_i2c_devs
= go
->board_info
->num_i2c_devs
;
1220 /* Probe the tuner model on the TV402U */
1221 if (go
->board_id
== GO7007_BOARDID_PX_TV402U
) {
1222 /* Board strapping indicates tuner model */
1223 if (go7007_usb_vendor_request(go
, 0x41, 0, 0, go
->usb_buf
, 3,
1225 dev_err(go
->dev
, "GPIO read failed!\n");
1228 switch (go
->usb_buf
[0] >> 6) {
1230 go
->tuner_type
= TUNER_SONY_BTF_PG472Z
;
1231 go
->std
= V4L2_STD_PAL
;
1232 strscpy(go
->name
, "Plextor PX-TV402U-EU",
1236 go
->tuner_type
= TUNER_SONY_BTF_PK467Z
;
1237 go
->std
= V4L2_STD_NTSC_M_JP
;
1239 strscpy(go
->name
, "Plextor PX-TV402U-JP",
1243 go
->tuner_type
= TUNER_SONY_BTF_PB463Z
;
1245 strscpy(go
->name
, "Plextor PX-TV402U-NA",
1249 pr_debug("unable to detect tuner type!\n");
1252 /* Configure tuner mode selection inputs connected
1253 * to the EZ-USB GPIO output pins */
1254 if (go7007_usb_vendor_request(go
, 0x40, 0x7f02, 0,
1256 dev_err(go
->dev
, "GPIO write failed!\n");
1261 /* Print a nasty message if the user attempts to use a USB2.0 device in
1262 * a USB1.1 port. There will be silent corruption of the stream. */
1263 if ((board
->flags
& GO7007_USB_EZUSB
) &&
1264 usbdev
->speed
!= USB_SPEED_HIGH
)
1265 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");
1267 /* Allocate the URBs and buffers for receiving the video stream */
1268 if (board
->flags
& GO7007_USB_EZUSB
) {
1269 if (!usb
->usbdev
->ep_in
[6])
1272 video_pipe
= usb_rcvbulkpipe(usb
->usbdev
, 6);
1274 if (!usb
->usbdev
->ep_in
[1])
1277 video_pipe
= usb_rcvbulkpipe(usb
->usbdev
, 1);
1279 for (i
= 0; i
< 8; ++i
) {
1280 usb
->video_urbs
[i
] = usb_alloc_urb(0, GFP_KERNEL
);
1281 if (usb
->video_urbs
[i
] == NULL
)
1283 usb
->video_urbs
[i
]->transfer_buffer
=
1284 kmalloc(v_urb_len
, GFP_KERNEL
);
1285 if (usb
->video_urbs
[i
]->transfer_buffer
== NULL
)
1287 usb_fill_bulk_urb(usb
->video_urbs
[i
], usb
->usbdev
, video_pipe
,
1288 usb
->video_urbs
[i
]->transfer_buffer
, v_urb_len
,
1289 go7007_usb_read_video_pipe_complete
, go
);
1292 /* Allocate the URBs and buffers for receiving the audio stream */
1293 if ((board
->flags
& GO7007_USB_EZUSB
) &&
1294 (board
->main_info
.flags
& GO7007_BOARD_HAS_AUDIO
)) {
1295 if (!usb
->usbdev
->ep_in
[8])
1297 for (i
= 0; i
< 8; ++i
) {
1298 usb
->audio_urbs
[i
] = usb_alloc_urb(0, GFP_KERNEL
);
1299 if (usb
->audio_urbs
[i
] == NULL
)
1301 usb
->audio_urbs
[i
]->transfer_buffer
= kmalloc(4096,
1303 if (usb
->audio_urbs
[i
]->transfer_buffer
== NULL
)
1305 usb_fill_bulk_urb(usb
->audio_urbs
[i
], usb
->usbdev
,
1306 usb_rcvbulkpipe(usb
->usbdev
, 8),
1307 usb
->audio_urbs
[i
]->transfer_buffer
, 4096,
1308 go7007_usb_read_audio_pipe_complete
, go
);
1312 /* Do any final GO7007 initialization, then register the
1313 * V4L2 and ALSA interfaces */
1314 if (go7007_register_encoder(go
, num_i2c_devs
) < 0)
1317 go
->status
= STATUS_ONLINE
;
1321 go7007_usb_release(go
);
1326 static void go7007_usb_disconnect(struct usb_interface
*intf
)
1328 struct go7007
*go
= to_go7007(usb_get_intfdata(intf
));
1330 mutex_lock(&go
->queue_lock
);
1331 mutex_lock(&go
->serialize_lock
);
1333 if (go
->audio_enabled
)
1334 go7007_snd_remove(go
);
1336 go
->status
= STATUS_SHUTDOWN
;
1337 v4l2_device_disconnect(&go
->v4l2_dev
);
1338 video_unregister_device(&go
->vdev
);
1339 mutex_unlock(&go
->serialize_lock
);
1340 mutex_unlock(&go
->queue_lock
);
1342 v4l2_device_put(&go
->v4l2_dev
);
1345 static struct usb_driver go7007_usb_driver
= {
1347 .probe
= go7007_usb_probe
,
1348 .disconnect
= go7007_usb_disconnect
,
1349 .id_table
= go7007_usb_id_table
,
1352 module_usb_driver(go7007_usb_driver
);
1353 MODULE_LICENSE("GPL v2");