mvp / uhubctl

uhubctl - USB hub per-port power control
Other
2.19k stars 228 forks source link

Raspberry Pi5 Raspbian 12 bookworm #547

Closed wlanrouter closed 5 months ago

wlanrouter commented 9 months ago

It seems like uhubctl ist not working on Raspberry Pi5 Raspbian 12 bookworm

# lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 012: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
# uhubctl
Current status for hub 4 [1d6b:0003 Linux 6.1.0-rpi6-rpi-v8 xhci-hcd xHCI Host Controller xhci-hcd.1, USB 3.00, 1 ports, ppps]
  Port 1: 02a0 power 5gbps Rx.Detect
Current status for hub 3 [1d6b:0002 Linux 6.1.0-rpi6-rpi-v8 xhci-hcd xHCI Host Controller xhci-hcd.1, USB 2.00, 2 ports, ppps]
  Port 1: 0100 power
  Port 2: 0100 power
Current status for hub 2 [1d6b:0003 Linux 6.1.0-rpi6-rpi-v8 xhci-hcd xHCI Host Controller xhci-hcd.0, USB 3.00, 1 ports, ppps]
  Port 1: 02a0 power 5gbps Rx.Detect
Current status for hub 1 [1d6b:0002 Linux 6.1.0-rpi6-rpi-v8 xhci-hcd xHCI Host Controller xhci-hcd.0, USB 2.00, 2 ports, ppps]
  Port 1: 0100 power
  Port 2: 0103 power enable connect [0403:6001 FTDI FT232R USB UART 001X8MQT]

I want to disable FT232 as I am used to from my Raspberry Pi 3B

# uhubctl -a 0 -l 1 -p 2
Current status for hub 1 [1d6b:0002 Linux 6.1.0-rpi6-rpi-v8 xhci-hcd xHCI Host Controller xhci-hcd.0, USB 2.00, 2 ports, ppps]
  Port 2: 0103 power enable connect [0403:6001 FTDI FT232R USB UART 001X8MQT]
Sent power off request
New status for hub 1 [1d6b:0002 Linux 6.1.0-rpi6-rpi-v8 xhci-hcd xHCI Host Controller xhci-hcd.0, USB 2.00, 2 ports, ppps]
  Port 2: 0000 off
# uhubctl
Current status for hub 4 [1d6b:0003 Linux 6.1.0-rpi6-rpi-v8 xhci-hcd xHCI Host Controller xhci-hcd.1, USB 3.00, 1 ports, ppps]
  Port 1: 02a0 power 5gbps Rx.Detect
Current status for hub 3 [1d6b:0002 Linux 6.1.0-rpi6-rpi-v8 xhci-hcd xHCI Host Controller xhci-hcd.1, USB 2.00, 2 ports, ppps]
  Port 1: 0100 power
  Port 2: 0100 power
Current status for hub 2 [1d6b:0003 Linux 6.1.0-rpi6-rpi-v8 xhci-hcd xHCI Host Controller xhci-hcd.0, USB 3.00, 1 ports, ppps]
  Port 1: 02a0 power 5gbps Rx.Detect
Current status for hub 1 [1d6b:0002 Linux 6.1.0-rpi6-rpi-v8 xhci-hcd xHCI Host Controller xhci-hcd.0, USB 2.00, 2 ports, ppps]
  Port 1: 0100 power
  Port 2: 0000 off
# lsusb
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 013: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

The device LED is also powered. Is it Raspberry that removed the feature from Pi5? Can believe it, but I am also not able to find information regarding the hardware support.

mvp commented 9 months ago

Unfortunately, I don't have RPi5. I have reached out to Rasperry Pi foundation with request to send me one to investigate if it is compatible with uhubctl, but they never replied.

I looked around for a places to buy RPi5, and all have this on long backorder (Feb 2024 is the earliest).

If anyone can give me remote ssh access to RPi5 with sudo root, that might be all I need to fix this, or at least to say if this is possible at all.

nbuchwitz commented 8 months ago

I did some investigation with RPi5 and uhubctl. Looks like the port are kinda ganged / the driver behaves oddly: If you disable USB3 duality handling (-e) and turn off each port individually the last port switches the power off (order does not matter). The first port which is activated turns the power back on (also order does not matter).

Will dig a bit deeper in the RP1 stuff and let you know if I found something.

nbuchwitz commented 8 months ago

