linux关于usb退出的命令,linux系统USB调试命令笔记

查看USB总线拓扑

lsusb -t

or

lsusb

例1 罗列当前系统下所有的USB Port

lsusb

Output:

Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub

Bus 002 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub

Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Bus 001 Device 003: ID 05c8:021e Cheng Uei Precision Industry Co., Ltd (Foxlink)

Bus 001 Device 007: ID 0cf3:3005 Atheros Communications, Inc. AR3011 Bluetooth

Bus 002 Device 003: ID 0781:5567 San Disk Corp. Cruzer Blade

参数解析:Bus 002 Device 003: ID 0781:5567 SanDisk Corp. Cruzer Blade

Bus 002 : This is bus number where SanDisk USB stick is attached.

Device 003: This is the third device attached to bus 002, the other two devices are “Linux Foundation 2.0 root hub” and ” Intel Corp. Integrated Rate Matching Hub”

ID 0781:5567 is the number given to this SanDisk, The number before : indicates the manufacture ID and number after : indicates device ID. To get more info on this visit Linux-USB site.

SanDisk Corp. Cruzer Blade is the name of manufacture and device name.

例2 检查系统下有多少可用的USB Port

find /dev/bus/

Output:

/dev/bus/

/dev/bus/usb

/dev/bus/usb/002

/dev/bus/usb/002/006

/dev/bus/usb/002/005

/dev/bus/usb/002/004

/dev/bus/usb/002/002

/dev/bus/usb/002/001

/dev/bus/usb/001

/dev/bus/usb/001/007

/dev/bus/usb/001/003

/dev/bus/usb/001/002

/dev/bus/usb/001/001

获取USB设备的详细信息

lsusb -D /dev/bus/usb/002/005

Output:

Device: ID 0951:1643 Kingston Technology Data Traveler G3 4GB

Couldn't open device, some information will be missing

Device Descriptor:

bLength 18

bDescriptorType 1

bcdUSB 2.00

bDeviceClass 0 (Defined at Interface level)

bDeviceSubClass 0

bDeviceProtocol 0

bMaxPacketSize0 64

idVendor 0x0951 Kingston Technology

idProduct 0x1643 DataTraveler G3 4GB

bcdDevice 1.00

iManufacturer 1

iProduct 2

iSerial 3

bNumConfigurations 1

Configuration Descriptor:

bLength 9

bDescriptorType 2

wTotalLength 32

bNumInterfaces 1

bConfigurationValue 1

iConfiguration 0

bmAttributes 0x80

(Bus Powered)

MaxPower 200mA

Interface Descriptor:

bLength 9

bDescriptorType 4

bInterfaceNumber 0

bAlternateSetting 0

bNumEndpoints 2

bInterfaceClass 8 Mass Storage

bInterfaceSubClass 6 SCSI

bInterfaceProtocol 80 Bulk-Only

iInterface 0

Endpoint Descriptor:

bLength 7

bDescriptorType 5

bEndpointAddress 0x81 EP 1 IN

bmAttributes 2

Transfer Type Bulk

Synch Type None

Usage Type Data

wMaxPacketSize 0x0200 1x 512 bytes

bInterval 0

Endpoint Descriptor:

bLength 7

bDescriptorType 5

bEndpointAddress 0x02 EP 2 OUT

bmAttributes 2

Transfer Type Bulk

Synch Type None

Usage Type Data

wMaxPacketSize 0x0200 1x 512 bytes

bInterval 0

例3 获取所有可用的USB Port

lsusb -v

Clipped output:

Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub

Couldn't open device, some information will be missing

Device Descriptor:

bLength 18

bDescriptorType 1

bcdUSB 2.00

bDeviceClass 9 Hub

bDeviceSubClass 0 Unused

bDeviceProtocol 1 Single TT

bMaxPacketSize0 64

idVendor 0x8087 Intel Corp.

idProduct 0x0024 Integrated Rate Matching Hub

bcdDevice 0.00

iManufacturer 0

iProduct 0

iSerial 0

bNumConfigurations 1

Configuration Descriptor:

bLength 9

bDescriptorType 2

wTotalLength 25

bNumInterfaces 1

bConfigurationValue 1

