Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 1 | /* |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 2 | * This file is part of wl1251 |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2008 Nokia Corporation |
| 5 | * |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 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 | |
Kalle Valo | 9bc6772 | 2010-10-10 11:28:32 +0300 | [diff] [blame] | 22 | #include "reg.h" |
| 23 | #include "ps.h" |
| 24 | #include "cmd.h" |
| 25 | #include "io.h" |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 26 | |
Kalle Valo | b5a1679 | 2009-11-30 10:17:59 +0200 | [diff] [blame] | 27 | /* in ms */ |
| 28 | #define WL1251_WAKEUP_TIMEOUT 100 |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 29 | |
Juuso Oikarinen | d5da79a | 2009-11-17 18:48:37 +0200 | [diff] [blame] | 30 | void wl1251_elp_work(struct work_struct *work) |
| 31 | { |
| 32 | struct delayed_work *dwork; |
| 33 | struct wl1251 *wl; |
| 34 | |
Geliang Tang | d1162f0 | 2016-03-18 13:22:03 +1100 | [diff] [blame^] | 35 | dwork = to_delayed_work(work); |
Juuso Oikarinen | d5da79a | 2009-11-17 18:48:37 +0200 | [diff] [blame] | 36 | wl = container_of(dwork, struct wl1251, elp_work); |
| 37 | |
| 38 | wl1251_debug(DEBUG_PSM, "elp work"); |
| 39 | |
| 40 | mutex_lock(&wl->mutex); |
| 41 | |
Jarkko Nikula | a0bbb58 | 2011-04-04 11:04:57 +0300 | [diff] [blame] | 42 | if (wl->elp || wl->station_mode == STATION_ACTIVE_MODE) |
Juuso Oikarinen | d5da79a | 2009-11-17 18:48:37 +0200 | [diff] [blame] | 43 | goto out; |
| 44 | |
| 45 | wl1251_debug(DEBUG_PSM, "chip to elp"); |
Grazvydas Ignotas | 3f9e750 | 2010-03-11 17:44:57 +0200 | [diff] [blame] | 46 | wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP); |
Juuso Oikarinen | d5da79a | 2009-11-17 18:48:37 +0200 | [diff] [blame] | 47 | wl->elp = true; |
| 48 | |
| 49 | out: |
| 50 | mutex_unlock(&wl->mutex); |
| 51 | } |
| 52 | |
| 53 | #define ELP_ENTRY_DELAY 5 |
| 54 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 55 | /* Routines to toggle sleep mode while in ELP */ |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 56 | void wl1251_ps_elp_sleep(struct wl1251 *wl) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 57 | { |
Juuso Oikarinen | d5da79a | 2009-11-17 18:48:37 +0200 | [diff] [blame] | 58 | unsigned long delay; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 59 | |
Jarkko Nikula | a0bbb58 | 2011-04-04 11:04:57 +0300 | [diff] [blame] | 60 | if (wl->station_mode != STATION_ACTIVE_MODE) { |
Juuso Oikarinen | d5da79a | 2009-11-17 18:48:37 +0200 | [diff] [blame] | 61 | delay = msecs_to_jiffies(ELP_ENTRY_DELAY); |
| 62 | ieee80211_queue_delayed_work(wl->hw, &wl->elp_work, delay); |
| 63 | } |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 64 | } |
| 65 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 66 | int wl1251_ps_elp_wakeup(struct wl1251 *wl) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 67 | { |
Kalle Valo | 7fa6282 | 2009-11-30 10:18:06 +0200 | [diff] [blame] | 68 | unsigned long timeout, start; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 69 | u32 elp_reg; |
| 70 | |
Tejun Heo | 02957f9 | 2012-12-21 17:56:59 -0800 | [diff] [blame] | 71 | cancel_delayed_work(&wl->elp_work); |
Grazvydas Ignotas | 5f6722e | 2011-03-06 19:23:37 +0200 | [diff] [blame] | 72 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 73 | if (!wl->elp) |
| 74 | return 0; |
| 75 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 76 | wl1251_debug(DEBUG_PSM, "waking up chip from elp"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 77 | |
Kalle Valo | 7fa6282 | 2009-11-30 10:18:06 +0200 | [diff] [blame] | 78 | start = jiffies; |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 79 | timeout = jiffies + msecs_to_jiffies(WL1251_WAKEUP_TIMEOUT); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 80 | |
Grazvydas Ignotas | 3f9e750 | 2010-03-11 17:44:57 +0200 | [diff] [blame] | 81 | wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 82 | |
Grazvydas Ignotas | 3f9e750 | 2010-03-11 17:44:57 +0200 | [diff] [blame] | 83 | elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 84 | |
| 85 | /* |
| 86 | * FIXME: we should wait for irq from chip but, as a temporary |
| 87 | * solution to simplify locking, let's poll instead |
| 88 | */ |
| 89 | while (!(elp_reg & ELPCTRL_WLAN_READY)) { |
| 90 | if (time_after(jiffies, timeout)) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 91 | wl1251_error("elp wakeup timeout"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 92 | return -ETIMEDOUT; |
| 93 | } |
| 94 | msleep(1); |
Grazvydas Ignotas | 3f9e750 | 2010-03-11 17:44:57 +0200 | [diff] [blame] | 95 | elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 96 | } |
| 97 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 98 | wl1251_debug(DEBUG_PSM, "wakeup time: %u ms", |
Kalle Valo | 7fa6282 | 2009-11-30 10:18:06 +0200 | [diff] [blame] | 99 | jiffies_to_msecs(jiffies - start)); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 100 | |
| 101 | wl->elp = false; |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
Jarkko Nikula | a0bbb58 | 2011-04-04 11:04:57 +0300 | [diff] [blame] | 106 | int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_station_mode mode) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 107 | { |
| 108 | int ret; |
| 109 | |
| 110 | switch (mode) { |
| 111 | case STATION_POWER_SAVE_MODE: |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 112 | wl1251_debug(DEBUG_PSM, "entering psm"); |
Kalle Valo | 4a81892 | 2009-08-07 13:34:56 +0300 | [diff] [blame] | 113 | |
Juuso Oikarinen | 6b21a2c | 2009-11-17 18:48:30 +0200 | [diff] [blame] | 114 | /* enable beacon filtering */ |
| 115 | ret = wl1251_acx_beacon_filter_opt(wl, true); |
| 116 | if (ret < 0) |
| 117 | return ret; |
| 118 | |
Kalle Valo | 4a81892 | 2009-08-07 13:34:56 +0300 | [diff] [blame] | 119 | ret = wl1251_acx_wake_up_conditions(wl, |
| 120 | WAKE_UP_EVENT_DTIM_BITMAP, |
| 121 | wl->listen_int); |
| 122 | if (ret < 0) |
| 123 | return ret; |
| 124 | |
David Gnedt | c3e334d | 2011-01-30 20:10:57 +0100 | [diff] [blame] | 125 | ret = wl1251_acx_bet_enable(wl, WL1251_ACX_BET_ENABLE, |
| 126 | WL1251_DEFAULT_BET_CONSECUTIVE); |
| 127 | if (ret < 0) |
| 128 | return ret; |
| 129 | |
Jarkko Nikula | a0bbb58 | 2011-04-04 11:04:57 +0300 | [diff] [blame] | 130 | ret = wl1251_cmd_ps_mode(wl, CHIP_POWER_SAVE_MODE); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 131 | if (ret < 0) |
| 132 | return ret; |
| 133 | |
Grazvydas Ignotas | d0c331a | 2011-03-06 19:23:36 +0200 | [diff] [blame] | 134 | ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 135 | if (ret < 0) |
| 136 | return ret; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 137 | break; |
Jarkko Nikula | 1e5f52d | 2011-04-04 11:04:58 +0300 | [diff] [blame] | 138 | case STATION_IDLE: |
| 139 | wl1251_debug(DEBUG_PSM, "entering idle"); |
| 140 | |
| 141 | ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP); |
| 142 | if (ret < 0) |
| 143 | return ret; |
| 144 | |
| 145 | ret = wl1251_cmd_template_set(wl, CMD_DISCONNECT, NULL, 0); |
| 146 | if (ret < 0) |
| 147 | return ret; |
| 148 | break; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 149 | case STATION_ACTIVE_MODE: |
| 150 | default: |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 151 | wl1251_debug(DEBUG_PSM, "leaving psm"); |
Grazvydas Ignotas | d0c331a | 2011-03-06 19:23:36 +0200 | [diff] [blame] | 152 | |
| 153 | ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 154 | if (ret < 0) |
| 155 | return ret; |
| 156 | |
David Gnedt | c3e334d | 2011-01-30 20:10:57 +0100 | [diff] [blame] | 157 | /* disable BET */ |
| 158 | ret = wl1251_acx_bet_enable(wl, WL1251_ACX_BET_DISABLE, |
| 159 | WL1251_DEFAULT_BET_CONSECUTIVE); |
| 160 | if (ret < 0) |
| 161 | return ret; |
| 162 | |
Juuso Oikarinen | 6b21a2c | 2009-11-17 18:48:30 +0200 | [diff] [blame] | 163 | /* disable beacon filtering */ |
| 164 | ret = wl1251_acx_beacon_filter_opt(wl, false); |
| 165 | if (ret < 0) |
| 166 | return ret; |
| 167 | |
Kalle Valo | 4a81892 | 2009-08-07 13:34:56 +0300 | [diff] [blame] | 168 | ret = wl1251_acx_wake_up_conditions(wl, |
| 169 | WAKE_UP_EVENT_DTIM_BITMAP, |
| 170 | wl->listen_int); |
| 171 | if (ret < 0) |
| 172 | return ret; |
| 173 | |
Jarkko Nikula | a0bbb58 | 2011-04-04 11:04:57 +0300 | [diff] [blame] | 174 | ret = wl1251_cmd_ps_mode(wl, CHIP_ACTIVE_MODE); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 175 | if (ret < 0) |
| 176 | return ret; |
| 177 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 178 | break; |
| 179 | } |
Jarkko Nikula | a0bbb58 | 2011-04-04 11:04:57 +0300 | [diff] [blame] | 180 | wl->station_mode = mode; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 181 | |
| 182 | return ret; |
| 183 | } |
| 184 | |