FreeBSD kernel ATH device code
ar5212_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 "ar5212/ar5212.h"
27#include "ar5212/ar5212reg.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 */
39static HAL_BOOL
40ar5212SetPowerModeAwake(struct ath_hal *ah, int setChip)
41{
42#define AR_SCR_MASK \
43 (AR_SCR_SLDUR|AR_SCR_SLE|AR_SCR_SLDTP|AR_SCR_SLDWP|\
44 AR_SCR_SLEPOL|AR_SCR_MIBIE|AR_SCR_UNKNOWN)
45#define POWER_UP_TIME 2000
46 uint32_t scr, val;
47 int i;
48
49 if (setChip) {
50 /*
51 * Be careful setting the AWAKE mode. When we are called
52 * with the chip powered down the read returns 0xffffffff
53 * which when blindly written back with OS_REG_RMW_FIELD
54 * enables the MIB interrupt for the sleep performance
55 * counters. This can result in an interrupt storm when
56 * ANI is in operation as no one knows to turn off the MIB
57 * interrupt cause.
58 */
59 scr = OS_REG_READ(ah, AR_SCR);
60 if (scr & ~AR_SCR_MASK) {
62 "%s: bogus SCR 0x%x, PCICFG 0x%x\n",
63 __func__, scr, OS_REG_READ(ah, AR_PCICFG));
64 scr = 0;
65 }
66 scr = (scr &~ AR_SCR_SLE) | AR_SCR_SLE_WAKE;
67 OS_REG_WRITE(ah, AR_SCR, scr);
68 OS_DELAY(10); /* Give chip the chance to awake */
69
70 for (i = POWER_UP_TIME / 50; i != 0; i--) {
71 val = OS_REG_READ(ah, AR_PCICFG);
72 if ((val & AR_PCICFG_SPWR_DN) == 0)
73 break;
74 OS_DELAY(50);
75 OS_REG_WRITE(ah, AR_SCR, scr);
76 }
77 if (i == 0) {
78#ifdef AH_DEBUG
79 ath_hal_printf(ah, "%s: Failed to wakeup in %ums\n",
80 __func__, POWER_UP_TIME/50);
81#endif
82 return AH_FALSE;
83 }
84 }
85
87 return AH_TRUE;
88#undef POWER_UP_TIME
89#undef AR_SCR_MASK
90}
91
92/*
93 * Notify Power Mgt is disabled in self-generated frames.
94 * If requested, force chip to sleep.
95 */
96static void
97ar5212SetPowerModeSleep(struct ath_hal *ah, int setChip)
98{
100 if (setChip)
102}
103
104/*
105 * Notify Power Management is enabled in self-generating
106 * fames. If request, set power mode of chip to
107 * auto/normal. Duration in units of 128us (1/8 TU).
108 */
109static void
111{
113 if (setChip)
115}
116
117/*
118 * Set power mgt to the requested mode, and conditionally set
119 * the chip as well
120 */
122ar5212SetPowerMode(struct ath_hal *ah, HAL_POWER_MODE mode, int setChip)
123{
124#ifdef AH_DEBUG
125 static const char* modes[] = {
126 "AWAKE",
127 "FULL-SLEEP",
128 "NETWORK SLEEP",
129 "UNDEFINED"
130 };
131#endif
132 int status = AH_TRUE;
133
134 HALDEBUG(ah, HAL_DEBUG_POWER, "%s: %s -> %s (%s)\n", __func__,
135 modes[ah->ah_powerMode], modes[mode],
136 setChip ? "set chip " : "");
137 switch (mode) {
138 case HAL_PM_AWAKE:
139 if (setChip)
140 ah->ah_powerMode = mode;
141 status = ar5212SetPowerModeAwake(ah, setChip);
142 break;
144 ar5212SetPowerModeSleep(ah, setChip);
145 if (setChip)
146 ah->ah_powerMode = mode;
147 break;
150 if (setChip)
151 ah->ah_powerMode = mode;
152 break;
153 default:
154 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: unknown power mode %u\n",
155 __func__, mode);
156 return AH_FALSE;
157 }
158 return status;
159}
160
161/*
162 * Return the current sleep mode of the chip
163 */
166{
167 /* Just so happens the h/w maps directly to the abstracted value */
168 return MS(OS_REG_READ(ah, AR_SCR), AR_SCR_SLE);
169}
170
171#if 0
172/*
173 * Return the current sleep state of the chip
174 * TRUE = sleeping
175 */
178{
179 return (OS_REG_READ(ah, AR_PCICFG) & AR_PCICFG_SPWR_DN) != 0;
180}
181#endif
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_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 MS(_v, _f)
Definition: ah_internal.h:588
#define OS_REG_CLR_BIT(_a, _r, _f)
Definition: ah_internal.h:596
#define OS_REG_RMW_FIELD(_a, _r, _f, _v)
Definition: ah_internal.h:591
#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_SCR
Definition: ar5210reg.h:56
#define AR_SCR_SLE_SLP
Definition: ar5210reg.h:262
#define AR_PCICFG_SPWR_DN
Definition: ar5210reg.h:278
#define AR_STA_ID1
Definition: ar5210reg.h:71
#define AR_PCICFG
Definition: ar5210reg.h:59
#define AR_SCR_SLE
Definition: ar5210reg.h:248
#define AR_SCR_SLE_WAKE
Definition: ar5210reg.h:261
#define AR_STA_ID1_PWR_SAV
Definition: ar5211reg.h:763
#define AR_SCR_SLE_NORM
Definition: ar5211reg.h:634
HAL_BOOL ar5212GetPowerStatus(struct ath_hal *ah)
static void ar5212SetPowerModeNetworkSleep(struct ath_hal *ah, int setChip)
Definition: ar5212_power.c:110
static void ar5212SetPowerModeSleep(struct ath_hal *ah, int setChip)
Definition: ar5212_power.c:97
HAL_BOOL ar5212SetPowerMode(struct ath_hal *ah, HAL_POWER_MODE mode, int setChip)
Definition: ar5212_power.c:122
HAL_POWER_MODE ar5212GetPowerMode(struct ath_hal *ah)
Definition: ar5212_power.c:165
#define POWER_UP_TIME
static HAL_BOOL ar5212SetPowerModeAwake(struct ath_hal *ah, int setChip)
Definition: ar5212_power.c:40
#define AR_SCR_MASK
Definition: ah.h:1219
HAL_POWER_MODE ah_powerMode
Definition: ah.h:1241