Skip to contentSkip to conversation

gpio: Convert two Intel GPIO drivers to use irqchip helpers

PATCH Applied Mika Westerberg 2 participants 5 messages Jul 25, 2014 – Jul 28, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover gpio: Convert two Intel GPIO drivers to use irqchip helpers

Hi,

As discussed in this thread:

https://www.mail-archive.com/linux-gpio%40vger.kernel.org/msg02929.html

This series converts the Intel Lynxpoint and Baytrail GPIO drivers to use the new irqchip helper functions and then moves ACPI event registration to happen in the helpers as well.

Mika Westerberg (3):
gpio: lynxpoint: Convert to use gpiolib irqchip
pinctrl: baytrail: Convert to use gpiolib irqchip
gpio / ACPI: Move event handling registration to gpiolib irqchip helpers

 drivers/gpio/Kconfig               |  2 +-
 drivers/gpio/gpio-lynxpoint.c      | 93 ++++++++++----------------------------
 drivers/gpio/gpiolib-acpi.c        | 38 ++++++++++++----
 drivers/gpio/gpiolib.c             |  4 ++
 drivers/gpio/gpiolib.h             |  9 ++++
 drivers/pinctrl/Kconfig            |  2 +-
 drivers/pinctrl/pinctrl-baytrail.c | 87 ++++++++---------------------------
 7 files changed, 87 insertions(+), 148 deletions(-)
Signature · 1 line
2.0.1
#1 lore raw

PATCH 1/3 gpio: lynxpoint: Convert to use gpiolib irqchip

Instead of open-coding irqchip handling in the driver we can take advantage of the new irqchip helpers provided by the gpiolib core.

While doing this we also make sure that we call gpiochip_irqchip_add() after the gpiochip itself is registered as required.

---
 drivers/gpio/Kconfig          |  2 +-
 drivers/gpio/gpio-lynxpoint.c | 93 ++++++++++++-------------------------------
 2 files changed, 26 insertions(+), 69 deletions(-)
drivers/gpio/Kconfig +1 -1
index 4a1b5113e527..e70297c20487 100644
@@ -423,7 +423,7 @@ config GPIO_GE_FPGA
 config GPIO_LYNXPOINT
 	tristate "Intel Lynxpoint GPIO support"
 	depends on ACPI && X86
-	select IRQ_DOMAIN
+	select GPIOLIB_IRQCHIP
 	help
 	  driver for GPIO functionality on Intel Lynxpoint PCH chipset
 	  Requires ACPI device enumeration code to set up a platform device.
drivers/gpio/gpio-lynxpoint.c +25 -68

175 lines not on this page · raw message

Signature · 1 line
2.0.1
#2 lore raw

PATCH 2/3 pinctrl: baytrail: Convert to use gpiolib irqchip

In reply to Mika Westerberg

Instead of open-coding irqchip handling in the driver we can take advantage of the new irqchip helpers provided by the gpiolib core.

While doing this we also make sure that we call gpiochip_irqchip_add() after the gpiochip itself is registered as required.

---
 drivers/pinctrl/Kconfig            |  2 +-
 drivers/pinctrl/pinctrl-baytrail.c | 87 +++++++++-----------------------------
 2 files changed, 20 insertions(+), 69 deletions(-)
drivers/pinctrl/Kconfig +1 -1
index 0042ccb46b9a..bd6f9926a569 100644
@@ -93,7 +93,7 @@ config PINCTRL_AT91
 config PINCTRL_BAYTRAIL
 	bool "Intel Baytrail GPIO pin control"
 	depends on GPIOLIB && ACPI && X86
-	select IRQ_DOMAIN
+	select GPIOLIB_IRQCHIP
 	help
 	  driver for memory mapped GPIO functionality on Intel Baytrail
 	  platforms. Supports 3 banks with 102, 28 and 44 gpios.
drivers/pinctrl/pinctrl-baytrail.c +19 -68

155 lines not on this page · raw message

Signature · 1 line
2.0.1
#3 lore raw

PATCH 3/3 gpio / ACPI: Move event handling registration to gpiolib irqchip helpers

In reply to Mika Westerberg

Since now we have irqchip helpers that the GPIO chip drivers are supposed to use if possible, we can move the registration of ACPI events to happen in these helpers. This seems to be more natural place and might encourage GPIO chip driver writers to take advantage of the irqchip helpers.

We make the functions available to GPIO chip drivers via private gpiolib.h, just in case generic irqchip helpers are not suitable.

---
 drivers/gpio/gpiolib-acpi.c | 38 ++++++++++++++++++++++++++++----------
 drivers/gpio/gpiolib.c      |  4 ++++
 drivers/gpio/gpiolib.h      |  9 +++++++++
 3 files changed, 41 insertions(+), 10 deletions(-)
drivers/gpio/gpiolib-acpi.c +28 -10
index 4a987917c186..f3edaeaf3b64 100644
@@ -221,7 +221,7 @@ fail_free_desc:
 
 /**
  * acpi_gpiochip_request_interrupts() - Register isr for gpio chip ACPI events
- * @acpi_gpio:      ACPI GPIO chip
+ * @chip:      GPIO chip
  *
  * ACPI5 platforms can use GPIO signaled ACPI events. These GPIO interrupts are
  * handled by ACPI event methods which need to be called from the GPIO
@@ -229,11 +229,21 @@ fail_free_desc:
  * gpio pins have acpi event methods and assigns interrupt handlers that calls
  * the acpi event methods for those pins.
  */
