Commit ec1a7460 authored by Tomas Winkler's avatar Tomas Winkler Committed by John W. Linville

iwlwifi: LED use correctly blink table

This patch makes correct usage of the LED blink table.
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 0eee6127
...@@ -2926,7 +2926,7 @@ struct iwl5000_calibration_chain_noise_gain_cmd { ...@@ -2926,7 +2926,7 @@ struct iwl5000_calibration_chain_noise_gain_cmd {
* For each of 3 possible LEDs (Activity/Link/Tech, selected by "id" field), * For each of 3 possible LEDs (Activity/Link/Tech, selected by "id" field),
* this command turns it on or off, or sets up a periodic blinking cycle. * this command turns it on or off, or sets up a periodic blinking cycle.
*/ */
struct iwl4965_led_cmd { struct iwl_led_cmd {
__le32 interval; /* "interval" in uSec */ __le32 interval; /* "interval" in uSec */
u8 id; /* 1: Activity, 2: Link, 3: Tech */ u8 id; /* 1: Activity, 2: Link, 3: Tech */
u8 off; /* # intervals off while blinking; u8 off; /* # intervals off while blinking;
......
...@@ -282,7 +282,7 @@ struct iwl_cmd { ...@@ -282,7 +282,7 @@ struct iwl_cmd {
struct iwl_cmd_header hdr; /* uCode API */ struct iwl_cmd_header hdr; /* uCode API */
union { union {
struct iwl_addsta_cmd addsta; struct iwl_addsta_cmd addsta;
struct iwl4965_led_cmd led; struct iwl_led_cmd led;
u32 flags; u32 flags;
u8 val8; u8 val8;
u16 val16; u16 val16;
......
...@@ -44,10 +44,6 @@ ...@@ -44,10 +44,6 @@
#include "iwl-io.h" #include "iwl-io.h"
#include "iwl-helpers.h" #include "iwl-helpers.h"
#define IWL_1MB_RATE (128 * 1024)
#define IWL_LED_THRESHOLD (16)
#define IWL_MAX_BLINK_TBL (10)
#ifdef CONFIG_IWLWIFI_DEBUG #ifdef CONFIG_IWLWIFI_DEBUG
static const char *led_type_str[] = { static const char *led_type_str[] = {
__stringify(IWL_LED_TRG_TX), __stringify(IWL_LED_TRG_TX),
...@@ -74,26 +70,31 @@ static const struct { ...@@ -74,26 +70,31 @@ static const struct {
{15, 95, 95 }, {15, 95, 95 },
{10, 110, 110}, {10, 110, 110},
{5, 130, 130}, {5, 130, 130},
{0, 167, 167} {0, 167, 167},
/* SOLID_ON */
{-1, IWL_LED_SOLID, 0}
}; };
static int iwl_led_cmd_callback(struct iwl_priv *priv, #define IWL_1MB_RATE (128 * 1024)
struct iwl_cmd *cmd, struct sk_buff *skb) #define IWL_LED_THRESHOLD (16)
#define IWL_MAX_BLINK_TBL (ARRAY_SIZE(blink_tbl) - 1) /* exclude SOLID_ON */
#define IWL_SOLID_BLINK_IDX (ARRAY_SIZE(blink_tbl) - 1)
/* [0-256] -> [0..8] FIXME: we need [0..10] */
static inline int iwl_brightness_to_idx(enum led_brightness brightness)
{ {
return 1; return fls(0x000000FF & (u32)brightness);
} }
/* Send led command */ /* Send led command */
static int iwl_send_led_cmd(struct iwl_priv *priv, static int iwl_send_led_cmd(struct iwl_priv *priv, struct iwl_led_cmd *led_cmd)
struct iwl4965_led_cmd *led_cmd)
{ {
struct iwl_host_cmd cmd = { struct iwl_host_cmd cmd = {
.id = REPLY_LEDS_CMD, .id = REPLY_LEDS_CMD,
.len = sizeof(struct iwl4965_led_cmd), .len = sizeof(struct iwl_led_cmd),
.data = led_cmd, .data = led_cmd,
.meta.flags = CMD_ASYNC, .meta.flags = CMD_ASYNC,
.meta.u.callback = iwl_led_cmd_callback .meta.u.callback = NULL,
}; };
u32 reg; u32 reg;
...@@ -104,33 +105,19 @@ static int iwl_send_led_cmd(struct iwl_priv *priv, ...@@ -104,33 +105,19 @@ static int iwl_send_led_cmd(struct iwl_priv *priv,
return iwl_send_cmd(priv, &cmd); return iwl_send_cmd(priv, &cmd);
} }
/* Set led pattern command */
/* Set led on command */ static int iwl4965_led_pattern(struct iwl_priv *priv, int led_id, int idx)
static int iwl4965_led_on(struct iwl_priv *priv, int led_id)
{ {
struct iwl4965_led_cmd led_cmd = { struct iwl_led_cmd led_cmd = {
.id = led_id, .id = led_id,
.on = IWL_LED_SOLID,
.off = 0,
.interval = IWL_DEF_LED_INTRVL .interval = IWL_DEF_LED_INTRVL
}; };
return iwl_send_led_cmd(priv, &led_cmd);
}
/* Set led on command */ BUG_ON(idx > IWL_MAX_BLINK_TBL);
static int iwl4965_led_pattern(struct iwl_priv *priv, int led_id,
enum led_brightness brightness) led_cmd.on = blink_tbl[idx].on_time;
{ led_cmd.off = blink_tbl[idx].off_time;
struct iwl4965_led_cmd led_cmd = {
.id = led_id,
.on = brightness,
.off = brightness,
.interval = IWL_DEF_LED_INTRVL
};
if (brightness == LED_FULL) {
led_cmd.on = IWL_LED_SOLID;
led_cmd.off = 0;
}
return iwl_send_led_cmd(priv, &led_cmd); return iwl_send_led_cmd(priv, &led_cmd);
} }
...@@ -143,10 +130,22 @@ static int iwl4965_led_on_reg(struct iwl_priv *priv, int led_id) ...@@ -143,10 +130,22 @@ static int iwl4965_led_on_reg(struct iwl_priv *priv, int led_id)
} }
#if 0 #if 0
/* Set led on command */
static int iwl4965_led_on(struct iwl_priv *priv, int led_id)
{
struct iwl_led_cmd led_cmd = {
.id = led_id,
.on = IWL_LED_SOLID,
.off = 0,
.interval = IWL_DEF_LED_INTRVL
};
return iwl_send_led_cmd(priv, &led_cmd);
}
/* Set led off command */ /* Set led off command */
int iwl4965_led_off(struct iwl_priv *priv, int led_id) int iwl4965_led_off(struct iwl_priv *priv, int led_id)
{ {
struct iwl4965_led_cmd led_cmd = { struct iwl_led_cmd led_cmd = {
.id = led_id, .id = led_id,
.on = 0, .on = 0,
.off = 0, .off = 0,
...@@ -169,7 +168,7 @@ static int iwl4965_led_off_reg(struct iwl_priv *priv, int led_id) ...@@ -169,7 +168,7 @@ static int iwl4965_led_off_reg(struct iwl_priv *priv, int led_id)
/* /*
* brightness call back function for Tx/Rx LED * brightness call back function for Tx/Rx LED
*/ */
static int iwl4965_led_associated(struct iwl_priv *priv, int led_id) static int iwl_led_associated(struct iwl_priv *priv, int led_id)
{ {
if (test_bit(STATUS_EXIT_PENDING, &priv->status) || if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
!test_bit(STATUS_READY, &priv->status)) !test_bit(STATUS_READY, &priv->status))
...@@ -213,8 +212,10 @@ static void iwl_led_brightness_set(struct led_classdev *led_cdev, ...@@ -213,8 +212,10 @@ static void iwl_led_brightness_set(struct led_classdev *led_cdev,
led->led_off(priv, IWL_LED_LINK); led->led_off(priv, IWL_LED_LINK);
break; break;
default: default:
if (led->led_pattern) if (led->led_pattern) {
led->led_pattern(priv, IWL_LED_LINK, brightness); int idx = iwl_brightness_to_idx(brightness);
led->led_pattern(priv, IWL_LED_LINK, idx);
}
break; break;
} }
} }
...@@ -256,10 +257,9 @@ static int iwl_leds_register_led(struct iwl_priv *priv, struct iwl_led *led, ...@@ -256,10 +257,9 @@ static int iwl_leds_register_led(struct iwl_priv *priv, struct iwl_led *led,
/* /*
* calculate blink rate according to last 2 sec Tx/Rx activities * calculate blink rate according to last 2 sec Tx/Rx activities
*/ */
static inline u8 get_blink_rate(struct iwl_priv *priv) static int iwl_get_blink_rate(struct iwl_priv *priv)
{ {
int i; int i;
u8 blink_rate;
u64 current_tpt = priv->tx_stats[2].bytes; u64 current_tpt = priv->tx_stats[2].bytes;
/* FIXME: + priv->rx_stats[2].bytes; */ /* FIXME: + priv->rx_stats[2].bytes; */
s64 tpt = current_tpt - priv->led_tpt; s64 tpt = current_tpt - priv->led_tpt;
...@@ -270,20 +270,15 @@ static inline u8 get_blink_rate(struct iwl_priv *priv) ...@@ -270,20 +270,15 @@ static inline u8 get_blink_rate(struct iwl_priv *priv)
IWL_DEBUG_LED("tpt %lld current_tpt %lld\n", tpt, current_tpt); IWL_DEBUG_LED("tpt %lld current_tpt %lld\n", tpt, current_tpt);
priv->led_tpt = current_tpt; priv->led_tpt = current_tpt;
if (tpt < IWL_LED_THRESHOLD) { if (!priv->allow_blinking)
i = IWL_MAX_BLINK_TBL; i = IWL_MAX_BLINK_TBL;
} else { else
for (i = 0; i < IWL_MAX_BLINK_TBL; i++) for (i = 0; i < IWL_MAX_BLINK_TBL; i++)
if (tpt > (blink_tbl[i].tpt * IWL_1MB_RATE)) if (tpt > (blink_tbl[i].tpt * IWL_1MB_RATE))
break; break;
}
/* if 0 frame is transfered */
if ((i == IWL_MAX_BLINK_TBL) || !priv->allow_blinking)
blink_rate = IWL_LED_SOLID;
else
blink_rate = blink_tbl[i].on_time;
return blink_rate; IWL_DEBUG_LED("LED BLINK IDX=%d", i);
return i;
} }
static inline int is_rf_kill(struct iwl_priv *priv) static inline int is_rf_kill(struct iwl_priv *priv)
...@@ -299,7 +294,7 @@ static inline int is_rf_kill(struct iwl_priv *priv) ...@@ -299,7 +294,7 @@ static inline int is_rf_kill(struct iwl_priv *priv)
*/ */
void iwl_leds_background(struct iwl_priv *priv) void iwl_leds_background(struct iwl_priv *priv)
{ {
u8 blink_rate; u8 blink_idx;
if (test_bit(STATUS_EXIT_PENDING, &priv->status)) { if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
priv->last_blink_time = 0; priv->last_blink_time = 0;
...@@ -312,9 +307,10 @@ void iwl_leds_background(struct iwl_priv *priv) ...@@ -312,9 +307,10 @@ void iwl_leds_background(struct iwl_priv *priv)
if (!priv->allow_blinking) { if (!priv->allow_blinking) {
priv->last_blink_time = 0; priv->last_blink_time = 0;
if (priv->last_blink_rate != IWL_LED_SOLID) { if (priv->last_blink_rate != IWL_SOLID_BLINK_IDX) {
priv->last_blink_rate = IWL_LED_SOLID; priv->last_blink_rate = IWL_SOLID_BLINK_IDX;
iwl4965_led_on(priv, IWL_LED_LINK); iwl4965_led_pattern(priv, IWL_LED_LINK,
IWL_SOLID_BLINK_IDX);
} }
return; return;
} }
...@@ -323,19 +319,14 @@ void iwl_leds_background(struct iwl_priv *priv) ...@@ -323,19 +319,14 @@ void iwl_leds_background(struct iwl_priv *priv)
msecs_to_jiffies(1000))) msecs_to_jiffies(1000)))
return; return;
blink_rate = get_blink_rate(priv); blink_idx = iwl_get_blink_rate(priv);
/* call only if blink rate change */ /* call only if blink rate change */
if (blink_rate != priv->last_blink_rate) { if (blink_idx != priv->last_blink_rate)
if (blink_rate != IWL_LED_SOLID) { iwl4965_led_pattern(priv, IWL_LED_LINK, blink_idx);
iwl4965_led_pattern(priv, IWL_LED_LINK, blink_rate);
} else {
iwl4965_led_on(priv, IWL_LED_LINK);
}
}
priv->last_blink_time = jiffies; priv->last_blink_time = jiffies;
priv->last_blink_rate = blink_rate; priv->last_blink_rate = blink_idx;
} }
EXPORT_SYMBOL(iwl_leds_background); EXPORT_SYMBOL(iwl_leds_background);
...@@ -386,8 +377,8 @@ int iwl_leds_register(struct iwl_priv *priv) ...@@ -386,8 +377,8 @@ int iwl_leds_register(struct iwl_priv *priv)
ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_RX], ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_RX],
IWL_LED_TRG_RX, 0, name, trigger); IWL_LED_TRG_RX, 0, name, trigger);
priv->led[IWL_LED_TRG_RX].led_on = iwl4965_led_associated; priv->led[IWL_LED_TRG_RX].led_on = iwl_led_associated;
priv->led[IWL_LED_TRG_RX].led_off = iwl4965_led_associated; priv->led[IWL_LED_TRG_RX].led_off = iwl_led_associated;
priv->led[IWL_LED_TRG_RX].led_pattern = iwl4965_led_pattern; priv->led[IWL_LED_TRG_RX].led_pattern = iwl4965_led_pattern;
if (ret) if (ret)
...@@ -398,8 +389,8 @@ int iwl_leds_register(struct iwl_priv *priv) ...@@ -398,8 +389,8 @@ int iwl_leds_register(struct iwl_priv *priv)
ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_TX], ret = iwl_leds_register_led(priv, &priv->led[IWL_LED_TRG_TX],
IWL_LED_TRG_TX, 0, name, trigger); IWL_LED_TRG_TX, 0, name, trigger);
priv->led[IWL_LED_TRG_TX].led_on = iwl4965_led_associated; priv->led[IWL_LED_TRG_TX].led_on = iwl_led_associated;
priv->led[IWL_LED_TRG_TX].led_off = iwl4965_led_associated; priv->led[IWL_LED_TRG_TX].led_off = iwl_led_associated;
priv->led[IWL_LED_TRG_TX].led_pattern = iwl4965_led_pattern; priv->led[IWL_LED_TRG_TX].led_pattern = iwl4965_led_pattern;
if (ret) if (ret)
......
...@@ -55,8 +55,7 @@ struct iwl_led { ...@@ -55,8 +55,7 @@ struct iwl_led {
int (*led_on) (struct iwl_priv *priv, int led_id); int (*led_on) (struct iwl_priv *priv, int led_id);
int (*led_off) (struct iwl_priv *priv, int led_id); int (*led_off) (struct iwl_priv *priv, int led_id);
int (*led_pattern) (struct iwl_priv *priv, int led_id, int (*led_pattern) (struct iwl_priv *priv, int led_id, int idx);
enum led_brightness brightness);
enum led_type type; enum led_type type;
unsigned int registered; unsigned int registered;
......
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