aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-cache.c
diff options
context:
space:
mode:
authorBarry Song <21cnbao@gmail.com>2010-01-26 22:46:17 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2010-01-27 05:42:59 -0500
commit63b62ab0d52c736b3274b294df962e0a4b7aae79 (patch)
tree1a26ae8ddc231a1d6061617abe1b5afcb46fc336 /sound/soc/soc-cache.c
parente473b847424bd215b686cbc1e781e82c904ee967 (diff)
ASoC: ad1836: use soc-cache framework for codec registers access
Signed-off-by: Barry Song <Barry.Song@analog.com> Acked-by: Liam Girdwood <lrg@slimlogic.co.uk> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/soc-cache.c')
-rw-r--r--sound/soc/soc-cache.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c
index 02c235711bb8..cde7b63de113 100644
--- a/sound/soc/soc-cache.c
+++ b/sound/soc/soc-cache.c
@@ -15,6 +15,68 @@
15#include <linux/spi/spi.h> 15#include <linux/spi/spi.h>
16#include <sound/soc.h> 16#include <sound/soc.h>
17 17
18static unsigned int snd_soc_4_12_read(struct snd_soc_codec *codec,
19 unsigned int reg)
20{
21 u16 *cache = codec->reg_cache;
22 if (reg >= codec->reg_cache_size)
23 return -1;
24 return cache[reg];
25}
26
27static int snd_soc_4_12_write(struct snd_soc_codec *codec, unsigned int reg,
28 unsigned int value)
29{
30 u16 *cache = codec->reg_cache;
31 u8 data[2];
32 int ret;
33
34 BUG_ON(codec->volatile_register);
35
36 data[0] = (reg << 4) | ((value >> 8) & 0x000f);
37 data[1] = value & 0x00ff;
38
39 if (reg < codec->reg_cache_size)
40 cache[reg] = value;
41 ret = codec->hw_write(codec->control_data, data, 2);
42 if (ret == 2)
43 return 0;
44 if (ret < 0)
45 return ret;
46 else
47 return -EIO;
48}
49
50#if defined(CONFIG_SPI_MASTER)
51static int snd_soc_4_12_spi_write(void *control_data, const char *data,
52 int len)
53{
54 struct spi_device *spi = control_data;
55 struct spi_transfer t;
56 struct spi_message m;
57 u8 msg[2];
58
59 if (len <= 0)
60 return 0;
61
62 msg[0] = data[1];
63 msg[1] = data[0];
64
65 spi_message_init(&m);
66 memset(&t, 0, (sizeof t));
67
68 t.tx_buf = &msg[0];
69 t.len = len;
70
71 spi_message_add_tail(&t, &m);
72 spi_sync(spi, &m);
73
74 return len;
75}
76#else
77#define snd_soc_4_12_spi_write NULL
78#endif
79
18static unsigned int snd_soc_7_9_read(struct snd_soc_codec *codec, 80static unsigned int snd_soc_7_9_read(struct snd_soc_codec *codec,
19 unsigned int reg) 81 unsigned int reg)
20{ 82{
@@ -180,6 +242,11 @@ static struct {
180 unsigned int (*i2c_read)(struct snd_soc_codec *, unsigned int); 242 unsigned int (*i2c_read)(struct snd_soc_codec *, unsigned int);
181} io_types[] = { 243} io_types[] = {
182 { 244 {
245 .addr_bits = 4, .data_bits = 12,
246 .write = snd_soc_4_12_write, .read = snd_soc_4_12_read,
247 .spi_write = snd_soc_4_12_spi_write,
248 },
249 {
183 .addr_bits = 7, .data_bits = 9, 250 .addr_bits = 7, .data_bits = 9,
184 .write = snd_soc_7_9_write, .read = snd_soc_7_9_read, 251 .write = snd_soc_7_9_write, .read = snd_soc_7_9_read,
185 .spi_write = snd_soc_7_9_spi_write, 252 .spi_write = snd_soc_7_9_spi_write,