14 #include <linux/i2c.h>
17 #include <linux/bitmap.h>
18 #include <linux/rbtree.h>
19 #include <linux/export.h>
23 static bool snd_soc_set_cache_val(
void *base,
unsigned int idx,
24 unsigned int val,
unsigned int word_size)
29 if (cache[idx] == val)
36 if (cache[idx] == val)
47 static unsigned int snd_soc_get_cache_val(
const void *base,
unsigned int idx,
48 unsigned int word_size)
91 dev_dbg(codec->
dev,
"Synced register %#x, value = %#x\n",
97 static int snd_soc_flat_cache_write(
struct snd_soc_codec *codec,
98 unsigned int reg,
unsigned int value)
100 snd_soc_set_cache_val(codec->
reg_cache, reg, value,
101 codec->
driver->reg_word_size);
105 static int snd_soc_flat_cache_read(
struct snd_soc_codec *codec,
106 unsigned int reg,
unsigned int *
value)
108 *value = snd_soc_get_cache_val(codec->
reg_cache, reg,
109 codec->
driver->reg_word_size);
113 static int snd_soc_flat_cache_exit(
struct snd_soc_codec *codec)
122 static int snd_soc_flat_cache_init(
struct snd_soc_codec *codec)
141 .init = snd_soc_flat_cache_init,
142 .exit = snd_soc_flat_cache_exit,
143 .read = snd_soc_flat_cache_read,
144 .write = snd_soc_flat_cache_write,
145 .sync = snd_soc_flat_cache_sync
159 dev_warn(codec->
dev,
"Could not match compress type: %d\n",
169 dev_dbg(codec->
dev,
"Initializing %s cache for %s codec\n",
184 dev_dbg(codec->
dev,
"Destroying %s cache for %s codec\n",
199 unsigned int reg,
unsigned int *
value)
206 ret = codec->
cache_ops->read(codec, reg, value);
224 unsigned int reg,
unsigned int value)
231 ret = codec->
cache_ops->write(codec, reg, value);
268 dev_dbg(codec->
dev,
"Syncing %s cache for %s codec\n",
270 trace_snd_soc_cache_sync(codec, name,
"start");
274 trace_snd_soc_cache_sync(codec, name,
"end");
279 static int snd_soc_get_reg_access_index(
struct snd_soc_codec *codec,
285 codec_drv = codec->
driver;
289 index = (min +
max) / 2;
296 }
while (min <= max);
305 if (reg >= codec->
driver->reg_cache_size)
307 index = snd_soc_get_reg_access_index(codec, reg);
310 return codec->
driver->reg_access_default[
index].vol;
319 if (reg >= codec->
driver->reg_cache_size)
321 index = snd_soc_get_reg_access_index(codec, reg);
324 return codec->
driver->reg_access_default[
index].read;
333 if (reg >= codec->
driver->reg_cache_size)
335 index = snd_soc_get_reg_access_index(codec, reg);
338 return codec->
driver->reg_access_default[
index].write;