All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH/RFC] rockchip: derive GPIO bank from alias if available
@ 2022-07-26 16:25 John Keeping
  2022-07-26 19:53 ` Simon Glass
  0 siblings, 1 reply; 3+ messages in thread
From: John Keeping @ 2022-07-26 16:25 UTC (permalink / raw)
  To: u-boot; +Cc: John Keeping, Simon Glass, Philipp Tomsich, Kever Yang

Upstream device trees now use standard node names like "gpio@ff..." but
the rk_gpio driver expects a name like "gpio0@ff..." (note the index
before the @).

This is not a change that can be made in a -u-boot.dtsi file, so
updating to the latest upstream device trees requires updating the
driver.

When a sequence number is given explicitly via an alias it makes sense
to use this for the bank number (and aliases can be added via
-u-boot.dtsi when they are not present upstream), so make this the
preferred scheme for assigning a bank index, falling back to the current
method if no alias is defined.

Signed-off-by: John Keeping <john@metanate.com>
---
I'm not sure if it would be better just to use dev_seq(dev)
unconditionally here.  If no aliases are defined, then the device tree
nodes are in the right order for all Rockchip SoCs anyway so the
sequence numbers will be sensible.

But this feels like the change with less risk of unintentionally
introducing a regression.

 drivers/gpio/rk_gpio.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/rk_gpio.c b/drivers/gpio/rk_gpio.c
index 68f30157a9..b2f6d0e925 100644
--- a/drivers/gpio/rk_gpio.c
+++ b/drivers/gpio/rk_gpio.c
@@ -151,8 +151,13 @@ static int rockchip_gpio_probe(struct udevice *dev)
 		return ret;
 
 	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;
 	uc_priv->bank_name = priv->name;
 
-- 
2.37.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH/RFC] rockchip: derive GPIO bank from alias if available
  2022-07-26 16:25 [PATCH/RFC] rockchip: derive GPIO bank from alias if available John Keeping
@ 2022-07-26 19:53 ` Simon Glass
  2022-07-27 16:27   ` John Keeping
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Glass @ 2022-07-26 19:53 UTC (permalink / raw)
  To: John Keeping; +Cc: U-Boot Mailing List, Philipp Tomsich, Kever Yang

Hi John,

On Tue, 26 Jul 2022 at 10:25, John Keeping <john@metanate.com> wrote:
>
> Upstream device trees now use standard node names like "gpio@ff..." but
> the rk_gpio driver expects a name like "gpio0@ff..." (note the index
> before the @).
>
> This is not a change that can be made in a -u-boot.dtsi file, so
> updating to the latest upstream device trees requires updating the
> driver.
>
> When a sequence number is given explicitly via an alias it makes sense
> to use this for the bank number (and aliases can be added via
> -u-boot.dtsi when they are not present upstream), so make this the
> preferred scheme for assigning a bank index, falling back to the current
> method if no alias is defined.
>
> Signed-off-by: John Keeping <john@metanate.com>
> ---
> I'm not sure if it would be better just to use dev_seq(dev)
> unconditionally here.  If no aliases are defined, then the device tree
> nodes are in the right order for all Rockchip SoCs anyway so the
> sequence numbers will be sensible.

Well dev_seq() should now match the alias numbers if provided, so it
seems better.

>
> But this feels like the change with less risk of unintentionally
> introducing a regression.
>
>  drivers/gpio/rk_gpio.c | 9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpio/rk_gpio.c b/drivers/gpio/rk_gpio.c
> index 68f30157a9..b2f6d0e925 100644
> --- a/drivers/gpio/rk_gpio.c
> +++ b/drivers/gpio/rk_gpio.c
> @@ -151,8 +151,13 @@ static int rockchip_gpio_probe(struct udevice *dev)
>                 return ret;
>
>         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;
>         uc_priv->bank_name = priv->name;
>
> --
> 2.37.1
>

Regards,
Simon

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH/RFC] rockchip: derive GPIO bank from alias if available
  2022-07-26 19:53 ` Simon Glass
@ 2022-07-27 16:27   ` John Keeping
  0 siblings, 0 replies; 3+ messages in thread
From: John Keeping @ 2022-07-27 16:27 UTC (permalink / raw)
  To: Simon Glass; +Cc: U-Boot Mailing List, Philipp Tomsich, Kever Yang

Hi Simon,

On Tue, Jul 26, 2022 at 01:53:44PM -0600, Simon Glass wrote:
> On Tue, 26 Jul 2022 at 10:25, John Keeping <john@metanate.com> wrote:
> >
> > Upstream device trees now use standard node names like "gpio@ff..." but
> > the rk_gpio driver expects a name like "gpio0@ff..." (note the index
> > before the @).
> >
> > This is not a change that can be made in a -u-boot.dtsi file, so
> > updating to the latest upstream device trees requires updating the
> > driver.
> >
> > When a sequence number is given explicitly via an alias it makes sense
> > to use this for the bank number (and aliases can be added via
> > -u-boot.dtsi when they are not present upstream), so make this the
> > preferred scheme for assigning a bank index, falling back to the current
> > method if no alias is defined.
> >
> > Signed-off-by: John Keeping <john@metanate.com>
> > ---
> > I'm not sure if it would be better just to use dev_seq(dev)
> > unconditionally here.  If no aliases are defined, then the device tree
> > nodes are in the right order for all Rockchip SoCs anyway so the
> > sequence numbers will be sensible.
> 
> Well dev_seq() should now match the alias numbers if provided, so it
> seems better.

Right, when there are aliases dev_seq() is definitely right, but
currently the bank number is derived from a node like:

	gpio0: gpio0@ff750000 {

where the name is "gpio0@..." and it's that zero that is used to
determine the bank.

I don't think all boards define aliases for the GPIOs, so I thought it
might be better to preserve the existing node-name scheme when no alias
is set.  But there seems to be quite a push towards standardised node
names upstream so eventually updating the device trees from upstream
will break this scheme.

Having looked around a bit more, it seems that of the drivers generating
a bank name with 'A'+index, while PIC32 uses the same node name scheme
as Rockchip, both octeon and mvebu use dev_seq(), so it does seem
sensible to just switch to dev_seq() as the right way to do this.


Regards,
John

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-27 16:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-26 16:25 [PATCH/RFC] rockchip: derive GPIO bank from alias if available John Keeping
2022-07-26 19:53 ` Simon Glass
2022-07-27 16:27   ` John Keeping

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.