第十五节、平台总线模型——probe函数编写
本节用于介绍平台总线模型——probe函数编写
编写probe函数的思路:
1、从device.c里面获得硬件资源
方式一:直接获得
platform驱动文件里面的probe函数传入的是struct platform_devic *变量
1 | int (*probe)(struct platform_device *); |
是一个指向struct platform_devic结构体的指针,也就是platform设备里面定义的struct platform_device
所以我们可以在probe函数里通过pdev直接访问platform_device变量
1 | printk("beep_res is %s\n", pdev->resource[0].name); |
不安全,不推荐此类方法
方法二:使用函数获得
文件位置路径:include/linux/platform_device.h
实际函数位置路径:drivers/base/platform.c
1 | extern struct resource *platform_get_resource(struct platform_device *, unsigned int, unsigned int); |
2、注册杂项/字符设备,完善file_operation结构体,并生成设备节点
3、在注册或者ioremap使用之前要登记(不登记也没有关系,这部分是为了防止资源被同时使用)
登记的目的是告诉内核自己要使用这部分资源,这样当其他驱动或者程序申请使用这部分资源的时候就会失败
同理如果有其他驱动或者程序正在使用这部分资源的时候,这里登记就会失败
文件位置路径:include/linux/ioport.h
1 |
|
4、释放登记函数
1 |
|