2 * Register cache access API - indexed caching support
4 * Copyright 2011 Wolfson Microelectronics plc
6 * Author: Dimitris Papastamos <dp@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>
17 static int regcache_indexed_read(struct regmap
*map
, unsigned int reg
,
22 ret
= regcache_lookup_reg(map
, reg
);
24 *value
= map
->reg_defaults
[ret
].def
;
29 static int regcache_indexed_write(struct regmap
*map
, unsigned int reg
,
34 ret
= regcache_lookup_reg(map
, reg
);
36 return regcache_insert_reg(map
, reg
, value
);
37 map
->reg_defaults
[ret
].def
= value
;
41 static int regcache_indexed_sync(struct regmap
*map
)
46 for (i
= 0; i
< map
->num_reg_defaults
; i
++) {
47 ret
= _regmap_write(map
, map
->reg_defaults
[i
].reg
,
48 map
->reg_defaults
[i
].def
);
51 dev_dbg(map
->dev
, "Synced register %#x, value %#x\n",
52 map
->reg_defaults
[i
].reg
,
53 map
->reg_defaults
[i
].def
);
58 struct regcache_ops regcache_indexed_ops
= {
59 .type
= REGCACHE_INDEXED
,
61 .read
= regcache_indexed_read
,
62 .write
= regcache_indexed_write
,
63 .sync
= regcache_indexed_sync