From 74d6255d2d3a68bba43128393397590cad3104d3 Mon Sep 17 00:00:00 2001 From: Boris Mittelberg Date: Thu, 11 Mar 2021 21:24:08 +0000 Subject: brya: Enable LEDs Enable control of right and left LEDs, display charging status. BRANCH=none BUG=b:182329831 TEST=buildall passes, manual test with ectool Signed-off-by: Boris Mittelberg Change-Id: I1463102924a6300843f3381e1b66d88ae0096157 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2752345 Reviewed-by: Tim Wawrzynczak --- baseboard/brya/baseboard.h | 3 ++ board/brya/board.h | 16 +++++++-- board/brya/build.mk | 1 + board/brya/led.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 board/brya/led.c diff --git a/baseboard/brya/baseboard.h b/baseboard/brya/baseboard.h index 298c2d0102..5f729e13da 100644 --- a/baseboard/brya/baseboard.h +++ b/baseboard/brya/baseboard.h @@ -43,6 +43,9 @@ #define CONFIG_MKBP_EVENT #define CONFIG_MKBP_USE_GPIO +/* LED */ +#define CONFIG_LED_COMMON + /* Common charger defines */ #define CONFIG_CHARGE_MANAGER #define CONFIG_CHARGER diff --git a/board/brya/board.h b/board/brya/board.h index de9bf5c97d..a50a2f15ee 100644 --- a/board/brya/board.h +++ b/board/brya/board.h @@ -24,6 +24,18 @@ */ #undef CONFIG_HIBERNATE +/* LED */ +#define CONFIG_LED_PWM +#define CONFIG_LED_PWM_COUNT 2 +#undef CONFIG_LED_PWM_NEAR_FULL_COLOR +#undef CONFIG_LED_PWM_SOC_ON_COLOR +#undef CONFIG_LED_PWM_SOC_SUSPEND_COLOR +#undef CONFIG_LED_PWM_LOW_BATT_COLOR +#define CONFIG_LED_PWM_NEAR_FULL_COLOR EC_LED_COLOR_WHITE +#define CONFIG_LED_PWM_SOC_ON_COLOR EC_LED_COLOR_WHITE +#define CONFIG_LED_PWM_SOC_SUSPEND_COLOR EC_LED_COLOR_WHITE +#define CONFIG_LED_PWM_LOW_BATT_COLOR EC_LED_COLOR_AMBER + /* USB Type A Features */ #define USB_PORT_COUNT 1 #define CONFIG_USB_PORT_POWER_DUMB @@ -167,11 +179,11 @@ enum battery_type { enum pwm_channel { PWM_CH_LED2 = 0, /* PWM0 (white charger) */ - PWM_CH_LED3, /* PWM1 */ + PWM_CH_LED3, /* PWM1 (orange on DB) */ PWM_CH_LED1, /* PWM2 (orange charger) */ PWM_CH_KBLIGHT, /* PWM3 */ PWM_CH_FAN, /* PWM5 */ - PWM_CH_LED4, /* PWM7 */ + PWM_CH_LED4, /* PWM7 (white on DB) */ PWM_CH_COUNT }; diff --git a/board/brya/build.mk b/board/brya/build.mk index 2033590344..03ef008527 100644 --- a/board/brya/build.mk +++ b/board/brya/build.mk @@ -17,6 +17,7 @@ board-y+=board.o board-y+=fans.o board-y+=i2c.o board-y+=keyboard.o +board-y+=led.o board-y+=pwm.o board-y+=sensors.o board-y+=usbc_config.o diff --git a/board/brya/led.c b/board/brya/led.c new file mode 100644 index 0000000000..09f815efc2 --- /dev/null +++ b/board/brya/led.c @@ -0,0 +1,86 @@ +/* Copyright 2021 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. + */ + +/* Waddledoo specific PWM LED settings. */ + +#include "common.h" +#include "ec_commands.h" +#include "led_pwm.h" +#include "pwm.h" +#include "util.h" + +const enum ec_led_id supported_led_ids[] = { + EC_LED_ID_LEFT_LED, + EC_LED_ID_RIGHT_LED, +}; + +const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids); + +/* + * We only have a white and an amber LED, so setting any other colour results in + * both LEDs being off. + */ +struct pwm_led led_color_map[EC_LED_COLOR_COUNT] = { + /* Amber, White */ + [EC_LED_COLOR_RED] = { 0, 0 }, + [EC_LED_COLOR_GREEN] = { 0, 0 }, + [EC_LED_COLOR_BLUE] = { 0, 0 }, + [EC_LED_COLOR_YELLOW] = { 0, 0 }, + [EC_LED_COLOR_WHITE] = { 0, 100 }, + [EC_LED_COLOR_AMBER] = { 100, 0 }, +}; + +/* Two logical LEDs with amber and white channels. */ +struct pwm_led pwm_leds[CONFIG_LED_PWM_COUNT] = { + { + .ch0 = PWM_CH_LED1, + .ch1 = PWM_CH_LED2, + .ch2 = PWM_LED_NO_CHANNEL, + .enable = &pwm_enable, + .set_duty = &pwm_set_duty, + }, + { + .ch0 = PWM_CH_LED3, + .ch1 = PWM_CH_LED4, + .ch2 = PWM_LED_NO_CHANNEL, + .enable = &pwm_enable, + .set_duty = &pwm_set_duty, + }, +}; + +void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range) +{ + memset(brightness_range, '\0', + sizeof(*brightness_range) * EC_LED_COLOR_COUNT); + brightness_range[EC_LED_COLOR_AMBER] = 100; + brightness_range[EC_LED_COLOR_WHITE] = 100; +} + +int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness) +{ + enum pwm_led_id pwm_id; + + /* Convert ec_led_id to pwm_led_id. */ + switch (led_id) { + case EC_LED_ID_LEFT_LED: + pwm_id = PWM_LED0; + break; + case EC_LED_ID_RIGHT_LED: + pwm_id = PWM_LED1; + break; + default: + return EC_ERROR_UNKNOWN; + } + + if (brightness[EC_LED_COLOR_WHITE]) + set_pwm_led_color(pwm_id, EC_LED_COLOR_WHITE); + else if (brightness[EC_LED_COLOR_AMBER]) + set_pwm_led_color(pwm_id, EC_LED_COLOR_AMBER); + else + /* Otherwise, the "color" is "off". */ + set_pwm_led_color(pwm_id, -1); + + return EC_SUCCESS; +} -- cgit v1.2.1