* [PATCH v1 0/8] Add T-Head TH15020 SoC pin control
@ 2023-12-15 14:38 Emil Renner Berthing
2023-12-15 14:38 ` [PATCH v1 1/8] dt-bindings: pinctrl: Add thead,th1520-pinctrl bindings Emil Renner Berthing
` (7 more replies)
0 siblings, 8 replies; 21+ messages in thread
From: Emil Renner Berthing @ 2023-12-15 14:38 UTC (permalink / raw)
To: linux-gpio, devicetree, linux-kernel, linux-riscv
Cc: Hoan Tran, Serge Semin, Linus Walleij, Bartosz Golaszewski,
Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
Jisheng Zhang, Guo Ren, Fu Wei, Paul Walmsley, Palmer Dabbelt
This adds a pin control driver for the T-Head TH1520 RISC-V SoC used on
the Lichee Pi 4A and BeagleV Ahead boards and updates the device trees
to make use of it.
It can be easily tested using my th1520 branch at
https://github.com/esmil/linux.git
..which also adds the MMC, PWM, ethernet and USB drivers that have
been posted but are not upstream yet.
Jisheng: I've added this driver to the generic TH1520 entry in
MAINTAINERS like you did with your USB driver. Let me know if that's not
ok and I'll create a separate entry for this driver with me as
maintainer.
Drew: The last patch is purely based on reading the schematics. It'd be
great if you could give it a spin on real hardware.
/Emil
Emil Renner Berthing (8):
dt-bindings: pinctrl: Add thead,th1520-pinctrl bindings
pinctrl: Add driver for the T-Head TH1520 SoC
riscv: dts: thead: Add TH1520 pin control nodes
dt-bindings: gpio: dwapb: allow gpio-ranges
riscv: dts: thead: Add TH1520 GPIO ranges
riscv: dts: thead: Adjust TH1520 GPIO labels
riscv: dts: thead: Add TH1520 pinctrl settings for UART0
riscv: dtb: thead: Add BeagleV Ahead LEDs
.../bindings/gpio/snps,dw-apb-gpio.yaml | 2 +
.../pinctrl/thead,th1520-pinctrl.yaml | 156 ++++
MAINTAINERS | 1 +
.../boot/dts/thead/th1520-beaglev-ahead.dts | 83 ++
.../boot/dts/thead/th1520-lichee-pi-4a.dts | 28 +
arch/riscv/boot/dts/thead/th1520.dtsi | 53 +-
drivers/pinctrl/Kconfig | 9 +
drivers/pinctrl/Makefile | 1 +
drivers/pinctrl/pinctrl-th1520.c | 796 ++++++++++++++++++
9 files changed, 1113 insertions(+), 16 deletions(-)
create mode 100644 Documentation/devicetree/bindings/pinctrl/thead,th1520-pinctrl.yaml
create mode 100644 drivers/pinctrl/pinctrl-th1520.c
--
2.40.1
^ permalink raw reply [flat|nested] 21+ messages in thread* [PATCH v1 1/8] dt-bindings: pinctrl: Add thead,th1520-pinctrl bindings 2023-12-15 14:38 [PATCH v1 0/8] Add T-Head TH15020 SoC pin control Emil Renner Berthing @ 2023-12-15 14:38 ` Emil Renner Berthing 2023-12-15 20:21 ` Rob Herring 2023-12-20 19:20 ` Linus Walleij 2023-12-15 14:39 ` [PATCH v1 2/8] pinctrl: Add driver for the T-Head TH1520 SoC Emil Renner Berthing ` (6 subsequent siblings) 7 siblings, 2 replies; 21+ messages in thread From: Emil Renner Berthing @ 2023-12-15 14:38 UTC (permalink / raw) To: linux-gpio, devicetree, linux-kernel, linux-riscv Cc: Hoan Tran, Serge Semin, Linus Walleij, Bartosz Golaszewski, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jisheng Zhang, Guo Ren, Fu Wei, Paul Walmsley, Palmer Dabbelt Add bindings for the pin controllers on the T-Head TH1520 RISC-V SoC. Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com> --- .../pinctrl/thead,th1520-pinctrl.yaml | 156 ++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 Documentation/devicetree/bindings/pinctrl/thead,th1520-pinctrl.yaml diff --git a/Documentation/devicetree/bindings/pinctrl/thead,th1520-pinctrl.yaml b/Documentation/devicetree/bindings/pinctrl/thead,th1520-pinctrl.yaml new file mode 100644 index 000000000000..1b1b446cd498 --- /dev/null +++ b/Documentation/devicetree/bindings/pinctrl/thead,th1520-pinctrl.yaml @@ -0,0 +1,156 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pinctrl/thead,th1520-pinctrl.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: T-Head TH1520 SoC pin controller + +maintainers: + - Emil Renner Berthing <emil.renner.berthing@canonical.com> + +description: | + Pinmux and pinconf controller in the T-Head TH1520 RISC-V SoC. + + The TH1520 has 3 groups of pads each controlled from different memory ranges. + Confusingly the memory ranges are named + PADCTRL_AOSYS -> PAD Group 1 + PADCTRL1_APSYS -> PAD Group 2 + PADCTRL0_APSYS -> PAD Group 3 + + Each pad can be muxed individually to up to 5 different functions. For most + pads only a few of those 5 configurations are valid though, and a few pads in + group 1 does not support muxing at all. + + Pinconf is fairly regular except for a few pads in group 1 that either can't + be configured or has some special functions. The rest have configurable drive + strength, input enable, schmitt trigger, slew rate, pull-up and pull-down in + addition to a special strong pull up. + + Certain pads in group 1 can be muxed to AUDIO_PA0 - AUDIO_PA30 functions and + are then meant to be used by the audio co-processor. Each such pad can then + be further muxed to either audio GPIO or one of 4 functions such as UART, I2C + and I2S. If the audio pad is muxed to one of the 4 functions then pinconf is + also configured in different registers. All of this is done from a different + AUDIO_IOCTRL memory range and is left to the audio co-processor for now. + +properties: + compatible: + enum: + - thead,th1520-group1-pinctrl + - thead,th1520-group2-pinctrl + - thead,th1520-group3-pinctrl + + reg: + maxItems: 1 + +patternProperties: + '-[0-9]+$': + type: object + patternProperties: + '-pins$': + type: object + $ref: /schemas/pinctrl/pincfg-node.yaml + description: + A pinctrl node should contain at least one subnode describing one + or more pads and their associated pinmux and pinconf settings. + + properties: + pins: + $ref: /schemas/types.yaml#/definitions/string-array + description: List of pads that properties in the node apply to. + + function: + $ref: /schemas/types.yaml#/definitions/string + enum: [ "0", "1", "2", "3", "4", "5" ] + description: The mux function to select for the given pins. + + bias-disable: true + + bias-pull-up: + type: boolean + + bias-pull-down: + type: boolean + + drive-strength: + enum: [ 1, 2, 3, 5, 7, 8, 10, 12, 13, 15, 16, 18, 20, 21, 23, 25 ] + + input-enable: true + + input-disable: true + + input-schmitt-enable: true + + input-schmitt-disable: true + + slew-rate: + maximum: 1 + + thead,strong-pull-up: + oneOf: + - type: boolean + - $ref: /schemas/types.yaml#/definitions/uint32 + enum: [ 0, 2100 ] + description: Enable or disable strong 2.1kOhm pull-up. + + required: + - pins + + additionalProperties: false + + additionalProperties: false + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + padctrl0_apsys: pinctrl@ec007000 { + compatible = "thead,th1520-group3-pinctrl"; + reg = <0xec007000 0x1000>; + + uart0_pins: uart0-0 { + tx-pins { + pins = "UART0_TXD"; + function = "0"; + bias-disable; + drive-strength = <3>; + input-disable; + input-schmitt-disable; + slew-rate = <0>; + }; + + rx-pins { + pins = "UART0_RXD"; + function = "0"; + bias-disable; + drive-strength = <1>; + input-enable; + input-schmitt-enable; + slew-rate = <0>; + }; + }; + }; + + padctrl1_apsys: pinctrl@e7f3c000 { + compatible = "thead,th1520-group2-pinctrl"; + reg = <0xe7f3c000 0x1000>; + + i2c5_pins: i2c5-0 { + i2c-pins { + pins = "QSPI1_CSN0", /* I2C5_SCL */ + "QSPI1_D0_MOSI"; /* I2C5_SDA */ + function = "2"; + bias-disable; + drive-strength = <7>; + input-enable; + input-schmitt-enable; + slew-rate = <0>; + thead,strong-pull-up; + }; + }; + }; -- 2.40.1 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH v1 1/8] dt-bindings: pinctrl: Add thead,th1520-pinctrl bindings 2023-12-15 14:38 ` [PATCH v1 1/8] dt-bindings: pinctrl: Add thead,th1520-pinctrl bindings Emil Renner Berthing @ 2023-12-15 20:21 ` Rob Herring 2023-12-16 13:57 ` Emil Renner Berthing 2023-12-20 19:20 ` Linus Walleij 1 sibling, 1 reply; 21+ messages in thread From: Rob Herring @ 2023-12-15 20:21 UTC (permalink / raw) To: Emil Renner Berthing Cc: linux-gpio, devicetree, linux-kernel, linux-riscv, Hoan Tran, Serge Semin, Linus Walleij, Bartosz Golaszewski, Andy Shevchenko, Krzysztof Kozlowski, Conor Dooley, Jisheng Zhang, Guo Ren, Fu Wei, Paul Walmsley, Palmer Dabbelt On Fri, Dec 15, 2023 at 03:38:59PM +0100, Emil Renner Berthing wrote: > Add bindings for the pin controllers on the T-Head TH1520 RISC-V SoC. > > Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com> > --- > .../pinctrl/thead,th1520-pinctrl.yaml | 156 ++++++++++++++++++ > 1 file changed, 156 insertions(+) > create mode 100644 Documentation/devicetree/bindings/pinctrl/thead,th1520-pinctrl.yaml > > diff --git a/Documentation/devicetree/bindings/pinctrl/thead,th1520-pinctrl.yaml b/Documentation/devicetree/bindings/pinctrl/thead,th1520-pinctrl.yaml > new file mode 100644 > index 000000000000..1b1b446cd498 > --- /dev/null > +++ b/Documentation/devicetree/bindings/pinctrl/thead,th1520-pinctrl.yaml > @@ -0,0 +1,156 @@ > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) > +%YAML 1.2 > +--- > +$id: http://devicetree.org/schemas/pinctrl/thead,th1520-pinctrl.yaml# > +$schema: http://devicetree.org/meta-schemas/core.yaml# > + > +title: T-Head TH1520 SoC pin controller > + > +maintainers: > + - Emil Renner Berthing <emil.renner.berthing@canonical.com> > + > +description: | > + Pinmux and pinconf controller in the T-Head TH1520 RISC-V SoC. > + > + The TH1520 has 3 groups of pads each controlled from different memory ranges. > + Confusingly the memory ranges are named > + PADCTRL_AOSYS -> PAD Group 1 > + PADCTRL1_APSYS -> PAD Group 2 > + PADCTRL0_APSYS -> PAD Group 3 Are the programming models different? > + > + Each pad can be muxed individually to up to 5 different functions. For most > + pads only a few of those 5 configurations are valid though, and a few pads in > + group 1 does not support muxing at all. > + > + Pinconf is fairly regular except for a few pads in group 1 that either can't > + be configured or has some special functions. The rest have configurable drive > + strength, input enable, schmitt trigger, slew rate, pull-up and pull-down in > + addition to a special strong pull up. > + > + Certain pads in group 1 can be muxed to AUDIO_PA0 - AUDIO_PA30 functions and > + are then meant to be used by the audio co-processor. Each such pad can then > + be further muxed to either audio GPIO or one of 4 functions such as UART, I2C > + and I2S. If the audio pad is muxed to one of the 4 functions then pinconf is > + also configured in different registers. All of this is done from a different > + AUDIO_IOCTRL memory range and is left to the audio co-processor for now. > + > +properties: > + compatible: > + enum: > + - thead,th1520-group1-pinctrl > + - thead,th1520-group2-pinctrl > + - thead,th1520-group3-pinctrl > + > + reg: > + maxItems: 1 > + > +patternProperties: > + '-[0-9]+$': Please make this a bit more specific. "-grp-[0-9]+$"? > + type: object blank line. And move additionalProperties here. Easier to read in the indented cases. > + patternProperties: > + '-pins$': > + type: object > + $ref: /schemas/pinctrl/pincfg-node.yaml > + description: > + A pinctrl node should contain at least one subnode describing one > + or more pads and their associated pinmux and pinconf settings. > + > + properties: > + pins: > + $ref: /schemas/types.yaml#/definitions/string-array Type is defined in pinmux-node.yaml. You need to reference it and drop this. Normally the possible values are listed out. > + description: List of pads that properties in the node apply to. > + > + function: > + $ref: /schemas/types.yaml#/definitions/string > + enum: [ "0", "1", "2", "3", "4", "5" ] > + description: The mux function to select for the given pins. > + > + bias-disable: true > + > + bias-pull-up: > + type: boolean > + > + bias-pull-down: > + type: boolean > + > + drive-strength: > + enum: [ 1, 2, 3, 5, 7, 8, 10, 12, 13, 15, 16, 18, 20, 21, 23, 25 ] > + > + input-enable: true > + > + input-disable: true > + > + input-schmitt-enable: true > + > + input-schmitt-disable: true > + > + slew-rate: > + maximum: 1 > + > + thead,strong-pull-up: > + oneOf: > + - type: boolean > + - $ref: /schemas/types.yaml#/definitions/uint32 > + enum: [ 0, 2100 ] > + description: Enable or disable strong 2.1kOhm pull-up. bias-pull-up can already specify the strength in Ohms. > + > + required: > + - pins > + > + additionalProperties: false > + > + additionalProperties: false > + > +required: > + - compatible > + - reg > + > +additionalProperties: false > + > +examples: > + - | > + padctrl0_apsys: pinctrl@ec007000 { > + compatible = "thead,th1520-group3-pinctrl"; > + reg = <0xec007000 0x1000>; > + > + uart0_pins: uart0-0 { > + tx-pins { > + pins = "UART0_TXD"; > + function = "0"; > + bias-disable; > + drive-strength = <3>; > + input-disable; > + input-schmitt-disable; > + slew-rate = <0>; > + }; > + > + rx-pins { > + pins = "UART0_RXD"; > + function = "0"; > + bias-disable; > + drive-strength = <1>; > + input-enable; > + input-schmitt-enable; > + slew-rate = <0>; > + }; > + }; > + }; > + > + padctrl1_apsys: pinctrl@e7f3c000 { > + compatible = "thead,th1520-group2-pinctrl"; > + reg = <0xe7f3c000 0x1000>; > + > + i2c5_pins: i2c5-0 { > + i2c-pins { > + pins = "QSPI1_CSN0", /* I2C5_SCL */ > + "QSPI1_D0_MOSI"; /* I2C5_SDA */ > + function = "2"; > + bias-disable; > + drive-strength = <7>; > + input-enable; > + input-schmitt-enable; > + slew-rate = <0>; > + thead,strong-pull-up; > + }; > + }; > + }; > -- > 2.40.1 > ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 1/8] dt-bindings: pinctrl: Add thead,th1520-pinctrl bindings 2023-12-15 20:21 ` Rob Herring @ 2023-12-16 13:57 ` Emil Renner Berthing 2023-12-20 19:24 ` Linus Walleij 0 siblings, 1 reply; 21+ messages in thread From: Emil Renner Berthing @ 2023-12-16 13:57 UTC (permalink / raw) To: Rob Herring, Emil Renner Berthing Cc: linux-gpio, devicetree, linux-kernel, linux-riscv, Hoan Tran, Serge Semin, Linus Walleij, Bartosz Golaszewski, Andy Shevchenko, Krzysztof Kozlowski, Conor Dooley, Jisheng Zhang, Guo Ren, Fu Wei, Paul Walmsley, Palmer Dabbelt Rob Herring wrote: > On Fri, Dec 15, 2023 at 03:38:59PM +0100, Emil Renner Berthing wrote: > > Add bindings for the pin controllers on the T-Head TH1520 RISC-V SoC. > > > > Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com> > > --- > > .../pinctrl/thead,th1520-pinctrl.yaml | 156 ++++++++++++++++++ > > 1 file changed, 156 insertions(+) > > create mode 100644 Documentation/devicetree/bindings/pinctrl/thead,th1520-pinctrl.yaml > > > > diff --git a/Documentation/devicetree/bindings/pinctrl/thead,th1520-pinctrl.yaml b/Documentation/devicetree/bindings/pinctrl/thead,th1520-pinctrl.yaml > > new file mode 100644 > > index 000000000000..1b1b446cd498 > > --- /dev/null > > +++ b/Documentation/devicetree/bindings/pinctrl/thead,th1520-pinctrl.yaml > > @@ -0,0 +1,156 @@ > > +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) > > +%YAML 1.2 > > +--- > > +$id: http://devicetree.org/schemas/pinctrl/thead,th1520-pinctrl.yaml# > > +$schema: http://devicetree.org/meta-schemas/core.yaml# > > + > > +title: T-Head TH1520 SoC pin controller > > + > > +maintainers: > > + - Emil Renner Berthing <emil.renner.berthing@canonical.com> > > + > > +description: | > > + Pinmux and pinconf controller in the T-Head TH1520 RISC-V SoC. > > + > > + The TH1520 has 3 groups of pads each controlled from different memory ranges. > > + Confusingly the memory ranges are named > > + PADCTRL_AOSYS -> PAD Group 1 > > + PADCTRL1_APSYS -> PAD Group 2 > > + PADCTRL0_APSYS -> PAD Group 3 > > Are the programming models different? Yes, they control different pads and different number of pads. Pad group 1 also has some special pins that have bespoke pinconf, no pinconf and/or no pinmux and a "gap" in the registers. Also if some day we'll need to set up pinmux on behald of the audio co-processor then pad group 1 will be even more special. > > + > > + Each pad can be muxed individually to up to 5 different functions. For most > > + pads only a few of those 5 configurations are valid though, and a few pads in > > + group 1 does not support muxing at all. > > + > > + Pinconf is fairly regular except for a few pads in group 1 that either can't > > + be configured or has some special functions. The rest have configurable drive > > + strength, input enable, schmitt trigger, slew rate, pull-up and pull-down in > > + addition to a special strong pull up. > > + > > + Certain pads in group 1 can be muxed to AUDIO_PA0 - AUDIO_PA30 functions and > > + are then meant to be used by the audio co-processor. Each such pad can then > > + be further muxed to either audio GPIO or one of 4 functions such as UART, I2C > > + and I2S. If the audio pad is muxed to one of the 4 functions then pinconf is > > + also configured in different registers. All of this is done from a different > > + AUDIO_IOCTRL memory range and is left to the audio co-processor for now. > > + > > +properties: > > + compatible: > > + enum: > > + - thead,th1520-group1-pinctrl > > + - thead,th1520-group2-pinctrl > > + - thead,th1520-group3-pinctrl > > + > > + reg: > > + maxItems: 1 > > + > > +patternProperties: > > + '-[0-9]+$': > > Please make this a bit more specific. "-grp-[0-9]+$"? Oh, I was just trying to copy what other drivers did, but I see now that eg. mediatek,mt6779-pinctrl is not in the majority. Unfortunately "group" already has 2 meanings in this context. One are the pad groups from the datasheet described above and then there are the mux groups in the pinctrl framework, which in this case just contains a single pin since each pin can be muxed individually. Can we come up with a better name or should we just add this 3rd type of group? > > + patternProperties: > > + '-pins$': > > + type: object > > + $ref: /schemas/pinctrl/pincfg-node.yaml > > + description: > > + A pinctrl node should contain at least one subnode describing one > > + or more pads and their associated pinmux and pinconf settings. > > + > > + properties: > > + pins: > > + $ref: /schemas/types.yaml#/definitions/string-array > > Type is defined in pinmux-node.yaml. You need to reference it and drop > this. > > Normally the possible values are listed out. This seems to work for me: allOf: - if: properties: compatible: const: thead,th1520-group1-pinctrl then: patternProperties: '-[0-9]+$': patternProperties: '-pins$': properties: pins: items: enum: - OSC_CLK_IN - OSC_CLK_OUT ... - if: properties: compatible: const: thead,th1520-group2-pinctrl then: patternProperties: '-[0-9]+$': patternProperties: '-pins$': properties: pins: items: enum: - QSPI1_SCLK - QSPI1_CSN0 ... ... Would that be the way to go about it? > > + description: List of pads that properties in the node apply to. > > + > > + function: > > + $ref: /schemas/types.yaml#/definitions/string > > + enum: [ "0", "1", "2", "3", "4", "5" ] > > + description: The mux function to select for the given pins. > > + > > + bias-disable: true > > + > > + bias-pull-up: > > + type: boolean > > + > > + bias-pull-down: > > + type: boolean > > + > > + drive-strength: > > + enum: [ 1, 2, 3, 5, 7, 8, 10, 12, 13, 15, 16, 18, 20, 21, 23, 25 ] > > + > > + input-enable: true > > + > > + input-disable: true > > + > > + input-schmitt-enable: true > > + > > + input-schmitt-disable: true > > + > > + slew-rate: > > + maximum: 1 > > + > > + thead,strong-pull-up: > > + oneOf: > > + - type: boolean > > + - $ref: /schemas/types.yaml#/definitions/uint32 > > + enum: [ 0, 2100 ] > > + description: Enable or disable strong 2.1kOhm pull-up. > > bias-pull-up can already specify the strength in Ohms. The strong pull up is a separate bit that can be enabled independently from the regular pull-up/down, so in theory you could enable both the regular pull-up and the strong pull-up at the same time, or even the regular poll-down and the strong pull-up which is probably not advised. So the idea here was just to make sure that you can do eg. thead,strong-pull-up = <0>; to make sure the bit is cleared. Thanks! /Emil ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 1/8] dt-bindings: pinctrl: Add thead,th1520-pinctrl bindings 2023-12-16 13:57 ` Emil Renner Berthing @ 2023-12-20 19:24 ` Linus Walleij 2023-12-21 12:28 ` Emil Renner Berthing 0 siblings, 1 reply; 21+ messages in thread From: Linus Walleij @ 2023-12-20 19:24 UTC (permalink / raw) To: Emil Renner Berthing Cc: Rob Herring, linux-gpio, devicetree, linux-kernel, linux-riscv, Hoan Tran, Serge Semin, Bartosz Golaszewski, Andy Shevchenko, Krzysztof Kozlowski, Conor Dooley, Jisheng Zhang, Guo Ren, Fu Wei, Paul Walmsley, Palmer Dabbelt On Sat, Dec 16, 2023 at 2:57 PM Emil Renner Berthing <emil.renner.berthing@canonical.com> wrote: > > > + thead,strong-pull-up: > > > + oneOf: > > > + - type: boolean > > > + - $ref: /schemas/types.yaml#/definitions/uint32 > > > + enum: [ 0, 2100 ] > > > + description: Enable or disable strong 2.1kOhm pull-up. > > > > bias-pull-up can already specify the strength in Ohms. > > The strong pull up is a separate bit that can be enabled independently from the > regular pull-up/down, so in theory you could enable both the regular pull-up > and the strong pull-up at the same time, or even the regular poll-down and the > strong pull-up which is probably not advised. bias-pull-up; <- Just regular pulling up the ordinary bias-pull-up = <100>; <- Same thing if the ordinary is 100 Ohm (figure out what resistance it actually is....) bias-pull-up = <21000000>; <- strong pull up bias-pull-up = <21000100>; <- both at the same time > So the idea here was just to make sure that you can do eg. > > thead,strong-pull-up = <0>; > > to make sure the bit is cleared. No use bias-disable; for this. Yours, Linus Walleij ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 1/8] dt-bindings: pinctrl: Add thead,th1520-pinctrl bindings 2023-12-20 19:24 ` Linus Walleij @ 2023-12-21 12:28 ` Emil Renner Berthing 2023-12-21 13:44 ` Linus Walleij 0 siblings, 1 reply; 21+ messages in thread From: Emil Renner Berthing @ 2023-12-21 12:28 UTC (permalink / raw) To: Linus Walleij, Emil Renner Berthing Cc: Rob Herring, linux-gpio, devicetree, linux-kernel, linux-riscv, Hoan Tran, Serge Semin, Bartosz Golaszewski, Andy Shevchenko, Krzysztof Kozlowski, Conor Dooley, Jisheng Zhang, Guo Ren, Fu Wei, Paul Walmsley, Palmer Dabbelt Linus Walleij wrote: > On Sat, Dec 16, 2023 at 2:57 PM Emil Renner Berthing > <emil.renner.berthing@canonical.com> wrote: > > > > > + thead,strong-pull-up: > > > > + oneOf: > > > > + - type: boolean > > > > + - $ref: /schemas/types.yaml#/definitions/uint32 > > > > + enum: [ 0, 2100 ] > > > > + description: Enable or disable strong 2.1kOhm pull-up. > > > > > > bias-pull-up can already specify the strength in Ohms. > > > > The strong pull up is a separate bit that can be enabled independently from the > > regular pull-up/down, so in theory you could enable both the regular pull-up > > and the strong pull-up at the same time, or even the regular poll-down and the > > strong pull-up which is probably not advised. > > bias-pull-up; <- Just regular pulling up the ordinary > bias-pull-up = <100>; <- Same thing if the ordinary is 100 Ohm (figure out what > resistance it actually is....) > bias-pull-up = <21000000>; <- strong pull up > bias-pull-up = <21000100>; <- both at the same time Hmm.. the two pull-ups combined would be a stronger pull-up, eg. lower resistance, right? So you'd need to calculate it using https://en.wikipedia.org/wiki/Series_and_parallel_circuits#Resistance_units_2 The problem is that the documentation doesn't actually mention what will happen if you combine the strong pull-up with the regular bias. My best guess for what happens if you enable the strong pull-up and the regular pull-down is that you create a sort of voltage divider. But how do you represent that as an Ohm value? We would kind of have to, otherwise the pinconf_get callbacks have states that it can't represent. > > So the idea here was just to make sure that you can do eg. > > > > thead,strong-pull-up = <0>; > > > > to make sure the bit is cleared. > > No use bias-disable; for this. > > Yours, > Linus Walleij > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 1/8] dt-bindings: pinctrl: Add thead,th1520-pinctrl bindings 2023-12-21 12:28 ` Emil Renner Berthing @ 2023-12-21 13:44 ` Linus Walleij 2023-12-21 14:07 ` Emil Renner Berthing 0 siblings, 1 reply; 21+ messages in thread From: Linus Walleij @ 2023-12-21 13:44 UTC (permalink / raw) To: Emil Renner Berthing Cc: Rob Herring, linux-gpio, devicetree, linux-kernel, linux-riscv, Hoan Tran, Serge Semin, Bartosz Golaszewski, Andy Shevchenko, Krzysztof Kozlowski, Conor Dooley, Jisheng Zhang, Guo Ren, Fu Wei, Paul Walmsley, Palmer Dabbelt On Thu, Dec 21, 2023 at 1:28 PM Emil Renner Berthing <emil.renner.berthing@canonical.com> wrote: > Linus Walleij wrote: > > On Sat, Dec 16, 2023 at 2:57 PM Emil Renner Berthing > > <emil.renner.berthing@canonical.com> wrote: > > > > > > > + thead,strong-pull-up: > > > > > + oneOf: > > > > > + - type: boolean > > > > > + - $ref: /schemas/types.yaml#/definitions/uint32 > > > > > + enum: [ 0, 2100 ] > > > > > + description: Enable or disable strong 2.1kOhm pull-up. > > > > > > > > bias-pull-up can already specify the strength in Ohms. > > > > > > The strong pull up is a separate bit that can be enabled independently from the > > > regular pull-up/down, so in theory you could enable both the regular pull-up > > > and the strong pull-up at the same time, or even the regular poll-down and the > > > strong pull-up which is probably not advised. > > > > bias-pull-up; <- Just regular pulling up the ordinary > > bias-pull-up = <100>; <- Same thing if the ordinary is 100 Ohm (figure out what > > resistance it actually is....) > > bias-pull-up = <21000000>; <- strong pull up > > bias-pull-up = <21000100>; <- both at the same time > > Hmm.. the two pull-ups combined would be a stronger pull-up, eg. lower > resistance, right? So you'd need to calculate it using > https://en.wikipedia.org/wiki/Series_and_parallel_circuits#Resistance_units_2 Yeah hehe elementary electronics beats me, of course it is in parallel. > The problem is that the documentation doesn't actually mention what will happen > if you combine the strong pull-up with the regular bias. So why even allow it then? Do the people designing boards using this have better documentation than what you have? Then either get that documentation or just don't give them too much rope. Yours, Linus Walleij ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 1/8] dt-bindings: pinctrl: Add thead,th1520-pinctrl bindings 2023-12-21 13:44 ` Linus Walleij @ 2023-12-21 14:07 ` Emil Renner Berthing 2023-12-23 0:18 ` Linus Walleij 0 siblings, 1 reply; 21+ messages in thread From: Emil Renner Berthing @ 2023-12-21 14:07 UTC (permalink / raw) To: Linus Walleij, Emil Renner Berthing Cc: Rob Herring, linux-gpio, devicetree, linux-kernel, linux-riscv, Hoan Tran, Serge Semin, Bartosz Golaszewski, Andy Shevchenko, Krzysztof Kozlowski, Conor Dooley, Jisheng Zhang, Guo Ren, Fu Wei, Paul Walmsley, Palmer Dabbelt Linus Walleij wrote: > On Thu, Dec 21, 2023 at 1:28 PM Emil Renner Berthing > <emil.renner.berthing@canonical.com> wrote: > > Linus Walleij wrote: > > > On Sat, Dec 16, 2023 at 2:57 PM Emil Renner Berthing > > > <emil.renner.berthing@canonical.com> wrote: > > > > > > > > > + thead,strong-pull-up: > > > > > > + oneOf: > > > > > > + - type: boolean > > > > > > + - $ref: /schemas/types.yaml#/definitions/uint32 > > > > > > + enum: [ 0, 2100 ] > > > > > > + description: Enable or disable strong 2.1kOhm pull-up. > > > > > > > > > > bias-pull-up can already specify the strength in Ohms. > > > > > > > > The strong pull up is a separate bit that can be enabled independently from the > > > > regular pull-up/down, so in theory you could enable both the regular pull-up > > > > and the strong pull-up at the same time, or even the regular poll-down and the > > > > strong pull-up which is probably not advised. > > > > > > bias-pull-up; <- Just regular pulling up the ordinary > > > bias-pull-up = <100>; <- Same thing if the ordinary is 100 Ohm (figure out what > > > resistance it actually is....) > > > bias-pull-up = <21000000>; <- strong pull up > > > bias-pull-up = <21000100>; <- both at the same time > > > > Hmm.. the two pull-ups combined would be a stronger pull-up, eg. lower > > resistance, right? So you'd need to calculate it using > > https://en.wikipedia.org/wiki/Series_and_parallel_circuits#Resistance_units_2 > > Yeah hehe elementary electronics beats me, of course it is in parallel. > > > The problem is that the documentation doesn't actually mention what will happen > > if you combine the strong pull-up with the regular bias. > > So why even allow it then? > > Do the people designing boards using this have better documentation than what > you have? Then either get that documentation or just don't give them > too much rope. We can certainly prevent Linux from ever combining the strong pull-up with the regular bias, but that doesn't mean that the vendor u-boot can't find a use for it and might hand over pins in such states Linux then wouldn't know how to handle. If you think its better we could just postpone that problem to when/if it ever happens. ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 1/8] dt-bindings: pinctrl: Add thead,th1520-pinctrl bindings 2023-12-21 14:07 ` Emil Renner Berthing @ 2023-12-23 0:18 ` Linus Walleij 0 siblings, 0 replies; 21+ messages in thread From: Linus Walleij @ 2023-12-23 0:18 UTC (permalink / raw) To: Emil Renner Berthing Cc: Rob Herring, linux-gpio, devicetree, linux-kernel, linux-riscv, Hoan Tran, Serge Semin, Bartosz Golaszewski, Andy Shevchenko, Krzysztof Kozlowski, Conor Dooley, Jisheng Zhang, Guo Ren, Fu Wei, Paul Walmsley, Palmer Dabbelt On Thu, Dec 21, 2023 at 3:07 PM Emil Renner Berthing <emil.renner.berthing@canonical.com> wrote: > Linus Walleij wrote: > > Do the people designing boards using this have better documentation than what > > you have? Then either get that documentation or just don't give them > > too much rope. > > We can certainly prevent Linux from ever combining the strong pull-up with the > regular bias, but that doesn't mean that the vendor u-boot can't find a use for > it and might hand over pins in such states Linux then wouldn't know how to > handle. What you are saying is "there might be people who have access to documentation that I don't have so they do this crazy thing". Clearly you cannot design for that. Print a big fat warning and fail probe if it happens. If U-Boot is using some feature you definitely cannot deal with if this happens, and then the people doing this can very well write a patch for the kernel. > If you think its better we could just postpone that problem to when/if it ever > happens. Yes please. Yours, Linus Walleij ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 1/8] dt-bindings: pinctrl: Add thead,th1520-pinctrl bindings 2023-12-15 14:38 ` [PATCH v1 1/8] dt-bindings: pinctrl: Add thead,th1520-pinctrl bindings Emil Renner Berthing 2023-12-15 20:21 ` Rob Herring @ 2023-12-20 19:20 ` Linus Walleij 2023-12-21 12:21 ` Emil Renner Berthing 1 sibling, 1 reply; 21+ messages in thread From: Linus Walleij @ 2023-12-20 19:20 UTC (permalink / raw) To: Emil Renner Berthing Cc: linux-gpio, devicetree, linux-kernel, linux-riscv, Hoan Tran, Serge Semin, Bartosz Golaszewski, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jisheng Zhang, Guo Ren, Fu Wei, Paul Walmsley, Palmer Dabbelt Hi Emil, thanks for your patch! On Fri, Dec 15, 2023 at 3:39 PM Emil Renner Berthing <emil.renner.berthing@canonical.com> wrote: > + The TH1520 has 3 groups of pads each controlled from different memory ranges. > + Confusingly the memory ranges are named > + PADCTRL_AOSYS -> PAD Group 1 > + PADCTRL1_APSYS -> PAD Group 2 > + PADCTRL0_APSYS -> PAD Group 3 Really, even in the documentation? If you look at the layout on the actual chip, does a pattern emerge? I think some use the north/south/east/west as group names with the BGA chip facing up with the package text correctly readable then it is a bit like a map. > + function: > + $ref: /schemas/types.yaml#/definitions/string > + enum: [ "0", "1", "2", "3", "4", "5" ] > + description: The mux function to select for the given pins. So why is the opaque names "0", "1" etc used, and they will be the same for all pins I bet. Most drivers use a string identifying the actual function here. Such as "i2c", "gpio", etc. Names that are just figures are *impossible* to understand without access to a datasheet. The point of device trees sources are to be human readable, strings of magic numbers are not human readable at all. > + bias-disable: true > + > + bias-pull-up: > + type: boolean > + > + bias-pull-down: > + type: boolean > + > + drive-strength: > + enum: [ 1, 2, 3, 5, 7, 8, 10, 12, 13, 15, 16, 18, 20, 21, 23, 25 ] milliamperes? Then use drive-strength-microamp. If not, explain what each setting means, i.e. the number of max microamps. At which point using drive-strength-microamp and a translation table in the driver may be a better idea. The only reason to use opaque numbers is if 1, 2 (etc) mean something like "number of driver stages" with a current output that varies with technology. > + thead,strong-pull-up: > + oneOf: > + - type: boolean > + - $ref: /schemas/types.yaml#/definitions/uint32 > + enum: [ 0, 2100 ] > + description: Enable or disable strong 2.1kOhm pull-up. Just use bias-pull-up with an argument. bias-pull-up = <2100000>; No argument would be the default setting. No need for custom bindings. > + uart0_pins: uart0-0 { > + tx-pins { > + pins = "UART0_TXD"; Pins have reasonable names, but... > + function = "0"; What about function = "uart_0" hmmm? Yours, Linus Walleij ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 1/8] dt-bindings: pinctrl: Add thead,th1520-pinctrl bindings 2023-12-20 19:20 ` Linus Walleij @ 2023-12-21 12:21 ` Emil Renner Berthing 0 siblings, 0 replies; 21+ messages in thread From: Emil Renner Berthing @ 2023-12-21 12:21 UTC (permalink / raw) To: Linus Walleij, Jisheng Zhang, Guo Ren, Drew Fustini, Emil Renner Berthing Cc: linux-gpio, devicetree, linux-kernel, linux-riscv, Hoan Tran, Serge Semin, Bartosz Golaszewski, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Fu Wei, Paul Walmsley, Palmer Dabbelt Linus Walleij wrote: > Hi Emil, > > thanks for your patch! > > On Fri, Dec 15, 2023 at 3:39 PM Emil Renner Berthing > <emil.renner.berthing@canonical.com> wrote: > > > + The TH1520 has 3 groups of pads each controlled from different memory ranges. > > + Confusingly the memory ranges are named > > + PADCTRL_AOSYS -> PAD Group 1 > > + PADCTRL1_APSYS -> PAD Group 2 > > + PADCTRL0_APSYS -> PAD Group 3 > > Really, even in the documentation? If you look at the layout on the actual > chip, does a pattern emerge? Yes, the documentation is where I got this from: https://git.beagleboard.org/beaglev-ahead/beaglev-ahead/-/blob/main/docs/TH1520%20System%20User%20Manual.pdf The pinmux chapter starting on page 31 only talks about the 3 pad groups, but if you match the base addresses, table 3-8 page 46, with the memory map, table 1-2 page 1, they same base addresses have the PADCTRL names above. > I think some use the north/south/east/west as group names with the BGA > chip facing up with the package text correctly readable then it is a bit > like a map. I don't know if or where such documentation is available. Jisheng, Guo or Drew, do you know? > > + function: > > + $ref: /schemas/types.yaml#/definitions/string > > + enum: [ "0", "1", "2", "3", "4", "5" ] > > + description: The mux function to select for the given pins. > > So why is the opaque names "0", "1" etc used, and they will be the same for > all pins I bet. Most drivers use a string identifying the actual function here. > Such as "i2c", "gpio", etc. > > Names that are just figures are *impossible* to understand without access > to a datasheet. > > The point of device trees sources are to be human readable, strings of > magic numbers are not human readable at all. > > > + bias-disable: true > > + > > + bias-pull-up: > > + type: boolean > > + > > + bias-pull-down: > > + type: boolean > > + > > + drive-strength: > > + enum: [ 1, 2, 3, 5, 7, 8, 10, 12, 13, 15, 16, 18, 20, 21, 23, 25 ] > > milliamperes? Then use drive-strength-microamp. > > If not, explain what each setting means, i.e. the number of max microamps. It *is* the number of mA. I can change it uA if that's better. > At which point using drive-strength-microamp and a translation table in the > driver may be a better idea. That's what it does, just with mA. > The only reason to use opaque numbers is if 1, 2 (etc) mean something like > "number of driver stages" with a current output that varies with technology. > > > + thead,strong-pull-up: > > + oneOf: > > + - type: boolean > > + - $ref: /schemas/types.yaml#/definitions/uint32 > > + enum: [ 0, 2100 ] > > + description: Enable or disable strong 2.1kOhm pull-up. > > Just use bias-pull-up with an argument. > > bias-pull-up = <2100000>; > > No argument would be the default setting. > > No need for custom bindings. > > > + uart0_pins: uart0-0 { > > + tx-pins { > > + pins = "UART0_TXD"; > > Pins have reasonable names, but... > > > + function = "0"; > > What about function = "uart_0" hmmm? > > Yours, > Linus Walleij > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv ^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v1 2/8] pinctrl: Add driver for the T-Head TH1520 SoC 2023-12-15 14:38 [PATCH v1 0/8] Add T-Head TH15020 SoC pin control Emil Renner Berthing 2023-12-15 14:38 ` [PATCH v1 1/8] dt-bindings: pinctrl: Add thead,th1520-pinctrl bindings Emil Renner Berthing @ 2023-12-15 14:39 ` Emil Renner Berthing 2023-12-15 17:27 ` Andy Shevchenko 2023-12-15 14:39 ` [PATCH v1 3/8] riscv: dts: thead: Add TH1520 pin control nodes Emil Renner Berthing ` (5 subsequent siblings) 7 siblings, 1 reply; 21+ messages in thread From: Emil Renner Berthing @ 2023-12-15 14:39 UTC (permalink / raw) To: linux-gpio, devicetree, linux-kernel, linux-riscv Cc: Hoan Tran, Serge Semin, Linus Walleij, Bartosz Golaszewski, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jisheng Zhang, Guo Ren, Fu Wei, Paul Walmsley, Palmer Dabbelt Add pinctrl driver for the T-Head TH1520 RISC-V SoC. Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com> --- MAINTAINERS | 1 + drivers/pinctrl/Kconfig | 9 + drivers/pinctrl/Makefile | 1 + drivers/pinctrl/pinctrl-th1520.c | 796 +++++++++++++++++++++++++++++++ 4 files changed, 807 insertions(+) create mode 100644 drivers/pinctrl/pinctrl-th1520.c diff --git a/MAINTAINERS b/MAINTAINERS index e2c6187a3ac8..7420914c2d77 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -18616,6 +18616,7 @@ M: Fu Wei <wefu@redhat.com> L: linux-riscv@lists.infradead.org S: Maintained F: arch/riscv/boot/dts/thead/ +F: drivers/pinctrl/pinctrl-th1520.c RNBD BLOCK DRIVERS M: Md. Haris Iqbal <haris.iqbal@ionos.com> diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig index 1de4e1edede0..44426fe0f848 100644 --- a/drivers/pinctrl/Kconfig +++ b/drivers/pinctrl/Kconfig @@ -469,6 +469,15 @@ config PINCTRL_TB10X depends on OF && ARC_PLAT_TB10X select GPIOLIB +config PINCTRL_TH1520 + tristate "Pinctrl driver for the T-Head TH1520 SoC" + depends on ARCH_THEAD || COMPILE_TEST + select GENERIC_PINMUX_FUNCTIONS + select GENERIC_PINCONF + select PINMUX + help + This selects the pinctrl driver for T-Head TH1520 RISC-V SoC. + config PINCTRL_ZYNQ bool "Pinctrl driver for Xilinx Zynq" depends on ARCH_ZYNQ diff --git a/drivers/pinctrl/Makefile b/drivers/pinctrl/Makefile index 37575deb7a69..74350d667add 100644 --- a/drivers/pinctrl/Makefile +++ b/drivers/pinctrl/Makefile @@ -48,6 +48,7 @@ obj-$(CONFIG_PINCTRL_ST) += pinctrl-st.o obj-$(CONFIG_PINCTRL_STMFX) += pinctrl-stmfx.o obj-$(CONFIG_PINCTRL_SX150X) += pinctrl-sx150x.o obj-$(CONFIG_PINCTRL_TB10X) += pinctrl-tb10x.o +obj-$(CONFIG_PINCTRL_TH1520) += pinctrl-th1520.o obj-$(CONFIG_PINCTRL_ZYNQMP) += pinctrl-zynqmp.o obj-$(CONFIG_PINCTRL_ZYNQ) += pinctrl-zynq.o diff --git a/drivers/pinctrl/pinctrl-th1520.c b/drivers/pinctrl/pinctrl-th1520.c new file mode 100644 index 000000000000..1efb6ec268e6 --- /dev/null +++ b/drivers/pinctrl/pinctrl-th1520.c @@ -0,0 +1,796 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Pinctrl driver for the T-Head TH1520 SoC + * + * Copyright (C) 2023 Emil Renner Berthing <emil.renner.berthing@canonical.com> + */ + +#include <linux/io.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/of.h> +#include <linux/platform_device.h> +#include <linux/seq_file.h> +#include <linux/spinlock.h> + +#include <linux/pinctrl/pinconf.h> +#include <linux/pinctrl/pinconf-generic.h> +#include <linux/pinctrl/pinctrl.h> +#include <linux/pinctrl/pinmux.h> + +#include "core.h" +#include "pinmux.h" +#include "pinconf.h" + +#define TH1520_PADCFG_IE BIT(9) +#define TH1520_PADCFG_SL BIT(8) +#define TH1520_PADCFG_ST BIT(7) +#define TH1520_PADCFG_SPU BIT(6) +#define TH1520_PADCFG_PS BIT(5) +#define TH1520_PADCFG_PE BIT(4) +#define TH1520_PADCFG_DS GENMASK(3, 0) + +#define TH1520_PULL_DOWN_OHM 44000 /* typ. 44kOhm */ +#define TH1520_PULL_UP_OHM 48000 /* typ. 48kOhm */ +#define TH1520_PULL_STRONG_OHM 2100 /* typ. 2.1kOhm */ + +#define TH1520_FLAG_NO_PADCFG BIT(0) +#define TH1520_FLAG_NO_MUXCFG BIT(1) + +struct th1520_padgroup { + const char *name; + const struct pinctrl_pin_desc *pins; + unsigned int npins; +}; + +struct th1520_pinctrl { + struct pinctrl_desc desc; + struct mutex mutex; /* serialize adding functions */ + raw_spinlock_t lock; /* serialize register access */ + void __iomem *base; + struct pinctrl_dev *pctl; +}; + +static void __iomem *th1520_padcfg(struct th1520_pinctrl *thp, + unsigned int pin) +{ + return thp->base + 4 * (pin / 2); +} + +static unsigned int th1520_padcfg_shift(unsigned int pin) +{ + return 16 * (pin & 0x1U); +} + +static void __iomem *th1520_muxcfg(struct th1520_pinctrl *thp, + unsigned int pin) +{ + return thp->base + 0x400 + 4 * (pin / 8); +} + +static unsigned int th1520_muxcfg_shift(unsigned int pin) +{ + return 4 * (pin & 0x7U); +} + +static const struct pinctrl_pin_desc th1520_group1_pins[] = { + { .number = 0, .name = "OSC_CLK_IN", /* TODO: handle special pad config */ + .drv_data = (void *)(TH1520_FLAG_NO_PADCFG | TH1520_FLAG_NO_MUXCFG) }, + { .number = 1, .name = "OSC_CLK_OUT", + .drv_data = (void *)(TH1520_FLAG_NO_PADCFG | TH1520_FLAG_NO_MUXCFG) }, + { .number = 2, .name = "SYS_RST_N", + .drv_data = (void *)(TH1520_FLAG_NO_PADCFG | TH1520_FLAG_NO_MUXCFG) }, + { .number = 3, .name = "RTC_CLK_IN", /* TODO: handle special pad config */ + .drv_data = (void *)(TH1520_FLAG_NO_PADCFG | TH1520_FLAG_NO_MUXCFG) }, + { .number = 4, .name = "RTC_CLK_OUT", + .drv_data = (void *)(TH1520_FLAG_NO_PADCFG | TH1520_FLAG_NO_MUXCFG) }, + /* + * skip number 5 so we can calculate register + * offsets and shifts from the pin number + */ + { .number = 6, .name = "TEST_MODE", + .drv_data = (void *)(TH1520_FLAG_NO_PADCFG | TH1520_FLAG_NO_MUXCFG) }, + { .number = 7, .name = "DEBUG_MODE", + .drv_data = (void *)TH1520_FLAG_NO_PADCFG }, + { .number = 8, .name = "POR_SEL", + .drv_data = (void *)(TH1520_FLAG_NO_PADCFG | TH1520_FLAG_NO_MUXCFG) }, + PINCTRL_PIN(9, "I2C_AON_SCL"), + PINCTRL_PIN(10, "I2C_AON_SDA"), + PINCTRL_PIN(11, "CPU_JTG_TCLK"), + PINCTRL_PIN(12, "CPU_JTG_TMS"), + PINCTRL_PIN(13, "CPU_JTG_TDI"), + PINCTRL_PIN(14, "CPU_JTG_TDO"), + PINCTRL_PIN(15, "CPU_JTG_TRST"), + PINCTRL_PIN(16, "AOGPIO_7"), + PINCTRL_PIN(17, "AOGPIO_8"), + PINCTRL_PIN(18, "AOGPIO_9"), + PINCTRL_PIN(19, "AOGPIO_10"), + PINCTRL_PIN(20, "AOGPIO_11"), + PINCTRL_PIN(21, "AOGPIO_12"), + PINCTRL_PIN(22, "AOGPIO_13"), + PINCTRL_PIN(23, "AOGPIO_14"), + PINCTRL_PIN(24, "AOGPIO_15"), + PINCTRL_PIN(25, "AUDIO_PA0"), + PINCTRL_PIN(26, "AUDIO_PA1"), + PINCTRL_PIN(27, "AUDIO_PA2"), + PINCTRL_PIN(28, "AUDIO_PA3"), + PINCTRL_PIN(29, "AUDIO_PA4"), + PINCTRL_PIN(30, "AUDIO_PA5"), + PINCTRL_PIN(31, "AUDIO_PA6"), + PINCTRL_PIN(32, "AUDIO_PA7"), + PINCTRL_PIN(33, "AUDIO_PA8"), + PINCTRL_PIN(34, "AUDIO_PA9"), + PINCTRL_PIN(35, "AUDIO_PA10"), + PINCTRL_PIN(36, "AUDIO_PA11"), + PINCTRL_PIN(37, "AUDIO_PA12"), + PINCTRL_PIN(38, "AUDIO_PA13"), + PINCTRL_PIN(39, "AUDIO_PA14"), + PINCTRL_PIN(40, "AUDIO_PA15"), + PINCTRL_PIN(41, "AUDIO_PA16"), + PINCTRL_PIN(42, "AUDIO_PA17"), + PINCTRL_PIN(43, "AUDIO_PA27"), + PINCTRL_PIN(44, "AUDIO_PA28"), + PINCTRL_PIN(45, "AUDIO_PA29"), + PINCTRL_PIN(46, "AUDIO_PA30"), +}; + +static const struct th1520_padgroup th1520_group1 = { + .name = "th1520-group1", + .pins = th1520_group1_pins, + .npins = ARRAY_SIZE(th1520_group1_pins), +}; + +static const struct pinctrl_pin_desc th1520_group2_pins[] = { + PINCTRL_PIN(0, "QSPI1_SCLK"), + PINCTRL_PIN(1, "QSPI1_CSN0"), + PINCTRL_PIN(2, "QSPI1_D0_MOSI"), + PINCTRL_PIN(3, "QSPI1_D1_MISO"), + PINCTRL_PIN(4, "QSPI1_D2_WP"), + PINCTRL_PIN(5, "QSPI1_D3_HOLD"), + PINCTRL_PIN(6, "I2C0_SCL"), + PINCTRL_PIN(7, "I2C0_SDA"), + PINCTRL_PIN(8, "I2C1_SCL"), + PINCTRL_PIN(9, "I2C1_SDA"), + PINCTRL_PIN(10, "UART1_TXD"), + PINCTRL_PIN(11, "UART1_RXD"), + PINCTRL_PIN(12, "UART4_TXD"), + PINCTRL_PIN(13, "UART4_RXD"), + PINCTRL_PIN(14, "UART4_CTSN"), + PINCTRL_PIN(15, "UART4_RTSN"), + PINCTRL_PIN(16, "UART3_TXD"), + PINCTRL_PIN(17, "UART3_RXD"), + PINCTRL_PIN(18, "GPIO0_18"), + PINCTRL_PIN(19, "GPIO0_19"), + PINCTRL_PIN(20, "GPIO0_20"), + PINCTRL_PIN(21, "GPIO0_21"), + PINCTRL_PIN(22, "GPIO0_22"), + PINCTRL_PIN(23, "GPIO0_23"), + PINCTRL_PIN(24, "GPIO0_24"), + PINCTRL_PIN(25, "GPIO0_25"), + PINCTRL_PIN(26, "GPIO0_26"), + PINCTRL_PIN(27, "GPIO0_27"), + PINCTRL_PIN(28, "GPIO0_28"), + PINCTRL_PIN(29, "GPIO0_29"), + PINCTRL_PIN(30, "GPIO0_30"), + PINCTRL_PIN(31, "GPIO0_31"), + PINCTRL_PIN(32, "GPIO1_0"), + PINCTRL_PIN(33, "GPIO1_1"), + PINCTRL_PIN(34, "GPIO1_2"), + PINCTRL_PIN(35, "GPIO1_3"), + PINCTRL_PIN(36, "GPIO1_4"), + PINCTRL_PIN(37, "GPIO1_5"), + PINCTRL_PIN(38, "GPIO1_6"), + PINCTRL_PIN(39, "GPIO1_7"), + PINCTRL_PIN(40, "GPIO1_8"), + PINCTRL_PIN(41, "GPIO1_9"), + PINCTRL_PIN(42, "GPIO1_10"), + PINCTRL_PIN(43, "GPIO1_11"), + PINCTRL_PIN(44, "GPIO1_12"), + PINCTRL_PIN(45, "GPIO1_13"), + PINCTRL_PIN(46, "GPIO1_14"), + PINCTRL_PIN(47, "GPIO1_15"), + PINCTRL_PIN(48, "GPIO1_16"), + PINCTRL_PIN(49, "CLK_OUT_0"), + PINCTRL_PIN(50, "CLK_OUT_1"), + PINCTRL_PIN(51, "CLK_OUT_2"), + PINCTRL_PIN(52, "CLK_OUT_3"), + PINCTRL_PIN(53, "GPIO1_21"), + PINCTRL_PIN(54, "GPIO1_22"), + PINCTRL_PIN(55, "GPIO1_23"), + PINCTRL_PIN(56, "GPIO1_24"), + PINCTRL_PIN(57, "GPIO1_25"), + PINCTRL_PIN(58, "GPIO1_26"), + PINCTRL_PIN(59, "GPIO1_27"), + PINCTRL_PIN(60, "GPIO1_28"), + PINCTRL_PIN(61, "GPIO1_29"), + PINCTRL_PIN(62, "GPIO1_30"), +}; + +static const struct th1520_padgroup th1520_group2 = { + .name = "th1520-group2", + .pins = th1520_group2_pins, + .npins = ARRAY_SIZE(th1520_group2_pins), +}; + +static const struct pinctrl_pin_desc th1520_group3_pins[] = { + PINCTRL_PIN(0, "UART0_TXD"), + PINCTRL_PIN(1, "UART0_RXD"), + PINCTRL_PIN(2, "QSPI0_SCLK"), + PINCTRL_PIN(3, "QSPI0_CSN0"), + PINCTRL_PIN(4, "QSPI0_CSN1"), + PINCTRL_PIN(5, "QSPI0_D0_MOSI"), + PINCTRL_PIN(6, "QSPI0_D1_MISO"), + PINCTRL_PIN(7, "QSPI0_D2_WP"), + PINCTRL_PIN(8, "QSPI1_D3_HOLD"), + PINCTRL_PIN(9, "I2C2_SCL"), + PINCTRL_PIN(10, "I2C2_SDA"), + PINCTRL_PIN(11, "I2C3_SCL"), + PINCTRL_PIN(12, "I2C3_SDA"), + PINCTRL_PIN(13, "GPIO2_13"), + PINCTRL_PIN(14, "SPI_SCLK"), + PINCTRL_PIN(15, "SPI_CSN"), + PINCTRL_PIN(16, "SPI_MOSI"), + PINCTRL_PIN(17, "SPI_MISO"), + PINCTRL_PIN(18, "GPIO2_18"), + PINCTRL_PIN(19, "GPIO2_19"), + PINCTRL_PIN(20, "GPIO2_20"), + PINCTRL_PIN(21, "GPIO2_21"), + PINCTRL_PIN(22, "GPIO2_22"), + PINCTRL_PIN(23, "GPIO2_23"), + PINCTRL_PIN(24, "GPIO2_24"), + PINCTRL_PIN(25, "GPIO2_25"), + PINCTRL_PIN(26, "SDIO0_WPRTN"), + PINCTRL_PIN(27, "SDIO0_DETN"), + PINCTRL_PIN(28, "SDIO1_WPRTN"), + PINCTRL_PIN(29, "SDIO1_DETN"), + PINCTRL_PIN(30, "GPIO2_30"), + PINCTRL_PIN(31, "GPIO2_31"), + PINCTRL_PIN(32, "GPIO3_0"), + PINCTRL_PIN(33, "GPIO3_1"), + PINCTRL_PIN(34, "GPIO3_2"), + PINCTRL_PIN(35, "GPIO3_3"), + PINCTRL_PIN(36, "HDMI_SCL"), + PINCTRL_PIN(37, "HDMI_SDA"), + PINCTRL_PIN(38, "HDMI_CEC"), + PINCTRL_PIN(39, "GMAC0_TX_CLK"), + PINCTRL_PIN(40, "GMAC0_RX_CLK"), + PINCTRL_PIN(41, "GMAC0_TXEN"), + PINCTRL_PIN(42, "GMAC0_TXD0"), + PINCTRL_PIN(43, "GMAC0_TXD1"), + PINCTRL_PIN(44, "GMAC0_TXD2"), + PINCTRL_PIN(45, "GMAC0_TXD3"), + PINCTRL_PIN(46, "GMAC0_RXDV"), + PINCTRL_PIN(47, "GMAC0_RXD0"), + PINCTRL_PIN(48, "GMAC0_RXD1"), + PINCTRL_PIN(49, "GMAC0_RXD2"), + PINCTRL_PIN(50, "GMAC0_RXD3"), + PINCTRL_PIN(51, "GMAC0_MDC"), + PINCTRL_PIN(52, "GMAC0_MDIO"), + PINCTRL_PIN(53, "GMAC0_COL"), + PINCTRL_PIN(54, "GMAC0_CRS"), +}; + +static const struct th1520_padgroup th1520_group3 = { + .name = "th1520-group3", + .pins = th1520_group3_pins, + .npins = ARRAY_SIZE(th1520_group3_pins), +}; + +static int th1520_pinctrl_get_groups_count(struct pinctrl_dev *pctldev) +{ + struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev); + + return thp->desc.npins; +} + +static const char *th1520_pinctrl_get_group_name(struct pinctrl_dev *pctldev, + unsigned int gsel) +{ + struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev); + + return thp->desc.pins[gsel].name; +} + +static int th1520_pinctrl_get_group_pins(struct pinctrl_dev *pctldev, + unsigned int gsel, + const unsigned int **pins, + unsigned int *npins) +{ + struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev); + + *pins = &thp->desc.pins[gsel].number; + *npins = 1; + return 0; +} + +#ifdef CONFIG_DEBUG_FS +static void th1520_pin_dbg_show(struct pinctrl_dev *pctldev, + struct seq_file *s, unsigned int pin) +{ + struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev); + void __iomem *padcfg = th1520_padcfg(thp, pin); + void __iomem *muxcfg = th1520_muxcfg(thp, pin); + unsigned long flags; + u32 pad; + u32 mux; + + raw_spin_lock_irqsave(&thp->lock, flags); + pad = readl_relaxed(padcfg); + mux = readl_relaxed(muxcfg); + raw_spin_unlock_irqrestore(&thp->lock, flags); + + seq_printf(s, "[PADCFG_%03u:0x%x=0x%07x MUXCFG_%03u:0x%x=0x%08x]", + 1 + pin / 2, 0x000 + 4 * (pin / 2), pad, + 1 + pin / 8, 0x400 + 4 * (pin / 8), mux); +} +#else +#define th1520_pin_dbg_show NULL +#endif + +static void th1520_pinctrl_dt_free_map(struct pinctrl_dev *pctldev, + struct pinctrl_map *map, unsigned int nmaps) +{ + unsigned long *seen = NULL; + unsigned int i; + + for (i = 0; i < nmaps; i++) { + if (map[i].type == PIN_MAP_TYPE_CONFIGS_PIN && + map[i].data.configs.configs != seen) { + seen = map[i].data.configs.configs; + kfree(seen); + } + } + + kfree(map); +} + +static int th1520_pinctrl_dt_node_to_map(struct pinctrl_dev *pctldev, + struct device_node *np, + struct pinctrl_map **maps, + unsigned int *num_maps) +{ + struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev); + struct device_node *child; + struct pinctrl_map *map; + unsigned long *configs; + unsigned int nconfigs; + unsigned int nmaps; + int ret; + + nmaps = 0; + for_each_available_child_of_node(np, child) { + int npins = of_property_count_strings(child, "pins"); + + if (npins <= 0) { + of_node_put(child); + return dev_err_probe(thp->pctl->dev, -EINVAL, + "no pins selected for %pOFn.%pOFn\n", + np, child); + } + nmaps += npins; + if (of_property_present(child, "function")) + nmaps += npins; + } + + map = kcalloc(nmaps, sizeof(*map), GFP_KERNEL); + if (!map) + return -ENOMEM; + + nmaps = 0; + mutex_lock(&thp->mutex); + for_each_available_child_of_node(np, child) { + unsigned int rollback = nmaps; + struct property *prop; + const char *funcname; + const char **pgnames; + const char *pinname; + uintptr_t muxdata; + int npins; + + ret = pinconf_generic_parse_dt_config(child, pctldev, &configs, &nconfigs); + if (ret) { + dev_err(thp->pctl->dev, "error parsing pin config of group %pOFn.%pOFn\n", + np, child); + goto put_child; + } + + if (!of_property_read_string(child, "function", &funcname)) { + if (funcname[0] < '0' || funcname[0] > '5' || funcname[1]) { + ret = -EINVAL; + dev_err(thp->pctl->dev, "%pOFn.%pOFn: invalid function '%s'\n", + np, child, funcname); + goto free_configs; + } + + muxdata = funcname[0] - '0'; + funcname = devm_kasprintf(thp->pctl->dev, GFP_KERNEL, "%pOFn.%pOFn", + np, child); + if (!funcname) { + ret = -ENOMEM; + goto free_configs; + } + + npins = of_property_count_strings(child, "pins"); + pgnames = devm_kcalloc(thp->pctl->dev, npins, sizeof(*pgnames), GFP_KERNEL); + if (!pgnames) { + ret = -ENOMEM; + goto free_configs; + } + } else { + funcname = NULL; + } + + npins = 0; + of_property_for_each_string(child, "pins", prop, pinname) { + unsigned int i; + + for (i = 0; i < thp->desc.npins; i++) { + if (!strcmp(pinname, thp->desc.pins[i].name)) + break; + } + if (i == thp->desc.npins) { + nmaps = rollback; + dev_err(thp->pctl->dev, "%pOFn.%pOFn: unknown pin '%s'\n", + np, child, pinname); + goto free_configs; + } + + if (nconfigs) { + map[nmaps].type = PIN_MAP_TYPE_CONFIGS_PIN; + map[nmaps].data.configs.group_or_pin = thp->desc.pins[i].name; + map[nmaps].data.configs.configs = configs; + map[nmaps].data.configs.num_configs = nconfigs; + nmaps += 1; + } + if (funcname) { + pgnames[npins++] = thp->desc.pins[i].name; + map[nmaps].type = PIN_MAP_TYPE_MUX_GROUP; + map[nmaps].data.mux.function = funcname; + map[nmaps].data.mux.group = thp->desc.pins[i].name; + nmaps += 1; + } + } + + if (funcname) { + ret = pinmux_generic_add_function(pctldev, funcname, pgnames, + npins, (void *)muxdata); + if (ret < 0) { + dev_err(thp->pctl->dev, "error adding function %s\n", funcname); + goto put_child; + } + } + } + + *maps = map; + *num_maps = nmaps; + mutex_unlock(&thp->mutex); + return 0; + +free_configs: + kfree(configs); +put_child: + of_node_put(child); + th1520_pinctrl_dt_free_map(pctldev, map, nmaps); + mutex_unlock(&thp->mutex); + return ret; +} + +static const struct pinctrl_ops th1520_pinctrl_ops = { + .get_groups_count = th1520_pinctrl_get_groups_count, + .get_group_name = th1520_pinctrl_get_group_name, + .get_group_pins = th1520_pinctrl_get_group_pins, + .pin_dbg_show = th1520_pin_dbg_show, + .dt_node_to_map = th1520_pinctrl_dt_node_to_map, + .dt_free_map = th1520_pinctrl_dt_free_map, +}; + +static int th1520_pinmux_set_mux(struct pinctrl_dev *pctldev, + unsigned int fsel, unsigned int gsel) +{ + struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev); + const struct function_desc *func = pinmux_generic_get_function(pctldev, fsel); + unsigned int pin = thp->desc.pins[gsel].number; + void __iomem *muxcfg = th1520_muxcfg(thp, pin); + unsigned int shift = th1520_muxcfg_shift(pin); + unsigned long flags; + u32 mask; + u32 value; + + if (!func || (uintptr_t)thp->desc.pins[gsel].drv_data & TH1520_FLAG_NO_MUXCFG) + return -EINVAL; + + mask = 0xfU << shift; + value = ((uintptr_t)func->data & 0xfU) << shift; + + raw_spin_lock_irqsave(&thp->lock, flags); + value |= readl_relaxed(muxcfg) & ~mask; + writel_relaxed(value, muxcfg); + raw_spin_unlock_irqrestore(&thp->lock, flags); + + return 0; +} + +static const struct pinmux_ops th1520_pinmux_ops = { + .get_functions_count = pinmux_generic_get_function_count, + .get_function_name = pinmux_generic_get_function_name, + .get_function_groups = pinmux_generic_get_function_groups, + .set_mux = th1520_pinmux_set_mux, + .strict = true, +}; + +static const u8 th1520_drive_strength_in_mA[16] = { + 1, 2, 3, 5, 7, 8, 10, 12, 13, 15, 16, 18, 20, 21, 23, 25, +}; + +static u16 th1520_drive_strength_from_mA(u32 arg) +{ + u16 v; + + for (v = 0; v < ARRAY_SIZE(th1520_drive_strength_in_mA) - 1; v++) { + if (arg <= th1520_drive_strength_in_mA[v]) + break; + } + + return v; +} + +static int th1520_padcfg_rmw(struct th1520_pinctrl *thp, unsigned int pin, + u16 _mask, u16 _value) +{ + void __iomem *padcfg = th1520_padcfg(thp, pin); + unsigned int shift = th1520_padcfg_shift(pin); + u32 mask = (u32)_mask << shift; + u32 value = (u32)_value << shift; + unsigned long flags; + + raw_spin_lock_irqsave(&thp->lock, flags); + value |= readl_relaxed(padcfg) & ~mask; + writel_relaxed(value, padcfg); + raw_spin_unlock_irqrestore(&thp->lock, flags); + return 0; +} + +#define PIN_CONFIG_THEAD_STRONG_PULL_UP (PIN_CONFIG_END + 1) +static const struct pinconf_generic_params th1520_pinconf_custom_params[] = { + { "thead,strong-pull-up", PIN_CONFIG_THEAD_STRONG_PULL_UP, 1 }, +}; + +#ifdef CONFIG_DEBUG_FS +static const struct pin_config_item th1520_pinconf_custom_conf_items[] = { + PCONFDUMP(PIN_CONFIG_THEAD_STRONG_PULL_UP, "input bias strong pull-up", "ohms", true), +}; +static_assert(ARRAY_SIZE(th1520_pinconf_custom_conf_items) == + ARRAY_SIZE(th1520_pinconf_custom_params)); +#else +#define th1520_pinconf_custom_conf_items NULL +#endif + +static int th1520_pinconf_get(struct pinctrl_dev *pctldev, + unsigned int pin, unsigned long *config) +{ + struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev); + const struct pin_desc *desc = pin_desc_get(pctldev, pin); + bool enabled; + int param; + u32 value; + u32 arg; + + if ((uintptr_t)desc->drv_data & TH1520_FLAG_NO_PADCFG) + return -ENOTSUPP; + + value = readl_relaxed(th1520_padcfg(thp, pin)); + value = (value >> th1520_padcfg_shift(pin)) & 0x3ffU; + + param = pinconf_to_config_param(*config); + switch (param) { + case PIN_CONFIG_BIAS_DISABLE: + enabled = !(value & TH1520_PADCFG_PE); + arg = 0; + break; + case PIN_CONFIG_BIAS_PULL_DOWN: + enabled = (value & (TH1520_PADCFG_PE | TH1520_PADCFG_PS)) == + TH1520_PADCFG_PE; + arg = enabled ? TH1520_PULL_DOWN_OHM : 0; + break; + case PIN_CONFIG_BIAS_PULL_UP: + enabled = (value & (TH1520_PADCFG_PE | TH1520_PADCFG_PS)) == + (TH1520_PADCFG_PE | TH1520_PADCFG_PS); + arg = enabled ? TH1520_PULL_UP_OHM : 0; + break; + case PIN_CONFIG_DRIVE_STRENGTH: + enabled = true; + arg = th1520_drive_strength_in_mA[value & TH1520_PADCFG_DS]; + break; + case PIN_CONFIG_INPUT_ENABLE: + enabled = value & TH1520_PADCFG_IE; + arg = enabled; + break; + case PIN_CONFIG_INPUT_SCHMITT_ENABLE: + enabled = value & TH1520_PADCFG_ST; + arg = enabled; + break; + case PIN_CONFIG_SLEW_RATE: + enabled = value & TH1520_PADCFG_SL; + arg = enabled; + break; + case PIN_CONFIG_THEAD_STRONG_PULL_UP: + enabled = value & TH1520_PADCFG_SPU; + arg = enabled ? TH1520_PULL_STRONG_OHM : 0; + break; + default: + return -ENOTSUPP; + } + + *config = pinconf_to_config_packed(param, arg); + return enabled ? 0 : -EINVAL; +} + +static int th1520_pinconf_group_get(struct pinctrl_dev *pctldev, + unsigned int gsel, unsigned long *config) +{ + struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev); + unsigned int pin = thp->desc.pins[gsel].number; + + return th1520_pinconf_get(pctldev, pin, config); +} + +static int th1520_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin, + unsigned long *configs, unsigned int num_configs) +{ + struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev); + unsigned int i; + u16 mask = 0; + u16 value = 0; + + for (i = 0; i < num_configs; i++) { + int param = pinconf_to_config_param(configs[i]); + u32 arg = pinconf_to_config_argument(configs[i]); + + switch (param) { + case PIN_CONFIG_BIAS_DISABLE: + mask |= TH1520_PADCFG_PE; + value &= ~TH1520_PADCFG_PE; + break; + case PIN_CONFIG_BIAS_PULL_DOWN: + if (arg == 0) + return -ENOTSUPP; + mask |= TH1520_PADCFG_PS; + value &= ~TH1520_PADCFG_PS; + break; + case PIN_CONFIG_BIAS_PULL_UP: + if (arg == 0) + return -ENOTSUPP; + mask |= TH1520_PADCFG_PS; + value |= TH1520_PADCFG_PS; + break; + case PIN_CONFIG_DRIVE_STRENGTH: + mask |= TH1520_PADCFG_DS; + value = (value & ~TH1520_PADCFG_DS) | + th1520_drive_strength_from_mA(arg); + break; + case PIN_CONFIG_INPUT_ENABLE: + mask |= TH1520_PADCFG_IE; + if (arg) + value |= TH1520_PADCFG_IE; + else + value &= ~TH1520_PADCFG_IE; + break; + case PIN_CONFIG_INPUT_SCHMITT_ENABLE: + mask |= TH1520_PADCFG_ST; + if (arg) + value |= TH1520_PADCFG_ST; + else + value &= ~TH1520_PADCFG_ST; + break; + case PIN_CONFIG_SLEW_RATE: + mask |= TH1520_PADCFG_SL; + if (arg) + value |= TH1520_PADCFG_SL; + else + value &= ~TH1520_PADCFG_SL; + break; + case PIN_CONFIG_THEAD_STRONG_PULL_UP: + mask |= TH1520_PADCFG_SPU; + if (arg) + value |= TH1520_PADCFG_SPU; + else + value &= ~TH1520_PADCFG_SPU; + break; + default: + return -ENOTSUPP; + } + } + + return th1520_padcfg_rmw(thp, pin, mask, value); +} + +static int th1520_pinconf_group_set(struct pinctrl_dev *pctldev, + unsigned int gsel, + unsigned long *configs, + unsigned int num_configs) +{ + struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev); + unsigned int pin = thp->desc.pins[gsel].number; + + return th1520_pinconf_set(pctldev, pin, configs, num_configs); +} + +#ifdef CONFIG_DEBUG_FS +static void th1520_pinconf_dbg_show(struct pinctrl_dev *pctldev, + struct seq_file *s, unsigned int pin) +{ + struct th1520_pinctrl *thp = pinctrl_dev_get_drvdata(pctldev); + u32 value = readl_relaxed(th1520_padcfg(thp, pin)); + + value = (value >> th1520_padcfg_shift(pin)) & 0x3ffU; + + seq_printf(s, " [0x%03x]", value); +} +#else +#define th1520_pinconf_dbg_show NULL +#endif + +static const struct pinconf_ops th1520_pinconf_ops = { + .pin_config_get = th1520_pinconf_get, + .pin_config_group_get = th1520_pinconf_group_get, + .pin_config_set = th1520_pinconf_set, + .pin_config_group_set = th1520_pinconf_group_set, + .pin_config_dbg_show = th1520_pinconf_dbg_show, + .is_generic = true, +}; + +static int th1520_pinctrl_probe(struct platform_device *pdev) +{ + const struct th1520_padgroup *group = device_get_match_data(&pdev->dev); + struct th1520_pinctrl *thp; + int ret; + + thp = devm_kzalloc(&pdev->dev, sizeof(*thp), GFP_KERNEL); + if (!thp) + return -ENOMEM; + + thp->base = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(thp->base)) + return PTR_ERR(thp->base); + + thp->desc.name = group->name; + thp->desc.pins = group->pins; + thp->desc.npins = group->npins; + thp->desc.pctlops = &th1520_pinctrl_ops; + thp->desc.pmxops = &th1520_pinmux_ops; + thp->desc.confops = &th1520_pinconf_ops; + thp->desc.owner = THIS_MODULE; + thp->desc.num_custom_params = ARRAY_SIZE(th1520_pinconf_custom_params); + thp->desc.custom_params = th1520_pinconf_custom_params; + thp->desc.custom_conf_items = th1520_pinconf_custom_conf_items; + mutex_init(&thp->mutex); + raw_spin_lock_init(&thp->lock); + + ret = devm_pinctrl_register_and_init(&pdev->dev, &thp->desc, thp, &thp->pctl); + if (ret) + return dev_err_probe(&pdev->dev, ret, "could not register pinctrl driver\n"); + + return pinctrl_enable(thp->pctl); +} + +static const struct of_device_id th1520_pinctrl_of_match[] = { + { .compatible = "thead,th1520-group1-pinctrl", .data = &th1520_group1 }, + { .compatible = "thead,th1520-group2-pinctrl", .data = &th1520_group2 }, + { .compatible = "thead,th1520-group3-pinctrl", .data = &th1520_group3 }, + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, th1520_pinctrl_of_match); + +static struct platform_driver th1520_pinctrl_driver = { + .probe = th1520_pinctrl_probe, + .driver = { + .name = "pinctrl-th1520", + .of_match_table = th1520_pinctrl_of_match, + }, +}; +module_platform_driver(th1520_pinctrl_driver); + +MODULE_DESCRIPTION("Pinctrl driver for the T-Head TH1520 SoC"); +MODULE_AUTHOR("Emil Renner Berthing <emil.renner.berthing@canonical.com>"); +MODULE_LICENSE("GPL"); -- 2.40.1 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH v1 2/8] pinctrl: Add driver for the T-Head TH1520 SoC 2023-12-15 14:39 ` [PATCH v1 2/8] pinctrl: Add driver for the T-Head TH1520 SoC Emil Renner Berthing @ 2023-12-15 17:27 ` Andy Shevchenko 0 siblings, 0 replies; 21+ messages in thread From: Andy Shevchenko @ 2023-12-15 17:27 UTC (permalink / raw) To: Emil Renner Berthing Cc: linux-gpio, devicetree, linux-kernel, linux-riscv, Hoan Tran, Serge Semin, Linus Walleij, Bartosz Golaszewski, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jisheng Zhang, Guo Ren, Fu Wei, Paul Walmsley, Palmer Dabbelt On Fri, Dec 15, 2023 at 03:39:00PM +0100, Emil Renner Berthing wrote: > Add pinctrl driver for the T-Head TH1520 RISC-V SoC. ... + array_size.h + bits.h + device.h (and so on, please make sure you follow IWYU principle -- "include what you use") > +#include <linux/io.h> > +#include <linux/mod_devicetable.h> > +#include <linux/module.h> > +#include <linux/mutex.h> > +#include <linux/of.h> Can you use device property API instead? (I briefly checked, all of the used of_ ones have the respective generic implementations either in fwnode_property_ or device_property_ namespace). OTOH, it's used in xlate/map functions which have device_node as a parameter... > +#include <linux/platform_device.h> > +#include <linux/seq_file.h> > +#include <linux/spinlock.h> ... > +#include "core.h" > +#include "pinmux.h" > +#include "pinconf.h" All of them are needed? ... > +static unsigned int th1520_padcfg_shift(unsigned int pin) > +{ > + return 16 * (pin & 0x1U); BIT(0) ? > +} ... > +static unsigned int th1520_muxcfg_shift(unsigned int pin) > +{ > + return 4 * (pin & 0x7U); GENMASK() ? > +} ... > + return dev_err_probe(thp->pctl->dev, -EINVAL, > + "no pins selected for %pOFn.%pOFn\n", > + np, child); > + dev_err(thp->pctl->dev, "error parsing pin config of group %pOFn.%pOFn\n", > + np, child); In the very same function you are using dev_err_probe(), please make sure you use the same for all error messages as it will be a unified format (in case of dev_err_probe() or if you explicitly do that with dev_err() calls). > + } ... > +static const struct pinctrl_ops th1520_pinctrl_ops = { > + .get_groups_count = th1520_pinctrl_get_groups_count, > + .get_group_name = th1520_pinctrl_get_group_name, > + .get_group_pins = th1520_pinctrl_get_group_pins, > + .pin_dbg_show = th1520_pin_dbg_show, Is ifdeffery needed for this one? > + .dt_node_to_map = th1520_pinctrl_dt_node_to_map, > + .dt_free_map = th1520_pinctrl_dt_free_map, Is ifdeffery needed for these two? > +}; ... > + mask = 0xfU << shift; > + value = ((uintptr_t)func->data & 0xfU) << shift; GENMASK() in both cases. > + raw_spin_lock_irqsave(&thp->lock, flags); > + value |= readl_relaxed(muxcfg) & ~mask; Instead of above, use the traditional pattern value = read() value = (value & ~mask) | (newval & mask); write() where newval is defined with a proper type and you get rid of all those ugly castings at once. > + writel_relaxed(value, muxcfg); > + raw_spin_unlock_irqrestore(&thp->lock, flags); ... > +static u16 th1520_drive_strength_from_mA(u32 arg) > +{ > + u16 v; > + > + for (v = 0; v < ARRAY_SIZE(th1520_drive_strength_in_mA) - 1; v++) { You may drop -1 here AFAIU (see below). > + if (arg <= th1520_drive_strength_in_mA[v]) > + break; return directly. > + } > + return v; return explicit value which will be robust against changes in the for-loop or elsewhere in the code. > +} ... > +static int th1520_padcfg_rmw(struct th1520_pinctrl *thp, unsigned int pin, > + u16 _mask, u16 _value) Why not naming them without underscores? > +{ > + void __iomem *padcfg = th1520_padcfg(thp, pin); > + unsigned int shift = th1520_padcfg_shift(pin); > + u32 mask = (u32)_mask << shift; > + u32 value = (u32)_value << shift; Oh, no castings, please. > + unsigned long flags; > + > + raw_spin_lock_irqsave(&thp->lock, flags); Use cleanup.h. > + value |= readl_relaxed(padcfg) & ~mask; > + writel_relaxed(value, padcfg); > + raw_spin_unlock_irqrestore(&thp->lock, flags); > + return 0; > +} ... > +#define PIN_CONFIG_THEAD_STRONG_PULL_UP (PIN_CONFIG_END + 1) Oh, custom flag! Linus, what is the expected approach for custom flags like this? I believe this is quite error prone. ... > + value = readl_relaxed(th1520_padcfg(thp, pin)); > + value = (value >> th1520_padcfg_shift(pin)) & 0x3ffU; GENMASK() and in many other places like this. ... > + enabled = value & TH1520_PADCFG_IE; > + arg = enabled; Assigning boolean to integer... Hmm... > + break; > + case PIN_CONFIG_INPUT_SCHMITT_ENABLE: > + enabled = value & TH1520_PADCFG_ST; > + arg = enabled; > + break; > + case PIN_CONFIG_SLEW_RATE: > + enabled = value & TH1520_PADCFG_SL; > + arg = enabled; > + break; ... > +static int th1520_pinctrl_probe(struct platform_device *pdev) > +{ struct device *dev = &pdev->dev; may give you some benefits. > + const struct th1520_padgroup *group = device_get_match_data(&pdev->dev); > + struct th1520_pinctrl *thp; > + int ret; > + > + thp = devm_kzalloc(&pdev->dev, sizeof(*thp), GFP_KERNEL); > + if (!thp) > + return -ENOMEM; > + > + thp->base = devm_platform_ioremap_resource(pdev, 0); > + if (IS_ERR(thp->base)) > + return PTR_ERR(thp->base); > + > + thp->desc.name = group->name; > + thp->desc.pins = group->pins; > + thp->desc.npins = group->npins; > + thp->desc.pctlops = &th1520_pinctrl_ops; > + thp->desc.pmxops = &th1520_pinmux_ops; > + thp->desc.confops = &th1520_pinconf_ops; > + thp->desc.owner = THIS_MODULE; > + thp->desc.num_custom_params = ARRAY_SIZE(th1520_pinconf_custom_params); > + thp->desc.custom_params = th1520_pinconf_custom_params; > + thp->desc.custom_conf_items = th1520_pinconf_custom_conf_items; > + mutex_init(&thp->mutex); > + raw_spin_lock_init(&thp->lock); > + > + ret = devm_pinctrl_register_and_init(&pdev->dev, &thp->desc, thp, &thp->pctl); > + if (ret) > + return dev_err_probe(&pdev->dev, ret, "could not register pinctrl driver\n"); > + > + return pinctrl_enable(thp->pctl); > +} -- With Best Regards, Andy Shevchenko ^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v1 3/8] riscv: dts: thead: Add TH1520 pin control nodes 2023-12-15 14:38 [PATCH v1 0/8] Add T-Head TH15020 SoC pin control Emil Renner Berthing 2023-12-15 14:38 ` [PATCH v1 1/8] dt-bindings: pinctrl: Add thead,th1520-pinctrl bindings Emil Renner Berthing 2023-12-15 14:39 ` [PATCH v1 2/8] pinctrl: Add driver for the T-Head TH1520 SoC Emil Renner Berthing @ 2023-12-15 14:39 ` Emil Renner Berthing 2023-12-15 14:39 ` [PATCH v1 4/8] dt-bindings: gpio: dwapb: allow gpio-ranges Emil Renner Berthing ` (4 subsequent siblings) 7 siblings, 0 replies; 21+ messages in thread From: Emil Renner Berthing @ 2023-12-15 14:39 UTC (permalink / raw) To: linux-gpio, devicetree, linux-kernel, linux-riscv Cc: Hoan Tran, Serge Semin, Linus Walleij, Bartosz Golaszewski, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jisheng Zhang, Guo Ren, Fu Wei, Paul Walmsley, Palmer Dabbelt Add nodes for pin controllers on the T-Head TH1520 RISC-V SoC. Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com> --- arch/riscv/boot/dts/thead/th1520.dtsi | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/arch/riscv/boot/dts/thead/th1520.dtsi b/arch/riscv/boot/dts/thead/th1520.dtsi index ba4d2c673ac8..397d5c71bd3d 100644 --- a/arch/riscv/boot/dts/thead/th1520.dtsi +++ b/arch/riscv/boot/dts/thead/th1520.dtsi @@ -242,6 +242,11 @@ portd: gpio-controller@0 { }; }; + padctrl1_apsys: pinctrl@ffe7f3c000 { + compatible = "thead,th1520-group2-pinctrl"; + reg = <0xff 0xe7f3c000 0x0 0x1000>; + }; + gpio0: gpio@ffec005000 { compatible = "snps,dw-apb-gpio"; reg = <0xff 0xec005000 0x0 0x1000>; @@ -278,6 +283,11 @@ portb: gpio-controller@0 { }; }; + padctrl0_apsys: pinctrl@ffec007000 { + compatible = "thead,th1520-group3-pinctrl"; + reg = <0xff 0xec007000 0x0 0x1000>; + }; + uart2: serial@ffec010000 { compatible = "snps,dw-apb-uart"; reg = <0xff 0xec010000 0x0 0x4000>; @@ -414,6 +424,11 @@ porte: gpio-controller@0 { }; }; + padctrl_aosys: pinctrl@fffff4a000 { + compatible = "thead,th1520-group1-pinctrl"; + reg = <0xff 0xfff4a000 0x0 0x2000>; + }; + ao_gpio1: gpio@fffff52000 { compatible = "snps,dw-apb-gpio"; reg = <0xff 0xfff52000 0x0 0x1000>; -- 2.40.1 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v1 4/8] dt-bindings: gpio: dwapb: allow gpio-ranges 2023-12-15 14:38 [PATCH v1 0/8] Add T-Head TH15020 SoC pin control Emil Renner Berthing ` (2 preceding siblings ...) 2023-12-15 14:39 ` [PATCH v1 3/8] riscv: dts: thead: Add TH1520 pin control nodes Emil Renner Berthing @ 2023-12-15 14:39 ` Emil Renner Berthing 2023-12-15 20:21 ` Rob Herring 2023-12-18 10:05 ` Bartosz Golaszewski 2023-12-15 14:39 ` [PATCH v1 5/8] riscv: dts: thead: Add TH1520 GPIO ranges Emil Renner Berthing ` (3 subsequent siblings) 7 siblings, 2 replies; 21+ messages in thread From: Emil Renner Berthing @ 2023-12-15 14:39 UTC (permalink / raw) To: linux-gpio, devicetree, linux-kernel, linux-riscv Cc: Hoan Tran, Serge Semin, Linus Walleij, Bartosz Golaszewski, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jisheng Zhang, Guo Ren, Fu Wei, Paul Walmsley, Palmer Dabbelt Allow the generic gpio-ranges property so GPIOs can be mapped to their corresponding pin. This way control of GPIO on pins that are already used by other peripherals can be denied and basic pinconf can be done on pin controllers that support it. Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com> --- Documentation/devicetree/bindings/gpio/snps,dw-apb-gpio.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/gpio/snps,dw-apb-gpio.yaml b/Documentation/devicetree/bindings/gpio/snps,dw-apb-gpio.yaml index eefe7b345286..ab2afc0e4153 100644 --- a/Documentation/devicetree/bindings/gpio/snps,dw-apb-gpio.yaml +++ b/Documentation/devicetree/bindings/gpio/snps,dw-apb-gpio.yaml @@ -65,6 +65,8 @@ patternProperties: minItems: 1 maxItems: 32 + gpio-ranges: true + ngpios: default: 32 minimum: 1 -- 2.40.1 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [PATCH v1 4/8] dt-bindings: gpio: dwapb: allow gpio-ranges 2023-12-15 14:39 ` [PATCH v1 4/8] dt-bindings: gpio: dwapb: allow gpio-ranges Emil Renner Berthing @ 2023-12-15 20:21 ` Rob Herring 2023-12-18 10:05 ` Bartosz Golaszewski 1 sibling, 0 replies; 21+ messages in thread From: Rob Herring @ 2023-12-15 20:21 UTC (permalink / raw) To: Emil Renner Berthing Cc: Fu Wei, Conor Dooley, Bartosz Golaszewski, Hoan Tran, Linus Walleij, Palmer Dabbelt, Rob Herring, linux-gpio, Andy Shevchenko, linux-kernel, Jisheng Zhang, Serge Semin, Krzysztof Kozlowski, Guo Ren, linux-riscv, Paul Walmsley, devicetree On Fri, 15 Dec 2023 15:39:02 +0100, Emil Renner Berthing wrote: > Allow the generic gpio-ranges property so GPIOs can be mapped to their > corresponding pin. This way control of GPIO on pins that are already used > by other peripherals can be denied and basic pinconf can be done on pin > controllers that support it. > > Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com> > --- > Documentation/devicetree/bindings/gpio/snps,dw-apb-gpio.yaml | 2 ++ > 1 file changed, 2 insertions(+) > Acked-by: Rob Herring <robh@kernel.org> ^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [PATCH v1 4/8] dt-bindings: gpio: dwapb: allow gpio-ranges 2023-12-15 14:39 ` [PATCH v1 4/8] dt-bindings: gpio: dwapb: allow gpio-ranges Emil Renner Berthing 2023-12-15 20:21 ` Rob Herring @ 2023-12-18 10:05 ` Bartosz Golaszewski 1 sibling, 0 replies; 21+ messages in thread From: Bartosz Golaszewski @ 2023-12-18 10:05 UTC (permalink / raw) To: Emil Renner Berthing Cc: linux-gpio, devicetree, linux-kernel, linux-riscv, Hoan Tran, Serge Semin, Linus Walleij, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jisheng Zhang, Guo Ren, Fu Wei, Paul Walmsley, Palmer Dabbelt On Fri, Dec 15, 2023 at 3:39 PM Emil Renner Berthing <emil.renner.berthing@canonical.com> wrote: > > Allow the generic gpio-ranges property so GPIOs can be mapped to their > corresponding pin. This way control of GPIO on pins that are already used > by other peripherals can be denied and basic pinconf can be done on pin > controllers that support it. > > Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com> > --- > Documentation/devicetree/bindings/gpio/snps,dw-apb-gpio.yaml | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/Documentation/devicetree/bindings/gpio/snps,dw-apb-gpio.yaml b/Documentation/devicetree/bindings/gpio/snps,dw-apb-gpio.yaml > index eefe7b345286..ab2afc0e4153 100644 > --- a/Documentation/devicetree/bindings/gpio/snps,dw-apb-gpio.yaml > +++ b/Documentation/devicetree/bindings/gpio/snps,dw-apb-gpio.yaml > @@ -65,6 +65,8 @@ patternProperties: > minItems: 1 > maxItems: 32 > > + gpio-ranges: true > + > ngpios: > default: 32 > minimum: 1 > -- > 2.40.1 > Applied, thanks! Bart ^ permalink raw reply [flat|nested] 21+ messages in thread
* [PATCH v1 5/8] riscv: dts: thead: Add TH1520 GPIO ranges 2023-12-15 14:38 [PATCH v1 0/8] Add T-Head TH15020 SoC pin control Emil Renner Berthing ` (3 preceding siblings ...) 2023-12-15 14:39 ` [PATCH v1 4/8] dt-bindings: gpio: dwapb: allow gpio-ranges Emil Renner Berthing @ 2023-12-15 14:39 ` Emil Renner Berthing 2023-12-15 14:39 ` [PATCH v1 6/8] riscv: dts: thead: Adjust TH1520 GPIO labels Emil Renner Berthing ` (2 subsequent siblings) 7 siblings, 0 replies; 21+ messages in thread From: Emil Renner Berthing @ 2023-12-15 14:39 UTC (permalink / raw) To: linux-gpio, devicetree, linux-kernel, linux-riscv Cc: Hoan Tran, Serge Semin, Linus Walleij, Bartosz Golaszewski, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jisheng Zhang, Guo Ren, Fu Wei, Paul Walmsley, Palmer Dabbelt Add gpio-ranges properties to the TH1520 device tree, so user space can change basic pinconf settings for GPIOs and are not allowed to use pads already used by other functions. Adjust number of GPIOs available for the different controllers. Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com> --- arch/riscv/boot/dts/thead/th1520.dtsi | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/riscv/boot/dts/thead/th1520.dtsi b/arch/riscv/boot/dts/thead/th1520.dtsi index 397d5c71bd3d..d5e2378a1afa 100644 --- a/arch/riscv/boot/dts/thead/th1520.dtsi +++ b/arch/riscv/boot/dts/thead/th1520.dtsi @@ -217,6 +217,7 @@ portc: gpio-controller@0 { gpio-controller; #gpio-cells = <2>; ngpios = <32>; + gpio-ranges = <&padctrl0_apsys 0 0 32>; reg = <0>; interrupt-controller; #interrupt-cells = <2>; @@ -234,7 +235,8 @@ portd: gpio-controller@0 { compatible = "snps,dw-apb-gpio-port"; gpio-controller; #gpio-cells = <2>; - ngpios = <32>; + ngpios = <23>; + gpio-ranges = <&padctrl0_apsys 0 32 23>; reg = <0>; interrupt-controller; #interrupt-cells = <2>; @@ -258,6 +260,7 @@ porta: gpio-controller@0 { gpio-controller; #gpio-cells = <2>; ngpios = <32>; + gpio-ranges = <&padctrl1_apsys 0 0 32>; reg = <0>; interrupt-controller; #interrupt-cells = <2>; @@ -275,7 +278,8 @@ portb: gpio-controller@0 { compatible = "snps,dw-apb-gpio-port"; gpio-controller; #gpio-cells = <2>; - ngpios = <32>; + ngpios = <31>; + gpio-ranges = <&padctrl1_apsys 0 32 31>; reg = <0>; interrupt-controller; #interrupt-cells = <2>; @@ -416,7 +420,8 @@ porte: gpio-controller@0 { compatible = "snps,dw-apb-gpio-port"; gpio-controller; #gpio-cells = <2>; - ngpios = <32>; + ngpios = <16>; + gpio-ranges = <&padctrl_aosys 0 9 16>; reg = <0>; interrupt-controller; #interrupt-cells = <2>; @@ -439,7 +444,8 @@ portf: gpio-controller@0 { compatible = "snps,dw-apb-gpio-port"; gpio-controller; #gpio-cells = <2>; - ngpios = <32>; + ngpios = <23>; + gpio-ranges = <&padctrl_aosys 0 25 22>, <&padctrl_aosys 22 7 1>; reg = <0>; interrupt-controller; #interrupt-cells = <2>; -- 2.40.1 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v1 6/8] riscv: dts: thead: Adjust TH1520 GPIO labels 2023-12-15 14:38 [PATCH v1 0/8] Add T-Head TH15020 SoC pin control Emil Renner Berthing ` (4 preceding siblings ...) 2023-12-15 14:39 ` [PATCH v1 5/8] riscv: dts: thead: Add TH1520 GPIO ranges Emil Renner Berthing @ 2023-12-15 14:39 ` Emil Renner Berthing 2023-12-15 14:39 ` [PATCH v1 7/8] riscv: dts: thead: Add TH1520 pinctrl settings for UART0 Emil Renner Berthing 2023-12-15 14:39 ` [PATCH v1 8/8] riscv: dtb: thead: Add BeagleV Ahead LEDs Emil Renner Berthing 7 siblings, 0 replies; 21+ messages in thread From: Emil Renner Berthing @ 2023-12-15 14:39 UTC (permalink / raw) To: linux-gpio, devicetree, linux-kernel, linux-riscv Cc: Hoan Tran, Serge Semin, Linus Walleij, Bartosz Golaszewski, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jisheng Zhang, Guo Ren, Fu Wei, Paul Walmsley, Palmer Dabbelt Adjust labels for the TH1520 GPIO controllers such that GPIOs can be referenced by the names used by the documentation. Eg. GPIO0_X -> <&gpio0 X Y> GPIO1_X -> <&gpio1 X Y> GPIO2_X -> <&gpio2 X Y> GPIO3_X -> <&gpio3 X Y> GPIO4_X -> <&gpio4 X Y> AOGPIO_X -> <&aogpio X Y> Remove labels for the parent GPIO devices that shouldn't need to be referenced. Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com> --- .../boot/dts/thead/th1520-beaglev-ahead.dts | 2 ++ .../boot/dts/thead/th1520-lichee-pi-4a.dts | 2 ++ arch/riscv/boot/dts/thead/th1520.dtsi | 24 +++++++++---------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/arch/riscv/boot/dts/thead/th1520-beaglev-ahead.dts b/arch/riscv/boot/dts/thead/th1520-beaglev-ahead.dts index 70e8042c8304..91ba96588ae8 100644 --- a/arch/riscv/boot/dts/thead/th1520-beaglev-ahead.dts +++ b/arch/riscv/boot/dts/thead/th1520-beaglev-ahead.dts @@ -17,6 +17,8 @@ aliases { gpio1 = &gpio1; gpio2 = &gpio2; gpio3 = &gpio3; + gpio4 = &gpio4; + gpio5 = &aogpio; serial0 = &uart0; serial1 = &uart1; serial2 = &uart2; diff --git a/arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts b/arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts index 9a3884a73e13..0ae2c20d5641 100644 --- a/arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts +++ b/arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts @@ -14,6 +14,8 @@ aliases { gpio1 = &gpio1; gpio2 = &gpio2; gpio3 = &gpio3; + gpio4 = &gpio4; + gpio5 = &aogpio; serial0 = &uart0; serial1 = &uart1; serial2 = &uart2; diff --git a/arch/riscv/boot/dts/thead/th1520.dtsi b/arch/riscv/boot/dts/thead/th1520.dtsi index d5e2378a1afa..17ca214b5a97 100644 --- a/arch/riscv/boot/dts/thead/th1520.dtsi +++ b/arch/riscv/boot/dts/thead/th1520.dtsi @@ -206,13 +206,13 @@ uart3: serial@ffe7f04000 { status = "disabled"; }; - gpio2: gpio@ffe7f34000 { + gpio@ffe7f34000 { compatible = "snps,dw-apb-gpio"; reg = <0xff 0xe7f34000 0x0 0x1000>; #address-cells = <1>; #size-cells = <0>; - portc: gpio-controller@0 { + gpio2: gpio-controller@0 { compatible = "snps,dw-apb-gpio-port"; gpio-controller; #gpio-cells = <2>; @@ -225,13 +225,13 @@ portc: gpio-controller@0 { }; }; - gpio3: gpio@ffe7f38000 { + gpio@ffe7f38000 { compatible = "snps,dw-apb-gpio"; reg = <0xff 0xe7f38000 0x0 0x1000>; #address-cells = <1>; #size-cells = <0>; - portd: gpio-controller@0 { + gpio3: gpio-controller@0 { compatible = "snps,dw-apb-gpio-port"; gpio-controller; #gpio-cells = <2>; @@ -249,13 +249,13 @@ padctrl1_apsys: pinctrl@ffe7f3c000 { reg = <0xff 0xe7f3c000 0x0 0x1000>; }; - gpio0: gpio@ffec005000 { + gpio@ffec005000 { compatible = "snps,dw-apb-gpio"; reg = <0xff 0xec005000 0x0 0x1000>; #address-cells = <1>; #size-cells = <0>; - porta: gpio-controller@0 { + gpio0: gpio-controller@0 { compatible = "snps,dw-apb-gpio-port"; gpio-controller; #gpio-cells = <2>; @@ -268,13 +268,13 @@ porta: gpio-controller@0 { }; }; - gpio1: gpio@ffec006000 { + gpio@ffec006000 { compatible = "snps,dw-apb-gpio"; reg = <0xff 0xec006000 0x0 0x1000>; #address-cells = <1>; #size-cells = <0>; - portb: gpio-controller@0 { + gpio1: gpio-controller@0 { compatible = "snps,dw-apb-gpio-port"; gpio-controller; #gpio-cells = <2>; @@ -410,13 +410,13 @@ timer7: timer@ffffc3303c { status = "disabled"; }; - ao_gpio0: gpio@fffff41000 { + gpio@fffff41000 { compatible = "snps,dw-apb-gpio"; reg = <0xff 0xfff41000 0x0 0x1000>; #address-cells = <1>; #size-cells = <0>; - porte: gpio-controller@0 { + aogpio: gpio-controller@0 { compatible = "snps,dw-apb-gpio-port"; gpio-controller; #gpio-cells = <2>; @@ -434,13 +434,13 @@ padctrl_aosys: pinctrl@fffff4a000 { reg = <0xff 0xfff4a000 0x0 0x2000>; }; - ao_gpio1: gpio@fffff52000 { + gpio@fffff52000 { compatible = "snps,dw-apb-gpio"; reg = <0xff 0xfff52000 0x0 0x1000>; #address-cells = <1>; #size-cells = <0>; - portf: gpio-controller@0 { + gpio4: gpio-controller@0 { compatible = "snps,dw-apb-gpio-port"; gpio-controller; #gpio-cells = <2>; -- 2.40.1 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v1 7/8] riscv: dts: thead: Add TH1520 pinctrl settings for UART0 2023-12-15 14:38 [PATCH v1 0/8] Add T-Head TH15020 SoC pin control Emil Renner Berthing ` (5 preceding siblings ...) 2023-12-15 14:39 ` [PATCH v1 6/8] riscv: dts: thead: Adjust TH1520 GPIO labels Emil Renner Berthing @ 2023-12-15 14:39 ` Emil Renner Berthing 2023-12-15 14:39 ` [PATCH v1 8/8] riscv: dtb: thead: Add BeagleV Ahead LEDs Emil Renner Berthing 7 siblings, 0 replies; 21+ messages in thread From: Emil Renner Berthing @ 2023-12-15 14:39 UTC (permalink / raw) To: linux-gpio, devicetree, linux-kernel, linux-riscv Cc: Hoan Tran, Serge Semin, Linus Walleij, Bartosz Golaszewski, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jisheng Zhang, Guo Ren, Fu Wei, Paul Walmsley, Palmer Dabbelt Add pinctrl settings for UART0 used as the default debug console on both the Lichee Pi 4A and BeagleV Ahead boards. Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com> --- .../boot/dts/thead/th1520-beaglev-ahead.dts | 26 +++++++++++++++++++ .../boot/dts/thead/th1520-lichee-pi-4a.dts | 26 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/arch/riscv/boot/dts/thead/th1520-beaglev-ahead.dts b/arch/riscv/boot/dts/thead/th1520-beaglev-ahead.dts index 91ba96588ae8..54d86aab6656 100644 --- a/arch/riscv/boot/dts/thead/th1520-beaglev-ahead.dts +++ b/arch/riscv/boot/dts/thead/th1520-beaglev-ahead.dts @@ -58,6 +58,32 @@ &dmac0 { status = "okay"; }; +&padctrl0_apsys { + uart0_pins: uart0-0 { + tx-pins { + pins = "UART0_TXD"; + function = "0"; + bias-disable; + drive-strength = <3>; + input-disable; + input-schmitt-disable; + slew-rate = <0>; + }; + + rx-pins { + pins = "UART0_RXD"; + function = "0"; + bias-disable; + drive-strength = <1>; + input-enable; + input-schmitt-enable; + slew-rate = <0>; + }; + }; +}; + &uart0 { + pinctrl-names = "default"; + pinctrl-0 = <&uart0_pins>; status = "okay"; }; diff --git a/arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts b/arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts index 0ae2c20d5641..260aa5e0769f 100644 --- a/arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts +++ b/arch/riscv/boot/dts/thead/th1520-lichee-pi-4a.dts @@ -29,6 +29,32 @@ chosen { }; }; +&padctrl0_apsys { + uart0_pins: uart0-0 { + tx-pins { + pins = "UART0_TXD"; + function = "0"; + bias-disable; + drive-strength = <3>; + input-disable; + input-schmitt-disable; + slew-rate = <0>; + }; + + rx-pins { + pins = "UART0_RXD"; + function = "0"; + bias-disable; + drive-strength = <1>; + input-enable; + input-schmitt-enable; + slew-rate = <0>; + }; + }; +}; + &uart0 { + pinctrl-names = "default"; + pinctrl-0 = <&uart0_pins>; status = "okay"; }; -- 2.40.1 ^ permalink raw reply related [flat|nested] 21+ messages in thread
* [PATCH v1 8/8] riscv: dtb: thead: Add BeagleV Ahead LEDs 2023-12-15 14:38 [PATCH v1 0/8] Add T-Head TH15020 SoC pin control Emil Renner Berthing ` (6 preceding siblings ...) 2023-12-15 14:39 ` [PATCH v1 7/8] riscv: dts: thead: Add TH1520 pinctrl settings for UART0 Emil Renner Berthing @ 2023-12-15 14:39 ` Emil Renner Berthing 7 siblings, 0 replies; 21+ messages in thread From: Emil Renner Berthing @ 2023-12-15 14:39 UTC (permalink / raw) To: linux-gpio, devicetree, linux-kernel, linux-riscv Cc: Hoan Tran, Serge Semin, Linus Walleij, Bartosz Golaszewski, Andy Shevchenko, Rob Herring, Krzysztof Kozlowski, Conor Dooley, Jisheng Zhang, Guo Ren, Fu Wei, Paul Walmsley, Palmer Dabbelt Add nodes for the 5 user controllable LEDs on the BeagleV Ahead board. Signed-off-by: Emil Renner Berthing <emil.renner.berthing@canonical.com> --- .../boot/dts/thead/th1520-beaglev-ahead.dts | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/arch/riscv/boot/dts/thead/th1520-beaglev-ahead.dts b/arch/riscv/boot/dts/thead/th1520-beaglev-ahead.dts index 54d86aab6656..35585eff6ab3 100644 --- a/arch/riscv/boot/dts/thead/th1520-beaglev-ahead.dts +++ b/arch/riscv/boot/dts/thead/th1520-beaglev-ahead.dts @@ -7,6 +7,8 @@ /dts-v1/; #include "th1520.dtsi" +#include <dt-bindings/gpio/gpio.h> +#include <dt-bindings/leds/common.h> / { model = "BeagleV Ahead"; @@ -34,7 +36,42 @@ chosen { memory@0 { device_type = "memory"; reg = <0x0 0x00000000 0x1 0x00000000>; + }; + leds { + pinctrl-names = "default"; + pinctrl-0 = <&led_pins>; + compatible = "gpio-leds"; + + led-1 { + gpios = <&gpio4 8 GPIO_ACTIVE_LOW>; + color = <LED_COLOR_ID_BLUE>; + label = "led1"; + }; + + led-2 { + gpios = <&gpio4 9 GPIO_ACTIVE_LOW>; + color = <LED_COLOR_ID_BLUE>; + label = "led2"; + }; + + led-3 { + gpios = <&gpio4 10 GPIO_ACTIVE_LOW>; + color = <LED_COLOR_ID_BLUE>; + label = "led3"; + }; + + led-4 { + gpios = <&gpio4 11 GPIO_ACTIVE_LOW>; + color = <LED_COLOR_ID_BLUE>; + label = "led4"; + }; + + led-5 { + gpios = <&gpio4 12 GPIO_ACTIVE_LOW>; + color = <LED_COLOR_ID_BLUE>; + label = "led5"; + }; }; }; @@ -58,6 +95,24 @@ &dmac0 { status = "okay"; }; +&padctrl_aosys { + led_pins: led-0 { + led-pins { + pins = "AUDIO_PA8", /* GPIO4_8 */ + "AUDIO_PA9", /* GPIO4_9 */ + "AUDIO_PA10", /* GPIO4_10 */ + "AUDIO_PA11", /* GPIO4_11 */ + "AUDIO_PA12"; /* GPIO4_12 */ + function = "3"; + bias-disable; + drive-strength = <3>; + input-disable; + input-schmitt-disable; + slew-rate = <0>; + }; + }; +}; + &padctrl0_apsys { uart0_pins: uart0-0 { tx-pins { -- 2.40.1 ^ permalink raw reply related [flat|nested] 21+ messages in thread
end of thread, other threads:[~2023-12-23 0:18 UTC | newest] Thread overview: 21+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2023-12-15 14:38 [PATCH v1 0/8] Add T-Head TH15020 SoC pin control Emil Renner Berthing 2023-12-15 14:38 ` [PATCH v1 1/8] dt-bindings: pinctrl: Add thead,th1520-pinctrl bindings Emil Renner Berthing 2023-12-15 20:21 ` Rob Herring 2023-12-16 13:57 ` Emil Renner Berthing 2023-12-20 19:24 ` Linus Walleij 2023-12-21 12:28 ` Emil Renner Berthing 2023-12-21 13:44 ` Linus Walleij 2023-12-21 14:07 ` Emil Renner Berthing 2023-12-23 0:18 ` Linus Walleij 2023-12-20 19:20 ` Linus Walleij 2023-12-21 12:21 ` Emil Renner Berthing 2023-12-15 14:39 ` [PATCH v1 2/8] pinctrl: Add driver for the T-Head TH1520 SoC Emil Renner Berthing 2023-12-15 17:27 ` Andy Shevchenko 2023-12-15 14:39 ` [PATCH v1 3/8] riscv: dts: thead: Add TH1520 pin control nodes Emil Renner Berthing 2023-12-15 14:39 ` [PATCH v1 4/8] dt-bindings: gpio: dwapb: allow gpio-ranges Emil Renner Berthing 2023-12-15 20:21 ` Rob Herring 2023-12-18 10:05 ` Bartosz Golaszewski 2023-12-15 14:39 ` [PATCH v1 5/8] riscv: dts: thead: Add TH1520 GPIO ranges Emil Renner Berthing 2023-12-15 14:39 ` [PATCH v1 6/8] riscv: dts: thead: Adjust TH1520 GPIO labels Emil Renner Berthing 2023-12-15 14:39 ` [PATCH v1 7/8] riscv: dts: thead: Add TH1520 pinctrl settings for UART0 Emil Renner Berthing 2023-12-15 14:39 ` [PATCH v1 8/8] riscv: dtb: thead: Add BeagleV Ahead LEDs Emil Renner Berthing
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).