Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 1 | /* |
| 2 | DVB device driver for em28xx |
| 3 | |
| 4 | (c) 2008 Mauro Carvalho Chehab <mchehab@infradead.org> |
| 5 | |
Devin Heitmueller | bdfbf95 | 2008-04-17 21:38:27 -0300 | [diff] [blame] | 6 | (c) 2008 Devin Heitmueller <devin.heitmueller@gmail.com> |
| 7 | - Fixes for the driver to properly work with HVR-950 |
Devin Heitmueller | 4fd305b | 2008-06-04 13:43:46 -0300 | [diff] [blame] | 8 | - Fixes for the driver to properly work with Pinnacle PCTV HD Pro Stick |
Devin Heitmueller | e14b365 | 2008-07-26 11:04:33 -0300 | [diff] [blame^] | 9 | - Fixes for the driver to properly work with AMD ATI TV Wonder HD 600 |
Devin Heitmueller | bdfbf95 | 2008-04-17 21:38:27 -0300 | [diff] [blame] | 10 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 11 | (c) 2008 Aidan Thornton <makosoft@googlemail.com> |
| 12 | |
| 13 | Based on cx88-dvb, saa7134-dvb and videobuf-dvb originally written by: |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 14 | (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au> |
| 15 | (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] |
| 16 | |
| 17 | This program is free software; you can redistribute it and/or modify |
| 18 | it under the terms of the GNU General Public License as published by |
| 19 | the Free Software Foundation; either version 2 of the License. |
| 20 | */ |
| 21 | |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/usb.h> |
| 24 | |
| 25 | #include "em28xx.h" |
| 26 | #include <media/v4l2-common.h> |
| 27 | #include <media/videobuf-vmalloc.h> |
| 28 | |
| 29 | #include "lgdt330x.h" |
Aidan Thornton | 7e6388a | 2008-04-17 21:40:03 -0300 | [diff] [blame] | 30 | #include "zl10353.h" |
Devin Heitmueller | 17d9d55 | 2008-06-08 10:22:03 -0300 | [diff] [blame] | 31 | #ifdef EM28XX_DRX397XD_SUPPORT |
| 32 | #include "drx397xD.h" |
| 33 | #endif |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 34 | |
| 35 | MODULE_DESCRIPTION("driver for em28xx based DVB cards"); |
| 36 | MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); |
| 37 | MODULE_LICENSE("GPL"); |
| 38 | |
| 39 | static unsigned int debug; |
| 40 | module_param(debug, int, 0644); |
| 41 | MODULE_PARM_DESC(debug, "enable debug messages [dvb]"); |
| 42 | |
| 43 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 44 | |
| 45 | #define dprintk(level, fmt, arg...) do { \ |
| 46 | if (debug >= level) \ |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 47 | printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \ |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 48 | } while (0) |
| 49 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 50 | #define EM28XX_DVB_NUM_BUFS 5 |
| 51 | #define EM28XX_DVB_MAX_PACKETSIZE 564 |
| 52 | #define EM28XX_DVB_MAX_PACKETS 64 |
| 53 | |
| 54 | struct em28xx_dvb { |
| 55 | struct dvb_frontend *frontend; |
| 56 | |
| 57 | /* feed count management */ |
| 58 | struct mutex lock; |
| 59 | int nfeeds; |
| 60 | |
| 61 | /* general boilerplate stuff */ |
| 62 | struct dvb_adapter adapter; |
| 63 | struct dvb_demux demux; |
| 64 | struct dmxdev dmxdev; |
| 65 | struct dmx_frontend fe_hw; |
| 66 | struct dmx_frontend fe_mem; |
| 67 | struct dvb_net net; |
| 68 | }; |
| 69 | |
| 70 | |
| 71 | static inline void print_err_status(struct em28xx *dev, |
| 72 | int packet, int status) |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 73 | { |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 74 | char *errmsg = "Unknown"; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 75 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 76 | switch (status) { |
| 77 | case -ENOENT: |
| 78 | errmsg = "unlinked synchronuously"; |
| 79 | break; |
| 80 | case -ECONNRESET: |
| 81 | errmsg = "unlinked asynchronuously"; |
| 82 | break; |
| 83 | case -ENOSR: |
| 84 | errmsg = "Buffer error (overrun)"; |
| 85 | break; |
| 86 | case -EPIPE: |
| 87 | errmsg = "Stalled (device not responding)"; |
| 88 | break; |
| 89 | case -EOVERFLOW: |
| 90 | errmsg = "Babble (bad cable?)"; |
| 91 | break; |
| 92 | case -EPROTO: |
| 93 | errmsg = "Bit-stuff error (bad cable?)"; |
| 94 | break; |
| 95 | case -EILSEQ: |
| 96 | errmsg = "CRC/Timeout (could be anything)"; |
| 97 | break; |
| 98 | case -ETIME: |
| 99 | errmsg = "Device does not respond"; |
| 100 | break; |
| 101 | } |
| 102 | if (packet < 0) { |
| 103 | dprintk(1, "URB status %d [%s].\n", status, errmsg); |
| 104 | } else { |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 105 | dprintk(1, "URB packet %d, status %d [%s].\n", |
| 106 | packet, status, errmsg); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 107 | } |
| 108 | } |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 109 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 110 | static inline int dvb_isoc_copy(struct em28xx *dev, struct urb *urb) |
| 111 | { |
| 112 | int i; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 113 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 114 | if (!dev) |
| 115 | return 0; |
| 116 | |
| 117 | if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) |
| 118 | return 0; |
| 119 | |
| 120 | if (urb->status < 0) { |
| 121 | print_err_status(dev, -1, urb->status); |
| 122 | if (urb->status == -ENOENT) |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | for (i = 0; i < urb->number_of_packets; i++) { |
| 127 | int status = urb->iso_frame_desc[i].status; |
| 128 | |
| 129 | if (status < 0) { |
| 130 | print_err_status(dev, i, status); |
| 131 | if (urb->iso_frame_desc[i].status != -EPROTO) |
| 132 | continue; |
| 133 | } |
| 134 | |
| 135 | dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer + |
| 136 | urb->iso_frame_desc[i].offset, |
| 137 | urb->iso_frame_desc[i].actual_length); |
| 138 | } |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 139 | |
| 140 | return 0; |
| 141 | } |
| 142 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 143 | static int start_streaming(struct em28xx_dvb *dvb) |
| 144 | { |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 145 | int rc; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 146 | struct em28xx *dev = dvb->adapter.priv; |
| 147 | |
| 148 | usb_set_interface(dev->udev, 0, 1); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 149 | rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); |
| 150 | if (rc < 0) |
| 151 | return rc; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 152 | |
| 153 | return em28xx_init_isoc(dev, EM28XX_DVB_MAX_PACKETS, |
| 154 | EM28XX_DVB_NUM_BUFS, EM28XX_DVB_MAX_PACKETSIZE, |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 155 | dvb_isoc_copy); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 156 | } |
| 157 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 158 | static int stop_streaming(struct em28xx_dvb *dvb) |
| 159 | { |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 160 | struct em28xx *dev = dvb->adapter.priv; |
| 161 | |
| 162 | em28xx_uninit_isoc(dev); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 163 | |
| 164 | em28xx_set_mode(dev, EM28XX_MODE_UNDEFINED); |
| 165 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | static int start_feed(struct dvb_demux_feed *feed) |
| 170 | { |
| 171 | struct dvb_demux *demux = feed->demux; |
| 172 | struct em28xx_dvb *dvb = demux->priv; |
| 173 | int rc, ret; |
| 174 | |
| 175 | if (!demux->dmx.frontend) |
| 176 | return -EINVAL; |
| 177 | |
| 178 | mutex_lock(&dvb->lock); |
| 179 | dvb->nfeeds++; |
| 180 | rc = dvb->nfeeds; |
| 181 | |
| 182 | if (dvb->nfeeds == 1) { |
| 183 | ret = start_streaming(dvb); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 184 | if (ret < 0) |
| 185 | rc = ret; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | mutex_unlock(&dvb->lock); |
| 189 | return rc; |
| 190 | } |
| 191 | |
| 192 | static int stop_feed(struct dvb_demux_feed *feed) |
| 193 | { |
| 194 | struct dvb_demux *demux = feed->demux; |
| 195 | struct em28xx_dvb *dvb = demux->priv; |
| 196 | int err = 0; |
| 197 | |
| 198 | mutex_lock(&dvb->lock); |
| 199 | dvb->nfeeds--; |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 200 | |
| 201 | if (0 == dvb->nfeeds) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 202 | err = stop_streaming(dvb); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 203 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 204 | mutex_unlock(&dvb->lock); |
| 205 | return err; |
| 206 | } |
| 207 | |
| 208 | |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 209 | |
| 210 | /* ------------------------------------------------------------------ */ |
| 211 | static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire) |
| 212 | { |
| 213 | struct em28xx *dev = fe->dvb->priv; |
| 214 | |
| 215 | if (acquire) |
| 216 | return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); |
| 217 | else |
| 218 | return em28xx_set_mode(dev, EM28XX_MODE_UNDEFINED); |
| 219 | } |
| 220 | |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 221 | /* ------------------------------------------------------------------ */ |
| 222 | |
Mauro Carvalho Chehab | 227ad4a | 2008-04-17 21:37:40 -0300 | [diff] [blame] | 223 | static struct lgdt330x_config em2880_lgdt3303_dev = { |
| 224 | .demod_address = 0x0e, |
| 225 | .demod_chip = LGDT3303, |
| 226 | }; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 227 | |
Aidan Thornton | 7e6388a | 2008-04-17 21:40:03 -0300 | [diff] [blame] | 228 | static struct zl10353_config em28xx_zl10353_with_xc3028 = { |
| 229 | .demod_address = (0x1e >> 1), |
| 230 | .no_tuner = 1, |
| 231 | .parallel_ts = 1, |
| 232 | .if2 = 45600, |
| 233 | }; |
| 234 | |
Devin Heitmueller | 17d9d55 | 2008-06-08 10:22:03 -0300 | [diff] [blame] | 235 | #ifdef EM28XX_DRX397XD_SUPPORT |
| 236 | /* [TODO] djh - not sure yet what the device config needs to contain */ |
| 237 | static struct drx397xD_config em28xx_drx397xD_with_xc3028 = { |
| 238 | .demod_address = (0xe0 >> 1), |
| 239 | }; |
| 240 | #endif |
| 241 | |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 242 | /* ------------------------------------------------------------------ */ |
| 243 | |
| 244 | static int attach_xc3028(u8 addr, struct em28xx *dev) |
| 245 | { |
| 246 | struct dvb_frontend *fe; |
Mauro Carvalho Chehab | 3ca9c09 | 2008-04-17 21:37:53 -0300 | [diff] [blame] | 247 | struct xc2028_config cfg; |
| 248 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 249 | memset(&cfg, 0, sizeof(cfg)); |
Mauro Carvalho Chehab | 3ca9c09 | 2008-04-17 21:37:53 -0300 | [diff] [blame] | 250 | cfg.i2c_adap = &dev->i2c_adap; |
| 251 | cfg.i2c_addr = addr; |
Mauro Carvalho Chehab | 3ca9c09 | 2008-04-17 21:37:53 -0300 | [diff] [blame] | 252 | cfg.callback = em28xx_tuner_callback; |
| 253 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 254 | if (!dev->dvb->frontend) { |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 255 | printk(KERN_ERR "%s/2: dvb frontend not attached. " |
| 256 | "Can't attach xc3028\n", |
| 257 | dev->name); |
| 258 | return -EINVAL; |
| 259 | } |
| 260 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 261 | fe = dvb_attach(xc2028_attach, dev->dvb->frontend, &cfg); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 262 | if (!fe) { |
| 263 | printk(KERN_ERR "%s/2: xc3028 attach failed\n", |
| 264 | dev->name); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 265 | dvb_frontend_detach(dev->dvb->frontend); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 266 | dev->dvb->frontend = NULL; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 267 | return -EINVAL; |
| 268 | } |
| 269 | |
| 270 | printk(KERN_INFO "%s/2: xc3028 attached\n", dev->name); |
| 271 | |
| 272 | return 0; |
| 273 | } |
| 274 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 275 | /* ------------------------------------------------------------------ */ |
| 276 | |
| 277 | int register_dvb(struct em28xx_dvb *dvb, |
| 278 | struct module *module, |
| 279 | struct em28xx *dev, |
| 280 | struct device *device) |
| 281 | { |
| 282 | int result; |
| 283 | |
| 284 | mutex_init(&dvb->lock); |
| 285 | |
| 286 | /* register adapter */ |
| 287 | result = dvb_register_adapter(&dvb->adapter, dev->name, module, device, |
| 288 | adapter_nr); |
| 289 | if (result < 0) { |
| 290 | printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n", |
| 291 | dev->name, result); |
| 292 | goto fail_adapter; |
| 293 | } |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 294 | |
| 295 | /* Ensure all frontends negotiate bus access */ |
| 296 | dvb->frontend->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl; |
| 297 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 298 | dvb->adapter.priv = dev; |
| 299 | |
| 300 | /* register frontend */ |
| 301 | result = dvb_register_frontend(&dvb->adapter, dvb->frontend); |
| 302 | if (result < 0) { |
| 303 | printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n", |
| 304 | dev->name, result); |
| 305 | goto fail_frontend; |
| 306 | } |
| 307 | |
| 308 | /* register demux stuff */ |
| 309 | dvb->demux.dmx.capabilities = |
| 310 | DMX_TS_FILTERING | DMX_SECTION_FILTERING | |
| 311 | DMX_MEMORY_BASED_FILTERING; |
| 312 | dvb->demux.priv = dvb; |
| 313 | dvb->demux.filternum = 256; |
| 314 | dvb->demux.feednum = 256; |
| 315 | dvb->demux.start_feed = start_feed; |
| 316 | dvb->demux.stop_feed = stop_feed; |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 317 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 318 | result = dvb_dmx_init(&dvb->demux); |
| 319 | if (result < 0) { |
| 320 | printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n", |
| 321 | dev->name, result); |
| 322 | goto fail_dmx; |
| 323 | } |
| 324 | |
| 325 | dvb->dmxdev.filternum = 256; |
| 326 | dvb->dmxdev.demux = &dvb->demux.dmx; |
| 327 | dvb->dmxdev.capabilities = 0; |
| 328 | result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter); |
| 329 | if (result < 0) { |
| 330 | printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n", |
| 331 | dev->name, result); |
| 332 | goto fail_dmxdev; |
| 333 | } |
| 334 | |
| 335 | dvb->fe_hw.source = DMX_FRONTEND_0; |
| 336 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 337 | if (result < 0) { |
| 338 | printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n", |
| 339 | dev->name, result); |
| 340 | goto fail_fe_hw; |
| 341 | } |
| 342 | |
| 343 | dvb->fe_mem.source = DMX_MEMORY_FE; |
| 344 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 345 | if (result < 0) { |
| 346 | printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n", |
| 347 | dev->name, result); |
| 348 | goto fail_fe_mem; |
| 349 | } |
| 350 | |
| 351 | result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 352 | if (result < 0) { |
| 353 | printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n", |
| 354 | dev->name, result); |
| 355 | goto fail_fe_conn; |
| 356 | } |
| 357 | |
| 358 | /* register network adapter */ |
| 359 | dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx); |
| 360 | return 0; |
| 361 | |
| 362 | fail_fe_conn: |
| 363 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 364 | fail_fe_mem: |
| 365 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 366 | fail_fe_hw: |
| 367 | dvb_dmxdev_release(&dvb->dmxdev); |
| 368 | fail_dmxdev: |
| 369 | dvb_dmx_release(&dvb->demux); |
| 370 | fail_dmx: |
| 371 | dvb_unregister_frontend(dvb->frontend); |
| 372 | fail_frontend: |
| 373 | dvb_frontend_detach(dvb->frontend); |
| 374 | dvb_unregister_adapter(&dvb->adapter); |
| 375 | fail_adapter: |
| 376 | return result; |
| 377 | } |
| 378 | |
| 379 | static void unregister_dvb(struct em28xx_dvb *dvb) |
| 380 | { |
| 381 | dvb_net_release(&dvb->net); |
| 382 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 383 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 384 | dvb_dmxdev_release(&dvb->dmxdev); |
| 385 | dvb_dmx_release(&dvb->demux); |
| 386 | dvb_unregister_frontend(dvb->frontend); |
| 387 | dvb_frontend_detach(dvb->frontend); |
| 388 | dvb_unregister_adapter(&dvb->adapter); |
| 389 | } |
| 390 | |
| 391 | |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 392 | static int dvb_init(struct em28xx *dev) |
| 393 | { |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 394 | int result = 0; |
| 395 | struct em28xx_dvb *dvb; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 396 | |
Devin Heitmueller | df61918 | 2008-06-10 12:34:35 -0300 | [diff] [blame] | 397 | if (!dev->has_dvb) { |
| 398 | /* This device does not support the extension */ |
| 399 | return 0; |
| 400 | } |
| 401 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 402 | dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 403 | |
| 404 | if (dvb == NULL) { |
| 405 | printk(KERN_INFO "em28xx_dvb: memory allocation failed\n"); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 406 | return -ENOMEM; |
| 407 | } |
| 408 | dev->dvb = dvb; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 409 | |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 410 | em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 411 | /* init frontend */ |
| 412 | switch (dev->model) { |
Mauro Carvalho Chehab | 227ad4a | 2008-04-17 21:37:40 -0300 | [diff] [blame] | 413 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950: |
Devin Heitmueller | 4fd305b | 2008-06-04 13:43:46 -0300 | [diff] [blame] | 414 | case EM2880_BOARD_PINNACLE_PCTV_HD_PRO: |
Devin Heitmueller | e14b365 | 2008-07-26 11:04:33 -0300 | [diff] [blame^] | 415 | case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600: |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 416 | dvb->frontend = dvb_attach(lgdt330x_attach, |
| 417 | &em2880_lgdt3303_dev, |
| 418 | &dev->i2c_adap); |
| 419 | if (attach_xc3028(0x61, dev) < 0) { |
| 420 | result = -EINVAL; |
| 421 | goto out_free; |
| 422 | } |
Mauro Carvalho Chehab | 227ad4a | 2008-04-17 21:37:40 -0300 | [diff] [blame] | 423 | break; |
Aidan Thornton | 7e6388a | 2008-04-17 21:40:03 -0300 | [diff] [blame] | 424 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900: |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 425 | dvb->frontend = dvb_attach(zl10353_attach, |
| 426 | &em28xx_zl10353_with_xc3028, |
| 427 | &dev->i2c_adap); |
| 428 | if (attach_xc3028(0x61, dev) < 0) { |
| 429 | result = -EINVAL; |
| 430 | goto out_free; |
| 431 | } |
Aidan Thornton | 7e6388a | 2008-04-17 21:40:03 -0300 | [diff] [blame] | 432 | break; |
Devin Heitmueller | 17d9d55 | 2008-06-08 10:22:03 -0300 | [diff] [blame] | 433 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2: |
| 434 | #ifdef EM28XX_DRX397XD_SUPPORT |
| 435 | /* We don't have the config structure properly populated, so |
| 436 | this is commented out for now */ |
| 437 | dvb->frontend = dvb_attach(drx397xD_attach, |
| 438 | &em28xx_drx397xD_with_xc3028, |
| 439 | &dev->i2c_adap); |
| 440 | if (attach_xc3028(0x61, dev) < 0) { |
| 441 | result = -EINVAL; |
| 442 | goto out_free; |
| 443 | } |
| 444 | break; |
| 445 | #endif |
reinhard schwab | 655b840 | 2008-07-26 10:47:00 -0300 | [diff] [blame] | 446 | case EM2880_BOARD_TERRATEC_HYBRID_XS: |
| 447 | dvb->frontend = dvb_attach(zl10353_attach, |
| 448 | &em28xx_zl10353_with_xc3028, |
| 449 | &dev->i2c_adap); |
| 450 | if (attach_xc3028(0x61, dev) < 0) { |
| 451 | result = -EINVAL; |
| 452 | goto out_free; |
| 453 | } |
| 454 | break; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 455 | default: |
| 456 | printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card" |
| 457 | " isn't supported yet\n", |
| 458 | dev->name); |
| 459 | break; |
| 460 | } |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 461 | if (NULL == dvb->frontend) { |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 462 | printk(KERN_ERR |
| 463 | "%s/2: frontend initialization failed\n", |
| 464 | dev->name); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 465 | result = -EINVAL; |
| 466 | goto out_free; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | /* register everything */ |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 470 | result = register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev); |
| 471 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 472 | if (result < 0) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 473 | goto out_free; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 474 | |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 475 | em28xx_set_mode(dev, EM28XX_MODE_UNDEFINED); |
Mauro Carvalho Chehab | 102a0b0 | 2008-04-17 21:40:45 -0300 | [diff] [blame] | 476 | printk(KERN_INFO "Successfully loaded em28xx-dvb\n"); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 477 | return 0; |
| 478 | |
| 479 | out_free: |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 480 | em28xx_set_mode(dev, EM28XX_MODE_UNDEFINED); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 481 | kfree(dvb); |
| 482 | dev->dvb = NULL; |
| 483 | return result; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | static int dvb_fini(struct em28xx *dev) |
| 487 | { |
Devin Heitmueller | df61918 | 2008-06-10 12:34:35 -0300 | [diff] [blame] | 488 | if (!dev->has_dvb) { |
| 489 | /* This device does not support the extension */ |
| 490 | return 0; |
| 491 | } |
| 492 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 493 | if (dev->dvb) { |
| 494 | unregister_dvb(dev->dvb); |
| 495 | dev->dvb = NULL; |
| 496 | } |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 497 | |
| 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | static struct em28xx_ops dvb_ops = { |
| 502 | .id = EM28XX_DVB, |
| 503 | .name = "Em28xx dvb Extension", |
| 504 | .init = dvb_init, |
| 505 | .fini = dvb_fini, |
| 506 | }; |
| 507 | |
| 508 | static int __init em28xx_dvb_register(void) |
| 509 | { |
| 510 | return em28xx_register_extension(&dvb_ops); |
| 511 | } |
| 512 | |
| 513 | static void __exit em28xx_dvb_unregister(void) |
| 514 | { |
| 515 | em28xx_unregister_extension(&dvb_ops); |
| 516 | } |
| 517 | |
| 518 | module_init(em28xx_dvb_register); |
| 519 | module_exit(em28xx_dvb_unregister); |