diff options
Diffstat (limited to 'drivers/core/regmap.c')
-rw-r--r-- | drivers/core/regmap.c | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c index a5e4e74825..0f787ab4e1 100644 --- a/drivers/core/regmap.c +++ b/drivers/core/regmap.c @@ -17,22 +17,13 @@ DECLARE_GLOBAL_DATA_PTR; -static struct regmap *regmap_alloc_count(int count) +static struct regmap *regmap_alloc(int count) { struct regmap *map; - map = malloc(sizeof(struct regmap)); + map = malloc(sizeof(*map) + sizeof(map->ranges[0]) * count); if (!map) return NULL; - if (count <= 1) { - map->range = &map->base_range; - } else { - map->range = malloc(count * sizeof(struct regmap_range)); - if (!map->range) { - free(map); - return NULL; - } - } map->range_count = count; return map; @@ -45,12 +36,11 @@ int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t *reg, int count, struct regmap_range *range; struct regmap *map; - map = regmap_alloc_count(count); + map = regmap_alloc(count); if (!map) return -ENOMEM; - map->base = *reg; - for (range = map->range; count > 0; reg += 2, range++, count--) { + for (range = map->ranges; count > 0; reg += 2, range++, count--) { range->start = *reg; range->size = reg[1]; } @@ -83,11 +73,11 @@ int regmap_init_mem(struct udevice *dev, struct regmap **mapp) if (!count) return -EINVAL; - map = regmap_alloc_count(count); + map = regmap_alloc(count); if (!map) return -ENOMEM; - for (range = map->range, index = 0; count > 0; + for (range = map->ranges, index = 0; count > 0; count--, range++, index++) { fdt_size_t sz; if (of_live_active()) { @@ -101,7 +91,6 @@ int regmap_init_mem(struct udevice *dev, struct regmap **mapp) range->size = sz; } } - map->base = map->range[0].start; *mapp = map; @@ -115,15 +104,13 @@ void *regmap_get_range(struct regmap *map, unsigned int range_num) if (range_num >= map->range_count) return NULL; - range = &map->range[range_num]; + range = &map->ranges[range_num]; return map_sysmem(range->start, range->size); } int regmap_uninit(struct regmap *map) { - if (map->range_count > 1) - free(map->range); free(map); return 0; @@ -131,7 +118,7 @@ int regmap_uninit(struct regmap *map) int regmap_read(struct regmap *map, uint offset, uint *valp) { - uint32_t *ptr = map_physmem(map->base + offset, 4, MAP_NOCACHE); + u32 *ptr = map_physmem(map->ranges[0].start + offset, 4, MAP_NOCACHE); *valp = le32_to_cpu(readl(ptr)); @@ -140,7 +127,7 @@ int regmap_read(struct regmap *map, uint offset, uint *valp) int regmap_write(struct regmap *map, uint offset, uint val) { - uint32_t *ptr = map_physmem(map->base + offset, 4, MAP_NOCACHE); + u32 *ptr = map_physmem(map->ranges[0].start + offset, 4, MAP_NOCACHE); writel(cpu_to_le32(val), ptr); |