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