Staging: netwave: delete the driver
[linux/fpc-iii.git] / drivers / net / wireless / wl12xx / wl1271_ps.c
blobe2b1ebf096e84ffa838ccf4613d29a4230f88d70
1 /*
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
20 * 02110-1301 USA
24 #include "wl1271_reg.h"
25 #include "wl1271_ps.h"
26 #include "wl1271_spi.h"
27 #include "wl1271_io.h"
29 #define WL1271_WAKEUP_TIMEOUT 500
31 void wl1271_elp_work(struct work_struct *work)
33 struct delayed_work *dwork;
34 struct wl1271 *wl;
36 dwork = container_of(work, struct delayed_work, work);
37 wl = container_of(dwork, struct wl1271, elp_work);
39 wl1271_debug(DEBUG_PSM, "elp work");
41 mutex_lock(&wl->mutex);
43 if (test_bit(WL1271_FLAG_IN_ELP, &wl->flags) ||
44 !test_bit(WL1271_FLAG_PSM, &wl->flags))
45 goto out;
47 wl1271_debug(DEBUG_PSM, "chip to elp");
48 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
49 set_bit(WL1271_FLAG_IN_ELP, &wl->flags);
51 out:
52 mutex_unlock(&wl->mutex);
55 #define ELP_ENTRY_DELAY 5
57 /* Routines to toggle sleep mode while in ELP */
58 void wl1271_ps_elp_sleep(struct wl1271 *wl)
60 if (test_bit(WL1271_FLAG_PSM, &wl->flags)) {
61 cancel_delayed_work(&wl->elp_work);
62 ieee80211_queue_delayed_work(wl->hw, &wl->elp_work,
63 msecs_to_jiffies(ELP_ENTRY_DELAY));
67 int wl1271_ps_elp_wakeup(struct wl1271 *wl, bool chip_awake)
69 DECLARE_COMPLETION_ONSTACK(compl);
70 unsigned long flags;
71 int ret;
72 u32 start_time = jiffies;
73 bool pending = false;
75 if (!test_bit(WL1271_FLAG_IN_ELP, &wl->flags))
76 return 0;
78 wl1271_debug(DEBUG_PSM, "waking up chip from elp");
81 * The spinlock is required here to synchronize both the work and
82 * the completion variable in one entity.
84 spin_lock_irqsave(&wl->wl_lock, flags);
85 if (work_pending(&wl->irq_work) || chip_awake)
86 pending = true;
87 else
88 wl->elp_compl = &compl;
89 spin_unlock_irqrestore(&wl->wl_lock, flags);
91 wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP);
93 if (!pending) {
94 ret = wait_for_completion_timeout(
95 &compl, msecs_to_jiffies(WL1271_WAKEUP_TIMEOUT));
96 if (ret == 0) {
97 wl1271_error("ELP wakeup timeout!");
98 ret = -ETIMEDOUT;
99 goto err;
100 } else if (ret < 0) {
101 wl1271_error("ELP wakeup completion error.");
102 goto err;
106 clear_bit(WL1271_FLAG_IN_ELP, &wl->flags);
108 wl1271_debug(DEBUG_PSM, "wakeup time: %u ms",
109 jiffies_to_msecs(jiffies - start_time));
110 goto out;
112 err:
113 spin_lock_irqsave(&wl->wl_lock, flags);
114 wl->elp_compl = NULL;
115 spin_unlock_irqrestore(&wl->wl_lock, flags);
116 return ret;
118 out:
119 return 0;
122 int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode,
123 bool send)
125 int ret;
127 switch (mode) {
128 case STATION_POWER_SAVE_MODE:
129 wl1271_debug(DEBUG_PSM, "entering psm");
131 ret = wl1271_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE, send);
132 if (ret < 0)
133 return ret;
135 set_bit(WL1271_FLAG_PSM, &wl->flags);
136 break;
137 case STATION_ACTIVE_MODE:
138 default:
139 wl1271_debug(DEBUG_PSM, "leaving psm");
140 ret = wl1271_ps_elp_wakeup(wl, false);
141 if (ret < 0)
142 return ret;
144 /* disable beacon early termination */
145 ret = wl1271_acx_bet_enable(wl, false);
146 if (ret < 0)
147 return ret;
149 /* disable beacon filtering */
150 ret = wl1271_acx_beacon_filter_opt(wl, false);
151 if (ret < 0)
152 return ret;
154 ret = wl1271_cmd_ps_mode(wl, STATION_ACTIVE_MODE, send);
155 if (ret < 0)
156 return ret;
158 clear_bit(WL1271_FLAG_PSM, &wl->flags);
159 break;
162 return ret;