blob: c5a464be7c44c4187960fea4c845f6d5a7c8b67c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glassdd6ab882014-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 Glassdd6ab882014-02-26 15:59:18 -07007 */
8
9#ifndef _DM_UCLASS_INTERNAL_H
10#define _DM_UCLASS_INTERNAL_H
11
Simon Glassee145d62017-05-18 20:09:09 -060012#include <dm/ofnode.h>
13
Simon Glassdd6ab882014-02-26 15:59:18 -070014/**
Simon Glass96404c22020-12-22 19:30:26 -070015 * uclass_set_priv() - Set the private data for a uclass
16 *
17 * This is normally handled by driver model, which automatically allocates
18 * private data when an 'auto' size if provided by the uclass driver.
19 *
20 * Use this function to override normal operation for special situations, such
21 * as needing to allocate a variable amount of data.
22 *
23 * @uc Uclass to update
24 * @priv New private-data pointer
25 */
26void uclass_set_priv(struct uclass *uc, void *priv);
27
28/**
Simon Glassb941f562020-12-16 21:20:30 -070029 * uclass_find_next_free_seq() - Get the next free sequence number
Jean-Jacques Hiblota5da3002018-12-07 14:50:39 +010030 *
Simon Glassb941f562020-12-16 21:20:30 -070031 * This returns the next free sequence number. This is useful only if
32 * OF_CONTROL is not used. The next free sequence number is simply the
33 * maximum sequence number used by all devices in the uclass + 1. The value
34 * returned is always greater than the largest alias, if DM_SEQ_ALIAS is enabled
35 * and the uclass has the DM_UC_FLAG_SEQ_ALIAS flag.
36 *
37 * This allows assigning the sequence number in the binding order.
Jean-Jacques Hiblota5da3002018-12-07 14:50:39 +010038 *
Simon Glass1ae093f2020-12-16 21:20:08 -070039 * @uc: uclass to check
Simon Glassb941f562020-12-16 21:20:30 -070040 * @return The next free sequence number
Jean-Jacques Hiblota5da3002018-12-07 14:50:39 +010041 */
Simon Glassb941f562020-12-16 21:20:30 -070042int uclass_find_next_free_seq(struct uclass *uc);
Jean-Jacques Hiblota5da3002018-12-07 14:50:39 +010043
44/**
Przemyslaw Marczakfa277fc2015-04-20 13:32:32 +020045 * uclass_get_device_tail() - handle the end of a get_device call
46 *
47 * This handles returning an error or probing a device as needed.
48 *
49 * @dev: Device that needs to be probed
50 * @ret: Error to return. If non-zero then the device is not probed
51 * @devp: Returns the value of 'dev' if there is no error
52 * @return ret, if non-zero, else the result of the device_probe() call
53 */
54int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp);
55
56/**
Jean-Jacques Hiblotc4f02482018-08-09 16:17:42 +020057 * dev_get_uclass_index() - Get uclass and index of device
58 * @dev: - in - Device that we want the uclass/index of
59 * @ucp: - out - A pointer to the uclass the device belongs to
60 *
61 * The device is not prepared for use - this is an internal function.
62 *
63 * @return the index of the device in the uclass list or -ENODEV if not found.
64 */
65int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp);
66
67/**
Simon Glassdd6ab882014-02-26 15:59:18 -070068 * uclass_find_device() - Return n-th child of uclass
69 * @id: Id number of the uclass
70 * @index: Position of the child in uclass's list
71 * #devp: Returns pointer to device, or NULL on error
72 *
Przemyslaw Marczakfa277fc2015-04-20 13:32:32 +020073 * The device is not prepared for use - this is an internal function.
74 * The function uclass_get_device_tail() can be used to probe the device.
Simon Glassdd6ab882014-02-26 15:59:18 -070075 *
76 * @return the uclass pointer of a child at the given index or
77 * return NULL on error.
78 */
Heiko Schocherb74fcb42014-05-22 12:43:05 +020079int uclass_find_device(enum uclass_id id, int index, struct udevice **devp);
Simon Glassdd6ab882014-02-26 15:59:18 -070080
81/**
Przemyslaw Marczakf9d156e2015-04-15 13:07:17 +020082 * uclass_find_first_device() - Return the first device in a uclass
83 * @id: Id number of the uclass
84 * #devp: Returns pointer to device, or NULL on error
85 *
Przemyslaw Marczakfa277fc2015-04-20 13:32:32 +020086 * The device is not prepared for use - this is an internal function.
87 * The function uclass_get_device_tail() can be used to probe the device.
Przemyslaw Marczakf9d156e2015-04-15 13:07:17 +020088 *
Simon Glass0bb44272019-09-25 08:55:55 -060089 * @return 0 if OK (found or not found), -ve on error
Przemyslaw Marczakf9d156e2015-04-15 13:07:17 +020090 */
91int uclass_find_first_device(enum uclass_id id, struct udevice **devp);
92
93/**
94 * uclass_find_next_device() - Return the next device in a uclass
95 * @devp: On entry, pointer to device to lookup. On exit, returns pointer
96 * to the next device in the same uclass, or NULL if none
97 *
Przemyslaw Marczakfa277fc2015-04-20 13:32:32 +020098 * The device is not prepared for use - this is an internal function.
99 * The function uclass_get_device_tail() can be used to probe the device.
Przemyslaw Marczakf9d156e2015-04-15 13:07:17 +0200100 *
Simon Glass0bb44272019-09-25 08:55:55 -0600101 * @return 0 if OK (found or not found), -ve on error
Przemyslaw Marczakf9d156e2015-04-15 13:07:17 +0200102 */
103int uclass_find_next_device(struct udevice **devp);
104
105/**
Przemyslaw Marczak2ffdf142015-04-15 13:07:22 +0200106 * uclass_find_device_by_name() - Find uclass device based on ID and name
107 *
Przemyslaw Marczakc9177722015-04-20 13:32:34 +0200108 * This searches for a device with the exactly given name.
Przemyslaw Marczak2ffdf142015-04-15 13:07:22 +0200109 *
110 * The device is NOT probed, it is merely returned.
111 *
112 * @id: ID to look up
113 * @name: name of a device to find
114 * @devp: Returns pointer to device (the first one with the name)
115 * @return 0 if OK, -ve on error
116 */
117int uclass_find_device_by_name(enum uclass_id id, const char *name,
118 struct udevice **devp);
119
120/**
121 * uclass_find_device_by_seq() - Find uclass device based on ID and sequence
122 *
Simon Glass07e13382020-12-16 21:20:29 -0700123 * This searches for a device with the given seq.
Przemyslaw Marczak2ffdf142015-04-15 13:07:22 +0200124 *
125 * The device is NOT probed, it is merely returned.
126 *
127 * @id: ID to look up
Simon Glass07e13382020-12-16 21:20:29 -0700128 * @seq: Sequence number to find (0=first)
Przemyslaw Marczak2ffdf142015-04-15 13:07:22 +0200129 * @devp: Returns pointer to device (there is only one per for each seq)
Simon Glass07e13382020-12-16 21:20:29 -0700130 * @return 0 if OK, -ENODEV if not found
Przemyslaw Marczak2ffdf142015-04-15 13:07:22 +0200131 */
Simon Glass07e13382020-12-16 21:20:29 -0700132int uclass_find_device_by_seq(enum uclass_id id, int seq,
133 struct udevice **devp);
Przemyslaw Marczak2ffdf142015-04-15 13:07:22 +0200134
135/**
Simon Glass96f04442016-01-21 19:43:57 -0700136 * uclass_find_device_by_of_offset() - Find a uclass device by device tree node
137 *
138 * This searches the devices in the uclass for one attached to the given
139 * device tree node.
140 *
141 * The device is NOT probed, it is merely returned.
142 *
143 * @id: ID to look up
144 * @node: Device tree offset to search for (if -ve then -ENODEV is returned)
145 * @devp: Returns pointer to device (there is only one for each node)
146 * @return 0 if OK, -ve on error
147 */
148int uclass_find_device_by_of_offset(enum uclass_id id, int node,
149 struct udevice **devp);
150
151/**
Simon Glassee145d62017-05-18 20:09:09 -0600152 * uclass_find_device_by_of_node() - Find a uclass device by device tree node
153 *
154 * This searches the devices in the uclass for one attached to the given
155 * device tree node.
156 *
157 * The device is NOT probed, it is merely returned.
158 *
159 * @id: ID to look up
160 * @node: Device tree offset to search for (if NULL then -ENODEV is returned)
161 * @devp: Returns pointer to device (there is only one for each node)
162 * @return 0 if OK, -ve on error
163 */
164int uclass_find_device_by_ofnode(enum uclass_id id, ofnode node,
165 struct udevice **devp);
166
167/**
Simon Glassdc3efdc2018-11-18 08:14:30 -0700168 * uclass_find_device_by_phandle() - Find a uclass device by phandle
169 *
170 * This searches the devices in the uclass for one with the given phandle.
171 *
172 * The device is NOT probed, it is merely returned.
173 *
174 * @id: ID to look up
175 * @parent: Parent device containing the phandle pointer
176 * @name: Name of property in the parent device node
177 * @devp: Returns pointer to device (there is only one for each node)
178 * @return 0 if OK, -ENOENT if there is no @name present in the node, other
179 * -ve on error
180 */
181int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent,
182 const char *name, struct udevice **devp);
183
184/**
Simon Glassdd6ab882014-02-26 15:59:18 -0700185 * uclass_bind_device() - Associate device with a uclass
186 *
187 * Connect the device into uclass's list of devices.
188 *
189 * @dev: Pointer to the device
190 * #return 0 on success, -ve on error
191 */
Heiko Schocherb74fcb42014-05-22 12:43:05 +0200192int uclass_bind_device(struct udevice *dev);
Simon Glassdd6ab882014-02-26 15:59:18 -0700193
194/**
195 * uclass_unbind_device() - Deassociate device with a uclass
196 *
197 * Disconnect the device from uclass's list of devices.
198 *
199 * @dev: Pointer to the device
200 * #return 0 on success, -ve on error
201 */
Masahiro Yamada04aa00d2015-08-12 07:31:52 +0900202#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
Heiko Schocherb74fcb42014-05-22 12:43:05 +0200203int uclass_unbind_device(struct udevice *dev);
Simon Glass8914c8a2015-02-27 22:06:31 -0700204#else
205static inline int uclass_unbind_device(struct udevice *dev) { return 0; }
206#endif
Simon Glassdd6ab882014-02-26 15:59:18 -0700207
208/**
Simon Glass9c1f3822015-03-05 12:25:22 -0700209 * uclass_pre_probe_device() - Deal with a device that is about to be probed
Simon Glass5104b982015-01-25 08:27:10 -0700210 *
211 * Perform any pre-processing that is needed by the uclass before it can be
Simon Glass9c1f3822015-03-05 12:25:22 -0700212 * probed. This includes the uclass' pre-probe() method and the parent
213 * uclass' child_pre_probe() method.
Simon Glass5104b982015-01-25 08:27:10 -0700214 *
215 * @dev: Pointer to the device
216 * #return 0 on success, -ve on error
217 */
Simon Glass9c1f3822015-03-05 12:25:22 -0700218int uclass_pre_probe_device(struct udevice *dev);
Simon Glass5104b982015-01-25 08:27:10 -0700219
220/**
Simon Glassdd6ab882014-02-26 15:59:18 -0700221 * uclass_post_probe_device() - Deal with a device that has just been probed
222 *
223 * Perform any post-processing of a probed device that is needed by the
224 * uclass.
225 *
226 * @dev: Pointer to the device
227 * #return 0 on success, -ve on error
228 */
Heiko Schocherb74fcb42014-05-22 12:43:05 +0200229int uclass_post_probe_device(struct udevice *dev);
Simon Glassdd6ab882014-02-26 15:59:18 -0700230
231/**
232 * uclass_pre_remove_device() - Handle a device which is about to be removed
233 *
234 * Perform any pre-processing of a device that is about to be removed.
235 *
236 * @dev: Pointer to the device
237 * #return 0 on success, -ve on error
238 */
Masahiro Yamada04aa00d2015-08-12 07:31:52 +0900239#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
Heiko Schocherb74fcb42014-05-22 12:43:05 +0200240int uclass_pre_remove_device(struct udevice *dev);
Simon Glass8914c8a2015-02-27 22:06:31 -0700241#else
242static inline int uclass_pre_remove_device(struct udevice *dev) { return 0; }
243#endif
Simon Glassdd6ab882014-02-26 15:59:18 -0700244
245/**
246 * uclass_find() - Find uclass by its id
247 *
248 * @id: Id to serach for
249 * @return pointer to uclass, or NULL if not found
250 */
251struct uclass *uclass_find(enum uclass_id key);
252
253/**
254 * uclass_destroy() - Destroy a uclass
255 *
256 * Destroy a uclass and all its devices
257 *
258 * @uc: uclass to destroy
259 * @return 0 on success, -ve on error
260 */
261int uclass_destroy(struct uclass *uc);
262
Simon Glassdd6ab882014-02-26 15:59:18 -0700263#endif