Finding power switch GPIO/ testing all possible GPIO

If you have a dts based device, then you will have /sys/firmware/devicetree/base/ with all nodes and properties of your used device tree populated...

Here you can read also something like the gpio number... Your gpio should be under gpio-export as in my example.

Example for WDR3600 (ath79):

hexdump /sys/firmware/devicetree/base/gpio-export/gpio_usb2_power/gpios 
0000000 0000 000f 0000 0015 0000 0000

0000 000f = phandle to gpio-controller node
0000 0015 = gpio number in hex (here gpio 21 on gpio controller with phandle 0000 000f)
0000 0000 = active high (0000 0001 = active low)

Output of phandle from gpio controller:

hexdump /sys/firmware/devicetree/base/ahb/apb/gpio@18040000/phandle 
0000000 0000 000f

You can search for all available gpio-controllers with
find /sys/firmware/devicetree/base -name gpio-controller

Example for WDR3600 (ATH79):

find /sys/firmware/devicetree/base -name gpio-controller
/sys/firmware/devicetree/base/ahb/apb/gpio@18040000/gpio-controller
/sys/firmware/devicetree/base/ahb/apb/pcie-controller@180c0000/wifi@168c,0033/gpio-controller

This device does have two gpio controllers.

1 Like