Skip to contentSkip to conversation

gpio: daVinci: cleanup and feature enhancement

PATCH Superseded Prabhakar Lad 5 participants 23 messages Nov 8, 2013 – Nov 19, 2013

Subsystems (6)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover gpio: daVinci: cleanup and feature enhancement

From: KV Sujith <[email protected]>

This patch series does the following 1> Ports the driver to use irqdomain. 2> Adds dt binding support for gpio-davinci. 3> Adds DA850 dt support goio.

Changes for v5:
1: Fixed review comments pointed by Grygorii. 2: Dropped the fixup patch

This patch series is based on following fixup series
http://us.generation-nt.com/answer/patch-0-2-davinci-gpio-fixes-help-212978272.html

KV Sujith (3):
gpio: davinci: add OF support
ARM: davinci: da850: add GPIO DT node
ARM: davinci: da850 evm: add GPIO pinumux entries DT node

Lad, Prabhakar (4):
gpio: davinci: remove unnecessary printk
gpio: davinci: use readl/writel instead of __raw_*
gpio: davinci: use irqdomain
gpio: davinci: remove unused variable intc_irq_num

 .../devicetree/bindings/gpio/gpio-davinci.txt      |   39 +++++
 arch/arm/boot/dts/da850-evm.dts                    |   20 +++
 arch/arm/boot/dts/da850.dtsi                       |   14 ++
 arch/arm/mach-davinci/da830.c                      |    1 -
 arch/arm/mach-davinci/da850.c                      |    1 -
 arch/arm/mach-davinci/dm355.c                      |    1 -
 arch/arm/mach-davinci/dm365.c                      |    1 -
 arch/arm/mach-davinci/dm644x.c                     |    1 -
 arch/arm/mach-davinci/dm646x.c                     |    1 -
 drivers/gpio/gpio-davinci.c                        |  170 +++++++++++++-------
 include/linux/platform_data/gpio-davinci.h         |    3 +-
 11 files changed, 185 insertions(+), 67 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-davinci.txt
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v5 1/7 gpio: davinci: remove unnecessary printk

From: "Lad, Prabhakar" <[email protected]>

the devm_*() helper prints error messages in case of errors no need to do the same in the driver.

---
 drivers/gpio/gpio-davinci.c |    6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpio/gpio-davinci.c +2 -4
index 84be701..7230c43 100644
@@ -389,11 +389,9 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
 	}
 
 	clk = devm_clk_get(dev, "gpio");
-	if (IS_ERR(clk)) {
-		printk(KERN_ERR "Error %ld getting gpio clock?\n",
-		       PTR_ERR(clk));
+	if (IS_ERR(clk))
 		return PTR_ERR(clk);
-	}
+
 	clk_prepare_enable(clk);
 
 	/*
Signature · 1 line
1.7.9.5
#2 lore raw

Re: [PATCH v5 1/7] gpio: davinci: remove unnecessary printk

Quoted 4 lines · Prabhakar Lad

From: "Lad, Prabhakar" <[email protected]>

the devm_*() helper prints error messages in case of errors no need to do the same in the driver.

Pls, drop it - devm_clk_get() doesn't always print error messages

Quoted 25 lines
---
  drivers/gpio/gpio-davinci.c |    6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpio/gpio-davinci.c +2 -4
index 84be701..7230c43 100644
@@ -389,11 +389,9 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
  	}
 
  	clk = devm_clk_get(dev, "gpio");
-	if (IS_ERR(clk)) {
-		printk(KERN_ERR "Error %ld getting gpio clock?\n",
-		       PTR_ERR(clk));
+	if (IS_ERR(clk))
  		return PTR_ERR(clk);
-	}
+
  	clk_prepare_enable(clk);
 
  	/*
#3 lore raw

Re: [PATCH v5 1/7] gpio: davinci: remove unnecessary printk

Hi Grygorii,

Thanks for the review.

Quoted 10 lines · Grygorii Strashko
Quoted 5 lines · Prabhakar Lad

From: "Lad, Prabhakar" <[email protected]>

the devm_*() helper prints error messages in case of errors no need to do the same in the driver.

Pls, drop it - devm_clk_get() doesn't always print error messages

OK will drop in the next version.

Regards,
--Prabhakar Lad

#4 lore raw

PATCH v5 2/7 gpio: davinci: use readl/writel instead of __raw_*

In reply to Prabhakar Lad

From: "Lad, Prabhakar" <[email protected]>

This patch replaces the __raw_readl/writel with readl and writel, Although the code runs on ARMv5 based SOCs, changing this will help copying the code for other uses.

---
 drivers/gpio/gpio-davinci.c |   36 ++++++++++++++++++------------------
 1 file changed, 18 insertions(+), 18 deletions(-)
drivers/gpio/gpio-davinci.c +18 -18
index 7230c43..ca3d7fd 100644
@@ -82,14 +82,14 @@ static inline int __davinci_direction(struct gpio_chip *chip,
 	u32 mask = 1 << offset;
 
 	spin_lock_irqsave(&d->lock, flags);
-	temp = __raw_readl(&g->dir);
+	temp = readl(&g->dir);
 	if (out) {
 		temp &= ~mask;
-		__raw_writel(mask, value ? &g->set_data : &g->clr_data);
+		writel(mask, value ? &g->set_data : &g->clr_data);
 	} else {
 		temp |= mask;
 	}
-	__raw_writel(temp, &g->dir);
+	writel(temp, &g->dir);
 	spin_unlock_irqrestore(&d->lock, flags);
 
 	return 0;
@@ -118,7 +118,7 @@ static int davinci_gpio_get(struct gpio_chip *chip, unsigned offset)
 	struct davinci_gpio_controller *d = chip2controller(chip);
 	struct davinci_gpio_regs __iomem *g = d->regs;
 
-	return (1 << offset) & __raw_readl(&g->in_data);
+	return (1 << offset) & readl(&g->in_data);
 }
 
 /*
@@ -130,7 +130,7 @@ davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
 	struct davinci_gpio_controller *d = chip2controller(chip);
 	struct davinci_gpio_regs __iomem *g = d->regs;
 
-	__raw_writel((1 << offset), value ? &g->set_data : &g->clr_data);
+	writel((1 << offset), value ? &g->set_data : &g->clr_data);
 }
 
 static int davinci_gpio_probe(struct platform_device *pdev)
@@ -227,8 +227,8 @@ static void gpio_irq_disable(struct irq_data *d)
 	struct davinci_gpio_regs __iomem *g = irq2regs(d->irq);
 	u32 mask = (u32) irq_data_get_irq_handler_data(d);
 
-	__raw_writel(mask, &g->clr_falling);
-	__raw_writel(mask, &g->clr_rising);
+	writel(mask, &g->clr_falling);
+	writel(mask, &g->clr_rising);
 }
 
 static void gpio_irq_enable(struct irq_data *d)
@@ -242,9 +242,9 @@ static void gpio_irq_enable(struct irq_data *d)
 		status = IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING;
 
 	if (status & IRQ_TYPE_EDGE_FALLING)
-		__raw_writel(mask, &g->set_falling);
+		writel(mask, &g->set_falling);
 	if (status & IRQ_TYPE_EDGE_RISING)
-		__raw_writel(mask, &g->set_rising);
+		writel(mask, &g->set_rising);
 }
 
 static int gpio_irq_type(struct irq_data *d, unsigned trigger)
@@ -286,10 +286,10 @@ gpio_irq_handler(unsigned irq, struct irq_desc *desc)
 		int		res;
 
 		/* ack any irqs */
-		status = __raw_readl(&g->intstat) & mask;
+		status = readl(&g->intstat) & mask;
 		if (!status)
 			break;
-		__raw_writel(status, &g->intstat);
+		writel(status, &g->intstat);
 
 		/* now demux them to the right lowlevel handler */
 		n = d->irq_base;
@@ -346,9 +346,9 @@ static int gpio_irq_type_unbanked(struct irq_data *data, unsigned trigger)
 	if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
 		return -EINVAL;
 
