blob: f4cdf9e8dc1888ced8e71fcc3a13f48d30283415 [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>
Devin Heitmuellerd3829fa2013-01-04 16:16:24 -030030#include <dvb_demux.h>
31#include <dvb_net.h>
32#include <dmxdev.h>
Franklin Mengd7de5d82009-06-06 17:05:02 -030033#include <media/tuner.h>
34#include "tuner-simple.h"
Antti Palosaari1e8f31f2012-07-19 21:10:36 -030035#include <linux/gpio.h>
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030036
37#include "lgdt330x.h"
Jarod Wilson7e48b302010-03-07 17:55:43 -030038#include "lgdt3305.h"
Aidan Thornton7e6388a2008-04-17 21:40:03 -030039#include "zl10353.h"
Robert Krakora6e7b9ea2009-01-18 21:59:34 -030040#include "s5h1409.h"
Devin Heitmueller4fb202a2009-07-12 17:51:12 -030041#include "mt352.h"
42#include "mt352_priv.h" /* FIXME */
Antti Palosaari285eb1a2009-09-15 14:42:13 -030043#include "tda1002x.h"
Jarod Wilson7e48b302010-03-07 17:55:43 -030044#include "tda18271.h"
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -030045#include "s921.h"
Devin Heitmueller75e2b862011-03-13 02:01:02 -030046#include "drxd.h"
Antti Palosaarid6a5f922011-04-07 16:34:44 -030047#include "cxd2820r.h"
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -030048#include "tda18271c2dd.h"
49#include "drxk.h"
Antti Palosaari36588712011-08-01 01:15:30 -030050#include "tda10071.h"
51#include "a8293.h"
Aivar Päkk1985f6f2011-12-11 18:15:00 -030052#include "qt1010.h"
Mauro Carvalho Chehab4159d012013-02-28 10:35:56 -030053#include "mb86a20s.h"
Antti Palosaariec573362013-02-25 09:01:13 -030054#include "m88ds3103.h"
55#include "m88ts2022.h"
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030056
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030057MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
58MODULE_LICENSE("GPL");
Mauro Carvalho Chehabd8992b02013-12-27 11:14:59 -030059MODULE_DESCRIPTION(DRIVER_DESC " - digital TV interface");
60MODULE_VERSION(EM28XX_VERSION);
61
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030062
63static unsigned int debug;
64module_param(debug, int, 0644);
65MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
66
67DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
68
69#define dprintk(level, fmt, arg...) do { \
70if (debug >= level) \
Aidan Thornton3421b772008-04-17 21:40:36 -030071 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030072} while (0)
73
Aidan Thornton3421b772008-04-17 21:40:36 -030074struct em28xx_dvb {
Antti Palosaarif71095b2011-04-07 15:51:52 -030075 struct dvb_frontend *fe[2];
Aidan Thornton3421b772008-04-17 21:40:36 -030076
77 /* feed count management */
78 struct mutex lock;
79 int nfeeds;
80
81 /* general boilerplate stuff */
82 struct dvb_adapter adapter;
83 struct dvb_demux demux;
84 struct dmxdev dmxdev;
85 struct dmx_frontend fe_hw;
86 struct dmx_frontend fe_mem;
87 struct dvb_net net;
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -030088
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -030089 /* Due to DRX-K - probably need changes */
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -030090 int (*gate_ctrl)(struct dvb_frontend *, int);
91 struct semaphore pll_mutex;
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -030092 bool dont_attach_fe1;
Antti Palosaari13a53362012-07-19 22:28:56 -030093 int lna_gpio;
Antti Palosaarieafa2ad2013-12-02 18:38:41 -030094 struct i2c_client *i2c_client_tuner;
Aidan Thornton3421b772008-04-17 21:40:36 -030095};
96
97
98static inline void print_err_status(struct em28xx *dev,
99 int packet, int status)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300100{
Aidan Thornton3421b772008-04-17 21:40:36 -0300101 char *errmsg = "Unknown";
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300102
Aidan Thornton3421b772008-04-17 21:40:36 -0300103 switch (status) {
104 case -ENOENT:
105 errmsg = "unlinked synchronuously";
106 break;
107 case -ECONNRESET:
108 errmsg = "unlinked asynchronuously";
109 break;
110 case -ENOSR:
111 errmsg = "Buffer error (overrun)";
112 break;
113 case -EPIPE:
114 errmsg = "Stalled (device not responding)";
115 break;
116 case -EOVERFLOW:
117 errmsg = "Babble (bad cable?)";
118 break;
119 case -EPROTO:
120 errmsg = "Bit-stuff error (bad cable?)";
121 break;
122 case -EILSEQ:
123 errmsg = "CRC/Timeout (could be anything)";
124 break;
125 case -ETIME:
126 errmsg = "Device does not respond";
127 break;
128 }
129 if (packet < 0) {
130 dprintk(1, "URB status %d [%s].\n", status, errmsg);
131 } else {
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300132 dprintk(1, "URB packet %d, status %d [%s].\n",
133 packet, status, errmsg);
Aidan Thornton3421b772008-04-17 21:40:36 -0300134 }
135}
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300136
Frank Schaefera950e4a2012-11-08 14:11:47 -0300137static inline int em28xx_dvb_urb_data_copy(struct em28xx *dev, struct urb *urb)
Aidan Thornton3421b772008-04-17 21:40:36 -0300138{
Frank Schaefera950e4a2012-11-08 14:11:47 -0300139 int xfer_bulk, num_packets, i;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300140
Aidan Thornton3421b772008-04-17 21:40:36 -0300141 if (!dev)
142 return 0;
143
Frank Schaefer2665c292012-12-27 19:02:43 -0300144 if (dev->disconnected)
Aidan Thornton3421b772008-04-17 21:40:36 -0300145 return 0;
146
Frank Schaefer1653cb0c2012-11-08 14:11:44 -0300147 if (urb->status < 0)
Aidan Thornton3421b772008-04-17 21:40:36 -0300148 print_err_status(dev, -1, urb->status);
Aidan Thornton3421b772008-04-17 21:40:36 -0300149
Frank Schaefera950e4a2012-11-08 14:11:47 -0300150 xfer_bulk = usb_pipebulk(urb->pipe);
Aidan Thornton3421b772008-04-17 21:40:36 -0300151
Frank Schaefera950e4a2012-11-08 14:11:47 -0300152 if (xfer_bulk) /* bulk */
153 num_packets = 1;
154 else /* isoc */
155 num_packets = urb->number_of_packets;
156
157 for (i = 0; i < num_packets; i++) {
158 if (xfer_bulk) {
159 if (urb->status < 0) {
160 print_err_status(dev, i, urb->status);
161 if (urb->status != -EPROTO)
162 continue;
163 }
164 dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer,
165 urb->actual_length);
166 } else {
167 if (urb->iso_frame_desc[i].status < 0) {
168 print_err_status(dev, i,
169 urb->iso_frame_desc[i].status);
170 if (urb->iso_frame_desc[i].status != -EPROTO)
171 continue;
172 }
173 dvb_dmx_swfilter(&dev->dvb->demux,
174 urb->transfer_buffer +
175 urb->iso_frame_desc[i].offset,
176 urb->iso_frame_desc[i].actual_length);
Aidan Thornton3421b772008-04-17 21:40:36 -0300177 }
Aidan Thornton3421b772008-04-17 21:40:36 -0300178 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300179
180 return 0;
181}
182
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300183static int em28xx_start_streaming(struct em28xx_dvb *dvb)
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300184{
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300185 int rc;
Hans Verkuil3de09fb2013-04-08 16:25:04 -0300186 struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
187 struct em28xx *dev = i2c_bus->dev;
Frank Schaeferc647a912012-11-08 14:11:52 -0300188 int dvb_max_packet_size, packet_multiplier, dvb_alt;
Aidan Thornton3421b772008-04-17 21:40:36 -0300189
Frank Schaeferc647a912012-11-08 14:11:52 -0300190 if (dev->dvb_xfer_bulk) {
191 if (!dev->dvb_ep_bulk)
192 return -ENODEV;
193 dvb_max_packet_size = 512; /* USB 2.0 spec */
194 packet_multiplier = EM28XX_DVB_BULK_PACKET_MULTIPLIER;
195 dvb_alt = 0;
196 } else { /* isoc */
197 if (!dev->dvb_ep_isoc)
198 return -ENODEV;
199 dvb_max_packet_size = dev->dvb_max_pkt_size_isoc;
200 if (dvb_max_packet_size < 0)
201 return dvb_max_packet_size;
202 packet_multiplier = EM28XX_DVB_NUM_ISOC_PACKETS;
203 dvb_alt = dev->dvb_alt_isoc;
204 }
205
206 usb_set_interface(dev->udev, 0, dvb_alt);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300207 rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
208 if (rc < 0)
209 return rc;
Aidan Thornton3421b772008-04-17 21:40:36 -0300210
Gianluca Gennari86d38d12012-02-13 13:59:22 -0300211 dprintk(1, "Using %d buffers each with %d x %d bytes\n",
Mauro Carvalho Chehabf7acc4b2011-07-28 15:42:00 -0300212 EM28XX_DVB_NUM_BUFS,
Frank Schaeferc647a912012-11-08 14:11:52 -0300213 packet_multiplier,
214 dvb_max_packet_size);
Devin Heitmuellerd18e2fd2009-05-16 17:09:28 -0300215
Frank Schaeferc647a912012-11-08 14:11:52 -0300216 return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE,
217 dev->dvb_xfer_bulk,
Frank Schaefer057ca0d2012-11-08 14:11:42 -0300218 EM28XX_DVB_NUM_BUFS,
Frank Schaeferc647a912012-11-08 14:11:52 -0300219 dvb_max_packet_size,
220 packet_multiplier,
Frank Schaefera950e4a2012-11-08 14:11:47 -0300221 em28xx_dvb_urb_data_copy);
Aidan Thornton3421b772008-04-17 21:40:36 -0300222}
223
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300224static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300225{
Hans Verkuil3de09fb2013-04-08 16:25:04 -0300226 struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
227 struct em28xx *dev = i2c_bus->dev;
Aidan Thornton3421b772008-04-17 21:40:36 -0300228
Gianluca Gennari5f5f1472012-03-22 08:48:17 -0300229 em28xx_stop_urbs(dev);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300230
Aidan Thornton3421b772008-04-17 21:40:36 -0300231 return 0;
232}
233
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300234static int em28xx_start_feed(struct dvb_demux_feed *feed)
Aidan Thornton3421b772008-04-17 21:40:36 -0300235{
236 struct dvb_demux *demux = feed->demux;
237 struct em28xx_dvb *dvb = demux->priv;
238 int rc, ret;
239
240 if (!demux->dmx.frontend)
241 return -EINVAL;
242
243 mutex_lock(&dvb->lock);
244 dvb->nfeeds++;
245 rc = dvb->nfeeds;
246
247 if (dvb->nfeeds == 1) {
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300248 ret = em28xx_start_streaming(dvb);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300249 if (ret < 0)
250 rc = ret;
Aidan Thornton3421b772008-04-17 21:40:36 -0300251 }
252
253 mutex_unlock(&dvb->lock);
254 return rc;
255}
256
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300257static int em28xx_stop_feed(struct dvb_demux_feed *feed)
Aidan Thornton3421b772008-04-17 21:40:36 -0300258{
259 struct dvb_demux *demux = feed->demux;
260 struct em28xx_dvb *dvb = demux->priv;
261 int err = 0;
262
263 mutex_lock(&dvb->lock);
264 dvb->nfeeds--;
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300265
266 if (0 == dvb->nfeeds)
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300267 err = em28xx_stop_streaming(dvb);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300268
Aidan Thornton3421b772008-04-17 21:40:36 -0300269 mutex_unlock(&dvb->lock);
270 return err;
271}
272
273
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300274
275/* ------------------------------------------------------------------ */
276static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
277{
Mauro Carvalho Chehaba3b60202013-04-28 10:33:57 -0300278 struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
Mauro Carvalho Chehab96346142013-12-26 12:41:03 -0300279 struct em28xx *dev = i2c_bus->dev;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300280
281 if (acquire)
282 return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
283 else
Mauro Carvalho Chehab2fe3e2e2008-11-27 09:10:40 -0300284 return em28xx_set_mode(dev, EM28XX_SUSPEND);
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300285}
286
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300287/* ------------------------------------------------------------------ */
288
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -0300289static struct lgdt330x_config em2880_lgdt3303_dev = {
290 .demod_address = 0x0e,
291 .demod_chip = LGDT3303,
292};
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300293
Jarod Wilson7e48b302010-03-07 17:55:43 -0300294static struct lgdt3305_config em2870_lgdt3304_dev = {
295 .i2c_addr = 0x0e,
296 .demod_chip = LGDT3304,
297 .spectral_inversion = 1,
298 .deny_i2c_rptr = 1,
299 .mpeg_mode = LGDT3305_MPEG_PARALLEL,
300 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
301 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
302 .vsb_if_khz = 3250,
303 .qam_if_khz = 4000,
304};
305
Jean-Francois Thibert6dbea9f2013-10-09 11:18:05 -0300306static struct lgdt3305_config em2874_lgdt3305_dev = {
307 .i2c_addr = 0x0e,
308 .demod_chip = LGDT3305,
309 .spectral_inversion = 1,
310 .deny_i2c_rptr = 0,
311 .mpeg_mode = LGDT3305_MPEG_SERIAL,
312 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
313 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
314 .vsb_if_khz = 3250,
315 .qam_if_khz = 4000,
316};
317
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300318static struct s921_config sharp_isdbt = {
319 .demod_address = 0x30 >> 1
320};
321
Aidan Thornton7e6388a2008-04-17 21:40:03 -0300322static struct zl10353_config em28xx_zl10353_with_xc3028 = {
323 .demod_address = (0x1e >> 1),
324 .no_tuner = 1,
325 .parallel_ts = 1,
326 .if2 = 45600,
327};
328
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300329static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
330 .demod_address = 0x32 >> 1,
331 .output_mode = S5H1409_PARALLEL_OUTPUT,
332 .gpio = S5H1409_GPIO_OFF,
333 .inversion = S5H1409_INVERSION_OFF,
334 .status_mode = S5H1409_DEMODLOCKING,
335 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
336};
337
Jarod Wilson7e48b302010-03-07 17:55:43 -0300338static struct tda18271_std_map kworld_a340_std_map = {
339 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
340 .if_lvl = 1, .rfagc_top = 0x37, },
341 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
342 .if_lvl = 1, .rfagc_top = 0x37, },
343};
344
345static struct tda18271_config kworld_a340_config = {
346 .std_map = &kworld_a340_std_map,
347};
348
Jean-Francois Thibert6dbea9f2013-10-09 11:18:05 -0300349static struct tda18271_config kworld_ub435q_v2_config = {
350 .std_map = &kworld_a340_std_map,
351 .gate = TDA18271_GATE_DIGITAL,
352};
353
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300354static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300355 .demod_address = (0x1e >> 1),
356 .no_tuner = 1,
357 .disable_i2c_gate_ctrl = 1,
358 .parallel_ts = 1,
359 .if2 = 45600,
360};
361
Devin Heitmueller75e2b862011-03-13 02:01:02 -0300362static struct drxd_config em28xx_drxd = {
Mauro Carvalho Chehabaac865f2011-12-26 09:41:14 -0300363 .demod_address = 0x70,
364 .demod_revision = 0xa2,
365 .pll_type = DRXD_PLL_NONE,
366 .clock = 12000,
367 .insert_rs_byte = 1,
368 .IF = 42800000,
Devin Heitmueller6b142b32011-03-13 02:02:01 -0300369 .disable_i2c_gate_ctrl = 1,
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300370};
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300371
Ezequiel García61bdbef2012-06-12 09:53:41 -0300372static struct drxk_config terratec_h5_drxk = {
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300373 .adr = 0x29,
Mauro Carvalho Chehabe4f4f872011-07-09 17:35:26 -0300374 .single_master = 1,
Mauro Carvalho Chehabf1fe1b72011-07-09 21:59:33 -0300375 .no_i2c_bridge = 1,
Mauro Carvalho Chehab8b9456a2011-07-11 14:33:51 -0300376 .microcode_name = "dvb-usb-terratec-h5-drxk.fw",
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300377 .qam_demod_parameter_count = 2,
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300378 .load_firmware_sync = true,
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300379};
380
Ezequiel García61bdbef2012-06-12 09:53:41 -0300381static struct drxk_config hauppauge_930c_drxk = {
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300382 .adr = 0x29,
383 .single_master = 1,
384 .no_i2c_bridge = 1,
385 .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
386 .chunk_size = 56,
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300387 .qam_demod_parameter_count = 2,
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300388 .load_firmware_sync = true,
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300389};
390
Martin Blumenstingl89040132012-10-04 14:22:54 -0300391static struct drxk_config terratec_htc_stick_drxk = {
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300392 .adr = 0x29,
393 .single_master = 1,
394 .no_i2c_bridge = 1,
395 .microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw",
396 .chunk_size = 54,
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300397 .qam_demod_parameter_count = 2,
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300398 /* Required for the antenna_gpio to disable LNA. */
399 .antenna_dvbt = true,
400 /* The windows driver uses the same. This will disable LNA. */
401 .antenna_gpio = 0x6,
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300402 .load_firmware_sync = true,
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300403};
404
Ezequiel García61bdbef2012-06-12 09:53:41 -0300405static struct drxk_config maxmedia_ub425_tc_drxk = {
Antti Palosaari35530852012-03-18 18:09:01 -0300406 .adr = 0x29,
407 .single_master = 1,
408 .no_i2c_bridge = 1,
Antti Palosaari8d100b22013-10-04 14:40:06 -0300409 .microcode_name = "dvb-demod-drxk-01.fw",
410 .chunk_size = 62,
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300411 .load_firmware_sync = true,
Antti Palosaaride0fc462013-10-04 15:25:55 -0300412 .qam_demod_parameter_count = 2,
Antti Palosaari35530852012-03-18 18:09:01 -0300413};
414
Ezequiel García61bdbef2012-06-12 09:53:41 -0300415static struct drxk_config pctv_520e_drxk = {
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300416 .adr = 0x29,
417 .single_master = 1,
418 .microcode_name = "dvb-demod-drxk-pctv.fw",
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300419 .qam_demod_parameter_count = 2,
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300420 .chunk_size = 58,
Antti Palosaarif6f379d2012-05-17 19:09:06 -0300421 .antenna_dvbt = true, /* disable LNA */
422 .antenna_gpio = (1 << 2), /* disable LNA */
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300423 .load_firmware_sync = true,
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300424};
425
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300426static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
427{
428 struct em28xx_dvb *dvb = fe->sec_priv;
429 int status;
430
431 if (!dvb)
432 return -EINVAL;
433
434 if (enable) {
435 down(&dvb->pll_mutex);
436 status = dvb->gate_ctrl(fe, 1);
437 } else {
438 status = dvb->gate_ctrl(fe, 0);
439 up(&dvb->pll_mutex);
440 }
441 return status;
442}
443
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300444static void hauppauge_hvr930c_init(struct em28xx *dev)
445{
446 int i;
447
448 struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
Frank Schaefer907d1092013-06-03 14:12:02 -0300449 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0x65},
450 {EM2874_R80_GPIO_P0_CTRL, 0xfb, 0xff, 0x32},
451 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0xb8},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300452 { -1, -1, -1, -1},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300453 };
454 struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
Frank Schaefer907d1092013-06-03 14:12:02 -0300455 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
456 {EM2874_R80_GPIO_P0_CTRL, 0xaf, 0xff, 0x65},
457 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x76},
458 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
459 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
460 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x40},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300461
Frank Schaefer907d1092013-06-03 14:12:02 -0300462 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x65},
463 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
464 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
465 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300466
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300467 { -1, -1, -1, -1},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300468 };
469
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300470 struct {
471 unsigned char r[4];
472 int len;
473 } regs[] = {
474 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
475 {{ 0x01, 0x02 }, 2},
476 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
477 {{ 0x01, 0x00 }, 2},
478 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
479 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
480 {{ 0x01, 0x00 }, 2},
481 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
482 {{ 0x04, 0x00 }, 2},
483 {{ 0x00, 0x04 }, 2},
484 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
485 {{ 0x04, 0x14 }, 2},
486 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
487 };
488
489 em28xx_gpio_set(dev, hauppauge_hvr930c_init);
490 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
491 msleep(10);
492 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
493 msleep(10);
494
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300495 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300496
497 for (i = 0; i < ARRAY_SIZE(regs); i++)
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300498 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300499 em28xx_gpio_set(dev, hauppauge_hvr930c_end);
500
501 msleep(100);
502
503 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
504 msleep(30);
505
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300506 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
507 msleep(10);
508
509}
510
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300511static void terratec_h5_init(struct em28xx *dev)
512{
513 int i;
514 struct em28xx_reg_seq terratec_h5_init[] = {
Frank Schaeferc074fc42013-06-03 14:12:03 -0300515 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
Frank Schaefer907d1092013-06-03 14:12:02 -0300516 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
517 {EM2874_R80_GPIO_P0_CTRL, 0xf2, 0xff, 50},
518 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300519 { -1, -1, -1, -1},
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300520 };
521 struct em28xx_reg_seq terratec_h5_end[] = {
Frank Schaefer907d1092013-06-03 14:12:02 -0300522 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
523 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
524 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300525 { -1, -1, -1, -1},
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300526 };
527 struct {
528 unsigned char r[4];
529 int len;
530 } regs[] = {
531 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
532 {{ 0x01, 0x02 }, 2},
533 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
534 {{ 0x01, 0x00 }, 2},
535 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
536 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
537 {{ 0x01, 0x00 }, 2},
538 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
539 {{ 0x04, 0x00 }, 2},
540 {{ 0x00, 0x04 }, 2},
541 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
542 {{ 0x04, 0x14 }, 2},
543 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
544 };
545
546 em28xx_gpio_set(dev, terratec_h5_init);
547 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
548 msleep(10);
549 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
550 msleep(10);
551
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300552 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300553
554 for (i = 0; i < ARRAY_SIZE(regs); i++)
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300555 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300556 em28xx_gpio_set(dev, terratec_h5_end);
557};
558
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300559static void terratec_htc_stick_init(struct em28xx *dev)
560{
561 int i;
562
563 /*
564 * GPIO configuration:
565 * 0xff: unknown (does not affect DVB-T).
566 * 0xf6: DRX-K (demodulator).
567 * 0xe6: unknown (does not affect DVB-T).
568 * 0xb6: unknown (does not affect DVB-T).
569 */
570 struct em28xx_reg_seq terratec_htc_stick_init[] = {
Frank Schaeferc074fc42013-06-03 14:12:03 -0300571 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
Frank Schaefer907d1092013-06-03 14:12:02 -0300572 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
573 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 50},
574 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300575 { -1, -1, -1, -1},
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300576 };
577 struct em28xx_reg_seq terratec_htc_stick_end[] = {
Frank Schaefer907d1092013-06-03 14:12:02 -0300578 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
579 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 50},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300580 { -1, -1, -1, -1},
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300581 };
582
Martin Blumenstingl89040132012-10-04 14:22:54 -0300583 /*
584 * Init the analog decoder (not yet supported), but
585 * it's probably still a good idea.
586 */
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300587 struct {
588 unsigned char r[4];
589 int len;
590 } regs[] = {
591 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
592 {{ 0x01, 0x02 }, 2},
593 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
594 {{ 0x01, 0x00 }, 2},
595 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
596 };
597
598 em28xx_gpio_set(dev, terratec_htc_stick_init);
599
600 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
601 msleep(10);
602 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
603 msleep(10);
604
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300605 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300606
607 for (i = 0; i < ARRAY_SIZE(regs); i++)
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300608 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300609
610 em28xx_gpio_set(dev, terratec_htc_stick_end);
611};
612
Martin Blumenstingl89040132012-10-04 14:22:54 -0300613static void terratec_htc_usb_xs_init(struct em28xx *dev)
614{
615 int i;
616
617 struct em28xx_reg_seq terratec_htc_usb_xs_init[] = {
Frank Schaeferc074fc42013-06-03 14:12:03 -0300618 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
Frank Schaefer907d1092013-06-03 14:12:02 -0300619 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 100},
620 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 50},
621 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300622 { -1, -1, -1, -1},
Martin Blumenstingl89040132012-10-04 14:22:54 -0300623 };
624 struct em28xx_reg_seq terratec_htc_usb_xs_end[] = {
Frank Schaefer907d1092013-06-03 14:12:02 -0300625 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 100},
626 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
627 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300628 { -1, -1, -1, -1},
Martin Blumenstingl89040132012-10-04 14:22:54 -0300629 };
630
631 /*
632 * Init the analog decoder (not yet supported), but
633 * it's probably still a good idea.
634 */
635 struct {
636 unsigned char r[4];
637 int len;
638 } regs[] = {
639 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
640 {{ 0x01, 0x02 }, 2},
641 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
642 {{ 0x01, 0x00 }, 2},
643 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
644 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
645 {{ 0x01, 0x00 }, 2},
646 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
647 {{ 0x04, 0x00 }, 2},
648 {{ 0x00, 0x04 }, 2},
649 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
650 {{ 0x04, 0x14 }, 2},
651 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
652 };
653
654 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
655
656 em28xx_gpio_set(dev, terratec_htc_usb_xs_init);
657
658 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
659 msleep(10);
660 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
661 msleep(10);
662
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300663 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
Martin Blumenstingl89040132012-10-04 14:22:54 -0300664
665 for (i = 0; i < ARRAY_SIZE(regs); i++)
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300666 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
Martin Blumenstingl89040132012-10-04 14:22:54 -0300667
668 em28xx_gpio_set(dev, terratec_htc_usb_xs_end);
669};
670
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300671static void pctv_520e_init(struct em28xx *dev)
672{
673 /*
Antti Palosaari26c8a722012-05-17 18:22:02 -0300674 * Init AVF4910B analog decoder. Looks like I2C traffic to
675 * digital demodulator and tuner are routed via AVF4910B.
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300676 */
677 int i;
678 struct {
679 unsigned char r[4];
680 int len;
681 } regs[] = {
682 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
683 {{ 0x01, 0x02 }, 2},
684 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
685 {{ 0x01, 0x00 }, 2},
686 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
687 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
688 {{ 0x01, 0x00 }, 2},
689 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
690 };
691
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300692 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; /* 0x41 */
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300693
694 for (i = 0; i < ARRAY_SIZE(regs); i++)
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300695 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300696};
697
Antti Palosaari33eebec2012-10-03 04:28:56 -0300698static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
Antti Palosaari13a53362012-07-19 22:28:56 -0300699{
Antti Palosaari33eebec2012-10-03 04:28:56 -0300700 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
Antti Palosaari13a53362012-07-19 22:28:56 -0300701 struct em28xx *dev = fe->dvb->priv;
702#ifdef CONFIG_GPIOLIB
703 struct em28xx_dvb *dvb = dev->dvb;
704 int ret;
705 unsigned long flags;
706
Antti Palosaari33eebec2012-10-03 04:28:56 -0300707 if (c->lna == 1)
708 flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
Antti Palosaari13a53362012-07-19 22:28:56 -0300709 else
Antti Palosaari33eebec2012-10-03 04:28:56 -0300710 flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
Antti Palosaari13a53362012-07-19 22:28:56 -0300711
712 ret = gpio_request_one(dvb->lna_gpio, flags, NULL);
713 if (ret)
714 em28xx_errdev("gpio request failed %d\n", ret);
715 else
716 gpio_free(dvb->lna_gpio);
717
718 return ret;
719#else
Antti Palosaari33eebec2012-10-03 04:28:56 -0300720 dev_warn(&dev->udev->dev, "%s: LNA control is disabled (lna=%u)\n",
721 KBUILD_MODNAME, c->lna);
Antti Palosaari13a53362012-07-19 22:28:56 -0300722 return 0;
723#endif
724}
725
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300726static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300727{
728 /* Values extracted from a USB trace of the Terratec Windows driver */
729 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
730 static u8 reset[] = { RESET, 0x80 };
731 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
732 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
733 static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
734 static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
735 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
736 static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
737 static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
Devin Heitmuellerff697862009-07-12 18:44:19 -0300738 static u8 tuner_go[] = { TUNER_GO, 0x01};
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300739
740 mt352_write(fe, clock_config, sizeof(clock_config));
741 udelay(200);
742 mt352_write(fe, reset, sizeof(reset));
743 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
744 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
745 mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
746 mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
747 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
748 mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
749 mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
750 mt352_write(fe, tuner_go, sizeof(tuner_go));
751 return 0;
752}
753
754static struct mt352_config terratec_xs_mt352_cfg = {
755 .demod_address = (0x1e >> 1),
756 .no_tuner = 1,
757 .if2 = 45600,
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300758 .demod_init = em28xx_mt352_terratec_xs_init,
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300759};
760
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300761static struct tda10023_config em28xx_tda10023_config = {
762 .demod_address = 0x0c,
763 .invert = 1,
764};
765
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300766static struct cxd2820r_config em28xx_cxd2820r_config = {
767 .i2c_address = (0xd8 >> 1),
768 .ts_mode = CXD2820R_TS_SERIAL,
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300769};
770
771static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
772 .output_opt = TDA18271_OUTPUT_LT_OFF,
Steve Kerrison0db4bf42011-08-09 07:16:21 -0300773 .gate = TDA18271_GATE_DIGITAL,
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300774};
775
Antti Palosaari36588712011-08-01 01:15:30 -0300776static const struct tda10071_config em28xx_tda10071_config = {
Michael Krufky41f55d52012-12-16 19:37:11 -0300777 .demod_i2c_addr = 0x55, /* (0xaa >> 1) */
778 .tuner_i2c_addr = 0x14,
Antti Palosaari36588712011-08-01 01:15:30 -0300779 .i2c_wr_max = 64,
780 .ts_mode = TDA10071_TS_SERIAL,
781 .spec_inv = 0,
782 .xtal = 40444000, /* 40.444 MHz */
783 .pll_multiplier = 20,
784};
785
786static const struct a8293_config em28xx_a8293_config = {
787 .i2c_addr = 0x08, /* (0x10 >> 1) */
788};
789
Aivar Päkk1985f6f2011-12-11 18:15:00 -0300790static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
791 .demod_address = (0x1e >> 1),
792 .disable_i2c_gate_ctrl = 1,
793 .no_tuner = 1,
794 .parallel_ts = 1,
795};
796static struct qt1010_config em28xx_qt1010_config = {
797 .i2c_address = 0x62
Aivar Päkk1985f6f2011-12-11 18:15:00 -0300798};
799
Mauro Carvalho Chehab4159d012013-02-28 10:35:56 -0300800static const struct mb86a20s_config c3tech_duo_mb86a20s_config = {
801 .demod_address = 0x10,
802 .is_serial = true,
803};
804
805static struct tda18271_std_map mb86a20s_tda18271_config = {
806 .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4,
807 .if_lvl = 1, .rfagc_top = 0x37, },
808};
809
810static struct tda18271_config c3tech_duo_tda18271_config = {
811 .std_map = &mb86a20s_tda18271_config,
812 .gate = TDA18271_GATE_DIGITAL,
813 .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
814};
815
Antti Palosaariec573362013-02-25 09:01:13 -0300816static const struct m88ds3103_config pctv_461e_m88ds3103_config = {
817 .i2c_addr = 0x68,
818 .clock = 27000000,
819 .i2c_wr_max = 33,
820 .clock_out = 0,
821 .ts_mode = M88DS3103_TS_PARALLEL_16,
822 .agc = 0x99,
823};
824
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300825/* ------------------------------------------------------------------ */
826
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300827static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300828{
829 struct dvb_frontend *fe;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300830 struct xc2028_config cfg;
Mauro Carvalho Chehabee972072014-01-12 11:08:22 -0300831 struct xc2028_ctrl ctl;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300832
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300833 memset(&cfg, 0, sizeof(cfg));
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300834 cfg.i2c_adap = &dev->i2c_adap[dev->def_i2c_bus];
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300835 cfg.i2c_addr = addr;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300836
Mauro Carvalho Chehabee972072014-01-12 11:08:22 -0300837 memset(&ctl, 0, sizeof(ctl));
838 em28xx_setup_xc3028(dev, &ctl);
839 cfg.ctrl = &ctl;
840
Antti Palosaarif71095b2011-04-07 15:51:52 -0300841 if (!dev->dvb->fe[0]) {
Filipe Rosset480be182009-11-04 15:32:37 -0300842 em28xx_errdev("/2: dvb frontend not attached. "
843 "Can't attach xc3028\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300844 return -EINVAL;
845 }
846
Antti Palosaarif71095b2011-04-07 15:51:52 -0300847 fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300848 if (!fe) {
Filipe Rosset480be182009-11-04 15:32:37 -0300849 em28xx_errdev("/2: xc3028 attach failed\n");
Antti Palosaarif71095b2011-04-07 15:51:52 -0300850 dvb_frontend_detach(dev->dvb->fe[0]);
851 dev->dvb->fe[0] = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300852 return -EINVAL;
853 }
854
Filipe Rosset480be182009-11-04 15:32:37 -0300855 em28xx_info("%s/2: xc3028 attached\n", dev->name);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300856
857 return 0;
858}
859
Aidan Thornton3421b772008-04-17 21:40:36 -0300860/* ------------------------------------------------------------------ */
861
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300862static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
863 struct em28xx *dev, struct device *device)
Aidan Thornton3421b772008-04-17 21:40:36 -0300864{
865 int result;
866
867 mutex_init(&dvb->lock);
868
869 /* register adapter */
870 result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
871 adapter_nr);
872 if (result < 0) {
873 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
874 dev->name, result);
875 goto fail_adapter;
876 }
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300877
878 /* Ensure all frontends negotiate bus access */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300879 dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
880 if (dvb->fe[1])
881 dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300882
Hans Verkuil3de09fb2013-04-08 16:25:04 -0300883 dvb->adapter.priv = &dev->i2c_bus[dev->def_i2c_bus];
Aidan Thornton3421b772008-04-17 21:40:36 -0300884
885 /* register frontend */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300886 result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300887 if (result < 0) {
888 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
889 dev->name, result);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300890 goto fail_frontend0;
891 }
892
893 /* register 2nd frontend */
894 if (dvb->fe[1]) {
895 result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
896 if (result < 0) {
897 printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
898 dev->name, result);
899 goto fail_frontend1;
900 }
Aidan Thornton3421b772008-04-17 21:40:36 -0300901 }
902
903 /* register demux stuff */
904 dvb->demux.dmx.capabilities =
905 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
906 DMX_MEMORY_BASED_FILTERING;
907 dvb->demux.priv = dvb;
908 dvb->demux.filternum = 256;
909 dvb->demux.feednum = 256;
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300910 dvb->demux.start_feed = em28xx_start_feed;
911 dvb->demux.stop_feed = em28xx_stop_feed;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300912
Aidan Thornton3421b772008-04-17 21:40:36 -0300913 result = dvb_dmx_init(&dvb->demux);
914 if (result < 0) {
915 printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
916 dev->name, result);
917 goto fail_dmx;
918 }
919
920 dvb->dmxdev.filternum = 256;
921 dvb->dmxdev.demux = &dvb->demux.dmx;
922 dvb->dmxdev.capabilities = 0;
923 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
924 if (result < 0) {
925 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
926 dev->name, result);
927 goto fail_dmxdev;
928 }
929
930 dvb->fe_hw.source = DMX_FRONTEND_0;
931 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
932 if (result < 0) {
933 printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
934 dev->name, result);
935 goto fail_fe_hw;
936 }
937
938 dvb->fe_mem.source = DMX_MEMORY_FE;
939 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
940 if (result < 0) {
941 printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
942 dev->name, result);
943 goto fail_fe_mem;
944 }
945
946 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
947 if (result < 0) {
948 printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
949 dev->name, result);
950 goto fail_fe_conn;
951 }
952
953 /* register network adapter */
954 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
955 return 0;
956
957fail_fe_conn:
958 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
959fail_fe_mem:
960 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
961fail_fe_hw:
962 dvb_dmxdev_release(&dvb->dmxdev);
963fail_dmxdev:
964 dvb_dmx_release(&dvb->demux);
965fail_dmx:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300966 if (dvb->fe[1])
967 dvb_unregister_frontend(dvb->fe[1]);
968 dvb_unregister_frontend(dvb->fe[0]);
969fail_frontend1:
970 if (dvb->fe[1])
971 dvb_frontend_detach(dvb->fe[1]);
972fail_frontend0:
973 dvb_frontend_detach(dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300974 dvb_unregister_adapter(&dvb->adapter);
975fail_adapter:
976 return result;
977}
978
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300979static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
Aidan Thornton3421b772008-04-17 21:40:36 -0300980{
981 dvb_net_release(&dvb->net);
982 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
983 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
984 dvb_dmxdev_release(&dvb->dmxdev);
985 dvb_dmx_release(&dvb->demux);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300986 if (dvb->fe[1])
987 dvb_unregister_frontend(dvb->fe[1]);
988 dvb_unregister_frontend(dvb->fe[0]);
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -0300989 if (dvb->fe[1] && !dvb->dont_attach_fe1)
Antti Palosaarif71095b2011-04-07 15:51:52 -0300990 dvb_frontend_detach(dvb->fe[1]);
991 dvb_frontend_detach(dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300992 dvb_unregister_adapter(&dvb->adapter);
993}
994
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300995static int em28xx_dvb_init(struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300996{
Antti Palosaari13a53362012-07-19 22:28:56 -0300997 int result = 0, mfe_shared = 0;
Aidan Thornton3421b772008-04-17 21:40:36 -0300998 struct em28xx_dvb *dvb;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300999
Mauro Carvalho Chehab822b8de2014-01-06 05:27:47 -03001000 if (dev->is_audio_only) {
1001 /* Shouldn't initialize IR for this interface */
1002 return 0;
1003 }
1004
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -03001005 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -03001006 /* This device does not support the extension */
1007 return 0;
1008 }
1009
Mauro Carvalho Chehab96346142013-12-26 12:41:03 -03001010 em28xx_info("Binding DVB extension\n");
1011
Aidan Thornton3421b772008-04-17 21:40:36 -03001012 dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -03001013
1014 if (dvb == NULL) {
Filipe Rosset480be182009-11-04 15:32:37 -03001015 em28xx_info("em28xx_dvb: memory allocation failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -03001016 return -ENOMEM;
1017 }
1018 dev->dvb = dvb;
Antti Palosaarif71095b2011-04-07 15:51:52 -03001019 dvb->fe[0] = dvb->fe[1] = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001020
Frank Schaefer27ba0da2014-01-12 13:24:19 -03001021 /* pre-allocate DVB usb transfer buffers */
1022 if (dev->dvb_xfer_bulk) {
1023 result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
1024 dev->dvb_xfer_bulk,
1025 EM28XX_DVB_NUM_BUFS,
1026 512,
1027 EM28XX_DVB_BULK_PACKET_MULTIPLIER);
1028 } else {
1029 result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
1030 dev->dvb_xfer_bulk,
1031 EM28XX_DVB_NUM_BUFS,
1032 dev->dvb_max_pkt_size_isoc,
1033 EM28XX_DVB_NUM_ISOC_PACKETS);
1034 }
1035 if (result) {
1036 em28xx_errdev("em28xx_dvb: failed to pre-allocate USB transfer buffers for DVB.\n");
1037 kfree(dvb);
1038 dev->dvb = NULL;
1039 return result;
1040 }
1041
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -03001042 mutex_lock(&dev->lock);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -03001043 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001044 /* init frontend */
1045 switch (dev->model) {
Mauro Carvalho Chehabebaefdb2011-06-01 10:16:25 -03001046 case EM2874_BOARD_LEADERSHIP_ISDBT:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001047 dvb->fe[0] = dvb_attach(s921_attach,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001048 &sharp_isdbt, &dev->i2c_adap[dev->def_i2c_bus]);
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -03001049
Antti Palosaarif71095b2011-04-07 15:51:52 -03001050 if (!dvb->fe[0]) {
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -03001051 result = -EINVAL;
1052 goto out_free;
1053 }
1054
1055 break;
Douglas Schilling Landgraff89bc322008-12-01 21:01:04 -03001056 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
Mauro Carvalho Chehab10ac6602008-07-27 14:58:58 -03001057 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
Devin Heitmueller4fd305b2008-06-04 13:43:46 -03001058 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
Devin Heitmuellere14b3652008-07-26 11:04:33 -03001059 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001060 dvb->fe[0] = dvb_attach(lgdt330x_attach,
Aidan Thornton3421b772008-04-17 21:40:36 -03001061 &em2880_lgdt3303_dev,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001062 &dev->i2c_adap[dev->def_i2c_bus]);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001063 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Aidan Thornton3421b772008-04-17 21:40:36 -03001064 result = -EINVAL;
1065 goto out_free;
1066 }
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -03001067 break;
Thierry MERLE46510b52008-10-11 16:56:13 -03001068 case EM2880_BOARD_KWORLD_DVB_310U:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001069 dvb->fe[0] = dvb_attach(zl10353_attach,
Aidan Thornton3421b772008-04-17 21:40:36 -03001070 &em28xx_zl10353_with_xc3028,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001071 &dev->i2c_adap[dev->def_i2c_bus]);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001072 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Aidan Thornton3421b772008-04-17 21:40:36 -03001073 result = -EINVAL;
1074 goto out_free;
1075 }
Aidan Thornton7e6388a2008-04-17 21:40:03 -03001076 break;
Devin Heitmuellera84f79a2009-07-12 17:05:02 -03001077 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
Uroš Vamplec994d02009-09-30 22:53:37 -03001078 case EM2882_BOARD_TERRATEC_HYBRID_XS:
Devin Heitmueller01a5fd62009-08-07 09:25:06 -03001079 case EM2880_BOARD_EMPIRE_DUAL_TV:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001080 dvb->fe[0] = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -03001081 &em28xx_zl10353_xc3028_no_i2c_gate,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001082 &dev->i2c_adap[dev->def_i2c_bus]);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001083 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmuellera84f79a2009-07-12 17:05:02 -03001084 result = -EINVAL;
1085 goto out_free;
1086 }
1087 break;
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001088 case EM2880_BOARD_TERRATEC_HYBRID_XS:
Catimimi65638012010-02-18 18:06:32 -03001089 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
Devin Heitmuellerd5b3ba92009-07-08 21:51:35 -03001090 case EM2881_BOARD_PINNACLE_HYBRID_PRO:
Andrea.Amorosi76@gmail.com7ca7ef62010-02-09 17:53:38 -03001091 case EM2882_BOARD_DIKOM_DK300:
Antonio Larrosa811fab62010-03-04 22:19:48 -03001092 case EM2882_BOARD_KWORLD_VS_DVBT:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001093 dvb->fe[0] = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -03001094 &em28xx_zl10353_xc3028_no_i2c_gate,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001095 &dev->i2c_adap[dev->def_i2c_bus]);
Antti Palosaarif71095b2011-04-07 15:51:52 -03001096 if (dvb->fe[0] == NULL) {
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001097 /* This board could have either a zl10353 or a mt352.
1098 If the chip id isn't for zl10353, try mt352 */
Antti Palosaarif71095b2011-04-07 15:51:52 -03001099 dvb->fe[0] = dvb_attach(mt352_attach,
Devin Heitmueller4fb202a2009-07-12 17:51:12 -03001100 &terratec_xs_mt352_cfg,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001101 &dev->i2c_adap[dev->def_i2c_bus]);
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001102 }
Devin Heitmueller4fb202a2009-07-12 17:51:12 -03001103
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001104 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001105 result = -EINVAL;
1106 goto out_free;
1107 }
1108 break;
Aivar Päkk1985f6f2011-12-11 18:15:00 -03001109 case EM2870_BOARD_KWORLD_355U:
1110 dvb->fe[0] = dvb_attach(zl10353_attach,
1111 &em28xx_zl10353_no_i2c_gate_dev,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001112 &dev->i2c_adap[dev->def_i2c_bus]);
Aivar Päkk1985f6f2011-12-11 18:15:00 -03001113 if (dvb->fe[0] != NULL)
1114 dvb_attach(qt1010_attach, dvb->fe[0],
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001115 &dev->i2c_adap[dev->def_i2c_bus], &em28xx_qt1010_config);
Aivar Päkk1985f6f2011-12-11 18:15:00 -03001116 break;
Robert Krakora6e7b9ea2009-01-18 21:59:34 -03001117 case EM2883_BOARD_KWORLD_HYBRID_330U:
Devin Heitmueller19859222009-06-19 00:33:54 -03001118 case EM2882_BOARD_EVGA_INDTUBE:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001119 dvb->fe[0] = dvb_attach(s5h1409_attach,
Robert Krakora6e7b9ea2009-01-18 21:59:34 -03001120 &em28xx_s5h1409_with_xc3028,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001121 &dev->i2c_adap[dev->def_i2c_bus]);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001122 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Robert Krakora6e7b9ea2009-01-18 21:59:34 -03001123 result = -EINVAL;
1124 goto out_free;
1125 }
1126 break;
Franklin Mengd7de5d82009-06-06 17:05:02 -03001127 case EM2882_BOARD_KWORLD_ATSC_315U:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001128 dvb->fe[0] = dvb_attach(lgdt330x_attach,
Franklin Mengd7de5d82009-06-06 17:05:02 -03001129 &em2880_lgdt3303_dev,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001130 &dev->i2c_adap[dev->def_i2c_bus]);
Antti Palosaarif71095b2011-04-07 15:51:52 -03001131 if (dvb->fe[0] != NULL) {
1132 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001133 &dev->i2c_adap[dev->def_i2c_bus], 0x61, TUNER_THOMSON_DTT761X)) {
Franklin Mengd7de5d82009-06-06 17:05:02 -03001134 result = -EINVAL;
1135 goto out_free;
1136 }
1137 }
1138 break;
Devin Heitmueller17d9d552008-06-08 10:22:03 -03001139 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
Devin Heitmuellerad9b4bb2011-03-13 02:09:59 -03001140 case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001141 dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001142 &dev->i2c_adap[dev->def_i2c_bus], &dev->udev->dev);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001143 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmueller17d9d552008-06-08 10:22:03 -03001144 result = -EINVAL;
1145 goto out_free;
1146 }
1147 break;
Antti Palosaari285eb1a2009-09-15 14:42:13 -03001148 case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
1149 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
Antti Palosaarif71095b2011-04-07 15:51:52 -03001150 dvb->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari285eb1a2009-09-15 14:42:13 -03001151 &em28xx_tda10023_config,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001152 &dev->i2c_adap[dev->def_i2c_bus], 0x48);
Antti Palosaarif71095b2011-04-07 15:51:52 -03001153 if (dvb->fe[0]) {
1154 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001155 &dev->i2c_adap[dev->def_i2c_bus], 0x60, TUNER_PHILIPS_CU1216L)) {
Antti Palosaari285eb1a2009-09-15 14:42:13 -03001156 result = -EINVAL;
1157 goto out_free;
1158 }
1159 }
1160 break;
Jarod Wilson7e48b302010-03-07 17:55:43 -03001161 case EM2870_BOARD_KWORLD_A340:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001162 dvb->fe[0] = dvb_attach(lgdt3305_attach,
Jarod Wilson7e48b302010-03-07 17:55:43 -03001163 &em2870_lgdt3304_dev,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001164 &dev->i2c_adap[dev->def_i2c_bus]);
Antti Palosaarif71095b2011-04-07 15:51:52 -03001165 if (dvb->fe[0] != NULL)
1166 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001167 &dev->i2c_adap[dev->def_i2c_bus], &kworld_a340_config);
Jarod Wilson7e48b302010-03-07 17:55:43 -03001168 break;
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001169 case EM28174_BOARD_PCTV_290E:
Antti Palosaaria36a66d2012-08-16 21:07:23 -03001170 /* set default GPIO0 for LNA, used if GPIOLIB is undefined */
1171 dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O |
1172 CXD2820R_GPIO_L;
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001173 dvb->fe[0] = dvb_attach(cxd2820r_attach,
Manu Abraham7e7b8282011-12-10 00:44:24 -03001174 &em28xx_cxd2820r_config,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001175 &dev->i2c_adap[dev->def_i2c_bus],
Antti Palosaari13a53362012-07-19 22:28:56 -03001176 &dvb->lna_gpio);
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001177 if (dvb->fe[0]) {
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001178 /* FE 0 attach tuner */
Manu Abraham7e7b8282011-12-10 00:44:24 -03001179 if (!dvb_attach(tda18271_attach,
1180 dvb->fe[0],
1181 0x60,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001182 &dev->i2c_adap[dev->def_i2c_bus],
Manu Abraham7e7b8282011-12-10 00:44:24 -03001183 &em28xx_cxd2820r_tda18271_config)) {
1184
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001185 dvb_frontend_detach(dvb->fe[0]);
1186 result = -EINVAL;
1187 goto out_free;
1188 }
Antti Palosaari1e8f31f2012-07-19 21:10:36 -03001189
Antti Palosaari13a53362012-07-19 22:28:56 -03001190#ifdef CONFIG_GPIOLIB
Antti Palosaari0c42a552012-09-19 20:52:21 -03001191 /* enable LNA for DVB-T, DVB-T2 and DVB-C */
1192 result = gpio_request_one(dvb->lna_gpio,
1193 GPIOF_OUT_INIT_LOW, NULL);
1194 if (result)
1195 em28xx_errdev("gpio request failed %d\n",
1196 result);
1197 else
1198 gpio_free(dvb->lna_gpio);
Antti Palosaari1e8f31f2012-07-19 21:10:36 -03001199
Antti Palosaari0c42a552012-09-19 20:52:21 -03001200 result = 0; /* continue even set LNA fails */
Antti Palosaari13a53362012-07-19 22:28:56 -03001201#endif
Antti Palosaari0c42a552012-09-19 20:52:21 -03001202 dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
1203 }
1204
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001205 break;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001206 case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
Mauro Carvalho Chehab85032322011-11-24 15:01:45 -02001207 {
1208 struct xc5000_config cfg;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001209 hauppauge_hvr930c_init(dev);
1210
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001211 dvb->fe[0] = dvb_attach(drxk_attach,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001212 &hauppauge_930c_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001213 if (!dvb->fe[0]) {
1214 result = -EINVAL;
1215 goto out_free;
1216 }
1217 /* FIXME: do we need a pll semaphore? */
1218 dvb->fe[0]->sec_priv = dvb;
1219 sema_init(&dvb->pll_mutex, 1);
1220 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1221 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001222
1223 /* Attach xc5000 */
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001224 memset(&cfg, 0, sizeof(cfg));
1225 cfg.i2c_address = 0x61;
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001226 cfg.if_khz = 4000;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001227
1228 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1229 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001230 if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001231 &cfg)) {
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001232 result = -EINVAL;
1233 goto out_free;
1234 }
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001235 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1236 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1237
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001238 break;
Mauro Carvalho Chehab85032322011-11-24 15:01:45 -02001239 }
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001240 case EM2884_BOARD_TERRATEC_H5:
1241 terratec_h5_init(dev);
1242
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001243 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -03001244 if (!dvb->fe[0]) {
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001245 result = -EINVAL;
1246 goto out_free;
1247 }
1248 /* FIXME: do we need a pll semaphore? */
1249 dvb->fe[0]->sec_priv = dvb;
1250 sema_init(&dvb->pll_mutex, 1);
1251 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1252 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001253
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -03001254 /* Attach tda18271 to DVB-C frontend */
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001255 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1256 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001257 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus], 0x60)) {
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001258 result = -EINVAL;
1259 goto out_free;
1260 }
1261 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1262 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -03001263
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001264 break;
Mauro Carvalho Chehab4159d012013-02-28 10:35:56 -03001265 case EM2884_BOARD_C3TECH_DIGITAL_DUO:
1266 dvb->fe[0] = dvb_attach(mb86a20s_attach,
1267 &c3tech_duo_mb86a20s_config,
1268 &dev->i2c_adap[dev->def_i2c_bus]);
1269 if (dvb->fe[0] != NULL)
1270 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1271 &dev->i2c_adap[dev->def_i2c_bus],
1272 &c3tech_duo_tda18271_config);
1273 break;
Antti Palosaari36588712011-08-01 01:15:30 -03001274 case EM28174_BOARD_PCTV_460E:
1275 /* attach demod */
1276 dvb->fe[0] = dvb_attach(tda10071_attach,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001277 &em28xx_tda10071_config, &dev->i2c_adap[dev->def_i2c_bus]);
Antti Palosaari36588712011-08-01 01:15:30 -03001278
1279 /* attach SEC */
1280 if (dvb->fe[0])
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001281 dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
Antti Palosaari36588712011-08-01 01:15:30 -03001282 &em28xx_a8293_config);
1283 break;
Jakob Haufe7c1dfdb2013-04-13 11:03:37 -03001284 case EM2874_BOARD_DELOCK_61959:
Antti Palosaari35530852012-03-18 18:09:01 -03001285 case EM2874_BOARD_MAXMEDIA_UB425_TC:
1286 /* attach demodulator */
1287 dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001288 &dev->i2c_adap[dev->def_i2c_bus]);
Antti Palosaari35530852012-03-18 18:09:01 -03001289
1290 if (dvb->fe[0]) {
1291 /* disable I2C-gate */
1292 dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
1293
1294 /* attach tuner */
Antti Palosaarib6c7abb2013-10-04 15:17:51 -03001295 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1296 &dev->i2c_adap[dev->def_i2c_bus],
1297 &em28xx_cxd2820r_tda18271_config)) {
Antti Palosaari35530852012-03-18 18:09:01 -03001298 dvb_frontend_detach(dvb->fe[0]);
1299 result = -EINVAL;
1300 goto out_free;
1301 }
1302 }
Antti Palosaari35530852012-03-18 18:09:01 -03001303 break;
Ivan Kalvachevfa5527c2012-03-19 20:09:55 -03001304 case EM2884_BOARD_PCTV_510E:
1305 case EM2884_BOARD_PCTV_520E:
1306 pctv_520e_init(dev);
1307
1308 /* attach demodulator */
1309 dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001310 &dev->i2c_adap[dev->def_i2c_bus]);
Ivan Kalvachevfa5527c2012-03-19 20:09:55 -03001311
1312 if (dvb->fe[0]) {
1313 /* attach tuner */
1314 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001315 &dev->i2c_adap[dev->def_i2c_bus],
Ivan Kalvachevfa5527c2012-03-19 20:09:55 -03001316 &em28xx_cxd2820r_tda18271_config)) {
1317 dvb_frontend_detach(dvb->fe[0]);
1318 result = -EINVAL;
1319 goto out_free;
1320 }
1321 }
1322 break;
Martin Blumenstinglc8dce002012-06-12 18:19:28 -03001323 case EM2884_BOARD_CINERGY_HTC_STICK:
1324 terratec_htc_stick_init(dev);
1325
1326 /* attach demodulator */
1327 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001328 &dev->i2c_adap[dev->def_i2c_bus]);
Martin Blumenstinglc8dce002012-06-12 18:19:28 -03001329 if (!dvb->fe[0]) {
1330 result = -EINVAL;
1331 goto out_free;
1332 }
1333
1334 /* Attach the demodulator. */
1335 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001336 &dev->i2c_adap[dev->def_i2c_bus],
Martin Blumenstinglc8dce002012-06-12 18:19:28 -03001337 &em28xx_cxd2820r_tda18271_config)) {
1338 result = -EINVAL;
1339 goto out_free;
1340 }
1341 break;
Martin Blumenstingl89040132012-10-04 14:22:54 -03001342 case EM2884_BOARD_TERRATEC_HTC_USB_XS:
1343 terratec_htc_usb_xs_init(dev);
1344
1345 /* attach demodulator */
1346 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001347 &dev->i2c_adap[dev->def_i2c_bus]);
Martin Blumenstingl89040132012-10-04 14:22:54 -03001348 if (!dvb->fe[0]) {
1349 result = -EINVAL;
1350 goto out_free;
1351 }
1352
1353 /* Attach the demodulator. */
1354 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001355 &dev->i2c_adap[dev->def_i2c_bus],
Martin Blumenstingl89040132012-10-04 14:22:54 -03001356 &em28xx_cxd2820r_tda18271_config)) {
1357 result = -EINVAL;
1358 goto out_free;
1359 }
1360 break;
Jean-Francois Thibert6dbea9f2013-10-09 11:18:05 -03001361 case EM2874_BOARD_KWORLD_UB435Q_V2:
1362 dvb->fe[0] = dvb_attach(lgdt3305_attach,
1363 &em2874_lgdt3305_dev,
1364 &dev->i2c_adap[dev->def_i2c_bus]);
1365 if (!dvb->fe[0]) {
1366 result = -EINVAL;
1367 goto out_free;
1368 }
1369
1370 /* Attach the demodulator. */
1371 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1372 &dev->i2c_adap[dev->def_i2c_bus],
1373 &kworld_ub435q_v2_config)) {
1374 result = -EINVAL;
1375 goto out_free;
1376 }
1377 break;
Antti Palosaariec573362013-02-25 09:01:13 -03001378 case EM28178_BOARD_PCTV_461E:
1379 {
1380 /* demod I2C adapter */
1381 struct i2c_adapter *i2c_adapter;
Antti Palosaarieafa2ad2013-12-02 18:38:41 -03001382 struct i2c_board_info info;
1383 struct m88ts2022_config m88ts2022_config = {
1384 .clock = 27000000,
1385 };
1386 memset(&info, 0, sizeof(struct i2c_board_info));
Antti Palosaariec573362013-02-25 09:01:13 -03001387
1388 /* attach demod */
1389 dvb->fe[0] = dvb_attach(m88ds3103_attach,
1390 &pctv_461e_m88ds3103_config,
1391 &dev->i2c_adap[dev->def_i2c_bus],
1392 &i2c_adapter);
1393 if (dvb->fe[0] == NULL) {
1394 result = -ENODEV;
1395 goto out_free;
1396 }
1397
1398 /* attach tuner */
Antti Palosaarieafa2ad2013-12-02 18:38:41 -03001399 m88ts2022_config.fe = dvb->fe[0];
1400 strlcpy(info.type, "m88ts2022", I2C_NAME_SIZE);
1401 info.addr = 0x60;
1402 info.platform_data = &m88ts2022_config;
1403 request_module("m88ts2022");
1404 dvb->i2c_client_tuner = i2c_new_device(i2c_adapter, &info);
Antti Palosaariec573362013-02-25 09:01:13 -03001405
1406 /* delegate signal strength measurement to tuner */
1407 dvb->fe[0]->ops.read_signal_strength =
1408 dvb->fe[0]->ops.tuner_ops.get_rf_strength;
1409
1410 /* attach SEC */
1411 if (!dvb_attach(a8293_attach, dvb->fe[0],
1412 &dev->i2c_adap[dev->def_i2c_bus],
1413 &em28xx_a8293_config)) {
1414 dvb_frontend_detach(dvb->fe[0]);
1415 result = -ENODEV;
1416 goto out_free;
1417 }
1418 }
1419 break;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001420 default:
Filipe Rosset480be182009-11-04 15:32:37 -03001421 em28xx_errdev("/2: The frontend of your DVB/ATSC card"
1422 " isn't supported yet\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001423 break;
1424 }
Antti Palosaarif71095b2011-04-07 15:51:52 -03001425 if (NULL == dvb->fe[0]) {
Filipe Rosset480be182009-11-04 15:32:37 -03001426 em28xx_errdev("/2: frontend initialization failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -03001427 result = -EINVAL;
1428 goto out_free;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001429 }
Michael Krufkyd7cba042008-09-12 13:31:45 -03001430 /* define general-purpose callback pointer */
Antti Palosaarif71095b2011-04-07 15:51:52 -03001431 dvb->fe[0]->callback = em28xx_tuner_callback;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001432 if (dvb->fe[1])
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001433 dvb->fe[1]->callback = em28xx_tuner_callback;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001434
1435 /* register everything */
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001436 result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
Aidan Thornton3421b772008-04-17 21:40:36 -03001437
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -03001438 if (result < 0)
Aidan Thornton3421b772008-04-17 21:40:36 -03001439 goto out_free;
Aidan Thornton3421b772008-04-17 21:40:36 -03001440
Antti Palosaarie3645432011-07-28 18:59:30 -03001441 /* MFE lock */
1442 dvb->adapter.mfe_shared = mfe_shared;
1443
Mauro Carvalho Chehab96346142013-12-26 12:41:03 -03001444 em28xx_info("DVB extension successfully initialized\n");
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -03001445ret:
1446 em28xx_set_mode(dev, EM28XX_SUSPEND);
1447 mutex_unlock(&dev->lock);
1448 return result;
Aidan Thornton3421b772008-04-17 21:40:36 -03001449
1450out_free:
1451 kfree(dvb);
1452 dev->dvb = NULL;
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -03001453 goto ret;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001454}
1455
Chris Rankin0b8bd832011-08-20 16:01:26 -03001456static inline void prevent_sleep(struct dvb_frontend_ops *ops)
1457{
1458 ops->set_voltage = NULL;
1459 ops->sleep = NULL;
1460 ops->tuner_ops.sleep = NULL;
1461}
1462
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001463static int em28xx_dvb_fini(struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001464{
Mauro Carvalho Chehab822b8de2014-01-06 05:27:47 -03001465 if (dev->is_audio_only) {
1466 /* Shouldn't initialize IR for this interface */
1467 return 0;
1468 }
1469
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -03001470 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -03001471 /* This device does not support the extension */
1472 return 0;
1473 }
1474
Mauro Carvalho Chehabaa929ad2014-01-12 19:22:07 -03001475 em28xx_info("Closing DVB extension");
1476
Aidan Thornton3421b772008-04-17 21:40:36 -03001477 if (dev->dvb) {
Chris Rankin0b8bd832011-08-20 16:01:26 -03001478 struct em28xx_dvb *dvb = dev->dvb;
1479
Frank Schaefer27ba0da2014-01-12 13:24:19 -03001480 em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE);
1481
Frank Schaefer2665c292012-12-27 19:02:43 -03001482 if (dev->disconnected) {
Chris Rankin0b8bd832011-08-20 16:01:26 -03001483 /* We cannot tell the device to sleep
1484 * once it has been unplugged. */
1485 if (dvb->fe[0])
1486 prevent_sleep(&dvb->fe[0]->ops);
1487 if (dvb->fe[1])
1488 prevent_sleep(&dvb->fe[1]->ops);
1489 }
1490
Antti Palosaarieafa2ad2013-12-02 18:38:41 -03001491 i2c_release_client(dvb->i2c_client_tuner);
Chris Rankin0b8bd832011-08-20 16:01:26 -03001492 em28xx_unregister_dvb(dvb);
1493 kfree(dvb);
Aidan Thornton3421b772008-04-17 21:40:36 -03001494 dev->dvb = NULL;
1495 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001496
1497 return 0;
1498}
1499
1500static struct em28xx_ops dvb_ops = {
1501 .id = EM28XX_DVB,
1502 .name = "Em28xx dvb Extension",
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001503 .init = em28xx_dvb_init,
1504 .fini = em28xx_dvb_fini,
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001505};
1506
1507static int __init em28xx_dvb_register(void)
1508{
1509 return em28xx_register_extension(&dvb_ops);
1510}
1511
1512static void __exit em28xx_dvb_unregister(void)
1513{
1514 em28xx_unregister_extension(&dvb_ops);
1515}
1516
1517module_init(em28xx_dvb_register);
1518module_exit(em28xx_dvb_unregister);