uboot driver

u-boot.2021.1/include/dm/device.h
207 * struct driver - A driver for a feature or peripheral
208 *
209 * This holds methods for setting up a new device, and also removing it.
210 * The device needs information to set itself up - this is provided either
211 * by platdata or a device tree node (which we find by looking up
212 * matching compatible strings with of_match).
213 *
214 * Drivers all belong to a uclass, representing a class of devices of the
215 * same type. Common elements of the drivers can be implemented in the uclass,
216 * or the uclass can provide a consistent interface to the drivers within
217 * it.
218 *
219 * @name: Device name
220 * @id: Identifies the uclass we belong to
221 * @of_match: List of compatible strings to match, and any identifying data
222 * for each.
223 * @bind: Called to bind a device to its driver
224 * @probe: Called to probe a device, i.e. activate it
225 * @remove: Called to remove a device, i.e. de-activate it
226 * @unbind: Called to unbind a device from its driver
227 * @ofdata_to_platdata: Called before probe to decode device tree data
228 * @child_post_bind: Called after a new child has been bound
229 * @child_pre_probe: Called before a child device is probed. The device has
230 * memory allocated but it has not yet been probed.
231 * @child_post_remove: Called after a child device is removed. The device
232 * has memory allocated but its device_remove() method has been called.
233 * @priv_auto_alloc_size: If non-zero this is the size of the private data
234 * to be allocated in the device's ->priv pointer. If zero, then the driver
235 * is responsible for allocating any data required.
236 * @platdata_auto_alloc_size: If non-zero this is the size of the
237 * platform data to be allocated in the device's ->platdata pointer.
238 * This is typically only useful for device-tree-aware drivers (those with
239 * an of_match), since drivers which use platdata will have the data
240 * provided in the U_BOOT_DEVICE() instantiation.
241 * @per_child_auto_alloc_size: Each device can hold private data owned by
242 * its parent. If required this will be automatically allocated if this
243 * value is non-zero.
244 * @per_child_platdata_auto_alloc_size: A bus likes to store information about
245 * its children. If non-zero this is the size of this data, to be allocated
246 * in the child's parent_platdata pointer.
247 * @ops: Driver-specific operations. This is typically a list of function
248 * pointers defined by the driver, to implement driver functions required by
249 * the uclass.
250 * @flags: driver flags - see DM_FLAGS_...
251 * @acpi_ops: Advanced Configuration and Power Interface (ACPI) operations,
252 * allowing the device to add things to the ACPI tables passed to Linux
253 */
254struct driver {
255	char *name;
256	enum uclass_id id;
257	const struct udevice_id *of_match;
258	int (*bind)(struct udevice *dev);
259	int (*probe)(struct udevice *dev);
260	int (*remove)(struct udevice *dev);
261	int (*unbind)(struct udevice *dev);
262	int (*ofdata_to_platdata)(struct udevice *dev);
263	int (*child_post_bind)(struct udevice *dev);
264	int (*child_pre_probe)(struct udevice *dev);
265	int (*child_post_remove)(struct udevice *dev);
266	int priv_auto_alloc_size;
267	int platdata_auto_alloc_size;
268	int per_child_auto_alloc_size;
269	int per_child_platdata_auto_alloc_size;
270	const void *ops;	/* driver-specific operations */
271	uint32_t flags;
272#if CONFIG_IS_ENABLED(ACPIGEN)
273	struct acpi_ops *acpi_ops;
274#endif
275};
  • struct udevice -驱动程序的实例,保存有关设备的信息,该设备是绑定到特定端口或外设的驱动程序(本质上是驱动程序实例)
  • 设备将通过'bind'调用实现可用,要么是由于U_BOOT_DEVICE()宏(在这种情况下,platdata是非null),要么是由于设备树中的节点(在这种情况下,of_offset >= 0)。在后一种情况下,我们将设备树信息转换为platdata在驱动程序的data_to_platdata方法实现的函数中(如果设备有设备树节点,则在probe方法之前调用)。
  • 所有的驱动程序都属于一个类,代表同一类型设备的一个类。驱动程序的公共元素可以在ucclass中实现,或者ucclass可以为其中的驱动程序提供一致的接口。
  • name:设备名称
  • id:标识我们所属的类
  • of_match:要匹配的兼容字符串的列表,以及每个字符串的任何标识数据。
  • bind:用于将设备绑定到其驱动程序
  • probe:用来探测一个设备,即激活它
  • remove:用于移除设备,即停用设备
  • unbind:用来解除设备与其驱动程序的绑定
  • ofdata_to_platdata:在探测之前调用,解码设备树数据
  • child_post_bind:在绑定新子节点后调用
  • child_pre_probe:在探测子设备之前调用。设备已分配了内存,但尚未对其进行探测。
  • child_post_remove:在移除子设备后调用。设备已分配内存,但其device_remove()方法已被调用。
  • priv_auto_alloc_size:如果非零,这是要在设备的->priv指针中分配的私有数据的大小。如果为零,则驱动程序负责分配所需的任何数据。
  • platdata_auto_alloc_size:如果非零,这是要在设备的->platdata指针中分配的平台数据的大小。这通常只对设备树感知驱动程序(具有of_match的驱动程序)有用,因为使用platdata的驱动程序将具有U_BOOT_DEVICE()实例化中提供的数据。
  • per_child_auto_alloc_size:每个设备可以保存父设备拥有的私有数据。如果需要,如果该值非零,将自动分配此值。
  • per_child_platdata_auto_alloc_size:总线喜欢存储其子节点的信息。如果非零,这是该数据的大小,将在子节点的parent_platdata指针中分配。
  • ops:特定于驱动程序的操作。这通常是由驱动程序定义的函数指针列表,用于实现ucclass所需的驱动程序函数。
  • flags:驱动标志-参见DM_FLAGS_…
  • acpi_ops:高级配置和电源接口(ACPI)操作,允许设备向传递给Linux的ACPI表中添加内容
  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

打个工而已

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值