From 5436afc8f67e740a49f1e6e4fae2c7f4c8dee16d Mon Sep 17 00:00:00 2001 From: Scott Collyer Date: Thu, 12 Oct 2017 14:09:53 -0700 Subject: coral: Add support for power LED for Robo devices Robo devices have a power button LED. For these devices the desried power button LED behavior is: S0 -> always on S3 -> charging, then 500 mSec off, 3 seconds on S3 -> not charging, always off S5 -> always off Because the hook tick runs at 200 msec, using 600 msec for the off period when blinking in S3. BUG=b:64015212 BRANCH=None TEST=Manual This LED is not connected on EVT, so added a wire on GPIO02 and used a scope. Verifed that in S0 the signal level is low, and in S3 that it control signal toggles 600 mSec high/3 sec low. Verifed than in S5 control signal is high. Change-Id: I72438a009a507fcddaae5a673bf3bc83988f2dd5 Signed-off-by: Scott Collyer Reviewed-on: https://chromium-review.googlesource.com/717183 Commit-Ready: Scott Collyer Tested-by: Scott Collyer Reviewed-by: Patrick Georgi --- board/coral/gpio.inc | 6 +++--- board/coral/led.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 48 insertions(+), 6 deletions(-) (limited to 'board/coral') diff --git a/board/coral/gpio.inc b/board/coral/gpio.inc index f0a49f387e..642e1fb8d4 100644 --- a/board/coral/gpio.inc +++ b/board/coral/gpio.inc @@ -75,7 +75,6 @@ GPIO(PCH_SLP_S0_L, PIN(7, 5), GPIO_INPUT) /* SLP_S0_L */ GPIO(EC_BRD_ID_EN, PIN(3, 5), GPIO_INPUT) GPIO(CCD_MODE_ODL, PIN(6, 3), GPIO_INPUT) -GPIO(EC_HAVEN_RESET_ODL, PIN(0, 2), GPIO_ODR_HIGH) GPIO(ENTERING_RW, PIN(7, 6), GPIO_OUTPUT) /* EC_ENTERING_RW */ GPIO(PCH_RSMRST_L, PIN(7, 0), GPIO_OUT_LOW) @@ -131,8 +130,9 @@ GPIO(USB_C1_PD_RST_ODL, PIN(7, 4), GPIO_ODR_LOW) GPIO(USB_C0_5V_EN, PIN(D, 3), GPIO_OUT_LOW | GPIO_PULL_UP) /* EN_USB_C0_5V_OUT, Enable C0 */ GPIO(USB_C1_5V_EN, PIN(D, 2), GPIO_OUT_LOW | GPIO_PULL_UP) /* EN_USB_C1_5V_OUT, Enable C1 */ -GPIO(BAT_LED_BLUE, PIN(8, 0), GPIO_OUT_HIGH) -GPIO(BAT_LED_AMBER, PIN(C, 4), GPIO_OUT_HIGH) +GPIO(BAT_LED_BLUE, PIN(8, 0), GPIO_OUT_HIGH) +GPIO(BAT_LED_AMBER, PIN(C, 4), GPIO_OUT_HIGH) +GPIO(POWER_LED, PIN(0, 2), GPIO_OUT_HIGH) /* diff --git a/board/coral/led.c b/board/coral/led.c index 671b02f228..6e26177522 100644 --- a/board/coral/led.c +++ b/board/coral/led.c @@ -23,6 +23,10 @@ #define LED_ONE_SEC (1000 / HOOK_TICK_INTERVAL_MS) #define LED_CHARGE_LEVEL_1_DEFAULT 100 #define LED_CHARGE_LEVEL_1_ROBO 5 +#define LED_POWER_BLINK_ON_MSEC 3000 +#define LED_POWER_BLINK_OFF_MSEC 600 +#define LED_POWER_ON_TICKS (LED_POWER_BLINK_ON_MSEC / HOOK_TICK_INTERVAL_MS) +#define LED_POWER_OFF_TICKS (LED_POWER_BLINK_OFF_MSEC / HOOK_TICK_INTERVAL_MS) const enum ec_led_id supported_led_ids[] = { EC_LED_ID_BATTERY_LED}; @@ -130,6 +134,11 @@ static int led_set_color_battery(enum led_color color) return EC_SUCCESS; } +static void led_set_color_power(int level) +{ + gpio_set_level(GPIO_POWER_LED, level); +} + void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range) { brightness_range[EC_LED_COLOR_BLUE] = 1; @@ -241,12 +250,45 @@ static void led_update_battery(void) ticks++; } -/* Called by hook task every 1 sec */ +static void led_robo_update_power(void) +{ + int level; + static int ticks; + + if (chipset_in_state(CHIPSET_STATE_ON)) { + /* In S0 power LED is always on */ + level = LED_ON_LVL; + ticks = 0; + } else if ((chipset_in_state(CHIPSET_STATE_SUSPEND) | + chipset_in_state(CHIPSET_STATE_STANDBY)) && + led.state <= STATE_CHARGING_LVL_3) { + int period; + + /* + * If in suspend/standby and the device is charging, then the + * power LED is off for 600 msec, on for 3 seconds. + */ + period = LED_POWER_ON_TICKS + LED_POWER_OFF_TICKS; + level = ticks % period < LED_POWER_OFF_TICKS ? + LED_OFF_LVL : LED_ON_LVL; + ticks++; + } else { + level = LED_OFF_LVL; + ticks = 0; + } + + led_set_color_power(level); +} + +/* Called by hook task every hook tick (200 msec) */ static void led_update(void) { /* Update battery LED */ - if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED)) + if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED)) { led_update_battery(); + if (led.update_power != NULL) + (*led.update_power)(); + } } DECLARE_HOOK(HOOK_TICK, led_update, HOOK_PRIO_DEFAULT); @@ -258,7 +300,7 @@ static void led_init(void) (sku >= 144 && sku <= 145)) { led.charge_lvl_1 = LED_CHARGE_LEVEL_1_ROBO; led.state_table = led_robo_state_table; - led.update_power = NULL; + led.update_power = led_robo_update_power; } else { led.charge_lvl_1 = LED_CHARGE_LEVEL_1_DEFAULT; led.state_table = led_default_state_table; -- cgit v1.2.1