1 1.1 alc /* 2 1.1 alc * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting 3 1.1 alc * Copyright (c) 2002-2006 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.1 alc * $Id: ar5211_power.c,v 1.1.1.1 2008/12/11 04:46:32 alc 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 24 1.1 alc #include "ar5211/ar5211.h" 25 1.1 alc #include "ar5211/ar5211reg.h" 26 1.1 alc #include "ar5211/ar5211desc.h" 27 1.1 alc 28 1.1 alc /* 29 1.1 alc * Notify Power Mgt is enabled in self-generated frames. 30 1.1 alc * If requested, force chip awake. 31 1.1 alc * 32 1.1 alc * Returns A_OK if chip is awake or successfully forced awake. 33 1.1 alc * 34 1.1 alc * WARNING WARNING WARNING 35 1.1 alc * There is a problem with the chip where sometimes it will not wake up. 36 1.1 alc */ 37 1.1 alc static HAL_BOOL 38 1.1 alc ar5211SetPowerModeAwake(struct ath_hal *ah, int setChip) 39 1.1 alc { 40 1.1 alc #define POWER_UP_TIME 2000 41 1.1 alc uint32_t val; 42 1.1 alc int i; 43 1.1 alc 44 1.1 alc if (setChip) { 45 1.1 alc OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLE, AR_SCR_SLE_WAKE); 46 1.1 alc OS_DELAY(10); /* Give chip the chance to awake */ 47 1.1 alc 48 1.1 alc for (i = POWER_UP_TIME / 200; i != 0; i--) { 49 1.1 alc val = OS_REG_READ(ah, AR_PCICFG); 50 1.1 alc if ((val & AR_PCICFG_SPWR_DN) == 0) 51 1.1 alc break; 52 1.1 alc OS_DELAY(200); 53 1.1 alc OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLE, 54 1.1 alc AR_SCR_SLE_WAKE); 55 1.1 alc } 56 1.1 alc if (i == 0) { 57 1.1 alc #ifdef AH_DEBUG 58 1.1 alc ath_hal_printf(ah, "%s: Failed to wakeup in %ums\n", 59 1.1 alc __func__, POWER_UP_TIME/20); 60 1.1 alc #endif 61 1.1 alc return AH_FALSE; 62 1.1 alc } 63 1.1 alc } 64 1.1 alc 65 1.1 alc OS_REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); 66 1.1 alc return AH_TRUE; 67 1.1 alc #undef POWER_UP_TIME 68 1.1 alc } 69 1.1 alc 70 1.1 alc /* 71 1.1 alc * Notify Power Mgt is disabled in self-generated frames. 72 1.1 alc * If requested, force chip to sleep. 73 1.1 alc */ 74 1.1 alc static void 75 1.1 alc ar5211SetPowerModeSleep(struct ath_hal *ah, int setChip) 76 1.1 alc { 77 1.1 alc OS_REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); 78 1.1 alc if (setChip) 79 1.1 alc OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLE, AR_SCR_SLE_SLP); 80 1.1 alc } 81 1.1 alc 82 1.1 alc /* 83 1.1 alc * Notify Power Management is enabled in self-generating 84 1.1 alc * fames. If request, set power mode of chip to 85 1.1 alc * auto/normal. Duration in units of 128us (1/8 TU). 86 1.1 alc */ 87 1.1 alc static void 88 1.1 alc ar5211SetPowerModeNetworkSleep(struct ath_hal *ah, int setChip) 89 1.1 alc { 90 1.1 alc OS_REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV); 91 1.1 alc if (setChip) 92 1.1 alc OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLE, AR_SCR_SLE_NORM); 93 1.1 alc } 94 1.1 alc 95 1.1 alc HAL_BOOL 96 1.1 alc ar5211SetPowerMode(struct ath_hal *ah, HAL_POWER_MODE mode, int setChip) 97 1.1 alc { 98 1.1 alc struct ath_hal_5211 *ahp = AH5211(ah); 99 1.1 alc #ifdef AH_DEBUG 100 1.1 alc static const char* modes[] = { 101 1.1 alc "AWAKE", 102 1.1 alc "FULL-SLEEP", 103 1.1 alc "NETWORK SLEEP", 104 1.1 alc "UNDEFINED" 105 1.1 alc }; 106 1.1 alc #endif 107 1.1 alc int status = AH_TRUE; 108 1.1 alc 109 1.1 alc HALDEBUG(ah, HAL_DEBUG_POWER, "%s: %s -> %s (%s)\n", __func__, 110 1.1 alc modes[ahp->ah_powerMode], modes[mode], 111 1.1 alc setChip ? "set chip " : ""); 112 1.1 alc switch (mode) { 113 1.1 alc case HAL_PM_AWAKE: 114 1.1 alc status = ar5211SetPowerModeAwake(ah, setChip); 115 1.1 alc break; 116 1.1 alc case HAL_PM_FULL_SLEEP: 117 1.1 alc ar5211SetPowerModeSleep(ah, setChip); 118 1.1 alc break; 119 1.1 alc case HAL_PM_NETWORK_SLEEP: 120 1.1 alc ar5211SetPowerModeNetworkSleep(ah, setChip); 121 1.1 alc break; 122 1.1 alc default: 123 1.1 alc HALDEBUG(ah, HAL_DEBUG_ANY, "%s: unknown power mode %u\n", 124 1.1 alc __func__, mode); 125 1.1 alc return AH_FALSE; 126 1.1 alc } 127 1.1 alc ahp->ah_powerMode = mode; 128 1.1 alc return status; 129 1.1 alc } 130 1.1 alc 131 1.1 alc HAL_POWER_MODE 132 1.1 alc ar5211GetPowerMode(struct ath_hal *ah) 133 1.1 alc { 134 1.1 alc /* Just so happens the h/w maps directly to the abstracted value */ 135 1.1 alc return MS(OS_REG_READ(ah, AR_SCR), AR_SCR_SLE); 136 1.1 alc } 137