linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/7] Renesas RZ/G2L IRQC support
@ 2022-05-18 19:29 Lad Prabhakar
  2022-05-18 19:29 ` [PATCH v4 1/7] dt-bindings: interrupt-controller: Add Renesas RZ/G2L Interrupt Controller Lad Prabhakar
                   ` (7 more replies)
  0 siblings, 8 replies; 20+ messages in thread
From: Lad Prabhakar @ 2022-05-18 19:29 UTC (permalink / raw)
  To: Marc Zyngier, Geert Uytterhoeven, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Linus Walleij, Bartosz Golaszewski,
	Thierry Reding, Jonathan Hunter, Bjorn Andersson, Andy Gross,
	Philipp Zabel, Andy Shevchenko, linux-gpio, linux-tegra,
	linux-arm-msm, devicetree
  Cc: linux-kernel, Prabhakar, linux-renesas-soc, Phil Edworthy,
	Biju Das, Lad Prabhakar

Hi All,

The RZ/G2L Interrupt Controller is a front-end for the GIC found on
Renesas RZ/G2L SoC's with below pins:
- IRQ sense select for 8 external interrupts, mapped to 8 GIC SPI
  interrupts
- GPIO pins used as external interrupt input pins out of GPIOINT0-122 a
  maximum of only 32 can be mapped to 32 GIC SPI interrupts,
- NMI edge select.

                                                             _____________
                                                             |    GIC     |
                                                             |  ________  |
                                      ____________           | |        | |
NMI --------------------------------->|          |  SPI0-479 | | GIC-600| |
             _______                  |          |------------>|        | |
             |      |                 |          |  PPI16-31 | |        | |
             |      | IRQ0-IRQ7       |   IRQC   |------------>|        | |
P0_P48_4 --->| GPIO |---------------->|          |           | |________| |
             |      |GPIOINT0-122     |          |           |            |
             |      |---------------->| TINT0-31 |           |            |
             |______|                 |__________|           |____________|

The proposed patches add hierarchical IRQ domain, one in IRQC driver and
another in pinctrl driver. Upon interrupt requests map the interrupt to
GIC. Out of GPIOINT0-122 only 32 can be mapped to GIC SPI, this mapping is
handled by the pinctrl and IRQC driver.

Cheers,
Prabhakar

Changes for v3->v4:
* Updated description for interrupts-cells property in patch #1
* Dropped the patch which overriding free callback in gpiolib
* Used devm helpers in patch#2
* Patch #4, #5 and #6 are newly added
* In patch #7 dropped using gpio offset as hwirq
* Implemented immutable GPIO in patch #7
* Implemented child_offset_to_irq() callback in patch #7

Changes for v2->v3:
* Updated description for interrupts-cells property in patch #1
* Included RB tag from Geert for binding patch
* Fixed review comments pointed by Geert, Biju and Sergei.

Changes for v1->v2:
* Included RB tag from Rob
* Fixed review comments pointed by Geert
* included GPIO driver changes

Changes for RFCV4 -> V1:
* Used unevaluatedProperties.
* Altered the sequence of reg property
* Set the parent type
* Used raw_spin_lock() instead of raw_spin_lock_irqsave()
* Simplified parsing IRQ map.
* Will send the GPIO and pinctrl changes as part of separate series

Changes for RFC v4:
* Used locking while RMW
* Now using interrupts property instead of interrupt-map
* Patch series depends on [0]
* Updated binding doc
* Fixed comments pointed by Andy

[0] https://patchwork.kernel.org/project/linux-renesas-soc/patch/
20220316200633.28974-1-prabhakar.mahadev-lad.rj@xxxxxxxxxxxxxx/

Changes for RFC v3:
-> Re-structured the driver as a hierarchical irq domain instead of chained
-> made use of IRQCHIP_* macros
-> dropped locking
-> Added support for IRQ0-7 interrupts
-> Introduced 2 new patches for GPIOLIB
-> Switched to using GPIOLIB for irqdomains in pinctrl

RFC v2: https://patchwork.kernel.org/project/linux-renesas-soc/cover/
20210921193028.13099-1-prabhakar.mahadev-lad.rj@xxxxxxxxxxxxxx/

RFC v1: https://patchwork.kernel.org/project/linux-renesas-soc/cover/
20210803175109.1729-1-prabhakar.mahadev-lad.rj@xxxxxxxxxxxxxx/

Lad Prabhakar (7):
  dt-bindings: interrupt-controller: Add Renesas RZ/G2L Interrupt
    Controller
  irqchip: Add RZ/G2L IA55 Interrupt Controller driver
  gpio: gpiolib: Add ngirq member to struct gpio_irq_chip
  gpio: gpiolib: Dont assume child_offset_to_irq callback always
    succeeds
  gpio: gpiolib: Add a check to validate GPIO hwirq
  dt-bindings: pinctrl: renesas,rzg2l-pinctrl: Document the properties
    to handle GPIO IRQ
  pinctrl: renesas: pinctrl-rzg2l: Add IRQ domain to handle GPIO
    interrupt

 .../renesas,rzg2l-irqc.yaml                   | 133 ++++++
 .../pinctrl/renesas,rzg2l-pinctrl.yaml        |  16 +
 drivers/gpio/gpio-tegra186.c                  |  14 +-
 drivers/gpio/gpiolib.c                        |  38 +-
 drivers/irqchip/Kconfig                       |   8 +
 drivers/irqchip/Makefile                      |   1 +
 drivers/irqchip/irq-renesas-rzg2l.c           | 425 ++++++++++++++++++
 drivers/pinctrl/qcom/pinctrl-spmi-gpio.c      |   7 +-
 drivers/pinctrl/qcom/pinctrl-spmi-mpp.c       |   7 +-
 drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c      |   7 +-
 drivers/pinctrl/qcom/pinctrl-ssbi-mpp.c       |   7 +-
 drivers/pinctrl/renesas/pinctrl-rzg2l.c       | 221 +++++++++
 include/linux/gpio/driver.h                   |  17 +-
 13 files changed, 880 insertions(+), 21 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/renesas,rzg2l-irqc.yaml
 create mode 100644 drivers/irqchip/irq-renesas-rzg2l.c

-- 
2.25.1


^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v4 1/7] dt-bindings: interrupt-controller: Add Renesas RZ/G2L Interrupt Controller
  2022-05-18 19:29 [PATCH v4 0/7] Renesas RZ/G2L IRQC support Lad Prabhakar
@ 2022-05-18 19:29 ` Lad Prabhakar
  2022-05-18 19:29 ` [PATCH v4 2/7] irqchip: Add RZ/G2L IA55 Interrupt Controller driver Lad Prabhakar
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 20+ messages in thread
From: Lad Prabhakar @ 2022-05-18 19:29 UTC (permalink / raw)
  To: Marc Zyngier, Geert Uytterhoeven, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Linus Walleij, Bartosz Golaszewski,
	Thierry Reding, Jonathan Hunter, Bjorn Andersson, Andy Gross,
	Philipp Zabel, Andy Shevchenko, linux-gpio, linux-tegra,
	linux-arm-msm, devicetree
  Cc: linux-kernel, Prabhakar, linux-renesas-soc, Phil Edworthy,
	Biju Das, Lad Prabhakar

Add DT bindings for the Renesas RZ/G2L Interrupt Controller.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
---
 .../renesas,rzg2l-irqc.yaml                   | 133 ++++++++++++++++++
 1 file changed, 133 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/interrupt-controller/renesas,rzg2l-irqc.yaml

