diff options
author | Fabio Baltieri <fabiobaltieri@google.com> | 2021-10-06 18:02:00 +0000 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-10-08 16:43:19 +0000 |
commit | 7c4b49722df9edc6e7eb6008d20bcbdddf0507d7 (patch) | |
tree | 9b65ef60a5a977b7e46b22b59b27c6603d927089 | |
parent | ed0bb610e7d55a903e08e11da5936ce4abf6969c (diff) | |
download | chrome-ec-7c4b49722df9edc6e7eb6008d20bcbdddf0507d7.tar.gz |
zephyr: shim: handle sidesel in the shim file
This adds handling for the sidesel channel from the shim driver, if the
sidesel node is specified.
With this, all the pwm-led combinations should be manageable from the
shim driver, so this also removes the conditionals from volteer driver
and drops it from the Zephyr build entirely.
BRANCH=none
BUG=b:177452529
TEST=build and run on volteer
TEST=checked the binary output if node not defined
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Change-Id: Id215d26a8b14330b9604c7385d6ce436ef1a60cd
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3207995
Commit-Queue: Keith Short <keithshort@chromium.org>
Reviewed-by: Keith Short <keithshort@chromium.org>
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
-rw-r--r-- | board/volteer/led.c | 2 | ||||
-rw-r--r-- | zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml | 7 | ||||
-rw-r--r-- | zephyr/projects/volteer/volteer/CMakeLists.txt | 2 | ||||
-rw-r--r-- | zephyr/projects/volteer/volteer/pwm_leds.dts | 2 | ||||
-rw-r--r-- | zephyr/shim/src/pwm_led.c | 44 |
5 files changed, 51 insertions, 6 deletions
diff --git a/board/volteer/led.c b/board/volteer/led.c index 3286cd1821..52a6b9d890 100644 --- a/board/volteer/led.c +++ b/board/volteer/led.c @@ -13,7 +13,6 @@ #include "led_pwm.h" #include "pwm.h" -#ifndef CONFIG_ZEPHYR const enum ec_led_id supported_led_ids[] = { EC_LED_ID_POWER_LED, }; @@ -78,7 +77,6 @@ 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 b629ceac0a..17e82bf648 100644 --- a/zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml +++ b/zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml @@ -24,7 +24,6 @@ properties: pwms = <&led3_red &led2_green &led1_blue - &led3_sidesel >; }; }; @@ -33,6 +32,12 @@ properties: leds = <&pwm_led0>; }; + sidesel: + type: phandle + required: false + description: | + PWM node phandle for the SIDESEL line, if present. + color-map-red: type: array required: false diff --git a/zephyr/projects/volteer/volteer/CMakeLists.txt b/zephyr/projects/volteer/volteer/CMakeLists.txt index 8c01874b1b..3a0ec26b4c 100644 --- a/zephyr/projects/volteer/volteer/CMakeLists.txt +++ b/zephyr/projects/volteer/volteer/CMakeLists.txt @@ -39,7 +39,5 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_BATTERY "${PLATFORM_EC_BOARD}/battery.c") zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_CBI_EEPROM "${PLATFORM_EC_BOARD}/cbi.c") -zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_LED_COMMON - "${PLATFORM_EC_BOARD}/led.c") zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_USBC "${PLATFORM_EC_BOARD}/usbc_config.c") diff --git a/zephyr/projects/volteer/volteer/pwm_leds.dts b/zephyr/projects/volteer/volteer/pwm_leds.dts index f5c33d0d97..099e8acc06 100644 --- a/zephyr/projects/volteer/volteer/pwm_leds.dts +++ b/zephyr/projects/volteer/volteer/pwm_leds.dts @@ -10,7 +10,6 @@ pwms = <&led3_red &led2_green &led1_blue - &led3_sidesel >; }; }; @@ -19,6 +18,7 @@ compatible = "cros-ec,pwm-leds"; leds = <&pwm_led0>; + sidesel = <&led3_sidesel>; color-map-red = <100 0 0>; color-map-green = < 0 100 0>; diff --git a/zephyr/shim/src/pwm_led.c b/zephyr/shim/src/pwm_led.c index fb40e660d5..915e0b1d38 100644 --- a/zephyr/shim/src/pwm_led.c +++ b/zephyr/shim/src/pwm_led.c @@ -10,6 +10,11 @@ #if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT) +#include "charge_manager.h" +#include "common.h" +#include "ec_commands.h" +#include "hooks.h" +#include "led_common.h" #include "led_pwm.h" #include "pwm.h" @@ -122,4 +127,43 @@ int led_set_brightness(enum ec_led_id led_id, const uint8_t *brightness) return EC_SUCCESS; } +#if DT_INST_NODE_HAS_PROP(0, sidesel) + +#define PWM_LED_SIDESEL PWM_CHANNEL(DT_INST_PROP(0, sidesel)) + +/* Illuminates the LED on the side of the active charging port. If not charging, + * illuminates both LEDs. + */ +static void led_set_charge_port_tick(void) +{ + int port; + int side_select_duty; + + port = charge_manager_get_active_charge_port(); + switch (port) { + case 0: + side_select_duty = 100; + break; + case 1: + side_select_duty = 0; + break; + default: + side_select_duty = 50; + } + + if (led_auto_control_is_enabled(EC_LED_ID_POWER_LED)) + pwm_set_duty(PWM_LED_SIDESEL, side_select_duty); +} +DECLARE_HOOK(HOOK_TICK, led_set_charge_port_tick, HOOK_PRIO_DEFAULT); + +static void board_led_init(void) +{ + /* Illuminate motherboard and daughter board LEDs equally to start. */ + pwm_enable(PWM_LED_SIDESEL, 1); + pwm_set_duty(PWM_LED_SIDESEL, 50); +} +DECLARE_HOOK(HOOK_INIT, board_led_init, HOOK_PRIO_DEFAULT); + +#endif /* DT_INST_NODE_HAS_PROP(0, sidesel) */ + #endif /* DT_HAS_COMPAT_STATUS_OKAY */ |