Devicetree
 help / color / mirror / Atom feed
* [PATCH v3 0/2] gpio: Add the Siflower SF19A2890 GPIO controller
@ 2026-11-23  1:37 Joseph Telaak via B4 Relay
  2026-11-23  1:37 ` [PATCH v3 1/2] dt-bindings: gpio: Add " Joseph Telaak via B4 Relay
  2026-11-23  1:37 ` [PATCH v3 2/2] gpio: Add Siflower GPIO controller driver Joseph Telaak via B4 Relay
  0 siblings, 2 replies; 5+ messages in thread
From: Joseph Telaak via B4 Relay @ 2026-11-23  1:37 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Philipp Zabel
  Cc: Chuanhong Guo, Qingfang Deng, Michael Walle, linux-mips,
	linux-gpio, devicetree, linux-kernel, Krzysztof Kozlowski,
	Joseph Telaak, Qingfang Deng

This series adds a binding and a driver for the GPIO controller of the
Siflower SoCs, starting with the SF19A2890, a MIPS SoC for home routers.
Each line has a register block of its own, and each group of 16 lines an
interrupt.

The binding is Chuanhong Guo's and the driver Qingfang Deng's, both from
Chuanhong's SF19A2890 branch [1], with my changes noted in each. The
same controller is in Siflower's SF21 RISC-V SoCs; the binding has only
the SF19A2890's compatible, the one I can test.

The SoC support itself (MACH_SIFLOWER_MIPS) goes through the MIPS tree;
until then the driver builds with COMPILE_TEST.

Tested on a GL.iNet GL-SFT1200. Earlier, on v7.4-rc1: gpio-keys sees
both buttons on both edges (the reset button on GPIO 27 as KEY_RESTART,
the mode slide switch on GPIO 1 as BTN_0, 1 and 0 per slide);
/sys/kernel/debug/gpio lists the 49 lines; the GSW150 switch comes out
of reset through GPIO 0 and the SPI NAND uses GPIO 8 as its chip select.
v3 was run again on OpenWrt's 6.18 kernel, with the driver backported
along with the gpio tree's gpio-regmap: the same four lines work, and
both buttons raise their interrupts on both edges through the driver's
IRQ domain. The board's device tree sets no debounce, so the debounce
path was not exercised.

[1] https://github.com/981213/linux/commits/siflower-7.1

---
Changes in v3:
- Move the driver to gpio-regmap on regmap-mmio, with a
  reg_mask_xlate() for the 0x40 stride between the lines' registers and
  the debounce in set_config() (Linus).
- Put the interrupts on an IRQ domain of the driver's own, with a
  chained handler for each group of 16 lines, since gpio-regmap sets up
  no gpio_irq_chip. The chained handlers are removed with devm.
- Patch 1: add Krzysztof's Reviewed-by.
- Link to v2: https://patch.msgid.link/20261109-sf19a2890-gpio-v2-0-b885fbd84c4c@telaak.dev

Changes in v2:
- Write my notes on Chuanhong's and Qingfang's patches as lists, with
  Co-developed-by on the driver (Bartosz).
- Get priv with gpiochip_get_data(), drop the two else branches, and add
  a blank line after the header comment (Bartosz).
- Get the reset with devm_reset_control_get_exclusive_deasserted(), as a
  local, not in priv (Philipp), and drop the OF_GPIO dependency.
- Name only the SF19A2890 in the Kconfig help and the binding's commit
  message, since the other SoCs need compatibles of their own (Conor).
- Drop the ngpios property, which the compatible implies: the driver
  takes the number of lines from its match data, and the binding takes
  exactly four interrupts (Conor).
- Order the binding's properties and its required list (Conor).
- Add a MAINTAINERS entry for the driver and its binding.
- Use GPL-2.0-or-later, not the deprecated GPL-2.0+ SPDX identifier.
- Use readl() and writel() directly, without wrapper functions (Linus).
- No comma after the match table's sentinel, as Uwe asked of the
  clock driver.
- Drop the unused linux/pinctrl/consumer.h include.
- Link to v1: https://patch.msgid.link/20261104-sf19a2890-gpio-v1-0-45e463c48728@telaak.dev

---
Chuanhong Guo (1):
      dt-bindings: gpio: Add Siflower SF19A2890 GPIO controller

Qingfang Deng (1):
      gpio: Add Siflower GPIO controller driver

 .../bindings/gpio/siflower,sf19a2890-gpio.yaml     |  76 +++++
 MAINTAINERS                                        |   7 +
 drivers/gpio/Kconfig                               |  14 +
 drivers/gpio/Makefile                              |   1 +
 drivers/gpio/gpio-siflower.c                       | 344 +++++++++++++++++++++
 5 files changed, 442 insertions(+)
