This section covers material for topic 1.101.7 for the Junior Level Administration (LPIC-1) exam 101. The topic has a weight of 1.
In this section we will look at Linux support for Universal Serial Bus or USB devices. USB was developed by a consortium of companies with the goal of providing a single, simple bus for attachment of peripherals. In the section on BIOS settings, we saw the complexities of managing ports, IRQs and DMA resources in ISA bus machines. The USB design allows devices to be hot-plugged and uses standard connectors for connecting devices. USB devices include keyboards, mice, printers, scanners, hard drives, flash memory drives, cameras, modems, ethernet adapters, and speakers. The list keeps growing. Current Linux support is quite comprehensive, although some devices require special drivers and others, particularly printers, may not be supported or may be only partially supported.
A computer system may provide one or more controllers or hubs. to which either a USB device or another (external) hub may be connected. A hub can support up to 7 devices, some or all of which may be additional hubs. The hub in the system is called the root hub. Each such star topology can support up to 127 hubs or devices.
Note: Frequently, we speak of a USB port which refers to the USB capability in a computer and the connecting socket (compare with serial port or parallel port) rather than the internal port addresses used by the device.
The USB system is a layered system.
- The Bus Interface layer provides physical, signaling, and packet connectivity between hosts and devices, providing data transfer between the host and devices.
- The Device layer is used by the system software to do generic USB operations with a device over the bus. This allows the host to determine characteristics of the device, including device class, vendor name, device name, power requirements, and many capabilities such as device speed or USB level supported.
- The Function layer provides additional capabilities that are specific to the device. Matched host and device software layers permit use device-specific functions.
The earlier USB specifications (1.0 and 1.1) support speeds up to 12Mbps (megabits per second). Devices conforming to this specification are relatively low speed devices, such as printers, mice, keyboards, scanners, and modems. The newer USB 2.0 specification supports speeds up to 480Mbps which is adequate for hard drives and external CD or DVD drives. Some USB 2.0 devices are backwards compatible to allow use on older systems, although not all faster devices are backwards compatible. If your computer does not have USB 2.0 support built in, PCI cards (or PC cards for laptops) are available to provide one or more USB 2.0 ports.
The USB cable is a thin, 4-wire cable with two signal lines plus power and ground. The end plugged into a hub has a flat rectangular connector (called an A connector) while the end plugged into a device or downstream hub has a small more square, connector (the B connector). Several different mini-B connectors exist for connecting small devices such as cameras to a computer. USB devices and hubs may draw power from the USB bus or may be self powered.
USB is now fairly well supported in Linux. Much of the development has occurred in the 2.6 kernel tree. A lot has been backported to 2.4 kernels, with some support even in 2.2 kernels. Linux supports USB 2.0 as well as the earlier specifications. Because of the hot-pluggable nature of USB, support is usually provided through kernel modules which can be loaded or unloaded as necessary. For this tutorial we will assume that the modules you need for your distribution are either available or already installed. If you need to compile your own kernel, refer to the tutorial for Exam 201 Topic 201 (see Resources).
After you have ascertained that your computer has USB ports,
you may check what your Linux system found using the
lspci command as shown in Listing
23. We have filtered the output to show just USB related
Listing 23. lspci output for USB devices
[root@lyrebird root]# lspci | grep -i usb 00:1d.0 USB Controller: Intel Corporation 82801DB/DBL/DBM (ICH4/ICH4-L/ICH4-M) USB UHCI Controller #1 (rev 01) 00:1d.1 USB Controller: Intel Corporation 82801DB/DBL/DBM (ICH4/ICH4-L/ICH4-M) USB UHCI Controller #2 (rev 01) 00:1d.2 USB Controller: Intel Corporation 82801DB/DBL/DBM (ICH4/ICH4-L/ICH4-M) USB UHCI Controller #3 (rev 01) 00:1d.7 USB Controller: Intel Corporation 82801DB/DBM (ICH4/ICH4-M) USB2 EHCI Controller (rev 01)
You will notice that there are four USB controllers in this system. The UHCI and EHCI fields indicate the driver module required to support the controller. The correct USB 1.1 driver depends on the chipset used in your controller. USB 2.0 requires the EHCI driver plus a USB 1.1 driver. See Table 5.
Table 5. Linux USB drivers
|EHCI||USB 2.0 Support - requires one of UHCI, OHCI or JE|
|UHCI||Intel and VIA chipsets|
|JE||This is an alternate to UHCI for 2.4 kernels. If UHCI does not work, and you have an Intel or VIA chipset, try JE|
|OHCI||Compaq, most PowerMacs, iMacs, and PowerBooks, OPTi, SiS, ALi|
We came across the
and the module configuration files /etc/modules.conf (2.4
kernel) and /etc/modprobe.conf (2.6 kernel in our earlier
discussion of sound support. Listing 24 shows some of the
modules associated with USB devices that are loaded on the
same system as Listing 23. This system has a USB mouse
Listing 24. Using lsmod to show loaded USB modules
[root@lyrebird root]# lsmod | egrep 'usb|hci|hid|mouse|Module' Module Size Used by Not tainted usbserial 23420 0 (autoclean) (unused) mousedev 5524 1 hid 22244 0 (unused) input 5888 0 [keybdev mousedev hid] ehci-hcd 20008 0 (unused) usb-uhci 25740 0 (unused) usbcore 77376 1 [usbserial hid ehci-hcd usb-uhci]
Note particularly that the usbcore module is used by all the other USB modules as well as the hid (human interface device) module.
So now we know something of the modules that support USB, how do we find out what USB devices are attached to our system? The information is to be found in the /proc/bus/usb part of the file system. The file /proc/bus/usb/devices contains summary information for currently attached USB devices. a partial listing for our system is shown in Listing 25.
Listing 25. Partial contents of /proc/bus/usb/devices
[root@lyrebird root]# cat /proc/bus/usb/devices T: Bus=04 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=480 MxCh= 6 B: Alloc= 0/800 us ( 0%), #Int= 0, #Iso= 0 D: Ver= 2.00 Cls=09(hub ) Sub=00 Prot=01 MxPS= 8 #Cfgs= 1 P: Vendor=0000 ProdID=0000 Rev= 2.04 S: Manufacturer=Linux 2.4.21-32.0.1.EL ehci-hcd S: Product=Intel Corp. 82801DB USB2 S: SerialNumber=00:1d.7 C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr= 0mA I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub E: Ad=81(I) Atr=03(Int.) MxPS= 2 Ivl=256ms T: Bus=03 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2 B: Alloc= 0/900 us ( 0%), #Int= 0, #Iso= 0 D: Ver= 1.00 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 P: Vendor=0000 ProdID=0000 Rev= 0.00 S: Product=USB UHCI Root Hub S: SerialNumber=1840 C:* #Ifs= 1 Cfg#= 1 Atr=40 MxPwr= 0mA I: If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=255ms
The Spd=480 that we've highlighted above indicates a USB 2.0 bus while the Spd=12 indicates a USB 1.1 (or possibly USB 1.0) device. Further down this listing our mouse is shown as having Spd=1.5. One and a half megabits per second should be fast enough for most mice.
As with other things that we have seen in the /proc file
system, you will be pleased to know that there is a
lsusb command to help you with
display of this information. In particular, you can get a
tree view of your USB devices by using the
-t option. This shows their
attachment hierarchy. You can use the
-d option for information about a
specific device if your system gives an abbreviated display
-t option. The
-v option produces verbose output
which interprets many of the fields that we saw in Listing
25. For Listing 26, we've plugged in an external hub, a
Nikon digital camera, a USB memory key and an external USB
2.00 hard drive and shown you some of the output.
Listing 26. Using the lsusb command
[root@lyrebird root]# lsusb -t Bus# 4 `-Dev# 1 Vendor 0x0000 Product 0x0000 |-Dev# 2 Vendor 0x0409 Product 0x0059 | |-Dev# 8 Vendor 0x04b0 Product 0x0108 | |-Dev# 4 Vendor 0x0d7d Product 0x1400 | `-Dev# 7 Vendor 0x1058 Product 0x0401 `-Dev# 3 Vendor 0x07d0 Product 0x1202 Bus# 3 `-Dev# 1 Vendor 0x0000 Product 0x0000 Bus# 2 `-Dev# 1 Vendor 0x0000 Product 0x0000 Bus# 1 `-Dev# 1 Vendor 0x0000 Product 0x0000 `-Dev# 2 Vendor 0x1241 Product 0x1111 [root@lyrebird root]# lsusb -d 0x0409:0x0059 Bus 004 Device 002: ID 0409:0059 NEC Corp. HighSpeed Hub [root@lyrebird root]# lsusb -d 0x04b0:0x0108 Bus 004 Device 008: ID 04b0:0108 Nikon Corp. Coolpix 2500 [root@lyrebird root]# lsusb -d 0x0d7d:0x1400 Bus 004 Device 004: ID 0d7d:1400 Phison Electronics Corp. [root@lyrebird root]# lsusb -d 0x1058:0x0401 Bus 004 Device 007: ID 1058:0401 Western Digital Technologies, Inc. [root@lyrebird root]# lsusb -d 0x07d0:0x1202 Bus 004 Device 003: ID 07d0:1202 Dazzle [root@lyrebird root]# lsusb -d 0x1241:0x1111 Bus 001 Device 002: ID 1241:1111 Belkin Mouse [root@lyrebird root]#
Listing 27 shows part of the verbose output available from
the lsusb command. This is for a memory key. Note that the
device has indicated its maximum power requirement (200mA).
Note that this device will be treated as a SCSI device. Use
dmesg command or the
fdisk -l command to find out
which SCSI device is mapped to a device. Most cameras
equipped with USB ports, as well as card readers, flash
devices and hard drives are treated as storage class devices
and handled as SCSI devices in Linux. Many cameras come with
Windows programs to help upload and pictures from the
camera. In Linux you can simply mount the SCSI device
representing the camera and copy the pictures to your hard
drive where you can edit them with a program such as the GNU
Image Manipulation Program (the GIMP). You can even erase
files from the memory card or write files to it from Linux,
allowing your camera to be used as an exotic replacement for
a floppy disk.
Listing 27. Verbose output (partial) from lsusb command
[root@lyrebird root]# lsusb -vd 0x0d7d:0x1400 Bus 004 Device 004: ID 0d7d:1400 Phison Electronics Corp. Device Descriptor: bLength 18 bDescriptorType 1 bcdUSB 2.00 bDeviceClass 0 (Defined at Interface level) bDeviceSubClass 0 bDeviceProtocol 0 bMaxPacketSize0 64 idVendor 0x0d7d Phison Electronics Corp. idProduct 0x1400 bcdDevice 0.02 iManufacturer 1 iProduct 2 USB DISK 12X iSerial 3 0743112A0083 bNumConfigurations 1 Configuration Descriptor: bLength 9 bDescriptorType 2 wTotalLength 32 bNumInterfaces 1 bConfigurationValue 1 iConfiguration 0 bmAttributes 0x80 MaxPower 200mA Interface Descriptor: bLength 9 bDescriptorType 4 bInterfaceNumber 0 bAlternateSetting 0 bNumEndpoints 2 bInterfaceClass 8 Mass Storage bInterfaceSubClass 6 SCSI bInterfaceProtocol 80 Bulk (Zip) iInterface 0 ...
One more piece of information that is available to us now that we know the bus and device ids of your USB devices from Listing 26 is a way to determine which modules are required for a particular device. We'll illustrate a couple in Listing 28.
Listing 27. Verbose output (partial) from lsusb command
[root@lyrebird root]# usbmodules --device /proc/bus/usb/004/003 usb-storage [root@lyrebird root]# usbmodules --device /proc/bus/usb/004/007 usb-storage hid
There are two commands that your system might use to handle hot plugging of USB devices, usbmgr and hotplug. According to which you are using, you will find configuration files in the /etc/usbmgr or /etc/hotplug directories. Newer systems are more likely to have hotplug.
Hot plugging for USB (and also PC cards) involves users plugging in devices while a system is running. The system then has to:
- Determine the device type and find a driver to run it
- Bind the driver to the device
- Notify other subsystems about the device. This allows disks to be mounted or print queues to be added for example.