Commit 94fb182cdf5f39befc822cd5a1110a1ca3b6631d

Authored by Alexander Graf
Committed by York Sun
1 parent b149c4c399

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: Alexander Graf <agraf@suse.de>
Acked-by: Scott Wood <scottwood@freescale.com>
Reviewed-by: York Sun <yorksun@freescale.com>

Showing 2 changed files with 34 additions and 6 deletions Side-by-side Diff

common/fdt_support.c
... ... @@ -50,6 +50,37 @@
50 50 }
51 51  
52 52 /**
  53 + * fdt_getprop_u32_default_node - Return a node's property or a default
  54 + *
  55 + * @fdt: ptr to device tree
  56 + * @off: offset of node
  57 + * @cell: cell offset in property
  58 + * @prop: property name
  59 + * @dflt: default value if the property isn't found
  60 + *
  61 + * Convenience function to return a node's property or a default value if
  62 + * the property doesn't exist.
  63 + */
  64 +u32 fdt_getprop_u32_default_node(const void *fdt, int off, int cell,
  65 + const char *prop, const u32 dflt)
  66 +{
  67 + const fdt32_t *val;
  68 + int len;
  69 +
  70 + val = fdt_getprop(fdt, off, prop, &len);
  71 +
  72 + /* Check if property exists */
  73 + if (!val)
  74 + return dflt;
  75 +
  76 + /* Check if property is long enough */
  77 + if (len < ((cell + 1) * sizeof(uint32_t)))
  78 + return dflt;
  79 +
  80 + return fdt32_to_cpu(*val);
  81 +}
  82 +
  83 +/**
53 84 * fdt_getprop_u32_default - Find a node and return it's property or a default
54 85 *
55 86 * @fdt: ptr to device tree
56 87  
... ... @@ -63,18 +94,13 @@
63 94 u32 fdt_getprop_u32_default(const void *fdt, const char *path,
64 95 const char *prop, const u32 dflt)
65 96 {
66   - const fdt32_t *val;
67 97 int off;
68 98  
69 99 off = fdt_path_offset(fdt, path);
70 100 if (off < 0)
71 101 return dflt;
72 102  
73   - val = fdt_getprop(fdt, off, prop, NULL);
74   - if (val)
75   - return fdt32_to_cpu(*val);
76   - else
77   - return dflt;
  103 + return fdt_getprop_u32_default_node(fdt, off, 0, prop, dflt);
78 104 }
79 105  
80 106 /**
include/fdt_support.h
... ... @@ -12,6 +12,8 @@
12 12  
13 13 #include <libfdt.h>
14 14  
  15 +u32 fdt_getprop_u32_default_node(const void *fdt, int off, int cell,
  16 + const char *prop, const u32 dflt);
15 17 u32 fdt_getprop_u32_default(const void *fdt, const char *path,
16 18 const char *prop, const u32 dflt);
17 19 int fdt_chosen(void *fdt, int force);