---
base-commit: d66b6b86d5a6278ca930112c634d03725beb7d9a
change-id: 20261102-sf19a2890-gpio-b21562e52f88

Best regards,
--  
Joseph Telaak <joseph@telaak.dev>



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

* [PATCH v3 1/2] dt-bindings: gpio: Add Siflower SF19A2890 GPIO controller
  2026-11-23  1:37 [PATCH v3 0/2] gpio: Add the Siflower SF19A2890 GPIO controller Joseph Telaak via B4 Relay
@ 2026-11-23  1:37 ` Joseph Telaak via B4 Relay
  2026-11-23  1:45   ` sashiko-bot
  2026-11-23  1:37 ` [PATCH v3 2/2] gpio: Add Siflower GPIO controller driver Joseph Telaak via B4 Relay
  1 sibling, 1 reply; 5+ messages in thread
From: Joseph Telaak via B4 Relay @ 2026-11-23  1:37 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Philipp Zabel
  Cc: Chuanhong Guo, Qingfang Deng, Michael Walle, linux-mips,
	linux-gpio, devicetree, linux-kernel, Krzysztof Kozlowski,
	Joseph Telaak

From: Chuanhong Guo <gch981213@gmail.com>

Document the GPIO controller of the Siflower SF19A2890. Siflower's SF21
RISC-V SoCs have the same controller, and will get compatibles of their
own with their device trees.

[Joseph Telaak:
  - take it from Chuanhong's siflower-7.1 branch
  - list myself as the binding's maintainer
  - use GPL-2.0-only instead of the deprecated GPL-2.0 SPDX
    identifier
  - indent the example by four spaces
  - drop the ngpios property, which the compatible implies, take
    exactly four interrupts, and order the properties as in required
  - commit message and subject]

Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Signed-off-by: Joseph Telaak <joseph@telaak.dev>
---
 .../bindings/gpio/siflower,sf19a2890-gpio.yaml     | 76 ++++++++++++++++++++++
 MAINTAINERS                                        |  6 ++
 2 files changed, 82 insertions(+)

diff --git a/Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml b/Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml
new file mode 100644
index 000000000000..830a049ae4f5
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml
@@ -0,0 +1,76 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/gpio/siflower,sf19a2890-gpio.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Siflower SF19A2890 GPIO controller
+
+maintainers:
+  - Joseph Telaak <joseph@telaak.dev>
+
+properties:
+  compatible:
+    const: siflower,sf19a2890-gpio
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    description: One interrupt per group of 16 GPIOs.
+    maxItems: 4
+
+  clocks:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+  gpio-controller: true
+
+  "#gpio-cells":
+    const: 2
+
+  gpio-ranges: true
+
+  interrupt-controller: true
+
+  "#interrupt-cells":
+    const: 2
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+  - resets
+  - gpio-controller
+  - "#gpio-cells"
+  - gpio-ranges
+  - interrupt-controller
+  - "#interrupt-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+    #include <dt-bindings/interrupt-controller/mips-gic.h>
+
+    gpio@19d00000 {
+        compatible = "siflower,sf19a2890-gpio";
+        reg = <0x19d00000 0x100000>;
+        interrupts = <GIC_SHARED 246 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SHARED 247 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SHARED 248 IRQ_TYPE_LEVEL_HIGH>,
+                     <GIC_SHARED 249 IRQ_TYPE_LEVEL_HIGH>;
+        clocks = <&gpioclk 0>;
+        resets = <&gpiorst 0>;
+
+        gpio-controller;
+        #gpio-cells = <2>;
+        gpio-ranges = <&pinctrl 0 0 49>;
+
+        interrupt-controller;
+        #interrupt-cells = <2>;
+    };
diff --git a/MAINTAINERS b/MAINTAINERS
index b5a6dc379c09..4193b433c915 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -25706,6 +25706,12 @@ N:	sifive
 K:	fu[57]40
 K:	[^@]sifive
 
+SIFLOWER GPIO DRIVER
+M:	Joseph Telaak <joseph@telaak.dev>
+L:	linux-gpio@vger.kernel.org
+S:	Maintained
+F:	Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml
+
 SILEAD TOUCHSCREEN DRIVER
 M:	Hans de Goede <hansg@kernel.org>
 L:	linux-input@vger.kernel.org

-- 
Git-155)



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

* [PATCH v3 2/2] gpio: Add Siflower GPIO controller driver
  2026-11-23  1:37 [PATCH v3 0/2] gpio: Add the Siflower SF19A2890 GPIO controller Joseph Telaak via B4 Relay
  2026-11-23  1:37 ` [PATCH v3 1/2] dt-bindings: gpio: Add " Joseph Telaak via B4 Relay
