diff options
author | Badhri Jagan Sridharan <badhri@google.com> | 2023-03-13 23:50:34 +0000 |
---|---|---|
committer | Badhri Jagan Sridharan <badhri@google.com> | 2023-04-05 01:08:14 +0000 |
commit | 7df383b34d453af72fca03a2e271b5e2435b3f26 (patch) | |
tree | 6c0a10debe1c01e10875b665c2d1e1f8966fa0d5 | |
parent | 46d7f38b1813b34129a32bf7a24c010be86f440a (diff) | |
download | bms-7df383b34d453af72fca03a2e271b5e2435b3f26.tar.gz |
max77759_charger: Enable CHG_INT_OK.AICL_OK interrupt
CHG_INT_OK.AICL_OK tracks whether the input voltage
regulation loop is kicking in. Vote on AICL_ACTIVE_EL
when the status changes.
No evidence of system rapidly going in and out of AICL
to cause interrupt storm so far. If needed,
CHG_INT_OK.AICL_OK can be throttled. i.e. enable once
per plug-in event.
Bug: 273366006
Test: Connect to a weak power source and make sure
AICL interrupts are triggered.
Change-Id: I4ff7fbcd9fc847c2cf256d3386163cffb67d1f98
Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
-rw-r--r-- | max77759_charger.c | 38 | ||||
-rw-r--r-- | max77759_charger.h | 2 |
2 files changed, 39 insertions, 1 deletions
diff --git a/max77759_charger.c b/max77759_charger.c index 065955e..e3bcf66 100644 --- a/max77759_charger.c +++ b/max77759_charger.c @@ -2678,6 +2678,32 @@ static const struct regmap_config max77759_chg_regmap_cfg = { }; +static void max77759_aicl_changed(struct max77759_chgr_data *data) +{ + uint8_t int_ok; + int ret; + bool aicl_active; + + ret = max77759_reg_read(data->regmap, MAX77759_CHG_INT_OK, &int_ok); + if (ret) { + dev_err(data->dev, "%s:Failed to read MAX77759_CHG_INT_OK.AICL_OK ret:%d\n", __func__, ret); + return; + } + + aicl_active = !(int_ok & MAX77759_CHG_INT_OK_AICL_OK); + + if (IS_ERR_OR_NULL(data->aicl_active_el)) + data->aicl_active_el = + gvotable_election_get_handle("AICL_ACTIVE_EL"); + + if (IS_ERR_OR_NULL(data->aicl_active_el)) { + dev_err(data->dev, "AICL_ACTIVE_EL get failed %ld\n", + PTR_ERR(data->aicl_active_el)); + return; + } + + gvotable_cast_long_vote(data->aicl_active_el, "BMS_VOTER", aicl_active, aicl_active); +} /* * int[0] @@ -2705,9 +2731,14 @@ static const struct regmap_config max77759_chg_regmap_cfg = { * MAX77759_CHG_INT2_MASK_CHG_STA_CC_M | * MAX77759_CHG_INT2_MASK_CHG_STA_CV_M | * MAX77759_CHG_INT_MASK_CHG_M + * + * TODO: MAX77759_CHG_INT_MASK_AICL_M needs to be throttled + * if system keeps going in and out of AICL regulation. + * No evidenvce of this happening so far. */ static u8 max77759_int_mask[MAX77759_CHG_INT_COUNT] = { - ~(MAX77759_CHG_INT_MASK_CHGIN_M | + (u8)~(MAX77759_CHG_INT_MASK_AICL_M | + MAX77759_CHG_INT_MASK_CHGIN_M | MAX77759_CHG_INT_MASK_WCIN_M | MAX77759_CHG_INT_MASK_BAT_M | MAX77759_CHG_INT_MASK_THM2_M_MASK), @@ -2818,6 +2849,11 @@ static irqreturn_t max77759_chgr_irq(int irq, void *client) charge_done, data->charge_done); } + if (chg_int[0] & MAX77759_CHG_INT_AICL_I) { + pr_debug("%s: AICL state change\n", __func__); + max77759_aicl_changed(data); + } + /* wired input is changed */ if (chg_int[0] & MAX77759_CHG_INT_MASK_CHGIN_M) { pr_debug("%s: CHGIN charge_done=%d\n", __func__, data->charge_done); diff --git a/max77759_charger.h b/max77759_charger.h index 3f163d6..dfbe846 100644 --- a/max77759_charger.h +++ b/max77759_charger.h @@ -66,6 +66,8 @@ struct max77759_chgr_data { /* debug interface, register to read or write */ u32 debug_reg_address; + struct gvotable_election *aicl_active_el; + /* thermal BCL */ #if IS_ENABLED(CONFIG_GOOGLE_BCL) struct bcl_device *bcl_dev; |