Long story short: Raspberry Pi 5 does only have one vbus switch (ganged) and thus cannot support per port power switching. If you switch off all ports, the last clear feature command switches off the power. The first set feature command turns it on again (like specified in the usb specs).

Also USB3 duality handling does not work, because it's a root hub and does not have a container id.

See https://github.com/raspberrypi/linux/issues/5870#issuecomment-1900684562

mvp commented 8 months ago

Thanks for investigating @nbuchwitz. Can you please show output for sudo uhubctl on RPi5, what it's USB topology looks like, which ports are required to be turned off, etc?

Basically, I want to create a doc page similar to what we have for RPi4B: https://github.com/mvp/uhubctl#raspberry-pi-4b.

nbuchwitz commented 8 months ago

Already working on a doc PR for this.

lsusb -tv:

/:  Bus 04.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 5000M
    ID 1d6b:0003 Linux Foundation 3.0 root hub
/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/2p, 480M
    ID 1d6b:0002 Linux Foundation 2.0 root hub
/:  Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/1p, 5000M
    ID 1d6b:0003 Linux Foundation 3.0 root hub
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci-hcd/2p, 480M
    ID 1d6b:0002 Linux Foundation 2.0 root hub

sudo uhubtl

Current status for hub 4 [1d6b:0003 Linux 6.1.0-rpi7-rpi-2712 xhci-hcd xHCI Host Controller xhci-hcd.1, USB 3.00, 1 ports, ppps]
  Port 1: 02a0 power 5gbps Rx.Detect
Current status for hub 3 [1d6b:0002 Linux 6.1.0-rpi7-rpi-2712 xhci-hcd xHCI Host Controller xhci-hcd.1, USB 2.00, 2 ports, ppps]
  Port 1: 0100 power
  Port 2: 0100 power
Current status for hub 2 [1d6b:0003 Linux 6.1.0-rpi7-rpi-2712 xhci-hcd xHCI Host Controller xhci-hcd.0, USB 3.00, 1 ports, ppps]
  Port 1: 02a0 power 5gbps Rx.Detect
Current status for hub 1 [1d6b:0002 Linux 6.1.0-rpi7-rpi-2712 xhci-hcd xHCI Host Controller xhci-hcd.0, USB 2.00, 2 ports, ppps]
  Port 1: 0100 power
  Port 2: 0100 power

In order to switch vusb off, you need to switch off each port and the last clear feature will remove vusb. For switching on the first ports set feature turns on vusb.

When multiple ports share a power switch, setting PORT_POWER on any port in the group will cause the power to all ports in the group to turn on. It will not, however, cause the other ports in that group to leave the Powered-off state.

(Universal Serial Bus Specification Revision 2.0, 11.11.1 Multiple Gangs)

wlanrouter commented 5 months ago

Hi all. I don't get it. Is it possible to turn off power? If not, does anyone knows a hardware solution? Like a USB Switch which can be controlled over another USB port or GPIO?

mvp commented 5 months ago

Again, unfortunately I don't have Raspberry Pi 5 in my possession and cannot confirm it one way or another. I suspect we may need some hack implemented in uhubctl to make RPi5 work, much like what we did for RPi4.

nbuchwitz commented 5 months ago

Try to find some spare time for my pr on this. As I already wrote above, the implementation on Pi5 is unfortunately a bit broken. There is only one ganged vbus switch, which disables all ports at once. This means that individual port vusb control cannot work on Pi5.

The vbus switch can easily be toggled via gpio too

wlanrouter commented 5 months ago

How can I disable all ports? There is only one device attached, so I could live with disabling all ports.

rmorgans commented 5 months ago

@mvp reach out if you want a pi5, email address in my github profile.

mvp commented 5 months ago

Thank you @rmorgans! Responded

mvp commented 5 months ago

Added support for Raspberry Pi 5 in 3d804c1ab7479.

Much thanks to @rmorgans for sending me new Raspberry Pi 5 so I was able to debug the issue.

Read more about RPi5 USB topology here https://github.com/mvp/uhubctl?tab=readme-ov-file#raspberry-pi-5, but long story short, build uhubctl from master branch, then use these 2 commands to turn power off (all ports only):

uhubctl -l 1 -a 0
uhubctl -l 3 -a 0

and this to turn back on:

uhubctl -l 1 -a 1
uhubctl -l 3 -a 1