aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/base/regmap/regcache-flat.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/drivers/base/regmap/regcache-flat.c b/drivers/base/regmap/regcache-flat.c
index 686c9e0b930e..3ee72550b1e3 100644
--- a/drivers/base/regmap/regcache-flat.c
+++ b/drivers/base/regmap/regcache-flat.c
@@ -16,20 +16,30 @@
16 16
17#include "internal.h" 17#include "internal.h"
18 18
19static inline unsigned int regcache_flat_get_index(const struct regmap *map,
20 unsigned int reg)
21{
22 return regcache_get_index_by_order(map, reg);
23}
24
19static int regcache_flat_init(struct regmap *map) 25static int regcache_flat_init(struct regmap *map)
20{ 26{
21 int i; 27 int i;
22 unsigned int *cache; 28 unsigned int *cache;
23 29
24 map->cache = kcalloc(map->max_register + 1, sizeof(unsigned int), 30 if (!map || map->reg_stride_order < 0)
25 GFP_KERNEL); 31 return -EINVAL;
32
33 map->cache = kcalloc(regcache_flat_get_index(map, map->max_register)
34 + 1, sizeof(unsigned int), GFP_KERNEL);
26 if (!map->cache) 35 if (!map->cache)
27 return -ENOMEM; 36 return -ENOMEM;
28 37
29 cache = map->cache; 38 cache = map->cache;
30 39
31 for (i = 0; i < map->num_reg_defaults; i++) 40 for (i = 0; i < map->num_reg_defaults; i++)
32 cache[map->reg_defaults[i].reg] = map->reg_defaults[i].def; 41 cache[regcache_flat_get_index(map, map->reg_defaults[i].reg)] =
42 map->reg_defaults[i].def;
33 43
34 return 0; 44 return 0;
35} 45}
@@ -47,7 +57,7 @@ static int regcache_flat_read(struct regmap *map,
47{ 57{
48 unsigned int *cache = map->cache; 58 unsigned int *cache = map->cache;
49 59
50 *value = cache[reg]; 60 *value = cache[regcache_flat_get_index(map, reg)];
51 61
52 return 0; 62 return 0;
53} 63}
@@ -57,7 +67,7 @@ static int regcache_flat_write(struct regmap *map, unsigned int reg,
57{ 67{
58 unsigned int *cache = map->cache; 68 unsigned int *cache = map->cache;
59 69
60 cache[reg] = value; 70 cache[regcache_flat_get_index(map, reg)] = value;
61 71
62 return 0; 72 return 0;
63} 73}