diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2021-01-11 00:45:08 +0100 |
---|---|---|
committer | Sebastian Reichel <sre@kernel.org> | 2021-01-13 22:25:07 +0100 |
commit | cb6d6918c56ffd98e88164d5471f692d33dabf2b (patch) | |
tree | d96b20e367affaf5b864361980767d4e8dec3c9a /drivers/power | |
parent | a3b4388ea19b055ec482114e227c58d0184edfa5 (diff) | |
download | linux-cb6d6918c56ffd98e88164d5471f692d33dabf2b.tar.gz linux-cb6d6918c56ffd98e88164d5471f692d33dabf2b.tar.bz2 linux-cb6d6918c56ffd98e88164d5471f692d33dabf2b.zip |
power: supply: wm97xx_battery: Convert to GPIO descriptor
This converts the WM97xx driver to use a GPIO descriptor
instead of passing a GPIO number thru platform data.
Like everything else in the driver, use a simple local
variable for the descriptor, it can only ever appear in
one instance anyway so it should not hurt.
After converting the driver I noticed that none of the
boardfiles actually define a meaningful GPIO line for
this, but hey, it is converted.
Cc: Haojian Zhuang <haojian.zhuang@gmail.com>
Cc: Robert Jarzmik <robert.jarzmik@free.fr>
Cc: linux-arm-kernel@lists.infradead.org
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Daniel Mack <daniel@zonque.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Diffstat (limited to 'drivers/power')
-rw-r--r-- | drivers/power/supply/wm97xx_battery.c | 45 |
1 files changed, 19 insertions, 26 deletions
diff --git a/drivers/power/supply/wm97xx_battery.c b/drivers/power/supply/wm97xx_battery.c index 58f01659daa5..a0e1eaa25d93 100644 --- a/drivers/power/supply/wm97xx_battery.c +++ b/drivers/power/supply/wm97xx_battery.c @@ -15,11 +15,12 @@ #include <linux/wm97xx.h> #include <linux/spinlock.h> #include <linux/interrupt.h> -#include <linux/gpio.h> +#include <linux/gpio/consumer.h> #include <linux/irq.h> #include <linux/slab.h> static struct work_struct bat_work; +static struct gpio_desc *charge_gpiod; static DEFINE_MUTEX(work_lock); static int bat_status = POWER_SUPPLY_STATUS_UNKNOWN; static enum power_supply_property *prop; @@ -96,12 +97,11 @@ static void wm97xx_bat_external_power_changed(struct power_supply *bat_ps) static void wm97xx_bat_update(struct power_supply *bat_ps) { int old_status = bat_status; - struct wm97xx_batt_pdata *pdata = power_supply_get_drvdata(bat_ps); mutex_lock(&work_lock); - bat_status = (pdata->charge_gpio >= 0) ? - (gpio_get_value(pdata->charge_gpio) ? + bat_status = (charge_gpiod) ? + (gpiod_get_value(charge_gpiod) ? POWER_SUPPLY_STATUS_DISCHARGING : POWER_SUPPLY_STATUS_CHARGING) : POWER_SUPPLY_STATUS_UNKNOWN; @@ -171,18 +171,19 @@ static int wm97xx_bat_probe(struct platform_device *dev) if (dev->id != -1) return -EINVAL; - if (gpio_is_valid(pdata->charge_gpio)) { - ret = gpio_request(pdata->charge_gpio, "BATT CHRG"); - if (ret) - goto err; - ret = gpio_direction_input(pdata->charge_gpio); - if (ret) - goto err2; - ret = request_irq(gpio_to_irq(pdata->charge_gpio), + charge_gpiod = devm_gpiod_get_optional(&dev->dev, NULL, GPIOD_IN); + if (IS_ERR(charge_gpiod)) + return dev_err_probe(&dev->dev, + PTR_ERR(charge_gpiod), + "failed to get charge GPIO\n"); + if (charge_gpiod) { + gpiod_set_consumer_name(charge_gpiod, "BATT CHRG"); + ret = request_irq(gpiod_to_irq(charge_gpiod), wm97xx_chrg_irq, 0, "AC Detect", dev); if (ret) - goto err2; + return dev_err_probe(&dev->dev, ret, + "failed to request GPIO irq\n"); props++; /* POWER_SUPPLY_PROP_STATUS */ } @@ -204,7 +205,7 @@ static int wm97xx_bat_probe(struct platform_device *dev) } prop[i++] = POWER_SUPPLY_PROP_PRESENT; - if (pdata->charge_gpio >= 0) + if (charge_gpiod) prop[i++] = POWER_SUPPLY_PROP_STATUS; if (pdata->batt_tech >= 0) prop[i++] = POWER_SUPPLY_PROP_TECHNOLOGY; @@ -242,23 +243,15 @@ static int wm97xx_bat_probe(struct platform_device *dev) err4: kfree(prop); err3: - if (gpio_is_valid(pdata->charge_gpio)) - free_irq(gpio_to_irq(pdata->charge_gpio), dev); -err2: - if (gpio_is_valid(pdata->charge_gpio)) - gpio_free(pdata->charge_gpio); -err: + if (charge_gpiod) + free_irq(gpiod_to_irq(charge_gpiod), dev); return ret; } static int wm97xx_bat_remove(struct platform_device *dev) { - struct wm97xx_batt_pdata *pdata = dev->dev.platform_data; - - if (pdata && gpio_is_valid(pdata->charge_gpio)) { - free_irq(gpio_to_irq(pdata->charge_gpio), dev); - gpio_free(pdata->charge_gpio); - } + if (charge_gpiod) + free_irq(gpiod_to_irq(charge_gpiod), dev); cancel_work_sync(&bat_work); power_supply_unregister(bat_psy); kfree(prop); |