Skip to content
Snippets Groups Projects
Commit 94fb182c authored by Alexander Graf's avatar Alexander Graf Committed by York Sun
Browse files

fdt_support: split fdt_getprop_u32_default


We already have a nice helper to give us a property cell value with default
fall back from a path. Split that into two helpers - one for the old path
based lookup and one to give us a value based on a node offset.

Signed-off-by: default avatarAlexander Graf <agraf@suse.de>
Acked-by: default avatarScott Wood <scottwood@freescale.com>
Reviewed-by: default avatarYork Sun <yorksun@freescale.com>
parent b149c4c3
No related branches found
No related tags found
No related merge requests found
...@@ -49,6 +49,37 @@ static void write_cell(u8 *addr, u64 val, int size) ...@@ -49,6 +49,37 @@ static void write_cell(u8 *addr, u64 val, int size)
} }
} }
/**
* fdt_getprop_u32_default_node - Return a node's property or a default
*
* @fdt: ptr to device tree
* @off: offset of node
* @cell: cell offset in property
* @prop: property name
* @dflt: default value if the property isn't found
*
* Convenience function to return a node's property or a default value if
* the property doesn't exist.
*/
u32 fdt_getprop_u32_default_node(const void *fdt, int off, int cell,
const char *prop, const u32 dflt)
{
const fdt32_t *val;
int len;
val = fdt_getprop(fdt, off, prop, &len);
/* Check if property exists */
if (!val)
return dflt;
/* Check if property is long enough */
if (len < ((cell + 1) * sizeof(uint32_t)))
return dflt;
return fdt32_to_cpu(*val);
}
/** /**
* fdt_getprop_u32_default - Find a node and return it's property or a default * fdt_getprop_u32_default - Find a node and return it's property or a default
* *
...@@ -63,18 +94,13 @@ static void write_cell(u8 *addr, u64 val, int size) ...@@ -63,18 +94,13 @@ static void write_cell(u8 *addr, u64 val, int size)
u32 fdt_getprop_u32_default(const void *fdt, const char *path, u32 fdt_getprop_u32_default(const void *fdt, const char *path,
const char *prop, const u32 dflt) const char *prop, const u32 dflt)
{ {
const fdt32_t *val;
int off; int off;
off = fdt_path_offset(fdt, path); off = fdt_path_offset(fdt, path);
if (off < 0) if (off < 0)
return dflt; return dflt;
val = fdt_getprop(fdt, off, prop, NULL); return fdt_getprop_u32_default_node(fdt, off, 0, prop, dflt);
if (val)
return fdt32_to_cpu(*val);
else
return dflt;
} }
/** /**
......
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
#include <libfdt.h> #include <libfdt.h>
u32 fdt_getprop_u32_default_node(const void *fdt, int off, int cell,
const char *prop, const u32 dflt);
u32 fdt_getprop_u32_default(const void *fdt, const char *path, u32 fdt_getprop_u32_default(const void *fdt, const char *path,
const char *prop, const u32 dflt); const char *prop, const u32 dflt);
int fdt_chosen(void *fdt, int force); int fdt_chosen(void *fdt, int force);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment