Skip to contentSkip to conversation

gpio: davinci: reuse for keystone arch

PATCH Superseded Grygorii Strashko 5 participants 12 messages Dec 18, 2013 – Dec 23, 2013

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover gpio: davinci: reuse for keystone arch

This series is intended to update Davinci GPIO driver and reuse it for Keystone SoCs, because Keystone uses the similar GPIO IP like Davinci. Keystone GPIO IP: supports:
- up to 32 GPIO lines;
- only unbanked irqs;

See Documentation:
Keystone - http://www.ti.com/lit/ug/sprugv1/sprugv1.pdf

This series based on:
https://git.kernel.org/cgit/linux/kernel/git/nsekhar/linux-davinci.git/log/?h=v3.14/gpio

Changes in v2:
- minor comments applied, no functional changes

v1: https://lkml.org/lkml/2013/12/12/366

Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Sekhar Nori <[email protected]>
Cc Santosh Shilimkar <[email protected]>

Grygorii Strashko (2):
gpio: davinci: don't create irq_domain in case of unbanked irqs
gpio: davinci: reuse for Keystone SoC

 .../devicetree/bindings/gpio/gpio-davinci.txt      |    4 +-
 drivers/gpio/gpio-davinci.c                        |   80 ++++++++++++++------
 2 files changed, 59 insertions(+), 25 deletions(-)
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v2 1/2 gpio: davinci: don't create irq_domain in case of unbanked irqs

The system may crash if:
- there are more then 1 bank
- unbanked irqs are enabled
- someone will call gpio_to_irq() for GPIO from bank2 or above

Hence, fix it by not creating irq_domain if unbanked irqs are enabled and correct gpio_to_irq_banked() to handle this properly.

Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Sekhar Nori <[email protected]>
---
 drivers/gpio/gpio-davinci.c |   34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)
drivers/gpio/gpio-davinci.c +19 -15
index 5d163c0..1b33806 100644
@@ -351,7 +351,10 @@ static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset)
 {
 	struct davinci_gpio_controller *d = chip2controller(chip);
 
-	return irq_create_mapping(d->irq_domain, d->chip.base + offset);
+	if (d->irq_domain)
+		return irq_create_mapping(d->irq_domain, d->chip.base + offset);
+	else
+		return -ENXIO;
 }
 
 static int gpio_to_irq_unbanked(struct gpio_chip *chip, unsigned offset)
@@ -429,7 +432,7 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
 	struct davinci_gpio_controller *chips = platform_get_drvdata(pdev);
 	struct davinci_gpio_platform_data *pdata = dev->platform_data;
 	struct davinci_gpio_regs __iomem *g;
-	struct irq_domain	*irq_domain;
+	struct irq_domain	*irq_domain = NULL;
 
 	ngpio = pdata->ngpio;
 	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
@@ -453,18 +456,20 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
 	}
 	clk_prepare_enable(clk);
 
