Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of wl1271 |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 Nokia Corporation |
| 5 | * |
| 6 | * Contact: Luciano Coelho <luciano.coelho@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 | |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 24 | #include "reg.h" |
| 25 | #include "ps.h" |
| 26 | #include "io.h" |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 27 | |
| 28 | #define WL1271_WAKEUP_TIMEOUT 500 |
| 29 | |
Juuso Oikarinen | 37b70a8 | 2009-10-08 21:56:21 +0300 | [diff] [blame] | 30 | void wl1271_elp_work(struct work_struct *work) |
| 31 | { |
| 32 | struct delayed_work *dwork; |
| 33 | struct wl1271 *wl; |
| 34 | |
| 35 | dwork = container_of(work, struct delayed_work, work); |
| 36 | wl = container_of(dwork, struct wl1271, elp_work); |
| 37 | |
| 38 | wl1271_debug(DEBUG_PSM, "elp work"); |
| 39 | |
| 40 | mutex_lock(&wl->mutex); |
| 41 | |
Juuso Oikarinen | 8c7f4f3 | 2010-09-21 06:23:29 +0200 | [diff] [blame] | 42 | if (unlikely(wl->state == WL1271_STATE_OFF)) |
| 43 | goto out; |
| 44 | |
Juuso Oikarinen | 71449f8 | 2009-12-11 15:41:07 +0200 | [diff] [blame] | 45 | if (test_bit(WL1271_FLAG_IN_ELP, &wl->flags) || |
Juuso Oikarinen | e197281 | 2010-04-09 11:07:29 +0300 | [diff] [blame] | 46 | (!test_bit(WL1271_FLAG_PSM, &wl->flags) && |
| 47 | !test_bit(WL1271_FLAG_IDLE, &wl->flags))) |
Juuso Oikarinen | 37b70a8 | 2009-10-08 21:56:21 +0300 | [diff] [blame] | 48 | goto out; |
| 49 | |
| 50 | wl1271_debug(DEBUG_PSM, "chip to elp"); |
Juuso Oikarinen | 7462141 | 2009-10-12 15:08:54 +0300 | [diff] [blame] | 51 | wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_SLEEP); |
Juuso Oikarinen | 71449f8 | 2009-12-11 15:41:07 +0200 | [diff] [blame] | 52 | set_bit(WL1271_FLAG_IN_ELP, &wl->flags); |
Juuso Oikarinen | 37b70a8 | 2009-10-08 21:56:21 +0300 | [diff] [blame] | 53 | |
| 54 | out: |
| 55 | mutex_unlock(&wl->mutex); |
| 56 | } |
| 57 | |
| 58 | #define ELP_ENTRY_DELAY 5 |
| 59 | |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 60 | /* Routines to toggle sleep mode while in ELP */ |
| 61 | void wl1271_ps_elp_sleep(struct wl1271 *wl) |
| 62 | { |
Juuso Oikarinen | e197281 | 2010-04-09 11:07:29 +0300 | [diff] [blame] | 63 | if (test_bit(WL1271_FLAG_PSM, &wl->flags) || |
| 64 | test_bit(WL1271_FLAG_IDLE, &wl->flags)) { |
Juuso Oikarinen | 37b70a8 | 2009-10-08 21:56:21 +0300 | [diff] [blame] | 65 | cancel_delayed_work(&wl->elp_work); |
| 66 | ieee80211_queue_delayed_work(wl->hw, &wl->elp_work, |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 67 | msecs_to_jiffies(ELP_ENTRY_DELAY)); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 68 | } |
| 69 | } |
| 70 | |
| 71 | int wl1271_ps_elp_wakeup(struct wl1271 *wl, bool chip_awake) |
| 72 | { |
| 73 | DECLARE_COMPLETION_ONSTACK(compl); |
| 74 | unsigned long flags; |
| 75 | int ret; |
| 76 | u32 start_time = jiffies; |
| 77 | bool pending = false; |
| 78 | |
Juuso Oikarinen | 71449f8 | 2009-12-11 15:41:07 +0200 | [diff] [blame] | 79 | if (!test_bit(WL1271_FLAG_IN_ELP, &wl->flags)) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 80 | return 0; |
| 81 | |
| 82 | wl1271_debug(DEBUG_PSM, "waking up chip from elp"); |
| 83 | |
| 84 | /* |
| 85 | * The spinlock is required here to synchronize both the work and |
| 86 | * the completion variable in one entity. |
| 87 | */ |
| 88 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 89 | if (work_pending(&wl->irq_work) || chip_awake) |
| 90 | pending = true; |
| 91 | else |
| 92 | wl->elp_compl = &compl; |
| 93 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 94 | |
Juuso Oikarinen | 7462141 | 2009-10-12 15:08:54 +0300 | [diff] [blame] | 95 | wl1271_raw_write32(wl, HW_ACCESS_ELP_CTRL_REG_ADDR, ELPCTRL_WAKE_UP); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 96 | |
| 97 | if (!pending) { |
| 98 | ret = wait_for_completion_timeout( |
| 99 | &compl, msecs_to_jiffies(WL1271_WAKEUP_TIMEOUT)); |
| 100 | if (ret == 0) { |
| 101 | wl1271_error("ELP wakeup timeout!"); |
Juuso Oikarinen | 52b0e7a | 2010-09-21 06:23:31 +0200 | [diff] [blame] | 102 | ieee80211_queue_work(wl->hw, &wl->recovery_work); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 103 | ret = -ETIMEDOUT; |
| 104 | goto err; |
| 105 | } else if (ret < 0) { |
| 106 | wl1271_error("ELP wakeup completion error."); |
| 107 | goto err; |
| 108 | } |
| 109 | } |
| 110 | |
Juuso Oikarinen | 71449f8 | 2009-12-11 15:41:07 +0200 | [diff] [blame] | 111 | clear_bit(WL1271_FLAG_IN_ELP, &wl->flags); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 112 | |
| 113 | wl1271_debug(DEBUG_PSM, "wakeup time: %u ms", |
| 114 | jiffies_to_msecs(jiffies - start_time)); |
| 115 | goto out; |
| 116 | |
| 117 | err: |
| 118 | spin_lock_irqsave(&wl->wl_lock, flags); |
| 119 | wl->elp_compl = NULL; |
| 120 | spin_unlock_irqrestore(&wl->wl_lock, flags); |
| 121 | return ret; |
| 122 | |
| 123 | out: |
| 124 | return 0; |
| 125 | } |
| 126 | |
Juuso Oikarinen | d8c42c0 | 2010-02-18 13:25:36 +0200 | [diff] [blame] | 127 | int wl1271_ps_set_mode(struct wl1271 *wl, enum wl1271_cmd_ps_mode mode, |
Juuso Oikarinen | 65cddbf1 | 2010-08-24 06:28:03 +0300 | [diff] [blame] | 128 | u32 rates, bool send) |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 129 | { |
| 130 | int ret; |
| 131 | |
| 132 | switch (mode) { |
| 133 | case STATION_POWER_SAVE_MODE: |
| 134 | wl1271_debug(DEBUG_PSM, "entering psm"); |
Juuso Oikarinen | 1922167 | 2009-10-08 21:56:35 +0300 | [diff] [blame] | 135 | |
Juuso Oikarinen | 03f06b7 | 2010-08-10 06:38:36 +0200 | [diff] [blame] | 136 | ret = wl1271_acx_wake_up_conditions(wl); |
| 137 | if (ret < 0) { |
| 138 | wl1271_error("couldn't set wake up conditions"); |
| 139 | return ret; |
| 140 | } |
| 141 | |
Eliad Peller | c8bde24 | 2011-02-02 09:59:35 +0200 | [diff] [blame] | 142 | ret = wl1271_cmd_ps_mode(wl, STATION_POWER_SAVE_MODE); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 143 | if (ret < 0) |
| 144 | return ret; |
| 145 | |
Juuso Oikarinen | 71449f8 | 2009-12-11 15:41:07 +0200 | [diff] [blame] | 146 | set_bit(WL1271_FLAG_PSM, &wl->flags); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 147 | break; |
| 148 | case STATION_ACTIVE_MODE: |
| 149 | default: |
| 150 | wl1271_debug(DEBUG_PSM, "leaving psm"); |
| 151 | ret = wl1271_ps_elp_wakeup(wl, false); |
| 152 | if (ret < 0) |
| 153 | return ret; |
| 154 | |
Juuso Oikarinen | 11f70f9 | 2009-10-13 12:47:46 +0300 | [diff] [blame] | 155 | /* disable beacon early termination */ |
| 156 | ret = wl1271_acx_bet_enable(wl, false); |
| 157 | if (ret < 0) |
| 158 | return ret; |
| 159 | |
Juuso Oikarinen | 1922167 | 2009-10-08 21:56:35 +0300 | [diff] [blame] | 160 | /* disable beacon filtering */ |
| 161 | ret = wl1271_acx_beacon_filter_opt(wl, false); |
| 162 | if (ret < 0) |
| 163 | return ret; |
| 164 | |
Eliad Peller | c8bde24 | 2011-02-02 09:59:35 +0200 | [diff] [blame] | 165 | ret = wl1271_cmd_ps_mode(wl, STATION_ACTIVE_MODE); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 166 | if (ret < 0) |
| 167 | return ret; |
| 168 | |
Juuso Oikarinen | 71449f8 | 2009-12-11 15:41:07 +0200 | [diff] [blame] | 169 | clear_bit(WL1271_FLAG_PSM, &wl->flags); |
Luciano Coelho | f5fc0f8 | 2009-08-06 16:25:28 +0300 | [diff] [blame] | 170 | break; |
| 171 | } |
| 172 | |
| 173 | return ret; |
| 174 | } |
| 175 | |
| 176 | |