#include <dm.h>
#include <fdtdec.h>
#include <fdt_support.h>
+#include <log.h>
#include <malloc.h>
#include <linux/libfdt.h>
#include <dm/of_access.h>
#include <dm/ofnode.h>
#include <linux/err.h>
#include <linux/ioport.h>
+#include <asm/global_data.h>
+
+bool ofnode_name_eq(ofnode node, const char *name)
+{
+ const char *node_name;
+ size_t len;
+
+ assert(ofnode_valid(node));
+
+ node_name = ofnode_get_name(node);
+ len = strchrnul(node_name, '@') - node_name;
+
+ return (strlen(name) == len) && !strncmp(node_name, name, len);
+}
int ofnode_read_u32(ofnode node, const char *propname, u32 *outp)
{
}
}
+#if !CONFIG_IS_ENABLED(DM_INLINE_OFNODE)
+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));
+ }
+}
+
ofnode ofnode_first_subnode(ofnode node)
{
assert(ofnode_valid(node));
return offset_to_ofnode(
fdt_next_subnode(gd->fdt_blob, ofnode_to_offset(node)));
}
+#endif /* !DM_INLINE_OFNODE */
ofnode ofnode_get_parent(ofnode node)
{
return fdt_get_name(gd->fdt_blob, ofnode_to_offset(node), NULL);
}
+int ofnode_get_path(ofnode node, char *buf, int buflen)
+{
+ assert(ofnode_valid(node));
+
+ if (ofnode_is_np(node)) {
+ if (strlen(node.np->full_name) >= buflen)
+ return -ENOSPC;
+
+ strcpy(buf, node.np->full_name);
+
+ return 0;
+ } else {
+ int res;
+
+ res = fdt_get_path(gd->fdt_blob, ofnode_to_offset(node), buf,
+ buflen);
+ if (!res)
+ return res;
+ else if (res == -FDT_ERR_NOSPACE)
+ return -ENOSPC;
+ else
+ return -EINVAL;
+ }
+}
+
ofnode ofnode_get_by_phandle(uint phandle)
{
ofnode node;
return node;
}
-fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *size)
+static fdt_addr_t __ofnode_get_addr_size_index(ofnode node, int index,
+ fdt_size_t *size, bool translate)
{
int na, ns;
+ if (size)
+ *size = FDT_SIZE_T_NONE;
+
if (ofnode_is_np(node)) {
const __be32 *prop_val;
u64 size64;
&flags);
if (!prop_val)
return FDT_ADDR_T_NONE;
+
if (size)
*size = size64;
ns = of_n_size_cells(ofnode_to_np(node));
- if (IS_ENABLED(CONFIG_OF_TRANSLATE) && ns > 0) {
+ if (translate && IS_ENABLED(CONFIG_OF_TRANSLATE) && ns > 0) {
return of_translate_address(ofnode_to_np(node), prop_val);
} else {
na = of_n_addr_cells(ofnode_to_np(node));
ns = ofnode_read_simple_size_cells(ofnode_get_parent(node));
return fdtdec_get_addr_size_fixed(gd->fdt_blob,
ofnode_to_offset(node), "reg",
- index, na, ns, size, true);
+ index, na, ns, size,
+ translate);
}
+}
- return FDT_ADDR_T_NONE;
+fdt_addr_t ofnode_get_addr_size_index(ofnode node, int index, fdt_size_t *size)
+{
+ return __ofnode_get_addr_size_index(node, index, size, true);
+}
+
+fdt_addr_t ofnode_get_addr_size_index_notrans(ofnode node, int index,
+ fdt_size_t *size)
+{
+ return __ofnode_get_addr_size_index(node, index, size, false);
}
fdt_addr_t ofnode_get_addr_index(ofnode node, int index)
return ofnode_get_addr_index(node, 0);
}
+fdt_size_t ofnode_get_size(ofnode node)
+{
+ fdt_size_t size;
+
+ ofnode_get_addr_size_index(node, 0, &size);
+
+ return size;
+}
+
int ofnode_stringlist_search(ofnode node, const char *property,
const char *string)
{
int ret;
ret = of_parse_phandle_with_args(ofnode_to_np(node),
- list_name, cells_name, index,
+ list_name, cells_name,
+ cell_count, index,
&args);
if (ret)
return ret;
}
int ofnode_count_phandle_with_args(ofnode node, const char *list_name,
- const char *cells_name)
+ const char *cells_name, int cell_count)
{
if (ofnode_is_np(node))
return of_count_phandle_with_args(ofnode_to_np(node),
- list_name, cells_name);
+ list_name, cells_name, cell_count);
else
return fdtdec_parse_phandle_with_args(gd->fdt_blob,
ofnode_to_offset(node), list_name, cells_name,
- 0, -1, NULL);
+ cell_count, -1, NULL);
}
ofnode ofnode_path(const char *path)
return ofnode_path(prop);
}
+const void *ofnode_read_aliases_prop(const char *propname, int *sizep)
+{
+ ofnode node;
+
+ node = ofnode_path("/aliases");
+
+ return ofnode_read_prop(node, propname, sizep);
+}
+
+ofnode ofnode_get_aliases_node(const char *name)
+{
+ const char *prop;
+
+ prop = ofnode_read_aliases_prop(name, NULL);
+ if (!prop)
+ return ofnode_null();
+
+ debug("%s: node_path: %s\n", __func__, prop);
+
+ return ofnode_path(prop);
+}
+
int ofnode_get_child_count(ofnode parent)
{
ofnode child;
int ofnode_read_addr_cells(ofnode node)
{
- if (ofnode_is_np(node))
+ if (ofnode_is_np(node)) {
return of_n_addr_cells(ofnode_to_np(node));
- else /* NOTE: this call should walk up the parent stack */
- return fdt_address_cells(gd->fdt_blob, ofnode_to_offset(node));
+ } else {
+ int parent = fdt_parent_offset(gd->fdt_blob,
+ ofnode_to_offset(node));
+
+ return fdt_address_cells(gd->fdt_blob, parent);
+ }
}
int ofnode_read_size_cells(ofnode node)
{
- if (ofnode_is_np(node))
+ if (ofnode_is_np(node)) {
return of_n_size_cells(ofnode_to_np(node));
- else /* NOTE: this call should walk up the parent stack */
- return fdt_size_cells(gd->fdt_blob, ofnode_to_offset(node));
+ } else {
+ int parent = fdt_parent_offset(gd->fdt_blob,
+ ofnode_to_offset(node));
+
+ return fdt_size_cells(gd->fdt_blob, parent);
+ }
}
int ofnode_read_simple_addr_cells(ofnode node)
return fdt_translate_dma_address(gd->fdt_blob, ofnode_to_offset(node), in_addr);
}
+int ofnode_get_dma_range(ofnode node, phys_addr_t *cpu, dma_addr_t *bus, u64 *size)
+{
+ if (ofnode_is_np(node))
+ return of_get_dma_range(ofnode_to_np(node), cpu, bus, size);
+ else
+ return fdt_get_dma_range(gd->fdt_blob, ofnode_to_offset(node),
+ cpu, bus, size);
+}
+
int ofnode_device_is_compatible(ofnode node, const char *compat)
{
if (ofnode_is_np(node))