blob: a70b19e07e370ab4f84dc61277bf9cc9f674fb48 [file] [log] [blame]
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001/*
2 DVB device driver for em28xx
3
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03004 (c) 2008-2011 Mauro Carvalho Chehab <mchehab@infradead.org>
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03005
Devin Heitmuellerbdfbf952008-04-17 21:38:27 -03006 (c) 2008 Devin Heitmueller <devin.heitmueller@gmail.com>
7 - Fixes for the driver to properly work with HVR-950
Devin Heitmueller4fd305b2008-06-04 13:43:46 -03008 - Fixes for the driver to properly work with Pinnacle PCTV HD Pro Stick
Devin Heitmuellere14b3652008-07-26 11:04:33 -03009 - Fixes for the driver to properly work with AMD ATI TV Wonder HD 600
Devin Heitmuellerbdfbf952008-04-17 21:38:27 -030010
Aidan Thornton3421b772008-04-17 21:40:36 -030011 (c) 2008 Aidan Thornton <makosoft@googlemail.com>
12
Frank Schaefera950e4a2012-11-08 14:11:47 -030013 (c) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
14
Aidan Thornton3421b772008-04-17 21:40:36 -030015 Based on cx88-dvb, saa7134-dvb and videobuf-dvb originally written by:
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030016 (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 Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030026#include <linux/usb.h>
27
28#include "em28xx.h"
29#include <media/v4l2-common.h>
30#include <media/videobuf-vmalloc.h>
Franklin Mengd7de5d82009-06-06 17:05:02 -030031#include <media/tuner.h>
32#include "tuner-simple.h"
Antti Palosaari1e8f31f2012-07-19 21:10:36 -030033#include <linux/gpio.h>
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030034
35#include "lgdt330x.h"
Jarod Wilson7e48b302010-03-07 17:55:43 -030036#include "lgdt3305.h"
Aidan Thornton7e6388a2008-04-17 21:40:03 -030037#include "zl10353.h"
Robert Krakora6e7b9ea2009-01-18 21:59:34 -030038#include "s5h1409.h"
Devin Heitmueller4fb202a2009-07-12 17:51:12 -030039#include "mt352.h"
40#include "mt352_priv.h" /* FIXME */
Antti Palosaari285eb1a2009-09-15 14:42:13 -030041#include "tda1002x.h"
Jarod Wilson7e48b302010-03-07 17:55:43 -030042#include "tda18271.h"
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -030043#include "s921.h"
Devin Heitmueller75e2b862011-03-13 02:01:02 -030044#include "drxd.h"
Antti Palosaarid6a5f922011-04-07 16:34:44 -030045#include "cxd2820r.h"
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -030046#include "tda18271c2dd.h"
47#include "drxk.h"
Antti Palosaari36588712011-08-01 01:15:30 -030048#include "tda10071.h"
49#include "a8293.h"
Aivar Päkk1985f6f2011-12-11 18:15:00 -030050#include "qt1010.h"
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030051
52MODULE_DESCRIPTION("driver for em28xx based DVB cards");
53MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
54MODULE_LICENSE("GPL");
55
56static unsigned int debug;
57module_param(debug, int, 0644);
58MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
59
60DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
61
62#define dprintk(level, fmt, arg...) do { \
63if (debug >= level) \
Aidan Thornton3421b772008-04-17 21:40:36 -030064 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030065} while (0)
66
Aidan Thornton3421b772008-04-17 21:40:36 -030067struct em28xx_dvb {
Antti Palosaarif71095b2011-04-07 15:51:52 -030068 struct dvb_frontend *fe[2];
Aidan Thornton3421b772008-04-17 21:40:36 -030069
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 Chehabfec528b2011-07-03 21:05:06 -030081
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -030082 /* Due to DRX-K - probably need changes */
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -030083 int (*gate_ctrl)(struct dvb_frontend *, int);
84 struct semaphore pll_mutex;
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -030085 bool dont_attach_fe1;
Antti Palosaari13a53362012-07-19 22:28:56 -030086 int lna_gpio;
Aidan Thornton3421b772008-04-17 21:40:36 -030087};
88
89
90static inline void print_err_status(struct em28xx *dev,
91 int packet, int status)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030092{
Aidan Thornton3421b772008-04-17 21:40:36 -030093 char *errmsg = "Unknown";
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030094
Aidan Thornton3421b772008-04-17 21:40:36 -030095 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 Landgraf6ea54d92008-04-17 21:41:10 -0300124 dprintk(1, "URB packet %d, status %d [%s].\n",
125 packet, status, errmsg);
Aidan Thornton3421b772008-04-17 21:40:36 -0300126 }
127}
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300128
Frank Schaefera950e4a2012-11-08 14:11:47 -0300129static inline int em28xx_dvb_urb_data_copy(struct em28xx *dev, struct urb *urb)
Aidan Thornton3421b772008-04-17 21:40:36 -0300130{
Frank Schaefera950e4a2012-11-08 14:11:47 -0300131 int xfer_bulk, num_packets, i;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300132
Aidan Thornton3421b772008-04-17 21:40:36 -0300133 if (!dev)
134 return 0;
135
136 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
137 return 0;
138
Frank Schaefer1653cb0c2012-11-08 14:11:44 -0300139 if (urb->status < 0)
Aidan Thornton3421b772008-04-17 21:40:36 -0300140 print_err_status(dev, -1, urb->status);
Aidan Thornton3421b772008-04-17 21:40:36 -0300141
Frank Schaefera950e4a2012-11-08 14:11:47 -0300142 xfer_bulk = usb_pipebulk(urb->pipe);
Aidan Thornton3421b772008-04-17 21:40:36 -0300143
Frank Schaefera950e4a2012-11-08 14:11:47 -0300144 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 Thornton3421b772008-04-17 21:40:36 -0300169 }
Aidan Thornton3421b772008-04-17 21:40:36 -0300170 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300171
172 return 0;
173}
174
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300175static int em28xx_start_streaming(struct em28xx_dvb *dvb)
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300176{
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300177 int rc;
Aidan Thornton3421b772008-04-17 21:40:36 -0300178 struct em28xx *dev = dvb->adapter.priv;
Frank Schaeferc647a912012-11-08 14:11:52 -0300179 int dvb_max_packet_size, packet_multiplier, dvb_alt;
Aidan Thornton3421b772008-04-17 21:40:36 -0300180
Frank Schaeferc647a912012-11-08 14:11:52 -0300181 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 Chehabc67ec532008-04-17 21:48:00 -0300198 rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
199 if (rc < 0)
200 return rc;
Aidan Thornton3421b772008-04-17 21:40:36 -0300201
Gianluca Gennari86d38d12012-02-13 13:59:22 -0300202 dprintk(1, "Using %d buffers each with %d x %d bytes\n",
Mauro Carvalho Chehabf7acc4b2011-07-28 15:42:00 -0300203 EM28XX_DVB_NUM_BUFS,
Frank Schaeferc647a912012-11-08 14:11:52 -0300204 packet_multiplier,
205 dvb_max_packet_size);
Devin Heitmuellerd18e2fd2009-05-16 17:09:28 -0300206
Frank Schaeferc647a912012-11-08 14:11:52 -0300207 return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE,
208 dev->dvb_xfer_bulk,
Frank Schaefer057ca0d2012-11-08 14:11:42 -0300209 EM28XX_DVB_NUM_BUFS,
Frank Schaeferc647a912012-11-08 14:11:52 -0300210 dvb_max_packet_size,
211 packet_multiplier,
Frank Schaefera950e4a2012-11-08 14:11:47 -0300212 em28xx_dvb_urb_data_copy);
Aidan Thornton3421b772008-04-17 21:40:36 -0300213}
214
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300215static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300216{
Aidan Thornton3421b772008-04-17 21:40:36 -0300217 struct em28xx *dev = dvb->adapter.priv;
218
Gianluca Gennari5f5f1472012-03-22 08:48:17 -0300219 em28xx_stop_urbs(dev);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300220
Mauro Carvalho Chehab2fe3e2e2008-11-27 09:10:40 -0300221 em28xx_set_mode(dev, EM28XX_SUSPEND);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300222
Aidan Thornton3421b772008-04-17 21:40:36 -0300223 return 0;
224}
225
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300226static int em28xx_start_feed(struct dvb_demux_feed *feed)
Aidan Thornton3421b772008-04-17 21:40:36 -0300227{
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 Wilsonf2d0c1c2011-07-14 19:06:08 -0300240 ret = em28xx_start_streaming(dvb);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300241 if (ret < 0)
242 rc = ret;
Aidan Thornton3421b772008-04-17 21:40:36 -0300243 }
244
245 mutex_unlock(&dvb->lock);
246 return rc;
247}
248
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300249static int em28xx_stop_feed(struct dvb_demux_feed *feed)
Aidan Thornton3421b772008-04-17 21:40:36 -0300250{
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 Landgraf6ea54d92008-04-17 21:41:10 -0300257
258 if (0 == dvb->nfeeds)
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300259 err = em28xx_stop_streaming(dvb);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300260
Aidan Thornton3421b772008-04-17 21:40:36 -0300261 mutex_unlock(&dvb->lock);
262 return err;
263}
264
265
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300266
267/* ------------------------------------------------------------------ */
268static 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 Chehab2fe3e2e2008-11-27 09:10:40 -0300275 return em28xx_set_mode(dev, EM28XX_SUSPEND);
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300276}
277
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300278/* ------------------------------------------------------------------ */
279
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -0300280static struct lgdt330x_config em2880_lgdt3303_dev = {
281 .demod_address = 0x0e,
282 .demod_chip = LGDT3303,
283};
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300284
Jarod Wilson7e48b302010-03-07 17:55:43 -0300285static 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 Chehabca3dfd62010-09-10 17:29:14 -0300297static struct s921_config sharp_isdbt = {
298 .demod_address = 0x30 >> 1
299};
300
Aidan Thornton7e6388a2008-04-17 21:40:03 -0300301static 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 Krakora6e7b9ea2009-01-18 21:59:34 -0300308static 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 Wilson7e48b302010-03-07 17:55:43 -0300317static 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
324static struct tda18271_config kworld_a340_config = {
325 .std_map = &kworld_a340_std_map,
326};
327
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300328static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300329 .demod_address = (0x1e >> 1),
330 .no_tuner = 1,
331 .disable_i2c_gate_ctrl = 1,
332 .parallel_ts = 1,
333 .if2 = 45600,
334};
335
Devin Heitmueller75e2b862011-03-13 02:01:02 -0300336static struct drxd_config em28xx_drxd = {
Mauro Carvalho Chehabaac865f2011-12-26 09:41:14 -0300337 .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 Heitmueller6b142b32011-03-13 02:02:01 -0300343 .disable_i2c_gate_ctrl = 1,
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300344};
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300345
Ezequiel García61bdbef2012-06-12 09:53:41 -0300346static struct drxk_config terratec_h5_drxk = {
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300347 .adr = 0x29,
Mauro Carvalho Chehabe4f4f872011-07-09 17:35:26 -0300348 .single_master = 1,
Mauro Carvalho Chehabf1fe1b72011-07-09 21:59:33 -0300349 .no_i2c_bridge = 1,
Mauro Carvalho Chehab8b9456a2011-07-11 14:33:51 -0300350 .microcode_name = "dvb-usb-terratec-h5-drxk.fw",
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300351 .qam_demod_parameter_count = 2,
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300352 .load_firmware_sync = true,
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300353};
354
Ezequiel García61bdbef2012-06-12 09:53:41 -0300355static struct drxk_config hauppauge_930c_drxk = {
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300356 .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 Blumenstingl9e23f50a2012-07-04 17:36:55 -0300361 .qam_demod_parameter_count = 2,
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300362 .load_firmware_sync = true,
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300363};
364
Martin Blumenstingl89040132012-10-04 14:22:54 -0300365static struct drxk_config terratec_htc_stick_drxk = {
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300366 .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 Blumenstingl9e23f50a2012-07-04 17:36:55 -0300371 .qam_demod_parameter_count = 2,
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300372 /* 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 Chehab2425bb32012-10-02 16:02:57 -0300376 .load_firmware_sync = true,
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300377};
378
Ezequiel García61bdbef2012-06-12 09:53:41 -0300379static struct drxk_config maxmedia_ub425_tc_drxk = {
Antti Palosaari35530852012-03-18 18:09:01 -0300380 .adr = 0x29,
381 .single_master = 1,
382 .no_i2c_bridge = 1,
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300383 .load_firmware_sync = true,
Antti Palosaari35530852012-03-18 18:09:01 -0300384};
385
Ezequiel García61bdbef2012-06-12 09:53:41 -0300386static struct drxk_config pctv_520e_drxk = {
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300387 .adr = 0x29,
388 .single_master = 1,
389 .microcode_name = "dvb-demod-drxk-pctv.fw",
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300390 .qam_demod_parameter_count = 2,
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300391 .chunk_size = 58,
Antti Palosaarif6f379d2012-05-17 19:09:06 -0300392 .antenna_dvbt = true, /* disable LNA */
393 .antenna_gpio = (1 << 2), /* disable LNA */
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300394 .load_firmware_sync = true,
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300395};
396
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300397static 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 Pieri82e7dbb2011-11-19 11:37:14 -0300415static void hauppauge_hvr930c_init(struct em28xx *dev)
416{
417 int i;
418
419 struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -0200420 {EM2874_R80_GPIO, 0xff, 0xff, 0x65},
421 {EM2874_R80_GPIO, 0xfb, 0xff, 0x32},
422 {EM2874_R80_GPIO, 0xff, 0xff, 0xb8},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300423 { -1, -1, -1, -1},
424 };
425 struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -0200426 {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 Pieri82e7dbb2011-11-19 11:37:14 -0300432
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -0200433 {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 Pieri82e7dbb2011-11-19 11:37:14 -0300437
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300438 { -1, -1, -1, -1},
439 };
440
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300441 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 Pieri82e7dbb2011-11-19 11:37:14 -0300477 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
478 msleep(10);
479
480}
481
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300482static 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 Blumenstinglc8dce002012-06-12 18:19:28 -0300530static 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 Blumenstingl89040132012-10-04 14:22:54 -0300554 /*
555 * Init the analog decoder (not yet supported), but
556 * it's probably still a good idea.
557 */
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300558 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 Blumenstingl89040132012-10-04 14:22:54 -0300584static 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 Palosaaric247d7b2012-03-19 11:48:19 -0300642static void pctv_520e_init(struct em28xx *dev)
643{
644 /*
Antti Palosaari26c8a722012-05-17 18:22:02 -0300645 * Init AVF4910B analog decoder. Looks like I2C traffic to
646 * digital demodulator and tuner are routed via AVF4910B.
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300647 */
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 Palosaari33eebec2012-10-03 04:28:56 -0300669static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
Antti Palosaari13a53362012-07-19 22:28:56 -0300670{
Antti Palosaari33eebec2012-10-03 04:28:56 -0300671 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
Antti Palosaari13a53362012-07-19 22:28:56 -0300672 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 Palosaari33eebec2012-10-03 04:28:56 -0300678 if (c->lna == 1)
679 flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
Antti Palosaari13a53362012-07-19 22:28:56 -0300680 else
Antti Palosaari33eebec2012-10-03 04:28:56 -0300681 flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
Antti Palosaari13a53362012-07-19 22:28:56 -0300682
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 Palosaari33eebec2012-10-03 04:28:56 -0300691 dev_warn(&dev->udev->dev, "%s: LNA control is disabled (lna=%u)\n",
692 KBUILD_MODNAME, c->lna);
Antti Palosaari13a53362012-07-19 22:28:56 -0300693 return 0;
694#endif
695}
696
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300697static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300698{
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 Heitmuellerff697862009-07-12 18:44:19 -0300709 static u8 tuner_go[] = { TUNER_GO, 0x01};
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300710
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
725static struct mt352_config terratec_xs_mt352_cfg = {
726 .demod_address = (0x1e >> 1),
727 .no_tuner = 1,
728 .if2 = 45600,
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300729 .demod_init = em28xx_mt352_terratec_xs_init,
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300730};
731
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300732static struct tda10023_config em28xx_tda10023_config = {
733 .demod_address = 0x0c,
734 .invert = 1,
735};
736
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300737static struct cxd2820r_config em28xx_cxd2820r_config = {
738 .i2c_address = (0xd8 >> 1),
739 .ts_mode = CXD2820R_TS_SERIAL,
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300740};
741
742static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
743 .output_opt = TDA18271_OUTPUT_LT_OFF,
Steve Kerrison0db4bf42011-08-09 07:16:21 -0300744 .gate = TDA18271_GATE_DIGITAL,
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300745};
746
Antti Palosaari36588712011-08-01 01:15:30 -0300747static const struct tda10071_config em28xx_tda10071_config = {
Michael Krufky41f55d52012-12-16 19:37:11 -0300748 .demod_i2c_addr = 0x55, /* (0xaa >> 1) */
749 .tuner_i2c_addr = 0x14,
Antti Palosaari36588712011-08-01 01:15:30 -0300750 .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
757static const struct a8293_config em28xx_a8293_config = {
758 .i2c_addr = 0x08, /* (0x10 >> 1) */
759};
760
Aivar Päkk1985f6f2011-12-11 18:15:00 -0300761static 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};
767static struct qt1010_config em28xx_qt1010_config = {
768 .i2c_address = 0x62
769
770};
771
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300772/* ------------------------------------------------------------------ */
773
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300774static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300775{
776 struct dvb_frontend *fe;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300777 struct xc2028_config cfg;
778
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300779 memset(&cfg, 0, sizeof(cfg));
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300780 cfg.i2c_adap = &dev->i2c_adap;
781 cfg.i2c_addr = addr;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300782
Antti Palosaarif71095b2011-04-07 15:51:52 -0300783 if (!dev->dvb->fe[0]) {
Filipe Rosset480be182009-11-04 15:32:37 -0300784 em28xx_errdev("/2: dvb frontend not attached. "
785 "Can't attach xc3028\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300786 return -EINVAL;
787 }
788
Antti Palosaarif71095b2011-04-07 15:51:52 -0300789 fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300790 if (!fe) {
Filipe Rosset480be182009-11-04 15:32:37 -0300791 em28xx_errdev("/2: xc3028 attach failed\n");
Antti Palosaarif71095b2011-04-07 15:51:52 -0300792 dvb_frontend_detach(dev->dvb->fe[0]);
793 dev->dvb->fe[0] = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300794 return -EINVAL;
795 }
796
Filipe Rosset480be182009-11-04 15:32:37 -0300797 em28xx_info("%s/2: xc3028 attached\n", dev->name);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300798
799 return 0;
800}
801
Aidan Thornton3421b772008-04-17 21:40:36 -0300802/* ------------------------------------------------------------------ */
803
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300804static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
805 struct em28xx *dev, struct device *device)
Aidan Thornton3421b772008-04-17 21:40:36 -0300806{
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 Chehabe3569ab2008-04-17 21:49:20 -0300819
820 /* Ensure all frontends negotiate bus access */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300821 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 Chehabe3569ab2008-04-17 21:49:20 -0300824
Aidan Thornton3421b772008-04-17 21:40:36 -0300825 dvb->adapter.priv = dev;
826
827 /* register frontend */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300828 result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300829 if (result < 0) {
830 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
831 dev->name, result);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300832 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 Thornton3421b772008-04-17 21:40:36 -0300843 }
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 Wilsonf2d0c1c2011-07-14 19:06:08 -0300852 dvb->demux.start_feed = em28xx_start_feed;
853 dvb->demux.stop_feed = em28xx_stop_feed;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300854
Aidan Thornton3421b772008-04-17 21:40:36 -0300855 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
899fail_fe_conn:
900 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
901fail_fe_mem:
902 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
903fail_fe_hw:
904 dvb_dmxdev_release(&dvb->dmxdev);
905fail_dmxdev:
906 dvb_dmx_release(&dvb->demux);
907fail_dmx:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300908 if (dvb->fe[1])
909 dvb_unregister_frontend(dvb->fe[1]);
910 dvb_unregister_frontend(dvb->fe[0]);
911fail_frontend1:
912 if (dvb->fe[1])
913 dvb_frontend_detach(dvb->fe[1]);
914fail_frontend0:
915 dvb_frontend_detach(dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300916 dvb_unregister_adapter(&dvb->adapter);
917fail_adapter:
918 return result;
919}
920
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300921static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
Aidan Thornton3421b772008-04-17 21:40:36 -0300922{
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 Palosaarif71095b2011-04-07 15:51:52 -0300928 if (dvb->fe[1])
929 dvb_unregister_frontend(dvb->fe[1]);
930 dvb_unregister_frontend(dvb->fe[0]);
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -0300931 if (dvb->fe[1] && !dvb->dont_attach_fe1)
Antti Palosaarif71095b2011-04-07 15:51:52 -0300932 dvb_frontend_detach(dvb->fe[1]);
933 dvb_frontend_detach(dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300934 dvb_unregister_adapter(&dvb->adapter);
935}
936
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300937static int em28xx_dvb_init(struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300938{
Antti Palosaari13a53362012-07-19 22:28:56 -0300939 int result = 0, mfe_shared = 0;
Aidan Thornton3421b772008-04-17 21:40:36 -0300940 struct em28xx_dvb *dvb;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300941
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -0300942 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -0300943 /* This device does not support the extension */
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300944 printk(KERN_INFO "em28xx_dvb: This device does not support the extension\n");
Devin Heitmuellerdf619182008-06-10 12:34:35 -0300945 return 0;
946 }
947
Aidan Thornton3421b772008-04-17 21:40:36 -0300948 dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300949
950 if (dvb == NULL) {
Filipe Rosset480be182009-11-04 15:32:37 -0300951 em28xx_info("em28xx_dvb: memory allocation failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -0300952 return -ENOMEM;
953 }
954 dev->dvb = dvb;
Antti Palosaarif71095b2011-04-07 15:51:52 -0300955 dvb->fe[0] = dvb->fe[1] = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300956
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -0300957 mutex_lock(&dev->lock);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300958 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300959 /* init frontend */
960 switch (dev->model) {
Mauro Carvalho Chehabebaefdb2011-06-01 10:16:25 -0300961 case EM2874_BOARD_LEADERSHIP_ISDBT:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300962 dvb->fe[0] = dvb_attach(s921_attach,
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300963 &sharp_isdbt, &dev->i2c_adap);
964
Antti Palosaarif71095b2011-04-07 15:51:52 -0300965 if (!dvb->fe[0]) {
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300966 result = -EINVAL;
967 goto out_free;
968 }
969
970 break;
Douglas Schilling Landgraff89bc322008-12-01 21:01:04 -0300971 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
Mauro Carvalho Chehab10ac6602008-07-27 14:58:58 -0300972 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
Devin Heitmueller4fd305b2008-06-04 13:43:46 -0300973 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
Devin Heitmuellere14b3652008-07-26 11:04:33 -0300974 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300975 dvb->fe[0] = dvb_attach(lgdt330x_attach,
Aidan Thornton3421b772008-04-17 21:40:36 -0300976 &em2880_lgdt3303_dev,
977 &dev->i2c_adap);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300978 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Aidan Thornton3421b772008-04-17 21:40:36 -0300979 result = -EINVAL;
980 goto out_free;
981 }
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -0300982 break;
Thierry MERLE46510b52008-10-11 16:56:13 -0300983 case EM2880_BOARD_KWORLD_DVB_310U:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300984 dvb->fe[0] = dvb_attach(zl10353_attach,
Aidan Thornton3421b772008-04-17 21:40:36 -0300985 &em28xx_zl10353_with_xc3028,
986 &dev->i2c_adap);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300987 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Aidan Thornton3421b772008-04-17 21:40:36 -0300988 result = -EINVAL;
989 goto out_free;
990 }
Aidan Thornton7e6388a2008-04-17 21:40:03 -0300991 break;
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300992 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
Uroš Vamplec994d02009-09-30 22:53:37 -0300993 case EM2882_BOARD_TERRATEC_HYBRID_XS:
Devin Heitmueller01a5fd62009-08-07 09:25:06 -0300994 case EM2880_BOARD_EMPIRE_DUAL_TV:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300995 dvb->fe[0] = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300996 &em28xx_zl10353_xc3028_no_i2c_gate,
997 &dev->i2c_adap);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300998 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300999 result = -EINVAL;
1000 goto out_free;
1001 }
1002 break;
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001003 case EM2880_BOARD_TERRATEC_HYBRID_XS:
Catimimi65638012010-02-18 18:06:32 -03001004 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
Devin Heitmuellerd5b3ba92009-07-08 21:51:35 -03001005 case EM2881_BOARD_PINNACLE_HYBRID_PRO:
Andrea.Amorosi76@gmail.com7ca7ef62010-02-09 17:53:38 -03001006 case EM2882_BOARD_DIKOM_DK300:
Antonio Larrosa811fab62010-03-04 22:19:48 -03001007 case EM2882_BOARD_KWORLD_VS_DVBT:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001008 dvb->fe[0] = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -03001009 &em28xx_zl10353_xc3028_no_i2c_gate,
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001010 &dev->i2c_adap);
Antti Palosaarif71095b2011-04-07 15:51:52 -03001011 if (dvb->fe[0] == NULL) {
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001012 /* This board could have either a zl10353 or a mt352.
1013 If the chip id isn't for zl10353, try mt352 */
Antti Palosaarif71095b2011-04-07 15:51:52 -03001014 dvb->fe[0] = dvb_attach(mt352_attach,
Devin Heitmueller4fb202a2009-07-12 17:51:12 -03001015 &terratec_xs_mt352_cfg,
1016 &dev->i2c_adap);
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001017 }
Devin Heitmueller4fb202a2009-07-12 17:51:12 -03001018
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001019 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001020 result = -EINVAL;
1021 goto out_free;
1022 }
1023 break;
Aivar Päkk1985f6f2011-12-11 18:15:00 -03001024 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 Krakora6e7b9ea2009-01-18 21:59:34 -03001032 case EM2883_BOARD_KWORLD_HYBRID_330U:
Devin Heitmueller19859222009-06-19 00:33:54 -03001033 case EM2882_BOARD_EVGA_INDTUBE:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001034 dvb->fe[0] = dvb_attach(s5h1409_attach,
Robert Krakora6e7b9ea2009-01-18 21:59:34 -03001035 &em28xx_s5h1409_with_xc3028,
1036 &dev->i2c_adap);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001037 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Robert Krakora6e7b9ea2009-01-18 21:59:34 -03001038 result = -EINVAL;
1039 goto out_free;
1040 }
1041 break;
Franklin Mengd7de5d82009-06-06 17:05:02 -03001042 case EM2882_BOARD_KWORLD_ATSC_315U:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001043 dvb->fe[0] = dvb_attach(lgdt330x_attach,
Franklin Mengd7de5d82009-06-06 17:05:02 -03001044 &em2880_lgdt3303_dev,
1045 &dev->i2c_adap);
Antti Palosaarif71095b2011-04-07 15:51:52 -03001046 if (dvb->fe[0] != NULL) {
1047 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
Franklin Mengd7de5d82009-06-06 17:05:02 -03001048 &dev->i2c_adap, 0x61, TUNER_THOMSON_DTT761X)) {
1049 result = -EINVAL;
1050 goto out_free;
1051 }
1052 }
1053 break;
Devin Heitmueller17d9d552008-06-08 10:22:03 -03001054 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
Devin Heitmuellerad9b4bb2011-03-13 02:09:59 -03001055 case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001056 dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
Devin Heitmueller75e2b862011-03-13 02:01:02 -03001057 &dev->i2c_adap, &dev->udev->dev);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001058 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmueller17d9d552008-06-08 10:22:03 -03001059 result = -EINVAL;
1060 goto out_free;
1061 }
1062 break;
Antti Palosaari285eb1a2009-09-15 14:42:13 -03001063 case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
1064 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
Antti Palosaarif71095b2011-04-07 15:51:52 -03001065 dvb->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari285eb1a2009-09-15 14:42:13 -03001066 &em28xx_tda10023_config,
1067 &dev->i2c_adap, 0x48);
Antti Palosaarif71095b2011-04-07 15:51:52 -03001068 if (dvb->fe[0]) {
1069 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
Antti Palosaari285eb1a2009-09-15 14:42:13 -03001070 &dev->i2c_adap, 0x60, TUNER_PHILIPS_CU1216L)) {
1071 result = -EINVAL;
1072 goto out_free;
1073 }
1074 }
1075 break;
Jarod Wilson7e48b302010-03-07 17:55:43 -03001076 case EM2870_BOARD_KWORLD_A340:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001077 dvb->fe[0] = dvb_attach(lgdt3305_attach,
Jarod Wilson7e48b302010-03-07 17:55:43 -03001078 &em2870_lgdt3304_dev,
1079 &dev->i2c_adap);
Antti Palosaarif71095b2011-04-07 15:51:52 -03001080 if (dvb->fe[0] != NULL)
1081 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Jarod Wilson7e48b302010-03-07 17:55:43 -03001082 &dev->i2c_adap, &kworld_a340_config);
1083 break;
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001084 case EM28174_BOARD_PCTV_290E:
Antti Palosaaria36a66d2012-08-16 21:07:23 -03001085 /* 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 Palosaarid6a5f922011-04-07 16:34:44 -03001088 dvb->fe[0] = dvb_attach(cxd2820r_attach,
Manu Abraham7e7b8282011-12-10 00:44:24 -03001089 &em28xx_cxd2820r_config,
Antti Palosaari1e8f31f2012-07-19 21:10:36 -03001090 &dev->i2c_adap,
Antti Palosaari13a53362012-07-19 22:28:56 -03001091 &dvb->lna_gpio);
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001092 if (dvb->fe[0]) {
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001093 /* FE 0 attach tuner */
Manu Abraham7e7b8282011-12-10 00:44:24 -03001094 if (!dvb_attach(tda18271_attach,
1095 dvb->fe[0],
1096 0x60,
1097 &dev->i2c_adap,
1098 &em28xx_cxd2820r_tda18271_config)) {
1099
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001100 dvb_frontend_detach(dvb->fe[0]);
1101 result = -EINVAL;
1102 goto out_free;
1103 }
Antti Palosaari1e8f31f2012-07-19 21:10:36 -03001104
Antti Palosaari13a53362012-07-19 22:28:56 -03001105#ifdef CONFIG_GPIOLIB
Antti Palosaari0c42a552012-09-19 20:52:21 -03001106 /* 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 Palosaari1e8f31f2012-07-19 21:10:36 -03001114
Antti Palosaari0c42a552012-09-19 20:52:21 -03001115 result = 0; /* continue even set LNA fails */
Antti Palosaari13a53362012-07-19 22:28:56 -03001116#endif
Antti Palosaari0c42a552012-09-19 20:52:21 -03001117 dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
1118 }
1119
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001120 break;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001121 case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
Mauro Carvalho Chehab85032322011-11-24 15:01:45 -02001122 {
1123 struct xc5000_config cfg;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001124 hauppauge_hvr930c_init(dev);
1125
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001126 dvb->fe[0] = dvb_attach(drxk_attach,
Mauro Carvalho Chehabfa4b2a12012-01-05 08:07:32 -02001127 &hauppauge_930c_drxk, &dev->i2c_adap);
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001128 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 Pieri82e7dbb2011-11-19 11:37:14 -03001137
1138 /* Attach xc5000 */
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001139 memset(&cfg, 0, sizeof(cfg));
1140 cfg.i2c_address = 0x61;
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001141 cfg.if_khz = 4000;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001142
1143 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1144 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001145 if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap,
1146 &cfg)) {
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001147 result = -EINVAL;
1148 goto out_free;
1149 }
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001150 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1151 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1152
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001153 break;
Mauro Carvalho Chehab85032322011-11-24 15:01:45 -02001154 }
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001155 case EM2884_BOARD_TERRATEC_H5:
1156 terratec_h5_init(dev);
1157
Mauro Carvalho Chehabfa4b2a12012-01-05 08:07:32 -02001158 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap);
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -03001159 if (!dvb->fe[0]) {
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001160 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 Chehabfec528b2011-07-03 21:05:06 -03001168
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -03001169 /* Attach tda18271 to DVB-C frontend */
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001170 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 Chehabc4c3a3d2011-07-14 22:23:18 -03001178
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001179 break;
Antti Palosaari36588712011-08-01 01:15:30 -03001180 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 Palosaari35530852012-03-18 18:09:01 -03001190 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 Kalvachevfa5527c2012-03-19 20:09:55 -03001213 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 Blumenstinglc8dce002012-06-12 18:19:28 -03001232 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 Blumenstingl89040132012-10-04 14:22:54 -03001251 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 Chehab3aefb792008-04-17 21:36:41 -03001270 default:
Filipe Rosset480be182009-11-04 15:32:37 -03001271 em28xx_errdev("/2: The frontend of your DVB/ATSC card"
1272 " isn't supported yet\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001273 break;
1274 }
Antti Palosaarif71095b2011-04-07 15:51:52 -03001275 if (NULL == dvb->fe[0]) {
Filipe Rosset480be182009-11-04 15:32:37 -03001276 em28xx_errdev("/2: frontend initialization failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -03001277 result = -EINVAL;
1278 goto out_free;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001279 }
Michael Krufkyd7cba042008-09-12 13:31:45 -03001280 /* define general-purpose callback pointer */
Antti Palosaarif71095b2011-04-07 15:51:52 -03001281 dvb->fe[0]->callback = em28xx_tuner_callback;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001282 if (dvb->fe[1])
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001283 dvb->fe[1]->callback = em28xx_tuner_callback;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001284
1285 /* register everything */
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001286 result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
Aidan Thornton3421b772008-04-17 21:40:36 -03001287
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -03001288 if (result < 0)
Aidan Thornton3421b772008-04-17 21:40:36 -03001289 goto out_free;
Aidan Thornton3421b772008-04-17 21:40:36 -03001290
Antti Palosaarie3645432011-07-28 18:59:30 -03001291 /* MFE lock */
1292 dvb->adapter.mfe_shared = mfe_shared;
1293
Filipe Rosset480be182009-11-04 15:32:37 -03001294 em28xx_info("Successfully loaded em28xx-dvb\n");
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -03001295ret:
1296 em28xx_set_mode(dev, EM28XX_SUSPEND);
1297 mutex_unlock(&dev->lock);
1298 return result;
Aidan Thornton3421b772008-04-17 21:40:36 -03001299
1300out_free:
1301 kfree(dvb);
1302 dev->dvb = NULL;
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -03001303 goto ret;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001304}
1305
Chris Rankin0b8bd832011-08-20 16:01:26 -03001306static 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 Wilsonf2d0c1c2011-07-14 19:06:08 -03001313static int em28xx_dvb_fini(struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001314{
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -03001315 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -03001316 /* This device does not support the extension */
1317 return 0;
1318 }
1319
Aidan Thornton3421b772008-04-17 21:40:36 -03001320 if (dev->dvb) {
Chris Rankin0b8bd832011-08-20 16:01:26 -03001321 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 Thornton3421b772008-04-17 21:40:36 -03001334 dev->dvb = NULL;
1335 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001336
1337 return 0;
1338}
1339
1340static struct em28xx_ops dvb_ops = {
1341 .id = EM28XX_DVB,
1342 .name = "Em28xx dvb Extension",
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001343 .init = em28xx_dvb_init,
1344 .fini = em28xx_dvb_fini,
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001345};
1346
1347static int __init em28xx_dvb_register(void)
1348{
1349 return em28xx_register_extension(&dvb_ops);
1350}
1351
1352static void __exit em28xx_dvb_unregister(void)
1353{
1354 em28xx_unregister_extension(&dvb_ops);
1355}
1356
1357module_init(em28xx_dvb_register);
1358module_exit(em28xx_dvb_unregister);