1 /*
2  * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3  * Copyright (c) 2002-2008 Atheros Communications, Inc.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  *
17  * $Id: ar5312_power.c,v 1.1.1.1 2008/12/11 04:46:45 alc Exp $
18  */
19 #include "opt_ah.h"
20 
21 #ifdef AH_SUPPORT_AR5312
22 
23 #include "ah.h"
24 #include "ah_internal.h"
25 
26 #include "ar5312/ar5312.h"
27 #include "ar5312/ar5312reg.h"
28 #include "ar5212/ar5212desc.h"
29 
30 /*
31  * Notify Power Mgt is enabled in self-generated frames.
32  * If requested, force chip awake.
33  *
34  * Returns A_OK if chip is awake or successfully forced awake.
35  *
36  * WARNING WARNING WARNING
37  * There is a problem with the chip where sometimes it will not wake up.
38  */
39 static HAL_BOOL
ar5312SetPowerModeAwake(struct ath_hal * ah,int setChip)40 ar5312SetPowerModeAwake(struct ath_hal *ah, int setChip)
41 {
42         /* No need for this at the moment for APs */
43           return AH_TRUE;
44 }
45 
46 /*
47  * Notify Power Mgt is disabled in self-generated frames.
48  * If requested, force chip to sleep.
49  */
50 static void
ar5312SetPowerModeSleep(struct ath_hal * ah,int setChip)51 ar5312SetPowerModeSleep(struct ath_hal *ah, int setChip)
52 {
53         /* No need for this at the moment for APs */
54 }
55 
56 /*
57  * Notify Power Management is enabled in self-generating
58  * fames.  If request, set power mode of chip to
59  * auto/normal.  Duration in units of 128us (1/8 TU).
60  */
61 static void
ar5312SetPowerModeNetworkSleep(struct ath_hal * ah,int setChip)62 ar5312SetPowerModeNetworkSleep(struct ath_hal *ah, int setChip)
63 {
64         /* No need for this at the moment for APs */
65 }
66 
67 /*
68  * Set power mgt to the requested mode, and conditionally set
69  * the chip as well
70  */
71 HAL_BOOL
ar5312SetPowerMode(struct ath_hal * ah,HAL_POWER_MODE mode,int setChip)72 ar5312SetPowerMode(struct ath_hal *ah, HAL_POWER_MODE mode, int setChip)
73 {
74           struct ath_hal_5212 *ahp = AH5212(ah);
75 #ifdef AH_DEBUG
76           static const char* modes[] = {
77                     "AWAKE",
78                     "FULL-SLEEP",
79                     "NETWORK SLEEP",
80                     "UNDEFINED"
81           };
82 #endif
83           int status = AH_TRUE;
84 
85           HALDEBUG(ah, HAL_DEBUG_POWER, "%s: %s -> %s (%s)\n", __func__,
86                     modes[ahp->ah_powerMode], modes[mode],
87                     setChip ? "set chip " : "");
88           switch (mode) {
89           case HAL_PM_AWAKE:
90                     status = ar5312SetPowerModeAwake(ah, setChip);
91                     break;
92           case HAL_PM_FULL_SLEEP:
93                     ar5312SetPowerModeSleep(ah, setChip);
94                     break;
95           case HAL_PM_NETWORK_SLEEP:
96                     ar5312SetPowerModeNetworkSleep(ah, setChip);
97                     break;
98           default:
99                     HALDEBUG(ah, HAL_DEBUG_POWER, "%s: unknown power mode %u\n",
100                         __func__, mode);
101                     return AH_FALSE;
102           }
103           ahp->ah_powerMode = mode;
104           return status;
105 }
106 
107 /*
108  * Return the current sleep mode of the chip
109  */
110 uint32_t
ar5312GetPowerMode(struct ath_hal * ah)111 ar5312GetPowerMode(struct ath_hal *ah)
112 {
113           return HAL_PM_AWAKE;
114 }
115 
116 /*
117  * Return the current sleep state of the chip
118  * TRUE = sleeping
119  */
120 HAL_BOOL
ar5312GetPowerStatus(struct ath_hal * ah)121 ar5312GetPowerStatus(struct ath_hal *ah)
122 {
123         return 0;             /* Currently, 5312 is never in sleep mode. */
124 }
125 #endif /* AH_SUPPORT_AR5312 */
126