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 void wl1271_elp_work(struct work_struct
*work
)
32 struct delayed_work
*dwork
;
35 dwork
= container_of(work
, struct delayed_work
, work
);
36 wl
= container_of(dwork
, struct wl1271
, elp_work
);
38 wl1271_debug(DEBUG_PSM
, "elp work");
40 mutex_lock(&wl
->mutex
);
42 if (wl
->elp
|| !wl
->psm
)
45 wl1271_debug(DEBUG_PSM
, "chip to elp");
46 wl1271_raw_write32(wl
, HW_ACCESS_ELP_CTRL_REG_ADDR
, ELPCTRL_SLEEP
);
50 mutex_unlock(&wl
->mutex
);
53 #define ELP_ENTRY_DELAY 5
55 /* Routines to toggle sleep mode while in ELP */
56 void wl1271_ps_elp_sleep(struct wl1271
*wl
)
59 cancel_delayed_work(&wl
->elp_work
);
60 ieee80211_queue_delayed_work(wl
->hw
, &wl
->elp_work
,
61 msecs_to_jiffies(ELP_ENTRY_DELAY
));
65 int wl1271_ps_elp_wakeup(struct wl1271
*wl
, bool chip_awake
)
67 DECLARE_COMPLETION_ONSTACK(compl);
70 u32 start_time
= jiffies
;
76 wl1271_debug(DEBUG_PSM
, "waking up chip from elp");
79 * The spinlock is required here to synchronize both the work and
80 * the completion variable in one entity.
82 spin_lock_irqsave(&wl
->wl_lock
, flags
);
83 if (work_pending(&wl
->irq_work
) || chip_awake
)
86 wl
->elp_compl
= &compl;
87 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
89 wl1271_raw_write32(wl
, HW_ACCESS_ELP_CTRL_REG_ADDR
, ELPCTRL_WAKE_UP
);
92 ret
= wait_for_completion_timeout(
93 &compl, msecs_to_jiffies(WL1271_WAKEUP_TIMEOUT
));
95 wl1271_error("ELP wakeup timeout!");
99 wl1271_error("ELP wakeup completion error.");
106 wl1271_debug(DEBUG_PSM
, "wakeup time: %u ms",
107 jiffies_to_msecs(jiffies
- start_time
));
111 spin_lock_irqsave(&wl
->wl_lock
, flags
);
112 wl
->elp_compl
= NULL
;
113 spin_unlock_irqrestore(&wl
->wl_lock
, flags
);
120 int wl1271_ps_set_mode(struct wl1271
*wl
, enum wl1271_cmd_ps_mode mode
)
125 case STATION_POWER_SAVE_MODE
:
126 wl1271_debug(DEBUG_PSM
, "entering psm");
128 /* enable beacon filtering */
129 ret
= wl1271_acx_beacon_filter_opt(wl
, true);
133 ret
= wl1271_cmd_ps_mode(wl
, STATION_POWER_SAVE_MODE
);
137 wl1271_ps_elp_sleep(wl
);
143 case STATION_ACTIVE_MODE
:
145 wl1271_debug(DEBUG_PSM
, "leaving psm");
146 ret
= wl1271_ps_elp_wakeup(wl
, false);
150 /* disable beacon filtering */
151 ret
= wl1271_acx_beacon_filter_opt(wl
, false);
155 ret
= wl1271_cmd_ps_mode(wl
, STATION_ACTIVE_MODE
);