Home » Linux Kernel » Linux Device Drivers » USB Driver » Understanding sysfs and USB

Understanding sysfs and USB

As we know the USB itself is a very complex peripheral to understand and work upon for development, due to such complexity the sysfs representation of USB bus and the peripherals attached to it is also complex.

We can now see how many root hubs our machine has as below,

$ cd /sys/bus/usb/devices
$ ls -al usb*
usb1 -> ../../../devices/pci0000:00/0000:00:14.0/usb1
usb2 -> ../../../devices/pci0000:00/0000:00:14.0/usb2

This shows that it has 2 root hubs. Now, lets try to correlate it with lsusb. A simple shell script which will print only RootHubs available on your machine.

$ vim lsusb.sh
#!/bin/sh
TOTAL_BUS_NUM=$1
for (( i=1; i <= $TOTAL_BUS_NUM; i++ ))
do
    lsusb -s $i:1
done

Run it as “bash lsusb.sh 2” [ Note: here 2 is the number of root hubs we seen in sysfs ]

$  bash lsusb.sh 2
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub

We can check the sysfs files for one particular device on a USB bus as,

$ tree ../../../devices/pci0000:00/0000:00:14.0/usb1/1-6/
../../../devices/pci0000:00/0000:00:14.0/usb1/1-6/
├── 1-6:1.0
│   ├── authorized
│   ├── bAlternateSetting
│   ├── bInterfaceClass
│   ├── bInterfaceNumber
│   ├── bInterfaceProtocol
│   ├── bInterfaceSubClass
│   ├── bNumEndpoints
│   ├── driver -> ../../../../../../bus/usb/drivers/rtsx_usb
│   ├── ep_01
│   │   ├── bEndpointAddress
│   │   ├── bInterval
│   │   ├── bLength
│   │   ├── bmAttributes
│   │   ├── direction
│   │   ├── interval
│   │   ├── power
│   │   │   ├── async
│   │   │   ├── autosuspend_delay_ms
│   │   │   ├── control
│   │   │   ├── runtime_active_kids
│   │   │   ├── runtime_active_time
│   │   │   ├── runtime_enabled
│   │   │   ├── runtime_status
│   │   │   ├── runtime_suspended_time
│   │   │   └── runtime_usage
│   │   ├── type
│   │   ├── uevent
│   │   └── wMaxPacketSize
│   ├── ep_82
│   │   ├── bEndpointAddress
│   │   ├── bInterval
│   │   ├── bLength
│   │   ├── bmAttributes
│   │   ├── direction
│   │   ├── interval
│   │   ├── power
│   │   │   ├── async
│   │   │   ├── autosuspend_delay_ms
│   │   │   ├── control
│   │   │   ├── runtime_active_kids
│   │   │   ├── runtime_active_time
│   │   │   ├── runtime_enabled
│   │   │   ├── runtime_status
│   │   │   ├── runtime_suspended_time
│   │   │   └── runtime_usage
│   │   ├── type
│   │   ├── uevent
│   │   └── wMaxPacketSize
│   ├── ep_83
│   │   ├── bEndpointAddress
│   │   ├── bInterval
│   │   ├── bLength
│   │   ├── bmAttributes
│   │   ├── direction
│   │   ├── interval
│   │   ├── power
│   │   │   ├── async
│   │   │   ├── autosuspend_delay_ms
│   │   │   ├── control
│   │   │   ├── runtime_active_kids
│   │   │   ├── runtime_active_time
│   │   │   ├── runtime_enabled
│   │   │   ├── runtime_status
│   │   │   ├── runtime_suspended_time
│   │   │   └── runtime_usage
│   │   ├── type
│   │   ├── uevent
│   │   └── wMaxPacketSize
│   ├── interface
│   ├── modalias
│   ├── power
│   │   ├── async
│   │   ├── runtime_active_kids
│   │   ├── runtime_enabled
│   │   ├── runtime_status
│   │   └── runtime_usage
│   ├── rtsx_usb_ms.2.auto
│   │   ├── driver -> ../../../../../../../bus/platform/drivers/rtsx_usb_ms
│   │   ├── driver_override
│   │   ├── memstick_host
│   │   │   └── memstick0
│   │   │       ├── device -> ../../../rtsx_usb_ms.2.auto
│   │   │       ├── power
│   │   │       │   ├── async
│   │   │       │   ├── autosuspend_delay_ms
│   │   │       │   ├── control
│   │   │       │   ├── runtime_active_kids
│   │   │       │   ├── runtime_active_time
│   │   │       │   ├── runtime_enabled
│   │   │       │   ├── runtime_status
│   │   │       │   ├── runtime_suspended_time
│   │   │       │   └── runtime_usage
│   │   │       ├── subsystem -> ../../../../../../../../../class/memstick_host
│   │   │       └── uevent
│   │   ├── modalias
│   │   ├── power
│   │   │   ├── async
│   │   │   ├── autosuspend_delay_ms
│   │   │   ├── control
│   │   │   ├── runtime_active_kids
│   │   │   ├── runtime_active_time
│   │   │   ├── runtime_enabled
│   │   │   ├── runtime_status
│   │   │   ├── runtime_suspended_time
│   │   │   └── runtime_usage
│   │   ├── subsystem -> ../../../../../../../bus/platform
│   │   └── uevent
│   ├── rtsx_usb_sdmmc.1.auto
│   │   ├── driver -> ../../../../../../../bus/platform/drivers/rtsx_usb_sdmmc
│   │   ├── driver_override
│   │   ├── leds
│   │   │   └── mmc0::
│   │   │       ├── brightness
│   │   │       ├── device -> ../../../rtsx_usb_sdmmc.1.auto
│   │   │       ├── max_brightness
│   │   │       ├── power
│   │   │       │   ├── async
│   │   │       │   ├── autosuspend_delay_ms
│   │   │       │   ├── control
│   │   │       │   ├── runtime_active_kids
│   │   │       │   ├── runtime_active_time
│   │   │       │   ├── runtime_enabled
│   │   │       │   ├── runtime_status
│   │   │       │   ├── runtime_suspended_time
│   │   │       │   └── runtime_usage
│   │   │       ├── subsystem -> ../../../../../../../../../class/leds
│   │   │       ├── trigger
│   │   │       └── uevent
│   │   ├── mmc_host
│   │   │   └── mmc0
│   │   │       ├── device -> ../../../rtsx_usb_sdmmc.1.auto
│   │   │       ├── power
│   │   │       │   ├── async
│   │   │       │   ├── autosuspend_delay_ms
│   │   │       │   ├── control
│   │   │       │   ├── runtime_active_kids
│   │   │       │   ├── runtime_active_time
│   │   │       │   ├── runtime_enabled
│   │   │       │   ├── runtime_status
│   │   │       │   ├── runtime_suspended_time
│   │   │       │   └── runtime_usage
│   │   │       ├── subsystem -> ../../../../../../../../../class/mmc_host
│   │   │       └── uevent
│   │   ├── modalias
│   │   ├── power
│   │   │   ├── async
│   │   │   ├── autosuspend_delay_ms
│   │   │   ├── control
│   │   │   ├── runtime_active_kids
│   │   │   ├── runtime_active_time
│   │   │   ├── runtime_enabled
│   │   │   ├── runtime_status
│   │   │   ├── runtime_suspended_time
│   │   │   └── runtime_usage
│   │   ├── subsystem -> ../../../../../../../bus/platform
│   │   └── uevent
│   ├── subsystem -> ../../../../../../bus/usb
│   ├── supports_autosuspend
│   └── uevent
├── authorized
├── avoid_reset_quirk
├── bcdDevice
├── bConfigurationValue
├── bDeviceClass
├── bDeviceProtocol
├── bDeviceSubClass
├── bmAttributes
├── bMaxPacketSize0
├── bMaxPower
├── bNumConfigurations
├── bNumInterfaces
├── busnum
├── configuration
├── descriptors
├── dev
├── devnum
├── devpath
├── driver -> ../../../../../bus/usb/drivers/usb
├── ep_00
│   ├── bEndpointAddress
│   ├── bInterval
│   ├── bLength
│   ├── bmAttributes
│   ├── direction
│   ├── interval
│   ├── power
│   │   ├── async
│   │   ├── autosuspend_delay_ms
│   │   ├── control
│   │   ├── runtime_active_kids
│   │   ├── runtime_active_time
│   │   ├── runtime_enabled
│   │   ├── runtime_status
│   │   ├── runtime_suspended_time
│   │   └── runtime_usage
│   ├── type
│   ├── uevent
│   └── wMaxPacketSize
├── firmware_node -> ../../../../LNXSYSTM:00/LNXSYBUS:00/PNP0A08:00/device:45/device:46/device:4d
├── idProduct
├── idVendor
├── ltm_capable
├── manufacturer
├── maxchild
├── port -> ../1-0:1.0/usb1-port6
├── power
│   ├── active_duration
│   ├── async
│   ├── autosuspend
│   ├── autosuspend_delay_ms
│   ├── connected_duration
│   ├── control
│   ├── level
│   ├── persist
│   ├── runtime_active_kids
│   ├── runtime_active_time
│   ├── runtime_enabled
│   ├── runtime_status
│   ├── runtime_suspended_time
│   ├── runtime_usage
│   ├── wakeup
│   ├── wakeup_abort_count
│   ├── wakeup_active
│   ├── wakeup_active_count
│   ├── wakeup_count
│   ├── wakeup_expire_count
│   ├── wakeup_last_time_ms
│   ├── wakeup_max_time_ms
│   └── wakeup_total_time_ms
├── product
├── quirks
├── removable
├── remove
├── rx_lanes
├── serial
├── speed
├── subsystem -> ../../../../../bus/usb
├── tx_lanes
├── uevent
├── urbnum
└── version

Reference’s


Subscribe our Rurban Life YouTube Channel.. "Rural Life, Urban LifeStyle"

Leave a Comment