Linux platform子系统【2】-PLATFORM注册(struct device)platform_bus


前言

<<Linux platform子系统【1】-PLATFORM(平台)总线详解>>
中分析了注册struct bus_type platform_bus_type 的过程,但是在int __init platform_bus_init(void)中还提前注册了一个(struct device)platform_bus

  1. 为什么要提前注册一个 虚拟的设备?
  2. 设备注册到platform_bus的具体过程是什么呢?
  3. 从设备树解析到注册设备具体的过程
    Linux I2C子系统【1】-I2C_adapter和I2C_client

一、为什么要提前注册一个 虚拟的设备(struct device)platform_bus?

coding
	struct device {
		struct device		*parent;
		struct device_private	*p;
	};
struct device platform_bus = {
	.init_name	= "platforms",
};
int __init platform_bus_init(void)
{
	int error;
	early_platform_cleanup();
	error = device_register(&platform_bus);
	error =  bus_register(&platform_bus_type);
	return error;
}

首先来理解一下device_register:
linux设备模型六(device细节)

  1. 从上可知系统上电初始化设备集合
    在这里插入图片描述
    /* /sys/devices/ */
    int __init devices_init(void){
    	struct kset *devices_kset = devices_kset = kset_create_and_add("devices", &device_uevent_ops, NULL);
    	printk(KERN_INFO "devices_kset=%s\n\n",devices_kset->kobj.name)(devices_kset=devices)
    }
    int device_register(struct device *dev)/*device_register(&platform_bus)*/
    {
    	device_initialize(dev);        /* 初始化通用数据结构 */
    	return device_add(dev);        /* 加入到该dev所属bus上 */
    }
    
    
    1. 因为platform本身属于一个虚拟bus,那么设备struct device platform_bus放在哪个总线上?
      /* 画重点了!!!---------给设备探测相应的驱动开始寻找设备所对应的驱动------------ 去bus上找dev对应的drv,主要执行__device_attach,主要进行match,sys_add,执行probe函数和绑定等操作 */
      到最后发现,struct device platform_bus没有相对应的bus,只是在文件系统下面显示/sys/devices/platform,之后为后面实际的设备,提供分组的父设备
      void bus_probe_device(struct device *dev)
      {
      	struct bus_type *bus = dev->bus;
      	struct subsys_interface *sif;
       
      	if (!bus)            /* device要查找自己bus上的driver,所以bus必须存在 */
      		return;
      }
      
      1. 总体经历
-->device_register(platform_bus)
-->device_initialize(platform_bus);
	{
		dev->kobj.kset = devices_kset;
	}
-->device_add(platform_bus);
-->device_private_init(dev);
	{
		dev->p = kzalloc(sizeof(struct device_private), GFP_KERNEL);
	}
-->bus_add_device(platform_bus);/* 添加设备的总线属性 将设备加入到管理它的bus总线的设备连表上
-->bus_probe_device(dev);       /* 画重点了!!!!!!!!!!!!---------给设备探测相应的驱动开始寻找设备所对应的驱动------------  去bus上找dev对应的drv,主要执行__device_attach,主要进行match,sys_add,执行probe函数和绑定等操作 */
	

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值