📄 ar5211_misc.c
字号:
/* * Copyright (c) 2002-2005 Sam Leffler, Errno Consulting * Copyright (c) 2002-2005 Atheros Communications, Inc. * All rights reserved. * * $Id: ar5211_misc.c,v 1.1.1.1 2006/09/12 03:45:23 steven Exp $ */#include "opt_ah.h"#ifdef AH_SUPPORT_AR5211#include "ah.h"#include "ah_internal.h"#include "ar5211/ar5211.h"#include "ar5211/ar5211reg.h"#include "ar5211/ar5211phy.h"#define AR_NUM_GPIO 6 /* 6 GPIO bits */#define AR_GPIOD_MASK 0x2f /* 6-bit mask */#define ANT_SWITCH_TABLE1 0x9960#define ANT_SWITCH_TABLE2 0x9964voidar5211GetMacAddress(struct ath_hal *ah, u_int8_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 u_int8_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, u_int8_t *mask){ static const u_int8_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 u_int8_t *mask){ return AH_FALSE;}/* * Read 16 bits of data from the specified EEPROM offset. */HAL_BOOLar5211EepromRead(struct ath_hal *ah, u_int off, u_int16_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, "%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, u_int16_t data){ OS_REG_WRITE(ah, AR_EEPROM_ADDR, off); OS_REG_WRITE(ah, AR_EEPROM_DATA, data); OS_REG_WRITE(ah, AR_EEPROM_CMD, AR_EEPROM_CMD_WRITE); if (!ath_hal_wait(ah, AR_EEPROM_STS, AR_EEPROM_STS_WRITE_COMPLETE | AR_EEPROM_STS_WRITE_ERROR, AR_EEPROM_STS_WRITE_COMPLETE)) { HALDEBUG(ah, "%s: write failed for entry 0x%x, data 0x%x\n", __func__, off, data); return AH_FALSE; } return AH_TRUE;}#endif /* AH_SUPPORT_WRITE_EEPROM *//* * Attempt to change the cards operating regulatory domain to the given value * Returns: A_EINVAL for an unsupported regulatory domain. * A_HARDWARE for an unwritable EEPROM or bad EEPROM version */HAL_BOOLar5211SetRegulatoryDomain(struct ath_hal *ah, u_int16_t regDomain, HAL_STATUS *status){ struct ath_hal_5211 *ahp = AH5211(ah); 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 (ahp->ah_eeprotect & AR_EEPROM_PROTECT_WP_128_191) { ecode = HAL_EEWRITE; goto bad; }#ifdef AH_SUPPORT_WRITE_REGDOMAIN if (ar5211EepromWrite(ah, AR_EEPROM_REG_DOMAIN, regDomain)) { HALDEBUG(ah, "%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){ struct ath_hal_5211 *ahp = AH5211(ah); u_int mode = 0; if (ahp->ah_Amode) { mode = HAL_MODE_11A; if (!ahp->ah_turbo5Disable) mode |= HAL_MODE_TURBO | HAL_MODE_108A; } if (ahp->ah_Bmode) mode |= HAL_MODE_11B; return mode;}/* * Accessor to get rfkill from private EEPROM structure */HAL_BOOLar5211GetRfKill(struct ath_hal *ah){ struct ath_hal_5211 *ahp = AH5211(ah); if (ahp->ah_rfKill) { u_int16_t rfsilent; if (!ar5211EepromRead(ah, AR_EEPROM_RFSILENT, &rfsilent)) return AH_FALSE; ahp->ah_gpioSelect = MS(rfsilent, AR_EEPROM_RFSILENT_GPIO_SEL); ahp->ah_polarity = MS(rfsilent, AR_EEPROM_RFSILENT_POLARITY); ahp->ah_eepEnabled = AH_TRUE; } else { ahp->ah_gpioSelect = ahp->ah_polarity = 0; ahp->ah_eepEnabled = AH_FALSE; } return (ahp->ah_rfKill != 0);}#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 * * TODO - can this really be above the hal on the GPIO interface for * TODO - the client only? */voidar5211EnableRfKill(struct ath_hal *ah){ struct ath_hal_5211 *ahp = AH5211(ah); u_int32_t val; /* * If radio disable switch connection to GPIO bit 0 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 0 hardware * connection is present. */ val = ar5211GpioGet(ah, 0); ar5211GpioSetIntr(ah, 0, (val == 0)); /* * Configure the desired GPIO port for input * and enable baseband rf silence. */ ar5211GpioCfgInput(ah, ahp->ah_gpioSelect);#ifdef notdef A_REG_RMW(ah, PHY_BASE, 0x00002000, 0);#else val = OS_REG_READ(ah, AR_PHY_BASE); OS_REG_WRITE(ah, AR_PHY_BASE, val &~ 0x2000);#endif /* * 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. */ ahp->ah_gpioBit = ar5211GpioGet(ah, ahp->ah_gpioSelect); ar5211GpioSet(ah, ahp->ah_gpioSelect, (ahp->ah_gpioBit != ahp->ah_polarity));}/* * Configure GPIO Output lines */HAL_BOOLar5211GpioCfgOutput(struct ath_hal *ah, u_int32_t gpio){ u_int32_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, u_int32_t gpio){ u_int32_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, u_int32_t gpio, u_int32_t val){ u_int32_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 */u_int32_tar5211GpioGet(struct ath_hal *ah, u_int32_t gpio){ if (gpio < AR_NUM_GPIO) { u_int32_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, u_int32_t ilevel){ u_int32_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 u_int32_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 u_int8_t *bssid, u_int16_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));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -