summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFabio Baltieri <fabiobaltieri@google.com>2021-10-05 21:50:29 +0000
committerCommit Bot <commit-bot@chromium.org>2021-10-06 00:05:09 +0000
commitcd8f949da6bde55f8993640a05a15dc900692364 (patch)
tree1dc77acb69c7a995b15d4a5d1b22f3a5addc06d2
parent9b17a09cf339aecb77b462fbac2efbc122ca21da (diff)
downloadchrome-ec-cd8f949da6bde55f8993640a05a15dc900692364.tar.gz
zephyr: shim: implement a default led_set_brightness
Implement a default led_set_brightness, should be good enough to replace all existing pwm leds currently defined: atlas, nocturne: 2 leds with independent channels volteer, boldar, trondo: 2 leds with sidesel terrador, todor, waddledee, wheelie: 1 led brya, kano, liara, waddledoo: 2 leds but only amber/white grunt:1 led with only blue/amber BRANCH=none BUG=b:177452529 TEST=build and run on volteer TEST=gdb disassemble/s led_set_brightness Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com> Change-Id: I24cb10574889ccfbc7c9fddc70ceb81d1e8b2170 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3207147 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
-rw-r--r--board/volteer/led.c2
-rw-r--r--zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml29
-rw-r--r--zephyr/projects/volteer/volteer/pwm_leds.dts8
-rw-r--r--zephyr/shim/src/pwm_led.c40
4 files changed, 78 insertions, 1 deletions
diff --git a/board/volteer/led.c b/board/volteer/led.c
index 6b09d5b4a0..e4d52c889f 100644
--- a/board/volteer/led.c
+++ b/board/volteer/led.c
@@ -49,7 +49,6 @@ 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)
{
@@ -79,6 +78,7 @@ int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
return EC_SUCCESS;
}
+#endif
/* Illuminates the LED on the side of the active charging port. If not charging,
* illuminates both LEDs.
diff --git a/zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml b/zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml
index cad2e14088..b629ceac0a 100644
--- a/zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml
+++ b/zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml
@@ -74,3 +74,32 @@ properties:
description: |
A list of brigthness range value for all supported channels in order,
Red, Green, Blue, Yellow, White, Amber (0 to 255).
+
+child-binding:
+ description: |
+ LED child binding node for mapping a PWM_LED to a EC_LED_ID.
+
+ For example
+
+ pwm_led_0@0 {
+ reg = <0>;
+ ec-led-name = "EC_LED_ID_LEFT_LED";
+ };
+ pwm_led_1@1 {
+ reg = <1>;
+ ec-led-name = "EC_LED_ID_RIGHT_LED";
+ };
+
+ properties:
+ reg:
+ type: int
+ required: true
+ description: LED ID, can be either 0 or 1 for PWM_LED0 and PWM_LED1
+ enum:
+ - 0 # PWM_LED0
+ - 1 # PWM_LED1
+
+ ec-led-name:
+ type: string
+ required: true
+ description: The EC_LED_ID value to map the LED to.
diff --git a/zephyr/projects/volteer/volteer/pwm_leds.dts b/zephyr/projects/volteer/volteer/pwm_leds.dts
index 659cdecbf2..f5c33d0d97 100644
--- a/zephyr/projects/volteer/volteer/pwm_leds.dts
+++ b/zephyr/projects/volteer/volteer/pwm_leds.dts
@@ -28,5 +28,13 @@
color-map-amber = <100 20 0>;
brightness-range = <255 255 255 0 0 0>;
+
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ pwm_led_0@0 {
+ reg = <0>;
+ ec-led-name = "EC_LED_ID_POWER_LED";
+ };
};
};
diff --git a/zephyr/shim/src/pwm_led.c b/zephyr/shim/src/pwm_led.c
index 4fef611a76..994c217fcf 100644
--- a/zephyr/shim/src/pwm_led.c
+++ b/zephyr/shim/src/pwm_led.c
@@ -71,4 +71,44 @@ void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
sizeof(dt_brigthness_range));
}
+#define PWM_NAME_TO_ID(node_id) \
+ case DT_STRING_TOKEN(node_id, ec_led_name): \
+ pwm_id = DT_REG_ADDR(node_id); \
+ break;
+
+int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness)
+{
+ enum pwm_led_id pwm_id;
+
+ switch (led_id) {
+ DT_INST_FOREACH_CHILD(0, PWM_NAME_TO_ID)
+ default:
+ return EC_ERROR_UNKNOWN;
+ }
+
+ if (DT_INST_NODE_HAS_PROP(0, color_map_red) &&
+ brightness[EC_LED_COLOR_RED])
+ set_pwm_led_color(pwm_id, EC_LED_COLOR_RED);
+ else if (DT_INST_NODE_HAS_PROP(0, color_map_green) &&
+ brightness[EC_LED_COLOR_GREEN])
+ set_pwm_led_color(pwm_id, EC_LED_COLOR_GREEN);
+ else if (DT_INST_NODE_HAS_PROP(0, color_map_blue) &&
+ brightness[EC_LED_COLOR_BLUE])
+ set_pwm_led_color(pwm_id, EC_LED_COLOR_BLUE);
+ else if (DT_INST_NODE_HAS_PROP(0, color_map_yellow) &&
+ brightness[EC_LED_COLOR_YELLOW])
+ set_pwm_led_color(pwm_id, EC_LED_COLOR_YELLOW);
+ else if (DT_INST_NODE_HAS_PROP(0, color_map_white) &&
+ brightness[EC_LED_COLOR_WHITE])
+ set_pwm_led_color(pwm_id, EC_LED_COLOR_WHITE);
+ else if (DT_INST_NODE_HAS_PROP(0, color_map_amber) &&
+ 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;
+}
+
#endif /* DT_HAS_COMPAT_STATUS_OKAY */