【问题标题】:Device tree binds the desired device driver at boot time in Linux (raspberry pi)设备树在 Linux (raspberry pi) 启动时绑定所需的设备驱动程序
【发布时间】:2018-11-20 06:53:45
【问题描述】:

我已经编写了一个平台驱动程序(虚拟驱动程序)并且想知道如何使用设备树或“在哪里添加我的设备节点?”在设备树中,以便我的驱动程序在启动时自动加载并自动调用 prob()。并且,
我不知道设备树在哪个目录中找到要绑定的特定驱动程序?
谢谢期待!!

【问题讨论】:

    标签: c linux kernel driver


    【解决方案1】:

    为此,您需要使用包含:

    #include <linux/of.h>       
    #include <linux/of_device.h>
    

    在您的设备声明中(请注意,我使用 &lt;you thing here&gt; 来更改您的设备名称):

    #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>;
    };
    

    设备树文件和你的设备驱动文件上的兼容属性必须一致,这样内核才能将设备树中其节点的信息与你的驱动匹配。

    并且记住设备树仅用于描述硬件,不要将其用于存储软件变量或其他软件内容。

    我建议你学习一些关于设备树 pinctrl 和 gpio 的知识。树莓基金会有一些设备树覆盖的材料: https://www.raspberrypi.org/documentation/configuration/device-tree.md

    【讨论】:

      猜你喜欢
      • 2018-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-13
      相关资源
      最近更新 更多