blob: 9b2be03c82e8628e3308c87be84ba9ce5f2946de [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"
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030045
46MODULE_DESCRIPTION("driver for em28xx based DVB cards");
47MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
48MODULE_LICENSE("GPL");
49
50static unsigned int debug;
51module_param(debug, int, 0644);
52MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
53
54DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
55
56#define dprintk(level, fmt, arg...) do { \
57if (debug >= level) \
Aidan Thornton3421b772008-04-17 21:40:36 -030058 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030059} while (0)
60
Aidan Thornton3421b772008-04-17 21:40:36 -030061#define EM28XX_DVB_NUM_BUFS 5
Aidan Thornton3421b772008-04-17 21:40:36 -030062#define EM28XX_DVB_MAX_PACKETS 64
63
64struct em28xx_dvb {
Antti Palosaarif71095b2011-04-07 15:51:52 -030065 struct dvb_frontend *fe[2];
Aidan Thornton3421b772008-04-17 21:40:36 -030066
67 /* feed count management */
68 struct mutex lock;
69 int nfeeds;
70
71 /* general boilerplate stuff */
72 struct dvb_adapter adapter;
73 struct dvb_demux demux;
74 struct dmxdev dmxdev;
75 struct dmx_frontend fe_hw;
76 struct dmx_frontend fe_mem;
77 struct dvb_net net;
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -030078
79 /* Due to DRX-D - probably need changes */
80 int (*gate_ctrl)(struct dvb_frontend *, int);
81 struct semaphore pll_mutex;
Aidan Thornton3421b772008-04-17 21:40:36 -030082};
83
84
85static inline void print_err_status(struct em28xx *dev,
86 int packet, int status)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030087{
Aidan Thornton3421b772008-04-17 21:40:36 -030088 char *errmsg = "Unknown";
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030089
Aidan Thornton3421b772008-04-17 21:40:36 -030090 switch (status) {
91 case -ENOENT:
92 errmsg = "unlinked synchronuously";
93 break;
94 case -ECONNRESET:
95 errmsg = "unlinked asynchronuously";
96 break;
97 case -ENOSR:
98 errmsg = "Buffer error (overrun)";
99 break;
100 case -EPIPE:
101 errmsg = "Stalled (device not responding)";
102 break;
103 case -EOVERFLOW:
104 errmsg = "Babble (bad cable?)";
105 break;
106 case -EPROTO:
107 errmsg = "Bit-stuff error (bad cable?)";
108 break;
109 case -EILSEQ:
110 errmsg = "CRC/Timeout (could be anything)";
111 break;
112 case -ETIME:
113 errmsg = "Device does not respond";
114 break;
115 }
116 if (packet < 0) {
117 dprintk(1, "URB status %d [%s].\n", status, errmsg);
118 } else {
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300119 dprintk(1, "URB packet %d, status %d [%s].\n",
120 packet, status, errmsg);
Aidan Thornton3421b772008-04-17 21:40:36 -0300121 }
122}
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300123
Aidan Thornton3421b772008-04-17 21:40:36 -0300124static inline int dvb_isoc_copy(struct em28xx *dev, struct urb *urb)
125{
126 int i;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300127
Aidan Thornton3421b772008-04-17 21:40:36 -0300128 if (!dev)
129 return 0;
130
131 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
132 return 0;
133
134 if (urb->status < 0) {
135 print_err_status(dev, -1, urb->status);
136 if (urb->status == -ENOENT)
137 return 0;
138 }
139
140 for (i = 0; i < urb->number_of_packets; i++) {
141 int status = urb->iso_frame_desc[i].status;
142
143 if (status < 0) {
144 print_err_status(dev, i, status);
145 if (urb->iso_frame_desc[i].status != -EPROTO)
146 continue;
147 }
148
149 dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer +
150 urb->iso_frame_desc[i].offset,
151 urb->iso_frame_desc[i].actual_length);
152 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300153
154 return 0;
155}
156
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300157static int start_streaming(struct em28xx_dvb *dvb)
158{
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300159 int rc;
Aidan Thornton3421b772008-04-17 21:40:36 -0300160 struct em28xx *dev = dvb->adapter.priv;
Devin Heitmuellerd18e2fd2009-05-16 17:09:28 -0300161 int max_dvb_packet_size;
Aidan Thornton3421b772008-04-17 21:40:36 -0300162
163 usb_set_interface(dev->udev, 0, 1);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300164 rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
165 if (rc < 0)
166 return rc;
Aidan Thornton3421b772008-04-17 21:40:36 -0300167
Devin Heitmuellerd18e2fd2009-05-16 17:09:28 -0300168 max_dvb_packet_size = em28xx_isoc_dvb_max_packetsize(dev);
169
Aidan Thornton3421b772008-04-17 21:40:36 -0300170 return em28xx_init_isoc(dev, EM28XX_DVB_MAX_PACKETS,
Devin Heitmuellerd18e2fd2009-05-16 17:09:28 -0300171 EM28XX_DVB_NUM_BUFS, max_dvb_packet_size,
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300172 dvb_isoc_copy);
Aidan Thornton3421b772008-04-17 21:40:36 -0300173}
174
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300175static int stop_streaming(struct em28xx_dvb *dvb)
176{
Aidan Thornton3421b772008-04-17 21:40:36 -0300177 struct em28xx *dev = dvb->adapter.priv;
178
179 em28xx_uninit_isoc(dev);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300180
Mauro Carvalho Chehab2fe3e2e2008-11-27 09:10:40 -0300181 em28xx_set_mode(dev, EM28XX_SUSPEND);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300182
Aidan Thornton3421b772008-04-17 21:40:36 -0300183 return 0;
184}
185
186static int start_feed(struct dvb_demux_feed *feed)
187{
188 struct dvb_demux *demux = feed->demux;
189 struct em28xx_dvb *dvb = demux->priv;
190 int rc, ret;
191
192 if (!demux->dmx.frontend)
193 return -EINVAL;
194
195 mutex_lock(&dvb->lock);
196 dvb->nfeeds++;
197 rc = dvb->nfeeds;
198
199 if (dvb->nfeeds == 1) {
200 ret = start_streaming(dvb);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300201 if (ret < 0)
202 rc = ret;
Aidan Thornton3421b772008-04-17 21:40:36 -0300203 }
204
205 mutex_unlock(&dvb->lock);
206 return rc;
207}
208
209static int stop_feed(struct dvb_demux_feed *feed)
210{
211 struct dvb_demux *demux = feed->demux;
212 struct em28xx_dvb *dvb = demux->priv;
213 int err = 0;
214
215 mutex_lock(&dvb->lock);
216 dvb->nfeeds--;
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300217
218 if (0 == dvb->nfeeds)
Aidan Thornton3421b772008-04-17 21:40:36 -0300219 err = stop_streaming(dvb);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300220
Aidan Thornton3421b772008-04-17 21:40:36 -0300221 mutex_unlock(&dvb->lock);
222 return err;
223}
224
225
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300226
227/* ------------------------------------------------------------------ */
228static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
229{
230 struct em28xx *dev = fe->dvb->priv;
231
232 if (acquire)
233 return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
234 else
Mauro Carvalho Chehab2fe3e2e2008-11-27 09:10:40 -0300235 return em28xx_set_mode(dev, EM28XX_SUSPEND);
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300236}
237
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300238/* ------------------------------------------------------------------ */
239
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -0300240static struct lgdt330x_config em2880_lgdt3303_dev = {
241 .demod_address = 0x0e,
242 .demod_chip = LGDT3303,
243};
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300244
Jarod Wilson7e48b302010-03-07 17:55:43 -0300245static struct lgdt3305_config em2870_lgdt3304_dev = {
246 .i2c_addr = 0x0e,
247 .demod_chip = LGDT3304,
248 .spectral_inversion = 1,
249 .deny_i2c_rptr = 1,
250 .mpeg_mode = LGDT3305_MPEG_PARALLEL,
251 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
252 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
253 .vsb_if_khz = 3250,
254 .qam_if_khz = 4000,
255};
256
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300257static struct s921_config sharp_isdbt = {
258 .demod_address = 0x30 >> 1
259};
260
Aidan Thornton7e6388a2008-04-17 21:40:03 -0300261static struct zl10353_config em28xx_zl10353_with_xc3028 = {
262 .demod_address = (0x1e >> 1),
263 .no_tuner = 1,
264 .parallel_ts = 1,
265 .if2 = 45600,
266};
267
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300268static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
269 .demod_address = 0x32 >> 1,
270 .output_mode = S5H1409_PARALLEL_OUTPUT,
271 .gpio = S5H1409_GPIO_OFF,
272 .inversion = S5H1409_INVERSION_OFF,
273 .status_mode = S5H1409_DEMODLOCKING,
274 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
275};
276
Jarod Wilson7e48b302010-03-07 17:55:43 -0300277static struct tda18271_std_map kworld_a340_std_map = {
278 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
279 .if_lvl = 1, .rfagc_top = 0x37, },
280 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
281 .if_lvl = 1, .rfagc_top = 0x37, },
282};
283
284static struct tda18271_config kworld_a340_config = {
285 .std_map = &kworld_a340_std_map,
286};
287
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300288static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300289 .demod_address = (0x1e >> 1),
290 .no_tuner = 1,
291 .disable_i2c_gate_ctrl = 1,
292 .parallel_ts = 1,
293 .if2 = 45600,
294};
295
Devin Heitmueller75e2b862011-03-13 02:01:02 -0300296static struct drxd_config em28xx_drxd = {
297 .index = 0, .demod_address = 0x70, .demod_revision = 0xa2,
298 .demoda_address = 0x00, .pll_address = 0x00,
299 .pll_type = DRXD_PLL_NONE, .clock = 12000, .insert_rs_byte = 1,
300 .pll_set = NULL, .osc_deviation = NULL, .IF = 42800000,
Devin Heitmueller6b142b32011-03-13 02:02:01 -0300301 .disable_i2c_gate_ctrl = 1,
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300302};
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300303
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300304struct drxk_config terratec_h5_drxk = {
305 .adr = 0x29,
Mauro Carvalho Chehabe4f4f872011-07-09 17:35:26 -0300306 .single_master = 1,
Mauro Carvalho Chehabf1fe1b72011-07-09 21:59:33 -0300307 .no_i2c_bridge = 1,
Mauro Carvalho Chehabe4f4f872011-07-09 17:35:26 -0300308 .microcode_name = "terratec_h5.fw",
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300309};
310
311static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
312{
313 struct em28xx_dvb *dvb = fe->sec_priv;
314 int status;
315
316 if (!dvb)
317 return -EINVAL;
318
319 if (enable) {
320 down(&dvb->pll_mutex);
321 status = dvb->gate_ctrl(fe, 1);
322 } else {
323 status = dvb->gate_ctrl(fe, 0);
324 up(&dvb->pll_mutex);
325 }
326 return status;
327}
328
329static void terratec_h5_init(struct em28xx *dev)
330{
331 int i;
332 struct em28xx_reg_seq terratec_h5_init[] = {
333 {EM28XX_R08_GPIO, 0xff, 0xff, 10},
334 {EM2874_R80_GPIO, 0xf6, 0xff, 100},
335 {EM2874_R80_GPIO, 0xf2, 0xff, 50},
336 {EM2874_R80_GPIO, 0xf6, 0xff, 100},
337 { -1, -1, -1, -1},
338 };
339 struct em28xx_reg_seq terratec_h5_end[] = {
340 {EM2874_R80_GPIO, 0xe6, 0xff, 100},
341 {EM2874_R80_GPIO, 0xa6, 0xff, 50},
342 {EM2874_R80_GPIO, 0xe6, 0xff, 100},
343 { -1, -1, -1, -1},
344 };
345 struct {
346 unsigned char r[4];
347 int len;
348 } regs[] = {
349 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
350 {{ 0x01, 0x02 }, 2},
351 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
352 {{ 0x01, 0x00 }, 2},
353 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
354 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
355 {{ 0x01, 0x00 }, 2},
356 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
357 {{ 0x04, 0x00 }, 2},
358 {{ 0x00, 0x04 }, 2},
359 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
360 {{ 0x04, 0x14 }, 2},
361 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
362 };
363
364 em28xx_gpio_set(dev, terratec_h5_init);
365 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
366 msleep(10);
367 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
368 msleep(10);
369
370 dev->i2c_client.addr = 0x82 >> 1;
371
372 for (i = 0; i < ARRAY_SIZE(regs); i++)
373 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
374 em28xx_gpio_set(dev, terratec_h5_end);
375};
376
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300377static int mt352_terratec_xs_init(struct dvb_frontend *fe)
378{
379 /* Values extracted from a USB trace of the Terratec Windows driver */
380 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
381 static u8 reset[] = { RESET, 0x80 };
382 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
383 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
384 static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
385 static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
386 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
387 static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
388 static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
Devin Heitmuellerff697862009-07-12 18:44:19 -0300389 static u8 tuner_go[] = { TUNER_GO, 0x01};
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300390
391 mt352_write(fe, clock_config, sizeof(clock_config));
392 udelay(200);
393 mt352_write(fe, reset, sizeof(reset));
394 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
395 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
396 mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
397 mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
398 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
399 mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
400 mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
401 mt352_write(fe, tuner_go, sizeof(tuner_go));
402 return 0;
403}
404
405static struct mt352_config terratec_xs_mt352_cfg = {
406 .demod_address = (0x1e >> 1),
407 .no_tuner = 1,
408 .if2 = 45600,
409 .demod_init = mt352_terratec_xs_init,
410};
411
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300412static struct tda10023_config em28xx_tda10023_config = {
413 .demod_address = 0x0c,
414 .invert = 1,
415};
416
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300417static struct cxd2820r_config em28xx_cxd2820r_config = {
418 .i2c_address = (0xd8 >> 1),
419 .ts_mode = CXD2820R_TS_SERIAL,
420 .if_dvbt_6 = 3300,
421 .if_dvbt_7 = 3500,
422 .if_dvbt_8 = 4000,
423 .if_dvbt2_6 = 3300,
424 .if_dvbt2_7 = 3500,
425 .if_dvbt2_8 = 4000,
426 .if_dvbc = 5000,
427
428 /* enable LNA for DVB-T2 and DVB-C */
429 .gpio_dvbt2[0] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | CXD2820R_GPIO_L,
430 .gpio_dvbc[0] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | CXD2820R_GPIO_L,
431};
432
433static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
434 .output_opt = TDA18271_OUTPUT_LT_OFF,
435};
436
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300437/* ------------------------------------------------------------------ */
438
439static int attach_xc3028(u8 addr, struct em28xx *dev)
440{
441 struct dvb_frontend *fe;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300442 struct xc2028_config cfg;
443
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300444 memset(&cfg, 0, sizeof(cfg));
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300445 cfg.i2c_adap = &dev->i2c_adap;
446 cfg.i2c_addr = addr;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300447
Antti Palosaarif71095b2011-04-07 15:51:52 -0300448 if (!dev->dvb->fe[0]) {
Filipe Rosset480be182009-11-04 15:32:37 -0300449 em28xx_errdev("/2: dvb frontend not attached. "
450 "Can't attach xc3028\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300451 return -EINVAL;
452 }
453
Antti Palosaarif71095b2011-04-07 15:51:52 -0300454 fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300455 if (!fe) {
Filipe Rosset480be182009-11-04 15:32:37 -0300456 em28xx_errdev("/2: xc3028 attach failed\n");
Antti Palosaarif71095b2011-04-07 15:51:52 -0300457 dvb_frontend_detach(dev->dvb->fe[0]);
458 dev->dvb->fe[0] = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300459 return -EINVAL;
460 }
461
Filipe Rosset480be182009-11-04 15:32:37 -0300462 em28xx_info("%s/2: xc3028 attached\n", dev->name);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300463
464 return 0;
465}
466
Aidan Thornton3421b772008-04-17 21:40:36 -0300467/* ------------------------------------------------------------------ */
468
Hans Verkuild45b9b82008-09-04 03:33:43 -0300469static int register_dvb(struct em28xx_dvb *dvb,
Aidan Thornton3421b772008-04-17 21:40:36 -0300470 struct module *module,
471 struct em28xx *dev,
472 struct device *device)
473{
474 int result;
475
476 mutex_init(&dvb->lock);
477
478 /* register adapter */
479 result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
480 adapter_nr);
481 if (result < 0) {
482 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
483 dev->name, result);
484 goto fail_adapter;
485 }
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300486
487 /* Ensure all frontends negotiate bus access */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300488 dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
489 if (dvb->fe[1])
490 dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300491
Aidan Thornton3421b772008-04-17 21:40:36 -0300492 dvb->adapter.priv = dev;
493
494 /* register frontend */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300495 result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300496 if (result < 0) {
497 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
498 dev->name, result);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300499 goto fail_frontend0;
500 }
501
502 /* register 2nd frontend */
503 if (dvb->fe[1]) {
504 result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
505 if (result < 0) {
506 printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
507 dev->name, result);
508 goto fail_frontend1;
509 }
Aidan Thornton3421b772008-04-17 21:40:36 -0300510 }
511
512 /* register demux stuff */
513 dvb->demux.dmx.capabilities =
514 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
515 DMX_MEMORY_BASED_FILTERING;
516 dvb->demux.priv = dvb;
517 dvb->demux.filternum = 256;
518 dvb->demux.feednum = 256;
519 dvb->demux.start_feed = start_feed;
520 dvb->demux.stop_feed = stop_feed;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300521
Aidan Thornton3421b772008-04-17 21:40:36 -0300522 result = dvb_dmx_init(&dvb->demux);
523 if (result < 0) {
524 printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
525 dev->name, result);
526 goto fail_dmx;
527 }
528
529 dvb->dmxdev.filternum = 256;
530 dvb->dmxdev.demux = &dvb->demux.dmx;
531 dvb->dmxdev.capabilities = 0;
532 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
533 if (result < 0) {
534 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
535 dev->name, result);
536 goto fail_dmxdev;
537 }
538
539 dvb->fe_hw.source = DMX_FRONTEND_0;
540 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
541 if (result < 0) {
542 printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
543 dev->name, result);
544 goto fail_fe_hw;
545 }
546
547 dvb->fe_mem.source = DMX_MEMORY_FE;
548 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
549 if (result < 0) {
550 printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
551 dev->name, result);
552 goto fail_fe_mem;
553 }
554
555 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
556 if (result < 0) {
557 printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
558 dev->name, result);
559 goto fail_fe_conn;
560 }
561
562 /* register network adapter */
563 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
564 return 0;
565
566fail_fe_conn:
567 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
568fail_fe_mem:
569 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
570fail_fe_hw:
571 dvb_dmxdev_release(&dvb->dmxdev);
572fail_dmxdev:
573 dvb_dmx_release(&dvb->demux);
574fail_dmx:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300575 if (dvb->fe[1])
576 dvb_unregister_frontend(dvb->fe[1]);
577 dvb_unregister_frontend(dvb->fe[0]);
578fail_frontend1:
579 if (dvb->fe[1])
580 dvb_frontend_detach(dvb->fe[1]);
581fail_frontend0:
582 dvb_frontend_detach(dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300583 dvb_unregister_adapter(&dvb->adapter);
584fail_adapter:
585 return result;
586}
587
588static void unregister_dvb(struct em28xx_dvb *dvb)
589{
590 dvb_net_release(&dvb->net);
591 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
592 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
593 dvb_dmxdev_release(&dvb->dmxdev);
594 dvb_dmx_release(&dvb->demux);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300595 if (dvb->fe[1])
596 dvb_unregister_frontend(dvb->fe[1]);
597 dvb_unregister_frontend(dvb->fe[0]);
598 if (dvb->fe[1])
599 dvb_frontend_detach(dvb->fe[1]);
600 dvb_frontend_detach(dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300601 dvb_unregister_adapter(&dvb->adapter);
602}
603
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300604static int dvb_init(struct em28xx *dev)
605{
Aidan Thornton3421b772008-04-17 21:40:36 -0300606 int result = 0;
607 struct em28xx_dvb *dvb;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300608
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -0300609 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -0300610 /* This device does not support the extension */
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300611 printk(KERN_INFO "em28xx_dvb: This device does not support the extension\n");
Devin Heitmuellerdf619182008-06-10 12:34:35 -0300612 return 0;
613 }
614
Aidan Thornton3421b772008-04-17 21:40:36 -0300615 dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300616
617 if (dvb == NULL) {
Filipe Rosset480be182009-11-04 15:32:37 -0300618 em28xx_info("em28xx_dvb: memory allocation failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -0300619 return -ENOMEM;
620 }
621 dev->dvb = dvb;
Antti Palosaarif71095b2011-04-07 15:51:52 -0300622 dvb->fe[0] = dvb->fe[1] = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300623
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -0300624 mutex_lock(&dev->lock);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300625 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300626 /* init frontend */
627 switch (dev->model) {
Mauro Carvalho Chehabebaefdb2011-06-01 10:16:25 -0300628 case EM2874_BOARD_LEADERSHIP_ISDBT:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300629 dvb->fe[0] = dvb_attach(s921_attach,
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300630 &sharp_isdbt, &dev->i2c_adap);
631
Antti Palosaarif71095b2011-04-07 15:51:52 -0300632 if (!dvb->fe[0]) {
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300633 result = -EINVAL;
634 goto out_free;
635 }
636
637 break;
Douglas Schilling Landgraff89bc322008-12-01 21:01:04 -0300638 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
Mauro Carvalho Chehab10ac6602008-07-27 14:58:58 -0300639 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
Devin Heitmueller4fd305b2008-06-04 13:43:46 -0300640 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
Devin Heitmuellere14b3652008-07-26 11:04:33 -0300641 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300642 dvb->fe[0] = dvb_attach(lgdt330x_attach,
Aidan Thornton3421b772008-04-17 21:40:36 -0300643 &em2880_lgdt3303_dev,
644 &dev->i2c_adap);
645 if (attach_xc3028(0x61, dev) < 0) {
646 result = -EINVAL;
647 goto out_free;
648 }
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -0300649 break;
Thierry MERLE46510b52008-10-11 16:56:13 -0300650 case EM2880_BOARD_KWORLD_DVB_310U:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300651 dvb->fe[0] = dvb_attach(zl10353_attach,
Aidan Thornton3421b772008-04-17 21:40:36 -0300652 &em28xx_zl10353_with_xc3028,
653 &dev->i2c_adap);
654 if (attach_xc3028(0x61, dev) < 0) {
655 result = -EINVAL;
656 goto out_free;
657 }
Aidan Thornton7e6388a2008-04-17 21:40:03 -0300658 break;
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300659 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
Uroš Vamplec994d02009-09-30 22:53:37 -0300660 case EM2882_BOARD_TERRATEC_HYBRID_XS:
Devin Heitmueller01a5fd62009-08-07 09:25:06 -0300661 case EM2880_BOARD_EMPIRE_DUAL_TV:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300662 dvb->fe[0] = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300663 &em28xx_zl10353_xc3028_no_i2c_gate,
664 &dev->i2c_adap);
665 if (attach_xc3028(0x61, dev) < 0) {
666 result = -EINVAL;
667 goto out_free;
668 }
669 break;
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300670 case EM2880_BOARD_TERRATEC_HYBRID_XS:
Catimimi65638012010-02-18 18:06:32 -0300671 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
Devin Heitmuellerd5b3ba92009-07-08 21:51:35 -0300672 case EM2881_BOARD_PINNACLE_HYBRID_PRO:
Andrea.Amorosi76@gmail.com7ca7ef62010-02-09 17:53:38 -0300673 case EM2882_BOARD_DIKOM_DK300:
Antonio Larrosa811fab62010-03-04 22:19:48 -0300674 case EM2882_BOARD_KWORLD_VS_DVBT:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300675 dvb->fe[0] = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300676 &em28xx_zl10353_xc3028_no_i2c_gate,
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300677 &dev->i2c_adap);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300678 if (dvb->fe[0] == NULL) {
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300679 /* This board could have either a zl10353 or a mt352.
680 If the chip id isn't for zl10353, try mt352 */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300681 dvb->fe[0] = dvb_attach(mt352_attach,
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300682 &terratec_xs_mt352_cfg,
683 &dev->i2c_adap);
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300684 }
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300685
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300686 if (attach_xc3028(0x61, dev) < 0) {
687 result = -EINVAL;
688 goto out_free;
689 }
690 break;
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300691 case EM2883_BOARD_KWORLD_HYBRID_330U:
Devin Heitmueller19859222009-06-19 00:33:54 -0300692 case EM2882_BOARD_EVGA_INDTUBE:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300693 dvb->fe[0] = dvb_attach(s5h1409_attach,
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300694 &em28xx_s5h1409_with_xc3028,
695 &dev->i2c_adap);
696 if (attach_xc3028(0x61, dev) < 0) {
697 result = -EINVAL;
698 goto out_free;
699 }
700 break;
Franklin Mengd7de5d82009-06-06 17:05:02 -0300701 case EM2882_BOARD_KWORLD_ATSC_315U:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300702 dvb->fe[0] = dvb_attach(lgdt330x_attach,
Franklin Mengd7de5d82009-06-06 17:05:02 -0300703 &em2880_lgdt3303_dev,
704 &dev->i2c_adap);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300705 if (dvb->fe[0] != NULL) {
706 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
Franklin Mengd7de5d82009-06-06 17:05:02 -0300707 &dev->i2c_adap, 0x61, TUNER_THOMSON_DTT761X)) {
708 result = -EINVAL;
709 goto out_free;
710 }
711 }
712 break;
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300713 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
Devin Heitmuellerad9b4bb2011-03-13 02:09:59 -0300714 case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300715 dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
Devin Heitmueller75e2b862011-03-13 02:01:02 -0300716 &dev->i2c_adap, &dev->udev->dev);
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300717 if (attach_xc3028(0x61, dev) < 0) {
718 result = -EINVAL;
719 goto out_free;
720 }
721 break;
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300722 case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
723 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300724 dvb->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300725 &em28xx_tda10023_config,
726 &dev->i2c_adap, 0x48);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300727 if (dvb->fe[0]) {
728 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300729 &dev->i2c_adap, 0x60, TUNER_PHILIPS_CU1216L)) {
730 result = -EINVAL;
731 goto out_free;
732 }
733 }
734 break;
Jarod Wilson7e48b302010-03-07 17:55:43 -0300735 case EM2870_BOARD_KWORLD_A340:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300736 dvb->fe[0] = dvb_attach(lgdt3305_attach,
Jarod Wilson7e48b302010-03-07 17:55:43 -0300737 &em2870_lgdt3304_dev,
738 &dev->i2c_adap);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300739 if (dvb->fe[0] != NULL)
740 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Jarod Wilson7e48b302010-03-07 17:55:43 -0300741 &dev->i2c_adap, &kworld_a340_config);
742 break;
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300743 case EM28174_BOARD_PCTV_290E:
744 /* MFE
745 * FE 0 = DVB-T/T2 + FE 1 = DVB-C, both sharing same tuner. */
746 /* FE 0 */
747 dvb->fe[0] = dvb_attach(cxd2820r_attach,
748 &em28xx_cxd2820r_config, &dev->i2c_adap, NULL);
749 if (dvb->fe[0]) {
750 struct i2c_adapter *i2c_tuner;
751 i2c_tuner = cxd2820r_get_tuner_i2c_adapter(dvb->fe[0]);
752 /* FE 0 attach tuner */
753 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
754 i2c_tuner, &em28xx_cxd2820r_tda18271_config)) {
755 dvb_frontend_detach(dvb->fe[0]);
756 result = -EINVAL;
757 goto out_free;
758 }
759 /* FE 1. This dvb_attach() cannot fail. */
760 dvb->fe[1] = dvb_attach(cxd2820r_attach, NULL, NULL,
761 dvb->fe[0]);
762 dvb->fe[1]->id = 1;
763 /* FE 1 attach tuner */
764 if (!dvb_attach(tda18271_attach, dvb->fe[1], 0x60,
765 i2c_tuner, &em28xx_cxd2820r_tda18271_config)) {
766 dvb_frontend_detach(dvb->fe[1]);
767 /* leave FE 0 still active */
768 }
769 }
770 break;
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300771 case EM2884_BOARD_TERRATEC_H5:
772 terratec_h5_init(dev);
773
774 /* dvb->fe[1] will be DVB-C, and dvb->fe[0] will be DVB-T */
775 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap, &dvb->fe[1]);
776 if (!dvb->fe[0] || !dvb->fe[1]) {
777 result = -EINVAL;
778 goto out_free;
779 }
780 /* FIXME: do we need a pll semaphore? */
781 dvb->fe[0]->sec_priv = dvb;
782 sema_init(&dvb->pll_mutex, 1);
783 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
784 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
785 dvb->fe[1]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
786 dvb->fe[1]->id = 1;
787
788 /* Attach tda18271 */
789 if (dvb->fe[0]->ops.i2c_gate_ctrl)
790 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
791 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap, 0x60)) {
792 result = -EINVAL;
793 goto out_free;
794 }
795 if (dvb->fe[0]->ops.i2c_gate_ctrl)
796 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
797 if (dvb->fe[1]->ops.i2c_gate_ctrl)
798 dvb->fe[1]->ops.i2c_gate_ctrl(dvb->fe[1], 1);
799
800 break;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300801 default:
Filipe Rosset480be182009-11-04 15:32:37 -0300802 em28xx_errdev("/2: The frontend of your DVB/ATSC card"
803 " isn't supported yet\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300804 break;
805 }
Antti Palosaarif71095b2011-04-07 15:51:52 -0300806 if (NULL == dvb->fe[0]) {
Filipe Rosset480be182009-11-04 15:32:37 -0300807 em28xx_errdev("/2: frontend initialization failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -0300808 result = -EINVAL;
809 goto out_free;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300810 }
Michael Krufkyd7cba042008-09-12 13:31:45 -0300811 /* define general-purpose callback pointer */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300812 dvb->fe[0]->callback = em28xx_tuner_callback;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300813
814 /* register everything */
Aidan Thornton3421b772008-04-17 21:40:36 -0300815 result = register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
816
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300817 if (result < 0)
Aidan Thornton3421b772008-04-17 21:40:36 -0300818 goto out_free;
Aidan Thornton3421b772008-04-17 21:40:36 -0300819
Filipe Rosset480be182009-11-04 15:32:37 -0300820 em28xx_info("Successfully loaded em28xx-dvb\n");
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -0300821ret:
822 em28xx_set_mode(dev, EM28XX_SUSPEND);
823 mutex_unlock(&dev->lock);
824 return result;
Aidan Thornton3421b772008-04-17 21:40:36 -0300825
826out_free:
827 kfree(dvb);
828 dev->dvb = NULL;
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -0300829 goto ret;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300830}
831
832static int dvb_fini(struct em28xx *dev)
833{
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -0300834 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -0300835 /* This device does not support the extension */
836 return 0;
837 }
838
Aidan Thornton3421b772008-04-17 21:40:36 -0300839 if (dev->dvb) {
840 unregister_dvb(dev->dvb);
Francesco Lavra19f48cb2009-12-31 08:47:11 -0300841 kfree(dev->dvb);
Aidan Thornton3421b772008-04-17 21:40:36 -0300842 dev->dvb = NULL;
843 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300844
845 return 0;
846}
847
848static struct em28xx_ops dvb_ops = {
849 .id = EM28XX_DVB,
850 .name = "Em28xx dvb Extension",
851 .init = dvb_init,
852 .fini = dvb_fini,
853};
854
855static int __init em28xx_dvb_register(void)
856{
857 return em28xx_register_extension(&dvb_ops);
858}
859
860static void __exit em28xx_dvb_unregister(void)
861{
862 em28xx_unregister_extension(&dvb_ops);
863}
864
865module_init(em28xx_dvb_register);
866module_exit(em28xx_dvb_unregister);