2 DVB device driver for em28xx
4 (c) 2008-2011 Mauro Carvalho Chehab <mchehab@infradead.org>
6 (c) 2008 Devin Heitmueller <devin.heitmueller@gmail.com>
7 - Fixes for the driver to properly work with HVR-950
8 - Fixes for the driver to properly work with Pinnacle PCTV HD Pro Stick
9 - Fixes for the driver to properly work with AMD ATI TV Wonder HD 600
11 (c) 2008 Aidan Thornton <makosoft@googlemail.com>
13 (c) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
15 Based on cx88-dvb, saa7134-dvb and videobuf-dvb originally written by:
16 (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
17 (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
19 This program is free software; you can redistribute it and/or modify
20 it under the terms of the GNU General Public License as published by
21 the Free Software Foundation; either version 2 of the License.
24 #include <linux/kernel.h>
25 #include <linux/slab.h>
26 #include <linux/usb.h>
29 #include <media/v4l2-common.h>
30 #include <dvb_demux.h>
33 #include <media/tuner.h>
34 #include "tuner-simple.h"
35 #include <linux/gpio.h>
43 #include "mt352_priv.h" /* FIXME */
45 #include "drx39xyj/drx39xxj.h"
50 #include "tda18271c2dd.h"
57 #include "m88ds3103.h"
62 #include "qm1d1c0042.h"
64 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
65 MODULE_LICENSE("GPL");
66 MODULE_DESCRIPTION(DRIVER_DESC " - digital TV interface");
67 MODULE_VERSION(EM28XX_VERSION);
69 static unsigned int debug;
70 module_param(debug, int, 0644);
71 MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
73 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
75 #define dprintk(level, fmt, arg...) do { \
77 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \
81 struct dvb_frontend *fe[2];
83 /* feed count management */
87 /* general boilerplate stuff */
88 struct dvb_adapter adapter;
89 struct dvb_demux demux;
91 struct dmx_frontend fe_hw;
92 struct dmx_frontend fe_mem;
95 /* Due to DRX-K - probably need changes */
96 int (*gate_ctrl)(struct dvb_frontend *, int);
97 struct semaphore pll_mutex;
100 struct i2c_client *i2c_client_demod;
101 struct i2c_client *i2c_client_tuner;
102 struct i2c_client *i2c_client_sec;
105 static inline void print_err_status(struct em28xx *dev,
106 int packet, int status)
108 char *errmsg = "Unknown";
112 errmsg = "unlinked synchronuously";
115 errmsg = "unlinked asynchronuously";
118 errmsg = "Buffer error (overrun)";
121 errmsg = "Stalled (device not responding)";
124 errmsg = "Babble (bad cable?)";
127 errmsg = "Bit-stuff error (bad cable?)";
130 errmsg = "CRC/Timeout (could be anything)";
133 errmsg = "Device does not respond";
137 dprintk(1, "URB status %d [%s].\n", status, errmsg);
139 dprintk(1, "URB packet %d, status %d [%s].\n",
140 packet, status, errmsg);
144 static inline int em28xx_dvb_urb_data_copy(struct em28xx *dev, struct urb *urb)
146 int xfer_bulk, num_packets, i;
151 if (dev->disconnected)
155 print_err_status(dev, -1, urb->status);
157 xfer_bulk = usb_pipebulk(urb->pipe);
159 if (xfer_bulk) /* bulk */
162 num_packets = urb->number_of_packets;
164 for (i = 0; i < num_packets; i++) {
166 if (urb->status < 0) {
167 print_err_status(dev, i, urb->status);
168 if (urb->status != -EPROTO)
171 if (!urb->actual_length)
173 dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer,
176 if (urb->iso_frame_desc[i].status < 0) {
177 print_err_status(dev, i,
178 urb->iso_frame_desc[i].status);
179 if (urb->iso_frame_desc[i].status != -EPROTO)
182 if (!urb->iso_frame_desc[i].actual_length)
184 dvb_dmx_swfilter(&dev->dvb->demux,
185 urb->transfer_buffer +
186 urb->iso_frame_desc[i].offset,
187 urb->iso_frame_desc[i].actual_length);
194 static int em28xx_start_streaming(struct em28xx_dvb *dvb)
197 struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
198 struct em28xx *dev = i2c_bus->dev;
199 int dvb_max_packet_size, packet_multiplier, dvb_alt;
201 if (dev->dvb_xfer_bulk) {
202 if (!dev->dvb_ep_bulk)
204 dvb_max_packet_size = 512; /* USB 2.0 spec */
205 packet_multiplier = EM28XX_DVB_BULK_PACKET_MULTIPLIER;
208 if (!dev->dvb_ep_isoc)
210 dvb_max_packet_size = dev->dvb_max_pkt_size_isoc;
211 if (dvb_max_packet_size < 0)
212 return dvb_max_packet_size;
213 packet_multiplier = EM28XX_DVB_NUM_ISOC_PACKETS;
214 dvb_alt = dev->dvb_alt_isoc;
217 usb_set_interface(dev->udev, dev->ifnum, dvb_alt);
218 rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
222 dprintk(1, "Using %d buffers each with %d x %d bytes, alternate %d\n",
225 dvb_max_packet_size, dvb_alt);
227 return em28xx_init_usb_xfer(dev, EM28XX_DIGITAL_MODE,
232 em28xx_dvb_urb_data_copy);
235 static int em28xx_stop_streaming(struct em28xx_dvb *dvb)
237 struct em28xx_i2c_bus *i2c_bus = dvb->adapter.priv;
238 struct em28xx *dev = i2c_bus->dev;
240 em28xx_stop_urbs(dev);
245 static int em28xx_start_feed(struct dvb_demux_feed *feed)
247 struct dvb_demux *demux = feed->demux;
248 struct em28xx_dvb *dvb = demux->priv;
251 if (!demux->dmx.frontend)
254 mutex_lock(&dvb->lock);
258 if (dvb->nfeeds == 1) {
259 ret = em28xx_start_streaming(dvb);
264 mutex_unlock(&dvb->lock);
268 static int em28xx_stop_feed(struct dvb_demux_feed *feed)
270 struct dvb_demux *demux = feed->demux;
271 struct em28xx_dvb *dvb = demux->priv;
274 mutex_lock(&dvb->lock);
277 if (0 == dvb->nfeeds)
278 err = em28xx_stop_streaming(dvb);
280 mutex_unlock(&dvb->lock);
285 /* ------------------------------------------------------------------ */
286 static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
288 struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
289 struct em28xx *dev = i2c_bus->dev;
292 return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
294 return em28xx_set_mode(dev, EM28XX_SUSPEND);
297 /* ------------------------------------------------------------------ */
299 static struct lgdt330x_config em2880_lgdt3303_dev = {
300 .demod_address = 0x0e,
301 .demod_chip = LGDT3303,
304 static struct lgdt3305_config em2870_lgdt3304_dev = {
306 .demod_chip = LGDT3304,
307 .spectral_inversion = 1,
309 .mpeg_mode = LGDT3305_MPEG_PARALLEL,
310 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
311 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
316 static struct lgdt3305_config em2874_lgdt3305_dev = {
318 .demod_chip = LGDT3305,
319 .spectral_inversion = 1,
321 .mpeg_mode = LGDT3305_MPEG_SERIAL,
322 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
323 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
328 static struct lgdt3305_config em2874_lgdt3305_nogate_dev = {
330 .demod_chip = LGDT3305,
331 .spectral_inversion = 1,
333 .mpeg_mode = LGDT3305_MPEG_SERIAL,
334 .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE,
335 .tpvalid_polarity = LGDT3305_TP_VALID_HIGH,
340 static struct s921_config sharp_isdbt = {
341 .demod_address = 0x30 >> 1
344 static struct zl10353_config em28xx_zl10353_with_xc3028 = {
345 .demod_address = (0x1e >> 1),
351 static struct s5h1409_config em28xx_s5h1409_with_xc3028 = {
352 .demod_address = 0x32 >> 1,
353 .output_mode = S5H1409_PARALLEL_OUTPUT,
354 .gpio = S5H1409_GPIO_OFF,
355 .inversion = S5H1409_INVERSION_OFF,
356 .status_mode = S5H1409_DEMODLOCKING,
357 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
360 static struct tda18271_std_map kworld_a340_std_map = {
361 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
362 .if_lvl = 1, .rfagc_top = 0x37, },
363 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
364 .if_lvl = 1, .rfagc_top = 0x37, },
367 static struct tda18271_config kworld_a340_config = {
368 .std_map = &kworld_a340_std_map,
371 static struct tda18271_config kworld_ub435q_v2_config = {
372 .std_map = &kworld_a340_std_map,
373 .gate = TDA18271_GATE_DIGITAL,
376 static struct tda18212_config kworld_ub435q_v3_config = {
381 static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
382 .demod_address = (0x1e >> 1),
384 .disable_i2c_gate_ctrl = 1,
389 static struct drxd_config em28xx_drxd = {
390 .demod_address = 0x70,
391 .demod_revision = 0xa2,
392 .pll_type = DRXD_PLL_NONE,
396 .disable_i2c_gate_ctrl = 1,
399 static struct drxk_config terratec_h5_drxk = {
403 .microcode_name = "dvb-usb-terratec-h5-drxk.fw",
404 .qam_demod_parameter_count = 2,
407 static struct drxk_config hauppauge_930c_drxk = {
411 .microcode_name = "dvb-usb-hauppauge-hvr930c-drxk.fw",
413 .qam_demod_parameter_count = 2,
416 static struct drxk_config terratec_htc_stick_drxk = {
420 .microcode_name = "dvb-usb-terratec-htc-stick-drxk.fw",
422 .qam_demod_parameter_count = 2,
423 /* Required for the antenna_gpio to disable LNA. */
424 .antenna_dvbt = true,
425 /* The windows driver uses the same. This will disable LNA. */
429 static struct drxk_config maxmedia_ub425_tc_drxk = {
433 .microcode_name = "dvb-demod-drxk-01.fw",
435 .qam_demod_parameter_count = 2,
438 static struct drxk_config pctv_520e_drxk = {
441 .microcode_name = "dvb-demod-drxk-pctv.fw",
442 .qam_demod_parameter_count = 2,
444 .antenna_dvbt = true, /* disable LNA */
445 .antenna_gpio = (1 << 2), /* disable LNA */
448 static int drxk_gate_ctrl(struct dvb_frontend *fe, int enable)
450 struct em28xx_dvb *dvb = fe->sec_priv;
457 down(&dvb->pll_mutex);
458 status = dvb->gate_ctrl(fe, 1);
460 status = dvb->gate_ctrl(fe, 0);
466 static void hauppauge_hvr930c_init(struct em28xx *dev)
470 struct em28xx_reg_seq hauppauge_hvr930c_init[] = {
471 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0x65},
472 {EM2874_R80_GPIO_P0_CTRL, 0xfb, 0xff, 0x32},
473 {EM2874_R80_GPIO_P0_CTRL, 0xff, 0xff, 0xb8},
476 struct em28xx_reg_seq hauppauge_hvr930c_end[] = {
477 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
478 {EM2874_R80_GPIO_P0_CTRL, 0xaf, 0xff, 0x65},
479 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x76},
480 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x01},
481 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
482 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x40},
484 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x65},
485 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
486 {EM2874_R80_GPIO_P0_CTRL, 0xcf, 0xff, 0x0b},
487 {EM2874_R80_GPIO_P0_CTRL, 0xef, 0xff, 0x65},
496 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
498 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
500 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
501 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
503 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
506 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
508 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
511 em28xx_gpio_set(dev, hauppauge_hvr930c_init);
512 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
514 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
517 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
519 for (i = 0; i < ARRAY_SIZE(regs); i++)
520 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
521 em28xx_gpio_set(dev, hauppauge_hvr930c_end);
525 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
528 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
533 static void terratec_h5_init(struct em28xx *dev)
536 struct em28xx_reg_seq terratec_h5_init[] = {
537 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
538 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
539 {EM2874_R80_GPIO_P0_CTRL, 0xf2, 0xff, 50},
540 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
543 struct em28xx_reg_seq terratec_h5_end[] = {
544 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
545 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
546 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
553 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
555 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
557 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
558 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
560 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
563 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
565 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
568 em28xx_gpio_set(dev, terratec_h5_init);
569 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
571 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x45);
574 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
576 for (i = 0; i < ARRAY_SIZE(regs); i++)
577 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
578 em28xx_gpio_set(dev, terratec_h5_end);
581 static void terratec_htc_stick_init(struct em28xx *dev)
586 * GPIO configuration:
587 * 0xff: unknown (does not affect DVB-T).
588 * 0xf6: DRX-K (demodulator).
589 * 0xe6: unknown (does not affect DVB-T).
590 * 0xb6: unknown (does not affect DVB-T).
592 struct em28xx_reg_seq terratec_htc_stick_init[] = {
593 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
594 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
595 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 50},
596 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 100},
599 struct em28xx_reg_seq terratec_htc_stick_end[] = {
600 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
601 {EM2874_R80_GPIO_P0_CTRL, 0xf6, 0xff, 50},
606 * Init the analog decoder (not yet supported), but
607 * it's probably still a good idea.
613 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
615 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
617 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
620 em28xx_gpio_set(dev, terratec_htc_stick_init);
622 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
624 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
627 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
629 for (i = 0; i < ARRAY_SIZE(regs); i++)
630 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
632 em28xx_gpio_set(dev, terratec_htc_stick_end);
635 static void terratec_htc_usb_xs_init(struct em28xx *dev)
639 struct em28xx_reg_seq terratec_htc_usb_xs_init[] = {
640 {EM2820_R08_GPIO_CTRL, 0xff, 0xff, 10},
641 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 100},
642 {EM2874_R80_GPIO_P0_CTRL, 0xb2, 0xff, 50},
643 {EM2874_R80_GPIO_P0_CTRL, 0xb6, 0xff, 100},
646 struct em28xx_reg_seq terratec_htc_usb_xs_end[] = {
647 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 100},
648 {EM2874_R80_GPIO_P0_CTRL, 0xa6, 0xff, 50},
649 {EM2874_R80_GPIO_P0_CTRL, 0xe6, 0xff, 100},
654 * Init the analog decoder (not yet supported), but
655 * it's probably still a good idea.
661 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
663 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
665 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
666 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
668 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
671 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
673 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
676 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
678 em28xx_gpio_set(dev, terratec_htc_usb_xs_init);
680 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x40);
682 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x44);
685 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1;
687 for (i = 0; i < ARRAY_SIZE(regs); i++)
688 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
690 em28xx_gpio_set(dev, terratec_htc_usb_xs_end);
693 static void pctv_520e_init(struct em28xx *dev)
696 * Init AVF4910B analog decoder. Looks like I2C traffic to
697 * digital demodulator and tuner are routed via AVF4910B.
704 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
706 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
708 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
709 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
711 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
714 dev->i2c_client[dev->def_i2c_bus].addr = 0x82 >> 1; /* 0x41 */
716 for (i = 0; i < ARRAY_SIZE(regs); i++)
717 i2c_master_send(&dev->i2c_client[dev->def_i2c_bus], regs[i].r, regs[i].len);
720 static int em28xx_pctv_290e_set_lna(struct dvb_frontend *fe)
722 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
723 struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
724 struct em28xx *dev = i2c_bus->dev;
725 #ifdef CONFIG_GPIOLIB
726 struct em28xx_dvb *dvb = dev->dvb;
731 flags = GPIOF_OUT_INIT_HIGH; /* enable LNA */
733 flags = GPIOF_OUT_INIT_LOW; /* disable LNA */
735 ret = gpio_request_one(dvb->lna_gpio, flags, NULL);
737 em28xx_errdev("gpio request failed %d\n", ret);
739 gpio_free(dvb->lna_gpio);
743 dev_warn(&dev->udev->dev, "%s: LNA control is disabled (lna=%u)\n",
744 KBUILD_MODNAME, c->lna);
749 static int em28xx_pctv_292e_set_lna(struct dvb_frontend *fe)
751 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
752 struct em28xx_i2c_bus *i2c_bus = fe->dvb->priv;
753 struct em28xx *dev = i2c_bus->dev;
761 return em28xx_write_reg_bits(dev, EM2874_R80_GPIO_P0_CTRL, lna, 0x01);
764 static int em28xx_mt352_terratec_xs_init(struct dvb_frontend *fe)
766 /* Values extracted from a USB trace of the Terratec Windows driver */
767 static u8 clock_config[] = { CLOCK_CTL, 0x38, 0x2c };
768 static u8 reset[] = { RESET, 0x80 };
769 static u8 adc_ctl_1_cfg[] = { ADC_CTL_1, 0x40 };
770 static u8 agc_cfg[] = { AGC_TARGET, 0x28, 0xa0 };
771 static u8 input_freq_cfg[] = { INPUT_FREQ_1, 0x31, 0xb8 };
772 static u8 rs_err_cfg[] = { RS_ERR_PER_1, 0x00, 0x4d };
773 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x32 };
774 static u8 trl_nom_cfg[] = { TRL_NOMINAL_RATE_1, 0x64, 0x00 };
775 static u8 tps_given_cfg[] = { TPS_GIVEN_1, 0x40, 0x80, 0x50 };
776 static u8 tuner_go[] = { TUNER_GO, 0x01};
778 mt352_write(fe, clock_config, sizeof(clock_config));
780 mt352_write(fe, reset, sizeof(reset));
781 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
782 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
783 mt352_write(fe, input_freq_cfg, sizeof(input_freq_cfg));
784 mt352_write(fe, rs_err_cfg, sizeof(rs_err_cfg));
785 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
786 mt352_write(fe, trl_nom_cfg, sizeof(trl_nom_cfg));
787 mt352_write(fe, tps_given_cfg, sizeof(tps_given_cfg));
788 mt352_write(fe, tuner_go, sizeof(tuner_go));
792 static void px_bcud_init(struct em28xx *dev)
813 static struct em28xx_reg_seq gpio[] = {
814 {EM28XX_R06_I2C_CLK, 0x40, 0xff, 300},
815 {EM2874_R80_GPIO_P0_CTRL, 0xfd, 0xff, 60},
816 {EM28XX_R15_RGAIN, 0x20, 0xff, 0},
817 {EM28XX_R16_GGAIN, 0x20, 0xff, 0},
818 {EM28XX_R17_BGAIN, 0x20, 0xff, 0},
819 {EM28XX_R18_ROFFSET, 0x00, 0xff, 0},
820 {EM28XX_R19_GOFFSET, 0x00, 0xff, 0},
821 {EM28XX_R1A_BOFFSET, 0x00, 0xff, 0},
822 {EM28XX_R23_UOFFSET, 0x00, 0xff, 0},
823 {EM28XX_R24_VOFFSET, 0x00, 0xff, 0},
824 {EM28XX_R26_COMPR, 0x00, 0xff, 0},
825 {0x13, 0x08, 0xff, 0},
826 {EM28XX_R12_VINENABLE, 0x27, 0xff, 0},
827 {EM28XX_R0C_USBSUSP, 0x10, 0xff, 0},
828 {EM28XX_R27_OUTFMT, 0x00, 0xff, 0},
829 {EM28XX_R10_VINMODE, 0x00, 0xff, 0},
830 {EM28XX_R11_VINCTRL, 0x11, 0xff, 0},
831 {EM2874_R50_IR_CONFIG, 0x01, 0xff, 0},
832 {EM2874_R5F_TS_ENABLE, 0x80, 0xff, 0},
833 {EM28XX_R06_I2C_CLK, 0x46, 0xff, 0},
835 em28xx_write_reg(dev, EM28XX_R06_I2C_CLK, 0x46);
836 /* sleeping ISDB-T */
837 dev->dvb->i2c_client_demod->addr = 0x14;
838 for (i = 0; i < ARRAY_SIZE(regs1); i++)
839 i2c_master_send(dev->dvb->i2c_client_demod, regs1[i].r,
841 /* sleeping ISDB-S */
842 dev->dvb->i2c_client_demod->addr = 0x15;
843 for (i = 0; i < ARRAY_SIZE(regs2); i++)
844 i2c_master_send(dev->dvb->i2c_client_demod, regs2[i].r,
846 for (i = 0; i < ARRAY_SIZE(gpio); i++) {
847 em28xx_write_reg_bits(dev, gpio[i].reg, gpio[i].val,
849 if (gpio[i].sleep > 0)
850 msleep(gpio[i].sleep);
854 static struct mt352_config terratec_xs_mt352_cfg = {
855 .demod_address = (0x1e >> 1),
858 .demod_init = em28xx_mt352_terratec_xs_init,
861 static struct tda10023_config em28xx_tda10023_config = {
862 .demod_address = 0x0c,
866 static struct cxd2820r_config em28xx_cxd2820r_config = {
867 .i2c_address = (0xd8 >> 1),
868 .ts_mode = CXD2820R_TS_SERIAL,
871 static struct tda18271_config em28xx_cxd2820r_tda18271_config = {
872 .output_opt = TDA18271_OUTPUT_LT_OFF,
873 .gate = TDA18271_GATE_DIGITAL,
876 static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev = {
877 .demod_address = (0x1e >> 1),
878 .disable_i2c_gate_ctrl = 1,
883 static struct mt2060_config em28xx_mt2060_config = {
887 static struct qt1010_config em28xx_qt1010_config = {
891 static const struct mb86a20s_config c3tech_duo_mb86a20s_config = {
892 .demod_address = 0x10,
896 static struct tda18271_std_map mb86a20s_tda18271_config = {
897 .dvbt_6 = { .if_freq = 4000, .agc_mode = 3, .std = 4,
898 .if_lvl = 1, .rfagc_top = 0x37, },
901 static struct tda18271_config c3tech_duo_tda18271_config = {
902 .std_map = &mb86a20s_tda18271_config,
903 .gate = TDA18271_GATE_DIGITAL,
904 .small_i2c = TDA18271_03_BYTE_CHUNK_INIT,
907 static const struct m88ds3103_config pctv_461e_m88ds3103_config = {
912 .ts_mode = M88DS3103_TS_PARALLEL,
918 static struct tda18271_std_map drx_j_std_map = {
919 .atsc_6 = { .if_freq = 5000, .agc_mode = 3, .std = 0, .if_lvl = 1,
920 .rfagc_top = 0x37, },
921 .qam_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3, .if_lvl = 1,
922 .rfagc_top = 0x37, },
925 static struct tda18271_config pinnacle_80e_dvb_config = {
926 .std_map = &drx_j_std_map,
927 .gate = TDA18271_GATE_DIGITAL,
928 .role = TDA18271_MASTER,
931 /* ------------------------------------------------------------------ */
933 static int em28xx_attach_xc3028(u8 addr, struct em28xx *dev)
935 struct dvb_frontend *fe;
936 struct xc2028_config cfg;
937 struct xc2028_ctrl ctl;
939 memset(&cfg, 0, sizeof(cfg));
940 cfg.i2c_adap = &dev->i2c_adap[dev->def_i2c_bus];
943 memset(&ctl, 0, sizeof(ctl));
944 em28xx_setup_xc3028(dev, &ctl);
947 if (!dev->dvb->fe[0]) {
948 em28xx_errdev("/2: dvb frontend not attached. "
949 "Can't attach xc3028\n");
953 fe = dvb_attach(xc2028_attach, dev->dvb->fe[0], &cfg);
955 em28xx_errdev("/2: xc3028 attach failed\n");
956 dvb_frontend_detach(dev->dvb->fe[0]);
957 dev->dvb->fe[0] = NULL;
961 em28xx_info("%s/2: xc3028 attached\n", dev->name);
966 /* ------------------------------------------------------------------ */
968 static int em28xx_register_dvb(struct em28xx_dvb *dvb, struct module *module,
969 struct em28xx *dev, struct device *device)
972 bool create_rf_connector = false;
974 mutex_init(&dvb->lock);
976 /* register adapter */
977 result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
980 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
984 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
985 dvb->adapter.mdev = dev->media_dev;
988 /* Ensure all frontends negotiate bus access */
989 dvb->fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
991 dvb->fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
993 dvb->adapter.priv = &dev->i2c_bus[dev->def_i2c_bus];
995 /* register frontend */
996 result = dvb_register_frontend(&dvb->adapter, dvb->fe[0]);
998 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
1000 goto fail_frontend0;
1003 /* register 2nd frontend */
1005 result = dvb_register_frontend(&dvb->adapter, dvb->fe[1]);
1007 printk(KERN_WARNING "%s: 2nd dvb_register_frontend failed (errno = %d)\n",
1009 goto fail_frontend1;
1013 /* register demux stuff */
1014 dvb->demux.dmx.capabilities =
1015 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
1016 DMX_MEMORY_BASED_FILTERING;
1017 dvb->demux.priv = dvb;
1018 dvb->demux.filternum = 256;
1019 dvb->demux.feednum = 256;
1020 dvb->demux.start_feed = em28xx_start_feed;
1021 dvb->demux.stop_feed = em28xx_stop_feed;
1023 result = dvb_dmx_init(&dvb->demux);
1025 printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
1030 dvb->dmxdev.filternum = 256;
1031 dvb->dmxdev.demux = &dvb->demux.dmx;
1032 dvb->dmxdev.capabilities = 0;
1033 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
1035 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
1040 dvb->fe_hw.source = DMX_FRONTEND_0;
1041 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
1043 printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
1048 dvb->fe_mem.source = DMX_MEMORY_FE;
1049 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
1051 printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
1056 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
1058 printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
1063 /* register network adapter */
1064 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
1066 /* If the analog part won't create RF connectors, DVB will do it */
1067 if (!dev->has_video || (dev->tuner_type == TUNER_ABSENT))
1068 create_rf_connector = true;
1070 result = dvb_create_media_graph(&dvb->adapter, create_rf_connector);
1072 goto fail_create_graph;
1077 dvb_net_release(&dvb->net);
1079 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
1081 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
1083 dvb_dmxdev_release(&dvb->dmxdev);
1085 dvb_dmx_release(&dvb->demux);
1088 dvb_unregister_frontend(dvb->fe[1]);
1089 dvb_unregister_frontend(dvb->fe[0]);
1092 dvb_frontend_detach(dvb->fe[1]);
1094 dvb_frontend_detach(dvb->fe[0]);
1095 dvb_unregister_adapter(&dvb->adapter);
1100 static void em28xx_unregister_dvb(struct em28xx_dvb *dvb)
1102 dvb_net_release(&dvb->net);
1103 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
1104 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
1105 dvb_dmxdev_release(&dvb->dmxdev);
1106 dvb_dmx_release(&dvb->demux);
1108 dvb_unregister_frontend(dvb->fe[1]);
1109 dvb_unregister_frontend(dvb->fe[0]);
1110 if (dvb->fe[1] && !dvb->dont_attach_fe1)
1111 dvb_frontend_detach(dvb->fe[1]);
1112 dvb_frontend_detach(dvb->fe[0]);
1113 dvb_unregister_adapter(&dvb->adapter);
1116 static int em28xx_dvb_init(struct em28xx *dev)
1119 struct em28xx_dvb *dvb;
1121 if (dev->is_audio_only) {
1122 /* Shouldn't initialize IR for this interface */
1126 if (!dev->board.has_dvb) {
1127 /* This device does not support the extension */
1131 em28xx_info("Binding DVB extension\n");
1133 dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
1135 em28xx_info("em28xx_dvb: memory allocation failed\n");
1139 dvb->fe[0] = dvb->fe[1] = NULL;
1141 /* pre-allocate DVB usb transfer buffers */
1142 if (dev->dvb_xfer_bulk) {
1143 result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
1145 EM28XX_DVB_NUM_BUFS,
1147 EM28XX_DVB_BULK_PACKET_MULTIPLIER);
1149 result = em28xx_alloc_urbs(dev, EM28XX_DIGITAL_MODE,
1151 EM28XX_DVB_NUM_BUFS,
1152 dev->dvb_max_pkt_size_isoc,
1153 EM28XX_DVB_NUM_ISOC_PACKETS);
1156 em28xx_errdev("em28xx_dvb: failed to pre-allocate USB transfer buffers for DVB.\n");
1162 mutex_lock(&dev->lock);
1163 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
1165 switch (dev->model) {
1166 case EM2874_BOARD_LEADERSHIP_ISDBT:
1167 dvb->fe[0] = dvb_attach(s921_attach,
1168 &sharp_isdbt, &dev->i2c_adap[dev->def_i2c_bus]);
1176 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850:
1177 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
1178 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
1179 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
1180 dvb->fe[0] = dvb_attach(lgdt330x_attach,
1181 &em2880_lgdt3303_dev,
1182 &dev->i2c_adap[dev->def_i2c_bus]);
1183 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1188 case EM2880_BOARD_KWORLD_DVB_310U:
1189 dvb->fe[0] = dvb_attach(zl10353_attach,
1190 &em28xx_zl10353_with_xc3028,
1191 &dev->i2c_adap[dev->def_i2c_bus]);
1192 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1197 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
1198 case EM2882_BOARD_TERRATEC_HYBRID_XS:
1199 case EM2880_BOARD_EMPIRE_DUAL_TV:
1200 dvb->fe[0] = dvb_attach(zl10353_attach,
1201 &em28xx_zl10353_xc3028_no_i2c_gate,
1202 &dev->i2c_adap[dev->def_i2c_bus]);
1203 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1208 case EM2880_BOARD_TERRATEC_HYBRID_XS:
1209 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
1210 case EM2881_BOARD_PINNACLE_HYBRID_PRO:
1211 case EM2882_BOARD_DIKOM_DK300:
1212 case EM2882_BOARD_KWORLD_VS_DVBT:
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 (dvb->fe[0] == NULL) {
1217 /* This board could have either a zl10353 or a mt352.
1218 If the chip id isn't for zl10353, try mt352 */
1219 dvb->fe[0] = dvb_attach(mt352_attach,
1220 &terratec_xs_mt352_cfg,
1221 &dev->i2c_adap[dev->def_i2c_bus]);
1224 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1229 case EM2870_BOARD_TERRATEC_XS_MT2060:
1230 dvb->fe[0] = dvb_attach(zl10353_attach,
1231 &em28xx_zl10353_no_i2c_gate_dev,
1232 &dev->i2c_adap[dev->def_i2c_bus]);
1233 if (dvb->fe[0] != NULL) {
1234 dvb_attach(mt2060_attach, dvb->fe[0],
1235 &dev->i2c_adap[dev->def_i2c_bus],
1236 &em28xx_mt2060_config, 1220);
1239 case EM2870_BOARD_KWORLD_355U:
1240 dvb->fe[0] = dvb_attach(zl10353_attach,
1241 &em28xx_zl10353_no_i2c_gate_dev,
1242 &dev->i2c_adap[dev->def_i2c_bus]);
1243 if (dvb->fe[0] != NULL)
1244 dvb_attach(qt1010_attach, dvb->fe[0],
1245 &dev->i2c_adap[dev->def_i2c_bus], &em28xx_qt1010_config);
1247 case EM2883_BOARD_KWORLD_HYBRID_330U:
1248 case EM2882_BOARD_EVGA_INDTUBE:
1249 dvb->fe[0] = dvb_attach(s5h1409_attach,
1250 &em28xx_s5h1409_with_xc3028,
1251 &dev->i2c_adap[dev->def_i2c_bus]);
1252 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1257 case EM2882_BOARD_KWORLD_ATSC_315U:
1258 dvb->fe[0] = dvb_attach(lgdt330x_attach,
1259 &em2880_lgdt3303_dev,
1260 &dev->i2c_adap[dev->def_i2c_bus]);
1261 if (dvb->fe[0] != NULL) {
1262 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
1263 &dev->i2c_adap[dev->def_i2c_bus],
1264 0x61, TUNER_THOMSON_DTT761X)) {
1270 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
1271 case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E:
1272 dvb->fe[0] = dvb_attach(drxd_attach, &em28xx_drxd, NULL,
1273 &dev->i2c_adap[dev->def_i2c_bus], &dev->udev->dev);
1274 if (em28xx_attach_xc3028(0x61, dev) < 0) {
1279 case EM2870_BOARD_REDDO_DVB_C_USB_BOX:
1280 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
1281 dvb->fe[0] = dvb_attach(tda10023_attach,
1282 &em28xx_tda10023_config,
1283 &dev->i2c_adap[dev->def_i2c_bus], 0x48);
1285 if (!dvb_attach(simple_tuner_attach, dvb->fe[0],
1286 &dev->i2c_adap[dev->def_i2c_bus],
1287 0x60, TUNER_PHILIPS_CU1216L)) {
1293 case EM2870_BOARD_KWORLD_A340:
1294 dvb->fe[0] = dvb_attach(lgdt3305_attach,
1295 &em2870_lgdt3304_dev,
1296 &dev->i2c_adap[dev->def_i2c_bus]);
1301 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1302 &dev->i2c_adap[dev->def_i2c_bus],
1303 &kworld_a340_config)) {
1304 dvb_frontend_detach(dvb->fe[0]);
1309 case EM28174_BOARD_PCTV_290E:
1310 /* set default GPIO0 for LNA, used if GPIOLIB is undefined */
1311 dvb->lna_gpio = CXD2820R_GPIO_E | CXD2820R_GPIO_O |
1313 dvb->fe[0] = dvb_attach(cxd2820r_attach,
1314 &em28xx_cxd2820r_config,
1315 &dev->i2c_adap[dev->def_i2c_bus],
1318 /* FE 0 attach tuner */
1319 if (!dvb_attach(tda18271_attach,
1322 &dev->i2c_adap[dev->def_i2c_bus],
1323 &em28xx_cxd2820r_tda18271_config)) {
1325 dvb_frontend_detach(dvb->fe[0]);
1330 #ifdef CONFIG_GPIOLIB
1331 /* enable LNA for DVB-T, DVB-T2 and DVB-C */
1332 result = gpio_request_one(dvb->lna_gpio,
1333 GPIOF_OUT_INIT_LOW, NULL);
1335 em28xx_errdev("gpio request failed %d\n",
1338 gpio_free(dvb->lna_gpio);
1340 result = 0; /* continue even set LNA fails */
1342 dvb->fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
1346 case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C:
1348 struct xc5000_config cfg;
1350 hauppauge_hvr930c_init(dev);
1352 dvb->fe[0] = dvb_attach(drxk_attach,
1353 &hauppauge_930c_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
1358 /* FIXME: do we need a pll semaphore? */
1359 dvb->fe[0]->sec_priv = dvb;
1360 sema_init(&dvb->pll_mutex, 1);
1361 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1362 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
1365 memset(&cfg, 0, sizeof(cfg));
1366 cfg.i2c_address = 0x61;
1369 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1370 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1371 if (!dvb_attach(xc5000_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus],
1376 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1377 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1381 case EM2884_BOARD_TERRATEC_H5:
1382 terratec_h5_init(dev);
1384 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_h5_drxk, &dev->i2c_adap[dev->def_i2c_bus]);
1389 /* FIXME: do we need a pll semaphore? */
1390 dvb->fe[0]->sec_priv = dvb;
1391 sema_init(&dvb->pll_mutex, 1);
1392 dvb->gate_ctrl = dvb->fe[0]->ops.i2c_gate_ctrl;
1393 dvb->fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
1395 /* Attach tda18271 to DVB-C frontend */
1396 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1397 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 1);
1398 if (!dvb_attach(tda18271c2dd_attach, dvb->fe[0], &dev->i2c_adap[dev->def_i2c_bus], 0x60)) {
1402 if (dvb->fe[0]->ops.i2c_gate_ctrl)
1403 dvb->fe[0]->ops.i2c_gate_ctrl(dvb->fe[0], 0);
1406 case EM2884_BOARD_C3TECH_DIGITAL_DUO:
1407 dvb->fe[0] = dvb_attach(mb86a20s_attach,
1408 &c3tech_duo_mb86a20s_config,
1409 &dev->i2c_adap[dev->def_i2c_bus]);
1410 if (dvb->fe[0] != NULL)
1411 dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1412 &dev->i2c_adap[dev->def_i2c_bus],
1413 &c3tech_duo_tda18271_config);
1415 case EM28174_BOARD_PCTV_460E: {
1416 struct i2c_client *client;
1417 struct i2c_board_info board_info;
1418 struct tda10071_platform_data tda10071_pdata = {};
1419 struct a8293_platform_data a8293_pdata = {};
1421 /* attach demod + tuner combo */
1422 tda10071_pdata.clk = 40444000, /* 40.444 MHz */
1423 tda10071_pdata.i2c_wr_max = 64,
1424 tda10071_pdata.ts_mode = TDA10071_TS_SERIAL,
1425 tda10071_pdata.pll_multiplier = 20,
1426 tda10071_pdata.tuner_i2c_addr = 0x14,
1427 memset(&board_info, 0, sizeof(board_info));
1428 strlcpy(board_info.type, "tda10071_cx24118", I2C_NAME_SIZE);
1429 board_info.addr = 0x55;
1430 board_info.platform_data = &tda10071_pdata;
1431 request_module("tda10071");
1432 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &board_info);
1433 if (client == NULL || client->dev.driver == NULL) {
1437 if (!try_module_get(client->dev.driver->owner)) {
1438 i2c_unregister_device(client);
1442 dvb->fe[0] = tda10071_pdata.get_dvb_frontend(client);
1443 dvb->i2c_client_demod = client;
1446 a8293_pdata.dvb_frontend = dvb->fe[0];
1447 memset(&board_info, 0, sizeof(board_info));
1448 strlcpy(board_info.type, "a8293", I2C_NAME_SIZE);
1449 board_info.addr = 0x08;
1450 board_info.platform_data = &a8293_pdata;
1451 request_module("a8293");
1452 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &board_info);
1453 if (client == NULL || client->dev.driver == NULL) {
1454 module_put(dvb->i2c_client_demod->dev.driver->owner);
1455 i2c_unregister_device(dvb->i2c_client_demod);
1459 if (!try_module_get(client->dev.driver->owner)) {
1460 i2c_unregister_device(client);
1461 module_put(dvb->i2c_client_demod->dev.driver->owner);
1462 i2c_unregister_device(dvb->i2c_client_demod);
1466 dvb->i2c_client_sec = client;
1469 case EM2874_BOARD_DELOCK_61959:
1470 case EM2874_BOARD_MAXMEDIA_UB425_TC:
1471 /* attach demodulator */
1472 dvb->fe[0] = dvb_attach(drxk_attach, &maxmedia_ub425_tc_drxk,
1473 &dev->i2c_adap[dev->def_i2c_bus]);
1476 /* disable I2C-gate */
1477 dvb->fe[0]->ops.i2c_gate_ctrl = NULL;
1480 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1481 &dev->i2c_adap[dev->def_i2c_bus],
1482 &em28xx_cxd2820r_tda18271_config)) {
1483 dvb_frontend_detach(dvb->fe[0]);
1489 case EM2884_BOARD_PCTV_510E:
1490 case EM2884_BOARD_PCTV_520E:
1491 pctv_520e_init(dev);
1493 /* attach demodulator */
1494 dvb->fe[0] = dvb_attach(drxk_attach, &pctv_520e_drxk,
1495 &dev->i2c_adap[dev->def_i2c_bus]);
1499 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1500 &dev->i2c_adap[dev->def_i2c_bus],
1501 &em28xx_cxd2820r_tda18271_config)) {
1502 dvb_frontend_detach(dvb->fe[0]);
1508 case EM2884_BOARD_ELGATO_EYETV_HYBRID_2008:
1509 case EM2884_BOARD_CINERGY_HTC_STICK:
1510 terratec_htc_stick_init(dev);
1512 /* attach demodulator */
1513 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1514 &dev->i2c_adap[dev->def_i2c_bus]);
1520 /* Attach the demodulator. */
1521 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1522 &dev->i2c_adap[dev->def_i2c_bus],
1523 &em28xx_cxd2820r_tda18271_config)) {
1528 case EM2884_BOARD_TERRATEC_HTC_USB_XS:
1529 terratec_htc_usb_xs_init(dev);
1531 /* attach demodulator */
1532 dvb->fe[0] = dvb_attach(drxk_attach, &terratec_htc_stick_drxk,
1533 &dev->i2c_adap[dev->def_i2c_bus]);
1539 /* Attach the demodulator. */
1540 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1541 &dev->i2c_adap[dev->def_i2c_bus],
1542 &em28xx_cxd2820r_tda18271_config)) {
1547 case EM2874_BOARD_KWORLD_UB435Q_V2:
1548 dvb->fe[0] = dvb_attach(lgdt3305_attach,
1549 &em2874_lgdt3305_dev,
1550 &dev->i2c_adap[dev->def_i2c_bus]);
1556 /* Attach the demodulator. */
1557 if (!dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1558 &dev->i2c_adap[dev->def_i2c_bus],
1559 &kworld_ub435q_v2_config)) {
1564 case EM2874_BOARD_KWORLD_UB435Q_V3:
1566 struct i2c_client *client;
1567 struct i2c_adapter *adapter = &dev->i2c_adap[dev->def_i2c_bus];
1568 struct i2c_board_info board_info = {
1571 .platform_data = &kworld_ub435q_v3_config,
1574 dvb->fe[0] = dvb_attach(lgdt3305_attach,
1575 &em2874_lgdt3305_nogate_dev,
1576 &dev->i2c_adap[dev->def_i2c_bus]);
1583 kworld_ub435q_v3_config.fe = dvb->fe[0];
1584 request_module("tda18212");
1585 client = i2c_new_device(adapter, &board_info);
1586 if (client == NULL || client->dev.driver == NULL) {
1587 dvb_frontend_detach(dvb->fe[0]);
1592 if (!try_module_get(client->dev.driver->owner)) {
1593 i2c_unregister_device(client);
1594 dvb_frontend_detach(dvb->fe[0]);
1599 dvb->i2c_client_tuner = client;
1602 case EM2874_BOARD_PCTV_HD_MINI_80E:
1603 dvb->fe[0] = dvb_attach(drx39xxj_attach, &dev->i2c_adap[dev->def_i2c_bus]);
1604 if (dvb->fe[0] != NULL) {
1605 dvb->fe[0] = dvb_attach(tda18271_attach, dvb->fe[0], 0x60,
1606 &dev->i2c_adap[dev->def_i2c_bus],
1607 &pinnacle_80e_dvb_config);
1614 case EM28178_BOARD_PCTV_461E: {
1615 struct i2c_client *client;
1616 struct i2c_adapter *i2c_adapter;
1617 struct i2c_board_info board_info;
1618 struct m88ds3103_platform_data m88ds3103_pdata = {};
1619 struct ts2020_config ts2020_config = {};
1620 struct a8293_platform_data a8293_pdata = {};
1623 m88ds3103_pdata.clk = 27000000;
1624 m88ds3103_pdata.i2c_wr_max = 33;
1625 m88ds3103_pdata.ts_mode = M88DS3103_TS_PARALLEL;
1626 m88ds3103_pdata.ts_clk = 16000;
1627 m88ds3103_pdata.ts_clk_pol = 1;
1628 m88ds3103_pdata.agc = 0x99;
1629 memset(&board_info, 0, sizeof(board_info));
1630 strlcpy(board_info.type, "m88ds3103", I2C_NAME_SIZE);
1631 board_info.addr = 0x68;
1632 board_info.platform_data = &m88ds3103_pdata;
1633 request_module("m88ds3103");
1634 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &board_info);
1635 if (client == NULL || client->dev.driver == NULL) {
1639 if (!try_module_get(client->dev.driver->owner)) {
1640 i2c_unregister_device(client);
1644 dvb->fe[0] = m88ds3103_pdata.get_dvb_frontend(client);
1645 i2c_adapter = m88ds3103_pdata.get_i2c_adapter(client);
1646 dvb->i2c_client_demod = client;
1649 ts2020_config.fe = dvb->fe[0];
1650 memset(&board_info, 0, sizeof(board_info));
1651 strlcpy(board_info.type, "ts2022", I2C_NAME_SIZE);
1652 board_info.addr = 0x60;
1653 board_info.platform_data = &ts2020_config;
1654 request_module("ts2020");
1655 client = i2c_new_device(i2c_adapter, &board_info);
1656 if (client == NULL || client->dev.driver == NULL) {
1657 module_put(dvb->i2c_client_demod->dev.driver->owner);
1658 i2c_unregister_device(dvb->i2c_client_demod);
1662 if (!try_module_get(client->dev.driver->owner)) {
1663 i2c_unregister_device(client);
1664 module_put(dvb->i2c_client_demod->dev.driver->owner);
1665 i2c_unregister_device(dvb->i2c_client_demod);
1669 dvb->i2c_client_tuner = client;
1670 /* delegate signal strength measurement to tuner */
1671 dvb->fe[0]->ops.read_signal_strength =
1672 dvb->fe[0]->ops.tuner_ops.get_rf_strength;
1675 a8293_pdata.dvb_frontend = dvb->fe[0];
1676 memset(&board_info, 0, sizeof(board_info));
1677 strlcpy(board_info.type, "a8293", I2C_NAME_SIZE);
1678 board_info.addr = 0x08;
1679 board_info.platform_data = &a8293_pdata;
1680 request_module("a8293");
1681 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &board_info);
1682 if (client == NULL || client->dev.driver == NULL) {
1683 module_put(dvb->i2c_client_tuner->dev.driver->owner);
1684 i2c_unregister_device(dvb->i2c_client_tuner);
1685 module_put(dvb->i2c_client_demod->dev.driver->owner);
1686 i2c_unregister_device(dvb->i2c_client_demod);
1690 if (!try_module_get(client->dev.driver->owner)) {
1691 i2c_unregister_device(client);
1692 module_put(dvb->i2c_client_tuner->dev.driver->owner);
1693 i2c_unregister_device(dvb->i2c_client_tuner);
1694 module_put(dvb->i2c_client_demod->dev.driver->owner);
1695 i2c_unregister_device(dvb->i2c_client_demod);
1699 dvb->i2c_client_sec = client;
1702 case EM28178_BOARD_PCTV_292E:
1704 struct i2c_adapter *adapter;
1705 struct i2c_client *client;
1706 struct i2c_board_info info;
1707 struct si2168_config si2168_config;
1708 struct si2157_config si2157_config;
1711 memset(&si2168_config, 0, sizeof(si2168_config));
1712 si2168_config.i2c_adapter = &adapter;
1713 si2168_config.fe = &dvb->fe[0];
1714 si2168_config.ts_mode = SI2168_TS_PARALLEL;
1715 memset(&info, 0, sizeof(struct i2c_board_info));
1716 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
1718 info.platform_data = &si2168_config;
1719 request_module(info.type);
1720 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &info);
1721 if (client == NULL || client->dev.driver == NULL) {
1726 if (!try_module_get(client->dev.driver->owner)) {
1727 i2c_unregister_device(client);
1732 dvb->i2c_client_demod = client;
1735 memset(&si2157_config, 0, sizeof(si2157_config));
1736 si2157_config.fe = dvb->fe[0];
1737 si2157_config.if_port = 1;
1738 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1739 si2157_config.mdev = dev->media_dev;
1741 memset(&info, 0, sizeof(struct i2c_board_info));
1742 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
1744 info.platform_data = &si2157_config;
1745 request_module(info.type);
1746 client = i2c_new_device(adapter, &info);
1747 if (client == NULL || client->dev.driver == NULL) {
1748 module_put(dvb->i2c_client_demod->dev.driver->owner);
1749 i2c_unregister_device(dvb->i2c_client_demod);
1754 if (!try_module_get(client->dev.driver->owner)) {
1755 i2c_unregister_device(client);
1756 module_put(dvb->i2c_client_demod->dev.driver->owner);
1757 i2c_unregister_device(dvb->i2c_client_demod);
1762 dvb->i2c_client_tuner = client;
1763 dvb->fe[0]->ops.set_lna = em28xx_pctv_292e_set_lna;
1766 case EM28178_BOARD_TERRATEC_T2_STICK_HD:
1768 struct i2c_adapter *adapter;
1769 struct i2c_client *client;
1770 struct i2c_board_info info;
1771 struct si2168_config si2168_config;
1772 struct si2157_config si2157_config;
1775 memset(&si2168_config, 0, sizeof(si2168_config));
1776 si2168_config.i2c_adapter = &adapter;
1777 si2168_config.fe = &dvb->fe[0];
1778 si2168_config.ts_mode = SI2168_TS_PARALLEL;
1779 memset(&info, 0, sizeof(struct i2c_board_info));
1780 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
1782 info.platform_data = &si2168_config;
1783 request_module(info.type);
1784 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &info);
1785 if (client == NULL || client->dev.driver == NULL) {
1790 if (!try_module_get(client->dev.driver->owner)) {
1791 i2c_unregister_device(client);
1796 dvb->i2c_client_demod = client;
1799 memset(&si2157_config, 0, sizeof(si2157_config));
1800 si2157_config.fe = dvb->fe[0];
1801 si2157_config.if_port = 0;
1802 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1803 si2157_config.mdev = dev->media_dev;
1805 memset(&info, 0, sizeof(struct i2c_board_info));
1806 strlcpy(info.type, "si2146", I2C_NAME_SIZE);
1808 info.platform_data = &si2157_config;
1809 request_module("si2157");
1810 client = i2c_new_device(adapter, &info);
1811 if (client == NULL || client->dev.driver == NULL) {
1812 module_put(dvb->i2c_client_demod->dev.driver->owner);
1813 i2c_unregister_device(dvb->i2c_client_demod);
1818 if (!try_module_get(client->dev.driver->owner)) {
1819 i2c_unregister_device(client);
1820 module_put(dvb->i2c_client_demod->dev.driver->owner);
1821 i2c_unregister_device(dvb->i2c_client_demod);
1826 dvb->i2c_client_tuner = client;
1830 case EM28178_BOARD_PLEX_PX_BCUD:
1832 struct i2c_client *client;
1833 struct i2c_board_info info;
1834 struct tc90522_config tc90522_config;
1835 struct qm1d1c0042_config qm1d1c0042_config;
1838 memset(&tc90522_config, 0, sizeof(tc90522_config));
1839 memset(&info, 0, sizeof(struct i2c_board_info));
1840 strlcpy(info.type, "tc90522sat", I2C_NAME_SIZE);
1842 info.platform_data = &tc90522_config;
1843 request_module("tc90522");
1844 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &info);
1845 if (client == NULL || client->dev.driver == NULL) {
1849 dvb->i2c_client_demod = client;
1850 if (!try_module_get(client->dev.driver->owner)) {
1851 i2c_unregister_device(client);
1857 memset(&qm1d1c0042_config, 0,
1858 sizeof(qm1d1c0042_config));
1859 qm1d1c0042_config.fe = tc90522_config.fe;
1860 qm1d1c0042_config.lpf = 1;
1861 memset(&info, 0, sizeof(struct i2c_board_info));
1862 strlcpy(info.type, "qm1d1c0042", I2C_NAME_SIZE);
1864 info.platform_data = &qm1d1c0042_config;
1865 request_module(info.type);
1866 client = i2c_new_device(tc90522_config.tuner_i2c,
1868 if (client == NULL || client->dev.driver == NULL) {
1869 module_put(dvb->i2c_client_demod->dev.driver->owner);
1870 i2c_unregister_device(dvb->i2c_client_demod);
1874 dvb->i2c_client_tuner = client;
1875 if (!try_module_get(client->dev.driver->owner)) {
1876 i2c_unregister_device(client);
1877 module_put(dvb->i2c_client_demod->dev.driver->owner);
1878 i2c_unregister_device(dvb->i2c_client_demod);
1882 dvb->fe[0] = tc90522_config.fe;
1886 case EM28174_BOARD_HAUPPAUGE_WINTV_DUALHD_DVB:
1888 struct i2c_adapter *adapter;
1889 struct i2c_client *client;
1890 struct i2c_board_info info;
1891 struct si2168_config si2168_config;
1892 struct si2157_config si2157_config;
1895 memset(&si2168_config, 0, sizeof(si2168_config));
1896 si2168_config.i2c_adapter = &adapter;
1897 si2168_config.fe = &dvb->fe[0];
1898 si2168_config.ts_mode = SI2168_TS_SERIAL;
1899 memset(&info, 0, sizeof(struct i2c_board_info));
1900 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
1902 info.platform_data = &si2168_config;
1903 request_module(info.type);
1904 client = i2c_new_device(&dev->i2c_adap[dev->def_i2c_bus], &info);
1905 if (client == NULL || client->dev.driver == NULL) {
1910 if (!try_module_get(client->dev.driver->owner)) {
1911 i2c_unregister_device(client);
1916 dvb->i2c_client_demod = client;
1919 memset(&si2157_config, 0, sizeof(si2157_config));
1920 si2157_config.fe = dvb->fe[0];
1921 si2157_config.if_port = 1;
1922 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
1923 si2157_config.mdev = dev->media_dev;
1925 memset(&info, 0, sizeof(struct i2c_board_info));
1926 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
1928 info.platform_data = &si2157_config;
1929 request_module(info.type);
1930 client = i2c_new_device(adapter, &info);
1931 if (client == NULL || client->dev.driver == NULL) {
1932 module_put(dvb->i2c_client_demod->dev.driver->owner);
1933 i2c_unregister_device(dvb->i2c_client_demod);
1938 if (!try_module_get(client->dev.driver->owner)) {
1939 i2c_unregister_device(client);
1940 module_put(dvb->i2c_client_demod->dev.driver->owner);
1941 i2c_unregister_device(dvb->i2c_client_demod);
1946 dvb->i2c_client_tuner = client;
1951 em28xx_errdev("/2: The frontend of your DVB/ATSC card"
1952 " isn't supported yet\n");
1955 if (NULL == dvb->fe[0]) {
1956 em28xx_errdev("/2: frontend initialization failed\n");
1960 /* define general-purpose callback pointer */
1961 dvb->fe[0]->callback = em28xx_tuner_callback;
1963 dvb->fe[1]->callback = em28xx_tuner_callback;
1965 /* register everything */
1966 result = em28xx_register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
1971 em28xx_info("DVB extension successfully initialized\n");
1973 kref_get(&dev->ref);
1976 em28xx_set_mode(dev, EM28XX_SUSPEND);
1977 mutex_unlock(&dev->lock);
1986 static inline void prevent_sleep(struct dvb_frontend_ops *ops)
1988 ops->set_voltage = NULL;
1990 ops->tuner_ops.sleep = NULL;
1993 static int em28xx_dvb_fini(struct em28xx *dev)
1995 struct em28xx_dvb *dvb;
1996 struct i2c_client *client;
1998 if (dev->is_audio_only) {
1999 /* Shouldn't initialize IR for this interface */
2003 if (!dev->board.has_dvb) {
2004 /* This device does not support the extension */
2011 em28xx_info("Closing DVB extension\n");
2015 em28xx_uninit_usb_xfer(dev, EM28XX_DIGITAL_MODE);
2017 if (dev->disconnected) {
2018 /* We cannot tell the device to sleep
2019 * once it has been unplugged. */
2021 prevent_sleep(&dvb->fe[0]->ops);
2022 dvb->fe[0]->exit = DVB_FE_DEVICE_REMOVED;
2025 prevent_sleep(&dvb->fe[1]->ops);
2026 dvb->fe[1]->exit = DVB_FE_DEVICE_REMOVED;
2030 /* remove I2C SEC */
2031 client = dvb->i2c_client_sec;
2033 module_put(client->dev.driver->owner);
2034 i2c_unregister_device(client);
2037 /* remove I2C tuner */
2038 client = dvb->i2c_client_tuner;
2040 module_put(client->dev.driver->owner);
2041 i2c_unregister_device(client);
2044 /* remove I2C demod */
2045 client = dvb->i2c_client_demod;
2047 module_put(client->dev.driver->owner);
2048 i2c_unregister_device(client);
2051 em28xx_unregister_dvb(dvb);
2054 kref_put(&dev->ref, em28xx_free_device);
2059 static int em28xx_dvb_suspend(struct em28xx *dev)
2063 if (dev->is_audio_only)
2066 if (!dev->board.has_dvb)
2069 em28xx_info("Suspending DVB extension\n");
2071 struct em28xx_dvb *dvb = dev->dvb;
2074 ret = dvb_frontend_suspend(dvb->fe[0]);
2075 em28xx_info("fe0 suspend %d\n", ret);
2078 dvb_frontend_suspend(dvb->fe[1]);
2079 em28xx_info("fe1 suspend %d\n", ret);
2086 static int em28xx_dvb_resume(struct em28xx *dev)
2090 if (dev->is_audio_only)
2093 if (!dev->board.has_dvb)
2096 em28xx_info("Resuming DVB extension\n");
2098 struct em28xx_dvb *dvb = dev->dvb;
2101 ret = dvb_frontend_resume(dvb->fe[0]);
2102 em28xx_info("fe0 resume %d\n", ret);
2106 ret = dvb_frontend_resume(dvb->fe[1]);
2107 em28xx_info("fe1 resume %d\n", ret);
2114 static struct em28xx_ops dvb_ops = {
2116 .name = "Em28xx dvb Extension",
2117 .init = em28xx_dvb_init,
2118 .fini = em28xx_dvb_fini,
2119 .suspend = em28xx_dvb_suspend,
2120 .resume = em28xx_dvb_resume,
2123 static int __init em28xx_dvb_register(void)
2125 return em28xx_register_extension(&dvb_ops);
2128 static void __exit em28xx_dvb_unregister(void)
2130 em28xx_unregister_extension(&dvb_ops);
2133 module_init(em28xx_dvb_register);
2134 module_exit(em28xx_dvb_unregister);