diff options
author | Fabio Baltieri <fabiobaltieri@google.com> | 2022-12-21 12:05:23 +0000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-12-23 12:00:38 +0000 |
commit | 3938a2ce1e6c3456a8bcfe2c91ad83bc7e490978 (patch) | |
tree | 3a3c13a9182f093edb98bb2800dabec3880fd27b | |
parent | 9d60e1406b943649cfefe57a6e3b8ae508010c71 (diff) | |
download | chrome-ec-3938a2ce1e6c3456a8bcfe2c91ad83bc7e490978.tar.gz |
zephyr: named-i2c-ports: remove DT_PATH usages
Replace a bunch of DT_PATH usages with some common macros to access the
named-i2c-ports node based on the DT compatible.
BRANCH=none
BUG=none
TEST=cq dry run
TEST=zmake compare-builds -a
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Change-Id: I2a817fda86b83811cd3d37abeca83048ea9b9eb7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4116773
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Reviewed-by: Aaron Massey <aaronmassey@google.com>
-rw-r--r-- | zephyr/shim/include/i2c/i2c.h | 13 | ||||
-rw-r--r-- | zephyr/shim/src/i2c.c | 6 | ||||
-rw-r--r-- | zephyr/test/i2c_dts/prj.conf | 3 | ||||
-rw-r--r-- | zephyr/test/i2c_dts/src/main.c | 4 |
4 files changed, 15 insertions, 11 deletions
diff --git a/zephyr/shim/include/i2c/i2c.h b/zephyr/shim/include/i2c/i2c.h index 3e95fbc9d3..31c8a0bd12 100644 --- a/zephyr/shim/include/i2c/i2c.h +++ b/zephyr/shim/include/i2c/i2c.h @@ -8,9 +8,12 @@ #include <zephyr/device.h> #include <zephyr/devicetree.h> +#include <zephyr/toolchain.h> -#ifdef CONFIG_PLATFORM_EC_I2C -#if DT_NODE_EXISTS(DT_PATH(named_i2c_ports)) +BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(named_i2c_ports) == 1, + "only one named-i2c-ports compatible node may be present"); + +#define NAMED_I2C_PORTS_NODE DT_COMPAT_GET_ANY_STATUS_OKAY(named_i2c_ports) #define NPCX_PORT_COMPAT nuvoton_npcx_i2c_port #define ITE_IT8XXX2_PORT_COMPAT ite_it8xxx2_i2c @@ -170,11 +173,7 @@ BUILD_ASSERT(I2C_PORT_COUNT != 0, "No I2C devices defined"); * I2C_PORT_BATTERY or I2C_PORT_SENSOR) to the unique port numbers created by * enum i2c_ports_chip above for every I2C port devicetree node. */ -enum i2c_ports { - DT_FOREACH_CHILD(DT_PATH(named_i2c_ports), NAMED_I2C_PORT_COMMA) -}; -#endif /* named_i2c_ports */ -#endif /* CONFIG_PLATFORM_EC_I2C */ +enum i2c_ports { DT_FOREACH_CHILD(NAMED_I2C_PORTS_NODE, NAMED_I2C_PORT_COMMA) }; /** * @brief Adaptation of platform/ec's port IDs which map a port/bus to a device. diff --git a/zephyr/shim/src/i2c.c b/zephyr/shim/src/i2c.c index 53766f1683..d893745d64 100644 --- a/zephyr/shim/src/i2c.c +++ b/zephyr/shim/src/i2c.c @@ -36,11 +36,11 @@ * Since all the ports will eventually be handled by device tree. This will * be removed at that point. */ -const struct i2c_port_t i2c_ports[] = { DT_FOREACH_CHILD( - DT_PATH(named_i2c_ports), I2C_PORT_INIT) }; +const struct i2c_port_t i2c_ports[] = { DT_FOREACH_CHILD(NAMED_I2C_PORTS_NODE, + I2C_PORT_INIT) }; const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); static const int i2c_remote_ports[I2C_PORT_COUNT] = { DT_FOREACH_CHILD( - DT_PATH(named_i2c_ports), INIT_REMOTE_PORTS) }; + NAMED_I2C_PORTS_NODE, INIT_REMOTE_PORTS) }; static const struct device *i2c_devices[I2C_PORT_COUNT] = { I2C_FOREACH_PORT( INIT_DEV_BINDING) }; diff --git a/zephyr/test/i2c_dts/prj.conf b/zephyr/test/i2c_dts/prj.conf index d79c1ff00e..e2075400e8 100644 --- a/zephyr/test/i2c_dts/prj.conf +++ b/zephyr/test/i2c_dts/prj.conf @@ -5,6 +5,9 @@ CONFIG_ZTEST=y CONFIG_ZTEST_NEW_API=y +CONFIG_PLATFORM_EC=y +CONFIG_CROS_EC=y + CONFIG_EMUL=y CONFIG_EMUL_BMI160=y CONFIG_SENSOR=y diff --git a/zephyr/test/i2c_dts/src/main.c b/zephyr/test/i2c_dts/src/main.c index 1557eaf9e9..3f24bbfd9c 100644 --- a/zephyr/test/i2c_dts/src/main.c +++ b/zephyr/test/i2c_dts/src/main.c @@ -3,6 +3,8 @@ * found in the LICENSE file. */ +#include "i2c.h" + #include <zephyr/device.h> #include <zephyr/devicetree.h> #include <zephyr/ztest.h> @@ -10,7 +12,7 @@ ZTEST(i2c_bindings, test_i2c_get_device) { const struct device *accel0 = DEVICE_DT_GET( - DT_PHANDLE(DT_PATH(named_i2c_ports, accel_0), i2c_port)); + DT_PHANDLE(DT_CHILD(NAMED_I2C_PORTS_NODE, accel_0), i2c_port)); const struct device *bmi_i2c = DEVICE_DT_GET(DT_NODELABEL(i2c0)); zassert_not_null(accel0, "accel0 was NULL"); |