Creating LED-driven device files
1th Step: Initialize the Cdev with the Cdev_init function
2nd step: Specify the device number. Assign directly in code or dynamically
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
Uninstalling LED-driven device files
You need to call the Device_destroy, Class_destroy, and Unregister_chrdev_region methods in turn
void Device_destroy (struct class *class, dev_t devt)
void Class_destroy (struct class *cls)
void Unregister_chrdev_region (dev_t from, unsigned count)
Control LED
LED drivers can control LEDs in two different ways:
1. Control the LEDs via a string.
2. Control the LEDs with the I/O command.
To control LEDs, use both of these methods. The LED driver must receive the corresponding data. If the LED is controlled by a string. You need to use the File_operations.write function. If the LEDs are controlled through the I/O command, you need to use the FILE_OPERATIONS.IOCTL function.
Porting Linux drivers is a very important one. is to modify the Linux driver source code, you should try not to modify the Linux driver interface.
This chapter focuses on LED drivers, a Linux driver that really deals with hardware. Although the LED driver is not complicated, it only controls a few LEDs, but the LED driver already includes all the necessary parts of the Linux drive. 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 porting of Linux drivers on different platforms is also handled in these two parts.
Andriod Deep Exploration of-hal and Driver Development Chapter Seventh reading notes