blob: c875e11a1324ecb8acc58628e0c5faf8dae9e373 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Simon Glassf11c7ab2017-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 Glassf11c7ab2017-05-18 20:09:03 -06007 */
8
9#ifndef _DM_READ_H
10#define _DM_READ_H
11
Dan Murphy9beacb62020-07-23 07:01:38 -050012#include <linux/errno.h>
13
Simon Glass2a64ada2020-07-19 10:15:39 -060014#include <dm/device.h>
Simon Glassf11c7ab2017-05-18 20:09:03 -060015#include <dm/fdtaddr.h>
16#include <dm/ofnode.h>
17#include <dm/uclass.h>
18
Simon Glassa4481012017-06-12 06:21:29 -060019struct resource;
20
Simon Glassf11c7ab2017-05-18 20:09:03 -060021#if CONFIG_IS_ENABLED(OF_LIVE)
Simon Glass88b3a372020-01-27 08:49:40 -070022static inline const struct device_node *dev_np(const struct udevice *dev)
Simon Glassf11c7ab2017-05-18 20:09:03 -060023{
Simon Glassf10643c2020-12-19 10:40:14 -070024 return ofnode_to_np(dev_ofnode(dev));
Simon Glassf11c7ab2017-05-18 20:09:03 -060025}
26#else
Simon Glass88b3a372020-01-27 08:49:40 -070027static inline const struct device_node *dev_np(const struct udevice *dev)
Simon Glassf11c7ab2017-05-18 20:09:03 -060028{
29 return NULL;
30}
31#endif
32
Simon Glass47a0fd32017-05-18 20:09:04 -060033#ifndef CONFIG_DM_DEV_READ_INLINE
T Karthik Reddy3f3d7712019-09-02 16:34:30 +020034
Simon Glass47a0fd32017-05-18 20:09:04 -060035/**
Masahiro Yamada3ab48f62017-12-30 02:00:05 +090036 * dev_read_u32() - read a 32-bit integer from a device's DT property
37 *
38 * @dev: device to read DT property from
39 * @propname: name of the property to read from
40 * @outp: place to put value (if found)
41 * @return 0 if OK, -ve on error
42 */
Simon Glass88b3a372020-01-27 08:49:40 -070043int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp);
Masahiro Yamada3ab48f62017-12-30 02:00:05 +090044
45/**
Simon Glass47a0fd32017-05-18 20:09:04 -060046 * dev_read_u32_default() - read a 32-bit integer from a device's DT property
47 *
48 * @dev: device to read DT property from
49 * @propname: name of the property to read from
50 * @def: default value to return if the property has no value
51 * @return property value, or @def if not found
52 */
Simon Glass88b3a372020-01-27 08:49:40 -070053int dev_read_u32_default(const struct udevice *dev, const char *propname,
54 int def);
Simon Glassf11c7ab2017-05-18 20:09:03 -060055
56/**
Dario Binacchi4bb70752020-03-29 18:04:41 +020057 * dev_read_u32_index() - read an indexed 32-bit integer from a device's DT
58 * property
59 *
60 * @dev: device to read DT property from
61 * @propname: name of the property to read from
62 * @index: index of the integer to return
63 * @outp: place to put value (if found)
64 * @return 0 if OK, -ve on error
65 */
66int dev_read_u32_index(struct udevice *dev, const char *propname, int index,
67 u32 *outp);
68
69/**
70 * dev_read_u32_index_default() - read an indexed 32-bit integer from a device's
71 * DT property
72 *
73 * @dev: device to read DT property from
74 * @propname: name of the property to read from
75 * @index: index of the integer to return
76 * @def: default value to return if the property has no value
77 * @return property value, or @def if not found
78 */
79u32 dev_read_u32_index_default(struct udevice *dev, const char *propname,
80 int index, u32 def);
81
82/**
Simon Glassa1b17e42018-12-10 10:37:37 -070083 * dev_read_s32() - read a signed 32-bit integer from a device's DT property
84 *
85 * @dev: device to read DT property from
86 * @propname: name of the property to read from
87 * @outp: place to put value (if found)
88 * @return 0 if OK, -ve on error
89 */
Simon Glass88b3a372020-01-27 08:49:40 -070090int dev_read_s32(const struct udevice *dev, const char *propname, s32 *outp);
Simon Glassa1b17e42018-12-10 10:37:37 -070091
92/**
93 * dev_read_s32_default() - read a signed 32-bit int from a device's DT property
94 *
95 * @dev: device to read DT property from
96 * @propname: name of the property to read from
97 * @def: default value to return if the property has no value
98 * @return property value, or @def if not found
99 */
Simon Glass88b3a372020-01-27 08:49:40 -0700100int dev_read_s32_default(const struct udevice *dev, const char *propname,
101 int def);
Simon Glassa1b17e42018-12-10 10:37:37 -0700102
103/**
104 * dev_read_u32u() - read a 32-bit integer from a device's DT property
105 *
106 * This version uses a standard uint type.
107 *
108 * @dev: device to read DT property from
109 * @propname: name of the property to read from
110 * @outp: place to put value (if found)
111 * @return 0 if OK, -ve on error
112 */
Simon Glass88b3a372020-01-27 08:49:40 -0700113int dev_read_u32u(const struct udevice *dev, const char *propname, uint *outp);
Simon Glassa1b17e42018-12-10 10:37:37 -0700114
115/**
T Karthik Reddy3f3d7712019-09-02 16:34:30 +0200116 * dev_read_u64() - read a 64-bit integer from a device's DT property
117 *
118 * @dev: device to read DT property from
119 * @propname: name of the property to read from
120 * @outp: place to put value (if found)
121 * @return 0 if OK, -ve on error
122 */
Simon Glass88b3a372020-01-27 08:49:40 -0700123int dev_read_u64(const struct udevice *dev, const char *propname, u64 *outp);
T Karthik Reddy3f3d7712019-09-02 16:34:30 +0200124
125/**
126 * dev_read_u64_default() - read a 64-bit integer from a device's DT property
127 *
128 * @dev: device to read DT property from
129 * @propname: name of the property to read from
130 * @def: default value to return if the property has no value
131 * @return property value, or @def if not found
132 */
Simon Glass88b3a372020-01-27 08:49:40 -0700133u64 dev_read_u64_default(const struct udevice *dev, const char *propname,
134 u64 def);
T Karthik Reddy3f3d7712019-09-02 16:34:30 +0200135
136/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600137 * dev_read_string() - Read a string from a device's DT property
138 *
139 * @dev: device to read DT property from
140 * @propname: name of the property to read
141 * @return string from property value, or NULL if there is no such property
142 */
Simon Glass88b3a372020-01-27 08:49:40 -0700143const char *dev_read_string(const struct udevice *dev, const char *propname);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600144
145/**
146 * dev_read_bool() - read a boolean value from a device's DT property
147 *
148 * @dev: device to read DT property from
149 * @propname: name of property to read
150 * @return true if property is present (meaning true), false if not present
151 */
Simon Glass88b3a372020-01-27 08:49:40 -0700152bool dev_read_bool(const struct udevice *dev, const char *propname);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600153
154/**
155 * dev_read_subnode() - find a named subnode of a device
156 *
157 * @dev: device whose DT node contains the subnode
158 * @subnode_name: name of subnode to find
159 * @return reference to subnode (which can be invalid if there is no such
160 * subnode)
161 */
Simon Glass88b3a372020-01-27 08:49:40 -0700162ofnode dev_read_subnode(const struct udevice *dev, const char *subbnode_name);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600163
164/**
165 * dev_read_size() - read the size of a property
166 *
167 * @dev: device to check
168 * @propname: property to check
169 * @return size of property if present, or -EINVAL if not
170 */
Simon Glass88b3a372020-01-27 08:49:40 -0700171int dev_read_size(const struct udevice *dev, const char *propname);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600172
173/**
174 * dev_read_addr_index() - Get the indexed reg property of a device
175 *
176 * @dev: Device to read from
177 * @index: the 'reg' property can hold a list of <addr, size> pairs
178 * and @index is used to select which one is required
179 *
180 * @return address or FDT_ADDR_T_NONE if not found
181 */
Simon Glass88b3a372020-01-27 08:49:40 -0700182fdt_addr_t dev_read_addr_index(const struct udevice *dev, int index);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600183
184/**
Sekhar Norif5b90472019-08-01 19:12:56 +0530185 * dev_read_addr_size_index() - Get the indexed reg property of a device
186 *
187 * @dev: Device to read from
188 * @index: the 'reg' property can hold a list of <addr, size> pairs
189 * and @index is used to select which one is required
190 * @size: place to put size value (on success)
191 *
192 * @return address or FDT_ADDR_T_NONE if not found
193 */
Simon Glass88b3a372020-01-27 08:49:40 -0700194fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, int index,
Sekhar Norif5b90472019-08-01 19:12:56 +0530195 fdt_size_t *size);
196
197/**
Álvaro Fernández Rojas30a90f52018-04-29 21:56:54 +0200198 * dev_remap_addr_index() - Get the indexed reg property of a device
199 * as a memory-mapped I/O pointer
200 *
201 * @dev: Device to read from
202 * @index: the 'reg' property can hold a list of <addr, size> pairs
203 * and @index is used to select which one is required
204 *
205 * @return pointer or NULL if not found
206 */
Simon Glass88b3a372020-01-27 08:49:40 -0700207void *dev_remap_addr_index(const struct udevice *dev, int index);
Álvaro Fernández Rojas30a90f52018-04-29 21:56:54 +0200208
209/**
Álvaro Fernández Rojas79598822018-12-03 19:37:09 +0100210 * dev_read_addr_name() - Get the reg property of a device, indexed by name
211 *
212 * @dev: Device to read from
213 * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
214 * 'reg-names' property providing named-based identification. @index
215 * indicates the value to search for in 'reg-names'.
216 *
217 * @return address or FDT_ADDR_T_NONE if not found
218 */
Simon Glass88b3a372020-01-27 08:49:40 -0700219fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name);
Álvaro Fernández Rojas79598822018-12-03 19:37:09 +0100220
221/**
Sekhar Norif5b90472019-08-01 19:12:56 +0530222 * dev_read_addr_size_name() - Get the reg property of a device, indexed by name
223 *
224 * @dev: Device to read from
225 * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
226 * 'reg-names' property providing named-based identification. @index
227 * indicates the value to search for in 'reg-names'.
228 * @size: place to put size value (on success)
229 *
230 * @return address or FDT_ADDR_T_NONE if not found
231 */
Simon Glass88b3a372020-01-27 08:49:40 -0700232fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name,
Sekhar Norif5b90472019-08-01 19:12:56 +0530233 fdt_size_t *size);
234
235/**
Álvaro Fernández Rojas79598822018-12-03 19:37:09 +0100236 * dev_remap_addr_name() - Get the reg property of a device, indexed by name,
237 * as a memory-mapped I/O pointer
238 *
239 * @dev: Device to read from
240 * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
241 * 'reg-names' property providing named-based identification. @index
242 * indicates the value to search for in 'reg-names'.
243 *
244 * @return pointer or NULL if not found
245 */
Simon Glass88b3a372020-01-27 08:49:40 -0700246void *dev_remap_addr_name(const struct udevice *dev, const char *name);
Álvaro Fernández Rojas79598822018-12-03 19:37:09 +0100247
248/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600249 * dev_read_addr() - Get the reg property of a device
250 *
251 * @dev: Device to read from
252 *
253 * @return address or FDT_ADDR_T_NONE if not found
254 */
Simon Glass88b3a372020-01-27 08:49:40 -0700255fdt_addr_t dev_read_addr(const struct udevice *dev);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600256
257/**
Philipp Tomsichc131c8b2017-09-11 22:04:12 +0200258 * dev_read_addr_ptr() - Get the reg property of a device
259 * as a pointer
260 *
261 * @dev: Device to read from
262 *
263 * @return pointer or NULL if not found
264 */
Simon Glass88b3a372020-01-27 08:49:40 -0700265void *dev_read_addr_ptr(const struct udevice *dev);
Philipp Tomsichc131c8b2017-09-11 22:04:12 +0200266
267/**
Simon Glass33c215a2019-09-15 12:08:58 -0600268 * dev_read_addr_pci() - Read an address and handle PCI address translation
269 *
270 * At present U-Boot does not have address translation logic for PCI in the
271 * livetree implementation (of_addr.c). This special function supports this for
272 * the flat tree implementation.
273 *
274 * This function should be removed (and code should use dev_read() instead)
275 * once:
276 *
277 * 1. PCI address translation is added; and either
278 * 2. everything uses livetree where PCI translation is used (which is feasible
279 * in SPL and U-Boot proper) or PCI address translation is added to
280 * fdtdec_get_addr() and friends.
281 *
282 * @dev: Device to read from
283 * @return address or FDT_ADDR_T_NONE if not found
284 */
Simon Glass88b3a372020-01-27 08:49:40 -0700285fdt_addr_t dev_read_addr_pci(const struct udevice *dev);
Simon Glass33c215a2019-09-15 12:08:58 -0600286
287/**
Álvaro Fernández Rojas30a90f52018-04-29 21:56:54 +0200288 * dev_remap_addr() - Get the reg property of a device as a
289 * memory-mapped I/O pointer
290 *
291 * @dev: Device to read from
292 *
293 * @return pointer or NULL if not found
294 */
Simon Glass88b3a372020-01-27 08:49:40 -0700295void *dev_remap_addr(const struct udevice *dev);
Álvaro Fernández Rojas30a90f52018-04-29 21:56:54 +0200296
297/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600298 * dev_read_addr_size() - get address and size from a device property
299 *
300 * This does no address translation. It simply reads an property that contains
301 * an address and a size value, one after the other.
302 *
303 * @dev: Device to read from
304 * @propname: property to read
305 * @sizep: place to put size value (on success)
306 * @return address value, or FDT_ADDR_T_NONE on error
307 */
Simon Glass88b3a372020-01-27 08:49:40 -0700308fdt_addr_t dev_read_addr_size(const struct udevice *dev, const char *propname,
309 fdt_size_t *sizep);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600310
311/**
312 * dev_read_name() - get the name of a device's node
313 *
Bin Meng15d61d02019-07-05 09:23:18 -0700314 * @dev: Device to read from
Simon Glassf11c7ab2017-05-18 20:09:03 -0600315 * @return name of node
316 */
Simon Glass88b3a372020-01-27 08:49:40 -0700317const char *dev_read_name(const struct udevice *dev);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600318
319/**
320 * dev_read_stringlist_search() - find string in a string list and return index
321 *
322 * Note that it is possible for this function to succeed on property values
323 * that are not NUL-terminated. That's because the function will stop after
324 * finding the first occurrence of @string. This can for example happen with
325 * small-valued cell properties, such as #address-cells, when searching for
326 * the empty string.
327 *
328 * @dev: device to check
329 * @propname: name of the property containing the string list
330 * @string: string to look up in the string list
331 *
332 * @return:
333 * the index of the string in the list of strings
334 * -ENODATA if the property is not found
335 * -EINVAL on some other error
336 */
Simon Glass88b3a372020-01-27 08:49:40 -0700337int dev_read_stringlist_search(const struct udevice *dev, const char *property,
338 const char *string);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600339
340/**
Jean-Jacques Hiblotb5a144a2017-09-21 17:03:09 +0200341 * dev_read_string_index() - obtain an indexed string from a string list
342 *
343 * @dev: device to examine
344 * @propname: name of the property containing the string list
345 * @index: index of the string to return
346 * @out: return location for the string
347 *
348 * @return:
349 * length of string, if found or -ve error value if not found
350 */
Simon Glass88b3a372020-01-27 08:49:40 -0700351int dev_read_string_index(const struct udevice *dev, const char *propname,
352 int index, const char **outp);
Jean-Jacques Hiblotb5a144a2017-09-21 17:03:09 +0200353
354/**
355 * dev_read_string_count() - find the number of strings in a string list
356 *
357 * @dev: device to examine
358 * @propname: name of the property containing the string list
359 * @return:
360 * number of strings in the list, or -ve error value if not found
361 */
Simon Glass88b3a372020-01-27 08:49:40 -0700362int dev_read_string_count(const struct udevice *dev, const char *propname);
Jean-Jacques Hiblotb5a144a2017-09-21 17:03:09 +0200363/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600364 * dev_read_phandle_with_args() - Find a node pointed by phandle in a list
365 *
366 * This function is useful to parse lists of phandles and their arguments.
367 * Returns 0 on success and fills out_args, on error returns appropriate
368 * errno value.
369 *
370 * Caller is responsible to call of_node_put() on the returned out_args->np
371 * pointer.
372 *
373 * Example:
374 *
375 * phandle1: node1 {
376 * #list-cells = <2>;
377 * }
378 *
379 * phandle2: node2 {
380 * #list-cells = <1>;
381 * }
382 *
383 * node3 {
384 * list = <&phandle1 1 2 &phandle2 3>;
385 * }
386 *
387 * To get a device_node of the `node2' node you may call this:
388 * dev_read_phandle_with_args(dev, "list", "#list-cells", 0, 1, &args);
389 *
390 * @dev: device whose node containing a list
391 * @list_name: property name that contains a list
392 * @cells_name: property name that specifies phandles' arguments count
393 * @cells_count: Cell count to use if @cells_name is NULL
394 * @index: index of a phandle to parse out
395 * @out_args: optional pointer to output arguments structure (will be filled)
396 * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
397 * @list_name does not exist, -EINVAL if a phandle was not found,
398 * @cells_name could not be found, the arguments were truncated or there
399 * were too many arguments.
400 */
Simon Glass88b3a372020-01-27 08:49:40 -0700401int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name,
402 const char *cells_name, int cell_count,
403 int index, struct ofnode_phandle_args *out_args);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600404
405/**
Patrice Chotard642346a2017-07-18 11:57:08 +0200406 * dev_count_phandle_with_args() - Return phandle number in a list
407 *
408 * This function is usefull to get phandle number contained in a property list.
409 * For example, this allows to allocate the right amount of memory to keep
410 * clock's reference contained into the "clocks" property.
411 *
412 *
413 * @dev: device whose node containing a list
414 * @list_name: property name that contains a list
415 * @cells_name: property name that specifies phandles' arguments count
Patrick Delaunay89f68302020-09-25 09:41:14 +0200416 * @cells_count: Cell count to use if @cells_name is NULL
Patrice Chotard642346a2017-07-18 11:57:08 +0200417 * @Returns number of phandle found on success, on error returns appropriate
418 * errno value.
419 */
420
Simon Glass88b3a372020-01-27 08:49:40 -0700421int dev_count_phandle_with_args(const struct udevice *dev,
Patrick Delaunay89f68302020-09-25 09:41:14 +0200422 const char *list_name, const char *cells_name,
423 int cell_count);
Patrice Chotard642346a2017-07-18 11:57:08 +0200424
425/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600426 * dev_read_addr_cells() - Get the number of address cells for a device's node
427 *
428 * This walks back up the tree to find the closest #address-cells property
429 * which controls the given node.
430 *
Mario Six7ba50412018-01-15 11:09:36 +0100431 * @dev: device to check
Simon Glassf11c7ab2017-05-18 20:09:03 -0600432 * @return number of address cells this node uses
433 */
Simon Glass88b3a372020-01-27 08:49:40 -0700434int dev_read_addr_cells(const struct udevice *dev);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600435
436/**
437 * dev_read_size_cells() - Get the number of size cells for a device's node
438 *
439 * This walks back up the tree to find the closest #size-cells property
440 * which controls the given node.
441 *
Mario Six7ba50412018-01-15 11:09:36 +0100442 * @dev: device to check
Simon Glassf11c7ab2017-05-18 20:09:03 -0600443 * @return number of size cells this node uses
444 */
Simon Glass88b3a372020-01-27 08:49:40 -0700445int dev_read_size_cells(const struct udevice *dev);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600446
447/**
Simon Glass878d68c2017-06-12 06:21:31 -0600448 * dev_read_addr_cells() - Get the address cells property in a node
449 *
450 * This function matches fdt_address_cells().
451 *
Mario Six7ba50412018-01-15 11:09:36 +0100452 * @dev: device to check
Simon Glass878d68c2017-06-12 06:21:31 -0600453 * @return number of address cells this node uses
454 */
Simon Glass88b3a372020-01-27 08:49:40 -0700455int dev_read_simple_addr_cells(const struct udevice *dev);
Simon Glass878d68c2017-06-12 06:21:31 -0600456
457/**
458 * dev_read_size_cells() - Get the size cells property in a node
459 *
460 * This function matches fdt_size_cells().
461 *
Mario Six7ba50412018-01-15 11:09:36 +0100462 * @dev: device to check
Simon Glass878d68c2017-06-12 06:21:31 -0600463 * @return number of size cells this node uses
464 */
Simon Glass88b3a372020-01-27 08:49:40 -0700465int dev_read_simple_size_cells(const struct udevice *dev);
Simon Glass878d68c2017-06-12 06:21:31 -0600466
467/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600468 * dev_read_phandle() - Get the phandle from a device
469 *
470 * @dev: device to check
471 * @return phandle (1 or greater), or 0 if no phandle or other error
472 */
Simon Glass88b3a372020-01-27 08:49:40 -0700473int dev_read_phandle(const struct udevice *dev);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600474
475/**
476 * dev_read_prop()- - read a property from a device's node
477 *
478 * @dev: device to check
479 * @propname: property to read
480 * @lenp: place to put length on success
481 * @return pointer to property, or NULL if not found
482 */
Simon Glass88b3a372020-01-27 08:49:40 -0700483const void *dev_read_prop(const struct udevice *dev, const char *propname,
484 int *lenp);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600485
486/**
Patrick Delaunayce891fca2020-01-13 11:34:56 +0100487 * dev_read_first_prop()- get the reference of the first property
488 *
489 * Get reference to the first property of the node, it is used to iterate
490 * and read all the property with dev_read_prop_by_prop().
491 *
492 * @dev: device to check
493 * @prop: place to put argument reference
494 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
495 */
496int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop);
497
498/**
499 * ofnode_get_next_property() - get the reference of the next property
500 *
501 * Get reference to the next property of the node, it is used to iterate
502 * and read all the property with dev_read_prop_by_prop().
503 *
504 * @prop: reference of current argument and place to put reference of next one
505 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
506 */
507int dev_read_next_prop(struct ofprop *prop);
508
509/**
510 * dev_read_prop_by_prop() - get a pointer to the value of a property
511 *
512 * Get value for the property identified by the provided reference.
513 *
514 * @prop: reference on property
515 * @propname: If non-NULL, place to property name on success,
516 * @lenp: If non-NULL, place to put length on success
517 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
518 */
519const void *dev_read_prop_by_prop(struct ofprop *prop,
520 const char **propname, int *lenp);
521
522/**
Simon Glassf11c7ab2017-05-18 20:09:03 -0600523 * dev_read_alias_seq() - Get the alias sequence number of a node
524 *
525 * This works out whether a node is pointed to by an alias, and if so, the
526 * sequence number of that alias. Aliases are of the form <base><num> where
527 * <num> is the sequence number. For example spi2 would be sequence number 2.
528 *
529 * @dev: device to look up
530 * @devnump: set to the sequence number if one is found
531 * @return 0 if a sequence was found, -ve if not
532 */
Simon Glass88b3a372020-01-27 08:49:40 -0700533int dev_read_alias_seq(const struct udevice *dev, int *devnump);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600534
535/**
536 * dev_read_u32_array() - Find and read an array of 32 bit integers
537 *
538 * Search for a property in a device node and read 32-bit value(s) from
539 * it.
540 *
541 * The out_values is modified only if a valid u32 value can be decoded.
542 *
543 * @dev: device to look up
544 * @propname: name of the property to read
545 * @out_values: pointer to return value, modified only if return value is 0
546 * @sz: number of array elements to read
547 * @return 0 on success, -EINVAL if the property does not exist, -ENODATA if
548 * property does not have a value, and -EOVERFLOW if the property data isn't
549 * large enough.
550 */
Simon Glass88b3a372020-01-27 08:49:40 -0700551int dev_read_u32_array(const struct udevice *dev, const char *propname,
Simon Glass47a0fd32017-05-18 20:09:04 -0600552 u32 *out_values, size_t sz);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600553
554/**
555 * dev_read_first_subnode() - find the first subnode of a device's node
556 *
557 * @dev: device to look up
558 * @return reference to the first subnode (which can be invalid if the device's
559 * node has no subnodes)
560 */
Simon Glass88b3a372020-01-27 08:49:40 -0700561ofnode dev_read_first_subnode(const struct udevice *dev);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600562
563/**
564 * ofnode_next_subnode() - find the next sibling of a subnode
565 *
566 * @node: valid reference to previous node (sibling)
567 * @return reference to the next subnode (which can be invalid if the node
568 * has no more siblings)
569 */
Simon Glass47a0fd32017-05-18 20:09:04 -0600570ofnode dev_read_next_subnode(ofnode node);
Simon Glassf11c7ab2017-05-18 20:09:03 -0600571
572/**
573 * dev_read_u8_array_ptr() - find an 8-bit array
574 *
575 * Look up a device's node property and return a pointer to its contents as a
576 * byte array of given length. The property must have at least enough data
577 * for the array (count bytes). It may have more, but this will be ignored.
578 * The data is not copied.
579 *
580 * @dev: device to look up
581 * @propname: name of property to find
582 * @sz: number of array elements
583 * @return pointer to byte array if found, or NULL if the property is not
584 * found or there is not enough data
585 */
Simon Glass88b3a372020-01-27 08:49:40 -0700586const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev,
587 const char *propname, size_t sz);
Simon Glass47a0fd32017-05-18 20:09:04 -0600588
Simon Glassf7d6fcf2017-06-12 06:21:30 -0600589/**
590 * dev_read_enabled() - check whether a node is enabled
591 *
592 * This looks for a 'status' property. If this exists, then returns 1 if
593 * the status is 'ok' and 0 otherwise. If there is no status property,
594 * it returns 1 on the assumption that anything mentioned should be enabled
595 * by default.
596 *
597 * @dev: device to examine
598 * @return integer value 0 (not enabled) or 1 (enabled)
599 */
Simon Glass88b3a372020-01-27 08:49:40 -0700600int dev_read_enabled(const struct udevice *dev);
Simon Glassf7d6fcf2017-06-12 06:21:30 -0600601
Simon Glassdcf98852017-07-25 08:29:55 -0600602/**
603 * dev_read_resource() - obtain an indexed resource from a device.
604 *
Masahiro Yamada7b8b47b2017-08-26 01:12:30 +0900605 * @dev: device to examine
Simon Glassdcf98852017-07-25 08:29:55 -0600606 * @index index of the resource to retrieve (0 = first)
607 * @res returns the resource
608 * @return 0 if ok, negative on error
609 */
Simon Glass88b3a372020-01-27 08:49:40 -0700610int dev_read_resource(const struct udevice *dev, uint index,
611 struct resource *res);
Simon Glassdcf98852017-07-25 08:29:55 -0600612
Masahiro Yamada7b8b47b2017-08-26 01:12:30 +0900613/**
614 * dev_read_resource_byname() - obtain a named resource from a device.
615 *
616 * @dev: device to examine
617 * @name: name of the resource to retrieve
618 * @res: returns the resource
619 * @return 0 if ok, negative on error
620 */
Simon Glass88b3a372020-01-27 08:49:40 -0700621int dev_read_resource_byname(const struct udevice *dev, const char *name,
Masahiro Yamada7b8b47b2017-08-26 01:12:30 +0900622 struct resource *res);
623
Mario Six147c6072018-01-15 11:07:19 +0100624/**
Fabien Dessenne641067f2019-05-31 15:11:30 +0200625 * dev_translate_address() - Translate a device-tree address
Mario Six147c6072018-01-15 11:07:19 +0100626 *
627 * Translate an address from the device-tree into a CPU physical address. This
628 * function walks up the tree and applies the various bus mappings along the
629 * way.
630 *
631 * @dev: device giving the context in which to translate the address
632 * @in_addr: pointer to the address to translate
633 * @return the translated address; OF_BAD_ADDR on error
634 */
Simon Glass88b3a372020-01-27 08:49:40 -0700635u64 dev_translate_address(const struct udevice *dev, const fdt32_t *in_addr);
Michal Simek83e4c7e2019-01-31 16:30:59 +0100636
637/**
Fabien Dessenne641067f2019-05-31 15:11:30 +0200638 * dev_translate_dma_address() - Translate a device-tree DMA address
639 *
640 * Translate a DMA address from the device-tree into a CPU physical address.
641 * This function walks up the tree and applies the various bus mappings along
642 * the way.
643 *
644 * @dev: device giving the context in which to translate the DMA address
645 * @in_addr: pointer to the DMA address to translate
646 * @return the translated DMA address; OF_BAD_ADDR on error
647 */
Simon Glass88b3a372020-01-27 08:49:40 -0700648u64 dev_translate_dma_address(const struct udevice *dev,
649 const fdt32_t *in_addr);
Fabien Dessenne641067f2019-05-31 15:11:30 +0200650
651/**
Michal Simek83e4c7e2019-01-31 16:30:59 +0100652 * dev_read_alias_highest_id - Get highest alias id for the given stem
653 * @stem: Alias stem to be examined
654 *
655 * The function travels the lookup table to get the highest alias id for the
656 * given alias stem.
657 * @return alias ID, if found, else -1
658 */
659int dev_read_alias_highest_id(const char *stem);
660
Chunfeng Yun89b84b82020-05-02 11:35:09 +0200661/**
662 * dev_get_child_count() - get the child count of a device
663 *
664 * @dev: device to use for interation (struct udevice *)
665 * @return the count of child subnode
666 */
667int dev_get_child_count(const struct udevice *dev);
668
Stefan Roese68f81b82020-08-05 13:56:11 +0200669/**
670 * dev_read_pci_bus_range - Read PCI bus-range resource
671 *
672 * Look at the bus range property of a device node and return the pci bus
673 * range for this node.
674 *
675 * @dev: device to examine
676 * @res returns the resource
677 * @return 0 if ok, negative on error
678 */
679int dev_read_pci_bus_range(const struct udevice *dev, struct resource *res);
680
Dario Binacchi15daa482020-12-30 00:16:26 +0100681/**
682 * dev_decode_display_timing() - decode display timings
683 *
684 * Decode display timings from the supplied 'display-timings' node.
685 * See doc/device-tree-bindings/video/display-timing.txt for binding
686 * information.
687 *
688 * @dev: device to read DT display timings from. The node linked to the device
689 * contains a child node called 'display-timings' which in turn contains
690 * one or more display timing nodes.
691 * @index: index number to read (0=first timing subnode)
692 * @config: place to put timings
693 * @return 0 if OK, -FDT_ERR_NOTFOUND if not found
694 */
695int dev_decode_display_timing(const struct udevice *dev, int index,
696 struct display_timing *config);
697
Simon Glass47a0fd32017-05-18 20:09:04 -0600698#else /* CONFIG_DM_DEV_READ_INLINE is enabled */
699
Simon Glass88b3a372020-01-27 08:49:40 -0700700static inline int dev_read_u32(const struct udevice *dev,
Masahiro Yamada3ab48f62017-12-30 02:00:05 +0900701 const char *propname, u32 *outp)
702{
703 return ofnode_read_u32(dev_ofnode(dev), propname, outp);
704}
705
Simon Glass88b3a372020-01-27 08:49:40 -0700706static inline int dev_read_u32_default(const struct udevice *dev,
Simon Glass47a0fd32017-05-18 20:09:04 -0600707 const char *propname, int def)
708{
709 return ofnode_read_u32_default(dev_ofnode(dev), propname, def);
710}
711
Dario Binacchi4bb70752020-03-29 18:04:41 +0200712static inline int dev_read_u32_index(struct udevice *dev,
713 const char *propname, int index, u32 *outp)
714{
715 return ofnode_read_u32_index(dev_ofnode(dev), propname, index, outp);
716}
717
718static inline u32 dev_read_u32_index_default(struct udevice *dev,
719 const char *propname, int index,
720 u32 def)
721{
722 return ofnode_read_u32_index_default(dev_ofnode(dev), propname, index,
723 def);
724}
725
Simon Glass88b3a372020-01-27 08:49:40 -0700726static inline int dev_read_s32(const struct udevice *dev,
Simon Glassa1b17e42018-12-10 10:37:37 -0700727 const char *propname, s32 *outp)
728{
729 return ofnode_read_s32(dev_ofnode(dev), propname, outp);
730}
731
Simon Glass88b3a372020-01-27 08:49:40 -0700732static inline int dev_read_s32_default(const struct udevice *dev,
Simon Glassa1b17e42018-12-10 10:37:37 -0700733 const char *propname, int def)
734{
735 return ofnode_read_s32_default(dev_ofnode(dev), propname, def);
736}
737
Simon Glass88b3a372020-01-27 08:49:40 -0700738static inline int dev_read_u32u(const struct udevice *dev,
Simon Glassa1b17e42018-12-10 10:37:37 -0700739 const char *propname, uint *outp)
740{
741 u32 val;
742 int ret;
743
744 ret = ofnode_read_u32(dev_ofnode(dev), propname, &val);
745 if (ret)
746 return ret;
747 *outp = val;
748
749 return 0;
750}
751
Simon Glass88b3a372020-01-27 08:49:40 -0700752static inline int dev_read_u64(const struct udevice *dev,
T Karthik Reddy3f3d7712019-09-02 16:34:30 +0200753 const char *propname, u64 *outp)
754{
755 return ofnode_read_u64(dev_ofnode(dev), propname, outp);
756}
757
Simon Glass88b3a372020-01-27 08:49:40 -0700758static inline u64 dev_read_u64_default(const struct udevice *dev,
T Karthik Reddy3f3d7712019-09-02 16:34:30 +0200759 const char *propname, u64 def)
760{
761 return ofnode_read_u64_default(dev_ofnode(dev), propname, def);
762}
763
Simon Glass88b3a372020-01-27 08:49:40 -0700764static inline const char *dev_read_string(const struct udevice *dev,
Simon Glass47a0fd32017-05-18 20:09:04 -0600765 const char *propname)
766{
767 return ofnode_read_string(dev_ofnode(dev), propname);
768}
769
Simon Glass88b3a372020-01-27 08:49:40 -0700770static inline bool dev_read_bool(const struct udevice *dev,
771 const char *propname)
Simon Glass47a0fd32017-05-18 20:09:04 -0600772{
773 return ofnode_read_bool(dev_ofnode(dev), propname);
774}
775
Simon Glass88b3a372020-01-27 08:49:40 -0700776static inline ofnode dev_read_subnode(const struct udevice *dev,
Simon Glass47a0fd32017-05-18 20:09:04 -0600777 const char *subbnode_name)
778{
779 return ofnode_find_subnode(dev_ofnode(dev), subbnode_name);
780}
781
Simon Glass88b3a372020-01-27 08:49:40 -0700782static inline int dev_read_size(const struct udevice *dev, const char *propname)
Simon Glass47a0fd32017-05-18 20:09:04 -0600783{
784 return ofnode_read_size(dev_ofnode(dev), propname);
785}
786
Simon Glass88b3a372020-01-27 08:49:40 -0700787static inline fdt_addr_t dev_read_addr_index(const struct udevice *dev,
788 int index)
Simon Glass47a0fd32017-05-18 20:09:04 -0600789{
790 return devfdt_get_addr_index(dev, index);
791}
792
Simon Glass88b3a372020-01-27 08:49:40 -0700793static inline fdt_addr_t dev_read_addr_size_index(const struct udevice *dev,
Sekhar Norif5b90472019-08-01 19:12:56 +0530794 int index,
795 fdt_size_t *size)
796{
797 return devfdt_get_addr_size_index(dev, index, size);
798}
799
Simon Glass88b3a372020-01-27 08:49:40 -0700800static inline fdt_addr_t dev_read_addr_name(const struct udevice *dev,
Álvaro Fernández Rojas79598822018-12-03 19:37:09 +0100801 const char *name)
802{
803 return devfdt_get_addr_name(dev, name);
804}
805
Simon Glass88b3a372020-01-27 08:49:40 -0700806static inline fdt_addr_t dev_read_addr_size_name(const struct udevice *dev,
Sekhar Norif5b90472019-08-01 19:12:56 +0530807 const char *name,
808 fdt_size_t *size)
809{
810 return devfdt_get_addr_size_name(dev, name, size);
811}
812
Simon Glass88b3a372020-01-27 08:49:40 -0700813static inline fdt_addr_t dev_read_addr(const struct udevice *dev)
Simon Glass47a0fd32017-05-18 20:09:04 -0600814{
815 return devfdt_get_addr(dev);
816}
817
Simon Glass88b3a372020-01-27 08:49:40 -0700818static inline void *dev_read_addr_ptr(const struct udevice *dev)
Philipp Tomsichc131c8b2017-09-11 22:04:12 +0200819{
Ovidiu Panait3fe69d32020-08-03 22:17:35 +0300820 return devfdt_get_addr_ptr(dev);
Philipp Tomsichc131c8b2017-09-11 22:04:12 +0200821}
822
Simon Glass88b3a372020-01-27 08:49:40 -0700823static inline fdt_addr_t dev_read_addr_pci(const struct udevice *dev)
Simon Glass33c215a2019-09-15 12:08:58 -0600824{
825 return devfdt_get_addr_pci(dev);
826}
827
Simon Glass88b3a372020-01-27 08:49:40 -0700828static inline void *dev_remap_addr(const struct udevice *dev)
Álvaro Fernández Rojas30a90f52018-04-29 21:56:54 +0200829{
830 return devfdt_remap_addr(dev);
831}
832
Simon Glass88b3a372020-01-27 08:49:40 -0700833static inline void *dev_remap_addr_index(const struct udevice *dev, int index)
Álvaro Fernández Rojas30a90f52018-04-29 21:56:54 +0200834{
835 return devfdt_remap_addr_index(dev, index);
836}
837
Simon Glass88b3a372020-01-27 08:49:40 -0700838static inline void *dev_remap_addr_name(const struct udevice *dev,
839 const char *name)
Álvaro Fernández Rojas79598822018-12-03 19:37:09 +0100840{
841 return devfdt_remap_addr_name(dev, name);
842}
843
Simon Glass88b3a372020-01-27 08:49:40 -0700844static inline fdt_addr_t dev_read_addr_size(const struct udevice *dev,
Simon Glass47a0fd32017-05-18 20:09:04 -0600845 const char *propname,
846 fdt_size_t *sizep)
847{
848 return ofnode_get_addr_size(dev_ofnode(dev), propname, sizep);
849}
850
Simon Glass88b3a372020-01-27 08:49:40 -0700851static inline const char *dev_read_name(const struct udevice *dev)
Simon Glass47a0fd32017-05-18 20:09:04 -0600852{
853 return ofnode_get_name(dev_ofnode(dev));
854}
855
Simon Glass88b3a372020-01-27 08:49:40 -0700856static inline int dev_read_stringlist_search(const struct udevice *dev,
Simon Glass47a0fd32017-05-18 20:09:04 -0600857 const char *propname,
858 const char *string)
859{
860 return ofnode_stringlist_search(dev_ofnode(dev), propname, string);
861}
862
Simon Glass88b3a372020-01-27 08:49:40 -0700863static inline int dev_read_string_index(const struct udevice *dev,
Jean-Jacques Hiblotb5a144a2017-09-21 17:03:09 +0200864 const char *propname, int index,
865 const char **outp)
866{
867 return ofnode_read_string_index(dev_ofnode(dev), propname, index, outp);
868}
869
Simon Glass88b3a372020-01-27 08:49:40 -0700870static inline int dev_read_string_count(const struct udevice *dev,
Jean-Jacques Hiblotb5a144a2017-09-21 17:03:09 +0200871 const char *propname)
872{
873 return ofnode_read_string_count(dev_ofnode(dev), propname);
874}
875
Simon Glass88b3a372020-01-27 08:49:40 -0700876static inline int dev_read_phandle_with_args(const struct udevice *dev,
Simon Glass47a0fd32017-05-18 20:09:04 -0600877 const char *list_name, const char *cells_name, int cell_count,
878 int index, struct ofnode_phandle_args *out_args)
879{
880 return ofnode_parse_phandle_with_args(dev_ofnode(dev), list_name,
881 cells_name, cell_count, index,
882 out_args);
883}
884
Simon Glass88b3a372020-01-27 08:49:40 -0700885static inline int dev_count_phandle_with_args(const struct udevice *dev,
Patrick Delaunay89f68302020-09-25 09:41:14 +0200886 const char *list_name, const char *cells_name, int cell_count)
Patrice Chotard642346a2017-07-18 11:57:08 +0200887{
888 return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
Patrick Delaunay89f68302020-09-25 09:41:14 +0200889 cells_name, cell_count);
Patrice Chotard642346a2017-07-18 11:57:08 +0200890}
891
Simon Glass88b3a372020-01-27 08:49:40 -0700892static inline int dev_read_addr_cells(const struct udevice *dev)
Simon Glass47a0fd32017-05-18 20:09:04 -0600893{
Heinrich Schuchardtae6b33d2020-07-25 21:38:49 +0200894 int parent = fdt_parent_offset(gd->fdt_blob, dev_of_offset(dev));
895
896 return fdt_address_cells(gd->fdt_blob, parent);
Simon Glass47a0fd32017-05-18 20:09:04 -0600897}
898
Simon Glass88b3a372020-01-27 08:49:40 -0700899static inline int dev_read_size_cells(const struct udevice *dev)
Simon Glass47a0fd32017-05-18 20:09:04 -0600900{
Heinrich Schuchardtae6b33d2020-07-25 21:38:49 +0200901 int parent = fdt_parent_offset(gd->fdt_blob, dev_of_offset(dev));
902
903 return fdt_size_cells(gd->fdt_blob, parent);
Simon Glass878d68c2017-06-12 06:21:31 -0600904}
905
Simon Glass88b3a372020-01-27 08:49:40 -0700906static inline int dev_read_simple_addr_cells(const struct udevice *dev)
Simon Glass878d68c2017-06-12 06:21:31 -0600907{
908 return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
909}
910
Simon Glass88b3a372020-01-27 08:49:40 -0700911static inline int dev_read_simple_size_cells(const struct udevice *dev)
Simon Glass878d68c2017-06-12 06:21:31 -0600912{
Simon Glass47a0fd32017-05-18 20:09:04 -0600913 return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
914}
915
Simon Glass88b3a372020-01-27 08:49:40 -0700916static inline int dev_read_phandle(const struct udevice *dev)
Simon Glass47a0fd32017-05-18 20:09:04 -0600917{
918 return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev));
919}
920
Simon Glass88b3a372020-01-27 08:49:40 -0700921static inline const void *dev_read_prop(const struct udevice *dev,
Masahiro Yamadafd736212017-07-17 12:18:39 +0900922 const char *propname, int *lenp)
Simon Glass47a0fd32017-05-18 20:09:04 -0600923{
Masahiro Yamada61e51ba2017-06-22 16:54:05 +0900924 return ofnode_get_property(dev_ofnode(dev), propname, lenp);
Simon Glass47a0fd32017-05-18 20:09:04 -0600925}
926
Patrick Delaunayce891fca2020-01-13 11:34:56 +0100927static inline int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop)
928{
929 return ofnode_get_first_property(dev_ofnode(dev), prop);
930}
931
932static inline int dev_read_next_prop(struct ofprop *prop)
933{
934 return ofnode_get_next_property(prop);
935}
936
937static inline const void *dev_read_prop_by_prop(struct ofprop *prop,
938 const char **propname,
939 int *lenp)
940{
941 return ofnode_get_property_by_prop(prop, propname, lenp);
942}
943
Simon Glass88b3a372020-01-27 08:49:40 -0700944static inline int dev_read_alias_seq(const struct udevice *dev, int *devnump)
Simon Glass47a0fd32017-05-18 20:09:04 -0600945{
Marcel Ziswiler45224e82019-05-20 02:44:57 +0200946#if CONFIG_IS_ENABLED(OF_CONTROL)
Simon Glass47a0fd32017-05-18 20:09:04 -0600947 return fdtdec_get_alias_seq(gd->fdt_blob, dev->uclass->uc_drv->name,
948 dev_of_offset(dev), devnump);
Marcel Ziswiler45224e82019-05-20 02:44:57 +0200949#else
950 return -ENOTSUPP;
951#endif
Simon Glass47a0fd32017-05-18 20:09:04 -0600952}
953
Simon Glass88b3a372020-01-27 08:49:40 -0700954static inline int dev_read_u32_array(const struct udevice *dev,
955 const char *propname, u32 *out_values,
956 size_t sz)
Simon Glass47a0fd32017-05-18 20:09:04 -0600957{
958 return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
959}
960
Simon Glass88b3a372020-01-27 08:49:40 -0700961static inline ofnode dev_read_first_subnode(const struct udevice *dev)
Simon Glass47a0fd32017-05-18 20:09:04 -0600962{
963 return ofnode_first_subnode(dev_ofnode(dev));
964}
965
966static inline ofnode dev_read_next_subnode(ofnode node)
967{
968 return ofnode_next_subnode(node);
969}
970
Simon Glass88b3a372020-01-27 08:49:40 -0700971static inline const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev,
Simon Glassf262d4c2020-01-27 08:49:47 -0700972 const char *propname,
973 size_t sz)
Simon Glassf11c7ab2017-05-18 20:09:03 -0600974{
975 return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
976}
977
Simon Glass88b3a372020-01-27 08:49:40 -0700978static inline int dev_read_enabled(const struct udevice *dev)
Simon Glassf7d6fcf2017-06-12 06:21:30 -0600979{
980 return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev));
981}
982
Simon Glass88b3a372020-01-27 08:49:40 -0700983static inline int dev_read_resource(const struct udevice *dev, uint index,
Simon Glassdcf98852017-07-25 08:29:55 -0600984 struct resource *res)
985{
986 return ofnode_read_resource(dev_ofnode(dev), index, res);
987}
988
Simon Glass88b3a372020-01-27 08:49:40 -0700989static inline int dev_read_resource_byname(const struct udevice *dev,
Masahiro Yamada7b8b47b2017-08-26 01:12:30 +0900990 const char *name,
991 struct resource *res)
992{
993 return ofnode_read_resource_byname(dev_ofnode(dev), name, res);
994}
995
Simon Glass88b3a372020-01-27 08:49:40 -0700996static inline u64 dev_translate_address(const struct udevice *dev,
997 const fdt32_t *in_addr)
Mario Six147c6072018-01-15 11:07:19 +0100998{
999 return ofnode_translate_address(dev_ofnode(dev), in_addr);
1000}
1001
Simon Glass88b3a372020-01-27 08:49:40 -07001002static inline u64 dev_translate_dma_address(const struct udevice *dev,
1003 const fdt32_t *in_addr)
Fabien Dessenne641067f2019-05-31 15:11:30 +02001004{
1005 return ofnode_translate_dma_address(dev_ofnode(dev), in_addr);
1006}
1007
Michal Simek83e4c7e2019-01-31 16:30:59 +01001008static inline int dev_read_alias_highest_id(const char *stem)
1009{
Michael Walle0a6b75f2020-06-02 01:47:08 +02001010 if (!CONFIG_IS_ENABLED(OF_LIBFDT))
1011 return -1;
Michal Simek83e4c7e2019-01-31 16:30:59 +01001012 return fdtdec_get_alias_highest_id(gd->fdt_blob, stem);
1013}
1014
Chunfeng Yun89b84b82020-05-02 11:35:09 +02001015static inline int dev_get_child_count(const struct udevice *dev)
1016{
1017 return ofnode_get_child_count(dev_ofnode(dev));
1018}
1019
Dario Binacchi15daa482020-12-30 00:16:26 +01001020static inline int dev_decode_display_timing(const struct udevice *dev,
1021 int index,
1022 struct display_timing *config)
1023{
1024 return ofnode_decode_display_timing(dev_ofnode(dev), index, config);
1025}
1026
Simon Glassf11c7ab2017-05-18 20:09:03 -06001027#endif /* CONFIG_DM_DEV_READ_INLINE */
1028
1029/**
1030 * dev_for_each_subnode() - Helper function to iterate through subnodes
1031 *
1032 * This creates a for() loop which works through the subnodes in a device's
1033 * device-tree node.
1034 *
1035 * @subnode: ofnode holding the current subnode
1036 * @dev: device to use for interation (struct udevice *)
1037 */
1038#define dev_for_each_subnode(subnode, dev) \
1039 for (subnode = dev_read_first_subnode(dev); \
1040 ofnode_valid(subnode); \
1041 subnode = ofnode_next_subnode(subnode))
1042
Patrick Delaunayce891fca2020-01-13 11:34:56 +01001043/**
1044 * dev_for_each_property() - Helper function to iterate through property
1045 *
1046 * This creates a for() loop which works through the property in a device's
1047 * device-tree node.
1048 *
1049 * @prop: struct ofprop holding the current property
1050 * @dev: device to use for interation (struct udevice *)
1051 */
1052#define dev_for_each_property(prop, dev) \
1053 for (int ret_prop = dev_read_first_prop(dev, &prop); \
1054 !ret_prop; \
1055 ret_prop = dev_read_next_prop(&prop))
1056
Simon Glassf11c7ab2017-05-18 20:09:03 -06001057#endif