blob: 97575bcad0443af1477a51fa66d6f9d7795bc49e [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
Dan Murphyd3aa90e2020-07-23 07:01:38 -050012#include <linux/errno.h>
13
Simon Glass992b6032020-07-19 10:15:39 -060014#include <dm/device.h>
Simon Glass34ef0c22017-05-18 20:09:03 -060015#include <dm/fdtaddr.h>
16#include <dm/ofnode.h>
17#include <dm/uclass.h>
18
Simon Glass170e17c2017-06-12 06:21:29 -060019struct resource;
20
Simon Glass34ef0c22017-05-18 20:09:03 -060021#if CONFIG_IS_ENABLED(OF_LIVE)
Simon Glass2f9a6122020-01-27 08:49:40 -070022static inline const struct device_node *dev_np(const struct udevice *dev)
Simon Glass34ef0c22017-05-18 20:09:03 -060023{
Simon Glassa7ece582020-12-19 10:40:14 -070024 return ofnode_to_np(dev_ofnode(dev));
Simon Glass34ef0c22017-05-18 20:09:03 -060025}
26#else
Simon Glass2f9a6122020-01-27 08:49:40 -070027static inline const struct device_node *dev_np(const struct udevice *dev)
Simon Glass34ef0c22017-05-18 20:09:03 -060028{
29 return NULL;
30}
31#endif
32
Simon Glass77f7c1e2021-01-21 13:57:10 -070033#if !defined(CONFIG_DM_DEV_READ_INLINE) || CONFIG_IS_ENABLED(OF_PLATDATA)
Simon Glasscfdae5c2017-05-18 20:09:04 -060034/**
Masahiro Yamada71d115f2017-12-30 02:00:05 +090035 * dev_read_u32() - read a 32-bit integer from a device's DT property
36 *
37 * @dev: device to read DT property from
38 * @propname: name of the property to read from
39 * @outp: place to put value (if found)
40 * @return 0 if OK, -ve on error
41 */
Simon Glass2f9a6122020-01-27 08:49:40 -070042int dev_read_u32(const struct udevice *dev, const char *propname, u32 *outp);
Masahiro Yamada71d115f2017-12-30 02:00:05 +090043
44/**
Simon Glasscfdae5c2017-05-18 20:09:04 -060045 * dev_read_u32_default() - read a 32-bit integer from a device's DT property
46 *
47 * @dev: device to read DT property from
48 * @propname: name of the property to read from
49 * @def: default value to return if the property has no value
50 * @return property value, or @def if not found
51 */
Simon Glass2f9a6122020-01-27 08:49:40 -070052int dev_read_u32_default(const struct udevice *dev, const char *propname,
53 int def);
Simon Glass34ef0c22017-05-18 20:09:03 -060054
55/**
Dario Binacchi81d80b52020-03-29 18:04:41 +020056 * dev_read_u32_index() - read an indexed 32-bit integer from a device's DT
57 * property
58 *
59 * @dev: device to read DT property from
60 * @propname: name of the property to read from
61 * @index: index of the integer to return
62 * @outp: place to put value (if found)
63 * @return 0 if OK, -ve on error
64 */
65int dev_read_u32_index(struct udevice *dev, const char *propname, int index,
66 u32 *outp);
67
68/**
69 * dev_read_u32_index_default() - read an indexed 32-bit integer from a device's
70 * DT property
71 *
72 * @dev: device to read DT property from
73 * @propname: name of the property to read from
74 * @index: index of the integer to return
75 * @def: default value to return if the property has no value
76 * @return property value, or @def if not found
77 */
78u32 dev_read_u32_index_default(struct udevice *dev, const char *propname,
79 int index, u32 def);
80
81/**
Simon Glass6df01f92018-12-10 10:37:37 -070082 * dev_read_s32() - read a signed 32-bit integer from a device's DT property
83 *
84 * @dev: device to read DT property from
85 * @propname: name of the property to read from
86 * @outp: place to put value (if found)
87 * @return 0 if OK, -ve on error
88 */
Simon Glass2f9a6122020-01-27 08:49:40 -070089int dev_read_s32(const struct udevice *dev, const char *propname, s32 *outp);
Simon Glass6df01f92018-12-10 10:37:37 -070090
91/**
92 * dev_read_s32_default() - read a signed 32-bit int from a device's DT property
93 *
94 * @dev: device to read DT property from
95 * @propname: name of the property to read from
96 * @def: default value to return if the property has no value
97 * @return property value, or @def if not found
98 */
Simon Glass2f9a6122020-01-27 08:49:40 -070099int dev_read_s32_default(const struct udevice *dev, const char *propname,
100 int def);
Simon Glass6df01f92018-12-10 10:37:37 -0700101
102/**
103 * dev_read_u32u() - read a 32-bit integer from a device's DT property
104 *
105 * This version uses a standard uint type.
106 *
107 * @dev: device to read DT property from
108 * @propname: name of the property to read from
109 * @outp: place to put value (if found)
110 * @return 0 if OK, -ve on error
111 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700112int dev_read_u32u(const struct udevice *dev, const char *propname, uint *outp);
Simon Glass6df01f92018-12-10 10:37:37 -0700113
114/**
T Karthik Reddy478860d2019-09-02 16:34:30 +0200115 * dev_read_u64() - read a 64-bit integer from a device's DT property
116 *
117 * @dev: device to read DT property from
118 * @propname: name of the property to read from
119 * @outp: place to put value (if found)
120 * @return 0 if OK, -ve on error
121 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700122int dev_read_u64(const struct udevice *dev, const char *propname, u64 *outp);
T Karthik Reddy478860d2019-09-02 16:34:30 +0200123
124/**
125 * dev_read_u64_default() - read a 64-bit integer from a device's DT property
126 *
127 * @dev: device to read DT property from
128 * @propname: name of the property to read from
129 * @def: default value to return if the property has no value
130 * @return property value, or @def if not found
131 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700132u64 dev_read_u64_default(const struct udevice *dev, const char *propname,
133 u64 def);
T Karthik Reddy478860d2019-09-02 16:34:30 +0200134
135/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600136 * dev_read_string() - Read a string from a device's DT property
137 *
138 * @dev: device to read DT property from
139 * @propname: name of the property to read
140 * @return string from property value, or NULL if there is no such property
141 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700142const char *dev_read_string(const struct udevice *dev, const char *propname);
Simon Glass34ef0c22017-05-18 20:09:03 -0600143
144/**
145 * dev_read_bool() - read a boolean value from a device's DT property
146 *
147 * @dev: device to read DT property from
148 * @propname: name of property to read
149 * @return true if property is present (meaning true), false if not present
150 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700151bool dev_read_bool(const struct udevice *dev, const char *propname);
Simon Glass34ef0c22017-05-18 20:09:03 -0600152
153/**
154 * dev_read_subnode() - find a named subnode of a device
155 *
156 * @dev: device whose DT node contains the subnode
157 * @subnode_name: name of subnode to find
158 * @return reference to subnode (which can be invalid if there is no such
159 * subnode)
160 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700161ofnode dev_read_subnode(const struct udevice *dev, const char *subbnode_name);
Simon Glass34ef0c22017-05-18 20:09:03 -0600162
163/**
164 * dev_read_size() - read the size of a property
165 *
166 * @dev: device to check
167 * @propname: property to check
168 * @return size of property if present, or -EINVAL if not
169 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700170int dev_read_size(const struct udevice *dev, const char *propname);
Simon Glass34ef0c22017-05-18 20:09:03 -0600171
172/**
173 * dev_read_addr_index() - Get the indexed reg property of a device
174 *
175 * @dev: Device to read from
176 * @index: the 'reg' property can hold a list of <addr, size> pairs
177 * and @index is used to select which one is required
178 *
179 * @return address or FDT_ADDR_T_NONE if not found
180 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700181fdt_addr_t dev_read_addr_index(const struct udevice *dev, int index);
Simon Glass34ef0c22017-05-18 20:09:03 -0600182
183/**
Sekhar Norif677c6f2019-08-01 19:12:56 +0530184 * dev_read_addr_size_index() - Get the indexed reg property of a device
185 *
186 * @dev: Device to read from
187 * @index: the 'reg' property can hold a list of <addr, size> pairs
188 * and @index is used to select which one is required
189 * @size: place to put size value (on success)
190 *
191 * @return address or FDT_ADDR_T_NONE if not found
192 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700193fdt_addr_t dev_read_addr_size_index(const struct udevice *dev, int index,
Sekhar Norif677c6f2019-08-01 19:12:56 +0530194 fdt_size_t *size);
195
196/**
Álvaro Fernández Rojas670361292018-04-29 21:56:54 +0200197 * dev_remap_addr_index() - Get the indexed reg property of a device
198 * as a memory-mapped I/O pointer
199 *
200 * @dev: Device to read from
201 * @index: the 'reg' property can hold a list of <addr, size> pairs
202 * and @index is used to select which one is required
203 *
204 * @return pointer or NULL if not found
205 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700206void *dev_remap_addr_index(const struct udevice *dev, int index);
Álvaro Fernández Rojas670361292018-04-29 21:56:54 +0200207
208/**
Álvaro Fernández Rojasa3181152018-12-03 19:37:09 +0100209 * dev_read_addr_name() - Get the reg property of a device, indexed by name
210 *
211 * @dev: Device to read from
212 * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
213 * 'reg-names' property providing named-based identification. @index
214 * indicates the value to search for in 'reg-names'.
215 *
216 * @return address or FDT_ADDR_T_NONE if not found
217 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700218fdt_addr_t dev_read_addr_name(const struct udevice *dev, const char *name);
Álvaro Fernández Rojasa3181152018-12-03 19:37:09 +0100219
220/**
Sekhar Norif677c6f2019-08-01 19:12:56 +0530221 * dev_read_addr_size_name() - Get the reg property of a device, indexed by name
222 *
223 * @dev: Device to read from
224 * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
225 * 'reg-names' property providing named-based identification. @index
226 * indicates the value to search for in 'reg-names'.
227 * @size: place to put size value (on success)
228 *
229 * @return address or FDT_ADDR_T_NONE if not found
230 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700231fdt_addr_t dev_read_addr_size_name(const struct udevice *dev, const char *name,
Sekhar Norif677c6f2019-08-01 19:12:56 +0530232 fdt_size_t *size);
233
234/**
Álvaro Fernández Rojasa3181152018-12-03 19:37:09 +0100235 * dev_remap_addr_name() - Get the reg property of a device, indexed by name,
236 * as a memory-mapped I/O pointer
237 *
238 * @dev: Device to read from
239 * @name: the 'reg' property can hold a list of <addr, size> pairs, with the
240 * 'reg-names' property providing named-based identification. @index
241 * indicates the value to search for in 'reg-names'.
242 *
243 * @return pointer or NULL if not found
244 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700245void *dev_remap_addr_name(const struct udevice *dev, const char *name);
Álvaro Fernández Rojasa3181152018-12-03 19:37:09 +0100246
247/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600248 * dev_read_addr() - Get the reg property of a device
249 *
250 * @dev: Device to read from
251 *
252 * @return address or FDT_ADDR_T_NONE if not found
253 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700254fdt_addr_t dev_read_addr(const struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600255
256/**
Philipp Tomsich7719b392017-09-11 22:04:12 +0200257 * dev_read_addr_ptr() - Get the reg property of a device
258 * as a pointer
259 *
260 * @dev: Device to read from
261 *
262 * @return pointer or NULL if not found
263 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700264void *dev_read_addr_ptr(const struct udevice *dev);
Philipp Tomsich7719b392017-09-11 22:04:12 +0200265
266/**
Simon Glass23b27592019-09-15 12:08:58 -0600267 * dev_read_addr_pci() - Read an address and handle PCI address translation
268 *
269 * At present U-Boot does not have address translation logic for PCI in the
270 * livetree implementation (of_addr.c). This special function supports this for
271 * the flat tree implementation.
272 *
273 * This function should be removed (and code should use dev_read() instead)
274 * once:
275 *
276 * 1. PCI address translation is added; and either
277 * 2. everything uses livetree where PCI translation is used (which is feasible
278 * in SPL and U-Boot proper) or PCI address translation is added to
279 * fdtdec_get_addr() and friends.
280 *
281 * @dev: Device to read from
282 * @return address or FDT_ADDR_T_NONE if not found
283 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700284fdt_addr_t dev_read_addr_pci(const struct udevice *dev);
Simon Glass23b27592019-09-15 12:08:58 -0600285
286/**
Álvaro Fernández Rojas670361292018-04-29 21:56:54 +0200287 * dev_remap_addr() - Get the reg property of a device as a
288 * memory-mapped I/O pointer
289 *
290 * @dev: Device to read from
291 *
292 * @return pointer or NULL if not found
293 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700294void *dev_remap_addr(const struct udevice *dev);
Álvaro Fernández Rojas670361292018-04-29 21:56:54 +0200295
296/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600297 * dev_read_addr_size() - get address and size from a device property
298 *
299 * This does no address translation. It simply reads an property that contains
300 * an address and a size value, one after the other.
301 *
302 * @dev: Device to read from
303 * @propname: property to read
304 * @sizep: place to put size value (on success)
305 * @return address value, or FDT_ADDR_T_NONE on error
306 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700307fdt_addr_t dev_read_addr_size(const struct udevice *dev, const char *propname,
308 fdt_size_t *sizep);
Simon Glass34ef0c22017-05-18 20:09:03 -0600309
310/**
311 * dev_read_name() - get the name of a device's node
312 *
Bin Meng4cf914d2019-07-05 09:23:18 -0700313 * @dev: Device to read from
Simon Glass34ef0c22017-05-18 20:09:03 -0600314 * @return name of node
315 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700316const char *dev_read_name(const struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600317
318/**
319 * dev_read_stringlist_search() - find string in a string list and return index
320 *
321 * Note that it is possible for this function to succeed on property values
322 * that are not NUL-terminated. That's because the function will stop after
323 * finding the first occurrence of @string. This can for example happen with
324 * small-valued cell properties, such as #address-cells, when searching for
325 * the empty string.
326 *
327 * @dev: device to check
328 * @propname: name of the property containing the string list
329 * @string: string to look up in the string list
330 *
331 * @return:
332 * the index of the string in the list of strings
333 * -ENODATA if the property is not found
334 * -EINVAL on some other error
335 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700336int dev_read_stringlist_search(const struct udevice *dev, const char *property,
337 const char *string);
Simon Glass34ef0c22017-05-18 20:09:03 -0600338
339/**
Jean-Jacques Hiblot8365ebd2017-09-21 17:03:09 +0200340 * dev_read_string_index() - obtain an indexed string from a string list
341 *
342 * @dev: device to examine
343 * @propname: name of the property containing the string list
344 * @index: index of the string to return
345 * @out: return location for the string
346 *
347 * @return:
348 * length of string, if found or -ve error value if not found
349 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700350int dev_read_string_index(const struct udevice *dev, const char *propname,
351 int index, const char **outp);
Jean-Jacques Hiblot8365ebd2017-09-21 17:03:09 +0200352
353/**
354 * dev_read_string_count() - find the number of strings in a string list
355 *
356 * @dev: device to examine
357 * @propname: name of the property containing the string list
358 * @return:
359 * number of strings in the list, or -ve error value if not found
360 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700361int dev_read_string_count(const struct udevice *dev, const char *propname);
Jean-Jacques Hiblot8365ebd2017-09-21 17:03:09 +0200362/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600363 * dev_read_phandle_with_args() - Find a node pointed by phandle in a list
364 *
365 * This function is useful to parse lists of phandles and their arguments.
366 * Returns 0 on success and fills out_args, on error returns appropriate
367 * errno value.
368 *
369 * Caller is responsible to call of_node_put() on the returned out_args->np
370 * pointer.
371 *
372 * Example:
373 *
374 * phandle1: node1 {
375 * #list-cells = <2>;
376 * }
377 *
378 * phandle2: node2 {
379 * #list-cells = <1>;
380 * }
381 *
382 * node3 {
383 * list = <&phandle1 1 2 &phandle2 3>;
384 * }
385 *
386 * To get a device_node of the `node2' node you may call this:
387 * dev_read_phandle_with_args(dev, "list", "#list-cells", 0, 1, &args);
388 *
389 * @dev: device whose node containing a list
390 * @list_name: property name that contains a list
391 * @cells_name: property name that specifies phandles' arguments count
392 * @cells_count: Cell count to use if @cells_name is NULL
393 * @index: index of a phandle to parse out
394 * @out_args: optional pointer to output arguments structure (will be filled)
395 * @return 0 on success (with @out_args filled out if not NULL), -ENOENT if
396 * @list_name does not exist, -EINVAL if a phandle was not found,
397 * @cells_name could not be found, the arguments were truncated or there
398 * were too many arguments.
399 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700400int dev_read_phandle_with_args(const struct udevice *dev, const char *list_name,
401 const char *cells_name, int cell_count,
402 int index, struct ofnode_phandle_args *out_args);
Simon Glass34ef0c22017-05-18 20:09:03 -0600403
404/**
Patrice Chotardbe7dd602017-07-18 11:57:08 +0200405 * dev_count_phandle_with_args() - Return phandle number in a list
406 *
407 * This function is usefull to get phandle number contained in a property list.
408 * For example, this allows to allocate the right amount of memory to keep
409 * clock's reference contained into the "clocks" property.
410 *
411 *
412 * @dev: device whose node containing a list
413 * @list_name: property name that contains a list
414 * @cells_name: property name that specifies phandles' arguments count
Patrick Delaunayd776a842020-09-25 09:41:14 +0200415 * @cells_count: Cell count to use if @cells_name is NULL
Patrice Chotardbe7dd602017-07-18 11:57:08 +0200416 * @Returns number of phandle found on success, on error returns appropriate
417 * errno value.
418 */
419
Simon Glass2f9a6122020-01-27 08:49:40 -0700420int dev_count_phandle_with_args(const struct udevice *dev,
Patrick Delaunayd776a842020-09-25 09:41:14 +0200421 const char *list_name, const char *cells_name,
422 int cell_count);
Patrice Chotardbe7dd602017-07-18 11:57:08 +0200423
424/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600425 * dev_read_addr_cells() - Get the number of address cells for a device's node
426 *
427 * This walks back up the tree to find the closest #address-cells property
428 * which controls the given node.
429 *
Mario Six16408ee2018-01-15 11:09:36 +0100430 * @dev: device to check
Simon Glass34ef0c22017-05-18 20:09:03 -0600431 * @return number of address cells this node uses
432 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700433int dev_read_addr_cells(const struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600434
435/**
436 * dev_read_size_cells() - Get the number of size cells for a device's node
437 *
438 * This walks back up the tree to find the closest #size-cells property
439 * which controls the given node.
440 *
Mario Six16408ee2018-01-15 11:09:36 +0100441 * @dev: device to check
Simon Glass34ef0c22017-05-18 20:09:03 -0600442 * @return number of size cells this node uses
443 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700444int dev_read_size_cells(const struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600445
446/**
Simon Glass4191dc12017-06-12 06:21:31 -0600447 * dev_read_addr_cells() - Get the address cells property in a node
448 *
449 * This function matches fdt_address_cells().
450 *
Mario Six16408ee2018-01-15 11:09:36 +0100451 * @dev: device to check
Simon Glass4191dc12017-06-12 06:21:31 -0600452 * @return number of address cells this node uses
453 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700454int dev_read_simple_addr_cells(const struct udevice *dev);
Simon Glass4191dc12017-06-12 06:21:31 -0600455
456/**
457 * dev_read_size_cells() - Get the size cells property in a node
458 *
459 * This function matches fdt_size_cells().
460 *
Mario Six16408ee2018-01-15 11:09:36 +0100461 * @dev: device to check
Simon Glass4191dc12017-06-12 06:21:31 -0600462 * @return number of size cells this node uses
463 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700464int dev_read_simple_size_cells(const struct udevice *dev);
Simon Glass4191dc12017-06-12 06:21:31 -0600465
466/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600467 * dev_read_phandle() - Get the phandle from a device
468 *
469 * @dev: device to check
470 * @return phandle (1 or greater), or 0 if no phandle or other error
471 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700472int dev_read_phandle(const struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600473
474/**
475 * dev_read_prop()- - read a property from a device's node
476 *
477 * @dev: device to check
478 * @propname: property to read
479 * @lenp: place to put length on success
480 * @return pointer to property, or NULL if not found
481 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700482const void *dev_read_prop(const struct udevice *dev, const char *propname,
483 int *lenp);
Simon Glass34ef0c22017-05-18 20:09:03 -0600484
485/**
Patrick Delaunaycaee1552020-01-13 11:34:56 +0100486 * dev_read_first_prop()- get the reference of the first property
487 *
488 * Get reference to the first property of the node, it is used to iterate
489 * and read all the property with dev_read_prop_by_prop().
490 *
491 * @dev: device to check
492 * @prop: place to put argument reference
493 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
494 */
495int dev_read_first_prop(const struct udevice *dev, struct ofprop *prop);
496
497/**
498 * ofnode_get_next_property() - get the reference of the next property
499 *
500 * Get reference to the next property of the node, it is used to iterate
501 * and read all the property with dev_read_prop_by_prop().
502 *
503 * @prop: reference of current argument and place to put reference of next one
504 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
505 */
506int dev_read_next_prop(struct ofprop *prop);
507
508/**
509 * dev_read_prop_by_prop() - get a pointer to the value of a property
510 *
511 * Get value for the property identified by the provided reference.
512 *
513 * @prop: reference on property
514 * @propname: If non-NULL, place to property name on success,
515 * @lenp: If non-NULL, place to put length on success
516 * @return 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
517 */
518const void *dev_read_prop_by_prop(struct ofprop *prop,
519 const char **propname, int *lenp);
520
521/**
Simon Glass34ef0c22017-05-18 20:09:03 -0600522 * dev_read_alias_seq() - Get the alias sequence number of a node
523 *
524 * This works out whether a node is pointed to by an alias, and if so, the
525 * sequence number of that alias. Aliases are of the form <base><num> where
526 * <num> is the sequence number. For example spi2 would be sequence number 2.
527 *
528 * @dev: device to look up
529 * @devnump: set to the sequence number if one is found
530 * @return 0 if a sequence was found, -ve if not
531 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700532int dev_read_alias_seq(const struct udevice *dev, int *devnump);
Simon Glass34ef0c22017-05-18 20:09:03 -0600533
534/**
535 * dev_read_u32_array() - Find and read an array of 32 bit integers
536 *
537 * Search for a property in a device node and read 32-bit value(s) from
538 * it.
539 *
540 * The out_values is modified only if a valid u32 value can be decoded.
541 *
542 * @dev: device to look up
543 * @propname: name of the property to read
544 * @out_values: pointer to return value, modified only if return value is 0
545 * @sz: number of array elements to read
546 * @return 0 on success, -EINVAL if the property does not exist, -ENODATA if
547 * property does not have a value, and -EOVERFLOW if the property data isn't
548 * large enough.
549 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700550int dev_read_u32_array(const struct udevice *dev, const char *propname,
Simon Glasscfdae5c2017-05-18 20:09:04 -0600551 u32 *out_values, size_t sz);
Simon Glass34ef0c22017-05-18 20:09:03 -0600552
553/**
554 * dev_read_first_subnode() - find the first subnode of a device's node
555 *
556 * @dev: device to look up
557 * @return reference to the first subnode (which can be invalid if the device's
558 * node has no subnodes)
559 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700560ofnode dev_read_first_subnode(const struct udevice *dev);
Simon Glass34ef0c22017-05-18 20:09:03 -0600561
562/**
563 * ofnode_next_subnode() - find the next sibling of a subnode
564 *
565 * @node: valid reference to previous node (sibling)
566 * @return reference to the next subnode (which can be invalid if the node
567 * has no more siblings)
568 */
Simon Glasscfdae5c2017-05-18 20:09:04 -0600569ofnode dev_read_next_subnode(ofnode node);
Simon Glass34ef0c22017-05-18 20:09:03 -0600570
571/**
572 * dev_read_u8_array_ptr() - find an 8-bit array
573 *
574 * Look up a device's node property and return a pointer to its contents as a
575 * byte array of given length. The property must have at least enough data
576 * for the array (count bytes). It may have more, but this will be ignored.
577 * The data is not copied.
578 *
579 * @dev: device to look up
580 * @propname: name of property to find
581 * @sz: number of array elements
582 * @return pointer to byte array if found, or NULL if the property is not
583 * found or there is not enough data
584 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700585const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev,
586 const char *propname, size_t sz);
Simon Glasscfdae5c2017-05-18 20:09:04 -0600587
Simon Glassfa031f82017-06-12 06:21:30 -0600588/**
589 * dev_read_enabled() - check whether a node is enabled
590 *
591 * This looks for a 'status' property. If this exists, then returns 1 if
592 * the status is 'ok' and 0 otherwise. If there is no status property,
593 * it returns 1 on the assumption that anything mentioned should be enabled
594 * by default.
595 *
596 * @dev: device to examine
597 * @return integer value 0 (not enabled) or 1 (enabled)
598 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700599int dev_read_enabled(const struct udevice *dev);
Simon Glassfa031f82017-06-12 06:21:30 -0600600
Simon Glassf7bfcc42017-07-25 08:29:55 -0600601/**
602 * dev_read_resource() - obtain an indexed resource from a device.
603 *
Masahiro Yamada4dada2c2017-08-26 01:12:30 +0900604 * @dev: device to examine
Simon Glassf7bfcc42017-07-25 08:29:55 -0600605 * @index index of the resource to retrieve (0 = first)
606 * @res returns the resource
607 * @return 0 if ok, negative on error
608 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700609int dev_read_resource(const struct udevice *dev, uint index,
610 struct resource *res);
Simon Glassf7bfcc42017-07-25 08:29:55 -0600611
Masahiro Yamada4dada2c2017-08-26 01:12:30 +0900612/**
613 * dev_read_resource_byname() - obtain a named resource from a device.
614 *
615 * @dev: device to examine
616 * @name: name of the resource to retrieve
617 * @res: returns the resource
618 * @return 0 if ok, negative on error
619 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700620int dev_read_resource_byname(const struct udevice *dev, const char *name,
Masahiro Yamada4dada2c2017-08-26 01:12:30 +0900621 struct resource *res);
622
Mario Sixaefac062018-01-15 11:07:19 +0100623/**
Fabien Dessenne22236e02019-05-31 15:11:30 +0200624 * dev_translate_address() - Translate a device-tree address
Mario Sixaefac062018-01-15 11:07:19 +0100625 *
626 * Translate an address from the device-tree into a CPU physical address. This
627 * function walks up the tree and applies the various bus mappings along the
628 * way.
629 *
630 * @dev: device giving the context in which to translate the address
631 * @in_addr: pointer to the address to translate
632 * @return the translated address; OF_BAD_ADDR on error
633 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700634u64 dev_translate_address(const struct udevice *dev, const fdt32_t *in_addr);
Michal Simekd0e30a02019-01-31 16:30:59 +0100635
636/**
Fabien Dessenne22236e02019-05-31 15:11:30 +0200637 * dev_translate_dma_address() - Translate a device-tree DMA address
638 *
639 * Translate a DMA address from the device-tree into a CPU physical address.
640 * This function walks up the tree and applies the various bus mappings along
641 * the way.
642 *
643 * @dev: device giving the context in which to translate the DMA address
644 * @in_addr: pointer to the DMA address to translate
645 * @return the translated DMA address; OF_BAD_ADDR on error
646 */
Simon Glass2f9a6122020-01-27 08:49:40 -0700647u64 dev_translate_dma_address(const struct udevice *dev,
648 const fdt32_t *in_addr);
Fabien Dessenne22236e02019-05-31 15:11:30 +0200649
650/**
Michal Simekd0e30a02019-01-31 16:30:59 +0100651 * dev_read_alias_highest_id - Get highest alias id for the given stem
652 * @stem: Alias stem to be examined
653 *
654 * The function travels the lookup table to get the highest alias id for the
655 * given alias stem.
656 * @return alias ID, if found, else -1
657 */
658int dev_read_alias_highest_id(const char *stem);
659
developerd93c8b42020-05-02 11:35:09 +0200660/**
661 * dev_get_child_count() - get the child count of a device
662 *
663 * @dev: device to use for interation (struct udevice *)
664 * @return the count of child subnode
665 */
666int dev_get_child_count(const struct udevice *dev);
667
Stefan Roese0a9ecc52020-08-05 13:56:11 +0200668/**
669 * dev_read_pci_bus_range - Read PCI bus-range resource
670 *
671 * Look at the bus range property of a device node and return the pci bus
672 * range for this node.
673 *
674 * @dev: device to examine
675 * @res returns the resource
676 * @return 0 if ok, negative on error
677 */
678int dev_read_pci_bus_range(const struct udevice *dev, struct resource *res);
679
Dario Binacchi836cc9d2020-12-30 00:16:26 +0100680/**
681 * dev_decode_display_timing() - decode display timings
682 *
683 * Decode display timings from the supplied 'display-timings' node.
684 * See doc/device-tree-bindings/video/display-timing.txt for binding
685 * information.
686 *
687 * @dev: device to read DT display timings from. The node linked to the device
688 * contains a child node called 'display-timings' which in turn contains
689 * one or more display timing nodes.
690 * @index: index number to read (0=first timing subnode)
691 * @config: place to put timings
692 * @return 0 if OK, -FDT_ERR_NOTFOUND if not found
693 */
694int dev_decode_display_timing(const struct udevice *dev, int index,
695 struct display_timing *config);
696
Simon Glasscfdae5c2017-05-18 20:09:04 -0600697#else /* CONFIG_DM_DEV_READ_INLINE is enabled */
Simon Glass3ba929a2020-10-30 21:38:53 -0600698#include <asm/global_data.h>
Simon Glasscfdae5c2017-05-18 20:09:04 -0600699
Simon Glass2f9a6122020-01-27 08:49:40 -0700700static inline int dev_read_u32(const struct udevice *dev,
Masahiro Yamada71d115f2017-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 Glass2f9a6122020-01-27 08:49:40 -0700706static inline int dev_read_u32_default(const struct udevice *dev,
Simon Glasscfdae5c2017-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 Binacchi81d80b52020-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 Glass2f9a6122020-01-27 08:49:40 -0700726static inline int dev_read_s32(const struct udevice *dev,
Simon Glass6df01f92018-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 Glass2f9a6122020-01-27 08:49:40 -0700732static inline int dev_read_s32_default(const struct udevice *dev,
Simon Glass6df01f92018-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 Glass2f9a6122020-01-27 08:49:40 -0700738static inline int dev_read_u32u(const struct udevice *dev,
Simon Glass6df01f92018-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 Glass2f9a6122020-01-27 08:49:40 -0700752static inline int dev_read_u64(const struct udevice *dev,
T Karthik Reddy478860d2019-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 Glass2f9a6122020-01-27 08:49:40 -0700758static inline u64 dev_read_u64_default(const struct udevice *dev,
T Karthik Reddy478860d2019-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 Glass2f9a6122020-01-27 08:49:40 -0700764static inline const char *dev_read_string(const struct udevice *dev,
Simon Glasscfdae5c2017-05-18 20:09:04 -0600765 const char *propname)
766{
767 return ofnode_read_string(dev_ofnode(dev), propname);
768}
769
Simon Glass2f9a6122020-01-27 08:49:40 -0700770static inline bool dev_read_bool(const struct udevice *dev,
771 const char *propname)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600772{
773 return ofnode_read_bool(dev_ofnode(dev), propname);
774}
775
Simon Glass2f9a6122020-01-27 08:49:40 -0700776static inline ofnode dev_read_subnode(const struct udevice *dev,
Simon Glasscfdae5c2017-05-18 20:09:04 -0600777 const char *subbnode_name)
778{
779 return ofnode_find_subnode(dev_ofnode(dev), subbnode_name);
780}
781
Simon Glass2f9a6122020-01-27 08:49:40 -0700782static inline int dev_read_size(const struct udevice *dev, const char *propname)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600783{
784 return ofnode_read_size(dev_ofnode(dev), propname);
785}
786
Simon Glass2f9a6122020-01-27 08:49:40 -0700787static inline fdt_addr_t dev_read_addr_index(const struct udevice *dev,
788 int index)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600789{
790 return devfdt_get_addr_index(dev, index);
791}
792
Simon Glass2f9a6122020-01-27 08:49:40 -0700793static inline fdt_addr_t dev_read_addr_size_index(const struct udevice *dev,
Sekhar Norif677c6f2019-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 Glass2f9a6122020-01-27 08:49:40 -0700800static inline fdt_addr_t dev_read_addr_name(const struct udevice *dev,
Álvaro Fernández Rojasa3181152018-12-03 19:37:09 +0100801 const char *name)
802{
803 return devfdt_get_addr_name(dev, name);
804}
805
Simon Glass2f9a6122020-01-27 08:49:40 -0700806static inline fdt_addr_t dev_read_addr_size_name(const struct udevice *dev,
Sekhar Norif677c6f2019-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 Glass2f9a6122020-01-27 08:49:40 -0700813static inline fdt_addr_t dev_read_addr(const struct udevice *dev)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600814{
815 return devfdt_get_addr(dev);
816}
817
Simon Glass2f9a6122020-01-27 08:49:40 -0700818static inline void *dev_read_addr_ptr(const struct udevice *dev)
Philipp Tomsich7719b392017-09-11 22:04:12 +0200819{
Ovidiu Panaita633f002020-08-03 22:17:35 +0300820 return devfdt_get_addr_ptr(dev);
Philipp Tomsich7719b392017-09-11 22:04:12 +0200821}
822
Simon Glass2f9a6122020-01-27 08:49:40 -0700823static inline fdt_addr_t dev_read_addr_pci(const struct udevice *dev)
Simon Glass23b27592019-09-15 12:08:58 -0600824{
825 return devfdt_get_addr_pci(dev);
826}
827
Simon Glass2f9a6122020-01-27 08:49:40 -0700828static inline void *dev_remap_addr(const struct udevice *dev)
Álvaro Fernández Rojas670361292018-04-29 21:56:54 +0200829{
830 return devfdt_remap_addr(dev);
831}
832
Simon Glass2f9a6122020-01-27 08:49:40 -0700833static inline void *dev_remap_addr_index(const struct udevice *dev, int index)
Álvaro Fernández Rojas670361292018-04-29 21:56:54 +0200834{
835 return devfdt_remap_addr_index(dev, index);
836}
837
Simon Glass2f9a6122020-01-27 08:49:40 -0700838static inline void *dev_remap_addr_name(const struct udevice *dev,
839 const char *name)
Álvaro Fernández Rojasa3181152018-12-03 19:37:09 +0100840{
841 return devfdt_remap_addr_name(dev, name);
842}
843
Simon Glass2f9a6122020-01-27 08:49:40 -0700844static inline fdt_addr_t dev_read_addr_size(const struct udevice *dev,
Simon Glasscfdae5c2017-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 Glass2f9a6122020-01-27 08:49:40 -0700851static inline const char *dev_read_name(const struct udevice *dev)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600852{
853 return ofnode_get_name(dev_ofnode(dev));
854}
855
Simon Glass2f9a6122020-01-27 08:49:40 -0700856static inline int dev_read_stringlist_search(const struct udevice *dev,
Simon Glasscfdae5c2017-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 Glass2f9a6122020-01-27 08:49:40 -0700863static inline int dev_read_string_index(const struct udevice *dev,
Jean-Jacques Hiblot8365ebd2017-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 Glass2f9a6122020-01-27 08:49:40 -0700870static inline int dev_read_string_count(const struct udevice *dev,
Jean-Jacques Hiblot8365ebd2017-09-21 17:03:09 +0200871 const char *propname)
872{
873 return ofnode_read_string_count(dev_ofnode(dev), propname);
874}
875
Simon Glass2f9a6122020-01-27 08:49:40 -0700876static inline int dev_read_phandle_with_args(const struct udevice *dev,
Simon Glasscfdae5c2017-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 Glass2f9a6122020-01-27 08:49:40 -0700885static inline int dev_count_phandle_with_args(const struct udevice *dev,
Patrick Delaunayd776a842020-09-25 09:41:14 +0200886 const char *list_name, const char *cells_name, int cell_count)
Patrice Chotardbe7dd602017-07-18 11:57:08 +0200887{
888 return ofnode_count_phandle_with_args(dev_ofnode(dev), list_name,
Patrick Delaunayd776a842020-09-25 09:41:14 +0200889 cells_name, cell_count);
Patrice Chotardbe7dd602017-07-18 11:57:08 +0200890}
891
Simon Glass2f9a6122020-01-27 08:49:40 -0700892static inline int dev_read_addr_cells(const struct udevice *dev)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600893{
Heinrich Schuchardt60a84af2020-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 Glasscfdae5c2017-05-18 20:09:04 -0600897}
898
Simon Glass2f9a6122020-01-27 08:49:40 -0700899static inline int dev_read_size_cells(const struct udevice *dev)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600900{
Heinrich Schuchardt60a84af2020-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 Glass4191dc12017-06-12 06:21:31 -0600904}
905
Simon Glass2f9a6122020-01-27 08:49:40 -0700906static inline int dev_read_simple_addr_cells(const struct udevice *dev)
Simon Glass4191dc12017-06-12 06:21:31 -0600907{
908 return fdt_address_cells(gd->fdt_blob, dev_of_offset(dev));
909}
910
Simon Glass2f9a6122020-01-27 08:49:40 -0700911static inline int dev_read_simple_size_cells(const struct udevice *dev)
Simon Glass4191dc12017-06-12 06:21:31 -0600912{
Simon Glasscfdae5c2017-05-18 20:09:04 -0600913 return fdt_size_cells(gd->fdt_blob, dev_of_offset(dev));
914}
915
Simon Glass2f9a6122020-01-27 08:49:40 -0700916static inline int dev_read_phandle(const struct udevice *dev)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600917{
918 return fdt_get_phandle(gd->fdt_blob, dev_of_offset(dev));
919}
920
Simon Glass2f9a6122020-01-27 08:49:40 -0700921static inline const void *dev_read_prop(const struct udevice *dev,
Masahiro Yamadabaebec12017-07-17 12:18:39 +0900922 const char *propname, int *lenp)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600923{
Masahiro Yamada9cf85cb2017-06-22 16:54:05 +0900924 return ofnode_get_property(dev_ofnode(dev), propname, lenp);
Simon Glasscfdae5c2017-05-18 20:09:04 -0600925}
926
Patrick Delaunaycaee1552020-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 Glass2f9a6122020-01-27 08:49:40 -0700944static inline int dev_read_alias_seq(const struct udevice *dev, int *devnump)
Simon Glasscfdae5c2017-05-18 20:09:04 -0600945{
Marcel Ziswiler65c2bf62019-05-20 02:44:57 +0200946#if CONFIG_IS_ENABLED(OF_CONTROL)
Simon Glasscfdae5c2017-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 Ziswiler65c2bf62019-05-20 02:44:57 +0200949#else
950 return -ENOTSUPP;
951#endif
Simon Glasscfdae5c2017-05-18 20:09:04 -0600952}
953
Simon Glass2f9a6122020-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 Glasscfdae5c2017-05-18 20:09:04 -0600957{
958 return ofnode_read_u32_array(dev_ofnode(dev), propname, out_values, sz);
959}
960
Simon Glass2f9a6122020-01-27 08:49:40 -0700961static inline ofnode dev_read_first_subnode(const struct udevice *dev)
Simon Glasscfdae5c2017-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 Glass2f9a6122020-01-27 08:49:40 -0700971static inline const uint8_t *dev_read_u8_array_ptr(const struct udevice *dev,
Simon Glass000676b2020-01-27 08:49:47 -0700972 const char *propname,
973 size_t sz)
Simon Glass34ef0c22017-05-18 20:09:03 -0600974{
975 return ofnode_read_u8_array_ptr(dev_ofnode(dev), propname, sz);
976}
977
Simon Glass2f9a6122020-01-27 08:49:40 -0700978static inline int dev_read_enabled(const struct udevice *dev)
Simon Glassfa031f82017-06-12 06:21:30 -0600979{
980 return fdtdec_get_is_enabled(gd->fdt_blob, dev_of_offset(dev));
981}
982
Simon Glass2f9a6122020-01-27 08:49:40 -0700983static inline int dev_read_resource(const struct udevice *dev, uint index,
Simon Glassf7bfcc42017-07-25 08:29:55 -0600984 struct resource *res)
985{
986 return ofnode_read_resource(dev_ofnode(dev), index, res);
987}
988
Simon Glass2f9a6122020-01-27 08:49:40 -0700989static inline int dev_read_resource_byname(const struct udevice *dev,
Masahiro Yamada4dada2c2017-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 Glass2f9a6122020-01-27 08:49:40 -0700996static inline u64 dev_translate_address(const struct udevice *dev,
997 const fdt32_t *in_addr)
Mario Sixaefac062018-01-15 11:07:19 +0100998{
999 return ofnode_translate_address(dev_ofnode(dev), in_addr);
1000}
1001
Simon Glass2f9a6122020-01-27 08:49:40 -07001002static inline u64 dev_translate_dma_address(const struct udevice *dev,
1003 const fdt32_t *in_addr)
Fabien Dessenne22236e02019-05-31 15:11:30 +02001004{
1005 return ofnode_translate_dma_address(dev_ofnode(dev), in_addr);
1006}
1007
Michal Simekd0e30a02019-01-31 16:30:59 +01001008static inline int dev_read_alias_highest_id(const char *stem)
1009{
Stanislav Pinchuke8649402021-01-20 21:52:23 +03001010 if (!CONFIG_IS_ENABLED(OF_LIBFDT) || !gd->fdt_blob)
Michael Walleeccf2d02020-06-02 01:47:08 +02001011 return -1;
Michal Simekd0e30a02019-01-31 16:30:59 +01001012 return fdtdec_get_alias_highest_id(gd->fdt_blob, stem);
1013}
1014
developerd93c8b42020-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 Binacchi836cc9d2020-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 Glass34ef0c22017-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 Delaunaycaee1552020-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 Glass34ef0c22017-05-18 20:09:03 -06001057#endif