diff options
-rw-r--r-- | common/usb_common.c | 12 | ||||
-rw-r--r-- | include/usb_pd.h | 9 |
2 files changed, 21 insertions, 0 deletions
diff --git a/common/usb_common.c b/common/usb_common.c index fbeb48c8d1..6fde61cfab 100644 --- a/common/usb_common.c +++ b/common/usb_common.c @@ -307,6 +307,18 @@ __overridable uint8_t board_get_usb_pd_port_count(void) return CONFIG_USB_PD_PORT_MAX_COUNT; } +__overridable bool board_is_usb_pd_port_present(int port) +{ + /* + * Use board_get_usb_pd_port_count() instead of checking + * CONFIG_USB_PD_PORT_MAX_COUNT directly here for legacy boards + * that implement board_get_usb_pd_port_count() but do not + * implement board_is_usb_pd_port_present(). + */ + + return (port >= 0) && (port < board_get_usb_pd_port_count()); +} + int pd_get_retry_count(int port, enum tcpm_transmit_type type) { /* PD 3.0 6.7.7: nRetryCount = 2; PD 2.0 6.6.9: nRetryCount = 3 */ diff --git a/include/usb_pd.h b/include/usb_pd.h index a31fefbc3d..71d2449753 100644 --- a/include/usb_pd.h +++ b/include/usb_pd.h @@ -2899,6 +2899,15 @@ __override_proto uint8_t get_dp_pin_mode(int port); */ __override_proto uint8_t board_get_usb_pd_port_count(void); +/** + * Return true if specified PD port is present. This is similar to + * checking CONFIG_USB_PD_PORT_MAX_COUNT but handles sparse numbering. + * + * @param port USB-C port number + * + * @return true if port is present. + */ +__override_proto bool board_is_usb_pd_port_present(int port); /** * Resets external PD chips including TCPCs and MCUs. |