summaryrefslogtreecommitdiff
path: root/common/usb_pd_protocol.c
diff options
context:
space:
mode:
authorParth Malkan <parthmalkan@google.com>2021-08-10 21:54:59 +0000
committerCommit Bot <commit-bot@chromium.org>2021-09-24 22:54:51 +0000
commit06d89b033065d9c96f4a6e53129b22b912fae224 (patch)
tree34c7038c6fe35b915db34d42aa7112be5a5e095f /common/usb_pd_protocol.c
parentd4938b281fede972db577180efb791a47c47140b (diff)
downloadchrome-ec-06d89b033065d9c96f4a6e53129b22b912fae224.tar.gz
SSFC: Framework to support two charger sources
Many platforms have requirements to support more than one charge source (eg. pirika). It can't be supported by just enabling two different CONFIGS as that can lead to conflicts. Eg.USD_PD_VBUS_DETECT_TCPC vs USB_PD_VBUS_DETECT_DISCHARGE. This change provides a framework that supports two different charger sources in the same build. Please see the CL for relevant logs. BRANCH=None BUG=b:194375840 TEST=make -j buildall Signed-off-by: Parth Malkan <parthmalkan@google.com> Change-Id: I309cc5930233983e615d90a4290fc749abf7aa2d Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3088232 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'common/usb_pd_protocol.c')
-rw-r--r--common/usb_pd_protocol.c76
1 files changed, 42 insertions, 34 deletions
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index 07b50363b9..abf75e8004 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -29,6 +29,7 @@
#include "usb_common.h"
#include "usb_mux.h"
#include "usb_pd.h"
+#include "usb_pd_flags.h"
#include "usb_pd_tcpm.h"
#include "usb_pd_tcpc.h"
#include "usbc_ocp.h"
@@ -1570,10 +1571,10 @@ static void handle_data_request(int port, uint32_t head,
if ((pd[port].task_state == PD_STATE_SNK_DISCOVERY)
|| (pd[port].task_state == PD_STATE_SNK_TRANSITION)
|| (pd[port].task_state == PD_STATE_SNK_REQUESTED)
-#ifdef CONFIG_USB_PD_VBUS_DETECT_NONE
- || (pd[port].task_state ==
- PD_STATE_SNK_HARD_RESET_RECOVER)
-#endif
+ || ((get_usb_pd_vbus_detect() ==
+ USB_PD_VBUS_DETECT_NONE)
+ && (pd[port].task_state ==
+ PD_STATE_SNK_HARD_RESET_RECOVER))
|| (pd[port].task_state == PD_STATE_SNK_READY)) {
#ifdef CONFIG_USB_PD_REV30
/*
@@ -4098,52 +4099,58 @@ void pd_task(void *u)
case PD_STATE_SNK_HARD_RESET_RECOVER:
if (pd[port].last_state != pd[port].task_state)
pd[port].flags |= PD_FLAGS_CHECK_IDENTITY;
-#ifdef CONFIG_USB_PD_VBUS_DETECT_NONE
- /*
- * Can't measure vbus state so this is the maximum
- * recovery time for the source.
- */
- if (pd[port].last_state != pd[port].task_state)
- set_state_timeout(port, get_time().val +
+
+ if (get_usb_pd_vbus_detect() ==
+ USB_PD_VBUS_DETECT_NONE) {
+ /*
+ * Can't measure vbus state so this is the
+ * maximum recovery time for the source.
+ */
+ if (pd[port].last_state != pd[port].task_state)
+ set_state_timeout(port, get_time().val +
PD_T_SAFE_0V +
PD_T_SRC_RECOVER_MAX +
PD_T_SRC_TURN_ON,
PD_STATE_SNK_DISCONNECTED);
-#else
- /* Wait for VBUS to go low and then high*/
- if (pd[port].last_state != pd[port].task_state) {
- snk_hard_reset_vbus_off = 0;
- set_state_timeout(port,
+ } else {
+#ifndef CONFIG_USB_PD_VBUS_DETECT_NONE
+ /* Wait for VBUS to go low and then high*/
+ if (pd[port].last_state !=
+ pd[port].task_state) {
+ snk_hard_reset_vbus_off = 0;
+ set_state_timeout(port,
get_time().val +
PD_T_SAFE_0V,
hard_reset_count <
PD_HARD_RESET_COUNT ?
PD_STATE_HARD_RESET_SEND :
PD_STATE_SNK_DISCOVERY);
- }
+ }
- if (!pd_is_vbus_present(port) &&
- !snk_hard_reset_vbus_off) {
- /* VBUS has gone low, reset timeout */
- snk_hard_reset_vbus_off = 1;
- set_state_timeout(port,
+ if (!pd_is_vbus_present(port) &&
+ !snk_hard_reset_vbus_off) {
+ /* VBUS has gone low, reset timeout */
+ snk_hard_reset_vbus_off = 1;
+ set_state_timeout(port,
get_time().val +
PD_T_SRC_RECOVER_MAX +
PD_T_SRC_TURN_ON,
PD_STATE_SNK_DISCONNECTED);
- }
- if (pd_is_vbus_present(port) &&
- snk_hard_reset_vbus_off) {
- /* VBUS went high again */
- set_state(port, PD_STATE_SNK_DISCOVERY);
- timeout = 10*MSEC;
- }
+ }
+ if (pd_is_vbus_present(port) &&
+ snk_hard_reset_vbus_off) {
+ /* VBUS went high again */
+ set_state(port, PD_STATE_SNK_DISCOVERY);
+ timeout = 10*MSEC;
+ }
- /*
- * Don't need to set timeout because VBUS changing
- * will trigger an interrupt and wake us up.
- */
+ /*
+ * Don't need to set timeout because VBUS
+ * changing will trigger an interrupt and
+ * wake us up.
+ */
#endif
+ }
break;
case PD_STATE_SNK_DISCOVERY:
/* Wait for source cap expired only if we are enabled */
@@ -4172,7 +4179,8 @@ void pd_task(void *u)
int batt_soc = usb_get_battery_soc();
if (batt_soc < CONFIG_USB_PD_RESET_MIN_BATT_SOC ||
- battery_get_disconnect_state() != BATTERY_NOT_DISCONNECTED)
+ battery_get_disconnect_state() !=
+ BATTERY_NOT_DISCONNECTED)
pd[port].flags |=
PD_FLAGS_SNK_WAITING_BATT;
else