blob: 0276d51d37ce78ee81d4088178b23ddd30149541 [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 */
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800152static void iwl_power_init_handle(struct iwl_priv *priv)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700153{
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
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800162 pow_data = &priv->power_data;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700163
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 }
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700182}
183
Tomas Winklera96a27f2008-10-23 23:48:56 -0700184/* adjust power command according to DTIM period and power level*/
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800185static int iwl_update_power_cmd(struct iwl_priv *priv,
186 struct iwl_powertable_cmd *cmd, u16 mode)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700187{
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700188 struct iwl_power_vec_entry *range;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700189 struct iwl_power_mgr *pow_data;
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800190 int i;
191 u32 max_sleep = 0;
192 u8 period;
193 bool skip;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700194
195 if (mode > IWL_POWER_INDEX_5) {
196 IWL_DEBUG_POWER("Error invalid power mode \n");
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800197 return -EINVAL;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700198 }
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800199
200 pow_data = &priv->power_data;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700201
202 if (pow_data->dtim_period <= IWL_POWER_RANGE_0_MAX)
203 range = &pow_data->pwr_range_0[0];
204 else if (pow_data->dtim_period <= IWL_POWER_RANGE_1_MAX)
205 range = &pow_data->pwr_range_1[0];
206 else
207 range = &pow_data->pwr_range_2[0];
208
209 period = pow_data->dtim_period;
Mohamed Abbasca579612008-07-18 13:52:57 +0800210 memcpy(cmd, &range[mode].cmd, sizeof(struct iwl_powertable_cmd));
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700211
212 if (period == 0) {
213 period = 1;
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800214 skip = false;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700215 } else {
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800216 skip = !!range[mode].no_dtim;
217 }
218
219 if (skip) {
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700220 __le32 slp_itrvl = cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1];
221 max_sleep = le32_to_cpu(slp_itrvl);
222 if (max_sleep == 0xFF)
223 max_sleep = period * (skip + 1);
224 else if (max_sleep > period)
225 max_sleep = (le32_to_cpu(slp_itrvl) / period) * period;
226 cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800227 } else {
228 max_sleep = period;
229 cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700230 }
231
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800232 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700233 if (le32_to_cpu(cmd->sleep_interval[i]) > max_sleep)
234 cmd->sleep_interval[i] = cpu_to_le32(max_sleep);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700235
236 IWL_DEBUG_POWER("Flags value = 0x%08X\n", cmd->flags);
237 IWL_DEBUG_POWER("Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
238 IWL_DEBUG_POWER("Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
239 IWL_DEBUG_POWER("Sleep interval vector = { %d , %d , %d , %d , %d }\n",
240 le32_to_cpu(cmd->sleep_interval[0]),
241 le32_to_cpu(cmd->sleep_interval[1]),
242 le32_to_cpu(cmd->sleep_interval[2]),
243 le32_to_cpu(cmd->sleep_interval[3]),
244 le32_to_cpu(cmd->sleep_interval[4]));
245
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800246 return 0;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700247}
248
249
250/*
Emmanuel Grumbacha33c2f42008-09-03 11:26:56 +0800251 * compute the final power mode index
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700252 */
Grumbach, Emmanuel04816442008-09-03 11:26:53 +0800253int iwl_power_update_mode(struct iwl_priv *priv, bool force)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700254{
255 struct iwl_power_mgr *setting = &(priv->power_data);
256 int ret = 0;
257 u16 uninitialized_var(final_mode);
Winkler, Tomasa71c8f62008-11-07 09:58:37 -0800258 bool update_chains;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700259
Grumbach, Emmanuel04816442008-09-03 11:26:53 +0800260 /* Don't update the RX chain when chain noise calibration is running */
Winkler, Tomasa71c8f62008-11-07 09:58:37 -0800261 update_chains = priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE ||
262 priv->chain_noise_data.state == IWL_CHAIN_NOISE_ALIVE;
Grumbach, Emmanuel04816442008-09-03 11:26:53 +0800263
Emmanuel Grumbacha33c2f42008-09-03 11:26:56 +0800264 /* If on battery, set to 3,
265 * if plugged into AC power, set to CAM ("continuously aware mode"),
266 * else user level */
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700267
268 switch (setting->system_power_setting) {
Esti Kummer298df1f2008-07-18 13:52:58 +0800269 case IWL_POWER_SYS_AUTO:
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700270 final_mode = iwl_get_auto_power_mode(priv);
271 break;
Esti Kummer298df1f2008-07-18 13:52:58 +0800272 case IWL_POWER_SYS_BATTERY:
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700273 final_mode = IWL_POWER_INDEX_3;
274 break;
Esti Kummer298df1f2008-07-18 13:52:58 +0800275 case IWL_POWER_SYS_AC:
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700276 final_mode = IWL_POWER_MODE_CAM;
277 break;
278 default:
Esti Kummer298df1f2008-07-18 13:52:58 +0800279 final_mode = IWL_POWER_INDEX_3;
280 WARN_ON(1);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700281 }
282
283 if (setting->critical_power_setting > final_mode)
284 final_mode = setting->critical_power_setting;
285
286 /* driver only support CAM for non STA network */
Johannes Berg05c914f2008-09-11 00:01:58 +0200287 if (priv->iw_mode != NL80211_IFTYPE_STATION)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700288 final_mode = IWL_POWER_MODE_CAM;
289
290 if (!iwl_is_rfkill(priv) && !setting->power_disabled &&
Grumbach, Emmanuel04816442008-09-03 11:26:53 +0800291 ((setting->power_mode != final_mode) || force)) {
Mohamed Abbasca579612008-07-18 13:52:57 +0800292 struct iwl_powertable_cmd cmd;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700293
294 if (final_mode != IWL_POWER_MODE_CAM)
295 set_bit(STATUS_POWER_PMI, &priv->status);
296
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800297 iwl_update_power_cmd(priv, &cmd, final_mode);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700298 cmd.keep_alive_beacons = 0;
299
300 if (final_mode == IWL_POWER_INDEX_5)
301 cmd.flags |= IWL_POWER_FAST_PD;
302
Mohamed Abbasca579612008-07-18 13:52:57 +0800303 ret = iwl_set_power(priv, &cmd);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700304
305 if (final_mode == IWL_POWER_MODE_CAM)
306 clear_bit(STATUS_POWER_PMI, &priv->status);
307 else
308 set_bit(STATUS_POWER_PMI, &priv->status);
309
Winkler, Tomasa71c8f62008-11-07 09:58:37 -0800310 if (priv->cfg->ops->lib->update_chain_flags && update_chains)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700311 priv->cfg->ops->lib->update_chain_flags(priv);
Winkler, Tomasa71c8f62008-11-07 09:58:37 -0800312 else
313 IWL_DEBUG_POWER("Cannot update the power, chain noise "
314 "calibration running: %d\n",
315 priv->chain_noise_data.state);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700316 if (!ret)
317 setting->power_mode = final_mode;
318 }
319
320 return ret;
321}
322EXPORT_SYMBOL(iwl_power_update_mode);
323
324/* Allow other iwl code to disable/enable power management active
Tomas Winklera96a27f2008-10-23 23:48:56 -0700325 * this will be useful for rate scale to disable PM during heavy
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700326 * Tx/Rx activities
327 */
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +0800328int iwl_power_disable_management(struct iwl_priv *priv, u32 ms)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700329{
330 u16 prev_mode;
331 int ret = 0;
332
333 if (priv->power_data.power_disabled)
334 return -EBUSY;
335
336 prev_mode = priv->power_data.user_power_setting;
337 priv->power_data.user_power_setting = IWL_POWER_MODE_CAM;
338 ret = iwl_power_update_mode(priv, 0);
339 priv->power_data.power_disabled = 1;
340 priv->power_data.user_power_setting = prev_mode;
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +0800341 cancel_delayed_work(&priv->set_power_save);
342 if (ms)
343 queue_delayed_work(priv->workqueue, &priv->set_power_save,
344 msecs_to_jiffies(ms));
345
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700346
347 return ret;
348}
349EXPORT_SYMBOL(iwl_power_disable_management);
350
351/* Allow other iwl code to disable/enable power management active
Tomas Winklera96a27f2008-10-23 23:48:56 -0700352 * this will be useful for rate scale to disable PM during high
353 * volume activities
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700354 */
355int iwl_power_enable_management(struct iwl_priv *priv)
356{
357 int ret = 0;
358
359 priv->power_data.power_disabled = 0;
360 ret = iwl_power_update_mode(priv, 0);
361 return ret;
362}
363EXPORT_SYMBOL(iwl_power_enable_management);
364
365/* set user_power_setting */
366int iwl_power_set_user_mode(struct iwl_priv *priv, u16 mode)
367{
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700368 if (mode > IWL_POWER_LIMIT)
369 return -EINVAL;
370
371 priv->power_data.user_power_setting = mode;
372
Grumbach, Emmanuel04816442008-09-03 11:26:53 +0800373 return iwl_power_update_mode(priv, 0);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700374}
375EXPORT_SYMBOL(iwl_power_set_user_mode);
376
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700377/* set system_power_setting. This should be set by over all
378 * PM application.
379 */
380int iwl_power_set_system_mode(struct iwl_priv *priv, u16 mode)
381{
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700382 if (mode > IWL_POWER_LIMIT)
383 return -EINVAL;
384
385 priv->power_data.system_power_setting = mode;
386
Grumbach, Emmanuel04816442008-09-03 11:26:53 +0800387 return iwl_power_update_mode(priv, 0);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700388}
389EXPORT_SYMBOL(iwl_power_set_system_mode);
390
Tomas Winklera96a27f2008-10-23 23:48:56 -0700391/* initialize to default */
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700392void iwl_power_initialize(struct iwl_priv *priv)
393{
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700394 iwl_power_init_handle(priv);
395 priv->power_data.user_power_setting = IWL_POWER_AUTO;
Esti Kummer298df1f2008-07-18 13:52:58 +0800396 priv->power_data.system_power_setting = IWL_POWER_SYS_AUTO;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700397 priv->power_data.power_disabled = 0;
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800398 priv->power_data.is_battery_active = 0;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700399 priv->power_data.critical_power_setting = 0;
400}
401EXPORT_SYMBOL(iwl_power_initialize);
402
403/* set critical_power_setting according to temperature value */
404int iwl_power_temperature_change(struct iwl_priv *priv)
405{
406 int ret = 0;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700407 s32 temperature = KELVIN_TO_CELSIUS(priv->last_temperature);
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800408 u16 new_critical = priv->power_data.critical_power_setting;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700409
410 if (temperature > IWL_CT_KILL_TEMPERATURE)
411 return 0;
412 else if (temperature > IWL_MIN_POWER_TEMPERATURE)
413 new_critical = IWL_POWER_INDEX_5;
414 else if (temperature > IWL_REDUCED_POWER_TEMPERATURE)
415 new_critical = IWL_POWER_INDEX_3;
416 else
417 new_critical = IWL_POWER_MODE_CAM;
418
419 if (new_critical != priv->power_data.critical_power_setting)
420 priv->power_data.critical_power_setting = new_critical;
421
422 if (priv->power_data.critical_power_setting >
423 priv->power_data.power_mode)
424 ret = iwl_power_update_mode(priv, 0);
425
426 return ret;
427}
428EXPORT_SYMBOL(iwl_power_temperature_change);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +0800429
430static void iwl_bg_set_power_save(struct work_struct *work)
431{
432 struct iwl_priv *priv = container_of(work,
433 struct iwl_priv, set_power_save.work);
434 IWL_DEBUG(IWL_DL_STATE, "update power\n");
435
436 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
437 return;
438
439 mutex_lock(&priv->mutex);
440
Tomas Winklera96a27f2008-10-23 23:48:56 -0700441 /* on starting association we disable power management
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +0800442 * until association, if association failed then this
443 * timer will expire and enable PM again.
444 */
445 if (!iwl_is_associated(priv))
446 iwl_power_enable_management(priv);
447
448 mutex_unlock(&priv->mutex);
449}
450void iwl_setup_power_deferred_work(struct iwl_priv *priv)
451{
452 INIT_DELAYED_WORK(&priv->set_power_save, iwl_bg_set_power_save);
453}
454EXPORT_SYMBOL(iwl_setup_power_deferred_work);
455
456void iwl_power_cancel_timeout(struct iwl_priv *priv)
457{
458 cancel_delayed_work(&priv->set_power_save);
459}
460EXPORT_SYMBOL(iwl_power_cancel_timeout);