Skip to contentSkip to conversation

Cleanup MSM_GPIOMUX and add DT support for gpio-msm

PATCH Superseded Rohit Vaswani 3 participants 9 messages Jun 1, 2013 – Jun 17, 2013

Subsystems (5)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover Cleanup MSM_GPIOMUX and add DT support for gpio-msm

v4:
for gpio-msm-v2 patch
* Made summary_irq and tlmm_base part of msm_gpio_dev
* Fixed the bitmap allocation
* Fixed some compile issues with non-ARM

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                         |  199 ++++++++++++--------
 13 files changed, 189 insertions(+), 208 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 v4 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 v4 1/3
#2 lore raw

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

Quoted 16 lines · Rohit Vaswani

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

Yours,
Linus Walleij

#3 lore raw

PATCH v4 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 v4 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                         |  194 ++++++++++++--------
 5 files changed, 165 insertions(+), 79 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..6d61a12 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 && OF && ARCH_MSM
 	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 +116 -78

294 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: [PATCHv4 3/3] gpio: msm: Add device tree and irqdomain support for gpio-msm-v2

Quoted 144 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.

---
 .../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                         |  194 ++++++++++++--------
 5 files changed, 165 insertions(+), 79 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..6d61a12 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 && OF && ARCH_MSM
        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 +4 -9
index 75cc821..5a824be 100644
@@ -19,17 +19,19 @@
 
 #include <linux/bitmap.h>
 #include <linux/bitops.h>
+#include <linux/err.h>
 #include <linux/gpio.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/irqchip/chained_irq.h>
 #include <linux/irq.h>
+#include <linux/irqdomain.h>
 #include <linux/module.h>
+#include <linux/of_address.h>
 #include <linux/platform_device.h>
 #include <linux/spinlock.h>
-
-#include <mach/msm_iomap.h>
+#include <linux/slab.h>
 
 /* Bits of interest in the GPIO_IN_OUT register.
  */
@@ -76,13 +78,6 @@ enum {
        TARGET_PROC_NONE     = 7,
 };
 
