Linux 平台驱动程序和普通设备驱动程序有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15610570/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 22:33:14  来源:igfitidea点击:

What is the difference between a Linux platform driver and normal device driver?

clinuxlinux-kernellinux-device-driver

提问by kzs

Earlier I had assumed that :

早些时候我假设:

  • Platform driver is for those devices that are on chip.
  • Normal device driver are for those that are interfaced to the processor chip.
  • 平台驱动程序用于那些片上设备。
  • 普通设备驱动程序用于那些与处理器芯片接口的设备驱动程序。

Before coming across one i2c driver... But here, I am reading through multi function i2c driver defined as platform driver. I had gone through https://www.kernel.org/doc/Documentation/driver-model/platform.txt. But still could not get clear idea to come to an conclusion on how to define drivers, like for both onchip as well interfaced devices.

在遇到一个 i2c 驱动程序之前……但在这里,我正在阅读定义为平台驱动程序的多功能 i2c 驱动程序。我已经浏览了https://www.kernel.org/doc/Documentation/driver-model/platform.txt。但是仍然无法清楚地得出关于如何定义驱动程序的结论,例如对于片上设备和接口设备。

Please somebody explain.

请人解释一下。

采纳答案by m-ric

Your references are good but lack a definition of what is a platform device. There is one on LWN. What we can learn from this page:

您的参考资料很好,但缺乏对什么是平台设备的定义。LWN上有一个。我们可以从这个页面学到什么:

  1. Platform devices are inherently not discoverable, i.e. the hardware cannot say "Hey! I'm present!"to the software. Typical examples are i2c devices, kernel/Documentation/i2c/instantiating-devicesstates:

    Unlike PCI or USB devices, I2C devices are not enumerated at the hardware level (at run time). Instead, the software must know (at compile time) which devices are connected on each I2C bus segment. So USB and PCI are notplatform devices.

  2. Platform devices are bound to drivers by matching names,

  3. Platform devices should be registered very earlyduring system boot. Because they are often critical to the rest of the system (platform) and its drivers.
  1. 平台设备本质上是不可发现的,即硬件不能说“嘿!我在场!” 到软件。典型示例是 i2c 设备,kernel/Documentation/i2c/instantiating-devices说明:

    与 PCI 或 USB 设备不同,I2C 设备不在硬件级别(在运行时)枚举。相反,软件必须知道(在编译时)每个 I2C 总线段上连接了哪些设备。所以USB和PCI不是平台设备。

  2. 平台设备通过匹配名称绑定到驱动程序,

  3. 平台设备应在系统引导期间尽早注册。因为它们通常对系统的其余部分(平台)及其驱动程序至关重要。

So basically, the question "is it a platform device or a standard device?" is more a question of which bus it uses. To work with a particular platform device, you have to:

所以基本上,问题“它是平台设备还是标准设备?更多的是它使用哪种总线的问题。要使用特定的平台设备,您必须:

  1. register a platform driverthat will manage this device. It should define a uniquename,
  2. register your platform device, defining the same name as the driver.
  1. 注册将管理此设备的平台驱动程序。它应该定义一个唯一的名称,
  2. 注册您的平台设备,定义与驱动程序相同的名称。

Platform driver is for those devices that are on chip.

平台驱动程序用于那些片上设备。

Not true (in theory, but true in practice). i2c devices are not onChip, but are platform devices because they are not discoverable. Also we can think of onChip devices which are normaldevices. Example: an integrated PCI GPU chip on a modern x86 processor. It is discoverable, thus not a platform device.

不正确(理论上,但在实践中是正确的)。i2c 设备不是片上设备,而是平台设备,因为它们是不可发现的。我们也可以认为是普通设备的 onChip设备。示例:现代 x86 处理器上的集成 PCI GPU 芯片。它是可发现的,因此不是平台设备。

Normal device driver are for those that are interfaced to the processor chip. before coming across one i2c driver.

普通设备驱动程序用于那些与处理器芯片接口的设备驱动程序。在遇到一个 i2c 驱动程序之前。

Not true. Many normaldevices are interfaced to the processor, but not through an i2c bus. Example: a USB mouse.

不对。许多普通设备与处理器接口,但不通过 i2c 总线。示例:USB 鼠标。

[EDIT]In your case, have a look to drivers/usb/host/ohci-pnx4008.c, which is a USB host controller platform device (Here the USB host controller is not discoverable, whereas USB devices, which will connect to it, are). It is a platform device registered by the board file(arch/arm/mach-pnx4008/core.c:pnx4008_init). And within its probe function, it registers its i2c device to the bus with i2c_register_driver. We can infer that the USB Host controller chipset talks tothe CPU through an i2c bus.

[编辑]在你的情况下,看看drivers/usb/host/ohci-pnx4008.c,它是一个 USB 主机控制器平台设备(这里 USB 主机控制器是不可发现的,而将连接到它的 USB 设备是)。它是由板文件( arch/arm/mach-pnx4008/core.c:pnx4008_init)注册的平台设备。在它的探测函数中,它使用i2c_register_driver. 我们可以推断,USB主控制器芯片组会谈,以通过I2C总线的CPU。

Why that architecture? Because on one hand, this device can be considered a bare i2c device providing some functionalities to the system. On the other hand, it is a USB Host capable device. It needs to register to the USB stack (usb_create_hcd). So probing only i2c will be insufficient. Have a look to Documentation/i2c/instantiating-devices.

为什么是那种架构?因为一方面,这个设备可以被认为是一个为系统提供一些功能的裸 i2c 设备。另一方面,它是一个支持 USB 主机的设备。它需要注册到 USB 堆栈 ( usb_create_hcd)。因此,仅探测 i2c 是不够的。去看看Documentation/i2c/instantiating-devices