How to rename GPIO pins (on DTS file)

I was using OpenWrt 19 as my system base, and now I am updating my system to use OpenWrt 22 (RC6). It uses GPIOs and UARTs of a MT7688 or MT7628 (Widora).

Listing the GPIOs on OpenWrt 19 (cat /sys/kernel/debug/gpio):

gpiochip0: GPIOs 0-31, parent: platform/10000600.gpio, 10000600.gpio:
 gpio-11  (                    |BTN_0               ) in  hi    
 gpio-17  (                    |sysfs               ) out hi    

gpiochip1: GPIOs 32-63, parent: platform/10000600.gpio, 10000600.gpio:
 gpio-38  (                    |reset               ) in  hi    
 gpio-39  (                    |sysfs               ) out lo    
 gpio-40  (                    |sysfs               ) out hi    

gpiochip2: GPIOs 64-95, parent: platform/10000600.gpio, 10000600.gpio:

We can see the low numbers. And listing on OpenWrt 22:

gpiochip2: GPIOs 416-447, parent: platform/10000600.gpio, 10000600.gpio-bank2:

gpiochip1: GPIOs 448-479, parent: platform/10000600.gpio, 10000600.gpio-bank1:
 gpio-454 (                    |reset               ) in  hi IRQ ACTIVE LOW

gpiochip0: GPIOs 480-511, parent: platform/10000600.gpio, 10000600.gpio-bank0:
 gpio-491 (                    |BTN_0               ) in  lo IRQ ACTIVE LOW
 gpio-497 (                    |sysfs               ) out hi

We can see high numbers.
I know that I could calculate these numbers like: bank_base + pin_number.
I did it with pin 17, which is 480 + 17 = 497. I exported it, and you can see it on the listing above.

But the idea is not changing these numbers everywhere in my system. Is it possible?

I tried to change the mt7628an.dtsi and mt7628an_widora_neo.dtsi files to try change these ranges.
I saw there is a gpio-base property, but I do not know if it can solve my problem and how to edit properly these files.

I'm not sure I read your question correctly. You want to replace the "new" GPIO numbers with the "old" ones?

As far as I am aware that is not possible. The upstream drivers merged the previously separate GPIO banks into one, and the GPIOs now need to be distinguished not by their bank and their number but their offset within the bank and their number on top of the offset.

1 Like

Yes!
I thought I could configure the base number as zero, and use (sysfs) GPIOs using the same numbers as before.
But OK. I'll get the base number with something like this:

cat "$(grep bank0 /sys/class/gpio/gpiochip*/label | sed -n 's/\(.*gpiochip[0-9]\+\).*/\1/p')/base"

Thank you

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.