Commit | Line | Data |
---|---|---|
2f01a1f5 | 1 | /* |
80301cdc | 2 | * This file is part of wl1251 |
2f01a1f5 KV |
3 | * |
4 | * Copyright (C) 2008 Nokia Corporation | |
5 | * | |
2f01a1f5 KV |
6 | * This program is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU General Public License | |
8 | * version 2 as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, but | |
11 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | * General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
18 | * 02110-1301 USA | |
19 | * | |
20 | */ | |
21 | ||
9bc6772e KV |
22 | #include "reg.h" |
23 | #include "ps.h" | |
24 | #include "cmd.h" | |
25 | #include "io.h" | |
2f01a1f5 | 26 | |
b5a16794 KV |
27 | /* in ms */ |
28 | #define WL1251_WAKEUP_TIMEOUT 100 | |
2f01a1f5 | 29 | |
d5da79ac | 30 | void wl1251_elp_work(struct work_struct *work) |
2f01a1f5 | 31 | { |
d5da79ac JO |
32 | struct delayed_work *dwork; |
33 | struct wl1251 *wl; | |
34 | ||
35 | dwork = container_of(work, struct delayed_work, work); | |
36 | wl = container_of(dwork, struct wl1251, elp_work); | |
37 | ||
38 | wl1251_debug(DEBUG_PSM, "elp work"); | |
39 | ||
40 | mutex_lock(&wl->mutex); | |
41 | ||
a0bbb58b | 42 | if (wl->elp || wl->station_mode == STATION_ACTIVE_MODE) |
d5da79ac | 43 | goto out; |
2f01a1f5 | 44 | |
80301cdc | 45 | wl1251_debug(DEBUG_PSM, "chip to elp"); |
3f9e750d | 46 | wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP); |
2f01a1f5 | 47 | wl->elp = true; |
d5da79ac JO |
48 | |
49 | out: | |
50 | mutex_unlock(&wl->mutex); | |
51 | } | |
52 | ||
53 | #define ELP_ENTRY_DELAY 5 | |
54 | ||
55 | /* Routines to toggle sleep mode while in ELP */ | |
56 | void wl1251_ps_elp_sleep(struct wl1251 *wl) | |
57 | { | |
58 | unsigned long delay; | |
59 | ||
a0bbb58b | 60 | if (wl->station_mode != STATION_ACTIVE_MODE) { |
d5da79ac JO |
61 | delay = msecs_to_jiffies(ELP_ENTRY_DELAY); |
62 | ieee80211_queue_delayed_work(wl->hw, &wl->elp_work, delay); | |
63 | } | |
2f01a1f5 KV |
64 | } |
65 | ||
80301cdc | 66 | int wl1251_ps_elp_wakeup(struct wl1251 *wl) |
2f01a1f5 | 67 | { |
7fa6282a | 68 | unsigned long timeout, start; |
2f01a1f5 KV |
69 | u32 elp_reg; |
70 | ||
02957f92 | 71 | cancel_delayed_work(&wl->elp_work); |
5f6722ee | 72 | |
2f01a1f5 KV |
73 | if (!wl->elp) |
74 | return 0; | |
75 | ||
80301cdc | 76 | wl1251_debug(DEBUG_PSM, "waking up chip from elp"); |
2f01a1f5 | 77 | |
7fa6282a | 78 | start = jiffies; |
80301cdc | 79 | timeout = jiffies + msecs_to_jiffies(WL1251_WAKEUP_TIMEOUT); |
2f01a1f5 | 80 | |
3f9e750d | 81 | wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP); |
2f01a1f5 | 82 | |
3f9e750d | 83 | elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR); |
2f01a1f5 KV |
84 | |
85 | /* | |
86 | * FIXME: we should wait for irq from chip but, as a temporary | |
87 | * solution to simplify locking, let's poll instead | |
88 | */ | |
89 | while (!(elp_reg & ELPCTRL_WLAN_READY)) { | |
90 | if (time_after(jiffies, timeout)) { | |
80301cdc | 91 | wl1251_error("elp wakeup timeout"); |
2f01a1f5 KV |
92 | return -ETIMEDOUT; |
93 | } | |
94 | msleep(1); | |
3f9e750d | 95 | elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR); |
2f01a1f5 KV |
96 | } |
97 | ||
80301cdc | 98 | wl1251_debug(DEBUG_PSM, "wakeup time: %u ms", |
7fa6282a | 99 | jiffies_to_msecs(jiffies - start)); |
2f01a1f5 KV |
100 | |
101 | wl->elp = false; | |
102 | ||
103 | return 0; | |
104 | } | |
105 | ||
a0bbb58b | 106 | int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_station_mode mode) |
2f01a1f5 KV |
107 | { |
108 | int ret; | |
109 | ||
110 | switch (mode) { | |
111 | case STATION_POWER_SAVE_MODE: | |
80301cdc | 112 | wl1251_debug(DEBUG_PSM, "entering psm"); |
4a818922 | 113 | |
6b21a2cd JO |
114 | /* enable beacon filtering */ |
115 | ret = wl1251_acx_beacon_filter_opt(wl, true); | |
116 | if (ret < 0) | |
117 | return ret; | |
118 | ||
4a818922 KV |
119 | ret = wl1251_acx_wake_up_conditions(wl, |
120 | WAKE_UP_EVENT_DTIM_BITMAP, | |
121 | wl->listen_int); | |
122 | if (ret < 0) | |
123 | return ret; | |
124 | ||
c3e334d2 DG |
125 | ret = wl1251_acx_bet_enable(wl, WL1251_ACX_BET_ENABLE, |
126 | WL1251_DEFAULT_BET_CONSECUTIVE); | |
127 | if (ret < 0) | |
128 | return ret; | |
129 | ||
a0bbb58b | 130 | ret = wl1251_cmd_ps_mode(wl, CHIP_POWER_SAVE_MODE); |
2f01a1f5 KV |
131 | if (ret < 0) |
132 | return ret; | |
133 | ||
d0c331af | 134 | ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP); |
2f01a1f5 KV |
135 | if (ret < 0) |
136 | return ret; | |
2f01a1f5 | 137 | break; |
1e5f52de JN |
138 | case STATION_IDLE: |
139 | wl1251_debug(DEBUG_PSM, "entering idle"); | |
140 | ||
141 | ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP); | |
142 | if (ret < 0) | |
143 | return ret; | |
144 | ||
145 | ret = wl1251_cmd_template_set(wl, CMD_DISCONNECT, NULL, 0); | |
146 | if (ret < 0) | |
147 | return ret; | |
148 | break; | |
2f01a1f5 KV |
149 | case STATION_ACTIVE_MODE: |
150 | default: | |
80301cdc | 151 | wl1251_debug(DEBUG_PSM, "leaving psm"); |
d0c331af GI |
152 | |
153 | ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM); | |
2f01a1f5 KV |
154 | if (ret < 0) |
155 | return ret; | |
156 | ||
c3e334d2 DG |
157 | /* disable BET */ |
158 | ret = wl1251_acx_bet_enable(wl, WL1251_ACX_BET_DISABLE, | |
159 | WL1251_DEFAULT_BET_CONSECUTIVE); | |
160 | if (ret < 0) | |
161 | return ret; | |
162 | ||
6b21a2cd JO |
163 | /* disable beacon filtering */ |
164 | ret = wl1251_acx_beacon_filter_opt(wl, false); | |
165 | if (ret < 0) | |
166 | return ret; | |
167 | ||
4a818922 KV |
168 | ret = wl1251_acx_wake_up_conditions(wl, |
169 | WAKE_UP_EVENT_DTIM_BITMAP, | |
170 | wl->listen_int); | |
171 | if (ret < 0) | |
172 | return ret; | |
173 | ||
a0bbb58b | 174 | ret = wl1251_cmd_ps_mode(wl, CHIP_ACTIVE_MODE); |
2f01a1f5 KV |
175 | if (ret < 0) |
176 | return ret; | |
177 | ||
2f01a1f5 KV |
178 | break; |
179 | } | |
a0bbb58b | 180 | wl->station_mode = mode; |
2f01a1f5 KV |
181 | |
182 | return ret; | |
183 | } | |
184 |