diff options
author | Fabio Baltieri <fabiobaltieri@google.com> | 2021-10-06 17:35:13 +0000 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-10-08 16:43:18 +0000 |
commit | ed0bb610e7d55a903e08e11da5936ce4abf6969c (patch) | |
tree | 2d248347f7079208457c53c6ba582c7836900dca /zephyr/shim/src/pwm_led.c | |
parent | 15434521097eb5184c5acbc3f37c138bd324c857 (diff) | |
download | chrome-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>
Diffstat (limited to 'zephyr/shim/src/pwm_led.c')
-rw-r--r-- | zephyr/shim/src/pwm_led.c | 13 |
1 files changed, 12 insertions, 1 deletions
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; |