wl1251: remove wl1251_ps_set_elp function
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / wl1251 / ps.c
1 /*
2  * This file is part of wl1251
3  *
4  * Copyright (C) 2008 Nokia Corporation
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * version 2 as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18  * 02110-1301 USA
19  *
20  */
21
22 #include "reg.h"
23 #include "ps.h"
24 #include "cmd.h"
25 #include "io.h"
26
27 /* in ms */
28 #define WL1251_WAKEUP_TIMEOUT 100
29
30 void wl1251_elp_work(struct work_struct *work)
31 {
32         struct delayed_work *dwork;
33         struct wl1251 *wl;
34
35         dwork = container_of(work, struct delayed_work, work);
36         wl = container_of(dwork, struct wl1251, elp_work);
37
38         wl1251_debug(DEBUG_PSM, "elp work");
39
40         mutex_lock(&wl->mutex);
41
42         if (wl->elp || !wl->psm)
43                 goto out;
44
45         wl1251_debug(DEBUG_PSM, "chip to elp");
46         wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP);
47         wl->elp = true;
48
49 out:
50         mutex_unlock(&wl->mutex);
51 }
52
53 #define ELP_ENTRY_DELAY  5
54
55 /* Routines to toggle sleep mode while in ELP */
56 void wl1251_ps_elp_sleep(struct wl1251 *wl)
57 {
58         unsigned long delay;
59
60         if (wl->psm) {
61                 cancel_delayed_work(&wl->elp_work);
62                 delay = msecs_to_jiffies(ELP_ENTRY_DELAY);
63                 ieee80211_queue_delayed_work(wl->hw, &wl->elp_work, delay);
64         }
65 }
66
67 int wl1251_ps_elp_wakeup(struct wl1251 *wl)
68 {
69         unsigned long timeout, start;
70         u32 elp_reg;
71
72         if (!wl->elp)
73                 return 0;
74
75         wl1251_debug(DEBUG_PSM, "waking up chip from elp");
76
77         start = jiffies;
78         timeout = jiffies + msecs_to_jiffies(WL1251_WAKEUP_TIMEOUT);
79
80         wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP);
81
82         elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
83
84         /*
85          * FIXME: we should wait for irq from chip but, as a temporary
86          * solution to simplify locking, let's poll instead
87          */
88         while (!(elp_reg & ELPCTRL_WLAN_READY)) {
89                 if (time_after(jiffies, timeout)) {
90                         wl1251_error("elp wakeup timeout");
91                         return -ETIMEDOUT;
92                 }
93                 msleep(1);
94                 elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR);
95         }
96
97         wl1251_debug(DEBUG_PSM, "wakeup time: %u ms",
98                      jiffies_to_msecs(jiffies - start));
99
100         wl->elp = false;
101
102         return 0;
103 }
104
105 int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_cmd_ps_mode mode)
106 {
107         int ret;
108
109         switch (mode) {
110         case STATION_POWER_SAVE_MODE:
111                 wl1251_debug(DEBUG_PSM, "entering psm");
112
113                 /* enable beacon filtering */
114                 ret = wl1251_acx_beacon_filter_opt(wl, true);
115                 if (ret < 0)
116                         return ret;
117
118                 ret = wl1251_acx_wake_up_conditions(wl,
119                                                     WAKE_UP_EVENT_DTIM_BITMAP,
120                                                     wl->listen_int);
121                 if (ret < 0)
122                         return ret;
123
124                 ret = wl1251_acx_bet_enable(wl, WL1251_ACX_BET_ENABLE,
125                                             WL1251_DEFAULT_BET_CONSECUTIVE);
126                 if (ret < 0)
127                         return ret;
128
129                 ret = wl1251_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE);
130                 if (ret < 0)
131                         return ret;
132
133                 ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP);
134                 if (ret < 0)
135                         return ret;
136
137                 wl->psm = 1;
138                 break;
139         case STATION_ACTIVE_MODE:
140         default:
141                 wl1251_debug(DEBUG_PSM, "leaving psm");
142
143                 ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM);
144                 if (ret < 0)
145                         return ret;
146
147                 /* disable BET */
148                 ret = wl1251_acx_bet_enable(wl, WL1251_ACX_BET_DISABLE,
149                                             WL1251_DEFAULT_BET_CONSECUTIVE);
150                 if (ret < 0)
151                         return ret;
152
153                 /* disable beacon filtering */
154                 ret = wl1251_acx_beacon_filter_opt(wl, false);
155                 if (ret < 0)
156                         return ret;
157
158                 ret = wl1251_acx_wake_up_conditions(wl,
159                                                     WAKE_UP_EVENT_DTIM_BITMAP,
160                                                     wl->listen_int);
161                 if (ret < 0)
162                         return ret;
163
164                 ret = wl1251_cmd_ps_mode(wl, STATION_ACTIVE_MODE);
165                 if (ret < 0)
166                         return ret;
167
168                 wl->psm = 0;
169                 break;
170         }
171
172         return ret;
173 }
174