blob: 301463f463c6889998e23f7333c1428e7c59c579 [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 }
Mauro Carvalho Chehabffdeca82014-03-02 08:20:54 -0300164 if (!urb->actual_length)
165 continue;
Frank Schaefera950e4a2012-11-08 14:11:47 -0300166 dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer,
167 urb->actual_length);
168 } else {
169 if (urb->iso_frame_desc[i].status < 0) {
170 print_err_status(dev, i,
171 urb->iso_frame_desc[i].status);
172 if (urb->iso_frame_desc[i].status != -EPROTO)
173 continue;
174 }
Mauro Carvalho Chehabffdeca82014-03-02 08:20:54 -0300175 if (!urb->iso_frame_desc[i].actual_length)
176 continue;
Frank Schaefera950e4a2012-11-08 14:11:47 -0300177 dvb_dmx_swfilter(&dev->dvb->demux,
178 urb->transfer_buffer +
179 urb->iso_frame_desc[i].offset,
180 urb->iso_frame_desc[i].actual_length);
Aidan Thornton3421b772008-04-17 21:40:36 -0300181 }
Aidan Thornton3421b772008-04-17 21:40:36 -0300182 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300183
184 return 0;
185}
186
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300187static int em28xx_start_streaming(struct em28xx_dvb *dvb)
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300188{
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300189 int rc;
Hans Verkuil3de09fb2013-04-08 16:25:04 -0300190 struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
191 struct em28xx *dev = i2c_bus->dev;
Frank Schaeferc647a912012-11-08 14:11:52 -0300192 int dvb_max_packet_size, packet_multiplier, dvb_alt;
Aidan Thornton3421b772008-04-17 21:40:36 -0300193
Frank Schaeferc647a912012-11-08 14:11:52 -0300194 if (dev->dvb_xfer_bulk) {
195 if (!dev->dvb_ep_bulk)
196 return -ENODEV;
197 dvb_max_packet_size = 512; /* USB 2.0 spec */
198 packet_multiplier = EM28XX_DVB_BULK_PACKET_MULTIPLIER;
199 dvb_alt = 0;
200 } else { /* isoc */
201 if (!dev->dvb_ep_isoc)
202 return -ENODEV;
203 dvb_max_packet_size = dev->dvb_max_pkt_size_isoc;
204 if (dvb_max_packet_size < 0)
205 return dvb_max_packet_size;
206 packet_multiplier = EM28XX_DVB_NUM_ISOC_PACKETS;
207 dvb_alt = dev->dvb_alt_isoc;
208 }
209
Frank Schaefer961717b2014-01-13 19:02:06 -0300210 usb_set_interface(dev->udev, dev->ifnum, dvb_alt);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300211 rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
212 if (rc < 0)
213 return rc;
Aidan Thornton3421b772008-04-17 21:40:36 -0300214
Gianluca Gennari86d38d12012-02-13 13:59:22 -0300215 dprintk(1, "Using %d buffers each with %d x %d bytes\n",
Mauro Carvalho Chehabf7acc4b2011-07-28 15:42:00 -0300216 EM28XX_DVB_NUM_BUFS,
Frank Schaeferc647a912012-11-08 14:11:52 -0300217 packet_multiplier,
218 dvb_max_packet_size);
Devin Heitmuellerd18e2fd2009-05-16 17:09:28 -0300219
Frank Schaeferc647a912012-11-08 14:11:52 -0300220 return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE,
221 dev->dvb_xfer_bulk,
Frank Schaefer057ca0d2012-11-08 14:11:42 -0300222 EM28XX_DVB_NUM_BUFS,
Frank Schaeferc647a912012-11-08 14:11:52 -0300223 dvb_max_packet_size,
224 packet_multiplier,
Frank Schaefera950e4a2012-11-08 14:11:47 -0300225 em28xx_dvb_urb_data_copy);
Aidan Thornton3421b772008-04-17 21:40:36 -0300226}
227
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300228static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300229{
Hans Verkuil3de09fb2013-04-08 16:25:04 -0300230 struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
231 struct em28xx *dev = i2c_bus->dev;
Aidan Thornton3421b772008-04-17 21:40:36 -0300232
Gianluca Gennari5f5f1472012-03-22 08:48:17 -0300233 em28xx_stop_urbs(dev);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300234
Aidan Thornton3421b772008-04-17 21:40:36 -0300235 return 0;
236}
237
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300238static int em28xx_start_feed(struct dvb_demux_feed *feed)
Aidan Thornton3421b772008-04-17 21:40:36 -0300239{
240 struct dvb_demux *demux = feed->demux;
241 struct em28xx_dvb *dvb = demux->priv;
242 int rc, ret;
243
244 if (!demux->dmx.frontend)
245 return -EINVAL;
246
247 mutex_lock(&dvb->lock);
248 dvb->nfeeds++;
249 rc = dvb->nfeeds;
250
251 if (dvb->nfeeds == 1) {
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300252 ret = em28xx_start_streaming(dvb);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300253 if (ret < 0)
254 rc = ret;
Aidan Thornton3421b772008-04-17 21:40:36 -0300255 }
256
257 mutex_unlock(&dvb->lock);
258 return rc;
259}
260
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300261static int em28xx_stop_feed(struct dvb_demux_feed *feed)
Aidan Thornton3421b772008-04-17 21:40:36 -0300262{
263 struct dvb_demux *demux = feed->demux;
264 struct em28xx_dvb *dvb = demux->priv;
265 int err = 0;
266
267 mutex_lock(&dvb->lock);
268 dvb->nfeeds--;
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300269
270 if (0 == dvb->nfeeds)
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300271 err = em28xx_stop_streaming(dvb);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300272
Aidan Thornton3421b772008-04-17 21:40:36 -0300273 mutex_unlock(&dvb->lock);
274 return err;
275}
276
277
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300278
279/* ------------------------------------------------------------------ */
280static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
281{
Mauro Carvalho Chehaba3b60202013-04-28 10:33:57 -0300282 struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
Mauro Carvalho Chehab96346142013-12-26 12:41:03 -0300283 struct em28xx *dev = i2c_bus->dev;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300284
285 if (acquire)
286 return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
287 else
Mauro Carvalho Chehab2fe3e2e2008-11-27 09:10:40 -0300288 return em28xx_set_mode(dev, EM28XX_SUSPEND);
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300289}
290
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300291/* ------------------------------------------------------------------ */
292
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -0300293static struct lgdt330x_config em2880_lgdt3303_dev = {
294 .demod_address = 0x0e,
295 .demod_chip = LGDT3303,
296};
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300297
Jarod Wilson7e48b302010-03-07 17:55:43 -0300298static struct lgdt3305_config em2870_lgdt3304_dev = {
299 .i2c_addr = 0x0e,
300 .demod_chip = LGDT3304,
301 .spectral_inversion = 1,
302 .deny_i2c_rptr = 1,
303 .mpeg_mode = LGDT3305_MPEG_PARALLEL,
304 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
305 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
306 .vsb_if_khz = 3250,
307 .qam_if_khz = 4000,
308};
309
Jean-Francois Thibert6dbea9f2013-10-09 11:18:05 -0300310static struct lgdt3305_config em2874_lgdt3305_dev = {
311 .i2c_addr = 0x0e,
312 .demod_chip = LGDT3305,
313 .spectral_inversion = 1,
314 .deny_i2c_rptr = 0,
315 .mpeg_mode = LGDT3305_MPEG_SERIAL,
316 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
317 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
318 .vsb_if_khz = 3250,
319 .qam_if_khz = 4000,
320};
321
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300322static struct s921_config sharp_isdbt = {
323 .demod_address = 0x30 >> 1
324};
325
Aidan Thornton7e6388a2008-04-17 21:40:03 -0300326static struct zl10353_config em28xx_zl10353_with_xc3028 = {
327 .demod_address = (0x1e >> 1),
328 .no_tuner = 1,
329 .parallel_ts = 1,
330 .if2 = 45600,
331};
332
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300333static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
334 .demod_address = 0x32 >> 1,
335 .output_mode = S5H1409_PARALLEL_OUTPUT,
336 .gpio = S5H1409_GPIO_OFF,
337 .inversion = S5H1409_INVERSION_OFF,
338 .status_mode = S5H1409_DEMODLOCKING,
339 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
340};
341
Jarod Wilson7e48b302010-03-07 17:55:43 -0300342static struct tda18271_std_map kworld_a340_std_map = {
343 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
344 .if_lvl = 1, .rfagc_top = 0x37, },
345 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
346 .if_lvl = 1, .rfagc_top = 0x37, },
347};
348
349static struct tda18271_config kworld_a340_config = {
350 .std_map = &kworld_a340_std_map,
351};
352
Jean-Francois Thibert6dbea9f2013-10-09 11:18:05 -0300353static struct tda18271_config kworld_ub435q_v2_config = {
354 .std_map = &kworld_a340_std_map,
355 .gate = TDA18271_GATE_DIGITAL,
356};
357
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300358static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300359 .demod_address = (0x1e >> 1),
360 .no_tuner = 1,
361 .disable_i2c_gate_ctrl = 1,
362 .parallel_ts = 1,
363 .if2 = 45600,
364};
365
Devin Heitmueller75e2b862011-03-13 02:01:02 -0300366static struct drxd_config em28xx_drxd = {
Mauro Carvalho Chehabaac865f2011-12-26 09:41:14 -0300367 .demod_address = 0x70,
368 .demod_revision = 0xa2,
369 .pll_type = DRXD_PLL_NONE,
370 .clock = 12000,
371 .insert_rs_byte = 1,
372 .IF = 42800000,
Devin Heitmueller6b142b32011-03-13 02:02:01 -0300373 .disable_i2c_gate_ctrl = 1,
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300374};
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300375
Ezequiel García61bdbef2012-06-12 09:53:41 -0300376static struct drxk_config terratec_h5_drxk = {
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300377 .adr = 0x29,
Mauro Carvalho Chehabe4f4f872011-07-09 17:35:26 -0300378 .single_master = 1,
Mauro Carvalho Chehabf1fe1b72011-07-09 21:59:33 -0300379 .no_i2c_bridge = 1,
Mauro Carvalho Chehab8b9456a2011-07-11 14:33:51 -0300380 .microcode_name = "dvb-usb-terratec-h5-drxk.fw",
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300381 .qam_demod_parameter_count = 2,
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300382};
383
Ezequiel García61bdbef2012-06-12 09:53:41 -0300384static struct drxk_config hauppauge_930c_drxk = {
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300385 .adr = 0x29,
386 .single_master = 1,
387 .no_i2c_bridge = 1,
388 .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
389 .chunk_size = 56,
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300390 .qam_demod_parameter_count = 2,
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300391};
392
Martin Blumenstingl89040132012-10-04 14:22:54 -0300393static struct drxk_config terratec_htc_stick_drxk = {
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300394 .adr = 0x29,
395 .single_master = 1,
396 .no_i2c_bridge = 1,
397 .microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw",
398 .chunk_size = 54,
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300399 .qam_demod_parameter_count = 2,
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300400 /* Required for the antenna_gpio to disable LNA. */
401 .antenna_dvbt = true,
402 /* The windows driver uses the same. This will disable LNA. */
403 .antenna_gpio = 0x6,
404};
405
Ezequiel García61bdbef2012-06-12 09:53:41 -0300406static struct drxk_config maxmedia_ub425_tc_drxk = {
Antti Palosaari35530852012-03-18 18:09:01 -0300407 .adr = 0x29,
408 .single_master = 1,
409 .no_i2c_bridge = 1,
Antti Palosaari8d100b22013-10-04 14:40:06 -0300410 .microcode_name = "dvb-demod-drxk-01.fw",
411 .chunk_size = 62,
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 */
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300423};
424
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300425static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
426{
427 struct em28xx_dvb *dvb = fe->sec_priv;
428 int status;
429
430 if (!dvb)
431 return -EINVAL;
432
433 if (enable) {
434 down(&dvb->pll_mutex);
435 status = dvb->gate_ctrl(fe, 1);
436 } else {
437 status = dvb->gate_ctrl(fe, 0);
438 up(&dvb->pll_mutex);
439 }
440 return status;
441}
442
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300443static void hauppauge_hvr930c_init(struct em28xx *dev)
444{
445 int i;
446
447 struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
Frank Schaefer907d1092013-06-03 14:12:02 -0300448 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0x65},
449 {EM2874_R80_GPIO_P0_CTRL, 0xfb, 0xff, 0x32},
450 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0xb8},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300451 { -1, -1, -1, -1},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300452 };
453 struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
Frank Schaefer907d1092013-06-03 14:12:02 -0300454 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
455 {EM2874_R80_GPIO_P0_CTRL, 0xaf, 0xff, 0x65},
456 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x76},
457 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
458 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
459 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x40},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300460
Frank Schaefer907d1092013-06-03 14:12:02 -0300461 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x65},
462 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
463 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
464 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300465
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300466 { -1, -1, -1, -1},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300467 };
468
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300469 struct {
470 unsigned char r[4];
471 int len;
472 } regs[] = {
473 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
474 {{ 0x01, 0x02 }, 2},
475 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
476 {{ 0x01, 0x00 }, 2},
477 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
478 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
479 {{ 0x01, 0x00 }, 2},
480 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
481 {{ 0x04, 0x00 }, 2},
482 {{ 0x00, 0x04 }, 2},
483 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
484 {{ 0x04, 0x14 }, 2},
485 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
486 };
487
488 em28xx_gpio_set(dev, hauppauge_hvr930c_init);
489 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
490 msleep(10);
491 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
492 msleep(10);
493
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300494 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300495
496 for (i = 0; i < ARRAY_SIZE(regs); i++)
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300497 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300498 em28xx_gpio_set(dev, hauppauge_hvr930c_end);
499
500 msleep(100);
501
502 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
503 msleep(30);
504
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300505 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
506 msleep(10);
507
508}
509
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300510static void terratec_h5_init(struct em28xx *dev)
511{
512 int i;
513 struct em28xx_reg_seq terratec_h5_init[] = {
Frank Schaeferc074fc42013-06-03 14:12:03 -0300514 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
Frank Schaefer907d1092013-06-03 14:12:02 -0300515 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
516 {EM2874_R80_GPIO_P0_CTRL, 0xf2, 0xff, 50},
517 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300518 { -1, -1, -1, -1},
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300519 };
520 struct em28xx_reg_seq terratec_h5_end[] = {
Frank Schaefer907d1092013-06-03 14:12:02 -0300521 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
522 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
523 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300524 { -1, -1, -1, -1},
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300525 };
526 struct {
527 unsigned char r[4];
528 int len;
529 } regs[] = {
530 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
531 {{ 0x01, 0x02 }, 2},
532 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
533 {{ 0x01, 0x00 }, 2},
534 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
535 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
536 {{ 0x01, 0x00 }, 2},
537 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
538 {{ 0x04, 0x00 }, 2},
539 {{ 0x00, 0x04 }, 2},
540 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
541 {{ 0x04, 0x14 }, 2},
542 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
543 };
544
545 em28xx_gpio_set(dev, terratec_h5_init);
546 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
547 msleep(10);
548 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
549 msleep(10);
550
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300551 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300552
553 for (i = 0; i < ARRAY_SIZE(regs); i++)
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300554 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300555 em28xx_gpio_set(dev, terratec_h5_end);
556};
557
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300558static void terratec_htc_stick_init(struct em28xx *dev)
559{
560 int i;
561
562 /*
563 * GPIO configuration:
564 * 0xff: unknown (does not affect DVB-T).
565 * 0xf6: DRX-K (demodulator).
566 * 0xe6: unknown (does not affect DVB-T).
567 * 0xb6: unknown (does not affect DVB-T).
568 */
569 struct em28xx_reg_seq terratec_htc_stick_init[] = {
Frank Schaeferc074fc42013-06-03 14:12:03 -0300570 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
Frank Schaefer907d1092013-06-03 14:12:02 -0300571 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
572 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 50},
573 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300574 { -1, -1, -1, -1},
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300575 };
576 struct em28xx_reg_seq terratec_htc_stick_end[] = {
Frank Schaefer907d1092013-06-03 14:12:02 -0300577 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
578 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 50},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300579 { -1, -1, -1, -1},
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300580 };
581
Martin Blumenstingl89040132012-10-04 14:22:54 -0300582 /*
583 * Init the analog decoder (not yet supported), but
584 * it's probably still a good idea.
585 */
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300586 struct {
587 unsigned char r[4];
588 int len;
589 } regs[] = {
590 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
591 {{ 0x01, 0x02 }, 2},
592 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
593 {{ 0x01, 0x00 }, 2},
594 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
595 };
596
597 em28xx_gpio_set(dev, terratec_htc_stick_init);
598
599 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
600 msleep(10);
601 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
602 msleep(10);
603
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300604 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300605
606 for (i = 0; i < ARRAY_SIZE(regs); i++)
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300607 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300608
609 em28xx_gpio_set(dev, terratec_htc_stick_end);
610};
611
Martin Blumenstingl89040132012-10-04 14:22:54 -0300612static void terratec_htc_usb_xs_init(struct em28xx *dev)
613{
614 int i;
615
616 struct em28xx_reg_seq terratec_htc_usb_xs_init[] = {
Frank Schaeferc074fc42013-06-03 14:12:03 -0300617 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
Frank Schaefer907d1092013-06-03 14:12:02 -0300618 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 100},
619 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 50},
620 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300621 { -1, -1, -1, -1},
Martin Blumenstingl89040132012-10-04 14:22:54 -0300622 };
623 struct em28xx_reg_seq terratec_htc_usb_xs_end[] = {
Frank Schaefer907d1092013-06-03 14:12:02 -0300624 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 100},
625 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
626 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300627 { -1, -1, -1, -1},
Martin Blumenstingl89040132012-10-04 14:22:54 -0300628 };
629
630 /*
631 * Init the analog decoder (not yet supported), but
632 * it's probably still a good idea.
633 */
634 struct {
635 unsigned char r[4];
636 int len;
637 } regs[] = {
638 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
639 {{ 0x01, 0x02 }, 2},
640 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
641 {{ 0x01, 0x00 }, 2},
642 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
643 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
644 {{ 0x01, 0x00 }, 2},
645 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
646 {{ 0x04, 0x00 }, 2},
647 {{ 0x00, 0x04 }, 2},
648 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
649 {{ 0x04, 0x14 }, 2},
650 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
651 };
652
653 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
654
655 em28xx_gpio_set(dev, terratec_htc_usb_xs_init);
656
657 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
658 msleep(10);
659 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
660 msleep(10);
661
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300662 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
Martin Blumenstingl89040132012-10-04 14:22:54 -0300663
664 for (i = 0; i < ARRAY_SIZE(regs); i++)
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300665 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
Martin Blumenstingl89040132012-10-04 14:22:54 -0300666
667 em28xx_gpio_set(dev, terratec_htc_usb_xs_end);
668};
669
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300670static void pctv_520e_init(struct em28xx *dev)
671{
672 /*
Antti Palosaari26c8a722012-05-17 18:22:02 -0300673 * Init AVF4910B analog decoder. Looks like I2C traffic to
674 * digital demodulator and tuner are routed via AVF4910B.
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300675 */
676 int i;
677 struct {
678 unsigned char r[4];
679 int len;
680 } regs[] = {
681 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
682 {{ 0x01, 0x02 }, 2},
683 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
684 {{ 0x01, 0x00 }, 2},
685 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
686 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
687 {{ 0x01, 0x00 }, 2},
688 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
689 };
690
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300691 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; /* 0x41 */
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300692
693 for (i = 0; i < ARRAY_SIZE(regs); i++)
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300694 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300695};
696
Antti Palosaari33eebec2012-10-03 04:28:56 -0300697static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
Antti Palosaari13a53362012-07-19 22:28:56 -0300698{
Antti Palosaari33eebec2012-10-03 04:28:56 -0300699 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
Antti Palosaari13a53362012-07-19 22:28:56 -0300700 struct em28xx *dev = fe->dvb->priv;
701#ifdef CONFIG_GPIOLIB
702 struct em28xx_dvb *dvb = dev->dvb;
703 int ret;
704 unsigned long flags;
705
Antti Palosaari33eebec2012-10-03 04:28:56 -0300706 if (c->lna == 1)
707 flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
Antti Palosaari13a53362012-07-19 22:28:56 -0300708 else
Antti Palosaari33eebec2012-10-03 04:28:56 -0300709 flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
Antti Palosaari13a53362012-07-19 22:28:56 -0300710
711 ret = gpio_request_one(dvb->lna_gpio, flags, NULL);
712 if (ret)
713 em28xx_errdev("gpio request failed %d\n", ret);
714 else
715 gpio_free(dvb->lna_gpio);
716
717 return ret;
718#else
Antti Palosaari33eebec2012-10-03 04:28:56 -0300719 dev_warn(&dev->udev->dev, "%s: LNA control is disabled (lna=%u)\n",
720 KBUILD_MODNAME, c->lna);
Antti Palosaari13a53362012-07-19 22:28:56 -0300721 return 0;
722#endif
723}
724
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300725static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300726{
727 /* Values extracted from a USB trace of the Terratec Windows driver */
728 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
729 static u8 reset[] = { RESET, 0x80 };
730 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
731 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
732 static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
733 static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
734 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
735 static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
736 static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
Devin Heitmuellerff697862009-07-12 18:44:19 -0300737 static u8 tuner_go[] = { TUNER_GO, 0x01};
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300738
739 mt352_write(fe, clock_config, sizeof(clock_config));
740 udelay(200);
741 mt352_write(fe, reset, sizeof(reset));
742 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
743 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
744 mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
745 mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
746 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
747 mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
748 mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
749 mt352_write(fe, tuner_go, sizeof(tuner_go));
750 return 0;
751}
752
753static struct mt352_config terratec_xs_mt352_cfg = {
754 .demod_address = (0x1e >> 1),
755 .no_tuner = 1,
756 .if2 = 45600,
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300757 .demod_init = em28xx_mt352_terratec_xs_init,
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300758};
759
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300760static struct tda10023_config em28xx_tda10023_config = {
761 .demod_address = 0x0c,
762 .invert = 1,
763};
764
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300765static struct cxd2820r_config em28xx_cxd2820r_config = {
766 .i2c_address = (0xd8 >> 1),
767 .ts_mode = CXD2820R_TS_SERIAL,
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300768};
769
770static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
771 .output_opt = TDA18271_OUTPUT_LT_OFF,
Steve Kerrison0db4bf42011-08-09 07:16:21 -0300772 .gate = TDA18271_GATE_DIGITAL,
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300773};
774
Antti Palosaari36588712011-08-01 01:15:30 -0300775static const struct tda10071_config em28xx_tda10071_config = {
Michael Krufky41f55d52012-12-16 19:37:11 -0300776 .demod_i2c_addr = 0x55, /* (0xaa >> 1) */
777 .tuner_i2c_addr = 0x14,
Antti Palosaari36588712011-08-01 01:15:30 -0300778 .i2c_wr_max = 64,
779 .ts_mode = TDA10071_TS_SERIAL,
780 .spec_inv = 0,
781 .xtal = 40444000, /* 40.444 MHz */
782 .pll_multiplier = 20,
783};
784
785static const struct a8293_config em28xx_a8293_config = {
786 .i2c_addr = 0x08, /* (0x10 >> 1) */
787};
788
Aivar Päkk1985f6f2011-12-11 18:15:00 -0300789static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
790 .demod_address = (0x1e >> 1),
791 .disable_i2c_gate_ctrl = 1,
792 .no_tuner = 1,
793 .parallel_ts = 1,
794};
795static struct qt1010_config em28xx_qt1010_config = {
796 .i2c_address = 0x62
Aivar Päkk1985f6f2011-12-11 18:15:00 -0300797};
798
Mauro Carvalho Chehab4159d012013-02-28 10:35:56 -0300799static const struct mb86a20s_config c3tech_duo_mb86a20s_config = {
800 .demod_address = 0x10,
801 .is_serial = true,
802};
803
804static struct tda18271_std_map mb86a20s_tda18271_config = {
805 .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4,
806 .if_lvl = 1, .rfagc_top = 0x37, },
807};
808
809static struct tda18271_config c3tech_duo_tda18271_config = {
810 .std_map = &mb86a20s_tda18271_config,
811 .gate = TDA18271_GATE_DIGITAL,
812 .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
813};
814
Antti Palosaariec573362013-02-25 09:01:13 -0300815static const struct m88ds3103_config pctv_461e_m88ds3103_config = {
816 .i2c_addr = 0x68,
817 .clock = 27000000,
818 .i2c_wr_max = 33,
819 .clock_out = 0,
820 .ts_mode = M88DS3103_TS_PARALLEL_16,
821 .agc = 0x99,
822};
823
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300824/* ------------------------------------------------------------------ */
825
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300826static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300827{
828 struct dvb_frontend *fe;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300829 struct xc2028_config cfg;
Mauro Carvalho Chehabee972072014-01-12 11:08:22 -0300830 struct xc2028_ctrl ctl;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300831
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300832 memset(&cfg, 0, sizeof(cfg));
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300833 cfg.i2c_adap = &dev->i2c_adap[dev->def_i2c_bus];
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300834 cfg.i2c_addr = addr;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300835
Mauro Carvalho Chehabee972072014-01-12 11:08:22 -0300836 memset(&ctl, 0, sizeof(ctl));
837 em28xx_setup_xc3028(dev, &ctl);
838 cfg.ctrl = &ctl;
839
Antti Palosaarif71095b2011-04-07 15:51:52 -0300840 if (!dev->dvb->fe[0]) {
Filipe Rosset480be182009-11-04 15:32:37 -0300841 em28xx_errdev("/2: dvb frontend not attached. "
842 "Can't attach xc3028\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300843 return -EINVAL;
844 }
845
Antti Palosaarif71095b2011-04-07 15:51:52 -0300846 fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300847 if (!fe) {
Filipe Rosset480be182009-11-04 15:32:37 -0300848 em28xx_errdev("/2: xc3028 attach failed\n");
Antti Palosaarif71095b2011-04-07 15:51:52 -0300849 dvb_frontend_detach(dev->dvb->fe[0]);
850 dev->dvb->fe[0] = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300851 return -EINVAL;
852 }
853
Filipe Rosset480be182009-11-04 15:32:37 -0300854 em28xx_info("%s/2: xc3028 attached\n", dev->name);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300855
856 return 0;
857}
858
Aidan Thornton3421b772008-04-17 21:40:36 -0300859/* ------------------------------------------------------------------ */
860
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300861static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
862 struct em28xx *dev, struct device *device)
Aidan Thornton3421b772008-04-17 21:40:36 -0300863{
864 int result;
865
866 mutex_init(&dvb->lock);
867
868 /* register adapter */
869 result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
870 adapter_nr);
871 if (result < 0) {
872 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
873 dev->name, result);
874 goto fail_adapter;
875 }
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300876
877 /* Ensure all frontends negotiate bus access */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300878 dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
879 if (dvb->fe[1])
880 dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300881
Hans Verkuil3de09fb2013-04-08 16:25:04 -0300882 dvb->adapter.priv = &dev->i2c_bus[dev->def_i2c_bus];
Aidan Thornton3421b772008-04-17 21:40:36 -0300883
884 /* register frontend */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300885 result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300886 if (result < 0) {
887 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
888 dev->name, result);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300889 goto fail_frontend0;
890 }
891
892 /* register 2nd frontend */
893 if (dvb->fe[1]) {
894 result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
895 if (result < 0) {
896 printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
897 dev->name, result);
898 goto fail_frontend1;
899 }
Aidan Thornton3421b772008-04-17 21:40:36 -0300900 }
901
902 /* register demux stuff */
903 dvb->demux.dmx.capabilities =
904 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
905 DMX_MEMORY_BASED_FILTERING;
906 dvb->demux.priv = dvb;
907 dvb->demux.filternum = 256;
908 dvb->demux.feednum = 256;
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300909 dvb->demux.start_feed = em28xx_start_feed;
910 dvb->demux.stop_feed = em28xx_stop_feed;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300911
Aidan Thornton3421b772008-04-17 21:40:36 -0300912 result = dvb_dmx_init(&dvb->demux);
913 if (result < 0) {
914 printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
915 dev->name, result);
916 goto fail_dmx;
917 }
918
919 dvb->dmxdev.filternum = 256;
920 dvb->dmxdev.demux = &dvb->demux.dmx;
921 dvb->dmxdev.capabilities = 0;
922 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
923 if (result < 0) {
924 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
925 dev->name, result);
926 goto fail_dmxdev;
927 }
928
929 dvb->fe_hw.source = DMX_FRONTEND_0;
930 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
931 if (result < 0) {
932 printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
933 dev->name, result);
934 goto fail_fe_hw;
935 }
936
937 dvb->fe_mem.source = DMX_MEMORY_FE;
938 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
939 if (result < 0) {
940 printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
941 dev->name, result);
942 goto fail_fe_mem;
943 }
944
945 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
946 if (result < 0) {
947 printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
948 dev->name, result);
949 goto fail_fe_conn;
950 }
951
952 /* register network adapter */
953 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
954 return 0;
955
956fail_fe_conn:
957 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
958fail_fe_mem:
959 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
960fail_fe_hw:
961 dvb_dmxdev_release(&dvb->dmxdev);
962fail_dmxdev:
963 dvb_dmx_release(&dvb->demux);
964fail_dmx:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300965 if (dvb->fe[1])
966 dvb_unregister_frontend(dvb->fe[1]);
967 dvb_unregister_frontend(dvb->fe[0]);
968fail_frontend1:
969 if (dvb->fe[1])
970 dvb_frontend_detach(dvb->fe[1]);
971fail_frontend0:
972 dvb_frontend_detach(dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300973 dvb_unregister_adapter(&dvb->adapter);
974fail_adapter:
975 return result;
976}
977
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300978static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
Aidan Thornton3421b772008-04-17 21:40:36 -0300979{
980 dvb_net_release(&dvb->net);
981 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
982 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
983 dvb_dmxdev_release(&dvb->dmxdev);
984 dvb_dmx_release(&dvb->demux);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300985 if (dvb->fe[1])
986 dvb_unregister_frontend(dvb->fe[1]);
987 dvb_unregister_frontend(dvb->fe[0]);
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -0300988 if (dvb->fe[1] && !dvb->dont_attach_fe1)
Antti Palosaarif71095b2011-04-07 15:51:52 -0300989 dvb_frontend_detach(dvb->fe[1]);
990 dvb_frontend_detach(dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300991 dvb_unregister_adapter(&dvb->adapter);
992}
993
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300994static int em28xx_dvb_init(struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300995{
Antti Palosaari13a53362012-07-19 22:28:56 -0300996 int result = 0, mfe_shared = 0;
Aidan Thornton3421b772008-04-17 21:40:36 -0300997 struct em28xx_dvb *dvb;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300998
Mauro Carvalho Chehab822b8de2014-01-06 05:27:47 -0300999 if (dev->is_audio_only) {
1000 /* Shouldn't initialize IR for this interface */
1001 return 0;
1002 }
1003
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -03001004 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -03001005 /* This device does not support the extension */
1006 return 0;
1007 }
1008
Mauro Carvalho Chehab96346142013-12-26 12:41:03 -03001009 em28xx_info("Binding DVB extension\n");
1010
Aidan Thornton3421b772008-04-17 21:40:36 -03001011 dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -03001012
1013 if (dvb == NULL) {
Filipe Rosset480be182009-11-04 15:32:37 -03001014 em28xx_info("em28xx_dvb: memory allocation failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -03001015 return -ENOMEM;
1016 }
1017 dev->dvb = dvb;
Antti Palosaarif71095b2011-04-07 15:51:52 -03001018 dvb->fe[0] = dvb->fe[1] = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001019
Frank Schaefer27ba0da2014-01-12 13:24:19 -03001020 /* pre-allocate DVB usb transfer buffers */
1021 if (dev->dvb_xfer_bulk) {
1022 result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
1023 dev->dvb_xfer_bulk,
1024 EM28XX_DVB_NUM_BUFS,
1025 512,
1026 EM28XX_DVB_BULK_PACKET_MULTIPLIER);
1027 } else {
1028 result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
1029 dev->dvb_xfer_bulk,
1030 EM28XX_DVB_NUM_BUFS,
1031 dev->dvb_max_pkt_size_isoc,
1032 EM28XX_DVB_NUM_ISOC_PACKETS);
1033 }
1034 if (result) {
1035 em28xx_errdev("em28xx_dvb: failed to pre-allocate USB transfer buffers for DVB.\n");
1036 kfree(dvb);
1037 dev->dvb = NULL;
1038 return result;
1039 }
1040
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -03001041 mutex_lock(&dev->lock);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -03001042 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001043 /* init frontend */
1044 switch (dev->model) {
Mauro Carvalho Chehabebaefdb2011-06-01 10:16:25 -03001045 case EM2874_BOARD_LEADERSHIP_ISDBT:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001046 dvb->fe[0] = dvb_attach(s921_attach,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001047 &sharp_isdbt, &dev->i2c_adap[dev->def_i2c_bus]);
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -03001048
Antti Palosaarif71095b2011-04-07 15:51:52 -03001049 if (!dvb->fe[0]) {
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -03001050 result = -EINVAL;
1051 goto out_free;
1052 }
1053
1054 break;
Douglas Schilling Landgraff89bc322008-12-01 21:01:04 -03001055 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
Mauro Carvalho Chehab10ac6602008-07-27 14:58:58 -03001056 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
Devin Heitmueller4fd305b2008-06-04 13:43:46 -03001057 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
Devin Heitmuellere14b3652008-07-26 11:04:33 -03001058 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001059 dvb->fe[0] = dvb_attach(lgdt330x_attach,
Aidan Thornton3421b772008-04-17 21:40:36 -03001060 &em2880_lgdt3303_dev,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001061 &dev->i2c_adap[dev->def_i2c_bus]);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001062 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Aidan Thornton3421b772008-04-17 21:40:36 -03001063 result = -EINVAL;
1064 goto out_free;
1065 }
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -03001066 break;
Thierry MERLE46510b52008-10-11 16:56:13 -03001067 case EM2880_BOARD_KWORLD_DVB_310U:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001068 dvb->fe[0] = dvb_attach(zl10353_attach,
Aidan Thornton3421b772008-04-17 21:40:36 -03001069 &em28xx_zl10353_with_xc3028,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001070 &dev->i2c_adap[dev->def_i2c_bus]);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001071 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Aidan Thornton3421b772008-04-17 21:40:36 -03001072 result = -EINVAL;
1073 goto out_free;
1074 }
Aidan Thornton7e6388a2008-04-17 21:40:03 -03001075 break;
Devin Heitmuellera84f79a2009-07-12 17:05:02 -03001076 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
Uroš Vamplec994d02009-09-30 22:53:37 -03001077 case EM2882_BOARD_TERRATEC_HYBRID_XS:
Devin Heitmueller01a5fd62009-08-07 09:25:06 -03001078 case EM2880_BOARD_EMPIRE_DUAL_TV:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001079 dvb->fe[0] = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -03001080 &em28xx_zl10353_xc3028_no_i2c_gate,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001081 &dev->i2c_adap[dev->def_i2c_bus]);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001082 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmuellera84f79a2009-07-12 17:05:02 -03001083 result = -EINVAL;
1084 goto out_free;
1085 }
1086 break;
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001087 case EM2880_BOARD_TERRATEC_HYBRID_XS:
Catimimi65638012010-02-18 18:06:32 -03001088 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
Devin Heitmuellerd5b3ba92009-07-08 21:51:35 -03001089 case EM2881_BOARD_PINNACLE_HYBRID_PRO:
Andrea.Amorosi76@gmail.com7ca7ef62010-02-09 17:53:38 -03001090 case EM2882_BOARD_DIKOM_DK300:
Antonio Larrosa811fab62010-03-04 22:19:48 -03001091 case EM2882_BOARD_KWORLD_VS_DVBT:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001092 dvb->fe[0] = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -03001093 &em28xx_zl10353_xc3028_no_i2c_gate,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001094 &dev->i2c_adap[dev->def_i2c_bus]);
Antti Palosaarif71095b2011-04-07 15:51:52 -03001095 if (dvb->fe[0] == NULL) {
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001096 /* This board could have either a zl10353 or a mt352.
1097 If the chip id isn't for zl10353, try mt352 */
Antti Palosaarif71095b2011-04-07 15:51:52 -03001098 dvb->fe[0] = dvb_attach(mt352_attach,
Devin Heitmueller4fb202a2009-07-12 17:51:12 -03001099 &terratec_xs_mt352_cfg,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001100 &dev->i2c_adap[dev->def_i2c_bus]);
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001101 }
Devin Heitmueller4fb202a2009-07-12 17:51:12 -03001102
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001103 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001104 result = -EINVAL;
1105 goto out_free;
1106 }
1107 break;
Aivar Päkk1985f6f2011-12-11 18:15:00 -03001108 case EM2870_BOARD_KWORLD_355U:
1109 dvb->fe[0] = dvb_attach(zl10353_attach,
1110 &em28xx_zl10353_no_i2c_gate_dev,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001111 &dev->i2c_adap[dev->def_i2c_bus]);
Aivar Päkk1985f6f2011-12-11 18:15:00 -03001112 if (dvb->fe[0] != NULL)
1113 dvb_attach(qt1010_attach, dvb->fe[0],
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001114 &dev->i2c_adap[dev->def_i2c_bus], &em28xx_qt1010_config);
Aivar Päkk1985f6f2011-12-11 18:15:00 -03001115 break;
Robert Krakora6e7b9ea2009-01-18 21:59:34 -03001116 case EM2883_BOARD_KWORLD_HYBRID_330U:
Devin Heitmueller19859222009-06-19 00:33:54 -03001117 case EM2882_BOARD_EVGA_INDTUBE:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001118 dvb->fe[0] = dvb_attach(s5h1409_attach,
Robert Krakora6e7b9ea2009-01-18 21:59:34 -03001119 &em28xx_s5h1409_with_xc3028,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001120 &dev->i2c_adap[dev->def_i2c_bus]);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001121 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Robert Krakora6e7b9ea2009-01-18 21:59:34 -03001122 result = -EINVAL;
1123 goto out_free;
1124 }
1125 break;
Franklin Mengd7de5d82009-06-06 17:05:02 -03001126 case EM2882_BOARD_KWORLD_ATSC_315U:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001127 dvb->fe[0] = dvb_attach(lgdt330x_attach,
Franklin Mengd7de5d82009-06-06 17:05:02 -03001128 &em2880_lgdt3303_dev,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001129 &dev->i2c_adap[dev->def_i2c_bus]);
Antti Palosaarif71095b2011-04-07 15:51:52 -03001130 if (dvb->fe[0] != NULL) {
1131 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001132 &dev->i2c_adap[dev->def_i2c_bus], 0x61, TUNER_THOMSON_DTT761X)) {
Franklin Mengd7de5d82009-06-06 17:05:02 -03001133 result = -EINVAL;
1134 goto out_free;
1135 }
1136 }
1137 break;
Devin Heitmueller17d9d552008-06-08 10:22:03 -03001138 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
Devin Heitmuellerad9b4bb2011-03-13 02:09:59 -03001139 case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001140 dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001141 &dev->i2c_adap[dev->def_i2c_bus], &dev->udev->dev);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001142 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmueller17d9d552008-06-08 10:22:03 -03001143 result = -EINVAL;
1144 goto out_free;
1145 }
1146 break;
Antti Palosaari285eb1a2009-09-15 14:42:13 -03001147 case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
1148 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
Antti Palosaarif71095b2011-04-07 15:51:52 -03001149 dvb->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari285eb1a2009-09-15 14:42:13 -03001150 &em28xx_tda10023_config,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001151 &dev->i2c_adap[dev->def_i2c_bus], 0x48);
Antti Palosaarif71095b2011-04-07 15:51:52 -03001152 if (dvb->fe[0]) {
1153 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001154 &dev->i2c_adap[dev->def_i2c_bus], 0x60, TUNER_PHILIPS_CU1216L)) {
Antti Palosaari285eb1a2009-09-15 14:42:13 -03001155 result = -EINVAL;
1156 goto out_free;
1157 }
1158 }
1159 break;
Jarod Wilson7e48b302010-03-07 17:55:43 -03001160 case EM2870_BOARD_KWORLD_A340:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001161 dvb->fe[0] = dvb_attach(lgdt3305_attach,
Jarod Wilson7e48b302010-03-07 17:55:43 -03001162 &em2870_lgdt3304_dev,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001163 &dev->i2c_adap[dev->def_i2c_bus]);
Antti Palosaarif71095b2011-04-07 15:51:52 -03001164 if (dvb->fe[0] != NULL)
1165 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001166 &dev->i2c_adap[dev->def_i2c_bus], &kworld_a340_config);
Jarod Wilson7e48b302010-03-07 17:55:43 -03001167 break;
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001168 case EM28174_BOARD_PCTV_290E:
Antti Palosaaria36a66d2012-08-16 21:07:23 -03001169 /* set default GPIO0 for LNA, used if GPIOLIB is undefined */
1170 dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O |
1171 CXD2820R_GPIO_L;
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001172 dvb->fe[0] = dvb_attach(cxd2820r_attach,
Manu Abraham7e7b8282011-12-10 00:44:24 -03001173 &em28xx_cxd2820r_config,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001174 &dev->i2c_adap[dev->def_i2c_bus],
Antti Palosaari13a53362012-07-19 22:28:56 -03001175 &dvb->lna_gpio);
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001176 if (dvb->fe[0]) {
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001177 /* FE 0 attach tuner */
Manu Abraham7e7b8282011-12-10 00:44:24 -03001178 if (!dvb_attach(tda18271_attach,
1179 dvb->fe[0],
1180 0x60,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001181 &dev->i2c_adap[dev->def_i2c_bus],
Manu Abraham7e7b8282011-12-10 00:44:24 -03001182 &em28xx_cxd2820r_tda18271_config)) {
1183
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001184 dvb_frontend_detach(dvb->fe[0]);
1185 result = -EINVAL;
1186 goto out_free;
1187 }
Antti Palosaari1e8f31f2012-07-19 21:10:36 -03001188
Antti Palosaari13a53362012-07-19 22:28:56 -03001189#ifdef CONFIG_GPIOLIB
Antti Palosaari0c42a552012-09-19 20:52:21 -03001190 /* enable LNA for DVB-T, DVB-T2 and DVB-C */
1191 result = gpio_request_one(dvb->lna_gpio,
1192 GPIOF_OUT_INIT_LOW, NULL);
1193 if (result)
1194 em28xx_errdev("gpio request failed %d\n",
1195 result);
1196 else
1197 gpio_free(dvb->lna_gpio);
Antti Palosaari1e8f31f2012-07-19 21:10:36 -03001198
Antti Palosaari0c42a552012-09-19 20:52:21 -03001199 result = 0; /* continue even set LNA fails */
Antti Palosaari13a53362012-07-19 22:28:56 -03001200#endif
Antti Palosaari0c42a552012-09-19 20:52:21 -03001201 dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
1202 }
1203
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001204 break;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001205 case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
Mauro Carvalho Chehab85032322011-11-24 15:01:45 -02001206 {
1207 struct xc5000_config cfg;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001208 hauppauge_hvr930c_init(dev);
1209
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001210 dvb->fe[0] = dvb_attach(drxk_attach,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001211 &hauppauge_930c_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001212 if (!dvb->fe[0]) {
1213 result = -EINVAL;
1214 goto out_free;
1215 }
1216 /* FIXME: do we need a pll semaphore? */
1217 dvb->fe[0]->sec_priv = dvb;
1218 sema_init(&dvb->pll_mutex, 1);
1219 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1220 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001221
1222 /* Attach xc5000 */
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001223 memset(&cfg, 0, sizeof(cfg));
1224 cfg.i2c_address = 0x61;
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001225 cfg.if_khz = 4000;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001226
1227 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1228 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001229 if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001230 &cfg)) {
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001231 result = -EINVAL;
1232 goto out_free;
1233 }
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001234 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1235 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1236
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001237 break;
Mauro Carvalho Chehab85032322011-11-24 15:01:45 -02001238 }
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001239 case EM2884_BOARD_TERRATEC_H5:
1240 terratec_h5_init(dev);
1241
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001242 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 -03001243 if (!dvb->fe[0]) {
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001244 result = -EINVAL;
1245 goto out_free;
1246 }
1247 /* FIXME: do we need a pll semaphore? */
1248 dvb->fe[0]->sec_priv = dvb;
1249 sema_init(&dvb->pll_mutex, 1);
1250 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1251 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001252
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -03001253 /* Attach tda18271 to DVB-C frontend */
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001254 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1255 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001256 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus], 0x60)) {
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001257 result = -EINVAL;
1258 goto out_free;
1259 }
1260 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1261 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -03001262
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001263 break;
Mauro Carvalho Chehab4159d012013-02-28 10:35:56 -03001264 case EM2884_BOARD_C3TECH_DIGITAL_DUO:
1265 dvb->fe[0] = dvb_attach(mb86a20s_attach,
1266 &c3tech_duo_mb86a20s_config,
1267 &dev->i2c_adap[dev->def_i2c_bus]);
1268 if (dvb->fe[0] != NULL)
1269 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1270 &dev->i2c_adap[dev->def_i2c_bus],
1271 &c3tech_duo_tda18271_config);
1272 break;
Antti Palosaari36588712011-08-01 01:15:30 -03001273 case EM28174_BOARD_PCTV_460E:
1274 /* attach demod */
1275 dvb->fe[0] = dvb_attach(tda10071_attach,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001276 &em28xx_tda10071_config, &dev->i2c_adap[dev->def_i2c_bus]);
Antti Palosaari36588712011-08-01 01:15:30 -03001277
1278 /* attach SEC */
1279 if (dvb->fe[0])
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001280 dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
Antti Palosaari36588712011-08-01 01:15:30 -03001281 &em28xx_a8293_config);
1282 break;
Jakob Haufe7c1dfdb2013-04-13 11:03:37 -03001283 case EM2874_BOARD_DELOCK_61959:
Antti Palosaari35530852012-03-18 18:09:01 -03001284 case EM2874_BOARD_MAXMEDIA_UB425_TC:
1285 /* attach demodulator */
1286 dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001287 &dev->i2c_adap[dev->def_i2c_bus]);
Antti Palosaari35530852012-03-18 18:09:01 -03001288
1289 if (dvb->fe[0]) {
1290 /* disable I2C-gate */
1291 dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
1292
1293 /* attach tuner */
Antti Palosaarib6c7abb2013-10-04 15:17:51 -03001294 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1295 &dev->i2c_adap[dev->def_i2c_bus],
1296 &em28xx_cxd2820r_tda18271_config)) {
Antti Palosaari35530852012-03-18 18:09:01 -03001297 dvb_frontend_detach(dvb->fe[0]);
1298 result = -EINVAL;
1299 goto out_free;
1300 }
1301 }
Antti Palosaari35530852012-03-18 18:09:01 -03001302 break;
Ivan Kalvachevfa5527c2012-03-19 20:09:55 -03001303 case EM2884_BOARD_PCTV_510E:
1304 case EM2884_BOARD_PCTV_520E:
1305 pctv_520e_init(dev);
1306
1307 /* attach demodulator */
1308 dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001309 &dev->i2c_adap[dev->def_i2c_bus]);
Ivan Kalvachevfa5527c2012-03-19 20:09:55 -03001310
1311 if (dvb->fe[0]) {
1312 /* attach tuner */
1313 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001314 &dev->i2c_adap[dev->def_i2c_bus],
Ivan Kalvachevfa5527c2012-03-19 20:09:55 -03001315 &em28xx_cxd2820r_tda18271_config)) {
1316 dvb_frontend_detach(dvb->fe[0]);
1317 result = -EINVAL;
1318 goto out_free;
1319 }
1320 }
1321 break;
Martin Blumenstinglc8dce002012-06-12 18:19:28 -03001322 case EM2884_BOARD_CINERGY_HTC_STICK:
1323 terratec_htc_stick_init(dev);
1324
1325 /* attach demodulator */
1326 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001327 &dev->i2c_adap[dev->def_i2c_bus]);
Martin Blumenstinglc8dce002012-06-12 18:19:28 -03001328 if (!dvb->fe[0]) {
1329 result = -EINVAL;
1330 goto out_free;
1331 }
1332
1333 /* Attach the demodulator. */
1334 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001335 &dev->i2c_adap[dev->def_i2c_bus],
Martin Blumenstinglc8dce002012-06-12 18:19:28 -03001336 &em28xx_cxd2820r_tda18271_config)) {
1337 result = -EINVAL;
1338 goto out_free;
1339 }
1340 break;
Martin Blumenstingl89040132012-10-04 14:22:54 -03001341 case EM2884_BOARD_TERRATEC_HTC_USB_XS:
1342 terratec_htc_usb_xs_init(dev);
1343
1344 /* attach demodulator */
1345 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001346 &dev->i2c_adap[dev->def_i2c_bus]);
Martin Blumenstingl89040132012-10-04 14:22:54 -03001347 if (!dvb->fe[0]) {
1348 result = -EINVAL;
1349 goto out_free;
1350 }
1351
1352 /* Attach the demodulator. */
1353 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001354 &dev->i2c_adap[dev->def_i2c_bus],
Martin Blumenstingl89040132012-10-04 14:22:54 -03001355 &em28xx_cxd2820r_tda18271_config)) {
1356 result = -EINVAL;
1357 goto out_free;
1358 }
1359 break;
Jean-Francois Thibert6dbea9f2013-10-09 11:18:05 -03001360 case EM2874_BOARD_KWORLD_UB435Q_V2:
1361 dvb->fe[0] = dvb_attach(lgdt3305_attach,
1362 &em2874_lgdt3305_dev,
1363 &dev->i2c_adap[dev->def_i2c_bus]);
1364 if (!dvb->fe[0]) {
1365 result = -EINVAL;
1366 goto out_free;
1367 }
1368
1369 /* Attach the demodulator. */
1370 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1371 &dev->i2c_adap[dev->def_i2c_bus],
1372 &kworld_ub435q_v2_config)) {
1373 result = -EINVAL;
1374 goto out_free;
1375 }
1376 break;
Antti Palosaariec573362013-02-25 09:01:13 -03001377 case EM28178_BOARD_PCTV_461E:
1378 {
1379 /* demod I2C adapter */
1380 struct i2c_adapter *i2c_adapter;
Antti Palosaari425f53a2014-02-12 14:46:44 -03001381 struct i2c_client *client;
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");
Antti Palosaari425f53a2014-02-12 14:46:44 -03001404 client = i2c_new_device(i2c_adapter, &info);
1405 if (client == NULL || client->dev.driver == NULL) {
1406 dvb_frontend_detach(dvb->fe[0]);
1407 result = -ENODEV;
1408 goto out_free;
1409 }
1410
1411 if (!try_module_get(client->dev.driver->owner)) {
1412 i2c_unregister_device(client);
1413 dvb_frontend_detach(dvb->fe[0]);
1414 result = -ENODEV;
1415 goto out_free;
1416 }
Antti Palosaariec573362013-02-25 09:01:13 -03001417
1418 /* delegate signal strength measurement to tuner */
1419 dvb->fe[0]->ops.read_signal_strength =
1420 dvb->fe[0]->ops.tuner_ops.get_rf_strength;
1421
1422 /* attach SEC */
1423 if (!dvb_attach(a8293_attach, dvb->fe[0],
1424 &dev->i2c_adap[dev->def_i2c_bus],
1425 &em28xx_a8293_config)) {
Antti Palosaari425f53a2014-02-12 14:46:44 -03001426 module_put(client->dev.driver->owner);
1427 i2c_unregister_device(client);
Antti Palosaariec573362013-02-25 09:01:13 -03001428 dvb_frontend_detach(dvb->fe[0]);
1429 result = -ENODEV;
1430 goto out_free;
1431 }
Antti Palosaari425f53a2014-02-12 14:46:44 -03001432
1433 dvb->i2c_client_tuner = client;
Antti Palosaariec573362013-02-25 09:01:13 -03001434 }
1435 break;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001436 default:
Filipe Rosset480be182009-11-04 15:32:37 -03001437 em28xx_errdev("/2: The frontend of your DVB/ATSC card"
1438 " isn't supported yet\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001439 break;
1440 }
Antti Palosaarif71095b2011-04-07 15:51:52 -03001441 if (NULL == dvb->fe[0]) {
Filipe Rosset480be182009-11-04 15:32:37 -03001442 em28xx_errdev("/2: frontend initialization failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -03001443 result = -EINVAL;
1444 goto out_free;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001445 }
Michael Krufkyd7cba042008-09-12 13:31:45 -03001446 /* define general-purpose callback pointer */
Antti Palosaarif71095b2011-04-07 15:51:52 -03001447 dvb->fe[0]->callback = em28xx_tuner_callback;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001448 if (dvb->fe[1])
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001449 dvb->fe[1]->callback = em28xx_tuner_callback;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001450
1451 /* register everything */
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001452 result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
Aidan Thornton3421b772008-04-17 21:40:36 -03001453
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -03001454 if (result < 0)
Aidan Thornton3421b772008-04-17 21:40:36 -03001455 goto out_free;
Aidan Thornton3421b772008-04-17 21:40:36 -03001456
Antti Palosaarie3645432011-07-28 18:59:30 -03001457 /* MFE lock */
1458 dvb->adapter.mfe_shared = mfe_shared;
1459
Mauro Carvalho Chehab96346142013-12-26 12:41:03 -03001460 em28xx_info("DVB extension successfully initialized\n");
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -03001461ret:
1462 em28xx_set_mode(dev, EM28XX_SUSPEND);
1463 mutex_unlock(&dev->lock);
1464 return result;
Aidan Thornton3421b772008-04-17 21:40:36 -03001465
1466out_free:
1467 kfree(dvb);
1468 dev->dvb = NULL;
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -03001469 goto ret;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001470}
1471
Chris Rankin0b8bd832011-08-20 16:01:26 -03001472static inline void prevent_sleep(struct dvb_frontend_ops *ops)
1473{
1474 ops->set_voltage = NULL;
1475 ops->sleep = NULL;
1476 ops->tuner_ops.sleep = NULL;
1477}
1478
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001479static int em28xx_dvb_fini(struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001480{
Mauro Carvalho Chehab822b8de2014-01-06 05:27:47 -03001481 if (dev->is_audio_only) {
1482 /* Shouldn't initialize IR for this interface */
1483 return 0;
1484 }
1485
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -03001486 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -03001487 /* This device does not support the extension */
1488 return 0;
1489 }
1490
Mauro Carvalho Chehabaa929ad2014-01-12 19:22:07 -03001491 em28xx_info("Closing DVB extension");
1492
Aidan Thornton3421b772008-04-17 21:40:36 -03001493 if (dev->dvb) {
Chris Rankin0b8bd832011-08-20 16:01:26 -03001494 struct em28xx_dvb *dvb = dev->dvb;
Antti Palosaari425f53a2014-02-12 14:46:44 -03001495 struct i2c_client *client = dvb->i2c_client_tuner;
Chris Rankin0b8bd832011-08-20 16:01:26 -03001496
Frank Schaefer27ba0da2014-01-12 13:24:19 -03001497 em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE);
1498
Frank Schaefer2665c292012-12-27 19:02:43 -03001499 if (dev->disconnected) {
Chris Rankin0b8bd832011-08-20 16:01:26 -03001500 /* We cannot tell the device to sleep
1501 * once it has been unplugged. */
1502 if (dvb->fe[0])
1503 prevent_sleep(&dvb->fe[0]->ops);
1504 if (dvb->fe[1])
1505 prevent_sleep(&dvb->fe[1]->ops);
1506 }
1507
Antti Palosaari425f53a2014-02-12 14:46:44 -03001508 /* remove I2C tuner */
1509 if (client) {
1510 module_put(client->dev.driver->owner);
1511 i2c_unregister_device(client);
1512 }
1513
Chris Rankin0b8bd832011-08-20 16:01:26 -03001514 em28xx_unregister_dvb(dvb);
1515 kfree(dvb);
Aidan Thornton3421b772008-04-17 21:40:36 -03001516 dev->dvb = NULL;
1517 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001518
1519 return 0;
1520}
1521
Shuah Khanca2b46d2014-02-21 21:50:15 -03001522static int em28xx_dvb_suspend(struct em28xx *dev)
1523{
1524 int ret = 0;
1525
1526 if (dev->is_audio_only)
1527 return 0;
1528
1529 if (!dev->board.has_dvb)
1530 return 0;
1531
1532 em28xx_info("Suspending DVB extension");
1533 if (dev->dvb) {
1534 struct em28xx_dvb *dvb = dev->dvb;
1535
1536 if (dvb->fe[0]) {
1537 ret = dvb_frontend_suspend(dvb->fe[0]);
1538 em28xx_info("fe0 suspend %d", ret);
1539 }
1540 if (dvb->fe[1]) {
1541 dvb_frontend_suspend(dvb->fe[1]);
1542 em28xx_info("fe1 suspend %d", ret);
1543 }
1544 }
1545
1546 return 0;
1547}
1548
1549static int em28xx_dvb_resume(struct em28xx *dev)
1550{
1551 int ret = 0;
1552
1553 if (dev->is_audio_only)
1554 return 0;
1555
1556 if (!dev->board.has_dvb)
1557 return 0;
1558
1559 em28xx_info("Resuming DVB extension");
1560 if (dev->dvb) {
1561 struct em28xx_dvb *dvb = dev->dvb;
1562
1563 if (dvb->fe[0]) {
1564 ret = dvb_frontend_resume(dvb->fe[0]);
1565 em28xx_info("fe0 resume %d", ret);
1566 }
1567
1568 if (dvb->fe[1]) {
1569 ret = dvb_frontend_resume(dvb->fe[1]);
1570 em28xx_info("fe1 resume %d", ret);
1571 }
1572 }
1573
1574 return 0;
1575}
1576
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001577static struct em28xx_ops dvb_ops = {
1578 .id = EM28XX_DVB,
1579 .name = "Em28xx dvb Extension",
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001580 .init = em28xx_dvb_init,
1581 .fini = em28xx_dvb_fini,
Shuah Khanca2b46d2014-02-21 21:50:15 -03001582 .suspend = em28xx_dvb_suspend,
1583 .resume = em28xx_dvb_resume,
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001584};
1585
1586static int __init em28xx_dvb_register(void)
1587{
1588 return em28xx_register_extension(&dvb_ops);
1589}
1590
1591static void __exit em28xx_dvb_unregister(void)
1592{
1593 em28xx_unregister_extension(&dvb_ops);
1594}
1595
1596module_init(em28xx_dvb_register);
1597module_exit(em28xx_dvb_unregister);