• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)
dev_np(struct udevice * dev)19 static inline const struct device_node *dev_np(struct udevice *dev)
20 {
21 	return ofnode_to_np(dev->node);
22 }
23 #else
dev_np(struct udevice * dev)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  */
dev_ofnode(struct udevice * dev)36 static inline ofnode dev_ofnode(struct udevice *dev)
37 {
38 	return dev->node;
39 }
40 
dev_of_valid(struct udevice * dev)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_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 /**
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 /**
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  */
292 fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *propname,
293 				fdt_size_t *sizep);
294 
295 /**
296  * dev_read_name() - get the name of a device's node
297  *
298  * @dev: Device to read from
299  * @return name of node
300  */
301 const char *dev_read_name(struct udevice *dev);
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  */
321 int dev_read_stringlist_search(struct udevice *dev, const char *property,
322 			  const char *string);
323 
324 /**
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 /**
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  */
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);
389 
390 /**
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 /**
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  *
414  * @dev: device to check
415  * @return number of address cells this node uses
416  */
417 int dev_read_addr_cells(struct udevice *dev);
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  *
425  * @dev: device to check
426  * @return number of size cells this node uses
427  */
428 int dev_read_size_cells(struct udevice *dev);
429 
430 /**
431  * dev_read_addr_cells() - Get the address cells property in a node
432  *
433  * This function matches fdt_address_cells().
434  *
435  * @dev: device to check
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  *
445  * @dev: device to check
446  * @return number of size cells this node uses
447  */
448 int dev_read_simple_size_cells(struct udevice *dev);
449 
450 /**
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  */
456 int dev_read_phandle(struct udevice *dev);
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  */
466 const void *dev_read_prop(struct udevice *dev, const char *propname, int *lenp);
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  */
479 int dev_read_alias_seq(struct udevice *dev, int *devnump);
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  */
497 int dev_read_u32_array(struct udevice *dev, const char *propname,
498 		       u32 *out_values, size_t sz);
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  */
507 ofnode dev_read_first_subnode(struct udevice *dev);
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  */
516 ofnode dev_read_next_subnode(ofnode node);
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  */
532 const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname,
533 				     size_t sz);
534 
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 
548 /**
549  * dev_read_resource() - obtain an indexed resource from a device.
550  *
551  * @dev: device to examine
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 
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 
569 /**
570  * dev_translate_address() - Translate a device-tree address
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);
581 
582 /**
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 /**
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 
605 #else /* CONFIG_DM_DEV_READ_INLINE is enabled */
606 
dev_read_u32(struct udevice * dev,const char * propname,u32 * outp)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 
dev_read_u32_default(struct udevice * dev,const char * propname,int def)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 
dev_read_s32(struct udevice * dev,const char * propname,s32 * outp)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 
dev_read_s32_default(struct udevice * dev,const char * propname,int def)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 
dev_read_u32u(struct udevice * dev,const char * propname,uint * outp)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 
dev_read_u64(struct udevice * dev,const char * propname,u64 * outp)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 
dev_read_u64_default(struct udevice * dev,const char * propname,u64 def)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 
dev_read_string(struct udevice * dev,const char * propname)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 
dev_read_bool(struct udevice * dev,const char * propname)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 
dev_read_subnode(struct udevice * dev,const char * subbnode_name)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 
dev_read_size(struct udevice * dev,const char * propname)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 
dev_read_addr_index(struct udevice * dev,int index)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 
dev_read_addr_size_index(struct udevice * dev,int index,fdt_size_t * size)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 
dev_read_addr_name(struct udevice * dev,const char * name)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 
dev_read_addr_size_name(struct udevice * dev,const char * name,fdt_size_t * size)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 
dev_read_addr(struct udevice * dev)704 static inline fdt_addr_t dev_read_addr(struct udevice *dev)
705 {
706 	return devfdt_get_addr(dev);
707 }
708 
dev_read_addr_ptr(struct udevice * dev)709 static inline void *dev_read_addr_ptr(struct udevice *dev)
710 {
711 	return devfdt_get_addr_ptr(dev);
712 }
713 
dev_read_addr_pci(struct udevice * dev)714 static inline fdt_addr_t dev_read_addr_pci(struct udevice *dev)
715 {
716 	return devfdt_get_addr_pci(dev);
717 }
718 
dev_remap_addr(struct udevice * dev)719 static inline void *dev_remap_addr(struct udevice *dev)
720 {
721 	return devfdt_remap_addr(dev);
722 }
723 
dev_remap_addr_index(struct udevice * dev,int index)724 static inline void *dev_remap_addr_index(struct udevice *dev, int index)
725 {
726 	return devfdt_remap_addr_index(dev, index);
727 }
728 
dev_remap_addr_name(struct udevice * dev,const char * name)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 
dev_read_addr_size(struct udevice * dev,const char * propname,fdt_size_t * sizep)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 
dev_read_name(struct udevice * dev)741 static inline const char *dev_read_name(struct udevice *dev)
742 {
743 	return ofnode_get_name(dev_ofnode(dev));
744 }
745 
dev_read_stringlist_search(struct udevice * dev,const char * propname,const char * string)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 
dev_read_string_index(struct udevice * dev,const char * propname,int index,const char ** outp)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 
dev_read_string_count(struct udevice * dev,const char * propname)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 
dev_read_phandle_with_args(struct udevice * dev,const char * list_name,const char * cells_name,int cell_count,int index,struct ofnode_phandle_args * out_args)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 
dev_count_phandle_with_args(struct udevice * dev,const char * list_name,const char * cells_name)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 
dev_read_addr_cells(struct udevice * dev)782 static inline int dev_read_addr_cells(struct udevice *dev)
783 {
784 	/* NOTE: this call should walk up the parent stack */
785 	return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
786 }
787 
dev_read_size_cells(struct udevice * dev)788 static inline int dev_read_size_cells(struct udevice *dev)
789 {
790 	/* NOTE: this call should walk up the parent stack */
791 	return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
792 }
793 
dev_read_simple_addr_cells(struct udevice * dev)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 
dev_read_simple_size_cells(struct udevice * dev)799 static inline int dev_read_simple_size_cells(struct udevice *dev)
800 {
801 	return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
802 }
803 
dev_read_phandle(struct udevice * dev)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 
dev_read_prop(struct udevice * dev,const char * propname,int * lenp)809 static inline const void *dev_read_prop(struct udevice *dev,
810 					const char *propname, int *lenp)
811 {
812 	return ofnode_get_property(dev_ofnode(dev), propname, lenp);
813 }
814 
dev_read_alias_seq(struct udevice * dev,int * devnump)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 
dev_read_u32_array(struct udevice * dev,const char * propname,u32 * out_values,size_t sz)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 
dev_read_first_subnode(struct udevice * dev)827 static inline ofnode dev_read_first_subnode(struct udevice *dev)
828 {
829 	return ofnode_first_subnode(dev_ofnode(dev));
830 }
831 
dev_read_next_subnode(ofnode node)832 static inline ofnode dev_read_next_subnode(ofnode node)
833 {
834 	return ofnode_next_subnode(node);
835 }
836 
dev_read_u8_array_ptr(struct udevice * dev,const char * propname,size_t sz)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 
dev_read_enabled(struct udevice * dev)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 
dev_read_resource(struct udevice * dev,uint index,struct resource * res)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 
dev_read_resource_byname(struct udevice * dev,const char * name,struct resource * res)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 
dev_translate_address(struct udevice * dev,const fdt32_t * in_addr)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 
dev_translate_dma_address(struct udevice * dev,const fdt32_t * in_addr)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 
dev_read_alias_highest_id(const char * stem)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 
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
893