xref: /dflybsd-src/sys/dev/netif/ath/ath_hal/ar5312/ar5312_power.c (revision d98a0bcf56cb1796ee67614a3ca0c005424745ef)
1572ff6f6SMatthew Dillon /*
2572ff6f6SMatthew Dillon  * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3572ff6f6SMatthew Dillon  * Copyright (c) 2002-2008 Atheros Communications, Inc.
4572ff6f6SMatthew Dillon  *
5572ff6f6SMatthew Dillon  * Permission to use, copy, modify, and/or distribute this software for any
6572ff6f6SMatthew Dillon  * purpose with or without fee is hereby granted, provided that the above
7572ff6f6SMatthew Dillon  * copyright notice and this permission notice appear in all copies.
8572ff6f6SMatthew Dillon  *
9572ff6f6SMatthew Dillon  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10572ff6f6SMatthew Dillon  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11572ff6f6SMatthew Dillon  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12572ff6f6SMatthew Dillon  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13572ff6f6SMatthew Dillon  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14572ff6f6SMatthew Dillon  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15572ff6f6SMatthew Dillon  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16572ff6f6SMatthew Dillon  *
17572ff6f6SMatthew Dillon  * $FreeBSD$
18572ff6f6SMatthew Dillon  */
19572ff6f6SMatthew Dillon #include "opt_ah.h"
20572ff6f6SMatthew Dillon 
21572ff6f6SMatthew Dillon #ifdef AH_SUPPORT_AR5312
22572ff6f6SMatthew Dillon 
23572ff6f6SMatthew Dillon #include "ah.h"
24572ff6f6SMatthew Dillon #include "ah_internal.h"
25572ff6f6SMatthew Dillon 
26572ff6f6SMatthew Dillon #include "ar5312/ar5312.h"
27572ff6f6SMatthew Dillon #include "ar5312/ar5312reg.h"
28572ff6f6SMatthew Dillon #include "ar5212/ar5212desc.h"
29572ff6f6SMatthew Dillon 
30572ff6f6SMatthew Dillon /*
31572ff6f6SMatthew Dillon  * Notify Power Mgt is enabled in self-generated frames.
32572ff6f6SMatthew Dillon  * If requested, force chip awake.
33572ff6f6SMatthew Dillon  *
34572ff6f6SMatthew Dillon  * Returns A_OK if chip is awake or successfully forced awake.
35572ff6f6SMatthew Dillon  *
36572ff6f6SMatthew Dillon  * WARNING WARNING WARNING
37572ff6f6SMatthew Dillon  * There is a problem with the chip where sometimes it will not wake up.
38572ff6f6SMatthew Dillon  */
39572ff6f6SMatthew Dillon static HAL_BOOL
ar5312SetPowerModeAwake(struct ath_hal * ah,int setChip)40572ff6f6SMatthew Dillon ar5312SetPowerModeAwake(struct ath_hal *ah, int setChip)
41572ff6f6SMatthew Dillon {
42572ff6f6SMatthew Dillon         /* No need for this at the moment for APs */
43572ff6f6SMatthew Dillon 	return AH_TRUE;
44572ff6f6SMatthew Dillon }
45572ff6f6SMatthew Dillon 
46572ff6f6SMatthew Dillon /*
47572ff6f6SMatthew Dillon  * Notify Power Mgt is disabled in self-generated frames.
48572ff6f6SMatthew Dillon  * If requested, force chip to sleep.
49572ff6f6SMatthew Dillon  */
50572ff6f6SMatthew Dillon static void
ar5312SetPowerModeSleep(struct ath_hal * ah,int setChip)51572ff6f6SMatthew Dillon ar5312SetPowerModeSleep(struct ath_hal *ah, int setChip)
52572ff6f6SMatthew Dillon {
53572ff6f6SMatthew Dillon         /* No need for this at the moment for APs */
54572ff6f6SMatthew Dillon }
55572ff6f6SMatthew Dillon 
56572ff6f6SMatthew Dillon /*
57572ff6f6SMatthew Dillon  * Notify Power Management is enabled in self-generating
58572ff6f6SMatthew Dillon  * fames.  If request, set power mode of chip to
59572ff6f6SMatthew Dillon  * auto/normal.  Duration in units of 128us (1/8 TU).
60572ff6f6SMatthew Dillon  */
61572ff6f6SMatthew Dillon static void
ar5312SetPowerModeNetworkSleep(struct ath_hal * ah,int setChip)62572ff6f6SMatthew Dillon ar5312SetPowerModeNetworkSleep(struct ath_hal *ah, int setChip)
63572ff6f6SMatthew Dillon {
64572ff6f6SMatthew Dillon         /* No need for this at the moment for APs */
65572ff6f6SMatthew Dillon }
66572ff6f6SMatthew Dillon 
67572ff6f6SMatthew Dillon /*
68572ff6f6SMatthew Dillon  * Set power mgt to the requested mode, and conditionally set
69572ff6f6SMatthew Dillon  * the chip as well
70572ff6f6SMatthew Dillon  */
71572ff6f6SMatthew Dillon HAL_BOOL
ar5312SetPowerMode(struct ath_hal * ah,HAL_POWER_MODE mode,int setChip)72572ff6f6SMatthew Dillon ar5312SetPowerMode(struct ath_hal *ah, HAL_POWER_MODE mode, int setChip)
73572ff6f6SMatthew Dillon {
74572ff6f6SMatthew Dillon #ifdef AH_DEBUG
75572ff6f6SMatthew Dillon 	static const char* modes[] = {
76572ff6f6SMatthew Dillon 		"AWAKE",
77572ff6f6SMatthew Dillon 		"FULL-SLEEP",
78572ff6f6SMatthew Dillon 		"NETWORK SLEEP",
79572ff6f6SMatthew Dillon 		"UNDEFINED"
80572ff6f6SMatthew Dillon 	};
81572ff6f6SMatthew Dillon #endif
82572ff6f6SMatthew Dillon 	int status = AH_TRUE;
83572ff6f6SMatthew Dillon 
84572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_POWER, "%s: %s -> %s (%s)\n", __func__,
85*d98a0bcfSMatthew Dillon 		modes[ah->ah_powerMode], modes[mode],
86572ff6f6SMatthew Dillon 		setChip ? "set chip " : "");
87572ff6f6SMatthew Dillon 	switch (mode) {
88572ff6f6SMatthew Dillon 	case HAL_PM_AWAKE:
89572ff6f6SMatthew Dillon 		status = ar5312SetPowerModeAwake(ah, setChip);
90572ff6f6SMatthew Dillon 		break;
91572ff6f6SMatthew Dillon 	case HAL_PM_FULL_SLEEP:
92572ff6f6SMatthew Dillon 		ar5312SetPowerModeSleep(ah, setChip);
93572ff6f6SMatthew Dillon 		break;
94572ff6f6SMatthew Dillon 	case HAL_PM_NETWORK_SLEEP:
95572ff6f6SMatthew Dillon 		ar5312SetPowerModeNetworkSleep(ah, setChip);
96572ff6f6SMatthew Dillon 		break;
97572ff6f6SMatthew Dillon 	default:
98572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_POWER, "%s: unknown power mode %u\n",
99572ff6f6SMatthew Dillon 		    __func__, mode);
100572ff6f6SMatthew Dillon 		return AH_FALSE;
101572ff6f6SMatthew Dillon 	}
102*d98a0bcfSMatthew Dillon 	ah->ah_powerMode = mode;
103572ff6f6SMatthew Dillon 	return status;
104572ff6f6SMatthew Dillon }
105572ff6f6SMatthew Dillon 
106572ff6f6SMatthew Dillon /*
107572ff6f6SMatthew Dillon  * Return the current sleep mode of the chip
108572ff6f6SMatthew Dillon  */
109572ff6f6SMatthew Dillon uint32_t
ar5312GetPowerMode(struct ath_hal * ah)110572ff6f6SMatthew Dillon ar5312GetPowerMode(struct ath_hal *ah)
111572ff6f6SMatthew Dillon {
112572ff6f6SMatthew Dillon 	return HAL_PM_AWAKE;
113572ff6f6SMatthew Dillon }
114572ff6f6SMatthew Dillon 
115572ff6f6SMatthew Dillon /*
116572ff6f6SMatthew Dillon  * Return the current sleep state of the chip
117572ff6f6SMatthew Dillon  * TRUE = sleeping
118572ff6f6SMatthew Dillon  */
119572ff6f6SMatthew Dillon HAL_BOOL
ar5312GetPowerStatus(struct ath_hal * ah)120572ff6f6SMatthew Dillon ar5312GetPowerStatus(struct ath_hal *ah)
121572ff6f6SMatthew Dillon {
122572ff6f6SMatthew Dillon         return 0;		/* Currently, 5312 is never in sleep mode. */
123572ff6f6SMatthew Dillon }
124572ff6f6SMatthew Dillon #endif /* AH_SUPPORT_AR5312 */
125