diff options
-rw-r--r-- | board/volteer/led.c | 2 | ||||
-rw-r--r-- | zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml | 29 | ||||
-rw-r--r-- | zephyr/projects/volteer/volteer/pwm_leds.dts | 8 | ||||
-rw-r--r-- | zephyr/shim/src/pwm_led.c | 40 |
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 */ |