Path: blob/main/sys/dev/ath/ath_hal/ar5211/ar5211_power.c
39566 views
/*-1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2002-2008 Sam Leffler, Errno Consulting4* Copyright (c) 2002-2006 Atheros Communications, Inc.5*6* Permission to use, copy, modify, and/or distribute this software for any7* purpose with or without fee is hereby granted, provided that the above8* copyright notice and this permission notice appear in all copies.9*10* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES11* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF12* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR13* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES14* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN15* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF16* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.17*/18#include "opt_ah.h"1920#include "ah.h"21#include "ah_internal.h"2223#include "ar5211/ar5211.h"24#include "ar5211/ar5211reg.h"25#include "ar5211/ar5211desc.h"2627/*28* Notify Power Mgt is enabled in self-generated frames.29* If requested, force chip awake.30*31* Returns A_OK if chip is awake or successfully forced awake.32*33* WARNING WARNING WARNING34* There is a problem with the chip where sometimes it will not wake up.35*/36static HAL_BOOL37ar5211SetPowerModeAwake(struct ath_hal *ah, int setChip)38{39#define POWER_UP_TIME 200040uint32_t val;41int i;4243if (setChip) {44OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLE, AR_SCR_SLE_WAKE);45OS_DELAY(10); /* Give chip the chance to awake */4647for (i = POWER_UP_TIME / 200; i != 0; i--) {48val = OS_REG_READ(ah, AR_PCICFG);49if ((val & AR_PCICFG_SPWR_DN) == 0)50break;51OS_DELAY(200);52OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLE,53AR_SCR_SLE_WAKE);54}55if (i == 0) {56#ifdef AH_DEBUG57ath_hal_printf(ah, "%s: Failed to wakeup in %ums\n",58__func__, POWER_UP_TIME/20);59#endif60return AH_FALSE;61}62}6364OS_REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);65return AH_TRUE;66#undef POWER_UP_TIME67}6869/*70* Notify Power Mgt is disabled in self-generated frames.71* If requested, force chip to sleep.72*/73static void74ar5211SetPowerModeSleep(struct ath_hal *ah, int setChip)75{76OS_REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);77if (setChip)78OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLE, AR_SCR_SLE_SLP);79}8081/*82* Notify Power Management is enabled in self-generating83* fames. If request, set power mode of chip to84* auto/normal. Duration in units of 128us (1/8 TU).85*/86static void87ar5211SetPowerModeNetworkSleep(struct ath_hal *ah, int setChip)88{89OS_REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);90if (setChip)91OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLE, AR_SCR_SLE_NORM);92}9394HAL_BOOL95ar5211SetPowerMode(struct ath_hal *ah, HAL_POWER_MODE mode, int setChip)96{97#ifdef AH_DEBUG98static const char* modes[] = {99"AWAKE",100"FULL-SLEEP",101"NETWORK SLEEP",102"UNDEFINED"103};104#endif105int status = AH_TRUE;106107HALDEBUG(ah, HAL_DEBUG_POWER, "%s: %s -> %s (%s)\n", __func__,108modes[ah->ah_powerMode], modes[mode],109setChip ? "set chip " : "");110switch (mode) {111case HAL_PM_AWAKE:112if (setChip)113ah->ah_powerMode = mode;114status = ar5211SetPowerModeAwake(ah, setChip);115break;116case HAL_PM_FULL_SLEEP:117ar5211SetPowerModeSleep(ah, setChip);118if (setChip)119ah->ah_powerMode = mode;120break;121case HAL_PM_NETWORK_SLEEP:122ar5211SetPowerModeNetworkSleep(ah, setChip);123if (setChip)124ah->ah_powerMode = mode;125break;126default:127HALDEBUG(ah, HAL_DEBUG_ANY, "%s: unknown power mode %u\n",128__func__, mode);129return AH_FALSE;130}131return status;132}133134HAL_POWER_MODE135ar5211GetPowerMode(struct ath_hal *ah)136{137/* Just so happens the h/w maps directly to the abstracted value */138return MS(OS_REG_READ(ah, AR_SCR), AR_SCR_SLE);139}140141142