Device driver development manual simplified version, manualsimplified

Source: Internet
Author: User

Device driver development manual simplified version, manualsimplified
Device driver development manual simplified version

Author: Eliot shao
Blog URL: blog.csdn.net/eliot_shao
Date: 2015.03.26
Description: linux device driver model is regular, Stand in the angle of the device driver users, just makes nodes in/dev (udev) or/sys (sysfs ). so just operate file system to build a bridge from user space file nodes to kernel data structures and device driver functions. each device has a device number, each device number connects to a device operations (file operations ).

Unused device driver framework

** Malloc master and slave device number
Int alloc_chrdev_region (dev_t * dev, unsigned baseminor, unsigned count,
Const char * name)
Initialize a cdev structure
Void cdev_init (struct cdev * cdev, const struct file_operations * fops)
NOTE: Fill file_operations!
Add a char device to the system
Int cdev_add (struct cdev * p, dev_t dev, unsigned count)
Now cdev has been create and add to system, but there is NO file node under the/dev connected device number. There are two ways to do:
1, Created under the/dev directory statically .~ #: Sudo mknod/dev/xxx c 234 0;
2. Kernel sysfs support, which is an important part of the Linux device model .**

2. Sysfs operations

** Create device type directory xxx on/sys/class, create a struct class structure
Struct class * class_create (struct module * owner, const char * name)
Creates a class device and registers it with sysfs, Send uevents to udev, so it'll create/dev nodes
Struct class_device * class_device_create (struct class * cls,
Struct class_device * parent,
Dev_t devt,
Struct device * device,
Const char * fmt ,...)
Create sysfs attribute file for device
Int device_create_file (struct device * dev, struct device_attribute * attr )**

Use device driver framework

If you use device driver framework, It's easier!
Input devices, for example:
1, Allocate an input device data structure
Input_allocate_device ();
2, Register with the input subsystem
Input_register_device (xxx_input_dev );
That is!

Stay tuned for more share ......

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.