blob: f72663a9b5c58c07ee62e92697091d64f4c54508 [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;
Antti Palosaarieafa2ad2013-12-02 18:38:41 -030092 struct i2c_client *i2c_client_tuner;
Aidan Thornton3421b772008-04-17 21:40:36 -030093};
94
95
96static inline void print_err_status(struct em28xx *dev,
97 int packet, int status)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030098{
Aidan Thornton3421b772008-04-17 21:40:36 -030099 char *errmsg = "Unknown";
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300100
Aidan Thornton3421b772008-04-17 21:40:36 -0300101 switch (status) {
102 case -ENOENT:
103 errmsg = "unlinked synchronuously";
104 break;
105 case -ECONNRESET:
106 errmsg = "unlinked asynchronuously";
107 break;
108 case -ENOSR:
109 errmsg = "Buffer error (overrun)";
110 break;
111 case -EPIPE:
112 errmsg = "Stalled (device not responding)";
113 break;
114 case -EOVERFLOW:
115 errmsg = "Babble (bad cable?)";
116 break;
117 case -EPROTO:
118 errmsg = "Bit-stuff error (bad cable?)";
119 break;
120 case -EILSEQ:
121 errmsg = "CRC/Timeout (could be anything)";
122 break;
123 case -ETIME:
124 errmsg = "Device does not respond";
125 break;
126 }
127 if (packet < 0) {
128 dprintk(1, "URB status %d [%s].\n", status, errmsg);
129 } else {
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300130 dprintk(1, "URB packet %d, status %d [%s].\n",
131 packet, status, errmsg);
Aidan Thornton3421b772008-04-17 21:40:36 -0300132 }
133}
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300134
Frank Schaefera950e4a2012-11-08 14:11:47 -0300135static inline int em28xx_dvb_urb_data_copy(struct em28xx *dev, struct urb *urb)
Aidan Thornton3421b772008-04-17 21:40:36 -0300136{
Frank Schaefera950e4a2012-11-08 14:11:47 -0300137 int xfer_bulk, num_packets, i;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300138
Aidan Thornton3421b772008-04-17 21:40:36 -0300139 if (!dev)
140 return 0;
141
Frank Schaefer2665c292012-12-27 19:02:43 -0300142 if (dev->disconnected)
Aidan Thornton3421b772008-04-17 21:40:36 -0300143 return 0;
144
Frank Schaefer1653cb0c2012-11-08 14:11:44 -0300145 if (urb->status < 0)
Aidan Thornton3421b772008-04-17 21:40:36 -0300146 print_err_status(dev, -1, urb->status);
Aidan Thornton3421b772008-04-17 21:40:36 -0300147
Frank Schaefera950e4a2012-11-08 14:11:47 -0300148 xfer_bulk = usb_pipebulk(urb->pipe);
Aidan Thornton3421b772008-04-17 21:40:36 -0300149
Frank Schaefera950e4a2012-11-08 14:11:47 -0300150 if (xfer_bulk) /* bulk */
151 num_packets = 1;
152 else /* isoc */
153 num_packets = urb->number_of_packets;
154
155 for (i = 0; i < num_packets; i++) {
156 if (xfer_bulk) {
157 if (urb->status < 0) {
158 print_err_status(dev, i, urb->status);
159 if (urb->status != -EPROTO)
160 continue;
161 }
162 dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer,
163 urb->actual_length);
164 } else {
165 if (urb->iso_frame_desc[i].status < 0) {
166 print_err_status(dev, i,
167 urb->iso_frame_desc[i].status);
168 if (urb->iso_frame_desc[i].status != -EPROTO)
169 continue;
170 }
171 dvb_dmx_swfilter(&dev->dvb->demux,
172 urb->transfer_buffer +
173 urb->iso_frame_desc[i].offset,
174 urb->iso_frame_desc[i].actual_length);
Aidan Thornton3421b772008-04-17 21:40:36 -0300175 }
Aidan Thornton3421b772008-04-17 21:40:36 -0300176 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300177
178 return 0;
179}
180
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300181static int em28xx_start_streaming(struct em28xx_dvb *dvb)
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300182{
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300183 int rc;
Hans Verkuil3de09fb2013-04-08 16:25:04 -0300184 struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
185 struct em28xx *dev = i2c_bus->dev;
Frank Schaeferc647a912012-11-08 14:11:52 -0300186 int dvb_max_packet_size, packet_multiplier, dvb_alt;
Aidan Thornton3421b772008-04-17 21:40:36 -0300187
Frank Schaeferc647a912012-11-08 14:11:52 -0300188 if (dev->dvb_xfer_bulk) {
189 if (!dev->dvb_ep_bulk)
190 return -ENODEV;
191 dvb_max_packet_size = 512; /* USB 2.0 spec */
192 packet_multiplier = EM28XX_DVB_BULK_PACKET_MULTIPLIER;
193 dvb_alt = 0;
194 } else { /* isoc */
195 if (!dev->dvb_ep_isoc)
196 return -ENODEV;
197 dvb_max_packet_size = dev->dvb_max_pkt_size_isoc;
198 if (dvb_max_packet_size < 0)
199 return dvb_max_packet_size;
200 packet_multiplier = EM28XX_DVB_NUM_ISOC_PACKETS;
201 dvb_alt = dev->dvb_alt_isoc;
202 }
203
204 usb_set_interface(dev->udev, 0, dvb_alt);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300205 rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
206 if (rc < 0)
207 return rc;
Aidan Thornton3421b772008-04-17 21:40:36 -0300208
Gianluca Gennari86d38d12012-02-13 13:59:22 -0300209 dprintk(1, "Using %d buffers each with %d x %d bytes\n",
Mauro Carvalho Chehabf7acc4b2011-07-28 15:42:00 -0300210 EM28XX_DVB_NUM_BUFS,
Frank Schaeferc647a912012-11-08 14:11:52 -0300211 packet_multiplier,
212 dvb_max_packet_size);
Devin Heitmuellerd18e2fd2009-05-16 17:09:28 -0300213
Frank Schaeferc647a912012-11-08 14:11:52 -0300214 return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE,
215 dev->dvb_xfer_bulk,
Frank Schaefer057ca0d2012-11-08 14:11:42 -0300216 EM28XX_DVB_NUM_BUFS,
Frank Schaeferc647a912012-11-08 14:11:52 -0300217 dvb_max_packet_size,
218 packet_multiplier,
Frank Schaefera950e4a2012-11-08 14:11:47 -0300219 em28xx_dvb_urb_data_copy);
Aidan Thornton3421b772008-04-17 21:40:36 -0300220}
221
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300222static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300223{
Hans Verkuil3de09fb2013-04-08 16:25:04 -0300224 struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
225 struct em28xx *dev = i2c_bus->dev;
Aidan Thornton3421b772008-04-17 21:40:36 -0300226
Gianluca Gennari5f5f1472012-03-22 08:48:17 -0300227 em28xx_stop_urbs(dev);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300228
Aidan Thornton3421b772008-04-17 21:40:36 -0300229 return 0;
230}
231
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300232static int em28xx_start_feed(struct dvb_demux_feed *feed)
Aidan Thornton3421b772008-04-17 21:40:36 -0300233{
234 struct dvb_demux *demux = feed->demux;
235 struct em28xx_dvb *dvb = demux->priv;
236 int rc, ret;
237
238 if (!demux->dmx.frontend)
239 return -EINVAL;
240
241 mutex_lock(&dvb->lock);
242 dvb->nfeeds++;
243 rc = dvb->nfeeds;
244
245 if (dvb->nfeeds == 1) {
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300246 ret = em28xx_start_streaming(dvb);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300247 if (ret < 0)
248 rc = ret;
Aidan Thornton3421b772008-04-17 21:40:36 -0300249 }
250
251 mutex_unlock(&dvb->lock);
252 return rc;
253}
254
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300255static int em28xx_stop_feed(struct dvb_demux_feed *feed)
Aidan Thornton3421b772008-04-17 21:40:36 -0300256{
257 struct dvb_demux *demux = feed->demux;
258 struct em28xx_dvb *dvb = demux->priv;
259 int err = 0;
260
261 mutex_lock(&dvb->lock);
262 dvb->nfeeds--;
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300263
264 if (0 == dvb->nfeeds)
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300265 err = em28xx_stop_streaming(dvb);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300266
Aidan Thornton3421b772008-04-17 21:40:36 -0300267 mutex_unlock(&dvb->lock);
268 return err;
269}
270
271
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300272
273/* ------------------------------------------------------------------ */
274static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
275{
Mauro Carvalho Chehaba3b60202013-04-28 10:33:57 -0300276 struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
Mauro Carvalho Chehab96346142013-12-26 12:41:03 -0300277 struct em28xx *dev = i2c_bus->dev;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300278
279 if (acquire)
280 return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
281 else
Mauro Carvalho Chehab2fe3e2e2008-11-27 09:10:40 -0300282 return em28xx_set_mode(dev, EM28XX_SUSPEND);
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300283}
284
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300285/* ------------------------------------------------------------------ */
286
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -0300287static struct lgdt330x_config em2880_lgdt3303_dev = {
288 .demod_address = 0x0e,
289 .demod_chip = LGDT3303,
290};
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300291
Jarod Wilson7e48b302010-03-07 17:55:43 -0300292static struct lgdt3305_config em2870_lgdt3304_dev = {
293 .i2c_addr = 0x0e,
294 .demod_chip = LGDT3304,
295 .spectral_inversion = 1,
296 .deny_i2c_rptr = 1,
297 .mpeg_mode = LGDT3305_MPEG_PARALLEL,
298 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
299 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
300 .vsb_if_khz = 3250,
301 .qam_if_khz = 4000,
302};
303
Jean-Francois Thibert6dbea9f2013-10-09 11:18:05 -0300304static struct lgdt3305_config em2874_lgdt3305_dev = {
305 .i2c_addr = 0x0e,
306 .demod_chip = LGDT3305,
307 .spectral_inversion = 1,
308 .deny_i2c_rptr = 0,
309 .mpeg_mode = LGDT3305_MPEG_SERIAL,
310 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
311 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
312 .vsb_if_khz = 3250,
313 .qam_if_khz = 4000,
314};
315
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300316static struct s921_config sharp_isdbt = {
317 .demod_address = 0x30 >> 1
318};
319
Aidan Thornton7e6388a2008-04-17 21:40:03 -0300320static struct zl10353_config em28xx_zl10353_with_xc3028 = {
321 .demod_address = (0x1e >> 1),
322 .no_tuner = 1,
323 .parallel_ts = 1,
324 .if2 = 45600,
325};
326
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300327static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
328 .demod_address = 0x32 >> 1,
329 .output_mode = S5H1409_PARALLEL_OUTPUT,
330 .gpio = S5H1409_GPIO_OFF,
331 .inversion = S5H1409_INVERSION_OFF,
332 .status_mode = S5H1409_DEMODLOCKING,
333 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
334};
335
Jarod Wilson7e48b302010-03-07 17:55:43 -0300336static struct tda18271_std_map kworld_a340_std_map = {
337 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
338 .if_lvl = 1, .rfagc_top = 0x37, },
339 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
340 .if_lvl = 1, .rfagc_top = 0x37, },
341};
342
343static struct tda18271_config kworld_a340_config = {
344 .std_map = &kworld_a340_std_map,
345};
346
Jean-Francois Thibert6dbea9f2013-10-09 11:18:05 -0300347static struct tda18271_config kworld_ub435q_v2_config = {
348 .std_map = &kworld_a340_std_map,
349 .gate = TDA18271_GATE_DIGITAL,
350};
351
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300352static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300353 .demod_address = (0x1e >> 1),
354 .no_tuner = 1,
355 .disable_i2c_gate_ctrl = 1,
356 .parallel_ts = 1,
357 .if2 = 45600,
358};
359
Devin Heitmueller75e2b862011-03-13 02:01:02 -0300360static struct drxd_config em28xx_drxd = {
Mauro Carvalho Chehabaac865f2011-12-26 09:41:14 -0300361 .demod_address = 0x70,
362 .demod_revision = 0xa2,
363 .pll_type = DRXD_PLL_NONE,
364 .clock = 12000,
365 .insert_rs_byte = 1,
366 .IF = 42800000,
Devin Heitmueller6b142b32011-03-13 02:02:01 -0300367 .disable_i2c_gate_ctrl = 1,
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300368};
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300369
Ezequiel García61bdbef2012-06-12 09:53:41 -0300370static struct drxk_config terratec_h5_drxk = {
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300371 .adr = 0x29,
Mauro Carvalho Chehabe4f4f872011-07-09 17:35:26 -0300372 .single_master = 1,
Mauro Carvalho Chehabf1fe1b72011-07-09 21:59:33 -0300373 .no_i2c_bridge = 1,
Mauro Carvalho Chehab8b9456a2011-07-11 14:33:51 -0300374 .microcode_name = "dvb-usb-terratec-h5-drxk.fw",
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300375 .qam_demod_parameter_count = 2,
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300376 .load_firmware_sync = true,
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300377};
378
Ezequiel García61bdbef2012-06-12 09:53:41 -0300379static struct drxk_config hauppauge_930c_drxk = {
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300380 .adr = 0x29,
381 .single_master = 1,
382 .no_i2c_bridge = 1,
383 .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
384 .chunk_size = 56,
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300385 .qam_demod_parameter_count = 2,
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300386 .load_firmware_sync = true,
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300387};
388
Martin Blumenstingl89040132012-10-04 14:22:54 -0300389static struct drxk_config terratec_htc_stick_drxk = {
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300390 .adr = 0x29,
391 .single_master = 1,
392 .no_i2c_bridge = 1,
393 .microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw",
394 .chunk_size = 54,
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300395 .qam_demod_parameter_count = 2,
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300396 /* Required for the antenna_gpio to disable LNA. */
397 .antenna_dvbt = true,
398 /* The windows driver uses the same. This will disable LNA. */
399 .antenna_gpio = 0x6,
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300400 .load_firmware_sync = true,
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300401};
402
Ezequiel García61bdbef2012-06-12 09:53:41 -0300403static struct drxk_config maxmedia_ub425_tc_drxk = {
Antti Palosaari35530852012-03-18 18:09:01 -0300404 .adr = 0x29,
405 .single_master = 1,
406 .no_i2c_bridge = 1,
Antti Palosaari8d100b22013-10-04 14:40:06 -0300407 .microcode_name = "dvb-demod-drxk-01.fw",
408 .chunk_size = 62,
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300409 .load_firmware_sync = true,
Antti Palosaaride0fc462013-10-04 15:25:55 -0300410 .qam_demod_parameter_count = 2,
Antti Palosaari35530852012-03-18 18:09:01 -0300411};
412
Ezequiel García61bdbef2012-06-12 09:53:41 -0300413static struct drxk_config pctv_520e_drxk = {
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300414 .adr = 0x29,
415 .single_master = 1,
416 .microcode_name = "dvb-demod-drxk-pctv.fw",
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300417 .qam_demod_parameter_count = 2,
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300418 .chunk_size = 58,
Antti Palosaarif6f379d2012-05-17 19:09:06 -0300419 .antenna_dvbt = true, /* disable LNA */
420 .antenna_gpio = (1 << 2), /* disable LNA */
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300421 .load_firmware_sync = true,
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300422};
423
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300424static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
425{
426 struct em28xx_dvb *dvb = fe->sec_priv;
427 int status;
428
429 if (!dvb)
430 return -EINVAL;
431
432 if (enable) {
433 down(&dvb->pll_mutex);
434 status = dvb->gate_ctrl(fe, 1);
435 } else {
436 status = dvb->gate_ctrl(fe, 0);
437 up(&dvb->pll_mutex);
438 }
439 return status;
440}
441
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300442static void hauppauge_hvr930c_init(struct em28xx *dev)
443{
444 int i;
445
446 struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
Frank Schaefer907d1092013-06-03 14:12:02 -0300447 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0x65},
448 {EM2874_R80_GPIO_P0_CTRL, 0xfb, 0xff, 0x32},
449 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0xb8},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300450 { -1, -1, -1, -1},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300451 };
452 struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
Frank Schaefer907d1092013-06-03 14:12:02 -0300453 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
454 {EM2874_R80_GPIO_P0_CTRL, 0xaf, 0xff, 0x65},
455 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x76},
456 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
457 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
458 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x40},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300459
Frank Schaefer907d1092013-06-03 14:12:02 -0300460 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x65},
461 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
462 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
463 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300464
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300465 { -1, -1, -1, -1},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300466 };
467
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300468 struct {
469 unsigned char r[4];
470 int len;
471 } regs[] = {
472 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
473 {{ 0x01, 0x02 }, 2},
474 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
475 {{ 0x01, 0x00 }, 2},
476 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
477 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
478 {{ 0x01, 0x00 }, 2},
479 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
480 {{ 0x04, 0x00 }, 2},
481 {{ 0x00, 0x04 }, 2},
482 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
483 {{ 0x04, 0x14 }, 2},
484 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
485 };
486
487 em28xx_gpio_set(dev, hauppauge_hvr930c_init);
488 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
489 msleep(10);
490 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
491 msleep(10);
492
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300493 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300494
495 for (i = 0; i < ARRAY_SIZE(regs); i++)
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300496 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300497 em28xx_gpio_set(dev, hauppauge_hvr930c_end);
498
499 msleep(100);
500
501 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
502 msleep(30);
503
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300504 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
505 msleep(10);
506
507}
508
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300509static void terratec_h5_init(struct em28xx *dev)
510{
511 int i;
512 struct em28xx_reg_seq terratec_h5_init[] = {
Frank Schaeferc074fc42013-06-03 14:12:03 -0300513 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
Frank Schaefer907d1092013-06-03 14:12:02 -0300514 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
515 {EM2874_R80_GPIO_P0_CTRL, 0xf2, 0xff, 50},
516 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300517 { -1, -1, -1, -1},
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300518 };
519 struct em28xx_reg_seq terratec_h5_end[] = {
Frank Schaefer907d1092013-06-03 14:12:02 -0300520 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
521 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
522 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300523 { -1, -1, -1, -1},
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300524 };
525 struct {
526 unsigned char r[4];
527 int len;
528 } regs[] = {
529 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
530 {{ 0x01, 0x02 }, 2},
531 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
532 {{ 0x01, 0x00 }, 2},
533 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
534 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
535 {{ 0x01, 0x00 }, 2},
536 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
537 {{ 0x04, 0x00 }, 2},
538 {{ 0x00, 0x04 }, 2},
539 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
540 {{ 0x04, 0x14 }, 2},
541 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
542 };
543
544 em28xx_gpio_set(dev, terratec_h5_init);
545 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
546 msleep(10);
547 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
548 msleep(10);
549
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300550 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300551
552 for (i = 0; i < ARRAY_SIZE(regs); i++)
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300553 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300554 em28xx_gpio_set(dev, terratec_h5_end);
555};
556
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300557static void terratec_htc_stick_init(struct em28xx *dev)
558{
559 int i;
560
561 /*
562 * GPIO configuration:
563 * 0xff: unknown (does not affect DVB-T).
564 * 0xf6: DRX-K (demodulator).
565 * 0xe6: unknown (does not affect DVB-T).
566 * 0xb6: unknown (does not affect DVB-T).
567 */
568 struct em28xx_reg_seq terratec_htc_stick_init[] = {
Frank Schaeferc074fc42013-06-03 14:12:03 -0300569 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
Frank Schaefer907d1092013-06-03 14:12:02 -0300570 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
571 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 50},
572 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300573 { -1, -1, -1, -1},
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300574 };
575 struct em28xx_reg_seq terratec_htc_stick_end[] = {
Frank Schaefer907d1092013-06-03 14:12:02 -0300576 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
577 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 50},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300578 { -1, -1, -1, -1},
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300579 };
580
Martin Blumenstingl89040132012-10-04 14:22:54 -0300581 /*
582 * Init the analog decoder (not yet supported), but
583 * it's probably still a good idea.
584 */
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300585 struct {
586 unsigned char r[4];
587 int len;
588 } regs[] = {
589 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
590 {{ 0x01, 0x02 }, 2},
591 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
592 {{ 0x01, 0x00 }, 2},
593 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
594 };
595
596 em28xx_gpio_set(dev, terratec_htc_stick_init);
597
598 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
599 msleep(10);
600 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
601 msleep(10);
602
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300603 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300604
605 for (i = 0; i < ARRAY_SIZE(regs); i++)
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300606 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300607
608 em28xx_gpio_set(dev, terratec_htc_stick_end);
609};
610
Martin Blumenstingl89040132012-10-04 14:22:54 -0300611static void terratec_htc_usb_xs_init(struct em28xx *dev)
612{
613 int i;
614
615 struct em28xx_reg_seq terratec_htc_usb_xs_init[] = {
Frank Schaeferc074fc42013-06-03 14:12:03 -0300616 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
Frank Schaefer907d1092013-06-03 14:12:02 -0300617 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 100},
618 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 50},
619 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300620 { -1, -1, -1, -1},
Martin Blumenstingl89040132012-10-04 14:22:54 -0300621 };
622 struct em28xx_reg_seq terratec_htc_usb_xs_end[] = {
Frank Schaefer907d1092013-06-03 14:12:02 -0300623 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 100},
624 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
625 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
Frank Schaeferb68cafc2013-10-10 14:36:30 -0300626 { -1, -1, -1, -1},
Martin Blumenstingl89040132012-10-04 14:22:54 -0300627 };
628
629 /*
630 * Init the analog decoder (not yet supported), but
631 * it's probably still a good idea.
632 */
633 struct {
634 unsigned char r[4];
635 int len;
636 } regs[] = {
637 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
638 {{ 0x01, 0x02 }, 2},
639 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
640 {{ 0x01, 0x00 }, 2},
641 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
642 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
643 {{ 0x01, 0x00 }, 2},
644 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
645 {{ 0x04, 0x00 }, 2},
646 {{ 0x00, 0x04 }, 2},
647 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
648 {{ 0x04, 0x14 }, 2},
649 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
650 };
651
652 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
653
654 em28xx_gpio_set(dev, terratec_htc_usb_xs_init);
655
656 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
657 msleep(10);
658 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
659 msleep(10);
660
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300661 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
Martin Blumenstingl89040132012-10-04 14:22:54 -0300662
663 for (i = 0; i < ARRAY_SIZE(regs); i++)
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300664 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
Martin Blumenstingl89040132012-10-04 14:22:54 -0300665
666 em28xx_gpio_set(dev, terratec_htc_usb_xs_end);
667};
668
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300669static void pctv_520e_init(struct em28xx *dev)
670{
671 /*
Antti Palosaari26c8a722012-05-17 18:22:02 -0300672 * Init AVF4910B analog decoder. Looks like I2C traffic to
673 * digital demodulator and tuner are routed via AVF4910B.
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300674 */
675 int i;
676 struct {
677 unsigned char r[4];
678 int len;
679 } regs[] = {
680 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
681 {{ 0x01, 0x02 }, 2},
682 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
683 {{ 0x01, 0x00 }, 2},
684 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
685 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
686 {{ 0x01, 0x00 }, 2},
687 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
688 };
689
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300690 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; /* 0x41 */
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300691
692 for (i = 0; i < ARRAY_SIZE(regs); i++)
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300693 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300694};
695
Antti Palosaari33eebec2012-10-03 04:28:56 -0300696static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
Antti Palosaari13a53362012-07-19 22:28:56 -0300697{
Antti Palosaari33eebec2012-10-03 04:28:56 -0300698 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
Antti Palosaari13a53362012-07-19 22:28:56 -0300699 struct em28xx *dev = fe->dvb->priv;
700#ifdef CONFIG_GPIOLIB
701 struct em28xx_dvb *dvb = dev->dvb;
702 int ret;
703 unsigned long flags;
704
Antti Palosaari33eebec2012-10-03 04:28:56 -0300705 if (c->lna == 1)
706 flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
Antti Palosaari13a53362012-07-19 22:28:56 -0300707 else
Antti Palosaari33eebec2012-10-03 04:28:56 -0300708 flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
Antti Palosaari13a53362012-07-19 22:28:56 -0300709
710 ret = gpio_request_one(dvb->lna_gpio, flags, NULL);
711 if (ret)
712 em28xx_errdev("gpio request failed %d\n", ret);
713 else
714 gpio_free(dvb->lna_gpio);
715
716 return ret;
717#else
Antti Palosaari33eebec2012-10-03 04:28:56 -0300718 dev_warn(&dev->udev->dev, "%s: LNA control is disabled (lna=%u)\n",
719 KBUILD_MODNAME, c->lna);
Antti Palosaari13a53362012-07-19 22:28:56 -0300720 return 0;
721#endif
722}
723
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300724static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300725{
726 /* Values extracted from a USB trace of the Terratec Windows driver */
727 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
728 static u8 reset[] = { RESET, 0x80 };
729 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
730 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
731 static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
732 static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
733 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
734 static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
735 static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
Devin Heitmuellerff697862009-07-12 18:44:19 -0300736 static u8 tuner_go[] = { TUNER_GO, 0x01};
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300737
738 mt352_write(fe, clock_config, sizeof(clock_config));
739 udelay(200);
740 mt352_write(fe, reset, sizeof(reset));
741 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
742 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
743 mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
744 mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
745 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
746 mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
747 mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
748 mt352_write(fe, tuner_go, sizeof(tuner_go));
749 return 0;
750}
751
752static struct mt352_config terratec_xs_mt352_cfg = {
753 .demod_address = (0x1e >> 1),
754 .no_tuner = 1,
755 .if2 = 45600,
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300756 .demod_init = em28xx_mt352_terratec_xs_init,
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300757};
758
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300759static struct tda10023_config em28xx_tda10023_config = {
760 .demod_address = 0x0c,
761 .invert = 1,
762};
763
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300764static struct cxd2820r_config em28xx_cxd2820r_config = {
765 .i2c_address = (0xd8 >> 1),
766 .ts_mode = CXD2820R_TS_SERIAL,
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300767};
768
769static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
770 .output_opt = TDA18271_OUTPUT_LT_OFF,
Steve Kerrison0db4bf42011-08-09 07:16:21 -0300771 .gate = TDA18271_GATE_DIGITAL,
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300772};
773
Antti Palosaari36588712011-08-01 01:15:30 -0300774static const struct tda10071_config em28xx_tda10071_config = {
Michael Krufky41f55d52012-12-16 19:37:11 -0300775 .demod_i2c_addr = 0x55, /* (0xaa >> 1) */
776 .tuner_i2c_addr = 0x14,
Antti Palosaari36588712011-08-01 01:15:30 -0300777 .i2c_wr_max = 64,
778 .ts_mode = TDA10071_TS_SERIAL,
779 .spec_inv = 0,
780 .xtal = 40444000, /* 40.444 MHz */
781 .pll_multiplier = 20,
782};
783
784static const struct a8293_config em28xx_a8293_config = {
785 .i2c_addr = 0x08, /* (0x10 >> 1) */
786};
787
Aivar Päkk1985f6f2011-12-11 18:15:00 -0300788static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
789 .demod_address = (0x1e >> 1),
790 .disable_i2c_gate_ctrl = 1,
791 .no_tuner = 1,
792 .parallel_ts = 1,
793};
794static struct qt1010_config em28xx_qt1010_config = {
795 .i2c_address = 0x62
Aivar Päkk1985f6f2011-12-11 18:15:00 -0300796};
797
Mauro Carvalho Chehab4159d012013-02-28 10:35:56 -0300798static const struct mb86a20s_config c3tech_duo_mb86a20s_config = {
799 .demod_address = 0x10,
800 .is_serial = true,
801};
802
803static struct tda18271_std_map mb86a20s_tda18271_config = {
804 .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4,
805 .if_lvl = 1, .rfagc_top = 0x37, },
806};
807
808static struct tda18271_config c3tech_duo_tda18271_config = {
809 .std_map = &mb86a20s_tda18271_config,
810 .gate = TDA18271_GATE_DIGITAL,
811 .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
812};
813
Antti Palosaariec573362013-02-25 09:01:13 -0300814static const struct m88ds3103_config pctv_461e_m88ds3103_config = {
815 .i2c_addr = 0x68,
816 .clock = 27000000,
817 .i2c_wr_max = 33,
818 .clock_out = 0,
819 .ts_mode = M88DS3103_TS_PARALLEL_16,
820 .agc = 0x99,
821};
822
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300823/* ------------------------------------------------------------------ */
824
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300825static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300826{
827 struct dvb_frontend *fe;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300828 struct xc2028_config cfg;
829
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300830 memset(&cfg, 0, sizeof(cfg));
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -0300831 cfg.i2c_adap = &dev->i2c_adap[dev->def_i2c_bus];
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300832 cfg.i2c_addr = addr;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300833
Antti Palosaarif71095b2011-04-07 15:51:52 -0300834 if (!dev->dvb->fe[0]) {
Filipe Rosset480be182009-11-04 15:32:37 -0300835 em28xx_errdev("/2: dvb frontend not attached. "
836 "Can't attach xc3028\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300837 return -EINVAL;
838 }
839
Antti Palosaarif71095b2011-04-07 15:51:52 -0300840 fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300841 if (!fe) {
Filipe Rosset480be182009-11-04 15:32:37 -0300842 em28xx_errdev("/2: xc3028 attach failed\n");
Antti Palosaarif71095b2011-04-07 15:51:52 -0300843 dvb_frontend_detach(dev->dvb->fe[0]);
844 dev->dvb->fe[0] = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300845 return -EINVAL;
846 }
847
Filipe Rosset480be182009-11-04 15:32:37 -0300848 em28xx_info("%s/2: xc3028 attached\n", dev->name);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300849
850 return 0;
851}
852
Aidan Thornton3421b772008-04-17 21:40:36 -0300853/* ------------------------------------------------------------------ */
854
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300855static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
856 struct em28xx *dev, struct device *device)
Aidan Thornton3421b772008-04-17 21:40:36 -0300857{
858 int result;
859
860 mutex_init(&dvb->lock);
861
862 /* register adapter */
863 result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
864 adapter_nr);
865 if (result < 0) {
866 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
867 dev->name, result);
868 goto fail_adapter;
869 }
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300870
871 /* Ensure all frontends negotiate bus access */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300872 dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
873 if (dvb->fe[1])
874 dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300875
Hans Verkuil3de09fb2013-04-08 16:25:04 -0300876 dvb->adapter.priv = &dev->i2c_bus[dev->def_i2c_bus];
Aidan Thornton3421b772008-04-17 21:40:36 -0300877
878 /* register frontend */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300879 result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300880 if (result < 0) {
881 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
882 dev->name, result);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300883 goto fail_frontend0;
884 }
885
886 /* register 2nd frontend */
887 if (dvb->fe[1]) {
888 result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
889 if (result < 0) {
890 printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
891 dev->name, result);
892 goto fail_frontend1;
893 }
Aidan Thornton3421b772008-04-17 21:40:36 -0300894 }
895
896 /* register demux stuff */
897 dvb->demux.dmx.capabilities =
898 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
899 DMX_MEMORY_BASED_FILTERING;
900 dvb->demux.priv = dvb;
901 dvb->demux.filternum = 256;
902 dvb->demux.feednum = 256;
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300903 dvb->demux.start_feed = em28xx_start_feed;
904 dvb->demux.stop_feed = em28xx_stop_feed;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300905
Aidan Thornton3421b772008-04-17 21:40:36 -0300906 result = dvb_dmx_init(&dvb->demux);
907 if (result < 0) {
908 printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
909 dev->name, result);
910 goto fail_dmx;
911 }
912
913 dvb->dmxdev.filternum = 256;
914 dvb->dmxdev.demux = &dvb->demux.dmx;
915 dvb->dmxdev.capabilities = 0;
916 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
917 if (result < 0) {
918 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
919 dev->name, result);
920 goto fail_dmxdev;
921 }
922
923 dvb->fe_hw.source = DMX_FRONTEND_0;
924 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
925 if (result < 0) {
926 printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
927 dev->name, result);
928 goto fail_fe_hw;
929 }
930
931 dvb->fe_mem.source = DMX_MEMORY_FE;
932 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
933 if (result < 0) {
934 printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
935 dev->name, result);
936 goto fail_fe_mem;
937 }
938
939 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
940 if (result < 0) {
941 printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
942 dev->name, result);
943 goto fail_fe_conn;
944 }
945
946 /* register network adapter */
947 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
948 return 0;
949
950fail_fe_conn:
951 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
952fail_fe_mem:
953 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
954fail_fe_hw:
955 dvb_dmxdev_release(&dvb->dmxdev);
956fail_dmxdev:
957 dvb_dmx_release(&dvb->demux);
958fail_dmx:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300959 if (dvb->fe[1])
960 dvb_unregister_frontend(dvb->fe[1]);
961 dvb_unregister_frontend(dvb->fe[0]);
962fail_frontend1:
963 if (dvb->fe[1])
964 dvb_frontend_detach(dvb->fe[1]);
965fail_frontend0:
966 dvb_frontend_detach(dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300967 dvb_unregister_adapter(&dvb->adapter);
968fail_adapter:
969 return result;
970}
971
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300972static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
Aidan Thornton3421b772008-04-17 21:40:36 -0300973{
974 dvb_net_release(&dvb->net);
975 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
976 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
977 dvb_dmxdev_release(&dvb->dmxdev);
978 dvb_dmx_release(&dvb->demux);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300979 if (dvb->fe[1])
980 dvb_unregister_frontend(dvb->fe[1]);
981 dvb_unregister_frontend(dvb->fe[0]);
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -0300982 if (dvb->fe[1] && !dvb->dont_attach_fe1)
Antti Palosaarif71095b2011-04-07 15:51:52 -0300983 dvb_frontend_detach(dvb->fe[1]);
984 dvb_frontend_detach(dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300985 dvb_unregister_adapter(&dvb->adapter);
986}
987
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300988static int em28xx_dvb_init(struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300989{
Antti Palosaari13a53362012-07-19 22:28:56 -0300990 int result = 0, mfe_shared = 0;
Aidan Thornton3421b772008-04-17 21:40:36 -0300991 struct em28xx_dvb *dvb;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300992
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -0300993 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -0300994 /* This device does not support the extension */
995 return 0;
996 }
997
Mauro Carvalho Chehab96346142013-12-26 12:41:03 -0300998 em28xx_info("Binding DVB extension\n");
999
Aidan Thornton3421b772008-04-17 21:40:36 -03001000 dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -03001001
1002 if (dvb == NULL) {
Filipe Rosset480be182009-11-04 15:32:37 -03001003 em28xx_info("em28xx_dvb: memory allocation failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -03001004 return -ENOMEM;
1005 }
1006 dev->dvb = dvb;
Antti Palosaarif71095b2011-04-07 15:51:52 -03001007 dvb->fe[0] = dvb->fe[1] = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001008
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -03001009 mutex_lock(&dev->lock);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -03001010 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001011 /* init frontend */
1012 switch (dev->model) {
Mauro Carvalho Chehabebaefdb2011-06-01 10:16:25 -03001013 case EM2874_BOARD_LEADERSHIP_ISDBT:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001014 dvb->fe[0] = dvb_attach(s921_attach,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001015 &sharp_isdbt, &dev->i2c_adap[dev->def_i2c_bus]);
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -03001016
Antti Palosaarif71095b2011-04-07 15:51:52 -03001017 if (!dvb->fe[0]) {
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -03001018 result = -EINVAL;
1019 goto out_free;
1020 }
1021
1022 break;
Douglas Schilling Landgraff89bc322008-12-01 21:01:04 -03001023 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
Mauro Carvalho Chehab10ac6602008-07-27 14:58:58 -03001024 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
Devin Heitmueller4fd305b2008-06-04 13:43:46 -03001025 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
Devin Heitmuellere14b3652008-07-26 11:04:33 -03001026 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001027 dvb->fe[0] = dvb_attach(lgdt330x_attach,
Aidan Thornton3421b772008-04-17 21:40:36 -03001028 &em2880_lgdt3303_dev,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001029 &dev->i2c_adap[dev->def_i2c_bus]);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001030 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Aidan Thornton3421b772008-04-17 21:40:36 -03001031 result = -EINVAL;
1032 goto out_free;
1033 }
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -03001034 break;
Thierry MERLE46510b52008-10-11 16:56:13 -03001035 case EM2880_BOARD_KWORLD_DVB_310U:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001036 dvb->fe[0] = dvb_attach(zl10353_attach,
Aidan Thornton3421b772008-04-17 21:40:36 -03001037 &em28xx_zl10353_with_xc3028,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001038 &dev->i2c_adap[dev->def_i2c_bus]);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001039 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Aidan Thornton3421b772008-04-17 21:40:36 -03001040 result = -EINVAL;
1041 goto out_free;
1042 }
Aidan Thornton7e6388a2008-04-17 21:40:03 -03001043 break;
Devin Heitmuellera84f79a2009-07-12 17:05:02 -03001044 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
Uroš Vamplec994d02009-09-30 22:53:37 -03001045 case EM2882_BOARD_TERRATEC_HYBRID_XS:
Devin Heitmueller01a5fd62009-08-07 09:25:06 -03001046 case EM2880_BOARD_EMPIRE_DUAL_TV:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001047 dvb->fe[0] = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -03001048 &em28xx_zl10353_xc3028_no_i2c_gate,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001049 &dev->i2c_adap[dev->def_i2c_bus]);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001050 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmuellera84f79a2009-07-12 17:05:02 -03001051 result = -EINVAL;
1052 goto out_free;
1053 }
1054 break;
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001055 case EM2880_BOARD_TERRATEC_HYBRID_XS:
Catimimi65638012010-02-18 18:06:32 -03001056 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
Devin Heitmuellerd5b3ba92009-07-08 21:51:35 -03001057 case EM2881_BOARD_PINNACLE_HYBRID_PRO:
Andrea.Amorosi76@gmail.com7ca7ef62010-02-09 17:53:38 -03001058 case EM2882_BOARD_DIKOM_DK300:
Antonio Larrosa811fab62010-03-04 22:19:48 -03001059 case EM2882_BOARD_KWORLD_VS_DVBT:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001060 dvb->fe[0] = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -03001061 &em28xx_zl10353_xc3028_no_i2c_gate,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001062 &dev->i2c_adap[dev->def_i2c_bus]);
Antti Palosaarif71095b2011-04-07 15:51:52 -03001063 if (dvb->fe[0] == NULL) {
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001064 /* This board could have either a zl10353 or a mt352.
1065 If the chip id isn't for zl10353, try mt352 */
Antti Palosaarif71095b2011-04-07 15:51:52 -03001066 dvb->fe[0] = dvb_attach(mt352_attach,
Devin Heitmueller4fb202a2009-07-12 17:51:12 -03001067 &terratec_xs_mt352_cfg,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001068 &dev->i2c_adap[dev->def_i2c_bus]);
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001069 }
Devin Heitmueller4fb202a2009-07-12 17:51:12 -03001070
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001071 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmuellerf7976082009-06-22 22:32:32 -03001072 result = -EINVAL;
1073 goto out_free;
1074 }
1075 break;
Aivar Päkk1985f6f2011-12-11 18:15:00 -03001076 case EM2870_BOARD_KWORLD_355U:
1077 dvb->fe[0] = dvb_attach(zl10353_attach,
1078 &em28xx_zl10353_no_i2c_gate_dev,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001079 &dev->i2c_adap[dev->def_i2c_bus]);
Aivar Päkk1985f6f2011-12-11 18:15:00 -03001080 if (dvb->fe[0] != NULL)
1081 dvb_attach(qt1010_attach, dvb->fe[0],
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001082 &dev->i2c_adap[dev->def_i2c_bus], &em28xx_qt1010_config);
Aivar Päkk1985f6f2011-12-11 18:15:00 -03001083 break;
Robert Krakora6e7b9ea2009-01-18 21:59:34 -03001084 case EM2883_BOARD_KWORLD_HYBRID_330U:
Devin Heitmueller19859222009-06-19 00:33:54 -03001085 case EM2882_BOARD_EVGA_INDTUBE:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001086 dvb->fe[0] = dvb_attach(s5h1409_attach,
Robert Krakora6e7b9ea2009-01-18 21:59:34 -03001087 &em28xx_s5h1409_with_xc3028,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001088 &dev->i2c_adap[dev->def_i2c_bus]);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001089 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Robert Krakora6e7b9ea2009-01-18 21:59:34 -03001090 result = -EINVAL;
1091 goto out_free;
1092 }
1093 break;
Franklin Mengd7de5d82009-06-06 17:05:02 -03001094 case EM2882_BOARD_KWORLD_ATSC_315U:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001095 dvb->fe[0] = dvb_attach(lgdt330x_attach,
Franklin Mengd7de5d82009-06-06 17:05:02 -03001096 &em2880_lgdt3303_dev,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001097 &dev->i2c_adap[dev->def_i2c_bus]);
Antti Palosaarif71095b2011-04-07 15:51:52 -03001098 if (dvb->fe[0] != NULL) {
1099 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001100 &dev->i2c_adap[dev->def_i2c_bus], 0x61, TUNER_THOMSON_DTT761X)) {
Franklin Mengd7de5d82009-06-06 17:05:02 -03001101 result = -EINVAL;
1102 goto out_free;
1103 }
1104 }
1105 break;
Devin Heitmueller17d9d552008-06-08 10:22:03 -03001106 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
Devin Heitmuellerad9b4bb2011-03-13 02:09:59 -03001107 case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001108 dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001109 &dev->i2c_adap[dev->def_i2c_bus], &dev->udev->dev);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001110 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmueller17d9d552008-06-08 10:22:03 -03001111 result = -EINVAL;
1112 goto out_free;
1113 }
1114 break;
Antti Palosaari285eb1a2009-09-15 14:42:13 -03001115 case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
1116 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
Antti Palosaarif71095b2011-04-07 15:51:52 -03001117 dvb->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari285eb1a2009-09-15 14:42:13 -03001118 &em28xx_tda10023_config,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001119 &dev->i2c_adap[dev->def_i2c_bus], 0x48);
Antti Palosaarif71095b2011-04-07 15:51:52 -03001120 if (dvb->fe[0]) {
1121 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001122 &dev->i2c_adap[dev->def_i2c_bus], 0x60, TUNER_PHILIPS_CU1216L)) {
Antti Palosaari285eb1a2009-09-15 14:42:13 -03001123 result = -EINVAL;
1124 goto out_free;
1125 }
1126 }
1127 break;
Jarod Wilson7e48b302010-03-07 17:55:43 -03001128 case EM2870_BOARD_KWORLD_A340:
Antti Palosaarif71095b2011-04-07 15:51:52 -03001129 dvb->fe[0] = dvb_attach(lgdt3305_attach,
Jarod Wilson7e48b302010-03-07 17:55:43 -03001130 &em2870_lgdt3304_dev,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001131 &dev->i2c_adap[dev->def_i2c_bus]);
Antti Palosaarif71095b2011-04-07 15:51:52 -03001132 if (dvb->fe[0] != NULL)
1133 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001134 &dev->i2c_adap[dev->def_i2c_bus], &kworld_a340_config);
Jarod Wilson7e48b302010-03-07 17:55:43 -03001135 break;
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001136 case EM28174_BOARD_PCTV_290E:
Antti Palosaaria36a66d2012-08-16 21:07:23 -03001137 /* set default GPIO0 for LNA, used if GPIOLIB is undefined */
1138 dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O |
1139 CXD2820R_GPIO_L;
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001140 dvb->fe[0] = dvb_attach(cxd2820r_attach,
Manu Abraham7e7b8282011-12-10 00:44:24 -03001141 &em28xx_cxd2820r_config,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001142 &dev->i2c_adap[dev->def_i2c_bus],
Antti Palosaari13a53362012-07-19 22:28:56 -03001143 &dvb->lna_gpio);
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001144 if (dvb->fe[0]) {
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001145 /* FE 0 attach tuner */
Manu Abraham7e7b8282011-12-10 00:44:24 -03001146 if (!dvb_attach(tda18271_attach,
1147 dvb->fe[0],
1148 0x60,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001149 &dev->i2c_adap[dev->def_i2c_bus],
Manu Abraham7e7b8282011-12-10 00:44:24 -03001150 &em28xx_cxd2820r_tda18271_config)) {
1151
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001152 dvb_frontend_detach(dvb->fe[0]);
1153 result = -EINVAL;
1154 goto out_free;
1155 }
Antti Palosaari1e8f31f2012-07-19 21:10:36 -03001156
Antti Palosaari13a53362012-07-19 22:28:56 -03001157#ifdef CONFIG_GPIOLIB
Antti Palosaari0c42a552012-09-19 20:52:21 -03001158 /* enable LNA for DVB-T, DVB-T2 and DVB-C */
1159 result = gpio_request_one(dvb->lna_gpio,
1160 GPIOF_OUT_INIT_LOW, NULL);
1161 if (result)
1162 em28xx_errdev("gpio request failed %d\n",
1163 result);
1164 else
1165 gpio_free(dvb->lna_gpio);
Antti Palosaari1e8f31f2012-07-19 21:10:36 -03001166
Antti Palosaari0c42a552012-09-19 20:52:21 -03001167 result = 0; /* continue even set LNA fails */
Antti Palosaari13a53362012-07-19 22:28:56 -03001168#endif
Antti Palosaari0c42a552012-09-19 20:52:21 -03001169 dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
1170 }
1171
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001172 break;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001173 case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
Mauro Carvalho Chehab85032322011-11-24 15:01:45 -02001174 {
1175 struct xc5000_config cfg;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001176 hauppauge_hvr930c_init(dev);
1177
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001178 dvb->fe[0] = dvb_attach(drxk_attach,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001179 &hauppauge_930c_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001180 if (!dvb->fe[0]) {
1181 result = -EINVAL;
1182 goto out_free;
1183 }
1184 /* FIXME: do we need a pll semaphore? */
1185 dvb->fe[0]->sec_priv = dvb;
1186 sema_init(&dvb->pll_mutex, 1);
1187 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1188 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001189
1190 /* Attach xc5000 */
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001191 memset(&cfg, 0, sizeof(cfg));
1192 cfg.i2c_address = 0x61;
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001193 cfg.if_khz = 4000;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001194
1195 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1196 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001197 if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001198 &cfg)) {
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001199 result = -EINVAL;
1200 goto out_free;
1201 }
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001202 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1203 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1204
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001205 break;
Mauro Carvalho Chehab85032322011-11-24 15:01:45 -02001206 }
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001207 case EM2884_BOARD_TERRATEC_H5:
1208 terratec_h5_init(dev);
1209
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001210 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 -03001211 if (!dvb->fe[0]) {
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001212 result = -EINVAL;
1213 goto out_free;
1214 }
1215 /* FIXME: do we need a pll semaphore? */
1216 dvb->fe[0]->sec_priv = dvb;
1217 sema_init(&dvb->pll_mutex, 1);
1218 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1219 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001220
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -03001221 /* Attach tda18271 to DVB-C frontend */
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001222 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1223 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001224 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus], 0x60)) {
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001225 result = -EINVAL;
1226 goto out_free;
1227 }
1228 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1229 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -03001230
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001231 break;
Mauro Carvalho Chehab4159d012013-02-28 10:35:56 -03001232 case EM2884_BOARD_C3TECH_DIGITAL_DUO:
1233 dvb->fe[0] = dvb_attach(mb86a20s_attach,
1234 &c3tech_duo_mb86a20s_config,
1235 &dev->i2c_adap[dev->def_i2c_bus]);
1236 if (dvb->fe[0] != NULL)
1237 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1238 &dev->i2c_adap[dev->def_i2c_bus],
1239 &c3tech_duo_tda18271_config);
1240 break;
Antti Palosaari36588712011-08-01 01:15:30 -03001241 case EM28174_BOARD_PCTV_460E:
1242 /* attach demod */
1243 dvb->fe[0] = dvb_attach(tda10071_attach,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001244 &em28xx_tda10071_config, &dev->i2c_adap[dev->def_i2c_bus]);
Antti Palosaari36588712011-08-01 01:15:30 -03001245
1246 /* attach SEC */
1247 if (dvb->fe[0])
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001248 dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
Antti Palosaari36588712011-08-01 01:15:30 -03001249 &em28xx_a8293_config);
1250 break;
Jakob Haufe7c1dfdb2013-04-13 11:03:37 -03001251 case EM2874_BOARD_DELOCK_61959:
Antti Palosaari35530852012-03-18 18:09:01 -03001252 case EM2874_BOARD_MAXMEDIA_UB425_TC:
1253 /* attach demodulator */
1254 dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001255 &dev->i2c_adap[dev->def_i2c_bus]);
Antti Palosaari35530852012-03-18 18:09:01 -03001256
1257 if (dvb->fe[0]) {
1258 /* disable I2C-gate */
1259 dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
1260
1261 /* attach tuner */
Antti Palosaarib6c7abb2013-10-04 15:17:51 -03001262 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1263 &dev->i2c_adap[dev->def_i2c_bus],
1264 &em28xx_cxd2820r_tda18271_config)) {
Antti Palosaari35530852012-03-18 18:09:01 -03001265 dvb_frontend_detach(dvb->fe[0]);
1266 result = -EINVAL;
1267 goto out_free;
1268 }
1269 }
Antti Palosaari35530852012-03-18 18:09:01 -03001270 break;
Ivan Kalvachevfa5527c2012-03-19 20:09:55 -03001271 case EM2884_BOARD_PCTV_510E:
1272 case EM2884_BOARD_PCTV_520E:
1273 pctv_520e_init(dev);
1274
1275 /* attach demodulator */
1276 dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001277 &dev->i2c_adap[dev->def_i2c_bus]);
Ivan Kalvachevfa5527c2012-03-19 20:09:55 -03001278
1279 if (dvb->fe[0]) {
1280 /* attach tuner */
1281 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001282 &dev->i2c_adap[dev->def_i2c_bus],
Ivan Kalvachevfa5527c2012-03-19 20:09:55 -03001283 &em28xx_cxd2820r_tda18271_config)) {
1284 dvb_frontend_detach(dvb->fe[0]);
1285 result = -EINVAL;
1286 goto out_free;
1287 }
1288 }
1289 break;
Martin Blumenstinglc8dce002012-06-12 18:19:28 -03001290 case EM2884_BOARD_CINERGY_HTC_STICK:
1291 terratec_htc_stick_init(dev);
1292
1293 /* attach demodulator */
1294 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001295 &dev->i2c_adap[dev->def_i2c_bus]);
Martin Blumenstinglc8dce002012-06-12 18:19:28 -03001296 if (!dvb->fe[0]) {
1297 result = -EINVAL;
1298 goto out_free;
1299 }
1300
1301 /* Attach the demodulator. */
1302 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001303 &dev->i2c_adap[dev->def_i2c_bus],
Martin Blumenstinglc8dce002012-06-12 18:19:28 -03001304 &em28xx_cxd2820r_tda18271_config)) {
1305 result = -EINVAL;
1306 goto out_free;
1307 }
1308 break;
Martin Blumenstingl89040132012-10-04 14:22:54 -03001309 case EM2884_BOARD_TERRATEC_HTC_USB_XS:
1310 terratec_htc_usb_xs_init(dev);
1311
1312 /* attach demodulator */
1313 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001314 &dev->i2c_adap[dev->def_i2c_bus]);
Martin Blumenstingl89040132012-10-04 14:22:54 -03001315 if (!dvb->fe[0]) {
1316 result = -EINVAL;
1317 goto out_free;
1318 }
1319
1320 /* Attach the demodulator. */
1321 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Mauro Carvalho Chehabc7a45e52013-03-05 06:55:26 -03001322 &dev->i2c_adap[dev->def_i2c_bus],
Martin Blumenstingl89040132012-10-04 14:22:54 -03001323 &em28xx_cxd2820r_tda18271_config)) {
1324 result = -EINVAL;
1325 goto out_free;
1326 }
1327 break;
Jean-Francois Thibert6dbea9f2013-10-09 11:18:05 -03001328 case EM2874_BOARD_KWORLD_UB435Q_V2:
1329 dvb->fe[0] = dvb_attach(lgdt3305_attach,
1330 &em2874_lgdt3305_dev,
1331 &dev->i2c_adap[dev->def_i2c_bus]);
1332 if (!dvb->fe[0]) {
1333 result = -EINVAL;
1334 goto out_free;
1335 }
1336
1337 /* Attach the demodulator. */
1338 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1339 &dev->i2c_adap[dev->def_i2c_bus],
1340 &kworld_ub435q_v2_config)) {
1341 result = -EINVAL;
1342 goto out_free;
1343 }
1344 break;
Antti Palosaariec573362013-02-25 09:01:13 -03001345 case EM28178_BOARD_PCTV_461E:
1346 {
1347 /* demod I2C adapter */
1348 struct i2c_adapter *i2c_adapter;
Antti Palosaarieafa2ad2013-12-02 18:38:41 -03001349 struct i2c_board_info info;
1350 struct m88ts2022_config m88ts2022_config = {
1351 .clock = 27000000,
1352 };
1353 memset(&info, 0, sizeof(struct i2c_board_info));
Antti Palosaariec573362013-02-25 09:01:13 -03001354
1355 /* attach demod */
1356 dvb->fe[0] = dvb_attach(m88ds3103_attach,
1357 &pctv_461e_m88ds3103_config,
1358 &dev->i2c_adap[dev->def_i2c_bus],
1359 &i2c_adapter);
1360 if (dvb->fe[0] == NULL) {
1361 result = -ENODEV;
1362 goto out_free;
1363 }
1364
1365 /* attach tuner */
Antti Palosaarieafa2ad2013-12-02 18:38:41 -03001366 m88ts2022_config.fe = dvb->fe[0];
1367 strlcpy(info.type, "m88ts2022", I2C_NAME_SIZE);
1368 info.addr = 0x60;
1369 info.platform_data = &m88ts2022_config;
1370 request_module("m88ts2022");
1371 dvb->i2c_client_tuner = i2c_new_device(i2c_adapter, &info);
Antti Palosaariec573362013-02-25 09:01:13 -03001372
1373 /* delegate signal strength measurement to tuner */
1374 dvb->fe[0]->ops.read_signal_strength =
1375 dvb->fe[0]->ops.tuner_ops.get_rf_strength;
1376
1377 /* attach SEC */
1378 if (!dvb_attach(a8293_attach, dvb->fe[0],
1379 &dev->i2c_adap[dev->def_i2c_bus],
1380 &em28xx_a8293_config)) {
1381 dvb_frontend_detach(dvb->fe[0]);
1382 result = -ENODEV;
1383 goto out_free;
1384 }
1385 }
1386 break;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001387 default:
Filipe Rosset480be182009-11-04 15:32:37 -03001388 em28xx_errdev("/2: The frontend of your DVB/ATSC card"
1389 " isn't supported yet\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001390 break;
1391 }
Antti Palosaarif71095b2011-04-07 15:51:52 -03001392 if (NULL == dvb->fe[0]) {
Filipe Rosset480be182009-11-04 15:32:37 -03001393 em28xx_errdev("/2: frontend initialization failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -03001394 result = -EINVAL;
1395 goto out_free;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001396 }
Michael Krufkyd7cba042008-09-12 13:31:45 -03001397 /* define general-purpose callback pointer */
Antti Palosaarif71095b2011-04-07 15:51:52 -03001398 dvb->fe[0]->callback = em28xx_tuner_callback;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001399 if (dvb->fe[1])
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001400 dvb->fe[1]->callback = em28xx_tuner_callback;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001401
1402 /* register everything */
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001403 result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
Aidan Thornton3421b772008-04-17 21:40:36 -03001404
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -03001405 if (result < 0)
Aidan Thornton3421b772008-04-17 21:40:36 -03001406 goto out_free;
Aidan Thornton3421b772008-04-17 21:40:36 -03001407
Antti Palosaarie3645432011-07-28 18:59:30 -03001408 /* MFE lock */
1409 dvb->adapter.mfe_shared = mfe_shared;
1410
Mauro Carvalho Chehab96346142013-12-26 12:41:03 -03001411 em28xx_info("DVB extension successfully initialized\n");
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -03001412ret:
1413 em28xx_set_mode(dev, EM28XX_SUSPEND);
1414 mutex_unlock(&dev->lock);
1415 return result;
Aidan Thornton3421b772008-04-17 21:40:36 -03001416
1417out_free:
1418 kfree(dvb);
1419 dev->dvb = NULL;
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -03001420 goto ret;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001421}
1422
Chris Rankin0b8bd832011-08-20 16:01:26 -03001423static inline void prevent_sleep(struct dvb_frontend_ops *ops)
1424{
1425 ops->set_voltage = NULL;
1426 ops->sleep = NULL;
1427 ops->tuner_ops.sleep = NULL;
1428}
1429
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001430static int em28xx_dvb_fini(struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001431{
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -03001432 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -03001433 /* This device does not support the extension */
1434 return 0;
1435 }
1436
Aidan Thornton3421b772008-04-17 21:40:36 -03001437 if (dev->dvb) {
Chris Rankin0b8bd832011-08-20 16:01:26 -03001438 struct em28xx_dvb *dvb = dev->dvb;
1439
Frank Schaefer2665c292012-12-27 19:02:43 -03001440 if (dev->disconnected) {
Chris Rankin0b8bd832011-08-20 16:01:26 -03001441 /* We cannot tell the device to sleep
1442 * once it has been unplugged. */
1443 if (dvb->fe[0])
1444 prevent_sleep(&dvb->fe[0]->ops);
1445 if (dvb->fe[1])
1446 prevent_sleep(&dvb->fe[1]->ops);
1447 }
1448
Antti Palosaarieafa2ad2013-12-02 18:38:41 -03001449 i2c_release_client(dvb->i2c_client_tuner);
Chris Rankin0b8bd832011-08-20 16:01:26 -03001450 em28xx_unregister_dvb(dvb);
1451 kfree(dvb);
Aidan Thornton3421b772008-04-17 21:40:36 -03001452 dev->dvb = NULL;
1453 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001454
1455 return 0;
1456}
1457
1458static struct em28xx_ops dvb_ops = {
1459 .id = EM28XX_DVB,
1460 .name = "Em28xx dvb Extension",
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001461 .init = em28xx_dvb_init,
1462 .fini = em28xx_dvb_fini,
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001463};
1464
1465static int __init em28xx_dvb_register(void)
1466{
1467 return em28xx_register_extension(&dvb_ops);
1468}
1469
1470static void __exit em28xx_dvb_unregister(void)
1471{
1472 em28xx_unregister_extension(&dvb_ops);
1473}
1474
1475module_init(em28xx_dvb_register);
1476module_exit(em28xx_dvb_unregister);