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

📄 phy.c

📁 linux内核源码
💻 C
📖 第 1 页 / 共 5 页
字号:
{	struct b43legacy_lopair *pair;	if (fixed) {		/* Use fixed values. Only for initialization. */		pair = b43legacy_find_lopair(dev, 2, 3, 0);	} else		pair = b43legacy_current_lopair(dev);	b43legacy_lo_write(dev, pair);}static void b43legacy_phy_lo_g_measure_txctl2(struct b43legacy_wldev *dev){	struct b43legacy_phy *phy = &dev->phy;	u16 txctl2 = 0;	u16 i;	u32 smallest;	u32 tmp;	b43legacy_radio_write16(dev, 0x0052, 0x0000);	udelay(10);	smallest = b43legacy_phy_lo_g_singledeviation(dev, 0);	for (i = 0; i < 16; i++) {		b43legacy_radio_write16(dev, 0x0052, i);		udelay(10);		tmp = b43legacy_phy_lo_g_singledeviation(dev, 0);		if (tmp < smallest) {			smallest = tmp;			txctl2 = i;		}	}	phy->txctl2 = txctl2;}staticvoid b43legacy_phy_lo_g_state(struct b43legacy_wldev *dev,			      const struct b43legacy_lopair *in_pair,			      struct b43legacy_lopair *out_pair,			      u16 r27){	static const struct b43legacy_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 b43legacy_lopair lowest_transition = {		.high = in_pair->high,		.low = in_pair->low,	};	struct b43legacy_lopair tmp_pair;	struct b43legacy_lopair transition;	int i = 12;	int state = 0;	int found_lower;	int j;	int begin;	int end;	u32 lowest_deviation;	u32 tmp;	/* Note that in_pair and out_pair can point to the same pair.	 * Be careful. */	b43legacy_lo_write(dev, &lowest_transition);	lowest_deviation = b43legacy_phy_lo_g_singledeviation(dev, r27);	do {		found_lower = 0;		B43legacy_WARN_ON(!(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) {			B43legacy_WARN_ON(!(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)) {				b43legacy_lo_write(dev, &transition);				tmp = b43legacy_phy_lo_g_singledeviation(dev,								       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 b43legacy_phy_set_baseband_attenuation(struct b43legacy_wldev *dev,					    u16 bbatt){	struct b43legacy_phy *phy = &dev->phy;	u16 value;	if (phy->analog == 0) {		value = (b43legacy_read16(dev, 0x03E6) & 0xFFF0);		value |= (bbatt & 0x000F);		b43legacy_write16(dev, 0x03E6, value);		return;	}	if (phy->analog > 1) {		value = b43legacy_phy_read(dev, 0x0060) & 0xFFC3;		value |= (bbatt << 2) & 0x003C;	} else {		value = b43legacy_phy_read(dev, 0x0060) & 0xFF87;		value |= (bbatt << 3) & 0x0078;	}	b43legacy_phy_write(dev, 0x0060, value);}/* http://bcm-specs.sipsolutions.net/LocalOscillator/Measure */void b43legacy_phy_lo_g_measure(struct b43legacy_wldev *dev){	static const u8 pairorder[10] = { 3, 1, 5, 7, 9, 2, 0, 4, 6, 8 };	const int is_initializing = (b43legacy_status(dev)				     < B43legacy_STAT_STARTED);	struct b43legacy_phy *phy = &dev->phy;	u16 h;	u16 i;	u16 oldi = 0;	u16 j;	struct b43legacy_lopair control;	struct b43legacy_lopair *tmp_control;	u16 tmp;	u16 regstack[16] = { 0 };	u8 oldchannel;	/* XXX: What are these? */	u8 r27 = 0;	u16 r31;	oldchannel = phy->channel;	/* Setup */	if (phy->gmode) {		regstack[0] = b43legacy_phy_read(dev, B43legacy_PHY_G_CRS);		regstack[1] = b43legacy_phy_read(dev, 0x0802);		b43legacy_phy_write(dev, B43legacy_PHY_G_CRS, regstack[0]				    & 0x7FFF);		b43legacy_phy_write(dev, 0x0802, regstack[1] & 0xFFFC);	}	regstack[3] = b43legacy_read16(dev, 0x03E2);	b43legacy_write16(dev, 0x03E2, regstack[3] | 0x8000);	regstack[4] = b43legacy_read16(dev, B43legacy_MMIO_CHANNEL_EXT);	regstack[5] = b43legacy_phy_read(dev, 0x15);	regstack[6] = b43legacy_phy_read(dev, 0x2A);	regstack[7] = b43legacy_phy_read(dev, 0x35);	regstack[8] = b43legacy_phy_read(dev, 0x60);	regstack[9] = b43legacy_radio_read16(dev, 0x43);	regstack[10] = b43legacy_radio_read16(dev, 0x7A);	regstack[11] = b43legacy_radio_read16(dev, 0x52);	if (phy->gmode) {		regstack[12] = b43legacy_phy_read(dev, 0x0811);		regstack[13] = b43legacy_phy_read(dev, 0x0812);		regstack[14] = b43legacy_phy_read(dev, 0x0814);		regstack[15] = b43legacy_phy_read(dev, 0x0815);	}	b43legacy_radio_selectchannel(dev, 6, 0);	if (phy->gmode) {		b43legacy_phy_write(dev, B43legacy_PHY_G_CRS, regstack[0]				    & 0x7FFF);		b43legacy_phy_write(dev, 0x0802, regstack[1] & 0xFFFC);		b43legacy_dummy_transmission(dev);	}	b43legacy_radio_write16(dev, 0x0043, 0x0006);	b43legacy_phy_set_baseband_attenuation(dev, 2);	b43legacy_write16(dev, B43legacy_MMIO_CHANNEL_EXT, 0x0000);	b43legacy_phy_write(dev, 0x002E, 0x007F);	b43legacy_phy_write(dev, 0x080F, 0x0078);	b43legacy_phy_write(dev, 0x0035, regstack[7] & ~(1 << 7));	b43legacy_radio_write16(dev, 0x007A, regstack[10] & 0xFFF0);	b43legacy_phy_write(dev, 0x002B, 0x0203);	b43legacy_phy_write(dev, 0x002A, 0x08A3);	if (phy->gmode) {		b43legacy_phy_write(dev, 0x0814, regstack[14] | 0x0003);		b43legacy_phy_write(dev, 0x0815, regstack[15] & 0xFFFC);		b43legacy_phy_write(dev, 0x0811, 0x01B3);		b43legacy_phy_write(dev, 0x0812, 0x00B2);	}	if (is_initializing)		b43legacy_phy_lo_g_measure_txctl2(dev);	b43legacy_phy_write(dev, 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 = b43legacy_get_lopair(phy, oldi,								   0);				memcpy(&control, tmp_control, sizeof(control));			} else {				tmp_control = b43legacy_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 = b43legacy_get_lopair(phy, i,								   j * 2);				if (!tmp_control->used)					continue;				memcpy(&control, tmp_control, sizeof(control));				r27 = 3;				r31 = 0;			}			b43legacy_radio_write16(dev, 0x43, i);			b43legacy_radio_write16(dev, 0x52, phy->txctl2);			udelay(10);			b43legacy_voluntary_preempt();			b43legacy_phy_set_baseband_attenuation(dev, j * 2);			tmp = (regstack[10] & 0xFFF0);			if (r31)				tmp |= 0x0008;			b43legacy_radio_write16(dev, 0x007A, tmp);			tmp_control = b43legacy_get_lopair(phy, i, j * 2);			b43legacy_phy_lo_g_state(dev, &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 = b43legacy_get_lopair(phy, i - 9,								 j * 2);				memcpy(&control, tmp_control, sizeof(control));				/* FIXME: The next line is wrong, as the				 * following if statement can never trigger. */				tmp = (i - 9) * 2 + j - 5;				r27 = 0;				r31 = 0;				if (tmp > 14) {					r31 = 1;					if (tmp > 17)						r27 = 1;					if (tmp > 19)						r27 = 2;				}			} else {				tmp_control = b43legacy_get_lopair(phy, i - 9,								   j * 2);				if (!tmp_control->used)					continue;				memcpy(&control, tmp_control, sizeof(control));				r27 = 3;				r31 = 0;			}			b43legacy_radio_write16(dev, 0x43, i - 9);			/* FIXME: shouldn't txctl1 be zero in the next line			 * and 3 in the loop above? */			b43legacy_radio_write16(dev, 0x52,					      phy->txctl2					      | (3/*txctl1*/ << 4));			udelay(10);			b43legacy_voluntary_preempt();			b43legacy_phy_set_baseband_attenuation(dev, j * 2);			tmp = (regstack[10] & 0xFFF0);			if (r31)				tmp |= 0x0008;			b43legacy_radio_write16(dev, 0x7A, tmp);			tmp_control = b43legacy_get_lopair(phy, i, j * 2);			b43legacy_phy_lo_g_state(dev, &control, tmp_control,						 r27);		}	}	/* Restoration */	if (phy->gmode) {		b43legacy_phy_write(dev, 0x0015, 0xE300);		b43legacy_phy_write(dev, 0x0812, (r27 << 8) | 0xA0);		udelay(5);		b43legacy_phy_write(dev, 0x0812, (r27 << 8) | 0xA2);		udelay(2);		b43legacy_phy_write(dev, 0x0812, (r27 << 8) | 0xA3);		b43legacy_voluntary_preempt();	} else		b43legacy_phy_write(dev, 0x0015, r27 | 0xEFA0);	b43legacy_phy_lo_adjust(dev, is_initializing);	b43legacy_phy_write(dev, 0x002E, 0x807F);	if (phy->gmode)		b43legacy_phy_write(dev, 0x002F, 0x0202);	else		b43legacy_phy_write(dev, 0x002F, 0x0101);	b43legacy_write16(dev, B43legacy_MMIO_CHANNEL_EXT, regstack[4]);	b43legacy_phy_write(dev, 0x0015, regstack[5]);	b43legacy_phy_write(dev, 0x002A, regstack[6]);	b43legacy_phy_write(dev, 0x0035, regstack[7]);	b43legacy_phy_write(dev, 0x0060, regstack[8]);	b43legacy_radio_write16(dev, 0x0043, regstack[9]);	b43legacy_radio_write16(dev, 0x007A, regstack[10]);	regstack[11] &= 0x00F0;	regstack[11] |= (b43legacy_radio_read16(dev, 0x52) & 0x000F);	b43legacy_radio_write16(dev, 0x52, regstack[11]);	b43legacy_write16(dev, 0x03E2, regstack[3]);	if (phy->gmode) {		b43legacy_phy_write(dev, 0x0811, regstack[12]);		b43legacy_phy_write(dev, 0x0812, regstack[13]);		b43legacy_phy_write(dev, 0x0814, regstack[14]);		b43legacy_phy_write(dev, 0x0815, regstack[15]);		b43legacy_phy_write(dev, B43legacy_PHY_G_CRS, regstack[0]);		b43legacy_phy_write(dev, 0x0802, regstack[1]);	}	b43legacy_radio_selectchannel(dev, oldchannel, 1);#ifdef CONFIG_B43LEGACY_DEBUG	{		/* Sanity check for all lopairs. */		for (i = 0; i < B43legacy_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)				b43legacywarn(dev->wl,				       "WARNING: Invalid LOpair (low: %d, high:"				       " %d, index: %d)\n",				       tmp_control->low, tmp_control->high, i);		}	}#endif /* CONFIG_B43LEGACY_DEBUG */}staticvoid b43legacy_phy_lo_mark_current_used(struct b43legacy_wldev *dev){	struct b43legacy_lopair *pair;	pair = b43legacy_current_lopair(dev);	pair->used = 1;}void b43legacy_phy_lo_mark_all_unused(struct b43legacy_wldev *dev){	struct b43legacy_phy *phy = &dev->phy;	struct b43legacy_lopair *pair;	int i;	for (i = 0; i < B43legacy_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 b43legacy_phy_estimate_power_out(struct b43legacy_wldev *dev, s8 tssi){	struct b43legacy_phy *phy = &dev->phy;	s8 dbm = 0;	s32 tmp;	tmp = phy->idle_tssi;	tmp += tssi;	tmp -= phy->savedpctlreg;	switch (phy->type) {	case B43legacy_PHYTYPE_B:	case B43legacy_PHYTYPE_G:		tmp = limit_value(tmp, 0x00, 0x3F);		dbm = phy->tssi2dbm[tmp];		break;	default:		B43legacy_BUG_ON(1);	}	return dbm;}/* http://bcm-specs.sipsolutions.net/RecalculateTransmissionPower */void b43legacy_phy_xmitpower(struct b43legacy_wldev *dev){	struct b43legacy_phy *phy = &dev->phy;	u16 tmp;	u16 txpower;	s8 v0;	s8 v1;	s8 v2;	s8 v3;	s8 average;	int max_pwr;

⌨️ 快捷键说明

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