[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <f6d18e80-a7ef-175b-dfa8-5c311c393e0b@redhat.com>
Date: Sun, 7 Nov 2021 21:46:30 +0100
From: Hans de Goede <hdegoede@...hat.com>
To: Yauhen Kharuzhy <jekhor@...il.com>,
Sebastian Reichel <sre@...nel.org>
Cc: linux-pm@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 3/4] power supply bq25890-charger: Handle temperature
faults
Hi,
On 11/7/21 21:20, Yauhen Kharuzhy wrote:
> 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@...il.com>
Thank you for your patch,
Patch subject prefix should be: "power: supply: bq25890: "
> ---
> 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;
> +
You only use the read value if bq->state.ntc_fault == NTC_FAULT_COOL
and i2c reads are somewhat expensive (or at least slow), can you
please move this to inside the
"if (bq->state.ntc_fault == NTC_FAULT_COOL) {" block ?
This is esp. relevant since this condition will normally be false,
so normally this will save us an i2c_read for every read of the
POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX property.
> 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}
Copy paste error? Surely the field in the second line must be F_NTG_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;
> }
>
Regards,
Hans
Powered by blists - more mailing lists