设备树 — platform_device和platform_driver如何让匹配

4.x的内核都是已经支持设备树的,所以platform bus也是做了一些调整。

  主要是在匹配函数里面的支持设备树。

1

2

3

4

5

6

7

8

struct bus_type platform_bus_type = {

    .name       = "platform",

    .dev_groups = platform_dev_groups,

    .match      = platform_match,

    .uevent     = platform_uevent,

    .dma_configure  = platform_dma_configure,

    .pm     = &platform_dev_pm_ops,

};

  

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

/**

 * 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 */

    /* 针对特殊情况,dev中的driver_override被设置,则只匹配和driver_override名字相同的驱动程序 */

    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 */

    /* 有驱动中有id_table,则dev中的名字和任何一个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_override被设置,优先级最高。
  2. 驱动里的of_match_table,和平台设备的compatible比较。
  3. 高级配置和电源管理之类的匹配。
  4. platform_driver里的id_table里的所有名字和设备名字匹配。
  5. 最后再是设备名字和驱动名字比较。

  当然除了第一个之外,其它的只要没匹配到,后面的几个匹配还会继续执行的。

设备树匹配方式

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值