blob: 6e3f15c2b0804c07f91b03e6f20f77e9b6527596 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass6494d702014-02-26 15:59:18 -07002/*
3 * Copyright (c) 2013 Google, Inc
4 *
5 * (C) Copyright 2012
6 * Pavel Herrmann <morpheus.ibis@gmail.com>
Simon Glass6494d702014-02-26 15:59:18 -07007 */
8
9#ifndef _DM_UCLASS_INTERNAL_H
10#define _DM_UCLASS_INTERNAL_H
11
Simon Glass40bb6372017-05-18 20:09:09 -060012#include <dm/ofnode.h>
13
Simon Glass6494d702014-02-26 15:59:18 -070014/**
Jean-Jacques Hiblot3542ff22018-12-07 14:50:39 +010015 * uclass_find_next_free_req_seq() - Get the next free req_seq number
16 *
17 * This returns the next free req_seq number. This is useful only if
18 * OF_CONTROL is not used. The next free req_seq number is simply the
19 * maximum req_seq of the uclass + 1.
20 * This allows assiging req_seq number in the binding order.
21 *
22 * @id: Id number of the uclass
23 * @return The next free req_seq number
24 */
25int uclass_find_next_free_req_seq(enum uclass_id id);
26
27/**
Przemyslaw Marczak794d5212015-04-20 13:32:32 +020028 * uclass_get_device_tail() - handle the end of a get_device call
29 *
30 * This handles returning an error or probing a device as needed.
31 *
32 * @dev: Device that needs to be probed
33 * @ret: Error to return. If non-zero then the device is not probed
34 * @devp: Returns the value of 'dev' if there is no error
35 * @return ret, if non-zero, else the result of the device_probe() call
36 */
37int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp);
38
39/**
Jean-Jacques Hiblote7c86562018-08-09 16:17:42 +020040 * dev_get_uclass_index() - Get uclass and index of device
41 * @dev: - in - Device that we want the uclass/index of
42 * @ucp: - out - A pointer to the uclass the device belongs to
43 *
44 * The device is not prepared for use - this is an internal function.
45 *
46 * @return the index of the device in the uclass list or -ENODEV if not found.
47 */
48int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp);
49
50/**
Simon Glass6494d702014-02-26 15:59:18 -070051 * uclass_find_device() - Return n-th child of uclass
52 * @id: Id number of the uclass
53 * @index: Position of the child in uclass's list
54 * #devp: Returns pointer to device, or NULL on error
55 *
Przemyslaw Marczak794d5212015-04-20 13:32:32 +020056 * 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.
Simon Glass6494d702014-02-26 15:59:18 -070058 *
59 * @return the uclass pointer of a child at the given index or
60 * return NULL on error.
61 */
Heiko Schocher54c5d082014-05-22 12:43:05 +020062int uclass_find_device(enum uclass_id id, int index, struct udevice **devp);
Simon Glass6494d702014-02-26 15:59:18 -070063
64/**
Przemyslaw Marczakc1d6f912015-04-15 13:07:17 +020065 * uclass_find_first_device() - Return the first device in a uclass
66 * @id: Id number of the uclass
67 * #devp: Returns pointer to device, or NULL on error
68 *
Przemyslaw Marczak794d5212015-04-20 13:32:32 +020069 * The device is not prepared for use - this is an internal function.
70 * The function uclass_get_device_tail() can be used to probe the device.
Przemyslaw Marczakc1d6f912015-04-15 13:07:17 +020071 *
Simon Glass4805a7a2019-09-25 08:55:55 -060072 * @return 0 if OK (found or not found), -ve on error
Przemyslaw Marczakc1d6f912015-04-15 13:07:17 +020073 */
74int uclass_find_first_device(enum uclass_id id, struct udevice **devp);
75
76/**
77 * uclass_find_next_device() - Return the next device in a uclass
78 * @devp: On entry, pointer to device to lookup. On exit, returns pointer
79 * to the next device in the same uclass, or NULL if none
80 *
Przemyslaw Marczak794d5212015-04-20 13:32:32 +020081 * The device is not prepared for use - this is an internal function.
82 * The function uclass_get_device_tail() can be used to probe the device.
Przemyslaw Marczakc1d6f912015-04-15 13:07:17 +020083 *
Simon Glass4805a7a2019-09-25 08:55:55 -060084 * @return 0 if OK (found or not found), -ve on error
Przemyslaw Marczakc1d6f912015-04-15 13:07:17 +020085 */
86int uclass_find_next_device(struct udevice **devp);
87
88/**
Przemyslaw Marczake0735a42015-04-15 13:07:22 +020089 * uclass_find_device_by_name() - Find uclass device based on ID and name
90 *
Przemyslaw Marczaka7b82502015-04-20 13:32:34 +020091 * This searches for a device with the exactly given name.
Przemyslaw Marczake0735a42015-04-15 13:07:22 +020092 *
93 * The device is NOT probed, it is merely returned.
94 *
95 * @id: ID to look up
96 * @name: name of a device to find
97 * @devp: Returns pointer to device (the first one with the name)
98 * @return 0 if OK, -ve on error
99 */
100int uclass_find_device_by_name(enum uclass_id id, const char *name,
101 struct udevice **devp);
102
103/**
104 * uclass_find_device_by_seq() - Find uclass device based on ID and sequence
105 *
106 * This searches for a device with the given seq or req_seq.
107 *
108 * For seq, if an active device has this sequence it will be returned.
109 * If there is no such device then this will return -ENODEV.
110 *
111 * For req_seq, if a device (whether activated or not) has this req_seq
112 * value, that device will be returned. This is a strong indication that
113 * the device will receive that sequence when activated.
114 *
115 * The device is NOT probed, it is merely returned.
116 *
117 * @id: ID to look up
118 * @seq_or_req_seq: Sequence number to find (0=first)
119 * @find_req_seq: true to find req_seq, false to find seq
120 * @devp: Returns pointer to device (there is only one per for each seq)
121 * @return 0 if OK, -ve on error
122 */
123int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq,
124 bool find_req_seq, struct udevice **devp);
125
126/**
Simon Glass1b30d612016-01-21 19:43:57 -0700127 * uclass_find_device_by_of_offset() - Find a uclass device by device tree node
128 *
129 * This searches the devices in the uclass for one attached to the given
130 * device tree node.
131 *
132 * The device is NOT probed, it is merely returned.
133 *
134 * @id: ID to look up
135 * @node: Device tree offset to search for (if -ve then -ENODEV is returned)
136 * @devp: Returns pointer to device (there is only one for each node)
137 * @return 0 if OK, -ve on error
138 */
139int uclass_find_device_by_of_offset(enum uclass_id id, int node,
140 struct udevice **devp);
141
142/**
Simon Glass40bb6372017-05-18 20:09:09 -0600143 * uclass_find_device_by_of_node() - Find a uclass device by device tree node
144 *
145 * This searches the devices in the uclass for one attached to the given
146 * device tree node.
147 *
148 * The device is NOT probed, it is merely returned.
149 *
150 * @id: ID to look up
151 * @node: Device tree offset to search for (if NULL then -ENODEV is returned)
152 * @devp: Returns pointer to device (there is only one for each node)
153 * @return 0 if OK, -ve on error
154 */
155int uclass_find_device_by_ofnode(enum uclass_id id, ofnode node,
156 struct udevice **devp);
157
158/**
Simon Glassd0b4f682018-11-18 08:14:30 -0700159 * uclass_find_device_by_phandle() - Find a uclass device by phandle
160 *
161 * This searches the devices in the uclass for one with the given phandle.
162 *
163 * The device is NOT probed, it is merely returned.
164 *
165 * @id: ID to look up
166 * @parent: Parent device containing the phandle pointer
167 * @name: Name of property in the parent device node
168 * @devp: Returns pointer to device (there is only one for each node)
169 * @return 0 if OK, -ENOENT if there is no @name present in the node, other
170 * -ve on error
171 */
172int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent,
173 const char *name, struct udevice **devp);
174
175/**
Simon Glass6494d702014-02-26 15:59:18 -0700176 * uclass_bind_device() - Associate device with a uclass
177 *
178 * Connect the device into uclass's list of devices.
179 *
180 * @dev: Pointer to the device
181 * #return 0 on success, -ve on error
182 */
Heiko Schocher54c5d082014-05-22 12:43:05 +0200183int uclass_bind_device(struct udevice *dev);
Simon Glass6494d702014-02-26 15:59:18 -0700184
185/**
186 * uclass_unbind_device() - Deassociate device with a uclass
187 *
188 * Disconnect the device from uclass's list of devices.
189 *
190 * @dev: Pointer to the device
191 * #return 0 on success, -ve on error
192 */
Masahiro Yamada0a5804b2015-08-12 07:31:52 +0900193#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
Heiko Schocher54c5d082014-05-22 12:43:05 +0200194int uclass_unbind_device(struct udevice *dev);
Simon Glass7f9875e2015-02-27 22:06:31 -0700195#else
196static inline int uclass_unbind_device(struct udevice *dev) { return 0; }
197#endif
Simon Glass6494d702014-02-26 15:59:18 -0700198
199/**
Simon Glass02c07b32015-03-05 12:25:22 -0700200 * uclass_pre_probe_device() - Deal with a device that is about to be probed
Simon Glass83c7e432015-01-25 08:27:10 -0700201 *
202 * Perform any pre-processing that is needed by the uclass before it can be
Simon Glass02c07b32015-03-05 12:25:22 -0700203 * probed. This includes the uclass' pre-probe() method and the parent
204 * uclass' child_pre_probe() method.
Simon Glass83c7e432015-01-25 08:27:10 -0700205 *
206 * @dev: Pointer to the device
207 * #return 0 on success, -ve on error
208 */
Simon Glass02c07b32015-03-05 12:25:22 -0700209int uclass_pre_probe_device(struct udevice *dev);
Simon Glass83c7e432015-01-25 08:27:10 -0700210
211/**
Simon Glass6494d702014-02-26 15:59:18 -0700212 * uclass_post_probe_device() - Deal with a device that has just been probed
213 *
214 * Perform any post-processing of a probed device that is needed by the
215 * uclass.
216 *
217 * @dev: Pointer to the device
218 * #return 0 on success, -ve on error
219 */
Heiko Schocher54c5d082014-05-22 12:43:05 +0200220int uclass_post_probe_device(struct udevice *dev);
Simon Glass6494d702014-02-26 15:59:18 -0700221
222/**
223 * uclass_pre_remove_device() - Handle a device which is about to be removed
224 *
225 * Perform any pre-processing of a device that is about to be removed.
226 *
227 * @dev: Pointer to the device
228 * #return 0 on success, -ve on error
229 */
Masahiro Yamada0a5804b2015-08-12 07:31:52 +0900230#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
Heiko Schocher54c5d082014-05-22 12:43:05 +0200231int uclass_pre_remove_device(struct udevice *dev);
Simon Glass7f9875e2015-02-27 22:06:31 -0700232#else
233static inline int uclass_pre_remove_device(struct udevice *dev) { return 0; }
234#endif
Simon Glass6494d702014-02-26 15:59:18 -0700235
236/**
237 * uclass_find() - Find uclass by its id
238 *
239 * @id: Id to serach for
240 * @return pointer to uclass, or NULL if not found
241 */
242struct uclass *uclass_find(enum uclass_id key);
243
244/**
245 * uclass_destroy() - Destroy a uclass
246 *
247 * Destroy a uclass and all its devices
248 *
249 * @uc: uclass to destroy
250 * @return 0 on success, -ve on error
251 */
252int uclass_destroy(struct uclass *uc);
253
Simon Glass6494d702014-02-26 15:59:18 -0700254#endif