From cff8bb2687bc373bce84e13e622585e5bc741eb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Barna=C5=9B?= Date: Wed, 23 Aug 2023 14:15:40 +0200 Subject: [PATCH] usbc: check if sampling CC lines were successful MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the get_cc function returns error, the CC lines should be considered as open. It may happen either due to some chip malfunction or chip going into sleep mode and needing time to reinitialize. TCPC should only go to sleep if there is no partner attaches, so in case of this error, the lines should be considered as disconnected. Signed-off-by: Michał Barnaś --- subsys/usb/usb_c/usbc_tc_common.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/subsys/usb/usb_c/usbc_tc_common.c b/subsys/usb/usb_c/usbc_tc_common.c index 605fad0390..88749b51d8 100644 --- a/subsys/usb/usb_c/usbc_tc_common.c +++ b/subsys/usb/usb_c/usbc_tc_common.c @@ -70,7 +70,14 @@ void tc_run(const struct device *dev, const int32_t dpm_request) } /* Sample CC lines */ - tcpc_get_cc(tcpc, &tc->cc1, &tc->cc2); + if (tcpc_get_cc(tcpc, &tc->cc1, &tc->cc2) != 0) { + /* If this function fails, it may mean that the TCPC is in sleep mode or + * the communication with TCPC has failed, so we can assume that the CC + * lines are open or existing connection is faulty. + */ + tc->cc1 = TC_CC_VOLT_OPEN; + tc->cc2 = TC_CC_VOLT_OPEN; + } /* Detect polarity */ tc->cc_polarity = (tc->cc1 > tc->cc2) ? TC_POLARITY_CC1 : TC_POLARITY_CC2;