Skip to contentSkip to conversation

Cleanup MSM_GPIOMUX and add device-tree support for

PATCH Superseded Rohit Vaswani 4 participants 10 messages May 21, 2013 – May 30, 2013

Subsystems (5)

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

cover Cleanup MSM_GPIOMUX and add device-tree support for

Hi Linus,
Could this series go through David's tree or is there a better way to do this? It would be great if I can have you ack for the gpio patch.

Thanks,
Rohit

Rohit Vaswani (3):
ARM: msm: Remove gpiomux-v2 and re-organize MSM_GPIOMUX configs
ARM: msm: Remove unused and unmapped MSM_TLMM_BASE for 8x60
gpio: msm: Add device tree and irqdomain support for gpio-msm-v2

 .../devicetree/bindings/gpio/gpio-msm.txt          |   26 ++++
 arch/arm/boot/dts/msm8660-surf.dts                 |   11 ++
 arch/arm/boot/dts/msm8960-cdp.dts                  |   11 ++
 arch/arm/mach-msm/Kconfig                          |   13 +-
 arch/arm/mach-msm/Makefile                         |    6 +-
 arch/arm/mach-msm/gpiomux-8x60.c                   |   19 ---
 arch/arm/mach-msm/gpiomux-v2.c                     |   25 ---
 arch/arm/mach-msm/gpiomux-v2.h                     |   61 --------
 arch/arm/mach-msm/gpiomux.c                        |   15 ++
 arch/arm/mach-msm/gpiomux.h                        |    5 -
 arch/arm/mach-msm/include/mach/msm_iomap-8x60.h    |    4 -
 drivers/gpio/Kconfig                               |    2 +-
 drivers/gpio/gpio-msm-v2.c                         |  158 ++++++++++++++------
 13 files changed, 183 insertions(+), 173 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-msm.txt
 delete mode 100644 arch/arm/mach-msm/gpiomux-8x60.c
 delete mode 100644 arch/arm/mach-msm/gpiomux-v2.c
 delete mode 100644 arch/arm/mach-msm/gpiomux-v2.h
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
#1 lore raw

PATCH 1/3 ARM: msm: Remove gpiomux-v2 and re-organize MSM_GPIOMUX configs

Remove gpiomux-v2 as it's not being used and make way for future improvements.

---
 arch/arm/mach-msm/Kconfig        |   13 +++-----
 arch/arm/mach-msm/Makefile       |    6 +--
 arch/arm/mach-msm/gpiomux-8x60.c |   19 ------------
 arch/arm/mach-msm/gpiomux-v2.c   |   25 ---------------
 arch/arm/mach-msm/gpiomux-v2.h   |   61 --------------------------------------
 arch/arm/mach-msm/gpiomux.c      |   15 +++++++++
 arch/arm/mach-msm/gpiomux.h      |    5 ---
 drivers/gpio/gpio-msm-v2.c       |    5 +--
 8 files changed, 24 insertions(+), 125 deletions(-)
 delete mode 100644 arch/arm/mach-msm/gpiomux-8x60.c
 delete mode 100644 arch/arm/mach-msm/gpiomux-v2.c
 delete mode 100644 arch/arm/mach-msm/gpiomux-v2.h
arch/arm/mach-msm/Kconfig +5 -8
index fceb093..614e41e 100644
@@ -48,9 +48,7 @@ config ARCH_MSM8X60
 	select CPU_V7
 	select GPIO_MSM_V2
 	select HAVE_SMP
-	select MSM_GPIOMUX
 	select MSM_SCM if SMP
-	select MSM_V2_TLMM
 	select USE_OF
 
 config ARCH_MSM8960
@@ -58,9 +56,8 @@ config ARCH_MSM8960
 	select ARM_GIC
 	select CPU_V7
 	select HAVE_SMP
-	select MSM_GPIOMUX
+	select GPIO_MSM_V2
 	select MSM_SCM if SMP
-	select MSM_V2_TLMM
 	select USE_OF
 
 config MSM_HAS_DEBUG_UART_HS
@@ -124,10 +121,10 @@ config MSM_SMD
 	bool
 
 config MSM_GPIOMUX
-	bool
-
-config MSM_V2_TLMM
-	bool
+	depends on !(ARCH_MSM8X60 || ARCH_MSM8960)
+	bool "MSM V1 TLMM GPIOMUX architecture"
+	help
+	  Support for MSM V1 TLMM GPIOMUX architecture.
 
 config MSM_SCM
 	bool
arch/arm/mach-msm/Makefile +2 -4
index 17519fa..1a26d04 100644
@@ -27,7 +27,5 @@ obj-$(CONFIG_ARCH_MSM7X30) += board-msm7x30.o devices-msm7x30.o
 obj-$(CONFIG_ARCH_QSD8X50) += board-qsd8x50.o devices-qsd8x50.o
 obj-$(CONFIG_ARCH_MSM8X60) += board-dt-8660.o
 obj-$(CONFIG_ARCH_MSM8960) += board-dt-8960.o