-	__raw_writel(mask, (trigger & IRQ_TYPE_EDGE_FALLING)
+	writel(mask, (trigger & IRQ_TYPE_EDGE_FALLING)
 		     ? &g->set_falling : &g->clr_falling);
-	__raw_writel(mask, (trigger & IRQ_TYPE_EDGE_RISING)
+	writel(mask, (trigger & IRQ_TYPE_EDGE_RISING)
 		     ? &g->set_rising : &g->clr_rising);
 
 	return 0;
@@ -430,8 +430,8 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
 
 		/* default trigger: both edges */
 		g = gpio2regs(0);
-		__raw_writel(~0, &g->set_falling);
-		__raw_writel(~0, &g->set_rising);
+		writel(~0, &g->set_falling);
+		writel(~0, &g->set_rising);
 
 		/* set the direct IRQs up to use that irqchip */
 		for (gpio = 0; gpio < pdata->gpio_unbanked; gpio++, irq++) {
@@ -454,8 +454,8 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
 
 		/* disabled by default, enabled only as needed */
 		g = gpio2regs(gpio);
-		__raw_writel(~0, &g->clr_falling);
-		__raw_writel(~0, &g->clr_rising);
+		writel(~0, &g->clr_falling);
+		writel(~0, &g->clr_rising);
 
 		/* set up all irqs in this bank */
 		irq_set_chained_handler(bank_irq, gpio_irq_handler);
@@ -483,7 +483,7 @@ done:
 	 * BINTEN -- per-bank interrupt enable. genirq would also let these
 	 * bits be set/cleared dynamically.
 	 */
-	__raw_writel(binten, gpio_base + BINTEN);
+	writel(binten, gpio_base + BINTEN);
 
 	printk(KERN_INFO "DaVinci: %d gpio irqs\n", irq - gpio_to_irq(0));
 
Signature · 1 line
1.7.9.5
#6 lore raw

PATCH v5 3/7 gpio: davinci: use irqdomain

In reply to Prabhakar Lad

From: "Lad, Prabhakar" <[email protected]>

This patch converts the davinci gpio driver to use irqdomain support.

---
 drivers/gpio/gpio-davinci.c                |   74 +++++++++++++++-------------
 include/linux/platform_data/gpio-davinci.h |    2 +-
 2 files changed, 41 insertions(+), 35 deletions(-)
drivers/gpio/gpio-davinci.c +40 -34
index ca3d7fd..b149239 100644
@@ -16,6 +16,7 @@
 #include <linux/err.h>
 #include <linux/io.h>
 #include <linux/irq.h>
+#include <linux/irqdomain.h>
 #include <linux/platform_device.h>
 #include <linux/platform_data/gpio-davinci.h>
 
@@ -282,8 +283,7 @@ gpio_irq_handler(unsigned irq, struct irq_desc *desc)
 	desc->irq_data.chip->irq_ack(&desc->irq_data);
 	while (1) {
 		u32		status;
-		int		n;
-		int		res;
+		int		bit;
 
 		/* ack any irqs */
 		status = readl(&g->intstat) & mask;
@@ -292,17 +292,11 @@ gpio_irq_handler(unsigned irq, struct irq_desc *desc)
 		writel(status, &g->intstat);
 
 		/* now demux them to the right lowlevel handler */
-		n = d->irq_base;
-		if (irq & 1) {
-			n += 16;
-			status >>= 16;
-		}
-
 		while (status) {
-			res = ffs(status);
-			n += res;
-			generic_handle_irq(n - 1);
-			status >>= res;
+			bit = __ffs(status);
+			status &= ~(1 << bit);
+			generic_handle_irq(irq_find_mapping(d->irq_domain,
+							    bit));
 		}
 	}
 	desc->irq_data.chip->irq_unmask(&desc->irq_data);
@@ -313,10 +307,7 @@ static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset)
 {
 	struct davinci_gpio_controller *d = chip2controller(chip);
 
-	if (d->irq_base >= 0)
-		return d->irq_base + offset;
-	else
-		return -ENODEV;
+	return irq_create_mapping(d->irq_domain, offset);
 }
 
 static int gpio_to_irq_unbanked(struct gpio_chip *chip, unsigned offset)
@@ -354,6 +345,28 @@ static int gpio_irq_type_unbanked(struct irq_data *data, unsigned trigger)
 	return 0;
 }
 
+static int davinci_gpio_irq_map(struct irq_domain *d, unsigned int irq,
+				irq_hw_number_t hw)
+{
+	struct davinci_gpio_controller *chip = d->host_data;
+	unsigned gpio = chip->chip.base + hw;
+	struct davinci_gpio_regs __iomem *g = gpio2regs(gpio);
+
+	irq_set_chip_and_handler_name(irq, &gpio_irqchip, handle_simple_irq,
+				"davinci_gpio");
+	irq_set_irq_type(irq, IRQ_TYPE_NONE);
+	irq_set_chip_data(irq, (__force void *)g);
+	irq_set_handler_data(irq, (void *)__gpio_mask(gpio));
+	set_irq_flags(irq, IRQF_VALID);
+
+	return 0;
+}
+
+static const struct irq_domain_ops davinci_gpio_irq_ops = {
+	.map = davinci_gpio_irq_map,
+	.xlate = irq_domain_xlate_onetwocell,
+};
+
 /*
  * NOTE:  for suspend/resume, probably best to make a platform_device with
  * suspend_late/resume_resume calls hooking into results of the set_wake()
@@ -402,9 +415,16 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
 	 */
 	for (gpio = 0, bank = 0; gpio < ngpio; bank++, gpio += 32) {
 		chips[bank].chip.to_irq = gpio_to_irq_banked;
-		chips[bank].irq_base = pdata->gpio_unbanked
-			? -EINVAL
-			: (pdata->intc_irq_num + gpio);
+		if (!pdata->gpio_unbanked) {
+			chips[bank].irq_domain =
+				irq_domain_add_linear(NULL,
+						      chips[bank].chip.ngpio,
+						      &davinci_gpio_irq_ops,
+						      &chips[bank]);
+
+			if (!chips[bank].irq_domain)
+				return -ENOMEM;
+		}
 	}
 
 	/*
@@ -447,11 +467,7 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
 	 * Or, AINTC can handle IRQs for banks of 16 GPIO IRQs, which we
 	 * then chain through our own handler.
 	 */
-	for (gpio = 0, irq = gpio_to_irq(0), bank = 0;
-			gpio < ngpio;
-			bank++, bank_irq++) {
-		unsigned		i;
-
+	for (gpio = 0, bank = 0; gpio < ngpio; bank++, bank_irq++, gpio += 16) {
 		/* disabled by default, enabled only as needed */
 		g = gpio2regs(gpio);
 		writel(~0, &g->clr_falling);
@@ -467,14 +483,6 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
 		 */
 		irq_set_handler_data(bank_irq, &chips[gpio / 32]);
 
-		for (i = 0; i < 16 && gpio < ngpio; i++, irq++, gpio++) {
-			irq_set_chip(irq, &gpio_irqchip);
-			irq_set_chip_data(irq, (__force void *)g);
-			irq_set_handler_data(irq, (void *)__gpio_mask(gpio));
-			irq_set_handler(irq, handle_simple_irq);
-			set_irq_flags(irq, IRQF_VALID);
-		}
-
 		binten |= BIT(bank);
 	}
 
@@ -485,8 +493,6 @@ done:
 	 */
 	writel(binten, gpio_base + BINTEN);
 
-	printk(KERN_INFO "DaVinci: %d gpio irqs\n", irq - gpio_to_irq(0));
-
 	return 0;
 }
 
include/linux/platform_data/gpio-davinci.h +1 -1
index 6efd202..0c3551b 100644
@@ -34,7 +34,7 @@ struct davinci_gpio_platform_data {
 
 struct davinci_gpio_controller {
 	struct gpio_chip	chip;
-	int			irq_base;
+	struct irq_domain	*irq_domain;
 	/* Serialize access to GPIO registers */
 	spinlock_t		lock;
 	void __iomem		*regs;
Signature · 1 line
1.7.9.5
#7 lore raw

Re: [PATCH v5 3/7] gpio: davinci: use irqdomain

Quoted 6 lines · Prabhakar Lad

From: "Lad, Prabhakar" <[email protected]>

This patch converts the davinci gpio driver to use irqdomain support.

(...)

drivers/gpio/gpio-davinci.c gpio_irq_handler(unsigned irq, struct irq_desc *desc) · line 286

Quoted 7 lines
drivers/gpio/gpio-davinci.c +1 -2
@@ -282,8 +283,7 @@ gpio_irq_handler(unsigned irq, struct irq_desc *desc)
        desc->irq_data.chip->irq_ack(&desc->irq_data);
        while (1) {
                u32             status;
-               int             n;
-               int             res;
+               int             bit;

Why is this an int? I think u8 would suffice.

Quoted 6 lines
drivers/gpio/gpio-davinci.c +0 -5
                /* now demux them to the right lowlevel handler */
-               n = d->irq_base;
-               if (irq & 1) {
-                       n += 16;
-                       status >>= 16;
-               }

drivers/gpio/gpio-davinci.c gpio_irq_handler(unsigned irq, struct irq_desc *desc) · line 299

Quoted 10 lines
drivers/gpio/gpio-davinci.c +4 -5
-
                while (status) {
-                       res = ffs(status);
-                       n += res;
-                       generic_handle_irq(n - 1);
-                       status >>= res;
+                       bit = __ffs(status);
+                       status &= ~(1 << bit);
+                       generic_handle_irq(irq_find_mapping(d->irq_domain,
+                                                           bit));

This is a nice hunk of the patch.

I would use <linux/bitops.h> and do:
status &= ~BIT(bit);

drivers/gpio/gpio-davinci.c static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset) · line 311

Quoted 10 lines
drivers/gpio/gpio-davinci.c +1 -4
@@ -313,10 +307,7 @@ static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset)
 {
        struct davinci_gpio_controller *d = chip2controller(chip);
 
-       if (d->irq_base >= 0)
-               return d->irq_base + offset;
-       else
-               return -ENODEV;
+       return irq_create_mapping(d->irq_domain, offset);
 }

I think we recently established that map creating cannot be done in gpio_to_irq* functions as that will not work properly if you request an IRQ from device tree without first obtaining the IRQ from the GPIO number with this function.

Instead call irq_create_mapping() on *all* used IRQ lines in the probe function and use irq_find_mapping() here too.

drivers/gpio/gpio-davinci.c static int davinci_gpio_irq_setup(struct platform_device *pdev) · line 484

Quoted 7 lines
drivers/gpio/gpio-davinci.c +1 -0
+       for (gpio = 0, bank = 0; gpio < ngpio; bank++, bank_irq++, gpio += 16) {
                /* disabled by default, enabled only as needed */
                g = gpio2regs(gpio);
                writel(~0, &g->clr_falling);
@@ -467,14 +483,6 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
                 */
                irq_set_handler_data(bank_irq, &chips[gpio / 32]);

So for example here you could call iurq_create_mapping();

Also: please write a patch that marks the IRQ lines. Call gpio_lock_as_irq(*gpio_chip, offset); in the irqchip startup/shutdown functions. (Can be a separate patch.)

Yours,
Linus Walleij

#8 lore raw

Re: [PATCH v5 3/7] gpio: davinci: use irqdomain

Quoted 11 lines · Linus Walleij
Quoted 6 lines · Prabhakar Lad

From: "Lad, Prabhakar" <[email protected]>

This patch converts the davinci gpio driver to use irqdomain support.

(...)

Quoted 9 lines

drivers/gpio/gpio-davinci.c gpio_irq_handler(unsigned irq, struct irq_desc *desc) · line 286

Quoted 7 lines
drivers/gpio/gpio-davinci.c +1 -2
@@ -282,8 +283,7 @@ gpio_irq_handler(unsigned irq, struct irq_desc *desc)
        desc->irq_data.chip->irq_ack(&desc->irq_data);
        while (1) {
                u32             status;
-               int             n;
-               int             res;
+               int             bit;

Why is this an int? I think u8 would suffice.

For local variables, it's better to use "int" or even "unsigned" here rather than u8. u8 tells the compiler that you want the variable to be 8-bit, which seems fine, except the compiler is then at liberty to keep on masking the register back down to 8-bit.

#9 lore raw

Re: [PATCH v5 3/7] gpio: davinci: use irqdomain

In reply to Linus Walleij

Hi Linus,

Quoted 48 lines · Linus Walleij
Quoted 6 lines · Prabhakar Lad

From: "Lad, Prabhakar" <[email protected]>

This patch converts the davinci gpio driver to use irqdomain support.

(...)

drivers/gpio/gpio-davinci.c gpio_irq_handler(unsigned irq, struct irq_desc *desc) · line 286

Quoted 7 lines
drivers/gpio/gpio-davinci.c +1 -2
@@ -282,8 +283,7 @@ gpio_irq_handler(unsigned irq, struct irq_desc *desc)
         desc->irq_data.chip->irq_ack(&desc->irq_data);
         while (1) {
                 u32             status;
-               int             n;
-               int             res;
+               int             bit;

Why is this an int? I think u8 would suffice.

Quoted 6 lines
drivers/gpio/gpio-davinci.c +0 -5
                 /* now demux them to the right lowlevel handler */
-               n = d->irq_base;
-               if (irq & 1) {
-                       n += 16;
-                       status >>= 16;
-               }

drivers/gpio/gpio-davinci.c gpio_irq_handler(unsigned irq, struct irq_desc *desc) · line 299

Quoted 10 lines
drivers/gpio/gpio-davinci.c +4 -5
-
                 while (status) {
-                       res = ffs(status);
-                       n += res;
-                       generic_handle_irq(n - 1);
-                       status >>= res;
+                       bit = __ffs(status);
+                       status &= ~(1 << bit);
+                       generic_handle_irq(irq_find_mapping(d->irq_domain,
+                                                           bit));

This is a nice hunk of the patch.

I would use <linux/bitops.h> and do:
status &= ~BIT(bit);

Quoted 4 lines
drivers/gpio/gpio-davinci.c +0 -0
@@ -313,10 +307,7 @@ static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset)
  {
         struct davinci_gpio_controller *d = chip2controller(chip);
 
Quoted 11 lines

drivers/gpio/gpio-davinci.c static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset) · line 311

Quoted 6 lines
drivers/gpio/gpio-davinci.c +1 -4
-       if (d->irq_base >= 0)
-               return d->irq_base + offset;
-       else
-               return -ENODEV;
+       return irq_create_mapping(d->irq_domain, offset);
  }

I think we recently established that map creating cannot be done in gpio_to_irq* functions as that will not work properly if you request an IRQ from device tree without first obtaining the IRQ from the GPIO number with this function.

Why? Could you point on corresponding thread, pls? Current call tree is:
irq_create_of_mapping()
|-hwirq = omain->ops->xlate() |-irq_create_mapping(domain, hwirq)

Quoted 14 lines

Instead call irq_create_mapping() on *all* used IRQ lines in the probe function and use irq_find_mapping() here too.

drivers/gpio/gpio-davinci.c static int davinci_gpio_irq_setup(struct platform_device *pdev) · line 484

Quoted 7 lines
drivers/gpio/gpio-davinci.c +1 -0
+       for (gpio = 0, bank = 0; gpio < ngpio; bank++, bank_irq++, gpio += 16) {
                 /* disabled by default, enabled only as needed */
                 g = gpio2regs(gpio);
                 writel(~0, &g->clr_falling);
@@ -467,14 +483,6 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
                  */
                 irq_set_handler_data(bank_irq, &chips[gpio / 32]);

So for example here you could call iurq_create_mapping();

Quoted 4 lines

Also: please write a patch that marks the IRQ lines. Call gpio_lock_as_irq(*gpio_chip, offset); in the irqchip startup/shutdown functions. (Can be a separate patch.)

It seems, some misunderstanding is here. So I'd like to clarify few points and would be very appreciate for your comments:
1) This patch itself will work unless we switch to DT (as in the following patch)

2) After this patch the following object structure will be created during Davinci GPIO driver initialization (DA850 has 144 IRQ lines):
- gpio_chip0(0..31)
|- irq_domain1
- gpio_chip1(32..63)
|- irq_domain2
- gpio_chip2(64..95)
|- irq_domain3
- gpio_chip3(96..127)
|- irq_domain4
- gpio_chip4(128..143)
|- irq_domain5

3) But in case of DT only one GPIO controller node will be created Example:

gpio: gpio at 1e26000 {
	compatible = "ti,dm6441-gpio";
	gpio-controller;
	reg = <0x226000 0x1000>;
	interrupt-parent = <&intc>;
	interrupts = <42 IRQ_TYPE_EDGE_BOTH 43 IRQ_TYPE_EDGE_BOTH
		44 IRQ_TYPE_EDGE_BOTH 45 IRQ_TYPE_EDGE_BOTH
		46 IRQ_TYPE_EDGE_BOTH 47 IRQ_TYPE_EDGE_BOTH
		48 IRQ_TYPE_EDGE_BOTH 49 IRQ_TYPE_EDGE_BOTH
		50 IRQ_TYPE_EDGE_BOTH>;
	interrupt-controller;
	#interrupt-cells = <2>;
	ti,ngpio = <144>;
	ti,davinci-gpio-unbanked = <0>;
}

4) As result, to make GPIO bindings/mappings work - we'll need to implement .of_xlate() callback per GPIO chip, which will provide us with valid valid gpio_chip and offset of gpio inside chip
(It was discussed before and supposed to be done as next step).

For example, gpio_chip3 and offset=15 should be selected:

devA {
    gpios = <&gpio 111 GPIO_ACTIVE_HIGH>;
}

5) What should be done to make GPIO IRQ bindings/mappings work?

Example:

devB {
    interrupt-parent = <&gpio>;
    interrupts = <111 IRQ_TYPE_EDGE_BOTH>;
}

Should we implement one IRQ domain per all GPIO chips (per GPIO controller)?

Thanks.

Regards,
-Grygorii

#10 lore raw

Re: [PATCH v5 3/7] gpio: davinci: use irqdomain

Quoted 8 lines · Grygorii Strashko
Quoted 4 lines · Linus Walleij

I think we recently established that map creating cannot be done in gpio_to_irq* functions as that will not work properly if you request an IRQ from device tree without first obtaining the IRQ from the GPIO number with this function.

Why? Could you point on corresponding thread, pls?

All that contain this:
"gpio: interrupt consistency check for OF GPIO IRQs"
http://marc.info/?l=linux-kernel&w=2&r=1&s=interrupt+consistency&q=b

Quoted 4 lines

Current call tree is:
irq_create_of_mapping()
|-hwirq = omain->ops->xlate()
|-irq_create_mapping(domain, hwirq)

OK that works for the pure device-tree scenario so mostly this is OK.

The problem that appear is if someone is using platform data-provided IRQs off the irq_chip without calling gpio_to_irq() on the GPIO line first. This has been determined to be legal to do, so preferably create the map when registering the lines.

Quoted 9 lines
Quoted 4 lines

Also: please write a patch that marks the IRQ lines. Call gpio_lock_as_irq(*gpio_chip, offset); in the irqchip startup/shutdown functions. (Can be a separate patch.)

It seems, some misunderstanding is here. So I'd like to clarify few points and would be very appreciate for your comments:
1) This patch itself will work unless we switch to DT (as in the following patch)

