linux 驱动-匹配1 (platform_bus_type)

目录

匹配入口

匹配顺序(platform_match )

方式1:

方式2(重点)

方式3

方式4 (重点)


匹配入口

driver_match_device 实际调用platform_match

driver_match_device(drv, dev);

static inline int driver_match_device(struct device_driver *drv,
				      struct device *dev)
{
	return drv->bus->match ? drv->bus->match(dev, drv) : 1;
}

匹配顺序(platform_match )

static struct platform_driver bcm2835_rng_driver = {
    .driver = {
        .name = "bcm2835-rng",              方式1 /方式5
        .of_match_table = bcm2835_rng_of_match, 方式2 /方式3()
    },
    .probe        = bcm2835_rng_probe,
    .id_table    = bcm2835_rng_devtype,  方式4
};

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)    	//方式1: 根据device_driver 的name
		return !strcmp(pdev->driver_override, drv->name);

	/* Attempt an OF style match first */
	if (of_driver_match_device(dev, drv))  //方式2: 根据device_driver的of_match_table
		return 1;                              去匹配device_node的compatibale/type/name

	/* Then try ACPI style match */
	if (acpi_driver_match_device(dev, drv))//方式3: 根据 device_driver的drv->acpi_match_table, drv->of_match_table
		return 1;

	/* Then try to match against the id table */
	if (pdrv->id_table)			 //方式4:根据platform_driver驱动的id_table(id->name 与pdev->name)
		return platform_match_id(pdrv->id_table, pdev) != NULL;

	/* fall-back to driver name match */
	return (strcmp(pdev->name, drv->name) == 0);
						//方式5: 根据device_driver的name
}

方式1:

        说明:driver_override 主要用于调试驱动,强制指定一个驱动来绑定到这个设备
        操作: 用户空间通过特定的接口(如 sysfs)来设置这个值
        实例: echo "my_driver" > /sys/bus/platform/devices/my_device/driver_override

方式2(重点)

  根据of_device_id 的 compatible, type, name顺序去匹配device_node的compatible, type, name

方式3

        acpi 方式,暂略

方式4 (重点)

        static struct platform_device_id bcm2835_rng_devtype[] = {
                { .name = "bcm2835-rng" },
                { .name = "bcm63xx-rng" },
                { /* sentinel */ }
        };

struct platform_device_id {
        char name[PLATFORM_NAME_SIZE];
        kernel_ulong_t driver_data;
};
static const struct platform_device_id *platform_match_id(
const struct platform_device_id *id,  struct platform_device *pdev)
{
        while (id->name[0]) {
                if (strcmp(pdev->name, id->name) == 0) {
                        pdev->id_entry = id; 填充platform_device 的id_entry
                        return id;
                }
                id++;
        }
        return NULL;
}

方式5:

         strcmp(pdev->name, drv->name) == 0

        

相关推荐

  1. linux 驱动-1 (platform_bus_type)

    2024-04-23 15:16:05       39 阅读
  2. Linux驱动_1_hello驱动

    2024-04-23 15:16:05       29 阅读
  3. Linux学习笔记9-Linux驱动1

    2024-04-23 15:16:05       62 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-23 15:16:05       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-23 15:16:05       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-23 15:16:05       87 阅读
  4. Python语言-面向对象

    2024-04-23 15:16:05       96 阅读

热门阅读

  1. 【根据消息类型实现订阅发布模型】

    2024-04-23 15:16:05       36 阅读
  2. vue中动态引入图片地址需要用require

    2024-04-23 15:16:05       31 阅读
  3. layui数据表格横向滚动条不显示问题

    2024-04-23 15:16:05       27 阅读
  4. cmake命令使用总结

    2024-04-23 15:16:05       28 阅读
  5. 大数据分析:使用Spark和Hadoop的实用指南

    2024-04-23 15:16:05       32 阅读
  6. R语言 数据的整理与清洗(第一篇)

    2024-04-23 15:16:05       35 阅读
  7. 信号量Semaphore

    2024-04-23 15:16:05       28 阅读
  8. 4.2 Python列表(list)

    2024-04-23 15:16:05       38 阅读
  9. OSPF的七种LSA类型

    2024-04-23 15:16:05       34 阅读
  10. 美国公司注册及美国MSB牌照申请流程

    2024-04-23 15:16:05       33 阅读
  11. MyBatis `<foreach>`

    2024-04-23 15:16:05       40 阅读