summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2020-01-14 16:59:58 -0800
committerCommit Bot <commit-bot@chromium.org>2020-01-21 23:55:45 +0000
commit23b0af225ef6cc09d5725343a0b7ae211ad53f86 (patch)
tree3dd40b056985c594e8ba361dd79c8d1fab093490
parentbb958e39ae8f001b2a423fcb9d48ff8f3a7f8442 (diff)
downloadchrome-ec-23b0af225ef6cc09d5725343a0b7ae211ad53f86.tar.gz
waddledoo: Add LED support
This commit adds LED support to waddledoo utilizing the common PWM LED framework. Waddledoo has a single bi-color PWM LED with amber and white channels. BUG=b:147702767 BRANCH=None TEST=Build and flash on waddledoo, verify that LEDs are working. Change-Id: Ie870a6df194a9e1ccd6b91a96c6e95a390353a8a Signed-off-by: Aseda Aboagye <aaboagye@google.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2001941 Commit-Queue: Aseda Aboagye <aaboagye@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org>
-rw-r--r--baseboard/dedede/baseboard.h2
-rw-r--r--baseboard/dedede/variant_ec_npcx796fc.c12
-rw-r--r--board/waddledoo/board.h13
-rw-r--r--board/waddledoo/build.mk2
-rw-r--r--board/waddledoo/led.c70
5 files changed, 98 insertions, 1 deletions
diff --git a/baseboard/dedede/baseboard.h b/baseboard/dedede/baseboard.h
index 3c1e150194..c8e9ec537f 100644
--- a/baseboard/dedede/baseboard.h
+++ b/baseboard/dedede/baseboard.h
@@ -107,6 +107,8 @@
#define CONFIG_KEYBOARD_PROTOCOL_8042
/* PWM */
+#define CONFIG_LED_COMMON
+#define CONFIG_LED_PWM
#define CONFIG_PWM
/* SoC */
diff --git a/baseboard/dedede/variant_ec_npcx796fc.c b/baseboard/dedede/variant_ec_npcx796fc.c
index 13e891a984..085f29c32f 100644
--- a/baseboard/dedede/variant_ec_npcx796fc.c
+++ b/baseboard/dedede/variant_ec_npcx796fc.c
@@ -71,5 +71,17 @@ const struct pwm_t pwm_channels[] = {
.flags = PWM_CONFIG_DSLEEP,
.freq = 10000,
},
+
+ [PWM_CH_LED1_AMBER] = {
+ .channel = 2,
+ .flags = PWM_CONFIG_DSLEEP | PWM_CONFIG_ACTIVE_LOW,
+ .freq = 2400,
+ },
+
+ [PWM_CH_LED2_WHITE] = {
+ .channel = 0,
+ .flags = PWM_CONFIG_DSLEEP | PWM_CONFIG_ACTIVE_LOW,
+ .freq = 2400,
+ }
};
BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT);
diff --git a/board/waddledoo/board.h b/board/waddledoo/board.h
index e5071fca2f..a8aef2dc9b 100644
--- a/board/waddledoo/board.h
+++ b/board/waddledoo/board.h
@@ -23,6 +23,17 @@
/* Keyboard */
#define CONFIG_PWM_KBLIGHT
+/* LED */
+#define CONFIG_LED_PWM_COUNT 1
+#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 */
#define CONFIG_BC12_DETECT_PI3USB9201
@@ -98,6 +109,8 @@ enum sensor_id {
enum pwm_channel {
PWM_CH_KBLIGHT,
+ PWM_CH_LED1_AMBER,
+ PWM_CH_LED2_WHITE,
PWM_CH_COUNT,
};
diff --git a/board/waddledoo/build.mk b/board/waddledoo/build.mk
index aeaa29b2a4..3cbadc55d7 100644
--- a/board/waddledoo/build.mk
+++ b/board/waddledoo/build.mk
@@ -11,4 +11,4 @@ CHIP_FAMILY:=npcx7
CHIP_VARIANT:=npcx7m6fc
BASEBOARD:=dedede
-board-y=board.o battery.o usb_pd_policy.o
+board-y=board.o battery.o led.o usb_pd_policy.o
diff --git a/board/waddledoo/led.c b/board/waddledoo/led.c
new file mode 100644
index 0000000000..ca9a05bd84
--- /dev/null
+++ b/board/waddledoo/led.c
@@ -0,0 +1,70 @@
+/* Copyright 2020 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_POWER_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 },
+};
+
+/* One logical LED with amber and white channels. */
+struct pwm_led pwm_leds[CONFIG_LED_PWM_COUNT] = {
+ {
+ .ch0 = PWM_CH_LED1_AMBER,
+ .ch1 = PWM_CH_LED2_WHITE,
+ .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. */
+ if (led_id == EC_LED_ID_POWER_LED)
+ pwm_id = PWM_LED0;
+ else
+ 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;
+}