【平台设备驱动】中module_platform_driver的定义和使用
2017-02-08 17:21
866 查看
该函数实际是一个宏,它在include/linux/platform_device.h中定义如下:
[cpp] view
plain copy
/* module_platform_driver() - Helper macro for drivers that don't do
* anything special in module init/exit. This eliminates a lot of
* boilerplate. Each module may only use this macro once, and
* calling it replaces module_init() and module_exit()
*/
#define module_platform_driver(__platform_driver) \
module_driver(__platform_driver, platform_driver_register, \
platform_driver_unregister)
其中的module_driver在/include/linux/device.h中定义,如下:
[cpp] view
plain copy
/**
* module_driver() - Helper macro for drivers that don't do anything
* special in module init/exit. This eliminates a lot of boilerplate.
* Each module may only use this macro once, and calling it replaces
* module_init() and module_exit().
*
* @__driver: driver name
* @__register: register function for this driver type
* @__unregister: unregister function for this driver type
* @...: Additional arguments to be passed to __register and __unregister.
*
* Use this macro to construct bus specific macros for registering
* drivers, and do not use it on its own.
*/
#define module_driver(__driver, __register, __unregister, ...) \
static int __init __driver##_init(void) \
{ \
return __register(&(__driver) , ##__VA_ARGS__); \
} \
module_init(__driver##_init); \
static void __exit __driver##_exit(void) \
{ \
__unregister(&(__driver) , ##__VA_ARGS__); \
} \
module_exit(__driver##_exit);
module_platform_driver(xxx);
最终展开后就是如下形式:
static int __init xxx_init(void)
{
return platform_driver_register(&xxx);
}
module_init(xxx_init);
static void __exit
xxx_init(void)
{
return platform_driver_unregister(&xxx);
}
module_exit(xxx_exit);
由上述定义可知,module_platform_driver()宏的作用就是定义指定名称的平台设备驱动注册函数和平台设备驱动注销函数,并且在函数体内分别通过platform_driver_register()函数和platform_driver_unregister()函数注册和注销该平台设备驱动。
参考文献:
1.Linux设备驱动工程师之路——platform类型按键驱动
2.Linux内核编程接口函数(alloc_chrdev_region/register_chrdev_region(字符设备)、class_create/device_create/device_create_file(设备节点)、module_platform_driver/container_of)
3.LINUX设备驱动之platform总线
4.platform设备驱动精讲,例程详细
相关文章推荐
- platform_driver平台设备驱动模型
- linux平台设备驱动架构详解 Linux Platform Device and Driver——神文,非常详细
- platform_device(平台设备)和platform_driver(平台驱动)及平台设备驱动工作原理
- 平台设备与平台驱动注册过程platform_driver_register与platform_device_register
- platform_device(平台设备)和platform_driver(平台驱动)及平台设备驱动工作原理
- linux平台设备驱动架构详解 Linux Platform Device and Driver
- platform_device(平台设备)和platform_driver(平台驱动)及平台设备驱动工作原理
- linux平台设备驱动架构详解 Linux Platform Device and Driver
- linux平台设备驱动架构详解 Linux Platform Device and Driver
- platform_device 和 platform_driver(平台设备和平台驱动)
- platform_driver平台驱动注册和注销过程
- 设备模型、设备与驱动关联的全过程分析 platform_device platform_driver driver bus关系
- (转)platform_driver_register,什么时候调用PROBE函数 注册后如何找到驱动匹配的设备
- platform平台设备驱动
- Linux平台设备驱动 platform_device
- 设备驱动模型第2节:platform_driver_register
- Android平台上PMEM的使用及Platform设备注册(一)
- 设备模型、设备与驱动关联的全过程分析 platform_device platform_driver driver bus关系
- platform_driver_register(struct platform_driver *drv)注册后如何找到驱动匹配的设备
- platform平台设备驱动简化示例代码