summaryrefslogtreecommitdiff
path: root/zephyr/shim/src/pwm_led.c
diff options
context:
space:
mode:
authorFabio Baltieri <fabiobaltieri@google.com>2021-09-10 14:39:16 +0000
committerCommit Bot <commit-bot@chromium.org>2021-09-10 22:35:05 +0000
commit2c0c44bed1d4b866cd33abc6ed29ac6241b32476 (patch)
treed0fc27a7bc01156f959a5f24e6906d153cddf912 /zephyr/shim/src/pwm_led.c
parent8b37b17df0b8946763b1da984c64c51418a6b381 (diff)
downloadchrome-ec-2c0c44bed1d4b866cd33abc6ed29ac6241b32476.tar.gz
zephyr: shim: set pwm_led data from device tree
Set up the pwm_leds data from the device tree, gets rid of most static map defines and sets CONFIG_LED_PWM_COUNT automatically. BRANCH=none BUG=b:177452529 TEST=build and run on volteer TEST=compared the built up pwm_leds structure with gdb Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com> Change-Id: Ib41faf86ae018f5a1ed8a1c96c4b6ec081e175d9 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3154256 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Reviewed-by: Yuval Peress <peress@google.com>
Diffstat (limited to 'zephyr/shim/src/pwm_led.c')
-rw-r--r--zephyr/shim/src/pwm_led.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/zephyr/shim/src/pwm_led.c b/zephyr/shim/src/pwm_led.c
new file mode 100644
index 0000000000..2f3dbc6857
--- /dev/null
+++ b/zephyr/shim/src/pwm_led.c
@@ -0,0 +1,37 @@
+/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#define DT_DRV_COMPAT cros_ec_pwm_leds
+
+#include <devicetree.h>
+
+#if DT_HAS_COMPAT_STATUS_OKAY(DT_DRV_COMPAT)
+
+#include "led_pwm.h"
+#include "pwm.h"
+
+BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(cros_ec_pwm_leds) <= 1,
+ "Multiple CrOS EC PWM LED instances defined");
+BUILD_ASSERT(DT_INST_PROP_LEN(0, leds) <= 2,
+ "Unsupported number of LEDs defined");
+
+#define PWM_CHANNEL_BY_IDX(node_id, prop, idx, led_ch) \
+ PWM_CHANNEL(DT_PWMS_CTLR_BY_IDX( \
+ DT_PHANDLE_BY_IDX(node_id, prop, idx), led_ch))
+
+#define PWM_LED_INIT(node_id, prop, idx) \
+ [PWM_LED##idx] = { \
+ .ch0 = PWM_CHANNEL_BY_IDX(node_id, prop, idx, 0), \
+ .ch1 = PWM_CHANNEL_BY_IDX(node_id, prop, idx, 1), \
+ .ch2 = PWM_CHANNEL_BY_IDX(node_id, prop, idx, 2), \
+ .enable = &pwm_enable, \
+ .set_duty = &pwm_set_duty, \
+ },
+
+struct pwm_led pwm_leds[] = {
+ DT_INST_FOREACH_PROP_ELEM(0, leds, PWM_LED_INIT)
+};
+
+#endif /* DT_HAS_COMPAT_STATUS_OKAY */