⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 skystar2.c

📁 linux环境下的dvb驱动程序
💻 C
📖 第 1 页 / 共 4 页
字号:
	u32 tmp;	tmp = read_reg_dw(adapter, 0x71c);	write_reg_dw(adapter, 0x71c, 1);	if (read_reg_dw(adapter, 0x71c) != 0) {		write_reg_dw(adapter, 0x71c, tmp);		adapter->dw_sram_type = tmp & 0x30000;		ddprintk("%s: dw_sram_type = %x\n", __FUNCTION__, adapter->dw_sram_type);	} else {		adapter->dw_sram_type = 0x10000;		ddprintk("%s: dw_sram_type = %x\n", __FUNCTION__, adapter->dw_sram_type);	}	/* return value is never used? *//*	return adapter->dw_sram_type; */}static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr){	u8 tmp1, tmp2;	dprintk("%s: mask = %x, addr = %x\n", __FUNCTION__, mask, addr);	sram_set_size(adapter, mask);	sram_init(adapter);	tmp2 = 0xa5;	tmp1 = 0x4f;	sram_write(adapter, addr, &tmp2, 1);	sram_write(adapter, addr + 4, &tmp1, 1);	tmp2 = 0;	mdelay(20);	sram_read(adapter, addr, &tmp2, 1);	sram_read(adapter, addr, &tmp2, 1);	dprintk("%s: wrote 0xa5, read 0x%2x\n", __FUNCTION__, tmp2);	if (tmp2 != 0xa5)		return 0;	tmp2 = 0x5a;	tmp1 = 0xf4;	sram_write(adapter, addr, &tmp2, 1);	sram_write(adapter, addr + 4, &tmp1, 1);	tmp2 = 0;	mdelay(20);	sram_read(adapter, addr, &tmp2, 1);	sram_read(adapter, addr, &tmp2, 1);	dprintk("%s: wrote 0x5a, read 0x%2x\n", __FUNCTION__, tmp2);	if (tmp2 != 0x5a)		return 0;	return 1;}static u32 sram_length(struct adapter *adapter){	if (adapter->dw_sram_type == 0x10000)		return 32768;	//  32K	if (adapter->dw_sram_type == 0x00000)		return 65536;	//  64K	if (adapter->dw_sram_type == 0x20000)		return 131072;	// 128K	return 32768;		// 32K}/* FlexcopII can work with 32K, 64K or 128K of external SRAM memory.    - for 128K there are 4x32K chips at bank 0,1,2,3.    - for  64K there are 2x32K chips at bank 1,2.    - for  32K there is one 32K chip at bank 0.   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*/static int sram_detect_for_flex2(struct adapter *adapter){	u32 tmp, tmp2, tmp3;	dprintk("%s:\n", __FUNCTION__);	tmp = read_reg_dw(adapter, 0x208);	write_reg_dw(adapter, 0x208, 0);	tmp2 = read_reg_dw(adapter, 0x71c);	dprintk("%s: tmp2 = %x\n", __FUNCTION__, tmp2);	write_reg_dw(adapter, 0x71c, 1);	tmp3 = read_reg_dw(adapter, 0x71c);	dprintk("%s: tmp3 = %x\n", __FUNCTION__, tmp3);	write_reg_dw(adapter, 0x71c, tmp2);	// check for internal SRAM ???	tmp3--;	if (tmp3 != 0) {		sram_set_size(adapter, 0x10000);		sram_init(adapter);		write_reg_dw(adapter, 0x208, tmp);		dprintk("%s: sram size = 32K\n", __FUNCTION__);		return 32;	}	if (sram_test_location(adapter, 0x20000, 0x18000) != 0) {		sram_set_size(adapter, 0x20000);		sram_init(adapter);		write_reg_dw(adapter, 0x208, tmp);		dprintk("%s: sram size = 128K\n", __FUNCTION__);		return 128;	}	if (sram_test_location(adapter, 0x00000, 0x10000) != 0) {		sram_set_size(adapter, 0x00000);		sram_init(adapter);		write_reg_dw(adapter, 0x208, tmp);		dprintk("%s: sram size = 64K\n", __FUNCTION__);		return 64;	}	if (sram_test_location(adapter, 0x10000, 0x00000) != 0) {		sram_set_size(adapter, 0x10000);		sram_init(adapter);		write_reg_dw(adapter, 0x208, tmp);		dprintk("%s: sram size = 32K\n", __FUNCTION__);		return 32;	}	sram_set_size(adapter, 0x10000);	sram_init(adapter);	write_reg_dw(adapter, 0x208, tmp);	dprintk("%s: SRAM detection failed. Set to 32K \n", __FUNCTION__);	return 0;}static void sll_detect_sram_size(struct adapter *adapter){	sram_detect_for_flex2(adapter);}/*EEPROM (Skystar2 has one "24LC08B" chip on board) *//*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){	return flex_i2c_read(adapter, 0x20000000, 0x50, addr, buf, len);}u8 calc_lrc(u8 *buf, int len){	int i;	u8 sum;	sum = 0;	for (i = 0; i < len; i++)		sum = sum ^ buf[i];	return sum;}static int eeprom_lrc_read(struct adapter *adapter, u32 addr, u32 len, u8 *buf, int retries){	int i;	for (i = 0; i < retries; i++) {		if (eeprom_read(adapter, addr, buf, len) == len) {			if (calc_lrc(buf, len - 1) == buf[len - 1])				return 1;		}	}	return 0;}/*static int eeprom_lrc_write(struct adapter *adapter, u32 addr, u32 len, u8 *wbuf, u8 *rbuf, int retries){	int i;	for (i = 0; i < retries; i++) {		if (eeprom_write(adapter, addr, wbuf, len) == len) {			if (eeprom_lrc_read(adapter, addr, len, rbuf, retries) == 1)				return 1;		}	}	return 0;}*//* These functions could be used to unlock SkyStar2 cards. *//*static int eeprom_writeKey(struct adapter *adapter, u8 *key, u32 len){	u8 rbuf[20];	u8 wbuf[20];	if (len != 16)		return 0;	memcpy(wbuf, key, len);	wbuf[16] = 0;	wbuf[17] = 0;	wbuf[18] = 0;	wbuf[19] = calc_lrc(wbuf, 19);	return eeprom_lrc_write(adapter, 0x3e4, 20, wbuf, rbuf, 4);}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)		return 0;	memcpy(key, buf, len);	return 1;}*/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 (type != 0) {			mac[0] = tmp[0];			mac[1] = tmp[1];			mac[2] = tmp[2];			mac[3] = 0xfe;			mac[4] = 0xff;			mac[5] = tmp[3];			mac[6] = tmp[4];			mac[7] = tmp[5];		} else {			mac[0] = tmp[0];			mac[1] = tmp[1];			mac[2] = tmp[2];			mac[3] = tmp[3];			mac[4] = tmp[4];			mac[5] = tmp[5];		}		return 1;	} else {		if (type == 0) {			memset(mac, 0, 6);		} else {			memset(mac, 0, 8);		}		return 0;	}}/*static char eeprom_set_mac_addr(struct adapter *adapter, char type, u8 *mac){	u8 tmp[8];	if (type != 0) {		tmp[0] = mac[0];		tmp[1] = mac[1];		tmp[2] = mac[2];		tmp[3] = mac[5];		tmp[4] = mac[6];		tmp[5] = mac[7];	} else {		tmp[0] = mac[0];		tmp[1] = mac[1];		tmp[2] = mac[2];		tmp[3] = mac[3];		tmp[4] = mac[4];		tmp[5] = mac[5];	}	tmp[6] = 0;	tmp[7] = calc_lrc(tmp, 7);	if (eeprom_write(adapter, 0x3f8, tmp, 8) == 8)		return 1;	return 0;}*//* PID filter *//* every flexcop has 6 "lower" hw PID filters     *//* these are enabled by setting bits 0-5 of 0x208 *//* 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){	dprintk("%s: id=%d op=%d\n", __FUNCTION__, id, op);	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, 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);	}}/*static void filter_enable_null_filter(struct adapter *adapter, u32 op){	dprintk("%s: op=%x\n", __FUNCTION__, op);	write_reg_bitfield(adapter, 0x208, 0x00000040, op?0x00000040:0);}*/static void filter_enable_mask_filter(struct adapter *adapter, u32 op){	dprintk("%s: op=%x\n", __FUNCTION__, op);	write_reg_bitfield(adapter, 0x208, 0x00000080, op ? 0x00000080 : 0);}static void ctrl_enable_mac(struct adapter *adapter, u32 op){	write_reg_bitfield(adapter, 0x208, 0x00004000, op ? 0x00004000 : 0);}static int ca_set_mac_dst_addr_filter(struct adapter *adapter, u8 *mac){	u32 tmp1, tmp2;	tmp1 = (mac[3] << 0x18) | (mac[2] << 0x10) | (mac[1] << 0x08) | mac[0];	tmp2 = (mac[5] << 0x08) | mac[4];	write_reg_dw(adapter, 0x418, tmp1);	write_reg_dw(adapter, 0x41c, tmp2);	return 0;}/*static void set_ignore_mac_filter(struct adapter *adapter, u8 op){	if (op != 0) {		write_reg_bitfield(adapter, 0x208, 0x00004000, 0);		adapter->mac_filter = 1;	} else {		if (adapter->mac_filter != 0) {			adapter->mac_filter = 0;			write_reg_bitfield(adapter, 0x208, 0x00004000, 0x00004000);		}	}}*//*static void check_null_filter_enable(struct adapter *adapter){	filter_enable_null_filter(adapter, 1);	filter_enable_mask_filter(adapter, 1);}*/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);}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);}/*static int pid_get_group_pid(struct adapter *adapter){	return read_reg_dw(adapter, 0x30c) & 0x00001fff;}static int pid_get_group_mask(struct adapter *adapter){	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_stream2_pid(adapter, 0x1fff);	filter_enable_stream2_filter(adapter, 0);	pid_set_pcr_pid(adapter, 0x1fff);	filter_enable_pcr_filter(adapter, 0);	pid_set_pmt_pid(adapter, 0x1fff);	filter_enable_pmt_filter(adapter, 0);	pid_set_ecm_pid(adapter, 0x1fff);	filter_enable_ecm_filter(adapter, 0);	pid_set_emm_pid(adapter, 0x1fff);	filter_enable_emm_filter(adapter, 0);}*/static void init_pids(struct adapter *adapter){	int i;	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);}static void open_whole_bandwidth(struct adapter *adapter){	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__);	pid_set_group_pid(adapter, 0);	pid_set_group_mask(adapter, 0x1fe0);/*	filter_enable_mask_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;	/* we can't use a filter for 0x2000, so no search */	if (pid != 0x2000) {		/* 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;			}		}	}	/* 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, u16 pid){	int i;	dprintk("%s: pid=%d\n", __FUNCTION__, pid);	if (pid <= 0x1f)		return 1;	/* we can't use a filter for 0x2000, so no search */	if (pid != 0x2000) {		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;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -