aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitris Papastamos <dp@opensource.wolfsonmicro.com>2011-03-22 06:36:59 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2011-03-26 13:44:48 -0400
commitb8cbc195202d05efcda6af81c669577e3cb793e5 (patch)
tree38587960091cb042d17dc3d1a10fa1985db8ffd7
parent26e9984cbcdde100e5af15382f2297fef1ce7804 (diff)
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: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> Acked-by: Liam Girdwood <lrg@ti.com> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r--sound/soc/soc-cache.c114
1 files changed, 18 insertions, 96 deletions
diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c
index 4ee473d6057a..abb0243f3adf 100644
--- a/sound/soc/soc-cache.c
+++ b/sound/soc/soc-cache.c
@@ -47,20 +47,19 @@ static int do_hw_write(struct snd_soc_codec *codec, unsigned int reg,
47 return -EIO; 47 return -EIO;
48} 48}
49 49
50static unsigned int snd_soc_4_12_read(struct snd_soc_codec *codec, 50static unsigned int do_hw_read(struct snd_soc_codec *codec, unsigned int reg)
51 unsigned int reg)
52{ 51{
53 int ret; 52 int ret;
54 unsigned int val; 53 unsigned int val;
55 54
56 if (reg >= codec->driver->reg_cache_size || 55 if (reg >= codec->driver->reg_cache_size ||
57 snd_soc_codec_volatile_register(codec, reg) || 56 snd_soc_codec_volatile_register(codec, reg) ||
58 codec->cache_bypass) { 57 codec->cache_bypass) {
59 if (codec->cache_only) 58 if (codec->cache_only)
60 return -1; 59 return -1;
61 60
62 BUG_ON(!codec->hw_read); 61 BUG_ON(!codec->hw_read);
63 return codec->hw_read(codec, reg); 62 return codec->hw_read(codec, reg);
64 } 63 }
65 64
66 ret = snd_soc_cache_read(codec, reg, &val); 65 ret = snd_soc_cache_read(codec, reg, &val);
@@ -69,6 +68,12 @@ static unsigned int snd_soc_4_12_read(struct snd_soc_codec *codec,
69 return val; 68 return val;
70} 69}
71 70
71static unsigned int snd_soc_4_12_read(struct snd_soc_codec *codec,
72 unsigned int reg)
73{
74 return do_hw_read(codec, reg);
75}
76
72static int snd_soc_4_12_write(struct snd_soc_codec *codec, unsigned int reg, 77static int snd_soc_4_12_write(struct snd_soc_codec *codec, unsigned int reg,
73 unsigned int value) 78 unsigned int value)
74{ 79{
@@ -113,23 +118,7 @@ static int snd_soc_4_12_spi_write(void *control_data, const char *data,
113static unsigned int snd_soc_7_9_read(struct snd_soc_codec *codec, 118static unsigned int snd_soc_7_9_read(struct snd_soc_codec *codec,
114 unsigned int reg) 119 unsigned int reg)
115{ 120{
116 int ret; 121 return do_hw_read(codec, reg);
117 unsigned int val;
118
119 if (reg >= codec->driver->reg_cache_size ||
120 snd_soc_codec_volatile_register(codec, reg) ||
121 codec->cache_bypass) {
122 if (codec->cache_only)
123 return -1;
124
125 BUG_ON(!codec->hw_read);
126 return codec->hw_read(codec, reg);
127 }
128
129 ret = snd_soc_cache_read(codec, reg, &val);
130 if (ret < 0)
131 return -1;
132 return val;
133} 122}
134 123
135static int snd_soc_7_9_write(struct snd_soc_codec *codec, unsigned int reg, 124static 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,
188static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec, 177static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec,
189 unsigned int reg) 178 unsigned int reg)
190{ 179{
191 int ret; 180 return do_hw_read(codec, reg);
192 unsigned int val;
193
194 reg &= 0xff;
195 if (reg >= codec->driver->reg_cache_size ||
196 snd_soc_codec_volatile_register(codec, reg) ||
197 codec->cache_bypass) {
198 if (codec->cache_only)
199 return -1;
200
201 BUG_ON(!codec->hw_read);
202 return codec->hw_read(codec, reg);
203 }
204
205 ret = snd_soc_cache_read(codec, reg, &val);
206 if (ret < 0)
207 return -1;
208 return val;
209} 181}
210 182
211#if defined(CONFIG_SPI_MASTER) 183#if defined(CONFIG_SPI_MASTER)
@@ -253,23 +225,7 @@ static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg,
253static unsigned int snd_soc_8_16_read(struct snd_soc_codec *codec, 225static unsigned int snd_soc_8_16_read(struct snd_soc_codec *codec,
254 unsigned int reg) 226 unsigned int reg)
255{ 227{
256 int ret; 228 return do_hw_read(codec, reg);
257 unsigned int val;
258
259 if (reg >= codec->driver->reg_cache_size ||
260 snd_soc_codec_volatile_register(codec, reg) ||
261 codec->cache_bypass) {
262 if (codec->cache_only)
263 return -1;
264
265 BUG_ON(!codec->hw_read);
266 return codec->hw_read(codec, reg);
267 }
268
269 ret = snd_soc_cache_read(codec, reg, &val);
270 if (ret < 0)
271 return -1;
272 return val;
273} 229}
274 230
275#if defined(CONFIG_SPI_MASTER) 231#if defined(CONFIG_SPI_MASTER)
@@ -389,24 +345,7 @@ static unsigned int snd_soc_16_8_read_i2c(struct snd_soc_codec *codec,
389static unsigned int snd_soc_16_8_read(struct snd_soc_codec *codec, 345static unsigned int snd_soc_16_8_read(struct snd_soc_codec *codec,
390 unsigned int reg) 346 unsigned int reg)
391{ 347{
392 int ret; 348 return do_hw_read(codec, reg);
393 unsigned int val;
394
395 reg &= 0xff;
396 if (reg >= codec->driver->reg_cache_size ||
397 snd_soc_codec_volatile_register(codec, reg) ||
398 codec->cache_bypass) {
399 if (codec->cache_only)
400 return -1;
401
402 BUG_ON(!codec->hw_read);
403 return codec->hw_read(codec, reg);
404 }
405
406 ret = snd_soc_cache_read(codec, reg, &val);
407 if (ret < 0)
408 return -1;
409 return val;
410} 349}
411 350
412static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg, 351static 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,
473static unsigned int snd_soc_16_16_read(struct snd_soc_codec *codec, 412static unsigned int snd_soc_16_16_read(struct snd_soc_codec *codec,
474 unsigned int reg) 413 unsigned int reg)
475{ 414{
476 int ret; 415 return do_hw_read(codec, reg);
477 unsigned int val;
478
479 if (reg >= codec->driver->reg_cache_size ||
480 snd_soc_codec_volatile_register(codec, reg) ||
481 codec->cache_bypass) {
482 if (codec->cache_only)
483 return -1;
484
485 BUG_ON(!codec->hw_read);
486 return codec->hw_read(codec, reg);
487 }
488
489 ret = snd_soc_cache_read(codec, reg, &val);
490 if (ret < 0)
491 return -1;
492
493 return val;
494} 416}
495 417
496static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg, 418static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg,