[PATCH V2 1/9] gpio: gpio-rockchip: parse gpio-ranges for bank id

Johan Jonker jbx6244 at gmail.com
Wed Feb 22 11:59:52 CET 2023


Hi Kever, Linus Walleij, Heiko,

My Linux proposal has a little different logic (see below) and was "Acked-by", but the merge status is unknown.

https://lore.kernel.org/linux-rockchip/890be9a0-8e82-a8f4-bc15-d5d1597343c2@gmail.com/

Could Linus/Heiko indicate if U-boot already can use this or are there other ideas?

Johan

On 2/13/23 23:27, Chris Morgan wrote:
> From: Chris Morgan <macromorgan at hotmail.com>
> 
> Use the new devicetree property of gpio-ranges to determine the GPIO
> bank ID. Preserve the "old" way of doing things too, so that boards
> can be migrated and tested gradually (I only have a 3566 and 3326 to
> test).
> 
> Signed-off-by: Chris Morgan <macromorgan at hotmail.com>
> Reviewed-by: Kever Yang <kever.yang at rock-chips.com>
> ---
>  drivers/gpio/rk_gpio.c | 20 +++++++++++++++++---
>  1 file changed, 17 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpio/rk_gpio.c b/drivers/gpio/rk_gpio.c
> index 68f30157a9..98a79b5f4d 100644
> --- a/drivers/gpio/rk_gpio.c
> +++ b/drivers/gpio/rk_gpio.c
> @@ -142,6 +142,7 @@ static int rockchip_gpio_probe(struct udevice *dev)
>  {
>  	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
>  	struct rockchip_gpio_priv *priv = dev_get_priv(dev);
> +	struct ofnode_phandle_args args;
>  	char *end;
>  	int ret;
> 
> @@ -150,9 +151,22 @@ static int rockchip_gpio_probe(struct udevice *dev)
>  	if (ret)
>  		return ret;
> 
> -	uc_priv->gpio_count = ROCKCHIP_GPIOS_PER_BANK;
> -	end = strrchr(dev->name, '@');
> -	priv->bank = trailing_strtoln(dev->name, end);
> +	/*
> +	 * If "gpio-ranges" is present in the devicetree use it to parse
> +	 * the GPIO bank ID, otherwise use the legacy method.
> +	 */
> +	ret = ofnode_parse_phandle_with_args(dev_ofnode(dev),
> +					     "gpio-ranges", NULL, 3,
> +					     0, &args);
> +	if (!ret || ret != -ENOENT) {
> +		uc_priv->gpio_count = args.args[2];

> +		priv->bank = args.args[1] / args.args[2];

		priv->bank = args.args[1] / 32;

args.args[2] The number of pins is not is not constant for every gpio node (see data sheets).
Therefore can't be used as divider to get the bank number.
I used 32 as simple offset method, because of register size.


> +	} else {
> +		uc_priv->gpio_count = ROCKCHIP_GPIOS_PER_BANK;
> +		end = strrchr(dev->name, '@');
> +		priv->bank = trailing_strtoln(dev->name, end);
> +	}
> +
>  	priv->name[0] = 'A' + priv->bank;
>  	uc_priv->bank_name = priv->name;
> 


More information about the U-Boot mailing list