Added two wireless drivers: atheros5000.device and realtek8180.device.
[AROS.git] / workbench / devs / networks / atheros5000 / hal / ar5211 / ar5211_power.c
blob177ebcbff542e1a1fed7bd8567cc926124a199f7
1 /*
2 * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3 * Copyright (c) 2002-2006 Atheros Communications, Inc.
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.
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.
17 * $Id$
19 #include "opt_ah.h"
21 #ifdef AH_SUPPORT_AR5211
23 #include "ah.h"
24 #include "ah_internal.h"
26 #include "ar5211/ar5211.h"
27 #include "ar5211/ar5211reg.h"
28 #include "ar5211/ar5211desc.h"
31 * Notify Power Mgt is enabled in self-generated frames.
32 * If requested, force chip awake.
34 * Returns A_OK if chip is awake or successfully forced awake.
36 * WARNING WARNING WARNING
37 * There is a problem with the chip where sometimes it will not wake up.
39 static HAL_BOOL
40 ar5211SetPowerModeAwake(struct ath_hal *ah, int setChip)
42 #define POWER_UP_TIME 2000
43 uint32_t val;
44 int i;
46 if (setChip) {
47 OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLE, AR_SCR_SLE_WAKE);
48 OS_DELAY(10); /* Give chip the chance to awake */
50 for (i = POWER_UP_TIME / 200; i != 0; i--) {
51 val = OS_REG_READ(ah, AR_PCICFG);
52 if ((val & AR_PCICFG_SPWR_DN) == 0)
53 break;
54 OS_DELAY(200);
55 OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLE,
56 AR_SCR_SLE_WAKE);
58 if (i == 0) {
59 #ifdef AH_DEBUG
60 ath_hal_printf(ah, "%s: Failed to wakeup in %ums\n",
61 __func__, POWER_UP_TIME/20);
62 #endif
63 return AH_FALSE;
67 OS_REG_CLR_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
68 return AH_TRUE;
69 #undef POWER_UP_TIME
73 * Notify Power Mgt is disabled in self-generated frames.
74 * If requested, force chip to sleep.
76 static void
77 ar5211SetPowerModeSleep(struct ath_hal *ah, int setChip)
79 OS_REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
80 if (setChip)
81 OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLE, AR_SCR_SLE_SLP);
85 * Notify Power Management is enabled in self-generating
86 * fames. If request, set power mode of chip to
87 * auto/normal. Duration in units of 128us (1/8 TU).
89 static void
90 ar5211SetPowerModeNetworkSleep(struct ath_hal *ah, int setChip)
92 OS_REG_SET_BIT(ah, AR_STA_ID1, AR_STA_ID1_PWR_SAV);
93 if (setChip)
94 OS_REG_RMW_FIELD(ah, AR_SCR, AR_SCR_SLE, AR_SCR_SLE_NORM);
97 HAL_BOOL
98 ar5211SetPowerMode(struct ath_hal *ah, HAL_POWER_MODE mode, int setChip)
100 struct ath_hal_5211 *ahp = AH5211(ah);
101 #ifdef AH_DEBUG
102 static const char* modes[] = {
103 "AWAKE",
104 "FULL-SLEEP",
105 "NETWORK SLEEP",
106 "UNDEFINED"
108 #endif
109 int status = AH_TRUE;
111 HALDEBUG(ah, HAL_DEBUG_POWER, "%s: %s -> %s (%s)\n", __func__,
112 modes[ahp->ah_powerMode], modes[mode],
113 setChip ? "set chip " : "");
114 switch (mode) {
115 case HAL_PM_AWAKE:
116 status = ar5211SetPowerModeAwake(ah, setChip);
117 break;
118 case HAL_PM_FULL_SLEEP:
119 ar5211SetPowerModeSleep(ah, setChip);
120 break;
121 case HAL_PM_NETWORK_SLEEP:
122 ar5211SetPowerModeNetworkSleep(ah, setChip);
123 break;
124 default:
125 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: unknown power mode %u\n",
126 __func__, mode);
127 return AH_FALSE;
129 ahp->ah_powerMode = mode;
130 return status;
133 HAL_POWER_MODE
134 ar5211GetPowerMode(struct ath_hal *ah)
136 /* Just so happens the h/w maps directly to the abstracted value */
137 return MS(OS_REG_READ(ah, AR_SCR), AR_SCR_SLE);
139 #endif /* AH_SUPPORT_AR5211 */