Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions drivers/power/supply/max17042_battery.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -1208,14 +1218,32 @@ 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,
CFG2_DSOCI_BIT_ENBL, 0);
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;
Expand All @@ -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");
Expand All @@ -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;
}

Expand Down
18 changes: 16 additions & 2 deletions drivers/power/supply/max77759_charger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions include/linux/mfd/max77759.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down