-
-obj-$(CONFIG_ARCH_MSM7X30) += gpiomux-v1.o gpiomux.o
-obj-$(CONFIG_ARCH_QSD8X50) += gpiomux-8x50.o gpiomux-v1.o gpiomux.o
-obj-$(CONFIG_ARCH_MSM8X60) += gpiomux-8x60.o gpiomux-v2.o gpiomux.o
+obj-$(CONFIG_MSM_GPIOMUX) += gpiomux.o
+obj-$(CONFIG_ARCH_QSD8X50) += gpiomux-8x50.o
arch/arm/mach-msm/gpiomux-8x60.c deleted +0 -19
deleted file mode 100644
index 7b380b3..0000000
@@ -1,19 +0,0 @@
-/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 and
- * only version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- */
-#include "gpiomux.h"
-
-struct msm_gpiomux_config msm_gpiomux_configs[GPIOMUX_NGPIOS] = {};
arch/arm/mach-msm/gpiomux-v2.c deleted +0 -25
deleted file mode 100644
index 273396d..0000000
@@ -1,25 +0,0 @@
-/* Copyright (c) 2010, Code Aurora Forum. All rights reserved.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 and
- * only version 2 as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- */
-#include <linux/io.h>
-#include <mach/msm_iomap.h>
-#include "gpiomux.h"
-
-void __msm_gpiomux_write(unsigned gpio, gpiomux_config_t val)
-{
-	writel(val & ~GPIOMUX_CTL_MASK,
-	       MSM_TLMM_BASE + 0x1000 + (0x10 * gpio));
-}
arch/arm/mach-msm/gpiomux-v2.h deleted +0 -61

61 lines not on this page · raw message

arch/arm/mach-msm/gpiomux.c +15 -0
index 53af21a..2b8e2d2 100644
@@ -17,9 +17,24 @@
 #include <linux/module.h>
 #include <linux/spinlock.h>
 #include "gpiomux.h"
+#include "proc_comm.h"
 
 static DEFINE_SPINLOCK(gpiomux_lock);
 
+static void __msm_gpiomux_write(unsigned gpio, gpiomux_config_t val)
+{
+	unsigned tlmm_config  = (val & ~GPIOMUX_CTL_MASK) |
+				((gpio & 0x3ff) << 4);
+	unsigned tlmm_disable = 0;
+	int rc;
+
+	rc = msm_proc_comm(PCOM_RPC_GPIO_TLMM_CONFIG_EX,
+			   &tlmm_config, &tlmm_disable);
+	if (rc)
+		pr_err("%s: unexpected proc_comm failure %d: %08x %08x\n",
+		       __func__, rc, tlmm_config, tlmm_disable);
+}
+
 int msm_gpiomux_write(unsigned gpio,
 		      gpiomux_config_t active,
 		      gpiomux_config_t suspended)
arch/arm/mach-msm/gpiomux.h +0 -5
index 00459f6..8e82f41 100644
@@ -20,12 +20,7 @@
 #include <linux/bitops.h>
 #include <linux/errno.h>
 #include <mach/msm_gpiomux.h>
-
-#if defined(CONFIG_MSM_V2_TLMM)
-#include "gpiomux-v2.h"
-#else
 #include "gpiomux-v1.h"
