summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Baltieri <fabiobaltieri@google.com>2021-09-20 17:05:01 +0000
committerCommit Bot <commit-bot@chromium.org>2021-09-22 20:49:48 +0000
commit2c0d93a1ae43c4ed9745005f46787fcaf7285b39 (patch)
treebc26735734db186928d2d4c939dacb4a5716e7dd
parentba61af3b8c8a1f04caba91c4a264c78c1fe7d77b (diff)
downloadchrome-ec-2c0d93a1ae43c4ed9745005f46787fcaf7285b39.tar.gz
zephyr: shim: implement a generic led_get_brightness_range
Implement a generic led_get_brightness_range function using static values from the device tree. This is currently ignoring led_id, but no pwm_led based device is using it right now anyway, so this could cover all existing use cases. BRANCH=none BUG=b:177452529 TEST=called the function, verified the values in runtime Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com> Change-Id: I67dc7564eb6724e401961261ff5cc5892899ad5f Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3170401 Reviewed-by: Yuval Peress <peress@google.com> Reviewed-by: Keith Short <keithshort@chromium.org> Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org>
-rw-r--r--board/volteer/led.c2
-rw-r--r--zephyr/Kconfig.led6
-rw-r--r--zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml7
-rw-r--r--zephyr/projects/volteer/volteer/pwm_leds.dts2
-rw-r--r--zephyr/shim/src/pwm_led.c14
5 files changed, 27 insertions, 4 deletions
diff --git a/board/volteer/led.c b/board/volteer/led.c
index 2fb9c8482c..6b09d5b4a0 100644
--- a/board/volteer/led.c
+++ b/board/volteer/led.c
@@ -42,7 +42,6 @@ struct pwm_led pwm_leds[] = {
.set_duty = &pwm_set_duty,
},
};
-#endif
void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
{
@@ -50,6 +49,7 @@ void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
brightness_range[EC_LED_COLOR_GREEN] = 255;
brightness_range[EC_LED_COLOR_BLUE] = 255;
}
+#endif
int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
{
diff --git a/zephyr/Kconfig.led b/zephyr/Kconfig.led
index 2274e46769..8955675d92 100644
--- a/zephyr/Kconfig.led
+++ b/zephyr/Kconfig.led
@@ -23,9 +23,9 @@ config PLATFORM_EC_LED_PWM
Enable PWM (Pulse Width Modulation) controlled LEDs that conform to
the Chromium OS LED behavior specification.
- Your board files must implement the led_get_brightness_range() and
- led_set_brightness() which are used by the LED PWM module to set the
- board LEDs in response to power and charging events.
+ Your board files must implement led_set_brightness() function, which
+ is used by the LED PWM module to set the board LEDs in response to
+ power and charging events.
if PLATFORM_EC_LED_PWM
diff --git a/zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml b/zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml
index ed0659aaac..fd99e3202a 100644
--- a/zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml
+++ b/zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml
@@ -66,3 +66,10 @@ properties:
color-map-amber:
type: array
required: true
+
+ brightness-range:
+ type: array
+ required: true
+ description: |
+ A list of brigthness range value for all supported channels in order,
+ Red, Green, Blue, Yellow, White, Amber (0 to 255).
diff --git a/zephyr/projects/volteer/volteer/pwm_leds.dts b/zephyr/projects/volteer/volteer/pwm_leds.dts
index aa2e5bafab..659cdecbf2 100644
--- a/zephyr/projects/volteer/volteer/pwm_leds.dts
+++ b/zephyr/projects/volteer/volteer/pwm_leds.dts
@@ -26,5 +26,7 @@
color-map-yellow = <100 70 0>;
color-map-white = <100 70 100>;
color-map-amber = <100 20 0>;
+
+ brightness-range = <255 255 255 0 0 0>;
};
};
diff --git a/zephyr/shim/src/pwm_led.c b/zephyr/shim/src/pwm_led.c
index 879f339b24..48565d2e56 100644
--- a/zephyr/shim/src/pwm_led.c
+++ b/zephyr/shim/src/pwm_led.c
@@ -5,6 +5,7 @@
#define DT_DRV_COMPAT cros_ec_pwm_leds
+#include <string.h>
#include <devicetree.h>
#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT)
@@ -43,4 +44,17 @@ struct pwm_led_color_map led_color_map[EC_LED_COLOR_COUNT] = {
[EC_LED_COLOR_AMBER] = DT_INST_PROP(0, color_map_amber),
};
+BUILD_ASSERT(DT_INST_PROP_LEN(0, brightness_range) == EC_LED_COLOR_COUNT,
+ "brightness_range must have exactly EC_LED_COLOR_COUNT values");
+
+static const uint8_t dt_brigthness_range[EC_LED_COLOR_COUNT] = DT_INST_PROP(
+ 0, brightness_range);
+
+void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
+{
+ /* led_id is ignored, same ranges for all LEDs */
+ memcpy(brightness_range, dt_brigthness_range,
+ sizeof(dt_brigthness_range));
+}
+
#endif /* DT_HAS_COMPAT_STATUS_OKAY */