summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@chromium.org>2021-03-23 01:24:03 -0600
committerCommit Bot <commit-bot@chromium.org>2021-04-08 07:39:45 +0000
commitf48f2ee331ead2bf641279d37ee091217e0d141c (patch)
treea98177440f53292e19b68c87d0292d19e27d29d4
parent8d70ee4c035e949d5e59655d93c43ebd81060c87 (diff)
downloadchrome-ec-f48f2ee331ead2bf641279d37ee091217e0d141c.tar.gz
zephyr: i2c mapping using an enum
Currently, every project will need to provide a custom mapping header for i2c as well as gpios. We'd like to move that overhead to the dts files, which will make the board dts a lot more reusable as well as clean up the bringup of new boards. Add to the i2c_ports enum from the dts named i2c port list. Each enum is only added if a node exists using that enum. This also allowes for verifying that the enum is only used once. BRANCH=none BUG=b:184786824 TEST=build and flashed volteer TEST=zmake testall Signed-off-by: Yuval Peress <peress@chromium.org> Change-Id: I42cc098a9badac57a3781fa9dfaf32c0ec0c5aca Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2780838
-rw-r--r--zephyr/dts/bindings/i2c/cros-ec,i2c-port-eeprom.yaml14
-rw-r--r--zephyr/dts/bindings/i2c/cros-ec-i2c-port-base.yaml34
-rw-r--r--zephyr/dts/bindings/i2c/named-i2c-ports.yaml9
-rw-r--r--zephyr/projects/kohaku/include/i2c_map.h11
-rw-r--r--zephyr/projects/trogdor/boards/arm/trogdor/trogdor.dts26
-rw-r--r--zephyr/projects/trogdor/lazor/include/i2c_map.h25
-rw-r--r--zephyr/projects/volteer/boards/arm/volteer/volteer.dts23
-rw-r--r--zephyr/projects/volteer/delbin/include/i2c_map.h25
-rw-r--r--zephyr/projects/volteer/volteer/include/i2c_map.h28
-rw-r--r--zephyr/shim/include/board.h2
-rw-r--r--zephyr/shim/include/i2c/i2c.h13
-rw-r--r--zephyr/test/i2c/overlay.dts1
-rw-r--r--zephyr/test/i2c_dts/overlay.dts1
13 files changed, 111 insertions, 101 deletions
diff --git a/zephyr/dts/bindings/i2c/cros-ec,i2c-port-eeprom.yaml b/zephyr/dts/bindings/i2c/cros-ec,i2c-port-eeprom.yaml
new file mode 100644
index 0000000000..e8e206cfb8
--- /dev/null
+++ b/zephyr/dts/bindings/i2c/cros-ec,i2c-port-eeprom.yaml
@@ -0,0 +1,14 @@
+# Copyright (c) 2021 The Chromium OS Authors
+# SPDX-License-Identifier: Apache-2.0
+
+description: I2C port properties for the EEPROM node
+
+compatible: "cros-ec,i2c-port-eeprom"
+
+include: [cros-ec-i2c-port-base.yaml]
+
+properties:
+ addr-flags:
+ type: int
+ description:
+ EEPROM flags.
diff --git a/zephyr/dts/bindings/i2c/cros-ec-i2c-port-base.yaml b/zephyr/dts/bindings/i2c/cros-ec-i2c-port-base.yaml
new file mode 100644
index 0000000000..49d9ee53c4
--- /dev/null
+++ b/zephyr/dts/bindings/i2c/cros-ec-i2c-port-base.yaml
@@ -0,0 +1,34 @@
+# Copyright (c) 2021 The Chromium OS Authors
+# SPDX-License-Identifier: Apache-2.0
+
+description: I2C port base properties
+
+properties:
+ i2c-port:
+ type: phandle
+ required: true
+ enum-name:
+ type: string
+ required: true
+ description:
+ Enum values used in the source code to refer to the i2c port
+ enum:
+ - I2C_PORT_ACCEL
+ - I2C_PORT_BATTERY
+ - I2C_PORT_CHARGER
+ - I2C_PORT_EEPROM
+ - I2C_PORT_POWER
+ - I2C_PORT_SENSOR
+ - I2C_PORT_TCPC0
+ - I2C_PORT_TCPC1
+ - I2C_PORT_USB_1_MIX
+ - I2C_PORT_USB_C0
+ - I2C_PORT_USB_C1
+ - I2C_PORT_VIRTUAL
+ - I2C_PORT_WLC
+ label:
+ required: true
+ type: string
+ description:
+ Human readable string describing the device (used as device_get_binding()
+ argument).
diff --git a/zephyr/dts/bindings/i2c/named-i2c-ports.yaml b/zephyr/dts/bindings/i2c/named-i2c-ports.yaml
index 088990eec1..4fce9c3229 100644
--- a/zephyr/dts/bindings/i2c/named-i2c-ports.yaml
+++ b/zephyr/dts/bindings/i2c/named-i2c-ports.yaml
@@ -7,11 +7,4 @@ compatible: "named-i2c-ports"
child-binding:
description: Named I2C ports child node
- properties:
- i2c-port:
- type: phandle
- required: true
- label:
- required: true
- type: string
- description: Human readable string describing the device (used as device_get_binding() argument)
+ include: [cros-ec-i2c-port-base.yaml]
diff --git a/zephyr/projects/kohaku/include/i2c_map.h b/zephyr/projects/kohaku/include/i2c_map.h
deleted file mode 100644
index bffb72de89..0000000000
--- a/zephyr/projects/kohaku/include/i2c_map.h
+++ /dev/null
@@ -1,11 +0,0 @@
-/* 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.
- */
-
-#ifndef __ZEPHYR_CHROME_I2C_MAP_H
-#define __ZEPHYR_CHROME_I2C_MAP_H
-
-/* TODO(b/177609422): add kohaku i2c mappings */
-
-#endif /* __ZEPHYR_CHROME_I2C_MAP_H */
diff --git a/zephyr/projects/trogdor/boards/arm/trogdor/trogdor.dts b/zephyr/projects/trogdor/boards/arm/trogdor/trogdor.dts
index 3afe140971..642c87e7fc 100644
--- a/zephyr/projects/trogdor/boards/arm/trogdor/trogdor.dts
+++ b/zephyr/projects/trogdor/boards/arm/trogdor/trogdor.dts
@@ -34,28 +34,54 @@
power {
i2c-port = <&i2c0_0>;
+ enum-name = "I2C_PORT_POWER";
label = "POWER";
};
+ battery {
+ i2c-port = <&i2c0_0>;
+ enum-name = "I2C_PORT_BATTERY";
+ label = "BATTERY";
+ };
+ virtual {
+ i2c-port = <&i2c0_0>;
+ enum-name = "I2C_PORT_VIRTUAL";
+ label = "VIRTUAL";
+ };
+ charger {
+ i2c-port = <&i2c0_0>;
+ enum-name = "I2C_PORT_CHARGER";
+ label = "CHARGER";
+ };
tcpc0 {
i2c-port = <&i2c1_0>;
+ enum-name = "I2C_PORT_TCPC0";
label = "TCPC0";
};
tcpc1 {
i2c-port = <&i2c2_0>;
+ enum-name = "I2C_PORT_TCPC1";
label = "TCPC1";
};
wlc {
i2c-port = <&i2c3_0>;
+ enum-name = "I2C_PORT_WLC";
label = "WLC";
};
eeprom {
i2c-port = <&i2c5_0>;
+ enum-name = "I2C_PORT_EEPROM";
label = "EEPROM";
};
sensor {
i2c-port = <&i2c7_0>;
+ enum-name = "I2C_PORT_SENSOR";
label = "SENSOR";
};
+ accel {
+ i2c-port = <&i2c7_0>;
+ enum-name = "I2C_PORT_ACCEL";
+ label = "ACCEL";
+ };
};
named-pwms {
diff --git a/zephyr/projects/trogdor/lazor/include/i2c_map.h b/zephyr/projects/trogdor/lazor/include/i2c_map.h
deleted file mode 100644
index 23f63aaaab..0000000000
--- a/zephyr/projects/trogdor/lazor/include/i2c_map.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/* 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.
- */
-
-#ifndef __ZEPHYR_I2C_MAP_H
-#define __ZEPHYR_I2C_MAP_H
-
-#include <devicetree.h>
-
-#include "i2c/i2c.h"
-
-#define I2C_PORT_BATTERY I2C_PORT_POWER
-#define I2C_PORT_VIRTUAL I2C_PORT_BATTERY
-#define I2C_PORT_CHARGER I2C_PORT_POWER
-#define I2C_PORT_ACCEL I2C_PORT_SENSOR
-
-#define I2C_PORT_POWER NAMED_I2C(power)
-#define I2C_PORT_TCPC0 NAMED_I2C(tcpc0)
-#define I2C_PORT_TCPC1 NAMED_I2C(tcpc1)
-#define I2C_PORT_WLC NAMED_I2C(wlc)
-#define I2C_PORT_EEPROM NAMED_I2C(eeprom)
-#define I2C_PORT_SENSOR NAMED_I2C(sensor)
-
-#endif /* __ZEPHYR_I2C_MAP_H */
diff --git a/zephyr/projects/volteer/boards/arm/volteer/volteer.dts b/zephyr/projects/volteer/boards/arm/volteer/volteer.dts
index 5eae87df97..ee28ed26b8 100644
--- a/zephyr/projects/volteer/boards/arm/volteer/volteer.dts
+++ b/zephyr/projects/volteer/boards/arm/volteer/volteer.dts
@@ -50,28 +50,51 @@
i2c_sensor: sensor {
i2c-port = <&i2c0_0>;
+ enum-name = "I2C_PORT_SENSOR";
label = "SENSOR";
};
+ i2c-accel {
+ i2c-port = <&i2c0_0>;
+ enum-name = "I2C_PORT_ACCEL";
+ label = "ACCEL";
+ };
usb-c0 {
i2c-port = <&i2c1_0>;
+ enum-name = "I2C_PORT_USB_C0";
label = "USB_C0";
};
usb-c1 {
i2c-port = <&i2c2_0>;
+ enum-name = "I2C_PORT_USB_C1";
label = "USB_C1";
};
usb1-mix {
i2c-port = <&i2c3_0>;
+ enum-name = "I2C_PORT_USB_1_MIX";
label = "USB_1_MIX";
};
power {
i2c-port = <&i2c5_0>;
+ enum-name = "I2C_PORT_POWER";
label = "POWER";
};
+ battery {
+ i2c-port = <&i2c5_0>;
+ enum-name = "I2C_PORT_BATTERY";
+ label = "BATTERY";
+ };
eeprom {
+ compatible = "cros-ec,i2c-port-eeprom";
i2c-port = <&i2c7_0>;
+ enum-name = "I2C_PORT_EEPROM";
+ addr-flags = <0x50>;
label = "EEPROM";
};
+ charger {
+ i2c-port = <&i2c7_0>;
+ enum-name = "I2C_PORT_CHARGER";
+ label = "CHARGER";
+ };
};
named-adc-channels {
diff --git a/zephyr/projects/volteer/delbin/include/i2c_map.h b/zephyr/projects/volteer/delbin/include/i2c_map.h
deleted file mode 100644
index 3bd7380014..0000000000
--- a/zephyr/projects/volteer/delbin/include/i2c_map.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/* 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.
- */
-
-#ifndef __ZEPHYR_I2C_MAP_H
-#define __ZEPHYR_I2C_MAP_H
-
-#include <devicetree.h>
-
-#include "i2c/i2c.h"
-
-#define I2C_PORT_ACCEL I2C_PORT_SENSOR
-#define I2C_PORT_SENSOR NAMED_I2C(sensor)
-#define I2C_PORT_USB_C0 NAMED_I2C(usb_c0)
-#define I2C_PORT_USB_C1 NAMED_I2C(usb_c1)
-#define I2C_PORT_USB_1_MIX NAMED_I2C(usb1_mix)
-#define I2C_PORT_POWER NAMED_I2C(power)
-#define I2C_PORT_EEPROM NAMED_I2C(eeprom)
-
-#define I2C_ADDR_EEPROM_FLAGS 0x50
-#define I2C_PORT_BATTERY I2C_PORT_POWER
-#define I2C_PORT_CHARGER I2C_PORT_EEPROM
-
-#endif /* __ZEPHYR_I2C_MAP_H */
diff --git a/zephyr/projects/volteer/volteer/include/i2c_map.h b/zephyr/projects/volteer/volteer/include/i2c_map.h
deleted file mode 100644
index 4a0b131a70..0000000000
--- a/zephyr/projects/volteer/volteer/include/i2c_map.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/* Copyright 2020 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.
- */
-
-#ifndef __ZEPHYR_CHROME_I2C_MAP_H
-#define __ZEPHYR_CHROME_I2C_MAP_H
-
-#include <devicetree.h>
-
-#include "config.h"
-
-/* We need registers.h to get the chip specific defines for now */
-#include "i2c/i2c.h"
-
-#define I2C_PORT_ACCEL I2C_PORT_SENSOR
-#define I2C_PORT_SENSOR NAMED_I2C(sensor)
-#define I2C_PORT_USB_C0 NAMED_I2C(usb_c0)
-#define I2C_PORT_USB_C1 NAMED_I2C(usb_c1)
-#define I2C_PORT_USB_1_MIX NAMED_I2C(usb1_mix)
-#define I2C_PORT_POWER NAMED_I2C(power)
-#define I2C_PORT_EEPROM NAMED_I2C(eeprom)
-
-#define I2C_ADDR_EEPROM_FLAGS 0x50
-#define I2C_PORT_BATTERY I2C_PORT_POWER
-#define I2C_PORT_CHARGER I2C_PORT_EEPROM
-
-#endif /* __ZEPHYR_CHROME_I2C_MAP_H */
diff --git a/zephyr/shim/include/board.h b/zephyr/shim/include/board.h
index 2d62c078ab..3c12788663 100644
--- a/zephyr/shim/include/board.h
+++ b/zephyr/shim/include/board.h
@@ -18,7 +18,7 @@
/* Include board specific i2c mapping if I2C is enabled. */
#if defined(CONFIG_I2C) && !defined(CONFIG_ZTEST)
-#include "i2c_map.h"
+#include "i2c/i2c.h"
#endif
#ifdef CONFIG_PWM
diff --git a/zephyr/shim/include/i2c/i2c.h b/zephyr/shim/include/i2c/i2c.h
index 8c8e98ace8..4130ba2037 100644
--- a/zephyr/shim/include/i2c/i2c.h
+++ b/zephyr/shim/include/i2c/i2c.h
@@ -11,11 +11,18 @@
#ifdef CONFIG_PLATFORM_EC_I2C
#if DT_NODE_EXISTS(DT_PATH(named_i2c_ports))
-#define I2C_PORT(id) DT_CAT(I2C_, id)
+
+/* EEPROM flags */
+#if DT_HAS_COMPAT_STATUS_OKAY(cros_ec_i2c_port_eeprom)
+#define I2C_ADDR_EEPROM_FLAGS \
+ DT_PROP(DT_INST(0, cros_ec_i2c_port_eeprom), addr_flags)
+#endif
+#define I2C_PORT(id) DT_ENUM_UPPER_TOKEN(id, enum_name)
#define I2C_PORT_WITH_COMMA(id) I2C_PORT(id),
+
enum i2c_ports {
-DT_FOREACH_CHILD(DT_PATH(named_i2c_ports), I2C_PORT_WITH_COMMA)
-I2C_PORT_COUNT
+ DT_FOREACH_CHILD(DT_PATH(named_i2c_ports), I2C_PORT_WITH_COMMA)
+ I2C_PORT_COUNT
};
#define NAMED_I2C(name) I2C_PORT(DT_PATH(named_i2c_ports, name))
#endif /* named_i2c_ports */
diff --git a/zephyr/test/i2c/overlay.dts b/zephyr/test/i2c/overlay.dts
index 301695b791..2c56ee3b7a 100644
--- a/zephyr/test/i2c/overlay.dts
+++ b/zephyr/test/i2c/overlay.dts
@@ -8,6 +8,7 @@
compatible = "named-i2c-ports";
accel-0 {
i2c-port = <&bmi_i2c>;
+ enum-name = "I2C_PORT_ACCEL";
label = "ACCEL_0";
};
};
diff --git a/zephyr/test/i2c_dts/overlay.dts b/zephyr/test/i2c_dts/overlay.dts
index 301695b791..2c56ee3b7a 100644
--- a/zephyr/test/i2c_dts/overlay.dts
+++ b/zephyr/test/i2c_dts/overlay.dts
@@ -8,6 +8,7 @@
compatible = "named-i2c-ports";
accel-0 {
i2c-port = <&bmi_i2c>;
+ enum-name = "I2C_PORT_ACCEL";
label = "ACCEL_0";
};
};