diff --git a/Documentation/devicetree/bindings/interrupt-controller/renesas,rzg2l-irqc.yaml b/Documentation/devicetree/bindings/interrupt-controller/renesas,rzg2l-irqc.yaml
new file mode 100644
index 000000000000..ffbb4ab4d9a7
--- /dev/null
+++ b/Documentation/devicetree/bindings/interrupt-controller/renesas,rzg2l-irqc.yaml
@@ -0,0 +1,133 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/interrupt-controller/renesas,rzg2l-irqc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Renesas RZ/G2L (and alike SoC's) Interrupt Controller (IA55)
+
+maintainers:
+  - Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
+  - Geert Uytterhoeven <geert+renesas@glider.be>
+
+description: |
+  IA55 performs various interrupt controls including synchronization for the external
+  interrupts of NMI, IRQ, and GPIOINT and the interrupts of the built-in peripheral
+  interrupts output by each IP. And it notifies the interrupt to the GIC
+    - IRQ sense select for 8 external interrupts, mapped to 8 GIC SPI interrupts
+    - GPIO pins used as external interrupt input pins, mapped to 32 GIC SPI interrupts
+    - NMI edge select (NMI is not treated as NMI exception and supports fall edge and
+      stand-up edge detection interrupts)
+
+allOf:
+  - $ref: /schemas/interrupt-controller.yaml#
+
+properties:
+  compatible:
+    items:
+      - enum:
+          - renesas,r9a07g044-irqc    # RZ/G2L
+      - const: renesas,rzg2l-irqc
+
+  '#interrupt-cells':
+    description: The first cell should contain external interrupt number (IRQ0-7) and the
+                 second cell is used to specify the flag.
+    const: 2
+
+  '#address-cells':
+    const: 0
+
+  interrupt-controller: true
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 41
+
+  clocks:
+    maxItems: 2
+
+  clock-names:
+    items:
+      - const: clk
+      - const: pclk
+
+  power-domains:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+required:
+  - compatible
+  - '#interrupt-cells'
+  - '#address-cells'
+  - interrupt-controller
+  - reg
+  - interrupts
+  - clocks
+  - clock-names
+  - power-domains
+  - resets
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/clock/r9a07g044-cpg.h>
+
+    irqc: interrupt-controller@110a0000 {
+            compatible = "renesas,r9a07g044-irqc", "renesas,rzg2l-irqc";
+            reg = <0x110a0000 0x10000>;
+            #interrupt-cells = <2>;
+            #address-cells = <0>;
+            interrupt-controller;
+            interrupts = <GIC_SPI 0 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 1 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 2 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 3 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 4 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 5 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 6 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 7 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 8 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 444 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 445 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 446 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 447 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 448 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 449 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 450 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 451 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 452 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 453 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 454 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 455 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 456 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 457 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 458 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 459 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 460 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 461 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 462 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 463 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 464 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 465 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 466 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 467 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 468 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 469 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 470 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 471 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 472 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 473 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 474 IRQ_TYPE_LEVEL_HIGH>,
+                         <GIC_SPI 475 IRQ_TYPE_LEVEL_HIGH>;
+            clocks = <&cpg CPG_MOD R9A07G044_IA55_CLK>,
+                     <&cpg CPG_MOD R9A07G044_IA55_PCLK>;
+            clock-names = "clk", "pclk";
+            power-domains = <&cpg>;
+            resets = <&cpg R9A07G044_IA55_RESETN>;
+    };
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v4 2/7] irqchip: Add RZ/G2L IA55 Interrupt Controller driver
  2022-05-18 19:29 [PATCH v4 0/7] Renesas RZ/G2L IRQC support Lad Prabhakar
  2022-05-18 19:29 ` [PATCH v4 1/7] dt-bindings: interrupt-controller: Add Renesas RZ/G2L Interrupt Controller Lad Prabhakar
@ 2022-05-18 19:29 ` Lad Prabhakar
  2022-05-18 19:29 ` [PATCH v4 3/7] gpio: gpiolib: Add ngirq member to struct gpio_irq_chip Lad Prabhakar
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 20+ messages in thread
From: Lad Prabhakar @ 2022-05-18 19:29 UTC (permalink / raw)
  To: Marc Zyngier, Geert Uytterhoeven, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Linus Walleij, Bartosz Golaszewski,
	Thierry Reding, Jonathan Hunter, Bjorn Andersson, Andy Gross,
	Philipp Zabel, Andy Shevchenko, linux-gpio, linux-tegra,
	linux-arm-msm, devicetree
  Cc: linux-kernel, Prabhakar, linux-renesas-soc, Phil Edworthy,
	Biju Das, Lad Prabhakar

Add a driver for the Renesas RZ/G2L Interrupt Controller.

This supports external pins being used as interrupts. It supports
one line for NMI, 8 external pins and 32 GPIO pins (out of 123)
to be used as IRQ lines.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
 drivers/irqchip/Kconfig             |   8 +
 drivers/irqchip/Makefile            |   1 +
 drivers/irqchip/irq-renesas-rzg2l.c | 425 ++++++++++++++++++++++++++++
 3 files changed, 434 insertions(+)
 create mode 100644 drivers/irqchip/irq-renesas-rzg2l.c

diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index 15edb9a6fcae..f3d071422f3b 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -242,6 +242,14 @@ config RENESAS_RZA1_IRQC
 	  Enable support for the Renesas RZ/A1 Interrupt Controller, to use up
 	  to 8 external interrupts with configurable sense select.
 
+config RENESAS_RZG2L_IRQC
+	bool "Renesas RZ/G2L (and alike SoC) IRQC support" if COMPILE_TEST
+	select GENERIC_IRQ_CHIP
+	select IRQ_DOMAIN_HIERARCHY
+	help
+	  Enable support for the Renesas RZ/G2L (and alike SoC) Interrupt Controller
+	  for external devices.
+
 config SL28CPLD_INTC
 	bool "Kontron sl28cpld IRQ controller"
 	depends on MFD_SL28CPLD=y || COMPILE_TEST
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index 160a1d8ceaa9..eaa56eec2b23 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -51,6 +51,7 @@ obj-$(CONFIG_RDA_INTC)			+= irq-rda-intc.o
 obj-$(CONFIG_RENESAS_INTC_IRQPIN)	+= irq-renesas-intc-irqpin.o
 obj-$(CONFIG_RENESAS_IRQC)		+= irq-renesas-irqc.o
 obj-$(CONFIG_RENESAS_RZA1_IRQC)		+= irq-renesas-rza1.o
+obj-$(CONFIG_RENESAS_RZG2L_IRQC)	+= irq-renesas-rzg2l.o
 obj-$(CONFIG_VERSATILE_FPGA_IRQ)	+= irq-versatile-fpga.o
 obj-$(CONFIG_ARCH_NSPIRE)		+= irq-zevio.o
 obj-$(CONFIG_ARCH_VT8500)		+= irq-vt8500.o
diff --git a/drivers/irqchip/irq-renesas-rzg2l.c b/drivers/irqchip/irq-renesas-rzg2l.c
new file mode 100644
index 000000000000..a846c6ee11d7
--- /dev/null
+++ b/drivers/irqchip/irq-renesas-rzg2l.c
@@ -0,0 +1,425 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Renesas RZ/G2L IRQC Driver
+ *
+ * Copyright (C) 2022 Renesas Electronics Corporation.
+ *
+ * Author: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
+ */
+
+#include <linux/bitfield.h>
+#include <linux/clk.h>
+#include <linux/err.h>
+#include <linux/io.h>
+#include <linux/irqchip.h>
+#include <linux/irqdomain.h>
+#include <linux/of_address.h>
+#include <linux/of_platform.h>
+#include <linux/pm_runtime.h>
+#include <linux/reset.h>
+#include <linux/spinlock.h>
+
+#define IRQC_IRQ_START			1
+#define IRQC_IRQ_COUNT			8
+#define IRQC_TINT_START			(IRQC_IRQ_START + IRQC_IRQ_COUNT)
+#define IRQC_TINT_COUNT			32
+#define IRQC_NUM_IRQ			(IRQC_TINT_START + IRQC_TINT_COUNT)
+
+#define ISCR				0x10
+#define IITSR				0x14
+#define TSCR				0x20
+#define TITSR0				0x24
+#define TITSR1				0x28
+#define TITSR0_MAX_INT			16
+#define TITSEL_WIDTH			0x2
+#define TSSR(n)				(0x30 + ((n) * 4))
+#define TIEN				BIT(7)
+#define TSSEL_SHIFT(n)			(8 * (n))
+#define TSSEL_MASK			GENMASK(7, 0)
+#define IRQ_MASK			0x3
+
+#define TSSR_OFFSET(n)			((n) % 4)
+#define TSSR_INDEX(n)			((n) / 4)
+
+#define TITSR_TITSEL_EDGE_RISING	0
+#define TITSR_TITSEL_EDGE_FALLING	1
+#define TITSR_TITSEL_LEVEL_HIGH		2
+#define TITSR_TITSEL_LEVEL_LOW		3
+
+#define IITSR_IITSEL(n, sense)		((sense) << ((n) * 2))
+#define IITSR_IITSEL_LEVEL_LOW		0
+#define IITSR_IITSEL_EDGE_FALLING	1
+#define IITSR_IITSEL_EDGE_RISING	2
+#define IITSR_IITSEL_EDGE_BOTH		3
+#define IITSR_IITSEL_MASK(n)		IITSR_IITSEL((n), 3)
+
+#define TINT_EXTRACT_HWIRQ(x)           FIELD_GET(GENMASK(15, 0), (x))
+#define TINT_EXTRACT_GPIOINT(x)         FIELD_GET(GENMASK(31, 16), (x))
+
+struct rzg2l_irqc_priv {
+	void __iomem *base;
+	struct of_phandle_args map[IRQC_NUM_IRQ];
+	raw_spinlock_t lock;
+};
+
+struct rzg2l_irqc_chip_data {
+	int tint;
+};
+
+static struct rzg2l_irqc_priv *irq_data_to_priv(struct irq_data *data)
+{
+	return data->domain->host_data;
+}
+
+static void rzg2l_irq_eoi(struct irq_data *d)
+{
+	unsigned int hw_irq = irqd_to_hwirq(d) - IRQC_IRQ_START;
+	struct rzg2l_irqc_priv *priv = irq_data_to_priv(d);
+	u32 bit = BIT(hw_irq);
+	u32 reg;
+
+	reg = readl_relaxed(priv->base + ISCR);
+	if (reg & bit)
+		writel_relaxed(reg & ~bit, priv->base + ISCR);
+}
+
+static void rzg2l_tint_eoi(struct irq_data *d)
+{
+	unsigned int hw_irq = irqd_to_hwirq(d) - IRQC_TINT_START;
+	struct rzg2l_irqc_priv *priv = irq_data_to_priv(d);
+	u32 bit = BIT(hw_irq);
+	u32 reg;
+
+	reg = readl_relaxed(priv->base + TSCR);
+	if (reg & bit)
+		writel_relaxed(reg & ~bit, priv->base + TSCR);
+}
+
+static void rzg2l_irqc_eoi(struct irq_data *d)
+{
+	struct rzg2l_irqc_priv *priv = irq_data_to_priv(d);
+	unsigned int hw_irq = irqd_to_hwirq(d);
+
+	raw_spin_lock(&priv->lock);
+	if (hw_irq >= IRQC_IRQ_START && hw_irq <= IRQC_IRQ_COUNT)
+		rzg2l_irq_eoi(d);
+	else if (hw_irq >= IRQC_TINT_START && hw_irq < IRQC_NUM_IRQ)
+		rzg2l_tint_eoi(d);
+	raw_spin_unlock(&priv->lock);
+	irq_chip_eoi_parent(d);
+}
+
+static void rzg2l_irqc_irq_disable(struct irq_data *d)
+{
+	unsigned int hw_irq = irqd_to_hwirq(d);
+
+	if (hw_irq >= IRQC_TINT_START && hw_irq < IRQC_NUM_IRQ) {
+		struct rzg2l_irqc_priv *priv = irq_data_to_priv(d);
+		u32 offset = hw_irq - IRQC_TINT_START;
+		u32 tssr_offset = TSSR_OFFSET(offset);
+		u8 tssr_index = TSSR_INDEX(offset);
+		u32 reg;
+
+		raw_spin_lock(&priv->lock);
+		reg = readl_relaxed(priv->base + TSSR(tssr_index));
+		reg &= ~(TSSEL_MASK << tssr_offset);
+		writel_relaxed(reg, priv->base + TSSR(tssr_index));
+		raw_spin_unlock(&priv->lock);
+	}
+	irq_chip_disable_parent(d);
+}
+
+static void rzg2l_irqc_irq_enable(struct irq_data *d)
+{
+	unsigned int hw_irq = irqd_to_hwirq(d);
+
+	if (hw_irq >= IRQC_TINT_START && hw_irq < IRQC_NUM_IRQ) {
+		struct rzg2l_irqc_priv *priv = irq_data_to_priv(d);
+		unsigned long chip_data = *(unsigned long *)d->chip_data;
+		u32 offset = hw_irq - IRQC_TINT_START;
+		u32 tssr_offset = TSSR_OFFSET(offset);
+		u8 tssr_index = TSSR_INDEX(offset);
+		u32 reg;
+
+		raw_spin_lock(&priv->lock);
+		reg = readl_relaxed(priv->base + TSSR(tssr_index));
+		reg |= (TIEN | chip_data) << TSSEL_SHIFT(tssr_offset);
+		writel_relaxed(reg, priv->base + TSSR(tssr_index));
+		raw_spin_unlock(&priv->lock);
+	}
+	irq_chip_enable_parent(d);
+}
+
+static int rzg2l_irq_set_type(struct irq_data *d, unsigned int type)
+{
+	unsigned int hw_irq = irqd_to_hwirq(d) - IRQC_IRQ_START;
+	struct rzg2l_irqc_priv *priv = irq_data_to_priv(d);
+	u16 sense, tmp;
+
+	switch (type & IRQ_TYPE_SENSE_MASK) {
+	case IRQ_TYPE_LEVEL_LOW:
+		sense = IITSR_IITSEL_LEVEL_LOW;
+		break;
+
+	case IRQ_TYPE_EDGE_FALLING:
+		sense = IITSR_IITSEL_EDGE_FALLING;
+		break;
+
+	case IRQ_TYPE_EDGE_RISING:
+		sense = IITSR_IITSEL_EDGE_RISING;
+		break;
+
+	case IRQ_TYPE_EDGE_BOTH:
+		sense = IITSR_IITSEL_EDGE_BOTH;
+		break;
+
+	default:
+		return -EINVAL;
+	}
+
+	raw_spin_lock(&priv->lock);
+	tmp = readl_relaxed(priv->base + IITSR);
+	tmp &= ~IITSR_IITSEL_MASK(hw_irq);
+	tmp |= IITSR_IITSEL(hw_irq, sense);
+	writel_relaxed(tmp, priv->base + IITSR);
+	raw_spin_unlock(&priv->lock);
+
+	return 0;
+}
+
+static int rzg2l_tint_set_edge(struct irq_data *d, unsigned int type)
+{
+	struct rzg2l_irqc_priv *priv = irq_data_to_priv(d);
+	unsigned int hwirq = irqd_to_hwirq(d);
+	u32 titseln = hwirq - IRQC_TINT_START;
+	u32 offset;
+	u8 sense;
+	u32 reg;
+
+	switch (type & IRQ_TYPE_SENSE_MASK) {
+	case IRQ_TYPE_EDGE_RISING:
+		sense = TITSR_TITSEL_EDGE_RISING;
+		break;
+
+	case IRQ_TYPE_EDGE_FALLING:
+		sense = TITSR_TITSEL_EDGE_FALLING;
+		break;
+
+	default:
+		return -EINVAL;
+	}
+
+	offset = TITSR0;
+	if (titseln >= TITSR0_MAX_INT) {
+		titseln -= TITSR0_MAX_INT;
+		offset = TITSR1;
+	}
+
+	raw_spin_lock(&priv->lock);
+	reg = readl_relaxed(priv->base + offset);
+	reg &= ~(IRQ_MASK << (titseln * TITSEL_WIDTH));
+	reg |= sense << (titseln * TITSEL_WIDTH);
+	writel_relaxed(reg, priv->base + offset);
+	raw_spin_unlock(&priv->lock);
+
+	return 0;
+}
+
+static int rzg2l_irqc_set_type(struct irq_data *d, unsigned int type)
+{
+	unsigned int hw_irq = irqd_to_hwirq(d);
+	int ret = -EINVAL;
+
+	if (hw_irq >= IRQC_IRQ_START && hw_irq <= IRQC_IRQ_COUNT)
+		ret = rzg2l_irq_set_type(d, type);
+	else if (hw_irq >= IRQC_TINT_START && hw_irq < IRQC_NUM_IRQ)
+		ret = rzg2l_tint_set_edge(d, type);
+	if (ret)
+		return ret;
+
+	return irq_chip_set_type_parent(d, IRQ_TYPE_LEVEL_HIGH);
+}
+
+static const struct irq_chip irqc_chip = {
+	.name			= "rzg2l-irqc",
+	.irq_eoi		= rzg2l_irqc_eoi,
+	.irq_mask		= irq_chip_mask_parent,
+	.irq_unmask		= irq_chip_unmask_parent,
+	.irq_disable		= rzg2l_irqc_irq_disable,
+	.irq_enable		= rzg2l_irqc_irq_enable,
+	.irq_get_irqchip_state	= irq_chip_get_parent_state,
+	.irq_set_irqchip_state	= irq_chip_set_parent_state,
+	.irq_retrigger		= irq_chip_retrigger_hierarchy,
+	.irq_set_type		= rzg2l_irqc_set_type,
+	.flags			= IRQCHIP_MASK_ON_SUSPEND |
+				  IRQCHIP_SET_TYPE_MASKED |
+				  IRQCHIP_SKIP_SET_WAKE,
+};
+
+static int rzg2l_irqc_alloc(struct irq_domain *domain, unsigned int virq,
+			    unsigned int nr_irqs, void *arg)
+{
+	struct rzg2l_irqc_priv *priv = domain->host_data;
+	unsigned long *chip_data = NULL;
+	struct irq_fwspec spec;
+	irq_hw_number_t hwirq;
+	int tint = -EINVAL;
+	unsigned int type;
+	unsigned int i;
+	int ret;
+
+	ret = irq_domain_translate_twocell(domain, arg, &hwirq, &type);
+	if (ret)
+		return ret;
+
+	/*
+	 * For TINT interrupts ie where pinctrl driver is child of irqc domain
+	 * the hwirq and TINT are encoded in fwspec->param[0].
+	 * hwirq for TINT range from 9-40, hwirq is embedded 0-15 bits and TINT
+	 * from 16-31 bits. TINT from the pinctrl driver needs to be programmed
+	 * in IRQC registers to enable a given gpio pin as interrupt.
+	 */
+	if (hwirq > IRQC_IRQ_COUNT) {
+		tint = TINT_EXTRACT_GPIOINT(hwirq);
+		hwirq = TINT_EXTRACT_HWIRQ(hwirq);
+
+		if (hwirq < IRQC_TINT_START)
+			return -EINVAL;
+	}
+
+	if (hwirq > (IRQC_NUM_IRQ - 1))
+		return -EINVAL;
+
+	chip_data = kzalloc(sizeof(*chip_data), GFP_KERNEL);
+	if (!chip_data)
+		return -ENOMEM;
+	*chip_data = tint;
+
+	ret = irq_domain_set_hwirq_and_chip(domain, virq, hwirq, &irqc_chip,
+					    chip_data);
+	if (ret) {
+		kfree(chip_data);
+		return ret;
+	}
+
+	spec.fwnode = domain->parent->fwnode;
+	spec.param_count = priv->map[hwirq].args_count;
+	for (i = 0; i < spec.param_count; i++)
+		spec.param[i] = priv->map[hwirq].args[i];
+
+	ret = irq_domain_alloc_irqs_parent(domain, virq, nr_irqs, &spec);
+	if (ret)
+		kfree(chip_data);
+
+	return ret;
+}
+
+static void rzg2l_irqc_domain_free(struct irq_domain *domain, unsigned int virq,
+				   unsigned int nr_irqs)
+{
+	struct irq_data *d;
+
+	d = irq_domain_get_irq_data(domain, virq);
+	if (d)
+		kfree(d->chip_data);
+
+	irq_domain_free_irqs_common(domain, virq, nr_irqs);
+}
+
+static const struct irq_domain_ops rzg2l_irqc_domain_ops = {
+	.alloc = rzg2l_irqc_alloc,
+	.free = rzg2l_irqc_domain_free,
+	.translate = irq_domain_translate_twocell,
+};
+
+static int rzg2l_irqc_parse_map(struct rzg2l_irqc_priv *priv,
+				struct device_node *np)
+{
+	unsigned int i;
+	int ret;
+
+	for (i = 0; i < IRQC_NUM_IRQ; i++) {
+		ret = of_irq_parse_one(np, i, &priv->map[i]);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
+static int rzg2l_irqc_init(struct device_node *node, struct device_node *parent)
+{
+	struct irq_domain *irq_domain, *parent_domain;
+	struct platform_device *pdev;
+	struct reset_control *resetn;
+	struct rzg2l_irqc_priv *priv;
+	int ret;
+
+	pdev = of_find_device_by_node(node);
+	if (!pdev)
+		return -ENODEV;
+
+	parent_domain = irq_find_host(parent);
+	if (!parent_domain) {
+		dev_err(&pdev->dev, "cannot find parent domain\n");
+		return -ENODEV;
+	}
+
+	priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->base = devm_of_iomap(&pdev->dev, pdev->dev.of_node, 0, NULL);
+	if (IS_ERR(priv->base))
+		return PTR_ERR(priv->base);
+
+	ret = rzg2l_irqc_parse_map(priv, node);
+	if (ret) {
+		dev_err(&pdev->dev, "cannot parse interrupts: %d\n", ret);
+		return ret;
+	}
+
+	resetn = devm_reset_control_get_exclusive_by_index(&pdev->dev, 0);
+	if (IS_ERR(resetn))
+		return IS_ERR(resetn);
+
+	ret = reset_control_deassert(resetn);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to deassert resetn pin, %d\n", ret);
+		return ret;
+	}
+
+	pm_runtime_enable(&pdev->dev);
+	ret = pm_runtime_resume_and_get(&pdev->dev);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "pm_runtime_resume_and_get failed: %d\n", ret);
+		goto pm_disable;
+	}
+
+	raw_spin_lock_init(&priv->lock);
+
+	irq_domain = irq_domain_add_hierarchy(parent_domain, 0, IRQC_NUM_IRQ,
+					      node, &rzg2l_irqc_domain_ops,
+					      priv);
+	if (!irq_domain) {
+		dev_err(&pdev->dev, "failed to add irq domain\n");
+		ret = -ENOMEM;
+		goto pm_put;
+	}
+
+	return 0;
+
+pm_put:
+	pm_runtime_put(&pdev->dev);
+pm_disable:
+	pm_runtime_disable(&pdev->dev);
+	reset_control_assert(resetn);
+	return ret;
+}
+
+IRQCHIP_PLATFORM_DRIVER_BEGIN(rzg2l_irqc)
+IRQCHIP_MATCH("renesas,rzg2l-irqc", rzg2l_irqc_init)
+IRQCHIP_PLATFORM_DRIVER_END(rzg2l_irqc)
+MODULE_AUTHOR("Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>");
+MODULE_DESCRIPTION("Renesas RZ/G2L IRQC Driver");
+MODULE_LICENSE("GPL");
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v4 3/7] gpio: gpiolib: Add ngirq member to struct gpio_irq_chip
  2022-05-18 19:29 [PATCH v4 0/7] Renesas RZ/G2L IRQC support Lad Prabhakar
  2022-05-18 19:29 ` [PATCH v4 1/7] dt-bindings: interrupt-controller: Add Renesas RZ/G2L Interrupt Controller Lad Prabhakar
  2022-05-18 19:29 ` [PATCH v4 2/7] irqchip: Add RZ/G2L IA55 Interrupt Controller driver Lad Prabhakar
@ 2022-05-18 19:29 ` Lad Prabhakar
  2022-05-19 13:26   ` Linus Walleij
  2022-05-18 19:29 ` [PATCH v4 4/7] gpio: gpiolib: Dont assume child_offset_to_irq callback always succeeds Lad Prabhakar
                   ` (4 subsequent siblings)
  7 siblings, 1 reply; 20+ messages in thread
From: Lad Prabhakar @ 2022-05-18 19:29 UTC (permalink / raw)
  To: Marc Zyngier, Geert Uytterhoeven, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Linus Walleij, Bartosz Golaszewski,
	Thierry Reding, Jonathan Hunter, Bjorn Andersson, Andy Gross,
	Philipp Zabel, Andy Shevchenko, linux-gpio, linux-tegra,
	linux-arm-msm, devicetree
  Cc: linux-kernel, Prabhakar, linux-renesas-soc, Phil Edworthy,
	Biju Das, Lad Prabhakar

Supported GPIO IRQs by the chip is not always equal to the number of GPIO
pins. For example on Renesas RZ/G2L SoC where it has GPIO0-122 pins but at
a given point a maximum of only 32 GPIO pins can be used as IRQ lines in
the IRQC domain.

This patch adds ngirq member to struct gpio_irq_chip and passes this as a
size to irq_domain_create_hierarchy()/irq_domain_create_simple() if it is
being set in the driver otherwise fallbacks to using ngpio.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
 drivers/gpio/gpiolib.c      | 4 ++--
 include/linux/gpio/driver.h | 8 ++++++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 690035124faa..43dbc4ee9d67 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1218,7 +1218,7 @@ static int gpiochip_hierarchy_add_domain(struct gpio_chip *gc)
 	gc->irq.domain = irq_domain_create_hierarchy(
 		gc->irq.parent_domain,
 		0,
-		gc->ngpio,
+		gc->irq.ngirq ?: gc->ngpio,
 		gc->irq.fwnode,
 		&gc->irq.child_irq_domain_ops,
 		gc);
@@ -1578,7 +1578,7 @@ static int gpiochip_add_irqchip(struct gpio_chip *gc,
 	} else {
 		/* Some drivers provide custom irqdomain ops */
 		gc->irq.domain = irq_domain_create_simple(fwnode,
-			gc->ngpio,
+			gc->irq.ngirq ?: gc->ngpio,
 			gc->irq.first,
 			gc->irq.domain_ops ?: &gpiochip_domain_ops,
 			gc);
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index cb689264f3e9..4ec3f010df7c 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -51,6 +51,14 @@ struct gpio_irq_chip {
 	 */
 	const struct irq_domain_ops *domain_ops;
 
+	/**
+	 * @ngirq:
+	 *
+	 * The number of GPIO IRQ's handled by this IRQ domain; usually is
+	 * equal to ngpio. If not set, ngpio will be used.
+	 */
+	u16 ngirq;
+
 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
 	/**
 	 * @fwnode:
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v4 4/7] gpio: gpiolib: Dont assume child_offset_to_irq callback always succeeds
  2022-05-18 19:29 [PATCH v4 0/7] Renesas RZ/G2L IRQC support Lad Prabhakar
                   ` (2 preceding siblings ...)
  2022-05-18 19:29 ` [PATCH v4 3/7] gpio: gpiolib: Add ngirq member to struct gpio_irq_chip Lad Prabhakar
@ 2022-05-18 19:29 ` Lad Prabhakar
  2022-05-19 13:30   ` Linus Walleij
  2022-05-18 19:29 ` [PATCH v4 5/7] gpio: gpiolib: Add a check to validate GPIO hwirq Lad Prabhakar
                   ` (3 subsequent siblings)
  7 siblings, 1 reply; 20+ messages in thread
From: Lad Prabhakar @ 2022-05-18 19:29 UTC (permalink / raw)
  To: Marc Zyngier, Geert Uytterhoeven, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Linus Walleij, Bartosz Golaszewski,
	Thierry Reding, Jonathan Hunter, Bjorn Andersson, Andy Gross,
	Philipp Zabel, Andy Shevchenko, linux-gpio, linux-tegra,
	linux-arm-msm, devicetree
  Cc: linux-kernel, Prabhakar, linux-renesas-soc, Phil Edworthy,
	Biju Das, Lad Prabhakar

On Renesas RZ/G2L SoC not all the GPIO pins can be simultaneously used as
interrupts. The SoC allows 32 interrupts which is first come first serve
basis and is dynamic i.e. if there is a free slot (after rmmod) this can
be used by other GPIO pins being used as an interrupt.

To handle such cases change child_offset_to_irq() callback to return error
codes in case of failure. All the users of child_offset_to_irq() callback
are also updated with this API change.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
 drivers/gpio/gpio-tegra186.c             | 14 ++++++++++---
 drivers/gpio/gpiolib.c                   | 25 +++++++++++++++++++-----
 drivers/pinctrl/qcom/pinctrl-spmi-gpio.c |  7 +++++--
 drivers/pinctrl/qcom/pinctrl-spmi-mpp.c  |  7 +++++--
 drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c |  7 +++++--
 drivers/pinctrl/qcom/pinctrl-ssbi-mpp.c  |  7 +++++--
 include/linux/gpio/driver.h              |  9 ++++++---
 7 files changed, 57 insertions(+), 19 deletions(-)

diff --git a/drivers/gpio/gpio-tegra186.c b/drivers/gpio/gpio-tegra186.c
index 031fe105b58e..baf73290ba44 100644
--- a/drivers/gpio/gpio-tegra186.c
+++ b/drivers/gpio/gpio-tegra186.c
@@ -552,14 +552,20 @@ static int tegra186_gpio_child_to_parent_hwirq(struct gpio_chip *chip,
 					       unsigned int *parent_hwirq,
 					       unsigned int *parent_type)
 {
-	*parent_hwirq = chip->irq.child_offset_to_irq(chip, hwirq);
+	int ret;
+
+	ret = chip->irq.child_offset_to_irq(chip, hwirq, parent_hwirq);
+	if (ret)
+		return ret;
+
 	*parent_type = type;
 
 	return 0;
 }
 
 static unsigned int tegra186_gpio_child_offset_to_irq(struct gpio_chip *chip,
-						      unsigned int offset)
+						      unsigned int offset,
+						      unsigned int *hwirq)
 {
 	struct tegra_gpio *gpio = gpiochip_get_data(chip);
 	unsigned int i;
@@ -571,7 +577,9 @@ static unsigned int tegra186_gpio_child_offset_to_irq(struct gpio_chip *chip,
 		offset -= gpio->soc->ports[i].pins;
 	}
 
-	return offset + i * 8;
+	*hwirq = offset + i * 8;
+
+	return 0;
 }
 
 static const struct of_device_id tegra186_pmc_of_match[] = {
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 43dbc4ee9d67..65e344a23c6a 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1036,6 +1036,7 @@ static void gpiochip_set_hierarchical_irqchip(struct gpio_chip *gc,
 			unsigned int parent_hwirq;
 			unsigned int parent_type;
 			struct gpio_irq_chip *girq = &gc->irq;
+			unsigned int hwirq;
 
 			/*
 			 * We call the child to parent translation function
@@ -1053,9 +1054,16 @@ static void gpiochip_set_hierarchical_irqchip(struct gpio_chip *gc,
 				continue;
 			}
 
+			ret = girq->child_offset_to_irq(gc, i, &hwirq);
+			if (ret) {
+				chip_err(gc,
+					 "child_offset_to_irq() failed to return hwirq for GPIO line %d: %d\n",
+					 i, ret);
+				continue;
+			}
 			fwspec.fwnode = gc->irq.fwnode;
 			/* This is the hwirq for the GPIO line side of things */
-			fwspec.param[0] = girq->child_offset_to_irq(gc, i);
+			fwspec.param[0] = hwirq;
 			/* Just pick something */
 			fwspec.param[1] = IRQ_TYPE_EDGE_RISING;
 			fwspec.param_count = 2;
@@ -1176,10 +1184,12 @@ static int gpiochip_hierarchy_irq_domain_alloc(struct irq_domain *d,
 	return ret;
 }
 
-static unsigned int gpiochip_child_offset_to_irq_noop(struct gpio_chip *gc,
-						      unsigned int offset)
+static int gpiochip_child_offset_to_irq_noop(struct gpio_chip *gc,
+					     unsigned int offset,
+					     unsigned int *hwirq)
 {
-	return offset;
+	*hwirq = offset;
+	return 0;
 }
 
 static void gpiochip_hierarchy_setup_domain_ops(struct irq_domain_ops *ops)
@@ -1420,10 +1430,15 @@ static int gpiochip_to_irq(struct gpio_chip *gc, unsigned int offset)
 #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
 	if (irq_domain_is_hierarchy(domain)) {
 		struct irq_fwspec spec;
+		unsigned int hwirq;
+		int ret;
 
+		ret = gc->irq.child_offset_to_irq(gc, offset, &hwirq);
+		if (ret)
+			return ret;
 		spec.fwnode = domain->fwnode;
 		spec.param_count = 2;
-		spec.param[0] = gc->irq.child_offset_to_irq(gc, offset);
+		spec.param[0] = hwirq;
 		spec.param[1] = IRQ_TYPE_NONE;
 
 		return irq_create_fwspec_mapping(&spec);
diff --git a/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c b/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
index 4fbf8d3938ef..30cd4080af09 100644
--- a/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
+++ b/drivers/pinctrl/qcom/pinctrl-spmi-gpio.c
@@ -947,9 +947,12 @@ static int pmic_gpio_domain_translate(struct irq_domain *domain,
 }
 
 static unsigned int pmic_gpio_child_offset_to_irq(struct gpio_chip *chip,
-						  unsigned int offset)
+						  unsigned int offset,
+						  unsigned int *hwirq)
 {
-	return offset + PMIC_GPIO_PHYSICAL_OFFSET;
+	*hwirq = offset + PMIC_GPIO_PHYSICAL_OFFSET;
+
+	return 0;
 }
 
 static int pmic_gpio_child_to_parent_hwirq(struct gpio_chip *chip,
diff --git a/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c b/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
index 6937157f50b3..a712a4deff34 100644
--- a/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
+++ b/drivers/pinctrl/qcom/pinctrl-spmi-mpp.c
@@ -804,9 +804,12 @@ static int pmic_mpp_domain_translate(struct irq_domain *domain,
 }
 
 static unsigned int pmic_mpp_child_offset_to_irq(struct gpio_chip *chip,
-						  unsigned int offset)
+						 unsigned int offset,
+						 unsigned int *hwirq)
 {
-	return offset + PMIC_MPP_PHYSICAL_OFFSET;
+	*hwirq = offset + PMIC_MPP_PHYSICAL_OFFSET;
+
+	return 0;
 }
 
 static int pmic_mpp_child_to_parent_hwirq(struct gpio_chip *chip,
diff --git a/drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c b/drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c
index 1b41adda8129..c3a7af6dc9cc 100644
--- a/drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c
+++ b/drivers/pinctrl/qcom/pinctrl-ssbi-gpio.c
@@ -678,9 +678,12 @@ static int pm8xxx_domain_translate(struct irq_domain *domain,
 }
 
 static unsigned int pm8xxx_child_offset_to_irq(struct gpio_chip *chip,
-					       unsigned int offset)
+					       unsigned int offset,
+					       unsigned int *hwirq)
 {
-	return offset + PM8XXX_GPIO_PHYSICAL_OFFSET;
+	*hwirq = offset + PM8XXX_GPIO_PHYSICAL_OFFSET;
+
+	return 0;
 }
 
 static int pm8xxx_child_to_parent_hwirq(struct gpio_chip *chip,
diff --git a/drivers/pinctrl/qcom/pinctrl-ssbi-mpp.c b/drivers/pinctrl/qcom/pinctrl-ssbi-mpp.c
index 49893a5133a8..1733743a6813 100644
--- a/drivers/pinctrl/qcom/pinctrl-ssbi-mpp.c
+++ b/drivers/pinctrl/qcom/pinctrl-ssbi-mpp.c
@@ -748,9 +748,12 @@ static int pm8xxx_mpp_domain_translate(struct irq_domain *domain,
 }
 
 static unsigned int pm8xxx_mpp_child_offset_to_irq(struct gpio_chip *chip,
-						   unsigned int offset)
+						   unsigned int offset,
+						   unsigned int *hwirq)
 {
-	return offset + PM8XXX_MPP_PHYSICAL_OFFSET;
+	*hwirq = offset + PM8XXX_MPP_PHYSICAL_OFFSET;
+
+	return 0;
 }
 
 static int pm8821_mpp_child_to_parent_hwirq(struct gpio_chip *chip,
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 4ec3f010df7c..a04428c7ba79 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -120,10 +120,13 @@ struct gpio_irq_chip {
 	 * This optional callback is used to translate the child's GPIO line
 	 * offset on the GPIO chip to an IRQ number for the GPIO to_irq()
 	 * callback. If this is not specified, then a default callback will be
-	 * provided that returns the line offset.
+	 * provided that sets hwirq to the line offset.
+	 *
+	 * If the hardware is not capable of handling anymore IRQs a negative
+	 * error code is returned and on success 0 is returned.
 	 */
-	unsigned int (*child_offset_to_irq)(struct gpio_chip *gc,
-					    unsigned int pin);
+	int (*child_offset_to_irq)(struct gpio_chip *gc, unsigned int pin,
+				   unsigned int *hwirq);
 
 	/**
 	 * @child_irq_domain_ops:
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v4 5/7] gpio: gpiolib: Add a check to validate GPIO hwirq
  2022-05-18 19:29 [PATCH v4 0/7] Renesas RZ/G2L IRQC support Lad Prabhakar
                   ` (3 preceding siblings ...)
  2022-05-18 19:29 ` [PATCH v4 4/7] gpio: gpiolib: Dont assume child_offset_to_irq callback always succeeds Lad Prabhakar
@ 2022-05-18 19:29 ` Lad Prabhakar
  2022-05-18 21:08   ` Andy Shevchenko
  2022-05-18 19:29 ` [PATCH v4 6/7] dt-bindings: pinctrl: renesas,rzg2l-pinctrl: Document the properties to handle GPIO IRQ Lad Prabhakar
                   ` (2 subsequent siblings)
  7 siblings, 1 reply; 20+ messages in thread
From: Lad Prabhakar @ 2022-05-18 19:29 UTC (permalink / raw)
  To: Marc Zyngier, Geert Uytterhoeven, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Linus Walleij, Bartosz Golaszewski,
	Thierry Reding, Jonathan Hunter, Bjorn Andersson, Andy Gross,
	Philipp Zabel, Andy Shevchenko, linux-gpio, linux-tegra,
	linux-arm-msm, devicetree
  Cc: linux-kernel, Prabhakar, linux-renesas-soc, Phil Edworthy,
	Biju Das, Lad Prabhakar

Add a check to validate GPIO hwirq is always within the range of hwirq_max
set in the GPIO irq domain.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
 drivers/gpio/gpiolib.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 65e344a23c6a..c1de7bb54c13 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1028,6 +1028,7 @@ static void gpiochip_set_hierarchical_irqchip(struct gpio_chip *gc,
 	 * it is necessary to keep this around.
 	 */
 	if (is_fwnode_irqchip(gc->irq.fwnode)) {
+		struct irq_domain *domain = gc->irq.domain;
 		int i;
 		int ret;
 
@@ -1061,6 +1062,11 @@ static void gpiochip_set_hierarchical_irqchip(struct gpio_chip *gc,
 					 i, ret);
 				continue;
 			}
+			if (WARN(hwirq >= domain->hwirq_max,
+				 "error: hwirq 0x%x is too large for %s\n",
+				 (int)hwirq, domain->name))
+				continue;
+
 			fwspec.fwnode = gc->irq.fwnode;
 			/* This is the hwirq for the GPIO line side of things */
 			fwspec.param[0] = hwirq;
@@ -1436,6 +1442,9 @@ static int gpiochip_to_irq(struct gpio_chip *gc, unsigned int offset)
 		ret = gc->irq.child_offset_to_irq(gc, offset, &hwirq);
 		if (ret)
 			return ret;
+		if (WARN(hwirq >= domain->hwirq_max,
+			 "error: hwirq 0x%x is too large for %s\n", (int)hwirq, domain->name))
+			return -EINVAL;
 		spec.fwnode = domain->fwnode;
 		spec.param_count = 2;
 		spec.param[0] = hwirq;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v4 6/7] dt-bindings: pinctrl: renesas,rzg2l-pinctrl: Document the properties to handle GPIO IRQ
  2022-05-18 19:29 [PATCH v4 0/7] Renesas RZ/G2L IRQC support Lad Prabhakar
                   ` (4 preceding siblings ...)
  2022-05-18 19:29 ` [PATCH v4 5/7] gpio: gpiolib: Add a check to validate GPIO hwirq Lad Prabhakar
@ 2022-05-18 19:29 ` Lad Prabhakar
  2022-05-19 12:01   ` Geert Uytterhoeven
  2022-05-18 19:29 ` [PATCH v4 7/7] pinctrl: renesas: pinctrl-rzg2l: Add IRQ domain to handle GPIO interrupt Lad Prabhakar
  2022-05-18 21:09 ` [PATCH v4 0/7] Renesas RZ/G2L IRQC support Andy Shevchenko
  7 siblings, 1 reply; 20+ messages in thread
From: Lad Prabhakar @ 2022-05-18 19:29 UTC (permalink / raw)
  To: Marc Zyngier, Geert Uytterhoeven, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Linus Walleij, Bartosz Golaszewski,
	Thierry Reding, Jonathan Hunter, Bjorn Andersson, Andy Gross,
	Philipp Zabel, Andy Shevchenko, linux-gpio, linux-tegra,
	linux-arm-msm, devicetree
  Cc: linux-kernel, Prabhakar, linux-renesas-soc, Phil Edworthy,
	Biju Das, Lad Prabhakar

Document the required properties to handle GPIO IRQ.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
 .../bindings/pinctrl/renesas,rzg2l-pinctrl.yaml  | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/Documentation/devicetree/bindings/pinctrl/renesas,rzg2l-pinctrl.yaml b/Documentation/devicetree/bindings/pinctrl/renesas,rzg2l-pinctrl.yaml
index 52df1b146174..d20ac03507cc 100644
--- a/Documentation/devicetree/bindings/pinctrl/renesas,rzg2l-pinctrl.yaml
+++ b/Documentation/devicetree/bindings/pinctrl/renesas,rzg2l-pinctrl.yaml
@@ -47,6 +47,17 @@ properties:
   gpio-ranges:
     maxItems: 1
 
+  interrupt-controller: true
+
+  '#interrupt-cells':
+    const: 2
+    description:
+      The first cell contains the global GPIO port index, constructed using the
+      RZG2L_GPIO() helper macro in <dt-bindings/pinctrl/rzg2l-pinctrl.h> and the
+      second cell is used to specify the flag.
+      E.g. "interrupts = <RZG2L_GPIO(43, 0) IRQ_TYPE_EDGE_FALLING>;" if P43_0 is
+      being used as an interrupt.
+
   clocks:
     maxItems: 1
 
@@ -110,6 +121,8 @@ required:
   - gpio-controller
   - '#gpio-cells'
   - gpio-ranges
+  - interrupt-controller
+  - '#interrupt-cells'
   - clocks
   - power-domains
   - resets
@@ -126,6 +139,9 @@ examples:
             gpio-controller;
             #gpio-cells = <2>;
             gpio-ranges = <&pinctrl 0 0 392>;
+            interrupt-controller;
+            #interrupt-cells = <2>;
+            interrupt-parent = <&irqc>;
             clocks = <&cpg CPG_MOD R9A07G044_GPIO_HCLK>;
             resets = <&cpg R9A07G044_GPIO_RSTN>,
                      <&cpg R9A07G044_GPIO_PORT_RESETN>,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v4 7/7] pinctrl: renesas: pinctrl-rzg2l: Add IRQ domain to handle GPIO interrupt
  2022-05-18 19:29 [PATCH v4 0/7] Renesas RZ/G2L IRQC support Lad Prabhakar
                   ` (5 preceding siblings ...)
  2022-05-18 19:29 ` [PATCH v4 6/7] dt-bindings: pinctrl: renesas,rzg2l-pinctrl: Document the properties to handle GPIO IRQ Lad Prabhakar
@ 2022-05-18 19:29 ` Lad Prabhakar
  2022-05-18 21:09 ` [PATCH v4 0/7] Renesas RZ/G2L IRQC support Andy Shevchenko
  7 siblings, 0 replies; 20+ messages in thread
From: Lad Prabhakar @ 2022-05-18 19:29 UTC (permalink / raw)
  To: Marc Zyngier, Geert Uytterhoeven, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Linus Walleij, Bartosz Golaszewski,
	Thierry Reding, Jonathan Hunter, Bjorn Andersson, Andy Gross,
	Philipp Zabel, Andy Shevchenko, linux-gpio, linux-tegra,
	linux-arm-msm, devicetree
  Cc: linux-kernel, Prabhakar, linux-renesas-soc, Phil Edworthy,
	Biju Das, Lad Prabhakar

Add IRQ domain to RZ/G2L pinctrl driver to handle GPIO interrupt.

GPIO0-GPIO122 pins can be used as IRQ lines but only 32 pins can be
used as IRQ lines at a given time. Selection of pins as IRQ lines
is handled by IA55 (which is the IRQC block) which sits in between the
GPIO and GIC.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
---
 drivers/pinctrl/renesas/pinctrl-rzg2l.c | 221 ++++++++++++++++++++++++
 1 file changed, 221 insertions(+)

diff --git a/drivers/pinctrl/renesas/pinctrl-rzg2l.c b/drivers/pinctrl/renesas/pinctrl-rzg2l.c
index a48cac55152c..335e22e7a442 100644
--- a/drivers/pinctrl/renesas/pinctrl-rzg2l.c
+++ b/drivers/pinctrl/renesas/pinctrl-rzg2l.c
@@ -9,8 +9,10 @@
 #include <linux/clk.h>
 #include <linux/gpio/driver.h>
 #include <linux/io.h>
+#include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/of_device.h>
+#include <linux/of_irq.h>
 #include <linux/pinctrl/pinconf-generic.h>
 #include <linux/pinctrl/pinconf.h>
 #include <linux/pinctrl/pinctrl.h>
@@ -89,6 +91,7 @@
 #define PIN(n)			(0x0800 + 0x10 + (n))
 #define IOLH(n)			(0x1000 + (n) * 8)
 #define IEN(n)			(0x1800 + (n) * 8)
+#define ISEL(n)			(0x2c80 + (n) * 8)
 #define PWPR			(0x3014)
 #define SD_CH(n)		(0x3000 + (n) * 4)
 #define QSPI			(0x3008)
@@ -112,6 +115,10 @@
 #define RZG2L_PIN_ID_TO_PORT_OFFSET(id)	(RZG2L_PIN_ID_TO_PORT(id) + 0x10)
 #define RZG2L_PIN_ID_TO_PIN(id)		((id) % RZG2L_PINS_PER_PORT)
 
+#define RZG2L_TINT_MAX_INTERRUPT	32
+#define RZG2L_TINT_IRQ_START_INDEX	9
+#define RZG2L_PACK_HWIRQ(t, i)		(((t) << 16) | (i))
+
 struct rzg2l_dedicated_configs {
 	const char *name;
 	u32 config;
@@ -137,6 +144,9 @@ struct rzg2l_pinctrl {
 
 	struct gpio_chip		gpio_chip;
 	struct pinctrl_gpio_range	gpio_range;
+	DECLARE_BITMAP(tint_slot, RZG2L_TINT_MAX_INTERRUPT);
+	spinlock_t			bitmap_lock;
+	unsigned int			hwirq[RZG2L_TINT_MAX_INTERRUPT];
 
 	spinlock_t			lock;
 };
@@ -883,8 +893,27 @@ static int rzg2l_gpio_get(struct gpio_chip *chip, unsigned int offset)
 
 static void rzg2l_gpio_free(struct gpio_chip *chip, unsigned int offset)
 {
+	struct rzg2l_pinctrl *pctrl = gpiochip_get_data(chip);
+	unsigned long flags;
+	unsigned int virq;
+	unsigned int i;
+
 	pinctrl_gpio_free(chip->base + offset);
 
+	for (i = 0; i < RZG2L_TINT_MAX_INTERRUPT; i++) {
+		if (pctrl->hwirq[i] == offset) {
+			spin_lock_irqsave(&pctrl->bitmap_lock, flags);
+			bitmap_release_region(pctrl->tint_slot, i, get_order(1));
+			spin_unlock_irqrestore(&pctrl->bitmap_lock, flags);
+			pctrl->hwirq[i] = 0;
+			break;
+		}
+	}
+
+	virq = irq_find_mapping(chip->irq.domain, offset);
+	if (virq)
+		irq_dispose_mapping(virq);
+
 	/*
 	 * Set the GPIO as an input to ensure that the next GPIO request won't
 	 * drive the GPIO pin as an output.
@@ -1104,14 +1133,196 @@ static struct {
 	}
 };
 
+static int rzg2l_gpio_get_gpioint(unsigned int virq)
+{
+	unsigned int gpioint;
+	unsigned int i;
+	u32 port, bit;
+
+	port = virq / 8;
+	bit = virq % 8;
+
+	if (port >= ARRAY_SIZE(rzg2l_gpio_configs) ||
+	    bit >= RZG2L_GPIO_PORT_GET_PINCNT(rzg2l_gpio_configs[port]))
+		return -EINVAL;
+
+	gpioint = bit;
+	for (i = 0; i < port; i++)
+		gpioint += RZG2L_GPIO_PORT_GET_PINCNT(rzg2l_gpio_configs[i]);
+
+	return gpioint;
+}
+
+static void rzg2l_gpio_irq_disable(struct irq_data *d)
+{
+	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
+	struct rzg2l_pinctrl *pctrl = container_of(gc, struct rzg2l_pinctrl, gpio_chip);
+	unsigned int hwirq = irqd_to_hwirq(d);
+	unsigned int offset;
+	unsigned long flags;
+	void __iomem *addr;
+	u32 port;
+	u8 bit;
+
+	offset = pctrl->hwirq[hwirq];
+	port = RZG2L_PIN_ID_TO_PORT(offset);
+	bit = RZG2L_PIN_ID_TO_PIN(offset);
+
+	addr = pctrl->base + ISEL(port);
+	if (bit >= 4) {
+		bit -= 4;
+		addr += 4;
+	}
+
+	spin_lock_irqsave(&pctrl->lock, flags);
+	writel(readl(addr) & ~BIT(bit * 8), addr);
+	spin_unlock_irqrestore(&pctrl->lock, flags);
+
+	gpiochip_disable_irq(gc, hwirq);
+	irq_chip_disable_parent(d);
+}
+
+static void rzg2l_gpio_irq_enable(struct irq_data *d)
+{
+	struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
+	struct rzg2l_pinctrl *pctrl = container_of(gc, struct rzg2l_pinctrl, gpio_chip);
+	unsigned int hwirq = irqd_to_hwirq(d);
+	unsigned int offset;
+	unsigned long flags;
+	void __iomem *addr;
+	u32 port;
+	u8 bit;
+
+	gpiochip_enable_irq(gc, hwirq);
+
+	offset = pctrl->hwirq[hwirq];
+	port = RZG2L_PIN_ID_TO_PORT(offset);
+	bit = RZG2L_PIN_ID_TO_PIN(offset);
+
+	addr = pctrl->base + ISEL(port);
+	if (bit >= 4) {
+		bit -= 4;
+		addr += 4;
+	}
+
+	spin_lock_irqsave(&pctrl->lock, flags);
+	writel(readl(addr) | BIT(bit * 8), addr);
+	spin_unlock_irqrestore(&pctrl->lock, flags);
+
+	irq_chip_enable_parent(d);
+}
+
+static int rzg2l_gpio_irq_set_type(struct irq_data *d, unsigned int type)
+{
+	return irq_chip_set_type_parent(d, type);
+}
+
+static void rzg2l_gpio_irqc_eoi(struct irq_data *d)
+{
+	irq_chip_eoi_parent(d);
+}
+
+static void rzg2l_gpio_irq_print_chip(struct irq_data *data, struct seq_file *p)
+{
+	struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
+
+	seq_printf(p, dev_name(gc->parent));
+}
+
+static const struct irq_chip rzg2l_gpio_irqchip = {
+	.name = "rzg2l-gpio",
+	.irq_disable = rzg2l_gpio_irq_disable,
+	.irq_enable = rzg2l_gpio_irq_enable,
+	.irq_mask = irq_chip_mask_parent,
+	.irq_unmask = irq_chip_unmask_parent,
+	.irq_set_type = rzg2l_gpio_irq_set_type,
+	.irq_eoi = rzg2l_gpio_irqc_eoi,
+	.irq_print_chip = rzg2l_gpio_irq_print_chip,
+	.flags = IRQCHIP_IMMUTABLE,
+	GPIOCHIP_IRQ_RESOURCE_HELPERS,
+};
+
+static int rzg2l_gpio_child_to_parent_hwirq(struct gpio_chip *gc,
+					    unsigned int child,
+					    unsigned int child_type,
+					    unsigned int *parent,
+					    unsigned int *parent_type)
+{
+	struct rzg2l_pinctrl *pctrl = gpiochip_get_data(gc);
+	int gpioint;
+
+	gpioint = rzg2l_gpio_get_gpioint(pctrl->hwirq[child]);
+	if (gpioint < 0)
+		return gpioint;
+
+	/* All these interrupts are level high in the CPU */
+	*parent_type = IRQ_TYPE_LEVEL_HIGH;
+	*parent = RZG2L_PACK_HWIRQ(gpioint, child + RZG2L_TINT_IRQ_START_INDEX);
+	return 0;
+}
+
+static void *rzg2l_gpio_populate_parent_fwspec(struct gpio_chip *chip,
+					       unsigned int parent_hwirq,
+					       unsigned int parent_type)
+{
+	struct irq_fwspec *fwspec;
+
+	fwspec = kzalloc(sizeof(*fwspec), GFP_KERNEL);
+	if (!fwspec)
+		return NULL;
+
+	fwspec->fwnode = chip->irq.parent_domain->fwnode;
+	fwspec->param_count = 2;
+	fwspec->param[0] = parent_hwirq;
+	fwspec->param[1] = parent_type;
+
+	return fwspec;
+}
+
+static int rzg2l_gpio_child_offset_to_irq(struct gpio_chip *gc,
+					  unsigned int offset,
+					  unsigned int *hwirq)
+{
+	struct rzg2l_pinctrl *pctrl = gpiochip_get_data(gc);
+	unsigned long flags;
+	int gpioint, irq;
+
+	gpioint = rzg2l_gpio_get_gpioint(offset);
+	if (gpioint < 0)
+		return gpioint;
+
+	spin_lock_irqsave(&pctrl->bitmap_lock, flags);
+	irq = bitmap_find_free_region(pctrl->tint_slot, RZG2L_TINT_MAX_INTERRUPT, get_order(1));
+	spin_unlock_irqrestore(&pctrl->bitmap_lock, flags);
+	if (irq < 0)
+		return -ENOSPC;
+
+	pctrl->hwirq[irq] = offset;
+	*hwirq = irq;
+
+	return 0;
+}
+
 static int rzg2l_gpio_register(struct rzg2l_pinctrl *pctrl)
 {
 	struct device_node *np = pctrl->dev->of_node;
 	struct gpio_chip *chip = &pctrl->gpio_chip;
 	const char *name = dev_name(pctrl->dev);
+	struct irq_domain *parent_domain;
 	struct of_phandle_args of_args;
+	struct device_node *parent_np;
+	struct gpio_irq_chip *girq;
 	int ret;
 
+	parent_np = of_irq_find_parent(np);
+	if (!parent_np)
+		return -ENXIO;
+
+	parent_domain = irq_find_host(parent_np);
+	of_node_put(parent_np);
+	if (!parent_domain)
+		return -EPROBE_DEFER;
+
 	ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, 0, &of_args);
 	if (ret) {
 		dev_err(pctrl->dev, "Unable to parse gpio-ranges\n");
@@ -1138,6 +1349,15 @@ static int rzg2l_gpio_register(struct rzg2l_pinctrl *pctrl)
 	chip->base = -1;
 	chip->ngpio = of_args.args[2];
 
+	girq = &chip->irq;
+	gpio_irq_chip_set_chip(girq, &rzg2l_gpio_irqchip);
+	girq->fwnode = of_node_to_fwnode(np);
+	girq->parent_domain = parent_domain;
+	girq->child_to_parent_hwirq = rzg2l_gpio_child_to_parent_hwirq;
+	girq->populate_parent_alloc_arg = rzg2l_gpio_populate_parent_fwspec;
+	girq->child_offset_to_irq = rzg2l_gpio_child_offset_to_irq;
+	girq->ngirq = RZG2L_TINT_MAX_INTERRUPT;
+
 	pctrl->gpio_range.id = 0;
 	pctrl->gpio_range.pin_base = 0;
 	pctrl->gpio_range.base = 0;
@@ -1253,6 +1473,7 @@ static int rzg2l_pinctrl_probe(struct platform_device *pdev)
 	}
 
 	spin_lock_init(&pctrl->lock);
+	spin_lock_init(&pctrl->bitmap_lock);
 
 	platform_set_drvdata(pdev, pctrl);
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH v4 5/7] gpio: gpiolib: Add a check to validate GPIO hwirq
  2022-05-18 19:29 ` [PATCH v4 5/7] gpio: gpiolib: Add a check to validate GPIO hwirq Lad Prabhakar