@ 2026-11-23  1:37 ` Joseph Telaak via B4 Relay
  2026-11-23  1:49   ` sashiko-bot
  1 sibling, 1 reply; 5+ messages in thread
From: Joseph Telaak via B4 Relay @ 2026-11-23  1:37 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Philipp Zabel
  Cc: Chuanhong Guo, Qingfang Deng, Michael Walle, linux-mips,
	linux-gpio, devicetree, linux-kernel, Qingfang Deng,
	Joseph Telaak

From: Qingfang Deng <qingfang.deng@siflower.com.cn>

Add a driver for the GPIO controller on Siflower SoCs.
This controller is found on all current Siflower MIPS and RISC-V
chips including SF19A2890, SF21A6826 and SF21H8898.

Signed-off-by: Qingfang Deng <qingfang.deng@siflower.com.cn>
Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
[Joseph Telaak:
  - take it from Chuanhong's siflower-7.1 branch
  - depend on MACH_SIFLOWER_MIPS instead of OF_GPIO, longer Kconfig help
  - get the reset with devm_reset_control_get_exclusive_deasserted(),
    so it is asserted again only after the GPIO chip is removed, not in
    a .remove that ran first
  - use gpio-regmap on regmap-mmio, with the 0x40 stride in
    reg_mask_xlate() and the debounce in set_config(), and put the
    interrupts on an IRQ domain of the driver's own, as gpio-regmap
    sets up no gpio_irq_chip and each group of 16 lines has its own
    parent interrupt
  - drop the irq_set_affinity callback, which reached the parent
    through irq_to_desc(), not exported with SPARSE_IRQ
  - call gpio_regmap_disable_irq() and gpio_regmap_enable_irq() from
    mask and unmask, as an immutable irqchip must
  - find the group by its parent IRQ instead of assuming consecutive
    numbers
  - take the number of lines from the match data, not from an
    ngpios property
  - include linux/math64.h, drop the unused linux/pinctrl/consumer.h,
    sort the includes, spell it "Siflower"
  - subject]
Co-developed-by: Joseph Telaak <joseph@telaak.dev>
Signed-off-by: Joseph Telaak <joseph@telaak.dev>
---
 MAINTAINERS                  |   1 +
 drivers/gpio/Kconfig         |  14 ++
 drivers/gpio/Makefile        |   1 +
 drivers/gpio/gpio-siflower.c | 344 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 360 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index 4193b433c915..0a3f91844072 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -25711,6 +25711,7 @@ M:	Joseph Telaak <joseph@telaak.dev>
 L:	linux-gpio@vger.kernel.org
 S:	Maintained
 F:	Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml
+F:	drivers/gpio/gpio-siflower.c
 
 SILEAD TOUCHSCREEN DRIVER
 M:	Hans de Goede <hansg@kernel.org>
diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
index 55e4280029d8..0b52fc2a5335 100644
--- a/drivers/gpio/Kconfig
+++ b/drivers/gpio/Kconfig
@@ -721,6 +721,20 @@ config GPIO_SIFIVE
 	help
 	  Say yes here to support the GPIO device on SiFive SoCs.
 
+config GPIO_SIFLOWER
+	tristate "Siflower GPIO support"
+	depends on MACH_SIFLOWER_MIPS || COMPILE_TEST
+	select GPIOLIB_IRQCHIP
+	select GPIO_REGMAP
+	select REGMAP_MMIO
+	help
+	  GPIO controller driver for the Siflower SF19A2890. Each line can be
+	  an input or an output and raise an interrupt on either edge or
+	  level, and inputs can be debounced in hardware.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called gpio-siflower.
+
 config GPIO_SIOX
 	tristate "SIOX GPIO support"
 	depends on SIOX
diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile
index 88f748846e60..bde6181081f9 100644
--- a/drivers/gpio/Makefile
+++ b/drivers/gpio/Makefile
@@ -171,6 +171,7 @@ obj-$(CONFIG_GPIO_SCH311X)		+= gpio-sch311x.o
 obj-$(CONFIG_GPIO_SCH)			+= gpio-sch.o
 obj-$(CONFIG_GPIO_SHARED_PROXY)		+= gpio-shared-proxy.o
 obj-$(CONFIG_GPIO_SIFIVE)		+= gpio-sifive.o
+obj-$(CONFIG_GPIO_SIFLOWER)		+= gpio-siflower.o
 obj-$(CONFIG_GPIO_SIM)			+= gpio-sim.o
 obj-$(CONFIG_GPIO_SIOX)			+= gpio-siox.o
 obj-$(CONFIG_GPIO_SL28CPLD)		+= gpio-sl28cpld.o
