Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Linus Walleij and committed by
Sebastian Reichel
b0327ffb ba940ed8

+11 -24
+11 -20
drivers/power/supply/generic-adc-battery.c
··· 12 12 #include <linux/interrupt.h> 13 13 #include <linux/platform_device.h> 14 14 #include <linux/power_supply.h> 15 - #include <linux/gpio.h> 15 + #include <linux/gpio/consumer.h> 16 16 #include <linux/err.h> 17 17 #include <linux/timer.h> 18 18 #include <linux/jiffies.h> ··· 52 52 int level; 53 53 int status; 54 54 bool cable_plugged; 55 + struct gpio_desc *charge_finished; 55 56 }; 56 57 57 58 static struct gab *to_generic_bat(struct power_supply *psy) ··· 92 91 93 92 static bool gab_charge_finished(struct gab *adc_bat) 94 93 { 95 - struct gab_platform_data *pdata = adc_bat->pdata; 96 - bool ret = gpio_get_value(pdata->gpio_charge_finished); 97 - bool inv = pdata->gpio_inverted; 98 - 99 - if (!gpio_is_valid(pdata->gpio_charge_finished)) 94 + if (!adc_bat->charge_finished) 100 95 return false; 101 - return ret ^ inv; 96 + return gpiod_get_value(adc_bat->charge_finished); 102 97 } 103 98 104 99 static int gab_get_status(struct gab *adc_bat) ··· 324 327 325 328 INIT_DELAYED_WORK(&adc_bat->bat_work, gab_work); 326 329 327 - if (gpio_is_valid(pdata->gpio_charge_finished)) { 330 + adc_bat->charge_finished = devm_gpiod_get_optional(&pdev->dev, 331 + "charged", GPIOD_IN); 332 + if (adc_bat->charge_finished) { 328 333 int irq; 329 - ret = gpio_request(pdata->gpio_charge_finished, "charged"); 330 - if (ret) 331 - goto gpio_req_fail; 332 334 333 - irq = gpio_to_irq(pdata->gpio_charge_finished); 335 + irq = gpiod_to_irq(adc_bat->charge_finished); 334 336 ret = request_any_context_irq(irq, gab_charged, 335 337 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 336 338 "battery charged", adc_bat); 337 339 if (ret < 0) 338 - goto err_gpio; 340 + goto gpio_req_fail; 339 341 } 340 342 341 343 platform_set_drvdata(pdev, adc_bat); ··· 344 348 msecs_to_jiffies(0)); 345 349 return 0; 346 350 347 - err_gpio: 348 - gpio_free(pdata->gpio_charge_finished); 349 351 gpio_req_fail: 350 352 power_supply_unregister(adc_bat->psy); 351 353 err_reg_fail: ··· 361 367 { 362 368 int chan; 363 369 struct gab *adc_bat = platform_get_drvdata(pdev); 364 - struct gab_platform_data *pdata = adc_bat->pdata; 365 370 366 371 power_supply_unregister(adc_bat->psy); 367 372 368 - if (gpio_is_valid(pdata->gpio_charge_finished)) { 369 - free_irq(gpio_to_irq(pdata->gpio_charge_finished), adc_bat); 370 - gpio_free(pdata->gpio_charge_finished); 371 - } 373 + if (adc_bat->charge_finished) 374 + free_irq(gpiod_to_irq(adc_bat->charge_finished), adc_bat); 372 375 373 376 for (chan = 0; chan < ARRAY_SIZE(gab_chan_name); chan++) { 374 377 if (adc_bat->channel[chan])
-4
include/linux/power/generic-adc-battery.h
··· 11 11 * @battery_info: recommended structure to specify static power supply 12 12 * parameters 13 13 * @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 16 14 * @jitter_delay: delay required after the interrupt to check battery 17 15 * status.Default set is 10ms. 18 16 */ 19 17 struct gab_platform_data { 20 18 struct power_supply_info battery_info; 21 19 int (*cal_charge)(long value); 22 - int gpio_charge_finished; 23 - bool gpio_inverted; 24 20 int jitter_delay; 25 21 }; 26 22