Reader small image

You're reading from  Mastering Linux Device Driver Development

Product typeBook
Published inJan 2021
PublisherPackt
ISBN-139781789342048
Edition1st Edition
Right arrow
Author (1)
John Madieu
John Madieu
author image
John Madieu

John Madieu is an embedded Linux and kernel engineer living in Paris, France. His main activities consist of developing device drivers and Board Support Packages (BSPs) for companies in domains such as IoT, automation, transport, healthcare, energy, and the military. John is the founder and chief consultant at LABCSMART, a company that provides training and services for embedded Linux and Linux kernel engineering. He is an open source and embedded systems enthusiast, convinced that it is only by sharing knowledge that we can learn more. He is passionate about boxing, which he practiced for 6 years professionally, and continues to channel this passion through training sessions that he provides voluntarily.
Read more about John Madieu

Right arrow

Preface

Linux is one of the fastest-growing operating systems in the world, and in the last few years, the Linux kernel has evolved significantly to support a wide variety of embedded devices, with its improved subsystems and a lot of new features.

Mastering Linux Device Driver Development provides complete coverage of kernel topics such as video and audio frameworks that usually go unaddressed. You'll delve into some of the most complex and impactful Linux kernel frameworks, such as PCI, ALSA for SoC, and Video4Linux2, gaining expert tips and best practices along the way. In addition to this, you'll learn how to leverage frameworks such as NVMEM and Watchdog. Once the book has got you started with Linux kernel helpers, you'll gradually progress to working with special device types such as Multi-Function Devices (MFDs), followed by video and audio device drivers.

By the end of this book, you'll be able to write rock-solid device drivers and integrate them with some of the most complex Linux kernel frameworks, including V4L2 and ALSA SoC.

Who this book is for

This book is essentially intended for embedded enthusiasts and developers, Linux system administrators, and kernel hackers. Whether you are a software developer, a system architect, or a maker (electronics hobbyist), looking to dive into Linux driver development, this book is for you.

What this book covers

Chapter 1, Linux Kernel Concepts for Embedded Developers, walks through the Linux kernel helpers for locking, blocking I/O, deferring work, and interrupt management.

Chapter 2, Leveraging the Regmap API and Simplifying the Code, provides an overview of the Regmap framework and shows you how to leverage its APIs to ease interrupt management and abstract register access.

Chapter 3, Delving into the MFD Subsystem and Syscon API, focuses on MFD drivers in the Linux kernel, their APIs, and their structures, as well as introducing the syscon and simple-mfd helpers.

Chapter 4, Storming the Common Clock Framework, explains the Linux kernel clock framework and explores both producer and consumer device drivers, as well as their device tree bindings.

Chapter 5, ALSA SoC Framework – Leveraging Codec and Platform Class Drivers, discusses ALSA driver development for both codec and platform devices and introduces concepts such as kcontrol and digital audio power management (DAPM).

Chapter 6, ALSA SoC Framework – Delving into the Machine Class Drivers, dives into ALSA machine class driver development and shows you how to bind both codec and platform together and how to define audio routes.

Chapter 7, Demystifying V4L2 and Video Capture Device Drivers, describes V4L2's key concepts. It focuses on bridge video devices, introduces the concept of subdevices, and covers their respective device drivers.

Chapter 8, Integrating with V4L2 Async and Media Controller Frameworks, introduces the concept of asynchronous probing so that you don't have to care about bridge and subdevice probing order. Finally, this chapter introduces media controller frameworks in order to provide video routing and video pipe customizations.

Chapter 9, Leveraging V4L2 API from the User Space, closes our teaching series on V4L2 and deals with V4L2 from the user space. It first teaches you how to write C code in order to open, configure, and grab data from a video device. It then shows you how to write as little code as possible by leveraging user-space video-related tools such as v4l2-ctl and media-ctl.

Chapter 10, Linux Kernel Power Management, discusses power management on Linux-based systems and teaches you how to write power-aware device drivers.

