2 DVB device driver for em28xx
4 (c) 2008-2011 Mauro Carvalho Chehab <mchehab@infradead.org>
6 (c) 2008 Devin Heitmueller <devin.heitmueller@gmail.com>
7 - Fixes for the driver to properly work with HVR-950
8 - Fixes for the driver to properly work with Pinnacle PCTV HD Pro Stick
9 - Fixes for the driver to properly work with AMD ATI TV Wonder HD 600
11 (c) 2008 Aidan Thornton <makosoft@googlemail.com>
13 (c) 2012 Frank Schäfer <fschaefer.oss@googlemail.com>
15 Based on cx88-dvb, saa7134-dvb and videobuf-dvb originally written by:
16 (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
17 (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
19 This program is free software; you can redistribute it and/or modify
20 it under the terms of the GNU General Public License as published by
21 the Free Software Foundation; either version 2 of the License.
24 #include <linux/kernel.h>
25 #include <linux/slab.h>
26 #include <linux/usb.h>
29 #include <media/v4l2-common.h>
30 #include <dvb_demux.h>
33 #include <media/tuner.h>
34 #include "tuner-simple.h"
35 #include <linux/gpio.h>
42 #include "mt352_priv.h" /* FIXME */
48 #include "tda18271c2dd.h"
54 MODULE_DESCRIPTION("driver for em28xx based DVB cards");
55 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
56 MODULE_LICENSE("GPL");
58 static unsigned int debug
;
59 module_param(debug
, int, 0644);
60 MODULE_PARM_DESC(debug
, "enable debug messages [dvb]");
62 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
64 #define dprintk(level, fmt, arg...) do { \
66 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \
70 struct dvb_frontend
*fe
[2];
72 /* feed count management */
76 /* general boilerplate stuff */
77 struct dvb_adapter adapter
;
78 struct dvb_demux demux
;
80 struct dmx_frontend fe_hw
;
81 struct dmx_frontend fe_mem
;
84 /* Due to DRX-K - probably need changes */
85 int (*gate_ctrl
)(struct dvb_frontend
*, int);
86 struct semaphore pll_mutex
;
92 static inline void print_err_status(struct em28xx
*dev
,
93 int packet
, int status
)
95 char *errmsg
= "Unknown";
99 errmsg
= "unlinked synchronuously";
102 errmsg
= "unlinked asynchronuously";
105 errmsg
= "Buffer error (overrun)";
108 errmsg
= "Stalled (device not responding)";
111 errmsg
= "Babble (bad cable?)";
114 errmsg
= "Bit-stuff error (bad cable?)";
117 errmsg
= "CRC/Timeout (could be anything)";
120 errmsg
= "Device does not respond";
124 dprintk(1, "URB status %d [%s].\n", status
, errmsg
);
126 dprintk(1, "URB packet %d, status %d [%s].\n",
127 packet
, status
, errmsg
);
131 static inline int em28xx_dvb_urb_data_copy(struct em28xx
*dev
, struct urb
*urb
)
133 int xfer_bulk
, num_packets
, i
;
138 if (dev
->disconnected
)
142 print_err_status(dev
, -1, urb
->status
);
144 xfer_bulk
= usb_pipebulk(urb
->pipe
);
146 if (xfer_bulk
) /* bulk */
149 num_packets
= urb
->number_of_packets
;
151 for (i
= 0; i
< num_packets
; i
++) {
153 if (urb
->status
< 0) {
154 print_err_status(dev
, i
, urb
->status
);
155 if (urb
->status
!= -EPROTO
)
158 dvb_dmx_swfilter(&dev
->dvb
->demux
, urb
->transfer_buffer
,
161 if (urb
->iso_frame_desc
[i
].status
< 0) {
162 print_err_status(dev
, i
,
163 urb
->iso_frame_desc
[i
].status
);
164 if (urb
->iso_frame_desc
[i
].status
!= -EPROTO
)
167 dvb_dmx_swfilter(&dev
->dvb
->demux
,
168 urb
->transfer_buffer
+
169 urb
->iso_frame_desc
[i
].offset
,
170 urb
->iso_frame_desc
[i
].actual_length
);
177 static int em28xx_start_streaming(struct em28xx_dvb
*dvb
)
180 struct em28xx
*dev
= dvb
->adapter
.priv
;
181 int dvb_max_packet_size
, packet_multiplier
, dvb_alt
;
183 if (dev
->dvb_xfer_bulk
) {
184 if (!dev
->dvb_ep_bulk
)
186 dvb_max_packet_size
= 512; /* USB 2.0 spec */
187 packet_multiplier
= EM28XX_DVB_BULK_PACKET_MULTIPLIER
;
190 if (!dev
->dvb_ep_isoc
)
192 dvb_max_packet_size
= dev
->dvb_max_pkt_size_isoc
;
193 if (dvb_max_packet_size
< 0)
194 return dvb_max_packet_size
;
195 packet_multiplier
= EM28XX_DVB_NUM_ISOC_PACKETS
;
196 dvb_alt
= dev
->dvb_alt_isoc
;
199 usb_set_interface(dev
->udev
, 0, dvb_alt
);
200 rc
= em28xx_set_mode(dev
, EM28XX_DIGITAL_MODE
);
204 dprintk(1, "Using %d buffers each with %d x %d bytes\n",
207 dvb_max_packet_size
);
209 return em28xx_init_usb_xfer(dev
, EM28XX_DIGITAL_MODE
,
214 em28xx_dvb_urb_data_copy
);
217 static int em28xx_stop_streaming(struct em28xx_dvb
*dvb
)
219 struct em28xx
*dev
= dvb
->adapter
.priv
;
221 em28xx_stop_urbs(dev
);
226 static int em28xx_start_feed(struct dvb_demux_feed
*feed
)
228 struct dvb_demux
*demux
= feed
->demux
;
229 struct em28xx_dvb
*dvb
= demux
->priv
;
232 if (!demux
->dmx
.frontend
)
235 mutex_lock(&dvb
->lock
);
239 if (dvb
->nfeeds
== 1) {
240 ret
= em28xx_start_streaming(dvb
);
245 mutex_unlock(&dvb
->lock
);
249 static int em28xx_stop_feed(struct dvb_demux_feed
*feed
)
251 struct dvb_demux
*demux
= feed
->demux
;
252 struct em28xx_dvb
*dvb
= demux
->priv
;
255 mutex_lock(&dvb
->lock
);
258 if (0 == dvb
->nfeeds
)
259 err
= em28xx_stop_streaming(dvb
);
261 mutex_unlock(&dvb
->lock
);
267 /* ------------------------------------------------------------------ */
268 static int em28xx_dvb_bus_ctrl(struct dvb_frontend
*fe
, int acquire
)
270 struct em28xx
*dev
= fe
->dvb
->priv
;
273 return em28xx_set_mode(dev
, EM28XX_DIGITAL_MODE
);
275 return em28xx_set_mode(dev
, EM28XX_SUSPEND
);
278 /* ------------------------------------------------------------------ */
280 static struct lgdt330x_config em2880_lgdt3303_dev
= {
281 .demod_address
= 0x0e,
282 .demod_chip
= LGDT3303
,
285 static struct lgdt3305_config em2870_lgdt3304_dev
= {
287 .demod_chip
= LGDT3304
,
288 .spectral_inversion
= 1,
290 .mpeg_mode
= LGDT3305_MPEG_PARALLEL
,
291 .tpclk_edge
= LGDT3305_TPCLK_FALLING_EDGE
,
292 .tpvalid_polarity
= LGDT3305_TP_VALID_HIGH
,
297 static struct s921_config sharp_isdbt
= {
298 .demod_address
= 0x30 >> 1
301 static struct zl10353_config em28xx_zl10353_with_xc3028
= {
302 .demod_address
= (0x1e >> 1),
308 static struct s5h1409_config em28xx_s5h1409_with_xc3028
= {
309 .demod_address
= 0x32 >> 1,
310 .output_mode
= S5H1409_PARALLEL_OUTPUT
,
311 .gpio
= S5H1409_GPIO_OFF
,
312 .inversion
= S5H1409_INVERSION_OFF
,
313 .status_mode
= S5H1409_DEMODLOCKING
,
314 .mpeg_timing
= S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
317 static struct tda18271_std_map kworld_a340_std_map
= {
318 .atsc_6
= { .if_freq
= 3250, .agc_mode
= 3, .std
= 0,
319 .if_lvl
= 1, .rfagc_top
= 0x37, },
320 .qam_6
= { .if_freq
= 4000, .agc_mode
= 3, .std
= 1,
321 .if_lvl
= 1, .rfagc_top
= 0x37, },
324 static struct tda18271_config kworld_a340_config
= {
325 .std_map
= &kworld_a340_std_map
,
328 static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate
= {
329 .demod_address
= (0x1e >> 1),
331 .disable_i2c_gate_ctrl
= 1,
336 static struct drxd_config em28xx_drxd
= {
337 .demod_address
= 0x70,
338 .demod_revision
= 0xa2,
339 .pll_type
= DRXD_PLL_NONE
,
343 .disable_i2c_gate_ctrl
= 1,
346 static struct drxk_config terratec_h5_drxk
= {
350 .microcode_name
= "dvb-usb-terratec-h5-drxk.fw",
351 .qam_demod_parameter_count
= 2,
352 .load_firmware_sync
= true,
355 static struct drxk_config hauppauge_930c_drxk
= {
359 .microcode_name
= "dvb-usb-hauppauge-hvr930c-drxk.fw",
361 .qam_demod_parameter_count
= 2,
362 .load_firmware_sync
= true,
365 static struct drxk_config terratec_htc_stick_drxk
= {
369 .microcode_name
= "dvb-usb-terratec-htc-stick-drxk.fw",
371 .qam_demod_parameter_count
= 2,
372 /* Required for the antenna_gpio to disable LNA. */
373 .antenna_dvbt
= true,
374 /* The windows driver uses the same. This will disable LNA. */
376 .load_firmware_sync
= true,
379 static struct drxk_config maxmedia_ub425_tc_drxk
= {
383 .load_firmware_sync
= true,
386 static struct drxk_config pctv_520e_drxk
= {
389 .microcode_name
= "dvb-demod-drxk-pctv.fw",
390 .qam_demod_parameter_count
= 2,
392 .antenna_dvbt
= true, /* disable LNA */
393 .antenna_gpio
= (1 << 2), /* disable LNA */
394 .load_firmware_sync
= true,
397 static int drxk_gate_ctrl(struct dvb_frontend
*fe
, int enable
)
399 struct em28xx_dvb
*dvb
= fe
->sec_priv
;
406 down(&dvb
->pll_mutex
);
407 status
= dvb
->gate_ctrl(fe
, 1);
409 status
= dvb
->gate_ctrl(fe
, 0);
415 static void hauppauge_hvr930c_init(struct em28xx
*dev
)
419 struct em28xx_reg_seq hauppauge_hvr930c_init
[] = {
420 {EM2874_R80_GPIO
, 0xff, 0xff, 0x65},
421 {EM2874_R80_GPIO
, 0xfb, 0xff, 0x32},
422 {EM2874_R80_GPIO
, 0xff, 0xff, 0xb8},
425 struct em28xx_reg_seq hauppauge_hvr930c_end
[] = {
426 {EM2874_R80_GPIO
, 0xef, 0xff, 0x01},
427 {EM2874_R80_GPIO
, 0xaf, 0xff, 0x65},
428 {EM2874_R80_GPIO
, 0xef, 0xff, 0x76},
429 {EM2874_R80_GPIO
, 0xef, 0xff, 0x01},
430 {EM2874_R80_GPIO
, 0xcf, 0xff, 0x0b},
431 {EM2874_R80_GPIO
, 0xef, 0xff, 0x40},
433 {EM2874_R80_GPIO
, 0xcf, 0xff, 0x65},
434 {EM2874_R80_GPIO
, 0xef, 0xff, 0x65},
435 {EM2874_R80_GPIO
, 0xcf, 0xff, 0x0b},
436 {EM2874_R80_GPIO
, 0xef, 0xff, 0x65},
445 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
447 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
449 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
450 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
452 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
455 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
457 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
460 em28xx_gpio_set(dev
, hauppauge_hvr930c_init
);
461 em28xx_write_reg(dev
, EM28XX_R06_I2C_CLK
, 0x40);
463 em28xx_write_reg(dev
, EM28XX_R06_I2C_CLK
, 0x44);
466 dev
->i2c_client
[dev
->def_i2c_bus
].addr
= 0x82 >> 1;
468 for (i
= 0; i
< ARRAY_SIZE(regs
); i
++)
469 i2c_master_send(&dev
->i2c_client
[dev
->def_i2c_bus
], regs
[i
].r
, regs
[i
].len
);
470 em28xx_gpio_set(dev
, hauppauge_hvr930c_end
);
474 em28xx_write_reg(dev
, EM28XX_R06_I2C_CLK
, 0x44);
477 em28xx_write_reg(dev
, EM28XX_R06_I2C_CLK
, 0x45);
482 static void terratec_h5_init(struct em28xx
*dev
)
485 struct em28xx_reg_seq terratec_h5_init
[] = {
486 {EM28XX_R08_GPIO
, 0xff, 0xff, 10},
487 {EM2874_R80_GPIO
, 0xf6, 0xff, 100},
488 {EM2874_R80_GPIO
, 0xf2, 0xff, 50},
489 {EM2874_R80_GPIO
, 0xf6, 0xff, 100},
492 struct em28xx_reg_seq terratec_h5_end
[] = {
493 {EM2874_R80_GPIO
, 0xe6, 0xff, 100},
494 {EM2874_R80_GPIO
, 0xa6, 0xff, 50},
495 {EM2874_R80_GPIO
, 0xe6, 0xff, 100},
502 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
504 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
506 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
507 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
509 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
512 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
514 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
517 em28xx_gpio_set(dev
, terratec_h5_init
);
518 em28xx_write_reg(dev
, EM28XX_R06_I2C_CLK
, 0x40);
520 em28xx_write_reg(dev
, EM28XX_R06_I2C_CLK
, 0x45);
523 dev
->i2c_client
[dev
->def_i2c_bus
].addr
= 0x82 >> 1;
525 for (i
= 0; i
< ARRAY_SIZE(regs
); i
++)
526 i2c_master_send(&dev
->i2c_client
[dev
->def_i2c_bus
], regs
[i
].r
, regs
[i
].len
);
527 em28xx_gpio_set(dev
, terratec_h5_end
);
530 static void terratec_htc_stick_init(struct em28xx
*dev
)
535 * GPIO configuration:
536 * 0xff: unknown (does not affect DVB-T).
537 * 0xf6: DRX-K (demodulator).
538 * 0xe6: unknown (does not affect DVB-T).
539 * 0xb6: unknown (does not affect DVB-T).
541 struct em28xx_reg_seq terratec_htc_stick_init
[] = {
542 {EM28XX_R08_GPIO
, 0xff, 0xff, 10},
543 {EM2874_R80_GPIO
, 0xf6, 0xff, 100},
544 {EM2874_R80_GPIO
, 0xe6, 0xff, 50},
545 {EM2874_R80_GPIO
, 0xf6, 0xff, 100},
548 struct em28xx_reg_seq terratec_htc_stick_end
[] = {
549 {EM2874_R80_GPIO
, 0xb6, 0xff, 100},
550 {EM2874_R80_GPIO
, 0xf6, 0xff, 50},
555 * Init the analog decoder (not yet supported), but
556 * it's probably still a good idea.
562 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
564 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
566 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
569 em28xx_gpio_set(dev
, terratec_htc_stick_init
);
571 em28xx_write_reg(dev
, EM28XX_R06_I2C_CLK
, 0x40);
573 em28xx_write_reg(dev
, EM28XX_R06_I2C_CLK
, 0x44);
576 dev
->i2c_client
[dev
->def_i2c_bus
].addr
= 0x82 >> 1;
578 for (i
= 0; i
< ARRAY_SIZE(regs
); i
++)
579 i2c_master_send(&dev
->i2c_client
[dev
->def_i2c_bus
], regs
[i
].r
, regs
[i
].len
);
581 em28xx_gpio_set(dev
, terratec_htc_stick_end
);
584 static void terratec_htc_usb_xs_init(struct em28xx
*dev
)
588 struct em28xx_reg_seq terratec_htc_usb_xs_init
[] = {
589 {EM28XX_R08_GPIO
, 0xff, 0xff, 10},
590 {EM2874_R80_GPIO
, 0xb2, 0xff, 100},
591 {EM2874_R80_GPIO
, 0xb2, 0xff, 50},
592 {EM2874_R80_GPIO
, 0xb6, 0xff, 100},
595 struct em28xx_reg_seq terratec_htc_usb_xs_end
[] = {
596 {EM2874_R80_GPIO
, 0xa6, 0xff, 100},
597 {EM2874_R80_GPIO
, 0xa6, 0xff, 50},
598 {EM2874_R80_GPIO
, 0xe6, 0xff, 100},
603 * Init the analog decoder (not yet supported), but
604 * it's probably still a good idea.
610 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
612 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
614 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
615 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
617 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
620 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
622 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
625 em28xx_write_reg(dev
, EM28XX_R06_I2C_CLK
, 0x40);
627 em28xx_gpio_set(dev
, terratec_htc_usb_xs_init
);
629 em28xx_write_reg(dev
, EM28XX_R06_I2C_CLK
, 0x40);
631 em28xx_write_reg(dev
, EM28XX_R06_I2C_CLK
, 0x44);
634 dev
->i2c_client
[dev
->def_i2c_bus
].addr
= 0x82 >> 1;
636 for (i
= 0; i
< ARRAY_SIZE(regs
); i
++)
637 i2c_master_send(&dev
->i2c_client
[dev
->def_i2c_bus
], regs
[i
].r
, regs
[i
].len
);
639 em28xx_gpio_set(dev
, terratec_htc_usb_xs_end
);
642 static void pctv_520e_init(struct em28xx
*dev
)
645 * Init AVF4910B analog decoder. Looks like I2C traffic to
646 * digital demodulator and tuner are routed via AVF4910B.
653 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
655 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
657 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
658 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
660 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
663 dev
->i2c_client
[dev
->def_i2c_bus
].addr
= 0x82 >> 1; /* 0x41 */
665 for (i
= 0; i
< ARRAY_SIZE(regs
); i
++)
666 i2c_master_send(&dev
->i2c_client
[dev
->def_i2c_bus
], regs
[i
].r
, regs
[i
].len
);
669 static int em28xx_pctv_290e_set_lna(struct dvb_frontend
*fe
)
671 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
672 struct em28xx
*dev
= fe
->dvb
->priv
;
673 #ifdef CONFIG_GPIOLIB
674 struct em28xx_dvb
*dvb
= dev
->dvb
;
679 flags
= GPIOF_OUT_INIT_HIGH
; /* enable LNA */
681 flags
= GPIOF_OUT_INIT_LOW
; /* disable LNA */
683 ret
= gpio_request_one(dvb
->lna_gpio
, flags
, NULL
);
685 em28xx_errdev("gpio request failed %d\n", ret
);
687 gpio_free(dvb
->lna_gpio
);
691 dev_warn(&dev
->udev
->dev
, "%s: LNA control is disabled (lna=%u)\n",
692 KBUILD_MODNAME
, c
->lna
);
697 static int em28xx_mt352_terratec_xs_init(struct dvb_frontend
*fe
)
699 /* Values extracted from a USB trace of the Terratec Windows driver */
700 static u8 clock_config
[] = { CLOCK_CTL
, 0x38, 0x2c };
701 static u8 reset
[] = { RESET
, 0x80 };
702 static u8 adc_ctl_1_cfg
[] = { ADC_CTL_1
, 0x40 };
703 static u8 agc_cfg
[] = { AGC_TARGET
, 0x28, 0xa0 };
704 static u8 input_freq_cfg
[] = { INPUT_FREQ_1
, 0x31, 0xb8 };
705 static u8 rs_err_cfg
[] = { RS_ERR_PER_1
, 0x00, 0x4d };
706 static u8 capt_range_cfg
[] = { CAPT_RANGE
, 0x32 };
707 static u8 trl_nom_cfg
[] = { TRL_NOMINAL_RATE_1
, 0x64, 0x00 };
708 static u8 tps_given_cfg
[] = { TPS_GIVEN_1
, 0x40, 0x80, 0x50 };
709 static u8 tuner_go
[] = { TUNER_GO
, 0x01};
711 mt352_write(fe
, clock_config
, sizeof(clock_config
));
713 mt352_write(fe
, reset
, sizeof(reset
));
714 mt352_write(fe
, adc_ctl_1_cfg
, sizeof(adc_ctl_1_cfg
));
715 mt352_write(fe
, agc_cfg
, sizeof(agc_cfg
));
716 mt352_write(fe
, input_freq_cfg
, sizeof(input_freq_cfg
));
717 mt352_write(fe
, rs_err_cfg
, sizeof(rs_err_cfg
));
718 mt352_write(fe
, capt_range_cfg
, sizeof(capt_range_cfg
));
719 mt352_write(fe
, trl_nom_cfg
, sizeof(trl_nom_cfg
));
720 mt352_write(fe
, tps_given_cfg
, sizeof(tps_given_cfg
));
721 mt352_write(fe
, tuner_go
, sizeof(tuner_go
));
725 static struct mt352_config terratec_xs_mt352_cfg
= {
726 .demod_address
= (0x1e >> 1),
729 .demod_init
= em28xx_mt352_terratec_xs_init
,
732 static struct tda10023_config em28xx_tda10023_config
= {
733 .demod_address
= 0x0c,
737 static struct cxd2820r_config em28xx_cxd2820r_config
= {
738 .i2c_address
= (0xd8 >> 1),
739 .ts_mode
= CXD2820R_TS_SERIAL
,
742 static struct tda18271_config em28xx_cxd2820r_tda18271_config
= {
743 .output_opt
= TDA18271_OUTPUT_LT_OFF
,
744 .gate
= TDA18271_GATE_DIGITAL
,
747 static const struct tda10071_config em28xx_tda10071_config
= {
748 .demod_i2c_addr
= 0x55, /* (0xaa >> 1) */
749 .tuner_i2c_addr
= 0x14,
751 .ts_mode
= TDA10071_TS_SERIAL
,
753 .xtal
= 40444000, /* 40.444 MHz */
754 .pll_multiplier
= 20,
757 static const struct a8293_config em28xx_a8293_config
= {
758 .i2c_addr
= 0x08, /* (0x10 >> 1) */
761 static struct zl10353_config em28xx_zl10353_no_i2c_gate_dev
= {
762 .demod_address
= (0x1e >> 1),
763 .disable_i2c_gate_ctrl
= 1,
767 static struct qt1010_config em28xx_qt1010_config
= {
772 /* ------------------------------------------------------------------ */
774 static int em28xx_attach_xc3028(u8 addr
, struct em28xx
*dev
)
776 struct dvb_frontend
*fe
;
777 struct xc2028_config cfg
;
779 memset(&cfg
, 0, sizeof(cfg
));
780 cfg
.i2c_adap
= &dev
->i2c_adap
[dev
->def_i2c_bus
];
783 if (!dev
->dvb
->fe
[0]) {
784 em28xx_errdev("/2: dvb frontend not attached. "
785 "Can't attach xc3028\n");
789 fe
= dvb_attach(xc2028_attach
, dev
->dvb
->fe
[0], &cfg
);
791 em28xx_errdev("/2: xc3028 attach failed\n");
792 dvb_frontend_detach(dev
->dvb
->fe
[0]);
793 dev
->dvb
->fe
[0] = NULL
;
797 em28xx_info("%s/2: xc3028 attached\n", dev
->name
);
802 /* ------------------------------------------------------------------ */
804 static int em28xx_register_dvb(struct em28xx_dvb
*dvb
, struct module
*module
,
805 struct em28xx
*dev
, struct device
*device
)
809 mutex_init(&dvb
->lock
);
811 /* register adapter */
812 result
= dvb_register_adapter(&dvb
->adapter
, dev
->name
, module
, device
,
815 printk(KERN_WARNING
"%s: dvb_register_adapter failed (errno = %d)\n",
820 /* Ensure all frontends negotiate bus access */
821 dvb
->fe
[0]->ops
.ts_bus_ctrl
= em28xx_dvb_bus_ctrl
;
823 dvb
->fe
[1]->ops
.ts_bus_ctrl
= em28xx_dvb_bus_ctrl
;
825 dvb
->adapter
.priv
= dev
;
827 /* register frontend */
828 result
= dvb_register_frontend(&dvb
->adapter
, dvb
->fe
[0]);
830 printk(KERN_WARNING
"%s: dvb_register_frontend failed (errno = %d)\n",
835 /* register 2nd frontend */
837 result
= dvb_register_frontend(&dvb
->adapter
, dvb
->fe
[1]);
839 printk(KERN_WARNING
"%s: 2nd dvb_register_frontend failed (errno = %d)\n",
845 /* register demux stuff */
846 dvb
->demux
.dmx
.capabilities
=
847 DMX_TS_FILTERING
| DMX_SECTION_FILTERING
|
848 DMX_MEMORY_BASED_FILTERING
;
849 dvb
->demux
.priv
= dvb
;
850 dvb
->demux
.filternum
= 256;
851 dvb
->demux
.feednum
= 256;
852 dvb
->demux
.start_feed
= em28xx_start_feed
;
853 dvb
->demux
.stop_feed
= em28xx_stop_feed
;
855 result
= dvb_dmx_init(&dvb
->demux
);
857 printk(KERN_WARNING
"%s: dvb_dmx_init failed (errno = %d)\n",
862 dvb
->dmxdev
.filternum
= 256;
863 dvb
->dmxdev
.demux
= &dvb
->demux
.dmx
;
864 dvb
->dmxdev
.capabilities
= 0;
865 result
= dvb_dmxdev_init(&dvb
->dmxdev
, &dvb
->adapter
);
867 printk(KERN_WARNING
"%s: dvb_dmxdev_init failed (errno = %d)\n",
872 dvb
->fe_hw
.source
= DMX_FRONTEND_0
;
873 result
= dvb
->demux
.dmx
.add_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
875 printk(KERN_WARNING
"%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
880 dvb
->fe_mem
.source
= DMX_MEMORY_FE
;
881 result
= dvb
->demux
.dmx
.add_frontend(&dvb
->demux
.dmx
, &dvb
->fe_mem
);
883 printk(KERN_WARNING
"%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
888 result
= dvb
->demux
.dmx
.connect_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
890 printk(KERN_WARNING
"%s: connect_frontend failed (errno = %d)\n",
895 /* register network adapter */
896 dvb_net_init(&dvb
->adapter
, &dvb
->net
, &dvb
->demux
.dmx
);
900 dvb
->demux
.dmx
.remove_frontend(&dvb
->demux
.dmx
, &dvb
->fe_mem
);
902 dvb
->demux
.dmx
.remove_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
904 dvb_dmxdev_release(&dvb
->dmxdev
);
906 dvb_dmx_release(&dvb
->demux
);
909 dvb_unregister_frontend(dvb
->fe
[1]);
910 dvb_unregister_frontend(dvb
->fe
[0]);
913 dvb_frontend_detach(dvb
->fe
[1]);
915 dvb_frontend_detach(dvb
->fe
[0]);
916 dvb_unregister_adapter(&dvb
->adapter
);
921 static void em28xx_unregister_dvb(struct em28xx_dvb
*dvb
)
923 dvb_net_release(&dvb
->net
);
924 dvb
->demux
.dmx
.remove_frontend(&dvb
->demux
.dmx
, &dvb
->fe_mem
);
925 dvb
->demux
.dmx
.remove_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
926 dvb_dmxdev_release(&dvb
->dmxdev
);
927 dvb_dmx_release(&dvb
->demux
);
929 dvb_unregister_frontend(dvb
->fe
[1]);
930 dvb_unregister_frontend(dvb
->fe
[0]);
931 if (dvb
->fe
[1] && !dvb
->dont_attach_fe1
)
932 dvb_frontend_detach(dvb
->fe
[1]);
933 dvb_frontend_detach(dvb
->fe
[0]);
934 dvb_unregister_adapter(&dvb
->adapter
);
937 static int em28xx_dvb_init(struct em28xx
*dev
)
939 int result
= 0, mfe_shared
= 0;
940 struct em28xx_dvb
*dvb
;
942 if (!dev
->board
.has_dvb
) {
943 /* This device does not support the extension */
944 printk(KERN_INFO
"em28xx_dvb: This device does not support the extension\n");
948 dvb
= kzalloc(sizeof(struct em28xx_dvb
), GFP_KERNEL
);
951 em28xx_info("em28xx_dvb: memory allocation failed\n");
955 dvb
->fe
[0] = dvb
->fe
[1] = NULL
;
957 mutex_lock(&dev
->lock
);
958 em28xx_set_mode(dev
, EM28XX_DIGITAL_MODE
);
960 switch (dev
->model
) {
961 case EM2874_BOARD_LEADERSHIP_ISDBT
:
962 dvb
->fe
[0] = dvb_attach(s921_attach
,
963 &sharp_isdbt
, &dev
->i2c_adap
[dev
->def_i2c_bus
]);
971 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850
:
972 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950
:
973 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO
:
974 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600
:
975 dvb
->fe
[0] = dvb_attach(lgdt330x_attach
,
976 &em2880_lgdt3303_dev
,
977 &dev
->i2c_adap
[dev
->def_i2c_bus
]);
978 if (em28xx_attach_xc3028(0x61, dev
) < 0) {
983 case EM2880_BOARD_KWORLD_DVB_310U
:
984 dvb
->fe
[0] = dvb_attach(zl10353_attach
,
985 &em28xx_zl10353_with_xc3028
,
986 &dev
->i2c_adap
[dev
->def_i2c_bus
]);
987 if (em28xx_attach_xc3028(0x61, dev
) < 0) {
992 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900
:
993 case EM2882_BOARD_TERRATEC_HYBRID_XS
:
994 case EM2880_BOARD_EMPIRE_DUAL_TV
:
995 dvb
->fe
[0] = dvb_attach(zl10353_attach
,
996 &em28xx_zl10353_xc3028_no_i2c_gate
,
997 &dev
->i2c_adap
[dev
->def_i2c_bus
]);
998 if (em28xx_attach_xc3028(0x61, dev
) < 0) {
1003 case EM2880_BOARD_TERRATEC_HYBRID_XS
:
1004 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR
:
1005 case EM2881_BOARD_PINNACLE_HYBRID_PRO
:
1006 case EM2882_BOARD_DIKOM_DK300
:
1007 case EM2882_BOARD_KWORLD_VS_DVBT
:
1008 dvb
->fe
[0] = dvb_attach(zl10353_attach
,
1009 &em28xx_zl10353_xc3028_no_i2c_gate
,
1010 &dev
->i2c_adap
[dev
->def_i2c_bus
]);
1011 if (dvb
->fe
[0] == NULL
) {
1012 /* This board could have either a zl10353 or a mt352.
1013 If the chip id isn't for zl10353, try mt352 */
1014 dvb
->fe
[0] = dvb_attach(mt352_attach
,
1015 &terratec_xs_mt352_cfg
,
1016 &dev
->i2c_adap
[dev
->def_i2c_bus
]);
1019 if (em28xx_attach_xc3028(0x61, dev
) < 0) {
1024 case EM2870_BOARD_KWORLD_355U
:
1025 dvb
->fe
[0] = dvb_attach(zl10353_attach
,
1026 &em28xx_zl10353_no_i2c_gate_dev
,
1027 &dev
->i2c_adap
[dev
->def_i2c_bus
]);
1028 if (dvb
->fe
[0] != NULL
)
1029 dvb_attach(qt1010_attach
, dvb
->fe
[0],
1030 &dev
->i2c_adap
[dev
->def_i2c_bus
], &em28xx_qt1010_config
);
1032 case EM2883_BOARD_KWORLD_HYBRID_330U
:
1033 case EM2882_BOARD_EVGA_INDTUBE
:
1034 dvb
->fe
[0] = dvb_attach(s5h1409_attach
,
1035 &em28xx_s5h1409_with_xc3028
,
1036 &dev
->i2c_adap
[dev
->def_i2c_bus
]);
1037 if (em28xx_attach_xc3028(0x61, dev
) < 0) {
1042 case EM2882_BOARD_KWORLD_ATSC_315U
:
1043 dvb
->fe
[0] = dvb_attach(lgdt330x_attach
,
1044 &em2880_lgdt3303_dev
,
1045 &dev
->i2c_adap
[dev
->def_i2c_bus
]);
1046 if (dvb
->fe
[0] != NULL
) {
1047 if (!dvb_attach(simple_tuner_attach
, dvb
->fe
[0],
1048 &dev
->i2c_adap
[dev
->def_i2c_bus
], 0x61, TUNER_THOMSON_DTT761X
)) {
1054 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2
:
1055 case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E
:
1056 dvb
->fe
[0] = dvb_attach(drxd_attach
, &em28xx_drxd
, NULL
,
1057 &dev
->i2c_adap
[dev
->def_i2c_bus
], &dev
->udev
->dev
);
1058 if (em28xx_attach_xc3028(0x61, dev
) < 0) {
1063 case EM2870_BOARD_REDDO_DVB_C_USB_BOX
:
1064 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
1065 dvb
->fe
[0] = dvb_attach(tda10023_attach
,
1066 &em28xx_tda10023_config
,
1067 &dev
->i2c_adap
[dev
->def_i2c_bus
], 0x48);
1069 if (!dvb_attach(simple_tuner_attach
, dvb
->fe
[0],
1070 &dev
->i2c_adap
[dev
->def_i2c_bus
], 0x60, TUNER_PHILIPS_CU1216L
)) {
1076 case EM2870_BOARD_KWORLD_A340
:
1077 dvb
->fe
[0] = dvb_attach(lgdt3305_attach
,
1078 &em2870_lgdt3304_dev
,
1079 &dev
->i2c_adap
[dev
->def_i2c_bus
]);
1080 if (dvb
->fe
[0] != NULL
)
1081 dvb_attach(tda18271_attach
, dvb
->fe
[0], 0x60,
1082 &dev
->i2c_adap
[dev
->def_i2c_bus
], &kworld_a340_config
);
1084 case EM28174_BOARD_PCTV_290E
:
1085 /* set default GPIO0 for LNA, used if GPIOLIB is undefined */
1086 dvb
->lna_gpio
= CXD2820R_GPIO_E
| CXD2820R_GPIO_O
|
1088 dvb
->fe
[0] = dvb_attach(cxd2820r_attach
,
1089 &em28xx_cxd2820r_config
,
1090 &dev
->i2c_adap
[dev
->def_i2c_bus
],
1093 /* FE 0 attach tuner */
1094 if (!dvb_attach(tda18271_attach
,
1097 &dev
->i2c_adap
[dev
->def_i2c_bus
],
1098 &em28xx_cxd2820r_tda18271_config
)) {
1100 dvb_frontend_detach(dvb
->fe
[0]);
1105 #ifdef CONFIG_GPIOLIB
1106 /* enable LNA for DVB-T, DVB-T2 and DVB-C */
1107 result
= gpio_request_one(dvb
->lna_gpio
,
1108 GPIOF_OUT_INIT_LOW
, NULL
);
1110 em28xx_errdev("gpio request failed %d\n",
1113 gpio_free(dvb
->lna_gpio
);
1115 result
= 0; /* continue even set LNA fails */
1117 dvb
->fe
[0]->ops
.set_lna
= em28xx_pctv_290e_set_lna
;
1121 case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C
:
1123 struct xc5000_config cfg
;
1124 hauppauge_hvr930c_init(dev
);
1126 dvb
->fe
[0] = dvb_attach(drxk_attach
,
1127 &hauppauge_930c_drxk
, &dev
->i2c_adap
[dev
->def_i2c_bus
]);
1132 /* FIXME: do we need a pll semaphore? */
1133 dvb
->fe
[0]->sec_priv
= dvb
;
1134 sema_init(&dvb
->pll_mutex
, 1);
1135 dvb
->gate_ctrl
= dvb
->fe
[0]->ops
.i2c_gate_ctrl
;
1136 dvb
->fe
[0]->ops
.i2c_gate_ctrl
= drxk_gate_ctrl
;
1139 memset(&cfg
, 0, sizeof(cfg
));
1140 cfg
.i2c_address
= 0x61;
1143 if (dvb
->fe
[0]->ops
.i2c_gate_ctrl
)
1144 dvb
->fe
[0]->ops
.i2c_gate_ctrl(dvb
->fe
[0], 1);
1145 if (!dvb_attach(xc5000_attach
, dvb
->fe
[0], &dev
->i2c_adap
[dev
->def_i2c_bus
],
1150 if (dvb
->fe
[0]->ops
.i2c_gate_ctrl
)
1151 dvb
->fe
[0]->ops
.i2c_gate_ctrl(dvb
->fe
[0], 0);
1155 case EM2884_BOARD_TERRATEC_H5
:
1156 terratec_h5_init(dev
);
1158 dvb
->fe
[0] = dvb_attach(drxk_attach
, &terratec_h5_drxk
, &dev
->i2c_adap
[dev
->def_i2c_bus
]);
1163 /* FIXME: do we need a pll semaphore? */
1164 dvb
->fe
[0]->sec_priv
= dvb
;
1165 sema_init(&dvb
->pll_mutex
, 1);
1166 dvb
->gate_ctrl
= dvb
->fe
[0]->ops
.i2c_gate_ctrl
;
1167 dvb
->fe
[0]->ops
.i2c_gate_ctrl
= drxk_gate_ctrl
;
1169 /* Attach tda18271 to DVB-C frontend */
1170 if (dvb
->fe
[0]->ops
.i2c_gate_ctrl
)
1171 dvb
->fe
[0]->ops
.i2c_gate_ctrl(dvb
->fe
[0], 1);
1172 if (!dvb_attach(tda18271c2dd_attach
, dvb
->fe
[0], &dev
->i2c_adap
[dev
->def_i2c_bus
], 0x60)) {
1176 if (dvb
->fe
[0]->ops
.i2c_gate_ctrl
)
1177 dvb
->fe
[0]->ops
.i2c_gate_ctrl(dvb
->fe
[0], 0);
1180 case EM28174_BOARD_PCTV_460E
:
1182 dvb
->fe
[0] = dvb_attach(tda10071_attach
,
1183 &em28xx_tda10071_config
, &dev
->i2c_adap
[dev
->def_i2c_bus
]);
1187 dvb_attach(a8293_attach
, dvb
->fe
[0], &dev
->i2c_adap
[dev
->def_i2c_bus
],
1188 &em28xx_a8293_config
);
1190 case EM2874_BOARD_MAXMEDIA_UB425_TC
:
1191 /* attach demodulator */
1192 dvb
->fe
[0] = dvb_attach(drxk_attach
, &maxmedia_ub425_tc_drxk
,
1193 &dev
->i2c_adap
[dev
->def_i2c_bus
]);
1196 /* disable I2C-gate */
1197 dvb
->fe
[0]->ops
.i2c_gate_ctrl
= NULL
;
1200 if (!dvb_attach(tda18271c2dd_attach
, dvb
->fe
[0],
1201 &dev
->i2c_adap
[dev
->def_i2c_bus
], 0x60)) {
1202 dvb_frontend_detach(dvb
->fe
[0]);
1208 /* TODO: we need drx-3913k firmware in order to support DVB-T */
1209 em28xx_info("MaxMedia UB425-TC: only DVB-C supported by that " \
1210 "driver version\n");
1213 case EM2884_BOARD_PCTV_510E
:
1214 case EM2884_BOARD_PCTV_520E
:
1215 pctv_520e_init(dev
);
1217 /* attach demodulator */
1218 dvb
->fe
[0] = dvb_attach(drxk_attach
, &pctv_520e_drxk
,
1219 &dev
->i2c_adap
[dev
->def_i2c_bus
]);
1223 if (!dvb_attach(tda18271_attach
, dvb
->fe
[0], 0x60,
1224 &dev
->i2c_adap
[dev
->def_i2c_bus
],
1225 &em28xx_cxd2820r_tda18271_config
)) {
1226 dvb_frontend_detach(dvb
->fe
[0]);
1232 case EM2884_BOARD_CINERGY_HTC_STICK
:
1233 terratec_htc_stick_init(dev
);
1235 /* attach demodulator */
1236 dvb
->fe
[0] = dvb_attach(drxk_attach
, &terratec_htc_stick_drxk
,
1237 &dev
->i2c_adap
[dev
->def_i2c_bus
]);
1243 /* Attach the demodulator. */
1244 if (!dvb_attach(tda18271_attach
, dvb
->fe
[0], 0x60,
1245 &dev
->i2c_adap
[dev
->def_i2c_bus
],
1246 &em28xx_cxd2820r_tda18271_config
)) {
1251 case EM2884_BOARD_TERRATEC_HTC_USB_XS
:
1252 terratec_htc_usb_xs_init(dev
);
1254 /* attach demodulator */
1255 dvb
->fe
[0] = dvb_attach(drxk_attach
, &terratec_htc_stick_drxk
,
1256 &dev
->i2c_adap
[dev
->def_i2c_bus
]);
1262 /* Attach the demodulator. */
1263 if (!dvb_attach(tda18271_attach
, dvb
->fe
[0], 0x60,
1264 &dev
->i2c_adap
[dev
->def_i2c_bus
],
1265 &em28xx_cxd2820r_tda18271_config
)) {
1271 em28xx_errdev("/2: The frontend of your DVB/ATSC card"
1272 " isn't supported yet\n");
1275 if (NULL
== dvb
->fe
[0]) {
1276 em28xx_errdev("/2: frontend initialization failed\n");
1280 /* define general-purpose callback pointer */
1281 dvb
->fe
[0]->callback
= em28xx_tuner_callback
;
1283 dvb
->fe
[1]->callback
= em28xx_tuner_callback
;
1285 /* register everything */
1286 result
= em28xx_register_dvb(dvb
, THIS_MODULE
, dev
, &dev
->udev
->dev
);
1292 dvb
->adapter
.mfe_shared
= mfe_shared
;
1294 em28xx_info("Successfully loaded em28xx-dvb\n");
1296 em28xx_set_mode(dev
, EM28XX_SUSPEND
);
1297 mutex_unlock(&dev
->lock
);
1306 static inline void prevent_sleep(struct dvb_frontend_ops
*ops
)
1308 ops
->set_voltage
= NULL
;
1310 ops
->tuner_ops
.sleep
= NULL
;
1313 static int em28xx_dvb_fini(struct em28xx
*dev
)
1315 if (!dev
->board
.has_dvb
) {
1316 /* This device does not support the extension */
1321 struct em28xx_dvb
*dvb
= dev
->dvb
;
1323 if (dev
->disconnected
) {
1324 /* We cannot tell the device to sleep
1325 * once it has been unplugged. */
1327 prevent_sleep(&dvb
->fe
[0]->ops
);
1329 prevent_sleep(&dvb
->fe
[1]->ops
);
1332 em28xx_unregister_dvb(dvb
);
1340 static struct em28xx_ops dvb_ops
= {
1342 .name
= "Em28xx dvb Extension",
1343 .init
= em28xx_dvb_init
,
1344 .fini
= em28xx_dvb_fini
,
1347 static int __init
em28xx_dvb_register(void)
1349 return em28xx_register_extension(&dvb_ops
);
1352 static void __exit
em28xx_dvb_unregister(void)
1354 em28xx_unregister_extension(&dvb_ops
);
1357 module_init(em28xx_dvb_register
);
1358 module_exit(em28xx_dvb_unregister
);