Skip to contentSkip to conversation

gpio / ACPI: convert users to gpiod_* and drop acpi_gpio.h

PATCH Superseded Mika Westerberg 7 participants 26 messages Nov 22, 2013 – Nov 25, 2013

Subsystems (10)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover gpio / ACPI: convert users to gpiod_* and drop acpi_gpio.h

Hi all,

Now that the mainline kernel has full ACPI support for the GPIO descriptor interface we can get rid of ACPI specific GPIO functions in favor of GPIO descriptor (gpiod_*) interfaces.

This series first converts the existing two users to this interface and then modifies gpiolib and gpiolib-acpi so that the ACPI functions are only called internally in drivers/gpio. We then remove the acpi_gpio.h and require all users to user gpiod_* interfaces.

This is second version of the series. Changes to the previous [1]:
* paz00 is passing the lookup table so that we don't need to have gpio conversion function in rfkill-gpio.c anymore.
* Corrected sdhci-acpi.c to pass con_id and added call to gpiod_direction_input().

I suppose it would make sense to merge the whole series via GPIO or ACPI trees because there's a dependency that the first two patches need to be applied before last three. Otherwise the drivers in question fail to compile.

[1] https://lkml.org/lkml/2013/11/21/317

Heikki Krogerus (3):
net: rfkill: gpio: convert to descriptor-based GPIO interface
ARM: tegra: add gpiod_lookup table for paz00
net: rfkill: gpio: remove gpio conversion support

Mika Westerberg (4):
mmc: sdhci-acpi: covert to use GPIO descriptor API gpio / ACPI: register to ACPI events automatically gpio / ACPI: get rid of acpi_gpio.h Documentation / ACPI: update to GPIO descriptor API

 Documentation/acpi/enumeration.txt | 36 ++++--------------
 arch/arm/mach-tegra/board-paz00.c  |  9 ++++-
 drivers/gpio/gpiolib-acpi.c        | 20 +++++++---
 drivers/gpio/gpiolib.c             |  5 ++-
 drivers/gpio/gpiolib.h             | 46 +++++++++++++++++++++++
 drivers/mmc/host/sdhci-acpi.c      | 26 ++++++-------
 drivers/pinctrl/pinctrl-baytrail.c |  4 --
 include/linux/acpi_gpio.h          | 51 -------------------------
 net/rfkill/rfkill-gpio.c           | 77 +++++++++++++++++---------------------
 9 files changed, 125 insertions(+), 149 deletions(-)
 create mode 100644 drivers/gpio/gpiolib.h
 delete mode 100644 include/linux/acpi_gpio.h
Signature · 1 line
1.8.4.3
#1 lore raw

PATCH v2 1/7 net: rfkill: gpio: convert to descriptor-based GPIO interface

From: Heikki Krogerus <[email protected]>

Convert to the safer gpiod_* family of API functions.

---
 net/rfkill/rfkill-gpio.c | 112 +++++++++++++++++++++++++++++------------------
 1 file changed, 70 insertions(+), 42 deletions(-)
net/rfkill/rfkill-gpio.c +70 -42
index 5620d3c07479..503432154616 100644
@@ -25,15 +25,15 @@
 #include <linux/clk.h>
 #include <linux/slab.h>
 #include <linux/acpi.h>
