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"
30 #define WL1251_WAKEUP_TIMEOUT 100
32 void wl1251_elp_work(struct work_struct *work)
34 struct delayed_work *dwork;
37 dwork = container_of(work, struct delayed_work, work);
38 wl = container_of(dwork, struct wl1251, elp_work);
40 wl1251_debug(DEBUG_PSM, "elp work");
42 mutex_lock(&wl->mutex);
44 if (wl->elp || !wl->psm)
47 wl1251_debug(DEBUG_PSM, "chip to elp");
48 wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
52 mutex_unlock(&wl->mutex);
55 #define ELP_ENTRY_DELAY 5
57 /* Routines to toggle sleep mode while in ELP */
58 void wl1251_ps_elp_sleep(struct wl1251 *wl)
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 DECLARE_COMPLETION_ONSTACK(compl);
75 if (delayed_work_pending(&wl->elp_work))
76 cancel_delayed_work(&wl->elp_work);
81 wl1251_debug(DEBUG_PSM, "waking up chip from elp");
85 elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
87 wl->elp_compl = &compl;
88 wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR,
89 ELPCTRL_WAKE_UP | ELPCTRL_IRQ_SRC);
91 elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
92 if (!(elp_reg & ELPCTRL_WLAN_READY)) {
93 ret = wait_for_completion_timeout(
94 &compl, msecs_to_jiffies(WL1251_WAKEUP_TIMEOUT));
96 wl1251_error("ELP wakeup timeout");
100 wl1251_error("ELP wakeup completion error.");
105 wl->elp_compl = NULL;
107 /* clear IRQ_SRC to switch irq source back from WLAN_RDY to HOST_IRQ */
108 wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP);
110 wl1251_debug(DEBUG_PSM, "wakeup time: %u ms",
111 jiffies_to_msecs(jiffies - start));
118 wl->elp_compl = NULL;
122 int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_cmd_ps_mode mode)
127 case STATION_POWER_SAVE_MODE:
128 wl1251_debug(DEBUG_PSM, "entering psm");
130 /* enable beacon filtering */
131 ret = wl1251_acx_beacon_filter_opt(wl, true);
135 ret = wl1251_acx_wake_up_conditions(wl,
136 WAKE_UP_EVENT_DTIM_BITMAP,
141 ret = wl1251_acx_bet_enable(wl, WL1251_ACX_BET_ENABLE,
142 WL1251_DEFAULT_BET_CONSECUTIVE);
146 ret = wl1251_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE);
150 ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP);
156 case STATION_ACTIVE_MODE:
158 wl1251_debug(DEBUG_PSM, "leaving psm");
160 ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
165 ret = wl1251_acx_bet_enable(wl, WL1251_ACX_BET_DISABLE,
166 WL1251_DEFAULT_BET_CONSECUTIVE);
170 /* disable beacon filtering */
171 ret = wl1251_acx_beacon_filter_opt(wl, false);
175 ret = wl1251_acx_wake_up_conditions(wl,
176 WAKE_UP_EVENT_DTIM_BITMAP,
181 ret = wl1251_cmd_ps_mode(wl, STATION_ACTIVE_MODE);