@ 2022-05-18 21:08   ` Andy Shevchenko
  2022-05-19  4:11     ` Lad, Prabhakar
  0 siblings, 1 reply; 20+ messages in thread
From: Andy Shevchenko @ 2022-05-18 21:08 UTC (permalink / raw)
  To: Lad Prabhakar
  Cc: Marc Zyngier, Geert Uytterhoeven, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Linus Walleij, Bartosz Golaszewski,
	Thierry Reding, Jonathan Hunter, Bjorn Andersson, Andy Gross,
	Philipp Zabel, open list:GPIO SUBSYSTEM, linux-tegra,
	linux-arm-msm, devicetree, Linux Kernel Mailing List, Prabhakar,
	Linux-Renesas, Phil Edworthy, Biju Das

On Wed, May 18, 2022 at 9:30 PM Lad Prabhakar
<prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
>
> Add a check to validate GPIO hwirq is always within the range of hwirq_max
> set in the GPIO irq domain.

...

> +                       if (WARN(hwirq >= domain->hwirq_max,
> +                                "error: hwirq 0x%x is too large for %s\n",
> +                                (int)hwirq, domain->name))

Using castings in the printf() often points to possible mistakes or
missed custom specifiers.

...

> +               if (WARN(hwirq >= domain->hwirq_max,
> +                        "error: hwirq 0x%x is too large for %s\n", (int)hwirq, domain->name))

