Skip to contentSkip to conversation

gpio: add support for GPIO controller on Siflower SoCs

PATCH In review Chuanhong Guo 3 participants 11 messages Dec 25, 2024 – Jan 13, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover gpio: add support for GPIO controller on Siflower SoCs

This patchset adds support for the GPIO controller found on various Siflower MIPS and RISC-V SoCs including SF19A2890, SF21A6826 and SF21H8898.

Chuanhong Guo (1):
dt-bindings: gpio: add binding doc for siflower,sf19a2890-gpio

Qingfang Deng (1):
gpio: add support for GPIO controller on Siflower SoCs

 .../gpio/siflower,sf19a2890-gpio.yaml         |  83 +++++
 drivers/gpio/Kconfig                          |   8 +
 drivers/gpio/Makefile                         |   1 +
 drivers/gpio/gpio-siflower.c                  | 347 ++++++++++++++++++
 4 files changed, 439 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml
 create mode 100644 drivers/gpio/gpio-siflower.c
Signature · 1 line
2.47.1
#1 lore raw

PATCH 1/2 dt-bindings: gpio: add binding doc for siflower,sf19a2890-gpio

Add dt binding doc for the GPIO controller found on Siflower SF19A2890 and various other Siflower MIPS and RISC-V SoCs.

---
 .../gpio/siflower,sf19a2890-gpio.yaml         | 83 +++++++++++++++++++
 1 file changed, 83 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml
Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml new file +83 -0
new file mode 100644
index 000000000000..7dab1e3f159c
@@ -0,0 +1,83 @@
+# SPDX-License-Identifier: (GPL-2.0 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:
+  - Chuanhong Guo <[email protected]>
+
+properties:
+  compatible:
+    const: siflower,sf19a2890-gpio
+
+  gpio-controller: true
+  "#gpio-cells":
+    const: 2
+
+  gpio-ranges: true
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    description:
+      Interrupt mapping, one interrupt per 16 GPIOs.
+    minItems: 1
+    maxItems: 10
+
+  clocks:
+    maxItems: 1
+
+  resets:
+    maxItems: 1
+
+  interrupt-controller: true
+
+  "#interrupt-cells":
+    const: 2
+
+  ngpios:
+    description:
+      The number of GPIOs available on the controller implementation.
+    minimum: 1
+
+required:
+  - compatible
+  - clocks
+  - gpio-controller
+  - gpio-ranges
+  - interrupt-controller
+  - interrupts
+  - ngpios
+  - reg
+  - resets
+  - "#gpio-cells"
+  - "#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>;
+      ngpios = <49>;
+      gpio-ranges = <&pinctrl 0 0 49>;
+
+      interrupt-controller;
+      #interrupt-cells = <2>;
+    };
Signature · 1 line
2.47.1
#2 lore raw

Re: [PATCH 1/2] dt-bindings: gpio: add binding doc for siflower,sf19a2890-gpio

Hi Chuanhong,

thanks for your patch!

Quoted 4 lines · Chuanhong Guo

Add dt binding doc for the GPIO controller found on Siflower SF19A2890 and various other Siflower MIPS and RISC-V SoCs.

(...)

Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml line 27

Quoted 3 lines
Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml new file +3 -0
+  interrupts:
+    description:
+      Interrupt mapping, one interrupt per 16 GPIOs.

So from the driver it is very clear that this is lumping together several GPIO blocks with 16 GPIOs in each into a bigger GPIO controller, despite the instances are identical. They even each have an individual IRQ.

Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml line 45

Quoted 4 lines
Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml new file +4 -0
+  ngpios:
+    description:
+      The number of GPIOs available on the controller implementation.
+    minimum: 1

I would say minimum: 1 maximum: 16 default: 16.

One instance per block/bank.

Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml line 68

Quoted 7 lines
Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml new file +7 -0
+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>;

Just use 4 instances. Since (looking at the driver) it seems there is an IRQ register that is "off the bulk" I would do something like:

instance 0:

reg = <0x19d00000 0x40>, <0x19d04000 4>;

