blob: 34c5ea9960318fe1584d8acbb2a26f8595a12608 [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
13 Based on cx88-dvb, saa7134-dvb and videobuf-dvb originally written by:
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030014 (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
15 (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
16
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation; either version 2 of the License.
20 */
21
22#include <linux/kernel.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030024#include <linux/usb.h>
25
26#include "em28xx.h"
27#include <media/v4l2-common.h>
28#include <media/videobuf-vmalloc.h>
Franklin Mengd7de5d82009-06-06 17:05:02 -030029#include <media/tuner.h>
30#include "tuner-simple.h"
Antti Palosaari1e8f31f2012-07-19 21:10:36 -030031#include <linux/gpio.h>
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030032
33#include "lgdt330x.h"
Jarod Wilson7e48b302010-03-07 17:55:43 -030034#include "lgdt3305.h"
Aidan Thornton7e6388a2008-04-17 21:40:03 -030035#include "zl10353.h"
Robert Krakora6e7b9ea2009-01-18 21:59:34 -030036#include "s5h1409.h"
Devin Heitmueller4fb202a2009-07-12 17:51:12 -030037#include "mt352.h"
38#include "mt352_priv.h" /* FIXME */
Antti Palosaari285eb1a2009-09-15 14:42:13 -030039#include "tda1002x.h"
Jarod Wilson7e48b302010-03-07 17:55:43 -030040#include "tda18271.h"
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -030041#include "s921.h"
Devin Heitmueller75e2b862011-03-13 02:01:02 -030042#include "drxd.h"
Antti Palosaarid6a5f922011-04-07 16:34:44 -030043#include "cxd2820r.h"
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -030044#include "tda18271c2dd.h"
45#include "drxk.h"
Antti Palosaari36588712011-08-01 01:15:30 -030046#include "tda10071.h"
47#include "a8293.h"
Aivar Päkk1985f6f2011-12-11 18:15:00 -030048#include "qt1010.h"
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030049
50MODULE_DESCRIPTION("driver for em28xx based DVB cards");
51MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
52MODULE_LICENSE("GPL");
53
54static unsigned int debug;
55module_param(debug, int, 0644);
56MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
57
58DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
59
60#define dprintk(level, fmt, arg...) do { \
61if (debug >= level) \
Aidan Thornton3421b772008-04-17 21:40:36 -030062 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030063} while (0)
64
Aidan Thornton3421b772008-04-17 21:40:36 -030065struct em28xx_dvb {
Antti Palosaarif71095b2011-04-07 15:51:52 -030066 struct dvb_frontend *fe[2];
Aidan Thornton3421b772008-04-17 21:40:36 -030067
68 /* feed count management */
69 struct mutex lock;
70 int nfeeds;
71
72 /* general boilerplate stuff */
73 struct dvb_adapter adapter;
74 struct dvb_demux demux;
75 struct dmxdev dmxdev;
76 struct dmx_frontend fe_hw;
77 struct dmx_frontend fe_mem;
78 struct dvb_net net;
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -030079
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -030080 /* Due to DRX-K - probably need changes */
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -030081 int (*gate_ctrl)(struct dvb_frontend *, int);
82 struct semaphore pll_mutex;
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -030083 bool dont_attach_fe1;
Aidan Thornton3421b772008-04-17 21:40:36 -030084};
85
86
87static inline void print_err_status(struct em28xx *dev,
88 int packet, int status)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030089{
Aidan Thornton3421b772008-04-17 21:40:36 -030090 char *errmsg = "Unknown";
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030091
Aidan Thornton3421b772008-04-17 21:40:36 -030092 switch (status) {
93 case -ENOENT:
94 errmsg = "unlinked synchronuously";
95 break;
96 case -ECONNRESET:
97 errmsg = "unlinked asynchronuously";
98 break;
99 case -ENOSR:
100 errmsg = "Buffer error (overrun)";
101 break;
102 case -EPIPE:
103 errmsg = "Stalled (device not responding)";
104 break;
105 case -EOVERFLOW:
106 errmsg = "Babble (bad cable?)";
107 break;
108 case -EPROTO:
109 errmsg = "Bit-stuff error (bad cable?)";
110 break;
111 case -EILSEQ:
112 errmsg = "CRC/Timeout (could be anything)";
113 break;
114 case -ETIME:
115 errmsg = "Device does not respond";
116 break;
117 }
118 if (packet < 0) {
119 dprintk(1, "URB status %d [%s].\n", status, errmsg);
120 } else {
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300121 dprintk(1, "URB packet %d, status %d [%s].\n",
122 packet, status, errmsg);
Aidan Thornton3421b772008-04-17 21:40:36 -0300123 }
124}
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300125
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300126static inline int em28xx_dvb_isoc_copy(struct em28xx *dev, struct urb *urb)
Aidan Thornton3421b772008-04-17 21:40:36 -0300127{
128 int i;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300129
Aidan Thornton3421b772008-04-17 21:40:36 -0300130 if (!dev)
131 return 0;
132
133 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
134 return 0;
135
136 if (urb->status < 0) {
137 print_err_status(dev, -1, urb->status);
138 if (urb->status == -ENOENT)
139 return 0;
140 }
141
142 for (i = 0; i < urb->number_of_packets; i++) {
143 int status = urb->iso_frame_desc[i].status;
144
145 if (status < 0) {
146 print_err_status(dev, i, status);
147 if (urb->iso_frame_desc[i].status != -EPROTO)
148 continue;
149 }
150
151 dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer +
152 urb->iso_frame_desc[i].offset,
153 urb->iso_frame_desc[i].actual_length);
154 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300155
156 return 0;
157}
158
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300159static int em28xx_start_streaming(struct em28xx_dvb *dvb)
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300160{
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300161 int rc;
Aidan Thornton3421b772008-04-17 21:40:36 -0300162 struct em28xx *dev = dvb->adapter.priv;
Devin Heitmuellerd18e2fd2009-05-16 17:09:28 -0300163 int max_dvb_packet_size;
Aidan Thornton3421b772008-04-17 21:40:36 -0300164
Holger Nelson8ab33622011-12-28 18:55:41 -0300165 usb_set_interface(dev->udev, 0, dev->dvb_alt);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300166 rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
167 if (rc < 0)
168 return rc;
Aidan Thornton3421b772008-04-17 21:40:36 -0300169
Holger Nelson8ab33622011-12-28 18:55:41 -0300170 max_dvb_packet_size = dev->dvb_max_pkt_size;
Mauro Carvalho Chehabf7acc4b2011-07-28 15:42:00 -0300171 if (max_dvb_packet_size < 0)
172 return max_dvb_packet_size;
Gianluca Gennari86d38d12012-02-13 13:59:22 -0300173 dprintk(1, "Using %d buffers each with %d x %d bytes\n",
Mauro Carvalho Chehabf7acc4b2011-07-28 15:42:00 -0300174 EM28XX_DVB_NUM_BUFS,
Gianluca Gennari86d38d12012-02-13 13:59:22 -0300175 EM28XX_DVB_MAX_PACKETS,
Mauro Carvalho Chehabf7acc4b2011-07-28 15:42:00 -0300176 max_dvb_packet_size);
Devin Heitmuellerd18e2fd2009-05-16 17:09:28 -0300177
Gianluca Gennari86d38d12012-02-13 13:59:22 -0300178 return em28xx_init_isoc(dev, EM28XX_DIGITAL_MODE,
179 EM28XX_DVB_MAX_PACKETS, EM28XX_DVB_NUM_BUFS,
180 max_dvb_packet_size, em28xx_dvb_isoc_copy);
Aidan Thornton3421b772008-04-17 21:40:36 -0300181}
182
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300183static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300184{
Aidan Thornton3421b772008-04-17 21:40:36 -0300185 struct em28xx *dev = dvb->adapter.priv;
186
Gianluca Gennari5f5f1472012-03-22 08:48:17 -0300187 em28xx_stop_urbs(dev);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300188
Mauro Carvalho Chehab2fe3e2e2008-11-27 09:10:40 -0300189 em28xx_set_mode(dev, EM28XX_SUSPEND);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300190
Aidan Thornton3421b772008-04-17 21:40:36 -0300191 return 0;
192}
193
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300194static int em28xx_start_feed(struct dvb_demux_feed *feed)
Aidan Thornton3421b772008-04-17 21:40:36 -0300195{
196 struct dvb_demux *demux = feed->demux;
197 struct em28xx_dvb *dvb = demux->priv;
198 int rc, ret;
199
200 if (!demux->dmx.frontend)
201 return -EINVAL;
202
203 mutex_lock(&dvb->lock);
204 dvb->nfeeds++;
205 rc = dvb->nfeeds;
206
207 if (dvb->nfeeds == 1) {
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300208 ret = em28xx_start_streaming(dvb);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300209 if (ret < 0)
210 rc = ret;
Aidan Thornton3421b772008-04-17 21:40:36 -0300211 }
212
213 mutex_unlock(&dvb->lock);
214 return rc;
215}
216
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300217static int em28xx_stop_feed(struct dvb_demux_feed *feed)
Aidan Thornton3421b772008-04-17 21:40:36 -0300218{
219 struct dvb_demux *demux = feed->demux;
220 struct em28xx_dvb *dvb = demux->priv;
221 int err = 0;
222
223 mutex_lock(&dvb->lock);
224 dvb->nfeeds--;
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300225
226 if (0 == dvb->nfeeds)
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300227 err = em28xx_stop_streaming(dvb);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300228
Aidan Thornton3421b772008-04-17 21:40:36 -0300229 mutex_unlock(&dvb->lock);
230 return err;
231}
232
233
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300234
235/* ------------------------------------------------------------------ */
236static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
237{
238 struct em28xx *dev = fe->dvb->priv;
239
240 if (acquire)
241 return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
242 else
Mauro Carvalho Chehab2fe3e2e2008-11-27 09:10:40 -0300243 return em28xx_set_mode(dev, EM28XX_SUSPEND);
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300244}
245
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300246/* ------------------------------------------------------------------ */
247
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -0300248static struct lgdt330x_config em2880_lgdt3303_dev = {
249 .demod_address = 0x0e,
250 .demod_chip = LGDT3303,
251};
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300252
Jarod Wilson7e48b302010-03-07 17:55:43 -0300253static struct lgdt3305_config em2870_lgdt3304_dev = {
254 .i2c_addr = 0x0e,
255 .demod_chip = LGDT3304,
256 .spectral_inversion = 1,
257 .deny_i2c_rptr = 1,
258 .mpeg_mode = LGDT3305_MPEG_PARALLEL,
259 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
260 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
261 .vsb_if_khz = 3250,
262 .qam_if_khz = 4000,
263};
264
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300265static struct s921_config sharp_isdbt = {
266 .demod_address = 0x30 >> 1
267};
268
Aidan Thornton7e6388a2008-04-17 21:40:03 -0300269static struct zl10353_config em28xx_zl10353_with_xc3028 = {
270 .demod_address = (0x1e >> 1),
271 .no_tuner = 1,
272 .parallel_ts = 1,
273 .if2 = 45600,
274};
275
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300276static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
277 .demod_address = 0x32 >> 1,
278 .output_mode = S5H1409_PARALLEL_OUTPUT,
279 .gpio = S5H1409_GPIO_OFF,
280 .inversion = S5H1409_INVERSION_OFF,
281 .status_mode = S5H1409_DEMODLOCKING,
282 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
283};
284
Jarod Wilson7e48b302010-03-07 17:55:43 -0300285static struct tda18271_std_map kworld_a340_std_map = {
286 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
287 .if_lvl = 1, .rfagc_top = 0x37, },
288 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
289 .if_lvl = 1, .rfagc_top = 0x37, },
290};
291
292static struct tda18271_config kworld_a340_config = {
293 .std_map = &kworld_a340_std_map,
294};
295
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300296static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300297 .demod_address = (0x1e >> 1),
298 .no_tuner = 1,
299 .disable_i2c_gate_ctrl = 1,
300 .parallel_ts = 1,
301 .if2 = 45600,
302};
303
Devin Heitmueller75e2b862011-03-13 02:01:02 -0300304static struct drxd_config em28xx_drxd = {
Mauro Carvalho Chehabaac865f2011-12-26 09:41:14 -0300305 .demod_address = 0x70,
306 .demod_revision = 0xa2,
307 .pll_type = DRXD_PLL_NONE,
308 .clock = 12000,
309 .insert_rs_byte = 1,
310 .IF = 42800000,
Devin Heitmueller6b142b32011-03-13 02:02:01 -0300311 .disable_i2c_gate_ctrl = 1,
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300312};
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300313
Ezequiel García61bdbef2012-06-12 09:53:41 -0300314static struct drxk_config terratec_h5_drxk = {
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300315 .adr = 0x29,
Mauro Carvalho Chehabe4f4f872011-07-09 17:35:26 -0300316 .single_master = 1,
Mauro Carvalho Chehabf1fe1b72011-07-09 21:59:33 -0300317 .no_i2c_bridge = 1,
Mauro Carvalho Chehab8b9456a2011-07-11 14:33:51 -0300318 .microcode_name = "dvb-usb-terratec-h5-drxk.fw",
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300319 .qam_demod_parameter_count = 2,
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300320};
321
Ezequiel García61bdbef2012-06-12 09:53:41 -0300322static struct drxk_config hauppauge_930c_drxk = {
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300323 .adr = 0x29,
324 .single_master = 1,
325 .no_i2c_bridge = 1,
326 .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
327 .chunk_size = 56,
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300328 .qam_demod_parameter_count = 2,
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300329};
330
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300331struct drxk_config terratec_htc_stick_drxk = {
332 .adr = 0x29,
333 .single_master = 1,
334 .no_i2c_bridge = 1,
335 .microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw",
336 .chunk_size = 54,
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300337 .qam_demod_parameter_count = 2,
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300338 /* Required for the antenna_gpio to disable LNA. */
339 .antenna_dvbt = true,
340 /* The windows driver uses the same. This will disable LNA. */
341 .antenna_gpio = 0x6,
342};
343
Ezequiel García61bdbef2012-06-12 09:53:41 -0300344static struct drxk_config maxmedia_ub425_tc_drxk = {
Antti Palosaari35530852012-03-18 18:09:01 -0300345 .adr = 0x29,
346 .single_master = 1,
347 .no_i2c_bridge = 1,
348};
349
Ezequiel García61bdbef2012-06-12 09:53:41 -0300350static struct drxk_config pctv_520e_drxk = {
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300351 .adr = 0x29,
352 .single_master = 1,
353 .microcode_name = "dvb-demod-drxk-pctv.fw",
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300354 .qam_demod_parameter_count = 2,
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300355 .chunk_size = 58,
Antti Palosaarif6f379d2012-05-17 19:09:06 -0300356 .antenna_dvbt = true, /* disable LNA */
357 .antenna_gpio = (1 << 2), /* disable LNA */
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300358};
359
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300360static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
361{
362 struct em28xx_dvb *dvb = fe->sec_priv;
363 int status;
364
365 if (!dvb)
366 return -EINVAL;
367
368 if (enable) {
369 down(&dvb->pll_mutex);
370 status = dvb->gate_ctrl(fe, 1);
371 } else {
372 status = dvb->gate_ctrl(fe, 0);
373 up(&dvb->pll_mutex);
374 }
375 return status;
376}
377
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300378static void hauppauge_hvr930c_init(struct em28xx *dev)
379{
380 int i;
381
382 struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -0200383 {EM2874_R80_GPIO, 0xff, 0xff, 0x65},
384 {EM2874_R80_GPIO, 0xfb, 0xff, 0x32},
385 {EM2874_R80_GPIO, 0xff, 0xff, 0xb8},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300386 { -1, -1, -1, -1},
387 };
388 struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -0200389 {EM2874_R80_GPIO, 0xef, 0xff, 0x01},
390 {EM2874_R80_GPIO, 0xaf, 0xff, 0x65},
391 {EM2874_R80_GPIO, 0xef, 0xff, 0x76},
392 {EM2874_R80_GPIO, 0xef, 0xff, 0x01},
393 {EM2874_R80_GPIO, 0xcf, 0xff, 0x0b},
394 {EM2874_R80_GPIO, 0xef, 0xff, 0x40},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300395
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -0200396 {EM2874_R80_GPIO, 0xcf, 0xff, 0x65},
397 {EM2874_R80_GPIO, 0xef, 0xff, 0x65},
398 {EM2874_R80_GPIO, 0xcf, 0xff, 0x0b},
399 {EM2874_R80_GPIO, 0xef, 0xff, 0x65},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300400
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300401 { -1, -1, -1, -1},
402 };
403
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300404 struct {
405 unsigned char r[4];
406 int len;
407 } regs[] = {
408 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
409 {{ 0x01, 0x02 }, 2},
410 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
411 {{ 0x01, 0x00 }, 2},
412 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
413 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
414 {{ 0x01, 0x00 }, 2},
415 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
416 {{ 0x04, 0x00 }, 2},
417 {{ 0x00, 0x04 }, 2},
418 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
419 {{ 0x04, 0x14 }, 2},
420 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
421 };
422
423 em28xx_gpio_set(dev, hauppauge_hvr930c_init);
424 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
425 msleep(10);
426 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
427 msleep(10);
428
429 dev->i2c_client.addr = 0x82 >> 1;
430
431 for (i = 0; i < ARRAY_SIZE(regs); i++)
432 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
433 em28xx_gpio_set(dev, hauppauge_hvr930c_end);
434
435 msleep(100);
436
437 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
438 msleep(30);
439
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300440 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
441 msleep(10);
442
443}
444
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300445static void terratec_h5_init(struct em28xx *dev)
446{
447 int i;
448 struct em28xx_reg_seq terratec_h5_init[] = {
449 {EM28XX_R08_GPIO, 0xff, 0xff, 10},
450 {EM2874_R80_GPIO, 0xf6, 0xff, 100},
451 {EM2874_R80_GPIO, 0xf2, 0xff, 50},
452 {EM2874_R80_GPIO, 0xf6, 0xff, 100},
453 { -1, -1, -1, -1},
454 };
455 struct em28xx_reg_seq terratec_h5_end[] = {
456 {EM2874_R80_GPIO, 0xe6, 0xff, 100},
457 {EM2874_R80_GPIO, 0xa6, 0xff, 50},
458 {EM2874_R80_GPIO, 0xe6, 0xff, 100},
459 { -1, -1, -1, -1},
460 };
461 struct {
462 unsigned char r[4];
463 int len;
464 } regs[] = {
465 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
466 {{ 0x01, 0x02 }, 2},
467 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
468 {{ 0x01, 0x00 }, 2},
469 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
470 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
471 {{ 0x01, 0x00 }, 2},
472 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
473 {{ 0x04, 0x00 }, 2},
474 {{ 0x00, 0x04 }, 2},
475 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
476 {{ 0x04, 0x14 }, 2},
477 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
478 };
479
480 em28xx_gpio_set(dev, terratec_h5_init);
481 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
482 msleep(10);
483 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
484 msleep(10);
485
486 dev->i2c_client.addr = 0x82 >> 1;
487
488 for (i = 0; i < ARRAY_SIZE(regs); i++)
489 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
490 em28xx_gpio_set(dev, terratec_h5_end);
491};
492
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300493static void terratec_htc_stick_init(struct em28xx *dev)
494{
495 int i;
496
497 /*
498 * GPIO configuration:
499 * 0xff: unknown (does not affect DVB-T).
500 * 0xf6: DRX-K (demodulator).
501 * 0xe6: unknown (does not affect DVB-T).
502 * 0xb6: unknown (does not affect DVB-T).
503 */
504 struct em28xx_reg_seq terratec_htc_stick_init[] = {
505 {EM28XX_R08_GPIO, 0xff, 0xff, 10},
506 {EM2874_R80_GPIO, 0xf6, 0xff, 100},
507 {EM2874_R80_GPIO, 0xe6, 0xff, 50},
508 {EM2874_R80_GPIO, 0xf6, 0xff, 100},
509 { -1, -1, -1, -1},
510 };
511 struct em28xx_reg_seq terratec_htc_stick_end[] = {
512 {EM2874_R80_GPIO, 0xb6, 0xff, 100},
513 {EM2874_R80_GPIO, 0xf6, 0xff, 50},
514 { -1, -1, -1, -1},
515 };
516
517 /* Init the analog decoder? */
518 struct {
519 unsigned char r[4];
520 int len;
521 } regs[] = {
522 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
523 {{ 0x01, 0x02 }, 2},
524 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
525 {{ 0x01, 0x00 }, 2},
526 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
527 };
528
529 em28xx_gpio_set(dev, terratec_htc_stick_init);
530
531 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
532 msleep(10);
533 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
534 msleep(10);
535
536 dev->i2c_client.addr = 0x82 >> 1;
537
538 for (i = 0; i < ARRAY_SIZE(regs); i++)
539 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
540
541 em28xx_gpio_set(dev, terratec_htc_stick_end);
542};
543
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300544static void pctv_520e_init(struct em28xx *dev)
545{
546 /*
Antti Palosaari26c8a722012-05-17 18:22:02 -0300547 * Init AVF4910B analog decoder. Looks like I2C traffic to
548 * digital demodulator and tuner are routed via AVF4910B.
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300549 */
550 int i;
551 struct {
552 unsigned char r[4];
553 int len;
554 } regs[] = {
555 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
556 {{ 0x01, 0x02 }, 2},
557 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
558 {{ 0x01, 0x00 }, 2},
559 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
560 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
561 {{ 0x01, 0x00 }, 2},
562 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
563 };
564
565 dev->i2c_client.addr = 0x82 >> 1; /* 0x41 */
566
567 for (i = 0; i < ARRAY_SIZE(regs); i++)
568 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
569};
570
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300571static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300572{
573 /* Values extracted from a USB trace of the Terratec Windows driver */
574 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
575 static u8 reset[] = { RESET, 0x80 };
576 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
577 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
578 static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
579 static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
580 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
581 static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
582 static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
Devin Heitmuellerff697862009-07-12 18:44:19 -0300583 static u8 tuner_go[] = { TUNER_GO, 0x01};
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300584
585 mt352_write(fe, clock_config, sizeof(clock_config));
586 udelay(200);
587 mt352_write(fe, reset, sizeof(reset));
588 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
589 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
590 mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
591 mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
592 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
593 mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
594 mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
595 mt352_write(fe, tuner_go, sizeof(tuner_go));
596 return 0;
597}
598
599static struct mt352_config terratec_xs_mt352_cfg = {
600 .demod_address = (0x1e >> 1),
601 .no_tuner = 1,
602 .if2 = 45600,
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300603 .demod_init = em28xx_mt352_terratec_xs_init,
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300604};
605
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300606static struct tda10023_config em28xx_tda10023_config = {
607 .demod_address = 0x0c,
608 .invert = 1,
609};
610
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300611static struct cxd2820r_config em28xx_cxd2820r_config = {
612 .i2c_address = (0xd8 >> 1),
613 .ts_mode = CXD2820R_TS_SERIAL,
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300614};
615
616static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
617 .output_opt = TDA18271_OUTPUT_LT_OFF,
Steve Kerrison0db4bf42011-08-09 07:16:21 -0300618 .gate = TDA18271_GATE_DIGITAL,
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300619};
620
Antti Palosaari36588712011-08-01 01:15:30 -0300621static const struct tda10071_config em28xx_tda10071_config = {
622 .i2c_address = 0x55, /* (0xaa >> 1) */
623 .i2c_wr_max = 64,
624 .ts_mode = TDA10071_TS_SERIAL,
625 .spec_inv = 0,
626 .xtal = 40444000, /* 40.444 MHz */
627 .pll_multiplier = 20,
628};
629
630static const struct a8293_config em28xx_a8293_config = {
631 .i2c_addr = 0x08, /* (0x10 >> 1) */
632};
633
Aivar Päkk1985f6f2011-12-11 18:15:00 -0300634static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
635 .demod_address = (0x1e >> 1),
636 .disable_i2c_gate_ctrl = 1,
637 .no_tuner = 1,
638 .parallel_ts = 1,
639};
640static struct qt1010_config em28xx_qt1010_config = {
641 .i2c_address = 0x62
642
643};
644
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300645/* ------------------------------------------------------------------ */
646
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300647static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300648{
649 struct dvb_frontend *fe;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300650 struct xc2028_config cfg;
651
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300652 memset(&cfg, 0, sizeof(cfg));
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300653 cfg.i2c_adap = &dev->i2c_adap;
654 cfg.i2c_addr = addr;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300655
Antti Palosaarif71095b2011-04-07 15:51:52 -0300656 if (!dev->dvb->fe[0]) {
Filipe Rosset480be182009-11-04 15:32:37 -0300657 em28xx_errdev("/2: dvb frontend not attached. "
658 "Can't attach xc3028\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300659 return -EINVAL;
660 }
661
Antti Palosaarif71095b2011-04-07 15:51:52 -0300662 fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300663 if (!fe) {
Filipe Rosset480be182009-11-04 15:32:37 -0300664 em28xx_errdev("/2: xc3028 attach failed\n");
Antti Palosaarif71095b2011-04-07 15:51:52 -0300665 dvb_frontend_detach(dev->dvb->fe[0]);
666 dev->dvb->fe[0] = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300667 return -EINVAL;
668 }
669
Filipe Rosset480be182009-11-04 15:32:37 -0300670 em28xx_info("%s/2: xc3028 attached\n", dev->name);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300671
672 return 0;
673}
674
Aidan Thornton3421b772008-04-17 21:40:36 -0300675/* ------------------------------------------------------------------ */
676
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300677static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
678 struct em28xx *dev, struct device *device)
Aidan Thornton3421b772008-04-17 21:40:36 -0300679{
680 int result;
681
682 mutex_init(&dvb->lock);
683
684 /* register adapter */
685 result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
686 adapter_nr);
687 if (result < 0) {
688 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
689 dev->name, result);
690 goto fail_adapter;
691 }
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300692
693 /* Ensure all frontends negotiate bus access */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300694 dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
695 if (dvb->fe[1])
696 dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300697
Aidan Thornton3421b772008-04-17 21:40:36 -0300698 dvb->adapter.priv = dev;
699
700 /* register frontend */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300701 result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300702 if (result < 0) {
703 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
704 dev->name, result);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300705 goto fail_frontend0;
706 }
707
708 /* register 2nd frontend */
709 if (dvb->fe[1]) {
710 result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
711 if (result < 0) {
712 printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
713 dev->name, result);
714 goto fail_frontend1;
715 }
Aidan Thornton3421b772008-04-17 21:40:36 -0300716 }
717
718 /* register demux stuff */
719 dvb->demux.dmx.capabilities =
720 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
721 DMX_MEMORY_BASED_FILTERING;
722 dvb->demux.priv = dvb;
723 dvb->demux.filternum = 256;
724 dvb->demux.feednum = 256;
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300725 dvb->demux.start_feed = em28xx_start_feed;
726 dvb->demux.stop_feed = em28xx_stop_feed;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300727
Aidan Thornton3421b772008-04-17 21:40:36 -0300728 result = dvb_dmx_init(&dvb->demux);
729 if (result < 0) {
730 printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
731 dev->name, result);
732 goto fail_dmx;
733 }
734
735 dvb->dmxdev.filternum = 256;
736 dvb->dmxdev.demux = &dvb->demux.dmx;
737 dvb->dmxdev.capabilities = 0;
738 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
739 if (result < 0) {
740 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
741 dev->name, result);
742 goto fail_dmxdev;
743 }
744
745 dvb->fe_hw.source = DMX_FRONTEND_0;
746 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
747 if (result < 0) {
748 printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
749 dev->name, result);
750 goto fail_fe_hw;
751 }
752
753 dvb->fe_mem.source = DMX_MEMORY_FE;
754 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
755 if (result < 0) {
756 printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
757 dev->name, result);
758 goto fail_fe_mem;
759 }
760
761 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
762 if (result < 0) {
763 printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
764 dev->name, result);
765 goto fail_fe_conn;
766 }
767
768 /* register network adapter */
769 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
770 return 0;
771
772fail_fe_conn:
773 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
774fail_fe_mem:
775 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
776fail_fe_hw:
777 dvb_dmxdev_release(&dvb->dmxdev);
778fail_dmxdev:
779 dvb_dmx_release(&dvb->demux);
780fail_dmx:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300781 if (dvb->fe[1])
782 dvb_unregister_frontend(dvb->fe[1]);
783 dvb_unregister_frontend(dvb->fe[0]);
784fail_frontend1:
785 if (dvb->fe[1])
786 dvb_frontend_detach(dvb->fe[1]);
787fail_frontend0:
788 dvb_frontend_detach(dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300789 dvb_unregister_adapter(&dvb->adapter);
790fail_adapter:
791 return result;
792}
793
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300794static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
Aidan Thornton3421b772008-04-17 21:40:36 -0300795{
796 dvb_net_release(&dvb->net);
797 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
798 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
799 dvb_dmxdev_release(&dvb->dmxdev);
800 dvb_dmx_release(&dvb->demux);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300801 if (dvb->fe[1])
802 dvb_unregister_frontend(dvb->fe[1]);
803 dvb_unregister_frontend(dvb->fe[0]);
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -0300804 if (dvb->fe[1] && !dvb->dont_attach_fe1)
Antti Palosaarif71095b2011-04-07 15:51:52 -0300805 dvb_frontend_detach(dvb->fe[1]);
806 dvb_frontend_detach(dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300807 dvb_unregister_adapter(&dvb->adapter);
808}
809
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300810static int em28xx_dvb_init(struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300811{
Antti Palosaari1e8f31f2012-07-19 21:10:36 -0300812 int result = 0, mfe_shared = 0, gpio_chip_base;
Aidan Thornton3421b772008-04-17 21:40:36 -0300813 struct em28xx_dvb *dvb;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300814
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -0300815 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -0300816 /* This device does not support the extension */
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300817 printk(KERN_INFO "em28xx_dvb: This device does not support the extension\n");
Devin Heitmuellerdf619182008-06-10 12:34:35 -0300818 return 0;
819 }
820
Aidan Thornton3421b772008-04-17 21:40:36 -0300821 dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300822
823 if (dvb == NULL) {
Filipe Rosset480be182009-11-04 15:32:37 -0300824 em28xx_info("em28xx_dvb: memory allocation failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -0300825 return -ENOMEM;
826 }
827 dev->dvb = dvb;
Antti Palosaarif71095b2011-04-07 15:51:52 -0300828 dvb->fe[0] = dvb->fe[1] = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300829
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -0300830 mutex_lock(&dev->lock);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300831 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300832 /* init frontend */
833 switch (dev->model) {
Mauro Carvalho Chehabebaefdb2011-06-01 10:16:25 -0300834 case EM2874_BOARD_LEADERSHIP_ISDBT:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300835 dvb->fe[0] = dvb_attach(s921_attach,
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300836 &sharp_isdbt, &dev->i2c_adap);
837
Antti Palosaarif71095b2011-04-07 15:51:52 -0300838 if (!dvb->fe[0]) {
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300839 result = -EINVAL;
840 goto out_free;
841 }
842
843 break;
Douglas Schilling Landgraff89bc322008-12-01 21:01:04 -0300844 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
Mauro Carvalho Chehab10ac6602008-07-27 14:58:58 -0300845 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
Devin Heitmueller4fd305b2008-06-04 13:43:46 -0300846 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
Devin Heitmuellere14b3652008-07-26 11:04:33 -0300847 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300848 dvb->fe[0] = dvb_attach(lgdt330x_attach,
Aidan Thornton3421b772008-04-17 21:40:36 -0300849 &em2880_lgdt3303_dev,
850 &dev->i2c_adap);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300851 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Aidan Thornton3421b772008-04-17 21:40:36 -0300852 result = -EINVAL;
853 goto out_free;
854 }
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -0300855 break;
Thierry MERLE46510b52008-10-11 16:56:13 -0300856 case EM2880_BOARD_KWORLD_DVB_310U:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300857 dvb->fe[0] = dvb_attach(zl10353_attach,
Aidan Thornton3421b772008-04-17 21:40:36 -0300858 &em28xx_zl10353_with_xc3028,
859 &dev->i2c_adap);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300860 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Aidan Thornton3421b772008-04-17 21:40:36 -0300861 result = -EINVAL;
862 goto out_free;
863 }
Aidan Thornton7e6388a2008-04-17 21:40:03 -0300864 break;
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300865 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
Uroš Vamplec994d02009-09-30 22:53:37 -0300866 case EM2882_BOARD_TERRATEC_HYBRID_XS:
Devin Heitmueller01a5fd62009-08-07 09:25:06 -0300867 case EM2880_BOARD_EMPIRE_DUAL_TV:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300868 dvb->fe[0] = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300869 &em28xx_zl10353_xc3028_no_i2c_gate,
870 &dev->i2c_adap);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300871 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300872 result = -EINVAL;
873 goto out_free;
874 }
875 break;
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300876 case EM2880_BOARD_TERRATEC_HYBRID_XS:
Catimimi65638012010-02-18 18:06:32 -0300877 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
Devin Heitmuellerd5b3ba92009-07-08 21:51:35 -0300878 case EM2881_BOARD_PINNACLE_HYBRID_PRO:
Andrea.Amorosi76@gmail.com7ca7ef62010-02-09 17:53:38 -0300879 case EM2882_BOARD_DIKOM_DK300:
Antonio Larrosa811fab62010-03-04 22:19:48 -0300880 case EM2882_BOARD_KWORLD_VS_DVBT:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300881 dvb->fe[0] = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300882 &em28xx_zl10353_xc3028_no_i2c_gate,
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300883 &dev->i2c_adap);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300884 if (dvb->fe[0] == NULL) {
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300885 /* This board could have either a zl10353 or a mt352.
886 If the chip id isn't for zl10353, try mt352 */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300887 dvb->fe[0] = dvb_attach(mt352_attach,
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300888 &terratec_xs_mt352_cfg,
889 &dev->i2c_adap);
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300890 }
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300891
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300892 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300893 result = -EINVAL;
894 goto out_free;
895 }
896 break;
Aivar Päkk1985f6f2011-12-11 18:15:00 -0300897 case EM2870_BOARD_KWORLD_355U:
898 dvb->fe[0] = dvb_attach(zl10353_attach,
899 &em28xx_zl10353_no_i2c_gate_dev,
900 &dev->i2c_adap);
901 if (dvb->fe[0] != NULL)
902 dvb_attach(qt1010_attach, dvb->fe[0],
903 &dev->i2c_adap, &em28xx_qt1010_config);
904 break;
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300905 case EM2883_BOARD_KWORLD_HYBRID_330U:
Devin Heitmueller19859222009-06-19 00:33:54 -0300906 case EM2882_BOARD_EVGA_INDTUBE:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300907 dvb->fe[0] = dvb_attach(s5h1409_attach,
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300908 &em28xx_s5h1409_with_xc3028,
909 &dev->i2c_adap);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300910 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300911 result = -EINVAL;
912 goto out_free;
913 }
914 break;
Franklin Mengd7de5d82009-06-06 17:05:02 -0300915 case EM2882_BOARD_KWORLD_ATSC_315U:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300916 dvb->fe[0] = dvb_attach(lgdt330x_attach,
Franklin Mengd7de5d82009-06-06 17:05:02 -0300917 &em2880_lgdt3303_dev,
918 &dev->i2c_adap);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300919 if (dvb->fe[0] != NULL) {
920 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
Franklin Mengd7de5d82009-06-06 17:05:02 -0300921 &dev->i2c_adap, 0x61, TUNER_THOMSON_DTT761X)) {
922 result = -EINVAL;
923 goto out_free;
924 }
925 }
926 break;
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300927 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
Devin Heitmuellerad9b4bb2011-03-13 02:09:59 -0300928 case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300929 dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
Devin Heitmueller75e2b862011-03-13 02:01:02 -0300930 &dev->i2c_adap, &dev->udev->dev);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300931 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300932 result = -EINVAL;
933 goto out_free;
934 }
935 break;
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300936 case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
937 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300938 dvb->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300939 &em28xx_tda10023_config,
940 &dev->i2c_adap, 0x48);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300941 if (dvb->fe[0]) {
942 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300943 &dev->i2c_adap, 0x60, TUNER_PHILIPS_CU1216L)) {
944 result = -EINVAL;
945 goto out_free;
946 }
947 }
948 break;
Jarod Wilson7e48b302010-03-07 17:55:43 -0300949 case EM2870_BOARD_KWORLD_A340:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300950 dvb->fe[0] = dvb_attach(lgdt3305_attach,
Jarod Wilson7e48b302010-03-07 17:55:43 -0300951 &em2870_lgdt3304_dev,
952 &dev->i2c_adap);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300953 if (dvb->fe[0] != NULL)
954 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Jarod Wilson7e48b302010-03-07 17:55:43 -0300955 &dev->i2c_adap, &kworld_a340_config);
956 break;
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300957 case EM28174_BOARD_PCTV_290E:
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300958 dvb->fe[0] = dvb_attach(cxd2820r_attach,
Manu Abraham7e7b8282011-12-10 00:44:24 -0300959 &em28xx_cxd2820r_config,
Antti Palosaari1e8f31f2012-07-19 21:10:36 -0300960 &dev->i2c_adap,
961 &gpio_chip_base);
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300962 if (dvb->fe[0]) {
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300963 /* FE 0 attach tuner */
Manu Abraham7e7b8282011-12-10 00:44:24 -0300964 if (!dvb_attach(tda18271_attach,
965 dvb->fe[0],
966 0x60,
967 &dev->i2c_adap,
968 &em28xx_cxd2820r_tda18271_config)) {
969
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300970 dvb_frontend_detach(dvb->fe[0]);
971 result = -EINVAL;
972 goto out_free;
973 }
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300974 }
Antti Palosaari1e8f31f2012-07-19 21:10:36 -0300975
976 /* enable LNA for DVB-T, DVB-T2 and DVB-C */
977 result = gpio_request_one(gpio_chip_base, GPIOF_INIT_LOW,
978 "LNA");
979 if (result)
980 em28xx_errdev("gpio request failed %d\n", result);
981 else
982 gpio_free(gpio_chip_base);
983
984 result = 0; /* continue even set LNA fails */
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300985 break;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300986 case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
Mauro Carvalho Chehab85032322011-11-24 15:01:45 -0200987 {
988 struct xc5000_config cfg;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300989 hauppauge_hvr930c_init(dev);
990
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -0200991 dvb->fe[0] = dvb_attach(drxk_attach,
Mauro Carvalho Chehabfa4b2a12012-01-05 08:07:32 -0200992 &hauppauge_930c_drxk, &dev->i2c_adap);
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300993 if (!dvb->fe[0]) {
994 result = -EINVAL;
995 goto out_free;
996 }
997 /* FIXME: do we need a pll semaphore? */
998 dvb->fe[0]->sec_priv = dvb;
999 sema_init(&dvb->pll_mutex, 1);
1000 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1001 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001002
1003 /* Attach xc5000 */
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001004 memset(&cfg, 0, sizeof(cfg));
1005 cfg.i2c_address = 0x61;
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001006 cfg.if_khz = 4000;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001007
1008 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1009 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001010 if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap,
1011 &cfg)) {
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001012 result = -EINVAL;
1013 goto out_free;
1014 }
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001015 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1016 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1017
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001018 break;
Mauro Carvalho Chehab85032322011-11-24 15:01:45 -02001019 }
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001020 case EM2884_BOARD_TERRATEC_H5:
1021 terratec_h5_init(dev);
1022
Mauro Carvalho Chehabfa4b2a12012-01-05 08:07:32 -02001023 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap);
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -03001024 if (!dvb->fe[0]) {
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001025 result = -EINVAL;
1026 goto out_free;
1027 }
1028 /* FIXME: do we need a pll semaphore? */
1029 dvb->fe[0]->sec_priv = dvb;
1030 sema_init(&dvb->pll_mutex, 1);
1031 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1032 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001033
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -03001034 /* Attach tda18271 to DVB-C frontend */
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001035 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1036 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1037 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap, 0x60)) {
1038 result = -EINVAL;
1039 goto out_free;
1040 }
1041 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1042 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -03001043
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001044 break;
Antti Palosaari36588712011-08-01 01:15:30 -03001045 case EM28174_BOARD_PCTV_460E:
1046 /* attach demod */
1047 dvb->fe[0] = dvb_attach(tda10071_attach,
1048 &em28xx_tda10071_config, &dev->i2c_adap);
1049
1050 /* attach SEC */
1051 if (dvb->fe[0])
1052 dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap,
1053 &em28xx_a8293_config);
1054 break;
Antti Palosaari35530852012-03-18 18:09:01 -03001055 case EM2874_BOARD_MAXMEDIA_UB425_TC:
1056 /* attach demodulator */
1057 dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
1058 &dev->i2c_adap);
1059
1060 if (dvb->fe[0]) {
1061 /* disable I2C-gate */
1062 dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
1063
1064 /* attach tuner */
1065 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0],
1066 &dev->i2c_adap, 0x60)) {
1067 dvb_frontend_detach(dvb->fe[0]);
1068 result = -EINVAL;
1069 goto out_free;
1070 }
1071 }
1072
1073 /* TODO: we need drx-3913k firmware in order to support DVB-T */
1074 em28xx_info("MaxMedia UB425-TC: only DVB-C supported by that " \
1075 "driver version\n");
1076
1077 break;
Ivan Kalvachevfa5527c2012-03-19 20:09:55 -03001078 case EM2884_BOARD_PCTV_510E:
1079 case EM2884_BOARD_PCTV_520E:
1080 pctv_520e_init(dev);
1081
1082 /* attach demodulator */
1083 dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
1084 &dev->i2c_adap);
1085
1086 if (dvb->fe[0]) {
1087 /* attach tuner */
1088 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1089 &dev->i2c_adap,
1090 &em28xx_cxd2820r_tda18271_config)) {
1091 dvb_frontend_detach(dvb->fe[0]);
1092 result = -EINVAL;
1093 goto out_free;
1094 }
1095 }
1096 break;
Martin Blumenstinglc8dce002012-06-12 18:19:28 -03001097 case EM2884_BOARD_CINERGY_HTC_STICK:
1098 terratec_htc_stick_init(dev);
1099
1100 /* attach demodulator */
1101 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1102 &dev->i2c_adap);
1103 if (!dvb->fe[0]) {
1104 result = -EINVAL;
1105 goto out_free;
1106 }
1107
1108 /* Attach the demodulator. */
1109 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1110 &dev->i2c_adap,
1111 &em28xx_cxd2820r_tda18271_config)) {
1112 result = -EINVAL;
1113 goto out_free;
1114 }
1115 break;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001116 default:
Filipe Rosset480be182009-11-04 15:32:37 -03001117 em28xx_errdev("/2: The frontend of your DVB/ATSC card"
1118 " isn't supported yet\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001119 break;
1120 }
Antti Palosaarif71095b2011-04-07 15:51:52 -03001121 if (NULL == dvb->fe[0]) {
Filipe Rosset480be182009-11-04 15:32:37 -03001122 em28xx_errdev("/2: frontend initialization failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -03001123 result = -EINVAL;
1124 goto out_free;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001125 }
Michael Krufkyd7cba042008-09-12 13:31:45 -03001126 /* define general-purpose callback pointer */
Antti Palosaarif71095b2011-04-07 15:51:52 -03001127 dvb->fe[0]->callback = em28xx_tuner_callback;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001128 if (dvb->fe[1])
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001129 dvb->fe[1]->callback = em28xx_tuner_callback;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001130
1131 /* register everything */
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001132 result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
Aidan Thornton3421b772008-04-17 21:40:36 -03001133
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -03001134 if (result < 0)
Aidan Thornton3421b772008-04-17 21:40:36 -03001135 goto out_free;
Aidan Thornton3421b772008-04-17 21:40:36 -03001136
Antti Palosaarie3645432011-07-28 18:59:30 -03001137 /* MFE lock */
1138 dvb->adapter.mfe_shared = mfe_shared;
1139
Filipe Rosset480be182009-11-04 15:32:37 -03001140 em28xx_info("Successfully loaded em28xx-dvb\n");
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -03001141ret:
1142 em28xx_set_mode(dev, EM28XX_SUSPEND);
1143 mutex_unlock(&dev->lock);
1144 return result;
Aidan Thornton3421b772008-04-17 21:40:36 -03001145
1146out_free:
1147 kfree(dvb);
1148 dev->dvb = NULL;
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -03001149 goto ret;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001150}
1151
Chris Rankin0b8bd832011-08-20 16:01:26 -03001152static inline void prevent_sleep(struct dvb_frontend_ops *ops)
1153{
1154 ops->set_voltage = NULL;
1155 ops->sleep = NULL;
1156 ops->tuner_ops.sleep = NULL;
1157}
1158
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001159static int em28xx_dvb_fini(struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001160{
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -03001161 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -03001162 /* This device does not support the extension */
1163 return 0;
1164 }
1165
Aidan Thornton3421b772008-04-17 21:40:36 -03001166 if (dev->dvb) {
Chris Rankin0b8bd832011-08-20 16:01:26 -03001167 struct em28xx_dvb *dvb = dev->dvb;
1168
1169 if (dev->state & DEV_DISCONNECTED) {
1170 /* We cannot tell the device to sleep
1171 * once it has been unplugged. */
1172 if (dvb->fe[0])
1173 prevent_sleep(&dvb->fe[0]->ops);
1174 if (dvb->fe[1])
1175 prevent_sleep(&dvb->fe[1]->ops);
1176 }
1177
1178 em28xx_unregister_dvb(dvb);
1179 kfree(dvb);
Aidan Thornton3421b772008-04-17 21:40:36 -03001180 dev->dvb = NULL;
1181 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001182
1183 return 0;
1184}
1185
1186static struct em28xx_ops dvb_ops = {
1187 .id = EM28XX_DVB,
1188 .name = "Em28xx dvb Extension",
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001189 .init = em28xx_dvb_init,
1190 .fini = em28xx_dvb_fini,
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001191};
1192
1193static int __init em28xx_dvb_register(void)
1194{
1195 return em28xx_register_extension(&dvb_ops);
1196}
1197
1198static void __exit em28xx_dvb_unregister(void)
1199{
1200 em28xx_unregister_extension(&dvb_ops);
1201}
1202
1203module_init(em28xx_dvb_register);
1204module_exit(em28xx_dvb_unregister);