Skip to contentSkip to conversation

rockchip: Make gpiod pin control work and add gpio-ranges

PATCH New Matthijs Kooijman 1 participant 3 messages Dec 5, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

The first patch fixes pin config (e.g. bias) done by userspace via the gpiod interface, which was not implemented for all rockchip boards.

The second patch is just because I was messing with this code already and had a test setup ready. It makes gpio-ranges explicit for the rk3308 instead of relying on the (possibly fragile) legacy workaround in gpio-rockchip to add them automatically.

I think the first patch might be a good candidate to backport to the stable releases, since it makes a userspace interface functional that currently silently fails. However, it is not a clear bugfix and I am not super familiar with the rules for -stable, so if you think this is not appropriate, feel free to drop the stable Cc from the patch when merging.

Both patches were tested on a rock pi s with a rk3308.

_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip

#1 lore raw

PATCH 1/2 gpio: rockchip: Call pinctrl for gpio config

Pinctrl is responsible for bias settings and possibly other pin config, so call gpiochip_generic_config to apply such config values. This might also include settings that pinctrl does not support, but then it can return ENOTSUPP as appropriate.

This makes sure any bias and other pin config set by userspace (via gpiod) actually takes effect.

---
 drivers/gpio/gpio-rockchip.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-rockchip.c +1 -1
index 47174eb3ba76f..106f7f734b4ff 100644
@@ -303,7 +303,7 @@ static int rockchip_gpio_set_config(struct gpio_chip *gc, unsigned int offset,
 		 */
 		return -ENOTSUPP;
 	default:
-		return -ENOTSUPP;
+		return gpiochip_generic_config(gc, offset, config);
 	}
 }
 
Signature · 1 line
2.48.1
#2 lore raw

PATCH 2/2 arm64: dts: rockchip: rk3308: Add gpio-ranges properties

In reply to Matthijs Kooijman

This makes the mapping between gpio and pinctrl explicit.

This does not immediately change functionality, because the gpio-rockchip.c driver has a workaround that defines ranges when they are not present in DT, but that relies on global gpio numbering (so AFAICS only works when the rockchip gpio banks are initialized first and in-order). This prevents the fragility of the workaround for rk3308.

---
 arch/arm64/boot/dts/rockchip/rk3308.dtsi | 5 +++++
 1 file changed, 5 insertions(+)
arch/arm64/boot/dts/rockchip/rk3308.dtsi +5 -0
index 31c25de2d689c..681d2429d541d 100644
@@ -889,6 +889,7 @@ gpio0: gpio@ff220000 {
 			interrupts = <GIC_SPI 40 IRQ_TYPE_LEVEL_HIGH>;
 			clocks = <&cru PCLK_GPIO0>;
 			gpio-controller;
+			gpio-ranges = <&pinctrl 0 0 32>;
 			#gpio-cells = <2>;
 			interrupt-controller;
 			#interrupt-cells = <2>;
@@ -900,6 +901,7 @@ gpio1: gpio@ff230000 {
 			interrupts = <GIC_SPI 41 IRQ_TYPE_LEVEL_HIGH>;
 			clocks = <&cru PCLK_GPIO1>;
 			gpio-controller;
+			gpio-ranges = <&pinctrl 0 32 32>;
 			#gpio-cells = <2>;
 			interrupt-controller;
 			#interrupt-cells = <2>;
@@ -911,6 +913,7 @@ gpio2: gpio@ff240000 {
 			interrupts = <GIC_SPI 42 IRQ_TYPE_LEVEL_HIGH>;
 			clocks = <&cru PCLK_GPIO2>;
 			gpio-controller;
+			gpio-ranges = <&pinctrl 0 64 32>;
 			#gpio-cells = <2>;
 			interrupt-controller;
 			#interrupt-cells = <2>;
@@ -922,6 +925,7 @@ gpio3: gpio@ff250000 {
 			interrupts = <GIC_SPI 43 IRQ_TYPE_LEVEL_HIGH>;
 			clocks = <&cru PCLK_GPIO3>;
 			gpio-controller;
+			gpio-ranges = <&pinctrl 0 96 32>;
 			#gpio-cells = <2>;
 			interrupt-controller;
 			#interrupt-cells = <2>;
@@ -933,6 +937,7 @@ gpio4: gpio@ff260000 {
 			interrupts = <GIC_SPI 44 IRQ_TYPE_LEVEL_HIGH>;
 			clocks = <&cru PCLK_GPIO4>;
 			gpio-controller;
+			gpio-ranges = <&pinctrl 0 128 32>;
 			#gpio-cells = <2>;
 			interrupt-controller;
 			#interrupt-cells = <2>;
Signature · 1 line
2.48.1