22 #include <linux/kernel.h>
23 #include <linux/slab.h>
54 static unsigned int debug;
60 #define dprintk(level, fmt, arg...) do { \
62 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \
88 static inline void print_err_status(
struct em28xx *
dev,
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)
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)
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)
164 int max_dvb_packet_size;
172 if (max_dvb_packet_size < 0)
173 return max_dvb_packet_size;
174 dprintk(1,
"Using %d buffers each with %d x %d bytes\n",
177 max_dvb_packet_size);
181 max_dvb_packet_size, em28xx_dvb_isoc_copy);
184 static int em28xx_stop_streaming(
struct em28xx_dvb *dvb)
201 if (!demux->
dmx.frontend)
209 ret = em28xx_start_streaming(dvb);
228 err = em28xx_stop_streaming(dvb);
237 static int em28xx_dvb_bus_ctrl(
struct dvb_frontend *
fe,
int acquire)
250 .demod_address = 0x0e,
257 .spectral_inversion = 1,
267 .demod_address = 0x30 >> 1
271 .demod_address = (0x1e >> 1),
278 .demod_address = 0x32 >> 1,
287 .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0,
288 .if_lvl = 1, .rfagc_top = 0x37, },
289 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1,
290 .if_lvl = 1, .rfagc_top = 0x37, },
294 .std_map = &kworld_a340_std_map,
297 static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = {
298 .demod_address = (0x1e >> 1),
306 .demod_address = 0x70,
307 .demod_revision = 0xa2,
312 .disable_i2c_gate_ctrl = 1,
319 .microcode_name =
"dvb-usb-terratec-h5-drxk.fw",
320 .qam_demod_parameter_count = 2,
321 .load_firmware_sync =
true,
328 .microcode_name =
"dvb-usb-hauppauge-hvr930c-drxk.fw",
330 .qam_demod_parameter_count = 2,
331 .load_firmware_sync =
true,
338 .microcode_name =
"dvb-usb-terratec-htc-stick-drxk.fw",
340 .qam_demod_parameter_count = 2,
342 .antenna_dvbt =
true,
345 .load_firmware_sync =
true,
348 static struct drxk_config maxmedia_ub425_tc_drxk = {
352 .load_firmware_sync =
true,
358 .microcode_name =
"dvb-demod-drxk-pctv.fw",
359 .qam_demod_parameter_count = 2,
361 .antenna_dvbt =
true,
362 .antenna_gpio = (1 << 2),
384 static void hauppauge_hvr930c_init(
struct em28xx *dev)
414 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
416 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
418 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
419 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
421 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
424 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
426 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
451 static void terratec_h5_init(
struct em28xx *dev)
471 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
473 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
475 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
476 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
478 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
481 {{ 0x00, 0x04, 0x00, 0x0a }, 4},
483 {{ 0x04, 0x14, 0x00, 0x00 }, 4},
499 static void terratec_htc_stick_init(
struct em28xx *dev)
528 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
530 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
532 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
550 static void pctv_520e_init(
struct em28xx *dev)
561 {{ 0x06, 0x02, 0x00, 0x31 }, 4},
563 {{ 0x01, 0x02, 0x00, 0xc6 }, 4},
565 {{ 0x01, 0x00, 0xff, 0xaf }, 4},
566 {{ 0x01, 0x00, 0x03, 0xa0 }, 4},
568 {{ 0x01, 0x00, 0x73, 0xaf }, 4},
577 static int em28xx_pctv_290e_set_lna(
struct dvb_frontend *fe)
581 #ifdef CONFIG_GPIOLIB
599 dev_warn(&dev->
udev->dev,
"%s: LNA control is disabled (lna=%u)\n",
600 KBUILD_MODNAME, c->
lna);
605 static int em28xx_mt352_terratec_xs_init(
struct dvb_frontend *fe)
608 static u8 clock_config[] = {
CLOCK_CTL, 0x38, 0x2c };
616 static u8 tps_given_cfg[] = {
TPS_GIVEN_1, 0x40, 0x80, 0x50 };
619 mt352_write(fe, clock_config,
sizeof(clock_config));
621 mt352_write(fe, reset,
sizeof(reset));
622 mt352_write(fe, adc_ctl_1_cfg,
sizeof(adc_ctl_1_cfg));
623 mt352_write(fe, agc_cfg,
sizeof(agc_cfg));
624 mt352_write(fe, input_freq_cfg,
sizeof(input_freq_cfg));
625 mt352_write(fe, rs_err_cfg,
sizeof(rs_err_cfg));
626 mt352_write(fe, capt_range_cfg,
sizeof(capt_range_cfg));
627 mt352_write(fe, trl_nom_cfg,
sizeof(trl_nom_cfg));
628 mt352_write(fe, tps_given_cfg,
sizeof(tps_given_cfg));
629 mt352_write(fe, tuner_go,
sizeof(tuner_go));
634 .demod_address = (0x1e >> 1),
641 .demod_address = 0x0c,
646 .i2c_address = (0xd8 >> 1),
661 .pll_multiplier = 20,
664 static const struct a8293_config em28xx_a8293_config = {
669 .demod_address = (0x1e >> 1),
681 static int em28xx_attach_xc3028(
u8 addr,
struct em28xx *dev)
690 if (!dev->
dvb->fe[0]) {
692 "Can't attach xc3028\n");
728 dvb->
fe[0]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
730 dvb->
fe[1]->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
753 dvb->
demux.dmx.capabilities =
756 dvb->
demux.priv = dvb;
757 dvb->
demux.filternum = 256;
758 dvb->
demux.feednum = 256;
759 dvb->
demux.start_feed = em28xx_start_feed;
760 dvb->
demux.stop_feed = em28xx_stop_feed;
769 dvb->
dmxdev.filternum = 256;
771 dvb->
dmxdev.capabilities = 0;
795 result = dvb->
demux.dmx.connect_frontend(&dvb->
demux.dmx, &dvb->
fe_hw);
828 static void em28xx_unregister_dvb(
struct em28xx_dvb *dvb)
844 static int em28xx_dvb_init(
struct em28xx *dev)
846 int result = 0, mfe_shared = 0;
849 if (!dev->
board.has_dvb) {
851 printk(
KERN_INFO "em28xx_dvb: This device does not support the extension\n");
858 em28xx_info(
"em28xx_dvb: memory allocation failed\n");
867 switch (dev->
model) {
883 &em2880_lgdt3303_dev,
885 if (em28xx_attach_xc3028(0x61, dev) < 0) {
892 &em28xx_zl10353_with_xc3028,
894 if (em28xx_attach_xc3028(0x61, dev) < 0) {
903 &em28xx_zl10353_xc3028_no_i2c_gate,
905 if (em28xx_attach_xc3028(0x61, dev) < 0) {
916 &em28xx_zl10353_xc3028_no_i2c_gate,
922 &terratec_xs_mt352_cfg,
926 if (em28xx_attach_xc3028(0x61, dev) < 0) {
933 &em28xx_zl10353_no_i2c_gate_dev,
937 &dev->
i2c_adap, &em28xx_qt1010_config);
942 &em28xx_s5h1409_with_xc3028,
944 if (em28xx_attach_xc3028(0x61, dev) < 0) {
951 &em2880_lgdt3303_dev,
955 &dev->
i2c_adap, 0x61, TUNER_THOMSON_DTT761X)) {
965 if (em28xx_attach_xc3028(0x61, dev) < 0) {
973 &em28xx_tda10023_config,
977 &dev->
i2c_adap, 0x60, TUNER_PHILIPS_CU1216L)) {
985 &em2870_lgdt3304_dev,
989 &dev->
i2c_adap, &kworld_a340_config);
996 &em28xx_cxd2820r_config,
1005 &em28xx_cxd2820r_tda18271_config)) {
1012 #ifdef CONFIG_GPIOLIB
1024 dvb->
fe[0]->ops.set_lna = em28xx_pctv_290e_set_lna;
1031 hauppauge_hvr930c_init(dev);
1034 &hauppauge_930c_drxk, &dev->
i2c_adap);
1040 dvb->
fe[0]->sec_priv = dvb;
1043 dvb->
fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
1047 cfg.i2c_address = 0x61;
1050 if (dvb->
fe[0]->ops.i2c_gate_ctrl)
1051 dvb->
fe[0]->ops.i2c_gate_ctrl(dvb->
fe[0], 1);
1057 if (dvb->
fe[0]->ops.i2c_gate_ctrl)
1058 dvb->
fe[0]->ops.i2c_gate_ctrl(dvb->
fe[0], 0);
1063 terratec_h5_init(dev);
1071 dvb->
fe[0]->sec_priv = dvb;
1074 dvb->
fe[0]->ops.i2c_gate_ctrl = drxk_gate_ctrl;
1077 if (dvb->
fe[0]->ops.i2c_gate_ctrl)
1078 dvb->
fe[0]->ops.i2c_gate_ctrl(dvb->
fe[0], 1);
1083 if (dvb->
fe[0]->ops.i2c_gate_ctrl)
1084 dvb->
fe[0]->ops.i2c_gate_ctrl(dvb->
fe[0], 0);
1090 &em28xx_tda10071_config, &dev->
i2c_adap);
1095 &em28xx_a8293_config);
1104 dvb->
fe[0]->ops.i2c_gate_ctrl =
NULL;
1116 em28xx_info(
"MaxMedia UB425-TC: only DVB-C supported by that " \
1117 "driver version\n");
1122 pctv_520e_init(dev);
1132 &em28xx_cxd2820r_tda18271_config)) {
1140 terratec_htc_stick_init(dev);
1153 &em28xx_cxd2820r_tda18271_config)) {
1160 " isn't supported yet\n");
1163 if (
NULL == dvb->
fe[0]) {
1180 dvb->
adapter.mfe_shared = mfe_shared;
1201 static int em28xx_dvb_fini(
struct em28xx *dev)
1203 if (!dev->
board.has_dvb) {
1215 prevent_sleep(&dvb->
fe[0]->ops);
1217 prevent_sleep(&dvb->
fe[1]->ops);
1220 em28xx_unregister_dvb(dvb);
1230 .name =
"Em28xx dvb Extension",
1231 .init = em28xx_dvb_init,
1232 .fini = em28xx_dvb_fini,
1235 static int __init em28xx_dvb_register(
void)
1240 static void __exit em28xx_dvb_unregister(
void)