instance: 1:

reg = <0x19d00040 0x40>, <0x19d04004 4>;

(...etc...)

You can add reg-names if you don't want the implicit order of registers. (Perhaps the bindings maintainers will push for this as well.)

Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml line 72

Quoted 4 lines
Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml new file +4 -0
+      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>;

Just one IRQ and handle just one block per instance.

Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml line 78

Quoted 6 lines
Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml new file +6 -0
+      clocks = <&gpioclk 0>;
+      resets = <&gpiorst 0>;
+
+      gpio-controller;
+      #gpio-cells = <2>;
+      ngpios = <49>;

Just omit this on instances 0,1,2 and set to 1 on
instance 3.

Quoted 1 line

+ gpio-ranges = <&pinctrl 0 0 49>;

Augment this accordingly to one instance per bank/range.

Yours,
Linus Walleij

#3 lore raw

Re: [PATCH 1/2] dt-bindings: gpio: add binding doc for siflower,sf19a2890-gpio

Hello!

Quoted 42 lines · Linus Walleij

Hi Chuanhong,

thanks for your patch!

Quoted 4 lines · Chuanhong Guo

Add dt binding doc for the GPIO controller found on Siflower SF19A2890 and various other Siflower MIPS and RISC-V SoCs.

(...)

Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml line 27

Quoted 3 lines
Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml new file +3 -0
+  interrupts:
+    description:
+      Interrupt mapping, one interrupt per 16 GPIOs.

So from the driver it is very clear that this is lumping together several GPIO blocks with 16 GPIOs in each into a bigger GPIO controller, despite the instances are identical. They even each have an individual IRQ.

Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml line 45

Quoted 4 lines
Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml new file +4 -0
+  ngpios:
+    description:
+      The number of GPIOs available on the controller implementation.
+    minimum: 1

I would say minimum: 1 maximum: 16 default: 16.

One instance per block/bank.

Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml line 68

Quoted 7 lines
Documentation/devicetree/bindings/gpio/siflower,sf19a2890-gpio.yaml new file +7 -0
+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>;

Just use 4 instances. Since (looking at the driver) it seems there is an IRQ register that is "off the bulk" I would do something like:

instance 0:

Quoted 7 lines

reg = <0x19d00000 0x40>, <0x19d04000 4>;

instance: 1:

reg = <0x19d00040 0x40>, <0x19d04004 4>;

(...etc...)

Actually, this weird GPIO controller uses one 0x40 block per pin (The 49 pin controller uses 0x40 * 49 or about 3K memory space just for IO registers!), and they share a single reset signal from the reset controller.
I don't know how one reset could be shared across multiple platform devices so I don't think this kind of split is possible.

--
Regards,
Chuanhong Guo

#4 lore raw

Re: [PATCH 1/2] dt-bindings: gpio: add binding doc for siflower,sf19a2890-gpio

Quoted 2 lines · Chuanhong Guo

I don't know how one reset could be shared across multiple platform devices so I don't think this kind of split is possible.

In general I don't think shared reset lines in silicon is any problem whatsoever, they are reference counted, just like clocks or regulators, and there is a flag RESET_CONTROL_FLAGS_BIT_SHARED
especially for this purpose.

You might have to fix the reset driver, or fix up the way they are defined in the device tree, I don't know how, but certainly it is possible. If in doubt consult the reset controller maintainer. (Philipp.)

Yours,
Linus Walleij

#5 lore raw

PATCH 2/2 gpio: add support for GPIO controller on Siflower SoCs

In reply to Chuanhong Guo

From: Qingfang Deng <[email protected]>

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.

---
 drivers/gpio/Kconfig         |   9 +
 drivers/gpio/Makefile        |   1 +
 drivers/gpio/gpio-siflower.c | 353 +++++++++++++++++++++++++++++++++++
 3 files changed, 363 insertions(+)
 create mode 100644 drivers/gpio/gpio-siflower.c
