power: supply: gpio-charger: Convert to GPIO descriptors
authorLinus Walleij <linus.walleij@linaro.org>
Thu, 27 Aug 2020 08:48:28 +0000 (10:48 +0200)
committerSebastian Reichel <sebastian.reichel@collabora.com>
Thu, 27 Aug 2020 14:47:14 +0000 (16:47 +0200)
This converts the GPIO charger to use exclusively GPIO
descriptors, moving the two remaining platforms passing
global GPIO numbers over to using a GPIO descriptor table.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Cc: Robert Jarzmik <robert.jarzmik@free.fr>
Cc: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
arch/arm/mach-pxa/tosa.c
arch/arm/mach-sa1100/collie.c
drivers/power/supply/gpio-charger.c
include/linux/power/gpio-charger.h

index 3d2c108..4317097 100644 (file)
@@ -369,6 +369,15 @@ static struct pxaficp_platform_data tosa_ficp_platform_data = {
 /*
  * Tosa AC IN
  */
+static struct gpiod_lookup_table tosa_power_gpiod_table = {
+       .dev_id = "gpio-charger",
+       .table = {
+               GPIO_LOOKUP("gpio-pxa", TOSA_GPIO_AC_IN,
+                           NULL, GPIO_ACTIVE_LOW),
+               { },
+       },
+};
+
 static char *tosa_ac_supplied_to[] = {
        "main-battery",
        "backup-battery",
@@ -378,8 +387,6 @@ static char *tosa_ac_supplied_to[] = {
 static struct gpio_charger_platform_data tosa_power_data = {
        .name                   = "charger",
        .type                   = POWER_SUPPLY_TYPE_MAINS,
-       .gpio                   = TOSA_GPIO_AC_IN,
-       .gpio_active_low        = 1,
        .supplied_to            = tosa_ac_supplied_to,
        .num_supplicants        = ARRAY_SIZE(tosa_ac_supplied_to),
 };
@@ -951,6 +958,7 @@ static void __init tosa_init(void)
        clk_add_alias("CLK_CK3P6MI", tc6393xb_device.name, "GPIO11_CLK", NULL);
 
        gpiod_add_lookup_table(&tosa_udc_gpiod_table);
+       gpiod_add_lookup_table(&tosa_power_gpiod_table);
        platform_add_devices(devices, ARRAY_SIZE(devices));
 }
 
index 3cc2b71..bd3a52f 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/gpio_keys.h>
 #include <linux/input.h>
 #include <linux/gpio.h>
+#include <linux/gpio/machine.h>
 #include <linux/power/gpio-charger.h>
 
 #include <video/sa1100fb.h>
@@ -131,16 +132,23 @@ static struct irda_platform_data collie_ir_data = {
 /*
  * Collie AC IN
  */
+static struct gpiod_lookup_table collie_power_gpiod_table = {
+       .dev_id = "gpio-charger",
+       .table = {
+               GPIO_LOOKUP("gpio", COLLIE_GPIO_AC_IN,
+                           NULL, GPIO_ACTIVE_HIGH),
+               { },
+       },
+};
+
 static char *collie_ac_supplied_to[] = {
        "main-battery",
        "backup-battery",
 };
 
-
 static struct gpio_charger_platform_data collie_power_data = {
        .name                   = "charger",
        .type                   = POWER_SUPPLY_TYPE_MAINS,
-       .gpio                   = COLLIE_GPIO_AC_IN,
        .supplied_to            = collie_ac_supplied_to,
        .num_supplicants        = ARRAY_SIZE(collie_ac_supplied_to),
 };
@@ -386,6 +394,8 @@ static void __init collie_init(void)
 
        platform_scoop_config = &collie_pcmcia_config;
 
+       gpiod_add_lookup_table(&collie_power_gpiod_table);
+
        ret = platform_add_devices(devices, ARRAY_SIZE(devices));
        if (ret) {
                printk(KERN_WARNING "collie: Unable to register LoCoMo device\n");
index 875735d..ae778f1 100644 (file)
@@ -5,7 +5,6 @@
  */
 
 #include <linux/device.h>
-#include <linux/gpio.h> /* For legacy platform data */
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/kernel.h>
@@ -131,7 +130,6 @@ static int gpio_charger_probe(struct platform_device *pdev)
        struct power_supply_desc *charger_desc;
        struct gpio_desc *charge_status;
        int charge_status_irq;
-       unsigned long flags;
        int ret;
        int num_props = 0;
 
@@ -149,29 +147,7 @@ static int gpio_charger_probe(struct platform_device *pdev)
         * boardfile descriptor tables. It's good to try this first.
         */
        gpio_charger->gpiod = devm_gpiod_get_optional(dev, NULL, GPIOD_IN);
-
-       /*
-        * Fallback to legacy platform data method, if no GPIO is specified
-        * using boardfile descriptor tables.
-        */
-       if (!gpio_charger->gpiod && pdata) {
-               /* Non-DT: use legacy GPIO numbers */
-               if (!gpio_is_valid(pdata->gpio)) {
-                       dev_err(dev, "Invalid gpio pin in pdata\n");
-                       return -EINVAL;
-               }
-               flags = GPIOF_IN;
-               if (pdata->gpio_active_low)
-                       flags |= GPIOF_ACTIVE_LOW;
-               ret = devm_gpio_request_one(dev, pdata->gpio, flags,
-                                           dev_name(dev));
-               if (ret) {
-                       dev_err(dev, "Failed to request gpio pin: %d\n", ret);
-                       return ret;
-               }
-               /* Then convert this to gpiod for now */
-               gpio_charger->gpiod = gpio_to_desc(pdata->gpio);
-       } else if (IS_ERR(gpio_charger->gpiod)) {
+       if (IS_ERR(gpio_charger->gpiod)) {
                /* Just try again if this happens */
                if (PTR_ERR(gpio_charger->gpiod) == -EPROBE_DEFER)
                        return -EPROBE_DEFER;
index 5a5a8de..c0b7657 100644 (file)
  * struct gpio_charger_platform_data - platform_data for gpio_charger devices
  * @name:              Name for the chargers power_supply device
  * @type:              Type of the charger
- * @gpio:              GPIO which is used to indicate the chargers status
- * @gpio_active_low:   Should be set to 1 if the GPIO is active low otherwise 0
  * @supplied_to:       Array of battery names to which this chargers supplies power
  * @num_supplicants:   Number of entries in the supplied_to array
  */
 struct gpio_charger_platform_data {
        const char *name;
        enum power_supply_type type;
-
-       int gpio;
-       int gpio_active_low;
-
        char **supplied_to;
        size_t num_supplicants;
 };