-#include <linux/acpi_gpio.h>
+#include <linux/gpio/consumer.h>
 
 #include <linux/rfkill-gpio.h>
 
 struct rfkill_gpio_data {
 	const char		*name;
 	enum rfkill_type	type;
-	int			reset_gpio;
-	int			shutdown_gpio;
+	struct gpio_desc	*reset_gpio;
+	struct gpio_desc	*shutdown_gpio;
 
 	struct rfkill		*rfkill_dev;
 	char			*reset_name;
@@ -48,19 +48,15 @@ static int rfkill_gpio_set_power(void *data, bool blocked)
 	struct rfkill_gpio_data *rfkill = data;
 
 	if (blocked) {
-		if (gpio_is_valid(rfkill->shutdown_gpio))
-			gpio_set_value(rfkill->shutdown_gpio, 0);
-		if (gpio_is_valid(rfkill->reset_gpio))
-			gpio_set_value(rfkill->reset_gpio, 0);
+		gpiod_set_value(rfkill->shutdown_gpio, 0);
+		gpiod_set_value(rfkill->reset_gpio, 0);
 		if (!IS_ERR(rfkill->clk) && rfkill->clk_enabled)
 			clk_disable(rfkill->clk);
 	} else {
 		if (!IS_ERR(rfkill->clk) && !rfkill->clk_enabled)
 			clk_enable(rfkill->clk);
-		if (gpio_is_valid(rfkill->reset_gpio))
-			gpio_set_value(rfkill->reset_gpio, 1);
-		if (gpio_is_valid(rfkill->shutdown_gpio))
-			gpio_set_value(rfkill->shutdown_gpio, 1);
+		gpiod_set_value(rfkill->reset_gpio, 1);
+		gpiod_set_value(rfkill->shutdown_gpio, 1);
 	}
 
 	rfkill->clk_enabled = blocked;
@@ -72,6 +68,35 @@ static const struct rfkill_ops rfkill_gpio_ops = {
 	.set_block = rfkill_gpio_set_power,
 };
 
+static int rfkill_gpio_convert_to_desc(struct platform_device *pdev,
+				       struct rfkill_gpio_data *rfkill)
+{
+	struct rfkill_gpio_platform_data *pdata = pdev->dev.platform_data;
+	int ret;
+
+	if (gpio_is_valid(pdata->reset_gpio)) {
+		ret = devm_gpio_request_one(&pdev->dev, pdata->reset_gpio,
+					    0, rfkill->reset_name);
+		if (ret) {
+			dev_err(&pdev->dev, "failed to get reset gpio.\n");
+			return ret;
+		}
+		rfkill->reset_gpio = gpio_to_desc(pdata->reset_gpio);
+	}
+
+	if (gpio_is_valid(pdata->shutdown_gpio)) {
+		ret = devm_gpio_request_one(&pdev->dev, pdata->shutdown_gpio,
+					    0, rfkill->shutdown_name);
+		if (ret) {
+			dev_err(&pdev->dev, "failed to get shutdown gpio.\n");
+			return ret;
+		}
+		rfkill->shutdown_gpio = gpio_to_desc(pdata->shutdown_gpio);
+	}
+
+	return 0;
+}
+
 static int rfkill_gpio_acpi_probe(struct device *dev,
 				  struct rfkill_gpio_data *rfkill)
 {
@@ -83,8 +108,6 @@ static int rfkill_gpio_acpi_probe(struct device *dev,
 
 	rfkill->name = dev_name(dev);
 	rfkill->type = (unsigned)id->driver_data;
-	rfkill->reset_gpio = acpi_get_gpio_by_index(dev, 0, NULL);
-	rfkill->shutdown_gpio = acpi_get_gpio_by_index(dev, 1, NULL);
 
 	return 0;
 }
@@ -94,8 +117,8 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
 	struct rfkill_gpio_platform_data *pdata = pdev->dev.platform_data;
 	struct rfkill_gpio_data *rfkill;
 	const char *clk_name = NULL;
-	int ret = 0;
-	int len = 0;
+	int ret;
+	int len;
 
 	rfkill = devm_kzalloc(&pdev->dev, sizeof(*rfkill), GFP_KERNEL);
 	if (!rfkill)
@@ -109,28 +132,10 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
 		clk_name = pdata->power_clk_name;
 		rfkill->name = pdata->name;
 		rfkill->type = pdata->type;
-		rfkill->reset_gpio = pdata->reset_gpio;
-		rfkill->shutdown_gpio = pdata->shutdown_gpio;
 	} else {
 		return -ENODEV;
 	}
 
-	/* make sure at-least one of the GPIO is defined and that
-	 * a name is specified for this instance */
-	if ((!gpio_is_valid(rfkill->reset_gpio) &&
-	     !gpio_is_valid(rfkill->shutdown_gpio)) || !rfkill->name) {
-		pr_warn("%s: invalid platform data\n", __func__);
-		return -EINVAL;
-	}
-
-	if (pdata && pdata->gpio_runtime_setup) {
-		ret = pdata->gpio_runtime_setup(pdev);
-		if (ret) {
-			pr_warn("%s: can't set up gpio\n", __func__);
-			return ret;
-		}
-	}
-
 	len = strlen(rfkill->name);
 	rfkill->reset_name = devm_kzalloc(&pdev->dev, len + 7, GFP_KERNEL);
 	if (!rfkill->reset_name)
@@ -145,20 +150,43 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
 
 	rfkill->clk = devm_clk_get(&pdev->dev, clk_name);
 
-	if (gpio_is_valid(rfkill->reset_gpio)) {
-		ret = devm_gpio_request_one(&pdev->dev, rfkill->reset_gpio,
-					    0, rfkill->reset_name);
-		if (ret) {
-			pr_warn("%s: failed to get reset gpio.\n", __func__);
+	if (pdata && (pdata->reset_gpio || pdata->shutdown_gpio)) {
+		ret = rfkill_gpio_convert_to_desc(pdev, rfkill);
+		if (ret)
 			return ret;
+	} else {
+		struct gpio_desc *gpio;
+
+		gpio = devm_gpiod_get_index(&pdev->dev, rfkill->reset_name, 0);
+		if (!IS_ERR(gpio)) {
+			ret = gpiod_direction_output(gpio, 0);
+			if (ret)
+				return ret;
+			rfkill->reset_gpio = gpio;
+		}
+
+		gpio = devm_gpiod_get_index(&pdev->dev,
+					    rfkill->shutdown_name, 1);
+		if (!IS_ERR(gpio)) {
+			ret = gpiod_direction_output(gpio, 0);
+			if (ret)
+				return ret;
+			rfkill->shutdown_gpio = gpio;
 		}
 	}
 
-	if (gpio_is_valid(rfkill->shutdown_gpio)) {
-		ret = devm_gpio_request_one(&pdev->dev, rfkill->shutdown_gpio,
-					    0, rfkill->shutdown_name);
+	/* Make sure at-least one of the GPIO is defined and that
+	 * a name is specified for this instance
+	 */
+	if ((!rfkill->reset_gpio && !rfkill->shutdown_gpio) || !rfkill->name) {
+		dev_err(&pdev->dev, "invalid platform data\n");
+		return -EINVAL;
+	}
+
+	if (pdata && pdata->gpio_runtime_setup) {
+		ret = pdata->gpio_runtime_setup(pdev);
 		if (ret) {
-			pr_warn("%s: failed to get shutdown gpio.\n", __func__);
+			dev_err(&pdev->dev, "can't set up gpio\n");
 			return ret;
 		}
 	}
Signature · 1 line
1.8.4.3
#2 lore raw

PATCH v2 2/7 ARM: tegra: add gpiod_lookup table for paz00

In reply to Mika Westerberg

From: Heikki Krogerus <[email protected]>

This makes it possible to request the gpio descriptors in rfkill-gpio driver regardless of the platform.

---
 arch/arm/mach-tegra/board-paz00.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
arch/arm/mach-tegra/board-paz00.c +7 -2
index 06f024070dab..2e132589be78 100644
@@ -18,13 +18,12 @@
  */
 
 #include <linux/platform_device.h>
+#include <linux/gpio/driver.h>
 #include <linux/rfkill-gpio.h>
 #include "board.h"
 
 static struct rfkill_gpio_platform_data wifi_rfkill_platform_data = {
 	.name		= "wifi_rfkill",
-	.reset_gpio	= 25, /* PD1 */
-	.shutdown_gpio	= 85, /* PK5 */
 	.type	= RFKILL_TYPE_WLAN,
 };
 
@@ -36,7 +35,13 @@ static struct platform_device wifi_rfkill_device = {
 	},
 };
 
+static struct gpiod_lookup wifi_gpio_lookup[] = {
+	GPIO_LOOKUP_IDX("tegra-gpio", 25, "rfkill_gpio", NULL, 0, 0),
+	GPIO_LOOKUP_IDX("tegra-gpio", 85, "rfkill_gpio", NULL, 1, 0),
+};
+
 void __init tegra_paz00_wifikill_init(void)
 {
+	gpiod_add_table(wifi_gpio_lookup, ARRAY_SIZE(wifi_gpio_lookup));
 	platform_device_register(&wifi_rfkill_device);
 }
Signature · 1 line
1.8.4.3
#5 lore raw

PATCH v2 3/7 net: rfkill: gpio: remove gpio conversion support

In reply to Mika Westerberg

From: Heikki Krogerus <[email protected]>

All platforms using this driver are now converted to the new descriptor-based GPIO interface.

---
 net/rfkill/rfkill-gpio.c | 61 ++++++++++--------------------------------------
 1 file changed, 12 insertions(+), 49 deletions(-)
net/rfkill/rfkill-gpio.c +12 -49
index 503432154616..bd2a5b90400c 100644
@@ -68,35 +68,6 @@ static const struct rfkill_ops rfkill_gpio_ops = {
 	.set_block = rfkill_gpio_set_power,
 };
 
-static int rfkill_gpio_convert_to_desc(struct platform_device *pdev,
-				       struct rfkill_gpio_data *rfkill)
-{
-	struct rfkill_gpio_platform_data *pdata = pdev->dev.platform_data;
-	int ret;
-
-	if (gpio_is_valid(pdata->reset_gpio)) {
-		ret = devm_gpio_request_one(&pdev->dev, pdata->reset_gpio,
-					    0, rfkill->reset_name);
-		if (ret) {
-			dev_err(&pdev->dev, "failed to get reset gpio.\n");
-			return ret;
-		}
-		rfkill->reset_gpio = gpio_to_desc(pdata->reset_gpio);
-	}
-
-	if (gpio_is_valid(pdata->shutdown_gpio)) {
-		ret = devm_gpio_request_one(&pdev->dev, pdata->shutdown_gpio,
-					    0, rfkill->shutdown_name);
-		if (ret) {
-			dev_err(&pdev->dev, "failed to get shutdown gpio.\n");
-			return ret;
-		}
-		rfkill->shutdown_gpio = gpio_to_desc(pdata->shutdown_gpio);
-	}
-
-	return 0;
-}
-
 static int rfkill_gpio_acpi_probe(struct device *dev,
 				  struct rfkill_gpio_data *rfkill)
 {
@@ -117,6 +88,7 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
 	struct rfkill_gpio_platform_data *pdata = pdev->dev.platform_data;
 	struct rfkill_gpio_data *rfkill;
 	const char *clk_name = NULL;
+	struct gpio_desc *gpio;
 	int ret;
 	int len;
 
@@ -150,29 +122,20 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
 
 	rfkill->clk = devm_clk_get(&pdev->dev, clk_name);
 
-	if (pdata && (pdata->reset_gpio || pdata->shutdown_gpio)) {
-		ret = rfkill_gpio_convert_to_desc(pdev, rfkill);
+	gpio = devm_gpiod_get_index(&pdev->dev, rfkill->reset_name, 0);
+	if (!IS_ERR(gpio)) {
+		ret = gpiod_direction_output(gpio, 0);
 		if (ret)
 			return ret;
-	} else {
-		struct gpio_desc *gpio;
-
-		gpio = devm_gpiod_get_index(&pdev->dev, rfkill->reset_name, 0);
-		if (!IS_ERR(gpio)) {
-			ret = gpiod_direction_output(gpio, 0);
-			if (ret)
-				return ret;
-			rfkill->reset_gpio = gpio;
-		}
+		rfkill->reset_gpio = gpio;
+	}
 
-		gpio = devm_gpiod_get_index(&pdev->dev,
-					    rfkill->shutdown_name, 1);
-		if (!IS_ERR(gpio)) {
-			ret = gpiod_direction_output(gpio, 0);
-			if (ret)
-				return ret;
-			rfkill->shutdown_gpio = gpio;
-		}
+	gpio = devm_gpiod_get_index(&pdev->dev, rfkill->shutdown_name, 1);
+	if (!IS_ERR(gpio)) {
+		ret = gpiod_direction_output(gpio, 0);
+		if (ret)
+			return ret;
+		rfkill->shutdown_gpio = gpio;
 	}
 
 	/* Make sure at-least one of the GPIO is defined and that
Signature · 1 line
1.8.4.3
#15 lore raw

PATCH v2 4/7 mmc: sdhci-acpi: covert to use GPIO descriptor API

In reply to Mika Westerberg

The new descriptor based GPIO interface is now the recommended and safer way of using GPIOs from device drivers. Convert the ACPI SDHCI driver to use that interface.

---
 drivers/mmc/host/sdhci-acpi.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)
drivers/mmc/host/sdhci-acpi.c +12 -14
index ef19874fcd1f..5c86550f83ad 100644
@@ -31,10 +31,9 @@
 #include <linux/bitops.h>
 #include <linux/types.h>
 #include <linux/err.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/interrupt.h>
 #include <linux/acpi.h>
-#include <linux/acpi_gpio.h>
 #include <linux/pm.h>
 #include <linux/pm_runtime.h>
 #include <linux/delay.h>
@@ -199,22 +198,23 @@ static irqreturn_t sdhci_acpi_sd_cd(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
-static int sdhci_acpi_add_own_cd(struct device *dev, int gpio,
-				 struct mmc_host *mmc)
+static int sdhci_acpi_add_own_cd(struct device *dev, struct mmc_host *mmc)
 {
+	struct gpio_desc *desc;
 	unsigned long flags;
 	int err, irq;
 
-	if (gpio < 0) {
-		err = gpio;
+	desc = devm_gpiod_get_index(dev, "sd_cd", 0);
+	if (IS_ERR(desc)) {
+		err = PTR_ERR(desc);
 		goto out;
 	}
 
-	err = devm_gpio_request_one(dev, gpio, GPIOF_DIR_IN, "sd_cd");
+	err = gpiod_direction_input(desc);
 	if (err)
-		goto out;
+		goto out_free;
 
-	irq = gpio_to_irq(gpio);
+	irq = gpiod_to_irq(desc);
 	if (irq < 0) {
 		err = irq;
 		goto out_free;
@@ -228,7 +228,7 @@ static int sdhci_acpi_add_own_cd(struct device *dev, int gpio,
 	return 0;
 
 out_free:
-	devm_gpio_free(dev, gpio);
+	devm_gpiod_put(dev, desc);
 out:
 	dev_warn(dev, "failed to setup card detect wake up\n");
 	return err;
@@ -254,7 +254,7 @@ static int sdhci_acpi_probe(struct platform_device *pdev)
 	struct resource *iomem;
 	resource_size_t len;
 	const char *hid;
-	int err, gpio;
+	int err;
 
 	if (acpi_bus_get_device(handle, &device))
 		return -ENODEV;
@@ -279,8 +279,6 @@ static int sdhci_acpi_probe(struct platform_device *pdev)
 	if (IS_ERR(host))
 		return PTR_ERR(host);
 
-	gpio = acpi_get_gpio_by_index(dev, 0, NULL);
-
 	c = sdhci_priv(host);
 	c->host = host;
 	c->slot = sdhci_acpi_get_slot(handle, hid);
@@ -338,7 +336,7 @@ static int sdhci_acpi_probe(struct platform_device *pdev)
 		goto err_free;
 
 	if (sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD)) {
-		if (sdhci_acpi_add_own_cd(dev, gpio, host->mmc))
+		if (sdhci_acpi_add_own_cd(dev, host->mmc))
 			c->use_runtime_pm = false;
 	}
 
Signature · 1 line
1.8.4.3
#18 lore raw

PATCH v2 5/7 gpio / ACPI: register to ACPI events automatically

In reply to Mika Westerberg

Instead of asking each driver to register to ACPI events we can just call acpi_gpiochip_register_interrupts() for each chip that has an ACPI handle. The function checks chip->to_irq and if it is set to NULL (a GPIO driver that doesn't do interrupts) the function does nothing.

We also add the a new header drivers/gpio/gpiolib.h that is used for functions internal to gpiolib and add ACPI GPIO chip registering functions to that header.

Once that is done we can remove call to acpi_gpiochip_register_interrupts() from its only user, pinctrl-baytrail.c

---
 drivers/gpio/gpiolib-acpi.c        | 16 ++++++++++++----
 drivers/gpio/gpiolib.c             |  4 ++++
 drivers/gpio/gpiolib.h             | 23 +++++++++++++++++++++++
 drivers/pinctrl/pinctrl-baytrail.c |  4 ----
 include/linux/acpi_gpio.h          |  6 ------
 5 files changed, 39 insertions(+), 14 deletions(-)
 create mode 100644 drivers/gpio/gpiolib.h
drivers/gpio/gpiolib-acpi.c +12 -4
index ae0ffdce8bd5..cb2da66fbbfe 100644
@@ -94,7 +94,7 @@ static void acpi_gpio_evt_dh(acpi_handle handle, void *data)
  * gpio pins have acpi event methods and assigns interrupt handlers that calls
  * the acpi event methods for those pins.
  */
-void acpi_gpiochip_request_interrupts(struct gpio_chip *chip)
+static void acpi_gpiochip_request_interrupts(struct gpio_chip *chip)
 {
 	struct acpi_buffer buf = {ACPI_ALLOCATE_BUFFER, NULL};
 	struct acpi_resource *res;
@@ -192,7 +192,6 @@ void acpi_gpiochip_request_interrupts(struct gpio_chip *chip)
 				irq);
 	}
 }
-EXPORT_SYMBOL(acpi_gpiochip_request_interrupts);
 
 /**
  * acpi_gpiochip_free_interrupts() - Free GPIO _EVT ACPI event interrupts.
@@ -203,7 +202,7 @@ EXPORT_SYMBOL(acpi_gpiochip_request_interrupts);
  * The remaining ACPI event interrupts associated with the chip are freed
  * automatically.
  */
-void acpi_gpiochip_free_interrupts(struct gpio_chip *chip)
+static void acpi_gpiochip_free_interrupts(struct gpio_chip *chip)
 {
 	acpi_handle handle;
 	acpi_status status;
@@ -230,7 +229,6 @@ void acpi_gpiochip_free_interrupts(struct gpio_chip *chip)
 	acpi_detach_data(handle, acpi_gpio_evt_dh);
 	kfree(evt_pins);
 }
-EXPORT_SYMBOL(acpi_gpiochip_free_interrupts);
 
 struct acpi_gpio_lookup {
 	struct acpi_gpio_info info;
@@ -310,3 +308,13 @@ struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index,
 	return lookup.desc ? lookup.desc : ERR_PTR(-ENODEV);
 }
 EXPORT_SYMBOL_GPL(acpi_get_gpiod_by_index);
+
+void acpi_gpiochip_add(struct gpio_chip *chip)
+{
+	acpi_gpiochip_request_interrupts(chip);
+}
+
+void acpi_gpiochip_remove(struct gpio_chip *chip)
+{
+	acpi_gpiochip_free_interrupts(chip);
+}
drivers/gpio/gpiolib.c +4 -0
index 4e10b10d3ddd..70abccf0d144 100644
@@ -15,6 +15,8 @@
 #include <linux/slab.h>
 #include <linux/acpi.h>
 
+#include "gpiolib.h"
+
 #define CREATE_TRACE_POINTS
 #include <trace/events/gpio.h>
 
@@ -1212,6 +1214,7 @@ int gpiochip_add(struct gpio_chip *chip)
 #endif
 
 	of_gpiochip_add(chip);
+	acpi_gpiochip_add(chip);
 
 	if (status)
 		goto fail;
@@ -1253,6 +1256,7 @@ int gpiochip_remove(struct gpio_chip *chip)
 
 	gpiochip_remove_pin_ranges(chip);
 	of_gpiochip_remove(chip);
+	acpi_gpiochip_remove(chip);
 
 	for (id = 0; id < chip->ngpio; id++) {
 		if (test_bit(FLAG_REQUESTED, &chip->desc[id].flags)) {
drivers/gpio/gpiolib.h new file +23 -0
new file mode 100644
index 000000000000..2ed23ab8298c
@@ -0,0 +1,23 @@
+/*
+ * Internal GPIO functions.
+ *
+ * Copyright (C) 2013, Intel Corporation
+ * Author: Mika Westerberg <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef GPIOLIB_H
+#define GPIOLIB_H
+
+#ifdef CONFIG_ACPI
+void acpi_gpiochip_add(struct gpio_chip *chip);
+void acpi_gpiochip_remove(struct gpio_chip *chip);
+#else
+static inline void acpi_gpiochip_add(struct gpio_chip *chip) { }
+static inline void acpi_gpiochip_remove(struct gpio_chip *chip) { }
+#endif
+
+#endif /* GPIOLIB_H */
drivers/pinctrl/pinctrl-baytrail.c +0 -4
index 2832576d8b12..98b87a59df2d 100644
@@ -29,7 +29,6 @@
 #include <linux/gpio.h>
 #include <linux/irqdomain.h>
 #include <linux/acpi.h>
-#include <linux/acpi_gpio.h>
 #include <linux/platform_device.h>
 #include <linux/seq_file.h>
 #include <linux/io.h>
@@ -485,9 +484,6 @@ static int byt_gpio_probe(struct platform_device *pdev)
 
 		irq_set_handler_data(hwirq, vg);
 		irq_set_chained_handler(hwirq, byt_gpio_irq_handler);
-
-		/* Register interrupt handlers for gpio signaled acpi events */
-		acpi_gpiochip_request_interrupts(gc);
 	}
 
 	pm_runtime_enable(dev);
include/linux/acpi_gpio.h +0 -6
index d875bc3dba3c..af96a0d452f6 100644
@@ -21,9 +21,6 @@ struct acpi_gpio_info {
 
 struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index,
 					  struct acpi_gpio_info *info);
-void acpi_gpiochip_request_interrupts(struct gpio_chip *chip);
-void acpi_gpiochip_free_interrupts(struct gpio_chip *chip);
-
 #else /* CONFIG_GPIO_ACPI */
 
 static inline struct gpio_desc *
@@ -33,9 +30,6 @@ acpi_get_gpiod_by_index(struct device *dev, int index,
 	return ERR_PTR(-ENOSYS);
 }
 
-static inline void acpi_gpiochip_request_interrupts(struct gpio_chip *chip) { }
-static inline void acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { }
-
 #endif /* CONFIG_GPIO_ACPI */
 
 static inline int acpi_get_gpio_by_index(struct device *dev, int index,
Signature · 1 line
1.8.4.3
#19 lore raw

PATCH v2 6/7 gpio / ACPI: get rid of acpi_gpio.h

In reply to Mika Westerberg

Now that all users of acpi_gpio.h have been moved to user either the GPIO descriptor interface or to the internal gpiolib.h we can get rid of acpi_gpio.h entirely.

Once this is done the only interface to get GPIOs to drivers enumerated from ACPI namespace is the descriptor based interface.

---
 drivers/gpio/gpiolib-acpi.c |  4 +++-
 drivers/gpio/gpiolib.c      |  1 -
 drivers/gpio/gpiolib.h      | 23 +++++++++++++++++++++++
 include/linux/acpi_gpio.h   | 45 ---------------------------------------------
 4 files changed, 26 insertions(+), 47 deletions(-)
 delete mode 100644 include/linux/acpi_gpio.h
drivers/gpio/gpiolib-acpi.c +3 -1
index cb2da66fbbfe..6c158d9a6efa 100644
@@ -12,11 +12,13 @@
 
 #include <linux/errno.h>
 #include <linux/gpio/consumer.h>
+#include <linux/gpio/driver.h>
 #include <linux/export.h>
-#include <linux/acpi_gpio.h>
 #include <linux/acpi.h>
 #include <linux/interrupt.h>
 
+#include "gpiolib.h"
+
 struct acpi_gpio_evt_pin {
 	struct list_head node;
 	acpi_handle *evt_handle;
drivers/gpio/gpiolib.c +0 -1
index 70abccf0d144..a6b82413c290 100644
@@ -10,7 +10,6 @@
 #include <linux/seq_file.h>
 #include <linux/gpio.h>
 #include <linux/of_gpio.h>
-#include <linux/acpi_gpio.h>
 #include <linux/idr.h>
 #include <linux/slab.h>
 #include <linux/acpi.h>
drivers/gpio/gpiolib.h +23 -0
index 2ed23ab8298c..82be586c1f90 100644
@@ -12,12 +12,35 @@
 #ifndef GPIOLIB_H
 #define GPIOLIB_H
 
+#include <linux/err.h>
+#include <linux/device.h>
+
+/**
+ * struct acpi_gpio_info - ACPI GPIO specific information
+ * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo
+ * @active_low: in case of @gpioint, the pin is active low
+ */
+struct acpi_gpio_info {
+	bool gpioint;
+	bool active_low;
+};
+
 #ifdef CONFIG_ACPI
 void acpi_gpiochip_add(struct gpio_chip *chip);
 void acpi_gpiochip_remove(struct gpio_chip *chip);
+
+struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index,
+					  struct acpi_gpio_info *info);
 #else
 static inline void acpi_gpiochip_add(struct gpio_chip *chip) { }
 static inline void acpi_gpiochip_remove(struct gpio_chip *chip) { }
+
+static inline struct gpio_desc *
+acpi_get_gpiod_by_index(struct device *dev, int index,
+			struct acpi_gpio_info *info)
+{
+	return ERR_PTR(-ENOSYS);
+}
 #endif
 
 #endif /* GPIOLIB_H */
include/linux/acpi_gpio.h deleted +0 -45

45 lines not on this page · raw message

Signature · 1 line
1.8.4.3
#24 lore raw

PATCH v2 7/7 Documentation / ACPI: update to GPIO descriptor API

In reply to Mika Westerberg

Update the documentation also to reflect the fact that there are no ACPI specific GPIO interfaces anymore but drivers should instead use the descriptor based GPIO APIs.

---
 Documentation/acpi/enumeration.txt | 36 +++++++-----------------------------
 1 file changed, 7 insertions(+), 29 deletions(-)
Documentation/acpi/enumeration.txt +7 -29
index b994bcb32b92..2a1519b87177 100644
@@ -293,36 +293,13 @@ the device to the driver. For example:
 
 These GPIO numbers are controller relative and path "\\_SB.PCI0.GPI0"
 specifies the path to the controller. In order to use these GPIOs in Linux
-we need to translate them to the Linux GPIO numbers.
+we need to translate them to the corresponding Linux GPIO descriptors.
 
-In a simple case of just getting the Linux GPIO number from device
-resources one can use acpi_get_gpio_by_index() helper function. It takes
-pointer to the device and index of the GpioIo/GpioInt descriptor in the
-device resources list. For example:
+There is a standard GPIO API for that and is documented in
+Documentation/gpio.txt.
 
-	int gpio_irq, gpio_power;
-	int ret;
-
-	gpio_irq = acpi_get_gpio_by_index(dev, 1, NULL);
-	if (gpio_irq < 0)
-		/* handle error */
-
-	gpio_power = acpi_get_gpio_by_index(dev, 0, NULL);
-	if (gpio_power < 0)
-		/* handle error */
-
-	/* Now we can use the GPIO numbers */
-
-Other GpioIo parameters must be converted first by the driver to be
-suitable to the gpiolib before passing them.
-
-In case of GpioInt resource an additional call to gpio_to_irq() must be
-done before calling request_irq().
-
-Note that the above API is ACPI specific and not recommended for drivers
-that need to support non-ACPI systems. The recommended way is to use
-the descriptor based GPIO interfaces. The above example looks like this
-when converted to the GPIO desc:
+In the above example we can get the corresponding two GPIO descriptors with
+a code like this:
 
 	#include <linux/gpio/consumer.h>
 	...
@@ -339,4 +316,5 @@ when converted to the GPIO desc:
 
 	/* Now we can use the GPIO descriptors */
 
-See also Documentation/gpio.txt.
+There are also devm_* versions of these functions which release the
+descriptors once the device is released.
Signature · 1 line
1.8.4.3
Acked-by on the v2 series
#25 lore raw
In reply to Mika Westerberg
Quoted 35 lines · Mika Westerberg

Hi all,

Now that the mainline kernel has full ACPI support for the GPIO descriptor interface we can get rid of ACPI specific GPIO functions in favor of GPIO descriptor (gpiod_*) interfaces.

This series first converts the existing two users to this interface and then modifies gpiolib and gpiolib-acpi so that the ACPI functions are only called internally in drivers/gpio. We then remove the acpi_gpio.h and require all users to user gpiod_* interfaces.

This is second version of the series. Changes to the previous [1]:
* paz00 is passing the lookup table so that we don't need to have gpio conversion function in rfkill-gpio.c anymore.
* Corrected sdhci-acpi.c to pass con_id and added call to gpiod_direction_input().

I suppose it would make sense to merge the whole series via GPIO or ACPI trees because there's a dependency that the first two patches need to be applied before last three. Otherwise the drivers in question fail to compile.

[1] https://lkml.org/lkml/2013/11/21/317

Heikki Krogerus (3):
net: rfkill: gpio: convert to descriptor-based GPIO interface
ARM: tegra: add gpiod_lookup table for paz00
net: rfkill: gpio: remove gpio conversion support

Mika Westerberg (4):
mmc: sdhci-acpi: covert to use GPIO descriptor API gpio / ACPI: register to ACPI events automatically gpio / ACPI: get rid of acpi_gpio.h Documentation / ACPI: update to GPIO descriptor API

Quoted 12 lines
 Documentation/acpi/enumeration.txt | 36 ++++--------------
 arch/arm/mach-tegra/board-paz00.c  |  9 ++++-
 drivers/gpio/gpiolib-acpi.c        | 20 +++++++---
 drivers/gpio/gpiolib.c             |  5 ++-
 drivers/gpio/gpiolib.h             | 46 +++++++++++++++++++++++
 drivers/mmc/host/sdhci-acpi.c      | 26 ++++++-------
 drivers/pinctrl/pinctrl-baytrail.c |  4 --
 include/linux/acpi_gpio.h          | 51 -------------------------
 net/rfkill/rfkill-gpio.c           | 77 +++++++++++++++++---------------------
 9 files changed, 125 insertions(+), 149 deletions(-)
 create mode 100644 drivers/gpio/gpiolib.h
 delete mode 100644 include/linux/acpi_gpio.h

for the ACPI-related material in this series.

Thanks,
Rafael

maintainer Acked-by on v2 4/7
#16 lore raw

Re: [PATCH v2 4/7] mmc: sdhci-acpi: covert to use GPIO descriptor API

In reply to Mika Westerberg
Quoted 5 lines · Mika Westerberg

The new descriptor based GPIO interface is now the recommended and safer way of using GPIOs from device drivers. Convert the ACPI SDHCI driver to use that interface.

Quoted 88 lines
---
 drivers/mmc/host/sdhci-acpi.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)
drivers/mmc/host/sdhci-acpi.c +12 -14
index ef19874fcd1f..5c86550f83ad 100644
@@ -31,10 +31,9 @@
 #include <linux/bitops.h>
 #include <linux/types.h>
 #include <linux/err.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/interrupt.h>
 #include <linux/acpi.h>
-#include <linux/acpi_gpio.h>
 #include <linux/pm.h>
 #include <linux/pm_runtime.h>
 #include <linux/delay.h>
@@ -199,22 +198,23 @@ static irqreturn_t sdhci_acpi_sd_cd(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
-static int sdhci_acpi_add_own_cd(struct device *dev, int gpio,
-				 struct mmc_host *mmc)
+static int sdhci_acpi_add_own_cd(struct device *dev, struct mmc_host *mmc)
 {
+	struct gpio_desc *desc;
 	unsigned long flags;
 	int err, irq;
 
-	if (gpio < 0) {
-		err = gpio;
+	desc = devm_gpiod_get_index(dev, "sd_cd", 0);
+	if (IS_ERR(desc)) {
+		err = PTR_ERR(desc);
 		goto out;
 	}
 
-	err = devm_gpio_request_one(dev, gpio, GPIOF_DIR_IN, "sd_cd");
+	err = gpiod_direction_input(desc);
 	if (err)
-		goto out;
+		goto out_free;
 
-	irq = gpio_to_irq(gpio);
+	irq = gpiod_to_irq(desc);
 	if (irq < 0) {
 		err = irq;
 		goto out_free;
@@ -228,7 +228,7 @@ static int sdhci_acpi_add_own_cd(struct device *dev, int gpio,
 	return 0;
 
 out_free:
-	devm_gpio_free(dev, gpio);
+	devm_gpiod_put(dev, desc);
 out:
 	dev_warn(dev, "failed to setup card detect wake up\n");
 	return err;
@@ -254,7 +254,7 @@ static int sdhci_acpi_probe(struct platform_device *pdev)
 	struct resource *iomem;
 	resource_size_t len;
 	const char *hid;
-	int err, gpio;
+	int err;
 
 	if (acpi_bus_get_device(handle, &device))
 		return -ENODEV;
@@ -279,8 +279,6 @@ static int sdhci_acpi_probe(struct platform_device *pdev)
 	if (IS_ERR(host))
 		return PTR_ERR(host);
 
-	gpio = acpi_get_gpio_by_index(dev, 0, NULL);
-
 	c = sdhci_priv(host);
 	c->host = host;
 	c->slot = sdhci_acpi_get_slot(handle, hid);
@@ -338,7 +336,7 @@ static int sdhci_acpi_probe(struct platform_device *pdev)
 		goto err_free;
 
 	if (sdhci_acpi_flag(c, SDHCI_ACPI_SD_CD)) {
-		if (sdhci_acpi_add_own_cd(dev, gpio, host->mmc))
+		if (sdhci_acpi_add_own_cd(dev, host->mmc))
 			c->use_runtime_pm = false;
 	}
 
Tested-by on v2 2/7
#3 lore raw

Re: [PATCH v2 2/7] ARM: tegra: add gpiod_lookup table for paz00

In reply to Mika Westerberg
Quoted 4 lines · Mika Westerberg

From: Heikki Krogerus <[email protected]>

This makes it possible to request the gpio descriptors in rfkill-gpio driver regardless of the platform.

Patches 1-3,

All the testing I did was to "cat /sys/kernel/debug/gpios" to make sure those two GPIOs had been correctly acquired by the driver, and that they changed state as expected via the command-line "rfkill {un,}block" commands.

However, please note that I had to apply a couple fixes to the gpiolib core to get this working:

1)

To solve the following build warning:

Quoted 3 lines

In file included from arch/arm/mach-tegra/board-paz00.c:21:0:
include/linux/gpio/driver.h:102:17: warning: ‘struct of_phandle_args’ declared inside parameter list [enabled by default] include/linux/gpio/driver.h:102:17: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]

I applied:

include/linux/gpio/driver.h line 11

Quoted 12 lines
include/linux/gpio/driver.h +1 -0
index 82eac610ce1a..5133cf29803a 100644
@@ -5,6 +5,7 @@
 
 struct device;
 struct gpio_desc;
+struct of_phandle_args;
 struct seq_file;
 
 /**

2)

In order to get the GPIO lookups from the rfkill driver working, I applied:

drivers/gpio/gpiolib.c static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id, · line 2374

Quoted 13 lines
drivers/gpio/gpiolib.c +1 -1
index ac53a9593662..b73c39f99858 100644
@@ -2368,7 +2368,7 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
 				continue;
 			}
 
-			if (chip->ngpio >= p->chip_hwnum) {
+			if (chip->ngpio <= p->chip_hwnum) {
 				dev_warn(dev, "GPIO chip %s has %d GPIOs\n",
 					 chip->label, chip->ngpio);
 				continue;

--
To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw

Re: [PATCH v2 3/7] net: rfkill: gpio: remove gpio conversion support

In reply to Mika Westerberg
Quoted 4 lines · Mika Westerberg

From: Heikki Krogerus <[email protected]>

All platforms using this driver are now converted to the new descriptor-based GPIO interface.

Don't you want to remove the fields from the pdata structure too, since it's pointless to set them anymore IIUC?

#7 lore raw

Re: [PATCH v2 3/7] net: rfkill: gpio: remove gpio conversion support

Quoted 8 lines · Stephen Warren
Quoted 4 lines · Mika Westerberg

From: Heikki Krogerus <[email protected]>

All platforms using this driver are now converted to the new descriptor-based GPIO interface.

Don't you want to remove the fields from the pdata structure too, since it's pointless to set them anymore IIUC?

Agreed. We should have removed them in this patch.

I have prepared a separate patch where I remove those and some other unused fields from the pdata structure (attachment). Would it be OK to add that to this patch set? Or should this patch simply be updated?

Signature · 1 line
heikki
Quoted 1 line

From 1c561787e04361b2a6a8114df99b6a2854834684 Mon Sep 17 00:00:00 2001

From: Heikki Krogerus <[email protected]>
Date: Fri, 22 Nov 2013 15:35:10 +0200
Subject: [PATCH] net: rfkill: gpio: remove obsolete fields from platform data

The driver does not support the legacy GPIO API any more and there are no users for the clock.

The platform setup hooks were apparently designed to be used if platform specific configurations like pin multiplexing needed handling. Now there is the pin control subsystem that is designed to cover such things. In any case, there are no users for those either.

---
 include/linux/rfkill-gpio.h | 15 ++-------------
 net/rfkill/rfkill-gpio.c    | 25 -------------------------
 2 files changed, 2 insertions(+), 38 deletions(-)
include/linux/rfkill-gpio.h +2 -13
index 4d09f6e..2c65e5d 100644
@@ -20,28 +20,17 @@
 #ifndef __RFKILL_GPIO_H
 #define __RFKILL_GPIO_H
 
-#include <linux/types.h>
 #include <linux/rfkill.h>
 
 /**
  * struct rfkill_gpio_platform_data - platform data for rfkill gpio device.
- * for unused gpio's, the expected value is -1.
- * @name:		name for the gpio rf kill instance
- * @reset_gpio:		GPIO which is used for reseting rfkill switch
- * @shutdown_gpio:	GPIO which is used for shutdown of rfkill switch
- * @power_clk_name:	[optional] name of clk to turn off while blocked
- * @gpio_runtime_close:	clean up platform specific gpio configuration
- * @gpio_runtime_setup:	set up platform specific gpio configuration
+ * @name: name for the gpio rfkill instance
+ * @type: rfkill type for the instance
  */
 
 struct rfkill_gpio_platform_data {
 	char			*name;
-	int			reset_gpio;
-	int			shutdown_gpio;
-	const char		*power_clk_name;
 	enum rfkill_type	type;
-	void	(*gpio_runtime_close)(struct platform_device *);
-	int	(*gpio_runtime_setup)(struct platform_device *);
 };
 
 #endif /* __RFKILL_GPIO_H */
net/rfkill/rfkill-gpio.c +0 -25
index bd2a5b9..829da11 100644
@@ -22,7 +22,6 @@
 #include <linux/module.h>
 #include <linux/rfkill.h>
 #include <linux/platform_device.h>
-#include <linux/clk.h>
 #include <linux/slab.h>
 #include <linux/acpi.h>
 #include <linux/gpio/consumer.h>
@@ -38,9 +37,6 @@ struct rfkill_gpio_data {
 	struct rfkill		*rfkill_dev;
 	char			*reset_name;
 	char			*shutdown_name;
-	struct clk		*clk;
-
-	bool			clk_enabled;
 };
 
 static int rfkill_gpio_set_power(void *data, bool blocked)
@@ -50,17 +46,11 @@ static int rfkill_gpio_set_power(void *data, bool blocked)
 	if (blocked) {
 		gpiod_set_value(rfkill->shutdown_gpio, 0);
 		gpiod_set_value(rfkill->reset_gpio, 0);
-		if (!IS_ERR(rfkill->clk) && rfkill->clk_enabled)
-			clk_disable(rfkill->clk);
 	} else {
-		if (!IS_ERR(rfkill->clk) && !rfkill->clk_enabled)
-			clk_enable(rfkill->clk);
 		gpiod_set_value(rfkill->reset_gpio, 1);
 		gpiod_set_value(rfkill->shutdown_gpio, 1);
 	}
 
-	rfkill->clk_enabled = blocked;
-
 	return 0;
 }
 
@@ -87,7 +77,6 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
 {
 	struct rfkill_gpio_platform_data *pdata = pdev->dev.platform_data;
 	struct rfkill_gpio_data *rfkill;
-	const char *clk_name = NULL;
 	struct gpio_desc *gpio;
 	int ret;
 	int len;
@@ -101,7 +90,6 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
 		if (ret)
 			return ret;
 	} else if (pdata) {
-		clk_name = pdata->power_clk_name;
 		rfkill->name = pdata->name;
 		rfkill->type = pdata->type;
 	} else {
@@ -120,8 +108,6 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
 	snprintf(rfkill->reset_name, len + 6 , "%s_reset", rfkill->name);
 	snprintf(rfkill->shutdown_name, len + 9, "%s_shutdown", rfkill->name);
 
-	rfkill->clk = devm_clk_get(&pdev->dev, clk_name);
-
 	gpio = devm_gpiod_get_index(&pdev->dev, rfkill->reset_name, 0);
 	if (!IS_ERR(gpio)) {
 		ret = gpiod_direction_output(gpio, 0);
@@ -146,14 +132,6 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	if (pdata && pdata->gpio_runtime_setup) {
-		ret = pdata->gpio_runtime_setup(pdev);
-		if (ret) {
-			dev_err(&pdev->dev, "can't set up gpio\n");
-			return ret;
-		}
-	}
-
 	rfkill->rfkill_dev = rfkill_alloc(rfkill->name, &pdev->dev,
 					  rfkill->type, &rfkill_gpio_ops,
 					  rfkill);
@@ -174,10 +152,7 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
 static int rfkill_gpio_remove(struct platform_device *pdev)
 {
 	struct rfkill_gpio_data *rfkill = platform_get_drvdata(pdev);
-	struct rfkill_gpio_platform_data *pdata = pdev->dev.platform_data;
 
-	if (pdata && pdata->gpio_runtime_close)
-		pdata->gpio_runtime_close(pdev);
 	rfkill_unregister(rfkill->rfkill_dev);
 	rfkill_destroy(rfkill->rfkill_dev);
 
Signature · 1 line
1.8.4.3
#8 lore raw

Re: [PATCH v2 3/7] net: rfkill: gpio: remove gpio conversion support

Quoted 7 lines · Heikki Krogerus
Quoted 6 lines · Stephen Warren
Quoted 4 lines · Mika Westerberg

From: Heikki Krogerus <[email protected]>

All platforms using this driver are now converted to the new descriptor-based GPIO interface.

Quoted 8 lines
Quoted 2 lines

Don't you want to remove the fields from the pdata structure too, since it's pointless to set them anymore IIUC?

Agreed. We should have removed them in this patch.

I have prepared a separate patch where I remove those and some other unused fields from the pdata structure (attachment). Would it be OK to add that to this patch set? Or should this patch simply be updated?

I would suggest killing off the two GPIO fields in this patch, since it's logically part of this change. I think the balance of the patch is unrelated to gpiod conversion, so should probably be sent separately, although watch out for dependencies.

#4 lore raw

Re: [PATCH v2 2/7] ARM: tegra: add gpiod_lookup table for paz00

In reply to Stephen Warren
Quoted 52 lines · Stephen Warren
Quoted 4 lines · Mika Westerberg

From: Heikki Krogerus <[email protected]>

This makes it possible to request the gpio descriptors in rfkill-gpio driver regardless of the platform.

Patches 1-3,

All the testing I did was to "cat /sys/kernel/debug/gpios" to make sure those two GPIOs had been correctly acquired by the driver, and that they changed state as expected via the command-line "rfkill {un,}block" commands.

However, please note that I had to apply a couple fixes to the gpiolib core to get this working:

1)

To solve the following build warning:

Quoted 3 lines

In file included from arch/arm/mach-tegra/board-paz00.c:21:0:
include/linux/gpio/driver.h:102:17: warning: ‘struct of_phandle_args’ declared inside parameter list [enabled by default] include/linux/gpio/driver.h:102:17: warning: its scope is only this definition or declaration, which is probably not what you want [enabled by default]

I applied:

include/linux/gpio/driver.h line 11

Quoted 12 lines
include/linux/gpio/driver.h +1 -0
index 82eac610ce1a..5133cf29803a 100644
@@ -5,6 +5,7 @@
 
 struct device;
 struct gpio_desc;
+struct of_phandle_args;
 struct seq_file;
 
 /**

2)

In order to get the GPIO lookups from the rfkill driver working, I applied:

Quoted 8 lines
drivers/gpio/gpiolib.c +0 -0
index ac53a9593662..b73c39f99858 100644
@@ -2368,7 +2368,7 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
                              continue;
                      }
 
Quoted 5 lines

drivers/gpio/gpiolib.c static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id, · line 2374

Quoted 5 lines
drivers/gpio/gpiolib.c +1 -1
-                     if (chip->ngpio >= p->chip_hwnum) {
+                     if (chip->ngpio <= p->chip_hwnum) {
                              dev_warn(dev, "GPIO chip %s has %d GPIOs\n",
                                       chip->label, chip->ngpio);
                              continue;

Mmm. I guess should be blamed for this one. I haven't tested GPIO platform lookup in a while and this seems to have slipped in at some point. :( I will send fixup patches to Linus for both issues, thanks for pointing them out.

Alex.
--
To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#10 lore raw

Re: [PATCH v2 3/7] net: rfkill: gpio: remove gpio conversion support

In reply to Mika Westerberg
Quoted 90 lines · Mika Westerberg

From: Heikki Krogerus <[email protected]>

All platforms using this driver are now converted to the new descriptor-based GPIO interface.

---
 net/rfkill/rfkill-gpio.c | 61 ++++++++++--------------------------------------
 1 file changed, 12 insertions(+), 49 deletions(-)
net/rfkill/rfkill-gpio.c +6 -48
index 503432154616..bd2a5b90400c 100644
@@ -68,35 +68,6 @@ static const struct rfkill_ops rfkill_gpio_ops = {
        .set_block = rfkill_gpio_set_power,
 };
 
-static int rfkill_gpio_convert_to_desc(struct platform_device *pdev,
-                                      struct rfkill_gpio_data *rfkill)
-{
-       struct rfkill_gpio_platform_data *pdata = pdev->dev.platform_data;
-       int ret;
-
-       if (gpio_is_valid(pdata->reset_gpio)) {
-               ret = devm_gpio_request_one(&pdev->dev, pdata->reset_gpio,
-                                           0, rfkill->reset_name);
-               if (ret) {
-                       dev_err(&pdev->dev, "failed to get reset gpio.\n");
-                       return ret;
-               }
-               rfkill->reset_gpio = gpio_to_desc(pdata->reset_gpio);
-       }
-
-       if (gpio_is_valid(pdata->shutdown_gpio)) {
-               ret = devm_gpio_request_one(&pdev->dev, pdata->shutdown_gpio,
-                                           0, rfkill->shutdown_name);
-               if (ret) {
-                       dev_err(&pdev->dev, "failed to get shutdown gpio.\n");
-                       return ret;
-               }
-               rfkill->shutdown_gpio = gpio_to_desc(pdata->shutdown_gpio);
-       }
-
-       return 0;
-}
-
 static int rfkill_gpio_acpi_probe(struct device *dev,
                                  struct rfkill_gpio_data *rfkill)
 {
@@ -117,6 +88,7 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
        struct rfkill_gpio_platform_data *pdata = pdev->dev.platform_data;
        struct rfkill_gpio_data *rfkill;
        const char *clk_name = NULL;
+       struct gpio_desc *gpio;
        int ret;
        int len;
 
@@ -150,29 +122,20 @@ static int rfkill_gpio_probe(struct platform_device *pdev)
 
        rfkill->clk = devm_clk_get(&pdev->dev, clk_name);
 
-       if (pdata && (pdata->reset_gpio || pdata->shutdown_gpio)) {
-               ret = rfkill_gpio_convert_to_desc(pdev, rfkill);
+       gpio = devm_gpiod_get_index(&pdev->dev, rfkill->reset_name, 0);
+       if (!IS_ERR(gpio)) {
+               ret = gpiod_direction_output(gpio, 0);
                if (ret)
                        return ret;
-       } else {
-               struct gpio_desc *gpio;
-
-               gpio = devm_gpiod_get_index(&pdev->dev, rfkill->reset_name, 0);
-               if (!IS_ERR(gpio)) {
-                       ret = gpiod_direction_output(gpio, 0);
-                       if (ret)
-                               return ret;
-                       rfkill->reset_gpio = gpio;
-               }
+               rfkill->reset_gpio = gpio;
+       }
 
-               gpio = devm_gpiod_get_index(&pdev->dev,
-                                           rfkill->shutdown_name, 1);
-               if (!IS_ERR(gpio)) {
-                       ret = gpiod_direction_output(gpio, 0);
-                       if (ret)
-                               return ret;
-                       rfkill->shutdown_gpio = gpio;

net/rfkill/rfkill-gpio.c static int rfkill_gpio_probe(struct platform_device *pdev) · line 141

Quoted 10 lines
net/rfkill/rfkill-gpio.c +6 -1
-               }
+       gpio = devm_gpiod_get_index(&pdev->dev, rfkill->shutdown_name, 1);
+       if (!IS_ERR(gpio)) {
+               ret = gpiod_direction_output(gpio, 0);
+               if (ret)
+                       return ret;
+               rfkill->shutdown_gpio = gpio;
        }
 
        /* Make sure at-least one of the GPIO is defined and that

Wouldn't it be possible (and simpler) to move patch 2 of your series to first position, and then to merge patch 1 and 3 together in second position? It seems to me that you are basically undoing much of the work of your first patch here (notably by removing rfkill_gpio_convert_to_desc() which ends up having a very short life) and that this could be avoided if you defined the platform lookup tables first.

Doing so would avoid prevent you from using gpio_to_desc() which you should never ever use anyway. :P

#20 lore raw

Re: [PATCH v2 6/7] gpio / ACPI: get rid of acpi_gpio.h

In reply to Mika Westerberg
Quoted 1 line · Mika Westerberg

Now that all users of acpi_gpio.h have been moved to user either the GPIO

s/user/use

Quoted 1 line

descriptor interface or to the internal gpiolib.h we can get rid of

gpiolib.h will also need to be renamed if you follow my suggestion below.

Quoted 4 lines

acpi_gpio.h entirely.

Once this is done the only interface to get GPIOs to drivers enumerated from ACPI namespace is the descriptor based interface.

Oh, do I like this. :)

Quoted 69 lines
---
 drivers/gpio/gpiolib-acpi.c |  4 +++-
 drivers/gpio/gpiolib.c      |  1 -
 drivers/gpio/gpiolib.h      | 23 +++++++++++++++++++++++
 include/linux/acpi_gpio.h   | 45 ---------------------------------------------
 4 files changed, 26 insertions(+), 47 deletions(-)
 delete mode 100644 include/linux/acpi_gpio.h
drivers/gpio/gpiolib-acpi.c +3 -1
index cb2da66fbbfe..6c158d9a6efa 100644
@@ -12,11 +12,13 @@
 
 #include <linux/errno.h>
 #include <linux/gpio/consumer.h>
+#include <linux/gpio/driver.h>
 #include <linux/export.h>
-#include <linux/acpi_gpio.h>
 #include <linux/acpi.h>
 #include <linux/interrupt.h>
 
+#include "gpiolib.h"
+
 struct acpi_gpio_evt_pin {
        struct list_head node;
        acpi_handle *evt_handle;
drivers/gpio/gpiolib.c +0 -1
index 70abccf0d144..a6b82413c290 100644
@@ -10,7 +10,6 @@
 #include <linux/seq_file.h>
 #include <linux/gpio.h>
 #include <linux/of_gpio.h>
-#include <linux/acpi_gpio.h>
 #include <linux/idr.h>
 #include <linux/slab.h>
 #include <linux/acpi.h>
drivers/gpio/gpiolib.h +16 -0
index 2ed23ab8298c..82be586c1f90 100644
@@ -12,12 +12,35 @@
 #ifndef GPIOLIB_H
 #define GPIOLIB_H
 
+#include <linux/err.h>
+#include <linux/device.h>
+
+/**
+ * struct acpi_gpio_info - ACPI GPIO specific information
+ * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo
+ * @active_low: in case of @gpioint, the pin is active low
+ */
+struct acpi_gpio_info {
+       bool gpioint;
+       bool active_low;
+};
+
 #ifdef CONFIG_ACPI
 void acpi_gpiochip_add(struct gpio_chip *chip);
 void acpi_gpiochip_remove(struct gpio_chip *chip);
+
+struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index,
+                                         struct acpi_gpio_info *info);
 #else

drivers/gpio/gpiolib.h line 44

Quoted 10 lines
drivers/gpio/gpiolib.h +7 -0
 static inline void acpi_gpiochip_add(struct gpio_chip *chip) { }
 static inline void acpi_gpiochip_remove(struct gpio_chip *chip) { }
+
+static inline struct gpio_desc *
+acpi_get_gpiod_by_index(struct device *dev, int index,
+                       struct acpi_gpio_info *info)
+{
+       return ERR_PTR(-ENOSYS);
+}
 #endif

Since this header contains purely ACPI-related declarations so far, I wonder if it should not be renamed acpi.h?

#9 lore raw

Re: [PATCH v2 3/7] net: rfkill: gpio: remove gpio conversion support

In reply to Stephen Warren
Quoted 9 lines · Stephen Warren
Quoted 3 lines · Heikki Krogerus

I have prepared a separate patch where I remove those and some other unused fields from the pdata structure (attachment). Would it be OK to add that to this patch set? Or should this patch simply be updated?

I would suggest killing off the two GPIO fields in this patch, since it's logically part of this change. I think the balance of the patch is unrelated to gpiod conversion, so should probably be sent separately, although watch out for dependencies.

Yes, we'll do it like that.

Thanks,

Signature · 1 line
heikki
#11 lore raw

Re: [PATCH v2 3/7] net: rfkill: gpio: remove gpio conversion support

In reply to Alexandre Courbot
Quoted 10 lines · Alexandre Courbot

Wouldn't it be possible (and simpler) to move patch 2 of your series to first position, and then to merge patch 1 and 3 together in second position? It seems to me that you are basically undoing much of the work of your first patch here (notably by removing rfkill_gpio_convert_to_desc() which ends up having a very short life) and that this could be avoided if you defined the platform lookup tables first.

Doing so would avoid prevent you from using gpio_to_desc() which you should never ever use anyway. :P

Adding the lookup table in first patch and then changing the driver in the second creates a point to the history where this driver stops working on this platform, which is something I'm not willing to do.

But, we can make one patch out of all three if everybody is OK with that.

Signature · 1 line
heikki
#12 lore raw

Re: [PATCH v2 3/7] net: rfkill: gpio: remove gpio conversion support

Quoted 9 lines · Heikki Krogerus
Quoted 8 lines · Alexandre Courbot

Wouldn't it be possible (and simpler) to move patch 2 of your series to first position, and then to merge patch 1 and 3 together in second position? It seems to me that you are basically undoing much of the work of your first patch here (notably by removing rfkill_gpio_convert_to_desc() which ends up having a very short life) and that this could be avoided if you defined the platform lookup tables first.

Quoted 6 lines
Quoted 2 lines

Doing so would avoid prevent you from using gpio_to_desc() which you should never ever use anyway. :P

Adding the lookup table in first patch and then changing the driver in the second creates a point to the history where this driver stops working on this platform, which is something I'm not willing to do.

Does it? If you just add a lookup table and keep using the integer-based GPIO interface, then your lookup table will not be used by anyone and will basically be a no-op. Then you can switch to the GPIO descriptor interface and take advantage of the lookup table. Unless I missed something there should not be any point that breaks in the git history.

(to be clear: the first patch should *only* contain the lookup table, and the second be a merge of the current patches 1 and 3 of this series.)

Quoted 2 lines

But, we can make one patch out of all three if everybody is OK with that.

IIUC platform changes should be distinct from drivers whenever possible, so this is probably not the best choice here.

Alex.

#21 lore raw

Re: [PATCH v2 6/7] gpio / ACPI: get rid of acpi_gpio.h

In reply to Alexandre Courbot
Quoted 5 lines · Alexandre Courbot
Quoted 1 line · Mika Westerberg

Now that all users of acpi_gpio.h have been moved to user either the GPIO

s/user/use

OK.

Quoted 86 lines
Quoted 2 lines

descriptor interface or to the internal gpiolib.h we can get rid of

gpiolib.h will also need to be renamed if you follow my suggestion below.

Quoted 4 lines

acpi_gpio.h entirely.

Once this is done the only interface to get GPIOs to drivers enumerated from ACPI namespace is the descriptor based interface.

Oh, do I like this. :)

Quoted 74 lines
---
 drivers/gpio/gpiolib-acpi.c |  4 +++-
 drivers/gpio/gpiolib.c      |  1 -
 drivers/gpio/gpiolib.h      | 23 +++++++++++++++++++++++
 include/linux/acpi_gpio.h   | 45 ---------------------------------------------
 4 files changed, 26 insertions(+), 47 deletions(-)
 delete mode 100644 include/linux/acpi_gpio.h
drivers/gpio/gpiolib-acpi.c +3 -1
index cb2da66fbbfe..6c158d9a6efa 100644
@@ -12,11 +12,13 @@
 
 #include <linux/errno.h>
 #include <linux/gpio/consumer.h>
+#include <linux/gpio/driver.h>
 #include <linux/export.h>
-#include <linux/acpi_gpio.h>
 #include <linux/acpi.h>
 #include <linux/interrupt.h>
 
+#include "gpiolib.h"
+
 struct acpi_gpio_evt_pin {
        struct list_head node;
        acpi_handle *evt_handle;
drivers/gpio/gpiolib.c +0 -1
index 70abccf0d144..a6b82413c290 100644
@@ -10,7 +10,6 @@
 #include <linux/seq_file.h>
 #include <linux/gpio.h>
 #include <linux/of_gpio.h>
-#include <linux/acpi_gpio.h>
 #include <linux/idr.h>
 #include <linux/slab.h>
 #include <linux/acpi.h>
drivers/gpio/gpiolib.h +19 -0
index 2ed23ab8298c..82be586c1f90 100644
@@ -12,12 +12,35 @@
 #ifndef GPIOLIB_H
 #define GPIOLIB_H
 
+#include <linux/err.h>
+#include <linux/device.h>
+
+/**
+ * struct acpi_gpio_info - ACPI GPIO specific information
+ * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo
+ * @active_low: in case of @gpioint, the pin is active low
+ */
+struct acpi_gpio_info {
+       bool gpioint;
+       bool active_low;
+};
+
 #ifdef CONFIG_ACPI
 void acpi_gpiochip_add(struct gpio_chip *chip);
 void acpi_gpiochip_remove(struct gpio_chip *chip);
+
+struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index,
+                                         struct acpi_gpio_info *info);
 #else
 static inline void acpi_gpiochip_add(struct gpio_chip *chip) { }
 static inline void acpi_gpiochip_remove(struct gpio_chip *chip) { }
+
+static inline struct gpio_desc *
+acpi_get_gpiod_by_index(struct device *dev, int index,
Quoted 8 lines

drivers/gpio/gpiolib.h line 44

Quoted 5 lines
drivers/gpio/gpiolib.h +4 -0
+                       struct acpi_gpio_info *info)
+{
+       return ERR_PTR(-ENOSYS);
+}
 #endif

Since this header contains purely ACPI-related declarations so far, I wonder if it should not be renamed acpi.h?

Well, for now it contains only ACPI related stuff but once you guys start tearing DT interfaces away from drivers, this header is expected to grow :)

So idea is to have gpiolib internal/private header where we can add stuff taht is not going to be exported to drivers.

Acked-by
#22 lore raw

Re: [PATCH v2 6/7] gpio / ACPI: get rid of acpi_gpio.h

Quoted 104 lines · Mika Westerberg
Quoted 5 lines · Alexandre Courbot
Quoted 1 line · Mika Westerberg

Now that all users of acpi_gpio.h have been moved to user either the GPIO

s/user/use

OK.

Quoted 86 lines
Quoted 2 lines

descriptor interface or to the internal gpiolib.h we can get rid of

gpiolib.h will also need to be renamed if you follow my suggestion below.

Quoted 4 lines

acpi_gpio.h entirely.

Once this is done the only interface to get GPIOs to drivers enumerated from ACPI namespace is the descriptor based interface.

Oh, do I like this. :)

Quoted 74 lines
---
  drivers/gpio/gpiolib-acpi.c |  4 +++-
  drivers/gpio/gpiolib.c      |  1 -
  drivers/gpio/gpiolib.h      | 23 +++++++++++++++++++++++
  include/linux/acpi_gpio.h   | 45 ---------------------------------------------
  4 files changed, 26 insertions(+), 47 deletions(-)

delete mode 100644 include/linux/acpi_gpio.h

drivers/gpio/gpiolib-acpi.c +3 -1
index cb2da66fbbfe..6c158d9a6efa 100644
@@ -12,11 +12,13 @@
 
  #include <linux/errno.h>
  #include <linux/gpio/consumer.h>
+#include <linux/gpio/driver.h>
  #include <linux/export.h>
-#include <linux/acpi_gpio.h>
  #include <linux/acpi.h>
  #include <linux/interrupt.h>
 
+#include "gpiolib.h"
+
  struct acpi_gpio_evt_pin {
         struct list_head node;
         acpi_handle *evt_handle;
drivers/gpio/gpiolib.c +0 -1
index 70abccf0d144..a6b82413c290 100644
@@ -10,7 +10,6 @@
  #include <linux/seq_file.h>
  #include <linux/gpio.h>
  #include <linux/of_gpio.h>
-#include <linux/acpi_gpio.h>
  #include <linux/idr.h>
  #include <linux/slab.h>
  #include <linux/acpi.h>
drivers/gpio/gpiolib.h +19 -0
index 2ed23ab8298c..82be586c1f90 100644
@@ -12,12 +12,35 @@
  #ifndef GPIOLIB_H
  #define GPIOLIB_H
 
+#include <linux/err.h>
+#include <linux/device.h>
+
+/**
+ * struct acpi_gpio_info - ACPI GPIO specific information
+ * @gpioint: if %true this GPIO is of type GpioInt otherwise type is GpioIo
+ * @active_low: in case of @gpioint, the pin is active low
+ */
+struct acpi_gpio_info {
+       bool gpioint;
+       bool active_low;
+};
+
  #ifdef CONFIG_ACPI
  void acpi_gpiochip_add(struct gpio_chip *chip);
  void acpi_gpiochip_remove(struct gpio_chip *chip);
+
+struct gpio_desc *acpi_get_gpiod_by_index(struct device *dev, int index,
+                                         struct acpi_gpio_info *info);
  #else
  static inline void acpi_gpiochip_add(struct gpio_chip *chip) { }
  static inline void acpi_gpiochip_remove(struct gpio_chip *chip) { }
+
+static inline struct gpio_desc *
+acpi_get_gpiod_by_index(struct device *dev, int index,
Quoted 8 lines

drivers/gpio/gpiolib.h line 44

Quoted 5 lines
drivers/gpio/gpiolib.h +4 -0
+                       struct acpi_gpio_info *info)
+{
+       return ERR_PTR(-ENOSYS);
+}
  #endif

Since this header contains purely ACPI-related declarations so far, I wonder if it should not be renamed acpi.h?

Quoted 5 lines

Well, for now it contains only ACPI related stuff but once you guys start tearing DT interfaces away from drivers, this header is expected to grow :)

So idea is to have gpiolib internal/private header where we can add stuff taht is not going to be exported to drivers.

I just wondered if these headers should not be split by GPIO providers, but if you prefer it that way I'm fine with it too. We can move stuff later if needed.

#13 lore raw

Re: [PATCH v2 3/7] net: rfkill: gpio: remove gpio conversion support

In reply to Alex Courbot
Quoted 12 lines · Alex Courbot
Quoted 3 lines · Heikki Krogerus

Adding the lookup table in first patch and then changing the driver in the second creates a point to the history where this driver stops working on this platform, which is something I'm not willing to do.

Does it? If you just add a lookup table and keep using the integer-based GPIO interface, then your lookup table will not be used by anyone and will basically be a no-op. Then you can switch to the GPIO descriptor interface and take advantage of the lookup table. Unless I missed something there should not be any point that breaks in the git history.

Quoted 3 lines

(to be clear: the first patch should *only* contain the lookup table, and the second be a merge of the current patches 1 and 3 of this series.)

OK, I agree. If I don't remove the old gpio numbers in in the first patch, there is no problem. We can do this with the two patches.

Thanks,

Signature · 1 line
heikki
#14 lore raw

Re: [PATCH v2 3/7] net: rfkill: gpio: remove gpio conversion support

Quoted 13 lines · Heikki Krogerus
Quoted 12 lines · Alex Courbot
Quoted 3 lines · Heikki Krogerus

Adding the lookup table in first patch and then changing the driver in the second creates a point to the history where this driver stops working on this platform, which is something I'm not willing to do.

Does it? If you just add a lookup table and keep using the integer-based GPIO interface, then your lookup table will not be used by anyone and will basically be a no-op. Then you can switch to the GPIO descriptor interface and take advantage of the lookup table. Unless I missed something there should not be any point that breaks in the git history.

Quoted 6 lines
Quoted 3 lines

(to be clear: the first patch should *only* contain the lookup table, and the second be a merge of the current patches 1 and 3 of this series.)

OK, I agree. If I don't remove the old gpio numbers in in the first patch, there is no problem. We can do this with the two patches.

Yep, that's what I meant. :) It would make the series considerably easier to understand by removing its temporary code.

Thanks,
Alex.

#23 lore raw

Re: [PATCH v2 6/7] gpio / ACPI: get rid of acpi_gpio.h

In reply to Alex Courbot
Quoted 5 lines · Alex Courbot

I just wondered if these headers should not be split by GPIO providers, but if you prefer it that way I'm fine with it too. We can move stuff later if needed.

Thanks!

BTW, I noticed that I missed removing EXPORT_SYMBOL_GPL() from acpi_get_gpiod_by_index(). I'm folding that change to this patch for the next version if nobody objects.