iConfiguration 0

bmAttributes 0xe0

Self Powered

Remote Wakeup

MaxPower 0mA

Interface Descriptor:

bLength 9

bDescriptorType 4

bInterfaceNumber 0

bAlternateSetting 0

bNumEndpoints 1

bInterfaceClass 9 Hub

bInterfaceSubClass 0 Unused

bInterfaceProtocol 0 Full speed (or root) hub

iInterface 0

Endpoint Descriptor:

bLength 7

bDescriptorType 5

bEndpointAddress 0x81 EP 1 IN

bmAttributes 3

Transfer Type Interrupt

Synch Type None

Usage Type Data

wMaxPacketSize 0x0001 1x 1 bytes

bInterval 12

例4 罗列系统下所有大容量存储设备

lsusb -v | grep -Ei '(idVendor|Mass Storage)'

Output:

idVendor 0x2006

bInterfaceClass 8 Mass Storage

idVendor 0x0781 SanDisk Corp.

bInterfaceClass 8 Mass Storage

idVendor 0x0951 Kingston Technology

bInterfaceClass 8 Mass Storage

从上述结果可以看出,共有三个大容量存储设备挂在总线上。

例5 查找USB设备的协议版本

lsusb -v | grep -i bcdusb

Output:

bcdUSB 1.10

bcdUSB 2.00

bcdUSB 2.00

bcdUSB 2.00

USB设备依据协议版本的不同,传输速率也是不同的。下面是USB协议版本与传输速率的对应关系:

USB 1.10

12Mb/s

USB 2.00

480Mb/s

USB 3.00

5Gb/s

例6 以树状结构显示设备信息

lsusb -t

Otuput:

2-1.1:1.1: No such file or directory

/: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/2p, 480M

|__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/6p, 480M

|__ Port 1: Dev 6, If 0, Class=stor., Driver=usb-storage, 480M

|__ Port 1: Dev 6, If 1, Class=vend., Driver=, 480M

|__ Port 2: Dev 7, If 0, Class=stor., Driver=usb-storage, 480M

|__ Port 3: Dev 5, If 0, Class=stor., Driver=usb-storage, 480M

/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci_hcd/2p, 480M

|__ Port 1: Dev 2, If 0, Class=hub, Driver=hub/6p, 480M

|__ Port 3: Dev 3, If 0, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M

|__ Port 3: Dev 3, If 1, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M

|__ Port 4: Dev 7, If 0, Class='bInterfaceClass 0xe0 not yet handled', Driver=btusb, 12M

|__ Port 4: Dev 7, If 1, Class='bInterfaceClass 0xe0 not yet handled', Driver=btusb, 12M

查看USB控制器的ID

cd /sys/bus/pci/drivers/xhci_hcd

ls

result

0000:00:xx.y

一旦知道了设备的ID,那么就可以通过命令disable和enable设备控制器。

//disable controller

echo -n "0000:00:xx.y" > unbind

//enable the controller

echo -n "0000:00:xx.y" > bind

USB Power On/Off

#disable external wake-up; do this only once

echo disabled > /sys/bus/usb/devices/usb1/power/wakeup

echo on > /sys/bus/usb/devices/usb1/power/control # turn on

echo suspend > /sys/bus/usb/devices/usb1/powercontrol # turn off

According to the docs, there were several changes to the USB power management from kernels 2.6.32, which seem to settle in 2.6.38. Now you'll need to wait for the device to become idle, which is governed by the particular device driver. The driver needs to support it, otherwise the device will never reach this state. Unluckily, now the user has no chance to force this. However, if you're lucky and your device can become idle, then to turn this off you need to:

echo "0" > "/sys/bus/usb/devices/usbX/power/autosuspend"

echo "auto" > "/sys/bus/usb/devices/usbX/power/level"

or, for kernels around 2.6.38 and above:

echo "0" > "/sys/bus/usb/devices/usbX/power/autosuspend_delay_ms"

echo "auto" > "/sys/bus/usb/devices/usbX/power/control"

This literally means, go suspend at the moment the device becomes idle.

So unless your fan is something "intelligent" that can be seen as a device and controlled by a driver, you probably won't have much luck on current kernels.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值