summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaveh Jalali <caveh@chromium.org>2021-02-17 02:46:43 -0800
committerCommit Bot <commit-bot@chromium.org>2021-02-24 23:52:43 +0000
commit38c6a96e4470b3a6afb276a862ec77c0265f5a40 (patch)
tree41d2b41e75cff2369bd8b791729db045c031e2d2
parent7a401a50478315bc37d84124f01b86b60fe8db22 (diff)
downloadchrome-ec-38c6a96e4470b3a6afb276a862ec77c0265f5a40.tar.gz
common: Add board_is_usb_pd_port_present function
This adds a new overridable function to check if a USB PD port exists on a system. This is preferred over using board_get_usb_pd_port_count() or CONFIG_USB_PD_PORT_MAX_COUNT because it handles sparse port numbering. The "missing" port no longer needs to be the highest numbered port and call sites no longer need to implement the special checks for this case. BRANCH=none BUG=b:173575131 TEST=buildall passes Change-Id: I3f74eddd99c6901b42ce05bab6f2bdd545127d1a Signed-off-by: Caveh Jalali <caveh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2700313 Commit-Queue: Keith Short <keithshort@chromium.org> Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
-rw-r--r--common/usb_common.c12
-rw-r--r--include/usb_pd.h9
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.