# \[PATCH 0/5\] gpio/omap: Cleanup and adaptation to Device Tree

- Subsystems: ARM PORT, GPIO SUBSYSTEM, OMAP GPIO DRIVER, OMAP2+ SUPPORT, OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS, THE REST
- Maintainers: Russell King, Linus Walleij, Bartosz Golaszewski, Grygorii Strashko, Santosh Shilimkar, Kevin Hilman, Aaro Koskinen, Andreas Kemnade, Kevin Hilman, Roger Quadros, Tony Lindgren, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Linus Torvalds
- Series: 5 patches touching 5 files, +280/-45
- Status: SUPERSEDED (Superseded by v2 posted 2012-02-24)
- Superseded by v2 (posted 2012-02-24).
- Revision v1 (2 revisions archived).
- List: linux-arm-kernel
- 43 messages, 10 authors
- Page: https://ratatoskr.run/linux-arm-kernel/2012/02/8057645/t

## \[PATCH 0/5\] gpio/omap: Cleanup and adaptation to Device Tree

- From: Benoit Cousson \<hidden\>
- Date: 2012-02-15 16:04:09 
- Message: https://ratatoskr.run/linux-arm-kernel/2012/02/8057645.md

```text
Hi Grant,

Here are a couple of GPIO cleanup + the DT adaptation patches.

This series is based on lo/master (a37cdd9) + for_3.4/dt_base branch to get
the needed cleanup and fixes for OMAP.

The interrupt controller support is using irq_domain_add_legacy for
the moment and will be updated next to use irqchip irq_domain.

It requires the irq_domain generalization and refinement series
available at:
  git://git.secretlab.ca/git/linux-2.6 irqdomain/next
  
But I guess you already know where to find it :-)

It requires as well Tarun's GPIO cleanup series available at:
  git://gitorious.org/~tarunkanti/omap-sw-develoment/tarunkantis-linux-omap-dev for_3.4/gpio_cleanup_fixes_v9

This series is available here for reference:
  git://git.kernel.org/pub/scm/linux/kernel/git/bcousson/linux-omap-dt.git for_3.4/dt_gpio

Regards,
Benoit


Benoit Cousson (5):
  gpio/omap: Remove bank->id information and misc cleanup
  gpio/omap: Use devm_ API and add request_mem_region
  gpio/omap: Add DT support to GPIO driver
  arm/dts: OMAP4: Add gpio nodes
  arm/dts: OMAP3: Add gpio nodes

 .../devicetree/bindings/gpio/gpio-omap.txt         |   30 ++++
 arch/arm/boot/dts/omap3.dtsi                       |   54 ++++++
 arch/arm/boot/dts/omap4.dtsi                       |   54 ++++++
 arch/arm/mach-omap2/gpio.c                         |    8 +-
 drivers/gpio/gpio-omap.c                           |  175 +++++++++++++++-----
 5 files changed, 278 insertions(+), 43 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-omap.txt
```

## \[PATCH 1/5\] gpio/omap: Remove bank-\>id information and misc cleanup

- From: Benoit Cousson \<hidden\>
- Date: 2012-02-15 16:04:10 
- Message: https://ratatoskr.run/linux-arm-kernel/2012/02/8057646.md

```text
The driver does not need anymore any id to identify the GPIO instance.
Remove every occurence of the bank->id inside the driver.

Remove two trailing spaces.
Add a dev variable for better readability in probe.
Remove unused variable bank->pbase.

Signed-off-by: Benoit Cousson <redacted>
Cc: Tarun Kanti DebBarma <redacted>
---
 drivers/gpio/gpio-omap.c |   23 +++++++++--------------
 1 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index f49bd6f..a0c3e03 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -50,7 +50,6 @@ struct gpio_regs {
 
 struct gpio_bank {
 	struct list_head node;
-	unsigned long pbase;
 	void __iomem *base;
 	u16 irq;
 	u16 virtual_irq_start;
@@ -77,7 +76,6 @@ struct gpio_bank {
 	int stride;
 	u32 width;
 	int context_loss_count;
-	u16 id;
 	int power_mode;
 	bool workaround_enabled;
 
@@ -155,7 +153,7 @@ static inline void _gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set)
 {
 	int l = __raw_readl(base + reg);
 
-	if (set) 
+	if (set)
 		l |= mask;
 	else
 		l &= ~mask;
@@ -495,7 +493,7 @@ static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
 	unsigned long flags;
 
 	if (bank->non_wakeup_gpios & gpio_bit) {
-		dev_err(bank->dev, 
+		dev_err(bank->dev,
 			"Unable to modify wakeup on non-wakeup GPIO%d\n", gpio);
 		return -EINVAL;
 	}
@@ -1048,37 +1046,36 @@ static void __devinit omap_gpio_chip_init(struct gpio_bank *bank)
 
 static int __devinit omap_gpio_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	struct omap_gpio_platform_data *pdata;
 	struct resource *res;
 	struct gpio_bank *bank;
 	int ret = 0;
 
-	if (!pdev->dev.platform_data) {
+	if (!dev->platform_data) {
 		ret = -EINVAL;
 		goto err_exit;
 	}
 
 	bank = kzalloc(sizeof(struct gpio_bank), GFP_KERNEL);
 	if (!bank) {
-		dev_err(&pdev->dev, "Memory alloc failed for gpio_bank\n");
+		dev_err(dev, "Memory alloc failed\n");
 		ret = -ENOMEM;
 		goto err_exit;
 	}
 
 	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
 	if (unlikely(!res)) {
-		dev_err(&pdev->dev, "GPIO Bank %i Invalid IRQ resource\n",
-				pdev->id);
+		dev_err(dev, "Invalid IRQ resource\n");
 		ret = -ENODEV;
 		goto err_free;
 	}
 
 	bank->irq = res->start;
-	bank->id = pdev->id;
 
 	pdata = pdev->dev.platform_data;
 	bank->virtual_irq_start = pdata->virtual_irq_start;
-	bank->dev = &pdev->dev;
+	bank->dev = dev;
 	bank->dbck_flag = pdata->dbck_flag;
 	bank->stride = pdata->bank_stride;
 	bank->width = pdata->bank_width;
@@ -1098,16 +1095,14 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
 	/* Static mapping, never released */
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (unlikely(!res)) {
-		dev_err(&pdev->dev, "GPIO Bank %i Invalid mem resource\n",
-				pdev->id);
+		dev_err(dev, "Invalid mem resource\n");
 		ret = -ENODEV;
 		goto err_free;
 	}
 
 	bank->base = ioremap(res->start, resource_size(res));
 	if (!bank->base) {
-		dev_err(&pdev->dev, "Could not ioremap gpio bank%i\n",
-				pdev->id);
+		dev_err(dev, "Could not ioremap\n");
 		ret = -ENOMEM;
 		goto err_free;
 	}
-- 
1.7.0.4
```

## \[PATCH 2/5\] gpio/omap: Use devm\_ API and add request\_mem\_region

- From: Benoit Cousson \<hidden\>
- Date: 2012-02-15 16:04:11 
- Message: https://ratatoskr.run/linux-arm-kernel/2012/02/8057647.md

```text
Replace the regular kzalloc and ioremap with the devm_ equivalent
to simplify error handling.

Add the missing devm_request_mem_region to reserve the region used
by the driver.

Signed-off-by: Benoit Cousson <redacted>
Cc: Tarun Kanti DebBarma <redacted>
---
 drivers/gpio/gpio-omap.c |   35 +++++++++++++++--------------------
 1 files changed, 15 insertions(+), 20 deletions(-)

diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index a0c3e03..c3a9dc8 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -19,7 +19,7 @@
 #include <linux/err.h>
 #include <linux/clk.h>
 #include <linux/io.h>
-#include <linux/slab.h>
+#include <linux/device.h>
 #include <linux/pm_runtime.h>
 #include <linux/pm.h>
 
@@ -1052,23 +1052,19 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
 	struct gpio_bank *bank;
 	int ret = 0;
 
-	if (!dev->platform_data) {
-		ret = -EINVAL;
-		goto err_exit;
-	}
+	if (!dev->platform_data)
+		return -EINVAL;
 
-	bank = kzalloc(sizeof(struct gpio_bank), GFP_KERNEL);
+	bank = devm_kzalloc(&pdev->dev, sizeof(struct gpio_bank), GFP_KERNEL);
 	if (!bank) {
 		dev_err(dev, "Memory alloc failed\n");
-		ret = -ENOMEM;
-		goto err_exit;
+		return -ENOMEM;
 	}
 
 	res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
 	if (unlikely(!res)) {
 		dev_err(dev, "Invalid IRQ resource\n");
-		ret = -ENODEV;
-		goto err_free;
+		return -ENODEV;
 	}
 
 	bank->irq = res->start;
@@ -1096,15 +1092,19 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (unlikely(!res)) {
 		dev_err(dev, "Invalid mem resource\n");
-		ret = -ENODEV;
-		goto err_free;
+		return -ENODEV;
+	}
+
+	if (!devm_request_mem_region(dev, res->start, resource_size(res),
+				     pdev->name)) {
+		dev_err(dev, "Region already claimed\n");
+		return -EBUSY;
 	}
 
-	bank->base = ioremap(res->start, resource_size(res));
+	bank->base = devm_ioremap(dev, res->start, resource_size(res));
 	if (!bank->base) {
 		dev_err(dev, "Could not ioremap\n");
-		ret = -ENOMEM;
-		goto err_free;
+		return -ENOMEM;
 	}
 
 	platform_set_drvdata(pdev, bank);
@@ -1125,11 +1125,6 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
 	list_add_tail(&bank->node, &omap_gpio_list);
 
 	return ret;
-
-err_free:
-	kfree(bank);
-err_exit:
-	return ret;
 }
 
 #ifdef CONFIG_ARCH_OMAP2PLUS
-- 
1.7.0.4
```

## \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Benoit Cousson \<hidden\>
- Date: 2012-02-15 16:04:12 
- Message: https://ratatoskr.run/linux-arm-kernel/2012/02/8057649.md

```text
Adapt the GPIO driver to retrieve information from a DT file.

Allocate the irq_base dynamically and rename bank->virtual_irq_start
to bank->irq_base.
Change irq_base type to int instead of u16 to match irq_alloc_descs
output.

Add documentation for GPIO properties specific to OMAP.

Signed-off-by: Benoit Cousson <redacted>
Cc: Tarun Kanti DebBarma <redacted>
---
 .../devicetree/bindings/gpio/gpio-omap.txt         |   30 +++++
 drivers/gpio/gpio-omap.c                           |  121 ++++++++++++++++++--
 2 files changed, 142 insertions(+), 9 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-omap.txt

diff --git a/Documentation/devicetree/bindings/gpio/gpio-omap.txt b/Documentation/devicetree/bindings/gpio/gpio-omap.txt
new file mode 100644
index 0000000..c1b3100
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/gpio-omap.txt
@@ -0,0 +1,30 @@
+OMAP GPIO controller bindings
+
+Required properties:
+- compatible:
+  - "ti,omap2-gpio" for OMAP2 controllers
+  - "ti,omap3-gpio" for OMAP3 controllers
+  - "ti,omap4-gpio" for OMAP4 controllers
+- #gpio-cells : Should be two.
+  - first cell is the pin number
+  - second cell is used to specify optional parameters (unused)
+- gpio-controller : Marks the device node as a GPIO controller.
+- #interrupt-cells : Should be one
+- interrupt-controller: Mark the device node as an interrupt controller
+
+OMAP specific properties:
+- ti,hwmods: Name of the hwmod associated to the GPIO:
+  "gpio<X>", <X> being the 1-based instance number from the HW spec
+
+
+Example:
+
+gpio4: gpio4 {
+    compatible = "ti,omap4-gpio";
+    ti,hwmods = "gpio4";
+    #gpio-cells = <2>;
+    gpio-controller;
+    #interrupt-cells = <1>;
+    interrupt-controller;
+};
+
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index c3a9dc8..bc2bd69 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -22,6 +22,9 @@
 #include <linux/device.h>
 #include <linux/pm_runtime.h>
 #include <linux/pm.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/irqdomain.h>
 
 #include <mach/hardware.h>
 #include <asm/irq.h>
@@ -52,7 +55,8 @@ struct gpio_bank {
 	struct list_head node;
 	void __iomem *base;
 	u16 irq;
-	u16 virtual_irq_start;
+	int irq_base;
+	struct irq_domain *domain;
 	u32 suspend_wakeup;
 	u32 saved_wakeup;
 	u32 non_wakeup_gpios;
@@ -669,7 +673,7 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
 		if (!isr)
 			break;
 
-		gpio_irq = bank->virtual_irq_start;
+		gpio_irq = bank->irq_base;
 		for (; isr != 0; isr >>= 1, gpio_irq++) {
 			gpio_index = GPIO_INDEX(bank, irq_to_gpio(gpio_irq));
 
@@ -915,7 +919,7 @@ static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
 	struct gpio_bank *bank;
 
 	bank = container_of(chip, struct gpio_bank, chip);
-	return bank->virtual_irq_start + offset;
+	return bank->irq_base + offset;
 }
 
 /*---------------------------------------------------------------------*/
@@ -1028,8 +1032,7 @@ static void __devinit omap_gpio_chip_init(struct gpio_bank *bank)
 
 	gpiochip_add(&bank->chip);
 
-	for (j = bank->virtual_irq_start;
-		     j < bank->virtual_irq_start + bank->width; j++) {
+	for (j = bank->irq_base; j < bank->irq_base + bank->width; j++) {
 		irq_set_lockdep_class(j, &gpio_lock_class);
 		irq_set_chip_data(j, bank);
 		if (bank->is_mpuio) {
@@ -1044,15 +1047,22 @@ static void __devinit omap_gpio_chip_init(struct gpio_bank *bank)
 	irq_set_handler_data(bank->irq, bank);
 }
 
+static const struct of_device_id omap_gpio_match[];
+
 static int __devinit omap_gpio_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
+	struct device_node *node = dev->of_node;
+	const struct of_device_id *match;
 	struct omap_gpio_platform_data *pdata;
 	struct resource *res;
 	struct gpio_bank *bank;
 	int ret = 0;
 
-	if (!dev->platform_data)
+	match = of_match_device(of_match_ptr(omap_gpio_match), dev);
+
+	pdata = match ? match->data : dev->platform_data;
+	if (!pdata)
 		return -EINVAL;
 
 	bank = devm_kzalloc(&pdev->dev, sizeof(struct gpio_bank), GFP_KERNEL);
@@ -1068,9 +1078,6 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
 	}
 
 	bank->irq = res->start;
-
-	pdata = pdev->dev.platform_data;
-	bank->virtual_irq_start = pdata->virtual_irq_start;
 	bank->dev = dev;
 	bank->dbck_flag = pdata->dbck_flag;
 	bank->stride = pdata->bank_stride;
@@ -1080,6 +1087,18 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
 	bank->loses_context = pdata->loses_context;
 	bank->get_context_loss_count = pdata->get_context_loss_count;
 	bank->regs = pdata->regs;
+#ifdef CONFIG_OF_GPIO
+	bank->chip.of_node = of_node_get(node);
+#endif
+
+	bank->irq_base = irq_alloc_descs(-1, 0, bank->width, 0);
+	if (bank->irq_base < 0) {
+		dev_err(dev, "Couldn't allocate IRQ numbers\n");
+		return -ENODEV;
+	}
+
+	bank->domain = irq_domain_add_legacy(node, bank->width, bank->irq_base,
+					     0, &irq_domain_simple_ops, NULL);
 
 	if (bank->regs->set_dataout && bank->regs->clr_dataout)
 		bank->set_dataout = _set_gpio_dataout_reg;
@@ -1387,11 +1406,95 @@ static const struct dev_pm_ops gpio_pm_ops = {
 									NULL)
 };
 
+#if defined(CONFIG_OF)
+static struct omap_gpio_reg_offs omap2_gpio_regs = {
+	.revision =		OMAP24XX_GPIO_REVISION,
+	.direction =		OMAP24XX_GPIO_OE,
+	.datain =		OMAP24XX_GPIO_DATAIN,
+	.dataout =		OMAP24XX_GPIO_DATAOUT,
+	.set_dataout =		OMAP24XX_GPIO_SETDATAOUT,
+	.clr_dataout =		OMAP24XX_GPIO_CLEARDATAOUT,
+	.irqstatus =		OMAP24XX_GPIO_IRQSTATUS1,
+	.irqstatus2 =		OMAP24XX_GPIO_IRQSTATUS2,
+	.irqenable =		OMAP24XX_GPIO_IRQENABLE1,
+	.irqenable2 =		OMAP24XX_GPIO_IRQENABLE2,
+	.set_irqenable =	OMAP24XX_GPIO_SETIRQENABLE1,
+	.clr_irqenable =	OMAP24XX_GPIO_CLEARIRQENABLE1,
+	.debounce =		OMAP24XX_GPIO_DEBOUNCE_VAL,
+	.debounce_en =		OMAP24XX_GPIO_DEBOUNCE_EN,
+	.ctrl =			OMAP24XX_GPIO_CTRL,
+	.wkup_en =		OMAP24XX_GPIO_WAKE_EN,
+	.leveldetect0 =		OMAP24XX_GPIO_LEVELDETECT0,
+	.leveldetect1 =		OMAP24XX_GPIO_LEVELDETECT1,
+	.risingdetect =		OMAP24XX_GPIO_RISINGDETECT,
+	.fallingdetect =	OMAP24XX_GPIO_FALLINGDETECT,
+};
+
+static struct omap_gpio_reg_offs omap4_gpio_regs = {
+	.revision =		OMAP4_GPIO_REVISION,
+	.direction =		OMAP4_GPIO_OE,
+	.datain =		OMAP4_GPIO_DATAIN,
+	.dataout =		OMAP4_GPIO_DATAOUT,
+	.set_dataout =		OMAP4_GPIO_SETDATAOUT,
+	.clr_dataout =		OMAP4_GPIO_CLEARDATAOUT,
+	.irqstatus =		OMAP4_GPIO_IRQSTATUS0,
+	.irqstatus2 =		OMAP4_GPIO_IRQSTATUS1,
+	.irqenable =		OMAP4_GPIO_IRQSTATUSSET0,
+	.irqenable2 =		OMAP4_GPIO_IRQSTATUSSET1,
+	.set_irqenable =	OMAP4_GPIO_IRQSTATUSSET0,
+	.clr_irqenable =	OMAP4_GPIO_IRQSTATUSCLR0,
+	.debounce =		OMAP4_GPIO_DEBOUNCINGTIME,
+	.debounce_en =		OMAP4_GPIO_DEBOUNCENABLE,
+	.ctrl =			OMAP4_GPIO_CTRL,
+	.wkup_en =		OMAP4_GPIO_IRQWAKEN0,
+	.leveldetect0 =		OMAP4_GPIO_LEVELDETECT0,
+	.leveldetect1 =		OMAP4_GPIO_LEVELDETECT1,
+	.risingdetect =		OMAP4_GPIO_RISINGDETECT,
+	.fallingdetect =	OMAP4_GPIO_FALLINGDETECT,
+};
+
+static struct omap_gpio_platform_data omap2_pdata = {
+	.regs = &omap2_gpio_regs,
+	.bank_width = 32,
+	.dbck_flag = false,
+};
+
+static struct omap_gpio_platform_data omap3_pdata = {
+	.regs = &omap2_gpio_regs,
+	.bank_width = 32,
+	.dbck_flag = true,
+};
+
+static struct omap_gpio_platform_data omap4_pdata = {
+	.regs = &omap4_gpio_regs,
+	.bank_width = 32,
+	.dbck_flag = true,
+};
+
+static const struct of_device_id omap_gpio_match[] = {
+	{
+		.compatible = "ti,omap4-gpio",
+		.data = &omap4_pdata,
+	},
+	{
+		.compatible = "ti,omap3-gpio",
+		.data = &omap3_pdata,
+	},
+	{
+		.compatible = "ti,omap2-gpio",
+		.data = &omap2_pdata,
+	},
+	{ },
+};
+MODULE_DEVICE_TABLE(of, omap_gpio_match);
+#endif
+
 static struct platform_driver omap_gpio_driver = {
 	.probe		= omap_gpio_probe,
 	.driver		= {
 		.name	= "omap_gpio",
 		.pm	= &gpio_pm_ops,
+		.of_match_table = of_match_ptr(omap_gpio_match),
 	},
 };
 
-- 
1.7.0.4
```

