linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Lee Jones <lee.jones@linaro.org>
To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org
Cc: STEricsson_nomadik_linux@list.st.com,
	linus.walleij@stericsson.com, arnd@arndb.de,
	Lee Jones <lee.jones@linaro.org>,
	Grant Likely <grant.likely@secretlab.ca>
Subject: [PATCH 18/19] gpio: Provide the tc3589x GPIO expander driver with an IRQ domain
Date: Fri,  7 Sep 2012 12:14:58 +0100	[thread overview]
Message-ID: <1347016499-29354-19-git-send-email-lee.jones@linaro.org> (raw)
In-Reply-To: <1347016499-29354-1-git-send-email-lee.jones@linaro.org>

In preparation for Device Tree enablement all IRQ controllers
should control their own IRQ domain. This patch provides just
that for the tc3589x GPIO expander.

CC: Grant Likely <grant.likely@secretlab.ca>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/gpio/gpio-tc3589x.c |   98 ++++++++++++++++++++++++++++++-------------
 1 file changed, 70 insertions(+), 28 deletions(-)

diff --git a/drivers/gpio/gpio-tc3589x.c b/drivers/gpio/gpio-tc3589x.c
index 2a82e89..6e89009 100644
--- a/drivers/gpio/gpio-tc3589x.c
+++ b/drivers/gpio/gpio-tc3589x.c
@@ -12,6 +12,7 @@
 #include <linux/slab.h>
 #include <linux/gpio.h>
 #include <linux/irq.h>
+#include <linux/irqdomain.h>
 #include <linux/interrupt.h>
 #include <linux/mfd/tc3589x.h>
 