diff --git a/drivers/gpio/gpio-siflower.c b/drivers/gpio/gpio-siflower.c
new file mode 100644
index 000000000000..4bf7e36960e4
--- /dev/null
+++ b/drivers/gpio/gpio-siflower.c
@@ -0,0 +1,344 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * GPIO controller driver for Siflower MIPS and RISC-V SoCs including:
+ *  Siflower SF19A2890
+ *  Siflower SF21A6826
+ *  Siflower SF21H8898
+ */
+
+#include <linux/bitops.h>
+#include <linux/clk.h>
+#include <linux/gpio/driver.h>
+#include <linux/gpio/regmap.h>
+#include <linux/irq.h>
+#include <linux/irqchip/chained_irq.h>
+#include <linux/irqdomain.h>
+#include <linux/math64.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+#include <linux/reset.h>
+
+/* Each line has its own registers, GPIO_STRIDE apart */
+#define GPIO_STRIDE	0x40
+#define GPIO_IR(n)	(GPIO_STRIDE * (n) + 0x00)
+#define GPIO_OR(n)	(GPIO_STRIDE * (n) + 0x04)
+#define GPIO_OEN(n)	(GPIO_STRIDE * (n) + 0x08)
+#define GPIO_IMR(n)	(GPIO_STRIDE * (n) + 0x0c)
+#define GPIO_GPIMR(n)	(GPIO_STRIDE * (n) + 0x10)
+#define GPIO_PIR(n)	(GPIO_STRIDE * (n) + 0x14)
+#define GPIO_ITR(n)	(GPIO_STRIDE * (n) + 0x18)
+#define GPIO_IFR(n)	(GPIO_STRIDE * (n) + 0x1c)
+#define GPIO_ICR(n)	(GPIO_STRIDE * (n) + 0x20)
+#define GPIO_GPxIR(n)	(0x4 * (n) + 0x4000)
+
+#define GPIOS_PER_GROUP	16
+
+static struct lock_class_key sf_gpio_irq_lock_class;
+static struct lock_class_key sf_gpio_irq_request_class;
+
+struct sf_gpio_soc_data {
+	unsigned int ngpios;
+};
+
+struct sf_gpio_priv {
+	struct gpio_regmap *gpio;
+	struct regmap *regmap;
+	struct irq_domain *domain;
+	struct clk *clk;
+	unsigned int ngroups;
+	unsigned int irq[];
+};
+
+static int sf_gpio_reg_mask_xlate(struct gpio_regmap *gpio,
+				  enum gpio_regmap_operation op,
+				  unsigned int base, unsigned int offset,
+				  unsigned int *reg, unsigned int *mask)
+{
+	*reg = base + GPIO_STRIDE * offset;
+	*mask = BIT(0);
+	return 0;
+}
+
+static int sf_gpio_set_debounce(struct sf_gpio_priv *priv, unsigned int offset,
+				u32 debounce)
+{
+	unsigned long freq = clk_get_rate(priv->clk);
+	u64 mul;
+	int ret;
+
+	/* (ICR + 1) * IFR = debounce_us * clkfreq_mhz / 4 */
+	mul = (u64)debounce * freq;
+	do_div(mul, 1000000 * 4);
+	if (mul > 0xff00)
+		return -EINVAL;
+
+	ret = regmap_write(priv->regmap, GPIO_ICR(offset), 0xff);
+	if (ret)
+		return ret;
+
+	return regmap_write(priv->regmap, GPIO_IFR(offset),
+			    DIV_ROUND_UP(mul, 0x100));
+}
+
+static int sf_gpio_set_config(struct gpio_regmap *gpio, struct gpio_chip *gc,
+			      unsigned int offset, unsigned long config)
+{
+	struct sf_gpio_priv *priv = gpio_regmap_get_drvdata(gpio);
+
+	switch (pinconf_to_config_param(config)) {
+	case PIN_CONFIG_INPUT_DEBOUNCE:
+		return sf_gpio_set_debounce(priv, offset,
+			pinconf_to_config_argument(config));
+	default:
+		return gpiochip_generic_config(gc, offset, config);
+	}
+}
+
+static void sf_gpio_irq_ack(struct irq_data *data)
+{
+	struct sf_gpio_priv *priv = irq_data_get_irq_chip_data(data);
+
+	regmap_write(priv->regmap, GPIO_PIR(irqd_to_hwirq(data)), 0);
+}
+
+static void sf_gpio_irq_mask(struct irq_data *data)
+{
+	struct sf_gpio_priv *priv = irq_data_get_irq_chip_data(data);
+	irq_hw_number_t hwirq = irqd_to_hwirq(data);
+
+	regmap_write(priv->regmap, GPIO_IMR(hwirq), 1);
+	regmap_write(priv->regmap, GPIO_GPIMR(hwirq), 1);
+	gpio_regmap_disable_irq(priv->gpio, hwirq);
+}
+
+static void sf_gpio_irq_unmask(struct irq_data *data)
+{
+	struct sf_gpio_priv *priv = irq_data_get_irq_chip_data(data);
+	irq_hw_number_t hwirq = irqd_to_hwirq(data);
+
+	gpio_regmap_enable_irq(priv->gpio, hwirq);
+	regmap_write(priv->regmap, GPIO_IMR(hwirq), 0);
+	regmap_write(priv->regmap, GPIO_GPIMR(hwirq), 0);
+}
+
+static int sf_gpio_irq_set_type(struct irq_data *data, unsigned int flow_type)
+{
+	struct sf_gpio_priv *priv = irq_data_get_irq_chip_data(data);
+	u32 val;
+	int ret;
+
+	switch (flow_type) {
+	case IRQ_TYPE_EDGE_RISING:
+		val = 4;
+		break;
+	case IRQ_TYPE_EDGE_FALLING:
+		val = 2;
+		break;
+	case IRQ_TYPE_EDGE_BOTH:
+		val = 6;
+		break;
+	case IRQ_TYPE_LEVEL_HIGH:
+		val = 1;
+		break;
+	case IRQ_TYPE_LEVEL_LOW:
+		val = 0;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	ret = regmap_write(priv->regmap, GPIO_ITR(irqd_to_hwirq(data)), val);
+	if (ret)
+		return ret;
+
+	if (flow_type & IRQ_TYPE_LEVEL_MASK)
+		irq_set_handler_locked(data, handle_level_irq);
+	else
+		irq_set_handler_locked(data, handle_edge_irq);
+
+	return 0;
+}
+
+static int sf_gpio_irq_request_resources(struct irq_data *data)
+{
+	struct sf_gpio_priv *priv = irq_data_get_irq_chip_data(data);
+
+	return gpio_regmap_reqres_irq(priv->gpio, irqd_to_hwirq(data));
+}
+
+static void sf_gpio_irq_release_resources(struct irq_data *data)
+{
+	struct sf_gpio_priv *priv = irq_data_get_irq_chip_data(data);
+
+	gpio_regmap_relres_irq(priv->gpio, irqd_to_hwirq(data));
+}
+
+static const struct irq_chip sf_gpio_irqchip = {
+	.name			= KBUILD_MODNAME,
+	.irq_ack		= sf_gpio_irq_ack,
+	.irq_mask		= sf_gpio_irq_mask,
+	.irq_unmask		= sf_gpio_irq_unmask,
+	.irq_set_type		= sf_gpio_irq_set_type,
+	.irq_request_resources	= sf_gpio_irq_request_resources,
+	.irq_release_resources	= sf_gpio_irq_release_resources,
+	.flags			= IRQCHIP_IMMUTABLE,
+};
+
+static void sf_gpio_irq_handler(struct irq_desc *desc)
+{
+	struct sf_gpio_priv *priv = irq_desc_get_handler_data(desc);
+	struct irq_chip *ic = irq_desc_get_chip(desc);
+	unsigned int irq = irq_desc_get_irq(desc);
+	unsigned int group, n, val;
+	unsigned long pending;
+
+	for (group = 0; group < priv->ngroups; group++)
+		if (priv->irq[group] == irq)
+			break;
+	if (WARN_ON_ONCE(group == priv->ngroups))
+		return;
+
+	chained_irq_enter(ic, desc);
+
+	if (!regmap_read(priv->regmap, GPIO_GPxIR(group), &val)) {
+		pending = val;
+		for_each_set_bit(n, &pending, GPIOS_PER_GROUP)
+			generic_handle_domain_irq(priv->domain,
+						  n + group * GPIOS_PER_GROUP);
+	}
+
+	chained_irq_exit(ic, desc);
+}
+
+static int sf_gpio_irq_map(struct irq_domain *domain, unsigned int irq,
+			   irq_hw_number_t hwirq)
+{
+	irq_set_chip_data(irq, domain->host_data);
+	irq_set_chip_and_handler(irq, &sf_gpio_irqchip, handle_bad_irq);
+	irq_set_noprobe(irq);
+	irq_set_lockdep_class(irq, &sf_gpio_irq_lock_class,
+			      &sf_gpio_irq_request_class);
+
+	return 0;
+}
+
+static const struct irq_domain_ops sf_gpio_irq_domain_ops = {
+	.map	= sf_gpio_irq_map,
+	.xlate	= irq_domain_xlate_twocell,
+};
+
+static void sf_gpio_remove_chained_handler(void *data)
+{
+	irq_set_chained_handler_and_data((unsigned long)data, NULL, NULL);
+}
+
+static const struct regmap_config sf_gpio_regmap_config = {
+	.reg_bits	= 32,
+	.reg_stride	= 4,
+	.val_bits	= 32,
+};
+
+static int sf_gpio_probe(struct platform_device *pdev)
+{
+	struct gpio_regmap_config config = { };
+	struct irq_domain_info d_info = { };
+	struct device *dev = &pdev->dev;
+	const struct sf_gpio_soc_data *soc;
+	struct reset_control *rstc;
+	struct sf_gpio_priv *priv;
+	unsigned int ngroups, i;
+	void __iomem *base;
+	int ret;
+
+	soc = device_get_match_data(dev);
+	if (!soc)
+		return -ENODEV;
+
+	ngroups = DIV_ROUND_UP(soc->ngpios, GPIOS_PER_GROUP);
+	priv = devm_kzalloc(dev, struct_size(priv, irq, ngroups), GFP_KERNEL);
+	if (!priv)
+		return -ENOMEM;
+
+	priv->ngroups = ngroups;
+
+	base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(base))
+		return PTR_ERR(base);
+
+	priv->regmap = devm_regmap_init_mmio(dev, base, &sf_gpio_regmap_config);
+	if (IS_ERR(priv->regmap))
+		return PTR_ERR(priv->regmap);
+
+	priv->clk = devm_clk_get_enabled(dev, NULL);
+	if (IS_ERR(priv->clk))
+		return PTR_ERR(priv->clk);
+
+	rstc = devm_reset_control_get_exclusive_deasserted(dev, NULL);
+	if (IS_ERR(rstc))
+		return PTR_ERR(rstc);
+
+	d_info.fwnode = dev_fwnode(dev);
+	d_info.size = soc->ngpios;
+	d_info.hwirq_max = soc->ngpios;
+	d_info.ops = &sf_gpio_irq_domain_ops;
+	d_info.host_data = priv;
+
+	priv->domain = devm_irq_domain_instantiate(dev, &d_info);
+	if (IS_ERR(priv->domain))
+		return PTR_ERR(priv->domain);
+
+	for (i = 0; i < ngroups; i++) {
+		ret = platform_get_irq(pdev, i);
+		if (ret < 0)
+			return ret;
+
+		priv->irq[i] = ret;
+		irq_set_chained_handler_and_data(priv->irq[i],
+						 sf_gpio_irq_handler, priv);
+		ret = devm_add_action_or_reset(dev,
+					       sf_gpio_remove_chained_handler,
+					       (void *)(unsigned long)priv->irq[i]);
+		if (ret)
+			return ret;
+	}
+
+	config.parent = dev;
+	config.regmap = priv->regmap;
+	config.ngpio = soc->ngpios;
+	config.reg_dat_base = GPIO_REGMAP_ADDR(GPIO_IR(0));
+	config.reg_set_base = GPIO_OR(0);
+	config.reg_dir_in_base = GPIO_OEN(0);
+	config.reg_mask_xlate = sf_gpio_reg_mask_xlate;
+	config.set_config = sf_gpio_set_config;
+	config.irq_domain = priv->domain;
+	config.drvdata = priv;
+
+	priv->gpio = devm_gpio_regmap_register(dev, &config);
+
+	return PTR_ERR_OR_ZERO(priv->gpio);
+}
+
+static const struct sf_gpio_soc_data sf19a2890_gpio_data = {
+	.ngpios = 49,
+};
+
+static const struct of_device_id sf_gpio_ids[] = {
+	{ .compatible = "siflower,sf19a2890-gpio", .data = &sf19a2890_gpio_data },
+	{ }
+};
+MODULE_DEVICE_TABLE(of, sf_gpio_ids);
+
+static struct platform_driver sf_gpio_driver = {
+	.probe		= sf_gpio_probe,
+	.driver = {
+		.name		= "siflower_gpio",
+		.of_match_table	= sf_gpio_ids,
+	},
+};
+module_platform_driver(sf_gpio_driver);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Qingfang Deng <qingfang.deng@siflower.com.cn>");
+MODULE_DESCRIPTION("GPIO driver for Siflower SoCs");