## \[PATCH 4/5\] arm/dts: OMAP4: Add gpio nodes

- From: Benoit Cousson \<hidden\>
- Date: 2012-02-15 16:04:13 
- Message: https://ratatoskr.run/linux-arm-kernel/2012/02/8057650.md

```text
Add the 6 GPIOs controller nodes present in OMAP4.

Remove gpio static device initialisation if DT is populated.

Signed-off-by: Benoit Cousson <redacted>
Cc: Grant Likely <redacted>
---
 arch/arm/boot/dts/omap4.dtsi |   54 ++++++++++++++++++++++++++++++++++++++++++
 arch/arm/mach-omap2/gpio.c   |    8 ++++-
 2 files changed, 60 insertions(+), 2 deletions(-)

diff --git a/arch/arm/boot/dts/omap4.dtsi b/arch/arm/boot/dts/omap4.dtsi
index 29f4589..4b81f03 100644
--- a/arch/arm/boot/dts/omap4.dtsi
+++ b/arch/arm/boot/dts/omap4.dtsi
@@ -104,6 +104,60 @@
 			      <0x48240100 0x0100>;
 		};
 
+		gpio1: gpio at 1 {
+			compatible = "ti,omap4-gpio";
+			ti,hwmods = "gpio1";
+			gpio-controller;
+			#gpio-cells = <2>;
+			interrupt-controller;
+			#interrupt-cells = <1>;
+		};
+
+		gpio2: gpio at 2 {
+			compatible = "ti,omap4-gpio";
+			ti,hwmods = "gpio2";
+			gpio-controller;
+			#gpio-cells = <2>;
+			interrupt-controller;
+			#interrupt-cells = <1>;
+		};
+
+		gpio3: gpio at 3 {
+			compatible = "ti,omap4-gpio";
+			ti,hwmods = "gpio3";
+			gpio-controller;
+			#gpio-cells = <2>;
+			interrupt-controller;
+			#interrupt-cells = <1>;
+		};
+
+		gpio4: gpio at 4 {
+			compatible = "ti,omap4-gpio";
+			ti,hwmods = "gpio4";
+			gpio-controller;
+			#gpio-cells = <2>;
+			interrupt-controller;
+			#interrupt-cells = <1>;
+		};
+
+		gpio5: gpio at 5 {
+			compatible = "ti,omap4-gpio";
+			ti,hwmods = "gpio5";
+			gpio-controller;
+			#gpio-cells = <2>;
+			interrupt-controller;
+			#interrupt-cells = <1>;
+		};
+
+		gpio6: gpio at 6 {
+			compatible = "ti,omap4-gpio";
+			ti,hwmods = "gpio6";
+			gpio-controller;
+			#gpio-cells = <2>;
+			interrupt-controller;
+			#interrupt-cells = <1>;
+		};
+
 		uart1: serial at 0x4806a000 {
 			compatible = "ti,omap4-uart";
 			ti,hwmods = "uart1";
diff --git a/arch/arm/mach-omap2/gpio.c b/arch/arm/mach-omap2/gpio.c
index 1e0b750..de22abd 100644
--- a/arch/arm/mach-omap2/gpio.c
+++ b/arch/arm/mach-omap2/gpio.c
@@ -20,6 +20,7 @@
 #include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/interrupt.h>
+#include <linux/of.h>
 
 #include <plat/omap_hwmod.h>
 #include <plat/omap_device.h>
@@ -146,7 +147,10 @@ static int omap2_gpio_dev_init(struct omap_hwmod *oh, void *unused)
  */
 static int __init omap2_gpio_init(void)
 {
-	return omap_hwmod_for_each_by_class("gpio", omap2_gpio_dev_init,
-						NULL);
+	/* If dtb is there, the devices will be created dynamically */
+	if (of_have_populated_dt())
+		return -ENODEV;
+
+	return omap_hwmod_for_each_by_class("gpio", omap2_gpio_dev_init, NULL);
 }
 postcore_initcall(omap2_gpio_init);
-- 
1.7.0.4
```

## \[PATCH 5/5\] arm/dts: OMAP3: Add gpio nodes

- From: Benoit Cousson \<hidden\>
- Date: 2012-02-15 16:04:14 
- Message: https://ratatoskr.run/linux-arm-kernel/2012/02/8057648.md

```text
Add the 6 GPIOs controller nodes present in OMAP3.

Signed-off-by: Benoit Cousson <redacted>
Cc: Grant Likely <redacted>
---
 arch/arm/boot/dts/omap3.dtsi |   54 ++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/arch/arm/boot/dts/omap3.dtsi b/arch/arm/boot/dts/omap3.dtsi
index ca37ba5..8eb181e 100644
--- a/arch/arm/boot/dts/omap3.dtsi
+++ b/arch/arm/boot/dts/omap3.dtsi
@@ -69,6 +69,60 @@
 			reg = <0x48200000 0x1000>;
 		};
 
+		gpio1: gpio at 1 {
+			compatible = "ti,omap3-gpio";
+			ti,hwmods = "gpio1";
+			gpio-controller;
+			#gpio-cells = <2>;
+			interrupt-controller;
+			#interrupt-cells = <1>;
+		};
+
+		gpio2: gpio at 2 {
+			compatible = "ti,omap3-gpio";
+			ti,hwmods = "gpio2";
+			gpio-controller;
+			#gpio-cells = <2>;
+			interrupt-controller;
+			#interrupt-cells = <1>;
+		};
+
+		gpio3: gpio at 3 {
+			compatible = "ti,omap3-gpio";
+			ti,hwmods = "gpio3";
+			gpio-controller;
+			#gpio-cells = <2>;
+			interrupt-controller;
+			#interrupt-cells = <1>;
+		};
+
+		gpio4: gpio at 4 {
+			compatible = "ti,omap3-gpio";
+			ti,hwmods = "gpio4";
+			gpio-controller;
+			#gpio-cells = <2>;
+			interrupt-controller;
+			#interrupt-cells = <1>;
+		};
+
+		gpio5: gpio at 5 {
+			compatible = "ti,omap3-gpio";
+			ti,hwmods = "gpio5";
+			gpio-controller;
+			#gpio-cells = <2>;
+			interrupt-controller;
+			#interrupt-cells = <1>;
+		};
+
+		gpio6: gpio at 6 {
+			compatible = "ti,omap3-gpio";
+			ti,hwmods = "gpio6";
+			gpio-controller;
+			#gpio-cells = <2>;
+			interrupt-controller;
+			#interrupt-cells = <1>;
+		};
+
 		uart1: serial at 0x4806a000 {
 			compatible = "ti,omap3-uart";
 			ti,hwmods = "uart1";
-- 
1.7.0.4
```

## Re: \[PATCH 2/5\] gpio/omap: Use devm\_ API and add request\_mem\_region

- From: DebBarma, Tarun Kanti \<hidden\>
- Date: 2012-02-16 05:41:52 
- Message: https://ratatoskr.run/linux-arm-kernel/2012/02/8057670.md

```text
Hi Benoit,

On Wed, Feb 15, 2012 at 9:34 PM, Benoit Cousson [ref] wrote:
> Replace the regular kzalloc and ioremap with the devm_ equivalent
> to simplify error handling.
>
> Add the missing devm_request_mem_region to reserve the region used
> by the driver.
>
> Signed-off-by: Benoit Cousson <redacted>
> Cc: Tarun Kanti DebBarma <redacted>
> ---
> ?drivers/gpio/gpio-omap.c | ? 35 +++++++++++++++--------------------
> ?1 files changed, 15 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
> index a0c3e03..c3a9dc8 100644
> --- a/drivers/gpio/gpio-omap.c
> +++ b/drivers/gpio/gpio-omap.c
> @@ -19,7 +19,7 @@
> ?#include <linux/err.h>
> ?#include <linux/clk.h>
> ?#include <linux/io.h>
> -#include <linux/slab.h>
> +#include <linux/device.h>
> ?#include <linux/pm_runtime.h>
> ?#include <linux/pm.h>
>
> @@ -1052,23 +1052,19 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
> ? ? ? ?struct gpio_bank *bank;
> ? ? ? ?int ret = 0;
>
> - ? ? ? if (!dev->platform_data) {
> - ? ? ? ? ? ? ? ret = -EINVAL;
> - ? ? ? ? ? ? ? goto err_exit;
> - ? ? ? }
> + ? ? ? if (!dev->platform_data)
> + ? ? ? ? ? ? ? return -EINVAL;
>
> - ? ? ? bank = kzalloc(sizeof(struct gpio_bank), GFP_KERNEL);
> + ? ? ? bank = devm_kzalloc(&pdev->dev, sizeof(struct gpio_bank), GFP_KERNEL);
> ? ? ? ?if (!bank) {
> ? ? ? ? ? ? ? ?dev_err(dev, "Memory alloc failed\n");
> - ? ? ? ? ? ? ? ret = -ENOMEM;
> - ? ? ? ? ? ? ? goto err_exit;
> + ? ? ? ? ? ? ? return -ENOMEM;
> ? ? ? ?}
>
> ? ? ? ?res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
> ? ? ? ?if (unlikely(!res)) {
> ? ? ? ? ? ? ? ?dev_err(dev, "Invalid IRQ resource\n");
> - ? ? ? ? ? ? ? ret = -ENODEV;
> - ? ? ? ? ? ? ? goto err_free;
> + ? ? ? ? ? ? ? return -ENODEV;
How is the memory allocated to 'bank' getting freed before return -ENODEV?

> ? ? ? ?}
>
> ? ? ? ?bank->irq = res->start;
> @@ -1096,15 +1092,19 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
> ? ? ? ?res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> ? ? ? ?if (unlikely(!res)) {
> ? ? ? ? ? ? ? ?dev_err(dev, "Invalid mem resource\n");
> - ? ? ? ? ? ? ? ret = -ENODEV;
> - ? ? ? ? ? ? ? goto err_free;
> + ? ? ? ? ? ? ? return -ENODEV;
And here?

> + ? ? ? }
> +
> + ? ? ? if (!devm_request_mem_region(dev, res->start, resource_size(res),
> + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?pdev->name)) {
> + ? ? ? ? ? ? ? dev_err(dev, "Region already claimed\n");
> + ? ? ? ? ? ? ? return -EBUSY;
> ? ? ? ?}
>
> - ? ? ? bank->base = ioremap(res->start, resource_size(res));
> + ? ? ? bank->base = devm_ioremap(dev, res->start, resource_size(res));
> ? ? ? ?if (!bank->base) {
> ? ? ? ? ? ? ? ?dev_err(dev, "Could not ioremap\n");
> - ? ? ? ? ? ? ? ret = -ENOMEM;
> - ? ? ? ? ? ? ? goto err_free;
> + ? ? ? ? ? ? ? return -ENOMEM;
And here?
--
Tarun
> ? ? ? ?}
>
> ? ? ? ?platform_set_drvdata(pdev, bank);
> @@ -1125,11 +1125,6 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
> ? ? ? ?list_add_tail(&bank->node, &omap_gpio_list);
>
> ? ? ? ?return ret;
> -
> -err_free:
> - ? ? ? kfree(bank);
> -err_exit:
> - ? ? ? return ret;
> ?}
>
> ?#ifdef CONFIG_ARCH_OMAP2PLUS
> --
> 1.7.0.4
>
```

## Re: \[PATCH 1/5\] gpio/omap: Remove bank-\>id information and misc cleanup

- From: DebBarma, Tarun Kanti \<hidden\>
- Date: 2012-02-16 05:53:47 
- Message: https://ratatoskr.run/linux-arm-kernel/2012/02/8057671.md

```text
On Wed, Feb 15, 2012 at 9:34 PM, Benoit Cousson [ref] wrote:
> The driver does not need anymore any id to identify the GPIO instance.
> Remove every occurence of the bank->id inside the driver.
>
> Remove two trailing spaces.
> Add a dev variable for better readability in probe.
> Remove unused variable bank->pbase.
>
> Signed-off-by: Benoit Cousson <redacted>
> Cc: Tarun Kanti DebBarma <redacted>
Looks fine.
If needed you can add my Acked-by:
--
Tarun

> ---
> ?drivers/gpio/gpio-omap.c | ? 23 +++++++++--------------
> ?1 files changed, 9 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
> index f49bd6f..a0c3e03 100644
> --- a/drivers/gpio/gpio-omap.c
> +++ b/drivers/gpio/gpio-omap.c
> @@ -50,7 +50,6 @@ struct gpio_regs {
>
> ?struct gpio_bank {
> ? ? ? ?struct list_head node;
> - ? ? ? unsigned long pbase;
> ? ? ? ?void __iomem *base;
> ? ? ? ?u16 irq;
> ? ? ? ?u16 virtual_irq_start;
> @@ -77,7 +76,6 @@ struct gpio_bank {
> ? ? ? ?int stride;
> ? ? ? ?u32 width;
> ? ? ? ?int context_loss_count;
> - ? ? ? u16 id;
> ? ? ? ?int power_mode;
> ? ? ? ?bool workaround_enabled;
>
> @@ -155,7 +153,7 @@ static inline void _gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set)
> ?{
> ? ? ? ?int l = __raw_readl(base + reg);
>
> - ? ? ? if (set)
> + ? ? ? if (set)
> ? ? ? ? ? ? ? ?l |= mask;
> ? ? ? ?else
> ? ? ? ? ? ? ? ?l &= ~mask;
> @@ -495,7 +493,7 @@ static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
> ? ? ? ?unsigned long flags;
>
> ? ? ? ?if (bank->non_wakeup_gpios & gpio_bit) {
> - ? ? ? ? ? ? ? dev_err(bank->dev,
> + ? ? ? ? ? ? ? dev_err(bank->dev,
> ? ? ? ? ? ? ? ? ? ? ? ?"Unable to modify wakeup on non-wakeup GPIO%d\n", gpio);
> ? ? ? ? ? ? ? ?return -EINVAL;
> ? ? ? ?}
> @@ -1048,37 +1046,36 @@ static void __devinit omap_gpio_chip_init(struct gpio_bank *bank)
>
> ?static int __devinit omap_gpio_probe(struct platform_device *pdev)
> ?{
> + ? ? ? struct device *dev = &pdev->dev;
> ? ? ? ?struct omap_gpio_platform_data *pdata;
> ? ? ? ?struct resource *res;
> ? ? ? ?struct gpio_bank *bank;
> ? ? ? ?int ret = 0;
>
> - ? ? ? if (!pdev->dev.platform_data) {
> + ? ? ? if (!dev->platform_data) {
> ? ? ? ? ? ? ? ?ret = -EINVAL;
> ? ? ? ? ? ? ? ?goto err_exit;
> ? ? ? ?}
>
> ? ? ? ?bank = kzalloc(sizeof(struct gpio_bank), GFP_KERNEL);
> ? ? ? ?if (!bank) {
> - ? ? ? ? ? ? ? dev_err(&pdev->dev, "Memory alloc failed for gpio_bank\n");
> + ? ? ? ? ? ? ? dev_err(dev, "Memory alloc failed\n");
> ? ? ? ? ? ? ? ?ret = -ENOMEM;
> ? ? ? ? ? ? ? ?goto err_exit;
> ? ? ? ?}
>
> ? ? ? ?res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
> ? ? ? ?if (unlikely(!res)) {
> - ? ? ? ? ? ? ? dev_err(&pdev->dev, "GPIO Bank %i Invalid IRQ resource\n",
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? pdev->id);
> + ? ? ? ? ? ? ? dev_err(dev, "Invalid IRQ resource\n");
> ? ? ? ? ? ? ? ?ret = -ENODEV;
> ? ? ? ? ? ? ? ?goto err_free;
> ? ? ? ?}
>
> ? ? ? ?bank->irq = res->start;
> - ? ? ? bank->id = pdev->id;
>
> ? ? ? ?pdata = pdev->dev.platform_data;
> ? ? ? ?bank->virtual_irq_start = pdata->virtual_irq_start;
> - ? ? ? bank->dev = &pdev->dev;
> + ? ? ? bank->dev = dev;
> ? ? ? ?bank->dbck_flag = pdata->dbck_flag;
> ? ? ? ?bank->stride = pdata->bank_stride;
> ? ? ? ?bank->width = pdata->bank_width;
> @@ -1098,16 +1095,14 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
> ? ? ? ?/* Static mapping, never released */
> ? ? ? ?res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> ? ? ? ?if (unlikely(!res)) {
> - ? ? ? ? ? ? ? dev_err(&pdev->dev, "GPIO Bank %i Invalid mem resource\n",
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? pdev->id);
> + ? ? ? ? ? ? ? dev_err(dev, "Invalid mem resource\n");
> ? ? ? ? ? ? ? ?ret = -ENODEV;
> ? ? ? ? ? ? ? ?goto err_free;
> ? ? ? ?}
>
> ? ? ? ?bank->base = ioremap(res->start, resource_size(res));
> ? ? ? ?if (!bank->base) {
> - ? ? ? ? ? ? ? dev_err(&pdev->dev, "Could not ioremap gpio bank%i\n",
> - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? pdev->id);
> + ? ? ? ? ? ? ? dev_err(dev, "Could not ioremap\n");
> ? ? ? ? ? ? ? ?ret = -ENOMEM;
> ? ? ? ? ? ? ? ?goto err_free;
> ? ? ? ?}
> --
> 1.7.0.4
>
```

## Re: \[PATCH 2/5\] gpio/omap: Use devm\_ API and add request\_mem\_region

- From: Grant Likely \<hidden\>
- Date: 2012-02-16 06:35:33 
- Message: https://ratatoskr.run/linux-arm-kernel/2012/02/8057673.md

```text
On Thu, Feb 16, 2012 at 11:11:52AM +0530, DebBarma, Tarun Kanti wrote:
> Hi Benoit,
> 
> On Wed, Feb 15, 2012 at 9:34 PM, Benoit Cousson [ref] wrote:
> > Replace the regular kzalloc and ioremap with the devm_ equivalent
> > to simplify error handling.
> >
> > Add the missing devm_request_mem_region to reserve the region used
> > by the driver.
> >
> > Signed-off-by: Benoit Cousson <redacted>
> > Cc: Tarun Kanti DebBarma <redacted>
> > ---
> > ?drivers/gpio/gpio-omap.c | ? 35 +++++++++++++++--------------------
> > ?1 files changed, 15 insertions(+), 20 deletions(-)
> >
> > diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
> > index a0c3e03..c3a9dc8 100644
> > --- a/drivers/gpio/gpio-omap.c
> > +++ b/drivers/gpio/gpio-omap.c
> > @@ -19,7 +19,7 @@
> > ?#include <linux/err.h>
> > ?#include <linux/clk.h>
> > ?#include <linux/io.h>
> > -#include <linux/slab.h>
> > +#include <linux/device.h>
> > ?#include <linux/pm_runtime.h>
> > ?#include <linux/pm.h>
> >
> > @@ -1052,23 +1052,19 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
> > ? ? ? ?struct gpio_bank *bank;
> > ? ? ? ?int ret = 0;
> >
> > - ? ? ? if (!dev->platform_data) {
> > - ? ? ? ? ? ? ? ret = -EINVAL;
> > - ? ? ? ? ? ? ? goto err_exit;
> > - ? ? ? }
> > + ? ? ? if (!dev->platform_data)
> > + ? ? ? ? ? ? ? return -EINVAL;
> >
> > - ? ? ? bank = kzalloc(sizeof(struct gpio_bank), GFP_KERNEL);
> > + ? ? ? bank = devm_kzalloc(&pdev->dev, sizeof(struct gpio_bank), GFP_KERNEL);
> > ? ? ? ?if (!bank) {
> > ? ? ? ? ? ? ? ?dev_err(dev, "Memory alloc failed\n");
> > - ? ? ? ? ? ? ? ret = -ENOMEM;
> > - ? ? ? ? ? ? ? goto err_exit;
> > + ? ? ? ? ? ? ? return -ENOMEM;
> > ? ? ? ?}
> >
> > ? ? ? ?res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
> > ? ? ? ?if (unlikely(!res)) {
> > ? ? ? ? ? ? ? ?dev_err(dev, "Invalid IRQ resource\n");
> > - ? ? ? ? ? ? ? ret = -ENODEV;
> > - ? ? ? ? ? ? ? goto err_free;
> > + ? ? ? ? ? ? ? return -ENODEV;
> How is the memory allocated to 'bank' getting freed before return -ENODEV?

The magic of devm_*() functions.  Anything allocated by those functions is
automatically freed on either probe failure or driver removal.

g.
```

