summaryrefslogtreecommitdiff
path: root/zephyr/shim/include/usbc
diff options
context:
space:
mode:
authorAdam Mills <adamjmills@google.com>2022-08-04 15:09:43 +1000
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-08-14 14:41:19 +0000
commit0a72494c194eacbf2dba51d6d09bfa4997ce11b8 (patch)
treec4d4dd3923749f39f3075774e374e9e77e0c876f /zephyr/shim/include/usbc
parent8f05c9aef54c508c5fa6adb0640029389edb4968 (diff)
downloadchrome-ec-0a72494c194eacbf2dba51d6d09bfa4997ce11b8.tar.gz
zephyr: Move ppc nodes under i2c bus
Move all ppc nodes under the i2c bus nodes instead of named-usbc-port nodes. The change should simplify the upstream process of the ppc chip drivers. BUG=b:240617931 TEST=zmake testall; zephyr/zmake/run_tests.sh BRANCH=main Signed-off-by: Adam Mills <adamjmills@google.com> Change-Id: I4fcf95cd200fc82b3fedd4b3bc166e8aa8243c79 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3810131 Reviewed-by: Andrew McRae <amcrae@google.com> Reviewed-by: Dawid Niedzwiecki <dawidn@google.com>
Diffstat (limited to 'zephyr/shim/include/usbc')
-rw-r--r--zephyr/shim/include/usbc/bc12_rt1739.h2
-rw-r--r--zephyr/shim/include/usbc/ppc.h40
-rw-r--r--zephyr/shim/include/usbc/ppc_nx20p348x.h6
-rw-r--r--zephyr/shim/include/usbc/ppc_rt1739.h18
-rw-r--r--zephyr/shim/include/usbc/ppc_sn5s330.h6
-rw-r--r--zephyr/shim/include/usbc/ppc_syv682x.h16
6 files changed, 40 insertions, 48 deletions
diff --git a/zephyr/shim/include/usbc/bc12_rt1739.h b/zephyr/shim/include/usbc/bc12_rt1739.h
index 15df73857a..13b307bd48 100644
--- a/zephyr/shim/include/usbc/bc12_rt1739.h
+++ b/zephyr/shim/include/usbc/bc12_rt1739.h
@@ -5,7 +5,7 @@
#include "driver/ppc/rt1739.h"
-#define RT1739_BC12_COMPAT richtek_rt1739_bc12
+#define RT1739_BC12_COMPAT richtek_rt1739
#define BC12_CHIP_RT1739(id) \
{ \
diff --git a/zephyr/shim/include/usbc/ppc.h b/zephyr/shim/include/usbc/ppc.h
index f6fe6e884b..4bb8f7e106 100644
--- a/zephyr/shim/include/usbc/ppc.h
+++ b/zephyr/shim/include/usbc/ppc.h
@@ -15,32 +15,24 @@
#include "usbc/utils.h"
#include "usbc_ppc.h"
-#define PPC_ID(id) DT_CAT(PPC_, id)
-#define PPC_ID_WITH_COMMA(id) PPC_ID(id),
-#define PPC_ALT_FOR(alt_id) USBC_PORT(DT_PHANDLE(alt_id, alternate_for))
-
-#define PPC_ALT_ENUM(id) \
- COND_CODE_1(DT_NODE_HAS_PROP(id, alternate_for), \
- (PPC_ID_WITH_COMMA(id)), ())
-
-enum ppc_chips_alt_id {
- DT_FOREACH_STATUS_OKAY(NX20P348X_COMPAT, PPC_ALT_ENUM)
- DT_FOREACH_STATUS_OKAY(RT1739_PPC_COMPAT, PPC_ALT_ENUM)
- DT_FOREACH_STATUS_OKAY(SN5S330_COMPAT, PPC_ALT_ENUM)
- DT_FOREACH_STATUS_OKAY(SYV682X_COMPAT,
- PPC_ALT_ENUM)
- PPC_CHIP_ALT_COUNT
-};
-
extern struct ppc_config_t ppc_chips_alt[];
-#define PPC_ENABLE_ALTERNATE(nodelabel) \
- do { \
- BUILD_ASSERT(DT_NODE_EXISTS(DT_NODELABEL(nodelabel)), \
- "PPC alternate node does not exist"); \
- memcpy(&ppc_chips[PPC_ALT_FOR(DT_NODELABEL(nodelabel))], \
- &ppc_chips_alt[PPC_ID(DT_NODELABEL(nodelabel))], \
- sizeof(struct ppc_config_t)); \
+#define ALT_PPC_CHIP_CHK(usbc_id, usb_port_num) \
+ COND_CODE_1(DT_REG_HAS_IDX(usbc_id, usb_port_num), \
+ (COND_CODE_1(DT_NODE_HAS_PROP(usbc_id, ppc_alt), (|| 1), \
+ (|| 0))), \
+ (|| 0))
+
+#define PPC_ENABLE_ALTERNATE(usb_port_num) \
+ do { \
+ BUILD_ASSERT( \
+ (0 DT_FOREACH_STATUS_OKAY_VARGS(named_usbc_port, \
+ ALT_PPC_CHIP_CHK, \
+ usb_port_num)), \
+ "Selected USB node does not exist or does not specify a PPC " \
+ "alternate chip"); \
+ memcpy(&ppc_chips[usb_port_num], &ppc_chips_alt[usb_port_num], \
+ sizeof(struct ppc_config_t)); \
} while (0)
#endif /* ZEPHYR_CHROME_USBC_PPC_H */
diff --git a/zephyr/shim/include/usbc/ppc_nx20p348x.h b/zephyr/shim/include/usbc/ppc_nx20p348x.h
index 162a937a99..31d6ded2a9 100644
--- a/zephyr/shim/include/usbc/ppc_nx20p348x.h
+++ b/zephyr/shim/include/usbc/ppc_nx20p348x.h
@@ -7,7 +7,7 @@
#define NX20P348X_COMPAT nxp_nx20p348x
-#define PPC_CHIP_NX20P348X(id) \
- { .i2c_port = I2C_PORT(DT_PHANDLE(id, port)), \
- .i2c_addr_flags = DT_STRING_UPPER_TOKEN(id, i2c_addr_flags), \
+#define PPC_CHIP_NX20P348X(id) \
+ { .i2c_port = I2C_PORT_BY_DEV(id), \
+ .i2c_addr_flags = DT_REG_ADDR(id), \
.drv = &nx20p348x_drv },
diff --git a/zephyr/shim/include/usbc/ppc_rt1739.h b/zephyr/shim/include/usbc/ppc_rt1739.h
index 19e169a436..bb4b75126a 100644
--- a/zephyr/shim/include/usbc/ppc_rt1739.h
+++ b/zephyr/shim/include/usbc/ppc_rt1739.h
@@ -5,14 +5,14 @@
#include "driver/ppc/rt1739.h"
-#define RT1739_PPC_COMPAT richtek_rt1739_ppc
+#define RT1739_PPC_COMPAT richtek_rt1739
-#define PPC_CHIP_RT1739(id) \
- { \
- .i2c_port = I2C_PORT(DT_PHANDLE(id, port)), \
- .i2c_addr_flags = DT_STRING_UPPER_TOKEN(id, i2c_addr_flags), \
- .drv = &rt1739_ppc_drv, \
- .frs_en = COND_CODE_1(DT_NODE_HAS_PROP(id, irq), \
- (GPIO_SIGNAL(DT_PHANDLE(id, irq))), \
- (0)), \
+#define PPC_CHIP_RT1739(id) \
+ { \
+ .i2c_port = I2C_PORT_BY_DEV(id), \
+ .i2c_addr_flags = DT_REG_ADDR(id), \
+ .drv = &rt1739_ppc_drv, \
+ .frs_en = COND_CODE_1(DT_NODE_HAS_PROP(id, irq), \
+ (GPIO_SIGNAL(DT_PHANDLE(id, irq))), \
+ (0)), \
},
diff --git a/zephyr/shim/include/usbc/ppc_sn5s330.h b/zephyr/shim/include/usbc/ppc_sn5s330.h
index 7ec9b434a8..71d29fd525 100644
--- a/zephyr/shim/include/usbc/ppc_sn5s330.h
+++ b/zephyr/shim/include/usbc/ppc_sn5s330.h
@@ -7,7 +7,7 @@
#define SN5S330_COMPAT ti_sn5s330
-#define PPC_CHIP_SN5S330(id) \
- { .i2c_port = I2C_PORT(DT_PHANDLE(id, port)), \
- .i2c_addr_flags = DT_STRING_UPPER_TOKEN(id, i2c_addr_flags), \
+#define PPC_CHIP_SN5S330(id) \
+ { .i2c_port = I2C_PORT_BY_DEV(id), \
+ .i2c_addr_flags = DT_REG_ADDR(id), \
.drv = &sn5s330_drv },
diff --git a/zephyr/shim/include/usbc/ppc_syv682x.h b/zephyr/shim/include/usbc/ppc_syv682x.h
index f177aebe8b..0d5b03c9ec 100644
--- a/zephyr/shim/include/usbc/ppc_syv682x.h
+++ b/zephyr/shim/include/usbc/ppc_syv682x.h
@@ -7,12 +7,12 @@
#define SYV682X_COMPAT silergy_syv682x
-#define PPC_CHIP_SYV682X(id) \
- { \
- .i2c_port = I2C_PORT(DT_PHANDLE(id, port)), \
- .i2c_addr_flags = DT_STRING_UPPER_TOKEN(id, i2c_addr_flags), \
- .drv = &syv682x_drv, \
- .frs_en = COND_CODE_1( \
- DT_NODE_HAS_PROP(id, frs_en_gpio), \
- (GPIO_SIGNAL(DT_PHANDLE(id, frs_en_gpio))), (0)), \
+#define PPC_CHIP_SYV682X(id) \
+ { \
+ .i2c_port = I2C_PORT_BY_DEV(id), \
+ .i2c_addr_flags = DT_REG_ADDR(id), \
+ .drv = &syv682x_drv, \
+ .frs_en = COND_CODE_1( \
+ DT_NODE_HAS_PROP(id, frs_en_gpio), \
+ (GPIO_SIGNAL(DT_PHANDLE(id, frs_en_gpio))), (0)), \
},