-static void acpi_gpiochip_request_interrupts(struct acpi_gpio_chip *acpi_gpio)
+void acpi_gpiochip_request_interrupts(struct gpio_chip *chip)
 {
-	struct gpio_chip *chip = acpi_gpio->chip;
+	struct acpi_gpio_chip *acpi_gpio;
+	acpi_handle handle;
+	acpi_status status;
+
+	if (!chip->dev || !chip->to_irq)
+		return;
 
-	if (!chip->to_irq)
+	handle = ACPI_HANDLE(chip->dev);
+	if (!handle)
+		return;
+
+	status = acpi_get_data(handle, acpi_gpio_chip_dh, (void **)&acpi_gpio);
+	if (ACPI_FAILURE(status))
 		return;
 
 	INIT_LIST_HEAD(&acpi_gpio->events);
@@ -243,17 +253,27 @@ static void acpi_gpiochip_request_interrupts(struct acpi_gpio_chip *acpi_gpio)
 
 /**
  * acpi_gpiochip_free_interrupts() - Free GPIO ACPI event interrupts.
- * @acpi_gpio:      ACPI GPIO chip
+ * @chip:      GPIO chip
  *
  * Free interrupts associated with GPIO ACPI event method for the given
  * GPIO chip.
  */
-static void acpi_gpiochip_free_interrupts(struct acpi_gpio_chip *acpi_gpio)
+void acpi_gpiochip_free_interrupts(struct gpio_chip *chip)
 {
+	struct acpi_gpio_chip *acpi_gpio;
 	struct acpi_gpio_event *event, *ep;
-	struct gpio_chip *chip = acpi_gpio->chip;
+	acpi_handle handle;
+	acpi_status status;
+
+	if (!chip->dev || !chip->to_irq)
+		return;
 
-	if (!chip->to_irq)
+	handle = ACPI_HANDLE(chip->dev);
+	if (!handle)
+		return;
+
+	status = acpi_get_data(handle, acpi_gpio_chip_dh, (void **)&acpi_gpio);
+	if (ACPI_FAILURE(status))
 		return;
 
 	list_for_each_entry_safe_reverse(event, ep, &acpi_gpio->events, node) {
@@ -525,7 +545,6 @@ void acpi_gpiochip_add(struct gpio_chip *chip)
 		return;
 	}
 
-	acpi_gpiochip_request_interrupts(acpi_gpio);
 	acpi_gpiochip_request_regions(acpi_gpio);
 }
 
@@ -549,7 +568,6 @@ void acpi_gpiochip_remove(struct gpio_chip *chip)
 	}
 
 	acpi_gpiochip_free_regions(acpi_gpio);
-	acpi_gpiochip_free_interrupts(acpi_gpio);
 
 	acpi_detach_data(handle, acpi_gpio_chip_dh);
 	kfree(acpi_gpio);
drivers/gpio/gpiolib.c +4 -0
index 2ebc9071e354..5a543969ad40 100644
@@ -1474,6 +1474,8 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
 {
 	unsigned int offset;
 
+	acpi_gpiochip_free_interrupts(gpiochip);
+
 	/* Remove all IRQ mappings and delete the domain */
 	if (gpiochip->irqdomain) {
 		for (offset = 0; offset < gpiochip->ngpio; offset++)
@@ -1567,6 +1569,8 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
 			gpiochip->irq_base = irq_base;
 	}
 
+	acpi_gpiochip_request_interrupts(gpiochip);
+
 	return 0;
 }
 EXPORT_SYMBOL_GPL(gpiochip_irqchip_add);
drivers/gpio/gpiolib.h +9 -0
index 1a4103dd38df..6c45cef6620c 100644
@@ -31,12 +31,21 @@ struct acpi_gpio_info {
 void acpi_gpiochip_add(struct gpio_chip *chip);
 void acpi_gpiochip_remove(struct gpio_chip *chip);
 
+void acpi_gpiochip_request_interrupts(struct gpio_chip *chip);
+void acpi_gpiochip_free_interrupts(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 void
+acpi_gpiochip_request_interrupts(struct gpio_chip *chip) { }
+
+static inline void
+acpi_gpiochip_free_interrupts(struct gpio_chip *chip) { }
+
 static inline struct gpio_desc *
 acpi_get_gpiod_by_index(struct device *dev, int index,
 			struct acpi_gpio_info *info)
Signature · 1 line
2.0.1
#4 lore raw
In reply to Mika Westerberg
Quoted 3 lines · Mika Westerberg

This series converts the Intel Lynxpoint and Baytrail GPIO drivers to use the new irqchip helper functions and then moves ACPI event registration to happen in the helpers as well.

Excellent patch set and irresistable to merge.

Applied patches 1 & 3 to the GPIO tree and patch 2 to the pinctrl tree.

Yours,
Linus Walleij