如何重置 USB 控制器?

如何重置 USB 控制器?

当我插入连接有鼠标和键盘的无名 USB 2.0 集线器时,计算机上的 USB 端口停止工作:不再检测到连接到它的设备,无论是通过集线器还是直接连接。

系统重新启动可以使端口再次工作,但我宁愿采用不那么严厉的方法,只“重置”USB 控制器。

答案1

我写了一个适合我的脚本(在 Debian 11 上):

#!/usr/bin/env bash
# Resets all USB host controllers of the system.
# This is useful in case one stopped working
# due to a faulty device having been connected to it.

base="/sys/bus/pci/drivers"
sleep_secs="1"

# This might find a sub-set of these:
# * 'ohci_hcd' - USB 3.0
# * 'ehci-pci' - USB 2.0
# * 'xhci_hcd' - USB 3.0
echo "Looking for USB standards ..."
for usb_std in "$base/"?hci[-_]?c*
do
    echo "* USB standard '$usb_std' ..."
    for dev_path in "$usb_std/"*:*
    do
        dev="$(basename "$dev_path")"
        echo "  - Resetting device '$dev' ..."
        printf '%s' "$dev" | sudo tee "$usb_std/unbind" > /dev/null
        sleep "$sleep_secs"
        printf '%s' "$dev" | sudo tee "$usb_std/bind" > /dev/null
        echo "    done."
    done
    echo "  done."
done
echo "done."

笔记:

  • 它需要 root 访问权限才能重置控制器。

想法取自: https://www.linux.org/threads/resetting-the-usb-subsystem.10404/

相关内容