]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
power: supply: bq257xx: Add fields for 'charging' and 'overvoltage' states
authorAlexey Charkov <alchark@flipper.net>
Tue, 2 Jun 2026 20:10:53 +0000 (00:10 +0400)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Wed, 3 Jun 2026 20:44:32 +0000 (22:44 +0200)
The driver currently reports the 'charging' and 'overvoltage' states based
on a logical expression in the get_charger_property() wrapper function.
This doesn't scale well to other chip variants, which may have a different
number and type of hardware reported conditions which fall into these
broad power supply states.

Move the logic for determining 'charging' and 'overvoltage' states into
chip-specific accessors, which can be overridden by each variant as
needed.

This helps keep the get_charger_property() wrapper function chip-agnostic
while allowing for new chip variants to be added bringing their own logic.

Tested-by: Chris Morgan <macromorgan@hotmail.com>
Signed-off-by: Alexey Charkov <alchark@flipper.net>
Link: https://patch.msgid.link/20260603-bq25792-v7-5-d487bed276d0@flipper.net
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/bq257xx_charger.c

index 0765673728e4360f131c775c4ff974de7d43dc68..9c082865e745bbfef41b8249c6c07895cf9e4491 100644 (file)
@@ -54,8 +54,10 @@ struct bq257xx_chip_info {
  * @bq: parent MFD device
  * @charger: power supply device
  * @online: charger input is present
+ * @charging: charger is actively charging the battery
  * @fast_charge: charger is in fast charge mode
  * @pre_charge: charger is in pre-charge mode
+ * @overvoltage: overvoltage fault detected
  * @ov_fault: charger reports over voltage fault
  * @batoc_fault: charger reports battery over current fault
  * @oc_fault: charger reports over current fault
@@ -71,8 +73,10 @@ struct bq257xx_chg {
        struct bq257xx_device *bq;
        struct power_supply *charger;
        bool online;
+       bool charging;
        bool fast_charge;
        bool pre_charge;
+       bool overvoltage;
        bool ov_fault;
        bool batoc_fault;
        bool oc_fault;
@@ -106,8 +110,10 @@ static int bq25703_get_state(struct bq257xx_chg *pdata)
        pdata->online = reg & BQ25703_STS_AC_STAT;
        pdata->fast_charge = reg & BQ25703_STS_IN_FCHRG;
        pdata->pre_charge = reg & BQ25703_STS_IN_PCHRG;
+       pdata->charging = pdata->fast_charge || pdata->pre_charge;
        pdata->ov_fault = reg & BQ25703_STS_FAULT_ACOV;
        pdata->batoc_fault = reg & BQ25703_STS_FAULT_BATOC;
+       pdata->overvoltage = pdata->ov_fault || pdata->batoc_fault;
        pdata->oc_fault = reg & BQ25703_STS_FAULT_ACOC;
 
        return 0;
@@ -478,14 +484,14 @@ static int bq257xx_get_charger_property(struct power_supply *psy,
        case POWER_SUPPLY_PROP_STATUS:
                if (!pdata->online)
                        val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
-               else if (pdata->fast_charge || pdata->pre_charge)
+               else if (pdata->charging)
                        val->intval = POWER_SUPPLY_STATUS_CHARGING;
                else
                        val->intval = POWER_SUPPLY_STATUS_NOT_CHARGING;
                break;
 
        case POWER_SUPPLY_PROP_HEALTH:
-               if (pdata->ov_fault || pdata->batoc_fault)
+               if (pdata->overvoltage)
                        val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE;
                else if (pdata->oc_fault)
                        val->intval = POWER_SUPPLY_HEALTH_OVERCURRENT;