]> www.infradead.org Git - users/willy/xarray.git/commitdiff
power: ip5xxx_power: Check for optional bits
authorCsókás, Bence <csokas.bence@prolan.hu>
Tue, 19 Nov 2024 18:07:37 +0000 (19:07 +0100)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Thu, 5 Dec 2024 00:07:08 +0000 (01:07 +0100)
Some parts may not have certain control bits. These bits
however may be non-essential to the system's operation,
as the default behaviour is the one we would set anyways,
or the bits are not applicable for said part (e. g. enabling
NTC on a part without an NTC pin, or one where it cannot
be disabled via registers anyways).

Signed-off-by: Csókás, Bence <csokas.bence@prolan.hu>
Link: https://lore.kernel.org/r/20241119180741.2237692-5-csokas.bence@prolan.hu
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/ip5xxx_power.c

index f64767b81c3b7b02e704e968a85c19fa98f8117e..2c4d338574d70bc531800b11cad5f61aaba77c17 100644 (file)
@@ -206,9 +206,11 @@ static int ip5xxx_initialize(struct power_supply *psy)
         * Disable shutdown under light load.
         * Enable power on when under load.
         */
-       ret = ip5xxx_write(ip5xxx, ip5xxx->regs.boost.light_load_shutdown.enable, 0);
-       if (ret)
-               return ret;
+       if (ip5xxx->regs.boost.light_load_shutdown.enable) {
+               ret = ip5xxx_write(ip5xxx, ip5xxx->regs.boost.light_load_shutdown.enable, 0);
+               if (ret)
+                       return ret;
+       }
        ret = ip5xxx_write(ip5xxx, ip5xxx->regs.boost.load_powerup_en, 1);
        if (ret)
                return ret;
@@ -231,9 +233,11 @@ static int ip5xxx_initialize(struct power_supply *psy)
         * Enable the NTC.
         * Configure the button for two presses => LED, long press => shutdown.
         */
-       ret = ip5xxx_write(ip5xxx, ip5xxx->regs.battery.ntc_dis, 0);
-       if (ret)
-               return ret;
+       if (ip5xxx->regs.battery.ntc_dis) {
+               ret = ip5xxx_write(ip5xxx, ip5xxx->regs.battery.ntc_dis, 0);
+               if (ret)
+                       return ret;
+       }
        ret = ip5xxx_write(ip5xxx, ip5xxx->regs.btn.wled_mode, 1);
        if (ret)
                return ret;
@@ -507,9 +511,12 @@ static int ip5xxx_battery_set_voltage_max(struct ip5xxx *ip5xxx, int val)
        if (ret)
                return ret;
 
-       ret = ip5xxx_write(ip5xxx, ip5xxx->regs.battery.vset_en, 1);
-       if (ret)
-               return ret;
+       /* Don't try to auto-detect battery type, even if the IC could */
+       if (ip5xxx->regs.battery.vset_en) {
+               ret = ip5xxx_write(ip5xxx, ip5xxx->regs.battery.vset_en, 1);
+               if (ret)
+                       return ret;
+       }
 
        return 0;
 }