如何正确探测平台设备?

问题描述 投票:0回答:1

我正在尝试创建一个平台驱动程序,我有以下代码

模块

// SPDX-License-Identifier: GPL-2.0

#include <linux/module.h>
#include <linux/init.h>
#include <linux/pm.h>
#include <linux/of_device.h>
#include <linux/fb.h>

static int simple_probe(struct platform_device *pdev)
{
    printk(KERN_ERR "SIMPLE: %s\n", "Probing");
    return 0;
}

const struct of_device_id simple_of_match[] = {
    {
        .compatible = "example,simple",
    },
    { /*End of List*/ },
};

struct platform_driver simple_driver = { 
    .probe = simple_probe,
    .driver = { 
        .name = "simple",
        .owner = THIS_MODULE,
        .of_match_table = simple_of_match 
    }
};

static int __init init(void)
{
    if (platform_driver_register(&simple_driver)) {
        printk(KERN_ERR "SIMPLE: %s\n", "Registerered");
    } else {
        printk(KERN_ERR "SIMPLE: %s\n", "Failed");
    }
    return 0;
}

static void __exit deinit(void)
{
    platform_driver_unregister(&simple_driver);
}

module_init(init);
module_exit(deinit);

MODULE_DESCRIPTION("Simple Platform driver");
MODULE_AUTHOR("Bret Joseph Antonio <[email protected]>");
MODULE_LICENSE("GPL");

我的设备树似乎没有运行覆盖,因此设备状态正常。它仍然没有运行探测回调。

设备树

/dts-v1/;

/ {
    simple@0 {
        compatible = "example,simple";
        pinctrl-names = "lcm_rst_out1_gpio", "lcm_rst_out0_gpio";
        pinctrl-0 = <&PHANDLE1>;
        pinctrl-1 = <&PHANDLE2>;
        status = "okay";
    };
};

我希望内核注册我的驱动程序,然后运行探测函数,但是代码

    if (platform_driver_register(&simple_driver) == 0) {
        printk(KERN_ERR "SIMPLE: %s\n", "Registered");
    } else {
        printk(KERN_ERR "SIMPLE: %s\n", "Failed");
    }

返回

[    0.178889] SIMPLE: Registered
,但探测功能保持沉默。探针功能取决于什么? 难道它不应该在设备树中找到节点后立即运行探测吗?

c linux-kernel linux-device-driver kernel-module
1个回答
0
投票

您需要使用

struct of_device_id simple_of_match[]
语句将您的 MODULE_DEVICE_TABLE(of, simple_of_match); 公开/导出到
of
(开放固件)子系统。


内核代码的约定是尽可能将所有符号声明为static。您的代码在这方面不一致,即

struct of_device_id simple_of_match[]
struct platform_driver simple_driver
是全局的。

© www.soinside.com 2019 - 2024. All rights reserved.