Ditto.

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v4 0/7] Renesas RZ/G2L IRQC support
  2022-05-18 19:29 [PATCH v4 0/7] Renesas RZ/G2L IRQC support Lad Prabhakar
                   ` (6 preceding siblings ...)
  2022-05-18 19:29 ` [PATCH v4 7/7] pinctrl: renesas: pinctrl-rzg2l: Add IRQ domain to handle GPIO interrupt Lad Prabhakar
@ 2022-05-18 21:09 ` Andy Shevchenko
  2022-05-19  4:07   ` Lad, Prabhakar
  7 siblings, 1 reply; 20+ messages in thread
From: Andy Shevchenko @ 2022-05-18 21:09 UTC (permalink / raw)
  To: Lad Prabhakar
  Cc: Marc Zyngier, Geert Uytterhoeven, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Linus Walleij, Bartosz Golaszewski,
	Thierry Reding, Jonathan Hunter, Bjorn Andersson, Andy Gross,
	Philipp Zabel, open list:GPIO SUBSYSTEM, linux-tegra,
	linux-arm-msm, devicetree, Linux Kernel Mailing List, Prabhakar,
	Linux-Renesas, Phil Edworthy, Biju Das

On Wed, May 18, 2022 at 9:29 PM Lad Prabhakar
<prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
>
> Hi All,
>
> The RZ/G2L Interrupt Controller is a front-end for the GIC found on
> Renesas RZ/G2L SoC's with below pins:
> - IRQ sense select for 8 external interrupts, mapped to 8 GIC SPI
>   interrupts
> - GPIO pins used as external interrupt input pins out of GPIOINT0-122 a
>   maximum of only 32 can be mapped to 32 GIC SPI interrupts,
> - NMI edge select.
>
>                                                              _____________
>                                                              |    GIC     |
>                                                              |  ________  |
>                                       ____________           | |        | |
> NMI --------------------------------->|          |  SPI0-479 | | GIC-600| |
>              _______                  |          |------------>|        | |
>              |      |                 |          |  PPI16-31 | |        | |
>              |      | IRQ0-IRQ7       |   IRQC   |------------>|        | |
> P0_P48_4 --->| GPIO |---------------->|          |           | |________| |
>              |      |GPIOINT0-122     |          |           |            |
>              |      |---------------->| TINT0-31 |           |            |
>              |______|                 |__________|           |____________|
>
> The proposed patches add hierarchical IRQ domain, one in IRQC driver and
> another in pinctrl driver. Upon interrupt requests map the interrupt to
> GIC. Out of GPIOINT0-122 only 32 can be mapped to GIC SPI, this mapping is
> handled by the pinctrl and IRQC driver.