Sure.... but this does not seem to have much to do with my request to use gpio_lock_as_irq().

Quoted 4 lines

2) After this patch the following object structure will be created during Davinci GPIO driver initialization (DA850 has 144 IRQ lines):
- gpio_chip0(0..31)
|- irq_domain1

Quoted 8 lines

- gpio_chip1(32..63)
|- irq_domain2
- gpio_chip2(64..95)
|- irq_domain3
- gpio_chip3(96..127)
|- irq_domain4
- gpio_chip4(128..143)
|- irq_domain5

OK that's nice.

Quoted 17 lines

3) But in case of DT only one GPIO controller node will be created Example:

gpio: gpio at 1e26000 {
        compatible = "ti,dm6441-gpio";
        gpio-controller;
        reg = <0x226000 0x1000>;
        interrupt-parent = <&intc>;
        interrupts = <42 IRQ_TYPE_EDGE_BOTH 43 IRQ_TYPE_EDGE_BOTH
                44 IRQ_TYPE_EDGE_BOTH 45 IRQ_TYPE_EDGE_BOTH
                46 IRQ_TYPE_EDGE_BOTH 47 IRQ_TYPE_EDGE_BOTH
                48 IRQ_TYPE_EDGE_BOTH 49 IRQ_TYPE_EDGE_BOTH
                50 IRQ_TYPE_EDGE_BOTH>;
        interrupt-controller;
        #interrupt-cells = <2>;
        ti,ngpio = <144>;
        ti,davinci-gpio-unbanked = <0>;
}