Chapter 11, Writing PCI Device Drivers, deals with the PCI subsystem and introduces you to its Linux kernel implementation. This chapter also shows you how to write PCI device drivers.

Chapter 12, Leveraging the NVMEM Framework, describes the Linux Non-Volatile Memory (NVEM) subsystem. It first teaches you how to write both provider and consumer drivers as well as their device tree bindings. Then, it shows you how to take the most out of the device from user space.

Chapter 13, Watchdog Device Drivers, provides an accurate description of the Linux kernel Watchdog subsystem. It first introduces you to Watchdog device drivers and gradually takes you through the core of the subsystem, introducing some key concepts such as pre-timeout and governors. Toward the end, this chapter teaches you how to manage the subsystem from the user space.

Chapter 14, Linux Kernel Debugging Tips and Best Practices, highlights the most-used Linux kernel debugging and tracing techniques using kernel-embedded tools such as ftrace and oops message analysis.

To get the most out of this book

To get the most out of this book, some C and system programming knowledge is required. Moreover, the content of the book assumes that you are familiar with the Linux system and most of its basic commands.

Any necessary packages not listed in the preceding table will be described in their respective chapters.

If you are using the digital version of this book, we advise you to type the code yourself. Doing so will help you avoid any potential errors related to the copying and pasting of code.

Download the color images

We also provide a PDF file that has color images of the screenshots/diagrams used in this book. You can download it here: http://www.packtpub.com/sites/default/files/downloads/9781789342048_ColorImages.pdf.

Conventions used

There are a number of text conventions used throughout this book.

Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: "The parent IRQ is not requested here using any of the request_irq() family methods because gpiochip_set_chained_irqchip() will invoke irq_set_chained_handler_and_data() under the hood."

A block of code is set as follows:

static int fake_probe(struct i2c_client *client,                       const struct i2c_device_id *id)
{
    [...]
    mutex_init(&data->mutex);
    [...]
}

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

static int __init my_init(void)
{
    pr_info('Wait queue example\n');
    INIT_WORK(&wrk, work_handler);
    schedule_work(&wrk);
    pr_info('Going to sleep %s\n', __FUNCTION__);
    wait_event_interruptible(my_wq, condition != 0);
    pr_info('woken up by the work job\n');
    return 0;}

Any command-line input or output is written as follows:

# echo 1 >/sys/module/printk/parameters/time
# cat /sys/module/printk/parameters/time

Bold: Indicates a new term, an important word, or words that you see onscreen. Here is an example: "The simple-mfd helper was introduced to handle zero conf/hacks subdevice registering, and syscon was introduced for sharing a device's memory region with other devices."

Tips or important notes

Appear like this.

Get in touch

Feedback from our readers is always welcome.

General feedback: If you have questions about any aspect of this book, mention the book title in the subject of your message and email us at customercare@packtpub.com.

Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata, selecting your book, clicking on the Errata Submission Form link, and entering the details.

Piracy: If you come across any illegal copies of our works in any form on the Internet, we would be grateful if you would provide us with the location address or website name. Please contact us at copyright@packt.com with a link to the material.

If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.

Reviews

Please leave a review. Once you have read and used this book, why not leave a review on the site that you purchased it from? Potential readers can then see and use your unbiased opinion to make purchase decisions, we at Packt can understand what you think about our products, and our authors can see your feedback on their book. Thank you!

For more information about Packt, please visit packt.com.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Mastering Linux Device Driver Development
Published in: Jan 2021Publisher: PacktISBN-13: 9781789342048
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
John Madieu

John Madieu is an embedded Linux and kernel engineer living in Paris, France. His main activities consist of developing device drivers and Board Support Packages (BSPs) for companies in domains such as IoT, automation, transport, healthcare, energy, and the military. John is the founder and chief consultant at LABCSMART, a company that provides training and services for embedded Linux and Linux kernel engineering. He is an open source and embedded systems enthusiast, convinced that it is only by sharing knowledge that we can learn more. He is passionate about boxing, which he practiced for 6 years professionally, and continues to channel this passion through training sessions that he provides voluntarily.
Read more about John Madieu