-#endif
 
 /**
  * struct msm_gpiomux_config: gpiomux settings for one gpio line.
drivers/gpio/gpio-msm-v2.c +2 -3
index dd2edde..75cc821 100644
@@ -29,7 +29,6 @@
 #include <linux/platform_device.h>
 #include <linux/spinlock.h>
 
-#include <mach/msm_gpiomux.h>
 #include <mach/msm_iomap.h>
 
 /* Bits of interest in the GPIO_IN_OUT register.
@@ -159,12 +158,12 @@ static int msm_gpio_direction_output(struct gpio_chip *chip,
 
 static int msm_gpio_request(struct gpio_chip *chip, unsigned offset)
 {
-	return msm_gpiomux_get(chip->base + offset);
+	return 0;
 }
 
 static void msm_gpio_free(struct gpio_chip *chip, unsigned offset)
 {
-	msm_gpiomux_put(chip->base + offset);
+	return;
 }
 
 static int msm_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
Acked-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] ARM: msm: Remove gpiomux-v2 and re-organize MSM_GPIOMUX configs

Quoted 3 lines · Rohit Vaswani

Remove gpiomux-v2 as it's not being used and make way for future improvements.

OK less problems in my world -> good.

I hope "future improvements" mean "we're switching to pin control".

Yours,
Linus Walleij

#3 lore raw

PATCH 2/3 ARM: msm: Remove unused and unmapped MSM_TLMM_BASE for 8x60

In reply to Rohit Vaswani

MSM_TLMM_BASE is currently not mapped by 8x60. Remove it.

---
 arch/arm/mach-msm/include/mach/msm_iomap-8x60.h |    4 ----
 1 files changed, 0 insertions(+), 4 deletions(-)
arch/arm/mach-msm/include/mach/msm_iomap-8x60.h +0 -4
index 199372e..cf24b5c 100644
@@ -41,10 +41,6 @@
 #define MSM8X60_QGIC_CPU_PHYS	0x02081000
 #define MSM8X60_QGIC_CPU_SIZE	SZ_4K
 
-#define MSM_TLMM_BASE		IOMEM(0xF0004000)
-#define MSM_TLMM_PHYS		0x00800000
-#define MSM_TLMM_SIZE		SZ_16K
-
 #define MSM8X60_TMR_PHYS	0x02000000
 #define MSM8X60_TMR_SIZE	SZ_4K
 
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
#4 lore raw

PATCH 3/3 gpio: msm: Add device tree and irqdomain support for gpio-msm-v2

In reply to Rohit Vaswani

This cleans up the gpio-msm-v2 driver of all the global define usage. The number of gpios are now defined in the device tree. This enables adding irqdomain support as well.

---
 .../devicetree/bindings/gpio/gpio-msm.txt          |   26 ++++
 arch/arm/boot/dts/msm8660-surf.dts                 |   11 ++
 arch/arm/boot/dts/msm8960-cdp.dts                  |   11 ++
 drivers/gpio/Kconfig                               |    2 +-
 drivers/gpio/gpio-msm-v2.c                         |  153 ++++++++++++++------
 5 files changed, 159 insertions(+), 44 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/gpio/gpio-msm.txt
Documentation/devicetree/bindings/gpio/gpio-msm.txt new file +26 -0
new file mode 100644
index 0000000..ac20e68
@@ -0,0 +1,26 @@
+MSM GPIO controller bindings
+
+Required properties:
+- compatible:
+  - "qcom,msm-gpio" for MSM 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 2.
+- interrupt-controller: Mark the device node as an interrupt controller
+- interrupts : Specify the TLMM summary interrupt number
+- ngpio : Specify the number of MSM GPIOs
+
+Example:
+
+	msmgpio: gpio@fd510000 {
+		compatible = "qcom,msm-gpio";
+		gpio-controller;
+		#gpio-cells = <2>;
+		interrupt-controller;
+		#interrupt-cells = <2>;
+		reg = <0xfd510000 0x4000>;
+		interrupts = <0 208 0>;
+		ngpio = <150>;
+	};
arch/arm/boot/dts/msm8660-surf.dts +11 -0
index 9bf49b3..8931906 100644
@@ -26,6 +26,17 @@
 		cpu-offset = <0x40000>;
 	};
 
+	msmgpio: gpio@800000 {
+		compatible = "qcom,msm-gpio";
+		reg = <0x00800000 0x1000>;
+		gpio-controller;
+		#gpio-cells = <2>;
+		ngpio = <173>;
+		interrupts = <0 32 0x4>;
+		interrupt-controller;
+		#interrupt-cells = <2>;
+	};
+
 	serial@19c400000 {
 		compatible = "qcom,msm-hsuart", "qcom,msm-uart";
 		reg = <0x19c40000 0x1000>,
arch/arm/boot/dts/msm8960-cdp.dts +11 -0
index 2e4d87a..52fe253 100644
@@ -26,6 +26,17 @@
 		cpu-offset = <0x80000>;
 	};
 
+	msmgpio: gpio@fd510000 {
+		compatible = "qcom,msm-gpio";
+		gpio-controller;
+		#gpio-cells = <2>;
+		ngpio = <150>;
+		interrupts = <0 32 0x4>;
+		interrupt-controller;
+		#interrupt-cells = <2>;
+		reg = <0xfd510000 0x4000>;
+	};
+
 	serial@19c400000 {
 		compatible = "qcom,msm-hsuart", "qcom,msm-uart";
 		reg = <0x16440000 0x1000>,
drivers/gpio/Kconfig +1 -1
index 87d5670..f3c1978 100644
@@ -165,7 +165,7 @@ config GPIO_MSM_V1
 
 config GPIO_MSM_V2
 	tristate "Qualcomm MSM GPIO v2"
-	depends on GPIOLIB && ARCH_MSM
+	depends on GPIOLIB && ARCH_MSM && OF
 	help
 	  Say yes here to support the GPIO interface on ARM v7 based
 	  Qualcomm MSM chips.  Most of the pins on the MSM can be
drivers/gpio/gpio-msm-v2.c +110 -43

252 lines not on this page · raw message

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation
#5 lore raw

Re: [PATCH 3/3] gpio: msm: Add device tree and irqdomain support for gpio-msm-v2

drivers/gpio/Kconfig config GPIO_MSM_V1 · line 168

Quoted 10 lines
drivers/gpio/Kconfig +1 -1
index 87d5670..f3c1978 100644
@@ -165,7 +165,7 @@ config GPIO_MSM_V1
 
 config GPIO_MSM_V2
 	tristate "Qualcomm MSM GPIO v2"
-	depends on GPIOLIB && ARCH_MSM
+	depends on GPIOLIB && ARCH_MSM && OF

This doesn't actually rely on ARCH_MSM anymore so I think we can drop that dependency.

drivers/gpio/Kconfig static void msm_gpio_update_dual_edge_pos(unsigned gpio) · line 232

Quoted 9 lines
drivers/gpio/Kconfig +0 -1
 	help
 	  Say yes here to support the GPIO interface on ARM v7 based
 	  Qualcomm MSM chips.  Most of the pins on the MSM can be
@@ -222,7 +229,6 @@ static void msm_gpio_update_dual_edge_pos(unsigned gpio)
 		else
 			set_gpio_bits(BIT(INTR_POL_CTL), GPIO_INTR_CFG(gpio));
 		val2 = readl(GPIO_IN_OUT(gpio)) & BIT(GPIO_IN);
-		intstat = readl(GPIO_INTR_STATUS(gpio)) & BIT(INTR_STATUS);
 		if (intstat || val == val2)

Looks like intstat is used uninitialized now?

drivers/gpio/Kconfig static void msm_gpio_update_dual_edge_pos(unsigned gpio)

Quoted 9 lines
drivers/gpio/Kconfig +9 -0
+
+static int msm_gpio_probe(struct platform_device *pdev)
+{
+	int i, irq, ret, ngpio;
+	struct resource *res;
+
+	msm_gpio.gpio_chip.label = pdev->name;
+	msm_gpio.gpio_chip.dev = &pdev->dev;
+	of_property_read_u32(pdev->dev.of_node, "ngpio", &ngpio);

Fail probe if the property isn't there?

drivers/gpio/Kconfig

Quoted 13 lines
drivers/gpio/Kconfig +13 -0
+	msm_gpio.gpio_chip.ngpio = ngpio;
+
+	res = platform_get_resource(&pdev->dev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(&pdev->dev, "%s: no mem resource\n", __func__);
+		return -EINVAL;
+	}
+
+	msm_tlmm_base = devm_ioremap_resource(pdev->dev, res);
+	if (!msm_tlmm_base) {
+		dev_err(&pdev->dev, "Couldn't allocate memory for msm tlmm base\n");
+		return -ENOMEM;
+	}

devm_ioremap_resource() returns an ERR_PTR on failure, not NULL. Also, it already prints messages on errors so you can drop all the prints around this. Just do

	res = platform_get_resource(&pdev->dev, IORESOURCE_MEM, 0);
	msm_tlmm_base = devm_ioremap_resource(pdev->dev, res);
	if (IS_ERR(msm_tlmm_base))
		return ERR_PTR(msm_tlmm_base);
Quoted 10 lines

static int __init msm_gpio_init(void)
{

drivers/gpio/Kconfig +0 -8
-	int rc;
-
-	rc = platform_driver_register(&msm_gpio_driver);
-	if (!rc) {
-		rc = platform_device_register(&msm_device_gpio);
-		if (rc)
-			platform_driver_unregister(&msm_gpio_driver);
-	}

drivers/gpio/Kconfig

Quoted 10 lines
drivers/gpio/Kconfig +1 -3
-
-	return rc;
+	return platform_driver_register(&msm_gpio_driver);
 }
 
 static void __exit msm_gpio_exit(void)
 {
-	platform_device_unregister(&msm_device_gpio);
 	platform_driver_unregister(&msm_gpio_driver);
 }

You could use module_platform_driver here now too.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
hosted by The Linux Foundation
#6 lore raw

Re: [PATCH 3/3] gpio: msm: Add device tree and irqdomain support for gpio-msm-v2

Quoted 6 lines · Stephen Boyd
Quoted 6 lines
drivers/gpio/Kconfig +0 -0
index 87d5670..f3c1978 100644
@@ -165,7 +165,7 @@ config GPIO_MSM_V1
 
Quoted 6 lines

drivers/gpio/Kconfig config GPIO_MSM_V1 · line 168

Quoted 4 lines
drivers/gpio/Kconfig +1 -1
  config GPIO_MSM_V2
  	tristate "Qualcomm MSM GPIO v2"
-	depends on GPIOLIB && ARCH_MSM
+	depends on GPIOLIB && ARCH_MSM && OF

This doesn't actually rely on ARCH_MSM anymore so I think we can drop that dependency.

Done.

Quoted 11 lines

drivers/gpio/Kconfig static void msm_gpio_update_dual_edge_pos(unsigned gpio) · line 232

Quoted 10 lines
drivers/gpio/Kconfig +0 -1
  	help
  	  Say yes here to support the GPIO interface on ARM v7 based
  	  Qualcomm MSM chips.  Most of the pins on the MSM can be
@@ -222,7 +229,6 @@ static void msm_gpio_update_dual_edge_pos(unsigned gpio)
  		else
  			set_gpio_bits(BIT(INTR_POL_CTL), GPIO_INTR_CFG(gpio));
  		val2 = readl(GPIO_IN_OUT(gpio)) & BIT(GPIO_IN);
-		intstat = readl(GPIO_INTR_STATUS(gpio)) & BIT(INTR_STATUS);
  		if (intstat || val == val2)

Looks like intstat is used uninitialized now?

Thanks for catching this. Will fix this.

Quoted 11 lines

drivers/gpio/Kconfig static void msm_gpio_update_dual_edge_pos(unsigned gpio)

Quoted 10 lines
drivers/gpio/Kconfig +9 -0
+
+static int msm_gpio_probe(struct platform_device *pdev)
+{
+	int i, irq, ret, ngpio;
+	struct resource *res;
+
+	msm_gpio.gpio_chip.label = pdev->name;
+	msm_gpio.gpio_chip.dev = &pdev->dev;
+	of_property_read_u32(pdev->dev.of_node, "ngpio", &ngpio);

Fail probe if the property isn't there?

Done.

Quoted 18 lines
Quoted 4 lines
drivers/gpio/Kconfig +3 -0
+	msm_gpio.gpio_chip.ngpio = ngpio;
+
+	res = platform_get_resource(&pdev->dev, IORESOURCE_MEM, 0);

drivers/gpio/Kconfig

Quoted 10 lines
drivers/gpio/Kconfig +10 -0
+	if (!res) {
+		dev_err(&pdev->dev, "%s: no mem resource\n", __func__);
+		return -EINVAL;
+	}
+
+	msm_tlmm_base = devm_ioremap_resource(pdev->dev, res);
+	if (!msm_tlmm_base) {
+		dev_err(&pdev->dev, "Couldn't allocate memory for msm tlmm base\n");
+		return -ENOMEM;
+	}

devm_ioremap_resource() returns an ERR_PTR on failure, not NULL. Also, it already prints messages on errors so you can drop all the prints around this. Just do

Quoted 5 lines
	res = platform_get_resource(&pdev->dev, IORESOURCE_MEM, 0);
	msm_tlmm_base = devm_ioremap_resource(pdev->dev, res);
	if (IS_ERR(msm_tlmm_base))
		return ERR_PTR(msm_tlmm_base);

Done.

Quoted 15 lines
Quoted 15 lines
  static int __init msm_gpio_init(void)
  {
drivers/gpio/Kconfig +1 -10
-	int rc;
-
-	rc = platform_driver_register(&msm_gpio_driver);
-	if (!rc) {
-		rc = platform_device_register(&msm_device_gpio);
-		if (rc)
-			platform_driver_unregister(&msm_gpio_driver);
-	}
-
-	return rc;
+	return platform_driver_register(&msm_gpio_driver);
  }
Quoted 7 lines

drivers/gpio/Kconfig

Quoted 5 lines
  static void __exit msm_gpio_exit(void)
  {
drivers/gpio/Kconfig +0 -1
-	platform_device_unregister(&msm_device_gpio);
  	platform_driver_unregister(&msm_gpio_driver);
  }

You could use module_platform_driver here now too.

Done. Thanks for the comments.

Thanks,
Rohit Vaswani

Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
#7 lore raw

Re: [PATCH 3/3] gpio: msm: Add device tree and irqdomain support for gpio-msm-v2

In reply to Rohit Vaswani

Hi, Rohit

Thanks for the patch!

Quoted 6 lines · Rohit Vaswani

This cleans up the gpio-msm-v2 driver of all the global define usage. The number of gpios are now defined in the device tree. This enables adding irqdomain support as well.

---

<cut>

drivers/gpio/gpio-msm-v2.c static void msm_gpio_free(struct gpio_chip *chip, unsigned offset) · line 178

Quoted 10 lines

static DEFINE_SPINLOCK(tlmm_lock);

drivers/gpio/gpio-msm-v2.c +3 -1
@@ -168,18 +173,20 @@ static void msm_gpio_free(struct gpio_chip *chip, unsigned offset)
 
 static int msm_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
 {
-	return MSM_GPIO_TO_INT(chip->base + offset);
+	struct msm_gpio_dev *g_dev = to_msm_gpio_dev(chip);
+	struct irq_domain *domain = g_dev->domain;
+	return irq_create_mapping(domain, offset);

IMO here you should use irq_find_mapping() and create irq mapping once in .probe. See below comment.

Quoted 2 lines
(quoted diff) +0 -0
 }
 

<cut>

Quoted 16 lines
drivers/gpio/gpio-msm-v2.c +15 -1
-static int msm_gpio_probe(struct platform_device *dev)
+static struct lock_class_key msm_gpio_lock_class;
+
+static int msm_gpio_irq_domain_map(struct irq_domain *d, unsigned int irq,
+				   irq_hw_number_t hwirq)
+{
+	irq_set_lockdep_class(irq, &msm_gpio_lock_class);
+	irq_set_chip_and_handler(irq, &msm_gpio_irq_chip,
+			handle_level_irq);
+	set_irq_flags(irq, IRQF_VALID);
+
+	return 0;
+}
+
+static const struct irq_domain_ops msm_gpio_irq_domain_ops = {
+	.xlate = irq_domain_xlate_twocell,

drivers/gpio/gpio-msm-v2.c static struct irq_chip msm_gpio_irq_chip = { · line 384

Quoted 10 lines
drivers/gpio/gpio-msm-v2.c +8 -1
+	.map = msm_gpio_irq_domain_map,
+};
+
+static int msm_gpio_irqdomain_init(struct device_node *node, int ngpio)
 {
-	int i, irq, ret;
+	msm_gpio.domain = irq_domain_add_linear(node, ngpio,
+			&msm_gpio_irq_domain_ops, &msm_gpio);
+	if (!msm_gpio.domain) {
+		WARN(1, "Cannot allocate irq_domain\n");

Are you sure that we want to WARN if no memory? I'd return an error and fail the probe if the driver can't works without interrupts.

Quoted 49 lines
drivers/gpio/gpio-msm-v2.c +42 -5
+		return -ENOMEM;
+	}
+
+	return 0;
+}
+
+static int msm_gpio_probe(struct platform_device *pdev)
+{
+	int i, irq, ret, ngpio;
+	struct resource *res;
+
+	msm_gpio.gpio_chip.label = pdev->name;
+	msm_gpio.gpio_chip.dev = &pdev->dev;
+	of_property_read_u32(pdev->dev.of_node, "ngpio", &ngpio);
+	msm_gpio.gpio_chip.ngpio = ngpio;
+
+	res = platform_get_resource(&pdev->dev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(&pdev->dev, "%s: no mem resource\n", __func__);
+		return -EINVAL;
+	}
+
+	msm_tlmm_base = devm_ioremap_resource(pdev->dev, res);
+	if (!msm_tlmm_base) {
+		dev_err(&pdev->dev, "Couldn't allocate memory for msm tlmm base\n");
+		return -ENOMEM;
+	}
+
+	msm_gpio.enabled_irqs = devm_kzalloc(&pdev->dev,
+						sizeof(unsigned long) * ngpio,
+						GFP_KERNEL);
+	msm_gpio.wake_irqs = devm_kzalloc(&pdev->dev,
+						sizeof(unsigned long) * ngpio,
+						GFP_KERNEL);
+	msm_gpio.dual_edge_irqs = devm_kzalloc(&pdev->dev,
+						sizeof(unsigned long) * ngpio,
+						GFP_KERNEL);
+	bitmap_zero(msm_gpio.enabled_irqs, ngpio);
+	bitmap_zero(msm_gpio.wake_irqs, ngpio);
+	bitmap_zero(msm_gpio.dual_edge_irqs, ngpio);
 
-	bitmap_zero(msm_gpio.enabled_irqs, NR_GPIO_IRQS);
-	bitmap_zero(msm_gpio.wake_irqs, NR_GPIO_IRQS);
-	bitmap_zero(msm_gpio.dual_edge_irqs, NR_GPIO_IRQS);
-	msm_gpio.gpio_chip.label = dev->name;
 	ret = gpiochip_add(&msm_gpio.gpio_chip);
-	if (ret < 0)
+	if (ret < 0) {
+		dev_err(&pdev->dev, "gpiochip_add failed with error %d\n", ret);

drivers/gpio/gpio-msm-v2.c static struct irq_chip msm_gpio_irq_chip = { · line 438

Quoted 10 lines
drivers/gpio/gpio-msm-v2.c +9 -0
 		return ret;
+	}
+
+	summary_irq = platform_get_irq(pdev, 0);
+	if (summary_irq < 0) {
+		dev_err(&pdev->dev, "No Summary irq defined for msmgpio\n");
+		return summary_irq;
+	}
+
+	msm_gpio_irqdomain_init(pdev->dev.of_node, msm_gpio.gpio_chip.ngpio);

Adding irqdomain might fail, could you check the return value. And if irqdomain init fail do we need to set up chained handler for summary_irq at all?

drivers/gpio/gpio-msm-v2.c static struct irq_chip msm_gpio_irq_chip = { · line 441

Quoted 3 lines
drivers/gpio/gpio-msm-v2.c +0 -0
 	for (i = 0; i < msm_gpio.gpio_chip.ngpio; ++i) {
 		irq = msm_gpio_to_irq(&msm_gpio.gpio_chip, i);

I'd call irq_create_mapping() instead. This way the mapping will be created once in .probe and use irq_find_mapping() in gpio_to_irq.

drivers/gpio/gpio-msm-v2.c static struct irq_chip msm_gpio_irq_chip = { · line 445

Quoted 4 lines
drivers/gpio/gpio-msm-v2.c +1 -0
+		irq_set_lockdep_class(irq, &msm_gpio_lock_class);
 		irq_set_chip_and_handler(irq, &msm_gpio_irq_chip,
 					 handle_level_irq);
 		set_irq_flags(irq, IRQF_VALID);

These three function calls are not needed anymore because irq_create_mapping() will call internally irqdomain .map operation. The .map already calls these three functions.

drivers/gpio/gpio-msm-v2.c static struct irq_chip msm_gpio_irq_chip = { · line 451

Quoted 9 lines
drivers/gpio/gpio-msm-v2.c +2 -2
 	}
 
-	irq_set_chained_handler(TLMM_SCSS_SUMMARY_IRQ,
-				msm_summary_irq_handler);
+	irq_set_chained_handler(summary_irq, msm_summary_irq_handler);
+
 	return 0;
 }

- Stan

#8 lore raw

Re: [PATCH 3/3] gpio: msm: Add device tree and irqdomain support for gpio-msm-v2

Quoted 3 lines · Stanimir Varbanov

Hi, Rohit

Thanks for the patch!

Thanks for the comments... more below

Quoted 14 lines · Rohit Vaswani
Quoted 6 lines

This cleans up the gpio-msm-v2 driver of all the global define usage. The number of gpios are now defined in the device tree. This enables adding irqdomain support as well.

---

<cut>

Quoted 4 lines
  
  static DEFINE_SPINLOCK(tlmm_lock);
(quoted diff) +0 -0
@@ -168,18 +173,20 @@ static void msm_gpio_free(struct gpio_chip *chip, unsigned offset)
 
Quoted 8 lines

drivers/gpio/gpio-msm-v2.c static void msm_gpio_free(struct gpio_chip *chip, unsigned offset) · line 178

Quoted 6 lines
drivers/gpio/gpio-msm-v2.c +3 -1
  static int msm_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
  {
-	return MSM_GPIO_TO_INT(chip->base + offset);
+	struct msm_gpio_dev *g_dev = to_msm_gpio_dev(chip);
+	struct irq_domain *domain = g_dev->domain;
+	return irq_create_mapping(domain, offset);

IMO here you should use irq_find_mapping() and create irq mapping once in .probe. See below comment.

Looking at this more, I would prefer to get rid of the entire for loop and the irq_create_mapping in probe and
just have the irq_create_mapping in msm_gpio_to_irq. This way we are not allocating a descriptor for every gpio and only for the ones that call the msm_gpio_to_irq.

Quoted 25 lines
Quoted 3 lines
(quoted diff) +0 -0
  }
 

<cut>

Quoted 20 lines
drivers/gpio/gpio-msm-v2.c +19 -1
-static int msm_gpio_probe(struct platform_device *dev)
+static struct lock_class_key msm_gpio_lock_class;
+
+static int msm_gpio_irq_domain_map(struct irq_domain *d, unsigned int irq,
+				   irq_hw_number_t hwirq)
+{
+	irq_set_lockdep_class(irq, &msm_gpio_lock_class);
+	irq_set_chip_and_handler(irq, &msm_gpio_irq_chip,
+			handle_level_irq);
+	set_irq_flags(irq, IRQF_VALID);
+
+	return 0;
+}
+
+static const struct irq_domain_ops msm_gpio_irq_domain_ops = {
+	.xlate = irq_domain_xlate_twocell,
+	.map = msm_gpio_irq_domain_map,
+};
+
+static int msm_gpio_irqdomain_init(struct device_node *node, int ngpio)
Quoted 8 lines

drivers/gpio/gpio-msm-v2.c static struct irq_chip msm_gpio_irq_chip = { · line 384

Quoted 6 lines
  {
drivers/gpio/gpio-msm-v2.c +4 -1
-	int i, irq, ret;
+	msm_gpio.domain = irq_domain_add_linear(node, ngpio,
+			&msm_gpio_irq_domain_ops, &msm_gpio);
+	if (!msm_gpio.domain) {
+		WARN(1, "Cannot allocate irq_domain\n");

Are you sure that we want to WARN if no memory? I'd return an error and fail the probe if the driver can't works without interrupts.

Done.

Quoted 55 lines
Quoted 55 lines
drivers/gpio/gpio-msm-v2.c +46 -5
+		return -ENOMEM;
+	}
+
+	return 0;
+}
+
+static int msm_gpio_probe(struct platform_device *pdev)
+{
+	int i, irq, ret, ngpio;
+	struct resource *res;
+
+	msm_gpio.gpio_chip.label = pdev->name;
+	msm_gpio.gpio_chip.dev = &pdev->dev;
+	of_property_read_u32(pdev->dev.of_node, "ngpio", &ngpio);
+	msm_gpio.gpio_chip.ngpio = ngpio;
+
+	res = platform_get_resource(&pdev->dev, IORESOURCE_MEM, 0);
+	if (!res) {
+		dev_err(&pdev->dev, "%s: no mem resource\n", __func__);
+		return -EINVAL;
+	}
+
+	msm_tlmm_base = devm_ioremap_resource(pdev->dev, res);
+	if (!msm_tlmm_base) {
+		dev_err(&pdev->dev, "Couldn't allocate memory for msm tlmm base\n");
+		return -ENOMEM;
+	}
+
+	msm_gpio.enabled_irqs = devm_kzalloc(&pdev->dev,
+						sizeof(unsigned long) * ngpio,
+						GFP_KERNEL);
+	msm_gpio.wake_irqs = devm_kzalloc(&pdev->dev,
+						sizeof(unsigned long) * ngpio,
+						GFP_KERNEL);
+	msm_gpio.dual_edge_irqs = devm_kzalloc(&pdev->dev,
+						sizeof(unsigned long) * ngpio,
+						GFP_KERNEL);
+	bitmap_zero(msm_gpio.enabled_irqs, ngpio);
+	bitmap_zero(msm_gpio.wake_irqs, ngpio);
+	bitmap_zero(msm_gpio.dual_edge_irqs, ngpio);
 
-	bitmap_zero(msm_gpio.enabled_irqs, NR_GPIO_IRQS);
-	bitmap_zero(msm_gpio.wake_irqs, NR_GPIO_IRQS);
-	bitmap_zero(msm_gpio.dual_edge_irqs, NR_GPIO_IRQS);
-	msm_gpio.gpio_chip.label = dev->name;
  	ret = gpiochip_add(&msm_gpio.gpio_chip);
-	if (ret < 0)
+	if (ret < 0) {
+		dev_err(&pdev->dev, "gpiochip_add failed with error %d\n", ret);
  		return ret;
+	}
+
+	summary_irq = platform_get_irq(pdev, 0);
+	if (summary_irq < 0) {
Quoted 8 lines

drivers/gpio/gpio-msm-v2.c static struct irq_chip msm_gpio_irq_chip = { · line 438

Quoted 5 lines
drivers/gpio/gpio-msm-v2.c +5 -0
+		dev_err(&pdev->dev, "No Summary irq defined for msmgpio\n");
+		return summary_irq;
+	}
+
+	msm_gpio_irqdomain_init(pdev->dev.of_node, msm_gpio.gpio_chip.ngpio);

Adding irqdomain might fail, could you check the return value. And if irqdomain init fail do we need to set up chained handler for summary_irq at all?

Done.

Quoted 6 lines
Quoted 4 lines
  
  	for (i = 0; i < msm_gpio.gpio_chip.ngpio; ++i) {
  		irq = msm_gpio_to_irq(&msm_gpio.gpio_chip, i);

I'd call irq_create_mapping() instead. This way the mapping will be created once in .probe and use irq_find_mapping() in gpio_to_irq.

Will get rid of this for loop as mentioned above. Thanks for catching this.

Quoted 8 lines

drivers/gpio/gpio-msm-v2.c static struct irq_chip msm_gpio_irq_chip = { · line 445

Quoted 5 lines
drivers/gpio/gpio-msm-v2.c +1 -0
+		irq_set_lockdep_class(irq, &msm_gpio_lock_class);
  		irq_set_chip_and_handler(irq, &msm_gpio_irq_chip,
  					 handle_level_irq);
  		set_irq_flags(irq, IRQF_VALID);

These three function calls are not needed anymore because irq_create_mapping() will call internally irqdomain .map operation. The .map already calls these three functions.

Done.

Quoted 11 lines

drivers/gpio/gpio-msm-v2.c static struct irq_chip msm_gpio_irq_chip = { · line 451

Quoted 10 lines
  	}
drivers/gpio/gpio-msm-v2.c +2 -2
-	irq_set_chained_handler(TLMM_SCSS_SUMMARY_IRQ,
-				msm_summary_irq_handler);
+	irq_set_chained_handler(summary_irq, msm_summary_irq_handler);
+
  	return 0;
  }

- Stan

Thanks,
Rohit Vaswani

Signature · 1 line
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, hosted by The Linux Foundation
#9 lore raw
In reply to Rohit Vaswani
Quoted 3 lines · Rohit Vaswani

Hi Linus,
Could this series go through David's tree or is there a better way to do this? It would be great if I can have you ack for the gpio patch.

Yep ACKed, go ahead.

Yours,
Linus Walleij