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" |
Jarod Wilson | 7e48b30 | 2010-03-07 17:55:43 -0300 | [diff] [blame] | 33 | #include "lgdt3305.h" |
Aidan Thornton | 7e6388a | 2008-04-17 21:40:03 -0300 | [diff] [blame] | 34 | #include "zl10353.h" |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 35 | #include "s5h1409.h" |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 36 | #include "mt352.h" |
| 37 | #include "mt352_priv.h" /* FIXME */ |
Antti Palosaari | 285eb1a | 2009-09-15 14:42:13 -0300 | [diff] [blame] | 38 | #include "tda1002x.h" |
Jarod Wilson | 7e48b30 | 2010-03-07 17:55:43 -0300 | [diff] [blame] | 39 | #include "tda18271.h" |
Mauro Carvalho Chehab | ca3dfd6 | 2010-09-10 17:29:14 -0300 | [diff] [blame] | 40 | #include "s921.h" |
Devin Heitmueller | 75e2b86 | 2011-03-13 02:01:02 -0300 | [diff] [blame] | 41 | #include "drxd.h" |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 42 | #include "cxd2820r.h" |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 43 | |
| 44 | MODULE_DESCRIPTION("driver for em28xx based DVB cards"); |
| 45 | MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); |
| 46 | MODULE_LICENSE("GPL"); |
| 47 | |
| 48 | static unsigned int debug; |
| 49 | module_param(debug, int, 0644); |
| 50 | MODULE_PARM_DESC(debug, "enable debug messages [dvb]"); |
| 51 | |
| 52 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 53 | |
| 54 | #define dprintk(level, fmt, arg...) do { \ |
| 55 | if (debug >= level) \ |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 56 | printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \ |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 57 | } while (0) |
| 58 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 59 | #define EM28XX_DVB_NUM_BUFS 5 |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 60 | #define EM28XX_DVB_MAX_PACKETS 64 |
| 61 | |
| 62 | struct em28xx_dvb { |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 63 | struct dvb_frontend *fe[2]; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 64 | |
| 65 | /* feed count management */ |
| 66 | struct mutex lock; |
| 67 | int nfeeds; |
| 68 | |
| 69 | /* general boilerplate stuff */ |
| 70 | struct dvb_adapter adapter; |
| 71 | struct dvb_demux demux; |
| 72 | struct dmxdev dmxdev; |
| 73 | struct dmx_frontend fe_hw; |
| 74 | struct dmx_frontend fe_mem; |
| 75 | struct dvb_net net; |
| 76 | }; |
| 77 | |
| 78 | |
| 79 | static inline void print_err_status(struct em28xx *dev, |
| 80 | int packet, int status) |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 81 | { |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 82 | char *errmsg = "Unknown"; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 83 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 84 | switch (status) { |
| 85 | case -ENOENT: |
| 86 | errmsg = "unlinked synchronuously"; |
| 87 | break; |
| 88 | case -ECONNRESET: |
| 89 | errmsg = "unlinked asynchronuously"; |
| 90 | break; |
| 91 | case -ENOSR: |
| 92 | errmsg = "Buffer error (overrun)"; |
| 93 | break; |
| 94 | case -EPIPE: |
| 95 | errmsg = "Stalled (device not responding)"; |
| 96 | break; |
| 97 | case -EOVERFLOW: |
| 98 | errmsg = "Babble (bad cable?)"; |
| 99 | break; |
| 100 | case -EPROTO: |
| 101 | errmsg = "Bit-stuff error (bad cable?)"; |
| 102 | break; |
| 103 | case -EILSEQ: |
| 104 | errmsg = "CRC/Timeout (could be anything)"; |
| 105 | break; |
| 106 | case -ETIME: |
| 107 | errmsg = "Device does not respond"; |
| 108 | break; |
| 109 | } |
| 110 | if (packet < 0) { |
| 111 | dprintk(1, "URB status %d [%s].\n", status, errmsg); |
| 112 | } else { |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 113 | dprintk(1, "URB packet %d, status %d [%s].\n", |
| 114 | packet, status, errmsg); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 115 | } |
| 116 | } |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 117 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 118 | static inline int dvb_isoc_copy(struct em28xx *dev, struct urb *urb) |
| 119 | { |
| 120 | int i; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 121 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 122 | if (!dev) |
| 123 | return 0; |
| 124 | |
| 125 | if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) |
| 126 | return 0; |
| 127 | |
| 128 | if (urb->status < 0) { |
| 129 | print_err_status(dev, -1, urb->status); |
| 130 | if (urb->status == -ENOENT) |
| 131 | return 0; |
| 132 | } |
| 133 | |
| 134 | for (i = 0; i < urb->number_of_packets; i++) { |
| 135 | int status = urb->iso_frame_desc[i].status; |
| 136 | |
| 137 | if (status < 0) { |
| 138 | print_err_status(dev, i, status); |
| 139 | if (urb->iso_frame_desc[i].status != -EPROTO) |
| 140 | continue; |
| 141 | } |
| 142 | |
| 143 | dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer + |
| 144 | urb->iso_frame_desc[i].offset, |
| 145 | urb->iso_frame_desc[i].actual_length); |
| 146 | } |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 151 | static int start_streaming(struct em28xx_dvb *dvb) |
| 152 | { |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 153 | int rc; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 154 | struct em28xx *dev = dvb->adapter.priv; |
Devin Heitmueller | d18e2fd | 2009-05-16 17:09:28 -0300 | [diff] [blame] | 155 | int max_dvb_packet_size; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 156 | |
| 157 | usb_set_interface(dev->udev, 0, 1); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 158 | rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); |
| 159 | if (rc < 0) |
| 160 | return rc; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 161 | |
Devin Heitmueller | d18e2fd | 2009-05-16 17:09:28 -0300 | [diff] [blame] | 162 | max_dvb_packet_size = em28xx_isoc_dvb_max_packetsize(dev); |
| 163 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 164 | return em28xx_init_isoc(dev, EM28XX_DVB_MAX_PACKETS, |
Devin Heitmueller | d18e2fd | 2009-05-16 17:09:28 -0300 | [diff] [blame] | 165 | EM28XX_DVB_NUM_BUFS, max_dvb_packet_size, |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 166 | dvb_isoc_copy); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 167 | } |
| 168 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 169 | static int stop_streaming(struct em28xx_dvb *dvb) |
| 170 | { |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 171 | struct em28xx *dev = dvb->adapter.priv; |
| 172 | |
| 173 | em28xx_uninit_isoc(dev); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 174 | |
Mauro Carvalho Chehab | 2fe3e2e | 2008-11-27 09:10:40 -0300 | [diff] [blame] | 175 | em28xx_set_mode(dev, EM28XX_SUSPEND); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 176 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | static int start_feed(struct dvb_demux_feed *feed) |
| 181 | { |
| 182 | struct dvb_demux *demux = feed->demux; |
| 183 | struct em28xx_dvb *dvb = demux->priv; |
| 184 | int rc, ret; |
| 185 | |
| 186 | if (!demux->dmx.frontend) |
| 187 | return -EINVAL; |
| 188 | |
| 189 | mutex_lock(&dvb->lock); |
| 190 | dvb->nfeeds++; |
| 191 | rc = dvb->nfeeds; |
| 192 | |
| 193 | if (dvb->nfeeds == 1) { |
| 194 | ret = start_streaming(dvb); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 195 | if (ret < 0) |
| 196 | rc = ret; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | mutex_unlock(&dvb->lock); |
| 200 | return rc; |
| 201 | } |
| 202 | |
| 203 | static int stop_feed(struct dvb_demux_feed *feed) |
| 204 | { |
| 205 | struct dvb_demux *demux = feed->demux; |
| 206 | struct em28xx_dvb *dvb = demux->priv; |
| 207 | int err = 0; |
| 208 | |
| 209 | mutex_lock(&dvb->lock); |
| 210 | dvb->nfeeds--; |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 211 | |
| 212 | if (0 == dvb->nfeeds) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 213 | err = stop_streaming(dvb); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 214 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 215 | mutex_unlock(&dvb->lock); |
| 216 | return err; |
| 217 | } |
| 218 | |
| 219 | |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 220 | |
| 221 | /* ------------------------------------------------------------------ */ |
| 222 | static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire) |
| 223 | { |
| 224 | struct em28xx *dev = fe->dvb->priv; |
| 225 | |
| 226 | if (acquire) |
| 227 | return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); |
| 228 | else |
Mauro Carvalho Chehab | 2fe3e2e | 2008-11-27 09:10:40 -0300 | [diff] [blame] | 229 | return em28xx_set_mode(dev, EM28XX_SUSPEND); |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 230 | } |
| 231 | |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 232 | /* ------------------------------------------------------------------ */ |
| 233 | |
Mauro Carvalho Chehab | 227ad4a | 2008-04-17 21:37:40 -0300 | [diff] [blame] | 234 | static struct lgdt330x_config em2880_lgdt3303_dev = { |
| 235 | .demod_address = 0x0e, |
| 236 | .demod_chip = LGDT3303, |
| 237 | }; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 238 | |
Jarod Wilson | 7e48b30 | 2010-03-07 17:55:43 -0300 | [diff] [blame] | 239 | static struct lgdt3305_config em2870_lgdt3304_dev = { |
| 240 | .i2c_addr = 0x0e, |
| 241 | .demod_chip = LGDT3304, |
| 242 | .spectral_inversion = 1, |
| 243 | .deny_i2c_rptr = 1, |
| 244 | .mpeg_mode = LGDT3305_MPEG_PARALLEL, |
| 245 | .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE, |
| 246 | .tpvalid_polarity = LGDT3305_TP_VALID_HIGH, |
| 247 | .vsb_if_khz = 3250, |
| 248 | .qam_if_khz = 4000, |
| 249 | }; |
| 250 | |
Mauro Carvalho Chehab | ca3dfd6 | 2010-09-10 17:29:14 -0300 | [diff] [blame] | 251 | static struct s921_config sharp_isdbt = { |
| 252 | .demod_address = 0x30 >> 1 |
| 253 | }; |
| 254 | |
Aidan Thornton | 7e6388a | 2008-04-17 21:40:03 -0300 | [diff] [blame] | 255 | static struct zl10353_config em28xx_zl10353_with_xc3028 = { |
| 256 | .demod_address = (0x1e >> 1), |
| 257 | .no_tuner = 1, |
| 258 | .parallel_ts = 1, |
| 259 | .if2 = 45600, |
| 260 | }; |
| 261 | |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 262 | static struct s5h1409_config em28xx_s5h1409_with_xc3028 = { |
| 263 | .demod_address = 0x32 >> 1, |
| 264 | .output_mode = S5H1409_PARALLEL_OUTPUT, |
| 265 | .gpio = S5H1409_GPIO_OFF, |
| 266 | .inversion = S5H1409_INVERSION_OFF, |
| 267 | .status_mode = S5H1409_DEMODLOCKING, |
| 268 | .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK |
| 269 | }; |
| 270 | |
Jarod Wilson | 7e48b30 | 2010-03-07 17:55:43 -0300 | [diff] [blame] | 271 | static struct tda18271_std_map kworld_a340_std_map = { |
| 272 | .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0, |
| 273 | .if_lvl = 1, .rfagc_top = 0x37, }, |
| 274 | .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1, |
| 275 | .if_lvl = 1, .rfagc_top = 0x37, }, |
| 276 | }; |
| 277 | |
| 278 | static struct tda18271_config kworld_a340_config = { |
| 279 | .std_map = &kworld_a340_std_map, |
| 280 | }; |
| 281 | |
Devin Heitmueller | a84f79a | 2009-07-12 17:05:02 -0300 | [diff] [blame] | 282 | static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = { |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 283 | .demod_address = (0x1e >> 1), |
| 284 | .no_tuner = 1, |
| 285 | .disable_i2c_gate_ctrl = 1, |
| 286 | .parallel_ts = 1, |
| 287 | .if2 = 45600, |
| 288 | }; |
| 289 | |
Devin Heitmueller | 75e2b86 | 2011-03-13 02:01:02 -0300 | [diff] [blame] | 290 | static struct drxd_config em28xx_drxd = { |
| 291 | .index = 0, .demod_address = 0x70, .demod_revision = 0xa2, |
| 292 | .demoda_address = 0x00, .pll_address = 0x00, |
| 293 | .pll_type = DRXD_PLL_NONE, .clock = 12000, .insert_rs_byte = 1, |
| 294 | .pll_set = NULL, .osc_deviation = NULL, .IF = 42800000, |
Devin Heitmueller | 6b142b3 | 2011-03-13 02:02:01 -0300 | [diff] [blame] | 295 | .disable_i2c_gate_ctrl = 1, |
Devin Heitmueller | 17d9d55 | 2008-06-08 10:22:03 -0300 | [diff] [blame] | 296 | }; |
Devin Heitmueller | 17d9d55 | 2008-06-08 10:22:03 -0300 | [diff] [blame] | 297 | |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 298 | static int mt352_terratec_xs_init(struct dvb_frontend *fe) |
| 299 | { |
| 300 | /* Values extracted from a USB trace of the Terratec Windows driver */ |
| 301 | static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c }; |
| 302 | static u8 reset[] = { RESET, 0x80 }; |
| 303 | static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 }; |
| 304 | static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 }; |
| 305 | static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 }; |
| 306 | static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d }; |
| 307 | static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 }; |
| 308 | static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 }; |
| 309 | static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 }; |
Devin Heitmueller | ff69786 | 2009-07-12 18:44:19 -0300 | [diff] [blame] | 310 | static u8 tuner_go[] = { TUNER_GO, 0x01}; |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 311 | |
| 312 | mt352_write(fe, clock_config, sizeof(clock_config)); |
| 313 | udelay(200); |
| 314 | mt352_write(fe, reset, sizeof(reset)); |
| 315 | mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg)); |
| 316 | mt352_write(fe, agc_cfg, sizeof(agc_cfg)); |
| 317 | mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg)); |
| 318 | mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg)); |
| 319 | mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg)); |
| 320 | mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg)); |
| 321 | mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg)); |
| 322 | mt352_write(fe, tuner_go, sizeof(tuner_go)); |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | static struct mt352_config terratec_xs_mt352_cfg = { |
| 327 | .demod_address = (0x1e >> 1), |
| 328 | .no_tuner = 1, |
| 329 | .if2 = 45600, |
| 330 | .demod_init = mt352_terratec_xs_init, |
| 331 | }; |
| 332 | |
Antti Palosaari | 285eb1a | 2009-09-15 14:42:13 -0300 | [diff] [blame] | 333 | static struct tda10023_config em28xx_tda10023_config = { |
| 334 | .demod_address = 0x0c, |
| 335 | .invert = 1, |
| 336 | }; |
| 337 | |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 338 | static struct cxd2820r_config em28xx_cxd2820r_config = { |
| 339 | .i2c_address = (0xd8 >> 1), |
| 340 | .ts_mode = CXD2820R_TS_SERIAL, |
| 341 | .if_dvbt_6 = 3300, |
| 342 | .if_dvbt_7 = 3500, |
| 343 | .if_dvbt_8 = 4000, |
| 344 | .if_dvbt2_6 = 3300, |
| 345 | .if_dvbt2_7 = 3500, |
| 346 | .if_dvbt2_8 = 4000, |
| 347 | .if_dvbc = 5000, |
| 348 | |
| 349 | /* enable LNA for DVB-T2 and DVB-C */ |
| 350 | .gpio_dvbt2[0] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | CXD2820R_GPIO_L, |
| 351 | .gpio_dvbc[0] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | CXD2820R_GPIO_L, |
| 352 | }; |
| 353 | |
| 354 | static struct tda18271_config em28xx_cxd2820r_tda18271_config = { |
| 355 | .output_opt = TDA18271_OUTPUT_LT_OFF, |
| 356 | }; |
| 357 | |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 358 | /* ------------------------------------------------------------------ */ |
| 359 | |
| 360 | static int attach_xc3028(u8 addr, struct em28xx *dev) |
| 361 | { |
| 362 | struct dvb_frontend *fe; |
Mauro Carvalho Chehab | 3ca9c09 | 2008-04-17 21:37:53 -0300 | [diff] [blame] | 363 | struct xc2028_config cfg; |
| 364 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 365 | memset(&cfg, 0, sizeof(cfg)); |
Mauro Carvalho Chehab | 3ca9c09 | 2008-04-17 21:37:53 -0300 | [diff] [blame] | 366 | cfg.i2c_adap = &dev->i2c_adap; |
| 367 | cfg.i2c_addr = addr; |
Mauro Carvalho Chehab | 3ca9c09 | 2008-04-17 21:37:53 -0300 | [diff] [blame] | 368 | |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 369 | if (!dev->dvb->fe[0]) { |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 370 | em28xx_errdev("/2: dvb frontend not attached. " |
| 371 | "Can't attach xc3028\n"); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 372 | return -EINVAL; |
| 373 | } |
| 374 | |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 375 | fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 376 | if (!fe) { |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 377 | em28xx_errdev("/2: xc3028 attach failed\n"); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 378 | dvb_frontend_detach(dev->dvb->fe[0]); |
| 379 | dev->dvb->fe[0] = NULL; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 380 | return -EINVAL; |
| 381 | } |
| 382 | |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 383 | em28xx_info("%s/2: xc3028 attached\n", dev->name); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 384 | |
| 385 | return 0; |
| 386 | } |
| 387 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 388 | /* ------------------------------------------------------------------ */ |
| 389 | |
Hans Verkuil | d45b9b8 | 2008-09-04 03:33:43 -0300 | [diff] [blame] | 390 | static int register_dvb(struct em28xx_dvb *dvb, |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 391 | struct module *module, |
| 392 | struct em28xx *dev, |
| 393 | struct device *device) |
| 394 | { |
| 395 | int result; |
| 396 | |
| 397 | mutex_init(&dvb->lock); |
| 398 | |
| 399 | /* register adapter */ |
| 400 | result = dvb_register_adapter(&dvb->adapter, dev->name, module, device, |
| 401 | adapter_nr); |
| 402 | if (result < 0) { |
| 403 | printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n", |
| 404 | dev->name, result); |
| 405 | goto fail_adapter; |
| 406 | } |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 407 | |
| 408 | /* Ensure all frontends negotiate bus access */ |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 409 | dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl; |
| 410 | if (dvb->fe[1]) |
| 411 | dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl; |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 412 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 413 | dvb->adapter.priv = dev; |
| 414 | |
| 415 | /* register frontend */ |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 416 | result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 417 | if (result < 0) { |
| 418 | printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n", |
| 419 | dev->name, result); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 420 | goto fail_frontend0; |
| 421 | } |
| 422 | |
| 423 | /* register 2nd frontend */ |
| 424 | if (dvb->fe[1]) { |
| 425 | result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]); |
| 426 | if (result < 0) { |
| 427 | printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n", |
| 428 | dev->name, result); |
| 429 | goto fail_frontend1; |
| 430 | } |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | /* register demux stuff */ |
| 434 | dvb->demux.dmx.capabilities = |
| 435 | DMX_TS_FILTERING | DMX_SECTION_FILTERING | |
| 436 | DMX_MEMORY_BASED_FILTERING; |
| 437 | dvb->demux.priv = dvb; |
| 438 | dvb->demux.filternum = 256; |
| 439 | dvb->demux.feednum = 256; |
| 440 | dvb->demux.start_feed = start_feed; |
| 441 | dvb->demux.stop_feed = stop_feed; |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 442 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 443 | result = dvb_dmx_init(&dvb->demux); |
| 444 | if (result < 0) { |
| 445 | printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n", |
| 446 | dev->name, result); |
| 447 | goto fail_dmx; |
| 448 | } |
| 449 | |
| 450 | dvb->dmxdev.filternum = 256; |
| 451 | dvb->dmxdev.demux = &dvb->demux.dmx; |
| 452 | dvb->dmxdev.capabilities = 0; |
| 453 | result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter); |
| 454 | if (result < 0) { |
| 455 | printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n", |
| 456 | dev->name, result); |
| 457 | goto fail_dmxdev; |
| 458 | } |
| 459 | |
| 460 | dvb->fe_hw.source = DMX_FRONTEND_0; |
| 461 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 462 | if (result < 0) { |
| 463 | printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n", |
| 464 | dev->name, result); |
| 465 | goto fail_fe_hw; |
| 466 | } |
| 467 | |
| 468 | dvb->fe_mem.source = DMX_MEMORY_FE; |
| 469 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 470 | if (result < 0) { |
| 471 | printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n", |
| 472 | dev->name, result); |
| 473 | goto fail_fe_mem; |
| 474 | } |
| 475 | |
| 476 | result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 477 | if (result < 0) { |
| 478 | printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n", |
| 479 | dev->name, result); |
| 480 | goto fail_fe_conn; |
| 481 | } |
| 482 | |
| 483 | /* register network adapter */ |
| 484 | dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx); |
| 485 | return 0; |
| 486 | |
| 487 | fail_fe_conn: |
| 488 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 489 | fail_fe_mem: |
| 490 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 491 | fail_fe_hw: |
| 492 | dvb_dmxdev_release(&dvb->dmxdev); |
| 493 | fail_dmxdev: |
| 494 | dvb_dmx_release(&dvb->demux); |
| 495 | fail_dmx: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 496 | if (dvb->fe[1]) |
| 497 | dvb_unregister_frontend(dvb->fe[1]); |
| 498 | dvb_unregister_frontend(dvb->fe[0]); |
| 499 | fail_frontend1: |
| 500 | if (dvb->fe[1]) |
| 501 | dvb_frontend_detach(dvb->fe[1]); |
| 502 | fail_frontend0: |
| 503 | dvb_frontend_detach(dvb->fe[0]); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 504 | dvb_unregister_adapter(&dvb->adapter); |
| 505 | fail_adapter: |
| 506 | return result; |
| 507 | } |
| 508 | |
| 509 | static void unregister_dvb(struct em28xx_dvb *dvb) |
| 510 | { |
| 511 | dvb_net_release(&dvb->net); |
| 512 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 513 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 514 | dvb_dmxdev_release(&dvb->dmxdev); |
| 515 | dvb_dmx_release(&dvb->demux); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 516 | if (dvb->fe[1]) |
| 517 | dvb_unregister_frontend(dvb->fe[1]); |
| 518 | dvb_unregister_frontend(dvb->fe[0]); |
| 519 | if (dvb->fe[1]) |
| 520 | dvb_frontend_detach(dvb->fe[1]); |
| 521 | dvb_frontend_detach(dvb->fe[0]); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 522 | dvb_unregister_adapter(&dvb->adapter); |
| 523 | } |
| 524 | |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 525 | static int dvb_init(struct em28xx *dev) |
| 526 | { |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 527 | int result = 0; |
| 528 | struct em28xx_dvb *dvb; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 529 | |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 530 | if (!dev->board.has_dvb) { |
Devin Heitmueller | df61918 | 2008-06-10 12:34:35 -0300 | [diff] [blame] | 531 | /* This device does not support the extension */ |
Mauro Carvalho Chehab | ca3dfd6 | 2010-09-10 17:29:14 -0300 | [diff] [blame] | 532 | printk(KERN_INFO "em28xx_dvb: This device does not support the extension\n"); |
Devin Heitmueller | df61918 | 2008-06-10 12:34:35 -0300 | [diff] [blame] | 533 | return 0; |
| 534 | } |
| 535 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 536 | dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 537 | |
| 538 | if (dvb == NULL) { |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 539 | em28xx_info("em28xx_dvb: memory allocation failed\n"); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 540 | return -ENOMEM; |
| 541 | } |
| 542 | dev->dvb = dvb; |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 543 | dvb->fe[0] = dvb->fe[1] = NULL; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 544 | |
Mauro Carvalho Chehab | 5013318 | 2010-04-07 17:07:58 -0300 | [diff] [blame] | 545 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 546 | em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 547 | /* init frontend */ |
| 548 | switch (dev->model) { |
Mauro Carvalho Chehab | ebaefdb | 2011-06-01 10:16:25 -0300 | [diff] [blame^] | 549 | case EM2874_BOARD_LEADERSHIP_ISDBT: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 550 | dvb->fe[0] = dvb_attach(s921_attach, |
Mauro Carvalho Chehab | ca3dfd6 | 2010-09-10 17:29:14 -0300 | [diff] [blame] | 551 | &sharp_isdbt, &dev->i2c_adap); |
| 552 | |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 553 | if (!dvb->fe[0]) { |
Mauro Carvalho Chehab | ca3dfd6 | 2010-09-10 17:29:14 -0300 | [diff] [blame] | 554 | result = -EINVAL; |
| 555 | goto out_free; |
| 556 | } |
| 557 | |
| 558 | break; |
Douglas Schilling Landgraf | f89bc32 | 2008-12-01 21:01:04 -0300 | [diff] [blame] | 559 | case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850: |
Mauro Carvalho Chehab | 10ac660 | 2008-07-27 14:58:58 -0300 | [diff] [blame] | 560 | case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950: |
Devin Heitmueller | 4fd305b | 2008-06-04 13:43:46 -0300 | [diff] [blame] | 561 | case EM2880_BOARD_PINNACLE_PCTV_HD_PRO: |
Devin Heitmueller | e14b365 | 2008-07-26 11:04:33 -0300 | [diff] [blame] | 562 | case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 563 | dvb->fe[0] = dvb_attach(lgdt330x_attach, |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 564 | &em2880_lgdt3303_dev, |
| 565 | &dev->i2c_adap); |
| 566 | if (attach_xc3028(0x61, dev) < 0) { |
| 567 | result = -EINVAL; |
| 568 | goto out_free; |
| 569 | } |
Mauro Carvalho Chehab | 227ad4a | 2008-04-17 21:37:40 -0300 | [diff] [blame] | 570 | break; |
Thierry MERLE | 46510b5 | 2008-10-11 16:56:13 -0300 | [diff] [blame] | 571 | case EM2880_BOARD_KWORLD_DVB_310U: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 572 | dvb->fe[0] = dvb_attach(zl10353_attach, |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 573 | &em28xx_zl10353_with_xc3028, |
| 574 | &dev->i2c_adap); |
| 575 | if (attach_xc3028(0x61, dev) < 0) { |
| 576 | result = -EINVAL; |
| 577 | goto out_free; |
| 578 | } |
Aidan Thornton | 7e6388a | 2008-04-17 21:40:03 -0300 | [diff] [blame] | 579 | break; |
Devin Heitmueller | a84f79a | 2009-07-12 17:05:02 -0300 | [diff] [blame] | 580 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900: |
Uroš Vampl | ec994d0 | 2009-09-30 22:53:37 -0300 | [diff] [blame] | 581 | case EM2882_BOARD_TERRATEC_HYBRID_XS: |
Devin Heitmueller | 01a5fd6 | 2009-08-07 09:25:06 -0300 | [diff] [blame] | 582 | case EM2880_BOARD_EMPIRE_DUAL_TV: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 583 | dvb->fe[0] = dvb_attach(zl10353_attach, |
Devin Heitmueller | a84f79a | 2009-07-12 17:05:02 -0300 | [diff] [blame] | 584 | &em28xx_zl10353_xc3028_no_i2c_gate, |
| 585 | &dev->i2c_adap); |
| 586 | if (attach_xc3028(0x61, dev) < 0) { |
| 587 | result = -EINVAL; |
| 588 | goto out_free; |
| 589 | } |
| 590 | break; |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 591 | case EM2880_BOARD_TERRATEC_HYBRID_XS: |
Catimimi | 6563801 | 2010-02-18 18:06:32 -0300 | [diff] [blame] | 592 | case EM2880_BOARD_TERRATEC_HYBRID_XS_FR: |
Devin Heitmueller | d5b3ba9 | 2009-07-08 21:51:35 -0300 | [diff] [blame] | 593 | case EM2881_BOARD_PINNACLE_HYBRID_PRO: |
Andrea.Amorosi76@gmail.com | 7ca7ef6 | 2010-02-09 17:53:38 -0300 | [diff] [blame] | 594 | case EM2882_BOARD_DIKOM_DK300: |
Antonio Larrosa | 811fab6 | 2010-03-04 22:19:48 -0300 | [diff] [blame] | 595 | case EM2882_BOARD_KWORLD_VS_DVBT: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 596 | dvb->fe[0] = dvb_attach(zl10353_attach, |
Devin Heitmueller | a84f79a | 2009-07-12 17:05:02 -0300 | [diff] [blame] | 597 | &em28xx_zl10353_xc3028_no_i2c_gate, |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 598 | &dev->i2c_adap); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 599 | if (dvb->fe[0] == NULL) { |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 600 | /* This board could have either a zl10353 or a mt352. |
| 601 | If the chip id isn't for zl10353, try mt352 */ |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 602 | dvb->fe[0] = dvb_attach(mt352_attach, |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 603 | &terratec_xs_mt352_cfg, |
| 604 | &dev->i2c_adap); |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 605 | } |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 606 | |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 607 | if (attach_xc3028(0x61, dev) < 0) { |
| 608 | result = -EINVAL; |
| 609 | goto out_free; |
| 610 | } |
| 611 | break; |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 612 | case EM2883_BOARD_KWORLD_HYBRID_330U: |
Devin Heitmueller | 1985922 | 2009-06-19 00:33:54 -0300 | [diff] [blame] | 613 | case EM2882_BOARD_EVGA_INDTUBE: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 614 | dvb->fe[0] = dvb_attach(s5h1409_attach, |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 615 | &em28xx_s5h1409_with_xc3028, |
| 616 | &dev->i2c_adap); |
| 617 | if (attach_xc3028(0x61, dev) < 0) { |
| 618 | result = -EINVAL; |
| 619 | goto out_free; |
| 620 | } |
| 621 | break; |
Franklin Meng | d7de5d8 | 2009-06-06 17:05:02 -0300 | [diff] [blame] | 622 | case EM2882_BOARD_KWORLD_ATSC_315U: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 623 | dvb->fe[0] = dvb_attach(lgdt330x_attach, |
Franklin Meng | d7de5d8 | 2009-06-06 17:05:02 -0300 | [diff] [blame] | 624 | &em2880_lgdt3303_dev, |
| 625 | &dev->i2c_adap); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 626 | if (dvb->fe[0] != NULL) { |
| 627 | if (!dvb_attach(simple_tuner_attach, dvb->fe[0], |
Franklin Meng | d7de5d8 | 2009-06-06 17:05:02 -0300 | [diff] [blame] | 628 | &dev->i2c_adap, 0x61, TUNER_THOMSON_DTT761X)) { |
| 629 | result = -EINVAL; |
| 630 | goto out_free; |
| 631 | } |
| 632 | } |
| 633 | break; |
Devin Heitmueller | 17d9d55 | 2008-06-08 10:22:03 -0300 | [diff] [blame] | 634 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2: |
Devin Heitmueller | ad9b4bb | 2011-03-13 02:09:59 -0300 | [diff] [blame] | 635 | case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 636 | dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL, |
Devin Heitmueller | 75e2b86 | 2011-03-13 02:01:02 -0300 | [diff] [blame] | 637 | &dev->i2c_adap, &dev->udev->dev); |
Devin Heitmueller | 17d9d55 | 2008-06-08 10:22:03 -0300 | [diff] [blame] | 638 | if (attach_xc3028(0x61, dev) < 0) { |
| 639 | result = -EINVAL; |
| 640 | goto out_free; |
| 641 | } |
| 642 | break; |
Antti Palosaari | 285eb1a | 2009-09-15 14:42:13 -0300 | [diff] [blame] | 643 | case EM2870_BOARD_REDDO_DVB_C_USB_BOX: |
| 644 | /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */ |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 645 | dvb->fe[0] = dvb_attach(tda10023_attach, |
Antti Palosaari | 285eb1a | 2009-09-15 14:42:13 -0300 | [diff] [blame] | 646 | &em28xx_tda10023_config, |
| 647 | &dev->i2c_adap, 0x48); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 648 | if (dvb->fe[0]) { |
| 649 | if (!dvb_attach(simple_tuner_attach, dvb->fe[0], |
Antti Palosaari | 285eb1a | 2009-09-15 14:42:13 -0300 | [diff] [blame] | 650 | &dev->i2c_adap, 0x60, TUNER_PHILIPS_CU1216L)) { |
| 651 | result = -EINVAL; |
| 652 | goto out_free; |
| 653 | } |
| 654 | } |
| 655 | break; |
Jarod Wilson | 7e48b30 | 2010-03-07 17:55:43 -0300 | [diff] [blame] | 656 | case EM2870_BOARD_KWORLD_A340: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 657 | dvb->fe[0] = dvb_attach(lgdt3305_attach, |
Jarod Wilson | 7e48b30 | 2010-03-07 17:55:43 -0300 | [diff] [blame] | 658 | &em2870_lgdt3304_dev, |
| 659 | &dev->i2c_adap); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 660 | if (dvb->fe[0] != NULL) |
| 661 | dvb_attach(tda18271_attach, dvb->fe[0], 0x60, |
Jarod Wilson | 7e48b30 | 2010-03-07 17:55:43 -0300 | [diff] [blame] | 662 | &dev->i2c_adap, &kworld_a340_config); |
| 663 | break; |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 664 | case EM28174_BOARD_PCTV_290E: |
| 665 | /* MFE |
| 666 | * FE 0 = DVB-T/T2 + FE 1 = DVB-C, both sharing same tuner. */ |
| 667 | /* FE 0 */ |
| 668 | dvb->fe[0] = dvb_attach(cxd2820r_attach, |
| 669 | &em28xx_cxd2820r_config, &dev->i2c_adap, NULL); |
| 670 | if (dvb->fe[0]) { |
| 671 | struct i2c_adapter *i2c_tuner; |
| 672 | i2c_tuner = cxd2820r_get_tuner_i2c_adapter(dvb->fe[0]); |
| 673 | /* FE 0 attach tuner */ |
| 674 | if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60, |
| 675 | i2c_tuner, &em28xx_cxd2820r_tda18271_config)) { |
| 676 | dvb_frontend_detach(dvb->fe[0]); |
| 677 | result = -EINVAL; |
| 678 | goto out_free; |
| 679 | } |
| 680 | /* FE 1. This dvb_attach() cannot fail. */ |
| 681 | dvb->fe[1] = dvb_attach(cxd2820r_attach, NULL, NULL, |
| 682 | dvb->fe[0]); |
| 683 | dvb->fe[1]->id = 1; |
| 684 | /* FE 1 attach tuner */ |
| 685 | if (!dvb_attach(tda18271_attach, dvb->fe[1], 0x60, |
| 686 | i2c_tuner, &em28xx_cxd2820r_tda18271_config)) { |
| 687 | dvb_frontend_detach(dvb->fe[1]); |
| 688 | /* leave FE 0 still active */ |
| 689 | } |
| 690 | } |
| 691 | break; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 692 | default: |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 693 | em28xx_errdev("/2: The frontend of your DVB/ATSC card" |
| 694 | " isn't supported yet\n"); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 695 | break; |
| 696 | } |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 697 | if (NULL == dvb->fe[0]) { |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 698 | em28xx_errdev("/2: frontend initialization failed\n"); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 699 | result = -EINVAL; |
| 700 | goto out_free; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 701 | } |
Michael Krufky | d7cba04 | 2008-09-12 13:31:45 -0300 | [diff] [blame] | 702 | /* define general-purpose callback pointer */ |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 703 | dvb->fe[0]->callback = em28xx_tuner_callback; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 704 | |
| 705 | /* register everything */ |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 706 | result = register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev); |
| 707 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 708 | if (result < 0) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 709 | goto out_free; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 710 | |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 711 | em28xx_info("Successfully loaded em28xx-dvb\n"); |
Mauro Carvalho Chehab | 5013318 | 2010-04-07 17:07:58 -0300 | [diff] [blame] | 712 | ret: |
| 713 | em28xx_set_mode(dev, EM28XX_SUSPEND); |
| 714 | mutex_unlock(&dev->lock); |
| 715 | return result; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 716 | |
| 717 | out_free: |
| 718 | kfree(dvb); |
| 719 | dev->dvb = NULL; |
Mauro Carvalho Chehab | 5013318 | 2010-04-07 17:07:58 -0300 | [diff] [blame] | 720 | goto ret; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | static int dvb_fini(struct em28xx *dev) |
| 724 | { |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 725 | if (!dev->board.has_dvb) { |
Devin Heitmueller | df61918 | 2008-06-10 12:34:35 -0300 | [diff] [blame] | 726 | /* This device does not support the extension */ |
| 727 | return 0; |
| 728 | } |
| 729 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 730 | if (dev->dvb) { |
| 731 | unregister_dvb(dev->dvb); |
Francesco Lavra | 19f48cb | 2009-12-31 08:47:11 -0300 | [diff] [blame] | 732 | kfree(dev->dvb); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 733 | dev->dvb = NULL; |
| 734 | } |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 735 | |
| 736 | return 0; |
| 737 | } |
| 738 | |
| 739 | static struct em28xx_ops dvb_ops = { |
| 740 | .id = EM28XX_DVB, |
| 741 | .name = "Em28xx dvb Extension", |
| 742 | .init = dvb_init, |
| 743 | .fini = dvb_fini, |
| 744 | }; |
| 745 | |
| 746 | static int __init em28xx_dvb_register(void) |
| 747 | { |
| 748 | return em28xx_register_extension(&dvb_ops); |
| 749 | } |
| 750 | |
| 751 | static void __exit em28xx_dvb_unregister(void) |
| 752 | { |
| 753 | em28xx_unregister_extension(&dvb_ops); |
| 754 | } |
| 755 | |
| 756 | module_init(em28xx_dvb_register); |
| 757 | module_exit(em28xx_dvb_unregister); |