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 (c) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
15 Based on cx88-dvb, saa7134-dvb and videobuf-dvb originally written by:
16 (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
17 (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
19 This program is free software; you can redistribute it and/or modify
20 it under the terms of the GNU General Public License as published by
21 the Free Software Foundation; either version 2 of the License.
24 #include <linux/kernel.h>
25 #include <linux/slab.h>
26 #include <linux/usb.h>
29 #include <media/v4l2-common.h>
30 #include <dvb_demux.h>
33 #include <media/tuner.h>
34 #include "tuner-simple.h"
35 #include <linux/gpio.h>
42 #include "mt352_priv.h" /* FIXME */
48 #include "tda18271c2dd.h"
54 #include "m88ds3103.h"
55 #include "m88ts2022.h"
57 MODULE_DESCRIPTION("driver for em28xx based DVB cards");
58 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
59 MODULE_LICENSE("GPL");
61 static unsigned int debug;
62 module_param(debug, int, 0644);
63 MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
65 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
67 #define dprintk(level, fmt, arg...) do { \
69 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \
73 struct dvb_frontend *fe[2];
75 /* feed count management */
79 /* general boilerplate stuff */
80 struct dvb_adapter adapter;
81 struct dvb_demux demux;
83 struct dmx_frontend fe_hw;
84 struct dmx_frontend fe_mem;
87 /* Due to DRX-K - probably need changes */
88 int (*gate_ctrl)(struct dvb_frontend *, int);
89 struct semaphore pll_mutex;
92 struct i2c_client *i2c_client_tuner;
96 static inline void print_err_status(struct em28xx *dev,
97 int packet, int status)
99 char *errmsg = "Unknown";
103 errmsg = "unlinked synchronuously";
106 errmsg = "unlinked asynchronuously";
109 errmsg = "Buffer error (overrun)";
112 errmsg = "Stalled (device not responding)";
115 errmsg = "Babble (bad cable?)";
118 errmsg = "Bit-stuff error (bad cable?)";
121 errmsg = "CRC/Timeout (could be anything)";
124 errmsg = "Device does not respond";
128 dprintk(1, "URB status %d [%s].\n", status, errmsg);
130 dprintk(1, "URB packet %d, status %d [%s].\n",
131 packet, status, errmsg);
135 static inline int em28xx_dvb_urb_data_copy(struct em28xx *dev, struct urb *urb)
137 int xfer_bulk, num_packets, i;
142 if (dev->disconnected)
146 print_err_status(dev, -1, urb->status);
148 xfer_bulk = usb_pipebulk(urb->pipe);
150 if (xfer_bulk) /* bulk */
153 num_packets = urb->number_of_packets;
155 for (i = 0; i < num_packets; i++) {
157 if (urb->status < 0) {
158 print_err_status(dev, i, urb->status);
159 if (urb->status != -EPROTO)
162 dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer,
165 if (urb->iso_frame_desc[i].status < 0) {
166 print_err_status(dev, i,
167 urb->iso_frame_desc[i].status);
168 if (urb->iso_frame_desc[i].status != -EPROTO)
171 dvb_dmx_swfilter(&dev->dvb->demux,
172 urb->transfer_buffer +
173 urb->iso_frame_desc[i].offset,
174 urb->iso_frame_desc[i].actual_length);
181 static int em28xx_start_streaming(struct em28xx_dvb *dvb)
184 struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
185 struct em28xx *dev = i2c_bus->dev;
186 int dvb_max_packet_size, packet_multiplier, dvb_alt;
188 if (dev->dvb_xfer_bulk) {
189 if (!dev->dvb_ep_bulk)
191 dvb_max_packet_size = 512; /* USB 2.0 spec */
192 packet_multiplier = EM28XX_DVB_BULK_PACKET_MULTIPLIER;
195 if (!dev->dvb_ep_isoc)
197 dvb_max_packet_size = dev->dvb_max_pkt_size_isoc;
198 if (dvb_max_packet_size < 0)
199 return dvb_max_packet_size;
200 packet_multiplier = EM28XX_DVB_NUM_ISOC_PACKETS;
201 dvb_alt = dev->dvb_alt_isoc;
204 usb_set_interface(dev->udev, 0, dvb_alt);
205 rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
209 dprintk(1, "Using %d buffers each with %d x %d bytes\n",
212 dvb_max_packet_size);
214 return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE,
219 em28xx_dvb_urb_data_copy);
222 static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
224 struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
225 struct em28xx *dev = i2c_bus->dev;
227 em28xx_stop_urbs(dev);
232 static int em28xx_start_feed(struct dvb_demux_feed *feed)
234 struct dvb_demux *demux = feed->demux;
235 struct em28xx_dvb *dvb = demux->priv;
238 if (!demux->dmx.frontend)
241 mutex_lock(&dvb->lock);
245 if (dvb->nfeeds == 1) {
246 ret = em28xx_start_streaming(dvb);
251 mutex_unlock(&dvb->lock);
255 static int em28xx_stop_feed(struct dvb_demux_feed *feed)
257 struct dvb_demux *demux = feed->demux;
258 struct em28xx_dvb *dvb = demux->priv;
261 mutex_lock(&dvb->lock);
264 if (0 == dvb->nfeeds)
265 err = em28xx_stop_streaming(dvb);
267 mutex_unlock(&dvb->lock);
273 /* ------------------------------------------------------------------ */
274 static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
276 struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
277 struct em28xx *dev = i2c_bus->dev;
280 return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
282 return em28xx_set_mode(dev, EM28XX_SUSPEND);
285 /* ------------------------------------------------------------------ */
287 static struct lgdt330x_config em2880_lgdt3303_dev = {
288 .demod_address = 0x0e,
289 .demod_chip = LGDT3303,
292 static struct lgdt3305_config em2870_lgdt3304_dev = {
294 .demod_chip = LGDT3304,
295 .spectral_inversion = 1,
297 .mpeg_mode = LGDT3305_MPEG_PARALLEL,
298 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
299 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
304 static struct lgdt3305_config em2874_lgdt3305_dev = {
306 .demod_chip = LGDT3305,
307 .spectral_inversion = 1,
309 .mpeg_mode = LGDT3305_MPEG_SERIAL,
310 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
311 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
316 static struct s921_config sharp_isdbt = {
317 .demod_address = 0x30 >> 1
320 static struct zl10353_config em28xx_zl10353_with_xc3028 = {
321 .demod_address = (0x1e >> 1),
327 static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
328 .demod_address = 0x32 >> 1,
329 .output_mode = S5H1409_PARALLEL_OUTPUT,
330 .gpio = S5H1409_GPIO_OFF,
331 .inversion = S5H1409_INVERSION_OFF,
332 .status_mode = S5H1409_DEMODLOCKING,
333 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
336 static struct tda18271_std_map kworld_a340_std_map = {
337 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
338 .if_lvl = 1, .rfagc_top = 0x37, },
339 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
340 .if_lvl = 1, .rfagc_top = 0x37, },
343 static struct tda18271_config kworld_a340_config = {
344 .std_map = &kworld_a340_std_map,
347 static struct tda18271_config kworld_ub435q_v2_config = {
348 .std_map = &kworld_a340_std_map,
349 .gate = TDA18271_GATE_DIGITAL,
352 static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
353 .demod_address = (0x1e >> 1),
355 .disable_i2c_gate_ctrl = 1,
360 static struct drxd_config em28xx_drxd = {
361 .demod_address = 0x70,
362 .demod_revision = 0xa2,
363 .pll_type = DRXD_PLL_NONE,
367 .disable_i2c_gate_ctrl = 1,
370 static struct drxk_config terratec_h5_drxk = {
374 .microcode_name = "dvb-usb-terratec-h5-drxk.fw",
375 .qam_demod_parameter_count = 2,
376 .load_firmware_sync = true,
379 static struct drxk_config hauppauge_930c_drxk = {
383 .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
385 .qam_demod_parameter_count = 2,
386 .load_firmware_sync = true,
389 static struct drxk_config terratec_htc_stick_drxk = {
393 .microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw",
395 .qam_demod_parameter_count = 2,
396 /* Required for the antenna_gpio to disable LNA. */
397 .antenna_dvbt = true,
398 /* The windows driver uses the same. This will disable LNA. */
400 .load_firmware_sync = true,
403 static struct drxk_config maxmedia_ub425_tc_drxk = {
407 .microcode_name = "dvb-demod-drxk-01.fw",
409 .load_firmware_sync = true,
410 .qam_demod_parameter_count = 2,
413 static struct drxk_config pctv_520e_drxk = {
416 .microcode_name = "dvb-demod-drxk-pctv.fw",
417 .qam_demod_parameter_count = 2,
419 .antenna_dvbt = true, /* disable LNA */
420 .antenna_gpio = (1 << 2), /* disable LNA */
421 .load_firmware_sync = true,
424 static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
426 struct em28xx_dvb *dvb = fe->sec_priv;
433 down(&dvb->pll_mutex);
434 status = dvb->gate_ctrl(fe, 1);
436 status = dvb->gate_ctrl(fe, 0);
442 static void hauppauge_hvr930c_init(struct em28xx *dev)
446 struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
447 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0x65},
448 {EM2874_R80_GPIO_P0_CTRL, 0xfb, 0xff, 0x32},
449 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0xb8},
452 struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
453 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
454 {EM2874_R80_GPIO_P0_CTRL, 0xaf, 0xff, 0x65},
455 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x76},
456 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
457 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
458 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x40},
460 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x65},
461 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
462 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
463 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
472 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
474 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
476 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
477 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
479 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
482 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
484 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
487 em28xx_gpio_set(dev, hauppauge_hvr930c_init);
488 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
490 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
493 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
495 for (i = 0; i < ARRAY_SIZE(regs); i++)
496 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
497 em28xx_gpio_set(dev, hauppauge_hvr930c_end);
501 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
504 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
509 static void terratec_h5_init(struct em28xx *dev)
512 struct em28xx_reg_seq terratec_h5_init[] = {
513 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
514 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
515 {EM2874_R80_GPIO_P0_CTRL, 0xf2, 0xff, 50},
516 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
519 struct em28xx_reg_seq terratec_h5_end[] = {
520 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
521 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
522 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
529 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
531 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
533 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
534 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
536 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
539 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
541 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
544 em28xx_gpio_set(dev, terratec_h5_init);
545 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
547 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
550 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
552 for (i = 0; i < ARRAY_SIZE(regs); i++)
553 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
554 em28xx_gpio_set(dev, terratec_h5_end);
557 static void terratec_htc_stick_init(struct em28xx *dev)
562 * GPIO configuration:
563 * 0xff: unknown (does not affect DVB-T).
564 * 0xf6: DRX-K (demodulator).
565 * 0xe6: unknown (does not affect DVB-T).
566 * 0xb6: unknown (does not affect DVB-T).
568 struct em28xx_reg_seq terratec_htc_stick_init[] = {
569 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
570 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
571 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 50},
572 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
575 struct em28xx_reg_seq terratec_htc_stick_end[] = {
576 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
577 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 50},
582 * Init the analog decoder (not yet supported), but
583 * it's probably still a good idea.
589 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
591 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
593 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
596 em28xx_gpio_set(dev, terratec_htc_stick_init);
598 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
600 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
603 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
605 for (i = 0; i < ARRAY_SIZE(regs); i++)
606 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
608 em28xx_gpio_set(dev, terratec_htc_stick_end);
611 static void terratec_htc_usb_xs_init(struct em28xx *dev)
615 struct em28xx_reg_seq terratec_htc_usb_xs_init[] = {
616 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
617 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 100},
618 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 50},
619 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
622 struct em28xx_reg_seq terratec_htc_usb_xs_end[] = {
623 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 100},
624 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
625 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
630 * Init the analog decoder (not yet supported), but
631 * it's probably still a good idea.
637 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
639 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
641 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
642 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
644 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
647 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
649 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
652 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
654 em28xx_gpio_set(dev, terratec_htc_usb_xs_init);
656 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
658 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
661 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
663 for (i = 0; i < ARRAY_SIZE(regs); i++)
664 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
666 em28xx_gpio_set(dev, terratec_htc_usb_xs_end);
669 static void pctv_520e_init(struct em28xx *dev)
672 * Init AVF4910B analog decoder. Looks like I2C traffic to
673 * digital demodulator and tuner are routed via AVF4910B.
680 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
682 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
684 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
685 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
687 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
690 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; /* 0x41 */
692 for (i = 0; i < ARRAY_SIZE(regs); i++)
693 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
696 static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
698 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
699 struct em28xx *dev = fe->dvb->priv;
700 #ifdef CONFIG_GPIOLIB
701 struct em28xx_dvb *dvb = dev->dvb;
706 flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
708 flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
710 ret = gpio_request_one(dvb->lna_gpio, flags, NULL);
712 em28xx_errdev("gpio request failed %d\n", ret);
714 gpio_free(dvb->lna_gpio);
718 dev_warn(&dev->udev->dev, "%s: LNA control is disabled (lna=%u)\n",
719 KBUILD_MODNAME, c->lna);
724 static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
726 /* Values extracted from a USB trace of the Terratec Windows driver */
727 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
728 static u8 reset[] = { RESET, 0x80 };
729 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
730 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
731 static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
732 static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
733 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
734 static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
735 static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
736 static u8 tuner_go[] = { TUNER_GO, 0x01};
738 mt352_write(fe, clock_config, sizeof(clock_config));
740 mt352_write(fe, reset, sizeof(reset));
741 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
742 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
743 mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
744 mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
745 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
746 mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
747 mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
748 mt352_write(fe, tuner_go, sizeof(tuner_go));
752 static struct mt352_config terratec_xs_mt352_cfg = {
753 .demod_address = (0x1e >> 1),
756 .demod_init = em28xx_mt352_terratec_xs_init,
759 static struct tda10023_config em28xx_tda10023_config = {
760 .demod_address = 0x0c,
764 static struct cxd2820r_config em28xx_cxd2820r_config = {
765 .i2c_address = (0xd8 >> 1),
766 .ts_mode = CXD2820R_TS_SERIAL,
769 static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
770 .output_opt = TDA18271_OUTPUT_LT_OFF,
771 .gate = TDA18271_GATE_DIGITAL,
774 static const struct tda10071_config em28xx_tda10071_config = {
775 .demod_i2c_addr = 0x55, /* (0xaa >> 1) */
776 .tuner_i2c_addr = 0x14,
778 .ts_mode = TDA10071_TS_SERIAL,
780 .xtal = 40444000, /* 40.444 MHz */
781 .pll_multiplier = 20,
784 static const struct a8293_config em28xx_a8293_config = {
785 .i2c_addr = 0x08, /* (0x10 >> 1) */
788 static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
789 .demod_address = (0x1e >> 1),
790 .disable_i2c_gate_ctrl = 1,
794 static struct qt1010_config em28xx_qt1010_config = {
798 static const struct mb86a20s_config c3tech_duo_mb86a20s_config = {
799 .demod_address = 0x10,
803 static struct tda18271_std_map mb86a20s_tda18271_config = {
804 .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4,
805 .if_lvl = 1, .rfagc_top = 0x37, },
808 static struct tda18271_config c3tech_duo_tda18271_config = {
809 .std_map = &mb86a20s_tda18271_config,
810 .gate = TDA18271_GATE_DIGITAL,
811 .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
814 static const struct m88ds3103_config pctv_461e_m88ds3103_config = {
819 .ts_mode = M88DS3103_TS_PARALLEL_16,
823 /* ------------------------------------------------------------------ */
825 static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
827 struct dvb_frontend *fe;
828 struct xc2028_config cfg;
830 memset(&cfg, 0, sizeof(cfg));
831 cfg.i2c_adap = &dev->i2c_adap[dev->def_i2c_bus];
834 if (!dev->dvb->fe[0]) {
835 em28xx_errdev("/2: dvb frontend not attached. "
836 "Can't attach xc3028\n");
840 fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
842 em28xx_errdev("/2: xc3028 attach failed\n");
843 dvb_frontend_detach(dev->dvb->fe[0]);
844 dev->dvb->fe[0] = NULL;
848 em28xx_info("%s/2: xc3028 attached\n", dev->name);
853 /* ------------------------------------------------------------------ */
855 static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
856 struct em28xx *dev, struct device *device)
860 mutex_init(&dvb->lock);
862 /* register adapter */
863 result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
866 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
871 /* Ensure all frontends negotiate bus access */
872 dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
874 dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
876 dvb->adapter.priv = &dev->i2c_bus[dev->def_i2c_bus];
878 /* register frontend */
879 result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
881 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
886 /* register 2nd frontend */
888 result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
890 printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
896 /* register demux stuff */
897 dvb->demux.dmx.capabilities =
898 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
899 DMX_MEMORY_BASED_FILTERING;
900 dvb->demux.priv = dvb;
901 dvb->demux.filternum = 256;
902 dvb->demux.feednum = 256;
903 dvb->demux.start_feed = em28xx_start_feed;
904 dvb->demux.stop_feed = em28xx_stop_feed;
906 result = dvb_dmx_init(&dvb->demux);
908 printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
913 dvb->dmxdev.filternum = 256;
914 dvb->dmxdev.demux = &dvb->demux.dmx;
915 dvb->dmxdev.capabilities = 0;
916 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
918 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
923 dvb->fe_hw.source = DMX_FRONTEND_0;
924 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
926 printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
931 dvb->fe_mem.source = DMX_MEMORY_FE;
932 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
934 printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
939 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
941 printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
946 /* register network adapter */
947 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
951 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
953 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
955 dvb_dmxdev_release(&dvb->dmxdev);
957 dvb_dmx_release(&dvb->demux);
960 dvb_unregister_frontend(dvb->fe[1]);
961 dvb_unregister_frontend(dvb->fe[0]);
964 dvb_frontend_detach(dvb->fe[1]);
966 dvb_frontend_detach(dvb->fe[0]);
967 dvb_unregister_adapter(&dvb->adapter);
972 static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
974 dvb_net_release(&dvb->net);
975 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
976 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
977 dvb_dmxdev_release(&dvb->dmxdev);
978 dvb_dmx_release(&dvb->demux);
980 dvb_unregister_frontend(dvb->fe[1]);
981 dvb_unregister_frontend(dvb->fe[0]);
982 if (dvb->fe[1] && !dvb->dont_attach_fe1)
983 dvb_frontend_detach(dvb->fe[1]);
984 dvb_frontend_detach(dvb->fe[0]);
985 dvb_unregister_adapter(&dvb->adapter);
988 static int em28xx_dvb_init(struct em28xx *dev)
990 int result = 0, mfe_shared = 0;
991 struct em28xx_dvb *dvb;
993 if (!dev->board.has_dvb) {
994 /* This device does not support the extension */
995 printk(KERN_INFO "em28xx_dvb: This device does not support the extension\n");
999 dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
1002 em28xx_info("em28xx_dvb: memory allocation failed\n");
1006 dvb->fe[0] = dvb->fe[1] = NULL;
1008 mutex_lock(&dev->lock);
1009 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
1011 switch (dev->model) {
1012 case EM2874_BOARD_LEADERSHIP_ISDBT:
1013 dvb->fe[0] = dvb_attach(s921_attach,
1014 &sharp_isdbt, &dev->i2c_adap[dev->def_i2c_bus]);
1022 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
1023 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
1024 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
1025 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
1026 dvb->fe[0] = dvb_attach(lgdt330x_attach,
1027 &em2880_lgdt3303_dev,
1028 &dev->i2c_adap[dev->def_i2c_bus]);
1029 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1034 case EM2880_BOARD_KWORLD_DVB_310U:
1035 dvb->fe[0] = dvb_attach(zl10353_attach,
1036 &em28xx_zl10353_with_xc3028,
1037 &dev->i2c_adap[dev->def_i2c_bus]);
1038 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1043 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
1044 case EM2882_BOARD_TERRATEC_HYBRID_XS:
1045 case EM2880_BOARD_EMPIRE_DUAL_TV:
1046 dvb->fe[0] = dvb_attach(zl10353_attach,
1047 &em28xx_zl10353_xc3028_no_i2c_gate,
1048 &dev->i2c_adap[dev->def_i2c_bus]);
1049 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1054 case EM2880_BOARD_TERRATEC_HYBRID_XS:
1055 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
1056 case EM2881_BOARD_PINNACLE_HYBRID_PRO:
1057 case EM2882_BOARD_DIKOM_DK300:
1058 case EM2882_BOARD_KWORLD_VS_DVBT:
1059 dvb->fe[0] = dvb_attach(zl10353_attach,
1060 &em28xx_zl10353_xc3028_no_i2c_gate,
1061 &dev->i2c_adap[dev->def_i2c_bus]);
1062 if (dvb->fe[0] == NULL) {
1063 /* This board could have either a zl10353 or a mt352.
1064 If the chip id isn't for zl10353, try mt352 */
1065 dvb->fe[0] = dvb_attach(mt352_attach,
1066 &terratec_xs_mt352_cfg,
1067 &dev->i2c_adap[dev->def_i2c_bus]);
1070 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1075 case EM2870_BOARD_KWORLD_355U:
1076 dvb->fe[0] = dvb_attach(zl10353_attach,
1077 &em28xx_zl10353_no_i2c_gate_dev,
1078 &dev->i2c_adap[dev->def_i2c_bus]);
1079 if (dvb->fe[0] != NULL)
1080 dvb_attach(qt1010_attach, dvb->fe[0],
1081 &dev->i2c_adap[dev->def_i2c_bus], &em28xx_qt1010_config);
1083 case EM2883_BOARD_KWORLD_HYBRID_330U:
1084 case EM2882_BOARD_EVGA_INDTUBE:
1085 dvb->fe[0] = dvb_attach(s5h1409_attach,
1086 &em28xx_s5h1409_with_xc3028,
1087 &dev->i2c_adap[dev->def_i2c_bus]);
1088 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1093 case EM2882_BOARD_KWORLD_ATSC_315U:
1094 dvb->fe[0] = dvb_attach(lgdt330x_attach,
1095 &em2880_lgdt3303_dev,
1096 &dev->i2c_adap[dev->def_i2c_bus]);
1097 if (dvb->fe[0] != NULL) {
1098 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
1099 &dev->i2c_adap[dev->def_i2c_bus], 0x61, TUNER_THOMSON_DTT761X)) {
1105 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
1106 case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
1107 dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
1108 &dev->i2c_adap[dev->def_i2c_bus], &dev->udev->dev);
1109 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1114 case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
1115 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
1116 dvb->fe[0] = dvb_attach(tda10023_attach,
1117 &em28xx_tda10023_config,
1118 &dev->i2c_adap[dev->def_i2c_bus], 0x48);
1120 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
1121 &dev->i2c_adap[dev->def_i2c_bus], 0x60, TUNER_PHILIPS_CU1216L)) {
1127 case EM2870_BOARD_KWORLD_A340:
1128 dvb->fe[0] = dvb_attach(lgdt3305_attach,
1129 &em2870_lgdt3304_dev,
1130 &dev->i2c_adap[dev->def_i2c_bus]);
1131 if (dvb->fe[0] != NULL)
1132 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1133 &dev->i2c_adap[dev->def_i2c_bus], &kworld_a340_config);
1135 case EM28174_BOARD_PCTV_290E:
1136 /* set default GPIO0 for LNA, used if GPIOLIB is undefined */
1137 dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O |
1139 dvb->fe[0] = dvb_attach(cxd2820r_attach,
1140 &em28xx_cxd2820r_config,
1141 &dev->i2c_adap[dev->def_i2c_bus],
1144 /* FE 0 attach tuner */
1145 if (!dvb_attach(tda18271_attach,
1148 &dev->i2c_adap[dev->def_i2c_bus],
1149 &em28xx_cxd2820r_tda18271_config)) {
1151 dvb_frontend_detach(dvb->fe[0]);
1156 #ifdef CONFIG_GPIOLIB
1157 /* enable LNA for DVB-T, DVB-T2 and DVB-C */
1158 result = gpio_request_one(dvb->lna_gpio,
1159 GPIOF_OUT_INIT_LOW, NULL);
1161 em28xx_errdev("gpio request failed %d\n",
1164 gpio_free(dvb->lna_gpio);
1166 result = 0; /* continue even set LNA fails */
1168 dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
1172 case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
1174 struct xc5000_config cfg;
1175 hauppauge_hvr930c_init(dev);
1177 dvb->fe[0] = dvb_attach(drxk_attach,
1178 &hauppauge_930c_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
1183 /* FIXME: do we need a pll semaphore? */
1184 dvb->fe[0]->sec_priv = dvb;
1185 sema_init(&dvb->pll_mutex, 1);
1186 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1187 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
1190 memset(&cfg, 0, sizeof(cfg));
1191 cfg.i2c_address = 0x61;
1194 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1195 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1196 if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
1201 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1202 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1206 case EM2884_BOARD_TERRATEC_H5:
1207 terratec_h5_init(dev);
1209 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
1214 /* FIXME: do we need a pll semaphore? */
1215 dvb->fe[0]->sec_priv = dvb;
1216 sema_init(&dvb->pll_mutex, 1);
1217 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1218 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
1220 /* Attach tda18271 to DVB-C frontend */
1221 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1222 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1223 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus], 0x60)) {
1227 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1228 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1231 case EM2884_BOARD_C3TECH_DIGITAL_DUO:
1232 dvb->fe[0] = dvb_attach(mb86a20s_attach,
1233 &c3tech_duo_mb86a20s_config,
1234 &dev->i2c_adap[dev->def_i2c_bus]);
1235 if (dvb->fe[0] != NULL)
1236 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1237 &dev->i2c_adap[dev->def_i2c_bus],
1238 &c3tech_duo_tda18271_config);
1240 case EM28174_BOARD_PCTV_460E:
1242 dvb->fe[0] = dvb_attach(tda10071_attach,
1243 &em28xx_tda10071_config, &dev->i2c_adap[dev->def_i2c_bus]);
1247 dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
1248 &em28xx_a8293_config);
1250 case EM2874_BOARD_DELOCK_61959:
1251 case EM2874_BOARD_MAXMEDIA_UB425_TC:
1252 /* attach demodulator */
1253 dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
1254 &dev->i2c_adap[dev->def_i2c_bus]);
1257 /* disable I2C-gate */
1258 dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
1261 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1262 &dev->i2c_adap[dev->def_i2c_bus],
1263 &em28xx_cxd2820r_tda18271_config)) {
1264 dvb_frontend_detach(dvb->fe[0]);
1270 case EM2884_BOARD_PCTV_510E:
1271 case EM2884_BOARD_PCTV_520E:
1272 pctv_520e_init(dev);
1274 /* attach demodulator */
1275 dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
1276 &dev->i2c_adap[dev->def_i2c_bus]);
1280 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1281 &dev->i2c_adap[dev->def_i2c_bus],
1282 &em28xx_cxd2820r_tda18271_config)) {
1283 dvb_frontend_detach(dvb->fe[0]);
1289 case EM2884_BOARD_CINERGY_HTC_STICK:
1290 terratec_htc_stick_init(dev);
1292 /* attach demodulator */
1293 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1294 &dev->i2c_adap[dev->def_i2c_bus]);
1300 /* Attach the demodulator. */
1301 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1302 &dev->i2c_adap[dev->def_i2c_bus],
1303 &em28xx_cxd2820r_tda18271_config)) {
1308 case EM2884_BOARD_TERRATEC_HTC_USB_XS:
1309 terratec_htc_usb_xs_init(dev);
1311 /* attach demodulator */
1312 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1313 &dev->i2c_adap[dev->def_i2c_bus]);
1319 /* Attach the demodulator. */
1320 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1321 &dev->i2c_adap[dev->def_i2c_bus],
1322 &em28xx_cxd2820r_tda18271_config)) {
1327 case EM2874_BOARD_KWORLD_UB435Q_V2:
1328 dvb->fe[0] = dvb_attach(lgdt3305_attach,
1329 &em2874_lgdt3305_dev,
1330 &dev->i2c_adap[dev->def_i2c_bus]);
1336 /* Attach the demodulator. */
1337 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1338 &dev->i2c_adap[dev->def_i2c_bus],
1339 &kworld_ub435q_v2_config)) {
1344 case EM28178_BOARD_PCTV_461E:
1346 /* demod I2C adapter */
1347 struct i2c_adapter *i2c_adapter;
1348 struct i2c_board_info info;
1349 struct m88ts2022_config m88ts2022_config = {
1352 memset(&info, 0, sizeof(struct i2c_board_info));
1355 dvb->fe[0] = dvb_attach(m88ds3103_attach,
1356 &pctv_461e_m88ds3103_config,
1357 &dev->i2c_adap[dev->def_i2c_bus],
1359 if (dvb->fe[0] == NULL) {
1365 m88ts2022_config.fe = dvb->fe[0];
1366 strlcpy(info.type, "m88ts2022", I2C_NAME_SIZE);
1368 info.platform_data = &m88ts2022_config;
1369 request_module("m88ts2022");
1370 dvb->i2c_client_tuner = i2c_new_device(i2c_adapter, &info);
1372 /* delegate signal strength measurement to tuner */
1373 dvb->fe[0]->ops.read_signal_strength =
1374 dvb->fe[0]->ops.tuner_ops.get_rf_strength;
1377 if (!dvb_attach(a8293_attach, dvb->fe[0],
1378 &dev->i2c_adap[dev->def_i2c_bus],
1379 &em28xx_a8293_config)) {
1380 dvb_frontend_detach(dvb->fe[0]);
1387 em28xx_errdev("/2: The frontend of your DVB/ATSC card"
1388 " isn't supported yet\n");
1391 if (NULL == dvb->fe[0]) {
1392 em28xx_errdev("/2: frontend initialization failed\n");
1396 /* define general-purpose callback pointer */
1397 dvb->fe[0]->callback = em28xx_tuner_callback;
1399 dvb->fe[1]->callback = em28xx_tuner_callback;
1401 /* register everything */
1402 result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
1408 dvb->adapter.mfe_shared = mfe_shared;
1410 em28xx_info("Successfully loaded em28xx-dvb\n");
1412 em28xx_set_mode(dev, EM28XX_SUSPEND);
1413 mutex_unlock(&dev->lock);
1422 static inline void prevent_sleep(struct dvb_frontend_ops *ops)
1424 ops->set_voltage = NULL;
1426 ops->tuner_ops.sleep = NULL;
1429 static int em28xx_dvb_fini(struct em28xx *dev)
1431 if (!dev->board.has_dvb) {
1432 /* This device does not support the extension */
1437 struct em28xx_dvb *dvb = dev->dvb;
1439 if (dev->disconnected) {
1440 /* We cannot tell the device to sleep
1441 * once it has been unplugged. */
1443 prevent_sleep(&dvb->fe[0]->ops);
1445 prevent_sleep(&dvb->fe[1]->ops);
1448 i2c_release_client(dvb->i2c_client_tuner);
1449 em28xx_unregister_dvb(dvb);
1457 static struct em28xx_ops dvb_ops = {
1459 .name = "Em28xx dvb Extension",
1460 .init = em28xx_dvb_init,
1461 .fini = em28xx_dvb_fini,
1464 static int __init em28xx_dvb_register(void)
1466 return em28xx_register_extension(&dvb_ops);
1469 static void __exit em28xx_dvb_unregister(void)
1471 em28xx_unregister_extension(&dvb_ops);
1474 module_init(em28xx_dvb_register);
1475 module_exit(em28xx_dvb_unregister);