Yep...

Quoted 4 lines

4) As result, to make GPIO bindings/mappings work - we'll need to implement .of_xlate() callback per GPIO chip, which will provide us with valid valid gpio_chip and offset of gpio inside chip
(It was discussed before and supposed to be done as next step).

Yeah.. this is usually a bit tricky.

Quoted 7 lines

For example, gpio_chip3 and offset=15 should be selected:

devA {
   gpios = <&gpio 111 GPIO_ACTIVE_HIGH>;
}

5) What should be done to make GPIO IRQ bindings/mappings work?

Quoted 7 lines

Example:

devB {
   interrupt-parent = <&gpio>;
   interrupts = <111 IRQ_TYPE_EDGE_BOTH>;
}

Should we implement one IRQ domain per all GPIO chips (per GPIO controller)?

I don't know, I cannot really see where the problem is.

The IRQ domain is for translationg hardware numbers such as bit offsets into Linux IRQ numbers and nothing else, so I'd suggest that as long as the thing you are translating/mapping is something simple like a bit index you're doing the right thing.

If it becomes something complex where that index is not just a bit but an index into an array of registers at various locations it is abusing the irqdomain.

So I think you should create one irqdomain per GPIO instance or bank or whatever you want to call it: like if there is this one register with 32 bits, then it gets its own IRQdomain.

I think you should try to keep the 5 irqdomains, but whatever gives the simplest code is usually the right answer, and divide-and-conquer (split down the problem) is usually a good idea.

How the GPIO block(s) are represented in the device tree is another totally separate issue about hardware description, do not let the device tree model your driver structure.

Yours,
Linus Walleij

#11 lore raw

Re: [PATCH v5 3/7] gpio: davinci: use irqdomain

Quoted 9 lines · Linus Walleij
Quoted 7 lines · Grygorii Strashko
Quoted 4 lines · Linus Walleij

I think we recently established that map creating cannot be done in gpio_to_irq* functions as that will not work properly if you request an IRQ from device tree without first obtaining the IRQ from the GPIO number with this function.

Quoted 5 lines
Quoted 1 line

Why? Could you point on corresponding thread, pls?

All that contain this:
"gpio: interrupt consistency check for OF GPIO IRQs"
http://marc.info/?l=linux-kernel&w=2&r=1&s=interrupt+consistency&q=b

Thanks.

Quoted 6 lines
Quoted 5 lines

Current call tree is:
irq_create_of_mapping()
|-hwirq = omain->ops->xlate()
|-irq_create_mapping(domain, hwirq)

Quoted 7 lines

OK that works for the pure device-tree scenario so mostly this is OK.

The problem that appear is if someone is using platform data-provided IRQs off the irq_chip without calling gpio_to_irq() on the GPIO line first. This has been determined to be legal to do, so preferably create the map when registering the lines.

Ok, I understand. It may fail in case if someone will define/calculate
IRQ number for device manually in board code, like:
dev_irq = (DA850_N_CP_INTC_IRQ + gpioN)

Also, looks like It is possible to fail if Main/arch IRQ controller code doesn't make call of irq_alloc_descs() during init, so allocated_irqs will be empty.

Actually, the irq_find_mapping() was called before from gpio_to_irq_banked() in v4 of this series - than It was changed according to my comment, to get maximum benefits of using linear IRQ domain.

Before recommending that, I've checked Davinci platform code and didn't find any risk places - BUT, Seems my findings need to be confirmed by Sekhar.

I purpose to move forward as is if above will be confirmed. Otherwise, we can switch to use irq_domain_add_legacy().

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Also: please write a patch that marks the IRQ lines. Call gpio_lock_as_irq(*gpio_chip, offset); in the irqchip startup/shutdown functions. (Can be a separate patch.)

Quoted 7 lines
Quoted 4 lines

It seems, some misunderstanding is here. So I'd like to clarify few points and would be very appreciate for your comments:
1) This patch itself will work unless we switch to DT (as in the following patch)

Sure.... but this does not seem to have much to do with my request to use gpio_lock_as_irq().

Oh no. Your request about gpio_lock_as_irq() is absolutely valid :) And it has to be added

Quoted 73 lines
Quoted 13 lines

2) After this patch the following object structure will be created during Davinci GPIO driver initialization (DA850 has 144 IRQ lines):
- gpio_chip0(0..31)
|- irq_domain1
- gpio_chip1(32..63)
|- irq_domain2
- gpio_chip2(64..95)
|- irq_domain3
- gpio_chip3(96..127)
|- irq_domain4
- gpio_chip4(128..143)
|- irq_domain5

OK that's nice.

Quoted 17 lines

3) But in case of DT only one GPIO controller node will be created Example:

gpio: gpio at 1e26000 {
         compatible = "ti,dm6441-gpio";
         gpio-controller;
         reg = <0x226000 0x1000>;
         interrupt-parent = <&intc>;
         interrupts = <42 IRQ_TYPE_EDGE_BOTH 43 IRQ_TYPE_EDGE_BOTH
                 44 IRQ_TYPE_EDGE_BOTH 45 IRQ_TYPE_EDGE_BOTH
                 46 IRQ_TYPE_EDGE_BOTH 47 IRQ_TYPE_EDGE_BOTH
                 48 IRQ_TYPE_EDGE_BOTH 49 IRQ_TYPE_EDGE_BOTH
                 50 IRQ_TYPE_EDGE_BOTH>;
         interrupt-controller;
         #interrupt-cells = <2>;
         ti,ngpio = <144>;
         ti,davinci-gpio-unbanked = <0>;
}

Yep...

Quoted 4 lines

4) As result, to make GPIO bindings/mappings work - we'll need to implement .of_xlate() callback per GPIO chip, which will provide us with valid valid gpio_chip and offset of gpio inside chip
(It was discussed before and supposed to be done as next step).

Yeah.. this is usually a bit tricky.

Quoted 7 lines

For example, gpio_chip3 and offset=15 should be selected:

devA {
    gpios = <&gpio 111 GPIO_ACTIVE_HIGH>;
}

