blob: a27b8554fb1c7808cf323470c5507bd07795b01d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glass34ef0c22017-05-18 20:09:03 -06002/*
3 * Function to read values from the device tree node attached to a udevice.
4 *
5 * Copyright (c) 2017 Google, Inc
6 * Written by Simon Glass <sjg@chromium.org>
Simon Glass34ef0c22017-05-18 20:09:03 -06007 */
8
9#ifndef _DM_READ_H
10#define _DM_READ_H
11
12#include <dm/fdtaddr.h>
13#include <dm/ofnode.h>
14#include <dm/uclass.h>
15
Simon Glass170e17c2017-06-12 06:21:29 -060016struct resource;
17
Simon Glass34ef0c22017-05-18 20:09:03 -060018#if CONFIG_IS_ENABLED(OF_LIVE)
19static inline const struct device_node *dev_np(struct udevice *dev)
20{
21 return ofnode_to_np(dev->node);
22}
23#else
24static 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 */
36static inline ofnode dev_ofnode(struct udevice *dev)
37{
38 return dev->node;
39}
40
41static inline bool dev_of_valid(struct udevice *dev)
42{
43 return ofnode_valid(dev_ofnode(dev));
44}
45
Simon Glasscfdae5c2017-05-18 20:09:04 -060046#ifndef CONFIG_DM_DEV_READ_INLINE
47/**
Masahiro Yamada71d115f2017-12-30 02:00:05 +090048 * dev_read_u32() - read a 32-bit integer from a device's DT property
49 *
50 * @dev: device to read DT property from
51 * @propname: name of the property to read from
52 * @outp: place to put value (if found)
53 * @return 0 if OK, -ve on error
54 */
55int dev_read_u32(struct udevice *dev, const char *propname, u32 *outp);
56
57/**
Simon Glasscfdae5c2017-05-18 20:09:04 -060058 * dev_read_u32_default() - read a 32-bit integer from a device's DT property
59 *
60 * @dev: device to read DT property from
61 * @propname: name of the property to read from
62 * @def: default value to return if the property has no value
63 * @return property value, or @def if not found
64 */
65int dev_read_u32_default(struct udevice *dev, const char *propname, int def);
Simon Glass34ef0c22017-05-18 20:09:03 -060066
67/**
68 * dev_read_string() - Read a string from a device's DT property
69 *
70 * @dev: device to read DT property from
71 * @propname: name of the property to read
72 * @return string from property value, or NULL if there is no such property
73 */
Simon Glasscfdae5c2017-05-18 20:09:04 -060074const char *dev_read_string(struct udevice *dev, const char *propname);
Simon Glass34ef0c22017-05-18 20:09:03 -060075
76/**
77 * dev_read_bool() - read a boolean value from a device's DT property
78 *
79 * @dev: device to read DT property from
80 * @propname: name of property to read
81 * @return true if property is present (meaning true), false if not present
82 */
Simon Glasscfdae5c2017-05-18 20:09:04 -060083bool dev_read_bool(struct udevice *dev, const char *propname);
Simon Glass34ef0c22017-05-18 20:09:03 -060084
85/**
86 * dev_read_subnode() - find a named subnode of a device
87 *
88 * @dev: device whose DT node contains the subnode
89 * @subnode_name: name of subnode to find
90 * @return reference to subnode (which can be invalid if there is no such
91 * subnode)
92 */
Simon Glasscfdae5c2017-05-18 20:09:04 -060093ofnode dev_read_subnode(struct udevice *dev, const char *subbnode_name);
Simon Glass34ef0c22017-05-18 20:09:03 -060094
95/**
96 * dev_read_size() - read the size of a property
97 *
98 * @dev: device to check
99 * @propname: property to check
100 * @return size of property if present, or -EINVAL if not
101 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600102int dev_read_size(struct udevice *dev, const char *propname);
Simon Glass34ef0c22017-05-18 20:09:03 -0600103
104/**
105 * dev_read_addr_index() - Get the indexed reg property of a device
106 *
107 * @dev: Device to read from
108 * @index: the 'reg' property can hold a list of <addr, size> pairs
109 * and @index is used to select which one is required
110 *
111 * @return address or FDT_ADDR_T_NONE if not found
112 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600113fdt_addr_t dev_read_addr_index(struct udevice *dev, int index);
Simon Glass34ef0c22017-05-18 20:09:03 -0600114
115/**
Álvaro Fernández Rojas670361292018-04-29 21:56:54 +0200116 * dev_remap_addr_index() - Get the indexed reg property of a device
117 * as a memory-mapped I/O pointer
118 *
119 * @dev: Device to read from
120 * @index: the 'reg' property can hold a list of <addr, size> pairs
121 * and @index is used to select which one is required
122 *
123 * @return pointer or NULL if not found
124 */
125void *dev_remap_addr_index(struct udevice *dev, int index);
126
127/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600128 * dev_read_addr() - Get the reg property of a device
129 *
130 * @dev: Device to read from
131 *
132 * @return address or FDT_ADDR_T_NONE if not found
133 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600134fdt_addr_t dev_read_addr(struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600135
136/**
Philipp Tomsich7719b392017-09-11 22:04:12 +0200137 * dev_read_addr_ptr() - Get the reg property of a device
138 * as a pointer
139 *
140 * @dev: Device to read from
141 *
142 * @return pointer or NULL if not found
143 */
144void *dev_read_addr_ptr(struct udevice *dev);
145
146/**
Álvaro Fernández Rojas670361292018-04-29 21:56:54 +0200147 * dev_remap_addr() - Get the reg property of a device as a
148 * memory-mapped I/O pointer
149 *
150 * @dev: Device to read from
151 *
152 * @return pointer or NULL if not found
153 */
154void *dev_remap_addr(struct udevice *dev);
155
156/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600157 * dev_read_addr_size() - get address and size from a device property
158 *
159 * This does no address translation. It simply reads an property that contains
160 * an address and a size value, one after the other.
161 *
162 * @dev: Device to read from
163 * @propname: property to read
164 * @sizep: place to put size value (on success)
165 * @return address value, or FDT_ADDR_T_NONE on error
166 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600167fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *propname,
168 fdt_size_t *sizep);
Simon Glass34ef0c22017-05-18 20:09:03 -0600169
170/**
171 * dev_read_name() - get the name of a device's node
172 *
173 * @node: valid node to look up
174 * @return name of node
175 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600176const char *dev_read_name(struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600177
178/**
179 * dev_read_stringlist_search() - find string in a string list and return index
180 *
181 * Note that it is possible for this function to succeed on property values
182 * that are not NUL-terminated. That's because the function will stop after
183 * finding the first occurrence of @string. This can for example happen with
184 * small-valued cell properties, such as #address-cells, when searching for
185 * the empty string.
186 *
187 * @dev: device to check
188 * @propname: name of the property containing the string list
189 * @string: string to look up in the string list
190 *
191 * @return:
192 * the index of the string in the list of strings
193 * -ENODATA if the property is not found
194 * -EINVAL on some other error
195 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600196int dev_read_stringlist_search(struct udevice *dev, const char *property,
197 const char *string);
Simon Glass34ef0c22017-05-18 20:09:03 -0600198
199/**
Jean-Jacques Hiblot8365ebd2017-09-21 17:03:09 +0200200 * dev_read_string_index() - obtain an indexed string from a string list
201 *
202 * @dev: device to examine
203 * @propname: name of the property containing the string list
204 * @index: index of the string to return
205 * @out: return location for the string
206 *
207 * @return:
208 * length of string, if found or -ve error value if not found
209 */
210int dev_read_string_index(struct udevice *dev, const char *propname, int index,
211 const char **outp);
212
213/**
214 * dev_read_string_count() - find the number of strings in a string list
215 *
216 * @dev: device to examine
217 * @propname: name of the property containing the string list
218 * @return:
219 * number of strings in the list, or -ve error value if not found
220 */
221int dev_read_string_count(struct udevice *dev, const char *propname);
222/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600223 * dev_read_phandle_with_args() - Find a node pointed by phandle in a list
224 *
225 * This function is useful to parse lists of phandles and their arguments.
226 * Returns 0 on success and fills out_args, on error returns appropriate
227 * errno value.
228 *
229 * Caller is responsible to call of_node_put() on the returned out_args->np
230 * pointer.
231 *
232 * Example:
233 *
234 * phandle1: node1 {
235 * #list-cells = <2>;
236 * }
237 *
238 * phandle2: node2 {
239 * #list-cells = <1>;
240 * }
241 *
242 * node3 {
243 * list = <&phandle1 1 2 &phandle2 3>;
244 * }
245 *
246 * To get a device_node of the `node2' node you may call this:
247 * dev_read_phandle_with_args(dev, "list", "#list-cells", 0, 1, &args);
248 *
249 * @dev: device whose node containing a list
250 * @list_name: property name that contains a list
251 * @cells_name: property name that specifies phandles' arguments count
252 * @cells_count: Cell count to use if @cells_name is NULL
253 * @index: index of a phandle to parse out
254 * @out_args: optional pointer to output arguments structure (will be filled)
255 * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
256 * @list_name does not exist, -EINVAL if a phandle was not found,
257 * @cells_name could not be found, the arguments were truncated or there
258 * were too many arguments.
259 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600260int dev_read_phandle_with_args(struct udevice *dev, const char *list_name,
261 const char *cells_name, int cell_count,
262 int index,
263 struct ofnode_phandle_args *out_args);
Simon Glass34ef0c22017-05-18 20:09:03 -0600264
265/**
Patrice Chotardbe7dd602017-07-18 11:57:08 +0200266 * dev_count_phandle_with_args() - Return phandle number in a list
267 *
268 * This function is usefull to get phandle number contained in a property list.
269 * For example, this allows to allocate the right amount of memory to keep
270 * clock's reference contained into the "clocks" property.
271 *
272 *
273 * @dev: device whose node containing a list
274 * @list_name: property name that contains a list
275 * @cells_name: property name that specifies phandles' arguments count
276 * @Returns number of phandle found on success, on error returns appropriate
277 * errno value.
278 */
279
280int dev_count_phandle_with_args(struct udevice *dev, const char *list_name,
281 const char *cells_name);
282
283/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600284 * dev_read_addr_cells() - Get the number of address cells for a device's node
285 *
286 * This walks back up the tree to find the closest #address-cells property
287 * which controls the given node.
288 *
Mario Six16408ee2018-01-15 11:09:36 +0100289 * @dev: device to check
Simon Glass34ef0c22017-05-18 20:09:03 -0600290 * @return number of address cells this node uses
291 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600292int dev_read_addr_cells(struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600293
294/**
295 * dev_read_size_cells() - Get the number of size cells for a device's node
296 *
297 * This walks back up the tree to find the closest #size-cells property
298 * which controls the given node.
299 *
Mario Six16408ee2018-01-15 11:09:36 +0100300 * @dev: device to check
Simon Glass34ef0c22017-05-18 20:09:03 -0600301 * @return number of size cells this node uses
302 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600303int dev_read_size_cells(struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600304
305/**
Simon Glass4191dc12017-06-12 06:21:31 -0600306 * dev_read_addr_cells() - Get the address cells property in a node
307 *
308 * This function matches fdt_address_cells().
309 *
Mario Six16408ee2018-01-15 11:09:36 +0100310 * @dev: device to check
Simon Glass4191dc12017-06-12 06:21:31 -0600311 * @return number of address cells this node uses
312 */
313int dev_read_simple_addr_cells(struct udevice *dev);
314
315/**
316 * dev_read_size_cells() - Get the size cells property in a node
317 *
318 * This function matches fdt_size_cells().
319 *
Mario Six16408ee2018-01-15 11:09:36 +0100320 * @dev: device to check
Simon Glass4191dc12017-06-12 06:21:31 -0600321 * @return number of size cells this node uses
322 */
323int dev_read_simple_size_cells(struct udevice *dev);
324
325/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600326 * dev_read_phandle() - Get the phandle from a device
327 *
328 * @dev: device to check
329 * @return phandle (1 or greater), or 0 if no phandle or other error
330 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600331int dev_read_phandle(struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600332
333/**
334 * dev_read_prop()- - read a property from a device's node
335 *
336 * @dev: device to check
337 * @propname: property to read
338 * @lenp: place to put length on success
339 * @return pointer to property, or NULL if not found
340 */
Masahiro Yamadabaebec12017-07-17 12:18:39 +0900341const void *dev_read_prop(struct udevice *dev, const char *propname, int *lenp);
Simon Glass34ef0c22017-05-18 20:09:03 -0600342
343/**
344 * dev_read_alias_seq() - Get the alias sequence number of a node
345 *
346 * This works out whether a node is pointed to by an alias, and if so, the
347 * sequence number of that alias. Aliases are of the form <base><num> where
348 * <num> is the sequence number. For example spi2 would be sequence number 2.
349 *
350 * @dev: device to look up
351 * @devnump: set to the sequence number if one is found
352 * @return 0 if a sequence was found, -ve if not
353 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600354int dev_read_alias_seq(struct udevice *dev, int *devnump);
Simon Glass34ef0c22017-05-18 20:09:03 -0600355
356/**
357 * dev_read_u32_array() - Find and read an array of 32 bit integers
358 *
359 * Search for a property in a device node and read 32-bit value(s) from
360 * it.
361 *
362 * The out_values is modified only if a valid u32 value can be decoded.
363 *
364 * @dev: device to look up
365 * @propname: name of the property to read
366 * @out_values: pointer to return value, modified only if return value is 0
367 * @sz: number of array elements to read
368 * @return 0 on success, -EINVAL if the property does not exist, -ENODATA if
369 * property does not have a value, and -EOVERFLOW if the property data isn't
370 * large enough.
371 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600372int dev_read_u32_array(struct udevice *dev, const char *propname,
373 u32 *out_values, size_t sz);
Simon Glass34ef0c22017-05-18 20:09:03 -0600374
375/**
376 * dev_read_first_subnode() - find the first subnode of a device's node
377 *
378 * @dev: device to look up
379 * @return reference to the first subnode (which can be invalid if the device's
380 * node has no subnodes)
381 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600382ofnode dev_read_first_subnode(struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600383
384/**
385 * ofnode_next_subnode() - find the next sibling of a subnode
386 *
387 * @node: valid reference to previous node (sibling)
388 * @return reference to the next subnode (which can be invalid if the node
389 * has no more siblings)
390 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600391ofnode dev_read_next_subnode(ofnode node);
Simon Glass34ef0c22017-05-18 20:09:03 -0600392
393/**
394 * dev_read_u8_array_ptr() - find an 8-bit array
395 *
396 * Look up a device's node property and return a pointer to its contents as a
397 * byte array of given length. The property must have at least enough data
398 * for the array (count bytes). It may have more, but this will be ignored.
399 * The data is not copied.
400 *
401 * @dev: device to look up
402 * @propname: name of property to find
403 * @sz: number of array elements
404 * @return pointer to byte array if found, or NULL if the property is not
405 * found or there is not enough data
406 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600407const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname,
408 size_t sz);
409
Simon Glassfa031f82017-06-12 06:21:30 -0600410/**
411 * dev_read_enabled() - check whether a node is enabled
412 *
413 * This looks for a 'status' property. If this exists, then returns 1 if
414 * the status is 'ok' and 0 otherwise. If there is no status property,
415 * it returns 1 on the assumption that anything mentioned should be enabled
416 * by default.
417 *
418 * @dev: device to examine
419 * @return integer value 0 (not enabled) or 1 (enabled)
420 */
421int dev_read_enabled(struct udevice *dev);
422
Simon Glassf7bfcc42017-07-25 08:29:55 -0600423/**
424 * dev_read_resource() - obtain an indexed resource from a device.
425 *
Masahiro Yamada4dada2c2017-08-26 01:12:30 +0900426 * @dev: device to examine
Simon Glassf7bfcc42017-07-25 08:29:55 -0600427 * @index index of the resource to retrieve (0 = first)
428 * @res returns the resource
429 * @return 0 if ok, negative on error
430 */
431int dev_read_resource(struct udevice *dev, uint index, struct resource *res);
432
Masahiro Yamada4dada2c2017-08-26 01:12:30 +0900433/**
434 * dev_read_resource_byname() - obtain a named resource from a device.
435 *
436 * @dev: device to examine
437 * @name: name of the resource to retrieve
438 * @res: returns the resource
439 * @return 0 if ok, negative on error
440 */
441int dev_read_resource_byname(struct udevice *dev, const char *name,
442 struct resource *res);
443
Mario Sixaefac062018-01-15 11:07:19 +0100444/**
445 * dev_translate_address() - Tranlate a device-tree address
446 *
447 * Translate an address from the device-tree into a CPU physical address. This
448 * function walks up the tree and applies the various bus mappings along the
449 * way.
450 *
451 * @dev: device giving the context in which to translate the address
452 * @in_addr: pointer to the address to translate
453 * @return the translated address; OF_BAD_ADDR on error
454 */
455u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr);
Simon Glasscfdae5c2017-05-18 20:09:04 -0600456#else /* CONFIG_DM_DEV_READ_INLINE is enabled */
457
Masahiro Yamada71d115f2017-12-30 02:00:05 +0900458static inline int dev_read_u32(struct udevice *dev,
459 const char *propname, u32 *outp)
460{
461 return ofnode_read_u32(dev_ofnode(dev), propname, outp);
462}
463
Simon Glasscfdae5c2017-05-18 20:09:04 -0600464static inline int dev_read_u32_default(struct udevice *dev,
465 const char *propname, int def)
466{
467 return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
468}
469
470static inline const char *dev_read_string(struct udevice *dev,
471 const char *propname)
472{
473 return ofnode_read_string(dev_ofnode(dev), propname);
474}
475
476static inline bool dev_read_bool(struct udevice *dev, const char *propname)
477{
478 return ofnode_read_bool(dev_ofnode(dev), propname);
479}
480
481static inline ofnode dev_read_subnode(struct udevice *dev,
482 const char *subbnode_name)
483{
484 return ofnode_find_subnode(dev_ofnode(dev), subbnode_name);
485}
486
487static inline int dev_read_size(struct udevice *dev, const char *propname)
488{
489 return ofnode_read_size(dev_ofnode(dev), propname);
490}
491
492static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index)
493{
494 return devfdt_get_addr_index(dev, index);
495}
496
497static inline fdt_addr_t dev_read_addr(struct udevice *dev)
498{
499 return devfdt_get_addr(dev);
500}
501
Philipp Tomsich7719b392017-09-11 22:04:12 +0200502static inline void *dev_read_addr_ptr(struct udevice *dev)
503{
504 return devfdt_get_addr_ptr(dev);
505}
506
Álvaro Fernández Rojas670361292018-04-29 21:56:54 +0200507static inline void *dev_remap_addr(struct udevice *dev)
508{
509 return devfdt_remap_addr(dev);
510}
511
512static inline void *dev_remap_addr_index(struct udevice *dev, int index)
513{
514 return devfdt_remap_addr_index(dev, index);
515}
516
Simon Glasscfdae5c2017-05-18 20:09:04 -0600517static inline fdt_addr_t dev_read_addr_size(struct udevice *dev,
518 const char *propname,
519 fdt_size_t *sizep)
520{
521 return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep);
522}
523
524static inline const char *dev_read_name(struct udevice *dev)
525{
526 return ofnode_get_name(dev_ofnode(dev));
527}
528
529static inline int dev_read_stringlist_search(struct udevice *dev,
530 const char *propname,
531 const char *string)
532{
533 return ofnode_stringlist_search(dev_ofnode(dev), propname, string);
534}
535
Jean-Jacques Hiblot8365ebd2017-09-21 17:03:09 +0200536static inline int dev_read_string_index(struct udevice *dev,
537 const char *propname, int index,
538 const char **outp)
539{
540 return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp);
541}
542
543static inline int dev_read_string_count(struct udevice *dev,
544 const char *propname)
545{
546 return ofnode_read_string_count(dev_ofnode(dev), propname);
547}
548
Simon Glasscfdae5c2017-05-18 20:09:04 -0600549static inline int dev_read_phandle_with_args(struct udevice *dev,
550 const char *list_name, const char *cells_name, int cell_count,
551 int index, struct ofnode_phandle_args *out_args)
552{
553 return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name,
554 cells_name, cell_count, index,
555 out_args);
556}
557
Patrice Chotardbe7dd602017-07-18 11:57:08 +0200558static inline int dev_count_phandle_with_args(struct udevice *dev,
559 const char *list_name, const char *cells_name)
560{
561 return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
562 cells_name);
563}
564
Simon Glasscfdae5c2017-05-18 20:09:04 -0600565static inline int dev_read_addr_cells(struct udevice *dev)
566{
Simon Glass4191dc12017-06-12 06:21:31 -0600567 /* NOTE: this call should walk up the parent stack */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600568 return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
569}
570
571static inline int dev_read_size_cells(struct udevice *dev)
572{
Simon Glass4191dc12017-06-12 06:21:31 -0600573 /* NOTE: this call should walk up the parent stack */
574 return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
575}
576
577static inline int dev_read_simple_addr_cells(struct udevice *dev)
578{
579 return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
580}
581
582static inline int dev_read_simple_size_cells(struct udevice *dev)
583{
Simon Glasscfdae5c2017-05-18 20:09:04 -0600584 return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
585}
586
587static inline int dev_read_phandle(struct udevice *dev)
588{
589 return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev));
590}
591
Masahiro Yamadabaebec12017-07-17 12:18:39 +0900592static inline const void *dev_read_prop(struct udevice *dev,
593 const char *propname, int *lenp)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600594{
Masahiro Yamada9cf85cb2017-06-22 16:54:05 +0900595 return ofnode_get_property(dev_ofnode(dev), propname, lenp);
Simon Glasscfdae5c2017-05-18 20:09:04 -0600596}
597
598static inline int dev_read_alias_seq(struct udevice *dev, int *devnump)
599{
600 return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name,
601 dev_of_offset(dev), devnump);
602}
603
604static inline int dev_read_u32_array(struct udevice *dev, const char *propname,
605 u32 *out_values, size_t sz)
606{
607 return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
608}
609
610static inline ofnode dev_read_first_subnode(struct udevice *dev)
611{
612 return ofnode_first_subnode(dev_ofnode(dev));
613}
614
615static inline ofnode dev_read_next_subnode(ofnode node)
616{
617 return ofnode_next_subnode(node);
618}
619
Simon Glass34ef0c22017-05-18 20:09:03 -0600620static inline const uint8_t *dev_read_u8_array_ptr(struct udevice *dev,
621 const char *propname, size_t sz)
622{
623 return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
624}
625
Simon Glassfa031f82017-06-12 06:21:30 -0600626static inline int dev_read_enabled(struct udevice *dev)
627{
628 return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev));
629}
630
Simon Glassf7bfcc42017-07-25 08:29:55 -0600631static inline int dev_read_resource(struct udevice *dev, uint index,
632 struct resource *res)
633{
634 return ofnode_read_resource(dev_ofnode(dev), index, res);
635}
636
Masahiro Yamada4dada2c2017-08-26 01:12:30 +0900637static inline int dev_read_resource_byname(struct udevice *dev,
638 const char *name,
639 struct resource *res)
640{
641 return ofnode_read_resource_byname(dev_ofnode(dev), name, res);
642}
643
Mario Sixaefac062018-01-15 11:07:19 +0100644static inline u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr)
645{
646 return ofnode_translate_address(dev_ofnode(dev), in_addr);
647}
648
Simon Glass34ef0c22017-05-18 20:09:03 -0600649#endif /* CONFIG_DM_DEV_READ_INLINE */
650
651/**
652 * dev_for_each_subnode() - Helper function to iterate through subnodes
653 *
654 * This creates a for() loop which works through the subnodes in a device's
655 * device-tree node.
656 *
657 * @subnode: ofnode holding the current subnode
658 * @dev: device to use for interation (struct udevice *)
659 */
660#define dev_for_each_subnode(subnode, dev) \
661 for (subnode = dev_read_first_subnode(dev); \
662 ofnode_valid(subnode); \
663 subnode = ofnode_next_subnode(subnode))
664
665#endif