我已经编写了一个平台驱动程序(虚拟驱动程序),并且想知道如何使用设备树或“在哪里添加我的设备节点?”在设备树中,以便我的驱动程序在启动时自动加载并自动调用 prob() 。并且,
我不知道设备树在哪个目录中找到要绑定(bind)的特定驱动程序?
谢谢期待!!
最佳答案
为此,您需要使用包含:
#include <linux/of.h>
#include <linux/of_device.h>
在您的设备声明中(请注意,我使用 <you thing here>
来更改您的设备名称):
#ifdef CONFIG_OF
static const struct of_device_id <your_device_name_here>_dt_match_table[] = {
{ .compatible = "<your compatible string here>" },
{ },
};
MODULE_DEVICE_TABLE(of, <your_device_name_here>_dt_match_table);
#endif
static struct platform_driver <your_device_name_here>_driver = {
.probe = <your_device_name_here>_probe,
.remove = <your_device_name_here>_remove,
.driver = {
.name = "<your_device_name_here>",
.of_match_table = of_match_ptr(clap_sensor_dt_match_table),
},
};
module_platform_driver(<your_device_name_here>_driver);
在您的驱动程序中使用此内容,您可以在设备树中编写以下内容:
<your_device_name_here> {
compatible = "<your compatible string here>";
pinctrl-names = "default";
pinctrl-0 = <&your_pins_pinctrl>;
label = "trigger";
trigger-gpios = <&gpio 23 GPIO_ACTIVE_LOW>;
};
设备树文件和您的设备驱动程序文件上的 Compatible 属性必须相同,这样内核才能将设备树中其节点的信息与您的驱动程序进行匹配。
记住设备树仅用于描述硬件,不要用它来存储软件变量或其他软件内容。
我建议你学习一些有关设备树pinctrl和gpio的知识。 Raspberry Foundation 有一些用于设备树覆盖的 Material : https://www.raspberrypi.org/documentation/configuration/device-tree.md
关于c - 设备树在Linux(树莓派)启动时绑定(bind)所需的设备驱动程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50790670/