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 | * |
| 6 | * Contact: Kalle Valo <kalle.valo@nokia.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * version 2 as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 20 | * 02110-1301 USA |
| 21 | * |
| 22 | */ |
| 23 | |
Kalle Valo | 29d904c | 2009-08-07 13:35:11 +0300 | [diff] [blame] | 24 | #include "wl1251_reg.h" |
Kalle Valo | ef2f8d4 | 2009-06-12 14:17:19 +0300 | [diff] [blame] | 25 | #include "wl1251_ps.h" |
Bob Copeland | 0764de6 | 2009-08-07 13:32:56 +0300 | [diff] [blame] | 26 | #include "wl1251_cmd.h" |
| 27 | #include "wl1251_io.h" |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 28 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 29 | #define WL1251_WAKEUP_TIMEOUT 2000 |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 30 | |
Juuso Oikarinen | d5da79a | 2009-11-17 18:48:37 +0200 | [diff] [blame] | 31 | void wl1251_elp_work(struct work_struct *work) |
| 32 | { |
| 33 | struct delayed_work *dwork; |
| 34 | struct wl1251 *wl; |
| 35 | |
| 36 | dwork = container_of(work, struct delayed_work, work); |
| 37 | wl = container_of(dwork, struct wl1251, elp_work); |
| 38 | |
| 39 | wl1251_debug(DEBUG_PSM, "elp work"); |
| 40 | |
| 41 | mutex_lock(&wl->mutex); |
| 42 | |
| 43 | if (wl->elp || !wl->psm) |
| 44 | goto out; |
| 45 | |
| 46 | wl1251_debug(DEBUG_PSM, "chip to elp"); |
| 47 | wl1251_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP); |
| 48 | wl->elp = true; |
| 49 | |
| 50 | out: |
| 51 | mutex_unlock(&wl->mutex); |
| 52 | } |
| 53 | |
| 54 | #define ELP_ENTRY_DELAY 5 |
| 55 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 56 | /* Routines to toggle sleep mode while in ELP */ |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 57 | void wl1251_ps_elp_sleep(struct wl1251 *wl) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 58 | { |
Juuso Oikarinen | d5da79a | 2009-11-17 18:48:37 +0200 | [diff] [blame] | 59 | unsigned long delay; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 60 | |
Juuso Oikarinen | d5da79a | 2009-11-17 18:48:37 +0200 | [diff] [blame] | 61 | if (wl->psm) { |
| 62 | cancel_delayed_work(&wl->elp_work); |
| 63 | delay = msecs_to_jiffies(ELP_ENTRY_DELAY); |
| 64 | ieee80211_queue_delayed_work(wl->hw, &wl->elp_work, delay); |
| 65 | } |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 66 | } |
| 67 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 68 | int wl1251_ps_elp_wakeup(struct wl1251 *wl) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 69 | { |
| 70 | unsigned long timeout; |
| 71 | u32 elp_reg; |
| 72 | |
| 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 | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 78 | timeout = jiffies + msecs_to_jiffies(WL1251_WAKEUP_TIMEOUT); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 79 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 80 | wl1251_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 81 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 82 | elp_reg = wl1251_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 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)) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 90 | wl1251_error("elp wakeup timeout"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 91 | return -ETIMEDOUT; |
| 92 | } |
| 93 | msleep(1); |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 94 | elp_reg = wl1251_read32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 95 | } |
| 96 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 97 | wl1251_debug(DEBUG_PSM, "wakeup time: %u ms", |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 98 | jiffies_to_msecs(jiffies) - |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 99 | (jiffies_to_msecs(timeout) - WL1251_WAKEUP_TIMEOUT)); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 100 | |
| 101 | wl->elp = false; |
| 102 | |
| 103 | return 0; |
| 104 | } |
| 105 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 106 | static int wl1251_ps_set_elp(struct wl1251 *wl, bool enable) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 107 | { |
| 108 | int ret; |
| 109 | |
| 110 | if (enable) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 111 | wl1251_debug(DEBUG_PSM, "sleep auth psm/elp"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 112 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 113 | ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 114 | if (ret < 0) |
| 115 | return ret; |
| 116 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 117 | wl1251_ps_elp_sleep(wl); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 118 | } else { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 119 | wl1251_debug(DEBUG_PSM, "sleep auth cam"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 120 | |
| 121 | /* |
| 122 | * When the target is in ELP, we can only |
| 123 | * access the ELP control register. Thus, |
| 124 | * we have to wake the target up before |
| 125 | * changing the power authorization. |
| 126 | */ |
| 127 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 128 | wl1251_ps_elp_wakeup(wl); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 129 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 130 | ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 131 | if (ret < 0) |
| 132 | return ret; |
| 133 | } |
| 134 | |
| 135 | return 0; |
| 136 | } |
| 137 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 138 | int wl1251_ps_set_mode(struct wl1251 *wl, enum wl1251_cmd_ps_mode mode) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 139 | { |
| 140 | int ret; |
| 141 | |
| 142 | switch (mode) { |
| 143 | case STATION_POWER_SAVE_MODE: |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 144 | wl1251_debug(DEBUG_PSM, "entering psm"); |
Kalle Valo | 4a81892 | 2009-08-07 13:34:56 +0300 | [diff] [blame] | 145 | |
Juuso Oikarinen | 6b21a2c | 2009-11-17 18:48:30 +0200 | [diff] [blame] | 146 | /* enable beacon filtering */ |
| 147 | ret = wl1251_acx_beacon_filter_opt(wl, true); |
| 148 | if (ret < 0) |
| 149 | return ret; |
| 150 | |
Kalle Valo | 4a81892 | 2009-08-07 13:34:56 +0300 | [diff] [blame] | 151 | ret = wl1251_acx_wake_up_conditions(wl, |
| 152 | WAKE_UP_EVENT_DTIM_BITMAP, |
| 153 | wl->listen_int); |
| 154 | if (ret < 0) |
| 155 | return ret; |
| 156 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 157 | ret = wl1251_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 158 | if (ret < 0) |
| 159 | return ret; |
| 160 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 161 | ret = wl1251_ps_set_elp(wl, true); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 162 | if (ret < 0) |
| 163 | return ret; |
| 164 | |
| 165 | wl->psm = 1; |
| 166 | break; |
| 167 | case STATION_ACTIVE_MODE: |
| 168 | default: |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 169 | wl1251_debug(DEBUG_PSM, "leaving psm"); |
| 170 | ret = wl1251_ps_set_elp(wl, false); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 171 | if (ret < 0) |
| 172 | return ret; |
| 173 | |
Juuso Oikarinen | 6b21a2c | 2009-11-17 18:48:30 +0200 | [diff] [blame] | 174 | /* disable beacon filtering */ |
| 175 | ret = wl1251_acx_beacon_filter_opt(wl, false); |
| 176 | if (ret < 0) |
| 177 | return ret; |
| 178 | |
Kalle Valo | 4a81892 | 2009-08-07 13:34:56 +0300 | [diff] [blame] | 179 | ret = wl1251_acx_wake_up_conditions(wl, |
| 180 | WAKE_UP_EVENT_DTIM_BITMAP, |
| 181 | wl->listen_int); |
| 182 | if (ret < 0) |
| 183 | return ret; |
| 184 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 185 | ret = wl1251_cmd_ps_mode(wl, STATION_ACTIVE_MODE); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 186 | if (ret < 0) |
| 187 | return ret; |
| 188 | |
| 189 | wl->psm = 0; |
| 190 | break; |
| 191 | } |
| 192 | |
| 193 | return ret; |
| 194 | } |
| 195 | |