FreeBSD kernel ATH device code
ar5211_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-2006 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 "
ar5211/ar5211.h
"
27
#include "
ar5211/ar5211reg.h
"
28
#include "
ar5211/ar5211desc.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
40
ar5211SetPowerModeAwake
(
struct
ath_hal
*ah,
int
setChip)
41
{
42
#define POWER_UP_TIME 2000
43
uint32_t val;
44
int
i;
45
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 */
49
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
);
57
}
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
;
64
}
65
}
66
67
OS_REG_CLR_BIT
(ah,
AR_STA_ID1
,
AR_STA_ID1_PWR_SAV
);
68
return
AH_TRUE
;
69
#undef POWER_UP_TIME
70
}
71
72
/*
73
* Notify Power Mgt is disabled in self-generated frames.
74
* If requested, force chip to sleep.
75
*/
76
static
void
77
ar5211SetPowerModeSleep
(
struct
ath_hal
*ah,
int
setChip)
78
{
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
);
82
}
83
84
/*
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).
88
*/
89
static
void
90
ar5211SetPowerModeNetworkSleep
(
struct
ath_hal
*ah,
int
setChip)
91
{
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
);
95
}
96
97
HAL_BOOL
98
ar5211SetPowerMode
(
struct
ath_hal
*ah,
HAL_POWER_MODE
mode,
int
setChip)
99
{
100
#ifdef AH_DEBUG
101
static
const
char
*
modes
[] = {
102
"AWAKE"
,
103
"FULL-SLEEP"
,
104
"NETWORK SLEEP"
,
105
"UNDEFINED"
106
};
107
#endif
108
int
status =
AH_TRUE
;
109
110
HALDEBUG
(ah,
HAL_DEBUG_POWER
,
"%s: %s -> %s (%s)\n"
, __func__,
111
modes
[ah->
ah_powerMode
],
modes
[mode],
112
setChip ?
"set chip "
:
""
);
113
switch
(mode) {
114
case
HAL_PM_AWAKE
:
115
if
(setChip)
116
ah->
ah_powerMode
= mode;
117
status =
ar5211SetPowerModeAwake
(ah, setChip);
118
break
;
119
case
HAL_PM_FULL_SLEEP
:
120
ar5211SetPowerModeSleep
(ah, setChip);
121
if
(setChip)
122
ah->
ah_powerMode
= mode;
123
break
;
124
case
HAL_PM_NETWORK_SLEEP
:
125
ar5211SetPowerModeNetworkSleep
(ah, setChip);
126
if
(setChip)
127
ah->
ah_powerMode
= mode;
128
break
;
129
default
:
130
HALDEBUG
(ah,
HAL_DEBUG_ANY
,
"%s: unknown power mode %u\n"
,
131
__func__, mode);
132
return
AH_FALSE
;
133
}
134
return
status;
135
}
136
137
HAL_POWER_MODE
138
ar5211GetPowerMode
(
struct
ath_hal
*ah)
139
{
140
/* Just so happens the h/w maps directly to the abstracted value */
141
return
MS
(
OS_REG_READ
(ah,
AR_SCR
),
AR_SCR_SLE
);
142
}
ah.h
HAL_POWER_MODE
HAL_POWER_MODE
Definition:
ah.h:439
HAL_PM_NETWORK_SLEEP
@ HAL_PM_NETWORK_SLEEP
Definition:
ah.h:442
HAL_PM_AWAKE
@ HAL_PM_AWAKE
Definition:
ah.h:440
HAL_PM_FULL_SLEEP
@ HAL_PM_FULL_SLEEP
Definition:
ah.h:441
HAL_BOOL
HAL_BOOL
Definition:
ah.h:93
AH_FALSE
@ AH_FALSE
Definition:
ah.h:94
AH_TRUE
@ AH_TRUE
Definition:
ah.h:95
HAL_DEBUG_ANY
@ HAL_DEBUG_ANY
Definition:
ah_debug.h:62
HAL_DEBUG_POWER
@ HAL_DEBUG_POWER
Definition:
ah_debug.h:46
ah_internal.h
OS_REG_SET_BIT
#define OS_REG_SET_BIT(_a, _r, _f)
Definition:
ah_internal.h:594
MS
#define MS(_v, _f)
Definition:
ah_internal.h:588
OS_REG_CLR_BIT
#define OS_REG_CLR_BIT(_a, _r, _f)
Definition:
ah_internal.h:596
OS_REG_RMW_FIELD
#define OS_REG_RMW_FIELD(_a, _r, _f, _v)
Definition:
ah_internal.h:591
HALDEBUG
#define HALDEBUG(_ah, __m,...)
Definition:
ah_internal.h:658
ath_hal_printf
void ath_hal_printf(struct ath_hal *, const char *,...)
Definition:
ah_osdep.c:80
OS_DELAY
#define OS_DELAY(_n)
Definition:
ah_osdep.h:69
OS_REG_READ
#define OS_REG_READ(_ah, _reg)
Definition:
ah_osdep.h:140
modes
static const struct cmode modes[]
Definition:
ah_regdomain.c:103
AR_SCR
#define AR_SCR
Definition:
ar5210reg.h:56
AR_SCR_SLE_SLP
#define AR_SCR_SLE_SLP
Definition:
ar5210reg.h:262
AR_PCICFG_SPWR_DN
#define AR_PCICFG_SPWR_DN
Definition:
ar5210reg.h:278
AR_STA_ID1
#define AR_STA_ID1
Definition:
ar5210reg.h:71
AR_PCICFG
#define AR_PCICFG
Definition:
ar5210reg.h:59
AR_SCR_SLE
#define AR_SCR_SLE
Definition:
ar5210reg.h:248
AR_SCR_SLE_WAKE
#define AR_SCR_SLE_WAKE
Definition:
ar5210reg.h:261
ar5211.h
ar5211SetPowerModeAwake
static HAL_BOOL ar5211SetPowerModeAwake(struct ath_hal *ah, int setChip)
Definition:
ar5211_power.c:40
ar5211SetPowerMode
HAL_BOOL ar5211SetPowerMode(struct ath_hal *ah, HAL_POWER_MODE mode, int setChip)
Definition:
ar5211_power.c:98
ar5211SetPowerModeNetworkSleep
static void ar5211SetPowerModeNetworkSleep(struct ath_hal *ah, int setChip)
Definition:
ar5211_power.c:90
POWER_UP_TIME
#define POWER_UP_TIME
ar5211SetPowerModeSleep
static void ar5211SetPowerModeSleep(struct ath_hal *ah, int setChip)
Definition:
ar5211_power.c:77
ar5211GetPowerMode
HAL_POWER_MODE ar5211GetPowerMode(struct ath_hal *ah)
Definition:
ar5211_power.c:138
ar5211desc.h
ar5211reg.h
AR_STA_ID1_PWR_SAV
#define AR_STA_ID1_PWR_SAV
Definition:
ar5211reg.h:763
AR_SCR_SLE_NORM
#define AR_SCR_SLE_NORM
Definition:
ar5211reg.h:634
ath_hal
Definition:
ah.h:1219
ath_hal::ah_powerMode
HAL_POWER_MODE ah_powerMode
Definition:
ah.h:1241
dev
ath
ath_hal
ar5211
ar5211_power.c
Generated by
1.9.3