FreeBSD kernel ATH device code
ar5416_power.c
Go to the documentation of this file.
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#include "ah.h"
24#include "ah_internal.h"
25
26#include "ar5416/ar5416.h"
27#include "ar5416/ar5416reg.h"
28
29/*
30 * Notify Power Mgt is enabled in self-generated frames.
31 * If requested, force chip awake.
32 *
33 * Returns A_OK if chip is awake or successfully forced awake.
34 *
35 * WARNING WARNING WARNING
36 * There is a problem with the chip where sometimes it will not wake up.
37 */
38static HAL_BOOL
39ar5416SetPowerModeAwake(struct ath_hal *ah, int setChip)
40{
41#define POWER_UP_TIME 200000
42 uint32_t val;
43 int i = 0;
44
45 if (setChip) {
46 /*
47 * Do a Power-On-Reset if OWL is shutdown
48 * the NetBSD driver power-cycles the Cardbus slot
49 * as part of the reset procedure.
50 */
51 if ((OS_REG_READ(ah, AR_RTC_STATUS)
54 goto bad;
55 AH5416(ah)->ah_initPLL(ah, AH_NULL);
56 }
57
58 if (AR_SREV_HOWL(ah))
60
62 if (AR_SREV_HOWL(ah))
63 OS_DELAY(10000);
64 else
65 OS_DELAY(50); /* Give chip the chance to awake */
66
67 for (i = POWER_UP_TIME / 50; i != 0; i--) {
69 if (val == AR_RTC_STATUS_ON)
70 break;
71 OS_DELAY(50);
73 }
74 bad:
75 if (i == 0) {
76#ifdef AH_DEBUG
77 ath_hal_printf(ah, "%s: Failed to wakeup in %ums\n",
78 __func__, POWER_UP_TIME/1000);
79#endif
80 return AH_FALSE;
81 }
82 }
83
85 return AH_TRUE;
86#undef POWER_UP_TIME
87}
88
89/*
90 * Notify Power Mgt is disabled in self-generated frames.
91 * If requested, force chip to sleep.
92 */
93static void
94ar5416SetPowerModeSleep(struct ath_hal *ah, int setChip)
95{
97 if (setChip) {
98 /* Clear the RTC force wake bit to allow the mac to sleep */
100 if (! AR_SREV_HOWL(ah))
102 /* Shutdown chip. Active low */
103 if (! AR_SREV_OWL(ah))
105 }
106}
107
108/*
109 * Notify Power Management is enabled in self-generating
110 * fames. If request, set power mode of chip to
111 * auto/normal. Duration in units of 128us (1/8 TU).
112 */
113static void
115{
117
118 if (setChip)
120}
121
122/*
123 * Set power mgt to the requested mode, and conditionally set
124 * the chip as well
125 */
127ar5416SetPowerMode(struct ath_hal *ah, HAL_POWER_MODE mode, int setChip)
128{
129#ifdef AH_DEBUG
130 static const char* modes[] = {
131 "AWAKE",
132 "FULL-SLEEP",
133 "NETWORK SLEEP",
134 "UNDEFINED"
135 };
136#endif
137 int status = AH_TRUE;
138
139#if 0
140 if (!setChip)
141 return AH_TRUE;
142#endif
143
144 HALDEBUG(ah, HAL_DEBUG_POWER, "%s: %s -> %s (%s)\n", __func__,
145 modes[ah->ah_powerMode], modes[mode], setChip ? "set chip " : "");
146 switch (mode) {
147 case HAL_PM_AWAKE:
148 if (setChip)
149 ah->ah_powerMode = mode;
150 status = ar5416SetPowerModeAwake(ah, setChip);
151 break;
153 ar5416SetPowerModeSleep(ah, setChip);
154 if (setChip)
155 ah->ah_powerMode = mode;
156 break;
159 if (setChip)
160 ah->ah_powerMode = mode;
161 break;
162 default:
163 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: unknown power mode 0x%x\n",
164 __func__, mode);
165 return AH_FALSE;
166 }
167 return status;
168}
169
170/*
171 * Return the current sleep mode of the chip
172 */
175{
176 int mode = OS_REG_READ(ah, AR_RTC_STATUS);
177 switch (mode & AR_RTC_PM_STATUS_M) {
178 case AR_RTC_STATUS_ON:
180 return HAL_PM_AWAKE;
184 return HAL_PM_FULL_SLEEP;
185 default:
187 "%s: unknown power mode, RTC_STATUS 0x%x\n",
188 __func__, mode);
189 return HAL_PM_UNDEFINED;
190 }
191}
HAL_POWER_MODE
Definition: ah.h:439
@ HAL_PM_NETWORK_SLEEP
Definition: ah.h:442
@ HAL_PM_AWAKE
Definition: ah.h:440
@ HAL_PM_FULL_SLEEP
Definition: ah.h:441
@ HAL_PM_UNDEFINED
Definition: ah.h:443
@ HAL_RESET_POWER_ON
Definition: ah.h:778
HAL_BOOL
Definition: ah.h:93
@ AH_FALSE
Definition: ah.h:94
@ AH_TRUE
Definition: ah.h:95
@ HAL_DEBUG_ANY
Definition: ah_debug.h:62
@ HAL_DEBUG_POWER
Definition: ah_debug.h:46
#define OS_REG_SET_BIT(_a, _r, _f)
Definition: ah_internal.h:594
#define OS_REG_CLR_BIT(_a, _r, _f)
Definition: ah_internal.h:596
#define AH_NULL
Definition: ah_internal.h:28
#define HALDEBUG(_ah, __m,...)
Definition: ah_internal.h:658
void ath_hal_printf(struct ath_hal *, const char *,...)
Definition: ah_osdep.c:80
#define OS_DELAY(_n)
Definition: ah_osdep.h:69
#define OS_REG_WRITE(_ah, _reg, _val)
Definition: ah_osdep.h:139
#define OS_REG_READ(_ah, _reg)
Definition: ah_osdep.h:140
static const struct cmode modes[]
Definition: ah_regdomain.c:103
#define AR_STA_ID1
Definition: ar5210reg.h:71
#define AR_RC
Definition: ar5210reg.h:55
#define AR_STA_ID1_PWR_SAV
Definition: ar5211reg.h:763
#define AH5416(_ah)
Definition: ar5416.h:162
HAL_BOOL ar5416SetResetReg(struct ath_hal *, uint32_t type)
static HAL_BOOL ar5416SetPowerModeAwake(struct ath_hal *ah, int setChip)
Definition: ar5416_power.c:39
static void ar5416SetPowerModeNetworkSleep(struct ath_hal *ah, int setChip)
Definition: ar5416_power.c:114
HAL_BOOL ar5416SetPowerMode(struct ath_hal *ah, HAL_POWER_MODE mode, int setChip)
Definition: ar5416_power.c:127
#define POWER_UP_TIME
static void ar5416SetPowerModeSleep(struct ath_hal *ah, int setChip)
Definition: ar5416_power.c:94
HAL_POWER_MODE ar5416GetPowerMode(struct ath_hal *ah)
Definition: ar5416_power.c:174
#define AR_RTC_STATUS_M
Definition: ar5416reg.h:416
#define AR_RC_HOSTIF
Definition: ar5416reg.h:191
#define AR_RTC_RESET_EN
Definition: ar5416reg.h:410
#define AR_RTC_STATUS_SLEEP
Definition: ar5416reg.h:420
#define AR_RTC_FORCE_WAKE_EN
Definition: ar5416reg.h:427
#define AR_RTC_STATUS_WAKEUP
Definition: ar5416reg.h:421
#define AR_RTC_RESET
Definition: ar5416reg.h:113
#define AR_RTC_FORCE_WAKE
Definition: ar5416reg.h:116
#define AR_RC_AHB
Definition: ar5416reg.h:189
#define AR_RTC_STATUS_SHUTDOWN
Definition: ar5416reg.h:418
#define AR_SREV_OWL(_ah)
Definition: ar5416reg.h:702
#define AR_SREV_HOWL(_ah)
Definition: ar5416reg.h:718
#define AR_RTC_STATUS_ON
Definition: ar5416reg.h:419
#define AR_RTC_PM_STATUS_M
Definition: ar5416reg.h:412
#define AR_RTC_STATUS
Definition: ar5416reg.h:114
Definition: ah.h:1219
HAL_POWER_MODE ah_powerMode
Definition: ah.h:1241