Platform 平台设备驱动框架
platform平台设备驱动是基于设备驱动模型的,它将总线结构体struct bus_type封装为struct bus_type platform_bus_type,将驱动结构体struct device_driver封装为struct platform_driver,将设备结构体struct device封装为struct platform_device。
平台总线结构体 platform_bus_type
struct bus_type platform_bus_type = {.name= "platform",.dev_groups= platform_dev_groups,//platform_match - bind platform device to platform driver..match= platform_match,.uevent= platform_uevent,.pm= &platform_dev_pm_ops,};
平台设备结构体 platform_device
### 如果内核不支持设备树,就需要编写此结构体,然后使用platform_device_register()将设备加载到内核中;### 如果内核支持设备树,只需要在设备树中编写此设备节点,内核会自动将其加载到内核中。struct platform_device {const char*name;intid;boolid_auto;struct devicedev;u32num_resources;struct resource*resource;const struct platform_device_id*id_entry;char *driver_override; /* Driver name to force a match *//* MFD cell pointer */struct mfd_cell *mfd_cell;/* arch specific additions */struct pdev_archdataarchdata;};### 注册与卸载平台设备函数platform_device_register() //注册platform设备platform_device_unregister() //卸载platform设备
平台驱动结构体 platform_driver
struct platform_driver {int (*probe)(struct platform_device *);int (*remove)(struct platform_device *);void (*shutdown)(struct platform_device *);int (*suspend)(struct platform_device *, pm_message_t state);int (*resume)(struct platform_device *);struct device_driver driver;const struct platform_device_id *id_table;bool prevent_deferred_probe;};### 注册与卸载平台驱动函数platform_driver_register() //注册platform驱动platform_driver_unregister() //卸载platform驱动
设备与驱动匹配
平台总线的platform_match()函数匹配成功以后,就会执行platform_driver平台驱动内的probe()函数。platform_match()函数匹配方式:方式1:platform_device.driver_override与platform_driver.device_driver.name作比较方式2:platform_driver.driver.of_match_table内的compatible属性与设备of_device_id的compatible属性作对比方式3:platform_driver.id_table与设备的i2c_device_id作比较方式4:platform_device.name与platform_driver.device_driver.name作比较