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_spi.h"
28 #define WL1271_WAKEUP_TIMEOUT 500
30 /* Routines to toggle sleep mode while in ELP */
31 void wl1271_ps_elp_sleep(struct wl1271
*wl
)
34 * FIXME: due to a problem in the firmware (causing a firmware
35 * crash), ELP entry is prevented below. Remove the "true" to
36 * re-enable ELP entry.
38 if (true || wl
->elp
|| !wl
->psm
)
42 * Go to ELP unless there is work already pending - pending work
43 * will immediately wakeup the chipset anyway.
45 if (!work_pending(&wl
->irq_work
) && !work_pending(&wl
->tx_work
)) {
46 wl1271_debug(DEBUG_PSM
, "chip to elp");
47 wl1271_write32(wl
, HW_ACCESS_ELP_CTRL_REG_ADDR
, ELPCTRL_SLEEP
);
52 int wl1271_ps_elp_wakeup(struct wl1271
*wl
, bool chip_awake
)
54 DECLARE_COMPLETION_ONSTACK(compl);
57 u32 start_time
= jiffies
;
63 wl1271_debug(DEBUG_PSM
, "waking up chip from elp");
66 * The spinlock is required here to synchronize both the work and
67 * the completion variable in one entity.
69 spin_lock_irqsave(&wl
->wl_lock
, flags
);
70 if (work_pending(&wl
->irq_work
) || chip_awake
)
73 wl
->elp_compl
= &compl;
74 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
76 wl1271_write32(wl
, HW_ACCESS_ELP_CTRL_REG_ADDR
, ELPCTRL_WAKE_UP
);
79 ret
= wait_for_completion_timeout(
80 &compl, msecs_to_jiffies(WL1271_WAKEUP_TIMEOUT
));
82 wl1271_error("ELP wakeup timeout!");
86 wl1271_error("ELP wakeup completion error.");
93 wl1271_debug(DEBUG_PSM
, "wakeup time: %u ms",
94 jiffies_to_msecs(jiffies
- start_time
));
98 spin_lock_irqsave(&wl
->wl_lock
, flags
);
100 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
107 int wl1271_ps_set_mode(struct wl1271
*wl
, enum wl1271_cmd_ps_mode mode
)
112 case STATION_POWER_SAVE_MODE
:
113 wl1271_debug(DEBUG_PSM
, "entering psm");
114 ret
= wl1271_cmd_ps_mode(wl
, STATION_POWER_SAVE_MODE
);
118 wl1271_ps_elp_sleep(wl
);
124 case STATION_ACTIVE_MODE
:
126 wl1271_debug(DEBUG_PSM
, "leaving psm");
127 ret
= wl1271_ps_elp_wakeup(wl
, false);
131 ret
= wl1271_cmd_ps_mode(wl
, STATION_ACTIVE_MODE
);