drivers/gpio/Kconfig +9 -0
index add5ad29a673..fdc9a89ffbf3 100644
@@ -637,6 +637,15 @@ config GPIO_SIFIVE
 	help
 	  Say yes here to support the GPIO device on SiFive SoCs.
 
+config GPIO_SIFLOWER
+	tristate "SiFlower GPIO support"
+	depends on OF_GPIO
+	depends on MIPS || RISCV || COMPILE_TEST
+	select GPIOLIB_IRQCHIP
+	help
+	  GPIO controller driver for SiFlower MIPS and RISC-V SoCs
+	  including SF19A2890, SF21A6826 and SF21H8898.
+
 config GPIO_SIOX
 	tristate "SIOX GPIO support"
 	depends on SIOX
drivers/gpio/Makefile +1 -0
index af3ba4d81b58..ec400ed6dcd1 100644
@@ -151,6 +151,7 @@ obj-$(CONFIG_GPIO_SAMA5D2_PIOBU)	+= gpio-sama5d2-piobu.o
 obj-$(CONFIG_GPIO_SCH311X)		+= gpio-sch311x.o
 obj-$(CONFIG_GPIO_SCH)			+= gpio-sch.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
drivers/gpio/gpio-siflower.c new file +353 -0

353 lines not on this page · raw message

Signature · 1 line
2.47.1
#6 lore raw

Hi Chuanhong,

thanks for your patch!

I think it is better to split the driver instances into 4, one for each physical block, as explained in the binding patch.

Quoted 11 lines · Chuanhong Guo

From: Qingfang Deng <[email protected]>

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.

drivers/gpio/Kconfig config GPIO_SIFIVE · line 644

Quoted 5 lines
drivers/gpio/Kconfig +5 -0
+config GPIO_SIFLOWER
+       tristate "SiFlower GPIO support"
+       depends on OF_GPIO
+       depends on MIPS || RISCV || COMPILE_TEST
+       select GPIOLIB_IRQCHIP

select GPIO_GENERIC

As you have only a set of 32-bit registers to handle for each instance, then some IRQs on top, you can untilize the MMIO library.

drivers/gpio/gpio-siflower.c line 26

Quoted 10 lines
drivers/gpio/gpio-siflower.c new file +10 -0
+#define GPIO_IR(n)     (0x40 * (n) + 0x00)
+#define GPIO_OR(n)     (0x40 * (n) + 0x04)
+#define GPIO_OEN(n)    (0x40 * (n) + 0x08)
+#define GPIO_IMR(n)    (0x40 * (n) + 0x0c)
+#define GPIO_GPIMR(n)  (0x40 * (n) + 0x10)
+#define GPIO_PIR(n)    (0x40 * (n) + 0x14)
+#define GPIO_ITR(n)    (0x40 * (n) + 0x18)
+#define GPIO_IFR(n)    (0x40 * (n) + 0x1c)
+#define GPIO_ICR(n)    (0x40 * (n) + 0x20)
+#define GPIO_GPxIR(n)  (0x4 * (n) + 0x4000)

Just define GPIO_IR 0, GPIO_OR 4, etc.

Look up the GPIO_GPIR register separately from the device tree and use it without offset.

Always register 16 GPIO lines unless ngpios is set.

Look at example drivers such as drivers/gpio/gpio-pl061.c drivers/gpio/gpio-ftgpio010.c
on how to use the MMIO helper library to implement a simple driver for one instance reusing the common code.

You will also get implementations for get/set_multiple() for free with this approach, as the library implements them!

Yours,
Linus Walleij

#7 lore raw

Hi Linus!

Quoted 33 lines · Linus Walleij

Hi Chuanhong,

thanks for your patch!

I think it is better to split the driver instances into 4, one for each physical block, as explained in the binding patch.

Quoted 11 lines · Chuanhong Guo

From: Qingfang Deng <[email protected]>

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.

drivers/gpio/Kconfig config GPIO_SIFIVE · line 644

Quoted 5 lines
drivers/gpio/Kconfig +5 -0
+config GPIO_SIFLOWER
+       tristate "SiFlower GPIO support"
+       depends on OF_GPIO
+       depends on MIPS || RISCV || COMPILE_TEST
+       select GPIOLIB_IRQCHIP

