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 | |
Frank Schaefer | a950e4a | 2012-11-08 14:11:47 -0300 | [diff] [blame] | 13 | (c) 2012 Frank Schäfer <fschaefer.oss@googlemail.com> |
| 14 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 15 | 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] | 16 | (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au> |
| 17 | (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs] |
| 18 | |
| 19 | This program is free software; you can redistribute it and/or modify |
| 20 | it under the terms of the GNU General Public License as published by |
| 21 | the Free Software Foundation; either version 2 of the License. |
| 22 | */ |
| 23 | |
| 24 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 26 | #include <linux/usb.h> |
| 27 | |
| 28 | #include "em28xx.h" |
| 29 | #include <media/v4l2-common.h> |
| 30 | #include <media/videobuf-vmalloc.h> |
Franklin Meng | d7de5d8 | 2009-06-06 17:05:02 -0300 | [diff] [blame] | 31 | #include <media/tuner.h> |
| 32 | #include "tuner-simple.h" |
Antti Palosaari | 1e8f31f | 2012-07-19 21:10:36 -0300 | [diff] [blame] | 33 | #include <linux/gpio.h> |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 34 | |
| 35 | #include "lgdt330x.h" |
Jarod Wilson | 7e48b30 | 2010-03-07 17:55:43 -0300 | [diff] [blame] | 36 | #include "lgdt3305.h" |
Aidan Thornton | 7e6388a | 2008-04-17 21:40:03 -0300 | [diff] [blame] | 37 | #include "zl10353.h" |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 38 | #include "s5h1409.h" |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 39 | #include "mt352.h" |
| 40 | #include "mt352_priv.h" /* FIXME */ |
Antti Palosaari | 285eb1a | 2009-09-15 14:42:13 -0300 | [diff] [blame] | 41 | #include "tda1002x.h" |
Jarod Wilson | 7e48b30 | 2010-03-07 17:55:43 -0300 | [diff] [blame] | 42 | #include "tda18271.h" |
Mauro Carvalho Chehab | ca3dfd6 | 2010-09-10 17:29:14 -0300 | [diff] [blame] | 43 | #include "s921.h" |
Devin Heitmueller | 75e2b86 | 2011-03-13 02:01:02 -0300 | [diff] [blame] | 44 | #include "drxd.h" |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 45 | #include "cxd2820r.h" |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 46 | #include "tda18271c2dd.h" |
| 47 | #include "drxk.h" |
Antti Palosaari | 3658871 | 2011-08-01 01:15:30 -0300 | [diff] [blame] | 48 | #include "tda10071.h" |
| 49 | #include "a8293.h" |
Aivar Päkk | 1985f6f | 2011-12-11 18:15:00 -0300 | [diff] [blame] | 50 | #include "qt1010.h" |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 51 | |
| 52 | MODULE_DESCRIPTION("driver for em28xx based DVB cards"); |
| 53 | MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); |
| 54 | MODULE_LICENSE("GPL"); |
| 55 | |
| 56 | static unsigned int debug; |
| 57 | module_param(debug, int, 0644); |
| 58 | MODULE_PARM_DESC(debug, "enable debug messages [dvb]"); |
| 59 | |
| 60 | DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); |
| 61 | |
| 62 | #define dprintk(level, fmt, arg...) do { \ |
| 63 | if (debug >= level) \ |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 64 | printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \ |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 65 | } while (0) |
| 66 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 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; |
Antti Palosaari | 13a5336 | 2012-07-19 22:28:56 -0300 | [diff] [blame] | 86 | int lna_gpio; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | |
| 90 | static inline void print_err_status(struct em28xx *dev, |
| 91 | int packet, int status) |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 92 | { |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 93 | char *errmsg = "Unknown"; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 94 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 95 | switch (status) { |
| 96 | case -ENOENT: |
| 97 | errmsg = "unlinked synchronuously"; |
| 98 | break; |
| 99 | case -ECONNRESET: |
| 100 | errmsg = "unlinked asynchronuously"; |
| 101 | break; |
| 102 | case -ENOSR: |
| 103 | errmsg = "Buffer error (overrun)"; |
| 104 | break; |
| 105 | case -EPIPE: |
| 106 | errmsg = "Stalled (device not responding)"; |
| 107 | break; |
| 108 | case -EOVERFLOW: |
| 109 | errmsg = "Babble (bad cable?)"; |
| 110 | break; |
| 111 | case -EPROTO: |
| 112 | errmsg = "Bit-stuff error (bad cable?)"; |
| 113 | break; |
| 114 | case -EILSEQ: |
| 115 | errmsg = "CRC/Timeout (could be anything)"; |
| 116 | break; |
| 117 | case -ETIME: |
| 118 | errmsg = "Device does not respond"; |
| 119 | break; |
| 120 | } |
| 121 | if (packet < 0) { |
| 122 | dprintk(1, "URB status %d [%s].\n", status, errmsg); |
| 123 | } else { |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 124 | dprintk(1, "URB packet %d, status %d [%s].\n", |
| 125 | packet, status, errmsg); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 126 | } |
| 127 | } |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 128 | |
Frank Schaefer | a950e4a | 2012-11-08 14:11:47 -0300 | [diff] [blame] | 129 | static inline int em28xx_dvb_urb_data_copy(struct em28xx *dev, struct urb *urb) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 130 | { |
Frank Schaefer | a950e4a | 2012-11-08 14:11:47 -0300 | [diff] [blame] | 131 | int xfer_bulk, num_packets, i; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 132 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 133 | if (!dev) |
| 134 | return 0; |
| 135 | |
| 136 | if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED)) |
| 137 | return 0; |
| 138 | |
Frank Schaefer | 1653cb0c | 2012-11-08 14:11:44 -0300 | [diff] [blame] | 139 | if (urb->status < 0) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 140 | print_err_status(dev, -1, urb->status); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 141 | |
Frank Schaefer | a950e4a | 2012-11-08 14:11:47 -0300 | [diff] [blame] | 142 | xfer_bulk = usb_pipebulk(urb->pipe); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 143 | |
Frank Schaefer | a950e4a | 2012-11-08 14:11:47 -0300 | [diff] [blame] | 144 | if (xfer_bulk) /* bulk */ |
| 145 | num_packets = 1; |
| 146 | else /* isoc */ |
| 147 | num_packets = urb->number_of_packets; |
| 148 | |
| 149 | for (i = 0; i < num_packets; i++) { |
| 150 | if (xfer_bulk) { |
| 151 | if (urb->status < 0) { |
| 152 | print_err_status(dev, i, urb->status); |
| 153 | if (urb->status != -EPROTO) |
| 154 | continue; |
| 155 | } |
| 156 | dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer, |
| 157 | urb->actual_length); |
| 158 | } else { |
| 159 | if (urb->iso_frame_desc[i].status < 0) { |
| 160 | print_err_status(dev, i, |
| 161 | urb->iso_frame_desc[i].status); |
| 162 | if (urb->iso_frame_desc[i].status != -EPROTO) |
| 163 | continue; |
| 164 | } |
| 165 | dvb_dmx_swfilter(&dev->dvb->demux, |
| 166 | urb->transfer_buffer + |
| 167 | urb->iso_frame_desc[i].offset, |
| 168 | urb->iso_frame_desc[i].actual_length); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 169 | } |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 170 | } |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 171 | |
| 172 | return 0; |
| 173 | } |
| 174 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 175 | static int em28xx_start_streaming(struct em28xx_dvb *dvb) |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 176 | { |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 177 | int rc; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 178 | struct em28xx *dev = dvb->adapter.priv; |
Frank Schaefer | c647a91 | 2012-11-08 14:11:52 -0300 | [diff] [blame] | 179 | int dvb_max_packet_size, packet_multiplier, dvb_alt; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 180 | |
Frank Schaefer | c647a91 | 2012-11-08 14:11:52 -0300 | [diff] [blame] | 181 | if (dev->dvb_xfer_bulk) { |
| 182 | if (!dev->dvb_ep_bulk) |
| 183 | return -ENODEV; |
| 184 | dvb_max_packet_size = 512; /* USB 2.0 spec */ |
| 185 | packet_multiplier = EM28XX_DVB_BULK_PACKET_MULTIPLIER; |
| 186 | dvb_alt = 0; |
| 187 | } else { /* isoc */ |
| 188 | if (!dev->dvb_ep_isoc) |
| 189 | return -ENODEV; |
| 190 | dvb_max_packet_size = dev->dvb_max_pkt_size_isoc; |
| 191 | if (dvb_max_packet_size < 0) |
| 192 | return dvb_max_packet_size; |
| 193 | packet_multiplier = EM28XX_DVB_NUM_ISOC_PACKETS; |
| 194 | dvb_alt = dev->dvb_alt_isoc; |
| 195 | } |
| 196 | |
| 197 | usb_set_interface(dev->udev, 0, dvb_alt); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 198 | rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); |
| 199 | if (rc < 0) |
| 200 | return rc; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 201 | |
Gianluca Gennari | 86d38d1 | 2012-02-13 13:59:22 -0300 | [diff] [blame] | 202 | dprintk(1, "Using %d buffers each with %d x %d bytes\n", |
Mauro Carvalho Chehab | f7acc4b | 2011-07-28 15:42:00 -0300 | [diff] [blame] | 203 | EM28XX_DVB_NUM_BUFS, |
Frank Schaefer | c647a91 | 2012-11-08 14:11:52 -0300 | [diff] [blame] | 204 | packet_multiplier, |
| 205 | dvb_max_packet_size); |
Devin Heitmueller | d18e2fd | 2009-05-16 17:09:28 -0300 | [diff] [blame] | 206 | |
Frank Schaefer | c647a91 | 2012-11-08 14:11:52 -0300 | [diff] [blame] | 207 | return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE, |
| 208 | dev->dvb_xfer_bulk, |
Frank Schaefer | 057ca0d | 2012-11-08 14:11:42 -0300 | [diff] [blame] | 209 | EM28XX_DVB_NUM_BUFS, |
Frank Schaefer | c647a91 | 2012-11-08 14:11:52 -0300 | [diff] [blame] | 210 | dvb_max_packet_size, |
| 211 | packet_multiplier, |
Frank Schaefer | a950e4a | 2012-11-08 14:11:47 -0300 | [diff] [blame] | 212 | em28xx_dvb_urb_data_copy); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 213 | } |
| 214 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 215 | static int em28xx_stop_streaming(struct em28xx_dvb *dvb) |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 216 | { |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 217 | struct em28xx *dev = dvb->adapter.priv; |
| 218 | |
Gianluca Gennari | 5f5f147 | 2012-03-22 08:48:17 -0300 | [diff] [blame] | 219 | em28xx_stop_urbs(dev); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 220 | |
Mauro Carvalho Chehab | 2fe3e2e | 2008-11-27 09:10:40 -0300 | [diff] [blame] | 221 | em28xx_set_mode(dev, EM28XX_SUSPEND); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 222 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 223 | return 0; |
| 224 | } |
| 225 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 226 | static int em28xx_start_feed(struct dvb_demux_feed *feed) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 227 | { |
| 228 | struct dvb_demux *demux = feed->demux; |
| 229 | struct em28xx_dvb *dvb = demux->priv; |
| 230 | int rc, ret; |
| 231 | |
| 232 | if (!demux->dmx.frontend) |
| 233 | return -EINVAL; |
| 234 | |
| 235 | mutex_lock(&dvb->lock); |
| 236 | dvb->nfeeds++; |
| 237 | rc = dvb->nfeeds; |
| 238 | |
| 239 | if (dvb->nfeeds == 1) { |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 240 | ret = em28xx_start_streaming(dvb); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 241 | if (ret < 0) |
| 242 | rc = ret; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | mutex_unlock(&dvb->lock); |
| 246 | return rc; |
| 247 | } |
| 248 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 249 | static int em28xx_stop_feed(struct dvb_demux_feed *feed) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 250 | { |
| 251 | struct dvb_demux *demux = feed->demux; |
| 252 | struct em28xx_dvb *dvb = demux->priv; |
| 253 | int err = 0; |
| 254 | |
| 255 | mutex_lock(&dvb->lock); |
| 256 | dvb->nfeeds--; |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 257 | |
| 258 | if (0 == dvb->nfeeds) |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 259 | err = em28xx_stop_streaming(dvb); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 260 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 261 | mutex_unlock(&dvb->lock); |
| 262 | return err; |
| 263 | } |
| 264 | |
| 265 | |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 266 | |
| 267 | /* ------------------------------------------------------------------ */ |
| 268 | static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire) |
| 269 | { |
| 270 | struct em28xx *dev = fe->dvb->priv; |
| 271 | |
| 272 | if (acquire) |
| 273 | return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); |
| 274 | else |
Mauro Carvalho Chehab | 2fe3e2e | 2008-11-27 09:10:40 -0300 | [diff] [blame] | 275 | return em28xx_set_mode(dev, EM28XX_SUSPEND); |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 276 | } |
| 277 | |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 278 | /* ------------------------------------------------------------------ */ |
| 279 | |
Mauro Carvalho Chehab | 227ad4a | 2008-04-17 21:37:40 -0300 | [diff] [blame] | 280 | static struct lgdt330x_config em2880_lgdt3303_dev = { |
| 281 | .demod_address = 0x0e, |
| 282 | .demod_chip = LGDT3303, |
| 283 | }; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 284 | |
Jarod Wilson | 7e48b30 | 2010-03-07 17:55:43 -0300 | [diff] [blame] | 285 | static struct lgdt3305_config em2870_lgdt3304_dev = { |
| 286 | .i2c_addr = 0x0e, |
| 287 | .demod_chip = LGDT3304, |
| 288 | .spectral_inversion = 1, |
| 289 | .deny_i2c_rptr = 1, |
| 290 | .mpeg_mode = LGDT3305_MPEG_PARALLEL, |
| 291 | .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE, |
| 292 | .tpvalid_polarity = LGDT3305_TP_VALID_HIGH, |
| 293 | .vsb_if_khz = 3250, |
| 294 | .qam_if_khz = 4000, |
| 295 | }; |
| 296 | |
Mauro Carvalho Chehab | ca3dfd6 | 2010-09-10 17:29:14 -0300 | [diff] [blame] | 297 | static struct s921_config sharp_isdbt = { |
| 298 | .demod_address = 0x30 >> 1 |
| 299 | }; |
| 300 | |
Aidan Thornton | 7e6388a | 2008-04-17 21:40:03 -0300 | [diff] [blame] | 301 | static struct zl10353_config em28xx_zl10353_with_xc3028 = { |
| 302 | .demod_address = (0x1e >> 1), |
| 303 | .no_tuner = 1, |
| 304 | .parallel_ts = 1, |
| 305 | .if2 = 45600, |
| 306 | }; |
| 307 | |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 308 | static struct s5h1409_config em28xx_s5h1409_with_xc3028 = { |
| 309 | .demod_address = 0x32 >> 1, |
| 310 | .output_mode = S5H1409_PARALLEL_OUTPUT, |
| 311 | .gpio = S5H1409_GPIO_OFF, |
| 312 | .inversion = S5H1409_INVERSION_OFF, |
| 313 | .status_mode = S5H1409_DEMODLOCKING, |
| 314 | .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK |
| 315 | }; |
| 316 | |
Jarod Wilson | 7e48b30 | 2010-03-07 17:55:43 -0300 | [diff] [blame] | 317 | static struct tda18271_std_map kworld_a340_std_map = { |
| 318 | .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0, |
| 319 | .if_lvl = 1, .rfagc_top = 0x37, }, |
| 320 | .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1, |
| 321 | .if_lvl = 1, .rfagc_top = 0x37, }, |
| 322 | }; |
| 323 | |
| 324 | static struct tda18271_config kworld_a340_config = { |
| 325 | .std_map = &kworld_a340_std_map, |
| 326 | }; |
| 327 | |
Devin Heitmueller | a84f79a | 2009-07-12 17:05:02 -0300 | [diff] [blame] | 328 | static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = { |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 329 | .demod_address = (0x1e >> 1), |
| 330 | .no_tuner = 1, |
| 331 | .disable_i2c_gate_ctrl = 1, |
| 332 | .parallel_ts = 1, |
| 333 | .if2 = 45600, |
| 334 | }; |
| 335 | |
Devin Heitmueller | 75e2b86 | 2011-03-13 02:01:02 -0300 | [diff] [blame] | 336 | static struct drxd_config em28xx_drxd = { |
Mauro Carvalho Chehab | aac865f | 2011-12-26 09:41:14 -0300 | [diff] [blame] | 337 | .demod_address = 0x70, |
| 338 | .demod_revision = 0xa2, |
| 339 | .pll_type = DRXD_PLL_NONE, |
| 340 | .clock = 12000, |
| 341 | .insert_rs_byte = 1, |
| 342 | .IF = 42800000, |
Devin Heitmueller | 6b142b3 | 2011-03-13 02:02:01 -0300 | [diff] [blame] | 343 | .disable_i2c_gate_ctrl = 1, |
Devin Heitmueller | 17d9d55 | 2008-06-08 10:22:03 -0300 | [diff] [blame] | 344 | }; |
Devin Heitmueller | 17d9d55 | 2008-06-08 10:22:03 -0300 | [diff] [blame] | 345 | |
Ezequiel García | 61bdbef | 2012-06-12 09:53:41 -0300 | [diff] [blame] | 346 | static struct drxk_config terratec_h5_drxk = { |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 347 | .adr = 0x29, |
Mauro Carvalho Chehab | e4f4f87 | 2011-07-09 17:35:26 -0300 | [diff] [blame] | 348 | .single_master = 1, |
Mauro Carvalho Chehab | f1fe1b7 | 2011-07-09 21:59:33 -0300 | [diff] [blame] | 349 | .no_i2c_bridge = 1, |
Mauro Carvalho Chehab | 8b9456a | 2011-07-11 14:33:51 -0300 | [diff] [blame] | 350 | .microcode_name = "dvb-usb-terratec-h5-drxk.fw", |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 351 | .qam_demod_parameter_count = 2, |
Mauro Carvalho Chehab | 2425bb3 | 2012-10-02 16:02:57 -0300 | [diff] [blame] | 352 | .load_firmware_sync = true, |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 353 | }; |
| 354 | |
Ezequiel García | 61bdbef | 2012-06-12 09:53:41 -0300 | [diff] [blame] | 355 | static struct drxk_config hauppauge_930c_drxk = { |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 356 | .adr = 0x29, |
| 357 | .single_master = 1, |
| 358 | .no_i2c_bridge = 1, |
| 359 | .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw", |
| 360 | .chunk_size = 56, |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 361 | .qam_demod_parameter_count = 2, |
Mauro Carvalho Chehab | 2425bb3 | 2012-10-02 16:02:57 -0300 | [diff] [blame] | 362 | .load_firmware_sync = true, |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 363 | }; |
| 364 | |
Martin Blumenstingl | 8904013 | 2012-10-04 14:22:54 -0300 | [diff] [blame] | 365 | static struct drxk_config terratec_htc_stick_drxk = { |
Martin Blumenstingl | c8dce00 | 2012-06-12 18:19:28 -0300 | [diff] [blame] | 366 | .adr = 0x29, |
| 367 | .single_master = 1, |
| 368 | .no_i2c_bridge = 1, |
| 369 | .microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw", |
| 370 | .chunk_size = 54, |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 371 | .qam_demod_parameter_count = 2, |
Martin Blumenstingl | c8dce00 | 2012-06-12 18:19:28 -0300 | [diff] [blame] | 372 | /* Required for the antenna_gpio to disable LNA. */ |
| 373 | .antenna_dvbt = true, |
| 374 | /* The windows driver uses the same. This will disable LNA. */ |
| 375 | .antenna_gpio = 0x6, |
Mauro Carvalho Chehab | 2425bb3 | 2012-10-02 16:02:57 -0300 | [diff] [blame] | 376 | .load_firmware_sync = true, |
Martin Blumenstingl | c8dce00 | 2012-06-12 18:19:28 -0300 | [diff] [blame] | 377 | }; |
| 378 | |
Ezequiel García | 61bdbef | 2012-06-12 09:53:41 -0300 | [diff] [blame] | 379 | static struct drxk_config maxmedia_ub425_tc_drxk = { |
Antti Palosaari | 3553085 | 2012-03-18 18:09:01 -0300 | [diff] [blame] | 380 | .adr = 0x29, |
| 381 | .single_master = 1, |
| 382 | .no_i2c_bridge = 1, |
Mauro Carvalho Chehab | 2425bb3 | 2012-10-02 16:02:57 -0300 | [diff] [blame] | 383 | .load_firmware_sync = true, |
Antti Palosaari | 3553085 | 2012-03-18 18:09:01 -0300 | [diff] [blame] | 384 | }; |
| 385 | |
Ezequiel García | 61bdbef | 2012-06-12 09:53:41 -0300 | [diff] [blame] | 386 | static struct drxk_config pctv_520e_drxk = { |
Antti Palosaari | c247d7b | 2012-03-19 11:48:19 -0300 | [diff] [blame] | 387 | .adr = 0x29, |
| 388 | .single_master = 1, |
| 389 | .microcode_name = "dvb-demod-drxk-pctv.fw", |
Martin Blumenstingl | 9e23f50a | 2012-07-04 17:36:55 -0300 | [diff] [blame] | 390 | .qam_demod_parameter_count = 2, |
Antti Palosaari | c247d7b | 2012-03-19 11:48:19 -0300 | [diff] [blame] | 391 | .chunk_size = 58, |
Antti Palosaari | f6f379d | 2012-05-17 19:09:06 -0300 | [diff] [blame] | 392 | .antenna_dvbt = true, /* disable LNA */ |
| 393 | .antenna_gpio = (1 << 2), /* disable LNA */ |
Mauro Carvalho Chehab | 2425bb3 | 2012-10-02 16:02:57 -0300 | [diff] [blame] | 394 | .load_firmware_sync = true, |
Antti Palosaari | c247d7b | 2012-03-19 11:48:19 -0300 | [diff] [blame] | 395 | }; |
| 396 | |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 397 | static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable) |
| 398 | { |
| 399 | struct em28xx_dvb *dvb = fe->sec_priv; |
| 400 | int status; |
| 401 | |
| 402 | if (!dvb) |
| 403 | return -EINVAL; |
| 404 | |
| 405 | if (enable) { |
| 406 | down(&dvb->pll_mutex); |
| 407 | status = dvb->gate_ctrl(fe, 1); |
| 408 | } else { |
| 409 | status = dvb->gate_ctrl(fe, 0); |
| 410 | up(&dvb->pll_mutex); |
| 411 | } |
| 412 | return status; |
| 413 | } |
| 414 | |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 415 | static void hauppauge_hvr930c_init(struct em28xx *dev) |
| 416 | { |
| 417 | int i; |
| 418 | |
| 419 | struct em28xx_reg_seq hauppauge_hvr930c_init[] = { |
Mauro Carvalho Chehab | de72405 | 2011-11-20 11:23:24 -0200 | [diff] [blame] | 420 | {EM2874_R80_GPIO, 0xff, 0xff, 0x65}, |
| 421 | {EM2874_R80_GPIO, 0xfb, 0xff, 0x32}, |
| 422 | {EM2874_R80_GPIO, 0xff, 0xff, 0xb8}, |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 423 | { -1, -1, -1, -1}, |
| 424 | }; |
| 425 | struct em28xx_reg_seq hauppauge_hvr930c_end[] = { |
Mauro Carvalho Chehab | de72405 | 2011-11-20 11:23:24 -0200 | [diff] [blame] | 426 | {EM2874_R80_GPIO, 0xef, 0xff, 0x01}, |
| 427 | {EM2874_R80_GPIO, 0xaf, 0xff, 0x65}, |
| 428 | {EM2874_R80_GPIO, 0xef, 0xff, 0x76}, |
| 429 | {EM2874_R80_GPIO, 0xef, 0xff, 0x01}, |
| 430 | {EM2874_R80_GPIO, 0xcf, 0xff, 0x0b}, |
| 431 | {EM2874_R80_GPIO, 0xef, 0xff, 0x40}, |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 432 | |
Mauro Carvalho Chehab | de72405 | 2011-11-20 11:23:24 -0200 | [diff] [blame] | 433 | {EM2874_R80_GPIO, 0xcf, 0xff, 0x65}, |
| 434 | {EM2874_R80_GPIO, 0xef, 0xff, 0x65}, |
| 435 | {EM2874_R80_GPIO, 0xcf, 0xff, 0x0b}, |
| 436 | {EM2874_R80_GPIO, 0xef, 0xff, 0x65}, |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 437 | |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 438 | { -1, -1, -1, -1}, |
| 439 | }; |
| 440 | |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 441 | struct { |
| 442 | unsigned char r[4]; |
| 443 | int len; |
| 444 | } regs[] = { |
| 445 | {{ 0x06, 0x02, 0x00, 0x31 }, 4}, |
| 446 | {{ 0x01, 0x02 }, 2}, |
| 447 | {{ 0x01, 0x02, 0x00, 0xc6 }, 4}, |
| 448 | {{ 0x01, 0x00 }, 2}, |
| 449 | {{ 0x01, 0x00, 0xff, 0xaf }, 4}, |
| 450 | {{ 0x01, 0x00, 0x03, 0xa0 }, 4}, |
| 451 | {{ 0x01, 0x00 }, 2}, |
| 452 | {{ 0x01, 0x00, 0x73, 0xaf }, 4}, |
| 453 | {{ 0x04, 0x00 }, 2}, |
| 454 | {{ 0x00, 0x04 }, 2}, |
| 455 | {{ 0x00, 0x04, 0x00, 0x0a }, 4}, |
| 456 | {{ 0x04, 0x14 }, 2}, |
| 457 | {{ 0x04, 0x14, 0x00, 0x00 }, 4}, |
| 458 | }; |
| 459 | |
| 460 | em28xx_gpio_set(dev, hauppauge_hvr930c_init); |
| 461 | em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40); |
| 462 | msleep(10); |
| 463 | em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44); |
| 464 | msleep(10); |
| 465 | |
| 466 | dev->i2c_client.addr = 0x82 >> 1; |
| 467 | |
| 468 | for (i = 0; i < ARRAY_SIZE(regs); i++) |
| 469 | i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len); |
| 470 | em28xx_gpio_set(dev, hauppauge_hvr930c_end); |
| 471 | |
| 472 | msleep(100); |
| 473 | |
| 474 | em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44); |
| 475 | msleep(30); |
| 476 | |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 477 | em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45); |
| 478 | msleep(10); |
| 479 | |
| 480 | } |
| 481 | |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 482 | static void terratec_h5_init(struct em28xx *dev) |
| 483 | { |
| 484 | int i; |
| 485 | struct em28xx_reg_seq terratec_h5_init[] = { |
| 486 | {EM28XX_R08_GPIO, 0xff, 0xff, 10}, |
| 487 | {EM2874_R80_GPIO, 0xf6, 0xff, 100}, |
| 488 | {EM2874_R80_GPIO, 0xf2, 0xff, 50}, |
| 489 | {EM2874_R80_GPIO, 0xf6, 0xff, 100}, |
| 490 | { -1, -1, -1, -1}, |
| 491 | }; |
| 492 | struct em28xx_reg_seq terratec_h5_end[] = { |
| 493 | {EM2874_R80_GPIO, 0xe6, 0xff, 100}, |
| 494 | {EM2874_R80_GPIO, 0xa6, 0xff, 50}, |
| 495 | {EM2874_R80_GPIO, 0xe6, 0xff, 100}, |
| 496 | { -1, -1, -1, -1}, |
| 497 | }; |
| 498 | struct { |
| 499 | unsigned char r[4]; |
| 500 | int len; |
| 501 | } regs[] = { |
| 502 | {{ 0x06, 0x02, 0x00, 0x31 }, 4}, |
| 503 | {{ 0x01, 0x02 }, 2}, |
| 504 | {{ 0x01, 0x02, 0x00, 0xc6 }, 4}, |
| 505 | {{ 0x01, 0x00 }, 2}, |
| 506 | {{ 0x01, 0x00, 0xff, 0xaf }, 4}, |
| 507 | {{ 0x01, 0x00, 0x03, 0xa0 }, 4}, |
| 508 | {{ 0x01, 0x00 }, 2}, |
| 509 | {{ 0x01, 0x00, 0x73, 0xaf }, 4}, |
| 510 | {{ 0x04, 0x00 }, 2}, |
| 511 | {{ 0x00, 0x04 }, 2}, |
| 512 | {{ 0x00, 0x04, 0x00, 0x0a }, 4}, |
| 513 | {{ 0x04, 0x14 }, 2}, |
| 514 | {{ 0x04, 0x14, 0x00, 0x00 }, 4}, |
| 515 | }; |
| 516 | |
| 517 | em28xx_gpio_set(dev, terratec_h5_init); |
| 518 | em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40); |
| 519 | msleep(10); |
| 520 | em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45); |
| 521 | msleep(10); |
| 522 | |
| 523 | dev->i2c_client.addr = 0x82 >> 1; |
| 524 | |
| 525 | for (i = 0; i < ARRAY_SIZE(regs); i++) |
| 526 | i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len); |
| 527 | em28xx_gpio_set(dev, terratec_h5_end); |
| 528 | }; |
| 529 | |
Martin Blumenstingl | c8dce00 | 2012-06-12 18:19:28 -0300 | [diff] [blame] | 530 | static void terratec_htc_stick_init(struct em28xx *dev) |
| 531 | { |
| 532 | int i; |
| 533 | |
| 534 | /* |
| 535 | * GPIO configuration: |
| 536 | * 0xff: unknown (does not affect DVB-T). |
| 537 | * 0xf6: DRX-K (demodulator). |
| 538 | * 0xe6: unknown (does not affect DVB-T). |
| 539 | * 0xb6: unknown (does not affect DVB-T). |
| 540 | */ |
| 541 | struct em28xx_reg_seq terratec_htc_stick_init[] = { |
| 542 | {EM28XX_R08_GPIO, 0xff, 0xff, 10}, |
| 543 | {EM2874_R80_GPIO, 0xf6, 0xff, 100}, |
| 544 | {EM2874_R80_GPIO, 0xe6, 0xff, 50}, |
| 545 | {EM2874_R80_GPIO, 0xf6, 0xff, 100}, |
| 546 | { -1, -1, -1, -1}, |
| 547 | }; |
| 548 | struct em28xx_reg_seq terratec_htc_stick_end[] = { |
| 549 | {EM2874_R80_GPIO, 0xb6, 0xff, 100}, |
| 550 | {EM2874_R80_GPIO, 0xf6, 0xff, 50}, |
| 551 | { -1, -1, -1, -1}, |
| 552 | }; |
| 553 | |
Martin Blumenstingl | 8904013 | 2012-10-04 14:22:54 -0300 | [diff] [blame] | 554 | /* |
| 555 | * Init the analog decoder (not yet supported), but |
| 556 | * it's probably still a good idea. |
| 557 | */ |
Martin Blumenstingl | c8dce00 | 2012-06-12 18:19:28 -0300 | [diff] [blame] | 558 | struct { |
| 559 | unsigned char r[4]; |
| 560 | int len; |
| 561 | } regs[] = { |
| 562 | {{ 0x06, 0x02, 0x00, 0x31 }, 4}, |
| 563 | {{ 0x01, 0x02 }, 2}, |
| 564 | {{ 0x01, 0x02, 0x00, 0xc6 }, 4}, |
| 565 | {{ 0x01, 0x00 }, 2}, |
| 566 | {{ 0x01, 0x00, 0xff, 0xaf }, 4}, |
| 567 | }; |
| 568 | |
| 569 | em28xx_gpio_set(dev, terratec_htc_stick_init); |
| 570 | |
| 571 | em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40); |
| 572 | msleep(10); |
| 573 | em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44); |
| 574 | msleep(10); |
| 575 | |
| 576 | dev->i2c_client.addr = 0x82 >> 1; |
| 577 | |
| 578 | for (i = 0; i < ARRAY_SIZE(regs); i++) |
| 579 | i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len); |
| 580 | |
| 581 | em28xx_gpio_set(dev, terratec_htc_stick_end); |
| 582 | }; |
| 583 | |
Martin Blumenstingl | 8904013 | 2012-10-04 14:22:54 -0300 | [diff] [blame] | 584 | static void terratec_htc_usb_xs_init(struct em28xx *dev) |
| 585 | { |
| 586 | int i; |
| 587 | |
| 588 | struct em28xx_reg_seq terratec_htc_usb_xs_init[] = { |
| 589 | {EM28XX_R08_GPIO, 0xff, 0xff, 10}, |
| 590 | {EM2874_R80_GPIO, 0xb2, 0xff, 100}, |
| 591 | {EM2874_R80_GPIO, 0xb2, 0xff, 50}, |
| 592 | {EM2874_R80_GPIO, 0xb6, 0xff, 100}, |
| 593 | { -1, -1, -1, -1}, |
| 594 | }; |
| 595 | struct em28xx_reg_seq terratec_htc_usb_xs_end[] = { |
| 596 | {EM2874_R80_GPIO, 0xa6, 0xff, 100}, |
| 597 | {EM2874_R80_GPIO, 0xa6, 0xff, 50}, |
| 598 | {EM2874_R80_GPIO, 0xe6, 0xff, 100}, |
| 599 | { -1, -1, -1, -1}, |
| 600 | }; |
| 601 | |
| 602 | /* |
| 603 | * Init the analog decoder (not yet supported), but |
| 604 | * it's probably still a good idea. |
| 605 | */ |
| 606 | struct { |
| 607 | unsigned char r[4]; |
| 608 | int len; |
| 609 | } regs[] = { |
| 610 | {{ 0x06, 0x02, 0x00, 0x31 }, 4}, |
| 611 | {{ 0x01, 0x02 }, 2}, |
| 612 | {{ 0x01, 0x02, 0x00, 0xc6 }, 4}, |
| 613 | {{ 0x01, 0x00 }, 2}, |
| 614 | {{ 0x01, 0x00, 0xff, 0xaf }, 4}, |
| 615 | {{ 0x01, 0x00, 0x03, 0xa0 }, 4}, |
| 616 | {{ 0x01, 0x00 }, 2}, |
| 617 | {{ 0x01, 0x00, 0x73, 0xaf }, 4}, |
| 618 | {{ 0x04, 0x00 }, 2}, |
| 619 | {{ 0x00, 0x04 }, 2}, |
| 620 | {{ 0x00, 0x04, 0x00, 0x0a }, 4}, |
| 621 | {{ 0x04, 0x14 }, 2}, |
| 622 | {{ 0x04, 0x14, 0x00, 0x00 }, 4}, |
| 623 | }; |
| 624 | |
| 625 | em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40); |
| 626 | |
| 627 | em28xx_gpio_set(dev, terratec_htc_usb_xs_init); |
| 628 | |
| 629 | em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40); |
| 630 | msleep(10); |
| 631 | em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44); |
| 632 | msleep(10); |
| 633 | |
| 634 | dev->i2c_client.addr = 0x82 >> 1; |
| 635 | |
| 636 | for (i = 0; i < ARRAY_SIZE(regs); i++) |
| 637 | i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len); |
| 638 | |
| 639 | em28xx_gpio_set(dev, terratec_htc_usb_xs_end); |
| 640 | }; |
| 641 | |
Antti Palosaari | c247d7b | 2012-03-19 11:48:19 -0300 | [diff] [blame] | 642 | static void pctv_520e_init(struct em28xx *dev) |
| 643 | { |
| 644 | /* |
Antti Palosaari | 26c8a72 | 2012-05-17 18:22:02 -0300 | [diff] [blame] | 645 | * Init AVF4910B analog decoder. Looks like I2C traffic to |
| 646 | * digital demodulator and tuner are routed via AVF4910B. |
Antti Palosaari | c247d7b | 2012-03-19 11:48:19 -0300 | [diff] [blame] | 647 | */ |
| 648 | int i; |
| 649 | struct { |
| 650 | unsigned char r[4]; |
| 651 | int len; |
| 652 | } regs[] = { |
| 653 | {{ 0x06, 0x02, 0x00, 0x31 }, 4}, |
| 654 | {{ 0x01, 0x02 }, 2}, |
| 655 | {{ 0x01, 0x02, 0x00, 0xc6 }, 4}, |
| 656 | {{ 0x01, 0x00 }, 2}, |
| 657 | {{ 0x01, 0x00, 0xff, 0xaf }, 4}, |
| 658 | {{ 0x01, 0x00, 0x03, 0xa0 }, 4}, |
| 659 | {{ 0x01, 0x00 }, 2}, |
| 660 | {{ 0x01, 0x00, 0x73, 0xaf }, 4}, |
| 661 | }; |
| 662 | |
| 663 | dev->i2c_client.addr = 0x82 >> 1; /* 0x41 */ |
| 664 | |
| 665 | for (i = 0; i < ARRAY_SIZE(regs); i++) |
| 666 | i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len); |
| 667 | }; |
| 668 | |
Antti Palosaari | 33eebec | 2012-10-03 04:28:56 -0300 | [diff] [blame] | 669 | static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe) |
Antti Palosaari | 13a5336 | 2012-07-19 22:28:56 -0300 | [diff] [blame] | 670 | { |
Antti Palosaari | 33eebec | 2012-10-03 04:28:56 -0300 | [diff] [blame] | 671 | struct dtv_frontend_properties *c = &fe->dtv_property_cache; |
Antti Palosaari | 13a5336 | 2012-07-19 22:28:56 -0300 | [diff] [blame] | 672 | struct em28xx *dev = fe->dvb->priv; |
| 673 | #ifdef CONFIG_GPIOLIB |
| 674 | struct em28xx_dvb *dvb = dev->dvb; |
| 675 | int ret; |
| 676 | unsigned long flags; |
| 677 | |
Antti Palosaari | 33eebec | 2012-10-03 04:28:56 -0300 | [diff] [blame] | 678 | if (c->lna == 1) |
| 679 | flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */ |
Antti Palosaari | 13a5336 | 2012-07-19 22:28:56 -0300 | [diff] [blame] | 680 | else |
Antti Palosaari | 33eebec | 2012-10-03 04:28:56 -0300 | [diff] [blame] | 681 | flags = GPIOF_OUT_INIT_LOW; /* disable LNA */ |
Antti Palosaari | 13a5336 | 2012-07-19 22:28:56 -0300 | [diff] [blame] | 682 | |
| 683 | ret = gpio_request_one(dvb->lna_gpio, flags, NULL); |
| 684 | if (ret) |
| 685 | em28xx_errdev("gpio request failed %d\n", ret); |
| 686 | else |
| 687 | gpio_free(dvb->lna_gpio); |
| 688 | |
| 689 | return ret; |
| 690 | #else |
Antti Palosaari | 33eebec | 2012-10-03 04:28:56 -0300 | [diff] [blame] | 691 | dev_warn(&dev->udev->dev, "%s: LNA control is disabled (lna=%u)\n", |
| 692 | KBUILD_MODNAME, c->lna); |
Antti Palosaari | 13a5336 | 2012-07-19 22:28:56 -0300 | [diff] [blame] | 693 | return 0; |
| 694 | #endif |
| 695 | } |
| 696 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 697 | static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe) |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 698 | { |
| 699 | /* Values extracted from a USB trace of the Terratec Windows driver */ |
| 700 | static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c }; |
| 701 | static u8 reset[] = { RESET, 0x80 }; |
| 702 | static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 }; |
| 703 | static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 }; |
| 704 | static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 }; |
| 705 | static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d }; |
| 706 | static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 }; |
| 707 | static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 }; |
| 708 | static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 }; |
Devin Heitmueller | ff69786 | 2009-07-12 18:44:19 -0300 | [diff] [blame] | 709 | static u8 tuner_go[] = { TUNER_GO, 0x01}; |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 710 | |
| 711 | mt352_write(fe, clock_config, sizeof(clock_config)); |
| 712 | udelay(200); |
| 713 | mt352_write(fe, reset, sizeof(reset)); |
| 714 | mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg)); |
| 715 | mt352_write(fe, agc_cfg, sizeof(agc_cfg)); |
| 716 | mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg)); |
| 717 | mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg)); |
| 718 | mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg)); |
| 719 | mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg)); |
| 720 | mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg)); |
| 721 | mt352_write(fe, tuner_go, sizeof(tuner_go)); |
| 722 | return 0; |
| 723 | } |
| 724 | |
| 725 | static struct mt352_config terratec_xs_mt352_cfg = { |
| 726 | .demod_address = (0x1e >> 1), |
| 727 | .no_tuner = 1, |
| 728 | .if2 = 45600, |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 729 | .demod_init = em28xx_mt352_terratec_xs_init, |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 730 | }; |
| 731 | |
Antti Palosaari | 285eb1a | 2009-09-15 14:42:13 -0300 | [diff] [blame] | 732 | static struct tda10023_config em28xx_tda10023_config = { |
| 733 | .demod_address = 0x0c, |
| 734 | .invert = 1, |
| 735 | }; |
| 736 | |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 737 | static struct cxd2820r_config em28xx_cxd2820r_config = { |
| 738 | .i2c_address = (0xd8 >> 1), |
| 739 | .ts_mode = CXD2820R_TS_SERIAL, |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 740 | }; |
| 741 | |
| 742 | static struct tda18271_config em28xx_cxd2820r_tda18271_config = { |
| 743 | .output_opt = TDA18271_OUTPUT_LT_OFF, |
Steve Kerrison | 0db4bf4 | 2011-08-09 07:16:21 -0300 | [diff] [blame] | 744 | .gate = TDA18271_GATE_DIGITAL, |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 745 | }; |
| 746 | |
Antti Palosaari | 3658871 | 2011-08-01 01:15:30 -0300 | [diff] [blame] | 747 | static const struct tda10071_config em28xx_tda10071_config = { |
Michael Krufky | 41f55d5 | 2012-12-16 19:37:11 -0300 | [diff] [blame] | 748 | .demod_i2c_addr = 0x55, /* (0xaa >> 1) */ |
| 749 | .tuner_i2c_addr = 0x14, |
Antti Palosaari | 3658871 | 2011-08-01 01:15:30 -0300 | [diff] [blame] | 750 | .i2c_wr_max = 64, |
| 751 | .ts_mode = TDA10071_TS_SERIAL, |
| 752 | .spec_inv = 0, |
| 753 | .xtal = 40444000, /* 40.444 MHz */ |
| 754 | .pll_multiplier = 20, |
| 755 | }; |
| 756 | |
| 757 | static const struct a8293_config em28xx_a8293_config = { |
| 758 | .i2c_addr = 0x08, /* (0x10 >> 1) */ |
| 759 | }; |
| 760 | |
Aivar Päkk | 1985f6f | 2011-12-11 18:15:00 -0300 | [diff] [blame] | 761 | static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = { |
| 762 | .demod_address = (0x1e >> 1), |
| 763 | .disable_i2c_gate_ctrl = 1, |
| 764 | .no_tuner = 1, |
| 765 | .parallel_ts = 1, |
| 766 | }; |
| 767 | static struct qt1010_config em28xx_qt1010_config = { |
| 768 | .i2c_address = 0x62 |
| 769 | |
| 770 | }; |
| 771 | |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 772 | /* ------------------------------------------------------------------ */ |
| 773 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 774 | static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev) |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 775 | { |
| 776 | struct dvb_frontend *fe; |
Mauro Carvalho Chehab | 3ca9c09 | 2008-04-17 21:37:53 -0300 | [diff] [blame] | 777 | struct xc2028_config cfg; |
| 778 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 779 | memset(&cfg, 0, sizeof(cfg)); |
Mauro Carvalho Chehab | 3ca9c09 | 2008-04-17 21:37:53 -0300 | [diff] [blame] | 780 | cfg.i2c_adap = &dev->i2c_adap; |
| 781 | cfg.i2c_addr = addr; |
Mauro Carvalho Chehab | 3ca9c09 | 2008-04-17 21:37:53 -0300 | [diff] [blame] | 782 | |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 783 | if (!dev->dvb->fe[0]) { |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 784 | em28xx_errdev("/2: dvb frontend not attached. " |
| 785 | "Can't attach xc3028\n"); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 786 | return -EINVAL; |
| 787 | } |
| 788 | |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 789 | fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 790 | if (!fe) { |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 791 | em28xx_errdev("/2: xc3028 attach failed\n"); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 792 | dvb_frontend_detach(dev->dvb->fe[0]); |
| 793 | dev->dvb->fe[0] = NULL; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 794 | return -EINVAL; |
| 795 | } |
| 796 | |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 797 | em28xx_info("%s/2: xc3028 attached\n", dev->name); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 798 | |
| 799 | return 0; |
| 800 | } |
| 801 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 802 | /* ------------------------------------------------------------------ */ |
| 803 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 804 | static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module, |
| 805 | struct em28xx *dev, struct device *device) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 806 | { |
| 807 | int result; |
| 808 | |
| 809 | mutex_init(&dvb->lock); |
| 810 | |
| 811 | /* register adapter */ |
| 812 | result = dvb_register_adapter(&dvb->adapter, dev->name, module, device, |
| 813 | adapter_nr); |
| 814 | if (result < 0) { |
| 815 | printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n", |
| 816 | dev->name, result); |
| 817 | goto fail_adapter; |
| 818 | } |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 819 | |
| 820 | /* Ensure all frontends negotiate bus access */ |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 821 | dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl; |
| 822 | if (dvb->fe[1]) |
| 823 | dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl; |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 824 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 825 | dvb->adapter.priv = dev; |
| 826 | |
| 827 | /* register frontend */ |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 828 | result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 829 | if (result < 0) { |
| 830 | printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n", |
| 831 | dev->name, result); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 832 | goto fail_frontend0; |
| 833 | } |
| 834 | |
| 835 | /* register 2nd frontend */ |
| 836 | if (dvb->fe[1]) { |
| 837 | result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]); |
| 838 | if (result < 0) { |
| 839 | printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n", |
| 840 | dev->name, result); |
| 841 | goto fail_frontend1; |
| 842 | } |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 843 | } |
| 844 | |
| 845 | /* register demux stuff */ |
| 846 | dvb->demux.dmx.capabilities = |
| 847 | DMX_TS_FILTERING | DMX_SECTION_FILTERING | |
| 848 | DMX_MEMORY_BASED_FILTERING; |
| 849 | dvb->demux.priv = dvb; |
| 850 | dvb->demux.filternum = 256; |
| 851 | dvb->demux.feednum = 256; |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 852 | dvb->demux.start_feed = em28xx_start_feed; |
| 853 | dvb->demux.stop_feed = em28xx_stop_feed; |
Mauro Carvalho Chehab | e3569ab | 2008-04-17 21:49:20 -0300 | [diff] [blame] | 854 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 855 | result = dvb_dmx_init(&dvb->demux); |
| 856 | if (result < 0) { |
| 857 | printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n", |
| 858 | dev->name, result); |
| 859 | goto fail_dmx; |
| 860 | } |
| 861 | |
| 862 | dvb->dmxdev.filternum = 256; |
| 863 | dvb->dmxdev.demux = &dvb->demux.dmx; |
| 864 | dvb->dmxdev.capabilities = 0; |
| 865 | result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter); |
| 866 | if (result < 0) { |
| 867 | printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n", |
| 868 | dev->name, result); |
| 869 | goto fail_dmxdev; |
| 870 | } |
| 871 | |
| 872 | dvb->fe_hw.source = DMX_FRONTEND_0; |
| 873 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 874 | if (result < 0) { |
| 875 | printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n", |
| 876 | dev->name, result); |
| 877 | goto fail_fe_hw; |
| 878 | } |
| 879 | |
| 880 | dvb->fe_mem.source = DMX_MEMORY_FE; |
| 881 | result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 882 | if (result < 0) { |
| 883 | printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n", |
| 884 | dev->name, result); |
| 885 | goto fail_fe_mem; |
| 886 | } |
| 887 | |
| 888 | result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 889 | if (result < 0) { |
| 890 | printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n", |
| 891 | dev->name, result); |
| 892 | goto fail_fe_conn; |
| 893 | } |
| 894 | |
| 895 | /* register network adapter */ |
| 896 | dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx); |
| 897 | return 0; |
| 898 | |
| 899 | fail_fe_conn: |
| 900 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 901 | fail_fe_mem: |
| 902 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 903 | fail_fe_hw: |
| 904 | dvb_dmxdev_release(&dvb->dmxdev); |
| 905 | fail_dmxdev: |
| 906 | dvb_dmx_release(&dvb->demux); |
| 907 | fail_dmx: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 908 | if (dvb->fe[1]) |
| 909 | dvb_unregister_frontend(dvb->fe[1]); |
| 910 | dvb_unregister_frontend(dvb->fe[0]); |
| 911 | fail_frontend1: |
| 912 | if (dvb->fe[1]) |
| 913 | dvb_frontend_detach(dvb->fe[1]); |
| 914 | fail_frontend0: |
| 915 | dvb_frontend_detach(dvb->fe[0]); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 916 | dvb_unregister_adapter(&dvb->adapter); |
| 917 | fail_adapter: |
| 918 | return result; |
| 919 | } |
| 920 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 921 | static void em28xx_unregister_dvb(struct em28xx_dvb *dvb) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 922 | { |
| 923 | dvb_net_release(&dvb->net); |
| 924 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem); |
| 925 | dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw); |
| 926 | dvb_dmxdev_release(&dvb->dmxdev); |
| 927 | dvb_dmx_release(&dvb->demux); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 928 | if (dvb->fe[1]) |
| 929 | dvb_unregister_frontend(dvb->fe[1]); |
| 930 | dvb_unregister_frontend(dvb->fe[0]); |
Mauro Carvalho Chehab | c4c3a3d | 2011-07-14 22:23:18 -0300 | [diff] [blame] | 931 | if (dvb->fe[1] && !dvb->dont_attach_fe1) |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 932 | dvb_frontend_detach(dvb->fe[1]); |
| 933 | dvb_frontend_detach(dvb->fe[0]); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 934 | dvb_unregister_adapter(&dvb->adapter); |
| 935 | } |
| 936 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 937 | static int em28xx_dvb_init(struct em28xx *dev) |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 938 | { |
Antti Palosaari | 13a5336 | 2012-07-19 22:28:56 -0300 | [diff] [blame] | 939 | int result = 0, mfe_shared = 0; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 940 | struct em28xx_dvb *dvb; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 941 | |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 942 | if (!dev->board.has_dvb) { |
Devin Heitmueller | df61918 | 2008-06-10 12:34:35 -0300 | [diff] [blame] | 943 | /* This device does not support the extension */ |
Mauro Carvalho Chehab | ca3dfd6 | 2010-09-10 17:29:14 -0300 | [diff] [blame] | 944 | 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] | 945 | return 0; |
| 946 | } |
| 947 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 948 | dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL); |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 949 | |
| 950 | if (dvb == NULL) { |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 951 | em28xx_info("em28xx_dvb: memory allocation failed\n"); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 952 | return -ENOMEM; |
| 953 | } |
| 954 | dev->dvb = dvb; |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 955 | dvb->fe[0] = dvb->fe[1] = NULL; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 956 | |
Mauro Carvalho Chehab | 5013318 | 2010-04-07 17:07:58 -0300 | [diff] [blame] | 957 | mutex_lock(&dev->lock); |
Mauro Carvalho Chehab | c67ec53 | 2008-04-17 21:48:00 -0300 | [diff] [blame] | 958 | em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 959 | /* init frontend */ |
| 960 | switch (dev->model) { |
Mauro Carvalho Chehab | ebaefdb | 2011-06-01 10:16:25 -0300 | [diff] [blame] | 961 | case EM2874_BOARD_LEADERSHIP_ISDBT: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 962 | dvb->fe[0] = dvb_attach(s921_attach, |
Mauro Carvalho Chehab | ca3dfd6 | 2010-09-10 17:29:14 -0300 | [diff] [blame] | 963 | &sharp_isdbt, &dev->i2c_adap); |
| 964 | |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 965 | if (!dvb->fe[0]) { |
Mauro Carvalho Chehab | ca3dfd6 | 2010-09-10 17:29:14 -0300 | [diff] [blame] | 966 | result = -EINVAL; |
| 967 | goto out_free; |
| 968 | } |
| 969 | |
| 970 | break; |
Douglas Schilling Landgraf | f89bc32 | 2008-12-01 21:01:04 -0300 | [diff] [blame] | 971 | case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850: |
Mauro Carvalho Chehab | 10ac660 | 2008-07-27 14:58:58 -0300 | [diff] [blame] | 972 | case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950: |
Devin Heitmueller | 4fd305b | 2008-06-04 13:43:46 -0300 | [diff] [blame] | 973 | case EM2880_BOARD_PINNACLE_PCTV_HD_PRO: |
Devin Heitmueller | e14b365 | 2008-07-26 11:04:33 -0300 | [diff] [blame] | 974 | case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 975 | dvb->fe[0] = dvb_attach(lgdt330x_attach, |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 976 | &em2880_lgdt3303_dev, |
| 977 | &dev->i2c_adap); |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 978 | if (em28xx_attach_xc3028(0x61, dev) < 0) { |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 979 | result = -EINVAL; |
| 980 | goto out_free; |
| 981 | } |
Mauro Carvalho Chehab | 227ad4a | 2008-04-17 21:37:40 -0300 | [diff] [blame] | 982 | break; |
Thierry MERLE | 46510b5 | 2008-10-11 16:56:13 -0300 | [diff] [blame] | 983 | case EM2880_BOARD_KWORLD_DVB_310U: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 984 | dvb->fe[0] = dvb_attach(zl10353_attach, |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 985 | &em28xx_zl10353_with_xc3028, |
| 986 | &dev->i2c_adap); |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 987 | if (em28xx_attach_xc3028(0x61, dev) < 0) { |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 988 | result = -EINVAL; |
| 989 | goto out_free; |
| 990 | } |
Aidan Thornton | 7e6388a | 2008-04-17 21:40:03 -0300 | [diff] [blame] | 991 | break; |
Devin Heitmueller | a84f79a | 2009-07-12 17:05:02 -0300 | [diff] [blame] | 992 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900: |
Uroš Vampl | ec994d0 | 2009-09-30 22:53:37 -0300 | [diff] [blame] | 993 | case EM2882_BOARD_TERRATEC_HYBRID_XS: |
Devin Heitmueller | 01a5fd6 | 2009-08-07 09:25:06 -0300 | [diff] [blame] | 994 | case EM2880_BOARD_EMPIRE_DUAL_TV: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 995 | dvb->fe[0] = dvb_attach(zl10353_attach, |
Devin Heitmueller | a84f79a | 2009-07-12 17:05:02 -0300 | [diff] [blame] | 996 | &em28xx_zl10353_xc3028_no_i2c_gate, |
| 997 | &dev->i2c_adap); |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 998 | if (em28xx_attach_xc3028(0x61, dev) < 0) { |
Devin Heitmueller | a84f79a | 2009-07-12 17:05:02 -0300 | [diff] [blame] | 999 | result = -EINVAL; |
| 1000 | goto out_free; |
| 1001 | } |
| 1002 | break; |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 1003 | case EM2880_BOARD_TERRATEC_HYBRID_XS: |
Catimimi | 6563801 | 2010-02-18 18:06:32 -0300 | [diff] [blame] | 1004 | case EM2880_BOARD_TERRATEC_HYBRID_XS_FR: |
Devin Heitmueller | d5b3ba9 | 2009-07-08 21:51:35 -0300 | [diff] [blame] | 1005 | case EM2881_BOARD_PINNACLE_HYBRID_PRO: |
Andrea.Amorosi76@gmail.com | 7ca7ef6 | 2010-02-09 17:53:38 -0300 | [diff] [blame] | 1006 | case EM2882_BOARD_DIKOM_DK300: |
Antonio Larrosa | 811fab6 | 2010-03-04 22:19:48 -0300 | [diff] [blame] | 1007 | case EM2882_BOARD_KWORLD_VS_DVBT: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 1008 | dvb->fe[0] = dvb_attach(zl10353_attach, |
Devin Heitmueller | a84f79a | 2009-07-12 17:05:02 -0300 | [diff] [blame] | 1009 | &em28xx_zl10353_xc3028_no_i2c_gate, |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 1010 | &dev->i2c_adap); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 1011 | if (dvb->fe[0] == NULL) { |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 1012 | /* This board could have either a zl10353 or a mt352. |
| 1013 | If the chip id isn't for zl10353, try mt352 */ |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 1014 | dvb->fe[0] = dvb_attach(mt352_attach, |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 1015 | &terratec_xs_mt352_cfg, |
| 1016 | &dev->i2c_adap); |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 1017 | } |
Devin Heitmueller | 4fb202a | 2009-07-12 17:51:12 -0300 | [diff] [blame] | 1018 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 1019 | if (em28xx_attach_xc3028(0x61, dev) < 0) { |
Devin Heitmueller | f797608 | 2009-06-22 22:32:32 -0300 | [diff] [blame] | 1020 | result = -EINVAL; |
| 1021 | goto out_free; |
| 1022 | } |
| 1023 | break; |
Aivar Päkk | 1985f6f | 2011-12-11 18:15:00 -0300 | [diff] [blame] | 1024 | case EM2870_BOARD_KWORLD_355U: |
| 1025 | dvb->fe[0] = dvb_attach(zl10353_attach, |
| 1026 | &em28xx_zl10353_no_i2c_gate_dev, |
| 1027 | &dev->i2c_adap); |
| 1028 | if (dvb->fe[0] != NULL) |
| 1029 | dvb_attach(qt1010_attach, dvb->fe[0], |
| 1030 | &dev->i2c_adap, &em28xx_qt1010_config); |
| 1031 | break; |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 1032 | case EM2883_BOARD_KWORLD_HYBRID_330U: |
Devin Heitmueller | 1985922 | 2009-06-19 00:33:54 -0300 | [diff] [blame] | 1033 | case EM2882_BOARD_EVGA_INDTUBE: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 1034 | dvb->fe[0] = dvb_attach(s5h1409_attach, |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 1035 | &em28xx_s5h1409_with_xc3028, |
| 1036 | &dev->i2c_adap); |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 1037 | if (em28xx_attach_xc3028(0x61, dev) < 0) { |
Robert Krakora | 6e7b9ea | 2009-01-18 21:59:34 -0300 | [diff] [blame] | 1038 | result = -EINVAL; |
| 1039 | goto out_free; |
| 1040 | } |
| 1041 | break; |
Franklin Meng | d7de5d8 | 2009-06-06 17:05:02 -0300 | [diff] [blame] | 1042 | case EM2882_BOARD_KWORLD_ATSC_315U: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 1043 | dvb->fe[0] = dvb_attach(lgdt330x_attach, |
Franklin Meng | d7de5d8 | 2009-06-06 17:05:02 -0300 | [diff] [blame] | 1044 | &em2880_lgdt3303_dev, |
| 1045 | &dev->i2c_adap); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 1046 | if (dvb->fe[0] != NULL) { |
| 1047 | if (!dvb_attach(simple_tuner_attach, dvb->fe[0], |
Franklin Meng | d7de5d8 | 2009-06-06 17:05:02 -0300 | [diff] [blame] | 1048 | &dev->i2c_adap, 0x61, TUNER_THOMSON_DTT761X)) { |
| 1049 | result = -EINVAL; |
| 1050 | goto out_free; |
| 1051 | } |
| 1052 | } |
| 1053 | break; |
Devin Heitmueller | 17d9d55 | 2008-06-08 10:22:03 -0300 | [diff] [blame] | 1054 | case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2: |
Devin Heitmueller | ad9b4bb | 2011-03-13 02:09:59 -0300 | [diff] [blame] | 1055 | case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 1056 | dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL, |
Devin Heitmueller | 75e2b86 | 2011-03-13 02:01:02 -0300 | [diff] [blame] | 1057 | &dev->i2c_adap, &dev->udev->dev); |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 1058 | if (em28xx_attach_xc3028(0x61, dev) < 0) { |
Devin Heitmueller | 17d9d55 | 2008-06-08 10:22:03 -0300 | [diff] [blame] | 1059 | result = -EINVAL; |
| 1060 | goto out_free; |
| 1061 | } |
| 1062 | break; |
Antti Palosaari | 285eb1a | 2009-09-15 14:42:13 -0300 | [diff] [blame] | 1063 | case EM2870_BOARD_REDDO_DVB_C_USB_BOX: |
| 1064 | /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */ |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 1065 | dvb->fe[0] = dvb_attach(tda10023_attach, |
Antti Palosaari | 285eb1a | 2009-09-15 14:42:13 -0300 | [diff] [blame] | 1066 | &em28xx_tda10023_config, |
| 1067 | &dev->i2c_adap, 0x48); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 1068 | if (dvb->fe[0]) { |
| 1069 | if (!dvb_attach(simple_tuner_attach, dvb->fe[0], |
Antti Palosaari | 285eb1a | 2009-09-15 14:42:13 -0300 | [diff] [blame] | 1070 | &dev->i2c_adap, 0x60, TUNER_PHILIPS_CU1216L)) { |
| 1071 | result = -EINVAL; |
| 1072 | goto out_free; |
| 1073 | } |
| 1074 | } |
| 1075 | break; |
Jarod Wilson | 7e48b30 | 2010-03-07 17:55:43 -0300 | [diff] [blame] | 1076 | case EM2870_BOARD_KWORLD_A340: |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 1077 | dvb->fe[0] = dvb_attach(lgdt3305_attach, |
Jarod Wilson | 7e48b30 | 2010-03-07 17:55:43 -0300 | [diff] [blame] | 1078 | &em2870_lgdt3304_dev, |
| 1079 | &dev->i2c_adap); |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 1080 | if (dvb->fe[0] != NULL) |
| 1081 | dvb_attach(tda18271_attach, dvb->fe[0], 0x60, |
Jarod Wilson | 7e48b30 | 2010-03-07 17:55:43 -0300 | [diff] [blame] | 1082 | &dev->i2c_adap, &kworld_a340_config); |
| 1083 | break; |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 1084 | case EM28174_BOARD_PCTV_290E: |
Antti Palosaari | a36a66d | 2012-08-16 21:07:23 -0300 | [diff] [blame] | 1085 | /* set default GPIO0 for LNA, used if GPIOLIB is undefined */ |
| 1086 | dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O | |
| 1087 | CXD2820R_GPIO_L; |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 1088 | dvb->fe[0] = dvb_attach(cxd2820r_attach, |
Manu Abraham | 7e7b828 | 2011-12-10 00:44:24 -0300 | [diff] [blame] | 1089 | &em28xx_cxd2820r_config, |
Antti Palosaari | 1e8f31f | 2012-07-19 21:10:36 -0300 | [diff] [blame] | 1090 | &dev->i2c_adap, |
Antti Palosaari | 13a5336 | 2012-07-19 22:28:56 -0300 | [diff] [blame] | 1091 | &dvb->lna_gpio); |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 1092 | if (dvb->fe[0]) { |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 1093 | /* FE 0 attach tuner */ |
Manu Abraham | 7e7b828 | 2011-12-10 00:44:24 -0300 | [diff] [blame] | 1094 | if (!dvb_attach(tda18271_attach, |
| 1095 | dvb->fe[0], |
| 1096 | 0x60, |
| 1097 | &dev->i2c_adap, |
| 1098 | &em28xx_cxd2820r_tda18271_config)) { |
| 1099 | |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 1100 | dvb_frontend_detach(dvb->fe[0]); |
| 1101 | result = -EINVAL; |
| 1102 | goto out_free; |
| 1103 | } |
Antti Palosaari | 1e8f31f | 2012-07-19 21:10:36 -0300 | [diff] [blame] | 1104 | |
Antti Palosaari | 13a5336 | 2012-07-19 22:28:56 -0300 | [diff] [blame] | 1105 | #ifdef CONFIG_GPIOLIB |
Antti Palosaari | 0c42a55 | 2012-09-19 20:52:21 -0300 | [diff] [blame] | 1106 | /* enable LNA for DVB-T, DVB-T2 and DVB-C */ |
| 1107 | result = gpio_request_one(dvb->lna_gpio, |
| 1108 | GPIOF_OUT_INIT_LOW, NULL); |
| 1109 | if (result) |
| 1110 | em28xx_errdev("gpio request failed %d\n", |
| 1111 | result); |
| 1112 | else |
| 1113 | gpio_free(dvb->lna_gpio); |
Antti Palosaari | 1e8f31f | 2012-07-19 21:10:36 -0300 | [diff] [blame] | 1114 | |
Antti Palosaari | 0c42a55 | 2012-09-19 20:52:21 -0300 | [diff] [blame] | 1115 | result = 0; /* continue even set LNA fails */ |
Antti Palosaari | 13a5336 | 2012-07-19 22:28:56 -0300 | [diff] [blame] | 1116 | #endif |
Antti Palosaari | 0c42a55 | 2012-09-19 20:52:21 -0300 | [diff] [blame] | 1117 | dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna; |
| 1118 | } |
| 1119 | |
Antti Palosaari | d6a5f92 | 2011-04-07 16:34:44 -0300 | [diff] [blame] | 1120 | break; |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 1121 | case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C: |
Mauro Carvalho Chehab | 8503232 | 2011-11-24 15:01:45 -0200 | [diff] [blame] | 1122 | { |
| 1123 | struct xc5000_config cfg; |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 1124 | hauppauge_hvr930c_init(dev); |
| 1125 | |
Mauro Carvalho Chehab | de72405 | 2011-11-20 11:23:24 -0200 | [diff] [blame] | 1126 | dvb->fe[0] = dvb_attach(drxk_attach, |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 1127 | &hauppauge_930c_drxk, &dev->i2c_adap); |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 1128 | if (!dvb->fe[0]) { |
| 1129 | result = -EINVAL; |
| 1130 | goto out_free; |
| 1131 | } |
| 1132 | /* FIXME: do we need a pll semaphore? */ |
| 1133 | dvb->fe[0]->sec_priv = dvb; |
| 1134 | sema_init(&dvb->pll_mutex, 1); |
| 1135 | dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl; |
| 1136 | dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl; |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 1137 | |
| 1138 | /* Attach xc5000 */ |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 1139 | memset(&cfg, 0, sizeof(cfg)); |
| 1140 | cfg.i2c_address = 0x61; |
Mauro Carvalho Chehab | de72405 | 2011-11-20 11:23:24 -0200 | [diff] [blame] | 1141 | cfg.if_khz = 4000; |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 1142 | |
| 1143 | if (dvb->fe[0]->ops.i2c_gate_ctrl) |
| 1144 | dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1); |
Mauro Carvalho Chehab | de72405 | 2011-11-20 11:23:24 -0200 | [diff] [blame] | 1145 | if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap, |
| 1146 | &cfg)) { |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 1147 | result = -EINVAL; |
| 1148 | goto out_free; |
| 1149 | } |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 1150 | if (dvb->fe[0]->ops.i2c_gate_ctrl) |
| 1151 | dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0); |
| 1152 | |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 1153 | break; |
Mauro Carvalho Chehab | 8503232 | 2011-11-24 15:01:45 -0200 | [diff] [blame] | 1154 | } |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 1155 | case EM2884_BOARD_TERRATEC_H5: |
| 1156 | terratec_h5_init(dev); |
| 1157 | |
Mauro Carvalho Chehab | fa4b2a1 | 2012-01-05 08:07:32 -0200 | [diff] [blame] | 1158 | 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] | 1159 | if (!dvb->fe[0]) { |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 1160 | result = -EINVAL; |
| 1161 | goto out_free; |
| 1162 | } |
| 1163 | /* FIXME: do we need a pll semaphore? */ |
| 1164 | dvb->fe[0]->sec_priv = dvb; |
| 1165 | sema_init(&dvb->pll_mutex, 1); |
| 1166 | dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl; |
| 1167 | dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl; |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 1168 | |
Mauro Carvalho Chehab | c4c3a3d | 2011-07-14 22:23:18 -0300 | [diff] [blame] | 1169 | /* Attach tda18271 to DVB-C frontend */ |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 1170 | if (dvb->fe[0]->ops.i2c_gate_ctrl) |
| 1171 | dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1); |
| 1172 | if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap, 0x60)) { |
| 1173 | result = -EINVAL; |
| 1174 | goto out_free; |
| 1175 | } |
| 1176 | if (dvb->fe[0]->ops.i2c_gate_ctrl) |
| 1177 | dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0); |
Mauro Carvalho Chehab | c4c3a3d | 2011-07-14 22:23:18 -0300 | [diff] [blame] | 1178 | |
Mauro Carvalho Chehab | fec528b | 2011-07-03 21:05:06 -0300 | [diff] [blame] | 1179 | break; |
Antti Palosaari | 3658871 | 2011-08-01 01:15:30 -0300 | [diff] [blame] | 1180 | case EM28174_BOARD_PCTV_460E: |
| 1181 | /* attach demod */ |
| 1182 | dvb->fe[0] = dvb_attach(tda10071_attach, |
| 1183 | &em28xx_tda10071_config, &dev->i2c_adap); |
| 1184 | |
| 1185 | /* attach SEC */ |
| 1186 | if (dvb->fe[0]) |
| 1187 | dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap, |
| 1188 | &em28xx_a8293_config); |
| 1189 | break; |
Antti Palosaari | 3553085 | 2012-03-18 18:09:01 -0300 | [diff] [blame] | 1190 | case EM2874_BOARD_MAXMEDIA_UB425_TC: |
| 1191 | /* attach demodulator */ |
| 1192 | dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk, |
| 1193 | &dev->i2c_adap); |
| 1194 | |
| 1195 | if (dvb->fe[0]) { |
| 1196 | /* disable I2C-gate */ |
| 1197 | dvb->fe[0]->ops.i2c_gate_ctrl = NULL; |
| 1198 | |
| 1199 | /* attach tuner */ |
| 1200 | if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], |
| 1201 | &dev->i2c_adap, 0x60)) { |
| 1202 | dvb_frontend_detach(dvb->fe[0]); |
| 1203 | result = -EINVAL; |
| 1204 | goto out_free; |
| 1205 | } |
| 1206 | } |
| 1207 | |
| 1208 | /* TODO: we need drx-3913k firmware in order to support DVB-T */ |
| 1209 | em28xx_info("MaxMedia UB425-TC: only DVB-C supported by that " \ |
| 1210 | "driver version\n"); |
| 1211 | |
| 1212 | break; |
Ivan Kalvachev | fa5527c | 2012-03-19 20:09:55 -0300 | [diff] [blame] | 1213 | case EM2884_BOARD_PCTV_510E: |
| 1214 | case EM2884_BOARD_PCTV_520E: |
| 1215 | pctv_520e_init(dev); |
| 1216 | |
| 1217 | /* attach demodulator */ |
| 1218 | dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk, |
| 1219 | &dev->i2c_adap); |
| 1220 | |
| 1221 | if (dvb->fe[0]) { |
| 1222 | /* attach tuner */ |
| 1223 | if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60, |
| 1224 | &dev->i2c_adap, |
| 1225 | &em28xx_cxd2820r_tda18271_config)) { |
| 1226 | dvb_frontend_detach(dvb->fe[0]); |
| 1227 | result = -EINVAL; |
| 1228 | goto out_free; |
| 1229 | } |
| 1230 | } |
| 1231 | break; |
Martin Blumenstingl | c8dce00 | 2012-06-12 18:19:28 -0300 | [diff] [blame] | 1232 | case EM2884_BOARD_CINERGY_HTC_STICK: |
| 1233 | terratec_htc_stick_init(dev); |
| 1234 | |
| 1235 | /* attach demodulator */ |
| 1236 | dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk, |
| 1237 | &dev->i2c_adap); |
| 1238 | if (!dvb->fe[0]) { |
| 1239 | result = -EINVAL; |
| 1240 | goto out_free; |
| 1241 | } |
| 1242 | |
| 1243 | /* Attach the demodulator. */ |
| 1244 | if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60, |
| 1245 | &dev->i2c_adap, |
| 1246 | &em28xx_cxd2820r_tda18271_config)) { |
| 1247 | result = -EINVAL; |
| 1248 | goto out_free; |
| 1249 | } |
| 1250 | break; |
Martin Blumenstingl | 8904013 | 2012-10-04 14:22:54 -0300 | [diff] [blame] | 1251 | case EM2884_BOARD_TERRATEC_HTC_USB_XS: |
| 1252 | terratec_htc_usb_xs_init(dev); |
| 1253 | |
| 1254 | /* attach demodulator */ |
| 1255 | dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk, |
| 1256 | &dev->i2c_adap); |
| 1257 | if (!dvb->fe[0]) { |
| 1258 | result = -EINVAL; |
| 1259 | goto out_free; |
| 1260 | } |
| 1261 | |
| 1262 | /* Attach the demodulator. */ |
| 1263 | if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60, |
| 1264 | &dev->i2c_adap, |
| 1265 | &em28xx_cxd2820r_tda18271_config)) { |
| 1266 | result = -EINVAL; |
| 1267 | goto out_free; |
| 1268 | } |
| 1269 | break; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 1270 | default: |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 1271 | em28xx_errdev("/2: The frontend of your DVB/ATSC card" |
| 1272 | " isn't supported yet\n"); |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 1273 | break; |
| 1274 | } |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 1275 | if (NULL == dvb->fe[0]) { |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 1276 | em28xx_errdev("/2: frontend initialization failed\n"); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 1277 | result = -EINVAL; |
| 1278 | goto out_free; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 1279 | } |
Michael Krufky | d7cba04 | 2008-09-12 13:31:45 -0300 | [diff] [blame] | 1280 | /* define general-purpose callback pointer */ |
Antti Palosaari | f71095b | 2011-04-07 15:51:52 -0300 | [diff] [blame] | 1281 | dvb->fe[0]->callback = em28xx_tuner_callback; |
Eddi De Pieri | 82e7dbb | 2011-11-19 11:37:14 -0300 | [diff] [blame] | 1282 | if (dvb->fe[1]) |
Mauro Carvalho Chehab | de72405 | 2011-11-20 11:23:24 -0200 | [diff] [blame] | 1283 | dvb->fe[1]->callback = em28xx_tuner_callback; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 1284 | |
| 1285 | /* register everything */ |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 1286 | result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 1287 | |
Douglas Schilling Landgraf | 6ea54d9 | 2008-04-17 21:41:10 -0300 | [diff] [blame] | 1288 | if (result < 0) |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 1289 | goto out_free; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 1290 | |
Antti Palosaari | e364543 | 2011-07-28 18:59:30 -0300 | [diff] [blame] | 1291 | /* MFE lock */ |
| 1292 | dvb->adapter.mfe_shared = mfe_shared; |
| 1293 | |
Filipe Rosset | 480be18 | 2009-11-04 15:32:37 -0300 | [diff] [blame] | 1294 | em28xx_info("Successfully loaded em28xx-dvb\n"); |
Mauro Carvalho Chehab | 5013318 | 2010-04-07 17:07:58 -0300 | [diff] [blame] | 1295 | ret: |
| 1296 | em28xx_set_mode(dev, EM28XX_SUSPEND); |
| 1297 | mutex_unlock(&dev->lock); |
| 1298 | return result; |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 1299 | |
| 1300 | out_free: |
| 1301 | kfree(dvb); |
| 1302 | dev->dvb = NULL; |
Mauro Carvalho Chehab | 5013318 | 2010-04-07 17:07:58 -0300 | [diff] [blame] | 1303 | goto ret; |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 1304 | } |
| 1305 | |
Chris Rankin | 0b8bd83 | 2011-08-20 16:01:26 -0300 | [diff] [blame] | 1306 | static inline void prevent_sleep(struct dvb_frontend_ops *ops) |
| 1307 | { |
| 1308 | ops->set_voltage = NULL; |
| 1309 | ops->sleep = NULL; |
| 1310 | ops->tuner_ops.sleep = NULL; |
| 1311 | } |
| 1312 | |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 1313 | static int em28xx_dvb_fini(struct em28xx *dev) |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 1314 | { |
Mauro Carvalho Chehab | 505b6d0 | 2008-11-25 09:39:50 -0300 | [diff] [blame] | 1315 | if (!dev->board.has_dvb) { |
Devin Heitmueller | df61918 | 2008-06-10 12:34:35 -0300 | [diff] [blame] | 1316 | /* This device does not support the extension */ |
| 1317 | return 0; |
| 1318 | } |
| 1319 | |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 1320 | if (dev->dvb) { |
Chris Rankin | 0b8bd83 | 2011-08-20 16:01:26 -0300 | [diff] [blame] | 1321 | struct em28xx_dvb *dvb = dev->dvb; |
| 1322 | |
| 1323 | if (dev->state & DEV_DISCONNECTED) { |
| 1324 | /* We cannot tell the device to sleep |
| 1325 | * once it has been unplugged. */ |
| 1326 | if (dvb->fe[0]) |
| 1327 | prevent_sleep(&dvb->fe[0]->ops); |
| 1328 | if (dvb->fe[1]) |
| 1329 | prevent_sleep(&dvb->fe[1]->ops); |
| 1330 | } |
| 1331 | |
| 1332 | em28xx_unregister_dvb(dvb); |
| 1333 | kfree(dvb); |
Aidan Thornton | 3421b77 | 2008-04-17 21:40:36 -0300 | [diff] [blame] | 1334 | dev->dvb = NULL; |
| 1335 | } |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 1336 | |
| 1337 | return 0; |
| 1338 | } |
| 1339 | |
| 1340 | static struct em28xx_ops dvb_ops = { |
| 1341 | .id = EM28XX_DVB, |
| 1342 | .name = "Em28xx dvb Extension", |
Jarod Wilson | f2d0c1c | 2011-07-14 19:06:08 -0300 | [diff] [blame] | 1343 | .init = em28xx_dvb_init, |
| 1344 | .fini = em28xx_dvb_fini, |
Mauro Carvalho Chehab | 3aefb79 | 2008-04-17 21:36:41 -0300 | [diff] [blame] | 1345 | }; |
| 1346 | |
| 1347 | static int __init em28xx_dvb_register(void) |
| 1348 | { |
| 1349 | return em28xx_register_extension(&dvb_ops); |
| 1350 | } |
| 1351 | |
| 1352 | static void __exit em28xx_dvb_unregister(void) |
| 1353 | { |
| 1354 | em28xx_unregister_extension(&dvb_ops); |
| 1355 | } |
| 1356 | |
| 1357 | module_init(em28xx_dvb_register); |
| 1358 | module_exit(em28xx_dvb_unregister); |