Commit b8cbc195 authored by Dimitris Papastamos's avatar Dimitris Papastamos Committed by Mark Brown

ASoC: soc-cache: Factor-out the hw_read() specific code

The handling of all snd_soc_x_y_read() functions is similar.
Factor it out into a separate function and update all callers.
Signed-off-by: default avatarDimitris Papastamos <dp@opensource.wolfsonmicro.com>
Acked-by: default avatarLiam Girdwood <lrg@ti.com>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 26e9984c
...@@ -47,8 +47,7 @@ static int do_hw_write(struct snd_soc_codec *codec, unsigned int reg, ...@@ -47,8 +47,7 @@ static int do_hw_write(struct snd_soc_codec *codec, unsigned int reg,
return -EIO; return -EIO;
} }
static unsigned int snd_soc_4_12_read(struct snd_soc_codec *codec, static unsigned int do_hw_read(struct snd_soc_codec *codec, unsigned int reg)
unsigned int reg)
{ {
int ret; int ret;
unsigned int val; unsigned int val;
...@@ -69,6 +68,12 @@ static unsigned int snd_soc_4_12_read(struct snd_soc_codec *codec, ...@@ -69,6 +68,12 @@ static unsigned int snd_soc_4_12_read(struct snd_soc_codec *codec,
return val; return val;
} }
static unsigned int snd_soc_4_12_read(struct snd_soc_codec *codec,
unsigned int reg)
{
return do_hw_read(codec, reg);
}
static int snd_soc_4_12_write(struct snd_soc_codec *codec, unsigned int reg, static int snd_soc_4_12_write(struct snd_soc_codec *codec, unsigned int reg,
unsigned int value) unsigned int value)
{ {
...@@ -113,23 +118,7 @@ static int snd_soc_4_12_spi_write(void *control_data, const char *data, ...@@ -113,23 +118,7 @@ static int snd_soc_4_12_spi_write(void *control_data, const char *data,
static unsigned int snd_soc_7_9_read(struct snd_soc_codec *codec, static unsigned int snd_soc_7_9_read(struct snd_soc_codec *codec,
unsigned int reg) unsigned int reg)
{ {
int ret; return do_hw_read(codec, reg);
unsigned int val;
if (reg >= codec->driver->reg_cache_size ||
snd_soc_codec_volatile_register(codec, reg) ||
codec->cache_bypass) {
if (codec->cache_only)
return -1;
BUG_ON(!codec->hw_read);
return codec->hw_read(codec, reg);
}
ret = snd_soc_cache_read(codec, reg, &val);
if (ret < 0)
return -1;
return val;
} }
static int snd_soc_7_9_write(struct snd_soc_codec *codec, unsigned int reg, static int snd_soc_7_9_write(struct snd_soc_codec *codec, unsigned int reg,
...@@ -188,24 +177,7 @@ static int snd_soc_8_8_write(struct snd_soc_codec *codec, unsigned int reg, ...@@ -188,24 +177,7 @@ static int snd_soc_8_8_write(struct snd_soc_codec *codec, unsigned int reg,
static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec, static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec,
unsigned int reg) unsigned int reg)
{ {
int ret; return do_hw_read(codec, reg);
unsigned int val;
reg &= 0xff;
if (reg >= codec->driver->reg_cache_size ||
snd_soc_codec_volatile_register(codec, reg) ||
codec->cache_bypass) {
if (codec->cache_only)
return -1;
BUG_ON(!codec->hw_read);
return codec->hw_read(codec, reg);
}
ret = snd_soc_cache_read(codec, reg, &val);
if (ret < 0)
return -1;
return val;
} }
#if defined(CONFIG_SPI_MASTER) #if defined(CONFIG_SPI_MASTER)
...@@ -253,23 +225,7 @@ static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg, ...@@ -253,23 +225,7 @@ static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg,
static unsigned int snd_soc_8_16_read(struct snd_soc_codec *codec, static unsigned int snd_soc_8_16_read(struct snd_soc_codec *codec,
unsigned int reg) unsigned int reg)
{ {
int ret; return do_hw_read(codec, reg);
unsigned int val;
if (reg >= codec->driver->reg_cache_size ||
snd_soc_codec_volatile_register(codec, reg) ||
codec->cache_bypass) {
if (codec->cache_only)
return -1;
BUG_ON(!codec->hw_read);
return codec->hw_read(codec, reg);
}
ret = snd_soc_cache_read(codec, reg, &val);
if (ret < 0)
return -1;
return val;
} }
#if defined(CONFIG_SPI_MASTER) #if defined(CONFIG_SPI_MASTER)
...@@ -389,24 +345,7 @@ static unsigned int snd_soc_16_8_read_i2c(struct snd_soc_codec *codec, ...@@ -389,24 +345,7 @@ static unsigned int snd_soc_16_8_read_i2c(struct snd_soc_codec *codec,
static unsigned int snd_soc_16_8_read(struct snd_soc_codec *codec, static unsigned int snd_soc_16_8_read(struct snd_soc_codec *codec,
unsigned int reg) unsigned int reg)
{ {
int ret; return do_hw_read(codec, reg);
unsigned int val;
reg &= 0xff;
if (reg >= codec->driver->reg_cache_size ||
snd_soc_codec_volatile_register(codec, reg) ||
codec->cache_bypass) {
if (codec->cache_only)
return -1;
BUG_ON(!codec->hw_read);
return codec->hw_read(codec, reg);
}
ret = snd_soc_cache_read(codec, reg, &val);
if (ret < 0)
return -1;
return val;
} }
static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg, static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg,
...@@ -473,24 +412,7 @@ static unsigned int snd_soc_16_16_read_i2c(struct snd_soc_codec *codec, ...@@ -473,24 +412,7 @@ static unsigned int snd_soc_16_16_read_i2c(struct snd_soc_codec *codec,
static unsigned int snd_soc_16_16_read(struct snd_soc_codec *codec, static unsigned int snd_soc_16_16_read(struct snd_soc_codec *codec,
unsigned int reg) unsigned int reg)
{ {
int ret; return do_hw_read(codec, reg);
unsigned int val;
if (reg >= codec->driver->reg_cache_size ||
snd_soc_codec_volatile_register(codec, reg) ||
codec->cache_bypass) {
if (codec->cache_only)
return -1;
BUG_ON(!codec->hw_read);
return codec->hw_read(codec, reg);
}
ret = snd_soc_cache_read(codec, reg, &val);
if (ret < 0)
return -1;
return val;
} }
static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg, static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment