1 // SPDX-License-Identifier: GPL-2.0
3 // Register map access API - Memory region
5 // This is intended for testing only
7 // Copyright (c) 2023, Arm Ltd
10 #include <linux/err.h>
12 #include <linux/module.h>
13 #include <linux/regmap.h>
14 #include <linux/slab.h>
15 #include <linux/swab.h>
19 static int regmap_ram_write(void *context, unsigned int reg, unsigned int val)
21 struct regmap_ram_data *data = context;
23 data->vals[reg] = val;
24 data->written[reg] = true;
29 static int regmap_ram_read(void *context, unsigned int reg, unsigned int *val)
31 struct regmap_ram_data *data = context;
33 *val = data->vals[reg];
34 data->read[reg] = true;
39 static void regmap_ram_free_context(void *context)
41 struct regmap_ram_data *data = context;
49 static const struct regmap_bus regmap_ram = {
51 .reg_write = regmap_ram_write,
52 .reg_read = regmap_ram_read,
53 .free_context = regmap_ram_free_context,
56 struct regmap *__regmap_init_ram(const struct regmap_config *config,
57 struct regmap_ram_data *data,
58 struct lock_class_key *lock_key,
59 const char *lock_name)
63 if (!config->max_register) {
64 pr_crit("No max_register specified for RAM regmap\n");
65 return ERR_PTR(-EINVAL);
68 data->read = kcalloc(sizeof(bool), config->max_register + 1,
71 return ERR_PTR(-ENOMEM);
73 data->written = kcalloc(sizeof(bool), config->max_register + 1,
76 return ERR_PTR(-ENOMEM);
78 map = __regmap_init(NULL, ®map_ram, data, config,
83 EXPORT_SYMBOL_GPL(__regmap_init_ram);
85 MODULE_LICENSE("GPL v2");