Where is the explanation on why valid_mask can't be used instead?


-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v4 0/7] Renesas RZ/G2L IRQC support
  2022-05-18 21:09 ` [PATCH v4 0/7] Renesas RZ/G2L IRQC support Andy Shevchenko
@ 2022-05-19  4:07   ` Lad, Prabhakar
  2022-05-19  6:58     ` Biju Das
  2022-05-19 10:07     ` Andy Shevchenko
  0 siblings, 2 replies; 20+ messages in thread
From: Lad, Prabhakar @ 2022-05-19  4:07 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Lad Prabhakar, Marc Zyngier, Geert Uytterhoeven, Thomas Gleixner,
	Rob Herring, Krzysztof Kozlowski, Linus Walleij,
	Bartosz Golaszewski, Thierry Reding, Jonathan Hunter,
	Bjorn Andersson, Andy Gross, Philipp Zabel,
	open list:GPIO SUBSYSTEM, linux-tegra, linux-arm-msm, devicetree,
	Linux Kernel Mailing List, Linux-Renesas, Phil Edworthy,
	Biju Das

On Wed, May 18, 2022 at 10:10 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Wed, May 18, 2022 at 9:29 PM Lad Prabhakar
> <prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
> >
> > Hi All,
> >
> > The RZ/G2L Interrupt Controller is a front-end for the GIC found on
> > Renesas RZ/G2L SoC's with below pins:
> > - IRQ sense select for 8 external interrupts, mapped to 8 GIC SPI
> >   interrupts
> > - GPIO pins used as external interrupt input pins out of GPIOINT0-122 a
> >   maximum of only 32 can be mapped to 32 GIC SPI interrupts,
> > - NMI edge select.
> >
> >                                                              _____________
> >                                                              |    GIC     |
> >                                                              |  ________  |
> >                                       ____________           | |        | |
> > NMI --------------------------------->|          |  SPI0-479 | | GIC-600| |
> >              _______                  |          |------------>|        | |
> >              |      |                 |          |  PPI16-31 | |        | |
> >              |      | IRQ0-IRQ7       |   IRQC   |------------>|        | |
> > P0_P48_4 --->| GPIO |---------------->|          |           | |________| |
> >              |      |GPIOINT0-122     |          |           |            |
> >              |      |---------------->| TINT0-31 |           |            |
> >              |______|                 |__________|           |____________|
> >
> > The proposed patches add hierarchical IRQ domain, one in IRQC driver and
> > another in pinctrl driver. Upon interrupt requests map the interrupt to
> > GIC. Out of GPIOINT0-122 only 32 can be mapped to GIC SPI, this mapping is
> > handled by the pinctrl and IRQC driver.
>
> Where is the explanation on why valid_mask can't be used instead?
>
The .valid_mask option is one time setting but what I need is
something dynamic i.e. out of 392 GPIO pins any 32 can be used as an
interrupt pin. Also with this patch we also save on memory here [0].