## Re: \[PATCH 2/5\] gpio/omap: Use devm\_ API and add request\_mem\_region

- From: Shubhrajyoti \<hidden\>
- Date: 2012-02-16 06:37:14 
- Message: https://ratatoskr.run/linux-arm-kernel/2012/02/8057674.md

```text
On Thursday 16 February 2012 11:11 AM, DebBarma, Tarun Kanti wrote:
> Hi Benoit,
>
> On Wed, Feb 15, 2012 at 9:34 PM, Benoit Cousson [ref] wrote:
>> Replace the regular kzalloc and ioremap with the devm_ equivalent
>> to simplify error handling.
>>
>> Add the missing devm_request_mem_region to reserve the region used
>> by the driver.
>>
>> Signed-off-by: Benoit Cousson <redacted>
>> Cc: Tarun Kanti DebBarma <redacted>
>> ---
>>  drivers/gpio/gpio-omap.c |   35 +++++++++++++++--------------------
>>  1 files changed, 15 insertions(+), 20 deletions(-)
>>
>> diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
>> index a0c3e03..c3a9dc8 100644
>> --- a/drivers/gpio/gpio-omap.c
>> +++ b/drivers/gpio/gpio-omap.c
>> @@ -19,7 +19,7 @@
>>  #include <linux/err.h>
>>  #include <linux/clk.h>
>>  #include <linux/io.h>
>> -#include <linux/slab.h>
>> +#include <linux/device.h>
>>  #include <linux/pm_runtime.h>
>>  #include <linux/pm.h>
>>
>> @@ -1052,23 +1052,19 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
>>        struct gpio_bank *bank;
>>        int ret = 0;
>>
>> -       if (!dev->platform_data) {
>> -               ret = -EINVAL;
>> -               goto err_exit;
>> -       }
>> +       if (!dev->platform_data)
>> +               return -EINVAL;
>>
>> -       bank = kzalloc(sizeof(struct gpio_bank), GFP_KERNEL);
>> +       bank = devm_kzalloc(&pdev->dev, sizeof(struct gpio_bank), GFP_KERNEL);
>>        if (!bank) {
>>                dev_err(dev, "Memory alloc failed\n");
>> -               ret = -ENOMEM;
>> -               goto err_exit;
>> +               return -ENOMEM;
>>        }
>>
>>        res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
>>        if (unlikely(!res)) {
>>                dev_err(dev, "Invalid IRQ resource\n");
>> -               ret = -ENODEV;
>> -               goto err_free;
>> +               return -ENODEV;
> How is the memory allocated to 'bank' getting freed before return -ENODEV?

I think that may not be needed

See http://www.kernel.org/doc/htmldocs/device-drivers/API-devm-kzalloc.html



>>        }
>>
>>        bank->irq = res->start;
>> @@ -1096,15 +1092,19 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
>>        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>>        if (unlikely(!res)) {
>>                dev_err(dev, "Invalid mem resource\n");
>> -               ret = -ENODEV;
>> -               goto err_free;
>> +               return -ENODEV;
> And here?
>
>> +       }
>> +
>> +       if (!devm_request_mem_region(dev, res->start, resource_size(res),
>> +                                    pdev->name)) {
>> +               dev_err(dev, "Region already claimed\n");
>> +               return -EBUSY;
>>        }
>>
>> -       bank->base = ioremap(res->start, resource_size(res));
>> +       bank->base = devm_ioremap(dev, res->start, resource_size(res));
>>        if (!bank->base) {
>>                dev_err(dev, "Could not ioremap\n");
>> -               ret = -ENOMEM;
>> -               goto err_free;
>> +               return -ENOMEM;
> And here?
> --
> Tarun
>>        }
>>
>>        platform_set_drvdata(pdev, bank);
>> @@ -1125,11 +1125,6 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
>>        list_add_tail(&bank->node, &omap_gpio_list);
>>
>>        return ret;
>> -
>> -err_free:
>> -       kfree(bank);
>> -err_exit:
>> -       return ret;
>>  }
>>
>>  #ifdef CONFIG_ARCH_OMAP2PLUS
>> --
>> 1.7.0.4
>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo at vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
```

## Re: \[PATCH 2/5\] gpio/omap: Use devm\_ API and add request\_mem\_region

- From: DebBarma, Tarun Kanti \<hidden\>
- Date: 2012-02-16 07:11:16 
- Message: https://ratatoskr.run/linux-arm-kernel/2012/02/8057675.md

```text
On Thu, Feb 16, 2012 at 12:05 PM, Grant Likely
[ref] wrote:
> On Thu, Feb 16, 2012 at 11:11:52AM +0530, DebBarma, Tarun Kanti wrote:
>> Hi Benoit,
>>
>> On Wed, Feb 15, 2012 at 9:34 PM, Benoit Cousson [ref] wrote:
>> > Replace the regular kzalloc and ioremap with the devm_ equivalent
>> > to simplify error handling.
>> >
>> > Add the missing devm_request_mem_region to reserve the region used
>> > by the driver.
>> >
>> > Signed-off-by: Benoit Cousson <redacted>
>> > Cc: Tarun Kanti DebBarma <redacted>
>> > ---
>> > ?drivers/gpio/gpio-omap.c | ? 35 +++++++++++++++--------------------
>> > ?1 files changed, 15 insertions(+), 20 deletions(-)
>> >
>> > diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
>> > index a0c3e03..c3a9dc8 100644
>> > --- a/drivers/gpio/gpio-omap.c
>> > +++ b/drivers/gpio/gpio-omap.c
>> > @@ -19,7 +19,7 @@
>> > ?#include <linux/err.h>
>> > ?#include <linux/clk.h>
>> > ?#include <linux/io.h>
>> > -#include <linux/slab.h>
>> > +#include <linux/device.h>
>> > ?#include <linux/pm_runtime.h>
>> > ?#include <linux/pm.h>
>> >
>> > @@ -1052,23 +1052,19 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
>> > ? ? ? ?struct gpio_bank *bank;
>> > ? ? ? ?int ret = 0;
>> >
>> > - ? ? ? if (!dev->platform_data) {
>> > - ? ? ? ? ? ? ? ret = -EINVAL;
>> > - ? ? ? ? ? ? ? goto err_exit;
>> > - ? ? ? }
>> > + ? ? ? if (!dev->platform_data)
>> > + ? ? ? ? ? ? ? return -EINVAL;
>> >
>> > - ? ? ? bank = kzalloc(sizeof(struct gpio_bank), GFP_KERNEL);
>> > + ? ? ? bank = devm_kzalloc(&pdev->dev, sizeof(struct gpio_bank), GFP_KERNEL);
>> > ? ? ? ?if (!bank) {
>> > ? ? ? ? ? ? ? ?dev_err(dev, "Memory alloc failed\n");
>> > - ? ? ? ? ? ? ? ret = -ENOMEM;
>> > - ? ? ? ? ? ? ? goto err_exit;
>> > + ? ? ? ? ? ? ? return -ENOMEM;
>> > ? ? ? ?}
>> >
>> > ? ? ? ?res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
>> > ? ? ? ?if (unlikely(!res)) {
>> > ? ? ? ? ? ? ? ?dev_err(dev, "Invalid IRQ resource\n");
>> > - ? ? ? ? ? ? ? ret = -ENODEV;
>> > - ? ? ? ? ? ? ? goto err_free;
>> > + ? ? ? ? ? ? ? return -ENODEV;
>> How is the memory allocated to 'bank' getting freed before return -ENODEV?
>
> The magic of devm_*() functions. ?Anything allocated by those functions is
> automatically freed on either probe failure or driver removal.
OK, thanks.
--
Tarun
>
> g.
>
```

## Re: \[PATCH 2/5\] gpio/omap: Use devm\_ API and add request\_mem\_region

- From: Cousson, Benoit \<hidden\>
- Date: 2012-02-16 08:56:13 
- Message: https://ratatoskr.run/linux-arm-kernel/2012/02/8057676.md

```text
On 2/16/2012 7:37 AM, Shubhrajyoti wrote:
> On Thursday 16 February 2012 11:11 AM, DebBarma, Tarun Kanti wrote:
>> Hi Benoit,
>>
>> On Wed, Feb 15, 2012 at 9:34 PM, Benoit Cousson[ref]  wrote:
>>> Replace the regular kzalloc and ioremap with the devm_ equivalent
>>> to simplify error handling.
>>>
>>> Add the missing devm_request_mem_region to reserve the region used
>>> by the driver.
>>>
>>> Signed-off-by: Benoit Cousson<redacted>
>>> Cc: Tarun Kanti DebBarma<redacted>
>>> ---
>>>   drivers/gpio/gpio-omap.c |   35 +++++++++++++++--------------------
>>>   1 files changed, 15 insertions(+), 20 deletions(-)
>>>
>>> diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
>>> index a0c3e03..c3a9dc8 100644
>>> --- a/drivers/gpio/gpio-omap.c
>>> +++ b/drivers/gpio/gpio-omap.c
>>> @@ -19,7 +19,7 @@
>>>   #include<linux/err.h>
>>>   #include<linux/clk.h>
>>>   #include<linux/io.h>
>>> -#include<linux/slab.h>
>>> +#include<linux/device.h>
>>>   #include<linux/pm_runtime.h>
>>>   #include<linux/pm.h>
>>>
>>> @@ -1052,23 +1052,19 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
>>>         struct gpio_bank *bank;
>>>         int ret = 0;
>>>
>>> -       if (!dev->platform_data) {
>>> -               ret = -EINVAL;
>>> -               goto err_exit;
>>> -       }
>>> +       if (!dev->platform_data)
>>> +               return -EINVAL;
>>>
>>> -       bank = kzalloc(sizeof(struct gpio_bank), GFP_KERNEL);
>>> +       bank = devm_kzalloc(&pdev->dev, sizeof(struct gpio_bank), GFP_KERNEL);
>>>         if (!bank) {
>>>                 dev_err(dev, "Memory alloc failed\n");
>>> -               ret = -ENOMEM;
>>> -               goto err_exit;
>>> +               return -ENOMEM;
>>>         }
>>>
>>>         res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
>>>         if (unlikely(!res)) {
>>>                 dev_err(dev, "Invalid IRQ resource\n");
>>> -               ret = -ENODEV;
>>> -               goto err_free;
>>> +               return -ENODEV;
>> How is the memory allocated to 'bank' getting freed before return -ENODEV?
>
> I think that may not be needed

It is indeed not needed, and this is the whole point of that API 
compared to the regular kzalloc... and that's why it is highly 
recommended to switch to this kind of API.

Regards,
Benoit
```

## Re: \[PATCH 1/5\] gpio/omap: Remove bank-\>id information and misc cleanup

- From: Cousson, Benoit \<hidden\>
- Date: 2012-02-16 09:33:57 
- Message: https://ratatoskr.run/linux-arm-kernel/2012/02/8057679.md

```text
On 2/16/2012 6:53 AM, DebBarma, Tarun Kanti wrote:
> On Wed, Feb 15, 2012 at 9:34 PM, Benoit Cousson[ref]  wrote:
>> The driver does not need anymore any id to identify the GPIO instance.
>> Remove every occurence of the bank->id inside the driver.
>>
>> Remove two trailing spaces.
>> Add a dev variable for better readability in probe.
>> Remove unused variable bank->pbase.
>>
>> Signed-off-by: Benoit Cousson<redacted>
>> Cc: Tarun Kanti DebBarma<redacted>
> Looks fine.
> If needed you can add my Acked-by:

Thanks,
Benoit

> --
> Tarun
>
>> ---
>>   drivers/gpio/gpio-omap.c |   23 +++++++++--------------
>>   1 files changed, 9 insertions(+), 14 deletions(-)
>>
>> diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
>> index f49bd6f..a0c3e03 100644
>> --- a/drivers/gpio/gpio-omap.c
>> +++ b/drivers/gpio/gpio-omap.c
>> @@ -50,7 +50,6 @@ struct gpio_regs {
>>
>>   struct gpio_bank {
>>         struct list_head node;
>> -       unsigned long pbase;
>>         void __iomem *base;
>>         u16 irq;
>>         u16 virtual_irq_start;
>> @@ -77,7 +76,6 @@ struct gpio_bank {
>>         int stride;
>>         u32 width;
>>         int context_loss_count;
>> -       u16 id;
>>         int power_mode;
>>         bool workaround_enabled;
>>
>> @@ -155,7 +153,7 @@ static inline void _gpio_rmw(void __iomem *base, u32 reg, u32 mask, bool set)
>>   {
>>         int l = __raw_readl(base + reg);
>>
>> -       if (set)
>> +       if (set)
>>                 l |= mask;
>>         else
>>                 l&= ~mask;
>> @@ -495,7 +493,7 @@ static int _set_gpio_wakeup(struct gpio_bank *bank, int gpio, int enable)
>>         unsigned long flags;
>>
>>         if (bank->non_wakeup_gpios&  gpio_bit) {
>> -               dev_err(bank->dev,
>> +               dev_err(bank->dev,
>>                         "Unable to modify wakeup on non-wakeup GPIO%d\n", gpio);
>>                 return -EINVAL;
>>         }
>> @@ -1048,37 +1046,36 @@ static void __devinit omap_gpio_chip_init(struct gpio_bank *bank)
>>
>>   static int __devinit omap_gpio_probe(struct platform_device *pdev)
>>   {
>> +       struct device *dev =&pdev->dev;
>>         struct omap_gpio_platform_data *pdata;
>>         struct resource *res;
>>         struct gpio_bank *bank;
>>         int ret = 0;
>>
>> -       if (!pdev->dev.platform_data) {
>> +       if (!dev->platform_data) {
>>                 ret = -EINVAL;
>>                 goto err_exit;
>>         }
>>
>>         bank = kzalloc(sizeof(struct gpio_bank), GFP_KERNEL);
>>         if (!bank) {
>> -               dev_err(&pdev->dev, "Memory alloc failed for gpio_bank\n");
>> +               dev_err(dev, "Memory alloc failed\n");
>>                 ret = -ENOMEM;
>>                 goto err_exit;
>>         }
>>
>>         res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
>>         if (unlikely(!res)) {
>> -               dev_err(&pdev->dev, "GPIO Bank %i Invalid IRQ resource\n",
>> -                               pdev->id);
>> +               dev_err(dev, "Invalid IRQ resource\n");
>>                 ret = -ENODEV;
>>                 goto err_free;
>>         }
>>
>>         bank->irq = res->start;
>> -       bank->id = pdev->id;
>>
>>         pdata = pdev->dev.platform_data;
>>         bank->virtual_irq_start = pdata->virtual_irq_start;
>> -       bank->dev =&pdev->dev;
>> +       bank->dev = dev;
>>         bank->dbck_flag = pdata->dbck_flag;
>>         bank->stride = pdata->bank_stride;
>>         bank->width = pdata->bank_width;
>> @@ -1098,16 +1095,14 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
>>         /* Static mapping, never released */
>>         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>>         if (unlikely(!res)) {
>> -               dev_err(&pdev->dev, "GPIO Bank %i Invalid mem resource\n",
>> -                               pdev->id);
>> +               dev_err(dev, "Invalid mem resource\n");
>>                 ret = -ENODEV;
>>                 goto err_free;
>>         }
>>
>>         bank->base = ioremap(res->start, resource_size(res));
>>         if (!bank->base) {
>> -               dev_err(&pdev->dev, "Could not ioremap gpio bank%i\n",
>> -                               pdev->id);
>> +               dev_err(dev, "Could not ioremap\n");
>>                 ret = -ENOMEM;
>>                 goto err_free;
>>         }
>> --
>> 1.7.0.4
>>
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Rob Herring \<hidden\>
- Date: 2012-02-22 14:23:18 
- Message: https://ratatoskr.run/linux-arm-kernel/2012/02/8057742.md

```text
On 02/15/2012 10:04 AM, Benoit Cousson wrote:
> Adapt the GPIO driver to retrieve information from a DT file.
> 
> Allocate the irq_base dynamically and rename bank->virtual_irq_start
> to bank->irq_base.
> Change irq_base type to int instead of u16 to match irq_alloc_descs
> output.
> 
> Add documentation for GPIO properties specific to OMAP.
> 
> Signed-off-by: Benoit Cousson <redacted>
> Cc: Tarun Kanti DebBarma <redacted>

One comment below, but otherwise:

Acked-by: Rob Herring <redacted>

> ---
>  .../devicetree/bindings/gpio/gpio-omap.txt         |   30 +++++
>  drivers/gpio/gpio-omap.c                           |  121 ++++++++++++++++++--
>  2 files changed, 142 insertions(+), 9 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/gpio/gpio-omap.txt
> 
> diff --git a/Documentation/devicetree/bindings/gpio/gpio-omap.txt b/Documentation/devicetree/bindings/gpio/gpio-omap.txt
> new file mode 100644
> index 0000000..c1b3100
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/gpio/gpio-omap.txt
> @@ -0,0 +1,30 @@
> +OMAP GPIO controller bindings
> +
> +Required properties:
> +- compatible:
> +  - "ti,omap2-gpio" for OMAP2 controllers
> +  - "ti,omap3-gpio" for OMAP3 controllers
> +  - "ti,omap4-gpio" for OMAP4 controllers
> +- #gpio-cells : Should be two.
> +  - first cell is the pin number
> +  - second cell is used to specify optional parameters (unused)
> +- gpio-controller : Marks the device node as a GPIO controller.
> +- #interrupt-cells : Should be one

There's no level/edge settings for gpios?

