xref: /freebsd/sys/dev/ath/ath_hal/ar5312/ar5312_power.c (revision b9f654b163bce26de79705e77b872427c9f2afa1)
1 /*-
2  * SPDX-License-Identifier: ISC
3  *
4  * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
5  * Copyright (c) 2002-2008 Atheros Communications, Inc.
6  *
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.
10  *
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.
18  *
19  * $FreeBSD$
20  */
21 #include "opt_ah.h"
22 
23 #ifdef AH_SUPPORT_AR5312
24 
25 #include "ah.h"
26 #include "ah_internal.h"
27 
28 #include "ar5312/ar5312.h"
29 #include "ar5312/ar5312reg.h"
30 #include "ar5212/ar5212desc.h"
31 
32 /*
33  * Notify Power Mgt is enabled in self-generated frames.
34  * If requested, force chip awake.
35  *
36  * Returns A_OK if chip is awake or successfully forced awake.
37  *
38  * WARNING WARNING WARNING
39  * There is a problem with the chip where sometimes it will not wake up.
40  */
41 static HAL_BOOL
42 ar5312SetPowerModeAwake(struct ath_hal *ah, int setChip)
43 {
44         /* No need for this at the moment for APs */
45 	return AH_TRUE;
46 }
47 
48 /*
49  * Notify Power Mgt is disabled in self-generated frames.
50  * If requested, force chip to sleep.
51  */
52 static void
53 ar5312SetPowerModeSleep(struct ath_hal *ah, int setChip)
54 {
55         /* No need for this at the moment for APs */
56 }
57 
58 /*
59  * Notify Power Management is enabled in self-generating
60  * fames.  If request, set power mode of chip to
61  * auto/normal.  Duration in units of 128us (1/8 TU).
62  */
63 static void
64 ar5312SetPowerModeNetworkSleep(struct ath_hal *ah, int setChip)
65 {
66         /* No need for this at the moment for APs */
67 }
68 
69 /*
70  * Set power mgt to the requested mode, and conditionally set
71  * the chip as well
72  */
73 HAL_BOOL
74 ar5312SetPowerMode(struct ath_hal *ah, HAL_POWER_MODE mode, int setChip)
75 {
76 #ifdef AH_DEBUG
77 	static const char* modes[] = {
78 		"AWAKE",
79 		"FULL-SLEEP",
80 		"NETWORK SLEEP",
81 		"UNDEFINED"
82 	};
83 #endif
84 	int status = AH_TRUE;
85 
86 	HALDEBUG(ah, HAL_DEBUG_POWER, "%s: %s -> %s (%s)\n", __func__,
87 		modes[ah->ah_powerMode], modes[mode],
88 		setChip ? "set chip " : "");
89 	switch (mode) {
90 	case HAL_PM_AWAKE:
91 		status = ar5312SetPowerModeAwake(ah, setChip);
92 		break;
93 	case HAL_PM_FULL_SLEEP:
94 		ar5312SetPowerModeSleep(ah, setChip);
95 		break;
96 	case HAL_PM_NETWORK_SLEEP:
97 		ar5312SetPowerModeNetworkSleep(ah, setChip);
98 		break;
99 	default:
100 		HALDEBUG(ah, HAL_DEBUG_POWER, "%s: unknown power mode %u\n",
101 		    __func__, mode);
102 		return AH_FALSE;
103 	}
104 	ah->ah_powerMode = mode;
105 	return status;
106 }
107 
108 /*
109  * Return the current sleep mode of the chip
110  */
111 uint32_t
112 ar5312GetPowerMode(struct ath_hal *ah)
113 {
114 	return HAL_PM_AWAKE;
115 }
116 
117 /*
118  * Return the current sleep state of the chip
119  * TRUE = sleeping
120  */
121 HAL_BOOL
122 ar5312GetPowerStatus(struct ath_hal *ah)
123 {
124         return 0;		/* Currently, 5312 is never in sleep mode. */
125 }
126 #endif /* AH_SUPPORT_AR5312 */
127