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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame^] | 23 | #include <linux/slab.h> |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 24 | #include <linux/usb.h> |
| 25 | |
| 26 | #include "em28xx.h" |
| 27 | #include <media/v4l2-common.h> |
| 28 | #include <media/videobuf-vmalloc.h> |
Franklin Meng | d7de5d8 | 2009-06-06 17:05:02 -0300 | [diff] [blame] | 29 | #include <media/tuner.h> |
| 30 | #include "tuner-simple.h" |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 31 | |
| 32 | #include "lgdt330x.h" |
Aidan Thornton | 7e6388a | 2008-04-17 21:40:03 -0300 | [diff] [blame] | 33 | #include "zl10353.h" |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 34 | #include "s5h1409.h" |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 35 | #include "mt352.h" |
| 36 | #include "mt352_priv.h" /* FIXME */ |
Antti Palosaari | 285eb1a | 2009-09-15 14:42:13 -0300 | [diff] [blame] | 37 | #include "tda1002x.h" |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 38 | |
| 39 | MODULE_DESCRIPTION("driver for em28xx based DVB cards"); |
| 40 | MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); |
| 41 | MODULE_LICENSE("GPL"); |
| 42 | |
| 43 | static unsigned int debug; |
| 44 | module_param(debug, int, 0644); |
| 45 | MODULE_PARM_DESC(debug, "enable debug messages [dvb]"); |
| 46 | |
| 47 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 48 | |
| 49 | #define dprintk(level, fmt, arg...) do { \ |
| 50 | if (debug >= level) \ |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 51 | printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \ |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 52 | } while (0) |
| 53 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 54 | #define EM28XX_DVB_NUM_BUFS 5 |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 55 | #define EM28XX_DVB_MAX_PACKETS 64 |
| 56 | |
| 57 | struct em28xx_dvb { |
| 58 | struct dvb_frontend *frontend; |
| 59 | |
| 60 | /* feed count management */ |
| 61 | struct mutex lock; |
| 62 | int nfeeds; |
| 63 | |
| 64 | /* general boilerplate stuff */ |
| 65 | struct dvb_adapter adapter; |
| 66 | struct dvb_demux demux; |
| 67 | struct dmxdev dmxdev; |
| 68 | struct dmx_frontend fe_hw; |
| 69 | struct dmx_frontend fe_mem; |
| 70 | struct dvb_net net; |
| 71 | }; |
| 72 | |
| 73 | |
| 74 | static inline void print_err_status(struct em28xx *dev, |
| 75 | int packet, int status) |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 76 | { |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 77 | char *errmsg = "Unknown"; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 78 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 79 | switch (status) { |
| 80 | case -ENOENT: |
| 81 | errmsg = "unlinked synchronuously"; |
| 82 | break; |
| 83 | case -ECONNRESET: |
| 84 | errmsg = "unlinked asynchronuously"; |
| 85 | break; |
| 86 | case -ENOSR: |
| 87 | errmsg = "Buffer error (overrun)"; |
| 88 | break; |
| 89 | case -EPIPE: |
| 90 | errmsg = "Stalled (device not responding)"; |
| 91 | break; |
| 92 | case -EOVERFLOW: |
| 93 | errmsg = "Babble (bad cable?)"; |
| 94 | break; |
| 95 | case -EPROTO: |
| 96 | errmsg = "Bit-stuff error (bad cable?)"; |
| 97 | break; |
| 98 | case -EILSEQ: |
| 99 | errmsg = "CRC/Timeout (could be anything)"; |
| 100 | break; |
| 101 | case -ETIME: |
| 102 | errmsg = "Device does not respond"; |
| 103 | break; |
| 104 | } |
| 105 | if (packet < 0) { |
| 106 | dprintk(1, "URB status %d [%s].\n", status, errmsg); |
| 107 | } else { |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 108 | dprintk(1, "URB packet %d, status %d [%s].\n", |
| 109 | packet, status, errmsg); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 110 | } |
| 111 | } |
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 | static inline int dvb_isoc_copy(struct em28xx *dev, struct urb *urb) |
| 114 | { |
| 115 | int i; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 116 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 117 | if (!dev) |
| 118 | return 0; |
| 119 | |
| 120 | if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) |
| 121 | return 0; |
| 122 | |
| 123 | if (urb->status < 0) { |
| 124 | print_err_status(dev, -1, urb->status); |
| 125 | if (urb->status == -ENOENT) |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | for (i = 0; i < urb->number_of_packets; i++) { |
| 130 | int status = urb->iso_frame_desc[i].status; |
| 131 | |
| 132 | if (status < 0) { |
| 133 | print_err_status(dev, i, status); |
| 134 | if (urb->iso_frame_desc[i].status != -EPROTO) |
| 135 | continue; |
| 136 | } |
| 137 | |
| 138 | dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer + |
| 139 | urb->iso_frame_desc[i].offset, |
| 140 | urb->iso_frame_desc[i].actual_length); |
| 141 | } |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 146 | static int start_streaming(struct em28xx_dvb *dvb) |
| 147 | { |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 148 | int rc; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 149 | struct em28xx *dev = dvb->adapter.priv; |
Devin Heitmueller | d18e2fd | 2009-05-16 17:09:28 -0300 | [diff] [blame] | 150 | int max_dvb_packet_size; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 151 | |
| 152 | usb_set_interface(dev->udev, 0, 1); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 153 | rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); |
| 154 | if (rc < 0) |
| 155 | return rc; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 156 | |
Devin Heitmueller | d18e2fd | 2009-05-16 17:09:28 -0300 | [diff] [blame] | 157 | max_dvb_packet_size = em28xx_isoc_dvb_max_packetsize(dev); |
| 158 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 159 | return em28xx_init_isoc(dev, EM28XX_DVB_MAX_PACKETS, |
Devin Heitmueller | d18e2fd | 2009-05-16 17:09:28 -0300 | [diff] [blame] | 160 | EM28XX_DVB_NUM_BUFS, max_dvb_packet_size, |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 161 | dvb_isoc_copy); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 162 | } |
| 163 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 164 | static int stop_streaming(struct em28xx_dvb *dvb) |
| 165 | { |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 166 | struct em28xx *dev = dvb->adapter.priv; |
| 167 | |
| 168 | em28xx_uninit_isoc(dev); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 169 | |
Mauro Carvalho Chehab | 2fe3e2e | 2008-11-27 09:10:40 -0300 | [diff] [blame] | 170 | em28xx_set_mode(dev, EM28XX_SUSPEND); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 171 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 172 | return 0; |
| 173 | } |
| 174 | |
| 175 | static int start_feed(struct dvb_demux_feed *feed) |
| 176 | { |
| 177 | struct dvb_demux *demux = feed->demux; |
| 178 | struct em28xx_dvb *dvb = demux->priv; |
| 179 | int rc, ret; |
| 180 | |
| 181 | if (!demux->dmx.frontend) |
| 182 | return -EINVAL; |
| 183 | |
| 184 | mutex_lock(&dvb->lock); |
| 185 | dvb->nfeeds++; |
| 186 | rc = dvb->nfeeds; |
| 187 | |
| 188 | if (dvb->nfeeds == 1) { |
| 189 | ret = start_streaming(dvb); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 190 | if (ret < 0) |
| 191 | rc = ret; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 192 | } |
| 193 | |
| 194 | mutex_unlock(&dvb->lock); |
| 195 | return rc; |
| 196 | } |
| 197 | |
| 198 | static int stop_feed(struct dvb_demux_feed *feed) |
| 199 | { |
| 200 | struct dvb_demux *demux = feed->demux; |
| 201 | struct em28xx_dvb *dvb = demux->priv; |
| 202 | int err = 0; |
| 203 | |
| 204 | mutex_lock(&dvb->lock); |
| 205 | dvb->nfeeds--; |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 206 | |
| 207 | if (0 == dvb->nfeeds) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 208 | err = stop_streaming(dvb); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 209 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 210 | mutex_unlock(&dvb->lock); |
| 211 | return err; |
| 212 | } |
| 213 | |
| 214 | |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 215 | |
| 216 | /* ------------------------------------------------------------------ */ |
| 217 | static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire) |
| 218 | { |
| 219 | struct em28xx *dev = fe->dvb->priv; |
| 220 | |
| 221 | if (acquire) |
| 222 | return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); |
| 223 | else |
Mauro Carvalho Chehab | 2fe3e2e | 2008-11-27 09:10:40 -0300 | [diff] [blame] | 224 | return em28xx_set_mode(dev, EM28XX_SUSPEND); |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 225 | } |
| 226 | |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 227 | /* ------------------------------------------------------------------ */ |
| 228 | |
Mauro Carvalho Chehab | 227ad4a | 2008-04-17 21:37:40 -0300 | [diff] [blame] | 229 | static struct lgdt330x_config em2880_lgdt3303_dev = { |
| 230 | .demod_address = 0x0e, |
| 231 | .demod_chip = LGDT3303, |
| 232 | }; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 233 | |
Aidan Thornton | 7e6388a | 2008-04-17 21:40:03 -0300 | [diff] [blame] | 234 | static struct zl10353_config em28xx_zl10353_with_xc3028 = { |
| 235 | .demod_address = (0x1e >> 1), |
| 236 | .no_tuner = 1, |
| 237 | .parallel_ts = 1, |
| 238 | .if2 = 45600, |
| 239 | }; |
| 240 | |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 241 | static struct s5h1409_config em28xx_s5h1409_with_xc3028 = { |
| 242 | .demod_address = 0x32 >> 1, |
| 243 | .output_mode = S5H1409_PARALLEL_OUTPUT, |
| 244 | .gpio = S5H1409_GPIO_OFF, |
| 245 | .inversion = S5H1409_INVERSION_OFF, |
| 246 | .status_mode = S5H1409_DEMODLOCKING, |
| 247 | .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK |
| 248 | }; |
| 249 | |
Devin Heitmueller | a84f79a | 2009-07-12 17:05:02 -0300 | [diff] [blame] | 250 | static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = { |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 251 | .demod_address = (0x1e >> 1), |
| 252 | .no_tuner = 1, |
| 253 | .disable_i2c_gate_ctrl = 1, |
| 254 | .parallel_ts = 1, |
| 255 | .if2 = 45600, |
| 256 | }; |
| 257 | |
Devin Heitmueller | 17d9d55 | 2008-06-08 10:22:03 -0300 | [diff] [blame] | 258 | #ifdef EM28XX_DRX397XD_SUPPORT |
| 259 | /* [TODO] djh - not sure yet what the device config needs to contain */ |
| 260 | static struct drx397xD_config em28xx_drx397xD_with_xc3028 = { |
| 261 | .demod_address = (0xe0 >> 1), |
| 262 | }; |
| 263 | #endif |
| 264 | |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 265 | static int mt352_terratec_xs_init(struct dvb_frontend *fe) |
| 266 | { |
| 267 | /* Values extracted from a USB trace of the Terratec Windows driver */ |
| 268 | static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c }; |
| 269 | static u8 reset[] = { RESET, 0x80 }; |
| 270 | static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 }; |
| 271 | static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 }; |
| 272 | static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 }; |
| 273 | static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d }; |
| 274 | static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 }; |
| 275 | static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 }; |
| 276 | static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 }; |
Devin Heitmueller | ff69786 | 2009-07-12 18:44:19 -0300 | [diff] [blame] | 277 | static u8 tuner_go[] = { TUNER_GO, 0x01}; |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 278 | |
| 279 | mt352_write(fe, clock_config, sizeof(clock_config)); |
| 280 | udelay(200); |
| 281 | mt352_write(fe, reset, sizeof(reset)); |
| 282 | mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg)); |
| 283 | mt352_write(fe, agc_cfg, sizeof(agc_cfg)); |
| 284 | mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg)); |
| 285 | mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg)); |
| 286 | mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg)); |
| 287 | mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg)); |
| 288 | mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg)); |
| 289 | mt352_write(fe, tuner_go, sizeof(tuner_go)); |
| 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | static struct mt352_config terratec_xs_mt352_cfg = { |
| 294 | .demod_address = (0x1e >> 1), |
| 295 | .no_tuner = 1, |
| 296 | .if2 = 45600, |
| 297 | .demod_init = mt352_terratec_xs_init, |
| 298 | }; |
| 299 | |
Antti Palosaari | 285eb1a | 2009-09-15 14:42:13 -0300 | [diff] [blame] | 300 | static struct tda10023_config em28xx_tda10023_config = { |
| 301 | .demod_address = 0x0c, |
| 302 | .invert = 1, |
| 303 | }; |
| 304 | |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 305 | /* ------------------------------------------------------------------ */ |
| 306 | |
| 307 | static int attach_xc3028(u8 addr, struct em28xx *dev) |
| 308 | { |
| 309 | struct dvb_frontend *fe; |
Mauro Carvalho Chehab | 3ca9c09 | 2008-04-17 21:37:53 -0300 | [diff] [blame] | 310 | struct xc2028_config cfg; |
| 311 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 312 | memset(&cfg, 0, sizeof(cfg)); |
Mauro Carvalho Chehab | 3ca9c09 | 2008-04-17 21:37:53 -0300 | [diff] [blame] | 313 | cfg.i2c_adap = &dev->i2c_adap; |
| 314 | cfg.i2c_addr = addr; |
Mauro Carvalho Chehab | 3ca9c09 | 2008-04-17 21:37:53 -0300 | [diff] [blame] | 315 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 316 | if (!dev->dvb->frontend) { |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 317 | em28xx_errdev("/2: dvb frontend not attached. " |
| 318 | "Can't attach xc3028\n"); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 319 | return -EINVAL; |
| 320 | } |
| 321 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 322 | fe = dvb_attach(xc2028_attach, dev->dvb->frontend, &cfg); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 323 | if (!fe) { |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 324 | em28xx_errdev("/2: xc3028 attach failed\n"); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 325 | dvb_frontend_detach(dev->dvb->frontend); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 326 | dev->dvb->frontend = NULL; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 327 | return -EINVAL; |
| 328 | } |
| 329 | |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 330 | em28xx_info("%s/2: xc3028 attached\n", dev->name); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 331 | |
| 332 | return 0; |
| 333 | } |
| 334 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 335 | /* ------------------------------------------------------------------ */ |
| 336 | |
Hans Verkuil | d45b9b8 | 2008-09-04 03:33:43 -0300 | [diff] [blame] | 337 | static int register_dvb(struct em28xx_dvb *dvb, |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 338 | struct module *module, |
| 339 | struct em28xx *dev, |
| 340 | struct device *device) |
| 341 | { |
| 342 | int result; |
| 343 | |
| 344 | mutex_init(&dvb->lock); |
| 345 | |
| 346 | /* register adapter */ |
| 347 | result = dvb_register_adapter(&dvb->adapter, dev->name, module, device, |
| 348 | adapter_nr); |
| 349 | if (result < 0) { |
| 350 | printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n", |
| 351 | dev->name, result); |
| 352 | goto fail_adapter; |
| 353 | } |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 354 | |
| 355 | /* Ensure all frontends negotiate bus access */ |
| 356 | dvb->frontend->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl; |
| 357 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 358 | dvb->adapter.priv = dev; |
| 359 | |
| 360 | /* register frontend */ |
| 361 | result = dvb_register_frontend(&dvb->adapter, dvb->frontend); |
| 362 | if (result < 0) { |
| 363 | printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n", |
| 364 | dev->name, result); |
| 365 | goto fail_frontend; |
| 366 | } |
| 367 | |
| 368 | /* register demux stuff */ |
| 369 | dvb->demux.dmx.capabilities = |
| 370 | DMX_TS_FILTERING | DMX_SECTION_FILTERING | |
| 371 | DMX_MEMORY_BASED_FILTERING; |
| 372 | dvb->demux.priv = dvb; |
| 373 | dvb->demux.filternum = 256; |
| 374 | dvb->demux.feednum = 256; |
| 375 | dvb->demux.start_feed = start_feed; |
| 376 | dvb->demux.stop_feed = stop_feed; |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 377 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 378 | result = dvb_dmx_init(&dvb->demux); |
| 379 | if (result < 0) { |
| 380 | printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n", |
| 381 | dev->name, result); |
| 382 | goto fail_dmx; |
| 383 | } |
| 384 | |
| 385 | dvb->dmxdev.filternum = 256; |
| 386 | dvb->dmxdev.demux = &dvb->demux.dmx; |
| 387 | dvb->dmxdev.capabilities = 0; |
| 388 | result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter); |
| 389 | if (result < 0) { |
| 390 | printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n", |
| 391 | dev->name, result); |
| 392 | goto fail_dmxdev; |
| 393 | } |
| 394 | |
| 395 | dvb->fe_hw.source = DMX_FRONTEND_0; |
| 396 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 397 | if (result < 0) { |
| 398 | printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n", |
| 399 | dev->name, result); |
| 400 | goto fail_fe_hw; |
| 401 | } |
| 402 | |
| 403 | dvb->fe_mem.source = DMX_MEMORY_FE; |
| 404 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 405 | if (result < 0) { |
| 406 | printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n", |
| 407 | dev->name, result); |
| 408 | goto fail_fe_mem; |
| 409 | } |
| 410 | |
| 411 | result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 412 | if (result < 0) { |
| 413 | printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n", |
| 414 | dev->name, result); |
| 415 | goto fail_fe_conn; |
| 416 | } |
| 417 | |
| 418 | /* register network adapter */ |
| 419 | dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx); |
| 420 | return 0; |
| 421 | |
| 422 | fail_fe_conn: |
| 423 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 424 | fail_fe_mem: |
| 425 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 426 | fail_fe_hw: |
| 427 | dvb_dmxdev_release(&dvb->dmxdev); |
| 428 | fail_dmxdev: |
| 429 | dvb_dmx_release(&dvb->demux); |
| 430 | fail_dmx: |
| 431 | dvb_unregister_frontend(dvb->frontend); |
| 432 | fail_frontend: |
| 433 | dvb_frontend_detach(dvb->frontend); |
| 434 | dvb_unregister_adapter(&dvb->adapter); |
| 435 | fail_adapter: |
| 436 | return result; |
| 437 | } |
| 438 | |
| 439 | static void unregister_dvb(struct em28xx_dvb *dvb) |
| 440 | { |
| 441 | dvb_net_release(&dvb->net); |
| 442 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 443 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 444 | dvb_dmxdev_release(&dvb->dmxdev); |
| 445 | dvb_dmx_release(&dvb->demux); |
| 446 | dvb_unregister_frontend(dvb->frontend); |
| 447 | dvb_frontend_detach(dvb->frontend); |
| 448 | dvb_unregister_adapter(&dvb->adapter); |
| 449 | } |
| 450 | |
| 451 | |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 452 | static int dvb_init(struct em28xx *dev) |
| 453 | { |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 454 | int result = 0; |
| 455 | struct em28xx_dvb *dvb; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 456 | |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 457 | if (!dev->board.has_dvb) { |
Devin Heitmueller | df61918 | 2008-06-10 12:34:35 -0300 | [diff] [blame] | 458 | /* This device does not support the extension */ |
| 459 | return 0; |
| 460 | } |
| 461 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 462 | dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 463 | |
| 464 | if (dvb == NULL) { |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 465 | em28xx_info("em28xx_dvb: memory allocation failed\n"); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 466 | return -ENOMEM; |
| 467 | } |
| 468 | dev->dvb = dvb; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 469 | |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 470 | em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 471 | /* init frontend */ |
| 472 | switch (dev->model) { |
Douglas Schilling Landgraf | f89bc32 | 2008-12-01 21:01:04 -0300 | [diff] [blame] | 473 | case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850: |
Mauro Carvalho Chehab | 10ac660 | 2008-07-27 14:58:58 -0300 | [diff] [blame] | 474 | case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950: |
Devin Heitmueller | 4fd305b | 2008-06-04 13:43:46 -0300 | [diff] [blame] | 475 | case EM2880_BOARD_PINNACLE_PCTV_HD_PRO: |
Devin Heitmueller | e14b365 | 2008-07-26 11:04:33 -0300 | [diff] [blame] | 476 | case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600: |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 477 | dvb->frontend = dvb_attach(lgdt330x_attach, |
| 478 | &em2880_lgdt3303_dev, |
| 479 | &dev->i2c_adap); |
| 480 | if (attach_xc3028(0x61, dev) < 0) { |
| 481 | result = -EINVAL; |
| 482 | goto out_free; |
| 483 | } |
Mauro Carvalho Chehab | 227ad4a | 2008-04-17 21:37:40 -0300 | [diff] [blame] | 484 | break; |
Thierry MERLE | 46510b5 | 2008-10-11 16:56:13 -0300 | [diff] [blame] | 485 | case EM2880_BOARD_KWORLD_DVB_310U: |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 486 | dvb->frontend = dvb_attach(zl10353_attach, |
| 487 | &em28xx_zl10353_with_xc3028, |
| 488 | &dev->i2c_adap); |
| 489 | if (attach_xc3028(0x61, dev) < 0) { |
| 490 | result = -EINVAL; |
| 491 | goto out_free; |
| 492 | } |
Aidan Thornton | 7e6388a | 2008-04-17 21:40:03 -0300 | [diff] [blame] | 493 | break; |
Devin Heitmueller | a84f79a | 2009-07-12 17:05:02 -0300 | [diff] [blame] | 494 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900: |
Uroš Vampl | ec994d0 | 2009-09-30 22:53:37 -0300 | [diff] [blame] | 495 | case EM2882_BOARD_TERRATEC_HYBRID_XS: |
Devin Heitmueller | 01a5fd6 | 2009-08-07 09:25:06 -0300 | [diff] [blame] | 496 | case EM2880_BOARD_EMPIRE_DUAL_TV: |
Devin Heitmueller | a84f79a | 2009-07-12 17:05:02 -0300 | [diff] [blame] | 497 | dvb->frontend = dvb_attach(zl10353_attach, |
| 498 | &em28xx_zl10353_xc3028_no_i2c_gate, |
| 499 | &dev->i2c_adap); |
| 500 | if (attach_xc3028(0x61, dev) < 0) { |
| 501 | result = -EINVAL; |
| 502 | goto out_free; |
| 503 | } |
| 504 | break; |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 505 | case EM2880_BOARD_TERRATEC_HYBRID_XS: |
Catimimi | 6563801 | 2010-02-18 18:06:32 -0300 | [diff] [blame] | 506 | case EM2880_BOARD_TERRATEC_HYBRID_XS_FR: |
Devin Heitmueller | d5b3ba9 | 2009-07-08 21:51:35 -0300 | [diff] [blame] | 507 | case EM2881_BOARD_PINNACLE_HYBRID_PRO: |
Andrea.Amorosi76@gmail.com | 7ca7ef6 | 2010-02-09 17:53:38 -0300 | [diff] [blame] | 508 | case EM2882_BOARD_DIKOM_DK300: |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 509 | dvb->frontend = dvb_attach(zl10353_attach, |
Devin Heitmueller | a84f79a | 2009-07-12 17:05:02 -0300 | [diff] [blame] | 510 | &em28xx_zl10353_xc3028_no_i2c_gate, |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 511 | &dev->i2c_adap); |
| 512 | if (dvb->frontend == NULL) { |
| 513 | /* This board could have either a zl10353 or a mt352. |
| 514 | If the chip id isn't for zl10353, try mt352 */ |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 515 | dvb->frontend = dvb_attach(mt352_attach, |
| 516 | &terratec_xs_mt352_cfg, |
| 517 | &dev->i2c_adap); |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 518 | } |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 519 | |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 520 | if (attach_xc3028(0x61, dev) < 0) { |
| 521 | result = -EINVAL; |
| 522 | goto out_free; |
| 523 | } |
| 524 | break; |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 525 | case EM2883_BOARD_KWORLD_HYBRID_330U: |
Devin Heitmueller | 1985922 | 2009-06-19 00:33:54 -0300 | [diff] [blame] | 526 | case EM2882_BOARD_EVGA_INDTUBE: |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 527 | dvb->frontend = dvb_attach(s5h1409_attach, |
| 528 | &em28xx_s5h1409_with_xc3028, |
| 529 | &dev->i2c_adap); |
| 530 | if (attach_xc3028(0x61, dev) < 0) { |
| 531 | result = -EINVAL; |
| 532 | goto out_free; |
| 533 | } |
| 534 | break; |
Franklin Meng | d7de5d8 | 2009-06-06 17:05:02 -0300 | [diff] [blame] | 535 | case EM2882_BOARD_KWORLD_ATSC_315U: |
| 536 | dvb->frontend = dvb_attach(lgdt330x_attach, |
| 537 | &em2880_lgdt3303_dev, |
| 538 | &dev->i2c_adap); |
| 539 | if (dvb->frontend != NULL) { |
| 540 | if (!dvb_attach(simple_tuner_attach, dvb->frontend, |
| 541 | &dev->i2c_adap, 0x61, TUNER_THOMSON_DTT761X)) { |
| 542 | result = -EINVAL; |
| 543 | goto out_free; |
| 544 | } |
| 545 | } |
| 546 | break; |
Devin Heitmueller | 17d9d55 | 2008-06-08 10:22:03 -0300 | [diff] [blame] | 547 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2: |
| 548 | #ifdef EM28XX_DRX397XD_SUPPORT |
| 549 | /* We don't have the config structure properly populated, so |
| 550 | this is commented out for now */ |
| 551 | dvb->frontend = dvb_attach(drx397xD_attach, |
| 552 | &em28xx_drx397xD_with_xc3028, |
| 553 | &dev->i2c_adap); |
| 554 | if (attach_xc3028(0x61, dev) < 0) { |
| 555 | result = -EINVAL; |
| 556 | goto out_free; |
| 557 | } |
| 558 | break; |
| 559 | #endif |
Antti Palosaari | 285eb1a | 2009-09-15 14:42:13 -0300 | [diff] [blame] | 560 | case EM2870_BOARD_REDDO_DVB_C_USB_BOX: |
| 561 | /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */ |
| 562 | dvb->frontend = dvb_attach(tda10023_attach, |
| 563 | &em28xx_tda10023_config, |
| 564 | &dev->i2c_adap, 0x48); |
| 565 | if (dvb->frontend) { |
| 566 | if (!dvb_attach(simple_tuner_attach, dvb->frontend, |
| 567 | &dev->i2c_adap, 0x60, TUNER_PHILIPS_CU1216L)) { |
| 568 | result = -EINVAL; |
| 569 | goto out_free; |
| 570 | } |
| 571 | } |
| 572 | break; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 573 | default: |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 574 | em28xx_errdev("/2: The frontend of your DVB/ATSC card" |
| 575 | " isn't supported yet\n"); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 576 | break; |
| 577 | } |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 578 | if (NULL == dvb->frontend) { |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 579 | em28xx_errdev("/2: frontend initialization failed\n"); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 580 | result = -EINVAL; |
| 581 | goto out_free; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 582 | } |
Michael Krufky | d7cba04 | 2008-09-12 13:31:45 -0300 | [diff] [blame] | 583 | /* define general-purpose callback pointer */ |
| 584 | dvb->frontend->callback = em28xx_tuner_callback; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 585 | |
| 586 | /* register everything */ |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 587 | result = register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev); |
| 588 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 589 | if (result < 0) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 590 | goto out_free; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 591 | |
Mauro Carvalho Chehab | 2fe3e2e | 2008-11-27 09:10:40 -0300 | [diff] [blame] | 592 | em28xx_set_mode(dev, EM28XX_SUSPEND); |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 593 | em28xx_info("Successfully loaded em28xx-dvb\n"); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 594 | return 0; |
| 595 | |
| 596 | out_free: |
Mauro Carvalho Chehab | 2fe3e2e | 2008-11-27 09:10:40 -0300 | [diff] [blame] | 597 | em28xx_set_mode(dev, EM28XX_SUSPEND); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 598 | kfree(dvb); |
| 599 | dev->dvb = NULL; |
| 600 | return result; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | static int dvb_fini(struct em28xx *dev) |
| 604 | { |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 605 | if (!dev->board.has_dvb) { |
Devin Heitmueller | df61918 | 2008-06-10 12:34:35 -0300 | [diff] [blame] | 606 | /* This device does not support the extension */ |
| 607 | return 0; |
| 608 | } |
| 609 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 610 | if (dev->dvb) { |
| 611 | unregister_dvb(dev->dvb); |
Francesco Lavra | 19f48cb | 2009-12-31 08:47:11 -0300 | [diff] [blame] | 612 | kfree(dev->dvb); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 613 | dev->dvb = NULL; |
| 614 | } |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 615 | |
| 616 | return 0; |
| 617 | } |
| 618 | |
| 619 | static struct em28xx_ops dvb_ops = { |
| 620 | .id = EM28XX_DVB, |
| 621 | .name = "Em28xx dvb Extension", |
| 622 | .init = dvb_init, |
| 623 | .fini = dvb_fini, |
| 624 | }; |
| 625 | |
| 626 | static int __init em28xx_dvb_register(void) |
| 627 | { |
| 628 | return em28xx_register_extension(&dvb_ops); |
| 629 | } |
| 630 | |
| 631 | static void __exit em28xx_dvb_unregister(void) |
| 632 | { |
| 633 | em28xx_unregister_extension(&dvb_ops); |
| 634 | } |
| 635 | |
| 636 | module_init(em28xx_dvb_register); |
| 637 | module_exit(em28xx_dvb_unregister); |