Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Function to read values from the device tree node attached to a udevice. |
| 4 | * |
| 5 | * Copyright (c) 2017 Google, Inc |
| 6 | * Written by Simon Glass <sjg@chromium.org> |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #ifndef _DM_READ_H |
| 10 | #define _DM_READ_H |
| 11 | |
| 12 | #include <dm/fdtaddr.h> |
| 13 | #include <dm/ofnode.h> |
| 14 | #include <dm/uclass.h> |
| 15 | |
Simon Glass | a448101 | 2017-06-12 06:21:29 -0600 | [diff] [blame] | 16 | struct resource; |
| 17 | |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 18 | #if CONFIG_IS_ENABLED(OF_LIVE) |
| 19 | static inline const struct device_node *dev_np(struct udevice *dev) |
| 20 | { |
| 21 | return ofnode_to_np(dev->node); |
| 22 | } |
| 23 | #else |
| 24 | static inline const struct device_node *dev_np(struct udevice *dev) |
| 25 | { |
| 26 | return NULL; |
| 27 | } |
| 28 | #endif |
| 29 | |
| 30 | /** |
| 31 | * dev_ofnode() - get the DT node reference associated with a udevice |
| 32 | * |
| 33 | * @dev: device to check |
| 34 | * @return reference of the the device's DT node |
| 35 | */ |
| 36 | static inline ofnode dev_ofnode(struct udevice *dev) |
| 37 | { |
| 38 | return dev->node; |
| 39 | } |
| 40 | |
| 41 | static inline bool dev_of_valid(struct udevice *dev) |
| 42 | { |
| 43 | return ofnode_valid(dev_ofnode(dev)); |
| 44 | } |
| 45 | |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 46 | #ifndef CONFIG_DM_DEV_READ_INLINE |
T Karthik Reddy | 3f3d771 | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 47 | |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 48 | /** |
Masahiro Yamada | 3ab48f6 | 2017-12-30 02:00:05 +0900 | [diff] [blame] | 49 | * dev_read_u32() - read a 32-bit integer from a device's DT property |
| 50 | * |
| 51 | * @dev: device to read DT property from |
| 52 | * @propname: name of the property to read from |
| 53 | * @outp: place to put value (if found) |
| 54 | * @return 0 if OK, -ve on error |
| 55 | */ |
| 56 | int dev_read_u32(struct udevice *dev, const char *propname, u32 *outp); |
| 57 | |
| 58 | /** |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 59 | * dev_read_u32_default() - read a 32-bit integer from a device's DT property |
| 60 | * |
| 61 | * @dev: device to read DT property from |
| 62 | * @propname: name of the property to read from |
| 63 | * @def: default value to return if the property has no value |
| 64 | * @return property value, or @def if not found |
| 65 | */ |
| 66 | int dev_read_u32_default(struct udevice *dev, const char *propname, int def); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 67 | |
| 68 | /** |
Simon Glass | a1b17e4 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 69 | * dev_read_s32() - read a signed 32-bit integer from a device's DT property |
| 70 | * |
| 71 | * @dev: device to read DT property from |
| 72 | * @propname: name of the property to read from |
| 73 | * @outp: place to put value (if found) |
| 74 | * @return 0 if OK, -ve on error |
| 75 | */ |
| 76 | int dev_read_s32(struct udevice *dev, const char *propname, s32 *outp); |
| 77 | |
| 78 | /** |
| 79 | * dev_read_s32_default() - read a signed 32-bit int from a device's DT property |
| 80 | * |
| 81 | * @dev: device to read DT property from |
| 82 | * @propname: name of the property to read from |
| 83 | * @def: default value to return if the property has no value |
| 84 | * @return property value, or @def if not found |
| 85 | */ |
| 86 | int dev_read_s32_default(struct udevice *dev, const char *propname, int def); |
| 87 | |
| 88 | /** |
| 89 | * dev_read_u32u() - read a 32-bit integer from a device's DT property |
| 90 | * |
| 91 | * This version uses a standard uint type. |
| 92 | * |
| 93 | * @dev: device to read DT property from |
| 94 | * @propname: name of the property to read from |
| 95 | * @outp: place to put value (if found) |
| 96 | * @return 0 if OK, -ve on error |
| 97 | */ |
| 98 | int dev_read_u32u(struct udevice *dev, const char *propname, uint *outp); |
| 99 | |
| 100 | /** |
T Karthik Reddy | 3f3d771 | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 101 | * dev_read_u64() - read a 64-bit integer from a device's DT property |
| 102 | * |
| 103 | * @dev: device to read DT property from |
| 104 | * @propname: name of the property to read from |
| 105 | * @outp: place to put value (if found) |
| 106 | * @return 0 if OK, -ve on error |
| 107 | */ |
| 108 | int dev_read_u64(struct udevice *dev, const char *propname, u64 *outp); |
| 109 | |
| 110 | /** |
| 111 | * dev_read_u64_default() - read a 64-bit integer from a device's DT property |
| 112 | * |
| 113 | * @dev: device to read DT property from |
| 114 | * @propname: name of the property to read from |
| 115 | * @def: default value to return if the property has no value |
| 116 | * @return property value, or @def if not found |
| 117 | */ |
| 118 | u64 dev_read_u64_default(struct udevice *dev, const char *propname, u64 def); |
| 119 | |
| 120 | /** |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 121 | * dev_read_string() - Read a string from a device's DT property |
| 122 | * |
| 123 | * @dev: device to read DT property from |
| 124 | * @propname: name of the property to read |
| 125 | * @return string from property value, or NULL if there is no such property |
| 126 | */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 127 | const char *dev_read_string(struct udevice *dev, const char *propname); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 128 | |
| 129 | /** |
| 130 | * dev_read_bool() - read a boolean value from a device's DT property |
| 131 | * |
| 132 | * @dev: device to read DT property from |
| 133 | * @propname: name of property to read |
| 134 | * @return true if property is present (meaning true), false if not present |
| 135 | */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 136 | bool dev_read_bool(struct udevice *dev, const char *propname); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 137 | |
| 138 | /** |
| 139 | * dev_read_subnode() - find a named subnode of a device |
| 140 | * |
| 141 | * @dev: device whose DT node contains the subnode |
| 142 | * @subnode_name: name of subnode to find |
| 143 | * @return reference to subnode (which can be invalid if there is no such |
| 144 | * subnode) |
| 145 | */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 146 | ofnode dev_read_subnode(struct udevice *dev, const char *subbnode_name); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 147 | |
| 148 | /** |
| 149 | * dev_read_size() - read the size of a property |
| 150 | * |
| 151 | * @dev: device to check |
| 152 | * @propname: property to check |
| 153 | * @return size of property if present, or -EINVAL if not |
| 154 | */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 155 | int dev_read_size(struct udevice *dev, const char *propname); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 156 | |
| 157 | /** |
| 158 | * dev_read_addr_index() - Get the indexed reg property of a device |
| 159 | * |
| 160 | * @dev: Device to read from |
| 161 | * @index: the 'reg' property can hold a list of <addr, size> pairs |
| 162 | * and @index is used to select which one is required |
| 163 | * |
| 164 | * @return address or FDT_ADDR_T_NONE if not found |
| 165 | */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 166 | fdt_addr_t dev_read_addr_index(struct udevice *dev, int index); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 167 | |
| 168 | /** |
Sekhar Nori | f5b9047 | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 169 | * dev_read_addr_size_index() - Get the indexed reg property of a device |
| 170 | * |
| 171 | * @dev: Device to read from |
| 172 | * @index: the 'reg' property can hold a list of <addr, size> pairs |
| 173 | * and @index is used to select which one is required |
| 174 | * @size: place to put size value (on success) |
| 175 | * |
| 176 | * @return address or FDT_ADDR_T_NONE if not found |
| 177 | */ |
| 178 | fdt_addr_t dev_read_addr_size_index(struct udevice *dev, int index, |
| 179 | fdt_size_t *size); |
| 180 | |
| 181 | /** |
Álvaro Fernández Rojas | 30a90f5 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 182 | * dev_remap_addr_index() - Get the indexed reg property of a device |
| 183 | * as a memory-mapped I/O pointer |
| 184 | * |
| 185 | * @dev: Device to read from |
| 186 | * @index: the 'reg' property can hold a list of <addr, size> pairs |
| 187 | * and @index is used to select which one is required |
| 188 | * |
| 189 | * @return pointer or NULL if not found |
| 190 | */ |
| 191 | void *dev_remap_addr_index(struct udevice *dev, int index); |
| 192 | |
| 193 | /** |
Álvaro Fernández Rojas | 7959882 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 194 | * dev_read_addr_name() - Get the reg property of a device, indexed by name |
| 195 | * |
| 196 | * @dev: Device to read from |
| 197 | * @name: the 'reg' property can hold a list of <addr, size> pairs, with the |
| 198 | * 'reg-names' property providing named-based identification. @index |
| 199 | * indicates the value to search for in 'reg-names'. |
| 200 | * |
| 201 | * @return address or FDT_ADDR_T_NONE if not found |
| 202 | */ |
| 203 | fdt_addr_t dev_read_addr_name(struct udevice *dev, const char* name); |
| 204 | |
| 205 | /** |
Sekhar Nori | f5b9047 | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 206 | * dev_read_addr_size_name() - Get the reg property of a device, indexed by name |
| 207 | * |
| 208 | * @dev: Device to read from |
| 209 | * @name: the 'reg' property can hold a list of <addr, size> pairs, with the |
| 210 | * 'reg-names' property providing named-based identification. @index |
| 211 | * indicates the value to search for in 'reg-names'. |
| 212 | * @size: place to put size value (on success) |
| 213 | * |
| 214 | * @return address or FDT_ADDR_T_NONE if not found |
| 215 | */ |
| 216 | fdt_addr_t dev_read_addr_size_name(struct udevice *dev, const char *name, |
| 217 | fdt_size_t *size); |
| 218 | |
| 219 | /** |
Álvaro Fernández Rojas | 7959882 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 220 | * dev_remap_addr_name() - Get the reg property of a device, indexed by name, |
| 221 | * as a memory-mapped I/O pointer |
| 222 | * |
| 223 | * @dev: Device to read from |
| 224 | * @name: the 'reg' property can hold a list of <addr, size> pairs, with the |
| 225 | * 'reg-names' property providing named-based identification. @index |
| 226 | * indicates the value to search for in 'reg-names'. |
| 227 | * |
| 228 | * @return pointer or NULL if not found |
| 229 | */ |
| 230 | void *dev_remap_addr_name(struct udevice *dev, const char* name); |
| 231 | |
| 232 | /** |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 233 | * dev_read_addr() - Get the reg property of a device |
| 234 | * |
| 235 | * @dev: Device to read from |
| 236 | * |
| 237 | * @return address or FDT_ADDR_T_NONE if not found |
| 238 | */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 239 | fdt_addr_t dev_read_addr(struct udevice *dev); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 240 | |
| 241 | /** |
Philipp Tomsich | c131c8b | 2017-09-11 22:04:12 +0200 | [diff] [blame] | 242 | * dev_read_addr_ptr() - Get the reg property of a device |
| 243 | * as a pointer |
| 244 | * |
| 245 | * @dev: Device to read from |
| 246 | * |
| 247 | * @return pointer or NULL if not found |
| 248 | */ |
| 249 | void *dev_read_addr_ptr(struct udevice *dev); |
| 250 | |
| 251 | /** |
Simon Glass | 33c215a | 2019-09-15 12:08:58 -0600 | [diff] [blame] | 252 | * dev_read_addr_pci() - Read an address and handle PCI address translation |
| 253 | * |
| 254 | * At present U-Boot does not have address translation logic for PCI in the |
| 255 | * livetree implementation (of_addr.c). This special function supports this for |
| 256 | * the flat tree implementation. |
| 257 | * |
| 258 | * This function should be removed (and code should use dev_read() instead) |
| 259 | * once: |
| 260 | * |
| 261 | * 1. PCI address translation is added; and either |
| 262 | * 2. everything uses livetree where PCI translation is used (which is feasible |
| 263 | * in SPL and U-Boot proper) or PCI address translation is added to |
| 264 | * fdtdec_get_addr() and friends. |
| 265 | * |
| 266 | * @dev: Device to read from |
| 267 | * @return address or FDT_ADDR_T_NONE if not found |
| 268 | */ |
| 269 | fdt_addr_t dev_read_addr_pci(struct udevice *dev); |
| 270 | |
| 271 | /** |
Álvaro Fernández Rojas | 30a90f5 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 272 | * dev_remap_addr() - Get the reg property of a device as a |
| 273 | * memory-mapped I/O pointer |
| 274 | * |
| 275 | * @dev: Device to read from |
| 276 | * |
| 277 | * @return pointer or NULL if not found |
| 278 | */ |
| 279 | void *dev_remap_addr(struct udevice *dev); |
| 280 | |
| 281 | /** |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 282 | * dev_read_addr_size() - get address and size from a device property |
| 283 | * |
| 284 | * This does no address translation. It simply reads an property that contains |
| 285 | * an address and a size value, one after the other. |
| 286 | * |
| 287 | * @dev: Device to read from |
| 288 | * @propname: property to read |
| 289 | * @sizep: place to put size value (on success) |
| 290 | * @return address value, or FDT_ADDR_T_NONE on error |
| 291 | */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 292 | fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *propname, |
| 293 | fdt_size_t *sizep); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 294 | |
| 295 | /** |
| 296 | * dev_read_name() - get the name of a device's node |
| 297 | * |
Bin Meng | 15d61d0 | 2019-07-05 09:23:18 -0700 | [diff] [blame] | 298 | * @dev: Device to read from |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 299 | * @return name of node |
| 300 | */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 301 | const char *dev_read_name(struct udevice *dev); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 302 | |
| 303 | /** |
| 304 | * dev_read_stringlist_search() - find string in a string list and return index |
| 305 | * |
| 306 | * Note that it is possible for this function to succeed on property values |
| 307 | * that are not NUL-terminated. That's because the function will stop after |
| 308 | * finding the first occurrence of @string. This can for example happen with |
| 309 | * small-valued cell properties, such as #address-cells, when searching for |
| 310 | * the empty string. |
| 311 | * |
| 312 | * @dev: device to check |
| 313 | * @propname: name of the property containing the string list |
| 314 | * @string: string to look up in the string list |
| 315 | * |
| 316 | * @return: |
| 317 | * the index of the string in the list of strings |
| 318 | * -ENODATA if the property is not found |
| 319 | * -EINVAL on some other error |
| 320 | */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 321 | int dev_read_stringlist_search(struct udevice *dev, const char *property, |
| 322 | const char *string); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 323 | |
| 324 | /** |
Jean-Jacques Hiblot | b5a144a | 2017-09-21 17:03:09 +0200 | [diff] [blame] | 325 | * dev_read_string_index() - obtain an indexed string from a string list |
| 326 | * |
| 327 | * @dev: device to examine |
| 328 | * @propname: name of the property containing the string list |
| 329 | * @index: index of the string to return |
| 330 | * @out: return location for the string |
| 331 | * |
| 332 | * @return: |
| 333 | * length of string, if found or -ve error value if not found |
| 334 | */ |
| 335 | int dev_read_string_index(struct udevice *dev, const char *propname, int index, |
| 336 | const char **outp); |
| 337 | |
| 338 | /** |
| 339 | * dev_read_string_count() - find the number of strings in a string list |
| 340 | * |
| 341 | * @dev: device to examine |
| 342 | * @propname: name of the property containing the string list |
| 343 | * @return: |
| 344 | * number of strings in the list, or -ve error value if not found |
| 345 | */ |
| 346 | int dev_read_string_count(struct udevice *dev, const char *propname); |
| 347 | /** |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 348 | * dev_read_phandle_with_args() - Find a node pointed by phandle in a list |
| 349 | * |
| 350 | * This function is useful to parse lists of phandles and their arguments. |
| 351 | * Returns 0 on success and fills out_args, on error returns appropriate |
| 352 | * errno value. |
| 353 | * |
| 354 | * Caller is responsible to call of_node_put() on the returned out_args->np |
| 355 | * pointer. |
| 356 | * |
| 357 | * Example: |
| 358 | * |
| 359 | * phandle1: node1 { |
| 360 | * #list-cells = <2>; |
| 361 | * } |
| 362 | * |
| 363 | * phandle2: node2 { |
| 364 | * #list-cells = <1>; |
| 365 | * } |
| 366 | * |
| 367 | * node3 { |
| 368 | * list = <&phandle1 1 2 &phandle2 3>; |
| 369 | * } |
| 370 | * |
| 371 | * To get a device_node of the `node2' node you may call this: |
| 372 | * dev_read_phandle_with_args(dev, "list", "#list-cells", 0, 1, &args); |
| 373 | * |
| 374 | * @dev: device whose node containing a list |
| 375 | * @list_name: property name that contains a list |
| 376 | * @cells_name: property name that specifies phandles' arguments count |
| 377 | * @cells_count: Cell count to use if @cells_name is NULL |
| 378 | * @index: index of a phandle to parse out |
| 379 | * @out_args: optional pointer to output arguments structure (will be filled) |
| 380 | * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if |
| 381 | * @list_name does not exist, -EINVAL if a phandle was not found, |
| 382 | * @cells_name could not be found, the arguments were truncated or there |
| 383 | * were too many arguments. |
| 384 | */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 385 | int dev_read_phandle_with_args(struct udevice *dev, const char *list_name, |
| 386 | const char *cells_name, int cell_count, |
| 387 | int index, |
| 388 | struct ofnode_phandle_args *out_args); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 389 | |
| 390 | /** |
Patrice Chotard | 642346a | 2017-07-18 11:57:08 +0200 | [diff] [blame] | 391 | * dev_count_phandle_with_args() - Return phandle number in a list |
| 392 | * |
| 393 | * This function is usefull to get phandle number contained in a property list. |
| 394 | * For example, this allows to allocate the right amount of memory to keep |
| 395 | * clock's reference contained into the "clocks" property. |
| 396 | * |
| 397 | * |
| 398 | * @dev: device whose node containing a list |
| 399 | * @list_name: property name that contains a list |
| 400 | * @cells_name: property name that specifies phandles' arguments count |
| 401 | * @Returns number of phandle found on success, on error returns appropriate |
| 402 | * errno value. |
| 403 | */ |
| 404 | |
| 405 | int dev_count_phandle_with_args(struct udevice *dev, const char *list_name, |
| 406 | const char *cells_name); |
| 407 | |
| 408 | /** |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 409 | * dev_read_addr_cells() - Get the number of address cells for a device's node |
| 410 | * |
| 411 | * This walks back up the tree to find the closest #address-cells property |
| 412 | * which controls the given node. |
| 413 | * |
Mario Six | 7ba5041 | 2018-01-15 11:09:36 +0100 | [diff] [blame] | 414 | * @dev: device to check |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 415 | * @return number of address cells this node uses |
| 416 | */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 417 | int dev_read_addr_cells(struct udevice *dev); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 418 | |
| 419 | /** |
| 420 | * dev_read_size_cells() - Get the number of size cells for a device's node |
| 421 | * |
| 422 | * This walks back up the tree to find the closest #size-cells property |
| 423 | * which controls the given node. |
| 424 | * |
Mario Six | 7ba5041 | 2018-01-15 11:09:36 +0100 | [diff] [blame] | 425 | * @dev: device to check |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 426 | * @return number of size cells this node uses |
| 427 | */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 428 | int dev_read_size_cells(struct udevice *dev); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 429 | |
| 430 | /** |
Simon Glass | 878d68c | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 431 | * dev_read_addr_cells() - Get the address cells property in a node |
| 432 | * |
| 433 | * This function matches fdt_address_cells(). |
| 434 | * |
Mario Six | 7ba5041 | 2018-01-15 11:09:36 +0100 | [diff] [blame] | 435 | * @dev: device to check |
Simon Glass | 878d68c | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 436 | * @return number of address cells this node uses |
| 437 | */ |
| 438 | int dev_read_simple_addr_cells(struct udevice *dev); |
| 439 | |
| 440 | /** |
| 441 | * dev_read_size_cells() - Get the size cells property in a node |
| 442 | * |
| 443 | * This function matches fdt_size_cells(). |
| 444 | * |
Mario Six | 7ba5041 | 2018-01-15 11:09:36 +0100 | [diff] [blame] | 445 | * @dev: device to check |
Simon Glass | 878d68c | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 446 | * @return number of size cells this node uses |
| 447 | */ |
| 448 | int dev_read_simple_size_cells(struct udevice *dev); |
| 449 | |
| 450 | /** |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 451 | * dev_read_phandle() - Get the phandle from a device |
| 452 | * |
| 453 | * @dev: device to check |
| 454 | * @return phandle (1 or greater), or 0 if no phandle or other error |
| 455 | */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 456 | int dev_read_phandle(struct udevice *dev); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 457 | |
| 458 | /** |
| 459 | * dev_read_prop()- - read a property from a device's node |
| 460 | * |
| 461 | * @dev: device to check |
| 462 | * @propname: property to read |
| 463 | * @lenp: place to put length on success |
| 464 | * @return pointer to property, or NULL if not found |
| 465 | */ |
Masahiro Yamada | fd73621 | 2017-07-17 12:18:39 +0900 | [diff] [blame] | 466 | const void *dev_read_prop(struct udevice *dev, const char *propname, int *lenp); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 467 | |
| 468 | /** |
| 469 | * dev_read_alias_seq() - Get the alias sequence number of a node |
| 470 | * |
| 471 | * This works out whether a node is pointed to by an alias, and if so, the |
| 472 | * sequence number of that alias. Aliases are of the form <base><num> where |
| 473 | * <num> is the sequence number. For example spi2 would be sequence number 2. |
| 474 | * |
| 475 | * @dev: device to look up |
| 476 | * @devnump: set to the sequence number if one is found |
| 477 | * @return 0 if a sequence was found, -ve if not |
| 478 | */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 479 | int dev_read_alias_seq(struct udevice *dev, int *devnump); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 480 | |
| 481 | /** |
| 482 | * dev_read_u32_array() - Find and read an array of 32 bit integers |
| 483 | * |
| 484 | * Search for a property in a device node and read 32-bit value(s) from |
| 485 | * it. |
| 486 | * |
| 487 | * The out_values is modified only if a valid u32 value can be decoded. |
| 488 | * |
| 489 | * @dev: device to look up |
| 490 | * @propname: name of the property to read |
| 491 | * @out_values: pointer to return value, modified only if return value is 0 |
| 492 | * @sz: number of array elements to read |
| 493 | * @return 0 on success, -EINVAL if the property does not exist, -ENODATA if |
| 494 | * property does not have a value, and -EOVERFLOW if the property data isn't |
| 495 | * large enough. |
| 496 | */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 497 | int dev_read_u32_array(struct udevice *dev, const char *propname, |
| 498 | u32 *out_values, size_t sz); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 499 | |
| 500 | /** |
| 501 | * dev_read_first_subnode() - find the first subnode of a device's node |
| 502 | * |
| 503 | * @dev: device to look up |
| 504 | * @return reference to the first subnode (which can be invalid if the device's |
| 505 | * node has no subnodes) |
| 506 | */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 507 | ofnode dev_read_first_subnode(struct udevice *dev); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 508 | |
| 509 | /** |
| 510 | * ofnode_next_subnode() - find the next sibling of a subnode |
| 511 | * |
| 512 | * @node: valid reference to previous node (sibling) |
| 513 | * @return reference to the next subnode (which can be invalid if the node |
| 514 | * has no more siblings) |
| 515 | */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 516 | ofnode dev_read_next_subnode(ofnode node); |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 517 | |
| 518 | /** |
| 519 | * dev_read_u8_array_ptr() - find an 8-bit array |
| 520 | * |
| 521 | * Look up a device's node property and return a pointer to its contents as a |
| 522 | * byte array of given length. The property must have at least enough data |
| 523 | * for the array (count bytes). It may have more, but this will be ignored. |
| 524 | * The data is not copied. |
| 525 | * |
| 526 | * @dev: device to look up |
| 527 | * @propname: name of property to find |
| 528 | * @sz: number of array elements |
| 529 | * @return pointer to byte array if found, or NULL if the property is not |
| 530 | * found or there is not enough data |
| 531 | */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 532 | const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname, |
| 533 | size_t sz); |
| 534 | |
Simon Glass | f7d6fcf | 2017-06-12 06:21:30 -0600 | [diff] [blame] | 535 | /** |
| 536 | * dev_read_enabled() - check whether a node is enabled |
| 537 | * |
| 538 | * This looks for a 'status' property. If this exists, then returns 1 if |
| 539 | * the status is 'ok' and 0 otherwise. If there is no status property, |
| 540 | * it returns 1 on the assumption that anything mentioned should be enabled |
| 541 | * by default. |
| 542 | * |
| 543 | * @dev: device to examine |
| 544 | * @return integer value 0 (not enabled) or 1 (enabled) |
| 545 | */ |
| 546 | int dev_read_enabled(struct udevice *dev); |
| 547 | |
Simon Glass | dcf9885 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 548 | /** |
| 549 | * dev_read_resource() - obtain an indexed resource from a device. |
| 550 | * |
Masahiro Yamada | 7b8b47b | 2017-08-26 01:12:30 +0900 | [diff] [blame] | 551 | * @dev: device to examine |
Simon Glass | dcf9885 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 552 | * @index index of the resource to retrieve (0 = first) |
| 553 | * @res returns the resource |
| 554 | * @return 0 if ok, negative on error |
| 555 | */ |
| 556 | int dev_read_resource(struct udevice *dev, uint index, struct resource *res); |
| 557 | |
Masahiro Yamada | 7b8b47b | 2017-08-26 01:12:30 +0900 | [diff] [blame] | 558 | /** |
| 559 | * dev_read_resource_byname() - obtain a named resource from a device. |
| 560 | * |
| 561 | * @dev: device to examine |
| 562 | * @name: name of the resource to retrieve |
| 563 | * @res: returns the resource |
| 564 | * @return 0 if ok, negative on error |
| 565 | */ |
| 566 | int dev_read_resource_byname(struct udevice *dev, const char *name, |
| 567 | struct resource *res); |
| 568 | |
Mario Six | 147c607 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 569 | /** |
Fabien Dessenne | 641067f | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 570 | * dev_translate_address() - Translate a device-tree address |
Mario Six | 147c607 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 571 | * |
| 572 | * Translate an address from the device-tree into a CPU physical address. This |
| 573 | * function walks up the tree and applies the various bus mappings along the |
| 574 | * way. |
| 575 | * |
| 576 | * @dev: device giving the context in which to translate the address |
| 577 | * @in_addr: pointer to the address to translate |
| 578 | * @return the translated address; OF_BAD_ADDR on error |
| 579 | */ |
| 580 | u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr); |
Michal Simek | 83e4c7e | 2019-01-31 16:30:59 +0100 | [diff] [blame] | 581 | |
| 582 | /** |
Fabien Dessenne | 641067f | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 583 | * dev_translate_dma_address() - Translate a device-tree DMA address |
| 584 | * |
| 585 | * Translate a DMA address from the device-tree into a CPU physical address. |
| 586 | * This function walks up the tree and applies the various bus mappings along |
| 587 | * the way. |
| 588 | * |
| 589 | * @dev: device giving the context in which to translate the DMA address |
| 590 | * @in_addr: pointer to the DMA address to translate |
| 591 | * @return the translated DMA address; OF_BAD_ADDR on error |
| 592 | */ |
| 593 | u64 dev_translate_dma_address(struct udevice *dev, const fdt32_t *in_addr); |
| 594 | |
| 595 | /** |
Michal Simek | 83e4c7e | 2019-01-31 16:30:59 +0100 | [diff] [blame] | 596 | * dev_read_alias_highest_id - Get highest alias id for the given stem |
| 597 | * @stem: Alias stem to be examined |
| 598 | * |
| 599 | * The function travels the lookup table to get the highest alias id for the |
| 600 | * given alias stem. |
| 601 | * @return alias ID, if found, else -1 |
| 602 | */ |
| 603 | int dev_read_alias_highest_id(const char *stem); |
| 604 | |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 605 | #else /* CONFIG_DM_DEV_READ_INLINE is enabled */ |
| 606 | |
Masahiro Yamada | 3ab48f6 | 2017-12-30 02:00:05 +0900 | [diff] [blame] | 607 | static inline int dev_read_u32(struct udevice *dev, |
| 608 | const char *propname, u32 *outp) |
| 609 | { |
| 610 | return ofnode_read_u32(dev_ofnode(dev), propname, outp); |
| 611 | } |
| 612 | |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 613 | static inline int dev_read_u32_default(struct udevice *dev, |
| 614 | const char *propname, int def) |
| 615 | { |
| 616 | return ofnode_read_u32_default(dev_ofnode(dev), propname, def); |
| 617 | } |
| 618 | |
Simon Glass | a1b17e4 | 2018-12-10 10:37:37 -0700 | [diff] [blame] | 619 | static inline int dev_read_s32(struct udevice *dev, |
| 620 | const char *propname, s32 *outp) |
| 621 | { |
| 622 | return ofnode_read_s32(dev_ofnode(dev), propname, outp); |
| 623 | } |
| 624 | |
| 625 | static inline int dev_read_s32_default(struct udevice *dev, |
| 626 | const char *propname, int def) |
| 627 | { |
| 628 | return ofnode_read_s32_default(dev_ofnode(dev), propname, def); |
| 629 | } |
| 630 | |
| 631 | static inline int dev_read_u32u(struct udevice *dev, |
| 632 | const char *propname, uint *outp) |
| 633 | { |
| 634 | u32 val; |
| 635 | int ret; |
| 636 | |
| 637 | ret = ofnode_read_u32(dev_ofnode(dev), propname, &val); |
| 638 | if (ret) |
| 639 | return ret; |
| 640 | *outp = val; |
| 641 | |
| 642 | return 0; |
| 643 | } |
| 644 | |
T Karthik Reddy | 3f3d771 | 2019-09-02 16:34:30 +0200 | [diff] [blame] | 645 | static inline int dev_read_u64(struct udevice *dev, |
| 646 | const char *propname, u64 *outp) |
| 647 | { |
| 648 | return ofnode_read_u64(dev_ofnode(dev), propname, outp); |
| 649 | } |
| 650 | |
| 651 | static inline u64 dev_read_u64_default(struct udevice *dev, |
| 652 | const char *propname, u64 def) |
| 653 | { |
| 654 | return ofnode_read_u64_default(dev_ofnode(dev), propname, def); |
| 655 | } |
| 656 | |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 657 | static inline const char *dev_read_string(struct udevice *dev, |
| 658 | const char *propname) |
| 659 | { |
| 660 | return ofnode_read_string(dev_ofnode(dev), propname); |
| 661 | } |
| 662 | |
| 663 | static inline bool dev_read_bool(struct udevice *dev, const char *propname) |
| 664 | { |
| 665 | return ofnode_read_bool(dev_ofnode(dev), propname); |
| 666 | } |
| 667 | |
| 668 | static inline ofnode dev_read_subnode(struct udevice *dev, |
| 669 | const char *subbnode_name) |
| 670 | { |
| 671 | return ofnode_find_subnode(dev_ofnode(dev), subbnode_name); |
| 672 | } |
| 673 | |
| 674 | static inline int dev_read_size(struct udevice *dev, const char *propname) |
| 675 | { |
| 676 | return ofnode_read_size(dev_ofnode(dev), propname); |
| 677 | } |
| 678 | |
| 679 | static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index) |
| 680 | { |
| 681 | return devfdt_get_addr_index(dev, index); |
| 682 | } |
| 683 | |
Sekhar Nori | f5b9047 | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 684 | static inline fdt_addr_t dev_read_addr_size_index(struct udevice *dev, |
| 685 | int index, |
| 686 | fdt_size_t *size) |
| 687 | { |
| 688 | return devfdt_get_addr_size_index(dev, index, size); |
| 689 | } |
| 690 | |
Álvaro Fernández Rojas | 7959882 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 691 | static inline fdt_addr_t dev_read_addr_name(struct udevice *dev, |
| 692 | const char *name) |
| 693 | { |
| 694 | return devfdt_get_addr_name(dev, name); |
| 695 | } |
| 696 | |
Sekhar Nori | f5b9047 | 2019-08-01 19:12:56 +0530 | [diff] [blame] | 697 | static inline fdt_addr_t dev_read_addr_size_name(struct udevice *dev, |
| 698 | const char *name, |
| 699 | fdt_size_t *size) |
| 700 | { |
| 701 | return devfdt_get_addr_size_name(dev, name, size); |
| 702 | } |
| 703 | |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 704 | static inline fdt_addr_t dev_read_addr(struct udevice *dev) |
| 705 | { |
| 706 | return devfdt_get_addr(dev); |
| 707 | } |
| 708 | |
Philipp Tomsich | c131c8b | 2017-09-11 22:04:12 +0200 | [diff] [blame] | 709 | static inline void *dev_read_addr_ptr(struct udevice *dev) |
| 710 | { |
| 711 | return devfdt_get_addr_ptr(dev); |
| 712 | } |
| 713 | |
Simon Glass | 33c215a | 2019-09-15 12:08:58 -0600 | [diff] [blame] | 714 | static inline fdt_addr_t dev_read_addr_pci(struct udevice *dev) |
| 715 | { |
| 716 | return devfdt_get_addr_pci(dev); |
| 717 | } |
| 718 | |
Álvaro Fernández Rojas | 30a90f5 | 2018-04-29 21:56:54 +0200 | [diff] [blame] | 719 | static inline void *dev_remap_addr(struct udevice *dev) |
| 720 | { |
| 721 | return devfdt_remap_addr(dev); |
| 722 | } |
| 723 | |
| 724 | static inline void *dev_remap_addr_index(struct udevice *dev, int index) |
| 725 | { |
| 726 | return devfdt_remap_addr_index(dev, index); |
| 727 | } |
| 728 | |
Álvaro Fernández Rojas | 7959882 | 2018-12-03 19:37:09 +0100 | [diff] [blame] | 729 | static inline void *dev_remap_addr_name(struct udevice *dev, const char *name) |
| 730 | { |
| 731 | return devfdt_remap_addr_name(dev, name); |
| 732 | } |
| 733 | |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 734 | static inline fdt_addr_t dev_read_addr_size(struct udevice *dev, |
| 735 | const char *propname, |
| 736 | fdt_size_t *sizep) |
| 737 | { |
| 738 | return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep); |
| 739 | } |
| 740 | |
| 741 | static inline const char *dev_read_name(struct udevice *dev) |
| 742 | { |
| 743 | return ofnode_get_name(dev_ofnode(dev)); |
| 744 | } |
| 745 | |
| 746 | static inline int dev_read_stringlist_search(struct udevice *dev, |
| 747 | const char *propname, |
| 748 | const char *string) |
| 749 | { |
| 750 | return ofnode_stringlist_search(dev_ofnode(dev), propname, string); |
| 751 | } |
| 752 | |
Jean-Jacques Hiblot | b5a144a | 2017-09-21 17:03:09 +0200 | [diff] [blame] | 753 | static inline int dev_read_string_index(struct udevice *dev, |
| 754 | const char *propname, int index, |
| 755 | const char **outp) |
| 756 | { |
| 757 | return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp); |
| 758 | } |
| 759 | |
| 760 | static inline int dev_read_string_count(struct udevice *dev, |
| 761 | const char *propname) |
| 762 | { |
| 763 | return ofnode_read_string_count(dev_ofnode(dev), propname); |
| 764 | } |
| 765 | |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 766 | static inline int dev_read_phandle_with_args(struct udevice *dev, |
| 767 | const char *list_name, const char *cells_name, int cell_count, |
| 768 | int index, struct ofnode_phandle_args *out_args) |
| 769 | { |
| 770 | return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name, |
| 771 | cells_name, cell_count, index, |
| 772 | out_args); |
| 773 | } |
| 774 | |
Patrice Chotard | 642346a | 2017-07-18 11:57:08 +0200 | [diff] [blame] | 775 | static inline int dev_count_phandle_with_args(struct udevice *dev, |
| 776 | const char *list_name, const char *cells_name) |
| 777 | { |
| 778 | return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name, |
| 779 | cells_name); |
| 780 | } |
| 781 | |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 782 | static inline int dev_read_addr_cells(struct udevice *dev) |
| 783 | { |
Simon Glass | 878d68c | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 784 | /* NOTE: this call should walk up the parent stack */ |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 785 | return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev)); |
| 786 | } |
| 787 | |
| 788 | static inline int dev_read_size_cells(struct udevice *dev) |
| 789 | { |
Simon Glass | 878d68c | 2017-06-12 06:21:31 -0600 | [diff] [blame] | 790 | /* NOTE: this call should walk up the parent stack */ |
| 791 | return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev)); |
| 792 | } |
| 793 | |
| 794 | static inline int dev_read_simple_addr_cells(struct udevice *dev) |
| 795 | { |
| 796 | return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev)); |
| 797 | } |
| 798 | |
| 799 | static inline int dev_read_simple_size_cells(struct udevice *dev) |
| 800 | { |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 801 | return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev)); |
| 802 | } |
| 803 | |
| 804 | static inline int dev_read_phandle(struct udevice *dev) |
| 805 | { |
| 806 | return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev)); |
| 807 | } |
| 808 | |
Masahiro Yamada | fd73621 | 2017-07-17 12:18:39 +0900 | [diff] [blame] | 809 | static inline const void *dev_read_prop(struct udevice *dev, |
| 810 | const char *propname, int *lenp) |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 811 | { |
Masahiro Yamada | 61e51ba | 2017-06-22 16:54:05 +0900 | [diff] [blame] | 812 | return ofnode_get_property(dev_ofnode(dev), propname, lenp); |
Simon Glass | 47a0fd3 | 2017-05-18 20:09:04 -0600 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | static inline int dev_read_alias_seq(struct udevice *dev, int *devnump) |
| 816 | { |
| 817 | return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name, |
| 818 | dev_of_offset(dev), devnump); |
| 819 | } |
| 820 | |
| 821 | static inline int dev_read_u32_array(struct udevice *dev, const char *propname, |
| 822 | u32 *out_values, size_t sz) |
| 823 | { |
| 824 | return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz); |
| 825 | } |
| 826 | |
| 827 | static inline ofnode dev_read_first_subnode(struct udevice *dev) |
| 828 | { |
| 829 | return ofnode_first_subnode(dev_ofnode(dev)); |
| 830 | } |
| 831 | |
| 832 | static inline ofnode dev_read_next_subnode(ofnode node) |
| 833 | { |
| 834 | return ofnode_next_subnode(node); |
| 835 | } |
| 836 | |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 837 | static inline const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, |
| 838 | const char *propname, size_t sz) |
| 839 | { |
| 840 | return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz); |
| 841 | } |
| 842 | |
Simon Glass | f7d6fcf | 2017-06-12 06:21:30 -0600 | [diff] [blame] | 843 | static inline int dev_read_enabled(struct udevice *dev) |
| 844 | { |
| 845 | return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev)); |
| 846 | } |
| 847 | |
Simon Glass | dcf9885 | 2017-07-25 08:29:55 -0600 | [diff] [blame] | 848 | static inline int dev_read_resource(struct udevice *dev, uint index, |
| 849 | struct resource *res) |
| 850 | { |
| 851 | return ofnode_read_resource(dev_ofnode(dev), index, res); |
| 852 | } |
| 853 | |
Masahiro Yamada | 7b8b47b | 2017-08-26 01:12:30 +0900 | [diff] [blame] | 854 | static inline int dev_read_resource_byname(struct udevice *dev, |
| 855 | const char *name, |
| 856 | struct resource *res) |
| 857 | { |
| 858 | return ofnode_read_resource_byname(dev_ofnode(dev), name, res); |
| 859 | } |
| 860 | |
Mario Six | 147c607 | 2018-01-15 11:07:19 +0100 | [diff] [blame] | 861 | static inline u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr) |
| 862 | { |
| 863 | return ofnode_translate_address(dev_ofnode(dev), in_addr); |
| 864 | } |
| 865 | |
Fabien Dessenne | 641067f | 2019-05-31 15:11:30 +0200 | [diff] [blame] | 866 | static inline u64 dev_translate_dma_address(struct udevice *dev, const fdt32_t *in_addr) |
| 867 | { |
| 868 | return ofnode_translate_dma_address(dev_ofnode(dev), in_addr); |
| 869 | } |
| 870 | |
Michal Simek | 83e4c7e | 2019-01-31 16:30:59 +0100 | [diff] [blame] | 871 | static inline int dev_read_alias_highest_id(const char *stem) |
| 872 | { |
| 873 | return fdtdec_get_alias_highest_id(gd->fdt_blob, stem); |
| 874 | } |
| 875 | |
Simon Glass | f11c7ab | 2017-05-18 20:09:03 -0600 | [diff] [blame] | 876 | #endif /* CONFIG_DM_DEV_READ_INLINE */ |
| 877 | |
| 878 | /** |
| 879 | * dev_for_each_subnode() - Helper function to iterate through subnodes |
| 880 | * |
| 881 | * This creates a for() loop which works through the subnodes in a device's |
| 882 | * device-tree node. |
| 883 | * |
| 884 | * @subnode: ofnode holding the current subnode |
| 885 | * @dev: device to use for interation (struct udevice *) |
| 886 | */ |
| 887 | #define dev_for_each_subnode(subnode, dev) \ |
| 888 | for (subnode = dev_read_first_subnode(dev); \ |
| 889 | ofnode_valid(subnode); \ |
| 890 | subnode = ofnode_next_subnode(subnode)) |
| 891 | |
| 892 | #endif |