Overview
"Probably the most wide ranging and complete Linux device driver book I've read."
--Alan Cox, Linux Guru and Key Kernel Developer
"Very comprehensive and detailed, covering almost every single Linux device driver type."
--Theodore Ts'o, First Linux Kernel Developer in North America and Chief Platform Strategist of the Linux Foundation
The Most Practical Guide to Writing Linux Device Drivers
![]() |
Essential Linux Device Drivers |
Linux now offers an exceptionally robust environment for driver development: with today's kernels, what once required years of development time can be accomplished in days. In this practical, example-driven book, one of the world's most experienced Linux driver developers systematically demonstrates how to develop reliable Linux drivers for virtually any device. Essential Linux Device Drivers is for any programmer with a working knowledge of operating systems and C, including programmers who have never written drivers before. Sreekrishnan Venkateswaran focuses on the essentials, bringing together all the concepts and techniques you need, while avoiding topics that only matter in highly specialized situations. Venkateswaran begins by reviewing the Linux 2.6 kernel capabilities that are most relevant to driver developers. He introduces simple device classes; then turns to serial buses such as I2C and SPI; external buses such as PCMCIA, PCI, and USB; video, audio, block, network, and wireless device drivers; user-space drivers; and drivers for embedded Linux–one of today's fastest growing areas of Linux development. For each, Venkateswaran explains the technology, inspects
relevant kernel source files, and walks through developing a complete example.
• Addresses drivers discussed in no other book, including drivers for I2C, video, sound, PCMCIA, and different types of flash memory
• Demystifies essential kernel services and facilities, including kernel threads and helper interfaces
• Teaches polling, asynchronous notification, and I/O control
• Introduces the Inter-Integrated Circuit Protocol for embedded Linux drivers
• Covers multimedia device drivers using the Linux-Video subsystem and Linux-Audio framework
• Shows how Linux implements support for wireless technologies such as Bluetooth, Infrared, WiFi, and cellular networking
• Describes the entire driver development lifecycle, through debugging and maintenance
• Includes reference appendixes covering Linux assembly, BIOS calls, and Seq files
It was the late 1990s, and at IBM we were putting the Linux kernel on a wristwatch. The target device was tiny,
but the task was turning out to be tough. The Memory Technology Devices subsystem didn't exist in the kernel,
which meant that before a filesystem could start life on the watch's flash memory, we had to develop the
necessary storage driver from scratch. Interfacing the watch's touch screen with user applications was
complicated because the kernel's input event driver interface hadn't been conceived yet. Getting X Windows to
run on the watch's LCD wasn't easy because it didn't work well with frame buffer drivers. Of what use is a
waterproof Linux wristwatch if you can't stream stock quotes from your bathtub? Bluetooth integration with
Linux was several years away, and months were spent porting a proprietary Bluetooth stack to Internet-enable
the watch. Power management support was good enough only to squeeze a few hours of juice from the watch's battery; hence we had work cut out on that front, too.
Linux-Infrared was still unstable, so we had to coax the stack before we could use an Infrared keyboard for data entry. And we had to compile the compiler and crosscompile
a compact application-set because there were no accepted distributions in the consumer electronics space.
Fast forward to the present: The baby penguin has grown into a healthy teenager. What took thousands of lines
of code and a year in development back then can be accomplished in a few days with the current kernels.
But to become a versatile kernel engineer who can magically weave solutions, you need to understand the myriad features and facilities that Linux offers today.
About the Book
Among the various subsystems residing in the kernel source tree, the drivers/ directory constitutes the single
largest chunk and is several times bigger than the others. With new and diverse technologies arriving in popular
form factors, the development of new device drivers in the kernel is accelerating steadily.
The latest kernels support more than 70 device driver families.
This book is about writing Linux device drivers. It covers the design and development of major device classes
supported by the kernel, including those I missed during my Linux-on-Watch days.
The discussion of each driver family starts by looking at the corresponding technology, moves on to develop a practical example, and ends by looking at relevant kernel source files.
Before foraying into the world of device drivers, however, this book introduces you to the kernel and discusses the important features of 2.6 Linux, emphasizing those portions that
are of special interest to device driver writers.
Table of Contents
Index
Copyright
Prentice Hall Open Source Software Development Series
Foreword
Preface
Acknowledgments
About the Author
Chapter 1. Introduction
Evolution
The GNU Copyleft
Kernel.org
Mailing Lists and Forums
Linux Distributions
Looking at the Sources
Building the Kernel
Loadable Modules
Before Starting
Chapter 2. A Peek Inside the Kernel
Booting Up
Kernel Mode and User Mode
Process Context and Interrupt Context
Kernel Timers
Concurrency in the Kernel
Process Filesystem
Allocating Memory
Looking at the Sources
Chapter 3. Kernel Facilities
Kernel Threads
Helper Interfaces
Looking at the Sources
Chapter 4. Laying the Groundwork
Introducing Devices and Drivers
Interrupt Handling
The Linux Device Model
Memory Barriers
Power Management
Looking at the Sources
Chapter 5. Character Drivers
Char Driver Basics
Device Example: System CMOS
Sensing Data Availability
Talking to the Parallel Port
RTC Subsystem
Pseudo Char Drivers
Misc Drivers
Character Caveats
Looking at the Sources
Chapter 6. Serial Drivers
Layered Architecture
UART Drivers
TTY Drivers
Line Disciplines
Looking at the Sources
Chapter 7. Input Drivers
Input Event Drivers
Input Device Drivers
Debugging
Looking at the Sources
Chapter 8. The Inter-Integrated Circuit Protocol
What's I2C/SMBus?
I2C Core
Bus Transactions
Device Example: EEPROM
Device Example: Real Time Clock
I2C-dev
Hardware Monitoring Using LM-Sensors
The Serial Peripheral Interface Bus
The 1-Wire Bus
Debugging
Looking at the Sources
Chapter 9. PCMCIA and Compact Flash
What's PCMCIA/CF?
Linux-PCMCIA Subsystem
Host Controller Drivers
PCMCIA Core
Driver Services
Client Drivers
Tying the Pieces Together
PCMCIA Storage
Serial PCMCIA
Debugging
Looking at the Sources
Chapter 10. Peripheral Component Interconnect
The PCI Family
Addressing and Identification
Accessing PCI Regions
Direct Memory Access
Device Example: Ethernet-Modem Card
Debugging
Looking at the Sources
Chapter 11. Universal Serial Bus
USB Architecture
Linux-USB Subsystem
Driver Data Structures
Enumeration
Device Example: Telemetry Card
Class Drivers
Gadget Drivers
Debugging
Looking at the Sources
Chapter 12. Video Drivers
Display Architecture
Linux-Video Subsystem
Display Parameters
The Frame Buffer API
Frame Buffer Drivers
Console Drivers
Debugging
Looking at the Sources
Chapter 13. Audio Drivers
Audio Architecture
Linux-Sound Subsystem
Device Example: MP3 Player
Debugging
Looking at the Sources
Chapter 14. Block Drivers
Storage Technologies
Linux Block I/O Layer
I/O Schedulers
Block Driver Data Structures and Methods
Device Example: Simple Storage Controller
Advanced Topics
Debugging
Looking at the Sources
Chapter 15. Network Interface Cards
Driver Data Structures
Talking with Protocol Layers
Buffer Management and Concurrency Control
Device Example: Ethernet NIC
ISA Network Drivers
Asynchronous Transfer Mode
Network Throughput
Looking at the Sources
Chapter 16. Linux Without Wires
Bluetooth
Infrared
WiFi
Cellular Networking
Current Trends
Chapter 17. Memory Technology Devices
What's Flash Memory?
Linux-MTD Subsystem
Map Drivers
NOR Chip Drivers
NAND Chip Drivers
User Modules
MTD-Utils
Configuring MTD
eXecute In Place
The Firmware Hub
Debugging
Looking at the Sources
Chapter 18. Embedding Linux
Challenges
Component Selection
Tool Chains
Embedded Bootloaders
Memory Layout
Kernel Porting
Embedded Drivers
The Root Filesystem
Test Infrastructure
Debugging
Chapter 19. Drivers in User Space
Process Scheduling and Response Times
Accessing I/O Regions
Accessing Memory Regions
User Mode SCSI
User Mode USB
User Mode I2C
UIO
Looking at the Sources
Chapter 20. More Devices and Drivers
ECC Reporting
Frequency Scaling
Embedded Controllers
ACPI
ISA and MCA
FireWire
Intelligent Input/Output
Amateur Radio
Voice over IP
High-Speed Interconnects
Chapter 21. Debugging Device Drivers
Kernel Debuggers
Kernel Probes
Kexec and Kdump
Profiling
Tracing
Linux Test Project
User Mode Linux
Diagnostic Tools
Kernel Hacking Config Options
Test Equipment
Chapter 22. Maintenance and Delivery
Coding Style
Change Markers
Version Control
Consistent Checksums
Build Scripts
Portable Code
Chapter 23. Shutting Down
Checklist
What Next?
Appendix A. Linux Assembly
Debugging
Appendix B. Linux and the BIOS
Real Mode Calls
Protected Mode Calls
BIOS and Legacy Drivers
Appendix C. Seq Files
The Seq File Advantage
Updating the NVRAM Driver
Looking at the Sources
Index
About the Author
Sreekrishnan Venkateswaran has a master's degree in computer science from the Indian Institute of
Technology, Kanpur, India. During the past 12 years that he has been working for IBM, he has ported Linux to various embedded devices such as a wristwatch, handheld, music player, VoIP phone, pacemaker programmer, and remote patient monitoring system. Sreekrishnan was a contributing editor and kernel columnist to the Linux Magazine for more than 2 years. Currently, he manages the embedded solutions group at IBM India.