2 * Driver for the Auvitek USB bridge
4 * Copyright (c) 2008 Steven Toth <stoth@linuxtv.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/module.h>
23 #include <linux/slab.h>
24 #include <linux/videodev2.h>
25 #include <media/v4l2-common.h>
26 #include <linux/mutex.h>
31 * 1 = General debug messages
37 module_param_named(debug
, au0828_debug
, int, 0644);
38 MODULE_PARM_DESC(debug
, "enable debug messages");
40 static unsigned int disable_usb_speed_check
;
41 module_param(disable_usb_speed_check
, int, 0444);
42 MODULE_PARM_DESC(disable_usb_speed_check
,
43 "override min bandwidth requirement of 480M bps");
45 #define _AU0828_BULKPIPE 0x03
46 #define _BULKPIPESIZE 0xffff
48 static int send_control_msg(struct au0828_dev
*dev
, u16 request
, u32 value
,
50 static int recv_control_msg(struct au0828_dev
*dev
, u16 request
, u32 value
,
51 u16 index
, unsigned char *cp
, u16 size
);
54 #define CMD_REQUEST_IN 0x00
55 #define CMD_REQUEST_OUT 0x01
57 u32
au0828_readreg(struct au0828_dev
*dev
, u16 reg
)
61 recv_control_msg(dev
, CMD_REQUEST_IN
, 0, reg
, &result
, 1);
62 dprintk(8, "%s(0x%04x) = 0x%02x\n", __func__
, reg
, result
);
67 u32
au0828_writereg(struct au0828_dev
*dev
, u16 reg
, u32 val
)
69 dprintk(8, "%s(0x%04x, 0x%02x)\n", __func__
, reg
, val
);
70 return send_control_msg(dev
, CMD_REQUEST_OUT
, val
, reg
);
73 static int send_control_msg(struct au0828_dev
*dev
, u16 request
, u32 value
,
80 /* cp must be memory that has been allocated by kmalloc */
81 status
= usb_control_msg(dev
->usbdev
,
82 usb_sndctrlpipe(dev
->usbdev
, 0),
84 USB_DIR_OUT
| USB_TYPE_VENDOR
|
86 value
, index
, NULL
, 0, 1000);
88 status
= min(status
, 0);
91 printk(KERN_ERR
"%s() Failed sending control message, error %d.\n",
100 static int recv_control_msg(struct au0828_dev
*dev
, u16 request
, u32 value
,
101 u16 index
, unsigned char *cp
, u16 size
)
103 int status
= -ENODEV
;
104 mutex_lock(&dev
->mutex
);
106 status
= usb_control_msg(dev
->usbdev
,
107 usb_rcvctrlpipe(dev
->usbdev
, 0),
109 USB_DIR_IN
| USB_TYPE_VENDOR
| USB_RECIP_DEVICE
,
111 dev
->ctrlmsg
, size
, 1000);
113 status
= min(status
, 0);
116 printk(KERN_ERR
"%s() Failed receiving control message, error %d.\n",
120 /* the host controller requires heap allocated memory, which
121 is why we didn't just pass "cp" into usb_control_msg */
122 memcpy(cp
, dev
->ctrlmsg
, size
);
124 mutex_unlock(&dev
->mutex
);
128 static void au0828_usb_release(struct au0828_dev
*dev
)
131 au0828_i2c_unregister(dev
);
136 #ifdef CONFIG_VIDEO_AU0828_V4L2
137 static void au0828_usb_v4l2_release(struct v4l2_device
*v4l2_dev
)
139 struct au0828_dev
*dev
=
140 container_of(v4l2_dev
, struct au0828_dev
, v4l2_dev
);
142 v4l2_ctrl_handler_free(&dev
->v4l2_ctrl_hdl
);
143 v4l2_device_unregister(&dev
->v4l2_dev
);
144 au0828_usb_release(dev
);
148 static void au0828_usb_disconnect(struct usb_interface
*interface
)
150 struct au0828_dev
*dev
= usb_get_intfdata(interface
);
152 dprintk(1, "%s()\n", __func__
);
155 au0828_dvb_unregister(dev
);
157 usb_set_intfdata(interface
, NULL
);
158 mutex_lock(&dev
->mutex
);
160 mutex_unlock(&dev
->mutex
);
161 #ifdef CONFIG_VIDEO_AU0828_V4L2
162 if (AUVI_INPUT(0).type
!= AU0828_VMUX_UNDEFINED
) {
163 au0828_analog_unregister(dev
);
164 v4l2_device_disconnect(&dev
->v4l2_dev
);
165 v4l2_device_put(&dev
->v4l2_dev
);
169 au0828_usb_release(dev
);
172 static int au0828_usb_probe(struct usb_interface
*interface
,
173 const struct usb_device_id
*id
)
178 struct au0828_dev
*dev
;
179 struct usb_device
*usbdev
= interface_to_usbdev(interface
);
181 ifnum
= interface
->altsetting
->desc
.bInterfaceNumber
;
186 dprintk(1, "%s() vendor id 0x%x device id 0x%x ifnum:%d\n", __func__
,
187 le16_to_cpu(usbdev
->descriptor
.idVendor
),
188 le16_to_cpu(usbdev
->descriptor
.idProduct
),
192 * Make sure we have 480 Mbps of bandwidth, otherwise things like
193 * video stream wouldn't likely work, since 12 Mbps is generally
194 * not enough even for most Digital TV streams.
196 if (usbdev
->speed
!= USB_SPEED_HIGH
&& disable_usb_speed_check
== 0) {
197 printk(KERN_ERR
"au0828: Device initialization failed.\n");
198 printk(KERN_ERR
"au0828: Device must be connected to a "
199 "high-speed USB 2.0 port.\n");
203 dev
= kzalloc(sizeof(*dev
), GFP_KERNEL
);
205 printk(KERN_ERR
"%s() Unable to allocate memory\n", __func__
);
209 mutex_init(&dev
->lock
);
210 mutex_lock(&dev
->lock
);
211 mutex_init(&dev
->mutex
);
212 mutex_init(&dev
->dvb
.lock
);
213 dev
->usbdev
= usbdev
;
214 dev
->boardnr
= id
->driver_info
;
216 #ifdef CONFIG_VIDEO_AU0828_V4L2
217 dev
->v4l2_dev
.release
= au0828_usb_v4l2_release
;
219 /* Create the v4l2_device */
220 retval
= v4l2_device_register(&interface
->dev
, &dev
->v4l2_dev
);
222 pr_err("%s() v4l2_device_register failed\n",
224 mutex_unlock(&dev
->lock
);
228 /* This control handler will inherit the controls from au8522 */
229 retval
= v4l2_ctrl_handler_init(&dev
->v4l2_ctrl_hdl
, 4);
231 pr_err("%s() v4l2_ctrl_handler_init failed\n",
233 mutex_unlock(&dev
->lock
);
237 dev
->v4l2_dev
.ctrl_handler
= &dev
->v4l2_ctrl_hdl
;
240 /* Power Up the bridge */
241 au0828_write(dev
, REG_600
, 1 << 4);
243 /* Bring up the GPIO's and supporting devices */
244 au0828_gpio_setup(dev
);
247 au0828_i2c_register(dev
);
250 au0828_card_setup(dev
);
252 #ifdef CONFIG_VIDEO_AU0828_V4L2
254 if (AUVI_INPUT(0).type
!= AU0828_VMUX_UNDEFINED
)
255 au0828_analog_register(dev
, interface
);
259 retval
= au0828_dvb_register(dev
);
261 pr_err("%s() au0282_dev_register failed\n",
265 /* Store the pointer to the au0828_dev so it can be accessed in
266 au0828_usb_disconnect */
267 usb_set_intfdata(interface
, dev
);
269 printk(KERN_INFO
"Registered device AU0828 [%s]\n",
270 dev
->board
.name
== NULL
? "Unset" : dev
->board
.name
);
272 mutex_unlock(&dev
->lock
);
277 static struct usb_driver au0828_usb_driver
= {
279 .probe
= au0828_usb_probe
,
280 .disconnect
= au0828_usb_disconnect
,
281 .id_table
= au0828_usb_id_table
,
284 static int __init
au0828_init(void)
288 if (au0828_debug
& 1)
289 printk(KERN_INFO
"%s() Debugging is enabled\n", __func__
);
291 if (au0828_debug
& 2)
292 printk(KERN_INFO
"%s() USB Debugging is enabled\n", __func__
);
294 if (au0828_debug
& 4)
295 printk(KERN_INFO
"%s() I2C Debugging is enabled\n", __func__
);
297 if (au0828_debug
& 8)
298 printk(KERN_INFO
"%s() Bridge Debugging is enabled\n",
301 printk(KERN_INFO
"au0828 driver loaded\n");
303 ret
= usb_register(&au0828_usb_driver
);
305 printk(KERN_ERR
"usb_register failed, error = %d\n", ret
);
310 static void __exit
au0828_exit(void)
312 usb_deregister(&au0828_usb_driver
);
315 module_init(au0828_init
);
316 module_exit(au0828_exit
);
318 MODULE_DESCRIPTION("Driver for Auvitek AU0828 based products");
319 MODULE_AUTHOR("Steven Toth <stoth@linuxtv.org>");
320 MODULE_LICENSE("GPL");
321 MODULE_VERSION("0.0.2");