Add support for nuvoton ma35d1 pin control
Subsystems (5)
v7 cover Add support for nuvoton ma35d1 pin control
From: Jacky Huang <[email protected]>
This patch series adds the pin control and GPIO driver for the nuvoton ma35d1 ARMv8 SoC. It includes DT binding documentation and the ma35d1 pin control driver.
This pin control driver has been tested on the ma35d1 som board with Linux 6.9.0.
v7:
- Replace the magic numbers appearing in the driver with defined constants, or provide comments to explain them.
- Update the ma35_irq_irqtype()
- irq_set_handler_locked(d, handle_edge_irq) and irq_set_handler_locked(d, handle_level_irq)
- add case IRQ_TYPE_EDGE_BOTH
- Use handle_bad_irq for girq->handler, instead of handle_level_irq
v6:
- Remove DTS from this patchset. The DTS will be submitted in another patchset.
v5:
- Update the pinctrl driver header file pinctrl-ma35.h
- Include platform_device.h to fix compile issues.
v4:
- Update the pinctrl driver Kconfig
- Add depends to CONFIG_PINCTRL_MA35D1 to prevent compilation errors.
- Update the pinctrl driver
- Utilize devm_kcalloc() instead of devm_kzalloc().
- Employ ARRAY_SIZE() instead of sizeof()/sizeof().
v3:
- Update DTS and YAML files
- Corrected the unit address of nodes gpioa ~ gpion.
- Removed the invalid "pin-default" node.
- Removed the phandle entry from "nuvoton,pins".
- Update pinctrl driver
- Fixed the Kconfig by using "depend on" instead of "if".
- Removed unused #include of header files.
- Utilized immutable irq_chip instead of dynamic irq_chip.
- Replaced ma35_dt_free_map() with pinconf_generic_dt_free_map().
- Implemented other minor fixes as suggested by the reviewer.
v2:
- Update nuvoton,ma35d1-pinctrl.yaml
- Update the 'nuvoton,pins' to follow the style of rockchip pinctrl approch.
- Use power-source to indicate the pin voltage selection which follow the realtek pinctrl approch.
- Instead of integer, use drive-strength-microamp to specify the real driving strength capability of IO pins.
- Update ma35d1 pinctrl driver
- Add I/O drive strength lookup table for translating device tree setting into control register.
- Remove ma35d1-pinfunc.h which is unused after update definition of 'nuvoton,pins'.
Jacky Huang (3):
dt-bindings: reset: Add syscon to nuvoton ma35d1 system-management
node
dt-bindings: pinctrl: Document nuvoton ma35d1 pin control
pinctrl: nuvoton: Add ma35d1 pinctrl and GPIO driver
.../pinctrl/nuvoton,ma35d1-pinctrl.yaml | 163 ++ .../bindings/reset/nuvoton,ma35d1-reset.yaml | 3 +- drivers/pinctrl/nuvoton/Kconfig | 19 + drivers/pinctrl/nuvoton/Makefile | 2 + drivers/pinctrl/nuvoton/pinctrl-ma35.c | 1233 +++++++++++ drivers/pinctrl/nuvoton/pinctrl-ma35.h | 51 + drivers/pinctrl/nuvoton/pinctrl-ma35d1.c | 1797 +++++++++++++++++ 7 files changed, 3267 insertions(+), 1 deletion(-) create mode 100644 Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml create mode 100644 drivers/pinctrl/nuvoton/pinctrl-ma35.c create mode 100644 drivers/pinctrl/nuvoton/pinctrl-ma35.h create mode 100644 drivers/pinctrl/nuvoton/pinctrl-ma35d1.c
Signature · 1 line
2.34.1
PATCH v7 1/3 dt-bindings: reset: Add syscon to nuvoton ma35d1 system-management node
From: Jacky Huang <[email protected]>
Add a compatible 'syscon' to the system management node since the system control registers are mapped by this driver. The other driver must access the system control registers through 'regmap' using a phandle that references this node.
--- .../devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/reset/nuvoton,ma35d1-reset.yaml +2 -1
@@ -18,6 +18,7 @@ properties: compatible: items: - const: nuvoton,ma35d1-reset + - const: syscon reg: maxItems: 1
@@ -37,7 +38,7 @@ examples: - | system-management@40460000 { - compatible = "nuvoton,ma35d1-reset"; + compatible = "nuvoton,ma35d1-reset", "syscon"; reg = <0x40460000 0x200>; #reset-cells = <1>; };
Signature · 1 line
2.34.1
PATCH v7 2/3 dt-bindings: pinctrl: Document nuvoton ma35d1 pin control
In reply to Jacky HuangFrom: Jacky Huang <[email protected]>
Add documentation to describe nuvoton ma35d1 pin control and GPIO.
--- .../pinctrl/nuvoton,ma35d1-pinctrl.yaml | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +163 -0
@@ -0,0 +1,163 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pinctrl/nuvoton,ma35d1-pinctrl.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nuvoton MA35D1 pin control and GPIO + +maintainers: + - Shan-Chun Hung <[email protected]> + - Jacky Huang <[email protected]> + +allOf: + - $ref: pinctrl.yaml# + +properties: + compatible: + enum: + - nuvoton,ma35d1-pinctrl + + '#address-cells': + const: 1 + + '#size-cells': + const: 1 + + nuvoton,sys: + $ref: /schemas/types.yaml#/definitions/phandle + description: + phandle of the system-management node. + + ranges: true + +patternProperties: + "^gpio@[0-9a-f]+$": + type: object + additionalProperties: false + properties: + gpio-controller: true + + '#gpio-cells': + const: 2 + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + interrupt-controller: true + + '#interrupt-cells': + const: 2 + + interrupts: + description: + The interrupt outputs to sysirq. + maxItems: 1 + + required: + - gpio-controller + - '#gpio-cells' + - reg + - clocks + - interrupt-controller + - '#interrupt-cells' + - interrupts + + "^pin-[a-z0-9]+$": + type: object + description: + A pinctrl node should contain at least one subnodes representing the + pinctrl groups available on the machine. Each subnode will list the + pins it needs, and how they should be configured, with regard to muxer + configuration, pullups, drive strength, input enable/disable and input + schmitt. + + $ref: pincfg-node.yaml# + + properties: + power-source: + description: | + Valid arguments are described as below: + 0: power supply of 1.8V + 1: power supply of 3.3V + enum: [0, 1] + + drive-strength-microamp: + oneOf: + - enum: [ 2900, 4400, 5800, 7300, 8600, 10100, 11500, 13000 ] + description: 1.8V I/O driving strength + - enum: [ 17100, 25600, 34100, 42800, 48000, 56000, 77000, 82000 ] + description: 3.3V I/O driving strength + + unevaluatedProperties: false + + "-grp$": + type: object + description: + Pinctrl node's client devices use subnodes for desired pin configuration. + Client device subnodes use below standard properties. + properties: + nuvoton,pins: + description: + Each entry consists of 4 parameters and represents the mux and config + setting for one pin. + $ref: /schemas/types.yaml#/definitions/uint32-matrix + minItems: 1 + items: + items: + - minimum: 0 + maximum: 13 + description: + Pin bank. + - minimum: 0 + maximum: 15 + description: + Pin bank index. + - minimum: 0 + maximum: 15 + description: + Mux 0 means GPIO and mux 1 to 15 means the specific device function. + +required: + - compatible + - nuvoton,sys + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/gpio/gpio.h> + #include <dt-bindings/clock/nuvoton,ma35d1-clk.h> + + pinctrl@40040000 { + compatible = "nuvoton,ma35d1-pinctrl"; + #address-cells = <1>; + #size-cells = <1>; + nuvoton,sys = <&sys>; + ranges = <0 0x40040000 0xc00>; + + gpio@0 { + reg = <0x0 0x40>; + interrupts = <GIC_SPI 14 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clk GPA_GATE>; + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + + uart-grp { + uart11-pins { + nuvoton,pins = <11 0 2>, + <11 1 2>, + <11 2 2>, + <11 3 2>; + bias-disable; + power-source = <1>; + }; + }; + };
Signature · 1 line
2.34.1
Rob Herring
maintainerRe: [PATCH v7 2/3] dt-bindings: pinctrl: Document nuvoton ma35d1 pin control
Quoted 37 lines · Jacky Huang
From: Jacky Huang <[email protected]>
Add documentation to describe nuvoton ma35d1 pin control and GPIO.
Signed-off-by Jacky Huang <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>--- .../pinctrl/nuvoton,ma35d1-pinctrl.yaml | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yamlDocumentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +20
-0@@ -0,0 +1,163 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pinctrl/nuvoton,ma35d1-pinctrl.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nuvoton MA35D1 pin control and GPIO + +maintainers: + - Shan-Chun Hung <[email protected]> + - Jacky Huang <[email protected]> + +allOf: + - $ref: pinctrl.yaml# + +properties: + compatible: + enum: + - nuvoton,ma35d1-pinctrl +
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml line 30
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +10
-0+ '#address-cells': + const: 1 + + '#size-cells': + const: 1 + + nuvoton,sys: + $ref: /schemas/types.yaml#/definitions/phandle + description: + phandle of the system-management node.
If these are the *only* registers to access the pinctrl functions, then this binding should be a child node of the system-management node and then you don't need this property.
And if the registers for pinctrl are a defined range, you should add a 'reg' property (even though Linux and regmap don't use it).
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml line 32
Quoted 2 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +2
-0+ + ranges: true
This property makes no sense with the binding as-is. You don't have any address to translate. Maybe with the above changes it will.
Quoted 53 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +53
-0+ +patternProperties: + "^gpio@[0-9a-f]+$": + type: object + additionalProperties: false + properties: + gpio-controller: true + + '#gpio-cells': + const: 2 + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + interrupt-controller: true + + '#interrupt-cells': + const: 2 + + interrupts: + description: + The interrupt outputs to sysirq. + maxItems: 1 + + required: + - gpio-controller + - '#gpio-cells' + - reg + - clocks + - interrupt-controller + - '#interrupt-cells' + - interrupts + + "^pin-[a-z0-9]+$": + type: object + description: + A pinctrl node should contain at least one subnodes representing the + pinctrl groups available on the machine. Each subnode will list the + pins it needs, and how they should be configured, with regard to muxer + configuration, pullups, drive strength, input enable/disable and input + schmitt. + + $ref: pincfg-node.yaml# + + properties: + power-source: + description: | + Valid arguments are described as below: + 0: power supply of 1.8V + 1: power supply of 3.3V
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml line 95
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +10
-0+ enum: [0, 1] + + drive-strength-microamp: + oneOf: + - enum: [ 2900, 4400, 5800, 7300, 8600, 10100, 11500, 13000 ] + description: 1.8V I/O driving strength + - enum: [ 17100, 25600, 34100, 42800, 48000, 56000, 77000, 82000 ] + description: 3.3V I/O driving strength + + unevaluatedProperties: false
In the indented cases, it's preferred to put this before 'properties'.
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml line 101
Quoted 6 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +6
-0+ + "-grp$": + type: object + description: + Pinctrl node's client devices use subnodes for desired pin configuration. + Client device subnodes use below standard properties.
Missing $ref to common properties and 'unevaluatedProperties'.
Quoted 43 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +43
-0+ properties: + nuvoton,pins: + description: + Each entry consists of 4 parameters and represents the mux and config + setting for one pin. + $ref: /schemas/types.yaml#/definitions/uint32-matrix + minItems: 1 + items: + items: + - minimum: 0 + maximum: 13 + description: + Pin bank. + - minimum: 0 + maximum: 15 + description: + Pin bank index. + - minimum: 0 + maximum: 15 + description: + Mux 0 means GPIO and mux 1 to 15 means the specific device function. + +required: + - compatible + - nuvoton,sys + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/gpio/gpio.h> + #include <dt-bindings/clock/nuvoton,ma35d1-clk.h> + + pinctrl@40040000 { + compatible = "nuvoton,ma35d1-pinctrl"; + #address-cells = <1>; + #size-cells = <1>; + nuvoton,sys = <&sys>; + ranges = <0 0x40040000 0xc00>; + + gpio@0 { + reg = <0x0 0x40>;
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml line 154
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +10
-0+ interrupts = <GIC_SPI 14 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clk GPA_GATE>; + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + + uart-grp { + uart11-pins {
This is not what the schema says.
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml line 162
Quoted 8 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +8
-0+ nuvoton,pins = <11 0 2>, + <11 1 2>, + <11 2 2>, + <11 3 2>; + bias-disable; + power-source = <1>; + }; + };
Include a pin-* node in the example.
Quoted 4 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +1
-0+ };Signature · 1 line
2.34.1
Re: [PATCH v7 2/3] dt-bindings: pinctrl: Document nuvoton ma35d1 pin control
Dear Rob,
Thanks for your review.
Quoted 52 lines · Rob Herring
Quoted 37 lines · Jacky Huang
From: Jacky Huang <[email protected]>
Add documentation to describe nuvoton ma35d1 pin control and GPIO.
Signed-off-by Jacky Huang <[email protected]>Reviewed-by Krzysztof Kozlowski <[email protected]>--- .../pinctrl/nuvoton,ma35d1-pinctrl.yaml | 163 ++++++++++++++++++ 1 file changed, 163 insertions(+)create mode 100644
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yamlDocumentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +20
-0@@ -0,0 +1,163 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pinctrl/nuvoton,ma35d1-pinctrl.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nuvoton MA35D1 pin control and GPIO + +maintainers: + - Shan-Chun Hung <[email protected]> + - Jacky Huang <[email protected]> + +allOf: + - $ref: pinctrl.yaml# + +properties: + compatible: + enum: + - nuvoton,ma35d1-pinctrl +Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml line 30
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +10
-0+ '#address-cells': + const: 1 + + '#size-cells': + const: 1 + + nuvoton,sys: + $ref: /schemas/types.yaml#/definitions/phandle + description: + phandle of the system-management node.If these are the *only* registers to access the pinctrl functions, then this binding should be a child node of the system-management node and then you don't need this property.
Quoted 2 lines
And if the registers for pinctrl are a defined range, you should add a 'reg' property (even though Linux and regmap don't use it).
I will add a 'reg' property for this.
Quoted 4 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml line 32
Quoted 2 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +2
-0+ + ranges: trueThis property makes no sense with the binding as-is. You don't have any address to translate. Maybe with the above changes it will.
I will fix the
ranges = <0 0x40040000 0xc00>;
as
reg = <0 0x40040000 0xc00>;
ranges;
Quoted 56 lines
Quoted 56 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +56
-0+ +patternProperties: + "^gpio@[0-9a-f]+$": + type: object + additionalProperties: false + properties: + gpio-controller: true + + '#gpio-cells': + const: 2 + + reg: + maxItems: 1 + + clocks: + maxItems: 1 + + interrupt-controller: true + + '#interrupt-cells': + const: 2 + + interrupts: + description: + The interrupt outputs to sysirq. + maxItems: 1 + + required: + - gpio-controller + - '#gpio-cells' + - reg + - clocks + - interrupt-controller + - '#interrupt-cells' + - interrupts + + "^pin-[a-z0-9]+$": + type: object + description: + A pinctrl node should contain at least one subnodes representing the + pinctrl groups available on the machine. Each subnode will list the + pins it needs, and how they should be configured, with regard to muxer + configuration, pullups, drive strength, input enable/disable and input + schmitt. + + $ref: pincfg-node.yaml# + + properties: + power-source: + description: | + Valid arguments are described as below: + 0: power supply of 1.8V + 1: power supply of 3.3V + enum: [0, 1] + + drive-strength-microamp:
Quoted 9 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml line 95
Quoted 7 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +7
-0+ oneOf: + - enum: [ 2900, 4400, 5800, 7300, 8600, 10100, 11500, 13000 ] + description: 1.8V I/O driving strength + - enum: [ 17100, 25600, 34100, 42800, 48000, 56000, 77000, 82000 ] + description: 3.3V I/O driving strength + + unevaluatedProperties: falseIn the indented cases, it's preferred to put this before 'properties'.
I will fix it.
Quoted 7 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml line 101
Quoted 6 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +6
-0+ + "-grp$": + type: object + description: + Pinctrl node's client devices use subnodes for desired pin configuration. + Client device subnodes use below standard properties.Missing $ref to common properties and 'unevaluatedProperties'.
I will fix it.
Quoted 62 lines
Quoted 43 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +43
-0+ properties: + nuvoton,pins: + description: + Each entry consists of 4 parameters and represents the mux and config + setting for one pin. + $ref: /schemas/types.yaml#/definitions/uint32-matrix + minItems: 1 + items: + items: + - minimum: 0 + maximum: 13 + description: + Pin bank. + - minimum: 0 + maximum: 15 + description: + Pin bank index. + - minimum: 0 + maximum: 15 + description: + Mux 0 means GPIO and mux 1 to 15 means the specific device function. + +required: + - compatible + - nuvoton,sys + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + #include <dt-bindings/gpio/gpio.h> + #include <dt-bindings/clock/nuvoton,ma35d1-clk.h> + + pinctrl@40040000 { + compatible = "nuvoton,ma35d1-pinctrl"; + #address-cells = <1>; + #size-cells = <1>; + nuvoton,sys = <&sys>; + ranges = <0 0x40040000 0xc00>; + + gpio@0 { + reg = <0x0 0x40>;Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml line 154
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +10
-0+ interrupts = <GIC_SPI 14 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clk GPA_GATE>; + gpio-controller; + #gpio-cells = <2>; + interrupt-controller; + #interrupt-cells = <2>; + }; + + uart-grp { + uart11-pins {This is not what the schema says.
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml line 162
Quoted 8 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +8
-0+ nuvoton,pins = <11 0 2>, + <11 1 2>, + <11 2 2>, + <11 3 2>; + bias-disable; + power-source = <1>; + }; + };
Quoted 1 line
Include a pin-* node in the example.
This is my mistake. "pin-*" was the naming convention used in previous versions, which has now been changed to "-pins". Additionally, its hierarchy should be under "-grp". I will make corrections for these two issues.
Quoted 4 lines
Quoted 4 lines
Documentation/devicetree/bindings/pinctrl/nuvoton,ma35d1-pinctrl.yaml new file +1
-0+ };Signature · 1 line
2.34.1
Best Regards,
Jacky Huang
PATCH v7 3/3 pinctrl: nuvoton: Add ma35d1 pinctrl and GPIO driver
In reply to Jacky HuangFrom: Jacky Huang <[email protected]>
Add common pinctrl and GPIO driver for Nuvoton MA35 series SoC, and add support for ma35d1 pinctrl.
--- drivers/pinctrl/nuvoton/Kconfig | 19 + drivers/pinctrl/nuvoton/Makefile | 2 + drivers/pinctrl/nuvoton/pinctrl-ma35.c | 1233 +++++++++++++++ drivers/pinctrl/nuvoton/pinctrl-ma35.h | 51 + drivers/pinctrl/nuvoton/pinctrl-ma35d1.c | 1797 ++++++++++++++++++++++ 5 files changed, 3102 insertions(+) create mode 100644 drivers/pinctrl/nuvoton/pinctrl-ma35.c create mode 100644 drivers/pinctrl/nuvoton/pinctrl-ma35.h create mode 100644 drivers/pinctrl/nuvoton/pinctrl-ma35d1.c
drivers/pinctrl/nuvoton/Kconfig +19 -0
@@ -45,3 +45,22 @@ config PINCTRL_NPCM8XX Say Y or M here to enable pin controller and GPIO support for the Nuvoton NPCM8XX SoC. This is strongly recommended when building a kernel that will run on this chip. + +config PINCTRL_MA35 + bool + depends on (ARCH_MA35 || COMPILE_TEST) && OF + select GENERIC_PINCTRL_GROUPS + select GENERIC_PINMUX_FUNCTIONS + select GENERIC_PINCONF + select GPIOLIB + select GPIO_GENERIC + select GPIOLIB_IRQCHIP + select MFD_SYSCON + +config PINCTRL_MA35D1 + bool "Pinctrl and GPIO driver for Nuvoton MA35D1" + depends on (ARCH_MA35 || COMPILE_TEST) && OF + select PINCTRL_MA35 + help + Say Y here to enable pin controller and GPIO support + for Nuvoton MA35D1 SoC.
drivers/pinctrl/nuvoton/Makefile +2 -0
@@ -4,3 +4,5 @@ obj-$(CONFIG_PINCTRL_WPCM450) += pinctrl-wpcm450.o obj-$(CONFIG_PINCTRL_NPCM7XX) += pinctrl-npcm7xx.o obj-$(CONFIG_PINCTRL_NPCM8XX) += pinctrl-npcm8xx.o +obj-$(CONFIG_PINCTRL_MA35) += pinctrl-ma35.o +obj-$(CONFIG_PINCTRL_MA35D1) += pinctrl-ma35d1.o
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +1233 -0
1,233 lines not on this page · raw message
drivers/pinctrl/nuvoton/pinctrl-ma35.h new file +51 -0
51 lines not on this page · raw message
drivers/pinctrl/nuvoton/pinctrl-ma35d1.c new file +1797 -0
1,689 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.34.1
Part of the diff is not shown here. View the raw message.
Re: [PATCH v7 3/3] pinctrl: nuvoton: Add ma35d1 pinctrl and GPIO driver
Tue, Apr 09, 2024 at 09:56:37AM +0000, Jacky Huang kirjoitti:
Quoted 4 lines
From: Jacky Huang <[email protected]>
Add common pinctrl and GPIO driver for Nuvoton MA35 series SoC, and add support for ma35d1 pinctrl.
...
Quoted 1 line
+ * Copyright (C) 2023 Nuvoton Technology Corp.
Almos mid of 2024...
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 14
Quoted 6 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +6
-0+#include <linux/gpio/driver.h> +#include <linux/mfd/syscon.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_device.h> +#include <linux/of_address.h>
Do you really need all of these pf*.h?
Don't you miss other headers to be included (spoiler: a lot!)
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 16
Quoted 2 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +2
-0+#include <linux/pinctrl/pinconf.h> +#include <linux/pinctrl/pinctrl.h>
Move this group...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 19
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+#include <linux/platform_device.h> +#include <linux/regmap.h> +
...to be here to show the relation to the pin control subsystem.
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+#include "../core.h" +#include "../pinconf.h" +#include "pinctrl-ma35.h"
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 55
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+#define MA35_GP_MODE_MASK_WIDTH 2 + +#define MA35_GP_SLEWCTL_MASK_WIDTH 2
I looked at the code how you use these... Oh, please switch to FIELD_GET() / FIELD_PREP() (don't forget to include bitfield.h)
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 87
Quoted 5 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +5
-0+struct ma35_pin_func { +const char *name; +const char **groups; +u32 ngroups; +};
NIH struct pinfunction.
You may still have a wrapper (as struct pingroup below most likely will be embedded in your custom data type), see the pinctrl-intel.h examples.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 100
Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+struct ma35_pin_group { +const char *name; +unsigned int npins; +unsigned int *pins;
NIH struct pingroup.
Quoted 2 lines
(quoted diff) +2
-0+ struct ma35_pin_setting *settings; +};
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 110
Quoted 7 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +7
-0+struct ma35_pin_bank { +void __iomem *reg_base; +struct clk *clk; +int irq; +u8 nr_pins; +const char *name; +u8 bank_num;
Interleaved fields with such a different type may lead to waste of memory. Run pahole and update the ordering in this struct accordingly.
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 112
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +2
-0+bool valid; +struct device_node *np;
Can you keep it fwnode-based?
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 118
Quoted 7 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +6
-0+struct gpio_chip chip; +u32 irqtype; +u32 irqinten; +struct regmap *regmap; +struct device *dev; +spinlock_t lock;
No use in RT_PREEMPT?
Quoted 1 line
+};
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 211
Quoted 10 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +10
-0+ new_map =devm_kcalloc (pctldev->dev, map_num,sizeof (*new_map),GFP_KERNEL ); +if (!new_map) +return -ENOMEM ; + + *map = new_map; + *num_maps = map_num; +/* create mux map */ + parent =of_get_parent (np); +if (!parent) { +devm_kfree (pctldev->dev, new_map);
Huh?! Are you sure you know the scope of usage of devm_*()?
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+return -EINVAL ; + } +
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 283
Quoted 2 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +2
-0+ regval &= ~GENMASK (setting->shift +MA35_MFP_BITS_PER_PORT -1 , + setting->shift);
This will generate an awful code. Use respective FIELD_*() macros.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 305
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+ regval &= ~GENMASK (gpio *MA35_GP_MODE_MASK_WIDTH -1 , + gpio *MA35_GP_MODE_MASK_WIDTH ); + regval |= mode << gpio *MA35_GP_MODE_MASK_WIDTH ;
Ditto.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 317
Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+ regval &=GENMASK (gpio *MA35_GP_MODE_MASK_WIDTH -1 , + gpio *MA35_GP_MODE_MASK_WIDTH ); + +return regval >> gpio *MA35_GP_MODE_MASK_WIDTH ;
Ditto.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 326
Quoted 7 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +7
-0+static int ma35_gpio_core_direction_in (struct gpio_chip *gc,unsigned int gpio) +{ +struct ma35_pin_bank *bank =gpiochip_get_data (gc); +void __iomem *reg_mode = bank->reg_base +MA35_GP_REG_MODE ; +unsigned long flags; + +spin_lock_irqsave (&bank->lock, flags);
Use cleanup.h, i.e. guard() in this case, from day 1. Similar approach for all other places.
Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+spin_unlock_irqrestore (&bank->lock, flags); + +return 0 ; +}
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 349
Quoted 5 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +5
-0+ regval =readl (reg_dout); +if (val) +writel (regval |BIT (gpio), reg_dout); +else +writel (regval & ~BIT (gpio), reg_dout);
Can you split regval update and make only a single writel() call? It's slightly better pattern
read() if (foo) v = else v = write()
Quoted 1 line
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +1
-0+ma35_gpio_set_mode (reg_mode, gpio,MA35_GP_MODE_OUTPUT );
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 389
Quoted 1 line
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +1
-0+ regval &= ~GENMASK (bit_offs +MA35_MFP_BITS_PER_PORT -1 , bit_offs);
FIELD_GET()
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 401
Quoted 1 line
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +1
-0+writel (1 <<num, reg_intsrc);
Oh, something happened here, besides indentation.
Have you meant BIT() ?
...
Review
Quoted 1 line
(quoted diff) +1
-0+ unsigned int num = (d->hwirq);
Read Documentation on how to access hwirq field and what type of the value should be. There are plently of the examples already in the kernel. Just check the recent (more or less) ones.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 418
Quoted 6 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +6
-0+/* +* The MA35_GP_REG_INTEN bits 0 ~ 15 control low-level or falling edge trigger, +* while bits 16 ~ 31 control high-level or rising edge trigger. +* We disable both type of interrupt. +*/ + regval &= ~(BIT (num +16 ) |BIT (num));
You have this idiom more than once in the code, make the definition and use it. Move comment closer to that definition.
...
Quoted 7 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +7
-0+irq_set_handler_locked (d, handle_edge_irq); + bank->irqtype &= ~(0x1 << num); + bank->irqinten |= (0x1 << num); + bank->irqinten &= ~(0x1 << (num +16 )); +break ; +case IRQ_TYPE_LEVEL_HIGH : +irq_set_handler_locked (d, handle_level_irq);
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 479
Quoted 10 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +10
-0+ bank->irqtype |= (0x1 << num); + bank->irqinten &= ~(0x1 << num); + bank->irqinten |= (0x1 << (num +16 )); +break ; +case IRQ_TYPE_LEVEL_LOW : +irq_set_handler_locked (d, handle_level_irq); + bank->irqtype |= (0x1 << num); + bank->irqinten &= ~(0x1 << (num +16 )); + bank->irqinten |= (0x1 << num); +break ;
BIT() in all cases.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 481
Quoted 1 line
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +1
-0+irq_set_handler_locked (d, handle_bad_irq);
Just assign it in the probe.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 499
Quoted 9 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +9
-0+static struct irq_chip ma35_gpio_irqchip = { + .name ="MA35-GPIO-IRQ" , + .irq_disable = ma35_irq_gpio_mask, + .irq_enable = ma35_irq_gpio_unmask, + .irq_ack = ma35_irq_gpio_ack, + .irq_mask = ma35_irq_gpio_mask, + .irq_unmask = ma35_irq_gpio_unmask, + .irq_set_type = ma35_irq_irqtype, + .flags =IRQCHIP_MASK_ON_SUSPEND |IRQCHIP_SKIP_SET_WAKE |IRQCHIP_IMMUTABLE ,
It doesn't look like IMMUTABLE. Again, check other examples, there are a lot.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 514
Quoted 12 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +11
-0+static void ma35_irq_demux_intgroup (struct irq_desc *desc) +{ +struct ma35_pin_bank *bank =gpiochip_get_data (irq_desc_get_handler_data (desc)); +struct irq_domain *irqdomain = bank->chip.irq.domain; +struct irq_chip *irqchip =irq_desc_get_chip (desc); +unsigned long isr; +int offset; + +chained_irq_enter (irqchip, desc); + isr =readl (bank->reg_base +MA35_GP_REG_INTSRC ); +if (isr)
Unneeded duplicate check.
Quoted 5 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +5
-0+for_each_set_bit (offset, &isr, bank->nr_pins) +generic_handle_irq (irq_find_mapping (irqdomain, offset)); + +chained_irq_exit (irqchip, desc); +}
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 528
Quoted 1 line
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +1
-0+for (i =0 ; i < ctrl->nr_banks; ++i, ++bank) {
Why pre-increments?
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 531
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+if (!bank->valid) { +dev_warn (&pdev->dev,"bank %s is not valid\n" , + bank->np->name);
Do not use fwnode / of_node name like this, use proper specifiers: %pfw / %pOF.
Quoted 16 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +16
-0+continue ; + } + bank->irqtype =0 ; + bank->irqinten =0 ; + bank->chip.label = bank->name; + bank->chip.of_gpio_n_cells =2 ; + bank->chip.parent = &pdev->dev; + bank->chip.request = ma35_gpio_core_to_request; + bank->chip.direction_input = ma35_gpio_core_direction_in; + bank->chip.direction_output = ma35_gpio_core_direction_out; + bank->chip.get = ma35_gpio_core_get; + bank->chip.set = ma35_gpio_core_set; + bank->chip.base =-1 ; + bank->chip.ngpio = bank->nr_pins; + bank->chip.can_sleep = false; +spin_lock_init (&bank->lock);
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 557
Quoted 10 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +10
-0+ +if (bank->irq >0 ) { +struct gpio_irq_chip *girq; + + girq = &bank->chip.irq; +gpio_irq_chip_set_chip (girq, &ma35_gpio_irqchip); + girq->parent_handler = ma35_irq_demux_intgroup; + girq->num_parents =1 ; + + girq->parents = devm_kcalloc(&pdev->dev, 1, sizeof(*girq->parents),
Use num_parents instead of 1.
Quoted 18 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +18
-0+ GFP_KERNEL); +if (!girq->parents) { + ret = -ENOMEM ; + goto fail; + } + + girq->parents[0 ] = bank->irq; + girq->default_type =IRQ_TYPE_NONE ; + girq->handler = handle_bad_irq; + } + + ret =gpiochip_add_data (&bank->chip, bank); +if (ret) { +dev_err (&pdev->dev,"failed to register gpio_chip %s, error code: %d\n" , + bank->chip.label, ret); + goto fail; + } + }
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 579
Quoted 2 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +2
-0+fail: +for (--i, --bank; i >=0 ; --i, --bank) {
while (i--) {
bank--;
...
}much better to read.
Quoted 6 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +6
-0+if (!bank->valid) +continue ; +gpiochip_remove (&bank->chip); + } +return ret; +}
...
Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+static int ma35_get_bank_data (struct ma35_pin_bank *bank,struct ma35_pinctrl *npctl) +{ +struct resource res; +
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 600
Quoted 10 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +10
-0+if (of_address_to_resource (bank->np,0 , &res)) { +dev_err (npctl->dev,"cannot find IO resource for bank\n" ); +return -ENOENT ; + } + + bank->reg_base =devm_ioremap_resource (npctl->dev, &res); +if (IS_ERR (bank->reg_base)) { +dev_err (npctl->dev,"cannot ioremap resource for bank\n" ); +return PTR_ERR (bank->reg_base); + }
Use fwnode_iomap()
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 602
Quoted 1 line
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +1
-0+ bank->irq =irq_of_parse_and_map (bank->np,0 );
Use fwnode_get_irq()
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 605
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+ bank->nr_pins =MA35_GPIO_PORT_MAX ; + + bank->clk =of_clk_get (bank->np,0 );
Can't you use simple clk_get()? Why?
Quoted 5 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +5
-0+if (IS_ERR (bank->clk)) +return PTR_ERR (bank->clk); + +return clk_prepare_enable (bank->clk); +}
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 633
Quoted 2 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +2
-0+for_each_gpiochip_node (&pdev->dev, child) { +struct device_node *np =to_of_node (child);
No need, just keep everythin fwnode based.
Quoted 8 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +8
-0+ bank = &ctrl->pin_banks[id]; + bank->np = np; + bank->regmap = pctl->regmap; + bank->dev = &pdev->dev; +if (!ma35_get_bank_data (bank, pctl)) + bank->valid = true; + id++; + }
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ regval &= ~GENMASK(port * MA35_GP_PUSEL_MASK_WIDTH - 1, + port * MA35_GP_PUSEL_MASK_WIDTH);
FIELD_*()
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 717
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+ regval &=GENMASK (port *MA35_GP_PUSEL_MASK_WIDTH -1 , + port *MA35_GP_PUSEL_MASK_WIDTH ); + regval >>= port *MA35_GP_PUSEL_MASK_WIDTH ;
Ditto.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 760
Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+if (regval &BIT (port)) +return MVOLT_3300 ; +else +return MVOLT_1800 ;
Can be written as
return (regval & BIT()) ? _3300 : _1800;
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 805
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+if (port <MA35_GP_DSH_BASE_PORT ) { + regval =readl (base +MA35_GP_REG_DSL ); + ds_val = (regval &GENMASK (port *4 +2 , port *4 )) >> port *4 ;
This is too complicated way of saying
ds_val = (regval >> port * 4) & GENMASK(2, 0);
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 809
Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+ }else { + port -=MA35_GP_DSH_BASE_PORT ; + regval =readl (base +MA35_GP_REG_DSH ); + ds_val = (regval &GENMASK (port *4 +2 , port *4 )) >> port *4 ;
Ditto.
Quoted 1 line
(quoted diff) +1
-0+ }
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 831
Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+if (ma35_pinconf_get_power_source (npctl, pin) ==MVOLT_1800 ) { +for (i =0 ; i <ARRAY_SIZE (ds_1800mv_tbl); i++) { +if (ds_1800mv_tbl[i] == strength) + ds_val = i;
And still continue?!
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 836
Quoted 5 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +5
-0+ } + }else { +for (i =0 ; i <ARRAY_SIZE (ds_3300mv_tbl); i++) { +if (ds_3300mv_tbl[i] == strength) + ds_val = i;
Ditto.
Review
Quoted 2 lines
(quoted diff) +2
-0+ } + }
Wondering if the linear_ranges or other existing tables approaches can be used here.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 848
Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+if (port <MA35_GP_DSH_BASE_PORT ) { + regval =readl (base +MA35_GP_REG_DSL ); + regval &= ~GENMASK (port *4 +2 , port *4 ); + regval |= ds_val << port *4 ;
As per above
~(GENMASK(2, 0) << (port * 4))
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 853
Quoted 5 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +5
-0+writel (regval, base +MA35_GP_REG_DSL ); + }else { + port -=MA35_GP_DSH_BASE_PORT ; + regval =readl (base +MA35_GP_REG_DSH ); + regval &= ~GENMASK (port *4 +2 , port *4 );
Ditto.
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+ regval |= ds_val << port *4 ; +writel (regval, base +MA35_GP_REG_DSH ); + }
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 923
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+ regval &= ~GENMASK (port *MA35_GP_SLEWCTL_MASK_WIDTH -1 , + port *MA35_GP_SLEWCTL_MASK_WIDTH ); + regval |= rate << port *MA35_GP_SLEWCTL_MASK_WIDTH ;
FIELD_*()
...
Quoted 7 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +7
-0+static int ma35_pinconf_get (struct pinctrl_dev *pctldev,unsigned int pin,unsigned long *config) +{ +struct ma35_pinctrl *npctl =pinctrl_dev_get_drvdata (pctldev); +enum pin_config_param param =pinconf_to_config_param (*config); +u32 arg; +int ret; +
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 944
Quoted 10 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +9
-0+switch (param) { +case PIN_CONFIG_BIAS_DISABLE : +case PIN_CONFIG_BIAS_PULL_DOWN : +case PIN_CONFIG_BIAS_PULL_UP : +if (ma35_pinconf_get_pull (npctl, pin) == param) + arg =1 ; +else +return -EINVAL ; +break ;
Check for the error case first and get rid of redundant 'else'.
Quoted 29 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +29
-0+case PIN_CONFIG_DRIVE_STRENGTH : + ret =ma35_pinconf_get_drive_strength (npctl, pin, &arg); +if (ret) +return ret; +break ; + +case PIN_CONFIG_INPUT_SCHMITT_ENABLE : + arg =ma35_pinconf_get_schmitt_enable (npctl, pin); +break ; + +case PIN_CONFIG_SLEW_RATE : + arg =ma35_pinconf_get_slew_rate (npctl, pin); +break ; + +case PIN_CONFIG_OUTPUT_ENABLE : + arg =ma35_pinconf_get_output (npctl, pin); +break ; + +case PIN_CONFIG_POWER_SOURCE : + arg =ma35_pinconf_get_power_source (npctl, pin); +break ; + +default : +return -EINVAL ; + } + *config =pinconf_to_config_packed (param, arg); + +return 0 ; +}
...
Quoted 36 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +36
-0+static int ma35_pinconf_set (struct pinctrl_dev *pctldev,unsigned int pin, +unsigned long *configs,unsigned int num_configs) +{ +struct ma35_pinctrl *npctl =pinctrl_dev_get_drvdata (pctldev); +enum pin_config_param param; +unsigned int arg =0 ; +int i, ret =0 ; + +for (i =0 ; i < num_configs; i++) { + param =pinconf_to_config_param (configs[i]); + arg =pinconf_to_config_argument (configs[i]); + +switch (param) { +case PIN_CONFIG_BIAS_DISABLE : +case PIN_CONFIG_BIAS_PULL_UP : +case PIN_CONFIG_BIAS_PULL_DOWN : + ret =ma35_pinconf_set_pull (npctl, pin, param); +break ; + +case PIN_CONFIG_DRIVE_STRENGTH : + ret =ma35_pinconf_set_drive_strength (npctl, pin, arg); +break ; + +case PIN_CONFIG_INPUT_SCHMITT_ENABLE : + ret =ma35_pinconf_set_schmitt (npctl, pin,1 ); +break ; + +case PIN_CONFIG_INPUT_SCHMITT : + ret =ma35_pinconf_set_schmitt (npctl, pin, arg); +break ; + +case PIN_CONFIG_SLEW_RATE : + ret =ma35_pinconf_set_slew_rate (npctl, pin, arg); +break ; + +case PIN_CONFIG_OUTPUT_ENABLE :
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 1021
Quoted 10 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +10
-0+ ret =ma35_pinconf_set_output (npctl, pin, arg); +break ; + +case PIN_CONFIG_POWER_SOURCE : + ret =ma35_pinconf_set_power_source (npctl, pin, arg); +break ; + +default : +return -EINVAL ; + }
No returning an error if we got ret != 0?!
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+ } +return ret; +}
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 1038
Quoted 8 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +7
-0+static int ma35_pinctrl_parse_groups (struct device_node *np,struct ma35_pin_group *grp, +struct ma35_pinctrl *npctl,u32 index) +{ +unsigned long *configs; +unsigned int nconfigs; +struct ma35_pin_setting *pin; +const __be32 *list;
Huh?!
Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+int i, j, size, ret; + +dev_dbg (npctl->dev,"group(%d): %s\n" , index, np->name); +
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 1052
Quoted 10 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +10
-0+ grp->name = np->name; + + ret =pinconf_generic_parse_dt_config (np,NULL , &configs, &nconfigs); +if (ret) +return ret; + +/* +* the binding format is nuvoton,pins = <bank pin-mfp pin-function>, +* do sanity check and calculate pins number +*/
/*
* Respect English grammar and puntuation
* in all multi-line comments. See the difference
* how it's done above and in this example.
*/
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 1053
Quoted 1 line
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +1
-0+ list =of_get_property (np,"nuvoton,pins" , &size);
Oh, no.
Use respective of_property_ calls.
Quoted 28 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +28
-0+ size /=sizeof (*list); +if (!size || size %3 ) { +dev_err (npctl->dev,"wrong setting!\n" ); +return -EINVAL ; + } + grp->npins = size /3 ; + + grp->pins =devm_kcalloc (npctl->dev, grp->npins,sizeof (*grp->pins),GFP_KERNEL ); +if (!grp->pins) +return -ENOMEM ; + + grp->settings =devm_kcalloc (npctl->dev, grp->npins,sizeof (*grp->settings),GFP_KERNEL ); +if (!grp->settings) +return -ENOMEM ; + + pin = grp->settings; + +for (i =0 , j =0 ; i < size; i +=3 , j++) { + pin->offset =be32_to_cpu (*list++) *MA35_MFP_REG_SZ_PER_BANK +MA35_MFP_REG_BASE ; + pin->shift = (be32_to_cpu (*list++) *MA35_MFP_BITS_PER_PORT ) %32 ; + pin->muxval =be32_to_cpu (*list++); + pin->configs = configs; + pin->nconfigs = nconfigs; + grp->pins[j] = npctl->info->get_pin_num (pin->offset, pin->shift); + pin++; + } +return 0 ; +}
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 1129
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+for_each_child_of_node (np, child) { +if (of_property_read_bool (child,"gpio-controller" )) +continue ;
There is a macro already present, for_each_gpiochip_node().
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+ npctl->nfunctions++; + npctl->ngroups +=of_get_child_count (child); + }
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 1129
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+for_each_child_of_node (np, child) { +if (of_property_read_bool (child,"gpio-controller" )) +continue ;
Ditto.
Quoted 7 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +7
-0+ ret =ma35_pinctrl_parse_functions (child, npctl, idx++); +if (ret) { +dev_err (&pdev->dev,"failed to parse function\n" ); +of_node_put (child); +return ret; + } + }
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 1170
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+if (!info || !info->pins || !info->npins) { +dev_err (&pdev->dev,"wrong pinctrl info\n" ); +return -EINVAL ;
return dev_err_probe(...);
Quoted 1 line
(quoted diff) +1
-0+ }
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 1210
Quoted 2 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +2
-0+ ret =devm_pinctrl_register_and_init (&pdev->dev, ma35_pinctrl_desc, + npctl, &npctl->pctl);
Haveing
struct device *dev = &pdev->dev;
makes in particular this one better
ret = devm_pinctrl_register_and_init(dev, ma35_pinctrl_desc, npctl, &npctl->pctl);
Quoted 2 lines
(quoted diff) +2
-0+ if (ret) + return dev_err_probe(&pdev->dev, ret, "fail to register MA35 pinctrl\n");
...
Quoted 1 line
+int
__maybe_unusedma35_pinctrl_suspend(struct device *dev)
No __maybe_unused.
Just use respective PM macros (pm_ptr(), DEFINE_,*PM_OPS, etc).
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 1228
Quoted 7 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +7
-0+{ +struct ma35_pinctrl *npctl =dev_get_drvdata (dev); + +return pinctrl_force_sleep (npctl->pctl); +} + +int __maybe_unused ma35_pinctrl_resume (struct device *dev)
Ditto.
Quoted 5 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +5
-0+{ +struct ma35_pinctrl *npctl =dev_get_drvdata (dev); + +return pinctrl_force_default (npctl->pctl); +}
...
drivers/pinctrl/nuvoton/pinctrl-ma35.h line 23
Quoted 10 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.h new file +10
-0+struct ma35_mux_desc { +const char *name; +u32 muxval; +}; + +struct ma35_pin_data { +u32 offset; +u32 shift; +struct ma35_mux_desc *muxes; +};
Don't pin control subsystem has already some data types suitable in this cases?
...
drivers/pinctrl/nuvoton/pinctrl-ma35.h line 33
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.h new file +3
-0+#define MA35_PIN (num, n, o, s, ...) { \ + .number = num, \ + .name = #n, \
Don't we have macros for this?
Quoted 7 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.h new file +7
-0+ .drv_data = &(struct ma35_pin_data) { \ + .offset = o, \ + .shift = s, \ + .muxes = (struct ma35_mux_desc []) { \ + __VA_ARGS__, { } }, \ + }, \ +}
...
drivers/pinctrl/nuvoton/pinctrl-ma35d1.c line 9
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35d1.c new file +3
-0+#include <linux/init.h> +#include <linux/io.h> +#include <linux/module.h>
Missing headers and stray ones. Please, get this into order by following IWYU principle.
Review
Quoted 2 lines
(quoted diff) +2
-0+#include <linux/of.h> +#include <linux/of_device.h>
How are these being used?
Quoted 1 line
+#include <
linux/pinctrl/pinctrl.h>
...
drivers/pinctrl/nuvoton/pinctrl-ma35d1.c line 1768
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35d1.c new file +3
-0+static const struct dev_pm_ops ma35d1_pinctrl_pm_ops = { +SET_LATE_SYSTEM_SLEEP_PM_OPS (ma35_pinctrl_suspend, ma35_pinctrl_resume) +};
New PM macros, please.
...
drivers/pinctrl/nuvoton/pinctrl-ma35d1.c line 1777
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35d1.c new file +3
-0+static const struct of_device_id ma35d1_pinctrl_of_match[] = { + { .compatible ="nuvoton,ma35d1-pinctrl" , }, + { },
No comma in the terminator entry.
Quoted 1 line
+};
...
drivers/pinctrl/nuvoton/pinctrl-ma35d1.c line 1784
Quoted 5 lines
drivers/pinctrl/nuvoton/pinctrl-ma35d1.c new file +5
-0+static struct platform_driver ma35d1_pinctrl_driver = { + .probe = ma35d1_pinctrl_probe, + .driver = { + .name ="ma35d1-pinctrl" , + .pm = &ma35d1_pinctrl_pm_ops,
New PM macro here.
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35d1.c new file +3
-0+ .of_match_table = ma35d1_pinctrl_of_match, + }, +};
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v7 3/3] pinctrl: nuvoton: Add ma35d1 pinctrl and GPIO driver
Dear Andy,
Sorry for the late response to your mail.
Due to email inbox policy issues, I just found this email. Regarding your comments, I will make all the modifications in the next version. Thank you for your help.
Best Regards,
Jacky Huang
Quoted 759 lines · Andy Shevchenko
CAUTION - External Email: Do not click links or open attachments unless you acknowledge the sender and content.
Tue, Apr 09, 2024 at 09:56:37AM +0000, Jacky Huang kirjoitti:
Quoted 4 lines
From: Jacky Huang <[email protected]>
Add common pinctrl and GPIO driver for Nuvoton MA35 series SoC, and add support for ma35d1 pinctrl.
...
Quoted 1 line
+ * Copyright (C) 2023 Nuvoton Technology Corp.
Almos mid of 2024...
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 14
Quoted 6 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +6
-0+#include <linux/gpio/driver.h> +#include <linux/mfd/syscon.h> +#include <linux/of.h> +#include <linux/of_irq.h> +#include <linux/of_device.h> +#include <linux/of_address.h> Do you really need all of these pf*.h?
Don't you miss other headers to be included (spoiler: a lot!)drivers/pinctrl/nuvoton/pinctrl-ma35.c line 16
Quoted 2 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +2
-0+#include <linux/pinctrl/pinconf.h> +#include <linux/pinctrl/pinctrl.h> Move this group...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 19
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+#include <linux/platform_device.h> +#include <linux/regmap.h> +...to be here to show the relation to the pin control subsystem.
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+#include "../core.h" +#include "../pinconf.h" +#include "pinctrl-ma35.h" ...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 55
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+#define MA35_GP_MODE_MASK_WIDTH 2 + +#define MA35_GP_SLEWCTL_MASK_WIDTH 2I looked at the code how you use these... Oh, please switch to
FIELD_GET()/FIELD_PREP()(don't forget to includebitfield.h)...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 87
Quoted 5 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +5
-0+struct ma35_pin_func { +const char *name; +const char **groups; +u32 ngroups; +};NIH struct pinfunction.
You may still have a wrapper (as struct pingroup below most likely will be embedded in your custom data type), see the
pinctrl-intel.hexamples....
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 100
Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+struct ma35_pin_group { +const char *name; +unsigned int npins; +unsigned int *pins;NIH struct pingroup.
Quoted 2 lines
(quoted diff) +2
-0+ struct ma35_pin_setting *settings; +};...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 110
Quoted 7 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +7
-0+struct ma35_pin_bank { +void __iomem *reg_base; +struct clk *clk; +int irq; +u8 nr_pins; +const char *name; +u8 bank_num;Interleaved fields with such a different type may lead to waste of memory. Run
paholeand update the ordering in this struct accordingly.drivers/pinctrl/nuvoton/pinctrl-ma35.c line 112
Quoted 2 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +2
-0+bool valid; +struct device_node *np;Can you keep it fwnode-based?
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 118
Quoted 6 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +6
-0+struct gpio_chip chip; +u32 irqtype; +u32 irqinten; +struct regmap *regmap; +struct device *dev; +spinlock_t lock;No use in
RT_PREEMPT?Quoted 1 line
+};
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 211
Quoted 10 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +10
-0+ new_map =devm_kcalloc (pctldev->dev, map_num,sizeof (*new_map),GFP_KERNEL ); +if (!new_map) +return -ENOMEM ; + + *map = new_map; + *num_maps = map_num; +/* create mux map */ + parent =of_get_parent (np); +if (!parent) { +devm_kfree (pctldev->dev, new_map);Huh?! Are you sure you know the scope of usage of devm_*()?
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+return -EINVAL ; + } +...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 283
Quoted 2 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +2
-0+ regval &= ~GENMASK (setting->shift +MA35_MFP_BITS_PER_PORT -1 , + setting->shift);This will generate an awful code. Use respective FIELD_*() macros.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 305
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+ regval &= ~GENMASK (gpio *MA35_GP_MODE_MASK_WIDTH -1 , + gpio *MA35_GP_MODE_MASK_WIDTH ); + regval |= mode << gpio *MA35_GP_MODE_MASK_WIDTH ;Ditto.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 317
Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+ regval &=GENMASK (gpio *MA35_GP_MODE_MASK_WIDTH -1 , + gpio *MA35_GP_MODE_MASK_WIDTH ); + +return regval >> gpio *MA35_GP_MODE_MASK_WIDTH ;Ditto.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 326
Quoted 7 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +7
-0+static int ma35_gpio_core_direction_in (struct gpio_chip *gc,unsigned int gpio) +{ +struct ma35_pin_bank *bank =gpiochip_get_data (gc); +void __iomem *reg_mode = bank->reg_base +MA35_GP_REG_MODE ; +unsigned long flags; + +spin_lock_irqsave (&bank->lock, flags);Use
cleanup.h, i.e.guard()in this case, from day 1. Similar approach for all other places.Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+spin_unlock_irqrestore (&bank->lock, flags); + +return 0 ; +}...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 349
Quoted 5 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +5
-0+ regval =readl (reg_dout); +if (val) +writel (regval |BIT (gpio), reg_dout); +else +writel (regval & ~BIT (gpio), reg_dout);Can you split regval update and make only a single
writel()call? It's slightly better patternread() if (foo) v = else v = write()Quoted 1 line
+
ma35_gpio_set_mode(reg_mode, gpio, MA35_GP_MODE_OUTPUT);...
Quoted 1 line
+ regval &= ~GENMASK(bit_offs +
MA35_MFP_BITS_PER_PORT- 1,bit_offs);
FIELD_GET()...
Quoted 1 line
+
writel(1<<num, reg_intsrc);Oh, something happened here, besides indentation.
Have you meantBIT()?...
Quoted 1 line
+ unsigned int num = (
d->hwirq);Read Documentation on how to access hwirq field and what type of the value should be. There are plently of the examples already in the kernel. Just check the recent (more or less) ones.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 418
Quoted 6 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +6
-0+/* +* The MA35_GP_REG_INTEN bits 0 ~ 15 control low-level or falling edge trigger, +* while bits 16 ~ 31 control high-level or rising edge trigger. +* We disable both type of interrupt. +*/ + regval &= ~(BIT (num +16 ) |BIT (num));You have this idiom more than once in the code, make the definition and use it. Move comment closer to that definition.
...
Quoted 7 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +7
-0+irq_set_handler_locked (d, handle_edge_irq); + bank->irqtype &= ~(0x1 << num); + bank->irqinten |= (0x1 << num); + bank->irqinten &= ~(0x1 << (num +16 )); +break ; +case IRQ_TYPE_LEVEL_HIGH : +irq_set_handler_locked (d, handle_level_irq);drivers/pinctrl/nuvoton/pinctrl-ma35.c line 479
Quoted 10 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +10
-0+ bank->irqtype |= (0x1 << num); + bank->irqinten &= ~(0x1 << num); + bank->irqinten |= (0x1 << (num +16 )); +break ; +case IRQ_TYPE_LEVEL_LOW : +irq_set_handler_locked (d, handle_level_irq); + bank->irqtype |= (0x1 << num); + bank->irqinten &= ~(0x1 << (num +16 )); + bank->irqinten |= (0x1 << num); +break ;
BIT()in all cases....
Quoted 1 line
+
irq_set_handler_locked(d, handle_bad_irq);Just assign it in the probe.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 499
Quoted 9 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +9
-0+static struct irq_chip ma35_gpio_irqchip = { + .name ="MA35-GPIO-IRQ" , + .irq_disable = ma35_irq_gpio_mask, + .irq_enable = ma35_irq_gpio_unmask, + .irq_ack = ma35_irq_gpio_ack, + .irq_mask = ma35_irq_gpio_mask, + .irq_unmask = ma35_irq_gpio_unmask, + .irq_set_type = ma35_irq_irqtype, + .flags =IRQCHIP_MASK_ON_SUSPEND |IRQCHIP_SKIP_SET_WAKE |IRQCHIP_IMMUTABLE ,It doesn't look like IMMUTABLE. Again, check other examples, there are a lot.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 514
Quoted 11 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +11
-0+static void ma35_irq_demux_intgroup (struct irq_desc *desc) +{ +struct ma35_pin_bank *bank =gpiochip_get_data (irq_desc_get_handler_data (desc)); +struct irq_domain *irqdomain = bank->chip.irq.domain; +struct irq_chip *irqchip =irq_desc_get_chip (desc); +unsigned long isr; +int offset; + +chained_irq_enter (irqchip, desc); + isr =readl (bank->reg_base +MA35_GP_REG_INTSRC ); +if (isr)Unneeded duplicate check.
Quoted 5 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +5
-0+for_each_set_bit (offset, &isr, bank->nr_pins) +generic_handle_irq (irq_find_mapping (irqdomain, offset)); + +chained_irq_exit (irqchip, desc); +}...
Quoted 1 line
+ for (i = 0; i <
ctrl->nr_banks; ++i, ++bank) {Why pre-increments?
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 531
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+if (!bank->valid) { +dev_warn (&pdev->dev,"bank %s is not valid\n" , + bank->np->name);Do not use fwnode /
of_nodename like this, use proper specifiers: %pfw / %pOF.Quoted 16 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +16
-0+continue ; + } + bank->irqtype =0 ; + bank->irqinten =0 ; + bank->chip.label = bank->name; + bank->chip.of_gpio_n_cells =2 ; + bank->chip.parent = &pdev->dev; + bank->chip.request = ma35_gpio_core_to_request; + bank->chip.direction_input = ma35_gpio_core_direction_in; + bank->chip.direction_output = ma35_gpio_core_direction_out; + bank->chip.get = ma35_gpio_core_get; + bank->chip.set = ma35_gpio_core_set; + bank->chip.base =-1 ; + bank->chip.ngpio = bank->nr_pins; + bank->chip.can_sleep = false; +spin_lock_init (&bank->lock);drivers/pinctrl/nuvoton/pinctrl-ma35.c line 557
Quoted 10 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +10
-0+ +if (bank->irq >0 ) { +struct gpio_irq_chip *girq; + + girq = &bank->chip.irq; +gpio_irq_chip_set_chip (girq, &ma35_gpio_irqchip); + girq->parent_handler = ma35_irq_demux_intgroup; + girq->num_parents =1 ; + + girq->parents = devm_kcalloc(&pdev->dev, 1, sizeof(*girq->parents),Use
num_parentsinstead of 1.Quoted 18 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +18
-0+ GFP_KERNEL); +if (!girq->parents) { + ret = -ENOMEM ; + goto fail; + } + + girq->parents[0 ] = bank->irq; + girq->default_type =IRQ_TYPE_NONE ; + girq->handler = handle_bad_irq; + } + + ret =gpiochip_add_data (&bank->chip, bank); +if (ret) { +dev_err (&pdev->dev,"failed to register gpio_chip %s, error code: %d\n" , + bank->chip.label, ret); + goto fail; + } + }...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 579
Quoted 2 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +2
-0+fail: +for (--i, --bank; i >=0 ; --i, --bank) {while (i--) { bank--; ... }much better to read.
Quoted 6 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +6
-0+if (!bank->valid) +continue ; +gpiochip_remove (&bank->chip); + } +return ret; +}...
Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+static int ma35_get_bank_data (struct ma35_pin_bank *bank,struct ma35_pinctrl *npctl) +{ +struct resource res; +drivers/pinctrl/nuvoton/pinctrl-ma35.c line 600
Quoted 10 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +10
-0+if (of_address_to_resource (bank->np,0 , &res)) { +dev_err (npctl->dev,"cannot find IO resource for bank\n" ); +return -ENOENT ; + } + + bank->reg_base =devm_ioremap_resource (npctl->dev, &res); +if (IS_ERR (bank->reg_base)) { +dev_err (npctl->dev,"cannot ioremap resource for bank\n" ); +return PTR_ERR (bank->reg_base); + }Use
fwnode_iomap()Quoted 1 line
+
bank->irq=irq_of_parse_and_map(bank->np, 0);Use
fwnode_get_irq()drivers/pinctrl/nuvoton/pinctrl-ma35.c line 605
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+ bank->nr_pins =MA35_GPIO_PORT_MAX ; + + bank->clk =of_clk_get (bank->np,0 );Can't you use simple
clk_get()? Why?Quoted 5 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +5
-0+if (IS_ERR (bank->clk)) +return PTR_ERR (bank->clk); + +return clk_prepare_enable (bank->clk); +}...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 633
Quoted 2 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +2
-0+for_each_gpiochip_node (&pdev->dev, child) { +struct device_node *np =to_of_node (child);No need, just keep everythin fwnode based.
Quoted 8 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +8
-0+ bank = &ctrl->pin_banks[id]; + bank->np = np; + bank->regmap = pctl->regmap; + bank->dev = &pdev->dev; +if (!ma35_get_bank_data (bank, pctl)) + bank->valid = true; + id++; + }...
Review
Quoted 2 lines
(quoted diff) +2
-0+ regval &= ~GENMASK(port * MA35_GP_PUSEL_MASK_WIDTH - 1, + port * MA35_GP_PUSEL_MASK_WIDTH);FIELD_*()
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 717
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+ regval &=GENMASK (port *MA35_GP_PUSEL_MASK_WIDTH -1 , + port *MA35_GP_PUSEL_MASK_WIDTH ); + regval >>= port *MA35_GP_PUSEL_MASK_WIDTH ;Ditto.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 760
Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+if (regval &BIT (port)) +return MVOLT_3300 ; +else +return MVOLT_1800 ;Can be written as
return (regval & BIT()) ? _3300 : _1800;...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 805
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+if (port <MA35_GP_DSH_BASE_PORT ) { + regval =readl (base +MA35_GP_REG_DSL ); + ds_val = (regval &GENMASK (port *4 +2 , port *4 )) >> port *4 ;This is too complicated way of saying
ds_val = (regval >> port * 4) & GENMASK(2, 0);drivers/pinctrl/nuvoton/pinctrl-ma35.c line 809
Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+ }else { + port -=MA35_GP_DSH_BASE_PORT ; + regval =readl (base +MA35_GP_REG_DSH ); + ds_val = (regval &GENMASK (port *4 +2 , port *4 )) >> port *4 ;Ditto.
Quoted 1 line
+ }
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 831
Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+if (ma35_pinconf_get_power_source (npctl, pin) ==MVOLT_1800 ) { +for (i =0 ; i <ARRAY_SIZE (ds_1800mv_tbl); i++) { +if (ds_1800mv_tbl[i] == strength) + ds_val = i;And still continue?!
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 836
Quoted 5 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +5
-0+ } + }else { +for (i =0 ; i <ARRAY_SIZE (ds_3300mv_tbl); i++) { +if (ds_3300mv_tbl[i] == strength) + ds_val = i;Ditto.
Review
Quoted 2 lines
(quoted diff) +2
-0+ } + }Wondering if the
linear_rangesor other existing tables approaches can be used here....
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 848
Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+if (port <MA35_GP_DSH_BASE_PORT ) { + regval =readl (base +MA35_GP_REG_DSL ); + regval &= ~GENMASK (port *4 +2 , port *4 ); + regval |= ds_val << port *4 ;As per above
~(GENMASK(2, 0) << (port * 4))drivers/pinctrl/nuvoton/pinctrl-ma35.c line 853
Quoted 5 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +5
-0+writel (regval, base +MA35_GP_REG_DSL ); + }else { + port -=MA35_GP_DSH_BASE_PORT ; + regval =readl (base +MA35_GP_REG_DSH ); + regval &= ~GENMASK (port *4 +2 , port *4 );Ditto.
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+ regval |= ds_val << port *4 ; +writel (regval, base +MA35_GP_REG_DSH ); + }...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 923
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+ regval &= ~GENMASK (port *MA35_GP_SLEWCTL_MASK_WIDTH -1 , + port *MA35_GP_SLEWCTL_MASK_WIDTH ); + regval |= rate << port *MA35_GP_SLEWCTL_MASK_WIDTH ;FIELD_*()
...
Quoted 6 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +6
-0+static int ma35_pinconf_get (struct pinctrl_dev *pctldev,unsigned int pin,unsigned long *config) +{ +struct ma35_pinctrl *npctl =pinctrl_dev_get_drvdata (pctldev); +enum pin_config_param param =pinconf_to_config_param (*config); +u32 arg; +int ret;drivers/pinctrl/nuvoton/pinctrl-ma35.c line 944
Quoted 10 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +10
-0+ +switch (param) { +case PIN_CONFIG_BIAS_DISABLE : +case PIN_CONFIG_BIAS_PULL_DOWN : +case PIN_CONFIG_BIAS_PULL_UP : +if (ma35_pinconf_get_pull (npctl, pin) == param) + arg =1 ; +else +return -EINVAL ; +break ;Check for the error case first and get rid of redundant 'else'.
Quoted 29 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +29
-0+case PIN_CONFIG_DRIVE_STRENGTH : + ret =ma35_pinconf_get_drive_strength (npctl, pin, &arg); +if (ret) +return ret; +break ; + +case PIN_CONFIG_INPUT_SCHMITT_ENABLE : + arg =ma35_pinconf_get_schmitt_enable (npctl, pin); +break ; + +case PIN_CONFIG_SLEW_RATE : + arg =ma35_pinconf_get_slew_rate (npctl, pin); +break ; + +case PIN_CONFIG_OUTPUT_ENABLE : + arg =ma35_pinconf_get_output (npctl, pin); +break ; + +case PIN_CONFIG_POWER_SOURCE : + arg =ma35_pinconf_get_power_source (npctl, pin); +break ; + +default : +return -EINVAL ; + } + *config =pinconf_to_config_packed (param, arg); + +return 0 ; +}...
Quoted 36 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +36
-0+static int ma35_pinconf_set (struct pinctrl_dev *pctldev,unsigned int pin, +unsigned long *configs,unsigned int num_configs) +{ +struct ma35_pinctrl *npctl =pinctrl_dev_get_drvdata (pctldev); +enum pin_config_param param; +unsigned int arg =0 ; +int i, ret =0 ; + +for (i =0 ; i < num_configs; i++) { + param =pinconf_to_config_param (configs[i]); + arg =pinconf_to_config_argument (configs[i]); + +switch (param) { +case PIN_CONFIG_BIAS_DISABLE : +case PIN_CONFIG_BIAS_PULL_UP : +case PIN_CONFIG_BIAS_PULL_DOWN : + ret =ma35_pinconf_set_pull (npctl, pin, param); +break ; + +case PIN_CONFIG_DRIVE_STRENGTH : + ret =ma35_pinconf_set_drive_strength (npctl, pin, arg); +break ; + +case PIN_CONFIG_INPUT_SCHMITT_ENABLE : + ret =ma35_pinconf_set_schmitt (npctl, pin,1 ); +break ; + +case PIN_CONFIG_INPUT_SCHMITT : + ret =ma35_pinconf_set_schmitt (npctl, pin, arg); +break ; + +case PIN_CONFIG_SLEW_RATE : + ret =ma35_pinconf_set_slew_rate (npctl, pin, arg); +break ; + +case PIN_CONFIG_OUTPUT_ENABLE :drivers/pinctrl/nuvoton/pinctrl-ma35.c line 1021
Quoted 10 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +10
-0+ ret =ma35_pinconf_set_output (npctl, pin, arg); +break ; + +case PIN_CONFIG_POWER_SOURCE : + ret =ma35_pinconf_set_power_source (npctl, pin, arg); +break ; + +default : +return -EINVAL ; + }No returning an error if we got ret != 0?!
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+ } +return ret; +}...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 1038
Quoted 7 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +7
-0+static int ma35_pinctrl_parse_groups (struct device_node *np,struct ma35_pin_group *grp, +struct ma35_pinctrl *npctl,u32 index) +{ +unsigned long *configs; +unsigned int nconfigs; +struct ma35_pin_setting *pin; +const __be32 *list;Huh?!
Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+int i, j, size, ret; + +dev_dbg (npctl->dev,"group(%d): %s\n" , index, np->name); +drivers/pinctrl/nuvoton/pinctrl-ma35.c line 1052
Quoted 10 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +10
-0+ grp->name = np->name; + + ret =pinconf_generic_parse_dt_config (np,NULL , &configs, &nconfigs); +if (ret) +return ret; + +/* +* the binding format is nuvoton,pins = <bank pin-mfp pin-function>, +* do sanity check and calculate pins number +*/ /*
* Respect English grammar and puntuation
* in all multi-line comments. See the difference
* how it's done above and in this example. */Quoted 1 line
+ list =
of_get_property(np, "nuvoton,pins", &size);Oh, no.
Use respectiveof_property_calls.Quoted 28 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +28
-0+ size /=sizeof (*list); +if (!size || size %3 ) { +dev_err (npctl->dev,"wrong setting!\n" ); +return -EINVAL ; + } + grp->npins = size /3 ; + + grp->pins =devm_kcalloc (npctl->dev, grp->npins,sizeof (*grp->pins),GFP_KERNEL ); +if (!grp->pins) +return -ENOMEM ; + + grp->settings =devm_kcalloc (npctl->dev, grp->npins,sizeof (*grp->settings),GFP_KERNEL ); +if (!grp->settings) +return -ENOMEM ; + + pin = grp->settings; + +for (i =0 , j =0 ; i < size; i +=3 , j++) { + pin->offset =be32_to_cpu (*list++) *MA35_MFP_REG_SZ_PER_BANK +MA35_MFP_REG_BASE ; + pin->shift = (be32_to_cpu (*list++) *MA35_MFP_BITS_PER_PORT ) %32 ; + pin->muxval =be32_to_cpu (*list++); + pin->configs = configs; + pin->nconfigs = nconfigs; + grp->pins[j] = npctl->info->get_pin_num (pin->offset, pin->shift); + pin++; + } +return 0 ; +}...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 1129
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+for_each_child_of_node (np, child) { +if (of_property_read_bool (child,"gpio-controller" )) +continue ;There is a macro already present,
for_each_gpiochip_node().Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+ npctl->nfunctions++; + npctl->ngroups +=of_get_child_count (child); + }...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 1129
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+for_each_child_of_node (np, child) { +if (of_property_read_bool (child,"gpio-controller" )) +continue ;Ditto.
Quoted 7 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +7
-0+ ret =ma35_pinctrl_parse_functions (child, npctl, idx++); +if (ret) { +dev_err (&pdev->dev,"failed to parse function\n" ); +of_node_put (child); +return ret; + } + }...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 1170
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+if (!info || !info->pins || !info->npins) { +dev_err (&pdev->dev,"wrong pinctrl info\n" ); +return -EINVAL ;return dev_err_probe(...);Quoted 1 line
+ }
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 1210
Quoted 2 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +2
-0+ ret =devm_pinctrl_register_and_init (&pdev->dev, ma35_pinctrl_desc, + npctl, &npctl->pctl);Haveing
struct device *dev = &pdev->dev;makes in particular this one better
ret = devm_pinctrl_register_and_init(dev, ma35_pinctrl_desc, npctl, &npctl->pctl);Quoted 2 lines
(quoted diff) +2
-0+ if (ret) + return dev_err_probe(&pdev->dev, ret, "fail to register MA35 pinctrl\n");...
Quoted 1 line
+int
__maybe_unusedma35_pinctrl_suspend(struct device *dev)No
__maybe_unused.
Just use respective PM macros (pm_ptr(), DEFINE_,*PM_OPS, etc).drivers/pinctrl/nuvoton/pinctrl-ma35.c line 1228
Quoted 7 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +7
-0+{ +struct ma35_pinctrl *npctl =dev_get_drvdata (dev); + +return pinctrl_force_sleep (npctl->pctl); +} + +int __maybe_unused ma35_pinctrl_resume (struct device *dev)Ditto.
Quoted 5 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +5
-0+{ +struct ma35_pinctrl *npctl =dev_get_drvdata (dev); + +return pinctrl_force_default (npctl->pctl); +}...
drivers/pinctrl/nuvoton/pinctrl-ma35.h line 23
Quoted 10 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.h new file +10
-0+struct ma35_mux_desc { +const char *name; +u32 muxval; +}; + +struct ma35_pin_data { +u32 offset; +u32 shift; +struct ma35_mux_desc *muxes; +};Don't pin control subsystem has already some data types suitable in this cases?
...
drivers/pinctrl/nuvoton/pinctrl-ma35.h line 33
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.h new file +3
-0+#define MA35_PIN (num, n, o, s, ...) { \ + .number = num, \ + .name = #n, \Don't we have macros for this?
Quoted 7 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.h new file +7
-0+ .drv_data = &(struct ma35_pin_data) { \ + .offset = o, \ + .shift = s, \ + .muxes = (struct ma35_mux_desc []) { \ + __VA_ARGS__, { } }, \ + }, \ +}...
drivers/pinctrl/nuvoton/pinctrl-ma35d1.c line 9
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35d1.c new file +3
-0+#include <linux/init.h> +#include <linux/io.h> +#include <linux/module.h> Missing headers and stray ones. Please, get this into order by following IWYU principle.
Review
Quoted 2 lines
(quoted diff) +2
-0+#include <linux/of.h> +#include <linux/of_device.h>How are these being used?
Quoted 1 line
+#include <
linux/pinctrl/pinctrl.h>...
drivers/pinctrl/nuvoton/pinctrl-ma35d1.c line 1768
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35d1.c new file +3
-0+static const struct dev_pm_ops ma35d1_pinctrl_pm_ops = { +SET_LATE_SYSTEM_SLEEP_PM_OPS (ma35_pinctrl_suspend, ma35_pinctrl_resume) +};New PM macros, please.
...
drivers/pinctrl/nuvoton/pinctrl-ma35d1.c line 1777
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35d1.c new file +3
-0+static const struct of_device_id ma35d1_pinctrl_of_match[] = { + { .compatible ="nuvoton,ma35d1-pinctrl" , }, + { },No comma in the terminator entry.
Quoted 1 line
+};
...
drivers/pinctrl/nuvoton/pinctrl-ma35d1.c line 1784
Quoted 5 lines
drivers/pinctrl/nuvoton/pinctrl-ma35d1.c new file +5
-0+static struct platform_driver ma35d1_pinctrl_driver = { + .probe = ma35d1_pinctrl_probe, + .driver = { + .name ="ma35d1-pinctrl" , + .pm = &ma35d1_pinctrl_pm_ops,New PM macro here.
drivers/pinctrl/nuvoton/pinctrl-ma35d1.c line 1787
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35d1.c new file +3
-0+ .of_match_table = ma35d1_pinctrl_of_match, + }, +};--
With Best Regards,
Andy Shevchenko
Re: [PATCH v7 3/3] pinctrl: nuvoton: Add ma35d1 pinctrl and GPIO driver
In reply to Andy ShevchenkoDear Andy,
Quoted 22 lines · Andy Shevchenko
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 55
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+#define MA35_GP_MODE_MASK_WIDTH 2 + +#define MA35_GP_SLEWCTL_MASK_WIDTH 2I looked at the code how you use these... Oh, please switch to
FIELD_GET()/FIELD_PREP()(don't forget to includebitfield.h)...
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 283
Quoted 2 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +2
-0+ regval &= ~GENMASK (setting->shift +MA35_MFP_BITS_PER_PORT -1 , + setting->shift);This will generate an awful code. Use respective FIELD_*() macros.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 305
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+ regval &= ~GENMASK (gpio *MA35_GP_MODE_MASK_WIDTH -1 , + gpio *MA35_GP_MODE_MASK_WIDTH ); + regval |= mode << gpio *MA35_GP_MODE_MASK_WIDTH ;Ditto.
...
Quoted 9 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 317
Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+ regval &=GENMASK (gpio *MA35_GP_MODE_MASK_WIDTH -1 , + gpio *MA35_GP_MODE_MASK_WIDTH ); + +return regval >> gpio *MA35_GP_MODE_MASK_WIDTH ;Ditto.
...
Allow me to remove irrelevant parts.
I attempted to follow your advice and use FIELD_GET() and FIELD_PREP(), but found it impractical. The reason is that these two macros require their 'mask' argument to be a constant, otherwise compilation errors occur, which is the issue I encountered. Since the mask here is calculated and not a constant, compilation errors occur.
Taking MA35_GP_REG_MODE as an example, within 32 bits, every 2 bits represent the mode of a GPIO pin, and the mask is obtained by GENMASK(gpio * 2 -1, gpio * 2), where the 'gpio' argument is a variable, not a constant, leading to compilation errors.
Due to this reason, I will leave this part unchanged, or do you have any other suggestions?
Best Regards,
Jacky Huang
Re: [PATCH v7 3/3] pinctrl: nuvoton: Add ma35d1 pinctrl and GPIO driver
Quoted 1 line · Jacky Huang
On 2024/4/10 下午 04:54, Andy Shevchenko wrote:
...
Quoted 27 lines
Quoted 27 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 55
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+#define MA35_GP_MODE_MASK_WIDTH 2 + +#define MA35_GP_SLEWCTL_MASK_WIDTH 2I looked at the code how you use these... Oh, please switch to
FIELD_GET()/FIELD_PREP()(don't forget to includebitfield.h)...
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 283
Quoted 2 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +2
-0+ regval &= ~GENMASK (setting->shift +MA35_MFP_BITS_PER_PORT -1 , + setting->shift);This will generate an awful code. Use respective FIELD_*() macros.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 305
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+ regval &= ~GENMASK (gpio *MA35_GP_MODE_MASK_WIDTH -1 , + gpio *MA35_GP_MODE_MASK_WIDTH ); + regval |= mode << gpio *MA35_GP_MODE_MASK_WIDTH ;Ditto.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 317
Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+ regval &=GENMASK (gpio *MA35_GP_MODE_MASK_WIDTH -1 , + gpio *MA35_GP_MODE_MASK_WIDTH ); + +return regval >> gpio *MA35_GP_MODE_MASK_WIDTH ;Ditto.
...
Quoted 11 lines
Allow me to remove irrelevant parts.
I attempted to follow your advice and use
FIELD_GET()andFIELD_PREP(), but found
it impractical. The reason is that these two macros require their 'mask' argument
to be a constant, otherwise compilation errors occur, which is the issue I encountered.
Since the mask here is calculated and not a constant, compilation errors occur.
Quoted 4 lines
Taking
MA35_GP_REG_MODEas an example, within 32 bits, every 2 bits represent
the mode of a GPIO pin, and the mask is obtained byGENMASK(gpio * 2 -1, gpio * 2),
This is not good for the compiler, it can't figure out (at least in some _supported_ by Linux kernel versions on some architectures) that GENMASK can be constant here just left-shifted by arbitrary bits.
Quoted 6 lines
where the 'gpio' argument is a variable, not a constant, leading to compilation
errors.Due to this reason, I will leave this part unchanged, or do you have any other suggestions?
If you need non-constant field_get()/field_prep(), add a new patch that moves them from drivers/iio/temperature/mlx90614.c (and there are more custom implementations:
https://elixir.bootlin.com/linux/latest/A/ident/field_get) to the bitfield.h and use them in your code.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v7 3/3] pinctrl: nuvoton: Add ma35d1 pinctrl and GPIO driver
Dear Andy,
Quoted 56 lines · Andy Shevchenko
Quoted 1 line · Jacky Huang
On 2024/4/10 下午 04:54, Andy Shevchenko wrote:
...
Quoted 27 lines
Quoted 27 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 55
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+#define MA35_GP_MODE_MASK_WIDTH 2 + +#define MA35_GP_SLEWCTL_MASK_WIDTH 2I looked at the code how you use these... Oh, please switch to
FIELD_GET()/FIELD_PREP()(don't forget to includebitfield.h)...
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 283
Quoted 2 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +2
-0+ regval &= ~GENMASK (setting->shift +MA35_MFP_BITS_PER_PORT -1 , + setting->shift);This will generate an awful code. Use respective FIELD_*() macros.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 305
Quoted 3 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +3
-0+ regval &= ~GENMASK (gpio *MA35_GP_MODE_MASK_WIDTH -1 , + gpio *MA35_GP_MODE_MASK_WIDTH ); + regval |= mode << gpio *MA35_GP_MODE_MASK_WIDTH ;Ditto.
...
drivers/pinctrl/nuvoton/pinctrl-ma35.c line 317
Quoted 4 lines
drivers/pinctrl/nuvoton/pinctrl-ma35.c new file +4
-0+ regval &=GENMASK (gpio *MA35_GP_MODE_MASK_WIDTH -1 , + gpio *MA35_GP_MODE_MASK_WIDTH ); + +return regval >> gpio *MA35_GP_MODE_MASK_WIDTH ;Ditto.
...
Quoted 11 lines
Allow me to remove irrelevant parts.
I attempted to follow your advice and use
FIELD_GET()andFIELD_PREP(), but found
it impractical. The reason is that these two macros require their 'mask' argument
to be a constant, otherwise compilation errors occur, which is the issue I encountered.
Since the mask here is calculated and not a constant, compilation errors occur.Quoted 4 lines
Taking
MA35_GP_REG_MODEas an example, within 32 bits, every 2 bits represent
the mode of a GPIO pin, and the mask is obtained byGENMASK(gpio * 2 -1, gpio * 2),This is not good for the compiler, it can't figure out (at least in some _supported_ by Linux kernel versions on some architectures) that GENMASK can be constant here just left-shifted by arbitrary bits.
Quoted 4 lines
where the 'gpio' argument is a variable, not a constant, leading to compilation
errors.
Quoted 8 lines
Quoted 2 lines
Due to this reason, I will leave this part unchanged, or do you have any other suggestions?
If you need non-constant field_get()/field_prep(), add a new patch that moves them from
drivers/iio/temperature/mlx90614.c(and there are more custom implementations:
https://elixir.bootlin.com/linux/latest/A/ident/field_get) to thebitfield.hand use them in your code.
Thank you. It works for me. I will adopt the approach used in mlx90614.c.
Best Regards,
Jacky Huang