[PATCH 3/4] power supply bq25890-charger: Handle temperature faults

From: Yauhen Kharuzhy
Date: Sun Nov 07 2021 - 15:20:40 EST


Add debug info about thermal failure to message in
bq25890_get_chip_state().

Take into account possible thermal failure when calculating a
POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX value as it described in
datasheet (in cold conditions a current limit is decreased to 20% or 50% of
ICHG field value depended on JEITA_ISET field).

Signed-off-by: Yauhen Kharuzhy <jekhor@xxxxxxxxx>
---
drivers/power/supply/bq25890_charger.c | 33 +++++++++++++++++++++++---
1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c
index 1c43555d5bd8..fb2f1578503c 100644
--- a/drivers/power/supply/bq25890_charger.c
+++ b/drivers/power/supply/bq25890_charger.c
@@ -95,6 +95,7 @@ struct bq25890_state {
u8 vsys_status;
u8 boost_fault;
u8 bat_fault;
+ u8 ntc_fault;
};

struct bq25890_device {
@@ -384,6 +385,14 @@ enum bq25890_chrg_fault {
CHRG_FAULT_TIMER_EXPIRED,
};

+enum bq25890_ntc_fault {
+ NTC_FAULT_NORMAL = 0,
+ NTC_FAULT_WARM = 2,
+ NTC_FAULT_COOL = 3,
+ NTC_FAULT_COLD = 5,
+ NTC_FAULT_HOT = 6,
+};
+
static bool bq25890_is_adc_property(enum power_supply_property psp)
{
switch (psp) {
@@ -474,7 +483,19 @@ static int bq25890_power_supply_get_property(struct power_supply *psy,
break;

case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
+ ret = bq25890_field_read(bq, F_JEITA_ISET);
+ if (ret < 0)
+ return ret;
+
val->intval = bq25890_find_val(bq->init_data.ichg, TBL_ICHG);
+
+ /* When temperature is too low, charge current is decreased */
+ if (bq->state.ntc_fault == NTC_FAULT_COOL) {
+ if (ret)
+ val->intval /= 5;
+ else
+ val->intval /= 2;
+ }
break;

case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
@@ -487,6 +508,10 @@ static int bq25890_power_supply_get_property(struct power_supply *psy,
if (ret < 0)
return ret;

+ ret = bq25890_field_read(bq, F_JEITA_VSET);
+ if (ret < 0)
+ return ret;
+
/* converted_val = 2.304V + ADC_val * 20mV (table 10.3.15) */
val->intval = 2304000 + ret * 20000;
break;
@@ -550,7 +575,8 @@ static int bq25890_get_chip_state(struct bq25890_device *bq,
{F_VSYS_STAT, &state->vsys_status},
{F_BOOST_FAULT, &state->boost_fault},
{F_BAT_FAULT, &state->bat_fault},
- {F_CHG_FAULT, &state->chrg_fault}
+ {F_CHG_FAULT, &state->chrg_fault},
+ {F_CHG_FAULT, &state->ntc_fault}
};

for (i = 0; i < ARRAY_SIZE(state_fields); i++) {
@@ -561,9 +587,10 @@ static int bq25890_get_chip_state(struct bq25890_device *bq,
*state_fields[i].data = ret;
}

- dev_dbg(bq->dev, "S:CHG/PG/VSYS=%d/%d/%d, F:CHG/BOOST/BAT=%d/%d/%d\n",
+ dev_dbg(bq->dev, "S:CHG/PG/VSYS=%d/%d/%d, F:CHG/BOOST/BAT/NTC=%d/%d/%d/%d\n",
state->chrg_status, state->online, state->vsys_status,
- state->chrg_fault, state->boost_fault, state->bat_fault);
+ state->chrg_fault, state->boost_fault, state->bat_fault,
+ state->ntc_fault);

return 0;
}
--
2.33.1