diff options
author | Dimitris Papastamos <dp@opensource.wolfsonmicro.com> | 2011-03-22 06:36:58 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2011-03-26 13:44:38 -0400 |
commit | 26e9984cbcdde100e5af15382f2297fef1ce7804 (patch) | |
tree | d6fdbb586764deb691db4cbfab419249a805e080 /sound/soc/soc-cache.c | |
parent | 67850a892bf627e1c627bc8d0bcd84b90ecc9d7f (diff) |
ASoC: soc-cache: Factor-out the hw_write() specific code
The handling of all snd_soc_x_y_write() functions is similar.
Factor it out into a separate function and update all functions
to use it.
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>
Diffstat (limited to 'sound/soc/soc-cache.c')
-rw-r--r-- | sound/soc/soc-cache.c | 153 |
1 files changed, 33 insertions, 120 deletions
diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c index 8bcd4e1cee91..4ee473d6057a 100644 --- a/sound/soc/soc-cache.c +++ b/sound/soc/soc-cache.c | |||
@@ -20,6 +20,33 @@ | |||
20 | 20 | ||
21 | #include <trace/events/asoc.h> | 21 | #include <trace/events/asoc.h> |
22 | 22 | ||
23 | static int do_hw_write(struct snd_soc_codec *codec, unsigned int reg, | ||
24 | unsigned int value, const void *data, int len) | ||
25 | { | ||
26 | int ret; | ||
27 | |||
28 | if (!snd_soc_codec_volatile_register(codec, reg) && | ||
29 | reg < codec->driver->reg_cache_size && | ||
30 | !codec->cache_bypass) { | ||
31 | ret = snd_soc_cache_write(codec, reg, value); | ||
32 | if (ret < 0) | ||
33 | return -1; | ||
34 | } | ||
35 | |||
36 | if (codec->cache_only) { | ||
37 | codec->cache_sync = 1; | ||
38 | return 0; | ||
39 | } | ||
40 | |||
41 | ret = codec->hw_write(codec->control_data, data, len); | ||
42 | if (ret == len) | ||
43 | return 0; | ||
44 | if (ret < 0) | ||
45 | return ret; | ||
46 | else | ||
47 | return -EIO; | ||
48 | } | ||
49 | |||
23 | static unsigned int snd_soc_4_12_read(struct snd_soc_codec *codec, | 50 | static unsigned int snd_soc_4_12_read(struct snd_soc_codec *codec, |
24 | unsigned int reg) | 51 | unsigned int reg) |
25 | { | 52 | { |
@@ -46,31 +73,11 @@ static int snd_soc_4_12_write(struct snd_soc_codec *codec, unsigned int reg, | |||
46 | unsigned int value) | 73 | unsigned int value) |
47 | { | 74 | { |
48 | u8 data[2]; | 75 | u8 data[2]; |
49 | int ret; | ||
50 | 76 | ||
51 | data[0] = (reg << 4) | ((value >> 8) & 0x000f); | 77 | data[0] = (reg << 4) | ((value >> 8) & 0x000f); |
52 | data[1] = value & 0x00ff; | 78 | data[1] = value & 0x00ff; |
53 | 79 | ||
54 | if (!snd_soc_codec_volatile_register(codec, reg) && | 80 | return do_hw_write(codec, reg, value, data, 2); |
55 | reg < codec->driver->reg_cache_size && | ||
56 | !codec->cache_bypass) { | ||
57 | ret = snd_soc_cache_write(codec, reg, value); | ||
58 | if (ret < 0) | ||
59 | return -1; | ||
60 | } | ||
61 | |||
62 | if (codec->cache_only) { | ||
63 | codec->cache_sync = 1; | ||
64 | return 0; | ||
65 | } | ||
66 | |||
67 | ret = codec->hw_write(codec->control_data, data, 2); | ||
68 | if (ret == 2) | ||
69 | return 0; | ||
70 | if (ret < 0) | ||
71 | return ret; | ||
72 | else | ||
73 | return -EIO; | ||
74 | } | 81 | } |
75 | 82 | ||
76 | #if defined(CONFIG_SPI_MASTER) | 83 | #if defined(CONFIG_SPI_MASTER) |
@@ -129,31 +136,11 @@ static int snd_soc_7_9_write(struct snd_soc_codec *codec, unsigned int reg, | |||
129 | unsigned int value) | 136 | unsigned int value) |
130 | { | 137 | { |
131 | u8 data[2]; | 138 | u8 data[2]; |
132 | int ret; | ||
133 | 139 | ||
134 | data[0] = (reg << 1) | ((value >> 8) & 0x0001); | 140 | data[0] = (reg << 1) | ((value >> 8) & 0x0001); |
135 | data[1] = value & 0x00ff; | 141 | data[1] = value & 0x00ff; |
136 | 142 | ||
137 | if (!snd_soc_codec_volatile_register(codec, reg) && | 143 | return do_hw_write(codec, reg, value, data, 2); |
138 | reg < codec->driver->reg_cache_size && | ||
139 | !codec->cache_bypass) { | ||
140 | ret = snd_soc_cache_write(codec, reg, value); | ||
141 | if (ret < 0) | ||
142 | return -1; | ||
143 | } | ||
144 | |||
145 | if (codec->cache_only) { | ||
146 | codec->cache_sync = 1; | ||
147 | return 0; | ||
148 | } | ||
149 | |||
150 | ret = codec->hw_write(codec->control_data, data, 2); | ||
151 | if (ret == 2) | ||
152 | return 0; | ||
153 | if (ret < 0) | ||
154 | return ret; | ||
155 | else | ||
156 | return -EIO; | ||
157 | } | 144 | } |
158 | 145 | ||
159 | #if defined(CONFIG_SPI_MASTER) | 146 | #if defined(CONFIG_SPI_MASTER) |
@@ -190,29 +177,12 @@ static int snd_soc_8_8_write(struct snd_soc_codec *codec, unsigned int reg, | |||
190 | unsigned int value) | 177 | unsigned int value) |
191 | { | 178 | { |
192 | u8 data[2]; | 179 | u8 data[2]; |
193 | int ret; | ||
194 | 180 | ||
195 | reg &= 0xff; | 181 | reg &= 0xff; |
196 | data[0] = reg; | 182 | data[0] = reg; |
197 | data[1] = value & 0xff; | 183 | data[1] = value & 0xff; |
198 | 184 | ||
199 | if (!snd_soc_codec_volatile_register(codec, reg) && | 185 | return do_hw_write(codec, reg, value, data, 2); |
200 | reg < codec->driver->reg_cache_size && | ||
201 | !codec->cache_bypass) { | ||
202 | ret = snd_soc_cache_write(codec, reg, value); | ||
203 | if (ret < 0) | ||
204 | return -1; | ||
205 | } | ||
206 | |||
207 | if (codec->cache_only) { | ||
208 | codec->cache_sync = 1; | ||
209 | return 0; | ||
210 | } | ||
211 | |||
212 | if (codec->hw_write(codec->control_data, data, 2) == 2) | ||
213 | return 0; | ||
214 | else | ||
215 | return -EIO; | ||
216 | } | 186 | } |
217 | 187 | ||
218 | static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec, | 188 | static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec, |
@@ -272,29 +242,12 @@ static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg, | |||
272 | unsigned int value) | 242 | unsigned int value) |
273 | { | 243 | { |
274 | u8 data[3]; | 244 | u8 data[3]; |
275 | int ret; | ||
276 | 245 | ||
277 | data[0] = reg; | 246 | data[0] = reg; |
278 | data[1] = (value >> 8) & 0xff; | 247 | data[1] = (value >> 8) & 0xff; |
279 | data[2] = value & 0xff; | 248 | data[2] = value & 0xff; |
280 | 249 | ||
281 | if (!snd_soc_codec_volatile_register(codec, reg) && | 250 | return do_hw_write(codec, reg, value, data, 3); |
282 | reg < codec->driver->reg_cache_size && | ||
283 | !codec->cache_bypass) { | ||
284 | ret = snd_soc_cache_write(codec, reg, value); | ||
285 | if (ret < 0) | ||
286 | return -1; | ||
287 | } | ||
288 | |||
289 | if (codec->cache_only) { | ||
290 | codec->cache_sync = 1; | ||
291 | return 0; | ||
292 | } | ||
293 | |||
294 | if (codec->hw_write(codec->control_data, data, 3) == 3) | ||
295 | return 0; | ||
296 | else | ||
297 | return -EIO; | ||
298 | } | 251 | } |
299 | 252 | ||
300 | static unsigned int snd_soc_8_16_read(struct snd_soc_codec *codec, | 253 | static unsigned int snd_soc_8_16_read(struct snd_soc_codec *codec, |
@@ -460,33 +413,13 @@ static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg, | |||
460 | unsigned int value) | 413 | unsigned int value) |
461 | { | 414 | { |
462 | u8 data[3]; | 415 | u8 data[3]; |
463 | int ret; | ||
464 | 416 | ||
465 | data[0] = (reg >> 8) & 0xff; | 417 | data[0] = (reg >> 8) & 0xff; |
466 | data[1] = reg & 0xff; | 418 | data[1] = reg & 0xff; |
467 | data[2] = value; | 419 | data[2] = value; |
468 | |||
469 | reg &= 0xff; | 420 | reg &= 0xff; |
470 | if (!snd_soc_codec_volatile_register(codec, reg) && | ||
471 | reg < codec->driver->reg_cache_size && | ||
472 | !codec->cache_bypass) { | ||
473 | ret = snd_soc_cache_write(codec, reg, value); | ||
474 | if (ret < 0) | ||
475 | return -1; | ||
476 | } | ||
477 | |||
478 | if (codec->cache_only) { | ||
479 | codec->cache_sync = 1; | ||
480 | return 0; | ||
481 | } | ||
482 | 421 | ||
483 | ret = codec->hw_write(codec->control_data, data, 3); | 422 | return do_hw_write(codec, reg, value, data, 3); |
484 | if (ret == 3) | ||
485 | return 0; | ||
486 | if (ret < 0) | ||
487 | return ret; | ||
488 | else | ||
489 | return -EIO; | ||
490 | } | 423 | } |
491 | 424 | ||
492 | #if defined(CONFIG_SPI_MASTER) | 425 | #if defined(CONFIG_SPI_MASTER) |
@@ -564,33 +497,13 @@ static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg, | |||
564 | unsigned int value) | 497 | unsigned int value) |
565 | { | 498 | { |
566 | u8 data[4]; | 499 | u8 data[4]; |
567 | int ret; | ||
568 | 500 | ||
569 | data[0] = (reg >> 8) & 0xff; | 501 | data[0] = (reg >> 8) & 0xff; |
570 | data[1] = reg & 0xff; | 502 | data[1] = reg & 0xff; |
571 | data[2] = (value >> 8) & 0xff; | 503 | data[2] = (value >> 8) & 0xff; |
572 | data[3] = value & 0xff; | 504 | data[3] = value & 0xff; |
573 | 505 | ||
574 | if (!snd_soc_codec_volatile_register(codec, reg) && | 506 | return do_hw_write(codec, reg, value, data, 4); |
575 | reg < codec->driver->reg_cache_size && | ||
576 | !codec->cache_bypass) { | ||
577 | ret = snd_soc_cache_write(codec, reg, value); | ||
578 | if (ret < 0) | ||
579 | return -1; | ||
580 | } | ||
581 | |||
582 | if (codec->cache_only) { | ||
583 | codec->cache_sync = 1; | ||
584 | return 0; | ||
585 | } | ||
586 | |||
587 | ret = codec->hw_write(codec->control_data, data, 4); | ||
588 | if (ret == 4) | ||
589 | return 0; | ||
590 | if (ret < 0) | ||
591 | return ret; | ||
592 | else | ||
593 | return -EIO; | ||
594 | } | 507 | } |
595 | 508 | ||
596 | #if defined(CONFIG_SPI_MASTER) | 509 | #if defined(CONFIG_SPI_MASTER) |