Device driver development manual simplified version

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

  1. Create cdev

** 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……

Linux Driver Development for Embedded Processors – Second Edition 版本: Learn to develop Linux embedded drivers with kernel 4.9 LTS The flexibility of Linux embedded, the availability of powerful, energy efficient processors designed for embedded computing and the low cost of new processors are encouraging many industrial companies to come up with new developments based on embedded processors. Current engineers have in their hands powerful tools for developing applications previously unimagined, but they need to understand the countless features that Linux offers today. This book will teach you how to develop device drivers for Device Tree Linux embedded systems. You will learn how to write different types of Linux drivers, as well as the appropriate APIs (Application Program Interfaces) and methods to interface with kernel and user spaces. This is a book is meant to be practical, but also provides an important theoretical base. More than twenty drivers are written and ported to three different processors. You can choose between NXP i.MX7D, Microchip SAMA5D2 and Broadcom BCM2837 processors to develop and test the drivers, whose implementation is described in detail in the practical lab sections of the book. Before you start reading, I encourage you to acquire any of these processor boards whenever you have access to some GPIOs, and at least one SPI and I2C controllers. One of the boards used to implement the drivers is the famous Raspberry PI 3 Model B board. You will learn how to develop drivers, from the simplest ones that do not interact with any external hardware, to drivers that manage different kind of devices: accelerometers, DACs, ADCs, RGB LEDs, Multi-Display LED controllers, I/O expanders, and Buttons. You will also develop DMA drivers, drivers that manage interrupts, and drivers that write/read on the internal registers of the processor to control external devices. To easy the development of some of these drivers, you will use different types of Frameworks: Miscellaneous framework, LED framework, UIO framework, Input framework and the IIO industrial one. This second edition has been updated to the v4.9 LTS kernel.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值