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.
14 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
16 #include <linux/module.h>
17 #include <linux/kernel.h>
18 #include <linux/wait.h>
19 #include <linux/list.h>
20 #include <linux/slab.h>
21 #include <linux/time.h>
23 #include <linux/usb.h>
24 #include <linux/i2c.h>
25 #include <asm/byteorder.h>
26 #include <media/i2c/saa7115.h>
27 #include <media/tuner.h>
28 #include <media/i2c/uda1342.h>
30 #include "go7007-priv.h"
32 static unsigned int assume_endura
;
33 module_param(assume_endura
, int, 0644);
34 MODULE_PARM_DESC(assume_endura
,
35 "when probing fails, hardware is a Pelco Endura");
37 /* #define GO7007_I2C_DEBUG */ /* for debugging the EZ-USB I2C adapter */
39 #define HPI_STATUS_ADDR 0xFFF4
40 #define INT_PARAM_ADDR 0xFFF6
41 #define INT_INDEX_ADDR 0xFFF8
44 * Pipes on EZ-USB interface:
47 * 2 snd - Download firmware (control)
48 * 4 rcv - Read Interrupt (interrupt)
49 * 6 rcv - Read Video (bulk)
50 * 8 rcv - Read Audio (bulk)
53 #define GO7007_USB_EZUSB (1<<0)
54 #define GO7007_USB_EZUSB_I2C (1<<1)
56 struct go7007_usb_board
{
58 struct go7007_board_info main_info
;
62 const struct go7007_usb_board
*board
;
63 struct mutex i2c_lock
;
64 struct usb_device
*usbdev
;
65 struct urb
*video_urbs
[8];
66 struct urb
*audio_urbs
[8];
70 /*********************** Product specification data ***********************/
72 static const struct go7007_usb_board board_matrix_ii
= {
73 .flags
= GO7007_USB_EZUSB
,
75 .flags
= GO7007_BOARD_HAS_AUDIO
|
76 GO7007_BOARD_USE_ONBOARD_I2C
,
77 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
83 .sensor_flags
= GO7007_SENSOR_656
|
84 GO7007_SENSOR_VALID_ENABLE
|
86 GO7007_SENSOR_SAA7115
|
88 GO7007_SENSOR_SCALING
,
108 .video_config
= SAA7115_IDQ_IS_DEFAULT
,
112 static const struct go7007_usb_board board_matrix_reload
= {
113 .flags
= GO7007_USB_EZUSB
,
115 .flags
= GO7007_BOARD_HAS_AUDIO
|
116 GO7007_BOARD_USE_ONBOARD_I2C
,
117 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
118 GO7007_AUDIO_I2S_MASTER
|
119 GO7007_AUDIO_WORD_16
,
124 .sensor_flags
= GO7007_SENSOR_656
|
145 .video_config
= SAA7115_IDQ_IS_DEFAULT
,
149 static const struct go7007_usb_board board_star_trek
= {
150 .flags
= GO7007_USB_EZUSB
| GO7007_USB_EZUSB_I2C
,
152 .flags
= GO7007_BOARD_HAS_AUDIO
, /* |
153 GO7007_BOARD_HAS_TUNER, */
154 .sensor_flags
= GO7007_SENSOR_656
|
155 GO7007_SENSOR_VALID_ENABLE
|
157 GO7007_SENSOR_SAA7115
|
159 GO7007_SENSOR_SCALING
,
160 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
161 GO7007_AUDIO_WORD_16
,
177 * .audio_index = AUDIO_TUNER,
183 /* .audio_index = AUDIO_EXTERN, */
188 /* .audio_index = AUDIO_EXTERN, */
192 .video_config
= SAA7115_IDQ_IS_DEFAULT
,
196 static const struct go7007_usb_board board_px_tv402u
= {
197 .flags
= GO7007_USB_EZUSB
| GO7007_USB_EZUSB_I2C
,
199 .flags
= GO7007_BOARD_HAS_AUDIO
|
200 GO7007_BOARD_HAS_TUNER
,
201 .sensor_flags
= GO7007_SENSOR_656
|
202 GO7007_SENSOR_VALID_ENABLE
|
204 GO7007_SENSOR_SAA7115
|
206 GO7007_SENSOR_SCALING
,
207 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
208 GO7007_AUDIO_WORD_16
,
233 .type
= "sony-btf-mpx",
255 .video_config
= SAA7115_IDQ_IS_DEFAULT
,
259 .audio_input
= UDA1342_IN2
,
263 .audio_input
= UDA1342_IN1
,
270 static const struct go7007_usb_board board_xmen
= {
273 .flags
= GO7007_BOARD_USE_ONBOARD_I2C
,
275 .sensor_flags
= GO7007_SENSOR_VREF_POLAR
,
277 .sensor_height
= 240,
278 .sensor_framerate
= 30030,
279 .audio_flags
= GO7007_AUDIO_ONE_CHANNEL
|
280 GO7007_AUDIO_I2S_MODE_3
|
281 GO7007_AUDIO_WORD_14
|
282 GO7007_AUDIO_I2S_MASTER
|
283 GO7007_AUDIO_BCLK_POLAR
|
284 GO7007_AUDIO_OKI_MODE
,
286 .audio_bclk_div
= 48,
304 static const struct go7007_usb_board board_matrix_revolution
= {
305 .flags
= GO7007_USB_EZUSB
,
307 .flags
= GO7007_BOARD_HAS_AUDIO
|
308 GO7007_BOARD_USE_ONBOARD_I2C
,
309 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
310 GO7007_AUDIO_I2S_MASTER
|
311 GO7007_AUDIO_WORD_16
,
316 .sensor_flags
= GO7007_SENSOR_656
|
342 static const struct go7007_usb_board board_lifeview_lr192
= {
343 .flags
= GO7007_USB_EZUSB
,
345 .flags
= GO7007_BOARD_HAS_AUDIO
|
346 GO7007_BOARD_USE_ONBOARD_I2C
,
347 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
348 GO7007_AUDIO_WORD_16
,
353 .sensor_flags
= GO7007_SENSOR_656
|
354 GO7007_SENSOR_VALID_ENABLE
|
357 GO7007_SENSOR_SCALING
,
370 static const struct go7007_usb_board board_endura
= {
374 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
375 GO7007_AUDIO_I2S_MASTER
|
376 GO7007_AUDIO_WORD_16
,
378 .audio_bclk_div
= 48,
381 .sensor_flags
= GO7007_SENSOR_656
|
383 .sensor_h_offset
= 8,
394 static const struct go7007_usb_board board_adlink_mpg24
= {
397 .flags
= GO7007_BOARD_USE_ONBOARD_I2C
,
398 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
399 GO7007_AUDIO_I2S_MASTER
|
400 GO7007_AUDIO_WORD_16
,
405 .sensor_flags
= GO7007_SENSOR_656
|
412 .addr
= 0x00, /* yes, really */
413 .flags
= I2C_CLIENT_TEN
,
426 static const struct go7007_usb_board board_sensoray_2250
= {
427 .flags
= GO7007_USB_EZUSB
| GO7007_USB_EZUSB_I2C
,
429 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
430 GO7007_AUDIO_I2S_MASTER
|
431 GO7007_AUDIO_WORD_16
,
432 .flags
= GO7007_BOARD_HAS_AUDIO
,
437 .sensor_flags
= GO7007_SENSOR_656
|
477 static const struct go7007_usb_board board_ads_usbav_709
= {
478 .flags
= GO7007_USB_EZUSB
,
480 .flags
= GO7007_BOARD_HAS_AUDIO
|
481 GO7007_BOARD_USE_ONBOARD_I2C
,
482 .audio_flags
= GO7007_AUDIO_I2S_MODE_1
|
483 GO7007_AUDIO_I2S_MASTER
|
484 GO7007_AUDIO_WORD_16
,
489 .sensor_flags
= GO7007_SENSOR_656
|
514 static const struct usb_device_id go7007_usb_id_table
[] = {
516 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
|
517 USB_DEVICE_ID_MATCH_INT_INFO
,
518 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
519 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
520 .bcdDevice_lo
= 0x200, /* Revision number of XMen */
521 .bcdDevice_hi
= 0x200,
522 .bInterfaceClass
= 255,
523 .bInterfaceSubClass
= 0,
524 .bInterfaceProtocol
= 255,
525 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_XMEN
,
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
= 0x202, /* Revision number of Matrix II */
532 .bcdDevice_hi
= 0x202,
533 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_MATRIX_II
,
536 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
537 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
538 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
539 .bcdDevice_lo
= 0x204, /* Revision number of Matrix */
540 .bcdDevice_hi
= 0x204, /* Reloaded */
541 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_MATRIX_RELOAD
,
544 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
|
545 USB_DEVICE_ID_MATCH_INT_INFO
,
546 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
547 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
548 .bcdDevice_lo
= 0x205, /* Revision number of XMen-II */
549 .bcdDevice_hi
= 0x205,
550 .bInterfaceClass
= 255,
551 .bInterfaceSubClass
= 0,
552 .bInterfaceProtocol
= 255,
553 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_XMEN_II
,
556 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
557 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
558 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
559 .bcdDevice_lo
= 0x208, /* Revision number of Star Trek */
560 .bcdDevice_hi
= 0x208,
561 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_STAR_TREK
,
564 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
|
565 USB_DEVICE_ID_MATCH_INT_INFO
,
566 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
567 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
568 .bcdDevice_lo
= 0x209, /* Revision number of XMen-III */
569 .bcdDevice_hi
= 0x209,
570 .bInterfaceClass
= 255,
571 .bInterfaceSubClass
= 0,
572 .bInterfaceProtocol
= 255,
573 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_XMEN_III
,
576 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
577 .idVendor
= 0x0eb1, /* Vendor ID of WIS Technologies */
578 .idProduct
= 0x7007, /* Product ID of GO7007SB chip */
579 .bcdDevice_lo
= 0x210, /* Revision number of Matrix */
580 .bcdDevice_hi
= 0x210, /* Revolution */
581 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_MATRIX_REV
,
584 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
585 .idVendor
= 0x093b, /* Vendor ID of Plextor */
586 .idProduct
= 0xa102, /* Product ID of M402U */
587 .bcdDevice_lo
= 0x1, /* revision number of Blueberry */
589 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_PX_M402U
,
592 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
593 .idVendor
= 0x093b, /* Vendor ID of Plextor */
594 .idProduct
= 0xa104, /* Product ID of TV402U */
597 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_PX_TV402U
,
600 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
601 .idVendor
= 0x10fd, /* Vendor ID of Anubis Electronics */
602 .idProduct
= 0xde00, /* Product ID of Lifeview LR192 */
605 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_LIFEVIEW_LR192
,
608 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
609 .idVendor
= 0x1943, /* Vendor ID Sensoray */
610 .idProduct
= 0x2250, /* Product ID of 2250/2251 */
613 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_SENSORAY_2250
,
616 .match_flags
= USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION
,
617 .idVendor
= 0x06e1, /* Vendor ID of ADS Technologies */
618 .idProduct
= 0x0709, /* Product ID of DVD Xpress DX2 */
619 .bcdDevice_lo
= 0x204,
620 .bcdDevice_hi
= 0x204,
621 .driver_info
= (kernel_ulong_t
)GO7007_BOARDID_ADS_USBAV_709
,
623 { } /* Terminating entry */
626 MODULE_DEVICE_TABLE(usb
, go7007_usb_id_table
);
628 /********************* Driver for EZ-USB HPI interface *********************/
630 static int go7007_usb_vendor_request(struct go7007
*go
, int request
,
631 int value
, int index
, void *transfer_buffer
, int length
, int in
)
633 struct go7007_usb
*usb
= go
->hpi_context
;
637 return usb_control_msg(usb
->usbdev
,
638 usb_rcvctrlpipe(usb
->usbdev
, 0), request
,
639 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
640 value
, index
, transfer_buffer
, length
, timeout
);
642 return usb_control_msg(usb
->usbdev
,
643 usb_sndctrlpipe(usb
->usbdev
, 0), request
,
644 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
645 value
, index
, transfer_buffer
, length
, timeout
);
649 static int go7007_usb_interface_reset(struct go7007
*go
)
651 struct go7007_usb
*usb
= go
->hpi_context
;
652 u16 intr_val
, intr_data
;
654 if (go
->status
== STATUS_SHUTDOWN
)
657 if (go7007_write_interrupt(go
, 0x0001, 0x0001) < 0)
661 if (usb
->board
->flags
& GO7007_USB_EZUSB
) {
662 /* Reset buffer in EZ-USB */
663 pr_debug("resetting EZ-USB buffers\n");
664 if (go7007_usb_vendor_request(go
, 0x10, 0, 0, NULL
, 0, 0) < 0 ||
665 go7007_usb_vendor_request(go
, 0x10, 0, 0, NULL
, 0, 0) < 0)
668 /* Reset encoder again */
669 if (go7007_write_interrupt(go
, 0x0001, 0x0001) < 0)
674 /* Wait for an interrupt to indicate successful hardware reset */
675 if (go7007_read_interrupt(go
, &intr_val
, &intr_data
) < 0 ||
676 (intr_val
& ~0x1) != 0x55aa) {
677 dev_err(go
->dev
, "unable to reset the USB interface\n");
683 static int go7007_usb_ezusb_write_interrupt(struct go7007
*go
,
686 struct go7007_usb
*usb
= go
->hpi_context
;
691 pr_debug("WriteInterrupt: %04x %04x\n", addr
, data
);
693 for (i
= 0; i
< 100; ++i
) {
694 r
= usb_control_msg(usb
->usbdev
,
695 usb_rcvctrlpipe(usb
->usbdev
, 0), 0x14,
696 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
| USB_DIR_IN
,
697 0, HPI_STATUS_ADDR
, go
->usb_buf
,
698 sizeof(status_reg
), timeout
);
701 status_reg
= le16_to_cpu(*((__le16
*)go
->usb_buf
));
702 if (!(status_reg
& 0x0010))
707 goto write_int_error
;
709 dev_err(go
->dev
, "device is hung, status reg = 0x%04x\n", status_reg
);
712 r
= usb_control_msg(usb
->usbdev
, usb_sndctrlpipe(usb
->usbdev
, 0), 0x12,
713 USB_TYPE_VENDOR
| USB_RECIP_DEVICE
, data
,
714 INT_PARAM_ADDR
, NULL
, 0, timeout
);
716 goto write_int_error
;
717 r
= usb_control_msg(usb
->usbdev
, usb_sndctrlpipe(usb
->usbdev
, 0),
718 0x12, USB_TYPE_VENDOR
| USB_RECIP_DEVICE
, addr
,
719 INT_INDEX_ADDR
, NULL
, 0, timeout
);
721 goto write_int_error
;
725 dev_err(go
->dev
, "error in WriteInterrupt: %d\n", r
);
729 static int go7007_usb_onboard_write_interrupt(struct go7007
*go
,
732 struct go7007_usb
*usb
= go
->hpi_context
;
736 pr_debug("WriteInterrupt: %04x %04x\n", addr
, data
);
738 go
->usb_buf
[0] = data
& 0xff;
739 go
->usb_buf
[1] = data
>> 8;
740 go
->usb_buf
[2] = addr
& 0xff;
741 go
->usb_buf
[3] = addr
>> 8;
742 go
->usb_buf
[4] = go
->usb_buf
[5] = go
->usb_buf
[6] = go
->usb_buf
[7] = 0;
743 r
= usb_control_msg(usb
->usbdev
, usb_sndctrlpipe(usb
->usbdev
, 2), 0x00,
744 USB_TYPE_VENDOR
| USB_RECIP_ENDPOINT
, 0x55aa,
745 0xf0f0, go
->usb_buf
, 8, timeout
);
747 dev_err(go
->dev
, "error in WriteInterrupt: %d\n", r
);
753 static void go7007_usb_readinterrupt_complete(struct urb
*urb
)
755 struct go7007
*go
= (struct go7007
*)urb
->context
;
756 __le16
*regs
= (__le16
*)urb
->transfer_buffer
;
757 int status
= urb
->status
;
760 if (status
!= -ESHUTDOWN
&&
761 go
->status
!= STATUS_SHUTDOWN
) {
762 dev_err(go
->dev
, "error in read interrupt: %d\n", urb
->status
);
764 wake_up(&go
->interrupt_waitq
);
767 } else if (urb
->actual_length
!= urb
->transfer_buffer_length
) {
768 dev_err(go
->dev
, "short read in interrupt pipe!\n");
770 go
->interrupt_available
= 1;
771 go
->interrupt_data
= __le16_to_cpu(regs
[0]);
772 go
->interrupt_value
= __le16_to_cpu(regs
[1]);
773 pr_debug("ReadInterrupt: %04x %04x\n",
774 go
->interrupt_value
, go
->interrupt_data
);
777 wake_up(&go
->interrupt_waitq
);
780 static int go7007_usb_read_interrupt(struct go7007
*go
)
782 struct go7007_usb
*usb
= go
->hpi_context
;
785 r
= usb_submit_urb(usb
->intr_urb
, GFP_KERNEL
);
787 dev_err(go
->dev
, "unable to submit interrupt urb: %d\n", r
);
793 static void go7007_usb_read_video_pipe_complete(struct urb
*urb
)
795 struct go7007
*go
= (struct go7007
*)urb
->context
;
796 int r
, status
= urb
->status
;
798 if (!vb2_is_streaming(&go
->vidq
)) {
799 wake_up_interruptible(&go
->frame_waitq
);
803 dev_err(go
->dev
, "error in video pipe: %d\n", status
);
806 if (urb
->actual_length
!= urb
->transfer_buffer_length
) {
807 dev_err(go
->dev
, "short read in video pipe!\n");
810 go7007_parse_video_stream(go
, urb
->transfer_buffer
, urb
->actual_length
);
811 r
= usb_submit_urb(urb
, GFP_ATOMIC
);
813 dev_err(go
->dev
, "error in video pipe: %d\n", r
);
816 static void go7007_usb_read_audio_pipe_complete(struct urb
*urb
)
818 struct go7007
*go
= (struct go7007
*)urb
->context
;
819 int r
, status
= urb
->status
;
821 if (!vb2_is_streaming(&go
->vidq
))
824 dev_err(go
->dev
, "error in audio pipe: %d\n",
828 if (urb
->actual_length
!= urb
->transfer_buffer_length
) {
829 dev_err(go
->dev
, "short read in audio pipe!\n");
832 if (go
->audio_deliver
!= NULL
)
833 go
->audio_deliver(go
, urb
->transfer_buffer
, urb
->actual_length
);
834 r
= usb_submit_urb(urb
, GFP_ATOMIC
);
836 dev_err(go
->dev
, "error in audio pipe: %d\n", r
);
839 static int go7007_usb_stream_start(struct go7007
*go
)
841 struct go7007_usb
*usb
= go
->hpi_context
;
844 for (i
= 0; i
< 8; ++i
) {
845 r
= usb_submit_urb(usb
->video_urbs
[i
], GFP_KERNEL
);
847 dev_err(go
->dev
, "error submitting video urb %d: %d\n", i
, r
);
848 goto video_submit_failed
;
851 if (!go
->audio_enabled
)
854 for (i
= 0; i
< 8; ++i
) {
855 r
= usb_submit_urb(usb
->audio_urbs
[i
], GFP_KERNEL
);
857 dev_err(go
->dev
, "error submitting audio urb %d: %d\n", i
, r
);
858 goto audio_submit_failed
;
864 for (i
= 0; i
< 7; ++i
)
865 usb_kill_urb(usb
->audio_urbs
[i
]);
867 for (i
= 0; i
< 8; ++i
)
868 usb_kill_urb(usb
->video_urbs
[i
]);
872 static int go7007_usb_stream_stop(struct go7007
*go
)
874 struct go7007_usb
*usb
= go
->hpi_context
;
877 if (go
->status
== STATUS_SHUTDOWN
)
879 for (i
= 0; i
< 8; ++i
)
880 usb_kill_urb(usb
->video_urbs
[i
]);
881 if (go
->audio_enabled
)
882 for (i
= 0; i
< 8; ++i
)
883 usb_kill_urb(usb
->audio_urbs
[i
]);
887 static int go7007_usb_send_firmware(struct go7007
*go
, u8
*data
, int len
)
889 struct go7007_usb
*usb
= go
->hpi_context
;
890 int transferred
, pipe
;
893 pr_debug("DownloadBuffer sending %d bytes\n", len
);
895 if (usb
->board
->flags
& GO7007_USB_EZUSB
)
896 pipe
= usb_sndbulkpipe(usb
->usbdev
, 2);
898 pipe
= usb_sndbulkpipe(usb
->usbdev
, 3);
900 return usb_bulk_msg(usb
->usbdev
, pipe
, data
, len
,
901 &transferred
, timeout
);
904 static void go7007_usb_release(struct go7007
*go
)
906 struct go7007_usb
*usb
= go
->hpi_context
;
907 struct urb
*vurb
, *aurb
;
911 usb_kill_urb(usb
->intr_urb
);
912 kfree(usb
->intr_urb
->transfer_buffer
);
913 usb_free_urb(usb
->intr_urb
);
916 /* Free USB-related structs */
917 for (i
= 0; i
< 8; ++i
) {
918 vurb
= usb
->video_urbs
[i
];
921 kfree(vurb
->transfer_buffer
);
924 aurb
= usb
->audio_urbs
[i
];
927 kfree(aurb
->transfer_buffer
);
932 kfree(go
->hpi_context
);
935 static const struct go7007_hpi_ops go7007_usb_ezusb_hpi_ops
= {
936 .interface_reset
= go7007_usb_interface_reset
,
937 .write_interrupt
= go7007_usb_ezusb_write_interrupt
,
938 .read_interrupt
= go7007_usb_read_interrupt
,
939 .stream_start
= go7007_usb_stream_start
,
940 .stream_stop
= go7007_usb_stream_stop
,
941 .send_firmware
= go7007_usb_send_firmware
,
942 .release
= go7007_usb_release
,
945 static const struct go7007_hpi_ops go7007_usb_onboard_hpi_ops
= {
946 .interface_reset
= go7007_usb_interface_reset
,
947 .write_interrupt
= go7007_usb_onboard_write_interrupt
,
948 .read_interrupt
= go7007_usb_read_interrupt
,
949 .stream_start
= go7007_usb_stream_start
,
950 .stream_stop
= go7007_usb_stream_stop
,
951 .send_firmware
= go7007_usb_send_firmware
,
952 .release
= go7007_usb_release
,
955 /********************* Driver for EZ-USB I2C adapter *********************/
957 static int go7007_usb_i2c_master_xfer(struct i2c_adapter
*adapter
,
958 struct i2c_msg msgs
[], int num
)
960 struct go7007
*go
= i2c_get_adapdata(adapter
);
961 struct go7007_usb
*usb
= go
->hpi_context
;
962 u8
*buf
= go
->usb_buf
;
966 if (go
->status
== STATUS_SHUTDOWN
)
969 mutex_lock(&usb
->i2c_lock
);
971 for (i
= 0; i
< num
; ++i
) {
972 /* The hardware command is "write some bytes then read some
973 * bytes", so we try to coalesce a write followed by a read
974 * into a single USB transaction */
975 if (i
+ 1 < num
&& msgs
[i
].addr
== msgs
[i
+ 1].addr
&&
976 !(msgs
[i
].flags
& I2C_M_RD
) &&
977 (msgs
[i
+ 1].flags
& I2C_M_RD
)) {
978 #ifdef GO7007_I2C_DEBUG
979 pr_debug("i2c write/read %d/%d bytes on %02x\n",
980 msgs
[i
].len
, msgs
[i
+ 1].len
, msgs
[i
].addr
);
983 buf
[1] = msgs
[i
].len
+ 1;
984 buf
[2] = msgs
[i
].addr
<< 1;
985 memcpy(&buf
[3], msgs
[i
].buf
, msgs
[i
].len
);
986 buf_len
= msgs
[i
].len
+ 3;
987 buf
[buf_len
++] = msgs
[++i
].len
;
988 } else if (msgs
[i
].flags
& I2C_M_RD
) {
989 #ifdef GO7007_I2C_DEBUG
990 pr_debug("i2c read %d bytes on %02x\n",
991 msgs
[i
].len
, msgs
[i
].addr
);
995 buf
[2] = msgs
[i
].addr
<< 1;
996 buf
[3] = msgs
[i
].len
;
999 #ifdef GO7007_I2C_DEBUG
1000 pr_debug("i2c write %d bytes on %02x\n",
1001 msgs
[i
].len
, msgs
[i
].addr
);
1004 buf
[1] = msgs
[i
].len
+ 1;
1005 buf
[2] = msgs
[i
].addr
<< 1;
1006 memcpy(&buf
[3], msgs
[i
].buf
, msgs
[i
].len
);
1007 buf_len
= msgs
[i
].len
+ 3;
1010 if (go7007_usb_vendor_request(go
, 0x24, 0, 0,
1011 buf
, buf_len
, 0) < 0)
1013 if (msgs
[i
].flags
& I2C_M_RD
) {
1014 memset(buf
, 0, msgs
[i
].len
+ 1);
1015 if (go7007_usb_vendor_request(go
, 0x25, 0, 0, buf
,
1016 msgs
[i
].len
+ 1, 1) < 0)
1018 memcpy(msgs
[i
].buf
, buf
+ 1, msgs
[i
].len
);
1024 mutex_unlock(&usb
->i2c_lock
);
1028 static u32
go7007_usb_functionality(struct i2c_adapter
*adapter
)
1030 /* No errors are reported by the hardware, so we don't bother
1031 * supporting quick writes to avoid confusing probing */
1032 return (I2C_FUNC_SMBUS_EMUL
) & ~I2C_FUNC_SMBUS_QUICK
;
1035 static const struct i2c_algorithm go7007_usb_algo
= {
1036 .master_xfer
= go7007_usb_i2c_master_xfer
,
1037 .functionality
= go7007_usb_functionality
,
1040 static struct i2c_adapter go7007_usb_adap_templ
= {
1041 .owner
= THIS_MODULE
,
1042 .name
= "WIS GO7007SB EZ-USB",
1043 .algo
= &go7007_usb_algo
,
1046 /********************* USB add/remove functions *********************/
1048 static int go7007_usb_probe(struct usb_interface
*intf
,
1049 const struct usb_device_id
*id
)
1052 struct go7007_usb
*usb
;
1053 const struct go7007_usb_board
*board
;
1054 struct usb_device
*usbdev
= interface_to_usbdev(intf
);
1055 unsigned num_i2c_devs
;
1057 int video_pipe
, i
, v_urb_len
;
1059 pr_debug("probing new GO7007 USB board\n");
1061 switch (id
->driver_info
) {
1062 case GO7007_BOARDID_MATRIX_II
:
1063 name
= "WIS Matrix II or compatible";
1064 board
= &board_matrix_ii
;
1066 case GO7007_BOARDID_MATRIX_RELOAD
:
1067 name
= "WIS Matrix Reloaded or compatible";
1068 board
= &board_matrix_reload
;
1070 case GO7007_BOARDID_MATRIX_REV
:
1071 name
= "WIS Matrix Revolution or compatible";
1072 board
= &board_matrix_revolution
;
1074 case GO7007_BOARDID_STAR_TREK
:
1075 name
= "WIS Star Trek or compatible";
1076 board
= &board_star_trek
;
1078 case GO7007_BOARDID_XMEN
:
1079 name
= "WIS XMen or compatible";
1080 board
= &board_xmen
;
1082 case GO7007_BOARDID_XMEN_II
:
1083 name
= "WIS XMen II or compatible";
1084 board
= &board_xmen
;
1086 case GO7007_BOARDID_XMEN_III
:
1087 name
= "WIS XMen III or compatible";
1088 board
= &board_xmen
;
1090 case GO7007_BOARDID_PX_M402U
:
1091 name
= "Plextor PX-M402U";
1092 board
= &board_matrix_ii
;
1094 case GO7007_BOARDID_PX_TV402U
:
1095 name
= "Plextor PX-TV402U (unknown tuner)";
1096 board
= &board_px_tv402u
;
1098 case GO7007_BOARDID_LIFEVIEW_LR192
:
1099 dev_err(&intf
->dev
, "The Lifeview TV Walker Ultra is not supported. Sorry!\n");
1102 name
= "Lifeview TV Walker Ultra";
1103 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_array(2, sizeof(u16
),
1148 if (usb
->intr_urb
->transfer_buffer
== NULL
)
1151 if (go
->board_id
== GO7007_BOARDID_SENSORAY_2250
)
1152 usb_fill_bulk_urb(usb
->intr_urb
, usb
->usbdev
,
1153 usb_rcvbulkpipe(usb
->usbdev
, 4),
1154 usb
->intr_urb
->transfer_buffer
, 2*sizeof(u16
),
1155 go7007_usb_readinterrupt_complete
, go
);
1157 usb_fill_int_urb(usb
->intr_urb
, usb
->usbdev
,
1158 usb_rcvintpipe(usb
->usbdev
, 4),
1159 usb
->intr_urb
->transfer_buffer
, 2*sizeof(u16
),
1160 go7007_usb_readinterrupt_complete
, go
, 8);
1161 usb_set_intfdata(intf
, &go
->v4l2_dev
);
1163 /* Boot the GO7007 */
1164 if (go7007_boot_encoder(go
, go
->board_info
->flags
&
1165 GO7007_BOARD_USE_ONBOARD_I2C
) < 0)
1168 /* Register the EZ-USB I2C adapter, if we're using it */
1169 if (board
->flags
& GO7007_USB_EZUSB_I2C
) {
1170 memcpy(&go
->i2c_adapter
, &go7007_usb_adap_templ
,
1171 sizeof(go7007_usb_adap_templ
));
1172 mutex_init(&usb
->i2c_lock
);
1173 go
->i2c_adapter
.dev
.parent
= go
->dev
;
1174 i2c_set_adapdata(&go
->i2c_adapter
, go
);
1175 if (i2c_add_adapter(&go
->i2c_adapter
) < 0) {
1176 dev_err(go
->dev
, "error: i2c_add_adapter failed\n");
1179 go
->i2c_adapter_online
= 1;
1182 /* Pelco and Adlink reused the XMen and XMen-III vendor and product
1183 * IDs for their own incompatible designs. We can detect XMen boards
1184 * by probing the sensor, but there is no way to probe the sensors on
1185 * the Pelco and Adlink designs so we default to the Adlink. If it
1186 * is actually a Pelco, the user must set the assume_endura module
1188 if ((go
->board_id
== GO7007_BOARDID_XMEN
||
1189 go
->board_id
== GO7007_BOARDID_XMEN_III
) &&
1190 go
->i2c_adapter_online
) {
1191 union i2c_smbus_data data
;
1193 /* Check to see if register 0x0A is 0x76 */
1194 i2c_smbus_xfer(&go
->i2c_adapter
, 0x21, I2C_CLIENT_SCCB
,
1195 I2C_SMBUS_READ
, 0x0A, I2C_SMBUS_BYTE_DATA
, &data
);
1196 if (data
.byte
!= 0x76) {
1197 if (assume_endura
) {
1198 go
->board_id
= GO7007_BOARDID_ENDURA
;
1199 usb
->board
= board
= &board_endura
;
1200 go
->board_info
= &board
->main_info
;
1201 strncpy(go
->name
, "Pelco Endura",
1206 /* read channel number from GPIO[1:0] */
1207 go7007_read_addr(go
, 0x3c81, &channel
);
1209 go
->board_id
= GO7007_BOARDID_ADLINK_MPG24
;
1210 usb
->board
= board
= &board_adlink_mpg24
;
1211 go
->board_info
= &board
->main_info
;
1212 go
->channel_number
= channel
;
1213 snprintf(go
->name
, sizeof(go
->name
),
1214 "Adlink PCI-MPG24, channel #%d",
1217 go7007_update_board(go
);
1221 num_i2c_devs
= go
->board_info
->num_i2c_devs
;
1223 /* Probe the tuner model on the TV402U */
1224 if (go
->board_id
== GO7007_BOARDID_PX_TV402U
) {
1225 /* Board strapping indicates tuner model */
1226 if (go7007_usb_vendor_request(go
, 0x41, 0, 0, go
->usb_buf
, 3,
1228 dev_err(go
->dev
, "GPIO read failed!\n");
1231 switch (go
->usb_buf
[0] >> 6) {
1233 go
->tuner_type
= TUNER_SONY_BTF_PG472Z
;
1234 go
->std
= V4L2_STD_PAL
;
1235 strncpy(go
->name
, "Plextor PX-TV402U-EU",
1239 go
->tuner_type
= TUNER_SONY_BTF_PK467Z
;
1240 go
->std
= V4L2_STD_NTSC_M_JP
;
1242 strncpy(go
->name
, "Plextor PX-TV402U-JP",
1246 go
->tuner_type
= TUNER_SONY_BTF_PB463Z
;
1248 strncpy(go
->name
, "Plextor PX-TV402U-NA",
1252 pr_debug("unable to detect tuner type!\n");
1255 /* Configure tuner mode selection inputs connected
1256 * to the EZ-USB GPIO output pins */
1257 if (go7007_usb_vendor_request(go
, 0x40, 0x7f02, 0,
1259 dev_err(go
->dev
, "GPIO write failed!\n");
1264 /* Print a nasty message if the user attempts to use a USB2.0 device in
1265 * a USB1.1 port. There will be silent corruption of the stream. */
1266 if ((board
->flags
& GO7007_USB_EZUSB
) &&
1267 usbdev
->speed
!= USB_SPEED_HIGH
)
1268 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");
1270 /* Allocate the URBs and buffers for receiving the video stream */
1271 if (board
->flags
& GO7007_USB_EZUSB
) {
1273 video_pipe
= usb_rcvbulkpipe(usb
->usbdev
, 6);
1276 video_pipe
= usb_rcvbulkpipe(usb
->usbdev
, 1);
1278 for (i
= 0; i
< 8; ++i
) {
1279 usb
->video_urbs
[i
] = usb_alloc_urb(0, GFP_KERNEL
);
1280 if (usb
->video_urbs
[i
] == NULL
)
1282 usb
->video_urbs
[i
]->transfer_buffer
=
1283 kmalloc(v_urb_len
, GFP_KERNEL
);
1284 if (usb
->video_urbs
[i
]->transfer_buffer
== NULL
)
1286 usb_fill_bulk_urb(usb
->video_urbs
[i
], usb
->usbdev
, video_pipe
,
1287 usb
->video_urbs
[i
]->transfer_buffer
, v_urb_len
,
1288 go7007_usb_read_video_pipe_complete
, go
);
1291 /* Allocate the URBs and buffers for receiving the audio stream */
1292 if ((board
->flags
& GO7007_USB_EZUSB
) &&
1293 (board
->main_info
.flags
& GO7007_BOARD_HAS_AUDIO
)) {
1294 for (i
= 0; i
< 8; ++i
) {
1295 usb
->audio_urbs
[i
] = usb_alloc_urb(0, GFP_KERNEL
);
1296 if (usb
->audio_urbs
[i
] == NULL
)
1298 usb
->audio_urbs
[i
]->transfer_buffer
= kmalloc(4096,
1300 if (usb
->audio_urbs
[i
]->transfer_buffer
== NULL
)
1302 usb_fill_bulk_urb(usb
->audio_urbs
[i
], usb
->usbdev
,
1303 usb_rcvbulkpipe(usb
->usbdev
, 8),
1304 usb
->audio_urbs
[i
]->transfer_buffer
, 4096,
1305 go7007_usb_read_audio_pipe_complete
, go
);
1309 /* Do any final GO7007 initialization, then register the
1310 * V4L2 and ALSA interfaces */
1311 if (go7007_register_encoder(go
, num_i2c_devs
) < 0)
1314 go
->status
= STATUS_ONLINE
;
1318 go7007_usb_release(go
);
1323 static void go7007_usb_disconnect(struct usb_interface
*intf
)
1325 struct go7007
*go
= to_go7007(usb_get_intfdata(intf
));
1327 mutex_lock(&go
->queue_lock
);
1328 mutex_lock(&go
->serialize_lock
);
1330 if (go
->audio_enabled
)
1331 go7007_snd_remove(go
);
1333 go
->status
= STATUS_SHUTDOWN
;
1334 v4l2_device_disconnect(&go
->v4l2_dev
);
1335 video_unregister_device(&go
->vdev
);
1336 mutex_unlock(&go
->serialize_lock
);
1337 mutex_unlock(&go
->queue_lock
);
1339 v4l2_device_put(&go
->v4l2_dev
);
1342 static struct usb_driver go7007_usb_driver
= {
1344 .probe
= go7007_usb_probe
,
1345 .disconnect
= go7007_usb_disconnect
,
1346 .id_table
= go7007_usb_id_table
,
1349 module_usb_driver(go7007_usb_driver
);
1350 MODULE_LICENSE("GPL v2");