Book Image

Linux Device Driver Development - Second Edition

By : John Madieu
Book Image

Linux Device Driver Development - Second Edition

By: John Madieu

Overview of this book

Linux is by far the most-used kernel on embedded systems. Thanks to its subsystems, the Linux kernel supports almost all of the application fields in the industrial world. This updated second edition of Linux Device Driver Development is a comprehensive introduction to the Linux kernel world and the different subsystems that it is made of, and will be useful for embedded developers from any discipline. You'll learn how to configure, tailor, and build the Linux kernel. Filled with real-world examples, the book covers each of the most-used subsystems in the embedded domains such as GPIO, direct memory access, interrupt management, and I2C/SPI device drivers. This book will show you how Linux abstracts each device from a hardware point of view and how a device is bound to its driver(s). You’ll also see how interrupts are propagated in the system as the book covers the interrupt processing mechanisms in-depth and describes every kernel structure and API involved. This new edition also addresses how not to write device drivers using user space libraries for GPIO clients, I2C, and SPI drivers. By the end of this Linux book, you’ll be able to write device drivers for most of the embedded devices out there.
Table of Contents (23 chapters)
1
Section 1 -Linux Kernel Development Basics
6
Section 2 - Linux Kernel Platform Abstraction and Device Drivers
12
Section 3 - Making the Most out of Your Hardware
18
Section 4 - Misc Kernel Subsystems for the Embedded World

What this book covers

Chapter 1, Introduction to Kernel Development, introduces the Linux kernel development process. The chapter will discuss the downloading, configuring, and compiling steps of a kernel, for x86 as well as for ARM-based systems.

Chapter 2, Understanding Linux Kernel Module Basic Concepts, deals with Linux modularity by means of kernel modules and describes their loading/unloading. It also describes module architecture with some basic concepts.

Chapter 3, Dealing with Kernel Core Helpers, walks through frequently used kernel functions and mechanisms, such as the work queue, wait queue, mutexes, spinlock, and any other facilities that are useful for improved driver reliability.

Chapter 4, Writing Character Device Drivers, focuses on exporting device functionalities to the user space by means of character devices, as well as supporting custom commands using the ioctl interface.

Chapter 5, Understanding and Leveraging the Device Tree, discusses the mechanism to declare and describe devices to the kernel. This chapter explains device addressing, resource handling, and every data type supported in device tree (DT) and their kernel APIs.

Chapter 6, Introduction to Devices, Drivers, and Platform Abstraction, explains the general concept of platform devices, the concept of a pseudo-platform bus, as well as the device- and driver-matching mechanisms.

Chapter 7, Understanding the Concept of Platform Devices and Drivers, describes platform driver architecture in a general manner, and how to handle platform data.

Chapter 8, Writing I2C Device Drivers, dives into I2C device driver architecture, the data structures, and device addressing and accessing methods on the bus.

Chapter 9, Writing SPI Device Drivers, describes SPI-based device driver architecture, as well as the data structures involved. The chapter discusses each device's access method and specificities, as well as traps you should avoid. SPI DT binding is discussed too.

Chapter 10, Understanding the Linux Kernel Memory Allocation, first introduces the concept of virtual memory, to describe the whole kernel memory layout. This chapter then walks through the kernel memory management subsystem, discussing memory allocation and mapping, their APIs, and all devices involved in such mechanisms, as well as the kernel caching mechanism.

Chapter 11, Implementing Direct Memory Access (DMA) Support, introduces DMA and its new kernel API: the DMA Engine API. This chapter will talk about different DMA mappings and describe how to address cache coherency issues. In addition, the chapter summarizes all the concepts with a generic use case.

Chapter 12, Abstracting Memory Access – Introduction to the Regmap API: a Register Map Abstraction, provides an overview of the register map APIs and how they abstract the underlying SPI and I2C transactions. This chapter describes the generic API, as well as the dedicated API.

Chapter 13, Demystifying the Kernel IRQ Framework, demystifies the Linux IRQ core. This chapter walks through Linux IRQ management, starting from interrupt propagation over the system and moving to interrupt controller drivers, thus explaining the concept of IRQ multiplexing, using the Linux IRQ domain API.

Chapter 14, Introduction to the Linux Device Model, provides an overview of the heart of Linux, describing how objects are represented in the kernel, and how Linux is designed under the hood in a general manner, starting from kobject to devices, through to buses, classes, and device drivers.

Chapter 15, Delving into the IIO Framework, introduces the kernel data acquisition and measurement framework, to handle Digital-to-Analog Converters (DACs) and Analog-to-Digital Converters (ADCs). This chapter walks through the IIO APIs, both from kernel space and user space (thanks to libiio), dealing with triggered buffers and continuous data capture.

Chapter 16, Getting the Most Out of the Pin Controller and GPIO Subsystems, describes the kernel pin control infrastructure and APIs, as well as GPIO chip drivers and gpiolib, which is the kernel API to handle GPIO. This chapter also discusses the old and deprecated integer-based GPIO interface, as well as the descriptor-based interface, which is the new one, and finally, the way they can be configured from within the device tree. It also covers libgpiod, which is the official library for dealing with GPIO in user space.

Chapter 17, Leveraging the Linux Kernel Input Subsystem, provides a global view of input subsystems, dealing with both IRQ-based and polled input devices, and introducing both APIs. This chapter explains and shows how user space code deals with such devices.