平台设备从何处获取名称 [英] From where platform device gets it name

查看:187
本文介绍了平台设备从何处获取名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读围绕总线,设备和驱动程序构建的Linux设备模型 我能够对设备和驱动程序的匹配方式有所了解,但在这里不清楚总线的作用以及总线与设备的匹配方式.

I am reading about the Linux Device model which is built around buses,devices and drivers .I am able to understand a bit about how devices and driver matches happen but not clear about the role of buses here,how buses matches with device.

我对平台设备从何处获取其名称还有一个疑问.

One more doubt I have regarding where platform device gets it name from.

平台总线仅将每个设备的名称与每个驱动程序的名称进行比较;如果它们相同,则该设备与驱动程序匹配."

"The platform bus,simply compares the name of each device against the name of each driver; if they are the same, the device matches the driver."

现在我还不太明白这一点.我相信设备名称首先在dts文件中定义,然后在平台驱动程序代码中定义了相应的驱动程序名称.

Now I could n't really understand above point .I believe device name is first defined in dts file and then corresponding Driver name is defined in platform driver code .

如果这两个名称匹配,则从驱动程序代码中调用探针,这将确认设备确实存在.

if these two name matches ,probe is called from driver code which will confirm device is really in existence.

有人可以从Bus的角度让我特别了解整个过程.

Could anybody let me know the whole process specially from Bus point of view.

推荐答案

要添加到@Federico的答案中,该答案很好地描述了一般情况,可以将平台设备平台驱动程序进行匹配使用四个优先事项.这是平台总线"的匹配功能:

To add to @Federico's answer, which describes very well the general case, platform devices can be matched to platform drivers using four things (that are prioritized). Here is the match function of the platform "bus":

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);

        /* 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);
}

有两个重要的问题.

使用设备树(of_driver_match_device)进行匹配.如果您还不了解设备树的概念,请继续阅读.在此数据结构中,每个设备在代表系统的树中都有其自己的节点.每个设备还具有compatible属性,该属性是字符串列表.如果任何平台驱动程序声明支持compatible字符串之一,则将存在匹配项,并且将调用驱动程序的探测.

Match using the device tree (of_driver_match_device). If you don't know the device tree concept yet, go read about it. In this data structure, each device has its own node within a tree representing the system. Each device also has a compatible property which is a list of strings. If any platform driver declares one of the compatible strings as being supported, there will be a match and the driver's probe will be called.

这是一个节点示例:

gpio0: gpio@44e07000 {
    compatible = "ti,omap4-gpio";
    ti,hwmods = "gpio1";
    gpio-controller;
    #gpio-cells = <2>;
    interrupt-controller;
    #interrupt-cells = <1>;
    reg = <0x44e07000 0x1000>;
    interrupts = <96>;
};

这描述了GPIO控制器.它只有一个兼容的字符串ti,omap4-gpio.任何声明此兼容字符串的已注册平台驱动程序都将被探测.这是其驱动程序:

This describes a GPIO controller. It only has one compatible string which is ti,omap4-gpio. Any registered platform driver declaring this same compatible string will be probed. Here's its driver:

static const struct of_device_id omap_gpio_match[] = {
    {
        .compatible = "ti,omap4-gpio",
        .data = &omap4_pdata,
    },
    {
        .compatible = "ti,omap3-gpio",
        .data = &omap3_pdata,
    },
    {
        .compatible = "ti,omap2-gpio",
        .data = &omap2_pdata,
    },
    { },
};
MODULE_DEVICE_TABLE(of, omap_gpio_match);

static struct platform_driver omap_gpio_driver = {
    .probe      = omap_gpio_probe,
    .driver     = {
        .name   = "omap_gpio",
        .pm = &gpio_pm_ops,
        .of_match_table = of_match_ptr(omap_gpio_match),
    },
};

驱动程序能够驱动三种类型的GPIO,包括前面提到的一种.

The driver is able to drive three types of GPIOs, including the one mentioned before.

请注意,平台设备并不是神奇地添加到平台总线中的.在这种情况下,借助OF函数扫描树,架构/板初始化将调用platform_device_addplatform_add_devices.

Please note that platform devices are not magically added to the platform bus. The architecture/board initialization will call platform_device_add or platform_add_devices, in this case with the help of OF functions to scan the tree.

如果您查看platform_match,您将看到匹配项归结为名称匹配项.在驱动程序名称和设备名称之间进行简单的字符串比较.这就是较旧的平台驱动程序的工作方式.其中有些仍然可以使用,例如这里的:

If you look at platform_match, you will see that the match falls back to name matching. A simple string comparison is done between the driver name and the device name. This is how older platform driver worked. Some of them still do, like this one here:

static struct platform_driver imx_ssi_driver = {
    .probe = imx_ssi_probe,
    .remove = imx_ssi_remove,

    .driver = {
        .name = "imx-ssi",
        .owner = THIS_MODULE,
    },
};

module_platform_driver(imx_ssi_driver);

同样,主板特定的初始化将必须调用platform_device_addplatform_add_devices来添加平台设备,在名称匹配设备的情况下,这些设备完全是在C中静态创建的(名称以C给出,IRQ和基本地址等).

Again, the board specific initialization will have to call platform_device_add or platform_add_devices to add platform devices, which in the case of name matching ones are entirely created statically in C (name is given in C, resources like IRQs and base addresses, etc.).

这篇关于平台设备从何处获取名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