]> git.dujemihanovic.xyz Git - linux.git/commitdiff
power: supply: generic-adc-battery: simplify read_channel logic
authorSebastian Reichel <sre@kernel.org>
Fri, 17 Mar 2023 22:57:02 +0000 (23:57 +0100)
committerSebastian Reichel <sre@kernel.org>
Wed, 29 Mar 2023 20:38:57 +0000 (22:38 +0200)
Drop mostly useless gab_prop_to_chan() function by directly
supplying the correct enum value to read_channel().

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>
Signed-off-by: Sebastian Reichel <sre@kernel.org>
drivers/power/supply/generic-adc-battery.c

index 42765cbf75181596993a481f1bcda9607898534b..4811e72df8cda737db87dff7986d02d6e9fbd24b 100644 (file)
@@ -86,31 +86,12 @@ static bool gab_charge_finished(struct gab *adc_bat)
        return gpiod_get_value(adc_bat->charge_finished);
 }
 
-static enum gab_chan_type gab_prop_to_chan(enum power_supply_property psp)
-{
-       switch (psp) {
-       case POWER_SUPPLY_PROP_POWER_NOW:
-               return GAB_POWER;
-       case POWER_SUPPLY_PROP_VOLTAGE_NOW:
-               return GAB_VOLTAGE;
-       case POWER_SUPPLY_PROP_CURRENT_NOW:
-               return GAB_CURRENT;
-       default:
-               WARN_ON(1);
-               break;
-       }
-       return GAB_POWER;
-}
-
-static int read_channel(struct gab *adc_bat, enum power_supply_property psp,
+static int read_channel(struct gab *adc_bat, enum gab_chan_type channel,
                int *result)
 {
        int ret;
-       int chan_index;
 
-       chan_index = gab_prop_to_chan(psp);
-       ret = iio_read_channel_processed(adc_bat->channel[chan_index],
-                       result);
+       ret = iio_read_channel_processed(adc_bat->channel[channel], result);
        if (ret < 0)
                pr_err("read channel error\n");
        else
@@ -123,26 +104,20 @@ static int gab_get_property(struct power_supply *psy,
                enum power_supply_property psp, union power_supply_propval *val)
 {
        struct gab *adc_bat = to_generic_bat(psy);
-       int result = 0;
-       int ret = 0;
 
        switch (psp) {
        case POWER_SUPPLY_PROP_STATUS:
                val->intval = adc_bat->status;
                return 0;
        case POWER_SUPPLY_PROP_VOLTAGE_NOW:
+               return read_channel(adc_bat, GAB_VOLTAGE, &val->intval);
        case POWER_SUPPLY_PROP_CURRENT_NOW:
+               return read_channel(adc_bat, GAB_CURRENT, &val->intval);
        case POWER_SUPPLY_PROP_POWER_NOW:
-               ret = read_channel(adc_bat, psp, &result);
-               if (ret < 0)
-                       goto err;
-               val->intval = result;
-               break;
+               return read_channel(adc_bat, GAB_POWER, &val->intval);
        default:
                return -EINVAL;
        }
-err:
-       return ret;
 }
 
 static void gab_work(struct work_struct *work)