blob: b0e5cbe1b40f0e341e9f37084145784e8dc5e2fd [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"
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030031
32#include "lgdt330x.h"
Jarod Wilson7e48b302010-03-07 17:55:43 -030033#include "lgdt3305.h"
Aidan Thornton7e6388a2008-04-17 21:40:03 -030034#include "zl10353.h"
Robert Krakora6e7b9ea2009-01-18 21:59:34 -030035#include "s5h1409.h"
Devin Heitmueller4fb202a2009-07-12 17:51:12 -030036#include "mt352.h"
37#include "mt352_priv.h" /* FIXME */
Antti Palosaari285eb1a2009-09-15 14:42:13 -030038#include "tda1002x.h"
Jarod Wilson7e48b302010-03-07 17:55:43 -030039#include "tda18271.h"
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -030040#include "s921.h"
Devin Heitmueller75e2b862011-03-13 02:01:02 -030041#include "drxd.h"
Antti Palosaarid6a5f922011-04-07 16:34:44 -030042#include "cxd2820r.h"
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -030043#include "tda18271c2dd.h"
44#include "drxk.h"
Antti Palosaari36588712011-08-01 01:15:30 -030045#include "tda10071.h"
46#include "a8293.h"
Aivar Päkk1985f6f2011-12-11 18:15:00 -030047#include "qt1010.h"
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030048
49MODULE_DESCRIPTION("driver for em28xx based DVB cards");
50MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
51MODULE_LICENSE("GPL");
52
53static unsigned int debug;
54module_param(debug, int, 0644);
55MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
56
57DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
58
59#define dprintk(level, fmt, arg...) do { \
60if (debug >= level) \
Aidan Thornton3421b772008-04-17 21:40:36 -030061 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030062} while (0)
63
Aidan Thornton3421b772008-04-17 21:40:36 -030064#define EM28XX_DVB_NUM_BUFS 5
Aidan Thornton3421b772008-04-17 21:40:36 -030065#define EM28XX_DVB_MAX_PACKETS 64
66
67struct em28xx_dvb {
Antti Palosaarif71095b2011-04-07 15:51:52 -030068 struct dvb_frontend *fe[2];
Aidan Thornton3421b772008-04-17 21:40:36 -030069
70 /* feed count management */
71 struct mutex lock;
72 int nfeeds;
73
74 /* general boilerplate stuff */
75 struct dvb_adapter adapter;
76 struct dvb_demux demux;
77 struct dmxdev dmxdev;
78 struct dmx_frontend fe_hw;
79 struct dmx_frontend fe_mem;
80 struct dvb_net net;
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -030081
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -030082 /* Due to DRX-K - probably need changes */
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -030083 int (*gate_ctrl)(struct dvb_frontend *, int);
84 struct semaphore pll_mutex;
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -030085 bool dont_attach_fe1;
Aidan Thornton3421b772008-04-17 21:40:36 -030086};
87
88
89static inline void print_err_status(struct em28xx *dev,
90 int packet, int status)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030091{
Aidan Thornton3421b772008-04-17 21:40:36 -030092 char *errmsg = "Unknown";
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030093
Aidan Thornton3421b772008-04-17 21:40:36 -030094 switch (status) {
95 case -ENOENT:
96 errmsg = "unlinked synchronuously";
97 break;
98 case -ECONNRESET:
99 errmsg = "unlinked asynchronuously";
100 break;
101 case -ENOSR:
102 errmsg = "Buffer error (overrun)";
103 break;
104 case -EPIPE:
105 errmsg = "Stalled (device not responding)";
106 break;
107 case -EOVERFLOW:
108 errmsg = "Babble (bad cable?)";
109 break;
110 case -EPROTO:
111 errmsg = "Bit-stuff error (bad cable?)";
112 break;
113 case -EILSEQ:
114 errmsg = "CRC/Timeout (could be anything)";
115 break;
116 case -ETIME:
117 errmsg = "Device does not respond";
118 break;
119 }
120 if (packet < 0) {
121 dprintk(1, "URB status %d [%s].\n", status, errmsg);
122 } else {
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300123 dprintk(1, "URB packet %d, status %d [%s].\n",
124 packet, status, errmsg);
Aidan Thornton3421b772008-04-17 21:40:36 -0300125 }
126}
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300127
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300128static inline int em28xx_dvb_isoc_copy(struct em28xx *dev, struct urb *urb)
Aidan Thornton3421b772008-04-17 21:40:36 -0300129{
130 int i;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300131
Aidan Thornton3421b772008-04-17 21:40:36 -0300132 if (!dev)
133 return 0;
134
135 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
136 return 0;
137
138 if (urb->status < 0) {
139 print_err_status(dev, -1, urb->status);
140 if (urb->status == -ENOENT)
141 return 0;
142 }
143
144 for (i = 0; i < urb->number_of_packets; i++) {
145 int status = urb->iso_frame_desc[i].status;
146
147 if (status < 0) {
148 print_err_status(dev, i, status);
149 if (urb->iso_frame_desc[i].status != -EPROTO)
150 continue;
151 }
152
153 dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer +
154 urb->iso_frame_desc[i].offset,
155 urb->iso_frame_desc[i].actual_length);
156 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300157
158 return 0;
159}
160
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300161static int em28xx_start_streaming(struct em28xx_dvb *dvb)
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300162{
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300163 int rc;
Aidan Thornton3421b772008-04-17 21:40:36 -0300164 struct em28xx *dev = dvb->adapter.priv;
Devin Heitmuellerd18e2fd2009-05-16 17:09:28 -0300165 int max_dvb_packet_size;
Aidan Thornton3421b772008-04-17 21:40:36 -0300166
167 usb_set_interface(dev->udev, 0, 1);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300168 rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
169 if (rc < 0)
170 return rc;
Aidan Thornton3421b772008-04-17 21:40:36 -0300171
Devin Heitmuellerd18e2fd2009-05-16 17:09:28 -0300172 max_dvb_packet_size = em28xx_isoc_dvb_max_packetsize(dev);
Mauro Carvalho Chehabf7acc4b2011-07-28 15:42:00 -0300173 if (max_dvb_packet_size < 0)
174 return max_dvb_packet_size;
175 dprintk(1, "Using %d buffers each with %d bytes\n",
176 EM28XX_DVB_NUM_BUFS,
177 max_dvb_packet_size);
Devin Heitmuellerd18e2fd2009-05-16 17:09:28 -0300178
Aidan Thornton3421b772008-04-17 21:40:36 -0300179 return em28xx_init_isoc(dev, EM28XX_DVB_MAX_PACKETS,
Devin Heitmuellerd18e2fd2009-05-16 17:09:28 -0300180 EM28XX_DVB_NUM_BUFS, max_dvb_packet_size,
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300181 em28xx_dvb_isoc_copy);
Aidan Thornton3421b772008-04-17 21:40:36 -0300182}
183
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300184static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300185{
Aidan Thornton3421b772008-04-17 21:40:36 -0300186 struct em28xx *dev = dvb->adapter.priv;
187
188 em28xx_uninit_isoc(dev);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300189
Mauro Carvalho Chehab2fe3e2e2008-11-27 09:10:40 -0300190 em28xx_set_mode(dev, EM28XX_SUSPEND);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300191
Aidan Thornton3421b772008-04-17 21:40:36 -0300192 return 0;
193}
194
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300195static int em28xx_start_feed(struct dvb_demux_feed *feed)
Aidan Thornton3421b772008-04-17 21:40:36 -0300196{
197 struct dvb_demux *demux = feed->demux;
198 struct em28xx_dvb *dvb = demux->priv;
199 int rc, ret;
200
201 if (!demux->dmx.frontend)
202 return -EINVAL;
203
204 mutex_lock(&dvb->lock);
205 dvb->nfeeds++;
206 rc = dvb->nfeeds;
207
208 if (dvb->nfeeds == 1) {
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300209 ret = em28xx_start_streaming(dvb);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300210 if (ret < 0)
211 rc = ret;
Aidan Thornton3421b772008-04-17 21:40:36 -0300212 }
213
214 mutex_unlock(&dvb->lock);
215 return rc;
216}
217
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300218static int em28xx_stop_feed(struct dvb_demux_feed *feed)
Aidan Thornton3421b772008-04-17 21:40:36 -0300219{
220 struct dvb_demux *demux = feed->demux;
221 struct em28xx_dvb *dvb = demux->priv;
222 int err = 0;
223
224 mutex_lock(&dvb->lock);
225 dvb->nfeeds--;
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300226
227 if (0 == dvb->nfeeds)
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300228 err = em28xx_stop_streaming(dvb);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300229
Aidan Thornton3421b772008-04-17 21:40:36 -0300230 mutex_unlock(&dvb->lock);
231 return err;
232}
233
234
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300235
236/* ------------------------------------------------------------------ */
237static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
238{
239 struct em28xx *dev = fe->dvb->priv;
240
241 if (acquire)
242 return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
243 else
Mauro Carvalho Chehab2fe3e2e2008-11-27 09:10:40 -0300244 return em28xx_set_mode(dev, EM28XX_SUSPEND);
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300245}
246
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300247/* ------------------------------------------------------------------ */
248
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -0300249static struct lgdt330x_config em2880_lgdt3303_dev = {
250 .demod_address = 0x0e,
251 .demod_chip = LGDT3303,
252};
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300253
Jarod Wilson7e48b302010-03-07 17:55:43 -0300254static struct lgdt3305_config em2870_lgdt3304_dev = {
255 .i2c_addr = 0x0e,
256 .demod_chip = LGDT3304,
257 .spectral_inversion = 1,
258 .deny_i2c_rptr = 1,
259 .mpeg_mode = LGDT3305_MPEG_PARALLEL,
260 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
261 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
262 .vsb_if_khz = 3250,
263 .qam_if_khz = 4000,
264};
265
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300266static struct s921_config sharp_isdbt = {
267 .demod_address = 0x30 >> 1
268};
269
Aidan Thornton7e6388a2008-04-17 21:40:03 -0300270static struct zl10353_config em28xx_zl10353_with_xc3028 = {
271 .demod_address = (0x1e >> 1),
272 .no_tuner = 1,
273 .parallel_ts = 1,
274 .if2 = 45600,
275};
276
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300277static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
278 .demod_address = 0x32 >> 1,
279 .output_mode = S5H1409_PARALLEL_OUTPUT,
280 .gpio = S5H1409_GPIO_OFF,
281 .inversion = S5H1409_INVERSION_OFF,
282 .status_mode = S5H1409_DEMODLOCKING,
283 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
284};
285
Jarod Wilson7e48b302010-03-07 17:55:43 -0300286static struct tda18271_std_map kworld_a340_std_map = {
287 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
288 .if_lvl = 1, .rfagc_top = 0x37, },
289 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
290 .if_lvl = 1, .rfagc_top = 0x37, },
291};
292
293static struct tda18271_config kworld_a340_config = {
294 .std_map = &kworld_a340_std_map,
295};
296
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300297static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300298 .demod_address = (0x1e >> 1),
299 .no_tuner = 1,
300 .disable_i2c_gate_ctrl = 1,
301 .parallel_ts = 1,
302 .if2 = 45600,
303};
304
Devin Heitmueller75e2b862011-03-13 02:01:02 -0300305static struct drxd_config em28xx_drxd = {
306 .index = 0, .demod_address = 0x70, .demod_revision = 0xa2,
307 .demoda_address = 0x00, .pll_address = 0x00,
308 .pll_type = DRXD_PLL_NONE, .clock = 12000, .insert_rs_byte = 1,
309 .pll_set = NULL, .osc_deviation = NULL, .IF = 42800000,
Devin Heitmueller6b142b32011-03-13 02:02:01 -0300310 .disable_i2c_gate_ctrl = 1,
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300311};
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300312
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300313struct drxk_config terratec_h5_drxk = {
314 .adr = 0x29,
Mauro Carvalho Chehabe4f4f872011-07-09 17:35:26 -0300315 .single_master = 1,
Mauro Carvalho Chehabf1fe1b72011-07-09 21:59:33 -0300316 .no_i2c_bridge = 1,
Mauro Carvalho Chehab8b9456a2011-07-11 14:33:51 -0300317 .microcode_name = "dvb-usb-terratec-h5-drxk.fw",
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300318};
319
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300320struct drxk_config hauppauge_930c_drxk = {
321 .adr = 0x29,
322 .single_master = 1,
323 .no_i2c_bridge = 1,
324 .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
325 .chunk_size = 56,
326};
327
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300328static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
329{
330 struct em28xx_dvb *dvb = fe->sec_priv;
331 int status;
332
333 if (!dvb)
334 return -EINVAL;
335
336 if (enable) {
337 down(&dvb->pll_mutex);
338 status = dvb->gate_ctrl(fe, 1);
339 } else {
340 status = dvb->gate_ctrl(fe, 0);
341 up(&dvb->pll_mutex);
342 }
343 return status;
344}
345
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300346static void hauppauge_hvr930c_init(struct em28xx *dev)
347{
348 int i;
349
350 struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -0200351 {EM2874_R80_GPIO, 0xff, 0xff, 0x65},
352 {EM2874_R80_GPIO, 0xfb, 0xff, 0x32},
353 {EM2874_R80_GPIO, 0xff, 0xff, 0xb8},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300354 { -1, -1, -1, -1},
355 };
356 struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -0200357 {EM2874_R80_GPIO, 0xef, 0xff, 0x01},
358 {EM2874_R80_GPIO, 0xaf, 0xff, 0x65},
359 {EM2874_R80_GPIO, 0xef, 0xff, 0x76},
360 {EM2874_R80_GPIO, 0xef, 0xff, 0x01},
361 {EM2874_R80_GPIO, 0xcf, 0xff, 0x0b},
362 {EM2874_R80_GPIO, 0xef, 0xff, 0x40},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300363
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -0200364 {EM2874_R80_GPIO, 0xcf, 0xff, 0x65},
365 {EM2874_R80_GPIO, 0xef, 0xff, 0x65},
366 {EM2874_R80_GPIO, 0xcf, 0xff, 0x0b},
367 {EM2874_R80_GPIO, 0xef, 0xff, 0x65},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300368
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300369 { -1, -1, -1, -1},
370 };
371
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300372 struct {
373 unsigned char r[4];
374 int len;
375 } regs[] = {
376 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
377 {{ 0x01, 0x02 }, 2},
378 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
379 {{ 0x01, 0x00 }, 2},
380 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
381 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
382 {{ 0x01, 0x00 }, 2},
383 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
384 {{ 0x04, 0x00 }, 2},
385 {{ 0x00, 0x04 }, 2},
386 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
387 {{ 0x04, 0x14 }, 2},
388 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
389 };
390
391 em28xx_gpio_set(dev, hauppauge_hvr930c_init);
392 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
393 msleep(10);
394 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
395 msleep(10);
396
397 dev->i2c_client.addr = 0x82 >> 1;
398
399 for (i = 0; i < ARRAY_SIZE(regs); i++)
400 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
401 em28xx_gpio_set(dev, hauppauge_hvr930c_end);
402
403 msleep(100);
404
405 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
406 msleep(30);
407
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300408 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
409 msleep(10);
410
411}
412
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300413static void terratec_h5_init(struct em28xx *dev)
414{
415 int i;
416 struct em28xx_reg_seq terratec_h5_init[] = {
417 {EM28XX_R08_GPIO, 0xff, 0xff, 10},
418 {EM2874_R80_GPIO, 0xf6, 0xff, 100},
419 {EM2874_R80_GPIO, 0xf2, 0xff, 50},
420 {EM2874_R80_GPIO, 0xf6, 0xff, 100},
421 { -1, -1, -1, -1},
422 };
423 struct em28xx_reg_seq terratec_h5_end[] = {
424 {EM2874_R80_GPIO, 0xe6, 0xff, 100},
425 {EM2874_R80_GPIO, 0xa6, 0xff, 50},
426 {EM2874_R80_GPIO, 0xe6, 0xff, 100},
427 { -1, -1, -1, -1},
428 };
429 struct {
430 unsigned char r[4];
431 int len;
432 } regs[] = {
433 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
434 {{ 0x01, 0x02 }, 2},
435 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
436 {{ 0x01, 0x00 }, 2},
437 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
438 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
439 {{ 0x01, 0x00 }, 2},
440 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
441 {{ 0x04, 0x00 }, 2},
442 {{ 0x00, 0x04 }, 2},
443 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
444 {{ 0x04, 0x14 }, 2},
445 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
446 };
447
448 em28xx_gpio_set(dev, terratec_h5_init);
449 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
450 msleep(10);
451 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
452 msleep(10);
453
454 dev->i2c_client.addr = 0x82 >> 1;
455
456 for (i = 0; i < ARRAY_SIZE(regs); i++)
457 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
458 em28xx_gpio_set(dev, terratec_h5_end);
459};
460
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300461static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300462{
463 /* Values extracted from a USB trace of the Terratec Windows driver */
464 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
465 static u8 reset[] = { RESET, 0x80 };
466 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
467 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
468 static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
469 static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
470 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
471 static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
472 static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
Devin Heitmuellerff697862009-07-12 18:44:19 -0300473 static u8 tuner_go[] = { TUNER_GO, 0x01};
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300474
475 mt352_write(fe, clock_config, sizeof(clock_config));
476 udelay(200);
477 mt352_write(fe, reset, sizeof(reset));
478 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
479 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
480 mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
481 mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
482 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
483 mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
484 mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
485 mt352_write(fe, tuner_go, sizeof(tuner_go));
486 return 0;
487}
488
489static struct mt352_config terratec_xs_mt352_cfg = {
490 .demod_address = (0x1e >> 1),
491 .no_tuner = 1,
492 .if2 = 45600,
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300493 .demod_init = em28xx_mt352_terratec_xs_init,
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300494};
495
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300496static struct tda10023_config em28xx_tda10023_config = {
497 .demod_address = 0x0c,
498 .invert = 1,
499};
500
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300501static struct cxd2820r_config em28xx_cxd2820r_config = {
502 .i2c_address = (0xd8 >> 1),
503 .ts_mode = CXD2820R_TS_SERIAL,
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300504
505 /* enable LNA for DVB-T2 and DVB-C */
506 .gpio_dvbt2[0] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | CXD2820R_GPIO_L,
507 .gpio_dvbc[0] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | CXD2820R_GPIO_L,
508};
509
510static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
511 .output_opt = TDA18271_OUTPUT_LT_OFF,
Steve Kerrison0db4bf42011-08-09 07:16:21 -0300512 .gate = TDA18271_GATE_DIGITAL,
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300513};
514
Antti Palosaari36588712011-08-01 01:15:30 -0300515static const struct tda10071_config em28xx_tda10071_config = {
516 .i2c_address = 0x55, /* (0xaa >> 1) */
517 .i2c_wr_max = 64,
518 .ts_mode = TDA10071_TS_SERIAL,
519 .spec_inv = 0,
520 .xtal = 40444000, /* 40.444 MHz */
521 .pll_multiplier = 20,
522};
523
524static const struct a8293_config em28xx_a8293_config = {
525 .i2c_addr = 0x08, /* (0x10 >> 1) */
526};
527
Aivar Päkk1985f6f2011-12-11 18:15:00 -0300528static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
529 .demod_address = (0x1e >> 1),
530 .disable_i2c_gate_ctrl = 1,
531 .no_tuner = 1,
532 .parallel_ts = 1,
533};
534static struct qt1010_config em28xx_qt1010_config = {
535 .i2c_address = 0x62
536
537};
538
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300539/* ------------------------------------------------------------------ */
540
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300541static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300542{
543 struct dvb_frontend *fe;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300544 struct xc2028_config cfg;
545
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300546 memset(&cfg, 0, sizeof(cfg));
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300547 cfg.i2c_adap = &dev->i2c_adap;
548 cfg.i2c_addr = addr;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300549
Antti Palosaarif71095b2011-04-07 15:51:52 -0300550 if (!dev->dvb->fe[0]) {
Filipe Rosset480be182009-11-04 15:32:37 -0300551 em28xx_errdev("/2: dvb frontend not attached. "
552 "Can't attach xc3028\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300553 return -EINVAL;
554 }
555
Antti Palosaarif71095b2011-04-07 15:51:52 -0300556 fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300557 if (!fe) {
Filipe Rosset480be182009-11-04 15:32:37 -0300558 em28xx_errdev("/2: xc3028 attach failed\n");
Antti Palosaarif71095b2011-04-07 15:51:52 -0300559 dvb_frontend_detach(dev->dvb->fe[0]);
560 dev->dvb->fe[0] = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300561 return -EINVAL;
562 }
563
Filipe Rosset480be182009-11-04 15:32:37 -0300564 em28xx_info("%s/2: xc3028 attached\n", dev->name);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300565
566 return 0;
567}
568
Aidan Thornton3421b772008-04-17 21:40:36 -0300569/* ------------------------------------------------------------------ */
570
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300571static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
572 struct em28xx *dev, struct device *device)
Aidan Thornton3421b772008-04-17 21:40:36 -0300573{
574 int result;
575
576 mutex_init(&dvb->lock);
577
578 /* register adapter */
579 result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
580 adapter_nr);
581 if (result < 0) {
582 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
583 dev->name, result);
584 goto fail_adapter;
585 }
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300586
587 /* Ensure all frontends negotiate bus access */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300588 dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
589 if (dvb->fe[1])
590 dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300591
Aidan Thornton3421b772008-04-17 21:40:36 -0300592 dvb->adapter.priv = dev;
593
594 /* register frontend */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300595 result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300596 if (result < 0) {
597 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
598 dev->name, result);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300599 goto fail_frontend0;
600 }
601
602 /* register 2nd frontend */
603 if (dvb->fe[1]) {
604 result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
605 if (result < 0) {
606 printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
607 dev->name, result);
608 goto fail_frontend1;
609 }
Aidan Thornton3421b772008-04-17 21:40:36 -0300610 }
611
612 /* register demux stuff */
613 dvb->demux.dmx.capabilities =
614 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
615 DMX_MEMORY_BASED_FILTERING;
616 dvb->demux.priv = dvb;
617 dvb->demux.filternum = 256;
618 dvb->demux.feednum = 256;
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300619 dvb->demux.start_feed = em28xx_start_feed;
620 dvb->demux.stop_feed = em28xx_stop_feed;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300621
Aidan Thornton3421b772008-04-17 21:40:36 -0300622 result = dvb_dmx_init(&dvb->demux);
623 if (result < 0) {
624 printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
625 dev->name, result);
626 goto fail_dmx;
627 }
628
629 dvb->dmxdev.filternum = 256;
630 dvb->dmxdev.demux = &dvb->demux.dmx;
631 dvb->dmxdev.capabilities = 0;
632 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
633 if (result < 0) {
634 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
635 dev->name, result);
636 goto fail_dmxdev;
637 }
638
639 dvb->fe_hw.source = DMX_FRONTEND_0;
640 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
641 if (result < 0) {
642 printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
643 dev->name, result);
644 goto fail_fe_hw;
645 }
646
647 dvb->fe_mem.source = DMX_MEMORY_FE;
648 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
649 if (result < 0) {
650 printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
651 dev->name, result);
652 goto fail_fe_mem;
653 }
654
655 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
656 if (result < 0) {
657 printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
658 dev->name, result);
659 goto fail_fe_conn;
660 }
661
662 /* register network adapter */
663 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
664 return 0;
665
666fail_fe_conn:
667 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
668fail_fe_mem:
669 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
670fail_fe_hw:
671 dvb_dmxdev_release(&dvb->dmxdev);
672fail_dmxdev:
673 dvb_dmx_release(&dvb->demux);
674fail_dmx:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300675 if (dvb->fe[1])
676 dvb_unregister_frontend(dvb->fe[1]);
677 dvb_unregister_frontend(dvb->fe[0]);
678fail_frontend1:
679 if (dvb->fe[1])
680 dvb_frontend_detach(dvb->fe[1]);
681fail_frontend0:
682 dvb_frontend_detach(dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300683 dvb_unregister_adapter(&dvb->adapter);
684fail_adapter:
685 return result;
686}
687
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300688static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
Aidan Thornton3421b772008-04-17 21:40:36 -0300689{
690 dvb_net_release(&dvb->net);
691 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
692 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
693 dvb_dmxdev_release(&dvb->dmxdev);
694 dvb_dmx_release(&dvb->demux);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300695 if (dvb->fe[1])
696 dvb_unregister_frontend(dvb->fe[1]);
697 dvb_unregister_frontend(dvb->fe[0]);
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -0300698 if (dvb->fe[1] && !dvb->dont_attach_fe1)
Antti Palosaarif71095b2011-04-07 15:51:52 -0300699 dvb_frontend_detach(dvb->fe[1]);
700 dvb_frontend_detach(dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300701 dvb_unregister_adapter(&dvb->adapter);
702}
703
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300704static int em28xx_dvb_init(struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300705{
Antti Palosaarie3645432011-07-28 18:59:30 -0300706 int result = 0, mfe_shared = 0;
Aidan Thornton3421b772008-04-17 21:40:36 -0300707 struct em28xx_dvb *dvb;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300708
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -0300709 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -0300710 /* This device does not support the extension */
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300711 printk(KERN_INFO "em28xx_dvb: This device does not support the extension\n");
Devin Heitmuellerdf619182008-06-10 12:34:35 -0300712 return 0;
713 }
714
Aidan Thornton3421b772008-04-17 21:40:36 -0300715 dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300716
717 if (dvb == NULL) {
Filipe Rosset480be182009-11-04 15:32:37 -0300718 em28xx_info("em28xx_dvb: memory allocation failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -0300719 return -ENOMEM;
720 }
721 dev->dvb = dvb;
Antti Palosaarif71095b2011-04-07 15:51:52 -0300722 dvb->fe[0] = dvb->fe[1] = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300723
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -0300724 mutex_lock(&dev->lock);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300725 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300726 /* init frontend */
727 switch (dev->model) {
Mauro Carvalho Chehabebaefdb2011-06-01 10:16:25 -0300728 case EM2874_BOARD_LEADERSHIP_ISDBT:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300729 dvb->fe[0] = dvb_attach(s921_attach,
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300730 &sharp_isdbt, &dev->i2c_adap);
731
Antti Palosaarif71095b2011-04-07 15:51:52 -0300732 if (!dvb->fe[0]) {
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300733 result = -EINVAL;
734 goto out_free;
735 }
736
737 break;
Douglas Schilling Landgraff89bc322008-12-01 21:01:04 -0300738 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
Mauro Carvalho Chehab10ac6602008-07-27 14:58:58 -0300739 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
Devin Heitmueller4fd305b2008-06-04 13:43:46 -0300740 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
Devin Heitmuellere14b3652008-07-26 11:04:33 -0300741 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300742 dvb->fe[0] = dvb_attach(lgdt330x_attach,
Aidan Thornton3421b772008-04-17 21:40:36 -0300743 &em2880_lgdt3303_dev,
744 &dev->i2c_adap);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300745 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Aidan Thornton3421b772008-04-17 21:40:36 -0300746 result = -EINVAL;
747 goto out_free;
748 }
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -0300749 break;
Thierry MERLE46510b52008-10-11 16:56:13 -0300750 case EM2880_BOARD_KWORLD_DVB_310U:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300751 dvb->fe[0] = dvb_attach(zl10353_attach,
Aidan Thornton3421b772008-04-17 21:40:36 -0300752 &em28xx_zl10353_with_xc3028,
753 &dev->i2c_adap);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300754 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Aidan Thornton3421b772008-04-17 21:40:36 -0300755 result = -EINVAL;
756 goto out_free;
757 }
Aidan Thornton7e6388a2008-04-17 21:40:03 -0300758 break;
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300759 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
Uroš Vamplec994d02009-09-30 22:53:37 -0300760 case EM2882_BOARD_TERRATEC_HYBRID_XS:
Devin Heitmueller01a5fd62009-08-07 09:25:06 -0300761 case EM2880_BOARD_EMPIRE_DUAL_TV:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300762 dvb->fe[0] = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300763 &em28xx_zl10353_xc3028_no_i2c_gate,
764 &dev->i2c_adap);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300765 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300766 result = -EINVAL;
767 goto out_free;
768 }
769 break;
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300770 case EM2880_BOARD_TERRATEC_HYBRID_XS:
Catimimi65638012010-02-18 18:06:32 -0300771 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
Devin Heitmuellerd5b3ba92009-07-08 21:51:35 -0300772 case EM2881_BOARD_PINNACLE_HYBRID_PRO:
Andrea.Amorosi76@gmail.com7ca7ef62010-02-09 17:53:38 -0300773 case EM2882_BOARD_DIKOM_DK300:
Antonio Larrosa811fab62010-03-04 22:19:48 -0300774 case EM2882_BOARD_KWORLD_VS_DVBT:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300775 dvb->fe[0] = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300776 &em28xx_zl10353_xc3028_no_i2c_gate,
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300777 &dev->i2c_adap);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300778 if (dvb->fe[0] == NULL) {
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300779 /* This board could have either a zl10353 or a mt352.
780 If the chip id isn't for zl10353, try mt352 */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300781 dvb->fe[0] = dvb_attach(mt352_attach,
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300782 &terratec_xs_mt352_cfg,
783 &dev->i2c_adap);
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300784 }
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300785
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300786 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300787 result = -EINVAL;
788 goto out_free;
789 }
790 break;
Aivar Päkk1985f6f2011-12-11 18:15:00 -0300791 case EM2870_BOARD_KWORLD_355U:
792 dvb->fe[0] = dvb_attach(zl10353_attach,
793 &em28xx_zl10353_no_i2c_gate_dev,
794 &dev->i2c_adap);
795 if (dvb->fe[0] != NULL)
796 dvb_attach(qt1010_attach, dvb->fe[0],
797 &dev->i2c_adap, &em28xx_qt1010_config);
798 break;
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300799 case EM2883_BOARD_KWORLD_HYBRID_330U:
Devin Heitmueller19859222009-06-19 00:33:54 -0300800 case EM2882_BOARD_EVGA_INDTUBE:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300801 dvb->fe[0] = dvb_attach(s5h1409_attach,
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300802 &em28xx_s5h1409_with_xc3028,
803 &dev->i2c_adap);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300804 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300805 result = -EINVAL;
806 goto out_free;
807 }
808 break;
Franklin Mengd7de5d82009-06-06 17:05:02 -0300809 case EM2882_BOARD_KWORLD_ATSC_315U:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300810 dvb->fe[0] = dvb_attach(lgdt330x_attach,
Franklin Mengd7de5d82009-06-06 17:05:02 -0300811 &em2880_lgdt3303_dev,
812 &dev->i2c_adap);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300813 if (dvb->fe[0] != NULL) {
814 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
Franklin Mengd7de5d82009-06-06 17:05:02 -0300815 &dev->i2c_adap, 0x61, TUNER_THOMSON_DTT761X)) {
816 result = -EINVAL;
817 goto out_free;
818 }
819 }
820 break;
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300821 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
Devin Heitmuellerad9b4bb2011-03-13 02:09:59 -0300822 case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300823 dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
Devin Heitmueller75e2b862011-03-13 02:01:02 -0300824 &dev->i2c_adap, &dev->udev->dev);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300825 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300826 result = -EINVAL;
827 goto out_free;
828 }
829 break;
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300830 case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
831 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300832 dvb->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300833 &em28xx_tda10023_config,
834 &dev->i2c_adap, 0x48);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300835 if (dvb->fe[0]) {
836 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300837 &dev->i2c_adap, 0x60, TUNER_PHILIPS_CU1216L)) {
838 result = -EINVAL;
839 goto out_free;
840 }
841 }
842 break;
Jarod Wilson7e48b302010-03-07 17:55:43 -0300843 case EM2870_BOARD_KWORLD_A340:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300844 dvb->fe[0] = dvb_attach(lgdt3305_attach,
Jarod Wilson7e48b302010-03-07 17:55:43 -0300845 &em2870_lgdt3304_dev,
846 &dev->i2c_adap);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300847 if (dvb->fe[0] != NULL)
848 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Jarod Wilson7e48b302010-03-07 17:55:43 -0300849 &dev->i2c_adap, &kworld_a340_config);
850 break;
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300851 case EM28174_BOARD_PCTV_290E:
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300852 dvb->fe[0] = dvb_attach(cxd2820r_attach,
Manu Abraham7e7b8282011-12-10 00:44:24 -0300853 &em28xx_cxd2820r_config,
854 &dev->i2c_adap,
855 NULL);
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300856 if (dvb->fe[0]) {
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300857 /* FE 0 attach tuner */
Manu Abraham7e7b8282011-12-10 00:44:24 -0300858 if (!dvb_attach(tda18271_attach,
859 dvb->fe[0],
860 0x60,
861 &dev->i2c_adap,
862 &em28xx_cxd2820r_tda18271_config)) {
863
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300864 dvb_frontend_detach(dvb->fe[0]);
865 result = -EINVAL;
866 goto out_free;
867 }
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300868 }
869 break;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300870 case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
Mauro Carvalho Chehab85032322011-11-24 15:01:45 -0200871 {
872 struct xc5000_config cfg;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300873 hauppauge_hvr930c_init(dev);
874
875 dvb->dont_attach_fe1 = 1;
876
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -0200877 dvb->fe[0] = dvb_attach(drxk_attach,
878 &hauppauge_930c_drxk, &dev->i2c_adap,
879 &dvb->fe[1]);
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300880 if (!dvb->fe[0]) {
881 result = -EINVAL;
882 goto out_free;
883 }
884 /* FIXME: do we need a pll semaphore? */
885 dvb->fe[0]->sec_priv = dvb;
886 sema_init(&dvb->pll_mutex, 1);
887 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
888 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
889 dvb->fe[1]->id = 1;
890
891 /* Attach xc5000 */
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300892 memset(&cfg, 0, sizeof(cfg));
893 cfg.i2c_address = 0x61;
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -0200894 cfg.if_khz = 4000;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300895
896 if (dvb->fe[0]->ops.i2c_gate_ctrl)
897 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -0200898 if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap,
899 &cfg)) {
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300900 result = -EINVAL;
901 goto out_free;
902 }
903
904 if (dvb->fe[0]->ops.i2c_gate_ctrl)
905 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
906
907 /* Hack - needed by drxk/tda18271c2dd */
908 dvb->fe[1]->tuner_priv = dvb->fe[0]->tuner_priv;
909 memcpy(&dvb->fe[1]->ops.tuner_ops,
910 &dvb->fe[0]->ops.tuner_ops,
911 sizeof(dvb->fe[0]->ops.tuner_ops));
912
Mauro Carvalho Chehab48763e22011-12-09 08:53:36 -0200913 mfe_shared = 1;
914
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300915 break;
Mauro Carvalho Chehab85032322011-11-24 15:01:45 -0200916 }
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300917 case EM2884_BOARD_TERRATEC_H5:
Andreas Oberrittera1ed02e2011-11-16 11:06:50 -0300918 case EM2884_BOARD_CINERGY_HTC_STICK:
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300919 terratec_h5_init(dev);
920
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -0300921 dvb->dont_attach_fe1 = 1;
922
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300923 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap, &dvb->fe[1]);
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -0300924 if (!dvb->fe[0]) {
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300925 result = -EINVAL;
926 goto out_free;
927 }
928 /* FIXME: do we need a pll semaphore? */
929 dvb->fe[0]->sec_priv = dvb;
930 sema_init(&dvb->pll_mutex, 1);
931 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
932 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300933 dvb->fe[1]->id = 1;
934
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -0300935 /* Attach tda18271 to DVB-C frontend */
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300936 if (dvb->fe[0]->ops.i2c_gate_ctrl)
937 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
938 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap, 0x60)) {
939 result = -EINVAL;
940 goto out_free;
941 }
942 if (dvb->fe[0]->ops.i2c_gate_ctrl)
943 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -0300944
945 /* Hack - needed by drxk/tda18271c2dd */
946 dvb->fe[1]->tuner_priv = dvb->fe[0]->tuner_priv;
947 memcpy(&dvb->fe[1]->ops.tuner_ops,
948 &dvb->fe[0]->ops.tuner_ops,
949 sizeof(dvb->fe[0]->ops.tuner_ops));
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300950
Mauro Carvalho Chehab48763e22011-12-09 08:53:36 -0200951 mfe_shared = 1;
952
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300953 break;
Antti Palosaari36588712011-08-01 01:15:30 -0300954 case EM28174_BOARD_PCTV_460E:
955 /* attach demod */
956 dvb->fe[0] = dvb_attach(tda10071_attach,
957 &em28xx_tda10071_config, &dev->i2c_adap);
958
959 /* attach SEC */
960 if (dvb->fe[0])
961 dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap,
962 &em28xx_a8293_config);
963 break;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300964 default:
Filipe Rosset480be182009-11-04 15:32:37 -0300965 em28xx_errdev("/2: The frontend of your DVB/ATSC card"
966 " isn't supported yet\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300967 break;
968 }
Antti Palosaarif71095b2011-04-07 15:51:52 -0300969 if (NULL == dvb->fe[0]) {
Filipe Rosset480be182009-11-04 15:32:37 -0300970 em28xx_errdev("/2: frontend initialization failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -0300971 result = -EINVAL;
972 goto out_free;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300973 }
Michael Krufkyd7cba042008-09-12 13:31:45 -0300974 /* define general-purpose callback pointer */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300975 dvb->fe[0]->callback = em28xx_tuner_callback;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300976 if (dvb->fe[1])
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -0200977 dvb->fe[1]->callback = em28xx_tuner_callback;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300978
979 /* register everything */
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300980 result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
Aidan Thornton3421b772008-04-17 21:40:36 -0300981
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300982 if (result < 0)
Aidan Thornton3421b772008-04-17 21:40:36 -0300983 goto out_free;
Aidan Thornton3421b772008-04-17 21:40:36 -0300984
Antti Palosaarie3645432011-07-28 18:59:30 -0300985 /* MFE lock */
986 dvb->adapter.mfe_shared = mfe_shared;
987
Filipe Rosset480be182009-11-04 15:32:37 -0300988 em28xx_info("Successfully loaded em28xx-dvb\n");
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -0300989ret:
990 em28xx_set_mode(dev, EM28XX_SUSPEND);
991 mutex_unlock(&dev->lock);
992 return result;
Aidan Thornton3421b772008-04-17 21:40:36 -0300993
994out_free:
995 kfree(dvb);
996 dev->dvb = NULL;
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -0300997 goto ret;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300998}
999
Chris Rankin0b8bd832011-08-20 16:01:26 -03001000static inline void prevent_sleep(struct dvb_frontend_ops *ops)
1001{
1002 ops->set_voltage = NULL;
1003 ops->sleep = NULL;
1004 ops->tuner_ops.sleep = NULL;
1005}
1006
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001007static int em28xx_dvb_fini(struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001008{
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -03001009 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -03001010 /* This device does not support the extension */
1011 return 0;
1012 }
1013
Aidan Thornton3421b772008-04-17 21:40:36 -03001014 if (dev->dvb) {
Chris Rankin0b8bd832011-08-20 16:01:26 -03001015 struct em28xx_dvb *dvb = dev->dvb;
1016
1017 if (dev->state & DEV_DISCONNECTED) {
1018 /* We cannot tell the device to sleep
1019 * once it has been unplugged. */
1020 if (dvb->fe[0])
1021 prevent_sleep(&dvb->fe[0]->ops);
1022 if (dvb->fe[1])
1023 prevent_sleep(&dvb->fe[1]->ops);
1024 }
1025
1026 em28xx_unregister_dvb(dvb);
1027 kfree(dvb);
Aidan Thornton3421b772008-04-17 21:40:36 -03001028 dev->dvb = NULL;
1029 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001030
1031 return 0;
1032}
1033
1034static struct em28xx_ops dvb_ops = {
1035 .id = EM28XX_DVB,
1036 .name = "Em28xx dvb Extension",
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001037 .init = em28xx_dvb_init,
1038 .fini = em28xx_dvb_fini,
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001039};
1040
1041static int __init em28xx_dvb_register(void)
1042{
1043 return em28xx_register_extension(&dvb_ops);
1044}
1045
1046static void __exit em28xx_dvb_unregister(void)
1047{
1048 em28xx_unregister_extension(&dvb_ops);
1049}
1050
1051module_init(em28xx_dvb_register);
1052module_exit(em28xx_dvb_unregister);