Skip to content

Commit

Permalink
ASoC: Delegate to hw specific read for volatile registers
Browse files Browse the repository at this point in the history
Ensure that reads on volatile registers will correctly delegate
to the bus specific read function.

Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
  • Loading branch information
Dimitris Papastamos authored and Mark Brown committed Sep 23, 2010
1 parent 3e13f65 commit db49c14
Showing 1 changed file with 50 additions and 26 deletions.
76 changes: 50 additions & 26 deletions sound/soc/soc-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,15 @@ static unsigned int snd_soc_4_12_read(struct snd_soc_codec *codec,
unsigned int reg)
{
u16 *cache = codec->reg_cache;
if (reg >= codec->driver->reg_cache_size)
return -1;

if (reg >= codec->driver->reg_cache_size ||
snd_soc_codec_volatile_register(codec, reg)) {
if (codec->cache_only)
return -1;

return codec->hw_read(codec, reg);
}

return cache[reg];
}

Expand All @@ -31,13 +38,12 @@ static int snd_soc_4_12_write(struct snd_soc_codec *codec, unsigned int reg,
u8 data[2];
int ret;

BUG_ON(codec->driver->volatile_register);

data[0] = (reg << 4) | ((value >> 8) & 0x000f);
data[1] = value & 0x00ff;

if (reg < codec->driver->reg_cache_size)
cache[reg] = value;
if (!snd_soc_codec_volatile_register(codec, reg) &&
reg < codec->driver->reg_cache_size)
cache[reg] = value;

if (codec->cache_only) {
codec->cache_sync = 1;
Expand Down Expand Up @@ -89,8 +95,15 @@ static unsigned int snd_soc_7_9_read(struct snd_soc_codec *codec,
unsigned int reg)
{
u16 *cache = codec->reg_cache;
if (reg >= codec->driver->reg_cache_size)
return -1;

if (reg >= codec->driver->reg_cache_size ||
snd_soc_codec_volatile_register(codec, reg)) {
if (codec->cache_only)
return -1;

return codec->hw_read(codec, reg);
}

return cache[reg];
}

Expand All @@ -101,13 +114,12 @@ static int snd_soc_7_9_write(struct snd_soc_codec *codec, unsigned int reg,
u8 data[2];
int ret;

BUG_ON(codec->driver->volatile_register);

data[0] = (reg << 1) | ((value >> 8) & 0x0001);
data[1] = value & 0x00ff;

if (reg < codec->driver->reg_cache_size)
cache[reg] = value;
if (!snd_soc_codec_volatile_register(codec, reg) &&
reg < codec->driver->reg_cache_size)
cache[reg] = value;

if (codec->cache_only) {
codec->cache_sync = 1;
Expand Down Expand Up @@ -161,14 +173,13 @@ static int snd_soc_8_8_write(struct snd_soc_codec *codec, unsigned int reg,
u8 *cache = codec->reg_cache;
u8 data[2];

BUG_ON(codec->driver->volatile_register);

reg &= 0xff;
data[0] = reg;
data[1] = value & 0xff;

if (reg < codec->driver->reg_cache_size)
cache[reg] = value;
if (!snd_soc_codec_volatile_register(codec, value) &&
reg < codec->driver->reg_cache_size)
cache[reg] = value;

if (codec->cache_only) {
codec->cache_sync = 1;
Expand All @@ -187,9 +198,16 @@ static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec,
unsigned int reg)
{
u8 *cache = codec->reg_cache;

reg &= 0xff;
if (reg >= codec->driver->reg_cache_size)
return -1;
if (reg >= codec->driver->reg_cache_size ||
snd_soc_codec_volatile_register(codec, reg)) {
if (codec->cache_only)
return -1;

return codec->hw_read(codec, reg);
}

return cache[reg];
}

Expand Down Expand Up @@ -344,8 +362,14 @@ static unsigned int snd_soc_16_8_read(struct snd_soc_codec *codec,
u8 *cache = codec->reg_cache;

reg &= 0xff;
if (reg >= codec->driver->reg_cache_size)
return -1;
if (reg >= codec->driver->reg_cache_size ||
snd_soc_codec_volatile_register(codec, reg)) {
if (codec->cache_only)
return -1;

return codec->hw_read(codec, reg);
}

return cache[reg];
}

Expand All @@ -356,15 +380,14 @@ static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg,
u8 data[3];
int ret;

BUG_ON(codec->driver->volatile_register);

data[0] = (reg >> 8) & 0xff;
data[1] = reg & 0xff;
data[2] = value;

reg &= 0xff;
if (reg < codec->driver->reg_cache_size)
cache[reg] = value;
if (!snd_soc_codec_volatile_register(codec, reg) &&
reg < codec->driver->reg_cache_size)
cache[reg] = value;

if (codec->cache_only) {
codec->cache_sync = 1;
Expand Down Expand Up @@ -475,8 +498,9 @@ static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg,
data[2] = (value >> 8) & 0xff;
data[3] = value & 0xff;

if (reg < codec->driver->reg_cache_size)
cache[reg] = value;
if (!snd_soc_codec_volatile_register(codec, reg) &&
reg < codec->driver->reg_cache_size)
cache[reg] = value;

if (codec->cache_only) {
codec->cache_sync = 1;
Expand Down

0 comments on commit db49c14

Please sign in to comment.