2 * Register cache access API - flat caching support
4 * Copyright 2012 Wolfson Microelectronics plc
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
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.
13 #include <linux/device.h>
14 #include <linux/seq_file.h>
15 #include <linux/slab.h>
19 static inline unsigned int regcache_flat_get_index(const struct regmap
*map
,
22 return regcache_get_index_by_order(map
, reg
);
25 static int regcache_flat_init(struct regmap
*map
)
30 if (!map
|| map
->reg_stride_order
< 0 || !map
->max_register
)
33 map
->cache
= kcalloc(regcache_flat_get_index(map
, map
->max_register
)
34 + 1, sizeof(unsigned int), GFP_KERNEL
);
40 for (i
= 0; i
< map
->num_reg_defaults
; i
++)
41 cache
[regcache_flat_get_index(map
, map
->reg_defaults
[i
].reg
)] =
42 map
->reg_defaults
[i
].def
;
47 static int regcache_flat_exit(struct regmap
*map
)
55 static int regcache_flat_read(struct regmap
*map
,
56 unsigned int reg
, unsigned int *value
)
58 unsigned int *cache
= map
->cache
;
60 *value
= cache
[regcache_flat_get_index(map
, reg
)];
65 static int regcache_flat_write(struct regmap
*map
, unsigned int reg
,
68 unsigned int *cache
= map
->cache
;
70 cache
[regcache_flat_get_index(map
, reg
)] = value
;
75 struct regcache_ops regcache_flat_ops
= {
76 .type
= REGCACHE_FLAT
,
78 .init
= regcache_flat_init
,
79 .exit
= regcache_flat_exit
,
80 .read
= regcache_flat_read
,
81 .write
= regcache_flat_write
,