Access GPIOs on AR750S

Hello,
I had a question about accessing the GPIOs on AR750S.
The spec shows that there are 4 GPIO pins in the router (18, 22, 5, 21).
The GPIO 5 and 21 are assigned for the I2C.

However, when I want to control the values of GPIO 18 and 22,
I found that I cannot control the value of GPIO 22.
The records are shown as following:

root@GL-AR750S:~# cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 0-31, parent: platform/ath79-gpio, ath79-gpio:
 gpio-1   (                    |gl-ar750s:white:powe) out lo
 gpio-2   (                    |reset               ) in  hi
 gpio-5   (                    |sda                 ) in  hi
 gpio-7   (                    |gl-ar750s:white:usbp) out hi
 gpio-8   (                    |right               ) in  hi
 gpio-18  (                    |sysfs               ) out hi
 gpio-19  (                    |gl-ar750s:white:wlan) out hi
 gpio-20  (                    |gl-ar750s:white:wlan) out hi
 gpio-21  (                    |scl                 ) in  hi
 gpio-22  (                    |sysfs               ) out hi

gpiochip1: GPIOs 489-511, parent: platform/qca956x_wmac, ath9k-phy1:
 gpio-490 (                    |ath9k-phy1          ) in  lo
root@GL-AR750S:~# echo 0 > /sys/class/gpio/gpio22/value
root@GL-AR750S:~# cat /sys/class/gpio/gpio22/value
1

The GPIO 18 is correct under the same setting.

root@GL-AR750S:~# echo 0 > /sys/class/gpio/gpio18/value
root@GL-AR750S:~# cat /sys/class/gpio/gpio18/value
0

Can anyone tell me anything wrong with my setting?
I had exported the GPIO and also made it become output mode.

By the way, I also have a problem with how to make the GPIO 5 and 21 leave the I2C mode.
I had tried the comment “rmmod i2c_dev”, but those pins still cannot export.

If any required information, please let me know.
Thanks for your answer.

Hello, does anyone meet the same problem?

I do some further test. The GPIO22 can switch to “0” when its direction is “in”.
However, the value still can not be changed under “out” mode.
The following is my record.

root@GL-AR750S:/sys/devices/platform/ath79-gpio/gpiochip0/gpio/gpio22# echo 0 >> value
root@GL-AR750S:/sys/devices/platform/ath79-gpio/gpiochip0/gpio/gpio22# cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 0-31, parent: platform/ath79-gpio, ath79-gpio:
 gpio-1   (                    |gl-ar750s:white:powe) out lo
 gpio-2   (                    |reset               ) in  hi
 gpio-5   (                    |sda                 ) in  hi
 gpio-7   (                    |gl-ar750s:white:usbp) out hi
 gpio-8   (                    |right               ) in  hi
 gpio-18  (                    |sysfs               ) out hi
 gpio-19  (                    |gl-ar750s:white:wlan) out hi
 gpio-20  (                    |gl-ar750s:white:wlan) out hi
 gpio-21  (                    |scl                 ) in  hi
 gpio-22  (                    |sysfs               ) out hi

gpiochip1: GPIOs 489-511, parent: platform/qca956x_wmac, ath9k-phy1:
 gpio-490 (                    |ath9k-phy1          ) in  lo
root@GL-AR750S:/sys/devices/platform/ath79-gpio/gpiochip0/gpio/gpio22# echo in >> direction
root@GL-AR750S:/sys/devices/platform/ath79-gpio/gpiochip0/gpio/gpio22# cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 0-31, parent: platform/ath79-gpio, ath79-gpio:
 gpio-1   (                    |gl-ar750s:white:powe) out lo
 gpio-2   (                    |reset               ) in  hi
 gpio-5   (                    |sda                 ) in  hi
 gpio-7   (                    |gl-ar750s:white:usbp) out hi
 gpio-8   (                    |right               ) in  hi
 gpio-18  (                    |sysfs               ) out hi
 gpio-19  (                    |gl-ar750s:white:wlan) out lo
 gpio-20  (                    |gl-ar750s:white:wlan) out hi
 gpio-21  (                    |scl                 ) in  hi
 gpio-22  (                    |sysfs               ) in  lo

gpiochip1: GPIOs 489-511, parent: platform/qca956x_wmac, ath9k-phy1:
 gpio-490 (                    |ath9k-phy1          ) in  lo

Any suggestions and comments are welcome!
Thank you.

Sorry for the late reply.

If you want to make the GPIO 5 and 21 leave the I2C mode, you should modify the source code and compile again.

For GPIO 18 and 22. It works for me.

root@GL-HK-Main:~# echo 18 > /sys/class/gpio/export 
root@GL-HK-Main:~# cat /sys/class/gpio/gpio18/direction 
in
root@GL-HK-Main:~# echo out > /sys/class/gpio/gpio18/direction 
root@GL-HK-Main:~# cat /sys/class/gpio/gpio18/value 
0
root@GL-HK-Main:~# echo 1 > /sys/class/gpio/gpio18/value 
root@GL-HK-Main:~# cat /sys/class/gpio/gpio18/value 
1

Hello Kyson,

Thanks for your reply.
Any suggests for me to do some further test on the device?
In my case, GPIO 18 works correct for me,
but GPIO 22 cannot change the value in the “out” mode.
By the way, can I use opkg to make the GPIO 5 and 21 leave the I2C mode?
Or I should rebuild the OpenWRT in this case?

