diff options
-rw-r--r-- | zephyr/shim/include/usbc/bb_retimer_usb_mux.h | 78 | ||||
-rw-r--r-- | zephyr/shim/src/usb_muxes.c | 3 |
2 files changed, 73 insertions, 8 deletions
diff --git a/zephyr/shim/include/usbc/bb_retimer_usb_mux.h b/zephyr/shim/include/usbc/bb_retimer_usb_mux.h index aa15c9f5f2..64e1e2693d 100644 --- a/zephyr/shim/include/usbc/bb_retimer_usb_mux.h +++ b/zephyr/shim/include/usbc/bb_retimer_usb_mux.h @@ -19,14 +19,27 @@ .i2c_addr_flags = DT_REG_ADDR(mux_id), \ } -#define BB_RETIMER_CONTROLS_CONFIG(mux_id) \ - { \ - .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), \ } /** @@ -44,4 +57,53 @@ 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/src/usb_muxes.c b/zephyr/shim/src/usb_muxes.c index d9f14d0c67..71dc66f76a 100644 --- a/zephyr/shim/src/usb_muxes.c +++ b/zephyr/shim/src/usb_muxes.c @@ -99,6 +99,9 @@ USB_MUX_FOREACH_MUX(USB_MUX_DEFINE) /* Create bb_controls only if BB or HB retimer driver is enabled */ #if defined(CONFIG_PLATFORM_EC_USBC_RETIMER_INTEL_BB) || \ defined(CONFIG_PLATFORM_EC_USBC_RETIMER_INTEL_HB) + +BB_RETIMER_CHECK_SAME_CONTROLS(BB_RETIMER_INSTANCES_LIST) + /** * @brief bb_controls array should be constant only if configuration cannot * change in runtime |