From ea077cccd9e5cf25176ab9082be438ac26823126 Mon Sep 17 00:00:00 2001 From: Denis Brockus Date: Mon, 27 Jul 2020 12:53:31 -0600 Subject: AOZ1380: initialize srcing/snking flags to reflect hardware The AOZ1380 always started off with not sinking and not sourcing. In a batteryless or dead battery condition this is not true. So making sure we start with an accurate state. BUG=b:162016100 BRANCH=none TEST=trembyle cold boot with only AC power Signed-off-by: Denis Brockus Change-Id: Ic542e52b3b8d715b7526e7e393ae4f4c40c721ac Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2321132 Tested-by: Denis Brockus Reviewed-by: Edward Hill Commit-Queue: Denis Brockus Auto-Submit: Denis Brockus --- driver/ppc/aoz1380.c | 11 +++++++++++ driver/tcpm/nct38xx.c | 2 ++ driver/tcpm/tcpci.c | 26 ++++++++++++++++++++++++++ driver/tcpm/tcpci.h | 3 +++ driver/tcpm/tcpm.h | 22 ++++++++++++++++++++++ include/usb_pd_tcpm.h | 22 ++++++++++++++++++++++ 6 files changed, 86 insertions(+) diff --git a/driver/ppc/aoz1380.c b/driver/ppc/aoz1380.c index 67ad00c5e8..42239dd168 100644 --- a/driver/ppc/aoz1380.c +++ b/driver/ppc/aoz1380.c @@ -37,8 +37,19 @@ static uint32_t flags[CONFIG_USB_PD_PORT_MAX_COUNT]; static int aoz1380_init(int port) { + int rv; + bool is_sinking, is_sourcing; + flags[port] = 0; + rv = tcpm_get_snk_ctrl(port, &is_sinking); + if (rv == EC_SUCCESS && is_sinking) + AOZ1380_SET_FLAG(port, AOZ1380_FLAGS_SINK_ENABLED); + + rv = tcpm_get_src_ctrl(port, &is_sourcing); + if (rv == EC_SUCCESS && is_sourcing) + AOZ1380_SET_FLAG(port, AOZ1380_FLAGS_SOURCE_ENABLED); + return EC_SUCCESS; } diff --git a/driver/tcpm/nct38xx.c b/driver/tcpm/nct38xx.c index 0c406810d9..5e35bfba22 100644 --- a/driver/tcpm/nct38xx.c +++ b/driver/tcpm/nct38xx.c @@ -186,7 +186,9 @@ const struct tcpm_drv nct38xx_tcpm_drv = { .drp_toggle = &tcpci_tcpc_drp_toggle, #endif #ifdef CONFIG_USBC_PPC + .get_snk_ctrl = &tcpci_tcpm_get_snk_ctrl, .set_snk_ctrl = &tcpci_tcpm_set_snk_ctrl, + .get_src_ctrl = &tcpci_tcpm_get_src_ctrl, .set_src_ctrl = &tcpci_tcpm_set_src_ctrl, #endif .get_chip_info = &tcpci_get_chip_info, diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c index ae03f7e097..ac39c9865a 100644 --- a/driver/tcpm/tcpci.c +++ b/driver/tcpm/tcpci.c @@ -565,6 +565,19 @@ int tcpci_tcpm_set_polarity(int port, enum tcpc_cc_polarity polarity) } #ifdef CONFIG_USBC_PPC +int tcpci_tcpm_get_snk_ctrl(int port, bool *sinking) +{ + int rv; + int pwr_sts; + + rv = tcpci_tcpm_get_power_status(port, &pwr_sts); + *sinking = (rv != EC_SUCCESS) + ? 0 + : pwr_sts & TCPC_REG_POWER_STATUS_SINKING_VBUS; + + return rv; +} + int tcpci_tcpm_set_snk_ctrl(int port, int enable) { int cmd = enable ? TCPC_REG_COMMAND_SNK_CTRL_HIGH : @@ -573,6 +586,19 @@ int tcpci_tcpm_set_snk_ctrl(int port, int enable) return tcpc_write(port, TCPC_REG_COMMAND, cmd); } +int tcpci_tcpm_get_src_ctrl(int port, bool *sourcing) +{ + int rv; + int pwr_sts; + + rv = tcpci_tcpm_get_power_status(port, &pwr_sts); + *sourcing = (rv != EC_SUCCESS) + ? 0 + : pwr_sts & TCPC_REG_POWER_STATUS_SOURCING_VBUS; + + return rv; +} + int tcpci_tcpm_set_src_ctrl(int port, int enable) { int cmd = enable ? TCPC_REG_COMMAND_SRC_CTRL_HIGH : diff --git a/driver/tcpm/tcpci.h b/driver/tcpm/tcpci.h index da8b47a479..7622d02e63 100644 --- a/driver/tcpm/tcpci.h +++ b/driver/tcpm/tcpci.h @@ -116,6 +116,7 @@ #define TCPC_REG_POWER_STATUS_SOURCING_VBUS BIT(4) #define TCPC_REG_POWER_STATUS_VBUS_DET BIT(3) #define TCPC_REG_POWER_STATUS_VBUS_PRES BIT(2) +#define TCPC_REG_POWER_STATUS_SINKING_VBUS BIT(0) #define TCPC_REG_FAULT_STATUS 0x1f #define TCPC_REG_FAULT_STATUS_ALL_REGS_RESET BIT(7) @@ -246,7 +247,9 @@ int tcpci_tcpm_mux_get(const struct usb_mux *me, mux_state_t *mux_state); int tcpci_get_chip_info(int port, int live, struct ec_response_pd_chip_info_v1 *chip_info); #ifdef CONFIG_USBC_PPC +int tcpci_tcpm_get_snk_ctrl(int port, bool *sinking); int tcpci_tcpm_set_snk_ctrl(int port, int enable); +int tcpci_tcpm_get_src_ctrl(int port, bool *sourcing); int tcpci_tcpm_set_src_ctrl(int port, int enable); #endif diff --git a/driver/tcpm/tcpm.h b/driver/tcpm/tcpm.h index 4dd9af993d..4ab993dcc2 100644 --- a/driver/tcpm/tcpm.h +++ b/driver/tcpm/tcpm.h @@ -230,6 +230,17 @@ static inline int tcpm_transmit(int port, enum tcpm_transmit_type type, } #ifdef CONFIG_USBC_PPC +static inline int tcpm_get_snk_ctrl(int port, bool *sinking) +{ + int rv = EC_ERROR_UNIMPLEMENTED; + + if (tcpc_config[port].drv->get_snk_ctrl != NULL) + rv = tcpc_config[port].drv->get_snk_ctrl(port, sinking); + else + *sinking = false; + + return rv; +} static inline int tcpm_set_snk_ctrl(int port, int enable) { if (tcpc_config[port].drv->set_snk_ctrl != NULL) @@ -238,6 +249,17 @@ static inline int tcpm_set_snk_ctrl(int port, int enable) return EC_ERROR_UNIMPLEMENTED; } +static inline int tcpm_get_src_ctrl(int port, bool *sourcing) +{ + int rv = EC_ERROR_UNIMPLEMENTED; + + if (tcpc_config[port].drv->get_src_ctrl != NULL) + rv = tcpc_config[port].drv->get_src_ctrl(port, sourcing); + else + *sourcing = false; + + return rv; +} static inline int tcpm_set_src_ctrl(int port, int enable) { if (tcpc_config[port].drv->set_src_ctrl != NULL) diff --git a/include/usb_pd_tcpm.h b/include/usb_pd_tcpm.h index 910a44d792..b039c6f63e 100644 --- a/include/usb_pd_tcpm.h +++ b/include/usb_pd_tcpm.h @@ -360,6 +360,17 @@ struct tcpm_drv { struct ec_response_pd_chip_info_v1 *info); #ifdef CONFIG_USBC_PPC + /** + * Request current sinking state of the TCPC + * NOTE: this is most useful for PPCs that can not tell on their own + * + * @param port Type-C port number + * @param is_sinking true for sinking, false for not + * + * @return EC_SUCCESS, EC_ERROR_UNIMPLEMENTED or error + */ + int (*get_snk_ctrl)(int port, bool *sinking); + /** * Send SinkVBUS or DisableSinkVBUS command * @@ -370,6 +381,17 @@ struct tcpm_drv { */ int (*set_snk_ctrl)(int port, int enable); + /** + * Request current sourcing state of the TCPC + * NOTE: this is most useful for PPCs that can not tell on their own + * + * @param port Type-C port number + * @param is_sourcing true for sourcing, false for not + * + * @return EC_SUCCESS, EC_ERROR_UNIMPLEMENTED or error + */ + int (*get_src_ctrl)(int port, bool *sourcing); + /** * Send SourceVBUS or DisableSourceVBUS command * -- cgit v1.2.1