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