1 // SPDX-License-Identifier: GPL-2.0
3 // Register cache access API - flat caching support
5 // Copyright 2012 Wolfson Microelectronics plc
7 // Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
9 #include <linux/device.h>
10 #include <linux/seq_file.h>
11 #include <linux/slab.h>
15 static inline unsigned int regcache_flat_get_index(const struct regmap
*map
,
18 return regcache_get_index_by_order(map
, reg
);
21 static int regcache_flat_init(struct regmap
*map
)
26 if (!map
|| map
->reg_stride_order
< 0 || !map
->max_register
)
29 map
->cache
= kcalloc(regcache_flat_get_index(map
, map
->max_register
)
30 + 1, sizeof(unsigned int), GFP_KERNEL
);
36 for (i
= 0; i
< map
->num_reg_defaults
; i
++) {
37 unsigned int reg
= map
->reg_defaults
[i
].reg
;
38 unsigned int index
= regcache_flat_get_index(map
, reg
);
40 cache
[index
] = map
->reg_defaults
[i
].def
;
46 static int regcache_flat_exit(struct regmap
*map
)
54 static int regcache_flat_read(struct regmap
*map
,
55 unsigned int reg
, unsigned int *value
)
57 unsigned int *cache
= map
->cache
;
58 unsigned int index
= regcache_flat_get_index(map
, reg
);
60 *value
= cache
[index
];
65 static int regcache_flat_write(struct regmap
*map
, unsigned int reg
,
68 unsigned int *cache
= map
->cache
;
69 unsigned int index
= regcache_flat_get_index(map
, reg
);
76 struct regcache_ops regcache_flat_ops
= {
77 .type
= REGCACHE_FLAT
,
79 .init
= regcache_flat_init
,
80 .exit
= regcache_flat_exit
,
81 .read
= regcache_flat_read
,
82 .write
= regcache_flat_write
,