0%

Master the art of developing customized device drivers for your embedded Linux systems

Key Features

  • Stay up to date with the Linux PCI, ASoC, and V4L2 subsystems and write device drivers for them
  • Get to grips with the Linux kernel power management infrastructure
  • Adopt a practical approach to customizing your Linux environment using best practices

Book Description

Linux is one of the fastest-growing operating systems around 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 range of new features. With this book, you'll find out how you can enhance your skills to write custom device drivers for your Linux operating system.

Mastering Linux Device Driver Development provides complete coverage of kernel topics, including video and audio frameworks, that usually go unaddressed. You'll work with some of the most complex and impactful Linux kernel frameworks, such as PCI, ALSA for SoC, and Video4Linux2, and discover expert tips and best practices along the way. In addition to this, you'll understand how to make the most of frameworks such as NVMEM and Watchdog. Once you've got to grips with Linux kernel helpers, you'll advance to working with special device types such as Multi-Function Devices (MFD) followed by video and audio device drivers.

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

What you will learn

  • Explore and adopt Linux kernel helpers for locking, work deferral, and interrupt management
  • Understand the Regmap subsystem to manage memory accesses and work with the IRQ subsystem
  • Get to grips with the PCI subsystem and write reliable drivers for PCI devices
  • Write full multimedia device drivers using ALSA SoC and the V4L2 framework
  • Build power-aware device drivers using the kernel power management framework
  • Find out how to get the most out of miscellaneous kernel subsystems such as NVMEM and Watchdog

Who this book is for

This book is for embedded developers, Linux system engineers, and system programmers who want to explore Linux kernel frameworks and subsystems. C programming skills and a basic understanding of driver development are necessary to get started with this book.

