Skip to content

Commit

Permalink
power: supply: ln8411: Clears CP_EN when protection fault is hit
Browse files Browse the repository at this point in the history
Clears CP_EN through power_supply when any of the COMP_FLAG
protections mentioned in 'Protections' in the d/s are tripped.

This is necessary as CP_EN does not autoclear after a protection
fault.

Change-Id: Id649eda39ff630eb2a77ac7ce683e61848d9f9ad
Signed-off-by: Ricardo Rivera-Matos <rriveram@opensource.cirrus.com>
  • Loading branch information
rriveramcrus committed Jun 28, 2023
1 parent 0c64ad1 commit da76abf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
27 changes: 17 additions & 10 deletions drivers/power/supply/ln8411_charger.c
Original file line number Diff line number Diff line change
Expand Up @@ -874,32 +874,39 @@ static int ln8411_post_irq_handler(void *irq_drv_data)
{
struct ln8411_device *ln8411 = irq_drv_data;
union power_supply_propval val = {0};
bool protect_flt_set = false;
unsigned int reg;
int ret;

ret = regmap_read(ln8411->regmap, LN8411_COMP_FLAG0, &reg);
if (ret)
return ret;

/* CP_EN bit does not auto clear during unplug, must be manually cleared*/
if (reg & LN8411_IBUS_UCP_FALL_FLAG) {
val.intval = POWER_SUPPLY_STATUS_NOT_CHARGING;

ret = power_supply_set_property(ln8411->charger, POWER_SUPPLY_PROP_STATUS, &val);
if (ret)
return ret;

dev_dbg(ln8411->dev, "Unplug detected, disabling converter\n");
}
if (reg & LN8411_PROTECT_FLTS_COMP_FLAG0)
protect_flt_set = true;

dev_dbg(ln8411->dev, "COMP_FLAG0: 0x%x\n", reg);

ret = regmap_read(ln8411->regmap, LN8411_COMP_FLAG1, &reg);
if (ret)
return ret;

if (reg & LN8411_PROTECT_FLTS_COMP_FLAG1)
protect_flt_set = true;

dev_dbg(ln8411->dev, "COMP_FLAG1: 0x%x\n", reg);

/* CP_EN bit does not auto clear during protection fault, must be manually cleared */
if (protect_flt_set) {
val.intval = POWER_SUPPLY_STATUS_NOT_CHARGING;

ret = power_supply_set_property(ln8411->charger, POWER_SUPPLY_PROP_STATUS, &val);
if (ret)
return ret;

dev_dbg(ln8411->dev, "Fault detected, disabling converter\n");
}

ret = regmap_set_bits(ln8411->regmap, LN8411_LION_INT_MASK_2, LN8411_CLEAR_INT);
if (ret)
return ret;
Expand Down
10 changes: 10 additions & 0 deletions drivers/power/supply/ln8411_charger.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,16 @@
#define LN8411_OTG_MIN_1TO2_MIN_UV (LN8411_OTG_MIN_UV * 2)
#define LN8411_OTG_MIN_1TO4_MIN_UV (LN8411_OTG_MIN_UV * 4)

#define LN8411_PROTECT_FLTS_COMP_FLAG0 (LN8411_VUSB_OVP_FLAG | \
LN8411_VWPC_OVP_FLAG | \
LN8411_IBUS_OCP_FLAG | \
LN8411_IBUS_UCP_FALL_FLAG | \
LN8411_VBAT_OVP_FLAG | \
LN8411_IBAT_OCP_FLAG)

#define LN8411_PROTECT_FLTS_COMP_FLAG1 (LN8411_PMID2OUT_UVP_FLAG | \
LN8411_PMID2OUT_OVP_FLAG)

enum ln8411_roles {
LN8411_USB = 0,
LN8411_DUAL,
Expand Down

0 comments on commit da76abf

Please sign in to comment.