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

📄 bcm43xx_phy.c

📁 无线网卡驱动,有很好的参考价值,在linux_2.6.21下可以直接使用,如果在其他平台,可以参考移植
💻 C
📖 第 1 页 / 共 5 页
字号:
	if (radio->revision == 8)		bcm43xx_phy_write(bcm, 0x0805, 0x3230);	bcm43xx_phy_init_pctl(bcm);	if (bcm->chip_id == 0x4306 && bcm->chip_package == 2) {		bcm43xx_phy_write(bcm, 0x0429,				  bcm43xx_phy_read(bcm, 0x0429) & 0xBFFF);		bcm43xx_phy_write(bcm, 0x04C3,				  bcm43xx_phy_read(bcm, 0x04C3) & 0x7FFF);	}}static u16 bcm43xx_phy_lo_b_r15_loop(struct bcm43xx_private *bcm){	int i;	u16 ret = 0;	unsigned long flags;	local_irq_save(flags);	for (i = 0; i < 10; i++){		bcm43xx_phy_write(bcm, 0x0015, 0xAFA0);		udelay(1);		bcm43xx_phy_write(bcm, 0x0015, 0xEFA0);		udelay(10);		bcm43xx_phy_write(bcm, 0x0015, 0xFFA0);		udelay(40);		ret += bcm43xx_phy_read(bcm, 0x002C);	}	local_irq_restore(flags);	bcm43xx_voluntary_preempt();	return ret;}void bcm43xx_phy_lo_b_measure(struct bcm43xx_private *bcm){	struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);	struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);	u16 regstack[12] = { 0 };	u16 mls;	u16 fval;	int i, j;	regstack[0] = bcm43xx_phy_read(bcm, 0x0015);	regstack[1] = bcm43xx_radio_read16(bcm, 0x0052) & 0xFFF0;	if (radio->version == 0x2053) {		regstack[2] = bcm43xx_phy_read(bcm, 0x000A);		regstack[3] = bcm43xx_phy_read(bcm, 0x002A);		regstack[4] = bcm43xx_phy_read(bcm, 0x0035);		regstack[5] = bcm43xx_phy_read(bcm, 0x0003);		regstack[6] = bcm43xx_phy_read(bcm, 0x0001);		regstack[7] = bcm43xx_phy_read(bcm, 0x0030);		regstack[8] = bcm43xx_radio_read16(bcm, 0x0043);		regstack[9] = bcm43xx_radio_read16(bcm, 0x007A);		regstack[10] = bcm43xx_read16(bcm, 0x03EC);		regstack[11] = bcm43xx_radio_read16(bcm, 0x0052) & 0x00F0;		bcm43xx_phy_write(bcm, 0x0030, 0x00FF);		bcm43xx_write16(bcm, 0x03EC, 0x3F3F);		bcm43xx_phy_write(bcm, 0x0035, regstack[4] & 0xFF7F);		bcm43xx_radio_write16(bcm, 0x007A, regstack[9] & 0xFFF0);	}	bcm43xx_phy_write(bcm, 0x0015, 0xB000);	bcm43xx_phy_write(bcm, 0x002B, 0x0004);	if (radio->version == 0x2053) {		bcm43xx_phy_write(bcm, 0x002B, 0x0203);		bcm43xx_phy_write(bcm, 0x002A, 0x08A3);	}	phy->minlowsig[0] = 0xFFFF;	for (i = 0; i < 4; i++) {		bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | i);		bcm43xx_phy_lo_b_r15_loop(bcm);	}	for (i = 0; i < 10; i++) {		bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | i);		mls = bcm43xx_phy_lo_b_r15_loop(bcm) / 10;		if (mls < phy->minlowsig[0]) {			phy->minlowsig[0] = mls;			phy->minlowsigpos[0] = i;		}	}	bcm43xx_radio_write16(bcm, 0x0052, regstack[1] | phy->minlowsigpos[0]);	phy->minlowsig[1] = 0xFFFF;	for (i = -4; i < 5; i += 2) {		for (j = -4; j < 5; j += 2) {			if (j < 0)				fval = (0x0100 * i) + j + 0x0100;			else				fval = (0x0100 * i) + j;			bcm43xx_phy_write(bcm, 0x002F, fval);			mls = bcm43xx_phy_lo_b_r15_loop(bcm) / 10;			if (mls < phy->minlowsig[1]) {				phy->minlowsig[1] = mls;				phy->minlowsigpos[1] = fval;			}		}	}	phy->minlowsigpos[1] += 0x0101;	bcm43xx_phy_write(bcm, 0x002F, phy->minlowsigpos[1]);	if (radio->version == 0x2053) {		bcm43xx_phy_write(bcm, 0x000A, regstack[2]);		bcm43xx_phy_write(bcm, 0x002A, regstack[3]);		bcm43xx_phy_write(bcm, 0x0035, regstack[4]);		bcm43xx_phy_write(bcm, 0x0003, regstack[5]);		bcm43xx_phy_write(bcm, 0x0001, regstack[6]);		bcm43xx_phy_write(bcm, 0x0030, regstack[7]);		bcm43xx_radio_write16(bcm, 0x0043, regstack[8]);		bcm43xx_radio_write16(bcm, 0x007A, regstack[9]);		bcm43xx_radio_write16(bcm, 0x0052,		                      (bcm43xx_radio_read16(bcm, 0x0052) & 0x000F)				      | regstack[11]);		bcm43xx_write16(bcm, 0x03EC, regstack[10]);	}	bcm43xx_phy_write(bcm, 0x0015, regstack[0]);}static inlineu16 bcm43xx_phy_lo_g_deviation_subval(struct bcm43xx_private *bcm, u16 control){	struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);	u16 ret;	unsigned long flags;	local_irq_save(flags);	if (phy->connected) {		bcm43xx_phy_write(bcm, 0x15, 0xE300);		control <<= 8;		bcm43xx_phy_write(bcm, 0x0812, control | 0x00B0);		udelay(5);		bcm43xx_phy_write(bcm, 0x0812, control | 0x00B2);		udelay(2);		bcm43xx_phy_write(bcm, 0x0812, control | 0x00B3);		udelay(4);		bcm43xx_phy_write(bcm, 0x0015, 0xF300);		udelay(8);	} else {		bcm43xx_phy_write(bcm, 0x0015, control | 0xEFA0);		udelay(2);		bcm43xx_phy_write(bcm, 0x0015, control | 0xEFE0);		udelay(4);		bcm43xx_phy_write(bcm, 0x0015, control | 0xFFE0);		udelay(8);	}	ret = bcm43xx_phy_read(bcm, 0x002D);	local_irq_restore(flags);	bcm43xx_voluntary_preempt();	return ret;}static u32 bcm43xx_phy_lo_g_singledeviation(struct bcm43xx_private *bcm, u16 control){	int i;	u32 ret = 0;	for (i = 0; i < 8; i++)		ret += bcm43xx_phy_lo_g_deviation_subval(bcm, control);	return ret;}/* Write the LocalOscillator CONTROL */static inlinevoid bcm43xx_lo_write(struct bcm43xx_private *bcm,		      struct bcm43xx_lopair *pair){	u16 value;	value = (u8)(pair->low);	value |= ((u8)(pair->high)) << 8;#ifdef CONFIG_BCM43XX_DEBUG	/* Sanity check. */	if (pair->low < -8 || pair->low > 8 ||	    pair->high < -8 || pair->high > 8) {		printk(KERN_WARNING PFX		       "WARNING: Writing invalid LOpair "		       "(low: %d, high: %d, index: %lu)\n",		       pair->low, pair->high,		       (unsigned long)(pair - bcm43xx_current_phy(bcm)->_lo_pairs));		dump_stack();	}#endif	bcm43xx_phy_write(bcm, BCM43xx_PHY_G_LO_CONTROL, value);}static inlinestruct bcm43xx_lopair * bcm43xx_find_lopair(struct bcm43xx_private *bcm,					    u16 baseband_attenuation,					    u16 radio_attenuation,					    u16 tx){	static const u8 dict[10] = { 11, 10, 11, 12, 13, 12, 13, 12, 13, 12 };	struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);	if (baseband_attenuation > 6)		baseband_attenuation = 6;	assert(radio_attenuation < 10);	if (tx == 3) {		return bcm43xx_get_lopair(phy,					  radio_attenuation,					  baseband_attenuation);	}	return bcm43xx_get_lopair(phy, dict[radio_attenuation], baseband_attenuation);}static inlinestruct bcm43xx_lopair * bcm43xx_current_lopair(struct bcm43xx_private *bcm){	struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);	return bcm43xx_find_lopair(bcm,				   radio->baseband_atten,				   radio->radio_atten,				   radio->txctl1);}/* Adjust B/G LO */void bcm43xx_phy_lo_adjust(struct bcm43xx_private *bcm, int fixed){	struct bcm43xx_lopair *pair;	if (fixed) {		/* Use fixed values. Only for initialization. */		pair = bcm43xx_find_lopair(bcm, 2, 3, 0);	} else		pair = bcm43xx_current_lopair(bcm);	bcm43xx_lo_write(bcm, pair);}static void bcm43xx_phy_lo_g_measure_txctl2(struct bcm43xx_private *bcm){	struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);	u16 txctl2 = 0, i;	u32 smallest, tmp;	bcm43xx_radio_write16(bcm, 0x0052, 0x0000);	udelay(10);	smallest = bcm43xx_phy_lo_g_singledeviation(bcm, 0);	for (i = 0; i < 16; i++) {		bcm43xx_radio_write16(bcm, 0x0052, i);		udelay(10);		tmp = bcm43xx_phy_lo_g_singledeviation(bcm, 0);		if (tmp < smallest) {			smallest = tmp;			txctl2 = i;		}	}	radio->txctl2 = txctl2;}staticvoid bcm43xx_phy_lo_g_state(struct bcm43xx_private *bcm,			    const struct bcm43xx_lopair *in_pair,			    struct bcm43xx_lopair *out_pair,			    u16 r27){	static const struct bcm43xx_lopair transitions[8] = {		{ .high =  1,  .low =  1, },		{ .high =  1,  .low =  0, },		{ .high =  1,  .low = -1, },		{ .high =  0,  .low = -1, },		{ .high = -1,  .low = -1, },		{ .high = -1,  .low =  0, },		{ .high = -1,  .low =  1, },		{ .high =  0,  .low =  1, },	};	struct bcm43xx_lopair lowest_transition = {		.high = in_pair->high,		.low = in_pair->low,	};	struct bcm43xx_lopair tmp_pair;	struct bcm43xx_lopair transition;	int i = 12;	int state = 0;	int found_lower;	int j, begin, end;	u32 lowest_deviation;	u32 tmp;	/* Note that in_pair and out_pair can point to the same pair. Be careful. */	bcm43xx_lo_write(bcm, &lowest_transition);	lowest_deviation = bcm43xx_phy_lo_g_singledeviation(bcm, r27);	do {		found_lower = 0;		assert(state >= 0 && state <= 8);		if (state == 0) {			begin = 1;			end = 8;		} else if (state % 2 == 0) {			begin = state - 1;			end = state + 1;		} else {			begin = state - 2;			end = state + 2;		}		if (begin < 1)			begin += 8;		if (end > 8)			end -= 8;		j = begin;		tmp_pair.high = lowest_transition.high;		tmp_pair.low = lowest_transition.low;		while (1) {			assert(j >= 1 && j <= 8);			transition.high = tmp_pair.high + transitions[j - 1].high;			transition.low = tmp_pair.low + transitions[j - 1].low;			if ((abs(transition.low) < 9) && (abs(transition.high) < 9)) {				bcm43xx_lo_write(bcm, &transition);				tmp = bcm43xx_phy_lo_g_singledeviation(bcm, r27);				if (tmp < lowest_deviation) {					lowest_deviation = tmp;					state = j;					found_lower = 1;					lowest_transition.high = transition.high;					lowest_transition.low = transition.low;				}			}			if (j == end)				break;			if (j == 8)				j = 1;			else				j++;		}	} while (i-- && found_lower);	out_pair->high = lowest_transition.high;	out_pair->low = lowest_transition.low;}/* Set the baseband attenuation value on chip. */void bcm43xx_phy_set_baseband_attenuation(struct bcm43xx_private *bcm,					  u16 baseband_attenuation){	struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);	u16 value;	if (phy->analog == 0) {		value = (bcm43xx_read16(bcm, 0x03E6) & 0xFFF0);		value |= (baseband_attenuation & 0x000F);		bcm43xx_write16(bcm, 0x03E6, value);		return;	}	if (phy->analog > 1) {		value = bcm43xx_phy_read(bcm, 0x0060) & ~0x003C;		value |= (baseband_attenuation << 2) & 0x003C;	} else {		value = bcm43xx_phy_read(bcm, 0x0060) & ~0x0078;		value |= (baseband_attenuation << 3) & 0x0078;	}	bcm43xx_phy_write(bcm, 0x0060, value);}/* http://bcm-specs.sipsolutions.net/LocalOscillator/Measure */void bcm43xx_phy_lo_g_measure(struct bcm43xx_private *bcm){	static const u8 pairorder[10] = { 3, 1, 5, 7, 9, 2, 0, 4, 6, 8 };	const int is_initializing = (bcm43xx_status(bcm) == BCM43xx_STAT_INITIALIZING);	struct bcm43xx_phyinfo *phy = bcm43xx_current_phy(bcm);	struct bcm43xx_radioinfo *radio = bcm43xx_current_radio(bcm);	u16 h, i, oldi = 0, j;	struct bcm43xx_lopair control;	struct bcm43xx_lopair *tmp_control;	u16 tmp;	u16 regstack[16] = { 0 };	u8 oldchannel;	//XXX: What are these?	u8 r27 = 0, r31;	oldchannel = radio->channel;	/* Setup */	if (phy->connected) {		regstack[0] = bcm43xx_phy_read(bcm, BCM43xx_PHY_G_CRS);		regstack[1] = bcm43xx_phy_read(bcm, 0x0802);		bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0] & 0x7FFF);		bcm43xx_phy_write(bcm, 0x0802, regstack[1] & 0xFFFC);	}	regstack[3] = bcm43xx_read16(bcm, 0x03E2);	bcm43xx_write16(bcm, 0x03E2, regstack[3] | 0x8000);	regstack[4] = bcm43xx_read16(bcm, BCM43xx_MMIO_CHANNEL_EXT);	regstack[5] = bcm43xx_phy_read(bcm, 0x15);	regstack[6] = bcm43xx_phy_read(bcm, 0x2A);	regstack[7] = bcm43xx_phy_read(bcm, 0x35);	regstack[8] = bcm43xx_phy_read(bcm, 0x60);	regstack[9] = bcm43xx_radio_read16(bcm, 0x43);	regstack[10] = bcm43xx_radio_read16(bcm, 0x7A);	regstack[11] = bcm43xx_radio_read16(bcm, 0x52);	if (phy->connected) {		regstack[12] = bcm43xx_phy_read(bcm, 0x0811);		regstack[13] = bcm43xx_phy_read(bcm, 0x0812);		regstack[14] = bcm43xx_phy_read(bcm, 0x0814);		regstack[15] = bcm43xx_phy_read(bcm, 0x0815);	}	bcm43xx_radio_selectchannel(bcm, 6, 0);	if (phy->connected) {		bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0] & 0x7FFF);		bcm43xx_phy_write(bcm, 0x0802, regstack[1] & 0xFFFC);		bcm43xx_dummy_transmission(bcm);	}	bcm43xx_radio_write16(bcm, 0x0043, 0x0006);	bcm43xx_phy_set_baseband_attenuation(bcm, 2);	bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, 0x0000);	bcm43xx_phy_write(bcm, 0x002E, 0x007F);	bcm43xx_phy_write(bcm, 0x080F, 0x0078);	bcm43xx_phy_write(bcm, 0x0035, regstack[7] & ~(1 << 7));

⌨️ 快捷键说明

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