ANDROID: usb: typec: tcpm: Add vendor hook to modify port src caps

Add a vendor hook to modify the port Source Capabilities. If the caps
are changed and the port state is feasible, start a Power Negotiation
AMS to update the current contract to the new one.

Bug: 201006190
Bug: 206108037
Bug: 271294543
Signed-off-by: Kyle Tso <kyletso@google.com>
Change-Id: I8b524242353781cb39b3ba85c6a75bd5a204ebcf
(cherry picked from commit 00e3210a2f)
This commit is contained in:
Kyle Tso
2021-11-06 00:44:36 +08:00
committed by Treehugger Robot
parent c8314fcb76
commit b499bac439
3 changed files with 35 additions and 1 deletions

View File

@@ -174,3 +174,4 @@ EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_typec_tcpci_override_toggling);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_rvh_typec_tcpci_get_vbus);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_typec_store_partner_src_caps);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_typec_tcpm_get_timer);
EXPORT_TRACEPOINT_SYMBOL_GPL(android_vh_typec_tcpm_modify_src_caps);

View File

@@ -5487,9 +5487,38 @@ static void tcpm_pd_event_handler(struct kthread_work *work)
}
if (events & TCPM_CC_EVENT) {
enum typec_cc_status cc1, cc2;
bool modified = false;
if (port->tcpc->get_cc(port->tcpc, &cc1, &cc2) == 0)
_tcpm_cc_change(port, cc1, cc2);
trace_android_vh_typec_tcpm_modify_src_caps(&port->nr_src_pdo,
&port->src_pdo, &modified);
if (modified) {
int ret;
switch (port->state) {
case SRC_UNATTACHED:
case SRC_ATTACH_WAIT:
case SRC_TRYWAIT:
tcpm_set_cc(port, tcpm_rp_cc(port));
break;
case SRC_SEND_CAPABILITIES:
case SRC_SEND_CAPABILITIES_TIMEOUT:
case SRC_NEGOTIATE_CAPABILITIES:
case SRC_READY:
case SRC_WAIT_NEW_CAPABILITIES:
port->caps_count = 0;
port->upcoming_state = SRC_SEND_CAPABILITIES;
ret = tcpm_ams_start(port, POWER_NEGOTIATION);
if (ret == -EAGAIN)
port->upcoming_state = INVALID_STATE;
break;
default:
break;
}
}
}
if (events & TCPM_FRS_EVENT) {
if (port->state == SNK_READY) {

View File

@@ -46,6 +46,10 @@ DECLARE_HOOK(android_vh_typec_store_partner_src_caps,
TP_PROTO(unsigned int *nr_source_caps, u32 (*source_caps)[]),
TP_ARGS(nr_source_caps, source_caps));
#endif /* _TRACE_HOOK_UFSHCD_H */
DECLARE_HOOK(android_vh_typec_tcpm_modify_src_caps,
TP_PROTO(unsigned int *nr_src_pdo, u32 (*src_pdo)[], bool *modified),
TP_ARGS(nr_src_pdo, src_pdo, modified));
#endif /* _TRACE_HOOK_TYPEC_H */
/* This part must be outside protection */
#include <trace/define_trace.h>