aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitris Papastamos <dp@opensource.wolfsonmicro.com>2011-03-22 06:37:03 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2011-03-26 13:44:14 -0400
commit5fb609d435f0679ed322ddeb1fdafe6142463fdf (patch)
treec0da5a9fca23fab307305acf6be95272eb2e8c52
parentf3594f5c5c489d159f6d487a889d9d68ca4c0123 (diff)
ASoC: soc-cache: Introduce raw bulk write support
As it has become more common to have to write firmware or similar large chunks of data to the hardware, add a function to perform raw bulk writes that bypass the cache. This only handles volatile registers as we should avoid getting out of sync with the actual cache. 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>
-rw-r--r--include/sound/soc.h3
-rw-r--r--sound/soc/soc-cache.c39
-rw-r--r--sound/soc/soc-core.c7
3 files changed, 49 insertions, 0 deletions
diff --git a/include/sound/soc.h b/include/sound/soc.h
index bfa4836ea107..2f2a51fe78e9 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -543,6 +543,7 @@ struct snd_soc_codec {
543 unsigned int (*hw_read)(struct snd_soc_codec *, unsigned int); 543 unsigned int (*hw_read)(struct snd_soc_codec *, unsigned int);
544 unsigned int (*read)(struct snd_soc_codec *, unsigned int); 544 unsigned int (*read)(struct snd_soc_codec *, unsigned int);
545 int (*write)(struct snd_soc_codec *, unsigned int, unsigned int); 545 int (*write)(struct snd_soc_codec *, unsigned int, unsigned int);
546 int (*bulk_write_raw)(struct snd_soc_codec *, unsigned int, const void *, size_t);
546 void *reg_cache; 547 void *reg_cache;
547 const void *reg_def_copy; 548 const void *reg_def_copy;
548 const struct snd_soc_cache_ops *cache_ops; 549 const struct snd_soc_cache_ops *cache_ops;
@@ -814,6 +815,8 @@ struct soc_enum {
814unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg); 815unsigned int snd_soc_read(struct snd_soc_codec *codec, unsigned int reg);
815unsigned int snd_soc_write(struct snd_soc_codec *codec, 816unsigned int snd_soc_write(struct snd_soc_codec *codec,
816 unsigned int reg, unsigned int val); 817 unsigned int reg, unsigned int val);
818unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
819 unsigned int reg, const void *data, size_t len);
817 820
818/* device driver data */ 821/* device driver data */
819 822
diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c
index 9f6737413a6e..8bcd4e1cee91 100644
--- a/sound/soc/soc-cache.c
+++ b/sound/soc/soc-cache.c
@@ -625,6 +625,44 @@ static int snd_soc_16_16_spi_write(void *control_data, const char *data,
625#define snd_soc_16_16_spi_write NULL 625#define snd_soc_16_16_spi_write NULL
626#endif 626#endif
627 627
628/* Primitive bulk write support for soc-cache. The data pointed to by `data' needs
629 * to already be in the form the hardware expects including any leading register specific
630 * data. Any data written through this function will not go through the cache as it
631 * only handles writing to volatile or out of bounds registers.
632 */
633static int snd_soc_hw_bulk_write_raw(struct snd_soc_codec *codec, unsigned int reg,
634 const void *data, size_t len)
635{
636 int ret;
637
638 /* Ensure that the base register is volatile. Subsequently
639 * any other register that is touched by this routine should be
640 * volatile as well to ensure that we don't get out of sync with
641 * the cache.
642 */
643 if (!snd_soc_codec_volatile_register(codec, reg)
644 && reg < codec->driver->reg_cache_size)
645 return -EINVAL;
646
647 switch (codec->control_type) {
648 case SND_SOC_I2C:
649 ret = i2c_master_send(codec->control_data, data, len);
650 break;
651 case SND_SOC_SPI:
652 ret = do_spi_write(codec->control_data, data, len);
653 break;
654 default:
655 BUG();
656 }
657
658 if (ret == len)
659 return 0;
660 if (ret < 0)
661 return ret;
662 else
663 return -EIO;
664}
665
628static struct { 666static struct {
629 int addr_bits; 667 int addr_bits;
630 int data_bits; 668 int data_bits;
@@ -708,6 +746,7 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
708 746
709 codec->write = io_types[i].write; 747 codec->write = io_types[i].write;
710 codec->read = io_types[i].read; 748 codec->read = io_types[i].read;
749 codec->bulk_write_raw = snd_soc_hw_bulk_write_raw;
711 750
712 switch (control) { 751 switch (control) {
713 case SND_SOC_CUSTOM: 752 case SND_SOC_CUSTOM:
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 4dda58926bc5..636328e868e8 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -2228,6 +2228,13 @@ unsigned int snd_soc_write(struct snd_soc_codec *codec,
2228} 2228}
2229EXPORT_SYMBOL_GPL(snd_soc_write); 2229EXPORT_SYMBOL_GPL(snd_soc_write);
2230 2230
2231unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
2232 unsigned int reg, const void *data, size_t len)
2233{
2234 return codec->bulk_write_raw(codec, reg, data, len);
2235}
2236EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw);
2237
2231/** 2238/**
2232 * snd_soc_update_bits - update codec register bits 2239 * snd_soc_update_bits - update codec register bits
2233 * @codec: audio codec 2240 * @codec: audio codec