From 6bed7a6de0c5c62cd7d23fe53ad16554e1cf8087 Mon Sep 17 00:00:00 2001 From: Daisuke Nojiri Date: Tue, 25 Jun 2019 10:24:41 -0700 Subject: 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 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 Commit-Queue: Daisuke Nojiri Tested-by: Daisuke Nojiri Auto-Submit: Daisuke Nojiri --- board/nami/led.c | 59 ++++++++++++++++++++++++++++++++++++++------------------ 1 file 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 -- cgit v1.2.1