-- 
Git-155)



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

* Re: [PATCH v3 1/2] dt-bindings: gpio: Add Siflower SF19A2890 GPIO controller
  2026-11-23  1:37 ` [PATCH v3 1/2] dt-bindings: gpio: Add " Joseph Telaak via B4 Relay
@ 2026-11-23  1:45   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-23  1:45 UTC (permalink / raw)
  To: Joseph Telaak; +Cc: linux-gpio, devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] dt-bindings: gpio: siflower: interrupts listed before clocks in
  schema
--

commit c75e336698c08299c54fb54d2e37ab281072dfba
Author: Chuanhong Guo <gch981213@gmail.com>

dt-bindings: gpio: Add Siflower SF19A2890 GPIO controller

This commit adds the Device Tree binding schema for the Siflower SF19A2890
GPIO controller and adds a MAINTAINERS entry for it.

> diff --git a/Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml b/Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml
> new file mode 100644
> index 0000000000000..830a049ae4f56
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml
> @@ -0,0 +1,76 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/gpio/siflower,sf19a2890-gpio.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Siflower SF19A2890 GPIO controller
> +
> +maintainers:
> +  - Joseph Telaak <joseph@telaak.dev>
> +
> +properties:
> +  compatible:
> +    const: siflower,sf19a2890-gpio
> +
> +  reg:
> +    maxItems: 1
> +
> +  interrupts:
> +    description: One interrupt per group of 16 GPIOs.
> +    maxItems: 4
> +
> +  clocks:
> +    maxItems: 1
> +
> +  resets:
> +    maxItems: 1
> +
> +  gpio-controller: true
> +
> +  "#gpio-cells":
> +    const: 2
> +
> +  gpio-ranges: true
> +
> +  interrupt-controller: true
> +
> +  "#interrupt-cells":
> +    const: 2
> +
> +required:
> +  - compatible
> +  - reg
> +  - interrupts
> +  - clocks
> +  - resets
> +  - gpio-controller
> +  - "#gpio-cells"
> +  - gpio-ranges
> +  - interrupt-controller
> +  - "#interrupt-cells"
> +
> +additionalProperties: false
> +
> +examples:
> +  - |
> +    #include <dt-bindings/interrupt-controller/irq.h>
> +    #include <dt-bindings/interrupt-controller/mips-gic.h>
> +
> +    gpio@19d00000 {
> +        compatible = "siflower,sf19a2890-gpio";
> +        reg = <0x19d00000 0x100000>;
> +        interrupts = <GIC_SHARED 246 IRQ_TYPE_LEVEL_HIGH>,
> +                     <GIC_SHARED 247 IRQ_TYPE_LEVEL_HIGH>,
> +                     <GIC_SHARED 248 IRQ_TYPE_LEVEL_HIGH>,
> +                     <GIC_SHARED 249 IRQ_TYPE_LEVEL_HIGH>;
> +        clocks = <&gpioclk 0>;

[Severity: Low]
In DT binding schemas and example nodes, clocks should be listed before
interrupts (compatible, reg, clocks, interrupts).  Should clocks be moved
before interrupts in properties, required, and the gpio@19d00000 example
node?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261122-sf19a2890-gpio-v3-0-3a4857ebc84a@telaak.dev?part=1

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

* Re: [PATCH v3 2/2] gpio: Add Siflower GPIO controller driver
  2026-11-23  1:37 ` [PATCH v3 2/2] gpio: Add Siflower GPIO controller driver Joseph Telaak via B4 Relay
