summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Baltieri <fabiobaltieri@google.com>2021-10-06 17:35:13 +0000
committerCommit Bot <commit-bot@chromium.org>2021-10-08 16:43:18 +0000
commited0bb610e7d55a903e08e11da5936ce4abf6969c (patch)
tree2d248347f7079208457c53c6ba582c7836900dca
parent15434521097eb5184c5acbc3f37c138bd324c857 (diff)
downloadchrome-ec-ed0bb610e7d55a903e08e11da5936ce4abf6969c.tar.gz
zephyr: shim: set supported_led_ids from the device tree
This populates supported_led_ids from the device tree pwm-leds child nodes, adds a validation to make sure that the leds device phandle count matches the number of led child nodes. BRANCH=none BUG=b:177452529 TEST=checked the static structures on the built binary Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com> Change-Id: Id8e35ce08b94dafaea34e340914eecd602e2f1ac Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3207994 Commit-Queue: Keith Short <keithshort@chromium.org> Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
-rw-r--r--board/volteer/led.c2
-rw-r--r--zephyr/shim/src/pwm_led.c13
2 files changed, 13 insertions, 2 deletions
diff --git a/board/volteer/led.c b/board/volteer/led.c
index e4d52c889f..3286cd1821 100644
--- a/board/volteer/led.c
+++ b/board/volteer/led.c
@@ -13,12 +13,12 @@
#include "led_pwm.h"
#include "pwm.h"
+#ifndef CONFIG_ZEPHYR
const enum ec_led_id supported_led_ids[] = {
EC_LED_ID_POWER_LED,
};
const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
-#ifndef CONFIG_ZEPHYR
struct pwm_led_color_map led_color_map[EC_LED_COLOR_COUNT] = {
/* Red, Green, Blue */
[EC_LED_COLOR_RED] = { 100, 0, 0 },
diff --git a/zephyr/shim/src/pwm_led.c b/zephyr/shim/src/pwm_led.c
index 994c217fcf..fb40e660d5 100644
--- a/zephyr/shim/src/pwm_led.c
+++ b/zephyr/shim/src/pwm_led.c
@@ -18,6 +18,17 @@ BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(cros_ec_pwm_leds) <= 1,
BUILD_ASSERT(DT_INST_PROP_LEN(0, leds) <= 2,
"Unsupported number of LEDs defined");
+#define PWM_LED_NAME(node_id) DT_STRING_UPPER_TOKEN(node_id, ec_led_name)
+#define PWM_LED_NAME_WITH_COMMA(node_id) PWM_LED_NAME(node_id),
+
+const enum ec_led_id supported_led_ids[] = {
+ DT_INST_FOREACH_CHILD(0, PWM_LED_NAME_WITH_COMMA)
+};
+const int supported_led_ids_count = ARRAY_SIZE(supported_led_ids);
+
+BUILD_ASSERT(ARRAY_SIZE(supported_led_ids) == DT_INST_PROP_LEN(0, leds),
+ "Mismatch count of LED device phandles and LED name map entries.");
+
#define PWM_CHANNEL_BY_IDX(node_id, prop, idx, led_ch) \
PWM_CHANNEL(DT_PWMS_CTLR_BY_IDX( \
DT_PHANDLE_BY_IDX(node_id, prop, idx), led_ch))
@@ -72,7 +83,7 @@ void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
}
#define PWM_NAME_TO_ID(node_id) \
- case DT_STRING_TOKEN(node_id, ec_led_name): \
+ case PWM_LED_NAME(node_id): \
pwm_id = DT_REG_ADDR(node_id); \
break;