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> |
Franklin Meng | d7de5d8 | 2009-06-06 17:05:02 -0300 | [diff] [blame] | 28 | #include <media/tuner.h> |
| 29 | #include "tuner-simple.h" |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 30 | |
| 31 | #include "lgdt330x.h" |
Aidan Thornton | 7e6388a | 2008-04-17 21:40:03 -0300 | [diff] [blame] | 32 | #include "zl10353.h" |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 33 | #include "s5h1409.h" |
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 |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 51 | #define EM28XX_DVB_MAX_PACKETS 64 |
| 52 | |
| 53 | struct em28xx_dvb { |
| 54 | struct dvb_frontend *frontend; |
| 55 | |
| 56 | /* feed count management */ |
| 57 | struct mutex lock; |
| 58 | int nfeeds; |
| 59 | |
| 60 | /* general boilerplate stuff */ |
| 61 | struct dvb_adapter adapter; |
| 62 | struct dvb_demux demux; |
| 63 | struct dmxdev dmxdev; |
| 64 | struct dmx_frontend fe_hw; |
| 65 | struct dmx_frontend fe_mem; |
| 66 | struct dvb_net net; |
| 67 | }; |
| 68 | |
| 69 | |
| 70 | static inline void print_err_status(struct em28xx *dev, |
| 71 | int packet, int status) |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 72 | { |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 73 | char *errmsg = "Unknown"; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 74 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 75 | switch (status) { |
| 76 | case -ENOENT: |
| 77 | errmsg = "unlinked synchronuously"; |
| 78 | break; |
| 79 | case -ECONNRESET: |
| 80 | errmsg = "unlinked asynchronuously"; |
| 81 | break; |
| 82 | case -ENOSR: |
| 83 | errmsg = "Buffer error (overrun)"; |
| 84 | break; |
| 85 | case -EPIPE: |
| 86 | errmsg = "Stalled (device not responding)"; |
| 87 | break; |
| 88 | case -EOVERFLOW: |
| 89 | errmsg = "Babble (bad cable?)"; |
| 90 | break; |
| 91 | case -EPROTO: |
| 92 | errmsg = "Bit-stuff error (bad cable?)"; |
| 93 | break; |
| 94 | case -EILSEQ: |
| 95 | errmsg = "CRC/Timeout (could be anything)"; |
| 96 | break; |
| 97 | case -ETIME: |
| 98 | errmsg = "Device does not respond"; |
| 99 | break; |
| 100 | } |
| 101 | if (packet < 0) { |
| 102 | dprintk(1, "URB status %d [%s].\n", status, errmsg); |
| 103 | } else { |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 104 | dprintk(1, "URB packet %d, status %d [%s].\n", |
| 105 | packet, status, errmsg); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 106 | } |
| 107 | } |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 108 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 109 | static inline int dvb_isoc_copy(struct em28xx *dev, struct urb *urb) |
| 110 | { |
| 111 | int i; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 112 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 113 | if (!dev) |
| 114 | return 0; |
| 115 | |
| 116 | if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) |
| 117 | return 0; |
| 118 | |
| 119 | if (urb->status < 0) { |
| 120 | print_err_status(dev, -1, urb->status); |
| 121 | if (urb->status == -ENOENT) |
| 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | for (i = 0; i < urb->number_of_packets; i++) { |
| 126 | int status = urb->iso_frame_desc[i].status; |
| 127 | |
| 128 | if (status < 0) { |
| 129 | print_err_status(dev, i, status); |
| 130 | if (urb->iso_frame_desc[i].status != -EPROTO) |
| 131 | continue; |
| 132 | } |
| 133 | |
| 134 | dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer + |
| 135 | urb->iso_frame_desc[i].offset, |
| 136 | urb->iso_frame_desc[i].actual_length); |
| 137 | } |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 142 | static int start_streaming(struct em28xx_dvb *dvb) |
| 143 | { |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 144 | int rc; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 145 | struct em28xx *dev = dvb->adapter.priv; |
Devin Heitmueller | d18e2fd | 2009-05-16 17:09:28 -0300 | [diff] [blame] | 146 | int max_dvb_packet_size; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 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 | |
Devin Heitmueller | d18e2fd | 2009-05-16 17:09:28 -0300 | [diff] [blame] | 153 | max_dvb_packet_size = em28xx_isoc_dvb_max_packetsize(dev); |
| 154 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 155 | return em28xx_init_isoc(dev, EM28XX_DVB_MAX_PACKETS, |
Devin Heitmueller | d18e2fd | 2009-05-16 17:09:28 -0300 | [diff] [blame] | 156 | EM28XX_DVB_NUM_BUFS, max_dvb_packet_size, |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 157 | dvb_isoc_copy); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 158 | } |
| 159 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 160 | static int stop_streaming(struct em28xx_dvb *dvb) |
| 161 | { |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 162 | struct em28xx *dev = dvb->adapter.priv; |
| 163 | |
| 164 | em28xx_uninit_isoc(dev); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 165 | |
Mauro Carvalho Chehab | 2fe3e2e | 2008-11-27 09:10:40 -0300 | [diff] [blame] | 166 | em28xx_set_mode(dev, EM28XX_SUSPEND); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 167 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | static int start_feed(struct dvb_demux_feed *feed) |
| 172 | { |
| 173 | struct dvb_demux *demux = feed->demux; |
| 174 | struct em28xx_dvb *dvb = demux->priv; |
| 175 | int rc, ret; |
| 176 | |
| 177 | if (!demux->dmx.frontend) |
| 178 | return -EINVAL; |
| 179 | |
| 180 | mutex_lock(&dvb->lock); |
| 181 | dvb->nfeeds++; |
| 182 | rc = dvb->nfeeds; |
| 183 | |
| 184 | if (dvb->nfeeds == 1) { |
| 185 | ret = start_streaming(dvb); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 186 | if (ret < 0) |
| 187 | rc = ret; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | mutex_unlock(&dvb->lock); |
| 191 | return rc; |
| 192 | } |
| 193 | |
| 194 | static int stop_feed(struct dvb_demux_feed *feed) |
| 195 | { |
| 196 | struct dvb_demux *demux = feed->demux; |
| 197 | struct em28xx_dvb *dvb = demux->priv; |
| 198 | int err = 0; |
| 199 | |
| 200 | mutex_lock(&dvb->lock); |
| 201 | dvb->nfeeds--; |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 202 | |
| 203 | if (0 == dvb->nfeeds) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 204 | err = stop_streaming(dvb); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 205 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 206 | mutex_unlock(&dvb->lock); |
| 207 | return err; |
| 208 | } |
| 209 | |
| 210 | |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 211 | |
| 212 | /* ------------------------------------------------------------------ */ |
| 213 | static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire) |
| 214 | { |
| 215 | struct em28xx *dev = fe->dvb->priv; |
| 216 | |
| 217 | if (acquire) |
| 218 | return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); |
| 219 | else |
Mauro Carvalho Chehab | 2fe3e2e | 2008-11-27 09:10:40 -0300 | [diff] [blame] | 220 | return em28xx_set_mode(dev, EM28XX_SUSPEND); |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 221 | } |
| 222 | |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 223 | /* ------------------------------------------------------------------ */ |
| 224 | |
Mauro Carvalho Chehab | 227ad4a | 2008-04-17 21:37:40 -0300 | [diff] [blame] | 225 | static struct lgdt330x_config em2880_lgdt3303_dev = { |
| 226 | .demod_address = 0x0e, |
| 227 | .demod_chip = LGDT3303, |
| 228 | }; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 229 | |
Aidan Thornton | 7e6388a | 2008-04-17 21:40:03 -0300 | [diff] [blame] | 230 | static struct zl10353_config em28xx_zl10353_with_xc3028 = { |
| 231 | .demod_address = (0x1e >> 1), |
| 232 | .no_tuner = 1, |
| 233 | .parallel_ts = 1, |
| 234 | .if2 = 45600, |
| 235 | }; |
| 236 | |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 237 | static struct s5h1409_config em28xx_s5h1409_with_xc3028 = { |
| 238 | .demod_address = 0x32 >> 1, |
| 239 | .output_mode = S5H1409_PARALLEL_OUTPUT, |
| 240 | .gpio = S5H1409_GPIO_OFF, |
| 241 | .inversion = S5H1409_INVERSION_OFF, |
| 242 | .status_mode = S5H1409_DEMODLOCKING, |
| 243 | .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK |
| 244 | }; |
| 245 | |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 246 | static struct zl10353_config em28xx_terratec_xs_zl10353_xc3028 = { |
| 247 | .demod_address = (0x1e >> 1), |
| 248 | .no_tuner = 1, |
| 249 | .disable_i2c_gate_ctrl = 1, |
| 250 | .parallel_ts = 1, |
| 251 | .if2 = 45600, |
| 252 | }; |
| 253 | |
Devin Heitmueller | 17d9d55 | 2008-06-08 10:22:03 -0300 | [diff] [blame] | 254 | #ifdef EM28XX_DRX397XD_SUPPORT |
| 255 | /* [TODO] djh - not sure yet what the device config needs to contain */ |
| 256 | static struct drx397xD_config em28xx_drx397xD_with_xc3028 = { |
| 257 | .demod_address = (0xe0 >> 1), |
| 258 | }; |
| 259 | #endif |
| 260 | |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 261 | /* ------------------------------------------------------------------ */ |
| 262 | |
| 263 | static int attach_xc3028(u8 addr, struct em28xx *dev) |
| 264 | { |
| 265 | struct dvb_frontend *fe; |
Mauro Carvalho Chehab | 3ca9c09 | 2008-04-17 21:37:53 -0300 | [diff] [blame] | 266 | struct xc2028_config cfg; |
| 267 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 268 | memset(&cfg, 0, sizeof(cfg)); |
Mauro Carvalho Chehab | 3ca9c09 | 2008-04-17 21:37:53 -0300 | [diff] [blame] | 269 | cfg.i2c_adap = &dev->i2c_adap; |
| 270 | cfg.i2c_addr = addr; |
Mauro Carvalho Chehab | 3ca9c09 | 2008-04-17 21:37:53 -0300 | [diff] [blame] | 271 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 272 | if (!dev->dvb->frontend) { |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 273 | printk(KERN_ERR "%s/2: dvb frontend not attached. " |
| 274 | "Can't attach xc3028\n", |
| 275 | dev->name); |
| 276 | return -EINVAL; |
| 277 | } |
| 278 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 279 | fe = dvb_attach(xc2028_attach, dev->dvb->frontend, &cfg); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 280 | if (!fe) { |
| 281 | printk(KERN_ERR "%s/2: xc3028 attach failed\n", |
| 282 | dev->name); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 283 | dvb_frontend_detach(dev->dvb->frontend); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 284 | dev->dvb->frontend = NULL; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 285 | return -EINVAL; |
| 286 | } |
| 287 | |
| 288 | printk(KERN_INFO "%s/2: xc3028 attached\n", dev->name); |
| 289 | |
| 290 | return 0; |
| 291 | } |
| 292 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 293 | /* ------------------------------------------------------------------ */ |
| 294 | |
Hans Verkuil | d45b9b8 | 2008-09-04 03:33:43 -0300 | [diff] [blame] | 295 | static int register_dvb(struct em28xx_dvb *dvb, |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 296 | struct module *module, |
| 297 | struct em28xx *dev, |
| 298 | struct device *device) |
| 299 | { |
| 300 | int result; |
| 301 | |
| 302 | mutex_init(&dvb->lock); |
| 303 | |
| 304 | /* register adapter */ |
| 305 | result = dvb_register_adapter(&dvb->adapter, dev->name, module, device, |
| 306 | adapter_nr); |
| 307 | if (result < 0) { |
| 308 | printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n", |
| 309 | dev->name, result); |
| 310 | goto fail_adapter; |
| 311 | } |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 312 | |
| 313 | /* Ensure all frontends negotiate bus access */ |
| 314 | dvb->frontend->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl; |
| 315 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 316 | dvb->adapter.priv = dev; |
| 317 | |
| 318 | /* register frontend */ |
| 319 | result = dvb_register_frontend(&dvb->adapter, dvb->frontend); |
| 320 | if (result < 0) { |
| 321 | printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n", |
| 322 | dev->name, result); |
| 323 | goto fail_frontend; |
| 324 | } |
| 325 | |
| 326 | /* register demux stuff */ |
| 327 | dvb->demux.dmx.capabilities = |
| 328 | DMX_TS_FILTERING | DMX_SECTION_FILTERING | |
| 329 | DMX_MEMORY_BASED_FILTERING; |
| 330 | dvb->demux.priv = dvb; |
| 331 | dvb->demux.filternum = 256; |
| 332 | dvb->demux.feednum = 256; |
| 333 | dvb->demux.start_feed = start_feed; |
| 334 | dvb->demux.stop_feed = stop_feed; |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 335 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 336 | result = dvb_dmx_init(&dvb->demux); |
| 337 | if (result < 0) { |
| 338 | printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n", |
| 339 | dev->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) { |
| 348 | printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n", |
| 349 | dev->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) { |
| 356 | printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n", |
| 357 | dev->name, result); |
| 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) { |
| 364 | printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n", |
| 365 | dev->name, result); |
| 366 | goto fail_fe_mem; |
| 367 | } |
| 368 | |
| 369 | result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 370 | if (result < 0) { |
| 371 | printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n", |
| 372 | dev->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 | static void unregister_dvb(struct em28xx_dvb *dvb) |
| 398 | { |
| 399 | dvb_net_release(&dvb->net); |
| 400 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 401 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 402 | dvb_dmxdev_release(&dvb->dmxdev); |
| 403 | dvb_dmx_release(&dvb->demux); |
| 404 | dvb_unregister_frontend(dvb->frontend); |
| 405 | dvb_frontend_detach(dvb->frontend); |
| 406 | dvb_unregister_adapter(&dvb->adapter); |
| 407 | } |
| 408 | |
| 409 | |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 410 | static int dvb_init(struct em28xx *dev) |
| 411 | { |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 412 | int result = 0; |
| 413 | struct em28xx_dvb *dvb; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 414 | |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 415 | if (!dev->board.has_dvb) { |
Devin Heitmueller | df61918 | 2008-06-10 12:34:35 -0300 | [diff] [blame] | 416 | /* This device does not support the extension */ |
| 417 | return 0; |
| 418 | } |
| 419 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 420 | dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 421 | |
| 422 | if (dvb == NULL) { |
| 423 | printk(KERN_INFO "em28xx_dvb: memory allocation failed\n"); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 424 | return -ENOMEM; |
| 425 | } |
| 426 | dev->dvb = dvb; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 427 | |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 428 | em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 429 | /* init frontend */ |
| 430 | switch (dev->model) { |
Douglas Schilling Landgraf | f89bc32 | 2008-12-01 21:01:04 -0300 | [diff] [blame] | 431 | case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850: |
Mauro Carvalho Chehab | 10ac660 | 2008-07-27 14:58:58 -0300 | [diff] [blame] | 432 | case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950: |
Devin Heitmueller | 4fd305b | 2008-06-04 13:43:46 -0300 | [diff] [blame] | 433 | case EM2880_BOARD_PINNACLE_PCTV_HD_PRO: |
Devin Heitmueller | e14b365 | 2008-07-26 11:04:33 -0300 | [diff] [blame] | 434 | case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600: |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 435 | dvb->frontend = dvb_attach(lgdt330x_attach, |
| 436 | &em2880_lgdt3303_dev, |
| 437 | &dev->i2c_adap); |
| 438 | if (attach_xc3028(0x61, dev) < 0) { |
| 439 | result = -EINVAL; |
| 440 | goto out_free; |
| 441 | } |
Mauro Carvalho Chehab | 227ad4a | 2008-04-17 21:37:40 -0300 | [diff] [blame] | 442 | break; |
Aidan Thornton | 7e6388a | 2008-04-17 21:40:03 -0300 | [diff] [blame] | 443 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900: |
Thierry MERLE | 46510b5 | 2008-10-11 16:56:13 -0300 | [diff] [blame] | 444 | case EM2880_BOARD_KWORLD_DVB_310U: |
Douglas Schilling Landgraf | e5db5d4 | 2009-04-09 18:24:34 -0300 | [diff] [blame] | 445 | case EM2880_BOARD_EMPIRE_DUAL_TV: |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 446 | dvb->frontend = dvb_attach(zl10353_attach, |
| 447 | &em28xx_zl10353_with_xc3028, |
| 448 | &dev->i2c_adap); |
| 449 | if (attach_xc3028(0x61, dev) < 0) { |
| 450 | result = -EINVAL; |
| 451 | goto out_free; |
| 452 | } |
Aidan Thornton | 7e6388a | 2008-04-17 21:40:03 -0300 | [diff] [blame] | 453 | break; |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 454 | case EM2880_BOARD_TERRATEC_HYBRID_XS: |
| 455 | dvb->frontend = dvb_attach(zl10353_attach, |
| 456 | &em28xx_terratec_xs_zl10353_xc3028, |
| 457 | &dev->i2c_adap); |
| 458 | if (dvb->frontend == NULL) { |
| 459 | /* This board could have either a zl10353 or a mt352. |
| 460 | If the chip id isn't for zl10353, try mt352 */ |
| 461 | |
| 462 | /* FIXME: make support for mt352 work */ |
| 463 | printk(KERN_ERR "version of this board with mt352 not " |
| 464 | "currently supported\n"); |
| 465 | result = -EINVAL; |
| 466 | goto out_free; |
| 467 | } |
| 468 | if (attach_xc3028(0x61, dev) < 0) { |
| 469 | result = -EINVAL; |
| 470 | goto out_free; |
| 471 | } |
| 472 | break; |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 473 | case EM2883_BOARD_KWORLD_HYBRID_330U: |
Devin Heitmueller | 1985922 | 2009-06-19 00:33:54 -0300 | [diff] [blame] | 474 | case EM2882_BOARD_EVGA_INDTUBE: |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 475 | dvb->frontend = dvb_attach(s5h1409_attach, |
| 476 | &em28xx_s5h1409_with_xc3028, |
| 477 | &dev->i2c_adap); |
| 478 | if (attach_xc3028(0x61, dev) < 0) { |
| 479 | result = -EINVAL; |
| 480 | goto out_free; |
| 481 | } |
| 482 | break; |
Franklin Meng | d7de5d8 | 2009-06-06 17:05:02 -0300 | [diff] [blame] | 483 | case EM2882_BOARD_KWORLD_ATSC_315U: |
| 484 | dvb->frontend = dvb_attach(lgdt330x_attach, |
| 485 | &em2880_lgdt3303_dev, |
| 486 | &dev->i2c_adap); |
| 487 | if (dvb->frontend != NULL) { |
| 488 | if (!dvb_attach(simple_tuner_attach, dvb->frontend, |
| 489 | &dev->i2c_adap, 0x61, TUNER_THOMSON_DTT761X)) { |
| 490 | result = -EINVAL; |
| 491 | goto out_free; |
| 492 | } |
| 493 | } |
| 494 | break; |
Devin Heitmueller | 17d9d55 | 2008-06-08 10:22:03 -0300 | [diff] [blame] | 495 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2: |
| 496 | #ifdef EM28XX_DRX397XD_SUPPORT |
| 497 | /* We don't have the config structure properly populated, so |
| 498 | this is commented out for now */ |
| 499 | dvb->frontend = dvb_attach(drx397xD_attach, |
| 500 | &em28xx_drx397xD_with_xc3028, |
| 501 | &dev->i2c_adap); |
| 502 | if (attach_xc3028(0x61, dev) < 0) { |
| 503 | result = -EINVAL; |
| 504 | goto out_free; |
| 505 | } |
| 506 | break; |
| 507 | #endif |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 508 | default: |
| 509 | printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card" |
| 510 | " isn't supported yet\n", |
| 511 | dev->name); |
| 512 | break; |
| 513 | } |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 514 | if (NULL == dvb->frontend) { |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 515 | printk(KERN_ERR |
| 516 | "%s/2: frontend initialization failed\n", |
| 517 | dev->name); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 518 | result = -EINVAL; |
| 519 | goto out_free; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 520 | } |
Michael Krufky | d7cba04 | 2008-09-12 13:31:45 -0300 | [diff] [blame] | 521 | /* define general-purpose callback pointer */ |
| 522 | dvb->frontend->callback = em28xx_tuner_callback; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 523 | |
| 524 | /* register everything */ |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 525 | result = register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev); |
| 526 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 527 | if (result < 0) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 528 | goto out_free; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 529 | |
Mauro Carvalho Chehab | 2fe3e2e | 2008-11-27 09:10:40 -0300 | [diff] [blame] | 530 | em28xx_set_mode(dev, EM28XX_SUSPEND); |
Mauro Carvalho Chehab | 102a0b0 | 2008-04-17 21:40:45 -0300 | [diff] [blame] | 531 | printk(KERN_INFO "Successfully loaded em28xx-dvb\n"); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 532 | return 0; |
| 533 | |
| 534 | out_free: |
Mauro Carvalho Chehab | 2fe3e2e | 2008-11-27 09:10:40 -0300 | [diff] [blame] | 535 | em28xx_set_mode(dev, EM28XX_SUSPEND); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 536 | kfree(dvb); |
| 537 | dev->dvb = NULL; |
| 538 | return result; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 539 | } |
| 540 | |
| 541 | static int dvb_fini(struct em28xx *dev) |
| 542 | { |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 543 | if (!dev->board.has_dvb) { |
Devin Heitmueller | df61918 | 2008-06-10 12:34:35 -0300 | [diff] [blame] | 544 | /* This device does not support the extension */ |
| 545 | return 0; |
| 546 | } |
| 547 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 548 | if (dev->dvb) { |
| 549 | unregister_dvb(dev->dvb); |
| 550 | dev->dvb = NULL; |
| 551 | } |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 552 | |
| 553 | return 0; |
| 554 | } |
| 555 | |
| 556 | static struct em28xx_ops dvb_ops = { |
| 557 | .id = EM28XX_DVB, |
| 558 | .name = "Em28xx dvb Extension", |
| 559 | .init = dvb_init, |
| 560 | .fini = dvb_fini, |
| 561 | }; |
| 562 | |
| 563 | static int __init em28xx_dvb_register(void) |
| 564 | { |
| 565 | return em28xx_register_extension(&dvb_ops); |
| 566 | } |
| 567 | |
| 568 | static void __exit em28xx_dvb_unregister(void) |
| 569 | { |
| 570 | em28xx_unregister_extension(&dvb_ops); |
| 571 | } |
| 572 | |
| 573 | module_init(em28xx_dvb_register); |
| 574 | module_exit(em28xx_dvb_unregister); |