xref: /freebsd/sys/dev/ath/ath_hal/ar5312/ar5312_power.c (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1*6e778a7eSPedro F. Giffuni /*-
2*6e778a7eSPedro F. Giffuni  * SPDX-License-Identifier: ISC
3*6e778a7eSPedro F. Giffuni  *
414779705SSam Leffler  * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
514779705SSam Leffler  * Copyright (c) 2002-2008 Atheros Communications, Inc.
614779705SSam Leffler  *
714779705SSam Leffler  * Permission to use, copy, modify, and/or distribute this software for any
814779705SSam Leffler  * purpose with or without fee is hereby granted, provided that the above
914779705SSam Leffler  * copyright notice and this permission notice appear in all copies.
1014779705SSam Leffler  *
1114779705SSam Leffler  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
1214779705SSam Leffler  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
1314779705SSam Leffler  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
1414779705SSam Leffler  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1514779705SSam Leffler  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1614779705SSam Leffler  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1714779705SSam Leffler  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1814779705SSam Leffler  */
1914779705SSam Leffler #include "opt_ah.h"
2014779705SSam Leffler 
2114779705SSam Leffler #ifdef AH_SUPPORT_AR5312
2214779705SSam Leffler 
2314779705SSam Leffler #include "ah.h"
2414779705SSam Leffler #include "ah_internal.h"
2514779705SSam Leffler 
2614779705SSam Leffler #include "ar5312/ar5312.h"
2714779705SSam Leffler #include "ar5312/ar5312reg.h"
2814779705SSam Leffler #include "ar5212/ar5212desc.h"
2914779705SSam Leffler 
3014779705SSam Leffler /*
3114779705SSam Leffler  * Notify Power Mgt is enabled in self-generated frames.
3214779705SSam Leffler  * If requested, force chip awake.
3314779705SSam Leffler  *
3414779705SSam Leffler  * Returns A_OK if chip is awake or successfully forced awake.
3514779705SSam Leffler  *
3614779705SSam Leffler  * WARNING WARNING WARNING
3714779705SSam Leffler  * There is a problem with the chip where sometimes it will not wake up.
3814779705SSam Leffler  */
3914779705SSam Leffler static HAL_BOOL
ar5312SetPowerModeAwake(struct ath_hal * ah,int setChip)4014779705SSam Leffler ar5312SetPowerModeAwake(struct ath_hal *ah, int setChip)
4114779705SSam Leffler {
4214779705SSam Leffler         /* No need for this at the moment for APs */
4314779705SSam Leffler 	return AH_TRUE;
4414779705SSam Leffler }
4514779705SSam Leffler 
4614779705SSam Leffler /*
4714779705SSam Leffler  * Notify Power Mgt is disabled in self-generated frames.
4814779705SSam Leffler  * If requested, force chip to sleep.
4914779705SSam Leffler  */
5014779705SSam Leffler static void
ar5312SetPowerModeSleep(struct ath_hal * ah,int setChip)5114779705SSam Leffler ar5312SetPowerModeSleep(struct ath_hal *ah, int setChip)
5214779705SSam Leffler {
5314779705SSam Leffler         /* No need for this at the moment for APs */
5414779705SSam Leffler }
5514779705SSam Leffler 
5614779705SSam Leffler /*
5714779705SSam Leffler  * Notify Power Management is enabled in self-generating
5814779705SSam Leffler  * fames.  If request, set power mode of chip to
5914779705SSam Leffler  * auto/normal.  Duration in units of 128us (1/8 TU).
6014779705SSam Leffler  */
6114779705SSam Leffler static void
ar5312SetPowerModeNetworkSleep(struct ath_hal * ah,int setChip)6214779705SSam Leffler ar5312SetPowerModeNetworkSleep(struct ath_hal *ah, int setChip)
6314779705SSam Leffler {
6414779705SSam Leffler         /* No need for this at the moment for APs */
6514779705SSam Leffler }
6614779705SSam Leffler 
6714779705SSam Leffler /*
6814779705SSam Leffler  * Set power mgt to the requested mode, and conditionally set
6914779705SSam Leffler  * the chip as well
7014779705SSam Leffler  */
7114779705SSam Leffler HAL_BOOL
ar5312SetPowerMode(struct ath_hal * ah,HAL_POWER_MODE mode,int setChip)7214779705SSam Leffler ar5312SetPowerMode(struct ath_hal *ah, HAL_POWER_MODE mode, int setChip)
7314779705SSam Leffler {
7414779705SSam Leffler #ifdef AH_DEBUG
7514779705SSam Leffler 	static const char* modes[] = {
7614779705SSam Leffler 		"AWAKE",
7714779705SSam Leffler 		"FULL-SLEEP",
7814779705SSam Leffler 		"NETWORK SLEEP",
7914779705SSam Leffler 		"UNDEFINED"
8014779705SSam Leffler 	};
8114779705SSam Leffler #endif
8214779705SSam Leffler 	int status = AH_TRUE;
8314779705SSam Leffler 
8414779705SSam Leffler 	HALDEBUG(ah, HAL_DEBUG_POWER, "%s: %s -> %s (%s)\n", __func__,
858a67b42aSAdrian Chadd 		modes[ah->ah_powerMode], modes[mode],
8614779705SSam Leffler 		setChip ? "set chip " : "");
8714779705SSam Leffler 	switch (mode) {
8814779705SSam Leffler 	case HAL_PM_AWAKE:
8914779705SSam Leffler 		status = ar5312SetPowerModeAwake(ah, setChip);
9014779705SSam Leffler 		break;
9114779705SSam Leffler 	case HAL_PM_FULL_SLEEP:
9214779705SSam Leffler 		ar5312SetPowerModeSleep(ah, setChip);
9314779705SSam Leffler 		break;
9414779705SSam Leffler 	case HAL_PM_NETWORK_SLEEP:
9514779705SSam Leffler 		ar5312SetPowerModeNetworkSleep(ah, setChip);
9614779705SSam Leffler 		break;
9714779705SSam Leffler 	default:
9814779705SSam Leffler 		HALDEBUG(ah, HAL_DEBUG_POWER, "%s: unknown power mode %u\n",
9914779705SSam Leffler 		    __func__, mode);
10014779705SSam Leffler 		return AH_FALSE;
10114779705SSam Leffler 	}
1028a67b42aSAdrian Chadd 	ah->ah_powerMode = mode;
10314779705SSam Leffler 	return status;
10414779705SSam Leffler }
10514779705SSam Leffler 
10614779705SSam Leffler /*
10714779705SSam Leffler  * Return the current sleep mode of the chip
10814779705SSam Leffler  */
10914779705SSam Leffler uint32_t
ar5312GetPowerMode(struct ath_hal * ah)11014779705SSam Leffler ar5312GetPowerMode(struct ath_hal *ah)
11114779705SSam Leffler {
11214779705SSam Leffler 	return HAL_PM_AWAKE;
11314779705SSam Leffler }
11414779705SSam Leffler 
11514779705SSam Leffler /*
11614779705SSam Leffler  * Return the current sleep state of the chip
11714779705SSam Leffler  * TRUE = sleeping
11814779705SSam Leffler  */
11914779705SSam Leffler HAL_BOOL
ar5312GetPowerStatus(struct ath_hal * ah)12014779705SSam Leffler ar5312GetPowerStatus(struct ath_hal *ah)
12114779705SSam Leffler {
12214779705SSam Leffler         return 0;		/* Currently, 5312 is never in sleep mode. */
12314779705SSam Leffler }
12414779705SSam Leffler #endif /* AH_SUPPORT_AR5312 */
125