aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitris Papastamos <dp@opensource.wolfsonmicro.com>2010-10-04 06:25:13 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2010-10-05 12:56:34 -0400
commitf479fd93d4028afccf155dec736c6d49cde92571 (patch)
treefcb2e2ace000bd2590199ec839ca9cf90c79df2d
parentbb5a027026db86b0c676104b2e3f6cc4768d1ac0 (diff)
ASoC: soc-cache: Add spi_write support for all I/O types
Ensure that all drivers that use SPI and I2C will work properly by providing SPI write functions for all different I/O types. Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com> Acked-by: Liam Girdwood <lrg@slimlogic.co.uk> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
-rw-r--r--sound/soc/soc-cache.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c
index 62f1e2b776c4..d214f02cbb65 100644
--- a/sound/soc/soc-cache.c
+++ b/sound/soc/soc-cache.c
@@ -211,6 +211,36 @@ static unsigned int snd_soc_8_8_read(struct snd_soc_codec *codec,
211 return cache[reg]; 211 return cache[reg];
212} 212}
213 213
214#if defined(CONFIG_SPI_MASTER)
215static int snd_soc_8_8_spi_write(void *control_data, const char *data,
216 int len)
217{
218 struct spi_device *spi = control_data;
219 struct spi_transfer t;
220 struct spi_message m;
221 u8 msg[2];
222
223 if (len <= 0)
224 return 0;
225
226 msg[0] = data[0];
227 msg[1] = data[1];
228
229 spi_message_init(&m);
230 memset(&t, 0, (sizeof t));
231
232 t.tx_buf = &msg[0];
233 t.len = len;
234
235 spi_message_add_tail(&t, &m);
236 spi_sync(spi, &m);
237
238 return len;
239}
240#else
241#define snd_soc_8_8_spi_write NULL
242#endif
243
214static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg, 244static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg,
215 unsigned int value) 245 unsigned int value)
216{ 246{
@@ -254,6 +284,37 @@ static unsigned int snd_soc_8_16_read(struct snd_soc_codec *codec,
254 } 284 }
255} 285}
256 286
287#if defined(CONFIG_SPI_MASTER)
288static int snd_soc_8_16_spi_write(void *control_data, const char *data,
289 int len)
290{
291 struct spi_device *spi = control_data;
292 struct spi_transfer t;
293 struct spi_message m;
294 u8 msg[3];
295
296 if (len <= 0)
297 return 0;
298
299 msg[0] = data[0];
300 msg[1] = data[1];
301 msg[2] = data[2];
302
303 spi_message_init(&m);
304 memset(&t, 0, (sizeof t));
305
306 t.tx_buf = &msg[0];
307 t.len = len;
308
309 spi_message_add_tail(&t, &m);
310 spi_sync(spi, &m);
311
312 return len;
313}
314#else
315#define snd_soc_8_16_spi_write NULL
316#endif
317
257#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE)) 318#if defined(CONFIG_I2C) || (defined(CONFIG_I2C_MODULE) && defined(MODULE))
258static unsigned int snd_soc_8_8_read_i2c(struct snd_soc_codec *codec, 319static unsigned int snd_soc_8_8_read_i2c(struct snd_soc_codec *codec,
259 unsigned int r) 320 unsigned int r)
@@ -518,6 +579,38 @@ static int snd_soc_16_16_write(struct snd_soc_codec *codec, unsigned int reg,
518 return -EIO; 579 return -EIO;
519} 580}
520 581
582#if defined(CONFIG_SPI_MASTER)
583static int snd_soc_16_16_spi_write(void *control_data, const char *data,
584 int len)
585{
586 struct spi_device *spi = control_data;
587 struct spi_transfer t;
588 struct spi_message m;
589 u8 msg[4];
590
591 if (len <= 0)
592 return 0;
593
594 msg[0] = data[0];
595 msg[1] = data[1];
596 msg[2] = data[2];
597 msg[3] = data[3];
598
599 spi_message_init(&m);
600 memset(&t, 0, (sizeof t));
601
602 t.tx_buf = &msg[0];
603 t.len = len;
604
605 spi_message_add_tail(&t, &m);
606 spi_sync(spi, &m);
607
608 return len;
609}
610#else
611#define snd_soc_16_16_spi_write NULL
612#endif
613
521static struct { 614static struct {
522 int addr_bits; 615 int addr_bits;
523 int data_bits; 616 int data_bits;
@@ -540,11 +633,13 @@ static struct {
540 .addr_bits = 8, .data_bits = 8, 633 .addr_bits = 8, .data_bits = 8,
541 .write = snd_soc_8_8_write, .read = snd_soc_8_8_read, 634 .write = snd_soc_8_8_write, .read = snd_soc_8_8_read,
542 .i2c_read = snd_soc_8_8_read_i2c, 635 .i2c_read = snd_soc_8_8_read_i2c,
636 .spi_write = snd_soc_8_8_spi_write,
543 }, 637 },
544 { 638 {
545 .addr_bits = 8, .data_bits = 16, 639 .addr_bits = 8, .data_bits = 16,
546 .write = snd_soc_8_16_write, .read = snd_soc_8_16_read, 640 .write = snd_soc_8_16_write, .read = snd_soc_8_16_read,
547 .i2c_read = snd_soc_8_16_read_i2c, 641 .i2c_read = snd_soc_8_16_read_i2c,
642 .spi_write = snd_soc_8_16_spi_write,
548 }, 643 },
549 { 644 {
550 .addr_bits = 16, .data_bits = 8, 645 .addr_bits = 16, .data_bits = 8,
@@ -556,6 +651,7 @@ static struct {
556 .addr_bits = 16, .data_bits = 16, 651 .addr_bits = 16, .data_bits = 16,
557 .write = snd_soc_16_16_write, .read = snd_soc_16_16_read, 652 .write = snd_soc_16_16_write, .read = snd_soc_16_16_read,
558 .i2c_read = snd_soc_16_16_read_i2c, 653 .i2c_read = snd_soc_16_16_read_i2c,
654 .spi_write = snd_soc_16_16_spi_write,
559 }, 655 },
560}; 656};
561 657