Skip to content

Commit b0327ff

Browse files
Linus Walleijsre
authored andcommitted
power: supply: generic-adc-battery: Use GPIO descriptors
This driver uses platform data to pass GPIO lines using the deprecated global GPIO numbers. There are no in-tree users of this platform data. Any out-of-tree or coming users of this driver can easily be migrated to use machine descriptor tables as described in Documentation/driver-api/gpio/board.rst section "platform data". Cc: Anish Kumar <anish198519851985@gmail.com> Cc: H. Nikolaus Schaller <hns@goldelico.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
1 parent ba940ed commit b0327ff

2 files changed

Lines changed: 11 additions & 24 deletions

File tree

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

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <linux/interrupt.h>
1313
#include <linux/platform_device.h>
1414
#include <linux/power_supply.h>
15-
#include <linux/gpio.h>
15+
#include <linux/gpio/consumer.h>
1616
#include <linux/err.h>
1717
#include <linux/timer.h>
1818
#include <linux/jiffies.h>
@@ -52,6 +52,7 @@ struct gab {
5252
int level;
5353
int status;
5454
bool cable_plugged;
55+
struct gpio_desc *charge_finished;
5556
};
5657

5758
static struct gab *to_generic_bat(struct power_supply *psy)
@@ -91,13 +92,9 @@ static const enum power_supply_property gab_dyn_props[] = {
9192

9293
static bool gab_charge_finished(struct gab *adc_bat)
9394
{
94-
struct gab_platform_data *pdata = adc_bat->pdata;
95-
bool ret = gpio_get_value(pdata->gpio_charge_finished);
96-
bool inv = pdata->gpio_inverted;
97-
98-
if (!gpio_is_valid(pdata->gpio_charge_finished))
95+
if (!adc_bat->charge_finished)
9996
return false;
100-
return ret ^ inv;
97+
return gpiod_get_value(adc_bat->charge_finished);
10198
}
10299

103100
static int gab_get_status(struct gab *adc_bat)
@@ -327,18 +324,17 @@ static int gab_probe(struct platform_device *pdev)
327324

328325
INIT_DELAYED_WORK(&adc_bat->bat_work, gab_work);
329326

330-
if (gpio_is_valid(pdata->gpio_charge_finished)) {
327+
adc_bat->charge_finished = devm_gpiod_get_optional(&pdev->dev,
328+
"charged", GPIOD_IN);
329+
if (adc_bat->charge_finished) {
331330
int irq;
332-
ret = gpio_request(pdata->gpio_charge_finished, "charged");
333-
if (ret)
334-
goto gpio_req_fail;
335331

336-
irq = gpio_to_irq(pdata->gpio_charge_finished);
332+
irq = gpiod_to_irq(adc_bat->charge_finished);
337333
ret = request_any_context_irq(irq, gab_charged,
338334
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
339335
"battery charged", adc_bat);
340336
if (ret < 0)
341-
goto err_gpio;
337+
goto gpio_req_fail;
342338
}
343339

344340
platform_set_drvdata(pdev, adc_bat);
@@ -348,8 +344,6 @@ static int gab_probe(struct platform_device *pdev)
348344
msecs_to_jiffies(0));
349345
return 0;
350346

351-
err_gpio:
352-
gpio_free(pdata->gpio_charge_finished);
353347
gpio_req_fail:
354348
power_supply_unregister(adc_bat->psy);
355349
err_reg_fail:
@@ -367,14 +361,11 @@ static int gab_remove(struct platform_device *pdev)
367361
{
368362
int chan;
369363
struct gab *adc_bat = platform_get_drvdata(pdev);
370-
struct gab_platform_data *pdata = adc_bat->pdata;
371364

372365
power_supply_unregister(adc_bat->psy);
373366

374-
if (gpio_is_valid(pdata->gpio_charge_finished)) {
375-
free_irq(gpio_to_irq(pdata->gpio_charge_finished), adc_bat);
376-
gpio_free(pdata->gpio_charge_finished);
377-
}
367+
if (adc_bat->charge_finished)
368+
free_irq(gpiod_to_irq(adc_bat->charge_finished), adc_bat);
378369

379370
for (chan = 0; chan < ARRAY_SIZE(gab_chan_name); chan++) {
380371
if (adc_bat->channel[chan])

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,12 @@
1111
* @battery_info: recommended structure to specify static power supply
1212
* parameters
1313
* @cal_charge: calculate charge level.
14-
* @gpio_charge_finished: gpio for the charger.
15-
* @gpio_inverted: Should be 1 if the GPIO is active low otherwise 0
1614
* @jitter_delay: delay required after the interrupt to check battery
1715
* status.Default set is 10ms.
1816
*/
1917
struct gab_platform_data {
2018
struct power_supply_info battery_info;
2119
int (*cal_charge)(long value);
22-
int gpio_charge_finished;
23-
bool gpio_inverted;
2420
int jitter_delay;
2521
};
2622

0 commit comments

Comments
 (0)