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