Pinctrl: Add Amlogic pinctrl driver
Subsystems (5)
Xianwei Zhao
maintainerv2 cover Pinctrl: Add Amlogic pinctrl driver
Add pinctrl driver support for Amloigc SoCs
Base on the previous discussion,
https://lore.kernel.org/r/[email protected]
The existed meson driver failed to meet the requirement of the current dt-binding. So we start this new pinctrl driver to solve problem.
The advantage of this version: Once the source file and binding document are added, adding dts node will be only operation for subsequent Amlogic SoCs (such as A4, A5).
The code in DTS file is also readable when using GPIO, as below:
reset-gpios = <&gpiob 6 GPIO_ACTIVE_LOW>;
---
Changes in v2:
- Some modifications and optimizations were made to bindings according to Rob's suggestions.
- Refined some details on functions node for bindings.
- Some source code optimizations were made according to Linus's suggestions.
- Add stand API to generic to deal pinmux propertity.
- Add private reg data to deal with for future SoCs.
- Simplified some unused processing (previously used for extension).
- Sync add to MAINTAINERS files.
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Xianwei Zhao (5):
dt-bindings: pinctrl: Add support for Amlogic SoCs
pinctrl: pinconf-generic: Add API for pinmux propertity in DTS file
pinctrl: Add driver support for Amlogic SoCs
arm64: dts: amlogic: a4: add pinctrl node
MAINTAINERS: Add an entry for Amlogic pinctrl driver
.../bindings/pinctrl/amlogic,pinctrl-a4.yaml | 155 +++ MAINTAINERS | 8 + arch/arm64/boot/dts/amlogic/amlogic-a4.dtsi | 133 +++ drivers/pinctrl/Kconfig | 18 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinconf-generic.c | 130 +++ drivers/pinctrl/pinconf.h | 4 + drivers/pinctrl/pinctrl-amlogic.c | 1047 ++++++++++++++++++++ include/dt-bindings/pinctrl/amlogic,pinctrl.h | 68 ++ include/linux/pinctrl/pinconf-generic.h | 4 + 10 files changed, 1568 insertions(+)
---
base-commit: 4de5110762b94b9978fb8182a568572fb2194f8b
change-id: 20241211-amlogic-pinctrl-22ea61820d0d
Best regards,
Signature · 1 line
Xianwei Zhao <[email protected]>
Xianwei Zhao
maintainerPATCH v2 1/5 dt-bindings: pinctrl: Add support for Amlogic SoCs
Add the dt-bindings for Amlogic pin controller, and add a new dt-binding header file which document the GPIO bank names and alternative func value of all Amlogic subsequent SoCs.
--- .../bindings/pinctrl/amlogic,pinctrl-a4.yaml | 155 +++++++++++++++++++++ include/dt-bindings/pinctrl/amlogic,pinctrl.h | 68 +++++++++ 2 files changed, 223 insertions(+)
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +155 -0
@@ -0,0 +1,155 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pinctrl/amlogic,pinctrl-a4.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Amlogic pinmux controller + +maintainers: + - Xianwei Zhao <[email protected]> + +allOf: + - $ref: pinctrl.yaml# + +properties: + compatible: + const: amlogic,pinctrl-a4 + + reg: + minItems: 2 + + reg-names: + items: + - const: mux + - const: gpio + + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + +required: + - compatible + - reg + - reg-names + - "#address-cells" + - "#size-cells" + +patternProperties: + "^gpio@[0-9a-f]+$": + type: object + + properties: + reg: + minItems: 2 + + mask: + $ref: /schemas/types.yaml#/definitions/uint32 + + gpio-controller: true + + "#gpio-cells": + const: 2 + + ngpios: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 1 + maximum: 32 + + identity: + description: | + identifier are provided by the pin controller header file at: + <include/dt-bindings/pinctrl/amlogic,pinctrl.h> + + $ref: /schemas/types.yaml#/definitions/uint32 + + required: + - reg + - gpio-controller + - "#gpio-cells" + - ngpios + - identity + + additionalProperties: false + + "^func-[0-9a-z-]+$": + type: object + additionalProperties: + type: object + allOf: + - $ref: pincfg-node.yaml# + - $ref: pinmux-node.yaml# + + description: + A pin multiplexing sub-node describes how to configure a set of (or a + single) pin in some desired alternate function mode. + A single sub-node may define several pin configurations. + + properties: + pinmux: + description: | + Integer array representing pin number and pin multiplexing + configuration. + When a pin has to be configured in alternate function mode, use + this property to identify the pin by its global index, and provide + its alternate function configuration number along with it. + bank identifier are provided by the pin controller header file at: + <include/dt-bindings/pinctrl/amlogic,pinctrl.h> + Integers values in "pinmux" argument list are assembled as: + (((BANK << 8) + PIN) << 8) | MUX_FUNC)) + + required: + - pinmux + + additionalProperties: true + +additionalProperties: false + +examples: + - | + #include <dt-bindings/pinctrl/amlogic,pinctrl.h> + apb { + #address-cells = <2>; + #size-cells = <2>; + periphs_pinctrl: pinctrl@8e700 { + compatible = "amlogic,pinctrl-a4"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x0 0x8e700 0x0 0x04>, + <0x0 0x8e704 0x0 0x60>; + reg-names = "mux", "gpio"; + + gpio@14 { + reg = <0x14>,<0x30>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <10>; + identity = <AMLOGIC_GPIO_B>; + }; + + func-uart-b { + uart-b-default { + pinmux = <AML_PINMUX(AMLOGIC_GPIO_B, 1, AF4)>; + bias-pull-up; + drive-strength-microamp = <4000>; + }; + + uart-b-pins1 { + pinmux = <AML_PINMUX(AMLOGIC_GPIO_B, 5, AF2)>; + bias-pull-up; + drive-strength-microamp = <4000>; + }; + }; + + func-uart-c { + uart-c-default { + pinmux = <AML_PINMUX(AMLOGIC_GPIO_B, 3, AF1)>, + <AML_PINMUX(AMLOGIC_GPIO_B, 2, AF1)>; + bias-pull-up; + drive-strength-microamp = <4000>; + }; + }; + }; + };
include/dt-bindings/pinctrl/amlogic,pinctrl.h new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
2.37.1
Rob Herring
maintainerRe: [PATCH v2 1/5] dt-bindings: pinctrl: Add support for Amlogic SoCs
Quoted 37 lines · Xianwei Zhao
Add the dt-bindings for Amlogic pin controller, and add a new dt-binding header file which document the GPIO bank names and alternative func value of all Amlogic subsequent SoCs.
Signed-off-by Xianwei Zhao <[email protected]>--- .../bindings/pinctrl/amlogic,pinctrl-a4.yaml | 155 +++++++++++++++++++++ include/dt-bindings/pinctrl/amlogic,pinctrl.h | 68 +++++++++ 2 files changed, 223 insertions(+)Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +21
-0@@ -0,0 +1,155 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pinctrl/amlogic,pinctrl-a4.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Amlogic pinmux controller + +maintainers: + - Xianwei Zhao <[email protected]> + +allOf: + - $ref: pinctrl.yaml# + +properties: + compatible: + const: amlogic,pinctrl-a4 + + reg: + minItems: 2 +
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml line 31
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +10
-0+ reg-names: + items: + - const: mux + - const: gpio + + "#address-cells": + const: 1 + + "#size-cells": + const: 0
The addresses in 'reg' below are MMIO, right? If so, #size-cells can't be 0 and you also need 'ranges' here.
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml line 33
Quoted 2 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +2
-0+ +required:
Move after 'patternProperties'.
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml line 46
Quoted 13 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +13
-0+ - compatible + - reg + - reg-names + - "#address-cells" + - "#size-cells" + +patternProperties: + "^gpio@[0-9a-f]+$": + type: object + + properties: + reg: + minItems: 2
You need to describe what each entry is:
items:
- description: foo
- description: bar
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml line 57
Quoted 11 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +11
-0+ + mask: + $ref: /schemas/types.yaml#/definitions/uint32 + + gpio-controller: true + + "#gpio-cells": + const: 2 + + ngpios: + $ref: /schemas/types.yaml#/definitions/uint32
Don't need a type here.
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml line 61
Quoted 4 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +4
-0+ minimum: 1 + maximum: 32 + + identity:
Needs a better name. This is the bank number?
But shouldn't you be able to use gpio-ranges here:
gpio-ranges = <&periphs_pinctrl 0 (bank# << 8) (value of npgios)>;
And do you really need ngpios if you have the value here?
Quoted 8 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +8
-0+ description: | + identifier are provided by the pin controller header file at: + <include/dt-bindings/pinctrl/amlogic,pinctrl.h> + + $ref: /schemas/types.yaml#/definitions/uint32 + + required: + - reg
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml line 79
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +10
-0+ - gpio-controller + - "#gpio-cells" + - ngpios + - identity + + additionalProperties: false + + "^func-[0-9a-z-]+$": + type: object + additionalProperties:
Define a pattern for the node names instead. We only allow anything for existing bindings.
Quoted 17 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +17
-0+ type: object + allOf: + - $ref: pincfg-node.yaml# + - $ref: pinmux-node.yaml# + + description: + A pin multiplexing sub-node describes how to configure a set of (or a + single) pin in some desired alternate function mode. + A single sub-node may define several pin configurations. + + properties: + pinmux: + description: | + Integer array representing pin number and pin multiplexing + configuration. + When a pin has to be configured in alternate function mode, use + this property to identify the pin by its global index, and provide
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml line 106
Quoted 10 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +10
-0+ its alternate function configuration number along with it. + bank identifier are provided by the pin controller header file at: + <include/dt-bindings/pinctrl/amlogic,pinctrl.h> + Integers values in "pinmux" argument list are assembled as: + (((BANK << 8) + PIN) << 8) | MUX_FUNC)) + + required: + - pinmux + + additionalProperties: true
No, not allowed to be true except on common schemas.
Quoted 71 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +49
-0+ +additionalProperties: false + +examples: + - | + #include <dt-bindings/pinctrl/amlogic,pinctrl.h> + apb { + #address-cells = <2>; + #size-cells = <2>; + periphs_pinctrl: pinctrl@8e700 { + compatible = "amlogic,pinctrl-a4"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x0 0x8e700 0x0 0x04>, + <0x0 0x8e704 0x0 0x60>; + reg-names = "mux", "gpio"; + + gpio@14 { + reg = <0x14>,<0x30>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <10>; + identity = <AMLOGIC_GPIO_B>; + }; + + func-uart-b { + uart-b-default { + pinmux = <AML_PINMUX(AMLOGIC_GPIO_B, 1, AF4)>; + bias-pull-up; + drive-strength-microamp = <4000>; + }; + + uart-b-pins1 { + pinmux = <AML_PINMUX(AMLOGIC_GPIO_B, 5, AF2)>; + bias-pull-up; + drive-strength-microamp = <4000>; + }; + }; + + func-uart-c { + uart-c-default { + pinmux = <AML_PINMUX(AMLOGIC_GPIO_B, 3, AF1)>, + <AML_PINMUX(AMLOGIC_GPIO_B, 2, AF1)>; + bias-pull-up; + drive-strength-microamp = <4000>; + }; + }; + }; + };include/dt-bindings/pinctrl/amlogic,pinctrl.h new file +16
-0@@ -0,0 +1,68 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR MIT) */ +/* +* Copyright (c) 2024 Amlogic, Inc. All rights reserved. +* Author: Xianwei Zhao <[email protected]> +*/ + +#ifndef _DT_BINDINGS_AMLOGIC_PINCTRL_H +#define _DT_BINDINGS_AMLOGIC_PINCTRL_H + +/* define PIN modes */ +#define AF0 0x0 +#define AF1 0x1 +#define AF2 0x2 +#define AF3 0x3 +#define AF4 0x4 +#define AF5 0x5
include/dt-bindings/pinctrl/amlogic,pinctrl.h line 26
Quoted 10 lines
include/dt-bindings/pinctrl/amlogic,pinctrl.h new file +10
-0+#define AF6 0x6 +#define AF7 0x7 +#define AF8 0x8 +#define AF9 0x9 +#define AF10 0xa +#define AF11 0xb +#define AF12 0xc +#define AF13 0xd +#define AF14 0xe +#define AF15 0xf
There's no need for defines in the form "FOOn n".
Quoted 46 lines
include/dt-bindings/pinctrl/amlogic,pinctrl.h new file +42
-0+ +#define AML_PIN_ALT_FUNC_MASK 0xf + +/* Normal PIN bank */ +#define AMLOGIC_GPIO_A 0 +#define AMLOGIC_GPIO_B 1 +#define AMLOGIC_GPIO_C 2 +#define AMLOGIC_GPIO_D 3 +#define AMLOGIC_GPIO_E 4 +#define AMLOGIC_GPIO_F 5 +#define AMLOGIC_GPIO_G 6 +#define AMLOGIC_GPIO_H 7 +#define AMLOGIC_GPIO_I 8 +#define AMLOGIC_GPIO_J 9 +#define AMLOGIC_GPIO_K 10 +#define AMLOGIC_GPIO_L 11 +#define AMLOGIC_GPIO_M 12 +#define AMLOGIC_GPIO_N 13 +#define AMLOGIC_GPIO_O 14 +#define AMLOGIC_GPIO_P 15 +#define AMLOGIC_GPIO_Q 16 +#define AMLOGIC_GPIO_R 17 +#define AMLOGIC_GPIO_S 18 +#define AMLOGIC_GPIO_T 19 +#define AMLOGIC_GPIO_U 20 +#define AMLOGIC_GPIO_V 21 +#define AMLOGIC_GPIO_W 22 +#define AMLOGIC_GPIO_X 23 +#define AMLOGIC_GPIO_Y 24 +#define AMLOGIC_GPIO_Z 25 + +/* Special PIN bank */ +#define AMLOGIC_GPIO_DV 26 +#define AMLOGIC_GPIO_AO 27 +#define AMLOGIC_GPIO_CC 28 +#define AMLOGIC_GPIO_TEST_N 29 + +#define AML_PINMUX (bank, offset, mode) (((((bank) << 8) + (offset)) << 8) | (mode)) +#define AML_PINMUX_TO_BANK (pinmux) (((pinmux) >> 16) & 0xff) +#define AML_PINMUX_TO_OFFSET (pinmux) (((pinmux) >> 8) & 0xff) + +#endif /* _DT_BINDINGS_AMLOGIC_PINCTRL_H */ Signature · 2 lines
-- 2.37.1
Xianwei Zhao
maintainerRe: [PATCH v2 1/5] dt-bindings: pinctrl: Add support for Amlogic SoCs
Hi Rob,
Thanks for your reply.
Quoted 45 lines · Rob Herring
[ EXTERNAL EMAIL ]
Quoted 42 lines · Xianwei Zhao
Add the dt-bindings for Amlogic pin controller, and add a new dt-binding header file which document the GPIO bank names and alternative func value of all Amlogic subsequent SoCs.
Signed-off-by Xianwei Zhao <[email protected]>--- .../bindings/pinctrl/amlogic,pinctrl-a4.yaml | 155 +++++++++++++++++++++ include/dt-bindings/pinctrl/amlogic,pinctrl.h | 68 +++++++++ 2 files changed, 223 insertions(+)Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +26
-0@@ -0,0 +1,155 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pinctrl/amlogic,pinctrl-a4.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Amlogic pinmux controller + +maintainers: + - Xianwei Zhao <[email protected]> + +allOf: + - $ref: pinctrl.yaml# + +properties: + compatible: + const: amlogic,pinctrl-a4 + + reg: + minItems: 2 + + reg-names: + items: + - const: mux + - const: gpio +
Quoted 9 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml line 31
Quoted 5 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +5
-0+ "#address-cells": + const: 1 + + "#size-cells": + const: 0The addresses in 'reg' below are MMIO, right? If so, #size-cells can't be 0 and you also need 'ranges' here.
Will add ranges here, reg and reg-names move into gpio object.
Quoted 5 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml line 33
Quoted 2 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +2
-0+ +required:Move after 'patternProperties'.
Will do.
Quoted 16 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml line 46
Quoted 13 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +13
-0+ - compatible + - reg + - reg-names + - "#address-cells" + - "#size-cells" + +patternProperties: + "^gpio@[0-9a-f]+$": + type: object + + properties: + reg: + minItems: 2You need to describe what each entry is:
Quoted 4 lines
items:
- description: foo
- description: bar
Will add description in next version
Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +5
-0+ + mask: + $ref: /schemas/types.yaml#/definitions/uint32 + + gpio-controller: true
Quoted 9 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml line 57
Quoted 6 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +6
-0+ + "#gpio-cells": + const: 2 + + ngpios: + $ref: /schemas/types.yaml#/definitions/uint32Don't need a type here.
Will drop ngpios, use gpio_rangs instead.
Quoted 7 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml line 61
Quoted 4 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +4
-0+ minimum: 1 + maximum: 32 + + identity:Needs a better name. This is the bank number?
named 'bank-number'.
Quoted 19 lines
But shouldn't you be able to use gpio-ranges here:
gpio-ranges = <
&periphs_pinctrl0 (bank# << 8) (value of npgios)>;And do you really need ngpios if you have the value here?
Quoted 13 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +13
-0+ description: | + identifier are provided by the pin controller header file at: + <include/dt-bindings/pinctrl/amlogic,pinctrl.h> + + $ref: /schemas/types.yaml#/definitions/uint32 + + required: + - reg + - gpio-controller + - "#gpio-cells" + - ngpios + - identity +
Quoted 9 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml line 79
Quoted 5 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +5
-0+ additionalProperties: false + + "^func-[0-9a-z-]+$": + type: object + additionalProperties:Define a pattern for the node names instead. We only allow anything for existing bindings.
Will use patternProperies
Quoted 21 lines
Quoted 21 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +21
-0+ type: object + allOf: + - $ref: pincfg-node.yaml# + - $ref: pinmux-node.yaml# + + description: + A pin multiplexing sub-node describes how to configure a set of (or a + single) pin in some desired alternate function mode. + A single sub-node may define several pin configurations. + + properties: + pinmux: + description: | + Integer array representing pin number and pin multiplexing + configuration. + When a pin has to be configured in alternate function mode, use + this property to identify the pin by its global index, and provide + its alternate function configuration number along with it. + bank identifier are provided by the pin controller header file at: + <include/dt-bindings/pinctrl/amlogic,pinctrl.h> + Integers values in "pinmux" argument list are assembled as:
Quoted 9 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml line 106
Quoted 6 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +6
-0+ (((BANK << 8) + PIN) << 8) | MUX_FUNC)) + + required: + - pinmux + + additionalProperties: trueNo, not allowed to be true except on common schemas.
This object I will only save
allOf:
- $ref: pincfg-node.yaml#
- $ref: pinmux-node.yaml#others(description, properties,required, additionalProperties) will be dropped.
Quoted 75 lines
Quoted 75 lines
Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml new file +49
-0+ +additionalProperties: false + +examples: + - | + #include <dt-bindings/pinctrl/amlogic,pinctrl.h> + apb { + #address-cells = <2>; + #size-cells = <2>; + periphs_pinctrl: pinctrl@8e700 { + compatible = "amlogic,pinctrl-a4"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x0 0x8e700 0x0 0x04>, + <0x0 0x8e704 0x0 0x60>; + reg-names = "mux", "gpio"; + + gpio@14 { + reg = <0x14>,<0x30>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <10>; + identity = <AMLOGIC_GPIO_B>; + }; + + func-uart-b { + uart-b-default { + pinmux = <AML_PINMUX(AMLOGIC_GPIO_B, 1, AF4)>; + bias-pull-up; + drive-strength-microamp = <4000>; + }; + + uart-b-pins1 { + pinmux = <AML_PINMUX(AMLOGIC_GPIO_B, 5, AF2)>; + bias-pull-up; + drive-strength-microamp = <4000>; + }; + }; + + func-uart-c { + uart-c-default { + pinmux = <AML_PINMUX(AMLOGIC_GPIO_B, 3, AF1)>, + <AML_PINMUX(AMLOGIC_GPIO_B, 2, AF1)>; + bias-pull-up; + drive-strength-microamp = <4000>; + }; + }; + }; + };include/dt-bindings/pinctrl/amlogic,pinctrl.h new file +20
-0@@ -0,0 +1,68 @@ +/* SPDX-License-Identifier: (GPL-2.0-only OR MIT) */ +/* +* Copyright (c) 2024 Amlogic, Inc. All rights reserved. +* Author: Xianwei Zhao <[email protected]> +*/ + +#ifndef _DT_BINDINGS_AMLOGIC_PINCTRL_H +#define _DT_BINDINGS_AMLOGIC_PINCTRL_H + +/* define PIN modes */ +#define AF0 0x0 +#define AF1 0x1 +#define AF2 0x2 +#define AF3 0x3 +#define AF4 0x4 +#define AF5 0x5 +#define AF6 0x6 +#define AF7 0x7 +#define AF8 0x8 +#define AF9 0x9
Quoted 9 lines
include/dt-bindings/pinctrl/amlogic,pinctrl.h line 26
Quoted 6 lines
include/dt-bindings/pinctrl/amlogic,pinctrl.h new file +6
-0+#define AF10 0xa +#define AF11 0xb +#define AF12 0xc +#define AF13 0xd +#define AF14 0xe +#define AF15 0xfThere's no need for defines in the form "FOOn n".
Will do.
Quoted 46 lines
Quoted 46 lines
include/dt-bindings/pinctrl/amlogic,pinctrl.h new file +42
-1+ +#define AML_PIN_ALT_FUNC_MASK 0xf + +/* Normal PIN bank */ +#define AMLOGIC_GPIO_A 0 +#define AMLOGIC_GPIO_B 1 +#define AMLOGIC_GPIO_C 2 +#define AMLOGIC_GPIO_D 3 +#define AMLOGIC_GPIO_E 4 +#define AMLOGIC_GPIO_F 5 +#define AMLOGIC_GPIO_G 6 +#define AMLOGIC_GPIO_H 7 +#define AMLOGIC_GPIO_I 8 +#define AMLOGIC_GPIO_J 9 +#define AMLOGIC_GPIO_K 10 +#define AMLOGIC_GPIO_L 11 +#define AMLOGIC_GPIO_M 12 +#define AMLOGIC_GPIO_N 13 +#define AMLOGIC_GPIO_O 14 +#define AMLOGIC_GPIO_P 15 +#define AMLOGIC_GPIO_Q 16 +#define AMLOGIC_GPIO_R 17 +#define AMLOGIC_GPIO_S 18 +#define AMLOGIC_GPIO_T 19 +#define AMLOGIC_GPIO_U 20 +#define AMLOGIC_GPIO_V 21 +#define AMLOGIC_GPIO_W 22 +#define AMLOGIC_GPIO_X 23 +#define AMLOGIC_GPIO_Y 24 +#define AMLOGIC_GPIO_Z 25 + +/* Special PIN bank */ +#define AMLOGIC_GPIO_DV 26 +#define AMLOGIC_GPIO_AO 27 +#define AMLOGIC_GPIO_CC 28 +#define AMLOGIC_GPIO_TEST_N 29 + +#define AML_PINMUX (bank, offset, mode) (((((bank) << 8) + (offset)) << 8) | (mode)) +#define AML_PINMUX_TO_BANK (pinmux) (((pinmux) >> 16) & 0xff) +#define AML_PINMUX_TO_OFFSET (pinmux) (((pinmux) >> 8) & 0xff) + +#endif /* _DT_BINDINGS_AMLOGIC_PINCTRL_H */ --2.37.1
Xianwei Zhao
maintainerPATCH v2 2/5 pinctrl: pinconf-generic: Add API for pinmux propertity in DTS file
In reply to Xianwei ZhaoWhen describing pin mux func through pinmux propertity, a standard API is added for support. The pinmux contains pin identification and mux values, which can include multiple pins. And groups configuration use other word. DTS such as:
func-name {
group_alias: group-name{
pinmux= <pin_id << 8 | mux_value)>,
<pin_id << 8 | mux_value)>;
bias-pull-up;
drive-strength-microamp = <4000>;
};
};--- drivers/pinctrl/pinconf-generic.c | 130 ++++++++++++++++++++++++++++++++ drivers/pinctrl/pinconf.h | 4 + include/linux/pinctrl/pinconf-generic.h | 4 + 3 files changed, 138 insertions(+)
drivers/pinctrl/pinconf-generic.c +130 -0
@@ -233,6 +233,67 @@ static void parse_dt_cfg(struct device_node *np, } } +/** +* pinconf_generic_parse_dt_pinmux() +* parse the pinmux properties into generic pin mux values. +* @np: node containing the pinmux properties +* @pctldev: pincontrol device +* @pid: array with pin identity entries +* @pmux: array with pin mux value entries +* @npins: number of pins +* +* pinmux propertity: mux value [0,7]bits and pin identity [8,31]bits. +*/ +int pinconf_generic_parse_dt_pinmux (struct device_node *np,struct device *dev, +unsigned int **pid,unsigned int **pmux, +unsigned int *npins) +{ +unsigned int *pid_t; +unsigned int *pmux_t; +struct property *prop; +unsigned int npins_t, i; +u32 value; +int ret; + + prop =of_find_property (np,"pinmux" ,NULL ); +if (!prop) { +dev_info (dev,"Missing pinmux property\n" ); +return -ENOENT ; + } + +if (!pid || !pmux || !npins) { +dev_err (dev,"paramers error\n" ); +return -EINVAL ; + } + + npins_t = prop->length /sizeof (u32); + pid_t =devm_kcalloc (dev, npins_t,sizeof (*pid_t),GFP_KERNEL ); + pmux_t =devm_kcalloc (dev, npins_t,sizeof (*pmux_t),GFP_KERNEL ); +if (!pid_t || !pmux_t) { +dev_err (dev,"kalloc memory fail\n" ); +return -ENOMEM ; + } +for (i =0 ; i < npins_t; i++) { + ret =of_property_read_u32_index (np,"pinmux" , i, &value); +if (ret) { +dev_err (dev,"get pinmux value fail\n" ); + goto exit; + } + pmux_t[i] = value &0xff ; + pid_t[i] = (value >>8 ) &0xffffff ; + } + *pid = pid_t; + *pmux = pmux_t; + *npins = npins_t; + +return 0 ; +exit: +devm_kfree (dev, pid_t); +devm_kfree (dev, pmux_t); +return ret; +} +EXPORT_SYMBOL_GPL (pinconf_generic_parse_dt_pinmux); +/** * pinconf_generic_parse_dt_config() * parse the config properties into generic pinconfig values.
@@ -295,6 +356,75 @@ int pinconf_generic_parse_dt_config(struct device_node *np, }EXPORT_SYMBOL_GPL (pinconf_generic_parse_dt_config); +int pinconf_generic_dt_node_to_map_pinmux (struct pinctrl_dev *pctldev, +struct device_node *np, +struct pinctrl_map **map, +unsigned int *num_maps) +{ +struct device *dev = pctldev->dev; +struct device_node *pnode; +unsigned long *configs =NULL ; +unsigned int num_configs =0 ; +struct property *prop; +unsigned int reserved_maps; +int reserve; +int ret; + + prop =of_find_property (np,"pinmux" ,NULL ); +if (!prop) { +dev_info (dev,"Missing pinmux property\n" ); +return -ENOENT ; + } + + pnode =of_get_parent (np); +if (!pnode) { +dev_info (dev,"Missing function node\n" ); +return -EINVAL ; + } + + reserved_maps =0 ; + *map =NULL ; + *num_maps =0 ; + + ret =pinconf_generic_parse_dt_config (np, pctldev, &configs, + &num_configs); +if (ret <0 ) { +dev_err (dev,"%pOF: could not parse node property\n" , np); +return ret; + } + + reserve =1 ; +if (num_configs) + reserve++; + + ret =pinctrl_utils_reserve_map (pctldev, map, &reserved_maps, + num_maps, reserve); +if (ret <0 ) + goto exit; + + ret =pinctrl_utils_add_map_mux (pctldev, map, + &reserved_maps, num_maps, np->name, + pnode->name); +if (ret <0 ) + goto exit; + +if (num_configs) { + ret =pinctrl_utils_add_map_configs (pctldev, map, &reserved_maps, + num_maps, np->name, configs, + num_configs,PIN_MAP_TYPE_CONFIGS_GROUP ); +if (ret <0 ) + goto exit; + } + +exit: +kfree (configs); +if (ret) +pinctrl_utils_free_map (pctldev, *map, *num_maps); + +return ret; +} +EXPORT_SYMBOL_GPL (pinconf_generic_dt_node_to_map_pinmux); + int pinconf_generic_dt_subnode_to_map(struct pinctrl_dev *pctldev, struct device_node *np, struct pinctrl_map **map, unsigned int *reserved_maps, unsigned int *num_maps,
drivers/pinctrl/pinconf.h +4 -0
@@ -138,4 +138,8 @@ int pinconf_generic_parse_dt_config(struct device_node *np,struct pinctrl_dev *pctldev, unsigned long **configs, unsigned int *nconfigs); + +int pinconf_generic_parse_dt_pinmux (struct device_node *np,struct device *dev, +unsigned int **pid,unsigned int **pmux, +unsigned int *npins);#endif
include/linux/pinctrl/pinconf-generic.h +4 -0
@@ -232,4 +232,8 @@ static inline int pinconf_generic_dt_node_to_map_all(struct pinctrl_dev *pctldev PIN_MAP_TYPE_INVALID); } +int pinconf_generic_dt_node_to_map_pinmux (struct pinctrl_dev *pctldev, +struct device_node *np, +struct pinctrl_map **map, +unsigned int *num_maps);#endif /* __LINUX_PINCTRL_PINCONF_GENERIC_H */
Signature · 1 line
2.37.1
kernel test robot
build botRe: [PATCH v2 2/5] pinctrl: pinconf-generic: Add API for pinmux propertity in DTS file
kernel test robot noticed the following build warnings:
Hi Xianwei,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 4de5110762b94b9978fb8182a568572fb2194f8b]
url: https://github.com/intel-lab-lkp/linux/commits/Xianwei-Zhao-via-B4-Relay/dt-bindings-pinctrl-Add-support-for-Amlogic-SoCs/20241226-155844 base: 4de5110762b94b9978fb8182a568572fb2194f8b patch link: https://lore.kernel.org/r/20241226-amlogic-pinctrl-v2-2-cdae42a67b76%40amlogic.com patch subject: [PATCH v2 2/5] pinctrl: pinconf-generic: Add API for pinmux propertity in DTS file config: arc-randconfig-001-20241226 (https://download.01.org/0day-ci/archive/20241226/[email protected]/config) compiler: arceb-elf-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241226/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
>> drivers/pinctrl/pinconf-generic.c:250: warning: Function parameter or struct member 'dev' not described in 'pinconf_generic_parse_dt_pinmux' >> drivers/pinctrl/pinconf-generic.c:250: warning: Excess function parameter 'pctldev' description in 'pinconf_generic_parse_dt_pinmux'
vim +250 drivers/pinctrl/pinconf-generic.c
235
236 /**
237 * pinconf_generic_parse_dt_pinmux()
238 * parse the pinmux properties into generic pin mux values.
239 * @np: node containing the pinmux properties
240 * @pctldev: pincontrol device
241 * @pid: array with pin identity entries
242 * @pmux: array with pin mux value entries
243 * @npins: number of pins
244 *
245 * pinmux propertity: mux value [0,7]bits and pin identity [8,31]bits.
246 */
247 int pinconf_generic_parse_dt_pinmux(struct device_node *np, struct device *dev,
248 unsigned int **pid, unsigned int **pmux,
249 unsigned int *npins)
> 250 { 251 unsigned int *pid_t;
252 unsigned int *pmux_t;
253 struct property *prop;
254 unsigned int npins_t, i;
255 u32 value;
256 int ret;
257
258 prop = of_find_property(np, "pinmux", NULL);
259 if (!prop) {
260 dev_info(dev, "Missing pinmux property\n");
261 return -ENOENT;
262 }
263
264 if (!pid || !pmux || !npins) {
265 dev_err(dev, "paramers error\n");
266 return -EINVAL;
267 }
268
269 npins_t = prop->length / sizeof(u32);
270 pid_t = devm_kcalloc(dev, npins_t, sizeof(*pid_t), GFP_KERNEL);
271 pmux_t = devm_kcalloc(dev, npins_t, sizeof(*pmux_t), GFP_KERNEL);
272 if (!pid_t || !pmux_t) {
273 dev_err(dev, "kalloc memory fail\n");
274 return -ENOMEM;
275 }
276 for (i = 0; i < npins_t; i++) {
277 ret = of_property_read_u32_index(np, "pinmux", i, &value);
278 if (ret) {
279 dev_err(dev, "get pinmux value fail\n");
280 goto exit;
281 }
282 pmux_t[i] = value & 0xff;
283 pid_t[i] = (value >> 8) & 0xffffff;
284 }
285 *pid = pid_t;
286 *pmux = pmux_t;
287 *npins = npins_t;
288
289 return 0;
290 exit:
291 devm_kfree(dev, pid_t);
292 devm_kfree(dev, pmux_t);
293 return ret;
294 }
295 EXPORT_SYMBOL_GPL(pinconf_generic_parse_dt_pinmux);
296
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
Re: [PATCH v2 2/5] pinctrl: pinconf-generic: Add API for pinmux propertity in DTS file
In reply to Xianwei ZhaoQuoted 16 lines · On Thu, Dec 26, 2024 at 8:57 AM Xianwei Zhao via B4 Relay…
From: Xianwei Zhao <[email protected]>
When describing pin mux func through pinmux propertity, a standard API is added for support. The pinmux contains pin identification and mux values, which can include multiple pins. And groups configuration use other word. DTS such as:
func-name { group_alias: group-name{ pinmux= <pin_id << 8 | mux_value)>, <pin_id << 8 | mux_value)>; bias-pull-up; drive-strength-microamp = <4000>; }; };
Quoted 1 line
Signed-off-by Xianwei Zhao <[email protected]>
There are some build errors, but I really like the path taken with the utility function here!
Yours,
Linus Walleij
Xianwei Zhao
maintainerRe: [PATCH v2 2/5] pinctrl: pinconf-generic: Add API for pinmux propertity in DTS file
Hi Linus,
Thanks for your reply.
Quoted 21 lines · Linus Walleij
[ EXTERNAL EMAIL ]
Quoted 16 lines · On Thu, Dec 26, 2024 at 8:57 AM Xianwei Zhao via B4 Relay…
From: Xianwei Zhao <[email protected]>
When describing pin mux func through pinmux propertity, a standard API is added for support. The pinmux contains pin identification and mux values, which can include multiple pins. And groups configuration use other word. DTS such as:
func-name { group_alias: group-name{ pinmux= <pin_id << 8 | mux_value)>, <pin_id << 8 | mux_value)>; bias-pull-up; drive-strength-microamp = <4000>; }; };
Quoted 5 lines
Quoted 1 line
Signed-off-by Xianwei Zhao <[email protected]>There are some build errors, but I really like the path taken with the utility function here!
I will fix the issue Reported by kernel test robot next version.
Quoted 2 lines
Yours,
Linus Walleij
Jerome Brunet
reviewerRe: [PATCH v2 2/5] pinctrl: pinconf-generic: Add API for pinmux propertity in DTS file
In reply to Xianwei ZhaoQuoted 11 lines · On Thu 26 Dec 2024 at 15:57, Xianwei Zhao via B4 Relay…
From: Xianwei Zhao <[email protected]>
When describing pin mux func through pinmux propertity, a standard API is added for support. The pinmux contains pin identification and mux values, which can include multiple pins. And groups configuration use other word. DTS such as:
func-name { group_alias: group-name{ pinmux= <pin_id << 8 | mux_value)>, <pin_id << 8 | mux_value)>;
This representation does not seem very generic but more tailored to your use-case.
Quoted 2 lines
bias-pull-up; drive-strength-microamp = <4000>;
If you want to add pinmux (aka alternate function) selection as a pinconf prop then I think there should be a single pinmux setting per group, and as many groups as you need per function defined.
something like
func-foo {
group-a {
groups = "pin_a", "pin_b";
bias-pull-up;
alternate-function = <2>;
};
group-b {
groups = "pin_c"";
bias-disable;
alternate-function = <5>;
};
};Something similar is already done to handle different pin bias requirement on single function on amlogic platforms:
Quoted 184 lines
}; };Signed-off-by Xianwei Zhao <[email protected]>--- drivers/pinctrl/pinconf-generic.c | 130 ++++++++++++++++++++++++++++++++ drivers/pinctrl/pinconf.h | 4 + include/linux/pinctrl/pinconf-generic.h | 4 + 3 files changed, 138 insertions(+)drivers/pinctrl/pinconf-generic.c +130
-0@@ -233,6 +233,67 @@ static void parse_dt_cfg(struct device_node *np, } } +/** +* pinconf_generic_parse_dt_pinmux() +* parse the pinmux properties into generic pin mux values. +* @np: node containing the pinmux properties +* @pctldev: pincontrol device +* @pid: array with pin identity entries +* @pmux: array with pin mux value entries +* @npins: number of pins +* +* pinmux propertity: mux value [0,7]bits and pin identity [8,31]bits. +*/ +int pinconf_generic_parse_dt_pinmux (struct device_node *np,struct device *dev, +unsigned int **pid,unsigned int **pmux, +unsigned int *npins) +{ +unsigned int *pid_t; +unsigned int *pmux_t; +struct property *prop; +unsigned int npins_t, i; +u32 value; +int ret; + + prop =of_find_property (np,"pinmux" ,NULL ); +if (!prop) { +dev_info (dev,"Missing pinmux property\n" ); +return -ENOENT ; + } + +if (!pid || !pmux || !npins) { +dev_err (dev,"paramers error\n" ); +return -EINVAL ; + } + + npins_t = prop->length /sizeof (u32); + pid_t =devm_kcalloc (dev, npins_t,sizeof (*pid_t),GFP_KERNEL ); + pmux_t =devm_kcalloc (dev, npins_t,sizeof (*pmux_t),GFP_KERNEL ); +if (!pid_t || !pmux_t) { +dev_err (dev,"kalloc memory fail\n" ); +return -ENOMEM ; + } +for (i =0 ; i < npins_t; i++) { + ret =of_property_read_u32_index (np,"pinmux" , i, &value); +if (ret) { +dev_err (dev,"get pinmux value fail\n" ); + goto exit; + } + pmux_t[i] = value &0xff ; + pid_t[i] = (value >>8 ) &0xffffff ; + } + *pid = pid_t; + *pmux = pmux_t; + *npins = npins_t; + +return 0 ; +exit: +devm_kfree (dev, pid_t); +devm_kfree (dev, pmux_t); +return ret; +} +EXPORT_SYMBOL_GPL (pinconf_generic_parse_dt_pinmux); +/** * pinconf_generic_parse_dt_config() * parse the config properties into generic pinconfig values. @@ -295,6 +356,75 @@ int pinconf_generic_parse_dt_config(struct device_node *np, }EXPORT_SYMBOL_GPL (pinconf_generic_parse_dt_config); +int pinconf_generic_dt_node_to_map_pinmux (struct pinctrl_dev *pctldev, +struct device_node *np, +struct pinctrl_map **map, +unsigned int *num_maps) +{ +struct device *dev = pctldev->dev; +struct device_node *pnode; +unsigned long *configs =NULL ; +unsigned int num_configs =0 ; +struct property *prop; +unsigned int reserved_maps; +int reserve; +int ret; + + prop =of_find_property (np,"pinmux" ,NULL ); +if (!prop) { +dev_info (dev,"Missing pinmux property\n" ); +return -ENOENT ; + } + + pnode =of_get_parent (np); +if (!pnode) { +dev_info (dev,"Missing function node\n" ); +return -EINVAL ; + } + + reserved_maps =0 ; + *map =NULL ; + *num_maps =0 ; + + ret =pinconf_generic_parse_dt_config (np, pctldev, &configs, + &num_configs); +if (ret <0 ) { +dev_err (dev,"%pOF: could not parse node property\n" , np); +return ret; + } + + reserve =1 ; +if (num_configs) + reserve++; + + ret =pinctrl_utils_reserve_map (pctldev, map, &reserved_maps, + num_maps, reserve); +if (ret <0 ) + goto exit; + + ret =pinctrl_utils_add_map_mux (pctldev, map, + &reserved_maps, num_maps, np->name, + pnode->name); +if (ret <0 ) + goto exit; + +if (num_configs) { + ret =pinctrl_utils_add_map_configs (pctldev, map, &reserved_maps, + num_maps, np->name, configs, + num_configs,PIN_MAP_TYPE_CONFIGS_GROUP ); +if (ret <0 ) + goto exit; + } + +exit: +kfree (configs); +if (ret) +pinctrl_utils_free_map (pctldev, *map, *num_maps); + +return ret; +} +EXPORT_SYMBOL_GPL (pinconf_generic_dt_node_to_map_pinmux); + int pinconf_generic_dt_subnode_to_map(struct pinctrl_dev *pctldev, struct device_node *np, struct pinctrl_map **map, unsigned int *reserved_maps, unsigned int *num_maps,drivers/pinctrl/pinconf.h +4
-0@@ -138,4 +138,8 @@ int pinconf_generic_parse_dt_config(struct device_node *np,struct pinctrl_dev *pctldev, unsigned long **configs, unsigned int *nconfigs); + +int pinconf_generic_parse_dt_pinmux (struct device_node *np,struct device *dev, +unsigned int **pid,unsigned int **pmux, +unsigned int *npins);#endif include/linux/pinctrl/pinconf-generic.h +4
-0@@ -232,4 +232,8 @@ static inline int pinconf_generic_dt_node_to_map_all(struct pinctrl_dev *pctldev PIN_MAP_TYPE_INVALID); } +int pinconf_generic_dt_node_to_map_pinmux (struct pinctrl_dev *pctldev, +struct device_node *np, +struct pinctrl_map **map, +unsigned int *num_maps);#endif /* __LINUX_PINCTRL_PINCONF_GENERIC_H */
Signature · 1 line
Jerome
Xianwei Zhao
maintainerRe: [PATCH v2 2/5] pinctrl: pinconf-generic: Add API for pinmux propertity in DTS file
Hi Jerome,
Thanks for your reply.
Quoted 11 lines · Jerome Brunet
[ EXTERNAL EMAIL ]
Quoted 7 lines · On Thu 26 Dec 2024 at 15:57, Xianwei Zhao via B4 Relay…
From: Xianwei Zhao <[email protected]>
When describing pin mux func through pinmux propertity, a standard API is added for support. The pinmux contains pin identification and mux values, which can include multiple pins. And groups configuration use other word. DTS such as:
Quoted 7 lines
Quoted 4 lines
func-name { group_alias: group-name{ pinmux= <pin_id << 8 | mux_value)>, <pin_id << 8 | mux_value)>;This representation does not seem very generic but more tailored to your use-case
The document above includes a description of the pinmux property. This is not my personal usage but rather a common practice, as other manufacturers' drivers also use it in a similar way. However, the specific definitions within pinmux may vary between manufacturers.
Quoted 217 lines
Quoted 3 lines
bias-pull-up; drive-strength-microamp = <4000>;If you want to add pinmux (aka alternate function) selection as a pinconf prop then I think there should be a single pinmux setting per group, and as many groups as you need per function defined.
something like
func-foo { group-a { groups = "pin_a", "pin_b"; bias-pull-up; alternate-function = <2>; }; group-b { groups = "pin_c""; bias-disable; alternate-function = <5>; }; };Something similar is already done to handle different pin bias requirement on single function on amlogic platforms:
Quoted 176 lines
}; };Signed-off-by Xianwei Zhao <[email protected]>--- drivers/pinctrl/pinconf-generic.c | 130 ++++++++++++++++++++++++++++++++ drivers/pinctrl/pinconf.h | 4 + include/linux/pinctrl/pinconf-generic.h | 4 + 3 files changed, 138 insertions(+)drivers/pinctrl/pinconf-generic.c +130
-0@@ -233,6 +233,67 @@ static void parse_dt_cfg(struct device_node *np, } } +/** +* pinconf_generic_parse_dt_pinmux() +* parse the pinmux properties into generic pin mux values. +* @np: node containing the pinmux properties +* @pctldev: pincontrol device +* @pid: array with pin identity entries +* @pmux: array with pin mux value entries +* @npins: number of pins +* +* pinmux propertity: mux value [0,7]bits and pin identity [8,31]bits. +*/ +int pinconf_generic_parse_dt_pinmux (struct device_node *np,struct device *dev, +unsigned int **pid,unsigned int **pmux, +unsigned int *npins) +{ +unsigned int *pid_t; +unsigned int *pmux_t; +struct property *prop; +unsigned int npins_t, i; +u32 value; +int ret; + + prop =of_find_property (np,"pinmux" ,NULL ); +if (!prop) { +dev_info (dev,"Missing pinmux property\n" ); +return -ENOENT ; + } + +if (!pid || !pmux || !npins) { +dev_err (dev,"paramers error\n" ); +return -EINVAL ; + } + + npins_t = prop->length /sizeof (u32); + pid_t =devm_kcalloc (dev, npins_t,sizeof (*pid_t),GFP_KERNEL ); + pmux_t =devm_kcalloc (dev, npins_t,sizeof (*pmux_t),GFP_KERNEL ); +if (!pid_t || !pmux_t) { +dev_err (dev,"kalloc memory fail\n" ); +return -ENOMEM ; + } +for (i =0 ; i < npins_t; i++) { + ret =of_property_read_u32_index (np,"pinmux" , i, &value); +if (ret) { +dev_err (dev,"get pinmux value fail\n" ); + goto exit; + } + pmux_t[i] = value &0xff ; + pid_t[i] = (value >>8 ) &0xffffff ; + } + *pid = pid_t; + *pmux = pmux_t; + *npins = npins_t; + +return 0 ; +exit: +devm_kfree (dev, pid_t); +devm_kfree (dev, pmux_t); +return ret; +} +EXPORT_SYMBOL_GPL (pinconf_generic_parse_dt_pinmux); +/** * pinconf_generic_parse_dt_config() * parse the config properties into generic pinconfig values. @@ -295,6 +356,75 @@ int pinconf_generic_parse_dt_config(struct device_node *np, }EXPORT_SYMBOL_GPL (pinconf_generic_parse_dt_config); +int pinconf_generic_dt_node_to_map_pinmux (struct pinctrl_dev *pctldev, +struct device_node *np, +struct pinctrl_map **map, +unsigned int *num_maps) +{ +struct device *dev = pctldev->dev; +struct device_node *pnode; +unsigned long *configs =NULL ; +unsigned int num_configs =0 ; +struct property *prop; +unsigned int reserved_maps; +int reserve; +int ret; + + prop =of_find_property (np,"pinmux" ,NULL ); +if (!prop) { +dev_info (dev,"Missing pinmux property\n" ); +return -ENOENT ; + } + + pnode =of_get_parent (np); +if (!pnode) { +dev_info (dev,"Missing function node\n" ); +return -EINVAL ; + } + + reserved_maps =0 ; + *map =NULL ; + *num_maps =0 ; + + ret =pinconf_generic_parse_dt_config (np, pctldev, &configs, + &num_configs); +if (ret <0 ) { +dev_err (dev,"%pOF: could not parse node property\n" , np); +return ret; + } + + reserve =1 ; +if (num_configs) + reserve++; + + ret =pinctrl_utils_reserve_map (pctldev, map, &reserved_maps, + num_maps, reserve); +if (ret <0 ) + goto exit; + + ret =pinctrl_utils_add_map_mux (pctldev, map, + &reserved_maps, num_maps, np->name, + pnode->name); +if (ret <0 ) + goto exit; + +if (num_configs) { + ret =pinctrl_utils_add_map_configs (pctldev, map, &reserved_maps, + num_maps, np->name, configs, + num_configs,PIN_MAP_TYPE_CONFIGS_GROUP ); +if (ret <0 ) + goto exit; + } + +exit: +kfree (configs); +if (ret) +pinctrl_utils_free_map (pctldev, *map, *num_maps); + +return ret; +} +EXPORT_SYMBOL_GPL (pinconf_generic_dt_node_to_map_pinmux); + int pinconf_generic_dt_subnode_to_map(struct pinctrl_dev *pctldev, struct device_node *np, struct pinctrl_map **map, unsigned int *reserved_maps, unsigned int *num_maps,drivers/pinctrl/pinconf.h +4
-0@@ -138,4 +138,8 @@ int pinconf_generic_parse_dt_config(struct device_node *np,struct pinctrl_dev *pctldev, unsigned long **configs, unsigned int *nconfigs); + +int pinconf_generic_parse_dt_pinmux (struct device_node *np,struct device *dev, +unsigned int **pid,unsigned int **pmux, +unsigned int *npins);#endif include/linux/pinctrl/pinconf-generic.h +0
-0include/linux/pinctrl/pinconf-generic.h static inline int pinconf_generic_dt_node_to_map_all(struct pinctrl_dev *pctldev · line 239
Quoted 8 lines
include/linux/pinctrl/pinconf-generic.h +4
-0@@ -232,4 +232,8 @@ static inline int pinconf_generic_dt_node_to_map_all(struct pinctrl_dev *pctldev PIN_MAP_TYPE_INVALID); } +int pinconf_generic_dt_node_to_map_pinmux (struct pinctrl_dev *pctldev, +struct device_node *np, +struct pinctrl_map **map, +unsigned int *num_maps);#endif /* __LINUX_PINCTRL_PINCONF_GENERIC_H */ --
Jerome
Xianwei Zhao
maintainerPATCH v2 3/5 pinctrl: Add driver support for Amlogic SoCs
In reply to Xianwei ZhaoAdd a new pinctrl driver for Amlogic SoCs. All future Amlogic SoCs pinctrl drives use this, such A4, A5, S6, S7 etc. To support new Amlogic SoCs, only need to add the corresponding dts file.
--- drivers/pinctrl/Kconfig | 18 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-amlogic.c | 1047 +++++++++++++++++++++++++++++++++++++ 3 files changed, 1066 insertions(+)
drivers/pinctrl/Kconfig +18 -0
@@ -49,6 +49,24 @@ config PINCTRL_AMD Requires ACPI/FDT device enumeration code to set up a platform device. +config PINCTRL_AMLOGIC + bool "AMLOGIC pincontrol" + depends on ARCH_MESON || COMPILE_TEST + depends on OF + default y + select PINMUX + select PINCONF + select GENERIC_PINCONF + select GPIOLIB + select OF_GPIO + select REGMAP_MMIO + help + This is the driver for the pin controller found on Amlogic SoCs. + + This driver is simplify subsequent support for new amlogic SoCs, + to support new Amlogic SoCs, only need to add the corresponding dts file, + no additional binding header files or C file are added. + config PINCTRL_APPLE_GPIO tristate "Apple SoC GPIO pin controller driver" depends on ARCH_APPLE
drivers/pinctrl/Makefile +1 -0
@@ -10,6 +10,7 @@ obj-$(CONFIG_GENERIC_PINCONF) += pinconf-generic.o obj-$(CONFIG_OF) += devicetree.o obj-$(CONFIG_PINCTRL_AMD) += pinctrl-amd.o +obj-$(CONFIG_PINCTRL_AMLOGIC) += pinctrl-amlogic.o obj-$(CONFIG_PINCTRL_APPLE_GPIO) += pinctrl-apple-gpio.o obj-$(CONFIG_PINCTRL_ARTPEC6) += pinctrl-artpec6.o obj-$(CONFIG_PINCTRL_AS3722) += pinctrl-as3722.o
drivers/pinctrl/pinctrl-amlogic.c new file +1047 -0
1,047 lines not on this page · raw message
Signature · 1 line
2.37.1
Martin Blumenstingl
reviewerRe: [PATCH v2 3/5] pinctrl: Add driver support for Amlogic SoCs
Hi Xianwei,
On Thu, Dec 26, 2024 at 8:57 AM Xianwei Zhao via B4 Relay <[email protected]> wrote:
[...]
drivers/pinctrl/pinctrl-amlogic.c line 861
Quoted 2 lines
drivers/pinctrl/pinctrl-amlogic.c new file +2
-0+if (of_property_read_u32 (np,"mask" , &bank->pc.mux_mask)) + bank->pc.mux_mask =0xf ;
I don't see any documentation for the mask property.
The discussion about the dt-bindings is still pretty heated. Everything else is already part of the documentation (which is good!). Please document his property as well (or remove the code to read it if there's no need to have it dynamic).
This is not a full code-review. However, since the discussion about the whole dt-bindings is still ongoing we need to make sure that whatever we document in the bindings is actually all that we need to write the driver.
Best regards,
Martin
Xianwei Zhao
maintainerRe: [PATCH v2 3/5] pinctrl: Add driver support for Amlogic SoCs
Hi Martin,
Thanks for your reply.
Quoted 15 lines · Martin Blumenstingl
[ EXTERNAL EMAIL ]
Hi Xianwei,
On Thu, Dec 26, 2024 at 8:57 AM Xianwei Zhao via B4 Relay <[email protected]> wrote:
[...]drivers/pinctrl/pinctrl-amlogic.c line 861
Quoted 2 lines
drivers/pinctrl/pinctrl-amlogic.c new file +2
-0+if (of_property_read_u32 (np,"mask" , &bank->pc.mux_mask)) + bank->pc.mux_mask =0xf ;I don't see any documentation for the mask property.
The discussion about the dt-bindings is still pretty heated. Everything else is already part of the documentation (which is good!). Please document his property as well (or remove the code to read it if there's no need to have it dynamic).
Quoted 5 lines
This is not a full code-review. However, since the discussion about the whole dt-bindings is still ongoing we need to make sure that whatever we document in the bindings is actually all that we need to write the driver.
The whole dt-bindings is still under discussion and revision. The 'mask' property will add description next version.
Quoted 3 lines
Best regards,
Martin
Xianwei Zhao
maintainerPATCH v2 4/5 arm64: dts: amlogic: a4: add pinctrl node
In reply to Xianwei ZhaoAdd pinctrl device to support Amlogic A4 and add uart pinconf.
--- arch/arm64/boot/dts/amlogic/amlogic-a4.dtsi | 133 ++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+)
arch/arm64/boot/dts/amlogic/amlogic-a4.dtsi +133 -0
@@ -5,6 +5,7 @@ #include "amlogic-a4-common.dtsi" #include <dt-bindings/power/amlogic,a4-pwrc.h> +#include <dt-bindings/pinctrl/amlogic,pinctrl.h> / { cpus { #address-cells = <2>;
@@ -48,3 +49,135 @@ pwrc: power-controller { }; }; }; + +&apb { + periphs_pinctrl: pinctrl@4000 { + compatible = "amlogic,pinctrl-a4"; + reg = <0x0 0x4000 0x0 0x0050>, + <0x0 0x40c0 0x0 0x0220>; + reg-names = "mux", "gpio"; + #address-cells = <1>; + #size-cells = <0>; + + gpiox: gpio@10 { + reg = <0x10>, <0x3>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <18>; + identity = <AMLOGIC_GPIO_X>; + }; + + gpiot: gpio@20 { + reg = <0x20>, <0xb>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <23>; + identity = <AMLOGIC_GPIO_T>; + }; + + gpiod: gpio@30 { + reg = <0x30>, <0x10>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <16>; + identity = <AMLOGIC_GPIO_D>; + }; + + gpioe: gpio@40 { + reg = <0x40>, <0x12>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <2>; + identity = <AMLOGIC_GPIO_E>; + }; + + gpiob: gpio@60 { + reg = <0x60>, <0x0>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <14>; + identity = <AMLOGIC_GPIO_B>; + }; + + func-uart-a { + uart_a_default: uart-a-pins1 { + pinmux= <AML_PINMUX(AMLOGIC_GPIO_X, 11, AF1)>, + <AML_PINMUX(AMLOGIC_GPIO_X, 12, AF1)>, + <AML_PINMUX(AMLOGIC_GPIO_X, 13, AF1)>, + <AML_PINMUX(AMLOGIC_GPIO_X, 14, AF1)>; + }; + + uart-a-pins2 { + pinmux= <AML_PINMUX(AMLOGIC_GPIO_D, 2, AF3)>, + <AML_PINMUX(AMLOGIC_GPIO_D, 3, AF3)>; + bias-pull-up; + drive-strength-microamp = <4000>; + }; + }; + + func-uart-b { + uart_b_default: uart-b-pins { + pinmux= <AML_PINMUX(AMLOGIC_GPIO_E, 0, AF3)>, + <AML_PINMUX(AMLOGIC_GPIO_E, 1, AF3)>; + bias-pull-up; + drive-strength-microamp = <4000>; + }; + }; + + func-uart-d { + uart_d_default: uart-d-pins1 { + pinmux= <AML_PINMUX(AMLOGIC_GPIO_T, 18, AF4)>, + <AML_PINMUX(AMLOGIC_GPIO_T, 19, AF4)>; + bias-pull-up; + drive-strength-microamp = <4000>; + }; + + uart-d-pins2 { + pinmux= <AML_PINMUX(AMLOGIC_GPIO_T, 7, AF2)>, + <AML_PINMUX(AMLOGIC_GPIO_T, 8, AF2)>, + <AML_PINMUX(AMLOGIC_GPIO_T, 9, AF2)>, + <AML_PINMUX(AMLOGIC_GPIO_T, 10, AF2)>; + bias-pull-up; + drive-strength-microamp = <4000>; + }; + }; + + func-uart-e { + uart_e_default: uart-e-pins { + pinmux= <AML_PINMUX(AMLOGIC_GPIO_T, 14, AF3)>, + <AML_PINMUX(AMLOGIC_GPIO_T, 15, AF3)>, + <AML_PINMUX(AMLOGIC_GPIO_T, 16, AF3)>, + <AML_PINMUX(AMLOGIC_GPIO_T, 17, AF3)>; + bias-pull-up; + drive-strength-microamp = <4000>; + }; + }; + }; + + aobus_pinctrl: pinctrl@8e700 { + compatible = "amlogic,pinctrl-a4"; + reg = <0x0 0x8e700 0x0 0x04>, + <0x0 0x8e704 0x0 0x60>; + reg-names = "mux", "gpio"; + #address-cells = <1>; + #size-cells = <0>; + + gpioao: gpio@0 { + reg = <0x0>, <0x0>; + mask = <0xfffffff>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <7>; + identity = <AMLOGIC_GPIO_AO>; + }; + + test_n: gpio@10 { + reg = <0x10>, <0x0>; + mask = <0xf0000000>; + gpio-controller; + #gpio-cells = <2>; + ngpios = <1>; + identity = <AMLOGIC_GPIO_TEST_N>; + }; + }; +};
Signature · 1 line
2.37.1
Xianwei Zhao
maintainerPATCH v2 5/5 MAINTAINERS: Add an entry for Amlogic pinctrl driver
In reply to Xianwei ZhaoAdd Amlogic pinctrl entry to MAINTAINERS to clarify the maintainers.
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -1218,6 +1218,14 @@ F: Documentation/devicetree/bindings/perf/amlogic,g12-ddr-pmu.yaml F: drivers/perf/amlogic/ F: include/soc/amlogic/ +AMLOGIC PINCTRL DRIVER +M: Xianwei Zhao <[email protected]> +L: [email protected] +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/pinctrl/amlogic,pinctrl-a4.yaml +F: drivers/pinctrl/pinctrl-amlogic.c + AMLOGIC RTC DRIVER M: Yiting Deng <[email protected]> M: Xianwei Zhao <[email protected]>
Signature · 1 line
2.37.1