diff --git a/board/kevin/board.c b/board/kevin/board.c index f3f99d38b9..65fa97f125 100644 --- a/board/kevin/board.c +++ b/board/kevin/board.c @@ -204,7 +204,8 @@ void board_set_charge_limit(int port, int supplier, int charge_ma) int extpower_is_present(void) { - return bd99955_extpower_is_present(); + /* Check VBUS on either port */ + return bd99955_is_vbus_provided(BD99955_CHARGE_PORT_BOTH); } static void board_init(void) diff --git a/board/reef/board.c b/board/reef/board.c index d61ae11b58..395ef77ef2 100644 --- a/board/reef/board.c +++ b/board/reef/board.c @@ -412,7 +412,8 @@ void board_set_charge_limit(int port, int supplier, int charge_ma) int extpower_is_present(void) { - return bd99955_extpower_is_present(); + /* Check VBUS on either port */ + return bd99955_is_vbus_provided(BD99955_CHARGE_PORT_BOTH); } int usb_charger_port_is_sourcing_vbus(int port) diff --git a/board/reef/usb_pd_policy.c b/board/reef/usb_pd_policy.c index 8af728b936..e399e1686c 100644 --- a/board/reef/usb_pd_policy.c +++ b/board/reef/usb_pd_policy.c @@ -106,7 +106,25 @@ void typec_set_input_current_limit(int port, uint32_t max_ma, int pd_snk_is_vbus_provided(int port) { - return extpower_is_present(); + enum bd99955_charge_port bd99955_port; + + /* + * TODO: Add a compile-time mapping to prevent + * duplication of this code. + */ + switch (port) { + case 0: + bd99955_port = BD99955_CHARGE_PORT_VBUS; + break; + case 1: + bd99955_port = BD99955_CHARGE_PORT_VCC; + break; + default: + panic("Invalid charge port\n"); + break; + } + + return bd99955_is_vbus_provided(bd99955_port); } int pd_board_checks(void) diff --git a/driver/charger/bd99955.c b/driver/charger/bd99955.c index c07cf70493..6953592fb1 100644 --- a/driver/charger/bd99955.c +++ b/driver/charger/bd99955.c @@ -437,7 +437,7 @@ int charger_get_status(int *status) } /* source of power */ - if (bd99955_extpower_is_present()) + if (bd99955_is_vbus_provided(BD99955_CHARGE_PORT_BOTH)) *status |= CHARGER_AC_PRESENT; return EC_SUCCESS; @@ -550,7 +550,7 @@ static void bd99995_init(void) (bi->voltage_max + 500) & 0x7ff0, BD99955_EXTENDED_COMMAND); } -DECLARE_HOOK(HOOK_INIT, bd99995_init, HOOK_PRIO_DEFAULT); +DECLARE_HOOK(HOOK_INIT, bd99995_init, HOOK_PRIO_INIT_EXTPOWER); int charger_post_init(void) { @@ -578,7 +578,7 @@ int charger_discharge_on_ac(int enable) /*** Non-standard interface functions ***/ -int bd99955_extpower_is_present(void) +int bd99955_is_vbus_provided(int port) { int reg; @@ -586,8 +586,17 @@ int bd99955_extpower_is_present(void) BD99955_EXTENDED_COMMAND)) return 0; - reg &= (BD99955_CMD_VBUS_VCC_STATUS_VCC_DETECT | - BD99955_CMD_VBUS_VCC_STATUS_VBUS_DETECT); + if (port == BD99955_CHARGE_PORT_VBUS) + reg &= BD99955_CMD_VBUS_VCC_STATUS_VBUS_DETECT; + else if (port == BD99955_CHARGE_PORT_VCC) + reg &= BD99955_CMD_VBUS_VCC_STATUS_VCC_DETECT; + else if (port == BD99955_CHARGE_PORT_BOTH) { + /* Check VBUS on either port */ + reg &= (BD99955_CMD_VBUS_VCC_STATUS_VCC_DETECT | + BD99955_CMD_VBUS_VCC_STATUS_VBUS_DETECT); + } else + reg = 0; + return !!reg; } diff --git a/driver/charger/bd99955.h b/driver/charger/bd99955.h index 69884dce13..7deae54b09 100644 --- a/driver/charger/bd99955.h +++ b/driver/charger/bd99955.h @@ -247,8 +247,8 @@ enum bd99955_charge_port { * functionality not part of the standard charger interface. */ -/* Return true if extpower is present on their input port. */ -int bd99955_extpower_is_present(void); +/* Is VBUS provided or external power present */ +int bd99955_is_vbus_provided(int port); /* Select input port from {VCC, VBUS, VCC&VBUS, NONE}. */ int bd99955_select_input_port(enum bd99955_charge_port port); /* Enable/Disable charging triggered by BC1.2 */