2 * This file is part of wl1251
4 * Copyright (C) 2008 Nokia Corporation
6 * Contact: Kalle Valo <kalle.valo@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 "wl1251_reg.h"
25 #include "wl1251_ps.h"
26 #include "wl1251_cmd.h"
27 #include "wl1251_io.h"
29 #define WL1251_WAKEUP_TIMEOUT 2000
31 void wl1251_elp_work(struct work_struct *work)
33 struct delayed_work *dwork;
36 dwork = container_of(work, struct delayed_work, work);
37 wl = container_of(dwork, struct wl1251, elp_work);
39 wl1251_debug(DEBUG_PSM, "elp work");
41 mutex_lock(&wl->mutex);
43 if (wl->elp || !wl->psm)
46 wl1251_debug(DEBUG_PSM, "chip to elp");
47 wl1251_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
51 mutex_unlock(&wl->mutex);
54 #define ELP_ENTRY_DELAY 5
56 /* Routines to toggle sleep mode while in ELP */
57 void wl1251_ps_elp_sleep(struct wl1251 *wl)
62 cancel_delayed_work(&wl->elp_work);
63 delay = msecs_to_jiffies(ELP_ENTRY_DELAY);
64 ieee80211_queue_delayed_work(wl->hw, &wl->elp_work, delay);
68 int wl1251_ps_elp_wakeup(struct wl1251 *wl)
70 unsigned long timeout;
76 wl1251_debug(DEBUG_PSM, "waking up chip from elp");
78 timeout = jiffies + msecs_to_jiffies(WL1251_WAKEUP_TIMEOUT);
80 wl1251_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP);
82 elp_reg = wl1251_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
85 * FIXME: we should wait for irq from chip but, as a temporary
86 * solution to simplify locking, let's poll instead
88 while (!(elp_reg & ELPCTRL_WLAN_READY)) {
89 if (time_after(jiffies, timeout)) {
90 wl1251_error("elp wakeup timeout");
94 elp_reg = wl1251_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
97 wl1251_debug(DEBUG_PSM, "wakeup time: %u ms",
98 jiffies_to_msecs(jiffies) -
99 (jiffies_to_msecs(timeout) - WL1251_WAKEUP_TIMEOUT));
106 static int wl1251_ps_set_elp(struct wl1251 *wl, bool enable)
111 wl1251_debug(DEBUG_PSM, "sleep auth psm/elp");
113 ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP);
117 wl1251_ps_elp_sleep(wl);
119 wl1251_debug(DEBUG_PSM, "sleep auth cam");
122 * When the target is in ELP, we can only
123 * access the ELP control register. Thus,
124 * we have to wake the target up before
125 * changing the power authorization.
128 wl1251_ps_elp_wakeup(wl);
130 ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
138 int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_cmd_ps_mode mode)
143 case STATION_POWER_SAVE_MODE:
144 wl1251_debug(DEBUG_PSM, "entering psm");
146 /* enable beacon filtering */
147 ret = wl1251_acx_beacon_filter_opt(wl, true);
151 ret = wl1251_acx_wake_up_conditions(wl,
152 WAKE_UP_EVENT_DTIM_BITMAP,
157 ret = wl1251_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE);
161 ret = wl1251_ps_set_elp(wl, true);
167 case STATION_ACTIVE_MODE:
169 wl1251_debug(DEBUG_PSM, "leaving psm");
170 ret = wl1251_ps_set_elp(wl, false);
174 /* disable beacon filtering */
175 ret = wl1251_acx_beacon_filter_opt(wl, false);
179 ret = wl1251_acx_wake_up_conditions(wl,
180 WAKE_UP_EVENT_DTIM_BITMAP,
185 ret = wl1251_cmd_ps_mode(wl, STATION_ACTIVE_MODE);