Skip to content

Commit 9489d1b

Browse files
committed
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>
1 parent 1b27bf7 commit 9489d1b

1 file changed

Lines changed: 5 additions & 30 deletions

File tree

drivers/power/supply/generic-adc-battery.c

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -86,31 +86,12 @@ static bool gab_charge_finished(struct gab *adc_bat)
8686
return gpiod_get_value(adc_bat->charge_finished);
8787
}
8888

89-
static enum gab_chan_type gab_prop_to_chan(enum power_supply_property psp)
90-
{
91-
switch (psp) {
92-
case POWER_SUPPLY_PROP_POWER_NOW:
93-
return GAB_POWER;
94-
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
95-
return GAB_VOLTAGE;
96-
case POWER_SUPPLY_PROP_CURRENT_NOW:
97-
return GAB_CURRENT;
98-
default:
99-
WARN_ON(1);
100-
break;
101-
}
102-
return GAB_POWER;
103-
}
104-
105-
static int read_channel(struct gab *adc_bat, enum power_supply_property psp,
89+
static int read_channel(struct gab *adc_bat, enum gab_chan_type channel,
10690
int *result)
10791
{
10892
int ret;
109-
int chan_index;
11093

111-
chan_index = gab_prop_to_chan(psp);
112-
ret = iio_read_channel_processed(adc_bat->channel[chan_index],
113-
result);
94+
ret = iio_read_channel_processed(adc_bat->channel[channel], result);
11495
if (ret < 0)
11596
pr_err("read channel error\n");
11697
else
@@ -123,26 +104,20 @@ static int gab_get_property(struct power_supply *psy,
123104
enum power_supply_property psp, union power_supply_propval *val)
124105
{
125106
struct gab *adc_bat = to_generic_bat(psy);
126-
int result = 0;
127-
int ret = 0;
128107

129108
switch (psp) {
130109
case POWER_SUPPLY_PROP_STATUS:
131110
val->intval = adc_bat->status;
132111
return 0;
133112
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
113+
return read_channel(adc_bat, GAB_VOLTAGE, &val->intval);
134114
case POWER_SUPPLY_PROP_CURRENT_NOW:
115+
return read_channel(adc_bat, GAB_CURRENT, &val->intval);
135116
case POWER_SUPPLY_PROP_POWER_NOW:
136-
ret = read_channel(adc_bat, psp, &result);
137-
if (ret < 0)
138-
goto err;
139-
val->intval = result;
140-
break;
117+
return read_channel(adc_bat, GAB_POWER, &val->intval);
141118
default:
142119
return -EINVAL;
143120
}
144-
err:
145-
return ret;
146121
}
147122

148123
static void gab_work(struct work_struct *work)

0 commit comments

Comments
 (0)