aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-io.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/soc-io.c')
-rw-r--r--sound/soc/soc-io.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/sound/soc/soc-io.c b/sound/soc/soc-io.c
index cca490c80589..a62f7dd4ba96 100644
--- a/sound/soc/soc-io.c
+++ b/sound/soc/soc-io.c
@@ -205,6 +205,25 @@ static unsigned int snd_soc_16_8_read_i2c(struct snd_soc_codec *codec,
205#define snd_soc_16_8_read_i2c NULL 205#define snd_soc_16_8_read_i2c NULL
206#endif 206#endif
207 207
208#if defined(CONFIG_SPI_MASTER)
209static unsigned int snd_soc_16_8_read_spi(struct snd_soc_codec *codec,
210 unsigned int r)
211{
212 struct spi_device *spi = codec->control_data;
213
214 const u16 reg = cpu_to_be16(r | 0x100);
215 u8 data;
216 int ret;
217
218 ret = spi_write_then_read(spi, &reg, 2, &data, 1);
219 if (ret < 0)
220 return 0;
221 return data;
222}
223#else
224#define snd_soc_16_8_read_spi NULL
225#endif
226
208static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg, 227static int snd_soc_16_8_write(struct snd_soc_codec *codec, unsigned int reg,
209 unsigned int value) 228 unsigned int value)
210{ 229{
@@ -295,6 +314,7 @@ static struct {
295 int (*write)(struct snd_soc_codec *codec, unsigned int, unsigned int); 314 int (*write)(struct snd_soc_codec *codec, unsigned int, unsigned int);
296 unsigned int (*read)(struct snd_soc_codec *, unsigned int); 315 unsigned int (*read)(struct snd_soc_codec *, unsigned int);
297 unsigned int (*i2c_read)(struct snd_soc_codec *, unsigned int); 316 unsigned int (*i2c_read)(struct snd_soc_codec *, unsigned int);
317 unsigned int (*spi_read)(struct snd_soc_codec *, unsigned int);
298} io_types[] = { 318} io_types[] = {
299 { 319 {
300 .addr_bits = 4, .data_bits = 12, 320 .addr_bits = 4, .data_bits = 12,
@@ -318,6 +338,7 @@ static struct {
318 .addr_bits = 16, .data_bits = 8, 338 .addr_bits = 16, .data_bits = 8,
319 .write = snd_soc_16_8_write, 339 .write = snd_soc_16_8_write,
320 .i2c_read = snd_soc_16_8_read_i2c, 340 .i2c_read = snd_soc_16_8_read_i2c,
341 .spi_read = snd_soc_16_8_read_spi,
321 }, 342 },
322 { 343 {
323 .addr_bits = 16, .data_bits = 16, 344 .addr_bits = 16, .data_bits = 16,
@@ -383,6 +404,8 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
383#ifdef CONFIG_SPI_MASTER 404#ifdef CONFIG_SPI_MASTER
384 codec->hw_write = do_spi_write; 405 codec->hw_write = do_spi_write;
385#endif 406#endif
407 if (io_types[i].spi_read)
408 codec->hw_read = io_types[i].spi_read;
386 409
387 codec->control_data = container_of(codec->dev, 410 codec->control_data = container_of(codec->dev,
388 struct spi_device, 411 struct spi_device,