Book Image

Linux Device Drivers Development

By : John Madieu
Book Image

Linux Device Drivers Development

By: John Madieu

Overview of this book

Linux kernel is a complex, portable, modular and widely used piece of software, running on around 80% of servers and embedded systems in more than half of devices throughout the World. Device drivers play a critical role in how well a Linux system performs. As Linux has turned out to be one of the most popular operating systems used, the interest in developing proprietary device drivers is also increasing steadily. This book will initially help you understand the basics of drivers as well as prepare for the long journey through the Linux Kernel. This book then covers drivers development based on various Linux subsystems such as memory management, PWM, RTC, IIO, IRQ management, and so on. The book also offers a practical approach on direct memory access and network device drivers. By the end of this book, you will be comfortable with the concept of device driver development and will be in a position to write any device driver from scratch using the latest kernel version (v4.13 at the time of writing this book).
Table of Contents (23 chapters)
Free Chapter
1
Introduction to Kernel Development

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, as well for x86 as for ARM-based systems

Chapter 2, Device Driver Basis, deals with Linux modularity by means of kernel modules, and describes their loading/unloading. It also describe a driver architecture and some basic concepts and some kernel best practices.

Chapter 3, Kernel Facilities and Helper Functions, walks through frequently used kernel functions and mechanisms, such as work queue, wait queue, mutexes, spinlock, and any other facilities that are useful for improved driver reliability.

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

Chapter 5, Platform Device Drivers, explains what a platform device is and introduces the concept of pseudo-platform bus, as well as the device and bus matching mechanism. This chapter describes platform driver architecture in a general manner, and how to handle platform data.

Chapter 6, The Concept of Device Tree, discusses the mechanism to feed device descriptions to the kernel. This chapter explains device addressing, resource handling, every data type supported in DT and their kernel APIs.

Chapter 7, I2C Client Drivers, dives into I2C device drivers architecture, the data structures and device addressing and accessing methods on the bus.

Chapter 8, SPI Device Drivers, describe SPI-based device driver architecture, as well as the data structures involved. The chapter discuss each device's access method and specificities, as well as traps one should avoid. SPI DT binding is discussed too.

Chapter 9, Regmap API – A Register Map Abstraction, provides an overview of the regmap API, and how it abstracts the underlying SPI and I2C transaction. This chapter describes the generic API, as well as the dedicated API.

Chapter 10, IIO framework, introduce the kernel data acquisition and measurement framework, to handle Digital to Analog Converters (DACs) and Analog to Digital Converters (ADCs). This walk through the IIO API, deals with triggered buffers and continuous data capture, and looks at single channel acquisition through the sysfs interface.

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

Chapter 12, DMA – Direct Memory Access, introduce DMA and its new kernel API: the DMA Engine API. This chapter will talk about different DMA mappings and describes how to address cache coherency issues. In addition, the chapter summarize the whole concepts in use cases, based on i.MX6 SoC, from NXP.

Chapter 13, 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 buses, classes, and device drivers. This chapter also highlight sometime unknown side in user space, the kernel object hierarchy in sysfs.

Chapter 14, Pin Control and GPIO Subsystem, describes the kernel pincontrol API 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 DT.

Chapter 15, GPIO Controller Drivers – gpio_chip, necessary elements to write such device drivers. That says, its main data structure is struct gpio_chip. This structure is explained in detail in this chapter, along with a full and working driver provided in the source of the book.

Chapter 16, Advanced IRQ Management, 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 17, Input Devices Drivers, 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.

Chapter 18, RTC Drivers, walks through and demystifies the RTC subsystem and its API. This chapter goes far enough and explains how to deal with alarms from within RTC drivers

Chapter 19, PWM Drivers, provides a full description of the PWM framework, talking about the controller side API as well the consumer side API. PWM management from the user space is discussed in the last section in this chapter.

Chapter 20, Regulator Framework, highlights how important power management is. The first part of the chapter deals with Power Management IC (PMIC) and explains its driver design and API. The second part focuses on the consumer side, talking about requesting and using regulators.

Chapter 21, Framebuffer Drivers, explains framebuffer concept and how it works. It also shows how to design framebuffer drivers, walks through its API, and discusses accelerated as well as non-accelerated methods. This chapter shows how drivers can expose framebuffer memory so that user space can write into, without worrying about underlying tasks.

Chapter 22, Network Interface Card Drivers, walk through the NIC driver’s architecture and their data structures, thus showing you how to handle device configuration, data transfer, and socket buffers.