- > probe()函数加载Linux内核驱动程序时未调用

发布于 2025-02-07 03:44:12 字数 1595 浏览 2 评论 0原文

这是我第一次写Linux内核驱动程序。在网上寻找示例之后,我开始写我的驱动程序。驱动程序正在初始化,但- > prope()函数未撤销。我已将C代码和相关设备树节点代码段的附加附加。

您能提供帮助,让我知道我应该做什么更改?

DTS文件:

ubv@96002000 {
    compatible = "ubv";
    no-map;
    reg = <0 0x96002000 0 0x0002000>;
};

驱动程序C代码:

static int ubv_probe(struct platform_device *pdev)
{
        printk (KERN_ALERT "%s\n", __FUNCTION__);
        pr_info("---------------%s\n", __func__);
        return 0;
}

static int ubv_remove(struct platform_device *pdev)
{
        pr_info("------------------- %s\n", __func__);
        return 0;
}

static struct of_device_id ubv_match_table[] = {
    { .compatible = "ubv" },
    {}
};

static struct platform_device_id ubv_plat_device_ids[] = {
    { .name = "ubv" },
    {}
};

static struct platform_driver ubv_platform_driver = {
        .probe = ubv_probe,
        .remove = ubv_remove,
        .id_table = ubv_plat_device_ids,
        .driver = {
                .name = "ubv",
                .owner = THIS_MODULE,
                .of_match_table = ubv_match_table,
        },
};

static int __init ubv_init(void)
{
    int ret;

    printk (KERN_ALERT "%s\n", __FUNCTION__);

    ret = platform_driver_probe(&ubv_platform_driver, ubv_probe);
    printk (KERN_ALERT "ret = %d\n", ret);
    pr_info("ret = %d\n", ret);

    return ret;
}

static void __exit ubv_exit(void)
{
    platform_driver_unregister(&ubv_platform_driver);
}

module_init(ubv_init);
module_exit(ubv_exit);

This is my first time writing a Linux kernel driver. After looking for examples online, I started to write my driver. The driver is getting initialized but the ->probe() function is not revoked. I have attached below my C code and the relevant device tree node code snippets.

Can you please help and let me know what changes should I make?

DTS file:

ubv@96002000 {
    compatible = "ubv";
    no-map;
    reg = <0 0x96002000 0 0x0002000>;
};

Driver C code:

static int ubv_probe(struct platform_device *pdev)
{
        printk (KERN_ALERT "%s\n", __FUNCTION__);
        pr_info("---------------%s\n", __func__);
        return 0;
}

static int ubv_remove(struct platform_device *pdev)
{
        pr_info("------------------- %s\n", __func__);
        return 0;
}

static struct of_device_id ubv_match_table[] = {
    { .compatible = "ubv" },
    {}
};

static struct platform_device_id ubv_plat_device_ids[] = {
    { .name = "ubv" },
    {}
};

static struct platform_driver ubv_platform_driver = {
        .probe = ubv_probe,
        .remove = ubv_remove,
        .id_table = ubv_plat_device_ids,
        .driver = {
                .name = "ubv",
                .owner = THIS_MODULE,
                .of_match_table = ubv_match_table,
        },
};

static int __init ubv_init(void)
{
    int ret;

    printk (KERN_ALERT "%s\n", __FUNCTION__);

    ret = platform_driver_probe(&ubv_platform_driver, ubv_probe);
    printk (KERN_ALERT "ret = %d\n", ret);
    pr_info("ret = %d\n", ret);

    return ret;
}

static void __exit ubv_exit(void)
{
    platform_driver_unregister(&ubv_platform_driver);
}

module_init(ubv_init);
module_exit(ubv_exit);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文