Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | 6494d70 | 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 | 6494d70 | 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 | 40bb637 | 2017-05-18 20:09:09 -0600 | [diff] [blame] | 12 | #include <dm/ofnode.h> |
| 13 | |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 14 | /** |
Simon Glass | 8064739 | 2020-12-22 19:30:26 -0700 | [diff] [blame^] | 15 | * 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 | */ |
| 26 | void uclass_set_priv(struct uclass *uc, void *priv); |
| 27 | |
| 28 | /** |
Simon Glass | a133e21 | 2020-12-16 21:20:30 -0700 | [diff] [blame] | 29 | * uclass_find_next_free_seq() - Get the next free sequence number |
Jean-Jacques Hiblot | 3542ff2 | 2018-12-07 14:50:39 +0100 | [diff] [blame] | 30 | * |
Simon Glass | a133e21 | 2020-12-16 21:20:30 -0700 | [diff] [blame] | 31 | * 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 Hiblot | 3542ff2 | 2018-12-07 14:50:39 +0100 | [diff] [blame] | 38 | * |
Simon Glass | d03adb4 | 2020-12-16 21:20:08 -0700 | [diff] [blame] | 39 | * @uc: uclass to check |
Simon Glass | a133e21 | 2020-12-16 21:20:30 -0700 | [diff] [blame] | 40 | * @return The next free sequence number |
Jean-Jacques Hiblot | 3542ff2 | 2018-12-07 14:50:39 +0100 | [diff] [blame] | 41 | */ |
Simon Glass | a133e21 | 2020-12-16 21:20:30 -0700 | [diff] [blame] | 42 | int uclass_find_next_free_seq(struct uclass *uc); |
Jean-Jacques Hiblot | 3542ff2 | 2018-12-07 14:50:39 +0100 | [diff] [blame] | 43 | |
| 44 | /** |
Przemyslaw Marczak | 794d521 | 2015-04-20 13:32:32 +0200 | [diff] [blame] | 45 | * 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 | */ |
| 54 | int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp); |
| 55 | |
| 56 | /** |
Jean-Jacques Hiblot | e7c8656 | 2018-08-09 16:17:42 +0200 | [diff] [blame] | 57 | * 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 | */ |
| 65 | int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp); |
| 66 | |
| 67 | /** |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 68 | * 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 Marczak | 794d521 | 2015-04-20 13:32:32 +0200 | [diff] [blame] | 73 | * 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 Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 75 | * |
| 76 | * @return the uclass pointer of a child at the given index or |
| 77 | * return NULL on error. |
| 78 | */ |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 79 | int uclass_find_device(enum uclass_id id, int index, struct udevice **devp); |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 80 | |
| 81 | /** |
Przemyslaw Marczak | c1d6f91 | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 82 | * 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 Marczak | 794d521 | 2015-04-20 13:32:32 +0200 | [diff] [blame] | 86 | * 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 Marczak | c1d6f91 | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 88 | * |
Simon Glass | 4805a7a | 2019-09-25 08:55:55 -0600 | [diff] [blame] | 89 | * @return 0 if OK (found or not found), -ve on error |
Przemyslaw Marczak | c1d6f91 | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 90 | */ |
| 91 | int 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 Marczak | 794d521 | 2015-04-20 13:32:32 +0200 | [diff] [blame] | 98 | * 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 Marczak | c1d6f91 | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 100 | * |
Simon Glass | 4805a7a | 2019-09-25 08:55:55 -0600 | [diff] [blame] | 101 | * @return 0 if OK (found or not found), -ve on error |
Przemyslaw Marczak | c1d6f91 | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 102 | */ |
| 103 | int uclass_find_next_device(struct udevice **devp); |
| 104 | |
| 105 | /** |
Przemyslaw Marczak | e0735a4 | 2015-04-15 13:07:22 +0200 | [diff] [blame] | 106 | * uclass_find_device_by_name() - Find uclass device based on ID and name |
| 107 | * |
Przemyslaw Marczak | a7b8250 | 2015-04-20 13:32:34 +0200 | [diff] [blame] | 108 | * This searches for a device with the exactly given name. |
Przemyslaw Marczak | e0735a4 | 2015-04-15 13:07:22 +0200 | [diff] [blame] | 109 | * |
| 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 | */ |
| 117 | int 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 Glass | 9917591 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 123 | * This searches for a device with the given seq. |
Przemyslaw Marczak | e0735a4 | 2015-04-15 13:07:22 +0200 | [diff] [blame] | 124 | * |
| 125 | * The device is NOT probed, it is merely returned. |
| 126 | * |
| 127 | * @id: ID to look up |
Simon Glass | 9917591 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 128 | * @seq: Sequence number to find (0=first) |
Przemyslaw Marczak | e0735a4 | 2015-04-15 13:07:22 +0200 | [diff] [blame] | 129 | * @devp: Returns pointer to device (there is only one per for each seq) |
Simon Glass | 9917591 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 130 | * @return 0 if OK, -ENODEV if not found |
Przemyslaw Marczak | e0735a4 | 2015-04-15 13:07:22 +0200 | [diff] [blame] | 131 | */ |
Simon Glass | 9917591 | 2020-12-16 21:20:29 -0700 | [diff] [blame] | 132 | int uclass_find_device_by_seq(enum uclass_id id, int seq, |
| 133 | struct udevice **devp); |
Przemyslaw Marczak | e0735a4 | 2015-04-15 13:07:22 +0200 | [diff] [blame] | 134 | |
| 135 | /** |
Simon Glass | 1b30d61 | 2016-01-21 19:43:57 -0700 | [diff] [blame] | 136 | * 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 | */ |
| 148 | int uclass_find_device_by_of_offset(enum uclass_id id, int node, |
| 149 | struct udevice **devp); |
| 150 | |
| 151 | /** |
Simon Glass | 40bb637 | 2017-05-18 20:09:09 -0600 | [diff] [blame] | 152 | * 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 | */ |
| 164 | int uclass_find_device_by_ofnode(enum uclass_id id, ofnode node, |
| 165 | struct udevice **devp); |
| 166 | |
| 167 | /** |
Simon Glass | d0b4f68 | 2018-11-18 08:14:30 -0700 | [diff] [blame] | 168 | * 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 | */ |
| 181 | int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent, |
| 182 | const char *name, struct udevice **devp); |
| 183 | |
| 184 | /** |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 185 | * 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 Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 192 | int uclass_bind_device(struct udevice *dev); |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 193 | |
| 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 Yamada | 0a5804b | 2015-08-12 07:31:52 +0900 | [diff] [blame] | 202 | #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE) |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 203 | int uclass_unbind_device(struct udevice *dev); |
Simon Glass | 7f9875e | 2015-02-27 22:06:31 -0700 | [diff] [blame] | 204 | #else |
| 205 | static inline int uclass_unbind_device(struct udevice *dev) { return 0; } |
| 206 | #endif |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 207 | |
| 208 | /** |
Simon Glass | 02c07b3 | 2015-03-05 12:25:22 -0700 | [diff] [blame] | 209 | * uclass_pre_probe_device() - Deal with a device that is about to be probed |
Simon Glass | 83c7e43 | 2015-01-25 08:27:10 -0700 | [diff] [blame] | 210 | * |
| 211 | * Perform any pre-processing that is needed by the uclass before it can be |
Simon Glass | 02c07b3 | 2015-03-05 12:25:22 -0700 | [diff] [blame] | 212 | * probed. This includes the uclass' pre-probe() method and the parent |
| 213 | * uclass' child_pre_probe() method. |
Simon Glass | 83c7e43 | 2015-01-25 08:27:10 -0700 | [diff] [blame] | 214 | * |
| 215 | * @dev: Pointer to the device |
| 216 | * #return 0 on success, -ve on error |
| 217 | */ |
Simon Glass | 02c07b3 | 2015-03-05 12:25:22 -0700 | [diff] [blame] | 218 | int uclass_pre_probe_device(struct udevice *dev); |
Simon Glass | 83c7e43 | 2015-01-25 08:27:10 -0700 | [diff] [blame] | 219 | |
| 220 | /** |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 221 | * 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 Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 229 | int uclass_post_probe_device(struct udevice *dev); |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 230 | |
| 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 Yamada | 0a5804b | 2015-08-12 07:31:52 +0900 | [diff] [blame] | 239 | #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE) |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 240 | int uclass_pre_remove_device(struct udevice *dev); |
Simon Glass | 7f9875e | 2015-02-27 22:06:31 -0700 | [diff] [blame] | 241 | #else |
| 242 | static inline int uclass_pre_remove_device(struct udevice *dev) { return 0; } |
| 243 | #endif |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 244 | |
| 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 | */ |
| 251 | struct 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 | */ |
| 261 | int uclass_destroy(struct uclass *uc); |
| 262 | |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 263 | #endif |