Blame view
drivers/media/video/au0828/au0828-dvb.c
10.9 KB
265a65106 V4L/DVB (7621): A... |
1 2 3 |
/* * Driver for the Auvitek USB bridge * |
6d8976164 V4L/DVB (8805): S... |
4 |
* Copyright (c) 2008 Steven Toth <stoth@linuxtv.org> |
265a65106 V4L/DVB (7621): A... |
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include <linux/module.h> #include <linux/init.h> #include <linux/device.h> #include <linux/suspend.h> #include <media/v4l2-common.h> #include "au0828.h" |
265a65106 V4L/DVB (7621): A... |
29 30 |
#include "au8522.h" #include "xc5000.h" |
59d27521c V4L/DVB (8530): a... |
31 |
#include "mxl5007t.h" |
8e8bd229e V4L/DVB (8556): a... |
32 |
#include "tda18271.h" |
265a65106 V4L/DVB (7621): A... |
33 34 |
DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
a9c36aad5 V4L/DVB (7634): a... |
35 36 |
#define _AU0828_BULKPIPE 0x83 #define _BULKPIPESIZE 0xe522 |
adeeac3b7 V4L/DVB (9149): h... |
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
static u8 hauppauge_hvr950q_led_states[] = { 0x00, /* off */ 0x02, /* yellow */ 0x04, /* green */ }; static struct au8522_led_config hauppauge_hvr950q_led_cfg = { .gpio_output = 0x00e0, .gpio_output_enable = 0x6006, .gpio_output_disable = 0x0660, .gpio_leds = 0x00e2, .led_states = hauppauge_hvr950q_led_states, .num_led_states = sizeof(hauppauge_hvr950q_led_states), .vsb8_strong = 20 /* dB */ * 10, .qam64_strong = 25 /* dB */ * 10, .qam256_strong = 32 /* dB */ * 10, }; |
265a65106 V4L/DVB (7621): A... |
56 57 58 |
static struct au8522_config hauppauge_hvr950q_config = { .demod_address = 0x8e >> 1, .status_mode = AU8522_DEMODLOCKING, |
e908b6e34 V4L/DVB (8600): a... |
59 60 |
.qam_if = AU8522_IF_6MHZ, .vsb_if = AU8522_IF_6MHZ, |
adeeac3b7 V4L/DVB (9149): h... |
61 62 63 64 65 66 67 68 |
.led_cfg = &hauppauge_hvr950q_led_cfg, }; static struct au8522_config fusionhdtv7usb_config = { .demod_address = 0x8e >> 1, .status_mode = AU8522_DEMODLOCKING, .qam_if = AU8522_IF_6MHZ, .vsb_if = AU8522_IF_6MHZ, |
265a65106 V4L/DVB (7621): A... |
69 |
}; |
8e8bd229e V4L/DVB (8556): a... |
70 71 72 73 74 75 |
static struct au8522_config hauppauge_woodbury_config = { .demod_address = 0x8e >> 1, .status_mode = AU8522_DEMODLOCKING, .qam_if = AU8522_IF_4MHZ, .vsb_if = AU8522_IF_3_25MHZ, }; |
265a65106 V4L/DVB (7621): A... |
76 77 78 |
static struct xc5000_config hauppauge_hvr950q_tunerconfig = { .i2c_address = 0x61, .if_khz = 6000, |
265a65106 V4L/DVB (7621): A... |
79 |
}; |
59d27521c V4L/DVB (8530): a... |
80 81 82 83 |
static struct mxl5007t_config mxl5007t_hvr950q_config = { .xtal_freq_hz = MxL_XTAL_24_MHZ, .if_freq_hz = MxL_IF_6_MHZ, }; |
8e8bd229e V4L/DVB (8556): a... |
84 85 86 |
static struct tda18271_config hauppauge_woodbury_tunerconfig = { .gate = TDA18271_GATE_DIGITAL, }; |
265a65106 V4L/DVB (7621): A... |
87 88 89 90 91 92 |
/*-------------------------------------------------------------------*/ static void urb_completion(struct urb *purb) { u8 *ptr; struct au0828_dev *dev = purb->context; int ptype = usb_pipetype(purb->pipe); |
f07e8e4bb V4L/DVB (7627): a... |
93 94 |
dprintk(2, "%s() ", __func__); |
bc3c613ce V4L/DVB (7625): a... |
95 |
|
9c26de555 V4L/DVB (7624): A... |
96 97 |
if (!dev) return; |
265a65106 V4L/DVB (7621): A... |
98 99 100 101 |
if (dev->urb_streaming == 0) return; if (ptype != PIPE_BULK) { |
f07e8e4bb V4L/DVB (7627): a... |
102 103 104 |
printk(KERN_ERR "%s() Unsupported URB type %d ", __func__, ptype); |
265a65106 V4L/DVB (7621): A... |
105 106 107 108 109 110 |
return; } ptr = (u8 *)purb->transfer_buffer; /* Feed the transport payload into the kernel demux */ |
a9c36aad5 V4L/DVB (7634): a... |
111 112 |
dvb_dmx_swfilter_packets(&dev->dvb.demux, purb->transfer_buffer, purb->actual_length / 188); |
265a65106 V4L/DVB (7621): A... |
113 114 115 116 117 118 119 120 121 122 123 |
/* Clean the buffer before we requeue */ memset(purb->transfer_buffer, 0, URB_BUFSIZE); /* Requeue URB */ usb_submit_urb(purb, GFP_ATOMIC); } static int stop_urb_transfer(struct au0828_dev *dev) { int i; |
f07e8e4bb V4L/DVB (7627): a... |
124 125 |
dprintk(2, "%s() ", __func__); |
265a65106 V4L/DVB (7621): A... |
126 |
|
265a65106 V4L/DVB (7621): A... |
127 128 129 130 131 132 133 134 135 136 |
for (i = 0; i < URB_COUNT; i++) { usb_kill_urb(dev->urbs[i]); kfree(dev->urbs[i]->transfer_buffer); usb_free_urb(dev->urbs[i]); } dev->urb_streaming = 0; return 0; } |
265a65106 V4L/DVB (7621): A... |
137 138 139 140 |
static int start_urb_transfer(struct au0828_dev *dev) { struct urb *purb; int i, ret = -ENOMEM; |
265a65106 V4L/DVB (7621): A... |
141 |
|
f07e8e4bb V4L/DVB (7627): a... |
142 143 |
dprintk(2, "%s() ", __func__); |
265a65106 V4L/DVB (7621): A... |
144 145 |
if (dev->urb_streaming) { |
f07e8e4bb V4L/DVB (7627): a... |
146 147 |
dprintk(2, "%s: iso xfer already running! ", __func__); |
265a65106 V4L/DVB (7621): A... |
148 149 150 151 152 153 |
return 0; } for (i = 0; i < URB_COUNT; i++) { dev->urbs[i] = usb_alloc_urb(0, GFP_KERNEL); |
18d73c58b V4L/DVB (7638): C... |
154 |
if (!dev->urbs[i]) |
265a65106 V4L/DVB (7621): A... |
155 |
goto err; |
265a65106 V4L/DVB (7621): A... |
156 157 158 159 160 161 |
purb = dev->urbs[i]; purb->transfer_buffer = kzalloc(URB_BUFSIZE, GFP_KERNEL); if (!purb->transfer_buffer) { usb_free_urb(purb); |
a6a3a17b7 media: fix intege... |
162 |
dev->urbs[i] = NULL; |
265a65106 V4L/DVB (7621): A... |
163 164 165 166 167 168 |
goto err; } purb->status = -EINPROGRESS; usb_fill_bulk_urb(purb, dev->usbdev, |
a8eb912c6 V4L/DVB (9252): a... |
169 170 |
usb_rcvbulkpipe(dev->usbdev, _AU0828_BULKPIPE), |
265a65106 V4L/DVB (7621): A... |
171 172 173 174 175 176 177 178 179 180 181 |
purb->transfer_buffer, URB_BUFSIZE, urb_completion, dev); } for (i = 0; i < URB_COUNT; i++) { ret = usb_submit_urb(dev->urbs[i], GFP_ATOMIC); if (ret != 0) { stop_urb_transfer(dev); |
f07e8e4bb V4L/DVB (7627): a... |
182 183 184 |
printk(KERN_ERR "%s: failed urb submission, " "err = %d ", __func__, ret); |
265a65106 V4L/DVB (7621): A... |
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 |
return ret; } } dev->urb_streaming = 1; ret = 0; err: return ret; } static int au0828_dvb_start_feed(struct dvb_demux_feed *feed) { struct dvb_demux *demux = feed->demux; struct au0828_dev *dev = (struct au0828_dev *) demux->priv; struct au0828_dvb *dvb = &dev->dvb; int ret = 0; |
f07e8e4bb V4L/DVB (7627): a... |
202 203 |
dprintk(1, "%s() ", __func__); |
265a65106 V4L/DVB (7621): A... |
204 205 206 |
if (!demux->dmx.frontend) return -EINVAL; |
265a65106 V4L/DVB (7621): A... |
207 208 209 |
if (dvb) { mutex_lock(&dvb->lock); if (dvb->feeding++ == 0) { |
bc3c613ce V4L/DVB (7625): a... |
210 |
/* Start transport */ |
265a65106 V4L/DVB (7621): A... |
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
au0828_write(dev, 0x608, 0x90); au0828_write(dev, 0x609, 0x72); au0828_write(dev, 0x60a, 0x71); au0828_write(dev, 0x60b, 0x01); ret = start_urb_transfer(dev); } mutex_unlock(&dvb->lock); } return ret; } static int au0828_dvb_stop_feed(struct dvb_demux_feed *feed) { struct dvb_demux *demux = feed->demux; struct au0828_dev *dev = (struct au0828_dev *) demux->priv; struct au0828_dvb *dvb = &dev->dvb; int ret = 0; |
f07e8e4bb V4L/DVB (7627): a... |
229 230 |
dprintk(1, "%s() ", __func__); |
265a65106 V4L/DVB (7621): A... |
231 232 233 234 |
if (dvb) { mutex_lock(&dvb->lock); if (--dvb->feeding == 0) { |
bc3c613ce V4L/DVB (7625): a... |
235 |
/* Stop transport */ |
265a65106 V4L/DVB (7621): A... |
236 237 238 239 240 241 242 243 244 245 246 |
au0828_write(dev, 0x608, 0x00); au0828_write(dev, 0x609, 0x00); au0828_write(dev, 0x60a, 0x00); au0828_write(dev, 0x60b, 0x00); ret = stop_urb_transfer(dev); } mutex_unlock(&dvb->lock); } return ret; } |
b33d24c4c V4L/DVB (7750): a... |
247 |
static int dvb_register(struct au0828_dev *dev) |
265a65106 V4L/DVB (7621): A... |
248 249 250 |
{ struct au0828_dvb *dvb = &dev->dvb; int result; |
f07e8e4bb V4L/DVB (7627): a... |
251 252 |
dprintk(1, "%s() ", __func__); |
bc3c613ce V4L/DVB (7625): a... |
253 |
|
265a65106 V4L/DVB (7621): A... |
254 255 256 257 |
/* register adapter */ result = dvb_register_adapter(&dvb->adapter, DRIVER_NAME, THIS_MODULE, &dev->usbdev->dev, adapter_nr); if (result < 0) { |
f07e8e4bb V4L/DVB (7627): a... |
258 259 260 |
printk(KERN_ERR "%s: dvb_register_adapter failed " "(errno = %d) ", DRIVER_NAME, result); |
265a65106 V4L/DVB (7621): A... |
261 262 263 264 265 266 267 |
goto fail_adapter; } dvb->adapter.priv = dev; /* register frontend */ result = dvb_register_frontend(&dvb->adapter, dvb->frontend); if (result < 0) { |
f07e8e4bb V4L/DVB (7627): a... |
268 269 270 |
printk(KERN_ERR "%s: dvb_register_frontend failed " "(errno = %d) ", DRIVER_NAME, result); |
265a65106 V4L/DVB (7621): A... |
271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
goto fail_frontend; } /* register demux stuff */ dvb->demux.dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING; dvb->demux.priv = dev; dvb->demux.filternum = 256; dvb->demux.feednum = 256; dvb->demux.start_feed = au0828_dvb_start_feed; dvb->demux.stop_feed = au0828_dvb_stop_feed; result = dvb_dmx_init(&dvb->demux); if (result < 0) { |
bc3c613ce V4L/DVB (7625): a... |
285 286 |
printk(KERN_ERR "%s: dvb_dmx_init failed (errno = %d) ", |
265a65106 V4L/DVB (7621): A... |
287 288 289 290 291 292 293 294 295 |
DRIVER_NAME, result); goto fail_dmx; } dvb->dmxdev.filternum = 256; dvb->dmxdev.demux = &dvb->demux.dmx; dvb->dmxdev.capabilities = 0; result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter); if (result < 0) { |
bc3c613ce V4L/DVB (7625): a... |
296 297 |
printk(KERN_ERR "%s: dvb_dmxdev_init failed (errno = %d) ", |
265a65106 V4L/DVB (7621): A... |
298 299 300 301 302 303 304 |
DRIVER_NAME, result); goto fail_dmxdev; } dvb->fe_hw.source = DMX_FRONTEND_0; result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw); if (result < 0) { |
f07e8e4bb V4L/DVB (7627): a... |
305 306 307 |
printk(KERN_ERR "%s: add_frontend failed " "(DMX_FRONTEND_0, errno = %d) ", DRIVER_NAME, result); |
265a65106 V4L/DVB (7621): A... |
308 309 310 311 312 313 |
goto fail_fe_hw; } dvb->fe_mem.source = DMX_MEMORY_FE; result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem); if (result < 0) { |
f07e8e4bb V4L/DVB (7627): a... |
314 315 316 |
printk(KERN_ERR "%s: add_frontend failed " "(DMX_MEMORY_FE, errno = %d) ", DRIVER_NAME, result); |
265a65106 V4L/DVB (7621): A... |
317 318 319 320 321 |
goto fail_fe_mem; } result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw); if (result < 0) { |
bc3c613ce V4L/DVB (7625): a... |
322 323 |
printk(KERN_ERR "%s: connect_frontend failed (errno = %d) ", |
265a65106 V4L/DVB (7621): A... |
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
DRIVER_NAME, result); goto fail_fe_conn; } /* register network adapter */ dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx); return 0; fail_fe_conn: dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); fail_fe_mem: dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); fail_fe_hw: dvb_dmxdev_release(&dvb->dmxdev); fail_dmxdev: dvb_dmx_release(&dvb->demux); fail_dmx: dvb_unregister_frontend(dvb->frontend); fail_frontend: dvb_frontend_detach(dvb->frontend); dvb_unregister_adapter(&dvb->adapter); fail_adapter: return result; } void au0828_dvb_unregister(struct au0828_dev *dev) { struct au0828_dvb *dvb = &dev->dvb; |
f07e8e4bb V4L/DVB (7627): a... |
352 353 |
dprintk(1, "%s() ", __func__); |
bc3c613ce V4L/DVB (7625): a... |
354 |
|
a9c36aad5 V4L/DVB (7634): a... |
355 |
if (dvb->frontend == NULL) |
9c26de555 V4L/DVB (7624): A... |
356 |
return; |
265a65106 V4L/DVB (7621): A... |
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
dvb_net_release(&dvb->net); dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); dvb_dmxdev_release(&dvb->dmxdev); dvb_dmx_release(&dvb->demux); dvb_unregister_frontend(dvb->frontend); dvb_frontend_detach(dvb->frontend); dvb_unregister_adapter(&dvb->adapter); } /* All the DVB attach calls go here, this function get's modified * for each new card. No other function in this file needs * to change. */ int au0828_dvb_register(struct au0828_dev *dev) { struct au0828_dvb *dvb = &dev->dvb; int ret; |
f07e8e4bb V4L/DVB (7627): a... |
375 376 |
dprintk(1, "%s() ", __func__); |
bc3c613ce V4L/DVB (7625): a... |
377 |
|
265a65106 V4L/DVB (7621): A... |
378 379 380 381 |
/* init frontend */ switch (dev->board) { case AU0828_BOARD_HAUPPAUGE_HVR850: case AU0828_BOARD_HAUPPAUGE_HVR950Q: |
265a65106 V4L/DVB (7621): A... |
382 383 384 |
dvb->frontend = dvb_attach(au8522_attach, &hauppauge_hvr950q_config, &dev->i2c_adap); |
48723543a V4L/DVB (7893): x... |
385 |
if (dvb->frontend != NULL) |
306509619 V4L/DVB (8951): x... |
386 387 |
dvb_attach(xc5000_attach, dvb->frontend, &dev->i2c_adap, &hauppauge_hvr950q_tunerconfig); |
265a65106 V4L/DVB (7621): A... |
388 |
break; |
59d27521c V4L/DVB (8530): a... |
389 390 391 392 393 394 395 396 397 |
case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL: dvb->frontend = dvb_attach(au8522_attach, &hauppauge_hvr950q_config, &dev->i2c_adap); if (dvb->frontend != NULL) dvb_attach(mxl5007t_attach, dvb->frontend, &dev->i2c_adap, 0x60, &mxl5007t_hvr950q_config); break; |
8e8bd229e V4L/DVB (8556): a... |
398 399 400 401 402 403 404 405 406 |
case AU0828_BOARD_HAUPPAUGE_WOODBURY: dvb->frontend = dvb_attach(au8522_attach, &hauppauge_woodbury_config, &dev->i2c_adap); if (dvb->frontend != NULL) dvb_attach(tda18271_attach, dvb->frontend, 0x60, &dev->i2c_adap, &hauppauge_woodbury_tunerconfig); break; |
adeeac3b7 V4L/DVB (9149): h... |
407 408 409 410 411 412 413 414 415 416 |
case AU0828_BOARD_DVICO_FUSIONHDTV7: dvb->frontend = dvb_attach(au8522_attach, &fusionhdtv7usb_config, &dev->i2c_adap); if (dvb->frontend != NULL) { dvb_attach(xc5000_attach, dvb->frontend, &dev->i2c_adap, &hauppauge_hvr950q_tunerconfig); } break; |
265a65106 V4L/DVB (7621): A... |
417 |
default: |
f07e8e4bb V4L/DVB (7627): a... |
418 419 420 |
printk(KERN_WARNING "The frontend of your DVB/ATSC card " "isn't supported yet "); |
265a65106 V4L/DVB (7621): A... |
421 422 423 |
break; } if (NULL == dvb->frontend) { |
f07e8e4bb V4L/DVB (7627): a... |
424 425 426 |
printk(KERN_ERR "%s() Frontend initialization failed ", __func__); |
265a65106 V4L/DVB (7621): A... |
427 428 |
return -1; } |
d7cba043d V4L/DVB (9049): c... |
429 430 |
/* define general-purpose callback pointer */ dvb->frontend->callback = au0828_tuner_callback; |
265a65106 V4L/DVB (7621): A... |
431 |
|
265a65106 V4L/DVB (7621): A... |
432 433 434 435 436 437 438 439 440 441 |
/* register everything */ ret = dvb_register(dev); if (ret < 0) { if (dvb->frontend->ops.release) dvb->frontend->ops.release(dvb->frontend); return ret; } return 0; } |