summaryrefslogtreecommitdiff
path: root/driver/charger/sm5803.c
diff options
context:
space:
mode:
Diffstat (limited to 'driver/charger/sm5803.c')
-rw-r--r--driver/charger/sm5803.c54
1 files changed, 50 insertions, 4 deletions
diff --git a/driver/charger/sm5803.c b/driver/charger/sm5803.c
index 81108e7506..d4a20826a7 100644
--- a/driver/charger/sm5803.c
+++ b/driver/charger/sm5803.c
@@ -9,6 +9,7 @@
#include "battery_smart.h"
#include "charge_state_v2.h"
#include "charger.h"
+#include "extpower.h"
#include "gpio.h"
#include "hooks.h"
#include "i2c.h"
@@ -624,6 +625,12 @@ static void sm5803_init(int chgnum)
rv = chg_write8(chgnum, SM5803_REG_DPM_VL_SET_MSB, (reg >> 3));
rv |= chg_write8(chgnum, SM5803_REG_DPM_VL_SET_LSB, (reg & 0x7));
+ /* Set the VCHGPWR thresholds to mirror those for VBUS. */
+ rv |= meas_write8(chgnum, SM5803_REG_VCHG_PWR_HIGH_TH,
+ SM5803_VBUS_HIGH_LEVEL);
+ rv |= meas_write8(chgnum, SM5803_REG_VCHG_PWR_LOW_TH,
+ SM5803_VBUS_LOW_LEVEL);
+
/* Set default input current */
reg = SM5803_CURRENT_TO_REG(CONFIG_CHARGER_INPUT_CURRENT)
& SM5803_CHG_ILIM_RAW;
@@ -647,8 +654,11 @@ static void sm5803_init(int chgnum)
SM5803_TINT_MIN_LEVEL);
- /* Configure TINT interrupts to fire after thresholds are set */
- rv |= main_write8(chgnum, SM5803_REG_INT2_EN, SM5803_INT2_TINT);
+ /*
+ * Configure TINT & VCHGPWR interrupts to fire after thresholds are set
+ */
+ rv |= main_write8(chgnum, SM5803_REG_INT2_EN, SM5803_INT2_TINT |
+ SM5803_INT2_VCHGPWR);
/*
* Configure CHG_ENABLE to only be set through I2C by setting
@@ -1020,12 +1030,10 @@ void sm5803_handle_interrupt(int chgnum)
charger_vbus[chgnum] = 0;
if (IS_ENABLED(CONFIG_USB_CHARGER))
usb_charger_vbus_change(chgnum, 0);
- board_vbus_present_change();
} else {
charger_vbus[chgnum] = 1;
if (IS_ENABLED(CONFIG_USB_CHARGER))
usb_charger_vbus_change(chgnum, 1);
- board_vbus_present_change();
}
}
@@ -1070,6 +1078,10 @@ void sm5803_handle_interrupt(int chgnum)
*/
}
+ /* Update extpower if VCHGPWR changes. */
+ if (int_reg & SM5803_INT2_VCHGPWR)
+ board_vbus_present_change();
+
/* TODO(b/159376384): Take action on fatal BFET power alert. */
rv = main_read8(chgnum, SM5803_REG_INT3_REQ, &int_reg);
if (rv) {
@@ -1474,6 +1486,40 @@ static enum ec_error_list sm5803_get_option(int chgnum, int *option)
return rv;
}
+enum ec_error_list sm5803_is_acok(int chgnum, bool *acok)
+{
+ int rv;
+ enum sm5803_charger_modes mode;
+ int reg;
+
+ rv = chg_read8(chgnum, SM5803_REG_FLOW1, &reg);
+ if (rv)
+ return rv;
+
+ /* The charger mode is contained in the last 2 bits. */
+ reg &= SM5803_FLOW1_MODE;
+ mode = (enum sm5803_charger_modes)reg;
+
+ /* If we're not sinking, then AC can't be OK. */
+ if (mode != CHARGER_MODE_SINK) {
+ *acok = false;
+ return EC_SUCCESS;
+ }
+
+ /*
+ * Okay, we're sinking. Check that VCHGPWR has some voltage. This
+ * should indicate that the path is good.
+ */
+ rv = meas_read8(chgnum, SM5803_REG_VCHG_PWR_MSB, &reg);
+ if (rv)
+ return rv;
+
+ /* Assume that ACOK would be asserted if VCHGPWR is higher than ~4V. */
+ *acok = reg >= SM5803_VBUS_HIGH_LEVEL;
+
+ return EC_SUCCESS;
+}
+
static enum ec_error_list sm5803_is_input_current_limit_reached(int chgnum,
bool *reached)
{