Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 Google, Inc |
| 3 | * |
| 4 | * (C) Copyright 2012 |
| 5 | * Pavel Herrmann <morpheus.ibis@gmail.com> |
| 6 | * Marek Vasut <marex@denx.de> |
| 7 | * |
| 8 | * SPDX-License-Identifier: GPL-2.0+ |
| 9 | */ |
| 10 | |
| 11 | #ifndef _DM_DEVICE_H |
| 12 | #define _DM_DEVICE_H |
| 13 | |
| 14 | #include <dm/uclass-id.h> |
Peng Fan | 99b7235 | 2015-02-10 14:46:32 +0800 | [diff] [blame] | 15 | #include <fdtdec.h> |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 16 | #include <linker_lists.h> |
| 17 | #include <linux/list.h> |
| 18 | |
| 19 | struct driver_info; |
| 20 | |
| 21 | /* Driver is active (probed). Cleared when it is removed */ |
| 22 | #define DM_FLAG_ACTIVATED (1 << 0) |
| 23 | |
| 24 | /* DM is responsible for allocating and freeing platdata */ |
Simon Glass | 4dbb5cf | 2014-06-11 23:29:54 -0600 | [diff] [blame] | 25 | #define DM_FLAG_ALLOC_PDATA (1 << 1) |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 26 | |
Simon Glass | fef72b7 | 2014-07-23 06:55:03 -0600 | [diff] [blame] | 27 | /* DM should init this device prior to relocation */ |
| 28 | #define DM_FLAG_PRE_RELOC (1 << 2) |
| 29 | |
Simon Glass | 11b6173 | 2015-01-25 08:27:01 -0700 | [diff] [blame] | 30 | /* DM is responsible for allocating and freeing parent_platdata */ |
| 31 | #define DM_FLAG_ALLOC_PARENT_PDATA (1 << 3) |
| 32 | |
Przemyslaw Marczak | d850e67 | 2015-04-15 13:07:18 +0200 | [diff] [blame] | 33 | /* DM is responsible for allocating and freeing uclass_platdata */ |
| 34 | #define DM_FLAG_ALLOC_UCLASS_PDATA (1 << 4) |
| 35 | |
Simon Glass | 825d3f9 | 2015-03-25 12:21:53 -0600 | [diff] [blame] | 36 | /* Allocate driver private data on a DMA boundary */ |
Przemyslaw Marczak | d850e67 | 2015-04-15 13:07:18 +0200 | [diff] [blame] | 37 | #define DM_FLAG_ALLOC_PRIV_DMA (1 << 5) |
Simon Glass | 825d3f9 | 2015-03-25 12:21:53 -0600 | [diff] [blame] | 38 | |
Masahiro Yamada | bdbb5dd | 2015-07-25 21:52:34 +0900 | [diff] [blame^] | 39 | /* Device is bound */ |
| 40 | #define DM_FLAG_BOUND (1 << 6) |
| 41 | |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 42 | /** |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 43 | * struct udevice - An instance of a driver |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 44 | * |
| 45 | * This holds information about a device, which is a driver bound to a |
| 46 | * particular port or peripheral (essentially a driver instance). |
| 47 | * |
| 48 | * A device will come into existence through a 'bind' call, either due to |
| 49 | * a U_BOOT_DEVICE() macro (in which case platdata is non-NULL) or a node |
| 50 | * in the device tree (in which case of_offset is >= 0). In the latter case |
| 51 | * we translate the device tree information into platdata in a function |
| 52 | * implemented by the driver ofdata_to_platdata method (called just before the |
| 53 | * probe method if the device has a device tree node. |
| 54 | * |
| 55 | * All three of platdata, priv and uclass_priv can be allocated by the |
| 56 | * driver, or you can use the auto_alloc_size members of struct driver and |
| 57 | * struct uclass_driver to have driver model do this automatically. |
| 58 | * |
| 59 | * @driver: The driver used by this device |
| 60 | * @name: Name of device, typically the FDT node name |
| 61 | * @platdata: Configuration data for this device |
Simon Glass | 11b6173 | 2015-01-25 08:27:01 -0700 | [diff] [blame] | 62 | * @parent_platdata: The parent bus's configuration data for this device |
Przemyslaw Marczak | d850e67 | 2015-04-15 13:07:18 +0200 | [diff] [blame] | 63 | * @uclass_platdata: The uclass's configuration data for this device |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 64 | * @of_offset: Device tree node offset for this device (- for none) |
Simon Glass | 46227bd | 2015-03-25 12:21:55 -0600 | [diff] [blame] | 65 | * @driver_data: Driver data word for the entry that matched this device with |
| 66 | * its driver |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 67 | * @parent: Parent of this device, or NULL for the top level device |
| 68 | * @priv: Private data for this device |
| 69 | * @uclass: Pointer to uclass for this device |
| 70 | * @uclass_priv: The uclass's private data for this device |
Simon Glass | 60d971b | 2014-07-23 06:55:20 -0600 | [diff] [blame] | 71 | * @parent_priv: The parent's private data for this device |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 72 | * @uclass_node: Used by uclass to link its devices |
| 73 | * @child_head: List of children of this device |
| 74 | * @sibling_node: Next device in list of all devices |
| 75 | * @flags: Flags for this device DM_FLAG_... |
Simon Glass | db6f020 | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 76 | * @req_seq: Requested sequence number for this device (-1 = any) |
Simon Glass | 47424ec | 2014-10-13 23:41:51 -0600 | [diff] [blame] | 77 | * @seq: Allocated sequence number for this device (-1 = none). This is set up |
| 78 | * when the device is probed and will be unique within the device's uclass. |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 79 | */ |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 80 | struct udevice { |
Simon Glass | a626dff | 2015-03-25 12:21:54 -0600 | [diff] [blame] | 81 | const struct driver *driver; |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 82 | const char *name; |
| 83 | void *platdata; |
Simon Glass | 11b6173 | 2015-01-25 08:27:01 -0700 | [diff] [blame] | 84 | void *parent_platdata; |
Przemyslaw Marczak | d850e67 | 2015-04-15 13:07:18 +0200 | [diff] [blame] | 85 | void *uclass_platdata; |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 86 | int of_offset; |
Simon Glass | 46227bd | 2015-03-25 12:21:55 -0600 | [diff] [blame] | 87 | ulong driver_data; |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 88 | struct udevice *parent; |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 89 | void *priv; |
| 90 | struct uclass *uclass; |
| 91 | void *uclass_priv; |
Simon Glass | 60d971b | 2014-07-23 06:55:20 -0600 | [diff] [blame] | 92 | void *parent_priv; |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 93 | struct list_head uclass_node; |
| 94 | struct list_head child_head; |
| 95 | struct list_head sibling_node; |
| 96 | uint32_t flags; |
Simon Glass | db6f020 | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 97 | int req_seq; |
| 98 | int seq; |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
Simon Glass | db6f020 | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 101 | /* Maximum sequence number supported */ |
| 102 | #define DM_MAX_SEQ 999 |
| 103 | |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 104 | /* Returns the operations for a device */ |
| 105 | #define device_get_ops(dev) (dev->driver->ops) |
| 106 | |
| 107 | /* Returns non-zero if the device is active (probed and not removed) */ |
| 108 | #define device_active(dev) ((dev)->flags & DM_FLAG_ACTIVATED) |
| 109 | |
| 110 | /** |
Simon Glass | 767827a | 2014-06-11 23:29:45 -0600 | [diff] [blame] | 111 | * struct udevice_id - Lists the compatible strings supported by a driver |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 112 | * @compatible: Compatible string |
| 113 | * @data: Data for this compatible string |
| 114 | */ |
Simon Glass | 767827a | 2014-06-11 23:29:45 -0600 | [diff] [blame] | 115 | struct udevice_id { |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 116 | const char *compatible; |
| 117 | ulong data; |
| 118 | }; |
| 119 | |
Masahiro Yamada | f797bc2 | 2014-10-07 14:51:31 +0900 | [diff] [blame] | 120 | #ifdef CONFIG_OF_CONTROL |
| 121 | #define of_match_ptr(_ptr) (_ptr) |
| 122 | #else |
| 123 | #define of_match_ptr(_ptr) NULL |
| 124 | #endif /* CONFIG_OF_CONTROL */ |
| 125 | |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 126 | /** |
| 127 | * struct driver - A driver for a feature or peripheral |
| 128 | * |
| 129 | * This holds methods for setting up a new device, and also removing it. |
| 130 | * The device needs information to set itself up - this is provided either |
| 131 | * by platdata or a device tree node (which we find by looking up |
| 132 | * matching compatible strings with of_match). |
| 133 | * |
| 134 | * Drivers all belong to a uclass, representing a class of devices of the |
| 135 | * same type. Common elements of the drivers can be implemented in the uclass, |
| 136 | * or the uclass can provide a consistent interface to the drivers within |
| 137 | * it. |
| 138 | * |
| 139 | * @name: Device name |
| 140 | * @id: Identiies the uclass we belong to |
| 141 | * @of_match: List of compatible strings to match, and any identifying data |
| 142 | * for each. |
| 143 | * @bind: Called to bind a device to its driver |
| 144 | * @probe: Called to probe a device, i.e. activate it |
| 145 | * @remove: Called to remove a device, i.e. de-activate it |
| 146 | * @unbind: Called to unbind a device from its driver |
| 147 | * @ofdata_to_platdata: Called before probe to decode device tree data |
Simon Glass | a4a51a0 | 2015-01-25 08:27:03 -0700 | [diff] [blame] | 148 | * @child_post_bind: Called after a new child has been bound |
Simon Glass | d45560d | 2014-07-23 06:55:21 -0600 | [diff] [blame] | 149 | * @child_pre_probe: Called before a child device is probed. The device has |
| 150 | * memory allocated but it has not yet been probed. |
| 151 | * @child_post_remove: Called after a child device is removed. The device |
| 152 | * has memory allocated but its device_remove() method has been called. |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 153 | * @priv_auto_alloc_size: If non-zero this is the size of the private data |
| 154 | * to be allocated in the device's ->priv pointer. If zero, then the driver |
| 155 | * is responsible for allocating any data required. |
| 156 | * @platdata_auto_alloc_size: If non-zero this is the size of the |
| 157 | * platform data to be allocated in the device's ->platdata pointer. |
| 158 | * This is typically only useful for device-tree-aware drivers (those with |
| 159 | * an of_match), since drivers which use platdata will have the data |
| 160 | * provided in the U_BOOT_DEVICE() instantiation. |
Simon Glass | 60d971b | 2014-07-23 06:55:20 -0600 | [diff] [blame] | 161 | * @per_child_auto_alloc_size: Each device can hold private data owned by |
| 162 | * its parent. If required this will be automatically allocated if this |
| 163 | * value is non-zero. |
Simon Glass | 1586a84 | 2014-10-13 23:41:50 -0600 | [diff] [blame] | 164 | * TODO(sjg@chromium.org): I'm considering dropping this, and just having |
| 165 | * device_probe_child() pass it in. So far the use case for allocating it |
| 166 | * is SPI, but I found that unsatisfactory. Since it is here I will leave it |
| 167 | * until things are clearer. |
Simon Glass | 11b6173 | 2015-01-25 08:27:01 -0700 | [diff] [blame] | 168 | * @per_child_platdata_auto_alloc_size: A bus likes to store information about |
| 169 | * its children. If non-zero this is the size of this data, to be allocated |
| 170 | * in the child's parent_platdata pointer. |
Simon Glass | cebcebb | 2014-07-23 06:55:17 -0600 | [diff] [blame] | 171 | * @ops: Driver-specific operations. This is typically a list of function |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 172 | * pointers defined by the driver, to implement driver functions required by |
| 173 | * the uclass. |
Simon Glass | fef72b7 | 2014-07-23 06:55:03 -0600 | [diff] [blame] | 174 | * @flags: driver flags - see DM_FLAGS_... |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 175 | */ |
| 176 | struct driver { |
| 177 | char *name; |
| 178 | enum uclass_id id; |
Simon Glass | 767827a | 2014-06-11 23:29:45 -0600 | [diff] [blame] | 179 | const struct udevice_id *of_match; |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 180 | int (*bind)(struct udevice *dev); |
| 181 | int (*probe)(struct udevice *dev); |
| 182 | int (*remove)(struct udevice *dev); |
| 183 | int (*unbind)(struct udevice *dev); |
| 184 | int (*ofdata_to_platdata)(struct udevice *dev); |
Simon Glass | a4a51a0 | 2015-01-25 08:27:03 -0700 | [diff] [blame] | 185 | int (*child_post_bind)(struct udevice *dev); |
Simon Glass | d45560d | 2014-07-23 06:55:21 -0600 | [diff] [blame] | 186 | int (*child_pre_probe)(struct udevice *dev); |
| 187 | int (*child_post_remove)(struct udevice *dev); |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 188 | int priv_auto_alloc_size; |
| 189 | int platdata_auto_alloc_size; |
Simon Glass | 60d971b | 2014-07-23 06:55:20 -0600 | [diff] [blame] | 190 | int per_child_auto_alloc_size; |
Simon Glass | 11b6173 | 2015-01-25 08:27:01 -0700 | [diff] [blame] | 191 | int per_child_platdata_auto_alloc_size; |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 192 | const void *ops; /* driver-specific operations */ |
Simon Glass | fef72b7 | 2014-07-23 06:55:03 -0600 | [diff] [blame] | 193 | uint32_t flags; |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 194 | }; |
| 195 | |
| 196 | /* Declare a new U-Boot driver */ |
| 197 | #define U_BOOT_DRIVER(__name) \ |
| 198 | ll_entry_declare(struct driver, __name, driver) |
| 199 | |
| 200 | /** |
| 201 | * dev_get_platdata() - Get the platform data for a device |
| 202 | * |
| 203 | * This checks that dev is not NULL, but no other checks for now |
| 204 | * |
| 205 | * @dev Device to check |
| 206 | * @return platform data, or NULL if none |
| 207 | */ |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 208 | void *dev_get_platdata(struct udevice *dev); |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 209 | |
| 210 | /** |
Simon Glass | 11b6173 | 2015-01-25 08:27:01 -0700 | [diff] [blame] | 211 | * dev_get_parent_platdata() - Get the parent platform data for a device |
| 212 | * |
| 213 | * This checks that dev is not NULL, but no other checks for now |
| 214 | * |
| 215 | * @dev Device to check |
| 216 | * @return parent's platform data, or NULL if none |
| 217 | */ |
| 218 | void *dev_get_parent_platdata(struct udevice *dev); |
| 219 | |
| 220 | /** |
Przemyslaw Marczak | d850e67 | 2015-04-15 13:07:18 +0200 | [diff] [blame] | 221 | * dev_get_uclass_platdata() - Get the uclass platform data for a device |
| 222 | * |
| 223 | * This checks that dev is not NULL, but no other checks for now |
| 224 | * |
| 225 | * @dev Device to check |
| 226 | * @return uclass's platform data, or NULL if none |
| 227 | */ |
| 228 | void *dev_get_uclass_platdata(struct udevice *dev); |
| 229 | |
| 230 | /** |
Simon Glass | 60d971b | 2014-07-23 06:55:20 -0600 | [diff] [blame] | 231 | * dev_get_parentdata() - Get the parent data for a device |
| 232 | * |
| 233 | * The parent data is data stored in the device but owned by the parent. |
| 234 | * For example, a USB device may have parent data which contains information |
| 235 | * about how to talk to the device over USB. |
| 236 | * |
| 237 | * This checks that dev is not NULL, but no other checks for now |
| 238 | * |
| 239 | * @dev Device to check |
| 240 | * @return parent data, or NULL if none |
| 241 | */ |
| 242 | void *dev_get_parentdata(struct udevice *dev); |
| 243 | |
| 244 | /** |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 245 | * dev_get_priv() - Get the private data for a device |
| 246 | * |
| 247 | * This checks that dev is not NULL, but no other checks for now |
| 248 | * |
| 249 | * @dev Device to check |
| 250 | * @return private data, or NULL if none |
| 251 | */ |
Heiko Schocher | b74fcb4 | 2014-05-22 12:43:05 +0200 | [diff] [blame] | 252 | void *dev_get_priv(struct udevice *dev); |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 253 | |
Simon Glass | db6f020 | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 254 | /** |
Simon Glass | 43f488a | 2014-11-11 10:46:19 -0700 | [diff] [blame] | 255 | * struct dev_get_parent() - Get the parent of a device |
| 256 | * |
| 257 | * @child: Child to check |
| 258 | * @return parent of child, or NULL if this is the root device |
| 259 | */ |
| 260 | struct udevice *dev_get_parent(struct udevice *child); |
| 261 | |
| 262 | /** |
Simon Glass | de0977b | 2015-03-05 12:25:20 -0700 | [diff] [blame] | 263 | * dev_get_uclass_priv() - Get the private uclass data for a device |
| 264 | * |
| 265 | * This checks that dev is not NULL, but no other checks for now |
| 266 | * |
| 267 | * @dev Device to check |
| 268 | * @return private uclass data for this device, or NULL if none |
| 269 | */ |
| 270 | void *dev_get_uclass_priv(struct udevice *dev); |
| 271 | |
| 272 | /** |
Simon Glass | 46227bd | 2015-03-25 12:21:55 -0600 | [diff] [blame] | 273 | * dev_get_driver_data() - get the driver data used to bind a device |
Simon Glass | 70c3a0e | 2014-11-11 10:46:18 -0700 | [diff] [blame] | 274 | * |
| 275 | * When a device is bound using a device tree node, it matches a |
| 276 | * particular compatible string as in struct udevice_id. This function |
Simon Glass | 46227bd | 2015-03-25 12:21:55 -0600 | [diff] [blame] | 277 | * returns the associated data value for that compatible string. This is |
| 278 | * the 'data' field in struct udevice_id. |
| 279 | * |
| 280 | * For USB devices, this is the driver_info field in struct usb_device_id. |
| 281 | * |
| 282 | * @dev: Device to check |
Simon Glass | 70c3a0e | 2014-11-11 10:46:18 -0700 | [diff] [blame] | 283 | */ |
Simon Glass | 46227bd | 2015-03-25 12:21:55 -0600 | [diff] [blame] | 284 | ulong dev_get_driver_data(struct udevice *dev); |
Simon Glass | 70c3a0e | 2014-11-11 10:46:18 -0700 | [diff] [blame] | 285 | |
Przemyslaw Marczak | d3ef0d7 | 2015-04-15 13:07:24 +0200 | [diff] [blame] | 286 | /** |
| 287 | * dev_get_driver_ops() - get the device's driver's operations |
| 288 | * |
| 289 | * This checks that dev is not NULL, and returns the pointer to device's |
| 290 | * driver's operations. |
| 291 | * |
| 292 | * @dev: Device to check |
| 293 | * @return void pointer to driver's operations or NULL for NULL-dev or NULL-ops |
| 294 | */ |
| 295 | const void *dev_get_driver_ops(struct udevice *dev); |
| 296 | |
Simon Glass | 98fd5d1 | 2015-01-25 08:27:04 -0700 | [diff] [blame] | 297 | /* |
| 298 | * device_get_uclass_id() - return the uclass ID of a device |
| 299 | * |
| 300 | * @dev: Device to check |
| 301 | * @return uclass ID for the device |
| 302 | */ |
| 303 | enum uclass_id device_get_uclass_id(struct udevice *dev); |
| 304 | |
Przemyslaw Marczak | 5ed2e42 | 2015-04-15 13:07:25 +0200 | [diff] [blame] | 305 | /* |
| 306 | * dev_get_uclass_name() - return the uclass name of a device |
| 307 | * |
| 308 | * This checks that dev is not NULL. |
| 309 | * |
| 310 | * @dev: Device to check |
| 311 | * @return pointer to the uclass name for the device |
| 312 | */ |
| 313 | const char *dev_get_uclass_name(struct udevice *dev); |
| 314 | |
Simon Glass | 70c3a0e | 2014-11-11 10:46:18 -0700 | [diff] [blame] | 315 | /** |
Simon Glass | 48d4e29 | 2014-07-23 06:55:19 -0600 | [diff] [blame] | 316 | * device_get_child() - Get the child of a device by index |
| 317 | * |
| 318 | * Returns the numbered child, 0 being the first. This does not use |
| 319 | * sequence numbers, only the natural order. |
| 320 | * |
| 321 | * @dev: Parent device to check |
| 322 | * @index: Child index |
| 323 | * @devp: Returns pointer to device |
Simon Glass | 147a560 | 2015-07-27 15:47:19 -0600 | [diff] [blame] | 324 | * @return 0 if OK, -ENODEV if no such device, other error if the device fails |
| 325 | * to probe |
Simon Glass | 48d4e29 | 2014-07-23 06:55:19 -0600 | [diff] [blame] | 326 | */ |
| 327 | int device_get_child(struct udevice *parent, int index, struct udevice **devp); |
| 328 | |
| 329 | /** |
Simon Glass | db6f020 | 2014-07-23 06:55:12 -0600 | [diff] [blame] | 330 | * device_find_child_by_seq() - Find a child device based on a sequence |
| 331 | * |
| 332 | * This searches for a device with the given seq or req_seq. |
| 333 | * |
| 334 | * For seq, if an active device has this sequence it will be returned. |
| 335 | * If there is no such device then this will return -ENODEV. |
| 336 | * |
| 337 | * For req_seq, if a device (whether activated or not) has this req_seq |
| 338 | * value, that device will be returned. This is a strong indication that |
| 339 | * the device will receive that sequence when activated. |
| 340 | * |
| 341 | * @parent: Parent device |
| 342 | * @seq_or_req_seq: Sequence number to find (0=first) |
| 343 | * @find_req_seq: true to find req_seq, false to find seq |
| 344 | * @devp: Returns pointer to device (there is only one per for each seq). |
| 345 | * Set to NULL if none is found |
| 346 | * @return 0 if OK, -ve on error |
| 347 | */ |
| 348 | int device_find_child_by_seq(struct udevice *parent, int seq_or_req_seq, |
| 349 | bool find_req_seq, struct udevice **devp); |
| 350 | |
Simon Glass | 48d4e29 | 2014-07-23 06:55:19 -0600 | [diff] [blame] | 351 | /** |
| 352 | * device_get_child_by_seq() - Get a child device based on a sequence |
| 353 | * |
| 354 | * If an active device has this sequence it will be returned. If there is no |
| 355 | * such device then this will check for a device that is requesting this |
| 356 | * sequence. |
| 357 | * |
| 358 | * The device is probed to activate it ready for use. |
| 359 | * |
| 360 | * @parent: Parent device |
| 361 | * @seq: Sequence number to find (0=first) |
| 362 | * @devp: Returns pointer to device (there is only one per for each seq) |
| 363 | * Set to NULL if none is found |
| 364 | * @return 0 if OK, -ve on error |
| 365 | */ |
| 366 | int device_get_child_by_seq(struct udevice *parent, int seq, |
| 367 | struct udevice **devp); |
| 368 | |
| 369 | /** |
| 370 | * device_find_child_by_of_offset() - Find a child device based on FDT offset |
| 371 | * |
| 372 | * Locates a child device by its device tree offset. |
| 373 | * |
| 374 | * @parent: Parent device |
| 375 | * @of_offset: Device tree offset to find |
| 376 | * @devp: Returns pointer to device if found, otherwise this is set to NULL |
| 377 | * @return 0 if OK, -ve on error |
| 378 | */ |
| 379 | int device_find_child_by_of_offset(struct udevice *parent, int of_offset, |
| 380 | struct udevice **devp); |
| 381 | |
| 382 | /** |
| 383 | * device_get_child_by_of_offset() - Get a child device based on FDT offset |
| 384 | * |
| 385 | * Locates a child device by its device tree offset. |
| 386 | * |
| 387 | * The device is probed to activate it ready for use. |
| 388 | * |
| 389 | * @parent: Parent device |
| 390 | * @of_offset: Device tree offset to find |
| 391 | * @devp: Returns pointer to device if found, otherwise this is set to NULL |
| 392 | * @return 0 if OK, -ve on error |
| 393 | */ |
Simon Glass | 861bc9f | 2015-06-23 15:38:38 -0600 | [diff] [blame] | 394 | int device_get_child_by_of_offset(struct udevice *parent, int of_offset, |
Simon Glass | 48d4e29 | 2014-07-23 06:55:19 -0600 | [diff] [blame] | 395 | struct udevice **devp); |
| 396 | |
Simon Glass | 44da735 | 2014-10-13 23:41:49 -0600 | [diff] [blame] | 397 | /** |
Simon Glass | ae2efac | 2015-06-23 15:38:37 -0600 | [diff] [blame] | 398 | * device_get_global_by_of_offset() - Get a device based on FDT offset |
| 399 | * |
| 400 | * Locates a device by its device tree offset, searching globally throughout |
| 401 | * the all driver model devices. |
| 402 | * |
| 403 | * The device is probed to activate it ready for use. |
| 404 | * |
| 405 | * @of_offset: Device tree offset to find |
| 406 | * @devp: Returns pointer to device if found, otherwise this is set to NULL |
| 407 | * @return 0 if OK, -ve on error |
| 408 | */ |
| 409 | int device_get_global_by_of_offset(int of_offset, struct udevice **devp); |
| 410 | |
| 411 | /** |
Simon Glass | 44da735 | 2014-10-13 23:41:49 -0600 | [diff] [blame] | 412 | * device_find_first_child() - Find the first child of a device |
| 413 | * |
| 414 | * @parent: Parent device to search |
| 415 | * @devp: Returns first child device, or NULL if none |
| 416 | * @return 0 |
| 417 | */ |
| 418 | int device_find_first_child(struct udevice *parent, struct udevice **devp); |
| 419 | |
| 420 | /** |
Simon Glass | 147a560 | 2015-07-27 15:47:19 -0600 | [diff] [blame] | 421 | * device_find_next_child() - Find the next child of a device |
Simon Glass | 44da735 | 2014-10-13 23:41:49 -0600 | [diff] [blame] | 422 | * |
| 423 | * @devp: Pointer to previous child device on entry. Returns pointer to next |
| 424 | * child device, or NULL if none |
| 425 | * @return 0 |
| 426 | */ |
| 427 | int device_find_next_child(struct udevice **devp); |
| 428 | |
Peng Fan | 99b7235 | 2015-02-10 14:46:32 +0800 | [diff] [blame] | 429 | /** |
| 430 | * dev_get_addr() - Get the reg property of a device |
| 431 | * |
| 432 | * @dev: Pointer to a device |
| 433 | * |
| 434 | * @return addr |
| 435 | */ |
| 436 | fdt_addr_t dev_get_addr(struct udevice *dev); |
| 437 | |
Simon Glass | 40f829a | 2015-03-25 12:21:57 -0600 | [diff] [blame] | 438 | /** |
| 439 | * device_has_children() - check if a device has any children |
| 440 | * |
| 441 | * @dev: Device to check |
| 442 | * @return true if the device has one or more children |
| 443 | */ |
| 444 | bool device_has_children(struct udevice *dev); |
| 445 | |
| 446 | /** |
| 447 | * device_has_active_children() - check if a device has any active children |
| 448 | * |
| 449 | * @dev: Device to check |
| 450 | * @return true if the device has one or more children and at least one of |
| 451 | * them is active (probed). |
| 452 | */ |
| 453 | bool device_has_active_children(struct udevice *dev); |
| 454 | |
| 455 | /** |
| 456 | * device_is_last_sibling() - check if a device is the last sibling |
| 457 | * |
| 458 | * This function can be useful for display purposes, when special action needs |
| 459 | * to be taken when displaying the last sibling. This can happen when a tree |
| 460 | * view of devices is being displayed. |
| 461 | * |
| 462 | * @dev: Device to check |
| 463 | * @return true if there are no more siblings after this one - i.e. is it |
| 464 | * last in the list. |
| 465 | */ |
| 466 | bool device_is_last_sibling(struct udevice *dev); |
| 467 | |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 468 | #endif |