platform 设备

platform可看作一种伪总线,通常用于将集成进片上系统的的轻量级设备和Linux设备模型连接在一起。platform由如下部分组成:

  1. platform设备。使用和特定结构的安装程序platform_device_register()或者其简化版本platform_device_register_simple()添加platform设备。你也可以用platform_add_devices()一次添加多个platform设备。定义于include/linux/platform_device.hplatform_device结构体代表了一个platform设备:

struct platform_device {

  const char *name;  /* 设备名称 */

  u32 id;            /* 此域用于注册一个platform设备的多个实例。

                        在本例中,两个USB_UART有不同的ID */

  struct device dev; /* 包括一个release() 方法和一个平台数据 */

  /* ... */

};

  1. platform驱动。platform驱动使用platform_driver_register()将自身注册进平台中。结构体platform_driver亦定义于include/linux/platform_device.h中,代表了platform驱动:

struct platform_driver {

  int (*probe)(struct platform_device *); /*Probe 方法*/

  int (*remove)(struct platform_device *);/*Remove 方法*/

  /* ... */

  /* The name field in the following structure should match

     the name field in the associated platform_device

     structure */

  struct device_driver driver;

};

关于platform设备和platform驱动更详细的文档可参考Documentation/driver-model/platform.txt。为了讨论简单,我们的例子驱动注册了platform设备和platform驱动。

原文地址:https://www.cnblogs.com/cute/p/2045674.html