Commit 298df1f6 authored by Esti Kummer's avatar Esti Kummer Committed by John W. Linville

iwlwifi: corrects power_level in sysfs

This patch corrects power_level in sysfs.
Signed-off-by: default avatarEsti Kummer <ester.kummer@intel.com>
Signed-off-by: default avatarTomas Winkler <tomas.winkler@intel.com>
Signed-off-by: default avatarZhu Yi <yi.zhu@intel.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent ca579617
...@@ -82,7 +82,7 @@ ...@@ -82,7 +82,7 @@
/* default power management (not Tx power) table values */ /* default power management (not Tx power) table values */
/* for tim 0-10 */ /* for tim 0-10 */
static struct iwl_power_vec_entry range_0[IWL_POWER_AC] = { static struct iwl_power_vec_entry range_0[IWL_POWER_MAX] = {
{{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
{{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0}, {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0},
{{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0}, {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 2, 2, 0xFF)}, 0},
...@@ -93,7 +93,7 @@ static struct iwl_power_vec_entry range_0[IWL_POWER_AC] = { ...@@ -93,7 +93,7 @@ static struct iwl_power_vec_entry range_0[IWL_POWER_AC] = {
/* for tim = 3-10 */ /* for tim = 3-10 */
static struct iwl_power_vec_entry range_1[IWL_POWER_AC] = { static struct iwl_power_vec_entry range_1[IWL_POWER_MAX] = {
{{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
{{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0}, {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 4)}, 0},
{{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 3, 4, 7)}, 0}, {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(1, 2, 3, 4, 7)}, 0},
...@@ -103,7 +103,7 @@ static struct iwl_power_vec_entry range_1[IWL_POWER_AC] = { ...@@ -103,7 +103,7 @@ static struct iwl_power_vec_entry range_1[IWL_POWER_AC] = {
}; };
/* for tim > 11 */ /* for tim > 11 */
static struct iwl_power_vec_entry range_2[IWL_POWER_AC] = { static struct iwl_power_vec_entry range_2[IWL_POWER_MAX] = {
{{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0}, {{NOSLP, SLP_TOUT(0), SLP_TOUT(0), SLP_VEC(0, 0, 0, 0, 0)}, 0},
{{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 0xFF)}, 0}, {{SLP, SLP_TOUT(200), SLP_TOUT(500), SLP_VEC(1, 2, 3, 4, 0xFF)}, 0},
{{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 0xFF)}, 0}, {{SLP, SLP_TOUT(200), SLP_TOUT(300), SLP_VEC(2, 4, 6, 7, 0xFF)}, 0},
...@@ -124,7 +124,7 @@ static int iwl_set_power(struct iwl_priv *priv, void *cmd) ...@@ -124,7 +124,7 @@ static int iwl_set_power(struct iwl_priv *priv, void *cmd)
*/ */
static u16 iwl_get_auto_power_mode(struct iwl_priv *priv) static u16 iwl_get_auto_power_mode(struct iwl_priv *priv)
{ {
u16 mode = priv->power_data.user_power_setting; u16 mode;
switch (priv->power_data.user_power_setting) { switch (priv->power_data.user_power_setting) {
case IWL_POWER_AUTO: case IWL_POWER_AUTO:
...@@ -136,12 +136,16 @@ static u16 iwl_get_auto_power_mode(struct iwl_priv *priv) ...@@ -136,12 +136,16 @@ static u16 iwl_get_auto_power_mode(struct iwl_priv *priv)
else else
mode = IWL_POWER_ON_AC_DISASSOC; mode = IWL_POWER_ON_AC_DISASSOC;
break; break;
/* FIXME: remove battery and ac from here */
case IWL_POWER_BATTERY: case IWL_POWER_BATTERY:
mode = IWL_POWER_INDEX_3; mode = IWL_POWER_INDEX_3;
break; break;
case IWL_POWER_AC: case IWL_POWER_AC:
mode = IWL_POWER_MODE_CAM; mode = IWL_POWER_MODE_CAM;
break; break;
default:
mode = priv->power_data.user_power_setting;
break;
} }
return mode; return mode;
} }
...@@ -151,7 +155,7 @@ static int iwl_power_init_handle(struct iwl_priv *priv) ...@@ -151,7 +155,7 @@ static int iwl_power_init_handle(struct iwl_priv *priv)
{ {
int ret = 0, i; int ret = 0, i;
struct iwl_power_mgr *pow_data; struct iwl_power_mgr *pow_data;
int size = sizeof(struct iwl_power_vec_entry) * IWL_POWER_AC; int size = sizeof(struct iwl_power_vec_entry) * IWL_POWER_MAX;
u16 pci_pm; u16 pci_pm;
IWL_DEBUG_POWER("Initialize power \n"); IWL_DEBUG_POWER("Initialize power \n");
...@@ -173,7 +177,7 @@ static int iwl_power_init_handle(struct iwl_priv *priv) ...@@ -173,7 +177,7 @@ static int iwl_power_init_handle(struct iwl_priv *priv)
IWL_DEBUG_POWER("adjust power command flags\n"); IWL_DEBUG_POWER("adjust power command flags\n");
for (i = 0; i < IWL_POWER_AC; i++) { for (i = 0; i < IWL_POWER_MAX; i++) {
cmd = &pow_data->pwr_range_0[i].cmd; cmd = &pow_data->pwr_range_0[i].cmd;
if (pci_pm & 0x1) if (pci_pm & 0x1)
...@@ -265,17 +269,18 @@ int iwl_power_update_mode(struct iwl_priv *priv, u8 refresh) ...@@ -265,17 +269,18 @@ int iwl_power_update_mode(struct iwl_priv *priv, u8 refresh)
* else user level */ * else user level */
switch (setting->system_power_setting) { switch (setting->system_power_setting) {
case IWL_POWER_AUTO: case IWL_POWER_SYS_AUTO:
final_mode = iwl_get_auto_power_mode(priv); final_mode = iwl_get_auto_power_mode(priv);
break; break;
case IWL_POWER_BATTERY: case IWL_POWER_SYS_BATTERY:
final_mode = IWL_POWER_INDEX_3; final_mode = IWL_POWER_INDEX_3;
break; break;
case IWL_POWER_AC: case IWL_POWER_SYS_AC:
final_mode = IWL_POWER_MODE_CAM; final_mode = IWL_POWER_MODE_CAM;
break; break;
default: default:
final_mode = setting->system_power_setting; final_mode = IWL_POWER_INDEX_3;
WARN_ON(1);
} }
if (setting->critical_power_setting > final_mode) if (setting->critical_power_setting > final_mode)
...@@ -394,7 +399,7 @@ void iwl_power_initialize(struct iwl_priv *priv) ...@@ -394,7 +399,7 @@ void iwl_power_initialize(struct iwl_priv *priv)
iwl_power_init_handle(priv); iwl_power_init_handle(priv);
priv->power_data.user_power_setting = IWL_POWER_AUTO; priv->power_data.user_power_setting = IWL_POWER_AUTO;
priv->power_data.power_disabled = 0; priv->power_data.power_disabled = 0;
priv->power_data.system_power_setting = IWL_POWER_AUTO; priv->power_data.system_power_setting = IWL_POWER_SYS_AUTO;
priv->power_data.is_battery_active = 0; priv->power_data.is_battery_active = 0;
priv->power_data.power_disabled = 0; priv->power_data.power_disabled = 0;
priv->power_data.critical_power_setting = 0; priv->power_data.critical_power_setting = 0;
......
...@@ -33,12 +33,25 @@ ...@@ -33,12 +33,25 @@
struct iwl_priv; struct iwl_priv;
#define IWL_POWER_MODE_CAM 0x00 /* Continuously Aware Mode, always on */ enum {
#define IWL_POWER_INDEX_3 0x03 IWL_POWER_MODE_CAM, /* Continuously Aware Mode, always on */
#define IWL_POWER_INDEX_5 0x05 IWL_POWER_INDEX_1,
#define IWL_POWER_AC 0x06 IWL_POWER_INDEX_2,
#define IWL_POWER_BATTERY 0x07 IWL_POWER_INDEX_3,
#define IWL_POWER_AUTO 0x08 IWL_POWER_INDEX_4,
IWL_POWER_INDEX_5,
IWL_POWER_AUTO,
IWL_POWER_MAX = IWL_POWER_AUTO,
IWL_POWER_AC,
IWL_POWER_BATTERY,
};
enum {
IWL_POWER_SYS_AUTO,
IWL_POWER_SYS_AC,
IWL_POWER_SYS_BATTERY,
};
#define IWL_POWER_LIMIT 0x08 #define IWL_POWER_LIMIT 0x08
#define IWL_POWER_MASK 0x0F #define IWL_POWER_MASK 0x0F
#define IWL_POWER_ENABLED 0x10 #define IWL_POWER_ENABLED 0x10
...@@ -52,9 +65,9 @@ struct iwl_power_vec_entry { ...@@ -52,9 +65,9 @@ struct iwl_power_vec_entry {
struct iwl_power_mgr { struct iwl_power_mgr {
spinlock_t lock; spinlock_t lock;
struct iwl_power_vec_entry pwr_range_0[IWL_POWER_AC]; struct iwl_power_vec_entry pwr_range_0[IWL_POWER_MAX];
struct iwl_power_vec_entry pwr_range_1[IWL_POWER_AC]; struct iwl_power_vec_entry pwr_range_1[IWL_POWER_MAX];
struct iwl_power_vec_entry pwr_range_2[IWL_POWER_AC]; struct iwl_power_vec_entry pwr_range_2[IWL_POWER_MAX];
u32 dtim_period; u32 dtim_period;
/* final power level that used to calculate final power command */ /* final power level that used to calculate final power command */
u8 power_mode; u8 power_mode;
......
...@@ -3800,76 +3800,53 @@ static ssize_t store_power_level(struct device *d, ...@@ -3800,76 +3800,53 @@ static ssize_t store_power_level(struct device *d,
const char *buf, size_t count) const char *buf, size_t count)
{ {
struct iwl_priv *priv = dev_get_drvdata(d); struct iwl_priv *priv = dev_get_drvdata(d);
int rc; int ret;
int mode; int mode;
mode = simple_strtoul(buf, NULL, 0); mode = simple_strtoul(buf, NULL, 0);
mutex_lock(&priv->mutex); mutex_lock(&priv->mutex);
if (!iwl_is_ready(priv)) { if (!iwl_is_ready(priv)) {
rc = -EAGAIN; ret = -EAGAIN;
goto out; goto out;
} }
rc = iwl_power_set_user_mode(priv, mode); ret = iwl_power_set_user_mode(priv, mode);
if (rc) { if (ret) {
IWL_DEBUG_MAC80211("failed setting power mode.\n"); IWL_DEBUG_MAC80211("failed setting power mode.\n");
goto out; goto out;
} }
rc = count; ret = count;
out: out:
mutex_unlock(&priv->mutex); mutex_unlock(&priv->mutex);
return rc; return ret;
} }
#define MAX_WX_STRING 80
/* Values are in microsecond */
static const s32 timeout_duration[] = {
350000,
250000,
75000,
37000,
25000,
};
static const s32 period_duration[] = {
400000,
700000,
1000000,
1000000,
1000000
};
static ssize_t show_power_level(struct device *d, static ssize_t show_power_level(struct device *d,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
struct iwl_priv *priv = dev_get_drvdata(d); struct iwl_priv *priv = dev_get_drvdata(d);
int mode = priv->power_data.user_power_setting;
int system = priv->power_data.system_power_setting;
int level = priv->power_data.power_mode; int level = priv->power_data.power_mode;
char *p = buf; char *p = buf;
p += sprintf(p, "%d ", level); switch (system) {
switch (level) { case IWL_POWER_SYS_AUTO:
case IWL_POWER_MODE_CAM: p += sprintf(p, "SYSTEM:auto");
case IWL_POWER_AC:
p += sprintf(p, "(AC)");
break; break;
case IWL_POWER_BATTERY: case IWL_POWER_SYS_AC:
p += sprintf(p, "(BATTERY)"); p += sprintf(p, "SYSTEM:ac");
break;
case IWL_POWER_SYS_BATTERY:
p += sprintf(p, "SYSTEM:battery");
break; break;
default:
p += sprintf(p,
"(Timeout %dms, Period %dms)",
timeout_duration[level - 1] / 1000,
period_duration[level - 1] / 1000);
} }
/*
if (!(priv->power_mode & IWL_POWER_ENABLED)) p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO)?"fixed":"auto");
p += sprintf(p, " OFF\n"); p += sprintf(p, "\tINDEX:%d", level);
else p += sprintf(p, "\n");
p += sprintf(p, " \n");
*/
p += sprintf(p, " \n");
return (p - buf + 1); return (p - buf + 1);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment