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 Based on cx88-dvb, saa7134-dvb and videobuf-dvb originally written by:
14 (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
15 (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
17 This program is free software; you can redistribute it and/or modify
18 it under the terms of the GNU General Public License as published by
19 the Free Software Foundation; either version 2 of the License.
22 #include <linux/kernel.h>
23 #include <linux/slab.h>
24 #include <linux/usb.h>
27 #include <media/v4l2-common.h>
28 #include <media/videobuf-vmalloc.h>
29 #include <media/tuner.h>
30 #include "tuner-simple.h"
37 #include "mt352_priv.h" /* FIXME */
43 #include "tda18271c2dd.h"
48 MODULE_DESCRIPTION("driver for em28xx based DVB cards");
49 MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
50 MODULE_LICENSE("GPL");
52 static unsigned int debug
;
53 module_param(debug
, int, 0644);
54 MODULE_PARM_DESC(debug
, "enable debug messages [dvb]");
56 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr
);
58 #define dprintk(level, fmt, arg...) do { \
60 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \
63 #define EM28XX_DVB_NUM_BUFS 5
64 #define EM28XX_DVB_MAX_PACKETS 64
67 struct dvb_frontend
*fe
[2];
69 /* feed count management */
73 /* general boilerplate stuff */
74 struct dvb_adapter adapter
;
75 struct dvb_demux demux
;
77 struct dmx_frontend fe_hw
;
78 struct dmx_frontend fe_mem
;
81 /* Due to DRX-K - probably need changes */
82 int (*gate_ctrl
)(struct dvb_frontend
*, int);
83 struct semaphore pll_mutex
;
88 static inline void print_err_status(struct em28xx
*dev
,
89 int packet
, int status
)
91 char *errmsg
= "Unknown";
95 errmsg
= "unlinked synchronuously";
98 errmsg
= "unlinked asynchronuously";
101 errmsg
= "Buffer error (overrun)";
104 errmsg
= "Stalled (device not responding)";
107 errmsg
= "Babble (bad cable?)";
110 errmsg
= "Bit-stuff error (bad cable?)";
113 errmsg
= "CRC/Timeout (could be anything)";
116 errmsg
= "Device does not respond";
120 dprintk(1, "URB status %d [%s].\n", status
, errmsg
);
122 dprintk(1, "URB packet %d, status %d [%s].\n",
123 packet
, status
, errmsg
);
127 static inline int em28xx_dvb_isoc_copy(struct em28xx
*dev
, struct urb
*urb
)
134 if ((dev
->state
& DEV_DISCONNECTED
) || (dev
->state
& DEV_MISCONFIGURED
))
137 if (urb
->status
< 0) {
138 print_err_status(dev
, -1, urb
->status
);
139 if (urb
->status
== -ENOENT
)
143 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
144 int status
= urb
->iso_frame_desc
[i
].status
;
147 print_err_status(dev
, i
, status
);
148 if (urb
->iso_frame_desc
[i
].status
!= -EPROTO
)
152 dvb_dmx_swfilter(&dev
->dvb
->demux
, urb
->transfer_buffer
+
153 urb
->iso_frame_desc
[i
].offset
,
154 urb
->iso_frame_desc
[i
].actual_length
);
160 static int em28xx_start_streaming(struct em28xx_dvb
*dvb
)
163 struct em28xx
*dev
= dvb
->adapter
.priv
;
164 int max_dvb_packet_size
;
166 usb_set_interface(dev
->udev
, 0, 1);
167 rc
= em28xx_set_mode(dev
, EM28XX_DIGITAL_MODE
);
171 max_dvb_packet_size
= em28xx_isoc_dvb_max_packetsize(dev
);
172 if (max_dvb_packet_size
< 0)
173 return max_dvb_packet_size
;
174 dprintk(1, "Using %d buffers each with %d bytes\n",
176 max_dvb_packet_size
);
178 return em28xx_init_isoc(dev
, EM28XX_DVB_MAX_PACKETS
,
179 EM28XX_DVB_NUM_BUFS
, max_dvb_packet_size
,
180 em28xx_dvb_isoc_copy
);
183 static int em28xx_stop_streaming(struct em28xx_dvb
*dvb
)
185 struct em28xx
*dev
= dvb
->adapter
.priv
;
187 em28xx_uninit_isoc(dev
);
189 em28xx_set_mode(dev
, EM28XX_SUSPEND
);
194 static int em28xx_start_feed(struct dvb_demux_feed
*feed
)
196 struct dvb_demux
*demux
= feed
->demux
;
197 struct em28xx_dvb
*dvb
= demux
->priv
;
200 if (!demux
->dmx
.frontend
)
203 mutex_lock(&dvb
->lock
);
207 if (dvb
->nfeeds
== 1) {
208 ret
= em28xx_start_streaming(dvb
);
213 mutex_unlock(&dvb
->lock
);
217 static int em28xx_stop_feed(struct dvb_demux_feed
*feed
)
219 struct dvb_demux
*demux
= feed
->demux
;
220 struct em28xx_dvb
*dvb
= demux
->priv
;
223 mutex_lock(&dvb
->lock
);
226 if (0 == dvb
->nfeeds
)
227 err
= em28xx_stop_streaming(dvb
);
229 mutex_unlock(&dvb
->lock
);
235 /* ------------------------------------------------------------------ */
236 static int em28xx_dvb_bus_ctrl(struct dvb_frontend
*fe
, int acquire
)
238 struct em28xx
*dev
= fe
->dvb
->priv
;
241 return em28xx_set_mode(dev
, EM28XX_DIGITAL_MODE
);
243 return em28xx_set_mode(dev
, EM28XX_SUSPEND
);
246 /* ------------------------------------------------------------------ */
248 static struct lgdt330x_config em2880_lgdt3303_dev
= {
249 .demod_address
= 0x0e,
250 .demod_chip
= LGDT3303
,
253 static struct lgdt3305_config em2870_lgdt3304_dev
= {
255 .demod_chip
= LGDT3304
,
256 .spectral_inversion
= 1,
258 .mpeg_mode
= LGDT3305_MPEG_PARALLEL
,
259 .tpclk_edge
= LGDT3305_TPCLK_FALLING_EDGE
,
260 .tpvalid_polarity
= LGDT3305_TP_VALID_HIGH
,
265 static struct s921_config sharp_isdbt
= {
266 .demod_address
= 0x30 >> 1
269 static struct zl10353_config em28xx_zl10353_with_xc3028
= {
270 .demod_address
= (0x1e >> 1),
276 static struct s5h1409_config em28xx_s5h1409_with_xc3028
= {
277 .demod_address
= 0x32 >> 1,
278 .output_mode
= S5H1409_PARALLEL_OUTPUT
,
279 .gpio
= S5H1409_GPIO_OFF
,
280 .inversion
= S5H1409_INVERSION_OFF
,
281 .status_mode
= S5H1409_DEMODLOCKING
,
282 .mpeg_timing
= S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK
285 static struct tda18271_std_map kworld_a340_std_map
= {
286 .atsc_6
= { .if_freq
= 3250, .agc_mode
= 3, .std
= 0,
287 .if_lvl
= 1, .rfagc_top
= 0x37, },
288 .qam_6
= { .if_freq
= 4000, .agc_mode
= 3, .std
= 1,
289 .if_lvl
= 1, .rfagc_top
= 0x37, },
292 static struct tda18271_config kworld_a340_config
= {
293 .std_map
= &kworld_a340_std_map
,
296 static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate
= {
297 .demod_address
= (0x1e >> 1),
299 .disable_i2c_gate_ctrl
= 1,
304 static struct drxd_config em28xx_drxd
= {
305 .index
= 0, .demod_address
= 0x70, .demod_revision
= 0xa2,
306 .demoda_address
= 0x00, .pll_address
= 0x00,
307 .pll_type
= DRXD_PLL_NONE
, .clock
= 12000, .insert_rs_byte
= 1,
308 .pll_set
= NULL
, .osc_deviation
= NULL
, .IF
= 42800000,
309 .disable_i2c_gate_ctrl
= 1,
312 struct drxk_config terratec_h5_drxk
= {
316 .microcode_name
= "dvb-usb-terratec-h5-drxk.fw",
319 struct drxk_config hauppauge_930c_drxk
= {
323 .microcode_name
= "dvb-usb-hauppauge-hvr930c-drxk.fw",
327 static int drxk_gate_ctrl(struct dvb_frontend
*fe
, int enable
)
329 struct em28xx_dvb
*dvb
= fe
->sec_priv
;
336 down(&dvb
->pll_mutex
);
337 status
= dvb
->gate_ctrl(fe
, 1);
339 status
= dvb
->gate_ctrl(fe
, 0);
345 static void hauppauge_hvr930c_init(struct em28xx
*dev
)
349 struct em28xx_reg_seq hauppauge_hvr930c_init
[] = {
350 {EM2874_R80_GPIO
, 0xff, 0xff, 0x65},
351 {EM2874_R80_GPIO
, 0xfb, 0xff, 0x32},
352 {EM2874_R80_GPIO
, 0xff, 0xff, 0xb8},
355 struct em28xx_reg_seq hauppauge_hvr930c_end
[] = {
356 {EM2874_R80_GPIO
, 0xef, 0xff, 0x01},
357 {EM2874_R80_GPIO
, 0xaf, 0xff, 0x65},
358 {EM2874_R80_GPIO
, 0xef, 0xff, 0x76},
359 {EM2874_R80_GPIO
, 0xef, 0xff, 0x01},
360 {EM2874_R80_GPIO
, 0xcf, 0xff, 0x0b},
361 {EM2874_R80_GPIO
, 0xef, 0xff, 0x40},
363 {EM2874_R80_GPIO
, 0xcf, 0xff, 0x65},
364 {EM2874_R80_GPIO
, 0xef, 0xff, 0x65},
365 {EM2874_R80_GPIO
, 0xcf, 0xff, 0x0b},
366 {EM2874_R80_GPIO
, 0xef, 0xff, 0x65},
375 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
377 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
379 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
380 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
382 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
385 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
387 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
390 em28xx_gpio_set(dev
, hauppauge_hvr930c_init
);
391 em28xx_write_reg(dev
, EM28XX_R06_I2C_CLK
, 0x40);
393 em28xx_write_reg(dev
, EM28XX_R06_I2C_CLK
, 0x44);
396 dev
->i2c_client
.addr
= 0x82 >> 1;
398 for (i
= 0; i
< ARRAY_SIZE(regs
); i
++)
399 i2c_master_send(&dev
->i2c_client
, regs
[i
].r
, regs
[i
].len
);
400 em28xx_gpio_set(dev
, hauppauge_hvr930c_end
);
404 em28xx_write_reg(dev
, EM28XX_R06_I2C_CLK
, 0x44);
407 em28xx_write_reg(dev
, EM28XX_R06_I2C_CLK
, 0x45);
412 static void terratec_h5_init(struct em28xx
*dev
)
415 struct em28xx_reg_seq terratec_h5_init
[] = {
416 {EM28XX_R08_GPIO
, 0xff, 0xff, 10},
417 {EM2874_R80_GPIO
, 0xf6, 0xff, 100},
418 {EM2874_R80_GPIO
, 0xf2, 0xff, 50},
419 {EM2874_R80_GPIO
, 0xf6, 0xff, 100},
422 struct em28xx_reg_seq terratec_h5_end
[] = {
423 {EM2874_R80_GPIO
, 0xe6, 0xff, 100},
424 {EM2874_R80_GPIO
, 0xa6, 0xff, 50},
425 {EM2874_R80_GPIO
, 0xe6, 0xff, 100},
432 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
434 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
436 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
437 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
439 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
442 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
444 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
447 em28xx_gpio_set(dev
, terratec_h5_init
);
448 em28xx_write_reg(dev
, EM28XX_R06_I2C_CLK
, 0x40);
450 em28xx_write_reg(dev
, EM28XX_R06_I2C_CLK
, 0x45);
453 dev
->i2c_client
.addr
= 0x82 >> 1;
455 for (i
= 0; i
< ARRAY_SIZE(regs
); i
++)
456 i2c_master_send(&dev
->i2c_client
, regs
[i
].r
, regs
[i
].len
);
457 em28xx_gpio_set(dev
, terratec_h5_end
);
460 static int em28xx_mt352_terratec_xs_init(struct dvb_frontend
*fe
)
462 /* Values extracted from a USB trace of the Terratec Windows driver */
463 static u8 clock_config
[] = { CLOCK_CTL
, 0x38, 0x2c };
464 static u8 reset
[] = { RESET
, 0x80 };
465 static u8 adc_ctl_1_cfg
[] = { ADC_CTL_1
, 0x40 };
466 static u8 agc_cfg
[] = { AGC_TARGET
, 0x28, 0xa0 };
467 static u8 input_freq_cfg
[] = { INPUT_FREQ_1
, 0x31, 0xb8 };
468 static u8 rs_err_cfg
[] = { RS_ERR_PER_1
, 0x00, 0x4d };
469 static u8 capt_range_cfg
[] = { CAPT_RANGE
, 0x32 };
470 static u8 trl_nom_cfg
[] = { TRL_NOMINAL_RATE_1
, 0x64, 0x00 };
471 static u8 tps_given_cfg
[] = { TPS_GIVEN_1
, 0x40, 0x80, 0x50 };
472 static u8 tuner_go
[] = { TUNER_GO
, 0x01};
474 mt352_write(fe
, clock_config
, sizeof(clock_config
));
476 mt352_write(fe
, reset
, sizeof(reset
));
477 mt352_write(fe
, adc_ctl_1_cfg
, sizeof(adc_ctl_1_cfg
));
478 mt352_write(fe
, agc_cfg
, sizeof(agc_cfg
));
479 mt352_write(fe
, input_freq_cfg
, sizeof(input_freq_cfg
));
480 mt352_write(fe
, rs_err_cfg
, sizeof(rs_err_cfg
));
481 mt352_write(fe
, capt_range_cfg
, sizeof(capt_range_cfg
));
482 mt352_write(fe
, trl_nom_cfg
, sizeof(trl_nom_cfg
));
483 mt352_write(fe
, tps_given_cfg
, sizeof(tps_given_cfg
));
484 mt352_write(fe
, tuner_go
, sizeof(tuner_go
));
488 static struct mt352_config terratec_xs_mt352_cfg
= {
489 .demod_address
= (0x1e >> 1),
492 .demod_init
= em28xx_mt352_terratec_xs_init
,
495 static struct tda10023_config em28xx_tda10023_config
= {
496 .demod_address
= 0x0c,
500 static struct cxd2820r_config em28xx_cxd2820r_config
= {
501 .i2c_address
= (0xd8 >> 1),
502 .ts_mode
= CXD2820R_TS_SERIAL
,
504 /* enable LNA for DVB-T2 and DVB-C */
505 .gpio_dvbt2
[0] = CXD2820R_GPIO_E
| CXD2820R_GPIO_O
| CXD2820R_GPIO_L
,
506 .gpio_dvbc
[0] = CXD2820R_GPIO_E
| CXD2820R_GPIO_O
| CXD2820R_GPIO_L
,
509 static struct tda18271_config em28xx_cxd2820r_tda18271_config
= {
510 .output_opt
= TDA18271_OUTPUT_LT_OFF
,
511 .gate
= TDA18271_GATE_DIGITAL
,
514 static const struct tda10071_config em28xx_tda10071_config
= {
515 .i2c_address
= 0x55, /* (0xaa >> 1) */
517 .ts_mode
= TDA10071_TS_SERIAL
,
519 .xtal
= 40444000, /* 40.444 MHz */
520 .pll_multiplier
= 20,
523 static const struct a8293_config em28xx_a8293_config
= {
524 .i2c_addr
= 0x08, /* (0x10 >> 1) */
527 /* ------------------------------------------------------------------ */
529 static int em28xx_attach_xc3028(u8 addr
, struct em28xx
*dev
)
531 struct dvb_frontend
*fe
;
532 struct xc2028_config cfg
;
534 memset(&cfg
, 0, sizeof(cfg
));
535 cfg
.i2c_adap
= &dev
->i2c_adap
;
538 if (!dev
->dvb
->fe
[0]) {
539 em28xx_errdev("/2: dvb frontend not attached. "
540 "Can't attach xc3028\n");
544 fe
= dvb_attach(xc2028_attach
, dev
->dvb
->fe
[0], &cfg
);
546 em28xx_errdev("/2: xc3028 attach failed\n");
547 dvb_frontend_detach(dev
->dvb
->fe
[0]);
548 dev
->dvb
->fe
[0] = NULL
;
552 em28xx_info("%s/2: xc3028 attached\n", dev
->name
);
557 /* ------------------------------------------------------------------ */
559 static int em28xx_register_dvb(struct em28xx_dvb
*dvb
, struct module
*module
,
560 struct em28xx
*dev
, struct device
*device
)
564 mutex_init(&dvb
->lock
);
566 /* register adapter */
567 result
= dvb_register_adapter(&dvb
->adapter
, dev
->name
, module
, device
,
570 printk(KERN_WARNING
"%s: dvb_register_adapter failed (errno = %d)\n",
575 /* Ensure all frontends negotiate bus access */
576 dvb
->fe
[0]->ops
.ts_bus_ctrl
= em28xx_dvb_bus_ctrl
;
578 dvb
->fe
[1]->ops
.ts_bus_ctrl
= em28xx_dvb_bus_ctrl
;
580 dvb
->adapter
.priv
= dev
;
582 /* register frontend */
583 result
= dvb_register_frontend(&dvb
->adapter
, dvb
->fe
[0]);
585 printk(KERN_WARNING
"%s: dvb_register_frontend failed (errno = %d)\n",
590 /* register 2nd frontend */
592 result
= dvb_register_frontend(&dvb
->adapter
, dvb
->fe
[1]);
594 printk(KERN_WARNING
"%s: 2nd dvb_register_frontend failed (errno = %d)\n",
600 /* register demux stuff */
601 dvb
->demux
.dmx
.capabilities
=
602 DMX_TS_FILTERING
| DMX_SECTION_FILTERING
|
603 DMX_MEMORY_BASED_FILTERING
;
604 dvb
->demux
.priv
= dvb
;
605 dvb
->demux
.filternum
= 256;
606 dvb
->demux
.feednum
= 256;
607 dvb
->demux
.start_feed
= em28xx_start_feed
;
608 dvb
->demux
.stop_feed
= em28xx_stop_feed
;
610 result
= dvb_dmx_init(&dvb
->demux
);
612 printk(KERN_WARNING
"%s: dvb_dmx_init failed (errno = %d)\n",
617 dvb
->dmxdev
.filternum
= 256;
618 dvb
->dmxdev
.demux
= &dvb
->demux
.dmx
;
619 dvb
->dmxdev
.capabilities
= 0;
620 result
= dvb_dmxdev_init(&dvb
->dmxdev
, &dvb
->adapter
);
622 printk(KERN_WARNING
"%s: dvb_dmxdev_init failed (errno = %d)\n",
627 dvb
->fe_hw
.source
= DMX_FRONTEND_0
;
628 result
= dvb
->demux
.dmx
.add_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
630 printk(KERN_WARNING
"%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
635 dvb
->fe_mem
.source
= DMX_MEMORY_FE
;
636 result
= dvb
->demux
.dmx
.add_frontend(&dvb
->demux
.dmx
, &dvb
->fe_mem
);
638 printk(KERN_WARNING
"%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
643 result
= dvb
->demux
.dmx
.connect_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
645 printk(KERN_WARNING
"%s: connect_frontend failed (errno = %d)\n",
650 /* register network adapter */
651 dvb_net_init(&dvb
->adapter
, &dvb
->net
, &dvb
->demux
.dmx
);
655 dvb
->demux
.dmx
.remove_frontend(&dvb
->demux
.dmx
, &dvb
->fe_mem
);
657 dvb
->demux
.dmx
.remove_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
659 dvb_dmxdev_release(&dvb
->dmxdev
);
661 dvb_dmx_release(&dvb
->demux
);
664 dvb_unregister_frontend(dvb
->fe
[1]);
665 dvb_unregister_frontend(dvb
->fe
[0]);
668 dvb_frontend_detach(dvb
->fe
[1]);
670 dvb_frontend_detach(dvb
->fe
[0]);
671 dvb_unregister_adapter(&dvb
->adapter
);
676 static void em28xx_unregister_dvb(struct em28xx_dvb
*dvb
)
678 dvb_net_release(&dvb
->net
);
679 dvb
->demux
.dmx
.remove_frontend(&dvb
->demux
.dmx
, &dvb
->fe_mem
);
680 dvb
->demux
.dmx
.remove_frontend(&dvb
->demux
.dmx
, &dvb
->fe_hw
);
681 dvb_dmxdev_release(&dvb
->dmxdev
);
682 dvb_dmx_release(&dvb
->demux
);
684 dvb_unregister_frontend(dvb
->fe
[1]);
685 dvb_unregister_frontend(dvb
->fe
[0]);
686 if (dvb
->fe
[1] && !dvb
->dont_attach_fe1
)
687 dvb_frontend_detach(dvb
->fe
[1]);
688 dvb_frontend_detach(dvb
->fe
[0]);
689 dvb_unregister_adapter(&dvb
->adapter
);
692 static int em28xx_dvb_init(struct em28xx
*dev
)
694 int result
= 0, mfe_shared
= 0;
695 struct em28xx_dvb
*dvb
;
697 if (!dev
->board
.has_dvb
) {
698 /* This device does not support the extension */
699 printk(KERN_INFO
"em28xx_dvb: This device does not support the extension\n");
703 dvb
= kzalloc(sizeof(struct em28xx_dvb
), GFP_KERNEL
);
706 em28xx_info("em28xx_dvb: memory allocation failed\n");
710 dvb
->fe
[0] = dvb
->fe
[1] = NULL
;
712 mutex_lock(&dev
->lock
);
713 em28xx_set_mode(dev
, EM28XX_DIGITAL_MODE
);
715 switch (dev
->model
) {
716 case EM2874_BOARD_LEADERSHIP_ISDBT
:
717 dvb
->fe
[0] = dvb_attach(s921_attach
,
718 &sharp_isdbt
, &dev
->i2c_adap
);
726 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_850
:
727 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950
:
728 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO
:
729 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600
:
730 dvb
->fe
[0] = dvb_attach(lgdt330x_attach
,
731 &em2880_lgdt3303_dev
,
733 if (em28xx_attach_xc3028(0x61, dev
) < 0) {
738 case EM2880_BOARD_KWORLD_DVB_310U
:
739 dvb
->fe
[0] = dvb_attach(zl10353_attach
,
740 &em28xx_zl10353_with_xc3028
,
742 if (em28xx_attach_xc3028(0x61, dev
) < 0) {
747 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900
:
748 case EM2882_BOARD_TERRATEC_HYBRID_XS
:
749 case EM2880_BOARD_EMPIRE_DUAL_TV
:
750 dvb
->fe
[0] = dvb_attach(zl10353_attach
,
751 &em28xx_zl10353_xc3028_no_i2c_gate
,
753 if (em28xx_attach_xc3028(0x61, dev
) < 0) {
758 case EM2880_BOARD_TERRATEC_HYBRID_XS
:
759 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR
:
760 case EM2881_BOARD_PINNACLE_HYBRID_PRO
:
761 case EM2882_BOARD_DIKOM_DK300
:
762 case EM2882_BOARD_KWORLD_VS_DVBT
:
763 dvb
->fe
[0] = dvb_attach(zl10353_attach
,
764 &em28xx_zl10353_xc3028_no_i2c_gate
,
766 if (dvb
->fe
[0] == NULL
) {
767 /* This board could have either a zl10353 or a mt352.
768 If the chip id isn't for zl10353, try mt352 */
769 dvb
->fe
[0] = dvb_attach(mt352_attach
,
770 &terratec_xs_mt352_cfg
,
774 if (em28xx_attach_xc3028(0x61, dev
) < 0) {
779 case EM2883_BOARD_KWORLD_HYBRID_330U
:
780 case EM2882_BOARD_EVGA_INDTUBE
:
781 dvb
->fe
[0] = dvb_attach(s5h1409_attach
,
782 &em28xx_s5h1409_with_xc3028
,
784 if (em28xx_attach_xc3028(0x61, dev
) < 0) {
789 case EM2882_BOARD_KWORLD_ATSC_315U
:
790 dvb
->fe
[0] = dvb_attach(lgdt330x_attach
,
791 &em2880_lgdt3303_dev
,
793 if (dvb
->fe
[0] != NULL
) {
794 if (!dvb_attach(simple_tuner_attach
, dvb
->fe
[0],
795 &dev
->i2c_adap
, 0x61, TUNER_THOMSON_DTT761X
)) {
801 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2
:
802 case EM2882_BOARD_PINNACLE_HYBRID_PRO_330E
:
803 dvb
->fe
[0] = dvb_attach(drxd_attach
, &em28xx_drxd
, NULL
,
804 &dev
->i2c_adap
, &dev
->udev
->dev
);
805 if (em28xx_attach_xc3028(0x61, dev
) < 0) {
810 case EM2870_BOARD_REDDO_DVB_C_USB_BOX
:
811 /* Philips CU1216L NIM (Philips TDA10023 + Infineon TUA6034) */
812 dvb
->fe
[0] = dvb_attach(tda10023_attach
,
813 &em28xx_tda10023_config
,
814 &dev
->i2c_adap
, 0x48);
816 if (!dvb_attach(simple_tuner_attach
, dvb
->fe
[0],
817 &dev
->i2c_adap
, 0x60, TUNER_PHILIPS_CU1216L
)) {
823 case EM2870_BOARD_KWORLD_A340
:
824 dvb
->fe
[0] = dvb_attach(lgdt3305_attach
,
825 &em2870_lgdt3304_dev
,
827 if (dvb
->fe
[0] != NULL
)
828 dvb_attach(tda18271_attach
, dvb
->fe
[0], 0x60,
829 &dev
->i2c_adap
, &kworld_a340_config
);
831 case EM28174_BOARD_PCTV_290E
:
833 * FE 0 = DVB-T/T2 + FE 1 = DVB-C, both sharing same tuner. */
835 dvb
->fe
[0] = dvb_attach(cxd2820r_attach
,
836 &em28xx_cxd2820r_config
, &dev
->i2c_adap
, NULL
);
838 /* FE 0 attach tuner */
839 if (!dvb_attach(tda18271_attach
, dvb
->fe
[0], 0x60,
840 &dev
->i2c_adap
, &em28xx_cxd2820r_tda18271_config
)) {
841 dvb_frontend_detach(dvb
->fe
[0]);
845 /* FE 1. This dvb_attach() cannot fail. */
846 dvb
->fe
[1] = dvb_attach(cxd2820r_attach
, NULL
, NULL
,
849 /* FE 1 attach tuner */
850 if (!dvb_attach(tda18271_attach
, dvb
->fe
[1], 0x60,
851 &dev
->i2c_adap
, &em28xx_cxd2820r_tda18271_config
)) {
852 dvb_frontend_detach(dvb
->fe
[1]);
853 /* leave FE 0 still active */
859 case EM2884_BOARD_HAUPPAUGE_WINTV_HVR_930C
:
861 struct xc5000_config cfg
;
862 hauppauge_hvr930c_init(dev
);
864 dvb
->dont_attach_fe1
= 1;
866 dvb
->fe
[0] = dvb_attach(drxk_attach
,
867 &hauppauge_930c_drxk
, &dev
->i2c_adap
,
873 /* FIXME: do we need a pll semaphore? */
874 dvb
->fe
[0]->sec_priv
= dvb
;
875 sema_init(&dvb
->pll_mutex
, 1);
876 dvb
->gate_ctrl
= dvb
->fe
[0]->ops
.i2c_gate_ctrl
;
877 dvb
->fe
[0]->ops
.i2c_gate_ctrl
= drxk_gate_ctrl
;
881 memset(&cfg
, 0, sizeof(cfg
));
882 cfg
.i2c_address
= 0x61;
885 if (dvb
->fe
[0]->ops
.i2c_gate_ctrl
)
886 dvb
->fe
[0]->ops
.i2c_gate_ctrl(dvb
->fe
[0], 1);
887 if (!dvb_attach(xc5000_attach
, dvb
->fe
[0], &dev
->i2c_adap
,
893 if (dvb
->fe
[0]->ops
.i2c_gate_ctrl
)
894 dvb
->fe
[0]->ops
.i2c_gate_ctrl(dvb
->fe
[0], 0);
896 /* Hack - needed by drxk/tda18271c2dd */
897 dvb
->fe
[1]->tuner_priv
= dvb
->fe
[0]->tuner_priv
;
898 memcpy(&dvb
->fe
[1]->ops
.tuner_ops
,
899 &dvb
->fe
[0]->ops
.tuner_ops
,
900 sizeof(dvb
->fe
[0]->ops
.tuner_ops
));
904 case EM2884_BOARD_TERRATEC_H5
:
905 terratec_h5_init(dev
);
907 dvb
->dont_attach_fe1
= 1;
909 dvb
->fe
[0] = dvb_attach(drxk_attach
, &terratec_h5_drxk
, &dev
->i2c_adap
, &dvb
->fe
[1]);
914 /* FIXME: do we need a pll semaphore? */
915 dvb
->fe
[0]->sec_priv
= dvb
;
916 sema_init(&dvb
->pll_mutex
, 1);
917 dvb
->gate_ctrl
= dvb
->fe
[0]->ops
.i2c_gate_ctrl
;
918 dvb
->fe
[0]->ops
.i2c_gate_ctrl
= drxk_gate_ctrl
;
921 /* Attach tda18271 to DVB-C frontend */
922 if (dvb
->fe
[0]->ops
.i2c_gate_ctrl
)
923 dvb
->fe
[0]->ops
.i2c_gate_ctrl(dvb
->fe
[0], 1);
924 if (!dvb_attach(tda18271c2dd_attach
, dvb
->fe
[0], &dev
->i2c_adap
, 0x60)) {
928 if (dvb
->fe
[0]->ops
.i2c_gate_ctrl
)
929 dvb
->fe
[0]->ops
.i2c_gate_ctrl(dvb
->fe
[0], 0);
931 /* Hack - needed by drxk/tda18271c2dd */
932 dvb
->fe
[1]->tuner_priv
= dvb
->fe
[0]->tuner_priv
;
933 memcpy(&dvb
->fe
[1]->ops
.tuner_ops
,
934 &dvb
->fe
[0]->ops
.tuner_ops
,
935 sizeof(dvb
->fe
[0]->ops
.tuner_ops
));
938 case EM28174_BOARD_PCTV_460E
:
940 dvb
->fe
[0] = dvb_attach(tda10071_attach
,
941 &em28xx_tda10071_config
, &dev
->i2c_adap
);
945 dvb_attach(a8293_attach
, dvb
->fe
[0], &dev
->i2c_adap
,
946 &em28xx_a8293_config
);
949 em28xx_errdev("/2: The frontend of your DVB/ATSC card"
950 " isn't supported yet\n");
953 if (NULL
== dvb
->fe
[0]) {
954 em28xx_errdev("/2: frontend initialization failed\n");
958 /* define general-purpose callback pointer */
959 dvb
->fe
[0]->callback
= em28xx_tuner_callback
;
961 dvb
->fe
[1]->callback
= em28xx_tuner_callback
;
963 /* register everything */
964 result
= em28xx_register_dvb(dvb
, THIS_MODULE
, dev
, &dev
->udev
->dev
);
970 dvb
->adapter
.mfe_shared
= mfe_shared
;
972 em28xx_info("Successfully loaded em28xx-dvb\n");
974 em28xx_set_mode(dev
, EM28XX_SUSPEND
);
975 mutex_unlock(&dev
->lock
);
984 static inline void prevent_sleep(struct dvb_frontend_ops
*ops
)
986 ops
->set_voltage
= NULL
;
988 ops
->tuner_ops
.sleep
= NULL
;
991 static int em28xx_dvb_fini(struct em28xx
*dev
)
993 if (!dev
->board
.has_dvb
) {
994 /* This device does not support the extension */
999 struct em28xx_dvb
*dvb
= dev
->dvb
;
1001 if (dev
->state
& DEV_DISCONNECTED
) {
1002 /* We cannot tell the device to sleep
1003 * once it has been unplugged. */
1005 prevent_sleep(&dvb
->fe
[0]->ops
);
1007 prevent_sleep(&dvb
->fe
[1]->ops
);
1010 em28xx_unregister_dvb(dvb
);
1018 static struct em28xx_ops dvb_ops
= {
1020 .name
= "Em28xx dvb Extension",
1021 .init
= em28xx_dvb_init
,
1022 .fini
= em28xx_dvb_fini
,
1025 static int __init
em28xx_dvb_register(void)
1027 return em28xx_register_extension(&dvb_ops
);
1030 static void __exit
em28xx_dvb_unregister(void)
1032 em28xx_unregister_extension(&dvb_ops
);
1035 module_init(em28xx_dvb_register
);
1036 module_exit(em28xx_dvb_unregister
);