Linux control USB power-enable switch

Hello, I am not able to find any way how to control USB power switch from Linux userspace. Testing it on Colibri VF61, Linux 4.4.39 - clean image by Toradex, slightly modified device tree for our board.

The USB Host power enable line is correctly defined in devicetree as a regulator on a proper GPIO. But how to control the regulator, when I want for example to power cycle freezed device on the port? After some googling, I found that sysfs file /sys/bus/usb/drivers/usb/usb1/power/control could be the point, but it does not accept the “suspend” value, error: Invalid argument.

Of course, if I unbind the regulator from GPIO using
echo regulator-usbh-vbus > /sys/bus/platform/drivers/reg-fixed-voltage/unbind
then I can export the GPIO line and control power switch manually. But I would expect there is some standard way how to control the power switch binded to usb host regulator.

Any experience with this issue?

For all I know, we define the regulator as vbus-supply. The USB driver (chipidea) seems to enable/disable that in ehci_ci_portpower, which is assigned to struct ehci_driver_overrides. So the USB stack should be able to control power power…

Looking at the kernels USB power management documentation (Documentation/usb/power-management.txt) it seems that the pm_qos_no_power_off file is relevant to control VBUS power. But only setting it at the main port seems not to help, all downstream ports need to have it configured too. With this I could successfully power off VBUS:

$ echo 0 > /sys/bus/usb/devices/usb1/1-0:1.0/usb1-port1/power/pm_qos_no_power_off
$ echo 0 > /sys/bus/usb/devices/usb1/1-1/1-1:1.0/1-1-port1/power/pm_qos_no_power_off
$ echo 0 > /sys/bus/usb/devices/usb1/1-1/1-1:1.0/1-1-port2/power/pm_qos_no_power_off
$ echo 0 > /sys/bus/usb/devices/usb1/1-1/1-1:1.0/1-1-port3/power/pm_qos_no_power_off
$ echo 0 > /sys/bus/usb/devices/usb1/1-1/1-1:1.0/1-1-port4/power/pm_qos_no_power_off

Note that this needs no USB device connected or the USB device already suspended/unbinded…