2 * This file is part of wl12xx
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
28 #define WL12XX_WAKEUP_TIMEOUT 2000
30 /* Routines to toggle sleep mode while in ELP */
31 void wl12xx_ps_elp_sleep(struct wl12xx *wl)
33 if (wl->elp || !wl->psm)
36 wl12xx_debug(DEBUG_PSM, "chip to elp");
38 wl12xx_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
43 int wl12xx_ps_elp_wakeup(struct wl12xx *wl)
45 unsigned long timeout;
51 wl12xx_debug(DEBUG_PSM, "waking up chip from elp");
53 timeout = jiffies + msecs_to_jiffies(WL12XX_WAKEUP_TIMEOUT);
55 wl12xx_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP);
57 elp_reg = wl12xx_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
60 * FIXME: we should wait for irq from chip but, as a temporary
61 * solution to simplify locking, let's poll instead
63 while (!(elp_reg & ELPCTRL_WLAN_READY)) {
64 if (time_after(jiffies, timeout)) {
65 wl12xx_error("elp wakeup timeout");
69 elp_reg = wl12xx_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
72 wl12xx_debug(DEBUG_PSM, "wakeup time: %u ms",
73 jiffies_to_msecs(jiffies) -
74 (jiffies_to_msecs(timeout) - WL12XX_WAKEUP_TIMEOUT));
81 static int wl12xx_ps_set_elp(struct wl12xx *wl, bool enable)
86 wl12xx_debug(DEBUG_PSM, "sleep auth psm/elp");
89 * FIXME: we should PSM_ELP, but because of firmware wakeup
90 * problems let's use only PSM_PS
92 ret = wl12xx_acx_sleep_auth(wl, WL12XX_PSM_PS);
96 wl12xx_ps_elp_sleep(wl);
98 wl12xx_debug(DEBUG_PSM, "sleep auth cam");
101 * When the target is in ELP, we can only
102 * access the ELP control register. Thus,
103 * we have to wake the target up before
104 * changing the power authorization.
107 wl12xx_ps_elp_wakeup(wl);
109 ret = wl12xx_acx_sleep_auth(wl, WL12XX_PSM_CAM);
117 int wl12xx_ps_set_mode(struct wl12xx *wl, enum acx_ps_mode mode)
122 case STATION_POWER_SAVE_MODE:
123 wl12xx_debug(DEBUG_PSM, "entering psm");
124 ret = wl12xx_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE);
128 ret = wl12xx_ps_set_elp(wl, true);
134 case STATION_ACTIVE_MODE:
136 wl12xx_debug(DEBUG_PSM, "leaving psm");
137 ret = wl12xx_ps_set_elp(wl, false);
141 ret = wl12xx_cmd_ps_mode(wl, STATION_ACTIVE_MODE);