Device driver development manual simplified version,manualsimplified

來源:互聯網
上載者: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……

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.