2018-05-06 21:58:06 +00:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0+ */
|
2017-05-17 23:18:10 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Google, Inc
|
|
|
|
* Written by Simon Glass <sjg@chromium.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _DM_OFNODE_H
|
|
|
|
#define _DM_OFNODE_H
|
|
|
|
|
2017-05-19 02:08:58 +00:00
|
|
|
/* TODO(sjg@chromium.org): Drop fdtdec.h include */
|
|
|
|
#include <fdtdec.h>
|
|
|
|
#include <dm/of.h>
|
2020-12-17 00:25:06 +00:00
|
|
|
#include <dm/of_access.h>
|
2020-09-23 06:23:27 +00:00
|
|
|
#include <log.h>
|
2022-04-06 22:33:01 +00:00
|
|
|
#include <phy_interface.h>
|
2017-05-19 02:08:58 +00:00
|
|
|
|
|
|
|
/* Enable checks to protect against invalid calls */
|
|
|
|
#undef OF_CHECKS
|
|
|
|
|
2017-07-25 14:29:55 +00:00
|
|
|
struct resource;
|
|
|
|
|
2022-07-30 21:52:06 +00:00
|
|
|
#include <dm/ofnode_decl.h>
|
2017-05-17 23:18:10 +00:00
|
|
|
|
2017-05-19 02:08:58 +00:00
|
|
|
struct ofnode_phandle_args {
|
|
|
|
ofnode node;
|
|
|
|
int args_count;
|
|
|
|
uint32_t args[OF_MAX_PHANDLE_ARGS];
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2020-09-23 06:23:27 +00:00
|
|
|
* ofnode_to_np() - convert an ofnode to a live DT node pointer
|
2017-05-19 02:08:58 +00:00
|
|
|
*
|
|
|
|
* This cannot be called if the reference contains an offset.
|
|
|
|
*
|
|
|
|
* @node: Reference containing struct device_node * (possibly invalid)
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: pointer to device node (can be NULL)
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
|
|
|
static inline const struct device_node *ofnode_to_np(ofnode node)
|
|
|
|
{
|
|
|
|
#ifdef OF_CHECKS
|
|
|
|
if (!of_live_active())
|
|
|
|
return NULL;
|
|
|
|
#endif
|
|
|
|
return node.np;
|
|
|
|
}
|
|
|
|
|
2017-05-17 23:18:10 +00:00
|
|
|
/**
|
|
|
|
* ofnode_to_offset() - convert an ofnode to a flat DT offset
|
|
|
|
*
|
|
|
|
* This cannot be called if the reference contains a node pointer.
|
|
|
|
*
|
|
|
|
* @node: Reference containing offset (possibly invalid)
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: DT offset (can be -1)
|
2017-05-17 23:18:10 +00:00
|
|
|
*/
|
|
|
|
static inline int ofnode_to_offset(ofnode node)
|
|
|
|
{
|
2017-05-19 02:08:58 +00:00
|
|
|
#ifdef OF_CHECKS
|
|
|
|
if (of_live_active())
|
|
|
|
return -1;
|
|
|
|
#endif
|
2017-05-17 23:18:10 +00:00
|
|
|
return node.of_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_valid() - check if an ofnode is valid
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @node: Reference containing offset (possibly invalid)
|
|
|
|
* Return: true if the reference contains a valid ofnode, false if it is NULL
|
2017-05-17 23:18:10 +00:00
|
|
|
*/
|
|
|
|
static inline bool ofnode_valid(ofnode node)
|
|
|
|
{
|
2017-05-19 02:08:58 +00:00
|
|
|
if (of_live_active())
|
|
|
|
return node.np != NULL;
|
|
|
|
else
|
2020-09-24 15:26:20 +00:00
|
|
|
return node.of_offset >= 0;
|
2017-05-17 23:18:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* offset_to_ofnode() - convert a DT offset to an ofnode
|
|
|
|
*
|
|
|
|
* @of_offset: DT offset (either valid, or -1)
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: reference to the associated DT offset
|
2017-05-17 23:18:10 +00:00
|
|
|
*/
|
|
|
|
static inline ofnode offset_to_ofnode(int of_offset)
|
|
|
|
{
|
|
|
|
ofnode node;
|
|
|
|
|
2017-05-19 02:08:58 +00:00
|
|
|
if (of_live_active())
|
|
|
|
node.np = NULL;
|
|
|
|
else
|
2019-12-07 04:41:36 +00:00
|
|
|
node.of_offset = of_offset >= 0 ? of_offset : -1;
|
2017-05-19 02:08:58 +00:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* np_to_ofnode() - convert a node pointer to an ofnode
|
|
|
|
*
|
|
|
|
* @np: Live node pointer (can be NULL)
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: reference to the associated node pointer
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
|
|
|
static inline ofnode np_to_ofnode(const struct device_node *np)
|
|
|
|
{
|
|
|
|
ofnode node;
|
|
|
|
|
|
|
|
node.np = np;
|
2017-05-17 23:18:10 +00:00
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2017-05-19 02:08:58 +00:00
|
|
|
/**
|
|
|
|
* ofnode_is_np() - check if a reference is a node pointer
|
|
|
|
*
|
|
|
|
* This function associated that if there is a valid live tree then all
|
|
|
|
* references will use it. This is because using the flat DT when the live tree
|
|
|
|
* is valid is not permitted.
|
|
|
|
*
|
|
|
|
* @node: reference to check (possibly invalid)
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: true if the reference is a live node pointer, false if it is a DT
|
2017-05-19 02:08:58 +00:00
|
|
|
* offset
|
|
|
|
*/
|
|
|
|
static inline bool ofnode_is_np(ofnode node)
|
|
|
|
{
|
|
|
|
#ifdef OF_CHECKS
|
|
|
|
/*
|
|
|
|
* Check our assumption that flat tree offsets are not used when a
|
|
|
|
* live tree is in use.
|
|
|
|
*/
|
|
|
|
assert(!ofnode_valid(node) ||
|
2020-09-23 06:23:27 +00:00
|
|
|
(of_live_active() ? ofnode_to_np(node)
|
|
|
|
: ofnode_to_np(node)));
|
2017-05-19 02:08:58 +00:00
|
|
|
#endif
|
|
|
|
return of_live_active() && ofnode_valid(node);
|
|
|
|
}
|
|
|
|
|
2017-05-17 23:18:10 +00:00
|
|
|
/**
|
|
|
|
* ofnode_equal() - check if two references are equal
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @ref1: first reference to check (possibly invalid)
|
|
|
|
* @ref2: second reference to check (possibly invalid)
|
|
|
|
* Return: true if equal, else false
|
2017-05-17 23:18:10 +00:00
|
|
|
*/
|
|
|
|
static inline bool ofnode_equal(ofnode ref1, ofnode ref2)
|
|
|
|
{
|
|
|
|
/* We only need to compare the contents */
|
|
|
|
return ref1.of_offset == ref2.of_offset;
|
|
|
|
}
|
|
|
|
|
2017-05-19 02:08:58 +00:00
|
|
|
/**
|
|
|
|
* ofnode_null() - Obtain a null ofnode
|
|
|
|
*
|
|
|
|
* This returns an ofnode which points to no node. It works both with the flat
|
|
|
|
* tree and livetree.
|
|
|
|
*/
|
|
|
|
static inline ofnode ofnode_null(void)
|
|
|
|
{
|
|
|
|
ofnode node;
|
|
|
|
|
|
|
|
if (of_live_active())
|
|
|
|
node.np = NULL;
|
|
|
|
else
|
|
|
|
node.of_offset = -1;
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2020-11-29 00:50:07 +00:00
|
|
|
static inline ofnode ofnode_root(void)
|
|
|
|
{
|
|
|
|
ofnode node;
|
|
|
|
|
|
|
|
if (of_live_active())
|
|
|
|
node.np = gd_of_root();
|
|
|
|
else
|
|
|
|
node.of_offset = 0;
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2022-07-30 21:52:08 +00:00
|
|
|
/**
|
|
|
|
* oftree_default() - Returns the default device tree (U-Boot's control FDT)
|
|
|
|
*
|
|
|
|
* Returns: reference to the control FDT
|
|
|
|
*/
|
|
|
|
static inline oftree oftree_default(void)
|
|
|
|
{
|
|
|
|
oftree tree;
|
|
|
|
|
|
|
|
if (of_live_active())
|
|
|
|
tree.np = gd_of_root();
|
|
|
|
else
|
|
|
|
tree.fdt = (void *)gd->fdt_blob;
|
|
|
|
|
|
|
|
return tree;
|
|
|
|
}
|
|
|
|
|
2021-07-21 15:58:30 +00:00
|
|
|
/**
|
|
|
|
* ofnode_name_eq() - Check if the node name is equivalent to a given name
|
|
|
|
* ignoring the unit address
|
|
|
|
*
|
|
|
|
* @node: valid node reference that has to be compared
|
|
|
|
* @name: name that has to be compared with the node name
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: true if matches, false if it doesn't match
|
2021-07-21 15:58:30 +00:00
|
|
|
*/
|
|
|
|
bool ofnode_name_eq(ofnode node, const char *name);
|
|
|
|
|
2017-05-19 02:08:58 +00:00
|
|
|
/**
|
|
|
|
* ofnode_read_u32() - Read a 32-bit integer from a property
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @node: valid node reference to read property from
|
2017-05-19 02:08:58 +00:00
|
|
|
* @propname: name of the property to read from
|
|
|
|
* @outp: place to put value (if found)
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: 0 if OK, -ve on error
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
|
|
|
int ofnode_read_u32(ofnode node, const char *propname, u32 *outp);
|
|
|
|
|
2020-03-29 16:04:41 +00:00
|
|
|
/**
|
|
|
|
* ofnode_read_u32_index() - Read a 32-bit integer from a multi-value property
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @node: valid node reference to read property from
|
2020-03-29 16:04:41 +00:00
|
|
|
* @propname: name of the property to read from
|
|
|
|
* @index: index of the integer to return
|
|
|
|
* @outp: place to put value (if found)
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: 0 if OK, -ve on error
|
2020-03-29 16:04:41 +00:00
|
|
|
*/
|
|
|
|
int ofnode_read_u32_index(ofnode node, const char *propname, int index,
|
|
|
|
u32 *outp);
|
|
|
|
|
2017-05-19 02:08:58 +00:00
|
|
|
/**
|
|
|
|
* ofnode_read_s32() - Read a 32-bit integer from a property
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @node: valid node reference to read property from
|
2017-05-19 02:08:58 +00:00
|
|
|
* @propname: name of the property to read from
|
|
|
|
* @outp: place to put value (if found)
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: 0 if OK, -ve on error
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
|
|
|
static inline int ofnode_read_s32(ofnode node, const char *propname,
|
2022-01-12 09:53:49 +00:00
|
|
|
s32 *outp)
|
2017-05-19 02:08:58 +00:00
|
|
|
{
|
2022-01-12 09:53:49 +00:00
|
|
|
return ofnode_read_u32(node, propname, (u32 *)outp);
|
2017-05-19 02:08:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_read_u32_default() - Read a 32-bit integer from a property
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @node: valid node reference to read property from
|
2017-05-19 02:08:58 +00:00
|
|
|
* @propname: name of the property to read from
|
|
|
|
* @def: default value to return if the property has no value
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: property value, or @def if not found
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
2022-01-12 09:53:49 +00:00
|
|
|
u32 ofnode_read_u32_default(ofnode node, const char *propname, u32 def);
|
2017-05-19 02:08:58 +00:00
|
|
|
|
2020-03-29 16:04:41 +00:00
|
|
|
/**
|
|
|
|
* ofnode_read_u32_index_default() - Read a 32-bit integer from a multi-value
|
|
|
|
* property
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @node: valid node reference to read property from
|
2020-03-29 16:04:41 +00:00
|
|
|
* @propname: name of the property to read from
|
|
|
|
* @index: index of the integer to return
|
|
|
|
* @def: default value to return if the property has no value
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: property value, or @def if not found
|
2020-03-29 16:04:41 +00:00
|
|
|
*/
|
2022-01-12 09:53:49 +00:00
|
|
|
u32 ofnode_read_u32_index_default(ofnode node, const char *propname, int index,
|
2020-03-29 16:04:41 +00:00
|
|
|
u32 def);
|
|
|
|
|
2017-05-19 02:08:58 +00:00
|
|
|
/**
|
|
|
|
* ofnode_read_s32_default() - Read a 32-bit integer from a property
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @node: valid node reference to read property from
|
2017-05-19 02:08:58 +00:00
|
|
|
* @propname: name of the property to read from
|
|
|
|
* @def: default value to return if the property has no value
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: property value, or @def if not found
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
|
|
|
int ofnode_read_s32_default(ofnode node, const char *propname, s32 def);
|
|
|
|
|
2018-11-22 10:26:35 +00:00
|
|
|
/**
|
|
|
|
* ofnode_read_u64() - Read a 64-bit integer from a property
|
|
|
|
*
|
|
|
|
* @node: valid node reference to read property from
|
|
|
|
* @propname: name of the property to read from
|
|
|
|
* @outp: place to put value (if found)
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: 0 if OK, -ve on error
|
2018-11-22 10:26:35 +00:00
|
|
|
*/
|
|
|
|
int ofnode_read_u64(ofnode node, const char *propname, u64 *outp);
|
|
|
|
|
2018-06-11 19:07:10 +00:00
|
|
|
/**
|
|
|
|
* ofnode_read_u64_default() - Read a 64-bit integer from a property
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @node: valid node reference to read property from
|
2018-06-11 19:07:10 +00:00
|
|
|
* @propname: name of the property to read from
|
|
|
|
* @def: default value to return if the property has no value
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: property value, or @def if not found
|
2018-06-11 19:07:10 +00:00
|
|
|
*/
|
2019-09-02 14:34:30 +00:00
|
|
|
u64 ofnode_read_u64_default(ofnode node, const char *propname, u64 def);
|
2018-06-11 19:07:10 +00:00
|
|
|
|
2020-01-27 15:49:44 +00:00
|
|
|
/**
|
|
|
|
* ofnode_read_prop() - Read a property from a node
|
|
|
|
*
|
|
|
|
* @node: valid node reference to read property from
|
|
|
|
* @propname: name of the property to read
|
|
|
|
* @sizep: if non-NULL, returns the size of the property, or an error code
|
2022-01-12 09:53:49 +00:00
|
|
|
* if not found
|
|
|
|
* Return: property value, or NULL if there is no such property
|
2020-01-27 15:49:44 +00:00
|
|
|
*/
|
|
|
|
const void *ofnode_read_prop(ofnode node, const char *propname, int *sizep);
|
|
|
|
|
2017-05-19 02:08:58 +00:00
|
|
|
/**
|
|
|
|
* ofnode_read_string() - Read a string from a property
|
|
|
|
*
|
2020-01-27 15:49:44 +00:00
|
|
|
* @node: valid node reference to read property from
|
2017-05-19 02:08:58 +00:00
|
|
|
* @propname: name of the property to read
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: string from property value, or NULL if there is no such property
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
|
|
|
const char *ofnode_read_string(ofnode node, const char *propname);
|
|
|
|
|
|
|
|
/**
|
2017-05-19 02:09:01 +00:00
|
|
|
* ofnode_read_u32_array() - Find and read an array of 32 bit integers
|
2017-05-19 02:08:58 +00:00
|
|
|
*
|
|
|
|
* @node: valid node reference to read property from
|
|
|
|
* @propname: name of the property to read
|
|
|
|
* @out_values: pointer to return value, modified only if return value is 0
|
|
|
|
* @sz: number of array elements to read
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: 0 if OK, -ve on error
|
2017-05-19 02:08:58 +00:00
|
|
|
*
|
|
|
|
* Search for a property in a device node and read 32-bit value(s) from
|
|
|
|
* it. Returns 0 on success, -EINVAL if the property does not exist,
|
|
|
|
* -ENODATA if property does not have a value, and -EOVERFLOW if the
|
|
|
|
* property data isn't large enough.
|
|
|
|
*
|
|
|
|
* The out_values is modified only if a valid u32 value can be decoded.
|
|
|
|
*/
|
|
|
|
int ofnode_read_u32_array(ofnode node, const char *propname,
|
|
|
|
u32 *out_values, size_t sz);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_read_bool() - read a boolean value from a property
|
|
|
|
*
|
|
|
|
* @node: valid node reference to read property from
|
|
|
|
* @propname: name of property to read
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: true if property is present (meaning true), false if not present
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
|
|
|
bool ofnode_read_bool(ofnode node, const char *propname);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_find_subnode() - find a named subnode of a parent node
|
|
|
|
*
|
|
|
|
* @node: valid reference to parent node
|
|
|
|
* @subnode_name: name of subnode to find
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: reference to subnode (which can be invalid if there is no such
|
2017-05-19 02:08:58 +00:00
|
|
|
* subnode)
|
|
|
|
*/
|
|
|
|
ofnode ofnode_find_subnode(ofnode node, const char *subnode_name);
|
|
|
|
|
2020-12-17 00:25:06 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_INLINE_OFNODE)
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
|
|
|
|
2020-12-17 00:25:06 +00:00
|
|
|
static inline bool ofnode_is_enabled(ofnode node)
|
|
|
|
{
|
|
|
|
if (ofnode_is_np(node)) {
|
|
|
|
return of_device_is_available(ofnode_to_np(node));
|
|
|
|
} else {
|
|
|
|
return fdtdec_get_is_enabled(gd->fdt_blob,
|
|
|
|
ofnode_to_offset(node));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline ofnode ofnode_first_subnode(ofnode node)
|
|
|
|
{
|
|
|
|
assert(ofnode_valid(node));
|
|
|
|
if (ofnode_is_np(node))
|
|
|
|
return np_to_ofnode(node.np->child);
|
|
|
|
|
|
|
|
return offset_to_ofnode(
|
|
|
|
fdt_first_subnode(gd->fdt_blob, ofnode_to_offset(node)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline ofnode ofnode_next_subnode(ofnode node)
|
|
|
|
{
|
|
|
|
assert(ofnode_valid(node));
|
|
|
|
if (ofnode_is_np(node))
|
|
|
|
return np_to_ofnode(node.np->sibling);
|
|
|
|
|
|
|
|
return offset_to_ofnode(
|
|
|
|
fdt_next_subnode(gd->fdt_blob, ofnode_to_offset(node)));
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/**
|
|
|
|
* ofnode_is_enabled() - Checks whether a node is enabled.
|
|
|
|
* This looks for a 'status' property. If this exists, then returns true if
|
|
|
|
* the status is 'okay' and false otherwise. If there is no status property,
|
|
|
|
* it returns true on the assumption that anything mentioned should be enabled
|
|
|
|
* by default.
|
|
|
|
*
|
|
|
|
* @node: node to examine
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: false (not enabled) or true (enabled)
|
2020-12-17 00:25:06 +00:00
|
|
|
*/
|
|
|
|
bool ofnode_is_enabled(ofnode node);
|
|
|
|
|
2017-05-19 02:08:58 +00:00
|
|
|
/**
|
|
|
|
* ofnode_first_subnode() - find the first subnode of a parent node
|
|
|
|
*
|
|
|
|
* @node: valid reference to a valid parent node
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: reference to the first subnode (which can be invalid if the parent
|
2017-05-19 02:08:58 +00:00
|
|
|
* node has no subnodes)
|
|
|
|
*/
|
|
|
|
ofnode ofnode_first_subnode(ofnode node);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_next_subnode() - find the next sibling of a subnode
|
|
|
|
*
|
|
|
|
* @node: valid reference to previous node (sibling)
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: reference to the next subnode (which can be invalid if the node
|
2017-05-19 02:08:58 +00:00
|
|
|
* has no more siblings)
|
|
|
|
*/
|
|
|
|
ofnode ofnode_next_subnode(ofnode node);
|
2020-12-17 00:25:06 +00:00
|
|
|
#endif /* DM_INLINE_OFNODE */
|
2017-05-19 02:08:58 +00:00
|
|
|
|
2018-02-23 16:38:49 +00:00
|
|
|
/**
|
|
|
|
* ofnode_get_parent() - get the ofnode's parent (enclosing ofnode)
|
|
|
|
*
|
|
|
|
* @node: valid node to look up
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: ofnode reference of the parent node
|
2018-02-23 16:38:49 +00:00
|
|
|
*/
|
|
|
|
ofnode ofnode_get_parent(ofnode node);
|
|
|
|
|
2017-05-19 02:08:58 +00:00
|
|
|
/**
|
|
|
|
* ofnode_get_name() - get the name of a node
|
|
|
|
*
|
|
|
|
* @node: valid node to look up
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: name of node
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
|
|
|
const char *ofnode_get_name(ofnode node);
|
|
|
|
|
2021-05-26 12:08:18 +00:00
|
|
|
/**
|
|
|
|
* ofnode_get_path() - get the full path of a node
|
|
|
|
*
|
|
|
|
* @node: valid node to look up
|
|
|
|
* @buf: buffer to write the node path into
|
|
|
|
* @buflen: buffer size
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: 0 if OK, -ve on error
|
2021-05-26 12:08:18 +00:00
|
|
|
*/
|
|
|
|
int ofnode_get_path(ofnode node, char *buf, int buflen);
|
|
|
|
|
2018-02-23 16:38:50 +00:00
|
|
|
/**
|
|
|
|
* ofnode_get_by_phandle() - get ofnode from phandle
|
|
|
|
*
|
|
|
|
* @phandle: phandle to look up
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: ofnode reference to the phandle
|
2018-02-23 16:38:50 +00:00
|
|
|
*/
|
|
|
|
ofnode ofnode_get_by_phandle(uint phandle);
|
|
|
|
|
2017-05-19 02:08:58 +00:00
|
|
|
/**
|
|
|
|
* ofnode_read_size() - read the size of a property
|
|
|
|
*
|
|
|
|
* @node: node to check
|
|
|
|
* @propname: property to check
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: size of property if present, or -EINVAL if not
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
|
|
|
int ofnode_read_size(ofnode node, const char *propname);
|
|
|
|
|
2019-04-24 11:49:53 +00:00
|
|
|
/**
|
|
|
|
* ofnode_get_addr_size_index() - get an address/size from a node
|
|
|
|
* based on index
|
|
|
|
*
|
|
|
|
* This reads the register address/size from a node based on index
|
|
|
|
*
|
|
|
|
* @node: node to read from
|
|
|
|
* @index: Index of address to read (0 for first)
|
|
|
|
* @size: Pointer to size of the address
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: address, or FDT_ADDR_T_NONE if not present or invalid
|
2019-04-24 11:49:53 +00:00
|
|
|
*/
|
|
|
|
phys_addr_t ofnode_get_addr_size_index(ofnode node, int index,
|
|
|
|
fdt_size_t *size);
|
|
|
|
|
2021-05-26 12:08:17 +00:00
|
|
|
/**
|
|
|
|
* ofnode_get_addr_size_index_notrans() - get an address/size from a node
|
|
|
|
* based on index, without address
|
|
|
|
* translation
|
|
|
|
*
|
|
|
|
* This reads the register address/size from a node based on index.
|
|
|
|
* The resulting address is not translated. Useful for example for on-disk
|
|
|
|
* addresses.
|
|
|
|
*
|
|
|
|
* @node: node to read from
|
|
|
|
* @index: Index of address to read (0 for first)
|
|
|
|
* @size: Pointer to size of the address
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: address, or FDT_ADDR_T_NONE if not present or invalid
|
2021-05-26 12:08:17 +00:00
|
|
|
*/
|
|
|
|
phys_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index,
|
|
|
|
fdt_size_t *size);
|
|
|
|
|
2017-05-19 02:09:01 +00:00
|
|
|
/**
|
|
|
|
* ofnode_get_addr_index() - get an address from a node
|
|
|
|
*
|
|
|
|
* This reads the register address from a node
|
|
|
|
*
|
|
|
|
* @node: node to read from
|
|
|
|
* @index: Index of address to read (0 for first)
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: address, or FDT_ADDR_T_NONE if not present or invalid
|
2017-05-19 02:09:01 +00:00
|
|
|
*/
|
|
|
|
phys_addr_t ofnode_get_addr_index(ofnode node, int index);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_get_addr() - get an address from a node
|
|
|
|
*
|
|
|
|
* This reads the register address from a node
|
|
|
|
*
|
|
|
|
* @node: node to read from
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: address, or FDT_ADDR_T_NONE if not present or invalid
|
2017-05-19 02:09:01 +00:00
|
|
|
*/
|
|
|
|
phys_addr_t ofnode_get_addr(ofnode node);
|
|
|
|
|
2021-04-12 06:51:11 +00:00
|
|
|
/**
|
|
|
|
* ofnode_get_size() - get size from a node
|
|
|
|
*
|
|
|
|
* This reads the register size from a node
|
|
|
|
*
|
|
|
|
* @node: node to read from
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: size of the address, or FDT_SIZE_T_NONE if not present or invalid
|
2021-04-12 06:51:11 +00:00
|
|
|
*/
|
|
|
|
fdt_size_t ofnode_get_size(ofnode node);
|
|
|
|
|
2017-05-19 02:08:58 +00:00
|
|
|
/**
|
|
|
|
* ofnode_stringlist_search() - find a string in a string list and return index
|
|
|
|
*
|
|
|
|
* Note that it is possible for this function to succeed on property values
|
|
|
|
* that are not NUL-terminated. That's because the function will stop after
|
|
|
|
* finding the first occurrence of @string. This can for example happen with
|
|
|
|
* small-valued cell properties, such as #address-cells, when searching for
|
|
|
|
* the empty string.
|
|
|
|
*
|
|
|
|
* @node: node to check
|
|
|
|
* @propname: name of the property containing the string list
|
|
|
|
* @string: string to look up in the string list
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return:
|
2017-05-19 02:08:58 +00:00
|
|
|
* the index of the string in the list of strings
|
|
|
|
* -ENODATA if the property is not found
|
|
|
|
* -EINVAL on some other error
|
|
|
|
*/
|
|
|
|
int ofnode_stringlist_search(ofnode node, const char *propname,
|
|
|
|
const char *string);
|
|
|
|
|
|
|
|
/**
|
2017-06-12 12:21:28 +00:00
|
|
|
* ofnode_read_string_index() - obtain an indexed string from a string list
|
2017-05-19 02:08:58 +00:00
|
|
|
*
|
|
|
|
* Note that this will successfully extract strings from properties with
|
|
|
|
* non-NUL-terminated values. For example on small-valued cell properties
|
|
|
|
* this function will return the empty string.
|
|
|
|
*
|
|
|
|
* If non-NULL, the length of the string (on success) or a negative error-code
|
|
|
|
* (on failure) will be stored in the integer pointer to by lenp.
|
|
|
|
*
|
|
|
|
* @node: node to check
|
|
|
|
* @propname: name of the property containing the string list
|
2021-10-23 23:26:06 +00:00
|
|
|
* @index: index of the string to return (cannot be negative)
|
2022-01-12 09:53:49 +00:00
|
|
|
* @outp: return location for the string
|
2017-05-19 02:08:58 +00:00
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return:
|
2021-10-23 23:26:06 +00:00
|
|
|
* 0 if found or -ve error value if not found
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
|
|
|
int ofnode_read_string_index(ofnode node, const char *propname, int index,
|
|
|
|
const char **outp);
|
|
|
|
|
2017-06-12 12:21:28 +00:00
|
|
|
/**
|
|
|
|
* ofnode_read_string_count() - find the number of strings in a string list
|
|
|
|
*
|
|
|
|
* @node: node to check
|
2022-01-12 09:53:49 +00:00
|
|
|
* @property: name of the property containing the string list
|
|
|
|
* Return:
|
2017-06-12 12:21:28 +00:00
|
|
|
* number of strings in the list, or -ve error value if not found
|
|
|
|
*/
|
|
|
|
int ofnode_read_string_count(ofnode node, const char *property);
|
|
|
|
|
2021-10-23 23:26:07 +00:00
|
|
|
/**
|
|
|
|
* ofnode_read_string_list() - read a list of strings
|
|
|
|
*
|
|
|
|
* This produces a list of string pointers with each one pointing to a string
|
|
|
|
* in the string list. If the property does not exist, it returns {NULL}.
|
|
|
|
*
|
|
|
|
* The data is allocated and the caller is reponsible for freeing the return
|
|
|
|
* value (the list of string pointers). The strings themselves may not be
|
|
|
|
* changed as they point directly into the devicetree property.
|
|
|
|
*
|
|
|
|
* @node: node to check
|
2022-01-12 09:53:49 +00:00
|
|
|
* @property: name of the property containing the string list
|
2021-10-23 23:26:07 +00:00
|
|
|
* @listp: returns an allocated, NULL-terminated list of strings if the return
|
|
|
|
* value is > 0, else is set to NULL
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return:
|
|
|
|
* number of strings in list, 0 if none, -ENOMEM if out of memory,
|
|
|
|
* -EINVAL if no such property, -EENODATA if property is empty
|
2021-10-23 23:26:07 +00:00
|
|
|
*/
|
|
|
|
int ofnode_read_string_list(ofnode node, const char *property,
|
|
|
|
const char ***listp);
|
|
|
|
|
2017-05-19 02:08:58 +00:00
|
|
|
/**
|
|
|
|
* ofnode_parse_phandle_with_args() - Find a node pointed by phandle in a list
|
|
|
|
*
|
|
|
|
* This function is useful to parse lists of phandles and their arguments.
|
|
|
|
* Returns 0 on success and fills out_args, on error returns appropriate
|
|
|
|
* errno value.
|
|
|
|
*
|
|
|
|
* Caller is responsible to call of_node_put() on the returned out_args->np
|
|
|
|
* pointer.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* .. code-block::
|
2017-05-19 02:08:58 +00:00
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* phandle1: node1 {
|
|
|
|
* #list-cells = <2>;
|
|
|
|
* };
|
|
|
|
* phandle2: node2 {
|
|
|
|
* #list-cells = <1>;
|
|
|
|
* };
|
|
|
|
* node3 {
|
|
|
|
* list = <&phandle1 1 2 &phandle2 3>;
|
|
|
|
* };
|
2017-05-19 02:08:58 +00:00
|
|
|
*
|
|
|
|
* To get a device_node of the `node2' node you may call this:
|
|
|
|
* ofnode_parse_phandle_with_args(node3, "list", "#list-cells", 0, 1, &args);
|
|
|
|
*
|
|
|
|
* @node: device tree node containing a list
|
|
|
|
* @list_name: property name that contains a list
|
|
|
|
* @cells_name: property name that specifies phandles' arguments count
|
2022-01-12 09:53:49 +00:00
|
|
|
* @cell_count: Cell count to use if @cells_name is NULL
|
2017-05-19 02:08:58 +00:00
|
|
|
* @index: index of a phandle to parse out
|
|
|
|
* @out_args: optional pointer to output arguments structure (will be filled)
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return:
|
|
|
|
* 0 on success (with @out_args filled out if not NULL), -ENOENT if
|
|
|
|
* @list_name does not exist, -EINVAL if a phandle was not found,
|
|
|
|
* @cells_name could not be found, the arguments were truncated or there
|
|
|
|
* were too many arguments.
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
|
|
|
int ofnode_parse_phandle_with_args(ofnode node, const char *list_name,
|
|
|
|
const char *cells_name, int cell_count,
|
|
|
|
int index,
|
|
|
|
struct ofnode_phandle_args *out_args);
|
|
|
|
|
2017-07-18 09:57:08 +00:00
|
|
|
/**
|
|
|
|
* ofnode_count_phandle_with_args() - Count number of phandle in a list
|
|
|
|
*
|
|
|
|
* This function is useful to count phandles into a list.
|
|
|
|
* Returns number of phandle on success, on error returns appropriate
|
|
|
|
* errno value.
|
|
|
|
*
|
|
|
|
* @node: device tree node containing a list
|
|
|
|
* @list_name: property name that contains a list
|
|
|
|
* @cells_name: property name that specifies phandles' arguments count
|
2022-01-12 09:53:49 +00:00
|
|
|
* @cell_count: Cell count to use if @cells_name is NULL
|
|
|
|
* Return:
|
|
|
|
* number of phandle on success, -ENOENT if @list_name does not exist,
|
|
|
|
* -EINVAL if a phandle was not found, @cells_name could not be found.
|
2017-07-18 09:57:08 +00:00
|
|
|
*/
|
|
|
|
int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
|
2020-09-25 07:41:14 +00:00
|
|
|
const char *cells_name, int cell_count);
|
2017-07-18 09:57:08 +00:00
|
|
|
|
2017-05-19 02:08:58 +00:00
|
|
|
/**
|
|
|
|
* ofnode_path() - find a node by full path
|
|
|
|
*
|
2022-07-30 21:52:08 +00:00
|
|
|
* This uses the control FDT.
|
|
|
|
*
|
2017-05-19 02:08:58 +00:00
|
|
|
* @path: Full path to node, e.g. "/bus/spi@1"
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: reference to the node found. Use ofnode_valid() to check if it exists
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
|
|
|
ofnode ofnode_path(const char *path);
|
|
|
|
|
2022-07-30 21:52:08 +00:00
|
|
|
/**
|
|
|
|
* ofnode_path_root() - find a node by full path from a root node
|
|
|
|
*
|
|
|
|
* @tree: Device tree to use
|
|
|
|
* @path: Full path to node, e.g. "/bus/spi@1"
|
|
|
|
* Return: reference to the node found. Use ofnode_valid() to check if it exists
|
|
|
|
*/
|
|
|
|
ofnode ofnode_path_root(oftree tree, const char *path);
|
|
|
|
|
2020-01-27 15:49:46 +00:00
|
|
|
/**
|
|
|
|
* ofnode_read_chosen_prop() - get the value of a chosen property
|
|
|
|
*
|
|
|
|
* This looks for a property within the /chosen node and returns its value
|
|
|
|
*
|
|
|
|
* @propname: Property name to look for
|
2022-01-12 09:53:49 +00:00
|
|
|
* @sizep: Returns size of property, or `FDT_ERR_...` error code if function
|
2020-01-27 15:49:46 +00:00
|
|
|
* returns NULL
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: property value if found, else NULL
|
2020-01-27 15:49:46 +00:00
|
|
|
*/
|
|
|
|
const void *ofnode_read_chosen_prop(const char *propname, int *sizep);
|
|
|
|
|
2017-05-19 02:08:58 +00:00
|
|
|
/**
|
2020-01-27 15:49:43 +00:00
|
|
|
* ofnode_read_chosen_string() - get the string value of a chosen property
|
2017-05-19 02:08:58 +00:00
|
|
|
*
|
2020-01-27 15:49:43 +00:00
|
|
|
* This looks for a property within the /chosen node and returns its value,
|
|
|
|
* checking that it is a valid nul-terminated string
|
2017-05-19 02:08:58 +00:00
|
|
|
*
|
|
|
|
* @propname: Property name to look for
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: string value if found, else NULL
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
2020-01-27 15:49:43 +00:00
|
|
|
const char *ofnode_read_chosen_string(const char *propname);
|
2017-05-19 02:08:58 +00:00
|
|
|
|
|
|
|
/**
|
2020-01-27 15:49:42 +00:00
|
|
|
* ofnode_get_chosen_node() - get a referenced node from the chosen node
|
2017-05-19 02:08:58 +00:00
|
|
|
*
|
2020-01-27 15:49:42 +00:00
|
|
|
* This looks up a named property in the chosen node and uses that as a path to
|
|
|
|
* look up a code.
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @propname: Property name to look for
|
|
|
|
* Return: the referenced node if present, else ofnode_null()
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
2020-01-27 15:49:42 +00:00
|
|
|
ofnode ofnode_get_chosen_node(const char *propname);
|
2017-05-19 02:08:58 +00:00
|
|
|
|
2020-07-28 10:51:08 +00:00
|
|
|
/**
|
|
|
|
* ofnode_read_aliases_prop() - get the value of a aliases property
|
|
|
|
*
|
|
|
|
* This looks for a property within the /aliases node and returns its value
|
|
|
|
*
|
|
|
|
* @propname: Property name to look for
|
2022-01-12 09:53:49 +00:00
|
|
|
* @sizep: Returns size of property, or `FDT_ERR_...` error code if function
|
2020-07-28 10:51:08 +00:00
|
|
|
* returns NULL
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: property value if found, else NULL
|
2020-07-28 10:51:08 +00:00
|
|
|
*/
|
|
|
|
const void *ofnode_read_aliases_prop(const char *propname, int *sizep);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_get_aliases_node() - get a referenced node from the aliases node
|
|
|
|
*
|
|
|
|
* This looks up a named property in the aliases node and uses that as a path to
|
|
|
|
* look up a code.
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @propname: Property name to look for
|
|
|
|
* Return: the referenced node if present, else ofnode_null()
|
2020-07-28 10:51:08 +00:00
|
|
|
*/
|
|
|
|
ofnode ofnode_get_aliases_node(const char *propname);
|
|
|
|
|
2017-05-19 02:08:58 +00:00
|
|
|
struct display_timing;
|
|
|
|
/**
|
|
|
|
* ofnode_decode_display_timing() - decode display timings
|
|
|
|
*
|
|
|
|
* Decode display timings from the supplied 'display-timings' node.
|
|
|
|
* See doc/device-tree-bindings/video/display-timing.txt for binding
|
|
|
|
* information.
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @node: 'display-timing' node containing the timing subnodes
|
|
|
|
* @index: Index number to read (0=first timing subnode)
|
|
|
|
* @config: Place to put timings
|
|
|
|
* Return: 0 if OK, -FDT_ERR_NOTFOUND if not found
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
|
|
|
int ofnode_decode_display_timing(ofnode node, int index,
|
|
|
|
struct display_timing *config);
|
|
|
|
|
|
|
|
/**
|
2020-01-13 10:34:56 +00:00
|
|
|
* ofnode_get_property() - get a pointer to the value of a node property
|
2017-05-19 02:08:58 +00:00
|
|
|
*
|
|
|
|
* @node: node to read
|
|
|
|
* @propname: property to read
|
|
|
|
* @lenp: place to put length on success
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: pointer to property, or NULL if not found
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
2017-06-22 07:54:05 +00:00
|
|
|
const void *ofnode_get_property(ofnode node, const char *propname, int *lenp);
|
2017-05-19 02:08:58 +00:00
|
|
|
|
2020-01-13 10:34:56 +00:00
|
|
|
/**
|
|
|
|
* ofnode_get_first_property()- get the reference of the first property
|
|
|
|
*
|
|
|
|
* Get reference to the first property of the node, it is used to iterate
|
|
|
|
* and read all the property with ofnode_get_property_by_prop().
|
|
|
|
*
|
|
|
|
* @node: node to read
|
|
|
|
* @prop: place to put argument reference
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
|
2020-01-13 10:34:56 +00:00
|
|
|
*/
|
|
|
|
int ofnode_get_first_property(ofnode node, struct ofprop *prop);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_get_next_property() - get the reference of the next property
|
|
|
|
*
|
|
|
|
* Get reference to the next property of the node, it is used to iterate
|
|
|
|
* and read all the property with ofnode_get_property_by_prop().
|
|
|
|
*
|
|
|
|
* @prop: reference of current argument and place to put reference of next one
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
|
2020-01-13 10:34:56 +00:00
|
|
|
*/
|
|
|
|
int ofnode_get_next_property(struct ofprop *prop);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_get_property_by_prop() - get a pointer to the value of a property
|
|
|
|
*
|
|
|
|
* Get value for the property identified by the provided reference.
|
|
|
|
*
|
|
|
|
* @prop: reference on property
|
|
|
|
* @propname: If non-NULL, place to property name on success,
|
|
|
|
* @lenp: If non-NULL, place to put length on success
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: 0 if OK, -ve on error. -FDT_ERR_NOTFOUND if not found
|
2020-01-13 10:34:56 +00:00
|
|
|
*/
|
|
|
|
const void *ofnode_get_property_by_prop(const struct ofprop *prop,
|
|
|
|
const char **propname, int *lenp);
|
|
|
|
|
2017-05-19 02:08:58 +00:00
|
|
|
/**
|
|
|
|
* ofnode_is_available() - check if a node is marked available
|
|
|
|
*
|
|
|
|
* @node: node to check
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: true if node's 'status' property is "okay" (or is missing)
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
|
|
|
bool ofnode_is_available(ofnode node);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_get_addr_size() - get address and size from a property
|
|
|
|
*
|
|
|
|
* This does no address translation. It simply reads an property that contains
|
|
|
|
* an address and a size value, one after the other.
|
|
|
|
*
|
|
|
|
* @node: node to read from
|
|
|
|
* @propname: property to read
|
|
|
|
* @sizep: place to put size value (on success)
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: address value, or FDT_ADDR_T_NONE on error
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
|
|
|
phys_addr_t ofnode_get_addr_size(ofnode node, const char *propname,
|
|
|
|
phys_size_t *sizep);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_read_u8_array_ptr() - find an 8-bit array
|
|
|
|
*
|
|
|
|
* Look up a property in a node and return a pointer to its contents as a
|
|
|
|
* byte array of given length. The property must have at least enough data
|
|
|
|
* for the array (count bytes). It may have more, but this will be ignored.
|
|
|
|
* The data is not copied.
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @node: node to examine
|
|
|
|
* @propname: name of property to find
|
|
|
|
* @sz: number of array elements
|
|
|
|
* Return:
|
|
|
|
* pointer to byte array if found, or NULL if the property is not found or
|
|
|
|
* there is not enough data
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
|
|
|
const uint8_t *ofnode_read_u8_array_ptr(ofnode node, const char *propname,
|
|
|
|
size_t sz);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_read_pci_addr() - look up a PCI address
|
|
|
|
*
|
|
|
|
* Look at an address property in a node and return the PCI address which
|
|
|
|
* corresponds to the given type in the form of fdt_pci_addr.
|
|
|
|
* The property must hold one fdt_pci_addr with a lengh.
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @node: node to examine
|
|
|
|
* @type: pci address type (FDT_PCI_SPACE_xxx)
|
|
|
|
* @propname: name of property to find
|
|
|
|
* @addr: returns pci address in the form of fdt_pci_addr
|
|
|
|
* Return:
|
|
|
|
* 0 if ok, -ENOENT if the property did not exist, -EINVAL if the
|
|
|
|
* format of the property was invalid, -ENXIO if the requested
|
|
|
|
* address type was not found
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
|
|
|
int ofnode_read_pci_addr(ofnode node, enum fdt_pci_space type,
|
|
|
|
const char *propname, struct fdt_pci_addr *addr);
|
|
|
|
|
2018-08-03 08:14:35 +00:00
|
|
|
/**
|
|
|
|
* ofnode_read_pci_vendev() - look up PCI vendor and device id
|
|
|
|
*
|
|
|
|
* Look at the compatible property of a device node that represents a PCI
|
|
|
|
* device and extract pci vendor id and device id from it.
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @node: node to examine
|
|
|
|
* @vendor: vendor id of the pci device
|
|
|
|
* @device: device id of the pci device
|
|
|
|
* Return: 0 if ok, negative on error
|
2018-08-03 08:14:35 +00:00
|
|
|
*/
|
|
|
|
int ofnode_read_pci_vendev(ofnode node, u16 *vendor, u16 *device);
|
|
|
|
|
2022-02-23 14:45:40 +00:00
|
|
|
/**
|
|
|
|
* ofnode_read_eth_phy_id() - look up eth phy vendor and device id
|
|
|
|
*
|
|
|
|
* Look at the compatible property of a device node that represents a eth phy
|
|
|
|
* device and extract phy vendor id and device id from it.
|
|
|
|
*
|
2022-03-24 15:22:32 +00:00
|
|
|
* @node: node to examine
|
|
|
|
* @vendor: vendor id of the eth phy device
|
|
|
|
* @device: device id of the eth phy device
|
|
|
|
* Return: 0 if ok, negative on error
|
2022-02-23 14:45:40 +00:00
|
|
|
*/
|
|
|
|
int ofnode_read_eth_phy_id(ofnode node, u16 *vendor, u16 *device);
|
|
|
|
|
2017-05-19 02:08:58 +00:00
|
|
|
/**
|
|
|
|
* ofnode_read_addr_cells() - Get the number of address cells for a node
|
|
|
|
*
|
|
|
|
* This walks back up the tree to find the closest #address-cells property
|
|
|
|
* which controls the given node.
|
|
|
|
*
|
|
|
|
* @node: Node to check
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: number of address cells this node uses
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
|
|
|
int ofnode_read_addr_cells(ofnode node);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_read_size_cells() - Get the number of size cells for a node
|
|
|
|
*
|
|
|
|
* This walks back up the tree to find the closest #size-cells property
|
|
|
|
* which controls the given node.
|
|
|
|
*
|
|
|
|
* @node: Node to check
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: number of size cells this node uses
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
|
|
|
int ofnode_read_size_cells(ofnode node);
|
|
|
|
|
2017-06-12 12:21:31 +00:00
|
|
|
/**
|
|
|
|
* ofnode_read_simple_addr_cells() - Get the address cells property in a node
|
|
|
|
*
|
|
|
|
* This function matches fdt_address_cells().
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @node: Node to check
|
|
|
|
* Return: value of #address-cells property in this node, or 2 if none
|
2017-06-12 12:21:31 +00:00
|
|
|
*/
|
|
|
|
int ofnode_read_simple_addr_cells(ofnode node);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_read_simple_size_cells() - Get the size cells property in a node
|
|
|
|
*
|
|
|
|
* This function matches fdt_size_cells().
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @node: Node to check
|
|
|
|
* Return: value of #size-cells property in this node, or 2 if none
|
2017-06-12 12:21:31 +00:00
|
|
|
*/
|
|
|
|
int ofnode_read_simple_size_cells(ofnode node);
|
|
|
|
|
2017-05-19 02:08:58 +00:00
|
|
|
/**
|
|
|
|
* ofnode_pre_reloc() - check if a node should be bound before relocation
|
|
|
|
*
|
|
|
|
* Device tree nodes can be marked as needing-to-be-bound in the loader stages
|
|
|
|
* via special device tree properties.
|
|
|
|
*
|
|
|
|
* Before relocation this function can be used to check if nodes are required
|
|
|
|
* in either SPL or TPL stages.
|
|
|
|
*
|
|
|
|
* After relocation and jumping into the real U-Boot binary it is possible to
|
|
|
|
* determine if a node was bound in one of SPL/TPL stages.
|
|
|
|
*
|
2019-05-21 17:19:13 +00:00
|
|
|
* There are 4 settings currently in use
|
|
|
|
* - u-boot,dm-pre-proper: U-Boot proper pre-relocation only
|
2017-05-19 02:08:58 +00:00
|
|
|
* - u-boot,dm-pre-reloc: legacy and indicates any of TPL or SPL
|
2022-01-12 09:53:49 +00:00
|
|
|
* Existing platforms only use it to indicate nodes needed in
|
|
|
|
* SPL. Should probably be replaced by u-boot,dm-spl for new platforms.
|
2019-05-21 17:19:13 +00:00
|
|
|
* - u-boot,dm-spl: SPL and U-Boot pre-relocation
|
|
|
|
* - u-boot,dm-tpl: TPL and U-Boot pre-relocation
|
2017-05-19 02:08:58 +00:00
|
|
|
*
|
|
|
|
* @node: node to check
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: true if node is needed in SPL/TL, false otherwise
|
2017-05-19 02:08:58 +00:00
|
|
|
*/
|
|
|
|
bool ofnode_pre_reloc(ofnode node);
|
|
|
|
|
2018-06-11 19:07:12 +00:00
|
|
|
/**
|
|
|
|
* ofnode_read_resource() - Read a resource from a node
|
|
|
|
*
|
|
|
|
* Read resource information from a node at the given index
|
|
|
|
*
|
|
|
|
* @node: Node to read from
|
|
|
|
* @index: Index of resource to read (0 = first)
|
|
|
|
* @res: Returns resource that was read, on success
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: 0 if OK, -ve on error
|
2018-06-11 19:07:12 +00:00
|
|
|
*/
|
2017-07-25 14:29:55 +00:00
|
|
|
int ofnode_read_resource(ofnode node, uint index, struct resource *res);
|
2018-06-11 19:07:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_read_resource_byname() - Read a resource from a node by name
|
|
|
|
*
|
|
|
|
* Read resource information from a node matching the given name. This uses a
|
|
|
|
* 'reg-names' string list property with the names matching the associated
|
|
|
|
* 'reg' property list.
|
|
|
|
*
|
|
|
|
* @node: Node to read from
|
|
|
|
* @name: Name of resource to read
|
|
|
|
* @res: Returns resource that was read, on success
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: 0 if OK, -ve on error
|
2018-06-11 19:07:12 +00:00
|
|
|
*/
|
2017-08-25 16:12:30 +00:00
|
|
|
int ofnode_read_resource_byname(ofnode node, const char *name,
|
|
|
|
struct resource *res);
|
2017-07-25 14:29:55 +00:00
|
|
|
|
2018-06-11 19:07:13 +00:00
|
|
|
/**
|
|
|
|
* ofnode_by_compatible() - Find the next compatible node
|
|
|
|
*
|
|
|
|
* Find the next node after @from that is compatible with @compat
|
|
|
|
*
|
|
|
|
* @from: ofnode to start from (use ofnode_null() to start at the beginning)
|
|
|
|
* @compat: Compatible string to match
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: ofnode found, or ofnode_null() if none
|
2018-06-11 19:07:13 +00:00
|
|
|
*/
|
|
|
|
ofnode ofnode_by_compatible(ofnode from, const char *compat);
|
|
|
|
|
2018-08-20 09:09:58 +00:00
|
|
|
/**
|
|
|
|
* ofnode_by_prop_value() - Find the next node with given property value
|
|
|
|
*
|
|
|
|
* Find the next node after @from that has a @propname with a value
|
|
|
|
* @propval and a length @proplen.
|
|
|
|
*
|
|
|
|
* @from: ofnode to start from (use ofnode_null() to start at the
|
2022-01-12 09:53:49 +00:00
|
|
|
* beginning)
|
|
|
|
* @propname: property name to check
|
|
|
|
* @propval: property value to search for
|
|
|
|
* @proplen: length of the value in propval
|
|
|
|
* Return: ofnode found, or ofnode_null() if none
|
2018-08-20 09:09:58 +00:00
|
|
|
*/
|
|
|
|
ofnode ofnode_by_prop_value(ofnode from, const char *propname,
|
|
|
|
const void *propval, int proplen);
|
|
|
|
|
2017-08-05 21:45:54 +00:00
|
|
|
/**
|
|
|
|
* ofnode_for_each_subnode() - iterate over all subnodes of a parent
|
|
|
|
*
|
|
|
|
* @node: child node (ofnode, lvalue)
|
|
|
|
* @parent: parent node (ofnode)
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* This is a wrapper around a for loop and is used like so::
|
2017-08-05 21:45:54 +00:00
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* ofnode node;
|
|
|
|
* ofnode_for_each_subnode(node, parent) {
|
|
|
|
* Use node
|
|
|
|
* ...
|
|
|
|
* }
|
2017-08-05 21:45:54 +00:00
|
|
|
*
|
|
|
|
* Note that this is implemented as a macro and @node is used as
|
|
|
|
* iterator in the loop. The parent variable can be a constant or even a
|
|
|
|
* literal.
|
|
|
|
*/
|
|
|
|
#define ofnode_for_each_subnode(node, parent) \
|
|
|
|
for (node = ofnode_first_subnode(parent); \
|
|
|
|
ofnode_valid(node); \
|
|
|
|
node = ofnode_next_subnode(node))
|
|
|
|
|
2021-10-15 13:15:17 +00:00
|
|
|
/**
|
|
|
|
* ofnode_for_each_compatible_node() - iterate over all nodes with a given
|
|
|
|
* compatible string
|
|
|
|
*
|
|
|
|
* @node: child node (ofnode, lvalue)
|
|
|
|
* @compat: compatible string to match
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* This is a wrapper around a for loop and is used like so::
|
2021-10-15 13:15:17 +00:00
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* ofnode node;
|
|
|
|
* ofnode_for_each_compatible_node(node, parent, compatible) {
|
|
|
|
* Use node
|
|
|
|
* ...
|
|
|
|
* }
|
2021-10-15 13:15:17 +00:00
|
|
|
*
|
|
|
|
* Note that this is implemented as a macro and @node is used as
|
|
|
|
* iterator in the loop.
|
|
|
|
*/
|
|
|
|
#define ofnode_for_each_compatible_node(node, compat) \
|
|
|
|
for (node = ofnode_by_compatible(ofnode_null(), compat); \
|
|
|
|
ofnode_valid(node); \
|
|
|
|
node = ofnode_by_compatible(node, compat))
|
|
|
|
|
2020-05-02 09:35:09 +00:00
|
|
|
/**
|
|
|
|
* ofnode_get_child_count() - get the child count of a ofnode
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @parent: valid node to get its child count
|
|
|
|
* Return: the number of subnodes
|
2020-05-02 09:35:09 +00:00
|
|
|
*/
|
|
|
|
int ofnode_get_child_count(ofnode parent);
|
|
|
|
|
2018-01-15 10:07:19 +00:00
|
|
|
/**
|
2019-05-31 13:11:30 +00:00
|
|
|
* ofnode_translate_address() - Translate a device-tree address
|
2018-01-15 10:07:19 +00:00
|
|
|
*
|
|
|
|
* Translate an address from the device-tree into a CPU physical address. This
|
|
|
|
* function walks up the tree and applies the various bus mappings along the
|
|
|
|
* way.
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @node: Device tree node giving the context in which to translate the address
|
2018-01-15 10:07:19 +00:00
|
|
|
* @in_addr: pointer to the address to translate
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: the translated address; OF_BAD_ADDR on error
|
2018-01-15 10:07:19 +00:00
|
|
|
*/
|
|
|
|
u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr);
|
2018-04-19 03:14:02 +00:00
|
|
|
|
2019-05-31 13:11:30 +00:00
|
|
|
/**
|
|
|
|
* ofnode_translate_dma_address() - Translate a device-tree DMA address
|
|
|
|
*
|
|
|
|
* Translate a DMA address from the device-tree into a CPU physical address.
|
|
|
|
* This function walks up the tree and applies the various bus mappings along
|
|
|
|
* the way.
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @node: Device tree node giving the context in which to translate the
|
|
|
|
* DMA address
|
2019-05-31 13:11:30 +00:00
|
|
|
* @in_addr: pointer to the DMA address to translate
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: the translated DMA address; OF_BAD_ADDR on error
|
2019-05-31 13:11:30 +00:00
|
|
|
*/
|
|
|
|
u64 ofnode_translate_dma_address(ofnode node, const fdt32_t *in_addr);
|
|
|
|
|
2021-01-12 12:55:22 +00:00
|
|
|
/**
|
|
|
|
* ofnode_get_dma_range() - get dma-ranges for a specific DT node
|
|
|
|
*
|
|
|
|
* Get DMA ranges for a specifc node, this is useful to perform bus->cpu and
|
|
|
|
* cpu->bus address translations
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @node: Device tree node
|
|
|
|
* @cpu: Pointer to variable storing the range's cpu address
|
|
|
|
* @bus: Pointer to variable storing the range's bus address
|
|
|
|
* @size: Pointer to variable storing the range's size
|
|
|
|
* Return: translated DMA address or OF_BAD_ADDR on error
|
2021-01-12 12:55:22 +00:00
|
|
|
*/
|
|
|
|
int ofnode_get_dma_range(ofnode node, phys_addr_t *cpu, dma_addr_t *bus,
|
|
|
|
u64 *size);
|
|
|
|
|
2018-04-19 03:14:02 +00:00
|
|
|
/**
|
|
|
|
* ofnode_device_is_compatible() - check if the node is compatible with compat
|
|
|
|
*
|
|
|
|
* This allows to check whether the node is comaptible with the compat.
|
|
|
|
*
|
|
|
|
* @node: Device tree node for which compatible needs to be verified.
|
|
|
|
* @compat: Compatible string which needs to verified in the given node.
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: true if OK, false if the compatible is not found
|
2018-04-19 03:14:02 +00:00
|
|
|
*/
|
|
|
|
int ofnode_device_is_compatible(ofnode node, const char *compat);
|
2018-06-26 06:46:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_write_prop() - Set a property of a ofnode
|
|
|
|
*
|
|
|
|
* Note that the value passed to the function is *not* allocated by the
|
2022-07-30 21:52:07 +00:00
|
|
|
* function itself, but must be allocated by the caller if necessary. However
|
|
|
|
* it does allocate memory for the property struct and name.
|
2018-06-26 06:46:48 +00:00
|
|
|
*
|
|
|
|
* @node: The node for whose property should be set
|
|
|
|
* @propname: The name of the property to set
|
|
|
|
* @value: The new value of the property (must be valid prior to calling
|
|
|
|
* the function)
|
2022-07-30 21:52:10 +00:00
|
|
|
* @len: The length of the new value of the property
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: 0 if successful, -ve on error
|
2018-06-26 06:46:48 +00:00
|
|
|
*/
|
2022-07-30 21:52:10 +00:00
|
|
|
int ofnode_write_prop(ofnode node, const char *propname, const void *value,
|
|
|
|
int len);
|
2018-06-26 06:46:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_write_string() - Set a string property of a ofnode
|
|
|
|
*
|
|
|
|
* Note that the value passed to the function is *not* allocated by the
|
|
|
|
* function itself, but must be allocated by the caller if necessary.
|
|
|
|
*
|
|
|
|
* @node: The node for whose string property should be set
|
|
|
|
* @propname: The name of the string property to set
|
|
|
|
* @value: The new value of the string property (must be valid prior to
|
|
|
|
* calling the function)
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: 0 if successful, -ve on error
|
2018-06-26 06:46:48 +00:00
|
|
|
*/
|
|
|
|
int ofnode_write_string(ofnode node, const char *propname, const char *value);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_set_enabled() - Enable or disable a device tree node given by its
|
|
|
|
* ofnode
|
|
|
|
*
|
|
|
|
* This function effectively sets the node's "status" property to either "okay"
|
|
|
|
* or "disable", hence making it available for driver model initialization or
|
|
|
|
* not.
|
|
|
|
*
|
|
|
|
* @node: The node to enable
|
|
|
|
* @value: Flag that tells the function to either disable or enable the
|
|
|
|
* node
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: 0 if successful, -ve on error
|
2018-06-26 06:46:48 +00:00
|
|
|
*/
|
|
|
|
int ofnode_set_enabled(ofnode node, bool value);
|
|
|
|
|
2022-03-28 22:14:37 +00:00
|
|
|
/**
|
|
|
|
* ofnode_get_phy_node() - Get PHY node for a MAC (if not fixed-link)
|
|
|
|
*
|
|
|
|
* This function parses PHY handle from the Ethernet controller's ofnode
|
|
|
|
* (trying all possible PHY handle property names), and returns the PHY ofnode.
|
|
|
|
*
|
|
|
|
* Before this is used, ofnode_phy_is_fixed_link() should be checked first, and
|
|
|
|
* if the result to that is true, this function should not be called.
|
|
|
|
*
|
|
|
|
* @eth_node: ofnode belonging to the Ethernet controller
|
|
|
|
* Return: ofnode of the PHY, if it exists, otherwise an invalid ofnode
|
|
|
|
*/
|
|
|
|
ofnode ofnode_get_phy_node(ofnode eth_node);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_read_phy_mode() - Read PHY connection type from a MAC node
|
|
|
|
*
|
|
|
|
* This function parses the "phy-mode" / "phy-connection-type" property and
|
|
|
|
* returns the corresponding PHY interface type.
|
|
|
|
*
|
|
|
|
* @mac_node: ofnode containing the property
|
|
|
|
* Return: one of PHY_INTERFACE_MODE_* constants, PHY_INTERFACE_MODE_NA on
|
|
|
|
* error
|
|
|
|
*/
|
|
|
|
phy_interface_t ofnode_read_phy_mode(ofnode mac_node);
|
|
|
|
|
|
|
|
#if CONFIG_IS_ENABLED(DM)
|
2021-08-07 13:24:01 +00:00
|
|
|
/**
|
|
|
|
* ofnode_conf_read_bool() - Read a boolean value from the U-Boot config
|
|
|
|
*
|
|
|
|
* This reads a property from the /config node of the devicetree.
|
|
|
|
*
|
|
|
|
* See doc/config.txt for bindings
|
|
|
|
*
|
2022-01-12 09:53:49 +00:00
|
|
|
* @prop_name: property name to look up
|
|
|
|
* Return: true, if it exists, false if not
|
2021-08-07 13:24:01 +00:00
|
|
|
*/
|
|
|
|
bool ofnode_conf_read_bool(const char *prop_name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_conf_read_int() - Read an integer value from the U-Boot config
|
|
|
|
*
|
|
|
|
* This reads a property from the /config node of the devicetree.
|
|
|
|
*
|
|
|
|
* See doc/config.txt for bindings
|
|
|
|
*
|
|
|
|
* @prop_name: property name to look up
|
|
|
|
* @default_val: default value to return if the property is not found
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: integer value, if found, or @default_val if not
|
2021-08-07 13:24:01 +00:00
|
|
|
*/
|
|
|
|
int ofnode_conf_read_int(const char *prop_name, int default_val);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ofnode_conf_read_str() - Read a string value from the U-Boot config
|
|
|
|
*
|
|
|
|
* This reads a property from the /config node of the devicetree.
|
|
|
|
*
|
|
|
|
* See doc/config.txt for bindings
|
|
|
|
*
|
|
|
|
* @prop_name: property name to look up
|
2022-01-12 09:53:49 +00:00
|
|
|
* Return: string value, if found, or NULL if not
|
2021-08-07 13:24:01 +00:00
|
|
|
*/
|
|
|
|
const char *ofnode_conf_read_str(const char *prop_name);
|
|
|
|
|
2022-03-28 22:14:37 +00:00
|
|
|
#else /* CONFIG_DM */
|
|
|
|
static inline bool ofnode_conf_read_bool(const char *prop_name)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2022-04-06 22:32:57 +00:00
|
|
|
|
2022-03-28 22:14:37 +00:00
|
|
|
static inline int ofnode_conf_read_int(const char *prop_name, int default_val)
|
|
|
|
{
|
|
|
|
return default_val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline const char *ofnode_conf_read_str(const char *prop_name)
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_DM */
|
2022-04-06 22:33:01 +00:00
|
|
|
|
2017-05-17 23:18:10 +00:00
|
|
|
#endif
|