xref: /openbmc/u-boot/include/dm/uclass-internal.h (revision 7ff485c68b7e5573e5a4a877066e98398283a24f)
183d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */
26494d708SSimon Glass /*
36494d708SSimon Glass  * Copyright (c) 2013 Google, Inc
46494d708SSimon Glass  *
56494d708SSimon Glass  * (C) Copyright 2012
66494d708SSimon Glass  * Pavel Herrmann <morpheus.ibis@gmail.com>
76494d708SSimon Glass  */
86494d708SSimon Glass 
96494d708SSimon Glass #ifndef _DM_UCLASS_INTERNAL_H
106494d708SSimon Glass #define _DM_UCLASS_INTERNAL_H
116494d708SSimon Glass 
1240bb637dSSimon Glass #include <dm/ofnode.h>
1340bb637dSSimon Glass 
146494d708SSimon Glass /**
15*3542ff29SJean-Jacques Hiblot  * uclass_find_next_free_req_seq() - Get the next free req_seq number
16*3542ff29SJean-Jacques Hiblot  *
17*3542ff29SJean-Jacques Hiblot  * This returns the next free req_seq number. This is useful only if
18*3542ff29SJean-Jacques Hiblot  * OF_CONTROL is not used. The next free req_seq number is simply the
19*3542ff29SJean-Jacques Hiblot  * maximum req_seq of the uclass + 1.
20*3542ff29SJean-Jacques Hiblot  * This allows assiging req_seq number in the binding order.
21*3542ff29SJean-Jacques Hiblot  *
22*3542ff29SJean-Jacques Hiblot  * @id:		Id number of the uclass
23*3542ff29SJean-Jacques Hiblot  * @return	The next free req_seq number
24*3542ff29SJean-Jacques Hiblot  */
25*3542ff29SJean-Jacques Hiblot int uclass_find_next_free_req_seq(enum uclass_id id);
26*3542ff29SJean-Jacques Hiblot 
27*3542ff29SJean-Jacques Hiblot /**
28794d5219SPrzemyslaw Marczak  * uclass_get_device_tail() - handle the end of a get_device call
29794d5219SPrzemyslaw Marczak  *
30794d5219SPrzemyslaw Marczak  * This handles returning an error or probing a device as needed.
31794d5219SPrzemyslaw Marczak  *
32794d5219SPrzemyslaw Marczak  * @dev: Device that needs to be probed
33794d5219SPrzemyslaw Marczak  * @ret: Error to return. If non-zero then the device is not probed
34794d5219SPrzemyslaw Marczak  * @devp: Returns the value of 'dev' if there is no error
35794d5219SPrzemyslaw Marczak  * @return ret, if non-zero, else the result of the device_probe() call
36794d5219SPrzemyslaw Marczak  */
37794d5219SPrzemyslaw Marczak int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp);
38794d5219SPrzemyslaw Marczak 
39794d5219SPrzemyslaw Marczak /**
40e7c86562SJean-Jacques Hiblot  * dev_get_uclass_index() - Get uclass and index of device
41e7c86562SJean-Jacques Hiblot  * @dev:	- in - Device that we want the uclass/index of
42e7c86562SJean-Jacques Hiblot  * @ucp:	- out - A pointer to the uclass the device belongs to
43e7c86562SJean-Jacques Hiblot  *
44e7c86562SJean-Jacques Hiblot  * The device is not prepared for use - this is an internal function.
45e7c86562SJean-Jacques Hiblot  *
46e7c86562SJean-Jacques Hiblot  * @return the index of the device in the uclass list or -ENODEV if not found.
47e7c86562SJean-Jacques Hiblot  */
48e7c86562SJean-Jacques Hiblot int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp);
49e7c86562SJean-Jacques Hiblot 
50e7c86562SJean-Jacques Hiblot /**
516494d708SSimon Glass  * uclass_find_device() - Return n-th child of uclass
526494d708SSimon Glass  * @id:		Id number of the uclass
536494d708SSimon Glass  * @index:	Position of the child in uclass's list
546494d708SSimon Glass  * #devp:	Returns pointer to device, or NULL on error
556494d708SSimon Glass  *
56794d5219SPrzemyslaw Marczak  * The device is not prepared for use - this is an internal function.
57794d5219SPrzemyslaw Marczak  * The function uclass_get_device_tail() can be used to probe the device.
586494d708SSimon Glass  *
596494d708SSimon Glass  * @return the uclass pointer of a child at the given index or
606494d708SSimon Glass  * return NULL on error.
616494d708SSimon Glass  */
6254c5d08aSHeiko Schocher int uclass_find_device(enum uclass_id id, int index, struct udevice **devp);
636494d708SSimon Glass 
646494d708SSimon Glass /**
65c1d6f919SPrzemyslaw Marczak  * uclass_find_first_device() - Return the first device in a uclass
66c1d6f919SPrzemyslaw Marczak  * @id:		Id number of the uclass
67c1d6f919SPrzemyslaw Marczak  * #devp:	Returns pointer to device, or NULL on error
68c1d6f919SPrzemyslaw Marczak  *
69794d5219SPrzemyslaw Marczak  * The device is not prepared for use - this is an internal function.
70794d5219SPrzemyslaw Marczak  * The function uclass_get_device_tail() can be used to probe the device.
71c1d6f919SPrzemyslaw Marczak  *
72c1d6f919SPrzemyslaw Marczak  * @return 0 if OK (found or not found), -1 on error
73c1d6f919SPrzemyslaw Marczak  */
74c1d6f919SPrzemyslaw Marczak int uclass_find_first_device(enum uclass_id id, struct udevice **devp);
75c1d6f919SPrzemyslaw Marczak 
76c1d6f919SPrzemyslaw Marczak /**
77c1d6f919SPrzemyslaw Marczak  * uclass_find_next_device() - Return the next device in a uclass
78c1d6f919SPrzemyslaw Marczak  * @devp: On entry, pointer to device to lookup. On exit, returns pointer
79c1d6f919SPrzemyslaw Marczak  * to the next device in the same uclass, or NULL if none
80c1d6f919SPrzemyslaw Marczak  *
81794d5219SPrzemyslaw Marczak  * The device is not prepared for use - this is an internal function.
82794d5219SPrzemyslaw Marczak  * The function uclass_get_device_tail() can be used to probe the device.
83c1d6f919SPrzemyslaw Marczak  *
84c1d6f919SPrzemyslaw Marczak  * @return 0 if OK (found or not found), -1 on error
85c1d6f919SPrzemyslaw Marczak  */
86c1d6f919SPrzemyslaw Marczak int uclass_find_next_device(struct udevice **devp);
87c1d6f919SPrzemyslaw Marczak 
88c1d6f919SPrzemyslaw Marczak /**
89e0735a4cSPrzemyslaw Marczak  * uclass_find_device_by_name() - Find uclass device based on ID and name
90e0735a4cSPrzemyslaw Marczak  *
91a7b82502SPrzemyslaw Marczak  * This searches for a device with the exactly given name.
92e0735a4cSPrzemyslaw Marczak  *
93e0735a4cSPrzemyslaw Marczak  * The device is NOT probed, it is merely returned.
94e0735a4cSPrzemyslaw Marczak  *
95e0735a4cSPrzemyslaw Marczak  * @id: ID to look up
96e0735a4cSPrzemyslaw Marczak  * @name: name of a device to find
97e0735a4cSPrzemyslaw Marczak  * @devp: Returns pointer to device (the first one with the name)
98e0735a4cSPrzemyslaw Marczak  * @return 0 if OK, -ve on error
99e0735a4cSPrzemyslaw Marczak  */
100e0735a4cSPrzemyslaw Marczak int uclass_find_device_by_name(enum uclass_id id, const char *name,
101e0735a4cSPrzemyslaw Marczak 			       struct udevice **devp);
102e0735a4cSPrzemyslaw Marczak 
103e0735a4cSPrzemyslaw Marczak /**
104e0735a4cSPrzemyslaw Marczak  * uclass_find_device_by_seq() - Find uclass device based on ID and sequence
105e0735a4cSPrzemyslaw Marczak  *
106e0735a4cSPrzemyslaw Marczak  * This searches for a device with the given seq or req_seq.
107e0735a4cSPrzemyslaw Marczak  *
108e0735a4cSPrzemyslaw Marczak  * For seq, if an active device has this sequence it will be returned.
109e0735a4cSPrzemyslaw Marczak  * If there is no such device then this will return -ENODEV.
110e0735a4cSPrzemyslaw Marczak  *
111e0735a4cSPrzemyslaw Marczak  * For req_seq, if a device (whether activated or not) has this req_seq
112e0735a4cSPrzemyslaw Marczak  * value, that device will be returned. This is a strong indication that
113e0735a4cSPrzemyslaw Marczak  * the device will receive that sequence when activated.
114e0735a4cSPrzemyslaw Marczak  *
115e0735a4cSPrzemyslaw Marczak  * The device is NOT probed, it is merely returned.
116e0735a4cSPrzemyslaw Marczak  *
117e0735a4cSPrzemyslaw Marczak  * @id: ID to look up
118e0735a4cSPrzemyslaw Marczak  * @seq_or_req_seq: Sequence number to find (0=first)
119e0735a4cSPrzemyslaw Marczak  * @find_req_seq: true to find req_seq, false to find seq
120e0735a4cSPrzemyslaw Marczak  * @devp: Returns pointer to device (there is only one per for each seq)
121e0735a4cSPrzemyslaw Marczak  * @return 0 if OK, -ve on error
122e0735a4cSPrzemyslaw Marczak  */
123e0735a4cSPrzemyslaw Marczak int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq,
124e0735a4cSPrzemyslaw Marczak 			      bool find_req_seq, struct udevice **devp);
125e0735a4cSPrzemyslaw Marczak 
126e0735a4cSPrzemyslaw Marczak /**
1271b30d61dSSimon Glass  * uclass_find_device_by_of_offset() - Find a uclass device by device tree node
1281b30d61dSSimon Glass  *
1291b30d61dSSimon Glass  * This searches the devices in the uclass for one attached to the given
1301b30d61dSSimon Glass  * device tree node.
1311b30d61dSSimon Glass  *
1321b30d61dSSimon Glass  * The device is NOT probed, it is merely returned.
1331b30d61dSSimon Glass  *
1341b30d61dSSimon Glass  * @id: ID to look up
1351b30d61dSSimon Glass  * @node: Device tree offset to search for (if -ve then -ENODEV is returned)
1361b30d61dSSimon Glass  * @devp: Returns pointer to device (there is only one for each node)
1371b30d61dSSimon Glass  * @return 0 if OK, -ve on error
1381b30d61dSSimon Glass  */
1391b30d61dSSimon Glass int uclass_find_device_by_of_offset(enum uclass_id id, int node,
1401b30d61dSSimon Glass 				    struct udevice **devp);
1411b30d61dSSimon Glass 
1421b30d61dSSimon Glass /**
14340bb637dSSimon Glass  * uclass_find_device_by_of_node() - Find a uclass device by device tree node
14440bb637dSSimon Glass  *
14540bb637dSSimon Glass  * This searches the devices in the uclass for one attached to the given
14640bb637dSSimon Glass  * device tree node.
14740bb637dSSimon Glass  *
14840bb637dSSimon Glass  * The device is NOT probed, it is merely returned.
14940bb637dSSimon Glass  *
15040bb637dSSimon Glass  * @id: ID to look up
15140bb637dSSimon Glass  * @node: Device tree offset to search for (if NULL then -ENODEV is returned)
15240bb637dSSimon Glass  * @devp: Returns pointer to device (there is only one for each node)
15340bb637dSSimon Glass  * @return 0 if OK, -ve on error
15440bb637dSSimon Glass  */
15540bb637dSSimon Glass int uclass_find_device_by_ofnode(enum uclass_id id, ofnode node,
15640bb637dSSimon Glass 				 struct udevice **devp);
15740bb637dSSimon Glass 
15840bb637dSSimon Glass /**
159d0b4f68dSSimon Glass  * uclass_find_device_by_phandle() - Find a uclass device by phandle
160d0b4f68dSSimon Glass  *
161d0b4f68dSSimon Glass  * This searches the devices in the uclass for one with the given phandle.
162d0b4f68dSSimon Glass  *
163d0b4f68dSSimon Glass  * The device is NOT probed, it is merely returned.
164d0b4f68dSSimon Glass  *
165d0b4f68dSSimon Glass  * @id: ID to look up
166d0b4f68dSSimon Glass  * @parent: Parent device containing the phandle pointer
167d0b4f68dSSimon Glass  * @name: Name of property in the parent device node
168d0b4f68dSSimon Glass  * @devp: Returns pointer to device (there is only one for each node)
169d0b4f68dSSimon Glass  * @return 0 if OK, -ENOENT if there is no @name present in the node, other
170d0b4f68dSSimon Glass  *	-ve on error
171d0b4f68dSSimon Glass  */
172d0b4f68dSSimon Glass int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent,
173d0b4f68dSSimon Glass 				  const char *name, struct udevice **devp);
174d0b4f68dSSimon Glass 
175d0b4f68dSSimon Glass /**
1766494d708SSimon Glass  * uclass_bind_device() - Associate device with a uclass
1776494d708SSimon Glass  *
1786494d708SSimon Glass  * Connect the device into uclass's list of devices.
1796494d708SSimon Glass  *
1806494d708SSimon Glass  * @dev:	Pointer to the device
1816494d708SSimon Glass  * #return 0 on success, -ve on error
1826494d708SSimon Glass  */
18354c5d08aSHeiko Schocher int uclass_bind_device(struct udevice *dev);
1846494d708SSimon Glass 
1856494d708SSimon Glass /**
1866494d708SSimon Glass  * uclass_unbind_device() - Deassociate device with a uclass
1876494d708SSimon Glass  *
1886494d708SSimon Glass  * Disconnect the device from uclass's list of devices.
1896494d708SSimon Glass  *
1906494d708SSimon Glass  * @dev:	Pointer to the device
1916494d708SSimon Glass  * #return 0 on success, -ve on error
1926494d708SSimon Glass  */
1930a5804b5SMasahiro Yamada #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
19454c5d08aSHeiko Schocher int uclass_unbind_device(struct udevice *dev);
1957f9875e7SSimon Glass #else
uclass_unbind_device(struct udevice * dev)1967f9875e7SSimon Glass static inline int uclass_unbind_device(struct udevice *dev) { return 0; }
1977f9875e7SSimon Glass #endif
1986494d708SSimon Glass 
1996494d708SSimon Glass /**
20002c07b37SSimon Glass  * uclass_pre_probe_device() - Deal with a device that is about to be probed
20183c7e434SSimon Glass  *
20283c7e434SSimon Glass  * Perform any pre-processing that is needed by the uclass before it can be
20302c07b37SSimon Glass  * probed. This includes the uclass' pre-probe() method and the parent
20402c07b37SSimon Glass  * uclass' child_pre_probe() method.
20583c7e434SSimon Glass  *
20683c7e434SSimon Glass  * @dev:	Pointer to the device
20783c7e434SSimon Glass  * #return 0 on success, -ve on error
20883c7e434SSimon Glass  */
20902c07b37SSimon Glass int uclass_pre_probe_device(struct udevice *dev);
21083c7e434SSimon Glass 
21183c7e434SSimon Glass /**
2126494d708SSimon Glass  * uclass_post_probe_device() - Deal with a device that has just been probed
2136494d708SSimon Glass  *
2146494d708SSimon Glass  * Perform any post-processing of a probed device that is needed by the
2156494d708SSimon Glass  * uclass.
2166494d708SSimon Glass  *
2176494d708SSimon Glass  * @dev:	Pointer to the device
2186494d708SSimon Glass  * #return 0 on success, -ve on error
2196494d708SSimon Glass  */
22054c5d08aSHeiko Schocher int uclass_post_probe_device(struct udevice *dev);
2216494d708SSimon Glass 
2226494d708SSimon Glass /**
2236494d708SSimon Glass  * uclass_pre_remove_device() - Handle a device which is about to be removed
2246494d708SSimon Glass  *
2256494d708SSimon Glass  * Perform any pre-processing of a device that is about to be removed.
2266494d708SSimon Glass  *
2276494d708SSimon Glass  * @dev:	Pointer to the device
2286494d708SSimon Glass  * #return 0 on success, -ve on error
2296494d708SSimon Glass  */
2300a5804b5SMasahiro Yamada #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
23154c5d08aSHeiko Schocher int uclass_pre_remove_device(struct udevice *dev);
2327f9875e7SSimon Glass #else
uclass_pre_remove_device(struct udevice * dev)2337f9875e7SSimon Glass static inline int uclass_pre_remove_device(struct udevice *dev) { return 0; }
2347f9875e7SSimon Glass #endif
2356494d708SSimon Glass 
2366494d708SSimon Glass /**
2376494d708SSimon Glass  * uclass_find() - Find uclass by its id
2386494d708SSimon Glass  *
2396494d708SSimon Glass  * @id:		Id to serach for
2406494d708SSimon Glass  * @return pointer to uclass, or NULL if not found
2416494d708SSimon Glass  */
2426494d708SSimon Glass struct uclass *uclass_find(enum uclass_id key);
2436494d708SSimon Glass 
2446494d708SSimon Glass /**
2456494d708SSimon Glass  * uclass_destroy() - Destroy a uclass
2466494d708SSimon Glass  *
2476494d708SSimon Glass  * Destroy a uclass and all its devices
2486494d708SSimon Glass  *
2496494d708SSimon Glass  * @uc: uclass to destroy
2506494d708SSimon Glass  * @return 0 on success, -ve on error
2516494d708SSimon Glass  */
2526494d708SSimon Glass int uclass_destroy(struct uclass *uc);
2536494d708SSimon Glass 
2546494d708SSimon Glass #endif
255