summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2018-01-22 11:50:57 +0800
committerchrome-bot <chrome-bot@chromium.org>2018-02-05 23:05:39 -0800
commitd940d2a991b33b5b1ad9d6a2698ebfcdaa0f59db (patch)
tree017ac8b77a97807db600d9bbf76c2b2e324cde74 /include
parent5ef9b94d70418dd596fd81fda834e52787a24296 (diff)
downloadchrome-ec-d940d2a991b33b5b1ad9d6a2698ebfcdaa0f59db.tar.gz
common: Add support for PWM LEDs.
This commit adds support for a common framework for PWM controlled LEDs. If there are multiple LEDs, they will all follow the same pattern. The pattern is such that it follows the Chrome OS LED behaviour specification, essentially a similar version of led_policy_std.c but for PWM controlled LEDs. To use this framework, a board must do the following: - First, define the number of logical PWM LEDs which will be controlled by this common policy, CONFIG_LED_PWM_COUNT. - Then declare those logical LEDs and define the PWM channels that comprise those LEDs. (struct pwm_led pwm_leds[]). - Next, define what each color should look like (struct pwm_led led_color_map[]). By default, the colors follow the recommended colors in the LED behaviour spec, which assume an LED with a red and green channel. If a board differs or wishes to change the colors in general, they can redefine the colors (CONFIG_LED_PWM_*_COLOR) as they see fit. The colors must be one in enum ec_led_colors. These colors are the ones that can represent the charging state, SoC state, etc. BUG=b:69138917,chromium:752553 BRANCH=None TEST=make -j buildall TEST=Enable led_pwm for meowth, and verify that LEDs behave as expected. Change-Id: I945b86a7f8ed30df58d7da835d83577192548bea Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/888220 Commit-Ready: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Edward Hill <ecgh@chromium.org>
Diffstat (limited to 'include')
-rw-r--r--include/config.h29
-rw-r--r--include/led_pwm.h48
2 files changed, 77 insertions, 0 deletions
diff --git a/include/config.h b/include/config.h
index b47b1e9892..243b51ca33 100644
--- a/include/config.h
+++ b/include/config.h
@@ -780,6 +780,7 @@
#define CONFIG_CMD_INA
#undef CONFIG_CMD_JUMPTAGS
#define CONFIG_CMD_KEYBOARD
+#undef CONFIG_CMD_LEDTEST
#undef CONFIG_CMD_LID_ANGLE
#undef CONFIG_CMD_MCDP
#define CONFIG_CMD_MD
@@ -1868,6 +1869,29 @@
#undef CONFIG_LED_POLICY_STD
/*
+ * Support common PWM-controlled LEDs that conform to the Chrome OS LED
+ * behaviour specification.
+ */
+#undef CONFIG_LED_PWM
+
+/*
+ * Here are some recommended color settings by default, but a board can change
+ * the colors to one of "enum ec_led_colors" as they see fit.
+ */
+#define CONFIG_LED_PWM_CHARGE_COLOR EC_LED_COLOR_AMBER
+#define CONFIG_LED_PWM_NEAR_FULL_COLOR EC_LED_COLOR_GREEN
+#define CONFIG_LED_PWM_CHARGE_ERROR_COLOR EC_LED_COLOR_RED
+#define CONFIG_LED_PWM_SOC_ON_COLOR EC_LED_COLOR_GREEN
+#define CONFIG_LED_PWM_SOC_SUSPEND_COLOR EC_LED_COLOR_GREEN
+#define CONFIG_LED_PWM_LOW_BATT_COLOR EC_LED_COLOR_AMBER
+
+/*
+ * How many PWM LEDs does the system have that will be controlled by the common
+ * PWM LED policy? Currently, this may be at most 2.
+ */
+#undef CONFIG_LED_PWM_COUNT
+
+/*
* LEDs for LED_POLICY STD may be inverted. In this case they are active low
* and the GPIO names will be GPIO_LED..._L.
*/
@@ -3267,6 +3291,11 @@
#define CONFIG_BUTTON_TRIGGERED_RECOVERY
#endif /* defined(CONFIG_DEDICATED_RECOVERY_BUTTON) */
+
+#ifdef CONFIG_LED_PWM_COUNT
+#define CONFIG_LED_PWM
+#endif /* defined(CONFIG_LED_PWM_COUNT) */
+
/*****************************************************************************/
/*
* Define derived configuration options for EC-EC communication
diff --git a/include/led_pwm.h b/include/led_pwm.h
new file mode 100644
index 0000000000..8814023d42
--- /dev/null
+++ b/include/led_pwm.h
@@ -0,0 +1,48 @@
+/* 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.
+ */
+
+#ifndef __CROS_EC_LED_PWM_H
+#define __CROS_EC_LED_PWM_H
+
+#include "ec_commands.h"
+
+#define PWM_LED_NO_CHANNEL -1
+
+struct pwm_led {
+ int ch0;
+ int ch1;
+ int ch2;
+};
+
+enum pwm_led_id {
+ PWM_LED0 = 0,
+#if CONFIG_LED_PWM_COUNT >= 2
+ PWM_LED1,
+#endif /* CONFIG_LED_PWM_COUNT > 2 */
+};
+
+/*
+ * A mapping of color to LED duty cycles per channel.
+ *
+ * This should be defined by the boards to declare what each color looks like.
+ * There should be an entry for every enum ec_led_colors value. For colors that
+ * are impossible for a given board, they should define a duty cycle of 0 for
+ * all applicable channels. (e.g. A bi-color LED which has a red and green
+ * channel should define all 0s for EC_LED_COLOR_BLUE and EC_LED_COLOR_WHITE.)
+ */
+extern struct pwm_led led_color_map[EC_LED_COLOR_COUNT];
+
+/*
+ * A map of the PWM channels to logical PWM LEDs.
+ *
+ * A logical PWM LED would be considered as "per diffuser". There may be 1-3
+ * channels per diffuser and they should form a single entry in pwm_leds. If a
+ * channel is not used, simply define that channel as PWM_LED_NO_CHANNEL.
+ */
+extern struct pwm_led pwm_leds[CONFIG_LED_PWM_COUNT];
+
+void set_pwm_led_color(enum pwm_led_id id, int color);
+
+#endif /* defined(__CROS_EC_LED_PWM_H) */