diff options
author | Devin Lu <devin.lu@quantatw.com> | 2019-04-08 14:27:40 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-04-20 03:58:23 -0700 |
commit | e4c9dbe8bd1d659fe2a0637069744c6150561cf8 (patch) | |
tree | 885e90755399d418ca7693c48d5fe8edaeafc5b5 | |
parent | d8fb8d23c9ae774bce3f345c882c880e25d1790c (diff) | |
download | chrome-ec-e4c9dbe8bd1d659fe2a0637069744c6150561cf8.tar.gz |
common: led_onoff_states: move forward baseboard led_state to common code
Now we have led_onoff_states instead of led_state of baseboard, to avoid
duplicate file so move forward to common code.
BUG=b:126460269
BRANCH=none
TEST=make buildall -j, make sure led behavior on meep intended as well.
Change-Id: I3adf20ebf2efd2f02b1ae101faf1c36f2f5ed454
Signed-off-by: Devin Lu <Devin.Lu@quantatw.com>
Reviewed-on: https://chromium-review.googlesource.com/1556869
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Reviewed-by: Marco Chen <marcochen@chromium.org>
Reviewed-by: Paul Fagerburg <pfagerburg@chromium.org>
Reviewed-by: Diana Z <dzigterman@chromium.org>
-rw-r--r-- | baseboard/octopus/baseboard.h | 1 | ||||
-rw-r--r-- | baseboard/octopus/build.mk | 1 | ||||
-rw-r--r-- | baseboard/octopus/led_states.c | 222 | ||||
-rw-r--r-- | baseboard/octopus/led_states.h | 95 | ||||
-rw-r--r-- | board/aleena/led.c | 2 | ||||
-rw-r--r-- | board/ampton/led.c | 2 | ||||
-rw-r--r-- | board/bloog/board.h | 4 | ||||
-rw-r--r-- | board/bloog/led.c | 2 | ||||
-rw-r--r-- | board/bobba/led.c | 2 | ||||
-rw-r--r-- | board/casta/board.h | 2 | ||||
-rw-r--r-- | board/casta/led.c | 2 | ||||
-rw-r--r-- | board/fleex/board.h | 2 | ||||
-rw-r--r-- | board/fleex/led.c | 2 | ||||
-rw-r--r-- | board/meep/board.h | 4 | ||||
-rw-r--r-- | board/meep/led.c | 2 | ||||
-rw-r--r-- | board/phaser/board.h | 2 | ||||
-rw-r--r-- | board/phaser/led.c | 2 | ||||
-rw-r--r-- | board/yorp/led.c | 2 | ||||
-rw-r--r-- | include/led_onoff_states.h | 2 |
19 files changed, 18 insertions, 335 deletions
diff --git a/baseboard/octopus/baseboard.h b/baseboard/octopus/baseboard.h index cb923fb385..977416f0d2 100644 --- a/baseboard/octopus/baseboard.h +++ b/baseboard/octopus/baseboard.h @@ -90,6 +90,7 @@ #define CONFIG_LOW_POWER_IDLE #define CONFIG_DPTF #define CONFIG_BOARD_HAS_RTC_RESET +#define CONFIG_LED_ONOFF_STATES /* Port80 -- allow larger buffer for port80 messages */ #undef CONFIG_PORT80_HISTORY_LEN diff --git a/baseboard/octopus/build.mk b/baseboard/octopus/build.mk index ccce76a0a6..efb37acb04 100644 --- a/baseboard/octopus/build.mk +++ b/baseboard/octopus/build.mk @@ -7,7 +7,6 @@ # baseboard-y=baseboard.o -baseboard-$(CONFIG_LED_COMMON)+=led_states.o baseboard-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_policy.o baseboard-$(VARIANT_OCTOPUS_EC_NPCX796FB)+=variant_ec_npcx796fb.o baseboard-$(VARIANT_OCTOPUS_EC_ITE8320)+=variant_ec_ite8320.o diff --git a/baseboard/octopus/led_states.c b/baseboard/octopus/led_states.c deleted file mode 100644 index 4836a1c18a..0000000000 --- a/baseboard/octopus/led_states.c +++ /dev/null @@ -1,222 +0,0 @@ -/* Copyright 2018 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * Power and battery LED state control for octopus boards - */ - -#include "battery.h" -#include "charge_state.h" -#include "chipset.h" -#include "console.h" -#include "ec_commands.h" -#include "extpower.h" -#include "hooks.h" -#include "led_common.h" -#include "led_states.h" - -#define CPRINTS(format, args...) cprints(CC_GPIO, format, ## args) - -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: - /* 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 - if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) - new_state = STATE_CHARGING_FULL_S5; - else - new_state = STATE_CHARGING_FULL_CHARGE; - break; - case PWR_STATE_DISCHARGE_FULL: - if (extpower_is_present()) { - if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) - new_state = STATE_CHARGING_FULL_S5; - else - new_state = STATE_CHARGING_FULL_CHARGE; - break; - } - /* Intentional fall-through */ - case PWR_STATE_DISCHARGE /* and PWR_STATE_DISCHARGE_FULL */: - if (chipset_in_state(CHIPSET_STATE_ON)) { -#ifdef OCTOPUS_BATT_FUEL_LOW_LED - if (charge_get_percent() < - OCTOPUS_BATT_FUEL_LOW_LED) - new_state = STATE_DISCHARGE_S0_BAT_LOW; - else -#endif - new_state = STATE_DISCHARGE_S0; - } - else if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND)) - new_state = STATE_DISCHARGE_S3; - else - new_state = STATE_DISCHARGE_S5; - break; - case PWR_STATE_ERROR: - new_state = STATE_BATTERY_ERROR; - break; - case PWR_STATE_CHARGE_NEAR_FULL: - if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) - new_state = STATE_CHARGING_FULL_S5; - else - new_state = STATE_CHARGING_FULL_CHARGE; - break; - case PWR_STATE_IDLE: /* External power connected in IDLE */ - 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 */ - break; - } - - return new_state; -} - -static void led_update_battery(void) -{ - static uint8_t ticks, period; - static int led_state = LED_NUM_STATES; - int phase; - enum led_states desired_state = led_get_state(); - - /* - * We always need to check the current state since the value could - * have been manually overwritten. If we're in a new valid state, - * update our ticks and period info. If our new state isn't defined, - * continue using the previous one. - */ - if (desired_state != led_state && desired_state < LED_NUM_STATES) { - /* - * Allow optional CHARGING_FULL_S5 state to fall back to - * FULL_CHARGE if not defined. - */ - if (desired_state == STATE_CHARGING_FULL_S5 && - led_bat_state_table[desired_state][LED_PHASE_0].time == 0) - desired_state = STATE_CHARGING_FULL_CHARGE; - - /* State is changing */ - led_state = desired_state; - /* Reset ticks and period when state changes */ - ticks = 0; - - period = led_bat_state_table[led_state][LED_PHASE_0].time + - led_bat_state_table[led_state][LED_PHASE_1].time; - - } - - /* If this state is undefined, turn the LED off */ - if (period == 0) { - CPRINTS("Undefined LED behavior for battery state %d," - "turning off LED", led_state); - led_set_color_battery(LED_OFF); - return; - } - - /* - * Determine which phase of the state table to use. The phase is - * determined if it falls within first phase time duration. - */ - phase = ticks < led_bat_state_table[led_state][LED_PHASE_0].time ? - 0 : 1; - ticks = (ticks + 1) % period; - - /* Set the color for the given state and phase */ - led_set_color_battery(led_bat_state_table[led_state][phase].color); -} - -#ifdef OCTOPUS_POWER_LED -static enum pwr_led_states pwr_led_get_state(void) -{ - if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND)) { - if (extpower_is_present()) - return PWR_LED_STATE_SUSPEND_AC; - else - return PWR_LED_STATE_SUSPEND_NO_AC; - } else if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) { - return PWR_LED_STATE_OFF; - } else if (chipset_in_state(CHIPSET_STATE_ON)) { - return PWR_LED_STATE_ON; - } - - return PWR_LED_NUM_STATES; -} - -static void led_update_power(void) -{ - static uint8_t ticks, period; - static enum pwr_led_states led_state = PWR_LED_NUM_STATES; - int phase; - enum pwr_led_states desired_state = pwr_led_get_state(); - - /* - * If we're in a new valid state, update our ticks and period info. - * Otherwise, continue to use old state - */ - if (desired_state != led_state && desired_state < PWR_LED_NUM_STATES) { - /* State is changing */ - led_state = desired_state; - /* Reset ticks and period when state changes */ - ticks = 0; - - period = led_pwr_state_table[led_state][LED_PHASE_0].time + - led_pwr_state_table[led_state][LED_PHASE_1].time; - - } - - /* If this state is undefined, turn the LED off */ - if (period == 0) { - CPRINTS("Undefined LED behavior for power state %d," - "turning off LED", led_state); - led_set_color_power(LED_OFF); - return; - } - - /* - * Determine which phase of the state table to use. The phase is - * determined if it falls within first phase time duration. - */ - phase = ticks < led_pwr_state_table[led_state][LED_PHASE_0].time ? - 0 : 1; - ticks = (ticks + 1) % period; - - /* Set the color for the given state and phase */ - led_set_color_power(led_pwr_state_table[led_state][phase].color); - -} -#endif - -static void led_init(void) -{ - /* If battery LED is enabled, set it to "off" to start with */ - if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED)) - led_set_color_battery(LED_OFF); -} -DECLARE_HOOK(HOOK_INIT, led_init, HOOK_PRIO_DEFAULT); - -/* Called by hook task every hook tick (200 msec) */ -static void led_update(void) -{ - /* - * If battery LED is enabled, set its state based on our power and - * charge - */ - if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED)) - led_update_battery(); -#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 deleted file mode 100644 index 72e8b37f73..0000000000 --- a/baseboard/octopus/led_states.h +++ /dev/null @@ -1,95 +0,0 @@ -/* Copyright 2018 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * Common functions for stateful LEDs (charger and power) - */ - -#ifndef __CROS_EC_BASEBOARD_LED_H -#define __CROS_EC_BASEBOARD_LED_H - -#include "ec_commands.h" - -#define LED_INDEFINITE UINT8_MAX -#define LED_ONE_SEC (1000 / HOOK_TICK_INTERVAL_MS) -#define LED_OFF EC_LED_COLOR_COUNT - -/* - * All LED states should have one phase defined, - * and an additional phase can be defined for blinking - */ -enum led_phase { - LED_PHASE_0, - LED_PHASE_1, - 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 - * - * STATE_CHARGING_FULL_S5 is optional and state machine will fall back to - * FULL_CHARGE if not defined - */ -enum led_states { - STATE_CHARGING_LVL_1, - STATE_CHARGING_LVL_2, - STATE_CHARGING_FULL_CHARGE, - STATE_CHARGING_FULL_S5, - STATE_DISCHARGE_S0, - STATE_DISCHARGE_S0_BAT_LOW, - STATE_DISCHARGE_S3, - STATE_DISCHARGE_S5, - STATE_BATTERY_ERROR, - STATE_FACTORY_TEST, - LED_NUM_STATES -}; - -struct led_descriptor { - enum ec_led_colors color; - uint8_t time; -}; - - -/* Charging LED state table - defined in board's led.c */ -extern 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 -enum pwr_led_states { - PWR_LED_STATE_ON, - PWR_LED_STATE_SUSPEND_AC, - PWR_LED_STATE_SUSPEND_NO_AC, - PWR_LED_STATE_OFF, - PWR_LED_NUM_STATES -}; - -/* Power LED state table - defined in board's led.c */ -extern const struct led_descriptor - led_pwr_state_table[PWR_LED_NUM_STATES][LED_NUM_PHASES]; - -#endif - -/** - * Set battery LED color - defined in board's led.c - * - * @param color Color to set on battery LED - * - */ -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(enum ec_led_colors color); -#endif - -#endif /* __CROS_EC_BASEBOARD_LED_H */ diff --git a/board/aleena/led.c b/board/aleena/led.c index f68f8c7374..430400e6ae 100644 --- a/board/aleena/led.c +++ b/board/aleena/led.c @@ -28,7 +28,7 @@ static enum gpio_signal led_amber = GPIO_BAT_LED_1_L; static enum gpio_signal led_blue = GPIO_BAT_LED_2_L; /* Note there is only LED for charge / power */ -const struct led_descriptor +struct led_descriptor led_bat_state_table[LED_NUM_STATES][LED_NUM_PHASES] = { [STATE_CHARGING_LVL_2] = {{EC_LED_COLOR_AMBER, LED_INDEFINITE} }, [STATE_CHARGING_FULL_CHARGE] = {{EC_LED_COLOR_BLUE, LED_INDEFINITE} }, diff --git a/board/ampton/led.c b/board/ampton/led.c index c6be838cbc..68f9e3eac8 100644 --- a/board/ampton/led.c +++ b/board/ampton/led.c @@ -8,7 +8,7 @@ #include "ec_commands.h" #include "gpio.h" #include "led_common.h" -#include "led_states.h" +#include "led_onoff_states.h" #define LED_OFF_LVL 0 #define LED_ON_LVL 1 diff --git a/board/bloog/board.h b/board/bloog/board.h index 075d70ecc0..aececb619d 100644 --- a/board/bloog/board.h +++ b/board/bloog/board.h @@ -22,7 +22,7 @@ #define CONFIG_CMD_ACCEL_INFO #define CONFIG_LED_COMMON -#define OCTOPUS_POWER_LED +#define CONFIG_LED_POWER_LED #define CONFIG_EC_FEATURE_BOARD_OVERRIDE @@ -48,7 +48,7 @@ #define CONFIG_KEYBOARD_FACTORY_TEST -#define OCTOPUS_BATT_FUEL_LOW_LED 10 +#define CONFIG_LED_ONOFF_STATES_BAT_LOW 10 #define CONFIG_ACCEL_LSM6DSM_INT_EVENT \ TASK_EVENT_MOTION_SENSOR_INTERRUPT(LID_ACCEL) diff --git a/board/bloog/led.c b/board/bloog/led.c index 86f425c406..8692cbc8c8 100644 --- a/board/bloog/led.c +++ b/board/bloog/led.c @@ -8,7 +8,7 @@ #include "ec_commands.h" #include "gpio.h" #include "led_common.h" -#include "led_states.h" +#include "led_onoff_states.h" #include "hooks.h" #define LED_OFF_LVL 1 diff --git a/board/bobba/led.c b/board/bobba/led.c index c54ffb6ab2..6c5ae18272 100644 --- a/board/bobba/led.c +++ b/board/bobba/led.c @@ -8,7 +8,7 @@ #include "ec_commands.h" #include "gpio.h" #include "led_common.h" -#include "led_states.h" +#include "led_onoff_states.h" #define LED_OFF_LVL 1 #define LED_ON_LVL 0 diff --git a/board/casta/board.h b/board/casta/board.h index e7afd7a51b..be9192ea3b 100644 --- a/board/casta/board.h +++ b/board/casta/board.h @@ -16,7 +16,7 @@ #include "baseboard.h" #define CONFIG_LED_COMMON -#define OCTOPUS_POWER_LED +#define CONFIG_LED_POWER_LED /* USB PD */ #undef CONFIG_USB_PD_VBUS_MEASURE_ADC_EACH_PORT diff --git a/board/casta/led.c b/board/casta/led.c index f5aecd24bf..97b32f86ec 100644 --- a/board/casta/led.c +++ b/board/casta/led.c @@ -10,7 +10,7 @@ #include "gpio.h" #include "hooks.h" #include "led_common.h" -#include "led_states.h" +#include "led_onoff_states.h" #define LED_OFF_LVL 1 #define LED_ON_LVL 0 diff --git a/board/fleex/board.h b/board/fleex/board.h index 6ff03fd4c0..2b23045be2 100644 --- a/board/fleex/board.h +++ b/board/fleex/board.h @@ -18,7 +18,7 @@ #define CONFIG_CMD_ACCEL_INFO #define CONFIG_LED_COMMON -#define OCTOPUS_BATT_FUEL_LOW_LED 10 +#define CONFIG_LED_ONOFF_STATES_BAT_LOW 10 /* Sensors */ #define CONFIG_ACCEL_LIS2DE /* Lid accel */ diff --git a/board/fleex/led.c b/board/fleex/led.c index c658dc369e..d502c16797 100644 --- a/board/fleex/led.c +++ b/board/fleex/led.c @@ -8,7 +8,7 @@ #include "ec_commands.h" #include "gpio.h" #include "led_common.h" -#include "led_states.h" +#include "led_onoff_states.h" #define LED_OFF_LVL 1 #define LED_ON_LVL 0 diff --git a/board/meep/board.h b/board/meep/board.h index 39782aeaf8..f1ab68ae9a 100644 --- a/board/meep/board.h +++ b/board/meep/board.h @@ -22,7 +22,7 @@ #define CONFIG_CMD_ACCEL_INFO #define CONFIG_LED_COMMON -#define OCTOPUS_POWER_LED +#define CONFIG_LED_POWER_LED /* Sensors */ #define CONFIG_ACCEL_KX022 /* Lid accel */ @@ -45,7 +45,7 @@ #define CONFIG_KEYBOARD_FACTORY_TEST -#define OCTOPUS_BATT_FUEL_LOW_LED 10 +#define CONFIG_LED_ONOFF_STATES_BAT_LOW 10 #define CONFIG_ACCEL_LSM6DSM_INT_EVENT \ TASK_EVENT_MOTION_SENSOR_INTERRUPT(BASE_ACCEL) diff --git a/board/meep/led.c b/board/meep/led.c index 7f4754ca2c..7baedca253 100644 --- a/board/meep/led.c +++ b/board/meep/led.c @@ -8,7 +8,7 @@ #include "ec_commands.h" #include "gpio.h" #include "led_common.h" -#include "led_states.h" +#include "led_onoff_states.h" #include "hooks.h" #define LED_OFF_LVL 1 diff --git a/board/phaser/board.h b/board/phaser/board.h index b035268b1c..b79b31dd58 100644 --- a/board/phaser/board.h +++ b/board/phaser/board.h @@ -18,7 +18,7 @@ #define GPIO_VOLUME_DOWN_L GPIO_EC_VOLDN_BTN_ODL #define CONFIG_LED_COMMON -#define OCTOPUS_POWER_LED +#define CONFIG_LED_POWER_LED #define CONFIG_TEMP_SENSOR #define CONFIG_THERMISTOR #define CONFIG_STEINHART_HART_3V3_13K7_47K_4050B diff --git a/board/phaser/led.c b/board/phaser/led.c index 6fcc2e36c0..115832e3b6 100644 --- a/board/phaser/led.c +++ b/board/phaser/led.c @@ -8,7 +8,7 @@ #include "ec_commands.h" #include "gpio.h" #include "led_common.h" -#include "led_states.h" +#include "led_onoff_states.h" #include "chipset.h" #define LED_ON_LVL 0 diff --git a/board/yorp/led.c b/board/yorp/led.c index 08ac48661e..e5dd48327b 100644 --- a/board/yorp/led.c +++ b/board/yorp/led.c @@ -8,7 +8,7 @@ #include "ec_commands.h" #include "gpio.h" #include "led_common.h" -#include "led_states.h" +#include "led_onoff_states.h" #define LED_OFF_LVL 1 #define LED_ON_LVL 0 diff --git a/include/led_onoff_states.h b/include/led_onoff_states.h index 6ec407acdd..e8c3e67cb2 100644 --- a/include/led_onoff_states.h +++ b/include/led_onoff_states.h @@ -55,7 +55,7 @@ struct led_descriptor { /* Charging LED state table - defined in board's led.c */ -extern const struct led_descriptor +extern struct led_descriptor led_bat_state_table[LED_NUM_STATES][LED_NUM_PHASES]; /* Charging LED state level 1 - defined in board's led.c */ |