Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 1 | /* |
| 2 | * Driver for the Auvitek USB bridge |
| 3 | * |
Steven Toth | 6d89761 | 2008-09-03 17:12:12 -0300 | [diff] [blame] | 4 | * Copyright (c) 2008 Steven Toth <stoth@linuxtv.org> |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 5 | * |
| 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. |
| 10 | * |
| 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 |
| 14 | * |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 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. |
| 20 | */ |
| 21 | |
| 22 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 23 | #include <linux/slab.h> |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 24 | #include <linux/init.h> |
| 25 | #include <linux/device.h> |
| 26 | #include <linux/suspend.h> |
| 27 | #include <media/v4l2-common.h> |
Michael Krufky | be183dc | 2012-04-08 21:39:56 -0300 | [diff] [blame] | 28 | #include <media/tuner.h> |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 29 | |
| 30 | #include "au0828.h" |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 31 | #include "au8522.h" |
| 32 | #include "xc5000.h" |
Michael Krufky | 59d2752 | 2008-07-09 00:23:08 -0300 | [diff] [blame] | 33 | #include "mxl5007t.h" |
Michael Krufky | 8e8bd22 | 2008-09-03 16:46:36 -0300 | [diff] [blame] | 34 | #include "tda18271.h" |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 35 | |
| 36 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 37 | |
Steven Toth | a9c36aa | 2008-04-17 21:41:28 -0300 | [diff] [blame] | 38 | #define _AU0828_BULKPIPE 0x83 |
| 39 | #define _BULKPIPESIZE 0xe522 |
| 40 | |
Michael Krufky | adeeac3 | 2008-04-05 20:55:14 -0300 | [diff] [blame] | 41 | static u8 hauppauge_hvr950q_led_states[] = { |
| 42 | 0x00, /* off */ |
| 43 | 0x02, /* yellow */ |
| 44 | 0x04, /* green */ |
| 45 | }; |
| 46 | |
| 47 | static struct au8522_led_config hauppauge_hvr950q_led_cfg = { |
| 48 | .gpio_output = 0x00e0, |
| 49 | .gpio_output_enable = 0x6006, |
| 50 | .gpio_output_disable = 0x0660, |
| 51 | |
| 52 | .gpio_leds = 0x00e2, |
| 53 | .led_states = hauppauge_hvr950q_led_states, |
| 54 | .num_led_states = sizeof(hauppauge_hvr950q_led_states), |
| 55 | |
| 56 | .vsb8_strong = 20 /* dB */ * 10, |
| 57 | .qam64_strong = 25 /* dB */ * 10, |
| 58 | .qam256_strong = 32 /* dB */ * 10, |
| 59 | }; |
| 60 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 61 | static struct au8522_config hauppauge_hvr950q_config = { |
| 62 | .demod_address = 0x8e >> 1, |
| 63 | .status_mode = AU8522_DEMODLOCKING, |
Michael Krufky | e908b6e | 2008-09-03 16:46:43 -0300 | [diff] [blame] | 64 | .qam_if = AU8522_IF_6MHZ, |
| 65 | .vsb_if = AU8522_IF_6MHZ, |
Michael Krufky | adeeac3 | 2008-04-05 20:55:14 -0300 | [diff] [blame] | 66 | .led_cfg = &hauppauge_hvr950q_led_cfg, |
| 67 | }; |
| 68 | |
| 69 | static struct au8522_config fusionhdtv7usb_config = { |
| 70 | .demod_address = 0x8e >> 1, |
| 71 | .status_mode = AU8522_DEMODLOCKING, |
| 72 | .qam_if = AU8522_IF_6MHZ, |
| 73 | .vsb_if = AU8522_IF_6MHZ, |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 74 | }; |
| 75 | |
Michael Krufky | 8e8bd22 | 2008-09-03 16:46:36 -0300 | [diff] [blame] | 76 | static struct au8522_config hauppauge_woodbury_config = { |
| 77 | .demod_address = 0x8e >> 1, |
| 78 | .status_mode = AU8522_DEMODLOCKING, |
| 79 | .qam_if = AU8522_IF_4MHZ, |
| 80 | .vsb_if = AU8522_IF_3_25MHZ, |
| 81 | }; |
| 82 | |
Michael Krufky | be183dc | 2012-04-08 21:39:56 -0300 | [diff] [blame] | 83 | static struct xc5000_config hauppauge_xc5000a_config = { |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 84 | .i2c_address = 0x61, |
| 85 | .if_khz = 6000, |
Michael Krufky | be183dc | 2012-04-08 21:39:56 -0300 | [diff] [blame] | 86 | .chip_id = XC5000A, |
| 87 | }; |
| 88 | |
| 89 | static struct xc5000_config hauppauge_xc5000c_config = { |
| 90 | .i2c_address = 0x61, |
| 91 | .if_khz = 6000, |
| 92 | .chip_id = XC5000C, |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 93 | }; |
| 94 | |
Michael Krufky | 59d2752 | 2008-07-09 00:23:08 -0300 | [diff] [blame] | 95 | static struct mxl5007t_config mxl5007t_hvr950q_config = { |
| 96 | .xtal_freq_hz = MxL_XTAL_24_MHZ, |
| 97 | .if_freq_hz = MxL_IF_6_MHZ, |
| 98 | }; |
| 99 | |
Michael Krufky | 8e8bd22 | 2008-09-03 16:46:36 -0300 | [diff] [blame] | 100 | static struct tda18271_config hauppauge_woodbury_tunerconfig = { |
| 101 | .gate = TDA18271_GATE_DIGITAL, |
| 102 | }; |
| 103 | |
Devin Heitmueller | 43f2ccc | 2012-08-06 22:46:53 -0300 | [diff] [blame] | 104 | static void au0828_restart_dvb_streaming(struct work_struct *work); |
| 105 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 106 | /*-------------------------------------------------------------------*/ |
| 107 | static void urb_completion(struct urb *purb) |
| 108 | { |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 109 | struct au0828_dev *dev = purb->context; |
| 110 | int ptype = usb_pipetype(purb->pipe); |
Devin Heitmueller | 43f2ccc | 2012-08-06 22:46:53 -0300 | [diff] [blame] | 111 | unsigned char *ptr; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 112 | |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 113 | dprintk(2, "%s()\n", __func__); |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 114 | |
Steven Toth | 9c26de55 | 2008-04-02 01:10:40 -0300 | [diff] [blame] | 115 | if (!dev) |
| 116 | return; |
| 117 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 118 | if (dev->urb_streaming == 0) |
| 119 | return; |
| 120 | |
| 121 | if (ptype != PIPE_BULK) { |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 122 | printk(KERN_ERR "%s() Unsupported URB type %d\n", |
| 123 | __func__, ptype); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 124 | return; |
| 125 | } |
| 126 | |
Devin Heitmueller | 43f2ccc | 2012-08-06 22:46:53 -0300 | [diff] [blame] | 127 | /* See if the stream is corrupted (to work around a hardware |
| 128 | bug where the stream gets misaligned */ |
| 129 | ptr = purb->transfer_buffer; |
| 130 | if (purb->actual_length > 0 && ptr[0] != 0x47) { |
| 131 | dprintk(1, "Need to restart streaming %02x len=%d!\n", |
| 132 | ptr[0], purb->actual_length); |
| 133 | schedule_work(&dev->restart_streaming); |
| 134 | return; |
| 135 | } |
| 136 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 137 | /* Feed the transport payload into the kernel demux */ |
Steven Toth | a9c36aa | 2008-04-17 21:41:28 -0300 | [diff] [blame] | 138 | dvb_dmx_swfilter_packets(&dev->dvb.demux, |
| 139 | purb->transfer_buffer, purb->actual_length / 188); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 140 | |
| 141 | /* Clean the buffer before we requeue */ |
| 142 | memset(purb->transfer_buffer, 0, URB_BUFSIZE); |
| 143 | |
| 144 | /* Requeue URB */ |
| 145 | usb_submit_urb(purb, GFP_ATOMIC); |
| 146 | } |
| 147 | |
| 148 | static int stop_urb_transfer(struct au0828_dev *dev) |
| 149 | { |
| 150 | int i; |
| 151 | |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 152 | dprintk(2, "%s()\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 153 | |
Devin Heitmueller | 43f2ccc | 2012-08-06 22:46:53 -0300 | [diff] [blame] | 154 | dev->urb_streaming = 0; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 155 | for (i = 0; i < URB_COUNT; i++) { |
| 156 | usb_kill_urb(dev->urbs[i]); |
| 157 | kfree(dev->urbs[i]->transfer_buffer); |
| 158 | usb_free_urb(dev->urbs[i]); |
| 159 | } |
| 160 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 161 | return 0; |
| 162 | } |
| 163 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 164 | static int start_urb_transfer(struct au0828_dev *dev) |
| 165 | { |
| 166 | struct urb *purb; |
| 167 | int i, ret = -ENOMEM; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 168 | |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 169 | dprintk(2, "%s()\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 170 | |
| 171 | if (dev->urb_streaming) { |
Michael Krufky | 5376176 | 2009-07-27 17:35:59 -0300 | [diff] [blame] | 172 | dprintk(2, "%s: bulk xfer already running!\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | for (i = 0; i < URB_COUNT; i++) { |
| 177 | |
| 178 | dev->urbs[i] = usb_alloc_urb(0, GFP_KERNEL); |
Mauro Carvalho Chehab | 18d73c5 | 2008-04-18 22:12:52 -0300 | [diff] [blame] | 179 | if (!dev->urbs[i]) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 180 | goto err; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 181 | |
| 182 | purb = dev->urbs[i]; |
| 183 | |
| 184 | purb->transfer_buffer = kzalloc(URB_BUFSIZE, GFP_KERNEL); |
| 185 | if (!purb->transfer_buffer) { |
| 186 | usb_free_urb(purb); |
Harvey Harrison | a6a3a17 | 2008-04-28 16:50:03 -0700 | [diff] [blame] | 187 | dev->urbs[i] = NULL; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 188 | goto err; |
| 189 | } |
| 190 | |
| 191 | purb->status = -EINPROGRESS; |
| 192 | usb_fill_bulk_urb(purb, |
| 193 | dev->usbdev, |
Steven Toth | a8eb912 | 2008-10-16 20:19:41 -0300 | [diff] [blame] | 194 | usb_rcvbulkpipe(dev->usbdev, |
| 195 | _AU0828_BULKPIPE), |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 196 | purb->transfer_buffer, |
| 197 | URB_BUFSIZE, |
| 198 | urb_completion, |
| 199 | dev); |
| 200 | |
| 201 | } |
| 202 | |
| 203 | for (i = 0; i < URB_COUNT; i++) { |
| 204 | ret = usb_submit_urb(dev->urbs[i], GFP_ATOMIC); |
| 205 | if (ret != 0) { |
| 206 | stop_urb_transfer(dev); |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 207 | printk(KERN_ERR "%s: failed urb submission, " |
| 208 | "err = %d\n", __func__, ret); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 209 | return ret; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | dev->urb_streaming = 1; |
| 214 | ret = 0; |
| 215 | |
| 216 | err: |
| 217 | return ret; |
| 218 | } |
| 219 | |
| 220 | static int au0828_dvb_start_feed(struct dvb_demux_feed *feed) |
| 221 | { |
| 222 | struct dvb_demux *demux = feed->demux; |
| 223 | struct au0828_dev *dev = (struct au0828_dev *) demux->priv; |
| 224 | struct au0828_dvb *dvb = &dev->dvb; |
| 225 | int ret = 0; |
| 226 | |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 227 | dprintk(1, "%s()\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 228 | |
| 229 | if (!demux->dmx.frontend) |
| 230 | return -EINVAL; |
| 231 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 232 | if (dvb) { |
| 233 | mutex_lock(&dvb->lock); |
| 234 | if (dvb->feeding++ == 0) { |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 235 | /* Start transport */ |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 236 | au0828_write(dev, 0x608, 0x90); |
| 237 | au0828_write(dev, 0x609, 0x72); |
| 238 | au0828_write(dev, 0x60a, 0x71); |
| 239 | au0828_write(dev, 0x60b, 0x01); |
| 240 | ret = start_urb_transfer(dev); |
| 241 | } |
| 242 | mutex_unlock(&dvb->lock); |
| 243 | } |
| 244 | |
| 245 | return ret; |
| 246 | } |
| 247 | |
| 248 | static int au0828_dvb_stop_feed(struct dvb_demux_feed *feed) |
| 249 | { |
| 250 | struct dvb_demux *demux = feed->demux; |
| 251 | struct au0828_dev *dev = (struct au0828_dev *) demux->priv; |
| 252 | struct au0828_dvb *dvb = &dev->dvb; |
| 253 | int ret = 0; |
| 254 | |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 255 | dprintk(1, "%s()\n", __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 256 | |
| 257 | if (dvb) { |
| 258 | mutex_lock(&dvb->lock); |
| 259 | if (--dvb->feeding == 0) { |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 260 | /* Stop transport */ |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 261 | ret = stop_urb_transfer(dev); |
Devin Heitmueller | 43f2ccc | 2012-08-06 22:46:53 -0300 | [diff] [blame] | 262 | au0828_write(dev, 0x60b, 0x00); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 263 | } |
| 264 | mutex_unlock(&dvb->lock); |
| 265 | } |
| 266 | |
| 267 | return ret; |
| 268 | } |
| 269 | |
Devin Heitmueller | 43f2ccc | 2012-08-06 22:46:53 -0300 | [diff] [blame] | 270 | static void au0828_restart_dvb_streaming(struct work_struct *work) |
| 271 | { |
| 272 | struct au0828_dev *dev = container_of(work, struct au0828_dev, |
| 273 | restart_streaming); |
| 274 | struct au0828_dvb *dvb = &dev->dvb; |
Devin Heitmueller | 43f2ccc | 2012-08-06 22:46:53 -0300 | [diff] [blame] | 275 | |
| 276 | if (dev->urb_streaming == 0) |
| 277 | return; |
| 278 | |
| 279 | dprintk(1, "Restarting streaming...!\n"); |
| 280 | |
| 281 | mutex_lock(&dvb->lock); |
| 282 | |
| 283 | /* Stop transport */ |
Mauro Carvalho Chehab | 2e7b318 | 2012-10-27 16:36:34 -0300 | [diff] [blame] | 284 | stop_urb_transfer(dev); |
Devin Heitmueller | 43f2ccc | 2012-08-06 22:46:53 -0300 | [diff] [blame] | 285 | au0828_write(dev, 0x608, 0x00); |
| 286 | au0828_write(dev, 0x609, 0x00); |
| 287 | au0828_write(dev, 0x60a, 0x00); |
| 288 | au0828_write(dev, 0x60b, 0x00); |
| 289 | |
| 290 | /* Start transport */ |
| 291 | au0828_write(dev, 0x608, 0x90); |
| 292 | au0828_write(dev, 0x609, 0x72); |
| 293 | au0828_write(dev, 0x60a, 0x71); |
| 294 | au0828_write(dev, 0x60b, 0x01); |
Mauro Carvalho Chehab | 2e7b318 | 2012-10-27 16:36:34 -0300 | [diff] [blame] | 295 | start_urb_transfer(dev); |
Devin Heitmueller | 43f2ccc | 2012-08-06 22:46:53 -0300 | [diff] [blame] | 296 | |
| 297 | mutex_unlock(&dvb->lock); |
| 298 | } |
| 299 | |
Adrian Bunk | b33d24c | 2008-04-25 19:06:03 -0300 | [diff] [blame] | 300 | static int dvb_register(struct au0828_dev *dev) |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 301 | { |
| 302 | struct au0828_dvb *dvb = &dev->dvb; |
| 303 | int result; |
| 304 | |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 305 | dprintk(1, "%s()\n", __func__); |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 306 | |
Devin Heitmueller | 43f2ccc | 2012-08-06 22:46:53 -0300 | [diff] [blame] | 307 | INIT_WORK(&dev->restart_streaming, au0828_restart_dvb_streaming); |
| 308 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 309 | /* register adapter */ |
| 310 | result = dvb_register_adapter(&dvb->adapter, DRIVER_NAME, THIS_MODULE, |
| 311 | &dev->usbdev->dev, adapter_nr); |
| 312 | if (result < 0) { |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 313 | printk(KERN_ERR "%s: dvb_register_adapter failed " |
| 314 | "(errno = %d)\n", DRIVER_NAME, result); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 315 | goto fail_adapter; |
| 316 | } |
| 317 | dvb->adapter.priv = dev; |
| 318 | |
| 319 | /* register frontend */ |
| 320 | result = dvb_register_frontend(&dvb->adapter, dvb->frontend); |
| 321 | if (result < 0) { |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 322 | printk(KERN_ERR "%s: dvb_register_frontend failed " |
| 323 | "(errno = %d)\n", DRIVER_NAME, result); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 324 | goto fail_frontend; |
| 325 | } |
| 326 | |
| 327 | /* register demux stuff */ |
| 328 | dvb->demux.dmx.capabilities = |
| 329 | DMX_TS_FILTERING | DMX_SECTION_FILTERING | |
| 330 | DMX_MEMORY_BASED_FILTERING; |
| 331 | dvb->demux.priv = dev; |
| 332 | dvb->demux.filternum = 256; |
| 333 | dvb->demux.feednum = 256; |
| 334 | dvb->demux.start_feed = au0828_dvb_start_feed; |
| 335 | dvb->demux.stop_feed = au0828_dvb_stop_feed; |
| 336 | result = dvb_dmx_init(&dvb->demux); |
| 337 | if (result < 0) { |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 338 | printk(KERN_ERR "%s: dvb_dmx_init failed (errno = %d)\n", |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 339 | DRIVER_NAME, result); |
| 340 | goto fail_dmx; |
| 341 | } |
| 342 | |
| 343 | dvb->dmxdev.filternum = 256; |
| 344 | dvb->dmxdev.demux = &dvb->demux.dmx; |
| 345 | dvb->dmxdev.capabilities = 0; |
| 346 | result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter); |
| 347 | if (result < 0) { |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 348 | printk(KERN_ERR "%s: dvb_dmxdev_init failed (errno = %d)\n", |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 349 | DRIVER_NAME, result); |
| 350 | goto fail_dmxdev; |
| 351 | } |
| 352 | |
| 353 | dvb->fe_hw.source = DMX_FRONTEND_0; |
| 354 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 355 | if (result < 0) { |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 356 | printk(KERN_ERR "%s: add_frontend failed " |
| 357 | "(DMX_FRONTEND_0, errno = %d)\n", DRIVER_NAME, result); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 358 | goto fail_fe_hw; |
| 359 | } |
| 360 | |
| 361 | dvb->fe_mem.source = DMX_MEMORY_FE; |
| 362 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 363 | if (result < 0) { |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 364 | printk(KERN_ERR "%s: add_frontend failed " |
| 365 | "(DMX_MEMORY_FE, errno = %d)\n", DRIVER_NAME, result); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 366 | goto fail_fe_mem; |
| 367 | } |
| 368 | |
| 369 | result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 370 | if (result < 0) { |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 371 | printk(KERN_ERR "%s: connect_frontend failed (errno = %d)\n", |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 372 | DRIVER_NAME, result); |
| 373 | goto fail_fe_conn; |
| 374 | } |
| 375 | |
| 376 | /* register network adapter */ |
| 377 | dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx); |
| 378 | return 0; |
| 379 | |
| 380 | fail_fe_conn: |
| 381 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 382 | fail_fe_mem: |
| 383 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 384 | fail_fe_hw: |
| 385 | dvb_dmxdev_release(&dvb->dmxdev); |
| 386 | fail_dmxdev: |
| 387 | dvb_dmx_release(&dvb->demux); |
| 388 | fail_dmx: |
| 389 | dvb_unregister_frontend(dvb->frontend); |
| 390 | fail_frontend: |
| 391 | dvb_frontend_detach(dvb->frontend); |
| 392 | dvb_unregister_adapter(&dvb->adapter); |
| 393 | fail_adapter: |
| 394 | return result; |
| 395 | } |
| 396 | |
| 397 | void au0828_dvb_unregister(struct au0828_dev *dev) |
| 398 | { |
| 399 | struct au0828_dvb *dvb = &dev->dvb; |
| 400 | |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 401 | dprintk(1, "%s()\n", __func__); |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 402 | |
Steven Toth | a9c36aa | 2008-04-17 21:41:28 -0300 | [diff] [blame] | 403 | if (dvb->frontend == NULL) |
Steven Toth | 9c26de55 | 2008-04-02 01:10:40 -0300 | [diff] [blame] | 404 | return; |
| 405 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 406 | dvb_net_release(&dvb->net); |
| 407 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 408 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 409 | dvb_dmxdev_release(&dvb->dmxdev); |
| 410 | dvb_dmx_release(&dvb->demux); |
| 411 | dvb_unregister_frontend(dvb->frontend); |
| 412 | dvb_frontend_detach(dvb->frontend); |
| 413 | dvb_unregister_adapter(&dvb->adapter); |
| 414 | } |
| 415 | |
| 416 | /* All the DVB attach calls go here, this function get's modified |
| 417 | * for each new card. No other function in this file needs |
| 418 | * to change. |
| 419 | */ |
| 420 | int au0828_dvb_register(struct au0828_dev *dev) |
| 421 | { |
| 422 | struct au0828_dvb *dvb = &dev->dvb; |
| 423 | int ret; |
| 424 | |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 425 | dprintk(1, "%s()\n", __func__); |
Steven Toth | bc3c613 | 2008-04-18 21:39:11 -0300 | [diff] [blame] | 426 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 427 | /* init frontend */ |
Devin Heitmueller | f1add5b | 2009-03-11 03:00:47 -0300 | [diff] [blame] | 428 | switch (dev->boardnr) { |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 429 | case AU0828_BOARD_HAUPPAUGE_HVR850: |
| 430 | case AU0828_BOARD_HAUPPAUGE_HVR950Q: |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 431 | dvb->frontend = dvb_attach(au8522_attach, |
| 432 | &hauppauge_hvr950q_config, |
| 433 | &dev->i2c_adap); |
Michael Krufky | 4872354 | 2008-05-10 14:34:09 -0300 | [diff] [blame] | 434 | if (dvb->frontend != NULL) |
Michael Krufky | be183dc | 2012-04-08 21:39:56 -0300 | [diff] [blame] | 435 | switch (dev->board.tuner_type) { |
| 436 | default: |
| 437 | case TUNER_XC5000: |
| 438 | dvb_attach(xc5000_attach, dvb->frontend, |
| 439 | &dev->i2c_adap, |
| 440 | &hauppauge_xc5000a_config); |
| 441 | break; |
| 442 | case TUNER_XC5000C: |
| 443 | dvb_attach(xc5000_attach, dvb->frontend, |
| 444 | &dev->i2c_adap, |
| 445 | &hauppauge_xc5000c_config); |
| 446 | break; |
| 447 | } |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 448 | break; |
Michael Krufky | 59d2752 | 2008-07-09 00:23:08 -0300 | [diff] [blame] | 449 | case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL: |
| 450 | dvb->frontend = dvb_attach(au8522_attach, |
| 451 | &hauppauge_hvr950q_config, |
| 452 | &dev->i2c_adap); |
| 453 | if (dvb->frontend != NULL) |
| 454 | dvb_attach(mxl5007t_attach, dvb->frontend, |
| 455 | &dev->i2c_adap, 0x60, |
| 456 | &mxl5007t_hvr950q_config); |
| 457 | break; |
Michael Krufky | 8e8bd22 | 2008-09-03 16:46:36 -0300 | [diff] [blame] | 458 | case AU0828_BOARD_HAUPPAUGE_WOODBURY: |
| 459 | dvb->frontend = dvb_attach(au8522_attach, |
| 460 | &hauppauge_woodbury_config, |
| 461 | &dev->i2c_adap); |
| 462 | if (dvb->frontend != NULL) |
| 463 | dvb_attach(tda18271_attach, dvb->frontend, |
| 464 | 0x60, &dev->i2c_adap, |
| 465 | &hauppauge_woodbury_tunerconfig); |
| 466 | break; |
Michael Krufky | adeeac3 | 2008-04-05 20:55:14 -0300 | [diff] [blame] | 467 | case AU0828_BOARD_DVICO_FUSIONHDTV7: |
| 468 | dvb->frontend = dvb_attach(au8522_attach, |
| 469 | &fusionhdtv7usb_config, |
| 470 | &dev->i2c_adap); |
| 471 | if (dvb->frontend != NULL) { |
| 472 | dvb_attach(xc5000_attach, dvb->frontend, |
| 473 | &dev->i2c_adap, |
Michael Krufky | be183dc | 2012-04-08 21:39:56 -0300 | [diff] [blame] | 474 | &hauppauge_xc5000a_config); |
Michael Krufky | adeeac3 | 2008-04-05 20:55:14 -0300 | [diff] [blame] | 475 | } |
| 476 | break; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 477 | default: |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 478 | printk(KERN_WARNING "The frontend of your DVB/ATSC card " |
| 479 | "isn't supported yet\n"); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 480 | break; |
| 481 | } |
| 482 | if (NULL == dvb->frontend) { |
Michael Krufky | f07e8e4 | 2008-04-18 21:42:30 -0300 | [diff] [blame] | 483 | printk(KERN_ERR "%s() Frontend initialization failed\n", |
| 484 | __func__); |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 485 | return -1; |
| 486 | } |
Michael Krufky | d7cba04 | 2008-09-12 13:31:45 -0300 | [diff] [blame] | 487 | /* define general-purpose callback pointer */ |
| 488 | dvb->frontend->callback = au0828_tuner_callback; |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 489 | |
Steven Toth | 265a651 | 2008-04-18 21:34:00 -0300 | [diff] [blame] | 490 | /* register everything */ |
| 491 | ret = dvb_register(dev); |
| 492 | if (ret < 0) { |
| 493 | if (dvb->frontend->ops.release) |
| 494 | dvb->frontend->ops.release(dvb->frontend); |
| 495 | return ret; |
| 496 | } |
| 497 | |
| 498 | return 0; |
| 499 | } |