Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 1 | /* |
| 2 | DVB device driver for em28xx |
| 3 | |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 4 | (c) 2008-2011 Mauro Carvalho Chehab <mchehab@infradead.org> |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 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 | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 43 | #include "tda18271c2dd.h" |
| 44 | #include "drxk.h" |
Antti Palosaari | 3658871 | 2011-08-01 01:15:30 -0300 | [diff] [blame] | 45 | #include "tda10071.h" |
| 46 | #include "a8293.h" |
Aivar Päkk | 1985f6f | 2011-12-11 18:15:00 -0300 | [diff] [blame] | 47 | #include "qt1010.h" |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 48 | |
| 49 | MODULE_DESCRIPTION("driver for em28xx based DVB cards"); |
| 50 | MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); |
| 51 | MODULE_LICENSE("GPL"); |
| 52 | |
| 53 | static unsigned int debug; |
| 54 | module_param(debug, int, 0644); |
| 55 | MODULE_PARM_DESC(debug, "enable debug messages [dvb]"); |
| 56 | |
| 57 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 58 | |
| 59 | #define dprintk(level, fmt, arg...) do { \ |
| 60 | if (debug >= level) \ |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 61 | printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \ |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 62 | } while (0) |
| 63 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 64 | #define EM28XX_DVB_NUM_BUFS 5 |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 65 | #define EM28XX_DVB_MAX_PACKETS 64 |
| 66 | |
| 67 | struct em28xx_dvb { |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 68 | struct dvb_frontend *fe[2]; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 69 | |
| 70 | /* feed count management */ |
| 71 | struct mutex lock; |
| 72 | int nfeeds; |
| 73 | |
| 74 | /* general boilerplate stuff */ |
| 75 | struct dvb_adapter adapter; |
| 76 | struct dvb_demux demux; |
| 77 | struct dmxdev dmxdev; |
| 78 | struct dmx_frontend fe_hw; |
| 79 | struct dmx_frontend fe_mem; |
| 80 | struct dvb_net net; |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 81 | |
Mauro Carvalho Chehab | c4c3a3d | 2011-07-14 22:23:18 -0300 | [diff] [blame] | 82 | /* Due to DRX-K - probably need changes */ |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 83 | int (*gate_ctrl)(struct dvb_frontend *, int); |
| 84 | struct semaphore pll_mutex; |
Mauro Carvalho Chehab | c4c3a3d | 2011-07-14 22:23:18 -0300 | [diff] [blame] | 85 | bool dont_attach_fe1; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 86 | }; |
| 87 | |
| 88 | |
| 89 | static inline void print_err_status(struct em28xx *dev, |
| 90 | int packet, int status) |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 91 | { |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 92 | char *errmsg = "Unknown"; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 93 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 94 | switch (status) { |
| 95 | case -ENOENT: |
| 96 | errmsg = "unlinked synchronuously"; |
| 97 | break; |
| 98 | case -ECONNRESET: |
| 99 | errmsg = "unlinked asynchronuously"; |
| 100 | break; |
| 101 | case -ENOSR: |
| 102 | errmsg = "Buffer error (overrun)"; |
| 103 | break; |
| 104 | case -EPIPE: |
| 105 | errmsg = "Stalled (device not responding)"; |
| 106 | break; |
| 107 | case -EOVERFLOW: |
| 108 | errmsg = "Babble (bad cable?)"; |
| 109 | break; |
| 110 | case -EPROTO: |
| 111 | errmsg = "Bit-stuff error (bad cable?)"; |
| 112 | break; |
| 113 | case -EILSEQ: |
| 114 | errmsg = "CRC/Timeout (could be anything)"; |
| 115 | break; |
| 116 | case -ETIME: |
| 117 | errmsg = "Device does not respond"; |
| 118 | break; |
| 119 | } |
| 120 | if (packet < 0) { |
| 121 | dprintk(1, "URB status %d [%s].\n", status, errmsg); |
| 122 | } else { |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 123 | dprintk(1, "URB packet %d, status %d [%s].\n", |
| 124 | packet, status, errmsg); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 125 | } |
| 126 | } |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 127 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 128 | static inline int em28xx_dvb_isoc_copy(struct em28xx *dev, struct urb *urb) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 129 | { |
| 130 | int i; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 131 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 132 | if (!dev) |
| 133 | return 0; |
| 134 | |
| 135 | if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) |
| 136 | return 0; |
| 137 | |
| 138 | if (urb->status < 0) { |
| 139 | print_err_status(dev, -1, urb->status); |
| 140 | if (urb->status == -ENOENT) |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | for (i = 0; i < urb->number_of_packets; i++) { |
| 145 | int status = urb->iso_frame_desc[i].status; |
| 146 | |
| 147 | if (status < 0) { |
| 148 | print_err_status(dev, i, status); |
| 149 | if (urb->iso_frame_desc[i].status != -EPROTO) |
| 150 | continue; |
| 151 | } |
| 152 | |
| 153 | dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer + |
| 154 | urb->iso_frame_desc[i].offset, |
| 155 | urb->iso_frame_desc[i].actual_length); |
| 156 | } |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 161 | static int em28xx_start_streaming(struct em28xx_dvb *dvb) |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 162 | { |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 163 | int rc; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 164 | struct em28xx *dev = dvb->adapter.priv; |
Devin Heitmueller | d18e2fd | 2009-05-16 17:09:28 -0300 | [diff] [blame] | 165 | int max_dvb_packet_size; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 166 | |
Holger Nelson | 8ab3362 | 2011-12-28 18:55:41 -0300 | [diff] [blame] | 167 | usb_set_interface(dev->udev, 0, dev->dvb_alt); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 168 | rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); |
| 169 | if (rc < 0) |
| 170 | return rc; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 171 | |
Holger Nelson | 8ab3362 | 2011-12-28 18:55:41 -0300 | [diff] [blame] | 172 | max_dvb_packet_size = dev->dvb_max_pkt_size; |
Mauro Carvalho Chehab | f7acc4b | 2011-07-28 15:42:00 -0300 | [diff] [blame] | 173 | if (max_dvb_packet_size < 0) |
| 174 | return max_dvb_packet_size; |
| 175 | dprintk(1, "Using %d buffers each with %d bytes\n", |
| 176 | EM28XX_DVB_NUM_BUFS, |
| 177 | max_dvb_packet_size); |
Devin Heitmueller | d18e2fd | 2009-05-16 17:09:28 -0300 | [diff] [blame] | 178 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 179 | return em28xx_init_isoc(dev, EM28XX_DVB_MAX_PACKETS, |
Devin Heitmueller | d18e2fd | 2009-05-16 17:09:28 -0300 | [diff] [blame] | 180 | EM28XX_DVB_NUM_BUFS, max_dvb_packet_size, |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 181 | em28xx_dvb_isoc_copy); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 182 | } |
| 183 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 184 | static int em28xx_stop_streaming(struct em28xx_dvb *dvb) |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 185 | { |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 186 | struct em28xx *dev = dvb->adapter.priv; |
| 187 | |
| 188 | em28xx_uninit_isoc(dev); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 189 | |
Mauro Carvalho Chehab | 2fe3e2e | 2008-11-27 09:10:40 -0300 | [diff] [blame] | 190 | em28xx_set_mode(dev, EM28XX_SUSPEND); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 191 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 192 | return 0; |
| 193 | } |
| 194 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 195 | static int em28xx_start_feed(struct dvb_demux_feed *feed) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 196 | { |
| 197 | struct dvb_demux *demux = feed->demux; |
| 198 | struct em28xx_dvb *dvb = demux->priv; |
| 199 | int rc, ret; |
| 200 | |
| 201 | if (!demux->dmx.frontend) |
| 202 | return -EINVAL; |
| 203 | |
| 204 | mutex_lock(&dvb->lock); |
| 205 | dvb->nfeeds++; |
| 206 | rc = dvb->nfeeds; |
| 207 | |
| 208 | if (dvb->nfeeds == 1) { |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 209 | ret = em28xx_start_streaming(dvb); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 210 | if (ret < 0) |
| 211 | rc = ret; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | mutex_unlock(&dvb->lock); |
| 215 | return rc; |
| 216 | } |
| 217 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 218 | static int em28xx_stop_feed(struct dvb_demux_feed *feed) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 219 | { |
| 220 | struct dvb_demux *demux = feed->demux; |
| 221 | struct em28xx_dvb *dvb = demux->priv; |
| 222 | int err = 0; |
| 223 | |
| 224 | mutex_lock(&dvb->lock); |
| 225 | dvb->nfeeds--; |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 226 | |
| 227 | if (0 == dvb->nfeeds) |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 228 | err = em28xx_stop_streaming(dvb); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 229 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 230 | mutex_unlock(&dvb->lock); |
| 231 | return err; |
| 232 | } |
| 233 | |
| 234 | |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 235 | |
| 236 | /* ------------------------------------------------------------------ */ |
| 237 | static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire) |
| 238 | { |
| 239 | struct em28xx *dev = fe->dvb->priv; |
| 240 | |
| 241 | if (acquire) |
| 242 | return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); |
| 243 | else |
Mauro Carvalho Chehab | 2fe3e2e | 2008-11-27 09:10:40 -0300 | [diff] [blame] | 244 | return em28xx_set_mode(dev, EM28XX_SUSPEND); |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 245 | } |
| 246 | |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 247 | /* ------------------------------------------------------------------ */ |
| 248 | |
Mauro Carvalho Chehab | 227ad4a | 2008-04-17 21:37:40 -0300 | [diff] [blame] | 249 | static struct lgdt330x_config em2880_lgdt3303_dev = { |
| 250 | .demod_address = 0x0e, |
| 251 | .demod_chip = LGDT3303, |
| 252 | }; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 253 | |
Jarod Wilson | 7e48b30 | 2010-03-07 17:55:43 -0300 | [diff] [blame] | 254 | static struct lgdt3305_config em2870_lgdt3304_dev = { |
| 255 | .i2c_addr = 0x0e, |
| 256 | .demod_chip = LGDT3304, |
| 257 | .spectral_inversion = 1, |
| 258 | .deny_i2c_rptr = 1, |
| 259 | .mpeg_mode = LGDT3305_MPEG_PARALLEL, |
| 260 | .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE, |
| 261 | .tpvalid_polarity = LGDT3305_TP_VALID_HIGH, |
| 262 | .vsb_if_khz = 3250, |
| 263 | .qam_if_khz = 4000, |
| 264 | }; |
| 265 | |
Mauro Carvalho Chehab | ca3dfd6 | 2010-09-10 17:29:14 -0300 | [diff] [blame] | 266 | static struct s921_config sharp_isdbt = { |
| 267 | .demod_address = 0x30 >> 1 |
| 268 | }; |
| 269 | |
Aidan Thornton | 7e6388a | 2008-04-17 21:40:03 -0300 | [diff] [blame] | 270 | static struct zl10353_config em28xx_zl10353_with_xc3028 = { |
| 271 | .demod_address = (0x1e >> 1), |
| 272 | .no_tuner = 1, |
| 273 | .parallel_ts = 1, |
| 274 | .if2 = 45600, |
| 275 | }; |
| 276 | |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 277 | static struct s5h1409_config em28xx_s5h1409_with_xc3028 = { |
| 278 | .demod_address = 0x32 >> 1, |
| 279 | .output_mode = S5H1409_PARALLEL_OUTPUT, |
| 280 | .gpio = S5H1409_GPIO_OFF, |
| 281 | .inversion = S5H1409_INVERSION_OFF, |
| 282 | .status_mode = S5H1409_DEMODLOCKING, |
| 283 | .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK |
| 284 | }; |
| 285 | |
Jarod Wilson | 7e48b30 | 2010-03-07 17:55:43 -0300 | [diff] [blame] | 286 | static struct tda18271_std_map kworld_a340_std_map = { |
| 287 | .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0, |
| 288 | .if_lvl = 1, .rfagc_top = 0x37, }, |
| 289 | .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1, |
| 290 | .if_lvl = 1, .rfagc_top = 0x37, }, |
| 291 | }; |
| 292 | |
| 293 | static struct tda18271_config kworld_a340_config = { |
| 294 | .std_map = &kworld_a340_std_map, |
| 295 | }; |
| 296 | |
Devin Heitmueller | a84f79a | 2009-07-12 17:05:02 -0300 | [diff] [blame] | 297 | static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = { |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 298 | .demod_address = (0x1e >> 1), |
| 299 | .no_tuner = 1, |
| 300 | .disable_i2c_gate_ctrl = 1, |
| 301 | .parallel_ts = 1, |
| 302 | .if2 = 45600, |
| 303 | }; |
| 304 | |
Devin Heitmueller | 75e2b86 | 2011-03-13 02:01:02 -0300 | [diff] [blame] | 305 | static struct drxd_config em28xx_drxd = { |
Mauro Carvalho Chehab | aac865f | 2011-12-26 09:41:14 -0300 | [diff] [blame] | 306 | .demod_address = 0x70, |
| 307 | .demod_revision = 0xa2, |
| 308 | .pll_type = DRXD_PLL_NONE, |
| 309 | .clock = 12000, |
| 310 | .insert_rs_byte = 1, |
| 311 | .IF = 42800000, |
Devin Heitmueller | 6b142b3 | 2011-03-13 02:02:01 -0300 | [diff] [blame] | 312 | .disable_i2c_gate_ctrl = 1, |
Devin Heitmueller | 17d9d55 | 2008-06-08 10:22:03 -0300 | [diff] [blame] | 313 | }; |
Devin Heitmueller | 17d9d55 | 2008-06-08 10:22:03 -0300 | [diff] [blame] | 314 | |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 315 | struct drxk_config terratec_h5_drxk = { |
| 316 | .adr = 0x29, |
Mauro Carvalho Chehab | e4f4f87 | 2011-07-09 17:35:26 -0300 | [diff] [blame] | 317 | .single_master = 1, |
Mauro Carvalho Chehab | f1fe1b7 | 2011-07-09 21:59:33 -0300 | [diff] [blame] | 318 | .no_i2c_bridge = 1, |
Mauro Carvalho Chehab | 8b9456a | 2011-07-11 14:33:51 -0300 | [diff] [blame] | 319 | .microcode_name = "dvb-usb-terratec-h5-drxk.fw", |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 320 | }; |
| 321 | |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 322 | struct drxk_config hauppauge_930c_drxk = { |
| 323 | .adr = 0x29, |
| 324 | .single_master = 1, |
| 325 | .no_i2c_bridge = 1, |
| 326 | .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw", |
| 327 | .chunk_size = 56, |
| 328 | }; |
| 329 | |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 330 | static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable) |
| 331 | { |
| 332 | struct em28xx_dvb *dvb = fe->sec_priv; |
| 333 | int status; |
| 334 | |
| 335 | if (!dvb) |
| 336 | return -EINVAL; |
| 337 | |
| 338 | if (enable) { |
| 339 | down(&dvb->pll_mutex); |
| 340 | status = dvb->gate_ctrl(fe, 1); |
| 341 | } else { |
| 342 | status = dvb->gate_ctrl(fe, 0); |
| 343 | up(&dvb->pll_mutex); |
| 344 | } |
| 345 | return status; |
| 346 | } |
| 347 | |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 348 | static void hauppauge_hvr930c_init(struct em28xx *dev) |
| 349 | { |
| 350 | int i; |
| 351 | |
| 352 | struct em28xx_reg_seq hauppauge_hvr930c_init[] = { |
Mauro Carvalho Chehab | de72405 | 2011-11-20 11:23:24 -0200 | [diff] [blame] | 353 | {EM2874_R80_GPIO, 0xff, 0xff, 0x65}, |
| 354 | {EM2874_R80_GPIO, 0xfb, 0xff, 0x32}, |
| 355 | {EM2874_R80_GPIO, 0xff, 0xff, 0xb8}, |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 356 | { -1, -1, -1, -1}, |
| 357 | }; |
| 358 | struct em28xx_reg_seq hauppauge_hvr930c_end[] = { |
Mauro Carvalho Chehab | de72405 | 2011-11-20 11:23:24 -0200 | [diff] [blame] | 359 | {EM2874_R80_GPIO, 0xef, 0xff, 0x01}, |
| 360 | {EM2874_R80_GPIO, 0xaf, 0xff, 0x65}, |
| 361 | {EM2874_R80_GPIO, 0xef, 0xff, 0x76}, |
| 362 | {EM2874_R80_GPIO, 0xef, 0xff, 0x01}, |
| 363 | {EM2874_R80_GPIO, 0xcf, 0xff, 0x0b}, |
| 364 | {EM2874_R80_GPIO, 0xef, 0xff, 0x40}, |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 365 | |
Mauro Carvalho Chehab | de72405 | 2011-11-20 11:23:24 -0200 | [diff] [blame] | 366 | {EM2874_R80_GPIO, 0xcf, 0xff, 0x65}, |
| 367 | {EM2874_R80_GPIO, 0xef, 0xff, 0x65}, |
| 368 | {EM2874_R80_GPIO, 0xcf, 0xff, 0x0b}, |
| 369 | {EM2874_R80_GPIO, 0xef, 0xff, 0x65}, |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 370 | |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 371 | { -1, -1, -1, -1}, |
| 372 | }; |
| 373 | |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 374 | struct { |
| 375 | unsigned char r[4]; |
| 376 | int len; |
| 377 | } regs[] = { |
| 378 | {{ 0x06, 0x02, 0x00, 0x31 }, 4}, |
| 379 | {{ 0x01, 0x02 }, 2}, |
| 380 | {{ 0x01, 0x02, 0x00, 0xc6 }, 4}, |
| 381 | {{ 0x01, 0x00 }, 2}, |
| 382 | {{ 0x01, 0x00, 0xff, 0xaf }, 4}, |
| 383 | {{ 0x01, 0x00, 0x03, 0xa0 }, 4}, |
| 384 | {{ 0x01, 0x00 }, 2}, |
| 385 | {{ 0x01, 0x00, 0x73, 0xaf }, 4}, |
| 386 | {{ 0x04, 0x00 }, 2}, |
| 387 | {{ 0x00, 0x04 }, 2}, |
| 388 | {{ 0x00, 0x04, 0x00, 0x0a }, 4}, |
| 389 | {{ 0x04, 0x14 }, 2}, |
| 390 | {{ 0x04, 0x14, 0x00, 0x00 }, 4}, |
| 391 | }; |
| 392 | |
| 393 | em28xx_gpio_set(dev, hauppauge_hvr930c_init); |
| 394 | em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40); |
| 395 | msleep(10); |
| 396 | em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44); |
| 397 | msleep(10); |
| 398 | |
| 399 | dev->i2c_client.addr = 0x82 >> 1; |
| 400 | |
| 401 | for (i = 0; i < ARRAY_SIZE(regs); i++) |
| 402 | i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len); |
| 403 | em28xx_gpio_set(dev, hauppauge_hvr930c_end); |
| 404 | |
| 405 | msleep(100); |
| 406 | |
| 407 | em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44); |
| 408 | msleep(30); |
| 409 | |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 410 | em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45); |
| 411 | msleep(10); |
| 412 | |
| 413 | } |
| 414 | |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 415 | static void terratec_h5_init(struct em28xx *dev) |
| 416 | { |
| 417 | int i; |
| 418 | struct em28xx_reg_seq terratec_h5_init[] = { |
| 419 | {EM28XX_R08_GPIO, 0xff, 0xff, 10}, |
| 420 | {EM2874_R80_GPIO, 0xf6, 0xff, 100}, |
| 421 | {EM2874_R80_GPIO, 0xf2, 0xff, 50}, |
| 422 | {EM2874_R80_GPIO, 0xf6, 0xff, 100}, |
| 423 | { -1, -1, -1, -1}, |
| 424 | }; |
| 425 | struct em28xx_reg_seq terratec_h5_end[] = { |
| 426 | {EM2874_R80_GPIO, 0xe6, 0xff, 100}, |
| 427 | {EM2874_R80_GPIO, 0xa6, 0xff, 50}, |
| 428 | {EM2874_R80_GPIO, 0xe6, 0xff, 100}, |
| 429 | { -1, -1, -1, -1}, |
| 430 | }; |
| 431 | struct { |
| 432 | unsigned char r[4]; |
| 433 | int len; |
| 434 | } regs[] = { |
| 435 | {{ 0x06, 0x02, 0x00, 0x31 }, 4}, |
| 436 | {{ 0x01, 0x02 }, 2}, |
| 437 | {{ 0x01, 0x02, 0x00, 0xc6 }, 4}, |
| 438 | {{ 0x01, 0x00 }, 2}, |
| 439 | {{ 0x01, 0x00, 0xff, 0xaf }, 4}, |
| 440 | {{ 0x01, 0x00, 0x03, 0xa0 }, 4}, |
| 441 | {{ 0x01, 0x00 }, 2}, |
| 442 | {{ 0x01, 0x00, 0x73, 0xaf }, 4}, |
| 443 | {{ 0x04, 0x00 }, 2}, |
| 444 | {{ 0x00, 0x04 }, 2}, |
| 445 | {{ 0x00, 0x04, 0x00, 0x0a }, 4}, |
| 446 | {{ 0x04, 0x14 }, 2}, |
| 447 | {{ 0x04, 0x14, 0x00, 0x00 }, 4}, |
| 448 | }; |
| 449 | |
| 450 | em28xx_gpio_set(dev, terratec_h5_init); |
| 451 | em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40); |
| 452 | msleep(10); |
| 453 | em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45); |
| 454 | msleep(10); |
| 455 | |
| 456 | dev->i2c_client.addr = 0x82 >> 1; |
| 457 | |
| 458 | for (i = 0; i < ARRAY_SIZE(regs); i++) |
| 459 | i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len); |
| 460 | em28xx_gpio_set(dev, terratec_h5_end); |
| 461 | }; |
| 462 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 463 | static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe) |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 464 | { |
| 465 | /* Values extracted from a USB trace of the Terratec Windows driver */ |
| 466 | static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c }; |
| 467 | static u8 reset[] = { RESET, 0x80 }; |
| 468 | static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 }; |
| 469 | static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 }; |
| 470 | static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 }; |
| 471 | static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d }; |
| 472 | static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 }; |
| 473 | static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 }; |
| 474 | static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 }; |
Devin Heitmueller | ff69786 | 2009-07-12 18:44:19 -0300 | [diff] [blame] | 475 | static u8 tuner_go[] = { TUNER_GO, 0x01}; |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 476 | |
| 477 | mt352_write(fe, clock_config, sizeof(clock_config)); |
| 478 | udelay(200); |
| 479 | mt352_write(fe, reset, sizeof(reset)); |
| 480 | mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg)); |
| 481 | mt352_write(fe, agc_cfg, sizeof(agc_cfg)); |
| 482 | mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg)); |
| 483 | mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg)); |
| 484 | mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg)); |
| 485 | mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg)); |
| 486 | mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg)); |
| 487 | mt352_write(fe, tuner_go, sizeof(tuner_go)); |
| 488 | return 0; |
| 489 | } |
| 490 | |
| 491 | static struct mt352_config terratec_xs_mt352_cfg = { |
| 492 | .demod_address = (0x1e >> 1), |
| 493 | .no_tuner = 1, |
| 494 | .if2 = 45600, |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 495 | .demod_init = em28xx_mt352_terratec_xs_init, |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 496 | }; |
| 497 | |
Antti Palosaari | 285eb1a | 2009-09-15 14:42:13 -0300 | [diff] [blame] | 498 | static struct tda10023_config em28xx_tda10023_config = { |
| 499 | .demod_address = 0x0c, |
| 500 | .invert = 1, |
| 501 | }; |
| 502 | |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 503 | static struct cxd2820r_config em28xx_cxd2820r_config = { |
| 504 | .i2c_address = (0xd8 >> 1), |
| 505 | .ts_mode = CXD2820R_TS_SERIAL, |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 506 | |
| 507 | /* enable LNA for DVB-T2 and DVB-C */ |
| 508 | .gpio_dvbt2[0] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | CXD2820R_GPIO_L, |
| 509 | .gpio_dvbc[0] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | CXD2820R_GPIO_L, |
| 510 | }; |
| 511 | |
| 512 | static struct tda18271_config em28xx_cxd2820r_tda18271_config = { |
| 513 | .output_opt = TDA18271_OUTPUT_LT_OFF, |
Steve Kerrison | 0db4bf4 | 2011-08-09 07:16:21 -0300 | [diff] [blame] | 514 | .gate = TDA18271_GATE_DIGITAL, |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 515 | }; |
| 516 | |
Antti Palosaari | 3658871 | 2011-08-01 01:15:30 -0300 | [diff] [blame] | 517 | static const struct tda10071_config em28xx_tda10071_config = { |
| 518 | .i2c_address = 0x55, /* (0xaa >> 1) */ |
| 519 | .i2c_wr_max = 64, |
| 520 | .ts_mode = TDA10071_TS_SERIAL, |
| 521 | .spec_inv = 0, |
| 522 | .xtal = 40444000, /* 40.444 MHz */ |
| 523 | .pll_multiplier = 20, |
| 524 | }; |
| 525 | |
| 526 | static const struct a8293_config em28xx_a8293_config = { |
| 527 | .i2c_addr = 0x08, /* (0x10 >> 1) */ |
| 528 | }; |
| 529 | |
Aivar Päkk | 1985f6f | 2011-12-11 18:15:00 -0300 | [diff] [blame] | 530 | static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = { |
| 531 | .demod_address = (0x1e >> 1), |
| 532 | .disable_i2c_gate_ctrl = 1, |
| 533 | .no_tuner = 1, |
| 534 | .parallel_ts = 1, |
| 535 | }; |
| 536 | static struct qt1010_config em28xx_qt1010_config = { |
| 537 | .i2c_address = 0x62 |
| 538 | |
| 539 | }; |
| 540 | |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 541 | /* ------------------------------------------------------------------ */ |
| 542 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 543 | static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev) |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 544 | { |
| 545 | struct dvb_frontend *fe; |
Mauro Carvalho Chehab | 3ca9c09 | 2008-04-17 21:37:53 -0300 | [diff] [blame] | 546 | struct xc2028_config cfg; |
| 547 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 548 | memset(&cfg, 0, sizeof(cfg)); |
Mauro Carvalho Chehab | 3ca9c09 | 2008-04-17 21:37:53 -0300 | [diff] [blame] | 549 | cfg.i2c_adap = &dev->i2c_adap; |
| 550 | cfg.i2c_addr = addr; |
Mauro Carvalho Chehab | 3ca9c09 | 2008-04-17 21:37:53 -0300 | [diff] [blame] | 551 | |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 552 | if (!dev->dvb->fe[0]) { |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 553 | em28xx_errdev("/2: dvb frontend not attached. " |
| 554 | "Can't attach xc3028\n"); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 555 | return -EINVAL; |
| 556 | } |
| 557 | |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 558 | fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 559 | if (!fe) { |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 560 | em28xx_errdev("/2: xc3028 attach failed\n"); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 561 | dvb_frontend_detach(dev->dvb->fe[0]); |
| 562 | dev->dvb->fe[0] = NULL; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 563 | return -EINVAL; |
| 564 | } |
| 565 | |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 566 | em28xx_info("%s/2: xc3028 attached\n", dev->name); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 567 | |
| 568 | return 0; |
| 569 | } |
| 570 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 571 | /* ------------------------------------------------------------------ */ |
| 572 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 573 | static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module, |
| 574 | struct em28xx *dev, struct device *device) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 575 | { |
| 576 | int result; |
| 577 | |
| 578 | mutex_init(&dvb->lock); |
| 579 | |
| 580 | /* register adapter */ |
| 581 | result = dvb_register_adapter(&dvb->adapter, dev->name, module, device, |
| 582 | adapter_nr); |
| 583 | if (result < 0) { |
| 584 | printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n", |
| 585 | dev->name, result); |
| 586 | goto fail_adapter; |
| 587 | } |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 588 | |
| 589 | /* Ensure all frontends negotiate bus access */ |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 590 | dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl; |
| 591 | if (dvb->fe[1]) |
| 592 | dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl; |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 593 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 594 | dvb->adapter.priv = dev; |
| 595 | |
| 596 | /* register frontend */ |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 597 | result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 598 | if (result < 0) { |
| 599 | printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n", |
| 600 | dev->name, result); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 601 | goto fail_frontend0; |
| 602 | } |
| 603 | |
| 604 | /* register 2nd frontend */ |
| 605 | if (dvb->fe[1]) { |
| 606 | result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]); |
| 607 | if (result < 0) { |
| 608 | printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n", |
| 609 | dev->name, result); |
| 610 | goto fail_frontend1; |
| 611 | } |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | /* register demux stuff */ |
| 615 | dvb->demux.dmx.capabilities = |
| 616 | DMX_TS_FILTERING | DMX_SECTION_FILTERING | |
| 617 | DMX_MEMORY_BASED_FILTERING; |
| 618 | dvb->demux.priv = dvb; |
| 619 | dvb->demux.filternum = 256; |
| 620 | dvb->demux.feednum = 256; |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 621 | dvb->demux.start_feed = em28xx_start_feed; |
| 622 | dvb->demux.stop_feed = em28xx_stop_feed; |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 623 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 624 | result = dvb_dmx_init(&dvb->demux); |
| 625 | if (result < 0) { |
| 626 | printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n", |
| 627 | dev->name, result); |
| 628 | goto fail_dmx; |
| 629 | } |
| 630 | |
| 631 | dvb->dmxdev.filternum = 256; |
| 632 | dvb->dmxdev.demux = &dvb->demux.dmx; |
| 633 | dvb->dmxdev.capabilities = 0; |
| 634 | result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter); |
| 635 | if (result < 0) { |
| 636 | printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n", |
| 637 | dev->name, result); |
| 638 | goto fail_dmxdev; |
| 639 | } |
| 640 | |
| 641 | dvb->fe_hw.source = DMX_FRONTEND_0; |
| 642 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 643 | if (result < 0) { |
| 644 | printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n", |
| 645 | dev->name, result); |
| 646 | goto fail_fe_hw; |
| 647 | } |
| 648 | |
| 649 | dvb->fe_mem.source = DMX_MEMORY_FE; |
| 650 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 651 | if (result < 0) { |
| 652 | printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n", |
| 653 | dev->name, result); |
| 654 | goto fail_fe_mem; |
| 655 | } |
| 656 | |
| 657 | result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 658 | if (result < 0) { |
| 659 | printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n", |
| 660 | dev->name, result); |
| 661 | goto fail_fe_conn; |
| 662 | } |
| 663 | |
| 664 | /* register network adapter */ |
| 665 | dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx); |
| 666 | return 0; |
| 667 | |
| 668 | fail_fe_conn: |
| 669 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 670 | fail_fe_mem: |
| 671 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 672 | fail_fe_hw: |
| 673 | dvb_dmxdev_release(&dvb->dmxdev); |
| 674 | fail_dmxdev: |
| 675 | dvb_dmx_release(&dvb->demux); |
| 676 | fail_dmx: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 677 | if (dvb->fe[1]) |
| 678 | dvb_unregister_frontend(dvb->fe[1]); |
| 679 | dvb_unregister_frontend(dvb->fe[0]); |
| 680 | fail_frontend1: |
| 681 | if (dvb->fe[1]) |
| 682 | dvb_frontend_detach(dvb->fe[1]); |
| 683 | fail_frontend0: |
| 684 | dvb_frontend_detach(dvb->fe[0]); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 685 | dvb_unregister_adapter(&dvb->adapter); |
| 686 | fail_adapter: |
| 687 | return result; |
| 688 | } |
| 689 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 690 | static void em28xx_unregister_dvb(struct em28xx_dvb *dvb) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 691 | { |
| 692 | dvb_net_release(&dvb->net); |
| 693 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 694 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 695 | dvb_dmxdev_release(&dvb->dmxdev); |
| 696 | dvb_dmx_release(&dvb->demux); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 697 | if (dvb->fe[1]) |
| 698 | dvb_unregister_frontend(dvb->fe[1]); |
| 699 | dvb_unregister_frontend(dvb->fe[0]); |
Mauro Carvalho Chehab | c4c3a3d | 2011-07-14 22:23:18 -0300 | [diff] [blame] | 700 | if (dvb->fe[1] && !dvb->dont_attach_fe1) |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 701 | dvb_frontend_detach(dvb->fe[1]); |
| 702 | dvb_frontend_detach(dvb->fe[0]); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 703 | dvb_unregister_adapter(&dvb->adapter); |
| 704 | } |
| 705 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 706 | static int em28xx_dvb_init(struct em28xx *dev) |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 707 | { |
Antti Palosaari | e364543 | 2011-07-28 18:59:30 -0300 | [diff] [blame] | 708 | int result = 0, mfe_shared = 0; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 709 | struct em28xx_dvb *dvb; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 710 | |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 711 | if (!dev->board.has_dvb) { |
Devin Heitmueller | df61918 | 2008-06-10 12:34:35 -0300 | [diff] [blame] | 712 | /* This device does not support the extension */ |
Mauro Carvalho Chehab | ca3dfd6 | 2010-09-10 17:29:14 -0300 | [diff] [blame] | 713 | 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] | 714 | return 0; |
| 715 | } |
| 716 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 717 | dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 718 | |
| 719 | if (dvb == NULL) { |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 720 | em28xx_info("em28xx_dvb: memory allocation failed\n"); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 721 | return -ENOMEM; |
| 722 | } |
| 723 | dev->dvb = dvb; |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 724 | dvb->fe[0] = dvb->fe[1] = NULL; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 725 | |
Mauro Carvalho Chehab | 5013318 | 2010-04-07 17:07:58 -0300 | [diff] [blame] | 726 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 727 | em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 728 | /* init frontend */ |
| 729 | switch (dev->model) { |
Mauro Carvalho Chehab | ebaefdb | 2011-06-01 10:16:25 -0300 | [diff] [blame] | 730 | case EM2874_BOARD_LEADERSHIP_ISDBT: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 731 | dvb->fe[0] = dvb_attach(s921_attach, |
Mauro Carvalho Chehab | ca3dfd6 | 2010-09-10 17:29:14 -0300 | [diff] [blame] | 732 | &sharp_isdbt, &dev->i2c_adap); |
| 733 | |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 734 | if (!dvb->fe[0]) { |
Mauro Carvalho Chehab | ca3dfd6 | 2010-09-10 17:29:14 -0300 | [diff] [blame] | 735 | result = -EINVAL; |
| 736 | goto out_free; |
| 737 | } |
| 738 | |
| 739 | break; |
Douglas Schilling Landgraf | f89bc32 | 2008-12-01 21:01:04 -0300 | [diff] [blame] | 740 | case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850: |
Mauro Carvalho Chehab | 10ac660 | 2008-07-27 14:58:58 -0300 | [diff] [blame] | 741 | case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950: |
Devin Heitmueller | 4fd305b | 2008-06-04 13:43:46 -0300 | [diff] [blame] | 742 | case EM2880_BOARD_PINNACLE_PCTV_HD_PRO: |
Devin Heitmueller | e14b365 | 2008-07-26 11:04:33 -0300 | [diff] [blame] | 743 | case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 744 | dvb->fe[0] = dvb_attach(lgdt330x_attach, |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 745 | &em2880_lgdt3303_dev, |
| 746 | &dev->i2c_adap); |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 747 | if (em28xx_attach_xc3028(0x61, dev) < 0) { |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 748 | result = -EINVAL; |
| 749 | goto out_free; |
| 750 | } |
Mauro Carvalho Chehab | 227ad4a | 2008-04-17 21:37:40 -0300 | [diff] [blame] | 751 | break; |
Thierry MERLE | 46510b5 | 2008-10-11 16:56:13 -0300 | [diff] [blame] | 752 | case EM2880_BOARD_KWORLD_DVB_310U: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 753 | dvb->fe[0] = dvb_attach(zl10353_attach, |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 754 | &em28xx_zl10353_with_xc3028, |
| 755 | &dev->i2c_adap); |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 756 | if (em28xx_attach_xc3028(0x61, dev) < 0) { |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 757 | result = -EINVAL; |
| 758 | goto out_free; |
| 759 | } |
Aidan Thornton | 7e6388a | 2008-04-17 21:40:03 -0300 | [diff] [blame] | 760 | break; |
Devin Heitmueller | a84f79a | 2009-07-12 17:05:02 -0300 | [diff] [blame] | 761 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900: |
Uroš Vampl | ec994d0 | 2009-09-30 22:53:37 -0300 | [diff] [blame] | 762 | case EM2882_BOARD_TERRATEC_HYBRID_XS: |
Devin Heitmueller | 01a5fd6 | 2009-08-07 09:25:06 -0300 | [diff] [blame] | 763 | case EM2880_BOARD_EMPIRE_DUAL_TV: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 764 | dvb->fe[0] = dvb_attach(zl10353_attach, |
Devin Heitmueller | a84f79a | 2009-07-12 17:05:02 -0300 | [diff] [blame] | 765 | &em28xx_zl10353_xc3028_no_i2c_gate, |
| 766 | &dev->i2c_adap); |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 767 | if (em28xx_attach_xc3028(0x61, dev) < 0) { |
Devin Heitmueller | a84f79a | 2009-07-12 17:05:02 -0300 | [diff] [blame] | 768 | result = -EINVAL; |
| 769 | goto out_free; |
| 770 | } |
| 771 | break; |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 772 | case EM2880_BOARD_TERRATEC_HYBRID_XS: |
Catimimi | 6563801 | 2010-02-18 18:06:32 -0300 | [diff] [blame] | 773 | case EM2880_BOARD_TERRATEC_HYBRID_XS_FR: |
Devin Heitmueller | d5b3ba9 | 2009-07-08 21:51:35 -0300 | [diff] [blame] | 774 | case EM2881_BOARD_PINNACLE_HYBRID_PRO: |
Andrea.Amorosi76@gmail.com | 7ca7ef6 | 2010-02-09 17:53:38 -0300 | [diff] [blame] | 775 | case EM2882_BOARD_DIKOM_DK300: |
Antonio Larrosa | 811fab6 | 2010-03-04 22:19:48 -0300 | [diff] [blame] | 776 | case EM2882_BOARD_KWORLD_VS_DVBT: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 777 | dvb->fe[0] = dvb_attach(zl10353_attach, |
Devin Heitmueller | a84f79a | 2009-07-12 17:05:02 -0300 | [diff] [blame] | 778 | &em28xx_zl10353_xc3028_no_i2c_gate, |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 779 | &dev->i2c_adap); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 780 | if (dvb->fe[0] == NULL) { |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 781 | /* This board could have either a zl10353 or a mt352. |
| 782 | If the chip id isn't for zl10353, try mt352 */ |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 783 | dvb->fe[0] = dvb_attach(mt352_attach, |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 784 | &terratec_xs_mt352_cfg, |
| 785 | &dev->i2c_adap); |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 786 | } |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 787 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 788 | if (em28xx_attach_xc3028(0x61, dev) < 0) { |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 789 | result = -EINVAL; |
| 790 | goto out_free; |
| 791 | } |
| 792 | break; |
Aivar Päkk | 1985f6f | 2011-12-11 18:15:00 -0300 | [diff] [blame] | 793 | case EM2870_BOARD_KWORLD_355U: |
| 794 | dvb->fe[0] = dvb_attach(zl10353_attach, |
| 795 | &em28xx_zl10353_no_i2c_gate_dev, |
| 796 | &dev->i2c_adap); |
| 797 | if (dvb->fe[0] != NULL) |
| 798 | dvb_attach(qt1010_attach, dvb->fe[0], |
| 799 | &dev->i2c_adap, &em28xx_qt1010_config); |
| 800 | break; |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 801 | case EM2883_BOARD_KWORLD_HYBRID_330U: |
Devin Heitmueller | 1985922 | 2009-06-19 00:33:54 -0300 | [diff] [blame] | 802 | case EM2882_BOARD_EVGA_INDTUBE: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 803 | dvb->fe[0] = dvb_attach(s5h1409_attach, |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 804 | &em28xx_s5h1409_with_xc3028, |
| 805 | &dev->i2c_adap); |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 806 | if (em28xx_attach_xc3028(0x61, dev) < 0) { |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 807 | result = -EINVAL; |
| 808 | goto out_free; |
| 809 | } |
| 810 | break; |
Franklin Meng | d7de5d8 | 2009-06-06 17:05:02 -0300 | [diff] [blame] | 811 | case EM2882_BOARD_KWORLD_ATSC_315U: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 812 | dvb->fe[0] = dvb_attach(lgdt330x_attach, |
Franklin Meng | d7de5d8 | 2009-06-06 17:05:02 -0300 | [diff] [blame] | 813 | &em2880_lgdt3303_dev, |
| 814 | &dev->i2c_adap); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 815 | if (dvb->fe[0] != NULL) { |
| 816 | if (!dvb_attach(simple_tuner_attach, dvb->fe[0], |
Franklin Meng | d7de5d8 | 2009-06-06 17:05:02 -0300 | [diff] [blame] | 817 | &dev->i2c_adap, 0x61, TUNER_THOMSON_DTT761X)) { |
| 818 | result = -EINVAL; |
| 819 | goto out_free; |
| 820 | } |
| 821 | } |
| 822 | break; |
Devin Heitmueller | 17d9d55 | 2008-06-08 10:22:03 -0300 | [diff] [blame] | 823 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2: |
Devin Heitmueller | ad9b4bb | 2011-03-13 02:09:59 -0300 | [diff] [blame] | 824 | case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 825 | dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL, |
Devin Heitmueller | 75e2b86 | 2011-03-13 02:01:02 -0300 | [diff] [blame] | 826 | &dev->i2c_adap, &dev->udev->dev); |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 827 | if (em28xx_attach_xc3028(0x61, dev) < 0) { |
Devin Heitmueller | 17d9d55 | 2008-06-08 10:22:03 -0300 | [diff] [blame] | 828 | result = -EINVAL; |
| 829 | goto out_free; |
| 830 | } |
| 831 | break; |
Antti Palosaari | 285eb1a | 2009-09-15 14:42:13 -0300 | [diff] [blame] | 832 | case EM2870_BOARD_REDDO_DVB_C_USB_BOX: |
| 833 | /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */ |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 834 | dvb->fe[0] = dvb_attach(tda10023_attach, |
Antti Palosaari | 285eb1a | 2009-09-15 14:42:13 -0300 | [diff] [blame] | 835 | &em28xx_tda10023_config, |
| 836 | &dev->i2c_adap, 0x48); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 837 | if (dvb->fe[0]) { |
| 838 | if (!dvb_attach(simple_tuner_attach, dvb->fe[0], |
Antti Palosaari | 285eb1a | 2009-09-15 14:42:13 -0300 | [diff] [blame] | 839 | &dev->i2c_adap, 0x60, TUNER_PHILIPS_CU1216L)) { |
| 840 | result = -EINVAL; |
| 841 | goto out_free; |
| 842 | } |
| 843 | } |
| 844 | break; |
Jarod Wilson | 7e48b30 | 2010-03-07 17:55:43 -0300 | [diff] [blame] | 845 | case EM2870_BOARD_KWORLD_A340: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 846 | dvb->fe[0] = dvb_attach(lgdt3305_attach, |
Jarod Wilson | 7e48b30 | 2010-03-07 17:55:43 -0300 | [diff] [blame] | 847 | &em2870_lgdt3304_dev, |
| 848 | &dev->i2c_adap); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 849 | if (dvb->fe[0] != NULL) |
| 850 | dvb_attach(tda18271_attach, dvb->fe[0], 0x60, |
Jarod Wilson | 7e48b30 | 2010-03-07 17:55:43 -0300 | [diff] [blame] | 851 | &dev->i2c_adap, &kworld_a340_config); |
| 852 | break; |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 853 | case EM28174_BOARD_PCTV_290E: |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 854 | dvb->fe[0] = dvb_attach(cxd2820r_attach, |
Manu Abraham | 7e7b828 | 2011-12-10 00:44:24 -0300 | [diff] [blame] | 855 | &em28xx_cxd2820r_config, |
Antti Palosaari | c2bbbe7 | 2012-01-19 14:46:43 -0300 | [diff] [blame] | 856 | &dev->i2c_adap); |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 857 | if (dvb->fe[0]) { |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 858 | /* FE 0 attach tuner */ |
Manu Abraham | 7e7b828 | 2011-12-10 00:44:24 -0300 | [diff] [blame] | 859 | if (!dvb_attach(tda18271_attach, |
| 860 | dvb->fe[0], |
| 861 | 0x60, |
| 862 | &dev->i2c_adap, |
| 863 | &em28xx_cxd2820r_tda18271_config)) { |
| 864 | |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 865 | dvb_frontend_detach(dvb->fe[0]); |
| 866 | result = -EINVAL; |
| 867 | goto out_free; |
| 868 | } |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 869 | } |
| 870 | break; |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 871 | case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C: |
Mauro Carvalho Chehab | 8503232 | 2011-11-24 15:01:45 -0200 | [diff] [blame] | 872 | { |
| 873 | struct xc5000_config cfg; |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 874 | hauppauge_hvr930c_init(dev); |
| 875 | |
Mauro Carvalho Chehab | de72405 | 2011-11-20 11:23:24 -0200 | [diff] [blame] | 876 | dvb->fe[0] = dvb_attach(drxk_attach, |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 877 | &hauppauge_930c_drxk, &dev->i2c_adap); |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 878 | if (!dvb->fe[0]) { |
| 879 | result = -EINVAL; |
| 880 | goto out_free; |
| 881 | } |
| 882 | /* FIXME: do we need a pll semaphore? */ |
| 883 | dvb->fe[0]->sec_priv = dvb; |
| 884 | sema_init(&dvb->pll_mutex, 1); |
| 885 | dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl; |
| 886 | dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl; |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 887 | |
| 888 | /* Attach xc5000 */ |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 889 | memset(&cfg, 0, sizeof(cfg)); |
| 890 | cfg.i2c_address = 0x61; |
Mauro Carvalho Chehab | de72405 | 2011-11-20 11:23:24 -0200 | [diff] [blame] | 891 | cfg.if_khz = 4000; |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 892 | |
| 893 | if (dvb->fe[0]->ops.i2c_gate_ctrl) |
| 894 | dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1); |
Mauro Carvalho Chehab | de72405 | 2011-11-20 11:23:24 -0200 | [diff] [blame] | 895 | if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap, |
| 896 | &cfg)) { |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 897 | result = -EINVAL; |
| 898 | goto out_free; |
| 899 | } |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 900 | if (dvb->fe[0]->ops.i2c_gate_ctrl) |
| 901 | dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0); |
| 902 | |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 903 | break; |
Mauro Carvalho Chehab | 8503232 | 2011-11-24 15:01:45 -0200 | [diff] [blame] | 904 | } |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 905 | case EM2884_BOARD_TERRATEC_H5: |
Andreas Oberritter | a1ed02e | 2011-11-16 11:06:50 -0300 | [diff] [blame] | 906 | case EM2884_BOARD_CINERGY_HTC_STICK: |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 907 | terratec_h5_init(dev); |
| 908 | |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 909 | dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap); |
Mauro Carvalho Chehab | c4c3a3d | 2011-07-14 22:23:18 -0300 | [diff] [blame] | 910 | if (!dvb->fe[0]) { |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 911 | result = -EINVAL; |
| 912 | goto out_free; |
| 913 | } |
| 914 | /* FIXME: do we need a pll semaphore? */ |
| 915 | dvb->fe[0]->sec_priv = dvb; |
| 916 | sema_init(&dvb->pll_mutex, 1); |
| 917 | dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl; |
| 918 | dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl; |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 919 | |
Mauro Carvalho Chehab | c4c3a3d | 2011-07-14 22:23:18 -0300 | [diff] [blame] | 920 | /* Attach tda18271 to DVB-C frontend */ |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 921 | if (dvb->fe[0]->ops.i2c_gate_ctrl) |
| 922 | dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1); |
| 923 | if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap, 0x60)) { |
| 924 | result = -EINVAL; |
| 925 | goto out_free; |
| 926 | } |
| 927 | if (dvb->fe[0]->ops.i2c_gate_ctrl) |
| 928 | dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0); |
Mauro Carvalho Chehab | c4c3a3d | 2011-07-14 22:23:18 -0300 | [diff] [blame] | 929 | |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 930 | break; |
Antti Palosaari | 3658871 | 2011-08-01 01:15:30 -0300 | [diff] [blame] | 931 | case EM28174_BOARD_PCTV_460E: |
| 932 | /* attach demod */ |
| 933 | dvb->fe[0] = dvb_attach(tda10071_attach, |
| 934 | &em28xx_tda10071_config, &dev->i2c_adap); |
| 935 | |
| 936 | /* attach SEC */ |
| 937 | if (dvb->fe[0]) |
| 938 | dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap, |
| 939 | &em28xx_a8293_config); |
| 940 | break; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 941 | default: |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 942 | em28xx_errdev("/2: The frontend of your DVB/ATSC card" |
| 943 | " isn't supported yet\n"); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 944 | break; |
| 945 | } |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 946 | if (NULL == dvb->fe[0]) { |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 947 | em28xx_errdev("/2: frontend initialization failed\n"); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 948 | result = -EINVAL; |
| 949 | goto out_free; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 950 | } |
Michael Krufky | d7cba04 | 2008-09-12 13:31:45 -0300 | [diff] [blame] | 951 | /* define general-purpose callback pointer */ |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 952 | dvb->fe[0]->callback = em28xx_tuner_callback; |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 953 | if (dvb->fe[1]) |
Mauro Carvalho Chehab | de72405 | 2011-11-20 11:23:24 -0200 | [diff] [blame] | 954 | dvb->fe[1]->callback = em28xx_tuner_callback; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 955 | |
| 956 | /* register everything */ |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 957 | result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 958 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 959 | if (result < 0) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 960 | goto out_free; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 961 | |
Antti Palosaari | e364543 | 2011-07-28 18:59:30 -0300 | [diff] [blame] | 962 | /* MFE lock */ |
| 963 | dvb->adapter.mfe_shared = mfe_shared; |
| 964 | |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 965 | em28xx_info("Successfully loaded em28xx-dvb\n"); |
Mauro Carvalho Chehab | 5013318 | 2010-04-07 17:07:58 -0300 | [diff] [blame] | 966 | ret: |
| 967 | em28xx_set_mode(dev, EM28XX_SUSPEND); |
| 968 | mutex_unlock(&dev->lock); |
| 969 | return result; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 970 | |
| 971 | out_free: |
| 972 | kfree(dvb); |
| 973 | dev->dvb = NULL; |
Mauro Carvalho Chehab | 5013318 | 2010-04-07 17:07:58 -0300 | [diff] [blame] | 974 | goto ret; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 975 | } |
| 976 | |
Chris Rankin | 0b8bd83 | 2011-08-20 16:01:26 -0300 | [diff] [blame] | 977 | static inline void prevent_sleep(struct dvb_frontend_ops *ops) |
| 978 | { |
| 979 | ops->set_voltage = NULL; |
| 980 | ops->sleep = NULL; |
| 981 | ops->tuner_ops.sleep = NULL; |
| 982 | } |
| 983 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 984 | static int em28xx_dvb_fini(struct em28xx *dev) |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 985 | { |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 986 | if (!dev->board.has_dvb) { |
Devin Heitmueller | df61918 | 2008-06-10 12:34:35 -0300 | [diff] [blame] | 987 | /* This device does not support the extension */ |
| 988 | return 0; |
| 989 | } |
| 990 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 991 | if (dev->dvb) { |
Chris Rankin | 0b8bd83 | 2011-08-20 16:01:26 -0300 | [diff] [blame] | 992 | struct em28xx_dvb *dvb = dev->dvb; |
| 993 | |
| 994 | if (dev->state & DEV_DISCONNECTED) { |
| 995 | /* We cannot tell the device to sleep |
| 996 | * once it has been unplugged. */ |
| 997 | if (dvb->fe[0]) |
| 998 | prevent_sleep(&dvb->fe[0]->ops); |
| 999 | if (dvb->fe[1]) |
| 1000 | prevent_sleep(&dvb->fe[1]->ops); |
| 1001 | } |
| 1002 | |
| 1003 | em28xx_unregister_dvb(dvb); |
| 1004 | kfree(dvb); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 1005 | dev->dvb = NULL; |
| 1006 | } |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 1007 | |
| 1008 | return 0; |
| 1009 | } |
| 1010 | |
| 1011 | static struct em28xx_ops dvb_ops = { |
| 1012 | .id = EM28XX_DVB, |
| 1013 | .name = "Em28xx dvb Extension", |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 1014 | .init = em28xx_dvb_init, |
| 1015 | .fini = em28xx_dvb_fini, |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 1016 | }; |
| 1017 | |
| 1018 | static int __init em28xx_dvb_register(void) |
| 1019 | { |
| 1020 | return em28xx_register_extension(&dvb_ops); |
| 1021 | } |
| 1022 | |
| 1023 | static void __exit em28xx_dvb_unregister(void) |
| 1024 | { |
| 1025 | em28xx_unregister_extension(&dvb_ops); |
| 1026 | } |
| 1027 | |
| 1028 | module_init(em28xx_dvb_register); |
| 1029 | module_exit(em28xx_dvb_unregister); |