diff options
author | eddylu <eddylu@ami.corp-partner.google.com> | 2018-07-16 16:04:25 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-07-26 04:07:46 -0700 |
commit | 524de25a4d879d8a27f630383f25ab28481cf8f4 (patch) | |
tree | 3f8d8bec11a1509fd536d882575a8595e305dd2f /baseboard | |
parent | a59038668c9bde21225563c8cd994dc961d15128 (diff) | |
download | chrome-ec-524de25a4d879d8a27f630383f25ab28481cf8f4.tar.gz |
octopus: Add phaser LED behavior support
Reference LED behavior spec and implement it.
Add Power LED common code.
Yorp and bip also do some necessary charges.
BUG=b:80501031,b:110086152
BRANCH=none
TEST=Verify LED behavior at different power state.
Change-Id: I88dbad30101e7983304c15f88b52b31457607749
Signed-off-by: eddylu <eddylu@ami.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/1116628
Commit-Ready: Eddy Lu <eddylu@ami.corp-partner.google.com>
Tested-by: Eddy Lu <eddylu@ami.corp-partner.google.com>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'baseboard')
-rw-r--r-- | baseboard/octopus/led_states.c | 63 | ||||
-rw-r--r-- | baseboard/octopus/led_states.h | 31 |
2 files changed, 88 insertions, 6 deletions
diff --git a/baseboard/octopus/led_states.c b/baseboard/octopus/led_states.c index 40d2ebefc8..43bad48b6e 100644 --- a/baseboard/octopus/led_states.c +++ b/baseboard/octopus/led_states.c @@ -16,12 +16,20 @@ static enum led_states led_get_state(void) { + int charge_lvl; enum led_states new_state = LED_NUM_STATES; switch (charge_get_state()) { case PWR_STATE_CHARGE: - new_state = STATE_CHARGING; - /* TODO(b/110086152): additional charging states for phasor */ + /* Get percent charge */ + charge_lvl = charge_get_percent(); + /* Determine which charge state to use */ + if (charge_lvl < led_charge_lvl_1) + new_state = STATE_CHARGING_LVL_1; + else if (charge_lvl < led_charge_lvl_2) + new_state = STATE_CHARGING_LVL_2; + else + new_state = STATE_CHARGING_FULL_CHARGE; break; case PWR_STATE_DISCHARGE_FULL: if (extpower_is_present()) { @@ -44,7 +52,10 @@ static enum led_states led_get_state(void) new_state = STATE_CHARGING_FULL_CHARGE; break; case PWR_STATE_IDLE: /* External power connected in IDLE */ - new_state = STATE_DISCHARGE_S0; + if (charge_get_flags() & CHARGE_FLAG_FORCE_IDLE) + new_state = STATE_FACTORY_TEST; + else + new_state = STATE_DISCHARGE_S0; break; default: /* Other states don't alter LED behavior */ @@ -95,6 +106,47 @@ static void led_update_battery(void) led_set_color_battery(led_bat_state_table[led_state][phase].color); } +#ifdef OCTOPUS_POWER_LED +static void led_update_power(void) +{ + int enable; + static int ticks; + enum led_states desired_state; + + if (chipset_in_state(CHIPSET_STATE_ON)) { + /* In S0 power LED is always on */ + enable = 1; + ticks = 0; + } else if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND)) { + desired_state = led_get_state(); + if (desired_state == STATE_CHARGING_FULL_CHARGE || + desired_state == STATE_CHARGING_LVL_1 || + desired_state == STATE_CHARGING_LVL_2) { + int period; + int led_power_on_ticks = led_power_blink_on_msec / HOOK_TICK_INTERVAL_MS; + int led_power_off_ticks = led_power_blink_off_msec / HOOK_TICK_INTERVAL_MS; + + /* + * If in suspend/standby and the device is charging, then the + * power LED is blinking. + */ + period = led_power_on_ticks + led_power_off_ticks; + enable = ticks % period < led_power_off_ticks ? + 0 : 1; + ticks++; + } else { + enable = 0; + ticks = 0; + } + } else { + enable = 0; + ticks = 0; + } + + led_set_color_power(enable); +} +#endif + static void led_init(void) { /* If battery LED is enabled, set it to "off" to start with */ @@ -112,6 +164,9 @@ static void led_update(void) */ if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED)) led_update_battery(); - /* TODO(b/110084784): add power LED support for phasor */ +#ifdef OCTOPUS_POWER_LED + if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED)) + led_update_power(); +#endif } DECLARE_HOOK(HOOK_TICK, led_update, HOOK_PRIO_DEFAULT); diff --git a/baseboard/octopus/led_states.h b/baseboard/octopus/led_states.h index f66c5adc70..643d9545fa 100644 --- a/baseboard/octopus/led_states.h +++ b/baseboard/octopus/led_states.h @@ -25,14 +25,20 @@ enum led_phase { LED_NUM_PHASES }; +/* + * STATE_CHARGING_LVL_1 is when 0 <= charge_percentage < led_charge_level_1 + * STATE_CHARGING_LVL_2 is when led_charge_level_1 <= charge_percentage < led_charge_level_2 + * STATE_CHARGING_FULL_CHARGE is when led_charge_level_2 <= charge_percentage < 100 + */ enum led_states { - STATE_CHARGING, - /* TODO(b/110086152): more charging states for phasor */ + STATE_CHARGING_LVL_1, + STATE_CHARGING_LVL_2, STATE_CHARGING_FULL_CHARGE, STATE_DISCHARGE_S0, STATE_DISCHARGE_S3, STATE_DISCHARGE_S5, STATE_BATTERY_ERROR, + STATE_FACTORY_TEST, LED_NUM_STATES }; @@ -46,6 +52,20 @@ struct led_descriptor { extern const struct led_descriptor led_bat_state_table[LED_NUM_STATES][LED_NUM_PHASES]; +/* Charging LED state level 1 - defined in board's led.c */ +extern const int led_charge_lvl_1; + +/* Charging LED state level 2 - defined in board's led.c */ +extern const int led_charge_lvl_2; + +#ifdef OCTOPUS_POWER_LED +/* Power LED blink on msec - defined in board's led.c */ +extern const int led_power_blink_on_msec; + +/* Power LED blink off msec - defined in board's led.c */ +extern const int led_power_blink_off_msec; +#endif + /** * Set battery LED color - defined in board's led.c * @@ -54,4 +74,11 @@ extern const struct led_descriptor */ void led_set_color_battery(enum ec_led_colors color); +#ifdef OCTOPUS_POWER_LED +/** + * Set power LED color - defined in board's led.c + */ +void led_set_color_power(int enable); +#endif + #endif /* __CROS_EC_BASEBOARD_LED_H */ |