blob: 13ae821949e9f5f3007aaf77554e63e1551cc28e [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;
Antti Palosaari13a53362012-07-19 22:28:56 -030084 int lna_gpio;
Aidan Thornton3421b772008-04-17 21:40:36 -030085};
86
87
88static inline void print_err_status(struct em28xx *dev,
89 int packet, int status)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030090{
Aidan Thornton3421b772008-04-17 21:40:36 -030091 char *errmsg = "Unknown";
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030092
Aidan Thornton3421b772008-04-17 21:40:36 -030093 switch (status) {
94 case -ENOENT:
95 errmsg = "unlinked synchronuously";
96 break;
97 case -ECONNRESET:
98 errmsg = "unlinked asynchronuously";
99 break;
100 case -ENOSR:
101 errmsg = "Buffer error (overrun)";
102 break;
103 case -EPIPE:
104 errmsg = "Stalled (device not responding)";
105 break;
106 case -EOVERFLOW:
107 errmsg = "Babble (bad cable?)";
108 break;
109 case -EPROTO:
110 errmsg = "Bit-stuff error (bad cable?)";
111 break;
112 case -EILSEQ:
113 errmsg = "CRC/Timeout (could be anything)";
114 break;
115 case -ETIME:
116 errmsg = "Device does not respond";
117 break;
118 }
119 if (packet < 0) {
120 dprintk(1, "URB status %d [%s].\n", status, errmsg);
121 } else {
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300122 dprintk(1, "URB packet %d, status %d [%s].\n",
123 packet, status, errmsg);
Aidan Thornton3421b772008-04-17 21:40:36 -0300124 }
125}
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300126
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300127static inline int em28xx_dvb_isoc_copy(struct em28xx *dev, struct urb *urb)
Aidan Thornton3421b772008-04-17 21:40:36 -0300128{
129 int i;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300130
Aidan Thornton3421b772008-04-17 21:40:36 -0300131 if (!dev)
132 return 0;
133
134 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
135 return 0;
136
137 if (urb->status < 0) {
138 print_err_status(dev, -1, urb->status);
139 if (urb->status == -ENOENT)
140 return 0;
141 }
142
143 for (i = 0; i < urb->number_of_packets; i++) {
144 int status = urb->iso_frame_desc[i].status;
145
146 if (status < 0) {
147 print_err_status(dev, i, status);
148 if (urb->iso_frame_desc[i].status != -EPROTO)
149 continue;
150 }
151
152 dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer +
153 urb->iso_frame_desc[i].offset,
154 urb->iso_frame_desc[i].actual_length);
155 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300156
157 return 0;
158}
159
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300160static int em28xx_start_streaming(struct em28xx_dvb *dvb)
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300161{
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300162 int rc;
Aidan Thornton3421b772008-04-17 21:40:36 -0300163 struct em28xx *dev = dvb->adapter.priv;
Devin Heitmuellerd18e2fd2009-05-16 17:09:28 -0300164 int max_dvb_packet_size;
Aidan Thornton3421b772008-04-17 21:40:36 -0300165
Holger Nelson8ab33622011-12-28 18:55:41 -0300166 usb_set_interface(dev->udev, 0, dev->dvb_alt);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300167 rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
168 if (rc < 0)
169 return rc;
Aidan Thornton3421b772008-04-17 21:40:36 -0300170
Holger Nelson8ab33622011-12-28 18:55:41 -0300171 max_dvb_packet_size = dev->dvb_max_pkt_size;
Mauro Carvalho Chehabf7acc4b2011-07-28 15:42:00 -0300172 if (max_dvb_packet_size < 0)
173 return max_dvb_packet_size;
Gianluca Gennari86d38d12012-02-13 13:59:22 -0300174 dprintk(1, "Using %d buffers each with %d x %d bytes\n",
Mauro Carvalho Chehabf7acc4b2011-07-28 15:42:00 -0300175 EM28XX_DVB_NUM_BUFS,
Gianluca Gennari86d38d12012-02-13 13:59:22 -0300176 EM28XX_DVB_MAX_PACKETS,
Mauro Carvalho Chehabf7acc4b2011-07-28 15:42:00 -0300177 max_dvb_packet_size);
Devin Heitmuellerd18e2fd2009-05-16 17:09:28 -0300178
Gianluca Gennari86d38d12012-02-13 13:59:22 -0300179 return em28xx_init_isoc(dev, EM28XX_DIGITAL_MODE,
180 EM28XX_DVB_MAX_PACKETS, EM28XX_DVB_NUM_BUFS,
181 max_dvb_packet_size, 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
Gianluca Gennari5f5f1472012-03-22 08:48:17 -0300188 em28xx_stop_urbs(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 = {
Mauro Carvalho Chehabaac865f2011-12-26 09:41:14 -0300306 .demod_address = 0x70,
307 .demod_revision = 0xa2,
308 .pll_type = DRXD_PLL_NONE,
309 .clock = 12000,
310 .insert_rs_byte = 1,
311 .IF = 42800000,
Devin Heitmueller6b142b32011-03-13 02:02:01 -0300312 .disable_i2c_gate_ctrl = 1,
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300313};
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300314
Ezequiel García61bdbef2012-06-12 09:53:41 -0300315static struct drxk_config terratec_h5_drxk = {
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300316 .adr = 0x29,
Mauro Carvalho Chehabe4f4f872011-07-09 17:35:26 -0300317 .single_master = 1,
Mauro Carvalho Chehabf1fe1b72011-07-09 21:59:33 -0300318 .no_i2c_bridge = 1,
Mauro Carvalho Chehab8b9456a2011-07-11 14:33:51 -0300319 .microcode_name = "dvb-usb-terratec-h5-drxk.fw",
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300320 .qam_demod_parameter_count = 2,
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300321 .load_firmware_sync = true,
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300322};
323
Ezequiel García61bdbef2012-06-12 09:53:41 -0300324static struct drxk_config hauppauge_930c_drxk = {
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300325 .adr = 0x29,
326 .single_master = 1,
327 .no_i2c_bridge = 1,
328 .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
329 .chunk_size = 56,
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300330 .qam_demod_parameter_count = 2,
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300331 .load_firmware_sync = true,
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300332};
333
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300334struct drxk_config terratec_htc_stick_drxk = {
335 .adr = 0x29,
336 .single_master = 1,
337 .no_i2c_bridge = 1,
338 .microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw",
339 .chunk_size = 54,
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300340 .qam_demod_parameter_count = 2,
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300341 /* Required for the antenna_gpio to disable LNA. */
342 .antenna_dvbt = true,
343 /* The windows driver uses the same. This will disable LNA. */
344 .antenna_gpio = 0x6,
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300345 .load_firmware_sync = true,
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300346};
347
Ezequiel García61bdbef2012-06-12 09:53:41 -0300348static struct drxk_config maxmedia_ub425_tc_drxk = {
Antti Palosaari35530852012-03-18 18:09:01 -0300349 .adr = 0x29,
350 .single_master = 1,
351 .no_i2c_bridge = 1,
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300352 .load_firmware_sync = true,
Antti Palosaari35530852012-03-18 18:09:01 -0300353};
354
Ezequiel García61bdbef2012-06-12 09:53:41 -0300355static struct drxk_config pctv_520e_drxk = {
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300356 .adr = 0x29,
357 .single_master = 1,
358 .microcode_name = "dvb-demod-drxk-pctv.fw",
Martin Blumenstingl9e23f50a2012-07-04 17:36:55 -0300359 .qam_demod_parameter_count = 2,
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300360 .chunk_size = 58,
Antti Palosaarif6f379d2012-05-17 19:09:06 -0300361 .antenna_dvbt = true, /* disable LNA */
362 .antenna_gpio = (1 << 2), /* disable LNA */
Mauro Carvalho Chehab2425bb32012-10-02 16:02:57 -0300363 .load_firmware_sync = true,
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300364};
365
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300366static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
367{
368 struct em28xx_dvb *dvb = fe->sec_priv;
369 int status;
370
371 if (!dvb)
372 return -EINVAL;
373
374 if (enable) {
375 down(&dvb->pll_mutex);
376 status = dvb->gate_ctrl(fe, 1);
377 } else {
378 status = dvb->gate_ctrl(fe, 0);
379 up(&dvb->pll_mutex);
380 }
381 return status;
382}
383
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300384static void hauppauge_hvr930c_init(struct em28xx *dev)
385{
386 int i;
387
388 struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -0200389 {EM2874_R80_GPIO, 0xff, 0xff, 0x65},
390 {EM2874_R80_GPIO, 0xfb, 0xff, 0x32},
391 {EM2874_R80_GPIO, 0xff, 0xff, 0xb8},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300392 { -1, -1, -1, -1},
393 };
394 struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -0200395 {EM2874_R80_GPIO, 0xef, 0xff, 0x01},
396 {EM2874_R80_GPIO, 0xaf, 0xff, 0x65},
397 {EM2874_R80_GPIO, 0xef, 0xff, 0x76},
398 {EM2874_R80_GPIO, 0xef, 0xff, 0x01},
399 {EM2874_R80_GPIO, 0xcf, 0xff, 0x0b},
400 {EM2874_R80_GPIO, 0xef, 0xff, 0x40},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300401
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -0200402 {EM2874_R80_GPIO, 0xcf, 0xff, 0x65},
403 {EM2874_R80_GPIO, 0xef, 0xff, 0x65},
404 {EM2874_R80_GPIO, 0xcf, 0xff, 0x0b},
405 {EM2874_R80_GPIO, 0xef, 0xff, 0x65},
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300406
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300407 { -1, -1, -1, -1},
408 };
409
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300410 struct {
411 unsigned char r[4];
412 int len;
413 } regs[] = {
414 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
415 {{ 0x01, 0x02 }, 2},
416 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
417 {{ 0x01, 0x00 }, 2},
418 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
419 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
420 {{ 0x01, 0x00 }, 2},
421 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
422 {{ 0x04, 0x00 }, 2},
423 {{ 0x00, 0x04 }, 2},
424 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
425 {{ 0x04, 0x14 }, 2},
426 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
427 };
428
429 em28xx_gpio_set(dev, hauppauge_hvr930c_init);
430 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
431 msleep(10);
432 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
433 msleep(10);
434
435 dev->i2c_client.addr = 0x82 >> 1;
436
437 for (i = 0; i < ARRAY_SIZE(regs); i++)
438 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
439 em28xx_gpio_set(dev, hauppauge_hvr930c_end);
440
441 msleep(100);
442
443 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
444 msleep(30);
445
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -0300446 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
447 msleep(10);
448
449}
450
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300451static void terratec_h5_init(struct em28xx *dev)
452{
453 int i;
454 struct em28xx_reg_seq terratec_h5_init[] = {
455 {EM28XX_R08_GPIO, 0xff, 0xff, 10},
456 {EM2874_R80_GPIO, 0xf6, 0xff, 100},
457 {EM2874_R80_GPIO, 0xf2, 0xff, 50},
458 {EM2874_R80_GPIO, 0xf6, 0xff, 100},
459 { -1, -1, -1, -1},
460 };
461 struct em28xx_reg_seq terratec_h5_end[] = {
462 {EM2874_R80_GPIO, 0xe6, 0xff, 100},
463 {EM2874_R80_GPIO, 0xa6, 0xff, 50},
464 {EM2874_R80_GPIO, 0xe6, 0xff, 100},
465 { -1, -1, -1, -1},
466 };
467 struct {
468 unsigned char r[4];
469 int len;
470 } regs[] = {
471 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
472 {{ 0x01, 0x02 }, 2},
473 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
474 {{ 0x01, 0x00 }, 2},
475 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
476 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
477 {{ 0x01, 0x00 }, 2},
478 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
479 {{ 0x04, 0x00 }, 2},
480 {{ 0x00, 0x04 }, 2},
481 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
482 {{ 0x04, 0x14 }, 2},
483 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
484 };
485
486 em28xx_gpio_set(dev, terratec_h5_init);
487 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
488 msleep(10);
489 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
490 msleep(10);
491
492 dev->i2c_client.addr = 0x82 >> 1;
493
494 for (i = 0; i < ARRAY_SIZE(regs); i++)
495 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
496 em28xx_gpio_set(dev, terratec_h5_end);
497};
498
Martin Blumenstinglc8dce002012-06-12 18:19:28 -0300499static void terratec_htc_stick_init(struct em28xx *dev)
500{
501 int i;
502
503 /*
504 * GPIO configuration:
505 * 0xff: unknown (does not affect DVB-T).
506 * 0xf6: DRX-K (demodulator).
507 * 0xe6: unknown (does not affect DVB-T).
508 * 0xb6: unknown (does not affect DVB-T).
509 */
510 struct em28xx_reg_seq terratec_htc_stick_init[] = {
511 {EM28XX_R08_GPIO, 0xff, 0xff, 10},
512 {EM2874_R80_GPIO, 0xf6, 0xff, 100},
513 {EM2874_R80_GPIO, 0xe6, 0xff, 50},
514 {EM2874_R80_GPIO, 0xf6, 0xff, 100},
515 { -1, -1, -1, -1},
516 };
517 struct em28xx_reg_seq terratec_htc_stick_end[] = {
518 {EM2874_R80_GPIO, 0xb6, 0xff, 100},
519 {EM2874_R80_GPIO, 0xf6, 0xff, 50},
520 { -1, -1, -1, -1},
521 };
522
523 /* Init the analog decoder? */
524 struct {
525 unsigned char r[4];
526 int len;
527 } regs[] = {
528 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
529 {{ 0x01, 0x02 }, 2},
530 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
531 {{ 0x01, 0x00 }, 2},
532 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
533 };
534
535 em28xx_gpio_set(dev, terratec_htc_stick_init);
536
537 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
538 msleep(10);
539 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
540 msleep(10);
541
542 dev->i2c_client.addr = 0x82 >> 1;
543
544 for (i = 0; i < ARRAY_SIZE(regs); i++)
545 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
546
547 em28xx_gpio_set(dev, terratec_htc_stick_end);
548};
549
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300550static void pctv_520e_init(struct em28xx *dev)
551{
552 /*
Antti Palosaari26c8a722012-05-17 18:22:02 -0300553 * Init AVF4910B analog decoder. Looks like I2C traffic to
554 * digital demodulator and tuner are routed via AVF4910B.
Antti Palosaaric247d7b2012-03-19 11:48:19 -0300555 */
556 int i;
557 struct {
558 unsigned char r[4];
559 int len;
560 } regs[] = {
561 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
562 {{ 0x01, 0x02 }, 2},
563 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
564 {{ 0x01, 0x00 }, 2},
565 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
566 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
567 {{ 0x01, 0x00 }, 2},
568 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
569 };
570
571 dev->i2c_client.addr = 0x82 >> 1; /* 0x41 */
572
573 for (i = 0; i < ARRAY_SIZE(regs); i++)
574 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
575};
576
Antti Palosaari33eebec2012-10-03 04:28:56 -0300577static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
Antti Palosaari13a53362012-07-19 22:28:56 -0300578{
Antti Palosaari33eebec2012-10-03 04:28:56 -0300579 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
Antti Palosaari13a53362012-07-19 22:28:56 -0300580 struct em28xx *dev = fe->dvb->priv;
581#ifdef CONFIG_GPIOLIB
582 struct em28xx_dvb *dvb = dev->dvb;
583 int ret;
584 unsigned long flags;
585
Antti Palosaari33eebec2012-10-03 04:28:56 -0300586 if (c->lna == 1)
587 flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
Antti Palosaari13a53362012-07-19 22:28:56 -0300588 else
Antti Palosaari33eebec2012-10-03 04:28:56 -0300589 flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
Antti Palosaari13a53362012-07-19 22:28:56 -0300590
591 ret = gpio_request_one(dvb->lna_gpio, flags, NULL);
592 if (ret)
593 em28xx_errdev("gpio request failed %d\n", ret);
594 else
595 gpio_free(dvb->lna_gpio);
596
597 return ret;
598#else
Antti Palosaari33eebec2012-10-03 04:28:56 -0300599 dev_warn(&dev->udev->dev, "%s: LNA control is disabled (lna=%u)\n",
600 KBUILD_MODNAME, c->lna);
Antti Palosaari13a53362012-07-19 22:28:56 -0300601 return 0;
602#endif
603}
604
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300605static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300606{
607 /* Values extracted from a USB trace of the Terratec Windows driver */
608 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
609 static u8 reset[] = { RESET, 0x80 };
610 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
611 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
612 static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
613 static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
614 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
615 static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
616 static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
Devin Heitmuellerff697862009-07-12 18:44:19 -0300617 static u8 tuner_go[] = { TUNER_GO, 0x01};
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300618
619 mt352_write(fe, clock_config, sizeof(clock_config));
620 udelay(200);
621 mt352_write(fe, reset, sizeof(reset));
622 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
623 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
624 mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
625 mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
626 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
627 mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
628 mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
629 mt352_write(fe, tuner_go, sizeof(tuner_go));
630 return 0;
631}
632
633static struct mt352_config terratec_xs_mt352_cfg = {
634 .demod_address = (0x1e >> 1),
635 .no_tuner = 1,
636 .if2 = 45600,
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300637 .demod_init = em28xx_mt352_terratec_xs_init,
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300638};
639
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300640static struct tda10023_config em28xx_tda10023_config = {
641 .demod_address = 0x0c,
642 .invert = 1,
643};
644
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300645static struct cxd2820r_config em28xx_cxd2820r_config = {
646 .i2c_address = (0xd8 >> 1),
647 .ts_mode = CXD2820R_TS_SERIAL,
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300648};
649
650static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
651 .output_opt = TDA18271_OUTPUT_LT_OFF,
Steve Kerrison0db4bf42011-08-09 07:16:21 -0300652 .gate = TDA18271_GATE_DIGITAL,
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300653};
654
Antti Palosaari36588712011-08-01 01:15:30 -0300655static const struct tda10071_config em28xx_tda10071_config = {
656 .i2c_address = 0x55, /* (0xaa >> 1) */
657 .i2c_wr_max = 64,
658 .ts_mode = TDA10071_TS_SERIAL,
659 .spec_inv = 0,
660 .xtal = 40444000, /* 40.444 MHz */
661 .pll_multiplier = 20,
662};
663
664static const struct a8293_config em28xx_a8293_config = {
665 .i2c_addr = 0x08, /* (0x10 >> 1) */
666};
667
Aivar Päkk1985f6f2011-12-11 18:15:00 -0300668static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
669 .demod_address = (0x1e >> 1),
670 .disable_i2c_gate_ctrl = 1,
671 .no_tuner = 1,
672 .parallel_ts = 1,
673};
674static struct qt1010_config em28xx_qt1010_config = {
675 .i2c_address = 0x62
676
677};
678
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300679/* ------------------------------------------------------------------ */
680
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300681static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300682{
683 struct dvb_frontend *fe;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300684 struct xc2028_config cfg;
685
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300686 memset(&cfg, 0, sizeof(cfg));
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300687 cfg.i2c_adap = &dev->i2c_adap;
688 cfg.i2c_addr = addr;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300689
Antti Palosaarif71095b2011-04-07 15:51:52 -0300690 if (!dev->dvb->fe[0]) {
Filipe Rosset480be182009-11-04 15:32:37 -0300691 em28xx_errdev("/2: dvb frontend not attached. "
692 "Can't attach xc3028\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300693 return -EINVAL;
694 }
695
Antti Palosaarif71095b2011-04-07 15:51:52 -0300696 fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300697 if (!fe) {
Filipe Rosset480be182009-11-04 15:32:37 -0300698 em28xx_errdev("/2: xc3028 attach failed\n");
Antti Palosaarif71095b2011-04-07 15:51:52 -0300699 dvb_frontend_detach(dev->dvb->fe[0]);
700 dev->dvb->fe[0] = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300701 return -EINVAL;
702 }
703
Filipe Rosset480be182009-11-04 15:32:37 -0300704 em28xx_info("%s/2: xc3028 attached\n", dev->name);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300705
706 return 0;
707}
708
Aidan Thornton3421b772008-04-17 21:40:36 -0300709/* ------------------------------------------------------------------ */
710
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300711static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
712 struct em28xx *dev, struct device *device)
Aidan Thornton3421b772008-04-17 21:40:36 -0300713{
714 int result;
715
716 mutex_init(&dvb->lock);
717
718 /* register adapter */
719 result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
720 adapter_nr);
721 if (result < 0) {
722 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
723 dev->name, result);
724 goto fail_adapter;
725 }
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300726
727 /* Ensure all frontends negotiate bus access */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300728 dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
729 if (dvb->fe[1])
730 dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300731
Aidan Thornton3421b772008-04-17 21:40:36 -0300732 dvb->adapter.priv = dev;
733
734 /* register frontend */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300735 result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300736 if (result < 0) {
737 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
738 dev->name, result);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300739 goto fail_frontend0;
740 }
741
742 /* register 2nd frontend */
743 if (dvb->fe[1]) {
744 result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
745 if (result < 0) {
746 printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
747 dev->name, result);
748 goto fail_frontend1;
749 }
Aidan Thornton3421b772008-04-17 21:40:36 -0300750 }
751
752 /* register demux stuff */
753 dvb->demux.dmx.capabilities =
754 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
755 DMX_MEMORY_BASED_FILTERING;
756 dvb->demux.priv = dvb;
757 dvb->demux.filternum = 256;
758 dvb->demux.feednum = 256;
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300759 dvb->demux.start_feed = em28xx_start_feed;
760 dvb->demux.stop_feed = em28xx_stop_feed;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300761
Aidan Thornton3421b772008-04-17 21:40:36 -0300762 result = dvb_dmx_init(&dvb->demux);
763 if (result < 0) {
764 printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
765 dev->name, result);
766 goto fail_dmx;
767 }
768
769 dvb->dmxdev.filternum = 256;
770 dvb->dmxdev.demux = &dvb->demux.dmx;
771 dvb->dmxdev.capabilities = 0;
772 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
773 if (result < 0) {
774 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
775 dev->name, result);
776 goto fail_dmxdev;
777 }
778
779 dvb->fe_hw.source = DMX_FRONTEND_0;
780 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
781 if (result < 0) {
782 printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
783 dev->name, result);
784 goto fail_fe_hw;
785 }
786
787 dvb->fe_mem.source = DMX_MEMORY_FE;
788 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
789 if (result < 0) {
790 printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
791 dev->name, result);
792 goto fail_fe_mem;
793 }
794
795 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
796 if (result < 0) {
797 printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
798 dev->name, result);
799 goto fail_fe_conn;
800 }
801
802 /* register network adapter */
803 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
804 return 0;
805
806fail_fe_conn:
807 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
808fail_fe_mem:
809 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
810fail_fe_hw:
811 dvb_dmxdev_release(&dvb->dmxdev);
812fail_dmxdev:
813 dvb_dmx_release(&dvb->demux);
814fail_dmx:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300815 if (dvb->fe[1])
816 dvb_unregister_frontend(dvb->fe[1]);
817 dvb_unregister_frontend(dvb->fe[0]);
818fail_frontend1:
819 if (dvb->fe[1])
820 dvb_frontend_detach(dvb->fe[1]);
821fail_frontend0:
822 dvb_frontend_detach(dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300823 dvb_unregister_adapter(&dvb->adapter);
824fail_adapter:
825 return result;
826}
827
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300828static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
Aidan Thornton3421b772008-04-17 21:40:36 -0300829{
830 dvb_net_release(&dvb->net);
831 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
832 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
833 dvb_dmxdev_release(&dvb->dmxdev);
834 dvb_dmx_release(&dvb->demux);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300835 if (dvb->fe[1])
836 dvb_unregister_frontend(dvb->fe[1]);
837 dvb_unregister_frontend(dvb->fe[0]);
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -0300838 if (dvb->fe[1] && !dvb->dont_attach_fe1)
Antti Palosaarif71095b2011-04-07 15:51:52 -0300839 dvb_frontend_detach(dvb->fe[1]);
840 dvb_frontend_detach(dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300841 dvb_unregister_adapter(&dvb->adapter);
842}
843
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300844static int em28xx_dvb_init(struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300845{
Antti Palosaari13a53362012-07-19 22:28:56 -0300846 int result = 0, mfe_shared = 0;
Aidan Thornton3421b772008-04-17 21:40:36 -0300847 struct em28xx_dvb *dvb;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300848
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -0300849 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -0300850 /* This device does not support the extension */
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300851 printk(KERN_INFO "em28xx_dvb: This device does not support the extension\n");
Devin Heitmuellerdf619182008-06-10 12:34:35 -0300852 return 0;
853 }
854
Aidan Thornton3421b772008-04-17 21:40:36 -0300855 dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300856
857 if (dvb == NULL) {
Filipe Rosset480be182009-11-04 15:32:37 -0300858 em28xx_info("em28xx_dvb: memory allocation failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -0300859 return -ENOMEM;
860 }
861 dev->dvb = dvb;
Antti Palosaarif71095b2011-04-07 15:51:52 -0300862 dvb->fe[0] = dvb->fe[1] = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300863
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -0300864 mutex_lock(&dev->lock);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300865 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300866 /* init frontend */
867 switch (dev->model) {
Mauro Carvalho Chehabebaefdb2011-06-01 10:16:25 -0300868 case EM2874_BOARD_LEADERSHIP_ISDBT:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300869 dvb->fe[0] = dvb_attach(s921_attach,
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300870 &sharp_isdbt, &dev->i2c_adap);
871
Antti Palosaarif71095b2011-04-07 15:51:52 -0300872 if (!dvb->fe[0]) {
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300873 result = -EINVAL;
874 goto out_free;
875 }
876
877 break;
Douglas Schilling Landgraff89bc322008-12-01 21:01:04 -0300878 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
Mauro Carvalho Chehab10ac6602008-07-27 14:58:58 -0300879 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
Devin Heitmueller4fd305b2008-06-04 13:43:46 -0300880 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
Devin Heitmuellere14b3652008-07-26 11:04:33 -0300881 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300882 dvb->fe[0] = dvb_attach(lgdt330x_attach,
Aidan Thornton3421b772008-04-17 21:40:36 -0300883 &em2880_lgdt3303_dev,
884 &dev->i2c_adap);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300885 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Aidan Thornton3421b772008-04-17 21:40:36 -0300886 result = -EINVAL;
887 goto out_free;
888 }
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -0300889 break;
Thierry MERLE46510b52008-10-11 16:56:13 -0300890 case EM2880_BOARD_KWORLD_DVB_310U:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300891 dvb->fe[0] = dvb_attach(zl10353_attach,
Aidan Thornton3421b772008-04-17 21:40:36 -0300892 &em28xx_zl10353_with_xc3028,
893 &dev->i2c_adap);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300894 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Aidan Thornton3421b772008-04-17 21:40:36 -0300895 result = -EINVAL;
896 goto out_free;
897 }
Aidan Thornton7e6388a2008-04-17 21:40:03 -0300898 break;
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300899 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
Uroš Vamplec994d02009-09-30 22:53:37 -0300900 case EM2882_BOARD_TERRATEC_HYBRID_XS:
Devin Heitmueller01a5fd62009-08-07 09:25:06 -0300901 case EM2880_BOARD_EMPIRE_DUAL_TV:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300902 dvb->fe[0] = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300903 &em28xx_zl10353_xc3028_no_i2c_gate,
904 &dev->i2c_adap);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300905 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300906 result = -EINVAL;
907 goto out_free;
908 }
909 break;
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300910 case EM2880_BOARD_TERRATEC_HYBRID_XS:
Catimimi65638012010-02-18 18:06:32 -0300911 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
Devin Heitmuellerd5b3ba92009-07-08 21:51:35 -0300912 case EM2881_BOARD_PINNACLE_HYBRID_PRO:
Andrea.Amorosi76@gmail.com7ca7ef62010-02-09 17:53:38 -0300913 case EM2882_BOARD_DIKOM_DK300:
Antonio Larrosa811fab62010-03-04 22:19:48 -0300914 case EM2882_BOARD_KWORLD_VS_DVBT:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300915 dvb->fe[0] = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300916 &em28xx_zl10353_xc3028_no_i2c_gate,
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300917 &dev->i2c_adap);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300918 if (dvb->fe[0] == NULL) {
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300919 /* This board could have either a zl10353 or a mt352.
920 If the chip id isn't for zl10353, try mt352 */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300921 dvb->fe[0] = dvb_attach(mt352_attach,
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300922 &terratec_xs_mt352_cfg,
923 &dev->i2c_adap);
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300924 }
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300925
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300926 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300927 result = -EINVAL;
928 goto out_free;
929 }
930 break;
Aivar Päkk1985f6f2011-12-11 18:15:00 -0300931 case EM2870_BOARD_KWORLD_355U:
932 dvb->fe[0] = dvb_attach(zl10353_attach,
933 &em28xx_zl10353_no_i2c_gate_dev,
934 &dev->i2c_adap);
935 if (dvb->fe[0] != NULL)
936 dvb_attach(qt1010_attach, dvb->fe[0],
937 &dev->i2c_adap, &em28xx_qt1010_config);
938 break;
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300939 case EM2883_BOARD_KWORLD_HYBRID_330U:
Devin Heitmueller19859222009-06-19 00:33:54 -0300940 case EM2882_BOARD_EVGA_INDTUBE:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300941 dvb->fe[0] = dvb_attach(s5h1409_attach,
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300942 &em28xx_s5h1409_with_xc3028,
943 &dev->i2c_adap);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300944 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300945 result = -EINVAL;
946 goto out_free;
947 }
948 break;
Franklin Mengd7de5d82009-06-06 17:05:02 -0300949 case EM2882_BOARD_KWORLD_ATSC_315U:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300950 dvb->fe[0] = dvb_attach(lgdt330x_attach,
Franklin Mengd7de5d82009-06-06 17:05:02 -0300951 &em2880_lgdt3303_dev,
952 &dev->i2c_adap);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300953 if (dvb->fe[0] != NULL) {
954 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
Franklin Mengd7de5d82009-06-06 17:05:02 -0300955 &dev->i2c_adap, 0x61, TUNER_THOMSON_DTT761X)) {
956 result = -EINVAL;
957 goto out_free;
958 }
959 }
960 break;
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300961 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
Devin Heitmuellerad9b4bb2011-03-13 02:09:59 -0300962 case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300963 dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
Devin Heitmueller75e2b862011-03-13 02:01:02 -0300964 &dev->i2c_adap, &dev->udev->dev);
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -0300965 if (em28xx_attach_xc3028(0x61, dev) < 0) {
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300966 result = -EINVAL;
967 goto out_free;
968 }
969 break;
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300970 case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
971 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300972 dvb->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300973 &em28xx_tda10023_config,
974 &dev->i2c_adap, 0x48);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300975 if (dvb->fe[0]) {
976 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300977 &dev->i2c_adap, 0x60, TUNER_PHILIPS_CU1216L)) {
978 result = -EINVAL;
979 goto out_free;
980 }
981 }
982 break;
Jarod Wilson7e48b302010-03-07 17:55:43 -0300983 case EM2870_BOARD_KWORLD_A340:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300984 dvb->fe[0] = dvb_attach(lgdt3305_attach,
Jarod Wilson7e48b302010-03-07 17:55:43 -0300985 &em2870_lgdt3304_dev,
986 &dev->i2c_adap);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300987 if (dvb->fe[0] != NULL)
988 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Jarod Wilson7e48b302010-03-07 17:55:43 -0300989 &dev->i2c_adap, &kworld_a340_config);
990 break;
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300991 case EM28174_BOARD_PCTV_290E:
Antti Palosaaria36a66d2012-08-16 21:07:23 -0300992 /* set default GPIO0 for LNA, used if GPIOLIB is undefined */
993 dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O |
994 CXD2820R_GPIO_L;
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300995 dvb->fe[0] = dvb_attach(cxd2820r_attach,
Manu Abraham7e7b8282011-12-10 00:44:24 -0300996 &em28xx_cxd2820r_config,
Antti Palosaari1e8f31f2012-07-19 21:10:36 -0300997 &dev->i2c_adap,
Antti Palosaari13a53362012-07-19 22:28:56 -0300998 &dvb->lna_gpio);
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300999 if (dvb->fe[0]) {
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001000 /* FE 0 attach tuner */
Manu Abraham7e7b8282011-12-10 00:44:24 -03001001 if (!dvb_attach(tda18271_attach,
1002 dvb->fe[0],
1003 0x60,
1004 &dev->i2c_adap,
1005 &em28xx_cxd2820r_tda18271_config)) {
1006
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001007 dvb_frontend_detach(dvb->fe[0]);
1008 result = -EINVAL;
1009 goto out_free;
1010 }
Antti Palosaari1e8f31f2012-07-19 21:10:36 -03001011
Antti Palosaari13a53362012-07-19 22:28:56 -03001012#ifdef CONFIG_GPIOLIB
Antti Palosaari0c42a552012-09-19 20:52:21 -03001013 /* enable LNA for DVB-T, DVB-T2 and DVB-C */
1014 result = gpio_request_one(dvb->lna_gpio,
1015 GPIOF_OUT_INIT_LOW, NULL);
1016 if (result)
1017 em28xx_errdev("gpio request failed %d\n",
1018 result);
1019 else
1020 gpio_free(dvb->lna_gpio);
Antti Palosaari1e8f31f2012-07-19 21:10:36 -03001021
Antti Palosaari0c42a552012-09-19 20:52:21 -03001022 result = 0; /* continue even set LNA fails */
Antti Palosaari13a53362012-07-19 22:28:56 -03001023#endif
Antti Palosaari0c42a552012-09-19 20:52:21 -03001024 dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
1025 }
1026
Antti Palosaarid6a5f922011-04-07 16:34:44 -03001027 break;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001028 case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
Mauro Carvalho Chehab85032322011-11-24 15:01:45 -02001029 {
1030 struct xc5000_config cfg;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001031 hauppauge_hvr930c_init(dev);
1032
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001033 dvb->fe[0] = dvb_attach(drxk_attach,
Mauro Carvalho Chehabfa4b2a12012-01-05 08:07:32 -02001034 &hauppauge_930c_drxk, &dev->i2c_adap);
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001035 if (!dvb->fe[0]) {
1036 result = -EINVAL;
1037 goto out_free;
1038 }
1039 /* FIXME: do we need a pll semaphore? */
1040 dvb->fe[0]->sec_priv = dvb;
1041 sema_init(&dvb->pll_mutex, 1);
1042 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1043 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001044
1045 /* Attach xc5000 */
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001046 memset(&cfg, 0, sizeof(cfg));
1047 cfg.i2c_address = 0x61;
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001048 cfg.if_khz = 4000;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001049
1050 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1051 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001052 if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap,
1053 &cfg)) {
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001054 result = -EINVAL;
1055 goto out_free;
1056 }
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001057 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1058 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1059
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001060 break;
Mauro Carvalho Chehab85032322011-11-24 15:01:45 -02001061 }
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001062 case EM2884_BOARD_TERRATEC_H5:
1063 terratec_h5_init(dev);
1064
Mauro Carvalho Chehabfa4b2a12012-01-05 08:07:32 -02001065 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap);
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -03001066 if (!dvb->fe[0]) {
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001067 result = -EINVAL;
1068 goto out_free;
1069 }
1070 /* FIXME: do we need a pll semaphore? */
1071 dvb->fe[0]->sec_priv = dvb;
1072 sema_init(&dvb->pll_mutex, 1);
1073 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1074 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001075
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -03001076 /* Attach tda18271 to DVB-C frontend */
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001077 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1078 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1079 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap, 0x60)) {
1080 result = -EINVAL;
1081 goto out_free;
1082 }
1083 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1084 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
Mauro Carvalho Chehabc4c3a3d2011-07-14 22:23:18 -03001085
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -03001086 break;
Antti Palosaari36588712011-08-01 01:15:30 -03001087 case EM28174_BOARD_PCTV_460E:
1088 /* attach demod */
1089 dvb->fe[0] = dvb_attach(tda10071_attach,
1090 &em28xx_tda10071_config, &dev->i2c_adap);
1091
1092 /* attach SEC */
1093 if (dvb->fe[0])
1094 dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap,
1095 &em28xx_a8293_config);
1096 break;
Antti Palosaari35530852012-03-18 18:09:01 -03001097 case EM2874_BOARD_MAXMEDIA_UB425_TC:
1098 /* attach demodulator */
1099 dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
1100 &dev->i2c_adap);
1101
1102 if (dvb->fe[0]) {
1103 /* disable I2C-gate */
1104 dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
1105
1106 /* attach tuner */
1107 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0],
1108 &dev->i2c_adap, 0x60)) {
1109 dvb_frontend_detach(dvb->fe[0]);
1110 result = -EINVAL;
1111 goto out_free;
1112 }
1113 }
1114
1115 /* TODO: we need drx-3913k firmware in order to support DVB-T */
1116 em28xx_info("MaxMedia UB425-TC: only DVB-C supported by that " \
1117 "driver version\n");
1118
1119 break;
Ivan Kalvachevfa5527c2012-03-19 20:09:55 -03001120 case EM2884_BOARD_PCTV_510E:
1121 case EM2884_BOARD_PCTV_520E:
1122 pctv_520e_init(dev);
1123
1124 /* attach demodulator */
1125 dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
1126 &dev->i2c_adap);
1127
1128 if (dvb->fe[0]) {
1129 /* attach tuner */
1130 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1131 &dev->i2c_adap,
1132 &em28xx_cxd2820r_tda18271_config)) {
1133 dvb_frontend_detach(dvb->fe[0]);
1134 result = -EINVAL;
1135 goto out_free;
1136 }
1137 }
1138 break;
Martin Blumenstinglc8dce002012-06-12 18:19:28 -03001139 case EM2884_BOARD_CINERGY_HTC_STICK:
1140 terratec_htc_stick_init(dev);
1141
1142 /* attach demodulator */
1143 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1144 &dev->i2c_adap);
1145 if (!dvb->fe[0]) {
1146 result = -EINVAL;
1147 goto out_free;
1148 }
1149
1150 /* Attach the demodulator. */
1151 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1152 &dev->i2c_adap,
1153 &em28xx_cxd2820r_tda18271_config)) {
1154 result = -EINVAL;
1155 goto out_free;
1156 }
1157 break;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001158 default:
Filipe Rosset480be182009-11-04 15:32:37 -03001159 em28xx_errdev("/2: The frontend of your DVB/ATSC card"
1160 " isn't supported yet\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001161 break;
1162 }
Antti Palosaarif71095b2011-04-07 15:51:52 -03001163 if (NULL == dvb->fe[0]) {
Filipe Rosset480be182009-11-04 15:32:37 -03001164 em28xx_errdev("/2: frontend initialization failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -03001165 result = -EINVAL;
1166 goto out_free;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001167 }
Michael Krufkyd7cba042008-09-12 13:31:45 -03001168 /* define general-purpose callback pointer */
Antti Palosaarif71095b2011-04-07 15:51:52 -03001169 dvb->fe[0]->callback = em28xx_tuner_callback;
Eddi De Pieri82e7dbb2011-11-19 11:37:14 -03001170 if (dvb->fe[1])
Mauro Carvalho Chehabde724052011-11-20 11:23:24 -02001171 dvb->fe[1]->callback = em28xx_tuner_callback;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001172
1173 /* register everything */
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001174 result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
Aidan Thornton3421b772008-04-17 21:40:36 -03001175
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -03001176 if (result < 0)
Aidan Thornton3421b772008-04-17 21:40:36 -03001177 goto out_free;
Aidan Thornton3421b772008-04-17 21:40:36 -03001178
Antti Palosaarie3645432011-07-28 18:59:30 -03001179 /* MFE lock */
1180 dvb->adapter.mfe_shared = mfe_shared;
1181
Filipe Rosset480be182009-11-04 15:32:37 -03001182 em28xx_info("Successfully loaded em28xx-dvb\n");
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -03001183ret:
1184 em28xx_set_mode(dev, EM28XX_SUSPEND);
1185 mutex_unlock(&dev->lock);
1186 return result;
Aidan Thornton3421b772008-04-17 21:40:36 -03001187
1188out_free:
1189 kfree(dvb);
1190 dev->dvb = NULL;
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -03001191 goto ret;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001192}
1193
Chris Rankin0b8bd832011-08-20 16:01:26 -03001194static inline void prevent_sleep(struct dvb_frontend_ops *ops)
1195{
1196 ops->set_voltage = NULL;
1197 ops->sleep = NULL;
1198 ops->tuner_ops.sleep = NULL;
1199}
1200
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001201static int em28xx_dvb_fini(struct em28xx *dev)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001202{
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -03001203 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -03001204 /* This device does not support the extension */
1205 return 0;
1206 }
1207
Aidan Thornton3421b772008-04-17 21:40:36 -03001208 if (dev->dvb) {
Chris Rankin0b8bd832011-08-20 16:01:26 -03001209 struct em28xx_dvb *dvb = dev->dvb;
1210
1211 if (dev->state & DEV_DISCONNECTED) {
1212 /* We cannot tell the device to sleep
1213 * once it has been unplugged. */
1214 if (dvb->fe[0])
1215 prevent_sleep(&dvb->fe[0]->ops);
1216 if (dvb->fe[1])
1217 prevent_sleep(&dvb->fe[1]->ops);
1218 }
1219
1220 em28xx_unregister_dvb(dvb);
1221 kfree(dvb);
Aidan Thornton3421b772008-04-17 21:40:36 -03001222 dev->dvb = NULL;
1223 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001224
1225 return 0;
1226}
1227
1228static struct em28xx_ops dvb_ops = {
1229 .id = EM28XX_DVB,
1230 .name = "Em28xx dvb Extension",
Jarod Wilsonf2d0c1c2011-07-14 19:06:08 -03001231 .init = em28xx_dvb_init,
1232 .fini = em28xx_dvb_fini,
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001233};
1234
1235static int __init em28xx_dvb_register(void)
1236{
1237 return em28xx_register_extension(&dvb_ops);
1238}
1239
1240static void __exit em28xx_dvb_unregister(void)
1241{
1242 em28xx_unregister_extension(&dvb_ops);
1243}
1244
1245module_init(em28xx_dvb_register);
1246module_exit(em28xx_dvb_unregister);