PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / base / regmap / regcache-flat.c
blobd9762e41959b07b55fa22c239b9170344dc9b634
1 /*
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/slab.h>
14 #include <linux/device.h>
15 #include <linux/seq_file.h>
17 #include "internal.h"
19 static int regcache_flat_init(struct regmap *map)
21 int i;
22 unsigned int *cache;
24 map->cache = kzalloc(sizeof(unsigned int) * (map->max_register + 1),
25 GFP_KERNEL);
26 if (!map->cache)
27 return -ENOMEM;
29 cache = map->cache;
31 for (i = 0; i < map->num_reg_defaults; i++)
32 cache[map->reg_defaults[i].reg] = map->reg_defaults[i].def;
34 return 0;
37 static int regcache_flat_exit(struct regmap *map)
39 kfree(map->cache);
40 map->cache = NULL;
42 return 0;
45 static int regcache_flat_read(struct regmap *map,
46 unsigned int reg, unsigned int *value)
48 unsigned int *cache = map->cache;
50 *value = cache[reg];
52 return 0;
55 static int regcache_flat_write(struct regmap *map, unsigned int reg,
56 unsigned int value)
58 unsigned int *cache = map->cache;
60 cache[reg] = value;
62 return 0;
65 struct 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,