linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] power: supply: gpio-charger: Convert to GPIO descriptors
@ 2020-08-27  8:48 Linus Walleij
  2020-08-27 15:58 ` Sebastian Reichel
  0 siblings, 1 reply; 2+ messages in thread
From: Linus Walleij @ 2020-08-27  8:48 UTC (permalink / raw)
  To: Sebastian Reichel
  Cc: linux-pm, Linus Walleij, Robert Jarzmik, Dmitry Eremin-Solenikov

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>
---
ChangeLog v1->v2:
- Rebased on v5.9-rc1
---
 arch/arm/mach-pxa/tosa.c            | 12 ++++++++++--
 arch/arm/mach-sa1100/collie.c       | 14 ++++++++++++--
 drivers/power/supply/gpio-charger.c | 26 +-------------------------
 include/linux/power/gpio-charger.h  |  6 ------
 4 files changed, 23 insertions(+), 35 deletions(-)

diff --git a/arch/arm/mach-pxa/tosa.c b/arch/arm/mach-pxa/tosa.c
index 3d2c108e911e..431709725d02 100644
--- a/arch/arm/mach-pxa/tosa.c
+++ b/arch/arm/mach-pxa/tosa.c
@@ -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));
 }
 
diff --git a/arch/arm/mach-sa1100/collie.c b/arch/arm/mach-sa1100/collie.c
index 3cc2b71e16f0..bd3a52fd09ce 100644
--- a/arch/arm/mach-sa1100/collie.c
+++ b/arch/arm/mach-sa1100/collie.c
@@ -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");
diff --git a/drivers/power/supply/gpio-charger.c b/drivers/power/supply/gpio-charger.c
index 875735d50716..ae778f110101 100644
--- a/drivers/power/supply/gpio-charger.c
+++ b/drivers/power/supply/gpio-charger.c
@@ -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;
diff --git a/include/linux/power/gpio-charger.h b/include/linux/power/gpio-charger.h
index 5a5a8de98181..c0b7657ac1df 100644
--- a/include/linux/power/gpio-charger.h
+++ b/include/linux/power/gpio-charger.h
@@ -13,18 +13,12 @@
  * 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;
 };
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] power: supply: gpio-charger: Convert to GPIO descriptors
  2020-08-27  8:48 [PATCH v2] power: supply: gpio-charger: Convert to GPIO descriptors Linus Walleij
@ 2020-08-27 15:58 ` Sebastian Reichel
  0 siblings, 0 replies; 2+ messages in thread
From: Sebastian Reichel @ 2020-08-27 15:58 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-pm, Robert Jarzmik, Dmitry Eremin-Solenikov

[-- Attachment #1: Type: text/plain, Size: 7920 bytes --]

Hi,

On Thu, Aug 27, 2020 at 10:48:28AM +0200, Linus Walleij wrote:
> 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>
> ---
> ChangeLog v1->v2:
> - Rebased on v5.9-rc1
> ---

Thanks Linus, I queued the patch into power-supply's for-next branch
after neither my patchset from June (with the same change), nor your
patch from a few weeks ago triggered any feedback from the ARM
maintainers.

If a conflict in linux-next is detected ARM tree can merge the
following:

The following changes since commit 9123e3a74ec7b934a4a099e98af6a61c2f80bbf5:

  Linux 5.9-rc1 (2020-08-16 13:04:57 -0700)

are available in the Git repository at:

  https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git tags/psy-arm-gpio-charger-immutable-for-5.10-signed

for you to fetch changes up to 17529bcf0ae20f1ac6d7846762bf0c6ad91dbb7f:

  power: supply: gpio-charger: Convert to GPIO descriptors (2020-08-27 16:47:14 +0200)

----------------------------------------------------------------
Immutable branch between arm and power-supply for gpio-charger for 5.10

This immutable branch drops legacy gpio API from
gpio-charger and updates the remaining users to
the new gpiod API instead.

Signed-off-by: Sebastian Reichel <sre@kernel.org>

----------------------------------------------------------------
Linus Walleij (1):
      power: supply: gpio-charger: Convert to GPIO descriptors

 arch/arm/mach-pxa/tosa.c            | 12 ++++++++++--
 arch/arm/mach-sa1100/collie.c       | 14 ++++++++++++--
 drivers/power/supply/gpio-charger.c | 26 +-------------------------
 include/linux/power/gpio-charger.h  |  6 ------
 4 files changed, 23 insertions(+), 35 deletions(-)

-- Sebastian

>  arch/arm/mach-pxa/tosa.c            | 12 ++++++++++--
>  arch/arm/mach-sa1100/collie.c       | 14 ++++++++++++--
>  drivers/power/supply/gpio-charger.c | 26 +-------------------------
>  include/linux/power/gpio-charger.h  |  6 ------
>  4 files changed, 23 insertions(+), 35 deletions(-)
> 
> diff --git a/arch/arm/mach-pxa/tosa.c b/arch/arm/mach-pxa/tosa.c
> index 3d2c108e911e..431709725d02 100644
> --- a/arch/arm/mach-pxa/tosa.c
> +++ b/arch/arm/mach-pxa/tosa.c
> @@ -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));
>  }
>  
> diff --git a/arch/arm/mach-sa1100/collie.c b/arch/arm/mach-sa1100/collie.c
> index 3cc2b71e16f0..bd3a52fd09ce 100644
> --- a/arch/arm/mach-sa1100/collie.c
> +++ b/arch/arm/mach-sa1100/collie.c
> @@ -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");
> diff --git a/drivers/power/supply/gpio-charger.c b/drivers/power/supply/gpio-charger.c
> index 875735d50716..ae778f110101 100644
> --- a/drivers/power/supply/gpio-charger.c
> +++ b/drivers/power/supply/gpio-charger.c
> @@ -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;
> diff --git a/include/linux/power/gpio-charger.h b/include/linux/power/gpio-charger.h
> index 5a5a8de98181..c0b7657ac1df 100644
> --- a/include/linux/power/gpio-charger.h
> +++ b/include/linux/power/gpio-charger.h
> @@ -13,18 +13,12 @@
>   * 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;
>  };
> -- 
> 2.26.2
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-08-27 15:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-27  8:48 [PATCH v2] power: supply: gpio-charger: Convert to GPIO descriptors Linus Walleij
2020-08-27 15:58 ` Sebastian Reichel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).