Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013 Google, Inc |
| 4 | * |
| 5 | * (C) Copyright 2012 |
| 6 | * Pavel Herrmann <morpheus.ibis@gmail.com> |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _DM_UCLASS_INTERNAL_H |
| 10 | #define _DM_UCLASS_INTERNAL_H |
| 11 | |
Simon Glass | ee145d6 | 2017-05-18 20:09:09 -0600 | [diff] [blame] | 12 | #include <dm/ofnode.h> |
| 13 | |
Simon Glass | 7074354 | 2021-03-15 17:25:14 +1300 | [diff] [blame] | 14 | /* |
| 15 | * These next two macros DM_UCLASS_INST() and DM_UCLASS_REF() are only allowed |
| 16 | * in code generated by dtoc, because the ordering is important and if other |
| 17 | * instances creep in then they may mess up the ordering expected by dtoc. |
| 18 | * |
| 19 | * It is OK to use them with 'extern' though, since that does not actually |
| 20 | * add a new record to the linker_list. |
| 21 | */ |
| 22 | |
| 23 | /** |
| 24 | * DM_UCLASS_INST() - Declare a uclass ready for run-time use |
| 25 | * |
| 26 | * This adds an actual struct uclass to a list which is found by driver model |
| 27 | * on start-up. |
| 28 | * |
| 29 | * For example: |
| 30 | * |
| 31 | * DM_UCLASS_INST(clk) = { |
| 32 | * .uc_drv = DM_UCLASS_DRIVER_REF(clk), |
| 33 | * ... |
| 34 | * }; |
| 35 | * |
| 36 | * @_name: Name of the uclass. This must be a valid C identifier, used by the |
| 37 | * linker_list. |
| 38 | */ |
| 39 | #define DM_UCLASS_INST(_name) \ |
| 40 | ll_entry_declare(struct uclass, _name, uclass) |
| 41 | |
| 42 | /** |
| 43 | * DM_UCLASS_REF() - Get a reference to a uclass |
| 44 | * |
| 45 | * This is useful for referencing a uclass at build time. Before this is used, |
| 46 | * an extern DM_UCLASS_INST() must have been declared. |
| 47 | * |
| 48 | * For example: |
| 49 | * |
| 50 | * extern DM_UCLASS_INST(clk); |
| 51 | * |
| 52 | * struct uclass *ucs[] = { |
| 53 | * DM_UCLASS_REF(clk), |
| 54 | * } |
| 55 | * |
| 56 | * @_name: Name of the uclass. This must be a valid C identifier, used by the |
| 57 | * linker_list |
Simon Glass | ebec3a7 | 2022-02-28 12:08:34 -0700 | [diff] [blame] | 58 | * Return: struct uclass * for the device |
Simon Glass | 7074354 | 2021-03-15 17:25:14 +1300 | [diff] [blame] | 59 | */ |
| 60 | #define DM_UCLASS_REF(_name) \ |
| 61 | ll_entry_ref(struct uclass, _name, uclass) |
| 62 | |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 63 | /** |
Simon Glass | 96404c2 | 2020-12-22 19:30:26 -0700 | [diff] [blame] | 64 | * uclass_set_priv() - Set the private data for a uclass |
| 65 | * |
| 66 | * This is normally handled by driver model, which automatically allocates |
| 67 | * private data when an 'auto' size if provided by the uclass driver. |
| 68 | * |
| 69 | * Use this function to override normal operation for special situations, such |
| 70 | * as needing to allocate a variable amount of data. |
| 71 | * |
Simon Glass | 2238594 | 2021-03-15 17:25:41 +1300 | [diff] [blame] | 72 | * If OF_PLATDATA_RT is enabled, this function cannot be used out of core driver |
| 73 | * model code, since the pointer must be within the gd->dm_priv_base region. |
| 74 | * |
Simon Glass | 96404c2 | 2020-12-22 19:30:26 -0700 | [diff] [blame] | 75 | * @uc Uclass to update |
| 76 | * @priv New private-data pointer |
| 77 | */ |
| 78 | void uclass_set_priv(struct uclass *uc, void *priv); |
| 79 | |
| 80 | /** |
Simon Glass | b941f56 | 2020-12-16 21:20:30 -0700 | [diff] [blame] | 81 | * uclass_find_next_free_seq() - Get the next free sequence number |
Jean-Jacques Hiblot | a5da300 | 2018-12-07 14:50:39 +0100 | [diff] [blame] | 82 | * |
Simon Glass | b941f56 | 2020-12-16 21:20:30 -0700 | [diff] [blame] | 83 | * This returns the next free sequence number. This is useful only if |
| 84 | * OF_CONTROL is not used. The next free sequence number is simply the |
| 85 | * maximum sequence number used by all devices in the uclass + 1. The value |
| 86 | * returned is always greater than the largest alias, if DM_SEQ_ALIAS is enabled |
| 87 | * and the uclass has the DM_UC_FLAG_SEQ_ALIAS flag. |
| 88 | * |
| 89 | * This allows assigning the sequence number in the binding order. |
Jean-Jacques Hiblot | a5da300 | 2018-12-07 14:50:39 +0100 | [diff] [blame] | 90 | * |
Simon Glass | 1ae093f | 2020-12-16 21:20:08 -0700 | [diff] [blame] | 91 | * @uc: uclass to check |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 92 | * Return: The next free sequence number |
Jean-Jacques Hiblot | a5da300 | 2018-12-07 14:50:39 +0100 | [diff] [blame] | 93 | */ |
Simon Glass | b941f56 | 2020-12-16 21:20:30 -0700 | [diff] [blame] | 94 | int uclass_find_next_free_seq(struct uclass *uc); |
Jean-Jacques Hiblot | a5da300 | 2018-12-07 14:50:39 +0100 | [diff] [blame] | 95 | |
| 96 | /** |
Przemyslaw Marczak | fa277fc | 2015-04-20 13:32:32 +0200 | [diff] [blame] | 97 | * uclass_get_device_tail() - handle the end of a get_device call |
| 98 | * |
| 99 | * This handles returning an error or probing a device as needed. |
| 100 | * |
| 101 | * @dev: Device that needs to be probed |
| 102 | * @ret: Error to return. If non-zero then the device is not probed |
| 103 | * @devp: Returns the value of 'dev' if there is no error |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 104 | * Return: ret, if non-zero, else the result of the device_probe() call |
Przemyslaw Marczak | fa277fc | 2015-04-20 13:32:32 +0200 | [diff] [blame] | 105 | */ |
| 106 | int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp); |
| 107 | |
| 108 | /** |
Jean-Jacques Hiblot | c4f0248 | 2018-08-09 16:17:42 +0200 | [diff] [blame] | 109 | * dev_get_uclass_index() - Get uclass and index of device |
| 110 | * @dev: - in - Device that we want the uclass/index of |
| 111 | * @ucp: - out - A pointer to the uclass the device belongs to |
| 112 | * |
| 113 | * The device is not prepared for use - this is an internal function. |
| 114 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 115 | * Return: the index of the device in the uclass list or -ENODEV if not found. |
Jean-Jacques Hiblot | c4f0248 | 2018-08-09 16:17:42 +0200 | [diff] [blame] | 116 | */ |
| 117 | int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp); |
| 118 | |
| 119 | /** |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 120 | * uclass_find_device() - Return n-th child of uclass |
| 121 | * @id: Id number of the uclass |
| 122 | * @index: Position of the child in uclass's list |
Simon Glass | ebec3a7 | 2022-02-28 12:08:34 -0700 | [diff] [blame] | 123 | * @devp: Returns pointer to device, or NULL on error |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 124 | * |
Przemyslaw Marczak | fa277fc | 2015-04-20 13:32:32 +0200 | [diff] [blame] | 125 | * The device is not prepared for use - this is an internal function. |
| 126 | * The function uclass_get_device_tail() can be used to probe the device. |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 127 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 128 | * Return: the uclass pointer of a child at the given index or |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 129 | * return NULL on error. |
| 130 | */ |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 131 | int uclass_find_device(enum uclass_id id, int index, struct udevice **devp); |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 132 | |
| 133 | /** |
Przemyslaw Marczak | f9d156e | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 134 | * uclass_find_first_device() - Return the first device in a uclass |
| 135 | * @id: Id number of the uclass |
Simon Glass | ebec3a7 | 2022-02-28 12:08:34 -0700 | [diff] [blame] | 136 | * @devp: Returns pointer to device, or NULL on error |
Przemyslaw Marczak | f9d156e | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 137 | * |
Przemyslaw Marczak | fa277fc | 2015-04-20 13:32:32 +0200 | [diff] [blame] | 138 | * The device is not prepared for use - this is an internal function. |
| 139 | * The function uclass_get_device_tail() can be used to probe the device. |
Przemyslaw Marczak | f9d156e | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 140 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 141 | * Return: 0 if OK (found or not found), -ve on error |
Przemyslaw Marczak | f9d156e | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 142 | */ |
| 143 | int uclass_find_first_device(enum uclass_id id, struct udevice **devp); |
| 144 | |
| 145 | /** |
| 146 | * uclass_find_next_device() - Return the next device in a uclass |
| 147 | * @devp: On entry, pointer to device to lookup. On exit, returns pointer |
| 148 | * to the next device in the same uclass, or NULL if none |
| 149 | * |
Przemyslaw Marczak | fa277fc | 2015-04-20 13:32:32 +0200 | [diff] [blame] | 150 | * The device is not prepared for use - this is an internal function. |
| 151 | * The function uclass_get_device_tail() can be used to probe the device. |
Przemyslaw Marczak | f9d156e | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 152 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 153 | * Return: 0 if OK (found or not found), -ve on error |
Przemyslaw Marczak | f9d156e | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 154 | */ |
| 155 | int uclass_find_next_device(struct udevice **devp); |
| 156 | |
| 157 | /** |
Simon Glass | 9670f7d | 2022-04-24 23:31:00 -0600 | [diff] [blame] | 158 | * uclass_find_device_by_namelen() - Find uclass device based on ID and name |
| 159 | * |
| 160 | * This searches for a device with the exactly given name. |
| 161 | * |
| 162 | * The device is NOT probed, it is merely returned. |
| 163 | * |
| 164 | * @id: ID to look up |
| 165 | * @name: name of a device to find |
| 166 | * @len: Length of @name (the uclass driver name must have the same length) |
| 167 | * @devp: Returns pointer to device (the first one with the name) |
| 168 | * Return: 0 if OK, -ve on error |
| 169 | */ |
| 170 | int uclass_find_device_by_namelen(enum uclass_id id, const char *name, int len, |
| 171 | struct udevice **devp); |
| 172 | |
| 173 | /** |
Przemyslaw Marczak | 2ffdf14 | 2015-04-15 13:07:22 +0200 | [diff] [blame] | 174 | * uclass_find_device_by_name() - Find uclass device based on ID and name |
| 175 | * |
Przemyslaw Marczak | c917772 | 2015-04-20 13:32:34 +0200 | [diff] [blame] | 176 | * This searches for a device with the exactly given name. |
Przemyslaw Marczak | 2ffdf14 | 2015-04-15 13:07:22 +0200 | [diff] [blame] | 177 | * |
| 178 | * The device is NOT probed, it is merely returned. |
| 179 | * |
| 180 | * @id: ID to look up |
| 181 | * @name: name of a device to find |
| 182 | * @devp: Returns pointer to device (the first one with the name) |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 183 | * Return: 0 if OK, -ve on error |
Przemyslaw Marczak | 2ffdf14 | 2015-04-15 13:07:22 +0200 | [diff] [blame] | 184 | */ |
| 185 | int uclass_find_device_by_name(enum uclass_id id, const char *name, |
| 186 | struct udevice **devp); |
| 187 | |
| 188 | /** |
| 189 | * uclass_find_device_by_seq() - Find uclass device based on ID and sequence |
| 190 | * |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 191 | * This searches for a device with the given seq. |
Przemyslaw Marczak | 2ffdf14 | 2015-04-15 13:07:22 +0200 | [diff] [blame] | 192 | * |
| 193 | * The device is NOT probed, it is merely returned. |
| 194 | * |
| 195 | * @id: ID to look up |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 196 | * @seq: Sequence number to find (0=first) |
Przemyslaw Marczak | 2ffdf14 | 2015-04-15 13:07:22 +0200 | [diff] [blame] | 197 | * @devp: Returns pointer to device (there is only one per for each seq) |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 198 | * Return: 0 if OK, -ENODEV if not found |
Przemyslaw Marczak | 2ffdf14 | 2015-04-15 13:07:22 +0200 | [diff] [blame] | 199 | */ |
Simon Glass | 07e1338 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 200 | int uclass_find_device_by_seq(enum uclass_id id, int seq, |
| 201 | struct udevice **devp); |
Przemyslaw Marczak | 2ffdf14 | 2015-04-15 13:07:22 +0200 | [diff] [blame] | 202 | |
| 203 | /** |
Simon Glass | 96f0444 | 2016-01-21 19:43:57 -0700 | [diff] [blame] | 204 | * uclass_find_device_by_of_offset() - Find a uclass device by device tree node |
| 205 | * |
| 206 | * This searches the devices in the uclass for one attached to the given |
| 207 | * device tree node. |
| 208 | * |
| 209 | * The device is NOT probed, it is merely returned. |
| 210 | * |
| 211 | * @id: ID to look up |
| 212 | * @node: Device tree offset to search for (if -ve then -ENODEV is returned) |
| 213 | * @devp: Returns pointer to device (there is only one for each node) |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 214 | * Return: 0 if OK, -ve on error |
Simon Glass | 96f0444 | 2016-01-21 19:43:57 -0700 | [diff] [blame] | 215 | */ |
| 216 | int uclass_find_device_by_of_offset(enum uclass_id id, int node, |
| 217 | struct udevice **devp); |
| 218 | |
| 219 | /** |
Simon Glass | ee145d6 | 2017-05-18 20:09:09 -0600 | [diff] [blame] | 220 | * uclass_find_device_by_of_node() - Find a uclass device by device tree node |
| 221 | * |
| 222 | * This searches the devices in the uclass for one attached to the given |
| 223 | * device tree node. |
| 224 | * |
| 225 | * The device is NOT probed, it is merely returned. |
| 226 | * |
| 227 | * @id: ID to look up |
| 228 | * @node: Device tree offset to search for (if NULL then -ENODEV is returned) |
| 229 | * @devp: Returns pointer to device (there is only one for each node) |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 230 | * Return: 0 if OK, -ve on error |
Simon Glass | ee145d6 | 2017-05-18 20:09:09 -0600 | [diff] [blame] | 231 | */ |
| 232 | int uclass_find_device_by_ofnode(enum uclass_id id, ofnode node, |
| 233 | struct udevice **devp); |
| 234 | |
| 235 | /** |
Simon Glass | dc3efdc | 2018-11-18 08:14:30 -0700 | [diff] [blame] | 236 | * uclass_find_device_by_phandle() - Find a uclass device by phandle |
| 237 | * |
| 238 | * This searches the devices in the uclass for one with the given phandle. |
| 239 | * |
| 240 | * The device is NOT probed, it is merely returned. |
| 241 | * |
| 242 | * @id: ID to look up |
| 243 | * @parent: Parent device containing the phandle pointer |
| 244 | * @name: Name of property in the parent device node |
| 245 | * @devp: Returns pointer to device (there is only one for each node) |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 246 | * Return: 0 if OK, -ENOENT if there is no @name present in the node, other |
Simon Glass | dc3efdc | 2018-11-18 08:14:30 -0700 | [diff] [blame] | 247 | * -ve on error |
| 248 | */ |
| 249 | int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent, |
| 250 | const char *name, struct udevice **devp); |
| 251 | |
| 252 | /** |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 253 | * uclass_bind_device() - Associate device with a uclass |
| 254 | * |
| 255 | * Connect the device into uclass's list of devices. |
| 256 | * |
| 257 | * @dev: Pointer to the device |
Simon Glass | ebec3a7 | 2022-02-28 12:08:34 -0700 | [diff] [blame] | 258 | * Return: 0 on success, -ve on error |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 259 | */ |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 260 | int uclass_bind_device(struct udevice *dev); |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 261 | |
Simon Glass | ce15bfb | 2021-10-23 17:26:05 -0600 | [diff] [blame] | 262 | #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE) |
| 263 | /** |
| 264 | * uclass_pre_unbind_device() - Prepare to deassociate device with a uclass |
| 265 | * |
| 266 | * Call any handled needed before uclass_unbind_device() is called |
| 267 | * |
| 268 | * @dev: Pointer to the device |
Simon Glass | ebec3a7 | 2022-02-28 12:08:34 -0700 | [diff] [blame] | 269 | * Return: 0 on success, -ve on error |
Simon Glass | ce15bfb | 2021-10-23 17:26:05 -0600 | [diff] [blame] | 270 | */ |
| 271 | int uclass_pre_unbind_device(struct udevice *dev); |
| 272 | |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 273 | /** |
| 274 | * uclass_unbind_device() - Deassociate device with a uclass |
| 275 | * |
| 276 | * Disconnect the device from uclass's list of devices. |
| 277 | * |
| 278 | * @dev: Pointer to the device |
Simon Glass | ebec3a7 | 2022-02-28 12:08:34 -0700 | [diff] [blame] | 279 | * Return: 0 on success, -ve on error |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 280 | */ |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 281 | int uclass_unbind_device(struct udevice *dev); |
Simon Glass | ce15bfb | 2021-10-23 17:26:05 -0600 | [diff] [blame] | 282 | |
Simon Glass | 8914c8a | 2015-02-27 22:06:31 -0700 | [diff] [blame] | 283 | #else |
Simon Glass | ce15bfb | 2021-10-23 17:26:05 -0600 | [diff] [blame] | 284 | static inline int uclass_pre_unbind_device(struct udevice *dev) { return 0; } |
Simon Glass | 8914c8a | 2015-02-27 22:06:31 -0700 | [diff] [blame] | 285 | static inline int uclass_unbind_device(struct udevice *dev) { return 0; } |
| 286 | #endif |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 287 | |
| 288 | /** |
Simon Glass | 9c1f382 | 2015-03-05 12:25:22 -0700 | [diff] [blame] | 289 | * uclass_pre_probe_device() - Deal with a device that is about to be probed |
Simon Glass | 5104b98 | 2015-01-25 08:27:10 -0700 | [diff] [blame] | 290 | * |
| 291 | * Perform any pre-processing that is needed by the uclass before it can be |
Simon Glass | 9c1f382 | 2015-03-05 12:25:22 -0700 | [diff] [blame] | 292 | * probed. This includes the uclass' pre-probe() method and the parent |
| 293 | * uclass' child_pre_probe() method. |
Simon Glass | 5104b98 | 2015-01-25 08:27:10 -0700 | [diff] [blame] | 294 | * |
| 295 | * @dev: Pointer to the device |
Simon Glass | ebec3a7 | 2022-02-28 12:08:34 -0700 | [diff] [blame] | 296 | * Return: 0 on success, -ve on error |
Simon Glass | 5104b98 | 2015-01-25 08:27:10 -0700 | [diff] [blame] | 297 | */ |
Simon Glass | 9c1f382 | 2015-03-05 12:25:22 -0700 | [diff] [blame] | 298 | int uclass_pre_probe_device(struct udevice *dev); |
Simon Glass | 5104b98 | 2015-01-25 08:27:10 -0700 | [diff] [blame] | 299 | |
| 300 | /** |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 301 | * uclass_post_probe_device() - Deal with a device that has just been probed |
| 302 | * |
| 303 | * Perform any post-processing of a probed device that is needed by the |
| 304 | * uclass. |
| 305 | * |
| 306 | * @dev: Pointer to the device |
Simon Glass | ebec3a7 | 2022-02-28 12:08:34 -0700 | [diff] [blame] | 307 | * Return: 0 on success, -ve on error |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 308 | */ |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 309 | int uclass_post_probe_device(struct udevice *dev); |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 310 | |
| 311 | /** |
| 312 | * uclass_pre_remove_device() - Handle a device which is about to be removed |
| 313 | * |
| 314 | * Perform any pre-processing of a device that is about to be removed. |
| 315 | * |
| 316 | * @dev: Pointer to the device |
Simon Glass | ebec3a7 | 2022-02-28 12:08:34 -0700 | [diff] [blame] | 317 | * Return: 0 on success, -ve on error |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 318 | */ |
Masahiro Yamada | 04aa00d | 2015-08-12 07:31:52 +0900 | [diff] [blame] | 319 | #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE) |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 320 | int uclass_pre_remove_device(struct udevice *dev); |
Simon Glass | 8914c8a | 2015-02-27 22:06:31 -0700 | [diff] [blame] | 321 | #else |
| 322 | static inline int uclass_pre_remove_device(struct udevice *dev) { return 0; } |
| 323 | #endif |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 324 | |
| 325 | /** |
Simon Glass | 51608c9 | 2021-12-16 20:59:32 -0700 | [diff] [blame] | 326 | * uclass_get_count() - Get the number of uclasses |
| 327 | * |
| 328 | * Returns the number of uclasses instantiated in driver model |
| 329 | */ |
| 330 | int uclass_get_count(void); |
| 331 | |
| 332 | /** |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 333 | * uclass_find() - Find uclass by its id |
| 334 | * |
| 335 | * @id: Id to serach for |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 336 | * Return: pointer to uclass, or NULL if not found |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 337 | */ |
| 338 | struct uclass *uclass_find(enum uclass_id key); |
| 339 | |
| 340 | /** |
| 341 | * uclass_destroy() - Destroy a uclass |
| 342 | * |
| 343 | * Destroy a uclass and all its devices |
| 344 | * |
| 345 | * @uc: uclass to destroy |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 346 | * Return: 0 on success, -ve on error |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 347 | */ |
| 348 | int uclass_destroy(struct uclass *uc); |
| 349 | |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 350 | #endif |