USB Power Control

I am trying to control the USB_VBUS_EN1 pin to switch the USB1 VBUS Power on and off.

The main problem we have is that a ZED-Mini camera will not work on boot up and requires to actually disconnect and re connect the USB cable (Issue https://github.com/stereolabs/zed-ros-wrapper/issues/249), the issue itself seems to be a long time to fix so in the mean time we are trying to find a good workaround.

I checked this topic https://devtalk.nvidia.com/default/topic/1030488/jetson-tx1/usb-power-control/ and was able to recompile the DTB following this instructions https://elinux.org/Jetson/TX2_SPI however if I remove the regulator for the “vdd-usb1-5v” as follow

regulator@5 {
                        reg = <0x5>;
                        gpio = <0x12 0x5d 0x0>;
                        regulator-name = "vdd-usb1-5v";
                        compatible = "regulator-fixed-sync";
                        enable-active-high;
                        regulator-min-microvolt = <0x4c4b40>;
                        regulator-disable-ramp-delay = <0x32c8>;
                        gpio-open-drain;
                        regulator-max-microvolt = <0x4c4b40>;
                        phandle = <0x9b>;
                        regulator-enable-ramp-delay = <0x320>;
                        linux,phandle = <0x9b>;
                };

I am able to control the pin on and off for the USB port like follow

sudo su
cd /sys/class/gpio
echo 349 > export
cd gpio349
echo out > direction && echo 0 > value # Will turn off the port
echo out > direction && echo 1 > value # Will turn on the port

But if I connect the camera I will get an error message on dmesg regarding over current condition as follow

[ 5126.689254] usb usb1-port2: over-current condition
[ 5126.696185] tegra186-padctl 3520000.pinctrl: tegra18x_phy_xusb_handle_overcurrent: clear port 1 pin 1 OC
[ 5126.729264] xhci-tegra 3530000.xhci: port 1 over-current detected
[ 5126.735379] tegra186-padctl 3520000.pinctrl: tegra18x_phy_xusb_handle_overcurrent: clear port 1 pin 1 OC
[ 5126.765267] xhci-tegra 3530000.xhci: port 1 over-current detected
[ 5126.771394] tegra186-padctl 3520000.pinctrl: tegra18x_phy_xusb_handle_overcurrent: clear port 1 pin 1 OC
[ 5126.801267] xhci-tegra 3530000.xhci: port 1 over-current detected
[ 5126.807383] tegra186-padctl 3520000.pinctrl: tegra18x_phy_xusb_handle_overcurrent: clear port 1 pin 1 OC
[ 5126.837263] xhci-tegra 3530000.xhci: port 1 over-current detected
[ 5126.843382] tegra186-padctl 3520000.pinctrl: tegra18x_phy_xusb_handle_overcurrent: clear port 1 pin 1 OC

and after that the whole USB will freeze, I understand the message is due to the DTB not having the regulator description but I really don’t know what to do o avoid it.

Please check if below post helps.
https://devtalk.nvidia.com/default/topic/1032451/jetson-tx1/usb-load-switches/post/5255930/#5255930

Hi Dane,

Thank you very much for your response, I am trying to follow the logic on the other topic but I still get the same over current error when I enable the regulator again.

My list of regulators is

lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.0 -> ../../devices/platform/reg-dummy/regulator/regulator.0/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.1 -> ../../devices/fixed-regulators/fixed-regulators:regulator@0/regulator/regulator.1/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.10 -> ../../devices/bpmp_i2c/i2c-4/4-003c/max77620-pmic/regulator/regulator.10/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.11 -> ../../devices/bpmp_i2c/i2c-4/4-003c/max77620-pmic/regulator/regulator.11/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.12 -> ../../devices/bpmp_i2c/i2c-4/4-003c/max77620-pmic/regulator/regulator.12/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.13 -> ../../devices/bpmp_i2c/i2c-4/4-003c/max77620-pmic/regulator/regulator.13/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.14 -> ../../devices/bpmp_i2c/i2c-4/4-003c/max77620-pmic/regulator/regulator.14/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.15 -> ../../devices/bpmp_i2c/i2c-4/4-003c/max77620-pmic/regulator/regulator.15/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.16 -> ../../devices/fixed-regulators/fixed-regulators:regulator@1/regulator/regulator.16/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.17 -> ../../devices/fixed-regulators/fixed-regulators:regulator@2/regulator/regulator.17/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.18 -> ../../devices/fixed-regulators/fixed-regulators:regulator@3/regulator/regulator.18/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.19 -> ../../devices/fixed-regulators/fixed-regulators:regulator@4/regulator/regulator.19/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.2 -> ../../devices/fixed-regulators/fixed-regulators:regulator@101/regulator/regulator.2/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.20 -> ../../devices/fixed-regulators/fixed-regulators:regulator@5/regulator/regulator.20/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.21 -> ../../devices/fixed-regulators/fixed-regulators:regulator@6/regulator/regulator.21/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.22 -> ../../devices/fixed-regulators/fixed-regulators:regulator@7/regulator/regulator.22/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.23 -> ../../devices/fixed-regulators/fixed-regulators:regulator@8/regulator/regulator.23/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.24 -> ../../devices/fixed-regulators/fixed-regulators:regulator@9/regulator/regulator.24/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.25 -> ../../devices/fixed-regulators/fixed-regulators:regulator@118/regulator/regulator.25/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.26 -> ../../devices/fixed-regulators/fixed-regulators:regulator@10/regulator/regulator.26/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.27 -> ../../devices/fixed-regulators/fixed-regulators:regulator@11/regulator/regulator.27/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.28 -> ../../devices/fixed-regulators/fixed-regulators:regulator@12/regulator/regulator.28/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.29 -> ../../devices/fixed-regulators/fixed-regulators:regulator@13/regulator/regulator.29/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.3 -> ../../devices/bpmp_i2c/i2c-4/4-003c/max77620-pmic/regulator/regulator.3/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.30 -> ../../devices/fixed-regulators/fixed-regulators:regulator@14/regulator/regulator.30/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.31 -> ../../devices/fixed-regulators/fixed-regulators:regulator@15/regulator/regulator.31/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.32 -> ../../devices/fixed-regulators/fixed-regulators:regulator@16/regulator/regulator.32/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.33 -> ../../devices/fixed-regulators/fixed-regulators:regulator@17/regulator/regulator.33/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.34 -> ../../devices/fixed-regulators/fixed-regulators:regulator@18/regulator/regulator.34/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.4 -> ../../devices/bpmp_i2c/i2c-4/4-003c/max77620-pmic/regulator/regulator.4/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.5 -> ../../devices/bpmp_i2c/i2c-4/4-003c/max77620-pmic/regulator/regulator.5/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.6 -> ../../devices/bpmp_i2c/i2c-4/4-003c/max77620-pmic/regulator/regulator.6/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.7 -> ../../devices/bpmp_i2c/i2c-4/4-003c/max77620-pmic/regulator/regulator.7/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.8 -> ../../devices/bpmp_i2c/i2c-4/4-003c/max77620-pmic/regulator/regulator.8/
lrwxrwxrwx  1 root root 0 Oct  5 10:30 regulator.9 -> ../../devices/bpmp_i2c/i2c-4/4-003c/max77620-pmic/regulator/regulator.9/

The result of running “sudo cat /sys/kernel/debug/gpio” is the follow:

GPIOs 216-223, platform/max77620-gpio, max77620-gpio, can sleep:
 gpio-216 (                    |external-connection:) in  hi    
 gpio-221 (                    |spmic_gpio_input_5  ) in  lo    
 gpio-222 (                    |spmic_gpio_input_6  ) in  hi    

GPIOs 224-239, i2c/0-0077, tca9539, can sleep:
 gpio-227 (                    |en-vdd-sys          ) out lo    
 gpio-228 (                    |lcd-bias-en-rail    ) out hi    
 gpio-233 (                    |en-vdd-cam          ) out lo    
 gpio-234 (                    |en-vdd-cam-1v2      ) out lo    

GPIOs 240-255, i2c/0-0074, tca9539, can sleep:
 gpio-240 (                    |vdd-usb2-5v         ) out lo    
 gpio-241 (                    |en-vdd-ts-1v8       ) out hi    
 gpio-242 (                    |en-vdd-ts-hv-3v3    ) out hi    
 gpio-243 (                    |en-vdd-disp-3v3     ) out lo    
 gpio-244 (                    |vdd-fan             ) out lo    
 gpio-247 (                    |en-mdm-pwr-3v7      ) out lo    
 gpio-249 (                    |en-vdd-disp-1v8     ) out lo    
 gpio-250 (                    |dis-vdd-1v2         ) out hi    
 gpio-252 (                    |vdd-hdmi            ) out hi    
 gpio-253 (                    |en-vdd-cam-hv-2v8   ) out lo    

GPIOs 256-447, platform/2200000.gpio, tegra-gpio:
 gpio-317 (                    |reset_gpio          ) out lo    
 gpio-348 (                    |vdd-usb0-5v         ) out lo    
 gpio-349 (                    |vdd-usb1-5v         ) out lo    
 gpio-356 (                    |eqos_phy_reset      ) out hi    
 gpio-357 (                    |eqos_phy_intr       ) in  hi    
 gpio-360 (                    |wlan_pwr            ) out hi    
 gpio-362 (                    |cam1-pwdn           ) out lo    
 gpio-377 (                    |hdmi2.0_hpd         ) in  lo    
 gpio-380 (                    |wp                  ) in  hi    
 gpio-381 (                    |cd                  ) in  hi    
 gpio-382 (                    |en-vdd-sd           ) out lo    
 gpio-392 (                    |cam_pwdn_gpio       ) out lo    
 gpio-393 (                    |cam1-rst            ) out lo    
 gpio-397 (                    |cam_reset_gpio      ) out lo    
 gpio-415 (                    |external-connection:) in  hi    
 gpio-420 (                    |bt_ext_wake         ) out hi    

GPIOs 448-511, platform/c2f0000.gpio, tegra-gpio-aon:
 gpio-464 (                    |temp_alert          ) in  hi    
 gpio-504 (                    |Power               ) in  hi    
 gpio-505 (                    |Volume Up           ) in  hi    
 gpio-506 (                    |Volume Down         ) in  hi    
 gpio-507 (                    |wifi-wake-ap        ) in  lo    
 gpio-508 (                    |bt_host_wake        ) in  lo

I tried the disable / enable cycle for the regulators 20 and 33, the regulator 20 is the one linked to “vdd-usb1-5” and gives me the over current error message. The regulator 33 is linked to “vdd-usb2-5v” and does nothing (that I can see at least).

Do you have any suggestions on how to proceed?

Hi molinadavid,
Do you use default carrier board or your own custom board? Are you on r28.2.1?

Hi Dane,
We are using the default Nvidia’s developer carrier board and the latest jetpack for the TX2 with r28.2.1

Hi molinadavid,
Please confirm the steps of reproducing the issue. We will try to reproduce it with USB cameras we have.

Clean flash of r28.2.1
Boot to ubuntu desktop
Insert USB camera and it runs well without hitting overvurrent
Disable regulator.20
Enable regulator.20
Overcurrent happens

Hi Dane,

Mostly those are the steps I did, however I also downloaded the Kernel and enabled the SPI following the instructions on this page https://elinux.org/Jetson/TX2_SPI

I will try now re flashing again just to be sure that I didn’t forget anything in the process.

Also the camera I am using is the Zed mini from Stereolabs.

Hi Dane,

I just confirmed that following the exact steps as you posted without patching the kernel will result on the same over current problem.

Thank you very much for your help

Hi Dane, I just want to check on any updates you can provide on this issue.

Hi molinadavid,
We are checking.

hi DaneLLL,
Do you have any update on this ?

I am facing the ‘over current’ issue too as reported here when trying to enable usb power control on TX2 by disabling regulator@5 block in device tree. For me though, after re-enabling regulator@5, the overcurrent issue goes away. I still am not able to control usb power from userspace. Found few threads discussions on USB power control but they are for TX1.

Please suggest the right way to do that on TX2.
Thanks for your help.

Hi molinadavid/FM2461,
Please remove this code from tegra186_enable_vbus_oc() of file pinctrl-tegra186-padctl.c

reg = padctl_readl(padctl, XUSB_PADCTL_VBUS_OC_MAP);
reg |= VBUS_ENABLE(pin);
padctl_writel(padctl, reg, XUSB_PADCTL_VBUS_OC_MAP);

and try.

Hi DaneLLL,
Where do I find the file pinctrl-tegra186-padctl.c. I don’t see it in the kernel sources (L4T 28.2.1).
Thanks

It is located in kernel/t18x/drivers/pinctrl/pinctrl-tegra186-padctl.c

Thank You Honey_Patouceul
Found it. I was looking in kernel/kernel-4.4/, didn’t realize there were other dirs in kernel/

Hi DaneLLL,
Tried what you suggested in #12 and it worked ! Thanks so much.

Couple of questions -
a) Could this be treated as an actual fix or it is a workaround that might have other implications ? I didn’t see any other issue when testing this fix but want to be sure.
b)Is there a plan to fix this in the next release or so ?
Thanks again!

Hi FM2461, we are checking it. It may not be in next release because we don’t shut down VBUS after booting. It is not the default mode.

hi,i use the jetpack3.3,tx2 and j120 with zedmini, ,the usb3.0 not work when each restart .and can’t find the in kernel/t18x/drivers/pinctrl/pinctrl-tegra186-padctl.c.

Hi,

The source code is at https://developer.nvidia.com/embedded/dlc/sources-r2821

ok,I got it ,but its more different form the jetpack 3.3,I download the jetpack3.3and unpacked,there is a foder named 64TX/2Linux_for_Tegra/kernel/, there is 2 different kernel,one is kernel_headers.tbz2,and anther is kernel_supplements.tbz2,I relly have no idea ahout how to change it and how to use for .can use tell me more detail?THX again .