@ 2026-11-23  1:49   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-23  1:49 UTC (permalink / raw)
  To: Joseph Telaak; +Cc: linux-gpio, devicetree, robh, conor+dt

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] gpio: siflower: non-raw regmap spinlock acquired in raw IRQ and
  hardirq contexts
- [High] gpio: siflower: IRQ domain and chained handlers registered
  before priv->gpio
- [Medium] gpio: siflower: undisposed virtual IRQ mappings in
  priv->domain on teardown
- [Medium] gpio: siflower: Kconfig dependency on undefined symbol
  MACH_SIFLOWER_MIPS
--

commit 86affe3feaf16149d7ee585860ef5d5bfff26ad5
Author: Qingfang Deng <qingfang.deng@siflower.com.cn>

gpio: Add Siflower GPIO controller driver

This commit adds a GPIO and interrupt controller driver for Siflower MIPS
and RISC-V SoCs using gpio-regmap and regmap-mmio.

> diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig
> index 55e4280029d86..0b52fc2a5335e 100644
> --- a/drivers/gpio/Kconfig
> +++ b/drivers/gpio/Kconfig
> @@ -721,6 +721,20 @@ config GPIO_SIFIVE
>  	help
>  	  Say yes here to support the GPIO device on SiFive SoCs.
>  
> +config GPIO_SIFLOWER
> +	tristate "Siflower GPIO support"
> +	depends on MACH_SIFLOWER_MIPS || COMPILE_TEST

