dm: core: Add functions to read 64-bit dt properties
[platform/kernel/u-boot.git] / include / dm / read.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
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>
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
16 struct resource;
17
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
46 #ifndef CONFIG_DM_DEV_READ_INLINE
47
48 /**
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 /**
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);
67
68 /**
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 /**
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 /**
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  */
127 const char *dev_read_string(struct udevice *dev, const char *propname);
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  */
136 bool dev_read_bool(struct udevice *dev, const char *propname);
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  */
146 ofnode dev_read_subnode(struct udevice *dev, const char *subbnode_name);
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  */
155 int dev_read_size(struct udevice *dev, const char *propname);
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  */
166 fdt_addr_t dev_read_addr_index(struct udevice *dev, int index);
167
168 /**
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 /**
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 /**
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 /**
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 /**
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 /**
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  */
239 fdt_addr_t dev_read_addr(struct udevice *dev);
240
241 /**
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 /**
252  * dev_remap_addr() - Get the reg property of a device as a
253  *                         memory-mapped I/O pointer
254  *
255  * @dev: Device to read from
256  *
257  * @return pointer or NULL if not found
258  */
259 void *dev_remap_addr(struct udevice *dev);
260
261 /**
262  * dev_read_addr_size() - get address and size from a device property
263  *
264  * This does no address translation. It simply reads an property that contains
265  * an address and a size value, one after the other.
266  *
267  * @dev: Device to read from
268  * @propname: property to read
269  * @sizep: place to put size value (on success)
270  * @return address value, or FDT_ADDR_T_NONE on error
271  */
272 fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *propname,
273                                 fdt_size_t *sizep);
274
275 /**
276  * dev_read_name() - get the name of a device's node
277  *
278  * @dev: Device to read from
279  * @return name of node
280  */
281 const char *dev_read_name(struct udevice *dev);
282
283 /**
284  * dev_read_stringlist_search() - find string in a string list and return index
285  *
286  * Note that it is possible for this function to succeed on property values
287  * that are not NUL-terminated. That's because the function will stop after
288  * finding the first occurrence of @string. This can for example happen with
289  * small-valued cell properties, such as #address-cells, when searching for
290  * the empty string.
291  *
292  * @dev: device to check
293  * @propname: name of the property containing the string list
294  * @string: string to look up in the string list
295  *
296  * @return:
297  *   the index of the string in the list of strings
298  *   -ENODATA if the property is not found
299  *   -EINVAL on some other error
300  */
301 int dev_read_stringlist_search(struct udevice *dev, const char *property,
302                           const char *string);
303
304 /**
305  * dev_read_string_index() - obtain an indexed string from a string list
306  *
307  * @dev: device to examine
308  * @propname: name of the property containing the string list
309  * @index: index of the string to return
310  * @out: return location for the string
311  *
312  * @return:
313  *   length of string, if found or -ve error value if not found
314  */
315 int dev_read_string_index(struct udevice *dev, const char *propname, int index,
316                           const char **outp);
317
318 /**
319  * dev_read_string_count() - find the number of strings in a string list
320  *
321  * @dev: device to examine
322  * @propname: name of the property containing the string list
323  * @return:
324  *   number of strings in the list, or -ve error value if not found
325  */
326 int dev_read_string_count(struct udevice *dev, const char *propname);
327 /**
328  * dev_read_phandle_with_args() - Find a node pointed by phandle in a list
329  *
330  * This function is useful to parse lists of phandles and their arguments.
331  * Returns 0 on success and fills out_args, on error returns appropriate
332  * errno value.
333  *
334  * Caller is responsible to call of_node_put() on the returned out_args->np
335  * pointer.
336  *
337  * Example:
338  *
339  * phandle1: node1 {
340  *      #list-cells = <2>;
341  * }
342  *
343  * phandle2: node2 {
344  *      #list-cells = <1>;
345  * }
346  *
347  * node3 {
348  *      list = <&phandle1 1 2 &phandle2 3>;
349  * }
350  *
351  * To get a device_node of the `node2' node you may call this:
352  * dev_read_phandle_with_args(dev, "list", "#list-cells", 0, 1, &args);
353  *
354  * @dev:        device whose node containing a list
355  * @list_name:  property name that contains a list
356  * @cells_name: property name that specifies phandles' arguments count
357  * @cells_count: Cell count to use if @cells_name is NULL
358  * @index:      index of a phandle to parse out
359  * @out_args:   optional pointer to output arguments structure (will be filled)
360  * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
361  *      @list_name does not exist, -EINVAL if a phandle was not found,
362  *      @cells_name could not be found, the arguments were truncated or there
363  *      were too many arguments.
364  */
365 int dev_read_phandle_with_args(struct udevice *dev, const char *list_name,
366                                 const char *cells_name, int cell_count,
367                                 int index,
368                                 struct ofnode_phandle_args *out_args);
369
370 /**
371  * dev_count_phandle_with_args() - Return phandle number in a list
372  *
373  * This function is usefull to get phandle number contained in a property list.
374  * For example, this allows to allocate the right amount of memory to keep
375  * clock's reference contained into the "clocks" property.
376  *
377  *
378  * @dev:        device whose node containing a list
379  * @list_name:  property name that contains a list
380  * @cells_name: property name that specifies phandles' arguments count
381  * @Returns number of phandle found on success, on error returns appropriate
382  * errno value.
383  */
384
385 int dev_count_phandle_with_args(struct udevice *dev, const char *list_name,
386                                 const char *cells_name);
387
388 /**
389  * dev_read_addr_cells() - Get the number of address cells for a device's node
390  *
391  * This walks back up the tree to find the closest #address-cells property
392  * which controls the given node.
393  *
394  * @dev: device to check
395  * @return number of address cells this node uses
396  */
397 int dev_read_addr_cells(struct udevice *dev);
398
399 /**
400  * dev_read_size_cells() - Get the number of size cells for a device's node
401  *
402  * This walks back up the tree to find the closest #size-cells property
403  * which controls the given node.
404  *
405  * @dev: device to check
406  * @return number of size cells this node uses
407  */
408 int dev_read_size_cells(struct udevice *dev);
409
410 /**
411  * dev_read_addr_cells() - Get the address cells property in a node
412  *
413  * This function matches fdt_address_cells().
414  *
415  * @dev: device to check
416  * @return number of address cells this node uses
417  */
418 int dev_read_simple_addr_cells(struct udevice *dev);
419
420 /**
421  * dev_read_size_cells() - Get the size cells property in a node
422  *
423  * This function matches fdt_size_cells().
424  *
425  * @dev: device to check
426  * @return number of size cells this node uses
427  */
428 int dev_read_simple_size_cells(struct udevice *dev);
429
430 /**
431  * dev_read_phandle() - Get the phandle from a device
432  *
433  * @dev: device to check
434  * @return phandle (1 or greater), or 0 if no phandle or other error
435  */
436 int dev_read_phandle(struct udevice *dev);
437
438 /**
439  * dev_read_prop()- - read a property from a device's node
440  *
441  * @dev: device to check
442  * @propname: property to read
443  * @lenp: place to put length on success
444  * @return pointer to property, or NULL if not found
445  */
446 const void *dev_read_prop(struct udevice *dev, const char *propname, int *lenp);
447
448 /**
449  * dev_read_alias_seq() - Get the alias sequence number of a node
450  *
451  * This works out whether a node is pointed to by an alias, and if so, the
452  * sequence number of that alias. Aliases are of the form <base><num> where
453  * <num> is the sequence number. For example spi2 would be sequence number 2.
454  *
455  * @dev: device to look up
456  * @devnump: set to the sequence number if one is found
457  * @return 0 if a sequence was found, -ve if not
458  */
459 int dev_read_alias_seq(struct udevice *dev, int *devnump);
460
461 /**
462  * dev_read_u32_array() - Find and read an array of 32 bit integers
463  *
464  * Search for a property in a device node and read 32-bit value(s) from
465  * it.
466  *
467  * The out_values is modified only if a valid u32 value can be decoded.
468  *
469  * @dev: device to look up
470  * @propname:   name of the property to read
471  * @out_values: pointer to return value, modified only if return value is 0
472  * @sz:         number of array elements to read
473  * @return 0 on success, -EINVAL if the property does not exist, -ENODATA if
474  * property does not have a value, and -EOVERFLOW if the property data isn't
475  * large enough.
476  */
477 int dev_read_u32_array(struct udevice *dev, const char *propname,
478                        u32 *out_values, size_t sz);
479
480 /**
481  * dev_read_first_subnode() - find the first subnode of a device's node
482  *
483  * @dev: device to look up
484  * @return reference to the first subnode (which can be invalid if the device's
485  * node has no subnodes)
486  */
487 ofnode dev_read_first_subnode(struct udevice *dev);
488
489 /**
490  * ofnode_next_subnode() - find the next sibling of a subnode
491  *
492  * @node:       valid reference to previous node (sibling)
493  * @return reference to the next subnode (which can be invalid if the node
494  * has no more siblings)
495  */
496 ofnode dev_read_next_subnode(ofnode node);
497
498 /**
499  * dev_read_u8_array_ptr() - find an 8-bit array
500  *
501  * Look up a device's node property and return a pointer to its contents as a
502  * byte array of given length. The property must have at least enough data
503  * for the array (count bytes). It may have more, but this will be ignored.
504  * The data is not copied.
505  *
506  * @dev: device to look up
507  * @propname: name of property to find
508  * @sz: number of array elements
509  * @return pointer to byte array if found, or NULL if the property is not
510  *              found or there is not enough data
511  */
512 const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname,
513                                      size_t sz);
514
515 /**
516  * dev_read_enabled() - check whether a node is enabled
517  *
518  * This looks for a 'status' property. If this exists, then returns 1 if
519  * the status is 'ok' and 0 otherwise. If there is no status property,
520  * it returns 1 on the assumption that anything mentioned should be enabled
521  * by default.
522  *
523  * @dev: device to examine
524  * @return integer value 0 (not enabled) or 1 (enabled)
525  */
526 int dev_read_enabled(struct udevice *dev);
527
528 /**
529  * dev_read_resource() - obtain an indexed resource from a device.
530  *
531  * @dev: device to examine
532  * @index index of the resource to retrieve (0 = first)
533  * @res returns the resource
534  * @return 0 if ok, negative on error
535  */
536 int dev_read_resource(struct udevice *dev, uint index, struct resource *res);
537
538 /**
539  * dev_read_resource_byname() - obtain a named resource from a device.
540  *
541  * @dev: device to examine
542  * @name: name of the resource to retrieve
543  * @res: returns the resource
544  * @return 0 if ok, negative on error
545  */
546 int dev_read_resource_byname(struct udevice *dev, const char *name,
547                              struct resource *res);
548
549 /**
550  * dev_translate_address() - Translate a device-tree address
551  *
552  * Translate an address from the device-tree into a CPU physical address.  This
553  * function walks up the tree and applies the various bus mappings along the
554  * way.
555  *
556  * @dev: device giving the context in which to translate the address
557  * @in_addr: pointer to the address to translate
558  * @return the translated address; OF_BAD_ADDR on error
559  */
560 u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr);
561
562 /**
563  * dev_translate_dma_address() - Translate a device-tree DMA address
564  *
565  * Translate a DMA address from the device-tree into a CPU physical address.
566  * This function walks up the tree and applies the various bus mappings along
567  * the way.
568  *
569  * @dev: device giving the context in which to translate the DMA address
570  * @in_addr: pointer to the DMA address to translate
571  * @return the translated DMA address; OF_BAD_ADDR on error
572  */
573 u64 dev_translate_dma_address(struct udevice *dev, const fdt32_t *in_addr);
574
575 /**
576  * dev_read_alias_highest_id - Get highest alias id for the given stem
577  * @stem:       Alias stem to be examined
578  *
579  * The function travels the lookup table to get the highest alias id for the
580  * given alias stem.
581  * @return alias ID, if found, else -1
582  */
583 int dev_read_alias_highest_id(const char *stem);
584
585 #else /* CONFIG_DM_DEV_READ_INLINE is enabled */
586
587 static inline int dev_read_u32(struct udevice *dev,
588                                const char *propname, u32 *outp)
589 {
590         return ofnode_read_u32(dev_ofnode(dev), propname, outp);
591 }
592
593 static inline int dev_read_u32_default(struct udevice *dev,
594                                        const char *propname, int def)
595 {
596         return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
597 }
598
599 static inline int dev_read_s32(struct udevice *dev,
600                                const char *propname, s32 *outp)
601 {
602         return ofnode_read_s32(dev_ofnode(dev), propname, outp);
603 }
604
605 static inline int dev_read_s32_default(struct udevice *dev,
606                                        const char *propname, int def)
607 {
608         return ofnode_read_s32_default(dev_ofnode(dev), propname, def);
609 }
610
611 static inline int dev_read_u32u(struct udevice *dev,
612                                 const char *propname, uint *outp)
613 {
614         u32 val;
615         int ret;
616
617         ret = ofnode_read_u32(dev_ofnode(dev), propname, &val);
618         if (ret)
619                 return ret;
620         *outp = val;
621
622         return 0;
623 }
624
625 static inline int dev_read_u64(struct udevice *dev,
626                                const char *propname, u64 *outp)
627 {
628         return ofnode_read_u64(dev_ofnode(dev), propname, outp);
629 }
630
631 static inline u64 dev_read_u64_default(struct udevice *dev,
632                                        const char *propname, u64 def)
633 {
634         return ofnode_read_u64_default(dev_ofnode(dev), propname, def);
635 }
636
637 static inline const char *dev_read_string(struct udevice *dev,
638                                           const char *propname)
639 {
640         return ofnode_read_string(dev_ofnode(dev), propname);
641 }
642
643 static inline bool dev_read_bool(struct udevice *dev, const char *propname)
644 {
645         return ofnode_read_bool(dev_ofnode(dev), propname);
646 }
647
648 static inline ofnode dev_read_subnode(struct udevice *dev,
649                                       const char *subbnode_name)
650 {
651         return ofnode_find_subnode(dev_ofnode(dev), subbnode_name);
652 }
653
654 static inline int dev_read_size(struct udevice *dev, const char *propname)
655 {
656         return ofnode_read_size(dev_ofnode(dev), propname);
657 }
658
659 static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index)
660 {
661         return devfdt_get_addr_index(dev, index);
662 }
663
664 static inline fdt_addr_t dev_read_addr_size_index(struct udevice *dev,
665                                                   int index,
666                                                   fdt_size_t *size)
667 {
668         return devfdt_get_addr_size_index(dev, index, size);
669 }
670
671 static inline fdt_addr_t dev_read_addr_name(struct udevice *dev,
672                                             const char *name)
673 {
674         return devfdt_get_addr_name(dev, name);
675 }
676
677 static inline fdt_addr_t dev_read_addr_size_name(struct udevice *dev,
678                                                  const char *name,
679                                                  fdt_size_t *size)
680 {
681         return devfdt_get_addr_size_name(dev, name, size);
682 }
683
684 static inline fdt_addr_t dev_read_addr(struct udevice *dev)
685 {
686         return devfdt_get_addr(dev);
687 }
688
689 static inline void *dev_read_addr_ptr(struct udevice *dev)
690 {
691         return devfdt_get_addr_ptr(dev);
692 }
693
694 static inline void *dev_remap_addr(struct udevice *dev)
695 {
696         return devfdt_remap_addr(dev);
697 }
698
699 static inline void *dev_remap_addr_index(struct udevice *dev, int index)
700 {
701         return devfdt_remap_addr_index(dev, index);
702 }
703
704 static inline void *dev_remap_addr_name(struct udevice *dev, const char *name)
705 {
706         return devfdt_remap_addr_name(dev, name);
707 }
708
709 static inline fdt_addr_t dev_read_addr_size(struct udevice *dev,
710                                             const char *propname,
711                                             fdt_size_t *sizep)
712 {
713         return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep);
714 }
715
716 static inline const char *dev_read_name(struct udevice *dev)
717 {
718         return ofnode_get_name(dev_ofnode(dev));
719 }
720
721 static inline int dev_read_stringlist_search(struct udevice *dev,
722                                              const char *propname,
723                                              const char *string)
724 {
725         return ofnode_stringlist_search(dev_ofnode(dev), propname, string);
726 }
727
728 static inline int dev_read_string_index(struct udevice *dev,
729                                         const char *propname, int index,
730                                         const char **outp)
731 {
732         return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp);
733 }
734
735 static inline int dev_read_string_count(struct udevice *dev,
736                                         const char *propname)
737 {
738         return ofnode_read_string_count(dev_ofnode(dev), propname);
739 }
740
741 static inline int dev_read_phandle_with_args(struct udevice *dev,
742                 const char *list_name, const char *cells_name, int cell_count,
743                 int index, struct ofnode_phandle_args *out_args)
744 {
745         return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name,
746                                               cells_name, cell_count, index,
747                                               out_args);
748 }
749
750 static inline int dev_count_phandle_with_args(struct udevice *dev,
751                 const char *list_name, const char *cells_name)
752 {
753         return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
754                                               cells_name);
755 }
756
757 static inline int dev_read_addr_cells(struct udevice *dev)
758 {
759         /* NOTE: this call should walk up the parent stack */
760         return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
761 }
762
763 static inline int dev_read_size_cells(struct udevice *dev)
764 {
765         /* NOTE: this call should walk up the parent stack */
766         return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
767 }
768
769 static inline int dev_read_simple_addr_cells(struct udevice *dev)
770 {
771         return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
772 }
773
774 static inline int dev_read_simple_size_cells(struct udevice *dev)
775 {
776         return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
777 }
778
779 static inline int dev_read_phandle(struct udevice *dev)
780 {
781         return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev));
782 }
783
784 static inline const void *dev_read_prop(struct udevice *dev,
785                                         const char *propname, int *lenp)
786 {
787         return ofnode_get_property(dev_ofnode(dev), propname, lenp);
788 }
789
790 static inline int dev_read_alias_seq(struct udevice *dev, int *devnump)
791 {
792         return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name,
793                                     dev_of_offset(dev), devnump);
794 }
795
796 static inline int dev_read_u32_array(struct udevice *dev, const char *propname,
797                                      u32 *out_values, size_t sz)
798 {
799         return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
800 }
801
802 static inline ofnode dev_read_first_subnode(struct udevice *dev)
803 {
804         return ofnode_first_subnode(dev_ofnode(dev));
805 }
806
807 static inline ofnode dev_read_next_subnode(ofnode node)
808 {
809         return ofnode_next_subnode(node);
810 }
811
812 static inline const uint8_t *dev_read_u8_array_ptr(struct udevice *dev,
813                                         const char *propname, size_t sz)
814 {
815         return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
816 }
817
818 static inline int dev_read_enabled(struct udevice *dev)
819 {
820         return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev));
821 }
822
823 static inline int dev_read_resource(struct udevice *dev, uint index,
824                                     struct resource *res)
825 {
826         return ofnode_read_resource(dev_ofnode(dev), index, res);
827 }
828
829 static inline int dev_read_resource_byname(struct udevice *dev,
830                                            const char *name,
831                                            struct resource *res)
832 {
833         return ofnode_read_resource_byname(dev_ofnode(dev), name, res);
834 }
835
836 static inline u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr)
837 {
838         return ofnode_translate_address(dev_ofnode(dev), in_addr);
839 }
840
841 static inline u64 dev_translate_dma_address(struct udevice *dev, const fdt32_t *in_addr)
842 {
843         return ofnode_translate_dma_address(dev_ofnode(dev), in_addr);
844 }
845
846 static inline int dev_read_alias_highest_id(const char *stem)
847 {
848         return fdtdec_get_alias_highest_id(gd->fdt_blob, stem);
849 }
850
851 #endif /* CONFIG_DM_DEV_READ_INLINE */
852
853 /**
854  * dev_for_each_subnode() - Helper function to iterate through subnodes
855  *
856  * This creates a for() loop which works through the subnodes in a device's
857  * device-tree node.
858  *
859  * @subnode: ofnode holding the current subnode
860  * @dev: device to use for interation (struct udevice *)
861  */
862 #define dev_for_each_subnode(subnode, dev) \
863         for (subnode = dev_read_first_subnode(dev); \
864              ofnode_valid(subnode); \
865              subnode = ofnode_next_subnode(subnode))
866
867 #endif