select GPIO_GENERIC

As you have only a set of 32-bit registers to handle for each instance, then some IRQs on top, you can untilize the MMIO library.

Quoted 9 lines

drivers/gpio/gpio-siflower.c line 25

Quoted 9 lines
drivers/gpio/gpio-siflower.c new file +9 -0
+#define GPIO_IR(n)     (0x40 * (n) + 0x00)
+#define GPIO_OR(n)     (0x40 * (n) + 0x04)
+#define GPIO_OEN(n)    (0x40 * (n) + 0x08)
+#define GPIO_IMR(n)    (0x40 * (n) + 0x0c)
+#define GPIO_GPIMR(n)  (0x40 * (n) + 0x10)
+#define GPIO_PIR(n)    (0x40 * (n) + 0x14)
+#define GPIO_ITR(n)    (0x40 * (n) + 0x18)
+#define GPIO_IFR(n)    (0x40 * (n) + 0x1c)
+#define GPIO_ICR(n)    (0x40 * (n) + 0x20)

This set of registers is for a single pin, not a multiple-pin block.

Quoted 7 lines
Quoted 1 line

+#define GPIO_GPxIR(n) (0x4 * (n) + 0x4000)

Just define GPIO_IR 0, GPIO_OR 4, etc.

Look up the GPIO_GPIR register separately from the device tree and use it without offset.

Quoted 7 lines

Always register 16 GPIO lines unless ngpios is set.

Look at example drivers such as drivers/gpio/gpio-pl061.c drivers/gpio/gpio-ftgpio010.c
on how to use the MMIO helper library to implement a simple driver for one instance reusing the common code.

In my case the MMIO library doesn't seem really helpful since that's for the more common case where multiple GPIO pins share one set of registers.

Signature · 2 lines
Regards,
Chuanhong Guo
#8 lore raw
In reply to Chuanhong Guo
Quoted 20 lines · Chuanhong Guo

From: Qingfang Deng <[email protected]>

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.

---
 drivers/gpio/Kconfig         |   9 +
 drivers/gpio/Makefile        |   1 +
 drivers/gpio/gpio-siflower.c | 353 +++++++++++++++++++++++++++++++++++
 3 files changed, 363 insertions(+)
 create mode 100644 drivers/gpio/gpio-siflower.c
drivers/gpio/Kconfig +0 -0
index add5ad29a673..fdc9a89ffbf3 100644

drivers/gpio/Kconfig config GPIO_SIFIVE · line 643

Quoted 7 lines
drivers/gpio/Kconfig +4 -0
@@ -637,6 +637,15 @@ config GPIO_SIFIVE
 	help
 	  Say yes here to support the GPIO device on SiFive SoCs.
 
+config GPIO_SIFLOWER
+	tristate "SiFlower GPIO support"
+	depends on OF_GPIO
+	depends on MIPS || RISCV || COMPILE_TEST

This is supposed to be dependency on ARCH, not instruction set. I don't se anything MIPS or RISCV here.

Quoted 4 lines
drivers/gpio/Kconfig +4 -0
+	select GPIOLIB_IRQCHIP
+	help
+	  GPIO controller driver for SiFlower MIPS and RISC-V SoCs
+	  including SF19A2890, SF21A6826 and SF21H8898.

...

