2 DVB device driver for em28xx
4 (c) 2008-2011 Mauro Carvalho Chehab <mchehab@infradead.org>
6 (c) 2008 Devin Heitmueller <devin.heitmueller@gmail.com>
7 - Fixes for the driver to properly work with HVR-950
8 - Fixes for the driver to properly work with Pinnacle PCTV HD Pro Stick
9 - Fixes for the driver to properly work with AMD ATI TV Wonder HD 600
11 (c) 2008 Aidan Thornton <makosoft@googlemail.com>
13 Based on cx88-dvb, saa7134-dvb and videobuf-dvb originally written by:
14 (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
15 (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
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.
22 #include <linux/kernel.h>
23 #include <linux/slab.h>
24 #include <linux/usb.h>
27 #include <media/v4l2-common.h>
28 #include <media/videobuf-vmalloc.h>
29 #include <media/tuner.h>
30 #include "tuner-simple.h"
37 #include "mt352_priv.h" /* FIXME */
43 #include "tda18271c2dd.h"
49 MODULE_DESCRIPTION("driver for em28xx based DVB cards");
50 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
51 MODULE_LICENSE("GPL");
53 static unsigned int debug;
54 module_param(debug, int, 0644);
55 MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
57 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
59 #define dprintk(level, fmt, arg...) do { \
61 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \
65 struct dvb_frontend *fe[2];
67 /* feed count management */
71 /* general boilerplate stuff */
72 struct dvb_adapter adapter;
73 struct dvb_demux demux;
75 struct dmx_frontend fe_hw;
76 struct dmx_frontend fe_mem;
79 /* Due to DRX-K - probably need changes */
80 int (*gate_ctrl)(struct dvb_frontend *, int);
81 struct semaphore pll_mutex;
86 static inline void print_err_status(struct em28xx *dev,
87 int packet, int status)
89 char *errmsg = "Unknown";
93 errmsg = "unlinked synchronuously";
96 errmsg = "unlinked asynchronuously";
99 errmsg = "Buffer error (overrun)";
102 errmsg = "Stalled (device not responding)";
105 errmsg = "Babble (bad cable?)";
108 errmsg = "Bit-stuff error (bad cable?)";
111 errmsg = "CRC/Timeout (could be anything)";
114 errmsg = "Device does not respond";
118 dprintk(1, "URB status %d [%s].\n", status, errmsg);
120 dprintk(1, "URB packet %d, status %d [%s].\n",
121 packet, status, errmsg);
125 static inline int em28xx_dvb_isoc_copy(struct em28xx *dev, struct urb *urb)
132 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
135 if (urb->status < 0) {
136 print_err_status(dev, -1, urb->status);
137 if (urb->status == -ENOENT)
141 for (i = 0; i < urb->number_of_packets; i++) {
142 int status = urb->iso_frame_desc[i].status;
145 print_err_status(dev, i, status);
146 if (urb->iso_frame_desc[i].status != -EPROTO)
150 dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer +
151 urb->iso_frame_desc[i].offset,
152 urb->iso_frame_desc[i].actual_length);
158 static int em28xx_start_streaming(struct em28xx_dvb *dvb)
161 struct em28xx *dev = dvb->adapter.priv;
162 int max_dvb_packet_size;
164 usb_set_interface(dev->udev, 0, dev->dvb_alt);
165 rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
169 max_dvb_packet_size = dev->dvb_max_pkt_size;
170 if (max_dvb_packet_size < 0)
171 return max_dvb_packet_size;
172 dprintk(1, "Using %d buffers each with %d x %d bytes\n",
174 EM28XX_DVB_MAX_PACKETS,
175 max_dvb_packet_size);
177 return em28xx_init_isoc(dev, EM28XX_DIGITAL_MODE,
178 EM28XX_DVB_MAX_PACKETS, EM28XX_DVB_NUM_BUFS,
179 max_dvb_packet_size, em28xx_dvb_isoc_copy);
182 static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
184 struct em28xx *dev = dvb->adapter.priv;
186 em28xx_stop_urbs(dev);
188 em28xx_set_mode(dev, EM28XX_SUSPEND);
193 static int em28xx_start_feed(struct dvb_demux_feed *feed)
195 struct dvb_demux *demux = feed->demux;
196 struct em28xx_dvb *dvb = demux->priv;
199 if (!demux->dmx.frontend)
202 mutex_lock(&dvb->lock);
206 if (dvb->nfeeds == 1) {
207 ret = em28xx_start_streaming(dvb);
212 mutex_unlock(&dvb->lock);
216 static int em28xx_stop_feed(struct dvb_demux_feed *feed)
218 struct dvb_demux *demux = feed->demux;
219 struct em28xx_dvb *dvb = demux->priv;
222 mutex_lock(&dvb->lock);
225 if (0 == dvb->nfeeds)
226 err = em28xx_stop_streaming(dvb);
228 mutex_unlock(&dvb->lock);
234 /* ------------------------------------------------------------------ */
235 static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
237 struct em28xx *dev = fe->dvb->priv;
240 return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
242 return em28xx_set_mode(dev, EM28XX_SUSPEND);
245 /* ------------------------------------------------------------------ */
247 static struct lgdt330x_config em2880_lgdt3303_dev = {
248 .demod_address = 0x0e,
249 .demod_chip = LGDT3303,
252 static struct lgdt3305_config em2870_lgdt3304_dev = {
254 .demod_chip = LGDT3304,
255 .spectral_inversion = 1,
257 .mpeg_mode = LGDT3305_MPEG_PARALLEL,
258 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
259 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
264 static struct s921_config sharp_isdbt = {
265 .demod_address = 0x30 >> 1
268 static struct zl10353_config em28xx_zl10353_with_xc3028 = {
269 .demod_address = (0x1e >> 1),
275 static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
276 .demod_address = 0x32 >> 1,
277 .output_mode = S5H1409_PARALLEL_OUTPUT,
278 .gpio = S5H1409_GPIO_OFF,
279 .inversion = S5H1409_INVERSION_OFF,
280 .status_mode = S5H1409_DEMODLOCKING,
281 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
284 static struct tda18271_std_map kworld_a340_std_map = {
285 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
286 .if_lvl = 1, .rfagc_top = 0x37, },
287 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
288 .if_lvl = 1, .rfagc_top = 0x37, },
291 static struct tda18271_config kworld_a340_config = {
292 .std_map = &kworld_a340_std_map,
295 static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
296 .demod_address = (0x1e >> 1),
298 .disable_i2c_gate_ctrl = 1,
303 static struct drxd_config em28xx_drxd = {
304 .demod_address = 0x70,
305 .demod_revision = 0xa2,
306 .pll_type = DRXD_PLL_NONE,
310 .disable_i2c_gate_ctrl = 1,
313 static struct drxk_config terratec_h5_drxk = {
317 .microcode_name = "dvb-usb-terratec-h5-drxk.fw",
320 static struct drxk_config hauppauge_930c_drxk = {
324 .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
328 struct drxk_config terratec_htc_stick_drxk = {
332 .microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw",
334 /* Required for the antenna_gpio to disable LNA. */
335 .antenna_dvbt = true,
336 /* The windows driver uses the same. This will disable LNA. */
340 static struct drxk_config maxmedia_ub425_tc_drxk = {
346 static struct drxk_config pctv_520e_drxk = {
349 .microcode_name = "dvb-demod-drxk-pctv.fw",
351 .antenna_dvbt = true, /* disable LNA */
352 .antenna_gpio = (1 << 2), /* disable LNA */
355 static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
357 struct em28xx_dvb *dvb = fe->sec_priv;
364 down(&dvb->pll_mutex);
365 status = dvb->gate_ctrl(fe, 1);
367 status = dvb->gate_ctrl(fe, 0);
373 static void hauppauge_hvr930c_init(struct em28xx *dev)
377 struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
378 {EM2874_R80_GPIO, 0xff, 0xff, 0x65},
379 {EM2874_R80_GPIO, 0xfb, 0xff, 0x32},
380 {EM2874_R80_GPIO, 0xff, 0xff, 0xb8},
383 struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
384 {EM2874_R80_GPIO, 0xef, 0xff, 0x01},
385 {EM2874_R80_GPIO, 0xaf, 0xff, 0x65},
386 {EM2874_R80_GPIO, 0xef, 0xff, 0x76},
387 {EM2874_R80_GPIO, 0xef, 0xff, 0x01},
388 {EM2874_R80_GPIO, 0xcf, 0xff, 0x0b},
389 {EM2874_R80_GPIO, 0xef, 0xff, 0x40},
391 {EM2874_R80_GPIO, 0xcf, 0xff, 0x65},
392 {EM2874_R80_GPIO, 0xef, 0xff, 0x65},
393 {EM2874_R80_GPIO, 0xcf, 0xff, 0x0b},
394 {EM2874_R80_GPIO, 0xef, 0xff, 0x65},
403 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
405 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
407 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
408 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
410 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
413 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
415 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
418 em28xx_gpio_set(dev, hauppauge_hvr930c_init);
419 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
421 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
424 dev->i2c_client.addr = 0x82 >> 1;
426 for (i = 0; i < ARRAY_SIZE(regs); i++)
427 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
428 em28xx_gpio_set(dev, hauppauge_hvr930c_end);
432 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
435 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
440 static void terratec_h5_init(struct em28xx *dev)
443 struct em28xx_reg_seq terratec_h5_init[] = {
444 {EM28XX_R08_GPIO, 0xff, 0xff, 10},
445 {EM2874_R80_GPIO, 0xf6, 0xff, 100},
446 {EM2874_R80_GPIO, 0xf2, 0xff, 50},
447 {EM2874_R80_GPIO, 0xf6, 0xff, 100},
450 struct em28xx_reg_seq terratec_h5_end[] = {
451 {EM2874_R80_GPIO, 0xe6, 0xff, 100},
452 {EM2874_R80_GPIO, 0xa6, 0xff, 50},
453 {EM2874_R80_GPIO, 0xe6, 0xff, 100},
460 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
462 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
464 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
465 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
467 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
470 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
472 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
475 em28xx_gpio_set(dev, terratec_h5_init);
476 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
478 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
481 dev->i2c_client.addr = 0x82 >> 1;
483 for (i = 0; i < ARRAY_SIZE(regs); i++)
484 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
485 em28xx_gpio_set(dev, terratec_h5_end);
488 static void terratec_htc_stick_init(struct em28xx *dev)
493 * GPIO configuration:
494 * 0xff: unknown (does not affect DVB-T).
495 * 0xf6: DRX-K (demodulator).
496 * 0xe6: unknown (does not affect DVB-T).
497 * 0xb6: unknown (does not affect DVB-T).
499 struct em28xx_reg_seq terratec_htc_stick_init[] = {
500 {EM28XX_R08_GPIO, 0xff, 0xff, 10},
501 {EM2874_R80_GPIO, 0xf6, 0xff, 100},
502 {EM2874_R80_GPIO, 0xe6, 0xff, 50},
503 {EM2874_R80_GPIO, 0xf6, 0xff, 100},
506 struct em28xx_reg_seq terratec_htc_stick_end[] = {
507 {EM2874_R80_GPIO, 0xb6, 0xff, 100},
508 {EM2874_R80_GPIO, 0xf6, 0xff, 50},
512 /* Init the analog decoder? */
517 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
519 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
521 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
524 em28xx_gpio_set(dev, terratec_htc_stick_init);
526 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
528 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
531 dev->i2c_client.addr = 0x82 >> 1;
533 for (i = 0; i < ARRAY_SIZE(regs); i++)
534 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
536 em28xx_gpio_set(dev, terratec_htc_stick_end);
539 static void pctv_520e_init(struct em28xx *dev)
542 * Init AVF4910B analog decoder. Looks like I2C traffic to
543 * digital demodulator and tuner are routed via AVF4910B.
550 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
552 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
554 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
555 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
557 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
560 dev->i2c_client.addr = 0x82 >> 1; /* 0x41 */
562 for (i = 0; i < ARRAY_SIZE(regs); i++)
563 i2c_master_send(&dev->i2c_client, regs[i].r, regs[i].len);
566 static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
568 /* Values extracted from a USB trace of the Terratec Windows driver */
569 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
570 static u8 reset[] = { RESET, 0x80 };
571 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
572 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
573 static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
574 static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
575 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
576 static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
577 static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
578 static u8 tuner_go[] = { TUNER_GO, 0x01};
580 mt352_write(fe, clock_config, sizeof(clock_config));
582 mt352_write(fe, reset, sizeof(reset));
583 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
584 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
585 mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
586 mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
587 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
588 mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
589 mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
590 mt352_write(fe, tuner_go, sizeof(tuner_go));
594 static struct mt352_config terratec_xs_mt352_cfg = {
595 .demod_address = (0x1e >> 1),
598 .demod_init = em28xx_mt352_terratec_xs_init,
601 static struct tda10023_config em28xx_tda10023_config = {
602 .demod_address = 0x0c,
606 static struct cxd2820r_config em28xx_cxd2820r_config = {
607 .i2c_address = (0xd8 >> 1),
608 .ts_mode = CXD2820R_TS_SERIAL,
610 /* enable LNA for DVB-T, DVB-T2 and DVB-C */
611 .gpio_dvbt[0] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | CXD2820R_GPIO_L,
612 .gpio_dvbt2[0] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | CXD2820R_GPIO_L,
613 .gpio_dvbc[0] = CXD2820R_GPIO_E | CXD2820R_GPIO_O | CXD2820R_GPIO_L,
616 static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
617 .output_opt = TDA18271_OUTPUT_LT_OFF,
618 .gate = TDA18271_GATE_DIGITAL,
621 static const struct tda10071_config em28xx_tda10071_config = {
622 .i2c_address = 0x55, /* (0xaa >> 1) */
624 .ts_mode = TDA10071_TS_SERIAL,
626 .xtal = 40444000, /* 40.444 MHz */
627 .pll_multiplier = 20,
630 static const struct a8293_config em28xx_a8293_config = {
631 .i2c_addr = 0x08, /* (0x10 >> 1) */
634 static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
635 .demod_address = (0x1e >> 1),
636 .disable_i2c_gate_ctrl = 1,
640 static struct qt1010_config em28xx_qt1010_config = {
645 /* ------------------------------------------------------------------ */
647 static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
649 struct dvb_frontend *fe;
650 struct xc2028_config cfg;
652 memset(&cfg, 0, sizeof(cfg));
653 cfg.i2c_adap = &dev->i2c_adap;
656 if (!dev->dvb->fe[0]) {
657 em28xx_errdev("/2: dvb frontend not attached. "
658 "Can't attach xc3028\n");
662 fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
664 em28xx_errdev("/2: xc3028 attach failed\n");
665 dvb_frontend_detach(dev->dvb->fe[0]);
666 dev->dvb->fe[0] = NULL;
670 em28xx_info("%s/2: xc3028 attached\n", dev->name);
675 /* ------------------------------------------------------------------ */
677 static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
678 struct em28xx *dev, struct device *device)
682 mutex_init(&dvb->lock);
684 /* register adapter */
685 result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
688 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
693 /* Ensure all frontends negotiate bus access */
694 dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
696 dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
698 dvb->adapter.priv = dev;
700 /* register frontend */
701 result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
703 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
708 /* register 2nd frontend */
710 result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
712 printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
718 /* register demux stuff */
719 dvb->demux.dmx.capabilities =
720 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
721 DMX_MEMORY_BASED_FILTERING;
722 dvb->demux.priv = dvb;
723 dvb->demux.filternum = 256;
724 dvb->demux.feednum = 256;
725 dvb->demux.start_feed = em28xx_start_feed;
726 dvb->demux.stop_feed = em28xx_stop_feed;
728 result = dvb_dmx_init(&dvb->demux);
730 printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
735 dvb->dmxdev.filternum = 256;
736 dvb->dmxdev.demux = &dvb->demux.dmx;
737 dvb->dmxdev.capabilities = 0;
738 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
740 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
745 dvb->fe_hw.source = DMX_FRONTEND_0;
746 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
748 printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
753 dvb->fe_mem.source = DMX_MEMORY_FE;
754 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
756 printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
761 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
763 printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
768 /* register network adapter */
769 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
773 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
775 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
777 dvb_dmxdev_release(&dvb->dmxdev);
779 dvb_dmx_release(&dvb->demux);
782 dvb_unregister_frontend(dvb->fe[1]);
783 dvb_unregister_frontend(dvb->fe[0]);
786 dvb_frontend_detach(dvb->fe[1]);
788 dvb_frontend_detach(dvb->fe[0]);
789 dvb_unregister_adapter(&dvb->adapter);
794 static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
796 dvb_net_release(&dvb->net);
797 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
798 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
799 dvb_dmxdev_release(&dvb->dmxdev);
800 dvb_dmx_release(&dvb->demux);
802 dvb_unregister_frontend(dvb->fe[1]);
803 dvb_unregister_frontend(dvb->fe[0]);
804 if (dvb->fe[1] && !dvb->dont_attach_fe1)
805 dvb_frontend_detach(dvb->fe[1]);
806 dvb_frontend_detach(dvb->fe[0]);
807 dvb_unregister_adapter(&dvb->adapter);
810 static int em28xx_dvb_init(struct em28xx *dev)
812 int result = 0, mfe_shared = 0;
813 struct em28xx_dvb *dvb;
815 if (!dev->board.has_dvb) {
816 /* This device does not support the extension */
817 printk(KERN_INFO "em28xx_dvb: This device does not support the extension\n");
821 dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
824 em28xx_info("em28xx_dvb: memory allocation failed\n");
828 dvb->fe[0] = dvb->fe[1] = NULL;
830 mutex_lock(&dev->lock);
831 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
833 switch (dev->model) {
834 case EM2874_BOARD_LEADERSHIP_ISDBT:
835 dvb->fe[0] = dvb_attach(s921_attach,
836 &sharp_isdbt, &dev->i2c_adap);
844 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
845 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
846 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
847 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
848 dvb->fe[0] = dvb_attach(lgdt330x_attach,
849 &em2880_lgdt3303_dev,
851 if (em28xx_attach_xc3028(0x61, dev) < 0) {
856 case EM2880_BOARD_KWORLD_DVB_310U:
857 dvb->fe[0] = dvb_attach(zl10353_attach,
858 &em28xx_zl10353_with_xc3028,
860 if (em28xx_attach_xc3028(0x61, dev) < 0) {
865 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
866 case EM2882_BOARD_TERRATEC_HYBRID_XS:
867 case EM2880_BOARD_EMPIRE_DUAL_TV:
868 dvb->fe[0] = dvb_attach(zl10353_attach,
869 &em28xx_zl10353_xc3028_no_i2c_gate,
871 if (em28xx_attach_xc3028(0x61, dev) < 0) {
876 case EM2880_BOARD_TERRATEC_HYBRID_XS:
877 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
878 case EM2881_BOARD_PINNACLE_HYBRID_PRO:
879 case EM2882_BOARD_DIKOM_DK300:
880 case EM2882_BOARD_KWORLD_VS_DVBT:
881 dvb->fe[0] = dvb_attach(zl10353_attach,
882 &em28xx_zl10353_xc3028_no_i2c_gate,
884 if (dvb->fe[0] == NULL) {
885 /* This board could have either a zl10353 or a mt352.
886 If the chip id isn't for zl10353, try mt352 */
887 dvb->fe[0] = dvb_attach(mt352_attach,
888 &terratec_xs_mt352_cfg,
892 if (em28xx_attach_xc3028(0x61, dev) < 0) {
897 case EM2870_BOARD_KWORLD_355U:
898 dvb->fe[0] = dvb_attach(zl10353_attach,
899 &em28xx_zl10353_no_i2c_gate_dev,
901 if (dvb->fe[0] != NULL)
902 dvb_attach(qt1010_attach, dvb->fe[0],
903 &dev->i2c_adap, &em28xx_qt1010_config);
905 case EM2883_BOARD_KWORLD_HYBRID_330U:
906 case EM2882_BOARD_EVGA_INDTUBE:
907 dvb->fe[0] = dvb_attach(s5h1409_attach,
908 &em28xx_s5h1409_with_xc3028,
910 if (em28xx_attach_xc3028(0x61, dev) < 0) {
915 case EM2882_BOARD_KWORLD_ATSC_315U:
916 dvb->fe[0] = dvb_attach(lgdt330x_attach,
917 &em2880_lgdt3303_dev,
919 if (dvb->fe[0] != NULL) {
920 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
921 &dev->i2c_adap, 0x61, TUNER_THOMSON_DTT761X)) {
927 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
928 case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
929 dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
930 &dev->i2c_adap, &dev->udev->dev);
931 if (em28xx_attach_xc3028(0x61, dev) < 0) {
936 case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
937 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
938 dvb->fe[0] = dvb_attach(tda10023_attach,
939 &em28xx_tda10023_config,
940 &dev->i2c_adap, 0x48);
942 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
943 &dev->i2c_adap, 0x60, TUNER_PHILIPS_CU1216L)) {
949 case EM2870_BOARD_KWORLD_A340:
950 dvb->fe[0] = dvb_attach(lgdt3305_attach,
951 &em2870_lgdt3304_dev,
953 if (dvb->fe[0] != NULL)
954 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
955 &dev->i2c_adap, &kworld_a340_config);
957 case EM28174_BOARD_PCTV_290E:
958 dvb->fe[0] = dvb_attach(cxd2820r_attach,
959 &em28xx_cxd2820r_config,
962 /* FE 0 attach tuner */
963 if (!dvb_attach(tda18271_attach,
967 &em28xx_cxd2820r_tda18271_config)) {
969 dvb_frontend_detach(dvb->fe[0]);
975 case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
977 struct xc5000_config cfg;
978 hauppauge_hvr930c_init(dev);
980 dvb->fe[0] = dvb_attach(drxk_attach,
981 &hauppauge_930c_drxk, &dev->i2c_adap);
986 /* FIXME: do we need a pll semaphore? */
987 dvb->fe[0]->sec_priv = dvb;
988 sema_init(&dvb->pll_mutex, 1);
989 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
990 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
993 memset(&cfg, 0, sizeof(cfg));
994 cfg.i2c_address = 0x61;
997 if (dvb->fe[0]->ops.i2c_gate_ctrl)
998 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
999 if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap,
1004 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1005 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1009 case EM2884_BOARD_TERRATEC_H5:
1010 terratec_h5_init(dev);
1012 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap);
1017 /* FIXME: do we need a pll semaphore? */
1018 dvb->fe[0]->sec_priv = dvb;
1019 sema_init(&dvb->pll_mutex, 1);
1020 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1021 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
1023 /* Attach tda18271 to DVB-C frontend */
1024 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1025 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1026 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap, 0x60)) {
1030 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1031 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1034 case EM28174_BOARD_PCTV_460E:
1036 dvb->fe[0] = dvb_attach(tda10071_attach,
1037 &em28xx_tda10071_config, &dev->i2c_adap);
1041 dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap,
1042 &em28xx_a8293_config);
1044 case EM2874_BOARD_MAXMEDIA_UB425_TC:
1045 /* attach demodulator */
1046 dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
1050 /* disable I2C-gate */
1051 dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
1054 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0],
1055 &dev->i2c_adap, 0x60)) {
1056 dvb_frontend_detach(dvb->fe[0]);
1062 /* TODO: we need drx-3913k firmware in order to support DVB-T */
1063 em28xx_info("MaxMedia UB425-TC: only DVB-C supported by that " \
1064 "driver version\n");
1067 case EM2884_BOARD_PCTV_510E:
1068 case EM2884_BOARD_PCTV_520E:
1069 pctv_520e_init(dev);
1071 /* attach demodulator */
1072 dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
1077 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1079 &em28xx_cxd2820r_tda18271_config)) {
1080 dvb_frontend_detach(dvb->fe[0]);
1086 case EM2884_BOARD_CINERGY_HTC_STICK:
1087 terratec_htc_stick_init(dev);
1089 /* attach demodulator */
1090 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1097 /* Attach the demodulator. */
1098 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1100 &em28xx_cxd2820r_tda18271_config)) {
1106 em28xx_errdev("/2: The frontend of your DVB/ATSC card"
1107 " isn't supported yet\n");
1110 if (NULL == dvb->fe[0]) {
1111 em28xx_errdev("/2: frontend initialization failed\n");
1115 /* define general-purpose callback pointer */
1116 dvb->fe[0]->callback = em28xx_tuner_callback;
1118 dvb->fe[1]->callback = em28xx_tuner_callback;
1120 /* register everything */
1121 result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
1127 dvb->adapter.mfe_shared = mfe_shared;
1129 em28xx_info("Successfully loaded em28xx-dvb\n");
1131 em28xx_set_mode(dev, EM28XX_SUSPEND);
1132 mutex_unlock(&dev->lock);
1141 static inline void prevent_sleep(struct dvb_frontend_ops *ops)
1143 ops->set_voltage = NULL;
1145 ops->tuner_ops.sleep = NULL;
1148 static int em28xx_dvb_fini(struct em28xx *dev)
1150 if (!dev->board.has_dvb) {
1151 /* This device does not support the extension */
1156 struct em28xx_dvb *dvb = dev->dvb;
1158 if (dev->state & DEV_DISCONNECTED) {
1159 /* We cannot tell the device to sleep
1160 * once it has been unplugged. */
1162 prevent_sleep(&dvb->fe[0]->ops);
1164 prevent_sleep(&dvb->fe[1]->ops);
1167 em28xx_unregister_dvb(dvb);
1175 static struct em28xx_ops dvb_ops = {
1177 .name = "Em28xx dvb Extension",
1178 .init = em28xx_dvb_init,
1179 .fini = em28xx_dvb_fini,
1182 static int __init em28xx_dvb_register(void)
1184 return em28xx_register_extension(&dvb_ops);
1187 static void __exit em28xx_dvb_unregister(void)
1189 em28xx_unregister_extension(&dvb_ops);
1192 module_init(em28xx_dvb_register);
1193 module_exit(em28xx_dvb_unregister);