diff options
author | Yilun Lin <yllin@google.com> | 2018-08-16 16:41:53 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-08-23 13:21:07 -0700 |
commit | eab2576658393d15af7fc55e97e827951cafa05e (patch) | |
tree | a498e430be9420115c71a4140b884238b38b6737 /driver | |
parent | 599232ba9103d3b8a0df0f24792801b6734ded64 (diff) | |
download | chrome-ec-eab2576658393d15af7fc55e97e827951cafa05e.tar.gz |
tcpc/mt6370: Fix state debouncing when enable auto-toggling w/o battery.
mt6370 updates CC pin information to different registers according to
whether it is DRP toggling or not.
When DRP toggling: CC information will update to CC_STATUS 0x1D
When DRP not toggling: CC information will update to ROLE_CTRL 0x1D
However, there is a situation that when we are enabling
CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE: When we detach the battery,
and plug type-c port to boot EC, the type-c port is already connected,
before auto-toggling is on. mt6370 here updates CC information to
ROLE_CTRL 0x1D, rather than CC_STATUS. So here, we should determine where
to retrieve the CC information dynamically.
BRANCH=None
BUG=b:112113303
TEST=w/ battery: check state transition behaves correctly when sourcing
and sinking.
TEST=w/o battery: check state transition behaves correctly when sinking.
Change-Id: Icf9e39f68aedb43a8fceba5d31795126a433d547
Signed-off-by: Yilun Lin <yllin@google.com>
Reviewed-on: https://chromium-review.googlesource.com/1177465
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: Yilun Lin <yllin@chromium.org>
Reviewed-by: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r-- | driver/tcpm/mt6370.c | 24 | ||||
-rw-r--r-- | driver/tcpm/tcpci.h | 1 |
2 files changed, 14 insertions, 11 deletions
diff --git a/driver/tcpm/mt6370.c b/driver/tcpm/mt6370.c index a9881b34d1..c7414601a1 100644 --- a/driver/tcpm/mt6370.c +++ b/driver/tcpm/mt6370.c @@ -58,12 +58,11 @@ static int mt6370_init(int port) return rv; } -#ifndef CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE static int mt6370_get_cc(int port, int *cc1, int *cc2) { int status; int rv; - int role; + int role, is_snk; rv = tcpc_read(port, TCPC_REG_CC_STATUS, &status); @@ -87,24 +86,27 @@ static int mt6370_get_cc(int port, int *cc1, int *cc2) */ rv = tcpc_read(port, TCPC_REG_ROLE_CTRL, &role); - if (*cc1 != TYPEC_CC_VOLT_OPEN) - *cc1 |= (TCPC_REG_ROLE_CTRL_CC1(role) == TYPEC_CC_RD) << 2; - if (*cc2 != TYPEC_CC_VOLT_OPEN) - *cc2 |= (TCPC_REG_ROLE_CTRL_CC2(role) == TYPEC_CC_RD) << 2; + if (TCPC_REG_ROLE_CTRL_DRP(role)) + is_snk = TCPC_REG_CC_STATUS_TERM(status); + else + /* CC1/CC2 states are the same, checking one-side is enough. */ + is_snk = TCPC_REG_CC_STATUS_CC1(role) == TYPEC_CC_RD; + + if (is_snk) { + if (*cc1 != TYPEC_CC_VOLT_OPEN) + *cc1 |= 0x04; + if (*cc2 != TYPEC_CC_VOLT_OPEN) + *cc2 |= 0x04; + } return rv; } -#endif /* MT6370 is a TCPCI compatible port controller */ const struct tcpm_drv mt6370_tcpm_drv = { .init = &mt6370_init, .release = &tcpci_tcpm_release, -#ifdef CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE - .get_cc = &tcpci_tcpm_get_cc, -#else .get_cc = &mt6370_get_cc, -#endif #ifdef CONFIG_USB_PD_VBUS_DETECT_TCPC .get_vbus_level = &tcpci_tcpm_get_vbus_level, #endif diff --git a/driver/tcpm/tcpci.h b/driver/tcpm/tcpci.h index 877e510210..1af01d9b60 100644 --- a/driver/tcpm/tcpci.h +++ b/driver/tcpm/tcpci.h @@ -54,6 +54,7 @@ #define TCPC_REG_ROLE_CTRL 0x1a #define TCPC_REG_ROLE_CTRL_SET(drp, rp, cc1, cc2) \ ((drp) << 6 | (rp) << 4 | (cc2) << 2 | (cc1)) +#define TCPC_REG_ROLE_CTRL_DRP(reg) (((reg) & 0x40) >> 6) #define TCPC_REG_ROLE_CTRL_RP_MASK 0x30 #define TCPC_REG_ROLE_CTRL_RP(reg) (((reg) & TCPC_REG_ROLE_CTRL_RP_MASK) >> 4) #define TCPC_REG_ROLE_CTRL_CC2(reg) (((reg) & 0xc) >> 2) |