Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
Reinette Chatre | 01f8162 | 2009-01-08 10:20:02 -0800 | [diff] [blame] | 3 | * Copyright(c) 2007 - 2009 Intel Corporation. All rights reserved. |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 4 | * |
| 5 | * Portions of this file are derived from the ipw3945 project, as well |
| 6 | * as portions of the ieee80211 subsystem header files. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of version 2 of the GNU General Public License as |
| 10 | * published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 13 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 14 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 15 | * more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along with |
| 18 | * this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution in the |
| 22 | * file called LICENSE. |
| 23 | * |
| 24 | * Contact Information: |
Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | *****************************************************************************/ |
| 28 | |
| 29 | |
| 30 | #include <linux/kernel.h> |
| 31 | #include <linux/module.h> |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 32 | #include <linux/init.h> |
| 33 | |
| 34 | #include <net/mac80211.h> |
| 35 | |
| 36 | #include "iwl-eeprom.h" |
Tomas Winkler | 3e0d4cb | 2008-04-24 11:55:38 -0700 | [diff] [blame] | 37 | #include "iwl-dev.h" |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 38 | #include "iwl-core.h" |
Tomas Winkler | 5a36ba0 | 2008-04-24 11:55:37 -0700 | [diff] [blame] | 39 | #include "iwl-commands.h" |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 40 | #include "iwl-debug.h" |
| 41 | #include "iwl-power.h" |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 42 | |
| 43 | /* |
| 44 | * Setting power level allow the card to go to sleep when not busy |
| 45 | * there are three factor that decide the power level to go to, they |
| 46 | * are list here with its priority |
| 47 | * 1- critical_power_setting this will be set according to card temperature. |
| 48 | * 2- system_power_setting this will be set by system PM manager. |
| 49 | * 3- user_power_setting this will be set by user either by writing to sys or |
| 50 | * mac80211 |
| 51 | * |
| 52 | * if system_power_setting and user_power_setting is set to auto |
| 53 | * the power level will be decided according to association status and battery |
| 54 | * status. |
| 55 | * |
| 56 | */ |
| 57 | |
| 58 | #define MSEC_TO_USEC 1024 |
| 59 | #define IWL_POWER_RANGE_0_MAX (2) |
| 60 | #define IWL_POWER_RANGE_1_MAX (10) |
| 61 | |
| 62 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 63 | |
| 64 | #define IWL_POWER_ON_BATTERY IWL_POWER_INDEX_5 |
| 65 | #define IWL_POWER_ON_AC_DISASSOC IWL_POWER_MODE_CAM |
| 66 | #define IWL_POWER_ON_AC_ASSOC IWL_POWER_MODE_CAM |
| 67 | |
| 68 | |
| 69 | #define IWL_CT_KILL_TEMPERATURE 110 |
| 70 | #define IWL_MIN_POWER_TEMPERATURE 100 |
| 71 | #define IWL_REDUCED_POWER_TEMPERATURE 95 |
| 72 | |
| 73 | /* default power management (not Tx power) table values */ |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 74 | /* for TIM 0-10 */ |
Esti Kummer | 298df1f | 2008-07-18 13:52:58 +0800 | [diff] [blame] | 75 | static struct iwl_power_vec_entry range_0[IWL_POWER_MAX] = { |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 76 | {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 77 | {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0}, |
| 78 | {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0}, |
| 79 | {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 2, 2, 2, 0xFF)}, 0}, |
| 80 | {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 2, 4, 4, 0xFF)}, 1}, |
| 81 | {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(2, 2, 4, 6, 0xFF)}, 2} |
| 82 | }; |
| 83 | |
| 84 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 85 | /* for TIM = 3-10 */ |
Esti Kummer | 298df1f | 2008-07-18 13:52:58 +0800 | [diff] [blame] | 86 | static struct iwl_power_vec_entry range_1[IWL_POWER_MAX] = { |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 87 | {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 88 | {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, |
| 89 | {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 3, 4, 7)}, 0}, |
| 90 | {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 4, 6, 7, 9)}, 0}, |
| 91 | {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 4, 6, 9, 10)}, 1}, |
| 92 | {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(2, 4, 7, 10, 10)}, 2} |
| 93 | }; |
| 94 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 95 | /* for TIM > 11 */ |
Esti Kummer | 298df1f | 2008-07-18 13:52:58 +0800 | [diff] [blame] | 96 | static struct iwl_power_vec_entry range_2[IWL_POWER_MAX] = { |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 97 | {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, |
| 98 | {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, |
| 99 | {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 0xFF)}, 0}, |
| 100 | {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, |
| 101 | {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0}, |
| 102 | {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(4, 7, 10, 10, 0xFF)}, 0} |
| 103 | }; |
| 104 | |
Winkler, Tomas | d25aabb | 2009-01-27 14:27:58 -0800 | [diff] [blame] | 105 | |
Mohamed Abbas | ca57961 | 2008-07-18 13:52:57 +0800 | [diff] [blame] | 106 | /* set card power command */ |
| 107 | static int iwl_set_power(struct iwl_priv *priv, void *cmd) |
| 108 | { |
| 109 | return iwl_send_cmd_pdu_async(priv, POWER_TABLE_CMD, |
| 110 | sizeof(struct iwl_powertable_cmd), |
| 111 | cmd, NULL); |
| 112 | } |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 113 | /* decide the right power level according to association status |
| 114 | * and battery status |
| 115 | */ |
| 116 | static u16 iwl_get_auto_power_mode(struct iwl_priv *priv) |
| 117 | { |
Esti Kummer | 298df1f | 2008-07-18 13:52:58 +0800 | [diff] [blame] | 118 | u16 mode; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 119 | |
| 120 | switch (priv->power_data.user_power_setting) { |
| 121 | case IWL_POWER_AUTO: |
| 122 | /* if running on battery */ |
| 123 | if (priv->power_data.is_battery_active) |
| 124 | mode = IWL_POWER_ON_BATTERY; |
| 125 | else if (iwl_is_associated(priv)) |
| 126 | mode = IWL_POWER_ON_AC_ASSOC; |
| 127 | else |
| 128 | mode = IWL_POWER_ON_AC_DISASSOC; |
| 129 | break; |
Esti Kummer | 298df1f | 2008-07-18 13:52:58 +0800 | [diff] [blame] | 130 | default: |
| 131 | mode = priv->power_data.user_power_setting; |
| 132 | break; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 133 | } |
| 134 | return mode; |
| 135 | } |
| 136 | |
| 137 | /* initialize to default */ |
Winkler, Tomas | 5cd19c5 | 2009-01-19 15:30:21 -0800 | [diff] [blame] | 138 | static void iwl_power_init_handle(struct iwl_priv *priv) |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 139 | { |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 140 | struct iwl_power_mgr *pow_data; |
Esti Kummer | 298df1f | 2008-07-18 13:52:58 +0800 | [diff] [blame] | 141 | int size = sizeof(struct iwl_power_vec_entry) * IWL_POWER_MAX; |
Tomas Winkler | e7b6358 | 2008-09-03 11:26:49 +0800 | [diff] [blame] | 142 | struct iwl_powertable_cmd *cmd; |
| 143 | int i; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 144 | u16 pci_pm; |
| 145 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 146 | IWL_DEBUG_POWER(priv, "Initialize power \n"); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 147 | |
Winkler, Tomas | 5cd19c5 | 2009-01-19 15:30:21 -0800 | [diff] [blame] | 148 | pow_data = &priv->power_data; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 149 | |
| 150 | memset(pow_data, 0, sizeof(*pow_data)); |
| 151 | |
| 152 | memcpy(&pow_data->pwr_range_0[0], &range_0[0], size); |
| 153 | memcpy(&pow_data->pwr_range_1[0], &range_1[0], size); |
| 154 | memcpy(&pow_data->pwr_range_2[0], &range_2[0], size); |
| 155 | |
Tomas Winkler | e7b6358 | 2008-09-03 11:26:49 +0800 | [diff] [blame] | 156 | pci_read_config_word(priv->pci_dev, PCI_CFG_LINK_CTRL, &pci_pm); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 157 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 158 | IWL_DEBUG_POWER(priv, "adjust power command flags\n"); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 159 | |
Tomas Winkler | e7b6358 | 2008-09-03 11:26:49 +0800 | [diff] [blame] | 160 | for (i = 0; i < IWL_POWER_MAX; i++) { |
| 161 | cmd = &pow_data->pwr_range_0[i].cmd; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 162 | |
Tomas Winkler | e7b6358 | 2008-09-03 11:26:49 +0800 | [diff] [blame] | 163 | if (pci_pm & PCI_CFG_LINK_CTRL_VAL_L0S_EN) |
| 164 | cmd->flags &= ~IWL_POWER_PCI_PM_MSK; |
| 165 | else |
| 166 | cmd->flags |= IWL_POWER_PCI_PM_MSK; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 167 | } |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 170 | /* adjust power command according to DTIM period and power level*/ |
Winkler, Tomas | 5cd19c5 | 2009-01-19 15:30:21 -0800 | [diff] [blame] | 171 | static int iwl_update_power_cmd(struct iwl_priv *priv, |
| 172 | struct iwl_powertable_cmd *cmd, u16 mode) |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 173 | { |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 174 | struct iwl_power_vec_entry *range; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 175 | struct iwl_power_mgr *pow_data; |
Winkler, Tomas | 5cd19c5 | 2009-01-19 15:30:21 -0800 | [diff] [blame] | 176 | int i; |
| 177 | u32 max_sleep = 0; |
| 178 | u8 period; |
| 179 | bool skip; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 180 | |
| 181 | if (mode > IWL_POWER_INDEX_5) { |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 182 | IWL_DEBUG_POWER(priv, "Error invalid power mode \n"); |
Winkler, Tomas | 5cd19c5 | 2009-01-19 15:30:21 -0800 | [diff] [blame] | 183 | return -EINVAL; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 184 | } |
Winkler, Tomas | 5cd19c5 | 2009-01-19 15:30:21 -0800 | [diff] [blame] | 185 | |
| 186 | pow_data = &priv->power_data; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 187 | |
| 188 | if (pow_data->dtim_period <= IWL_POWER_RANGE_0_MAX) |
| 189 | range = &pow_data->pwr_range_0[0]; |
| 190 | else if (pow_data->dtim_period <= IWL_POWER_RANGE_1_MAX) |
| 191 | range = &pow_data->pwr_range_1[0]; |
| 192 | else |
| 193 | range = &pow_data->pwr_range_2[0]; |
| 194 | |
| 195 | period = pow_data->dtim_period; |
Mohamed Abbas | ca57961 | 2008-07-18 13:52:57 +0800 | [diff] [blame] | 196 | memcpy(cmd, &range[mode].cmd, sizeof(struct iwl_powertable_cmd)); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 197 | |
| 198 | if (period == 0) { |
| 199 | period = 1; |
Winkler, Tomas | 5cd19c5 | 2009-01-19 15:30:21 -0800 | [diff] [blame] | 200 | skip = false; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 201 | } else { |
Winkler, Tomas | 5cd19c5 | 2009-01-19 15:30:21 -0800 | [diff] [blame] | 202 | skip = !!range[mode].no_dtim; |
| 203 | } |
| 204 | |
| 205 | if (skip) { |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 206 | __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]; |
| 207 | max_sleep = le32_to_cpu(slp_itrvl); |
| 208 | if (max_sleep == 0xFF) |
| 209 | max_sleep = period * (skip + 1); |
| 210 | else if (max_sleep > period) |
| 211 | max_sleep = (le32_to_cpu(slp_itrvl) / period) * period; |
| 212 | cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK; |
Winkler, Tomas | 5cd19c5 | 2009-01-19 15:30:21 -0800 | [diff] [blame] | 213 | } else { |
| 214 | max_sleep = period; |
| 215 | cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 216 | } |
| 217 | |
Winkler, Tomas | 5cd19c5 | 2009-01-19 15:30:21 -0800 | [diff] [blame] | 218 | for (i = 0; i < IWL_POWER_VEC_SIZE; i++) |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 219 | if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep) |
| 220 | cmd->sleep_interval[i] = cpu_to_le32(max_sleep); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 221 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 222 | IWL_DEBUG_POWER(priv, "Flags value = 0x%08X\n", cmd->flags); |
| 223 | IWL_DEBUG_POWER(priv, "Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout)); |
| 224 | IWL_DEBUG_POWER(priv, "Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout)); |
| 225 | IWL_DEBUG_POWER(priv, "Sleep interval vector = { %d , %d , %d , %d , %d }\n", |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 226 | le32_to_cpu(cmd->sleep_interval[0]), |
| 227 | le32_to_cpu(cmd->sleep_interval[1]), |
| 228 | le32_to_cpu(cmd->sleep_interval[2]), |
| 229 | le32_to_cpu(cmd->sleep_interval[3]), |
| 230 | le32_to_cpu(cmd->sleep_interval[4])); |
| 231 | |
Winkler, Tomas | 5cd19c5 | 2009-01-19 15:30:21 -0800 | [diff] [blame] | 232 | return 0; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | |
| 236 | /* |
Emmanuel Grumbach | a33c2f4 | 2008-09-03 11:26:56 +0800 | [diff] [blame] | 237 | * compute the final power mode index |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 238 | */ |
Grumbach, Emmanuel | 0481644 | 2008-09-03 11:26:53 +0800 | [diff] [blame] | 239 | int iwl_power_update_mode(struct iwl_priv *priv, bool force) |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 240 | { |
| 241 | struct iwl_power_mgr *setting = &(priv->power_data); |
| 242 | int ret = 0; |
| 243 | u16 uninitialized_var(final_mode); |
Winkler, Tomas | a71c8f6 | 2008-11-07 09:58:37 -0800 | [diff] [blame] | 244 | bool update_chains; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 245 | |
Grumbach, Emmanuel | 0481644 | 2008-09-03 11:26:53 +0800 | [diff] [blame] | 246 | /* Don't update the RX chain when chain noise calibration is running */ |
Winkler, Tomas | a71c8f6 | 2008-11-07 09:58:37 -0800 | [diff] [blame] | 247 | update_chains = priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE || |
| 248 | priv->chain_noise_data.state == IWL_CHAIN_NOISE_ALIVE; |
Grumbach, Emmanuel | 0481644 | 2008-09-03 11:26:53 +0800 | [diff] [blame] | 249 | |
Emmanuel Grumbach | a33c2f4 | 2008-09-03 11:26:56 +0800 | [diff] [blame] | 250 | /* If on battery, set to 3, |
| 251 | * if plugged into AC power, set to CAM ("continuously aware mode"), |
| 252 | * else user level */ |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 253 | |
| 254 | switch (setting->system_power_setting) { |
Esti Kummer | 298df1f | 2008-07-18 13:52:58 +0800 | [diff] [blame] | 255 | case IWL_POWER_SYS_AUTO: |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 256 | final_mode = iwl_get_auto_power_mode(priv); |
| 257 | break; |
Esti Kummer | 298df1f | 2008-07-18 13:52:58 +0800 | [diff] [blame] | 258 | case IWL_POWER_SYS_BATTERY: |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 259 | final_mode = IWL_POWER_INDEX_3; |
| 260 | break; |
Esti Kummer | 298df1f | 2008-07-18 13:52:58 +0800 | [diff] [blame] | 261 | case IWL_POWER_SYS_AC: |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 262 | final_mode = IWL_POWER_MODE_CAM; |
| 263 | break; |
| 264 | default: |
Esti Kummer | 298df1f | 2008-07-18 13:52:58 +0800 | [diff] [blame] | 265 | final_mode = IWL_POWER_INDEX_3; |
| 266 | WARN_ON(1); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | if (setting->critical_power_setting > final_mode) |
| 270 | final_mode = setting->critical_power_setting; |
| 271 | |
| 272 | /* driver only support CAM for non STA network */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 273 | if (priv->iw_mode != NL80211_IFTYPE_STATION) |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 274 | final_mode = IWL_POWER_MODE_CAM; |
| 275 | |
| 276 | if (!iwl_is_rfkill(priv) && !setting->power_disabled && |
Grumbach, Emmanuel | 0481644 | 2008-09-03 11:26:53 +0800 | [diff] [blame] | 277 | ((setting->power_mode != final_mode) || force)) { |
Mohamed Abbas | ca57961 | 2008-07-18 13:52:57 +0800 | [diff] [blame] | 278 | struct iwl_powertable_cmd cmd; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 279 | |
| 280 | if (final_mode != IWL_POWER_MODE_CAM) |
| 281 | set_bit(STATUS_POWER_PMI, &priv->status); |
| 282 | |
Winkler, Tomas | 5cd19c5 | 2009-01-19 15:30:21 -0800 | [diff] [blame] | 283 | iwl_update_power_cmd(priv, &cmd, final_mode); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 284 | cmd.keep_alive_beacons = 0; |
| 285 | |
| 286 | if (final_mode == IWL_POWER_INDEX_5) |
| 287 | cmd.flags |= IWL_POWER_FAST_PD; |
| 288 | |
Mohamed Abbas | ca57961 | 2008-07-18 13:52:57 +0800 | [diff] [blame] | 289 | ret = iwl_set_power(priv, &cmd); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 290 | |
| 291 | if (final_mode == IWL_POWER_MODE_CAM) |
| 292 | clear_bit(STATUS_POWER_PMI, &priv->status); |
| 293 | else |
| 294 | set_bit(STATUS_POWER_PMI, &priv->status); |
| 295 | |
Winkler, Tomas | a71c8f6 | 2008-11-07 09:58:37 -0800 | [diff] [blame] | 296 | if (priv->cfg->ops->lib->update_chain_flags && update_chains) |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 297 | priv->cfg->ops->lib->update_chain_flags(priv); |
Winkler, Tomas | a71c8f6 | 2008-11-07 09:58:37 -0800 | [diff] [blame] | 298 | else |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 299 | IWL_DEBUG_POWER(priv, "Cannot update the power, chain noise " |
Winkler, Tomas | a71c8f6 | 2008-11-07 09:58:37 -0800 | [diff] [blame] | 300 | "calibration running: %d\n", |
| 301 | priv->chain_noise_data.state); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 302 | if (!ret) |
| 303 | setting->power_mode = final_mode; |
| 304 | } |
| 305 | |
| 306 | return ret; |
| 307 | } |
| 308 | EXPORT_SYMBOL(iwl_power_update_mode); |
| 309 | |
| 310 | /* Allow other iwl code to disable/enable power management active |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 311 | * this will be useful for rate scale to disable PM during heavy |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 312 | * Tx/Rx activities |
| 313 | */ |
Emmanuel Grumbach | c90a74ba | 2008-09-03 11:26:50 +0800 | [diff] [blame] | 314 | int iwl_power_disable_management(struct iwl_priv *priv, u32 ms) |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 315 | { |
| 316 | u16 prev_mode; |
| 317 | int ret = 0; |
| 318 | |
| 319 | if (priv->power_data.power_disabled) |
| 320 | return -EBUSY; |
| 321 | |
| 322 | prev_mode = priv->power_data.user_power_setting; |
| 323 | priv->power_data.user_power_setting = IWL_POWER_MODE_CAM; |
| 324 | ret = iwl_power_update_mode(priv, 0); |
| 325 | priv->power_data.power_disabled = 1; |
| 326 | priv->power_data.user_power_setting = prev_mode; |
Emmanuel Grumbach | c90a74ba | 2008-09-03 11:26:50 +0800 | [diff] [blame] | 327 | cancel_delayed_work(&priv->set_power_save); |
| 328 | if (ms) |
| 329 | queue_delayed_work(priv->workqueue, &priv->set_power_save, |
| 330 | msecs_to_jiffies(ms)); |
| 331 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 332 | |
| 333 | return ret; |
| 334 | } |
| 335 | EXPORT_SYMBOL(iwl_power_disable_management); |
| 336 | |
| 337 | /* Allow other iwl code to disable/enable power management active |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 338 | * this will be useful for rate scale to disable PM during high |
| 339 | * volume activities |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 340 | */ |
| 341 | int iwl_power_enable_management(struct iwl_priv *priv) |
| 342 | { |
| 343 | int ret = 0; |
| 344 | |
| 345 | priv->power_data.power_disabled = 0; |
| 346 | ret = iwl_power_update_mode(priv, 0); |
| 347 | return ret; |
| 348 | } |
| 349 | EXPORT_SYMBOL(iwl_power_enable_management); |
| 350 | |
| 351 | /* set user_power_setting */ |
| 352 | int iwl_power_set_user_mode(struct iwl_priv *priv, u16 mode) |
| 353 | { |
Winkler, Tomas | d25aabb | 2009-01-27 14:27:58 -0800 | [diff] [blame] | 354 | if (mode > IWL_POWER_MAX) |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 355 | return -EINVAL; |
| 356 | |
| 357 | priv->power_data.user_power_setting = mode; |
| 358 | |
Grumbach, Emmanuel | 0481644 | 2008-09-03 11:26:53 +0800 | [diff] [blame] | 359 | return iwl_power_update_mode(priv, 0); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 360 | } |
| 361 | EXPORT_SYMBOL(iwl_power_set_user_mode); |
| 362 | |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 363 | /* set system_power_setting. This should be set by over all |
| 364 | * PM application. |
| 365 | */ |
| 366 | int iwl_power_set_system_mode(struct iwl_priv *priv, u16 mode) |
| 367 | { |
Winkler, Tomas | d25aabb | 2009-01-27 14:27:58 -0800 | [diff] [blame] | 368 | if (mode < IWL_POWER_SYS_MAX) |
| 369 | priv->power_data.system_power_setting = mode; |
| 370 | else |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 371 | return -EINVAL; |
Grumbach, Emmanuel | 0481644 | 2008-09-03 11:26:53 +0800 | [diff] [blame] | 372 | return iwl_power_update_mode(priv, 0); |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 373 | } |
| 374 | EXPORT_SYMBOL(iwl_power_set_system_mode); |
| 375 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 376 | /* initialize to default */ |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 377 | void iwl_power_initialize(struct iwl_priv *priv) |
| 378 | { |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 379 | iwl_power_init_handle(priv); |
| 380 | priv->power_data.user_power_setting = IWL_POWER_AUTO; |
Esti Kummer | 298df1f | 2008-07-18 13:52:58 +0800 | [diff] [blame] | 381 | priv->power_data.system_power_setting = IWL_POWER_SYS_AUTO; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 382 | priv->power_data.power_disabled = 0; |
Winkler, Tomas | 5cd19c5 | 2009-01-19 15:30:21 -0800 | [diff] [blame] | 383 | priv->power_data.is_battery_active = 0; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 384 | priv->power_data.critical_power_setting = 0; |
| 385 | } |
| 386 | EXPORT_SYMBOL(iwl_power_initialize); |
| 387 | |
| 388 | /* set critical_power_setting according to temperature value */ |
| 389 | int iwl_power_temperature_change(struct iwl_priv *priv) |
| 390 | { |
| 391 | int ret = 0; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 392 | s32 temperature = KELVIN_TO_CELSIUS(priv->last_temperature); |
Winkler, Tomas | 5cd19c5 | 2009-01-19 15:30:21 -0800 | [diff] [blame] | 393 | u16 new_critical = priv->power_data.critical_power_setting; |
Mohamed Abbas | 5da4b55 | 2008-04-21 15:41:51 -0700 | [diff] [blame] | 394 | |
| 395 | if (temperature > IWL_CT_KILL_TEMPERATURE) |
| 396 | return 0; |
| 397 | else if (temperature > IWL_MIN_POWER_TEMPERATURE) |
| 398 | new_critical = IWL_POWER_INDEX_5; |
| 399 | else if (temperature > IWL_REDUCED_POWER_TEMPERATURE) |
| 400 | new_critical = IWL_POWER_INDEX_3; |
| 401 | else |
| 402 | new_critical = IWL_POWER_MODE_CAM; |
| 403 | |
| 404 | if (new_critical != priv->power_data.critical_power_setting) |
| 405 | priv->power_data.critical_power_setting = new_critical; |
| 406 | |
| 407 | if (priv->power_data.critical_power_setting > |
| 408 | priv->power_data.power_mode) |
| 409 | ret = iwl_power_update_mode(priv, 0); |
| 410 | |
| 411 | return ret; |
| 412 | } |
| 413 | EXPORT_SYMBOL(iwl_power_temperature_change); |
Emmanuel Grumbach | c90a74ba | 2008-09-03 11:26:50 +0800 | [diff] [blame] | 414 | |
| 415 | static void iwl_bg_set_power_save(struct work_struct *work) |
| 416 | { |
| 417 | struct iwl_priv *priv = container_of(work, |
| 418 | struct iwl_priv, set_power_save.work); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 419 | IWL_DEBUG_POWER(priv, "update power\n"); |
Emmanuel Grumbach | c90a74ba | 2008-09-03 11:26:50 +0800 | [diff] [blame] | 420 | |
| 421 | if (test_bit(STATUS_EXIT_PENDING, &priv->status)) |
| 422 | return; |
| 423 | |
| 424 | mutex_lock(&priv->mutex); |
| 425 | |
Tomas Winkler | a96a27f | 2008-10-23 23:48:56 -0700 | [diff] [blame] | 426 | /* on starting association we disable power management |
Emmanuel Grumbach | c90a74ba | 2008-09-03 11:26:50 +0800 | [diff] [blame] | 427 | * until association, if association failed then this |
| 428 | * timer will expire and enable PM again. |
| 429 | */ |
| 430 | if (!iwl_is_associated(priv)) |
| 431 | iwl_power_enable_management(priv); |
| 432 | |
| 433 | mutex_unlock(&priv->mutex); |
| 434 | } |
| 435 | void iwl_setup_power_deferred_work(struct iwl_priv *priv) |
| 436 | { |
| 437 | INIT_DELAYED_WORK(&priv->set_power_save, iwl_bg_set_power_save); |
| 438 | } |
| 439 | EXPORT_SYMBOL(iwl_setup_power_deferred_work); |
| 440 | |
| 441 | void iwl_power_cancel_timeout(struct iwl_priv *priv) |
| 442 | { |
| 443 | cancel_delayed_work(&priv->set_power_save); |
| 444 | } |
| 445 | EXPORT_SYMBOL(iwl_power_cancel_timeout); |