平台设备从哪里得到它的名字 [英] From where platform device gets it name

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

问题描述

我正在阅读围绕总线、设备和驱动程序构建的 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 .

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

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

谁能让我特别从巴士的角度告诉我整个过程.

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

推荐答案

要添加到@Federico 的答案中,该答案很好地描述了一般情况,平台设备 可以与平台驱动程序匹配 使用四件事(优先级).这里是平台bus"的匹配函数:

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.

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

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天全站免登陆