1 1.1 alc /* 2 1.1 alc * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting 3 1.1 alc * Copyright (c) 2002-2008 Atheros Communications, Inc. 4 1.1 alc * 5 1.1 alc * Permission to use, copy, modify, and/or distribute this software for any 6 1.1 alc * purpose with or without fee is hereby granted, provided that the above 7 1.1 alc * copyright notice and this permission notice appear in all copies. 8 1.1 alc * 9 1.1 alc * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 1.1 alc * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 1.1 alc * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 1.1 alc * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 1.1 alc * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 1.1 alc * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 1.1 alc * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 1.1 alc * 17 1.3 cegger * $Id: ar5312_attach.c,v 1.3 2011/03/07 11:25:43 cegger Exp $ 18 1.1 alc */ 19 1.1 alc #include "opt_ah.h" 20 1.1 alc 21 1.1 alc #include "ah.h" 22 1.1 alc #include "ah_internal.h" 23 1.1 alc #include "ah_devid.h" 24 1.1 alc 25 1.1 alc #include "ar5312/ar5312.h" 26 1.1 alc #include "ar5312/ar5312reg.h" 27 1.1 alc #include "ar5312/ar5312phy.h" 28 1.1 alc 29 1.1 alc /* Add static register initialization vectors */ 30 1.1 alc #define AH_5212_COMMON 31 1.1 alc #include "ar5212/ar5212.ini" 32 1.1 alc 33 1.1 alc static HAL_BOOL ar5312GetMacAddr(struct ath_hal *ah); 34 1.1 alc 35 1.1 alc static void 36 1.1 alc ar5312AniSetup(struct ath_hal *ah) 37 1.1 alc { 38 1.1 alc static const struct ar5212AniParams aniparams = { 39 1.1 alc .maxNoiseImmunityLevel = 4, /* levels 0..4 */ 40 1.1 alc .totalSizeDesired = { -41, -41, -48, -48, -48 }, 41 1.1 alc .coarseHigh = { -18, -18, -16, -14, -12 }, 42 1.1 alc .coarseLow = { -56, -56, -60, -60, -60 }, 43 1.1 alc .firpwr = { -72, -72, -75, -78, -80 }, 44 1.1 alc .maxSpurImmunityLevel = 2, 45 1.1 alc .cycPwrThr1 = { 2, 4, 6 }, 46 1.1 alc .maxFirstepLevel = 2, /* levels 0..2 */ 47 1.1 alc .firstep = { 0, 4, 8 }, 48 1.1 alc .ofdmTrigHigh = 500, 49 1.1 alc .ofdmTrigLow = 200, 50 1.1 alc .cckTrigHigh = 200, 51 1.1 alc .cckTrigLow = 100, 52 1.1 alc .rssiThrHigh = 40, 53 1.1 alc .rssiThrLow = 7, 54 1.1 alc .period = 100, 55 1.1 alc }; 56 1.1 alc ar5212AniAttach(ah, &aniparams, &aniparams, AH_TRUE); 57 1.1 alc } 58 1.1 alc 59 1.1 alc /* 60 1.1 alc * Attach for an AR5312 part. 61 1.1 alc */ 62 1.1 alc static struct ath_hal * 63 1.1 alc ar5312Attach(uint16_t devid, HAL_SOFTC sc, 64 1.1 alc HAL_BUS_TAG st, HAL_BUS_HANDLE sh, HAL_STATUS *status) 65 1.1 alc { 66 1.1 alc struct ath_hal_5212 *ahp = AH_NULL; 67 1.1 alc struct ath_hal *ah; 68 1.1 alc struct ath_hal_rf *rf; 69 1.1 alc uint32_t val; 70 1.1 alc uint16_t eeval; 71 1.1 alc HAL_STATUS ecode; 72 1.1 alc 73 1.1 alc HALDEBUG(AH_NULL, HAL_DEBUG_ATTACH, "%s: sc %p st %p sh %p\n", 74 1.1 alc __func__, sc, st, (void*) sh); 75 1.1 alc 76 1.1 alc /* NB: memory is returned zero'd */ 77 1.1 alc ahp = ath_hal_malloc(sizeof (struct ath_hal_5212)); 78 1.1 alc if (ahp == AH_NULL) { 79 1.1 alc HALDEBUG(AH_NULL, HAL_DEBUG_ANY, 80 1.1 alc "%s: cannot allocate memory for state block\n", __func__); 81 1.1 alc *status = HAL_ENOMEM; 82 1.1 alc return AH_NULL; 83 1.1 alc } 84 1.1 alc ar5212InitState(ahp, devid, sc, st, sh, status); 85 1.1 alc ah = &ahp->ah_priv.h; 86 1.1 alc 87 1.1 alc /* override 5212 methods for our needs */ 88 1.1 alc ah->ah_reset = ar5312Reset; 89 1.1 alc ah->ah_phyDisable = ar5312PhyDisable; 90 1.1 alc ah->ah_setLedState = ar5312SetLedState; 91 1.1 alc ah->ah_detectCardPresent = ar5312DetectCardPresent; 92 1.1 alc ah->ah_setPowerMode = ar5312SetPowerMode; 93 1.1 alc ah->ah_getPowerMode = ar5312GetPowerMode; 94 1.1 alc ah->ah_isInterruptPending = ar5312IsInterruptPending; 95 1.1 alc 96 1.1 alc ahp->ah_priv.ah_eepromRead = ar5312EepromRead; 97 1.1 alc #ifdef AH_SUPPORT_WRITE_EEPROM 98 1.1 alc ahp->ah_priv.ah_eepromWrite = ar5312EepromWrite; 99 1.1 alc #endif 100 1.1 alc #if ( AH_SUPPORT_2316 || AH_SUPPORT_2317) 101 1.1 alc if (IS_5315(ah)) { 102 1.1 alc ahp->ah_priv.ah_gpioCfgOutput = ar5315GpioCfgOutput; 103 1.1 alc ahp->ah_priv.ah_gpioCfgInput = ar5315GpioCfgInput; 104 1.1 alc ahp->ah_priv.ah_gpioGet = ar5315GpioGet; 105 1.1 alc ahp->ah_priv.ah_gpioSet = ar5315GpioSet; 106 1.1 alc ahp->ah_priv.ah_gpioSetIntr = ar5315GpioSetIntr; 107 1.1 alc } else 108 1.1 alc #endif 109 1.1 alc { 110 1.1 alc ahp->ah_priv.ah_gpioCfgOutput = ar5312GpioCfgOutput; 111 1.1 alc ahp->ah_priv.ah_gpioCfgInput = ar5312GpioCfgInput; 112 1.1 alc ahp->ah_priv.ah_gpioGet = ar5312GpioGet; 113 1.1 alc ahp->ah_priv.ah_gpioSet = ar5312GpioSet; 114 1.1 alc ahp->ah_priv.ah_gpioSetIntr = ar5312GpioSetIntr; 115 1.1 alc } 116 1.1 alc 117 1.1 alc ah->ah_gpioCfgInput = ahp->ah_priv.ah_gpioCfgInput; 118 1.1 alc ah->ah_gpioCfgOutput = ahp->ah_priv.ah_gpioCfgOutput; 119 1.1 alc ah->ah_gpioGet = ahp->ah_priv.ah_gpioGet; 120 1.1 alc ah->ah_gpioSet = ahp->ah_priv.ah_gpioSet; 121 1.1 alc ah->ah_gpioSetIntr = ahp->ah_priv.ah_gpioSetIntr; 122 1.1 alc 123 1.1 alc /* setup common ini data; rf backends handle remainder */ 124 1.1 alc HAL_INI_INIT(&ahp->ah_ini_modes, ar5212Modes, 6); 125 1.3 cegger HAL_INI_INIT(&ahp->ah_ini_common, ar5212Common, 2); 126 1.1 alc 127 1.1 alc if (!ar5312ChipReset(ah, AH_NULL)) { /* reset chip */ 128 1.1 alc HALDEBUG(ah, HAL_DEBUG_ANY, "%s: chip reset failed\n", __func__); 129 1.1 alc ecode = HAL_EIO; 130 1.1 alc goto bad; 131 1.1 alc } 132 1.1 alc 133 1.1 alc #if ( AH_SUPPORT_2316 || AH_SUPPORT_2317) 134 1.1 alc if ((devid == AR5212_AR2315_REV6) || 135 1.1 alc (devid == AR5212_AR2315_REV7) || 136 1.1 alc (devid == AR5212_AR2317_REV1) || 137 1.1 alc (devid == AR5212_AR2317_REV2) ) { 138 1.1 alc val = ((OS_REG_READ(ah, (AR5315_RSTIMER_BASE -((uint32_t) sh)) + AR5315_WREV)) >> AR5315_WREV_S) 139 1.1 alc & AR5315_WREV_ID; 140 1.1 alc AH_PRIVATE(ah)->ah_macVersion = val >> AR5315_WREV_ID_S; 141 1.1 alc AH_PRIVATE(ah)->ah_macRev = val & AR5315_WREV_REVISION; 142 1.1 alc HALDEBUG(ah, HAL_DEBUG_ATTACH, 143 1.1 alc "%s: Mac Chip Rev 0x%02x.%x\n" , __func__, 144 1.1 alc AH_PRIVATE(ah)->ah_macVersion, AH_PRIVATE(ah)->ah_macRev); 145 1.1 alc } else 146 1.1 alc #endif 147 1.1 alc { 148 1.1 alc val = OS_REG_READ(ah, (AR5312_RSTIMER_BASE - ((uint32_t) sh)) + 0x0020); 149 1.1 alc val = OS_REG_READ(ah, (AR5312_RSTIMER_BASE - ((uint32_t) sh)) + 0x0080); 150 1.1 alc /* Read Revisions from Chips */ 151 1.1 alc val = ((OS_REG_READ(ah, (AR5312_RSTIMER_BASE - ((uint32_t) sh)) + AR5312_WREV)) >> AR5312_WREV_S) & AR5312_WREV_ID; 152 1.1 alc AH_PRIVATE(ah)->ah_macVersion = val >> AR5312_WREV_ID_S; 153 1.1 alc AH_PRIVATE(ah)->ah_macRev = val & AR5312_WREV_REVISION; 154 1.1 alc } 155 1.1 alc /* XXX - THIS IS WRONG. NEEDS TO BE FIXED */ 156 1.1 alc if (((AH_PRIVATE(ah)->ah_macVersion != AR_SREV_VERSION_VENICE && 157 1.1 alc AH_PRIVATE(ah)->ah_macVersion != AR_SREV_VERSION_VENICE) || 158 1.1 alc AH_PRIVATE(ah)->ah_macRev < AR_SREV_D2PLUS) && 159 1.1 alc AH_PRIVATE(ah)->ah_macVersion != AR_SREV_VERSION_COBRA) { 160 1.1 alc #ifdef AH_DEBUG 161 1.1 alc ath_hal_printf(ah, "%s: Mac Chip Rev 0x%02x.%x is not supported by " 162 1.1 alc "this driver\n", __func__, 163 1.1 alc AH_PRIVATE(ah)->ah_macVersion, 164 1.1 alc AH_PRIVATE(ah)->ah_macRev); 165 1.1 alc #endif 166 1.1 alc ecode = HAL_ENOTSUPP; 167 1.1 alc goto bad; 168 1.1 alc } 169 1.1 alc 170 1.1 alc AH_PRIVATE(ah)->ah_phyRev = OS_REG_READ(ah, AR_PHY_CHIP_ID); 171 1.1 alc 172 1.1 alc if (!ar5212ChipTest(ah)) { 173 1.1 alc HALDEBUG(ah, HAL_DEBUG_ANY, "%s: hardware self-test failed\n", 174 1.1 alc __func__); 175 1.1 alc ecode = HAL_ESELFTEST; 176 1.1 alc goto bad; 177 1.1 alc } 178 1.1 alc 179 1.1 alc /* 180 1.1 alc * Set correct Baseband to analog shift 181 1.1 alc * setting to access analog chips. 182 1.1 alc */ 183 1.1 alc OS_REG_WRITE(ah, AR_PHY(0), 0x00000007); 184 1.1 alc 185 1.1 alc /* Read Radio Chip Rev Extract */ 186 1.1 alc AH_PRIVATE(ah)->ah_analog5GhzRev = ar5212GetRadioRev(ah); 187 1.1 alc 188 1.1 alc rf = ath_hal_rfprobe(ah, &ecode); 189 1.1 alc if (rf == AH_NULL) 190 1.1 alc goto bad; 191 1.1 alc if (IS_RAD5112(ah) && !IS_RADX112_REV2(ah)) { 192 1.1 alc #ifdef AH_DEBUG 193 1.1 alc ath_hal_printf(ah, "%s: 5112 Rev 1 is not supported by this " 194 1.1 alc "driver (analog5GhzRev 0x%x)\n", __func__, 195 1.1 alc AH_PRIVATE(ah)->ah_analog5GhzRev); 196 1.1 alc #endif 197 1.1 alc ecode = HAL_ENOTSUPP; 198 1.1 alc goto bad; 199 1.1 alc } 200 1.1 alc 201 1.1 alc ecode = ath_hal_legacyEepromAttach(ah); 202 1.1 alc if (ecode != HAL_OK) { 203 1.1 alc goto bad; 204 1.1 alc } 205 1.1 alc 206 1.1 alc /* 207 1.1 alc * If Bmode and AR5212, verify 2.4 analog exists 208 1.1 alc */ 209 1.1 alc if (ath_hal_eepromGetFlag(ah, AR_EEP_BMODE) && 210 1.1 alc (AH_PRIVATE(ah)->ah_analog5GhzRev & 0xF0) == AR_RAD5111_SREV_MAJOR) { 211 1.1 alc /* 212 1.1 alc * Set correct Baseband to analog shift 213 1.1 alc * setting to access analog chips. 214 1.1 alc */ 215 1.1 alc OS_REG_WRITE(ah, AR_PHY(0), 0x00004007); 216 1.1 alc OS_DELAY(2000); 217 1.1 alc AH_PRIVATE(ah)->ah_analog2GhzRev = ar5212GetRadioRev(ah); 218 1.1 alc 219 1.1 alc /* Set baseband for 5GHz chip */ 220 1.1 alc OS_REG_WRITE(ah, AR_PHY(0), 0x00000007); 221 1.1 alc OS_DELAY(2000); 222 1.1 alc if ((AH_PRIVATE(ah)->ah_analog2GhzRev & 0xF0) != AR_RAD2111_SREV_MAJOR) { 223 1.1 alc #ifdef AH_DEBUG 224 1.1 alc ath_hal_printf(ah, "%s: 2G Radio Chip Rev 0x%02X is not " 225 1.1 alc "supported by this driver\n", __func__, 226 1.1 alc AH_PRIVATE(ah)->ah_analog2GhzRev); 227 1.1 alc #endif 228 1.1 alc ecode = HAL_ENOTSUPP; 229 1.1 alc goto bad; 230 1.1 alc } 231 1.1 alc } 232 1.1 alc 233 1.1 alc ecode = ath_hal_eepromGet(ah, AR_EEP_REGDMN_0, &eeval); 234 1.1 alc if (ecode != HAL_OK) { 235 1.1 alc HALDEBUG(ah, HAL_DEBUG_ANY, 236 1.1 alc "%s: cannot read regulatory domain from EEPROM\n", 237 1.1 alc __func__); 238 1.1 alc goto bad; 239 1.1 alc } 240 1.1 alc AH_PRIVATE(ah)->ah_currentRD = eeval; 241 1.1 alc /* XXX record serial number */ 242 1.1 alc 243 1.1 alc /* XXX other capabilities */ 244 1.1 alc /* 245 1.1 alc * Got everything we need now to setup the capabilities. 246 1.1 alc */ 247 1.1 alc if (!ar5212FillCapabilityInfo(ah)) { 248 1.1 alc HALDEBUG(ah, HAL_DEBUG_ANY, 249 1.1 alc "%s: failed ar5212FillCapabilityInfo\n", __func__); 250 1.1 alc ecode = HAL_EEREAD; 251 1.1 alc goto bad; 252 1.1 alc } 253 1.1 alc 254 1.1 alc if (!rf->attach(ah, &ecode)) { 255 1.1 alc HALDEBUG(ah, HAL_DEBUG_ANY, "%s: RF setup failed, status %u\n", 256 1.1 alc __func__, ecode); 257 1.1 alc goto bad; 258 1.1 alc } 259 1.1 alc /* arrange a direct call instead of thunking */ 260 1.1 alc AH_PRIVATE(ah)->ah_getNfAdjust = ahp->ah_rfHal->getNfAdjust; 261 1.1 alc 262 1.1 alc /* Initialize gain ladder thermal calibration structure */ 263 1.1 alc ar5212InitializeGainValues(ah); 264 1.1 alc 265 1.1 alc /* BSP specific call for MAC address of this WMAC device */ 266 1.1 alc if (!ar5312GetMacAddr(ah)) { 267 1.1 alc ecode = HAL_EEBADMAC; 268 1.1 alc goto bad; 269 1.1 alc } 270 1.1 alc 271 1.1 alc ar5312AniSetup(ah); 272 1.1 alc ar5212InitNfCalHistBuffer(ah); 273 1.1 alc 274 1.1 alc /* XXX EAR stuff goes here */ 275 1.1 alc return ah; 276 1.1 alc 277 1.1 alc bad: 278 1.1 alc if (ahp) 279 1.1 alc ar5212Detach((struct ath_hal *) ahp); 280 1.1 alc if (status) 281 1.1 alc *status = ecode; 282 1.1 alc return AH_NULL; 283 1.1 alc } 284 1.1 alc 285 1.1 alc static HAL_BOOL 286 1.1 alc ar5312GetMacAddr(struct ath_hal *ah) 287 1.1 alc { 288 1.1 alc const struct ar531x_boarddata *board = AR5312_BOARDCONFIG(ah); 289 1.1 alc int wlanNum = AR5312_UNIT(ah); 290 1.1 alc const uint8_t *macAddr; 291 1.1 alc 292 1.1 alc switch (wlanNum) { 293 1.1 alc case 0: 294 1.1 alc macAddr = board->wlan0Mac; 295 1.1 alc break; 296 1.1 alc case 1: 297 1.1 alc macAddr = board->wlan1Mac; 298 1.1 alc break; 299 1.1 alc default: 300 1.1 alc #ifdef AH_DEBUG 301 1.1 alc ath_hal_printf(ah, "Invalid WLAN wmac index (%d)\n", 302 1.1 alc wlanNum); 303 1.1 alc #endif 304 1.1 alc return AH_FALSE; 305 1.1 alc } 306 1.1 alc OS_MEMCPY(AH5212(ah)->ah_macaddr, macAddr, 6); 307 1.1 alc return AH_TRUE; 308 1.1 alc } 309 1.1 alc 310 1.1 alc static const char* 311 1.1 alc ar5312Probe(uint16_t vendorid, uint16_t devid) 312 1.1 alc { 313 1.1 alc if (vendorid == ATHEROS_VENDOR_ID) { 314 1.1 alc switch (devid) { 315 1.1 alc case AR5212_AR5312_REV2: 316 1.1 alc case AR5212_AR5312_REV7: 317 1.1 alc return "Atheros 5312 WiSoC"; 318 1.1 alc case AR5212_AR2313_REV8: 319 1.1 alc return "Atheros 2313 WiSoC"; 320 1.1 alc case AR5212_AR2315_REV6: 321 1.1 alc case AR5212_AR2315_REV7: 322 1.1 alc return "Atheros 2315 WiSoC"; 323 1.1 alc case AR5212_AR2317_REV1: 324 1.3 cegger case AR5212_AR2317_REV2: 325 1.1 alc return "Atheros 2317 WiSoC"; 326 1.1 alc case AR5212_AR2413: 327 1.1 alc return "Atheros 2413"; 328 1.1 alc case AR5212_AR2417: 329 1.1 alc return "Atheros 2417"; 330 1.1 alc } 331 1.1 alc } 332 1.1 alc return AH_NULL; 333 1.1 alc } 334 1.1 alc AH_CHIP(AR5312, ar5312Probe, ar5312Attach); 335