blob: 4a725bc923b5c974664102d1951396a456039bde [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/**
116 * dev_read_addr() - Get the reg property of a device
117 *
118 * @dev: Device to read from
119 *
120 * @return address or FDT_ADDR_T_NONE if not found
121 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600122fdt_addr_t dev_read_addr(struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600123
124/**
Philipp Tomsich7719b392017-09-11 22:04:12 +0200125 * dev_read_addr_ptr() - Get the reg property of a device
126 * as a pointer
127 *
128 * @dev: Device to read from
129 *
130 * @return pointer or NULL if not found
131 */
132void *dev_read_addr_ptr(struct udevice *dev);
133
134/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600135 * dev_read_addr_size() - get address and size from a device property
136 *
137 * This does no address translation. It simply reads an property that contains
138 * an address and a size value, one after the other.
139 *
140 * @dev: Device to read from
141 * @propname: property to read
142 * @sizep: place to put size value (on success)
143 * @return address value, or FDT_ADDR_T_NONE on error
144 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600145fdt_addr_t dev_read_addr_size(struct udevice *dev, const char *propname,
146 fdt_size_t *sizep);
Simon Glass34ef0c22017-05-18 20:09:03 -0600147
148/**
149 * dev_read_name() - get the name of a device's node
150 *
151 * @node: valid node to look up
152 * @return name of node
153 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600154const char *dev_read_name(struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600155
156/**
157 * dev_read_stringlist_search() - find string in a string list and return index
158 *
159 * Note that it is possible for this function to succeed on property values
160 * that are not NUL-terminated. That's because the function will stop after
161 * finding the first occurrence of @string. This can for example happen with
162 * small-valued cell properties, such as #address-cells, when searching for
163 * the empty string.
164 *
165 * @dev: device to check
166 * @propname: name of the property containing the string list
167 * @string: string to look up in the string list
168 *
169 * @return:
170 * the index of the string in the list of strings
171 * -ENODATA if the property is not found
172 * -EINVAL on some other error
173 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600174int dev_read_stringlist_search(struct udevice *dev, const char *property,
175 const char *string);
Simon Glass34ef0c22017-05-18 20:09:03 -0600176
177/**
Jean-Jacques Hiblot8365ebd2017-09-21 17:03:09 +0200178 * dev_read_string_index() - obtain an indexed string from a string list
179 *
180 * @dev: device to examine
181 * @propname: name of the property containing the string list
182 * @index: index of the string to return
183 * @out: return location for the string
184 *
185 * @return:
186 * length of string, if found or -ve error value if not found
187 */
188int dev_read_string_index(struct udevice *dev, const char *propname, int index,
189 const char **outp);
190
191/**
192 * dev_read_string_count() - find the number of strings in a string list
193 *
194 * @dev: device to examine
195 * @propname: name of the property containing the string list
196 * @return:
197 * number of strings in the list, or -ve error value if not found
198 */
199int dev_read_string_count(struct udevice *dev, const char *propname);
200/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600201 * dev_read_phandle_with_args() - Find a node pointed by phandle in a list
202 *
203 * This function is useful to parse lists of phandles and their arguments.
204 * Returns 0 on success and fills out_args, on error returns appropriate
205 * errno value.
206 *
207 * Caller is responsible to call of_node_put() on the returned out_args->np
208 * pointer.
209 *
210 * Example:
211 *
212 * phandle1: node1 {
213 * #list-cells = <2>;
214 * }
215 *
216 * phandle2: node2 {
217 * #list-cells = <1>;
218 * }
219 *
220 * node3 {
221 * list = <&phandle1 1 2 &phandle2 3>;
222 * }
223 *
224 * To get a device_node of the `node2' node you may call this:
225 * dev_read_phandle_with_args(dev, "list", "#list-cells", 0, 1, &args);
226 *
227 * @dev: device whose node containing a list
228 * @list_name: property name that contains a list
229 * @cells_name: property name that specifies phandles' arguments count
230 * @cells_count: Cell count to use if @cells_name is NULL
231 * @index: index of a phandle to parse out
232 * @out_args: optional pointer to output arguments structure (will be filled)
233 * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
234 * @list_name does not exist, -EINVAL if a phandle was not found,
235 * @cells_name could not be found, the arguments were truncated or there
236 * were too many arguments.
237 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600238int dev_read_phandle_with_args(struct udevice *dev, const char *list_name,
239 const char *cells_name, int cell_count,
240 int index,
241 struct ofnode_phandle_args *out_args);
Simon Glass34ef0c22017-05-18 20:09:03 -0600242
243/**
Patrice Chotardbe7dd602017-07-18 11:57:08 +0200244 * dev_count_phandle_with_args() - Return phandle number in a list
245 *
246 * This function is usefull to get phandle number contained in a property list.
247 * For example, this allows to allocate the right amount of memory to keep
248 * clock's reference contained into the "clocks" property.
249 *
250 *
251 * @dev: device whose node containing a list
252 * @list_name: property name that contains a list
253 * @cells_name: property name that specifies phandles' arguments count
254 * @Returns number of phandle found on success, on error returns appropriate
255 * errno value.
256 */
257
258int dev_count_phandle_with_args(struct udevice *dev, const char *list_name,
259 const char *cells_name);
260
261/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600262 * dev_read_addr_cells() - Get the number of address cells for a device's node
263 *
264 * This walks back up the tree to find the closest #address-cells property
265 * which controls the given node.
266 *
Mario Six16408ee2018-01-15 11:09:36 +0100267 * @dev: device to check
Simon Glass34ef0c22017-05-18 20:09:03 -0600268 * @return number of address cells this node uses
269 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600270int dev_read_addr_cells(struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600271
272/**
273 * dev_read_size_cells() - Get the number of size cells for a device's node
274 *
275 * This walks back up the tree to find the closest #size-cells property
276 * which controls the given node.
277 *
Mario Six16408ee2018-01-15 11:09:36 +0100278 * @dev: device to check
Simon Glass34ef0c22017-05-18 20:09:03 -0600279 * @return number of size cells this node uses
280 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600281int dev_read_size_cells(struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600282
283/**
Simon Glass4191dc12017-06-12 06:21:31 -0600284 * dev_read_addr_cells() - Get the address cells property in a node
285 *
286 * This function matches fdt_address_cells().
287 *
Mario Six16408ee2018-01-15 11:09:36 +0100288 * @dev: device to check
Simon Glass4191dc12017-06-12 06:21:31 -0600289 * @return number of address cells this node uses
290 */
291int dev_read_simple_addr_cells(struct udevice *dev);
292
293/**
294 * dev_read_size_cells() - Get the size cells property in a node
295 *
296 * This function matches fdt_size_cells().
297 *
Mario Six16408ee2018-01-15 11:09:36 +0100298 * @dev: device to check
Simon Glass4191dc12017-06-12 06:21:31 -0600299 * @return number of size cells this node uses
300 */
301int dev_read_simple_size_cells(struct udevice *dev);
302
303/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600304 * dev_read_phandle() - Get the phandle from a device
305 *
306 * @dev: device to check
307 * @return phandle (1 or greater), or 0 if no phandle or other error
308 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600309int dev_read_phandle(struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600310
311/**
312 * dev_read_prop()- - read a property from a device's node
313 *
314 * @dev: device to check
315 * @propname: property to read
316 * @lenp: place to put length on success
317 * @return pointer to property, or NULL if not found
318 */
Masahiro Yamadabaebec12017-07-17 12:18:39 +0900319const void *dev_read_prop(struct udevice *dev, const char *propname, int *lenp);
Simon Glass34ef0c22017-05-18 20:09:03 -0600320
321/**
322 * dev_read_alias_seq() - Get the alias sequence number of a node
323 *
324 * This works out whether a node is pointed to by an alias, and if so, the
325 * sequence number of that alias. Aliases are of the form <base><num> where
326 * <num> is the sequence number. For example spi2 would be sequence number 2.
327 *
328 * @dev: device to look up
329 * @devnump: set to the sequence number if one is found
330 * @return 0 if a sequence was found, -ve if not
331 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600332int dev_read_alias_seq(struct udevice *dev, int *devnump);
Simon Glass34ef0c22017-05-18 20:09:03 -0600333
334/**
335 * dev_read_u32_array() - Find and read an array of 32 bit integers
336 *
337 * Search for a property in a device node and read 32-bit value(s) from
338 * it.
339 *
340 * The out_values is modified only if a valid u32 value can be decoded.
341 *
342 * @dev: device to look up
343 * @propname: name of the property to read
344 * @out_values: pointer to return value, modified only if return value is 0
345 * @sz: number of array elements to read
346 * @return 0 on success, -EINVAL if the property does not exist, -ENODATA if
347 * property does not have a value, and -EOVERFLOW if the property data isn't
348 * large enough.
349 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600350int dev_read_u32_array(struct udevice *dev, const char *propname,
351 u32 *out_values, size_t sz);
Simon Glass34ef0c22017-05-18 20:09:03 -0600352
353/**
354 * dev_read_first_subnode() - find the first subnode of a device's node
355 *
356 * @dev: device to look up
357 * @return reference to the first subnode (which can be invalid if the device's
358 * node has no subnodes)
359 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600360ofnode dev_read_first_subnode(struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600361
362/**
363 * ofnode_next_subnode() - find the next sibling of a subnode
364 *
365 * @node: valid reference to previous node (sibling)
366 * @return reference to the next subnode (which can be invalid if the node
367 * has no more siblings)
368 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600369ofnode dev_read_next_subnode(ofnode node);
Simon Glass34ef0c22017-05-18 20:09:03 -0600370
371/**
372 * dev_read_u8_array_ptr() - find an 8-bit array
373 *
374 * Look up a device's node property and return a pointer to its contents as a
375 * byte array of given length. The property must have at least enough data
376 * for the array (count bytes). It may have more, but this will be ignored.
377 * The data is not copied.
378 *
379 * @dev: device to look up
380 * @propname: name of property to find
381 * @sz: number of array elements
382 * @return pointer to byte array if found, or NULL if the property is not
383 * found or there is not enough data
384 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600385const uint8_t *dev_read_u8_array_ptr(struct udevice *dev, const char *propname,
386 size_t sz);
387
Simon Glassfa031f82017-06-12 06:21:30 -0600388/**
389 * dev_read_enabled() - check whether a node is enabled
390 *
391 * This looks for a 'status' property. If this exists, then returns 1 if
392 * the status is 'ok' and 0 otherwise. If there is no status property,
393 * it returns 1 on the assumption that anything mentioned should be enabled
394 * by default.
395 *
396 * @dev: device to examine
397 * @return integer value 0 (not enabled) or 1 (enabled)
398 */
399int dev_read_enabled(struct udevice *dev);
400
Simon Glassf7bfcc42017-07-25 08:29:55 -0600401/**
402 * dev_read_resource() - obtain an indexed resource from a device.
403 *
Masahiro Yamada4dada2c2017-08-26 01:12:30 +0900404 * @dev: device to examine
Simon Glassf7bfcc42017-07-25 08:29:55 -0600405 * @index index of the resource to retrieve (0 = first)
406 * @res returns the resource
407 * @return 0 if ok, negative on error
408 */
409int dev_read_resource(struct udevice *dev, uint index, struct resource *res);
410
Masahiro Yamada4dada2c2017-08-26 01:12:30 +0900411/**
412 * dev_read_resource_byname() - obtain a named resource from a device.
413 *
414 * @dev: device to examine
415 * @name: name of the resource to retrieve
416 * @res: returns the resource
417 * @return 0 if ok, negative on error
418 */
419int dev_read_resource_byname(struct udevice *dev, const char *name,
420 struct resource *res);
421
Mario Sixaefac062018-01-15 11:07:19 +0100422/**
423 * dev_translate_address() - Tranlate a device-tree address
424 *
425 * Translate an address from the device-tree into a CPU physical address. This
426 * function walks up the tree and applies the various bus mappings along the
427 * way.
428 *
429 * @dev: device giving the context in which to translate the address
430 * @in_addr: pointer to the address to translate
431 * @return the translated address; OF_BAD_ADDR on error
432 */
433u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr);
Simon Glasscfdae5c2017-05-18 20:09:04 -0600434#else /* CONFIG_DM_DEV_READ_INLINE is enabled */
435
Masahiro Yamada71d115f2017-12-30 02:00:05 +0900436static inline int dev_read_u32(struct udevice *dev,
437 const char *propname, u32 *outp)
438{
439 return ofnode_read_u32(dev_ofnode(dev), propname, outp);
440}
441
Simon Glasscfdae5c2017-05-18 20:09:04 -0600442static inline int dev_read_u32_default(struct udevice *dev,
443 const char *propname, int def)
444{
445 return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
446}
447
448static inline const char *dev_read_string(struct udevice *dev,
449 const char *propname)
450{
451 return ofnode_read_string(dev_ofnode(dev), propname);
452}
453
454static inline bool dev_read_bool(struct udevice *dev, const char *propname)
455{
456 return ofnode_read_bool(dev_ofnode(dev), propname);
457}
458
459static inline ofnode dev_read_subnode(struct udevice *dev,
460 const char *subbnode_name)
461{
462 return ofnode_find_subnode(dev_ofnode(dev), subbnode_name);
463}
464
465static inline int dev_read_size(struct udevice *dev, const char *propname)
466{
467 return ofnode_read_size(dev_ofnode(dev), propname);
468}
469
470static inline fdt_addr_t dev_read_addr_index(struct udevice *dev, int index)
471{
472 return devfdt_get_addr_index(dev, index);
473}
474
475static inline fdt_addr_t dev_read_addr(struct udevice *dev)
476{
477 return devfdt_get_addr(dev);
478}
479
Philipp Tomsich7719b392017-09-11 22:04:12 +0200480static inline void *dev_read_addr_ptr(struct udevice *dev)
481{
482 return devfdt_get_addr_ptr(dev);
483}
484
Simon Glasscfdae5c2017-05-18 20:09:04 -0600485static inline fdt_addr_t dev_read_addr_size(struct udevice *dev,
486 const char *propname,
487 fdt_size_t *sizep)
488{
489 return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep);
490}
491
492static inline const char *dev_read_name(struct udevice *dev)
493{
494 return ofnode_get_name(dev_ofnode(dev));
495}
496
497static inline int dev_read_stringlist_search(struct udevice *dev,
498 const char *propname,
499 const char *string)
500{
501 return ofnode_stringlist_search(dev_ofnode(dev), propname, string);
502}
503
Jean-Jacques Hiblot8365ebd2017-09-21 17:03:09 +0200504static inline int dev_read_string_index(struct udevice *dev,
505 const char *propname, int index,
506 const char **outp)
507{
508 return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp);
509}
510
511static inline int dev_read_string_count(struct udevice *dev,
512 const char *propname)
513{
514 return ofnode_read_string_count(dev_ofnode(dev), propname);
515}
516
Simon Glasscfdae5c2017-05-18 20:09:04 -0600517static inline int dev_read_phandle_with_args(struct udevice *dev,
518 const char *list_name, const char *cells_name, int cell_count,
519 int index, struct ofnode_phandle_args *out_args)
520{
521 return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name,
522 cells_name, cell_count, index,
523 out_args);
524}
525
Patrice Chotardbe7dd602017-07-18 11:57:08 +0200526static inline int dev_count_phandle_with_args(struct udevice *dev,
527 const char *list_name, const char *cells_name)
528{
529 return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
530 cells_name);
531}
532
Simon Glasscfdae5c2017-05-18 20:09:04 -0600533static inline int dev_read_addr_cells(struct udevice *dev)
534{
Simon Glass4191dc12017-06-12 06:21:31 -0600535 /* NOTE: this call should walk up the parent stack */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600536 return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
537}
538
539static inline int dev_read_size_cells(struct udevice *dev)
540{
Simon Glass4191dc12017-06-12 06:21:31 -0600541 /* NOTE: this call should walk up the parent stack */
542 return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
543}
544
545static inline int dev_read_simple_addr_cells(struct udevice *dev)
546{
547 return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
548}
549
550static inline int dev_read_simple_size_cells(struct udevice *dev)
551{
Simon Glasscfdae5c2017-05-18 20:09:04 -0600552 return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
553}
554
555static inline int dev_read_phandle(struct udevice *dev)
556{
557 return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev));
558}
559
Masahiro Yamadabaebec12017-07-17 12:18:39 +0900560static inline const void *dev_read_prop(struct udevice *dev,
561 const char *propname, int *lenp)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600562{
Masahiro Yamada9cf85cb2017-06-22 16:54:05 +0900563 return ofnode_get_property(dev_ofnode(dev), propname, lenp);
Simon Glasscfdae5c2017-05-18 20:09:04 -0600564}
565
566static inline int dev_read_alias_seq(struct udevice *dev, int *devnump)
567{
568 return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name,
569 dev_of_offset(dev), devnump);
570}
571
572static inline int dev_read_u32_array(struct udevice *dev, const char *propname,
573 u32 *out_values, size_t sz)
574{
575 return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
576}
577
578static inline ofnode dev_read_first_subnode(struct udevice *dev)
579{
580 return ofnode_first_subnode(dev_ofnode(dev));
581}
582
583static inline ofnode dev_read_next_subnode(ofnode node)
584{
585 return ofnode_next_subnode(node);
586}
587
Simon Glass34ef0c22017-05-18 20:09:03 -0600588static inline const uint8_t *dev_read_u8_array_ptr(struct udevice *dev,
589 const char *propname, size_t sz)
590{
591 return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
592}
593
Simon Glassfa031f82017-06-12 06:21:30 -0600594static inline int dev_read_enabled(struct udevice *dev)
595{
596 return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev));
597}
598
Simon Glassf7bfcc42017-07-25 08:29:55 -0600599static inline int dev_read_resource(struct udevice *dev, uint index,
600 struct resource *res)
601{
602 return ofnode_read_resource(dev_ofnode(dev), index, res);
603}
604
Masahiro Yamada4dada2c2017-08-26 01:12:30 +0900605static inline int dev_read_resource_byname(struct udevice *dev,
606 const char *name,
607 struct resource *res)
608{
609 return ofnode_read_resource_byname(dev_ofnode(dev), name, res);
610}
611
Mario Sixaefac062018-01-15 11:07:19 +0100612static inline u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr)
613{
614 return ofnode_translate_address(dev_ofnode(dev), in_addr);
615}
616
Simon Glass34ef0c22017-05-18 20:09:03 -0600617#endif /* CONFIG_DM_DEV_READ_INLINE */
618
619/**
620 * dev_for_each_subnode() - Helper function to iterate through subnodes
621 *
622 * This creates a for() loop which works through the subnodes in a device's
623 * device-tree node.
624 *
625 * @subnode: ofnode holding the current subnode
626 * @dev: device to use for interation (struct udevice *)
627 */
628#define dev_for_each_subnode(subnode, dev) \
629 for (subnode = dev_read_first_subnode(dev); \
630 ofnode_valid(subnode); \
631 subnode = ofnode_next_subnode(subnode))
632
633#endif