blob: abe0d2966a5632fd3b6eaf92b0602d0376f46e81 [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
Mohamed Abbas5da4b552008-04-21 15:41:51 -070063
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 Winklera96a27f2008-10-23 23:48:56 -070074/* for TIM 0-10 */
Esti Kummer298df1f2008-07-18 13:52:58 +080075static struct iwl_power_vec_entry range_0[IWL_POWER_MAX] = {
Mohamed Abbas5da4b552008-04-21 15:41:51 -070076 {{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 Winklera96a27f2008-10-23 23:48:56 -070085/* for TIM = 3-10 */
Esti Kummer298df1f2008-07-18 13:52:58 +080086static struct iwl_power_vec_entry range_1[IWL_POWER_MAX] = {
Mohamed Abbas5da4b552008-04-21 15:41:51 -070087 {{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 Winklera96a27f2008-10-23 23:48:56 -070095/* for TIM > 11 */
Esti Kummer298df1f2008-07-18 13:52:58 +080096static struct iwl_power_vec_entry range_2[IWL_POWER_MAX] = {
Mohamed Abbas5da4b552008-04-21 15:41:51 -070097 {{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
Mohamed Abbasca579612008-07-18 13:52:57 +0800105/* set card power command */
106static int iwl_set_power(struct iwl_priv *priv, void *cmd)
107{
108 return iwl_send_cmd_pdu_async(priv, POWER_TABLE_CMD,
109 sizeof(struct iwl_powertable_cmd),
110 cmd, NULL);
111}
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700112/* decide the right power level according to association status
113 * and battery status
114 */
115static u16 iwl_get_auto_power_mode(struct iwl_priv *priv)
116{
Esti Kummer298df1f2008-07-18 13:52:58 +0800117 u16 mode;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700118
119 switch (priv->power_data.user_power_setting) {
120 case IWL_POWER_AUTO:
121 /* if running on battery */
122 if (priv->power_data.is_battery_active)
123 mode = IWL_POWER_ON_BATTERY;
124 else if (iwl_is_associated(priv))
125 mode = IWL_POWER_ON_AC_ASSOC;
126 else
127 mode = IWL_POWER_ON_AC_DISASSOC;
128 break;
Esti Kummer298df1f2008-07-18 13:52:58 +0800129 /* FIXME: remove battery and ac from here */
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700130 case IWL_POWER_BATTERY:
131 mode = IWL_POWER_INDEX_3;
132 break;
133 case IWL_POWER_AC:
134 mode = IWL_POWER_MODE_CAM;
135 break;
Esti Kummer298df1f2008-07-18 13:52:58 +0800136 default:
137 mode = priv->power_data.user_power_setting;
138 break;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700139 }
140 return mode;
141}
142
143/* initialize to default */
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800144static void iwl_power_init_handle(struct iwl_priv *priv)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700145{
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700146 struct iwl_power_mgr *pow_data;
Esti Kummer298df1f2008-07-18 13:52:58 +0800147 int size = sizeof(struct iwl_power_vec_entry) * IWL_POWER_MAX;
Tomas Winklere7b63582008-09-03 11:26:49 +0800148 struct iwl_powertable_cmd *cmd;
149 int i;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700150 u16 pci_pm;
151
Tomas Winklere1623442009-01-27 14:27:56 -0800152 IWL_DEBUG_POWER(priv, "Initialize power \n");
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700153
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800154 pow_data = &priv->power_data;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700155
156 memset(pow_data, 0, sizeof(*pow_data));
157
158 memcpy(&pow_data->pwr_range_0[0], &range_0[0], size);
159 memcpy(&pow_data->pwr_range_1[0], &range_1[0], size);
160 memcpy(&pow_data->pwr_range_2[0], &range_2[0], size);
161
Tomas Winklere7b63582008-09-03 11:26:49 +0800162 pci_read_config_word(priv->pci_dev, PCI_CFG_LINK_CTRL, &pci_pm);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700163
Tomas Winklere1623442009-01-27 14:27:56 -0800164 IWL_DEBUG_POWER(priv, "adjust power command flags\n");
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700165
Tomas Winklere7b63582008-09-03 11:26:49 +0800166 for (i = 0; i < IWL_POWER_MAX; i++) {
167 cmd = &pow_data->pwr_range_0[i].cmd;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700168
Tomas Winklere7b63582008-09-03 11:26:49 +0800169 if (pci_pm & PCI_CFG_LINK_CTRL_VAL_L0S_EN)
170 cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
171 else
172 cmd->flags |= IWL_POWER_PCI_PM_MSK;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700173 }
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700174}
175
Tomas Winklera96a27f2008-10-23 23:48:56 -0700176/* adjust power command according to DTIM period and power level*/
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800177static int iwl_update_power_cmd(struct iwl_priv *priv,
178 struct iwl_powertable_cmd *cmd, u16 mode)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700179{
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700180 struct iwl_power_vec_entry *range;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700181 struct iwl_power_mgr *pow_data;
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800182 int i;
183 u32 max_sleep = 0;
184 u8 period;
185 bool skip;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700186
187 if (mode > IWL_POWER_INDEX_5) {
Tomas Winklere1623442009-01-27 14:27:56 -0800188 IWL_DEBUG_POWER(priv, "Error invalid power mode \n");
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800189 return -EINVAL;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700190 }
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800191
192 pow_data = &priv->power_data;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700193
194 if (pow_data->dtim_period <= IWL_POWER_RANGE_0_MAX)
195 range = &pow_data->pwr_range_0[0];
196 else if (pow_data->dtim_period <= IWL_POWER_RANGE_1_MAX)
197 range = &pow_data->pwr_range_1[0];
198 else
199 range = &pow_data->pwr_range_2[0];
200
201 period = pow_data->dtim_period;
Mohamed Abbasca579612008-07-18 13:52:57 +0800202 memcpy(cmd, &range[mode].cmd, sizeof(struct iwl_powertable_cmd));
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700203
204 if (period == 0) {
205 period = 1;
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800206 skip = false;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700207 } else {
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800208 skip = !!range[mode].no_dtim;
209 }
210
211 if (skip) {
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700212 __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
213 max_sleep = le32_to_cpu(slp_itrvl);
214 if (max_sleep == 0xFF)
215 max_sleep = period * (skip + 1);
216 else if (max_sleep > period)
217 max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
218 cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800219 } else {
220 max_sleep = period;
221 cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700222 }
223
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800224 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700225 if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
226 cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700227
Tomas Winklere1623442009-01-27 14:27:56 -0800228 IWL_DEBUG_POWER(priv, "Flags value = 0x%08X\n", cmd->flags);
229 IWL_DEBUG_POWER(priv, "Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
230 IWL_DEBUG_POWER(priv, "Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
231 IWL_DEBUG_POWER(priv, "Sleep interval vector = { %d , %d , %d , %d , %d }\n",
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700232 le32_to_cpu(cmd->sleep_interval[0]),
233 le32_to_cpu(cmd->sleep_interval[1]),
234 le32_to_cpu(cmd->sleep_interval[2]),
235 le32_to_cpu(cmd->sleep_interval[3]),
236 le32_to_cpu(cmd->sleep_interval[4]));
237
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800238 return 0;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700239}
240
241
242/*
Emmanuel Grumbacha33c2f42008-09-03 11:26:56 +0800243 * compute the final power mode index
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700244 */
Grumbach, Emmanuel04816442008-09-03 11:26:53 +0800245int iwl_power_update_mode(struct iwl_priv *priv, bool force)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700246{
247 struct iwl_power_mgr *setting = &(priv->power_data);
248 int ret = 0;
249 u16 uninitialized_var(final_mode);
Winkler, Tomasa71c8f62008-11-07 09:58:37 -0800250 bool update_chains;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700251
Grumbach, Emmanuel04816442008-09-03 11:26:53 +0800252 /* Don't update the RX chain when chain noise calibration is running */
Winkler, Tomasa71c8f62008-11-07 09:58:37 -0800253 update_chains = priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE ||
254 priv->chain_noise_data.state == IWL_CHAIN_NOISE_ALIVE;
Grumbach, Emmanuel04816442008-09-03 11:26:53 +0800255
Emmanuel Grumbacha33c2f42008-09-03 11:26:56 +0800256 /* If on battery, set to 3,
257 * if plugged into AC power, set to CAM ("continuously aware mode"),
258 * else user level */
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700259
260 switch (setting->system_power_setting) {
Esti Kummer298df1f2008-07-18 13:52:58 +0800261 case IWL_POWER_SYS_AUTO:
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700262 final_mode = iwl_get_auto_power_mode(priv);
263 break;
Esti Kummer298df1f2008-07-18 13:52:58 +0800264 case IWL_POWER_SYS_BATTERY:
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700265 final_mode = IWL_POWER_INDEX_3;
266 break;
Esti Kummer298df1f2008-07-18 13:52:58 +0800267 case IWL_POWER_SYS_AC:
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700268 final_mode = IWL_POWER_MODE_CAM;
269 break;
270 default:
Esti Kummer298df1f2008-07-18 13:52:58 +0800271 final_mode = IWL_POWER_INDEX_3;
272 WARN_ON(1);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700273 }
274
275 if (setting->critical_power_setting > final_mode)
276 final_mode = setting->critical_power_setting;
277
278 /* driver only support CAM for non STA network */
Johannes Berg05c914f2008-09-11 00:01:58 +0200279 if (priv->iw_mode != NL80211_IFTYPE_STATION)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700280 final_mode = IWL_POWER_MODE_CAM;
281
282 if (!iwl_is_rfkill(priv) && !setting->power_disabled &&
Grumbach, Emmanuel04816442008-09-03 11:26:53 +0800283 ((setting->power_mode != final_mode) || force)) {
Mohamed Abbasca579612008-07-18 13:52:57 +0800284 struct iwl_powertable_cmd cmd;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700285
286 if (final_mode != IWL_POWER_MODE_CAM)
287 set_bit(STATUS_POWER_PMI, &priv->status);
288
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800289 iwl_update_power_cmd(priv, &cmd, final_mode);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700290 cmd.keep_alive_beacons = 0;
291
292 if (final_mode == IWL_POWER_INDEX_5)
293 cmd.flags |= IWL_POWER_FAST_PD;
294
Mohamed Abbasca579612008-07-18 13:52:57 +0800295 ret = iwl_set_power(priv, &cmd);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700296
297 if (final_mode == IWL_POWER_MODE_CAM)
298 clear_bit(STATUS_POWER_PMI, &priv->status);
299 else
300 set_bit(STATUS_POWER_PMI, &priv->status);
301
Winkler, Tomasa71c8f62008-11-07 09:58:37 -0800302 if (priv->cfg->ops->lib->update_chain_flags && update_chains)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700303 priv->cfg->ops->lib->update_chain_flags(priv);
Winkler, Tomasa71c8f62008-11-07 09:58:37 -0800304 else
Tomas Winklere1623442009-01-27 14:27:56 -0800305 IWL_DEBUG_POWER(priv, "Cannot update the power, chain noise "
Winkler, Tomasa71c8f62008-11-07 09:58:37 -0800306 "calibration running: %d\n",
307 priv->chain_noise_data.state);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700308 if (!ret)
309 setting->power_mode = final_mode;
310 }
311
312 return ret;
313}
314EXPORT_SYMBOL(iwl_power_update_mode);
315
316/* Allow other iwl code to disable/enable power management active
Tomas Winklera96a27f2008-10-23 23:48:56 -0700317 * this will be useful for rate scale to disable PM during heavy
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700318 * Tx/Rx activities
319 */
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +0800320int iwl_power_disable_management(struct iwl_priv *priv, u32 ms)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700321{
322 u16 prev_mode;
323 int ret = 0;
324
325 if (priv->power_data.power_disabled)
326 return -EBUSY;
327
328 prev_mode = priv->power_data.user_power_setting;
329 priv->power_data.user_power_setting = IWL_POWER_MODE_CAM;
330 ret = iwl_power_update_mode(priv, 0);
331 priv->power_data.power_disabled = 1;
332 priv->power_data.user_power_setting = prev_mode;
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +0800333 cancel_delayed_work(&priv->set_power_save);
334 if (ms)
335 queue_delayed_work(priv->workqueue, &priv->set_power_save,
336 msecs_to_jiffies(ms));
337
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700338
339 return ret;
340}
341EXPORT_SYMBOL(iwl_power_disable_management);
342
343/* Allow other iwl code to disable/enable power management active
Tomas Winklera96a27f2008-10-23 23:48:56 -0700344 * this will be useful for rate scale to disable PM during high
345 * volume activities
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700346 */
347int iwl_power_enable_management(struct iwl_priv *priv)
348{
349 int ret = 0;
350
351 priv->power_data.power_disabled = 0;
352 ret = iwl_power_update_mode(priv, 0);
353 return ret;
354}
355EXPORT_SYMBOL(iwl_power_enable_management);
356
357/* set user_power_setting */
358int iwl_power_set_user_mode(struct iwl_priv *priv, u16 mode)
359{
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700360 if (mode > IWL_POWER_LIMIT)
361 return -EINVAL;
362
363 priv->power_data.user_power_setting = mode;
364
Grumbach, Emmanuel04816442008-09-03 11:26:53 +0800365 return iwl_power_update_mode(priv, 0);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700366}
367EXPORT_SYMBOL(iwl_power_set_user_mode);
368
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700369/* set system_power_setting. This should be set by over all
370 * PM application.
371 */
372int iwl_power_set_system_mode(struct iwl_priv *priv, u16 mode)
373{
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700374 if (mode > IWL_POWER_LIMIT)
375 return -EINVAL;
376
377 priv->power_data.system_power_setting = mode;
378
Grumbach, Emmanuel04816442008-09-03 11:26:53 +0800379 return iwl_power_update_mode(priv, 0);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700380}
381EXPORT_SYMBOL(iwl_power_set_system_mode);
382
Tomas Winklera96a27f2008-10-23 23:48:56 -0700383/* initialize to default */
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700384void iwl_power_initialize(struct iwl_priv *priv)
385{
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700386 iwl_power_init_handle(priv);
387 priv->power_data.user_power_setting = IWL_POWER_AUTO;
Esti Kummer298df1f2008-07-18 13:52:58 +0800388 priv->power_data.system_power_setting = IWL_POWER_SYS_AUTO;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700389 priv->power_data.power_disabled = 0;
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800390 priv->power_data.is_battery_active = 0;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700391 priv->power_data.critical_power_setting = 0;
392}
393EXPORT_SYMBOL(iwl_power_initialize);
394
395/* set critical_power_setting according to temperature value */
396int iwl_power_temperature_change(struct iwl_priv *priv)
397{
398 int ret = 0;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700399 s32 temperature = KELVIN_TO_CELSIUS(priv->last_temperature);
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800400 u16 new_critical = priv->power_data.critical_power_setting;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700401
402 if (temperature > IWL_CT_KILL_TEMPERATURE)
403 return 0;
404 else if (temperature > IWL_MIN_POWER_TEMPERATURE)
405 new_critical = IWL_POWER_INDEX_5;
406 else if (temperature > IWL_REDUCED_POWER_TEMPERATURE)
407 new_critical = IWL_POWER_INDEX_3;
408 else
409 new_critical = IWL_POWER_MODE_CAM;
410
411 if (new_critical != priv->power_data.critical_power_setting)
412 priv->power_data.critical_power_setting = new_critical;
413
414 if (priv->power_data.critical_power_setting >
415 priv->power_data.power_mode)
416 ret = iwl_power_update_mode(priv, 0);
417
418 return ret;
419}
420EXPORT_SYMBOL(iwl_power_temperature_change);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +0800421
422static void iwl_bg_set_power_save(struct work_struct *work)
423{
424 struct iwl_priv *priv = container_of(work,
425 struct iwl_priv, set_power_save.work);
Tomas Winklere1623442009-01-27 14:27:56 -0800426 IWL_DEBUG_POWER(priv, "update power\n");
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +0800427
428 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
429 return;
430
431 mutex_lock(&priv->mutex);
432
Tomas Winklera96a27f2008-10-23 23:48:56 -0700433 /* on starting association we disable power management
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +0800434 * until association, if association failed then this
435 * timer will expire and enable PM again.
436 */
437 if (!iwl_is_associated(priv))
438 iwl_power_enable_management(priv);
439
440 mutex_unlock(&priv->mutex);
441}
442void iwl_setup_power_deferred_work(struct iwl_priv *priv)
443{
444 INIT_DELAYED_WORK(&priv->set_power_save, iwl_bg_set_power_save);
445}
446EXPORT_SYMBOL(iwl_setup_power_deferred_work);
447
448void iwl_power_cancel_timeout(struct iwl_priv *priv)
449{
450 cancel_delayed_work(&priv->set_power_save);
451}
452EXPORT_SYMBOL(iwl_power_cancel_timeout);