Turn USB power on/off

Hello everyone.

Does anyone know how to toggle on and off the usb port on the beaglebone black? I basically need to turn off a webcam so i can save some battery. Thanks in advance.

Hi @Andres_Ulloa there is a gpio pin you can toggle, to turn off the USB bus…

I last tried it in 2015, it definitely took down the USB port… However when trying to bring it back up, the USB subsystem kernel panic’ed. :wink:



1 Like

Thanks Robert, this helps.

Hi Robert,

Thanks for this. I’m also keen to be able to power-cycle USB devices from a script.

I’ve tried adding the device-tree entries like this (I’m not using overlays):

/ {
       usb_power_ctl_a {                                                                                                         
                pinctrl-names = "default";                                                                                        
                pinctrl-0 = <&usb0_pins>;                                                                                         
                compatible = "gpio-leds";                                                                                         
                usba {                                                                                                            
                        label = "EN-5V-HDA#";                                                                                     
                        gpios = <&gpio0 18 GPIO_ACTIVE_HIGH>;                                                                     
                        default-state = "on";                                                                                     

&am33xx_pinmux {
        pinctrl-names = "default";
        usb0_pins: usb0_pins {
                pinctrl-single,pins = <
                AM33XX_PADCONF(AM335X_PIN_USB0_DRVVBUS, PIN_OUTPUT, MUX_MODE7)        /* usb0_drvvbus.gpio0_18        */

&usb0 {
        pinctrl-names = "default";
        pinctrl-0 = <&usb0_pins>;

        status = "okay";
        dr_mode = "host";

However, this results in the kernel complaining at boot time, and no entry is created under /sys/class/leds:

[    2.132563] pinctrl-single 44e10800.pinmux: pin PIN135 already requested by 47401400.usb; cannot claim for usb_power_ctl_a
[    2.132603] pinctrl-single 44e10800.pinmux: pin-135 (usb_power_ctl_a) status -22
[    2.132620] pinctrl-single 44e10800.pinmux: could not request pin 135 (PIN135) from group usb0_pins  on device pinctrl-single
[    2.132636] leds-gpio usb_power_ctl_a: Error applying setting, reverse things back
[    2.132666] leds-gpio: probe of usb_power_ctl_a failed with error -22

If I take the pinctrl lines out of usb0, then there are no kernel errors, and there’s an entry under /sys/class/leds/EN-5V-HDA#, but changing the “brightness” from 1 to 0 and back has no effect: devices do not enumerate and the USB bus does not work.

If instead I take out the usb_power_ctl_a portion, the error is fxed, but there’s nothing in /sys/class/leds to toggle, obviously.

So it appears that the USB driver really wants to own the USB0_DRVVBUS pin.

What am I missing? I’m using kernel 5.10.59-bone49.

Thanks for any advice,