summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevin Lu <Devin.Lu@quantatw.com>2021-08-09 16:25:58 +0800
committerCommit Bot <commit-bot@chromium.org>2021-08-19 01:45:21 +0000
commit8be18be723171d018a788e005686413ee9b7293d (patch)
treed1c56930a1ee5493490442b8b15f59b8281d4033
parent981c67a39da61e5e23f2889e4a6628750b0dcb2b (diff)
downloadchrome-ec-stabilize-14163.B-main.tar.gz
sm5803: Replace is_acok methodstabilize-14163.B-main
Since the CHARGER_MODE_SINK bit is not truly ACOK if discharging on ac. Also the VCHGPWR will drop to zero if discharging on ac. This patch replace is_acok method to avoid AC off while discharging on ac. BUG=b:194990808, b:196998260 BRANCH=dedede TEST=Make sure ectool chargecontrol discharge works. Attached charger to make sure AC is ON. Signed-off-by: Devin Lu <Devin.Lu@quantatw.com> Change-Id: I7ee72da26b99c8bcb8fbd8c878c930506a244e28 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3081039 Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r--driver/charger/sm5803.c40
1 files changed, 12 insertions, 28 deletions
diff --git a/driver/charger/sm5803.c b/driver/charger/sm5803.c
index a3d59b1e55..460dcf4093 100644
--- a/driver/charger/sm5803.c
+++ b/driver/charger/sm5803.c
@@ -653,12 +653,6 @@ 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;
@@ -689,12 +683,8 @@ static void sm5803_init(int chgnum)
rv |= main_write8(chgnum, SM5803_REG_INT2_EN, reg);
- /*
- * Configure TINT & VCHGPWR interrupts to fire after thresholds are set.
- */
- rv |= main_read8(chgnum, SM5803_REG_INT2_EN, &reg);
- reg |= SM5803_INT2_TINT | SM5803_INT2_VCHGPWR;
- rv |= main_write8(chgnum, SM5803_REG_INT2_EN, reg);
+ /* Configure TINT interrupts to fire after thresholds are set */
+ rv |= main_write8(chgnum, SM5803_REG_INT2_EN, SM5803_INT2_TINT);
/*
* Configure CHG_ENABLE to only be set through I2C by setting
@@ -1071,6 +1061,7 @@ void sm5803_handle_interrupt(int chgnum)
if (IS_ENABLED(CONFIG_USB_CHARGER))
usb_charger_vbus_change(chgnum, 1);
}
+ board_check_extpower();
}
rv = main_read8(chgnum, SM5803_REG_INT2_REQ, &int_reg);
@@ -1114,10 +1105,6 @@ void sm5803_handle_interrupt(int chgnum)
*/
}
- /* Update extpower if VCHGPWR changes. */
- if (int_reg & SM5803_INT2_VCHGPWR)
- board_check_extpower();
-
if (int_reg & SM5803_INT2_VBATSNSP) {
int meas_volt;
uint32_t platform_id;
@@ -1597,33 +1584,30 @@ static enum ec_error_list sm5803_get_option(int chgnum, int *option)
enum ec_error_list sm5803_is_acok(int chgnum, bool *acok)
{
int rv;
- enum sm5803_charger_modes mode;
- int reg;
+ int reg, vbus_mv;
+
+ rv = main_read8(chgnum, SM5803_REG_STATUS1, &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) {
+ if (!(reg & SM5803_STATUS1_CHG_DET)) {
*acok = false;
return EC_SUCCESS;
}
/*
- * Okay, we're sinking. Check that VCHGPWR has some voltage. This
+ * Okay, we're sinking. Check that VBUS has some voltage. This
* should indicate that the path is good.
*/
- rv = meas_read8(chgnum, SM5803_REG_VCHG_PWR_MSB, &reg);
+ rv = charger_get_vbus_voltage(chgnum, &vbus_mv);
+
if (rv)
return rv;
- /* Assume that ACOK would be asserted if VCHGPWR is higher than ~4V. */
- *acok = reg >= SM5803_VBUS_HIGH_LEVEL;
+ /* Assume that ACOK would be asserted if VBUS is higher than ~4V. */
+ *acok = vbus_mv >= 4000;
return EC_SUCCESS;
}