blob: 4f8f687ea99a5ace88eed71e2cc88787fcd088c9 [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
57MODULE_DESCRIPTION("driver for em28xx based DVB cards");
58MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
59MODULE_LICENSE("GPL");
60
61static unsigned int debug;
62module_param(debug, int, 0644);
63MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
64
65DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
66
67#define dprintk(level, fmt, arg...) do { \
68if (debug >= level) \
Aidan Thornton3421b772008-04-17 21:40:36 -030069 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030070} while (0)
71
Aidan Thornton3421b772008-04-17 21:40:36 -030072struct em28xx_dvb {
Antti Palosaarif71095b2011-04-07 15:51:52 -030073 struct dvb_frontend *fe[2];
Aidan Thornton3421b772008-04-17 21:40:36 -030074
75 /* feed count management */
76 struct mutex lock;
77 int nfeeds;
78
79 /* general boilerplate stuff */
80 struct dvb_adapter adapter;
81 struct dvb_demux demux;
82 struct dmxdev dmxdev;
83 struct dmx_frontend fe_hw;
84 struct dmx_frontend fe_mem;
85 struct dvb_net net;
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -030086
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -030087 /* Due to DRX-K - probably need changes */
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -030088 int (*gate_ctrl)(struct dvb_frontend *, int);
89 struct semaphore pll_mutex;
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -030090 bool dont_attach_fe1;
Antti Palosaari13a53362012-07-19 22:28:56 -030091 int lna_gpio;
Aidan Thornton3421b772008-04-17 21:40:36 -030092};
93
94
95static inline void print_err_status(struct em28xx *dev,
96 int packet, int status)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030097{
Aidan Thornton3421b772008-04-17 21:40:36 -030098 char *errmsg = "Unknown";
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030099
Aidan Thornton3421b772008-04-17 21:40:36 -0300100 switch (status) {
101 case -ENOENT:
102 errmsg = "unlinked synchronuously";
103 break;
104 case -ECONNRESET:
105 errmsg = "unlinked asynchronuously";
106 break;
107 case -ENOSR:
108 errmsg = "Buffer error (overrun)";
109 break;
110 case -EPIPE:
111 errmsg = "Stalled (device not responding)";
112 break;
113 case -EOVERFLOW:
114 errmsg = "Babble (bad cable?)";
115 break;
116 case -EPROTO:
117 errmsg = "Bit-stuff error (bad cable?)";
118 break;
119 case -EILSEQ:
120 errmsg = "CRC/Timeout (could be anything)";
121 break;
122 case -ETIME:
123 errmsg = "Device does not respond";
124 break;
125 }
126 if (packet < 0) {
127 dprintk(1, "URB status %d [%s].\n", status, errmsg);
128 } else {
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300129 dprintk(1, "URB packet %d, status %d [%s].\n",
130 packet, status, errmsg);
Aidan Thornton3421b772008-04-17 21:40:36 -0300131 }
132}
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300133
Frank Schaefera950e4a2012-11-08 14:11:47 -0300134static inline int em28xx_dvb_urb_data_copy(struct em28xx *dev, struct urb *urb)
Aidan Thornton3421b772008-04-17 21:40:36 -0300135{
Frank Schaefera950e4a2012-11-08 14:11:47 -0300136 int xfer_bulk, num_packets, i;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300137
Aidan Thornton3421b772008-04-17 21:40:36 -0300138 if (!dev)
139 return 0;
140
Frank Schaefer2665c292012-12-27 19:02:43 -0300141 if (dev->disconnected)
Aidan Thornton3421b772008-04-17 21:40:36 -0300142 return 0;
143
Frank Schaefer1653cb0c2012-11-08 14:11:44 -0300144 if (urb->status < 0)
Aidan Thornton3421b772008-04-17 21:40:36 -0300145 print_err_status(dev, -1, urb->status);
Aidan Thornton3421b772008-04-17 21:40:36 -0300146
Frank Schaefera950e4a2012-11-08 14:11:47 -0300147 xfer_bulk = usb_pipebulk(urb->pipe);
Aidan Thornton3421b772008-04-17 21:40:36 -0300148
Frank Schaefera950e4a2012-11-08 14:11:47 -0300149 if (xfer_bulk) /* bulk */
150 num_packets = 1;
151 else /* isoc */
152 num_packets = urb->number_of_packets;
153
154 for (i = 0; i < num_packets; i++) {
155 if (xfer_bulk) {
156 if (urb->status < 0) {
157 print_err_status(dev, i, urb->status);
158 if (urb->status != -EPROTO)
159 continue;
160 }
161 dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer,
162 urb->actual_length);
163 } else {
164 if (urb->iso_frame_desc[i].status < 0) {
165 print_err_status(dev, i,
166 urb->iso_frame_desc[i].status);
167 if (urb->iso_frame_desc[i].status != -EPROTO)
168 continue;
169 }
170 dvb_dmx_swfilter(&dev->dvb->demux,
171 urb->transfer_buffer +
172 urb->iso_frame_desc[i].offset,
173 urb->iso_frame_desc[i].actual_length);
Aidan Thornton3421b772008-04-17 21:40:36 -0300174 }
Aidan Thornton3421b772008-04-17 21:40:36 -0300175 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300176
177 return 0;
178}
179
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300180static int em28xx_start_streaming(struct em28xx_dvb *dvb)
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300181{
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300182 int rc;
Hans Verkuil3de09fb2013-04-08 16:25:04 -0300183 struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
184 struct em28xx *dev = i2c_bus->dev;
Frank Schaeferc647a912012-11-08 14:11:52 -0300185 int dvb_max_packet_size, packet_multiplier, dvb_alt;
Aidan Thornton3421b772008-04-17 21:40:36 -0300186
Frank Schaeferc647a912012-11-08 14:11:52 -0300187 if (dev->dvb_xfer_bulk) {
188 if (!dev->dvb_ep_bulk)
189 return -ENODEV;
190 dvb_max_packet_size = 512; /* USB 2.0 spec */
191 packet_multiplier = EM28XX_DVB_BULK_PACKET_MULTIPLIER;
192 dvb_alt = 0;
193 } else { /* isoc */
194 if (!dev->dvb_ep_isoc)
195 return -ENODEV;
196 dvb_max_packet_size = dev->dvb_max_pkt_size_isoc;
197 if (dvb_max_packet_size < 0)
198 return dvb_max_packet_size;
199 packet_multiplier = EM28XX_DVB_NUM_ISOC_PACKETS;
200 dvb_alt = dev->dvb_alt_isoc;
201 }
202
203 usb_set_interface(dev->udev, 0, dvb_alt);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300204 rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
205 if (rc < 0)
206 return rc;
Aidan Thornton3421b772008-04-17 21:40:36 -0300207
Gianluca Gennari86d38d12012-02-13 13:59:22 -0300208 dprintk(1, "Using %d buffers each with %d x %d bytes\n",
Mauro Carvalho Chehabf7acc4b2011-07-28 15:42:00 -0300209 EM28XX_DVB_NUM_BUFS,
Frank Schaeferc647a912012-11-08 14:11:52 -0300210 packet_multiplier,
211 dvb_max_packet_size);
Devin Heitmuellerd18e2fd2009-05-16 17:09:28 -0300212
Frank Schaeferc647a912012-11-08 14:11:52 -0300213 return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE,
214 dev->dvb_xfer_bulk,
Frank Schaefer057ca0d2012-11-08 14:11:42 -0300215 EM28XX_DVB_NUM_BUFS,
Frank Schaeferc647a912012-11-08 14:11:52 -0300216 dvb_max_packet_size,
217 packet_multiplier,
Frank Schaefera950e4a2012-11-08 14:11:47 -0300218 em28xx_dvb_urb_data_copy);
Aidan Thornton3421b772008-04-17 21:40:36 -0300219}
220
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300221static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300222{
Hans Verkuil3de09fb2013-04-08 16:25:04 -0300223 struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
224 struct em28xx *dev = i2c_bus->dev;
Aidan Thornton3421b772008-04-17 21:40:36 -0300225
Gianluca Gennari5f5f1472012-03-22 08:48:17 -0300226 em28xx_stop_urbs(dev);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300227
Aidan Thornton3421b772008-04-17 21:40:36 -0300228 return 0;
229}
230
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300231static int em28xx_start_feed(struct dvb_demux_feed *feed)
Aidan Thornton3421b772008-04-17 21:40:36 -0300232{
233 struct dvb_demux *demux = feed->demux;
234 struct em28xx_dvb *dvb = demux->priv;
235 int rc, ret;
236
237 if (!demux->dmx.frontend)
238 return -EINVAL;
239
240 mutex_lock(&dvb->lock);
241 dvb->nfeeds++;
242 rc = dvb->nfeeds;
243
244 if (dvb->nfeeds == 1) {
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300245 ret = em28xx_start_streaming(dvb);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300246 if (ret < 0)
247 rc = ret;
Aidan Thornton3421b772008-04-17 21:40:36 -0300248 }
249
250 mutex_unlock(&dvb->lock);
251 return rc;
252}
253
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300254static int em28xx_stop_feed(struct dvb_demux_feed *feed)
Aidan Thornton3421b772008-04-17 21:40:36 -0300255{
256 struct dvb_demux *demux = feed->demux;
257 struct em28xx_dvb *dvb = demux->priv;
258 int err = 0;
259
260 mutex_lock(&dvb->lock);
261 dvb->nfeeds--;
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300262
263 if (0 == dvb->nfeeds)
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300264 err = em28xx_stop_streaming(dvb);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300265
Aidan Thornton3421b772008-04-17 21:40:36 -0300266 mutex_unlock(&dvb->lock);
267 return err;
268}
269
270
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300271
272/* ------------------------------------------------------------------ */
273static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
274{
Mauro Carvalho Chehaba3b60202013-04-28 10:33:57 -0300275 struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
276 struct em28xx *dev = i2c_bus->dev;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300277
278 if (acquire)
279 return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
280 else
Mauro Carvalho Chehab2fe3e2e2008-11-27 09:10:40 -0300281 return em28xx_set_mode(dev, EM28XX_SUSPEND);
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300282}
283
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300284/* ------------------------------------------------------------------ */
285
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -0300286static struct lgdt330x_config em2880_lgdt3303_dev = {
287 .demod_address = 0x0e,
288 .demod_chip = LGDT3303,
289};
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300290
Jarod Wilson7e48b302010-03-07 17:55:43 -0300291static struct lgdt3305_config em2870_lgdt3304_dev = {
292 .i2c_addr = 0x0e,
293 .demod_chip = LGDT3304,
294 .spectral_inversion = 1,
295 .deny_i2c_rptr = 1,
296 .mpeg_mode = LGDT3305_MPEG_PARALLEL,
297 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
298 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
299 .vsb_if_khz = 3250,
300 .qam_if_khz = 4000,
301};
302
Jean-Francois Thibert6dbea9f2013-10-09 11:18:05 -0300303static struct lgdt3305_config em2874_lgdt3305_dev = {
304 .i2c_addr = 0x0e,
305 .demod_chip = LGDT3305,
306 .spectral_inversion = 1,
307 .deny_i2c_rptr = 0,
308 .mpeg_mode = LGDT3305_MPEG_SERIAL,
309 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
310 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
311 .vsb_if_khz = 3250,
312 .qam_if_khz = 4000,
313};
314
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300315static struct s921_config sharp_isdbt = {
316 .demod_address = 0x30 >> 1
317};
318
Aidan Thornton7e6388a2008-04-17 21:40:03 -0300319static struct zl10353_config em28xx_zl10353_with_xc3028 = {
320 .demod_address = (0x1e >> 1),
321 .no_tuner = 1,
322 .parallel_ts = 1,
323 .if2 = 45600,
324};
325
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300326static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
327 .demod_address = 0x32 >> 1,
328 .output_mode = S5H1409_PARALLEL_OUTPUT,
329 .gpio = S5H1409_GPIO_OFF,
330 .inversion = S5H1409_INVERSION_OFF,
331 .status_mode = S5H1409_DEMODLOCKING,
332 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
333};
334
Jarod Wilson7e48b302010-03-07 17:55:43 -0300335static struct tda18271_std_map kworld_a340_std_map = {
336 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
337 .if_lvl = 1, .rfagc_top = 0x37, },
338 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
339 .if_lvl = 1, .rfagc_top = 0x37, },
340};
341
342static struct tda18271_config kworld_a340_config = {
343 .std_map = &kworld_a340_std_map,
344};
345
Jean-Francois Thibert6dbea9f2013-10-09 11:18:05 -0300346static struct tda18271_config kworld_ub435q_v2_config = {
347 .std_map = &kworld_a340_std_map,
348 .gate = TDA18271_GATE_DIGITAL,
349};
350
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300351static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300352 .demod_address = (0x1e >> 1),
353 .no_tuner = 1,
354 .disable_i2c_gate_ctrl = 1,
355 .parallel_ts = 1,
356 .if2 = 45600,
357};
358
Devin Heitmueller75e2b862011-03-13 02:01:02 -0300359static struct drxd_config em28xx_drxd = {
Mauro Carvalho Chehabaac865f2011-12-26 09:41:14 -0300360 .demod_address = 0x70,
361 .demod_revision = 0xa2,
362 .pll_type = DRXD_PLL_NONE,
363 .clock = 12000,
364 .insert_rs_byte = 1,
365 .IF = 42800000,
Devin Heitmueller6b142b32011-03-13 02:02:01 -0300366 .disable_i2c_gate_ctrl = 1,
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300367};
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300368
Ezequiel García61bdbef2012-06-12 09:53:41 -0300369static struct drxk_config terratec_h5_drxk = {
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300370 .adr = 0x29,
Mauro Carvalho Chehabe4f4f872011-07-09 17:35:26 -0300371 .single_master = 1,
Mauro Carvalho Chehabf1fe1b72011-07-09 21:59:33 -0300372 .no_i2c_bridge = 1,
Mauro Carvalho Chehab8b9456a2011-07-11 14:33:51 -0300373 .microcode_name = "dvb-usb-terratec-h5-drxk.fw",
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300374 .qam_demod_parameter_count = 2,
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300375 .load_firmware_sync = true,
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300376};
377
Ezequiel García61bdbef2012-06-12 09:53:41 -0300378static struct drxk_config hauppauge_930c_drxk = {
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300379 .adr = 0x29,
380 .single_master = 1,
381 .no_i2c_bridge = 1,
382 .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
383 .chunk_size = 56,
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300384 .qam_demod_parameter_count = 2,
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300385 .load_firmware_sync = true,
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300386};
387
Martin Blumenstingl89040132012-10-04 14:22:54 -0300388static struct drxk_config terratec_htc_stick_drxk = {
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300389 .adr = 0x29,
390 .single_master = 1,
391 .no_i2c_bridge = 1,
392 .microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw",
393 .chunk_size = 54,
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300394 .qam_demod_parameter_count = 2,
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300395 /* Required for the antenna_gpio to disable LNA. */
396 .antenna_dvbt = true,
397 /* The windows driver uses the same. This will disable LNA. */
398 .antenna_gpio = 0x6,
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300399 .load_firmware_sync = true,
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300400};
401
Ezequiel García61bdbef2012-06-12 09:53:41 -0300402static struct drxk_config maxmedia_ub425_tc_drxk = {
Antti Palosaari35530852012-03-18 18:09:01 -0300403 .adr = 0x29,
404 .single_master = 1,
405 .no_i2c_bridge = 1,
Antti Palosaari8d100b22013-10-04 14:40:06 -0300406 .microcode_name = "dvb-demod-drxk-01.fw",
407 .chunk_size = 62,
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300408 .load_firmware_sync = true,
Antti Palosaaride0fc462013-10-04 15:25:55 -0300409 .qam_demod_parameter_count = 2,
Antti Palosaari35530852012-03-18 18:09:01 -0300410};
411
Ezequiel García61bdbef2012-06-12 09:53:41 -0300412static struct drxk_config pctv_520e_drxk = {
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300413 .adr = 0x29,
414 .single_master = 1,
415 .microcode_name = "dvb-demod-drxk-pctv.fw",
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300416 .qam_demod_parameter_count = 2,
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300417 .chunk_size = 58,
Antti Palosaarif6f379d2012-05-17 19:09:06 -0300418 .antenna_dvbt = true, /* disable LNA */
419 .antenna_gpio = (1 << 2), /* disable LNA */
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300420 .load_firmware_sync = true,
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300421};
422
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300423static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
424{
425 struct em28xx_dvb *dvb = fe->sec_priv;
426 int status;
427
428 if (!dvb)
429 return -EINVAL;
430
431 if (enable) {
432 down(&dvb->pll_mutex);
433 status = dvb->gate_ctrl(fe, 1);
434 } else {
435 status = dvb->gate_ctrl(fe, 0);
436 up(&dvb->pll_mutex);
437 }
438 return status;
439}
440
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300441static void hauppauge_hvr930c_init(struct em28xx *dev)
442{
443 int i;
444
445 struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
Frank Schaefer907d1092013-06-03 14:12:02 -0300446 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0x65},
447 {EM2874_R80_GPIO_P0_CTRL, 0xfb, 0xff, 0x32},
448 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0xb8},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300449 { -1, -1, -1, -1},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300450 };
451 struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
Frank Schaefer907d1092013-06-03 14:12:02 -0300452 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
453 {EM2874_R80_GPIO_P0_CTRL, 0xaf, 0xff, 0x65},
454 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x76},
455 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
456 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
457 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x40},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300458
Frank Schaefer907d1092013-06-03 14:12:02 -0300459 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x65},
460 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
461 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
462 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300463
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300464 { -1, -1, -1, -1},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300465 };
466
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300467 struct {
468 unsigned char r[4];
469 int len;
470 } regs[] = {
471 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
472 {{ 0x01, 0x02 }, 2},
473 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
474 {{ 0x01, 0x00 }, 2},
475 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
476 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
477 {{ 0x01, 0x00 }, 2},
478 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
479 {{ 0x04, 0x00 }, 2},
480 {{ 0x00, 0x04 }, 2},
481 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
482 {{ 0x04, 0x14 }, 2},
483 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
484 };
485
486 em28xx_gpio_set(dev, hauppauge_hvr930c_init);
487 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
488 msleep(10);
489 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
490 msleep(10);
491
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300492 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300493
494 for (i = 0; i < ARRAY_SIZE(regs); i++)
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300495 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300496 em28xx_gpio_set(dev, hauppauge_hvr930c_end);
497
498 msleep(100);
499
500 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
501 msleep(30);
502
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300503 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
504 msleep(10);
505
506}
507
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300508static void terratec_h5_init(struct em28xx *dev)
509{
510 int i;
511 struct em28xx_reg_seq terratec_h5_init[] = {
Frank Schaeferc074fc42013-06-03 14:12:03 -0300512 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
Frank Schaefer907d1092013-06-03 14:12:02 -0300513 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
514 {EM2874_R80_GPIO_P0_CTRL, 0xf2, 0xff, 50},
515 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300516 { -1, -1, -1, -1},
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300517 };
518 struct em28xx_reg_seq terratec_h5_end[] = {
Frank Schaefer907d1092013-06-03 14:12:02 -0300519 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
520 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
521 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300522 { -1, -1, -1, -1},
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300523 };
524 struct {
525 unsigned char r[4];
526 int len;
527 } regs[] = {
528 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
529 {{ 0x01, 0x02 }, 2},
530 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
531 {{ 0x01, 0x00 }, 2},
532 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
533 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
534 {{ 0x01, 0x00 }, 2},
535 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
536 {{ 0x04, 0x00 }, 2},
537 {{ 0x00, 0x04 }, 2},
538 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
539 {{ 0x04, 0x14 }, 2},
540 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
541 };
542
543 em28xx_gpio_set(dev, terratec_h5_init);
544 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
545 msleep(10);
546 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
547 msleep(10);
548
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300549 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300550
551 for (i = 0; i < ARRAY_SIZE(regs); i++)
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300552 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300553 em28xx_gpio_set(dev, terratec_h5_end);
554};
555
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300556static void terratec_htc_stick_init(struct em28xx *dev)
557{
558 int i;
559
560 /*
561 * GPIO configuration:
562 * 0xff: unknown (does not affect DVB-T).
563 * 0xf6: DRX-K (demodulator).
564 * 0xe6: unknown (does not affect DVB-T).
565 * 0xb6: unknown (does not affect DVB-T).
566 */
567 struct em28xx_reg_seq terratec_htc_stick_init[] = {
Frank Schaeferc074fc42013-06-03 14:12:03 -0300568 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
Frank Schaefer907d1092013-06-03 14:12:02 -0300569 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
570 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 50},
571 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300572 { -1, -1, -1, -1},
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300573 };
574 struct em28xx_reg_seq terratec_htc_stick_end[] = {
Frank Schaefer907d1092013-06-03 14:12:02 -0300575 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
576 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 50},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300577 { -1, -1, -1, -1},
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300578 };
579
Martin Blumenstingl89040132012-10-04 14:22:54 -0300580 /*
581 * Init the analog decoder (not yet supported), but
582 * it's probably still a good idea.
583 */
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300584 struct {
585 unsigned char r[4];
586 int len;
587 } regs[] = {
588 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
589 {{ 0x01, 0x02 }, 2},
590 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
591 {{ 0x01, 0x00 }, 2},
592 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
593 };
594
595 em28xx_gpio_set(dev, terratec_htc_stick_init);
596
597 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
598 msleep(10);
599 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
600 msleep(10);
601
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300602 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300603
604 for (i = 0; i < ARRAY_SIZE(regs); i++)
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300605 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300606
607 em28xx_gpio_set(dev, terratec_htc_stick_end);
608};
609
Martin Blumenstingl89040132012-10-04 14:22:54 -0300610static void terratec_htc_usb_xs_init(struct em28xx *dev)
611{
612 int i;
613
614 struct em28xx_reg_seq terratec_htc_usb_xs_init[] = {
Frank Schaeferc074fc42013-06-03 14:12:03 -0300615 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
Frank Schaefer907d1092013-06-03 14:12:02 -0300616 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 100},
617 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 50},
618 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300619 { -1, -1, -1, -1},
Martin Blumenstingl89040132012-10-04 14:22:54 -0300620 };
621 struct em28xx_reg_seq terratec_htc_usb_xs_end[] = {
Frank Schaefer907d1092013-06-03 14:12:02 -0300622 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 100},
623 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
624 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300625 { -1, -1, -1, -1},
Martin Blumenstingl89040132012-10-04 14:22:54 -0300626 };
627
628 /*
629 * Init the analog decoder (not yet supported), but
630 * it's probably still a good idea.
631 */
632 struct {
633 unsigned char r[4];
634 int len;
635 } regs[] = {
636 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
637 {{ 0x01, 0x02 }, 2},
638 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
639 {{ 0x01, 0x00 }, 2},
640 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
641 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
642 {{ 0x01, 0x00 }, 2},
643 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
644 {{ 0x04, 0x00 }, 2},
645 {{ 0x00, 0x04 }, 2},
646 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
647 {{ 0x04, 0x14 }, 2},
648 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
649 };
650
651 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
652
653 em28xx_gpio_set(dev, terratec_htc_usb_xs_init);
654
655 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
656 msleep(10);
657 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
658 msleep(10);
659
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300660 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
Martin Blumenstingl89040132012-10-04 14:22:54 -0300661
662 for (i = 0; i < ARRAY_SIZE(regs); i++)
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300663 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
Martin Blumenstingl89040132012-10-04 14:22:54 -0300664
665 em28xx_gpio_set(dev, terratec_htc_usb_xs_end);
666};
667
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300668static void pctv_520e_init(struct em28xx *dev)
669{
670 /*
Antti Palosaari26c8a722012-05-17 18:22:02 -0300671 * Init AVF4910B analog decoder. Looks like I2C traffic to
672 * digital demodulator and tuner are routed via AVF4910B.
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300673 */
674 int i;
675 struct {
676 unsigned char r[4];
677 int len;
678 } regs[] = {
679 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
680 {{ 0x01, 0x02 }, 2},
681 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
682 {{ 0x01, 0x00 }, 2},
683 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
684 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
685 {{ 0x01, 0x00 }, 2},
686 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
687 };
688
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300689 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; /* 0x41 */
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300690
691 for (i = 0; i < ARRAY_SIZE(regs); i++)
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300692 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300693};
694
Antti Palosaari33eebec2012-10-03 04:28:56 -0300695static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
Antti Palosaari13a53362012-07-19 22:28:56 -0300696{
Antti Palosaari33eebec2012-10-03 04:28:56 -0300697 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
Antti Palosaari13a53362012-07-19 22:28:56 -0300698 struct em28xx *dev = fe->dvb->priv;
699#ifdef CONFIG_GPIOLIB
700 struct em28xx_dvb *dvb = dev->dvb;
701 int ret;
702 unsigned long flags;
703
Antti Palosaari33eebec2012-10-03 04:28:56 -0300704 if (c->lna == 1)
705 flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
Antti Palosaari13a53362012-07-19 22:28:56 -0300706 else
Antti Palosaari33eebec2012-10-03 04:28:56 -0300707 flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
Antti Palosaari13a53362012-07-19 22:28:56 -0300708
709 ret = gpio_request_one(dvb->lna_gpio, flags, NULL);
710 if (ret)
711 em28xx_errdev("gpio request failed %d\n", ret);
712 else
713 gpio_free(dvb->lna_gpio);
714
715 return ret;
716#else
Antti Palosaari33eebec2012-10-03 04:28:56 -0300717 dev_warn(&dev->udev->dev, "%s: LNA control is disabled (lna=%u)\n",
718 KBUILD_MODNAME, c->lna);
Antti Palosaari13a53362012-07-19 22:28:56 -0300719 return 0;
720#endif
721}
722
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300723static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300724{
725 /* Values extracted from a USB trace of the Terratec Windows driver */
726 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
727 static u8 reset[] = { RESET, 0x80 };
728 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
729 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
730 static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
731 static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
732 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
733 static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
734 static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
Devin Heitmuellerff697862009-07-12 18:44:19 -0300735 static u8 tuner_go[] = { TUNER_GO, 0x01};
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300736
737 mt352_write(fe, clock_config, sizeof(clock_config));
738 udelay(200);
739 mt352_write(fe, reset, sizeof(reset));
740 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
741 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
742 mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
743 mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
744 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
745 mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
746 mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
747 mt352_write(fe, tuner_go, sizeof(tuner_go));
748 return 0;
749}
750
751static struct mt352_config terratec_xs_mt352_cfg = {
752 .demod_address = (0x1e >> 1),
753 .no_tuner = 1,
754 .if2 = 45600,
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300755 .demod_init = em28xx_mt352_terratec_xs_init,
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300756};
757
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300758static struct tda10023_config em28xx_tda10023_config = {
759 .demod_address = 0x0c,
760 .invert = 1,
761};
762
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300763static struct cxd2820r_config em28xx_cxd2820r_config = {
764 .i2c_address = (0xd8 >> 1),
765 .ts_mode = CXD2820R_TS_SERIAL,
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300766};
767
768static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
769 .output_opt = TDA18271_OUTPUT_LT_OFF,
Steve Kerrison0db4bf42011-08-09 07:16:21 -0300770 .gate = TDA18271_GATE_DIGITAL,
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300771};
772
Antti Palosaari36588712011-08-01 01:15:30 -0300773static const struct tda10071_config em28xx_tda10071_config = {
Michael Krufky41f55d52012-12-16 19:37:11 -0300774 .demod_i2c_addr = 0x55, /* (0xaa >> 1) */
775 .tuner_i2c_addr = 0x14,
Antti Palosaari36588712011-08-01 01:15:30 -0300776 .i2c_wr_max = 64,
777 .ts_mode = TDA10071_TS_SERIAL,
778 .spec_inv = 0,
779 .xtal = 40444000, /* 40.444 MHz */
780 .pll_multiplier = 20,
781};
782
783static const struct a8293_config em28xx_a8293_config = {
784 .i2c_addr = 0x08, /* (0x10 >> 1) */
785};
786
Aivar Päkk1985f6f2011-12-11 18:15:00 -0300787static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
788 .demod_address = (0x1e >> 1),
789 .disable_i2c_gate_ctrl = 1,
790 .no_tuner = 1,
791 .parallel_ts = 1,
792};
793static struct qt1010_config em28xx_qt1010_config = {
794 .i2c_address = 0x62
Aivar Päkk1985f6f2011-12-11 18:15:00 -0300795};
796
Mauro Carvalho Chehab4159d012013-02-28 10:35:56 -0300797static const struct mb86a20s_config c3tech_duo_mb86a20s_config = {
798 .demod_address = 0x10,
799 .is_serial = true,
800};
801
802static struct tda18271_std_map mb86a20s_tda18271_config = {
803 .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4,
804 .if_lvl = 1, .rfagc_top = 0x37, },
805};
806
807static struct tda18271_config c3tech_duo_tda18271_config = {
808 .std_map = &mb86a20s_tda18271_config,
809 .gate = TDA18271_GATE_DIGITAL,
810 .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
811};
812
Antti Palosaariec573362013-02-25 09:01:13 -0300813static const struct m88ds3103_config pctv_461e_m88ds3103_config = {
814 .i2c_addr = 0x68,
815 .clock = 27000000,
816 .i2c_wr_max = 33,
817 .clock_out = 0,
818 .ts_mode = M88DS3103_TS_PARALLEL_16,
819 .agc = 0x99,
820};
821
822static const struct m88ts2022_config em28xx_m88ts2022_config = {
823 .i2c_addr = 0x60,
824 .clock = 27000000,
825};
Mauro Carvalho Chehab4159d012013-02-28 10:35:56 -0300826
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300827/* ------------------------------------------------------------------ */
828
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300829static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300830{
831 struct dvb_frontend *fe;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300832 struct xc2028_config cfg;
833
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300834 memset(&cfg, 0, sizeof(cfg));
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300835 cfg.i2c_adap = &dev->i2c_adap[dev->def_i2c_bus];
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300836 cfg.i2c_addr = addr;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300837
Antti Palosaarif71095b2011-04-07 15:51:52 -0300838 if (!dev->dvb->fe[0]) {
Filipe Rosset480be182009-11-04 15:32:37 -0300839 em28xx_errdev("/2: dvb frontend not attached. "
840 "Can't attach xc3028\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300841 return -EINVAL;
842 }
843
Antti Palosaarif71095b2011-04-07 15:51:52 -0300844 fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300845 if (!fe) {
Filipe Rosset480be182009-11-04 15:32:37 -0300846 em28xx_errdev("/2: xc3028 attach failed\n");
Antti Palosaarif71095b2011-04-07 15:51:52 -0300847 dvb_frontend_detach(dev->dvb->fe[0]);
848 dev->dvb->fe[0] = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300849 return -EINVAL;
850 }
851
Filipe Rosset480be182009-11-04 15:32:37 -0300852 em28xx_info("%s/2: xc3028 attached\n", dev->name);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300853
854 return 0;
855}
856
Aidan Thornton3421b772008-04-17 21:40:36 -0300857/* ------------------------------------------------------------------ */
858
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300859static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
860 struct em28xx *dev, struct device *device)
Aidan Thornton3421b772008-04-17 21:40:36 -0300861{
862 int result;
863
864 mutex_init(&dvb->lock);
865
866 /* register adapter */
867 result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
868 adapter_nr);
869 if (result < 0) {
870 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
871 dev->name, result);
872 goto fail_adapter;
873 }
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300874
875 /* Ensure all frontends negotiate bus access */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300876 dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
877 if (dvb->fe[1])
878 dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300879
Hans Verkuil3de09fb2013-04-08 16:25:04 -0300880 dvb->adapter.priv = &dev->i2c_bus[dev->def_i2c_bus];
Aidan Thornton3421b772008-04-17 21:40:36 -0300881
882 /* register frontend */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300883 result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300884 if (result < 0) {
885 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
886 dev->name, result);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300887 goto fail_frontend0;
888 }
889
890 /* register 2nd frontend */
891 if (dvb->fe[1]) {
892 result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
893 if (result < 0) {
894 printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
895 dev->name, result);
896 goto fail_frontend1;
897 }
Aidan Thornton3421b772008-04-17 21:40:36 -0300898 }
899
900 /* register demux stuff */
901 dvb->demux.dmx.capabilities =
902 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
903 DMX_MEMORY_BASED_FILTERING;
904 dvb->demux.priv = dvb;
905 dvb->demux.filternum = 256;
906 dvb->demux.feednum = 256;
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300907 dvb->demux.start_feed = em28xx_start_feed;
908 dvb->demux.stop_feed = em28xx_stop_feed;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300909
Aidan Thornton3421b772008-04-17 21:40:36 -0300910 result = dvb_dmx_init(&dvb->demux);
911 if (result < 0) {
912 printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
913 dev->name, result);
914 goto fail_dmx;
915 }
916
917 dvb->dmxdev.filternum = 256;
918 dvb->dmxdev.demux = &dvb->demux.dmx;
919 dvb->dmxdev.capabilities = 0;
920 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
921 if (result < 0) {
922 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
923 dev->name, result);
924 goto fail_dmxdev;
925 }
926
927 dvb->fe_hw.source = DMX_FRONTEND_0;
928 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
929 if (result < 0) {
930 printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
931 dev->name, result);
932 goto fail_fe_hw;
933 }
934
935 dvb->fe_mem.source = DMX_MEMORY_FE;
936 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
937 if (result < 0) {
938 printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
939 dev->name, result);
940 goto fail_fe_mem;
941 }
942
943 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
944 if (result < 0) {
945 printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
946 dev->name, result);
947 goto fail_fe_conn;
948 }
949
950 /* register network adapter */
951 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
952 return 0;
953
954fail_fe_conn:
955 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
956fail_fe_mem:
957 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
958fail_fe_hw:
959 dvb_dmxdev_release(&dvb->dmxdev);
960fail_dmxdev:
961 dvb_dmx_release(&dvb->demux);
962fail_dmx:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300963 if (dvb->fe[1])
964 dvb_unregister_frontend(dvb->fe[1]);
965 dvb_unregister_frontend(dvb->fe[0]);
966fail_frontend1:
967 if (dvb->fe[1])
968 dvb_frontend_detach(dvb->fe[1]);
969fail_frontend0:
970 dvb_frontend_detach(dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300971 dvb_unregister_adapter(&dvb->adapter);
972fail_adapter:
973 return result;
974}
975
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300976static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
Aidan Thornton3421b772008-04-17 21:40:36 -0300977{
978 dvb_net_release(&dvb->net);
979 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
980 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
981 dvb_dmxdev_release(&dvb->dmxdev);
982 dvb_dmx_release(&dvb->demux);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300983 if (dvb->fe[1])
984 dvb_unregister_frontend(dvb->fe[1]);
985 dvb_unregister_frontend(dvb->fe[0]);
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -0300986 if (dvb->fe[1] && !dvb->dont_attach_fe1)
Antti Palosaarif71095b2011-04-07 15:51:52 -0300987 dvb_frontend_detach(dvb->fe[1]);
988 dvb_frontend_detach(dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300989 dvb_unregister_adapter(&dvb->adapter);
990}
991
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300992static int em28xx_dvb_init(struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300993{
Antti Palosaari13a53362012-07-19 22:28:56 -0300994 int result = 0, mfe_shared = 0;
Aidan Thornton3421b772008-04-17 21:40:36 -0300995 struct em28xx_dvb *dvb;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300996
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -0300997 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -0300998 /* This device does not support the extension */
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300999 printk(KERN_INFO "em28xx_dvb: This device does not support the extension\n");
Devin Heitmuellerdf619182008-06-10 12:34:35 -03001000 return 0;
1001 }
1002
Aidan Thornton3421b772008-04-17 21:40:36 -03001003 dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -03001004
1005 if (dvb == NULL) {
Filipe Rosset480be182009-11-04 15:32:37 -03001006 em28xx_info("em28xx_dvb: memory allocation failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -03001007 return -ENOMEM;
1008 }
1009 dev->dvb = dvb;
Antti Palosaarif71095b2011-04-07 15:51:52 -03001010 dvb->fe[0] = dvb->fe[1] = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001011
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -03001012 mutex_lock(&dev->lock);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -03001013 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001014 /* init frontend */
1015 switch (dev->model) {
Mauro Carvalho Chehabebaefdb2011-06-01 10:16:25 -03001016 case EM2874_BOARD_LEADERSHIP_ISDBT:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001017 dvb->fe[0] = dvb_attach(s921_attach,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001018 &sharp_isdbt, &dev->i2c_adap[dev->def_i2c_bus]);
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -03001019
Antti Palosaarif71095b2011-04-07 15:51:52 -03001020 if (!dvb->fe[0]) {
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -03001021 result = -EINVAL;
1022 goto out_free;
1023 }
1024
1025 break;
Douglas Schilling Landgraff89bc322008-12-01 21:01:04 -03001026 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
Mauro Carvalho Chehab10ac6602008-07-27 14:58:58 -03001027 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
Devin Heitmueller4fd305b2008-06-04 13:43:46 -03001028 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
Devin Heitmuellere14b3652008-07-26 11:04:33 -03001029 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001030 dvb->fe[0] = dvb_attach(lgdt330x_attach,
Aidan Thornton3421b772008-04-17 21:40:36 -03001031 &em2880_lgdt3303_dev,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001032 &dev->i2c_adap[dev->def_i2c_bus]);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001033 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Aidan Thornton3421b772008-04-17 21:40:36 -03001034 result = -EINVAL;
1035 goto out_free;
1036 }
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -03001037 break;
Thierry MERLE46510b52008-10-11 16:56:13 -03001038 case EM2880_BOARD_KWORLD_DVB_310U:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001039 dvb->fe[0] = dvb_attach(zl10353_attach,
Aidan Thornton3421b772008-04-17 21:40:36 -03001040 &em28xx_zl10353_with_xc3028,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001041 &dev->i2c_adap[dev->def_i2c_bus]);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001042 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Aidan Thornton3421b772008-04-17 21:40:36 -03001043 result = -EINVAL;
1044 goto out_free;
1045 }
Aidan Thornton7e6388a2008-04-17 21:40:03 -03001046 break;
Devin Heitmuellera84f79a2009-07-12 17:05:02 -03001047 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
Uroš Vamplec994d02009-09-30 22:53:37 -03001048 case EM2882_BOARD_TERRATEC_HYBRID_XS:
Devin Heitmueller01a5fd62009-08-07 09:25:06 -03001049 case EM2880_BOARD_EMPIRE_DUAL_TV:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001050 dvb->fe[0] = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -03001051 &em28xx_zl10353_xc3028_no_i2c_gate,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001052 &dev->i2c_adap[dev->def_i2c_bus]);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001053 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmuellera84f79a2009-07-12 17:05:02 -03001054 result = -EINVAL;
1055 goto out_free;
1056 }
1057 break;
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001058 case EM2880_BOARD_TERRATEC_HYBRID_XS:
Catimimi65638012010-02-18 18:06:32 -03001059 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
Devin Heitmuellerd5b3ba92009-07-08 21:51:35 -03001060 case EM2881_BOARD_PINNACLE_HYBRID_PRO:
Andrea.Amorosi76@gmail.com7ca7ef62010-02-09 17:53:38 -03001061 case EM2882_BOARD_DIKOM_DK300:
Antonio Larrosa811fab62010-03-04 22:19:48 -03001062 case EM2882_BOARD_KWORLD_VS_DVBT:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001063 dvb->fe[0] = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -03001064 &em28xx_zl10353_xc3028_no_i2c_gate,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001065 &dev->i2c_adap[dev->def_i2c_bus]);
Antti Palosaarif71095b2011-04-07 15:51:52 -03001066 if (dvb->fe[0] == NULL) {
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001067 /* This board could have either a zl10353 or a mt352.
1068 If the chip id isn't for zl10353, try mt352 */
Antti Palosaarif71095b2011-04-07 15:51:52 -03001069 dvb->fe[0] = dvb_attach(mt352_attach,
Devin Heitmueller4fb202a2009-07-12 17:51:12 -03001070 &terratec_xs_mt352_cfg,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001071 &dev->i2c_adap[dev->def_i2c_bus]);
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001072 }
Devin Heitmueller4fb202a2009-07-12 17:51:12 -03001073
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001074 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001075 result = -EINVAL;
1076 goto out_free;
1077 }
1078 break;
Aivar Päkk1985f6f2011-12-11 18:15:00 -03001079 case EM2870_BOARD_KWORLD_355U:
1080 dvb->fe[0] = dvb_attach(zl10353_attach,
1081 &em28xx_zl10353_no_i2c_gate_dev,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001082 &dev->i2c_adap[dev->def_i2c_bus]);
Aivar Päkk1985f6f2011-12-11 18:15:00 -03001083 if (dvb->fe[0] != NULL)
1084 dvb_attach(qt1010_attach, dvb->fe[0],
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001085 &dev->i2c_adap[dev->def_i2c_bus], &em28xx_qt1010_config);
Aivar Päkk1985f6f2011-12-11 18:15:00 -03001086 break;
Robert Krakora6e7b9ea2009-01-18 21:59:34 -03001087 case EM2883_BOARD_KWORLD_HYBRID_330U:
Devin Heitmueller19859222009-06-19 00:33:54 -03001088 case EM2882_BOARD_EVGA_INDTUBE:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001089 dvb->fe[0] = dvb_attach(s5h1409_attach,
Robert Krakora6e7b9ea2009-01-18 21:59:34 -03001090 &em28xx_s5h1409_with_xc3028,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001091 &dev->i2c_adap[dev->def_i2c_bus]);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001092 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Robert Krakora6e7b9ea2009-01-18 21:59:34 -03001093 result = -EINVAL;
1094 goto out_free;
1095 }
1096 break;
Franklin Mengd7de5d82009-06-06 17:05:02 -03001097 case EM2882_BOARD_KWORLD_ATSC_315U:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001098 dvb->fe[0] = dvb_attach(lgdt330x_attach,
Franklin Mengd7de5d82009-06-06 17:05:02 -03001099 &em2880_lgdt3303_dev,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001100 &dev->i2c_adap[dev->def_i2c_bus]);
Antti Palosaarif71095b2011-04-07 15:51:52 -03001101 if (dvb->fe[0] != NULL) {
1102 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001103 &dev->i2c_adap[dev->def_i2c_bus], 0x61, TUNER_THOMSON_DTT761X)) {
Franklin Mengd7de5d82009-06-06 17:05:02 -03001104 result = -EINVAL;
1105 goto out_free;
1106 }
1107 }
1108 break;
Devin Heitmueller17d9d552008-06-08 10:22:03 -03001109 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
Devin Heitmuellerad9b4bb2011-03-13 02:09:59 -03001110 case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001111 dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001112 &dev->i2c_adap[dev->def_i2c_bus], &dev->udev->dev);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001113 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmueller17d9d552008-06-08 10:22:03 -03001114 result = -EINVAL;
1115 goto out_free;
1116 }
1117 break;
Antti Palosaari285eb1a2009-09-15 14:42:13 -03001118 case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
1119 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
Antti Palosaarif71095b2011-04-07 15:51:52 -03001120 dvb->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari285eb1a2009-09-15 14:42:13 -03001121 &em28xx_tda10023_config,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001122 &dev->i2c_adap[dev->def_i2c_bus], 0x48);
Antti Palosaarif71095b2011-04-07 15:51:52 -03001123 if (dvb->fe[0]) {
1124 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001125 &dev->i2c_adap[dev->def_i2c_bus], 0x60, TUNER_PHILIPS_CU1216L)) {
Antti Palosaari285eb1a2009-09-15 14:42:13 -03001126 result = -EINVAL;
1127 goto out_free;
1128 }
1129 }
1130 break;
Jarod Wilson7e48b302010-03-07 17:55:43 -03001131 case EM2870_BOARD_KWORLD_A340:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001132 dvb->fe[0] = dvb_attach(lgdt3305_attach,
Jarod Wilson7e48b302010-03-07 17:55:43 -03001133 &em2870_lgdt3304_dev,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001134 &dev->i2c_adap[dev->def_i2c_bus]);
Antti Palosaarif71095b2011-04-07 15:51:52 -03001135 if (dvb->fe[0] != NULL)
1136 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001137 &dev->i2c_adap[dev->def_i2c_bus], &kworld_a340_config);
Jarod Wilson7e48b302010-03-07 17:55:43 -03001138 break;
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001139 case EM28174_BOARD_PCTV_290E:
Antti Palosaaria36a66d2012-08-16 21:07:23 -03001140 /* set default GPIO0 for LNA, used if GPIOLIB is undefined */
1141 dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O |
1142 CXD2820R_GPIO_L;
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001143 dvb->fe[0] = dvb_attach(cxd2820r_attach,
Manu Abraham7e7b8282011-12-10 00:44:24 -03001144 &em28xx_cxd2820r_config,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001145 &dev->i2c_adap[dev->def_i2c_bus],
Antti Palosaari13a53362012-07-19 22:28:56 -03001146 &dvb->lna_gpio);
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001147 if (dvb->fe[0]) {
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001148 /* FE 0 attach tuner */
Manu Abraham7e7b8282011-12-10 00:44:24 -03001149 if (!dvb_attach(tda18271_attach,
1150 dvb->fe[0],
1151 0x60,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001152 &dev->i2c_adap[dev->def_i2c_bus],
Manu Abraham7e7b8282011-12-10 00:44:24 -03001153 &em28xx_cxd2820r_tda18271_config)) {
1154
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001155 dvb_frontend_detach(dvb->fe[0]);
1156 result = -EINVAL;
1157 goto out_free;
1158 }
Antti Palosaari1e8f31f2012-07-19 21:10:36 -03001159
Antti Palosaari13a53362012-07-19 22:28:56 -03001160#ifdef CONFIG_GPIOLIB
Antti Palosaari0c42a552012-09-19 20:52:21 -03001161 /* enable LNA for DVB-T, DVB-T2 and DVB-C */
1162 result = gpio_request_one(dvb->lna_gpio,
1163 GPIOF_OUT_INIT_LOW, NULL);
1164 if (result)
1165 em28xx_errdev("gpio request failed %d\n",
1166 result);
1167 else
1168 gpio_free(dvb->lna_gpio);
Antti Palosaari1e8f31f2012-07-19 21:10:36 -03001169
Antti Palosaari0c42a552012-09-19 20:52:21 -03001170 result = 0; /* continue even set LNA fails */
Antti Palosaari13a53362012-07-19 22:28:56 -03001171#endif
Antti Palosaari0c42a552012-09-19 20:52:21 -03001172 dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
1173 }
1174
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001175 break;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001176 case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
Mauro Carvalho Chehab85032322011-11-24 15:01:45 -02001177 {
1178 struct xc5000_config cfg;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001179 hauppauge_hvr930c_init(dev);
1180
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001181 dvb->fe[0] = dvb_attach(drxk_attach,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001182 &hauppauge_930c_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001183 if (!dvb->fe[0]) {
1184 result = -EINVAL;
1185 goto out_free;
1186 }
1187 /* FIXME: do we need a pll semaphore? */
1188 dvb->fe[0]->sec_priv = dvb;
1189 sema_init(&dvb->pll_mutex, 1);
1190 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1191 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001192
1193 /* Attach xc5000 */
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001194 memset(&cfg, 0, sizeof(cfg));
1195 cfg.i2c_address = 0x61;
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001196 cfg.if_khz = 4000;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001197
1198 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1199 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001200 if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001201 &cfg)) {
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001202 result = -EINVAL;
1203 goto out_free;
1204 }
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001205 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1206 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1207
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001208 break;
Mauro Carvalho Chehab85032322011-11-24 15:01:45 -02001209 }
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001210 case EM2884_BOARD_TERRATEC_H5:
1211 terratec_h5_init(dev);
1212
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001213 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 -03001214 if (!dvb->fe[0]) {
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001215 result = -EINVAL;
1216 goto out_free;
1217 }
1218 /* FIXME: do we need a pll semaphore? */
1219 dvb->fe[0]->sec_priv = dvb;
1220 sema_init(&dvb->pll_mutex, 1);
1221 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1222 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001223
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -03001224 /* Attach tda18271 to DVB-C frontend */
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001225 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1226 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001227 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus], 0x60)) {
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001228 result = -EINVAL;
1229 goto out_free;
1230 }
1231 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1232 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -03001233
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001234 break;
Mauro Carvalho Chehab4159d012013-02-28 10:35:56 -03001235 case EM2884_BOARD_C3TECH_DIGITAL_DUO:
1236 dvb->fe[0] = dvb_attach(mb86a20s_attach,
1237 &c3tech_duo_mb86a20s_config,
1238 &dev->i2c_adap[dev->def_i2c_bus]);
1239 if (dvb->fe[0] != NULL)
1240 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1241 &dev->i2c_adap[dev->def_i2c_bus],
1242 &c3tech_duo_tda18271_config);
1243 break;
Antti Palosaari36588712011-08-01 01:15:30 -03001244 case EM28174_BOARD_PCTV_460E:
1245 /* attach demod */
1246 dvb->fe[0] = dvb_attach(tda10071_attach,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001247 &em28xx_tda10071_config, &dev->i2c_adap[dev->def_i2c_bus]);
Antti Palosaari36588712011-08-01 01:15:30 -03001248
1249 /* attach SEC */
1250 if (dvb->fe[0])
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001251 dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
Antti Palosaari36588712011-08-01 01:15:30 -03001252 &em28xx_a8293_config);
1253 break;
Jakob Haufe7c1dfdb2013-04-13 11:03:37 -03001254 case EM2874_BOARD_DELOCK_61959:
Antti Palosaari35530852012-03-18 18:09:01 -03001255 case EM2874_BOARD_MAXMEDIA_UB425_TC:
1256 /* attach demodulator */
1257 dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001258 &dev->i2c_adap[dev->def_i2c_bus]);
Antti Palosaari35530852012-03-18 18:09:01 -03001259
1260 if (dvb->fe[0]) {
1261 /* disable I2C-gate */
1262 dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
1263
1264 /* attach tuner */
Antti Palosaarib6c7abb2013-10-04 15:17:51 -03001265 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1266 &dev->i2c_adap[dev->def_i2c_bus],
1267 &em28xx_cxd2820r_tda18271_config)) {
Antti Palosaari35530852012-03-18 18:09:01 -03001268 dvb_frontend_detach(dvb->fe[0]);
1269 result = -EINVAL;
1270 goto out_free;
1271 }
1272 }
Antti Palosaari35530852012-03-18 18:09:01 -03001273 break;
Ivan Kalvachevfa5527c2012-03-19 20:09:55 -03001274 case EM2884_BOARD_PCTV_510E:
1275 case EM2884_BOARD_PCTV_520E:
1276 pctv_520e_init(dev);
1277
1278 /* attach demodulator */
1279 dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001280 &dev->i2c_adap[dev->def_i2c_bus]);
Ivan Kalvachevfa5527c2012-03-19 20:09:55 -03001281
1282 if (dvb->fe[0]) {
1283 /* attach tuner */
1284 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001285 &dev->i2c_adap[dev->def_i2c_bus],
Ivan Kalvachevfa5527c2012-03-19 20:09:55 -03001286 &em28xx_cxd2820r_tda18271_config)) {
1287 dvb_frontend_detach(dvb->fe[0]);
1288 result = -EINVAL;
1289 goto out_free;
1290 }
1291 }
1292 break;
Martin Blumenstinglc8dce002012-06-12 18:19:28 -03001293 case EM2884_BOARD_CINERGY_HTC_STICK:
1294 terratec_htc_stick_init(dev);
1295
1296 /* attach demodulator */
1297 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001298 &dev->i2c_adap[dev->def_i2c_bus]);
Martin Blumenstinglc8dce002012-06-12 18:19:28 -03001299 if (!dvb->fe[0]) {
1300 result = -EINVAL;
1301 goto out_free;
1302 }
1303
1304 /* Attach the demodulator. */
1305 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001306 &dev->i2c_adap[dev->def_i2c_bus],
Martin Blumenstinglc8dce002012-06-12 18:19:28 -03001307 &em28xx_cxd2820r_tda18271_config)) {
1308 result = -EINVAL;
1309 goto out_free;
1310 }
1311 break;
Martin Blumenstingl89040132012-10-04 14:22:54 -03001312 case EM2884_BOARD_TERRATEC_HTC_USB_XS:
1313 terratec_htc_usb_xs_init(dev);
1314
1315 /* attach demodulator */
1316 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001317 &dev->i2c_adap[dev->def_i2c_bus]);
Martin Blumenstingl89040132012-10-04 14:22:54 -03001318 if (!dvb->fe[0]) {
1319 result = -EINVAL;
1320 goto out_free;
1321 }
1322
1323 /* Attach the demodulator. */
1324 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001325 &dev->i2c_adap[dev->def_i2c_bus],
Martin Blumenstingl89040132012-10-04 14:22:54 -03001326 &em28xx_cxd2820r_tda18271_config)) {
1327 result = -EINVAL;
1328 goto out_free;
1329 }
1330 break;
Jean-Francois Thibert6dbea9f2013-10-09 11:18:05 -03001331 case EM2874_BOARD_KWORLD_UB435Q_V2:
1332 dvb->fe[0] = dvb_attach(lgdt3305_attach,
1333 &em2874_lgdt3305_dev,
1334 &dev->i2c_adap[dev->def_i2c_bus]);
1335 if (!dvb->fe[0]) {
1336 result = -EINVAL;
1337 goto out_free;
1338 }
1339
1340 /* Attach the demodulator. */
1341 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1342 &dev->i2c_adap[dev->def_i2c_bus],
1343 &kworld_ub435q_v2_config)) {
1344 result = -EINVAL;
1345 goto out_free;
1346 }
1347 break;
Antti Palosaariec573362013-02-25 09:01:13 -03001348 case EM28178_BOARD_PCTV_461E:
1349 {
1350 /* demod I2C adapter */
1351 struct i2c_adapter *i2c_adapter;
1352
1353 /* attach demod */
1354 dvb->fe[0] = dvb_attach(m88ds3103_attach,
1355 &pctv_461e_m88ds3103_config,
1356 &dev->i2c_adap[dev->def_i2c_bus],
1357 &i2c_adapter);
1358 if (dvb->fe[0] == NULL) {
1359 result = -ENODEV;
1360 goto out_free;
1361 }
1362
1363 /* attach tuner */
1364 if (!dvb_attach(m88ts2022_attach, dvb->fe[0],
1365 i2c_adapter,
1366 &em28xx_m88ts2022_config)) {
1367 dvb_frontend_detach(dvb->fe[0]);
1368 result = -ENODEV;
1369 goto out_free;
1370 }
1371
1372 /* delegate signal strength measurement to tuner */
1373 dvb->fe[0]->ops.read_signal_strength =
1374 dvb->fe[0]->ops.tuner_ops.get_rf_strength;
1375
1376 /* attach SEC */
1377 if (!dvb_attach(a8293_attach, dvb->fe[0],
1378 &dev->i2c_adap[dev->def_i2c_bus],
1379 &em28xx_a8293_config)) {
1380 dvb_frontend_detach(dvb->fe[0]);
1381 result = -ENODEV;
1382 goto out_free;
1383 }
1384 }
1385 break;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001386 default:
Filipe Rosset480be182009-11-04 15:32:37 -03001387 em28xx_errdev("/2: The frontend of your DVB/ATSC card"
1388 " isn't supported yet\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001389 break;
1390 }
Antti Palosaarif71095b2011-04-07 15:51:52 -03001391 if (NULL == dvb->fe[0]) {
Filipe Rosset480be182009-11-04 15:32:37 -03001392 em28xx_errdev("/2: frontend initialization failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -03001393 result = -EINVAL;
1394 goto out_free;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001395 }
Michael Krufkyd7cba042008-09-12 13:31:45 -03001396 /* define general-purpose callback pointer */
Antti Palosaarif71095b2011-04-07 15:51:52 -03001397 dvb->fe[0]->callback = em28xx_tuner_callback;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001398 if (dvb->fe[1])
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001399 dvb->fe[1]->callback = em28xx_tuner_callback;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001400
1401 /* register everything */
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001402 result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
Aidan Thornton3421b772008-04-17 21:40:36 -03001403
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -03001404 if (result < 0)
Aidan Thornton3421b772008-04-17 21:40:36 -03001405 goto out_free;
Aidan Thornton3421b772008-04-17 21:40:36 -03001406
Antti Palosaarie3645432011-07-28 18:59:30 -03001407 /* MFE lock */
1408 dvb->adapter.mfe_shared = mfe_shared;
1409
Filipe Rosset480be182009-11-04 15:32:37 -03001410 em28xx_info("Successfully loaded em28xx-dvb\n");
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -03001411ret:
1412 em28xx_set_mode(dev, EM28XX_SUSPEND);
1413 mutex_unlock(&dev->lock);
1414 return result;
Aidan Thornton3421b772008-04-17 21:40:36 -03001415
1416out_free:
1417 kfree(dvb);
1418 dev->dvb = NULL;
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -03001419 goto ret;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001420}
1421
Chris Rankin0b8bd832011-08-20 16:01:26 -03001422static inline void prevent_sleep(struct dvb_frontend_ops *ops)
1423{
1424 ops->set_voltage = NULL;
1425 ops->sleep = NULL;
1426 ops->tuner_ops.sleep = NULL;
1427}
1428
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001429static int em28xx_dvb_fini(struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001430{
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -03001431 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -03001432 /* This device does not support the extension */
1433 return 0;
1434 }
1435
Aidan Thornton3421b772008-04-17 21:40:36 -03001436 if (dev->dvb) {
Chris Rankin0b8bd832011-08-20 16:01:26 -03001437 struct em28xx_dvb *dvb = dev->dvb;
1438
Frank Schaefer2665c292012-12-27 19:02:43 -03001439 if (dev->disconnected) {
Chris Rankin0b8bd832011-08-20 16:01:26 -03001440 /* We cannot tell the device to sleep
1441 * once it has been unplugged. */
1442 if (dvb->fe[0])
1443 prevent_sleep(&dvb->fe[0]->ops);
1444 if (dvb->fe[1])
1445 prevent_sleep(&dvb->fe[1]->ops);
1446 }
1447
1448 em28xx_unregister_dvb(dvb);
1449 kfree(dvb);
Aidan Thornton3421b772008-04-17 21:40:36 -03001450 dev->dvb = NULL;
1451 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001452
1453 return 0;
1454}
1455
1456static struct em28xx_ops dvb_ops = {
1457 .id = EM28XX_DVB,
1458 .name = "Em28xx dvb Extension",
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001459 .init = em28xx_dvb_init,
1460 .fini = em28xx_dvb_fini,
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001461};
1462
1463static int __init em28xx_dvb_register(void)
1464{
1465 return em28xx_register_extension(&dvb_ops);
1466}
1467
1468static void __exit em28xx_dvb_unregister(void)
1469{
1470 em28xx_unregister_extension(&dvb_ops);
1471}
1472
1473module_init(em28xx_dvb_register);
1474module_exit(em28xx_dvb_unregister);