Table of Contents

  1. Mastering Linux Device Driver Development
  2. Why subscribe?
  3. Contributors
  4. About the author
  5. About the reviewers
  6. Packt is searching for authors like you
  7. Preface
    1. Who this book is for
    2. What this book covers
    3. To get the most out of this book
    4. Download the color images
    5. Conventions used
    6. Get in touch
    7. Reviews
  8. Section 1:Kernel Core Frameworks for Embedded Device Driver Development
  9. Chapter 1: Linux Kernel Concepts for Embedded Developers
    1. Technical requirements
    2. The kernel locking API and shared objects
    3. Spinlocks
    4. Mutexes
    5. The try-lock method
    6. Waiting, sensing, and blocking in the Linux kernel
    7. Work deferring mechanisms
    8. SoftIRQs
    9. Tasklets
    10. Workqueues
    11. Workqueues – a new generation
    12. Linux kernel interrupt management
    13. Designing an interrupt handler
    14. Summary
  10. Chapter 2: Leveraging the Regmap API and Simplifying the Code
    1. Technical requirements
    2. Introduction to regmap and its data structures – I2C, SPI, and MMIO
    3. Accessing device registers
    4. Quick recap on Linux kernel IRQ management
    5. Regmap IRQ API and data structures
    6. Summary
  11. Chapter 3: Delving into the MFD Subsystem and Syscon API
    1. Technical requirements
    2. Introducing the MFD subsystem and Syscon APIs
    3. Device tree binding for MFD devices
    4. Understanding Syscon and simple-mfd
    5. Introducing simple-mfd
    6. Summary
  12. Chapter 4: Storming the Common Clock Framework
    1. Technical requirements
    2. CCF data structures and interfaces
    3. Understanding struct clk_hw and its dependencies
    4. Registering/unregistering the clock provider
    5. Exposing clocks to others (in detail)
    6. Writing a clock provider driver
    7. Providing clock ops
    8. Putting it all together – global overview
    9. Grabbing and releasing clocks
    10. Preparing/unpreparing clocks
    11. Rate functions
    12. Parent functions
    13. Putting it all together
  13. Section 2: Multimedia and Power Saving in Embedded Linux Systems
  14. Chapter 5: ALSA SoC Framework – Leveraging Codec and Platform Class Drivers
    1. Technical requirements
    2. Introduction to ASoC
    3. ASoC Digital Audio Interface
    4. ASoC sub-elements
    5. Writing codec class drivers
    6. Codec DAI and PCM (AKA DSP) configurations
    7. The concept of controls
    8. The concept of DAPM
    9. Writing the platform class driver
    10. The CPU DAI driver
    11. The platform DMA driver AKA PCM DMA driver
    12. Summary
  15. Chapter 6: ALSA SoC Framework – Delving into the Machine Class Drivers
    1. Technical requirements
    2. Introduction to machine class drivers
    3. The DAI link
    4. Machine routing consideration
    5. Codec pins
    6. Board connectors
    7. Machine routing
    8. Clocking and formatting considerations
    9. Sound card registration
    10. Leveraging the simple-card machine driver
    11. Codec-less sound cards
    12. Summary
  16. Chapter 7: Demystifying V4L2 and Video Capture Device Drivers
    1. Technical requirements
    2. Framework architecture and the main data structures
    3. Initializing and registering a V4L2 device
    4. Introducing video device drivers – the bridge driver
    5. Initializing and registering the video device
    6. Video device file operations
    7. V4L2 ioctl handling
    8. The videobuf2 interface and APIs
    9. The concept of sub-devices
    10. Sub-device initialization
    11. Sub-device operations
    12. Traditional sub-device (un)registration
    13. V4L2 controls infrastructure
    14. A word about control inheritance
    15. Summary
  17. Chapter 8: Integrating with V4L2 Async and Media Controller Frameworks
    1. Technical requirements
    2. The V4L2 async interface and the concept of graph binding
    3. Graph binding
    4. The V4L2 async and graph-oriented API
    5. V4L2 async
    6. The Linux media controller framework
    7. The media controller abstraction model
    8. Integrating media controller support in the driver
    9. Media controller from user space
    10. Summary
  18. Chapter 9:Leveraging the V4L2 API from the User Space
    1. Technical requirements
    2. Introduction to V4L2 from user space
    3. The V4L2 user space API
    4. Video device opening and property management
    5. Querying the device capabilities
    6. Buffer management
    7. Image (buffer) format
    8. Requesting buffers
    9. Enqueueing the buffer and enabling streaming
    10. Dequeuing buffers
    11. V4L2 user space tools
    12. Using v4l2-ctl
    13. Debugging V4L2 in user space
    14. Summary
  19. Chapter 10: Linux Kernel Power Management
    1. Technical requirements
    2. The concept of power management on Linux-based systems
    3. Runtime power management
    4. System power management sleep states
    5. Adding power management capabilities to device drivers
    6. Implementing runtime PM capability
    7. System suspend and resume sequences
    8. Implementing system sleep capability
    9. Being a source of system wakeup
    10. Wakeup source and sysfs (or debugfs)
    11. The IRQF_NO_SUSPEND flag
    12. Summary
  20. Section 3: Staying Up to Date with Other Linux Kernel Subsystems
  21. Chapter 11: Writing PCI Device Drivers
    1. Technical requirements
    2. Introduction to PCI buses and interfaces
    3. Terminology
    4. PCI bus enumeration, device configuration, and addressing
    5. PCI address spaces
    6. Interrupt distribution
    7. The Linux kernel PCI subsystem and data structures
    8. PCI data structures
    9. Overview of the PCI driver structure
    10. PCI and Direct Memory Access (DMA)
    11. PCI coherent (aka consistent) mapping
    12. Streaming DMA mapping
    13. Summary
  22. Chapter 12: Leveraging the NVMEM Framework
    1. Technical requirements
    2. Introducing NVMEM data structures and APIs
    3. Writing the NVMEM provider driver
    4. NVMEM device (un)registration
    5. Implementing NVMEM read/write callbacks
    6. Device tree bindings for NVMEM providers
    7. NVMEM consumer driver APIs
    8. NVMEM in user space
    9. Summary
  23. Chapter 13: Watchdog Device Drivers
    1. Technical requirements
    2. Watchdog data structures and APIs
    3. Registering/unregistering a watchdog device
    4. Handling pretimeouts and governors
    5. GPIO-based watchdogs
    6. The watchdog user space interface
    7. Starting and stopping the watchdog
    8. Getting watchdog capabilities and identity
    9. Setting and getting the timeout and pretimeout
    10. Getting the (boot/reboot) status
    11. The watchdog sysfs interface
    12. Summary
  24. Chapter 14: Linux Kernel Debugging Tips and Best Practices
    1. Technical requirements
    2. Understanding the Linux kernel release process
    3. Linux kernel development tips
    4. Message printing
    5. Linux kernel tracing and performance analysis
    6. Using Ftrace to instrument the code
    7. Linux kernel debugging tips
    8. Oops and panic analysis
    9. Using objdump to identify the faulty code line in the kernel module
    10. Summary
  25. Other Books You May Enjoy
    1. Leave a review - let other readers know what you think
3.142.197.212