diff --git a/drivers/power/supply/max17042_battery.c b/drivers/power/supply/max17042_battery.c index 3f251034cd..2c7186c686 100644 --- a/drivers/power/supply/max17042_battery.c +++ b/drivers/power/supply/max17042_battery.c @@ -1193,9 +1193,19 @@ static void max17042_set_critical_soc_threshold(struct max17042_chip *chip) 0xff00 + MAX17042_CRITICAL_SOC : 0xff00); } +/* + * The MAX17055 and the MAX77759 raise Status.dSOCi on every whole-percent + * change of the SOC, so they don't need a SALRT window around the current SOC. + */ +static bool max17042_has_dsoci(struct max17042_chip *chip) +{ + return chip->chip_type == MAXIM_DEVICE_TYPE_MAX17055 || + chip->chip_type == MAXIM_DEVICE_TYPE_MAX77759; +} + static void max17042_enable_soc_alerts(struct max17042_chip *chip) { - if (chip->chip_type == MAXIM_DEVICE_TYPE_MAX17055) { + if (max17042_has_dsoci(chip)) { regmap_update_bits(chip->regmap, MAX17055_Config2, CFG2_DSOCI_BIT_ENBL, CFG2_DSOCI_BIT_ENBL); @@ -1208,7 +1218,7 @@ static void max17042_enable_soc_alerts(struct max17042_chip *chip) static void max17042_suspend_soc_alerts(struct max17042_chip *chip) { - if (chip->chip_type != MAXIM_DEVICE_TYPE_MAX17055) + if (!max17042_has_dsoci(chip)) return; regmap_update_bits(chip->regmap, MAX17055_Config2, @@ -1216,6 +1226,24 @@ static void max17042_suspend_soc_alerts(struct max17042_chip *chip) max17042_set_critical_soc_threshold(chip); } +/* + * The MAX77759 releases ALRT only at a fuel-gauge update after Status was + * cleared, up to one task period later. The interrupt is level-triggered and + * oneshot, so it would be taken again every few milliseconds until then, each + * time with Status already clear. Keep it masked until the gauge has updated. + */ +static void max17042_alert_holdoff(struct max17042_chip *chip) +{ + unsigned int period_ms; + + if (chip->chip_type != MAXIM_DEVICE_TYPE_MAX77759) + return; + + /* TaskPeriod counts 1/32768 s; allow half a period of margin */ + period_ms = DIV_ROUND_UP(READ_ONCE(chip->task_period) * 1000, 32768); + msleep(period_ms + period_ms / 2); +} + static irqreturn_t max17042_thread_handler(int id, void *dev) { struct max17042_chip *chip = dev; @@ -1226,6 +1254,12 @@ static irqreturn_t max17042_thread_handler(int id, void *dev) if (ret) return IRQ_HANDLED; + /* Nothing latched: not our interrupt, or ALRT not released yet */ + if (!val) { + max17042_alert_holdoff(chip); + return IRQ_NONE; + } + if ((val & STATUS_SMN_BIT) || (val & STATUS_SMX_BIT) || (val & STATUS_DSOCI_BIT)) { dev_dbg(chip->dev, "SOC threshold INTR\n"); @@ -1237,6 +1271,7 @@ static irqreturn_t max17042_thread_handler(int id, void *dev) 0xFFFF & ~(STATUS_POR_BIT | STATUS_BST_BIT)); power_supply_changed(chip->battery); + max17042_alert_holdoff(chip); return IRQ_HANDLED; } diff --git a/drivers/power/supply/max77759_charger.c b/drivers/power/supply/max77759_charger.c index 572279b060..61e118fd95 100644 --- a/drivers/power/supply/max77759_charger.c +++ b/drivers/power/supply/max77759_charger.c @@ -158,8 +158,12 @@ static int charger_input_valid(struct max77759_charger *chg) if (ret) return ret; - return (val & MAX77759_CHGR_REG_CHG_INT_CHG) && - (val & MAX77759_CHGR_REG_CHG_INT_CHGIN); + /* + * CHGIN alone says whether the input is there. CHG_OK clears when a + * charge is done (and on charger faults), which the status property + * already reports. + */ + return !!(val & MAX77759_CHGR_REG_CHG_INT_CHGIN); } static int get_online(struct max77759_charger *chg) @@ -654,6 +658,16 @@ static int max77759_charger_init(struct max77759_charger *chg) if (ret) goto relock; + /* + * Disable the fast-charge safety timer. At a low input limit a full + * charge outlasts it, and the charger then stops in a timer fault + * with the cable still in, until it is replugged or reset. + */ + ret = regmap_update_bits(chg->regmap, MAX77759_CHGR_REG_CHG_CNFG_01, + MAX77759_CHGR_REG_CHG_CNFG_01_FCHGTIME, 0); + if (ret) + goto relock; + return unlock_prot_regs(chg, false); relock: diff --git a/include/linux/mfd/max77759.h b/include/linux/mfd/max77759.h index 10f400e97c..4c04a600a6 100644 --- a/include/linux/mfd/max77759.h +++ b/include/linux/mfd/max77759.h @@ -91,6 +91,7 @@ #define MAX77759_CHGR_REG_CHG_CNFG_00 0xb9 #define MAX77759_CHGR_REG_CHG_CNFG_00_MODE GENMASK(3, 0) #define MAX77759_CHGR_REG_CHG_CNFG_01 0xba +#define MAX77759_CHGR_REG_CHG_CNFG_01_FCHGTIME GENMASK(2, 0) #define MAX77759_CHGR_REG_CHG_CNFG_02 0xbb #define MAX77759_CHGR_REG_CHG_CNFG_02_CHGCC GENMASK(5, 0) #define MAX77759_CHGR_REG_CHG_CNFG_03 0xbc