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.
26 #include <linux/kernel.h>
27 #include <linux/slab.h>
28 #include <linux/usb.h>
30 #include <media/v4l2-common.h>
31 #include <dvb_demux.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");
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 *, int);
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 synchronuously";
118 errmsg = "unlinked asynchronuously";
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 struct usb_device *udev = interface_to_usbdev(dev->intf);
203 int dvb_max_packet_size, packet_multiplier, dvb_alt;
205 if (dev->dvb_xfer_bulk) {
206 if (!dev->dvb_ep_bulk)
208 dvb_max_packet_size = 512; /* USB 2.0 spec */
209 packet_multiplier = EM28XX_DVB_BULK_PACKET_MULTIPLIER;
212 if (!dev->dvb_ep_isoc)
214 dvb_max_packet_size = dev->dvb_max_pkt_size_isoc;
215 if (dvb_max_packet_size < 0)
216 return dvb_max_packet_size;
217 packet_multiplier = EM28XX_DVB_NUM_ISOC_PACKETS;
218 dvb_alt = dev->dvb_alt_isoc;
221 usb_set_interface(udev, dev->ifnum, dvb_alt);
222 rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
226 dprintk(1, "Using %d buffers each with %d x %d bytes, alternate %d\n",
229 dvb_max_packet_size, dvb_alt);
231 return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE,
236 em28xx_dvb_urb_data_copy);
239 static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
241 struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
242 struct em28xx *dev = i2c_bus->dev;
244 em28xx_stop_urbs(dev);
249 static int em28xx_start_feed(struct dvb_demux_feed *feed)
251 struct dvb_demux *demux = feed->demux;
252 struct em28xx_dvb *dvb = demux->priv;
255 if (!demux->dmx.frontend)
258 mutex_lock(&dvb->lock);
262 if (dvb->nfeeds == 1) {
263 ret = em28xx_start_streaming(dvb);
268 mutex_unlock(&dvb->lock);
272 static int em28xx_stop_feed(struct dvb_demux_feed *feed)
274 struct dvb_demux *demux = feed->demux;
275 struct em28xx_dvb *dvb = demux->priv;
278 mutex_lock(&dvb->lock);
281 if (0 == dvb->nfeeds)
282 err = em28xx_stop_streaming(dvb);
284 mutex_unlock(&dvb->lock);
289 /* ------------------------------------------------------------------ */
290 static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
292 struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
293 struct em28xx *dev = i2c_bus->dev;
296 return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
298 return em28xx_set_mode(dev, EM28XX_SUSPEND);
301 /* ------------------------------------------------------------------ */
303 static struct lgdt330x_config em2880_lgdt3303_dev = {
304 .demod_address = 0x0e,
305 .demod_chip = LGDT3303,
308 static struct lgdt3305_config em2870_lgdt3304_dev = {
310 .demod_chip = LGDT3304,
311 .spectral_inversion = 1,
313 .mpeg_mode = LGDT3305_MPEG_PARALLEL,
314 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
315 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
320 static struct lgdt3305_config em2874_lgdt3305_dev = {
322 .demod_chip = LGDT3305,
323 .spectral_inversion = 1,
325 .mpeg_mode = LGDT3305_MPEG_SERIAL,
326 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
327 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
332 static struct lgdt3305_config em2874_lgdt3305_nogate_dev = {
334 .demod_chip = LGDT3305,
335 .spectral_inversion = 1,
337 .mpeg_mode = LGDT3305_MPEG_SERIAL,
338 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
339 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
344 static struct s921_config sharp_isdbt = {
345 .demod_address = 0x30 >> 1
348 static struct zl10353_config em28xx_zl10353_with_xc3028 = {
349 .demod_address = (0x1e >> 1),
355 static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
356 .demod_address = 0x32 >> 1,
357 .output_mode = S5H1409_PARALLEL_OUTPUT,
358 .gpio = S5H1409_GPIO_OFF,
359 .inversion = S5H1409_INVERSION_OFF,
360 .status_mode = S5H1409_DEMODLOCKING,
361 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
364 static struct tda18271_std_map kworld_a340_std_map = {
365 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
366 .if_lvl = 1, .rfagc_top = 0x37, },
367 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
368 .if_lvl = 1, .rfagc_top = 0x37, },
371 static struct tda18271_config kworld_a340_config = {
372 .std_map = &kworld_a340_std_map,
375 static struct tda18271_config kworld_ub435q_v2_config = {
376 .std_map = &kworld_a340_std_map,
377 .gate = TDA18271_GATE_DIGITAL,
380 static struct tda18212_config kworld_ub435q_v3_config = {
385 static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
386 .demod_address = (0x1e >> 1),
388 .disable_i2c_gate_ctrl = 1,
393 static struct drxd_config em28xx_drxd = {
394 .demod_address = 0x70,
395 .demod_revision = 0xa2,
396 .pll_type = DRXD_PLL_NONE,
400 .disable_i2c_gate_ctrl = 1,
403 static struct drxk_config terratec_h5_drxk = {
407 .microcode_name = "dvb-usb-terratec-h5-drxk.fw",
408 .qam_demod_parameter_count = 2,
411 static struct drxk_config hauppauge_930c_drxk = {
415 .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
417 .qam_demod_parameter_count = 2,
420 static struct drxk_config terratec_htc_stick_drxk = {
424 .microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw",
426 .qam_demod_parameter_count = 2,
427 /* Required for the antenna_gpio to disable LNA. */
428 .antenna_dvbt = true,
429 /* The windows driver uses the same. This will disable LNA. */
433 static struct drxk_config maxmedia_ub425_tc_drxk = {
437 .microcode_name = "dvb-demod-drxk-01.fw",
439 .qam_demod_parameter_count = 2,
442 static struct drxk_config pctv_520e_drxk = {
445 .microcode_name = "dvb-demod-drxk-pctv.fw",
446 .qam_demod_parameter_count = 2,
448 .antenna_dvbt = true, /* disable LNA */
449 .antenna_gpio = (1 << 2), /* disable LNA */
452 static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
454 struct em28xx_dvb *dvb = fe->sec_priv;
461 down(&dvb->pll_mutex);
462 status = dvb->gate_ctrl(fe, 1);
464 status = dvb->gate_ctrl(fe, 0);
470 static void hauppauge_hvr930c_init(struct em28xx *dev)
474 struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
475 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0x65},
476 {EM2874_R80_GPIO_P0_CTRL, 0xfb, 0xff, 0x32},
477 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0xb8},
480 struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
481 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
482 {EM2874_R80_GPIO_P0_CTRL, 0xaf, 0xff, 0x65},
483 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x76},
484 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
485 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
486 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x40},
488 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x65},
489 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
490 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
491 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
500 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
502 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
504 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
505 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
507 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
510 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
512 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
515 em28xx_gpio_set(dev, hauppauge_hvr930c_init);
516 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
518 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
521 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
523 for (i = 0; i < ARRAY_SIZE(regs); i++)
524 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
525 em28xx_gpio_set(dev, hauppauge_hvr930c_end);
529 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
532 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
537 static void terratec_h5_init(struct em28xx *dev)
540 struct em28xx_reg_seq terratec_h5_init[] = {
541 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
542 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
543 {EM2874_R80_GPIO_P0_CTRL, 0xf2, 0xff, 50},
544 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
547 struct em28xx_reg_seq terratec_h5_end[] = {
548 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
549 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
550 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
557 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
559 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
561 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
562 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
564 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
567 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
569 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
572 em28xx_gpio_set(dev, terratec_h5_init);
573 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
575 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
578 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
580 for (i = 0; i < ARRAY_SIZE(regs); i++)
581 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
582 em28xx_gpio_set(dev, terratec_h5_end);
585 static void terratec_htc_stick_init(struct em28xx *dev)
590 * GPIO configuration:
591 * 0xff: unknown (does not affect DVB-T).
592 * 0xf6: DRX-K (demodulator).
593 * 0xe6: unknown (does not affect DVB-T).
594 * 0xb6: unknown (does not affect DVB-T).
596 struct em28xx_reg_seq terratec_htc_stick_init[] = {
597 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
598 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
599 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 50},
600 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
603 struct em28xx_reg_seq terratec_htc_stick_end[] = {
604 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
605 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 50},
610 * Init the analog decoder (not yet supported), but
611 * it's probably still a good idea.
617 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
619 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
621 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
624 em28xx_gpio_set(dev, terratec_htc_stick_init);
626 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
628 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
631 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
633 for (i = 0; i < ARRAY_SIZE(regs); i++)
634 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
636 em28xx_gpio_set(dev, terratec_htc_stick_end);
639 static void terratec_htc_usb_xs_init(struct em28xx *dev)
643 struct em28xx_reg_seq terratec_htc_usb_xs_init[] = {
644 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
645 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 100},
646 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 50},
647 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
650 struct em28xx_reg_seq terratec_htc_usb_xs_end[] = {
651 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 100},
652 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
653 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
658 * Init the analog decoder (not yet supported), but
659 * it's probably still a good idea.
665 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
667 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
669 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
670 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
672 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
675 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
677 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
680 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
682 em28xx_gpio_set(dev, terratec_htc_usb_xs_init);
684 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
686 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
689 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
691 for (i = 0; i < ARRAY_SIZE(regs); i++)
692 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], 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], regs[i].r, regs[i].len);
724 static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
726 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
727 struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
728 struct em28xx *dev = i2c_bus->dev;
729 #ifdef CONFIG_GPIOLIB
730 struct em28xx_dvb *dvb = dev->dvb;
735 flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
737 flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
739 ret = gpio_request_one(dvb->lna_gpio, flags, NULL);
741 dev_err(&dev->intf->dev, "gpio request failed %d\n", ret);
743 gpio_free(dvb->lna_gpio);
747 dev_warn(&dev->intf->dev, "%s: LNA control is disabled (lna=%u)\n",
748 KBUILD_MODNAME, c->lna);
753 static int em28xx_pctv_292e_set_lna(struct dvb_frontend *fe)
755 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
756 struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
757 struct em28xx *dev = i2c_bus->dev;
765 return em28xx_write_reg_bits(dev, EM2874_R80_GPIO_P0_CTRL, lna, 0x01);
768 static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
770 /* Values extracted from a USB trace of the Terratec Windows driver */
771 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
772 static u8 reset[] = { RESET, 0x80 };
773 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
774 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
775 static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
776 static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
777 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
778 static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
779 static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
780 static u8 tuner_go[] = { TUNER_GO, 0x01};
782 mt352_write(fe, clock_config, sizeof(clock_config));
784 mt352_write(fe, reset, sizeof(reset));
785 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
786 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
787 mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
788 mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
789 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
790 mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
791 mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
792 mt352_write(fe, tuner_go, sizeof(tuner_go));
796 static void px_bcud_init(struct em28xx *dev)
817 static struct em28xx_reg_seq gpio[] = {
818 {EM28XX_R06_I2C_CLK, 0x40, 0xff, 300},
819 {EM2874_R80_GPIO_P0_CTRL, 0xfd, 0xff, 60},
820 {EM28XX_R15_RGAIN, 0x20, 0xff, 0},
821 {EM28XX_R16_GGAIN, 0x20, 0xff, 0},
822 {EM28XX_R17_BGAIN, 0x20, 0xff, 0},
823 {EM28XX_R18_ROFFSET, 0x00, 0xff, 0},
824 {EM28XX_R19_GOFFSET, 0x00, 0xff, 0},
825 {EM28XX_R1A_BOFFSET, 0x00, 0xff, 0},
826 {EM28XX_R23_UOFFSET, 0x00, 0xff, 0},
827 {EM28XX_R24_VOFFSET, 0x00, 0xff, 0},
828 {EM28XX_R26_COMPR, 0x00, 0xff, 0},
829 {0x13, 0x08, 0xff, 0},
830 {EM28XX_R12_VINENABLE, 0x27, 0xff, 0},
831 {EM28XX_R0C_USBSUSP, 0x10, 0xff, 0},
832 {EM28XX_R27_OUTFMT, 0x00, 0xff, 0},
833 {EM28XX_R10_VINMODE, 0x00, 0xff, 0},
834 {EM28XX_R11_VINCTRL, 0x11, 0xff, 0},
835 {EM2874_R50_IR_CONFIG, 0x01, 0xff, 0},
836 {EM2874_R5F_TS_ENABLE, 0x80, 0xff, 0},
837 {EM28XX_R06_I2C_CLK, 0x46, 0xff, 0},
839 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x46);
840 /* sleeping ISDB-T */
841 dev->dvb->i2c_client_demod->addr = 0x14;
842 for (i = 0; i < ARRAY_SIZE(regs1); i++)
843 i2c_master_send(dev->dvb->i2c_client_demod, regs1[i].r,
845 /* sleeping ISDB-S */
846 dev->dvb->i2c_client_demod->addr = 0x15;
847 for (i = 0; i < ARRAY_SIZE(regs2); i++)
848 i2c_master_send(dev->dvb->i2c_client_demod, regs2[i].r,
850 for (i = 0; i < ARRAY_SIZE(gpio); i++) {
851 em28xx_write_reg_bits(dev, gpio[i].reg, gpio[i].val,
853 if (gpio[i].sleep > 0)
854 msleep(gpio[i].sleep);
858 static struct mt352_config terratec_xs_mt352_cfg = {
859 .demod_address = (0x1e >> 1),
862 .demod_init = em28xx_mt352_terratec_xs_init,
865 static struct tda10023_config em28xx_tda10023_config = {
866 .demod_address = 0x0c,
870 static struct cxd2820r_config em28xx_cxd2820r_config = {
871 .i2c_address = (0xd8 >> 1),
872 .ts_mode = CXD2820R_TS_SERIAL,
875 static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
876 .output_opt = TDA18271_OUTPUT_LT_OFF,
877 .gate = TDA18271_GATE_DIGITAL,
880 static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
881 .demod_address = (0x1e >> 1),
882 .disable_i2c_gate_ctrl = 1,
887 static struct mt2060_config em28xx_mt2060_config = {
891 static struct qt1010_config em28xx_qt1010_config = {
895 static const struct mb86a20s_config c3tech_duo_mb86a20s_config = {
896 .demod_address = 0x10,
900 static struct tda18271_std_map mb86a20s_tda18271_config = {
901 .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4,
902 .if_lvl = 1, .rfagc_top = 0x37, },
905 static struct tda18271_config c3tech_duo_tda18271_config = {
906 .std_map = &mb86a20s_tda18271_config,
907 .gate = TDA18271_GATE_DIGITAL,
908 .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
911 static struct tda18271_std_map drx_j_std_map = {
912 .atsc_6 = { .if_freq = 5000, .agc_mode = 3, .std = 0, .if_lvl = 1,
913 .rfagc_top = 0x37, },
914 .qam_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3, .if_lvl = 1,
915 .rfagc_top = 0x37, },
918 static struct tda18271_config pinnacle_80e_dvb_config = {
919 .std_map = &drx_j_std_map,
920 .gate = TDA18271_GATE_DIGITAL,
921 .role = TDA18271_MASTER,
924 static struct lgdt3306a_config hauppauge_01595_lgdt3306a_config = {
927 .spectral_inversion = 0,
929 .mpeg_mode = LGDT3306A_MPEG_SERIAL,
930 .tpclk_edge = LGDT3306A_TPCLK_RISING_EDGE,
931 .tpvalid_polarity = LGDT3306A_TP_VALID_HIGH,
935 /* ------------------------------------------------------------------ */
937 static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
939 struct dvb_frontend *fe;
940 struct xc2028_config cfg;
941 struct xc2028_ctrl ctl;
943 memset(&cfg, 0, sizeof(cfg));
944 cfg.i2c_adap = &dev->i2c_adap[dev->def_i2c_bus];
947 memset(&ctl, 0, sizeof(ctl));
948 em28xx_setup_xc3028(dev, &ctl);
951 if (!dev->dvb->fe[0]) {
952 dev_err(&dev->intf->dev,
953 "dvb frontend not attached. Can't attach xc3028\n");
957 fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
959 dev_err(&dev->intf->dev, "xc3028 attach failed\n");
960 dvb_frontend_detach(dev->dvb->fe[0]);
961 dev->dvb->fe[0] = NULL;
965 dev_info(&dev->intf->dev, "xc3028 attached\n");
970 /* ------------------------------------------------------------------ */
972 static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
973 struct em28xx *dev, struct device *device)
976 bool create_rf_connector = false;
978 mutex_init(&dvb->lock);
980 /* register adapter */
981 result = dvb_register_adapter(&dvb->adapter,
982 dev_name(&dev->intf->dev), module,
985 dev_warn(&dev->intf->dev,
986 "dvb_register_adapter failed (errno = %d)\n",
990 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
991 dvb->adapter.mdev = dev->media_dev;
994 /* Ensure all frontends negotiate bus access */
995 dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
997 dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
999 dvb->adapter.priv = &dev->i2c_bus[dev->def_i2c_bus];
1001 /* register frontend */
1002 result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
1004 dev_warn(&dev->intf->dev,
1005 "dvb_register_frontend failed (errno = %d)\n",
1007 goto fail_frontend0;
1010 /* register 2nd frontend */
1012 result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
1014 dev_warn(&dev->intf->dev,
1015 "2nd dvb_register_frontend failed (errno = %d)\n",
1017 goto fail_frontend1;
1021 /* register demux stuff */
1022 dvb->demux.dmx.capabilities =
1023 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
1024 DMX_MEMORY_BASED_FILTERING;
1025 dvb->demux.priv = dvb;
1026 dvb->demux.filternum = 256;
1027 dvb->demux.feednum = 256;
1028 dvb->demux.start_feed = em28xx_start_feed;
1029 dvb->demux.stop_feed = em28xx_stop_feed;
1031 result = dvb_dmx_init(&dvb->demux);
1033 dev_warn(&dev->intf->dev,
1034 "dvb_dmx_init failed (errno = %d)\n",
1039 dvb->dmxdev.filternum = 256;
1040 dvb->dmxdev.demux = &dvb->demux.dmx;
1041 dvb->dmxdev.capabilities = 0;
1042 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
1044 dev_warn(&dev->intf->dev,
1045 "dvb_dmxdev_init failed (errno = %d)\n",
1050 dvb->fe_hw.source = DMX_FRONTEND_0;
1051 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
1053 dev_warn(&dev->intf->dev,
1054 "add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
1059 dvb->fe_mem.source = DMX_MEMORY_FE;
1060 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
1062 dev_warn(&dev->intf->dev,
1063 "add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
1068 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
1070 dev_warn(&dev->intf->dev,
1071 "connect_frontend failed (errno = %d)\n",
1076 /* register network adapter */
1077 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
1079 /* If the analog part won't create RF connectors, DVB will do it */
1080 if (!dev->has_video || (dev->tuner_type == TUNER_ABSENT))
1081 create_rf_connector = true;
1083 result = dvb_create_media_graph(&dvb->adapter, create_rf_connector);
1085 goto fail_create_graph;
1090 dvb_net_release(&dvb->net);
1092 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
1094 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
1096 dvb_dmxdev_release(&dvb->dmxdev);
1098 dvb_dmx_release(&dvb->demux);
1101 dvb_unregister_frontend(dvb->fe[1]);
1102 dvb_unregister_frontend(dvb->fe[0]);
1105 dvb_frontend_detach(dvb->fe[1]);
1107 dvb_frontend_detach(dvb->fe[0]);
1108 dvb_unregister_adapter(&dvb->adapter);
1113 static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
1115 dvb_net_release(&dvb->net);
1116 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
1117 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
1118 dvb_dmxdev_release(&dvb->dmxdev);
1119 dvb_dmx_release(&dvb->demux);
1121 dvb_unregister_frontend(dvb->fe[1]);
1122 dvb_unregister_frontend(dvb->fe[0]);
1123 if (dvb->fe[1] && !dvb->dont_attach_fe1)
1124 dvb_frontend_detach(dvb->fe[1]);
1125 dvb_frontend_detach(dvb->fe[0]);
1126 dvb_unregister_adapter(&dvb->adapter);
1129 static int em28xx_dvb_init(struct em28xx *dev)
1132 struct em28xx_dvb *dvb;
1134 if (dev->is_audio_only) {
1135 /* Shouldn't initialize IR for this interface */
1139 if (!dev->board.has_dvb) {
1140 /* This device does not support the extension */
1144 dev_info(&dev->intf->dev, "Binding DVB extension\n");
1146 dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
1151 dvb->fe[0] = dvb->fe[1] = NULL;
1153 /* pre-allocate DVB usb transfer buffers */
1154 if (dev->dvb_xfer_bulk) {
1155 result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
1157 EM28XX_DVB_NUM_BUFS,
1159 EM28XX_DVB_BULK_PACKET_MULTIPLIER);
1161 result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
1163 EM28XX_DVB_NUM_BUFS,
1164 dev->dvb_max_pkt_size_isoc,
1165 EM28XX_DVB_NUM_ISOC_PACKETS);
1168 dev_err(&dev->intf->dev,
1169 "failed to pre-allocate USB transfer buffers for DVB.\n");
1175 mutex_lock(&dev->lock);
1176 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
1178 switch (dev->model) {
1179 case EM2874_BOARD_LEADERSHIP_ISDBT:
1180 dvb->fe[0] = dvb_attach(s921_attach,
1181 &sharp_isdbt, &dev->i2c_adap[dev->def_i2c_bus]);
1189 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
1190 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
1191 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
1192 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
1193 dvb->fe[0] = dvb_attach(lgdt330x_attach,
1194 &em2880_lgdt3303_dev,
1195 &dev->i2c_adap[dev->def_i2c_bus]);
1196 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1201 case EM2880_BOARD_KWORLD_DVB_310U:
1202 dvb->fe[0] = dvb_attach(zl10353_attach,
1203 &em28xx_zl10353_with_xc3028,
1204 &dev->i2c_adap[dev->def_i2c_bus]);
1205 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1210 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
1211 case EM2882_BOARD_TERRATEC_HYBRID_XS:
1212 case EM2880_BOARD_EMPIRE_DUAL_TV:
1213 dvb->fe[0] = dvb_attach(zl10353_attach,
1214 &em28xx_zl10353_xc3028_no_i2c_gate,
1215 &dev->i2c_adap[dev->def_i2c_bus]);
1216 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1221 case EM2880_BOARD_TERRATEC_HYBRID_XS:
1222 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
1223 case EM2881_BOARD_PINNACLE_HYBRID_PRO:
1224 case EM2882_BOARD_DIKOM_DK300:
1225 case EM2882_BOARD_KWORLD_VS_DVBT:
1226 dvb->fe[0] = dvb_attach(zl10353_attach,
1227 &em28xx_zl10353_xc3028_no_i2c_gate,
1228 &dev->i2c_adap[dev->def_i2c_bus]);
1229 if (dvb->fe[0] == NULL) {
1230 /* This board could have either a zl10353 or a mt352.
1231 If the chip id isn't for zl10353, try mt352 */
1232 dvb->fe[0] = dvb_attach(mt352_attach,
1233 &terratec_xs_mt352_cfg,
1234 &dev->i2c_adap[dev->def_i2c_bus]);
1237 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1242 case EM2870_BOARD_TERRATEC_XS_MT2060:
1243 dvb->fe[0] = dvb_attach(zl10353_attach,
1244 &em28xx_zl10353_no_i2c_gate_dev,
1245 &dev->i2c_adap[dev->def_i2c_bus]);
1246 if (dvb->fe[0] != NULL) {
1247 dvb_attach(mt2060_attach, dvb->fe[0],
1248 &dev->i2c_adap[dev->def_i2c_bus],
1249 &em28xx_mt2060_config, 1220);
1252 case EM2870_BOARD_KWORLD_355U:
1253 dvb->fe[0] = dvb_attach(zl10353_attach,
1254 &em28xx_zl10353_no_i2c_gate_dev,
1255 &dev->i2c_adap[dev->def_i2c_bus]);
1256 if (dvb->fe[0] != NULL)
1257 dvb_attach(qt1010_attach, dvb->fe[0],
1258 &dev->i2c_adap[dev->def_i2c_bus], &em28xx_qt1010_config);
1260 case EM2883_BOARD_KWORLD_HYBRID_330U:
1261 case EM2882_BOARD_EVGA_INDTUBE:
1262 dvb->fe[0] = dvb_attach(s5h1409_attach,
1263 &em28xx_s5h1409_with_xc3028,
1264 &dev->i2c_adap[dev->def_i2c_bus]);
1265 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1270 case EM2882_BOARD_KWORLD_ATSC_315U:
1271 dvb->fe[0] = dvb_attach(lgdt330x_attach,
1272 &em2880_lgdt3303_dev,
1273 &dev->i2c_adap[dev->def_i2c_bus]);
1274 if (dvb->fe[0] != NULL) {
1275 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
1276 &dev->i2c_adap[dev->def_i2c_bus],
1277 0x61, TUNER_THOMSON_DTT761X)) {
1283 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
1284 case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
1285 dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
1286 &dev->i2c_adap[dev->def_i2c_bus],
1288 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1293 case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
1294 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
1295 dvb->fe[0] = dvb_attach(tda10023_attach,
1296 &em28xx_tda10023_config,
1297 &dev->i2c_adap[dev->def_i2c_bus], 0x48);
1299 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
1300 &dev->i2c_adap[dev->def_i2c_bus],
1301 0x60, TUNER_PHILIPS_CU1216L)) {
1307 case EM2870_BOARD_KWORLD_A340:
1308 dvb->fe[0] = dvb_attach(lgdt3305_attach,
1309 &em2870_lgdt3304_dev,
1310 &dev->i2c_adap[dev->def_i2c_bus]);
1315 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1316 &dev->i2c_adap[dev->def_i2c_bus],
1317 &kworld_a340_config)) {
1318 dvb_frontend_detach(dvb->fe[0]);
1323 case EM28174_BOARD_PCTV_290E:
1324 /* set default GPIO0 for LNA, used if GPIOLIB is undefined */
1325 dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O |
1327 dvb->fe[0] = dvb_attach(cxd2820r_attach,
1328 &em28xx_cxd2820r_config,
1329 &dev->i2c_adap[dev->def_i2c_bus],
1332 /* FE 0 attach tuner */
1333 if (!dvb_attach(tda18271_attach,
1336 &dev->i2c_adap[dev->def_i2c_bus],
1337 &em28xx_cxd2820r_tda18271_config)) {
1339 dvb_frontend_detach(dvb->fe[0]);
1344 #ifdef CONFIG_GPIOLIB
1345 /* enable LNA for DVB-T, DVB-T2 and DVB-C */
1346 result = gpio_request_one(dvb->lna_gpio,
1347 GPIOF_OUT_INIT_LOW, NULL);
1349 dev_err(&dev->intf->dev,
1350 "gpio request failed %d\n",
1353 gpio_free(dvb->lna_gpio);
1355 result = 0; /* continue even set LNA fails */
1357 dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
1361 case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
1363 struct xc5000_config cfg;
1365 hauppauge_hvr930c_init(dev);
1367 dvb->fe[0] = dvb_attach(drxk_attach,
1368 &hauppauge_930c_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
1373 /* FIXME: do we need a pll semaphore? */
1374 dvb->fe[0]->sec_priv = dvb;
1375 sema_init(&dvb->pll_mutex, 1);
1376 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1377 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
1380 memset(&cfg, 0, sizeof(cfg));
1381 cfg.i2c_address = 0x61;
1384 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1385 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1386 if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
1391 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1392 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1396 case EM2884_BOARD_TERRATEC_H5:
1397 terratec_h5_init(dev);
1399 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
1404 /* FIXME: do we need a pll semaphore? */
1405 dvb->fe[0]->sec_priv = dvb;
1406 sema_init(&dvb->pll_mutex, 1);
1407 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1408 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
1410 /* Attach tda18271 to DVB-C frontend */
1411 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1412 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1413 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus], 0x60)) {
1417 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1418 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1421 case EM2884_BOARD_C3TECH_DIGITAL_DUO:
1422 dvb->fe[0] = dvb_attach(mb86a20s_attach,
1423 &c3tech_duo_mb86a20s_config,
1424 &dev->i2c_adap[dev->def_i2c_bus]);
1425 if (dvb->fe[0] != NULL)
1426 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1427 &dev->i2c_adap[dev->def_i2c_bus],
1428 &c3tech_duo_tda18271_config);
1430 case EM28174_BOARD_PCTV_460E: {
1431 struct i2c_client *client;
1432 struct i2c_board_info board_info;
1433 struct tda10071_platform_data tda10071_pdata = {};
1434 struct a8293_platform_data a8293_pdata = {};
1436 /* attach demod + tuner combo */
1437 tda10071_pdata.clk = 40444000, /* 40.444 MHz */
1438 tda10071_pdata.i2c_wr_max = 64,
1439 tda10071_pdata.ts_mode = TDA10071_TS_SERIAL,
1440 tda10071_pdata.pll_multiplier = 20,
1441 tda10071_pdata.tuner_i2c_addr = 0x14,
1442 memset(&board_info, 0, sizeof(board_info));
1443 strlcpy(board_info.type, "tda10071_cx24118", I2C_NAME_SIZE);
1444 board_info.addr = 0x55;
1445 board_info.platform_data = &tda10071_pdata;
1446 request_module("tda10071");
1447 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &board_info);
1448 if (client == NULL || client->dev.driver == NULL) {
1452 if (!try_module_get(client->dev.driver->owner)) {
1453 i2c_unregister_device(client);
1457 dvb->fe[0] = tda10071_pdata.get_dvb_frontend(client);
1458 dvb->i2c_client_demod = client;
1461 a8293_pdata.dvb_frontend = dvb->fe[0];
1462 memset(&board_info, 0, sizeof(board_info));
1463 strlcpy(board_info.type, "a8293", I2C_NAME_SIZE);
1464 board_info.addr = 0x08;
1465 board_info.platform_data = &a8293_pdata;
1466 request_module("a8293");
1467 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &board_info);
1468 if (client == NULL || client->dev.driver == NULL) {
1469 module_put(dvb->i2c_client_demod->dev.driver->owner);
1470 i2c_unregister_device(dvb->i2c_client_demod);
1474 if (!try_module_get(client->dev.driver->owner)) {
1475 i2c_unregister_device(client);
1476 module_put(dvb->i2c_client_demod->dev.driver->owner);
1477 i2c_unregister_device(dvb->i2c_client_demod);
1481 dvb->i2c_client_sec = client;
1484 case EM2874_BOARD_DELOCK_61959:
1485 case EM2874_BOARD_MAXMEDIA_UB425_TC:
1486 /* attach demodulator */
1487 dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
1488 &dev->i2c_adap[dev->def_i2c_bus]);
1491 /* disable I2C-gate */
1492 dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
1495 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1496 &dev->i2c_adap[dev->def_i2c_bus],
1497 &em28xx_cxd2820r_tda18271_config)) {
1498 dvb_frontend_detach(dvb->fe[0]);
1504 case EM2884_BOARD_PCTV_510E:
1505 case EM2884_BOARD_PCTV_520E:
1506 pctv_520e_init(dev);
1508 /* attach demodulator */
1509 dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
1510 &dev->i2c_adap[dev->def_i2c_bus]);
1514 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1515 &dev->i2c_adap[dev->def_i2c_bus],
1516 &em28xx_cxd2820r_tda18271_config)) {
1517 dvb_frontend_detach(dvb->fe[0]);
1523 case EM2884_BOARD_ELGATO_EYETV_HYBRID_2008:
1524 case EM2884_BOARD_CINERGY_HTC_STICK:
1525 terratec_htc_stick_init(dev);
1527 /* attach demodulator */
1528 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1529 &dev->i2c_adap[dev->def_i2c_bus]);
1535 /* Attach the demodulator. */
1536 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1537 &dev->i2c_adap[dev->def_i2c_bus],
1538 &em28xx_cxd2820r_tda18271_config)) {
1543 case EM2884_BOARD_TERRATEC_HTC_USB_XS:
1544 terratec_htc_usb_xs_init(dev);
1546 /* attach demodulator */
1547 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1548 &dev->i2c_adap[dev->def_i2c_bus]);
1554 /* Attach the demodulator. */
1555 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1556 &dev->i2c_adap[dev->def_i2c_bus],
1557 &em28xx_cxd2820r_tda18271_config)) {
1562 case EM2874_BOARD_KWORLD_UB435Q_V2:
1563 dvb->fe[0] = dvb_attach(lgdt3305_attach,
1564 &em2874_lgdt3305_dev,
1565 &dev->i2c_adap[dev->def_i2c_bus]);
1571 /* Attach the demodulator. */
1572 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1573 &dev->i2c_adap[dev->def_i2c_bus],
1574 &kworld_ub435q_v2_config)) {
1579 case EM2874_BOARD_KWORLD_UB435Q_V3:
1581 struct i2c_client *client;
1582 struct i2c_adapter *adapter = &dev->i2c_adap[dev->def_i2c_bus];
1583 struct i2c_board_info board_info = {
1586 .platform_data = &kworld_ub435q_v3_config,
1589 dvb->fe[0] = dvb_attach(lgdt3305_attach,
1590 &em2874_lgdt3305_nogate_dev,
1591 &dev->i2c_adap[dev->def_i2c_bus]);
1598 kworld_ub435q_v3_config.fe = dvb->fe[0];
1599 request_module("tda18212");
1600 client = i2c_new_device(adapter, &board_info);
1601 if (client == NULL || client->dev.driver == NULL) {
1602 dvb_frontend_detach(dvb->fe[0]);
1607 if (!try_module_get(client->dev.driver->owner)) {
1608 i2c_unregister_device(client);
1609 dvb_frontend_detach(dvb->fe[0]);
1614 dvb->i2c_client_tuner = client;
1617 case EM2874_BOARD_PCTV_HD_MINI_80E:
1618 dvb->fe[0] = dvb_attach(drx39xxj_attach, &dev->i2c_adap[dev->def_i2c_bus]);
1619 if (dvb->fe[0] != NULL) {
1620 dvb->fe[0] = dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1621 &dev->i2c_adap[dev->def_i2c_bus],
1622 &pinnacle_80e_dvb_config);
1629 case EM28178_BOARD_PCTV_461E: {
1630 struct i2c_client *client;
1631 struct i2c_adapter *i2c_adapter;
1632 struct i2c_board_info board_info;
1633 struct m88ds3103_platform_data m88ds3103_pdata = {};
1634 struct ts2020_config ts2020_config = {};
1635 struct a8293_platform_data a8293_pdata = {};
1638 m88ds3103_pdata.clk = 27000000;
1639 m88ds3103_pdata.i2c_wr_max = 33;
1640 m88ds3103_pdata.ts_mode = M88DS3103_TS_PARALLEL;
1641 m88ds3103_pdata.ts_clk = 16000;
1642 m88ds3103_pdata.ts_clk_pol = 1;
1643 m88ds3103_pdata.agc = 0x99;
1644 memset(&board_info, 0, sizeof(board_info));
1645 strlcpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
1646 board_info.addr = 0x68;
1647 board_info.platform_data = &m88ds3103_pdata;
1648 request_module("m88ds3103");
1649 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &board_info);
1650 if (client == NULL || client->dev.driver == NULL) {
1654 if (!try_module_get(client->dev.driver->owner)) {
1655 i2c_unregister_device(client);
1659 dvb->fe[0] = m88ds3103_pdata.get_dvb_frontend(client);
1660 i2c_adapter = m88ds3103_pdata.get_i2c_adapter(client);
1661 dvb->i2c_client_demod = client;
1664 ts2020_config.fe = dvb->fe[0];
1665 memset(&board_info, 0, sizeof(board_info));
1666 strlcpy(board_info.type, "ts2022", I2C_NAME_SIZE);
1667 board_info.addr = 0x60;
1668 board_info.platform_data = &ts2020_config;
1669 request_module("ts2020");
1670 client = i2c_new_device(i2c_adapter, &board_info);
1671 if (client == NULL || client->dev.driver == NULL) {
1672 module_put(dvb->i2c_client_demod->dev.driver->owner);
1673 i2c_unregister_device(dvb->i2c_client_demod);
1677 if (!try_module_get(client->dev.driver->owner)) {
1678 i2c_unregister_device(client);
1679 module_put(dvb->i2c_client_demod->dev.driver->owner);
1680 i2c_unregister_device(dvb->i2c_client_demod);
1684 dvb->i2c_client_tuner = client;
1685 /* delegate signal strength measurement to tuner */
1686 dvb->fe[0]->ops.read_signal_strength =
1687 dvb->fe[0]->ops.tuner_ops.get_rf_strength;
1690 a8293_pdata.dvb_frontend = dvb->fe[0];
1691 memset(&board_info, 0, sizeof(board_info));
1692 strlcpy(board_info.type, "a8293", I2C_NAME_SIZE);
1693 board_info.addr = 0x08;
1694 board_info.platform_data = &a8293_pdata;
1695 request_module("a8293");
1696 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &board_info);
1697 if (client == NULL || client->dev.driver == NULL) {
1698 module_put(dvb->i2c_client_tuner->dev.driver->owner);
1699 i2c_unregister_device(dvb->i2c_client_tuner);
1700 module_put(dvb->i2c_client_demod->dev.driver->owner);
1701 i2c_unregister_device(dvb->i2c_client_demod);
1705 if (!try_module_get(client->dev.driver->owner)) {
1706 i2c_unregister_device(client);
1707 module_put(dvb->i2c_client_tuner->dev.driver->owner);
1708 i2c_unregister_device(dvb->i2c_client_tuner);
1709 module_put(dvb->i2c_client_demod->dev.driver->owner);
1710 i2c_unregister_device(dvb->i2c_client_demod);
1714 dvb->i2c_client_sec = client;
1717 case EM28178_BOARD_PCTV_292E:
1719 struct i2c_adapter *adapter;
1720 struct i2c_client *client;
1721 struct i2c_board_info info;
1722 struct si2168_config si2168_config;
1723 struct si2157_config si2157_config;
1726 memset(&si2168_config, 0, sizeof(si2168_config));
1727 si2168_config.i2c_adapter = &adapter;
1728 si2168_config.fe = &dvb->fe[0];
1729 si2168_config.ts_mode = SI2168_TS_PARALLEL;
1730 memset(&info, 0, sizeof(struct i2c_board_info));
1731 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
1733 info.platform_data = &si2168_config;
1734 request_module(info.type);
1735 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &info);
1736 if (client == NULL || client->dev.driver == NULL) {
1741 if (!try_module_get(client->dev.driver->owner)) {
1742 i2c_unregister_device(client);
1747 dvb->i2c_client_demod = client;
1750 memset(&si2157_config, 0, sizeof(si2157_config));
1751 si2157_config.fe = dvb->fe[0];
1752 si2157_config.if_port = 1;
1753 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1754 si2157_config.mdev = dev->media_dev;
1756 memset(&info, 0, sizeof(struct i2c_board_info));
1757 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
1759 info.platform_data = &si2157_config;
1760 request_module(info.type);
1761 client = i2c_new_device(adapter, &info);
1762 if (client == NULL || client->dev.driver == NULL) {
1763 module_put(dvb->i2c_client_demod->dev.driver->owner);
1764 i2c_unregister_device(dvb->i2c_client_demod);
1769 if (!try_module_get(client->dev.driver->owner)) {
1770 i2c_unregister_device(client);
1771 module_put(dvb->i2c_client_demod->dev.driver->owner);
1772 i2c_unregister_device(dvb->i2c_client_demod);
1777 dvb->i2c_client_tuner = client;
1778 dvb->fe[0]->ops.set_lna = em28xx_pctv_292e_set_lna;
1781 case EM28178_BOARD_TERRATEC_T2_STICK_HD:
1783 struct i2c_adapter *adapter;
1784 struct i2c_client *client;
1785 struct i2c_board_info info;
1786 struct si2168_config si2168_config;
1787 struct si2157_config si2157_config;
1790 memset(&si2168_config, 0, sizeof(si2168_config));
1791 si2168_config.i2c_adapter = &adapter;
1792 si2168_config.fe = &dvb->fe[0];
1793 si2168_config.ts_mode = SI2168_TS_PARALLEL;
1794 memset(&info, 0, sizeof(struct i2c_board_info));
1795 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
1797 info.platform_data = &si2168_config;
1798 request_module(info.type);
1799 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &info);
1800 if (client == NULL || client->dev.driver == NULL) {
1805 if (!try_module_get(client->dev.driver->owner)) {
1806 i2c_unregister_device(client);
1811 dvb->i2c_client_demod = client;
1814 memset(&si2157_config, 0, sizeof(si2157_config));
1815 si2157_config.fe = dvb->fe[0];
1816 si2157_config.if_port = 0;
1817 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1818 si2157_config.mdev = dev->media_dev;
1820 memset(&info, 0, sizeof(struct i2c_board_info));
1821 strlcpy(info.type, "si2146", I2C_NAME_SIZE);
1823 info.platform_data = &si2157_config;
1824 request_module("si2157");
1825 client = i2c_new_device(adapter, &info);
1826 if (client == NULL || client->dev.driver == NULL) {
1827 module_put(dvb->i2c_client_demod->dev.driver->owner);
1828 i2c_unregister_device(dvb->i2c_client_demod);
1833 if (!try_module_get(client->dev.driver->owner)) {
1834 i2c_unregister_device(client);
1835 module_put(dvb->i2c_client_demod->dev.driver->owner);
1836 i2c_unregister_device(dvb->i2c_client_demod);
1841 dvb->i2c_client_tuner = client;
1845 case EM28178_BOARD_PLEX_PX_BCUD:
1847 struct i2c_client *client;
1848 struct i2c_board_info info;
1849 struct tc90522_config tc90522_config;
1850 struct qm1d1c0042_config qm1d1c0042_config;
1853 memset(&tc90522_config, 0, sizeof(tc90522_config));
1854 memset(&info, 0, sizeof(struct i2c_board_info));
1855 strlcpy(info.type, "tc90522sat", I2C_NAME_SIZE);
1857 info.platform_data = &tc90522_config;
1858 request_module("tc90522");
1859 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &info);
1860 if (client == NULL || client->dev.driver == NULL) {
1864 dvb->i2c_client_demod = client;
1865 if (!try_module_get(client->dev.driver->owner)) {
1866 i2c_unregister_device(client);
1872 memset(&qm1d1c0042_config, 0,
1873 sizeof(qm1d1c0042_config));
1874 qm1d1c0042_config.fe = tc90522_config.fe;
1875 qm1d1c0042_config.lpf = 1;
1876 memset(&info, 0, sizeof(struct i2c_board_info));
1877 strlcpy(info.type, "qm1d1c0042", I2C_NAME_SIZE);
1879 info.platform_data = &qm1d1c0042_config;
1880 request_module(info.type);
1881 client = i2c_new_device(tc90522_config.tuner_i2c,
1883 if (client == NULL || client->dev.driver == NULL) {
1884 module_put(dvb->i2c_client_demod->dev.driver->owner);
1885 i2c_unregister_device(dvb->i2c_client_demod);
1889 dvb->i2c_client_tuner = client;
1890 if (!try_module_get(client->dev.driver->owner)) {
1891 i2c_unregister_device(client);
1892 module_put(dvb->i2c_client_demod->dev.driver->owner);
1893 i2c_unregister_device(dvb->i2c_client_demod);
1897 dvb->fe[0] = tc90522_config.fe;
1901 case EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_DVB:
1903 struct i2c_adapter *adapter;
1904 struct i2c_client *client;
1905 struct i2c_board_info info;
1906 struct si2168_config si2168_config;
1907 struct si2157_config si2157_config;
1910 memset(&si2168_config, 0, sizeof(si2168_config));
1911 si2168_config.i2c_adapter = &adapter;
1912 si2168_config.fe = &dvb->fe[0];
1913 si2168_config.ts_mode = SI2168_TS_SERIAL;
1914 memset(&info, 0, sizeof(struct i2c_board_info));
1915 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
1917 info.platform_data = &si2168_config;
1918 request_module(info.type);
1919 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &info);
1920 if (client == NULL || client->dev.driver == NULL) {
1925 if (!try_module_get(client->dev.driver->owner)) {
1926 i2c_unregister_device(client);
1931 dvb->i2c_client_demod = client;
1934 memset(&si2157_config, 0, sizeof(si2157_config));
1935 si2157_config.fe = dvb->fe[0];
1936 si2157_config.if_port = 1;
1937 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1938 si2157_config.mdev = dev->media_dev;
1940 memset(&info, 0, sizeof(struct i2c_board_info));
1941 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
1943 info.platform_data = &si2157_config;
1944 request_module(info.type);
1945 client = i2c_new_device(adapter, &info);
1946 if (client == NULL || client->dev.driver == NULL) {
1947 module_put(dvb->i2c_client_demod->dev.driver->owner);
1948 i2c_unregister_device(dvb->i2c_client_demod);
1953 if (!try_module_get(client->dev.driver->owner)) {
1954 i2c_unregister_device(client);
1955 module_put(dvb->i2c_client_demod->dev.driver->owner);
1956 i2c_unregister_device(dvb->i2c_client_demod);
1961 dvb->i2c_client_tuner = client;
1965 case EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_01595:
1967 struct i2c_adapter *adapter;
1968 struct i2c_client *client;
1969 struct i2c_board_info info = {};
1970 struct lgdt3306a_config lgdt3306a_config;
1971 struct si2157_config si2157_config = {};
1974 lgdt3306a_config = hauppauge_01595_lgdt3306a_config;
1975 lgdt3306a_config.fe = &dvb->fe[0];
1976 lgdt3306a_config.i2c_adapter = &adapter;
1977 strlcpy(info.type, "lgdt3306a", sizeof(info.type));
1979 info.platform_data = &lgdt3306a_config;
1980 request_module(info.type);
1981 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus],
1983 if (client == NULL || client->dev.driver == NULL) {
1988 if (!try_module_get(client->dev.driver->owner)) {
1989 i2c_unregister_device(client);
1994 dvb->i2c_client_demod = client;
1997 si2157_config.fe = dvb->fe[0];
1998 si2157_config.if_port = 1;
1999 si2157_config.inversion = 1;
2000 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
2001 si2157_config.mdev = dev->media_dev;
2003 memset(&info, 0, sizeof(struct i2c_board_info));
2004 strlcpy(info.type, "si2157", sizeof(info.type));
2006 info.platform_data = &si2157_config;
2007 request_module(info.type);
2009 client = i2c_new_device(adapter, &info);
2010 if (client == NULL || client->dev.driver == NULL) {
2011 module_put(dvb->i2c_client_demod->dev.driver->owner);
2012 i2c_unregister_device(dvb->i2c_client_demod);
2016 if (!try_module_get(client->dev.driver->owner)) {
2017 i2c_unregister_device(client);
2018 module_put(dvb->i2c_client_demod->dev.driver->owner);
2019 i2c_unregister_device(dvb->i2c_client_demod);
2024 dvb->i2c_client_tuner = client;
2028 dev_err(&dev->intf->dev,
2029 "The frontend of your DVB/ATSC card isn't supported yet\n");
2032 if (NULL == dvb->fe[0]) {
2033 dev_err(&dev->intf->dev, "frontend initialization failed\n");
2037 /* define general-purpose callback pointer */
2038 dvb->fe[0]->callback = em28xx_tuner_callback;
2040 dvb->fe[1]->callback = em28xx_tuner_callback;
2042 /* register everything */
2043 result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->intf->dev);
2048 dev_info(&dev->intf->dev, "DVB extension successfully initialized\n");
2050 kref_get(&dev->ref);
2053 em28xx_set_mode(dev, EM28XX_SUSPEND);
2054 mutex_unlock(&dev->lock);
2063 static inline void prevent_sleep(struct dvb_frontend_ops *ops)
2065 ops->set_voltage = NULL;
2067 ops->tuner_ops.sleep = NULL;
2070 static int em28xx_dvb_fini(struct em28xx *dev)
2072 struct em28xx_dvb *dvb;
2073 struct i2c_client *client;
2075 if (dev->is_audio_only) {
2076 /* Shouldn't initialize IR for this interface */
2080 if (!dev->board.has_dvb) {
2081 /* This device does not support the extension */
2088 dev_info(&dev->intf->dev, "Closing DVB extension\n");
2092 em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE);
2094 if (dev->disconnected) {
2095 /* We cannot tell the device to sleep
2096 * once it has been unplugged. */
2098 prevent_sleep(&dvb->fe[0]->ops);
2099 dvb->fe[0]->exit = DVB_FE_DEVICE_REMOVED;
2102 prevent_sleep(&dvb->fe[1]->ops);
2103 dvb->fe[1]->exit = DVB_FE_DEVICE_REMOVED;
2107 /* remove I2C SEC */
2108 client = dvb->i2c_client_sec;
2110 module_put(client->dev.driver->owner);
2111 i2c_unregister_device(client);
2114 /* remove I2C tuner */
2115 client = dvb->i2c_client_tuner;
2117 module_put(client->dev.driver->owner);
2118 i2c_unregister_device(client);
2121 /* remove I2C demod */
2122 client = dvb->i2c_client_demod;
2124 module_put(client->dev.driver->owner);
2125 i2c_unregister_device(client);
2128 em28xx_unregister_dvb(dvb);
2131 kref_put(&dev->ref, em28xx_free_device);
2136 static int em28xx_dvb_suspend(struct em28xx *dev)
2140 if (dev->is_audio_only)
2143 if (!dev->board.has_dvb)
2146 dev_info(&dev->intf->dev, "Suspending DVB extension\n");
2148 struct em28xx_dvb *dvb = dev->dvb;
2151 ret = dvb_frontend_suspend(dvb->fe[0]);
2152 dev_info(&dev->intf->dev, "fe0 suspend %d\n", ret);
2155 dvb_frontend_suspend(dvb->fe[1]);
2156 dev_info(&dev->intf->dev, "fe1 suspend %d\n", ret);
2163 static int em28xx_dvb_resume(struct em28xx *dev)
2167 if (dev->is_audio_only)
2170 if (!dev->board.has_dvb)
2173 dev_info(&dev->intf->dev, "Resuming DVB extension\n");
2175 struct em28xx_dvb *dvb = dev->dvb;
2178 ret = dvb_frontend_resume(dvb->fe[0]);
2179 dev_info(&dev->intf->dev, "fe0 resume %d\n", ret);
2183 ret = dvb_frontend_resume(dvb->fe[1]);
2184 dev_info(&dev->intf->dev, "fe1 resume %d\n", ret);
2191 static struct em28xx_ops dvb_ops = {
2193 .name = "Em28xx dvb Extension",
2194 .init = em28xx_dvb_init,
2195 .fini = em28xx_dvb_fini,
2196 .suspend = em28xx_dvb_suspend,
2197 .resume = em28xx_dvb_resume,
2200 static int __init em28xx_dvb_register(void)
2202 return em28xx_register_extension(&dvb_ops);
2205 static void __exit em28xx_dvb_unregister(void)
2207 em28xx_unregister_extension(&dvb_ops);
2210 module_init(em28xx_dvb_register);
2211 module_exit(em28xx_dvb_unregister);