5) What should be done to make GPIO IRQ bindings/mappings work?

Quoted 7 lines

Example:

devB {
    interrupt-parent = <&gpio>;
    interrupts = <111 IRQ_TYPE_EDGE_BOTH>;
}

Should we implement one IRQ domain per all GPIO chips (per GPIO controller)?

I don't know, I cannot really see where the problem is.

The IRQ domain is for translationg hardware numbers such as bit offsets into Linux IRQ numbers and nothing else, so I'd suggest that as long as the thing you are translating/mapping is something simple like a bit index you're doing the right thing.

If it becomes something complex where that index is not just a bit but an index into an array of registers at various locations it is abusing the irqdomain.

So I think you should create one irqdomain per GPIO instance or bank or whatever you want to call it: like if there is this one register with 32 bits, then it gets its own IRQdomain.

Quoted 8 lines

I think you should try to keep the 5 irqdomains, but whatever gives the simplest code is usually the right answer, and divide-and-conquer (split down the problem) is usually a good idea.

How the GPIO block(s) are represented in the device tree is another totally separate issue about hardware description, do not let the device tree model your driver structure.

Thanks for you comments, but looks like I have to be more specific :)

How irq_find_host() will look for proper IRQ domain in our case? And will it work at all, taking into account that all (5) IRQ domains will have the same value of "of_node" property? of_irq_to_resource()
|-irq_of_parse_and_map()
|-irq_create_of_mapping()

     |-irq_find_host(irq_data->np)

where np will point on GPIO node.

As result my question is about what do DT core frameworks allow or not allow to do? And according to that implementation of driver can be changed.

Regards,
-grygorii

#12 lore raw

Re: [PATCH v5 3/7] gpio: davinci: use irqdomain

Quoted 10 lines · Grygorii Strashko
Quoted 4 lines · Linus Walleij

The problem that appear is if someone is using platform data-provided IRQs off the irq_chip without calling gpio_to_irq() on the GPIO line first. This has been determined to be legal to do, so preferably create the map when registering the lines.

Ok, I understand. It may fail in case if someone will define/calculate
IRQ number for device manually in board code, like:
dev_irq = (DA850_N_CP_INTC_IRQ + gpioN)

Usually people just hardcode the IRQ value or use some #define, like they have often also done with GPIO numbers ...

Quoted 3 lines

Also, looks like It is possible to fail if Main/arch IRQ controller code doesn't make call of irq_alloc_descs() during init, so allocated_irqs will be empty.

If you use irq_domain_add_simple() the irqdomain core will actually attempt to do this.

But if you use a linear domain, you have to create these irqdescs as you go. The simplest way to do this is to call irq_create_mapping() on all IRQs, because that call will also allocate some descriptor.

Quoted 3 lines

Before recommending that, I've checked Davinci platform code and didn't find any risk places - BUT, Seems my findings need to be confirmed by Sekhar.

It's no big deal, but I just want you to be aware that this may cause a problem at some point.

Quoted 18 lines
Quoted 8 lines

I think you should try to keep the 5 irqdomains, but whatever gives the simplest code is usually the right answer, and divide-and-conquer (split down the problem) is usually a good idea.

How the GPIO block(s) are represented in the device tree is another totally separate issue about hardware description, do not let the device tree model your driver structure.

Thanks for you comments, but looks like I have to be more specific :)

How irq_find_host() will look for proper IRQ domain in our case? And will it work at all, taking into account that all (5) IRQ domains will have the same value of "of_node" property? of_irq_to_resource()
|-irq_of_parse_and_map()
|-irq_create_of_mapping()

Quoted 6 lines
    |-irq_find_host(irq_data->np)

where np will point on GPIO node.

As result my question is about what do DT core frameworks allow or not allow to do? And according to that implementation of driver can be changed.

Hm, I'm not like a super-expert on the interrupt core, but maybe you need to create subnodes inside the top node to represent this, then use of_platform_populate(pdev->dev.of_node, NULL, NULL, &pdev->dev); to populate them from the main node.

Yours,
Linus Walleij

#13 lore raw

PATCH v5 4/7 gpio: davinci: remove unused variable intc_irq_num

In reply to Prabhakar Lad

From: "Lad, Prabhakar" <[email protected]>

As the davinci-gpio driver is migrated to use irqdomain there is no need to pass the irq base for the gpio driver. This patch removes this variable from davinci_gpio_platform_data and also the references from the machine file.

---
 arch/arm/mach-davinci/da830.c              |    1 -
 arch/arm/mach-davinci/da850.c              |    1 -
 arch/arm/mach-davinci/dm355.c              |    1 -
 arch/arm/mach-davinci/dm365.c              |    1 -
 arch/arm/mach-davinci/dm644x.c             |    1 -
 arch/arm/mach-davinci/dm646x.c             |    1 -
 include/linux/platform_data/gpio-davinci.h |    1 -
 7 files changed, 7 deletions(-)
