diff options
Diffstat (limited to 'linux/drivers/media/dvb/b2c2')
-rw-r--r-- | linux/drivers/media/dvb/b2c2/skystar2.c | 1005 |
1 files changed, 482 insertions, 523 deletions
diff --git a/linux/drivers/media/dvb/b2c2/skystar2.c b/linux/drivers/media/dvb/b2c2/skystar2.c index 5c8a11b63..5f8f678b9 100644 --- a/linux/drivers/media/dvb/b2c2/skystar2.c +++ b/linux/drivers/media/dvb/b2c2/skystar2.c @@ -5,11 +5,12 @@ * Copyright (C) 2003 Vadim Catana, skystar@moldova.cc * * FIX: DISEQC Tone Burst in flexcop_diseqc_ioctl() - * FIX: FULL soft DiSEqC for skystar2 (FlexCopII rev .130) VP310 equipped - * Vincenzo Di Massa, hawk.it at tiscalinet.it + * FIX: FULL soft DiSEqC for skystar2 (FlexCopII rev 130) VP310 equipped + * Vincenzo Di Massa, hawk.it at tiscalinet.it * - * IMP: Converted to Linux coding style - * Roberto Ragusa, r.ragusa at libero.it + * Converted to Linux coding style + * Misc reorganization, polishing, restyling + * Roberto Ragusa, r.ragusa at libero.it * * Added hardware filtering support, * Niklas Peinecke, peinecke at gdv.uni-hannover.de @@ -54,16 +55,15 @@ static int debug = 0; #define dprintk(x...) do { if (debug>=1) printk(x); } while (0) #define ddprintk(x...) do { if (debug>=2) printk(x); } while (0) -static int enable_hw_filters=1; +static int enable_hw_filters = 2; -#define SIZE_OF_BUF_DMA1 0x3AC00 +#define SIZE_OF_BUF_DMA1 0x3ac00 #define SIZE_OF_BUF_DMA2 0x758 -#define N_HW_FILTERS (6+32) +#define MAX_N_HW_FILTERS (6+32) #define N_PID_SLOTS 256 struct dmaq { - u32 bus_addr; u32 head; u32 tail; @@ -73,7 +73,6 @@ struct dmaq { struct adapter { - struct pci_dev *pdev; u8 card_revision; @@ -106,37 +105,31 @@ struct adapter { spinlock_t lock; - u16 pids[N_HW_FILTERS]; + int useable_hw_filters; + u16 hw_pids[MAX_N_HW_FILTERS]; u16 pid_list[N_PID_SLOTS]; - u8 pid_rc[N_PID_SLOTS]; // ref counters for the pids - u16 pid_count; - int whole_bandwidth; + u8 pid_rc[N_PID_SLOTS]; // ref counters for the pids + int pid_count; + int whole_bandwidth_count; u32 mac_filter; }; #define write_reg_dw(adapter,reg,value) writel(value, adapter->io_mem + reg) #define read_reg_dw(adapter,reg) readl(adapter->io_mem + reg) -static void write_reg_op(struct adapter *adapter, u32 reg, u32 operation, u32 andvalue, u32 orvalue) +static void write_reg_bitfield(struct adapter *adapter, u32 reg, u32 zeromask, u32 orvalue) { u32 tmp; tmp = read_reg_dw(adapter, reg); - - if (operation == 1) - tmp = tmp | orvalue; - if (operation == 2) - tmp = tmp & andvalue; - if (operation == 3) - tmp = (tmp & andvalue) | orvalue; - + tmp = (tmp & ~zeromask) | orvalue; write_reg_dw(adapter, reg, tmp); } /* i2c functions */ -static int i2c_main_write_for_flex2(struct adapter * adapter, u32 command, u8 * buf, u32 retries) +static int i2c_main_write_for_flex2(struct adapter *adapter, u32 command, u8 *buf, int retries) { - u32 i; + int i; u32 value; write_reg_dw(adapter, 0x100, 0); @@ -153,7 +146,6 @@ static int i2c_main_write_for_flex2(struct adapter * adapter, u32 command, u8 * return 1; } } else { - write_reg_dw(adapter, 0x100, 0); write_reg_dw(adapter, 0x100, command); } @@ -173,7 +165,7 @@ static void i2c_main_setup(u32 device, u32 chip_addr, u8 op, u8 addr, u32 value, *command = *command | 0x01000000; } -static int flex_i2c_read4(struct adapter * adapter, u32 device, u32 chip_addr, u16 addr, u8 * buf, u8 len) +static int flex_i2c_read4(struct adapter *adapter, u32 device, u32 chip_addr, u16 addr, u8 *buf, u8 len) { u32 command; u32 value; @@ -198,7 +190,7 @@ static int flex_i2c_read4(struct adapter * adapter, u32 device, u32 chip_addr, u return result; } -static int flex_i2c_write4(struct adapter * adapter, u32 device, u32 chip_addr, u32 addr, u8 * buf, u8 len) +static int flex_i2c_write4(struct adapter *adapter, u32 device, u32 chip_addr, u32 addr, u8 *buf, u8 len) { u32 command; u32 value; @@ -228,7 +220,7 @@ static void fixchipaddr(u32 device, u32 bus, u32 addr, u32 *ret) *ret = bus; } -static u32 flex_i2c_read(struct adapter * adapter, u32 device, u32 bus, u32 addr, u8 * buf, u32 len) +static u32 flex_i2c_read(struct adapter *adapter, u32 device, u32 bus, u32 addr, u8 *buf, u32 len) { u32 chipaddr; u32 bytes_to_transfer; @@ -257,7 +249,7 @@ static u32 flex_i2c_read(struct adapter * adapter, u32 device, u32 bus, u32 addr return buf - start; } -static u32 flex_i2c_write(struct adapter * adapter, u32 device, u32 bus, u32 addr, u8 * buf, u32 len) +static u32 flex_i2c_write(struct adapter *adapter, u32 device, u32 bus, u32 addr, u8 *buf, u32 len) { u32 chipaddr; u32 bytes_to_transfer; @@ -296,78 +288,74 @@ static int master_xfer(struct dvb_i2c_bus *i2c, const struct i2c_msg *msgs, int ddprintk("%s: %d messages to transfer\n", __FUNCTION__, num); - for (i = 0; i < num; i++) - { + for (i = 0; i < num; i++) { ddprintk("message %d: flags=0x%x, addr=0x%x, buf=0x%x, len=%d \n", i, - msgs[i].flags, msgs[i].addr, msgs[i].buf[0], msgs[i].len); + msgs[i].flags, msgs[i].addr, msgs[i].buf[0], msgs[i].len); /* allow only the mt312 and stv0299 frontends to access the bus */ - if ((msgs[i].addr != 0x0E) && (msgs[i].addr != 0x68) && (msgs[i].addr != 0x61) ) - { - up(&tmp->i2c_sem); + if ((msgs[i].addr != 0x0e) && (msgs[i].addr != 0x68) && (msgs[i].addr != 0x61)) { + up(&tmp->i2c_sem); - return -EREMOTEIO; + return -EREMOTEIO; } } // read command - if ( (num == 2) && (msgs[0].flags == 0) && (msgs[1].flags == I2C_M_RD) && - (msgs[0].buf != NULL) && (msgs[1].buf != NULL) ) - { - ret = flex_i2c_read(tmp, 0x10000000, msgs[0].addr, msgs[0].buf[0], msgs[1].buf, msgs[1].len); - - up(&tmp->i2c_sem); - - if (ret != msgs[1].len) - { - printk("%s: read error !\n", __FUNCTION__); - printk("message 0: flags=0x%x, addr=0x%x, buf=0x%x, len=%d \n", - msgs[0].flags, msgs[0].addr, msgs[0].buf[0], msgs[0].len); - printk("message 1: flags=0x%x, addr=0x%x, buf=0x%x, len=%d \n", - msgs[1].flags, msgs[1].addr, msgs[1].buf[0], msgs[1].len); - - return -EREMOTEIO; - } - - return num; - } + if ((num == 2) && (msgs[0].flags == 0) && (msgs[1].flags == I2C_M_RD) && (msgs[0].buf != NULL) && (msgs[1].buf != NULL)) { + + ret = flex_i2c_read(tmp, 0x10000000, msgs[0].addr, msgs[0].buf[0], msgs[1].buf, msgs[1].len); + + up(&tmp->i2c_sem); + + if (ret != msgs[1].len) { + printk("%s: read error !\n", __FUNCTION__); + + for (i = 0; i < 2; i++) { + printk("message %d: flags=0x%x, addr=0x%x, buf=0x%x, len=%d \n", i, + msgs[i].flags, msgs[i].addr, msgs[i].buf[0], msgs[i].len); + } + + return -EREMOTEIO; + } + return num; + } // write command for (i = 0; i < num; i++) { - if ( (msgs[i].flags != 0) || (msgs[i].buf == NULL) || ( msgs[i].len < 2 ) ) return -EINVAL; + if ((msgs[i].flags != 0) || (msgs[i].buf == NULL) || (msgs[i].len < 2)) + return -EINVAL; - ret = flex_i2c_write(tmp, 0x10000000, msgs[i].addr, msgs[i].buf[0], &msgs[i].buf[1], msgs[i].len - 1); + ret = flex_i2c_write(tmp, 0x10000000, msgs[i].addr, msgs[i].buf[0], &msgs[i].buf[1], msgs[i].len - 1); - up(&tmp->i2c_sem); + up(&tmp->i2c_sem); - if (ret != msgs[0].len - 1) - { - printk("%s: write error %i !\n", __FUNCTION__, ret); + if (ret != msgs[0].len - 1) { + printk("%s: write error %i !\n", __FUNCTION__, ret); + + printk("message %d: flags=0x%x, addr=0x%x, buf[0]=0x%x, len=%d \n", i, + msgs[i].flags, msgs[i].addr, msgs[i].buf[0], msgs[i].len); + + return -EREMOTEIO; + } - printk("message %d: flags=0x%x, addr=0x%x, buf[0]=0x%x, len=%d \n", i, - msgs[i].flags, msgs[i].addr, msgs[i].buf[0], msgs[i].len); - - return -EREMOTEIO; - } - - return num; + return num; } printk("%s: unknown command format !\n", __FUNCTION__); - + return -EINVAL; } /* SRAM (Skystar2 rev2.3 has one "ISSI IS61LV256" chip on board, but it seems that FlexCopII can work with more than one chip) */ -static void sram_set_net_dest(struct adapter * adapter, u8 dest) +static void sram_set_net_dest(struct adapter *adapter, u8 dest) { u32 tmp; udelay(1000); - tmp = (read_reg_dw(adapter, 0x714) & 0xFFFFFFFC) | (dest & 3); + tmp = (read_reg_dw(adapter, 0x714) & 0xfffffffc) | (dest & 3); udelay(1000); @@ -376,17 +364,17 @@ static void sram_set_net_dest(struct adapter * adapter, u8 dest) udelay(1000); - /* return value is never used? */ + /*return value is never used? */ /* return tmp; */ } -static void sram_set_cai_dest(struct adapter * adapter, u8 dest) +static void sram_set_cai_dest(struct adapter *adapter, u8 dest) { u32 tmp; udelay(1000); - tmp = (read_reg_dw(adapter, 0x714) & 0xFFFFFFF3) | ((dest & 3) << 2); + tmp = (read_reg_dw(adapter, 0x714) & 0xfffffff3) | ((dest & 3) << 2); udelay(1000); udelay(1000); @@ -396,17 +384,17 @@ static void sram_set_cai_dest(struct adapter * adapter, u8 dest) udelay(1000); - /* return value is never used? */ + /*return value is never used? */ /* return tmp; */ } -static void sram_set_cao_dest(struct adapter * adapter, u8 dest) +static void sram_set_cao_dest(struct adapter *adapter, u8 dest) { u32 tmp; udelay(1000); - tmp = (read_reg_dw(adapter, 0x714) & 0xFFFFFFCF) | ((dest & 3) << 4); + tmp = (read_reg_dw(adapter, 0x714) & 0xffffffcf) | ((dest & 3) << 4); udelay(1000); udelay(1000); @@ -416,17 +404,17 @@ static void sram_set_cao_dest(struct adapter * adapter, u8 dest) udelay(1000); - /* return value is never used? */ + /*return value is never used? */ /* return tmp; */ } -static void sram_set_media_dest(struct adapter * adapter, u8 dest) +static void sram_set_media_dest(struct adapter *adapter, u8 dest) { u32 tmp; udelay(1000); - tmp = (read_reg_dw(adapter, 0x714) & 0xFFFFFF3F) | ((dest & 3) << 6); + tmp = (read_reg_dw(adapter, 0x714) & 0xffffff3f) | ((dest & 3) << 6); udelay(1000); udelay(1000); @@ -449,9 +437,10 @@ static void sram_set_media_dest(struct adapter * adapter, u8 dest) bits 28-29 : memory bank selector bit 31 : busy flag */ -static void flex_sram_write(struct adapter *adapter, u32 bank, u32 addr, u8 * buf, u32 len) +static void flex_sram_write(struct adapter *adapter, u32 bank, u32 addr, u8 *buf, u32 len) { - u32 i, command, retries; + int i, retries; + u32 command; for (i = 0; i < len; i++) { command = bank | addr | 0x04000000 | (*buf << 0x10); @@ -473,9 +462,10 @@ static void flex_sram_write(struct adapter *adapter, u32 bank, u32 addr, u8 * bu } } -static void flex_sram_read(struct adapter *adapter, u32 bank, u32 addr, u8 * buf, u32 len) +static void flex_sram_read(struct adapter *adapter, u32 bank, u32 addr, u8 *buf, u32 len) { - u32 i, command, value, retries; + int i, retries; + u32 command, value; for (i = 0; i < len; i++) { command = bank | addr | 0x04008000; @@ -511,47 +501,47 @@ static void flex_sram_read(struct adapter *adapter, u32 bank, u32 addr, u8 * buf } } -static void sram_writeChunk(struct adapter *adapter, u32 addr, u8 * buf, u16 len) +static void sram_writeChunk(struct adapter *adapter, u32 addr, u8 *buf, u16 len) { u32 bank; bank = 0; if (adapter->dw_sram_type == 0x20000) { - bank = (addr & 0x18000) << 0x0D; + bank = (addr & 0x18000) << 0x0d; } if (adapter->dw_sram_type == 0x00000) { - if ((addr >> 0x0F) == 0) + if ((addr >> 0x0f) == 0) bank = 0x20000000; else bank = 0x10000000; } - flex_sram_write(adapter, bank, addr & 0x7FFF, buf, len); + flex_sram_write(adapter, bank, addr & 0x7fff, buf, len); } -static void sram_readChunk(struct adapter *adapter, u32 addr, u8 * buf, u16 len) +static void sram_readChunk(struct adapter *adapter, u32 addr, u8 *buf, u16 len) { u32 bank; bank = 0; if (adapter->dw_sram_type == 0x20000) { - bank = (addr & 0x18000) << 0x0D; + bank = (addr & 0x18000) << 0x0d; } if (adapter->dw_sram_type == 0x00000) { - if ((addr >> 0x0F) == 0) + if ((addr >> 0x0f) == 0) bank = 0x20000000; else bank = 0x10000000; } - flex_sram_read(adapter, bank, addr & 0x7FFF, buf, len); + flex_sram_read(adapter, bank, addr & 0x7fff, buf, len); } -static void sram_read(struct adapter *adapter, u32 addr, u8 * buf, u32 len) +static void sram_read(struct adapter *adapter, u32 addr, u8 *buf, u32 len) { u32 length; @@ -561,8 +551,8 @@ static void sram_read(struct adapter *adapter, u32 addr, u8 * buf, u32 len) // check if the address range belongs to the same // 32K memory chip. If not, the data is read from // one chip at a time. - if ((addr >> 0x0F) != ((addr + len - 1) >> 0x0F)) { - length = (((addr >> 0x0F) + 1) << 0x0F) - addr; + if ((addr >> 0x0f) != ((addr + len - 1) >> 0x0f)) { + length = (((addr >> 0x0f) + 1) << 0x0f) - addr; } sram_readChunk(adapter, addr, buf, length); @@ -573,7 +563,7 @@ static void sram_read(struct adapter *adapter, u32 addr, u8 * buf, u32 len) } } -static void sram_write(struct adapter *adapter, u32 addr, u8 * buf, u32 len) +static void sram_write(struct adapter *adapter, u32 addr, u8 *buf, u32 len) { u32 length; @@ -583,8 +573,8 @@ static void sram_write(struct adapter *adapter, u32 addr, u8 * buf, u32 len) // check if the address range belongs to the same // 32K memory chip. If not, the data is written to // one chip at a time. - if ((addr >> 0x0F) != ((addr + len - 1) >> 0x0F)) { - length = (((addr >> 0x0F) + 1) << 0x0F) - addr; + if ((addr >> 0x0f) != ((addr + len - 1) >> 0x0f)) { + length = (((addr >> 0x0f) + 1) << 0x0f) - addr; } sram_writeChunk(adapter, addr, buf, length); @@ -597,19 +587,19 @@ static void sram_write(struct adapter *adapter, u32 addr, u8 * buf, u32 len) static void sram_set_size(struct adapter *adapter, u32 mask) { - write_reg_dw(adapter, 0x71C, (mask | (~0x30000 & read_reg_dw(adapter, 0x71C)))); + write_reg_dw(adapter, 0x71c, (mask | (~0x30000 & read_reg_dw(adapter, 0x71c)))); } static void sram_init(struct adapter *adapter) { u32 tmp; - tmp = read_reg_dw(adapter, 0x71C); + tmp = read_reg_dw(adapter, 0x71c); - write_reg_dw(adapter, 0x71C, 1); + write_reg_dw(adapter, 0x71c, 1); - if (read_reg_dw(adapter, 0x71C) != 0) { - write_reg_dw(adapter, 0x71C, tmp); + if (read_reg_dw(adapter, 0x71c) != 0) { + write_reg_dw(adapter, 0x71c, tmp); adapter->dw_sram_type = tmp & 0x30000; @@ -635,8 +625,8 @@ static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr) sram_set_size(adapter, mask); sram_init(adapter); - tmp2 = 0xA5; - tmp1 = 0x4F; + tmp2 = 0xa5; + tmp1 = 0x4f; sram_write(adapter, addr, &tmp2, 1); sram_write(adapter, addr + 4, &tmp1, 1); @@ -648,13 +638,13 @@ static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr) sram_read(adapter, addr, &tmp2, 1); sram_read(adapter, addr, &tmp2, 1); - dprintk("%s: wrote 0xA5, read 0x%2x\n", __FUNCTION__, tmp2); + dprintk("%s: wrote 0xa5, read 0x%2x\n", __FUNCTION__, tmp2); - if (tmp2 != 0xA5) + if (tmp2 != 0xa5) return 0; - tmp2 = 0x5A; - tmp1 = 0xF4; + tmp2 = 0x5a; + tmp1 = 0xf4; sram_write(adapter, addr, &tmp2, 1); sram_write(adapter, addr + 4, &tmp1, 1); @@ -666,15 +656,15 @@ static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr) sram_read(adapter, addr, &tmp2, 1); sram_read(adapter, addr, &tmp2, 1); - dprintk("%s: wrote 0x5A, read 0x%2x\n", __FUNCTION__, tmp2); + dprintk("%s: wrote 0x5a, read 0x%2x\n", __FUNCTION__, tmp2); - if (tmp2 != 0x5A) + if (tmp2 != 0x5a) return 0; return 1; } -static u32 sram_length(struct adapter * adapter) +static u32 sram_length(struct adapter *adapter) { if (adapter->dw_sram_type == 0x10000) return 32768; // 32K @@ -694,10 +684,10 @@ static u32 sram_length(struct adapter * adapter) FlexCop works only with one bank at a time. The bank is selected by bits 28-29 of the 0x700 register. - bank 0 covers addresses 0x00000-0x07FFF - bank 1 covers addresses 0x08000-0x0FFFF - bank 2 covers addresses 0x10000-0x17FFF - bank 3 covers addresses 0x18000-0x1FFFF + bank 0 covers addresses 0x00000-0x07fff + bank 1 covers addresses 0x08000-0x0ffff + bank 2 covers addresses 0x10000-0x17fff + bank 3 covers addresses 0x18000-0x1ffff */ static int sram_detect_for_flex2(struct adapter *adapter) { @@ -708,17 +698,17 @@ static int sram_detect_for_flex2(struct adapter *adapter) tmp = read_reg_dw(adapter, 0x208); write_reg_dw(adapter, 0x208, 0); - tmp2 = read_reg_dw(adapter, 0x71C); + tmp2 = read_reg_dw(adapter, 0x71c); dprintk("%s: tmp2 = %x\n", __FUNCTION__, tmp2); - write_reg_dw(adapter, 0x71C, 1); + write_reg_dw(adapter, 0x71c, 1); - tmp3 = read_reg_dw(adapter, 0x71C); + tmp3 = read_reg_dw(adapter, 0x71c); dprintk("%s: tmp3 = %x\n", __FUNCTION__, tmp3); - write_reg_dw(adapter, 0x71C, tmp2); + write_reg_dw(adapter, 0x71c, tmp2); // check for internal SRAM ??? tmp3--; @@ -775,22 +765,23 @@ static void sll_detect_sram_size(struct adapter *adapter) { sram_detect_for_flex2(adapter); } -/* EEPROM (Skystar2 has one "24LC08B" chip on board) */ + +/*EEPROM (Skystar2 has one "24LC08B" chip on board) */ /* -static int eeprom_write(struct adapter *adapter, u16 addr, u8 * buf, u16 len) +static int eeprom_write(struct adapter *adapter, u16 addr, u8 *buf, u16 len) { return flex_i2c_write(adapter, 0x20000000, 0x50, addr, buf, len); } */ -static int eeprom_read(struct adapter *adapter, u16 addr, u8 * buf, u16 len) +static int eeprom_read(struct adapter *adapter, u16 addr, u8 *buf, u16 len) { return flex_i2c_read(adapter, 0x20000000, 0x50, addr, buf, len); } -u8 calc_lrc(u8 * buf, u32 len) +u8 calc_lrc(u8 *buf, int len) { - u32 i; + int i; u8 sum; sum = 0; @@ -801,7 +792,7 @@ u8 calc_lrc(u8 * buf, u32 len) return sum; } -static int eeprom_lrc_read(struct adapter *adapter, u32 addr, u32 len, u8 * buf, u32 retries) +static int eeprom_lrc_read(struct adapter *adapter, u32 addr, u32 len, u8 *buf, int retries) { int i; @@ -816,7 +807,7 @@ static int eeprom_lrc_read(struct adapter *adapter, u32 addr, u32 len, u8 * buf, } /* -static int eeprom_lrc_write(struct adapter *adapter, u32 addr, u32 len, u8 * wbuf, u8 * rbuf, u32 retries) +static int eeprom_lrc_write(struct adapter *adapter, u32 addr, u32 len, u8 *wbuf, u8 *rbuf, int retries) { int i; @@ -835,7 +826,7 @@ static int eeprom_lrc_write(struct adapter *adapter, u32 addr, u32 len, u8 * wbu /* These functions could be used to unlock SkyStar2 cards. */ /* -static int eeprom_writeKey(struct adapter *adapter, u8 * key, u32 len) +static int eeprom_writeKey(struct adapter *adapter, u8 *key, u32 len) { u8 rbuf[20]; u8 wbuf[20]; @@ -850,17 +841,17 @@ static int eeprom_writeKey(struct adapter *adapter, u8 * key, u32 len) wbuf[18] = 0; wbuf[19] = calc_lrc(wbuf, 19); - return eeprom_lrc_write(adapter, 0x3E4, 20, wbuf, rbuf, 4); + return eeprom_lrc_write(adapter, 0x3e4, 20, wbuf, rbuf, 4); } -static int eeprom_readKey(struct adapter *adapter, u8 * key, u32 len) +static int eeprom_readKey(struct adapter *adapter, u8 *key, u32 len) { u8 buf[20]; if (len != 16) return 0; - if (eeprom_lrc_read(adapter, 0x3E4, 20, buf, 4) == 0) + if (eeprom_lrc_read(adapter, 0x3e4, 20, buf, 4) == 0) return 0; memcpy(key, buf, len); @@ -869,17 +860,17 @@ static int eeprom_readKey(struct adapter *adapter, u8 * key, u32 len) } */ -static int eeprom_get_mac_addr(struct adapter *adapter, char type, u8 * mac) +static int eeprom_get_mac_addr(struct adapter *adapter, char type, u8 *mac) { u8 tmp[8]; - if (eeprom_lrc_read(adapter, 0x3F8, 8, tmp, 4) != 0) { + if (eeprom_lrc_read(adapter, 0x3f8, 8, tmp, 4) != 0) { if (type != 0) { mac[0] = tmp[0]; mac[1] = tmp[1]; mac[2] = tmp[2]; - mac[3] = 0xFE; - mac[4] = 0xFF; + mac[3] = 0xfe; + mac[4] = 0xff; mac[5] = tmp[3]; mac[6] = tmp[4]; mac[7] = tmp[5]; @@ -911,7 +902,7 @@ static int eeprom_get_mac_addr(struct adapter *adapter, char type, u8 * mac) } /* -static char eeprom_set_mac_addr(struct adapter *adapter, char type, u8 * mac) +static char eeprom_set_mac_addr(struct adapter *adapter, char type, u8 *mac) { u8 tmp[8]; @@ -936,7 +927,7 @@ static char eeprom_set_mac_addr(struct adapter *adapter, char type, u8 * mac) tmp[6] = 0; tmp[7] = calc_lrc(tmp, 7); - if (eeprom_write(adapter, 0x3F8, tmp, 8) == 8) + if (eeprom_write(adapter, 0x3f8, tmp, 8) == 8) return 1; return 0; @@ -947,26 +938,38 @@ static char eeprom_set_mac_addr(struct adapter *adapter, char type, u8 * mac) /* every flexcop has 6 "lower" hw PID filters */ /* these are enabled by setting bits 0-5 of 0x208 */ -/* we do not check for id>5 here! */ -static void filter_enable_hw_filter(struct adapter *adapter,u8 id,u8 op) +/* for the 32 additional filters we have to select one */ +/* of them through 0x310 and modify through 0x314 */ +/* op: 0=disable, 1=enable */ +static void filter_enable_hw_filter(struct adapter *adapter, int id, u8 op) { - u32 mask=( 0x00000001 << id ); - dprintk("%s: id=%d op=%d\n", __FUNCTION__, id, op); - - if (op == 0) write_reg_op(adapter, 0x208, 2, ~mask, 0); - else write_reg_op(adapter, 0x208, 1, 0, mask); + if (id <= 5) { + u32 mask = (0x00000001 << id); + write_reg_bitfield(adapter, 0x208, mask, op ? mask : 0); + } else { + /* select */ + write_reg_bitfield(adapter, 0x310, 0x1f, (id - 6) & 0x1f); + /* modify */ + write_reg_bitfield(adapter, 0x314, 0x00006000, op ? 0x00004000 : 0); + } } /* this sets the PID that should pass the specified filter */ -static void pid_set_hw_pid(struct adapter * adapter,u8 id,u32 pid) -{ - u32 adr=0x300+((id&6)<<1); - - dprintk("%s: id=%d addr=%x %c pid=%d\n", __FUNCTION__, id, adr, (id&1)? 'h':'l', pid); - - if((id&1)==0) write_reg_op(adapter,adr,3,0xffff8000,pid&0x1fff); - else write_reg_op(adapter,adr,3,0x8000ffff,(pid&0x1fff)<<16); +static void pid_set_hw_pid(struct adapter *adapter, int id, u16 pid) +{ + dprintk("%s: id=%d pid=%d\n", __FUNCTION__, id, pid); + if (id <= 5) { + u32 adr = 0x300 + ((id & 6) << 1); + int shift = (id & 1) ? 16 : 0; + dprintk("%s: id=%d addr=%x %c pid=%d\n", __FUNCTION__, id, adr, (id & 1) ? 'h' : 'l', pid); + write_reg_bitfield(adapter, adr, (0x7fff) << shift, (pid & 0x1fff) << shift); + } else { + /* select */ + write_reg_bitfield(adapter, 0x310, 0x1f, (id - 6) & 0x1f); + /* modify */ + write_reg_bitfield(adapter, 0x314, 0x1fff, pid & 0x1fff); + } } @@ -975,13 +978,7 @@ static void filter_enable_null_filter(struct adapter *adapter, u32 op) { dprintk("%s: op=%x\n", __FUNCTION__, op); - if (op == 0) { - write_reg_op(adapter, 0x208, 2, ~0x00000040, 0); - - } else { - - write_reg_op(adapter, 0x208, 1, 0, 0x00000040); - } + write_reg_bitfield(adapter, 0x208, 0x00000040, op?0x00000040:0); } */ @@ -989,47 +986,16 @@ static void filter_enable_mask_filter(struct adapter *adapter, u32 op) { dprintk("%s: op=%x\n", __FUNCTION__, op); - if (op == 0) { - write_reg_op(adapter, 0x208, 2, ~0x00000080, 0); - - } else { - - write_reg_op(adapter, 0x208, 1, 0, 0x00000080); - } + write_reg_bitfield(adapter, 0x208, 0x00000080, op ? 0x00000080 : 0); } static void ctrl_enable_mac(struct adapter *adapter, u32 op) { - if (op == 0) { - write_reg_op(adapter, 0x208, 2, ~0x00004000, 0); - - } else { - - write_reg_op(adapter, 0x208, 1, 0, 0x00004000); - } + write_reg_bitfield(adapter, 0x208, 0x00004000, op ? 0x00004000 : 0); } -/* select data filter nr. id for setup */ -static void filter_select_data_filter(struct adapter *adapter,u8 id) -{ - write_reg_op(adapter,0x310,3,0xffffffe0,id&0x1f); -} - -/* enable data filter; 0: disable, 1: enable */ -static void filter_enable_data_filter(struct adapter *adapter,u8 op) -{ - if(op==0) write_reg_op(adapter,0x314,2,0xffff9fff,0); - else write_reg_op(adapter,0x314,3,0xffff9fff,0x00004000); -} - -/* set PID for data filter */ -static void pid_set_data_pid(struct adapter *adapter,u32 pid) -{ - write_reg_op(adapter,0x314,3,0xffffe000,pid & 0x1fff); -} - -static int ca_set_mac_dst_addr_filter(struct adapter *adapter, u8 * mac) +static int ca_set_mac_dst_addr_filter(struct adapter *adapter, u8 *mac) { u32 tmp1, tmp2; @@ -1037,7 +1003,7 @@ static int ca_set_mac_dst_addr_filter(struct adapter *adapter, u8 * mac) tmp2 = (mac[5] << 0x08) | mac[4]; write_reg_dw(adapter, 0x418, tmp1); - write_reg_dw(adapter, 0x41C, tmp2); + write_reg_dw(adapter, 0x41c, tmp2); return 0; } @@ -1046,16 +1012,12 @@ static int ca_set_mac_dst_addr_filter(struct adapter *adapter, u8 * mac) static void set_ignore_mac_filter(struct adapter *adapter, u8 op) { if (op != 0) { - write_reg_op(adapter, 0x208, 2, ~0x00004000, 0); - + write_reg_bitfield(adapter, 0x208, 0x00004000, 0); adapter->mac_filter = 1; - } else { - if (adapter->mac_filter != 0) { adapter->mac_filter = 0; - - write_reg_op(adapter, 0x208, 1, 0, 0x00004000); + write_reg_bitfield(adapter, 0x208, 0x00004000, 0x00004000); } } } @@ -1069,64 +1031,54 @@ static void check_null_filter_enable(struct adapter *adapter) } */ -static void pid_set_group_pid(struct adapter * adapter, u32 pid) +static void pid_set_group_pid(struct adapter *adapter, u16 pid) { u32 value; dprintk("%s: pid=%x\n", __FUNCTION__, pid); - - value = (pid & 0x3FFF) | (read_reg_dw(adapter, 0x30C) & 0xFFFF0000); - - write_reg_dw(adapter, 0x30C, value); - - /* return value is never used? */ -/* return value; */ + value = (pid & 0x3fff) | (read_reg_dw(adapter, 0x30c) & 0xffff0000); + write_reg_dw(adapter, 0x30c, value); } -static void pid_set_group_mask(struct adapter * adapter, u32 pid) +static void pid_set_group_mask(struct adapter *adapter, u16 pid) { u32 value; dprintk("%s: pid=%x\n", __FUNCTION__, pid); - - value = ((pid & 0x3FFF) << 0x10) | (read_reg_dw(adapter, 0x30C) & 0xFFFF); - - write_reg_dw(adapter, 0x30C, value); - - /* return value is never used? */ -/* return value; */ + value = ((pid & 0x3fff) << 0x10) | (read_reg_dw(adapter, 0x30c) & 0xffff); + write_reg_dw(adapter, 0x30c, value); } /* -static int pid_get_group_pid(struct adapter * adapter) +static int pid_get_group_pid(struct adapter *adapter) { - return read_reg_dw(adapter, 0x30C) & 0x00001FFF; + return read_reg_dw(adapter, 0x30c) & 0x00001fff; } -static int pid_get_group_mask(struct adapter * adapter) +static int pid_get_group_mask(struct adapter *adapter) { - return (read_reg_dw(adapter, 0x30C) >> 0x10)& 0x00001FFF; + return (read_reg_dw(adapter, 0x30c) >> 0x10)& 0x00001fff; } */ /* static void reset_hardware_pid_filter(struct adapter *adapter) { - pid_set_stream1_pid(adapter, 0x1FFF); + pid_set_stream1_pid(adapter, 0x1fff); - pid_set_stream2_pid(adapter, 0x1FFF); + pid_set_stream2_pid(adapter, 0x1fff); filter_enable_stream2_filter(adapter, 0); - pid_set_pcr_pid(adapter, 0x1FFF); + pid_set_pcr_pid(adapter, 0x1fff); filter_enable_pcr_filter(adapter, 0); - pid_set_pmt_pid(adapter, 0x1FFF); + pid_set_pmt_pid(adapter, 0x1fff); filter_enable_pmt_filter(adapter, 0); - pid_set_ecm_pid(adapter, 0x1FFF); + pid_set_ecm_pid(adapter, 0x1fff); filter_enable_ecm_filter(adapter, 0); - pid_set_emm_pid(adapter, 0x1FFF); + pid_set_emm_pid(adapter, 0x1fff); filter_enable_emm_filter(adapter, 0); } */ @@ -1135,184 +1087,171 @@ static void init_pids(struct adapter *adapter) { int i; - for (i = 0; i < N_HW_FILTERS; i++) - adapter->pids[i] = 0x1FFF; - adapter->pid_count=0; - adapter->whole_bandwidth = 0; - + adapter->pid_count = 0; + adapter->whole_bandwidth_count = 0; + for (i = 0; i < adapter->useable_hw_filters; i++) { + dprintk("%s: setting filter %d to 0x1fff\n", __FUNCTION__, i); + adapter->hw_pids[i] = 0x1fff; + pid_set_hw_pid(adapter, i, 0x1fff); + } + pid_set_group_pid(adapter, 0); - pid_set_group_mask(adapter, 0x1FE0); - pid_set_hw_pid(adapter,0,0x1FFF); - pid_set_hw_pid(adapter,1,0x1FFF); - pid_set_hw_pid(adapter,2,0x1FFF); - pid_set_hw_pid(adapter,3,0x1FFF); - pid_set_hw_pid(adapter,4,0x1FFF); - pid_set_hw_pid(adapter,5,0x1FFF); + pid_set_group_mask(adapter, 0x1fe0); } static void open_whole_bandwidth(struct adapter *adapter) { - dprintk("%s:\n", __FUNCTION__); - + dprintk("%s:\n", __FUNCTION__); pid_set_group_pid(adapter, 0); - pid_set_group_mask(adapter, 0); - +/* filter_enable_mask_filter(adapter, 1); +*/ } static void close_whole_bandwidth(struct adapter *adapter) { - dprintk("%s:\n", __FUNCTION__); - + dprintk("%s:\n", __FUNCTION__); pid_set_group_pid(adapter, 0); - pid_set_group_mask(adapter, 0x1fe0); - +/* filter_enable_mask_filter(adapter, 1); +*/ } -/* this tries to add the specified PID to be let through the - hw filters. return 1 on success. - if this cannot be done (all filter in use), returns -1 - for PID <= 0x1f there is always success reported, since - these are let through by the group filters anyway. */ -static int add_hw_pid(struct adapter *adapter, u32 pid) -{ - int num,i; - - if(pid<=0x1f) return 1; - - if(adapter->b2c2_revision==0xc0 || adapter->b2c2_revision==0xc3) - num=38; // FlexCop IIb & III have 6+32 hw filters - else num=6; // FlexCop II has 6 hw filters, every other should have at least 6 - - for (i=0; i<num; i++) { - if (adapter->pids[i] == 0x1fff) { // find a free pid slot - adapter->pids[i]=pid; - if(i<6) { - pid_set_hw_pid(adapter,i,pid); - filter_enable_hw_filter(adapter,i,1); - return 1; - } else { - filter_select_data_filter(adapter,i-6); - pid_set_data_pid(adapter,pid); - filter_enable_data_filter(adapter,1); +static void whole_bandwidth_inc(struct adapter *adapter) +{ + if (adapter->whole_bandwidth_count++ == 0) + open_whole_bandwidth(adapter); +} + +static void whole_bandwidth_dec(struct adapter *adapter) +{ + if (--adapter->whole_bandwidth_count <= 0) + close_whole_bandwidth(adapter); +} + +/* The specified PID has to be let through the + hw filters. + We try to allocate an hardware filter and open whole + bandwidth when allocation is impossible. + All pids<=0x1f pass through the group filter. + Returns 1 on success, -1 on error */ +static int add_hw_pid(struct adapter *adapter, u16 pid) +{ + int i; + + dprintk("%s: pid=%d\n", __FUNCTION__, pid); + + if (pid <= 0x1f) + return 1; + + if (pid == 0x2000) { + /* we can't use a filter, so no search */ + } else { + /* find an unused hardware filter */ + for (i = 0; i < adapter->useable_hw_filters; i++) { + dprintk("%s: pid=%d searching slot=%d\n", __FUNCTION__, pid, i); + if (adapter->hw_pids[i] == 0x1fff) { + dprintk("%s: pid=%d slot=%d\n", __FUNCTION__, pid, i); + adapter->hw_pids[i] = pid; + pid_set_hw_pid(adapter, i, pid); + filter_enable_hw_filter(adapter, i, 1); return 1; } } } - return -1; + /* if we have not used a filter, this pid depends on whole bandwidth */ + dprintk("%s: pid=%d whole_bandwidth\n", __FUNCTION__, pid); + whole_bandwidth_inc(adapter); + return 1; } /* returns -1 if the pid was not present in the filters */ -static int remove_hw_pid(struct adapter *adapter, u32 pid) -{ - int num,i; - - if(pid<=0x1f) return 1; - - if(adapter->b2c2_revision==0xc0 || adapter->b2c2_revision==0xc3) - num=38; // FlexCop IIb & III have 6+32 hw filters - else num=6; // FlexCop II has 6 hw filters, every other should have at least 6 - - for(i=0; i<num; i++) { - if (adapter->pids[i] == pid) { // find the pid slot - adapter->pids[i]=0x1fff; - if(i<6) { - pid_set_hw_pid(adapter,i,pid); - filter_enable_hw_filter(adapter,i,0); - return 1; - } else { - filter_select_data_filter(adapter,i-6); - pid_set_data_pid(adapter,pid); - filter_enable_data_filter(adapter,0); +static int remove_hw_pid(struct adapter *adapter, u16 pid) +{ + int i; + + dprintk("%s: pid=%d\n", __FUNCTION__, pid); + + if (pid <= 0x1f) + return 1; + + if (pid == 0x2000) { + /* we can't use a filter, so no search */ + } else { + for (i = 0; i < adapter->useable_hw_filters; i++) { + dprintk("%s: pid=%d searching slot=%d\n", __FUNCTION__, pid, i); + if (adapter->hw_pids[i] == pid) { // find the pid slot + dprintk("%s: pid=%d slot=%d\n", __FUNCTION__, pid, i); + adapter->hw_pids[i] = 0x1fff; + pid_set_hw_pid(adapter, i, 0x1fff); + filter_enable_hw_filter(adapter, i, 0); return 1; } } } - return -1; + /* if we have not used a filter, this pid depended on whole bandwith */ + dprintk("%s: pid=%d whole_bandwidth\n", __FUNCTION__, pid); + whole_bandwidth_dec(adapter); + return 1; } /* Adds a PID to the filters. - If there are no more hw filters available, open the whole - ts stream to pass by. - Adding a pid more than once has no effect. - If pid==0x2000, open whole ts stream also. - Returns 1 on success, -1 on error */ -static int add_pid(struct adapter *adapter,u32 pid) + Adding a pid more than once is possible, we keep reference counts. + Whole stream available through pid==0x2000. + Returns 1 on success, -1 on error */ +static int add_pid(struct adapter *adapter, u16 pid) { int i; - + dprintk("%s: pid=%d\n", __FUNCTION__, pid); - - if(pid==0x2000) { - if (adapter->whole_bandwidth == 0) - open_whole_bandwidth(adapter); - ++adapter->whole_bandwidth; - return 1; - } - - if (pid > 0x1ffe) return -1; - + + if (pid > 0x1ffe && pid != 0x2000) + return -1; + // check if the pid is already present - for(i=0; i<adapter->pid_count; i++) - if(adapter->pid_list[i]==pid) { - adapter->pid_rc[i]++; // increment ref counter + for (i = 0; i < adapter->pid_count; i++) + if (adapter->pid_list[i] == pid) { + adapter->pid_rc[i]++; // increment ref counter return 1; } - - if(adapter->pid_count==N_PID_SLOTS) return -1; // no more pids can be added - adapter->pid_list[adapter->pid_count]=pid; // register pid - adapter->pid_rc[adapter->pid_count]=1; + + if (adapter->pid_count == N_PID_SLOTS) + return -1; // no more pids can be added + adapter->pid_list[adapter->pid_count] = pid; // register pid + adapter->pid_rc[adapter->pid_count] = 1; adapter->pid_count++; - - // setup a filter for the pid - // if there are no filters left, let the whole ts pass - if (add_hw_pid(adapter,pid)==-1) { - if (adapter->whole_bandwidth == 0) - open_whole_bandwidth(adapter); - adapter->whole_bandwidth++; - } - + // hardware setting + add_hw_pid(adapter, pid); + return 1; } /* Removes a PID from the filters. */ -static int remove_pid(struct adapter *adapter, u32 pid) -{ - int i,j; - - if (pid==0x2000) { - if (adapter->whole_bandwidth <= 0) return -1; // cannot remove a pid that was not added ;) - adapter->whole_bandwidth--; - if (adapter->whole_bandwidth == 0) - close_whole_bandwidth(adapter); - return 1; - } - - if (pid > 0x1ffe && pid != 0x2000) return -1; - - // check if the pid is present - for (i=0; i<adapter->pid_count; i++) { - if(adapter->pid_list[i]==pid) { +static int remove_pid(struct adapter *adapter, u16 pid) +{ + int i, j; + + dprintk("%s: pid=%d\n", __FUNCTION__, pid); + + if (pid > 0x1ffe && pid != 0x2000) + return -1; + + // check if the pid is present (it must be!) + for (i = 0; i < adapter->pid_count; i++) { + if (adapter->pid_list[i] == pid) { adapter->pid_rc[i]--; - if(adapter->pid_rc[i]<=0) { + if (adapter->pid_rc[i] <= 0) { // remove from the list adapter->pid_count--; - for(j=i; j<adapter->pid_count; j++) { - adapter->pid_list[j]=adapter->pid_list[j+1]; - adapter->pid_rc[j]=adapter->pid_rc[j+1]; - } - // close filter and take care to reverse the effect of open_whole_bandwidth - if (remove_hw_pid(adapter,pid)==-1) { - if (adapter->whole_bandwidth > 0) - --adapter->whole_bandwidth; - if (adapter->whole_bandwidth == 0) - close_whole_bandwidth(adapter); + for (j = i; j < adapter->pid_count; j++) { + adapter->pid_list[j] = adapter->pid_list[j + 1]; + adapter->pid_rc[j] = adapter->pid_rc[j + 1]; } + // hardware setting + remove_hw_pid(adapter, pid); } - return 1; } } @@ -1323,18 +1262,12 @@ static int remove_pid(struct adapter *adapter, u32 pid) /* dma & irq */ static void ctrl_enable_smc(struct adapter *adapter, u32 op) { - if (op == 0) { - write_reg_op(adapter, 0x208, 2, ~0x00000800, 0); - - } else { - - write_reg_op(adapter, 0x208, 1, 0, 0x00000800); - } + write_reg_bitfield(adapter, 0x208, 0x00000800, op ? 0x00000800 : 0); } static void dma_enable_disable_irq(struct adapter *adapter, u32 flag1, u32 flag2, u32 flag3) { - adapter->dma_ctrl = adapter->dma_ctrl & 0x000F0000; + adapter->dma_ctrl = adapter->dma_ctrl & 0x000f0000; if (flag1 == 0) { if (flag2 == 0) @@ -1361,14 +1294,14 @@ static void dma_enable_disable_irq(struct adapter *adapter, u32 flag1, u32 flag2 } } -static void irq_dma_enable_disable_irq(struct adapter * adapter, u32 op) +static void irq_dma_enable_disable_irq(struct adapter *adapter, u32 op) { u32 value; - value = read_reg_dw(adapter, 0x208) & 0xFFF0FFFF; + value = read_reg_dw(adapter, 0x208) & 0xfff0ffff; if (op != 0) - value = value | (adapter->dma_ctrl & 0x000F0000); + value = value | (adapter->dma_ctrl & 0x000f0000); write_reg_dw(adapter, 0x208, value); } @@ -1389,7 +1322,7 @@ static void irq_dma_enable_disable_irq(struct adapter * adapter, u32 op) subbuffer. The last 2 bits contain 0, when dma1 is disabled and 1, when dma1 is enabled. - the first 30 bits of register 0x00C contain the address of the second + the first 30 bits of register 0x00c contain the address of the second subbuffer. the last 2 bits contain 1. register 0x008 will contain the address of the subbuffer that was filled @@ -1404,7 +1337,7 @@ static void irq_dma_enable_disable_irq(struct adapter * adapter, u32 op) subbuffer. The last 2 bits contain 0, when dma1 is disabled and 1, when dma1 is enabled. - the first 30 bits of register 0x01C contain the address of the second + the first 30 bits of register 0x01c contain the address of the second subbuffer. the last 2 bits contain 1. register 0x018 contains the address of the subbuffer that was filled @@ -1421,9 +1354,9 @@ static int dma_init_dma(struct adapter *adapter, u32 dma_channel) subbufsize = (((adapter->dmaq1.buffer_size / 2) / 4) << 8) | subbuffers; - subbuf0 = adapter->dmaq1.bus_addr & 0xFFFFFFFC; + subbuf0 = adapter->dmaq1.bus_addr & 0xfffffffc; - subbuf1 = ((adapter->dmaq1.bus_addr + adapter->dmaq1.buffer_size / 2) & 0xFFFFFFFC) | 1; + subbuf1 = ((adapter->dmaq1.bus_addr + adapter->dmaq1.buffer_size / 2) & 0xfffffffc) | 1; dprintk("%s: first subbuffer address = 0x%x\n", __FUNCTION__, subbuf0); udelay(1000); @@ -1435,10 +1368,10 @@ static int dma_init_dma(struct adapter *adapter, u32 dma_channel) dprintk("%s: second subbuffer address = 0x%x\n", __FUNCTION__, subbuf1); udelay(1000); - write_reg_dw(adapter, 0x00C, subbuf1); + write_reg_dw(adapter, 0x00c, subbuf1); - dprintk("%s: counter = 0x%x\n", __FUNCTION__, adapter->dmaq1.bus_addr & 0xFFFFFFFC); - write_reg_dw(adapter, 0x008, adapter->dmaq1.bus_addr & 0xFFFFFFFC); + dprintk("%s: counter = 0x%x\n", __FUNCTION__, adapter->dmaq1.bus_addr & 0xfffffffc); + write_reg_dw(adapter, 0x008, adapter->dmaq1.bus_addr & 0xfffffffc); udelay(1000); if (subbuffers == 0) @@ -1461,9 +1394,9 @@ static int dma_init_dma(struct adapter *adapter, u32 dma_channel) subbufsize = (((adapter->dmaq2.buffer_size / 2) / 4) << 8) | subbuffers; - subbuf0 = adapter->dmaq2.bus_addr & 0xFFFFFFFC; + subbuf0 = adapter->dmaq2.bus_addr & 0xfffffffc; - subbuf1 = ((adapter->dmaq2.bus_addr + adapter->dmaq2.buffer_size / 2) & 0xFFFFFFFC) | 1; + subbuf1 = ((adapter->dmaq2.bus_addr + adapter->dmaq2.buffer_size / 2) & 0xfffffffc) | 1; dprintk("%s: first subbuffer address = 0x%x\n", __FUNCTION__, subbuf0); udelay(1000); @@ -1475,7 +1408,7 @@ static int dma_init_dma(struct adapter *adapter, u32 dma_channel) dprintk("%s: second buffer address = 0x%x\n", __FUNCTION__, subbuf1); udelay(1000); - write_reg_dw(adapter, 0x01C, subbuf1); + write_reg_dw(adapter, 0x01c, subbuf1); sram_set_cai_dest(adapter, 2); } @@ -1486,14 +1419,10 @@ static int dma_init_dma(struct adapter *adapter, u32 dma_channel) static void ctrl_enable_receive_data(struct adapter *adapter, u32 op) { if (op == 0) { - write_reg_op(adapter, 0x208, 2, ~0x00008000, 0); - + write_reg_bitfield(adapter, 0x208, 0x00008000, 0); adapter->dma_status = adapter->dma_status & ~0x00000004; - } else { - - write_reg_op(adapter, 0x208, 1, 0, 0x00008000); - + write_reg_bitfield(adapter, 0x208, 0x00008000, 0x00008000); adapter->dma_status = adapter->dma_status | 0x00000004; } } @@ -1501,7 +1430,7 @@ static void ctrl_enable_receive_data(struct adapter *adapter, u32 op) /* bit 0 of dma_mask is set to 1 if dma1 channel has to be enabled/disabled bit 1 of dma_mask is set to 1 if dma2 channel has to be enabled/disabled */ -static void dma_start_stop0x2102(struct adapter *adapter, u32 dma_mask, u32 start_stop) +static void dma_start_stop(struct adapter *adapter, u32 dma_mask, int start_stop) { u32 dma_enable, dma1_enable, dma2_enable; @@ -1525,7 +1454,7 @@ static void dma_start_stop0x2102(struct adapter *adapter, u32 dma_mask, u32 star // enable dma1 and dma2 if ((dma1_enable == 1) && (dma2_enable == 1)) { write_reg_dw(adapter, 0x000, adapter->dmaq1.bus_addr | 1); - write_reg_dw(adapter, 0x00C, (adapter->dmaq1.bus_addr + adapter->dmaq1.buffer_size / 2) | 1); + write_reg_dw(adapter, 0x00c, (adapter->dmaq1.bus_addr + adapter->dmaq1.buffer_size / 2) | 1); write_reg_dw(adapter, 0x010, adapter->dmaq2.bus_addr | 1); ctrl_enable_receive_data(adapter, 1); @@ -1535,7 +1464,7 @@ static void dma_start_stop0x2102(struct adapter *adapter, u32 dma_mask, u32 star // enable dma1 if ((dma1_enable == 1) && (dma2_enable == 0)) { write_reg_dw(adapter, 0x000, adapter->dmaq1.bus_addr | 1); - write_reg_dw(adapter, 0x00C, (adapter->dmaq1.bus_addr + adapter->dmaq1.buffer_size / 2) | 1); + write_reg_dw(adapter, 0x00c, (adapter->dmaq1.bus_addr + adapter->dmaq1.buffer_size / 2) | 1); ctrl_enable_receive_data(adapter, 1); @@ -1558,31 +1487,31 @@ static void dma_start_stop0x2102(struct adapter *adapter, u32 dma_mask, u32 star } else { - dprintk("%s: stoping dma\n", __FUNCTION__); + dprintk("%s: stopping dma\n", __FUNCTION__); dma_enable = adapter->dma_status & 0x00000003; if (((dma_mask & 1) != 0) && ((adapter->dma_status & 1) != 0)) { - dma_enable = dma_enable & 0xFFFFFFFE; + dma_enable = dma_enable & 0xfffffffe; } if (((dma_mask & 2) != 0) && ((adapter->dma_status & 2) != 0)) { - dma_enable = dma_enable & 0xFFFFFFFD; + dma_enable = dma_enable & 0xfffffffd; } - //stop dma + // stop dma if ((dma_enable == 0) && ((adapter->dma_status & 4) != 0)) { ctrl_enable_receive_data(adapter, 0); udelay(3000); } - //disable dma1 + // disable dma1 if (((dma_mask & 1) != 0) && ((adapter->dma_status & 1) != 0) && (adapter->dmaq1.bus_addr != 0)) { write_reg_dw(adapter, 0x000, adapter->dmaq1.bus_addr); - write_reg_dw(adapter, 0x00C, (adapter->dmaq1.bus_addr + adapter->dmaq1.buffer_size / 2) | 1); + write_reg_dw(adapter, 0x00c, (adapter->dmaq1.bus_addr + adapter->dmaq1.buffer_size / 2) | 1); adapter->dma_status = adapter->dma_status & ~0x00000001; } - //disable dma2 + // disable dma2 if (((dma_mask & 2) != 0) && ((adapter->dma_status & 2) != 0) && (adapter->dmaq2.bus_addr != 0)) { write_reg_dw(adapter, 0x010, adapter->dmaq2.bus_addr); @@ -1591,7 +1520,7 @@ static void dma_start_stop0x2102(struct adapter *adapter, u32 dma_mask, u32 star } } -static void open_stream(struct adapter *adapter, u32 pid) +static void open_stream(struct adapter *adapter, u16 pid) { u32 dma_mask; @@ -1599,12 +1528,7 @@ static void open_stream(struct adapter *adapter, u32 pid) filter_enable_mask_filter(adapter, 1); - if(enable_hw_filters==1) add_pid(adapter, pid); - else { - if (adapter->whole_bandwidth == 0) - open_whole_bandwidth(adapter); - adapter->whole_bandwidth++; - } + add_pid(adapter, pid); dprintk("%s: adapter->dma_status=%x\n", __FUNCTION__, adapter->dma_status); @@ -1630,12 +1554,12 @@ static void open_stream(struct adapter *adapter, u32 pid) if (dma_mask != 0) { irq_dma_enable_disable_irq(adapter, 1); - dma_start_stop0x2102(adapter, dma_mask, 1); + dma_start_stop(adapter, dma_mask, 1); } } } -static void close_stream(struct adapter *adapter, u32 pid) +static void close_stream(struct adapter *adapter, u16 pid) { if (adapter->capturing > 0) --adapter->capturing; @@ -1649,20 +1573,12 @@ static void close_stream(struct adapter *adapter, u32 pid) dma_mask = dma_mask | 0x00000001; if ((adapter->dma_status & 2) != 0) dma_mask = dma_mask | 0x00000002; - + if (dma_mask != 0) { - dma_start_stop0x2102(adapter, dma_mask, 0); - } - } - if (enable_hw_filters==1) - remove_pid(adapter, pid); - else { - if (adapter->whole_bandwidth > 0) { - adapter->whole_bandwidth--; - if (adapter->whole_bandwidth == 0) - close_whole_bandwidth(adapter); + dma_start_stop(adapter, dma_mask, 0); } } + remove_pid(adapter, pid); } static void interrupt_service_dma1(struct adapter *adapter) @@ -1694,9 +1610,9 @@ static void interrupt_service_dma1(struct adapter *adapter) n_num_new_bytes_transferred = (adapter->dmaq1.buffer_size - adapter->dmaq1.tail) + n_cur_dma_counter; } - ddprintk("%s: n_cur_dma_counter = %d\n" , __FUNCTION__, n_cur_dma_counter); - ddprintk("%s: dmaq1.tail = %d\n" , __FUNCTION__, adapter->dmaq1.tail); - ddprintk("%s: bytes_transferred = %d\n" , __FUNCTION__, n_num_new_bytes_transferred); + ddprintk("%s: n_cur_dma_counter = %d\n", __FUNCTION__, n_cur_dma_counter); + ddprintk("%s: dmaq1.tail = %d\n", __FUNCTION__, adapter->dmaq1.tail); + ddprintk("%s: bytes_transferred = %d\n", __FUNCTION__, n_num_new_bytes_transferred); if (n_num_new_bytes_transferred < dw_default_packet_size) return; @@ -1707,15 +1623,16 @@ static void interrupt_service_dma1(struct adapter *adapter) pb_dma_buf_cur_pos = adapter->dmaq1.buffer + adapter->dmaq1.tail; if (adapter->dmaq1.buffer + adapter->dmaq1.buffer_size < adapter->dmaq1.buffer + adapter->dmaq1.tail + 188) { - memcpy(gb_tmp_buffer, adapter->dmaq1.buffer + adapter->dmaq1.tail, adapter->dmaq1.buffer_size - adapter->dmaq1.tail); - memcpy(gb_tmp_buffer + (adapter->dmaq1.buffer_size - adapter->dmaq1.tail), adapter->dmaq1.buffer, (188 - (adapter->dmaq1.buffer_size - adapter->dmaq1.tail))); + memcpy(gb_tmp_buffer, adapter->dmaq1.buffer + adapter->dmaq1.tail, + adapter->dmaq1.buffer_size - adapter->dmaq1.tail); + memcpy(gb_tmp_buffer + (adapter->dmaq1.buffer_size - adapter->dmaq1.tail), adapter->dmaq1.buffer, + (188 - (adapter->dmaq1.buffer_size - adapter->dmaq1.tail))); pb_dma_buf_cur_pos = gb_tmp_buffer; } if (adapter->capturing != 0) { - dvb_dmx_swfilter_packets(dvbdmx, pb_dma_buf_cur_pos, - dw_default_packet_size / 188); + dvb_dmx_swfilter_packets(dvbdmx, pb_dma_buf_cur_pos, dw_default_packet_size / 188); } n_num_bytes_parsed = n_num_bytes_parsed + dw_default_packet_size; @@ -1742,17 +1659,17 @@ static irqreturn_t isr(int irq, void *dev_id, struct pt_regs *regs) spin_lock_irq(&tmp->lock); - if (0 == ((value = read_reg_dw(tmp, 0x20C)) & 0x0F)) { + if (0 == ((value = read_reg_dw(tmp, 0x20c)) & 0x0f)) { spin_unlock_irq(&tmp->lock); return IRQ_NONE; } - + while (value != 0) { if ((value & 0x03) != 0) interrupt_service_dma1(tmp); - if ((value & 0x0C) != 0) + if ((value & 0x0c) != 0) interrupt_service_dma2(tmp); - value = read_reg_dw(tmp, 0x20C) & 0x0F; + value = read_reg_dw(tmp, 0x20c) & 0x0f; } spin_unlock_irq(&tmp->lock); @@ -1902,17 +1819,56 @@ static int claim_adapter(struct adapter *adapter) static int sll_reset_flexcop(struct adapter *adapter) { write_reg_dw(adapter, 0x208, 0); - write_reg_dw(adapter, 0x210, 0xB2FF); + write_reg_dw(adapter, 0x210, 0xb2ff); return 0; } */ -static int driver_initialize(struct pci_dev * pdev) +static void decide_how_many_hw_filters(struct adapter *adapter) +{ + int hw_filters; + int mod_option_hw_filters; + + // FlexCop IIb & III have 6+32 hw filters + // FlexCop II has 6 hw filters, every other should have at least 6 + switch (adapter->b2c2_revision) { + case 0x82: /* II */ + hw_filters = 6; + break; + case 0xc3: /* IIB */ + hw_filters = 6 + 32; + break; + case 0xc0: /* III */ + hw_filters = 6 + 32; + break; + default: + hw_filters = 6; + break; + } + printk("%s: the chip has %i hardware filters", __FILE__, hw_filters); + + mod_option_hw_filters = 0; + if (enable_hw_filters >= 1) + mod_option_hw_filters += 6; + if (enable_hw_filters >= 2) + mod_option_hw_filters += 32; + + if (mod_option_hw_filters >= hw_filters) { + adapter->useable_hw_filters = hw_filters; + } else { + adapter->useable_hw_filters = mod_option_hw_filters; + printk(", but only %d will be used because of module option", mod_option_hw_filters); + } + printk("\n"); + dprintk("%s: useable_hardware_filters set to %i\n", __FILE__, adapter->useable_hw_filters); +} + +static int driver_initialize(struct pci_dev *pdev) { struct adapter *adapter; u32 tmp; - + if (!(adapter = kmalloc(sizeof(struct adapter), GFP_KERNEL))) { dprintk("%s: out of memory!\n", __FUNCTION__); @@ -1921,7 +1877,7 @@ static int driver_initialize(struct pci_dev * pdev) memset(adapter, 0, sizeof(struct adapter)); - pci_set_drvdata(pdev,adapter); + pci_set_drvdata(pdev, adapter); adapter->pdev = pdev; adapter->irq = pdev->irq; @@ -1944,11 +1900,9 @@ static int driver_initialize(struct pci_dev * pdev) read_reg_dw(adapter, 0x208); write_reg_dw(adapter, 0x208, 0); - write_reg_dw(adapter, 0x210, 0xB2FF); + write_reg_dw(adapter, 0x210, 0xb2ff); write_reg_dw(adapter, 0x208, 0x40); - init_pids(adapter); - init_dma_queue(adapter); if ((adapter->dma_status & 0x30000000) == 0) { @@ -1959,26 +1913,30 @@ static int driver_initialize(struct pci_dev * pdev) adapter->b2c2_revision = (read_reg_dw(adapter, 0x204) >> 0x18); - switch(adapter->b2c2_revision) { - case 0x82: - printk("%s: FlexCopII(rev.130) chip found\n", __FILE__); - break; - case 0xC3: - printk("%s: FlexCopIIB(rev.195) chip found\n", __FILE__); - break; - case 0xC0: - printk("%s: FlexCopIII(rev.192) chip found\n", __FILE__); - break; - default: - printk("%s: The revision of the FlexCop chip on your card is %d\n", __FILE__, adapter->b2c2_revision); - printk("%s: This driver works only with FlexCopII(rev.130), FlexCopIIB(rev.195) and FlexCopIII(rev. 192).\n", __FILE__); - free_adapter_object(adapter); - pci_set_drvdata(pdev, NULL); - release_region(pci_resource_start(pdev,1), pci_resource_len(pdev,1)); - release_mem_region(pci_resource_start(pdev,0), pci_resource_len(pdev,0)); - return -ENODEV; + switch (adapter->b2c2_revision) { + case 0x82: + printk("%s: FlexCopII(rev.130) chip found\n", __FILE__); + break; + case 0xc3: + printk("%s: FlexCopIIB(rev.195) chip found\n", __FILE__); + break; + case 0xc0: + printk("%s: FlexCopIII(rev.192) chip found\n", __FILE__); + break; + default: + printk("%s: The revision of the FlexCop chip on your card is %d\n", __FILE__, adapter->b2c2_revision); + printk("%s: This driver works only with FlexCopII(rev.130), FlexCopIIB(rev.195) and FlexCopIII(rev.192).\n", __FILE__); + free_adapter_object(adapter); + pci_set_drvdata(pdev, NULL); + release_region(pci_resource_start(pdev, 1), pci_resource_len(pdev, 1)); + release_mem_region(pci_resource_start(pdev, 0), pci_resource_len(pdev, 0)); + return -ENODEV; } + decide_how_many_hw_filters(adapter); + + init_pids(adapter); + tmp = read_reg_dw(adapter, 0x204); write_reg_dw(adapter, 0x204, 0); @@ -2007,7 +1965,9 @@ static int driver_initialize(struct pci_dev * pdev) dma_enable_disable_irq(adapter, 1, 0, 0); if (eeprom_get_mac_addr(adapter, 0, adapter->mac_addr) != 0) { - printk("%s MAC address = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x \n", __FUNCTION__, adapter->mac_addr[0], adapter->mac_addr[1], adapter->mac_addr[2], adapter->mac_addr[3], adapter->mac_addr[4], adapter->mac_addr[5], adapter->mac_addr[6], adapter->mac_addr[7] + printk("%s MAC address = %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x \n", __FUNCTION__, adapter->mac_addr[0], + adapter->mac_addr[1], adapter->mac_addr[2], adapter->mac_addr[3], adapter->mac_addr[4], adapter->mac_addr[5], + adapter->mac_addr[6], adapter->mac_addr[7] ); ca_set_mac_dst_addr_filter(adapter, adapter->mac_addr); @@ -2065,7 +2025,7 @@ static int dvb_stop_feed(struct dvb_demux_feed *dvbdmxfeed) /* lnb control */ static void set_tuner_tone(struct adapter *adapter, u8 tone) { - u16 wz_half_period_for_45_mhz[] = { 0x01FF, 0x0154, 0x00FF, 0x00CC }; + u16 wz_half_period_for_45_mhz[] = { 0x01ff, 0x0154, 0x00ff, 0x00cc }; u16 ax; dprintk("%s: %u\n", __FUNCTION__, tone); @@ -2089,11 +2049,11 @@ static void set_tuner_tone(struct adapter *adapter, u8 tone) } if (ax != 0) { - write_reg_dw(adapter, 0x200, ((ax << 0x0F) + (ax & 0x7FFF)) | 0x40000000); + write_reg_dw(adapter, 0x200, ((ax << 0x0f) + (ax & 0x7fff)) | 0x40000000); } else { - write_reg_dw(adapter, 0x200, 0x40FF8000); + write_reg_dw(adapter, 0x200, 0x40ff8000); } } @@ -2123,7 +2083,7 @@ static void set_tuner_polarity(struct adapter *adapter, u8 polarity) write_reg_dw(adapter, 0x204, var); } -static void diseqc_send_bit (struct adapter *adapter, int data) +static void diseqc_send_bit(struct adapter *adapter, int data) { set_tuner_tone(adapter, 1); udelay(data ? 500 : 1000); @@ -2132,12 +2092,12 @@ static void diseqc_send_bit (struct adapter *adapter, int data) } -static void diseqc_send_byte (struct adapter *adapter, int data) +static void diseqc_send_byte(struct adapter *adapter, int data) { - int i, par=1, d; + int i, par = 1, d; - for (i=7; i>=0; i--) { - d = (data>>i)&1; + for (i = 7; i >= 0; i--) { + d = (data >> i) & 1; par ^= d; diseqc_send_bit(adapter, d); } @@ -2146,19 +2106,19 @@ static void diseqc_send_byte (struct adapter *adapter, int data) } -static int send_diseqc_msg (struct adapter *adapter, int len, u8 *msg, unsigned long burst) +static int send_diseqc_msg(struct adapter *adapter, int len, u8 *msg, unsigned long burst) { int i; set_tuner_tone(adapter, 0); mdelay(16); - for (i=0; i<len; i++) + for (i = 0; i < len; i++) diseqc_send_byte(adapter, msg[i]); mdelay(16); - if (burst!=-1) { + if (burst != -1) { if (burst) diseqc_send_byte(adapter, 0xff); else { @@ -2173,39 +2133,39 @@ static int send_diseqc_msg (struct adapter *adapter, int len, u8 *msg, unsigned } -int soft_diseqc (struct adapter *adapter, unsigned int cmd, void *arg) +int soft_diseqc(struct adapter *adapter, unsigned int cmd, void *arg) { switch (cmd) { - case FE_SET_TONE: - switch ((fe_sec_tone_mode_t) arg) { - case SEC_TONE_ON: - set_tuner_tone(adapter, 1); - break; - case SEC_TONE_OFF: - set_tuner_tone(adapter, 0); - break; - default: - return -EINVAL; - }; - break; - - case FE_DISEQC_SEND_MASTER_CMD: - { - struct dvb_diseqc_master_cmd *cmd = arg; - - send_diseqc_msg (adapter, cmd->msg_len, cmd->msg, 0); - break; + case FE_SET_TONE: + switch ((fe_sec_tone_mode_t) arg) { + case SEC_TONE_ON: + set_tuner_tone(adapter, 1); + break; + case SEC_TONE_OFF: + set_tuner_tone(adapter, 0); + break; + default: + return -EINVAL; + }; + break; + + case FE_DISEQC_SEND_MASTER_CMD: + { + struct dvb_diseqc_master_cmd *cmd = arg; + + send_diseqc_msg(adapter, cmd->msg_len, cmd->msg, 0); + break; } - case FE_DISEQC_SEND_BURST: - send_diseqc_msg (adapter, 0, NULL, (unsigned long)arg); - break; + case FE_DISEQC_SEND_BURST: + send_diseqc_msg(adapter, 0, NULL, (unsigned long) arg); + break; - default: - return -EOPNOTSUPP; + default: + return -EOPNOTSUPP; }; - return 0; + return 0; } static int flexcop_diseqc_ioctl(struct dvb_frontend *fe, unsigned int cmd, void *arg) @@ -2213,61 +2173,60 @@ static int flexcop_diseqc_ioctl(struct dvb_frontend *fe, unsigned int cmd, void struct adapter *adapter = fe->before_after_data; struct dvb_frontend_info info; - + fe->ioctl(fe, FE_GET_INFO, &info); - + // we must use different DiSEqC hw - - if ( strcmp(info.name, "Zarlink MT312") == 0){ + + if (strcmp(info.name, "Zarlink MT312") == 0) { //VP310 using mt312 driver for tuning only: diseqc not wired //use FCII instead - if (!soft_diseqc(adapter,cmd,arg)) + if (!soft_diseqc(adapter, cmd, arg)) return 0; } - + switch (cmd) { - case FE_SLEEP: - { + case FE_SLEEP: + { dprintk("%s: FE_SLEEP\n", __FUNCTION__); set_tuner_polarity(adapter, 0); // return -EOPNOTSUPP, to make DVB core also send "FE_SLEEP" command to frontend. return -EOPNOTSUPP; - } + } - case FE_SET_VOLTAGE: - { + case FE_SET_VOLTAGE: + { dprintk("%s: FE_SET_VOLTAGE\n", __FUNCTION__); - switch ((fe_sec_voltage_t) arg) - { - case SEC_VOLTAGE_13: + switch ((fe_sec_voltage_t) arg) { + case SEC_VOLTAGE_13: - dprintk("%s: SEC_VOLTAGE_13, %x\n", __FUNCTION__, SEC_VOLTAGE_13); + dprintk("%s: SEC_VOLTAGE_13, %x\n", __FUNCTION__, SEC_VOLTAGE_13); - set_tuner_polarity(adapter, 1); + set_tuner_polarity(adapter, 1); - return 0; + return 0; - case SEC_VOLTAGE_18: + case SEC_VOLTAGE_18: - dprintk("%s: SEC_VOLTAGE_18, %x\n", __FUNCTION__, SEC_VOLTAGE_18); + dprintk("%s: SEC_VOLTAGE_18, %x\n", __FUNCTION__, SEC_VOLTAGE_18); - set_tuner_polarity(adapter, 2); + set_tuner_polarity(adapter, 2); - return 0; + return 0; - default: + default: - return -EINVAL; + return -EINVAL; }; - } + } - default: - - return -EOPNOTSUPP; + default: + + return -EOPNOTSUPP; }; @@ -2308,7 +2267,7 @@ static int skystar2_probe(struct pci_dev *pdev, const struct pci_device_id *ent) if (!adapter->i2c_bus) return -ENOMEM; - + dvb_add_frontend_ioctls(adapter->dvb_adapter, flexcop_diseqc_ioctl, NULL, adapter); dvbdemux = &adapter->demux; @@ -2383,9 +2342,9 @@ static void skystar2_remove(struct pci_dev *pdev) } static struct pci_device_id skystar2_pci_tbl[] = { - { 0x000013D0, 0x00002103, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000 }, - { 0x000013D0, 0x00002200, 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000, 0x00000000 }, //FCIII - { 0, }, + {0x000013d0, 0x00002103, 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x00000000}, + {0x000013d0, 0x00002200, 0xffffffff, 0xffffffff, 0x00000000, 0x00000000, 0x00000000}, //FCIII + {0,}, }; static struct pci_driver skystar2_pci_driver = { @@ -2408,10 +2367,10 @@ static void skystar2_cleanup(void) module_init(skystar2_init); module_exit(skystar2_cleanup); -MODULE_PARM(debug,"i"); +MODULE_PARM(debug, "i"); MODULE_PARM_DESC(debug, "enable verbose debug messages: supported values: 1 and 2"); -MODULE_PARM(enable_hw_filters,"i"); -MODULE_PARM_DESC(enable_hw_filters, "enable hardware filters, if disabled the whole ts is passed through"); +MODULE_PARM(enable_hw_filters, "i"); +MODULE_PARM_DESC(enable_hw_filters, "enable hardware filters: supported values: 0 (none), 1, 2"); MODULE_DESCRIPTION("Technisat SkyStar2 DVB PCI Driver"); MODULE_LICENSE("GPL"); |