Creating LED -driven device files
Step 1 : Initialize the cdev with the cdev_init function
Step 2 : Specify the device number. Assign directly in code or dynamically
Step 3 : Use the cdev_add function to add a character device to a character device array in the kernel
Step 4 : 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 Device_destroy,Class_destroy , and unregister_chrdev_region in turn Method
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 LEDsvia 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 LEDis 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.
My blog address: http://home.cnblogs.com/u/jie617530/
Andriod Deep Exploration of-hal and Driver development Seventh Chapter reading notes and a little experience