summaryrefslogtreecommitdiff
path: root/zephyr/shim/src
diff options
context:
space:
mode:
authorFabio Baltieri <fabiobaltieri@google.com>2021-10-06 18:02:00 +0000
committerCommit Bot <commit-bot@chromium.org>2021-10-08 16:43:19 +0000
commit7c4b49722df9edc6e7eb6008d20bcbdddf0507d7 (patch)
tree9b65ef60a5a977b7e46b22b59b27c6603d927089 /zephyr/shim/src
parented0bb610e7d55a903e08e11da5936ce4abf6969c (diff)
downloadchrome-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>
Diffstat (limited to 'zephyr/shim/src')
-rw-r--r--zephyr/shim/src/pwm_led.c44
1 files changed, 44 insertions, 0 deletions
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 */