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 | /** |
Jean-Jacques Hiblot | 3542ff2 | 2018-12-07 14:50:39 +0100 | [diff] [blame] | 15 | * uclass_find_next_free_req_seq() - Get the next free req_seq number |
| 16 | * |
| 17 | * This returns the next free req_seq number. This is useful only if |
| 18 | * OF_CONTROL is not used. The next free req_seq number is simply the |
| 19 | * maximum req_seq of the uclass + 1. |
| 20 | * This allows assiging req_seq number in the binding order. |
| 21 | * |
Simon Glass | d03adb4 | 2020-12-16 21:20:08 -0700 | [diff] [blame^] | 22 | * @uc: uclass to check |
Jean-Jacques Hiblot | 3542ff2 | 2018-12-07 14:50:39 +0100 | [diff] [blame] | 23 | * @return The next free req_seq number |
| 24 | */ |
Simon Glass | d03adb4 | 2020-12-16 21:20:08 -0700 | [diff] [blame^] | 25 | int uclass_find_next_free_req_seq(struct uclass *uc); |
Jean-Jacques Hiblot | 3542ff2 | 2018-12-07 14:50:39 +0100 | [diff] [blame] | 26 | |
| 27 | /** |
Przemyslaw Marczak | 794d521 | 2015-04-20 13:32:32 +0200 | [diff] [blame] | 28 | * uclass_get_device_tail() - handle the end of a get_device call |
| 29 | * |
| 30 | * This handles returning an error or probing a device as needed. |
| 31 | * |
| 32 | * @dev: Device that needs to be probed |
| 33 | * @ret: Error to return. If non-zero then the device is not probed |
| 34 | * @devp: Returns the value of 'dev' if there is no error |
| 35 | * @return ret, if non-zero, else the result of the device_probe() call |
| 36 | */ |
| 37 | int uclass_get_device_tail(struct udevice *dev, int ret, struct udevice **devp); |
| 38 | |
| 39 | /** |
Jean-Jacques Hiblot | e7c8656 | 2018-08-09 16:17:42 +0200 | [diff] [blame] | 40 | * dev_get_uclass_index() - Get uclass and index of device |
| 41 | * @dev: - in - Device that we want the uclass/index of |
| 42 | * @ucp: - out - A pointer to the uclass the device belongs to |
| 43 | * |
| 44 | * The device is not prepared for use - this is an internal function. |
| 45 | * |
| 46 | * @return the index of the device in the uclass list or -ENODEV if not found. |
| 47 | */ |
| 48 | int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp); |
| 49 | |
| 50 | /** |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 51 | * uclass_find_device() - Return n-th child of uclass |
| 52 | * @id: Id number of the uclass |
| 53 | * @index: Position of the child in uclass's list |
| 54 | * #devp: Returns pointer to device, or NULL on error |
| 55 | * |
Przemyslaw Marczak | 794d521 | 2015-04-20 13:32:32 +0200 | [diff] [blame] | 56 | * The device is not prepared for use - this is an internal function. |
| 57 | * 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] | 58 | * |
| 59 | * @return the uclass pointer of a child at the given index or |
| 60 | * return NULL on error. |
| 61 | */ |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 62 | 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] | 63 | |
| 64 | /** |
Przemyslaw Marczak | c1d6f91 | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 65 | * uclass_find_first_device() - Return the first device in a uclass |
| 66 | * @id: Id number of the uclass |
| 67 | * #devp: Returns pointer to device, or NULL on error |
| 68 | * |
Przemyslaw Marczak | 794d521 | 2015-04-20 13:32:32 +0200 | [diff] [blame] | 69 | * The device is not prepared for use - this is an internal function. |
| 70 | * 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] | 71 | * |
Simon Glass | 4805a7a | 2019-09-25 08:55:55 -0600 | [diff] [blame] | 72 | * @return 0 if OK (found or not found), -ve on error |
Przemyslaw Marczak | c1d6f91 | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 73 | */ |
| 74 | int uclass_find_first_device(enum uclass_id id, struct udevice **devp); |
| 75 | |
| 76 | /** |
| 77 | * uclass_find_next_device() - Return the next device in a uclass |
| 78 | * @devp: On entry, pointer to device to lookup. On exit, returns pointer |
| 79 | * to the next device in the same uclass, or NULL if none |
| 80 | * |
Przemyslaw Marczak | 794d521 | 2015-04-20 13:32:32 +0200 | [diff] [blame] | 81 | * The device is not prepared for use - this is an internal function. |
| 82 | * 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] | 83 | * |
Simon Glass | 4805a7a | 2019-09-25 08:55:55 -0600 | [diff] [blame] | 84 | * @return 0 if OK (found or not found), -ve on error |
Przemyslaw Marczak | c1d6f91 | 2015-04-15 13:07:17 +0200 | [diff] [blame] | 85 | */ |
| 86 | int uclass_find_next_device(struct udevice **devp); |
| 87 | |
| 88 | /** |
Przemyslaw Marczak | e0735a4 | 2015-04-15 13:07:22 +0200 | [diff] [blame] | 89 | * uclass_find_device_by_name() - Find uclass device based on ID and name |
| 90 | * |
Przemyslaw Marczak | a7b8250 | 2015-04-20 13:32:34 +0200 | [diff] [blame] | 91 | * This searches for a device with the exactly given name. |
Przemyslaw Marczak | e0735a4 | 2015-04-15 13:07:22 +0200 | [diff] [blame] | 92 | * |
| 93 | * The device is NOT probed, it is merely returned. |
| 94 | * |
| 95 | * @id: ID to look up |
| 96 | * @name: name of a device to find |
| 97 | * @devp: Returns pointer to device (the first one with the name) |
| 98 | * @return 0 if OK, -ve on error |
| 99 | */ |
| 100 | int uclass_find_device_by_name(enum uclass_id id, const char *name, |
| 101 | struct udevice **devp); |
| 102 | |
| 103 | /** |
| 104 | * uclass_find_device_by_seq() - Find uclass device based on ID and sequence |
| 105 | * |
| 106 | * This searches for a device with the given seq or req_seq. |
| 107 | * |
| 108 | * For seq, if an active device has this sequence it will be returned. |
| 109 | * If there is no such device then this will return -ENODEV. |
| 110 | * |
| 111 | * For req_seq, if a device (whether activated or not) has this req_seq |
| 112 | * value, that device will be returned. This is a strong indication that |
| 113 | * the device will receive that sequence when activated. |
| 114 | * |
| 115 | * The device is NOT probed, it is merely returned. |
| 116 | * |
| 117 | * @id: ID to look up |
| 118 | * @seq_or_req_seq: Sequence number to find (0=first) |
| 119 | * @find_req_seq: true to find req_seq, false to find seq |
| 120 | * @devp: Returns pointer to device (there is only one per for each seq) |
| 121 | * @return 0 if OK, -ve on error |
| 122 | */ |
| 123 | int uclass_find_device_by_seq(enum uclass_id id, int seq_or_req_seq, |
| 124 | bool find_req_seq, struct udevice **devp); |
| 125 | |
| 126 | /** |
Simon Glass | 1b30d61 | 2016-01-21 19:43:57 -0700 | [diff] [blame] | 127 | * uclass_find_device_by_of_offset() - Find a uclass device by device tree node |
| 128 | * |
| 129 | * This searches the devices in the uclass for one attached to the given |
| 130 | * device tree node. |
| 131 | * |
| 132 | * The device is NOT probed, it is merely returned. |
| 133 | * |
| 134 | * @id: ID to look up |
| 135 | * @node: Device tree offset to search for (if -ve then -ENODEV is returned) |
| 136 | * @devp: Returns pointer to device (there is only one for each node) |
| 137 | * @return 0 if OK, -ve on error |
| 138 | */ |
| 139 | int uclass_find_device_by_of_offset(enum uclass_id id, int node, |
| 140 | struct udevice **devp); |
| 141 | |
| 142 | /** |
Simon Glass | 40bb637 | 2017-05-18 20:09:09 -0600 | [diff] [blame] | 143 | * uclass_find_device_by_of_node() - Find a uclass device by device tree node |
| 144 | * |
| 145 | * This searches the devices in the uclass for one attached to the given |
| 146 | * device tree node. |
| 147 | * |
| 148 | * The device is NOT probed, it is merely returned. |
| 149 | * |
| 150 | * @id: ID to look up |
| 151 | * @node: Device tree offset to search for (if NULL then -ENODEV is returned) |
| 152 | * @devp: Returns pointer to device (there is only one for each node) |
| 153 | * @return 0 if OK, -ve on error |
| 154 | */ |
| 155 | int uclass_find_device_by_ofnode(enum uclass_id id, ofnode node, |
| 156 | struct udevice **devp); |
| 157 | |
| 158 | /** |
Simon Glass | d0b4f68 | 2018-11-18 08:14:30 -0700 | [diff] [blame] | 159 | * uclass_find_device_by_phandle() - Find a uclass device by phandle |
| 160 | * |
| 161 | * This searches the devices in the uclass for one with the given phandle. |
| 162 | * |
| 163 | * The device is NOT probed, it is merely returned. |
| 164 | * |
| 165 | * @id: ID to look up |
| 166 | * @parent: Parent device containing the phandle pointer |
| 167 | * @name: Name of property in the parent device node |
| 168 | * @devp: Returns pointer to device (there is only one for each node) |
| 169 | * @return 0 if OK, -ENOENT if there is no @name present in the node, other |
| 170 | * -ve on error |
| 171 | */ |
| 172 | int uclass_find_device_by_phandle(enum uclass_id id, struct udevice *parent, |
| 173 | const char *name, struct udevice **devp); |
| 174 | |
| 175 | /** |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 176 | * uclass_bind_device() - Associate device with a uclass |
| 177 | * |
| 178 | * Connect the device into uclass's list of devices. |
| 179 | * |
| 180 | * @dev: Pointer to the device |
| 181 | * #return 0 on success, -ve on error |
| 182 | */ |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 183 | int uclass_bind_device(struct udevice *dev); |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 184 | |
| 185 | /** |
| 186 | * uclass_unbind_device() - Deassociate device with a uclass |
| 187 | * |
| 188 | * Disconnect the device from uclass's list of devices. |
| 189 | * |
| 190 | * @dev: Pointer to the device |
| 191 | * #return 0 on success, -ve on error |
| 192 | */ |
Masahiro Yamada | 0a5804b | 2015-08-12 07:31:52 +0900 | [diff] [blame] | 193 | #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE) |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 194 | int uclass_unbind_device(struct udevice *dev); |
Simon Glass | 7f9875e | 2015-02-27 22:06:31 -0700 | [diff] [blame] | 195 | #else |
| 196 | static inline int uclass_unbind_device(struct udevice *dev) { return 0; } |
| 197 | #endif |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 198 | |
| 199 | /** |
Simon Glass | 02c07b3 | 2015-03-05 12:25:22 -0700 | [diff] [blame] | 200 | * 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] | 201 | * |
| 202 | * 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] | 203 | * probed. This includes the uclass' pre-probe() method and the parent |
| 204 | * uclass' child_pre_probe() method. |
Simon Glass | 83c7e43 | 2015-01-25 08:27:10 -0700 | [diff] [blame] | 205 | * |
| 206 | * @dev: Pointer to the device |
| 207 | * #return 0 on success, -ve on error |
| 208 | */ |
Simon Glass | 02c07b3 | 2015-03-05 12:25:22 -0700 | [diff] [blame] | 209 | int uclass_pre_probe_device(struct udevice *dev); |
Simon Glass | 83c7e43 | 2015-01-25 08:27:10 -0700 | [diff] [blame] | 210 | |
| 211 | /** |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 212 | * uclass_post_probe_device() - Deal with a device that has just been probed |
| 213 | * |
| 214 | * Perform any post-processing of a probed device that is needed by the |
| 215 | * uclass. |
| 216 | * |
| 217 | * @dev: Pointer to the device |
| 218 | * #return 0 on success, -ve on error |
| 219 | */ |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 220 | int uclass_post_probe_device(struct udevice *dev); |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 221 | |
| 222 | /** |
| 223 | * uclass_pre_remove_device() - Handle a device which is about to be removed |
| 224 | * |
| 225 | * Perform any pre-processing of a device that is about to be removed. |
| 226 | * |
| 227 | * @dev: Pointer to the device |
| 228 | * #return 0 on success, -ve on error |
| 229 | */ |
Masahiro Yamada | 0a5804b | 2015-08-12 07:31:52 +0900 | [diff] [blame] | 230 | #if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE) |
Heiko Schocher | 54c5d08 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 231 | int uclass_pre_remove_device(struct udevice *dev); |
Simon Glass | 7f9875e | 2015-02-27 22:06:31 -0700 | [diff] [blame] | 232 | #else |
| 233 | static inline int uclass_pre_remove_device(struct udevice *dev) { return 0; } |
| 234 | #endif |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 235 | |
| 236 | /** |
| 237 | * uclass_find() - Find uclass by its id |
| 238 | * |
| 239 | * @id: Id to serach for |
| 240 | * @return pointer to uclass, or NULL if not found |
| 241 | */ |
| 242 | struct uclass *uclass_find(enum uclass_id key); |
| 243 | |
| 244 | /** |
| 245 | * uclass_destroy() - Destroy a uclass |
| 246 | * |
| 247 | * Destroy a uclass and all its devices |
| 248 | * |
| 249 | * @uc: uclass to destroy |
| 250 | * @return 0 on success, -ve on error |
| 251 | */ |
| 252 | int uclass_destroy(struct uclass *uc); |
| 253 | |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 254 | #endif |