[0] https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/tree/kernel/irq/irqdomain.c?h=next-20220518#n153

Cheers,
Prabhakar
>
> --
> With Best Regards,
> Andy Shevchenko

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v4 5/7] gpio: gpiolib: Add a check to validate GPIO hwirq
  2022-05-18 21:08   ` Andy Shevchenko
@ 2022-05-19  4:11     ` Lad, Prabhakar
  0 siblings, 0 replies; 20+ messages in thread
From: Lad, Prabhakar @ 2022-05-19  4:11 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Lad Prabhakar, Marc Zyngier, Geert Uytterhoeven, Thomas Gleixner,
	Rob Herring, Krzysztof Kozlowski, Linus Walleij,
	Bartosz Golaszewski, Thierry Reding, Jonathan Hunter,
	Bjorn Andersson, Andy Gross, Philipp Zabel,
	open list:GPIO SUBSYSTEM, linux-tegra, linux-arm-msm, devicetree,
	Linux Kernel Mailing List, Linux-Renesas, Phil Edworthy,
	Biju Das

Hi Andy,

Thank you for the review.

On Wed, May 18, 2022 at 10:08 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Wed, May 18, 2022 at 9:30 PM Lad Prabhakar
> <prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
> >
> > Add a check to validate GPIO hwirq is always within the range of hwirq_max
> > set in the GPIO irq domain.
>
> ...
>
> > +                       if (WARN(hwirq >= domain->hwirq_max,
> > +                                "error: hwirq 0x%x is too large for %s\n",
> > +                                (int)hwirq, domain->name))
>
> Using castings in the printf() often points to possible mistakes or
> missed custom specifiers.
>
Right, I picked up the printf() just a few lines above where it did
the same exact thing. I will update it in the next version.

