summaryrefslogtreecommitdiffstats
path: root/common/memory.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2013-02-21 00:21:29 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2013-03-06 11:41:29 +0100
commit9d8e08353cf8628d41335b9c5910bd352ef75f4d (patch)
tree75b534f7a701420c3ae112b22d7e58fe35d8c76d /common/memory.c
parentcf95711e5201b04e32be8f9122200308638279e9 (diff)
downloadbarebox-9d8e08353cf8628d41335b9c5910bd352ef75f4d.tar.gz
of: fixup unflattened devicetree
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/memory.c')
-rw-r--r--common/memory.c48
1 files changed, 14 insertions, 34 deletions
diff --git a/common/memory.c b/common/memory.c
index 81641f0..1d2e3a3 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -165,22 +165,6 @@ int release_sdram_region(struct resource *res)
#ifdef CONFIG_OFTREE
/*
- * Get cells len in bytes
- * if #NNNN-cells property is 2 then len is 8
- * otherwise len is 4
- */
-static int get_cells_len(struct fdt_header *fdt, char *nr_cells_name)
-{
- const u32 *cell;
-
- cell = fdt_getprop(fdt, 0, nr_cells_name, NULL);
- if (cell && *cell == 2)
- return 8;
-
- return 4;
-}
-
-/*
* Write a 4 or 8 byte big endian cell
*/
static void write_cell(u8 *addr, u64 val, int size)
@@ -193,28 +177,24 @@ static void write_cell(u8 *addr, u64 val, int size)
}
}
-static int of_memory_fixup(struct fdt_header *fdt)
+static int of_memory_fixup(struct device_node *node)
{
struct memory_bank *bank;
- int err, nodeoffset;
+ int err;
int addr_cell_len, size_cell_len, len = 0;
+ struct device_node *memnode;
u8 tmp[16 * 16]; /* Up to 64-bit address + 64-bit size */
- /* update, or add and update /memory node */
- nodeoffset = fdt_get_path_or_create(fdt, "/memory");
- if (nodeoffset < 0)
- return nodeoffset;
+ memnode = of_create_node(node, "/memory");
+ if (!memnode)
+ return -ENOMEM;
- err = fdt_setprop(fdt, nodeoffset, "device_type", "memory",
- sizeof("memory"));
- if (err < 0) {
- printf("WARNING: could not set %s %s.\n", "device_type",
- fdt_strerror(err));
+ err = of_set_property(memnode, "device_type", "memory", sizeof("memory"), 1);
+ if (err)
return err;
- }
- addr_cell_len = get_cells_len(fdt, "#address-cells");
- size_cell_len = get_cells_len(fdt, "#size-cells");
+ addr_cell_len = of_n_addr_cells(memnode) * 4;
+ size_cell_len = of_n_size_cells(memnode) * 4;
for_each_memory_bank(bank) {
write_cell(tmp + len, bank->start, addr_cell_len);
@@ -223,12 +203,12 @@ static int of_memory_fixup(struct fdt_header *fdt)
len += size_cell_len;
}
- err = fdt_setprop(fdt, nodeoffset, "reg", tmp, len);
- if (err < 0) {
- printf("WARNING: could not set %s %s.\n",
- "reg", fdt_strerror(err));
+ err = of_set_property(memnode, "reg", tmp, len, 1);
+ if (err) {
+ pr_err("could not set reg %s.\n", strerror(-err));
return err;
}
+
return 0;
}