-	irq = irq_alloc_descs(-1, 0, ngpio, 0);
-	if (irq < 0) {
-		dev_err(dev, "Couldn't allocate IRQ numbers\n");
-		return irq;
-	}
+	if (!pdata->gpio_unbanked) {
+		irq = irq_alloc_descs(-1, 0, ngpio, 0);
+		if (irq < 0) {
+			dev_err(dev, "Couldn't allocate IRQ numbers\n");
+			return -ENODEV;
+		}
 
-	irq_domain = irq_domain_add_legacy(NULL, ngpio, irq, 0,
-						&davinci_gpio_irq_ops,
-						chips);
-	if (!irq_domain) {
-		dev_err(dev, "Couldn't register an IRQ domain\n");
-		return -ENODEV;
+		irq_domain = irq_domain_add_legacy(NULL, ngpio, irq, 0,
+							&davinci_gpio_irq_ops,
+							chips);
+		if (!irq_domain) {
+			dev_err(dev, "Couldn't register an IRQ domain\n");
+			return -ENODEV;
+		}
 	}
 
 	/*
@@ -475,8 +480,7 @@ 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;
-		if (!pdata->gpio_unbanked)
-			chips[bank].irq_domain = irq_domain;
+		chips[bank].irq_domain = irq_domain;
 	}
 
 	/*
Signature · 1 line
1.7.9.5
Acked-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] gpio: davinci: don't create irq_domain in case of unbanked irqs

Quoted 8 lines · Grygorii Strashko

The system may crash if:
- there are more then 1 bank
- unbanked irqs are enabled
- someone will call gpio_to_irq() for GPIO from bank2 or above

Hence, fix it by not creating irq_domain if unbanked irqs are enabled and correct gpio_to_irq_banked() to handle this properly.

Quoted 6 lines
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Sekhar Nori <[email protected]>

Regards,
--Prabhakar Lad

#3 lore raw

Re: [PATCH v2 1/2] gpio: davinci: don't create irq_domain in case of unbanked irqs

In reply to Grygorii Strashko
Quoted 2 lines · Grygorii Strashko

The system may crash if:
- there are more then 1 bank

s/then/than

Quoted 45 lines

- unbanked irqs are enabled
- someone will call gpio_to_irq() for GPIO from bank2 or above

Hence, fix it by not creating irq_domain if unbanked irqs are enabled and correct gpio_to_irq_banked() to handle this properly.

Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Sekhar Nori <[email protected]>
---
 drivers/gpio/gpio-davinci.c |   34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)
drivers/gpio/gpio-davinci.c +5 -2
index 5d163c0..1b33806 100644
@@ -351,7 +351,10 @@ static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset)
 {
 	struct davinci_gpio_controller *d = chip2controller(chip);
 
-	return irq_create_mapping(d->irq_domain, d->chip.base + offset);
+	if (d->irq_domain)
+		return irq_create_mapping(d->irq_domain, d->chip.base + offset);
+	else
+		return -ENXIO;
 }
 
 static int gpio_to_irq_unbanked(struct gpio_chip *chip, unsigned offset)
@@ -429,7 +432,7 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
 	struct davinci_gpio_controller *chips = platform_get_drvdata(pdev);
 	struct davinci_gpio_platform_data *pdata = dev->platform_data;
 	struct davinci_gpio_regs __iomem *g;
-	struct irq_domain	*irq_domain;
+	struct irq_domain	*irq_domain = NULL;
 
 	ngpio = pdata->ngpio;
 	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
@@ -453,18 +456,20 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
 	}
 	clk_prepare_enable(clk);
 

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

Quoted 10 lines
drivers/gpio/gpio-davinci.c +5 -5
-	irq = irq_alloc_descs(-1, 0, ngpio, 0);
-	if (irq < 0) {
-		dev_err(dev, "Couldn't allocate IRQ numbers\n");
-		return irq;
-	}
+	if (!pdata->gpio_unbanked) {
+		irq = irq_alloc_descs(-1, 0, ngpio, 0);
+		if (irq < 0) {
+			dev_err(dev, "Couldn't allocate IRQ numbers\n");
+			return -ENODEV;

The code was correct before moving. Any objections to doing

			return irq;

instead?

Thanks,
Sekhar

#4 lore raw

Re: [PATCH v2 1/2] gpio: davinci: don't create irq_domain in case of unbanked irqs

Quoted 64 lines · Sekhar Nori
Quoted 2 lines · Grygorii Strashko

The system may crash if:
- there are more then 1 bank

s/then/than

Quoted 45 lines

- unbanked irqs are enabled
- someone will call gpio_to_irq() for GPIO from bank2 or above

Hence, fix it by not creating irq_domain if unbanked irqs are enabled and correct gpio_to_irq_banked() to handle this properly.

Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Sekhar Nori <[email protected]>
---
  drivers/gpio/gpio-davinci.c |   34 +++++++++++++++++++---------------
  1 file changed, 19 insertions(+), 15 deletions(-)
drivers/gpio/gpio-davinci.c +5 -2
index 5d163c0..1b33806 100644
@@ -351,7 +351,10 @@ static int gpio_to_irq_banked(struct gpio_chip *chip, unsigned offset)
  {
  	struct davinci_gpio_controller *d = chip2controller(chip);
 
-	return irq_create_mapping(d->irq_domain, d->chip.base + offset);
+	if (d->irq_domain)
+		return irq_create_mapping(d->irq_domain, d->chip.base + offset);
+	else
+		return -ENXIO;
  }
 
  static int gpio_to_irq_unbanked(struct gpio_chip *chip, unsigned offset)
@@ -429,7 +432,7 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
  	struct davinci_gpio_controller *chips = platform_get_drvdata(pdev);
  	struct davinci_gpio_platform_data *pdata = dev->platform_data;
  	struct davinci_gpio_regs __iomem *g;
-	struct irq_domain	*irq_domain;
+	struct irq_domain	*irq_domain = NULL;
 
  	ngpio = pdata->ngpio;
  	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
@@ -453,18 +456,20 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
  	}
  	clk_prepare_enable(clk);
 

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

Quoted 10 lines
drivers/gpio/gpio-davinci.c +5 -5
-	irq = irq_alloc_descs(-1, 0, ngpio, 0);
-	if (irq < 0) {
-		dev_err(dev, "Couldn't allocate IRQ numbers\n");
-		return irq;
-	}
+	if (!pdata->gpio_unbanked) {
+		irq = irq_alloc_descs(-1, 0, ngpio, 0);
+		if (irq < 0) {
+			dev_err(dev, "Couldn't allocate IRQ numbers\n");
+			return -ENODEV;

The code was correct before moving. Any objections to doing

Quoted 3 lines
			return irq;

instead?

This is mistake. I'll update. Thanks

Quoted 4 lines

Thanks,
Sekhar

#5 lore raw

PATCH v2 2/2 gpio: davinci: reuse for Keystone SoC

In reply to Grygorii Strashko

The similar GPIO HW block is used by keystone SoCs as in Davinci SoCs.
Hence, reuse Davinci GPIO driver for Keystone taking into account that Keystone contains ARM GIC IRQ controller which is implemented using IRQ Chip.

Documentation:

	http://www.ti.com/lit/ug/sprugv1/sprugv1.pdf
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Sekhar Nori <[email protected]>
---
 .../devicetree/bindings/gpio/gpio-davinci.txt      |    4 +-
 drivers/gpio/gpio-davinci.c                        |   46 ++++++++++++++++----
 2 files changed, 40 insertions(+), 10 deletions(-)
Documentation/devicetree/bindings/gpio/gpio-davinci.txt +2 -2
index a2e839d..4ce9862 100644
@@ -1,7 +1,7 @@
-Davinci GPIO controller bindings
+Davinci/Keystone GPIO controller bindings
 
 Required Properties:
-- compatible: should be "ti,dm6441-gpio"
+- compatible: should be "ti,dm6441-gpio", "ti,keystone-gpio"
 
 - reg: Physical base address of the controller and the size of memory mapped
        registers.
drivers/gpio/gpio-davinci.c +38 -8

82 lines not on this page · raw message

Signature · 1 line
1.7.9.5
Acked-by on v2 2/2
#6 lore raw

Re: [PATCH v2 2/2] gpio: davinci: reuse for Keystone SoC

Quoted 9 lines · Grygorii Strashko

The similar GPIO HW block is used by keystone SoCs as in Davinci SoCs.
Hence, reuse Davinci GPIO driver for Keystone taking into account that Keystone contains ARM GIC IRQ controller which is implemented using IRQ Chip.

Documentation:

        http://www.ti.com/lit/ug/sprugv1/sprugv1.pdf
Quoted 7 lines
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Sekhar Nori <[email protected]>
Cc devicetree at vger.kernel.org

Regards,
--Prabhakar Lad

#7 lore raw

Re: [PATCH v2 2/2] gpio: davinci: reuse for Keystone SoC

In reply to Grygorii Strashko

Rob,

Quoted 26 lines · Grygorii Strashko

The similar GPIO HW block is used by keystone SoCs as in Davinci SoCs.
Hence, reuse Davinci GPIO driver for Keystone taking into account that Keystone contains ARM GIC IRQ controller which is implemented using IRQ Chip.

Documentation:

	http://www.ti.com/lit/ug/sprugv1/sprugv1.pdf
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Sekhar Nori <[email protected]>
Cc devicetree at vger.kernel.org
---
 .../devicetree/bindings/gpio/gpio-davinci.txt      |    4 +-
 drivers/gpio/gpio-davinci.c                        |   46 ++++++++++++++++----
 2 files changed, 40 insertions(+), 10 deletions(-)
Documentation/devicetree/bindings/gpio/gpio-davinci.txt +0 -0
index a2e839d..4ce9862 100644

Documentation/devicetree/bindings/gpio/gpio-davinci.txt line 4

Quoted 6 lines
Documentation/devicetree/bindings/gpio/gpio-davinci.txt +2 -2
@@ -1,7 +1,7 @@
-Davinci GPIO controller bindings
+Davinci/Keystone GPIO controller bindings
 
 Required Properties:
-- compatible: should be "ti,dm6441-gpio"
+- compatible: should be "ti,dm6441-gpio", "ti,keystone-gpio"

Can I get your ack for this change? Its pretty trivial, but still..

Thanks,
Sekhar

#8 lore raw

Re: [PATCH v2 2/2] gpio: davinci: reuse for Keystone SoC

In reply to Grygorii Strashko
Quoted 72 lines · Grygorii Strashko

The similar GPIO HW block is used by keystone SoCs as in Davinci SoCs.
Hence, reuse Davinci GPIO driver for Keystone taking into account that Keystone contains ARM GIC IRQ controller which is implemented using IRQ Chip.

Documentation:

	http://www.ti.com/lit/ug/sprugv1/sprugv1.pdf
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Sekhar Nori <[email protected]>
Cc devicetree at vger.kernel.org
---
 .../devicetree/bindings/gpio/gpio-davinci.txt      |    4 +-
 drivers/gpio/gpio-davinci.c                        |   46 ++++++++++++++++----
 2 files changed, 40 insertions(+), 10 deletions(-)
Documentation/devicetree/bindings/gpio/gpio-davinci.txt +2 -2
index a2e839d..4ce9862 100644
@@ -1,7 +1,7 @@
-Davinci GPIO controller bindings
+Davinci/Keystone GPIO controller bindings
 
 Required Properties:
-- compatible: should be "ti,dm6441-gpio"
+- compatible: should be "ti,dm6441-gpio", "ti,keystone-gpio"
 
 - reg: Physical base address of the controller and the size of memory mapped
        registers.
drivers/gpio/gpio-davinci.c +22 -0
index 1b33806..38741cc 100644
@@ -413,6 +413,26 @@ static const struct irq_domain_ops davinci_gpio_irq_ops = {
 	.xlate = irq_domain_xlate_onetwocell,
 };
 
+static struct irq_chip *davinci_gpio_get_irq_chip(unsigned int irq)
+{
+	static struct irq_chip_type gpio_unbanked;
+
+	gpio_unbanked = *container_of(irq_get_chip(irq),
+				      struct irq_chip_type, chip);
+
+	return &gpio_unbanked.chip;
+};
+
+static struct irq_chip *keystone_gpio_get_irq_chip(unsigned int irq)
+{
+	static struct irq_chip gpio_unbanked;
+
+	gpio_unbanked = *irq_get_chip(irq);
+	return &gpio_unbanked;
+};
+
+static const struct of_device_id davinci_gpio_ids[];
+
 /*
  * NOTE:  for suspend/resume, probably best to make a platform_device with
  * suspend_late/resume_resume calls hooking into results of the set_wake()
@@ -433,6 +453,18 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
 	struct davinci_gpio_platform_data *pdata = dev->platform_data;
 	struct davinci_gpio_regs __iomem *g;
 	struct irq_domain	*irq_domain = NULL;
+	const struct of_device_id *match;
+	struct irq_chip *irq_chip;

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

Quoted 10 lines
drivers/gpio/gpio-davinci.c +10 -0
+	struct irq_chip *(*gpio_get_irq_chip)(unsigned int irq);
+
+	/*
+	 * Use davinci_gpio_get_irq_chip by default to handle non DT cases
+	 */
+	gpio_get_irq_chip = davinci_gpio_get_irq_chip;
+	match = of_match_device(of_match_ptr(davinci_gpio_ids),
+				dev);
+	if (match)
+		gpio_get_irq_chip = match->data;

This produces a sparse warning:

CHECK drivers/gpio/gpio-davinci.c
drivers/gpio/gpio-davinci.c:467:35: warning: incorrect type in assignment (different modifiers)
drivers/gpio/gpio-davinci.c:467:35: expected struct irq_chip *( *[assigned] gpio_get_irq_chip )( ... )
drivers/gpio/gpio-davinci.c:467:35: got void const *const data

Thanks,
Sekhar

#9 lore raw

Re: [PATCH v2 2/2] gpio: davinci: reuse for Keystone SoC

Quoted 86 lines · Sekhar Nori
Quoted 72 lines · Grygorii Strashko

The similar GPIO HW block is used by keystone SoCs as in Davinci SoCs.
Hence, reuse Davinci GPIO driver for Keystone taking into account that Keystone contains ARM GIC IRQ controller which is implemented using IRQ Chip.

Documentation:

	http://www.ti.com/lit/ug/sprugv1/sprugv1.pdf
Cc Linus Walleij <[email protected]>
Cc Alexandre Courbot <[email protected]>
Cc Sekhar Nori <[email protected]>
---
  .../devicetree/bindings/gpio/gpio-davinci.txt      |    4 +-
  drivers/gpio/gpio-davinci.c                        |   46 ++++++++++++++++----
  2 files changed, 40 insertions(+), 10 deletions(-)
Documentation/devicetree/bindings/gpio/gpio-davinci.txt +2 -2
index a2e839d..4ce9862 100644
@@ -1,7 +1,7 @@
-Davinci GPIO controller bindings
+Davinci/Keystone GPIO controller bindings
 
  Required Properties:
-- compatible: should be "ti,dm6441-gpio"
+- compatible: should be "ti,dm6441-gpio", "ti,keystone-gpio"
 
  - reg: Physical base address of the controller and the size of memory mapped
         registers.
drivers/gpio/gpio-davinci.c +22 -0
index 1b33806..38741cc 100644
@@ -413,6 +413,26 @@ static const struct irq_domain_ops davinci_gpio_irq_ops = {
  	.xlate = irq_domain_xlate_onetwocell,
  };
 
+static struct irq_chip *davinci_gpio_get_irq_chip(unsigned int irq)
+{
+	static struct irq_chip_type gpio_unbanked;
+
+	gpio_unbanked = *container_of(irq_get_chip(irq),
+				      struct irq_chip_type, chip);
+
+	return &gpio_unbanked.chip;
+};
+
+static struct irq_chip *keystone_gpio_get_irq_chip(unsigned int irq)
+{
+	static struct irq_chip gpio_unbanked;
+
+	gpio_unbanked = *irq_get_chip(irq);
+	return &gpio_unbanked;
+};
+
+static const struct of_device_id davinci_gpio_ids[];
+
  /*
   * NOTE:  for suspend/resume, probably best to make a platform_device with
   * suspend_late/resume_resume calls hooking into results of the set_wake()
@@ -433,6 +453,18 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
  	struct davinci_gpio_platform_data *pdata = dev->platform_data;
  	struct davinci_gpio_regs __iomem *g;
  	struct irq_domain	*irq_domain = NULL;
+	const struct of_device_id *match;
+	struct irq_chip *irq_chip;

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

Quoted 10 lines
drivers/gpio/gpio-davinci.c +10 -0
+	struct irq_chip *(*gpio_get_irq_chip)(unsigned int irq);
+
+	/*
+	 * Use davinci_gpio_get_irq_chip by default to handle non DT cases
+	 */
+	gpio_get_irq_chip = davinci_gpio_get_irq_chip;
+	match = of_match_device(of_match_ptr(davinci_gpio_ids),
+				dev);
+	if (match)
+		gpio_get_irq_chip = match->data;

This produces a sparse warning:

Quoted 5 lines

CHECK drivers/gpio/gpio-davinci.c
drivers/gpio/gpio-davinci.c:467:35: warning: incorrect type in assignment (different modifiers)
drivers/gpio/gpio-davinci.c:467:35: expected struct irq_chip *( *[assigned] gpio_get_irq_chip )( ... )
drivers/gpio/gpio-davinci.c:467:35: got void const *const data

I'll fix it, thanks.

Acked-by on the v2 series
#10 lore raw
In reply to Grygorii Strashko
Quoted 9 lines · Grygorii Strashko

This series is intended to update Davinci GPIO driver and reuse it for Keystone SoCs, because Keystone uses the similar GPIO IP like Davinci. Keystone GPIO IP: supports:
- up to 32 GPIO lines;
- only unbanked irqs;

See Documentation:
Keystone - http://www.ti.com/lit/ug/sprugv1/sprugv1.pdf

Quoted 7 lines

This series based on:
https://git.kernel.org/cgit/linux/kernel/git/nsekhar/linux-davinci.git/log/?h=v3.14/gpio

Changes in v2:
- minor comments applied, no functional changes

v1: https://lkml.org/lkml/2013/12/12/366

For this v2 series.

Expecting this to go in through the DaVinci tree!

Yours,
Linus Walleij

#11 lore raw
Quoted 15 lines · Linus Walleij
Quoted 12 lines · Grygorii Strashko

This series is intended to update Davinci GPIO driver and reuse it for Keystone SoCs, because Keystone uses the similar GPIO IP like Davinci. Keystone GPIO IP: supports:
- up to 32 GPIO lines;
- only unbanked irqs;

See Documentation:
Keystone - http://www.ti.com/lit/ug/sprugv1/sprugv1.pdf

This series based on:
https://git.kernel.org/cgit/linux/kernel/git/nsekhar/linux-davinci.git/log/?h=v3.14/gpio

Quoted 7 lines
Quoted 4 lines

Changes in v2:
- minor comments applied, no functional changes

v1: https://lkml.org/lkml/2013/12/12/366

Great !!

Quoted 4 lines

For this v2 series.

Expecting this to go in through the DaVinci tree!

Sekhar, Can you please include these to your DaVinci gpio branch ?

Regards,
Santosh