Skip to content

Commit 1b27bf7

Browse files
committed
power: supply: generic-adc-battery: use simple-battery API
Constant battery data is available through power-supply's simple-battery API. This works automatically, so the manual handling can be removed without loosing any feature :) Note, that the POWER_SUPPLY_STATUS_FULL check for the level variable can be dropped, since the variable is never written. It can be re-introduced properly once the driver gets functionality to calculate the current charge level. Apart from that the check must be done fuzzy anyways, since charge estimation usually is not precise enough to always return exactly the full charge capacity for a full battery. 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 2f25b97 commit 1b27bf7

2 files changed

Lines changed: 4 additions & 74 deletions

File tree

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

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include <linux/slab.h>
2323
#include <linux/iio/consumer.h>
2424
#include <linux/iio/types.h>
25-
#include <linux/power/generic-adc-battery.h>
2625
#include <linux/devm-helpers.h>
2726

2827
#define JITTER_DEFAULT 10 /* hope 10ms is enough */
@@ -48,9 +47,7 @@ struct gab {
4847
struct power_supply *psy;
4948
struct power_supply_desc psy_desc;
5049
struct iio_channel *channel[GAB_MAX_CHAN_TYPE];
51-
struct gab_platform_data *pdata;
5250
struct delayed_work bat_work;
53-
int level;
5451
int status;
5552
bool cable_plugged;
5653
struct gpio_desc *charge_finished;
@@ -70,14 +67,6 @@ static void gab_ext_power_changed(struct power_supply *psy)
7067

7168
static const enum power_supply_property gab_props[] = {
7269
POWER_SUPPLY_PROP_STATUS,
73-
POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN,
74-
POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN,
75-
POWER_SUPPLY_PROP_VOLTAGE_NOW,
76-
POWER_SUPPLY_PROP_CURRENT_NOW,
77-
POWER_SUPPLY_PROP_TECHNOLOGY,
78-
POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
79-
POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN,
80-
POWER_SUPPLY_PROP_MODEL_NAME,
8170
};
8271

8372
/*
@@ -97,17 +86,6 @@ static bool gab_charge_finished(struct gab *adc_bat)
9786
return gpiod_get_value(adc_bat->charge_finished);
9887
}
9988

100-
static int gab_get_status(struct gab *adc_bat)
101-
{
102-
struct gab_platform_data *pdata = adc_bat->pdata;
103-
struct power_supply_info *bat_info;
104-
105-
bat_info = &pdata->battery_info;
106-
if (adc_bat->level == bat_info->charge_full_design)
107-
return POWER_SUPPLY_STATUS_FULL;
108-
return adc_bat->status;
109-
}
110-
11189
static enum gab_chan_type gab_prop_to_chan(enum power_supply_property psp)
11290
{
11391
switch (psp) {
@@ -144,27 +122,14 @@ static int read_channel(struct gab *adc_bat, enum power_supply_property psp,
144122
static int gab_get_property(struct power_supply *psy,
145123
enum power_supply_property psp, union power_supply_propval *val)
146124
{
147-
struct gab *adc_bat;
148-
struct gab_platform_data *pdata;
149-
struct power_supply_info *bat_info;
125+
struct gab *adc_bat = to_generic_bat(psy);
150126
int result = 0;
151127
int ret = 0;
152128

153-
adc_bat = to_generic_bat(psy);
154-
if (!adc_bat) {
155-
dev_err(&psy->dev, "no battery infos ?!\n");
156-
return -EINVAL;
157-
}
158-
pdata = adc_bat->pdata;
159-
bat_info = &pdata->battery_info;
160-
161129
switch (psp) {
162130
case POWER_SUPPLY_PROP_STATUS:
163-
val->intval = gab_get_status(adc_bat);
164-
break;
165-
case POWER_SUPPLY_PROP_CHARGE_EMPTY_DESIGN:
166-
val->intval = 0;
167-
break;
131+
val->intval = adc_bat->status;
132+
return 0;
168133
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
169134
case POWER_SUPPLY_PROP_CURRENT_NOW:
170135
case POWER_SUPPLY_PROP_POWER_NOW:
@@ -173,21 +138,6 @@ static int gab_get_property(struct power_supply *psy,
173138
goto err;
174139
val->intval = result;
175140
break;
176-
case POWER_SUPPLY_PROP_TECHNOLOGY:
177-
val->intval = bat_info->technology;
178-
break;
179-
case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
180-
val->intval = bat_info->voltage_min_design;
181-
break;
182-
case POWER_SUPPLY_PROP_VOLTAGE_MAX_DESIGN:
183-
val->intval = bat_info->voltage_max_design;
184-
break;
185-
case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN:
186-
val->intval = bat_info->charge_full_design;
187-
break;
188-
case POWER_SUPPLY_PROP_MODEL_NAME:
189-
val->strval = bat_info->name;
190-
break;
191141
default:
192142
return -EINVAL;
193143
}
@@ -235,7 +185,6 @@ static int gab_probe(struct platform_device *pdev)
235185
struct gab *adc_bat;
236186
struct power_supply_desc *psy_desc;
237187
struct power_supply_config psy_cfg = {};
238-
struct gab_platform_data *pdata = pdev->dev.platform_data;
239188
enum power_supply_property *properties;
240189
int ret = 0;
241190
int chan;
@@ -248,15 +197,14 @@ static int gab_probe(struct platform_device *pdev)
248197

249198
psy_cfg.drv_data = adc_bat;
250199
psy_desc = &adc_bat->psy_desc;
251-
psy_desc->name = pdata->battery_info.name;
200+
psy_desc->name = dev_name(&pdev->dev);
252201

253202
/* bootup default values for the battery */
254203
adc_bat->cable_plugged = false;
255204
adc_bat->status = POWER_SUPPLY_STATUS_DISCHARGING;
256205
psy_desc->type = POWER_SUPPLY_TYPE_BATTERY;
257206
psy_desc->get_property = gab_get_property;
258207
psy_desc->external_power_changed = gab_ext_power_changed;
259-
adc_bat->pdata = pdata;
260208

261209
/*
262210
* copying the static properties and allocating extra memory for holding

include/linux/power/generic-adc-battery.h

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)