The so-called I/O memory is a mapping of the host's memory through various interfaces connected to the host's hardware. The LED driver also provides two ways of interacting: command and read-write device files.
Steps to create a device file:
1th Step: Initialize the Cdev with the Cdev_init function
2nd step: Specify the device number
The device number of the Linux device file is the primary device number and the secondary device number, where the first 12 bits represent the main device number, and the last 20 bits represent the secondary device number. There are two ways to specify the device number:
(1) Specify (hard-coded) directly in the code.
(2) Dynamic allocation.
3rd Step: Use the Cdev_add function to add the character device to the character device array in the kernel
4th step: Create a struct class using the Class_create macro
5th step: Create a device file using the Device_create function
LED drivers can use the following two ways to control LEDs:
(1) control led via string
(2) control led via I/o command
A complete Linux driver consists of two parts: internal processing and hardware interaction. The internal processing mainly refers to the Linux driver loading, unloading, and device file-related action processing (read and write device files, send I/O commands to the device file), as well as business logic. The interaction with hardware mainly refers to the data interaction with the hardware register through IOWRITE32,IOREAD32 and other functions. The porting of Linux drivers on different platforms is also handled in these two parts. Porting between different Linux kernel versions is primarily the first part of porting, which is the internal processing of Linux drivers.
7th Chapter LED will blink for me: Control the Light emitting diode