diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2019-02-04 10:30:54 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-02-09 03:14:26 -0800 |
commit | a012cf8d31667b213f6bd49dd4447b5a3061be79 (patch) | |
tree | e3c06c8e52c9ee734e7cdb7736714a454ee1d660 | |
parent | 6ea830328941f24fc01213030c8ab8865ac4a2f1 (diff) | |
download | chrome-ec-a012cf8d31667b213f6bd49dd4447b5a3061be79.tar.gz |
RT946x: Make mt6370_led_set_color accept composite colors
Currently, mt6370_led_set_color can handle only simple colors. That
is, if a green LED is turned on, other LEDs are forced to be off.
To allow composite colors (e.g. red+green), this change makes
mt6370_led_set_color control LEDs independently. For example, to mix
green and red, it can be called as
mt6370_led_set_color(LED_MASK_GREEN | LED_MASK_RED);
This is consistent with other RT946x LED APIs in the sense that they
also control each LED independently.
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
BUG=b/123613083
BRANCH=none
TEST=Verify LED behavior doesn't change on Kukui by console command
Change-Id: Idb80a124462b30adca6af86621aed136be8caa99
Reviewed-on: https://chromium-review.googlesource.com/1452617
Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r-- | board/kukui/led.c | 20 | ||||
-rw-r--r-- | driver/charger/rt946x.c | 16 | ||||
-rw-r--r-- | driver/charger/rt946x.h | 10 |
3 files changed, 23 insertions, 23 deletions
diff --git a/board/kukui/led.c b/board/kukui/led.c index 2b6c19a07e..f66dd46fbf 100644 --- a/board/kukui/led.c +++ b/board/kukui/led.c @@ -20,6 +20,10 @@ const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids); #define LED_GREEN MT6370_LED_ID1 #define LED_RED MT6370_LED_ID2 +#define LED_MASK_OFF 0 +#define LED_MASK_GREEN MT6370_MASK_RGB_ISNK1DIM_EN +#define LED_MASK_RED MT6370_MASK_RGB_ISNK2DIM_EN + static void kukui_led_set_battery(void) { static int battery_second; @@ -30,29 +34,29 @@ static void kukui_led_set_battery(void) switch (charge_get_state()) { case PWR_STATE_CHARGE: /* Always indicate when charging, even in suspend. */ - mt6370_led_set_color(LED_RED); + mt6370_led_set_color(LED_MASK_RED); break; case PWR_STATE_DISCHARGE: if (charge_get_percent() <= 10) - mt6370_led_set_color( - (battery_second & 0x4) ? LED_RED : LED_OFF); + mt6370_led_set_color((battery_second & 0x4) ? + LED_MASK_RED : LED_MASK_OFF); else - mt6370_led_set_color(LED_OFF); + mt6370_led_set_color(LED_MASK_OFF); break; case PWR_STATE_ERROR: mt6370_led_set_color((battery_second & 0x2) ? - LED_RED : LED_OFF); + LED_MASK_RED : LED_MASK_OFF); break; case PWR_STATE_CHARGE_NEAR_FULL: - mt6370_led_set_color(LED_GREEN); + mt6370_led_set_color(LED_MASK_GREEN); break; case PWR_STATE_IDLE: /* External power connected in IDLE. */ if (chflags & CHARGE_FLAG_FORCE_IDLE) { - mt6370_led_set_color(LED_RED); + mt6370_led_set_color(LED_MASK_RED); mt6370_led_set_dim_mode(LED_RED, MT6370_LED_DIM_MODE_BREATH); } else { - mt6370_led_set_color(LED_GREEN); + mt6370_led_set_color(LED_MASK_GREEN); mt6370_led_set_dim_mode(LED_GREEN, MT6370_LED_DIM_MODE_BREATH); } diff --git a/driver/charger/rt946x.c b/driver/charger/rt946x.c index c6f748017d..35fb6fcb15 100644 --- a/driver/charger/rt946x.c +++ b/driver/charger/rt946x.c @@ -1033,20 +1033,10 @@ int mt6370_led_set_dim_mode(enum mt6370_led_index index, return EC_SUCCESS; } -int mt6370_led_set_color(enum mt6370_led_index index) +int mt6370_led_set_color(uint8_t mask) { - int val; - - if (index >= MT6370_LED_ID_COUNT) - return EC_ERROR_INVAL; - - if (index == MT6370_LED_ID_OFF) - val = 0; - else - val = 1 << (MT6370_SHIFT_RGB_ISNKDIM_BASE - index); - - rt946x_update_bits(MT6370_REG_RGBEN, MT6370_MASK_RGB_ISNK_ALL_EN, val); - return EC_SUCCESS; + return rt946x_update_bits(MT6370_REG_RGBEN, MT6370_MASK_RGB_ISNK_ALL_EN, + mask); } int mt6370_led_set_brightness(enum mt6370_led_index index, uint8_t brightness) diff --git a/driver/charger/rt946x.h b/driver/charger/rt946x.h index 21ce65536b..9f1d682901 100644 --- a/driver/charger/rt946x.h +++ b/driver/charger/rt946x.h @@ -566,8 +566,14 @@ enum mt6370_led_pwm_freq { /* Set LED brightness */ int mt6370_led_set_brightness(enum mt6370_led_index index, uint8_t brightness); -/* Set LED Color */ -int mt6370_led_set_color(enum mt6370_led_index index); +/** + * Set LED Color + * + * mask: Bitmap indicating 1=on 0=off for each LED. 000 = all off. + * Combination of MT6370_MASK_RGB_ISNK1/2/3DIM_EN. + * return: EC_SUCCESS or EC_ERROR_* on error. + */ +int mt6370_led_set_color(uint8_t mask); /* Set LED dim mode, available modes: REGISTER, PWM, BREATH. */ int mt6370_led_set_dim_mode(enum mt6370_led_index index, |