22 #define pr_fmt(fmt) "dvb_bt8xx: " fmt
24 #include <linux/bitops.h>
25 #include <linux/module.h>
27 #include <linux/kernel.h>
28 #include <linux/device.h>
30 #include <linux/slab.h>
31 #include <linux/i2c.h>
47 #define dprintk( args... ) \
49 if (debug) printk(KERN_DEBUG args); \
52 #define IF_FREQUENCYx6 217
54 static void dvb_bt8xx_task(
unsigned long data)
60 while (card->
bt->last_block != card->
bt->finished_block) {
63 &card->
bt->buf_cpu[card->
bt->last_block *
64 card->
bt->block_bytes],
65 card->
bt->block_bytes);
66 card->
bt->last_block = (card->
bt->last_block + 1) %
67 card->
bt->block_count;
77 dprintk(
"dvb_bt8xx: start_feed\n");
79 if (!dvbdmx->
dmx.frontend)
97 dprintk(
"dvb_bt8xx: stop_feed\n");
99 if (!dvbdmx->
dmx.frontend)
111 static int is_pci_slot_eq(
struct pci_dev* adev,
struct pci_dev* bdev)
115 (adev->
bus->number == bdev->
bus->number) &&
123 unsigned int card_nr;
126 for (card_nr = 0; card_nr <
bt878_num; card_nr++)
127 if (is_pci_slot_eq(
bt878[card_nr].
dev, bttv_pci_dev))
128 return &
bt878[card_nr];
132 static int thomson_dtt7579_demod_init(
struct dvb_frontend* fe)
134 static u8 mt352_clock_config [] = { 0x89, 0x38, 0x38 };
135 static u8 mt352_reset [] = { 0x50, 0x80 };
136 static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 };
137 static u8 mt352_agc_cfg [] = { 0x67, 0x28, 0x20 };
138 static u8 mt352_gpp_ctl_cfg [] = { 0x8C, 0x33 };
139 static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 };
141 mt352_write(fe, mt352_clock_config,
sizeof(mt352_clock_config));
143 mt352_write(fe, mt352_reset,
sizeof(mt352_reset));
144 mt352_write(fe, mt352_adc_ctl_1_cfg,
sizeof(mt352_adc_ctl_1_cfg));
146 mt352_write(fe, mt352_agc_cfg,
sizeof(mt352_agc_cfg));
147 mt352_write(fe, mt352_gpp_ctl_cfg,
sizeof(mt352_gpp_ctl_cfg));
148 mt352_write(fe, mt352_capt_range_cfg,
sizeof(mt352_capt_range_cfg));
153 static int thomson_dtt7579_tuner_calc_regs(
struct dvb_frontend *fe,
u8* pllbuf,
int buf_len)
157 unsigned char bs = 0;
158 unsigned char cp = 0;
180 pllbuf[1] = div >> 8;
181 pllbuf[2] = div & 0xff;
189 .demod_address = 0x0f,
190 .demod_init = thomson_dtt7579_demod_init,
194 .demod_address = 0x0f,
197 static int cx24108_tuner_set_params(
struct dvb_frontend *fe)
203 u32 osci[]={950000,1019000,1075000,1178000,1296000,1432000,
204 1576000,1718000,1856000,2036000,2150000};
205 u32 bandsel[]={0,0x00020000,0x00040000,0x00100800,0x00101000,
206 0x00102000,0x00104000,0x00108000,0x00110000,
207 0x00120000,0x00140000};
210 dprintk(
"cx24108 debug: entering SetTunerFreq, freq=%d\n", freq);
216 else if (freq>2150000)
220 for(i = 1; (i <
ARRAY_SIZE(osci) - 1) && (osci[i] < freq); i++);
221 dprintk(
"cx24108 debug: select vco #%d (f=%d)\n", i, freq);
228 n=((i<=2?2:1)*freq*10L)/(
XTAL/100);
229 a=n%32; n/=32;
if(a==0) n--;
230 pump=(freq<(osci[i-1]+osci[
i])/2);
232 ((pump?1:2)<<(14+11))|
237 dprintk(
"cx24108 debug: pump=%d, n=%d, a=%d\n", pump, n, a);
238 cx24110_pll_write(fe,band);
241 cx24110_pll_write(fe,0x500c0000);
242 cx24110_pll_write(fe,0x83f1f800);
243 cx24110_pll_write(fe,pll);
269 .demod_address = 0x55,
272 static int microtune_mt7202dtf_tuner_set_params(
struct dvb_frontend *fe)
276 u8 cfg, cpump, band_select;
281 div = (36000000 + c->
frequency + 83333) / 166666;
302 data[0] = (div >> 8) & 0x7f;
303 data[1] = div & 0xff;
304 data[2] = ((div >> 10) & 0x60) |
cfg;
305 data[3] = (cpump << 6) | band_select;
307 if (fe->
ops.i2c_gate_ctrl)
308 fe->
ops.i2c_gate_ctrl(fe, 1);
310 return (div * 166666 - 36000000);
321 .demod_address = 0x70,
322 .request_firmware = microtune_mt7202dtf_request_firmware,
325 static int advbt771_samsung_tdtc9251dh0_demod_init(
struct dvb_frontend* fe)
327 static u8 mt352_clock_config [] = { 0x89, 0x38, 0x2d };
328 static u8 mt352_reset [] = { 0x50, 0x80 };
329 static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 };
330 static u8 mt352_agc_cfg [] = { 0x67, 0x10, 0x23, 0x00, 0xFF, 0xFF,
331 0x00, 0xFF, 0x00, 0x40, 0x40 };
332 static u8 mt352_av771_extra[] = { 0xB5, 0x7A };
333 static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 };
335 mt352_write(fe, mt352_clock_config,
sizeof(mt352_clock_config));
337 mt352_write(fe, mt352_reset,
sizeof(mt352_reset));
338 mt352_write(fe, mt352_adc_ctl_1_cfg,
sizeof(mt352_adc_ctl_1_cfg));
340 mt352_write(fe, mt352_agc_cfg,
sizeof(mt352_agc_cfg));
342 mt352_write(fe, mt352_av771_extra,
sizeof(mt352_av771_extra));
343 mt352_write(fe, mt352_capt_range_cfg,
sizeof(mt352_capt_range_cfg));
348 static int advbt771_samsung_tdtc9251dh0_tuner_calc_regs(
struct dvb_frontend *fe,
u8 *pllbuf,
int buf_len)
352 unsigned char bs = 0;
353 unsigned char cp = 0;
355 if (buf_len < 5)
return -
EINVAL;
398 pllbuf[1] = div >> 8;
399 pllbuf[2] = div & 0xff;
406 static struct mt352_config advbt771_samsung_tdtc9251dh0_config = {
407 .demod_address = 0x0f,
408 .demod_init = advbt771_samsung_tdtc9251dh0_demod_init,
415 static int or51211_request_firmware(
struct dvb_frontend* fe,
const struct firmware **fw,
char* name)
462 .request_firmware = or51211_request_firmware,
463 .setmode = or51211_setmode,
464 .reset = or51211_reset,
465 .sleep = or51211_sleep,
468 static int vp3021_alps_tded4_tuner_set_params(
struct dvb_frontend *fe)
474 struct i2c_msg msg = { .addr = 0x60, .flags = 0, .buf =
buf, .len =
sizeof(
buf) };
476 div = (c->
frequency + 36166667) / 166667;
478 buf[0] = (div >> 8) & 0x7F;
492 if (fe->
ops.i2c_gate_ctrl)
493 fe->
ops.i2c_gate_ctrl(fe, 1);
499 .demod_address = 0x0a,
500 .clock_inversion = 1,
503 static int digitv_alps_tded4_demod_init(
struct dvb_frontend* fe)
505 static u8 mt352_clock_config [] = { 0x89, 0x38, 0x2d };
506 static u8 mt352_reset [] = { 0x50, 0x80 };
507 static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 };
508 static u8 mt352_agc_cfg [] = { 0x67, 0x20, 0xa0 };
509 static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 };
511 mt352_write(fe, mt352_clock_config,
sizeof(mt352_clock_config));
513 mt352_write(fe, mt352_reset,
sizeof(mt352_reset));
514 mt352_write(fe, mt352_adc_ctl_1_cfg,
sizeof(mt352_adc_ctl_1_cfg));
515 mt352_write(fe, mt352_agc_cfg,
sizeof(mt352_agc_cfg));
516 mt352_write(fe, mt352_capt_range_cfg,
sizeof(mt352_capt_range_cfg));
521 static int digitv_alps_tded4_tuner_calc_regs(
struct dvb_frontend *fe,
u8 *pllbuf,
int buf_len)
532 pllbuf[1] = (div >> 8) & 0x7F;
533 pllbuf[2] = div & 0xFF;
573 .demod_address = 0x0a,
574 .demod_init = digitv_alps_tded4_demod_init,
578 .demod_address = 0x0e,
609 card->
fe->ops.tuner_ops.calc_regs = thomson_dtt7579_tuner_calc_regs;
610 card->
fe->ops.info.frequency_min = 174000000;
611 card->
fe->ops.info.frequency_max = 862000000;
616 lgdt330x_reset(card);
621 TUNER_LG_TDVS_H06XF);
622 dprintk (
"dvb_bt8xx: lgdt330x detected\n");
633 digitv_alps_tded4_reset(card);
636 card->
fe->ops.tuner_ops.set_params = vp3021_alps_tded4_tuner_set_params;
637 dprintk (
"dvb_bt8xx: an nxt6000 was detected on your digitv card\n");
642 digitv_alps_tded4_reset(card);
646 card->
fe->ops.tuner_ops.calc_regs = digitv_alps_tded4_tuner_calc_regs;
647 dprintk (
"dvb_bt8xx: an mt352 was detected on your digitv card\n");
654 card->
fe->ops.tuner_ops.set_params = microtune_mt7202dtf_tuner_set_params;
661 card->
fe->ops.tuner_ops.calc_regs = advbt771_samsung_tdtc9251dh0_tuner_calc_regs;
662 card->
fe->ops.info.frequency_min = 174000000;
663 card->
fe->ops.info.frequency_max = 862000000;
675 state->
config = &dst_config;
677 state->
bt = card->
bt;
681 pr_err(
"%s: Could not find a Twinhan DST\n", __func__);
694 card->
fe->ops.tuner_ops.init = pinnsat_tuner_init;
695 card->
fe->ops.tuner_ops.sleep = pinnsat_tuner_sleep;
696 card->
fe->ops.tuner_ops.set_params = cx24108_tuner_set_params;
705 TUNER_PHILIPS_FCV1236D);
710 pr_err(
"A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
711 card->
bt->dev->vendor,
712 card->
bt->dev->device,
713 card->
bt->dev->subsystem_vendor,
714 card->
bt->dev->subsystem_device);
717 pr_err(
"Frontend registration failed!\n");
731 pr_err(
"dvb_register_adapter failed (errno = %d)\n", result);
743 card->
demux.filternum = 256;
744 card->
demux.feednum = 256;
745 card->
demux.start_feed = dvb_bt8xx_start_feed;
746 card->
demux.stop_feed = dvb_bt8xx_stop_feed;
751 pr_err(
"dvb_dmx_init failed (errno = %d)\n", result);
752 goto err_unregister_adaptor;
755 card->
dmxdev.filternum = 256;
757 card->
dmxdev.capabilities = 0;
761 pr_err(
"dvb_dmxdev_init failed (errno = %d)\n", result);
762 goto err_dmx_release;
769 pr_err(
"dvb_dmx_init failed (errno = %d)\n", result);
770 goto err_dmxdev_release;
777 pr_err(
"dvb_dmx_init failed (errno = %d)\n", result);
778 goto err_remove_hw_frontend;
781 result = card->
demux.dmx.connect_frontend(&card->
demux.dmx, &card->
fe_hw);
783 pr_err(
"dvb_dmx_init failed (errno = %d)\n", result);
784 goto err_remove_mem_frontend;
789 pr_err(
"dvb_net_init failed (errno = %d)\n", result);
790 goto err_disconnect_frontend;
793 tasklet_init(&card->
bt->tasklet, dvb_bt8xx_task, (
unsigned long) card);
795 frontend_init(card, type);
799 err_disconnect_frontend:
800 card->
demux.dmx.disconnect_frontend(&card->
demux.dmx);
801 err_remove_mem_frontend:
803 err_remove_hw_frontend:
809 err_unregister_adaptor:
828 switch(sub->
core->type) {
854 card->
gpio_mode = (1 << 26) | (1 << 14) | (1 << 5);
892 pr_err(
"Unknown bttv card type: %d\n", sub->
core->type);
905 if (!(card->
bt = dvb_bt8xx_878_match(card->
bttv_nr, bttv_pci_dev))) {
906 pr_err(
"unable to determine DMA core of card %d,\n", card->
bttv_nr);
907 pr_err(
"if you have the ALSA bt87x audio driver installed, try removing it.\n");
914 card->
bt->bttv_nr = sub->
core->nr;
916 if ( (ret = dvb_bt8xx_load_card(card, sub->
core->type)) ) {
951 .probe = dvb_bt8xx_probe,
952 .remove = dvb_bt8xx_remove,
960 static int __init dvb_bt8xx_init(
void)
965 static void __exit dvb_bt8xx_exit(
void)