summaryrefslogtreecommitdiff
path: root/zephyr/shim/include/usbc
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/shim/include/usbc')
-rw-r--r--zephyr/shim/include/usbc/amd_fp6_usb_mux.h21
-rw-r--r--zephyr/shim/include/usbc/anx7447_usb_mux.h22
-rw-r--r--zephyr/shim/include/usbc/anx7483_usb_mux.h17
-rw-r--r--zephyr/shim/include/usbc/bb_retimer_usb_mux.h109
-rw-r--r--zephyr/shim/include/usbc/bc12_pi3usb9201.h7
-rw-r--r--zephyr/shim/include/usbc/bc12_rt1718s.h13
-rw-r--r--zephyr/shim/include/usbc/bc12_rt1739.h9
-rw-r--r--zephyr/shim/include/usbc/bc12_rt9490.h7
-rw-r--r--zephyr/shim/include/usbc/it5205_usb_mux.h17
-rw-r--r--zephyr/shim/include/usbc/ppc.h41
-rw-r--r--zephyr/shim/include/usbc/ppc_aoz1380.h11
-rw-r--r--zephyr/shim/include/usbc/ppc_nx20p348x.h13
-rw-r--r--zephyr/shim/include/usbc/ppc_rt1739.h20
-rw-r--r--zephyr/shim/include/usbc/ppc_sn5s330.h12
-rw-r--r--zephyr/shim/include/usbc/ppc_syv682x.h18
-rw-r--r--zephyr/shim/include/usbc/ps8743_usb_mux.h21
-rw-r--r--zephyr/shim/include/usbc/ps8818_usb_mux.h21
-rw-r--r--zephyr/shim/include/usbc/tcpc_anx7447.h20
-rw-r--r--zephyr/shim/include/usbc/tcpc_ccgxxf.h21
-rw-r--r--zephyr/shim/include/usbc/tcpc_fusb302.h19
-rw-r--r--zephyr/shim/include/usbc/tcpc_generic_emul.h20
-rw-r--r--zephyr/shim/include/usbc/tcpc_it8xxx2.h14
-rw-r--r--zephyr/shim/include/usbc/tcpc_nct38xx.h21
-rw-r--r--zephyr/shim/include/usbc/tcpc_ps8xxx.h21
-rw-r--r--zephyr/shim/include/usbc/tcpc_ps8xxx_emul.h19
-rw-r--r--zephyr/shim/include/usbc/tcpc_rt1718s.h20
-rw-r--r--zephyr/shim/include/usbc/tcpci.h18
-rw-r--r--zephyr/shim/include/usbc/tcpci_usb_mux.h49
-rw-r--r--zephyr/shim/include/usbc/tusb1064_usb_mux.h45
-rw-r--r--zephyr/shim/include/usbc/usb_muxes.h474
-rw-r--r--zephyr/shim/include/usbc/utils.h21
-rw-r--r--zephyr/shim/include/usbc/virtual_usb_mux.h14
32 files changed, 806 insertions, 369 deletions
diff --git a/zephyr/shim/include/usbc/amd_fp6_usb_mux.h b/zephyr/shim/include/usbc/amd_fp6_usb_mux.h
new file mode 100644
index 0000000000..a474a4eee4
--- /dev/null
+++ b/zephyr/shim/include/usbc/amd_fp6_usb_mux.h
@@ -0,0 +1,21 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef __ZEPHYR_SHIM_AMD_FP6_USB_MUX_H
+#define __ZEPHYR_SHIM_AMD_FP6_USB_MUX_H
+
+#include "usb_mux.h"
+
+#define AMD_FP6_USB_MUX_COMPAT amd_usbc_mux_amd_fp6
+
+#define USB_MUX_CONFIG_AMD_FP6(mux_id) \
+ { \
+ USB_MUX_COMMON_FIELDS(mux_id), \
+ .driver = &amd_fp6_usb_mux_driver, \
+ .i2c_port = I2C_PORT_BY_DEV(mux_id), \
+ .i2c_addr_flags = DT_REG_ADDR(mux_id), \
+ }
+
+#endif /* __ZEPHYR_SHIM_AMD_FP6_USB_MUX_H */
diff --git a/zephyr/shim/include/usbc/anx7447_usb_mux.h b/zephyr/shim/include/usbc/anx7447_usb_mux.h
new file mode 100644
index 0000000000..874958c04c
--- /dev/null
+++ b/zephyr/shim/include/usbc/anx7447_usb_mux.h
@@ -0,0 +1,22 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef __ZEPHYR_SHIM_ANX7447_USB_MUX_H
+#define __ZEPHYR_SHIM_ANX7447_USB_MUX_H
+
+#include "tcpm/anx7447_public.h"
+
+#define ANX7447_USB_MUX_COMPAT analogix_usbc_mux_anx7447
+
+#define USB_MUX_CONFIG_ANX7447(mux_id) \
+ { \
+ USB_MUX_COMMON_FIELDS(mux_id), \
+ .driver = &anx7447_usb_mux_driver, \
+ .hpd_update = COND_CODE_1( \
+ DT_PROP(mux_id, hpd_update_enable), \
+ (&anx7447_tcpc_update_hpd_status), (NULL)), \
+ }
+
+#endif /* __ZEPHYR_SHIM_ANX7447_USB_MUX_H */
diff --git a/zephyr/shim/include/usbc/anx7483_usb_mux.h b/zephyr/shim/include/usbc/anx7483_usb_mux.h
index 606928b016..5e56837e3a 100644
--- a/zephyr/shim/include/usbc/anx7483_usb_mux.h
+++ b/zephyr/shim/include/usbc/anx7483_usb_mux.h
@@ -1,4 +1,4 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -8,15 +8,14 @@
#include "driver/retimer/anx7483_public.h"
-#define ANX7483_USB_MUX_COMPAT analogix_anx7483
+#define ANX7483_USB_MUX_COMPAT analogix_anx7483
-#define USB_MUX_CONFIG_ANX7483(mux_id, port_id, idx) \
- { \
- USB_MUX_COMMON_FIELDS(mux_id, port_id, idx), \
- .driver = &anx7483_usb_retimer_driver, \
- .i2c_port = I2C_PORT(DT_PHANDLE(mux_id, port)), \
- .i2c_addr_flags = \
- DT_STRING_UPPER_TOKEN(mux_id, i2c_addr_flags), \
+#define USB_MUX_CONFIG_ANX7483(mux_id) \
+ { \
+ USB_MUX_COMMON_FIELDS(mux_id), \
+ .driver = &anx7483_usb_retimer_driver, \
+ .i2c_port = I2C_PORT_BY_DEV(mux_id), \
+ .i2c_addr_flags = DT_REG_ADDR(mux_id), \
}
#endif /* __ZEPHYR_SHIM_ANX7483_USB_MUX_H */
diff --git a/zephyr/shim/include/usbc/bb_retimer_usb_mux.h b/zephyr/shim/include/usbc/bb_retimer_usb_mux.h
index 611c52e081..64e1e2693d 100644
--- a/zephyr/shim/include/usbc/bb_retimer_usb_mux.h
+++ b/zephyr/shim/include/usbc/bb_retimer_usb_mux.h
@@ -1,4 +1,4 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -10,23 +10,100 @@
#define BB_RETIMER_USB_MUX_COMPAT intel_jhl8040r
-#define USB_MUX_CONFIG_BB_RETIMER(mux_id, port_id, idx) \
- { \
- USB_MUX_COMMON_FIELDS(mux_id, port_id, idx), \
- .driver = &bb_usb_retimer, \
- .hpd_update = bb_retimer_hpd_update, \
- .i2c_port = I2C_PORT(DT_PHANDLE(mux_id, port)), \
- .i2c_addr_flags = DT_PROP(mux_id, i2c_addr_flags), \
+#define USB_MUX_CONFIG_BB_RETIMER(mux_id) \
+ { \
+ USB_MUX_COMMON_FIELDS(mux_id), \
+ .driver = &bb_usb_retimer, \
+ .hpd_update = bb_retimer_hpd_update, \
+ .i2c_port = I2C_PORT_BY_DEV(mux_id), \
+ .i2c_addr_flags = DT_REG_ADDR(mux_id), \
}
-#define BB_RETIMER_CONTROLS_CONFIG(mux_id, port_id, idx) \
- { \
- .retimer_rst_gpio = \
- GPIO_SIGNAL(DT_PHANDLE(mux_id, reset_pin)), \
- .usb_ls_en_gpio = COND_CODE_1( \
- DT_NODE_HAS_PROP(mux_id, ls_en_pin), \
- (GPIO_SIGNAL(DT_PHANDLE(mux_id, ls_en_pin))), \
- (GPIO_UNIMPLEMENTED)), \
+/**
+ * @brief Get reset gpio for @p mux_id retimer
+ *
+ * @param mux_id BB retimer DTS node
+ */
+#define BB_RETIMER_RESET_GPIO(mux_id) GPIO_SIGNAL(DT_PHANDLE(mux_id, reset_pin))
+
+/**
+ * @brief Get LS_EN gpio for @p mux_id retimer
+ *
+ * @param mux_id BB retimer DTS node
+ */
+#define BB_RETIMER_LS_EN_GPIO(mux_id) \
+ COND_CODE_1(DT_NODE_HAS_PROP(mux_id, ls_en_pin), \
+ (GPIO_SIGNAL(DT_PHANDLE(mux_id, ls_en_pin))), \
+ (GPIO_UNIMPLEMENTED))
+
+#define BB_RETIMER_CONTROLS_CONFIG(mux_id) \
+ { \
+ .retimer_rst_gpio = BB_RETIMER_RESET_GPIO(mux_id), \
+ .usb_ls_en_gpio = BB_RETIMER_LS_EN_GPIO(mux_id), \
}
+/**
+ * @brief Set entry in bb_controls array
+ *
+ * @param mux_id BB retimer node ID
+ */
+#define USB_MUX_BB_RETIMER_CONTROL_ARRAY(mux_id) \
+ [USB_MUX_PORT(mux_id)] = BB_RETIMER_CONTROLS_CONFIG(mux_id),
+
+/**
+ * @brief Call USB_MUX_BB_RETIMER_CONTROL_ARRAY for every BB retimer in DTS
+ */
+#define USB_MUX_BB_RETIMERS_CONTROLS_ARRAY \
+ DT_FOREACH_STATUS_OKAY(BB_RETIMER_USB_MUX_COMPAT, \
+ USB_MUX_BB_RETIMER_CONTROL_ARRAY)
+
+/**
+ * @brief Check if BB retimers @p id_1 and @p id_2 has matching configuration
+ * Configuration match if reset and ls_en pins are the same for muxes
+ * which are on the same USB-C port.
+ *
+ * @param id_1 First BB retimer DTS node
+ * @param id_2 Second BB retimer DTS node
+ */
+#define BB_RETIMER_CHECK_PAIR(id_1, id_2) \
+ BUILD_ASSERT(USB_MUX_PORT(id_1) != USB_MUX_PORT(id_2) || \
+ (BB_RETIMER_RESET_GPIO(id_1) == \
+ BB_RETIMER_RESET_GPIO(id_2) && \
+ BB_RETIMER_LS_EN_GPIO(id_1) == \
+ BB_RETIMER_LS_EN_GPIO(id_2)), \
+ "BB retimers " #id_1 " and " #id_2 " have different pin " \
+ "configuration and same USB-C port")
+
+/**
+ * @brief Check if BB retimers with @p inst instance number has matching
+ * configuration with muxes of higher instance number on @p bb_list list.
+ * Configuration match if reset and ls_en pins are the same for muxes
+ * which are on the same USB-C port.
+ *
+ * @param inst Instance number of BB retimer mux
+ * @param bb_list List of BB retimers in instance number order
+ */
+#define BB_RETIMER_CHECK_INSTANCE_WITH_LIST(inst, bb_list) \
+ FOR_EACH_FIXED_ARG(BB_RETIMER_CHECK_PAIR, (;), \
+ DT_INST(inst, BB_RETIMER_USB_MUX_COMPAT), \
+ GET_ARGS_LESS_N(inst, __DEBRACKET bb_list))
+
+/**
+ * @brief Check if BB retimers on the @p bb_list list have matching
+ * configurations (i.e. reset and ls_en pins are the same for muxes
+ * which are on the same USB-C port). This check is required, because
+ * USB_MUX_ENABLE_ALTERNATE() doesn't update bb_control[] array, so all
+ * BB retimers needs to use the same GPIO pins.
+ *
+ * @param bb_list List of BB retimers in instance number order
+ */
+#define BB_RETIMER_CHECK_SAME_CONTROLS(bb_list) \
+ LISTIFY(DT_NUM_INST_STATUS_OKAY(BB_RETIMER_USB_MUX_COMPAT), \
+ BB_RETIMER_CHECK_INSTANCE_WITH_LIST, (;), bb_list);
+
+/** List of all BB retimers in DTS in instance number order */
+#define BB_RETIMER_INSTANCES_LIST \
+ (LISTIFY(DT_NUM_INST_STATUS_OKAY(BB_RETIMER_USB_MUX_COMPAT), DT_INST, \
+ (, ), BB_RETIMER_USB_MUX_COMPAT))
+
#endif /* __ZEPHYR_SHIM_BB_RETIMER_USB_MUX_H */
diff --git a/zephyr/shim/include/usbc/bc12_pi3usb9201.h b/zephyr/shim/include/usbc/bc12_pi3usb9201.h
index 59b84cd868..701090133f 100644
--- a/zephyr/shim/include/usbc/bc12_pi3usb9201.h
+++ b/zephyr/shim/include/usbc/bc12_pi3usb9201.h
@@ -1,4 +1,4 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -7,4 +7,7 @@
#define PI3USB9201_COMPAT pericom_pi3usb9201
-#define BC12_CHIP_PI3USB9201(id) { .drv = &pi3usb9201_drv, },
+#define BC12_CHIP_PI3USB9201(id) \
+ { \
+ .drv = &pi3usb9201_drv, \
+ },
diff --git a/zephyr/shim/include/usbc/bc12_rt1718s.h b/zephyr/shim/include/usbc/bc12_rt1718s.h
new file mode 100644
index 0000000000..e34f21c9e0
--- /dev/null
+++ b/zephyr/shim/include/usbc/bc12_rt1718s.h
@@ -0,0 +1,13 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "tcpm/rt1718s_public.h"
+
+#define RT1718S_BC12_COMPAT richtek_rt1718s_bc12
+
+#define BC12_CHIP_RT1718S(id) \
+ { \
+ .drv = &rt1718s_bc12_drv, \
+ },
diff --git a/zephyr/shim/include/usbc/bc12_rt1739.h b/zephyr/shim/include/usbc/bc12_rt1739.h
index 3347d7d717..8d7427b271 100644
--- a/zephyr/shim/include/usbc/bc12_rt1739.h
+++ b/zephyr/shim/include/usbc/bc12_rt1739.h
@@ -1,10 +1,13 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "driver/ppc/rt1739.h"
-#define RT1739_BC12_COMPAT richtek_rt1739_bc12
+#define RT1739_BC12_COMPAT richtek_rt1739
-#define BC12_CHIP_RT1739(id) { .drv = &rt1739_bc12_drv, },
+#define BC12_CHIP_RT1739(id) \
+ { \
+ .drv = &rt1739_bc12_drv, \
+ },
diff --git a/zephyr/shim/include/usbc/bc12_rt9490.h b/zephyr/shim/include/usbc/bc12_rt9490.h
index f9bc82f292..a9371ddeea 100644
--- a/zephyr/shim/include/usbc/bc12_rt9490.h
+++ b/zephyr/shim/include/usbc/bc12_rt9490.h
@@ -1,4 +1,4 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -7,4 +7,7 @@
#define RT9490_BC12_COMPAT richtek_rt9490_bc12
-#define BC12_CHIP_RT9490(id) { .drv = &rt9490_bc12_drv, },
+#define BC12_CHIP_RT9490(id) \
+ { \
+ .drv = &rt9490_bc12_drv, \
+ },
diff --git a/zephyr/shim/include/usbc/it5205_usb_mux.h b/zephyr/shim/include/usbc/it5205_usb_mux.h
index 58412e0bd3..983248f3e2 100644
--- a/zephyr/shim/include/usbc/it5205_usb_mux.h
+++ b/zephyr/shim/include/usbc/it5205_usb_mux.h
@@ -1,4 +1,4 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -8,15 +8,14 @@
#include "usb_mux/it5205_public.h"
-#define IT5205_USB_MUX_COMPAT ite_it5205
+#define IT5205_USB_MUX_COMPAT ite_it5205
-#define USB_MUX_CONFIG_IT5205(mux_id, port_id, idx) \
- { \
- USB_MUX_COMMON_FIELDS(mux_id, port_id, idx), \
- .driver = &it5205_usb_mux_driver, \
- .i2c_port = I2C_PORT(DT_PHANDLE(mux_id, port)), \
- .i2c_addr_flags = \
- DT_STRING_UPPER_TOKEN(mux_id, i2c_addr_flags), \
+#define USB_MUX_CONFIG_IT5205(mux_id) \
+ { \
+ USB_MUX_COMMON_FIELDS(mux_id), \
+ .driver = &it5205_usb_mux_driver, \
+ .i2c_port = I2C_PORT_BY_DEV(mux_id), \
+ .i2c_addr_flags = DT_REG_ADDR(mux_id), \
}
#endif /* __ZEPHYR_SHIM_IT5205_USB_MUX_H */
diff --git a/zephyr/shim/include/usbc/ppc.h b/zephyr/shim/include/usbc/ppc.h
index 94aee49f36..28e518a3ef 100644
--- a/zephyr/shim/include/usbc/ppc.h
+++ b/zephyr/shim/include/usbc/ppc.h
@@ -1,4 +1,4 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+/* Copyright 2021 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -9,35 +9,30 @@
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include "usbc/ppc_rt1739.h"
+#include "usbc/ppc_nx20p348x.h"
#include "usbc/ppc_sn5s330.h"
#include "usbc/ppc_syv682x.h"
#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(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_aoz1380.h b/zephyr/shim/include/usbc/ppc_aoz1380.h
new file mode 100644
index 0000000000..1ff20b802f
--- /dev/null
+++ b/zephyr/shim/include/usbc/ppc_aoz1380.h
@@ -0,0 +1,11 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "ppc/aoz1380_public.h"
+
+#define AOZ1380_COMPAT aoz_aoz1380
+
+/* Note: This chip has no i2c interface */
+#define PPC_CHIP_AOZ1380(id) { .drv = &aoz1380_drv },
diff --git a/zephyr/shim/include/usbc/ppc_nx20p348x.h b/zephyr/shim/include/usbc/ppc_nx20p348x.h
new file mode 100644
index 0000000000..2d36ab09f6
--- /dev/null
+++ b/zephyr/shim/include/usbc/ppc_nx20p348x.h
@@ -0,0 +1,13 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "ppc/nx20p348x_public.h"
+
+#define NX20P348X_COMPAT nxp_nx20p348x
+
+#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..5b71b9ff9c 100644
--- a/zephyr/shim/include/usbc/ppc_rt1739.h
+++ b/zephyr/shim/include/usbc/ppc_rt1739.h
@@ -1,18 +1,18 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#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 1c48777107..ecbcb53deb 100644
--- a/zephyr/shim/include/usbc/ppc_sn5s330.h
+++ b/zephyr/shim/include/usbc/ppc_sn5s330.h
@@ -1,4 +1,4 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+/* Copyright 2021 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -7,9 +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), \
- .drv = &sn5s330_drv \
- },
+#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 1c2691f684..33813a5256 100644
--- a/zephyr/shim/include/usbc/ppc_syv682x.h
+++ b/zephyr/shim/include/usbc/ppc_syv682x.h
@@ -1,4 +1,4 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+/* Copyright 2021 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -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)), \
},
diff --git a/zephyr/shim/include/usbc/ps8743_usb_mux.h b/zephyr/shim/include/usbc/ps8743_usb_mux.h
new file mode 100644
index 0000000000..75ce778bac
--- /dev/null
+++ b/zephyr/shim/include/usbc/ps8743_usb_mux.h
@@ -0,0 +1,21 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef __ZEPHYR_SHIM_PS8743_USB_MUX_H
+#define __ZEPHYR_SHIM_PS8743_USB_MUX_H
+
+#include "usb_mux/ps8743_public.h"
+
+#define PS8743_USB_MUX_COMPAT parade_ps8743
+
+#define USB_MUX_CONFIG_PS8743(mux_id) \
+ { \
+ USB_MUX_COMMON_FIELDS(mux_id), \
+ .driver = &ps8743_usb_mux_driver, \
+ .i2c_port = I2C_PORT_BY_DEV(mux_id), \
+ .i2c_addr_flags = DT_REG_ADDR(mux_id), \
+ }
+
+#endif /* __ZEPHYR_SHIM_PS8743_USB_MUX_H */
diff --git a/zephyr/shim/include/usbc/ps8818_usb_mux.h b/zephyr/shim/include/usbc/ps8818_usb_mux.h
new file mode 100644
index 0000000000..c45e69aee3
--- /dev/null
+++ b/zephyr/shim/include/usbc/ps8818_usb_mux.h
@@ -0,0 +1,21 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef __ZEPHYR_SHIM_PS8818_USB_MUX_H
+#define __ZEPHYR_SHIM_PS8818_USB_MUX_H
+
+#include "driver/retimer/ps8818_public.h"
+
+#define PS8818_USB_MUX_COMPAT parade_ps8818
+
+#define USB_MUX_CONFIG_PS8818(mux_id) \
+ { \
+ USB_MUX_COMMON_FIELDS(mux_id), \
+ .driver = &ps8818_usb_retimer_driver, \
+ .i2c_port = I2C_PORT_BY_DEV(mux_id), \
+ .i2c_addr_flags = DT_REG_ADDR(mux_id), \
+ }
+
+#endif /* __ZEPHYR_SHIM_PS8818_USB_MUX_H */
diff --git a/zephyr/shim/include/usbc/tcpc_anx7447.h b/zephyr/shim/include/usbc/tcpc_anx7447.h
new file mode 100644
index 0000000000..7a59296e74
--- /dev/null
+++ b/zephyr/shim/include/usbc/tcpc_anx7447.h
@@ -0,0 +1,20 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <zephyr/devicetree.h>
+#include "tcpm/anx7447_public.h"
+
+#define ANX7447_TCPC_COMPAT anologix_anx7447_tcpc
+
+#define TCPC_CONFIG_ANX7447(id) \
+ { \
+ .bus_type = EC_BUS_TYPE_I2C, \
+ .i2c_info = { \
+ .port = I2C_PORT_BY_DEV(id), \
+ .addr_flags = DT_REG_ADDR(id), \
+ }, \
+ .drv = &anx7447_tcpm_drv, \
+ .flags = DT_PROP(id, tcpc_flags), \
+ },
diff --git a/zephyr/shim/include/usbc/tcpc_ccgxxf.h b/zephyr/shim/include/usbc/tcpc_ccgxxf.h
index 566fed03d6..0c02cf6846 100644
--- a/zephyr/shim/include/usbc/tcpc_ccgxxf.h
+++ b/zephyr/shim/include/usbc/tcpc_ccgxxf.h
@@ -1,4 +1,4 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -8,14 +8,13 @@
#define CCGXXF_TCPC_COMPAT cypress_ccgxxf
-#define TCPC_CONFIG_CCGXXF(id) \
- { \
- .bus_type = EC_BUS_TYPE_I2C, \
- .i2c_info = { \
- .port = I2C_PORT(DT_PHANDLE(id, port)), \
- .addr_flags = DT_STRING_UPPER_TOKEN( \
- id, i2c_addr_flags), \
- }, \
- .drv = &ccgxxf_tcpm_drv, \
- .flags = TCPC_FLAGS_TCPCI_REV2_0, \
+#define TCPC_CONFIG_CCGXXF(id) \
+ { \
+ .bus_type = EC_BUS_TYPE_I2C, \
+ .i2c_info = { \
+ .port = I2C_PORT_BY_DEV(id), \
+ .addr_flags = DT_REG_ADDR(id), \
+ }, \
+ .drv = &ccgxxf_tcpm_drv, \
+ .flags = TCPC_FLAGS_TCPCI_REV2_0, \
},
diff --git a/zephyr/shim/include/usbc/tcpc_fusb302.h b/zephyr/shim/include/usbc/tcpc_fusb302.h
index fefb54af7d..a2e512d938 100644
--- a/zephyr/shim/include/usbc/tcpc_fusb302.h
+++ b/zephyr/shim/include/usbc/tcpc_fusb302.h
@@ -1,4 +1,4 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -8,13 +8,12 @@
#define FUSB302_TCPC_COMPAT fairchild_fusb302
-#define TCPC_CONFIG_FUSB302(id) \
- { \
- .bus_type = EC_BUS_TYPE_I2C, \
- .i2c_info = { \
- .port = I2C_PORT(DT_PHANDLE(id, port)), \
- .addr_flags = DT_STRING_UPPER_TOKEN( \
- id, i2c_addr_flags), \
- }, \
- .drv = &fusb302_tcpm_drv, \
+#define TCPC_CONFIG_FUSB302(id) \
+ { \
+ .bus_type = EC_BUS_TYPE_I2C, \
+ .i2c_info = { \
+ .port = I2C_PORT_BY_DEV(id), \
+ .addr_flags = DT_REG_ADDR(id), \
+ }, \
+ .drv = &fusb302_tcpm_drv, \
},
diff --git a/zephyr/shim/include/usbc/tcpc_generic_emul.h b/zephyr/shim/include/usbc/tcpc_generic_emul.h
new file mode 100644
index 0000000000..7dc46c51ba
--- /dev/null
+++ b/zephyr/shim/include/usbc/tcpc_generic_emul.h
@@ -0,0 +1,20 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <zephyr/devicetree.h>
+
+#include "driver/tcpm/tcpci.h"
+
+#define TCPCI_EMUL_COMPAT cros_tcpci_generic_emul
+
+#define TCPC_CONFIG_TCPCI_EMUL(id) \
+ { \
+ .bus_type = EC_BUS_TYPE_I2C, \
+ .i2c_info = { \
+ .port = I2C_PORT_BY_DEV(id), \
+ .addr_flags = DT_REG_ADDR(id), \
+ }, \
+ .drv = &tcpci_tcpm_drv, \
+ },
diff --git a/zephyr/shim/include/usbc/tcpc_it8xxx2.h b/zephyr/shim/include/usbc/tcpc_it8xxx2.h
index be275441d8..c619656667 100644
--- a/zephyr/shim/include/usbc/tcpc_it8xxx2.h
+++ b/zephyr/shim/include/usbc/tcpc_it8xxx2.h
@@ -1,4 +1,4 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -6,11 +6,11 @@
#include <zephyr/devicetree.h>
#include "driver/tcpm/it8xxx2_pd_public.h"
-#define IT8XXX2_TCPC_COMPAT ite_it8xxx2_tcpc
+#define IT8XXX2_TCPC_COMPAT ite_it8xxx2_usbpd
-#define TCPC_CONFIG_IT8XXX2(id) \
- { \
- .bus_type = EC_BUS_TYPE_EMBEDDED, \
- .drv = &it8xxx2_tcpm_drv, \
- .flags = 0, \
+#define TCPC_CONFIG_IT8XXX2(id) \
+ { \
+ .bus_type = EC_BUS_TYPE_EMBEDDED, \
+ .drv = &it8xxx2_tcpm_drv, \
+ .flags = 0, \
},
diff --git a/zephyr/shim/include/usbc/tcpc_nct38xx.h b/zephyr/shim/include/usbc/tcpc_nct38xx.h
index 87b222c794..87ba3379c8 100644
--- a/zephyr/shim/include/usbc/tcpc_nct38xx.h
+++ b/zephyr/shim/include/usbc/tcpc_nct38xx.h
@@ -1,4 +1,4 @@
-/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+/* Copyright 2021 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -11,16 +11,15 @@
#define NCT38XX_TCPC_COMPAT nuvoton_nct38xx
-#define TCPC_CONFIG_NCT38XX(id) \
- { \
- .bus_type = EC_BUS_TYPE_I2C, \
- .i2c_info = { \
- .port = I2C_PORT(DT_PHANDLE(id, port)), \
- .addr_flags = DT_STRING_UPPER_TOKEN( \
- id, i2c_addr_flags), \
- }, \
- .drv = &nct38xx_tcpm_drv, \
- .flags = DT_PROP(id, tcpc_flags), \
+#define TCPC_CONFIG_NCT38XX(id) \
+ { \
+ .bus_type = EC_BUS_TYPE_I2C, \
+ .i2c_info = { \
+ .port = I2C_PORT_BY_DEV(id), \
+ .addr_flags = DT_REG_ADDR(id), \
+ }, \
+ .drv = &nct38xx_tcpm_drv, \
+ .flags = DT_PROP(id, tcpc_flags), \
},
/**
diff --git a/zephyr/shim/include/usbc/tcpc_ps8xxx.h b/zephyr/shim/include/usbc/tcpc_ps8xxx.h
index d47f6cc9df..1a457af09b 100644
--- a/zephyr/shim/include/usbc/tcpc_ps8xxx.h
+++ b/zephyr/shim/include/usbc/tcpc_ps8xxx.h
@@ -1,4 +1,4 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -8,14 +8,13 @@
#define PS8XXX_COMPAT parade_ps8xxx
-#define TCPC_CONFIG_PS8XXX(id) \
- { \
- .bus_type = EC_BUS_TYPE_I2C, \
- .i2c_info = { \
- .port = I2C_PORT(DT_PHANDLE(id, port)), \
- .addr_flags = DT_STRING_UPPER_TOKEN( \
- id, i2c_addr_flags), \
- }, \
- .drv = &ps8xxx_tcpm_drv, \
- .flags = DT_PROP(id, tcpc_flags), \
+#define TCPC_CONFIG_PS8XXX(id) \
+ { \
+ .bus_type = EC_BUS_TYPE_I2C, \
+ .i2c_info = { \
+ .port = I2C_PORT_BY_DEV(id), \
+ .addr_flags = DT_REG_ADDR(id), \
+ }, \
+ .drv = &ps8xxx_tcpm_drv, \
+ .flags = DT_PROP(id, tcpc_flags), \
},
diff --git a/zephyr/shim/include/usbc/tcpc_ps8xxx_emul.h b/zephyr/shim/include/usbc/tcpc_ps8xxx_emul.h
new file mode 100644
index 0000000000..fbd2e4bfd1
--- /dev/null
+++ b/zephyr/shim/include/usbc/tcpc_ps8xxx_emul.h
@@ -0,0 +1,19 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <zephyr/devicetree.h>
+#include "driver/tcpm/ps8xxx_public.h"
+
+#define PS8XXX_EMUL_COMPAT cros_ps8xxx_emul
+
+#define TCPC_CONFIG_PS8XXX_EMUL(id) \
+ { \
+ .bus_type = EC_BUS_TYPE_I2C, \
+ .i2c_info = { \
+ .port = I2C_PORT_BY_DEV(id), \
+ .addr_flags = DT_REG_ADDR(id), \
+ }, \
+ .drv = &ps8xxx_tcpm_drv, \
+ },
diff --git a/zephyr/shim/include/usbc/tcpc_rt1718s.h b/zephyr/shim/include/usbc/tcpc_rt1718s.h
new file mode 100644
index 0000000000..794fb99480
--- /dev/null
+++ b/zephyr/shim/include/usbc/tcpc_rt1718s.h
@@ -0,0 +1,20 @@
+/* Copyright 2022 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include <zephyr/devicetree.h>
+#include "tcpm/rt1718s_public.h"
+
+#define RT1718S_TCPC_COMPAT richtek_rt1718s_tcpc
+
+#define TCPC_CONFIG_RT1718S(id) \
+ { \
+ .bus_type = EC_BUS_TYPE_I2C, \
+ .i2c_info = { \
+ .port = I2C_PORT_BY_DEV(id), \
+ .addr_flags = DT_REG_ADDR(id), \
+ }, \
+ .drv = &rt1718s_tcpm_drv, \
+ .flags = DT_PROP(id, tcpc_flags), \
+ },
diff --git a/zephyr/shim/include/usbc/tcpci.h b/zephyr/shim/include/usbc/tcpci.h
index 35f706d09b..67138dbe99 100644
--- a/zephyr/shim/include/usbc/tcpci.h
+++ b/zephyr/shim/include/usbc/tcpci.h
@@ -1,4 +1,4 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -9,12 +9,12 @@
#define TCPCI_COMPAT cros_ec_tcpci
-#define TCPC_CONFIG_TCPCI(id) \
- { \
- .bus_type = EC_BUS_TYPE_I2C, \
- .i2c_info = { \
- .port = I2C_PORT(DT_PHANDLE(id, port)), \
- .addr_flags = DT_PROP(id, i2c_addr_flags), \
- }, \
- .drv = &tcpci_tcpm_drv, \
+#define TCPC_CONFIG_TCPCI(id) \
+ { \
+ .bus_type = EC_BUS_TYPE_I2C, \
+ .i2c_info = { \
+ .port = I2C_PORT_BY_DEV(id), \
+ .addr_flags = DT_REG_ADDR(id), \
+ }, \
+ .drv = &tcpci_tcpm_drv, \
},
diff --git a/zephyr/shim/include/usbc/tcpci_usb_mux.h b/zephyr/shim/include/usbc/tcpci_usb_mux.h
index 9fa29c7c85..1a5dd38241 100644
--- a/zephyr/shim/include/usbc/tcpci_usb_mux.h
+++ b/zephyr/shim/include/usbc/tcpci_usb_mux.h
@@ -1,4 +1,4 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -10,41 +10,36 @@
#include "tcpm/ps8xxx_public.h"
#include "tcpm/tcpci.h"
-#define TCPCI_TCPM_USB_MUX_COMPAT cros_ec_usbc_mux_tcpci
-#define PS8XXX_USB_MUX_COMPAT parade_usbc_mux_ps8xxx
+#define TCPCI_TCPM_USB_MUX_COMPAT cros_ec_usbc_mux_tcpci
+#define PS8XXX_USB_MUX_COMPAT parade_usbc_mux_ps8xxx
/**
* Add I2C configuration and USB_MUX_FLAG_NOT_TCPC to enforce it when
* mux_read()/mux_write() functions are used.
*/
-#define USB_MUX_CONFIG_TCPCI_TCPM_WITH_I2C(mux_id, port_id, idx) \
- { \
- USB_MUX_COMMON_FIELDS_WITH_FLAGS(mux_id, port_id, idx, \
- USB_MUX_FLAG_NOT_TCPC, \
- USB_MUX_FLAG_NOT_TCPC),\
- .driver = &tcpci_tcpm_usb_mux_driver, \
- .hpd_update = USB_MUX_CALLBACK_OR_NULL(mux_id, \
- hpd_update), \
- .i2c_port = I2C_PORT(DT_PHANDLE(mux_id, port)), \
- .i2c_addr_flags = DT_PROP(mux_id, i2c_addr_flags), \
+#define USB_MUX_CONFIG_TCPCI_TCPM_WITH_I2C(mux_id) \
+ { \
+ USB_MUX_COMMON_FIELDS_WITH_FLAGS( \
+ mux_id, USB_MUX_FLAG_NOT_TCPC, USB_MUX_FLAG_NOT_TCPC), \
+ .driver = &tcpci_tcpm_usb_mux_driver, \
+ .hpd_update = \
+ USB_MUX_CALLBACK_OR_NULL(mux_id, hpd_update), \
+ .i2c_port = I2C_PORT_BY_DEV(mux_id), \
+ .i2c_addr_flags = DT_REG_ADDR(mux_id), \
}
/** Use I2C configuration from TCPC */
-#define USB_MUX_CONFIG_TCPCI_TCPM_WO_I2C(mux_id, port_id, idx) \
- { \
- USB_MUX_COMMON_FIELDS(mux_id, port_id, idx), \
- .driver = &tcpci_tcpm_usb_mux_driver, \
- .hpd_update = USB_MUX_CALLBACK_OR_NULL(mux_id, \
- hpd_update), \
+#define USB_MUX_CONFIG_TCPCI_TCPM_WO_I2C(mux_id) \
+ { \
+ USB_MUX_COMMON_FIELDS(mux_id), \
+ .driver = &tcpci_tcpm_usb_mux_driver, \
+ .hpd_update = \
+ USB_MUX_CALLBACK_OR_NULL(mux_id, hpd_update), \
}
-/** This macro will fail if only port or i2c_addr_flags property is present */
-#define USB_MUX_CONFIG_TCPCI_TCPM(mux_id, port_id, idx) \
- COND_CODE_1(UTIL_OR(DT_NODE_HAS_PROP(mux_id, port), \
- DT_NODE_HAS_PROP(mux_id, i2c_addr_flags)), \
- (USB_MUX_CONFIG_TCPCI_TCPM_WITH_I2C(mux_id, port_id,\
- idx)), \
- (USB_MUX_CONFIG_TCPCI_TCPM_WO_I2C(mux_id, port_id, \
- idx)))
+#define USB_MUX_CONFIG_TCPCI_TCPM(mux_id) \
+ COND_CODE_1(DT_NODE_HAS_PROP(mux_id, reg), \
+ (USB_MUX_CONFIG_TCPCI_TCPM_WITH_I2C(mux_id)), \
+ (USB_MUX_CONFIG_TCPCI_TCPM_WO_I2C(mux_id)))
#endif /* __ZEPHYR_SHIM_TCPCI_USB_MUX_H */
diff --git a/zephyr/shim/include/usbc/tusb1064_usb_mux.h b/zephyr/shim/include/usbc/tusb1064_usb_mux.h
index 159f42c500..55dc8d4645 100644
--- a/zephyr/shim/include/usbc/tusb1064_usb_mux.h
+++ b/zephyr/shim/include/usbc/tusb1064_usb_mux.h
@@ -1,4 +1,4 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -8,35 +8,32 @@
#include "driver/usb_mux/tusb1064.h"
-#define TUSB1064_USB_MUX_COMPAT ti_tusb1064
+#define TUSB1064_USB_MUX_COMPAT ti_tusb1064
#if defined(CONFIG_USB_MUX_TUSB1044)
-#define USB_MUX_CONFIG_TUSB1064(mux_id, port_id, idx) \
- { \
- USB_MUX_COMMON_FIELDS(mux_id, port_id, idx), \
- .driver = &tusb1064_usb_mux_driver, \
- .i2c_port = I2C_PORT(DT_PHANDLE(mux_id, port)), \
- .i2c_addr_flags = \
- DT_STRING_UPPER_TOKEN(mux_id, i2c_addr_flags), \
- .hpd_update = &tusb1044_hpd_update, \
+#define USB_MUX_CONFIG_TUSB1064(mux_id) \
+ { \
+ USB_MUX_COMMON_FIELDS(mux_id), \
+ .driver = &tusb1064_usb_mux_driver, \
+ .i2c_port = I2C_PORT_BY_DEV(mux_id), \
+ .i2c_addr_flags = DT_REG_ADDR(mux_id), \
+ .hpd_update = &tusb1044_hpd_update, \
}
#elif defined(CONFIG_USB_MUX_TUSB546)
-#define USB_MUX_CONFIG_TUSB1064(mux_id, port_id, idx) \
- { \
- USB_MUX_COMMON_FIELDS(mux_id, port_id, idx), \
- .driver = &tusb1064_usb_mux_driver, \
- .i2c_port = I2C_PORT(DT_PHANDLE(mux_id, port)), \
- .i2c_addr_flags = \
- DT_STRING_UPPER_TOKEN(mux_id, i2c_addr_flags), \
+#define USB_MUX_CONFIG_TUSB1064(mux_id) \
+ { \
+ USB_MUX_COMMON_FIELDS(mux_id), \
+ .driver = &tusb1064_usb_mux_driver, \
+ .i2c_port = I2C_PORT_BY_DEV(mux_id), \
+ .i2c_addr_flags = DT_REG_ADDR(mux_id), \
}
#else
-#define USB_MUX_CONFIG_TUSB1064(mux_id, port_id, idx) \
- { \
- USB_MUX_COMMON_FIELDS(mux_id, port_id, idx), \
- .driver = &tusb1064_usb_mux_driver, \
- .i2c_port = I2C_PORT(DT_PHANDLE(mux_id, port)), \
- .i2c_addr_flags = \
- DT_STRING_UPPER_TOKEN(mux_id, i2c_addr_flags), \
+#define USB_MUX_CONFIG_TUSB1064(mux_id) \
+ { \
+ USB_MUX_COMMON_FIELDS(mux_id), \
+ .driver = &tusb1064_usb_mux_driver, \
+ .i2c_port = I2C_PORT_BY_DEV(mux_id), \
+ .i2c_addr_flags = DT_REG_ADDR(mux_id), \
}
#endif /* defined(CONFIG_USB_MUX_TUSB1044) */
diff --git a/zephyr/shim/include/usbc/usb_muxes.h b/zephyr/shim/include/usbc/usb_muxes.h
index 9422d4008d..d161b72b08 100644
--- a/zephyr/shim/include/usbc/usb_muxes.h
+++ b/zephyr/shim/include/usbc/usb_muxes.h
@@ -1,4 +1,4 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -9,108 +9,158 @@
#include <zephyr/devicetree.h>
#include <zephyr/sys/util_macro.h>
#include "usb_mux.h"
+#include "usbc/amd_fp6_usb_mux.h"
+#include "usbc/anx7447_usb_mux.h"
#include "usbc/anx7483_usb_mux.h"
#include "usbc/bb_retimer_usb_mux.h"
#include "usbc/it5205_usb_mux.h"
+#include "usbc/ps8743_usb_mux.h"
+#include "usbc/ps8818_usb_mux.h"
#include "usbc/tcpci_usb_mux.h"
#include "usbc/tusb1064_usb_mux.h"
+#include "usbc/utils.h"
#include "usbc/virtual_usb_mux.h"
/**
* @brief List of USB mux drivers compatibles and their configurations. Each
* element of list has to have (compatible, config) format.
*/
-#define USB_MUX_DRIVERS \
- (ANX7483_USB_MUX_COMPAT, USB_MUX_CONFIG_ANX7483), \
- (BB_RETIMER_USB_MUX_COMPAT, USB_MUX_CONFIG_BB_RETIMER), \
- (IT5205_USB_MUX_COMPAT, USB_MUX_CONFIG_IT5205), \
- (PS8XXX_USB_MUX_COMPAT, USB_MUX_CONFIG_TCPCI_TCPM), \
- (TCPCI_TCPM_USB_MUX_COMPAT, USB_MUX_CONFIG_TCPCI_TCPM), \
- (TUSB1064_USB_MUX_COMPAT, USB_MUX_CONFIG_TUSB1064), \
- (VIRTUAL_USB_MUX_COMPAT, USB_MUX_CONFIG_VIRTUAL)
+#define USB_MUX_DRIVERS \
+ (AMD_FP6_USB_MUX_COMPAT, USB_MUX_CONFIG_AMD_FP6), \
+ (ANX7447_USB_MUX_COMPAT, USB_MUX_CONFIG_ANX7447), \
+ (ANX7483_USB_MUX_COMPAT, USB_MUX_CONFIG_ANX7483), \
+ (BB_RETIMER_USB_MUX_COMPAT, USB_MUX_CONFIG_BB_RETIMER), \
+ (IT5205_USB_MUX_COMPAT, USB_MUX_CONFIG_IT5205), \
+ (PS8743_USB_MUX_COMPAT, USB_MUX_CONFIG_PS8743), \
+ (PS8818_USB_MUX_COMPAT, USB_MUX_CONFIG_PS8818), \
+ (PS8XXX_USB_MUX_COMPAT, USB_MUX_CONFIG_TCPCI_TCPM), \
+ (TCPCI_TCPM_USB_MUX_COMPAT, USB_MUX_CONFIG_TCPCI_TCPM), \
+ (TUSB1064_USB_MUX_COMPAT, USB_MUX_CONFIG_TUSB1064), \
+ (VIRTUAL_USB_MUX_COMPAT, USB_MUX_CONFIG_VIRTUAL)
/**
* @brief Get compatible from @p driver
*
* @param driver USB mux driver description in format (compatible, config)
*/
-#define USB_MUX_DRIVER_GET_COMPAT(driver) GET_ARG_N(1, __DEBRACKET driver)
+#define USB_MUX_DRIVER_GET_COMPAT(driver) GET_ARG_N(1, __DEBRACKET driver)
/**
* @brief Get configuration from @p driver
*
* @param driver USB mux driver description in format (compatible, config)
*/
-#define USB_MUX_DRIVER_GET_CONFIG(driver) GET_ARG_N(2, __DEBRACKET driver)
+#define USB_MUX_DRIVER_GET_CONFIG(driver) GET_ARG_N(2, __DEBRACKET driver)
/**
- * @brief USB mux port number based on parent node in DTS
+ * @brief Name of USB mux chain structure for given port and place in chain.
+ * Note, that root of chain is not referred by this name, but
+ * usb_muxes[@p port_id].
*
- * @param port_id USBC node ID
+ * @param idx Place in chain
+ * @param port_id USBC port id
*/
-#define USB_MUX_PORT(port_id) DT_REG_ADDR(port_id)
+#define USB_MUX_CHAIN_STRUCT_NAME(idx, port_id) \
+ DT_CAT4(USB_MUX_chain_port_, port_id, _mux_, idx)
/**
- * @brief Name of USB mux structure if node is not EMPTY. Note, that root of
- * chain is not referred by this name, but usb_muxes[USB_MUX_PORT(id)].
+ * @brief Declaration of USB mux chain structure for @p idx mux in @p port_id
+ * USB-C port's chain
+ *
+ * @param port_id USBC port ID (number)
+ * @param idx Place in chain
+ */
+#define USB_MUX_CHAIN_STRUCT_DECLARE(port_id, idx) \
+ MAYBE_CONST struct usb_mux_chain USB_MUX_CHAIN_STRUCT_NAME(idx, port_id)
+
+/**
+ * @brief Name of USB mux structure if node @p mux_id is not EMPTY.
*
* @param mux_id USB mux node ID
*/
-#define USB_MUX_STRUCT_NAME(mux_id) \
+#define USB_MUX_STRUCT_NAME(mux_id) \
COND_CODE_0(IS_EMPTY(mux_id), (DT_CAT(USB_MUX_NODE_, mux_id)), (EMPTY))
/**
* @brief USB muxes in chain should be constant only if configuration
* cannot change in runtime
*/
-#define MAYBE_CONST COND_CODE_1(CONFIG_PLATFORM_EC_USB_MUX_RUNTIME_CONFIG, \
- (), (const))
+#define MAYBE_CONST \
+ COND_CODE_1(CONFIG_PLATFORM_EC_USB_MUX_RUNTIME_CONFIG, (), (const))
/**
* @brief Declaration of USB mux structure
*
* @param mux_id USB mux node ID
*/
-#define USB_MUX_STRUCT_DECLARE(mux_id) \
+#define USB_MUX_STRUCT_DECLARE(mux_id) \
MAYBE_CONST struct usb_mux USB_MUX_STRUCT_NAME(mux_id)
/**
+ * @brief Declaration of USB mux board_init function
+ *
+ * @param mux_id USB mux node ID
+ */
+#define USB_MUX_CB_BOARD_INIT_DECLARE(mux_id) \
+ int DT_STRING_TOKEN(mux_id, board_init)(const struct usb_mux *);
+
+/**
+ * @brief Declaration of USB mux board_set function
+ *
+ * @param mux_id USB mux node ID
+ */
+#define USB_MUX_CB_BOARD_SET_DECLARE(mux_id) \
+ int DT_STRING_TOKEN(mux_id, board_set)(const struct usb_mux *, \
+ mux_state_t);
+
+/**
* @brief Get pointer by referencing @p name or NULL if @p name is EMPTY
*
* @param name Identifier to reference
*/
-#define USB_MUX_POINTER_OR_NULL(name) \
+#define USB_MUX_POINTER_OR_NULL(name) \
COND_CODE_0(IS_EMPTY(name), (&name), (NULL))
/**
* @brief Get node id of @p idx USB mux in chain
*
+ * @param chain_id USB mux chain node ID
* @param idx Position of USB mux in chain
- * @param port_id USBC node ID
*/
-#define USB_MUX_GET_CHAIN_N(idx, port_id) \
- DT_PHANDLE_BY_IDX(port_id, usb_muxes, idx)
+#define USB_MUX_GET_CHAIN_N(chain_id, idx) \
+ DT_PHANDLE_BY_IDX(chain_id, usb_muxes, idx)
/**
- * @brief Get node id of next USB mux in chain or EMPTY if it is last mux
+ * @brief Get next USB mux chain structure name or EMPTY if it is last mux
*
- * @param port_id USBC node ID
+ * @param chain_id USB mux chain node ID
* @param idx Position of USB mux in chain
*/
-#define USB_MUX_NEXT(port_id, idx) \
- GET_ARG_N(2, GET_ARGS_LESS_N(idx, \
- LISTIFY(DT_PROP_LEN(port_id, usb_muxes), \
- USB_MUX_GET_CHAIN_N, (,), port_id)), \
+#define USB_MUX_CHAIN_NEXT_NAME(chain_id, idx) \
+ GET_ARG_N(2, \
+ GET_ARGS_LESS_N(idx, \
+ LISTIFY(DT_PROP_LEN(chain_id, usb_muxes), \
+ USB_MUX_CHAIN_STRUCT_NAME, (, ), \
+ USBC_PORT(chain_id))), \
EMPTY)
/**
* @brief Get pointer to next USB mux in chain or NULL if it is last mux
*
- * @param port_id USBC node ID
+ * @param chain_id USB mux chain node ID
* @param idx Position of USB mux in chain
*/
-#define USB_MUX_NEXT_POINTER(port_id, idx) \
- USB_MUX_POINTER_OR_NULL(USB_MUX_STRUCT_NAME(USB_MUX_NEXT(port_id, idx)))
+#define USB_MUX_CHAIN_NEXT_POINTER(chain_id, idx) \
+ USB_MUX_POINTER_OR_NULL(USB_MUX_CHAIN_NEXT_NAME(chain_id, idx))
+
+/**
+ * @brief Get pointer to USB mux that is @p idx in chain @p chain_id
+ *
+ * @param chain_id USB mux chain node ID
+ * @param idx Position of USB mux in chain
+ */
+#define USB_MUX_POINTER(chain_id, idx) \
+ &USB_MUX_STRUCT_NAME(USB_MUX_GET_CHAIN_N(chain_id, idx))
/**
* @brief Generate pointer to function from @p cb_name property or NULL
@@ -119,217 +169,335 @@
* @param mux_id USB mux node ID
* @param cb_name Name of property with callback function
*/
-#define USB_MUX_CALLBACK_OR_NULL(mux_id, cb_name) \
+#define USB_MUX_CALLBACK_OR_NULL(mux_id, cb_name) \
USB_MUX_POINTER_OR_NULL(DT_STRING_TOKEN_OR(mux_id, cb_name, EMPTY))
/**
* @brief Set struct usb_mux fields common for all USB muxes and alter flags
*
* @param mux_id USB mux node ID
- * @param port_id USBC node ID
- * @param idx Position of USB mux in chain
* @param flags_mask Mask for bits that should be igonred in flags property
* @param flags_val Value that should be used instead for masked bits
*/
-#define USB_MUX_COMMON_FIELDS_WITH_FLAGS(mux_id, port_id, idx, \
- flags_mask, flags_val) \
- .usb_port = USB_MUX_PORT(port_id), \
- .next_mux = USB_MUX_NEXT_POINTER(port_id, idx), \
- .board_init = USB_MUX_CALLBACK_OR_NULL(mux_id, board_init), \
- .board_set = USB_MUX_CALLBACK_OR_NULL(mux_id, board_set), \
+#define USB_MUX_COMMON_FIELDS_WITH_FLAGS(mux_id, flags_mask, flags_val) \
+ .usb_port = USB_MUX_PORT(mux_id), \
+ .board_init = USB_MUX_CALLBACK_OR_NULL(mux_id, board_init), \
+ .board_set = USB_MUX_CALLBACK_OR_NULL(mux_id, board_set), \
.flags = (DT_PROP(mux_id, flags) & ~(flags_mask)) | (flags_val)
/**
* @brief Set struct usb_mux fields common for all USB muxes
*
* @param mux_id USB mux node ID
- * @param port_id USBC node ID
- * @param idx Position of USB mux in chain
*/
-#define USB_MUX_COMMON_FIELDS(mux_id, port_id, idx) \
- USB_MUX_COMMON_FIELDS_WITH_FLAGS(mux_id, port_id, idx, 0, 0)
+#define USB_MUX_COMMON_FIELDS(mux_id) \
+ USB_MUX_COMMON_FIELDS_WITH_FLAGS(mux_id, 0, 0)
/**
- * @brief Expands to 1 if @p mux_id has @p compat compatible. It is required
- * to makes sure that @p compat is expanded before DT_NODE_HAS_COMPAT
+ * @brief Declare USB mux structure
*
* @param mux_id USB mux node ID
- * @param compat USB mux driver compatible
+ * @param conf Driver configuration function
*/
-#define USB_MUX_IS_COMPATIBLE(mux_id, compat) \
- DT_NODE_HAS_COMPAT(mux_id, compat)
+#define USB_MUX_DECLARE(mux_id, conf) extern USB_MUX_STRUCT_DECLARE(mux_id);
/**
- * @brief Expands to @p driver config if @p mux_id is compatible with @p driver
+ * @brief Define USB mux structure using driver USB_MUX_CONFIG_* macro
*
- * @param driver USB mux driver description in format (compatible, config)
* @param mux_id USB mux node ID
+ * @param conf Driver configuration function
*/
-#define USB_MUX_DRIVER_CONFIG_IF_COMPAT(driver, mux_id) \
- COND_CODE_1(USB_MUX_IS_COMPATIBLE( \
- mux_id, USB_MUX_DRIVER_GET_COMPAT(driver)), \
- (USB_MUX_DRIVER_GET_CONFIG(driver)), ())
+#define USB_MUX_DEFINE(mux_id, conf) \
+ USB_MUX_STRUCT_DECLARE(mux_id) = conf(mux_id);
/**
- * @brief Find driver from USB_MUX_DRIVERS that is compatible with @p mux_id
+ * @brief Call @p cb_op if @p mux_id has @p cb_prop property
*
* @param mux_id USB mux node ID
+ * @param cb_prop The callback property name
+ * @param cb_op Operation to perform on USB muxes
*/
-#define USB_MUX_FIND_DRIVER_CONFIG(mux_id) \
- FOR_EACH_FIXED_ARG(USB_MUX_DRIVER_CONFIG_IF_COMPAT, (), mux_id, \
- USB_MUX_DRIVERS)
+#define USB_MUX_CB_DECLARE_IF_EXIST(mux_id, cb_prop, cb_op) \
+ COND_CODE_1(DT_NODE_HAS_PROP(mux_id, cb_prop), (cb_op(mux_id)), ())
/**
- * @brief Get driver configuration macro for @p mux_id and call @p op
+ * @brief Declare USB mux board_set function @p mux_id has board_set property
*
* @param mux_id USB mux node ID
- * @param port_id USBC node ID
- * @param idx Position of USB mux in chain
- * @param op Operation to perform on USB muxes
+ * @param conf Driver configuration function
*/
-#define USB_MUX_CALL_OP(mux_id, port_id, idx, op) \
- op(mux_id, port_id, idx, USB_MUX_FIND_DRIVER_CONFIG(mux_id))
+#define USB_MUX_CB_BOARD_SET_DECLARE_IF_EXISTS(mux_id, conf) \
+ USB_MUX_CB_DECLARE_IF_EXIST(mux_id, board_set, \
+ USB_MUX_CB_BOARD_SET_DECLARE)
/**
- * @brief Get USB mux node ID and call USB_MUX_CALL_OP
+ * @brief Declare USB mux board_init function @p mux_id has board_init property
*
- * @param port_id USBC node ID
- * @param idx Position of USB mux in chain
- * @param op Operation to perform on USB muxes
+ * @param mux_id USB mux node ID
+ * @param conf Driver configuration function
*/
-#define USB_MUX_DO(port_id, idx, op) \
- USB_MUX_CALL_OP(USB_MUX_GET_CHAIN_N(idx, port_id), port_id, idx, op)
+#define USB_MUX_CB_BOARD_INIT_DECLARE_IF_EXISTS(mux_id, conf) \
+ USB_MUX_CB_DECLARE_IF_EXIST(mux_id, board_init, \
+ USB_MUX_CB_BOARD_INIT_DECLARE)
/**
- * @brief Declare USB mux structure
+ * @brief Call @p op operation for each node that is compatible with @p driver
*
- * @param mux_id USB mux node ID
- * @param port_id USBC node ID
- * @param idx Position of USB mux in chain
- * @param conf Driver configuration function
+ * @param driver USB mux driver description in format (compatible, config)
+ * @param op Operation to perform on each USB mux. Should accept mux node ID and
+ * driver config as arguments.
*/
-#define USB_MUX_DECLARE(mux_id, port_id, idx, conf) \
- extern USB_MUX_STRUCT_DECLARE(mux_id);
+#define USB_MUX_DRIVER_CONFIG(driver, op) \
+ DT_FOREACH_STATUS_OKAY_VARGS(USB_MUX_DRIVER_GET_COMPAT(driver), op, \
+ USB_MUX_DRIVER_GET_CONFIG(driver))
/**
- * @brief Define USB mux structure using driver USB_MUX_CONFIG_* macro
+ * @brief Call @p op operation for each USB mux node that is compatible with
+ * any driver from the USB_MUX_DRIVERS list.
+ * DT_FOREACH_STATUS_OKAY_VARGS() macro can not be used in @p op
*
- * @param mux_id USB mux node ID
- * @param port_id USBC node ID
- * @param idx Position of USB mux in chain
- * @param conf Driver configuration function
+ * @param op Operation to perform on each USB mux. Should accept mux node ID and
+ * driver config as arguments.
*/
-#define USB_MUX_DEFINE(mux_id, port_id, idx, conf) \
- USB_MUX_STRUCT_DECLARE(mux_id) = conf(mux_id, port_id, idx);
+#define USB_MUX_FOREACH_MUX_DT_VARGS(op) \
+ FOR_EACH_FIXED_ARG(USB_MUX_DRIVER_CONFIG, (), op, USB_MUX_DRIVERS)
/**
- * @brief Define entry of usb_muxes array using driver USB_MUX_CONFIG_* macro
+ * @brief Convert @p mux_id and @p conf pair into USB_MUX_LIST entry
*
* @param mux_id USB mux node ID
- * @param port_id USBC node ID
- * @param idx Position of USB mux in chain
* @param conf Driver configuration function
*/
-#define USB_MUX_ARRAY(mux_id, port_id, idx, conf) \
- [USB_MUX_PORT(port_id)] = conf(mux_id, port_id, idx),
+#define USB_MUX_TO_LIST(mux_id, conf) , (mux_id, conf)
+
+/**
+ * @brief List of all USB muxes with config matched by compatible. List is in
+ * format (mux1_id, conf1) , (mux2_id, conf2) ...
+ */
+#define USB_MUX_LIST \
+ LIST_DROP_EMPTY(USB_MUX_FOREACH_MUX_DT_VARGS(USB_MUX_TO_LIST))
+
+/**
+ * @brief Call @p op with @p args arguments
+ *
+ * @param op Operation to perform on USB mux. Should accept mux node ID and
+ * driver config as arguments.
+ * @param args Arguments for @p op. Should be in format (mux_id, conf).
+ */
+#define USB_MUX_CALL_OP(args, op) op args
/**
- * @brief Call @p op with first mux in chain
+ * @brief Call @p op operation for each USB mux node from USB_MUX_LIST. This is
+ * like USB_MUX_FOREACH_MUX_DT_VARGS(), except
+ * DT_FOREACH_STATUS_OKAY_VARGS() macro can be used in @p op
*
- * @param port_id USBC node ID
- * @param op Operation to perform on USB mux first in chain. Needs to accept
- * USB mux node ID, USBC port node ID, position in chain, and driver
- * config as arguments.
+ * @param op Operation to perform on each USB mux. Should accept mux node ID and
+ * driver config as arguments.
*/
-#define USB_MUX_FIRST(port_id, op) \
- USB_MUX_DO(port_id, 0, op)
+#define USB_MUX_FOREACH_MUX(op) \
+ COND_CODE_0( \
+ IS_EMPTY(USB_MUX_LIST), \
+ (FOR_EACH_FIXED_ARG(USB_MUX_CALL_OP, (), op, USB_MUX_LIST)), \
+ (EMPTY))
/**
- * @brief Call USB_MUX_DO if @p idx is not 0 (is not first mux in chain)
+ * @brief Initialise chain structure for @p idx mux
*
- * @param port_id USBC node ID
+ * @param chain_id Chain DTS node ID
+ * @param idx USB mux index
+ */
+#define USB_MUX_CHAIN_STRUCT_INIT(chain_id, idx) \
+ { \
+ .mux = USB_MUX_POINTER(chain_id, idx), \
+ .next = USB_MUX_CHAIN_NEXT_POINTER(chain_id, idx), \
+ }
+
+/**
+ * @brief Helper macro to set chain structure value for @p idx mux
+ *
+ * @param chain_id Chain DTS node ID
+ * @param idx USB mux index
+ */
+#define USB_MUX_CHAIN_STRUCT_SET(chain_id, idx) \
+ (struct usb_mux_chain) USB_MUX_CHAIN_STRUCT_INIT(chain_id, idx)
+
+/**
+ * @brief Declaration of USB mux chain extern structure for @p idx mux in
+ * @p chain_id chain
+ *
+ * @param chain_id USB mux chain node ID
+ * @param idx Place in chain
+ */
+#define USB_MUX_CHAIN_STRUCT_DECLARE_EXTERN_OP(chain_id, idx) \
+ extern USB_MUX_CHAIN_STRUCT_DECLARE(USBC_PORT(chain_id), idx);
+
+/**
+ * @brief Declaration of USB mux chain structure for @p idx mux in @p chain_id
+ * chain
+ *
+ * @param chain_id USB mux chain node ID
+ * @param idx Place in chain
+ */
+#define USB_MUX_CHAIN_STRUCT_DECLARE_OP(chain_id, idx) \
+ USB_MUX_CHAIN_STRUCT_DECLARE(USBC_PORT(chain_id), idx);
+
+/**
+ * @brief Definition of USB mux chain structure for @p idx mux in @p chain_id
+ * chain
+ *
+ * @param chain_id USB mux chain node ID
+ * @param idx Place in chain
+ */
+#define USB_MUX_CHAIN_STRUCT_DEFINE_OP(chain_id, idx) \
+ USB_MUX_CHAIN_STRUCT_DECLARE(USBC_PORT(chain_id), idx) = \
+ USB_MUX_CHAIN_STRUCT_INIT(chain_id, idx);
+
+/**
+ * @brief Call @p op if @p idx is not 0 (is not the root mux of chain)
+ *
+ * @param chain_id Chain DTS node ID
* @param unused2 This argument is expected by DT_FOREACH_PROP_ELEM_VARGS
* @param idx Position of USB mux in chain
* @param op Operation to perform on USB muxes
*/
-#define USB_MUX_DO_SKIP_FIRST(port_id, unused2, idx, op) \
- COND_CODE_1(UTIL_BOOL(idx), (USB_MUX_DO(port_id, idx, op)), ())
+#define USB_MUX_SKIP_ROOT(chain_id, unused2, idx, op) \
+ COND_CODE_1(UTIL_BOOL(idx), (op(chain_id, idx)), ())
+
+/**
+ * @brief Call @p op for each mux in @p chain_id chain except the root mux
+ *
+ * @param chain_id Chain DTS node ID
+ * @param op Operation to perform on USB muxes
+ */
+#define USB_MUX_FOREACH_NO_ROOT_MUX(chain_id, op) \
+ DT_FOREACH_PROP_ELEM_VARGS(chain_id, usb_muxes, USB_MUX_SKIP_ROOT, op)
+
+/**
+ * @brief Create usb_muxes array entry for @p chain_id chain
+ *
+ * @param chain_id Chain DTS node ID
+ */
+#define USB_MUX_DEFINE_ROOT_MUX(chain_id) \
+ [USBC_PORT(chain_id)] = USB_MUX_CHAIN_STRUCT_INIT(chain_id, 0),
+
+/**
+ * @brief Call @p op only if chain @p chain_id is not alternative
+ *
+ * @param chain_id Chain DTS node ID
+ * @param op Operation to perform on main USB mux chain
+ * @param ... Arguments to pass to the @p op operation
+ */
+#define USB_MUX_FOR_MAIN_CHAIN(chain_id, op, ...) \
+ COND_CODE_0(DT_PROP(chain_id, alternative_chain), \
+ (op(chain_id, ##__VA_ARGS__)), ())
/**
- * @brief Call @p op with every mux in chain expect the first one
+ * @brief Call @p op for each USB mux chain
*
- * @param port_id USBC node ID
- * @param op Operation to perform on USB muxes. Needs to accept USB mux node
- * ID, USBC port node ID, position in chain, and driver config as
- * arguments.
+ * @param op Operation to perform on USB mux chain
*/
-#define USB_MUX_NO_FIRST(port_id, op) \
- DT_FOREACH_PROP_ELEM_VARGS(port_id, usb_muxes, \
- USB_MUX_DO_SKIP_FIRST, op)
+#define USB_MUX_FOREACH_CHAIN(op) \
+ DT_FOREACH_STATUS_OKAY(cros_ec_usb_mux_chain, op)
/**
- * @brief Call @p op if @p idx mux in chain has BB retimer compatible
+ * @brief Call @p op for each USB mux chain with arguments
*
- * @param port_id USBC node ID
+ * @param op Operation to perform on USB mux chain
+ * @param ... Arguments to pass to the @p op operation
+ */
+#define USB_MUX_FOREACH_CHAIN_VARGS(op, ...) \
+ DT_FOREACH_STATUS_OKAY_VARGS(cros_ec_usb_mux_chain, op, __VA_ARGS__)
+
+/**
+ * @brief Construct first half of conditional expression (?:) that evaluates to
+ * @p chain_id USB port if @p idx mux in @p chain_id is the same as
+ * @p mux_id
+ *
+ * @param chain_id USB mux chain node ID
* @param unused2 This argument is expected by DT_FOREACH_PROP_ELEM_VARGS
* @param idx Position of USB mux in chain
- * @param op Operation to perform on BB retimer
+ * @param mux_id USB mux node ID to compare with @p idx mux
*/
-#define USB_MUX_ONLY_BB_RETIMER(port_id, unused2, idx, op) \
- COND_CODE_1(USB_MUX_IS_COMPATIBLE( \
- USB_MUX_GET_CHAIN_N(idx, port_id), \
- BB_RETIMER_USB_MUX_COMPAT), \
- (op(USB_MUX_GET_CHAIN_N(idx, port_id), port_id, \
- idx, BB_RETIMER_CONTROLS_CONFIG)), ())
+#define USB_MUX_PORT_IF_SAME_NODES(chain_id, unused2, idx, mux_id) \
+ DT_SAME_NODE(mux_id, USB_MUX_GET_CHAIN_N(chain_id, idx)) ? \
+ USBC_PORT(chain_id):
/**
- * @brief Call @p op with every BB retimer in chain
+ * @brief Compare @p mux_id with all muxes in @p chain_id
*
- * @param port_id USBC node ID
- * @param op Operation to perform on BB retimers. Needs to accept USB mux node
- * ID, USBC port node ID, position in chain, and driver config as
- * arguments.
+ * @param chain_id USB mux chain node ID
+ * @param mux_id USB mux node ID
*/
-#define USB_MUX_BB_RETIMERS(port_id, op) \
- DT_FOREACH_PROP_ELEM_VARGS(port_id, usb_muxes, \
- USB_MUX_ONLY_BB_RETIMER, op)
+#define USB_MUX_FIND_PORT(chain_id, mux_id) \
+ DT_FOREACH_PROP_ELEM_VARGS(chain_id, usb_muxes, \
+ USB_MUX_PORT_IF_SAME_NODES, mux_id)
/**
- * @brief If @p port_id has usb_muxes property, call @p op with every mux in
- * chain that passes @p filter
+ * @brief Get port for @p mux_id by looking for an usb mux chain where @p mux_id
+ * is present. If the mux is not present in any chain, this macro
+ * evaluate to -1.
+ *
+ * This expands to:
+ * (DT_DEP_ORD(mux_id) == DT_DEP_ORD(USB_MUX_GET_CHAIN_N(chain1_id, 0))) ?
+ * USBC_PORT(chain1_id) :
+ * (DT_DEP_ORD(mux_id) == DT_DEP_ORD(USB_MUX_GET_CHAIN_N(chain1_id, 1))) ?
+ * USBC_PORT(chain1_id) :
+ * ...
+ * (DT_DEP_ORD(mux_id) == DT_DEP_ORD(USB_MUX_GET_CHAIN_N(chain1_id, n))) ?
+ * USBC_PORT(chain1_id) :
+ * (DT_DEP_ORD(mux_id) == DT_DEP_ORD(USB_MUX_GET_CHAIN_N(chain2_id, 0))) ?
+ * USBC_PORT(chain2_id) :
+ * ...
+ * (DT_DEP_ORD(mux_id) == DT_DEP_ORD(USB_MUX_GET_CHAIN_N(chainm_id, k))) ?
+ * USBC_PORT(chainm_id) : (-1)
*
- * @param port_id USBC node ID
- * @param filter Macro that should filter USB muxes and call @p op on them.
- * It has @p port_id and @p op as arguments. It is called
- * only for @p port_id that has usb_muxes property.
- * @param op Operation to perform on USB muxes. Needs to accept USB mux node
- * ID, USBC port node ID, position in chain, and driver config as
- * arguments.
+ * @param mux_id USB mux node ID
+ */
+#define USB_MUX_PORT(mux_id) \
+ (USB_MUX_FOREACH_CHAIN_VARGS(USB_MUX_FIND_PORT, mux_id)(-1))
+
+/**
+ * @brief Set usb_mux_chain structure for mux @p idx in chain @p chain_id
+ *
+ * @param chain_id Alternative USB mux chain node ID
+ * @param idx Position of the mux in chain
+ */
+#define USB_MUX_SET_ALTERNATIVE(chain_id, idx) \
+ USB_MUX_CHAIN_STRUCT_NAME(idx, USBC_PORT(chain_id)) = \
+ USB_MUX_CHAIN_STRUCT_SET(chain_id, idx);
+
+/**
+ * @brief Enable alternative USB mux chain
+ *
+ * @param chain_id Alternative USB mux chain node ID
*/
-#define USB_MUX_USBC_PORT_HAS_MUXES(port_id, filter, op) \
- COND_CODE_1(DT_NODE_HAS_PROP(port_id, usb_muxes), \
- (filter(port_id, op)), ())
+#define USB_MUX_ENABLE_ALTERNATIVE_NODE(chain_id) \
+ do { \
+ usb_muxes[USBC_PORT(chain_id)] = \
+ USB_MUX_CHAIN_STRUCT_SET(chain_id, 0); \
+ USB_MUX_FOREACH_NO_ROOT_MUX(chain_id, USB_MUX_SET_ALTERNATIVE) \
+ } while (0)
/**
- * @brief For every USBC port that has muxes, call @p op with every mux in chain
- * that passes @p filter
+ * @brief Enable alternative USB mux chain
*
- * @param filter Macro that should filter USB muxes and call @p op on them.
- * It has USBC port node ID and @p op as arguments. It is called
- * only for USBC ports that have usb_muxes property.
- * @param op Operation to perform on USB muxes. Needs to accept USB mux node
- * ID, USBC port node ID, position in chain, and driver config as
- * arguments.
+ * @param nodelabel Label of alternative USB mux chain
*/
-#define USB_MUX_FOREACH_USBC_PORT(filter, op) \
- DT_FOREACH_STATUS_OKAY_VARGS(named_usbc_port, \
- USB_MUX_USBC_PORT_HAS_MUXES, \
- filter, op)
+#define USB_MUX_ENABLE_ALTERNATIVE(nodelabel) \
+ USB_MUX_ENABLE_ALTERNATIVE_NODE(DT_NODELABEL(nodelabel))
/**
* Forward declare all usb_mux structures e.g.
* MAYBE_CONST struct usb_mux USB_MUX_NODE_<node_id>;
*/
-USB_MUX_FOREACH_USBC_PORT(USB_MUX_NO_FIRST, USB_MUX_DECLARE)
+USB_MUX_FOREACH_MUX(USB_MUX_DECLARE)
+
+/**
+ * Forward declare all usb_mux_chain structures e.g.
+ * extern MAYBE_CONST struct usb_mux_chain
+ * USB_MUX_chain_port_<node_id>_mux_<position_id>;
+ */
+USB_MUX_FOREACH_CHAIN_VARGS(USB_MUX_FOREACH_NO_ROOT_MUX,
+ USB_MUX_CHAIN_STRUCT_DECLARE_EXTERN_OP)
#endif /* ZEPHYR_CHROME_USBC_USB_MUXES_H */
diff --git a/zephyr/shim/include/usbc/utils.h b/zephyr/shim/include/usbc/utils.h
index 49b9aa4b71..53e9a34856 100644
--- a/zephyr/shim/include/usbc/utils.h
+++ b/zephyr/shim/include/usbc/utils.h
@@ -1,22 +1,19 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef __CROS_EC_ZEPHYR_SHIM_USBC_UTIL
-
/*
* Enable interrupt from the `irq` property of an instance's node.
*
* @param inst: instance number
*/
-#define BC12_GPIO_ENABLE_INTERRUPT(inst) \
- IF_ENABLED(DT_INST_NODE_HAS_PROP(inst, irq), \
- (gpio_enable_dt_interrupt( \
- GPIO_INT_FROM_NODE(DT_INST_PHANDLE(inst, irq)));\
- ) \
- )
+#define BC12_GPIO_ENABLE_INTERRUPT(inst) \
+ IF_ENABLED(DT_INST_NODE_HAS_PROP(inst, irq), \
+ (gpio_enable_dt_interrupt( \
+ GPIO_INT_FROM_NODE(DT_INST_PHANDLE(inst, irq)));))
/*
* Get the port number from a child of `named-usbc-port` node.
@@ -26,11 +23,17 @@
#define USBC_PORT(id) DT_REG_ADDR(DT_PARENT(id))
/*
+ * Get the port number from a `named-usbc-port` node.
+ *
+ * @param id: `named-usbc-port` node id
+ */
+#define USBC_PORT_NEW(id) DT_REG_ADDR(id)
+
+/*
* Get the port number from a child of `named-usbc-port` node.
*
* @param inst: instance number of the node
*/
#define USBC_PORT_FROM_INST(inst) USBC_PORT(DT_DRV_INST(inst))
-
#endif /* __CROS_EC_ZEPHYR_SHIM_USBC_UTIL */
diff --git a/zephyr/shim/include/usbc/virtual_usb_mux.h b/zephyr/shim/include/usbc/virtual_usb_mux.h
index 5f4c2fb466..bbb2d8730e 100644
--- a/zephyr/shim/include/usbc/virtual_usb_mux.h
+++ b/zephyr/shim/include/usbc/virtual_usb_mux.h
@@ -1,4 +1,4 @@
-/* Copyright 2022 The Chromium OS Authors. All rights reserved.
+/* Copyright 2022 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
@@ -8,13 +8,13 @@
#include "usb_mux.h"
-#define VIRTUAL_USB_MUX_COMPAT cros_ec_usbc_mux_virtual
+#define VIRTUAL_USB_MUX_COMPAT cros_ec_usbc_mux_virtual
-#define USB_MUX_CONFIG_VIRTUAL(mux_id, port_id, idx) \
- { \
- USB_MUX_COMMON_FIELDS(mux_id, port_id, idx), \
- .driver = &virtual_usb_mux_driver, \
- .hpd_update = &virtual_hpd_update, \
+#define USB_MUX_CONFIG_VIRTUAL(mux_id) \
+ { \
+ USB_MUX_COMMON_FIELDS(mux_id), \
+ .driver = &virtual_usb_mux_driver, \
+ .hpd_update = &virtual_hpd_update, \
}
#endif /* __ZEPHYR_SHIM_VIRTUAL_USB_MUX_H */