嵌入式linux 设备树

直入主题,从设备树转换得来的 platform_device 会被注册进内核里,以后当我们每 注册一个 platform_driver 时,它们就会两两确定能否配对,如果能配对成功 就调用 platform_driver 的 probe 函数。
platform_match
 

/**
 * platform_match - bind platform device to platform driver.
 * @dev: device.
 * @drv: driver.
   *
 * Platform device IDs are assumed to be encoded like this:
 * "<name><instance>", where <name> is a short description of the type of
 * device, like "pci" or "floppy", and <instance> is the enumerated
 * instance of the device, like '0' or '42'.  Driver IDs are simply
 * "<name>".  So, extract the <name> from the platform_device structure,
 * and compare it against the name of the driver. Return whether they match
 * or not.
   */
   static int platform_match(struct device *dev, struct device_driver *drv)
   {
   struct platform_device *pdev = to_platform_device(dev);
   struct platform_driver *pdrv = to_platform_driver(drv);

   /* When driver_override is set, only bind to the matching driver */
   if (pdev->driver_override)
   	return !strcmp(pdev->driver_override, drv->name);

   /* Attempt an OF style match first */
   if (of_driver_match_device(dev, drv))
   	return 1;

   /* Then try ACPI style match */
   if (acpi_driver_match_device(dev, drv))
   	return 1;

   /* Then try to match against the id table */
   if (pdrv->id_table)
   	return platform_match_id(pdrv->id_table, pdev) != NULL;

   /* fall-back to driver name match */
   return (strcmp(pdev->name, drv->name) == 0);
   }

1.最先比较:是否强制选择某个 driver

if (pdev->driver_override)
   	return !strcmp(pdev->driver_override, drv->name);

2.然后比较:设备树信息

if (of_driver_match_device(dev, drv))
   	return 1;

3.接下来比较:platform_device_id

if (pdrv->id_table)
   	return platform_match_id(pdrv->id_table, pdev) != NULL;

4.最后比较

xxxxxxxxxx return (strcmp(pdev->name, drv->name) == 0);

没有转换为 platform_device 的节点,如何使用
任意驱动程序里,都可以直接访问设备树。

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

7yewh

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值