]> git.ipfire.org Git - people/ms/u-boot.git/blame - include/dm/uclass-internal.h
dm: test: Add tests for get/find uclass's device by name
[people/ms/u-boot.git] / include / dm / uclass-internal.h
CommitLineData
6494d708
SG
1/*
2 * Copyright (c) 2013 Google, Inc
3 *
4 * (C) Copyright 2012
5 * Pavel Herrmann <morpheus.ibis@gmail.com>
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10#ifndef _DM_UCLASS_INTERNAL_H
11#define _DM_UCLASS_INTERNAL_H
12
794d5219
PM
13/**
14 * uclass_get_device_tail() - handle the end of a get_device call
15 *
16 * This handles returning an error or probing a device as needed.
17 *
18 * @dev: Device that needs to be probed
19 * @ret: Error to return. If non-zero then the device is not probed
20 * @devp: Returns the value of 'dev' if there is no error
21 * @return ret, if non-zero, else the result of the device_probe() call
22 */
23int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp);
24
6494d708
SG
25/**
26 * uclass_find_device() - Return n-th child of uclass
27 * @id: Id number of the uclass
28 * @index: Position of the child in uclass's list
29 * #devp: Returns pointer to device, or NULL on error
30 *
794d5219
PM
31 * The device is not prepared for use - this is an internal function.
32 * The function uclass_get_device_tail() can be used to probe the device.
6494d708
SG
33 *
34 * @return the uclass pointer of a child at the given index or
35 * return NULL on error.
36 */
54c5d08a 37int uclass_find_device(enum uclass_id id, int index, struct udevice **devp);
6494d708 38
c1d6f919
PM
39/**
40 * uclass_find_first_device() - Return the first device in a uclass
41 * @id: Id number of the uclass
42 * #devp: Returns pointer to device, or NULL on error
43 *
794d5219
PM
44 * The device is not prepared for use - this is an internal function.
45 * The function uclass_get_device_tail() can be used to probe the device.
c1d6f919
PM
46 *
47 * @return 0 if OK (found or not found), -1 on error
48 */
49int uclass_find_first_device(enum uclass_id id, struct udevice **devp);
50
51/**
52 * uclass_find_next_device() - Return the next device in a uclass
53 * @devp: On entry, pointer to device to lookup. On exit, returns pointer
54 * to the next device in the same uclass, or NULL if none
55 *
794d5219
PM
56 * The device is not prepared for use - this is an internal function.
57 * The function uclass_get_device_tail() can be used to probe the device.
c1d6f919
PM
58 *
59 * @return 0 if OK (found or not found), -1 on error
60 */
61int uclass_find_next_device(struct udevice **devp);
62
e0735a4c
PM
63/**
64 * uclass_find_device_by_name() - Find uclass device based on ID and name
65 *
66 * This searches for a device with the given name.
67 *
68 * The device is NOT probed, it is merely returned.
69 *
70 * @id: ID to look up
71 * @name: name of a device to find
72 * @devp: Returns pointer to device (the first one with the name)
73 * @return 0 if OK, -ve on error
74 */
75int uclass_find_device_by_name(enum uclass_id id, const char *name,
76 struct udevice **devp);
77
78/**
79 * uclass_find_device_by_seq() - Find uclass device based on ID and sequence
80 *
81 * This searches for a device with the given seq or req_seq.
82 *
83 * For seq, if an active device has this sequence it will be returned.
84 * If there is no such device then this will return -ENODEV.
85 *
86 * For req_seq, if a device (whether activated or not) has this req_seq
87 * value, that device will be returned. This is a strong indication that
88 * the device will receive that sequence when activated.
89 *
90 * The device is NOT probed, it is merely returned.
91 *
92 * @id: ID to look up
93 * @seq_or_req_seq: Sequence number to find (0=first)
94 * @find_req_seq: true to find req_seq, false to find seq
95 * @devp: Returns pointer to device (there is only one per for each seq)
96 * @return 0 if OK, -ve on error
97 */
98int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq,
99 bool find_req_seq, struct udevice **devp);
100
6494d708
SG
101/**
102 * uclass_bind_device() - Associate device with a uclass
103 *
104 * Connect the device into uclass's list of devices.
105 *
106 * @dev: Pointer to the device
107 * #return 0 on success, -ve on error
108 */
54c5d08a 109int uclass_bind_device(struct udevice *dev);
6494d708
SG
110
111/**
112 * uclass_unbind_device() - Deassociate device with a uclass
113 *
114 * Disconnect the device from uclass's list of devices.
115 *
116 * @dev: Pointer to the device
117 * #return 0 on success, -ve on error
118 */
54c5d08a 119int uclass_unbind_device(struct udevice *dev);
6494d708 120
83c7e434 121/**
02c07b37 122 * uclass_pre_probe_device() - Deal with a device that is about to be probed
83c7e434
SG
123 *
124 * Perform any pre-processing that is needed by the uclass before it can be
02c07b37
SG
125 * probed. This includes the uclass' pre-probe() method and the parent
126 * uclass' child_pre_probe() method.
83c7e434
SG
127 *
128 * @dev: Pointer to the device
129 * #return 0 on success, -ve on error
130 */
02c07b37 131int uclass_pre_probe_device(struct udevice *dev);
83c7e434 132
6494d708
SG
133/**
134 * uclass_post_probe_device() - Deal with a device that has just been probed
135 *
136 * Perform any post-processing of a probed device that is needed by the
137 * uclass.
138 *
139 * @dev: Pointer to the device
140 * #return 0 on success, -ve on error
141 */
54c5d08a 142int uclass_post_probe_device(struct udevice *dev);
6494d708
SG
143
144/**
145 * uclass_pre_remove_device() - Handle a device which is about to be removed
146 *
147 * Perform any pre-processing of a device that is about to be removed.
148 *
149 * @dev: Pointer to the device
150 * #return 0 on success, -ve on error
151 */
54c5d08a 152int uclass_pre_remove_device(struct udevice *dev);
6494d708
SG
153
154/**
155 * uclass_find() - Find uclass by its id
156 *
157 * @id: Id to serach for
158 * @return pointer to uclass, or NULL if not found
159 */
160struct uclass *uclass_find(enum uclass_id key);
161
162/**
163 * uclass_destroy() - Destroy a uclass
164 *
165 * Destroy a uclass and all its devices
166 *
167 * @uc: uclass to destroy
168 * @return 0 on success, -ve on error
169 */
170int uclass_destroy(struct uclass *uc);
171
172#endif