diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2009-07-10 18:28:16 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2009-08-03 11:59:16 -0400 |
commit | 27ded041f03026e8c6be9efc626e11ddfb4620c1 (patch) | |
tree | f8b156b2c31a97805c8341fd215648e989e12430 /sound/soc/soc-cache.c | |
parent | 8d50e447d19fec64adebeef55f2b60d695435412 (diff) |
ASoC: Factor out 7 bit register 9 bit data SPI write
This converts all the Wolfson drivers using this format (the only devices
that do) except WM8753 to use it.
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 | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c index ab058b811633..56ec3f22bf1c 100644 --- a/sound/soc/soc-cache.c +++ b/sound/soc/soc-cache.c | |||
@@ -12,6 +12,7 @@ | |||
12 | */ | 12 | */ |
13 | 13 | ||
14 | #include <linux/i2c.h> | 14 | #include <linux/i2c.h> |
15 | #include <linux/spi/spi.h> | ||
15 | #include <sound/soc.h> | 16 | #include <sound/soc.h> |
16 | 17 | ||
17 | static unsigned int snd_soc_7_9_read(struct snd_soc_codec *codec, | 18 | static unsigned int snd_soc_7_9_read(struct snd_soc_codec *codec, |
@@ -46,6 +47,36 @@ static int snd_soc_7_9_write(struct snd_soc_codec *codec, unsigned int reg, | |||
46 | return -EIO; | 47 | return -EIO; |
47 | } | 48 | } |
48 | 49 | ||
50 | #if defined(CONFIG_SPI_MASTER) | ||
51 | static int snd_soc_7_9_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[0]; | ||
63 | msg[1] = data[1]; | ||
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_7_9_spi_write NULL | ||
78 | #endif | ||
79 | |||
49 | static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg, | 80 | static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg, |
50 | unsigned int value) | 81 | unsigned int value) |
51 | { | 82 | { |
@@ -115,12 +146,12 @@ static struct { | |||
115 | int addr_bits; | 146 | int addr_bits; |
116 | int data_bits; | 147 | int data_bits; |
117 | int (*write)(struct snd_soc_codec *codec, unsigned int, unsigned int); | 148 | int (*write)(struct snd_soc_codec *codec, unsigned int, unsigned int); |
149 | int (*spi_write)(void *, const char *, int); | ||
118 | unsigned int (*read)(struct snd_soc_codec *, unsigned int); | 150 | unsigned int (*read)(struct snd_soc_codec *, unsigned int); |
119 | unsigned int (*i2c_read)(struct snd_soc_codec *, unsigned int); | 151 | unsigned int (*i2c_read)(struct snd_soc_codec *, unsigned int); |
120 | } io_types[] = { | 152 | } io_types[] = { |
121 | { 7, 9, snd_soc_7_9_write, snd_soc_7_9_read }, | 153 | { 7, 9, snd_soc_7_9_write, snd_soc_7_9_spi_write, snd_soc_7_9_read }, |
122 | { 8, 16, | 154 | { 8, 16, snd_soc_8_16_write, NULL, snd_soc_8_16_read, |
123 | snd_soc_8_16_write, snd_soc_8_16_read, | ||
124 | snd_soc_8_16_read_i2c }, | 155 | snd_soc_8_16_read_i2c }, |
125 | }; | 156 | }; |
126 | 157 | ||
@@ -177,6 +208,8 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec, | |||
177 | break; | 208 | break; |
178 | 209 | ||
179 | case SND_SOC_SPI: | 210 | case SND_SOC_SPI: |
211 | if (io_types[i].spi_write) | ||
212 | codec->hw_write = io_types[i].spi_write; | ||
180 | break; | 213 | break; |
181 | } | 214 | } |
182 | 215 | ||