OSDN Git Service

power: supply: sbs-battery: combine get_presence_and_health
authorIkjoon Jang <ikjn@chromium.org>
Thu, 13 Aug 2020 05:10:07 +0000 (13:10 +0800)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Thu, 27 Aug 2020 21:56:37 +0000 (23:56 +0200)
This patch enables calling sbs_get_battery_presence_and_health()
without checking its chip type. No functional changes.

Signed-off-by: Ikjoon Jang <ikjn@chromium.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
drivers/power/supply/sbs-battery.c

index 5dfb872..6273211 100644 (file)
@@ -473,37 +473,6 @@ static bool sbs_bat_needs_calibration(struct i2c_client *client)
        return !!(ret & BIT(7));
 }
 
-static int sbs_get_battery_presence_and_health(
-       struct i2c_client *client, enum power_supply_property psp,
-       union power_supply_propval *val)
-{
-       int ret;
-
-       /* Dummy command; if it succeeds, battery is present. */
-       ret = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);
-
-       if (ret < 0) { /* battery not present*/
-               if (psp == POWER_SUPPLY_PROP_PRESENT) {
-                       val->intval = 0;
-                       return 0;
-               }
-               return ret;
-       }
-
-       if (psp == POWER_SUPPLY_PROP_PRESENT)
-               val->intval = 1; /* battery present */
-       else { /* POWER_SUPPLY_PROP_HEALTH */
-               if (sbs_bat_needs_calibration(client)) {
-                       val->intval = POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED;
-               } else {
-                       /* SBS spec doesn't have a general health command. */
-                       val->intval = POWER_SUPPLY_HEALTH_UNKNOWN;
-               }
-       }
-
-       return 0;
-}
-
 static int sbs_get_ti_battery_presence_and_health(
        struct i2c_client *client, enum power_supply_property psp,
        union power_supply_propval *val)
@@ -562,6 +531,41 @@ static int sbs_get_ti_battery_presence_and_health(
        return 0;
 }
 
+static int sbs_get_battery_presence_and_health(
+       struct i2c_client *client, enum power_supply_property psp,
+       union power_supply_propval *val)
+{
+       struct sbs_info *chip = i2c_get_clientdata(client);
+       int ret;
+
+       if (chip->flags & SBS_FLAGS_TI_BQ20ZX5)
+               return sbs_get_ti_battery_presence_and_health(client, psp, val);
+
+       /* Dummy command; if it succeeds, battery is present. */
+       ret = sbs_read_word_data(client, sbs_data[REG_STATUS].addr);
+
+       if (ret < 0) { /* battery not present*/
+               if (psp == POWER_SUPPLY_PROP_PRESENT) {
+                       val->intval = 0;
+                       return 0;
+               }
+               return ret;
+       }
+
+       if (psp == POWER_SUPPLY_PROP_PRESENT)
+               val->intval = 1; /* battery present */
+       else { /* POWER_SUPPLY_PROP_HEALTH */
+               if (sbs_bat_needs_calibration(client)) {
+                       val->intval = POWER_SUPPLY_HEALTH_CALIBRATION_REQUIRED;
+               } else {
+                       /* SBS spec doesn't have a general health command. */
+                       val->intval = POWER_SUPPLY_HEALTH_UNKNOWN;
+               }
+       }
+
+       return 0;
+}
+
 static int sbs_get_battery_property(struct i2c_client *client,
        int reg_offset, enum power_supply_property psp,
        union power_supply_propval *val)
@@ -864,12 +868,7 @@ static int sbs_get_property(struct power_supply *psy,
        switch (psp) {
        case POWER_SUPPLY_PROP_PRESENT:
        case POWER_SUPPLY_PROP_HEALTH:
-               if (chip->flags & SBS_FLAGS_TI_BQ20ZX5)
-                       ret = sbs_get_ti_battery_presence_and_health(client,
-                                                                    psp, val);
-               else
-                       ret = sbs_get_battery_presence_and_health(client, psp,
-                                                                 val);
+               ret = sbs_get_battery_presence_and_health(client, psp, val);
 
                /* this can only be true if no gpio is used */
                if (psp == POWER_SUPPLY_PROP_PRESENT)