summaryrefslogtreecommitdiff
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
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>
-rw-r--r--board/volteer/led.c2
-rw-r--r--zephyr/Kconfig.led9
-rw-r--r--zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml19
-rw-r--r--zephyr/projects/volteer/volteer/include/pwm_map.h3
-rw-r--r--zephyr/projects/volteer/volteer/pwm.dts12
-rw-r--r--zephyr/projects/volteer/volteer/pwm_leds.dts23
-rw-r--r--zephyr/projects/volteer/volteer/zmake.yaml1
-rw-r--r--zephyr/shim/include/config_chip.h4
-rw-r--r--zephyr/shim/src/CMakeLists.txt1
-rw-r--r--zephyr/shim/src/pwm_led.c37
10 files changed, 93 insertions, 18 deletions
diff --git a/board/volteer/led.c b/board/volteer/led.c
index c0ad9be6b0..35bede89c5 100644
--- a/board/volteer/led.c
+++ b/board/volteer/led.c
@@ -31,6 +31,7 @@ struct pwm_led led_color_map[] = {
[EC_LED_COLOR_AMBER] = { 100, 20, 0 },
};
+#ifndef CONFIG_ZEPHYR
struct pwm_led pwm_leds[] = {
/* 2 RGB diffusers controlled by 1 set of 3 channels. */
[PWM_LED0] = {
@@ -41,6 +42,7 @@ struct pwm_led pwm_leds[] = {
.set_duty = &pwm_set_duty,
},
};
+#endif
void led_get_brightness_range(enum ec_led_id led_id, uint8_t *brightness_range)
{
diff --git a/zephyr/Kconfig.led b/zephyr/Kconfig.led
index 0fc928a0aa..2274e46769 100644
--- a/zephyr/Kconfig.led
+++ b/zephyr/Kconfig.led
@@ -29,15 +29,6 @@ config PLATFORM_EC_LED_PWM
if PLATFORM_EC_LED_PWM
-config PLATFORM_EC_LED_PWM_COUNT
- int "Number of PWM LEDs"
- default 1
- help
- This sets the number of PWM LEDs that are controlled by the common
- PWM LED policy. The maximum number of PWM LEDs is currently 2.
-
- TODO(b/177452529): Set this parameter from the device tree.
-
config PLATFORM_EC_CONSOLE_CMD_LEDTEST
bool "Console command: ledtest"
default y
diff --git a/zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml b/zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml
new file mode 100644
index 0000000000..cc27013ca9
--- /dev/null
+++ b/zephyr/dts/bindings/led/cros-ec,pwm-leds.yaml
@@ -0,0 +1,19 @@
+# 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.
+
+description: PWM LED configuration
+
+compatible: "cros-ec,pwm-leds"
+
+include: base.yaml
+
+properties:
+ leds:
+ type: phandles
+ description: |
+ List of pwm-leds nodes. These are expected to have a pwms property
+ pointing to the relevant PWMs, in red, green, blue and optionally sidesel
+ order.
+
+ # TODO(b/177452529): add led_color_map support
diff --git a/zephyr/projects/volteer/volteer/include/pwm_map.h b/zephyr/projects/volteer/volteer/include/pwm_map.h
index 2616bad589..67ab70936f 100644
--- a/zephyr/projects/volteer/volteer/include/pwm_map.h
+++ b/zephyr/projects/volteer/volteer/include/pwm_map.h
@@ -16,9 +16,6 @@
* TODO(b/177452529): eliminate the dependency on enum pwm_channel
* and configure this information directly from the device tree.
*/
-#define PWM_CH_LED1_BLUE NAMED_PWM(led1_blue)
-#define PWM_CH_LED2_GREEN NAMED_PWM(led2_green)
-#define PWM_CH_LED3_RED NAMED_PWM(led3_red)
#define PWM_CH_LED4_SIDESEL NAMED_PWM(led3_sidesel)
#define PWM_CH_KBLIGHT NAMED_PWM(kblight)
diff --git a/zephyr/projects/volteer/volteer/pwm.dts b/zephyr/projects/volteer/volteer/pwm.dts
index f8a24840cd..f8a0fef7df 100644
--- a/zephyr/projects/volteer/volteer/pwm.dts
+++ b/zephyr/projects/volteer/volteer/pwm.dts
@@ -7,22 +7,26 @@
named-pwms {
compatible = "named-pwms";
- led1_blue {
+ led1_blue: led1_blue {
+ #pwm-cells = <0>;
pwms = <&pwm2 0 PWM_POLARITY_INVERTED>;
label = "LED1_BLUE";
frequency = <4800>;
};
- led2_green {
+ led2_green: led2_green {
+ #pwm-cells = <0>;
pwms = <&pwm0 0 PWM_POLARITY_INVERTED>;
label = "LED2_GREEN";
frequency = <4800>;
};
- led3_red {
+ led3_red: led3_red {
+ #pwm-cells = <0>;
pwms = <&pwm1 0 PWM_POLARITY_INVERTED>;
label = "LED3_RED";
frequency = <4800>;
};
- led3_sidesel {
+ led3_sidesel: led3_sidesel {
+ #pwm-cells = <0>;
pwms = <&pwm7 0 PWM_POLARITY_INVERTED>;
label = "LED4_SIDESEL";
frequency = <2400>;
diff --git a/zephyr/projects/volteer/volteer/pwm_leds.dts b/zephyr/projects/volteer/volteer/pwm_leds.dts
new file mode 100644
index 0000000000..c89c3f2ef8
--- /dev/null
+++ b/zephyr/projects/volteer/volteer/pwm_leds.dts
@@ -0,0 +1,23 @@
+/* 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.
+ */
+
+/ {
+ pwmleds {
+ compatible = "pwm-leds";
+ pwm_led0: pwm_led_0 {
+ pwms = <&led3_red
+ &led2_green
+ &led1_blue
+ &led3_sidesel
+ >;
+ };
+ };
+
+ cros-pwmleds {
+ compatible = "cros-ec,pwm-leds";
+
+ leds = <&pwm_led0>;
+ };
+};
diff --git a/zephyr/projects/volteer/volteer/zmake.yaml b/zephyr/projects/volteer/volteer/zmake.yaml
index 3f291ce671..a89c0287af 100644
--- a/zephyr/projects/volteer/volteer/zmake.yaml
+++ b/zephyr/projects/volteer/volteer/zmake.yaml
@@ -11,6 +11,7 @@ dts-overlays:
- keyboard.dts
- motionsense.dts
- pwm.dts
+ - pwm_leds.dts
supported-toolchains:
- coreboot-sdk
- zephyr
diff --git a/zephyr/shim/include/config_chip.h b/zephyr/shim/include/config_chip.h
index eff014a781..0ab812a5b8 100644
--- a/zephyr/shim/include/config_chip.h
+++ b/zephyr/shim/include/config_chip.h
@@ -549,8 +549,8 @@
#endif
#undef CONFIG_LED_PWM_COUNT
-#ifdef CONFIG_PLATFORM_EC_LED_PWM_COUNT
-#define CONFIG_LED_PWM_COUNT CONFIG_PLATFORM_EC_LED_PWM_COUNT
+#if DT_HAS_COMPAT_STATUS_OKAY(cros_ec_pwm_leds)
+#define CONFIG_LED_PWM_COUNT DT_PROP_LEN(DT_INST(0, cros_ec_pwm_leds), leds)
#endif
#undef CONFIG_CMD_LEDTEST
diff --git a/zephyr/shim/src/CMakeLists.txt b/zephyr/shim/src/CMakeLists.txt
index 4b21fa3cfb..e30671c6d6 100644
--- a/zephyr/shim/src/CMakeLists.txt
+++ b/zephyr/shim/src/CMakeLists.txt
@@ -34,6 +34,7 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_MOTIONSENSE
motionsense_sensors.c)
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_PANIC panic.c)
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_PWM pwm.c)
+zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_LED_COMMON pwm_led.c)
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_RTC rtc.c)
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_SWITCHCAP_GPIO
switchcap_gpio.c)
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 */