diff mbox series

[v2,09/15] gpio: rockchip: Use gpio alias id as gpio bank id

Message ID 20240217002304.2141064-10-jonas@kwiboo.se
State Accepted
Commit f41738d0f101fc07c79aea6093650ab2ed4bf8c4
Delegated to: Kever Yang
Headers show
Series rockchip: rk3328: Update defconfigs, DTs and enable boot from SPI | expand

Commit Message

Jonas Karlman Feb. 17, 2024, 12:22 a.m. UTC
The U-Boot driver try to base the gpio bank id on the gpio-ranges prop
and fall back to base the bank id on the node name. However, the linux
driver try to base the bank id on the gpio alias id and fall back on
node order.

This can cause issues when SoC DT is synced from linux and gpioX@ nodes
has been renamed to gpio@ and gpio-ranges or a SoC specific alias has
not been assigned.

Try to use the gpio alias id as first fallback when a gpio-ranges prop
is missing to ease sync of updated SoC DT. Keep the current fallback on
node name as a third fallback to not affect any existing unsynced DT.

Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
---
v2:
- No change
---
 drivers/gpio/rk_gpio.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Comments

Quentin Schulz Feb. 22, 2024, 9:57 a.m. UTC | #1
Hi Jonas,

On 2/17/24 01:22, Jonas Karlman wrote:
> The U-Boot driver try to base the gpio bank id on the gpio-ranges prop
> and fall back to base the bank id on the node name. However, the linux
> driver try to base the bank id on the gpio alias id and fall back on
> node order.
> 
> This can cause issues when SoC DT is synced from linux and gpioX@ nodes
> has been renamed to gpio@ and gpio-ranges or a SoC specific alias has
> not been assigned.
> 
> Try to use the gpio alias id as first fallback when a gpio-ranges prop
> is missing to ease sync of updated SoC DT. Keep the current fallback on
> node name as a third fallback to not affect any existing unsynced DT.
> 

The gpio alias is not necessarily the same as the gpio bank in the SoC. 
But I guess if it's good enough for the Linux kernel AND the fact that 
we take our device trees from the Linux kernel, it'd be near impossible 
to have a non-working setup for upstream-supported devices. But 
considering all Rockchip SoCs in the Linux kernel have the gpio aliases 
set in the SoC.dtsi and that no board seems to be overriding them, it is 
safe to do.

There's also a possible issue with two gpio controllers using the same 
bank, e.g. if there's one using the first of the three methods, another 
the second one and another one the third one. But again considering all 
Rockchip SoCs in the Linux kernel have the gpio aliases set in the 
SoC.dtsi, this should be covered as well during the next DT sync from Linux.

Therefore,

Reviewed-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>

Thanks,
Quentin
Kever Yang March 14, 2024, 3:30 a.m. UTC | #2
On 2024/2/17 08:22, Jonas Karlman wrote:
> The U-Boot driver try to base the gpio bank id on the gpio-ranges prop
> and fall back to base the bank id on the node name. However, the linux
> driver try to base the bank id on the gpio alias id and fall back on
> node order.
>
> This can cause issues when SoC DT is synced from linux and gpioX@ nodes
> has been renamed to gpio@ and gpio-ranges or a SoC specific alias has
> not been assigned.
>
> Try to use the gpio alias id as first fallback when a gpio-ranges prop
> is missing to ease sync of updated SoC DT. Keep the current fallback on
> node name as a third fallback to not affect any existing unsynced DT.
>
> Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
Reviewed-by: Kever Yang <kever.yang@rock-chips.com>

Thanks,
- Kever
> ---
> v2:
> - No change
> ---
>   drivers/gpio/rk_gpio.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpio/rk_gpio.c b/drivers/gpio/rk_gpio.c
> index 4a6ae554bf78..24fedd456353 100644
> --- a/drivers/gpio/rk_gpio.c
> +++ b/drivers/gpio/rk_gpio.c
> @@ -201,8 +201,11 @@ static int rockchip_gpio_probe(struct udevice *dev)
>   		priv->bank = args.args[1] / ROCKCHIP_GPIOS_PER_BANK;
>   	} else {
>   		uc_priv->gpio_count = ROCKCHIP_GPIOS_PER_BANK;
> -		end = strrchr(dev->name, '@');
> -		priv->bank = trailing_strtoln(dev->name, end);
> +		ret = dev_read_alias_seq(dev, &priv->bank);
> +		if (ret) {
> +			end = strrchr(dev->name, '@');
> +			priv->bank = trailing_strtoln(dev->name, end);
> +		}
>   	}
>   
>   	priv->name[0] = 'A' + priv->bank;
diff mbox series

Patch

diff --git a/drivers/gpio/rk_gpio.c b/drivers/gpio/rk_gpio.c
index 4a6ae554bf78..24fedd456353 100644
--- a/drivers/gpio/rk_gpio.c
+++ b/drivers/gpio/rk_gpio.c
@@ -201,8 +201,11 @@  static int rockchip_gpio_probe(struct udevice *dev)
 		priv->bank = args.args[1] / ROCKCHIP_GPIOS_PER_BANK;
 	} else {
 		uc_priv->gpio_count = ROCKCHIP_GPIOS_PER_BANK;
-		end = strrchr(dev->name, '@');
-		priv->bank = trailing_strtoln(dev->name, end);
+		ret = dev_read_alias_seq(dev, &priv->bank);
+		if (ret) {
+			end = strrchr(dev->name, '@');
+			priv->bank = trailing_strtoln(dev->name, end);
+		}
 	}
 
 	priv->name[0] = 'A' + priv->bank;