> +- interrupt-controller: Mark the device node as an interrupt controller
> +
> +OMAP specific properties:
> +- ti,hwmods: Name of the hwmod associated to the GPIO:
> +  "gpio<X>", <X> being the 1-based instance number from the HW spec
> +
> +
> +Example:
> +
> +gpio4: gpio4 {
> +    compatible = "ti,omap4-gpio";
> +    ti,hwmods = "gpio4";
> +    #gpio-cells = <2>;
> +    gpio-controller;
> +    #interrupt-cells = <1>;
> +    interrupt-controller;
> +};
> +
> diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
> index c3a9dc8..bc2bd69 100644
> --- a/drivers/gpio/gpio-omap.c
> +++ b/drivers/gpio/gpio-omap.c
> @@ -22,6 +22,9 @@
>  #include <linux/device.h>
>  #include <linux/pm_runtime.h>
>  #include <linux/pm.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/irqdomain.h>
>  
>  #include <mach/hardware.h>
>  #include <asm/irq.h>
> @@ -52,7 +55,8 @@ struct gpio_bank {
>  	struct list_head node;
>  	void __iomem *base;
>  	u16 irq;
> -	u16 virtual_irq_start;
> +	int irq_base;
> +	struct irq_domain *domain;
>  	u32 suspend_wakeup;
>  	u32 saved_wakeup;
>  	u32 non_wakeup_gpios;
> @@ -669,7 +673,7 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
>  		if (!isr)
>  			break;
>  
> -		gpio_irq = bank->virtual_irq_start;
> +		gpio_irq = bank->irq_base;
>  		for (; isr != 0; isr >>= 1, gpio_irq++) {
>  			gpio_index = GPIO_INDEX(bank, irq_to_gpio(gpio_irq));
>  
> @@ -915,7 +919,7 @@ static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
>  	struct gpio_bank *bank;
>  
>  	bank = container_of(chip, struct gpio_bank, chip);
> -	return bank->virtual_irq_start + offset;
> +	return bank->irq_base + offset;
>  }
>  
>  /*---------------------------------------------------------------------*/
> @@ -1028,8 +1032,7 @@ static void __devinit omap_gpio_chip_init(struct gpio_bank *bank)
>  
>  	gpiochip_add(&bank->chip);
>  
> -	for (j = bank->virtual_irq_start;
> -		     j < bank->virtual_irq_start + bank->width; j++) {
> +	for (j = bank->irq_base; j < bank->irq_base + bank->width; j++) {
>  		irq_set_lockdep_class(j, &gpio_lock_class);
>  		irq_set_chip_data(j, bank);
>  		if (bank->is_mpuio) {
> @@ -1044,15 +1047,22 @@ static void __devinit omap_gpio_chip_init(struct gpio_bank *bank)
>  	irq_set_handler_data(bank->irq, bank);
>  }
>  
> +static const struct of_device_id omap_gpio_match[];
> +
>  static int __devinit omap_gpio_probe(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> +	struct device_node *node = dev->of_node;
> +	const struct of_device_id *match;
>  	struct omap_gpio_platform_data *pdata;
>  	struct resource *res;
>  	struct gpio_bank *bank;
>  	int ret = 0;
>  
> -	if (!dev->platform_data)
> +	match = of_match_device(of_match_ptr(omap_gpio_match), dev);
> +
> +	pdata = match ? match->data : dev->platform_data;
> +	if (!pdata)
>  		return -EINVAL;
>  
>  	bank = devm_kzalloc(&pdev->dev, sizeof(struct gpio_bank), GFP_KERNEL);
> @@ -1068,9 +1078,6 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
>  	}
>  
>  	bank->irq = res->start;
> -
> -	pdata = pdev->dev.platform_data;
> -	bank->virtual_irq_start = pdata->virtual_irq_start;
>  	bank->dev = dev;
>  	bank->dbck_flag = pdata->dbck_flag;
>  	bank->stride = pdata->bank_stride;
> @@ -1080,6 +1087,18 @@ static int __devinit omap_gpio_probe(struct platform_device *pdev)
>  	bank->loses_context = pdata->loses_context;
>  	bank->get_context_loss_count = pdata->get_context_loss_count;
>  	bank->regs = pdata->regs;
> +#ifdef CONFIG_OF_GPIO
> +	bank->chip.of_node = of_node_get(node);
> +#endif
> +
> +	bank->irq_base = irq_alloc_descs(-1, 0, bank->width, 0);
> +	if (bank->irq_base < 0) {
> +		dev_err(dev, "Couldn't allocate IRQ numbers\n");
> +		return -ENODEV;
> +	}
> +
> +	bank->domain = irq_domain_add_legacy(node, bank->width, bank->irq_base,
> +					     0, &irq_domain_simple_ops, NULL);
>  
>  	if (bank->regs->set_dataout && bank->regs->clr_dataout)
>  		bank->set_dataout = _set_gpio_dataout_reg;
> @@ -1387,11 +1406,95 @@ static const struct dev_pm_ops gpio_pm_ops = {
>  									NULL)
>  };
>  
> +#if defined(CONFIG_OF)
> +static struct omap_gpio_reg_offs omap2_gpio_regs = {
> +	.revision =		OMAP24XX_GPIO_REVISION,
> +	.direction =		OMAP24XX_GPIO_OE,
> +	.datain =		OMAP24XX_GPIO_DATAIN,
> +	.dataout =		OMAP24XX_GPIO_DATAOUT,
> +	.set_dataout =		OMAP24XX_GPIO_SETDATAOUT,
> +	.clr_dataout =		OMAP24XX_GPIO_CLEARDATAOUT,
> +	.irqstatus =		OMAP24XX_GPIO_IRQSTATUS1,
> +	.irqstatus2 =		OMAP24XX_GPIO_IRQSTATUS2,
> +	.irqenable =		OMAP24XX_GPIO_IRQENABLE1,
> +	.irqenable2 =		OMAP24XX_GPIO_IRQENABLE2,
> +	.set_irqenable =	OMAP24XX_GPIO_SETIRQENABLE1,
> +	.clr_irqenable =	OMAP24XX_GPIO_CLEARIRQENABLE1,
> +	.debounce =		OMAP24XX_GPIO_DEBOUNCE_VAL,
> +	.debounce_en =		OMAP24XX_GPIO_DEBOUNCE_EN,
> +	.ctrl =			OMAP24XX_GPIO_CTRL,
> +	.wkup_en =		OMAP24XX_GPIO_WAKE_EN,
> +	.leveldetect0 =		OMAP24XX_GPIO_LEVELDETECT0,
> +	.leveldetect1 =		OMAP24XX_GPIO_LEVELDETECT1,
> +	.risingdetect =		OMAP24XX_GPIO_RISINGDETECT,
> +	.fallingdetect =	OMAP24XX_GPIO_FALLINGDETECT,
> +};
> +
> +static struct omap_gpio_reg_offs omap4_gpio_regs = {
> +	.revision =		OMAP4_GPIO_REVISION,
> +	.direction =		OMAP4_GPIO_OE,
> +	.datain =		OMAP4_GPIO_DATAIN,
> +	.dataout =		OMAP4_GPIO_DATAOUT,
> +	.set_dataout =		OMAP4_GPIO_SETDATAOUT,
> +	.clr_dataout =		OMAP4_GPIO_CLEARDATAOUT,
> +	.irqstatus =		OMAP4_GPIO_IRQSTATUS0,
> +	.irqstatus2 =		OMAP4_GPIO_IRQSTATUS1,
> +	.irqenable =		OMAP4_GPIO_IRQSTATUSSET0,
> +	.irqenable2 =		OMAP4_GPIO_IRQSTATUSSET1,
> +	.set_irqenable =	OMAP4_GPIO_IRQSTATUSSET0,
> +	.clr_irqenable =	OMAP4_GPIO_IRQSTATUSCLR0,
> +	.debounce =		OMAP4_GPIO_DEBOUNCINGTIME,
> +	.debounce_en =		OMAP4_GPIO_DEBOUNCENABLE,
> +	.ctrl =			OMAP4_GPIO_CTRL,
> +	.wkup_en =		OMAP4_GPIO_IRQWAKEN0,
> +	.leveldetect0 =		OMAP4_GPIO_LEVELDETECT0,
> +	.leveldetect1 =		OMAP4_GPIO_LEVELDETECT1,
> +	.risingdetect =		OMAP4_GPIO_RISINGDETECT,
> +	.fallingdetect =	OMAP4_GPIO_FALLINGDETECT,
> +};
> +
> +static struct omap_gpio_platform_data omap2_pdata = {
> +	.regs = &omap2_gpio_regs,
> +	.bank_width = 32,
> +	.dbck_flag = false,
> +};
> +
> +static struct omap_gpio_platform_data omap3_pdata = {
> +	.regs = &omap2_gpio_regs,
> +	.bank_width = 32,
> +	.dbck_flag = true,
> +};
> +
> +static struct omap_gpio_platform_data omap4_pdata = {
> +	.regs = &omap4_gpio_regs,
> +	.bank_width = 32,
> +	.dbck_flag = true,
> +};
> +
> +static const struct of_device_id omap_gpio_match[] = {
> +	{
> +		.compatible = "ti,omap4-gpio",
> +		.data = &omap4_pdata,
> +	},
> +	{
> +		.compatible = "ti,omap3-gpio",
> +		.data = &omap3_pdata,
> +	},
> +	{
> +		.compatible = "ti,omap2-gpio",
> +		.data = &omap2_pdata,
> +	},
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(of, omap_gpio_match);
> +#endif
> +
>  static struct platform_driver omap_gpio_driver = {
>  	.probe		= omap_gpio_probe,
>  	.driver		= {
>  		.name	= "omap_gpio",
>  		.pm	= &gpio_pm_ops,
> +		.of_match_table = of_match_ptr(omap_gpio_match),
>  	},
>  };
>  
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Cousson, Benoit \<hidden\>
- Date: 2012-02-22 14:31:19 
- Message: https://ratatoskr.run/linux-arm-kernel/2012/02/8057743.md

```text
On 2/22/2012 3:23 PM, Rob Herring wrote:
> On 02/15/2012 10:04 AM, Benoit Cousson wrote:
>> Adapt the GPIO driver to retrieve information from a DT file.
>>
>> Allocate the irq_base dynamically and rename bank->virtual_irq_start
>> to bank->irq_base.
>> Change irq_base type to int instead of u16 to match irq_alloc_descs
>> output.
>>
>> Add documentation for GPIO properties specific to OMAP.
>>
>> Signed-off-by: Benoit Cousson<redacted>
>> Cc: Tarun Kanti DebBarma<redacted>
>
> One comment below, but otherwise:
>
> Acked-by: Rob Herring<redacted>
>
>> ---
>>   .../devicetree/bindings/gpio/gpio-omap.txt         |   30 +++++
>>   drivers/gpio/gpio-omap.c                           |  121 ++++++++++++++++++--
>>   2 files changed, 142 insertions(+), 9 deletions(-)
>>   create mode 100644 Documentation/devicetree/bindings/gpio/gpio-omap.txt
>>
>> diff --git a/Documentation/devicetree/bindings/gpio/gpio-omap.txt b/Documentation/devicetree/bindings/gpio/gpio-omap.txt
>> new file mode 100644
>> index 0000000..c1b3100
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/gpio/gpio-omap.txt
>> @@ -0,0 +1,30 @@
>> +OMAP GPIO controller bindings
>> +
>> +Required properties:
>> +- compatible:
>> +  - "ti,omap2-gpio" for OMAP2 controllers
>> +  - "ti,omap3-gpio" for OMAP3 controllers
>> +  - "ti,omap4-gpio" for OMAP4 controllers
>> +- #gpio-cells : Should be two.
>> +  - first cell is the pin number
>> +  - second cell is used to specify optional parameters (unused)
>> +- gpio-controller : Marks the device node as a GPIO controller.
>> +- #interrupt-cells : Should be one
>
> There's no level/edge settings for gpios?

That's a good question, because I was wondering as well :-)

I did no see how it was done in other GPIO implementation.

Benoit
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Rob Herring \<hidden\>
- Date: 2012-02-22 17:23:16 
- Message: https://ratatoskr.run/linux-arm-kernel/2012/02/8057762.md

```text
On 02/22/2012 08:31 AM, Cousson, Benoit wrote:
> On 2/22/2012 3:23 PM, Rob Herring wrote:
>> On 02/15/2012 10:04 AM, Benoit Cousson wrote:
>>> Adapt the GPIO driver to retrieve information from a DT file.
>>>
>>> Allocate the irq_base dynamically and rename bank->virtual_irq_start
>>> to bank->irq_base.
>>> Change irq_base type to int instead of u16 to match irq_alloc_descs
>>> output.
>>>
>>> Add documentation for GPIO properties specific to OMAP.
>>>
>>> Signed-off-by: Benoit Cousson<redacted>
>>> Cc: Tarun Kanti DebBarma<redacted>
>>
>> One comment below, but otherwise:
>>
>> Acked-by: Rob Herring<redacted>
>>
>>> ---
>>>   .../devicetree/bindings/gpio/gpio-omap.txt         |   30 +++++
>>>   drivers/gpio/gpio-omap.c                           |  121
>>> ++++++++++++++++++--
>>>   2 files changed, 142 insertions(+), 9 deletions(-)
>>>   create mode 100644
>>> Documentation/devicetree/bindings/gpio/gpio-omap.txt
>>>
>>> diff --git a/Documentation/devicetree/bindings/gpio/gpio-omap.txt
>>> b/Documentation/devicetree/bindings/gpio/gpio-omap.txt
>>> new file mode 100644
>>> index 0000000..c1b3100
>>> --- /dev/null
>>> +++ b/Documentation/devicetree/bindings/gpio/gpio-omap.txt
>>> @@ -0,0 +1,30 @@
>>> +OMAP GPIO controller bindings
>>> +
>>> +Required properties:
>>> +- compatible:
>>> +  - "ti,omap2-gpio" for OMAP2 controllers
>>> +  - "ti,omap3-gpio" for OMAP3 controllers
>>> +  - "ti,omap4-gpio" for OMAP4 controllers
>>> +- #gpio-cells : Should be two.
>>> +  - first cell is the pin number
>>> +  - second cell is used to specify optional parameters (unused)
>>> +- gpio-controller : Marks the device node as a GPIO controller.
>>> +- #interrupt-cells : Should be one
>>
>> There's no level/edge settings for gpios?
> 
> That's a good question, because I was wondering as well :-)
> 
> I did no see how it was done in other GPIO implementation.

There's not really a good example that I've found. Many gpio nodes don't
even have "interrupt-controller" set.

So if you have an irq_set_type function for gpio's, then you should have
2 cells.

Rob
```

## RE: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Stephen Warren \<hidden\>
- Date: 2012-02-22 18:29:43 
- Message: https://ratatoskr.run/linux-arm-kernel/2012/02/8057764.md

```text
Rob Herring wrote at Wednesday, February 22, 2012 10:23 AM:
> On 02/22/2012 08:31 AM, Cousson, Benoit wrote:
> > On 2/22/2012 3:23 PM, Rob Herring wrote:
> >> On 02/15/2012 10:04 AM, Benoit Cousson wrote:
> >>> Adapt the GPIO driver to retrieve information from a DT file.
> >>>
> >>> Allocate the irq_base dynamically and rename bank->virtual_irq_start
> >>> to bank->irq_base.
> >>> Change irq_base type to int instead of u16 to match irq_alloc_descs
> >>> output.
> >>>
> >>> Add documentation for GPIO properties specific to OMAP.
> >>>
> >>> Signed-off-by: Benoit Cousson<redacted>
> >>> Cc: Tarun Kanti DebBarma<redacted>
> >>
> >> One comment below, but otherwise:
> >>
> >> Acked-by: Rob Herring<redacted>
> >>
> >>> ---
> >>>   .../devicetree/bindings/gpio/gpio-omap.txt         |   30 +++++
> >>>   drivers/gpio/gpio-omap.c                           |  121
> >>> ++++++++++++++++++--
> >>>   2 files changed, 142 insertions(+), 9 deletions(-)
> >>>   create mode 100644
> >>> Documentation/devicetree/bindings/gpio/gpio-omap.txt
> >>>
> >>> diff --git a/Documentation/devicetree/bindings/gpio/gpio-omap.txt
> >>> b/Documentation/devicetree/bindings/gpio/gpio-omap.txt
> >>> new file mode 100644
> >>> index 0000000..c1b3100
> >>> --- /dev/null
> >>> +++ b/Documentation/devicetree/bindings/gpio/gpio-omap.txt
> >>> @@ -0,0 +1,30 @@
> >>> +OMAP GPIO controller bindings
> >>> +
> >>> +Required properties:
> >>> +- compatible:
> >>> +  - "ti,omap2-gpio" for OMAP2 controllers
> >>> +  - "ti,omap3-gpio" for OMAP3 controllers
> >>> +  - "ti,omap4-gpio" for OMAP4 controllers
> >>> +- #gpio-cells : Should be two.
> >>> +  - first cell is the pin number
> >>> +  - second cell is used to specify optional parameters (unused)
> >>> +- gpio-controller : Marks the device node as a GPIO controller.
> >>> +- #interrupt-cells : Should be one
> >>
> >> There's no level/edge settings for gpios?
> >
> > That's a good question, because I was wondering as well :-)
> >
> > I did no see how it was done in other GPIO implementation.
> 
> There's not really a good example that I've found. Many gpio nodes don't
> even have "interrupt-controller" set.
> 
> So if you have an irq_set_type function for gpio's, then you should have
> 2 cells.

Tegra's GPIO IRQ binding (gpio_nvidia.txt in linux-next at least) says:

- #interrupt-cells : Should be 2.
  The first cell is the GPIO number.
  The second cell is used to specify flags:
    bits[3:0] trigger type and level flags:
      1 = low-to-high edge triggered.
      2 = high-to-low edge triggered.
      4 = active high level-sensitive.
      8 = active low level-sensitive.
      Valid combinations are 1, 2, 3, 4, 8.

Presumably, that's what you meant.

-- 
nvpublic
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Cousson, Benoit \<hidden\>
- Date: 2012-02-24 15:30:16 
- Message: https://ratatoskr.run/linux-arm-kernel/2012/02/8057830.md

```text
On 2/22/2012 7:29 PM, Stephen Warren wrote:
> Rob Herring wrote at Wednesday, February 22, 2012 10:23 AM:
>> On 02/22/2012 08:31 AM, Cousson, Benoit wrote:
>>> On 2/22/2012 3:23 PM, Rob Herring wrote:
>>>> On 02/15/2012 10:04 AM, Benoit Cousson wrote:
>>>>> Adapt the GPIO driver to retrieve information from a DT file.
>>>>>
>>>>> Allocate the irq_base dynamically and rename bank->virtual_irq_start
>>>>> to bank->irq_base.
>>>>> Change irq_base type to int instead of u16 to match irq_alloc_descs
>>>>> output.
>>>>>
>>>>> Add documentation for GPIO properties specific to OMAP.
>>>>>
>>>>> Signed-off-by: Benoit Cousson<redacted>
>>>>> Cc: Tarun Kanti DebBarma<redacted>
>>>>
>>>> One comment below, but otherwise:
>>>>
>>>> Acked-by: Rob Herring<redacted>
>>>>
>>>>> ---
>>>>>    .../devicetree/bindings/gpio/gpio-omap.txt         |   30 +++++
>>>>>    drivers/gpio/gpio-omap.c                           |  121
>>>>> ++++++++++++++++++--
>>>>>    2 files changed, 142 insertions(+), 9 deletions(-)
>>>>>    create mode 100644
>>>>> Documentation/devicetree/bindings/gpio/gpio-omap.txt
>>>>>
>>>>> diff --git a/Documentation/devicetree/bindings/gpio/gpio-omap.txt
>>>>> b/Documentation/devicetree/bindings/gpio/gpio-omap.txt
>>>>> new file mode 100644
>>>>> index 0000000..c1b3100
>>>>> --- /dev/null
>>>>> +++ b/Documentation/devicetree/bindings/gpio/gpio-omap.txt
>>>>> @@ -0,0 +1,30 @@
>>>>> +OMAP GPIO controller bindings
>>>>> +
>>>>> +Required properties:
>>>>> +- compatible:
>>>>> +  - "ti,omap2-gpio" for OMAP2 controllers
>>>>> +  - "ti,omap3-gpio" for OMAP3 controllers
>>>>> +  - "ti,omap4-gpio" for OMAP4 controllers
>>>>> +- #gpio-cells : Should be two.
>>>>> +  - first cell is the pin number
>>>>> +  - second cell is used to specify optional parameters (unused)
>>>>> +- gpio-controller : Marks the device node as a GPIO controller.
>>>>> +- #interrupt-cells : Should be one
>>>>
>>>> There's no level/edge settings for gpios?
>>>
>>> That's a good question, because I was wondering as well :-)
>>>
>>> I did no see how it was done in other GPIO implementation.
>>
>> There's not really a good example that I've found. Many gpio nodes don't
>> even have "interrupt-controller" set.
>>
>> So if you have an irq_set_type function for gpio's, then you should have
>> 2 cells.

After checking the OMAP gpio code, I do have a gpio_irq_type and the 
GPIO do support the 4 types. I'm not sure yet about the combinations.

> Tegra's GPIO IRQ binding (gpio_nvidia.txt in linux-next at least) says:
>
> - #interrupt-cells : Should be 2.
>    The first cell is the GPIO number.
>    The second cell is used to specify flags:
>      bits[3:0] trigger type and level flags:
>        1 = low-to-high edge triggered.
>        2 = high-to-low edge triggered.
>        4 = active high level-sensitive.
>        8 = active low level-sensitive.
>        Valid combinations are 1, 2, 3, 4, 8.

Indeed, so I'll just copy / paste Tegra's binding...

Thanks,
Benoit
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Javier Martinez Canillas \<hidden\>
- Date: 2013-02-26 10:01:20 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068655.md

```text
On Fri, Feb 24, 2012 at 4:30 PM, Cousson, Benoit [ref] wrote:
> On 2/22/2012 7:29 PM, Stephen Warren wrote:
>>
>> Rob Herring wrote at Wednesday, February 22, 2012 10:23 AM:
>>>
>>> On 02/22/2012 08:31 AM, Cousson, Benoit wrote:
>>>>
>>>> On 2/22/2012 3:23 PM, Rob Herring wrote:
>>>>>
>>>>> On 02/15/2012 10:04 AM, Benoit Cousson wrote:
>>>>>>
>>>>>> Adapt the GPIO driver to retrieve information from a DT file.
>>>>>>
>>>>>> Allocate the irq_base dynamically and rename bank->virtual_irq_start
>>>>>> to bank->irq_base.
>>>>>> Change irq_base type to int instead of u16 to match irq_alloc_descs
>>>>>> output.
>>>>>>
>>>>>> Add documentation for GPIO properties specific to OMAP.
>>>>>>
>>>>>> Signed-off-by: Benoit Cousson<redacted>
>>>>>> Cc: Tarun Kanti DebBarma<redacted>
>>>>>
>>>>>
>>>>> One comment below, but otherwise:
>>>>>
>>>>> Acked-by: Rob Herring<redacted>
>>>>>
>>>>>> ---
>>>>>>    .../devicetree/bindings/gpio/gpio-omap.txt         |   30 +++++
>>>>>>    drivers/gpio/gpio-omap.c                           |  121
>>>>>> ++++++++++++++++++--
>>>>>>    2 files changed, 142 insertions(+), 9 deletions(-)
>>>>>>    create mode 100644
>>>>>> Documentation/devicetree/bindings/gpio/gpio-omap.txt
>>>>>>
>>>>>> diff --git a/Documentation/devicetree/bindings/gpio/gpio-omap.txt
>>>>>> b/Documentation/devicetree/bindings/gpio/gpio-omap.txt
>>>>>> new file mode 100644
>>>>>> index 0000000..c1b3100
>>>>>> --- /dev/null
>>>>>> +++ b/Documentation/devicetree/bindings/gpio/gpio-omap.txt
>>>>>> @@ -0,0 +1,30 @@
>>>>>> +OMAP GPIO controller bindings
>>>>>> +
>>>>>> +Required properties:
>>>>>> +- compatible:
>>>>>> +  - "ti,omap2-gpio" for OMAP2 controllers
>>>>>> +  - "ti,omap3-gpio" for OMAP3 controllers
>>>>>> +  - "ti,omap4-gpio" for OMAP4 controllers
>>>>>> +- #gpio-cells : Should be two.
>>>>>> +  - first cell is the pin number
>>>>>> +  - second cell is used to specify optional parameters (unused)
>>>>>> +- gpio-controller : Marks the device node as a GPIO controller.
>>>>>> +- #interrupt-cells : Should be one
>>>>>
>>>>>
>>>>> There's no level/edge settings for gpios?
>>>>
>>>>
>>>> That's a good question, because I was wondering as well :-)
>>>>
>>>> I did no see how it was done in other GPIO implementation.
>>>
>>>
>>> There's not really a good example that I've found. Many gpio nodes don't
>>> even have "interrupt-controller" set.
>>>
>>> So if you have an irq_set_type function for gpio's, then you should have
>>> 2 cells.
>
>
> After checking the OMAP gpio code, I do have a gpio_irq_type and the GPIO do
> support the 4 types. I'm not sure yet about the combinations.
>
>
>> Tegra's GPIO IRQ binding (gpio_nvidia.txt in linux-next at least) says:
>>
>> - #interrupt-cells : Should be 2.
>>    The first cell is the GPIO number.
>>    The second cell is used to specify flags:
>>      bits[3:0] trigger type and level flags:
>>        1 = low-to-high edge triggered.
>>        2 = high-to-low edge triggered.
>>        4 = active high level-sensitive.
>>        8 = active low level-sensitive.
>>        Valid combinations are 1, 2, 3, 4, 8.
>
>
> Indeed, so I'll just copy / paste Tegra's binding...
>
> Thanks,
> Benoit
>
>

Hello,

I was wondering if the level/edge settings for gpios is working on OMAP.

I'm adding DT support for an SMSC911x ethernet chip connected to the
GPMC for an OMAP3 SoC based board.

In the smsc911x driver probe function (smsc911x_drv_probe() in
drivers/net/ethernet/smsc/smsc911x.c), a call to request_irq() with
the flag IRQF_TRIGGER_LOW is needed because of the wiring on my board.

Reading the gpio-omap.txt documentation it says that #interrupt-cells
should be <2> and that a value of 8 is "active low level-sensitive".

So I tried this:

&gpmc {
	ethernet at 5,0 {
		pinctrl-names = "default";
		pinctrl-0 = <&smsc911x_pins>;
		compatible = "smsc,lan9221", "smsc,lan9115";
		reg = <5 0 0xff>; /* CS5 */
		interrupt-parent = <&gpio6>;
		interrupts = <16 8>; /* gpio line 176 */
		interrupt-names = "smsc911x irq";
		vmmc-supply = <&vddvario>;
		vmmc_aux-supply = <&vdd33a>;
		reg-io-width = <4>;

		smsc,save-mac-address;
      };
};

But in the smsc911x probe function:

irq_res->flags & IRQF_TRIGGER_MASK;

returns 0 which means that no trigger flags where set.

I took a look to the GPIOs device node definition on omap{3,4,5}.dtsi
and all look like this:

e.g from omap3.dtsi:

                gpio6: gpio at 49058000 {
                        compatible = "ti,omap3-gpio";
                        ti,hwmods = "gpio6";
                        gpio-controller;
                        #gpio-cells = <2>;
                        interrupt-controller;
                        #interrupt-cells = <1>;
                };

So, even when the documentation says that all the GPIO device nodes in
OMAP2+ should use a #interrupt-cells property value of <2>, they are
only using <1>. Changing that value to 2 makes hangs the kernel and it
does not boot.

This is not part of my dayjob and I'm working on this in my free time
so it would be great if someone can give me some pointers or at least
confirm that  this is a known issue so I can debug/fix/extend
drivers/gpio/gpio-omap.c to parse and pass the IRQF_TRIGGER_*  flags
to the IORESOURCE_IRQ resource structure.

Thanks a lot and best regards,
Javier
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Stephen Warren \<hidden\>
- Date: 2013-02-26 16:33:24 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068667.md

```text
On 02/26/2013 03:01 AM, Javier Martinez Canillas wrote:
...
> I was wondering if the level/edge settings for gpios is working on OMAP.
...
> Reading the gpio-omap.txt documentation it says that #interrupt-cells
> should be <2> and that a value of 8 is "active low level-sensitive".
> 
> So I tried this:
> 
> &gpmc {
> 	ethernet at 5,0 {
...
> 		interrupt-parent = <&gpio6>;
> 		interrupts = <16 8>; /* gpio line 176 */
> 		interrupt-names = "smsc911x irq";
...
> 
> But in the smsc911x probe function:
> 
> irq_res->flags & IRQF_TRIGGER_MASK;
> 
> returns 0 which means that no trigger flags where set.
> 
> I took a look to the GPIOs device node definition on omap{3,4,5}.dtsi
> and all look like this:
> 
> e.g from omap3.dtsi:
> 
>                 gpio6: gpio at 49058000 {
...
>                         #interrupt-cells = <1>;
...
> So, even when the documentation says that all the GPIO device nodes in
> OMAP2+ should use a #interrupt-cells property value of <2>, they are
> only using <1>. Changing that value to 2 makes hangs the kernel and it
> does not boot.

Take a look at what the OMAP GPIO driver is plugging in for the of_xlate
function; does it correctly handle the case where there are two cells?

Is there a default for the flags when no second cell is provided, such
that when you set #interrupt-cells to <2>, you're changing away from the
default and mis-configuring things?

And, did you check for any other interrupts hooked through the GPIO
module, for which you'll need to add the second cell into their GPIO
specifier throughout the entire device tree?
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Jon Hunter \<hidden\>
- Date: 2013-02-26 22:40:26 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068688.md

```text

On 02/26/2013 04:01 AM, Javier Martinez Canillas wrote:

[snip]

> I was wondering if the level/edge settings for gpios is working on OMAP.
> 
> I'm adding DT support for an SMSC911x ethernet chip connected to the
> GPMC for an OMAP3 SoC based board.
> 
> In the smsc911x driver probe function (smsc911x_drv_probe() in
> drivers/net/ethernet/smsc/smsc911x.c), a call to request_irq() with
> the flag IRQF_TRIGGER_LOW is needed because of the wiring on my board.
> 
> Reading the gpio-omap.txt documentation it says that #interrupt-cells
> should be <2> and that a value of 8 is "active low level-sensitive".
> 
> So I tried this:
> 
> &gpmc {
> 	ethernet at 5,0 {
> 		pinctrl-names = "default";
> 		pinctrl-0 = <&smsc911x_pins>;
> 		compatible = "smsc,lan9221", "smsc,lan9115";
> 		reg = <5 0 0xff>; /* CS5 */
> 		interrupt-parent = <&gpio6>;
> 		interrupts = <16 8>; /* gpio line 176 */
> 		interrupt-names = "smsc911x irq";
> 		vmmc-supply = <&vddvario>;
> 		vmmc_aux-supply = <&vdd33a>;
> 		reg-io-width = <4>;
> 
> 		smsc,save-mac-address;
>       };
> };

Are you requesting the gpio anywhere? If not then this is not going to
work as-is. This was discussed fairly recently [1] and the conclusion
was that the gpio needs to be requested before we can use as an interrupt.

I have not seen your latest smsc code for omap, but when you are
requesting the gpmc chip-select you should also request the gpio.

> But in the smsc911x probe function:
> 
> irq_res->flags & IRQF_TRIGGER_MASK;
> 
> returns 0 which means that no trigger flags where set.
> 
> I took a look to the GPIOs device node definition on omap{3,4,5}.dtsi
> and all look like this:
> 
> e.g from omap3.dtsi:
> 
>                 gpio6: gpio at 49058000 {
>                         compatible = "ti,omap3-gpio";
>                         ti,hwmods = "gpio6";
>                         gpio-controller;
>                         #gpio-cells = <2>;
>                         interrupt-controller;
>                         #interrupt-cells = <1>;
>                 };
> 
> So, even when the documentation says that all the GPIO device nodes in
> OMAP2+ should use a #interrupt-cells property value of <2>, they are
> only using <1>. Changing that value to 2 makes hangs the kernel and it
> does not boot.

I will need to take a look at that. Is your code available anywhere so I
can test?

Cheers
Jon

[1] http://permalink.gmane.org/gmane.linux.ports.arm.omap/92192
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Stephen Warren \<hidden\>
- Date: 2013-02-26 22:44:01 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068689.md

```text
On 02/26/2013 03:40 PM, Jon Hunter wrote:
> 
> On 02/26/2013 04:01 AM, Javier Martinez Canillas wrote:
> 
> [snip]
> 
>> I was wondering if the level/edge settings for gpios is working on OMAP.
>>
>> I'm adding DT support for an SMSC911x ethernet chip connected to the
>> GPMC for an OMAP3 SoC based board.
>>
>> In the smsc911x driver probe function (smsc911x_drv_probe() in
>> drivers/net/ethernet/smsc/smsc911x.c), a call to request_irq() with
>> the flag IRQF_TRIGGER_LOW is needed because of the wiring on my board.
>>
>> Reading the gpio-omap.txt documentation it says that #interrupt-cells
>> should be <2> and that a value of 8 is "active low level-sensitive".
>>
>> So I tried this:
>>
>> &gpmc {
>> 	ethernet at 5,0 {
>> 		pinctrl-names = "default";
>> 		pinctrl-0 = <&smsc911x_pins>;
>> 		compatible = "smsc,lan9221", "smsc,lan9115";
>> 		reg = <5 0 0xff>; /* CS5 */
>> 		interrupt-parent = <&gpio6>;
>> 		interrupts = <16 8>; /* gpio line 176 */
>> 		interrupt-names = "smsc911x irq";
>> 		vmmc-supply = <&vddvario>;
>> 		vmmc_aux-supply = <&vdd33a>;
>> 		reg-io-width = <4>;
>>
>> 		smsc,save-mac-address;
>>       };
>> };
> 
> Are you requesting the gpio anywhere? If not then this is not going to
> work as-is. This was discussed fairly recently [1] and the conclusion
> was that the gpio needs to be requested before we can use as an interrupt.

That seems wrong; the GPIO/IRQ driver should handle this internally. The
Ethernet driver shouldn't know/care whether the interrupt it's given is
some form of dedicated interrupt or a GPIO-based interrupt, and even if
it somehow did, there's no irq_to_gpio() any more, so the driver can't
tell which GPIO ID it should request, unless it's given yet another
property to represent this.
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Jon Hunter \<hidden\>
- Date: 2013-02-26 23:01:22 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068691.md

```text

On 02/26/2013 04:44 PM, Stephen Warren wrote:
> On 02/26/2013 03:40 PM, Jon Hunter wrote:
>>
>> On 02/26/2013 04:01 AM, Javier Martinez Canillas wrote:
>>
>> [snip]
>>
>>> I was wondering if the level/edge settings for gpios is working on OMAP.
>>>
>>> I'm adding DT support for an SMSC911x ethernet chip connected to the
>>> GPMC for an OMAP3 SoC based board.
>>>
>>> In the smsc911x driver probe function (smsc911x_drv_probe() in
>>> drivers/net/ethernet/smsc/smsc911x.c), a call to request_irq() with
>>> the flag IRQF_TRIGGER_LOW is needed because of the wiring on my board.
>>>
>>> Reading the gpio-omap.txt documentation it says that #interrupt-cells
>>> should be <2> and that a value of 8 is "active low level-sensitive".
>>>
>>> So I tried this:
>>>
>>> &gpmc {
>>> 	ethernet at 5,0 {
>>> 		pinctrl-names = "default";
>>> 		pinctrl-0 = <&smsc911x_pins>;
>>> 		compatible = "smsc,lan9221", "smsc,lan9115";
>>> 		reg = <5 0 0xff>; /* CS5 */
>>> 		interrupt-parent = <&gpio6>;
>>> 		interrupts = <16 8>; /* gpio line 176 */
>>> 		interrupt-names = "smsc911x irq";
>>> 		vmmc-supply = <&vddvario>;
>>> 		vmmc_aux-supply = <&vdd33a>;
>>> 		reg-io-width = <4>;
>>>
>>> 		smsc,save-mac-address;
>>>       };
>>> };
>>
>> Are you requesting the gpio anywhere? If not then this is not going to
>> work as-is. This was discussed fairly recently [1] and the conclusion
>> was that the gpio needs to be requested before we can use as an interrupt.
> 
> That seems wrong; the GPIO/IRQ driver should handle this internally. The
> Ethernet driver shouldn't know/care whether the interrupt it's given is
> some form of dedicated interrupt or a GPIO-based interrupt, and even if
> it somehow did, there's no irq_to_gpio() any more, so the driver can't
> tell which GPIO ID it should request, unless it's given yet another
> property to represent this.

I agree that ideally this should be handled internally. Did you read the
discussion on the thread that I referenced [1]? If you have any thoughts
we are open to ideas :-)

Cheers
Jon

[1] http://comments.gmane.org/gmane.linux.ports.arm.omap/92192
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Stephen Warren \<hidden\>
- Date: 2013-02-26 23:06:14 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068692.md

```text
On 02/26/2013 04:01 PM, Jon Hunter wrote:
> 
> On 02/26/2013 04:44 PM, Stephen Warren wrote:
>> On 02/26/2013 03:40 PM, Jon Hunter wrote:
>>>
>>> On 02/26/2013 04:01 AM, Javier Martinez Canillas wrote:
>>>
>>> [snip]
>>>
>>>> I was wondering if the level/edge settings for gpios is working on OMAP.
>>>>
>>>> I'm adding DT support for an SMSC911x ethernet chip connected to the
>>>> GPMC for an OMAP3 SoC based board.
>>>>
>>>> In the smsc911x driver probe function (smsc911x_drv_probe() in
>>>> drivers/net/ethernet/smsc/smsc911x.c), a call to request_irq() with
>>>> the flag IRQF_TRIGGER_LOW is needed because of the wiring on my board.
>>>>
>>>> Reading the gpio-omap.txt documentation it says that #interrupt-cells
>>>> should be <2> and that a value of 8 is "active low level-sensitive".
>>>>
>>>> So I tried this:
>>>>
>>>> &gpmc {
>>>> 	ethernet at 5,0 {
>>>> 		pinctrl-names = "default";
>>>> 		pinctrl-0 = <&smsc911x_pins>;
>>>> 		compatible = "smsc,lan9221", "smsc,lan9115";
>>>> 		reg = <5 0 0xff>; /* CS5 */
>>>> 		interrupt-parent = <&gpio6>;
>>>> 		interrupts = <16 8>; /* gpio line 176 */
>>>> 		interrupt-names = "smsc911x irq";
>>>> 		vmmc-supply = <&vddvario>;
>>>> 		vmmc_aux-supply = <&vdd33a>;
>>>> 		reg-io-width = <4>;
>>>>
>>>> 		smsc,save-mac-address;
>>>>       };
>>>> };
>>>
>>> Are you requesting the gpio anywhere? If not then this is not going to
>>> work as-is. This was discussed fairly recently [1] and the conclusion
>>> was that the gpio needs to be requested before we can use as an interrupt.
>>
>> That seems wrong; the GPIO/IRQ driver should handle this internally. The
>> Ethernet driver shouldn't know/care whether the interrupt it's given is
>> some form of dedicated interrupt or a GPIO-based interrupt, and even if
>> it somehow did, there's no irq_to_gpio() any more, so the driver can't
>> tell which GPIO ID it should request, unless it's given yet another
>> property to represent this.
> 
> I agree that ideally this should be handled internally. Did you read the
> discussion on the thread that I referenced [1]? If you have any thoughts
> we are open to ideas :-)
> 
> Cheers
> Jon
> 
> [1] http://comments.gmane.org/gmane.linux.ports.arm.omap/92192

Oh, when I clicked that link the first time, all I saw was the patch,
not any discussion. I guess it must have timed out finding the other
emails or something.

I disagree that the GPIO needs to be requested, and that a custom DT
property and associated code are needed for that; simply requesting the
IRQ should be enough to make everything work.

In the Tegra GPIO IRQ driver for example, the irq_set_type irq_chip op
goes and configures the base GPIO HW to enable the pin as a GPIO, just
like gpio_request() would. I imagine the OMAP driver can do whatever
similar action it needs.
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Jon Hunter \<hidden\>
- Date: 2013-02-26 23:08:44 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068693.md

```text

On 02/26/2013 04:01 AM, Javier Martinez Canillas wrote:

[snip]

> I was wondering if the level/edge settings for gpios is working on OMAP.
> 
> I'm adding DT support for an SMSC911x ethernet chip connected to the
> GPMC for an OMAP3 SoC based board.
> 
> In the smsc911x driver probe function (smsc911x_drv_probe() in
> drivers/net/ethernet/smsc/smsc911x.c), a call to request_irq() with
> the flag IRQF_TRIGGER_LOW is needed because of the wiring on my board.
> 
> Reading the gpio-omap.txt documentation it says that #interrupt-cells
> should be <2> and that a value of 8 is "active low level-sensitive".
> 
> So I tried this:
> 
> &gpmc {
> 	ethernet at 5,0 {
> 		pinctrl-names = "default";
> 		pinctrl-0 = <&smsc911x_pins>;
> 		compatible = "smsc,lan9221", "smsc,lan9115";
> 		reg = <5 0 0xff>; /* CS5 */
> 		interrupt-parent = <&gpio6>;
> 		interrupts = <16 8>; /* gpio line 176 */
> 		interrupt-names = "smsc911x irq";
> 		vmmc-supply = <&vddvario>;
> 		vmmc_aux-supply = <&vdd33a>;
> 		reg-io-width = <4>;

By the way, reg-io-width for omap does not look correct. The GPMC only
supports 8-bit or 16-bit devices IIRC. I believe all my omap boards use
16-bit.

Cheers
Jon
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Jon Hunter \<hidden\>
- Date: 2013-02-26 23:45:15 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068695.md

```text

On 02/26/2013 05:06 PM, Stephen Warren wrote:
> On 02/26/2013 04:01 PM, Jon Hunter wrote:
>>
>> On 02/26/2013 04:44 PM, Stephen Warren wrote:
>>> On 02/26/2013 03:40 PM, Jon Hunter wrote:
>>>>
>>>> On 02/26/2013 04:01 AM, Javier Martinez Canillas wrote:
>>>>
>>>> [snip]
>>>>
>>>>> I was wondering if the level/edge settings for gpios is working on OMAP.
>>>>>
>>>>> I'm adding DT support for an SMSC911x ethernet chip connected to the
>>>>> GPMC for an OMAP3 SoC based board.
>>>>>
>>>>> In the smsc911x driver probe function (smsc911x_drv_probe() in
>>>>> drivers/net/ethernet/smsc/smsc911x.c), a call to request_irq() with
>>>>> the flag IRQF_TRIGGER_LOW is needed because of the wiring on my board.
>>>>>
>>>>> Reading the gpio-omap.txt documentation it says that #interrupt-cells
>>>>> should be <2> and that a value of 8 is "active low level-sensitive".
>>>>>
>>>>> So I tried this:
>>>>>
>>>>> &gpmc {
>>>>> 	ethernet at 5,0 {
>>>>> 		pinctrl-names = "default";
>>>>> 		pinctrl-0 = <&smsc911x_pins>;
>>>>> 		compatible = "smsc,lan9221", "smsc,lan9115";
>>>>> 		reg = <5 0 0xff>; /* CS5 */
>>>>> 		interrupt-parent = <&gpio6>;
>>>>> 		interrupts = <16 8>; /* gpio line 176 */
>>>>> 		interrupt-names = "smsc911x irq";
>>>>> 		vmmc-supply = <&vddvario>;
>>>>> 		vmmc_aux-supply = <&vdd33a>;
>>>>> 		reg-io-width = <4>;
>>>>>
>>>>> 		smsc,save-mac-address;
>>>>>       };
>>>>> };
>>>>
>>>> Are you requesting the gpio anywhere? If not then this is not going to
>>>> work as-is. This was discussed fairly recently [1] and the conclusion
>>>> was that the gpio needs to be requested before we can use as an interrupt.
>>>
>>> That seems wrong; the GPIO/IRQ driver should handle this internally. The
>>> Ethernet driver shouldn't know/care whether the interrupt it's given is
>>> some form of dedicated interrupt or a GPIO-based interrupt, and even if
>>> it somehow did, there's no irq_to_gpio() any more, so the driver can't
>>> tell which GPIO ID it should request, unless it's given yet another
>>> property to represent this.
>>
>> I agree that ideally this should be handled internally. Did you read the
>> discussion on the thread that I referenced [1]? If you have any thoughts
>> we are open to ideas :-)
>>
>> Cheers
>> Jon
>>
>> [1] http://comments.gmane.org/gmane.linux.ports.arm.omap/92192
> 
> Oh, when I clicked that link the first time, all I saw was the patch,
> not any discussion. I guess it must have timed out finding the other
> emails or something.

Actually, I sent a slightly different link the 2nd time to ensure you
saw the thread. So my fault ;-)

> I disagree that the GPIO needs to be requested, and that a custom DT
> property and associated code are needed for that; simply requesting the
> IRQ should be enough to make everything work.
> 
> In the Tegra GPIO IRQ driver for example, the irq_set_type irq_chip op
> goes and configures the base GPIO HW to enable the pin as a GPIO, just
> like gpio_request() would. I imagine the OMAP driver can do whatever
> similar action it needs.

Yes that is similar to what the patch in the thread was attempting to
do, but this got shot down.

One issue I see is that by not calling gpio_request, then potentially
you could have someone request a gpio via gpio_request() and someone
trying to use it as an interrupt source via request_irq(). Now obviously
that represents a bug because there is only one physical gpio, but I
gather it is something we need to protect against.

Cheers
Jon
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Stephen Warren \<hidden\>
- Date: 2013-02-27 00:13:56 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068696.md

```text
On 02/26/2013 04:45 PM, Jon Hunter wrote:
> 
> On 02/26/2013 05:06 PM, Stephen Warren wrote:
>> On 02/26/2013 04:01 PM, Jon Hunter wrote:
>>>
>>> On 02/26/2013 04:44 PM, Stephen Warren wrote:
>>>> On 02/26/2013 03:40 PM, Jon Hunter wrote:
>>>>>
>>>>> On 02/26/2013 04:01 AM, Javier Martinez Canillas wrote:
>>>>>
>>>>> [snip]
>>>>>
>>>>>> I was wondering if the level/edge settings for gpios is working on OMAP.
>>>>>>
>>>>>> I'm adding DT support for an SMSC911x ethernet chip connected to the
>>>>>> GPMC for an OMAP3 SoC based board.
>>>>>>
>>>>>> In the smsc911x driver probe function (smsc911x_drv_probe() in
>>>>>> drivers/net/ethernet/smsc/smsc911x.c), a call to request_irq() with
>>>>>> the flag IRQF_TRIGGER_LOW is needed because of the wiring on my board.
>>>>>>
>>>>>> Reading the gpio-omap.txt documentation it says that #interrupt-cells
>>>>>> should be <2> and that a value of 8 is "active low level-sensitive".
>>>>>>
>>>>>> So I tried this:
>>>>>>
>>>>>> &gpmc {
>>>>>> 	ethernet at 5,0 {
>>>>>> 		pinctrl-names = "default";
>>>>>> 		pinctrl-0 = <&smsc911x_pins>;
>>>>>> 		compatible = "smsc,lan9221", "smsc,lan9115";
>>>>>> 		reg = <5 0 0xff>; /* CS5 */
>>>>>> 		interrupt-parent = <&gpio6>;
>>>>>> 		interrupts = <16 8>; /* gpio line 176 */
>>>>>> 		interrupt-names = "smsc911x irq";
>>>>>> 		vmmc-supply = <&vddvario>;
>>>>>> 		vmmc_aux-supply = <&vdd33a>;
>>>>>> 		reg-io-width = <4>;
>>>>>>
>>>>>> 		smsc,save-mac-address;
>>>>>>       };
>>>>>> };
>>>>>
>>>>> Are you requesting the gpio anywhere? If not then this is not going to
>>>>> work as-is. This was discussed fairly recently [1] and the conclusion
>>>>> was that the gpio needs to be requested before we can use as an interrupt.
>>>>
>>>> That seems wrong; the GPIO/IRQ driver should handle this internally. The
>>>> Ethernet driver shouldn't know/care whether the interrupt it's given is
>>>> some form of dedicated interrupt or a GPIO-based interrupt, and even if
>>>> it somehow did, there's no irq_to_gpio() any more, so the driver can't
>>>> tell which GPIO ID it should request, unless it's given yet another
>>>> property to represent this.
>>>
>>> I agree that ideally this should be handled internally. Did you read the
>>> discussion on the thread that I referenced [1]? If you have any thoughts
>>> we are open to ideas :-)
>>>
>>> Cheers
>>> Jon
>>>
>>> [1] http://comments.gmane.org/gmane.linux.ports.arm.omap/92192
>>
>> Oh, when I clicked that link the first time, all I saw was the patch,
>> not any discussion. I guess it must have timed out finding the other
>> emails or something.
> 
> Actually, I sent a slightly different link the 2nd time to ensure you
> saw the thread. So my fault ;-)
> 
>> I disagree that the GPIO needs to be requested, and that a custom DT
>> property and associated code are needed for that; simply requesting the
>> IRQ should be enough to make everything work.
>>
>> In the Tegra GPIO IRQ driver for example, the irq_set_type irq_chip op
>> goes and configures the base GPIO HW to enable the pin as a GPIO, just
>> like gpio_request() would. I imagine the OMAP driver can do whatever
>> similar action it needs.
> 
> Yes that is similar to what the patch in the thread was attempting to
> do, but this got shot down.
> 
> One issue I see is that by not calling gpio_request, then potentially
> you could have someone request a gpio via gpio_request() and someone
> trying to use it as an interrupt source via request_irq(). Now obviously
> that represents a bug because there is only one physical gpio, but I
> gather it is something we need to protect against.

I'm not sure it's really that much of an issue, but presumably the
solution is for a combined GPIO+IRQ driver to simply call gpio_request
internally from within some irq_chip function. It looks like struct
irq_chip doesn't have a request/free, but perhaps they could be added to
solve this?
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Jon Hunter \<hidden\>
- Date: 2013-02-27 01:07:36 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068699.md

```text

On 02/26/2013 06:13 PM, Stephen Warren wrote:
> On 02/26/2013 04:45 PM, Jon Hunter wrote:
>>
>> On 02/26/2013 05:06 PM, Stephen Warren wrote:
>>> On 02/26/2013 04:01 PM, Jon Hunter wrote:
>>>>
>>>> On 02/26/2013 04:44 PM, Stephen Warren wrote:
>>>>> On 02/26/2013 03:40 PM, Jon Hunter wrote:
>>>>>>
>>>>>> On 02/26/2013 04:01 AM, Javier Martinez Canillas wrote:
>>>>>>
>>>>>> [snip]
>>>>>>
>>>>>>> I was wondering if the level/edge settings for gpios is working on OMAP.
>>>>>>>
>>>>>>> I'm adding DT support for an SMSC911x ethernet chip connected to the
>>>>>>> GPMC for an OMAP3 SoC based board.
>>>>>>>
>>>>>>> In the smsc911x driver probe function (smsc911x_drv_probe() in
>>>>>>> drivers/net/ethernet/smsc/smsc911x.c), a call to request_irq() with
>>>>>>> the flag IRQF_TRIGGER_LOW is needed because of the wiring on my board.
>>>>>>>
>>>>>>> Reading the gpio-omap.txt documentation it says that #interrupt-cells
>>>>>>> should be <2> and that a value of 8 is "active low level-sensitive".
>>>>>>>
>>>>>>> So I tried this:
>>>>>>>
>>>>>>> &gpmc {
>>>>>>> 	ethernet at 5,0 {
>>>>>>> 		pinctrl-names = "default";
>>>>>>> 		pinctrl-0 = <&smsc911x_pins>;
>>>>>>> 		compatible = "smsc,lan9221", "smsc,lan9115";
>>>>>>> 		reg = <5 0 0xff>; /* CS5 */
>>>>>>> 		interrupt-parent = <&gpio6>;
>>>>>>> 		interrupts = <16 8>; /* gpio line 176 */
>>>>>>> 		interrupt-names = "smsc911x irq";
>>>>>>> 		vmmc-supply = <&vddvario>;
>>>>>>> 		vmmc_aux-supply = <&vdd33a>;
>>>>>>> 		reg-io-width = <4>;
>>>>>>>
>>>>>>> 		smsc,save-mac-address;
>>>>>>>       };
>>>>>>> };
>>>>>>
>>>>>> Are you requesting the gpio anywhere? If not then this is not going to
>>>>>> work as-is. This was discussed fairly recently [1] and the conclusion
>>>>>> was that the gpio needs to be requested before we can use as an interrupt.
>>>>>
>>>>> That seems wrong; the GPIO/IRQ driver should handle this internally. The
>>>>> Ethernet driver shouldn't know/care whether the interrupt it's given is
>>>>> some form of dedicated interrupt or a GPIO-based interrupt, and even if
>>>>> it somehow did, there's no irq_to_gpio() any more, so the driver can't
>>>>> tell which GPIO ID it should request, unless it's given yet another
>>>>> property to represent this.
>>>>
>>>> I agree that ideally this should be handled internally. Did you read the
>>>> discussion on the thread that I referenced [1]? If you have any thoughts
>>>> we are open to ideas :-)
>>>>
>>>> Cheers
>>>> Jon
>>>>
>>>> [1] http://comments.gmane.org/gmane.linux.ports.arm.omap/92192
>>>
>>> Oh, when I clicked that link the first time, all I saw was the patch,
>>> not any discussion. I guess it must have timed out finding the other
>>> emails or something.
>>
>> Actually, I sent a slightly different link the 2nd time to ensure you
>> saw the thread. So my fault ;-)
>>
>>> I disagree that the GPIO needs to be requested, and that a custom DT
>>> property and associated code are needed for that; simply requesting the
>>> IRQ should be enough to make everything work.
>>>
>>> In the Tegra GPIO IRQ driver for example, the irq_set_type irq_chip op
>>> goes and configures the base GPIO HW to enable the pin as a GPIO, just
>>> like gpio_request() would. I imagine the OMAP driver can do whatever
>>> similar action it needs.
>>
>> Yes that is similar to what the patch in the thread was attempting to
>> do, but this got shot down.
>>
>> One issue I see is that by not calling gpio_request, then potentially
>> you could have someone request a gpio via gpio_request() and someone
>> trying to use it as an interrupt source via request_irq(). Now obviously
>> that represents a bug because there is only one physical gpio, but I
>> gather it is something we need to protect against.
> 
> I'm not sure it's really that much of an issue, but presumably the
> solution is for a combined GPIO+IRQ driver to simply call gpio_request
> internally from within some irq_chip function. It looks like struct
> irq_chip doesn't have a request/free, but perhaps they could be added to
> solve this?

Yes I was wondering if we could do something like that. That would work,
may be that's what we should propose.

Thanks
Jon
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Javier Martinez Canillas \<hidden\>
- Date: 2013-02-27 03:33:48 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068703.md

```text
On Tue, Feb 26, 2013 at 11:40 PM, Jon Hunter [ref] wrote:
>
> On 02/26/2013 04:01 AM, Javier Martinez Canillas wrote:
>
> [snip]
>
>> I was wondering if the level/edge settings for gpios is working on OMAP.
>>
>> I'm adding DT support for an SMSC911x ethernet chip connected to the
>> GPMC for an OMAP3 SoC based board.
>>
>> In the smsc911x driver probe function (smsc911x_drv_probe() in
>> drivers/net/ethernet/smsc/smsc911x.c), a call to request_irq() with
>> the flag IRQF_TRIGGER_LOW is needed because of the wiring on my board.
>>
>> Reading the gpio-omap.txt documentation it says that #interrupt-cells
>> should be <2> and that a value of 8 is "active low level-sensitive".
>>
>> So I tried this:
>>
>> &gpmc {
>>       ethernet at 5,0 {
>>               pinctrl-names = "default";
>>               pinctrl-0 = <&smsc911x_pins>;
>>               compatible = "smsc,lan9221", "smsc,lan9115";
>>               reg = <5 0 0xff>; /* CS5 */
>>               interrupt-parent = <&gpio6>;
>>               interrupts = <16 8>; /* gpio line 176 */
>>               interrupt-names = "smsc911x irq";
>>               vmmc-supply = <&vddvario>;
>>               vmmc_aux-supply = <&vdd33a>;
>>               reg-io-width = <4>;
>>
>>               smsc,save-mac-address;
>>       };
>> };
>
> Are you requesting the gpio anywhere? If not then this is not going to
> work as-is. This was discussed fairly recently [1] and the conclusion
> was that the gpio needs to be requested before we can use as an interrupt.
>
> I have not seen your latest smsc code for omap, but when you are
> requesting the gpmc chip-select you should also request the gpio.
>

Yes, I realized that requesting the gpio was necessary so what I did
is to use the "regulator-fixed" optional property "gpio" and define
the GPIO used as an IRQ in a regulator used by the SMSC chip. So, I
have this on my board DT:

vddvario: regulator-vddvario {
	compatible = "regulator-fixed";
	regulator-name = "vddvario";
	regulator-always-on;
	gpio = <&gpio6 16 8>;  /* gpio line 176 */
	enable-active-high;
	gpio-open-drain;
	regulator-boot-on;
};

&gpmc {
	ethernet at 5,0 {
		pinctrl-names = "default";
		pinctrl-0 = <&smsc911x_pins>;
		compatible = "smsc,lan9221", "smsc,lan9115";
		reg = <5 0 0xff>;
		interrupt-parent = <&gpio6>;
		interrupts = <16 8>; /* gpio line 176 */
		interrupt-names = "smsc911x irq";
		vmmc-supply = <&vddvario>;
		vmmc_aux-supply = <&vdd33a>;
		reg-io-width = <4>;

		smsc,save-mac-address;
      };
};

That way a call to gpio_request_one() is made and the GPIO is requested.

This look a little hack-ish for me but I've seen this in other
DeviceTrees like omap4-sdp.dts so I thought it was a common DT
pattern.

>> But in the smsc911x probe function:
>>
>> irq_res->flags & IRQF_TRIGGER_MASK;
>>
>> returns 0 which means that no trigger flags where set.
>>
>> I took a look to the GPIOs device node definition on omap{3,4,5}.dtsi
>> and all look like this:
>>
>> e.g from omap3.dtsi:
>>
>>                 gpio6: gpio at 49058000 {
>>                         compatible = "ti,omap3-gpio";
>>                         ti,hwmods = "gpio6";
>>                         gpio-controller;
>>                         #gpio-cells = <2>;
>>                         interrupt-controller;
>>                         #interrupt-cells = <1>;
>>                 };
>>
>> So, even when the documentation says that all the GPIO device nodes in
>> OMAP2+ should use a #interrupt-cells property value of <2>, they are
>> only using <1>. Changing that value to 2 makes hangs the kernel and it
>> does not boot.
>
> I will need to take a look at that. Is your code available anywhere so I
> can test?
>

Of course, I pushed a gpmc-smsc911x branch to my github linux repository [2].

The branch is latest Linus' master + Benoit's linux-omap-dt/for_3.9/dts +
"ARM: OMAP2+: Prevent potential crash if GPMC probe fails" [3] +
"ARM: dts: OMAP3: Add GPMC controller" [4] + my patches:

Javier Martinez Canillas (5):
      ARM: dts: OMAP3: reduce GPMC mapped registers address space
      ARM: dts: OMAP3: make GPMC node compatible with simple-bus
      ARM: dts: OMAP3: add ranges property for GPMC chip-select 5
      ARM: dts: omap3-igep0020: Add SMSC911x LAN chip support
      smsc: smc911x: (HACK) force "active low" polarity for IRQ

The last patch is just an ugly hack that forces the IRQ flags to
active low level-sensitive so the SMSC911x IRQ is triggered on my
board (IGEPv2).

I just added for testing purposes since the omap3-gpio
interrupt-controller #interrupt-cells = <2> seems to not be working
and I can't pass this flag when defining the IRQ in the smsc911x
ethernet device node.

> Cheers
> Jon
>

Thanks a lot for your help and best regards,
Javier

[1]: http://permalink.gmane.org/gmane.linux.ports.arm.omap/92192
[2]: https://github.com/martinezjavier/linux.git
[3]: https://patchwork.kernel.org/patch/2118831/
[4]: https://patchwork.kernel.org/patch/2057111/
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Javier Martinez Canillas \<hidden\>
- Date: 2013-02-27 03:47:42 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068704.md

```text
On Wed, Feb 27, 2013 at 12:08 AM, Jon Hunter [ref] wrote:
>
> On 02/26/2013 04:01 AM, Javier Martinez Canillas wrote:
>
> [snip]
>
>> I was wondering if the level/edge settings for gpios is working on OMAP.
>>
>> I'm adding DT support for an SMSC911x ethernet chip connected to the
>> GPMC for an OMAP3 SoC based board.
>>
>> In the smsc911x driver probe function (smsc911x_drv_probe() in
>> drivers/net/ethernet/smsc/smsc911x.c), a call to request_irq() with
>> the flag IRQF_TRIGGER_LOW is needed because of the wiring on my board.
>>
>> Reading the gpio-omap.txt documentation it says that #interrupt-cells
>> should be <2> and that a value of 8 is "active low level-sensitive".
>>
>> So I tried this:
>>
>> &gpmc {
>>       ethernet at 5,0 {
>>               pinctrl-names = "default";
>>               pinctrl-0 = <&smsc911x_pins>;
>>               compatible = "smsc,lan9221", "smsc,lan9115";
>>               reg = <5 0 0xff>; /* CS5 */
>>               interrupt-parent = <&gpio6>;
>>               interrupts = <16 8>; /* gpio line 176 */
>>               interrupt-names = "smsc911x irq";
>>               vmmc-supply = <&vddvario>;
>>               vmmc_aux-supply = <&vdd33a>;
>>               reg-io-width = <4>;
>
> By the way, reg-io-width for omap does not look correct. The GPMC only
> supports 8-bit or 16-bit devices IIRC. I believe all my omap boards use
> 16-bit.
>

I thought that even when the GPMC was a 16-bit external memory
controller it could do some access adaptation to support 32-bit
devices.

By looking at the board files for others OMAP3 based boards
(board-{omap3evm,overo,zoom-debugboard}.c) most of them set the struct
omap_smsc911x_platform_data .flags member to SMSC911X_USE_32BIT.

And by looking at Documentation/devicetree/bindings/net/smsc911x.txt I
thought that the corresponding DT property for this flag was
"reg-io-width"

Anyway, I tried using both reg-io-width = <4> and reg-io-width = <2>.
The ethernet chip works with both of them and I don't see too much
difference in performance:

16-bit
round-trip min/avg/max = 0.611/0.738/0.946 ms

32-bit
round-trip min/avg/max = 0.519/0.690/0.976 ms

So, is your call ;-)

> Cheers
> Jon

Thanks a lot for your help,
Javier
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Javier Martinez Canillas \<hidden\>
- Date: 2013-02-27 03:57:38 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068705.md

```text
On Wed, Feb 27, 2013 at 2:07 AM, Jon Hunter [ref] wrote:
>
> On 02/26/2013 06:13 PM, Stephen Warren wrote:
>> On 02/26/2013 04:45 PM, Jon Hunter wrote:
>>>
>>> On 02/26/2013 05:06 PM, Stephen Warren wrote:
>>>> On 02/26/2013 04:01 PM, Jon Hunter wrote:
>>>>>
>>>>> On 02/26/2013 04:44 PM, Stephen Warren wrote:
>>>>>> On 02/26/2013 03:40 PM, Jon Hunter wrote:
>>>>>>>
>>>>>>> On 02/26/2013 04:01 AM, Javier Martinez Canillas wrote:
>>>>>>>
>>>>>>> [snip]
>>>>>>>
>>>>>>>> I was wondering if the level/edge settings for gpios is working on OMAP.
>>>>>>>>
>>>>>>>> I'm adding DT support for an SMSC911x ethernet chip connected to the
>>>>>>>> GPMC for an OMAP3 SoC based board.
>>>>>>>>
>>>>>>>> In the smsc911x driver probe function (smsc911x_drv_probe() in
>>>>>>>> drivers/net/ethernet/smsc/smsc911x.c), a call to request_irq() with
>>>>>>>> the flag IRQF_TRIGGER_LOW is needed because of the wiring on my board.
>>>>>>>>
>>>>>>>> Reading the gpio-omap.txt documentation it says that #interrupt-cells
>>>>>>>> should be <2> and that a value of 8 is "active low level-sensitive".
>>>>>>>>
>>>>>>>> So I tried this:
>>>>>>>>
>>>>>>>> &gpmc {
>>>>>>>>         ethernet at 5,0 {
>>>>>>>>                 pinctrl-names = "default";
>>>>>>>>                 pinctrl-0 = <&smsc911x_pins>;
>>>>>>>>                 compatible = "smsc,lan9221", "smsc,lan9115";
>>>>>>>>                 reg = <5 0 0xff>; /* CS5 */
>>>>>>>>                 interrupt-parent = <&gpio6>;
>>>>>>>>                 interrupts = <16 8>; /* gpio line 176 */
>>>>>>>>                 interrupt-names = "smsc911x irq";
>>>>>>>>                 vmmc-supply = <&vddvario>;
>>>>>>>>                 vmmc_aux-supply = <&vdd33a>;
>>>>>>>>                 reg-io-width = <4>;
>>>>>>>>
>>>>>>>>                 smsc,save-mac-address;
>>>>>>>>       };
>>>>>>>> };
>>>>>>>
>>>>>>> Are you requesting the gpio anywhere? If not then this is not going to
>>>>>>> work as-is. This was discussed fairly recently [1] and the conclusion
>>>>>>> was that the gpio needs to be requested before we can use as an interrupt.
>>>>>>
>>>>>> That seems wrong; the GPIO/IRQ driver should handle this internally. The
>>>>>> Ethernet driver shouldn't know/care whether the interrupt it's given is
>>>>>> some form of dedicated interrupt or a GPIO-based interrupt, and even if
>>>>>> it somehow did, there's no irq_to_gpio() any more, so the driver can't
>>>>>> tell which GPIO ID it should request, unless it's given yet another
>>>>>> property to represent this.
>>>>>
>>>>> I agree that ideally this should be handled internally. Did you read the
>>>>> discussion on the thread that I referenced [1]? If you have any thoughts
>>>>> we are open to ideas :-)
>>>>>
>>>>> Cheers
>>>>> Jon
>>>>>
>>>>> [1] http://comments.gmane.org/gmane.linux.ports.arm.omap/92192
>>>>
>>>> Oh, when I clicked that link the first time, all I saw was the patch,
>>>> not any discussion. I guess it must have timed out finding the other
>>>> emails or something.
>>>
>>> Actually, I sent a slightly different link the 2nd time to ensure you
>>> saw the thread. So my fault ;-)
>>>
>>>> I disagree that the GPIO needs to be requested, and that a custom DT
>>>> property and associated code are needed for that; simply requesting the
>>>> IRQ should be enough to make everything work.
>>>>
>>>> In the Tegra GPIO IRQ driver for example, the irq_set_type irq_chip op
>>>> goes and configures the base GPIO HW to enable the pin as a GPIO, just
>>>> like gpio_request() would. I imagine the OMAP driver can do whatever
>>>> similar action it needs.
>>>
>>> Yes that is similar to what the patch in the thread was attempting to
>>> do, but this got shot down.
>>>
>>> One issue I see is that by not calling gpio_request, then potentially
>>> you could have someone request a gpio via gpio_request() and someone
>>> trying to use it as an interrupt source via request_irq(). Now obviously
>>> that represents a bug because there is only one physical gpio, but I
>>> gather it is something we need to protect against.
>>
>> I'm not sure it's really that much of an issue, but presumably the
>> solution is for a combined GPIO+IRQ driver to simply call gpio_request
>> internally from within some irq_chip function. It looks like struct
>> irq_chip doesn't have a request/free, but perhaps they could be added to
>> solve this?
>
> Yes I was wondering if we could do something like that. That would work,
> may be that's what we should propose.
>
> Thanks
> Jon