[Severity: Medium]
Is MACH_SIFLOWER_MIPS defined anywhere in the tree?  Because that Kconfig
symbol does not exist (and there is no RISC-V dependency for the RISC-V
SoCs mentioned in the changelog), GPIO_SIFLOWER can only be enabled when
COMPILE_TEST is set.

> diff --git a/drivers/gpio/gpio-siflower.c b/drivers/gpio/gpio-siflower.c
> new file mode 100644
> index 0000000000000..4bf7e36960e4c
> --- /dev/null
> +++ b/drivers/gpio/gpio-siflower.c
[ ... ]
> +static const struct regmap_config sf_gpio_regmap_config = {
> +	.reg_bits	= 32,
> +	.reg_stride	= 4,
> +	.val_bits	= 32,
> +};

[Severity: High]
Should sf_gpio_regmap_config set .use_raw_spinlock = true?

Without it, devm_regmap_init_mmio() protects priv->regmap with a non-raw
spinlock_t.  sf_gpio_irq_ack(), sf_gpio_irq_mask(), sf_gpio_irq_unmask()
and sf_gpio_irq_set_type() access priv->regmap while holding the irq_desc
raw_spinlock_t, and sf_gpio_irq_handler() reads priv->regmap in hardirq
context, triggering a lockdep invalid wait context splat or sleeping in
atomic context on PREEMPT_RT.

