summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorBen Chen <ben.chen2@quanta.corp-partner.google.com>2018-09-18 16:39:19 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-09-27 19:44:34 -0700
commit95f05008c2b9babcdae8d9552a7e1490b07eb62d (patch)
tree478ec244b50c94fdf54f41ec91e07d8eaf023e7d /include
parent72cd97f4b84e0076099b4a15698fc28e807e00f8 (diff)
downloadchrome-ec-95f05008c2b9babcdae8d9552a7e1490b07eb62d.tar.gz
led: Board-defined tables for LED states
Add common code to support GPIO-controlled LEDs for common battery/power states through a board-defined lookup table. BUG=b:113611642 BRANCH=none TEST=Correct charge states shown on Aleena LED Change-Id: Id3ab88965e67d170bdc875112475565ab2dca542 Signed-off-by: Ben Chen <ben.chen2@quanta.corp-partner.google.com> Reviewed-on: https://chromium-review.googlesource.com/1233093 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: Ryan Zhang <ryan.zhang@quanta.corp-partner.google.com> Reviewed-by: Edward Hill <ecgh@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'include')
-rw-r--r--include/config.h18
-rw-r--r--include/led_onoff_states.h93
2 files changed, 111 insertions, 0 deletions
diff --git a/include/config.h b/include/config.h
index 7ac08ad6b1..44af10b3a3 100644
--- a/include/config.h
+++ b/include/config.h
@@ -2202,6 +2202,24 @@
#undef CONFIG_LED_PWM_COUNT
/*
+ * Support GPIO-controlled LEDs for common battery/power
+ * states through a board-defined lookup table.
+ */
+#undef CONFIG_LED_ONOFF_STATES
+
+/*
+ * Set the battery charge percentage for optional STATE_DISCHARGE_S0_BAT_LOW
+ * provided by CONFIG_LED_ONOFF_STATES.
+ */
+#undef CONFIG_LED_ONOFF_STATES_BAT_LOW
+
+/*
+ * Adds a power LED under the control of the board-defined lookup table.
+ * Must be used with the CONFIG_LED_ONOFF_STATES option.
+ */
+#undef CONFIG_LED_POWER_LED
+
+/*
* LEDs for LED_POLICY STD may be inverted. In this case they are active low
* and the GPIO names will be GPIO_LED..._L.
*/
diff --git a/include/led_onoff_states.h b/include/led_onoff_states.h
new file mode 100644
index 0000000000..2cbb1c1121
--- /dev/null
+++ b/include/led_onoff_states.h
@@ -0,0 +1,93 @@
+/* Copyright 2018 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.
+ *
+ * Common functions for stateful LEDs (charger and power)
+ */
+
+#ifndef __CROS_EC_ONOFFSTATES_LED_H
+#define __CROS_EC_ONOFFSTATES_LED_H
+
+#include "ec_commands.h"
+
+#define LED_INDEFINITE UINT8_MAX
+#define LED_ONE_SEC (1000 / HOOK_TICK_INTERVAL_MS)
+#define LED_OFF EC_LED_COLOR_COUNT
+
+/*
+ * All LED states should have one phase defined,
+ * and an additional phase can be defined for blinking
+ */
+enum led_phase {
+ LED_PHASE_0,
+ LED_PHASE_1,
+ LED_NUM_PHASES
+};
+
+/*
+ * STATE_CHARGING_LVL_1 is when 0 <= charge_percentage < led_charge_level_1
+ * STATE_CHARGING_LVL_2 is when led_charge_level_1 <=
+ * charge_percentage < led_charge_level_2.
+ * STATE_CHARGING_FULL_CHARGE is when
+ * led_charge_level_2 <= charge_percentage < 100.
+ */
+enum led_states {
+ STATE_CHARGING_LVL_1,
+ STATE_CHARGING_LVL_2,
+ STATE_CHARGING_FULL_CHARGE,
+ STATE_DISCHARGE_S0,
+ STATE_DISCHARGE_S0_BAT_LOW,
+ STATE_DISCHARGE_S3,
+ STATE_DISCHARGE_S5,
+ STATE_BATTERY_ERROR,
+ STATE_FACTORY_TEST,
+ LED_NUM_STATES
+};
+
+struct led_descriptor {
+ enum ec_led_colors color;
+ uint8_t time;
+};
+
+
+/* Charging LED state table - defined in board's led.c */
+extern const struct led_descriptor
+ led_bat_state_table[LED_NUM_STATES][LED_NUM_PHASES];
+
+/* Charging LED state level 1 - defined in board's led.c */
+extern const int led_charge_lvl_1;
+
+/* Charging LED state level 2 - defined in board's led.c */
+extern const int led_charge_lvl_2;
+
+#ifdef CONFIG_LED_POWER_LED
+enum pwr_led_states {
+ PWR_LED_STATE_ON,
+ PWR_LED_STATE_SUSPEND_AC,
+ PWR_LED_STATE_SUSPEND_NO_AC,
+ PWR_LED_STATE_OFF,
+ PWR_LED_NUM_STATES
+};
+
+/* Power LED state table - defined in board's led.c */
+extern const struct led_descriptor
+ led_pwr_state_table[PWR_LED_NUM_STATES][LED_NUM_PHASES];
+
+#endif
+
+/**
+ * Set battery LED color - defined in board's led.c
+ *
+ * @param color Color to set on battery LED
+ *
+ */
+void led_set_color_battery(enum ec_led_colors color);
+
+#ifdef CONFIG_LED_POWER_LED
+/**
+ * Set power LED color - defined in board's led.c
+ */
+void led_set_color_power(enum ec_led_colors color);
+#endif
+
+#endif /* __CROS_EC_ONOFFSTATES_LED_H */