diff options
author | Jamie Honan <devnull@localhost> | 2003-10-28 02:33:54 +0000 |
---|---|---|
committer | Jamie Honan <devnull@localhost> | 2003-10-28 02:33:54 +0000 |
commit | 9b0f2f531601da08a7e4d942038c0a38cecdb0fe (patch) | |
tree | 3dbffcba745abd5621ac867259d1f1e3cefadd14 /linux/drivers/media/dvb | |
parent | 153c77c86087e28cb4b4830a2475dea6f1468238 (diff) | |
download | mediapointer-dvb-s2-9b0f2f531601da08a7e4d942038c0a38cecdb0fe.tar.gz mediapointer-dvb-s2-9b0f2f531601da08a7e4d942038c0a38cecdb0fe.tar.bz2 |
- reworked i2c / gpio so not so hackerish and more in line with
what Gerd is moving to
- allowed multiple instances of dst frontend.
- should handle terrestial cards correctly. Can mix and match
ts204, new tuner packets, symbol rate types in tuner packets
- has more DST strings on i2c asic discovery (in dst_check_ci)
- can override card PCI id using card=0x68 for bttv driver. bt878
audio dma still hogs all cards it finds, but this is an interim
release to work towards fixing this
- put in rudimentary signal strength / snr. The scale factors
are not right. Should work for terrestial / satellite.
- Put in Dimitri's fix of not doing dst_enable after reciept of
the 0xFF ack, but allowing the asic to do this itself.
Diffstat (limited to 'linux/drivers/media/dvb')
-rw-r--r-- | linux/drivers/media/dvb/bt8xx/bt878.c | 112 | ||||
-rw-r--r-- | linux/drivers/media/dvb/bt8xx/bt878.h | 5 | ||||
-rw-r--r-- | linux/drivers/media/dvb/bt8xx/dvb-bt8xx.c | 143 | ||||
-rw-r--r-- | linux/drivers/media/dvb/bt8xx/dvb-bt8xx.h | 2 | ||||
-rw-r--r-- | linux/drivers/media/dvb/frontends/dst-bt878.h | 33 | ||||
-rw-r--r-- | linux/drivers/media/dvb/frontends/dst.c | 595 | ||||
-rw-r--r-- | linux/drivers/media/dvb/frontends/dst.h | 30 |
7 files changed, 580 insertions, 340 deletions
diff --git a/linux/drivers/media/dvb/bt8xx/bt878.c b/linux/drivers/media/dvb/bt8xx/bt878.c index 6d8939782..32b0c53a1 100644 --- a/linux/drivers/media/dvb/bt8xx/bt878.c +++ b/linux/drivers/media/dvb/bt8xx/bt878.c @@ -41,7 +41,15 @@ #include <linux/vmalloc.h> #include <linux/init.h> +#include "dmxdev.h" +#include "dvbdev.h" #include "bt878.h" +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) +#include "dst-bt878.h" +#else +#include "../frontends/dst-bt878.h" +#endif + #include "dvb_functions.h" /**************************************/ @@ -60,10 +68,10 @@ MODULE_LICENSE("GPL"); int bt878_num; struct bt878 bt878[BT878_MAX]; -EXPORT_SYMBOL_GPL(bt878_debug); -EXPORT_SYMBOL_GPL(bt878_verbose); -EXPORT_SYMBOL_GPL(bt878_num); -EXPORT_SYMBOL_GPL(bt878); +EXPORT_SYMBOL(bt878_debug); +EXPORT_SYMBOL(bt878_verbose); +EXPORT_SYMBOL(bt878_num); +EXPORT_SYMBOL(bt878); #define btwrite(dat,adr) bmtwrite((dat), (bt->bt878_mem+(adr))) #define btread(adr) bmtread(bt->bt878_mem+(adr)) @@ -213,8 +221,8 @@ void bt878_start(struct bt878 *bt, u32 controlreg, u32 op_sync_orin, * the card specifics */ bt878_risc_program(bt, op_sync_orin); - controlreg &= ~0x13; - controlreg |= 0x1B; + controlreg &= ~0x1f; + controlreg |= 0x1b; btwrite(cpu_to_le32(bt->risc_dma), BT878_ARISC_START); @@ -258,8 +266,8 @@ void bt878_stop(struct bt878 *bt) bt->nr, i, stat); } -EXPORT_SYMBOL_GPL(bt878_start); -EXPORT_SYMBOL_GPL(bt878_stop); +EXPORT_SYMBOL(bt878_start); +EXPORT_SYMBOL(bt878_stop); /*****************************/ /* Interrupt service routine */ @@ -335,6 +343,68 @@ static irqreturn_t bt878_irq(int irq, void *dev_id, struct pt_regs *regs) return IRQ_HANDLED; } +extern int bttv_gpio_enable(unsigned int card, unsigned long mask, unsigned long data); +extern int bttv_read_gpio(unsigned int card, unsigned long *data); +extern int bttv_write_gpio(unsigned int card, unsigned long mask, unsigned long data); + +int +bt878_device_control(struct bt878 *bt, unsigned int cmd, union dst_gpio_packet *mp) +{ + int retval; + + retval = 0; + if (down_interruptible (&bt->gpio_lock)) + return -ERESTARTSYS; + /* special gpio signal */ + switch (cmd) { + case DST_IG_ENABLE: + // dprintk("dvb_bt8xx: dst enable mask 0x%02x enb 0x%02x \n", mp->dstg.enb.mask, mp->dstg.enb.enable); + retval = bttv_gpio_enable(bt->bttv_nr, + mp->enb.mask, + mp->enb.enable); + break; + case DST_IG_WRITE: + // dprintk("dvb_bt8xx: dst write gpio mask 0x%02x out 0x%02x\n", mp->dstg.outp.mask, mp->dstg.outp.highvals); + retval = bttv_write_gpio(bt->bttv_nr, + mp->outp.mask, + mp->outp.highvals); + + break; + case DST_IG_READ: + /* read */ + retval = bttv_read_gpio(bt->bttv_nr, &mp->rd.value); + // dprintk("dvb_bt8xx: dst read gpio 0x%02x\n", (unsigned)mp->dstg.rd.value); + break; + case DST_IG_TS: + /* Set packet size */ + bt->TS_Size = mp->psize; + break; + + default: + retval = -EINVAL; + break; + } + up(&bt->gpio_lock); + return retval; +} + +EXPORT_SYMBOL(bt878_device_control); + +struct bt878 *bt878_find_by_dvb_adap(struct dvb_adapter *adap) +{ + unsigned int card_nr; + + printk("bt878 find by dvb adap: checking \"%s\"\n",adap->name); + for (card_nr = 0; card_nr < bt878_num; card_nr++) { + if (bt878[card_nr].adap_ptr == adap) + return &bt878[card_nr]; + } + printk("bt878 find by dvb adap: NOT found \"%s\"\n",adap->name); + return NULL; +} + +EXPORT_SYMBOL(bt878_find_by_dvb_adap); + /***********************/ /* PCI device handling */ /***********************/ @@ -492,6 +562,19 @@ static struct pci_driver bt878_pci_driver = { .remove = bt878_remove, }; +static int bt878_pci_driver_registered = 0; + +/* This will be used later by dvb-bt8xx to only use the audio + * dma of certain cards */ +int bt878_find_audio_dma(void) +{ + // pci_register_driver(&bt878_pci_driver); + bt878_pci_driver_registered = 1; + return 0; +} + +EXPORT_SYMBOL(bt878_find_audio_dma); + /*******************************/ /* Module management functions */ /*******************************/ @@ -499,6 +582,7 @@ static struct pci_driver bt878_pci_driver = { int bt878_init_module(void) { bt878_num = 0; + bt878_pci_driver_registered = 0; printk(KERN_INFO "bt878: AUDIO driver version %d.%d.%d loaded\n", (BT878_VERSION_CODE >> 16) & 0xff, @@ -507,17 +591,23 @@ int bt878_init_module(void) /* bt878_check_chipset(); */ + /* later we register inside of bt878_find_audio_dma + * because we may want to ignore certain cards */ + bt878_pci_driver_registered = 1; return pci_module_init(&bt878_pci_driver); } void bt878_cleanup_module(void) { - pci_unregister_driver(&bt878_pci_driver); + if (bt878_pci_driver_registered) { + bt878_pci_driver_registered = 0; + pci_unregister_driver(&bt878_pci_driver); + } return; } -EXPORT_SYMBOL_GPL(bt878_init_module); -EXPORT_SYMBOL_GPL(bt878_cleanup_module); +EXPORT_SYMBOL(bt878_init_module); +EXPORT_SYMBOL(bt878_cleanup_module); module_init(bt878_init_module); module_exit(bt878_cleanup_module); diff --git a/linux/drivers/media/dvb/bt8xx/bt878.h b/linux/drivers/media/dvb/bt8xx/bt878.h index e929a062d..ebffd121a 100644 --- a/linux/drivers/media/dvb/bt8xx/bt878.h +++ b/linux/drivers/media/dvb/bt8xx/bt878.h @@ -91,10 +91,13 @@ extern int bt878_num; extern struct bt878 bt878[BT878_MAX]; struct bt878 { - spinlock_t s_lock; + struct semaphore gpio_lock; unsigned int nr; + unsigned int bttv_nr; + struct dvb_adapter *adap_ptr; struct pci_dev *dev; unsigned int id; + unsigned int TS_Size; unsigned char revision; unsigned int irq; unsigned long bt878_adr; diff --git a/linux/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/linux/drivers/media/dvb/bt8xx/dvb-bt8xx.c index a36a00e90..ddbd8c690 100644 --- a/linux/drivers/media/dvb/bt8xx/dvb-bt8xx.c +++ b/linux/drivers/media/dvb/bt8xx/dvb-bt8xx.c @@ -34,12 +34,6 @@ #include "dvb-bt8xx.h" #include "bt878.h" -#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) -#include "dst.h" -#else -#include "../frontends/dst.h" -#endif - /* ID THAT MUST GO INTO i2c ids */ #ifndef I2C_DRIVERID_DVB_BT878A @@ -51,10 +45,6 @@ extern int bttv_get_cardinfo(unsigned int card, int *type, int *cardid); extern struct pci_dev* bttv_get_pcidev(unsigned int card); -extern int bttv_gpio_enable(unsigned int card, unsigned long mask, unsigned long data); -extern int bttv_read_gpio(unsigned int card, unsigned long *data); -extern int bttv_write_gpio(unsigned int card, unsigned long mask, unsigned long data); - static LIST_HEAD(card_list); static int debug = 0; @@ -66,7 +56,7 @@ static void dvb_bt8xx_task(unsigned long data) //printk("%d ", finished_block); while (card->bt->last_block != card->bt->finished_block) { - (card->TS_Size ? dvb_dmx_swfilter_204 : dvb_dmx_swfilter)(&card->demux, &card->bt->buf_cpu[card->bt->last_block * card->bt->block_bytes], card->bt->block_bytes); + (card->bt->TS_Size ? dvb_dmx_swfilter_204 : dvb_dmx_swfilter)(&card->demux, &card->bt->buf_cpu[card->bt->last_block * card->bt->block_bytes], card->bt->block_bytes); card->bt->last_block = (card->bt->last_block + 1) % card->bt->block_count; } } @@ -115,71 +105,15 @@ static int master_xfer (struct dvb_i2c_bus *i2c, const struct i2c_msg msgs[], in { struct dvb_bt8xx_card *card = i2c->data; int retval; - int i; - struct dst_gpio_packet *mp; - if (down_interruptible (&card->i2c_lock)) + if (down_interruptible (&card->bt->gpio_lock)) return -ERESTARTSYS; - retval = 0; - for (i = 0 ; i < num; i++) { - - if (msgs[i].addr != DST_IG_ADDR) { - retval = i2c_transfer(card->i2c_adapter, &msgs[i], 1); - if (retval < 0) { - break; - } - continue; - } - if (msgs[i].len < sizeof(struct dst_gpio_packet)) { - retval = -EINVAL; - break; - } - mp = (struct dst_gpio_packet *)(msgs[i].buf); - /* special gpio signal */ - switch (mp->cmd) { - case DST_IG_ENABLE: - // dprintk("dvb_bt8xx: dst enable mask 0x%02x enb 0x%02x \n", mp->dstg.enb.mask, mp->dstg.enb.enable); - retval = bttv_gpio_enable(card->bttv_nr, - mp->dstg.enb.mask, - mp->dstg.enb.enable); - if (retval < 0) - break; - continue; - case DST_IG_WRITE: - // dprintk("dvb_bt8xx: dst write gpio mask 0x%02x out 0x%02x\n", mp->dstg.outp.mask, mp->dstg.outp.highvals); - retval = bttv_write_gpio(card->bttv_nr, - mp->dstg.outp.mask, - mp->dstg.outp.highvals); - if (retval < 0) - break; - continue; - case DST_IG_READ: - /* read */ - retval = bttv_read_gpio(card->bttv_nr, &mp->dstg.rd.value); - if (retval < 0) - break; - // dprintk("dvb_bt8xx: dst read gpio 0x%02x\n", (unsigned)mp->dstg.rd.value); - continue; - case DST_IG_TS: - /* Set packet size */ - card->TS_Size = 1; - continue; + retval = i2c_transfer(card->i2c_adapter, msgs, num); - default: - retval = -EINVAL; - break; - } - break; - } - up(&card->i2c_lock); - if (retval < 0) - return retval; - if (i < num) { - dprintk("%s: i %d less than num %d\n", __FUNCTION__, i, num); - return -EIO; - } - return num; + up(&card->bt->gpio_lock); + + return retval; } static int is_pci_slot_eq(struct pci_dev* adev, struct pci_dev* bdev) @@ -231,7 +165,8 @@ static int __init dvb_bt8xx_card_match(unsigned int bttv_nr, char *card_name, u3 return -EFAULT; } - + init_MUTEX(&card->bt->gpio_lock); + card->bt->bttv_nr = bttv_nr; card->gpio_mode = gpio_mode; card->op_sync_orin = op_sync_orin; card->irq_err_ignore = irq_err_ignore; @@ -259,11 +194,10 @@ static void __init dvb_bt8xx_get_adaps(void) list_del(&card->list); kfree(card); } - init_MUTEX(&card->i2c_lock); } } -static void dvb_bt8xx_adap_free(struct i2c_adapter *adap) +static void dvb_bt8xx_i2c_adap_free(struct i2c_adapter *adap) { } @@ -275,12 +209,12 @@ static void __exit dvb_bt8xx_exit_adaps(void) /* More complicated. but cleaner better */ -static struct dvb_bt8xx_card *dvb_bt8xx_find_by_adap(struct i2c_adapter *adap) +static struct dvb_bt8xx_card *dvb_bt8xx_find_by_i2c_adap(struct i2c_adapter *adap) { struct dvb_bt8xx_card *card; struct list_head *item; - printk("find by adap: checking \"%s\"\n",adap->name); + printk("find by i2c adap: checking \"%s\"\n",adap->name); list_for_each(item, &card_list) { card = list_entry(item, struct dvb_bt8xx_card, list); if (card->i2c_adapter == adap) @@ -326,7 +260,6 @@ static int dvb_bt8xx_attach(struct i2c_adapter *adap) if (!card) return 0; card->i2c_adapter = adap; - init_MUTEX(&card->i2c_lock); printk("attach: \"%s\", to card %d\n", adap->name, card->bttv_nr); try_module_get(adap->owner); @@ -334,7 +267,7 @@ static int dvb_bt8xx_attach(struct i2c_adapter *adap) return 0; } -static void dvb_bt8xx_adap_free(struct i2c_adapter *adap) +static void dvb_bt8xx_i2c_adap_free(struct i2c_adapter *adap) { module_put(adap->owner); } @@ -343,7 +276,7 @@ static int dvb_bt8xx_detach(struct i2c_adapter *adap) { struct dvb_bt8xx_card *card; - card = dvb_bt8xx_find_by_adap(adap); + card = dvb_bt8xx_find_by_i2c_adap(adap); if (!card) return 0; @@ -384,22 +317,21 @@ static int __init dvb_bt8xx_load_card( struct dvb_bt8xx_card *card) } - bttv_gpio_enable(card->bttv_nr, ~0, 0); - if ((result = dvb_register_adapter(&card->dvb_adapter, card->card_name)) < 0) { printk("dvb_bt8xx: dvb_register_adapter failed (errno = %d)\n", result); - dvb_bt8xx_adap_free(card->i2c_adapter); + dvb_bt8xx_i2c_adap_free(card->i2c_adapter); return result; } + card->bt->adap_ptr = card->dvb_adapter; if (!(dvb_register_i2c_bus(master_xfer, card, card->dvb_adapter, 0))) { printk("dvb_bt8xx: dvb_register_i2c_bus of card%d failed\n", card->bttv_nr); dvb_unregister_adapter(card->dvb_adapter); - dvb_bt8xx_adap_free(card->i2c_adapter); + dvb_bt8xx_i2c_adap_free(card->i2c_adapter); return -EFAULT; } @@ -420,7 +352,7 @@ static int __init dvb_bt8xx_load_card( struct dvb_bt8xx_card *card) dvb_unregister_i2c_bus(master_xfer, card->dvb_adapter, 0); dvb_unregister_adapter(card->dvb_adapter); - dvb_bt8xx_adap_free(card->i2c_adapter); + dvb_bt8xx_i2c_adap_free(card->i2c_adapter); return result; } @@ -435,7 +367,7 @@ static int __init dvb_bt8xx_load_card( struct dvb_bt8xx_card *card) dvb_dmx_release(&card->demux); dvb_unregister_i2c_bus(master_xfer, card->dvb_adapter, 0); dvb_unregister_adapter(card->dvb_adapter); - dvb_bt8xx_adap_free(card->i2c_adapter); + dvb_bt8xx_i2c_adap_free(card->i2c_adapter); return result; } @@ -449,7 +381,7 @@ static int __init dvb_bt8xx_load_card( struct dvb_bt8xx_card *card) dvb_dmx_release(&card->demux); dvb_unregister_i2c_bus(master_xfer, card->dvb_adapter, 0); dvb_unregister_adapter(card->dvb_adapter); - dvb_bt8xx_adap_free(card->i2c_adapter); + dvb_bt8xx_i2c_adap_free(card->i2c_adapter); return result; } @@ -464,7 +396,7 @@ static int __init dvb_bt8xx_load_card( struct dvb_bt8xx_card *card) dvb_dmx_release(&card->demux); dvb_unregister_i2c_bus(master_xfer, card->dvb_adapter, 0); dvb_unregister_adapter(card->dvb_adapter); - dvb_bt8xx_adap_free(card->i2c_adapter); + dvb_bt8xx_i2c_adap_free(card->i2c_adapter); return result; } @@ -478,7 +410,7 @@ static int __init dvb_bt8xx_load_card( struct dvb_bt8xx_card *card) dvb_dmx_release(&card->demux); dvb_unregister_i2c_bus(master_xfer, card->dvb_adapter, 0); dvb_unregister_adapter(card->dvb_adapter); - dvb_bt8xx_adap_free(card->i2c_adapter); + dvb_bt8xx_i2c_adap_free(card->i2c_adapter); return result; } @@ -509,6 +441,9 @@ static int __init dvb_bt8xx_load_all(void) } +#define BT878_NEBULA 0x68 +#define BT878_TWINHAN_DST 0x71 + static int __init dvb_bt8xx_init(void) { unsigned int card_nr = 0; @@ -527,6 +462,7 @@ static int __init dvb_bt8xx_init(void) * DA_APP(parallel) */ break; case 0x01010071: +nebula: dvb_bt8xx_card_match(card_nr, "Nebula DigiTV DVB-T", (1 << 26) | (1 << 14) | (1 << 5), 0, 0); @@ -539,6 +475,13 @@ static int __init dvb_bt8xx_init(void) /* A_PWRDN DA_SBR DA_APP (high speed serial) */ break; case 0x0: + if (card_type == BT878_NEBULA || + card_type == BT878_TWINHAN_DST) + goto dst; + goto unknown_card; + case 0x2611BD: + case 0x11822: +dst: dvb_bt8xx_card_match(card_nr, "DST DVB-S", 0x2204f2c, BT878_RISC_SYNC_MASK, BT878_APABORT | BT878_ARIPERR | BT878_APPERR | BT878_AFBUS); @@ -555,12 +498,23 @@ static int __init dvb_bt8xx_init(void) * RISC+FIFO ENABLE */ break; default: - dprintk("%s: unknown card_nr found %0X\n", - __FUNCTION__, card_nr); - dprintk("%s: unknown card_id found %0X\n", +unknown_card: + printk("%s: unknown card_id found %0X\n", __FUNCTION__, card_id); - dprintk("%s: unknown card_type found %0X\n", + if (card_type == BT878_NEBULA) { + printk("%s: bttv type set to nebula\n", + __FUNCTION__); + goto nebula; + } + if (card_type == BT878_TWINHAN_DST) { + printk("%s: bttv type set to Twinhan DST\n", + __FUNCTION__); + goto dst; + } + printk("%s: unknown card_type found %0X, NOT LOADED\n", __FUNCTION__, card_type); + printk("%s: unknown card_nr found %0X\n", + __FUNCTION__, card_nr); } card_nr++; } @@ -583,7 +537,6 @@ static void __exit dvb_bt8xx_exit(void) dprintk("dvb_bt8xx: unloading card%d\n", card->bttv_nr); bt878_stop(card->bt); - tasklet_kill(&card->bt->tasklet); dvb_net_release(&card->dvbnet); card->demux.dmx.remove_frontend(&card->demux.dmx, &card->fe_mem); @@ -591,8 +544,8 @@ static void __exit dvb_bt8xx_exit(void) dvb_dmxdev_release(&card->dmxdev); dvb_dmx_release(&card->demux); dvb_unregister_i2c_bus(master_xfer, card->dvb_adapter, 0); + dvb_bt8xx_i2c_adap_free(card->i2c_adapter); dvb_unregister_adapter(card->dvb_adapter); - dvb_bt8xx_adap_free(card->i2c_adapter); list_del(&card->list); kfree(card); diff --git a/linux/drivers/media/dvb/bt8xx/dvb-bt8xx.h b/linux/drivers/media/dvb/bt8xx/dvb-bt8xx.h index f7e56b181..973e69e50 100644 --- a/linux/drivers/media/dvb/bt8xx/dvb-bt8xx.h +++ b/linux/drivers/media/dvb/bt8xx/dvb-bt8xx.h @@ -30,7 +30,6 @@ struct dvb_bt8xx_card { struct list_head list; u8 active; - u8 TS_Size; char card_name[32]; struct dvb_adapter *dvb_adapter; struct bt878 *bt; @@ -43,7 +42,6 @@ struct dvb_bt8xx_card { u32 op_sync_orin; u32 irq_err_ignore; struct i2c_adapter *i2c_adapter; - struct semaphore i2c_lock; struct dvb_net dvbnet; }; diff --git a/linux/drivers/media/dvb/frontends/dst-bt878.h b/linux/drivers/media/dvb/frontends/dst-bt878.h new file mode 100644 index 000000000..ee98ddbfb --- /dev/null +++ b/linux/drivers/media/dvb/frontends/dst-bt878.h @@ -0,0 +1,33 @@ + +struct dst_gpio_enable { + u32 mask; + u32 enable; +}; + +struct dst_gpio_output { + u32 mask; + u32 highvals; +}; + +struct dst_gpio_read { + unsigned long value; +}; + +union dst_gpio_packet { + struct dst_gpio_enable enb; + struct dst_gpio_output outp; + struct dst_gpio_read rd; + int psize; +}; + +#define DST_IG_ENABLE 0 +#define DST_IG_WRITE 1 +#define DST_IG_READ 2 +#define DST_IG_TS 3 + +struct bt878 ; + +int +bt878_device_control(struct bt878 *bt, unsigned int cmd, union dst_gpio_packet *mp); + +struct bt878 *bt878_find_by_dvb_adap(struct dvb_adapter *adap); diff --git a/linux/drivers/media/dvb/frontends/dst.c b/linux/drivers/media/dvb/frontends/dst.c index 240e131b0..a82fdc404 100644 --- a/linux/drivers/media/dvb/frontends/dst.c +++ b/linux/drivers/media/dvb/frontends/dst.c @@ -33,8 +33,7 @@ #include "dvb_frontend.h" #include "dvb_functions.h" -#include "dst.h" - +#include "dst-bt878.h" unsigned int dst_debug = 0; unsigned int dst_verbose = 0; @@ -46,15 +45,23 @@ MODULE_PARM_DESC(dst_debug, "debug messages, default is 0 (no)"); #define dprintk if (dst_debug) printk -#define HAS_CI 1 -#define HAS_LOCK 2 -#define ATTEMPT_TUNE 4 -#define HAS_POWER 8 +#define DST_TYPE_HAS_TERR 1 +#define DST_TYPE_HAS_SAT 2 +#define DST_TYPE_HAS_CABLE 4 +#define DST_TYPE_HAS_NEWTUNE 8 +#define DST_TYPE_HAS_TS204 0x10 +#define DST_TYPE_HAS_SYMDIV 0x20 + +#define HAS_LOCK 1 +#define ATTEMPT_TUNE 2 +#define HAS_POWER 4 struct dst_data { u8 tx_tuna[10]; u8 rx_tuna[10]; - u8 flags; + u8 rxbuffer[10]; + u8 diseq_flags; + u32 type_flags; u32 frequency; /* intermediate frequency in kHz for QPSK */ fe_spectral_inversion_t inversion; u32 symbol_rate; /* symbol rate in Symbols per second */ @@ -62,13 +69,18 @@ struct dst_data { fe_sec_voltage_t voltage; fe_sec_tone_mode_t tone; u32 decode_freq; - u32 decode_n1; - u32 decode_n2; + u8 decode_lock; + u16 decode_strength; + u16 decode_snr; + unsigned long cur_jiff; u8 k22; + fe_bandwidth_t bandwidth; + struct bt878 *bt; + struct dvb_i2c_bus *i2c; } ; -static struct dvb_frontend_info dst_info = { - .name = "DST FTA", +static struct dvb_frontend_info dst_info_sat = { + .name = "DST SAT", .type = FE_QPSK, .frequency_min = 950000, .frequency_max = 2150000, @@ -83,60 +95,66 @@ static struct dvb_frontend_info dst_info = { FE_CAN_QPSK }; -static void dst_packsize(struct dvb_i2c_bus *i2c) +static struct dvb_frontend_info dst_info_tv = { + .name = "DST TERR", + .type = FE_OFDM, + .frequency_min = 137000000, + .frequency_max = 858000000, + .frequency_stepsize = 166667, + .caps = FE_CAN_INVERSION_AUTO | + FE_CAN_FEC_AUTO | + FE_CAN_QAM_AUTO | + FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO +}; + +static void dst_packsize(struct dst_data *dst, int psize) { - struct dst_gpio_packet bits; - struct i2c_msg msg = { - .addr = DST_IG_ADDR, .flags = 0, .buf = (u8*)(&bits), .len = sizeof(struct dst_gpio_packet) }; - bits.cmd = DST_IG_TS; - i2c->xfer (i2c, &msg, 1); + union dst_gpio_packet bits; + + bits.psize = psize; + bt878_device_control(dst->bt, DST_IG_TS, &bits); } -static int dst_gpio_outb(struct dvb_i2c_bus *i2c, u32 mask, u32 enbb, u32 outhigh) +static int dst_gpio_outb(struct dst_data *dst, u32 mask, u32 enbb, u32 outhigh) { - struct dst_gpio_packet enb; - struct dst_gpio_packet bits; - struct i2c_msg msgs[2] = { - { .addr = DST_IG_ADDR, .flags = 0, .buf = (u8*)(&enb), .len = sizeof(struct dst_gpio_packet) }, - { .addr = DST_IG_ADDR, .flags = 0, .buf = (u8*)(&bits), .len = sizeof(struct dst_gpio_packet) } }; + union dst_gpio_packet enb; + union dst_gpio_packet bits; int err; - int msg_cnt; - enb.cmd = DST_IG_ENABLE; - enb.dstg.enb.mask = mask; - enb.dstg.enb.enable = enbb; - bits.cmd = DST_IG_WRITE; - bits.dstg.outp.mask = enbb; - bits.dstg.outp.highvals = outhigh; + enb.enb.mask = mask; + enb.enb.enable = enbb; + if ((err = bt878_device_control(dst->bt, DST_IG_ENABLE, &enb)) < 0) { + dprintk ("%s: dst_gpio_enb error (err == %i, mask == 0x%02x, enb == 0x%02x)\n", __FUNCTION__, err, mask, enbb); + return -EREMOTEIO; + } /* because complete disabling means no output, no need to do * output packet */ - msg_cnt = 2; if (enbb == 0) - msg_cnt = 1; - if ((err = i2c->xfer (i2c, &msgs[0], msg_cnt)) < 0) { - dprintk ("%s: dst_gpio_outb error (err == %i, mask == 0x%02x, enb == 0x%02x, outhigh == 0x%02x)\n", __FUNCTION__, err, mask, enbb, outhigh); + return 0; + + bits.outp.mask = enbb; + bits.outp.highvals = outhigh; + + if ((err = bt878_device_control(dst->bt, DST_IG_WRITE, &bits)) < 0) { + dprintk ("%s: dst_gpio_outb error (err == %i, enbb == 0x%02x, outhigh == 0x%02x)\n", __FUNCTION__, err, enbb, outhigh); return -EREMOTEIO; } return 0; } -static int dst_gpio_inb(struct dvb_i2c_bus *i2c, u8 *result) +static int dst_gpio_inb(struct dst_data *dst, u8 *result) { - struct dst_gpio_packet rd_packet; - struct i2c_msg msg = { - .addr = DST_IG_ADDR, .flags = 0, .buf = (u8*)(&rd_packet), .len = sizeof(struct dst_gpio_packet) }; + union dst_gpio_packet rd_packet; int err; *result = 0; - rd_packet.cmd = DST_IG_READ; - - if ((err = i2c->xfer (i2c, &msg, 1)) < 0) { + if ((err = bt878_device_control(dst->bt, DST_IG_READ, &rd_packet)) < 0) { dprintk ("%s: dst_gpio_inb error (err == %i)\n", __FUNCTION__, err); return -EREMOTEIO; } - *result = (u8)rd_packet.dstg.rd.value; + *result = (u8)rd_packet.rd.value; return 0; } @@ -144,28 +162,28 @@ static int dst_gpio_inb(struct dvb_i2c_bus *i2c, u8 *result) #define DST_8820 2 static int -dst_reset8820(struct dvb_i2c_bus *i2c) +dst_reset8820(struct dst_data *dst) { int retval; /* pull 8820 gpio pin low, wait, then release it */ // dprintk ("%s: reset 8820\n", __FUNCTION__); - retval = dst_gpio_outb(i2c, DST_8820, DST_8820, 0); + retval = dst_gpio_outb(dst, DST_8820, DST_8820, 0); if (retval < 0) return retval; udelay(10); - retval = dst_gpio_outb(i2c, DST_8820, DST_8820, DST_8820); + retval = dst_gpio_outb(dst, DST_8820, DST_8820, DST_8820); if (retval < 0) return retval; return 0; } static int -dst_i2c_enable(struct dvb_i2c_bus *i2c) +dst_i2c_enable(struct dst_data *dst) { int retval; /* pull I2C enable gpio pin low, wait */ // dprintk ("%s: i2c enable\n", __FUNCTION__); - retval = dst_gpio_outb(i2c, ~0, DST_I2C_ENABLE, 0); + retval = dst_gpio_outb(dst, ~0, DST_I2C_ENABLE, 0); if (retval < 0) return retval; // dprintk ("%s: i2c enable delay\n", __FUNCTION__); @@ -174,12 +192,12 @@ int retval; } static int -dst_i2c_disable(struct dvb_i2c_bus *i2c) +dst_i2c_disable(struct dst_data *dst) { int retval; /* release I2C enable gpio pin, wait */ // dprintk ("%s: i2c disable\n", __FUNCTION__); - retval = dst_gpio_outb(i2c, ~0, 0, 0); + retval = dst_gpio_outb(dst, ~0, 0, 0); if (retval < 0) return retval; // dprintk ("%s: i2c disable delay\n", __FUNCTION__); @@ -188,13 +206,13 @@ int retval; } static int -dst_wait_dst_ready(struct dvb_i2c_bus *i2c) +dst_wait_dst_ready(struct dst_data *dst) { u8 reply; int retval; int i; for (i = 0; i < 200; i++) { - retval = dst_gpio_inb(i2c, &reply); + retval = dst_gpio_inb(dst, &reply); if (retval < 0) return retval; if ((reply & DST_I2C_ENABLE) == 0) { @@ -209,7 +227,7 @@ int i; #define DST_I2C_ADDR 0x55 -static int write_dst (struct dvb_i2c_bus *i2c, u8 *data, u8 len) +static int write_dst (struct dst_data *dst, u8 *data, u8 len) { struct i2c_msg msg = { .addr = DST_I2C_ADDR, .flags = 0, .buf = data, .len = len }; @@ -226,11 +244,11 @@ static int write_dst (struct dvb_i2c_bus *i2c, u8 *data, u8 len) } dvb_delay(30); for (cnt = 0; cnt < 4; cnt++) { - if ((err = i2c->xfer (i2c, &msg, 1)) < 0) { + if ((err = dst->i2c->xfer (dst->i2c, &msg, 1)) < 0) { dprintk ("%s: write_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__, err, len, data[0]); - dst_i2c_disable(i2c); + dst_i2c_disable(dst); dvb_delay(500); - dst_i2c_enable(i2c); + dst_i2c_enable(dst); dvb_delay(500); continue; } else @@ -241,7 +259,7 @@ static int write_dst (struct dvb_i2c_bus *i2c, u8 *data, u8 len) return 0; } -static int read_dst (struct dvb_i2c_bus *i2c, u8 *ret, u8 len) +static int read_dst (struct dst_data *dst, u8 *ret, u8 len) { struct i2c_msg msg = { .addr = DST_I2C_ADDR, .flags = I2C_M_RD, .buf = ret, .len = len }; @@ -249,10 +267,10 @@ static int read_dst (struct dvb_i2c_bus *i2c, u8 *ret, u8 len) int cnt; for (cnt = 0; cnt < 4; cnt++) { - if ((err = i2c->xfer (i2c, &msg, 1)) < 0) { + if ((err = dst->i2c->xfer (dst->i2c, &msg, 1)) < 0) { dprintk ("%s: read_dst error (err == %i, len == 0x%02x, b0 == 0x%02x)\n", __FUNCTION__, err, len, ret[0]); - dst_i2c_disable(i2c); - dst_i2c_enable(i2c); + dst_i2c_disable(dst); + dst_i2c_enable(dst); continue; } else break; @@ -274,17 +292,82 @@ static int dst_set_freq(struct dst_data *dst, u32 freq) u8 *val; dst->frequency = freq; - freq = freq / 1000; + // dprintk("%s: set frequency %u\n", __FUNCTION__, freq); - if (freq < 950 || freq > 2150) - return -EINVAL; + if (dst->type_flags & DST_TYPE_HAS_SAT) { + freq = freq / 1000; + if (freq < 950 || freq > 2150) + return -EINVAL; + val = &dst->tx_tuna[0]; + val[2] = (freq >> 8) & 0x7f; + val[3] = (u8)freq; + val[4] = 1; + val[8] &= ~4; + if (freq < 1531) + val[8] |= 4; + } else if (dst->type_flags & DST_TYPE_HAS_TERR) { + freq = freq / 1000; + if (freq < 137000 || freq > 858000) + return -EINVAL; + val = &dst->tx_tuna[0]; + val[2] = (freq >> 16) & 0xff; + val[3] = (freq >> 8) & 0xff; + val[4] = (u8)freq; + val[5] = 0; + switch (dst->bandwidth) { + case BANDWIDTH_6_MHZ: + val[6] = 6; + break; + + case BANDWIDTH_7_MHZ: + case BANDWIDTH_AUTO: + val[6] = 7; + break; + + case BANDWIDTH_8_MHZ: + val[6] = 8; + break; + } + + val[7] = 0; + val[8] = 0; + } else if (dst->type_flags & DST_TYPE_HAS_CABLE) { + /* guess till will get one */ + freq = freq / 1000; + val = &dst->tx_tuna[0]; + val[2] = (freq >> 16) & 0xff; + val[3] = (freq >> 8) & 0xff; + val[4] = (u8)freq; + } + return 0; +} + +static int dst_set_bandwidth(struct dst_data *dst, fe_bandwidth_t bandwidth) +{ + u8 *val; + + dst->bandwidth = bandwidth; + + if (0 == (dst->type_flags & DST_TYPE_HAS_TERR)) + return 0; + val = &dst->tx_tuna[0]; - val[2] = (freq >> 8) & 0x7f; - val[3] = (u8)freq; - val[4] = 1; - val[8] &= ~4; - if (freq < 1531) - val[8] |= 4; + switch (bandwidth) { + case BANDWIDTH_6_MHZ: + val[6] = 6; + break; + + case BANDWIDTH_7_MHZ: + val[6] = 7; + break; + + case BANDWIDTH_8_MHZ: + val[6] = 8; + break; + + default: + return -EINVAL; + } return 0; } @@ -332,15 +415,15 @@ static int dst_set_symbolrate (struct dst_data *dst, u32 srate) dst->symbol_rate = srate; + if (dst->type_flags & DST_TYPE_HAS_TERR) { + return 0; + } + // dprintk("%s: set srate %u\n", __FUNCTION__, srate); srate /= 1000; val = &dst->tx_tuna[0]; - if (dst->flags & HAS_CI) { - val[5] = (u8)(srate >> 16) & 0x7f; - val[6] = (u8)(srate >> 8); - val[7] = (u8)srate; - } else { + if (dst->type_flags & DST_TYPE_HAS_SYMDIV) { sval = srate; sval <<= 20; do_div(sval, 88000); @@ -349,6 +432,10 @@ static int dst_set_symbolrate (struct dst_data *dst, u32 srate) val[5] = (u8)(symcalc >> 12); val[6] = (u8)(symcalc >> 4); val[7] = (u8)(symcalc << 4); + } else { + val[5] = (u8)(srate >> 16) & 0x7f; + val[6] = (u8)(srate >> 8); + val[7] = (u8)srate; } val[8] &= ~0x20; if (srate > 8000) @@ -369,27 +456,49 @@ static u8 dst_check_sum(u8 *buf, u32 len) return ((~val) + 1); } -static int dst_check_ci (struct dvb_i2c_bus *i2c) + +typedef struct dst_types { + char *mstr; + int offs; + u32 type_flags; +} DST_TYPES; + +struct dst_types dst_tlist[] = { + { "DST-020", 0, DST_TYPE_HAS_SAT|DST_TYPE_HAS_SYMDIV }, + { "DST-030", 0, DST_TYPE_HAS_SAT|DST_TYPE_HAS_TS204|DST_TYPE_HAS_NEWTUNE }, + { "DST-03T", 0, DST_TYPE_HAS_SAT|DST_TYPE_HAS_SYMDIV}, + { "DST-M0T", 0, DST_TYPE_HAS_SAT|DST_TYPE_HAS_TS204|DST_TYPE_HAS_NEWTUNE }, + { "DST-CI", 1, DST_TYPE_HAS_SAT|DST_TYPE_HAS_TS204|DST_TYPE_HAS_NEWTUNE }, + { "DSTMCI", 1, DST_TYPE_HAS_SAT|DST_TYPE_HAS_NEWTUNE }, + { "DSTFCI", 1, DST_TYPE_HAS_SAT|DST_TYPE_HAS_NEWTUNE }, + { "DCTNEW", 1, DST_TYPE_HAS_CABLE|DST_TYPE_HAS_NEWTUNE }, + { "DCT_CI", 1, DST_TYPE_HAS_CABLE|DST_TYPE_HAS_NEWTUNE|DST_TYPE_HAS_TS204 }, + { "DTTDIG" , 1, DST_TYPE_HAS_TERR} }; +/* DCTNEW and DCT-CI are guesses */ + +static int dst_check_ci (struct dst_data *dst) { u8 txbuf[8]; u8 rxbuf[8]; int retval; + int i; + struct dst_types *dsp; memset(txbuf, 0, sizeof(txbuf)); txbuf[1] = 6; txbuf[7] = dst_check_sum (txbuf, 7); - dst_i2c_enable(i2c); - dst_reset8820(i2c); - retval = write_dst (i2c, txbuf, 8); + dst_i2c_enable(dst); + dst_reset8820(dst); + retval = write_dst (dst, txbuf, 8); if (retval < 0) { - dst_i2c_disable(i2c); + dst_i2c_disable(dst); dprintk("%s: write not successful, maybe no card?\n", __FUNCTION__); return retval; } dvb_delay(3); - retval = read_dst (i2c, rxbuf, 1); - dst_i2c_disable(i2c); + retval = read_dst (dst, rxbuf, 1); + dst_i2c_disable(dst); if (retval < 0) { dprintk("%s: read not successful, maybe no card?\n", __FUNCTION__); return retval; @@ -398,11 +507,11 @@ static int dst_check_ci (struct dvb_i2c_bus *i2c) dprintk("%s: write reply not 0xff, not ci (%02x)\n", __FUNCTION__, rxbuf[0]); return retval; } - if (!dst_wait_dst_ready(i2c)) + if (!dst_wait_dst_ready(dst)) return 0; - dst_i2c_enable(i2c); - retval = read_dst (i2c, rxbuf, 8); - dst_i2c_disable(i2c); + // dst_i2c_enable(i2c); Dimitri + retval = read_dst (dst, rxbuf, 8); + dst_i2c_disable(dst); if (retval < 0) { dprintk("%s: read not successful\n", __FUNCTION__); return retval; @@ -412,33 +521,42 @@ static int dst_check_ci (struct dvb_i2c_bus *i2c) return retval; } rxbuf[7] = '\0'; - if (!strncmp(&rxbuf[1], "DST-CI", 6)) { - printk("%s: IS DST-CI\n", __FUNCTION__); - dst_packsize(i2c); - return 1; + for (i = 0, dsp = &dst_tlist[0]; i < sizeof(dst_tlist) / sizeof(dst_tlist[0]); i++, dsp++) { + if (!strncmp(&rxbuf[dsp->offs], + dsp->mstr, + strlen(dsp->mstr))) { + dst->type_flags = dsp->type_flags; + printk("%s: recognize %s\n", __FUNCTION__, dsp->mstr); + break; + } + } + if (i >= sizeof(dst_tlist) / sizeof(dst_tlist[0])) { + printk("%s: unable to recognize %s or %s, guessing CI satellite\n", __FUNCTION__, &rxbuf[0], &rxbuf[1]); + printk("%s please email dvb-kernel@linuxtv.org with this type info\n", __FUNCTION__); + dst->type_flags = DST_TYPE_HAS_SAT|DST_TYPE_HAS_SYMDIV; + } + if (dst->type_flags & DST_TYPE_HAS_TS204) { + dst_packsize(dst, 204); } - printk("%s: IS NOT DST-CI, but %s\n", __FUNCTION__, rxbuf); return 0; } -static int dst_command (struct dst_data *dst, struct dvb_i2c_bus *i2c, u8 *data, u8 len) - +static int dst_command (struct dst_data *dst, u8 *data, u8 len) { int retval; u8 reply; - u8 rxbuf[8]; - dst_i2c_enable(i2c); - dst_reset8820(i2c); - retval = write_dst (i2c, data, len); + dst_i2c_enable(dst); + dst_reset8820(dst); + retval = write_dst (dst, data, len); if (retval < 0) { - dst_i2c_disable(i2c); + dst_i2c_disable(dst); dprintk("%s: write not successful\n", __FUNCTION__); return retval; } dvb_delay(33); - retval = read_dst (i2c, &reply, 1); - dst_i2c_disable(i2c); + retval = read_dst (dst, &reply, 1); + dst_i2c_disable(dst); if (retval < 0) { dprintk("%s: read verify not successful\n", __FUNCTION__); return retval; @@ -449,22 +567,57 @@ static int dst_command (struct dst_data *dst, struct dvb_i2c_bus *i2c, u8 *data, } if (len >= 2 && data[0] == 0 && (data[1] == 1 || data[1] == 3)) return 0; - if (!dst_wait_dst_ready(i2c)) + if (!dst_wait_dst_ready(dst)) return 0; - dst_i2c_enable(i2c); - retval = read_dst (i2c, rxbuf, 8); - dst_i2c_disable(i2c); + // dst_i2c_enable(i2c); Per dimitri + retval = read_dst (dst, dst->rxbuffer, 8); + dst_i2c_disable(dst); if (retval < 0) { dprintk("%s: read not successful\n", __FUNCTION__); return 0; } - if (rxbuf[7] != dst_check_sum (rxbuf, 7)) { + if (dst->rxbuffer[7] != dst_check_sum (dst->rxbuffer, 7)) { dprintk("%s: checksum failure\n", __FUNCTION__); return 0; } return 0; } +static int dst_get_signal(struct dst_data *dst) +{ + int retval; + u8 get_signal[] = {0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb}; + + if ((dst->diseq_flags & ATTEMPT_TUNE) == 0) { + dst->decode_lock = dst->decode_strength = dst->decode_snr = 0; + return 0; + } + if (0 == (dst->diseq_flags & HAS_LOCK)) { + dst->decode_lock = dst->decode_strength = dst->decode_snr = 0; + return 0; + } + if (time_after_eq(jiffies, dst->cur_jiff + (HZ/5))) { + retval = dst_command(dst, get_signal, 8); + if (retval < 0) + return retval; + if (dst->type_flags & DST_TYPE_HAS_SAT) { + dst->decode_lock = ((dst->rxbuffer[6] & 0x10) == 0) ? + 1 : 0; + dst->decode_strength = dst->rxbuffer[5] << 8; + dst->decode_snr = dst->rxbuffer[2] << 8 | + dst->rxbuffer[3]; + } else if (dst->type_flags & + (DST_TYPE_HAS_TERR|DST_TYPE_HAS_CABLE)) { + dst->decode_lock = (dst->rxbuffer[2]) ? + 1 : 0; + dst->decode_strength = dst->rxbuffer[6] << 8; + dst->decode_snr = dst->rxbuffer[4] << 8; + } + dst->cur_jiff = jiffies; + } + return 0; +} + /* * line22k0 0x00, 0x09, 0x00, 0xff, 0x01, 0x00, 0x00, 0x00 * line22k1 0x00, 0x09, 0x01, 0xff, 0x01, 0x00, 0x00, 0x00 @@ -479,22 +632,28 @@ static int dst_command (struct dst_data *dst, struct dvb_i2c_bus *i2c, u8 *data, * Diseqc 4 0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xfc, 0xe0 */ -static int dst_set_diseqc (struct dst_data *dst, struct dvb_i2c_bus *i2c, u8 *cmd, u8 len) +static int dst_set_diseqc (struct dst_data *dst, u8 *cmd, u8 len) { u8 paket[8] = {0x00, 0x08, 0x04, 0xe0, 0x10, 0x38, 0xf0, 0xec }; + if (dst->type_flags & DST_TYPE_HAS_TERR) + return 0; + if (len == 0 || len > 4) return -EINVAL; memcpy(&paket[3], cmd, len); paket[7] = dst_check_sum (&paket[0], 7); - dst_command(dst, i2c, paket, 8); + dst_command(dst, paket, 8); return 0; } -static int dst_tone_power_cmd (struct dst_data *dst, struct dvb_i2c_bus *i2c) +static int dst_tone_power_cmd (struct dst_data *dst) { u8 paket[8] = {0x00, 0x09, 0xff, 0xff, 0x01, 0x00, 0x00, 0x00}; + if (dst->type_flags & DST_TYPE_HAS_TERR) + return 0; + if (dst->voltage == SEC_VOLTAGE_OFF) paket[4] = 0; else @@ -504,52 +663,58 @@ static int dst_tone_power_cmd (struct dst_data *dst, struct dvb_i2c_bus *i2c) else paket[2] = 0; paket[7] = dst_check_sum (&paket[0], 7); - dst_command(dst, i2c, paket, 8); + dst_command(dst, paket, 8); return 0; } -static int dst_set_voltage (struct dst_data *dst, struct dvb_i2c_bus *i2c, fe_sec_voltage_t voltage) +static int dst_set_voltage (struct dst_data *dst, fe_sec_voltage_t voltage) { u8 *val; int need_cmd; dst->voltage = voltage; + if (dst->type_flags & DST_TYPE_HAS_TERR) + return 0; + need_cmd = 0; val = &dst->tx_tuna[0]; val[8] &= ~0x40; switch (voltage) { case SEC_VOLTAGE_13: - if ((dst->flags & HAS_POWER) == 0) + if ((dst->diseq_flags & HAS_POWER) == 0) need_cmd = 1; - dst->flags |= HAS_POWER; + dst->diseq_flags |= HAS_POWER; break; case SEC_VOLTAGE_18: - if ((dst->flags & HAS_POWER) == 0) + if ((dst->diseq_flags & HAS_POWER) == 0) need_cmd = 1; - dst->flags |= HAS_POWER; + dst->diseq_flags |= HAS_POWER; val[8] |= 0x40; break; case SEC_VOLTAGE_OFF: need_cmd = 1; - dst->flags &= ~(HAS_POWER|HAS_LOCK|ATTEMPT_TUNE); + dst->diseq_flags &= ~(HAS_POWER|HAS_LOCK|ATTEMPT_TUNE); break; default: return -EINVAL; } if (need_cmd) { - dst_tone_power_cmd(dst, i2c); + dst_tone_power_cmd(dst); } return 0; } -static int dst_set_tone (struct dst_data *dst, struct dvb_i2c_bus *i2c, fe_sec_tone_mode_t tone) +static int dst_set_tone (struct dst_data *dst, fe_sec_tone_mode_t tone) { u8 *val; dst->tone = tone; + if (dst->type_flags & DST_TYPE_HAS_TERR) + return 0; + val = &dst->tx_tuna[0]; val[8] &= ~0x1; @@ -563,29 +728,29 @@ static int dst_set_tone (struct dst_data *dst, struct dvb_i2c_bus *i2c, fe_sec_t default: return -EINVAL; } - dst_tone_power_cmd(dst, i2c); + dst_tone_power_cmd(dst); return 0; } -static int dst_get_tuna (struct dst_data *dst, struct dvb_i2c_bus *i2c) +static int dst_get_tuna (struct dst_data *dst) { int retval; - if ((dst->flags & ATTEMPT_TUNE) == 0) + if ((dst->diseq_flags & ATTEMPT_TUNE) == 0) return 0; - dst->flags &= ~(HAS_LOCK); - if (!dst_wait_dst_ready(i2c)) + dst->diseq_flags &= ~(HAS_LOCK); + if (!dst_wait_dst_ready(dst)) return 0; - if (dst->flags & HAS_CI) { + if (dst->type_flags & DST_TYPE_HAS_NEWTUNE) { /* how to get variable length reply ???? */ - retval = read_dst (i2c, dst->rx_tuna, 10); + retval = read_dst (dst, dst->rx_tuna, 10); } else { - retval = read_dst (i2c, &dst->rx_tuna[2], 8); + retval = read_dst (dst, &dst->rx_tuna[2], 8); } if (retval < 0) { dprintk("%s: read not successful\n", __FUNCTION__); return 0; } - if (dst->flags & HAS_CI) { + if (dst->type_flags & DST_TYPE_HAS_NEWTUNE) { if (dst->rx_tuna[9] != dst_check_sum (&dst->rx_tuna[0], 9)) { dprintk("%s: checksum failure?\n", __FUNCTION__); return 0; @@ -600,45 +765,49 @@ int retval; return 0; dst->decode_freq = ((dst->rx_tuna[2] & 0x7f) << 8) + dst->rx_tuna[3]; + dst->decode_lock = 1; + /* dst->decode_n1 = (dst->rx_tuna[4] << 8) + (dst->rx_tuna[5]); dst->decode_n2 = (dst->rx_tuna[8] << 8) + (dst->rx_tuna[7]); - dst->flags |= HAS_LOCK; + */ + dst->diseq_flags |= HAS_LOCK; + /* dst->cur_jiff = jiffies; */ return 1; } -static int dst_write_tuna (struct dst_data *dst, struct dvb_i2c_bus *i2c) +static int dst_write_tuna (struct dst_data *dst) { int retval; u8 reply; - dprintk("%s: flags 0x%x \n", __FUNCTION__, dst->flags); + dprintk("%s: type_flags 0x%x \n", __FUNCTION__, dst->type_flags); dst->decode_freq = 0; - dst->decode_n1 = 0; - dst->decode_n2 = 0; - if (!(dst->flags & HAS_POWER)) - dst_set_voltage (dst, i2c, SEC_VOLTAGE_13); - - dst->flags &= ~(HAS_LOCK|ATTEMPT_TUNE); - dst_i2c_enable(i2c); - if (dst->flags & HAS_CI) { - dst_reset8820(i2c); + dst->decode_lock = dst->decode_strength = dst->decode_snr = 0; + if (dst->type_flags & DST_TYPE_HAS_SAT) { + if (!(dst->diseq_flags & HAS_POWER)) + dst_set_voltage (dst, SEC_VOLTAGE_13); + } + dst->diseq_flags &= ~(HAS_LOCK|ATTEMPT_TUNE); + dst_i2c_enable(dst); + if (dst->type_flags & DST_TYPE_HAS_NEWTUNE) { + dst_reset8820(dst); dst->tx_tuna[9] = dst_check_sum (&dst->tx_tuna[0], 9); - retval = write_dst (i2c, &dst->tx_tuna[0], 10); + retval = write_dst (dst, &dst->tx_tuna[0], 10); } else { dst->tx_tuna[9] = dst_check_sum (&dst->tx_tuna[2], 7); - retval = write_dst (i2c, &dst->tx_tuna[2], 8); + retval = write_dst (dst, &dst->tx_tuna[2], 8); } if (retval < 0) { - dst_i2c_disable(i2c); + dst_i2c_disable(dst); dprintk("%s: write not successful\n", __FUNCTION__); return retval; } dvb_delay(3); - retval = read_dst (i2c, &reply, 1); - dst_i2c_disable(i2c); + retval = read_dst (dst, &reply, 1); + dst_i2c_disable(dst); if (retval < 0) { dprintk("%s: read verify not successful\n", __FUNCTION__); return retval; @@ -647,26 +816,38 @@ static int dst_write_tuna (struct dst_data *dst, struct dvb_i2c_bus *i2c) dprintk("%s: write reply not 0xff 0x%02x \n", __FUNCTION__, reply); return 0; } - dst->flags |= ATTEMPT_TUNE; - return dst_get_tuna(dst, i2c); + dst->diseq_flags |= ATTEMPT_TUNE; + return dst_get_tuna(dst); } -static void dst_init (struct dst_data *dst, int is_ci, struct dvb_i2c_bus *i2c) +static void dst_init (struct dst_data *dst) { -static u8 ini_ci_tuna[] = { 9, 0, 3, 0xb6, 1, 0, 0x73, 0x21, 0, 0 }; -static u8 ini_fta_tuna[] = { 0, 0, 3, 0xb6, 1, 0x55, 0xbd, 0x50, 0, 0 }; - memset(dst, 0, sizeof(*dst)); - dst->frequency = 950000; +static u8 ini_satci_tuna[] = { 9, 0, 3, 0xb6, 1, 0, 0x73, 0x21, 0, 0 }; +static u8 ini_satfta_tuna[] = { 0, 0, 3, 0xb6, 1, 0x55, 0xbd, 0x50, 0, 0 }; +static u8 ini_tvfta_tuna[] = { 0, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; +static u8 ini_tvci_tuna[] = { 9, 0, 3, 0xb6, 1, 7, 0x0, 0x0, 0, 0 }; dst->inversion = INVERSION_ON; dst->voltage = SEC_VOLTAGE_13; dst->tone = SEC_TONE_OFF; dst->symbol_rate = 29473000; dst->fec = FEC_AUTO; - dst->flags = (is_ci ? HAS_CI : 0); + dst->diseq_flags = 0; dst->k22 = 0x02; - memcpy(dst->tx_tuna, (is_ci ? ini_ci_tuna : ini_fta_tuna), - sizeof(ini_fta_tuna)); + dst->bandwidth = BANDWIDTH_7_MHZ; + dst->cur_jiff = jiffies; + if (dst->type_flags & DST_TYPE_HAS_SAT) { + dst->frequency = 950000; + memcpy(dst->tx_tuna, ((dst->type_flags & DST_TYPE_HAS_NEWTUNE )? + ini_satci_tuna : ini_satfta_tuna), + sizeof(ini_satfta_tuna)); + } else if (dst->type_flags & DST_TYPE_HAS_TERR) { + dst->frequency = 137000000; + memcpy(dst->tx_tuna, ((dst->type_flags & DST_TYPE_HAS_NEWTUNE )? + ini_tvci_tuna : ini_tvfta_tuna), + sizeof(ini_tvfta_tuna)); + } } + struct lkup { unsigned int cmd; char *desc; @@ -688,7 +869,6 @@ struct lkup { static int dst_ioctl (struct dvb_frontend *fe, unsigned int cmd, void *arg) { - struct dvb_i2c_bus *i2c = fe->i2c; struct dst_data *dst = fe->data; int retval; /* @@ -703,9 +883,15 @@ static int dst_ioctl (struct dvb_frontend *fe, unsigned int cmd, void *arg) } dprintk("%s cmd %s (0x%x)\n",__FUNCTION__, cc, cmd); */ + // printk("%s: dst %8.8x bt %8.8x i2c %8.8x\n", __FUNCTION__, dst, dst->bt, dst->i2c); + /* should be set by attach, but just in case */ + dst->i2c = fe->i2c; switch (cmd) { case FE_GET_INFO: - memcpy (arg, &dst_info, sizeof(struct dvb_frontend_info)); + memcpy (arg, + ((dst->type_flags & DST_TYPE_HAS_TERR) ? + &dst_info_tv : &dst_info_sat), + sizeof(struct dvb_frontend_info)); break; case FE_READ_STATUS: @@ -713,27 +899,15 @@ static int dst_ioctl (struct dvb_frontend *fe, unsigned int cmd, void *arg) fe_status_t *status = arg; *status = 0; - if (dst->flags & HAS_LOCK) { - *status |= FE_HAS_LOCK | FE_HAS_SIGNAL |FE_HAS_CARRIER| - FE_HAS_SYNC|FE_HAS_VITERBI; + if (dst->diseq_flags & HAS_LOCK) { + dst_get_signal(dst); + if (dst->decode_lock) + *status |= FE_HAS_LOCK + | FE_HAS_SIGNAL + | FE_HAS_CARRIER + | FE_HAS_SYNC + | FE_HAS_VITERBI; } - /* - if (sync & 1) - *status |= FE_HAS_SIGNAL; - - if (sync & 2) - *status |= FE_HAS_CARRIER; - - if (sync & 4) - *status |= FE_HAS_VITERBI; - - if (sync & 8) - *status |= FE_HAS_SYNC; - - if ((sync & 0x1f) == 0x1f) - *status |= FE_HAS_LOCK; - */ - break; } @@ -742,21 +916,20 @@ static int dst_ioctl (struct dvb_frontend *fe, unsigned int cmd, void *arg) /* guess */ // *(u32*) arg = dst->decode_n1; *(u32*) arg = 0; - - break; + return -EOPNOTSUPP; } case FE_READ_SIGNAL_STRENGTH: { - /* guess */ - // *((u16*) arg) = (u16)dst->decode_n2; - *((u16*) arg) = 0; + dst_get_signal(dst); + *((u16*) arg) = dst->decode_strength; break; } case FE_READ_SNR: { - *(u16*) arg = 0; + dst_get_signal(dst); + *((u16*) arg) = dst->decode_snr; break; } @@ -772,9 +945,14 @@ static int dst_ioctl (struct dvb_frontend *fe, unsigned int cmd, void *arg) dst_set_freq (dst, p->frequency); dst_set_inversion (dst, p->inversion); - dst_set_fec (dst, p->u.qpsk.fec_inner); - dst_set_symbolrate (dst, p->u.qpsk.symbol_rate); - dst_write_tuna (dst, i2c); + if (dst->type_flags & DST_TYPE_HAS_SAT) { + dst_set_fec (dst, p->u.qpsk.fec_inner); + dst_set_symbolrate (dst, p->u.qpsk.symbol_rate); + } else + if (dst->type_flags & DST_TYPE_HAS_TERR) { + dst_set_bandwidth(dst, p->u.ofdm.bandwidth); + } + dst_write_tuna (dst); break; } @@ -786,8 +964,12 @@ static int dst_ioctl (struct dvb_frontend *fe, unsigned int cmd, void *arg) p->frequency = dst->decode_freq; p->inversion = dst->inversion; - p->u.qpsk.symbol_rate = dst->symbol_rate; - p->u.qpsk.fec_inner = dst_get_fec (dst); + if (dst->type_flags & DST_TYPE_HAS_SAT) { + p->u.qpsk.symbol_rate = dst->symbol_rate; + p->u.qpsk.fec_inner = dst_get_fec (dst); + } else if (dst->type_flags & DST_TYPE_HAS_TERR) { + p->u.ofdm.bandwidth = dst->bandwidth; + } break; } @@ -795,7 +977,7 @@ static int dst_ioctl (struct dvb_frontend *fe, unsigned int cmd, void *arg) return 0; case FE_INIT: - dst_init (dst, dst->flags & HAS_CI, i2c); + dst_init(dst); break; case FE_RESET: @@ -804,18 +986,18 @@ static int dst_ioctl (struct dvb_frontend *fe, unsigned int cmd, void *arg) case FE_DISEQC_SEND_MASTER_CMD: { struct dvb_diseqc_master_cmd *cmd = (struct dvb_diseqc_master_cmd *)arg; - retval = dst_set_diseqc (dst, i2c, cmd->msg, cmd->msg_len); + retval = dst_set_diseqc (dst, cmd->msg, cmd->msg_len); if (retval < 0) return retval; break; } case FE_SET_TONE: - retval = dst_set_tone (dst, i2c, (fe_sec_tone_mode_t) arg); + retval = dst_set_tone (dst, (fe_sec_tone_mode_t) arg); if (retval < 0) return retval; break; case FE_SET_VOLTAGE: - retval = dst_set_voltage (dst, i2c, (fe_sec_voltage_t) arg); + retval = dst_set_voltage (dst, (fe_sec_voltage_t) arg); if (retval < 0) return retval; break; @@ -829,43 +1011,54 @@ static int dst_ioctl (struct dvb_frontend *fe, unsigned int cmd, void *arg) static int dst_attach (struct dvb_i2c_bus *i2c, void **data) { - int is_ci; - static struct dst_data sdst; struct dst_data *dst; + struct bt878 *bt; + struct dvb_frontend_info *info; dprintk("%s: check ci\n", __FUNCTION__); - is_ci = dst_check_ci (i2c); - if (is_ci < 0) + bt = bt878_find_by_dvb_adap(i2c->adapter); + if (!bt) return -ENODEV; -#if 0 dst = kmalloc(sizeof(struct dst_data), GFP_KERNEL); if (dst == NULL) { printk(KERN_INFO "%s: Out of memory.\n", __FUNCTION__); return -ENOMEM; } -#else - dst = &sdst; -#endif - dst_init (dst, is_ci, i2c); + memset(dst, 0, sizeof(*dst)); + *data = dst; + dst->bt = bt; + dst->i2c = i2c; + if (dst_check_ci(dst) < 0) { + kfree(dst); + return -ENODEV; + } + + dst_init (dst); + dprintk("%s: register dst %8.8x bt %8.8x i2c %8.8x\n", __FUNCTION__, + (u32)dst, (u32)(dst->bt), (u32)(dst->i2c)); - dvb_register_frontend (dst_ioctl, i2c, dst, &dst_info); + info = &dst_info_sat; + if (dst->type_flags & DST_TYPE_HAS_TERR) + info = &dst_info_tv; + + dvb_register_frontend (dst_ioctl, i2c, dst, info); return 0; } static void dst_detach (struct dvb_i2c_bus *i2c, void *data) { - /* kfree dst at this point ???? */ dvb_unregister_frontend (dst_ioctl, i2c); + dprintk("%s: unregister dst %8.8x\n", __FUNCTION__, (u32)(data)); + if (data) + kfree(data); } - static int __init init_dst (void) { return dvb_register_i2c_device (THIS_MODULE, dst_attach, dst_detach); } - static void __exit exit_dst (void) { dvb_unregister_i2c_device (dst_attach); diff --git a/linux/drivers/media/dvb/frontends/dst.h b/linux/drivers/media/dvb/frontends/dst.h deleted file mode 100644 index fe4638497..000000000 --- a/linux/drivers/media/dvb/frontends/dst.h +++ /dev/null @@ -1,30 +0,0 @@ - -#define DST_IG_ADDR 0xff /* fake address to do gpio */ - -struct dst_gpio_enable { - u32 mask; - u32 enable; -}; - -struct dst_gpio_output { - u32 mask; - u32 highvals; -}; - -struct dst_gpio_read { - unsigned long value; -}; - -struct dst_gpio_packet { - u8 cmd; - union { - struct dst_gpio_enable enb; - struct dst_gpio_output outp; - struct dst_gpio_read rd; - } dstg; -}; - -#define DST_IG_ENABLE 0 -#define DST_IG_WRITE 1 -#define DST_IG_READ 2 -#define DST_IG_TS 3 |