diff options
-rw-r--r-- | common/usb_charger.c | 2 | ||||
-rw-r--r-- | driver/ppc/aoz1380.c | 9 | ||||
-rw-r--r-- | driver/tcpm/nct38xx.c | 15 | ||||
-rw-r--r-- | driver/tcpm/tcpci.c | 16 | ||||
-rw-r--r-- | include/driver/tcpm/tcpci.h | 4 | ||||
-rw-r--r-- | include/driver/tcpm/tcpm.h | 23 | ||||
-rw-r--r-- | include/usb_pd_tcpm.h | 10 |
7 files changed, 25 insertions, 54 deletions
diff --git a/common/usb_charger.c b/common/usb_charger.c index 40f71062b4..20031a9469 100644 --- a/common/usb_charger.c +++ b/common/usb_charger.c @@ -41,6 +41,8 @@ static void update_vbus_supplier(int port, int vbus_level) #define USB_5V_EN(port) board_is_sourcing_vbus(port) #elif defined(CONFIG_USBC_PPC) #define USB_5V_EN(port) ppc_is_sourcing_vbus(port) +#elif defined(CONFIG_USB_PD_PPC) +#define USB_5V_EN(port) tcpci_tcpm_get_src_ctrl(port) #elif defined(CONFIG_USB_PD_5V_CHARGER_CTRL) #define USB_5V_EN(port) charger_is_sourcing_otg_power(port) #elif defined(CONFIG_USB_PD_5V_EN_ACTIVE_LOW) diff --git a/driver/ppc/aoz1380.c b/driver/ppc/aoz1380.c index 9ce5b442ac..4e2188c60d 100644 --- a/driver/ppc/aoz1380.c +++ b/driver/ppc/aoz1380.c @@ -37,17 +37,12 @@ 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) + if (tcpm_get_snk_ctrl(port)) AOZ1380_SET_FLAG(port, AOZ1380_FLAGS_SINK_ENABLED); - rv = tcpm_get_src_ctrl(port, &is_sourcing); - if (rv == EC_SUCCESS && is_sourcing) + if (tcpm_get_src_ctrl(port)) AOZ1380_SET_FLAG(port, AOZ1380_FLAGS_SOURCE_ENABLED); return EC_SUCCESS; diff --git a/driver/tcpm/nct38xx.c b/driver/tcpm/nct38xx.c index 5d2be3ad2f..f4e3382d3a 100644 --- a/driver/tcpm/nct38xx.c +++ b/driver/tcpm/nct38xx.c @@ -148,19 +148,10 @@ static int nct38xx_tcpm_set_cc(int port, int pull) * SNKEN will be re-enabled in nct38xx_init above (from tcpm_init), or * when CC lines are set again, or when sinking is disabled. */ - enum mask_update_action action = MASK_SET; int rv; - - if (pull == TYPEC_CC_OPEN) { - bool is_sinking; - - rv = tcpm_get_snk_ctrl(port, &is_sinking); - if (rv) - return rv; - - if (is_sinking) - action = MASK_CLR; - } + enum mask_update_action action = + pull == TYPEC_CC_OPEN && tcpm_get_snk_ctrl(port) ? + MASK_CLR : MASK_SET; rv = tcpc_update8(port, NCT38XX_REG_CTRL_OUT_EN, diff --git a/driver/tcpm/tcpci.c b/driver/tcpm/tcpci.c index 64707c67df..56af65cc75 100644 --- a/driver/tcpm/tcpci.c +++ b/driver/tcpm/tcpci.c @@ -575,17 +575,15 @@ int tcpci_tcpm_set_polarity(int port, enum tcpc_cc_polarity polarity) } #ifdef CONFIG_USB_PD_PPC -int tcpci_tcpm_get_snk_ctrl(int port, bool *sinking) +bool tcpci_tcpm_get_snk_ctrl(int port) { 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; + return rv == EC_SUCCESS && + pwr_sts & TCPC_REG_POWER_STATUS_SINKING_VBUS; } int tcpci_tcpm_set_snk_ctrl(int port, int enable) @@ -596,17 +594,15 @@ 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) +bool tcpci_tcpm_get_src_ctrl(int port) { 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; + return rv == EC_SUCCESS && + pwr_sts & TCPC_REG_POWER_STATUS_SOURCING_VBUS; } int tcpci_tcpm_set_src_ctrl(int port, int enable) diff --git a/include/driver/tcpm/tcpci.h b/include/driver/tcpm/tcpci.h index 0dc5dadc6a..18cddd9b61 100644 --- a/include/driver/tcpm/tcpci.h +++ b/include/driver/tcpm/tcpci.h @@ -282,9 +282,9 @@ int tcpci_tcpm_mux_enter_low_power(const struct usb_mux *me); 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); +bool tcpci_tcpm_get_snk_ctrl(int port); int tcpci_tcpm_set_snk_ctrl(int port, int enable); -int tcpci_tcpm_get_src_ctrl(int port, bool *sourcing); +bool tcpci_tcpm_get_src_ctrl(int port); int tcpci_tcpm_set_src_ctrl(int port, int enable); #endif diff --git a/include/driver/tcpm/tcpm.h b/include/driver/tcpm/tcpm.h index 901f44a26a..df717dcb6a 100644 --- a/include/driver/tcpm/tcpm.h +++ b/include/driver/tcpm/tcpm.h @@ -255,16 +255,10 @@ static inline int tcpm_transmit(int port, enum tcpm_transmit_type type, } #ifdef CONFIG_USB_PD_PPC -static inline int tcpm_get_snk_ctrl(int port, bool *sinking) +static inline bool tcpm_get_snk_ctrl(int port) { - 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; + return tcpc_config[port].drv->get_snk_ctrl ? + tcpc_config[port].drv->get_snk_ctrl(port) : false; } static inline int tcpm_set_snk_ctrl(int port, int enable) { @@ -274,16 +268,11 @@ 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) +static inline bool tcpm_get_src_ctrl(int port) { - 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; + return tcpc_config[port].drv->get_src_ctrl ? + tcpc_config[port].drv->get_src_ctrl(port) : false; } static inline int tcpm_set_src_ctrl(int port, int enable) { diff --git a/include/usb_pd_tcpm.h b/include/usb_pd_tcpm.h index a814c2b7af..fddcb04c3a 100644 --- a/include/usb_pd_tcpm.h +++ b/include/usb_pd_tcpm.h @@ -373,11 +373,10 @@ struct tcpm_drv { * 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 + * @return true if sinking else false */ - int (*get_snk_ctrl)(int port, bool *sinking); + bool (*get_snk_ctrl)(int port); /** * Send SinkVBUS or DisableSinkVBUS command @@ -394,11 +393,10 @@ struct tcpm_drv { * 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 + * @return true if sourcing else false */ - int (*get_src_ctrl)(int port, bool *sourcing); + bool (*get_src_ctrl)(int port); /** * Send SourceVBUS or DisableSourceVBUS command |