C H A P T E R  8

Universal Serial Bus

The Universal Serial Bus (USB) is a ubiquitous technology found in a wide variety of products, notably computer peripherals, including mice, keyboards, hard drives, and printers, as well as almost any other type of device or equipment that can be connected to a computer. The USB is a specification that defines the communication between a device, such as a printer or mobile phone, and a host controlled by a computer device, such as your Mac or iPad. The USB specification was developed in 1996 by a consortium of companies, including Compaq, DEC, IBM, Intel, Microsoft, NEC, and Nortel. The motivation was to replace a series of connectors with a universal connector, making it easier to connect external devices to personal computers. The USB specification is currently at version 3.0. Support for 3.0 is still emerging, and support for version 2.0 is by far the most ubiquitous at this time. Apple has yet to release hardware capable of supporting the latest USB 3.0 specification, but Apple computers have shipped with USB support since before OS X. The iOS series of devices are themselves USB devices, but they can also act as USB hosts. An example of this is the iPad, which can act as a host for USB devices, such as digital cameras.

USB is based on a master-slave system, where a controller (host) communicates with slave devices. A host commonly has a one-to-one relationship with a bus.

As a kernel programmer, if you are tasked with writing a driver for a hardware device, there is a major chance that it would be for a USB device. The good news (for us lazy programmers, anyway) is that you can get away without having a driver if your device conforms to one of the classes defined by the USB Implementers Forum (USB-IF). For example, keyboards and mice comply with the human interface device (HID) specification, which makes it unnecessary for a vendor to supply a driver, as the OS will already have a generic driver that can be used to communicate with these devices. However, the vendor could still elect to develop a driver—for example, if the device has advanced capabilities, such as additional customizable buttons on a mouse.

This chapter will provide a broad overview of the USB specification and architecture. The specification is much longer than this book, so obviously a detailed discussion is out of the question. We will instead focus on the parts that matter when implementing a driver for a USB device. We will also discuss the architecture of the USB subsystem provided by I/O Kit, as well as provide code for a fictional USB device driver. It is worth mentioning that USB drivers can be written both in the kernel and in user space. A kernel driver is generally needed when a driver/device can be accessed concurrently by many applications, or if the primary client of the driver is the kernel itself. Examples of devices typically implemented in the kernel are storage, networking, audio, and display drivers, whereas drivers for printers, mice, and keyboards may be handled fully or partially by a user space driver. In this chapter, we will focus on the USB in general, and on the implementation of kernel space drivers. A discussion about user space drivers is provided in Chapter 15.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.46.109