From 3386e8b54f90aed82d5f21cd52cc1ec2ca10c7c2 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Mon, 20 Sep 2021 15:53:01 +0000 Subject: zephyr: shim: define led_color_map from the devicetree This adds a set of properties for color mapping in the device tree for the pwm-leds device, and maps them to the internal "struct pwm_led_color_map". BRANCH=none BUG=b:177452529 TEST=compared the structure on gdb TEST=build and run on volteer Signed-off-by: Fabio Baltieri Change-Id: Ib3a704afccad40eab7115371dbf72c568f5602d9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3170400 Reviewed-by: Yuval Peress Reviewed-by: Keith Short Reviewed-by: Jack Rosenthal Commit-Queue: Keith Short --- board/volteer/led.c | 2 +- zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml | 34 ++++++++++++++++++++++++++- zephyr/projects/volteer/volteer/pwm_leds.dts | 7 ++++++ zephyr/shim/src/pwm_led.c | 9 +++++++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/board/volteer/led.c b/board/volteer/led.c index 357cdd038a..2fb9c8482c 100644 --- a/board/volteer/led.c +++ b/board/volteer/led.c @@ -18,6 +18,7 @@ const enum ec_led_id supported_led_ids[] = { }; 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 }, @@ -31,7 +32,6 @@ struct pwm_led_color_map led_color_map[EC_LED_COLOR_COUNT] = { [EC_LED_COLOR_AMBER] = { 100, 20, 0 }, }; -#ifndef CONFIG_ZEPHYR struct pwm_led pwm_leds[] = { /* 2 RGB diffusers controlled by 1 set of 3 channels. */ [PWM_LED0] = { diff --git a/zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml b/zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml index 2a16c9150c..ed0659aaac 100644 --- a/zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml +++ b/zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml @@ -33,4 +33,36 @@ properties: leds = <&pwm_led0>; }; - # TODO(b/177452529): add led_color_map support + color-map-red: + type: array + required: true + description: | + A map of PWM duty cycles per color, up to three channels. + + For example + color-map-red = <100 0 0>; + color-map-green = < 0 100 0>; + color-map-blue = < 0 0 100>; + color-map-yellow = <100 70 0>; + color-map-white = <100 70 100>; + color-map-amber = <100 20 0>; + + color-map-green: + type: array + required: true + + color-map-blue: + type: array + required: true + + color-map-yellow: + type: array + required: true + + color-map-white: + type: array + required: true + + color-map-amber: + type: array + required: true diff --git a/zephyr/projects/volteer/volteer/pwm_leds.dts b/zephyr/projects/volteer/volteer/pwm_leds.dts index c89c3f2ef8..aa2e5bafab 100644 --- a/zephyr/projects/volteer/volteer/pwm_leds.dts +++ b/zephyr/projects/volteer/volteer/pwm_leds.dts @@ -19,5 +19,12 @@ compatible = "cros-ec,pwm-leds"; leds = <&pwm_led0>; + + color-map-red = <100 0 0>; + color-map-green = < 0 100 0>; + color-map-blue = < 0 0 100>; + color-map-yellow = <100 70 0>; + color-map-white = <100 70 100>; + color-map-amber = <100 20 0>; }; }; diff --git a/zephyr/shim/src/pwm_led.c b/zephyr/shim/src/pwm_led.c index 2f3dbc6857..879f339b24 100644 --- a/zephyr/shim/src/pwm_led.c +++ b/zephyr/shim/src/pwm_led.c @@ -34,4 +34,13 @@ struct pwm_led pwm_leds[] = { DT_INST_FOREACH_PROP_ELEM(0, leds, PWM_LED_INIT) }; +struct pwm_led_color_map led_color_map[EC_LED_COLOR_COUNT] = { + [EC_LED_COLOR_RED] = DT_INST_PROP(0, color_map_red), + [EC_LED_COLOR_GREEN] = DT_INST_PROP(0, color_map_green), + [EC_LED_COLOR_BLUE] = DT_INST_PROP(0, color_map_blue), + [EC_LED_COLOR_YELLOW] = DT_INST_PROP(0, color_map_yellow), + [EC_LED_COLOR_WHITE] = DT_INST_PROP(0, color_map_white), + [EC_LED_COLOR_AMBER] = DT_INST_PROP(0, color_map_amber), +}; + #endif /* DT_HAS_COMPAT_STATUS_OKAY */ -- cgit v1.2.1