blob: f14c7a7ba87c716a6ba0e26f8e343ee8871f47da [file] [log] [blame]
Simon Glass34ef0c22017-05-18 20:09:03 -06001/*
2 * Function to read values from the device tree node attached to a udevice.
3 *
4 * Copyright (c) 2017 Google, Inc
5 * Written by Simon Glass <sjg@chromium.org>
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10#ifndef _DM_READ_H
11#define _DM_READ_H
12
13#include <dm/fdtaddr.h>
14#include <dm/ofnode.h>
15#include <dm/uclass.h>
16
Simon Glass170e17c2017-06-12 06:21:29 -060017struct resource;
18
Simon Glass34ef0c22017-05-18 20:09:03 -060019#if CONFIG_IS_ENABLED(OF_LIVE)
20static inline const struct device_node *dev_np(struct udevice *dev)
21{
22 return ofnode_to_np(dev->node);
23}
24#else
25static inline const struct device_node *dev_np(struct udevice *dev)
26{
27 return NULL;
28}
29#endif
30
31/**
32 * dev_ofnode() - get the DT node reference associated with a udevice
33 *
34 * @dev: device to check
35 * @return reference of the the device's DT node
36 */
37static inline ofnode dev_ofnode(struct udevice *dev)
38{
39 return dev->node;
40}
41
42static inline bool dev_of_valid(struct udevice *dev)
43{
44 return ofnode_valid(dev_ofnode(dev));
45}
46
Simon Glasscfdae5c2017-05-18 20:09:04 -060047#ifndef CONFIG_DM_DEV_READ_INLINE
48/**
Masahiro Yamada71d115f2017-12-30 02:00:05 +090049 * 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 */
56int dev_read_u32(struct udevice *dev, const char *propname, u32 *outp);
57
58/**
Simon Glasscfdae5c2017-05-18 20:09:04 -060059 * 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 */
66int dev_read_u32_default(struct udevice *dev, const char *propname, int def);
Simon Glass34ef0c22017-05-18 20:09:03 -060067
68/**
69 * dev_read_string() - Read a string from a device's DT property
70 *
71 * @dev: device to read DT property from
72 * @propname: name of the property to read
73 * @return string from property value, or NULL if there is no such property
74 */
Simon Glasscfdae5c2017-05-18 20:09:04 -060075const char *dev_read_string(struct udevice *dev, const char *propname);
Simon Glass34ef0c22017-05-18 20:09:03 -060076
77/**
78 * dev_read_bool() - read a boolean value from a device's DT property
79 *
80 * @dev: device to read DT property from
81 * @propname: name of property to read
82 * @return true if property is present (meaning true), false if not present
83 */
Simon Glasscfdae5c2017-05-18 20:09:04 -060084bool dev_read_bool(struct udevice *dev, const char *propname);
Simon Glass34ef0c22017-05-18 20:09:03 -060085
86/**
87 * dev_read_subnode() - find a named subnode of a device
88 *
89 * @dev: device whose DT node contains the subnode
90 * @subnode_name: name of subnode to find
91 * @return reference to subnode (which can be invalid if there is no such
92 * subnode)
93 */
Simon Glasscfdae5c2017-05-18 20:09:04 -060094ofnode dev_read_subnode(struct udevice *dev, const char *subbnode_name);
Simon Glass34ef0c22017-05-18 20:09:03 -060095
96/**
97 * dev_read_size() - read the size of a property
98 *
99 * @dev: device to check
100 * @propname: property to check
101 * @return size of property if present, or -EINVAL if not
102 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600103int dev_read_size(struct udevice *dev, const char *propname);
Simon Glass34ef0c22017-05-18 20:09:03 -0600104
105/**
106 * dev_read_addr_index() - Get the indexed reg property of a device
107 *
108 * @dev: Device to read from
109 * @index: the 'reg' property can hold a list of <addr, size> pairs
110 * and @index is used to select which one is required
111 *
112 * @return address or FDT_ADDR_T_NONE if not found
113 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600114fdt_addr_t dev_read_addr_index(struct udevice *dev, int index);
Simon Glass34ef0c22017-05-18 20:09:03 -0600115
116/**
117 * dev_read_addr() - Get the reg property of a device
118 *
119 * @dev: Device to read from
120 *
121 * @return address or FDT_ADDR_T_NONE if not found
122 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600123fdt_addr_t dev_read_addr(struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600124
125/**
Philipp Tomsich7719b392017-09-11 22:04:12 +0200126 * dev_read_addr_ptr() - Get the reg property of a device
127 * as a pointer
128 *
129 * @dev: Device to read from
130 *
131 * @return pointer or NULL if not found
132 */
133void *dev_read_addr_ptr(struct udevice *dev);
134
135/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600136 * dev_read_addr_size() - get address and size from a device property
137 *
138 * This does no address translation. It simply reads an property that contains
139 * an address and a size value, one after the other.
140 *
141 * @dev: Device to read from
142 * @propname: property to read
143 * @sizep: place to put size value (on success)
144 * @return address value, or FDT_ADDR_T_NONE on error
145 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600146fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *propname,
147 fdt_size_t *sizep);
Simon Glass34ef0c22017-05-18 20:09:03 -0600148
149/**
150 * dev_read_name() - get the name of a device's node
151 *
152 * @node: valid node to look up
153 * @return name of node
154 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600155const char *dev_read_name(struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600156
157/**
158 * dev_read_stringlist_search() - find string in a string list and return index
159 *
160 * Note that it is possible for this function to succeed on property values
161 * that are not NUL-terminated. That's because the function will stop after
162 * finding the first occurrence of @string. This can for example happen with
163 * small-valued cell properties, such as #address-cells, when searching for
164 * the empty string.
165 *
166 * @dev: device to check
167 * @propname: name of the property containing the string list
168 * @string: string to look up in the string list
169 *
170 * @return:
171 * the index of the string in the list of strings
172 * -ENODATA if the property is not found
173 * -EINVAL on some other error
174 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600175int dev_read_stringlist_search(struct udevice *dev, const char *property,
176 const char *string);
Simon Glass34ef0c22017-05-18 20:09:03 -0600177
178/**
Jean-Jacques Hiblot8365ebd2017-09-21 17:03:09 +0200179 * dev_read_string_index() - obtain an indexed string from a string list
180 *
181 * @dev: device to examine
182 * @propname: name of the property containing the string list
183 * @index: index of the string to return
184 * @out: return location for the string
185 *
186 * @return:
187 * length of string, if found or -ve error value if not found
188 */
189int dev_read_string_index(struct udevice *dev, const char *propname, int index,
190 const char **outp);
191
192/**
193 * dev_read_string_count() - find the number of strings in a string list
194 *
195 * @dev: device to examine
196 * @propname: name of the property containing the string list
197 * @return:
198 * number of strings in the list, or -ve error value if not found
199 */
200int dev_read_string_count(struct udevice *dev, const char *propname);
201/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600202 * dev_read_phandle_with_args() - Find a node pointed by phandle in a list
203 *
204 * This function is useful to parse lists of phandles and their arguments.
205 * Returns 0 on success and fills out_args, on error returns appropriate
206 * errno value.
207 *
208 * Caller is responsible to call of_node_put() on the returned out_args->np
209 * pointer.
210 *
211 * Example:
212 *
213 * phandle1: node1 {
214 * #list-cells = <2>;
215 * }
216 *
217 * phandle2: node2 {
218 * #list-cells = <1>;
219 * }
220 *
221 * node3 {
222 * list = <&phandle1 1 2 &phandle2 3>;
223 * }
224 *
225 * To get a device_node of the `node2' node you may call this:
226 * dev_read_phandle_with_args(dev, "list", "#list-cells", 0, 1, &args);
227 *
228 * @dev: device whose node containing a list
229 * @list_name: property name that contains a list
230 * @cells_name: property name that specifies phandles' arguments count
231 * @cells_count: Cell count to use if @cells_name is NULL
232 * @index: index of a phandle to parse out
233 * @out_args: optional pointer to output arguments structure (will be filled)
234 * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
235 * @list_name does not exist, -EINVAL if a phandle was not found,
236 * @cells_name could not be found, the arguments were truncated or there
237 * were too many arguments.
238 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600239int dev_read_phandle_with_args(struct udevice *dev, const char *list_name,
240 const char *cells_name, int cell_count,
241 int index,
242 struct ofnode_phandle_args *out_args);
Simon Glass34ef0c22017-05-18 20:09:03 -0600243
244/**
Patrice Chotardbe7dd602017-07-18 11:57:08 +0200245 * dev_count_phandle_with_args() - Return phandle number in a list
246 *
247 * This function is usefull to get phandle number contained in a property list.
248 * For example, this allows to allocate the right amount of memory to keep
249 * clock's reference contained into the "clocks" property.
250 *
251 *
252 * @dev: device whose node containing a list
253 * @list_name: property name that contains a list
254 * @cells_name: property name that specifies phandles' arguments count
255 * @Returns number of phandle found on success, on error returns appropriate
256 * errno value.
257 */
258
259int dev_count_phandle_with_args(struct udevice *dev, const char *list_name,
260 const char *cells_name);
261
262/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600263 * dev_read_addr_cells() - Get the number of address cells for a device's node
264 *
265 * This walks back up the tree to find the closest #address-cells property
266 * which controls the given node.
267 *
Mario Six16408ee2018-01-15 11:09:36 +0100268 * @dev: device to check
Simon Glass34ef0c22017-05-18 20:09:03 -0600269 * @return number of address cells this node uses
270 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600271int dev_read_addr_cells(struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600272
273/**
274 * dev_read_size_cells() - Get the number of size cells for a device's node
275 *
276 * This walks back up the tree to find the closest #size-cells property
277 * which controls the given node.
278 *
Mario Six16408ee2018-01-15 11:09:36 +0100279 * @dev: device to check
Simon Glass34ef0c22017-05-18 20:09:03 -0600280 * @return number of size cells this node uses
281 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600282int dev_read_size_cells(struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600283
284/**
Simon Glass4191dc12017-06-12 06:21:31 -0600285 * dev_read_addr_cells() - Get the address cells property in a node
286 *
287 * This function matches fdt_address_cells().
288 *
Mario Six16408ee2018-01-15 11:09:36 +0100289 * @dev: device to check
Simon Glass4191dc12017-06-12 06:21:31 -0600290 * @return number of address cells this node uses
291 */
292int dev_read_simple_addr_cells(struct udevice *dev);
293
294/**
295 * dev_read_size_cells() - Get the size cells property in a node
296 *
297 * This function matches fdt_size_cells().
298 *
Mario Six16408ee2018-01-15 11:09:36 +0100299 * @dev: device to check
Simon Glass4191dc12017-06-12 06:21:31 -0600300 * @return number of size cells this node uses
301 */
302int dev_read_simple_size_cells(struct udevice *dev);
303
304/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600305 * dev_read_phandle() - Get the phandle from a device
306 *
307 * @dev: device to check
308 * @return phandle (1 or greater), or 0 if no phandle or other error
309 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600310int dev_read_phandle(struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600311
312/**
313 * dev_read_prop()- - read a property from a device's node
314 *
315 * @dev: device to check
316 * @propname: property to read
317 * @lenp: place to put length on success
318 * @return pointer to property, or NULL if not found
319 */
Masahiro Yamadabaebec12017-07-17 12:18:39 +0900320const void *dev_read_prop(struct udevice *dev, const char *propname, int *lenp);
Simon Glass34ef0c22017-05-18 20:09:03 -0600321
322/**
323 * dev_read_alias_seq() - Get the alias sequence number of a node
324 *
325 * This works out whether a node is pointed to by an alias, and if so, the
326 * sequence number of that alias. Aliases are of the form <base><num> where
327 * <num> is the sequence number. For example spi2 would be sequence number 2.
328 *
329 * @dev: device to look up
330 * @devnump: set to the sequence number if one is found
331 * @return 0 if a sequence was found, -ve if not
332 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600333int dev_read_alias_seq(struct udevice *dev, int *devnump);
Simon Glass34ef0c22017-05-18 20:09:03 -0600334
335/**
336 * dev_read_u32_array() - Find and read an array of 32 bit integers
337 *
338 * Search for a property in a device node and read 32-bit value(s) from
339 * it.
340 *
341 * The out_values is modified only if a valid u32 value can be decoded.
342 *
343 * @dev: device to look up
344 * @propname: name of the property to read
345 * @out_values: pointer to return value, modified only if return value is 0
346 * @sz: number of array elements to read
347 * @return 0 on success, -EINVAL if the property does not exist, -ENODATA if
348 * property does not have a value, and -EOVERFLOW if the property data isn't
349 * large enough.
350 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600351int dev_read_u32_array(struct udevice *dev, const char *propname,
352 u32 *out_values, size_t sz);
Simon Glass34ef0c22017-05-18 20:09:03 -0600353
354/**
355 * dev_read_first_subnode() - find the first subnode of a device's node
356 *
357 * @dev: device to look up
358 * @return reference to the first subnode (which can be invalid if the device's
359 * node has no subnodes)
360 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600361ofnode dev_read_first_subnode(struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600362
363/**
364 * ofnode_next_subnode() - find the next sibling of a subnode
365 *
366 * @node: valid reference to previous node (sibling)
367 * @return reference to the next subnode (which can be invalid if the node
368 * has no more siblings)
369 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600370ofnode dev_read_next_subnode(ofnode node);
Simon Glass34ef0c22017-05-18 20:09:03 -0600371
372/**
373 * dev_read_u8_array_ptr() - find an 8-bit array
374 *
375 * Look up a device's node property and return a pointer to its contents as a
376 * byte array of given length. The property must have at least enough data
377 * for the array (count bytes). It may have more, but this will be ignored.
378 * The data is not copied.
379 *
380 * @dev: device to look up
381 * @propname: name of property to find
382 * @sz: number of array elements
383 * @return pointer to byte array if found, or NULL if the property is not
384 * found or there is not enough data
385 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600386const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname,
387 size_t sz);
388
Simon Glassfa031f82017-06-12 06:21:30 -0600389/**
390 * dev_read_enabled() - check whether a node is enabled
391 *
392 * This looks for a 'status' property. If this exists, then returns 1 if
393 * the status is 'ok' and 0 otherwise. If there is no status property,
394 * it returns 1 on the assumption that anything mentioned should be enabled
395 * by default.
396 *
397 * @dev: device to examine
398 * @return integer value 0 (not enabled) or 1 (enabled)
399 */
400int dev_read_enabled(struct udevice *dev);
401
Simon Glassf7bfcc42017-07-25 08:29:55 -0600402/**
403 * dev_read_resource() - obtain an indexed resource from a device.
404 *
Masahiro Yamada4dada2c2017-08-26 01:12:30 +0900405 * @dev: device to examine
Simon Glassf7bfcc42017-07-25 08:29:55 -0600406 * @index index of the resource to retrieve (0 = first)
407 * @res returns the resource
408 * @return 0 if ok, negative on error
409 */
410int dev_read_resource(struct udevice *dev, uint index, struct resource *res);
411
Masahiro Yamada4dada2c2017-08-26 01:12:30 +0900412/**
413 * dev_read_resource_byname() - obtain a named resource from a device.
414 *
415 * @dev: device to examine
416 * @name: name of the resource to retrieve
417 * @res: returns the resource
418 * @return 0 if ok, negative on error
419 */
420int dev_read_resource_byname(struct udevice *dev, const char *name,
421 struct resource *res);
422
Mario Sixaefac062018-01-15 11:07:19 +0100423/**
424 * dev_translate_address() - Tranlate a device-tree address
425 *
426 * Translate an address from the device-tree into a CPU physical address. This
427 * function walks up the tree and applies the various bus mappings along the
428 * way.
429 *
430 * @dev: device giving the context in which to translate the address
431 * @in_addr: pointer to the address to translate
432 * @return the translated address; OF_BAD_ADDR on error
433 */
434u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr);
Simon Glasscfdae5c2017-05-18 20:09:04 -0600435#else /* CONFIG_DM_DEV_READ_INLINE is enabled */
436
Masahiro Yamada71d115f2017-12-30 02:00:05 +0900437static inline int dev_read_u32(struct udevice *dev,
438 const char *propname, u32 *outp)
439{
440 return ofnode_read_u32(dev_ofnode(dev), propname, outp);
441}
442
Simon Glasscfdae5c2017-05-18 20:09:04 -0600443static inline int dev_read_u32_default(struct udevice *dev,
444 const char *propname, int def)
445{
446 return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
447}
448
449static inline const char *dev_read_string(struct udevice *dev,
450 const char *propname)
451{
452 return ofnode_read_string(dev_ofnode(dev), propname);
453}
454
455static inline bool dev_read_bool(struct udevice *dev, const char *propname)
456{
457 return ofnode_read_bool(dev_ofnode(dev), propname);
458}
459
460static inline ofnode dev_read_subnode(struct udevice *dev,
461 const char *subbnode_name)
462{
463 return ofnode_find_subnode(dev_ofnode(dev), subbnode_name);
464}
465
466static inline int dev_read_size(struct udevice *dev, const char *propname)
467{
468 return ofnode_read_size(dev_ofnode(dev), propname);
469}
470
471static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index)
472{
473 return devfdt_get_addr_index(dev, index);
474}
475
476static inline fdt_addr_t dev_read_addr(struct udevice *dev)
477{
478 return devfdt_get_addr(dev);
479}
480
Philipp Tomsich7719b392017-09-11 22:04:12 +0200481static inline void *dev_read_addr_ptr(struct udevice *dev)
482{
483 return devfdt_get_addr_ptr(dev);
484}
485
Simon Glasscfdae5c2017-05-18 20:09:04 -0600486static inline fdt_addr_t dev_read_addr_size(struct udevice *dev,
487 const char *propname,
488 fdt_size_t *sizep)
489{
490 return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep);
491}
492
493static inline const char *dev_read_name(struct udevice *dev)
494{
495 return ofnode_get_name(dev_ofnode(dev));
496}
497
498static inline int dev_read_stringlist_search(struct udevice *dev,
499 const char *propname,
500 const char *string)
501{
502 return ofnode_stringlist_search(dev_ofnode(dev), propname, string);
503}
504
Jean-Jacques Hiblot8365ebd2017-09-21 17:03:09 +0200505static inline int dev_read_string_index(struct udevice *dev,
506 const char *propname, int index,
507 const char **outp)
508{
509 return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp);
510}
511
512static inline int dev_read_string_count(struct udevice *dev,
513 const char *propname)
514{
515 return ofnode_read_string_count(dev_ofnode(dev), propname);
516}
517
Simon Glasscfdae5c2017-05-18 20:09:04 -0600518static inline int dev_read_phandle_with_args(struct udevice *dev,
519 const char *list_name, const char *cells_name, int cell_count,
520 int index, struct ofnode_phandle_args *out_args)
521{
522 return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name,
523 cells_name, cell_count, index,
524 out_args);
525}
526
Patrice Chotardbe7dd602017-07-18 11:57:08 +0200527static inline int dev_count_phandle_with_args(struct udevice *dev,
528 const char *list_name, const char *cells_name)
529{
530 return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
531 cells_name);
532}
533
Simon Glasscfdae5c2017-05-18 20:09:04 -0600534static inline int dev_read_addr_cells(struct udevice *dev)
535{
Simon Glass4191dc12017-06-12 06:21:31 -0600536 /* NOTE: this call should walk up the parent stack */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600537 return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
538}
539
540static inline int dev_read_size_cells(struct udevice *dev)
541{
Simon Glass4191dc12017-06-12 06:21:31 -0600542 /* NOTE: this call should walk up the parent stack */
543 return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
544}
545
546static inline int dev_read_simple_addr_cells(struct udevice *dev)
547{
548 return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
549}
550
551static inline int dev_read_simple_size_cells(struct udevice *dev)
552{
Simon Glasscfdae5c2017-05-18 20:09:04 -0600553 return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
554}
555
556static inline int dev_read_phandle(struct udevice *dev)
557{
558 return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev));
559}
560
Masahiro Yamadabaebec12017-07-17 12:18:39 +0900561static inline const void *dev_read_prop(struct udevice *dev,
562 const char *propname, int *lenp)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600563{
Masahiro Yamada9cf85cb2017-06-22 16:54:05 +0900564 return ofnode_get_property(dev_ofnode(dev), propname, lenp);
Simon Glasscfdae5c2017-05-18 20:09:04 -0600565}
566
567static inline int dev_read_alias_seq(struct udevice *dev, int *devnump)
568{
569 return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name,
570 dev_of_offset(dev), devnump);
571}
572
573static inline int dev_read_u32_array(struct udevice *dev, const char *propname,
574 u32 *out_values, size_t sz)
575{
576 return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
577}
578
579static inline ofnode dev_read_first_subnode(struct udevice *dev)
580{
581 return ofnode_first_subnode(dev_ofnode(dev));
582}
583
584static inline ofnode dev_read_next_subnode(ofnode node)
585{
586 return ofnode_next_subnode(node);
587}
588
Simon Glass34ef0c22017-05-18 20:09:03 -0600589static inline const uint8_t *dev_read_u8_array_ptr(struct udevice *dev,
590 const char *propname, size_t sz)
591{
592 return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
593}
594
Simon Glassfa031f82017-06-12 06:21:30 -0600595static inline int dev_read_enabled(struct udevice *dev)
596{
597 return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev));
598}
599
Simon Glassf7bfcc42017-07-25 08:29:55 -0600600static inline int dev_read_resource(struct udevice *dev, uint index,
601 struct resource *res)
602{
603 return ofnode_read_resource(dev_ofnode(dev), index, res);
604}
605
Masahiro Yamada4dada2c2017-08-26 01:12:30 +0900606static inline int dev_read_resource_byname(struct udevice *dev,
607 const char *name,
608 struct resource *res)
609{
610 return ofnode_read_resource_byname(dev_ofnode(dev), name, res);
611}
612
Mario Sixaefac062018-01-15 11:07:19 +0100613static inline u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr)
614{
615 return ofnode_translate_address(dev_ofnode(dev), in_addr);
616}
617
Simon Glass34ef0c22017-05-18 20:09:03 -0600618#endif /* CONFIG_DM_DEV_READ_INLINE */
619
620/**
621 * dev_for_each_subnode() - Helper function to iterate through subnodes
622 *
623 * This creates a for() loop which works through the subnodes in a device's
624 * device-tree node.
625 *
626 * @subnode: ofnode holding the current subnode
627 * @dev: device to use for interation (struct udevice *)
628 */
629#define dev_for_each_subnode(subnode, dev) \
630 for (subnode = dev_read_first_subnode(dev); \
631 ofnode_valid(subnode); \
632 subnode = ofnode_next_subnode(subnode))
633
634#endif