diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2020-10-30 15:24:24 +0300 |
---|---|---|
committer | Sebastian Reichel <sebastian.reichel@collabora.com> | 2020-11-30 04:42:42 +0300 |
commit | b0327ffb133fb2148fc3bc2afb39af2871ab21cb (patch) | |
tree | 6c577cfaf37fcd59714011cefaba56bb09cf42af | |
parent | ba940ed83218f034f728184439c7e87795237752 (diff) | |
download | linux-b0327ffb133fb2148fc3bc2afb39af2871ab21cb.tar.xz |
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>
-rw-r--r-- | drivers/power/supply/generic-adc-battery.c | 31 | ||||
-rw-r--r-- | include/linux/power/generic-adc-battery.h | 4 |
2 files changed, 11 insertions, 24 deletions
diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c index caa829738ef7..0032069fbc2b 100644 --- a/drivers/power/supply/generic-adc-battery.c +++ b/drivers/power/supply/generic-adc-battery.c @@ -12,7 +12,7 @@ #include <linux/interrupt.h> #include <linux/platform_device.h> #include <linux/power_supply.h> -#include <linux/gpio.h> +#include <linux/gpio/consumer.h> #include <linux/err.h> #include <linux/timer.h> #include <linux/jiffies.h> @@ -52,6 +52,7 @@ struct gab { int level; int status; bool cable_plugged; + struct gpio_desc *charge_finished; }; static struct gab *to_generic_bat(struct power_supply *psy) @@ -91,13 +92,9 @@ static const enum power_supply_property gab_dyn_props[] = { static bool gab_charge_finished(struct gab *adc_bat) { - struct gab_platform_data *pdata = adc_bat->pdata; - bool ret = gpio_get_value(pdata->gpio_charge_finished); - bool inv = pdata->gpio_inverted; - - if (!gpio_is_valid(pdata->gpio_charge_finished)) + if (!adc_bat->charge_finished) return false; - return ret ^ inv; + return gpiod_get_value(adc_bat->charge_finished); } static int gab_get_status(struct gab *adc_bat) @@ -327,18 +324,17 @@ static int gab_probe(struct platform_device *pdev) INIT_DELAYED_WORK(&adc_bat->bat_work, gab_work); - if (gpio_is_valid(pdata->gpio_charge_finished)) { + adc_bat->charge_finished = devm_gpiod_get_optional(&pdev->dev, + "charged", GPIOD_IN); + if (adc_bat->charge_finished) { int irq; - ret = gpio_request(pdata->gpio_charge_finished, "charged"); - if (ret) - goto gpio_req_fail; - irq = gpio_to_irq(pdata->gpio_charge_finished); + irq = gpiod_to_irq(adc_bat->charge_finished); ret = request_any_context_irq(irq, gab_charged, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, "battery charged", adc_bat); if (ret < 0) - goto err_gpio; + goto gpio_req_fail; } platform_set_drvdata(pdev, adc_bat); @@ -348,8 +344,6 @@ static int gab_probe(struct platform_device *pdev) msecs_to_jiffies(0)); return 0; -err_gpio: - gpio_free(pdata->gpio_charge_finished); gpio_req_fail: power_supply_unregister(adc_bat->psy); err_reg_fail: @@ -367,14 +361,11 @@ static int gab_remove(struct platform_device *pdev) { int chan; struct gab *adc_bat = platform_get_drvdata(pdev); - struct gab_platform_data *pdata = adc_bat->pdata; power_supply_unregister(adc_bat->psy); - if (gpio_is_valid(pdata->gpio_charge_finished)) { - free_irq(gpio_to_irq(pdata->gpio_charge_finished), adc_bat); - gpio_free(pdata->gpio_charge_finished); - } + if (adc_bat->charge_finished) + free_irq(gpiod_to_irq(adc_bat->charge_finished), adc_bat); for (chan = 0; chan < ARRAY_SIZE(gab_chan_name); chan++) { if (adc_bat->channel[chan]) diff --git a/include/linux/power/generic-adc-battery.h b/include/linux/power/generic-adc-battery.h index 40f9c7628f7b..c68cbf34cd34 100644 --- a/include/linux/power/generic-adc-battery.h +++ b/include/linux/power/generic-adc-battery.h @@ -11,16 +11,12 @@ * @battery_info: recommended structure to specify static power supply * parameters * @cal_charge: calculate charge level. - * @gpio_charge_finished: gpio for the charger. - * @gpio_inverted: Should be 1 if the GPIO is active low otherwise 0 * @jitter_delay: delay required after the interrupt to check battery * status.Default set is 10ms. */ struct gab_platform_data { struct power_supply_info battery_info; int (*cal_charge)(long value); - int gpio_charge_finished; - bool gpio_inverted; int jitter_delay; }; |