diff options
-rw-r--r-- | board/samus/board.h | 1 | ||||
-rw-r--r-- | board/samus/power_sequence.c | 30 | ||||
-rw-r--r-- | common/lightbar.c | 20 | ||||
-rw-r--r-- | include/config.h | 7 | ||||
-rw-r--r-- | include/lb_common.h | 5 |
5 files changed, 57 insertions, 6 deletions
diff --git a/board/samus/board.h b/board/samus/board.h index eb13854008..0bcaddb0bb 100644 --- a/board/samus/board.h +++ b/board/samus/board.h @@ -23,6 +23,7 @@ #define CONFIG_KEYBOARD_BOARD_CONFIG #define CONFIG_KEYBOARD_PROTOCOL_8042 #define CONFIG_KEYBOARD_COL2_INVERTED +#define CONFIG_LIGHTBAR_POWER_RAILS #define CONFIG_LOW_POWER_IDLE #define CONFIG_POWER_BUTTON #define CONFIG_POWER_BUTTON_X86 diff --git a/board/samus/power_sequence.c b/board/samus/power_sequence.c index aabb83d78d..9c166093e8 100644 --- a/board/samus/power_sequence.c +++ b/board/samus/power_sequence.c @@ -436,6 +436,36 @@ enum power_state power_handle_state(enum power_state state) return state; } +#ifdef CONFIG_LIGHTBAR_POWER_RAILS +/* Returns true if a change was made, NOT the new state */ +int lb_power(int enabled) +{ + /* No change needed. */ + if (enabled == gpio_get_level(GPIO_PP5000_EN)) + return 0; + + /* If the AP is on, we don't change the rails. */ + if (!chipset_in_state(CHIPSET_STATE_ANY_OFF)) + return 0; + + /* + * If the AP is off, we can still turn the lightbar on briefly. + * When turning on, we have to wait for the rails to come up fully + * before we the lightbar ICs will respond. There's not a reliable + * PGOOD signal for that (I tried), so we just have to wait. These + * delays seem to work. + */ + gpio_set_level(GPIO_PP5000_EN, enabled); + if (enabled) + msleep(10); + gpio_set_level(GPIO_LIGHTBAR_RESET_L, enabled); + if (enabled) + msleep(1); + + return 1; +} +#endif + static int host_command_gsv(struct host_cmd_handler_args *args) { const struct ec_params_get_set_value *p = args->params; diff --git a/common/lightbar.c b/common/lightbar.c index e817b38da5..8b0352a878 100644 --- a/common/lightbar.c +++ b/common/lightbar.c @@ -74,7 +74,7 @@ static const struct lightbar_params_v1 default_params = { .s3_ramp_up = 2500, .s3_ramp_down = 10000, .tap_tick_delay = 5000, /* oscillation step time */ - .tap_display_time = 5000000, /* total sequence time */ + .tap_display_time = 3000000, /* total sequence time */ .tap_pct_red = 10, /* below this is red */ .tap_pct_green = 97, /* above this is green */ @@ -819,6 +819,8 @@ static uint32_t sequence_TAP_inner(void) start = get_time(); while (1) { + get_battery_level(); + if (st.battery_percent < st.p.tap_pct_red) base_color = RED; else if (st.battery_percent > st.p.tap_pct_green) @@ -877,11 +879,13 @@ static uint32_t sequence_TAP(void) uint32_t r; uint8_t br, save[NUM_LEDS][3]; - /* TODO(crosbug.com/p/29041): Do we need more than lb_init()? - * Yes. And then we may need to turn it off again, if the AP is still - * off when we're done. - */ - lb_init(); +#ifdef CONFIG_LIGHTBAR_POWER_RAILS + /* Request that the lightbar power rails be turned on. */ + if (lb_power(1)) { + lb_init(); + lb_set_rgb(NUM_LEDS, 0, 0, 0); + } +#endif lb_on(); for (i = 0; i < NUM_LEDS; i++) @@ -895,6 +899,10 @@ static uint32_t sequence_TAP(void) for (i = 0; i < NUM_LEDS; i++) lb_set_rgb(i, save[i][0], save[i][1], save[i][2]); +#ifdef CONFIG_LIGHTBAR_POWER_RAILS + /* Suggest that the lightbar power rails can be shut down again. */ + lb_power(0); +#endif return r; } diff --git a/include/config.h b/include/config.h index 535008525c..2a5b6d6999 100644 --- a/include/config.h +++ b/include/config.h @@ -652,6 +652,13 @@ #define CONFIG_LID_SWITCH /* + * Support for turning the lightbar power rails on briefly when the AP is off. + * Enabling this requires implementing the board-specific lb_power() function + * to do it (see lb_common.h). + */ +#undef CONFIG_LIGHTBAR_POWER_RAILS + +/* * Low power idle options. These are disabled by default and all boards that * want to use low power idle must define it. When using the LFIOSC, the low * frequency clock will be used to conserve even more power when possible. diff --git a/include/lb_common.h b/include/lb_common.h index f2f53aae35..49ab193254 100644 --- a/include/lb_common.h +++ b/include/lb_common.h @@ -34,5 +34,10 @@ void lb_start_builtin_cycle(void); void lb_hc_cmd_dump(struct ec_response_lightbar *out); /* Write the IC controller register given by the LIGHTBAR_CMD_REG command. */ void lb_hc_cmd_reg(const struct ec_params_lightbar *in); +/* + * Optional (see config.h). Request that the lightbar power rails be on or off. + * Returns true if a change to the rails was made, false if it wasn't. + */ +int lb_power(int enabled); #endif /* __CROS_EC_LB_COMMON_H */ |