1 // SPDX-License-Identifier: GPL-2.0-only
3 * This file is part of wl1251
5 * Copyright (C) 2008 Nokia Corporation
14 #define WL1251_WAKEUP_TIMEOUT 100
16 void wl1251_elp_work(struct work_struct
*work
)
18 struct delayed_work
*dwork
;
21 dwork
= to_delayed_work(work
);
22 wl
= container_of(dwork
, struct wl1251
, elp_work
);
24 wl1251_debug(DEBUG_PSM
, "elp work");
26 mutex_lock(&wl
->mutex
);
28 if (wl
->elp
|| wl
->station_mode
== STATION_ACTIVE_MODE
)
31 wl1251_debug(DEBUG_PSM
, "chip to elp");
32 wl1251_write_elp(wl
, HW_ACCESS_ELP_CTRL_REG_ADDR
, ELPCTRL_SLEEP
);
36 mutex_unlock(&wl
->mutex
);
39 #define ELP_ENTRY_DELAY 5
41 /* Routines to toggle sleep mode while in ELP */
42 void wl1251_ps_elp_sleep(struct wl1251
*wl
)
46 if (wl
->station_mode
!= STATION_ACTIVE_MODE
) {
47 delay
= msecs_to_jiffies(ELP_ENTRY_DELAY
);
48 ieee80211_queue_delayed_work(wl
->hw
, &wl
->elp_work
, delay
);
52 int wl1251_ps_elp_wakeup(struct wl1251
*wl
)
54 unsigned long timeout
, start
;
57 cancel_delayed_work(&wl
->elp_work
);
62 wl1251_debug(DEBUG_PSM
, "waking up chip from elp");
65 timeout
= jiffies
+ msecs_to_jiffies(WL1251_WAKEUP_TIMEOUT
);
67 wl1251_write_elp(wl
, HW_ACCESS_ELP_CTRL_REG_ADDR
, ELPCTRL_WAKE_UP
);
69 elp_reg
= wl1251_read_elp(wl
, HW_ACCESS_ELP_CTRL_REG_ADDR
);
72 * FIXME: we should wait for irq from chip but, as a temporary
73 * solution to simplify locking, let's poll instead
75 while (!(elp_reg
& ELPCTRL_WLAN_READY
)) {
76 if (time_after(jiffies
, timeout
)) {
77 wl1251_error("elp wakeup timeout");
81 elp_reg
= wl1251_read_elp(wl
, HW_ACCESS_ELP_CTRL_REG_ADDR
);
84 wl1251_debug(DEBUG_PSM
, "wakeup time: %u ms",
85 jiffies_to_msecs(jiffies
- start
));
92 int wl1251_ps_set_mode(struct wl1251
*wl
, enum wl1251_station_mode mode
)
97 case STATION_POWER_SAVE_MODE
:
98 wl1251_debug(DEBUG_PSM
, "entering psm");
100 /* enable beacon filtering */
101 ret
= wl1251_acx_beacon_filter_opt(wl
, true);
105 ret
= wl1251_acx_wake_up_conditions(wl
,
106 WAKE_UP_EVENT_DTIM_BITMAP
,
111 ret
= wl1251_acx_bet_enable(wl
, WL1251_ACX_BET_ENABLE
,
112 WL1251_DEFAULT_BET_CONSECUTIVE
);
116 ret
= wl1251_cmd_ps_mode(wl
, CHIP_POWER_SAVE_MODE
);
120 ret
= wl1251_acx_sleep_auth(wl
, WL1251_PSM_ELP
);
125 wl1251_debug(DEBUG_PSM
, "entering idle");
127 ret
= wl1251_acx_sleep_auth(wl
, WL1251_PSM_ELP
);
131 ret
= wl1251_cmd_template_set(wl
, CMD_DISCONNECT
, NULL
, 0);
135 case STATION_ACTIVE_MODE
:
137 wl1251_debug(DEBUG_PSM
, "leaving psm");
139 ret
= wl1251_acx_sleep_auth(wl
, WL1251_PSM_CAM
);
144 ret
= wl1251_acx_bet_enable(wl
, WL1251_ACX_BET_DISABLE
,
145 WL1251_DEFAULT_BET_CONSECUTIVE
);
149 /* disable beacon filtering */
150 ret
= wl1251_acx_beacon_filter_opt(wl
, false);
154 ret
= wl1251_acx_wake_up_conditions(wl
,
155 WAKE_UP_EVENT_DTIM_BITMAP
,
160 ret
= wl1251_cmd_ps_mode(wl
, CHIP_ACTIVE_MODE
);
166 wl
->station_mode
= mode
;