diff options
author | Diana Z <dzigterman@chromium.org> | 2020-08-11 10:48:10 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-08-14 22:02:18 +0000 |
commit | 86c55038ec6a43db5ae677defd575da7651b8602 (patch) | |
tree | 628400e4cf48af7a3eaa01c74700e1a1db69048b /driver/charger/sm5803.c | |
parent | d31bb8257e8baff006bbf174e8fdaf20666abc02 (diff) | |
download | chrome-ec-86c55038ec6a43db5ae677defd575da7651b8602.tar.gz |
SM5803: Switch to using charger detect interrupt
Charger detect interrupt appears to be more robust at signaling when a
non-PD chrager has been inserted than the Vbus levels. This change
switches the driver over to that indication and disables the Vbus
threshold interrupt.
Note there are still some power role swap issues present with this
change, but not more than on current ToT.
BRANCH=None
BUG=b:163136683,b:161566084
TEST=on waddledee, verify:
-Suzy-q is detected as a charger on both ports
-45W charger is detected as a charger on both ports
-HooToo hub is detected as a charger after power role swap
Signed-off-by: Diana Z <dzigterman@chromium.org>
Change-Id: I85776f4a79413ca1b0eb454e03ccf2a6f8466ca3
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2349284
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'driver/charger/sm5803.c')
-rw-r--r-- | driver/charger/sm5803.c | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/driver/charger/sm5803.c b/driver/charger/sm5803.c index dca3add717..3899b95887 100644 --- a/driver/charger/sm5803.c +++ b/driver/charger/sm5803.c @@ -443,11 +443,8 @@ static void sm5803_init(int chgnum) & SM5803_CHG_ILIM_RAW; rv |= chg_write8(chgnum, SM5803_REG_CHG_ILIM, reg); - /* Set Vbus interrupt levels for 3.5V and 4.0V */ - rv |= meas_write8(chgnum, SM5803_REG_VBUS_LOW_TH, - SM5803_VBUS_LOW_LEVEL); - rv |= meas_write8(chgnum, SM5803_REG_VBUS_HIGH_TH, - SM5803_VBUS_HIGH_LEVEL); + /* Configure charger insertion interrupts */ + rv |= main_write8(chgnum, SM5803_REG_INT1_EN, SM5803_INT1_CHG); /* Set TINT interrupts for 360 K and 330 K */ rv |= meas_write8(chgnum, SM5803_REG_TINT_HIGH_TH, @@ -455,12 +452,9 @@ static void sm5803_init(int chgnum) rv |= meas_write8(chgnum, SM5803_REG_TINT_LOW_TH, SM5803_TINT_LOW_LEVEL); - /* - * Configure TINT and Vbus interrupts to fire after thresholds are - * configured - */ - rv |= main_write8(chgnum, SM5803_REG_INT2_EN, SM5803_INT2_TINT - | SM5803_INT2_VBUS); + /* 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 * HOST_MODE_EN bit (all other register bits are 0 by default) @@ -510,7 +504,29 @@ void sm5803_handle_interrupt(int chgnum) int int_reg, meas_reg; static bool throttled; - /* Note: Interrupt register is clear on read */ + /* Note: Interrupt registers are clear on read */ + rv = main_read8(chgnum, SM5803_REG_INT1_REQ, &int_reg); + if (rv) { + CPRINTS("%s %d: Failed read int1 register", CHARGER_NAME, + chgnum); + return; + } + + if (int_reg & SM5803_INT1_CHG) { + rv = main_read8(chgnum, SM5803_REG_STATUS1, &meas_reg); + if (!(meas_reg & SM5803_STATUS1_CHG_DET)) { + 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(); + } + } + rv = main_read8(chgnum, SM5803_REG_INT2_REQ, &int_reg); if (rv) { CPRINTS("%s %d: Failed read int2 register", CHARGER_NAME, @@ -541,22 +557,6 @@ void sm5803_handle_interrupt(int chgnum) */ } - if ((int_reg & SM5803_INT2_VBUS) && - !sm5803_is_sourcing_otg_power(chgnum, chgnum)) { - rv = meas_read8(chgnum, SM5803_REG_VBUS_MEAS_MSB, &meas_reg); - if (meas_reg <= SM5803_VBUS_LOW_LEVEL) { - charger_vbus[chgnum] = 0; - usb_charger_vbus_change(chgnum, 0); - board_vbus_present_change(); - } else if (meas_reg >= SM5803_VBUS_HIGH_LEVEL) { - charger_vbus[chgnum] = 1; - usb_charger_vbus_change(chgnum, 1); - board_vbus_present_change(); - } else { - CPRINTS("%s %d: Unexpected Vbus interrupt: 0x%02x", - CHARGER_NAME, chgnum, meas_reg); - } - } } static void sm5803_irq_deferred(void) |