Something like that would definitely solve the GPIO request issue but
we still have the issue that the current OMAP GPIO controller binding
does not support #interrupt-cells = <2>.

So, we can't pass the trigger type and level flags for an IRQ-GPIO
when using an GPIO controller as the interrupt-parent for a device
node.

Do you have any comments on that issue?

I'll try to check Stephen's pointers but I'm not familiar with the
gpio-omap driver neither gpiolib.

Best regards,
Javier
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Stephen Warren \<hidden\>
- Date: 2013-02-27 17:47:39 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068733.md

```text
On 02/26/2013 08:33 PM, Javier Martinez Canillas wrote:
...
> Yes, I realized that requesting the gpio was necessary so what I did
> is to use the "regulator-fixed" optional property "gpio" and define
> the GPIO used as an IRQ in a regulator used by the SMSC chip. So, I
> have this on my board DT:
> 
> vddvario: regulator-vddvario {
> 	compatible = "regulator-fixed";
> 	regulator-name = "vddvario";
> 	regulator-always-on;
> 	gpio = <&gpio6 16 8>;  /* gpio line 176 */
> 	enable-active-high;
> 	gpio-open-drain;

While admittedly it's configured as open-drain, that will configure the
GPIO to be an output, whereas for usage as an interrupt, it really
should be configured as an input... Perhaps it makes no difference on
OMAP HW since the I/O paths are separate, but I can easily imagine HW
where this hack wouldn't work.

> 	regulator-boot-on;
> };
> 
> &gpmc {
> 	ethernet at 5,0 {
> 		pinctrl-names = "default";
> 		pinctrl-0 = <&smsc911x_pins>;
> 		compatible = "smsc,lan9221", "smsc,lan9115";
> 		reg = <5 0 0xff>;
> 		interrupt-parent = <&gpio6>;
> 		interrupts = <16 8>; /* gpio line 176 */
> 		interrupt-names = "smsc911x irq";
> 		vmmc-supply = <&vddvario>;
> 		vmmc_aux-supply = <&vdd33a>;
> 		reg-io-width = <4>;
> 
> 		smsc,save-mac-address;
>       };
> };
> 
> That way a call to gpio_request_one() is made and the GPIO is requested.
> 
> This look a little hack-ish for me but I've seen this in other
> DeviceTrees like omap4-sdp.dts so I thought it was a common DT
> pattern.

Indeed; the GPIO is in no way a regulator, so while the above is fine
for testing, it's in no way a solution that can actually be used and
checked in.
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Stephen Warren \<hidden\>
- Date: 2013-02-27 17:50:57 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068734.md

```text
On 02/26/2013 08:57 PM, Javier Martinez Canillas wrote:
> On Wed, Feb 27, 2013 at 2:07 AM, Jon Hunter [ref] wrote:
>>
>> On 02/26/2013 06:13 PM, Stephen Warren wrote:
>>> On 02/26/2013 04:45 PM, Jon Hunter wrote:
...
>>>> One issue I see is that by not calling gpio_request, then potentially
>>>> you could have someone request a gpio via gpio_request() and someone
>>>> trying to use it as an interrupt source via request_irq(). Now obviously
>>>> that represents a bug because there is only one physical gpio, but I
>>>> gather it is something we need to protect against.
>>>
>>> I'm not sure it's really that much of an issue, but presumably the
>>> solution is for a combined GPIO+IRQ driver to simply call gpio_request
>>> internally from within some irq_chip function. It looks like struct
>>> irq_chip doesn't have a request/free, but perhaps they could be added to
>>> solve this?
>>
>> Yes I was wondering if we could do something like that. That would work,
>> may be that's what we should propose.
> 
> Something like that would definitely solve the GPIO request issue but
> we still have the issue that the current OMAP GPIO controller binding
> does not support #interrupt-cells = <2>.

