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:
[url]USB Load Switches - Jetson TX1 - NVIDIA Developer Forums

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.External Media

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
[url]Lack of USB3.0 - Jetson TX2 - NVIDIA Developer Forums
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:

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)

1 Like

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.