blob: a9f9ffe4b94e0364024298408d862117cca22f2f [file] [log] [blame]
Mohamed Abbas5da4b552008-04-21 15:41:51 -07001/******************************************************************************
2 *
Reinette Chatre01f81622009-01-08 10:20:02 -08003 * Copyright(c) 2007 - 2009 Intel Corporation. All rights reserved.
Mohamed Abbas5da4b552008-04-21 15:41:51 -07004 *
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, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Mohamed Abbas5da4b552008-04-21 15:41:51 -070026 * 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 Abbas5da4b552008-04-21 15:41:51 -070032#include <linux/init.h>
33
34#include <net/mac80211.h>
35
36#include "iwl-eeprom.h"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070037#include "iwl-dev.h"
Mohamed Abbas5da4b552008-04-21 15:41:51 -070038#include "iwl-core.h"
Tomas Winkler5a36ba02008-04-24 11:55:37 -070039#include "iwl-commands.h"
Mohamed Abbas5da4b552008-04-21 15:41:51 -070040#include "iwl-debug.h"
41#include "iwl-power.h"
Mohamed Abbas5da4b552008-04-21 15:41:51 -070042
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
63#define NOSLP __constant_cpu_to_le16(0), 0, 0
64#define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
65#define SLP_TOUT(T) __constant_cpu_to_le32((T) * MSEC_TO_USEC)
66#define SLP_VEC(X0, X1, X2, X3, X4) {__constant_cpu_to_le32(X0), \
67 __constant_cpu_to_le32(X1), \
68 __constant_cpu_to_le32(X2), \
69 __constant_cpu_to_le32(X3), \
70 __constant_cpu_to_le32(X4)}
71
72#define IWL_POWER_ON_BATTERY IWL_POWER_INDEX_5
73#define IWL_POWER_ON_AC_DISASSOC IWL_POWER_MODE_CAM
74#define IWL_POWER_ON_AC_ASSOC IWL_POWER_MODE_CAM
75
76
77#define IWL_CT_KILL_TEMPERATURE 110
78#define IWL_MIN_POWER_TEMPERATURE 100
79#define IWL_REDUCED_POWER_TEMPERATURE 95
80
81/* default power management (not Tx power) table values */
Tomas Winklera96a27f2008-10-23 23:48:56 -070082/* for TIM 0-10 */
Esti Kummer298df1f2008-07-18 13:52:58 +080083static struct iwl_power_vec_entry range_0[IWL_POWER_MAX] = {
Mohamed Abbas5da4b552008-04-21 15:41:51 -070084 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
85 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0},
86 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0},
87 {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 2, 2, 2, 0xFF)}, 0},
88 {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 2, 4, 4, 0xFF)}, 1},
89 {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(2, 2, 4, 6, 0xFF)}, 2}
90};
91
92
Tomas Winklera96a27f2008-10-23 23:48:56 -070093/* for TIM = 3-10 */
Esti Kummer298df1f2008-07-18 13:52:58 +080094static struct iwl_power_vec_entry range_1[IWL_POWER_MAX] = {
Mohamed Abbas5da4b552008-04-21 15:41:51 -070095 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
96 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
97 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 3, 4, 7)}, 0},
98 {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 4, 6, 7, 9)}, 0},
99 {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 4, 6, 9, 10)}, 1},
100 {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(2, 4, 7, 10, 10)}, 2}
101};
102
Tomas Winklera96a27f2008-10-23 23:48:56 -0700103/* for TIM > 11 */
Esti Kummer298df1f2008-07-18 13:52:58 +0800104static struct iwl_power_vec_entry range_2[IWL_POWER_MAX] = {
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700105 {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
106 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
107 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
108 {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
109 {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
110 {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
111};
112
Mohamed Abbasca579612008-07-18 13:52:57 +0800113/* set card power command */
114static int iwl_set_power(struct iwl_priv *priv, void *cmd)
115{
116 return iwl_send_cmd_pdu_async(priv, POWER_TABLE_CMD,
117 sizeof(struct iwl_powertable_cmd),
118 cmd, NULL);
119}
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700120/* decide the right power level according to association status
121 * and battery status
122 */
123static u16 iwl_get_auto_power_mode(struct iwl_priv *priv)
124{
Esti Kummer298df1f2008-07-18 13:52:58 +0800125 u16 mode;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700126
127 switch (priv->power_data.user_power_setting) {
128 case IWL_POWER_AUTO:
129 /* if running on battery */
130 if (priv->power_data.is_battery_active)
131 mode = IWL_POWER_ON_BATTERY;
132 else if (iwl_is_associated(priv))
133 mode = IWL_POWER_ON_AC_ASSOC;
134 else
135 mode = IWL_POWER_ON_AC_DISASSOC;
136 break;
Esti Kummer298df1f2008-07-18 13:52:58 +0800137 /* FIXME: remove battery and ac from here */
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700138 case IWL_POWER_BATTERY:
139 mode = IWL_POWER_INDEX_3;
140 break;
141 case IWL_POWER_AC:
142 mode = IWL_POWER_MODE_CAM;
143 break;
Esti Kummer298df1f2008-07-18 13:52:58 +0800144 default:
145 mode = priv->power_data.user_power_setting;
146 break;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700147 }
148 return mode;
149}
150
151/* initialize to default */
152static int iwl_power_init_handle(struct iwl_priv *priv)
153{
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700154 struct iwl_power_mgr *pow_data;
Esti Kummer298df1f2008-07-18 13:52:58 +0800155 int size = sizeof(struct iwl_power_vec_entry) * IWL_POWER_MAX;
Tomas Winklere7b63582008-09-03 11:26:49 +0800156 struct iwl_powertable_cmd *cmd;
157 int i;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700158 u16 pci_pm;
159
160 IWL_DEBUG_POWER("Initialize power \n");
161
162 pow_data = &(priv->power_data);
163
164 memset(pow_data, 0, sizeof(*pow_data));
165
166 memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
167 memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
168 memcpy(&pow_data->pwr_range_2[0], &range_2[0], size);
169
Tomas Winklere7b63582008-09-03 11:26:49 +0800170 pci_read_config_word(priv->pci_dev, PCI_CFG_LINK_CTRL, &pci_pm);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700171
Tomas Winklere7b63582008-09-03 11:26:49 +0800172 IWL_DEBUG_POWER("adjust power command flags\n");
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700173
Tomas Winklere7b63582008-09-03 11:26:49 +0800174 for (i = 0; i < IWL_POWER_MAX; i++) {
175 cmd = &pow_data->pwr_range_0[i].cmd;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700176
Tomas Winklere7b63582008-09-03 11:26:49 +0800177 if (pci_pm & PCI_CFG_LINK_CTRL_VAL_L0S_EN)
178 cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
179 else
180 cmd->flags |= IWL_POWER_PCI_PM_MSK;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700181 }
Tomas Winklere7b63582008-09-03 11:26:49 +0800182 return 0;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700183}
184
Tomas Winklera96a27f2008-10-23 23:48:56 -0700185/* adjust power command according to DTIM period and power level*/
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700186static int iwl_update_power_command(struct iwl_priv *priv,
Mohamed Abbasca579612008-07-18 13:52:57 +0800187 struct iwl_powertable_cmd *cmd,
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700188 u16 mode)
189{
190 int ret = 0, i;
191 u8 skip;
192 u32 max_sleep = 0;
193 struct iwl_power_vec_entry *range;
194 u8 period = 0;
195 struct iwl_power_mgr *pow_data;
196
197 if (mode > IWL_POWER_INDEX_5) {
198 IWL_DEBUG_POWER("Error invalid power mode \n");
199 return -1;
200 }
201 pow_data = &(priv->power_data);
202
203 if (pow_data->dtim_period <= IWL_POWER_RANGE_0_MAX)
204 range = &pow_data->pwr_range_0[0];
205 else if (pow_data->dtim_period <= IWL_POWER_RANGE_1_MAX)
206 range = &pow_data->pwr_range_1[0];
207 else
208 range = &pow_data->pwr_range_2[0];
209
210 period = pow_data->dtim_period;
Mohamed Abbasca579612008-07-18 13:52:57 +0800211 memcpy(cmd, &range[mode].cmd, sizeof(struct iwl_powertable_cmd));
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700212
213 if (period == 0) {
214 period = 1;
215 skip = 0;
216 } else
217 skip = range[mode].no_dtim;
218
219 if (skip == 0) {
220 max_sleep = period;
221 cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
222 } else {
223 __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
224 max_sleep = le32_to_cpu(slp_itrvl);
225 if (max_sleep == 0xFF)
226 max_sleep = period * (skip + 1);
227 else if (max_sleep > period)
228 max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
229 cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
230 }
231
232 for (i = 0; i < IWL_POWER_VEC_SIZE; i++) {
233 if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
234 cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
235 }
236
237 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
238 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
239 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
240 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
241 le32_to_cpu(cmd->sleep_interval[0]),
242 le32_to_cpu(cmd->sleep_interval[1]),
243 le32_to_cpu(cmd->sleep_interval[2]),
244 le32_to_cpu(cmd->sleep_interval[3]),
245 le32_to_cpu(cmd->sleep_interval[4]));
246
247 return ret;
248}
249
250
251/*
Emmanuel Grumbacha33c2f42008-09-03 11:26:56 +0800252 * compute the final power mode index
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700253 */
Grumbach, Emmanuel04816442008-09-03 11:26:53 +0800254int iwl_power_update_mode(struct iwl_priv *priv, bool force)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700255{
256 struct iwl_power_mgr *setting = &(priv->power_data);
257 int ret = 0;
258 u16 uninitialized_var(final_mode);
Winkler, Tomasa71c8f62008-11-07 09:58:37 -0800259 bool update_chains;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700260
Grumbach, Emmanuel04816442008-09-03 11:26:53 +0800261 /* Don't update the RX chain when chain noise calibration is running */
Winkler, Tomasa71c8f62008-11-07 09:58:37 -0800262 update_chains = priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE ||
263 priv->chain_noise_data.state == IWL_CHAIN_NOISE_ALIVE;
Grumbach, Emmanuel04816442008-09-03 11:26:53 +0800264
Emmanuel Grumbacha33c2f42008-09-03 11:26:56 +0800265 /* If on battery, set to 3,
266 * if plugged into AC power, set to CAM ("continuously aware mode"),
267 * else user level */
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700268
269 switch (setting->system_power_setting) {
Esti Kummer298df1f2008-07-18 13:52:58 +0800270 case IWL_POWER_SYS_AUTO:
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700271 final_mode = iwl_get_auto_power_mode(priv);
272 break;
Esti Kummer298df1f2008-07-18 13:52:58 +0800273 case IWL_POWER_SYS_BATTERY:
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700274 final_mode = IWL_POWER_INDEX_3;
275 break;
Esti Kummer298df1f2008-07-18 13:52:58 +0800276 case IWL_POWER_SYS_AC:
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700277 final_mode = IWL_POWER_MODE_CAM;
278 break;
279 default:
Esti Kummer298df1f2008-07-18 13:52:58 +0800280 final_mode = IWL_POWER_INDEX_3;
281 WARN_ON(1);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700282 }
283
284 if (setting->critical_power_setting > final_mode)
285 final_mode = setting->critical_power_setting;
286
287 /* driver only support CAM for non STA network */
Johannes Berg05c914f2008-09-11 00:01:58 +0200288 if (priv->iw_mode != NL80211_IFTYPE_STATION)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700289 final_mode = IWL_POWER_MODE_CAM;
290
291 if (!iwl_is_rfkill(priv) && !setting->power_disabled &&
Grumbach, Emmanuel04816442008-09-03 11:26:53 +0800292 ((setting->power_mode != final_mode) || force)) {
Mohamed Abbasca579612008-07-18 13:52:57 +0800293 struct iwl_powertable_cmd cmd;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700294
295 if (final_mode != IWL_POWER_MODE_CAM)
296 set_bit(STATUS_POWER_PMI, &priv->status);
297
298 iwl_update_power_command(priv, &cmd, final_mode);
299 cmd.keep_alive_beacons = 0;
300
301 if (final_mode == IWL_POWER_INDEX_5)
302 cmd.flags |= IWL_POWER_FAST_PD;
303
Mohamed Abbasca579612008-07-18 13:52:57 +0800304 ret = iwl_set_power(priv, &cmd);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700305
306 if (final_mode == IWL_POWER_MODE_CAM)
307 clear_bit(STATUS_POWER_PMI, &priv->status);
308 else
309 set_bit(STATUS_POWER_PMI, &priv->status);
310
Winkler, Tomasa71c8f62008-11-07 09:58:37 -0800311 if (priv->cfg->ops->lib->update_chain_flags && update_chains)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700312 priv->cfg->ops->lib->update_chain_flags(priv);
Winkler, Tomasa71c8f62008-11-07 09:58:37 -0800313 else
314 IWL_DEBUG_POWER("Cannot update the power, chain noise "
315 "calibration running: %d\n",
316 priv->chain_noise_data.state);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700317 if (!ret)
318 setting->power_mode = final_mode;
319 }
320
321 return ret;
322}
323EXPORT_SYMBOL(iwl_power_update_mode);
324
325/* Allow other iwl code to disable/enable power management active
Tomas Winklera96a27f2008-10-23 23:48:56 -0700326 * this will be useful for rate scale to disable PM during heavy
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700327 * Tx/Rx activities
328 */
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +0800329int iwl_power_disable_management(struct iwl_priv *priv, u32 ms)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700330{
331 u16 prev_mode;
332 int ret = 0;
333
334 if (priv->power_data.power_disabled)
335 return -EBUSY;
336
337 prev_mode = priv->power_data.user_power_setting;
338 priv->power_data.user_power_setting = IWL_POWER_MODE_CAM;
339 ret = iwl_power_update_mode(priv, 0);
340 priv->power_data.power_disabled = 1;
341 priv->power_data.user_power_setting = prev_mode;
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +0800342 cancel_delayed_work(&priv->set_power_save);
343 if (ms)
344 queue_delayed_work(priv->workqueue, &priv->set_power_save,
345 msecs_to_jiffies(ms));
346
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700347
348 return ret;
349}
350EXPORT_SYMBOL(iwl_power_disable_management);
351
352/* Allow other iwl code to disable/enable power management active
Tomas Winklera96a27f2008-10-23 23:48:56 -0700353 * this will be useful for rate scale to disable PM during high
354 * volume activities
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700355 */
356int iwl_power_enable_management(struct iwl_priv *priv)
357{
358 int ret = 0;
359
360 priv->power_data.power_disabled = 0;
361 ret = iwl_power_update_mode(priv, 0);
362 return ret;
363}
364EXPORT_SYMBOL(iwl_power_enable_management);
365
366/* set user_power_setting */
367int iwl_power_set_user_mode(struct iwl_priv *priv, u16 mode)
368{
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700369 if (mode > IWL_POWER_LIMIT)
370 return -EINVAL;
371
372 priv->power_data.user_power_setting = mode;
373
Grumbach, Emmanuel04816442008-09-03 11:26:53 +0800374 return iwl_power_update_mode(priv, 0);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700375}
376EXPORT_SYMBOL(iwl_power_set_user_mode);
377
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700378/* set system_power_setting. This should be set by over all
379 * PM application.
380 */
381int iwl_power_set_system_mode(struct iwl_priv *priv, u16 mode)
382{
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700383 if (mode > IWL_POWER_LIMIT)
384 return -EINVAL;
385
386 priv->power_data.system_power_setting = mode;
387
Grumbach, Emmanuel04816442008-09-03 11:26:53 +0800388 return iwl_power_update_mode(priv, 0);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700389}
390EXPORT_SYMBOL(iwl_power_set_system_mode);
391
Tomas Winklera96a27f2008-10-23 23:48:56 -0700392/* initialize to default */
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700393void iwl_power_initialize(struct iwl_priv *priv)
394{
395
396 iwl_power_init_handle(priv);
397 priv->power_data.user_power_setting = IWL_POWER_AUTO;
398 priv->power_data.power_disabled = 0;
Esti Kummer298df1f2008-07-18 13:52:58 +0800399 priv->power_data.system_power_setting = IWL_POWER_SYS_AUTO;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700400 priv->power_data.is_battery_active = 0;
401 priv->power_data.power_disabled = 0;
402 priv->power_data.critical_power_setting = 0;
403}
404EXPORT_SYMBOL(iwl_power_initialize);
405
406/* set critical_power_setting according to temperature value */
407int iwl_power_temperature_change(struct iwl_priv *priv)
408{
409 int ret = 0;
410 u16 new_critical = priv->power_data.critical_power_setting;
411 s32 temperature = KELVIN_TO_CELSIUS(priv->last_temperature);
412
413 if (temperature > IWL_CT_KILL_TEMPERATURE)
414 return 0;
415 else if (temperature > IWL_MIN_POWER_TEMPERATURE)
416 new_critical = IWL_POWER_INDEX_5;
417 else if (temperature > IWL_REDUCED_POWER_TEMPERATURE)
418 new_critical = IWL_POWER_INDEX_3;
419 else
420 new_critical = IWL_POWER_MODE_CAM;
421
422 if (new_critical != priv->power_data.critical_power_setting)
423 priv->power_data.critical_power_setting = new_critical;
424
425 if (priv->power_data.critical_power_setting >
426 priv->power_data.power_mode)
427 ret = iwl_power_update_mode(priv, 0);
428
429 return ret;
430}
431EXPORT_SYMBOL(iwl_power_temperature_change);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +0800432
433static void iwl_bg_set_power_save(struct work_struct *work)
434{
435 struct iwl_priv *priv = container_of(work,
436 struct iwl_priv, set_power_save.work);
437 IWL_DEBUG(IWL_DL_STATE, "update power\n");
438
439 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
440 return;
441
442 mutex_lock(&priv->mutex);
443
Tomas Winklera96a27f2008-10-23 23:48:56 -0700444 /* on starting association we disable power management
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +0800445 * until association, if association failed then this
446 * timer will expire and enable PM again.
447 */
448 if (!iwl_is_associated(priv))
449 iwl_power_enable_management(priv);
450
451 mutex_unlock(&priv->mutex);
452}
453void iwl_setup_power_deferred_work(struct iwl_priv *priv)
454{
455 INIT_DELAYED_WORK(&priv->set_power_save, iwl_bg_set_power_save);
456}
457EXPORT_SYMBOL(iwl_setup_power_deferred_work);
458
459void iwl_power_cancel_timeout(struct iwl_priv *priv)
460{
461 cancel_delayed_work(&priv->set_power_save);
462}
463EXPORT_SYMBOL(iwl_power_cancel_timeout);