The binding documentation in
Documentation/devicetree/bindings/gpio/gpio-omap.txt indicates that it
does. If this doesn't work in practice, it's a driver bug that can
presumably be easily fixed. And no need to change any ABI definitions:-)

BTW, I notice in that binding document that the description of the two
cells for #interrupt-cells is actually part of the description of the
"interrupt-controller" property; it should be moved up one line really.
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Javier Martinez Canillas \<hidden\>
- Date: 2013-02-27 20:00:13 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068737.md

```text
On Wed, Feb 27, 2013 at 6:47 PM, Stephen Warren [ref] wrote:
> On 02/26/2013 08:33 PM, Javier Martinez Canillas wrote:
> ...
>> Yes, I realized that requesting the gpio was necessary so what I did
>> is to use the "regulator-fixed" optional property "gpio" and define
>> the GPIO used as an IRQ in a regulator used by the SMSC chip. So, I
>> have this on my board DT:
>>
>> vddvario: regulator-vddvario {
>>       compatible = "regulator-fixed";
>>       regulator-name = "vddvario";
>>       regulator-always-on;
>>       gpio = <&gpio6 16 8>;  /* gpio line 176 */
>>       enable-active-high;
>>       gpio-open-drain;
>
> While admittedly it's configured as open-drain, that will configure the
> GPIO to be an output, whereas for usage as an interrupt, it really
> should be configured as an input... Perhaps it makes no difference on
> OMAP HW since the I/O paths are separate, but I can easily imagine HW
> where this hack wouldn't work.
>
>>       regulator-boot-on;
>> };
>>
>> &gpmc {
>>       ethernet at 5,0 {
>>               pinctrl-names = "default";
>>               pinctrl-0 = <&smsc911x_pins>;
>>               compatible = "smsc,lan9221", "smsc,lan9115";
>>               reg = <5 0 0xff>;
>>               interrupt-parent = <&gpio6>;
>>               interrupts = <16 8>; /* gpio line 176 */
>>               interrupt-names = "smsc911x irq";
>>               vmmc-supply = <&vddvario>;
>>               vmmc_aux-supply = <&vdd33a>;
>>               reg-io-width = <4>;
>>
>>               smsc,save-mac-address;
>>       };
>> };
>>
>> That way a call to gpio_request_one() is made and the GPIO is requested.
>>
>> This look a little hack-ish for me but I've seen this in other
>> DeviceTrees like omap4-sdp.dts so I thought it was a common DT
>> pattern.
>
> Indeed; the GPIO is in no way a regulator, so while the above is fine
> for testing, it's in no way a solution that can actually be used and
> checked in.

Yes, this is just a work-in-progress and is not meant to be taken as a
patch submission.

I'm just doing some testing with DT and figuring out how much effort
will take to have the same hardware support we currently with board
files for IGEP boards.

Thanks a lot for your feedback and best regards,
Javier
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Javier Martinez Canillas \<hidden\>
- Date: 2013-02-27 20:05:35 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068738.md

```text
On Wed, Feb 27, 2013 at 6:50 PM, Stephen Warren [ref] wrote:
> On 02/26/2013 08:57 PM, Javier Martinez Canillas wrote:
>> On Wed, Feb 27, 2013 at 2:07 AM, Jon Hunter [ref] wrote:
>>>
>>> On 02/26/2013 06:13 PM, Stephen Warren wrote:
>>>> On 02/26/2013 04:45 PM, Jon Hunter wrote:
> ...
>>>>> One issue I see is that by not calling gpio_request, then potentially
>>>>> you could have someone request a gpio via gpio_request() and someone
>>>>> trying to use it as an interrupt source via request_irq(). Now obviously
>>>>> that represents a bug because there is only one physical gpio, but I
>>>>> gather it is something we need to protect against.
>>>>
>>>> I'm not sure it's really that much of an issue, but presumably the
>>>> solution is for a combined GPIO+IRQ driver to simply call gpio_request
>>>> internally from within some irq_chip function. It looks like struct
>>>> irq_chip doesn't have a request/free, but perhaps they could be added to
>>>> solve this?
>>>
>>> Yes I was wondering if we could do something like that. That would work,
>>> may be that's what we should propose.
>>
>> Something like that would definitely solve the GPIO request issue but
>> we still have the issue that the current OMAP GPIO controller binding
>> does not support #interrupt-cells = <2>.
>
> The binding documentation in
> Documentation/devicetree/bindings/gpio/gpio-omap.txt indicates that it
> does. If this doesn't work in practice, it's a driver bug that can
> presumably be easily fixed. And no need to change any ABI definitions:-)
>

