2 * This file is part of wl1271
4 * Copyright (C) 2008-2009 Nokia Corporation
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
24 #include "wl1271_reg.h"
25 #include "wl1271_ps.h"
26 #include "wl1271_io.h"
28 #define WL1271_WAKEUP_TIMEOUT 500
30 void wl1271_elp_work(struct work_struct *work)
32 struct delayed_work *dwork;
35 dwork = container_of(work, struct delayed_work, work);
36 wl = container_of(dwork, struct wl1271, elp_work);
38 wl1271_debug(DEBUG_PSM, "elp work");
40 mutex_lock(&wl->mutex);
42 if (unlikely(wl->state == WL1271_STATE_OFF))
45 if (test_bit(WL1271_FLAG_IN_ELP, &wl->flags) ||
46 (!test_bit(WL1271_FLAG_PSM, &wl->flags) &&
47 !test_bit(WL1271_FLAG_IDLE, &wl->flags)))
50 wl1271_debug(DEBUG_PSM, "chip to elp");
51 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
52 set_bit(WL1271_FLAG_IN_ELP, &wl->flags);
55 mutex_unlock(&wl->mutex);
58 #define ELP_ENTRY_DELAY 5
60 /* Routines to toggle sleep mode while in ELP */
61 void wl1271_ps_elp_sleep(struct wl1271 *wl)
63 if (test_bit(WL1271_FLAG_PSM, &wl->flags) ||
64 test_bit(WL1271_FLAG_IDLE, &wl->flags)) {
65 cancel_delayed_work(&wl->elp_work);
66 ieee80211_queue_delayed_work(wl->hw, &wl->elp_work,
67 msecs_to_jiffies(ELP_ENTRY_DELAY));
71 int wl1271_ps_elp_wakeup(struct wl1271 *wl, bool chip_awake)
73 DECLARE_COMPLETION_ONSTACK(compl);
76 u32 start_time = jiffies;
79 if (!test_bit(WL1271_FLAG_IN_ELP, &wl->flags))
82 wl1271_debug(DEBUG_PSM, "waking up chip from elp");
85 * The spinlock is required here to synchronize both the work and
86 * the completion variable in one entity.
88 spin_lock_irqsave(&wl->wl_lock, flags);
89 if (work_pending(&wl->irq_work) || chip_awake)
92 wl->elp_compl = &compl;
93 spin_unlock_irqrestore(&wl->wl_lock, flags);
95 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP);
98 ret = wait_for_completion_timeout(
99 &compl, msecs_to_jiffies(WL1271_WAKEUP_TIMEOUT));
101 wl1271_error("ELP wakeup timeout!");
102 ieee80211_queue_work(wl->hw, &wl->recovery_work);
105 } else if (ret < 0) {
106 wl1271_error("ELP wakeup completion error.");
111 clear_bit(WL1271_FLAG_IN_ELP, &wl->flags);
113 wl1271_debug(DEBUG_PSM, "wakeup time: %u ms",
114 jiffies_to_msecs(jiffies - start_time));
118 spin_lock_irqsave(&wl->wl_lock, flags);
119 wl->elp_compl = NULL;
120 spin_unlock_irqrestore(&wl->wl_lock, flags);
127 int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode,
128 u32 rates, bool send)
133 case STATION_POWER_SAVE_MODE:
134 wl1271_debug(DEBUG_PSM, "entering psm");
136 ret = wl1271_acx_wake_up_conditions(wl);
138 wl1271_error("couldn't set wake up conditions");
142 ret = wl1271_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE,
147 set_bit(WL1271_FLAG_PSM, &wl->flags);
149 case STATION_ACTIVE_MODE:
151 wl1271_debug(DEBUG_PSM, "leaving psm");
152 ret = wl1271_ps_elp_wakeup(wl, false);
156 /* disable beacon early termination */
157 ret = wl1271_acx_bet_enable(wl, false);
161 /* disable beacon filtering */
162 ret = wl1271_acx_beacon_filter_opt(wl, false);
166 ret = wl1271_cmd_ps_mode(wl, STATION_ACTIVE_MODE,
171 clear_bit(WL1271_FLAG_PSM, &wl->flags);