summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--board/eve/board.c4
-rw-r--r--board/pyro/board.c4
-rw-r--r--board/reef/board.c4
-rw-r--r--board/samus_pd/board.c2
-rw-r--r--board/snappy/board.c4
-rw-r--r--common/charge_manager.c2
-rw-r--r--common/charge_ramp.c6
-rw-r--r--driver/charger/bd9995x.c21
-rw-r--r--driver/charger/bd9995x.h2
-rw-r--r--include/charge_ramp.h3
-rw-r--r--include/charger.h4
-rw-r--r--test/charge_ramp.c2
12 files changed, 29 insertions, 29 deletions
diff --git a/board/eve/board.c b/board/eve/board.c
index ea7a0e76b6..efc4273f63 100644
--- a/board/eve/board.c
+++ b/board/eve/board.c
@@ -537,9 +537,9 @@ int board_is_consuming_full_charge(void)
/**
* Return if VBUS is sagging too low
*/
-int board_is_vbus_too_low(enum chg_ramp_vbus_state ramp_state)
+int board_is_vbus_too_low(int port, enum chg_ramp_vbus_state ramp_state)
{
- return charger_get_vbus_level() < BD9995X_BC12_MIN_VOLTAGE;
+ return charger_get_vbus_voltage(port) < BD9995X_BC12_MIN_VOLTAGE;
}
/* Enable or disable input devices, based upon chipset state and tablet mode */
diff --git a/board/pyro/board.c b/board/pyro/board.c
index a8d3bde88a..58da8e6b2b 100644
--- a/board/pyro/board.c
+++ b/board/pyro/board.c
@@ -648,9 +648,9 @@ int board_is_consuming_full_charge(void)
/**
* Return if VBUS is sagging too low
*/
-int board_is_vbus_too_low(enum chg_ramp_vbus_state ramp_state)
+int board_is_vbus_too_low(int port, enum chg_ramp_vbus_state ramp_state)
{
- return charger_get_vbus_level() < BD9995X_BC12_MIN_VOLTAGE;
+ return charger_get_vbus_voltage(port) < BD9995X_BC12_MIN_VOLTAGE;
}
static void enable_input_devices(void)
diff --git a/board/reef/board.c b/board/reef/board.c
index 82a2df4dc8..1bae63f92a 100644
--- a/board/reef/board.c
+++ b/board/reef/board.c
@@ -650,9 +650,9 @@ int board_is_consuming_full_charge(void)
/**
* Return if VBUS is sagging too low
*/
-int board_is_vbus_too_low(enum chg_ramp_vbus_state ramp_state)
+int board_is_vbus_too_low(int port, enum chg_ramp_vbus_state ramp_state)
{
- return charger_get_vbus_level() < BD9995X_BC12_MIN_VOLTAGE;
+ return charger_get_vbus_voltage(port) < BD9995X_BC12_MIN_VOLTAGE;
}
static void enable_input_devices(void)
diff --git a/board/samus_pd/board.c b/board/samus_pd/board.c
index 288ff1cbb7..aa929186f7 100644
--- a/board/samus_pd/board.c
+++ b/board/samus_pd/board.c
@@ -417,7 +417,7 @@ int board_is_consuming_full_charge(void)
/**
* Return if VBUS is sagging too low
*/
-int board_is_vbus_too_low(enum chg_ramp_vbus_state ramp_state)
+int board_is_vbus_too_low(int port, enum chg_ramp_vbus_state ramp_state)
{
static int vbus[VBUS_STABLE_SAMPLE_COUNT];
static int vbus_idx, vbus_samples_full;
diff --git a/board/snappy/board.c b/board/snappy/board.c
index 76bedcf5f4..ddb6471ea0 100644
--- a/board/snappy/board.c
+++ b/board/snappy/board.c
@@ -647,9 +647,9 @@ int board_is_consuming_full_charge(void)
/**
* Return if VBUS is sagging too low
*/
-int board_is_vbus_too_low(enum chg_ramp_vbus_state ramp_state)
+int board_is_vbus_too_low(int port, enum chg_ramp_vbus_state ramp_state)
{
- return charger_get_vbus_level() < BD9995X_BC12_MIN_VOLTAGE;
+ return charger_get_vbus_voltage(port) < BD9995X_BC12_MIN_VOLTAGE;
}
static void enable_input_devices(void)
diff --git a/common/charge_manager.c b/common/charge_manager.c
index da748b39a0..908d82281c 100644
--- a/common/charge_manager.c
+++ b/common/charge_manager.c
@@ -314,7 +314,7 @@ static void charge_manager_fill_power_info(int port,
r->meas.voltage_now = 5000;
else {
#ifdef CONFIG_USB_PD_VBUS_DETECT_CHARGER
- r->meas.voltage_now = charger_get_vbus_level();
+ r->meas.voltage_now = charger_get_vbus_voltage(port);
#else
if (ADC_VBUS >= 0)
r->meas.voltage_now =
diff --git a/common/charge_ramp.c b/common/charge_ramp.c
index f6942d7516..1c9dfecc33 100644
--- a/common/charge_ramp.c
+++ b/common/charge_ramp.c
@@ -264,7 +264,8 @@ void chg_ramp_task(void)
}
/* If VBUS is sagging a lot, then stop ramping */
- if (board_is_vbus_too_low(CHG_RAMP_VBUS_RAMPING)) {
+ if (board_is_vbus_too_low(active_port,
+ CHG_RAMP_VBUS_RAMPING)) {
CPRINTS("VBUS low");
active_icl_new = MAX(min_icl, active_icl -
RAMP_ICL_BACKOFF);
@@ -310,7 +311,8 @@ void chg_ramp_task(void)
/* Keep an eye on VBUS and restart ramping if it dips */
if (board_is_ramp_allowed(active_sup) &&
- board_is_vbus_too_low(CHG_RAMP_VBUS_STABLE)) {
+ board_is_vbus_too_low(active_port,
+ CHG_RAMP_VBUS_STABLE)) {
CPRINTS("VBUS low; Re-ramp");
max_icl = MAX(min_icl,
max_icl - RAMP_ICL_BACKOFF);
diff --git a/driver/charger/bd9995x.c b/driver/charger/bd9995x.c
index 33ff4c78af..df69f348e8 100644
--- a/driver/charger/bd9995x.c
+++ b/driver/charger/bd9995x.c
@@ -867,25 +867,22 @@ int charger_discharge_on_ac(int enable)
BD9995X_EXTENDED_COMMAND);
}
-int charger_get_vbus_level(void)
+int charger_get_vbus_voltage(int port)
{
- int vbus_val;
- int vcc_val;
- int rv;
+ uint8_t read_reg;
+ int voltage;
- rv = ch_raw_read16(BD9995X_CMD_VBUS_VAL, &vbus_val,
- BD9995X_EXTENDED_COMMAND);
+ read_reg = (bd9995x_pd_port_to_chg_port(port) ==
+ BD9995X_CHARGE_PORT_VBUS) ? BD9995X_CMD_VBUS_VAL :
+ BD9995X_CMD_VCC_VAL;
- rv += ch_raw_read16(BD9995X_CMD_VCC_VAL, &vcc_val,
- BD9995X_EXTENDED_COMMAND);
-
- return rv ? 0 : MAX(vbus_val, vcc_val);
+ return ch_raw_read16(read_reg, &voltage, BD9995X_EXTENDED_COMMAND) ?
+ 0 : voltage;
}
-
/*** Non-standard interface functions ***/
-int bd9995x_is_vbus_provided(int port)
+int bd9995x_is_vbus_provided(enum bd9995x_charge_port port)
{
int reg;
diff --git a/driver/charger/bd9995x.h b/driver/charger/bd9995x.h
index a5ce174aea..6140fb2971 100644
--- a/driver/charger/bd9995x.h
+++ b/driver/charger/bd9995x.h
@@ -344,7 +344,7 @@ static inline enum bd9995x_charge_port bd9995x_pd_port_to_chg_port(int port)
*/
/* Is VBUS provided or external power present */
-int bd9995x_is_vbus_provided(int port);
+int bd9995x_is_vbus_provided(enum bd9995x_charge_port port);
/* Select or deselect input port from {VCC, VBUS, VCC&VBUS}. */
int bd9995x_select_input_port(enum bd9995x_charge_port port, int select);
/* Get input current limit for BC1.2 suppliers */
diff --git a/include/charge_ramp.h b/include/charge_ramp.h
index 62145568c4..9718663d33 100644
--- a/include/charge_ramp.h
+++ b/include/charge_ramp.h
@@ -45,11 +45,12 @@ int board_is_consuming_full_charge(void);
/**
* Check if VBUS is too low
*
+ * @param port Charge ramp port
* @param ramp_state Current ramp state
*
* @return VBUS is sagging low
*/
-int board_is_vbus_too_low(enum chg_ramp_vbus_state ramp_state);
+int board_is_vbus_too_low(int port, enum chg_ramp_vbus_state ramp_state);
/**
* Get the input current limit set by ramp module
diff --git a/include/charger.h b/include/charger.h
index 86ff5edc34..a9f4f41fbd 100644
--- a/include/charger.h
+++ b/include/charger.h
@@ -99,8 +99,8 @@ int charger_set_voltage(int voltage);
/* Discharge battery when on AC power. */
int charger_discharge_on_ac(int enable);
-/* Get the VBUS level from the charger */
-int charger_get_vbus_level(void);
+/* Get the VBUS voltage (mV) from the charger */
+int charger_get_vbus_voltage(int port);
/* Custom board function to discharge battery when on AC power */
int board_discharge_on_ac(int enable);
diff --git a/test/charge_ramp.c b/test/charge_ramp.c
index 33db036a59..6e9f239101 100644
--- a/test/charge_ramp.c
+++ b/test/charge_ramp.c
@@ -47,7 +47,7 @@ int board_is_consuming_full_charge(void)
return charge_limit_ma <= system_load_current_ma;
}
-int board_is_vbus_too_low(enum chg_ramp_vbus_state ramp_state)
+int board_is_vbus_too_low(int port, enum chg_ramp_vbus_state ramp_state)
{
return MIN(system_load_current_ma, charge_limit_ma) >
vbus_low_current_ma;