-
-#define GPIO_INTR_CFG_SU(gpio)    (MSM_TLMM_BASE + 0x0400 + (0x04 * (gpio)))
-#define GPIO_CONFIG(gpio)         (MSM_TLMM_BASE + 0x1000 + (0x10 * (gpio)))
-#define GPIO_IN_OUT(gpio)         (MSM_TLMM_BASE + 0x1004 + (0x10 * (gpio)))
-#define GPIO_INTR_CFG(gpio)       (MSM_TLMM_BASE + 0x1008 + (0x10 * (gpio)))
-#define GPIO_INTR_STATUS(gpio)    (MSM_TLMM_BASE + 0x100c + (0x10 * (gpio)))
-
 /**
  * struct msm_gpio_dev: the MSM8660 SoC GPIO device structure
  *

drivers/gpio/gpio-msm-v2.c enum { · line 101

Quoted 9 lines
drivers/gpio/gpio-msm-v2.c +3 -3
@@ -101,11 +96,27 @@ enum {
  */
 struct msm_gpio_dev {
        struct gpio_chip gpio_chip;
-       DECLARE_BITMAP(enabled_irqs, NR_GPIO_IRQS);
-       DECLARE_BITMAP(wake_irqs, NR_GPIO_IRQS);
-       DECLARE_BITMAP(dual_edge_irqs, NR_GPIO_IRQS);
+       unsigned long *enabled_irqs;
+       unsigned long *wake_irqs;
+       unsigned long *dual_edge_irqs;

Was there a reason you ignored the comment to leave these bitmaps as statically allocated?

[...]

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

Quoted 7 lines
drivers/gpio/gpio-msm-v2.c +7 -0
+       msm_gpio.enabled_irqs = devm_kzalloc(&pdev->dev,
+                                               sizeof(unsigned long) *
+                                               BITS_TO_LONGS(ngpio) * 3,
+                                               GFP_KERNEL);
+       msm_gpio.wake_irqs = &msm_gpio.enabled_irqs[BITS_TO_LONGS(ngpio)];
+       msm_gpio.dual_edge_irqs =
+                       &msm_gpio.enabled_irqs[BITS_TO_LONGS(ngpio * 2)];

I should have just deleted my comment about doing it this way. I was making the point that one allocation is better that three; but then I also said that it was better to not allocate at all. Go back to the statically allocated bitmap array. It is far better than this.

g.

#6 lore raw

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

Quoted 166 lines · Grant Likely
Quoted 144 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.

---
  .../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                         |  194 ++++++++++++--------
  5 files changed, 165 insertions(+), 79 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..6d61a12 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 && OF && ARCH_MSM
         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 +4 -9
index 75cc821..5a824be 100644
@@ -19,17 +19,19 @@
 
  #include <linux/bitmap.h>
  #include <linux/bitops.h>
+#include <linux/err.h>
  #include <linux/gpio.h>
  #include <linux/init.h>
  #include <linux/interrupt.h>
  #include <linux/io.h>
  #include <linux/irqchip/chained_irq.h>
  #include <linux/irq.h>
+#include <linux/irqdomain.h>
  #include <linux/module.h>
+#include <linux/of_address.h>
  #include <linux/platform_device.h>
  #include <linux/spinlock.h>
-
-#include <mach/msm_iomap.h>
+#include <linux/slab.h>
 
  /* Bits of interest in the GPIO_IN_OUT register.
   */
@@ -76,13 +78,6 @@ enum {
         TARGET_PROC_NONE     = 7,
  };
 
-
-#define GPIO_INTR_CFG_SU(gpio)    (MSM_TLMM_BASE + 0x0400 + (0x04 * (gpio)))
-#define GPIO_CONFIG(gpio)         (MSM_TLMM_BASE + 0x1000 + (0x10 * (gpio)))
-#define GPIO_IN_OUT(gpio)         (MSM_TLMM_BASE + 0x1004 + (0x10 * (gpio)))
-#define GPIO_INTR_CFG(gpio)       (MSM_TLMM_BASE + 0x1008 + (0x10 * (gpio)))
-#define GPIO_INTR_STATUS(gpio)    (MSM_TLMM_BASE + 0x100c + (0x10 * (gpio)))
-
  /**
   * struct msm_gpio_dev: the MSM8660 SoC GPIO device structure
   *

drivers/gpio/gpio-msm-v2.c enum { · line 101

Quoted 9 lines
drivers/gpio/gpio-msm-v2.c +3 -3
@@ -101,11 +96,27 @@ enum {
   */
  struct msm_gpio_dev {
         struct gpio_chip gpio_chip;
-       DECLARE_BITMAP(enabled_irqs, NR_GPIO_IRQS);
-       DECLARE_BITMAP(wake_irqs, NR_GPIO_IRQS);
-       DECLARE_BITMAP(dual_edge_irqs, NR_GPIO_IRQS);
+       unsigned long *enabled_irqs;
+       unsigned long *wake_irqs;
+       unsigned long *dual_edge_irqs;

Was there a reason you ignored the comment to leave these bitmaps as statically allocated?

[...]

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

Quoted 7 lines
drivers/gpio/gpio-msm-v2.c +7 -0
+       msm_gpio.enabled_irqs = devm_kzalloc(&pdev->dev,
+                                               sizeof(unsigned long) *
+                                               BITS_TO_LONGS(ngpio) * 3,
+                                               GFP_KERNEL);
+       msm_gpio.wake_irqs = &msm_gpio.enabled_irqs[BITS_TO_LONGS(ngpio)];
+       msm_gpio.dual_edge_irqs =
+                       &msm_gpio.enabled_irqs[BITS_TO_LONGS(ngpio * 2)];
Quoted 6 lines

I should have just deleted my comment about doing it this way. I was making the point that one allocation is better that three; but then I also said that it was better to not allocate at all. Go back to the statically allocated bitmap array. It is far better than this.

g.

I agree that DECLARE_BITMAP is the most efficient way, but DECLARE_BITMAP takes a statically defined number of gpios as an argument. Since we get the ngpio from device tree, these had to go as well. Under this scheme, 1 allocation was better than 3 and went ahead with your suggestion.

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: [PATCHv4 3/3] gpio: msm: Add device tree and irqdomain support for gpio-msm-v2

Quoted 34 lines · Rohit Vaswani
Quoted 33 lines · Grant Likely
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.

drivers/gpio/gpio-msm-v2.c enum { · line 101

Quoted 9 lines
drivers/gpio/gpio-msm-v2.c +3 -3
@@ -101,11 +96,27 @@ enum {
   */
  struct msm_gpio_dev {
         struct gpio_chip gpio_chip;
-       DECLARE_BITMAP(enabled_irqs, NR_GPIO_IRQS);
-       DECLARE_BITMAP(wake_irqs, NR_GPIO_IRQS);
-       DECLARE_BITMAP(dual_edge_irqs, NR_GPIO_IRQS);
+       unsigned long *enabled_irqs;
+       unsigned long *wake_irqs;
+       unsigned long *dual_edge_irqs;

Was there a reason you ignored the comment to leave these bitmaps as statically allocated?

[...]

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

Quoted 7 lines
drivers/gpio/gpio-msm-v2.c +7 -0
+       msm_gpio.enabled_irqs = devm_kzalloc(&pdev->dev,
+                                               sizeof(unsigned long) *
+                                               BITS_TO_LONGS(ngpio) * 3,
+                                               GFP_KERNEL);
+       msm_gpio.wake_irqs = &msm_gpio.enabled_irqs[BITS_TO_LONGS(ngpio)];
+       msm_gpio.dual_edge_irqs =
+                       &msm_gpio.enabled_irqs[BITS_TO_LONGS(ngpio * 2)];

I should have just deleted my comment about doing it this way. I was making the point that one allocation is better that three; but then I also said that it was better to not allocate at all. Go back to the statically allocated bitmap array. It is far better than this.

Quoted 7 lines
Quoted 1 line

g.

I agree that DECLARE_BITMAP is the most efficient way, but DECLARE_BITMAP takes a statically defined number of gpios as an argument. Since we get the ngpio from device tree, these had to go as well. Under this scheme, 1 allocation was better than 3 and went ahead with your suggestion.

Think about it for a moment; You *know* all the devices that are going to use the driver. The largest size for ngpios that I see is 173 which is a mere 18 long words for 3 bitmaps. Even if you were to quadruple that amount the total for all the bitmasks is 72 long words. You're optimizing at the wrong place. Changing it to dynamic allocation makes the code slower, more complicated, and probably doesn't do anything to save on real memory consumption.

The solution is simple; choose a maximum value of ngpios that the driver will likely need to work support. If a device appears with more GPIOs, then the driver should throw a warning and work with the maximum it can support. Part of enablement for the new device will be increasing the driver to handle more gpios.

g.

#8 lore raw

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

Quoted 49 lines · Grant Likely
Quoted 34 lines · Rohit Vaswani
Quoted 33 lines · Grant Likely
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.

drivers/gpio/gpio-msm-v2.c enum { · line 101

Quoted 9 lines
drivers/gpio/gpio-msm-v2.c +3 -3
@@ -101,11 +96,27 @@ enum {
    */
   struct msm_gpio_dev {
          struct gpio_chip gpio_chip;
-       DECLARE_BITMAP(enabled_irqs, NR_GPIO_IRQS);
-       DECLARE_BITMAP(wake_irqs, NR_GPIO_IRQS);
-       DECLARE_BITMAP(dual_edge_irqs, NR_GPIO_IRQS);
+       unsigned long *enabled_irqs;
+       unsigned long *wake_irqs;
+       unsigned long *dual_edge_irqs;

Was there a reason you ignored the comment to leave these bitmaps as statically allocated?

[...]

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

Quoted 7 lines
drivers/gpio/gpio-msm-v2.c +7 -0
+       msm_gpio.enabled_irqs = devm_kzalloc(&pdev->dev,
+                                               sizeof(unsigned long) *
+                                               BITS_TO_LONGS(ngpio) * 3,
+                                               GFP_KERNEL);
+       msm_gpio.wake_irqs = &msm_gpio.enabled_irqs[BITS_TO_LONGS(ngpio)];
+       msm_gpio.dual_edge_irqs =
+                       &msm_gpio.enabled_irqs[BITS_TO_LONGS(ngpio * 2)];

I should have just deleted my comment about doing it this way. I was making the point that one allocation is better that three; but then I also said that it was better to not allocate at all. Go back to the statically allocated bitmap array. It is far better than this.

Quoted 6 lines
Quoted 1 line

g.

I agree that DECLARE_BITMAP is the most efficient way, but DECLARE_BITMAP takes a statically defined number of gpios as an argument. Since we get the ngpio from device tree, these had to go as well. Under this scheme, 1 allocation was better than 3 and went ahead with your suggestion.

Think about it for a moment; You *know* all the devices that are going to use the driver. The largest size for ngpios that I see is 173 which is a mere 18 long words for 3 bitmaps. Even if you were to quadruple that amount the total for all the bitmasks is 72 long words. You're optimizing at the wrong place. Changing it to dynamic allocation makes the code slower, more complicated, and probably doesn't do anything to save on real memory consumption.

Quoted 7 lines

The solution is simple; choose a maximum value of ngpios that the driver will likely need to work support. If a device appears with more GPIOs, then the driver should throw a warning and work with the maximum it can support. Part of enablement for the new device will be increasing the driver to handle more gpios.

g.

Got it.

Thanks,
Rohit Vaswani

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