Linux device drivers are the bridge between advanced applications and hardware devices. Driver development is a technology that combines software and hardware. This book is a book dedicated to Linux device driver development, covering Linux driver basics, driver models, memory management, kernel synchronization mechanisms, I2C drivers, LCD drivers, network drivers, USB drivers, input subsystem drivers, block device drivers, audio device drivers, etc. This book takes examples as the main line and is a learning book and practical guide tailored for Linux device driver developers. This book is based on the Linux 4.5 kernel, provides rich example codes and detailed comments, and comes with complete source code for readers to download. This book is mainly for embedded Linux software and hardware development engineers at all levels, and can also be used as a training experiment textbook for various embedded system training institutions and a supplementary book for computer courses in colleges and universities. Chapter 1 Introduction to Linux Device Drivers 1 1.1 Basics of Device Drivers 1 1.1.1 Concept of Drivers 1 1.1.2 How to Load Drivers 2 1.1.3 Writing Loadable Modules 3 1.1.4 Loadable Modules with Parameters 4 1.1.5 Module Dependencies 5 1.1.6 Levels of printk 7 1.1.7 Device Driver Categories 8 1.2 Principles of Character Device Drivers 9 1.2.1 file_operations structure 9 1.2.2 Registering Character Devices with register_chrdev 11 1.2.3 Registering Character Devices with cdev_add 14 1.2.4 Reading and Writing Character Devices 16 1.2.5 IOCTL Interface 17 1.2.6 Seek Interface 20 1.2.7 Poll Interface 22 1.2.8 Asynchronous Notification 26 1.3 seq_file Mechanism 28 1.3.1 seq_file Principle 28 1.3.2 seq_file Example 29 1.4 /proc File System 35 1.4.1 /proc File System Overview 35 1.4.2 /proc File System Interface 36 1.5 Introduction to the Linux Kernel 40 1.5.1 Linux Kernel Composition 40 1.5.2 Linux Code Structure 42 1.5.3 Kernel Makefile 43 Chapter 2 Linux Device Driver Model 44 2.1 Kernel Object 44 2.1.1 Kobject 44 2.1.2 kobj_type 45 2.1.3 Kset 45 2.2 Device Model Hierarchy 46 2.3 sysfs File System 49 2.4 Platform Concept 51 2.5 Attributes 56 2.6 Device Event Notification 60 2.6.1 kobject uevent 60 2.6.2 uevent helper 61 2.6.3 udev 63 2.7 Device Tree 64 Chapter 3 Linux Kernel Synchronization Mechanism 67 3.1 Atomic Operation 67 3.2 Lock Mechanism 68 3.2.1 Spin Lock 68 3.2.2 Read-Write Lock 70 3.2.3 RCU 71 3.2.4 Semaphore 75 3.2.5 Read-Write Semaphore 77 3.2.6 Mutex 77 3.3 Waiting Queue 78 3.3.1 Waiting Queue Principle 78 3.3.2 Blocking Mode Read Instance 78 3.3.3 Completion Event 81 3.4 Notification Chain 83 Chapter 4 Memory Management and Linked List 86 4.1 Physical Address and Virtual Address 86 4.2 Memory Allocation and Release 87 4.3 Cache 88 4.4 IO Port to Virtual Address Mapping 88 4.4.1 Static Mapping 88 4.4.2 ioremap 89 4.5 Mapping kernel space to user space 90 4.5.1 mmap interface 90 4.5.2 mmap system call 91 4.6 DMA mapping 93 4.7 Kernel linked list 93 4.7.1 Linked list in Linux kernel 93 4.7.2 Kernel linked list example 95 Chapter 5 Tasks and Scheduling 98 5.1 schedule 98 5.2 Kernel thread 99 5.3 Kernel calls application 101 5.4 Softirq mechanism 103 5.4.1 Softirq principle 103 5.4.2 Tasklet 106 5.5 Work queue 108 5.5.1 Work queue principle 108 5.5.2 Delayed work queue 110 5.6 Kernel time 110 5.6.1 Time concept under Linux 110 5.6.2 Delay under Linux 111 5.6.3 Kernel timer 112 Chapter 6 Chapter Simple Hardware Device Driver 115 6.1 Hardware Basics 115 6.1.1 Hardware Device Principle 115 6.1.2 Timing Diagram Principle 116 6.1.3 Embedded Linux System Composition 117 6.1.4 Hardware Initialization 117 6.1.5 clk System 120 6.2 dev/mem and dev/kmem 121 6.3 Register Access 124 6.3.1 S3C6410X Address Mapping 124 6.3.2 S3C6410X Watchdog Driver Example 128 6.4 Level Control 131 6.4.1 S3C6410X LED Driver Example 132 6.4.2 Scanning Button Driver Example 135 6.5 Hardware Interrupt Processing 137 6.5.1 Hardware Interrupt Processing Principle 137 6.5.2 Interrupt Button Driver Example 141 6.6 Watchdog Driver Architecture 146 6.7 RTC Driver 148 6.8 LED Devices 153 Chapter 7 I2C Device Driver 157 7.1 I2C Interface Principle 157 7.2 Linux I2C Driver Architecture 159 7.2.1 I2C Adapter 160 7.2.2 I2C Algorithm 161 7.2.3 I2C Slave Device 161 7.2.4 I2C Slave Device Driver 162 7.2.5 I2C Slave Device Driver Development 163 7.3 I2C Controller Driver 163 7.3.1 S3C2410X I2C Controller 163 7.3.2 S3C2410X I2C Controller Driver 164 7.4 Generic I2C Slave Device 172 7.4.1 Generic I2C Slave Device Driver 172 7.4.2 Reading and Writing through the read and write interfaces 174 7.4.3 Reading and Writing through the I2C_RDWR Command 177 7.4.4 I2Ctools 180 7.5 Personalized I2C Slave Device Driver 181 Chapter 8 TTY and Serial Port Driver 185 8.1 TTY Concept 185 8.2 Linux TTY Driver System 185 8.2.1 TTY Driver Architecture 185 8.2.2 TTY File Layer 186 8.2.3 Line Discipline Layer 188 8.2.4 TTY Driver Layer 190 8.2.5 TTY Data Link Analysis 193 8.3 Serial Port Driver Layer 194 8.3.1 uart_driver 194 8.3.2 uart_port 195 8.4 S3C6410X Serial Port Device Driver 197 8.5 TTY Application layer 201 Chapter 9 Framebuffer driver 203 9.1 Linux Framebuffer driver principle 203 9.1.1 Framebuffer core data structure 203 9.1.2 Framebuffer operation interface 206 9.1.3 Framebuffer driver file interface 207 9.1.4 Framebuffer driver framework code analysis 209 9.2 S3C6410X display controller 210 9.3 S3C6410X LCD Driver Example 215 9.3.1 Registration and Initialization 215 9.3.2 fb_ops Implementation 220 9.3.3 DMA Transfer Mechanism 222 9.3.4 Kernel Configuration 227 9.4 Framebuffer Application Layer 227 9.5 Qt Interface System Porting 229 Chapter 10 Input Subsystem 231 10.1 Overview of Linux Input Subsystem 231 10.2 Principle of Linux Input Subsystem 231 10.2.1 Input Device 232 10.2.2 Input Event 233 10.2.3 Input Handler Layer 234 10.2.4 Commonly Used Input Handler 236 10.3 Input Device Application Layer 241 10.4 Keyboard Input Device Driver Example 243 10.5 Event Interface Example 249
You Might Like
Recommended ContentMore
Open source project More
Popular Components
Searched by Users
Just Take a LookMore
Trending Downloads
Trending ArticlesMore