treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / net / wireless / ti / wl1251 / ps.c
blobdcb7d1cc78078724e6f6cba19e3a710692b32811
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * This file is part of wl1251
5 * Copyright (C) 2008 Nokia Corporation
6 */
8 #include "reg.h"
9 #include "ps.h"
10 #include "cmd.h"
11 #include "io.h"
13 /* in ms */
14 #define WL1251_WAKEUP_TIMEOUT 100
16 void wl1251_elp_work(struct work_struct *work)
18 struct delayed_work *dwork;
19 struct wl1251 *wl;
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)
29 goto out;
31 wl1251_debug(DEBUG_PSM, "chip to elp");
32 wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
33 wl->elp = true;
35 out:
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)
44 unsigned long delay;
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;
55 u32 elp_reg;
57 cancel_delayed_work(&wl->elp_work);
59 if (!wl->elp)
60 return 0;
62 wl1251_debug(DEBUG_PSM, "waking up chip from elp");
64 start = jiffies;
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");
78 return -ETIMEDOUT;
80 msleep(1);
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));
87 wl->elp = false;
89 return 0;
92 int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_station_mode mode)
94 int ret;
96 switch (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);
102 if (ret < 0)
103 return ret;
105 ret = wl1251_acx_wake_up_conditions(wl,
106 WAKE_UP_EVENT_DTIM_BITMAP,
107 wl->listen_int);
108 if (ret < 0)
109 return ret;
111 ret = wl1251_acx_bet_enable(wl, WL1251_ACX_BET_ENABLE,
112 WL1251_DEFAULT_BET_CONSECUTIVE);
113 if (ret < 0)
114 return ret;
116 ret = wl1251_cmd_ps_mode(wl, CHIP_POWER_SAVE_MODE);
117 if (ret < 0)
118 return ret;
120 ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP);
121 if (ret < 0)
122 return ret;
123 break;
124 case STATION_IDLE:
125 wl1251_debug(DEBUG_PSM, "entering idle");
127 ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP);
128 if (ret < 0)
129 return ret;
131 ret = wl1251_cmd_template_set(wl, CMD_DISCONNECT, NULL, 0);
132 if (ret < 0)
133 return ret;
134 break;
135 case STATION_ACTIVE_MODE:
136 default:
137 wl1251_debug(DEBUG_PSM, "leaving psm");
139 ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
140 if (ret < 0)
141 return ret;
143 /* disable BET */
144 ret = wl1251_acx_bet_enable(wl, WL1251_ACX_BET_DISABLE,
145 WL1251_DEFAULT_BET_CONSECUTIVE);
146 if (ret < 0)
147 return ret;
149 /* disable beacon filtering */
150 ret = wl1251_acx_beacon_filter_opt(wl, false);
151 if (ret < 0)
152 return ret;
154 ret = wl1251_acx_wake_up_conditions(wl,
155 WAKE_UP_EVENT_DTIM_BITMAP,
156 wl->listen_int);
157 if (ret < 0)
158 return ret;
160 ret = wl1251_cmd_ps_mode(wl, CHIP_ACTIVE_MODE);
161 if (ret < 0)
162 return ret;
164 break;
166 wl->station_mode = mode;
168 return ret;