aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/regmap/regcache-flat.c
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2012-12-19 09:51:55 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2013-01-02 05:58:53 -0500
commit2ac902ce17f9dfa0d4d1f0818be147b5d2515fb7 (patch)
tree20edcdd038f298fca0e39b658a40620e48ea1504 /drivers/base/regmap/regcache-flat.c
parenta49f0d1ea3ec94fc7cf33a7c36a16343b74bd565 (diff)
regmap: flat: Add flat cache type
While for I2C and SPI devices the overhead of using rbtree for devices with only one block of registers is negligible the same isn't always going to be true for MMIO devices where the I/O costs are very much lower. Cater for these devices by adding a simple flat array type for them where the lookups are simple array accesses, taking us right back to the original ASoC cache implementation. Thanks to Magnus Damm for the discussion which prompted this. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/base/regmap/regcache-flat.c')
-rw-r--r--drivers/base/regmap/regcache-flat.c72
1 files changed, 72 insertions, 0 deletions
diff --git a/drivers/base/regmap/regcache-flat.c b/drivers/base/regmap/regcache-flat.c
new file mode 100644
index 000000000000..d9762e41959b
--- /dev/null
+++ b/drivers/base/regmap/regcache-flat.c
@@ -0,0 +1,72 @@
1/*
2 * Register cache access API - flat caching support
3 *
4 * Copyright 2012 Wolfson Microelectronics plc
5 *
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/slab.h>
14#include <linux/device.h>
15#include <linux/seq_file.h>
16
17#include "internal.h"
18
19static int regcache_flat_init(struct regmap *map)
20{
21 int i;
22 unsigned int *cache;
23
24 map->cache = kzalloc(sizeof(unsigned int) * (map->max_register + 1),
25 GFP_KERNEL);
26 if (!map->cache)
27 return -ENOMEM;
28
29 cache = map->cache;
30
31 for (i = 0; i < map->num_reg_defaults; i++)
32 cache[map->reg_defaults[i].reg] = map->reg_defaults[i].def;
33
34 return 0;
35}
36
37static int regcache_flat_exit(struct regmap *map)
38{
39 kfree(map->cache);
40 map->cache = NULL;
41
42 return 0;
43}
44
45static int regcache_flat_read(struct regmap *map,
46 unsigned int reg, unsigned int *value)
47{
48 unsigned int *cache = map->cache;
49
50 *value = cache[reg];
51
52 return 0;
53}
54
55static int regcache_flat_write(struct regmap *map, unsigned int reg,
56 unsigned int value)
57{
58 unsigned int *cache = map->cache;
59
60 cache[reg] = value;
61
62 return 0;
63}
64
65struct regcache_ops regcache_flat_ops = {
66 .type = REGCACHE_FLAT,
67 .name = "flat",
68 .init = regcache_flat_init,
69 .exit = regcache_flat_exit,
70 .read = regcache_flat_read,
71 .write = regcache_flat_write,
72};