diff options
-rw-r--r-- | board/damu/board.h | 4 | ||||
-rw-r--r-- | board/damu/build.mk | 2 | ||||
-rw-r--r-- | board/damu/gpio.inc | 3 | ||||
-rw-r--r-- | board/damu/led.c | 105 |
4 files changed, 113 insertions, 1 deletions
diff --git a/board/damu/board.h b/board/damu/board.h index c708676e3e..5c3c6187a4 100644 --- a/board/damu/board.h +++ b/board/damu/board.h @@ -41,6 +41,10 @@ #define CONFIG_USB_MUX_IT5205 +#define CONFIG_LED_ONOFF_STATES +#define CONFIG_LED_POWER_LED +#define CONFIG_LED_COMMON + /* Motion Sensors */ #ifdef SECTION_IS_RW #define CONFIG_MAG_BMI160_BMM150 diff --git a/board/damu/build.mk b/board/damu/build.mk index 6f67a089d7..0b3565fd84 100644 --- a/board/damu/build.mk +++ b/board/damu/build.mk @@ -12,4 +12,4 @@ CHIP_FAMILY:=stm32f0 CHIP_VARIANT:=stm32f09x BASEBOARD:=kukui -board-y=battery.o board.o +board-y=battery.o board.o led.o diff --git a/board/damu/gpio.inc b/board/damu/gpio.inc index 840baee37d..4c555e84b7 100644 --- a/board/damu/gpio.inc +++ b/board/damu/gpio.inc @@ -82,6 +82,9 @@ GPIO(BOOTBLOCK_EN_L, PIN(C, 1), GPIO_ODR_HIGH) GPIO(EN_PP1800_S5_L, PIN(A, 14), GPIO_OUT_LOW) GPIO(USB_C0_DISCHARGE, PIN(B, 6), GPIO_OUT_LOW) +IOEX(PWR_LED_WHITE_L, EXPIN(0, 2, 2), GPIO_OUT_HIGH) +IOEX(BAT_LED_WHITE_L, EXPIN(0, 1, 3), GPIO_OUT_HIGH) +IOEX(BAT_LED_AMBER_L, EXPIN(0, 1, 2), GPIO_OUT_HIGH) /* * TODO(b:138352732): On IT88801 expander, To be readded once IT8801 driver and * gpio expander framework has landed. diff --git a/board/damu/led.c b/board/damu/led.c new file mode 100644 index 0000000000..a6f27f2200 --- /dev/null +++ b/board/damu/led.c @@ -0,0 +1,105 @@ +/* Copyright 2020 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 control for Damu + */ +#include "common.h" +#include "ioexpander.h" +#include "driver/ioexpander/it8801.h" +#include "ec_commands.h" +#include "led_common.h" +#include "led_onoff_states.h" + +#define LED_ON_LVL 0 +#define LED_OFF_LVL 1 + +const int led_charge_lvl_1 = 5; +const int led_charge_lvl_2 = 95; + +struct led_descriptor led_bat_state_table[LED_NUM_STATES][LED_NUM_PHASES] = { + [STATE_CHARGING_LVL_1] = {{EC_LED_COLOR_AMBER, LED_INDEFINITE} }, + [STATE_CHARGING_LVL_2] = {{EC_LED_COLOR_AMBER, LED_INDEFINITE} }, + [STATE_CHARGING_FULL_CHARGE] = {{EC_LED_COLOR_WHITE, LED_INDEFINITE} }, + [STATE_DISCHARGE_S0] = {{LED_OFF, LED_INDEFINITE} }, + [STATE_DISCHARGE_S3] = {{LED_OFF, LED_INDEFINITE} }, + [STATE_DISCHARGE_S5] = {{LED_OFF, LED_INDEFINITE} }, + [STATE_BATTERY_ERROR] = {{EC_LED_COLOR_AMBER, 1 * LED_ONE_SEC}, + {LED_OFF, 1 * LED_ONE_SEC} }, + [STATE_FACTORY_TEST] = {{EC_LED_COLOR_WHITE, 2 * LED_ONE_SEC}, + {EC_LED_COLOR_AMBER, 2 * LED_ONE_SEC} }, +}; + +const struct led_descriptor led_pwr_state_table[PWR_LED_NUM_STATES][LED_NUM_PHASES] = { + [PWR_LED_STATE_ON] = {{EC_LED_COLOR_WHITE, LED_INDEFINITE} }, + [PWR_LED_STATE_SUSPEND_AC] = {{EC_LED_COLOR_WHITE, 1 * LED_ONE_SEC}, + {LED_OFF, 3 * LED_ONE_SEC} }, + [PWR_LED_STATE_SUSPEND_NO_AC] = {{LED_OFF, LED_INDEFINITE} }, + [PWR_LED_STATE_OFF] = {{LED_OFF, LED_INDEFINITE} }, +}; + +const enum ec_led_id supported_led_ids[] = { + EC_LED_ID_POWER_LED, + EC_LED_ID_BATTERY_LED +}; +const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids); + +void led_set_color_battery(enum ec_led_colors color) +{ + switch (color) { + case EC_LED_COLOR_WHITE: + ioex_set_level(IOEX_BAT_LED_WHITE_L, LED_ON_LVL); + ioex_set_level(IOEX_BAT_LED_AMBER_L, LED_OFF_LVL); + break; + case EC_LED_COLOR_AMBER: + ioex_set_level(IOEX_BAT_LED_WHITE_L, LED_OFF_LVL); + ioex_set_level(IOEX_BAT_LED_AMBER_L, LED_ON_LVL); + break; + default: /* LED_OFF and other unsupported colors */ + ioex_set_level(IOEX_BAT_LED_WHITE_L, LED_OFF_LVL); + ioex_set_level(IOEX_BAT_LED_AMBER_L, LED_OFF_LVL); + break; + } +} + +void led_set_color_power(enum ec_led_colors color) +{ + switch (color) { + case EC_LED_COLOR_WHITE: + ioex_set_level(IOEX_PWR_LED_WHITE_L, LED_ON_LVL); + break; + default: + ioex_set_level(IOEX_PWR_LED_WHITE_L, LED_OFF_LVL); + break; + } +} + +void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range) +{ + if(led_id == EC_LED_ID_BATTERY_LED) { + brightness_range[EC_LED_COLOR_AMBER] = 1; + brightness_range[EC_LED_COLOR_WHITE] = 1; + } else if(led_id == EC_LED_ID_POWER_LED) { + brightness_range[EC_LED_COLOR_WHITE] = 1; + } +} + +int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness) +{ + if(led_id == EC_LED_ID_BATTERY_LED) { + if(brightness[EC_LED_COLOR_AMBER] != 0) + led_set_color_battery(EC_LED_COLOR_AMBER); + else if(brightness[EC_LED_COLOR_WHITE] != 0) + led_set_color_battery(EC_LED_COLOR_WHITE); + else + led_set_color_battery(LED_OFF); + } else if(led_id == EC_LED_ID_POWER_LED) { + if (brightness[EC_LED_COLOR_WHITE] != 0) + led_set_color_power(EC_LED_COLOR_WHITE); + else + led_set_color_power(LED_OFF); + } else { + return EC_ERROR_INVAL; + } + return EC_SUCCESS; +} |