> +static int sf_gpio_probe(struct platform_device *pdev)
> +{
[ ... ]
> +	d_info.fwnode = dev_fwnode(dev);
> +	d_info.size = soc->ngpios;
> +	d_info.hwirq_max = soc->ngpios;
> +	d_info.ops = &sf_gpio_irq_domain_ops;
> +	d_info.host_data = priv;
> +
> +	priv->domain = devm_irq_domain_instantiate(dev, &d_info);
> +	if (IS_ERR(priv->domain))
> +		return PTR_ERR(priv->domain);

[Severity: Medium]
Does teardown dispose of virtual IRQ mappings in priv->domain before the
domain is removed?

Because priv->domain is allocated externally and passed via
config.irq_domain, gpiochip_irqchip_remove() skips irq_dispose_mapping().
When devm_irq_domain_remove() then calls irq_domain_remove(), any mapped
irq_desc entries are leaked with dangling pointers to the freed domain and
priv.

> +	for (i = 0; i < ngroups; i++) {
> +		ret = platform_get_irq(pdev, i);
> +		if (ret < 0)
> +			return ret;
> +
> +		priv->irq[i] = ret;
> +		irq_set_chained_handler_and_data(priv->irq[i],
> +						 sf_gpio_irq_handler, priv);
> +		ret = devm_add_action_or_reset(dev,
> +					       sf_gpio_remove_chained_handler,
> +					       (void *)(unsigned long)priv->irq[i]);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	config.parent = dev;
> +	config.regmap = priv->regmap;
> +	config.ngpio = soc->ngpios;
> +	config.reg_dat_base = GPIO_REGMAP_ADDR(GPIO_IR(0));
> +	config.reg_set_base = GPIO_OR(0);
> +	config.reg_dir_in_base = GPIO_OEN(0);
> +	config.reg_mask_xlate = sf_gpio_reg_mask_xlate;
> +	config.set_config = sf_gpio_set_config;
> +	config.irq_domain = priv->domain;
> +	config.drvdata = priv;
> +
> +	priv->gpio = devm_gpio_regmap_register(dev, &config);

[Severity: High]
Can irq_chip callbacks dereference priv->gpio before it is initialized or
after it has been freed?

sf_gpio_irq_mask(), sf_gpio_irq_unmask(), sf_gpio_irq_request_resources()
and sf_gpio_irq_release_resources() all pass priv->gpio to
gpio_regmap_*_irq(), which dereferences &gpio->gpio_chip.  Because
priv->domain and the parent chained handlers are registered before
devm_gpio_regmap_register(), priv->gpio is NULL until
devm_gpio_regmap_register() returns.  Furthermore, devres unwinds in
reverse order on unbind, so devm_gpio_regmap_unregister() frees priv->gpio
before sf_gpio_remove_chained_handler() and devm_irq_domain_remove() run,
leaving a use-after-free window if an IRQ is masked, unmasked or released
during teardown.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261122-sf19a2890-gpio-v3-0-3a4857ebc84a@telaak.dev?part=2

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

end of thread, other threads:[~2026-11-23  1:49 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23  1:37 [PATCH v3 0/2] gpio: Add the Siflower SF19A2890 GPIO controller Joseph Telaak via B4 Relay
2026-11-23  1:37 ` [PATCH v3 1/2] dt-bindings: gpio: Add " Joseph Telaak via B4 Relay
2026-11-23  1:45   ` sashiko-bot
2026-11-23  1:37 ` [PATCH v3 2/2] gpio: Add Siflower GPIO controller driver Joseph Telaak via B4 Relay
2026-11-23  1:49   ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox