Lines Matching +full:pm +full:- +full:api
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Mac80211 power management API for ST-Ericsson CW1200 drivers
5 * Copyright (c) 2011, ST-Ericsson
12 #include "pm.h"
96 int cw1200_pm_init(struct cw1200_pm_state *pm, in cw1200_pm_init() argument
99 spin_lock_init(&pm->lock); in cw1200_pm_init()
101 timer_setup(&pm->stay_awake, cw1200_pm_stay_awake_tmo, 0); in cw1200_pm_init()
106 void cw1200_pm_deinit(struct cw1200_pm_state *pm) in cw1200_pm_deinit() argument
108 del_timer_sync(&pm->stay_awake); in cw1200_pm_deinit()
111 void cw1200_pm_stay_awake(struct cw1200_pm_state *pm, in cw1200_pm_stay_awake() argument
115 spin_lock_bh(&pm->lock); in cw1200_pm_stay_awake()
116 cur_tmo = pm->stay_awake.expires - jiffies; in cw1200_pm_stay_awake()
117 if (!timer_pending(&pm->stay_awake) || cur_tmo < (long)tmo) in cw1200_pm_stay_awake()
118 mod_timer(&pm->stay_awake, jiffies + tmo); in cw1200_pm_stay_awake()
119 spin_unlock_bh(&pm->lock); in cw1200_pm_stay_awake()
128 tmo = work->timer.expires - jiffies; in cw1200_suspend_work()
132 tmo = -1; in cw1200_suspend_work()
144 return queue_delayed_work(priv->workqueue, work, tmo); in cw1200_resume_work()
149 if (atomic_read(&priv->bh_rx)) { in cw1200_can_suspend()
150 wiphy_dbg(priv->hw->wiphy, "Suspend interrupted.\n"); in cw1200_can_suspend()
159 struct cw1200_common *priv = hw->priv; in cw1200_wow_suspend()
160 struct cw1200_pm_state *pm_state = &priv->pm_state; in cw1200_wow_suspend()
164 spin_lock_bh(&pm_state->lock); in cw1200_wow_suspend()
165 ret = timer_pending(&pm_state->stay_awake); in cw1200_wow_suspend()
166 spin_unlock_bh(&pm_state->lock); in cw1200_wow_suspend()
168 return -EAGAIN; in cw1200_wow_suspend()
171 if (priv->tx_queue_stats.num_queued) in cw1200_wow_suspend()
172 return -EBUSY; in cw1200_wow_suspend()
175 if (!mutex_trylock(&priv->conf_mutex)) in cw1200_wow_suspend()
176 return -EBUSY; in cw1200_wow_suspend()
182 if (priv->channel_switch_in_progress) in cw1200_wow_suspend()
186 if (priv->join_pending) in cw1200_wow_suspend()
190 if (down_trylock(&priv->scan.lock)) in cw1200_wow_suspend()
199 if (wait_event_timeout(priv->bh_evt_wq, in cw1200_wow_suspend()
200 !priv->hw_bufs_used, HZ / 10) <= 0) in cw1200_wow_suspend()
215 if (!priv->vif->p2p && in cw1200_wow_suspend()
216 priv->join_status == CW1200_JOIN_STATUS_STA && in cw1200_wow_suspend()
217 priv->powersave_mode.mode != WSM_PSM_PS) { in cw1200_wow_suspend()
218 state->prev_ps_mode = priv->powersave_mode.mode; in cw1200_wow_suspend()
219 priv->powersave_mode.mode = WSM_PSM_PS; in cw1200_wow_suspend()
220 cw1200_set_pm(priv, &priv->powersave_mode); in cw1200_wow_suspend()
221 if (wait_event_interruptible_timeout(priv->ps_mode_switch_done, in cw1200_wow_suspend()
222 !priv->ps_mode_switch_in_progress, 1*HZ) <= 0) { in cw1200_wow_suspend()
228 state->bss_loss_tmo = in cw1200_wow_suspend()
229 cw1200_suspend_work(&priv->bss_loss_work); in cw1200_wow_suspend()
230 state->join_tmo = in cw1200_wow_suspend()
231 cw1200_suspend_work(&priv->join_timeout); in cw1200_wow_suspend()
232 state->direct_probe = in cw1200_wow_suspend()
233 cw1200_suspend_work(&priv->scan.probe_work); in cw1200_wow_suspend()
234 state->link_id_gc = in cw1200_wow_suspend()
235 cw1200_suspend_work(&priv->link_id_gc_work); in cw1200_wow_suspend()
237 cancel_delayed_work_sync(&priv->clear_recent_scan_work); in cw1200_wow_suspend()
238 atomic_set(&priv->recent_scan, 0); in cw1200_wow_suspend()
241 if (priv->join_status == CW1200_JOIN_STATUS_STA && in cw1200_wow_suspend()
242 priv->join_dtim_period && in cw1200_wow_suspend()
243 !priv->has_multicast_subscription) { in cw1200_wow_suspend()
244 state->beacon_skipping = true; in cw1200_wow_suspend()
246 priv->join_dtim_period, in cw1200_wow_suspend()
247 CW1200_BEACON_SKIPPING_MULTIPLIER * priv->join_dtim_period); in cw1200_wow_suspend()
254 ret = timer_pending(&priv->mcast_timeout); in cw1200_wow_suspend()
259 pm_state->suspend_state = state; in cw1200_wow_suspend()
262 ret = priv->hwbus_ops->power_mgmt(priv->hwbus_priv, true); in cw1200_wow_suspend()
264 wiphy_err(priv->hw->wiphy, in cw1200_wow_suspend()
265 "PM request failed: %d. WoW is disabled.\n", ret); in cw1200_wow_suspend()
267 return -EBUSY; in cw1200_wow_suspend()
271 if (atomic_read(&priv->bh_rx)) { in cw1200_wow_suspend()
273 return -EAGAIN; in cw1200_wow_suspend()
281 cw1200_resume_work(priv, &priv->bss_loss_work, in cw1200_wow_suspend()
282 state->bss_loss_tmo); in cw1200_wow_suspend()
283 cw1200_resume_work(priv, &priv->join_timeout, in cw1200_wow_suspend()
284 state->join_tmo); in cw1200_wow_suspend()
285 cw1200_resume_work(priv, &priv->scan.probe_work, in cw1200_wow_suspend()
286 state->direct_probe); in cw1200_wow_suspend()
287 cw1200_resume_work(priv, &priv->link_id_gc_work, in cw1200_wow_suspend()
288 state->link_id_gc); in cw1200_wow_suspend()
296 up(&priv->scan.lock); in cw1200_wow_suspend()
298 mutex_unlock(&priv->conf_mutex); in cw1200_wow_suspend()
299 return -EBUSY; in cw1200_wow_suspend()
304 struct cw1200_common *priv = hw->priv; in cw1200_wow_resume()
305 struct cw1200_pm_state *pm_state = &priv->pm_state; in cw1200_wow_resume()
308 state = pm_state->suspend_state; in cw1200_wow_resume()
309 pm_state->suspend_state = NULL; in cw1200_wow_resume()
312 priv->hwbus_ops->power_mgmt(priv->hwbus_priv, false); in cw1200_wow_resume()
318 up(&priv->scan.lock); in cw1200_wow_resume()
324 if (!priv->vif->p2p && priv->join_status == CW1200_JOIN_STATUS_STA) { in cw1200_wow_resume()
325 priv->powersave_mode.mode = state->prev_ps_mode; in cw1200_wow_resume()
326 cw1200_set_pm(priv, &priv->powersave_mode); in cw1200_wow_resume()
329 if (state->beacon_skipping) { in cw1200_wow_resume()
330 wsm_set_beacon_wakeup_period(priv, priv->beacon_int * in cw1200_wow_resume()
331 priv->join_dtim_period > in cw1200_wow_resume()
333 priv->join_dtim_period, 0); in cw1200_wow_resume()
334 state->beacon_skipping = false; in cw1200_wow_resume()
338 cw1200_resume_work(priv, &priv->bss_loss_work, in cw1200_wow_resume()
339 state->bss_loss_tmo); in cw1200_wow_resume()
340 cw1200_resume_work(priv, &priv->join_timeout, in cw1200_wow_resume()
341 state->join_tmo); in cw1200_wow_resume()
342 cw1200_resume_work(priv, &priv->scan.probe_work, in cw1200_wow_resume()
343 state->direct_probe); in cw1200_wow_resume()
344 cw1200_resume_work(priv, &priv->link_id_gc_work, in cw1200_wow_resume()
345 state->link_id_gc); in cw1200_wow_resume()
357 mutex_unlock(&priv->conf_mutex); in cw1200_wow_resume()