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 | b5a1679 | 2009-11-30 10:17:59 +0200 | [diff] [blame] | 29 | /* in ms */ |
| 30 | #define WL1251_WAKEUP_TIMEOUT 100 |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 31 | |
Juuso Oikarinen | d5da79a | 2009-11-17 18:48:37 +0200 | [diff] [blame] | 32 | void wl1251_elp_work(struct work_struct *work) |
| 33 | { |
| 34 | struct delayed_work *dwork; |
| 35 | struct wl1251 *wl; |
| 36 | |
| 37 | dwork = container_of(work, struct delayed_work, work); |
| 38 | wl = container_of(dwork, struct wl1251, elp_work); |
| 39 | |
| 40 | wl1251_debug(DEBUG_PSM, "elp work"); |
| 41 | |
| 42 | mutex_lock(&wl->mutex); |
| 43 | |
| 44 | if (wl->elp || !wl->psm) |
| 45 | goto out; |
| 46 | |
| 47 | wl1251_debug(DEBUG_PSM, "chip to elp"); |
Grazvydas Ignotas | 3f9e750 | 2010-03-11 17:44:57 +0200 | [diff] [blame] | 48 | wl1251_write_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP); |
Juuso Oikarinen | d5da79a | 2009-11-17 18:48:37 +0200 | [diff] [blame] | 49 | wl->elp = true; |
| 50 | |
| 51 | out: |
| 52 | mutex_unlock(&wl->mutex); |
| 53 | } |
| 54 | |
| 55 | #define ELP_ENTRY_DELAY 5 |
| 56 | |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 57 | /* Routines to toggle sleep mode while in ELP */ |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 58 | void wl1251_ps_elp_sleep(struct wl1251 *wl) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 59 | { |
Juuso Oikarinen | d5da79a | 2009-11-17 18:48:37 +0200 | [diff] [blame] | 60 | unsigned long delay; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 61 | |
Juuso Oikarinen | d5da79a | 2009-11-17 18:48:37 +0200 | [diff] [blame] | 62 | if (wl->psm) { |
| 63 | cancel_delayed_work(&wl->elp_work); |
| 64 | delay = msecs_to_jiffies(ELP_ENTRY_DELAY); |
| 65 | ieee80211_queue_delayed_work(wl->hw, &wl->elp_work, delay); |
| 66 | } |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 67 | } |
| 68 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 69 | int wl1251_ps_elp_wakeup(struct wl1251 *wl) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 70 | { |
Kalle Valo | 7fa6282 | 2009-11-30 10:18:06 +0200 | [diff] [blame] | 71 | unsigned long timeout, start; |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 72 | u32 elp_reg; |
| 73 | |
| 74 | if (!wl->elp) |
| 75 | return 0; |
| 76 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 77 | wl1251_debug(DEBUG_PSM, "waking up chip from elp"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 78 | |
Kalle Valo | 7fa6282 | 2009-11-30 10:18:06 +0200 | [diff] [blame] | 79 | start = jiffies; |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 80 | timeout = jiffies + msecs_to_jiffies(WL1251_WAKEUP_TIMEOUT); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 81 | |
Grazvydas Ignotas | 3f9e750 | 2010-03-11 17:44:57 +0200 | [diff] [blame] | 82 | 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] | 83 | |
Grazvydas Ignotas | 3f9e750 | 2010-03-11 17:44:57 +0200 | [diff] [blame] | 84 | elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 85 | |
| 86 | /* |
| 87 | * FIXME: we should wait for irq from chip but, as a temporary |
| 88 | * solution to simplify locking, let's poll instead |
| 89 | */ |
| 90 | while (!(elp_reg & ELPCTRL_WLAN_READY)) { |
| 91 | if (time_after(jiffies, timeout)) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 92 | wl1251_error("elp wakeup timeout"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 93 | return -ETIMEDOUT; |
| 94 | } |
| 95 | msleep(1); |
Grazvydas Ignotas | 3f9e750 | 2010-03-11 17:44:57 +0200 | [diff] [blame] | 96 | elp_reg = wl1251_read_elp(wl, HW_ACCESS_ELP_CTRL_REG_ADDR); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 97 | } |
| 98 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 99 | wl1251_debug(DEBUG_PSM, "wakeup time: %u ms", |
Kalle Valo | 7fa6282 | 2009-11-30 10:18:06 +0200 | [diff] [blame] | 100 | jiffies_to_msecs(jiffies - start)); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 101 | |
| 102 | wl->elp = false; |
| 103 | |
| 104 | return 0; |
| 105 | } |
| 106 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 107 | static int wl1251_ps_set_elp(struct wl1251 *wl, bool enable) |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 108 | { |
| 109 | int ret; |
| 110 | |
| 111 | if (enable) { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 112 | wl1251_debug(DEBUG_PSM, "sleep auth psm/elp"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 113 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 114 | ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_ELP); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 115 | if (ret < 0) |
| 116 | return ret; |
| 117 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 118 | wl1251_ps_elp_sleep(wl); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 119 | } else { |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 120 | wl1251_debug(DEBUG_PSM, "sleep auth cam"); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 121 | |
| 122 | /* |
| 123 | * When the target is in ELP, we can only |
| 124 | * access the ELP control register. Thus, |
| 125 | * we have to wake the target up before |
| 126 | * changing the power authorization. |
| 127 | */ |
| 128 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 129 | wl1251_ps_elp_wakeup(wl); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 130 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 131 | ret = wl1251_acx_sleep_auth(wl, WL1251_PSM_CAM); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 132 | if (ret < 0) |
| 133 | return ret; |
| 134 | } |
| 135 | |
| 136 | return 0; |
| 137 | } |
| 138 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 139 | 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] | 140 | { |
| 141 | int ret; |
| 142 | |
| 143 | switch (mode) { |
| 144 | case STATION_POWER_SAVE_MODE: |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 145 | wl1251_debug(DEBUG_PSM, "entering psm"); |
Kalle Valo | 4a81892 | 2009-08-07 13:34:56 +0300 | [diff] [blame] | 146 | |
Juuso Oikarinen | 6b21a2c | 2009-11-17 18:48:30 +0200 | [diff] [blame] | 147 | /* enable beacon filtering */ |
| 148 | ret = wl1251_acx_beacon_filter_opt(wl, true); |
| 149 | if (ret < 0) |
| 150 | return ret; |
| 151 | |
Kalle Valo | 4a81892 | 2009-08-07 13:34:56 +0300 | [diff] [blame] | 152 | ret = wl1251_acx_wake_up_conditions(wl, |
| 153 | WAKE_UP_EVENT_DTIM_BITMAP, |
| 154 | wl->listen_int); |
| 155 | if (ret < 0) |
| 156 | return ret; |
| 157 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 158 | ret = wl1251_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 159 | if (ret < 0) |
| 160 | return ret; |
| 161 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 162 | ret = wl1251_ps_set_elp(wl, true); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 163 | if (ret < 0) |
| 164 | return ret; |
| 165 | |
| 166 | wl->psm = 1; |
| 167 | break; |
| 168 | case STATION_ACTIVE_MODE: |
| 169 | default: |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 170 | wl1251_debug(DEBUG_PSM, "leaving psm"); |
| 171 | ret = wl1251_ps_set_elp(wl, false); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 172 | if (ret < 0) |
| 173 | return ret; |
| 174 | |
Juuso Oikarinen | 6b21a2c | 2009-11-17 18:48:30 +0200 | [diff] [blame] | 175 | /* disable beacon filtering */ |
| 176 | ret = wl1251_acx_beacon_filter_opt(wl, false); |
| 177 | if (ret < 0) |
| 178 | return ret; |
| 179 | |
Kalle Valo | 4a81892 | 2009-08-07 13:34:56 +0300 | [diff] [blame] | 180 | ret = wl1251_acx_wake_up_conditions(wl, |
| 181 | WAKE_UP_EVENT_DTIM_BITMAP, |
| 182 | wl->listen_int); |
| 183 | if (ret < 0) |
| 184 | return ret; |
| 185 | |
Kalle Valo | 80301cd | 2009-06-12 14:17:39 +0300 | [diff] [blame] | 186 | ret = wl1251_cmd_ps_mode(wl, STATION_ACTIVE_MODE); |
Kalle Valo | 2f01a1f | 2009-04-29 23:33:31 +0300 | [diff] [blame] | 187 | if (ret < 0) |
| 188 | return ret; |
| 189 | |
| 190 | wl->psm = 0; |
| 191 | break; |
| 192 | } |
| 193 | |
| 194 | return ret; |
| 195 | } |
| 196 | |