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 u8 hauppauge_hvr950q_led_states[] = {
45 static struct au8522_led_config hauppauge_hvr950q_led_cfg = {
46 .gpio_output = 0x00e0,
47 .gpio_output_enable = 0x6006,
48 .gpio_output_disable = 0x0660,
51 .led_states = hauppauge_hvr950q_led_states,
52 .num_led_states = sizeof(hauppauge_hvr950q_led_states),
54 .vsb8_strong = 20 /* dB */ * 10,
55 .qam64_strong = 25 /* dB */ * 10,
56 .qam256_strong = 32 /* dB */ * 10,
59 static struct au8522_config hauppauge_hvr950q_config = {
60 .demod_address = 0x8e >> 1,
61 .status_mode = AU8522_DEMODLOCKING,
62 .qam_if = AU8522_IF_6MHZ,
63 .vsb_if = AU8522_IF_6MHZ,
64 .led_cfg = &hauppauge_hvr950q_led_cfg,
67 static struct au8522_config fusionhdtv7usb_config = {
68 .demod_address = 0x8e >> 1,
69 .status_mode = AU8522_DEMODLOCKING,
70 .qam_if = AU8522_IF_6MHZ,
71 .vsb_if = AU8522_IF_6MHZ,
74 static struct au8522_config hauppauge_woodbury_config = {
75 .demod_address = 0x8e >> 1,
76 .status_mode = AU8522_DEMODLOCKING,
77 .qam_if = AU8522_IF_4MHZ,
78 .vsb_if = AU8522_IF_3_25MHZ,
81 static struct xc5000_config hauppauge_hvr950q_tunerconfig = {
86 static struct mxl5007t_config mxl5007t_hvr950q_config = {
87 .xtal_freq_hz = MxL_XTAL_24_MHZ,
88 .if_freq_hz = MxL_IF_6_MHZ,
91 static struct tda18271_config hauppauge_woodbury_tunerconfig = {
92 .gate = TDA18271_GATE_DIGITAL,
95 /*-------------------------------------------------------------------*/
96 static void urb_completion(struct urb *purb)
99 struct au0828_dev *dev = purb->context;
100 int ptype = usb_pipetype(purb->pipe);
102 dprintk(2, "%s()\n", __func__);
107 if (dev->urb_streaming == 0)
110 if (ptype != PIPE_BULK) {
111 printk(KERN_ERR "%s() Unsupported URB type %d\n",
116 ptr = (u8 *)purb->transfer_buffer;
118 /* Feed the transport payload into the kernel demux */
119 dvb_dmx_swfilter_packets(&dev->dvb.demux,
120 purb->transfer_buffer, purb->actual_length / 188);
122 /* Clean the buffer before we requeue */
123 memset(purb->transfer_buffer, 0, URB_BUFSIZE);
126 usb_submit_urb(purb, GFP_ATOMIC);
129 static int stop_urb_transfer(struct au0828_dev *dev)
133 dprintk(2, "%s()\n", __func__);
135 for (i = 0; i < URB_COUNT; i++) {
136 usb_kill_urb(dev->urbs[i]);
137 kfree(dev->urbs[i]->transfer_buffer);
138 usb_free_urb(dev->urbs[i]);
141 dev->urb_streaming = 0;
146 static int start_urb_transfer(struct au0828_dev *dev)
149 int i, ret = -ENOMEM;
151 dprintk(2, "%s()\n", __func__);
153 if (dev->urb_streaming) {
154 dprintk(2, "%s: iso xfer already running!\n", __func__);
158 for (i = 0; i < URB_COUNT; i++) {
160 dev->urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
166 purb->transfer_buffer = kzalloc(URB_BUFSIZE, GFP_KERNEL);
167 if (!purb->transfer_buffer) {
173 purb->status = -EINPROGRESS;
174 usb_fill_bulk_urb(purb,
176 usb_rcvbulkpipe(dev->usbdev, _AU0828_BULKPIPE),
177 purb->transfer_buffer,
184 for (i = 0; i < URB_COUNT; i++) {
185 ret = usb_submit_urb(dev->urbs[i], GFP_ATOMIC);
187 stop_urb_transfer(dev);
188 printk(KERN_ERR "%s: failed urb submission, "
189 "err = %d\n", __func__, ret);
194 dev->urb_streaming = 1;
201 static int au0828_dvb_start_feed(struct dvb_demux_feed *feed)
203 struct dvb_demux *demux = feed->demux;
204 struct au0828_dev *dev = (struct au0828_dev *) demux->priv;
205 struct au0828_dvb *dvb = &dev->dvb;
208 dprintk(1, "%s()\n", __func__);
210 if (!demux->dmx.frontend)
214 mutex_lock(&dvb->lock);
215 if (dvb->feeding++ == 0) {
216 /* Start transport */
217 au0828_write(dev, 0x608, 0x90);
218 au0828_write(dev, 0x609, 0x72);
219 au0828_write(dev, 0x60a, 0x71);
220 au0828_write(dev, 0x60b, 0x01);
221 ret = start_urb_transfer(dev);
223 mutex_unlock(&dvb->lock);
229 static int au0828_dvb_stop_feed(struct dvb_demux_feed *feed)
231 struct dvb_demux *demux = feed->demux;
232 struct au0828_dev *dev = (struct au0828_dev *) demux->priv;
233 struct au0828_dvb *dvb = &dev->dvb;
236 dprintk(1, "%s()\n", __func__);
239 mutex_lock(&dvb->lock);
240 if (--dvb->feeding == 0) {
242 au0828_write(dev, 0x608, 0x00);
243 au0828_write(dev, 0x609, 0x00);
244 au0828_write(dev, 0x60a, 0x00);
245 au0828_write(dev, 0x60b, 0x00);
246 ret = stop_urb_transfer(dev);
248 mutex_unlock(&dvb->lock);
254 static int dvb_register(struct au0828_dev *dev)
256 struct au0828_dvb *dvb = &dev->dvb;
259 dprintk(1, "%s()\n", __func__);
261 /* register adapter */
262 result = dvb_register_adapter(&dvb->adapter, DRIVER_NAME, THIS_MODULE,
263 &dev->usbdev->dev, adapter_nr);
265 printk(KERN_ERR "%s: dvb_register_adapter failed "
266 "(errno = %d)\n", DRIVER_NAME, result);
269 dvb->adapter.priv = dev;
271 /* register frontend */
272 result = dvb_register_frontend(&dvb->adapter, dvb->frontend);
274 printk(KERN_ERR "%s: dvb_register_frontend failed "
275 "(errno = %d)\n", DRIVER_NAME, result);
279 /* register demux stuff */
280 dvb->demux.dmx.capabilities =
281 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
282 DMX_MEMORY_BASED_FILTERING;
283 dvb->demux.priv = dev;
284 dvb->demux.filternum = 256;
285 dvb->demux.feednum = 256;
286 dvb->demux.start_feed = au0828_dvb_start_feed;
287 dvb->demux.stop_feed = au0828_dvb_stop_feed;
288 result = dvb_dmx_init(&dvb->demux);
290 printk(KERN_ERR "%s: dvb_dmx_init failed (errno = %d)\n",
291 DRIVER_NAME, result);
295 dvb->dmxdev.filternum = 256;
296 dvb->dmxdev.demux = &dvb->demux.dmx;
297 dvb->dmxdev.capabilities = 0;
298 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
300 printk(KERN_ERR "%s: dvb_dmxdev_init failed (errno = %d)\n",
301 DRIVER_NAME, result);
305 dvb->fe_hw.source = DMX_FRONTEND_0;
306 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
308 printk(KERN_ERR "%s: add_frontend failed "
309 "(DMX_FRONTEND_0, errno = %d)\n", DRIVER_NAME, result);
313 dvb->fe_mem.source = DMX_MEMORY_FE;
314 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
316 printk(KERN_ERR "%s: add_frontend failed "
317 "(DMX_MEMORY_FE, errno = %d)\n", DRIVER_NAME, result);
321 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
323 printk(KERN_ERR "%s: connect_frontend failed (errno = %d)\n",
324 DRIVER_NAME, result);
328 /* register network adapter */
329 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
333 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
335 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
337 dvb_dmxdev_release(&dvb->dmxdev);
339 dvb_dmx_release(&dvb->demux);
341 dvb_unregister_frontend(dvb->frontend);
343 dvb_frontend_detach(dvb->frontend);
344 dvb_unregister_adapter(&dvb->adapter);
349 void au0828_dvb_unregister(struct au0828_dev *dev)
351 struct au0828_dvb *dvb = &dev->dvb;
353 dprintk(1, "%s()\n", __func__);
355 if (dvb->frontend == NULL)
358 dvb_net_release(&dvb->net);
359 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
360 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
361 dvb_dmxdev_release(&dvb->dmxdev);
362 dvb_dmx_release(&dvb->demux);
363 dvb_unregister_frontend(dvb->frontend);
364 dvb_frontend_detach(dvb->frontend);
365 dvb_unregister_adapter(&dvb->adapter);
368 /* All the DVB attach calls go here, this function get's modified
369 * for each new card. No other function in this file needs
372 int au0828_dvb_register(struct au0828_dev *dev)
374 struct au0828_dvb *dvb = &dev->dvb;
377 dprintk(1, "%s()\n", __func__);
380 switch (dev->board) {
381 case AU0828_BOARD_HAUPPAUGE_HVR850:
382 case AU0828_BOARD_HAUPPAUGE_HVR950Q:
383 dvb->frontend = dvb_attach(au8522_attach,
384 &hauppauge_hvr950q_config,
386 if (dvb->frontend != NULL)
387 dvb_attach(xc5000_attach, dvb->frontend, &dev->i2c_adap,
388 &hauppauge_hvr950q_tunerconfig);
390 case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
391 dvb->frontend = dvb_attach(au8522_attach,
392 &hauppauge_hvr950q_config,
394 if (dvb->frontend != NULL)
395 dvb_attach(mxl5007t_attach, dvb->frontend,
396 &dev->i2c_adap, 0x60,
397 &mxl5007t_hvr950q_config);
399 case AU0828_BOARD_HAUPPAUGE_WOODBURY:
400 dvb->frontend = dvb_attach(au8522_attach,
401 &hauppauge_woodbury_config,
403 if (dvb->frontend != NULL)
404 dvb_attach(tda18271_attach, dvb->frontend,
405 0x60, &dev->i2c_adap,
406 &hauppauge_woodbury_tunerconfig);
408 case AU0828_BOARD_DVICO_FUSIONHDTV7:
409 dvb->frontend = dvb_attach(au8522_attach,
410 &fusionhdtv7usb_config,
412 if (dvb->frontend != NULL) {
413 dvb_attach(xc5000_attach, dvb->frontend,
415 &hauppauge_hvr950q_tunerconfig);
419 printk(KERN_WARNING "The frontend of your DVB/ATSC card "
420 "isn't supported yet\n");
423 if (NULL == dvb->frontend) {
424 printk(KERN_ERR "%s() Frontend initialization failed\n",
428 /* define general-purpose callback pointer */
429 dvb->frontend->callback = au0828_tuner_callback;
431 /* register everything */
432 ret = dvb_register(dev);
434 if (dvb->frontend->ops.release)
435 dvb->frontend->ops.release(dvb->frontend);