> ...
>
> > +               if (WARN(hwirq >= domain->hwirq_max,
> > +                        "error: hwirq 0x%x is too large for %s\n", (int)hwirq, domain->name))
>
> Ditto.
>
Will drop castings.

Cheers,
Prabhakar

^ permalink raw reply	[flat|nested] 20+ messages in thread

* RE: [PATCH v4 0/7] Renesas RZ/G2L IRQC support
  2022-05-19  4:07   ` Lad, Prabhakar
@ 2022-05-19  6:58     ` Biju Das
  2022-05-23 17:28       ` Lad, Prabhakar
  2022-05-19 10:07     ` Andy Shevchenko
  1 sibling, 1 reply; 20+ messages in thread
From: Biju Das @ 2022-05-19  6:58 UTC (permalink / raw)
  To: Lad, Prabhakar, Andy Shevchenko
  Cc: Prabhakar Mahadev Lad, Marc Zyngier, Geert Uytterhoeven,
	Thomas Gleixner, Rob Herring, Krzysztof Kozlowski, Linus Walleij,
	Bartosz Golaszewski, Thierry Reding, Jonathan Hunter,
	Bjorn Andersson, Andy Gross, Philipp Zabel,
	open list:GPIO SUBSYSTEM, linux-tegra, linux-arm-msm, devicetree,
	Linux Kernel Mailing List, Linux-Renesas, Phil Edworthy

Hi Prabhakar,

> Subject: Re: [PATCH v4 0/7] Renesas RZ/G2L IRQC support
> 
> On Wed, May 18, 2022 at 10:10 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> >
> > On Wed, May 18, 2022 at 9:29 PM Lad Prabhakar
> > <prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
> > >
> > > Hi All,
> > >
> > > The RZ/G2L Interrupt Controller is a front-end for the GIC found on
> > > Renesas RZ/G2L SoC's with below pins:
> > > - IRQ sense select for 8 external interrupts, mapped to 8 GIC SPI
> > >   interrupts
> > > - GPIO pins used as external interrupt input pins out of GPIOINT0-122 a
> > >   maximum of only 32 can be mapped to 32 GIC SPI interrupts,
> > > - NMI edge select.
> > >
> > >
> _____________
> > >                                                              |    GIC
> |
> > >                                                              |
> ________  |
> > >                                       ____________           | |
> | |
> > > NMI --------------------------------->|          |  SPI0-479 | | GIC-
> 600| |
> > >              _______                  |          |------------>|
> | |
> > >              |      |                 |          |  PPI16-31 | |
> | |
> > >              |      | IRQ0-IRQ7       |   IRQC   |------------>|
> | |
> > > P0_P48_4 --->| GPIO |---------------->|          |           |
> |________| |
> > >              |      |GPIOINT0-122     |          |           |
> |
> > >              |      |---------------->| TINT0-31 |           |
> |
> > >              |______|                 |__________|
> |____________|
> > >
> > > The proposed patches add hierarchical IRQ domain, one in IRQC driver
> > > and another in pinctrl driver. Upon interrupt requests map the
> > > interrupt to GIC. Out of GPIOINT0-122 only 32 can be mapped to GIC
> > > SPI, this mapping is handled by the pinctrl and IRQC driver.
> >
> > Where is the explanation on why valid_mask can't be used instead?
> >
> The .valid_mask option is one time setting 

One question, if it is one time setting, Is it possible to use .valid mask to invalidate 
invalid gpio lines?(ie, currently gpio range is 392, but there is only 123 GPIOs
present in the SoC, not sure this call back can be used to invalidate the non-supported GPIOS??).

Cheers,
Biju



but what I need is something
> dynamic i.e. out of 392 GPIO pins any 32 can be used as an interrupt pin.
> Also with this patch we also save on memory here [0].
,
> > Andy Shevchenko

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v4 0/7] Renesas RZ/G2L IRQC support
  2022-05-19  4:07   ` Lad, Prabhakar
  2022-05-19  6:58     ` Biju Das
@ 2022-05-19 10:07     ` Andy Shevchenko
  1 sibling, 0 replies; 20+ messages in thread
From: Andy Shevchenko @ 2022-05-19 10:07 UTC (permalink / raw)
  To: Lad, Prabhakar
  Cc: Lad Prabhakar, Marc Zyngier, Geert Uytterhoeven, Thomas Gleixner,
	Rob Herring, Krzysztof Kozlowski, Linus Walleij,
	Bartosz Golaszewski, Thierry Reding, Jonathan Hunter,
	Bjorn Andersson, Andy Gross, Philipp Zabel,
	open list:GPIO SUBSYSTEM, linux-tegra, linux-arm-msm, devicetree,
	Linux Kernel Mailing List, Linux-Renesas, Phil Edworthy,
	Biju Das

On Thu, May 19, 2022 at 6:07 AM Lad, Prabhakar
<prabhakar.csengg@gmail.com> wrote:
> On Wed, May 18, 2022 at 10:10 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> > On Wed, May 18, 2022 at 9:29 PM Lad Prabhakar
> > <prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:

...

> > > GIC. Out of GPIOINT0-122 only 32 can be mapped to GIC SPI, this mapping is
> > > handled by the pinctrl and IRQC driver.
> >
> > Where is the explanation on why valid_mask can't be used instead?
> >
> The .valid_mask option is one time setting but what I need is
> something dynamic i.e. out of 392 GPIO pins any 32 can be used as an
> interrupt pin. Also with this patch we also save on memory here [0].

Which internal APIs are bound to valid_mask not to be updated?

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v4 6/7] dt-bindings: pinctrl: renesas,rzg2l-pinctrl: Document the properties to handle GPIO IRQ
  2022-05-18 19:29 ` [PATCH v4 6/7] dt-bindings: pinctrl: renesas,rzg2l-pinctrl: Document the properties to handle GPIO IRQ Lad Prabhakar
@ 2022-05-19 12:01   ` Geert Uytterhoeven
  2022-05-23 17:29     ` Lad, Prabhakar
  0 siblings, 1 reply; 20+ messages in thread
From: Geert Uytterhoeven @ 2022-05-19 12:01 UTC (permalink / raw)
  To: Lad Prabhakar
  Cc: Marc Zyngier, Geert Uytterhoeven, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Linus Walleij, Bartosz Golaszewski,
	Thierry Reding, Jonathan Hunter, Bjorn Andersson, Andy Gross,
	Philipp Zabel, Andy Shevchenko, open list:GPIO SUBSYSTEM,
	linux-tegra, linux-arm-msm,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	Linux Kernel Mailing List, Prabhakar, Linux-Renesas,
	Phil Edworthy, Biju Das

Hi Prabhakar,

On Wed, May 18, 2022 at 9:30 PM Lad Prabhakar
<prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
> Document the required properties to handle GPIO IRQ.
>
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

Thanks for your patch!

> --- a/Documentation/devicetree/bindings/pinctrl/renesas,rzg2l-pinctrl.yaml
> +++ b/Documentation/devicetree/bindings/pinctrl/renesas,rzg2l-pinctrl.yaml
> @@ -126,6 +139,9 @@ examples:
>              gpio-controller;
>              #gpio-cells = <2>;
>              gpio-ranges = <&pinctrl 0 0 392>;
> +            interrupt-controller;
> +            #interrupt-cells = <2>;
> +            interrupt-parent = <&irqc>;

I think the "interrupt-parent" property can be dropped from the example.

>              clocks = <&cpg CPG_MOD R9A07G044_GPIO_HCLK>;
>              resets = <&cpg R9A07G044_GPIO_RSTN>,
>                       <&cpg R9A07G044_GPIO_PORT_RESETN>,

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v4 3/7] gpio: gpiolib: Add ngirq member to struct gpio_irq_chip
  2022-05-18 19:29 ` [PATCH v4 3/7] gpio: gpiolib: Add ngirq member to struct gpio_irq_chip Lad Prabhakar
@ 2022-05-19 13:26   ` Linus Walleij
  2022-05-23 17:27     ` Lad, Prabhakar
  0 siblings, 1 reply; 20+ messages in thread
From: Linus Walleij @ 2022-05-19 13:26 UTC (permalink / raw)
  To: Lad Prabhakar
  Cc: Marc Zyngier, Geert Uytterhoeven, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Bartosz Golaszewski, Thierry Reding,
	Jonathan Hunter, Bjorn Andersson, Andy Gross, Philipp Zabel,
	Andy Shevchenko, linux-gpio, linux-tegra, linux-arm-msm,
	devicetree, linux-kernel, Prabhakar, linux-renesas-soc,
	Phil Edworthy, Biju Das

On Wed, May 18, 2022 at 9:30 PM Lad Prabhakar
<prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:

> Supported GPIO IRQs by the chip is not always equal to the number of GPIO
> pins. For example on Renesas RZ/G2L SoC where it has GPIO0-122 pins but at
> a given point a maximum of only 32 GPIO pins can be used as IRQ lines in
> the IRQC domain.
>
> This patch adds ngirq member to struct gpio_irq_chip and passes this as a
> size to irq_domain_create_hierarchy()/irq_domain_create_simple() if it is
> being set in the driver otherwise fallbacks to using ngpio.
>
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

NAK

As pointed out this is a property of the hardware and thus you should
derive this property of the hardware from the compatible string.

For example by passing per-variant .data in struct of_device_id.

Unique hardware properties means unique hardware means it should
have a unique compatible string. Otherwise something is wrong
with the compatibles.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v4 4/7] gpio: gpiolib: Dont assume child_offset_to_irq callback always succeeds
  2022-05-18 19:29 ` [PATCH v4 4/7] gpio: gpiolib: Dont assume child_offset_to_irq callback always succeeds Lad Prabhakar
