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/init.h>
25 #include <linux/device.h>
26 #include <linux/suspend.h>
27 #include <media/v4l2-common.h>
35 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
37 #define _AU0828_BULKPIPE 0x83
38 #define _BULKPIPESIZE 0xe522
40 static u8 hauppauge_hvr950q_led_states
[] = {
46 static struct au8522_led_config hauppauge_hvr950q_led_cfg
= {
47 .gpio_output
= 0x00e0,
48 .gpio_output_enable
= 0x6006,
49 .gpio_output_disable
= 0x0660,
52 .led_states
= hauppauge_hvr950q_led_states
,
53 .num_led_states
= sizeof(hauppauge_hvr950q_led_states
),
55 .vsb8_strong
= 20 /* dB */ * 10,
56 .qam64_strong
= 25 /* dB */ * 10,
57 .qam256_strong
= 32 /* dB */ * 10,
60 static struct au8522_config hauppauge_hvr950q_config
= {
61 .demod_address
= 0x8e >> 1,
62 .status_mode
= AU8522_DEMODLOCKING
,
63 .qam_if
= AU8522_IF_6MHZ
,
64 .vsb_if
= AU8522_IF_6MHZ
,
65 .led_cfg
= &hauppauge_hvr950q_led_cfg
,
68 static struct au8522_config fusionhdtv7usb_config
= {
69 .demod_address
= 0x8e >> 1,
70 .status_mode
= AU8522_DEMODLOCKING
,
71 .qam_if
= AU8522_IF_6MHZ
,
72 .vsb_if
= AU8522_IF_6MHZ
,
75 static struct au8522_config hauppauge_woodbury_config
= {
76 .demod_address
= 0x8e >> 1,
77 .status_mode
= AU8522_DEMODLOCKING
,
78 .qam_if
= AU8522_IF_4MHZ
,
79 .vsb_if
= AU8522_IF_3_25MHZ
,
82 static struct xc5000_config hauppauge_hvr950q_tunerconfig
= {
87 static struct mxl5007t_config mxl5007t_hvr950q_config
= {
88 .xtal_freq_hz
= MxL_XTAL_24_MHZ
,
89 .if_freq_hz
= MxL_IF_6_MHZ
,
92 static struct tda18271_config hauppauge_woodbury_tunerconfig
= {
93 .gate
= TDA18271_GATE_DIGITAL
,
96 /*-------------------------------------------------------------------*/
97 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 /* Feed the transport payload into the kernel demux */
117 dvb_dmx_swfilter_packets(&dev
->dvb
.demux
,
118 purb
->transfer_buffer
, purb
->actual_length
/ 188);
120 /* Clean the buffer before we requeue */
121 memset(purb
->transfer_buffer
, 0, URB_BUFSIZE
);
124 usb_submit_urb(purb
, GFP_ATOMIC
);
127 static int stop_urb_transfer(struct au0828_dev
*dev
)
131 dprintk(2, "%s()\n", __func__
);
133 for (i
= 0; i
< URB_COUNT
; i
++) {
134 usb_kill_urb(dev
->urbs
[i
]);
135 kfree(dev
->urbs
[i
]->transfer_buffer
);
136 usb_free_urb(dev
->urbs
[i
]);
139 dev
->urb_streaming
= 0;
144 static int start_urb_transfer(struct au0828_dev
*dev
)
147 int i
, ret
= -ENOMEM
;
149 dprintk(2, "%s()\n", __func__
);
151 if (dev
->urb_streaming
) {
152 dprintk(2, "%s: bulk xfer already running!\n", __func__
);
156 for (i
= 0; i
< URB_COUNT
; i
++) {
158 dev
->urbs
[i
] = usb_alloc_urb(0, GFP_KERNEL
);
164 purb
->transfer_buffer
= kzalloc(URB_BUFSIZE
, GFP_KERNEL
);
165 if (!purb
->transfer_buffer
) {
171 purb
->status
= -EINPROGRESS
;
172 usb_fill_bulk_urb(purb
,
174 usb_rcvbulkpipe(dev
->usbdev
,
176 purb
->transfer_buffer
,
183 for (i
= 0; i
< URB_COUNT
; i
++) {
184 ret
= usb_submit_urb(dev
->urbs
[i
], GFP_ATOMIC
);
186 stop_urb_transfer(dev
);
187 printk(KERN_ERR
"%s: failed urb submission, "
188 "err = %d\n", __func__
, ret
);
193 dev
->urb_streaming
= 1;
200 static int au0828_dvb_start_feed(struct dvb_demux_feed
*feed
)
202 struct dvb_demux
*demux
= feed
->demux
;
203 struct au0828_dev
*dev
= (struct au0828_dev
*) demux
->priv
;
204 struct au0828_dvb
*dvb
= &dev
->dvb
;
207 dprintk(1, "%s()\n", __func__
);
209 if (!demux
->dmx
.frontend
)
213 mutex_lock(&dvb
->lock
);
214 if (dvb
->feeding
++ == 0) {
215 /* Start transport */
216 au0828_write(dev
, 0x608, 0x90);
217 au0828_write(dev
, 0x609, 0x72);
218 au0828_write(dev
, 0x60a, 0x71);
219 au0828_write(dev
, 0x60b, 0x01);
220 ret
= start_urb_transfer(dev
);
222 mutex_unlock(&dvb
->lock
);
228 static int au0828_dvb_stop_feed(struct dvb_demux_feed
*feed
)
230 struct dvb_demux
*demux
= feed
->demux
;
231 struct au0828_dev
*dev
= (struct au0828_dev
*) demux
->priv
;
232 struct au0828_dvb
*dvb
= &dev
->dvb
;
235 dprintk(1, "%s()\n", __func__
);
238 mutex_lock(&dvb
->lock
);
239 if (--dvb
->feeding
== 0) {
241 au0828_write(dev
, 0x608, 0x00);
242 au0828_write(dev
, 0x609, 0x00);
243 au0828_write(dev
, 0x60a, 0x00);
244 au0828_write(dev
, 0x60b, 0x00);
245 ret
= stop_urb_transfer(dev
);
247 mutex_unlock(&dvb
->lock
);
253 static int dvb_register(struct au0828_dev
*dev
)
255 struct au0828_dvb
*dvb
= &dev
->dvb
;
258 dprintk(1, "%s()\n", __func__
);
260 /* register adapter */
261 result
= dvb_register_adapter(&dvb
->adapter
, DRIVER_NAME
, THIS_MODULE
,
262 &dev
->usbdev
->dev
, adapter_nr
);
264 printk(KERN_ERR
"%s: dvb_register_adapter failed "
265 "(errno = %d)\n", DRIVER_NAME
, result
);
268 dvb
->adapter
.priv
= dev
;
270 /* register frontend */
271 result
= dvb_register_frontend(&dvb
->adapter
, dvb
->frontend
);
273 printk(KERN_ERR
"%s: dvb_register_frontend failed "
274 "(errno = %d)\n", DRIVER_NAME
, result
);
278 /* register demux stuff */
279 dvb
->demux
.dmx
.capabilities
=
280 DMX_TS_FILTERING
| DMX_SECTION_FILTERING
|
281 DMX_MEMORY_BASED_FILTERING
;
282 dvb
->demux
.priv
= dev
;
283 dvb
->demux
.filternum
= 256;
284 dvb
->demux
.feednum
= 256;
285 dvb
->demux
.start_feed
= au0828_dvb_start_feed
;
286 dvb
->demux
.stop_feed
= au0828_dvb_stop_feed
;
287 result
= dvb_dmx_init(&dvb
->demux
);
289 printk(KERN_ERR
"%s: dvb_dmx_init failed (errno = %d)\n",
290 DRIVER_NAME
, result
);
294 dvb
->dmxdev
.filternum
= 256;
295 dvb
->dmxdev
.demux
= &dvb
->demux
.dmx
;
296 dvb
->dmxdev
.capabilities
= 0;
297 result
= dvb_dmxdev_init(&dvb
->dmxdev
, &dvb
->adapter
);
299 printk(KERN_ERR
"%s: dvb_dmxdev_init failed (errno = %d)\n",
300 DRIVER_NAME
, result
);
304 dvb
->fe_hw
.source
= DMX_FRONTEND_0
;
305 result
= dvb
->demux
.dmx
.add_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
307 printk(KERN_ERR
"%s: add_frontend failed "
308 "(DMX_FRONTEND_0, errno = %d)\n", DRIVER_NAME
, result
);
312 dvb
->fe_mem
.source
= DMX_MEMORY_FE
;
313 result
= dvb
->demux
.dmx
.add_frontend(&dvb
->demux
.dmx
, &dvb
->fe_mem
);
315 printk(KERN_ERR
"%s: add_frontend failed "
316 "(DMX_MEMORY_FE, errno = %d)\n", DRIVER_NAME
, result
);
320 result
= dvb
->demux
.dmx
.connect_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
322 printk(KERN_ERR
"%s: connect_frontend failed (errno = %d)\n",
323 DRIVER_NAME
, result
);
327 /* register network adapter */
328 dvb_net_init(&dvb
->adapter
, &dvb
->net
, &dvb
->demux
.dmx
);
332 dvb
->demux
.dmx
.remove_frontend(&dvb
->demux
.dmx
, &dvb
->fe_mem
);
334 dvb
->demux
.dmx
.remove_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
336 dvb_dmxdev_release(&dvb
->dmxdev
);
338 dvb_dmx_release(&dvb
->demux
);
340 dvb_unregister_frontend(dvb
->frontend
);
342 dvb_frontend_detach(dvb
->frontend
);
343 dvb_unregister_adapter(&dvb
->adapter
);
348 void au0828_dvb_unregister(struct au0828_dev
*dev
)
350 struct au0828_dvb
*dvb
= &dev
->dvb
;
352 dprintk(1, "%s()\n", __func__
);
354 if (dvb
->frontend
== NULL
)
357 dvb_net_release(&dvb
->net
);
358 dvb
->demux
.dmx
.remove_frontend(&dvb
->demux
.dmx
, &dvb
->fe_mem
);
359 dvb
->demux
.dmx
.remove_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
360 dvb_dmxdev_release(&dvb
->dmxdev
);
361 dvb_dmx_release(&dvb
->demux
);
362 dvb_unregister_frontend(dvb
->frontend
);
363 dvb_frontend_detach(dvb
->frontend
);
364 dvb_unregister_adapter(&dvb
->adapter
);
367 /* All the DVB attach calls go here, this function get's modified
368 * for each new card. No other function in this file needs
371 int au0828_dvb_register(struct au0828_dev
*dev
)
373 struct au0828_dvb
*dvb
= &dev
->dvb
;
376 dprintk(1, "%s()\n", __func__
);
379 switch (dev
->boardnr
) {
380 case AU0828_BOARD_HAUPPAUGE_HVR850
:
381 case AU0828_BOARD_HAUPPAUGE_HVR950Q
:
382 dvb
->frontend
= dvb_attach(au8522_attach
,
383 &hauppauge_hvr950q_config
,
385 if (dvb
->frontend
!= NULL
)
386 dvb_attach(xc5000_attach
, dvb
->frontend
, &dev
->i2c_adap
,
387 &hauppauge_hvr950q_tunerconfig
);
389 case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL
:
390 dvb
->frontend
= dvb_attach(au8522_attach
,
391 &hauppauge_hvr950q_config
,
393 if (dvb
->frontend
!= NULL
)
394 dvb_attach(mxl5007t_attach
, dvb
->frontend
,
395 &dev
->i2c_adap
, 0x60,
396 &mxl5007t_hvr950q_config
);
398 case AU0828_BOARD_HAUPPAUGE_WOODBURY
:
399 dvb
->frontend
= dvb_attach(au8522_attach
,
400 &hauppauge_woodbury_config
,
402 if (dvb
->frontend
!= NULL
)
403 dvb_attach(tda18271_attach
, dvb
->frontend
,
404 0x60, &dev
->i2c_adap
,
405 &hauppauge_woodbury_tunerconfig
);
407 case AU0828_BOARD_DVICO_FUSIONHDTV7
:
408 dvb
->frontend
= dvb_attach(au8522_attach
,
409 &fusionhdtv7usb_config
,
411 if (dvb
->frontend
!= NULL
) {
412 dvb_attach(xc5000_attach
, dvb
->frontend
,
414 &hauppauge_hvr950q_tunerconfig
);
418 printk(KERN_WARNING
"The frontend of your DVB/ATSC card "
419 "isn't supported yet\n");
422 if (NULL
== dvb
->frontend
) {
423 printk(KERN_ERR
"%s() Frontend initialization failed\n",
427 /* define general-purpose callback pointer */
428 dvb
->frontend
->callback
= au0828_tuner_callback
;
430 /* register everything */
431 ret
= dvb_register(dev
);
433 if (dvb
->frontend
->ops
.release
)
434 dvb
->frontend
->ops
.release(dvb
->frontend
);