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

📄 ar5211_misc.c

📁 最新之atheros芯片driver source code, 基于linux操作系统,內含atheros芯片HAL全部代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting * Copyright (c) 2002-2006 Atheros Communications, Inc. * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * $Id: ar5211_misc.c,v 1.7 2008/11/27 22:29:52 sam Exp $ */#include "opt_ah.h"#include "ah.h"#include "ah_internal.h"#include "ar5211/ar5211.h"#include "ar5211/ar5211reg.h"#include "ar5211/ar5211phy.h"#include "ah_eeprom_v3.h"#define	AR_NUM_GPIO	6		/* 6 GPIO bits */#define	AR_GPIOD_MASK	0x2f		/* 6-bit mask */voidar5211GetMacAddress(struct ath_hal *ah, uint8_t *mac){	struct ath_hal_5211 *ahp = AH5211(ah);	OS_MEMCPY(mac, ahp->ah_macaddr, IEEE80211_ADDR_LEN);}HAL_BOOLar5211SetMacAddress(struct ath_hal *ah, const uint8_t *mac){	struct ath_hal_5211 *ahp = AH5211(ah);	OS_MEMCPY(ahp->ah_macaddr, mac, IEEE80211_ADDR_LEN);	return AH_TRUE;}voidar5211GetBssIdMask(struct ath_hal *ah, uint8_t *mask){	static const uint8_t ones[IEEE80211_ADDR_LEN] =		{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };	OS_MEMCPY(mask, ones, IEEE80211_ADDR_LEN);}HAL_BOOLar5211SetBssIdMask(struct ath_hal *ah, const uint8_t *mask){	return AH_FALSE;}/* * Read 16 bits of data from the specified EEPROM offset. */HAL_BOOLar5211EepromRead(struct ath_hal *ah, u_int off, uint16_t *data){	OS_REG_WRITE(ah, AR_EEPROM_ADDR, off);	OS_REG_WRITE(ah, AR_EEPROM_CMD, AR_EEPROM_CMD_READ);	if (!ath_hal_wait(ah, AR_EEPROM_STS,	    AR_EEPROM_STS_READ_COMPLETE | AR_EEPROM_STS_READ_ERROR,	    AR_EEPROM_STS_READ_COMPLETE)) {		HALDEBUG(ah, HAL_DEBUG_ANY,		    "%s: read failed for entry 0x%x\n", __func__, off);		return AH_FALSE;	}	*data = OS_REG_READ(ah, AR_EEPROM_DATA) & 0xffff;	return AH_TRUE;}#ifdef AH_SUPPORT_WRITE_EEPROM/* * Write 16 bits of data to the specified EEPROM offset. */HAL_BOOLar5211EepromWrite(struct ath_hal *ah, u_int off, uint16_t data){	return AH_FALSE;}#endif /* AH_SUPPORT_WRITE_EEPROM *//* * Attempt to change the cards operating regulatory domain to the given value */HAL_BOOLar5211SetRegulatoryDomain(struct ath_hal *ah,	uint16_t regDomain, HAL_STATUS *status){	HAL_STATUS ecode;	if (AH_PRIVATE(ah)->ah_currentRD == regDomain) {		ecode = HAL_EINVAL;		goto bad;	}	/*	 * Check if EEPROM is configured to allow this; must	 * be a proper version and the protection bits must	 * permit re-writing that segment of the EEPROM.	 */	if (ath_hal_eepromGetFlag(ah, AR_EEP_WRITEPROTECT)) {		ecode = HAL_EEWRITE;		goto bad;	}#ifdef AH_SUPPORT_WRITE_REGDOMAIN	if (ar5211EepromWrite(ah, AR_EEPROM_REG_DOMAIN, regDomain)) {		HALDEBUG(ah, HAL_DEBUG_ANY,		    "%s: set regulatory domain to %u (0x%x)\n",		    __func__, regDomain, regDomain);		AH_PRIVATE(ah)->ah_currentRD = regDomain;		return AH_TRUE;	}#endif	ecode = HAL_EIO;bad:	if (status)		*status = ecode;	return AH_FALSE;}/* * Return the wireless modes (a,b,g,t) supported by hardware. * * This value is what is actually supported by the hardware * and is unaffected by regulatory/country code settings. * */u_intar5211GetWirelessModes(struct ath_hal *ah){	u_int mode = 0;	if (ath_hal_eepromGetFlag(ah, AR_EEP_AMODE)) {		mode = HAL_MODE_11A;		if (!ath_hal_eepromGetFlag(ah, AR_EEP_TURBO5DISABLE))			mode |= HAL_MODE_TURBO | HAL_MODE_108A;	}	if (ath_hal_eepromGetFlag(ah, AR_EEP_BMODE))		mode |= HAL_MODE_11B;	return mode;}#if 0HAL_BOOLar5211GetTurboDisable(struct ath_hal *ah){	return (AH5211(ah)->ah_turboDisable != 0);}#endif/* * Called if RfKill is supported (according to EEPROM).  Set the interrupt and * GPIO values so the ISR and can disable RF on a switch signal */voidar5211EnableRfKill(struct ath_hal *ah){	uint16_t rfsilent = AH_PRIVATE(ah)->ah_rfsilent;	int select = MS(rfsilent, AR_EEPROM_RFSILENT_GPIO_SEL);	int polarity = MS(rfsilent, AR_EEPROM_RFSILENT_POLARITY);	/*	 * Configure the desired GPIO port for input	 * and enable baseband rf silence.	 */	ar5211GpioCfgInput(ah, select);	OS_REG_SET_BIT(ah, AR_PHY_BASE, 0x00002000);	/*	 * If radio disable switch connection to GPIO bit x is enabled	 * program GPIO interrupt.	 * If rfkill bit on eeprom is 1, setupeeprommap routine has already	 * verified that it is a later version of eeprom, it has a place for	 * rfkill bit and it is set to 1, indicating that GPIO bit x hardware	 * connection is present.	 */	ar5211GpioSetIntr(ah, select, (ar5211GpioGet(ah, select) != polarity));}/* * Configure GPIO Output lines */HAL_BOOLar5211GpioCfgOutput(struct ath_hal *ah, uint32_t gpio){	uint32_t reg;	HALASSERT(gpio < AR_NUM_GPIO);	reg =  OS_REG_READ(ah, AR_GPIOCR);	reg &= ~(AR_GPIOCR_0_CR_A << (gpio * AR_GPIOCR_CR_SHIFT));	reg |= AR_GPIOCR_0_CR_A << (gpio * AR_GPIOCR_CR_SHIFT);	OS_REG_WRITE(ah, AR_GPIOCR, reg);	return AH_TRUE;}/* * Configure GPIO Input lines */HAL_BOOLar5211GpioCfgInput(struct ath_hal *ah, uint32_t gpio){	uint32_t reg;	HALASSERT(gpio < AR_NUM_GPIO);	reg =  OS_REG_READ(ah, AR_GPIOCR);	reg &= ~(AR_GPIOCR_0_CR_A << (gpio * AR_GPIOCR_CR_SHIFT));	reg |= AR_GPIOCR_0_CR_N << (gpio * AR_GPIOCR_CR_SHIFT);	OS_REG_WRITE(ah, AR_GPIOCR, reg);	return AH_TRUE;}/* * Once configured for I/O - set output lines */HAL_BOOLar5211GpioSet(struct ath_hal *ah, uint32_t gpio, uint32_t val){	uint32_t reg;	HALASSERT(gpio < AR_NUM_GPIO);	reg =  OS_REG_READ(ah, AR_GPIODO);	reg &= ~(1 << gpio);	reg |= (val&1) << gpio;	OS_REG_WRITE(ah, AR_GPIODO, reg);	return AH_TRUE;}/* * Once configured for I/O - get input lines */uint32_tar5211GpioGet(struct ath_hal *ah, uint32_t gpio){	if (gpio < AR_NUM_GPIO) {		uint32_t val = OS_REG_READ(ah, AR_GPIODI);		val = ((val & AR_GPIOD_MASK) >> gpio) & 0x1;		return val;	} else  {		return 0xffffffff;	}}/* * Set the GPIO 0 Interrupt (gpio is ignored) */voidar5211GpioSetIntr(struct ath_hal *ah, u_int gpio, uint32_t ilevel){	uint32_t val = OS_REG_READ(ah, AR_GPIOCR);	/* Clear the bits that we will modify. */	val &= ~(AR_GPIOCR_INT_SEL0 | AR_GPIOCR_INT_SELH | AR_GPIOCR_INT_ENA |			AR_GPIOCR_0_CR_A);	val |= AR_GPIOCR_INT_SEL0 | AR_GPIOCR_INT_ENA;	if (ilevel)		val |= AR_GPIOCR_INT_SELH;	/* Don't need to change anything for low level interrupt. */	OS_REG_WRITE(ah, AR_GPIOCR, val);	/* Change the interrupt mask. */	ar5211SetInterrupts(ah, AH5211(ah)->ah_maskReg | HAL_INT_GPIO);}/* * Change the LED blinking pattern to correspond to the connectivity */voidar5211SetLedState(struct ath_hal *ah, HAL_LED_STATE state){	static const uint32_t ledbits[8] = {		AR_PCICFG_LEDCTL_NONE|AR_PCICFG_LEDMODE_PROP, /* HAL_LED_INIT */		AR_PCICFG_LEDCTL_PEND|AR_PCICFG_LEDMODE_PROP, /* HAL_LED_SCAN */		AR_PCICFG_LEDCTL_PEND|AR_PCICFG_LEDMODE_PROP, /* HAL_LED_AUTH */		AR_PCICFG_LEDCTL_ASSOC|AR_PCICFG_LEDMODE_PROP,/* HAL_LED_ASSOC*/		AR_PCICFG_LEDCTL_ASSOC|AR_PCICFG_LEDMODE_PROP,/* HAL_LED_RUN */		AR_PCICFG_LEDCTL_NONE|AR_PCICFG_LEDMODE_RAND,		AR_PCICFG_LEDCTL_NONE|AR_PCICFG_LEDMODE_RAND,		AR_PCICFG_LEDCTL_NONE|AR_PCICFG_LEDMODE_RAND,	};	OS_REG_WRITE(ah, AR_PCICFG,		(OS_REG_READ(ah, AR_PCICFG) &~			(AR_PCICFG_LEDCTL | AR_PCICFG_LEDMODE))		| ledbits[state & 0x7]	);}/* * Change association related fields programmed into the hardware. * Writing a valid BSSID to the hardware effectively enables the hardware * to synchronize its TSF to the correct beacons and receive frames coming * from that BSSID. It is called by the SME JOIN operation. */voidar5211WriteAssocid(struct ath_hal *ah, const uint8_t *bssid, uint16_t assocId){	struct ath_hal_5211 *ahp = AH5211(ah);	/* XXX save bssid for possible re-use on reset */	OS_MEMCPY(ahp->ah_bssid, bssid, IEEE80211_ADDR_LEN);	OS_REG_WRITE(ah, AR_BSS_ID0, LE_READ_4(ahp->ah_bssid));	OS_REG_WRITE(ah, AR_BSS_ID1, LE_READ_2(ahp->ah_bssid+4) |				     ((assocId & 0x3fff)<<AR_BSS_ID1_AID_S));}/* * Get the current hardware tsf for stamlme. */uint64_tar5211GetTsf64(struct ath_hal *ah){	uint32_t low1, low2, u32;	/* sync multi-word read */	low1 = OS_REG_READ(ah, AR_TSF_L32);	u32 = OS_REG_READ(ah, AR_TSF_U32);	low2 = OS_REG_READ(ah, AR_TSF_L32);	if (low2 < low1) {	/* roll over */		/*		 * If we are not preempted this will work.  If we are		 * then we re-reading AR_TSF_U32 does no good as the		 * low bits will be meaningless.  Likewise reading		 * L32, U32, U32, then comparing the last two reads		 * to check for rollover doesn't help if preempted--so		 * we take this approach as it costs one less PCI

⌨️ 快捷键说明

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