OpenWrt Forum Archive

Topic: '/sys/class/gpio/gpio4/value' can not be changed by 'echo 0 >...' WHY?

The content of this topic has been archived on 4 May 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

How and why can the following happen? How can I overcome this?

root@OpenWrt:~# cat /sys/class/gpio/gpio4/value 
1
root@OpenWrt:~# echo 0 > /sys/class/gpio/gpio4/value 
root@OpenWrt:~# cat /sys/class/gpio/gpio4/value 
1

A little bit about the background:
I want to reset a freezing 3G stick, so I want to turn USB power off temporarily. I'm on a TP-Link TL-MR3420 v2.3, running BARRIER BREAKER 14.07, r42625 (but CHAOS CALMER Bleeding Edge, r44797 behaves just the same).

It maybe helps:

root@OpenWrt:~# cat /sys/kernel/debug/gpio
GPIOs 0-22, ath79:
 gpio-4   (USB power           ) out hi
 gpio-11  (tp-link:green:3g    ) out hi
 gpio-12  (tp-link:green:lan4  ) out hi
 gpio-13  (tp-link:green:wlan  ) out hi
 gpio-14  (tp-link:green:system) out lo
 gpio-15  (tp-link:green:qss   ) out hi
 gpio-16  (WPS                 ) in  hi
 gpio-17  (Reset button        ) in  hi
 gpio-18  (tp-link:green:wan   ) out hi
 gpio-19  (tp-link:green:lan1  ) out hi
 gpio-20  (tp-link:green:lan2  ) out hi
 gpio-21  (tp-link:green:lan3  ) out hi

Thanks a lot!

The sysfs/gpio does not work on pins that have already been claimed by other parts of the kernel.

Thanks for the reply! Is there a way/patch to workaround this? The above method (echo 0 >...) worked well on earlier versions of this router, which gives me some hope... smile

Two years ago OpenWRT worked well on this device, except powering USB port. However in changeset 37878 they fixed it (see more here). Now I can not power it off. wink Is that possible at all, or MUST one decide at kernel compile time whether to power the USB port or not?

Thanks!

Yes, like you are saying, decide at compile time.  The new version is compiled to take control of pin 4 and force it on so that USB always works right away.  If you want the old way you would have to take that out of the kernel, which I think is just a line in the dts file for the model.

There may be another interface similar to how the buttons and LEDs work.  But it isn't a general gpio like where you were looking.

(Last edited by mk24 on 23 Mar 2015, 16:34)

Thanks a lot, mk24! At least I don't waste my time trying to solve the impossible...

It should also be noted that if your 3G modem keeps crashing, it could be a lack of sufficient DC power from the router.  The radio transmitter in those modems can draw a heavy pulsed current that is close to or over the 500 mA maximum, which is hard on the host's USB power supply.

The discussion might have continued from here.