1 // SPDX-License-Identifier: GPL-2.0
3 // DVB device driver for em28xx
5 // (c) 2008-2011 Mauro Carvalho Chehab <mchehab@infradead.org>
7 // (c) 2008 Devin Heitmueller <devin.heitmueller@gmail.com>
8 // - Fixes for the driver to properly work with HVR-950
9 // - Fixes for the driver to properly work with Pinnacle PCTV HD Pro Stick
10 // - Fixes for the driver to properly work with AMD ATI TV Wonder HD 600
12 // (c) 2008 Aidan Thornton <makosoft@googlemail.com>
14 // (c) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
16 // Based on cx88-dvb, saa7134-dvb and videobuf-dvb originally written by:
17 // (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
18 // (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
20 // This program is free software; you can redistribute it and/or modify
21 // it under the terms of the GNU General Public License as published by
22 // the Free Software Foundation version 2 of the License.
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/usb.h>
30 #include <media/v4l2-common.h>
31 #include <media/dvb_demux.h>
32 #include <media/dvb_net.h>
33 #include <media/dmxdev.h>
34 #include <media/tuner.h>
35 #include "tuner-simple.h"
36 #include <linux/gpio.h>
40 #include "lgdt3306a.h"
45 #include "mt352_priv.h" /* FIXME */
47 #include "drx39xyj/drx39xxj.h"
52 #include "tda18271c2dd.h"
59 #include "m88ds3103.h"
64 #include "qm1d1c0042.h"
66 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
67 MODULE_LICENSE("GPL v2");
68 MODULE_DESCRIPTION(DRIVER_DESC " - digital TV interface");
69 MODULE_VERSION(EM28XX_VERSION);
71 static unsigned int debug;
72 module_param(debug, int, 0644);
73 MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
75 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
77 #define dprintk(level, fmt, arg...) do { \
79 dev_printk(KERN_DEBUG, &dev->intf->dev, \
80 "dvb: " fmt, ## arg); \
84 struct dvb_frontend *fe[2];
86 /* feed count management */
90 /* general boilerplate stuff */
91 struct dvb_adapter adapter;
92 struct dvb_demux demux;
94 struct dmx_frontend fe_hw;
95 struct dmx_frontend fe_mem;
98 /* Due to DRX-K - probably need changes */
99 int (*gate_ctrl)(struct dvb_frontend *fe, int gate);
100 struct semaphore pll_mutex;
101 bool dont_attach_fe1;
103 struct i2c_client *i2c_client_demod;
104 struct i2c_client *i2c_client_tuner;
105 struct i2c_client *i2c_client_sec;
108 static inline void print_err_status(struct em28xx *dev,
109 int packet, int status)
111 char *errmsg = "Unknown";
115 errmsg = "unlinked synchronously";
118 errmsg = "unlinked asynchronously";
121 errmsg = "Buffer error (overrun)";
124 errmsg = "Stalled (device not responding)";
127 errmsg = "Babble (bad cable?)";
130 errmsg = "Bit-stuff error (bad cable?)";
133 errmsg = "CRC/Timeout (could be anything)";
136 errmsg = "Device does not respond";
140 dprintk(1, "URB status %d [%s].\n", status, errmsg);
142 dprintk(1, "URB packet %d, status %d [%s].\n",
143 packet, status, errmsg);
147 static inline int em28xx_dvb_urb_data_copy(struct em28xx *dev, struct urb *urb)
149 int xfer_bulk, num_packets, i;
154 if (dev->disconnected)
158 print_err_status(dev, -1, urb->status);
160 xfer_bulk = usb_pipebulk(urb->pipe);
162 if (xfer_bulk) /* bulk */
165 num_packets = urb->number_of_packets;
167 for (i = 0; i < num_packets; i++) {
169 if (urb->status < 0) {
170 print_err_status(dev, i, urb->status);
171 if (urb->status != -EPROTO)
174 if (!urb->actual_length)
176 dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer,
179 if (urb->iso_frame_desc[i].status < 0) {
180 print_err_status(dev, i,
181 urb->iso_frame_desc[i].status);
182 if (urb->iso_frame_desc[i].status != -EPROTO)
185 if (!urb->iso_frame_desc[i].actual_length)
187 dvb_dmx_swfilter(&dev->dvb->demux,
188 urb->transfer_buffer +
189 urb->iso_frame_desc[i].offset,
190 urb->iso_frame_desc[i].actual_length);
197 static int em28xx_start_streaming(struct em28xx_dvb *dvb)
200 struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
201 struct em28xx *dev = i2c_bus->dev;
202 int dvb_max_packet_size, packet_multiplier, dvb_alt;
204 if (dev->dvb_xfer_bulk) {
205 if (!dev->dvb_ep_bulk)
207 dvb_max_packet_size = 512; /* USB 2.0 spec */
208 packet_multiplier = EM28XX_DVB_BULK_PACKET_MULTIPLIER;
211 if (!dev->dvb_ep_isoc)
213 dvb_max_packet_size = dev->dvb_max_pkt_size_isoc;
214 if (dvb_max_packet_size < 0)
215 return dvb_max_packet_size;
216 packet_multiplier = EM28XX_DVB_NUM_ISOC_PACKETS;
217 dvb_alt = dev->dvb_alt_isoc;
220 rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
224 dprintk(1, "Using %d buffers each with %d x %d bytes, alternate %d\n",
227 dvb_max_packet_size, dvb_alt);
229 return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE,
234 em28xx_dvb_urb_data_copy);
237 static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
239 struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
240 struct em28xx *dev = i2c_bus->dev;
242 em28xx_stop_urbs(dev);
247 static int em28xx_start_feed(struct dvb_demux_feed *feed)
249 struct dvb_demux *demux = feed->demux;
250 struct em28xx_dvb *dvb = demux->priv;
253 if (!demux->dmx.frontend)
256 mutex_lock(&dvb->lock);
260 if (dvb->nfeeds == 1) {
261 ret = em28xx_start_streaming(dvb);
266 mutex_unlock(&dvb->lock);
270 static int em28xx_stop_feed(struct dvb_demux_feed *feed)
272 struct dvb_demux *demux = feed->demux;
273 struct em28xx_dvb *dvb = demux->priv;
276 mutex_lock(&dvb->lock);
280 err = em28xx_stop_streaming(dvb);
282 mutex_unlock(&dvb->lock);
286 /* ------------------------------------------------------------------ */
287 static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
289 struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
290 struct em28xx *dev = i2c_bus->dev;
293 return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
295 return em28xx_set_mode(dev, EM28XX_SUSPEND);
298 /* ------------------------------------------------------------------ */
300 static struct lgdt330x_config em2880_lgdt3303_dev = {
301 .demod_address = 0x0e,
302 .demod_chip = LGDT3303,
305 static struct lgdt3305_config em2870_lgdt3304_dev = {
307 .demod_chip = LGDT3304,
308 .spectral_inversion = 1,
310 .mpeg_mode = LGDT3305_MPEG_PARALLEL,
311 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
312 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
317 static struct lgdt3305_config em2874_lgdt3305_dev = {
319 .demod_chip = LGDT3305,
320 .spectral_inversion = 1,
322 .mpeg_mode = LGDT3305_MPEG_SERIAL,
323 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
324 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
329 static struct lgdt3305_config em2874_lgdt3305_nogate_dev = {
331 .demod_chip = LGDT3305,
332 .spectral_inversion = 1,
334 .mpeg_mode = LGDT3305_MPEG_SERIAL,
335 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
336 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
341 static struct s921_config sharp_isdbt = {
342 .demod_address = 0x30 >> 1
345 static struct zl10353_config em28xx_zl10353_with_xc3028 = {
346 .demod_address = (0x1e >> 1),
352 static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
353 .demod_address = 0x32 >> 1,
354 .output_mode = S5H1409_PARALLEL_OUTPUT,
355 .gpio = S5H1409_GPIO_OFF,
356 .inversion = S5H1409_INVERSION_OFF,
357 .status_mode = S5H1409_DEMODLOCKING,
358 .mpeg_timing = S5H1409_MPEGTIMING_CONTINUOUS_NONINVERTING_CLOCK
361 static struct tda18271_std_map kworld_a340_std_map = {
362 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
363 .if_lvl = 1, .rfagc_top = 0x37, },
364 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
365 .if_lvl = 1, .rfagc_top = 0x37, },
368 static struct tda18271_config kworld_a340_config = {
369 .std_map = &kworld_a340_std_map,
372 static struct tda18271_config kworld_ub435q_v2_config = {
373 .std_map = &kworld_a340_std_map,
374 .gate = TDA18271_GATE_DIGITAL,
377 static struct tda18212_config kworld_ub435q_v3_config = {
382 static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
383 .demod_address = (0x1e >> 1),
385 .disable_i2c_gate_ctrl = 1,
390 static struct drxd_config em28xx_drxd = {
391 .demod_address = 0x70,
392 .demod_revision = 0xa2,
393 .pll_type = DRXD_PLL_NONE,
397 .disable_i2c_gate_ctrl = 1,
400 static struct drxk_config terratec_h5_drxk = {
404 .microcode_name = "dvb-usb-terratec-h5-drxk.fw",
405 .qam_demod_parameter_count = 2,
408 static struct drxk_config hauppauge_930c_drxk = {
412 .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
414 .qam_demod_parameter_count = 2,
417 static struct drxk_config terratec_htc_stick_drxk = {
421 .microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw",
423 .qam_demod_parameter_count = 2,
424 /* Required for the antenna_gpio to disable LNA. */
425 .antenna_dvbt = true,
426 /* The windows driver uses the same. This will disable LNA. */
430 static struct drxk_config maxmedia_ub425_tc_drxk = {
434 .microcode_name = "dvb-demod-drxk-01.fw",
436 .qam_demod_parameter_count = 2,
439 static struct drxk_config pctv_520e_drxk = {
442 .microcode_name = "dvb-demod-drxk-pctv.fw",
443 .qam_demod_parameter_count = 2,
445 .antenna_dvbt = true, /* disable LNA */
446 .antenna_gpio = (1 << 2), /* disable LNA */
449 static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
451 struct em28xx_dvb *dvb = fe->sec_priv;
458 down(&dvb->pll_mutex);
459 status = dvb->gate_ctrl(fe, 1);
461 status = dvb->gate_ctrl(fe, 0);
467 static void hauppauge_hvr930c_init(struct em28xx *dev)
471 struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
472 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0x65},
473 {EM2874_R80_GPIO_P0_CTRL, 0xfb, 0xff, 0x32},
474 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0xb8},
477 struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
478 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
479 {EM2874_R80_GPIO_P0_CTRL, 0xaf, 0xff, 0x65},
480 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x76},
481 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
482 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
483 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x40},
485 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x65},
486 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
487 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
488 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
497 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
499 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
501 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
502 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
504 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
507 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
509 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
512 em28xx_gpio_set(dev, hauppauge_hvr930c_init);
513 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
514 usleep_range(10000, 11000);
515 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
516 usleep_range(10000, 11000);
518 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
520 for (i = 0; i < ARRAY_SIZE(regs); i++)
521 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
522 regs[i].r, regs[i].len);
523 em28xx_gpio_set(dev, hauppauge_hvr930c_end);
527 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
530 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
531 usleep_range(10000, 11000);
534 static void terratec_h5_init(struct em28xx *dev)
537 struct em28xx_reg_seq terratec_h5_init[] = {
538 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
539 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
540 {EM2874_R80_GPIO_P0_CTRL, 0xf2, 0xff, 50},
541 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
544 struct em28xx_reg_seq terratec_h5_end[] = {
545 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
546 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
547 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
554 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
556 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
558 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
559 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
561 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
564 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
566 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
569 em28xx_gpio_set(dev, terratec_h5_init);
570 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
571 usleep_range(10000, 11000);
572 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
573 usleep_range(10000, 11000);
575 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
577 for (i = 0; i < ARRAY_SIZE(regs); i++)
578 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
579 regs[i].r, regs[i].len);
580 em28xx_gpio_set(dev, terratec_h5_end);
583 static void terratec_htc_stick_init(struct em28xx *dev)
588 * GPIO configuration:
589 * 0xff: unknown (does not affect DVB-T).
590 * 0xf6: DRX-K (demodulator).
591 * 0xe6: unknown (does not affect DVB-T).
592 * 0xb6: unknown (does not affect DVB-T).
594 struct em28xx_reg_seq terratec_htc_stick_init[] = {
595 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
596 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
597 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 50},
598 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
601 struct em28xx_reg_seq terratec_htc_stick_end[] = {
602 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
603 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 50},
608 * Init the analog decoder (not yet supported), but
609 * it's probably still a good idea.
615 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
617 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
619 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
622 em28xx_gpio_set(dev, terratec_htc_stick_init);
624 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
625 usleep_range(10000, 11000);
626 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
627 usleep_range(10000, 11000);
629 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
631 for (i = 0; i < ARRAY_SIZE(regs); i++)
632 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
633 regs[i].r, regs[i].len);
635 em28xx_gpio_set(dev, terratec_htc_stick_end);
638 static void terratec_htc_usb_xs_init(struct em28xx *dev)
642 struct em28xx_reg_seq terratec_htc_usb_xs_init[] = {
643 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
644 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 100},
645 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 50},
646 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
649 struct em28xx_reg_seq terratec_htc_usb_xs_end[] = {
650 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 100},
651 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
652 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
657 * Init the analog decoder (not yet supported), but
658 * it's probably still a good idea.
664 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
666 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
668 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
669 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
671 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
674 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
676 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
679 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
681 em28xx_gpio_set(dev, terratec_htc_usb_xs_init);
683 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
684 usleep_range(10000, 11000);
685 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
686 usleep_range(10000, 11000);
688 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
690 for (i = 0; i < ARRAY_SIZE(regs); i++)
691 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
692 regs[i].r, regs[i].len);
694 em28xx_gpio_set(dev, terratec_htc_usb_xs_end);
697 static void pctv_520e_init(struct em28xx *dev)
700 * Init AVF4910B analog decoder. Looks like I2C traffic to
701 * digital demodulator and tuner are routed via AVF4910B.
708 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
710 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
712 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
713 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
715 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
718 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; /* 0x41 */
720 for (i = 0; i < ARRAY_SIZE(regs); i++)
721 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus],
722 regs[i].r, regs[i].len);
725 static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
727 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
728 struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
729 struct em28xx *dev = i2c_bus->dev;
730 #ifdef CONFIG_GPIOLIB
731 struct em28xx_dvb *dvb = dev->dvb;
736 flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
738 flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
740 ret = gpio_request_one(dvb->lna_gpio, flags, NULL);
742 dev_err(&dev->intf->dev, "gpio request failed %d\n", ret);
744 gpio_free(dvb->lna_gpio);
748 dev_warn(&dev->intf->dev, "%s: LNA control is disabled (lna=%u)\n",
749 KBUILD_MODNAME, c->lna);
754 static int em28xx_pctv_292e_set_lna(struct dvb_frontend *fe)
756 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
757 struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
758 struct em28xx *dev = i2c_bus->dev;
766 return em28xx_write_reg_bits(dev, EM2874_R80_GPIO_P0_CTRL, lna, 0x01);
769 static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
771 /* Values extracted from a USB trace of the Terratec Windows driver */
772 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
773 static u8 reset[] = { RESET, 0x80 };
774 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
775 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
776 static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
777 static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
778 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
779 static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
780 static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
781 static u8 tuner_go[] = { TUNER_GO, 0x01};
783 mt352_write(fe, clock_config, sizeof(clock_config));
784 usleep_range(200, 250);
785 mt352_write(fe, reset, sizeof(reset));
786 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
787 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
788 mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
789 mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
790 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
791 mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
792 mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
793 mt352_write(fe, tuner_go, sizeof(tuner_go));
797 static void px_bcud_init(struct em28xx *dev)
818 static struct em28xx_reg_seq gpio[] = {
819 {EM28XX_R06_I2C_CLK, 0x40, 0xff, 300},
820 {EM2874_R80_GPIO_P0_CTRL, 0xfd, 0xff, 60},
821 {EM28XX_R15_RGAIN, 0x20, 0xff, 0},
822 {EM28XX_R16_GGAIN, 0x20, 0xff, 0},
823 {EM28XX_R17_BGAIN, 0x20, 0xff, 0},
824 {EM28XX_R18_ROFFSET, 0x00, 0xff, 0},
825 {EM28XX_R19_GOFFSET, 0x00, 0xff, 0},
826 {EM28XX_R1A_BOFFSET, 0x00, 0xff, 0},
827 {EM28XX_R23_UOFFSET, 0x00, 0xff, 0},
828 {EM28XX_R24_VOFFSET, 0x00, 0xff, 0},
829 {EM28XX_R26_COMPR, 0x00, 0xff, 0},
830 {0x13, 0x08, 0xff, 0},
831 {EM28XX_R12_VINENABLE, 0x27, 0xff, 0},
832 {EM28XX_R0C_USBSUSP, 0x10, 0xff, 0},
833 {EM28XX_R27_OUTFMT, 0x00, 0xff, 0},
834 {EM28XX_R10_VINMODE, 0x00, 0xff, 0},
835 {EM28XX_R11_VINCTRL, 0x11, 0xff, 0},
836 {EM2874_R50_IR_CONFIG, 0x01, 0xff, 0},
837 {EM2874_R5F_TS_ENABLE, 0x80, 0xff, 0},
838 {EM28XX_R06_I2C_CLK, 0x46, 0xff, 0},
840 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x46);
841 /* sleeping ISDB-T */
842 dev->dvb->i2c_client_demod->addr = 0x14;
843 for (i = 0; i < ARRAY_SIZE(regs1); i++)
844 i2c_master_send(dev->dvb->i2c_client_demod,
845 regs1[i].r, regs1[i].len);
846 /* sleeping ISDB-S */
847 dev->dvb->i2c_client_demod->addr = 0x15;
848 for (i = 0; i < ARRAY_SIZE(regs2); i++)
849 i2c_master_send(dev->dvb->i2c_client_demod, regs2[i].r,
851 for (i = 0; i < ARRAY_SIZE(gpio); i++) {
852 em28xx_write_reg_bits(dev, gpio[i].reg, gpio[i].val,
854 if (gpio[i].sleep > 0)
855 msleep(gpio[i].sleep);
859 static struct mt352_config terratec_xs_mt352_cfg = {
860 .demod_address = (0x1e >> 1),
863 .demod_init = em28xx_mt352_terratec_xs_init,
866 static struct tda10023_config em28xx_tda10023_config = {
867 .demod_address = 0x0c,
871 static struct cxd2820r_config em28xx_cxd2820r_config = {
872 .i2c_address = (0xd8 >> 1),
873 .ts_mode = CXD2820R_TS_SERIAL,
876 static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
877 .output_opt = TDA18271_OUTPUT_LT_OFF,
878 .gate = TDA18271_GATE_DIGITAL,
881 static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
882 .demod_address = (0x1e >> 1),
883 .disable_i2c_gate_ctrl = 1,
888 static struct mt2060_config em28xx_mt2060_config = {
892 static struct qt1010_config em28xx_qt1010_config = {
896 static const struct mb86a20s_config c3tech_duo_mb86a20s_config = {
897 .demod_address = 0x10,
901 static struct tda18271_std_map mb86a20s_tda18271_config = {
902 .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4,
903 .if_lvl = 1, .rfagc_top = 0x37, },
906 static struct tda18271_config c3tech_duo_tda18271_config = {
907 .std_map = &mb86a20s_tda18271_config,
908 .gate = TDA18271_GATE_DIGITAL,
909 .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
912 static struct tda18271_std_map drx_j_std_map = {
913 .atsc_6 = { .if_freq = 5000, .agc_mode = 3, .std = 0, .if_lvl = 1,
914 .rfagc_top = 0x37, },
915 .qam_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3, .if_lvl = 1,
916 .rfagc_top = 0x37, },
919 static struct tda18271_config pinnacle_80e_dvb_config = {
920 .std_map = &drx_j_std_map,
921 .gate = TDA18271_GATE_DIGITAL,
922 .role = TDA18271_MASTER,
925 static struct lgdt3306a_config hauppauge_01595_lgdt3306a_config = {
928 .spectral_inversion = 0,
930 .mpeg_mode = LGDT3306A_MPEG_SERIAL,
931 .tpclk_edge = LGDT3306A_TPCLK_RISING_EDGE,
932 .tpvalid_polarity = LGDT3306A_TP_VALID_HIGH,
936 /* ------------------------------------------------------------------ */
938 static noinline_for_stack int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
940 struct dvb_frontend *fe;
941 struct xc2028_config cfg;
942 struct xc2028_ctrl ctl;
944 memset(&cfg, 0, sizeof(cfg));
945 cfg.i2c_adap = &dev->i2c_adap[dev->def_i2c_bus];
948 memset(&ctl, 0, sizeof(ctl));
949 em28xx_setup_xc3028(dev, &ctl);
952 if (!dev->dvb->fe[0]) {
953 dev_err(&dev->intf->dev,
954 "dvb frontend not attached. Can't attach xc3028\n");
958 fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
960 dev_err(&dev->intf->dev, "xc3028 attach failed\n");
961 dvb_frontend_detach(dev->dvb->fe[0]);
962 dev->dvb->fe[0] = NULL;
966 dev_info(&dev->intf->dev, "xc3028 attached\n");
971 /* ------------------------------------------------------------------ */
973 static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
974 struct em28xx *dev, struct device *device)
977 bool create_rf_connector = false;
979 mutex_init(&dvb->lock);
981 /* register adapter */
982 result = dvb_register_adapter(&dvb->adapter,
983 dev_name(&dev->intf->dev), module,
986 dev_warn(&dev->intf->dev,
987 "dvb_register_adapter failed (errno = %d)\n",
991 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
992 dvb->adapter.mdev = dev->media_dev;
995 /* Ensure all frontends negotiate bus access */
996 dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
998 dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
1000 dvb->adapter.priv = &dev->i2c_bus[dev->def_i2c_bus];
1002 /* register frontend */
1003 result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
1005 dev_warn(&dev->intf->dev,
1006 "dvb_register_frontend failed (errno = %d)\n",
1008 goto fail_frontend0;
1011 /* register 2nd frontend */
1013 result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
1015 dev_warn(&dev->intf->dev,
1016 "2nd dvb_register_frontend failed (errno = %d)\n",
1018 goto fail_frontend1;
1022 /* register demux stuff */
1023 dvb->demux.dmx.capabilities =
1024 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
1025 DMX_MEMORY_BASED_FILTERING;
1026 dvb->demux.priv = dvb;
1027 dvb->demux.filternum = 256;
1028 dvb->demux.feednum = 256;
1029 dvb->demux.start_feed = em28xx_start_feed;
1030 dvb->demux.stop_feed = em28xx_stop_feed;
1032 result = dvb_dmx_init(&dvb->demux);
1034 dev_warn(&dev->intf->dev,
1035 "dvb_dmx_init failed (errno = %d)\n",
1040 dvb->dmxdev.filternum = 256;
1041 dvb->dmxdev.demux = &dvb->demux.dmx;
1042 dvb->dmxdev.capabilities = 0;
1043 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
1045 dev_warn(&dev->intf->dev,
1046 "dvb_dmxdev_init failed (errno = %d)\n",
1051 dvb->fe_hw.source = DMX_FRONTEND_0;
1052 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
1054 dev_warn(&dev->intf->dev,
1055 "add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
1060 dvb->fe_mem.source = DMX_MEMORY_FE;
1061 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
1063 dev_warn(&dev->intf->dev,
1064 "add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
1069 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
1071 dev_warn(&dev->intf->dev,
1072 "connect_frontend failed (errno = %d)\n",
1077 /* register network adapter */
1078 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
1080 /* If the analog part won't create RF connectors, DVB will do it */
1081 if (!dev->has_video || dev->tuner_type == TUNER_ABSENT)
1082 create_rf_connector = true;
1084 result = dvb_create_media_graph(&dvb->adapter, create_rf_connector);
1086 goto fail_create_graph;
1091 dvb_net_release(&dvb->net);
1093 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
1095 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
1097 dvb_dmxdev_release(&dvb->dmxdev);
1099 dvb_dmx_release(&dvb->demux);
1102 dvb_unregister_frontend(dvb->fe[1]);
1103 dvb_unregister_frontend(dvb->fe[0]);
1106 dvb_frontend_detach(dvb->fe[1]);
1108 dvb_frontend_detach(dvb->fe[0]);
1109 dvb_unregister_adapter(&dvb->adapter);
1114 static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
1116 dvb_net_release(&dvb->net);
1117 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
1118 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
1119 dvb_dmxdev_release(&dvb->dmxdev);
1120 dvb_dmx_release(&dvb->demux);
1122 dvb_unregister_frontend(dvb->fe[1]);
1123 dvb_unregister_frontend(dvb->fe[0]);
1124 if (dvb->fe[1] && !dvb->dont_attach_fe1)
1125 dvb_frontend_detach(dvb->fe[1]);
1126 dvb_frontend_detach(dvb->fe[0]);
1127 dvb_unregister_adapter(&dvb->adapter);
1130 static int em28174_dvb_init_pctv_460e(struct em28xx *dev)
1132 struct em28xx_dvb *dvb = dev->dvb;
1133 struct tda10071_platform_data tda10071_pdata = {};
1134 struct a8293_platform_data a8293_pdata = {};
1136 /* attach demod + tuner combo */
1137 tda10071_pdata.clk = 40444000; /* 40.444 MHz */
1138 tda10071_pdata.i2c_wr_max = 64;
1139 tda10071_pdata.ts_mode = TDA10071_TS_SERIAL;
1140 tda10071_pdata.pll_multiplier = 20;
1141 tda10071_pdata.tuner_i2c_addr = 0x14;
1143 dvb->i2c_client_demod = dvb_module_probe("tda10071", "tda10071_cx24118",
1144 &dev->i2c_adap[dev->def_i2c_bus],
1145 0x55, &tda10071_pdata);
1146 if (!dvb->i2c_client_demod)
1149 dvb->fe[0] = tda10071_pdata.get_dvb_frontend(dvb->i2c_client_demod);
1152 a8293_pdata.dvb_frontend = dvb->fe[0];
1154 dvb->i2c_client_sec = dvb_module_probe("a8293", NULL,
1155 &dev->i2c_adap[dev->def_i2c_bus],
1156 0x08, &a8293_pdata);
1157 if (!dvb->i2c_client_sec) {
1158 dvb_module_release(dvb->i2c_client_demod);
1165 static int em28178_dvb_init_pctv_461e(struct em28xx *dev)
1167 struct em28xx_dvb *dvb = dev->dvb;
1168 struct i2c_adapter *i2c_adapter;
1169 struct m88ds3103_platform_data m88ds3103_pdata = {};
1170 struct ts2020_config ts2020_config = {};
1171 struct a8293_platform_data a8293_pdata = {};
1174 m88ds3103_pdata.clk = 27000000;
1175 m88ds3103_pdata.i2c_wr_max = 33;
1176 m88ds3103_pdata.ts_mode = M88DS3103_TS_PARALLEL;
1177 m88ds3103_pdata.ts_clk = 16000;
1178 m88ds3103_pdata.ts_clk_pol = 1;
1179 m88ds3103_pdata.agc = 0x99;
1181 dvb->i2c_client_demod = dvb_module_probe("m88ds3103", NULL,
1182 &dev->i2c_adap[dev->def_i2c_bus],
1183 0x68, &m88ds3103_pdata);
1184 if (!dvb->i2c_client_demod)
1187 dvb->fe[0] = m88ds3103_pdata.get_dvb_frontend(dvb->i2c_client_demod);
1188 i2c_adapter = m88ds3103_pdata.get_i2c_adapter(dvb->i2c_client_demod);
1191 ts2020_config.fe = dvb->fe[0];
1193 dvb->i2c_client_tuner = dvb_module_probe("ts2020", "ts2022",
1195 0x60, &ts2020_config);
1196 if (!dvb->i2c_client_tuner) {
1197 dvb_module_release(dvb->i2c_client_demod);
1201 /* delegate signal strength measurement to tuner */
1202 dvb->fe[0]->ops.read_signal_strength =
1203 dvb->fe[0]->ops.tuner_ops.get_rf_strength;
1206 a8293_pdata.dvb_frontend = dvb->fe[0];
1207 dvb->i2c_client_sec = dvb_module_probe("a8293", NULL,
1208 &dev->i2c_adap[dev->def_i2c_bus],
1209 0x08, &a8293_pdata);
1210 if (!dvb->i2c_client_sec) {
1211 dvb_module_release(dvb->i2c_client_tuner);
1212 dvb_module_release(dvb->i2c_client_demod);
1219 static int em28178_dvb_init_pctv_292e(struct em28xx *dev)
1221 struct em28xx_dvb *dvb = dev->dvb;
1222 struct i2c_adapter *adapter;
1223 struct si2168_config si2168_config = {};
1224 struct si2157_config si2157_config = {};
1227 si2168_config.i2c_adapter = &adapter;
1228 si2168_config.fe = &dvb->fe[0];
1229 si2168_config.ts_mode = SI2168_TS_PARALLEL;
1230 si2168_config.spectral_inversion = true;
1232 dvb->i2c_client_demod = dvb_module_probe("si2168", NULL,
1233 &dev->i2c_adap[dev->def_i2c_bus],
1234 0x64, &si2168_config);
1235 if (!dvb->i2c_client_demod)
1239 si2157_config.fe = dvb->fe[0];
1240 si2157_config.if_port = 1;
1241 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1242 si2157_config.mdev = dev->media_dev;
1244 dvb->i2c_client_tuner = dvb_module_probe("si2157", NULL,
1246 0x60, &si2157_config);
1247 if (!dvb->i2c_client_tuner) {
1248 dvb_module_release(dvb->i2c_client_demod);
1251 dvb->fe[0]->ops.set_lna = em28xx_pctv_292e_set_lna;
1256 static int em28178_dvb_init_terratec_t2_stick_hd(struct em28xx *dev)
1258 struct em28xx_dvb *dvb = dev->dvb;
1259 struct i2c_adapter *adapter;
1260 struct si2168_config si2168_config = {};
1261 struct si2157_config si2157_config = {};
1264 si2168_config.i2c_adapter = &adapter;
1265 si2168_config.fe = &dvb->fe[0];
1266 si2168_config.ts_mode = SI2168_TS_PARALLEL;
1268 dvb->i2c_client_demod = dvb_module_probe("si2168", NULL,
1269 &dev->i2c_adap[dev->def_i2c_bus],
1270 0x64, &si2168_config);
1271 if (!dvb->i2c_client_demod)
1275 memset(&si2157_config, 0, sizeof(si2157_config));
1276 si2157_config.fe = dvb->fe[0];
1277 si2157_config.if_port = 0;
1278 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1279 si2157_config.mdev = dev->media_dev;
1281 dvb->i2c_client_tuner = dvb_module_probe("si2157", "si2146",
1283 0x60, &si2157_config);
1284 if (!dvb->i2c_client_tuner) {
1285 dvb_module_release(dvb->i2c_client_demod);
1292 static int em28178_dvb_init_plex_px_bcud(struct em28xx *dev)
1294 struct em28xx_dvb *dvb = dev->dvb;
1295 struct tc90522_config tc90522_config = {};
1296 struct qm1d1c0042_config qm1d1c0042_config = {};
1299 dvb->i2c_client_demod = dvb_module_probe("tc90522", "tc90522sat",
1300 &dev->i2c_adap[dev->def_i2c_bus],
1301 0x15, &tc90522_config);
1302 if (!dvb->i2c_client_demod)
1306 qm1d1c0042_config.fe = tc90522_config.fe;
1307 qm1d1c0042_config.lpf = 1;
1309 dvb->i2c_client_tuner = dvb_module_probe("qm1d1c0042", NULL,
1310 tc90522_config.tuner_i2c,
1311 0x61, &qm1d1c0042_config);
1312 if (!dvb->i2c_client_tuner) {
1313 dvb_module_release(dvb->i2c_client_demod);
1317 dvb->fe[0] = tc90522_config.fe;
1323 static int em28174_dvb_init_hauppauge_wintv_dualhd_dvb(struct em28xx *dev)
1325 struct em28xx_dvb *dvb = dev->dvb;
1326 struct i2c_adapter *adapter;
1327 struct si2168_config si2168_config = {};
1328 struct si2157_config si2157_config = {};
1332 si2168_config.i2c_adapter = &adapter;
1333 si2168_config.fe = &dvb->fe[0];
1334 si2168_config.ts_mode = SI2168_TS_SERIAL;
1335 si2168_config.spectral_inversion = true;
1336 addr = (dev->ts == PRIMARY_TS) ? 0x64 : 0x67;
1338 dvb->i2c_client_demod = dvb_module_probe("si2168", NULL,
1339 &dev->i2c_adap[dev->def_i2c_bus],
1340 addr, &si2168_config);
1341 if (!dvb->i2c_client_demod)
1345 memset(&si2157_config, 0, sizeof(si2157_config));
1346 si2157_config.fe = dvb->fe[0];
1347 si2157_config.if_port = 1;
1348 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1349 si2157_config.mdev = dev->media_dev;
1351 addr = (dev->ts == PRIMARY_TS) ? 0x60 : 0x63;
1353 dvb->i2c_client_tuner = dvb_module_probe("si2157", NULL,
1355 addr, &si2157_config);
1356 if (!dvb->i2c_client_tuner) {
1357 dvb_module_release(dvb->i2c_client_demod);
1364 static int em28174_dvb_init_hauppauge_wintv_dualhd_01595(struct em28xx *dev)
1366 struct em28xx_dvb *dvb = dev->dvb;
1367 struct i2c_adapter *adapter;
1368 struct lgdt3306a_config lgdt3306a_config = {};
1369 struct si2157_config si2157_config = {};
1373 lgdt3306a_config = hauppauge_01595_lgdt3306a_config;
1374 lgdt3306a_config.fe = &dvb->fe[0];
1375 lgdt3306a_config.i2c_adapter = &adapter;
1376 addr = (dev->ts == PRIMARY_TS) ? 0x59 : 0x0e;
1378 dvb->i2c_client_demod = dvb_module_probe("lgdt3306a", NULL,
1379 &dev->i2c_adap[dev->def_i2c_bus],
1380 addr, &lgdt3306a_config);
1381 if (!dvb->i2c_client_demod)
1385 si2157_config.fe = dvb->fe[0];
1386 si2157_config.if_port = 1;
1387 si2157_config.inversion = 1;
1388 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1389 si2157_config.mdev = dev->media_dev;
1391 addr = (dev->ts == PRIMARY_TS) ? 0x60 : 0x62;
1393 dvb->i2c_client_tuner = dvb_module_probe("si2157", NULL,
1395 0x60, &si2157_config);
1396 if (!dvb->i2c_client_tuner) {
1397 dvb_module_release(dvb->i2c_client_demod);
1404 static int em28xx_dvb_init(struct em28xx *dev)
1406 int result = 0, dvb_alt = 0;
1407 struct em28xx_dvb *dvb;
1408 struct usb_device *udev;
1410 if (dev->is_audio_only) {
1411 /* Shouldn't initialize IR for this interface */
1415 if (!dev->board.has_dvb) {
1416 /* This device does not support the extension */
1420 dev_info(&dev->intf->dev, "Binding DVB extension\n");
1422 dvb = kzalloc(sizeof(*dvb), GFP_KERNEL);
1430 /* pre-allocate DVB usb transfer buffers */
1431 if (dev->dvb_xfer_bulk) {
1432 result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
1434 EM28XX_DVB_NUM_BUFS,
1436 EM28XX_DVB_BULK_PACKET_MULTIPLIER);
1438 result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
1440 EM28XX_DVB_NUM_BUFS,
1441 dev->dvb_max_pkt_size_isoc,
1442 EM28XX_DVB_NUM_ISOC_PACKETS);
1445 dev_err(&dev->intf->dev,
1446 "failed to pre-allocate USB transfer buffers for DVB.\n");
1452 mutex_lock(&dev->lock);
1453 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
1455 switch (dev->model) {
1456 case EM2874_BOARD_LEADERSHIP_ISDBT:
1457 dvb->fe[0] = dvb_attach(s921_attach,
1459 &dev->i2c_adap[dev->def_i2c_bus]);
1467 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
1468 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
1469 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
1470 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
1471 dvb->fe[0] = dvb_attach(lgdt330x_attach,
1472 &em2880_lgdt3303_dev,
1473 &dev->i2c_adap[dev->def_i2c_bus]);
1474 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1479 case EM2880_BOARD_KWORLD_DVB_310U:
1480 dvb->fe[0] = dvb_attach(zl10353_attach,
1481 &em28xx_zl10353_with_xc3028,
1482 &dev->i2c_adap[dev->def_i2c_bus]);
1483 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1488 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
1489 case EM2882_BOARD_TERRATEC_HYBRID_XS:
1490 case EM2880_BOARD_EMPIRE_DUAL_TV:
1491 dvb->fe[0] = dvb_attach(zl10353_attach,
1492 &em28xx_zl10353_xc3028_no_i2c_gate,
1493 &dev->i2c_adap[dev->def_i2c_bus]);
1494 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1499 case EM2880_BOARD_TERRATEC_HYBRID_XS:
1500 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
1501 case EM2881_BOARD_PINNACLE_HYBRID_PRO:
1502 case EM2882_BOARD_DIKOM_DK300:
1503 case EM2882_BOARD_KWORLD_VS_DVBT:
1505 * Those boards could have either a zl10353 or a mt352.
1506 * If the chip id isn't for zl10353, try mt352.
1508 dvb->fe[0] = dvb_attach(zl10353_attach,
1509 &em28xx_zl10353_xc3028_no_i2c_gate,
1510 &dev->i2c_adap[dev->def_i2c_bus]);
1512 dvb->fe[0] = dvb_attach(mt352_attach,
1513 &terratec_xs_mt352_cfg,
1514 &dev->i2c_adap[dev->def_i2c_bus]);
1516 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1521 case EM2870_BOARD_TERRATEC_XS_MT2060:
1522 dvb->fe[0] = dvb_attach(zl10353_attach,
1523 &em28xx_zl10353_no_i2c_gate_dev,
1524 &dev->i2c_adap[dev->def_i2c_bus]);
1526 dvb_attach(mt2060_attach, dvb->fe[0],
1527 &dev->i2c_adap[dev->def_i2c_bus],
1528 &em28xx_mt2060_config, 1220);
1531 case EM2870_BOARD_KWORLD_355U:
1532 dvb->fe[0] = dvb_attach(zl10353_attach,
1533 &em28xx_zl10353_no_i2c_gate_dev,
1534 &dev->i2c_adap[dev->def_i2c_bus]);
1536 dvb_attach(qt1010_attach, dvb->fe[0],
1537 &dev->i2c_adap[dev->def_i2c_bus],
1538 &em28xx_qt1010_config);
1540 case EM2883_BOARD_KWORLD_HYBRID_330U:
1541 case EM2882_BOARD_EVGA_INDTUBE:
1542 dvb->fe[0] = dvb_attach(s5h1409_attach,
1543 &em28xx_s5h1409_with_xc3028,
1544 &dev->i2c_adap[dev->def_i2c_bus]);
1545 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1550 case EM2882_BOARD_KWORLD_ATSC_315U:
1551 dvb->fe[0] = dvb_attach(lgdt330x_attach,
1552 &em2880_lgdt3303_dev,
1553 &dev->i2c_adap[dev->def_i2c_bus]);
1555 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
1556 &dev->i2c_adap[dev->def_i2c_bus],
1557 0x61, TUNER_THOMSON_DTT761X)) {
1563 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
1564 case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
1565 dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
1566 &dev->i2c_adap[dev->def_i2c_bus],
1568 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1573 case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
1574 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
1575 dvb->fe[0] = dvb_attach(tda10023_attach,
1576 &em28xx_tda10023_config,
1577 &dev->i2c_adap[dev->def_i2c_bus],
1580 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
1581 &dev->i2c_adap[dev->def_i2c_bus],
1582 0x60, TUNER_PHILIPS_CU1216L)) {
1588 case EM2870_BOARD_KWORLD_A340:
1589 dvb->fe[0] = dvb_attach(lgdt3305_attach,
1590 &em2870_lgdt3304_dev,
1591 &dev->i2c_adap[dev->def_i2c_bus]);
1596 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1597 &dev->i2c_adap[dev->def_i2c_bus],
1598 &kworld_a340_config)) {
1599 dvb_frontend_detach(dvb->fe[0]);
1604 case EM28174_BOARD_PCTV_290E:
1605 /* set default GPIO0 for LNA, used if GPIOLIB is undefined */
1606 dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O |
1608 dvb->fe[0] = dvb_attach(cxd2820r_attach,
1609 &em28xx_cxd2820r_config,
1610 &dev->i2c_adap[dev->def_i2c_bus],
1613 /* FE 0 attach tuner */
1614 if (!dvb_attach(tda18271_attach,
1617 &dev->i2c_adap[dev->def_i2c_bus],
1618 &em28xx_cxd2820r_tda18271_config)) {
1619 dvb_frontend_detach(dvb->fe[0]);
1624 #ifdef CONFIG_GPIOLIB
1625 /* enable LNA for DVB-T, DVB-T2 and DVB-C */
1626 result = gpio_request_one(dvb->lna_gpio,
1627 GPIOF_OUT_INIT_LOW, NULL);
1629 dev_err(&dev->intf->dev,
1630 "gpio request failed %d\n",
1633 gpio_free(dvb->lna_gpio);
1635 result = 0; /* continue even set LNA fails */
1637 dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
1641 case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
1643 struct xc5000_config cfg = {};
1645 hauppauge_hvr930c_init(dev);
1647 dvb->fe[0] = dvb_attach(drxk_attach,
1648 &hauppauge_930c_drxk,
1649 &dev->i2c_adap[dev->def_i2c_bus]);
1654 /* FIXME: do we need a pll semaphore? */
1655 dvb->fe[0]->sec_priv = dvb;
1656 sema_init(&dvb->pll_mutex, 1);
1657 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1658 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
1661 cfg.i2c_address = 0x61;
1664 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1665 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1666 if (!dvb_attach(xc5000_attach, dvb->fe[0],
1667 &dev->i2c_adap[dev->def_i2c_bus], &cfg)) {
1671 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1672 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1676 case EM2884_BOARD_TERRATEC_H5:
1677 terratec_h5_init(dev);
1679 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk,
1680 &dev->i2c_adap[dev->def_i2c_bus]);
1685 /* FIXME: do we need a pll semaphore? */
1686 dvb->fe[0]->sec_priv = dvb;
1687 sema_init(&dvb->pll_mutex, 1);
1688 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1689 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
1691 /* Attach tda18271 to DVB-C frontend */
1692 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1693 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1694 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0],
1695 &dev->i2c_adap[dev->def_i2c_bus], 0x60)) {
1699 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1700 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1703 case EM2884_BOARD_C3TECH_DIGITAL_DUO:
1704 dvb->fe[0] = dvb_attach(mb86a20s_attach,
1705 &c3tech_duo_mb86a20s_config,
1706 &dev->i2c_adap[dev->def_i2c_bus]);
1708 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1709 &dev->i2c_adap[dev->def_i2c_bus],
1710 &c3tech_duo_tda18271_config);
1712 case EM28174_BOARD_PCTV_460E:
1713 result = em28174_dvb_init_pctv_460e(dev);
1717 case EM2874_BOARD_DELOCK_61959:
1718 case EM2874_BOARD_MAXMEDIA_UB425_TC:
1719 /* attach demodulator */
1720 dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
1721 &dev->i2c_adap[dev->def_i2c_bus]);
1724 /* disable I2C-gate */
1725 dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
1728 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1729 &dev->i2c_adap[dev->def_i2c_bus],
1730 &em28xx_cxd2820r_tda18271_config)) {
1731 dvb_frontend_detach(dvb->fe[0]);
1737 case EM2884_BOARD_PCTV_510E:
1738 case EM2884_BOARD_PCTV_520E:
1739 pctv_520e_init(dev);
1741 /* attach demodulator */
1742 dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
1743 &dev->i2c_adap[dev->def_i2c_bus]);
1747 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1748 &dev->i2c_adap[dev->def_i2c_bus],
1749 &em28xx_cxd2820r_tda18271_config)) {
1750 dvb_frontend_detach(dvb->fe[0]);
1756 case EM2884_BOARD_ELGATO_EYETV_HYBRID_2008:
1757 case EM2884_BOARD_CINERGY_HTC_STICK:
1758 case EM2884_BOARD_TERRATEC_H6:
1759 terratec_htc_stick_init(dev);
1761 /* attach demodulator */
1762 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1763 &dev->i2c_adap[dev->def_i2c_bus]);
1769 /* Attach the demodulator. */
1770 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1771 &dev->i2c_adap[dev->def_i2c_bus],
1772 &em28xx_cxd2820r_tda18271_config)) {
1777 case EM2884_BOARD_TERRATEC_HTC_USB_XS:
1778 terratec_htc_usb_xs_init(dev);
1780 /* attach demodulator */
1781 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1782 &dev->i2c_adap[dev->def_i2c_bus]);
1788 /* Attach the demodulator. */
1789 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1790 &dev->i2c_adap[dev->def_i2c_bus],
1791 &em28xx_cxd2820r_tda18271_config)) {
1796 case EM2874_BOARD_KWORLD_UB435Q_V2:
1797 dvb->fe[0] = dvb_attach(lgdt3305_attach,
1798 &em2874_lgdt3305_dev,
1799 &dev->i2c_adap[dev->def_i2c_bus]);
1805 /* Attach the demodulator. */
1806 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1807 &dev->i2c_adap[dev->def_i2c_bus],
1808 &kworld_ub435q_v2_config)) {
1813 case EM2874_BOARD_KWORLD_UB435Q_V3:
1815 struct i2c_adapter *adapter = &dev->i2c_adap[dev->def_i2c_bus];
1817 dvb->fe[0] = dvb_attach(lgdt3305_attach,
1818 &em2874_lgdt3305_nogate_dev,
1819 &dev->i2c_adap[dev->def_i2c_bus]);
1826 kworld_ub435q_v3_config.fe = dvb->fe[0];
1828 dvb->i2c_client_tuner = dvb_module_probe("tda18212", NULL,
1830 &kworld_ub435q_v3_config);
1831 if (!dvb->i2c_client_tuner) {
1832 dvb_frontend_detach(dvb->fe[0]);
1838 case EM2874_BOARD_PCTV_HD_MINI_80E:
1839 dvb->fe[0] = dvb_attach(drx39xxj_attach,
1840 &dev->i2c_adap[dev->def_i2c_bus]);
1842 dvb->fe[0] = dvb_attach(tda18271_attach, dvb->fe[0],
1844 &dev->i2c_adap[dev->def_i2c_bus],
1845 &pinnacle_80e_dvb_config);
1852 case EM28178_BOARD_PCTV_461E:
1853 result = em28178_dvb_init_pctv_461e(dev);
1857 case EM28178_BOARD_PCTV_292E:
1858 result = em28178_dvb_init_pctv_292e(dev);
1862 case EM28178_BOARD_TERRATEC_T2_STICK_HD:
1863 result = em28178_dvb_init_terratec_t2_stick_hd(dev);
1867 case EM28178_BOARD_PLEX_PX_BCUD:
1868 result = em28178_dvb_init_plex_px_bcud(dev);
1872 case EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_DVB:
1873 result = em28174_dvb_init_hauppauge_wintv_dualhd_dvb(dev);
1877 case EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_01595:
1878 result = em28174_dvb_init_hauppauge_wintv_dualhd_01595(dev);
1883 dev_err(&dev->intf->dev,
1884 "The frontend of your DVB/ATSC card isn't supported yet\n");
1888 dev_err(&dev->intf->dev, "frontend initialization failed\n");
1892 /* define general-purpose callback pointer */
1893 dvb->fe[0]->callback = em28xx_tuner_callback;
1895 dvb->fe[1]->callback = em28xx_tuner_callback;
1897 /* register everything */
1898 result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->intf->dev);
1903 if (dev->dvb_xfer_bulk) {
1906 dvb_alt = dev->dvb_alt_isoc;
1909 udev = interface_to_usbdev(dev->intf);
1910 usb_set_interface(udev, dev->ifnum, dvb_alt);
1911 dev_info(&dev->intf->dev, "DVB extension successfully initialized\n");
1913 kref_get(&dev->ref);
1916 em28xx_set_mode(dev, EM28XX_SUSPEND);
1917 mutex_unlock(&dev->lock);
1926 static inline void prevent_sleep(struct dvb_frontend_ops *ops)
1928 ops->set_voltage = NULL;
1930 ops->tuner_ops.sleep = NULL;
1933 static int em28xx_dvb_fini(struct em28xx *dev)
1935 struct em28xx_dvb *dvb;
1937 if (dev->is_audio_only) {
1938 /* Shouldn't initialize IR for this interface */
1942 if (!dev->board.has_dvb) {
1943 /* This device does not support the extension */
1950 dev_info(&dev->intf->dev, "Closing DVB extension\n");
1954 em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE);
1956 if (dev->disconnected) {
1958 * We cannot tell the device to sleep
1959 * once it has been unplugged.
1962 prevent_sleep(&dvb->fe[0]->ops);
1963 dvb->fe[0]->exit = DVB_FE_DEVICE_REMOVED;
1966 prevent_sleep(&dvb->fe[1]->ops);
1967 dvb->fe[1]->exit = DVB_FE_DEVICE_REMOVED;
1971 em28xx_unregister_dvb(dvb);
1973 /* release I2C module bindings */
1974 dvb_module_release(dvb->i2c_client_sec);
1975 dvb_module_release(dvb->i2c_client_tuner);
1976 dvb_module_release(dvb->i2c_client_demod);
1980 kref_put(&dev->ref, em28xx_free_device);
1985 static int em28xx_dvb_suspend(struct em28xx *dev)
1989 if (dev->is_audio_only)
1992 if (!dev->board.has_dvb)
1995 dev_info(&dev->intf->dev, "Suspending DVB extension\n");
1997 struct em28xx_dvb *dvb = dev->dvb;
2000 ret = dvb_frontend_suspend(dvb->fe[0]);
2001 dev_info(&dev->intf->dev, "fe0 suspend %d\n", ret);
2004 dvb_frontend_suspend(dvb->fe[1]);
2005 dev_info(&dev->intf->dev, "fe1 suspend %d\n", ret);
2012 static int em28xx_dvb_resume(struct em28xx *dev)
2016 if (dev->is_audio_only)
2019 if (!dev->board.has_dvb)
2022 dev_info(&dev->intf->dev, "Resuming DVB extension\n");
2024 struct em28xx_dvb *dvb = dev->dvb;
2027 ret = dvb_frontend_resume(dvb->fe[0]);
2028 dev_info(&dev->intf->dev, "fe0 resume %d\n", ret);
2032 ret = dvb_frontend_resume(dvb->fe[1]);
2033 dev_info(&dev->intf->dev, "fe1 resume %d\n", ret);
2040 static struct em28xx_ops dvb_ops = {
2042 .name = "Em28xx dvb Extension",
2043 .init = em28xx_dvb_init,
2044 .fini = em28xx_dvb_fini,
2045 .suspend = em28xx_dvb_suspend,
2046 .resume = em28xx_dvb_resume,
2049 static int __init em28xx_dvb_register(void)
2051 return em28xx_register_extension(&dvb_ops);
2054 static void __exit em28xx_dvb_unregister(void)
2056 em28xx_unregister_extension(&dvb_ops);
2059 module_init(em28xx_dvb_register);
2060 module_exit(em28xx_dvb_unregister);