aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/wireless/wl12xx/wl1251_ps.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/wireless/wl12xx/wl1251_ps.c')
-rw-r--r--drivers/net/wireless/wl12xx/wl1251_ps.c147
1 files changed, 147 insertions, 0 deletions
diff --git a/drivers/net/wireless/wl12xx/wl1251_ps.c b/drivers/net/wireless/wl12xx/wl1251_ps.c
new file mode 100644
index 00000000000..83baaa2eb19
--- /dev/null
+++ b/drivers/net/wireless/wl12xx/wl1251_ps.c
@@ -0,0 +1,147 @@
1/*
2 * This file is part of wl12xx
3 *
4 * Copyright (C) 2008 Nokia Corporation
5 *
6 * Contact: Kalle Valo <kalle.valo@nokia.com>
7 *
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.
11 *
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.
16 *
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
20 * 02110-1301 USA
21 *
22 */
23
24#include "reg.h"
25#include "wl1251_ps.h"
26#include "wl1251_spi.h"
27
28#define WL12XX_WAKEUP_TIMEOUT 2000
29
30/* Routines to toggle sleep mode while in ELP */
31void wl12xx_ps_elp_sleep(struct wl12xx *wl)
32{
33 if (wl->elp || !wl->psm)
34 return;
35
36 wl12xx_debug(DEBUG_PSM, "chip to elp");
37
38 wl12xx_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
39
40 wl->elp = true;
41}
42
43int wl12xx_ps_elp_wakeup(struct wl12xx *wl)
44{
45 unsigned long timeout;
46 u32 elp_reg;
47
48 if (!wl->elp)
49 return 0;
50
51 wl12xx_debug(DEBUG_PSM, "waking up chip from elp");
52
53 timeout = jiffies + msecs_to_jiffies(WL12XX_WAKEUP_TIMEOUT);
54
55 wl12xx_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP);
56
57 elp_reg = wl12xx_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
58
59 /*
60 * FIXME: we should wait for irq from chip but, as a temporary
61 * solution to simplify locking, let's poll instead
62 */
63 while (!(elp_reg & ELPCTRL_WLAN_READY)) {
64 if (time_after(jiffies, timeout)) {
65 wl12xx_error("elp wakeup timeout");
66 return -ETIMEDOUT;
67 }
68 msleep(1);
69 elp_reg = wl12xx_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
70 }
71
72 wl12xx_debug(DEBUG_PSM, "wakeup time: %u ms",
73 jiffies_to_msecs(jiffies) -
74 (jiffies_to_msecs(timeout) - WL12XX_WAKEUP_TIMEOUT));
75
76 wl->elp = false;
77
78 return 0;
79}
80
81static int wl12xx_ps_set_elp(struct wl12xx *wl, bool enable)
82{
83 int ret;
84
85 if (enable) {
86 wl12xx_debug(DEBUG_PSM, "sleep auth psm/elp");
87
88 ret = wl12xx_acx_sleep_auth(wl, WL12XX_PSM_ELP);
89 if (ret < 0)
90 return ret;
91
92 wl12xx_ps_elp_sleep(wl);
93 } else {
94 wl12xx_debug(DEBUG_PSM, "sleep auth cam");
95
96 /*
97 * When the target is in ELP, we can only
98 * access the ELP control register. Thus,
99 * we have to wake the target up before
100 * changing the power authorization.
101 */
102
103 wl12xx_ps_elp_wakeup(wl);
104
105 ret = wl12xx_acx_sleep_auth(wl, WL12XX_PSM_CAM);
106 if (ret < 0)
107 return ret;
108 }
109
110 return 0;
111}
112
113int wl12xx_ps_set_mode(struct wl12xx *wl, enum wl12xx_cmd_ps_mode mode)
114{
115 int ret;
116
117 switch (mode) {
118 case STATION_POWER_SAVE_MODE:
119 wl12xx_debug(DEBUG_PSM, "entering psm");
120 ret = wl12xx_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE);
121 if (ret < 0)
122 return ret;
123
124 ret = wl12xx_ps_set_elp(wl, true);
125 if (ret < 0)
126 return ret;
127
128 wl->psm = 1;
129 break;
130 case STATION_ACTIVE_MODE:
131 default:
132 wl12xx_debug(DEBUG_PSM, "leaving psm");
133 ret = wl12xx_ps_set_elp(wl, false);
134 if (ret < 0)
135 return ret;
136
137 ret = wl12xx_cmd_ps_mode(wl, STATION_ACTIVE_MODE);
138 if (ret < 0)
139 return ret;
140
141 wl->psm = 0;
142 break;
143 }
144
145 return ret;
146}
147