blob: bcd3c371009b9467ac6cdf4551cc2adc0b858a93 [file] [log] [blame]
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -03001/*
2 DVB device driver for em28xx
3
4 (c) 2008 Mauro Carvalho Chehab <mchehab@infradead.org>
5
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"
Aidan Thornton7e6388a2008-04-17 21:40:03 -030033#include "zl10353.h"
Robert Krakora6e7b9ea2009-01-18 21:59:34 -030034#include "s5h1409.h"
Devin Heitmueller4fb202a2009-07-12 17:51:12 -030035#include "mt352.h"
36#include "mt352_priv.h" /* FIXME */
Antti Palosaari285eb1a2009-09-15 14:42:13 -030037#include "tda1002x.h"
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030038
39MODULE_DESCRIPTION("driver for em28xx based DVB cards");
40MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
41MODULE_LICENSE("GPL");
42
43static unsigned int debug;
44module_param(debug, int, 0644);
45MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
46
47DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
48
49#define dprintk(level, fmt, arg...) do { \
50if (debug >= level) \
Aidan Thornton3421b772008-04-17 21:40:36 -030051 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030052} while (0)
53
Aidan Thornton3421b772008-04-17 21:40:36 -030054#define EM28XX_DVB_NUM_BUFS 5
Aidan Thornton3421b772008-04-17 21:40:36 -030055#define EM28XX_DVB_MAX_PACKETS 64
56
57struct em28xx_dvb {
58 struct dvb_frontend *frontend;
59
60 /* feed count management */
61 struct mutex lock;
62 int nfeeds;
63
64 /* general boilerplate stuff */
65 struct dvb_adapter adapter;
66 struct dvb_demux demux;
67 struct dmxdev dmxdev;
68 struct dmx_frontend fe_hw;
69 struct dmx_frontend fe_mem;
70 struct dvb_net net;
71};
72
73
74static inline void print_err_status(struct em28xx *dev,
75 int packet, int status)
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030076{
Aidan Thornton3421b772008-04-17 21:40:36 -030077 char *errmsg = "Unknown";
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -030078
Aidan Thornton3421b772008-04-17 21:40:36 -030079 switch (status) {
80 case -ENOENT:
81 errmsg = "unlinked synchronuously";
82 break;
83 case -ECONNRESET:
84 errmsg = "unlinked asynchronuously";
85 break;
86 case -ENOSR:
87 errmsg = "Buffer error (overrun)";
88 break;
89 case -EPIPE:
90 errmsg = "Stalled (device not responding)";
91 break;
92 case -EOVERFLOW:
93 errmsg = "Babble (bad cable?)";
94 break;
95 case -EPROTO:
96 errmsg = "Bit-stuff error (bad cable?)";
97 break;
98 case -EILSEQ:
99 errmsg = "CRC/Timeout (could be anything)";
100 break;
101 case -ETIME:
102 errmsg = "Device does not respond";
103 break;
104 }
105 if (packet < 0) {
106 dprintk(1, "URB status %d [%s].\n", status, errmsg);
107 } else {
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300108 dprintk(1, "URB packet %d, status %d [%s].\n",
109 packet, status, errmsg);
Aidan Thornton3421b772008-04-17 21:40:36 -0300110 }
111}
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300112
Aidan Thornton3421b772008-04-17 21:40:36 -0300113static inline int dvb_isoc_copy(struct em28xx *dev, struct urb *urb)
114{
115 int i;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300116
Aidan Thornton3421b772008-04-17 21:40:36 -0300117 if (!dev)
118 return 0;
119
120 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
121 return 0;
122
123 if (urb->status < 0) {
124 print_err_status(dev, -1, urb->status);
125 if (urb->status == -ENOENT)
126 return 0;
127 }
128
129 for (i = 0; i < urb->number_of_packets; i++) {
130 int status = urb->iso_frame_desc[i].status;
131
132 if (status < 0) {
133 print_err_status(dev, i, status);
134 if (urb->iso_frame_desc[i].status != -EPROTO)
135 continue;
136 }
137
138 dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer +
139 urb->iso_frame_desc[i].offset,
140 urb->iso_frame_desc[i].actual_length);
141 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300142
143 return 0;
144}
145
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300146static int start_streaming(struct em28xx_dvb *dvb)
147{
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300148 int rc;
Aidan Thornton3421b772008-04-17 21:40:36 -0300149 struct em28xx *dev = dvb->adapter.priv;
Devin Heitmuellerd18e2fd2009-05-16 17:09:28 -0300150 int max_dvb_packet_size;
Aidan Thornton3421b772008-04-17 21:40:36 -0300151
152 usb_set_interface(dev->udev, 0, 1);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300153 rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
154 if (rc < 0)
155 return rc;
Aidan Thornton3421b772008-04-17 21:40:36 -0300156
Devin Heitmuellerd18e2fd2009-05-16 17:09:28 -0300157 max_dvb_packet_size = em28xx_isoc_dvb_max_packetsize(dev);
158
Aidan Thornton3421b772008-04-17 21:40:36 -0300159 return em28xx_init_isoc(dev, EM28XX_DVB_MAX_PACKETS,
Devin Heitmuellerd18e2fd2009-05-16 17:09:28 -0300160 EM28XX_DVB_NUM_BUFS, max_dvb_packet_size,
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300161 dvb_isoc_copy);
Aidan Thornton3421b772008-04-17 21:40:36 -0300162}
163
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300164static int stop_streaming(struct em28xx_dvb *dvb)
165{
Aidan Thornton3421b772008-04-17 21:40:36 -0300166 struct em28xx *dev = dvb->adapter.priv;
167
168 em28xx_uninit_isoc(dev);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300169
Mauro Carvalho Chehab2fe3e2e2008-11-27 09:10:40 -0300170 em28xx_set_mode(dev, EM28XX_SUSPEND);
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300171
Aidan Thornton3421b772008-04-17 21:40:36 -0300172 return 0;
173}
174
175static int start_feed(struct dvb_demux_feed *feed)
176{
177 struct dvb_demux *demux = feed->demux;
178 struct em28xx_dvb *dvb = demux->priv;
179 int rc, ret;
180
181 if (!demux->dmx.frontend)
182 return -EINVAL;
183
184 mutex_lock(&dvb->lock);
185 dvb->nfeeds++;
186 rc = dvb->nfeeds;
187
188 if (dvb->nfeeds == 1) {
189 ret = start_streaming(dvb);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300190 if (ret < 0)
191 rc = ret;
Aidan Thornton3421b772008-04-17 21:40:36 -0300192 }
193
194 mutex_unlock(&dvb->lock);
195 return rc;
196}
197
198static int stop_feed(struct dvb_demux_feed *feed)
199{
200 struct dvb_demux *demux = feed->demux;
201 struct em28xx_dvb *dvb = demux->priv;
202 int err = 0;
203
204 mutex_lock(&dvb->lock);
205 dvb->nfeeds--;
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300206
207 if (0 == dvb->nfeeds)
Aidan Thornton3421b772008-04-17 21:40:36 -0300208 err = stop_streaming(dvb);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300209
Aidan Thornton3421b772008-04-17 21:40:36 -0300210 mutex_unlock(&dvb->lock);
211 return err;
212}
213
214
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300215
216/* ------------------------------------------------------------------ */
217static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
218{
219 struct em28xx *dev = fe->dvb->priv;
220
221 if (acquire)
222 return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
223 else
Mauro Carvalho Chehab2fe3e2e2008-11-27 09:10:40 -0300224 return em28xx_set_mode(dev, EM28XX_SUSPEND);
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300225}
226
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300227/* ------------------------------------------------------------------ */
228
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -0300229static struct lgdt330x_config em2880_lgdt3303_dev = {
230 .demod_address = 0x0e,
231 .demod_chip = LGDT3303,
232};
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300233
Aidan Thornton7e6388a2008-04-17 21:40:03 -0300234static struct zl10353_config em28xx_zl10353_with_xc3028 = {
235 .demod_address = (0x1e >> 1),
236 .no_tuner = 1,
237 .parallel_ts = 1,
238 .if2 = 45600,
239};
240
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300241static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
242 .demod_address = 0x32 >> 1,
243 .output_mode = S5H1409_PARALLEL_OUTPUT,
244 .gpio = S5H1409_GPIO_OFF,
245 .inversion = S5H1409_INVERSION_OFF,
246 .status_mode = S5H1409_DEMODLOCKING,
247 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
248};
249
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300250static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300251 .demod_address = (0x1e >> 1),
252 .no_tuner = 1,
253 .disable_i2c_gate_ctrl = 1,
254 .parallel_ts = 1,
255 .if2 = 45600,
256};
257
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300258#ifdef EM28XX_DRX397XD_SUPPORT
259/* [TODO] djh - not sure yet what the device config needs to contain */
260static struct drx397xD_config em28xx_drx397xD_with_xc3028 = {
261 .demod_address = (0xe0 >> 1),
262};
263#endif
264
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300265static int mt352_terratec_xs_init(struct dvb_frontend *fe)
266{
267 /* Values extracted from a USB trace of the Terratec Windows driver */
268 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
269 static u8 reset[] = { RESET, 0x80 };
270 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
271 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
272 static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
273 static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
274 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
275 static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
276 static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
Devin Heitmuellerff697862009-07-12 18:44:19 -0300277 static u8 tuner_go[] = { TUNER_GO, 0x01};
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300278
279 mt352_write(fe, clock_config, sizeof(clock_config));
280 udelay(200);
281 mt352_write(fe, reset, sizeof(reset));
282 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
283 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
284 mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
285 mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
286 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
287 mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
288 mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
289 mt352_write(fe, tuner_go, sizeof(tuner_go));
290 return 0;
291}
292
293static struct mt352_config terratec_xs_mt352_cfg = {
294 .demod_address = (0x1e >> 1),
295 .no_tuner = 1,
296 .if2 = 45600,
297 .demod_init = mt352_terratec_xs_init,
298};
299
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300300static struct tda10023_config em28xx_tda10023_config = {
301 .demod_address = 0x0c,
302 .invert = 1,
303};
304
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300305/* ------------------------------------------------------------------ */
306
307static int attach_xc3028(u8 addr, struct em28xx *dev)
308{
309 struct dvb_frontend *fe;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300310 struct xc2028_config cfg;
311
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300312 memset(&cfg, 0, sizeof(cfg));
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300313 cfg.i2c_adap = &dev->i2c_adap;
314 cfg.i2c_addr = addr;
Mauro Carvalho Chehab3ca9c092008-04-17 21:37:53 -0300315
Aidan Thornton3421b772008-04-17 21:40:36 -0300316 if (!dev->dvb->frontend) {
Filipe Rosset480be182009-11-04 15:32:37 -0300317 em28xx_errdev("/2: dvb frontend not attached. "
318 "Can't attach xc3028\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300319 return -EINVAL;
320 }
321
Aidan Thornton3421b772008-04-17 21:40:36 -0300322 fe = dvb_attach(xc2028_attach, dev->dvb->frontend, &cfg);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300323 if (!fe) {
Filipe Rosset480be182009-11-04 15:32:37 -0300324 em28xx_errdev("/2: xc3028 attach failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -0300325 dvb_frontend_detach(dev->dvb->frontend);
Aidan Thornton3421b772008-04-17 21:40:36 -0300326 dev->dvb->frontend = NULL;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300327 return -EINVAL;
328 }
329
Filipe Rosset480be182009-11-04 15:32:37 -0300330 em28xx_info("%s/2: xc3028 attached\n", dev->name);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300331
332 return 0;
333}
334
Aidan Thornton3421b772008-04-17 21:40:36 -0300335/* ------------------------------------------------------------------ */
336
Hans Verkuild45b9b82008-09-04 03:33:43 -0300337static int register_dvb(struct em28xx_dvb *dvb,
Aidan Thornton3421b772008-04-17 21:40:36 -0300338 struct module *module,
339 struct em28xx *dev,
340 struct device *device)
341{
342 int result;
343
344 mutex_init(&dvb->lock);
345
346 /* register adapter */
347 result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
348 adapter_nr);
349 if (result < 0) {
350 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
351 dev->name, result);
352 goto fail_adapter;
353 }
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300354
355 /* Ensure all frontends negotiate bus access */
356 dvb->frontend->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
357
Aidan Thornton3421b772008-04-17 21:40:36 -0300358 dvb->adapter.priv = dev;
359
360 /* register frontend */
361 result = dvb_register_frontend(&dvb->adapter, dvb->frontend);
362 if (result < 0) {
363 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
364 dev->name, result);
365 goto fail_frontend;
366 }
367
368 /* register demux stuff */
369 dvb->demux.dmx.capabilities =
370 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
371 DMX_MEMORY_BASED_FILTERING;
372 dvb->demux.priv = dvb;
373 dvb->demux.filternum = 256;
374 dvb->demux.feednum = 256;
375 dvb->demux.start_feed = start_feed;
376 dvb->demux.stop_feed = stop_feed;
Mauro Carvalho Chehabe3569ab2008-04-17 21:49:20 -0300377
Aidan Thornton3421b772008-04-17 21:40:36 -0300378 result = dvb_dmx_init(&dvb->demux);
379 if (result < 0) {
380 printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
381 dev->name, result);
382 goto fail_dmx;
383 }
384
385 dvb->dmxdev.filternum = 256;
386 dvb->dmxdev.demux = &dvb->demux.dmx;
387 dvb->dmxdev.capabilities = 0;
388 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
389 if (result < 0) {
390 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
391 dev->name, result);
392 goto fail_dmxdev;
393 }
394
395 dvb->fe_hw.source = DMX_FRONTEND_0;
396 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
397 if (result < 0) {
398 printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
399 dev->name, result);
400 goto fail_fe_hw;
401 }
402
403 dvb->fe_mem.source = DMX_MEMORY_FE;
404 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
405 if (result < 0) {
406 printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
407 dev->name, result);
408 goto fail_fe_mem;
409 }
410
411 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
412 if (result < 0) {
413 printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
414 dev->name, result);
415 goto fail_fe_conn;
416 }
417
418 /* register network adapter */
419 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
420 return 0;
421
422fail_fe_conn:
423 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
424fail_fe_mem:
425 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
426fail_fe_hw:
427 dvb_dmxdev_release(&dvb->dmxdev);
428fail_dmxdev:
429 dvb_dmx_release(&dvb->demux);
430fail_dmx:
431 dvb_unregister_frontend(dvb->frontend);
432fail_frontend:
433 dvb_frontend_detach(dvb->frontend);
434 dvb_unregister_adapter(&dvb->adapter);
435fail_adapter:
436 return result;
437}
438
439static void unregister_dvb(struct em28xx_dvb *dvb)
440{
441 dvb_net_release(&dvb->net);
442 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
443 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
444 dvb_dmxdev_release(&dvb->dmxdev);
445 dvb_dmx_release(&dvb->demux);
446 dvb_unregister_frontend(dvb->frontend);
447 dvb_frontend_detach(dvb->frontend);
448 dvb_unregister_adapter(&dvb->adapter);
449}
450
451
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300452static int dvb_init(struct em28xx *dev)
453{
Aidan Thornton3421b772008-04-17 21:40:36 -0300454 int result = 0;
455 struct em28xx_dvb *dvb;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300456
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -0300457 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -0300458 /* This device does not support the extension */
459 return 0;
460 }
461
Aidan Thornton3421b772008-04-17 21:40:36 -0300462 dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300463
464 if (dvb == NULL) {
Filipe Rosset480be182009-11-04 15:32:37 -0300465 em28xx_info("em28xx_dvb: memory allocation failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -0300466 return -ENOMEM;
467 }
468 dev->dvb = dvb;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300469
Mauro Carvalho Chehabc67ec532008-04-17 21:48:00 -0300470 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300471 /* init frontend */
472 switch (dev->model) {
Douglas Schilling Landgraff89bc322008-12-01 21:01:04 -0300473 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
Mauro Carvalho Chehab10ac6602008-07-27 14:58:58 -0300474 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
Devin Heitmueller4fd305b2008-06-04 13:43:46 -0300475 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
Devin Heitmuellere14b3652008-07-26 11:04:33 -0300476 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
Aidan Thornton3421b772008-04-17 21:40:36 -0300477 dvb->frontend = dvb_attach(lgdt330x_attach,
478 &em2880_lgdt3303_dev,
479 &dev->i2c_adap);
480 if (attach_xc3028(0x61, dev) < 0) {
481 result = -EINVAL;
482 goto out_free;
483 }
Mauro Carvalho Chehab227ad4a2008-04-17 21:37:40 -0300484 break;
Thierry MERLE46510b52008-10-11 16:56:13 -0300485 case EM2880_BOARD_KWORLD_DVB_310U:
Aidan Thornton3421b772008-04-17 21:40:36 -0300486 dvb->frontend = dvb_attach(zl10353_attach,
487 &em28xx_zl10353_with_xc3028,
488 &dev->i2c_adap);
489 if (attach_xc3028(0x61, dev) < 0) {
490 result = -EINVAL;
491 goto out_free;
492 }
Aidan Thornton7e6388a2008-04-17 21:40:03 -0300493 break;
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300494 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
Uroš Vamplec994d02009-09-30 22:53:37 -0300495 case EM2882_BOARD_TERRATEC_HYBRID_XS:
Devin Heitmueller01a5fd62009-08-07 09:25:06 -0300496 case EM2880_BOARD_EMPIRE_DUAL_TV:
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300497 dvb->frontend = dvb_attach(zl10353_attach,
498 &em28xx_zl10353_xc3028_no_i2c_gate,
499 &dev->i2c_adap);
500 if (attach_xc3028(0x61, dev) < 0) {
501 result = -EINVAL;
502 goto out_free;
503 }
504 break;
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300505 case EM2880_BOARD_TERRATEC_HYBRID_XS:
Catimimi65638012010-02-18 18:06:32 -0300506 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
Devin Heitmuellerd5b3ba92009-07-08 21:51:35 -0300507 case EM2881_BOARD_PINNACLE_HYBRID_PRO:
Andrea.Amorosi76@gmail.com7ca7ef62010-02-09 17:53:38 -0300508 case EM2882_BOARD_DIKOM_DK300:
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300509 dvb->frontend = dvb_attach(zl10353_attach,
Devin Heitmuellera84f79a2009-07-12 17:05:02 -0300510 &em28xx_zl10353_xc3028_no_i2c_gate,
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300511 &dev->i2c_adap);
512 if (dvb->frontend == NULL) {
513 /* This board could have either a zl10353 or a mt352.
514 If the chip id isn't for zl10353, try mt352 */
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300515 dvb->frontend = dvb_attach(mt352_attach,
516 &terratec_xs_mt352_cfg,
517 &dev->i2c_adap);
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300518 }
Devin Heitmueller4fb202a2009-07-12 17:51:12 -0300519
Devin Heitmuellerf7976082009-06-22 22:32:32 -0300520 if (attach_xc3028(0x61, dev) < 0) {
521 result = -EINVAL;
522 goto out_free;
523 }
524 break;
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300525 case EM2883_BOARD_KWORLD_HYBRID_330U:
Devin Heitmueller19859222009-06-19 00:33:54 -0300526 case EM2882_BOARD_EVGA_INDTUBE:
Robert Krakora6e7b9ea2009-01-18 21:59:34 -0300527 dvb->frontend = dvb_attach(s5h1409_attach,
528 &em28xx_s5h1409_with_xc3028,
529 &dev->i2c_adap);
530 if (attach_xc3028(0x61, dev) < 0) {
531 result = -EINVAL;
532 goto out_free;
533 }
534 break;
Franklin Mengd7de5d82009-06-06 17:05:02 -0300535 case EM2882_BOARD_KWORLD_ATSC_315U:
536 dvb->frontend = dvb_attach(lgdt330x_attach,
537 &em2880_lgdt3303_dev,
538 &dev->i2c_adap);
539 if (dvb->frontend != NULL) {
540 if (!dvb_attach(simple_tuner_attach, dvb->frontend,
541 &dev->i2c_adap, 0x61, TUNER_THOMSON_DTT761X)) {
542 result = -EINVAL;
543 goto out_free;
544 }
545 }
546 break;
Devin Heitmueller17d9d552008-06-08 10:22:03 -0300547 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
548#ifdef EM28XX_DRX397XD_SUPPORT
549 /* We don't have the config structure properly populated, so
550 this is commented out for now */
551 dvb->frontend = dvb_attach(drx397xD_attach,
552 &em28xx_drx397xD_with_xc3028,
553 &dev->i2c_adap);
554 if (attach_xc3028(0x61, dev) < 0) {
555 result = -EINVAL;
556 goto out_free;
557 }
558 break;
559#endif
Antti Palosaari285eb1a2009-09-15 14:42:13 -0300560 case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
561 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
562 dvb->frontend = dvb_attach(tda10023_attach,
563 &em28xx_tda10023_config,
564 &dev->i2c_adap, 0x48);
565 if (dvb->frontend) {
566 if (!dvb_attach(simple_tuner_attach, dvb->frontend,
567 &dev->i2c_adap, 0x60, TUNER_PHILIPS_CU1216L)) {
568 result = -EINVAL;
569 goto out_free;
570 }
571 }
572 break;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300573 default:
Filipe Rosset480be182009-11-04 15:32:37 -0300574 em28xx_errdev("/2: The frontend of your DVB/ATSC card"
575 " isn't supported yet\n");
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300576 break;
577 }
Aidan Thornton3421b772008-04-17 21:40:36 -0300578 if (NULL == dvb->frontend) {
Filipe Rosset480be182009-11-04 15:32:37 -0300579 em28xx_errdev("/2: frontend initialization failed\n");
Aidan Thornton3421b772008-04-17 21:40:36 -0300580 result = -EINVAL;
581 goto out_free;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300582 }
Michael Krufkyd7cba042008-09-12 13:31:45 -0300583 /* define general-purpose callback pointer */
584 dvb->frontend->callback = em28xx_tuner_callback;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300585
586 /* register everything */
Aidan Thornton3421b772008-04-17 21:40:36 -0300587 result = register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
588
Douglas Schilling Landgraf6ea54d92008-04-17 21:41:10 -0300589 if (result < 0)
Aidan Thornton3421b772008-04-17 21:40:36 -0300590 goto out_free;
Aidan Thornton3421b772008-04-17 21:40:36 -0300591
Mauro Carvalho Chehab2fe3e2e2008-11-27 09:10:40 -0300592 em28xx_set_mode(dev, EM28XX_SUSPEND);
Filipe Rosset480be182009-11-04 15:32:37 -0300593 em28xx_info("Successfully loaded em28xx-dvb\n");
Aidan Thornton3421b772008-04-17 21:40:36 -0300594 return 0;
595
596out_free:
Mauro Carvalho Chehab2fe3e2e2008-11-27 09:10:40 -0300597 em28xx_set_mode(dev, EM28XX_SUSPEND);
Aidan Thornton3421b772008-04-17 21:40:36 -0300598 kfree(dvb);
599 dev->dvb = NULL;
600 return result;
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300601}
602
603static int dvb_fini(struct em28xx *dev)
604{
Mauro Carvalho Chehab505b6d02008-11-25 09:39:50 -0300605 if (!dev->board.has_dvb) {
Devin Heitmuellerdf619182008-06-10 12:34:35 -0300606 /* This device does not support the extension */
607 return 0;
608 }
609
Aidan Thornton3421b772008-04-17 21:40:36 -0300610 if (dev->dvb) {
611 unregister_dvb(dev->dvb);
Francesco Lavra19f48cb2009-12-31 08:47:11 -0300612 kfree(dev->dvb);
Aidan Thornton3421b772008-04-17 21:40:36 -0300613 dev->dvb = NULL;
614 }
Mauro Carvalho Chehab3aefb792008-04-17 21:36:41 -0300615
616 return 0;
617}
618
619static struct em28xx_ops dvb_ops = {
620 .id = EM28XX_DVB,
621 .name = "Em28xx dvb Extension",
622 .init = dvb_init,
623 .fini = dvb_fini,
624};
625
626static int __init em28xx_dvb_register(void)
627{
628 return em28xx_register_extension(&dvb_ops);
629}
630
631static void __exit em28xx_dvb_unregister(void)
632{
633 em28xx_unregister_extension(&dvb_ops);
634}
635
636module_init(em28xx_dvb_register);
637module_exit(em28xx_dvb_unregister);