Skip to contentSkip to conversation

gpio: pl061: add DT binding support

PATCH New Rob Herring 3 participants 12 messages Aug 3, 2011 – Oct 24, 2011 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: pl061: add DT binding support

From: Rob Herring <[email protected]>

This adds devicetree binding support to the ARM pl061 driver removing the platform_data dependency. When DT binding is used, the gpio numbering is assigned dynamically. The interrupt assignment is converted to use the irq_domain infrastructure.

---
 drivers/gpio/gpio-pl061.c |   32 +++++++++++++++++++++++---------
 1 files changed, 23 insertions(+), 9 deletions(-)
drivers/gpio/gpio-pl061.c +23 -9
index 2c5a18f..7ea74ff 100644
@@ -23,6 +23,7 @@
 #include <linux/amba/bus.h>
 #include <linux/amba/pl061.h>
 #include <linux/slab.h>
+#include <linux/of_irq.h>
 
 #define GPIODIR 0x400
 #define GPIOIS  0x404
@@ -246,6 +247,20 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 	if (chip == NULL)
 		return -ENOMEM;
 
+	pdata = dev->dev.platform_data;
+	if (pdata) {
+		chip->gc.base = pdata->gpio_base;
+		chip->irq_base = pdata->irq_base;
+	} else if (dev->dev.of_node) {
+		u32 intspec = 0;
+		chip->gc.base = -1;
+		chip->irq_base = irq_create_of_mapping(dev->dev.of_node,
+						       &intspec, 1);
+	} else {
+		ret = -ENODEV;
+		goto free_mem;
+	}
+
 	if (!request_mem_region(dev->res.start,
 				resource_size(&dev->res), "pl061")) {
 		ret = -EBUSY;
@@ -267,14 +282,11 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 	chip->gc.get = pl061_get_value;
 	chip->gc.set = pl061_set_value;
 	chip->gc.to_irq = pl061_to_irq;
-	chip->gc.base = pdata->gpio_base;
 	chip->gc.ngpio = PL061_GPIO_NR;
 	chip->gc.label = dev_name(&dev->dev);
 	chip->gc.dev = &dev->dev;
 	chip->gc.owner = THIS_MODULE;
 
-	chip->irq_base = pdata->irq_base;
-
 	ret = gpiochip_add(&chip->gc);
 	if (ret)
 		goto iounmap;
@@ -283,7 +295,7 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 	 * irq_chip support
 	 */
 
-	if (chip->irq_base == (unsigned) -1)
+	if (chip->irq_base == NO_IRQ)
 		return 0;
 
 	writeb(0, chip->base + GPIOIE); /* disable irqs */
@@ -307,11 +319,13 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 	list_add(&chip->list, chip_list);
 
 	for (i = 0; i < PL061_GPIO_NR; i++) {
-		if (pdata->directions & (1 << i))
-			pl061_direction_output(&chip->gc, i,
-					pdata->values & (1 << i));
-		else
-			pl061_direction_input(&chip->gc, i);
+		if (pdata) {
+			if (pdata->directions & (1 << i))
+				pl061_direction_output(&chip->gc, i,
+						pdata->values & (1 << i));
+			else
+				pl061_direction_input(&chip->gc, i);
+		}
 
 		irq_set_chip_and_handler(i + chip->irq_base, &pl061_irqchip,
 					 handle_simple_irq);
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH 1/1 gpio: pl061: add DT binding support

Hi Rob,

Quoted 13 lines · Rob Herring

From: Rob Herring <[email protected]>

This adds devicetree binding support to the ARM pl061 driver removing the platform_data dependency. When DT binding is used, the gpio numbering is assigned dynamically. The interrupt assignment is converted to use the irq_domain infrastructure.

---
 drivers/gpio/gpio-pl061.c |   32 +++++++++++++++++++++++---------
 1 files changed, 23 insertions(+), 9 deletions(-)

[snip]

drivers/gpio/gpio-pl061.c static int pl061_probe(struct amba_device *dev, const · line 299

Quoted 7 lines
drivers/gpio/gpio-pl061.c +1 -1
@@ -283,7 +295,7 @@ static int pl061_probe(struct amba_device *dev, const 
 struct amba_id *id)
 	 * irq_chip support
 	 */
 
-	if (chip->irq_base == (unsigned) -1)
+	if (chip->irq_base == NO_IRQ)

Please update the comment at include/linux/amba/pl061.h as well.

drivers/gpio/gpio-pl061.c static int pl061_probe(struct amba_device *dev, const struct amba_id *id)

Quoted 4 lines
drivers/gpio/gpio-pl061.c +0 -0
 		return 0;
 
drivers/gpio/gpio-pl061.c +0 -0
 	writeb(0, chip->base + GPIOIE); /* disable irqs */
@@ -307,11 +319,13 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)

[snip]

baruch

Signature · 3 lines
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
#2 lore raw

PATCH 1/1 gpio: pl061: add DT binding support

In reply to Rob Herring
Quoted 28 lines · Rob Herring

From: Rob Herring <[email protected]>

This adds devicetree binding support to the ARM pl061 driver removing the platform_data dependency. When DT binding is used, the gpio numbering is assigned dynamically. The interrupt assignment is converted to use the irq_domain infrastructure.

---
?drivers/gpio/gpio-pl061.c | ? 32 +++++++++++++++++++++++--------- ?1 files changed, 23 insertions(+), 9 deletions(-)

drivers/gpio/gpio-pl061.c +0 -0
index 2c5a18f..7ea74ff 100644
@@ -23,6 +23,7 @@

?#include <linux/amba/bus.h>
?#include <linux/amba/pl061.h>
?#include <linux/slab.h>
+#include <linux/of_irq.h>

?#define GPIODIR 0x400
?#define GPIOIS ?0x404

drivers/gpio/gpio-pl061.c +0 -0
@@ -246,6 +247,20 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 ? ? ? ?if (chip == NULL)
 ? ? ? ? ? ? ? ?return -ENOMEM;

drivers/gpio/gpio-pl061.c static int pl061_probe(struct amba_device *dev, const struct amba_id *id) · line 258

Quoted 10 lines
drivers/gpio/gpio-pl061.c +9 -0
 
+ ? ? ? pdata = dev->dev.platform_data;
+ ? ? ? if (pdata) {
+ ? ? ? ? ? ? ? chip->gc.base = pdata->gpio_base;
+ ? ? ? ? ? ? ? chip->irq_base = pdata->irq_base;
+ ? ? ? } else if (dev->dev.of_node) {
+ ? ? ? ? ? ? ? u32 intspec = 0;
+ ? ? ? ? ? ? ? chip->gc.base = -1;
+ ? ? ? ? ? ? ? chip->irq_base = irq_create_of_mapping(dev->dev.of_node,
+ ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?&intspec, 1);

This looks wrong. intspec is always 0 here, when I would assume you would want the value of the interrupts property from this device's node. Is this the cascade irq number? Or is it supposed to be the starting interrupt number for the gpios? If it is starting interrupt number, then it should actually be dynamically assigned. If it is the cascade, then platform_get_irq() should work.

g.

#3 lore raw

PATCH 1/1 gpio: pl061: add DT binding support

Grant,

Quoted 30 lines · Grant Likely
Quoted 29 lines · Rob Herring

From: Rob Herring <[email protected]>

This adds devicetree binding support to the ARM pl061 driver removing the platform_data dependency. When DT binding is used, the gpio numbering is assigned dynamically. The interrupt assignment is converted to use the irq_domain infrastructure.

---
 drivers/gpio/gpio-pl061.c |   32 +++++++++++++++++++++++---------
 1 files changed, 23 insertions(+), 9 deletions(-)
drivers/gpio/gpio-pl061.c +1 -0
index 2c5a18f..7ea74ff 100644
@@ -23,6 +23,7 @@
 #include <linux/amba/bus.h>
 #include <linux/amba/pl061.h>
 #include <linux/slab.h>
+#include <linux/of_irq.h>
 
 #define GPIODIR 0x400
 #define GPIOIS  0x404
@@ -246,6 +247,20 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
       if (chip == NULL)
               return -ENOMEM;
 
Quoted 17 lines

drivers/gpio/gpio-pl061.c static int pl061_probe(struct amba_device *dev, const struct amba_id *id) · line 258

Quoted 9 lines
drivers/gpio/gpio-pl061.c +9 -0
+       pdata = dev->dev.platform_data;
+       if (pdata) {
+               chip->gc.base = pdata->gpio_base;
+               chip->irq_base = pdata->irq_base;
+       } else if (dev->dev.of_node) {
+               u32 intspec = 0;
+               chip->gc.base = -1;
+               chip->irq_base = irq_create_of_mapping(dev->dev.of_node,
+                                                      &intspec, 1);

This looks wrong. intspec is always 0 here, when I would assume you would want the value of the interrupts property from this device's node. Is this the cascade irq number? Or is it supposed to be the starting interrupt number for the gpios? If it is starting interrupt number, then it should actually be dynamically assigned. If it is the cascade, then platform_get_irq() should work.

It's the latter case that I need to retrieve. I have this platform code assigning the linux irq numbers:

        struct device_node *node;
        int n = 0;

        node = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-gic");
        if (!node)
                panic("missing gic devicetree node\n");
        irq_domain_add_simple(node, 0);

        for_each_compatible_node(node, NULL, "arm,pl061") {
                irq_domain_add_simple(node, 160 + (8 * n));
                n++;
        }

In this case with simple translation, intspec is really a don't care. irq_create_of_mapping just finds the domain that matches the gpio ctrlr's node and returns the domain's irq_base (+ 0) as the translate function will just return the intspec value for the hw_irq.

Have I missed something? There is not yet any dynamic assignment of linux irq numbers?

Rob

#4 lore raw

PATCH 1/1 gpio: pl061: add DT binding support

Quoted 66 lines · Rob Herring

Grant,

Quoted 30 lines · Grant Likely
Quoted 29 lines · Rob Herring

From: Rob Herring <[email protected]>

This adds devicetree binding support to the ARM pl061 driver removing the platform_data dependency. When DT binding is used, the gpio numbering is assigned dynamically. The interrupt assignment is converted to use the irq_domain infrastructure.

---
 drivers/gpio/gpio-pl061.c |   32 +++++++++++++++++++++++---------
 1 files changed, 23 insertions(+), 9 deletions(-)
drivers/gpio/gpio-pl061.c +1 -0
index 2c5a18f..7ea74ff 100644
@@ -23,6 +23,7 @@
 #include <linux/amba/bus.h>
 #include <linux/amba/pl061.h>
 #include <linux/slab.h>
+#include <linux/of_irq.h>
 
 #define GPIODIR 0x400
 #define GPIOIS  0x404
@@ -246,6 +247,20 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
       if (chip == NULL)
               return -ENOMEM;
 
Quoted 17 lines

drivers/gpio/gpio-pl061.c static int pl061_probe(struct amba_device *dev, const struct amba_id *id) · line 258

Quoted 9 lines
drivers/gpio/gpio-pl061.c +9 -0
+       pdata = dev->dev.platform_data;
+       if (pdata) {
+               chip->gc.base = pdata->gpio_base;
+               chip->irq_base = pdata->irq_base;
+       } else if (dev->dev.of_node) {
+               u32 intspec = 0;
+               chip->gc.base = -1;
+               chip->irq_base = irq_create_of_mapping(dev->dev.of_node,
+                                                      &intspec, 1);

This looks wrong. intspec is always 0 here, when I would assume you would want the value of the interrupts property from this device's node. Is this the cascade irq number? Or is it supposed to be the starting interrupt number for the gpios? If it is starting interrupt number, then it should actually be dynamically assigned. If it is the cascade, then platform_get_irq() should work.

It's the latter case that I need to retrieve. I have this platform code assigning the linux irq numbers:

        struct device_node *node;
        int n = 0;

        node = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-gic");
        if (!node)
                panic("missing gic devicetree node\n");
        irq_domain_add_simple(node, 0);

        for_each_compatible_node(node, NULL, "arm,pl061") {
                irq_domain_add_simple(node, 160 + (8 * n));
                n++;
        }
Quoted 7 lines

In this case with simple translation, intspec is really a don't care. irq_create_of_mapping just finds the domain that matches the gpio ctrlr's node and returns the domain's irq_base (+ 0) as the translate function will just return the intspec value for the hw_irq.

Have I missed something? There is not yet any dynamic assignment of linux irq numbers?

Yes, the kernel does support dynamic irq number assignment, but the interrupt controller still needs to manage it. I've not yet decided what the best way to integrate it into irq_domain is.

g.

#5 lore raw

PATCH 1/1 gpio: pl061: add DT binding support

Quoted 72 lines · Grant Likely
Quoted 71 lines · Rob Herring

Grant,

Quoted 30 lines · Grant Likely
Quoted 29 lines · Rob Herring

From: Rob Herring <[email protected]>

This adds devicetree binding support to the ARM pl061 driver removing the platform_data dependency. When DT binding is used, the gpio numbering is assigned dynamically. The interrupt assignment is converted to use the irq_domain infrastructure.

---
 drivers/gpio/gpio-pl061.c |   32 +++++++++++++++++++++++---------
 1 files changed, 23 insertions(+), 9 deletions(-)
drivers/gpio/gpio-pl061.c +1 -0
index 2c5a18f..7ea74ff 100644
@@ -23,6 +23,7 @@
 #include <linux/amba/bus.h>
 #include <linux/amba/pl061.h>
 #include <linux/slab.h>
+#include <linux/of_irq.h>
 
 #define GPIODIR 0x400
 #define GPIOIS  0x404
@@ -246,6 +247,20 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
       if (chip == NULL)
               return -ENOMEM;
 
Quoted 17 lines

drivers/gpio/gpio-pl061.c static int pl061_probe(struct amba_device *dev, const struct amba_id *id) · line 258

Quoted 9 lines
drivers/gpio/gpio-pl061.c +9 -0
+       pdata = dev->dev.platform_data;
+       if (pdata) {
+               chip->gc.base = pdata->gpio_base;
+               chip->irq_base = pdata->irq_base;
+       } else if (dev->dev.of_node) {
+               u32 intspec = 0;
+               chip->gc.base = -1;
+               chip->irq_base = irq_create_of_mapping(dev->dev.of_node,
+                                                      &intspec, 1);

This looks wrong. intspec is always 0 here, when I would assume you would want the value of the interrupts property from this device's node. Is this the cascade irq number? Or is it supposed to be the starting interrupt number for the gpios? If it is starting interrupt number, then it should actually be dynamically assigned. If it is the cascade, then platform_get_irq() should work.

It's the latter case that I need to retrieve. I have this platform code assigning the linux irq numbers:

        struct device_node *node;
        int n = 0;

        node = of_find_compatible_node(NULL, NULL, "arm,cortex-a9-gic");
        if (!node)
                panic("missing gic devicetree node\n");
        irq_domain_add_simple(node, 0);

        for_each_compatible_node(node, NULL, "arm,pl061") {
                irq_domain_add_simple(node, 160 + (8 * n));
                n++;
        }

In this case with simple translation, intspec is really a don't care. irq_create_of_mapping just finds the domain that matches the gpio ctrlr's node and returns the domain's irq_base (+ 0) as the translate function will just return the intspec value for the hw_irq.

Quoted 7 lines
Quoted 2 lines

Have I missed something? There is not yet any dynamic assignment of linux irq numbers?

Yes, the kernel does support dynamic irq number assignment, but the interrupt controller still needs to manage it. I've not yet decided what the best way to integrate it into irq_domain is.

I had since figured that out with the GIC series. We should discuss at Connect. My plan here is to make generic-irq-chip use domains and irq_alloc_descs, then convert pl061 to use generic-irq-chip.

Rob

#6 lore raw

PATCH v2 1/1 gpio: pl061: add DT binding support

In reply to Rob Herring

From: Rob Herring <[email protected]>

This adds devicetree binding support to the ARM pl061 driver removing the platform_data dependency. When DT binding is used, the gpio numbering is assigned dynamically. For now, interrupts are not supported with DT until irqdomains learn dynamic irq assignment.

Rather than add another case of -1, updating the driver to use NO_IRQ.

---

v2:
- Add other -1 to NO_IRQ conversions
- Drop DT irq support for now

 drivers/gpio/gpio-pl061.c  |   31 +++++++++++++++++++++----------
 include/linux/amba/pl061.h |    3 +--
 2 files changed, 22 insertions(+), 12 deletions(-)
drivers/gpio/gpio-pl061.c +21 -10
index 2c5a18f..093c90b 100644
@@ -118,7 +118,7 @@ static int pl061_to_irq(struct gpio_chip *gc, unsigned offset)
 {
 	struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
 
-	if (chip->irq_base == (unsigned) -1)
+	if (chip->irq_base == NO_IRQ)
 		return -EINVAL;
 
 	return chip->irq_base + offset;
@@ -246,6 +246,18 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 	if (chip == NULL)
 		return -ENOMEM;
 
+	pdata = dev->dev.platform_data;
+	if (pdata) {
+		chip->gc.base = pdata->gpio_base;
+		chip->irq_base = pdata->irq_base;
+	} else if (dev->dev.of_node) {
+		chip->gc.base = -1;
+		chip->irq_base = NO_IRQ;
+	} else {
+		ret = -ENODEV;
+		goto free_mem;
+	}
+
 	if (!request_mem_region(dev->res.start,
 				resource_size(&dev->res), "pl061")) {
 		ret = -EBUSY;
@@ -267,14 +279,11 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 	chip->gc.get = pl061_get_value;
 	chip->gc.set = pl061_set_value;
 	chip->gc.to_irq = pl061_to_irq;
-	chip->gc.base = pdata->gpio_base;
 	chip->gc.ngpio = PL061_GPIO_NR;
 	chip->gc.label = dev_name(&dev->dev);
 	chip->gc.dev = &dev->dev;
 	chip->gc.owner = THIS_MODULE;
 
-	chip->irq_base = pdata->irq_base;
-
 	ret = gpiochip_add(&chip->gc);
 	if (ret)
 		goto iounmap;
@@ -283,7 +292,7 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 	 * irq_chip support
 	 */
 
-	if (chip->irq_base == (unsigned) -1)
+	if (chip->irq_base == NO_IRQ)
 		return 0;
 
 	writeb(0, chip->base + GPIOIE); /* disable irqs */
@@ -307,11 +316,13 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 	list_add(&chip->list, chip_list);
 
 	for (i = 0; i < PL061_GPIO_NR; i++) {
-		if (pdata->directions & (1 << i))
-			pl061_direction_output(&chip->gc, i,
-					pdata->values & (1 << i));
-		else
-			pl061_direction_input(&chip->gc, i);
+		if (pdata) {
+			if (pdata->directions & (1 << i))
+				pl061_direction_output(&chip->gc, i,
+						pdata->values & (1 << i));
+			else
+				pl061_direction_input(&chip->gc, i);
+		}
 
 		irq_set_chip_and_handler(i + chip->irq_base, &pl061_irqchip,
 					 handle_simple_irq);
include/linux/amba/pl061.h +1 -2
index 5ddd9ad..2412af9 100644
@@ -7,8 +7,7 @@ struct pl061_platform_data {
 	unsigned	gpio_base;
 
 	/* number of the first IRQ.
-	 * If the IRQ functionality in not desired this must be set to
-	 * (unsigned) -1.
+	 * If the IRQ functionality in not desired this must be set to NO_IRQ.
 	 */
 	unsigned	irq_base;
 
Signature · 1 line
1.7.4.1
#7 lore raw

PATCH v2 1/1 gpio: pl061: add DT binding support

Hi Rob,

Quoted 7 lines · Rob Herring

From: Rob Herring <[email protected]>

This adds devicetree binding support to the ARM pl061 driver removing the platform_data dependency. When DT binding is used, the gpio numbering is assigned dynamically. For now, interrupts are not supported with DT until irqdomains learn dynamic irq assignment.

Quoted 8 lines

Rather than add another case of -1, updating the driver to use NO_IRQ.

---

v2:
- Add other -1 to NO_IRQ conversions

Migrating existing pl061_platform_data users to NO_IRQ would be nice as well. But this should probably be a separate patch.

FWIW:

baruch

Signature · 3 lines
                                                     ~. .~   Tk Open Systems
=}------------------------------------------------ooO--U--Ooo------------{=
   - baruch at tkos.co.il - tel: +972.2.679.5364, http://www.tkos.co.il -
#8 lore raw

PATCH v2 1/1 gpio: pl061: add DT binding support

Quoted 16 lines · Baruch Siach

Hi Rob,

Quoted 13 lines · Rob Herring

From: Rob Herring <[email protected]>

This adds devicetree binding support to the ARM pl061 driver removing the platform_data dependency. When DT binding is used, the gpio numbering is assigned dynamically. For now, interrupts are not supported with DT until irqdomains learn dynamic irq assignment.

Rather than add another case of -1, updating the driver to use NO_IRQ.

---

Quoted 6 lines
Quoted 2 lines

v2:
- Add other -1 to NO_IRQ conversions

Migrating existing pl061_platform_data users to NO_IRQ would be nice as well. But this should probably be a separate patch.

Actually, I expect we can kill off the platform_data once all users are converted over to device tree.

Quoted 3 lines

FWIW:

Thanks.

Rob

#9 lore raw

PATCH v2 1/1 gpio: pl061: add DT binding support

In reply to Rob Herring

Grant,

Quoted 7 lines · Rob Herring

From: Rob Herring <[email protected]>

This adds devicetree binding support to the ARM pl061 driver removing the platform_data dependency. When DT binding is used, the gpio numbering is assigned dynamically. For now, interrupts are not supported with DT until irqdomains learn dynamic irq assignment.

Quoted 5 lines

Rather than add another case of -1, updating the driver to use NO_IRQ.

---

Ping. Any comments on this?

Rob

Quoted 98 lines

v2:
- Add other -1 to NO_IRQ conversions
- Drop DT irq support for now

 drivers/gpio/gpio-pl061.c  |   31 +++++++++++++++++++++----------
 include/linux/amba/pl061.h |    3 +--
 2 files changed, 22 insertions(+), 12 deletions(-)
drivers/gpio/gpio-pl061.c +21 -10
index 2c5a18f..093c90b 100644
@@ -118,7 +118,7 @@ static int pl061_to_irq(struct gpio_chip *gc, unsigned offset)
 {
 	struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
 
-	if (chip->irq_base == (unsigned) -1)
+	if (chip->irq_base == NO_IRQ)
 		return -EINVAL;
 
 	return chip->irq_base + offset;
@@ -246,6 +246,18 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 	if (chip == NULL)
 		return -ENOMEM;
 
+	pdata = dev->dev.platform_data;
+	if (pdata) {
+		chip->gc.base = pdata->gpio_base;
+		chip->irq_base = pdata->irq_base;
+	} else if (dev->dev.of_node) {
+		chip->gc.base = -1;
+		chip->irq_base = NO_IRQ;
+	} else {
+		ret = -ENODEV;
+		goto free_mem;
+	}
+
 	if (!request_mem_region(dev->res.start,
 				resource_size(&dev->res), "pl061")) {
 		ret = -EBUSY;
@@ -267,14 +279,11 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 	chip->gc.get = pl061_get_value;
 	chip->gc.set = pl061_set_value;
 	chip->gc.to_irq = pl061_to_irq;
-	chip->gc.base = pdata->gpio_base;
 	chip->gc.ngpio = PL061_GPIO_NR;
 	chip->gc.label = dev_name(&dev->dev);
 	chip->gc.dev = &dev->dev;
 	chip->gc.owner = THIS_MODULE;
 
-	chip->irq_base = pdata->irq_base;
-
 	ret = gpiochip_add(&chip->gc);
 	if (ret)
 		goto iounmap;
@@ -283,7 +292,7 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 	 * irq_chip support
 	 */
 
-	if (chip->irq_base == (unsigned) -1)
+	if (chip->irq_base == NO_IRQ)
 		return 0;
 
 	writeb(0, chip->base + GPIOIE); /* disable irqs */
@@ -307,11 +316,13 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 	list_add(&chip->list, chip_list);
 
 	for (i = 0; i < PL061_GPIO_NR; i++) {
-		if (pdata->directions & (1 << i))
-			pl061_direction_output(&chip->gc, i,
-					pdata->values & (1 << i));
-		else
-			pl061_direction_input(&chip->gc, i);
+		if (pdata) {
+			if (pdata->directions & (1 << i))
+				pl061_direction_output(&chip->gc, i,
+						pdata->values & (1 << i));
+			else
+				pl061_direction_input(&chip->gc, i);
+		}
 
 		irq_set_chip_and_handler(i + chip->irq_base, &pl061_irqchip,
 					 handle_simple_irq);
include/linux/amba/pl061.h +1 -2
index 5ddd9ad..2412af9 100644
@@ -7,8 +7,7 @@ struct pl061_platform_data {
 	unsigned	gpio_base;
 
 	/* number of the first IRQ.
-	 * If the IRQ functionality in not desired this must be set to
-	 * (unsigned) -1.
+	 * If the IRQ functionality in not desired this must be set to NO_IRQ.
 	 */
 	unsigned	irq_base;
 
#10 lore raw

PATCH v2 1/1 gpio: pl061: add DT binding support

Grant,

Quoted 10 lines · Rob Herring

Grant,

Quoted 7 lines · Rob Herring

From: Rob Herring <[email protected]>

This adds devicetree binding support to the ARM pl061 driver removing the platform_data dependency. When DT binding is used, the gpio numbering is assigned dynamically. For now, interrupts are not supported with DT until irqdomains learn dynamic irq assignment.

Quoted 8 lines
Quoted 5 lines

Rather than add another case of -1, updating the driver to use NO_IRQ.

---

Ping. Any comments on this?

Ping. Can you apply this for 3.2.

Rob

Quoted 100 lines

Rob

Quoted 98 lines

v2:
- Add other -1 to NO_IRQ conversions
- Drop DT irq support for now

 drivers/gpio/gpio-pl061.c  |   31 +++++++++++++++++++++----------
 include/linux/amba/pl061.h |    3 +--
 2 files changed, 22 insertions(+), 12 deletions(-)
drivers/gpio/gpio-pl061.c +21 -10
index 2c5a18f..093c90b 100644
@@ -118,7 +118,7 @@ static int pl061_to_irq(struct gpio_chip *gc, unsigned offset)
 {
 	struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
 
-	if (chip->irq_base == (unsigned) -1)
+	if (chip->irq_base == NO_IRQ)
 		return -EINVAL;
 
 	return chip->irq_base + offset;
@@ -246,6 +246,18 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 	if (chip == NULL)
 		return -ENOMEM;
 
+	pdata = dev->dev.platform_data;
+	if (pdata) {
+		chip->gc.base = pdata->gpio_base;
+		chip->irq_base = pdata->irq_base;
+	} else if (dev->dev.of_node) {
+		chip->gc.base = -1;
+		chip->irq_base = NO_IRQ;
+	} else {
+		ret = -ENODEV;
+		goto free_mem;
+	}
+
 	if (!request_mem_region(dev->res.start,
 				resource_size(&dev->res), "pl061")) {
 		ret = -EBUSY;
@@ -267,14 +279,11 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 	chip->gc.get = pl061_get_value;
 	chip->gc.set = pl061_set_value;
 	chip->gc.to_irq = pl061_to_irq;
-	chip->gc.base = pdata->gpio_base;
 	chip->gc.ngpio = PL061_GPIO_NR;
 	chip->gc.label = dev_name(&dev->dev);
 	chip->gc.dev = &dev->dev;
 	chip->gc.owner = THIS_MODULE;
 
-	chip->irq_base = pdata->irq_base;
-
 	ret = gpiochip_add(&chip->gc);
 	if (ret)
 		goto iounmap;
@@ -283,7 +292,7 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 	 * irq_chip support
 	 */
 
-	if (chip->irq_base == (unsigned) -1)
+	if (chip->irq_base == NO_IRQ)
 		return 0;
 
 	writeb(0, chip->base + GPIOIE); /* disable irqs */
@@ -307,11 +316,13 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 	list_add(&chip->list, chip_list);
 
 	for (i = 0; i < PL061_GPIO_NR; i++) {
-		if (pdata->directions & (1 << i))
-			pl061_direction_output(&chip->gc, i,
-					pdata->values & (1 << i));
-		else
-			pl061_direction_input(&chip->gc, i);
+		if (pdata) {
+			if (pdata->directions & (1 << i))
+				pl061_direction_output(&chip->gc, i,
+						pdata->values & (1 << i));
+			else
+				pl061_direction_input(&chip->gc, i);
+		}
 
 		irq_set_chip_and_handler(i + chip->irq_base, &pl061_irqchip,
 					 handle_simple_irq);
include/linux/amba/pl061.h +1 -2
index 5ddd9ad..2412af9 100644
@@ -7,8 +7,7 @@ struct pl061_platform_data {
 	unsigned	gpio_base;
 
 	/* number of the first IRQ.
-	 * If the IRQ functionality in not desired this must be set to
-	 * (unsigned) -1.
+	 * If the IRQ functionality in not desired this must be set to NO_IRQ.
 	 */
 	unsigned	irq_base;
 
Applied
#11 lore raw

PATCH v2 1/1 gpio: pl061: add DT binding support

In reply to Rob Herring
Quoted 11 lines · Rob Herring

From: Rob Herring <[email protected]>

This adds devicetree binding support to the ARM pl061 driver removing the platform_data dependency. When DT binding is used, the gpio numbering is assigned dynamically. For now, interrupts are not supported with DT until irqdomains learn dynamic irq assignment.

Rather than add another case of -1, updating the driver to use NO_IRQ.

Applied, thanks.

g.

Quoted 102 lines

---

v2:
- Add other -1 to NO_IRQ conversions
- Drop DT irq support for now

 drivers/gpio/gpio-pl061.c  |   31 +++++++++++++++++++++----------
 include/linux/amba/pl061.h |    3 +--
 2 files changed, 22 insertions(+), 12 deletions(-)
drivers/gpio/gpio-pl061.c +21 -10
index 2c5a18f..093c90b 100644
@@ -118,7 +118,7 @@ static int pl061_to_irq(struct gpio_chip *gc, unsigned offset)
 {
 	struct pl061_gpio *chip = container_of(gc, struct pl061_gpio, gc);
 
-	if (chip->irq_base == (unsigned) -1)
+	if (chip->irq_base == NO_IRQ)
 		return -EINVAL;
 
 	return chip->irq_base + offset;
@@ -246,6 +246,18 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 	if (chip == NULL)
 		return -ENOMEM;
 
+	pdata = dev->dev.platform_data;
+	if (pdata) {
+		chip->gc.base = pdata->gpio_base;
+		chip->irq_base = pdata->irq_base;
+	} else if (dev->dev.of_node) {
+		chip->gc.base = -1;
+		chip->irq_base = NO_IRQ;
+	} else {
+		ret = -ENODEV;
+		goto free_mem;
+	}
+
 	if (!request_mem_region(dev->res.start,
 				resource_size(&dev->res), "pl061")) {
 		ret = -EBUSY;
@@ -267,14 +279,11 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 	chip->gc.get = pl061_get_value;
 	chip->gc.set = pl061_set_value;
 	chip->gc.to_irq = pl061_to_irq;
-	chip->gc.base = pdata->gpio_base;
 	chip->gc.ngpio = PL061_GPIO_NR;
 	chip->gc.label = dev_name(&dev->dev);
 	chip->gc.dev = &dev->dev;
 	chip->gc.owner = THIS_MODULE;
 
-	chip->irq_base = pdata->irq_base;
-
 	ret = gpiochip_add(&chip->gc);
 	if (ret)
 		goto iounmap;
@@ -283,7 +292,7 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 	 * irq_chip support
 	 */
 
-	if (chip->irq_base == (unsigned) -1)
+	if (chip->irq_base == NO_IRQ)
 		return 0;
 
 	writeb(0, chip->base + GPIOIE); /* disable irqs */
@@ -307,11 +316,13 @@ static int pl061_probe(struct amba_device *dev, const struct amba_id *id)
 	list_add(&chip->list, chip_list);
 
 	for (i = 0; i < PL061_GPIO_NR; i++) {
-		if (pdata->directions & (1 << i))
-			pl061_direction_output(&chip->gc, i,
-					pdata->values & (1 << i));
-		else
-			pl061_direction_input(&chip->gc, i);
+		if (pdata) {
+			if (pdata->directions & (1 << i))
+				pl061_direction_output(&chip->gc, i,
+						pdata->values & (1 << i));
+			else
+				pl061_direction_input(&chip->gc, i);
+		}
 
 		irq_set_chip_and_handler(i + chip->irq_base, &pl061_irqchip,
 					 handle_simple_irq);
include/linux/amba/pl061.h +1 -2
index 5ddd9ad..2412af9 100644
@@ -7,8 +7,7 @@ struct pl061_platform_data {
 	unsigned	gpio_base;
 
 	/* number of the first IRQ.
-	 * If the IRQ functionality in not desired this must be set to
-	 * (unsigned) -1.
+	 * If the IRQ functionality in not desired this must be set to NO_IRQ.
 	 */
 	unsigned	irq_base;
 
Signature · 1 line
1.7.4.1