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