@@ -29,6 +30,7 @@ struct tc3589x_gpio {
 	struct tc3589x *tc3589x;
 	struct device *dev;
 	struct mutex irq_lock;
+	struct irq_domain *domain;
 
 	int irq_base;
 
@@ -92,11 +94,28 @@ static int tc3589x_gpio_direction_input(struct gpio_chip *chip,
 	return tc3589x_set_bits(tc3589x, reg, 1 << pos, 0);
 }
 
+/**
+ * tc3589x_gpio_irq_get_virq(): Map an interrupt on a chip to a virtual IRQ
+ *
+ * @tc3589x_gpio: tc3589x_gpio_irq controller to operate on.
+ * @irq: index of the interrupt requested in the chip IRQs
+ *
+ * Useful for drivers to request their own IRQs.
+ */
+static int tc3589x_gpio_irq_get_virq(struct tc3589x_gpio *tc3589x_gpio,
+				     int irq)
+{
+	if (!tc3589x_gpio)
+		return -EINVAL;
+
+	return irq_create_mapping(tc3589x_gpio->domain, irq);
+}
+
 static int tc3589x_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
 {
 	struct tc3589x_gpio *tc3589x_gpio = to_tc3589x_gpio(chip);
 
-	return tc3589x_gpio->irq_base + offset;
+	return tc3589x_gpio_irq_get_virq(tc3589x_gpio, offset);
 }
 
 static struct gpio_chip template_chip = {
@@ -113,7 +132,7 @@ static struct gpio_chip template_chip = {
 static int tc3589x_gpio_irq_set_type(struct irq_data *d, unsigned int type)
 {
 	struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d);
-	int offset = d->irq - tc3589x_gpio->irq_base;
+	int offset = d->hwirq;
 	int regoffset = offset / 8;
 	int mask = 1 << (offset % 8);
 
@@ -175,7 +194,7 @@ static void tc3589x_gpio_irq_sync_unlock(struct irq_data *d)
 static void tc3589x_gpio_irq_mask(struct irq_data *d)
 {
 	struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d);
-	int offset = d->irq - tc3589x_gpio->irq_base;
+	int offset = d->hwirq;
 	int regoffset = offset / 8;
 	int mask = 1 << (offset % 8);
 
@@ -185,7 +204,7 @@ static void tc3589x_gpio_irq_mask(struct irq_data *d)
 static void tc3589x_gpio_irq_unmask(struct irq_data *d)
 {
 	struct tc3589x_gpio *tc3589x_gpio = irq_data_get_irq_chip_data(d);
-	int offset = d->irq - tc3589x_gpio->irq_base;
+	int offset = d->hwirq;
 	int regoffset = offset / 8;
 	int mask = 1 << (offset % 8);
 
@@ -222,8 +241,9 @@ static irqreturn_t tc3589x_gpio_irq(int irq, void *dev)
 		while (stat) {
 			int bit = __ffs(stat);
 			int line = i * 8 + bit;
+			int virq = tc3589x_gpio_irq_get_virq(tc3589x_gpio, line);
 
-			handle_nested_irq(tc3589x_gpio->irq_base + line);
+			handle_nested_irq(virq);
 			stat &= ~(1 << bit);
 		}
 
@@ -233,38 +253,60 @@ static irqreturn_t tc3589x_gpio_irq(int irq, void *dev)
 	return IRQ_HANDLED;
 }
 
-static int tc3589x_gpio_irq_init(struct tc3589x_gpio *tc3589x_gpio)
+static int tc3589x_gpio_irq_map(struct irq_domain *d, unsigned int virq,
+				irq_hw_number_t hwirq)
 {
-	int base = tc3589x_gpio->irq_base;
-	int irq;
+	struct tc3589x *tc3589x_gpio = d->host_data;
 
-	for (irq = base; irq < base + tc3589x_gpio->chip.ngpio; irq++) {
-		irq_set_chip_data(irq, tc3589x_gpio);
-		irq_set_chip_and_handler(irq, &tc3589x_gpio_irq_chip,
-					 handle_simple_irq);
-		irq_set_nested_thread(irq, 1);
+	irq_set_chip_data(virq, tc3589x_gpio);
+	irq_set_chip_and_handler(virq, &tc3589x_gpio_irq_chip,
+				handle_simple_irq);
+	irq_set_nested_thread(virq, 1);
 #ifdef CONFIG_ARM
-		set_irq_flags(irq, IRQF_VALID);
+	set_irq_flags(virq, IRQF_VALID);
 #else
-		irq_set_noprobe(irq);
+	irq_set_noprobe(virq);
 #endif
-	}
 
 	return 0;
 }
 
-static void tc3589x_gpio_irq_remove(struct tc3589x_gpio *tc3589x_gpio)
+static void tc3589x_gpio_irq_unmap(struct irq_domain *d, unsigned int virq)
 {
-	int base = tc3589x_gpio->irq_base;
-	int irq;
-
-	for (irq = base; irq < base + tc3589x_gpio->chip.ngpio; irq++) {
 #ifdef CONFIG_ARM
-		set_irq_flags(irq, 0);
+	set_irq_flags(virq, 0);
 #endif
-		irq_set_chip_and_handler(irq, NULL, NULL);
-		irq_set_chip_data(irq, NULL);
+	irq_set_chip_and_handler(virq, NULL, NULL);
+	irq_set_chip_data(virq, NULL);
+}
+
+static struct irq_domain_ops tc3589x_irq_ops = {
+        .map    = tc3589x_gpio_irq_map,
+        .unmap  = tc3589x_gpio_irq_unmap,
+        .xlate  = irq_domain_xlate_twocell,
+};
+
+static int tc3589x_gpio_irq_init(struct tc3589x_gpio *tc3589x_gpio)
+{
+	int base = tc3589x_gpio->irq_base;
+
+	if (base) {
+		tc3589x_gpio->domain = irq_domain_add_legacy(
+			NULL, tc3589x_gpio->chip.ngpio, base,
+			0, &tc3589x_irq_ops, tc3589x_gpio);
 	}
+	else {
+		tc3589x_gpio->domain = irq_domain_add_linear(
+			NULL, tc3589x_gpio->chip.ngpio,
+			&tc3589x_irq_ops, tc3589x_gpio);
+	}
+
+	if (!tc3589x_gpio->domain) {
+		dev_err(tc3589x_gpio->dev, "Failed to create irqdomain\n");
+		return -ENOSYS;
+	}
+
+	return 0;
 }
 
 static int __devinit tc3589x_gpio_probe(struct platform_device *pdev)
@@ -299,6 +341,9 @@ static int __devinit tc3589x_gpio_probe(struct platform_device *pdev)
 
 	tc3589x_gpio->irq_base = tc3589x->irq_base + TC3589x_INT_GPIO(0);
 
+	tc3589x_gpio->irq_base = tc3589x->irq_base ?
+		tc3589x->irq_base + TC3589x_INT_GPIO(0) : 0;
+
 	/* Bring the GPIO module out of reset */
 	ret = tc3589x_set_bits(tc3589x, TC3589x_RSTCTRL,
 			       TC3589x_RSTCTRL_GPIRST, 0);
@@ -313,7 +358,7 @@ static int __devinit tc3589x_gpio_probe(struct platform_device *pdev)
 				   "tc3589x-gpio", tc3589x_gpio);
 	if (ret) {
 		dev_err(&pdev->dev, "unable to get irq: %d\n", ret);
-		goto out_removeirq;
+		goto out_free;
 	}
 
 	ret = gpiochip_add(&tc3589x_gpio->chip);
@@ -331,8 +376,6 @@ static int __devinit tc3589x_gpio_probe(struct platform_device *pdev)
 
 out_freeirq:
 	free_irq(irq, tc3589x_gpio);
-out_removeirq:
-	tc3589x_gpio_irq_remove(tc3589x_gpio);
 out_free:
 	kfree(tc3589x_gpio);
 	return ret;
@@ -357,7 +400,6 @@ static int __devexit tc3589x_gpio_remove(struct platform_device *pdev)
 	}
 
 	free_irq(irq, tc3589x_gpio);
-	tc3589x_gpio_irq_remove(tc3589x_gpio);
 
 	platform_set_drvdata(pdev, NULL);
 	kfree(tc3589x_gpio);
-- 
1.7.9.5


  parent reply	other threads:[~2012-09-07 11:15 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-07 11:14 [PATCH 00/19] First HREF Device Tree enablement patch-set Lee Jones
2012-09-07 11:14 ` [PATCH 01/19] ARM: ux500: Add skeleton Device Tree for the HREF reference board Lee Jones
2012-09-10  8:47   ` Linus Walleij
2012-09-14  9:37     ` Lee Jones
2012-09-14 14:01       ` Linus Walleij
2012-09-07 11:14 ` [PATCH 02/19] ARM: ux500: Add UART support to the HREF Device Tree Lee Jones
2012-09-10  8:49   ` Linus Walleij
2012-09-07 11:14 ` [PATCH 03/19] ARM: ux500: Pass SDI DMA information though AUX_DATA to MMCI Lee Jones
2012-09-10  8:50   ` Linus Walleij
2012-09-07 11:14 ` [PATCH 04/19] ARM: ux500: Add SDI (MMC) support to the HREF Device Tree Lee Jones
2012-09-07 12:29   ` Arnd Bergmann
2012-09-07 12:39     ` Lee Jones
2012-09-10  9:51   ` Linus Walleij
2012-09-07 11:14 ` [PATCH 05/19] ARM: ux500: Stop registering HREF's SDI devices from platform data Lee Jones
2012-09-07 12:30   ` Arnd Bergmann
2012-09-07 11:14 ` [PATCH 06/19] ARM: ux500: Add nodes for the MSP into the HREF Device Tree Lee Jones
2012-09-10  9:53   ` Linus Walleij
2012-09-14  9:23     ` Lee Jones
2012-09-14 14:00       ` Linus Walleij
2012-09-07 11:14 ` [PATCH 07/19] ARM: ux500: Add all encompassing sound node to " Lee Jones
2012-09-10  9:56   ` Linus Walleij
2012-09-14  9:20     ` Lee Jones
2012-09-07 11:14 ` [PATCH 08/19] ARM: ux500: Stop registering Audio devices for HREF when DT is enabled Lee Jones
2012-09-10  9:57   ` Linus Walleij
2012-09-07 11:14 ` [PATCH 09/19] ARM: ux500: Enable SSP (SPI) for HREF when booting Device Tree Lee Jones
2012-09-10 11:11   ` Linus Walleij
2012-09-14  9:18     ` Lee Jones
2012-09-17 17:03     ` Roland Stigge
2012-09-18 12:08       ` Linus Walleij
2012-09-18 12:13         ` Roland Stigge
2012-09-07 11:14 ` [PATCH 10/19] ARM: ux500: Remove redundant #gpio-cell properties from HREF and Snowball DT Lee Jones
2012-09-10 11:12   ` Linus Walleij
2012-09-14  9:10     ` Lee Jones
2012-09-14 13:58       ` Linus Walleij
2012-09-07 11:14 ` [PATCH 11/19] ARM: ux500: Add all known I2C sub-device nodes to the HREF DT Lee Jones
2012-09-10 11:34   ` Linus Walleij
2012-09-14  8:47     ` Lee Jones
2012-09-20  6:51       ` Linus Walleij
2012-09-18 15:49     ` Lee Jones
2012-09-07 11:14 ` [PATCH 12/19] i2c-nomadik: Register sub-devices when passed via Device Tree Lee Jones
2012-09-10 11:42   ` Linus Walleij
2012-09-12 10:52     ` Wolfram Sang
2012-09-14  8:27       ` Lee Jones
2012-09-14  8:41         ` Wolfram Sang
2012-09-14  9:02           ` Lee Jones
2012-09-14  9:39             ` Wolfram Sang
2012-09-14 10:15               ` Lee Jones
2012-09-14 11:32                 ` Wolfram Sang
2012-09-19 20:12                   ` Lee Jones
2012-10-06 11:25                     ` Wolfram Sang
2012-09-14  8:22     ` Lee Jones
2012-09-07 11:14 ` [PATCH 13/19] ARM: ux500: Stop registering I2C sub-devices for HREF when DT is enabled Lee Jones
2012-09-10 12:56   ` Linus Walleij
2012-09-07 11:14 ` [PATCH 14/19] ARM: ux500: Apply tc3589x's GPIO/IRQ properties to HREF's DT Lee Jones
2012-09-10 12:58   ` Linus Walleij
2012-09-14  8:33     ` Lee Jones
2012-09-07 11:14 ` [PATCH 15/19] mfd: Don't convert just one IRQ using irqdomain if a range is provided Lee Jones
2012-09-07 12:35   ` Arnd Bergmann
2012-09-07 12:46     ` Lee Jones
2012-09-07 13:37       ` Arnd Bergmann
2012-09-07 13:43         ` Lee Jones
2012-09-07 13:57           ` Arnd Bergmann
2012-09-17 13:45             ` Samuel Ortiz
2012-09-17 14:11               ` Lee Jones
2012-09-21 22:20                 ` Samuel Ortiz
2012-09-07 11:14 ` [PATCH 16/19] mfd: Provide the tc3589x with its own IRQ domain Lee Jones
2012-09-10 13:05   ` Linus Walleij
2012-09-16 23:45   ` Samuel Ortiz
2012-09-07 11:14 ` [PATCH 17/19] mfd: Enable the tc3589x for Device Tree Lee Jones
2012-09-10 13:08   ` Linus Walleij
2012-09-16 23:45   ` Samuel Ortiz
2012-09-07 11:14 ` Lee Jones [this message]
2012-09-10 13:10   ` [PATCH 18/19] gpio: Provide the tc3589x GPIO expander driver with an IRQ domain Linus Walleij
2012-09-12 13:04     ` Linus Walleij
2012-09-14  8:14     ` Lee Jones
2012-09-12 21:21   ` Linus Walleij
2012-09-07 11:14 ` [PATCH 19/19] gpio: Enable the tc3298x GPIO expander driver for Device Tree Lee Jones
2012-09-10 13:20   ` Linus Walleij
2012-09-12 21:21   ` Linus Walleij
2012-09-07 12:41 ` [PATCH 00/19] First HREF Device Tree enablement patch-set Arnd Bergmann
2012-09-07 13:01   ` Lee Jones
2012-09-07 13:58     ` Arnd Bergmann
2012-09-07 14:22       ` Lee Jones
2012-09-10  8:41       ` Linus Walleij
2012-09-10 10:13         ` Arnd Bergmann
2012-09-10 11:29           ` Linus Walleij
2012-09-10 13:49             ` Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1347016499-29354-19-git-send-email-lee.jones@linaro.org \
    --to=lee.jones@linaro.org \
    --cc=STEricsson_nomadik_linux@list.st.com \
    --cc=arnd@arndb.de \
    --cc=grant.likely@secretlab.ca \
    --cc=linus.walleij@stericsson.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).