]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
power: supply: bq257xx: Consistently use indirect get/set helpers
authorAlexey Charkov <alchark@flipper.net>
Tue, 2 Jun 2026 20:10:52 +0000 (00:10 +0400)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Wed, 3 Jun 2026 20:44:29 +0000 (22:44 +0200)
Move the remaining get/set helper functions to indirect calls via the
per-chip bq257xx_chip_info struct.

This improves the consistency of the code and prepares the driver to
support multiple chip variants with different register layouts and bit
definitions.

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

index 39718223c3f9ce26264b66abd3fc79bed6ac8644..0765673728e4360f131c775c4ff974de7d43dc68 100644 (file)
@@ -22,18 +22,30 @@ struct bq257xx_chg;
  * @bq257xx_hw_init: init function for hw
  * @bq257xx_hw_shutdown: shutdown function for hw
  * @bq257xx_get_state: get and update state of hardware
+ * @bq257xx_get_ichg: get maximum charge current (in uA)
  * @bq257xx_set_ichg: set maximum charge current (in uA)
+ * @bq257xx_get_vbatreg: get maximum charge voltage (in uV)
  * @bq257xx_set_vbatreg: set maximum charge voltage (in uV)
+ * @bq257xx_get_iindpm: get maximum input current (in uA)
  * @bq257xx_set_iindpm: set maximum input current (in uA)
+ * @bq257xx_get_cur: get battery current from ADC (in uA)
+ * @bq257xx_get_vbat: get battery voltage from ADC (in uV)
+ * @bq257xx_get_min_vsys: get minimum system voltage (in uV)
  */
 struct bq257xx_chip_info {
        int default_iindpm_uA;
        int (*bq257xx_hw_init)(struct bq257xx_chg *pdata);
        void (*bq257xx_hw_shutdown)(struct bq257xx_chg *pdata);
        int (*bq257xx_get_state)(struct bq257xx_chg *pdata);
+       int (*bq257xx_get_ichg)(struct bq257xx_chg *pdata, int *intval);
        int (*bq257xx_set_ichg)(struct bq257xx_chg *pdata, int ichg);
+       int (*bq257xx_get_vbatreg)(struct bq257xx_chg *pdata, int *intval);
        int (*bq257xx_set_vbatreg)(struct bq257xx_chg *pdata, int vbatreg);
+       int (*bq257xx_get_iindpm)(struct bq257xx_chg *pdata, int *intval);
        int (*bq257xx_set_iindpm)(struct bq257xx_chg *pdata, int iindpm);
+       int (*bq257xx_get_cur)(struct bq257xx_chg *pdata, int *intval);
+       int (*bq257xx_get_vbat)(struct bq257xx_chg *pdata, int *intval);
+       int (*bq257xx_get_min_vsys)(struct bq257xx_chg *pdata, int *intval);
 };
 
 /**
@@ -490,22 +502,22 @@ static int bq257xx_get_charger_property(struct power_supply *psy,
                break;
 
        case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
-               return bq25703_get_iindpm(pdata, &val->intval);
+               return pdata->chip->bq257xx_get_iindpm(pdata, &val->intval);
 
        case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
-               return bq25703_get_chrg_volt(pdata, &val->intval);
+               return pdata->chip->bq257xx_get_vbatreg(pdata, &val->intval);
 
        case POWER_SUPPLY_PROP_CURRENT_NOW:
-               return bq25703_get_cur(pdata, &val->intval);
+               return pdata->chip->bq257xx_get_cur(pdata, &val->intval);
 
        case POWER_SUPPLY_PROP_VOLTAGE_NOW:
-               return bq25703_get_vbat(pdata, &val->intval);
+               return pdata->chip->bq257xx_get_vbat(pdata, &val->intval);
 
        case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
-               return bq25703_get_ichg_cur(pdata, &val->intval);
+               return pdata->chip->bq257xx_get_ichg(pdata, &val->intval);
 
        case POWER_SUPPLY_PROP_VOLTAGE_MIN:
-               return bq25703_get_min_vsys(pdata, &val->intval);
+               return pdata->chip->bq257xx_get_min_vsys(pdata, &val->intval);
 
        case POWER_SUPPLY_PROP_USB_TYPE:
                val->intval = pdata->usb_type;
@@ -633,9 +645,15 @@ static const struct bq257xx_chip_info bq25703_chip_info = {
                .bq257xx_hw_init = &bq25703_hw_init,
                .bq257xx_hw_shutdown = &bq25703_hw_shutdown,
                .bq257xx_get_state = &bq25703_get_state,
+               .bq257xx_get_ichg = &bq25703_get_ichg_cur,
                .bq257xx_set_ichg = &bq25703_set_ichg_cur,
+               .bq257xx_get_vbatreg = &bq25703_get_chrg_volt,
                .bq257xx_set_vbatreg = &bq25703_set_chrg_volt,
+               .bq257xx_get_iindpm = &bq25703_get_iindpm,
                .bq257xx_set_iindpm = &bq25703_set_iindpm,
+               .bq257xx_get_cur = &bq25703_get_cur,
+               .bq257xx_get_vbat = &bq25703_get_vbat,
+               .bq257xx_get_min_vsys = &bq25703_get_min_vsys,
 };
 
 /**