Quoted 9 lines
drivers/gpio/Kconfig +9 -0
+static void sf_gpio_remove(struct platform_device *pdev)
+{
+	struct sf_gpio_priv *priv = platform_get_drvdata(pdev);
+
+	reset_control_assert(priv->rstc);
+}
+
+static const struct of_device_id sf_gpio_ids[] = {
+	{ .compatible = "siflower,sf19a2890-gpio" },

drivers/gpio/Kconfig

Quoted 10 lines
drivers/gpio/Kconfig +10 -0
+	{},
+};
+MODULE_DEVICE_TABLE(of, sf_gpio_ids);
+
+static struct platform_driver sf_gpio_driver = {
+	.probe		= sf_gpio_probe,
+	.remove		= sf_gpio_remove,
+	.driver = {
+		.name		= "siflower_gpio",
+		.owner		= THIS_MODULE,

You sent us some old code with old code style, so probably you sent us donwstream poor driver. Please clean it up before posting.

Please run standard kernel tools for static analysis, like coccinelle, smatch and sparse, and fix reported warnings. Also please check for warnings when building with W=1. Most of these commands (checks or W=1 build) can build specific targets, like some directory, to narrow the scope to only your code. The code here looks like it needs a fix. Feel free to get in touch if the warning is not clear.

Best regards,
Krzysztof

#9 lore raw

Hello Krzysztof!

Quoted 25 lines · Krzysztof Kozlowski
Quoted 23 lines · Chuanhong Guo

From: Qingfang Deng <[email protected]>

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.

---
 drivers/gpio/Kconfig         |   9 +
 drivers/gpio/Makefile        |   1 +
 drivers/gpio/gpio-siflower.c | 353 +++++++++++++++++++++++++++++++++++
 3 files changed, 363 insertions(+)
 create mode 100644 drivers/gpio/gpio-siflower.c
drivers/gpio/Kconfig +0 -0
index add5ad29a673..fdc9a89ffbf3 100644
@@ -637,6 +637,15 @@ config GPIO_SIFIVE
      help
        Say yes here to support the GPIO device on SiFive SoCs.
 
Quoted 7 lines

drivers/gpio/Kconfig config GPIO_SIFIVE · line 643

Quoted 4 lines
drivers/gpio/Kconfig +4 -0
+config GPIO_SIFLOWER
+     tristate "SiFlower GPIO support"
+     depends on OF_GPIO
+     depends on MIPS || RISCV || COMPILE_TEST

This is supposed to be dependency on ARCH, not instruction set. I don't se anything MIPS or RISCV here.

I haven't sent any arch patches yet. The SoCs basically work with MIPS/RISC-V generic kernel so I was planning to deal with it last with some device trees.
Should I simply drop this dependency line for now, or should I add ARCH_xxx to arch/{mips,riscv}/Kconfig first?

Quoted 22 lines
Quoted 5 lines
drivers/gpio/Kconfig +4 -0
+     select GPIOLIB_IRQCHIP
+     help
+       GPIO controller driver for SiFlower MIPS and RISC-V SoCs
+       including SF19A2890, SF21A6826 and SF21H8898.

...

Quoted 14 lines
drivers/gpio/Kconfig +14 -0
+static void sf_gpio_remove(struct platform_device *pdev)
+{
+     struct sf_gpio_priv *priv = platform_get_drvdata(pdev);
+
+     reset_control_assert(priv->rstc);
+}
+
+static const struct of_device_id sf_gpio_ids[] = {
+     { .compatible = "siflower,sf19a2890-gpio" },
+     {},
+};
+MODULE_DEVICE_TABLE(of, sf_gpio_ids);
+
+static struct platform_driver sf_gpio_driver = {
Quoted 8 lines

drivers/gpio/Kconfig

Quoted 5 lines
drivers/gpio/Kconfig +5 -0
+     .probe          = sf_gpio_probe,
+     .remove         = sf_gpio_remove,
+     .driver = {
+             .name           = "siflower_gpio",
+             .owner          = THIS_MODULE,

You sent us some old code with old code style, so probably you sent us donwstream poor driver.

I'll drop this owner line.

Quoted 1 line

Please clean it up before posting.

Do you have other specific review comments? I haven't found other stuff to clean up currently.

Quoted 1 line

Please run standard kernel tools for static analysis, like coccinelle,

coccinelle failed on something else:

make ARCH=mips CROSS_COMPILE=mipsel-linux-gnu- C=2 CHECK="scripts/coccicheck" drivers/gpio/gpio-siflower.o

[...]
/usr/bin/spatch -D report --no-show-diff --very-quiet --cocci-file ./scripts/coccinelle/misc/secs_to_jiffies.cocci -I ./arch/mips/include -I ./arch/mips/include/generated -I ./include -I ./include -I ./arch/mips/include/uapi -I ./arch/mips/include/generated/uapi -I ./include/uapi -I ./include/generated/uapi --include ./include/linux/compiler-version.h --include ./include/linux/kconfig.h scripts/mod/empty.c
virtual rule report not supported
coccicheck failed

After removing ./scripts/coccinelle/misc/secs_to_jiffies.cocci, I got:

[...]
/usr/bin/spatch -D report --no-show-diff --very-quiet --cocci-file ./scripts/coccinelle/api/stream
_open.cocci -I ./arch/mips/include -I ./arch/mips/include/generated -I ./include -I ./include -I .
/arch/mips/include/uapi -I ./arch/mips/include/generated/uapi -I ./include/uapi -I ./include/gener
ated/uapi --include ./include/linux/compiler-version.h --include ./include/linux/kconfig.h drivers
/gpio/gpio-siflower.c
warning: line 140: should noop_llseek be a metavariable?
warning: line 222: should nonseekable_open be a metavariable?
warning: line 289: should nonseekable_open be a metavariable?
warning: line 337: should nonseekable_open be a metavariable? [...]

These doesn't seem to be related to gpio-siflower.c. There's no noop_llseek or nonseekable_open in it.

Quoted 1 line

smatch

smatch give me nothing:

make ARCH=mips CROSS_COMPILE=mipsel-linux-gnu- C=2 CHECK="smatch -p=kernel" drivers/gpio/gpio-siflower.o
[...]
CC kernel/bounds.s
CC arch/mips/kernel/asm-offsets.s
CALL scripts/checksyscalls.sh
CHKSHA1 include/linux/atomic/atomic-arch-fallback.h CHKSHA1 include/linux/atomic/atomic-instrumented.h CHKSHA1 include/linux/atomic/atomic-long.h
CC drivers/gpio/gpio-siflower.o
CHECK drivers/gpio/gpio-siflower.c

Quoted 1 line

and sparse

sparse doesn't seem to tell me anything about the driver itself either.

make ARCH=mips CROSS_COMPILE=mipsel-linux-gnu- C=2 CHECK="sparse" drivers/gpio/gpio-siflower.o
CHECK scripts/mod/empty.c
command-line: note: in included file:
builtin:1:9: warning: preprocessor token __ATOMIC_ACQUIRE redefined builtin:0:0: this was the original definition builtin:1:9: warning: preprocessor token __ATOMIC_SEQ_CST redefined builtin:0:0: this was the original definition builtin:1:9: warning: preprocessor token __ATOMIC_ACQ_REL redefined builtin:0:0: this was the original definition builtin:1:9: warning: preprocessor token __ATOMIC_RELEASE redefined builtin:0:0: this was the original definition
CALL scripts/checksyscalls.sh
CHECK drivers/gpio/gpio-siflower.c
command-line: note: in included file:
builtin:1:9: warning: preprocessor token __ATOMIC_ACQUIRE redefined builtin:0:0: this was the original definition builtin:1:9: warning: preprocessor token __ATOMIC_SEQ_CST redefined builtin:0:0: this was the original definition builtin:1:9: warning: preprocessor token __ATOMIC_ACQ_REL redefined builtin:0:0: this was the original definition builtin:1:9: warning: preprocessor token __ATOMIC_RELEASE redefined builtin:0:0: this was the original definition

Quoted 2 lines

, and fix reported warnings. Also please check for warnings when building with W=1.

I also got nothing from this one:

rm drivers/gpio/gpio-siflower.o && make ARCH=mips CROSS_COMPILE=mipsel-linux-gnu- W=1 drivers/gpio/gpio-siflower.o

  CC      scripts/mod/empty.o
  MKELF   scripts/mod/elfconfig.h
  HOSTCC  scripts/mod/modpost.o
  CC      scripts/mod/devicetable-offsets.s
  HOSTCC  scripts/mod/file2alias.o
  HOSTCC  scripts/mod/sumversion.o
  HOSTCC  scripts/mod/symsearch.o
  HOSTLD  scripts/mod/modpost
  CC      kernel/bounds.s
  CC      arch/mips/kernel/asm-offsets.s
  CALL    scripts/checksyscalls.sh
  CC      drivers/gpio/gpio-siflower.o
Quoted 3 lines

Most of these commands (checks or W=1
build) can build specific targets, like some directory, to narrow the scope to only your code. The code here looks like it needs a fix.

Would you mind sharing the warnings you found, and the command to reproduce those?

Quoted 6 lines

Feel
free to get in touch if the warning is not clear.

Best regards,
Krzysztof

Signature · 2 lines
Regards,
Chuanhong Guo
#10 lore raw
Quoted 36 lines · Chuanhong Guo

Hello Krzysztof!

Quoted 25 lines · Krzysztof Kozlowski
Quoted 23 lines · Chuanhong Guo

From: Qingfang Deng <[email protected]>

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.

---
 drivers/gpio/Kconfig         |   9 +
 drivers/gpio/Makefile        |   1 +
 drivers/gpio/gpio-siflower.c | 353 +++++++++++++++++++++++++++++++++++
 3 files changed, 363 insertions(+)
 create mode 100644 drivers/gpio/gpio-siflower.c
drivers/gpio/Kconfig +0 -0
index add5ad29a673..fdc9a89ffbf3 100644
@@ -637,6 +637,15 @@ config GPIO_SIFIVE
      help
        Say yes here to support the GPIO device on SiFive SoCs.
 
Quoted 7 lines

drivers/gpio/Kconfig config GPIO_SIFIVE · line 643

Quoted 4 lines
drivers/gpio/Kconfig +4 -0
+config GPIO_SIFLOWER
+     tristate "SiFlower GPIO support"
+     depends on OF_GPIO
+     depends on MIPS || RISCV || COMPILE_TEST

This is supposed to be dependency on ARCH, not instruction set. I don't se anything MIPS or RISCV here.

Quoted 4 lines

I haven't sent any arch patches yet. The SoCs basically work with MIPS/RISC-V generic kernel so I was planning to deal with it last with some device trees.
Should I simply drop this dependency line for now, or should I add

This would work but OTOH it is also easy to forget to re-add it later.

Quoted 1 line

ARCH_xxx to arch/{mips,riscv}/Kconfig first?

But this is preferred. For me ARCH always comes first (or in parallel), not the last. Why would we like to accept drivers which are not really usable without the main parts?

Quoted 25 lines
Quoted 8 lines
Quoted 6 lines
drivers/gpio/Kconfig +4 -0
+     select GPIOLIB_IRQCHIP
+     help
+       GPIO controller driver for SiFlower MIPS and RISC-V SoCs
+       including SF19A2890, SF21A6826 and SF21H8898.

...

rm drivers/gpio/gpio-siflower.o && make ARCH=mips CROSS_COMPILE=mipsel-linux-gnu- W=1 drivers/gpio/gpio-siflower.o

  CC      scripts/mod/empty.o
  MKELF   scripts/mod/elfconfig.h
  HOSTCC  scripts/mod/modpost.o
  CC      scripts/mod/devicetable-offsets.s
  HOSTCC  scripts/mod/file2alias.o
  HOSTCC  scripts/mod/sumversion.o
  HOSTCC  scripts/mod/symsearch.o
  HOSTLD  scripts/mod/modpost
  CC      kernel/bounds.s
  CC      arch/mips/kernel/asm-offsets.s
  CALL    scripts/checksyscalls.sh
  CC      drivers/gpio/gpio-siflower.o
Quoted 6 lines
Quoted 3 lines

Most of these commands (checks or W=1
build) can build specific targets, like some directory, to narrow the scope to only your code. The code here looks like it needs a fix.

Would you mind sharing the warnings you found, and the command to reproduce those?

Cocci prints warning for the owner and based on owner presence I suspect there could be more of patterns we fixed over last 10 years.

Best regards,
Krzysztof