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_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
58 MODULE_LICENSE("GPL");
59 MODULE_DESCRIPTION(DRIVER_DESC " - digital TV interface");
60 MODULE_VERSION(EM28XX_VERSION);
63 static unsigned int debug;
64 module_param(debug, int, 0644);
65 MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
67 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
69 #define dprintk(level, fmt, arg...) do { \
71 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \
75 struct dvb_frontend *fe[2];
77 /* feed count management */
81 /* general boilerplate stuff */
82 struct dvb_adapter adapter;
83 struct dvb_demux demux;
85 struct dmx_frontend fe_hw;
86 struct dmx_frontend fe_mem;
89 /* Due to DRX-K - probably need changes */
90 int (*gate_ctrl)(struct dvb_frontend *, int);
91 struct semaphore pll_mutex;
94 struct i2c_client *i2c_client_tuner;
98 static inline void print_err_status(struct em28xx *dev,
99 int packet, int status)
101 char *errmsg = "Unknown";
105 errmsg = "unlinked synchronuously";
108 errmsg = "unlinked asynchronuously";
111 errmsg = "Buffer error (overrun)";
114 errmsg = "Stalled (device not responding)";
117 errmsg = "Babble (bad cable?)";
120 errmsg = "Bit-stuff error (bad cable?)";
123 errmsg = "CRC/Timeout (could be anything)";
126 errmsg = "Device does not respond";
130 dprintk(1, "URB status %d [%s].\n", status, errmsg);
132 dprintk(1, "URB packet %d, status %d [%s].\n",
133 packet, status, errmsg);
137 static inline int em28xx_dvb_urb_data_copy(struct em28xx *dev, struct urb *urb)
139 int xfer_bulk, num_packets, i;
144 if (dev->disconnected)
148 print_err_status(dev, -1, urb->status);
150 xfer_bulk = usb_pipebulk(urb->pipe);
152 if (xfer_bulk) /* bulk */
155 num_packets = urb->number_of_packets;
157 for (i = 0; i < num_packets; i++) {
159 if (urb->status < 0) {
160 print_err_status(dev, i, urb->status);
161 if (urb->status != -EPROTO)
164 dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer,
167 if (urb->iso_frame_desc[i].status < 0) {
168 print_err_status(dev, i,
169 urb->iso_frame_desc[i].status);
170 if (urb->iso_frame_desc[i].status != -EPROTO)
173 dvb_dmx_swfilter(&dev->dvb->demux,
174 urb->transfer_buffer +
175 urb->iso_frame_desc[i].offset,
176 urb->iso_frame_desc[i].actual_length);
183 static int em28xx_start_streaming(struct em28xx_dvb *dvb)
186 struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
187 struct em28xx *dev = i2c_bus->dev;
188 int dvb_max_packet_size, packet_multiplier, dvb_alt;
190 if (dev->dvb_xfer_bulk) {
191 if (!dev->dvb_ep_bulk)
193 dvb_max_packet_size = 512; /* USB 2.0 spec */
194 packet_multiplier = EM28XX_DVB_BULK_PACKET_MULTIPLIER;
197 if (!dev->dvb_ep_isoc)
199 dvb_max_packet_size = dev->dvb_max_pkt_size_isoc;
200 if (dvb_max_packet_size < 0)
201 return dvb_max_packet_size;
202 packet_multiplier = EM28XX_DVB_NUM_ISOC_PACKETS;
203 dvb_alt = dev->dvb_alt_isoc;
206 usb_set_interface(dev->udev, 0, dvb_alt);
207 rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
211 dprintk(1, "Using %d buffers each with %d x %d bytes\n",
214 dvb_max_packet_size);
216 return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE,
221 em28xx_dvb_urb_data_copy);
224 static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
226 struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
227 struct em28xx *dev = i2c_bus->dev;
229 em28xx_stop_urbs(dev);
234 static int em28xx_start_feed(struct dvb_demux_feed *feed)
236 struct dvb_demux *demux = feed->demux;
237 struct em28xx_dvb *dvb = demux->priv;
240 if (!demux->dmx.frontend)
243 mutex_lock(&dvb->lock);
247 if (dvb->nfeeds == 1) {
248 ret = em28xx_start_streaming(dvb);
253 mutex_unlock(&dvb->lock);
257 static int em28xx_stop_feed(struct dvb_demux_feed *feed)
259 struct dvb_demux *demux = feed->demux;
260 struct em28xx_dvb *dvb = demux->priv;
263 mutex_lock(&dvb->lock);
266 if (0 == dvb->nfeeds)
267 err = em28xx_stop_streaming(dvb);
269 mutex_unlock(&dvb->lock);
275 /* ------------------------------------------------------------------ */
276 static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
278 struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
279 struct em28xx *dev = i2c_bus->dev;
282 return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
284 return em28xx_set_mode(dev, EM28XX_SUSPEND);
287 /* ------------------------------------------------------------------ */
289 static struct lgdt330x_config em2880_lgdt3303_dev = {
290 .demod_address = 0x0e,
291 .demod_chip = LGDT3303,
294 static struct lgdt3305_config em2870_lgdt3304_dev = {
296 .demod_chip = LGDT3304,
297 .spectral_inversion = 1,
299 .mpeg_mode = LGDT3305_MPEG_PARALLEL,
300 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
301 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
306 static struct lgdt3305_config em2874_lgdt3305_dev = {
308 .demod_chip = LGDT3305,
309 .spectral_inversion = 1,
311 .mpeg_mode = LGDT3305_MPEG_SERIAL,
312 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
313 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
318 static struct s921_config sharp_isdbt = {
319 .demod_address = 0x30 >> 1
322 static struct zl10353_config em28xx_zl10353_with_xc3028 = {
323 .demod_address = (0x1e >> 1),
329 static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
330 .demod_address = 0x32 >> 1,
331 .output_mode = S5H1409_PARALLEL_OUTPUT,
332 .gpio = S5H1409_GPIO_OFF,
333 .inversion = S5H1409_INVERSION_OFF,
334 .status_mode = S5H1409_DEMODLOCKING,
335 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
338 static struct tda18271_std_map kworld_a340_std_map = {
339 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
340 .if_lvl = 1, .rfagc_top = 0x37, },
341 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
342 .if_lvl = 1, .rfagc_top = 0x37, },
345 static struct tda18271_config kworld_a340_config = {
346 .std_map = &kworld_a340_std_map,
349 static struct tda18271_config kworld_ub435q_v2_config = {
350 .std_map = &kworld_a340_std_map,
351 .gate = TDA18271_GATE_DIGITAL,
354 static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
355 .demod_address = (0x1e >> 1),
357 .disable_i2c_gate_ctrl = 1,
362 static struct drxd_config em28xx_drxd = {
363 .demod_address = 0x70,
364 .demod_revision = 0xa2,
365 .pll_type = DRXD_PLL_NONE,
369 .disable_i2c_gate_ctrl = 1,
372 static struct drxk_config terratec_h5_drxk = {
376 .microcode_name = "dvb-usb-terratec-h5-drxk.fw",
377 .qam_demod_parameter_count = 2,
378 .load_firmware_sync = true,
381 static struct drxk_config hauppauge_930c_drxk = {
385 .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
387 .qam_demod_parameter_count = 2,
388 .load_firmware_sync = true,
391 static struct drxk_config terratec_htc_stick_drxk = {
395 .microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw",
397 .qam_demod_parameter_count = 2,
398 /* Required for the antenna_gpio to disable LNA. */
399 .antenna_dvbt = true,
400 /* The windows driver uses the same. This will disable LNA. */
402 .load_firmware_sync = true,
405 static struct drxk_config maxmedia_ub425_tc_drxk = {
409 .microcode_name = "dvb-demod-drxk-01.fw",
411 .load_firmware_sync = true,
412 .qam_demod_parameter_count = 2,
415 static struct drxk_config pctv_520e_drxk = {
418 .microcode_name = "dvb-demod-drxk-pctv.fw",
419 .qam_demod_parameter_count = 2,
421 .antenna_dvbt = true, /* disable LNA */
422 .antenna_gpio = (1 << 2), /* disable LNA */
423 .load_firmware_sync = true,
426 static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
428 struct em28xx_dvb *dvb = fe->sec_priv;
435 down(&dvb->pll_mutex);
436 status = dvb->gate_ctrl(fe, 1);
438 status = dvb->gate_ctrl(fe, 0);
444 static void hauppauge_hvr930c_init(struct em28xx *dev)
448 struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
449 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0x65},
450 {EM2874_R80_GPIO_P0_CTRL, 0xfb, 0xff, 0x32},
451 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0xb8},
454 struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
455 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
456 {EM2874_R80_GPIO_P0_CTRL, 0xaf, 0xff, 0x65},
457 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x76},
458 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
459 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
460 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x40},
462 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x65},
463 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
464 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
465 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
474 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
476 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
478 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
479 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
481 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
484 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
486 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
489 em28xx_gpio_set(dev, hauppauge_hvr930c_init);
490 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
492 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
495 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
497 for (i = 0; i < ARRAY_SIZE(regs); i++)
498 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
499 em28xx_gpio_set(dev, hauppauge_hvr930c_end);
503 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
506 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
511 static void terratec_h5_init(struct em28xx *dev)
514 struct em28xx_reg_seq terratec_h5_init[] = {
515 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
516 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
517 {EM2874_R80_GPIO_P0_CTRL, 0xf2, 0xff, 50},
518 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
521 struct em28xx_reg_seq terratec_h5_end[] = {
522 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
523 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
524 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
531 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
533 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
535 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
536 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
538 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
541 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
543 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
546 em28xx_gpio_set(dev, terratec_h5_init);
547 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
549 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
552 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
554 for (i = 0; i < ARRAY_SIZE(regs); i++)
555 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
556 em28xx_gpio_set(dev, terratec_h5_end);
559 static void terratec_htc_stick_init(struct em28xx *dev)
564 * GPIO configuration:
565 * 0xff: unknown (does not affect DVB-T).
566 * 0xf6: DRX-K (demodulator).
567 * 0xe6: unknown (does not affect DVB-T).
568 * 0xb6: unknown (does not affect DVB-T).
570 struct em28xx_reg_seq terratec_htc_stick_init[] = {
571 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
572 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
573 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 50},
574 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
577 struct em28xx_reg_seq terratec_htc_stick_end[] = {
578 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
579 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 50},
584 * Init the analog decoder (not yet supported), but
585 * it's probably still a good idea.
591 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
593 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
595 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
598 em28xx_gpio_set(dev, terratec_htc_stick_init);
600 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
602 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
605 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
607 for (i = 0; i < ARRAY_SIZE(regs); i++)
608 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
610 em28xx_gpio_set(dev, terratec_htc_stick_end);
613 static void terratec_htc_usb_xs_init(struct em28xx *dev)
617 struct em28xx_reg_seq terratec_htc_usb_xs_init[] = {
618 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
619 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 100},
620 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 50},
621 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
624 struct em28xx_reg_seq terratec_htc_usb_xs_end[] = {
625 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 100},
626 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
627 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
632 * Init the analog decoder (not yet supported), but
633 * it's probably still a good idea.
639 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
641 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
643 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
644 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
646 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
649 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
651 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
654 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
656 em28xx_gpio_set(dev, terratec_htc_usb_xs_init);
658 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
660 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
663 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
665 for (i = 0; i < ARRAY_SIZE(regs); i++)
666 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
668 em28xx_gpio_set(dev, terratec_htc_usb_xs_end);
671 static void pctv_520e_init(struct em28xx *dev)
674 * Init AVF4910B analog decoder. Looks like I2C traffic to
675 * digital demodulator and tuner are routed via AVF4910B.
682 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
684 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
686 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
687 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
689 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
692 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; /* 0x41 */
694 for (i = 0; i < ARRAY_SIZE(regs); i++)
695 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
698 static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
700 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
701 struct em28xx *dev = fe->dvb->priv;
702 #ifdef CONFIG_GPIOLIB
703 struct em28xx_dvb *dvb = dev->dvb;
708 flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
710 flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
712 ret = gpio_request_one(dvb->lna_gpio, flags, NULL);
714 em28xx_errdev("gpio request failed %d\n", ret);
716 gpio_free(dvb->lna_gpio);
720 dev_warn(&dev->udev->dev, "%s: LNA control is disabled (lna=%u)\n",
721 KBUILD_MODNAME, c->lna);
726 static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
728 /* Values extracted from a USB trace of the Terratec Windows driver */
729 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
730 static u8 reset[] = { RESET, 0x80 };
731 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
732 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
733 static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
734 static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
735 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
736 static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
737 static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
738 static u8 tuner_go[] = { TUNER_GO, 0x01};
740 mt352_write(fe, clock_config, sizeof(clock_config));
742 mt352_write(fe, reset, sizeof(reset));
743 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
744 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
745 mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
746 mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
747 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
748 mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
749 mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
750 mt352_write(fe, tuner_go, sizeof(tuner_go));
754 static struct mt352_config terratec_xs_mt352_cfg = {
755 .demod_address = (0x1e >> 1),
758 .demod_init = em28xx_mt352_terratec_xs_init,
761 static struct tda10023_config em28xx_tda10023_config = {
762 .demod_address = 0x0c,
766 static struct cxd2820r_config em28xx_cxd2820r_config = {
767 .i2c_address = (0xd8 >> 1),
768 .ts_mode = CXD2820R_TS_SERIAL,
771 static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
772 .output_opt = TDA18271_OUTPUT_LT_OFF,
773 .gate = TDA18271_GATE_DIGITAL,
776 static const struct tda10071_config em28xx_tda10071_config = {
777 .demod_i2c_addr = 0x55, /* (0xaa >> 1) */
778 .tuner_i2c_addr = 0x14,
780 .ts_mode = TDA10071_TS_SERIAL,
782 .xtal = 40444000, /* 40.444 MHz */
783 .pll_multiplier = 20,
786 static const struct a8293_config em28xx_a8293_config = {
787 .i2c_addr = 0x08, /* (0x10 >> 1) */
790 static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
791 .demod_address = (0x1e >> 1),
792 .disable_i2c_gate_ctrl = 1,
796 static struct qt1010_config em28xx_qt1010_config = {
800 static const struct mb86a20s_config c3tech_duo_mb86a20s_config = {
801 .demod_address = 0x10,
805 static struct tda18271_std_map mb86a20s_tda18271_config = {
806 .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4,
807 .if_lvl = 1, .rfagc_top = 0x37, },
810 static struct tda18271_config c3tech_duo_tda18271_config = {
811 .std_map = &mb86a20s_tda18271_config,
812 .gate = TDA18271_GATE_DIGITAL,
813 .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
816 static const struct m88ds3103_config pctv_461e_m88ds3103_config = {
821 .ts_mode = M88DS3103_TS_PARALLEL_16,
825 /* ------------------------------------------------------------------ */
827 static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
829 struct dvb_frontend *fe;
830 struct xc2028_config cfg;
831 struct xc2028_ctrl ctl;
833 memset(&cfg, 0, sizeof(cfg));
834 cfg.i2c_adap = &dev->i2c_adap[dev->def_i2c_bus];
837 memset(&ctl, 0, sizeof(ctl));
838 em28xx_setup_xc3028(dev, &ctl);
841 if (!dev->dvb->fe[0]) {
842 em28xx_errdev("/2: dvb frontend not attached. "
843 "Can't attach xc3028\n");
847 fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
849 em28xx_errdev("/2: xc3028 attach failed\n");
850 dvb_frontend_detach(dev->dvb->fe[0]);
851 dev->dvb->fe[0] = NULL;
855 em28xx_info("%s/2: xc3028 attached\n", dev->name);
860 /* ------------------------------------------------------------------ */
862 static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
863 struct em28xx *dev, struct device *device)
867 mutex_init(&dvb->lock);
869 /* register adapter */
870 result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
873 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
878 /* Ensure all frontends negotiate bus access */
879 dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
881 dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
883 dvb->adapter.priv = &dev->i2c_bus[dev->def_i2c_bus];
885 /* register frontend */
886 result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
888 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
893 /* register 2nd frontend */
895 result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
897 printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
903 /* register demux stuff */
904 dvb->demux.dmx.capabilities =
905 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
906 DMX_MEMORY_BASED_FILTERING;
907 dvb->demux.priv = dvb;
908 dvb->demux.filternum = 256;
909 dvb->demux.feednum = 256;
910 dvb->demux.start_feed = em28xx_start_feed;
911 dvb->demux.stop_feed = em28xx_stop_feed;
913 result = dvb_dmx_init(&dvb->demux);
915 printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
920 dvb->dmxdev.filternum = 256;
921 dvb->dmxdev.demux = &dvb->demux.dmx;
922 dvb->dmxdev.capabilities = 0;
923 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
925 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
930 dvb->fe_hw.source = DMX_FRONTEND_0;
931 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
933 printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
938 dvb->fe_mem.source = DMX_MEMORY_FE;
939 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
941 printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
946 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
948 printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
953 /* register network adapter */
954 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
958 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
960 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
962 dvb_dmxdev_release(&dvb->dmxdev);
964 dvb_dmx_release(&dvb->demux);
967 dvb_unregister_frontend(dvb->fe[1]);
968 dvb_unregister_frontend(dvb->fe[0]);
971 dvb_frontend_detach(dvb->fe[1]);
973 dvb_frontend_detach(dvb->fe[0]);
974 dvb_unregister_adapter(&dvb->adapter);
979 static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
981 dvb_net_release(&dvb->net);
982 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
983 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
984 dvb_dmxdev_release(&dvb->dmxdev);
985 dvb_dmx_release(&dvb->demux);
987 dvb_unregister_frontend(dvb->fe[1]);
988 dvb_unregister_frontend(dvb->fe[0]);
989 if (dvb->fe[1] && !dvb->dont_attach_fe1)
990 dvb_frontend_detach(dvb->fe[1]);
991 dvb_frontend_detach(dvb->fe[0]);
992 dvb_unregister_adapter(&dvb->adapter);
995 static int em28xx_dvb_init(struct em28xx *dev)
997 int result = 0, mfe_shared = 0;
998 struct em28xx_dvb *dvb;
1000 if (dev->is_audio_only) {
1001 /* Shouldn't initialize IR for this interface */
1005 if (!dev->board.has_dvb) {
1006 /* This device does not support the extension */
1010 em28xx_info("Binding DVB extension\n");
1012 dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
1015 em28xx_info("em28xx_dvb: memory allocation failed\n");
1019 dvb->fe[0] = dvb->fe[1] = NULL;
1021 mutex_lock(&dev->lock);
1022 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
1024 switch (dev->model) {
1025 case EM2874_BOARD_LEADERSHIP_ISDBT:
1026 dvb->fe[0] = dvb_attach(s921_attach,
1027 &sharp_isdbt, &dev->i2c_adap[dev->def_i2c_bus]);
1035 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
1036 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
1037 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
1038 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
1039 dvb->fe[0] = dvb_attach(lgdt330x_attach,
1040 &em2880_lgdt3303_dev,
1041 &dev->i2c_adap[dev->def_i2c_bus]);
1042 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1047 case EM2880_BOARD_KWORLD_DVB_310U:
1048 dvb->fe[0] = dvb_attach(zl10353_attach,
1049 &em28xx_zl10353_with_xc3028,
1050 &dev->i2c_adap[dev->def_i2c_bus]);
1051 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1056 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
1057 case EM2882_BOARD_TERRATEC_HYBRID_XS:
1058 case EM2880_BOARD_EMPIRE_DUAL_TV:
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 (em28xx_attach_xc3028(0x61, dev) < 0) {
1067 case EM2880_BOARD_TERRATEC_HYBRID_XS:
1068 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
1069 case EM2881_BOARD_PINNACLE_HYBRID_PRO:
1070 case EM2882_BOARD_DIKOM_DK300:
1071 case EM2882_BOARD_KWORLD_VS_DVBT:
1072 dvb->fe[0] = dvb_attach(zl10353_attach,
1073 &em28xx_zl10353_xc3028_no_i2c_gate,
1074 &dev->i2c_adap[dev->def_i2c_bus]);
1075 if (dvb->fe[0] == NULL) {
1076 /* This board could have either a zl10353 or a mt352.
1077 If the chip id isn't for zl10353, try mt352 */
1078 dvb->fe[0] = dvb_attach(mt352_attach,
1079 &terratec_xs_mt352_cfg,
1080 &dev->i2c_adap[dev->def_i2c_bus]);
1083 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1088 case EM2870_BOARD_KWORLD_355U:
1089 dvb->fe[0] = dvb_attach(zl10353_attach,
1090 &em28xx_zl10353_no_i2c_gate_dev,
1091 &dev->i2c_adap[dev->def_i2c_bus]);
1092 if (dvb->fe[0] != NULL)
1093 dvb_attach(qt1010_attach, dvb->fe[0],
1094 &dev->i2c_adap[dev->def_i2c_bus], &em28xx_qt1010_config);
1096 case EM2883_BOARD_KWORLD_HYBRID_330U:
1097 case EM2882_BOARD_EVGA_INDTUBE:
1098 dvb->fe[0] = dvb_attach(s5h1409_attach,
1099 &em28xx_s5h1409_with_xc3028,
1100 &dev->i2c_adap[dev->def_i2c_bus]);
1101 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1106 case EM2882_BOARD_KWORLD_ATSC_315U:
1107 dvb->fe[0] = dvb_attach(lgdt330x_attach,
1108 &em2880_lgdt3303_dev,
1109 &dev->i2c_adap[dev->def_i2c_bus]);
1110 if (dvb->fe[0] != NULL) {
1111 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
1112 &dev->i2c_adap[dev->def_i2c_bus], 0x61, TUNER_THOMSON_DTT761X)) {
1118 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
1119 case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
1120 dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
1121 &dev->i2c_adap[dev->def_i2c_bus], &dev->udev->dev);
1122 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1127 case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
1128 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
1129 dvb->fe[0] = dvb_attach(tda10023_attach,
1130 &em28xx_tda10023_config,
1131 &dev->i2c_adap[dev->def_i2c_bus], 0x48);
1133 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
1134 &dev->i2c_adap[dev->def_i2c_bus], 0x60, TUNER_PHILIPS_CU1216L)) {
1140 case EM2870_BOARD_KWORLD_A340:
1141 dvb->fe[0] = dvb_attach(lgdt3305_attach,
1142 &em2870_lgdt3304_dev,
1143 &dev->i2c_adap[dev->def_i2c_bus]);
1144 if (dvb->fe[0] != NULL)
1145 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1146 &dev->i2c_adap[dev->def_i2c_bus], &kworld_a340_config);
1148 case EM28174_BOARD_PCTV_290E:
1149 /* set default GPIO0 for LNA, used if GPIOLIB is undefined */
1150 dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O |
1152 dvb->fe[0] = dvb_attach(cxd2820r_attach,
1153 &em28xx_cxd2820r_config,
1154 &dev->i2c_adap[dev->def_i2c_bus],
1157 /* FE 0 attach tuner */
1158 if (!dvb_attach(tda18271_attach,
1161 &dev->i2c_adap[dev->def_i2c_bus],
1162 &em28xx_cxd2820r_tda18271_config)) {
1164 dvb_frontend_detach(dvb->fe[0]);
1169 #ifdef CONFIG_GPIOLIB
1170 /* enable LNA for DVB-T, DVB-T2 and DVB-C */
1171 result = gpio_request_one(dvb->lna_gpio,
1172 GPIOF_OUT_INIT_LOW, NULL);
1174 em28xx_errdev("gpio request failed %d\n",
1177 gpio_free(dvb->lna_gpio);
1179 result = 0; /* continue even set LNA fails */
1181 dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
1185 case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
1187 struct xc5000_config cfg;
1188 hauppauge_hvr930c_init(dev);
1190 dvb->fe[0] = dvb_attach(drxk_attach,
1191 &hauppauge_930c_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
1196 /* FIXME: do we need a pll semaphore? */
1197 dvb->fe[0]->sec_priv = dvb;
1198 sema_init(&dvb->pll_mutex, 1);
1199 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1200 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
1203 memset(&cfg, 0, sizeof(cfg));
1204 cfg.i2c_address = 0x61;
1207 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1208 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1209 if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
1214 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1215 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1219 case EM2884_BOARD_TERRATEC_H5:
1220 terratec_h5_init(dev);
1222 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
1227 /* FIXME: do we need a pll semaphore? */
1228 dvb->fe[0]->sec_priv = dvb;
1229 sema_init(&dvb->pll_mutex, 1);
1230 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1231 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
1233 /* Attach tda18271 to DVB-C frontend */
1234 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1235 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1236 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus], 0x60)) {
1240 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1241 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1244 case EM2884_BOARD_C3TECH_DIGITAL_DUO:
1245 dvb->fe[0] = dvb_attach(mb86a20s_attach,
1246 &c3tech_duo_mb86a20s_config,
1247 &dev->i2c_adap[dev->def_i2c_bus]);
1248 if (dvb->fe[0] != NULL)
1249 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1250 &dev->i2c_adap[dev->def_i2c_bus],
1251 &c3tech_duo_tda18271_config);
1253 case EM28174_BOARD_PCTV_460E:
1255 dvb->fe[0] = dvb_attach(tda10071_attach,
1256 &em28xx_tda10071_config, &dev->i2c_adap[dev->def_i2c_bus]);
1260 dvb_attach(a8293_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
1261 &em28xx_a8293_config);
1263 case EM2874_BOARD_DELOCK_61959:
1264 case EM2874_BOARD_MAXMEDIA_UB425_TC:
1265 /* attach demodulator */
1266 dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
1267 &dev->i2c_adap[dev->def_i2c_bus]);
1270 /* disable I2C-gate */
1271 dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
1274 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1275 &dev->i2c_adap[dev->def_i2c_bus],
1276 &em28xx_cxd2820r_tda18271_config)) {
1277 dvb_frontend_detach(dvb->fe[0]);
1283 case EM2884_BOARD_PCTV_510E:
1284 case EM2884_BOARD_PCTV_520E:
1285 pctv_520e_init(dev);
1287 /* attach demodulator */
1288 dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
1289 &dev->i2c_adap[dev->def_i2c_bus]);
1293 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1294 &dev->i2c_adap[dev->def_i2c_bus],
1295 &em28xx_cxd2820r_tda18271_config)) {
1296 dvb_frontend_detach(dvb->fe[0]);
1302 case EM2884_BOARD_CINERGY_HTC_STICK:
1303 terratec_htc_stick_init(dev);
1305 /* attach demodulator */
1306 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1307 &dev->i2c_adap[dev->def_i2c_bus]);
1313 /* Attach the demodulator. */
1314 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1315 &dev->i2c_adap[dev->def_i2c_bus],
1316 &em28xx_cxd2820r_tda18271_config)) {
1321 case EM2884_BOARD_TERRATEC_HTC_USB_XS:
1322 terratec_htc_usb_xs_init(dev);
1324 /* attach demodulator */
1325 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1326 &dev->i2c_adap[dev->def_i2c_bus]);
1332 /* Attach the demodulator. */
1333 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1334 &dev->i2c_adap[dev->def_i2c_bus],
1335 &em28xx_cxd2820r_tda18271_config)) {
1340 case EM2874_BOARD_KWORLD_UB435Q_V2:
1341 dvb->fe[0] = dvb_attach(lgdt3305_attach,
1342 &em2874_lgdt3305_dev,
1343 &dev->i2c_adap[dev->def_i2c_bus]);
1349 /* Attach the demodulator. */
1350 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1351 &dev->i2c_adap[dev->def_i2c_bus],
1352 &kworld_ub435q_v2_config)) {
1357 case EM28178_BOARD_PCTV_461E:
1359 /* demod I2C adapter */
1360 struct i2c_adapter *i2c_adapter;
1361 struct i2c_board_info info;
1362 struct m88ts2022_config m88ts2022_config = {
1365 memset(&info, 0, sizeof(struct i2c_board_info));
1368 dvb->fe[0] = dvb_attach(m88ds3103_attach,
1369 &pctv_461e_m88ds3103_config,
1370 &dev->i2c_adap[dev->def_i2c_bus],
1372 if (dvb->fe[0] == NULL) {
1378 m88ts2022_config.fe = dvb->fe[0];
1379 strlcpy(info.type, "m88ts2022", I2C_NAME_SIZE);
1381 info.platform_data = &m88ts2022_config;
1382 request_module("m88ts2022");
1383 dvb->i2c_client_tuner = i2c_new_device(i2c_adapter, &info);
1385 /* delegate signal strength measurement to tuner */
1386 dvb->fe[0]->ops.read_signal_strength =
1387 dvb->fe[0]->ops.tuner_ops.get_rf_strength;
1390 if (!dvb_attach(a8293_attach, dvb->fe[0],
1391 &dev->i2c_adap[dev->def_i2c_bus],
1392 &em28xx_a8293_config)) {
1393 dvb_frontend_detach(dvb->fe[0]);
1400 em28xx_errdev("/2: The frontend of your DVB/ATSC card"
1401 " isn't supported yet\n");
1404 if (NULL == dvb->fe[0]) {
1405 em28xx_errdev("/2: frontend initialization failed\n");
1409 /* define general-purpose callback pointer */
1410 dvb->fe[0]->callback = em28xx_tuner_callback;
1412 dvb->fe[1]->callback = em28xx_tuner_callback;
1414 /* register everything */
1415 result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
1421 dvb->adapter.mfe_shared = mfe_shared;
1423 em28xx_info("DVB extension successfully initialized\n");
1425 em28xx_set_mode(dev, EM28XX_SUSPEND);
1426 mutex_unlock(&dev->lock);
1435 static inline void prevent_sleep(struct dvb_frontend_ops *ops)
1437 ops->set_voltage = NULL;
1439 ops->tuner_ops.sleep = NULL;
1442 static int em28xx_dvb_fini(struct em28xx *dev)
1444 if (dev->is_audio_only) {
1445 /* Shouldn't initialize IR for this interface */
1449 if (!dev->board.has_dvb) {
1450 /* This device does not support the extension */
1455 struct em28xx_dvb *dvb = dev->dvb;
1457 if (dev->disconnected) {
1458 /* We cannot tell the device to sleep
1459 * once it has been unplugged. */
1461 prevent_sleep(&dvb->fe[0]->ops);
1463 prevent_sleep(&dvb->fe[1]->ops);
1466 i2c_release_client(dvb->i2c_client_tuner);
1467 em28xx_unregister_dvb(dvb);
1475 static struct em28xx_ops dvb_ops = {
1477 .name = "Em28xx dvb Extension",
1478 .init = em28xx_dvb_init,
1479 .fini = em28xx_dvb_fini,
1482 static int __init em28xx_dvb_register(void)
1484 return em28xx_register_extension(&dvb_ops);
1487 static void __exit em28xx_dvb_unregister(void)
1489 em28xx_unregister_extension(&dvb_ops);
1492 module_init(em28xx_dvb_register);
1493 module_exit(em28xx_dvb_unregister);