Merge tag 'v3.3.7' into 3.3/master
[zen-stable.git] / drivers / net / wireless / wl1251 / ps.c
blobdb719f7d26928c4012a1020a050edbd3a9560980
1 /*
2 * This file is part of wl1251
4 * Copyright (C) 2008 Nokia Corporation
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.
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.
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
22 #include "reg.h"
23 #include "ps.h"
24 #include "cmd.h"
25 #include "io.h"
27 /* in ms */
28 #define WL1251_WAKEUP_TIMEOUT 100
30 void wl1251_elp_work(struct work_struct *work)
32 struct delayed_work *dwork;
33 struct wl1251 *wl;
35 dwork = container_of(work, struct delayed_work, work);
36 wl = container_of(dwork, struct wl1251, elp_work);
38 wl1251_debug(DEBUG_PSM, "elp work");
40 mutex_lock(&wl->mutex);
42 if (wl->elp || wl->station_mode == STATION_ACTIVE_MODE)
43 goto out;
45 wl1251_debug(DEBUG_PSM, "chip to elp");
46 wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
47 wl->elp = true;
49 out:
50 mutex_unlock(&wl->mutex);
53 #define ELP_ENTRY_DELAY 5
55 /* Routines to toggle sleep mode while in ELP */
56 void wl1251_ps_elp_sleep(struct wl1251 *wl)
58 unsigned long delay;
60 if (wl->station_mode != STATION_ACTIVE_MODE) {
61 delay = msecs_to_jiffies(ELP_ENTRY_DELAY);
62 ieee80211_queue_delayed_work(wl->hw, &wl->elp_work, delay);
66 int wl1251_ps_elp_wakeup(struct wl1251 *wl)
68 unsigned long timeout, start;
69 u32 elp_reg;
71 if (delayed_work_pending(&wl->elp_work))
72 cancel_delayed_work(&wl->elp_work);
74 if (!wl->elp)
75 return 0;
77 wl1251_debug(DEBUG_PSM, "waking up chip from elp");
79 start = jiffies;
80 timeout = jiffies + msecs_to_jiffies(WL1251_WAKEUP_TIMEOUT);
82 wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP);
84 elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
87 * FIXME: we should wait for irq from chip but, as a temporary
88 * solution to simplify locking, let's poll instead
90 while (!(elp_reg & ELPCTRL_WLAN_READY)) {
91 if (time_after(jiffies, timeout)) {
92 wl1251_error("elp wakeup timeout");
93 return -ETIMEDOUT;
95 msleep(1);
96 elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
99 wl1251_debug(DEBUG_PSM, "wakeup time: %u ms",
100 jiffies_to_msecs(jiffies - start));
102 wl->elp = false;
104 return 0;
107 int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_station_mode mode)
109 int ret;
111 switch (mode) {
112 case STATION_POWER_SAVE_MODE:
113 wl1251_debug(DEBUG_PSM, "entering psm");
115 /* enable beacon filtering */
116 ret = wl1251_acx_beacon_filter_opt(wl, true);
117 if (ret < 0)
118 return ret;
120 ret = wl1251_acx_wake_up_conditions(wl,
121 WAKE_UP_EVENT_DTIM_BITMAP,
122 wl->listen_int);
123 if (ret < 0)
124 return ret;
126 ret = wl1251_acx_bet_enable(wl, WL1251_ACX_BET_ENABLE,
127 WL1251_DEFAULT_BET_CONSECUTIVE);
128 if (ret < 0)
129 return ret;
131 ret = wl1251_cmd_ps_mode(wl, CHIP_POWER_SAVE_MODE);
132 if (ret < 0)
133 return ret;
135 ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP);
136 if (ret < 0)
137 return ret;
138 break;
139 case STATION_IDLE:
140 wl1251_debug(DEBUG_PSM, "entering idle");
142 ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP);
143 if (ret < 0)
144 return ret;
146 ret = wl1251_cmd_template_set(wl, CMD_DISCONNECT, NULL, 0);
147 if (ret < 0)
148 return ret;
149 break;
150 case STATION_ACTIVE_MODE:
151 default:
152 wl1251_debug(DEBUG_PSM, "leaving psm");
154 ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
155 if (ret < 0)
156 return ret;
158 /* disable BET */
159 ret = wl1251_acx_bet_enable(wl, WL1251_ACX_BET_DISABLE,
160 WL1251_DEFAULT_BET_CONSECUTIVE);
161 if (ret < 0)
162 return ret;
164 /* disable beacon filtering */
165 ret = wl1251_acx_beacon_filter_opt(wl, false);
166 if (ret < 0)
167 return ret;
169 ret = wl1251_acx_wake_up_conditions(wl,
170 WAKE_UP_EVENT_DTIM_BITMAP,
171 wl->listen_int);
172 if (ret < 0)
173 return ret;
175 ret = wl1251_cmd_ps_mode(wl, CHIP_ACTIVE_MODE);
176 if (ret < 0)
177 return ret;
179 break;
181 wl->station_mode = mode;
183 return ret;