power: supply: generic-adc-battery: simplify read_channel logic
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>
This commit is contained in:
parent
1b27bf793f
commit
9489d1bdb7
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user