blob: b7abd86676fdeeb304a6dffb58eb96bc11435c20 [file] [log] [blame]
Mohamed Abbas5da4b552008-04-21 15:41:51 -07001/******************************************************************************
2 *
Reinette Chatre1f447802010-01-15 13:43:41 -08003 * Copyright(c) 2007 - 2010 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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Mohamed Abbas5da4b552008-04-21 15:41:51 -070033#include <linux/init.h>
34
35#include <net/mac80211.h>
36
37#include "iwl-eeprom.h"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070038#include "iwl-dev.h"
Mohamed Abbas5da4b552008-04-21 15:41:51 -070039#include "iwl-core.h"
Wey-Yi Guy39b73fb12009-07-24 11:13:02 -070040#include "iwl-io.h"
Tomas Winkler5a36ba02008-04-24 11:55:37 -070041#include "iwl-commands.h"
Mohamed Abbas5da4b552008-04-21 15:41:51 -070042#include "iwl-debug.h"
43#include "iwl-power.h"
Mohamed Abbas5da4b552008-04-21 15:41:51 -070044
45/*
Johannes Berge312c242009-08-07 15:41:51 -070046 * Setting power level allows the card to go to sleep when not busy.
Mohamed Abbas5da4b552008-04-21 15:41:51 -070047 *
Johannes Berge312c242009-08-07 15:41:51 -070048 * We calculate a sleep command based on the required latency, which
49 * we get from mac80211. In order to handle thermal throttling, we can
50 * also use pre-defined power levels.
Mohamed Abbas5da4b552008-04-21 15:41:51 -070051 */
52
Johannes Berge312c242009-08-07 15:41:51 -070053/*
54 * For now, keep using power level 1 instead of automatically
55 * adjusting ...
56 */
57bool no_sleep_autoadjust = true;
58module_param(no_sleep_autoadjust, bool, S_IRUGO);
59MODULE_PARM_DESC(no_sleep_autoadjust,
60 "don't automatically adjust sleep level "
61 "according to maximum network latency");
Mohamed Abbas5da4b552008-04-21 15:41:51 -070062
Johannes Berge312c242009-08-07 15:41:51 -070063/*
64 * This defines the old power levels. They are still used by default
65 * (level 1) and for thermal throttle (levels 3 through 5)
66 */
67
68struct iwl_power_vec_entry {
69 struct iwl_powertable_cmd cmd;
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -070070 u8 no_dtim; /* number of skip dtim */
Johannes Berge312c242009-08-07 15:41:51 -070071};
72
73#define IWL_DTIM_RANGE_0_MAX 2
74#define IWL_DTIM_RANGE_1_MAX 10
Mohamed Abbas5da4b552008-04-21 15:41:51 -070075
Johannes Berg7af2c462009-05-08 13:44:38 -070076#define NOSLP cpu_to_le16(0), 0, 0
77#define SLP IWL_POWER_DRIVER_ALLOW_SLEEP_MSK, 0, 0
78#define TU_TO_USEC 1024
79#define SLP_TOUT(T) cpu_to_le32((T) * TU_TO_USEC)
80#define SLP_VEC(X0, X1, X2, X3, X4) {cpu_to_le32(X0), \
81 cpu_to_le32(X1), \
82 cpu_to_le32(X2), \
83 cpu_to_le32(X3), \
84 cpu_to_le32(X4)}
Mohamed Abbas5da4b552008-04-21 15:41:51 -070085/* default power management (not Tx power) table values */
Johannes Berge312c242009-08-07 15:41:51 -070086/* for DTIM period 0 through IWL_DTIM_RANGE_0_MAX */
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -070087/* DTIM 0 - 2 */
Johannes Berg7af2c462009-05-08 13:44:38 -070088static const struct iwl_power_vec_entry range_0[IWL_POWER_NUM] = {
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -070089 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 1, 2, 2, 0xFF)}, 0},
Mohamed Abbas5da4b552008-04-21 15:41:51 -070090 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0},
91 {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 2, 2, 2, 0xFF)}, 0},
92 {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 2, 4, 4, 0xFF)}, 1},
93 {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(2, 2, 4, 6, 0xFF)}, 2}
94};
95
96
Johannes Berge312c242009-08-07 15:41:51 -070097/* for DTIM period IWL_DTIM_RANGE_0_MAX + 1 through IWL_DTIM_RANGE_1_MAX */
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -070098/* DTIM 3 - 10 */
Johannes Berg7af2c462009-05-08 13:44:38 -070099static const struct iwl_power_vec_entry range_1[IWL_POWER_NUM] = {
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700100 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
101 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 3, 4, 7)}, 0},
102 {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 4, 6, 7, 9)}, 0},
103 {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 4, 6, 9, 10)}, 1},
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700104 {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(2, 4, 6, 10, 10)}, 2}
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700105};
106
Johannes Berge312c242009-08-07 15:41:51 -0700107/* for DTIM period > IWL_DTIM_RANGE_1_MAX */
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700108/* DTIM 11 - */
Johannes Berg7af2c462009-05-08 13:44:38 -0700109static const struct iwl_power_vec_entry range_2[IWL_POWER_NUM] = {
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700110 {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
111 {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
112 {{SLP, SLP_TOUT(50), SLP_TOUT(100), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
113 {{SLP, SLP_TOUT(50), SLP_TOUT(25), SLP_VEC(2, 7, 9, 9, 0xFF)}, 0},
114 {{SLP, SLP_TOUT(25), SLP_TOUT(25), SLP_VEC(4, 7, 10, 10, 0xFF)}, 0}
115};
116
Johannes Berge312c242009-08-07 15:41:51 -0700117static void iwl_static_sleep_cmd(struct iwl_priv *priv,
118 struct iwl_powertable_cmd *cmd,
119 enum iwl_power_level lvl, int period)
120{
121 const struct iwl_power_vec_entry *table;
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700122 int max_sleep[IWL_POWER_VEC_SIZE] = { 0 };
123 int i;
124 u8 skip;
125 u32 slp_itrvl;
Johannes Berge312c242009-08-07 15:41:51 -0700126
127 table = range_2;
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700128 if (period <= IWL_DTIM_RANGE_1_MAX)
Johannes Berge312c242009-08-07 15:41:51 -0700129 table = range_1;
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700130 if (period <= IWL_DTIM_RANGE_0_MAX)
Johannes Berge312c242009-08-07 15:41:51 -0700131 table = range_0;
132
133 BUG_ON(lvl < 0 || lvl >= IWL_POWER_NUM);
134
135 *cmd = table[lvl].cmd;
136
137 if (period == 0) {
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700138 skip = 0;
Johannes Berge312c242009-08-07 15:41:51 -0700139 period = 1;
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700140 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
141 max_sleep[i] = 1;
142
Johannes Berge312c242009-08-07 15:41:51 -0700143 } else {
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700144 skip = table[lvl].no_dtim;
145 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
146 max_sleep[i] = le32_to_cpu(cmd->sleep_interval[i]);
147 max_sleep[IWL_POWER_VEC_SIZE - 1] = skip + 1;
Johannes Berge312c242009-08-07 15:41:51 -0700148 }
149
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700150 slp_itrvl = le32_to_cpu(cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]);
151 /* figure out the listen interval based on dtim period and skip */
152 if (slp_itrvl == 0xFF)
153 cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1] =
154 cpu_to_le32(period * (skip + 1));
155
156 slp_itrvl = le32_to_cpu(cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]);
157 if (slp_itrvl > period)
158 cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1] =
159 cpu_to_le32((slp_itrvl / period) * period);
160
161 if (skip)
Johannes Berge312c242009-08-07 15:41:51 -0700162 cmd->flags |= IWL_POWER_SLEEP_OVER_DTIM_MSK;
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700163 else
Johannes Berge312c242009-08-07 15:41:51 -0700164 cmd->flags &= ~IWL_POWER_SLEEP_OVER_DTIM_MSK;
Johannes Berge312c242009-08-07 15:41:51 -0700165
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700166 slp_itrvl = le32_to_cpu(cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1]);
Wey-Yi Guy570af862009-10-23 13:42:33 -0700167 if (slp_itrvl > IWL_CONN_MAX_LISTEN_INTERVAL)
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700168 cmd->sleep_interval[IWL_POWER_VEC_SIZE - 1] =
Wey-Yi Guy570af862009-10-23 13:42:33 -0700169 cpu_to_le32(IWL_CONN_MAX_LISTEN_INTERVAL);
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700170
171 /* enforce max sleep interval */
172 for (i = IWL_POWER_VEC_SIZE - 1; i >= 0 ; i--) {
173 if (le32_to_cpu(cmd->sleep_interval[i]) >
174 (max_sleep[i] * period))
175 cmd->sleep_interval[i] =
176 cpu_to_le32(max_sleep[i] * period);
177 if (i != (IWL_POWER_VEC_SIZE - 1)) {
178 if (le32_to_cpu(cmd->sleep_interval[i]) >
179 le32_to_cpu(cmd->sleep_interval[i+1]))
180 cmd->sleep_interval[i] =
181 cmd->sleep_interval[i+1];
182 }
183 }
Johannes Berge312c242009-08-07 15:41:51 -0700184
185 if (priv->power_data.pci_pm)
186 cmd->flags |= IWL_POWER_PCI_PM_MSK;
187 else
188 cmd->flags &= ~IWL_POWER_PCI_PM_MSK;
189
Wey-Yi Guy4ad177b2009-10-16 14:25:58 -0700190 IWL_DEBUG_POWER(priv, "numSkipDtim = %u, dtimPeriod = %d\n",
191 skip, period);
Johannes Berge312c242009-08-07 15:41:51 -0700192 IWL_DEBUG_POWER(priv, "Sleep command for index %d\n", lvl + 1);
193}
194
Johannes Berge312c242009-08-07 15:41:51 -0700195static void iwl_power_sleep_cam_cmd(struct iwl_priv *priv,
196 struct iwl_powertable_cmd *cmd)
Mohamed Abbasca579612008-07-18 13:52:57 +0800197{
Johannes Berge312c242009-08-07 15:41:51 -0700198 memset(cmd, 0, sizeof(*cmd));
199
200 if (priv->power_data.pci_pm)
201 cmd->flags |= IWL_POWER_PCI_PM_MSK;
202
203 IWL_DEBUG_POWER(priv, "Sleep command for CAM\n");
Mohamed Abbasca579612008-07-18 13:52:57 +0800204}
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700205
Johannes Berge312c242009-08-07 15:41:51 -0700206static void iwl_power_fill_sleep_cmd(struct iwl_priv *priv,
207 struct iwl_powertable_cmd *cmd,
208 int dynps_ms, int wakeup_period)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700209{
Johannes Berg4c561a02009-08-28 09:44:48 -0700210 /*
211 * These are the original power level 3 sleep successions. The
212 * device may behave better with such succession and was also
213 * only tested with that. Just like the original sleep commands,
214 * also adjust the succession here to the wakeup_period below.
215 * The ranges are the same as for the sleep commands, 0-2, 3-9
216 * and >10, which is selected based on the DTIM interval for
217 * the sleep index but here we use the wakeup period since that
218 * is what we need to do for the latency requirements.
219 */
220 static const u8 slp_succ_r0[IWL_POWER_VEC_SIZE] = { 2, 2, 2, 2, 2 };
221 static const u8 slp_succ_r1[IWL_POWER_VEC_SIZE] = { 2, 4, 6, 7, 9 };
222 static const u8 slp_succ_r2[IWL_POWER_VEC_SIZE] = { 2, 7, 9, 9, 0xFF };
223 const u8 *slp_succ = slp_succ_r0;
Tomas Winklere7b63582008-09-03 11:26:49 +0800224 int i;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700225
Johannes Berg4c561a02009-08-28 09:44:48 -0700226 if (wakeup_period > IWL_DTIM_RANGE_0_MAX)
227 slp_succ = slp_succ_r1;
228 if (wakeup_period > IWL_DTIM_RANGE_1_MAX)
229 slp_succ = slp_succ_r2;
230
Johannes Berge312c242009-08-07 15:41:51 -0700231 memset(cmd, 0, sizeof(*cmd));
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700232
Johannes Berge312c242009-08-07 15:41:51 -0700233 cmd->flags = IWL_POWER_DRIVER_ALLOW_SLEEP_MSK |
234 IWL_POWER_FAST_PD; /* no use seeing frames for others */
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700235
Johannes Berge312c242009-08-07 15:41:51 -0700236 if (priv->power_data.pci_pm)
237 cmd->flags |= IWL_POWER_PCI_PM_MSK;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700238
Johannes Berge312c242009-08-07 15:41:51 -0700239 cmd->rx_data_timeout = cpu_to_le32(1000 * dynps_ms);
240 cmd->tx_data_timeout = cpu_to_le32(1000 * dynps_ms);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700241
Winkler, Tomas5cd19c52009-01-19 15:30:21 -0800242 for (i = 0; i < IWL_POWER_VEC_SIZE; i++)
Johannes Berg4c561a02009-08-28 09:44:48 -0700243 cmd->sleep_interval[i] =
244 cpu_to_le32(min_t(int, slp_succ[i], wakeup_period));
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700245
Johannes Berge312c242009-08-07 15:41:51 -0700246 IWL_DEBUG_POWER(priv, "Automatic sleep command\n");
247}
248
249static int iwl_set_power(struct iwl_priv *priv, struct iwl_powertable_cmd *cmd)
250{
251 IWL_DEBUG_POWER(priv, "Sending power/sleep command\n");
Tomas Winklere1623442009-01-27 14:27:56 -0800252 IWL_DEBUG_POWER(priv, "Flags value = 0x%08X\n", cmd->flags);
253 IWL_DEBUG_POWER(priv, "Tx timeout = %u\n", le32_to_cpu(cmd->tx_data_timeout));
254 IWL_DEBUG_POWER(priv, "Rx timeout = %u\n", le32_to_cpu(cmd->rx_data_timeout));
255 IWL_DEBUG_POWER(priv, "Sleep interval vector = { %d , %d , %d , %d , %d }\n",
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700256 le32_to_cpu(cmd->sleep_interval[0]),
257 le32_to_cpu(cmd->sleep_interval[1]),
258 le32_to_cpu(cmd->sleep_interval[2]),
259 le32_to_cpu(cmd->sleep_interval[3]),
260 le32_to_cpu(cmd->sleep_interval[4]));
261
Johannes Berge312c242009-08-07 15:41:51 -0700262 return iwl_send_cmd_pdu(priv, POWER_TABLE_CMD,
263 sizeof(struct iwl_powertable_cmd), cmd);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700264}
265
Stanislaw Gruszkaac4f5452010-10-22 17:04:29 +0200266static void iwl_power_build_cmd(struct iwl_priv *priv,
267 struct iwl_powertable_cmd *cmd)
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700268{
Johannes Berg4d695922010-01-21 05:24:04 -0800269 bool enabled = priv->hw->conf.flags & IEEE80211_CONF_PS;
Johannes Berge312c242009-08-07 15:41:51 -0700270 int dtimper;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700271
Stanislaw Gruszkaac4f5452010-10-22 17:04:29 +0200272 dtimper = priv->hw->conf.ps_dtim_period ?: 1;
273
274 if (priv->cfg->base_params->broken_powersave)
275 iwl_power_sleep_cam_cmd(priv, cmd);
276 else if (priv->cfg->base_params->supports_idle &&
277 priv->hw->conf.flags & IEEE80211_CONF_IDLE)
278 iwl_static_sleep_cmd(priv, cmd, IWL_POWER_INDEX_5, 20);
279 else if (priv->cfg->ops->lib->tt_ops.lower_power_detection &&
280 priv->cfg->ops->lib->tt_ops.tt_power_mode &&
281 priv->cfg->ops->lib->tt_ops.lower_power_detection(priv)) {
282 /* in thermal throttling low power state */
283 iwl_static_sleep_cmd(priv, cmd,
284 priv->cfg->ops->lib->tt_ops.tt_power_mode(priv), dtimper);
285 } else if (!enabled)
286 iwl_power_sleep_cam_cmd(priv, cmd);
287 else if (priv->power_data.debug_sleep_level_override >= 0)
288 iwl_static_sleep_cmd(priv, cmd,
289 priv->power_data.debug_sleep_level_override,
290 dtimper);
291 else if (no_sleep_autoadjust)
292 iwl_static_sleep_cmd(priv, cmd, IWL_POWER_INDEX_1, dtimper);
293 else
294 iwl_power_fill_sleep_cmd(priv, cmd,
295 priv->hw->conf.dynamic_ps_timeout,
296 priv->hw->conf.max_sleep_period);
297}
298
299int iwl_power_set_mode(struct iwl_priv *priv, struct iwl_powertable_cmd *cmd,
300 bool force)
301{
302 int ret;
303 bool update_chains;
304
305 lockdep_assert_held(&priv->mutex);
306
Grumbach, Emmanuel04816442008-09-03 11:26:53 +0800307 /* Don't update the RX chain when chain noise calibration is running */
Winkler, Tomasa71c8f62008-11-07 09:58:37 -0800308 update_chains = priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE ||
309 priv->chain_noise_data.state == IWL_CHAIN_NOISE_ALIVE;
Grumbach, Emmanuel04816442008-09-03 11:26:53 +0800310
Stanislaw Gruszkaac4f5452010-10-22 17:04:29 +0200311 if (!memcmp(&priv->power_data.sleep_cmd, cmd, sizeof(*cmd)) && !force)
312 return 0;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700313
Stanislaw Gruszkaac4f5452010-10-22 17:04:29 +0200314 if (!iwl_is_ready_rf(priv))
315 return -EIO;
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700316
Stanislaw Gruszkaac4f5452010-10-22 17:04:29 +0200317 /* scan complete use sleep_power_next, need to be updated */
318 memcpy(&priv->power_data.sleep_cmd_next, cmd, sizeof(*cmd));
319 if (test_bit(STATUS_SCANNING, &priv->status) && !force) {
320 IWL_DEBUG_INFO(priv, "Defer power set mode while scanning\n");
321 return 0;
322 }
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700323
Stanislaw Gruszkaac4f5452010-10-22 17:04:29 +0200324 if (cmd->flags & IWL_POWER_DRIVER_ALLOW_SLEEP_MSK)
325 set_bit(STATUS_POWER_PMI, &priv->status);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700326
Stanislaw Gruszkaac4f5452010-10-22 17:04:29 +0200327 ret = iwl_set_power(priv, cmd);
328 if (!ret) {
329 if (!(cmd->flags & IWL_POWER_DRIVER_ALLOW_SLEEP_MSK))
330 clear_bit(STATUS_POWER_PMI, &priv->status);
331
332 if (priv->cfg->ops->lib->update_chain_flags && update_chains)
333 priv->cfg->ops->lib->update_chain_flags(priv);
334 else if (priv->cfg->ops->lib->update_chain_flags)
335 IWL_DEBUG_POWER(priv,
Wey-Yi Guy3a780d22009-08-07 15:41:47 -0700336 "Cannot update the power, chain noise "
Winkler, Tomasa71c8f62008-11-07 09:58:37 -0800337 "calibration running: %d\n",
338 priv->chain_noise_data.state);
Stanislaw Gruszkaac4f5452010-10-22 17:04:29 +0200339
340 memcpy(&priv->power_data.sleep_cmd, cmd, sizeof(*cmd));
341 } else
342 IWL_ERR(priv, "set power fail, ret = %d", ret);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700343
344 return ret;
345}
Stanislaw Gruszkaac4f5452010-10-22 17:04:29 +0200346EXPORT_SYMBOL(iwl_power_set_mode);
347
348int iwl_power_update_mode(struct iwl_priv *priv, bool force)
349{
350 struct iwl_powertable_cmd cmd;
351
352 iwl_power_build_cmd(priv, &cmd);
353 return iwl_power_set_mode(priv, &cmd, force);
354}
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700355EXPORT_SYMBOL(iwl_power_update_mode);
356
Tomas Winklera96a27f2008-10-23 23:48:56 -0700357/* initialize to default */
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700358void iwl_power_initialize(struct iwl_priv *priv)
359{
Johannes Berge312c242009-08-07 15:41:51 -0700360 u16 lctl = iwl_pcie_link_ctl(priv);
361
362 priv->power_data.pci_pm = !(lctl & PCI_CFG_LINK_CTRL_VAL_L0S_EN);
363
364 priv->power_data.debug_sleep_level_override = -1;
365
366 memset(&priv->power_data.sleep_cmd, 0,
367 sizeof(priv->power_data.sleep_cmd));
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700368}
369EXPORT_SYMBOL(iwl_power_initialize);