indeed :-)

In fact I think that some documentation bits were borrowed from the
NVIDIA Tegra GPIO controller bindings but it was never implemented in
the OMAP GPIO driver to parse the second interrupt-cell which should
specify the flags.

> BTW, I notice in that binding document that the description of the two
> cells for #interrupt-cells is actually part of the description of the
> "interrupt-controller" property; it should be moved up one line really.

Right, will submit a patch to fix this.

Best regards,
Javier
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Jon Hunter \<hidden\>
- Date: 2013-02-27 20:13:10 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068740.md

```text

On 02/26/2013 09:47 PM, Javier Martinez Canillas wrote:
> On Wed, Feb 27, 2013 at 12:08 AM, Jon Hunter [ref] wrote:
>>
>> On 02/26/2013 04:01 AM, Javier Martinez Canillas wrote:
>>
>> [snip]
>>
>>> I was wondering if the level/edge settings for gpios is working on OMAP.
>>>
>>> I'm adding DT support for an SMSC911x ethernet chip connected to the
>>> GPMC for an OMAP3 SoC based board.
>>>
>>> In the smsc911x driver probe function (smsc911x_drv_probe() in
>>> drivers/net/ethernet/smsc/smsc911x.c), a call to request_irq() with
>>> the flag IRQF_TRIGGER_LOW is needed because of the wiring on my board.
>>>
>>> Reading the gpio-omap.txt documentation it says that #interrupt-cells
>>> should be <2> and that a value of 8 is "active low level-sensitive".
>>>
>>> So I tried this:
>>>
>>> &gpmc {
>>>       ethernet at 5,0 {
>>>               pinctrl-names = "default";
>>>               pinctrl-0 = <&smsc911x_pins>;
>>>               compatible = "smsc,lan9221", "smsc,lan9115";
>>>               reg = <5 0 0xff>; /* CS5 */
>>>               interrupt-parent = <&gpio6>;
>>>               interrupts = <16 8>; /* gpio line 176 */
>>>               interrupt-names = "smsc911x irq";
>>>               vmmc-supply = <&vddvario>;
>>>               vmmc_aux-supply = <&vdd33a>;
>>>               reg-io-width = <4>;
>>
>> By the way, reg-io-width for omap does not look correct. The GPMC only
>> supports 8-bit or 16-bit devices IIRC. I believe all my omap boards use
>> 16-bit.
>>
> 
> I thought that even when the GPMC was a 16-bit external memory
> controller it could do some access adaptation to support 32-bit
> devices.

Right the GPMC itself may be able to translate 32-bit accesses into
16-bit. However, I have not looked at the data sheet for the smsc parts
to know what impact this would have on any register accesses in the smsc
device.

> By looking at the board files for others OMAP3 based boards
> (board-{omap3evm,overo,zoom-debugboard}.c) most of them set the struct
> omap_smsc911x_platform_data .flags member to SMSC911X_USE_32BIT.

I see this too now. I was looking at the
arch/arm/mach-omap2/gpmc-smc91x.c which has SMC91X_USE_16BIT and
GPMC_CONFIG1_DEVICESIZE_16. So this is for a slightly different ethernet
chip but same concept. Hopefully, someone knew what they were doing for
those other boards!

> And by looking at Documentation/devicetree/bindings/net/smsc911x.txt I
> thought that the corresponding DT property for this flag was
> "reg-io-width"
> 
> Anyway, I tried using both reg-io-width = <4> and reg-io-width = <2>.
> The ethernet chip works with both of them and I don't see too much
> difference in performance:
> 
> 16-bit
> round-trip min/avg/max = 0.611/0.738/0.946 ms
> 
> 32-bit
> round-trip min/avg/max = 0.519/0.690/0.976 ms
> 
> So, is your call ;-)

While I can't argue with the fact it works, I would not be prepared to
make that call without reviewing the documentation for the smsc and the
driver.

Cheers
Jon
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Jon Hunter \<hidden\>
- Date: 2013-02-27 23:16:09 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068743.md

```text

