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

📄 bcm43xx_phy.c

📁 博通的bcm43xx系列Minipci接口无线网卡驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
struct bcm43xx_lopair * bcm43xx_current_lopair(struct bcm43xx_private *bcm){	return bcm43xx_find_lopair(bcm,				   bcm->current_core->radio->txpower[0],				   bcm->current_core->radio->txpower[1],				   bcm->current_core->radio->txpower[2]);}/* 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 inlinevoid bcm43xx_phy_lo_g_measure_txctl2(struct bcm43xx_private *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;		}	}	bcm->current_core->radio->txpower[3] = 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){	u16 value;	if (bcm->current_core->phy->version == 0) {		value = (bcm43xx_read16(bcm, 0x03E6) & 0xFFF0);		value |= (baseband_attenuation & 0x000F);		bcm43xx_write16(bcm, 0x03E6, value);		return;	}	if (bcm->current_core->phy->version > 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_is_initializing(bcm);	struct bcm43xx_phyinfo *phy = bcm->current_core->phy;	struct bcm43xx_radioinfo *radio = bcm->current_core->radio;	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));	bcm43xx_radio_write16(bcm, 0x007A, regstack[10] & 0xFFF0);	bcm43xx_phy_write(bcm, 0x002B, 0x0203);	bcm43xx_phy_write(bcm, 0x002A, 0x08A3);	if (phy->connected) {		bcm43xx_phy_write(bcm, 0x0814, regstack[14] | 0x0003);		bcm43xx_phy_write(bcm, 0x0815, regstack[15] & 0xFFFC);		bcm43xx_phy_write(bcm, 0x0811, 0x01B3);		bcm43xx_phy_write(bcm, 0x0812, 0x00B2);	}	if (is_initializing)		bcm43xx_phy_lo_g_measure_txctl2(bcm);	bcm43xx_phy_write(bcm, 0x080F, 0x8078);	/* Measure */	control.low = 0;	control.high = 0;	for (h = 0; h < 10; h++) {		/* Loop over each possible RadioAttenuation (0-9) */		i = pairorder[h];		if (is_initializing) {			if (i == 3) {				control.low = 0;				control.high = 0;			} else if (((i % 2 == 1) && (oldi % 2 == 1)) ||				  ((i % 2 == 0) && (oldi % 2 == 0))) {				tmp_control = bcm43xx_get_lopair(phy, oldi, 0);				memcpy(&control, tmp_control, sizeof(control));			} else {				tmp_control = bcm43xx_get_lopair(phy, 3, 0);				memcpy(&control, tmp_control, sizeof(control));			}		}		/* Loop over each possible BasebandAttenuation/2 */		for (j = 0; j < 4; j++) {			if (is_initializing) {				tmp = i * 2 + j;				r27 = 0;				r31 = 0;				if (tmp > 14) {					r31 = 1;					if (tmp > 17)						r27 = 1;					if (tmp > 19)						r27 = 2;				}			} else {				tmp_control = bcm43xx_get_lopair(phy, i, j * 2);				if (!tmp_control->used)					continue;				memcpy(&control, tmp_control, sizeof(control));				r27 = 3;				r31 = 0;			}			bcm43xx_radio_write16(bcm, 0x43, i);			bcm43xx_radio_write16(bcm, 0x52,					      radio->txpower[3]);			udelay(10);			bcm43xx_phy_set_baseband_attenuation(bcm, j * 2);			tmp = (regstack[10] & 0xFFF0);			if (r31)				tmp |= 0x0008;			bcm43xx_radio_write16(bcm, 0x007A, tmp);			tmp_control = bcm43xx_get_lopair(phy, i, j * 2);			bcm43xx_phy_lo_g_state(bcm, &control, tmp_control, r27);		}		oldi = i;	}	/* Loop over each possible RadioAttenuation (10-13) */	for (i = 10; i < 14; i++) {		/* Loop over each possible BasebandAttenuation/2 */		for (j = 0; j < 4; j++) {			if (is_initializing) {				tmp_control = bcm43xx_get_lopair(phy, i - 9, j * 2);				memcpy(&control, tmp_control, sizeof(control));				tmp = (i - 9) * 2 + j - 5;//FIXME: This is wrong, as the following if statement can never trigger.				r27 = 0;				r31 = 0;				if (tmp > 14) {					r31 = 1;					if (tmp > 17)						r27 = 1;					if (tmp > 19)						r27 = 2;				}			} else {				tmp_control = bcm43xx_get_lopair(phy, i - 9, j * 2);				if (!tmp_control->used)					continue;				memcpy(&control, tmp_control, sizeof(control));				r27 = 3;				r31 = 0;			}			bcm43xx_radio_write16(bcm, 0x43, i - 9);			bcm43xx_radio_write16(bcm, 0x52,					      radio->txpower[3]					      | (3/*txctl1*/ << 4));//FIXME: shouldn't txctl1 be zero here and 3 in the loop above?			udelay(10);			bcm43xx_phy_set_baseband_attenuation(bcm, j * 2);			tmp = (regstack[10] & 0xFFF0);			if (r31)				tmp |= 0x0008;			bcm43xx_radio_write16(bcm, 0x7A, tmp);			tmp_control = bcm43xx_get_lopair(phy, i, j * 2);			bcm43xx_phy_lo_g_state(bcm, &control, tmp_control, r27);		}	}	/* Restoration */	if (phy->connected) {		bcm43xx_phy_write(bcm, 0x0015, 0xE300);		bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA0);		udelay(5);		bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA2);		udelay(2);		bcm43xx_phy_write(bcm, 0x0812, (r27 << 8) | 0xA3);	} else		bcm43xx_phy_write(bcm, 0x0015, r27 | 0xEFA0);	bcm43xx_phy_lo_adjust(bcm, is_initializing);	bcm43xx_phy_write(bcm, 0x002E, 0x807F);	if (phy->connected)		bcm43xx_phy_write(bcm, 0x002F, 0x0202);	else		bcm43xx_phy_write(bcm, 0x002F, 0x0101);	bcm43xx_write16(bcm, BCM43xx_MMIO_CHANNEL_EXT, regstack[4]);	bcm43xx_phy_write(bcm, 0x0015, regstack[5]);	bcm43xx_phy_write(bcm, 0x002A, regstack[6]);	bcm43xx_phy_write(bcm, 0x0035, regstack[7]);	bcm43xx_phy_write(bcm, 0x0060, regstack[8]);	bcm43xx_radio_write16(bcm, 0x0043, regstack[9]);	bcm43xx_radio_write16(bcm, 0x007A, regstack[10]);	regstack[11] &= 0x00F0;	regstack[11] |= (bcm43xx_radio_read16(bcm, 0x52) & 0x000F);	bcm43xx_radio_write16(bcm, 0x52, regstack[11]);	bcm43xx_write16(bcm, 0x03E2, regstack[3]);	if (phy->connected) {		bcm43xx_phy_write(bcm, 0x0811, regstack[12]);		bcm43xx_phy_write(bcm, 0x0812, regstack[13]);		bcm43xx_phy_write(bcm, 0x0814, regstack[14]);		bcm43xx_phy_write(bcm, 0x0815, regstack[15]);		bcm43xx_phy_write(bcm, BCM43xx_PHY_G_CRS, regstack[0]);		bcm43xx_phy_write(bcm, 0x0802, regstack[1]);	}	bcm43xx_radio_selectchannel(bcm, oldchannel, 1);#ifdef CONFIG_BCM43XX_DEBUG	{		/* Sanity check for all lopairs. */		for (i = 0; i < BCM43xx_LO_COUNT; i++) {			tmp_control = phy->_lo_pairs + i;			if (tmp_control->low < -8 || tmp_control->low > 8 ||			    tmp_control->high < -8 || tmp_control->high > 8) {				printk(KERN_WARNING PFX				       "WARNING: Invalid LOpair (low: %d, high: %d, index: %d)\n",				       tmp_control->low, tmp_control->high, i);			}		}	}#endif /* CONFIG_BCM43XX_DEBUG */}staticvoid bcm43xx_phy_lo_mark_current_used(struct bcm43xx_private *bcm){	struct bcm43xx_lopair *pair;	pair = bcm43xx_current_lopair(bcm);	pair->used = 1;}void bcm43xx_phy_lo_mark_all_unused(struct bcm43xx_private *bcm){	struct bcm43xx_phyinfo *phy = bcm->current_core->phy;	struct bcm43xx_lopair *pair;	int i;	for (i = 0; i < BCM43xx_LO_COUNT; i++) {		pair = phy->_lo_pairs + i;		pair->used = 0;	}}/* http://bcm-specs.sipsolutions.net/EstimatePowerOut * This function converts a TSSI value to dBm in Q5.2 */static s8 bcm43xx_phy_estimate_power_out(struct bcm43xx_private *bcm, s8 tssi){	struct bcm43xx_phyinfo *phy = bcm->current_core->phy;	s8 dbm = 0;	s32 tmp;	tmp = phy->idle_tssi;	tmp += tssi;	tmp -= phy->savedpctlreg;	switch (phy->type) {		case BCM43xx_PHYTYPE_A:			tmp += 0x80;			tmp = limit_value(tmp, 0x00, 0xFF);			dbm = phy->tssi2dbm[tmp];			TODO(); //TODO: There's a FIXME on the specs			break;		case BCM43xx_PHYTYPE_B:		case BCM43xx_PHYTYPE_G:			tmp = limit_value(tmp, 0x00, 0x3F);			dbm = phy->tssi2dbm[tmp];			break;		default:			assert(0);	}	return dbm;}/* http://bcm-specs.sipsolutions.net/RecalculateTransmissionPower */void bcm43xx_phy_xmitpower(struct bcm43xx_private *bcm){

⌨️ 快捷键说明

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