Add Nuvoton NPCM SGPIO feature
Subsystems (3)
v9 cover Add Nuvoton NPCM SGPIO feature
This SGPIO controller is for NUVOTON NPCM7xx and NPCM8xx SoC. Nuvoton NPCM SGPIO module is combine serial to parallel IC (HC595) and parallel to serial IC (HC165), and use APB3 clock to control it. This interface has 4 pins (D_out , D_in, S_CLK, LDSH). NPCM7xx/NPCM8xx have two sgpio module each module can support up to 64 output pins,and up to 64 input pin, the pin is only for GPI or GPO. GPIO pins have sequential, First half is GPO and second half is GPI.
Jim Liu (3):
dt-bindings: gpio: add NPCM sgpio driver bindings
arm: dts: nuvoton: npcm: Add sgpio feature
gpio: nuvoton: Add Nuvoton NPCM sgpio driver
.../bindings/gpio/nuvoton,sgpio.yaml | 86 +++ .../dts/nuvoton/nuvoton-common-npcm7xx.dtsi | 24 + drivers/gpio/Kconfig | 7 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-npcm-sgpio.c | 635 ++++++++++++++++++ 5 files changed, 753 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml create mode 100644 drivers/gpio/gpio-npcm-sgpio.c
Signature · 1 line
2.25.1
PATCH v9 1/3 dt-bindings: gpio: add NPCM sgpio driver bindings
Add dt-bindings document for the Nuvoton NPCM7xx sgpio driver
---
Changes for v9:
- no changed
Changes for v8:
- no changed
Changes for v7:
- no changed
--- .../bindings/gpio/nuvoton,sgpio.yaml | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +86 -0
@@ -0,0 +1,86 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/gpio/nuvoton,sgpio.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nuvoton SGPIO controller + +maintainers: + - Jim LIU <[email protected]> + +description: | + This SGPIO controller is for NUVOTON NPCM7xx and NPCM8xx SoC. + Nuvoton NPCM7xx SGPIO module is combine serial to parallel IC (HC595) + and parallel to serial IC (HC165), and use APB3 clock to control it. + This interface has 4 pins (D_out , D_in, S_CLK, LDSH). + NPCM7xx/NPCM8xx have two sgpio module each module can support up + to 64 output pins,and up to 64 input pin, the pin is only for gpi or gpo. + GPIO pins have sequential, First half is gpo and second half is gpi. + GPIO pins can be programmed to support the following options + - Support interrupt option for each input port and various interrupt + sensitivity option (level-high, level-low, edge-high, edge-low) + - ngpios is number of nuvoton,input-ngpios GPIO lines and nuvoton,output-ngpios GPIO lines. + nuvoton,input-ngpios GPIO lines is only for gpi. + nuvoton,output-ngpios GPIO lines is only for gpo. + +properties: + compatible: + enum: + - nuvoton,npcm750-sgpio + - nuvoton,npcm845-sgpio + + reg: + maxItems: 1 + + gpio-controller: true + + '#gpio-cells': + const: 2 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + nuvoton,input-ngpios: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + The numbers of GPIO's exposed. GPIO lines is only for gpi. + minimum: 0 + maximum: 64 + + nuvoton,output-ngpios: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + The numbers of GPIO's exposed. GPIO lines is only for gpo. + minimum: 0 + maximum: 64 + +required: + - compatible + - reg + - gpio-controller + - '#gpio-cells' + - interrupts + - nuvoton,input-ngpios + - nuvoton,output-ngpios + - clocks + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/nuvoton,npcm7xx-clock.h> + #include <dt-bindings/interrupt-controller/arm-gic.h> + gpio8: gpio@101000 { + compatible = "nuvoton,npcm750-sgpio"; + reg = <0x101000 0x200>; + clocks = <&clk NPCM7XX_CLK_APB3>; + interrupts = <GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH>; + gpio-controller; + #gpio-cells = <2>; + nuvoton,input-ngpios = <64>; + nuvoton,output-ngpios = <64>; + };
Signature · 1 line
2.25.1
Re: [PATCH v9 1/3] dt-bindings: gpio: add NPCM sgpio driver bindings
Dear Jim,
Thank you for your patch.
Am 12.12.23 um 07:51 schrieb Jim Liu:
Quoted 5 lines
Add dt-bindings document for the Nuvoton NPCM7xx sgpio driver
Signed-off-by Jim Liu <[email protected]>Reviewed-by Linus Walleij <[email protected]>Reviewed-by Rob Herring <[email protected]>
As you seem to be employed by Nuvoton, should your company/work email be listed somehow, and even be used for the author address?
Quoted 22 lines
---
Changes for v9:
- no changed
Changes for v8:
- no changed
Changes for v7:
- no changed--- .../bindings/gpio/nuvoton,sgpio.yaml | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+)create mode 100644
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yamlDocumentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +4
-0@@ -0,0 +1,86 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/gpio/nuvoton,sgpio.yaml#
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 14
Quoted 10 lines
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +10
-0+$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nuvoton SGPIO controller + +maintainers: + - Jim LIU <[email protected]> + +description: | + This SGPIO controller is for NUVOTON NPCM7xx and NPCM8xx SoC. + Nuvoton NPCM7xx SGPIO module is combine serial to parallel IC (HC595)
s/is combine/combines a/
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 15
Quoted 1 line
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +1
-0+ and parallel to serial IC (HC165), and use APB3 clock to control it.
use*s*
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 16
Quoted 1 line
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +1
-0+ This interface has 4 pins (D_out , D_in, S_CLK, LDSH).
Only one space before the (.
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 17
Quoted 1 line
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +1
-0+ NPCM7xx/NPCM8xx have two sgpio module each module can support up
… modules. Each module …
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 18
Quoted 1 line
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +1
-0+ to 64 output pins,and up to 64 input pin, the pin is only for gpi or gpo.
1. Space after the comma.
2. 64 input pin*s
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 19
Quoted 1 line
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +1
-0+ GPIO pins have sequential, First half is gpo and second half is gpi.
have sequential ?.
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 22
Quoted 3 lines
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +3
-0+ GPIO pins can be programmed to support the following options + - Support interrupt option for each input port and various interrupt + sensitivity option (level-high, level-low, edge-high, edge-low)
option*s*
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 24
Quoted 2 lines
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +2
-0+ - ngpios is number of nuvoton,input-ngpios GPIO lines and nuvoton,output-ngpios GPIO lines. + nuvoton,input-ngpios GPIO lines is only for gpi.
s/is/are/
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 25
Quoted 1 line
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +1
-0+ nuvoton,output-ngpios GPIO lines is only for gpo.
s/is/are/
It’d be great if you mentioned the datasheet name and revision in the description.
Quoted 15 lines
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +15
-0+ +properties: + compatible: + enum: + - nuvoton,npcm750-sgpio + - nuvoton,npcm845-sgpio + + reg: + maxItems: 1 + + gpio-controller: true + + '#gpio-cells': + const: 2 +
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 50
Quoted 10 lines
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +10
-0+ interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + nuvoton,input-ngpios: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + The numbers of GPIO's exposed. GPIO lines is only for gpi.
s/is/are/
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 57
Quoted 7 lines
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +7
-0+ minimum: 0 + maximum: 64 + + nuvoton,output-ngpios: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + The numbers of GPIO's exposed. GPIO lines is only for gpo.
s/is/are/
Quoted 19 lines
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +19
-0+ minimum: 0 + maximum: 64 + +required: + - compatible + - reg + - gpio-controller + - '#gpio-cells' + - interrupts + - nuvoton,input-ngpios + - nuvoton,output-ngpios + - clocks + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/nuvoton,npcm7xx-clock.h> + #include <dt-bindings/interrupt-controller/arm-gic.h>
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 86
Quoted 10 lines
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +10
-0+ gpio8: gpio@101000 { + compatible = "nuvoton,npcm750-sgpio"; + reg = <0x101000 0x200>; + clocks = <&clk NPCM7XX_CLK_APB3>; + interrupts = <GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH>; + gpio-controller; + #gpio-cells = <2>; + nuvoton,input-ngpios = <64>; + nuvoton,output-ngpios = <64>; + };
Kind regards,
Paul Menzel
Re: [PATCH v9 1/3] dt-bindings: gpio: add NPCM sgpio driver bindings
Hi Paul
Thanks for your review.
I will modify it in the next version.
Best regards,
Jim
Quoted 164 lines · Paul Menzel
Dear Jim,
Thank you for your patch.
Am 12.12.23 um 07:51 schrieb Jim Liu:
Quoted 5 lines
Add dt-bindings document for the Nuvoton NPCM7xx sgpio driver
Signed-off-by Jim Liu <[email protected]>Reviewed-by Linus Walleij <[email protected]>Reviewed-by Rob Herring <[email protected]>As you seem to be employed by Nuvoton, should your company/work email be listed somehow, and even be used for the author address?
Quoted 22 lines
---
Changes for v9:
- no changed
Changes for v8:
- no changed
Changes for v7:
- no changed--- .../bindings/gpio/nuvoton,sgpio.yaml | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+)create mode 100644
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yamlDocumentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +4
-0@@ -0,0 +1,86 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/gpio/nuvoton,sgpio.yaml#Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 14
Quoted 10 lines
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +10
-0+$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nuvoton SGPIO controller + +maintainers: + - Jim LIU <[email protected]> + +description: | + This SGPIO controller is for NUVOTON NPCM7xx and NPCM8xx SoC. + Nuvoton NPCM7xx SGPIO module is combine serial to parallel IC (HC595)s/is combine/combines a/
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 15
Quoted 1 line
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +1
-0+ and parallel to serial IC (HC165), and use APB3 clock to control it.use*s*
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 16
Quoted 1 line
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +1
-0+ This interface has 4 pins (D_out , D_in, S_CLK, LDSH).Only one space before the (.
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 17
Quoted 1 line
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +1
-0+ NPCM7xx/NPCM8xx have two sgpio module each module can support up… modules. Each module …
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 18
Quoted 1 line
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +1
-0+ to 64 output pins,and up to 64 input pin, the pin is only for gpi or gpo.1. Space after the comma.
2. 64 input pin*sDocumentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 19
Quoted 1 line
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +1
-0+ GPIO pins have sequential, First half is gpo and second half is gpi.have sequential ?.
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 22
Quoted 3 lines
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +3
-0+ GPIO pins can be programmed to support the following options + - Support interrupt option for each input port and various interrupt + sensitivity option (level-high, level-low, edge-high, edge-low)option*s*
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 24
Quoted 2 lines
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +2
-0+ - ngpios is number of nuvoton,input-ngpios GPIO lines and nuvoton,output-ngpios GPIO lines. + nuvoton,input-ngpios GPIO lines is only for gpi.s/is/are/
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 25
Quoted 1 line
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +1
-0+ nuvoton,output-ngpios GPIO lines is only for gpo.s/is/are/
It’d be great if you mentioned the datasheet name and revision in the description.
Quoted 15 lines
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +15
-0+ +properties: + compatible: + enum: + - nuvoton,npcm750-sgpio + - nuvoton,npcm845-sgpio + + reg: + maxItems: 1 + + gpio-controller: true + + '#gpio-cells': + const: 2 +Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 50
Quoted 10 lines
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +10
-0+ interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + nuvoton,input-ngpios: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + The numbers of GPIO's exposed. GPIO lines is only for gpi.s/is/are/
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 57
Quoted 7 lines
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +7
-0+ minimum: 0 + maximum: 64 + + nuvoton,output-ngpios: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + The numbers of GPIO's exposed. GPIO lines is only for gpo.s/is/are/
Quoted 19 lines
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +19
-0+ minimum: 0 + maximum: 64 + +required: + - compatible + - reg + - gpio-controller + - '#gpio-cells' + - interrupts + - nuvoton,input-ngpios + - nuvoton,output-ngpios + - clocks + +additionalProperties: false + +examples: + - | + #include <dt-bindings/clock/nuvoton,npcm7xx-clock.h> + #include <dt-bindings/interrupt-controller/arm-gic.h>Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml line 86
Quoted 10 lines
Documentation/devicetree/bindings/gpio/nuvoton,sgpio.yaml new file +10
-0+ gpio8: gpio@101000 { + compatible = "nuvoton,npcm750-sgpio"; + reg = <0x101000 0x200>; + clocks = <&clk NPCM7XX_CLK_APB3>; + interrupts = <GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH>; + gpio-controller; + #gpio-cells = <2>; + nuvoton,input-ngpios = <64>; + nuvoton,output-ngpios = <64>; + };Reviewed-by Paul Menzel <[email protected]>Kind regards,
Paul Menzel
PATCH v9 2/3 arm: dts: nuvoton: npcm: Add sgpio feature
In reply to Jim LiuAdd the SGPIO controller to the NPCM7xx devicetree
---
Changes for v9:
- no changed
Changes for v8:
- no changed
Changes for v7:
- no changed
--- .../dts/nuvoton/nuvoton-common-npcm7xx.dtsi | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+)
arch/arm/boot/dts/nuvoton/nuvoton-common-npcm7xx.dtsi +24 -0
@@ -372,6 +372,30 @@ &fanin12_pins &fanin13_pins status = "disabled"; }; + gpio8: gpio@101000 { + compatible = "nuvoton,npcm750-sgpio"; + reg = <0x101000 0x200>; + clocks = <&clk NPCM7XX_CLK_APB3>; + interrupts = <GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH>; + gpio-controller; + #gpio-cells = <2>; + nuvoton,input-ngpios = <64>; + nuvoton,output-ngpios = <64>; + status = "disabled"; + }; + + gpio9: gpio@102000 { + compatible = "nuvoton,npcm750-sgpio"; + reg = <0x102000 0x200>; + clocks = <&clk NPCM7XX_CLK_APB3>; + interrupts = <GIC_SPI 19 IRQ_TYPE_LEVEL_HIGH>; + gpio-controller; + #gpio-cells = <2>; + nuvoton,input-ngpios = <64>; + nuvoton,output-ngpios = <64>; + status = "disabled"; + }; + i2c0: i2c@80000 { reg = <0x80000 0x1000>; compatible = "nuvoton,npcm750-i2c";
Signature · 1 line
2.25.1
PATCH v9 3/3 gpio: nuvoton: Add Nuvoton NPCM sgpio driver
In reply to Jim LiuAdd Nuvoton BMC NPCM7xx/NPCM8xx sgpio driver support. Nuvoton NPCM SGPIO module is combine serial to parallel IC (HC595) and parallel to serial IC (HC165), and use APB3 clock to control it. This interface has 4 pins (D_out , D_in, S_CLK, LDSH).
BMC can use this driver to increase 64 GPI pins and 64 GPO pins to use.
---
Changes for v9:
- fix kernel rebot test warning
Changes for v8:
- Remove OF_GPIO/GPIO_GENERIC and redundant assignments
- Use GENMASK() and BIT()
- Use dev_WARN and dev_err_probe
- Check indentation issue
- Use raw_spinlock_t
Changes for v7:
- Remove unused variable
- Remove return in bank_reg function
- Fix warning for const issue
--- drivers/gpio/Kconfig | 7 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-npcm-sgpio.c | 635 +++++++++++++++++++++++++++++++++ 3 files changed, 643 insertions(+) create mode 100644 drivers/gpio/gpio-npcm-sgpio.c
drivers/gpio/Kconfig +7 -0
@@ -478,6 +478,13 @@ config GPIO_MXS select GPIO_GENERIC select GENERIC_IRQ_CHIP +config GPIO_NPCM_SGPIO + bool "Nuvoton SGPIO support" + depends on ARCH_NPCM || COMPILE_TEST + select GPIOLIB_IRQCHIP + help + Say Y here to support Nuvoton NPCM7XX/NPCM8XX SGPIO functionality. + config GPIO_OCTEON tristate "Cavium OCTEON GPIO" depends on CAVIUM_OCTEON_SOC
drivers/gpio/Makefile +1 -0
@@ -116,6 +116,7 @@ obj-$(CONFIG_GPIO_MT7621) += gpio-mt7621.o obj-$(CONFIG_GPIO_MVEBU) += gpio-mvebu.o obj-$(CONFIG_GPIO_MXC) += gpio-mxc.o obj-$(CONFIG_GPIO_MXS) += gpio-mxs.o +obj-$(CONFIG_GPIO_NPCM_SGPIO) += gpio-npcm-sgpio.o obj-$(CONFIG_GPIO_OCTEON) += gpio-octeon.o obj-$(CONFIG_GPIO_OMAP) += gpio-omap.o obj-$(CONFIG_GPIO_PALMAS) += gpio-palmas.o
drivers/gpio/gpio-npcm-sgpio.c new file +635 -0
635 lines not on this page · raw message
Signature · 1 line
2.25.1
Re: [PATCH v9 3/3] gpio: nuvoton: Add Nuvoton NPCM sgpio driver
Quoted 5 lines · Jim Liu
Add Nuvoton BMC NPCM7xx/NPCM8xx sgpio driver support. Nuvoton NPCM SGPIO module is combine serial to parallel IC (HC595) and parallel to serial IC (HC165), and use APB3 clock to control it. This interface has 4 pins (
D_out,D_in,S_CLK, LDSH).
BMC can use this driver to increase 64 GPI pins and 64 GPO pins to use.
...
drivers/gpio/gpio-npcm-sgpio.c line 14
Quoted 8 lines
drivers/gpio/gpio-npcm-sgpio.c new file +7
-0+#include <linux/bitfield.h> +#include <linux/clk.h> +#include <linux/gpio/driver.h> +#include <linux/hashtable.h> +#include <linux/init.h> +#include <linux/io.h> +#include <linux/kernel.h>
Is this a proxy to some other headers like array_size.h? Please use respective headers directly.
Quoted 4 lines
drivers/gpio/gpio-npcm-sgpio.c new file +4
-0+#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/spinlock.h> +#include <linux/string.h>
...
Quoted 1 line
+#define
NPCM_CLK_MHZ8000000
HZ_PER_MHZ from units.h?
...
drivers/gpio/gpio-npcm-sgpio.c line 59
Quoted 5 lines
drivers/gpio/gpio-npcm-sgpio.c new file +5
-0+struct npcm_sgpio { +struct gpio_chip chip; +struct clk *pclk; +struct irq_chip intc; +raw_spinlock_t lock;/*protect event config*/
Missing spaces.
Quoted 8 lines
drivers/gpio/gpio-npcm-sgpio.c new file +8
-0+void __iomem *base; +int irq; +u8 nin_sgpio; +u8 nout_sgpio; +u8 in_port; +u8 out_port; +u8 int_type[MAX_NR_HW_SGPIO ]; +};
...
drivers/gpio/gpio-npcm-sgpio.c line 132
Quoted 7 lines
drivers/gpio/gpio-npcm-sgpio.c new file +7
-0+ { + .wdata_reg = 0x07, + .rdata_reg = 0x0f, + .event_config = 0x1e, + .event_status = 0x27, + }, +
Redundant blank line.
...
Quoted 6 lines
drivers/gpio/gpio-npcm-sgpio.c new file +6
-0+static void __iomem *bank_reg (struct npcm_sgpio *gpio, +const struct npcm_sgpio_bank *bank, +const enum npcm_sgpio_reg reg) +{ +switch (reg) { +case READ_DATA :
drivers/gpio/gpio-npcm-sgpio.c line 150
Quoted 10 lines
drivers/gpio/gpio-npcm-sgpio.c new file +10
-0+return gpio->base + bank->rdata_reg; +case WRITE_DATA : +return gpio->base + bank->wdata_reg; +case EVENT_CFG : +return gpio->base + bank->event_config; +case EVENT_STS : +return gpio->base + bank->event_status; +default : +/* actually if code runs to here, it's an error case */ +dev_WARN (gpio->chip.parent,"Getting here is an error condition" );
...then return an error here.
Review
Quoted 2 lines
(quoted diff) +2
-0+ } + return 0;
See above.
drivers/gpio/gpio-npcm-sgpio.c line 162
Quoted 3 lines
drivers/gpio/gpio-npcm-sgpio.c new file +2
-0+} +static void irqd_to_npcm_sgpio_data(struct irq_data *d,
Respect namespace, here it's better to have npcm_sgpio_irqd_to_data().
Quoted 3 lines
drivers/gpio/gpio-npcm-sgpio.c new file +3
-0+struct npcm_sgpio **gpio, + const struct npcm_sgpio_bank **bank, + u8 *bit, unsigned int *offset)
...
drivers/gpio/gpio-npcm-sgpio.c line 184
Quoted 7 lines
drivers/gpio/gpio-npcm-sgpio.c new file +7
-0+static int npcm_sgpio_init_port (struct npcm_sgpio *gpio) +{ +u8 in_port, out_port, set_port, reg; + + in_port =GPIO_BANK (gpio->nin_sgpio); +if (GPIO_BIT (gpio->nin_sgpio) >0 ) + in_port +=1 ;
This is strange... So, you are telling that offsets start from 1 and not 0?
drivers/gpio/gpio-npcm-sgpio.c line 188
Quoted 3 lines
drivers/gpio/gpio-npcm-sgpio.c new file +3
-0+ out_port =GPIO_BANK (gpio->nout_sgpio); +if (GPIO_BIT (gpio->nout_sgpio) >0 ) + out_port +=1 ;
Ditto.
...
drivers/gpio/gpio-npcm-sgpio.c line 192
Quoted 1 line
drivers/gpio/gpio-npcm-sgpio.c new file +1
-0+ set_port = ((out_port &NPCM_IOXCFG2_PORT ) <<4 ) | (in_port &NPCM_IOXCFG2_PORT );
Outer parentheses are redundant.
...
drivers/gpio/gpio-npcm-sgpio.c line 214
Quoted 7 lines
drivers/gpio/gpio-npcm-sgpio.c new file +6
-0+static int npcm_sgpio_dir_out (struct gpio_chip *gc,unsigned int offset,int val) +{ + gc->set (gc, offset, val); + +return 0 ; +
Redundant blank line.
drivers/gpio/gpio-npcm-sgpio.c line 222
Quoted 8 lines
drivers/gpio/gpio-npcm-sgpio.c new file +7
-0+} + +static int npcm_sgpio_get_direction (struct gpio_chip *gc,unsigned int offset) +{ +struct npcm_sgpio *gpio =gpiochip_get_data (gc); +if (offset > gpio->chip.ngpio) +return -EINVAL ;
Why do you need this check?
Quoted 5 lines
drivers/gpio/gpio-npcm-sgpio.c new file +5
-0+if (offset < gpio->nout_sgpio) +return GPIO_LINE_DIRECTION_OUT ; + +return GPIO_LINE_DIRECTION_IN ; +}
...
drivers/gpio/gpio-npcm-sgpio.c line 241
Quoted 12 lines
drivers/gpio/gpio-npcm-sgpio.c new file +12
-0+static void npcm_sgpio_set (struct gpio_chip *gc,unsigned int offset,int val) +{ +struct npcm_sgpio *gpio =gpiochip_get_data (gc); +const struct npcm_sgpio_bank *bank =offset_to_bank (offset); +void __iomem *addr; +u8 reg =0 ; + + addr =bank_reg (gpio, bank,WRITE_DATA ); + reg =ioread8 (addr); + +if (val) + reg |= (val <<GPIO_BIT (offset));
...and if val is not 1?..
drivers/gpio/gpio-npcm-sgpio.c line 243
Quoted 2 lines
drivers/gpio/gpio-npcm-sgpio.c new file +2
-0+else + reg &= ~(1 <<GPIO_BIT (offset));
In both cases use BIT().
Quoted 2 lines
(quoted diff) +2
-0+ iowrite8(reg, addr); +}
...
Quoted 5 lines
drivers/gpio/gpio-npcm-sgpio.c new file +5
-0+ dir =npcm_sgpio_get_direction (gc, offset); +if (dir ==0 ) { + bank =offset_to_bank (offset); + + addr =bank_reg (gpio, bank,WRITE_DATA );
drivers/gpio/gpio-npcm-sgpio.c line 270
Quoted 10 lines
drivers/gpio/gpio-npcm-sgpio.c new file +10
-0+ reg =ioread8 (addr); + reg = !!(reg &GPIO_BIT (offset)); + }else { + offset -= gpio->nout_sgpio; + bank =offset_to_bank (offset); + + addr =bank_reg (gpio, bank,READ_DATA ); + reg =ioread8 (addr); + reg = !!(reg &GPIO_BIT (offset)); + }
Instead of conditional(s) use arithmetics. You can get all these directly from the properly formed calculations.
...
drivers/gpio/gpio-npcm-sgpio.c line 277
Quoted 4 lines
drivers/gpio/gpio-npcm-sgpio.c new file +3
-0+static void npcm_sgpio_setup_enable (struct npcm_sgpio *gpio,bool enable) +{ +u8 reg =0 ;
Redundant assignment.
drivers/gpio/gpio-npcm-sgpio.c line 281
Quoted 4 lines
drivers/gpio/gpio-npcm-sgpio.c new file +3
-0+ reg =ioread8 (gpio->base +NPCM_IOXCTS ); + reg = reg & ~NPCM_IOXCTS_RD_MODE ; + reg = reg |NPCM_IOXCTS_RD_MODE_PERIODIC ;
Combine them.
Quoted 8 lines
drivers/gpio/gpio-npcm-sgpio.c new file +8
-0+if (enable) { + reg |=NPCM_IOXCTS_IOXIF_EN ; +iowrite8 (reg, gpio->base +NPCM_IOXCTS ); + }else { + reg &= ~NPCM_IOXCTS_IOXIF_EN ; +iowrite8 (reg, gpio->base +NPCM_IOXCTS ); + } +}
...
Quoted 10 lines
drivers/gpio/gpio-npcm-sgpio.c new file +10
-0+static int npcm_sgpio_setup_clk (struct npcm_sgpio *gpio, +const struct npcm_clk_cfg *clk_cfg) +{ +unsigned long apb_freq; +u32 val; +u8 tmp; +int i; + + apb_freq =clk_get_rate (gpio->pclk); + tmp =ioread8 (gpio->base +NPCM_IOXCFG1 ) & ~NPCM_IOXCFG1_SFT_CLK ;
drivers/gpio/gpio-npcm-sgpio.c line 311
Quoted 10 lines
drivers/gpio/gpio-npcm-sgpio.c new file +10
-0+ +for (i =0 ; i < clk_cfg->cfg_opt; i++) { + val = apb_freq / clk_cfg->sft_clk[i]; +if ((NPCM_CLK_MHZ < val) && (i !=0 ) ) { +iowrite8 (clk_cfg->clk_sel[i-1 ] | tmp, gpio->base +NPCM_IOXCFG1 ); +return 0 ; + }else if (i == (clk_cfg->cfg_opt-1 ) && (NPCM_CLK_MHZ > val)) { +iowrite8 (clk_cfg->clk_sel[i] | tmp, gpio->base +NPCM_IOXCFG1 ); +return 0 ; + }
These i == / i != checks probably due to wrong operator be chosen. Consider using while-loop, or do-while. I believe it will make code better.
Quoted 4 lines
drivers/gpio/gpio-npcm-sgpio.c new file +4
-0+ } + +return -EINVAL ; +}
...
drivers/gpio/gpio-npcm-sgpio.c line 321
Quoted 6 lines
drivers/gpio/gpio-npcm-sgpio.c new file +5
-0+static void npcm_sgpio_irq_init_valid_mask (struct gpio_chip *gc, +unsigned long *valid_mask,unsigned int ngpios) +{ +struct npcm_sgpio *gpio =gpiochip_get_data (gc); +int n = gpio->nin_sgpio;
Why do you need this variable, what for?
Quoted 4 lines
drivers/gpio/gpio-npcm-sgpio.c new file +4
-0+/* input GPIOs in the high range */ +bitmap_set (valid_mask, gpio->nout_sgpio, n); +bitmap_clear (valid_mask,0 , gpio->nout_sgpio); +}
...
Review
Quoted 1 line
(quoted diff) +1
-0+ raw_spin_lock_irqsave(&gpio->lock, flags);
Don't you need to use spin lock in the other APIs? It seem whole driver works by luck.
drivers/gpio/gpio-npcm-sgpio.c line 350
Quoted 8 lines
drivers/gpio/gpio-npcm-sgpio.c new file +8
-0+npcm_sgpio_setup_enable (gpio, false); + + reg =ioread16 (addr); +if (set) { + reg &= ~(NPCM_IXOEVCFG_MASK << (bit *2 )); + }else { + type = gpio->int_type[offset]; + reg |= (type << (bit *2 ));
At least the calculations can be done outside of the lock.
Quoted 12 lines
drivers/gpio/gpio-npcm-sgpio.c new file +12
-0+ } + +iowrite16 (reg, addr); + +npcm_sgpio_setup_enable (gpio, true); + + addr =bank_reg (gpio, bank,EVENT_STS ); + reg =ioread8 (addr); + reg |=BIT (bit); +iowrite8 (reg, addr); + +raw_spin_unlock_irqrestore (&gpio->lock, flags);
...
Quoted 14 lines
drivers/gpio/gpio-npcm-sgpio.c new file +14
-0+switch (type &IRQ_TYPE_SENSE_MASK ) { +case IRQ_TYPE_EDGE_BOTH : + val =NPCM_IXOEVCFG_BOTH ; + handler = handle_edge_irq; +break ; +case IRQ_TYPE_EDGE_RISING : + val =NPCM_IXOEVCFG_RISING ; + handler = handle_edge_irq; +break ; +case IRQ_TYPE_EDGE_FALLING : + val =NPCM_IXOEVCFG_FALLING ; + handler = handle_edge_irq; +break ; +case IRQ_TYPE_LEVEL_HIGH :
drivers/gpio/gpio-npcm-sgpio.c line 427
Quoted 10 lines
drivers/gpio/gpio-npcm-sgpio.c new file +10
-0+ val =NPCM_IXOEVCFG_RISING ; + handler = handle_level_irq; +break ; +case IRQ_TYPE_LEVEL_LOW : + val =NPCM_IXOEVCFG_FALLING ; + handler = handle_level_irq; +break ; +default : +return -EINVAL ; + }
You can split the handler setup and make this function less by 5 LoCs or so.
See, for example, gpio-tangier.c.
...
drivers/gpio/gpio-npcm-sgpio.c line 463
Quoted 7 lines
drivers/gpio/gpio-npcm-sgpio.c new file +7
-0+for (i =0 ; i <ARRAY_SIZE (npcm_sgpio_banks); i++) { +const struct npcm_sgpio_bank *bank = &npcm_sgpio_banks[i]; + + reg =ioread8 (bank_reg (gpio, bank,EVENT_STS )); +for_each_set_bit (j, ®,8 ) { + girq =irq_find_mapping (gc->irq.domain, i *8 + gpio->nout_sgpio + j); +generic_handle_irq (girq);
generic_handle_domain_irq()
Quoted 2 lines
(quoted diff) +2
-0+ } + }
...
Quoted 9 lines
drivers/gpio/gpio-npcm-sgpio.c new file +9
-0+static int npcm_sgpio_setup_irqs (struct npcm_sgpio *gpio, +struct platform_device *pdev) +{ +int rc, i; +struct gpio_irq_chip *irq; + + rc =platform_get_irq (pdev,0 ); +if (rc <0 ) +return rc;
drivers/gpio/gpio-npcm-sgpio.c line 498
Quoted 10 lines
drivers/gpio/gpio-npcm-sgpio.c new file +9
-0+ + gpio->irq = rc; + +npcm_sgpio_setup_enable (gpio, false); + +/* Disable IRQ and clear Interrupt status registers for all SGPIO Pins. */ +for (i =0 ; i <ARRAY_SIZE (npcm_sgpio_banks); i++) { +const struct npcm_sgpio_bank *bank = &npcm_sgpio_banks[i]; +iowrite16 (0x0000 ,bank_reg (gpio, bank,EVENT_CFG ));
0 is enough.
drivers/gpio/gpio-npcm-sgpio.c line 499
Quoted 1 line
drivers/gpio/gpio-npcm-sgpio.c new file +1
-0+iowrite8 (0xff ,bank_reg (gpio, bank,EVENT_STS ));
GENMASK() ?
Quoted 14 lines
drivers/gpio/gpio-npcm-sgpio.c new file +14
-0+ } + + irq = &gpio->chip.irq; +gpio_irq_chip_set_chip (irq, &sgpio_irq_chip); + irq->init_valid_mask = npcm_sgpio_irq_init_valid_mask; + irq->handler = handle_bad_irq; + irq->default_type =IRQ_TYPE_NONE ; + irq->parent_handler = npcm_sgpio_irq_handler; + irq->parent_handler_data = gpio; + irq->parents = &gpio->irq; + irq->num_parents =1 ; + +return 0 ; +}
...
drivers/gpio/gpio-npcm-sgpio.c line 534
Quoted 4 lines
drivers/gpio/gpio-npcm-sgpio.c new file +4
-0+static struct npcm_clk_cfg npcm750_sgpio_pdata = { + .sft_clk = npcm750_SFT_CLK, + .clk_sel = npcm750_CLK_SEL, + .cfg_opt =6 ,
Define this magic and use it in the above arrays as the capacity.
drivers/gpio/gpio-npcm-sgpio.c line 540
Quoted 7 lines
drivers/gpio/gpio-npcm-sgpio.c new file +6
-0+}; + +static const struct npcm_clk_cfg npcm845_sgpio_pdata = { + .sft_clk = npcm845_SFT_CLK, + .clk_sel = npcm845_CLK_SEL, + .cfg_opt =5 ,
Ditto.
Quoted 1 line
+};
...
drivers/gpio/gpio-npcm-sgpio.c line 548
Quoted 6 lines
drivers/gpio/gpio-npcm-sgpio.c new file +6
-0+static const struct of_device_id npcm_sgpio_of_table[] = { + { .compatible ="nuvoton,npcm750-sgpio" , .data = &npcm750_sgpio_pdata, }, + { .compatible ="nuvoton,npcm845-sgpio" , .data = &npcm845_sgpio_pdata, }, + {} +}; +MODULE_DEVICE_TABLE (of, npcm_sgpio_of_table);
Move this closer to its user below.
...
drivers/gpio/gpio-npcm-sgpio.c line 582
Quoted 4 lines
drivers/gpio/gpio-npcm-sgpio.c new file +4
-0+if (gpio->nin_sgpio >MAX_NR_HW_SGPIO || gpio->nout_sgpio >MAX_NR_HW_SGPIO ) { +dev_err (&pdev->dev,"Number of GPIOs exceeds the maximum of %d: input: %d output: %d\n" , +MAX_NR_HW_SGPIO , nin_gpios, nout_gpios); +return -EINVAL ;
return dev_err_probe(...);
drivers/gpio/gpio-npcm-sgpio.c line 588
Quoted 6 lines
drivers/gpio/gpio-npcm-sgpio.c new file +6
-0+ } + + gpio->pclk =devm_clk_get (&pdev->dev,NULL ); +if (IS_ERR (gpio->pclk)) { +dev_err (&pdev->dev,"Could not get pclk\n" ); +return PTR_ERR (gpio->pclk);
Ditto.
Quoted 1 line
(quoted diff) +1
-0+ }
...
drivers/gpio/gpio-npcm-sgpio.c line 615
Quoted 2 lines
drivers/gpio/gpio-npcm-sgpio.c new file +2
-0+ rc =devm_gpiochip_add_data (&pdev->dev, &gpio->chip, gpio); +if (rc <0 )
Here and in the other cases, why ' < 0'? Does it have positive value to be returned in some cases?
Quoted 1 line
(quoted diff) +1
-0+ return rc;
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v9 3/3] gpio: nuvoton: Add Nuvoton NPCM sgpio driver
Hi Andy
Thanks for your comments.
I will modify it in the next version.
But some description as below
Quoted 10 lines
drivers/gpio/gpio-npcm-sgpio.c line 184
Quoted 7 lines
drivers/gpio/gpio-npcm-sgpio.c new file +7
-0+static int npcm_sgpio_init_port (struct npcm_sgpio *gpio) +{ +u8 in_port, out_port, set_port, reg; + + in_port =GPIO_BANK (gpio->nin_sgpio); +if (GPIO_BIT (gpio->nin_sgpio) >0 ) + in_port +=1 ;This is strange... So, you are telling that offsets start from 1 and not 0?
Quoted 6 lines
drivers/gpio/gpio-npcm-sgpio.c line 188
Quoted 3 lines
drivers/gpio/gpio-npcm-sgpio.c new file +3
-0+ out_port =GPIO_BANK (gpio->nout_sgpio); +if (GPIO_BIT (gpio->nout_sgpio) >0 ) + out_port +=1 ;Ditto.
Yes, if the customer has defined the in/out pins the offsets start from 1. The NPCM_IOXCFG2_PORT register is the set number of in/out ports. NPCM_IOXCFG2_PORT register define as below:
0~3 bit is the number of input ports
4~7 bit is the number of output ports
Each module can support 8 input ports and 8 output ports.
Quoted 8 lines
...
Quoted 1 line
+
set_port= ((out_port&NPCM_IOXCFG2_PORT) << 4) | (in_port&NPCM_IOXCFG2_PORT);Outer parentheses are redundant.
...
Best regards,
Jim
Re: [PATCH v9 3/3] gpio: nuvoton: Add Nuvoton NPCM sgpio driver
On Thu, Dec 21, 2023 at 02:27:13PM +0800, Jim Liu wrote:
...
Quoted 6 lines
Quoted 6 lines
drivers/gpio/gpio-npcm-sgpio.c line 184
Quoted 3 lines
drivers/gpio/gpio-npcm-sgpio.c new file +3
-0+ in_port =GPIO_BANK (gpio->nin_sgpio); +if (GPIO_BIT (gpio->nin_sgpio) >0 ) + in_port +=1 ;This is strange... So, you are telling that offsets start from 1 and not 0?
Quoted 7 lines
Quoted 6 lines
drivers/gpio/gpio-npcm-sgpio.c line 188
Quoted 3 lines
drivers/gpio/gpio-npcm-sgpio.c new file +3
-0+ out_port =GPIO_BANK (gpio->nout_sgpio); +if (GPIO_BIT (gpio->nout_sgpio) >0 ) + out_port +=1 ;Ditto.
Yes, if the customer has defined the in/out pins the offsets start from 1.
Why?
Quoted 5 lines
The
NPCM_IOXCFG2_PORTregister is the set number of in/out ports.NPCM_IOXCFG2_PORTregister define as below:
0~3 bit is the number of input ports
4~7 bit is the number of output ports
Each module can support 8 input ports and 8 output ports.
Right, this doesn't answer why.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v9 3/3] gpio: nuvoton: Add Nuvoton NPCM sgpio driver
In reply to Jim LiuHi Andy
Thanks for your reply.
The description as below
Quoted 10 lines
Quoted 10 lines
drivers/gpio/gpio-npcm-sgpio.c line 184
Quoted 3 lines
drivers/gpio/gpio-npcm-sgpio.c new file +3
-0+ in_port =GPIO_BANK (gpio->nin_sgpio); +if (GPIO_BIT (gpio->nin_sgpio) >0 ) + in_port +=1 ;This is strange... So, you are telling that offsets start from 1 and not 0?
Quoted 3 lines
drivers/gpio/gpio-npcm-sgpio.c new file +3
-0+ out_port =GPIO_BANK (gpio->nout_sgpio); +if (GPIO_BIT (gpio->nout_sgpio) >0 ) + out_port +=1 ;
Quoted 5 lines
Quoted 2 lines
Ditto.
Yes, if the customer has defined the in/out pins the offsets start from 1.
Why?
The NPCM_IOXCFG2_PORT default setting is to enable 0 input port and 0 output port.
The register default value is 0x0. Each port can support 8 pins. If the register value is 0x31 means enable 3 output ports and 1 input port. If customer has define nuvoton,input-ngpios or nuvoton,output-ngpios dts property
For example , nuvoton,output-ngpios = <9>
Quoted 1 line
Quoted 1 line
Quoted 1 line
+
out_port=GPIO_BANK(gpio->nout_sgpio);
The out_port value is 1 but one port only supports 8 pins.
Quoted 2 lines
Quoted 2 lines
drivers/gpio/gpio-npcm-sgpio.c line 188
Quoted 2 lines
drivers/gpio/gpio-npcm-sgpio.c new file +2
-0+if (GPIO_BIT (gpio->nout_sgpio) >0 ) + out_port +=1 ;
This out_port value is 2, the driver will enable two port to support 9 pins.
Maybe it is my expression error , the out_port and in_port default value is 0.
Quoted 5 lines
The
NPCM_IOXCFG2_PORTregister is the set number of in/out ports.NPCM_IOXCFG2_PORTregister define as below:
0~3 bit is the number of input ports
4~7 bit is the number of output ports
Each module can support 8 input ports and 8 output ports.
Best regards,
Jim