@ 2022-05-19 13:30   ` Linus Walleij
  0 siblings, 0 replies; 20+ messages in thread
From: Linus Walleij @ 2022-05-19 13:30 UTC (permalink / raw)
  To: Lad Prabhakar
  Cc: Marc Zyngier, Geert Uytterhoeven, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Bartosz Golaszewski, Thierry Reding,
	Jonathan Hunter, Bjorn Andersson, Andy Gross, Philipp Zabel,
	Andy Shevchenko, linux-gpio, linux-tegra, linux-arm-msm,
	devicetree, linux-kernel, Prabhakar, linux-renesas-soc,
	Phil Edworthy, Biju Das

On Wed, May 18, 2022 at 9:30 PM Lad Prabhakar
<prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:

> On Renesas RZ/G2L SoC not all the GPIO pins can be simultaneously used as
> interrupts. The SoC allows 32 interrupts which is first come first serve
> basis and is dynamic i.e. if there is a free slot (after rmmod) this can
> be used by other GPIO pins being used as an interrupt.
>
> To handle such cases change child_offset_to_irq() callback to return error
> codes in case of failure. All the users of child_offset_to_irq() callback
> are also updated with this API change.
>
> Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>

This looks very useful!
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v4 3/7] gpio: gpiolib: Add ngirq member to struct gpio_irq_chip
  2022-05-19 13:26   ` Linus Walleij
@ 2022-05-23 17:27     ` Lad, Prabhakar
  0 siblings, 0 replies; 20+ messages in thread
From: Lad, Prabhakar @ 2022-05-23 17:27 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Lad Prabhakar, Marc Zyngier, Geert Uytterhoeven, Thomas Gleixner,
	Rob Herring, Krzysztof Kozlowski, Bartosz Golaszewski,
	Thierry Reding, Jonathan Hunter, Bjorn Andersson, Andy Gross,
	Philipp Zabel, Andy Shevchenko, open list:GPIO SUBSYSTEM,
	linux-tegra, linux-arm-msm,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS, LKML,
	Linux-Renesas, Phil Edworthy, Biju Das

Hi Linus,

Thank you for the review.

On Thu, May 19, 2022 at 2:26 PM Linus Walleij <linus.walleij@linaro.org> wrote:
>
> On Wed, May 18, 2022 at 9:30 PM Lad Prabhakar
> <prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
>
> > Supported GPIO IRQs by the chip is not always equal to the number of GPIO
> > pins. For example on Renesas RZ/G2L SoC where it has GPIO0-122 pins but at
> > a given point a maximum of only 32 GPIO pins can be used as IRQ lines in
> > the IRQC domain.
> >
> > This patch adds ngirq member to struct gpio_irq_chip and passes this as a
> > size to irq_domain_create_hierarchy()/irq_domain_create_simple() if it is
> > being set in the driver otherwise fallbacks to using ngpio.
> >
> > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
>
> NAK
>
> As pointed out this is a property of the hardware and thus you should
> derive this property of the hardware from the compatible string.
>
> For example by passing per-variant .data in struct of_device_id.
>
> Unique hardware properties means unique hardware means it should
> have a unique compatible string. Otherwise something is wrong
> with the compatibles.
>
Agreed, I will drop this.

Cheers,
Prabhakar

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v4 0/7] Renesas RZ/G2L IRQC support
  2022-05-19  6:58     ` Biju Das
@ 2022-05-23 17:28       ` Lad, Prabhakar
  0 siblings, 0 replies; 20+ messages in thread
From: Lad, Prabhakar @ 2022-05-23 17:28 UTC (permalink / raw)
  To: Biju Das
  Cc: Andy Shevchenko, Prabhakar Mahadev Lad, Marc Zyngier,
	Geert Uytterhoeven, Thomas Gleixner, Rob Herring,
	Krzysztof Kozlowski, Linus Walleij, Bartosz Golaszewski,
	Thierry Reding, Jonathan Hunter, Bjorn Andersson, Andy Gross,
	Philipp Zabel, open list:GPIO SUBSYSTEM, linux-tegra,
	linux-arm-msm, devicetree, Linux Kernel Mailing List,
	Linux-Renesas, Phil Edworthy

Hi Biju,

On Thu, May 19, 2022 at 7:58 AM Biju Das <biju.das.jz@bp.renesas.com> wrote:
>
> Hi Prabhakar,
>
> > Subject: Re: [PATCH v4 0/7] Renesas RZ/G2L IRQC support
> >
> > On Wed, May 18, 2022 at 10:10 PM Andy Shevchenko
> > <andy.shevchenko@gmail.com> wrote:
> > >
> > > On Wed, May 18, 2022 at 9:29 PM Lad Prabhakar
> > > <prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
> > > >
> > > > Hi All,
> > > >
> > > > The RZ/G2L Interrupt Controller is a front-end for the GIC found on
> > > > Renesas RZ/G2L SoC's with below pins:
> > > > - IRQ sense select for 8 external interrupts, mapped to 8 GIC SPI
> > > >   interrupts
> > > > - GPIO pins used as external interrupt input pins out of GPIOINT0-122 a
> > > >   maximum of only 32 can be mapped to 32 GIC SPI interrupts,
> > > > - NMI edge select.
> > > >
> > > >
> > _____________
> > > >                                                              |    GIC
> > |
> > > >                                                              |
> > ________  |
> > > >                                       ____________           | |
> > | |
> > > > NMI --------------------------------->|          |  SPI0-479 | | GIC-
> > 600| |
> > > >              _______                  |          |------------>|
> > | |
> > > >              |      |                 |          |  PPI16-31 | |
> > | |
> > > >              |      | IRQ0-IRQ7       |   IRQC   |------------>|
> > | |
> > > > P0_P48_4 --->| GPIO |---------------->|          |           |
> > |________| |
> > > >              |      |GPIOINT0-122     |          |           |
> > |
> > > >              |      |---------------->| TINT0-31 |           |
> > |
> > > >              |______|                 |__________|
> > |____________|
> > > >
> > > > The proposed patches add hierarchical IRQ domain, one in IRQC driver
> > > > and another in pinctrl driver. Upon interrupt requests map the
> > > > interrupt to GIC. Out of GPIOINT0-122 only 32 can be mapped to GIC
> > > > SPI, this mapping is handled by the pinctrl and IRQC driver.
> > >
> > > Where is the explanation on why valid_mask can't be used instead?
> > >
> > The .valid_mask option is one time setting
>
> One question, if it is one time setting, Is it possible to use .valid mask to invalidate
> invalid gpio lines?(ie, currently gpio range is 392, but there is only 123 GPIOs
> present in the SoC, not sure this call back can be used to invalidate the non-supported GPIOS??).
>
Yes can be added, I will include it in the next version.

Cheers,
Prabhakar

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v4 6/7] dt-bindings: pinctrl: renesas,rzg2l-pinctrl: Document the properties to handle GPIO IRQ
  2022-05-19 12:01   ` Geert Uytterhoeven
@ 2022-05-23 17:29     ` Lad, Prabhakar
  0 siblings, 0 replies; 20+ messages in thread
From: Lad, Prabhakar @ 2022-05-23 17:29 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: Lad Prabhakar, Marc Zyngier, Geert Uytterhoeven, Thomas Gleixner,
	Rob Herring, Krzysztof Kozlowski, Linus Walleij,
	Bartosz Golaszewski, Thierry Reding, Jonathan Hunter,
	Bjorn Andersson, Andy Gross, Philipp Zabel, Andy Shevchenko,
	open list:GPIO SUBSYSTEM, linux-tegra, linux-arm-msm,
	open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS,
	Linux Kernel Mailing List, Linux-Renesas, Phil Edworthy,
	Biju Das

Hi Geert,

Thank you for the review.

On Thu, May 19, 2022 at 1:01 PM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
>
> Hi Prabhakar,
>
> On Wed, May 18, 2022 at 9:30 PM Lad Prabhakar
> <prabhakar.mahadev-lad.rj@bp.renesas.com> wrote:
> > Document the required properties to handle GPIO IRQ.
> >
> > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
>
> Thanks for your patch!
>
> > --- a/Documentation/devicetree/bindings/pinctrl/renesas,rzg2l-pinctrl.yaml
> > +++ b/Documentation/devicetree/bindings/pinctrl/renesas,rzg2l-pinctrl.yaml
> > @@ -126,6 +139,9 @@ examples:
> >              gpio-controller;
> >              #gpio-cells = <2>;
> >              gpio-ranges = <&pinctrl 0 0 392>;
> > +            interrupt-controller;
> > +            #interrupt-cells = <2>;
> > +            interrupt-parent = <&irqc>;
>
> I think the "interrupt-parent" property can be dropped from the example.
>
Sure will drop it in the next version.

Cheers,
Prabhakar

> >              clocks = <&cpg CPG_MOD R9A07G044_GPIO_HCLK>;
> >              resets = <&cpg R9A07G044_GPIO_RSTN>,
> >                       <&cpg R9A07G044_GPIO_PORT_RESETN>,
>
> Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
>
> Gr{oetje,eeting}s,
>
>                         Geert
>
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
>
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
>                                 -- Linus Torvalds

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2022-05-23 18:13 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-18 19:29 [PATCH v4 0/7] Renesas RZ/G2L IRQC support Lad Prabhakar
2022-05-18 19:29 ` [PATCH v4 1/7] dt-bindings: interrupt-controller: Add Renesas RZ/G2L Interrupt Controller Lad Prabhakar
2022-05-18 19:29 ` [PATCH v4 2/7] irqchip: Add RZ/G2L IA55 Interrupt Controller driver Lad Prabhakar
2022-05-18 19:29 ` [PATCH v4 3/7] gpio: gpiolib: Add ngirq member to struct gpio_irq_chip Lad Prabhakar
2022-05-19 13:26   ` Linus Walleij
2022-05-23 17:27     ` Lad, Prabhakar
2022-05-18 19:29 ` [PATCH v4 4/7] gpio: gpiolib: Dont assume child_offset_to_irq callback always succeeds Lad Prabhakar
2022-05-19 13:30   ` Linus Walleij
2022-05-18 19:29 ` [PATCH v4 5/7] gpio: gpiolib: Add a check to validate GPIO hwirq Lad Prabhakar
2022-05-18 21:08   ` Andy Shevchenko
2022-05-19  4:11     ` Lad, Prabhakar
2022-05-18 19:29 ` [PATCH v4 6/7] dt-bindings: pinctrl: renesas,rzg2l-pinctrl: Document the properties to handle GPIO IRQ Lad Prabhakar
2022-05-19 12:01   ` Geert Uytterhoeven
2022-05-23 17:29     ` Lad, Prabhakar
2022-05-18 19:29 ` [PATCH v4 7/7] pinctrl: renesas: pinctrl-rzg2l: Add IRQ domain to handle GPIO interrupt Lad Prabhakar
2022-05-18 21:09 ` [PATCH v4 0/7] Renesas RZ/G2L IRQC support Andy Shevchenko
2022-05-19  4:07   ` Lad, Prabhakar
2022-05-19  6:58     ` Biju Das
2022-05-23 17:28       ` Lad, Prabhakar
2022-05-19 10:07     ` Andy Shevchenko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).