2 * Driver for the Auvitek USB bridge
4 * Copyright (c) 2008 Steven Toth <stoth@hauppauge.com>
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>
33 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
35 #define _AU0828_BULKPIPE 0x83
36 #define _BULKPIPESIZE 0xe522
38 static struct au8522_config hauppauge_hvr950q_config
= {
39 .demod_address
= 0x8e >> 1,
40 .status_mode
= AU8522_DEMODLOCKING
,
43 static struct xc5000_config hauppauge_hvr950q_tunerconfig
= {
46 .tuner_callback
= au0828_tuner_callback
49 static struct mxl5007t_config mxl5007t_hvr950q_config
= {
50 .xtal_freq_hz
= MxL_XTAL_24_MHZ
,
51 .if_freq_hz
= MxL_IF_6_MHZ
,
54 /*-------------------------------------------------------------------*/
55 static void urb_completion(struct urb
*purb
)
58 struct au0828_dev
*dev
= purb
->context
;
59 int ptype
= usb_pipetype(purb
->pipe
);
61 dprintk(2, "%s()\n", __func__
);
66 if (dev
->urb_streaming
== 0)
69 if (ptype
!= PIPE_BULK
) {
70 printk(KERN_ERR
"%s() Unsupported URB type %d\n",
75 ptr
= (u8
*)purb
->transfer_buffer
;
77 /* Feed the transport payload into the kernel demux */
78 dvb_dmx_swfilter_packets(&dev
->dvb
.demux
,
79 purb
->transfer_buffer
, purb
->actual_length
/ 188);
81 /* Clean the buffer before we requeue */
82 memset(purb
->transfer_buffer
, 0, URB_BUFSIZE
);
85 usb_submit_urb(purb
, GFP_ATOMIC
);
88 static int stop_urb_transfer(struct au0828_dev
*dev
)
92 dprintk(2, "%s()\n", __func__
);
94 for (i
= 0; i
< URB_COUNT
; i
++) {
95 usb_kill_urb(dev
->urbs
[i
]);
96 kfree(dev
->urbs
[i
]->transfer_buffer
);
97 usb_free_urb(dev
->urbs
[i
]);
100 dev
->urb_streaming
= 0;
105 static int start_urb_transfer(struct au0828_dev
*dev
)
108 int i
, ret
= -ENOMEM
;
110 dprintk(2, "%s()\n", __func__
);
112 if (dev
->urb_streaming
) {
113 dprintk(2, "%s: iso xfer already running!\n", __func__
);
117 for (i
= 0; i
< URB_COUNT
; i
++) {
119 dev
->urbs
[i
] = usb_alloc_urb(0, GFP_KERNEL
);
125 purb
->transfer_buffer
= kzalloc(URB_BUFSIZE
, GFP_KERNEL
);
126 if (!purb
->transfer_buffer
) {
132 purb
->status
= -EINPROGRESS
;
133 usb_fill_bulk_urb(purb
,
135 usb_rcvbulkpipe(dev
->usbdev
, _AU0828_BULKPIPE
),
136 purb
->transfer_buffer
,
143 for (i
= 0; i
< URB_COUNT
; i
++) {
144 ret
= usb_submit_urb(dev
->urbs
[i
], GFP_ATOMIC
);
146 stop_urb_transfer(dev
);
147 printk(KERN_ERR
"%s: failed urb submission, "
148 "err = %d\n", __func__
, ret
);
153 dev
->urb_streaming
= 1;
160 static int au0828_dvb_start_feed(struct dvb_demux_feed
*feed
)
162 struct dvb_demux
*demux
= feed
->demux
;
163 struct au0828_dev
*dev
= (struct au0828_dev
*) demux
->priv
;
164 struct au0828_dvb
*dvb
= &dev
->dvb
;
167 dprintk(1, "%s()\n", __func__
);
169 if (!demux
->dmx
.frontend
)
173 mutex_lock(&dvb
->lock
);
174 if (dvb
->feeding
++ == 0) {
175 /* Start transport */
176 au0828_write(dev
, 0x608, 0x90);
177 au0828_write(dev
, 0x609, 0x72);
178 au0828_write(dev
, 0x60a, 0x71);
179 au0828_write(dev
, 0x60b, 0x01);
180 ret
= start_urb_transfer(dev
);
182 mutex_unlock(&dvb
->lock
);
188 static int au0828_dvb_stop_feed(struct dvb_demux_feed
*feed
)
190 struct dvb_demux
*demux
= feed
->demux
;
191 struct au0828_dev
*dev
= (struct au0828_dev
*) demux
->priv
;
192 struct au0828_dvb
*dvb
= &dev
->dvb
;
195 dprintk(1, "%s()\n", __func__
);
198 mutex_lock(&dvb
->lock
);
199 if (--dvb
->feeding
== 0) {
201 au0828_write(dev
, 0x608, 0x00);
202 au0828_write(dev
, 0x609, 0x00);
203 au0828_write(dev
, 0x60a, 0x00);
204 au0828_write(dev
, 0x60b, 0x00);
205 ret
= stop_urb_transfer(dev
);
207 mutex_unlock(&dvb
->lock
);
213 static int dvb_register(struct au0828_dev
*dev
)
215 struct au0828_dvb
*dvb
= &dev
->dvb
;
218 dprintk(1, "%s()\n", __func__
);
220 /* register adapter */
221 result
= dvb_register_adapter(&dvb
->adapter
, DRIVER_NAME
, THIS_MODULE
,
222 &dev
->usbdev
->dev
, adapter_nr
);
224 printk(KERN_ERR
"%s: dvb_register_adapter failed "
225 "(errno = %d)\n", DRIVER_NAME
, result
);
228 dvb
->adapter
.priv
= dev
;
230 /* register frontend */
231 result
= dvb_register_frontend(&dvb
->adapter
, dvb
->frontend
);
233 printk(KERN_ERR
"%s: dvb_register_frontend failed "
234 "(errno = %d)\n", DRIVER_NAME
, result
);
238 /* register demux stuff */
239 dvb
->demux
.dmx
.capabilities
=
240 DMX_TS_FILTERING
| DMX_SECTION_FILTERING
|
241 DMX_MEMORY_BASED_FILTERING
;
242 dvb
->demux
.priv
= dev
;
243 dvb
->demux
.filternum
= 256;
244 dvb
->demux
.feednum
= 256;
245 dvb
->demux
.start_feed
= au0828_dvb_start_feed
;
246 dvb
->demux
.stop_feed
= au0828_dvb_stop_feed
;
247 result
= dvb_dmx_init(&dvb
->demux
);
249 printk(KERN_ERR
"%s: dvb_dmx_init failed (errno = %d)\n",
250 DRIVER_NAME
, result
);
254 dvb
->dmxdev
.filternum
= 256;
255 dvb
->dmxdev
.demux
= &dvb
->demux
.dmx
;
256 dvb
->dmxdev
.capabilities
= 0;
257 result
= dvb_dmxdev_init(&dvb
->dmxdev
, &dvb
->adapter
);
259 printk(KERN_ERR
"%s: dvb_dmxdev_init failed (errno = %d)\n",
260 DRIVER_NAME
, result
);
264 dvb
->fe_hw
.source
= DMX_FRONTEND_0
;
265 result
= dvb
->demux
.dmx
.add_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
267 printk(KERN_ERR
"%s: add_frontend failed "
268 "(DMX_FRONTEND_0, errno = %d)\n", DRIVER_NAME
, result
);
272 dvb
->fe_mem
.source
= DMX_MEMORY_FE
;
273 result
= dvb
->demux
.dmx
.add_frontend(&dvb
->demux
.dmx
, &dvb
->fe_mem
);
275 printk(KERN_ERR
"%s: add_frontend failed "
276 "(DMX_MEMORY_FE, errno = %d)\n", DRIVER_NAME
, result
);
280 result
= dvb
->demux
.dmx
.connect_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
282 printk(KERN_ERR
"%s: connect_frontend failed (errno = %d)\n",
283 DRIVER_NAME
, result
);
287 /* register network adapter */
288 dvb_net_init(&dvb
->adapter
, &dvb
->net
, &dvb
->demux
.dmx
);
292 dvb
->demux
.dmx
.remove_frontend(&dvb
->demux
.dmx
, &dvb
->fe_mem
);
294 dvb
->demux
.dmx
.remove_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
296 dvb_dmxdev_release(&dvb
->dmxdev
);
298 dvb_dmx_release(&dvb
->demux
);
300 dvb_unregister_frontend(dvb
->frontend
);
302 dvb_frontend_detach(dvb
->frontend
);
303 dvb_unregister_adapter(&dvb
->adapter
);
308 void au0828_dvb_unregister(struct au0828_dev
*dev
)
310 struct au0828_dvb
*dvb
= &dev
->dvb
;
312 dprintk(1, "%s()\n", __func__
);
314 if (dvb
->frontend
== NULL
)
317 dvb_net_release(&dvb
->net
);
318 dvb
->demux
.dmx
.remove_frontend(&dvb
->demux
.dmx
, &dvb
->fe_mem
);
319 dvb
->demux
.dmx
.remove_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
320 dvb_dmxdev_release(&dvb
->dmxdev
);
321 dvb_dmx_release(&dvb
->demux
);
322 dvb_unregister_frontend(dvb
->frontend
);
323 dvb_frontend_detach(dvb
->frontend
);
324 dvb_unregister_adapter(&dvb
->adapter
);
327 /* All the DVB attach calls go here, this function get's modified
328 * for each new card. No other function in this file needs
331 int au0828_dvb_register(struct au0828_dev
*dev
)
333 struct au0828_dvb
*dvb
= &dev
->dvb
;
336 dprintk(1, "%s()\n", __func__
);
339 switch (dev
->board
) {
340 case AU0828_BOARD_HAUPPAUGE_HVR850
:
341 case AU0828_BOARD_HAUPPAUGE_HVR950Q
:
342 case AU0828_BOARD_DVICO_FUSIONHDTV7
:
343 dvb
->frontend
= dvb_attach(au8522_attach
,
344 &hauppauge_hvr950q_config
,
346 if (dvb
->frontend
!= NULL
)
347 dvb_attach(xc5000_attach
, dvb
->frontend
,
349 &hauppauge_hvr950q_tunerconfig
, dev
);
351 case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL
:
352 dvb
->frontend
= dvb_attach(au8522_attach
,
353 &hauppauge_hvr950q_config
,
355 if (dvb
->frontend
!= NULL
)
356 dvb_attach(mxl5007t_attach
, dvb
->frontend
,
357 &dev
->i2c_adap
, 0x60,
358 &mxl5007t_hvr950q_config
);
361 printk(KERN_WARNING
"The frontend of your DVB/ATSC card "
362 "isn't supported yet\n");
365 if (NULL
== dvb
->frontend
) {
366 printk(KERN_ERR
"%s() Frontend initialization failed\n",
371 /* register everything */
372 ret
= dvb_register(dev
);
374 if (dvb
->frontend
->ops
.release
)
375 dvb
->frontend
->ops
.release(dvb
->frontend
);