From 59cbeb9672262df22cff21fde85c9f87eeb8effd Mon Sep 17 00:00:00 2001 From: Icenowy Zheng Date: Wed, 23 Apr 2025 00:22:48 +0800 Subject: [PATCH 1/3] dt-bindings: pinctrl: jh7110-sys: add force inputs The internal inputs routed by the pin controller could be routed not to any GPIOs but forced low/high in the pin controller, which is a useful feature for some input signals (e.g. overcurrent_n pin of the USB controller, which needs to be tied to high if not externally routed). Add two properties to support forcing inputs to low/high. Signed-off-by: Icenowy Zheng Signed-off-by: Linux RISC-V bot --- .../bindings/pinctrl/starfive,jh7110-sys-pinctrl.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/devicetree/bindings/pinctrl/starfive,jh7110-sys-pinctrl.yaml b/Documentation/devicetree/bindings/pinctrl/starfive,jh7110-sys-pinctrl.yaml index 222b9e240f8af9..d793290afdd742 100644 --- a/Documentation/devicetree/bindings/pinctrl/starfive,jh7110-sys-pinctrl.yaml +++ b/Documentation/devicetree/bindings/pinctrl/starfive,jh7110-sys-pinctrl.yaml @@ -46,6 +46,16 @@ properties: '#gpio-cells': const: 2 + starfive,force-low-inputs: + description: + The list of input signals forced to be low inside the SoC itself. + $ref: /schemas/types.yaml#/definitions/uint32-array + + starfive,force-high-inputs: + description: + The list of input signals forced to be high inside the SoC itself. + $ref: /schemas/types.yaml#/definitions/uint32-array + patternProperties: '-[0-9]+$': type: object From 7e89860ff68ba7c0230bd4689bb75fe5f4884a59 Mon Sep 17 00:00:00 2001 From: Icenowy Zheng Date: Wed, 23 Apr 2025 00:22:49 +0800 Subject: [PATCH 2/3] pinctrl: starfive: jh7110: support forcing inputs to low/high The internal input signals inside JH7110 SoC (output of the pin controller) could be routed to fixed low/high level instead of external GPIOs. Support this feature in the pinctrl driver, which is quite useful for some peripherals (e.g. USB) because of the low GPIO count of JH7110. Signed-off-by: Icenowy Zheng Signed-off-by: Linux RISC-V bot --- .../starfive/pinctrl-starfive-jh7110.c | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c index 1d0d6c224c104e..5652f9bb658a2a 100644 --- a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c +++ b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c @@ -837,6 +837,41 @@ static void jh7110_disable_clock(void *data) clk_disable_unprepare(data); } +static int jh7110_force_input_pins(struct jh7110_pinctrl *sfp, + const char *property, u32 forced_input) +{ + int i, nforce; + int ret; + u32 pin, val; + unsigned int offset, shift; + struct device *dev = sfp->dev; + const struct jh7110_pinctrl_soc_info *info = sfp->info; + + nforce = of_property_count_u32_elems(dev->of_node, property); + + if (nforce > 0) { + for (i = 0; i < nforce; i++) { + ret = of_property_read_u32_index(dev->of_node, property, + i, &pin); + if (ret) + return ret; + + offset = 4 * (pin / 4); + shift = 8 * (pin % 4); + + val = readl_relaxed(sfp->base + + info->gpi_reg_base + offset); + val &= info->gpi_mask << shift; + val |= (forced_input & info->gpi_mask) << shift; + + writel_relaxed(val, sfp->base + + info->gpi_reg_base + offset); + } + } + + return 0; +} + int jh7110_pinctrl_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -964,6 +999,14 @@ int jh7110_pinctrl_probe(struct platform_device *pdev) dev_info(dev, "StarFive GPIO chip registered %d GPIOs\n", sfp->gc.ngpio); + ret = jh7110_force_input_pins(sfp, "starfive,force-low-inputs", 0); + if (ret) + return ret; + + ret = jh7110_force_input_pins(sfp, "starfive,force-high-inputs", 1); + if (ret) + return ret; + return pinctrl_enable(sfp->pctl); } EXPORT_SYMBOL_GPL(jh7110_pinctrl_probe); From cc09de752d4a5f080423be8da96ec448089de20d Mon Sep 17 00:00:00 2001 From: Icenowy Zheng Date: Wed, 23 Apr 2025 00:22:50 +0800 Subject: [PATCH 3/3] riscv: dts: starfive: jh7110-pine64-star64: force no USB overcurrent The Star64 board has no GPIOs to indicate USB overcurrent, however the USB controller would stop to work if the overcurrent_n signal it gets is low (which means overcurrent situations happening because of the _n). Use the pin controller to force the overcurrent_n signal to be high in order to ensure stable behavior of the USB controller. Signed-off-by: Icenowy Zheng Signed-off-by: Linux RISC-V bot --- arch/riscv/boot/dts/starfive/jh7110-pine64-star64.dts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/riscv/boot/dts/starfive/jh7110-pine64-star64.dts b/arch/riscv/boot/dts/starfive/jh7110-pine64-star64.dts index 31e825be2065af..dab0e0054e6488 100644 --- a/arch/riscv/boot/dts/starfive/jh7110-pine64-star64.dts +++ b/arch/riscv/boot/dts/starfive/jh7110-pine64-star64.dts @@ -81,6 +81,8 @@ }; &sysgpio { + starfive,force-high-inputs = ; + usb0_pins: usb0-0 { vbus-pins { pinmux =