1

I want to turn off (and back on) the USB functionality of a port while leaving the power for charging purpose. I can do this easily with unbind and bind once a device is connected. However, is there a way to do it before a device is connected, to never have a device going active in the first place? I only want to have this one USB port active (manually activated from the console) for service purpose.

I'm using RPi3 ComputeModule with Raspbian Stretch.

Thanks McL

2
  • What model RPi, and which OS version?
    – Seamus
    Commented Jul 3, 2018 at 10:27
  • RPi 3 Compute Module and Raspbian Stretch.
    – McLion
    Commented Jul 3, 2018 at 10:50

2 Answers 2

1

You can let the devices bind on plugin and then unbind them right away via an udev rule. I haven't tested those but they should get you started:

SUBSYSTEMS=="usb", RUN+="/bin/sh -c 'echo -n %k > /sys/bus/usb/drivers/usb/unbind'"
SUBSYSTEMS=="usb", RUN+="/bin/sh -c 'echo 0 > /sys/bus/usb/devices/%k/authorized'"

You can disable this rule from the console before using the USB ports should you need them.

0

You can call unbind on the internal USB hub driver itself. Output from lsusb should include:

Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp. SMC9514 Hub
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

There are directories with bind and unbind nodes for them in /sys/bus/usb/drivers:

hub/
smsc95xx/
5
  • Ok, thanks. But, that will turn off all USB ports, correct? Is there no way to selectively turn off ports? I have a Audio CODEC on one USB port and a storage media on another one, both of them I need permanently. It's an (1) external port that I want to disable but keep supply on for charging.
    – McLion
    Commented Jul 3, 2018 at 14:08
  • Yeah, that will turn off all ports. I very much doubt there is a way to turn off an individual port. You could use a small external hub for the stuff you want to disable.
    – goldilocks
    Commented Jul 3, 2018 at 14:20
  • Actually, there would be a way, if we would have equipped the EEPROM to the LAN9514. Unfortunately, we didn't.
    – McLion
    Commented Jul 3, 2018 at 14:25
  • As a 'second best' solution, it would also be ok to turn the supply off, i.e. completely shut the port down. However, this also seems possible only once a device on the port has been enumerated.
    – McLion
    Commented Jul 3, 2018 at 14:27
  • Output from lsusb on my RPi3B+ lists: Bus 001 Device 007: ID 0781:556c SanDisk Corp. Ultra Bus 001 Device 005: ID 0424:7800 Standard Microsystems Corp. Bus 001 Device 003: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub Bus 001 Device 002: ID 0424:2514 Standard Microsystems Corp. USB 2.0 Hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub It's not obvious which of the driver folders it is necessary to unbind... how is that determined?
    – Seamus
    Commented Jul 3, 2018 at 16:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.