Linux Platform Device and Driver
来源:互联网 发布:linux ant安装路径 编辑:程序博客网 时间:2024/05/17 07:54
从Linux 2.6 起引入了一套新的驱动管理和注册机制 :Platform_device 和 Platform_driver 。
Linux 中大部分的设备驱动,都可以使用这套机制 , 设备用Platform_device 表示,驱动用Platform_driver 进行注册。
Linux platform driver 机制和传统的 device driver 机制 ( 通过 driver_register 函数进行注册 ) 相比,一个十分明显的优势在于platform 机制将设备本身的资源注册进内核,由内核统一管理,在驱动程序中使用这些资源时通过 platform device 提供的标准接口进行申请并使用。这样提高了驱动和资源管理的独立性,并且拥有较好的可移植性和安全性 ( 这些标准接口是安全的 ) 。
Platform 机制的本身使用并不复杂,由两部分组成: platform_device 和 platfrom_driver 。
通过 Platform 机制开发发底层驱动的大致流程为 : 定义 platform_device -> 注册 platform_device-> 定义 platform_driver-> 注册 platform_driver 。
首先要确认的就是设备的资源信息,例如设备的地址,中断号等。
在 2.6 内核中 platform 设备用结构体 platform_device 来描述,该结构体定义在kernel/include/linux/platform_device.h 中,
struct platform_device {
const char *name;
u32 id;
struct devicedev;
u32num_resources;
struct resource* resource;
};
该结构一个重要的元素是 resource ,该元素存入了最为重要的设备资源信息,定义在kernel/include/linux/ioport.h 中,
struct resource {
const char*name;
unsigned longstart, end;
unsigned longflags;
struct resource*parent, *sibling, *child;
};
定义好了 platform_device 结构体后就可以调用函数 platform_add_devices 向系统中添加该设备了,之后可以调用platform_device_register() 进行设备注册。要注意的是,这里的 platform_device 设备的注册过程必须在相应设备驱动加载之前被调用,即执行 platform_driver_register 之前 , 原因是因为驱动注册时需要匹配内核中所以已注册的设备名。
在驱动初始化函数中调用函数 platform_driver_register()注册platform_driver ,当注册成功时会调用 platform_driver结构元素 probe 函数指针,当进入 probe 函数后,需要获取设备的资源信息 ,常用获取资源的函数主要是:
struct resource *platform_get_resource(struct platform_device *dev, unsigned int type, unsignedint num);
根据参数 type 所指定类型,例如 IORESOURCE_MEM 或IORESOURCE_IRQ等,来获取指定的资源。
- Linux Platform Device and Driver
- Linux Platform Device and Driver
- Linux Platform Device and Driver
- Linux Platform Device and Driver
- Linux Platform Device and Driver
- Linux Platform Device and Driver
- Linux Platform Device and Driver
- Linux Platform Device and Driver
- Linux Platform Device and Driver
- Linux Platform Device and Driver
- Linux Platform Device and Driver
- Linux Platform Device and Driver
- Linux Platform Device and Driver
- Linux Platform Device and Driver
- Linux Platform Device and Driver .
- Linux Platform Device and Driver
- Linux Platform Device and Driver
- Linux Platform Device and Driver
- 算法记录(2010.1.23-1)
- 2010-01-23
- 转:为什么美国的垃圾在中国是奢侈品?
- Linq 与sql方式 添加数据效率比较
- mysql中编码的设置
- Linux Platform Device and Driver
- 人生有三件事不可俭省
- 如何解决系统补丁VS2008 SP1(KB971092)重复安装问题
- 美国互联网公司为何在中国水土不服?
- WinDriver驱动程序框架
- 期待新译作
- 迷路
- 户外迷路指南
- PHP整合FCKeditor