diff options
author | Fabio Baltieri <fabiobaltieri@google.com> | 2022-11-15 16:52:31 +0000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-11-18 16:53:14 +0000 |
commit | 86fb647593499b5e5cf3f8cff7b4da8df6d2b08f (patch) | |
tree | 7417842876b4b0869b5af39dc030ad704db53b3b /zephyr/shim/src | |
parent | 4f6def440f575126fae7db8f1bb9a50716f6b5bb (diff) | |
download | chrome-ec-86fb647593499b5e5cf3f8cff7b4da8df6d2b08f.tar.gz |
zephyr: switchcap: rename binding, clean up code
Various cleanups on the switchcap code:
- rename the bindings to add the vendor prefix
- split the Kconfig option for the common code (used in project specific
drivers) and the generic one (devicetree based)
- drop the choice and use the compatible to select the option
automatically instead
- cleanup the code to remove the now unnecessary guards
- use DT_INST macros instead of DT_PATH so we don't depends on the node
path anymore
BRANCH=none
BUG=none
TEST=cq dry run
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Change-Id: I77e790c0b7b0d947e4eafed64b0ace556a22c034
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4028145
Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Diffstat (limited to 'zephyr/shim/src')
-rw-r--r-- | zephyr/shim/src/CMakeLists.txt | 6 | ||||
-rw-r--r-- | zephyr/shim/src/switchcap_gpio.c | 28 | ||||
-rw-r--r-- | zephyr/shim/src/switchcap_ln9310.c | 21 |
3 files changed, 18 insertions, 37 deletions
diff --git a/zephyr/shim/src/CMakeLists.txt b/zephyr/shim/src/CMakeLists.txt index 74da11da2c..543c2b2303 100644 --- a/zephyr/shim/src/CMakeLists.txt +++ b/zephyr/shim/src/CMakeLists.txt @@ -55,9 +55,9 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_PWM_HC pwm_hc.c) zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_LED_PWM 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) -zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_SWITCHCAP_LN9310 - switchcap_ln9310.c) + switchcap_gpio.c) +zephyr_library_sources_ifdef(CONFIG_CROS_EC_SWITCHCAP_LN9310 + switchcap_ln9310.c) zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_TEMP_SENSOR temp_sensors.c thermal.c) zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_TIMER hwtimer.c) diff --git a/zephyr/shim/src/switchcap_gpio.c b/zephyr/shim/src/switchcap_gpio.c index 54d69a3672..982e5ff98c 100644 --- a/zephyr/shim/src/switchcap_gpio.c +++ b/zephyr/shim/src/switchcap_gpio.c @@ -3,6 +3,8 @@ * found in the LICENSE file. */ +#define DT_DRV_COMPAT cros_ec_switchcap_gpio + #include "common.h" #include <zephyr/devicetree.h> @@ -11,26 +13,14 @@ /* TODO(b/218600962): Consolidate switchcap code. */ -#if DT_NODE_EXISTS(DT_PATH(switchcap)) - -#if !DT_NODE_HAS_COMPAT(DT_PATH(switchcap), switchcap_gpio) -#error "Invalid /switchcap node in device tree" -#endif - -#define SC_PIN_ENABLE_PHANDLE \ - DT_PHANDLE_BY_IDX(DT_PATH(switchcap), enable_pin, 0) -#define SC_PIN_ENABLE GPIO_DT_FROM_NODE(SC_PIN_ENABLE_PHANDLE) +#define SC_PIN_ENABLE_GPIO DT_INST_PROP(0, enable_pin) +#define SC_PIN_ENABLE GPIO_DT_FROM_NODE(SC_PIN_ENABLE_GPIO) -#define SC_PIN_POWER_GOOD_PHANDLE \ - DT_PHANDLE_BY_IDX(DT_PATH(switchcap), power_good_pin, 0) -#define SC_PIN_POWER_GOOD_EXISTS DT_NODE_EXISTS(SC_PIN_POWER_GOOD_PHANDLE) -#define SC_PIN_POWER_GOOD GPIO_DT_FROM_NODE(SC_PIN_POWER_GOOD_PHANDLE) +#define SC_PIN_POWER_GOOD_GPIO DT_INST_PROP(0, power_good_pin) +#define SC_PIN_POWER_GOOD_EXISTS DT_NODE_EXISTS(SC_PIN_POWER_GOOD_GPIO) +#define SC_PIN_POWER_GOOD GPIO_DT_FROM_NODE(SC_PIN_POWER_GOOD_GPIO) -#if DT_NODE_HAS_PROP(DT_PATH(switchcap), poff_delay_ms) -static const int32_t poff_delay_ms = DT_PROP(DT_PATH(switchcap), poff_delay_ms); -#else -static const int32_t poff_delay_ms; -#endif +static const int32_t poff_delay_ms = DT_INST_PROP_OR(0, poff_delay_ms, 0); void board_set_switchcap_power(int enable) { @@ -52,5 +42,3 @@ int board_is_switchcap_power_good(void) return 1; #endif } - -#endif diff --git a/zephyr/shim/src/switchcap_ln9310.c b/zephyr/shim/src/switchcap_ln9310.c index f3b037bfd4..54087ef6f2 100644 --- a/zephyr/shim/src/switchcap_ln9310.c +++ b/zephyr/shim/src/switchcap_ln9310.c @@ -3,6 +3,8 @@ * found in the LICENSE file. */ +#define DT_DRV_COMPAT lion_ln9310 + #include "common.h" #include "ln9310.h" @@ -11,20 +13,13 @@ /* TODO(b/218600962): Consolidate switchcap code. */ -#if DT_NODE_EXISTS(DT_PATH(switchcap)) - -#if !DT_NODE_HAS_COMPAT(DT_PATH(switchcap), switchcap_ln9310) -#error "Invalid /switchcap node in device tree" -#endif +#define SC_PIN_ENABLE_GPIO DT_INST_PROP(0, enable_pin) +#define SC_PIN_ENABLE GPIO_DT_FROM_NODE(SC_PIN_ENABLE_GPIO) -#define SC_PIN_ENABLE_PHANDLE \ - DT_PHANDLE_BY_IDX(DT_PATH(switchcap), enable_pin, 0) -#define SC_PIN_ENABLE GPIO_DT_FROM_NODE(SC_PIN_ENABLE_PHANDLE) +#define SC_PORT_NODE DT_INST_PHANDLE(0, port) +#define SC_PORT DT_STRING_UPPER_TOKEN_BY_IDX(SC_PORT_NODE, enum_names, 0) -#define SC_PORT_PHANDLE DT_PHANDLE(DT_PATH(switchcap), port) -#define SC_PORT DT_STRING_UPPER_TOKEN_BY_IDX(SC_PORT_PHANDLE, enum_names, 0) - -#define SC_ADDR_FLAGS DT_STRING_UPPER_TOKEN(DT_PATH(switchcap), addr_flags) +#define SC_ADDR_FLAGS DT_INST_STRING_UPPER_TOKEN(0, addr_flags) void board_set_switchcap_power(int enable) { @@ -46,5 +41,3 @@ const struct ln9310_config_t ln9310_config = { .i2c_port = SC_PORT, .i2c_addr_flags = SC_ADDR_FLAGS, }; - -#endif |