summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2019-06-25 10:24:41 -0700
committerCommit Bot <commit-bot@chromium.org>2019-06-27 16:53:14 +0000
commit6bed7a6de0c5c62cd7d23fe53ad16554e1cf8087 (patch)
tree55c6930fa0358ffae4aeb02ca3a766527067d270
parent7b81c0ac3b0c046b271f64cd276c2562406ebaeb (diff)
downloadchrome-ec-6bed7a6de0c5c62cd7d23fe53ad16554e1cf8087.tar.gz
Nami: Set LED pattern only when pattern is different
This patch makes EC check the currently active LED pattern before setting a new pattern. This will prevent a power LED from blinking every time the soc changes. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> BUG=b/135897885 BRANCH=Nami TEST=Verify LED behavior on Sona Change-Id: I5175dcd12c17c405bdb41f8fd6d370cf0ab272e8 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1679049 Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org> Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org> Tested-by: Daisuke Nojiri <dnojiri@chromium.org> Auto-Submit: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r--board/nami/led.c59
1 files changed, 40 insertions, 19 deletions
diff --git a/board/nami/led.c b/board/nami/led.c
index b09f15fd1d..3e7132756d 100644
--- a/board/nami/led.c
+++ b/board/nami/led.c
@@ -322,9 +322,37 @@ static struct {
uint8_t pulse;
} tick[2];
-static void config_tick(enum ec_led_id id, const struct led_pattern *pattern)
+static void tick_battery(void);
+DECLARE_DEFERRED(tick_battery);
+static void tick_power(void);
+DECLARE_DEFERRED(tick_power);
+static void cancel_tick(enum ec_led_id id)
{
- uint32_t stride = PULSE_INTERVAL(pattern->pulse);
+ if (id == EC_LED_ID_BATTERY_LED)
+ hook_call_deferred(&tick_battery_data, -1);
+ else
+ hook_call_deferred(&tick_power_data, -1);
+}
+
+static int config_tick(enum ec_led_id id, const struct led_pattern *pattern)
+{
+ static const struct led_pattern *patterns[2];
+ uint32_t stride;
+
+ if (pattern == patterns[id])
+ /* This pattern was already set */
+ return -1;
+
+ patterns[id] = pattern;
+
+ if (!pattern->pulse) {
+ /* This is a steady pattern. cancel the tick */
+ cancel_tick(id);
+ set_color(id, pattern->color, 100);
+ return 1;
+ }
+
+ stride = PULSE_INTERVAL(pattern->pulse);
if (IS_PULSING(pattern->pulse)) {
tick[id].interval = LED_PULSE_TICK_US;
tick[id].duty_inc = 100 / (stride / LED_PULSE_TICK_US);
@@ -336,6 +364,8 @@ static void config_tick(enum ec_led_id id, const struct led_pattern *pattern)
tick[id].duty = 0;
tick[id].alternate = 0;
tick[id].pulse = pattern->pulse;
+
+ return 0;
}
/*
@@ -376,37 +406,28 @@ static uint32_t tick_led(enum ec_led_id id)
return next > elapsed ? next - elapsed : 0;
}
-static void tick_battery(void);
-DECLARE_DEFERRED(tick_battery);
static void tick_battery(void)
{
hook_call_deferred(&tick_battery_data, tick_led(EC_LED_ID_BATTERY_LED));
}
-static void tick_power(void);
-DECLARE_DEFERRED(tick_power);
static void tick_power(void)
{
hook_call_deferred(&tick_power_data, tick_led(EC_LED_ID_POWER_LED));
}
-static void cancel_tick(enum ec_led_id id)
-{
- if (id == EC_LED_ID_BATTERY_LED)
- hook_call_deferred(&tick_battery_data, -1);
- else
- hook_call_deferred(&tick_power_data, -1);
-}
-
static void start_tick(enum ec_led_id id, const struct led_pattern *pattern)
{
- if (!pattern->pulse) {
- cancel_tick(id);
- set_color(id, pattern->color, 100);
+ if (config_tick(id, pattern))
+ /*
+ * If this pattern is already active, ticking must have started
+ * already. So, we don't re-start ticking to prevent LED from
+ * blinking at every SOC change.
+ *
+ * If this pattern is static, we skip ticking as well.
+ */
return;
- }
- config_tick(id, pattern);
if (id == EC_LED_ID_BATTERY_LED)
tick_battery();
else