USB/Guide

This document helps a user setup USB on a Gentoo system and configure various USB devices as well.

What is USB?
USB stands for Universal Serial Bus and is basically an external interface standard that enables communication between the computer and various other peripherals. Some of the most commonly used USB devices today are keyboards, mice, pen drives, digital cameras, external CD & DVD writers, printers etc.

There are currently two versions of USB in use, i.e. USB 1.1 and USB 2.0. Since USB has always been backward compatible with its previous versions, USB 2.0 is backwards compatible with USB 1.1. The latest USB devices are typically USB 2.0 compatible. USB 2.0 supports a maximum data transmission speed of 480 Mbps or 60 MBps and this is the major difference between the two standards. Another advantage with USB is that the devices are all hot-pluggable, which means that you do not have to restart your system in order for you to be able to use these devices.

A technical perspective
Before we go onto the exact configuration options in the kernel, it would be apt to look at USB in a little more detail. If you're in a hurry or want to skip this section, please go to the kernel section.

A USB system has a host controller, hubs, a root hub amongst others and can support up to 127 USB devices including the hubs. The host controller is nothing but the hardware interface between the USB device and the operating system. There are a couple of HCI (Host Controller Interface) in use today and they are the OHCI (Open HCI) by Compaq, UHCI (Universal HCI) and EHCI (Enhanced HCI), both from Intel. The OHCI/UHCI are the two industry standard USB 1.1 interfaces whereas the EHCI is for USB 2.0.

The hardware vendor provides an interface for the programmer that allows the system to interact with the hardware and this is called the HCD or Host Controller Device. It is through this HCD that the device interacts with the system software. The following diagram should make things easier to comprehend.

A USB device can either use a custom driver or use one already present in the system and this is based on the concept of a device class. This means that if a device belongs to a certain class, then other devices belonging to the same class can make use of the same device driver. Some of these classes are the USB HID (Human Interface Devices) class which covers input devices like keyboards and mice, the USB Mass Storage devices class which covers devices like pen drives, digital cameras, audio players etc and the USB CDC (Communication Devices Class) which essentially covers USB modems and similar devices.

What's on your machine?
It is very simple to find out whether your machine has USB 2.0 support or not. We make use of the  command for this purpose.

Example for a USB 1.1 compliant system (not the UHCI in the output):

A system that is USB 2.0 compliant, note the EHCI and UHCI:

So using the  command, we can find out if the system supports USB 2.0. This is useful as we will be enabling the corresponding options in the kernel.

Getting the kernel
First emerge the kernel sources of your choice. Here we'll use. For more information on the various kernel sources available on Portage, please look up the Gentoo Linux Kernel Guide.

Now, lets get on with the task of configuring the kernel.

Config options for the kernel
Now we will look at some of the options we will have to enable in the kernel to ensure proper USB support for our devices.

If you have a USB keyboard, mouse, joystick, or any other input device, you need to enable HID support. Go back one level to "Device drivers" and enable HID support as shown:

Now that your options are set, you can (re)compile the kernel and USB support should be functional once you reboot into the new kernel.

dmesg is your friend!
In this section, we'll see how the system responds to various USB devices. We'll start by plugging in a USB 512 MB Memory Stick/Pen Drive. You could use some other similar mass storage device. We will primarily use  to see what is happening and how the system responds to the device.

Plug in Memory Stick into available USB port and then...

Once the device is connected and mounted, you can access it like a normal hard disk. Usual operations like,  ,  , etc work fine. You could also create a filesystem on the USB stick/format it.

How would a USB mouse show up in case you had one? It will show up as an HID device.

Another nifty command you can use to see the status of your USB ports is. This is part of  and will be covered in the next chapter.

Nifty tools
So far we've seen how much support exists on the kernel/system side for USB on Linux. Now we'll take a peek into what kind of support is provided by Gentoo for USB in the userspace.

One of the most useful tools around is. This lists all the usb devices connected to the system. Installing it is a breeze.

Once installed, you can just run  to get simple info on the USB devices attached to the machine.

If you are one of those types who love to see lots of information, you have the option of running. Try that and see the amount of info it gives out. Another good option is that  dumps the current physical USB hierarchy as a tree and thus makes it easier to understand the exact device map. The command is. For example,

You can easily correlate the outputs of  and , which helps debugging as well as understanding how USB works.

External resources
A good number of online documents helped me during the development of this document and there are some that are highly technical but truly interesting. I thought they all deserve some credit, so here we go!


 * The Official USB Website
 * The USB FAQ
 * Compaq's OHCI Standard
 * Intel's UHCI Standard
 * Intel's EHCI Standard

Acknowledgements
We would like to thank the following authors and editors for their contributions to this guide:


 * Shyam Mani