1*c942fddfSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 225aee3deSMauro Carvalho Chehab /* 325aee3deSMauro Carvalho Chehab * Bt8xx based DVB adapter driver 425aee3deSMauro Carvalho Chehab * 525aee3deSMauro Carvalho Chehab * Copyright (C) 2002,2003 Florian Schirmer <jolt@tuxbox.org> 625aee3deSMauro Carvalho Chehab */ 725aee3deSMauro Carvalho Chehab 8fa132a64SMauro Carvalho Chehab #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 925aee3deSMauro Carvalho Chehab 1025aee3deSMauro Carvalho Chehab #include <linux/bitops.h> 1125aee3deSMauro Carvalho Chehab #include <linux/module.h> 1225aee3deSMauro Carvalho Chehab #include <linux/init.h> 1325aee3deSMauro Carvalho Chehab #include <linux/kernel.h> 1425aee3deSMauro Carvalho Chehab #include <linux/device.h> 1525aee3deSMauro Carvalho Chehab #include <linux/delay.h> 1625aee3deSMauro Carvalho Chehab #include <linux/slab.h> 1725aee3deSMauro Carvalho Chehab #include <linux/i2c.h> 1825aee3deSMauro Carvalho Chehab 19fada1935SMauro Carvalho Chehab #include <media/dmxdev.h> 20fada1935SMauro Carvalho Chehab #include <media/dvbdev.h> 21fada1935SMauro Carvalho Chehab #include <media/dvb_demux.h> 22fada1935SMauro Carvalho Chehab #include <media/dvb_frontend.h> 2325aee3deSMauro Carvalho Chehab #include "dvb-bt8xx.h" 2425aee3deSMauro Carvalho Chehab #include "bt878.h" 2525aee3deSMauro Carvalho Chehab 2625aee3deSMauro Carvalho Chehab static int debug; 2725aee3deSMauro Carvalho Chehab 2825aee3deSMauro Carvalho Chehab module_param(debug, int, 0644); 2925aee3deSMauro Carvalho Chehab MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off)."); 3025aee3deSMauro Carvalho Chehab 3125aee3deSMauro Carvalho Chehab DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 3225aee3deSMauro Carvalho Chehab 33fa132a64SMauro Carvalho Chehab #define dprintk(fmt, arg...) do { \ 34fa132a64SMauro Carvalho Chehab if (debug) \ 35fa132a64SMauro Carvalho Chehab printk(KERN_DEBUG pr_fmt("%s: " fmt), \ 36fa132a64SMauro Carvalho Chehab __func__, ##arg); \ 3725aee3deSMauro Carvalho Chehab } while (0) 3825aee3deSMauro Carvalho Chehab 39fa132a64SMauro Carvalho Chehab 4025aee3deSMauro Carvalho Chehab #define IF_FREQUENCYx6 217 /* 6 * 36.16666666667MHz */ 4125aee3deSMauro Carvalho Chehab 4225aee3deSMauro Carvalho Chehab static void dvb_bt8xx_task(unsigned long data) 4325aee3deSMauro Carvalho Chehab { 4425aee3deSMauro Carvalho Chehab struct dvb_bt8xx_card *card = (struct dvb_bt8xx_card *)data; 4525aee3deSMauro Carvalho Chehab 46fa132a64SMauro Carvalho Chehab dprintk("%d\n", card->bt->finished_block); 4725aee3deSMauro Carvalho Chehab 4825aee3deSMauro Carvalho Chehab while (card->bt->last_block != card->bt->finished_block) { 4925aee3deSMauro Carvalho Chehab (card->bt->TS_Size ? dvb_dmx_swfilter_204 : dvb_dmx_swfilter) 5025aee3deSMauro Carvalho Chehab (&card->demux, 5125aee3deSMauro Carvalho Chehab &card->bt->buf_cpu[card->bt->last_block * 5225aee3deSMauro Carvalho Chehab card->bt->block_bytes], 5325aee3deSMauro Carvalho Chehab card->bt->block_bytes); 5425aee3deSMauro Carvalho Chehab card->bt->last_block = (card->bt->last_block + 1) % 5525aee3deSMauro Carvalho Chehab card->bt->block_count; 5625aee3deSMauro Carvalho Chehab } 5725aee3deSMauro Carvalho Chehab } 5825aee3deSMauro Carvalho Chehab 5925aee3deSMauro Carvalho Chehab static int dvb_bt8xx_start_feed(struct dvb_demux_feed *dvbdmxfeed) 6025aee3deSMauro Carvalho Chehab { 6125aee3deSMauro Carvalho Chehab struct dvb_demux*dvbdmx = dvbdmxfeed->demux; 6225aee3deSMauro Carvalho Chehab struct dvb_bt8xx_card *card = dvbdmx->priv; 6325aee3deSMauro Carvalho Chehab int rc; 6425aee3deSMauro Carvalho Chehab 6525aee3deSMauro Carvalho Chehab dprintk("dvb_bt8xx: start_feed\n"); 6625aee3deSMauro Carvalho Chehab 6725aee3deSMauro Carvalho Chehab if (!dvbdmx->dmx.frontend) 6825aee3deSMauro Carvalho Chehab return -EINVAL; 6925aee3deSMauro Carvalho Chehab 7025aee3deSMauro Carvalho Chehab mutex_lock(&card->lock); 7125aee3deSMauro Carvalho Chehab card->nfeeds++; 7225aee3deSMauro Carvalho Chehab rc = card->nfeeds; 7325aee3deSMauro Carvalho Chehab if (card->nfeeds == 1) 7425aee3deSMauro Carvalho Chehab bt878_start(card->bt, card->gpio_mode, 7525aee3deSMauro Carvalho Chehab card->op_sync_orin, card->irq_err_ignore); 7625aee3deSMauro Carvalho Chehab mutex_unlock(&card->lock); 7725aee3deSMauro Carvalho Chehab return rc; 7825aee3deSMauro Carvalho Chehab } 7925aee3deSMauro Carvalho Chehab 8025aee3deSMauro Carvalho Chehab static int dvb_bt8xx_stop_feed(struct dvb_demux_feed *dvbdmxfeed) 8125aee3deSMauro Carvalho Chehab { 8225aee3deSMauro Carvalho Chehab struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 8325aee3deSMauro Carvalho Chehab struct dvb_bt8xx_card *card = dvbdmx->priv; 8425aee3deSMauro Carvalho Chehab 8525aee3deSMauro Carvalho Chehab dprintk("dvb_bt8xx: stop_feed\n"); 8625aee3deSMauro Carvalho Chehab 8725aee3deSMauro Carvalho Chehab if (!dvbdmx->dmx.frontend) 8825aee3deSMauro Carvalho Chehab return -EINVAL; 8925aee3deSMauro Carvalho Chehab 9025aee3deSMauro Carvalho Chehab mutex_lock(&card->lock); 9125aee3deSMauro Carvalho Chehab card->nfeeds--; 9225aee3deSMauro Carvalho Chehab if (card->nfeeds == 0) 9325aee3deSMauro Carvalho Chehab bt878_stop(card->bt); 9425aee3deSMauro Carvalho Chehab mutex_unlock(&card->lock); 9525aee3deSMauro Carvalho Chehab 9625aee3deSMauro Carvalho Chehab return 0; 9725aee3deSMauro Carvalho Chehab } 9825aee3deSMauro Carvalho Chehab 9925aee3deSMauro Carvalho Chehab static int is_pci_slot_eq(struct pci_dev* adev, struct pci_dev* bdev) 10025aee3deSMauro Carvalho Chehab { 10125aee3deSMauro Carvalho Chehab if ((adev->subsystem_vendor == bdev->subsystem_vendor) && 10225aee3deSMauro Carvalho Chehab (adev->subsystem_device == bdev->subsystem_device) && 10325aee3deSMauro Carvalho Chehab (adev->bus->number == bdev->bus->number) && 10425aee3deSMauro Carvalho Chehab (PCI_SLOT(adev->devfn) == PCI_SLOT(bdev->devfn))) 10525aee3deSMauro Carvalho Chehab return 1; 10625aee3deSMauro Carvalho Chehab return 0; 10725aee3deSMauro Carvalho Chehab } 10825aee3deSMauro Carvalho Chehab 1094c62e976SGreg Kroah-Hartman static struct bt878 *dvb_bt8xx_878_match(unsigned int bttv_nr, 1104c62e976SGreg Kroah-Hartman struct pci_dev* bttv_pci_dev) 11125aee3deSMauro Carvalho Chehab { 11225aee3deSMauro Carvalho Chehab unsigned int card_nr; 11325aee3deSMauro Carvalho Chehab 11425aee3deSMauro Carvalho Chehab /* Hmm, n squared. Hope n is small */ 11525aee3deSMauro Carvalho Chehab for (card_nr = 0; card_nr < bt878_num; card_nr++) 11625aee3deSMauro Carvalho Chehab if (is_pci_slot_eq(bt878[card_nr].dev, bttv_pci_dev)) 11725aee3deSMauro Carvalho Chehab return &bt878[card_nr]; 11825aee3deSMauro Carvalho Chehab return NULL; 11925aee3deSMauro Carvalho Chehab } 12025aee3deSMauro Carvalho Chehab 12125aee3deSMauro Carvalho Chehab static int thomson_dtt7579_demod_init(struct dvb_frontend* fe) 12225aee3deSMauro Carvalho Chehab { 12325aee3deSMauro Carvalho Chehab static u8 mt352_clock_config [] = { 0x89, 0x38, 0x38 }; 12425aee3deSMauro Carvalho Chehab static u8 mt352_reset [] = { 0x50, 0x80 }; 12525aee3deSMauro Carvalho Chehab static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 }; 12625aee3deSMauro Carvalho Chehab static u8 mt352_agc_cfg [] = { 0x67, 0x28, 0x20 }; 12725aee3deSMauro Carvalho Chehab static u8 mt352_gpp_ctl_cfg [] = { 0x8C, 0x33 }; 12825aee3deSMauro Carvalho Chehab static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 }; 12925aee3deSMauro Carvalho Chehab 13025aee3deSMauro Carvalho Chehab mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config)); 13125aee3deSMauro Carvalho Chehab udelay(2000); 13225aee3deSMauro Carvalho Chehab mt352_write(fe, mt352_reset, sizeof(mt352_reset)); 13325aee3deSMauro Carvalho Chehab mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg)); 13425aee3deSMauro Carvalho Chehab 13525aee3deSMauro Carvalho Chehab mt352_write(fe, mt352_agc_cfg, sizeof(mt352_agc_cfg)); 13625aee3deSMauro Carvalho Chehab mt352_write(fe, mt352_gpp_ctl_cfg, sizeof(mt352_gpp_ctl_cfg)); 13725aee3deSMauro Carvalho Chehab mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg)); 13825aee3deSMauro Carvalho Chehab 13925aee3deSMauro Carvalho Chehab return 0; 14025aee3deSMauro Carvalho Chehab } 14125aee3deSMauro Carvalho Chehab 14225aee3deSMauro Carvalho Chehab static int thomson_dtt7579_tuner_calc_regs(struct dvb_frontend *fe, u8* pllbuf, int buf_len) 14325aee3deSMauro Carvalho Chehab { 14425aee3deSMauro Carvalho Chehab struct dtv_frontend_properties *c = &fe->dtv_property_cache; 14525aee3deSMauro Carvalho Chehab u32 div; 14625aee3deSMauro Carvalho Chehab unsigned char bs = 0; 14725aee3deSMauro Carvalho Chehab unsigned char cp = 0; 14825aee3deSMauro Carvalho Chehab 14925aee3deSMauro Carvalho Chehab if (buf_len < 5) 15025aee3deSMauro Carvalho Chehab return -EINVAL; 15125aee3deSMauro Carvalho Chehab 15225aee3deSMauro Carvalho Chehab div = (((c->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6; 15325aee3deSMauro Carvalho Chehab 15425aee3deSMauro Carvalho Chehab if (c->frequency < 542000000) 15525aee3deSMauro Carvalho Chehab cp = 0xb4; 15625aee3deSMauro Carvalho Chehab else if (c->frequency < 771000000) 15725aee3deSMauro Carvalho Chehab cp = 0xbc; 15825aee3deSMauro Carvalho Chehab else 15925aee3deSMauro Carvalho Chehab cp = 0xf4; 16025aee3deSMauro Carvalho Chehab 16125aee3deSMauro Carvalho Chehab if (c->frequency == 0) 16225aee3deSMauro Carvalho Chehab bs = 0x03; 16325aee3deSMauro Carvalho Chehab else if (c->frequency < 443250000) 16425aee3deSMauro Carvalho Chehab bs = 0x02; 16525aee3deSMauro Carvalho Chehab else 16625aee3deSMauro Carvalho Chehab bs = 0x08; 16725aee3deSMauro Carvalho Chehab 16825aee3deSMauro Carvalho Chehab pllbuf[0] = 0x60; 16925aee3deSMauro Carvalho Chehab pllbuf[1] = div >> 8; 17025aee3deSMauro Carvalho Chehab pllbuf[2] = div & 0xff; 17125aee3deSMauro Carvalho Chehab pllbuf[3] = cp; 17225aee3deSMauro Carvalho Chehab pllbuf[4] = bs; 17325aee3deSMauro Carvalho Chehab 17425aee3deSMauro Carvalho Chehab return 5; 17525aee3deSMauro Carvalho Chehab } 17625aee3deSMauro Carvalho Chehab 17725aee3deSMauro Carvalho Chehab static struct mt352_config thomson_dtt7579_config = { 17825aee3deSMauro Carvalho Chehab .demod_address = 0x0f, 17925aee3deSMauro Carvalho Chehab .demod_init = thomson_dtt7579_demod_init, 18025aee3deSMauro Carvalho Chehab }; 18125aee3deSMauro Carvalho Chehab 18225aee3deSMauro Carvalho Chehab static struct zl10353_config thomson_dtt7579_zl10353_config = { 18325aee3deSMauro Carvalho Chehab .demod_address = 0x0f, 18425aee3deSMauro Carvalho Chehab }; 18525aee3deSMauro Carvalho Chehab 18625aee3deSMauro Carvalho Chehab static int cx24108_tuner_set_params(struct dvb_frontend *fe) 18725aee3deSMauro Carvalho Chehab { 18825aee3deSMauro Carvalho Chehab struct dtv_frontend_properties *c = &fe->dtv_property_cache; 18925aee3deSMauro Carvalho Chehab u32 freq = c->frequency; 19025aee3deSMauro Carvalho Chehab int i, a, n, pump; 19125aee3deSMauro Carvalho Chehab u32 band, pll; 19225aee3deSMauro Carvalho Chehab u32 osci[]={950000,1019000,1075000,1178000,1296000,1432000, 19325aee3deSMauro Carvalho Chehab 1576000,1718000,1856000,2036000,2150000}; 19425aee3deSMauro Carvalho Chehab u32 bandsel[]={0,0x00020000,0x00040000,0x00100800,0x00101000, 19525aee3deSMauro Carvalho Chehab 0x00102000,0x00104000,0x00108000,0x00110000, 19625aee3deSMauro Carvalho Chehab 0x00120000,0x00140000}; 19725aee3deSMauro Carvalho Chehab 19825aee3deSMauro Carvalho Chehab #define XTAL 1011100 /* Hz, really 1.0111 MHz and a /10 prescaler */ 19925aee3deSMauro Carvalho Chehab dprintk("cx24108 debug: entering SetTunerFreq, freq=%d\n", freq); 20025aee3deSMauro Carvalho Chehab 20125aee3deSMauro Carvalho Chehab /* This is really the bit driving the tuner chip cx24108 */ 20225aee3deSMauro Carvalho Chehab 20325aee3deSMauro Carvalho Chehab if (freq<950000) 20425aee3deSMauro Carvalho Chehab freq = 950000; /* kHz */ 20525aee3deSMauro Carvalho Chehab else if (freq>2150000) 20625aee3deSMauro Carvalho Chehab freq = 2150000; /* satellite IF is 950..2150MHz */ 20725aee3deSMauro Carvalho Chehab 20825aee3deSMauro Carvalho Chehab /* decide which VCO to use for the input frequency */ 20925aee3deSMauro Carvalho Chehab for(i = 1; (i < ARRAY_SIZE(osci) - 1) && (osci[i] < freq); i++); 21025aee3deSMauro Carvalho Chehab dprintk("cx24108 debug: select vco #%d (f=%d)\n", i, freq); 21125aee3deSMauro Carvalho Chehab band=bandsel[i]; 21225aee3deSMauro Carvalho Chehab /* the gain values must be set by SetSymbolrate */ 21325aee3deSMauro Carvalho Chehab /* compute the pll divider needed, from Conexant data sheet, 21425aee3deSMauro Carvalho Chehab resolved for (n*32+a), remember f(vco) is f(receive) *2 or *4, 21525aee3deSMauro Carvalho Chehab depending on the divider bit. It is set to /4 on the 2 lowest 21625aee3deSMauro Carvalho Chehab bands */ 21725aee3deSMauro Carvalho Chehab n=((i<=2?2:1)*freq*10L)/(XTAL/100); 21825aee3deSMauro Carvalho Chehab a=n%32; n/=32; if(a==0) n--; 21925aee3deSMauro Carvalho Chehab pump=(freq<(osci[i-1]+osci[i])/2); 22025aee3deSMauro Carvalho Chehab pll=0xf8000000| 22125aee3deSMauro Carvalho Chehab ((pump?1:2)<<(14+11))| 22225aee3deSMauro Carvalho Chehab ((n&0x1ff)<<(5+11))| 22325aee3deSMauro Carvalho Chehab ((a&0x1f)<<11); 22425aee3deSMauro Carvalho Chehab /* everything is shifted left 11 bits to left-align the bits in the 22525aee3deSMauro Carvalho Chehab 32bit word. Output to the tuner goes MSB-aligned, after all */ 22625aee3deSMauro Carvalho Chehab dprintk("cx24108 debug: pump=%d, n=%d, a=%d\n", pump, n, a); 22725aee3deSMauro Carvalho Chehab cx24110_pll_write(fe,band); 22825aee3deSMauro Carvalho Chehab /* set vga and vca to their widest-band settings, as a precaution. 22925aee3deSMauro Carvalho Chehab SetSymbolrate might not be called to set this up */ 23025aee3deSMauro Carvalho Chehab cx24110_pll_write(fe,0x500c0000); 23125aee3deSMauro Carvalho Chehab cx24110_pll_write(fe,0x83f1f800); 23225aee3deSMauro Carvalho Chehab cx24110_pll_write(fe,pll); 23325aee3deSMauro Carvalho Chehab //writereg(client,0x56,0x7f); 23425aee3deSMauro Carvalho Chehab 23525aee3deSMauro Carvalho Chehab return 0; 23625aee3deSMauro Carvalho Chehab } 23725aee3deSMauro Carvalho Chehab 23825aee3deSMauro Carvalho Chehab static int pinnsat_tuner_init(struct dvb_frontend* fe) 23925aee3deSMauro Carvalho Chehab { 24025aee3deSMauro Carvalho Chehab struct dvb_bt8xx_card *card = fe->dvb->priv; 24125aee3deSMauro Carvalho Chehab 24225aee3deSMauro Carvalho Chehab bttv_gpio_enable(card->bttv_nr, 1, 1); /* output */ 24325aee3deSMauro Carvalho Chehab bttv_write_gpio(card->bttv_nr, 1, 1); /* relay on */ 24425aee3deSMauro Carvalho Chehab 24525aee3deSMauro Carvalho Chehab return 0; 24625aee3deSMauro Carvalho Chehab } 24725aee3deSMauro Carvalho Chehab 24825aee3deSMauro Carvalho Chehab static int pinnsat_tuner_sleep(struct dvb_frontend* fe) 24925aee3deSMauro Carvalho Chehab { 25025aee3deSMauro Carvalho Chehab struct dvb_bt8xx_card *card = fe->dvb->priv; 25125aee3deSMauro Carvalho Chehab 25225aee3deSMauro Carvalho Chehab bttv_write_gpio(card->bttv_nr, 1, 0); /* relay off */ 25325aee3deSMauro Carvalho Chehab 25425aee3deSMauro Carvalho Chehab return 0; 25525aee3deSMauro Carvalho Chehab } 25625aee3deSMauro Carvalho Chehab 25725aee3deSMauro Carvalho Chehab static struct cx24110_config pctvsat_config = { 25825aee3deSMauro Carvalho Chehab .demod_address = 0x55, 25925aee3deSMauro Carvalho Chehab }; 26025aee3deSMauro Carvalho Chehab 26125aee3deSMauro Carvalho Chehab static int microtune_mt7202dtf_tuner_set_params(struct dvb_frontend *fe) 26225aee3deSMauro Carvalho Chehab { 26325aee3deSMauro Carvalho Chehab struct dtv_frontend_properties *c = &fe->dtv_property_cache; 26425aee3deSMauro Carvalho Chehab struct dvb_bt8xx_card *card = (struct dvb_bt8xx_card *) fe->dvb->priv; 26525aee3deSMauro Carvalho Chehab u8 cfg, cpump, band_select; 26625aee3deSMauro Carvalho Chehab u8 data[4]; 26725aee3deSMauro Carvalho Chehab u32 div; 26825aee3deSMauro Carvalho Chehab struct i2c_msg msg = { .addr = 0x60, .flags = 0, .buf = data, .len = sizeof(data) }; 26925aee3deSMauro Carvalho Chehab 27025aee3deSMauro Carvalho Chehab div = (36000000 + c->frequency + 83333) / 166666; 27125aee3deSMauro Carvalho Chehab cfg = 0x88; 27225aee3deSMauro Carvalho Chehab 27325aee3deSMauro Carvalho Chehab if (c->frequency < 175000000) 27425aee3deSMauro Carvalho Chehab cpump = 2; 27525aee3deSMauro Carvalho Chehab else if (c->frequency < 390000000) 27625aee3deSMauro Carvalho Chehab cpump = 1; 27725aee3deSMauro Carvalho Chehab else if (c->frequency < 470000000) 27825aee3deSMauro Carvalho Chehab cpump = 2; 27925aee3deSMauro Carvalho Chehab else if (c->frequency < 750000000) 28025aee3deSMauro Carvalho Chehab cpump = 2; 28125aee3deSMauro Carvalho Chehab else 28225aee3deSMauro Carvalho Chehab cpump = 3; 28325aee3deSMauro Carvalho Chehab 28425aee3deSMauro Carvalho Chehab if (c->frequency < 175000000) 28525aee3deSMauro Carvalho Chehab band_select = 0x0e; 28625aee3deSMauro Carvalho Chehab else if (c->frequency < 470000000) 28725aee3deSMauro Carvalho Chehab band_select = 0x05; 28825aee3deSMauro Carvalho Chehab else 28925aee3deSMauro Carvalho Chehab band_select = 0x03; 29025aee3deSMauro Carvalho Chehab 29125aee3deSMauro Carvalho Chehab data[0] = (div >> 8) & 0x7f; 29225aee3deSMauro Carvalho Chehab data[1] = div & 0xff; 29325aee3deSMauro Carvalho Chehab data[2] = ((div >> 10) & 0x60) | cfg; 29425aee3deSMauro Carvalho Chehab data[3] = (cpump << 6) | band_select; 29525aee3deSMauro Carvalho Chehab 29625aee3deSMauro Carvalho Chehab if (fe->ops.i2c_gate_ctrl) 29725aee3deSMauro Carvalho Chehab fe->ops.i2c_gate_ctrl(fe, 1); 29825aee3deSMauro Carvalho Chehab i2c_transfer(card->i2c_adapter, &msg, 1); 29925aee3deSMauro Carvalho Chehab return (div * 166666 - 36000000); 30025aee3deSMauro Carvalho Chehab } 30125aee3deSMauro Carvalho Chehab 30225aee3deSMauro Carvalho Chehab static int microtune_mt7202dtf_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name) 30325aee3deSMauro Carvalho Chehab { 30425aee3deSMauro Carvalho Chehab struct dvb_bt8xx_card* bt = (struct dvb_bt8xx_card*) fe->dvb->priv; 30525aee3deSMauro Carvalho Chehab 30625aee3deSMauro Carvalho Chehab return request_firmware(fw, name, &bt->bt->dev->dev); 30725aee3deSMauro Carvalho Chehab } 30825aee3deSMauro Carvalho Chehab 30964e423d4SJulia Lawall static const struct sp887x_config microtune_mt7202dtf_config = { 31025aee3deSMauro Carvalho Chehab .demod_address = 0x70, 31125aee3deSMauro Carvalho Chehab .request_firmware = microtune_mt7202dtf_request_firmware, 31225aee3deSMauro Carvalho Chehab }; 31325aee3deSMauro Carvalho Chehab 31425aee3deSMauro Carvalho Chehab static int advbt771_samsung_tdtc9251dh0_demod_init(struct dvb_frontend* fe) 31525aee3deSMauro Carvalho Chehab { 31625aee3deSMauro Carvalho Chehab static u8 mt352_clock_config [] = { 0x89, 0x38, 0x2d }; 31725aee3deSMauro Carvalho Chehab static u8 mt352_reset [] = { 0x50, 0x80 }; 31825aee3deSMauro Carvalho Chehab static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 }; 31925aee3deSMauro Carvalho Chehab static u8 mt352_agc_cfg [] = { 0x67, 0x10, 0x23, 0x00, 0xFF, 0xFF, 32025aee3deSMauro Carvalho Chehab 0x00, 0xFF, 0x00, 0x40, 0x40 }; 32125aee3deSMauro Carvalho Chehab static u8 mt352_av771_extra[] = { 0xB5, 0x7A }; 32225aee3deSMauro Carvalho Chehab static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 }; 32325aee3deSMauro Carvalho Chehab 32425aee3deSMauro Carvalho Chehab mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config)); 32525aee3deSMauro Carvalho Chehab udelay(2000); 32625aee3deSMauro Carvalho Chehab mt352_write(fe, mt352_reset, sizeof(mt352_reset)); 32725aee3deSMauro Carvalho Chehab mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg)); 32825aee3deSMauro Carvalho Chehab 32925aee3deSMauro Carvalho Chehab mt352_write(fe, mt352_agc_cfg,sizeof(mt352_agc_cfg)); 33025aee3deSMauro Carvalho Chehab udelay(2000); 33125aee3deSMauro Carvalho Chehab mt352_write(fe, mt352_av771_extra,sizeof(mt352_av771_extra)); 33225aee3deSMauro Carvalho Chehab mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg)); 33325aee3deSMauro Carvalho Chehab 33425aee3deSMauro Carvalho Chehab return 0; 33525aee3deSMauro Carvalho Chehab } 33625aee3deSMauro Carvalho Chehab 33725aee3deSMauro Carvalho Chehab static int advbt771_samsung_tdtc9251dh0_tuner_calc_regs(struct dvb_frontend *fe, u8 *pllbuf, int buf_len) 33825aee3deSMauro Carvalho Chehab { 33925aee3deSMauro Carvalho Chehab struct dtv_frontend_properties *c = &fe->dtv_property_cache; 34025aee3deSMauro Carvalho Chehab u32 div; 34125aee3deSMauro Carvalho Chehab unsigned char bs = 0; 34225aee3deSMauro Carvalho Chehab unsigned char cp = 0; 34325aee3deSMauro Carvalho Chehab 34425aee3deSMauro Carvalho Chehab if (buf_len < 5) return -EINVAL; 34525aee3deSMauro Carvalho Chehab 34625aee3deSMauro Carvalho Chehab div = (((c->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6; 34725aee3deSMauro Carvalho Chehab 34825aee3deSMauro Carvalho Chehab if (c->frequency < 150000000) 34925aee3deSMauro Carvalho Chehab cp = 0xB4; 35025aee3deSMauro Carvalho Chehab else if (c->frequency < 173000000) 35125aee3deSMauro Carvalho Chehab cp = 0xBC; 35225aee3deSMauro Carvalho Chehab else if (c->frequency < 250000000) 35325aee3deSMauro Carvalho Chehab cp = 0xB4; 35425aee3deSMauro Carvalho Chehab else if (c->frequency < 400000000) 35525aee3deSMauro Carvalho Chehab cp = 0xBC; 35625aee3deSMauro Carvalho Chehab else if (c->frequency < 420000000) 35725aee3deSMauro Carvalho Chehab cp = 0xF4; 35825aee3deSMauro Carvalho Chehab else if (c->frequency < 470000000) 35925aee3deSMauro Carvalho Chehab cp = 0xFC; 36025aee3deSMauro Carvalho Chehab else if (c->frequency < 600000000) 36125aee3deSMauro Carvalho Chehab cp = 0xBC; 36225aee3deSMauro Carvalho Chehab else if (c->frequency < 730000000) 36325aee3deSMauro Carvalho Chehab cp = 0xF4; 36425aee3deSMauro Carvalho Chehab else 36525aee3deSMauro Carvalho Chehab cp = 0xFC; 36625aee3deSMauro Carvalho Chehab 36725aee3deSMauro Carvalho Chehab if (c->frequency < 150000000) 36825aee3deSMauro Carvalho Chehab bs = 0x01; 36925aee3deSMauro Carvalho Chehab else if (c->frequency < 173000000) 37025aee3deSMauro Carvalho Chehab bs = 0x01; 37125aee3deSMauro Carvalho Chehab else if (c->frequency < 250000000) 37225aee3deSMauro Carvalho Chehab bs = 0x02; 37325aee3deSMauro Carvalho Chehab else if (c->frequency < 400000000) 37425aee3deSMauro Carvalho Chehab bs = 0x02; 37525aee3deSMauro Carvalho Chehab else if (c->frequency < 420000000) 37625aee3deSMauro Carvalho Chehab bs = 0x02; 37725aee3deSMauro Carvalho Chehab else if (c->frequency < 470000000) 37825aee3deSMauro Carvalho Chehab bs = 0x02; 37925aee3deSMauro Carvalho Chehab else 38025aee3deSMauro Carvalho Chehab bs = 0x08; 38125aee3deSMauro Carvalho Chehab 38225aee3deSMauro Carvalho Chehab pllbuf[0] = 0x61; 38325aee3deSMauro Carvalho Chehab pllbuf[1] = div >> 8; 38425aee3deSMauro Carvalho Chehab pllbuf[2] = div & 0xff; 38525aee3deSMauro Carvalho Chehab pllbuf[3] = cp; 38625aee3deSMauro Carvalho Chehab pllbuf[4] = bs; 38725aee3deSMauro Carvalho Chehab 38825aee3deSMauro Carvalho Chehab return 5; 38925aee3deSMauro Carvalho Chehab } 39025aee3deSMauro Carvalho Chehab 39125aee3deSMauro Carvalho Chehab static struct mt352_config advbt771_samsung_tdtc9251dh0_config = { 39225aee3deSMauro Carvalho Chehab .demod_address = 0x0f, 39325aee3deSMauro Carvalho Chehab .demod_init = advbt771_samsung_tdtc9251dh0_demod_init, 39425aee3deSMauro Carvalho Chehab }; 39525aee3deSMauro Carvalho Chehab 39625aee3deSMauro Carvalho Chehab static struct dst_config dst_config = { 39725aee3deSMauro Carvalho Chehab .demod_address = 0x55, 39825aee3deSMauro Carvalho Chehab }; 39925aee3deSMauro Carvalho Chehab 40025aee3deSMauro Carvalho Chehab static int or51211_request_firmware(struct dvb_frontend* fe, const struct firmware **fw, char* name) 40125aee3deSMauro Carvalho Chehab { 40225aee3deSMauro Carvalho Chehab struct dvb_bt8xx_card* bt = (struct dvb_bt8xx_card*) fe->dvb->priv; 40325aee3deSMauro Carvalho Chehab 40425aee3deSMauro Carvalho Chehab return request_firmware(fw, name, &bt->bt->dev->dev); 40525aee3deSMauro Carvalho Chehab } 40625aee3deSMauro Carvalho Chehab 40725aee3deSMauro Carvalho Chehab static void or51211_setmode(struct dvb_frontend * fe, int mode) 40825aee3deSMauro Carvalho Chehab { 40925aee3deSMauro Carvalho Chehab struct dvb_bt8xx_card *bt = fe->dvb->priv; 41025aee3deSMauro Carvalho Chehab bttv_write_gpio(bt->bttv_nr, 0x0002, mode); /* Reset */ 41125aee3deSMauro Carvalho Chehab msleep(20); 41225aee3deSMauro Carvalho Chehab } 41325aee3deSMauro Carvalho Chehab 41425aee3deSMauro Carvalho Chehab static void or51211_reset(struct dvb_frontend * fe) 41525aee3deSMauro Carvalho Chehab { 41625aee3deSMauro Carvalho Chehab struct dvb_bt8xx_card *bt = fe->dvb->priv; 41725aee3deSMauro Carvalho Chehab 41825aee3deSMauro Carvalho Chehab /* RESET DEVICE 41925aee3deSMauro Carvalho Chehab * reset is controlled by GPIO-0 42025aee3deSMauro Carvalho Chehab * when set to 0 causes reset and when to 1 for normal op 42125aee3deSMauro Carvalho Chehab * must remain reset for 128 clock cycles on a 50Mhz clock 42225aee3deSMauro Carvalho Chehab * also PRM1 PRM2 & PRM4 are controlled by GPIO-1,GPIO-2 & GPIO-4 42325aee3deSMauro Carvalho Chehab * We assume that the reset has be held low long enough or we 42425aee3deSMauro Carvalho Chehab * have been reset by a power on. When the driver is unloaded 42525aee3deSMauro Carvalho Chehab * reset set to 0 so if reloaded we have been reset. 42625aee3deSMauro Carvalho Chehab */ 42725aee3deSMauro Carvalho Chehab /* reset & PRM1,2&4 are outputs */ 42825aee3deSMauro Carvalho Chehab int ret = bttv_gpio_enable(bt->bttv_nr, 0x001F, 0x001F); 42925aee3deSMauro Carvalho Chehab if (ret != 0) 430fa132a64SMauro Carvalho Chehab pr_warn("or51211: Init Error - Can't Reset DVR (%i)\n", ret); 43125aee3deSMauro Carvalho Chehab bttv_write_gpio(bt->bttv_nr, 0x001F, 0x0000); /* Reset */ 43225aee3deSMauro Carvalho Chehab msleep(20); 43325aee3deSMauro Carvalho Chehab /* Now set for normal operation */ 43425aee3deSMauro Carvalho Chehab bttv_write_gpio(bt->bttv_nr, 0x0001F, 0x0001); 43525aee3deSMauro Carvalho Chehab /* wait for operation to begin */ 43625aee3deSMauro Carvalho Chehab msleep(500); 43725aee3deSMauro Carvalho Chehab } 43825aee3deSMauro Carvalho Chehab 43925aee3deSMauro Carvalho Chehab static void or51211_sleep(struct dvb_frontend * fe) 44025aee3deSMauro Carvalho Chehab { 44125aee3deSMauro Carvalho Chehab struct dvb_bt8xx_card *bt = fe->dvb->priv; 44225aee3deSMauro Carvalho Chehab bttv_write_gpio(bt->bttv_nr, 0x0001, 0x0000); 44325aee3deSMauro Carvalho Chehab } 44425aee3deSMauro Carvalho Chehab 4454a40c73eSJulia Lawall static const struct or51211_config or51211_config = { 44625aee3deSMauro Carvalho Chehab .demod_address = 0x15, 44725aee3deSMauro Carvalho Chehab .request_firmware = or51211_request_firmware, 44825aee3deSMauro Carvalho Chehab .setmode = or51211_setmode, 44925aee3deSMauro Carvalho Chehab .reset = or51211_reset, 45025aee3deSMauro Carvalho Chehab .sleep = or51211_sleep, 45125aee3deSMauro Carvalho Chehab }; 45225aee3deSMauro Carvalho Chehab 45325aee3deSMauro Carvalho Chehab static int vp3021_alps_tded4_tuner_set_params(struct dvb_frontend *fe) 45425aee3deSMauro Carvalho Chehab { 45525aee3deSMauro Carvalho Chehab struct dtv_frontend_properties *c = &fe->dtv_property_cache; 45625aee3deSMauro Carvalho Chehab struct dvb_bt8xx_card *card = (struct dvb_bt8xx_card *) fe->dvb->priv; 45725aee3deSMauro Carvalho Chehab u8 buf[4]; 45825aee3deSMauro Carvalho Chehab u32 div; 45925aee3deSMauro Carvalho Chehab struct i2c_msg msg = { .addr = 0x60, .flags = 0, .buf = buf, .len = sizeof(buf) }; 46025aee3deSMauro Carvalho Chehab 46125aee3deSMauro Carvalho Chehab div = (c->frequency + 36166667) / 166667; 46225aee3deSMauro Carvalho Chehab 46325aee3deSMauro Carvalho Chehab buf[0] = (div >> 8) & 0x7F; 46425aee3deSMauro Carvalho Chehab buf[1] = div & 0xFF; 46525aee3deSMauro Carvalho Chehab buf[2] = 0x85; 46625aee3deSMauro Carvalho Chehab if ((c->frequency >= 47000000) && (c->frequency < 153000000)) 46725aee3deSMauro Carvalho Chehab buf[3] = 0x01; 46825aee3deSMauro Carvalho Chehab else if ((c->frequency >= 153000000) && (c->frequency < 430000000)) 46925aee3deSMauro Carvalho Chehab buf[3] = 0x02; 47025aee3deSMauro Carvalho Chehab else if ((c->frequency >= 430000000) && (c->frequency < 824000000)) 47125aee3deSMauro Carvalho Chehab buf[3] = 0x0C; 47225aee3deSMauro Carvalho Chehab else if ((c->frequency >= 824000000) && (c->frequency < 863000000)) 47325aee3deSMauro Carvalho Chehab buf[3] = 0x8C; 47425aee3deSMauro Carvalho Chehab else 47525aee3deSMauro Carvalho Chehab return -EINVAL; 47625aee3deSMauro Carvalho Chehab 47725aee3deSMauro Carvalho Chehab if (fe->ops.i2c_gate_ctrl) 47825aee3deSMauro Carvalho Chehab fe->ops.i2c_gate_ctrl(fe, 1); 47925aee3deSMauro Carvalho Chehab i2c_transfer(card->i2c_adapter, &msg, 1); 48025aee3deSMauro Carvalho Chehab return 0; 48125aee3deSMauro Carvalho Chehab } 48225aee3deSMauro Carvalho Chehab 48325aee3deSMauro Carvalho Chehab static struct nxt6000_config vp3021_alps_tded4_config = { 48425aee3deSMauro Carvalho Chehab .demod_address = 0x0a, 48525aee3deSMauro Carvalho Chehab .clock_inversion = 1, 48625aee3deSMauro Carvalho Chehab }; 48725aee3deSMauro Carvalho Chehab 48825aee3deSMauro Carvalho Chehab static int digitv_alps_tded4_demod_init(struct dvb_frontend* fe) 48925aee3deSMauro Carvalho Chehab { 49025aee3deSMauro Carvalho Chehab static u8 mt352_clock_config [] = { 0x89, 0x38, 0x2d }; 49125aee3deSMauro Carvalho Chehab static u8 mt352_reset [] = { 0x50, 0x80 }; 49225aee3deSMauro Carvalho Chehab static u8 mt352_adc_ctl_1_cfg [] = { 0x8E, 0x40 }; 49325aee3deSMauro Carvalho Chehab static u8 mt352_agc_cfg [] = { 0x67, 0x20, 0xa0 }; 49425aee3deSMauro Carvalho Chehab static u8 mt352_capt_range_cfg[] = { 0x75, 0x32 }; 49525aee3deSMauro Carvalho Chehab 49625aee3deSMauro Carvalho Chehab mt352_write(fe, mt352_clock_config, sizeof(mt352_clock_config)); 49725aee3deSMauro Carvalho Chehab udelay(2000); 49825aee3deSMauro Carvalho Chehab mt352_write(fe, mt352_reset, sizeof(mt352_reset)); 49925aee3deSMauro Carvalho Chehab mt352_write(fe, mt352_adc_ctl_1_cfg, sizeof(mt352_adc_ctl_1_cfg)); 50025aee3deSMauro Carvalho Chehab mt352_write(fe, mt352_agc_cfg,sizeof(mt352_agc_cfg)); 50125aee3deSMauro Carvalho Chehab mt352_write(fe, mt352_capt_range_cfg, sizeof(mt352_capt_range_cfg)); 50225aee3deSMauro Carvalho Chehab 50325aee3deSMauro Carvalho Chehab return 0; 50425aee3deSMauro Carvalho Chehab } 50525aee3deSMauro Carvalho Chehab 50625aee3deSMauro Carvalho Chehab static int digitv_alps_tded4_tuner_calc_regs(struct dvb_frontend *fe, u8 *pllbuf, int buf_len) 50725aee3deSMauro Carvalho Chehab { 50825aee3deSMauro Carvalho Chehab u32 div; 50925aee3deSMauro Carvalho Chehab struct dtv_frontend_properties *c = &fe->dtv_property_cache; 51025aee3deSMauro Carvalho Chehab 51125aee3deSMauro Carvalho Chehab if (buf_len < 5) 51225aee3deSMauro Carvalho Chehab return -EINVAL; 51325aee3deSMauro Carvalho Chehab 51425aee3deSMauro Carvalho Chehab div = (((c->frequency + 83333) * 3) / 500000) + IF_FREQUENCYx6; 51525aee3deSMauro Carvalho Chehab 51625aee3deSMauro Carvalho Chehab pllbuf[0] = 0x61; 51725aee3deSMauro Carvalho Chehab pllbuf[1] = (div >> 8) & 0x7F; 51825aee3deSMauro Carvalho Chehab pllbuf[2] = div & 0xFF; 51925aee3deSMauro Carvalho Chehab pllbuf[3] = 0x85; 52025aee3deSMauro Carvalho Chehab 52125aee3deSMauro Carvalho Chehab dprintk("frequency %u, div %u\n", c->frequency, div); 52225aee3deSMauro Carvalho Chehab 52325aee3deSMauro Carvalho Chehab if (c->frequency < 470000000) 52425aee3deSMauro Carvalho Chehab pllbuf[4] = 0x02; 52525aee3deSMauro Carvalho Chehab else if (c->frequency > 823000000) 52625aee3deSMauro Carvalho Chehab pllbuf[4] = 0x88; 52725aee3deSMauro Carvalho Chehab else 52825aee3deSMauro Carvalho Chehab pllbuf[4] = 0x08; 52925aee3deSMauro Carvalho Chehab 53025aee3deSMauro Carvalho Chehab if (c->bandwidth_hz == 8000000) 53125aee3deSMauro Carvalho Chehab pllbuf[4] |= 0x04; 53225aee3deSMauro Carvalho Chehab 53325aee3deSMauro Carvalho Chehab return 5; 53425aee3deSMauro Carvalho Chehab } 53525aee3deSMauro Carvalho Chehab 53625aee3deSMauro Carvalho Chehab static void digitv_alps_tded4_reset(struct dvb_bt8xx_card *bt) 53725aee3deSMauro Carvalho Chehab { 53825aee3deSMauro Carvalho Chehab /* 53925aee3deSMauro Carvalho Chehab * Reset the frontend, must be called before trying 54025aee3deSMauro Carvalho Chehab * to initialise the MT352 or mt352_attach 54125aee3deSMauro Carvalho Chehab * will fail. Same goes for the nxt6000 frontend. 54225aee3deSMauro Carvalho Chehab * 54325aee3deSMauro Carvalho Chehab */ 54425aee3deSMauro Carvalho Chehab 54525aee3deSMauro Carvalho Chehab int ret = bttv_gpio_enable(bt->bttv_nr, 0x08, 0x08); 54625aee3deSMauro Carvalho Chehab if (ret != 0) 547fa132a64SMauro Carvalho Chehab pr_warn("digitv_alps_tded4: Init Error - Can't Reset DVR (%i)\n", 548fa132a64SMauro Carvalho Chehab ret); 54925aee3deSMauro Carvalho Chehab 55025aee3deSMauro Carvalho Chehab /* Pulse the reset line */ 55125aee3deSMauro Carvalho Chehab bttv_write_gpio(bt->bttv_nr, 0x08, 0x08); /* High */ 55225aee3deSMauro Carvalho Chehab bttv_write_gpio(bt->bttv_nr, 0x08, 0x00); /* Low */ 55325aee3deSMauro Carvalho Chehab msleep(100); 55425aee3deSMauro Carvalho Chehab 55525aee3deSMauro Carvalho Chehab bttv_write_gpio(bt->bttv_nr, 0x08, 0x08); /* High */ 55625aee3deSMauro Carvalho Chehab } 55725aee3deSMauro Carvalho Chehab 55825aee3deSMauro Carvalho Chehab static struct mt352_config digitv_alps_tded4_config = { 55925aee3deSMauro Carvalho Chehab .demod_address = 0x0a, 56025aee3deSMauro Carvalho Chehab .demod_init = digitv_alps_tded4_demod_init, 56125aee3deSMauro Carvalho Chehab }; 56225aee3deSMauro Carvalho Chehab 56325aee3deSMauro Carvalho Chehab static struct lgdt330x_config tdvs_tua6034_config = { 56425aee3deSMauro Carvalho Chehab .demod_chip = LGDT3303, 56525aee3deSMauro Carvalho Chehab .serial_mpeg = 0x40, /* TPSERIAL for 3303 in TOP_CONTROL */ 56625aee3deSMauro Carvalho Chehab }; 56725aee3deSMauro Carvalho Chehab 56825aee3deSMauro Carvalho Chehab static void lgdt330x_reset(struct dvb_bt8xx_card *bt) 56925aee3deSMauro Carvalho Chehab { 57025aee3deSMauro Carvalho Chehab /* Set pin 27 of the lgdt3303 chip high to reset the frontend */ 57125aee3deSMauro Carvalho Chehab 57225aee3deSMauro Carvalho Chehab /* Pulse the reset line */ 57325aee3deSMauro Carvalho Chehab bttv_write_gpio(bt->bttv_nr, 0x00e00007, 0x00000001); /* High */ 57425aee3deSMauro Carvalho Chehab bttv_write_gpio(bt->bttv_nr, 0x00e00007, 0x00000000); /* Low */ 57525aee3deSMauro Carvalho Chehab msleep(100); 57625aee3deSMauro Carvalho Chehab 57725aee3deSMauro Carvalho Chehab bttv_write_gpio(bt->bttv_nr, 0x00e00007, 0x00000001); /* High */ 57825aee3deSMauro Carvalho Chehab msleep(100); 57925aee3deSMauro Carvalho Chehab } 58025aee3deSMauro Carvalho Chehab 58125aee3deSMauro Carvalho Chehab static void frontend_init(struct dvb_bt8xx_card *card, u32 type) 58225aee3deSMauro Carvalho Chehab { 58325aee3deSMauro Carvalho Chehab struct dst_state* state = NULL; 58425aee3deSMauro Carvalho Chehab 58525aee3deSMauro Carvalho Chehab switch(type) { 58625aee3deSMauro Carvalho Chehab case BTTV_BOARD_DVICO_DVBT_LITE: 58725aee3deSMauro Carvalho Chehab card->fe = dvb_attach(mt352_attach, &thomson_dtt7579_config, card->i2c_adapter); 58825aee3deSMauro Carvalho Chehab 58925aee3deSMauro Carvalho Chehab if (card->fe == NULL) 59025aee3deSMauro Carvalho Chehab card->fe = dvb_attach(zl10353_attach, &thomson_dtt7579_zl10353_config, 59125aee3deSMauro Carvalho Chehab card->i2c_adapter); 59225aee3deSMauro Carvalho Chehab 59325aee3deSMauro Carvalho Chehab if (card->fe != NULL) { 59425aee3deSMauro Carvalho Chehab card->fe->ops.tuner_ops.calc_regs = thomson_dtt7579_tuner_calc_regs; 595f1b1eabfSMauro Carvalho Chehab card->fe->ops.info.frequency_min_hz = 174 * MHz; 596f1b1eabfSMauro Carvalho Chehab card->fe->ops.info.frequency_max_hz = 862 * MHz; 59725aee3deSMauro Carvalho Chehab } 59825aee3deSMauro Carvalho Chehab break; 59925aee3deSMauro Carvalho Chehab 60025aee3deSMauro Carvalho Chehab case BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE: 60125aee3deSMauro Carvalho Chehab lgdt330x_reset(card); 60223ba635dSMauro Carvalho Chehab card->fe = dvb_attach(lgdt330x_attach, &tdvs_tua6034_config, 60323ba635dSMauro Carvalho Chehab 0x0e, card->i2c_adapter); 60425aee3deSMauro Carvalho Chehab if (card->fe != NULL) { 60525aee3deSMauro Carvalho Chehab dvb_attach(simple_tuner_attach, card->fe, 60625aee3deSMauro Carvalho Chehab card->i2c_adapter, 0x61, 60725aee3deSMauro Carvalho Chehab TUNER_LG_TDVS_H06XF); 60825aee3deSMauro Carvalho Chehab dprintk("dvb_bt8xx: lgdt330x detected\n"); 60925aee3deSMauro Carvalho Chehab } 61025aee3deSMauro Carvalho Chehab break; 61125aee3deSMauro Carvalho Chehab 61225aee3deSMauro Carvalho Chehab case BTTV_BOARD_NEBULA_DIGITV: 61325aee3deSMauro Carvalho Chehab /* 61425aee3deSMauro Carvalho Chehab * It is possible to determine the correct frontend using the I2C bus (see the Nebula SDK); 61525aee3deSMauro Carvalho Chehab * this would be a cleaner solution than trying each frontend in turn. 61625aee3deSMauro Carvalho Chehab */ 61725aee3deSMauro Carvalho Chehab 61825aee3deSMauro Carvalho Chehab /* Old Nebula (marked (c)2003 on high profile pci card) has nxt6000 demod */ 61925aee3deSMauro Carvalho Chehab digitv_alps_tded4_reset(card); 62025aee3deSMauro Carvalho Chehab card->fe = dvb_attach(nxt6000_attach, &vp3021_alps_tded4_config, card->i2c_adapter); 62125aee3deSMauro Carvalho Chehab if (card->fe != NULL) { 62225aee3deSMauro Carvalho Chehab card->fe->ops.tuner_ops.set_params = vp3021_alps_tded4_tuner_set_params; 62325aee3deSMauro Carvalho Chehab dprintk("dvb_bt8xx: an nxt6000 was detected on your digitv card\n"); 62425aee3deSMauro Carvalho Chehab break; 62525aee3deSMauro Carvalho Chehab } 62625aee3deSMauro Carvalho Chehab 62725aee3deSMauro Carvalho Chehab /* New Nebula (marked (c)2005 on low profile pci card) has mt352 demod */ 62825aee3deSMauro Carvalho Chehab digitv_alps_tded4_reset(card); 62925aee3deSMauro Carvalho Chehab card->fe = dvb_attach(mt352_attach, &digitv_alps_tded4_config, card->i2c_adapter); 63025aee3deSMauro Carvalho Chehab 63125aee3deSMauro Carvalho Chehab if (card->fe != NULL) { 63225aee3deSMauro Carvalho Chehab card->fe->ops.tuner_ops.calc_regs = digitv_alps_tded4_tuner_calc_regs; 63325aee3deSMauro Carvalho Chehab dprintk("dvb_bt8xx: an mt352 was detected on your digitv card\n"); 63425aee3deSMauro Carvalho Chehab } 63525aee3deSMauro Carvalho Chehab break; 63625aee3deSMauro Carvalho Chehab 63725aee3deSMauro Carvalho Chehab case BTTV_BOARD_AVDVBT_761: 63825aee3deSMauro Carvalho Chehab card->fe = dvb_attach(sp887x_attach, µtune_mt7202dtf_config, card->i2c_adapter); 63925aee3deSMauro Carvalho Chehab if (card->fe) { 64025aee3deSMauro Carvalho Chehab card->fe->ops.tuner_ops.set_params = microtune_mt7202dtf_tuner_set_params; 64125aee3deSMauro Carvalho Chehab } 64225aee3deSMauro Carvalho Chehab break; 64325aee3deSMauro Carvalho Chehab 64425aee3deSMauro Carvalho Chehab case BTTV_BOARD_AVDVBT_771: 64525aee3deSMauro Carvalho Chehab card->fe = dvb_attach(mt352_attach, &advbt771_samsung_tdtc9251dh0_config, card->i2c_adapter); 64625aee3deSMauro Carvalho Chehab if (card->fe != NULL) { 64725aee3deSMauro Carvalho Chehab card->fe->ops.tuner_ops.calc_regs = advbt771_samsung_tdtc9251dh0_tuner_calc_regs; 648f1b1eabfSMauro Carvalho Chehab card->fe->ops.info.frequency_min_hz = 174 * MHz; 649f1b1eabfSMauro Carvalho Chehab card->fe->ops.info.frequency_max_hz = 862 * MHz; 65025aee3deSMauro Carvalho Chehab } 65125aee3deSMauro Carvalho Chehab break; 65225aee3deSMauro Carvalho Chehab 65325aee3deSMauro Carvalho Chehab case BTTV_BOARD_TWINHAN_DST: 65425aee3deSMauro Carvalho Chehab /* DST is not a frontend driver !!! */ 65525aee3deSMauro Carvalho Chehab state = kmalloc(sizeof (struct dst_state), GFP_KERNEL); 65625aee3deSMauro Carvalho Chehab if (!state) { 65725aee3deSMauro Carvalho Chehab pr_err("No memory\n"); 65825aee3deSMauro Carvalho Chehab break; 65925aee3deSMauro Carvalho Chehab } 66025aee3deSMauro Carvalho Chehab /* Setup the Card */ 66125aee3deSMauro Carvalho Chehab state->config = &dst_config; 66225aee3deSMauro Carvalho Chehab state->i2c = card->i2c_adapter; 66325aee3deSMauro Carvalho Chehab state->bt = card->bt; 66425aee3deSMauro Carvalho Chehab state->dst_ca = NULL; 66525aee3deSMauro Carvalho Chehab /* DST is not a frontend, attaching the ASIC */ 66625aee3deSMauro Carvalho Chehab if (dvb_attach(dst_attach, state, &card->dvb_adapter) == NULL) { 66725aee3deSMauro Carvalho Chehab pr_err("%s: Could not find a Twinhan DST\n", __func__); 6686792eb0cSSudip Mukherjee kfree(state); 66925aee3deSMauro Carvalho Chehab break; 67025aee3deSMauro Carvalho Chehab } 67125aee3deSMauro Carvalho Chehab /* Attach other DST peripherals if any */ 67225aee3deSMauro Carvalho Chehab /* Conditional Access device */ 67325aee3deSMauro Carvalho Chehab card->fe = &state->frontend; 67425aee3deSMauro Carvalho Chehab if (state->dst_hw_cap & DST_TYPE_HAS_CA) 67525aee3deSMauro Carvalho Chehab dvb_attach(dst_ca_attach, state, &card->dvb_adapter); 67625aee3deSMauro Carvalho Chehab break; 67725aee3deSMauro Carvalho Chehab 67825aee3deSMauro Carvalho Chehab case BTTV_BOARD_PINNACLESAT: 67925aee3deSMauro Carvalho Chehab card->fe = dvb_attach(cx24110_attach, &pctvsat_config, card->i2c_adapter); 68025aee3deSMauro Carvalho Chehab if (card->fe) { 68125aee3deSMauro Carvalho Chehab card->fe->ops.tuner_ops.init = pinnsat_tuner_init; 68225aee3deSMauro Carvalho Chehab card->fe->ops.tuner_ops.sleep = pinnsat_tuner_sleep; 68325aee3deSMauro Carvalho Chehab card->fe->ops.tuner_ops.set_params = cx24108_tuner_set_params; 68425aee3deSMauro Carvalho Chehab } 68525aee3deSMauro Carvalho Chehab break; 68625aee3deSMauro Carvalho Chehab 68725aee3deSMauro Carvalho Chehab case BTTV_BOARD_PC_HDTV: 68825aee3deSMauro Carvalho Chehab card->fe = dvb_attach(or51211_attach, &or51211_config, card->i2c_adapter); 68925aee3deSMauro Carvalho Chehab if (card->fe != NULL) 69025aee3deSMauro Carvalho Chehab dvb_attach(simple_tuner_attach, card->fe, 69125aee3deSMauro Carvalho Chehab card->i2c_adapter, 0x61, 69225aee3deSMauro Carvalho Chehab TUNER_PHILIPS_FCV1236D); 69325aee3deSMauro Carvalho Chehab break; 69425aee3deSMauro Carvalho Chehab } 69525aee3deSMauro Carvalho Chehab 69625aee3deSMauro Carvalho Chehab if (card->fe == NULL) 69725aee3deSMauro Carvalho Chehab pr_err("A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n", 69825aee3deSMauro Carvalho Chehab card->bt->dev->vendor, 69925aee3deSMauro Carvalho Chehab card->bt->dev->device, 70025aee3deSMauro Carvalho Chehab card->bt->dev->subsystem_vendor, 70125aee3deSMauro Carvalho Chehab card->bt->dev->subsystem_device); 70225aee3deSMauro Carvalho Chehab else 70325aee3deSMauro Carvalho Chehab if (dvb_register_frontend(&card->dvb_adapter, card->fe)) { 70425aee3deSMauro Carvalho Chehab pr_err("Frontend registration failed!\n"); 70525aee3deSMauro Carvalho Chehab dvb_frontend_detach(card->fe); 70625aee3deSMauro Carvalho Chehab card->fe = NULL; 70725aee3deSMauro Carvalho Chehab } 70825aee3deSMauro Carvalho Chehab } 70925aee3deSMauro Carvalho Chehab 7104c62e976SGreg Kroah-Hartman static int dvb_bt8xx_load_card(struct dvb_bt8xx_card *card, u32 type) 71125aee3deSMauro Carvalho Chehab { 71225aee3deSMauro Carvalho Chehab int result; 71325aee3deSMauro Carvalho Chehab 71425aee3deSMauro Carvalho Chehab result = dvb_register_adapter(&card->dvb_adapter, card->card_name, 71525aee3deSMauro Carvalho Chehab THIS_MODULE, &card->bt->dev->dev, 71625aee3deSMauro Carvalho Chehab adapter_nr); 71725aee3deSMauro Carvalho Chehab if (result < 0) { 71825aee3deSMauro Carvalho Chehab pr_err("dvb_register_adapter failed (errno = %d)\n", result); 71925aee3deSMauro Carvalho Chehab return result; 72025aee3deSMauro Carvalho Chehab } 72125aee3deSMauro Carvalho Chehab card->dvb_adapter.priv = card; 72225aee3deSMauro Carvalho Chehab 72325aee3deSMauro Carvalho Chehab card->bt->adapter = card->i2c_adapter; 72425aee3deSMauro Carvalho Chehab 72525aee3deSMauro Carvalho Chehab memset(&card->demux, 0, sizeof(struct dvb_demux)); 72625aee3deSMauro Carvalho Chehab 72725aee3deSMauro Carvalho Chehab card->demux.dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING; 72825aee3deSMauro Carvalho Chehab 72925aee3deSMauro Carvalho Chehab card->demux.priv = card; 73025aee3deSMauro Carvalho Chehab card->demux.filternum = 256; 73125aee3deSMauro Carvalho Chehab card->demux.feednum = 256; 73225aee3deSMauro Carvalho Chehab card->demux.start_feed = dvb_bt8xx_start_feed; 73325aee3deSMauro Carvalho Chehab card->demux.stop_feed = dvb_bt8xx_stop_feed; 73425aee3deSMauro Carvalho Chehab card->demux.write_to_decoder = NULL; 73525aee3deSMauro Carvalho Chehab 73625aee3deSMauro Carvalho Chehab result = dvb_dmx_init(&card->demux); 73725aee3deSMauro Carvalho Chehab if (result < 0) { 73825aee3deSMauro Carvalho Chehab pr_err("dvb_dmx_init failed (errno = %d)\n", result); 73925aee3deSMauro Carvalho Chehab goto err_unregister_adaptor; 74025aee3deSMauro Carvalho Chehab } 74125aee3deSMauro Carvalho Chehab 74225aee3deSMauro Carvalho Chehab card->dmxdev.filternum = 256; 74325aee3deSMauro Carvalho Chehab card->dmxdev.demux = &card->demux.dmx; 74425aee3deSMauro Carvalho Chehab card->dmxdev.capabilities = 0; 74525aee3deSMauro Carvalho Chehab 74625aee3deSMauro Carvalho Chehab result = dvb_dmxdev_init(&card->dmxdev, &card->dvb_adapter); 74725aee3deSMauro Carvalho Chehab if (result < 0) { 74825aee3deSMauro Carvalho Chehab pr_err("dvb_dmxdev_init failed (errno = %d)\n", result); 74925aee3deSMauro Carvalho Chehab goto err_dmx_release; 75025aee3deSMauro Carvalho Chehab } 75125aee3deSMauro Carvalho Chehab 75225aee3deSMauro Carvalho Chehab card->fe_hw.source = DMX_FRONTEND_0; 75325aee3deSMauro Carvalho Chehab 75425aee3deSMauro Carvalho Chehab result = card->demux.dmx.add_frontend(&card->demux.dmx, &card->fe_hw); 75525aee3deSMauro Carvalho Chehab if (result < 0) { 75625aee3deSMauro Carvalho Chehab pr_err("dvb_dmx_init failed (errno = %d)\n", result); 75725aee3deSMauro Carvalho Chehab goto err_dmxdev_release; 75825aee3deSMauro Carvalho Chehab } 75925aee3deSMauro Carvalho Chehab 76025aee3deSMauro Carvalho Chehab card->fe_mem.source = DMX_MEMORY_FE; 76125aee3deSMauro Carvalho Chehab 76225aee3deSMauro Carvalho Chehab result = card->demux.dmx.add_frontend(&card->demux.dmx, &card->fe_mem); 76325aee3deSMauro Carvalho Chehab if (result < 0) { 76425aee3deSMauro Carvalho Chehab pr_err("dvb_dmx_init failed (errno = %d)\n", result); 76525aee3deSMauro Carvalho Chehab goto err_remove_hw_frontend; 76625aee3deSMauro Carvalho Chehab } 76725aee3deSMauro Carvalho Chehab 76825aee3deSMauro Carvalho Chehab result = card->demux.dmx.connect_frontend(&card->demux.dmx, &card->fe_hw); 76925aee3deSMauro Carvalho Chehab if (result < 0) { 77025aee3deSMauro Carvalho Chehab pr_err("dvb_dmx_init failed (errno = %d)\n", result); 77125aee3deSMauro Carvalho Chehab goto err_remove_mem_frontend; 77225aee3deSMauro Carvalho Chehab } 77325aee3deSMauro Carvalho Chehab 77425aee3deSMauro Carvalho Chehab result = dvb_net_init(&card->dvb_adapter, &card->dvbnet, &card->demux.dmx); 77525aee3deSMauro Carvalho Chehab if (result < 0) { 77625aee3deSMauro Carvalho Chehab pr_err("dvb_net_init failed (errno = %d)\n", result); 77725aee3deSMauro Carvalho Chehab goto err_disconnect_frontend; 77825aee3deSMauro Carvalho Chehab } 77925aee3deSMauro Carvalho Chehab 78025aee3deSMauro Carvalho Chehab tasklet_init(&card->bt->tasklet, dvb_bt8xx_task, (unsigned long) card); 78125aee3deSMauro Carvalho Chehab 78225aee3deSMauro Carvalho Chehab frontend_init(card, type); 78325aee3deSMauro Carvalho Chehab 78425aee3deSMauro Carvalho Chehab return 0; 78525aee3deSMauro Carvalho Chehab 78625aee3deSMauro Carvalho Chehab err_disconnect_frontend: 78725aee3deSMauro Carvalho Chehab card->demux.dmx.disconnect_frontend(&card->demux.dmx); 78825aee3deSMauro Carvalho Chehab err_remove_mem_frontend: 78925aee3deSMauro Carvalho Chehab card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_mem); 79025aee3deSMauro Carvalho Chehab err_remove_hw_frontend: 79125aee3deSMauro Carvalho Chehab card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw); 79225aee3deSMauro Carvalho Chehab err_dmxdev_release: 79325aee3deSMauro Carvalho Chehab dvb_dmxdev_release(&card->dmxdev); 79425aee3deSMauro Carvalho Chehab err_dmx_release: 79525aee3deSMauro Carvalho Chehab dvb_dmx_release(&card->demux); 79625aee3deSMauro Carvalho Chehab err_unregister_adaptor: 79725aee3deSMauro Carvalho Chehab dvb_unregister_adapter(&card->dvb_adapter); 79825aee3deSMauro Carvalho Chehab return result; 79925aee3deSMauro Carvalho Chehab } 80025aee3deSMauro Carvalho Chehab 8014c62e976SGreg Kroah-Hartman static int dvb_bt8xx_probe(struct bttv_sub_device *sub) 80225aee3deSMauro Carvalho Chehab { 80325aee3deSMauro Carvalho Chehab struct dvb_bt8xx_card *card; 80425aee3deSMauro Carvalho Chehab struct pci_dev* bttv_pci_dev; 80525aee3deSMauro Carvalho Chehab int ret; 80625aee3deSMauro Carvalho Chehab 80725aee3deSMauro Carvalho Chehab if (!(card = kzalloc(sizeof(struct dvb_bt8xx_card), GFP_KERNEL))) 80825aee3deSMauro Carvalho Chehab return -ENOMEM; 80925aee3deSMauro Carvalho Chehab 81025aee3deSMauro Carvalho Chehab mutex_init(&card->lock); 81125aee3deSMauro Carvalho Chehab card->bttv_nr = sub->core->nr; 812c0decac1SMauro Carvalho Chehab strscpy(card->card_name, sub->core->v4l2_dev.name, 813c0decac1SMauro Carvalho Chehab sizeof(card->card_name)); 81425aee3deSMauro Carvalho Chehab card->i2c_adapter = &sub->core->i2c_adap; 81525aee3deSMauro Carvalho Chehab 81625aee3deSMauro Carvalho Chehab switch(sub->core->type) { 81725aee3deSMauro Carvalho Chehab case BTTV_BOARD_PINNACLESAT: 81825aee3deSMauro Carvalho Chehab card->gpio_mode = 0x0400c060; 81925aee3deSMauro Carvalho Chehab /* should be: BT878_A_GAIN=0,BT878_A_PWRDN,BT878_DA_DPM,BT878_DA_SBR, 82025aee3deSMauro Carvalho Chehab BT878_DA_IOM=1,BT878_DA_APP to enable serial highspeed mode. */ 82125aee3deSMauro Carvalho Chehab card->op_sync_orin = BT878_RISC_SYNC_MASK; 82225aee3deSMauro Carvalho Chehab card->irq_err_ignore = BT878_AFBUS | BT878_AFDSR; 82325aee3deSMauro Carvalho Chehab break; 82425aee3deSMauro Carvalho Chehab 82525aee3deSMauro Carvalho Chehab case BTTV_BOARD_DVICO_DVBT_LITE: 82625aee3deSMauro Carvalho Chehab card->gpio_mode = 0x0400C060; 82725aee3deSMauro Carvalho Chehab card->op_sync_orin = BT878_RISC_SYNC_MASK; 82825aee3deSMauro Carvalho Chehab card->irq_err_ignore = BT878_AFBUS | BT878_AFDSR; 82925aee3deSMauro Carvalho Chehab /* 26, 15, 14, 6, 5 83025aee3deSMauro Carvalho Chehab * A_PWRDN DA_DPM DA_SBR DA_IOM_DA 83125aee3deSMauro Carvalho Chehab * DA_APP(parallel) */ 83225aee3deSMauro Carvalho Chehab break; 83325aee3deSMauro Carvalho Chehab 83425aee3deSMauro Carvalho Chehab case BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE: 83525aee3deSMauro Carvalho Chehab card->gpio_mode = 0x0400c060; 83625aee3deSMauro Carvalho Chehab card->op_sync_orin = BT878_RISC_SYNC_MASK; 83725aee3deSMauro Carvalho Chehab card->irq_err_ignore = BT878_AFBUS | BT878_AFDSR; 83825aee3deSMauro Carvalho Chehab break; 83925aee3deSMauro Carvalho Chehab 84025aee3deSMauro Carvalho Chehab case BTTV_BOARD_NEBULA_DIGITV: 84125aee3deSMauro Carvalho Chehab case BTTV_BOARD_AVDVBT_761: 84225aee3deSMauro Carvalho Chehab card->gpio_mode = (1 << 26) | (1 << 14) | (1 << 5); 84325aee3deSMauro Carvalho Chehab card->op_sync_orin = BT878_RISC_SYNC_MASK; 84425aee3deSMauro Carvalho Chehab card->irq_err_ignore = BT878_AFBUS | BT878_AFDSR; 84525aee3deSMauro Carvalho Chehab /* A_PWRDN DA_SBR DA_APP (high speed serial) */ 84625aee3deSMauro Carvalho Chehab break; 84725aee3deSMauro Carvalho Chehab 84825aee3deSMauro Carvalho Chehab case BTTV_BOARD_AVDVBT_771: //case 0x07711461: 84925aee3deSMauro Carvalho Chehab card->gpio_mode = 0x0400402B; 85025aee3deSMauro Carvalho Chehab card->op_sync_orin = BT878_RISC_SYNC_MASK; 85125aee3deSMauro Carvalho Chehab card->irq_err_ignore = BT878_AFBUS | BT878_AFDSR; 85225aee3deSMauro Carvalho Chehab /* A_PWRDN DA_SBR DA_APP[0] PKTP=10 RISC_ENABLE FIFO_ENABLE*/ 85325aee3deSMauro Carvalho Chehab break; 85425aee3deSMauro Carvalho Chehab 85525aee3deSMauro Carvalho Chehab case BTTV_BOARD_TWINHAN_DST: 85625aee3deSMauro Carvalho Chehab card->gpio_mode = 0x2204f2c; 85725aee3deSMauro Carvalho Chehab card->op_sync_orin = BT878_RISC_SYNC_MASK; 85825aee3deSMauro Carvalho Chehab card->irq_err_ignore = BT878_APABORT | BT878_ARIPERR | 85925aee3deSMauro Carvalho Chehab BT878_APPERR | BT878_AFBUS; 86025aee3deSMauro Carvalho Chehab /* 25,21,14,11,10,9,8,3,2 then 86125aee3deSMauro Carvalho Chehab * 0x33 = 5,4,1,0 86225aee3deSMauro Carvalho Chehab * A_SEL=SML, DA_MLB, DA_SBR, 86325aee3deSMauro Carvalho Chehab * DA_SDR=f, fifo trigger = 32 DWORDS 86425aee3deSMauro Carvalho Chehab * IOM = 0 == audio A/D 86525aee3deSMauro Carvalho Chehab * DPM = 0 == digital audio mode 86625aee3deSMauro Carvalho Chehab * == async data parallel port 86725aee3deSMauro Carvalho Chehab * then 0x33 (13 is set by start_capture) 86825aee3deSMauro Carvalho Chehab * DA_APP = async data parallel port, 86925aee3deSMauro Carvalho Chehab * ACAP_EN = 1, 87025aee3deSMauro Carvalho Chehab * RISC+FIFO ENABLE */ 87125aee3deSMauro Carvalho Chehab break; 87225aee3deSMauro Carvalho Chehab 87325aee3deSMauro Carvalho Chehab case BTTV_BOARD_PC_HDTV: 87425aee3deSMauro Carvalho Chehab card->gpio_mode = 0x0100EC7B; 87525aee3deSMauro Carvalho Chehab card->op_sync_orin = BT878_RISC_SYNC_MASK; 87625aee3deSMauro Carvalho Chehab card->irq_err_ignore = BT878_AFBUS | BT878_AFDSR; 87725aee3deSMauro Carvalho Chehab break; 87825aee3deSMauro Carvalho Chehab 87925aee3deSMauro Carvalho Chehab default: 88025aee3deSMauro Carvalho Chehab pr_err("Unknown bttv card type: %d\n", sub->core->type); 88125aee3deSMauro Carvalho Chehab kfree(card); 88225aee3deSMauro Carvalho Chehab return -ENODEV; 88325aee3deSMauro Carvalho Chehab } 88425aee3deSMauro Carvalho Chehab 88525aee3deSMauro Carvalho Chehab dprintk("dvb_bt8xx: identified card%d as %s\n", card->bttv_nr, card->card_name); 88625aee3deSMauro Carvalho Chehab 88725aee3deSMauro Carvalho Chehab if (!(bttv_pci_dev = bttv_get_pcidev(card->bttv_nr))) { 88825aee3deSMauro Carvalho Chehab pr_err("no pci device for card %d\n", card->bttv_nr); 88925aee3deSMauro Carvalho Chehab kfree(card); 89025aee3deSMauro Carvalho Chehab return -ENODEV; 89125aee3deSMauro Carvalho Chehab } 89225aee3deSMauro Carvalho Chehab 89325aee3deSMauro Carvalho Chehab if (!(card->bt = dvb_bt8xx_878_match(card->bttv_nr, bttv_pci_dev))) { 89425aee3deSMauro Carvalho Chehab pr_err("unable to determine DMA core of card %d,\n", card->bttv_nr); 89525aee3deSMauro Carvalho Chehab pr_err("if you have the ALSA bt87x audio driver installed, try removing it.\n"); 89625aee3deSMauro Carvalho Chehab 89725aee3deSMauro Carvalho Chehab kfree(card); 89825aee3deSMauro Carvalho Chehab return -ENODEV; 89925aee3deSMauro Carvalho Chehab } 90025aee3deSMauro Carvalho Chehab 90125aee3deSMauro Carvalho Chehab mutex_init(&card->bt->gpio_lock); 90225aee3deSMauro Carvalho Chehab card->bt->bttv_nr = sub->core->nr; 90325aee3deSMauro Carvalho Chehab 90425aee3deSMauro Carvalho Chehab if ( (ret = dvb_bt8xx_load_card(card, sub->core->type)) ) { 90525aee3deSMauro Carvalho Chehab kfree(card); 90625aee3deSMauro Carvalho Chehab return ret; 90725aee3deSMauro Carvalho Chehab } 90825aee3deSMauro Carvalho Chehab 90925aee3deSMauro Carvalho Chehab dev_set_drvdata(&sub->dev, card); 91025aee3deSMauro Carvalho Chehab return 0; 91125aee3deSMauro Carvalho Chehab } 91225aee3deSMauro Carvalho Chehab 91325aee3deSMauro Carvalho Chehab static void dvb_bt8xx_remove(struct bttv_sub_device *sub) 91425aee3deSMauro Carvalho Chehab { 91525aee3deSMauro Carvalho Chehab struct dvb_bt8xx_card *card = dev_get_drvdata(&sub->dev); 91625aee3deSMauro Carvalho Chehab 91725aee3deSMauro Carvalho Chehab dprintk("dvb_bt8xx: unloading card%d\n", card->bttv_nr); 91825aee3deSMauro Carvalho Chehab 91925aee3deSMauro Carvalho Chehab bt878_stop(card->bt); 92025aee3deSMauro Carvalho Chehab tasklet_kill(&card->bt->tasklet); 92125aee3deSMauro Carvalho Chehab dvb_net_release(&card->dvbnet); 92225aee3deSMauro Carvalho Chehab card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_mem); 92325aee3deSMauro Carvalho Chehab card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_hw); 92425aee3deSMauro Carvalho Chehab dvb_dmxdev_release(&card->dmxdev); 92525aee3deSMauro Carvalho Chehab dvb_dmx_release(&card->demux); 92625aee3deSMauro Carvalho Chehab if (card->fe) { 92725aee3deSMauro Carvalho Chehab dvb_unregister_frontend(card->fe); 92825aee3deSMauro Carvalho Chehab dvb_frontend_detach(card->fe); 92925aee3deSMauro Carvalho Chehab } 93025aee3deSMauro Carvalho Chehab dvb_unregister_adapter(&card->dvb_adapter); 93125aee3deSMauro Carvalho Chehab 93225aee3deSMauro Carvalho Chehab kfree(card); 93325aee3deSMauro Carvalho Chehab } 93425aee3deSMauro Carvalho Chehab 93525aee3deSMauro Carvalho Chehab static struct bttv_sub_driver driver = { 93625aee3deSMauro Carvalho Chehab .drv = { 93725aee3deSMauro Carvalho Chehab .name = "dvb-bt8xx", 93825aee3deSMauro Carvalho Chehab }, 93925aee3deSMauro Carvalho Chehab .probe = dvb_bt8xx_probe, 94025aee3deSMauro Carvalho Chehab .remove = dvb_bt8xx_remove, 94125aee3deSMauro Carvalho Chehab /* FIXME: 94225aee3deSMauro Carvalho Chehab * .shutdown = dvb_bt8xx_shutdown, 94325aee3deSMauro Carvalho Chehab * .suspend = dvb_bt8xx_suspend, 94425aee3deSMauro Carvalho Chehab * .resume = dvb_bt8xx_resume, 94525aee3deSMauro Carvalho Chehab */ 94625aee3deSMauro Carvalho Chehab }; 94725aee3deSMauro Carvalho Chehab 94825aee3deSMauro Carvalho Chehab static int __init dvb_bt8xx_init(void) 94925aee3deSMauro Carvalho Chehab { 95025aee3deSMauro Carvalho Chehab return bttv_sub_register(&driver, "dvb"); 95125aee3deSMauro Carvalho Chehab } 95225aee3deSMauro Carvalho Chehab 95325aee3deSMauro Carvalho Chehab static void __exit dvb_bt8xx_exit(void) 95425aee3deSMauro Carvalho Chehab { 95525aee3deSMauro Carvalho Chehab bttv_sub_unregister(&driver); 95625aee3deSMauro Carvalho Chehab } 95725aee3deSMauro Carvalho Chehab 95825aee3deSMauro Carvalho Chehab module_init(dvb_bt8xx_init); 95925aee3deSMauro Carvalho Chehab module_exit(dvb_bt8xx_exit); 96025aee3deSMauro Carvalho Chehab 96125aee3deSMauro Carvalho Chehab MODULE_DESCRIPTION("Bt8xx based DVB adapter driver"); 96225aee3deSMauro Carvalho Chehab MODULE_AUTHOR("Florian Schirmer <jolt@tuxbox.org>"); 96325aee3deSMauro Carvalho Chehab MODULE_LICENSE("GPL"); 964