summaryrefslogtreecommitdiff
path: root/zephyr/shim/src/i2c.c
diff options
context:
space:
mode:
authorYuval Peress <peress@chromium.org>2021-04-07 00:17:55 -0600
committerCommit Bot <commit-bot@chromium.org>2021-04-09 07:06:52 +0000
commitc4d1b01bc345557ea9be3793f724d7d35ddbf174 (patch)
tree67a82f814ef889de07b6ed819dbe2f0ee0beca21 /zephyr/shim/src/i2c.c
parent41aeb59c43bfb94ac7d34a4a796aa245759ee8e3 (diff)
downloadchrome-ec-c4d1b01bc345557ea9be3793f724d7d35ddbf174.tar.gz
zephyr: volteer: init i2c_ports
Populate i2c_ports[] and set i2c_ports_used correctly. Add child bindings for named i2c ports that allow configurations. A configured named i2c node MUST have a kbps property and 2 child nodes for `scl` and `sda` which will use the same enums as the named gpios. This provides a compile-time check to make sure that the overlay gpio.dts defined a named gpio using the SCL/SDA enums. This means that if the i2c port config uses a valid enum from gpio-enum-name.yaml but the overlay did not define a node using that same enum, the build will break (because the gpio_signal enum will not have that enum defined). BRANCH=none BUG=b:184269641 TEST=zmake testall TEST=run firmware_ECCbiEeprom FAFT on volteer Signed-off-by: Yuval Peress <peress@chromium.org> Change-Id: I7f46ab8f8b4079cf6ae5287869e6844fea38a100 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2810333 Commit-Queue: Simon Glass <sjg@chromium.org> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'zephyr/shim/src/i2c.c')
-rw-r--r--zephyr/shim/src/i2c.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/zephyr/shim/src/i2c.c b/zephyr/shim/src/i2c.c
index ddd73e27f1..c42e9e9e75 100644
--- a/zephyr/shim/src/i2c.c
+++ b/zephyr/shim/src/i2c.c
@@ -16,6 +16,21 @@
i2c_devices[I2C_PORT(id)] = device_get_binding( \
DT_PROP_BY_PHANDLE(id, i2c_port, label));
+#define I2C_CONFIG_GPIO(id, type) \
+ DT_ENUM_UPPER_TOKEN(DT_CHILD(DT_CHILD(id, config), type), enum_name)
+
+#define I2C_PORT_INIT(id) \
+ COND_CODE_1(DT_NODE_EXISTS(DT_CHILD(id, config)), \
+ ( \
+ { \
+ .name = DT_LABEL(id), \
+ .port = I2C_PORT(id), \
+ .kbps = DT_PROP(DT_CHILD(id, config), \
+ frequency), \
+ .scl = I2C_CONFIG_GPIO(id, scl), \
+ .sda = I2C_CONFIG_GPIO(id, sda), \
+ }, ), \
+ ())
/*
* Long term we will not need these, for now they're needed to get things to
* build since these extern symbols are usually defined in
@@ -24,7 +39,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[] = {};
+const struct i2c_port_t i2c_ports[] = {
+#if DT_NODE_EXISTS(DT_PATH(named_i2c_ports))
+ DT_FOREACH_CHILD(DT_PATH(named_i2c_ports), I2C_PORT_INIT)
+#endif
+};
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
int i2c_get_line_levels(int port)