mirror of
https://github.com/AsahiLinux/u-boot
synced 2025-02-17 22:49:02 +00:00
dm: regmap: Add support for livetree
Modify regmap to support livetree. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
40bb637dae
commit
23d6326791
1 changed files with 22 additions and 15 deletions
|
@ -12,8 +12,9 @@
|
|||
#include <malloc.h>
|
||||
#include <mapmem.h>
|
||||
#include <regmap.h>
|
||||
|
||||
#include <asm/io.h>
|
||||
#include <dm/of_addr.h>
|
||||
#include <linux/ioport.h>
|
||||
|
||||
DECLARE_GLOBAL_DATA_PTR;
|
||||
|
||||
|
@ -62,25 +63,25 @@ int regmap_init_mem_platdata(struct udevice *dev, u32 *reg, int count,
|
|||
#else
|
||||
int regmap_init_mem(struct udevice *dev, struct regmap **mapp)
|
||||
{
|
||||
const void *blob = gd->fdt_blob;
|
||||
struct regmap_range *range;
|
||||
const fdt32_t *cell;
|
||||
struct regmap *map;
|
||||
int count;
|
||||
int addr_len, size_len, both_len;
|
||||
int parent;
|
||||
int len;
|
||||
int index;
|
||||
ofnode node = dev_ofnode(dev);
|
||||
struct resource r;
|
||||
|
||||
parent = dev_of_offset(dev->parent);
|
||||
addr_len = fdt_address_cells(blob, parent);
|
||||
size_len = fdt_size_cells(blob, parent);
|
||||
addr_len = dev_read_addr_cells(dev->parent);
|
||||
size_len = dev_read_size_cells(dev->parent);
|
||||
both_len = addr_len + size_len;
|
||||
|
||||
cell = fdt_getprop(blob, dev_of_offset(dev), "reg", &len);
|
||||
len /= sizeof(*cell);
|
||||
len = dev_read_size(dev, "reg");
|
||||
if (len < 0)
|
||||
return len;
|
||||
len /= sizeof(fdt32_t);
|
||||
count = len / both_len;
|
||||
if (!cell || !count)
|
||||
if (!count)
|
||||
return -EINVAL;
|
||||
|
||||
map = regmap_alloc_count(count);
|
||||
|
@ -88,12 +89,18 @@ int regmap_init_mem(struct udevice *dev, struct regmap **mapp)
|
|||
return -ENOMEM;
|
||||
|
||||
for (range = map->range, index = 0; count > 0;
|
||||
count--, cell += both_len, range++, index++) {
|
||||
count--, range++, index++) {
|
||||
fdt_size_t sz;
|
||||
range->start = fdtdec_get_addr_size_fixed(blob,
|
||||
dev_of_offset(dev), "reg", index, addr_len,
|
||||
size_len, &sz, true);
|
||||
range->size = sz;
|
||||
if (of_live_active()) {
|
||||
of_address_to_resource(ofnode_to_np(node), index, &r);
|
||||
range->start = r.start;
|
||||
range->size = r.end - r.start + 1;
|
||||
} else {
|
||||
range->start = fdtdec_get_addr_size_fixed(gd->fdt_blob,
|
||||
dev_of_offset(dev), "reg", index,
|
||||
addr_len, size_len, &sz, true);
|
||||
range->size = sz;
|
||||
}
|
||||
}
|
||||
map->base = map->range[0].start;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue