blob: c5a464be7c44c4187960fea4c845f6d5a7c8b67c [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/**
Simon Glass80647392020-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 Glassa133e212020-12-16 21:20:30 -070029 * uclass_find_next_free_seq() - Get the next free sequence number
Jean-Jacques Hiblot3542ff22018-12-07 14:50:39 +010030 *
Simon Glassa133e212020-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 Hiblot3542ff22018-12-07 14:50:39 +010038 *
Simon Glassd03adb42020-12-16 21:20:08 -070039 * @uc: uclass to check
Simon Glassa133e212020-12-16 21:20:30 -070040 * @return The next free sequence number
Jean-Jacques Hiblot3542ff22018-12-07 14:50:39 +010041 */
Simon Glassa133e212020-12-16 21:20:30 -070042int uclass_find_next_free_seq(struct uclass *uc);
Jean-Jacques Hiblot3542ff22018-12-07 14:50:39 +010043
44/**
Przemyslaw Marczak794d5212015-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 Hiblote7c86562018-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 Glass6494d702014-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 Marczak794d5212015-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 Glass6494d702014-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 Schocher54c5d082014-05-22 12:43:05 +020079int uclass_find_device(enum uclass_id id, int index, struct udevice **devp);
Simon Glass6494d702014-02-26 15:59:18 -070080
81/**
Przemyslaw Marczakc1d6f912015-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 Marczak794d5212015-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 Marczakc1d6f912015-04-15 13:07:17 +020088 *
Simon Glass4805a7a2019-09-25 08:55:55 -060089 * @return 0 if OK (found or not found), -ve on error
Przemyslaw Marczakc1d6f912015-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 Marczak794d5212015-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 Marczakc1d6f912015-04-15 13:07:17 +0200100 *
Simon Glass4805a7a2019-09-25 08:55:55 -0600101 * @return 0 if OK (found or not found), -ve on error
Przemyslaw Marczakc1d6f912015-04-15 13:07:17 +0200102 */
103int uclass_find_next_device(struct udevice **devp);
104
105/**
Przemyslaw Marczake0735a42015-04-15 13:07:22 +0200106 * uclass_find_device_by_name() - Find uclass device based on ID and name
107 *
Przemyslaw Marczaka7b82502015-04-20 13:32:34 +0200108 * This searches for a device with the exactly given name.
Przemyslaw Marczake0735a42015-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 Glass99175912020-12-16 21:20:29 -0700123 * This searches for a device with the given seq.
Przemyslaw Marczake0735a42015-04-15 13:07:22 +0200124 *
125 * The device is NOT probed, it is merely returned.
126 *
127 * @id: ID to look up
Simon Glass99175912020-12-16 21:20:29 -0700128 * @seq: Sequence number to find (0=first)
Przemyslaw Marczake0735a42015-04-15 13:07:22 +0200129 * @devp: Returns pointer to device (there is only one per for each seq)
Simon Glass99175912020-12-16 21:20:29 -0700130 * @return 0 if OK, -ENODEV if not found
Przemyslaw Marczake0735a42015-04-15 13:07:22 +0200131 */
Simon Glass99175912020-12-16 21:20:29 -0700132int uclass_find_device_by_seq(enum uclass_id id, int seq,
133 struct udevice **devp);
Przemyslaw Marczake0735a42015-04-15 13:07:22 +0200134
135/**
Simon Glass1b30d612016-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 Glass40bb6372017-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 Glassd0b4f682018-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 Glass6494d702014-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 Schocher54c5d082014-05-22 12:43:05 +0200192int uclass_bind_device(struct udevice *dev);
Simon Glass6494d702014-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 Yamada0a5804b2015-08-12 07:31:52 +0900202#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
Heiko Schocher54c5d082014-05-22 12:43:05 +0200203int uclass_unbind_device(struct udevice *dev);
Simon Glass7f9875e2015-02-27 22:06:31 -0700204#else
205static inline int uclass_unbind_device(struct udevice *dev) { return 0; }
206#endif
Simon Glass6494d702014-02-26 15:59:18 -0700207
208/**
Simon Glass02c07b32015-03-05 12:25:22 -0700209 * uclass_pre_probe_device() - Deal with a device that is about to be probed
Simon Glass83c7e432015-01-25 08:27:10 -0700210 *
211 * Perform any pre-processing that is needed by the uclass before it can be
Simon Glass02c07b32015-03-05 12:25:22 -0700212 * probed. This includes the uclass' pre-probe() method and the parent
213 * uclass' child_pre_probe() method.
Simon Glass83c7e432015-01-25 08:27:10 -0700214 *
215 * @dev: Pointer to the device
216 * #return 0 on success, -ve on error
217 */
Simon Glass02c07b32015-03-05 12:25:22 -0700218int uclass_pre_probe_device(struct udevice *dev);
Simon Glass83c7e432015-01-25 08:27:10 -0700219
220/**
Simon Glass6494d702014-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 Schocher54c5d082014-05-22 12:43:05 +0200229int uclass_post_probe_device(struct udevice *dev);
Simon Glass6494d702014-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 Yamada0a5804b2015-08-12 07:31:52 +0900239#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
Heiko Schocher54c5d082014-05-22 12:43:05 +0200240int uclass_pre_remove_device(struct udevice *dev);
Simon Glass7f9875e2015-02-27 22:06:31 -0700241#else
242static inline int uclass_pre_remove_device(struct udevice *dev) { return 0; }
243#endif
Simon Glass6494d702014-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 Glass6494d702014-02-26 15:59:18 -0700263#endif