On 02/26/2013 09:57 PM, Javier Martinez Canillas wrote:

[snip]

> Something like that would definitely solve the GPIO request issue but
> we still have the issue that the current OMAP GPIO controller binding
> does not support #interrupt-cells = <2>.
> 
> So, we can't pass the trigger type and level flags for an IRQ-GPIO
> when using an GPIO controller as the interrupt-parent for a device
> node.
> 
> Do you have any comments on that issue?

Can you elaborate a bit more on why you say this is not supported?

I have been playing with this today on an omap board and if I set the
#interrupt-cells = <2>, then I do see that irq_domain_xlate_onetwocell()
is called and the irq number and flags read as expected. Following which
I then see it will call the omap_irq_type() to set type. So AFAICT it works.

Please note I do see that when the SMC driver calls request_irq() in
smc_drv_probe() it is also settings the trigger type to
IRQ_TYPE_EDGE_RISING (default). So if you are setting to low-level
sensitive in DT, then this is being overwritten. We could fix this by
setting SMC_IRQ_FLAGS to -1 for OMAP.

In general we do need to fix the gpio binding for omap to default to
#interrupt-cell = <2>, as this should work. However, before we can do
that we need to fix the issue of ensuring the gpio module is enabled if
being used as an interrupt source without having to call gpio_request()
first.

We should probably add the following patch as well to avoid any hangs if
the bank is not enabled, when omap_irq_type is called.

commit 5e298de564e09f5ca4148a9bc0ed5d16b4742f14
Author: Jon Hunter [ref]
Date:   Wed Feb 27 17:14:11 2013 -0600

    gpio/omap: warn if gpio bank is not enabled on setting irq type

diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index f1fbedb2..cbdc796 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -421,6 +421,9 @@ static int gpio_irq_type(struct irq_data *d,
unsigned type)
        int retval;
        unsigned long flags;

+       if (WARN_ON(!bank->mod_usage))
+               return -EINVAL;
+
 #ifdef CONFIG_ARCH_OMAP1
        if (d->irq > IH_MPUIO_BASE)
                gpio = OMAP_MPUIO(d->irq - IH_MPUIO_BASE);


Cheers
Jon
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Linus Walleij \<hidden\>
- Date: 2013-02-27 23:41:06 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068747.md

```text
On Wed, Feb 15, 2012 at 5:04 PM, Benoit Cousson [ref] wrote:

> @@ -52,7 +55,8 @@ struct gpio_bank {
>         struct list_head node;
>         void __iomem *base;
>         u16 irq;
> -       u16 virtual_irq_start;
> +       int irq_base;
> +       struct irq_domain *domain;

This seems wrong. IRQ domains are used to avoid keeping track of
irq base offsets. I would even say it's the whole point of irq domains.

> @@ -669,7 +673,7 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
>                 if (!isr)
>                         break;
>
> -               gpio_irq = bank->virtual_irq_start;
> +               gpio_irq = bank->irq_base;
>                 for (; isr != 0; isr >>= 1, gpio_irq++) {
>                         gpio_index = GPIO_INDEX(bank, irq_to_gpio(gpio_irq));
>

Use irq_find_mapping(irqdomain, hwirq) in this function.


> @@ -915,7 +919,7 @@ static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
>         struct gpio_bank *bank;
>
>         bank = container_of(chip, struct gpio_bank, chip);
> -       return bank->virtual_irq_start + offset;
> +       return bank->irq_base + offset;

Use irq_create_mapping() in this function.

> +       bank->irq_base = irq_alloc_descs(-1, 0, bank->width, 0);
> +       if (bank->irq_base < 0) {
> +               dev_err(dev, "Couldn't allocate IRQ numbers\n");
> +               return -ENODEV;
> +       }
> +
> +       bank->domain = irq_domain_add_legacy(node, bank->width, bank->irq_base,
> +                                            0, &irq_domain_simple_ops, NULL);

Use irq_domain_add_simple() and the descs will be allocated for
you as part of the domain creation, when using a pre-fixed base.

If you fix this I suspect the device tree discussion also will fix
itself :-)

Documentation/IRQ-domain.txt

Yours,
Linus Walleij
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Javier Martinez Canillas \<hidden\>
- Date: 2013-02-28 12:17:39 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068769.md

```text
On Thu, Feb 28, 2013 at 12:16 AM, Jon Hunter [ref] wrote:
>
> On 02/26/2013 09:57 PM, Javier Martinez Canillas wrote:
>
> [snip]
>
>> Something like that would definitely solve the GPIO request issue but
>> we still have the issue that the current OMAP GPIO controller binding
>> does not support #interrupt-cells = <2>.
>>
>> So, we can't pass the trigger type and level flags for an IRQ-GPIO
>> when using an GPIO controller as the interrupt-parent for a device
>> node.
>>
>> Do you have any comments on that issue?
>
> Can you elaborate a bit more on why you say this is not supported?
>
> I have been playing with this today on an omap board and if I set the
> #interrupt-cells = <2>, then I do see that irq_domain_xlate_onetwocell()
> is called and the irq number and flags read as expected. Following which
> I then see it will call the omap_irq_type() to set type. So AFAICT it works.
>

Yes, it does.

I (wrongly) assumed that it was not working since the GPIO OMAP
binding documentation says that #interrupt-cells should be <2> but all
OMAP2+ DTs use <1> instead. Also, when trying to change to <2> I had
the kernel hang.

But it was indeed that the GPIO bank was not enabled before calling
gpio_irq_type() and this made the kernel to hang. Your patch fixed the
issue and allowed me to find the cause.

The problem was that when using the DT hack of defining the GPIO in
the ethernet chip regulator,  the calls to
irq_domain_xlate_onetwocell() and gpio_irq_type() were made before the
call to gpio_request_one() so the GPIO bank was not enabled.

If gpio_request() is called in gpmc_probe_dt(), then the GPIO bank is
enabled and gpio_irq_type() succeeds.

So, it was just me being stupid and don't understanding the implementation.

> Please note I do see that when the SMC driver calls request_irq() in
> smc_drv_probe() it is also settings the trigger type to
> IRQ_TYPE_EDGE_RISING (default). So if you are setting to low-level
> sensitive in DT, then this is being overwritten. We could fix this by
> setting SMC_IRQ_FLAGS to -1 for OMAP.
>

Please note that I'm using a SMSC 911x chip and not a SMSC 91x, so the
driver is not smc91x but smc911x. It has the same behaviour though
(IRQ flags overwritten somehow), just to be sure that we are on the
same page.

I don't know if just setting SMC_IRQ_FLAGS to -1 will be enough to fix
the smc91x since request_irq() is just passing whatever value is in
irq_flags.

By looking at the two drivers (smc91x and smsc911x) it seems that the
only difference on how they manage the flags is that smc91x does:

unsigned long irq_flags = SMC_IRQ_FLAGS;
...
       if (irq_flags == -1 || ires->flags & IRQF_TRIGGER_MASK)
                irq_flags = ires->flags & IRQF_TRIGGER_MASK;

while smsc911x driver's probe function uses the flags from the
resource unconditionally:

irq_flags = irq_res->flags & IRQF_TRIGGER_MASK;

So, at the end both will set irq_flags to whatever is on the
IORESOURCE_IRQ struct resource flags member.

The real problem is irq_flags to be 0 instead of the value defined on
the second cell of the "interrupts" property.

when irq_domain_xlate_onetwocell() is called for the ethernet GPIO-IRQ
I see that both the cells size and the second cell with the flag
values are set correctly (2 and IRQF_TRIGGER_LOW).

But even when gpio_irq_type() succeeds it seems that the struct
resource IRQ flags passed to the smsc911x driver is still overwritten
or not set correctly since flags & IRQF_TRIGGER_MASK is always 0.

> In general we do need to fix the gpio binding for omap to default to
> #interrupt-cell = <2>, as this should work. However, before we can do
> that we need to fix the issue of ensuring the gpio module is enabled if
> being used as an interrupt source without having to call gpio_request()
> first.
>

Indeed, although I still wonder why the flags are not set correctly
for the smsc911x driver.

I had only tested it with this device so I don't know if this is a
general issue of IORESOURCE_IRQ structs not been initialized correctly
when using GPIOs as IRQ on OMAP or if is only related to this driver.

> We should probably add the following patch as well to avoid any hangs if
> the bank is not enabled, when omap_irq_type is called.
>
> commit 5e298de564e09f5ca4148a9bc0ed5d16b4742f14
> Author: Jon Hunter [ref]
> Date:   Wed Feb 27 17:14:11 2013 -0600
>
>     gpio/omap: warn if gpio bank is not enabled on setting irq type
>
> diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
> index f1fbedb2..cbdc796 100644
> --- a/drivers/gpio/gpio-omap.c
> +++ b/drivers/gpio/gpio-omap.c
> @@ -421,6 +421,9 @@ static int gpio_irq_type(struct irq_data *d,
> unsigned type)
>         int retval;
>         unsigned long flags;
>
> +       if (WARN_ON(!bank->mod_usage))
> +               return -EINVAL;
> +
>  #ifdef CONFIG_ARCH_OMAP1
>         if (d->irq > IH_MPUIO_BASE)
>                 gpio = OMAP_MPUIO(d->irq - IH_MPUIO_BASE);
>
>
> Cheers
> Jon
>
>

Thanks a lot for your help and best regards,
Javier
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Benoit Cousson \<hidden\>
- Date: 2013-02-28 13:04:32 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068770.md

```text
+ Jon who was brave enough to take over the OMAP GPIO  driver
+ New email address for Kevin since he is no longer at TI :-(.
- Tarun that left TI but I don't have his new email

Hi Linus,

On 02/28/2013 12:41 AM, Linus Walleij wrote:
> On Wed, Feb 15, 2012 at 5:04 PM, Benoit Cousson [ref] wrote:

Gosh! That's pretty old stuff :-)

>> @@ -52,7 +55,8 @@ struct gpio_bank {
>>         struct list_head node;
>>         void __iomem *base;
>>         u16 irq;
>> -       u16 virtual_irq_start;
>> +       int irq_base;
>> +       struct irq_domain *domain;
> 
> This seems wrong. IRQ domains are used to avoid keeping track of
> irq base offsets. I would even say it's the whole point of irq domains.

Well at that time, it was not the only point. We were trying to boot
with DT, and for that irq_domain was mandatory. At the very same time,
Grant was cleaning and consolidating the whole irq_domain
infrastructure, and thus most of the following API were not really
stabilized or even available.

So, this idea was to avoid any regression while allowing DT boot... And
obviously a lot of stuff happened since that good old time.

>> @@ -669,7 +673,7 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
>>                 if (!isr)
>>                         break;
>>
>> -               gpio_irq = bank->virtual_irq_start;
>> +               gpio_irqkhilman at ti.com = bank->irq_base;
>>                 for (; isr != 0; isr >>= 1, gpio_irq++) {
>>                         gpio_index = GPIO_INDEX(bank, irq_to_gpio(gpio_irq));
>>
> 
> Use irq_find_mapping(irqdomain, hwirq) in this function.
> 
> 
>> @@ -915,7 +919,7 @@ static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
>>         struct gpio_bank *bank;
>>
>>         bank = container_of(chip, struct gpio_bank, chip);
>> -       return bank->virtual_irq_start + offset;
>> +       return bank->irq_base + offset;
> 
> Use irq_create_mapping() in this function.
> 
>> +       bank->irq_base = irq_alloc_descs(-1, 0, bank->width, 0);
>> +       if (bank->irq_base < 0) {
>> +               dev_err(dev, "Couldn't allocate IRQ numbers\n");
>> +               return -ENODEV;
>> +       }
>> +
>> +       bank->domain = irq_domain_add_legacy(node, bank->width, bank->irq_base,
>> +                                            0, &irq_domain_simple_ops, NULL);
> 
> Use irq_domain_add_simple() and the descs will be allocated for
> you as part of the domain creation, when using a pre-fixed base.

Funny, that API was removed while I was writing this patch, and is now
back in town...

> If you fix this I suspect the device tree discussion also will fix
> itself :-)

Mmm, I hope it is the case, but I'm not sure it will be that easy :-)

Thanks,
Benoit
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Jon Hunter \<hidden\>
- Date: 2013-02-28 20:49:03 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/02/8068777.md

```text

On 02/28/2013 06:17 AM, Javier Martinez Canillas wrote:
> On Thu, Feb 28, 2013 at 12:16 AM, Jon Hunter [ref] wrote:
>>
>> On 02/26/2013 09:57 PM, Javier Martinez Canillas wrote:
>>
>> [snip]
>>
>>> Something like that would definitely solve the GPIO request issue but
>>> we still have the issue that the current OMAP GPIO controller binding
>>> does not support #interrupt-cells = <2>.
>>>
>>> So, we can't pass the trigger type and level flags for an IRQ-GPIO
>>> when using an GPIO controller as the interrupt-parent for a device
>>> node.
>>>
>>> Do you have any comments on that issue?
>>
>> Can you elaborate a bit more on why you say this is not supported?
>>
>> I have been playing with this today on an omap board and if I set the
>> #interrupt-cells = <2>, then I do see that irq_domain_xlate_onetwocell()
>> is called and the irq number and flags read as expected. Following which
>> I then see it will call the omap_irq_type() to set type. So AFAICT it works.
>>
> 
> Yes, it does.
> 
> I (wrongly) assumed that it was not working since the GPIO OMAP
> binding documentation says that #interrupt-cells should be <2> but all
> OMAP2+ DTs use <1> instead. Also, when trying to change to <2> I had
> the kernel hang.
> 
> But it was indeed that the GPIO bank was not enabled before calling
> gpio_irq_type() and this made the kernel to hang. Your patch fixed the
> issue and allowed me to find the cause.
> 
> The problem was that when using the DT hack of defining the GPIO in
> the ethernet chip regulator,  the calls to
> irq_domain_xlate_onetwocell() and gpio_irq_type() were made before the
> call to gpio_request_one() so the GPIO bank was not enabled.
> 
> If gpio_request() is called in gpmc_probe_dt(), then the GPIO bank is
> enabled and gpio_irq_type() succeeds.
> 
> So, it was just me being stupid and don't understanding the implementation.

No problem. Glad we are on the same page :-)

>> Please note I do see that when the SMC driver calls request_irq() in
>> smc_drv_probe() it is also settings the trigger type to
>> IRQ_TYPE_EDGE_RISING (default). So if you are setting to low-level
>> sensitive in DT, then this is being overwritten. We could fix this by
>> setting SMC_IRQ_FLAGS to -1 for OMAP.
>>
> 
> Please note that I'm using a SMSC 911x chip and not a SMSC 91x, so the
> driver is not smc91x but smc911x. It has the same behaviour though
> (IRQ flags overwritten somehow), just to be sure that we are on the
> same page.
> 
> I don't know if just setting SMC_IRQ_FLAGS to -1 will be enough to fix
> the smc91x since request_irq() is just passing whatever value is in
> irq_flags.
> 
> By looking at the two drivers (smc91x and smsc911x) it seems that the
> only difference on how they manage the flags is that smc91x does:
> 
> unsigned long irq_flags = SMC_IRQ_FLAGS;
> ...
>        if (irq_flags == -1 || ires->flags & IRQF_TRIGGER_MASK)
>                 irq_flags = ires->flags & IRQF_TRIGGER_MASK;
> 
> while smsc911x driver's probe function uses the flags from the
> resource unconditionally:
> 
> irq_flags = irq_res->flags & IRQF_TRIGGER_MASK;
> 
> So, at the end both will set irq_flags to whatever is on the
> IORESOURCE_IRQ struct resource flags member.

Actually, that's not the case for smc91x. By default SMC_IRQ_FLAGS != -1
(for omap) and so it will not set irq_flags to ires->flags &
IRQF_TRIGGER_MASK. However, if I force irq_flags to be -1, then I see
that irq_flags are to 0.

> The real problem is irq_flags to be 0 instead of the value defined on
> the second cell of the "interrupts" property.

So the resource flags for each irq is set in
of_irq_to_resource() which just does ...

	r->start = r->end = irq;
	r->flags = IORESOURCE_IRQ;
	r->name = name ? name : dev->full_name;


of_irq_to_resource() calls irq_to_parse_and_map() which eventually just
calls irq_set_irq_type() but type/flags is not returned and not populated.

I am wondering if this is intentional. The irq_type is being correctly
configured by irq_set_irq_type() when of_irq_to_resource() is called. In
the smc driver, if irq_flags are 0, then when request_irq() is called
the trigger type will not be set again (which is ok). __setup_irq has
the following ...

	/* Setup the type (level, edge polarity) if configured: */
	if (new->flags & IRQF_TRIGGER_MASK) {
		ret = __irq_set_trigger(desc, irq,
			new->flags & IRQF_TRIGGER_MASK);

Cheers
Jon
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Linus Walleij \<hidden\>
- Date: 2013-03-01 00:09:19 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/03/8068778.md

```text
On Thu, Feb 28, 2013 at 2:04 PM, Benoit Cousson [ref] wrote:

> On 02/28/2013 12:41 AM, Linus Walleij wrote:
>> On Wed, Feb 15, 2012 at 5:04 PM, Benoit Cousson [ref] wrote:
>
> Gosh! That's pretty old stuff :-)

Hm yeah, haha :-)

I didn't notice that someone was replying in the thread for
some other reason (or maybe using the same subject and
confusing my gmail reader?).

Anyway, the basic idea is sound, so are you still working
on the patch? I remember discussing this with someone
in Denmark...

Yours,
Linus Walleij
```

## Re: \[PATCH 3/5\] gpio/omap: Add DT support to GPIO driver

- From: Jon Hunter \<hidden\>
- Date: 2013-03-01 00:42:14 
- Message: https://ratatoskr.run/linux-arm-kernel/2013/03/8068779.md

```text

On 02/28/2013 06:09 PM, Linus Walleij wrote:
> On Thu, Feb 28, 2013 at 2:04 PM, Benoit Cousson [ref] wrote:
> 
>> On 02/28/2013 12:41 AM, Linus Walleij wrote:
>>> On Wed, Feb 15, 2012 at 5:04 PM, Benoit Cousson [ref] wrote:
>>
>> Gosh! That's pretty old stuff :-)
> 
> Hm yeah, haha :-)
> 
> I didn't notice that someone was replying in the thread for
> some other reason (or maybe using the same subject and
> confusing my gmail reader?).
> 
> Anyway, the basic idea is sound, so are you still working
> on the patch? I remember discussing this with someone
> in Denmark...

That was me :-)

I have the patch, I am testing and will send tomorrow for review.

Cheers
Jon
```
