【u-boot】u-boot驱动模型-struct uclass_driver
本文基于u-boot版本v2017.11
一、struct uclass_driver简介
一个struct uclass_driver为一组相关的驱动提供统一的接口,struct uclass_driver实现如下:
struct uclass_driver {/* uclass 驱动的名称 */const char *name;/* 此 uclass 的 ID 号 */enum uclass_id id;/* 当一个新设备绑定到该uclass之后调用 */int (*post_bind)(struct udevice *dev);/* 当一个设备从该 uclass 解绑之前调用 */int (*pre_unbind)(struct udevice *dev);/* 当一个新设备探测(probe)之前调用 */int (*pre_probe)(struct udevice *dev);/* 当一个新设备探测(probe)之后调用 */int (*post_probe)(struct udevice *dev);/* 当一个设备被移除之前调用 */int (*pre_remove)(struct udevice *dev);/* 当一个子设备绑定到该 uclass 中的设备之后调用 */int (*child_post_bind)(struct udevice *dev);int (*child_pre_probe)(struct udevice *dev);/* 用于初始化该 uclass */int (*init)(struct uclass *class);/* 用于销毁该 uclass */int (*destroy)(struct uclass *class);/** 若非零,则表示应为uclass的->priv指针自动分配的私有数据区大小。* 若为零,则表示该uclass驱动需自行分配所需数据。*/int priv_auto_alloc_size;/** 每个设备都可以持有一份由uclass拥有的私有数据。* 若该值非零,则系统会自动为每个设备分配这块内存。*/int per_device_auto_alloc_size;/** 每个设备都可以持有一份由uclass拥有的平台数据,* 存放在dev->uclass_platdata中。* 若该值非零,则系统会自动分配该数据区。*/int per_device_platdata_auto_alloc_size;/** 每个子设备(即属于该uclass中父设备的子设备)* 都可以持有一份与父设备/uclass相关的父级数据。* 若驱动中此成员为 0,则使用此字段作为后备分配大小。*/int per_child_auto_alloc_size;/** 类似于总线(bus)希望为其子设备保存信息。* 若该值非零,则为每个子设备自动分配对应的数据区,* 存放在子设备的parent_platdata指针中。* 若驱动中此成员为0,则使用此字段作为后备值。*/int per_child_platdata_auto_alloc_size;/* uclass的操作集,为该类中的设备提供统一的接口。*/const 