Linux设备模型中:bus_type、device、device_driver 《Linux设备驱动程序》的linux设备模型章中说到设备模型中,所有设备都通过总线相连。 添加设备devA,必须指定其device结构体的bus_type域,初始化其他域,然后调用device_register(&devA),将设备devA 注册到指定总线。 添加该设备驱动driverA,也必须指定其device_driver结构体的bus_type域,初始化其他域,然后调用driver_register(&driverA), 将该驱动注册到总线上。 如果驱动driverA和设备devA匹配成功,即调用probe函数成功,则建立他们之间的符号链接,即将设备与驱动捆绑起来。 而实际我看Linux源代码中却大量使用platform_device, struct platform_device { const char * name; u32 id; struct device dev; u32 num_resources; struct resource * resource; }; 和 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 (*suspend_late)(struct platform_device *, pm_message_t state); int (*resume_early)(struct platform_device *); int (*resume)(struct platform_device *); struct device_driver driver; }; 从结构体可以看出,platform_device是device派生出,platform_driver是device_driver派生出 同样添加设备PlatformDevA,初始化platform_device结构体的dev域时,没有初始化其bus_type域,而实际将该设备添加在sys/bus/platform/devices目录下, 在源代码中哪里可以看到这部分代码。 同样添加驱动PlatformDrvA,初始化platform_driver结构体的driver域时,没有初始化其bus_type域,而实际将该驱动添加在sys/bus/platform/drivers目录下, 在源代码中哪里可以看到这部分代码。 还有 struct miscdevice { int minor; const char *name; const struct file_operations *fops; struct list_head list; struct device *parent; struct device *this_device; }; 与字符型设备 struct cdev { struct kobject kobj; struct module *owner; const struct file_operations *ops; struct list_head list; dev_t dev; unsigned int count; }; 从结构体可以看出,miscdevice是device派生出,它与platform_device区别: 1、platform_device中有设备使用的资源的信息resource。 2、miscdevice中有该设备的使用方法file_operations。 |
|
来自: nt_bookworm > 《驱动》