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/init.h>
24 #include <linux/device.h>
25 #include <linux/suspend.h>
26 #include <media/v4l2-common.h>
34 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
36 #define _AU0828_BULKPIPE 0x83
37 #define _BULKPIPESIZE 0xe522
39 static struct au8522_config hauppauge_hvr950q_config = {
40 .demod_address = 0x8e >> 1,
41 .status_mode = AU8522_DEMODLOCKING,
42 .qam_if = AU8522_IF_6MHZ,
43 .vsb_if = AU8522_IF_6MHZ,
46 static struct au8522_config hauppauge_woodbury_config = {
47 .demod_address = 0x8e >> 1,
48 .status_mode = AU8522_DEMODLOCKING,
49 .qam_if = AU8522_IF_4MHZ,
50 .vsb_if = AU8522_IF_3_25MHZ,
53 static struct xc5000_config hauppauge_hvr950q_tunerconfig = {
56 .tuner_callback = au0828_tuner_callback
59 static struct mxl5007t_config mxl5007t_hvr950q_config = {
60 .xtal_freq_hz = MxL_XTAL_24_MHZ,
61 .if_freq_hz = MxL_IF_6_MHZ,
64 static struct tda18271_config hauppauge_woodbury_tunerconfig = {
65 .gate = TDA18271_GATE_DIGITAL,
68 /*-------------------------------------------------------------------*/
69 static void urb_completion(struct urb *purb)
72 struct au0828_dev *dev = purb->context;
73 int ptype = usb_pipetype(purb->pipe);
75 dprintk(2, "%s()\n", __func__);
80 if (dev->urb_streaming == 0)
83 if (ptype != PIPE_BULK) {
84 printk(KERN_ERR "%s() Unsupported URB type %d\n",
89 ptr = (u8 *)purb->transfer_buffer;
91 /* Feed the transport payload into the kernel demux */
92 dvb_dmx_swfilter_packets(&dev->dvb.demux,
93 purb->transfer_buffer, purb->actual_length / 188);
95 /* Clean the buffer before we requeue */
96 memset(purb->transfer_buffer, 0, URB_BUFSIZE);
99 usb_submit_urb(purb, GFP_ATOMIC);
102 static int stop_urb_transfer(struct au0828_dev *dev)
106 dprintk(2, "%s()\n", __func__);
108 for (i = 0; i < URB_COUNT; i++) {
109 usb_kill_urb(dev->urbs[i]);
110 kfree(dev->urbs[i]->transfer_buffer);
111 usb_free_urb(dev->urbs[i]);
114 dev->urb_streaming = 0;
119 static int start_urb_transfer(struct au0828_dev *dev)
122 int i, ret = -ENOMEM;
124 dprintk(2, "%s()\n", __func__);
126 if (dev->urb_streaming) {
127 dprintk(2, "%s: iso xfer already running!\n", __func__);
131 for (i = 0; i < URB_COUNT; i++) {
133 dev->urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
139 purb->transfer_buffer = kzalloc(URB_BUFSIZE, GFP_KERNEL);
140 if (!purb->transfer_buffer) {
146 purb->status = -EINPROGRESS;
147 usb_fill_bulk_urb(purb,
149 usb_rcvbulkpipe(dev->usbdev, _AU0828_BULKPIPE),
150 purb->transfer_buffer,
157 for (i = 0; i < URB_COUNT; i++) {
158 ret = usb_submit_urb(dev->urbs[i], GFP_ATOMIC);
160 stop_urb_transfer(dev);
161 printk(KERN_ERR "%s: failed urb submission, "
162 "err = %d\n", __func__, ret);
167 dev->urb_streaming = 1;
174 static int au0828_dvb_start_feed(struct dvb_demux_feed *feed)
176 struct dvb_demux *demux = feed->demux;
177 struct au0828_dev *dev = (struct au0828_dev *) demux->priv;
178 struct au0828_dvb *dvb = &dev->dvb;
181 dprintk(1, "%s()\n", __func__);
183 if (!demux->dmx.frontend)
187 mutex_lock(&dvb->lock);
188 if (dvb->feeding++ == 0) {
189 /* Start transport */
190 au0828_write(dev, 0x608, 0x90);
191 au0828_write(dev, 0x609, 0x72);
192 au0828_write(dev, 0x60a, 0x71);
193 au0828_write(dev, 0x60b, 0x01);
194 ret = start_urb_transfer(dev);
196 mutex_unlock(&dvb->lock);
202 static int au0828_dvb_stop_feed(struct dvb_demux_feed *feed)
204 struct dvb_demux *demux = feed->demux;
205 struct au0828_dev *dev = (struct au0828_dev *) demux->priv;
206 struct au0828_dvb *dvb = &dev->dvb;
209 dprintk(1, "%s()\n", __func__);
212 mutex_lock(&dvb->lock);
213 if (--dvb->feeding == 0) {
215 au0828_write(dev, 0x608, 0x00);
216 au0828_write(dev, 0x609, 0x00);
217 au0828_write(dev, 0x60a, 0x00);
218 au0828_write(dev, 0x60b, 0x00);
219 ret = stop_urb_transfer(dev);
221 mutex_unlock(&dvb->lock);
227 static int dvb_register(struct au0828_dev *dev)
229 struct au0828_dvb *dvb = &dev->dvb;
232 dprintk(1, "%s()\n", __func__);
234 /* register adapter */
235 result = dvb_register_adapter(&dvb->adapter, DRIVER_NAME, THIS_MODULE,
236 &dev->usbdev->dev, adapter_nr);
238 printk(KERN_ERR "%s: dvb_register_adapter failed "
239 "(errno = %d)\n", DRIVER_NAME, result);
242 dvb->adapter.priv = dev;
244 /* register frontend */
245 result = dvb_register_frontend(&dvb->adapter, dvb->frontend);
247 printk(KERN_ERR "%s: dvb_register_frontend failed "
248 "(errno = %d)\n", DRIVER_NAME, result);
252 /* register demux stuff */
253 dvb->demux.dmx.capabilities =
254 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
255 DMX_MEMORY_BASED_FILTERING;
256 dvb->demux.priv = dev;
257 dvb->demux.filternum = 256;
258 dvb->demux.feednum = 256;
259 dvb->demux.start_feed = au0828_dvb_start_feed;
260 dvb->demux.stop_feed = au0828_dvb_stop_feed;
261 result = dvb_dmx_init(&dvb->demux);
263 printk(KERN_ERR "%s: dvb_dmx_init failed (errno = %d)\n",
264 DRIVER_NAME, result);
268 dvb->dmxdev.filternum = 256;
269 dvb->dmxdev.demux = &dvb->demux.dmx;
270 dvb->dmxdev.capabilities = 0;
271 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
273 printk(KERN_ERR "%s: dvb_dmxdev_init failed (errno = %d)\n",
274 DRIVER_NAME, result);
278 dvb->fe_hw.source = DMX_FRONTEND_0;
279 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
281 printk(KERN_ERR "%s: add_frontend failed "
282 "(DMX_FRONTEND_0, errno = %d)\n", DRIVER_NAME, result);
286 dvb->fe_mem.source = DMX_MEMORY_FE;
287 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
289 printk(KERN_ERR "%s: add_frontend failed "
290 "(DMX_MEMORY_FE, errno = %d)\n", DRIVER_NAME, result);
294 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
296 printk(KERN_ERR "%s: connect_frontend failed (errno = %d)\n",
297 DRIVER_NAME, result);
301 /* register network adapter */
302 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
306 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
308 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
310 dvb_dmxdev_release(&dvb->dmxdev);
312 dvb_dmx_release(&dvb->demux);
314 dvb_unregister_frontend(dvb->frontend);
316 dvb_frontend_detach(dvb->frontend);
317 dvb_unregister_adapter(&dvb->adapter);
322 void au0828_dvb_unregister(struct au0828_dev *dev)
324 struct au0828_dvb *dvb = &dev->dvb;
326 dprintk(1, "%s()\n", __func__);
328 if (dvb->frontend == NULL)
331 dvb_net_release(&dvb->net);
332 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
333 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
334 dvb_dmxdev_release(&dvb->dmxdev);
335 dvb_dmx_release(&dvb->demux);
336 dvb_unregister_frontend(dvb->frontend);
337 dvb_frontend_detach(dvb->frontend);
338 dvb_unregister_adapter(&dvb->adapter);
341 /* All the DVB attach calls go here, this function get's modified
342 * for each new card. No other function in this file needs
345 int au0828_dvb_register(struct au0828_dev *dev)
347 struct au0828_dvb *dvb = &dev->dvb;
350 dprintk(1, "%s()\n", __func__);
353 switch (dev->board) {
354 case AU0828_BOARD_HAUPPAUGE_HVR850:
355 case AU0828_BOARD_HAUPPAUGE_HVR950Q:
356 case AU0828_BOARD_DVICO_FUSIONHDTV7:
357 dvb->frontend = dvb_attach(au8522_attach,
358 &hauppauge_hvr950q_config,
360 if (dvb->frontend != NULL)
361 dvb_attach(xc5000_attach, dvb->frontend,
363 &hauppauge_hvr950q_tunerconfig, dev);
365 case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
366 dvb->frontend = dvb_attach(au8522_attach,
367 &hauppauge_hvr950q_config,
369 if (dvb->frontend != NULL)
370 dvb_attach(mxl5007t_attach, dvb->frontend,
371 &dev->i2c_adap, 0x60,
372 &mxl5007t_hvr950q_config);
374 case AU0828_BOARD_HAUPPAUGE_WOODBURY:
375 dvb->frontend = dvb_attach(au8522_attach,
376 &hauppauge_woodbury_config,
378 if (dvb->frontend != NULL)
379 dvb_attach(tda18271_attach, dvb->frontend,
380 0x60, &dev->i2c_adap,
381 &hauppauge_woodbury_tunerconfig);
384 printk(KERN_WARNING "The frontend of your DVB/ATSC card "
385 "isn't supported yet\n");
388 if (NULL == dvb->frontend) {
389 printk(KERN_ERR "%s() Frontend initialization failed\n",
394 /* register everything */
395 ret = dvb_register(dev);
397 if (dvb->frontend->ops.release)
398 dvb->frontend->ops.release(dvb->frontend);