open 返回 inappropriate ioctl for device_设备树(二):device_node与device绑定

本文介绍了Linux内核v5.6中,设备树(device_tree)如何与platform_device绑定。从平台设备和SPI设备两个角度,详细阐述了设备节点的解析、数据结构填充及设备和驱动的匹配过程,展示了设备如何加入统一设备模型。
摘要由CSDN通过智能技术生成

28b7900f13c1f694ba2a224162001160.png

内核版本

  • linux-v5.6

参考资料

  • Documentation/devicetree/usage-model.txt

在“设备树(一):kernel解析dtb文件”中,已经知道dtb文件中的节点与属性信息会被解析填充到kernel的device_node和property结构体中;在start_kernel的后续初始化过程中,device_node还会进一步和各种device进行绑定,有虚拟的platform bus下的platform_device,也有spi、i2c等物理bus下的从设备(client)。

spi、i2c的控制器(master)作为platform_device设备与device_node进行绑定

一、platform_device

在设备树的usage-model.txt文档中有如下描述:

The trick is that the kernel starts at the root of the tree and looks for nodes that have a 'compatible' property.
For each of these nodes, Linux allocates and registers a platform_device, which in turn may get bound to a platform_driver.

也就是说,kernel会为设备树root节点下所有带'compatible' 属性的节点都分配并注册一个platform_device;另外,如果某节点的'compatible' 符合某些matches条件,则会为该节点下所有带'compatible' 属性的子节点(child)也分配并注册一个platform_device。

1.1 数据结构

struct platform_device {
    
        const char      *name;
        int             id;
        bool            id_auto;
        /* 以此挂入统一设备模型 */
        struct device   dev;
        u64             platform_dma_mask;
        /* io和irq资源的总数 */
        u32             num_resources;
        /* 指向resource数组 */
        struct resource *resource;

        const struct platform_device_id *id_entry;
};

1.2 创建与填充过程

在of_platform_default_populate_init()函数中会对platform_device进行填充,路径如下:

start_kernel
--> arch_call_rest_init
    --> rest_init
        --> kernel_init
            --> kernel_init_freeable
                --> do_basic_setup
                    --> do_initcalls
                        --> of_platform_default_populate_init

函数实现如下:

/* drivers/of/platform.c */
static int __init of_platform_default_populate_init(void)
{
    
        /* 检查of_root("/"节点)是否为NULL */
        if (!of_have_populated_dt())
                return -ENODEV;

        /* 进行实际的platform_device填充操作 */
        of_platform_default_populate(NULL, NULL, NULL);

        return 0;
}
/* 在do_initcalls会被调用执行 */
arch_initcall_sync(of_platform_default_po
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值