blob: b8686c1eb3b690ac3349ae79135f87900078a7d5 [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 -0300304#define TERRATEC_H5_DRXK_I2C_ADDR 0x29
305
306struct drxk_config terratec_h5_drxk = {
307 .adr = 0x29,
308};
309
310static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
311{
312 struct em28xx_dvb *dvb = fe->sec_priv;
313 int status;
314
315 if (!dvb)
316 return -EINVAL;
317
318 if (enable) {
319 down(&dvb->pll_mutex);
320 status = dvb->gate_ctrl(fe, 1);
321 } else {
322 status = dvb->gate_ctrl(fe, 0);
323 up(&dvb->pll_mutex);
324 }
325 return status;
326}
327
328static void terratec_h5_init(struct em28xx *dev)
329{
330 int i;
331 struct em28xx_reg_seq terratec_h5_init[] = {
332 {EM28XX_R08_GPIO, 0xff, 0xff, 10},
333 {EM2874_R80_GPIO, 0xf6, 0xff, 100},
334 {EM2874_R80_GPIO, 0xf2, 0xff, 50},
335 {EM2874_R80_GPIO, 0xf6, 0xff, 100},
336 { -1, -1, -1, -1},
337 };
338 struct em28xx_reg_seq terratec_h5_end[] = {
339 {EM2874_R80_GPIO, 0xe6, 0xff, 100},
340 {EM2874_R80_GPIO, 0xa6, 0xff, 50},
341 {EM2874_R80_GPIO, 0xe6, 0xff, 100},
342 { -1, -1, -1, -1},
343 };
344 struct {
345 unsigned char r[4];
346 int len;
347 } regs[] = {
348 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
349 {{ 0x01, 0x02 }, 2},
350 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
351 {{ 0x01, 0x00 }, 2},
352 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
353 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
354 {{ 0x01, 0x00 }, 2},
355 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
356 {{ 0x04, 0x00 }, 2},
357 {{ 0x00, 0x04 }, 2},
358 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
359 {{ 0x04, 0x14 }, 2},
360 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
361 };
362
363 em28xx_gpio_set(dev, terratec_h5_init);
364 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
365 msleep(10);
366 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
367 msleep(10);
368
369 dev->i2c_client.addr = 0x82 >> 1;
370
371 for (i = 0; i < ARRAY_SIZE(regs); i++)
372 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
373 em28xx_gpio_set(dev, terratec_h5_end);
374};
375
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300376static int mt352_terratec_xs_init(struct dvb_frontend *fe)
377{
378 /* Values extracted from a USB trace of the Terratec Windows driver */
379 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
380 static u8 reset[] = { RESET, 0x80 };
381 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
382 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
383 static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
384 static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
385 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
386 static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
387 static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
Devin Heitmuellerff697862009-07-12 18:44:19 -0300388 static u8 tuner_go[] = { TUNER_GO, 0x01};
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300389
390 mt352_write(fe, clock_config, sizeof(clock_config));
391 udelay(200);
392 mt352_write(fe, reset, sizeof(reset));
393 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
394 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
395 mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
396 mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
397 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
398 mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
399 mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
400 mt352_write(fe, tuner_go, sizeof(tuner_go));
401 return 0;
402}
403
404static struct mt352_config terratec_xs_mt352_cfg = {
405 .demod_address = (0x1e >> 1),
406 .no_tuner = 1,
407 .if2 = 45600,
408 .demod_init = mt352_terratec_xs_init,
409};
410
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300411static struct tda10023_config em28xx_tda10023_config = {
412 .demod_address = 0x0c,
413 .invert = 1,
414};
415
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300416static struct cxd2820r_config em28xx_cxd2820r_config = {
417 .i2c_address = (0xd8 >> 1),
418 .ts_mode = CXD2820R_TS_SERIAL,
419 .if_dvbt_6 = 3300,
420 .if_dvbt_7 = 3500,
421 .if_dvbt_8 = 4000,
422 .if_dvbt2_6 = 3300,
423 .if_dvbt2_7 = 3500,
424 .if_dvbt2_8 = 4000,
425 .if_dvbc = 5000,
426
427 /* enable LNA for DVB-T2 and DVB-C */
428 .gpio_dvbt2[0] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | CXD2820R_GPIO_L,
429 .gpio_dvbc[0] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | CXD2820R_GPIO_L,
430};
431
432static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
433 .output_opt = TDA18271_OUTPUT_LT_OFF,
434};
435
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300436/* ------------------------------------------------------------------ */
437
438static int attach_xc3028(u8 addr, struct em28xx *dev)
439{
440 struct dvb_frontend *fe;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300441 struct xc2028_config cfg;
442
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300443 memset(&cfg, 0, sizeof(cfg));
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300444 cfg.i2c_adap = &dev->i2c_adap;
445 cfg.i2c_addr = addr;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300446
Antti Palosaarif71095b2011-04-07 15:51:52 -0300447 if (!dev->dvb->fe[0]) {
Filipe Rosset480be182009-11-04 15:32:37 -0300448 em28xx_errdev("/2: dvb frontend not attached. "
449 "Can't attach xc3028\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300450 return -EINVAL;
451 }
452
Antti Palosaarif71095b2011-04-07 15:51:52 -0300453 fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300454 if (!fe) {
Filipe Rosset480be182009-11-04 15:32:37 -0300455 em28xx_errdev("/2: xc3028 attach failed\n");
Antti Palosaarif71095b2011-04-07 15:51:52 -0300456 dvb_frontend_detach(dev->dvb->fe[0]);
457 dev->dvb->fe[0] = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300458 return -EINVAL;
459 }
460
Filipe Rosset480be182009-11-04 15:32:37 -0300461 em28xx_info("%s/2: xc3028 attached\n", dev->name);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300462
463 return 0;
464}
465
Aidan Thornton3421b772008-04-17 21:40:36 -0300466/* ------------------------------------------------------------------ */
467
Hans Verkuild45b9b82008-09-04 03:33:43 -0300468static int register_dvb(struct em28xx_dvb *dvb,
Aidan Thornton3421b772008-04-17 21:40:36 -0300469 struct module *module,
470 struct em28xx *dev,
471 struct device *device)
472{
473 int result;
474
475 mutex_init(&dvb->lock);
476
477 /* register adapter */
478 result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
479 adapter_nr);
480 if (result < 0) {
481 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
482 dev->name, result);
483 goto fail_adapter;
484 }
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300485
486 /* Ensure all frontends negotiate bus access */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300487 dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
488 if (dvb->fe[1])
489 dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300490
Aidan Thornton3421b772008-04-17 21:40:36 -0300491 dvb->adapter.priv = dev;
492
493 /* register frontend */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300494 result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300495 if (result < 0) {
496 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
497 dev->name, result);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300498 goto fail_frontend0;
499 }
500
501 /* register 2nd frontend */
502 if (dvb->fe[1]) {
503 result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
504 if (result < 0) {
505 printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
506 dev->name, result);
507 goto fail_frontend1;
508 }
Aidan Thornton3421b772008-04-17 21:40:36 -0300509 }
510
511 /* register demux stuff */
512 dvb->demux.dmx.capabilities =
513 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
514 DMX_MEMORY_BASED_FILTERING;
515 dvb->demux.priv = dvb;
516 dvb->demux.filternum = 256;
517 dvb->demux.feednum = 256;
518 dvb->demux.start_feed = start_feed;
519 dvb->demux.stop_feed = stop_feed;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300520
Aidan Thornton3421b772008-04-17 21:40:36 -0300521 result = dvb_dmx_init(&dvb->demux);
522 if (result < 0) {
523 printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
524 dev->name, result);
525 goto fail_dmx;
526 }
527
528 dvb->dmxdev.filternum = 256;
529 dvb->dmxdev.demux = &dvb->demux.dmx;
530 dvb->dmxdev.capabilities = 0;
531 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
532 if (result < 0) {
533 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
534 dev->name, result);
535 goto fail_dmxdev;
536 }
537
538 dvb->fe_hw.source = DMX_FRONTEND_0;
539 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
540 if (result < 0) {
541 printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
542 dev->name, result);
543 goto fail_fe_hw;
544 }
545
546 dvb->fe_mem.source = DMX_MEMORY_FE;
547 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
548 if (result < 0) {
549 printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
550 dev->name, result);
551 goto fail_fe_mem;
552 }
553
554 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
555 if (result < 0) {
556 printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
557 dev->name, result);
558 goto fail_fe_conn;
559 }
560
561 /* register network adapter */
562 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
563 return 0;
564
565fail_fe_conn:
566 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
567fail_fe_mem:
568 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
569fail_fe_hw:
570 dvb_dmxdev_release(&dvb->dmxdev);
571fail_dmxdev:
572 dvb_dmx_release(&dvb->demux);
573fail_dmx:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300574 if (dvb->fe[1])
575 dvb_unregister_frontend(dvb->fe[1]);
576 dvb_unregister_frontend(dvb->fe[0]);
577fail_frontend1:
578 if (dvb->fe[1])
579 dvb_frontend_detach(dvb->fe[1]);
580fail_frontend0:
581 dvb_frontend_detach(dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300582 dvb_unregister_adapter(&dvb->adapter);
583fail_adapter:
584 return result;
585}
586
587static void unregister_dvb(struct em28xx_dvb *dvb)
588{
589 dvb_net_release(&dvb->net);
590 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
591 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
592 dvb_dmxdev_release(&dvb->dmxdev);
593 dvb_dmx_release(&dvb->demux);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300594 if (dvb->fe[1])
595 dvb_unregister_frontend(dvb->fe[1]);
596 dvb_unregister_frontend(dvb->fe[0]);
597 if (dvb->fe[1])
598 dvb_frontend_detach(dvb->fe[1]);
599 dvb_frontend_detach(dvb->fe[0]);
Aidan Thornton3421b772008-04-17 21:40:36 -0300600 dvb_unregister_adapter(&dvb->adapter);
601}
602
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300603static int dvb_init(struct em28xx *dev)
604{
Aidan Thornton3421b772008-04-17 21:40:36 -0300605 int result = 0;
606 struct em28xx_dvb *dvb;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300607
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -0300608 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -0300609 /* This device does not support the extension */
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300610 printk(KERN_INFO "em28xx_dvb: This device does not support the extension\n");
Devin Heitmuellerdf619182008-06-10 12:34:35 -0300611 return 0;
612 }
613
Aidan Thornton3421b772008-04-17 21:40:36 -0300614 dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300615
616 if (dvb == NULL) {
Filipe Rosset480be182009-11-04 15:32:37 -0300617 em28xx_info("em28xx_dvb: memory allocation failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -0300618 return -ENOMEM;
619 }
620 dev->dvb = dvb;
Antti Palosaarif71095b2011-04-07 15:51:52 -0300621 dvb->fe[0] = dvb->fe[1] = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300622
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -0300623 mutex_lock(&dev->lock);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300624 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300625 /* init frontend */
626 switch (dev->model) {
Mauro Carvalho Chehabebaefdb2011-06-01 10:16:25 -0300627 case EM2874_BOARD_LEADERSHIP_ISDBT:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300628 dvb->fe[0] = dvb_attach(s921_attach,
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300629 &sharp_isdbt, &dev->i2c_adap);
630
Antti Palosaarif71095b2011-04-07 15:51:52 -0300631 if (!dvb->fe[0]) {
Mauro Carvalho Chehabca3dfd62010-09-10 17:29:14 -0300632 result = -EINVAL;
633 goto out_free;
634 }
635
636 break;
Douglas Schilling Landgraff89bc322008-12-01 21:01:04 -0300637 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
Mauro Carvalho Chehab10ac6602008-07-27 14:58:58 -0300638 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
Devin Heitmueller4fd305b2008-06-04 13:43:46 -0300639 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
Devin Heitmuellere14b3652008-07-26 11:04:33 -0300640 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300641 dvb->fe[0] = dvb_attach(lgdt330x_attach,
Aidan Thornton3421b772008-04-17 21:40:36 -0300642 &em2880_lgdt3303_dev,
643 &dev->i2c_adap);
644 if (attach_xc3028(0x61, dev) < 0) {
645 result = -EINVAL;
646 goto out_free;
647 }
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -0300648 break;
Thierry MERLE46510b52008-10-11 16:56:13 -0300649 case EM2880_BOARD_KWORLD_DVB_310U:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300650 dvb->fe[0] = dvb_attach(zl10353_attach,
Aidan Thornton3421b772008-04-17 21:40:36 -0300651 &em28xx_zl10353_with_xc3028,
652 &dev->i2c_adap);
653 if (attach_xc3028(0x61, dev) < 0) {
654 result = -EINVAL;
655 goto out_free;
656 }
Aidan Thornton7e6388a2008-04-17 21:40:03 -0300657 break;
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300658 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
Uroš Vamplec994d02009-09-30 22:53:37 -0300659 case EM2882_BOARD_TERRATEC_HYBRID_XS:
Devin Heitmueller01a5fd62009-08-07 09:25:06 -0300660 case EM2880_BOARD_EMPIRE_DUAL_TV:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300661 dvb->fe[0] = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300662 &em28xx_zl10353_xc3028_no_i2c_gate,
663 &dev->i2c_adap);
664 if (attach_xc3028(0x61, dev) < 0) {
665 result = -EINVAL;
666 goto out_free;
667 }
668 break;
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300669 case EM2880_BOARD_TERRATEC_HYBRID_XS:
Catimimi65638012010-02-18 18:06:32 -0300670 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
Devin Heitmuellerd5b3ba92009-07-08 21:51:35 -0300671 case EM2881_BOARD_PINNACLE_HYBRID_PRO:
Andrea.Amorosi76@gmail.com7ca7ef62010-02-09 17:53:38 -0300672 case EM2882_BOARD_DIKOM_DK300:
Antonio Larrosa811fab62010-03-04 22:19:48 -0300673 case EM2882_BOARD_KWORLD_VS_DVBT:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300674 dvb->fe[0] = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300675 &em28xx_zl10353_xc3028_no_i2c_gate,
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300676 &dev->i2c_adap);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300677 if (dvb->fe[0] == NULL) {
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300678 /* This board could have either a zl10353 or a mt352.
679 If the chip id isn't for zl10353, try mt352 */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300680 dvb->fe[0] = dvb_attach(mt352_attach,
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300681 &terratec_xs_mt352_cfg,
682 &dev->i2c_adap);
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300683 }
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300684
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300685 if (attach_xc3028(0x61, dev) < 0) {
686 result = -EINVAL;
687 goto out_free;
688 }
689 break;
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300690 case EM2883_BOARD_KWORLD_HYBRID_330U:
Devin Heitmueller19859222009-06-19 00:33:54 -0300691 case EM2882_BOARD_EVGA_INDTUBE:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300692 dvb->fe[0] = dvb_attach(s5h1409_attach,
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300693 &em28xx_s5h1409_with_xc3028,
694 &dev->i2c_adap);
695 if (attach_xc3028(0x61, dev) < 0) {
696 result = -EINVAL;
697 goto out_free;
698 }
699 break;
Franklin Mengd7de5d82009-06-06 17:05:02 -0300700 case EM2882_BOARD_KWORLD_ATSC_315U:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300701 dvb->fe[0] = dvb_attach(lgdt330x_attach,
Franklin Mengd7de5d82009-06-06 17:05:02 -0300702 &em2880_lgdt3303_dev,
703 &dev->i2c_adap);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300704 if (dvb->fe[0] != NULL) {
705 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
Franklin Mengd7de5d82009-06-06 17:05:02 -0300706 &dev->i2c_adap, 0x61, TUNER_THOMSON_DTT761X)) {
707 result = -EINVAL;
708 goto out_free;
709 }
710 }
711 break;
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300712 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
Devin Heitmuellerad9b4bb2011-03-13 02:09:59 -0300713 case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300714 dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
Devin Heitmueller75e2b862011-03-13 02:01:02 -0300715 &dev->i2c_adap, &dev->udev->dev);
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300716 if (attach_xc3028(0x61, dev) < 0) {
717 result = -EINVAL;
718 goto out_free;
719 }
720 break;
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300721 case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
722 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300723 dvb->fe[0] = dvb_attach(tda10023_attach,
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300724 &em28xx_tda10023_config,
725 &dev->i2c_adap, 0x48);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300726 if (dvb->fe[0]) {
727 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300728 &dev->i2c_adap, 0x60, TUNER_PHILIPS_CU1216L)) {
729 result = -EINVAL;
730 goto out_free;
731 }
732 }
733 break;
Jarod Wilson7e48b302010-03-07 17:55:43 -0300734 case EM2870_BOARD_KWORLD_A340:
Antti Palosaarif71095b2011-04-07 15:51:52 -0300735 dvb->fe[0] = dvb_attach(lgdt3305_attach,
Jarod Wilson7e48b302010-03-07 17:55:43 -0300736 &em2870_lgdt3304_dev,
737 &dev->i2c_adap);
Antti Palosaarif71095b2011-04-07 15:51:52 -0300738 if (dvb->fe[0] != NULL)
739 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
Jarod Wilson7e48b302010-03-07 17:55:43 -0300740 &dev->i2c_adap, &kworld_a340_config);
741 break;
Antti Palosaarid6a5f922011-04-07 16:34:44 -0300742 case EM28174_BOARD_PCTV_290E:
743 /* MFE
744 * FE 0 = DVB-T/T2 + FE 1 = DVB-C, both sharing same tuner. */
745 /* FE 0 */
746 dvb->fe[0] = dvb_attach(cxd2820r_attach,
747 &em28xx_cxd2820r_config, &dev->i2c_adap, NULL);
748 if (dvb->fe[0]) {
749 struct i2c_adapter *i2c_tuner;
750 i2c_tuner = cxd2820r_get_tuner_i2c_adapter(dvb->fe[0]);
751 /* FE 0 attach tuner */
752 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
753 i2c_tuner, &em28xx_cxd2820r_tda18271_config)) {
754 dvb_frontend_detach(dvb->fe[0]);
755 result = -EINVAL;
756 goto out_free;
757 }
758 /* FE 1. This dvb_attach() cannot fail. */
759 dvb->fe[1] = dvb_attach(cxd2820r_attach, NULL, NULL,
760 dvb->fe[0]);
761 dvb->fe[1]->id = 1;
762 /* FE 1 attach tuner */
763 if (!dvb_attach(tda18271_attach, dvb->fe[1], 0x60,
764 i2c_tuner, &em28xx_cxd2820r_tda18271_config)) {
765 dvb_frontend_detach(dvb->fe[1]);
766 /* leave FE 0 still active */
767 }
768 }
769 break;
Mauro Carvalho Chehabfec528b2011-07-03 21:05:06 -0300770 case EM2884_BOARD_TERRATEC_H5:
771 terratec_h5_init(dev);
772
773 /* dvb->fe[1] will be DVB-C, and dvb->fe[0] will be DVB-T */
774 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap, &dvb->fe[1]);
775 if (!dvb->fe[0] || !dvb->fe[1]) {
776 result = -EINVAL;
777 goto out_free;
778 }
779 /* FIXME: do we need a pll semaphore? */
780 dvb->fe[0]->sec_priv = dvb;
781 sema_init(&dvb->pll_mutex, 1);
782 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
783 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
784 dvb->fe[1]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
785 dvb->fe[1]->id = 1;
786
787 /* Attach tda18271 */
788 if (dvb->fe[0]->ops.i2c_gate_ctrl)
789 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
790 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap, 0x60)) {
791 result = -EINVAL;
792 goto out_free;
793 }
794 if (dvb->fe[0]->ops.i2c_gate_ctrl)
795 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
796 if (dvb->fe[1]->ops.i2c_gate_ctrl)
797 dvb->fe[1]->ops.i2c_gate_ctrl(dvb->fe[1], 1);
798
799 break;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300800 default:
Filipe Rosset480be182009-11-04 15:32:37 -0300801 em28xx_errdev("/2: The frontend of your DVB/ATSC card"
802 " isn't supported yet\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300803 break;
804 }
Antti Palosaarif71095b2011-04-07 15:51:52 -0300805 if (NULL == dvb->fe[0]) {
Filipe Rosset480be182009-11-04 15:32:37 -0300806 em28xx_errdev("/2: frontend initialization failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -0300807 result = -EINVAL;
808 goto out_free;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300809 }
Michael Krufkyd7cba042008-09-12 13:31:45 -0300810 /* define general-purpose callback pointer */
Antti Palosaarif71095b2011-04-07 15:51:52 -0300811 dvb->fe[0]->callback = em28xx_tuner_callback;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300812
813 /* register everything */
Aidan Thornton3421b772008-04-17 21:40:36 -0300814 result = register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
815
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300816 if (result < 0)
Aidan Thornton3421b772008-04-17 21:40:36 -0300817 goto out_free;
Aidan Thornton3421b772008-04-17 21:40:36 -0300818
Filipe Rosset480be182009-11-04 15:32:37 -0300819 em28xx_info("Successfully loaded em28xx-dvb\n");
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -0300820ret:
821 em28xx_set_mode(dev, EM28XX_SUSPEND);
822 mutex_unlock(&dev->lock);
823 return result;
Aidan Thornton3421b772008-04-17 21:40:36 -0300824
825out_free:
826 kfree(dvb);
827 dev->dvb = NULL;
Mauro Carvalho Chehab50133182010-04-07 17:07:58 -0300828 goto ret;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300829}
830
831static int dvb_fini(struct em28xx *dev)
832{
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -0300833 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -0300834 /* This device does not support the extension */
835 return 0;
836 }
837
Aidan Thornton3421b772008-04-17 21:40:36 -0300838 if (dev->dvb) {
839 unregister_dvb(dev->dvb);
Francesco Lavra19f48cb2009-12-31 08:47:11 -0300840 kfree(dev->dvb);
Aidan Thornton3421b772008-04-17 21:40:36 -0300841 dev->dvb = NULL;
842 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300843
844 return 0;
845}
846
847static struct em28xx_ops dvb_ops = {
848 .id = EM28XX_DVB,
849 .name = "Em28xx dvb Extension",
850 .init = dvb_init,
851 .fini = dvb_fini,
852};
853
854static int __init em28xx_dvb_register(void)
855{
856 return em28xx_register_extension(&dvb_ops);
857}
858
859static void __exit em28xx_dvb_unregister(void)
860{
861 em28xx_unregister_extension(&dvb_ops);
862}
863
864module_init(em28xx_dvb_register);
865module_exit(em28xx_dvb_unregister);