arch/arm/mach-davinci/da830.c +0 -1
index 0813b51..fb72035 100644
@@ -1153,7 +1153,6 @@ static struct davinci_id da830_ids[] = {
 
 static struct davinci_gpio_platform_data da830_gpio_platform_data = {
 	.ngpio = 128,
-	.intc_irq_num = DA830_N_CP_INTC_IRQ,
 };
 
 int __init da830_register_gpio(void)
arch/arm/mach-davinci/da850.c +0 -1
index 352984e..4379317 100644
@@ -1283,7 +1283,6 @@ int __init da850_register_vpif_capture(struct vpif_capture_config
 
 static struct davinci_gpio_platform_data da850_gpio_platform_data = {
 	.ngpio = 144,
-	.intc_irq_num = DA850_N_CP_INTC_IRQ,
 };
 
 int __init da850_register_gpio(void)
arch/arm/mach-davinci/dm355.c +0 -1
index 536ce52..a1713cc 100644
@@ -900,7 +900,6 @@ static struct resource dm355_gpio_resources[] = {
 
 static struct davinci_gpio_platform_data dm355_gpio_platform_data = {
 	.ngpio		= 104,
-	.intc_irq_num	= DAVINCI_N_AINTC_IRQ,
 };
 
 int __init dm355_gpio_register(void)
arch/arm/mach-davinci/dm365.c +0 -1
index 9c96520..2595097 100644
@@ -713,7 +713,6 @@ static struct resource dm365_gpio_resources[] = {
 
 static struct davinci_gpio_platform_data dm365_gpio_platform_data = {
 	.ngpio		= 104,
-	.intc_irq_num	= DAVINCI_N_AINTC_IRQ,
 	.gpio_unbanked	= 8,
 };
 
arch/arm/mach-davinci/dm644x.c +0 -1
index 72a3aa7..d83436d 100644
@@ -786,7 +786,6 @@ static struct resource dm644_gpio_resources[] = {
 
 static struct davinci_gpio_platform_data dm644_gpio_platform_data = {
 	.ngpio		= 71,
-	.intc_irq_num	= DAVINCI_N_AINTC_IRQ,
 };
 
 int __init dm644x_gpio_register(void)
arch/arm/mach-davinci/dm646x.c +0 -1
index d1b646c..5d289f4 100644
@@ -763,7 +763,6 @@ static struct resource dm646x_gpio_resources[] = {
 
 static struct davinci_gpio_platform_data dm646x_gpio_platform_data = {
 	.ngpio		= 43,
-	.intc_irq_num	= DAVINCI_N_AINTC_IRQ,
 };
 
 int __init dm646x_gpio_register(void)
include/linux/platform_data/gpio-davinci.h +0 -1
index 0c3551b..fbe2f75 100644
@@ -28,7 +28,6 @@ enum davinci_gpio_type {
 struct davinci_gpio_platform_data {
 	u32	ngpio;
 	u32	gpio_unbanked;
-	u32	intc_irq_num;
 };
 
 
Signature · 1 line
1.7.9.5
#14 lore raw

PATCH v5 5/7 gpio: davinci: add OF support

In reply to Prabhakar Lad

From: KV Sujith <[email protected]>

This patch adds OF parser support for davinci gpio driver and also appropriate documentation in gpio-davinci.txt located at Documentation/devicetree/bindings/gpio/.

[prabhakar.csengg at gmail.com: simplified the OF code, removed
unnecessary DT property and also simplified the commit message]

---
 .../devicetree/bindings/gpio/gpio-davinci.txt      |   39 ++++++++++++++
 drivers/gpio/gpio-davinci.c                        |   54 ++++++++++++++++++--
 2 files changed, 90 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-davinci.txt
Documentation/devicetree/bindings/gpio/gpio-davinci.txt new file +39 -0
new file mode 100644
index 0000000..d677bbe
@@ -0,0 +1,39 @@
+Davinci GPIO controller bindings
+
+Required Properties:
+- compatible: should be "ti,dm6441-gpio"
+
+- reg: Physical base address of the controller and the size of memory mapped
+       registers.
+
+- gpio-controller : Marks the device node as a gpio controller.
+
+- interrupt-parent: phandle of the parent interrupt controller.
+
+- interrupts: Array of GPIO interrupt number. Only banked or unbanked IRQs are
+	      supported at a time.
+
+- ti,ngpio: The number of GPIO pins supported.
+
+- ti,davinci-gpio-unbanked: The number of GPIOs that have an individual interrupt
+		             line to processor.
+
+The GPIO controller also acts as an interrupt controller. It uses the default
+two cells specifier as described in Documentation/devicetree/bindings/
+interrupt-controller/interrupts.txt.
+
+Example:
+
+gpio: gpio at 1e26000 {
+	compatible = "ti,dm6441-gpio";
+	gpio-controller;
+	reg = <0x226000 0x1000>;
+	interrupt-parent = <&intc>;
+	interrupts = <42 IRQ_TYPE_EDGE_BOTH 43 IRQ_TYPE_EDGE_BOTH
+		44 IRQ_TYPE_EDGE_BOTH 45 IRQ_TYPE_EDGE_BOTH
+		46 IRQ_TYPE_EDGE_BOTH 47 IRQ_TYPE_EDGE_BOTH
+		48 IRQ_TYPE_EDGE_BOTH 49 IRQ_TYPE_EDGE_BOTH
+		50 IRQ_TYPE_EDGE_BOTH>;
+	ti,ngpio = <144>;
+	ti,davinci-gpio-unbanked = <0>;
+};
drivers/gpio/gpio-davinci.c +51 -3

86 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#15 lore raw

Re: [PATCH v5 5/7] gpio: davinci: add OF support

Quoted 78 lines · Prabhakar Lad

From: KV Sujith <[email protected]>

This patch adds OF parser support for davinci gpio driver and also appropriate documentation in gpio-davinci.txt located at Documentation/devicetree/bindings/gpio/.

[prabhakar.csengg at gmail.com: simplified the OF code, removed
unnecessary DT property and also simplified the commit message]

---
  .../devicetree/bindings/gpio/gpio-davinci.txt      |   39 ++++++++++++++
  drivers/gpio/gpio-davinci.c                        |   54 ++++++++++++++++++--
  2 files changed, 90 insertions(+), 3 deletions(-)

create mode 100644 Documentation/devicetree/bindings/gpio/gpio-davinci.txt

Documentation/devicetree/bindings/gpio/gpio-davinci.txt new file +39 -0
new file mode 100644
index 0000000..d677bbe
@@ -0,0 +1,39 @@
+Davinci GPIO controller bindings
+
+Required Properties:
+- compatible: should be "ti,dm6441-gpio"
+
+- reg: Physical base address of the controller and the size of memory mapped
+       registers.
+
+- gpio-controller : Marks the device node as a gpio controller.
+
+- interrupt-parent: phandle of the parent interrupt controller.
+
+- interrupts: Array of GPIO interrupt number. Only banked or unbanked IRQs are
+	      supported at a time.
+
+- ti,ngpio: The number of GPIO pins supported.
+
+- ti,davinci-gpio-unbanked: The number of GPIOs that have an individual interrupt
+		             line to processor.
+
+The GPIO controller also acts as an interrupt controller. It uses the default
+two cells specifier as described in Documentation/devicetree/bindings/
+interrupt-controller/interrupts.txt.
+
+Example:
+
+gpio: gpio at 1e26000 {
+	compatible = "ti,dm6441-gpio";
+	gpio-controller;
+	reg = <0x226000 0x1000>;
+	interrupt-parent = <&intc>;
+	interrupts = <42 IRQ_TYPE_EDGE_BOTH 43 IRQ_TYPE_EDGE_BOTH
+		44 IRQ_TYPE_EDGE_BOTH 45 IRQ_TYPE_EDGE_BOTH
+		46 IRQ_TYPE_EDGE_BOTH 47 IRQ_TYPE_EDGE_BOTH
+		48 IRQ_TYPE_EDGE_BOTH 49 IRQ_TYPE_EDGE_BOTH
+		50 IRQ_TYPE_EDGE_BOTH>;
+	ti,ngpio = <144>;
+	ti,davinci-gpio-unbanked = <0>;
+};
drivers/gpio/gpio-davinci.c +3 -0
index b149239..ed04835 100644
@@ -17,6 +17,9 @@
  #include <linux/io.h>
  #include <linux/irq.h>
  #include <linux/irqdomain.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
  #include <linux/platform_device.h>
  #include <linux/platform_data/gpio-davinci.h>
 

drivers/gpio/gpio-davinci.c davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value) · line 141

Quoted 5 lines
drivers/gpio/gpio-davinci.c +2 -0
@@ -134,6 +137,40 @@ davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
  	writel((1 << offset), value ? &g->set_data : &g->clr_data);
  }
 
+static struct davinci_gpio_platform_data *
+davinci_gpio_get_pdata(struct platform_device *pdev)

Minor: usually such functions have "_of" in their names:
davinci_gpio_of_get_pdata()

Quoted 38 lines
drivers/gpio/gpio-davinci.c +32 -0
+{
+	struct device_node *dn = pdev->dev.of_node;
+	struct davinci_gpio_platform_data *pdata;
+	int ret;
+	u32 val;
+
+	if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node)
+		return pdev->dev.platform_data;
+
+	pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+	if (!pdata)
+		return NULL;
+
+	ret = of_property_read_u32(dn, "ti,ngpio", &val);
+	if (ret)
+		goto of_err;
+
+	pdata->ngpio = val;
+
+	ret = of_property_read_u32(dn, "ti,davinci-gpio-unbanked", &val);
+	if (ret)
+		goto of_err;
+
+	pdata->gpio_unbanked = val;
+
+	return pdata;
+
+of_err:
+	dev_err(&pdev->dev, "Populating pdata from DT failed: err %d\n", ret);
+	return NULL;
+}
+
  static int davinci_gpio_probe(struct platform_device *pdev)
  {
  	int i, base;
@@ -144,12 +181,14 @@ static int davinci_gpio_probe(struct platform_device *pdev)
  	struct device *dev = &pdev->dev;
  	struct resource *res;

drivers/gpio/gpio-davinci.c static int davinci_gpio_probe(struct platform_device *pdev) · line 191

Quoted 10 lines
drivers/gpio/gpio-davinci.c +3 -1
 
-	pdata = dev->platform_data;
+	pdata = davinci_gpio_get_pdata(pdev);
  	if (!pdata) {
  		dev_err(dev, "No platform data found\n");
  		return -EINVAL;
  	}
 
+	dev->platform_data = pdata;
+

Pls, add following code to GPIO chip initialization:

@@ -233,6 +245,9 @@ static int davinci_gpio_probe(struct platform_device *pdev)

                chips[i].chip.ngpio = ngpio - base;
                if (chips[i].chip.ngpio > 32)
                        chips[i].chip.ngpio = 32;

+#ifdef CONFIG_OF_GPIO
+ chips[i].chip.of_node = dev->of_node;
+#endif

Quoted 17 lines
drivers/gpio/gpio-davinci.c +8 -0
  	/*
  	 * The gpio banks conceptually expose a segmented bitmap,
  	 * and "ngpio" is one more than the largest zero-based
@@ -496,11 +535,20 @@ done:
  	return 0;
  }
 
+#if IS_ENABLED(CONFIG_OF)
+static const struct of_device_id davinci_gpio_ids[] = {
+	{ .compatible = "ti,dm6441-gpio", },
+	{ /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, davinci_gpio_ids);
+#endif
+
  static struct platform_driver davinci_gpio_driver = {

drivers/gpio/gpio-davinci.c done: · line 554

Quoted 10 lines
drivers/gpio/gpio-davinci.c +3 -2
  	.probe		= davinci_gpio_probe,
  	.driver		= {
-		.name	= "davinci_gpio",
-		.owner	= THIS_MODULE,
+		.name		= "davinci_gpio",
+		.owner		= THIS_MODULE,
+		.of_match_table	= of_match_ptr(davinci_gpio_ids),
  	},
  };
 

Regards,
- grygorii

#16 lore raw

Re: [PATCH v5 5/7] gpio: davinci: add OF support

Hi Grygorii,

Thanks for the review.

Quoted 1 line · Grygorii Strashko

On 11/08/2013 12:11 PM, Prabhakar Lad wrote:

[Snip]

Quoted 10 lines

drivers/gpio/gpio-davinci.c davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value) · line 141

Quoted 6 lines
drivers/gpio/gpio-davinci.c +2 -0
@@ -134,6 +137,40 @@ davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
      writel((1 << offset), value ? &g->set_data : &g->clr_data);
  }
 
+static struct davinci_gpio_platform_data *
+davinci_gpio_get_pdata(struct platform_device *pdev)

Minor: usually such functions have "_of" in their names:
davinci_gpio_of_get_pdata()

Ahh but actual this function is intended to get pdata in both the cases DT and NON-DT, so kept it generic :)

Quoted 52 lines
Quoted 38 lines
drivers/gpio/gpio-davinci.c +32 -0
+{
+     struct device_node *dn = pdev->dev.of_node;
+     struct davinci_gpio_platform_data *pdata;
+     int ret;
+     u32 val;
+
+     if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node)
+             return pdev->dev.platform_data;
+
+     pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+     if (!pdata)
+             return NULL;
+
+     ret = of_property_read_u32(dn, "ti,ngpio", &val);
+     if (ret)
+             goto of_err;
+
+     pdata->ngpio = val;
+
+     ret = of_property_read_u32(dn, "ti,davinci-gpio-unbanked", &val);
+     if (ret)
+             goto of_err;
+
+     pdata->gpio_unbanked = val;
+
+     return pdata;
+
+of_err:
+     dev_err(&pdev->dev, "Populating pdata from DT failed: err %d\n", ret);
+     return NULL;
+}
+
  static int davinci_gpio_probe(struct platform_device *pdev)
  {
      int i, base;
@@ -144,12 +181,14 @@ static int davinci_gpio_probe(struct platform_device *pdev)
      struct device *dev = &pdev->dev;
      struct resource *res;

drivers/gpio/gpio-davinci.c static int davinci_gpio_probe(struct platform_device *pdev) · line 191

Quoted 10 lines
drivers/gpio/gpio-davinci.c +3 -1
 
-     pdata = dev->platform_data;
+     pdata = davinci_gpio_get_pdata(pdev);
      if (!pdata) {
              dev_err(dev, "No platform data found\n");
              return -EINVAL;
      }
 
+     dev->platform_data = pdata;
+

Pls, add following code to GPIO chip initialization:

Review static int davinci_gpio_probe(struct platform_device *pdev) · line 252

Quoted 8 lines
(quoted diff) +3 -0
@@ -233,6 +245,9 @@ static int davinci_gpio_probe(struct platform_device *pdev)
                chips[i].chip.ngpio = ngpio - base;
                if (chips[i].chip.ngpio > 32)
                        chips[i].chip.ngpio = 32;
+#ifdef CONFIG_OF_GPIO
+               chips[i].chip.of_node = dev->of_node;
+#endif
 
 

OK

Regards,
--Prabhakar Lad

#17 lore raw

Re: [PATCH v5 5/7] gpio: davinci: add OF support

Quoted 12 lines · Prabhakar Lad

Hi Grygorii,

Thanks for the review.

Quoted 1 line · Grygorii Strashko

On 11/08/2013 12:11 PM, Prabhakar Lad wrote:

[Snip]

Quoted 4 lines
Quoted 4 lines
drivers/gpio/gpio-davinci.c +0 -0
@@ -134,6 +137,40 @@ davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
       writel((1 << offset), value ? &g->set_data : &g->clr_data);
   }
 
Quoted 8 lines
Quoted 6 lines

drivers/gpio/gpio-davinci.c davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value) · line 141

Quoted 2 lines
drivers/gpio/gpio-davinci.c +2 -0
+static struct davinci_gpio_platform_data *
+davinci_gpio_get_pdata(struct platform_device *pdev)

Minor: usually such functions have "_of" in their names:
davinci_gpio_of_get_pdata()

Ahh but actual this function is intended to get pdata in both the cases DT and NON-DT, so kept it generic :)

np

Quoted 66 lines
Quoted 53 lines
Quoted 39 lines
drivers/gpio/gpio-davinci.c +32 -0
+{
+     struct device_node *dn = pdev->dev.of_node;
+     struct davinci_gpio_platform_data *pdata;
+     int ret;
+     u32 val;
+
+     if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node)
+             return pdev->dev.platform_data;
+
+     pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+     if (!pdata)
+             return NULL;
+
+     ret = of_property_read_u32(dn, "ti,ngpio", &val);
+     if (ret)
+             goto of_err;
+
+     pdata->ngpio = val;
+
+     ret = of_property_read_u32(dn, "ti,davinci-gpio-unbanked", &val);
+     if (ret)
+             goto of_err;
+
+     pdata->gpio_unbanked = val;
+
+     return pdata;
+
+of_err:
+     dev_err(&pdev->dev, "Populating pdata from DT failed: err %d\n", ret);
+     return NULL;
+}
+
   static int davinci_gpio_probe(struct platform_device *pdev)
   {
       int i, base;
@@ -144,12 +181,14 @@ static int davinci_gpio_probe(struct platform_device *pdev)
       struct device *dev = &pdev->dev;
       struct resource *res;

drivers/gpio/gpio-davinci.c static int davinci_gpio_probe(struct platform_device *pdev) · line 191

Quoted 10 lines
drivers/gpio/gpio-davinci.c +3 -1
 
-     pdata = dev->platform_data;
+     pdata = davinci_gpio_get_pdata(pdev);
       if (!pdata) {
               dev_err(dev, "No platform data found\n");
               return -EINVAL;
       }
 
+     dev->platform_data = pdata;
+

Pls, add following code to GPIO chip initialization:

Review static int davinci_gpio_probe(struct platform_device *pdev) · line 252

Quoted 8 lines
(quoted diff) +3 -0
@@ -233,6 +245,9 @@ static int davinci_gpio_probe(struct platform_device *pdev)
                 chips[i].chip.ngpio = ngpio - base;
                 if (chips[i].chip.ngpio > 32)
                         chips[i].chip.ngpio = 32;
+#ifdef CONFIG_OF_GPIO
+               chips[i].chip.of_node = dev->of_node;
+#endif
 
 

OK

Regards,
--Prabhakar Lad

Acked-by on v5 5/7
#18 lore raw

Re: [PATCH v5 5/7] gpio: davinci: add OF support

In reply to Prabhakar Lad
Quoted 6 lines · Prabhakar Lad

From: KV Sujith <[email protected]>

This patch adds OF parser support for davinci gpio driver and also appropriate documentation in gpio-davinci.txt located at Documentation/devicetree/bindings/gpio/.

Quoted 6 lines

[prabhakar.csengg at gmail.com: simplified the OF code, removed
unnecessary DT property and also simplified the commit message]

I like this patch now!

Yours,
Linus Walleij

Acked-by on v5 5/7
#19 lore raw

Re: [PATCH v5 5/7] gpio: davinci: add OF support

In reply to Prabhakar Lad
Quoted 6 lines · Prabhakar Lad

From: KV Sujith <[email protected]>

This patch adds OF parser support for davinci gpio driver and also appropriate documentation in gpio-davinci.txt located at Documentation/devicetree/bindings/gpio/.

Quoted 6 lines

[prabhakar.csengg at gmail.com: simplified the OF code, removed
unnecessary DT property and also simplified the commit message]

You should add the interrupt-controller and #interrupt-cells properties to the example. Otherwise:

Quoted 152 lines
---
 .../devicetree/bindings/gpio/gpio-davinci.txt      |   39 ++++++++++++++
 drivers/gpio/gpio-davinci.c                        |   54 ++++++++++++++++++--
 2 files changed, 90 insertions(+), 3 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-davinci.txt
Documentation/devicetree/bindings/gpio/gpio-davinci.txt new file +39 -0
new file mode 100644
index 0000000..d677bbe
@@ -0,0 +1,39 @@
+Davinci GPIO controller bindings
+
+Required Properties:
+- compatible: should be "ti,dm6441-gpio"
+
+- reg: Physical base address of the controller and the size of memory mapped
+       registers.
+
+- gpio-controller : Marks the device node as a gpio controller.
+
+- interrupt-parent: phandle of the parent interrupt controller.
+
+- interrupts: Array of GPIO interrupt number. Only banked or unbanked IRQs are
+             supported at a time.
+
+- ti,ngpio: The number of GPIO pins supported.
+
+- ti,davinci-gpio-unbanked: The number of GPIOs that have an individual interrupt
+                            line to processor.
+
+The GPIO controller also acts as an interrupt controller. It uses the default
+two cells specifier as described in Documentation/devicetree/bindings/
+interrupt-controller/interrupts.txt.
+
+Example:
+
+gpio: gpio at 1e26000 {
+       compatible = "ti,dm6441-gpio";
+       gpio-controller;
+       reg = <0x226000 0x1000>;
+       interrupt-parent = <&intc>;
+       interrupts = <42 IRQ_TYPE_EDGE_BOTH 43 IRQ_TYPE_EDGE_BOTH
+               44 IRQ_TYPE_EDGE_BOTH 45 IRQ_TYPE_EDGE_BOTH
+               46 IRQ_TYPE_EDGE_BOTH 47 IRQ_TYPE_EDGE_BOTH
+               48 IRQ_TYPE_EDGE_BOTH 49 IRQ_TYPE_EDGE_BOTH
+               50 IRQ_TYPE_EDGE_BOTH>;
+       ti,ngpio = <144>;
+       ti,davinci-gpio-unbanked = <0>;
+};
drivers/gpio/gpio-davinci.c +51 -4
index b149239..ed04835 100644
@@ -17,6 +17,9 @@
 #include <linux/io.h>
 #include <linux/irq.h>
 #include <linux/irqdomain.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
 #include <linux/platform_device.h>
 #include <linux/platform_data/gpio-davinci.h>
 
@@ -134,6 +137,40 @@ davinci_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
        writel((1 << offset), value ? &g->set_data : &g->clr_data);
 }
 
+static struct davinci_gpio_platform_data *
+davinci_gpio_get_pdata(struct platform_device *pdev)
+{
+       struct device_node *dn = pdev->dev.of_node;
+       struct davinci_gpio_platform_data *pdata;
+       int ret;
+       u32 val;
+
+       if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node)
+               return pdev->dev.platform_data;
+
+       pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
+       if (!pdata)
+               return NULL;
+
+       ret = of_property_read_u32(dn, "ti,ngpio", &val);
+       if (ret)
+               goto of_err;
+
+       pdata->ngpio = val;
+
+       ret = of_property_read_u32(dn, "ti,davinci-gpio-unbanked", &val);
+       if (ret)
+               goto of_err;
+
+       pdata->gpio_unbanked = val;
+
+       return pdata;
+
+of_err:
+       dev_err(&pdev->dev, "Populating pdata from DT failed: err %d\n", ret);
+       return NULL;
+}
+
 static int davinci_gpio_probe(struct platform_device *pdev)
 {
        int i, base;
@@ -144,12 +181,14 @@ static int davinci_gpio_probe(struct platform_device *pdev)
        struct device *dev = &pdev->dev;
        struct resource *res;
 
-       pdata = dev->platform_data;
+       pdata = davinci_gpio_get_pdata(pdev);
        if (!pdata) {
                dev_err(dev, "No platform data found\n");
                return -EINVAL;
        }
 
+       dev->platform_data = pdata;
+
        /*
         * The gpio banks conceptually expose a segmented bitmap,
         * and "ngpio" is one more than the largest zero-based
@@ -496,11 +535,20 @@ done:
        return 0;
 }
 
+#if IS_ENABLED(CONFIG_OF)
+static const struct of_device_id davinci_gpio_ids[] = {
+       { .compatible = "ti,dm6441-gpio", },
+       { /* sentinel */ },
+};
+MODULE_DEVICE_TABLE(of, davinci_gpio_ids);
+#endif
+
 static struct platform_driver davinci_gpio_driver = {
        .probe          = davinci_gpio_probe,
        .driver         = {
-               .name   = "davinci_gpio",
-               .owner  = THIS_MODULE,
+               .name           = "davinci_gpio",
+               .owner          = THIS_MODULE,
+               .of_match_table = of_match_ptr(davinci_gpio_ids),
        },
 };
 
--

1.7.9.5

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

#20 lore raw

PATCH v5 6/7 ARM: davinci: da850: add GPIO DT node

In reply to Prabhakar Lad

From: KV Sujith <[email protected]>

Add DT node for Davinci GPIO driver.

---
 arch/arm/boot/dts/da850.dtsi |   14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/arm/boot/dts/da850.dtsi +14 -0
index 8d17346..b695548 100644
@@ -8,6 +8,7 @@
  * option) any later version.
  */
 #include "skeleton.dtsi"
+#include <dt-bindings/interrupt-controller/irq.h>
 
 / {
 	arm {
@@ -256,6 +257,19 @@
 					36
 					>;
 		};
+		gpio: gpio at 1e26000 {
+			compatible = "ti,dm6441-gpio";
+			gpio-controller;
+			reg = <0x226000 0x1000>;
+			interrupts = <42 IRQ_TYPE_EDGE_BOTH
+				43 IRQ_TYPE_EDGE_BOTH 44 IRQ_TYPE_EDGE_BOTH
+				45 IRQ_TYPE_EDGE_BOTH 46 IRQ_TYPE_EDGE_BOTH
+				47 IRQ_TYPE_EDGE_BOTH 48 IRQ_TYPE_EDGE_BOTH
+				49 IRQ_TYPE_EDGE_BOTH 50 IRQ_TYPE_EDGE_BOTH>;
+			ti,ngpio = <144>;
+			ti,davinci-gpio-unbanked = <0>;
+			status = "disabled";
+		};
 	};
 	nand_cs3 at 62000000 {
 		compatible = "ti,davinci-nand";
Signature · 1 line
1.7.9.5
#21 lore raw

PATCH v5 7/7 ARM: davinci: da850 evm: add GPIO pinumux entries DT node

In reply to Prabhakar Lad

From: KV Sujith <[email protected]>

Add GPIO DT node and pinmux entries for DA850 EVM. GPIO is configurable differently on different boards. So add GPIO pinmuxing in dts file.

---
 arch/arm/boot/dts/da850-evm.dts |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
arch/arm/boot/dts/da850-evm.dts +20 -0
index 588ce58..f82c129 100644
@@ -17,6 +17,21 @@
 	soc {
 		pmx_core: pinmux at 1c14120 {
 			status = "okay";
+
+			gpio_pins: pinmux_gpio_pins {
+				pinctrl-single,bits = <
+					/* GPIO2_4 GPIO2_6 */
+					0x18 0x00008080 0x0000f0f0
+					/* GPIO2_8 GPIO2_15 */
+					0x14 0x80000008 0xf000000f
+					/* GPIO3_12 GPIO3_13 */
+					0x1C 0x00008800 0x0000ff00
+					/* GPIO4_0 GPIO4_1 */
+					0x28 0x88000000 0xff000000
+					/* GPIO6_9 GPIO6_10 GPIO6_13 */
+					0x34 0x08800800 0x0ff00f00
+				>;
+			};
 		};
 		serial0: serial at 1c42000 {
 			status = "okay";
@@ -101,6 +116,11 @@
 			pinctrl-names = "default";
 			pinctrl-0 = <&mii_pins>;
 		};
+		gpio: gpio at 1e26000 {
+			status = "okay";
+			pinctrl-names = "default";
+			pinctrl-0 = <&gpio_pins>;
+		};
 	};
 	nand_cs3 at 62000000 {
 		status = "okay";
Signature · 1 line
1.7.9.5
#22 lore raw
In reply to Prabhakar Lad

Hi Prabhakar Lad,

Quoted 7 lines · Prabhakar Lad

From: KV Sujith <[email protected]>

This patch series does the following 1> Ports the driver to use irqdomain. 2> Adds dt binding support for gpio-davinci. 3> Adds DA850 dt support goio.

Quoted 6 lines

Changes for v5:
1: Fixed review comments pointed by Grygorii. 2: Dropped the fixup patch

This patch series is based on following fixup series
http://us.generation-nt.com/answer/patch-0-2-davinci-gpio-fixes-help-212978272.html

Few comments to this series - the rest looks ok to me.
Hope it will pass review of bindings :P

Quoted 24 lines

KV Sujith (3):
gpio: davinci: add OF support
ARM: davinci: da850: add GPIO DT node
ARM: davinci: da850 evm: add GPIO pinumux entries DT node

Lad, Prabhakar (4):
gpio: davinci: remove unnecessary printk
gpio: davinci: use readl/writel instead of __raw_*
gpio: davinci: use irqdomain
gpio: davinci: remove unused variable intc_irq_num

  .../devicetree/bindings/gpio/gpio-davinci.txt      |   39 +++++
  arch/arm/boot/dts/da850-evm.dts                    |   20 +++
  arch/arm/boot/dts/da850.dtsi                       |   14 ++
  arch/arm/mach-davinci/da830.c                      |    1 -
  arch/arm/mach-davinci/da850.c                      |    1 -
  arch/arm/mach-davinci/dm355.c                      |    1 -
  arch/arm/mach-davinci/dm365.c                      |    1 -
  arch/arm/mach-davinci/dm644x.c                     |    1 -
  arch/arm/mach-davinci/dm646x.c                     |    1 -
  drivers/gpio/gpio-davinci.c                        |  170 +++++++++++++-------
  include/linux/platform_data/gpio-davinci.h         |    3 +-
  11 files changed, 185 insertions(+), 67 deletions(-)
Quoted 2 lines

create mode 100644 Documentation/devicetree/bindings/gpio/gpio-davinci.txt

Regards,
- grygorii