ofc, you can unbind i2c function, but it doesn’t work after the reboot, so you should do it again if reboot.

root@GL-AR750S:/# echo "i2c-gpio.0" > /sys/bus/platform/drivers/i2c-gpio/unbind 
root@GL-AR750S:/# echo 5 > /sys/class/gpio/export 
root@GL-AR750S:/# cat /sys/class/gpio/gpio5/direction 
in
root@GL-AR750S:/# echo out > /sys/class/gpio/gpio5/direction 
root@GL-AR750S:/# cat /sys/class/gpio/gpio5/value 
0
root@GL-AR750S:/# echo 1 > /sys/class/gpio/gpio5/value 
root@GL-AR750S:/# cat /sys/class/gpio/gpio5/value 
1

Thank you for your prompt reply.
I will test it and report my testing results.

After unbidden the I2C, the ping 5 and 21 work correctly.
Thank you.

root@GL-AR750S:~#  echo "i2c-gpio.0" > /sys/bus/platform/drivers/i2c-gpio/unbind

root@GL-AR750S:~# echo 5 > /sys/class/gpio/export
root@GL-AR750S:~# cat /sys/class/gpio/gpio5/direction
in
root@GL-AR750S:~# echo out > /sys/class/gpio/gpio5/direction
root@GL-AR750S:~# cat /sys/class/gpio/gpio5/value
0
root@GL-AR750S:~# echo 1 > /sys/class/gpio/gpio5/value
root@GL-AR750S:~# cat /sys/class/gpio/gpio5/value
1
root@GL-AR750S:~# echo 21 > /sys/class/gpio/export
root@GL-AR750S:~# cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 0-31, parent: platform/ath79-gpio, ath79-gpio:
 gpio-1   (                    |gl-ar750s:white:powe) out lo
 gpio-2   (                    |reset               ) in  hi
 gpio-5   (                    |sysfs               ) out hi
 gpio-7   (                    |gl-ar750s:white:usbp) out hi
 gpio-8   (                    |right               ) in  hi
 gpio-19  (                    |gl-ar750s:white:wlan) out hi
 gpio-20  (                    |gl-ar750s:white:wlan) out hi
 gpio-21  (                    |sysfs               ) in  hi
 gpio-22  (                    |sysfs               ) out hi

gpiochip1: GPIOs 489-511, parent: platform/qca956x_wmac, ath9k-phy1:
 gpio-490 (                    |ath9k-phy1          ) in  lo

We had buy another two AR750S modules, but the gpio pin 22 still has the same problem (The gpio 22 can not be set to LOW).

The first one testing record (MAC=E4:95:6E:45:A0:D8)

root@GL-AR750S:~#  ifconfig eth0
eth0      Link encap:Ethernet  HWaddr E4:95:6E:45:A0:D8
          inet6 addr: fe80::e695:6eff:fe45:a0d8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1115326 errors:0 dropped:0 overruns:0 frame:0
          TX packets:942661 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:219084931 (208.9 MiB)  TX bytes:177970230 (169.7 MiB)
          Interrupt:4

root@GL-AR750S:~#  echo 0 > /sys/class/gpio/gpio22/value
root@GL-AR750S:~# cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 0-31, parent: platform/ath79-gpio, ath79-gpio:
 gpio-1   (                    |gl-ar750s:white:powe) out lo
 gpio-2   (                    |reset               ) in  hi
 gpio-5   (                    |sda                 ) in  hi
 gpio-7   (                    |gl-ar750s:white:usbp) out hi
 gpio-8   (                    |right               ) in  hi
 gpio-18  (                    |sysfs               ) out lo
 gpio-19  (                    |gl-ar750s:white:wlan) out lo
 gpio-20  (                    |gl-ar750s:white:wlan) out lo
 gpio-21  (                    |scl                 ) in  hi
 gpio-22  (                    |sysfs               ) out hi

gpiochip1: GPIOs 489-511, parent: platform/qca956x_wmac, ath9k-phy1:
 gpio-490 (                    |ath9k-phy1          ) in  lo

The second one testing record (MAC=E4:95:6E:45:99:3A)

root@GL-AR750S:~# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr E4:95:6E:45:99:3A
          inet6 addr: fe80::e695:6eff:fe45:993a/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1853 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1362 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:242653 (236.9 KiB)  TX bytes:234321 (228.8 KiB)
          Interrupt:4

root@GL-AR750S:~# echo 0 > /sys/class/gpio/gpio22/value
root@GL-AR750S:~# cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 0-31, parent: platform/ath79-gpio, ath79-gpio:
 gpio-1   (                    |gl-ar750s:white:powe) out lo
 gpio-2   (                    |reset               ) in  hi
 gpio-5   (                    |sda                 ) in  hi
 gpio-7   (                    |gl-ar750s:white:usbp) out hi
 gpio-8   (                    |right               ) in  hi
 gpio-18  (                    |sysfs               ) out hi
 gpio-19  (                    |gl-ar750s:white:wlan) out lo
 gpio-20  (                    |gl-ar750s:white:wlan) out hi
 gpio-21  (                    |scl                 ) in  hi
 gpio-22  (                    |sysfs               ) out hi

gpiochip1: GPIOs 489-511, parent: platform/qca956x_wmac, ath9k-phy1:
 gpio-490 (                    |ath9k-phy1          ) in  lo

However, the gpio 18 is correct in the testing.
Maybe it is cause by a hardware or a driver error?