2 * SPDX-License-Identifier: ISC
4 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
5 * Copyright (c) 2002-2008 Atheros Communications, Inc.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 #include "ah_internal.h"
26 #include "ar5416/ar5416.h"
27 #include "ar5416/ar5416reg.h"
30 * Notify Power Mgt is enabled in self-generated frames.
31 * If requested, force chip awake.
33 * Returns A_OK if chip is awake or successfully forced awake.
35 * WARNING WARNING WARNING
36 * There is a problem with the chip where sometimes it will not wake up.
39 ar5416SetPowerModeAwake(struct ath_hal *ah, int setChip)
41 #define POWER_UP_TIME 200000
47 * Do a Power-On-Reset if OWL is shutdown
48 * the NetBSD driver power-cycles the Cardbus slot
49 * as part of the reset procedure.
51 if ((OS_REG_READ(ah, AR_RTC_STATUS)
52 & AR_RTC_PM_STATUS_M) == AR_RTC_STATUS_SHUTDOWN) {
53 if (!ar5416SetResetReg(ah, HAL_RESET_POWER_ON))
55 AH5416(ah)->ah_initPLL(ah, AH_NULL);
59 OS_REG_SET_BIT(ah, AR_RTC_RESET, AR_RTC_RESET_EN);
61 OS_REG_SET_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
65 OS_DELAY(50); /* Give chip the chance to awake */
67 for (i = POWER_UP_TIME / 50; i != 0; i--) {
68 val = OS_REG_READ(ah, AR_RTC_STATUS) & AR_RTC_STATUS_M;
69 if (val == AR_RTC_STATUS_ON)
72 OS_REG_SET_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
77 ath_hal_printf(ah, "%s: Failed to wakeup in %ums\n",
78 __func__, POWER_UP_TIME/1000);
84 OS_REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
90 * Notify Power Mgt is disabled in self-generated frames.
91 * If requested, force chip to sleep.
94 ar5416SetPowerModeSleep(struct ath_hal *ah, int setChip)
96 OS_REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
98 /* Clear the RTC force wake bit to allow the mac to sleep */
99 OS_REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
100 if (! AR_SREV_HOWL(ah))
101 OS_REG_WRITE(ah, AR_RC, AR_RC_AHB|AR_RC_HOSTIF);
102 /* Shutdown chip. Active low */
103 if (! AR_SREV_OWL(ah))
104 OS_REG_CLR_BIT(ah, AR_RTC_RESET, AR_RTC_RESET_EN);
109 * Notify Power Management is enabled in self-generating
110 * fames. If request, set power mode of chip to
111 * auto/normal. Duration in units of 128us (1/8 TU).
114 ar5416SetPowerModeNetworkSleep(struct ath_hal *ah, int setChip)
116 OS_REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
119 OS_REG_CLR_BIT(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN);
123 * Set power mgt to the requested mode, and conditionally set
127 ar5416SetPowerMode(struct ath_hal *ah, HAL_POWER_MODE mode, int setChip)
130 static const char* modes[] = {
137 int status = AH_TRUE;
144 HALDEBUG(ah, HAL_DEBUG_POWER, "%s: %s -> %s (%s)\n", __func__,
145 modes[ah->ah_powerMode], modes[mode], setChip ? "set chip " : "");
149 ah->ah_powerMode = mode;
150 status = ar5416SetPowerModeAwake(ah, setChip);
152 case HAL_PM_FULL_SLEEP:
153 ar5416SetPowerModeSleep(ah, setChip);
155 ah->ah_powerMode = mode;
157 case HAL_PM_NETWORK_SLEEP:
158 ar5416SetPowerModeNetworkSleep(ah, setChip);
160 ah->ah_powerMode = mode;
163 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: unknown power mode 0x%x\n",
171 * Return the current sleep mode of the chip
174 ar5416GetPowerMode(struct ath_hal *ah)
176 int mode = OS_REG_READ(ah, AR_RTC_STATUS);
177 switch (mode & AR_RTC_PM_STATUS_M) {
178 case AR_RTC_STATUS_ON:
179 case AR_RTC_STATUS_WAKEUP:
181 case AR_RTC_STATUS_SLEEP:
182 return HAL_PM_NETWORK_SLEEP;
183 case AR_RTC_STATUS_SHUTDOWN:
184 return HAL_PM_FULL_SLEEP;
186 HALDEBUG(ah, HAL_DEBUG_ANY,
187 "%s: unknown power mode, RTC_STATUS 0x%x\n",
189 return HAL_PM_UNDEFINED;