|
@@ -17,22 +17,13 @@
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
-static struct regmap *regmap_alloc_count(int count)
|
|
|
|
|
|
+static struct regmap *regmap_alloc(int count)
|
|
{
|
|
{
|
|
struct regmap *map;
|
|
struct regmap *map;
|
|
|
|
|
|
- map = malloc(sizeof(struct regmap));
|
|
|
|
|
|
+ map = malloc(sizeof(*map) + sizeof(map->ranges[0]) * count);
|
|
if (!map)
|
|
if (!map)
|
|
return NULL;
|
|
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;
|
|
map->range_count = count;
|
|
|
|
|
|
return map;
|
|
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_range *range;
|
|
struct regmap *map;
|
|
struct regmap *map;
|
|
|
|
|
|
- map = regmap_alloc_count(count);
|
|
|
|
|
|
+ map = regmap_alloc(count);
|
|
if (!map)
|
|
if (!map)
|
|
return -ENOMEM;
|
|
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->start = *reg;
|
|
range->size = reg[1];
|
|
range->size = reg[1];
|
|
}
|
|
}
|
|
@@ -83,11 +73,11 @@ int regmap_init_mem(struct udevice *dev, struct regmap **mapp)
|
|
if (!count)
|
|
if (!count)
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
|
|
|
|
- map = regmap_alloc_count(count);
|
|
|
|
|
|
+ map = regmap_alloc(count);
|
|
if (!map)
|
|
if (!map)
|
|
return -ENOMEM;
|
|
return -ENOMEM;
|
|
|
|
|
|
- for (range = map->range, index = 0; count > 0;
|
|
|
|
|
|
+ for (range = map->ranges, index = 0; count > 0;
|
|
count--, range++, index++) {
|
|
count--, range++, index++) {
|
|
fdt_size_t sz;
|
|
fdt_size_t sz;
|
|
if (of_live_active()) {
|
|
if (of_live_active()) {
|
|
@@ -101,7 +91,6 @@ int regmap_init_mem(struct udevice *dev, struct regmap **mapp)
|
|
range->size = sz;
|
|
range->size = sz;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- map->base = map->range[0].start;
|
|
|
|
|
|
|
|
*mapp = map;
|
|
*mapp = map;
|
|
|
|
|
|
@@ -115,15 +104,13 @@ void *regmap_get_range(struct regmap *map, unsigned int range_num)
|
|
|
|
|
|
if (range_num >= map->range_count)
|
|
if (range_num >= map->range_count)
|
|
return NULL;
|
|
return NULL;
|
|
- range = &map->range[range_num];
|
|
|
|
|
|
+ range = &map->ranges[range_num];
|
|
|
|
|
|
return map_sysmem(range->start, range->size);
|
|
return map_sysmem(range->start, range->size);
|
|
}
|
|
}
|
|
|
|
|
|
int regmap_uninit(struct regmap *map)
|
|
int regmap_uninit(struct regmap *map)
|
|
{
|
|
{
|
|
- if (map->range_count > 1)
|
|
|
|
- free(map->range);
|
|
|
|
free(map);
|
|
free(map);
|
|
|
|
|
|
return 0;
|
|
return 0;
|
|
@@ -131,7 +118,7 @@ int regmap_uninit(struct regmap *map)
|
|
|
|
|
|
int regmap_read(struct regmap *map, uint offset, uint *valp)
|
|
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));
|
|
*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)
|
|
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);
|
|
writel(cpu_to_le32(val), ptr);
|
|
|
|
|