summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTeddy Shih <teddyshih@ami.corp-partner.google.com>2021-12-29 18:02:18 +0800
committerCommit Bot <commit-bot@chromium.org>2021-12-30 09:28:17 +0000
commitbb3654f2b2a32a4376c6fcd1e81f6127472f1e82 (patch)
tree67dc7eed85498d5d1735d76e0d865bc96a28add4
parent65b5bd9d3b23421332a66ed5e4fd3734395f101e (diff)
downloadchrome-ec-bb3654f2b2a32a4376c6fcd1e81f6127472f1e82.tar.gz
beadrix: Implement charging LEDs
LED behavior: Charging | Red on (S0/S3/S5) Full Charged | Blue on (S0/S3/S5) Discharging S3 | Red on 1 sec, off 3 sec Discharging S5 | off Error | Red on 1 sec, off 1 sec Discharging S0 | Blue on Factory mode | Blue on 2 sec, Red on 2 sec BUG=b:204882915 BRANCH=None TEST=make BOARD=beadrix check led behavior in every state on beadrix Signed-off-by: Teddy Shih <teddyshih@ami.corp-partner.google.com> Change-Id: Ibd828447c1c031bef419d619d2b8cfb1a8fe7e9e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3360329 Reviewed-by: Henry Sun <henrysun@google.com> Commit-Queue: Henry Sun <henrysun@google.com>
-rw-r--r--board/beadrix/board.c19
-rw-r--r--board/beadrix/board.h7
-rw-r--r--board/beadrix/gpio.inc6
-rw-r--r--board/beadrix/led.c182
4 files changed, 132 insertions, 82 deletions
diff --git a/board/beadrix/board.c b/board/beadrix/board.c
index df7f050464..4057db2c8f 100644
--- a/board/beadrix/board.c
+++ b/board/beadrix/board.c
@@ -435,26 +435,7 @@ const struct pwm_t pwm_channels[] = {
.channel = 0,
.flags = PWM_CONFIG_DSLEEP,
.freq_hz = 10000,
- },
-
- [PWM_CH_LED_RED] = {
- .channel = 1,
- .flags = PWM_CONFIG_DSLEEP | PWM_CONFIG_ACTIVE_LOW,
- .freq_hz = 2400,
- },
-
- [PWM_CH_LED_GREEN] = {
- .channel = 2,
- .flags = PWM_CONFIG_DSLEEP | PWM_CONFIG_ACTIVE_LOW,
- .freq_hz = 2400,
- },
-
- [PWM_CH_LED_BLUE] = {
- .channel = 3,
- .flags = PWM_CONFIG_DSLEEP | PWM_CONFIG_ACTIVE_LOW,
- .freq_hz = 2400,
}
-
};
BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT);
diff --git a/board/beadrix/board.h b/board/beadrix/board.h
index 80b0222c98..e9787c9373 100644
--- a/board/beadrix/board.h
+++ b/board/beadrix/board.h
@@ -39,10 +39,6 @@
*/
#define GPIO_USB_C1_INT_ODL GPIO_USB_C1_INT_V1_ODL
-/* LED */
-#define CONFIG_LED_PWM
-#define CONFIG_LED_PWM_COUNT 1
-
/* PWM */
#define CONFIG_PWM
@@ -98,9 +94,6 @@ enum chg_id {
enum pwm_channel {
PWM_CH_KBLIGHT,
- PWM_CH_LED_RED,
- PWM_CH_LED_GREEN,
- PWM_CH_LED_BLUE,
PWM_CH_COUNT,
};
diff --git a/board/beadrix/gpio.inc b/board/beadrix/gpio.inc
index 4a5a903fd9..7b14151e12 100644
--- a/board/beadrix/gpio.inc
+++ b/board/beadrix/gpio.inc
@@ -106,6 +106,10 @@ GPIO(PEN_DET_ODL, PIN(J, 1), GPIO_INPUT | GPIO_PULL_UP)
GPIO(EN_KB_BL, PIN(J, 3), GPIO_OUT_LOW) /* Currently unused */
GPIO(ECH1_PACKET_MODE, PIN(H, 1), GPIO_OUT_LOW)
+/* LEDs */
+GPIO(EC_LED_R_ODL, PIN(A, 1), GPIO_OUT_LOW)
+GPIO(EC_LED_B_ODL, PIN(A, 3), GPIO_OUT_LOW)
+
/* NC pins, enable internal pull-down to avoid floating state. */
GPIO(GPIOC0_NC, PIN(C, 0), GPIO_INPUT | GPIO_PULL_DOWN)
GPIO(GPIOC3_NC, PIN(C, 3), GPIO_INPUT | GPIO_PULL_DOWN)
@@ -135,4 +139,4 @@ ALTERNATE(PIN_MASK(L, BIT(0)), 0, MODULE_ADC, 0) /* ADC13: EC_SUB_ANALOG */
ALTERNATE(PIN_MASK(I, BIT(0) | BIT(2) | BIT(3)), 0, MODULE_ADC, 0) /* ADC0: EC_VSNS_PP3300_A, ADC2: TEMP_SENSOR_1, ADC3: TEMP_SENSOR_2 */
/* PWM */
-ALTERNATE(PIN_MASK(A, BIT(0) | BIT(1) | BIT(2) | BIT(3)), 0, MODULE_PWM, 0) /* KB_BL_PWM, LED_[R,G,B]_ODL */
+ALTERNATE(PIN_MASK(A, BIT(0)), 0, MODULE_PWM, 0) /* KB_BL_PWM */
diff --git a/board/beadrix/led.c b/board/beadrix/led.c
index 6fcff58280..ab011d49d4 100644
--- a/board/beadrix/led.c
+++ b/board/beadrix/led.c
@@ -3,80 +3,152 @@
* found in the LICENSE file.
*/
-/* Waddledee specific PWM LED settings. */
+/* Beadrix specific LED settings. */
+#include "battery.h"
+#include "charge_manager.h"
+#include "charge_state.h"
+#include "chipset.h"
#include "common.h"
#include "ec_commands.h"
-#include "led_pwm.h"
-#include "pwm.h"
+#include "gpio.h"
+#include "hooks.h"
+#include "host_command.h"
+#include "led_common.h"
+#include "system.h"
#include "util.h"
+#define LED_ONE_SEC (1000 / HOOK_TICK_INTERVAL_MS)
+#define BAT_LED_ON 0
+#define BAT_LED_OFF 1
+
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);
-/*
- * Board has one physical LED with red, green, and blue
- */
-struct pwm_led_color_map led_color_map[EC_LED_COLOR_COUNT] = {
- /* Red, Green, Blue */
- [EC_LED_COLOR_RED] = { 100, 0, 0 },
- [EC_LED_COLOR_GREEN] = { 0, 100, 0 },
- [EC_LED_COLOR_BLUE] = { 0, 0, 100 },
- [EC_LED_COLOR_YELLOW] = { 50, 50, 0 },
- [EC_LED_COLOR_WHITE] = { 50, 50, 50 },
- [EC_LED_COLOR_AMBER] = { 70, 30, 0 },
+enum led_color {
+ LED_OFF = 0,
+ LED_RED,
+ LED_BLUE,
+ LED_COLOR_COUNT /* Number of colors, not a color itself */
};
-/* One logical LED with red, green, and blue channels. */
-struct pwm_led pwm_leds[CONFIG_LED_PWM_COUNT] = {
- {
- .ch0 = PWM_CH_LED_RED,
- .ch1 = PWM_CH_LED_GREEN,
- .ch2 = PWM_CH_LED_BLUE,
- .enable = &pwm_enable,
- .set_duty = &pwm_set_duty,
- },
-};
+static void led_set_color(enum led_color color)
+{
+ gpio_set_level(GPIO_EC_LED_R_ODL,
+ (color == LED_RED) ? BAT_LED_ON : BAT_LED_OFF);
+ gpio_set_level(GPIO_EC_LED_B_ODL,
+ (color == LED_BLUE) ? BAT_LED_ON : BAT_LED_OFF);
+}
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_RED] = 100;
- brightness_range[EC_LED_COLOR_GREEN] = 100;
- brightness_range[EC_LED_COLOR_BLUE] = 100;
- brightness_range[EC_LED_COLOR_YELLOW] = 100;
- brightness_range[EC_LED_COLOR_WHITE] = 100;
- brightness_range[EC_LED_COLOR_AMBER] = 100;
+ brightness_range[EC_LED_COLOR_RED] = 1;
+ brightness_range[EC_LED_COLOR_BLUE] = 1;
}
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. */
- if (led_id == EC_LED_ID_POWER_LED)
- pwm_id = PWM_LED0;
+ if (brightness[EC_LED_COLOR_BLUE] != 0)
+ led_set_color(LED_BLUE);
+ else if (brightness[EC_LED_COLOR_RED] != 0)
+ led_set_color(LED_RED);
else
- return EC_ERROR_UNKNOWN;
-
- if (brightness[EC_LED_COLOR_RED])
- set_pwm_led_color(pwm_id, EC_LED_COLOR_RED);
- else if (brightness[EC_LED_COLOR_GREEN])
- set_pwm_led_color(pwm_id, EC_LED_COLOR_GREEN);
- else if (brightness[EC_LED_COLOR_BLUE])
- set_pwm_led_color(pwm_id, EC_LED_COLOR_BLUE);
- else if (brightness[EC_LED_COLOR_YELLOW])
- set_pwm_led_color(pwm_id, EC_LED_COLOR_YELLOW);
- else 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);
+ led_set_color(LED_OFF);
return EC_SUCCESS;
}
+
+static void board_led_set_battery(void)
+{
+ static int battery_ticks;
+ enum led_color color = LED_OFF;
+ int period = 0;
+ uint32_t chflags = charge_get_flags();
+
+ battery_ticks++;
+
+ switch (charge_get_state()) {
+ case PWR_STATE_CHARGE:
+ /* Always indicate amber on when charging. */
+ color = LED_RED;
+ break;
+ case PWR_STATE_DISCHARGE:
+ if (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND)) {
+ /* Discharging in S3: Red 1 sec, off 3 sec */
+ period = (1 + 3) * LED_ONE_SEC;
+ battery_ticks = battery_ticks % period;
+ if (battery_ticks < 1 * LED_ONE_SEC)
+ color = LED_RED;
+ else
+ color = LED_OFF;
+ } else if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) {
+ /* Discharging in S5: off */
+ color = LED_OFF;
+ } else if (chipset_in_state(CHIPSET_STATE_ON)) {
+ /* Discharging in S0: Blue on */
+ color = LED_BLUE;
+ }
+ break;
+ case PWR_STATE_ERROR:
+ /* Battery error: Red 1 sec, off 1 sec */
+ period = (1 + 1) * LED_ONE_SEC;
+ battery_ticks = battery_ticks % period;
+ if (battery_ticks < 1 * LED_ONE_SEC)
+ color = LED_RED;
+ else
+ color = LED_OFF;
+ break;
+ case PWR_STATE_CHARGE_NEAR_FULL:
+ /* Full Charged: Blue on */
+ color = LED_BLUE;
+ break;
+ case PWR_STATE_IDLE: /* External power connected in IDLE */
+ if (chflags & CHARGE_FLAG_FORCE_IDLE) {
+ /* Factory mode: Blue 2 sec, Red 2 sec */
+ period = (2 + 2) * LED_ONE_SEC;
+ battery_ticks = battery_ticks % period;
+ if (battery_ticks < 2 * LED_ONE_SEC)
+ color = LED_BLUE;
+ else
+ color = LED_RED;
+ } else
+ color = LED_BLUE;
+ break;
+ default:
+ /* Other states don't alter LED behavior */
+ break;
+ }
+
+ led_set_color(color);
+}
+
+/* Called by hook task every TICK */
+static void led_tick(void)
+{
+ if (led_auto_control_is_enabled(EC_LED_ID_BATTERY_LED))
+ board_led_set_battery();
+}
+DECLARE_HOOK(HOOK_TICK, led_tick, HOOK_PRIO_DEFAULT);
+
+void led_control(enum ec_led_id led_id, enum ec_led_state state)
+{
+ enum led_color color;
+
+ if ((led_id != EC_LED_ID_RECOVERY_HW_REINIT_LED) &&
+ (led_id != EC_LED_ID_SYSRQ_DEBUG_LED))
+ return;
+
+ if (state == LED_STATE_RESET) {
+ led_auto_control(EC_LED_ID_BATTERY_LED, 1);
+ board_led_set_battery();
+ return;
+ }
+
+ color = state ? LED_BLUE : LED_OFF;
+
+ led_auto_control(EC_LED_ID_BATTERY_LED, 0);
+
+ led_set_color(color);
+}