USB Power control

Hi,
We are using the Jetson Nano dev board and we need to be able to power-cycle the USB ports from user-space.

I have seen posts like this, which looks good:
https://devtalk.nvidia.com/default/topic/1032451/jetson-tx1/usb-load-switches/post/5255930/#5255930

Is this possible with the Nano on the dev-kit?

Thanks

Hi,
Please check if your board version is A02. On A02 board, the control pin is GPIO_PA6.

Thank you very much for the response.

Our device is a ‘A02’ version, however I’m not able to export the pin.

ubuntu@jetson-1:~$ sudo cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 0-255, parent: platform/6000d000.gpio, tegra-gpio:
 gpio-2   (                    |pcie_wake           ) in  hi
 gpio-6   (                    |vdd-usb-hub-en      ) out hi
 gpio-151 (                    |cam_reset_gpio      ) out lo
 gpio-187 (                    |?                   ) out hi
 gpio-189 (                    |Power               ) in  hi IRQ
 gpio-190 (                    |Forcerecovery       ) in  hi IRQ
 gpio-201 (                    |cd                  ) in  lo IRQ
 gpio-202 (                    |pwm-fan-tach        ) in  hi IRQ
 gpio-203 (                    |vdd-3v3-sd          ) out hi
 gpio-225 (                    |hdmi2.0_hpd         ) in  hi IRQ
 gpio-228 (                    |extcon:extcon@1     ) in  hi IRQ

gpiochip1: GPIOs 504-511, parent: platform/max77620-gpio, max77620-gpio, can sleep:
 gpio-505 (                    |spmic-default-output) out hi
 gpio-507 (                    |vdd-3v3-sys         ) out hi
 gpio-510 (                    |enable              ) out lo
 gpio-511 (                    |avdd-io-edp-1v05    ) out lo

ubuntu@jetson-1:~$ sudo echo 6 > /sys/class/gpio/export
echo: write error: Device or resource busy

I get the same response using python gpio library. Can you tell me how to use access this pin?

Cheers

Hi,
Please refer to
https://devtalk.nvidia.com/default/topic/1045488/jetson-tx2/lack-of-usb3-0/post/5305955/#5305955
The pin might be used as another function.

The problem is this:

sudo echo 6 > /sys/class/gpio/export

This tells the shell to run “echo 6” in the context of super-user, after redirecting standard out to /sys/class/gpio/export…
But the shell is not root, so it can’t redirect to that file.
You need to either first “sudo -i” and then run the commands without sudo (so you have a root shell,) or run the entire shell expression as root.

sudo sh -c 'echo 6 > /sys/class/gpio/export

Or you can just bang the registers directly, using C/C++ code. There’s some code here to do that:
https://github.com/jwatte/jetson-gpio-example

Note that this code is written as an example of how to talk to the GPIO hardware from user space; I haven’t tested it for this particular use case. But … it ought to work, perhaps with minimal changes?
Also, because it uses /dev/mem, it needs root.

Thanks very much DaneLLL and snarky.

The echo 6 suggestion yields the same result as before, even with the extra sudo flag.

DaneLLL: your link points to pretty much exactly what we’re trying to do: power-cycle the usb hub.
However, the corresponding regulator device on the Nano doesn’t seem to respond to writing to the ‘state’ file as shown here:

root@MA10014:/home/ubuntu# cat /sys/kernel/debug/regulator/vdd-usb-hub-en/regulator/state
enabled
root@MA10014:/home/ubuntu# echo disabled > /sys/kernel/debug/regulator/vdd-usb-hub-en/regulator/state
root@MA10014:/home/ubuntu# cat /sys/kernel/debug/regulator/vdd-usb-hub-en/regulator/state
disabled
root@MA10014:/home/ubuntu# echo disablebad > /sys/kernel/debug/regulator/vdd-usb-hub-en/regulator/state
root@MA10014:/home/ubuntu# cat /sys/kernel/debug/regulator/vdd-usb-hub-en/regulator/state
disabled
root@MA10014:/home/ubuntu# echo enabled > /sys/kernel/debug/regulator/vdd-usb-hub-en/regulator/state
root@MA10014:/home/ubuntu# cat /sys/kernel/debug/regulator/vdd-usb-hub-en/regulator/state
enabled

Is there anything else I need to do for that setting to take effect?

Thanks.

Hi,
On Nano, please download/extract the attachment and follow the steps:

Copy realtek_hub_power_cycle.c to Jetson Nano
$ sudo apt-get install libusb-1.0-0-dev
$ gcc -o power_cycle realtek_hub_power_cycle.c -lusb-1.0
$ sudo ./power_cycle

realtek_hub_power_cycle.zip (653 Bytes)

Thank you very much DaneLLL, that worked perfectly. Very much appreciated.

Can you point me to any documentation for the commands that libusb_control_transfer is using?

Cheers

Hi,

It is suggested by vendor and there is no public document. FYI.

As I am having an unstable WLAN Access I supected that this solution could help.
Using this command (June 2020; more recent software):
sudo apt-get install libusb-1.0-0-dev
Its said, already installed.
When using:
gcc -o power_cycle realtek_hub_power_cycle.c -lusb-1.0
there is an error message:
gcc: error: realtek_hub_power_cycle.c: No such file or directory.
Nevertheless, the message: WARNING: system is no being throttled is still coming.
Was there a change?

Hi,
power_cycle realtek_hub_power_cycle.c is in the attachment

Hi, just want to confirm, if this script works for Jetson Nano to power cycle individual USB port? or is there anyway to control individual port? Thanks!

Hi,

It is to reset vendor’s hub. If you would need further detail, please contact vendor. Thanks.