ASoC: Factor out 7 bit register 9 bit data SPI write
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Fri, 10 Jul 2009 22:28:16 +0000 (23:28 +0100)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Mon, 3 Aug 2009 15:59:16 +0000 (16:59 +0100)
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>
sound/soc/codecs/wm8510.c
sound/soc/codecs/wm8728.c
sound/soc/codecs/wm8731.c
sound/soc/codecs/wm8750.c
sound/soc/codecs/wm8988.c
sound/soc/soc-cache.c

index 4ca724ff4c6e0425fc69dd054745e6bd7fd5c0cc..bcd6a40171dcbb621805d3810decee331fa2265a 100644 (file)
@@ -737,30 +737,6 @@ static struct spi_driver wm8510_spi_driver = {
        .probe          = wm8510_spi_probe,
        .remove         = __devexit_p(wm8510_spi_remove),
 };
-
-static int wm8510_spi_write(struct spi_device *spi, const char *data, int len)
-{
-       struct spi_transfer t;
-       struct spi_message m;
-       u8 msg[2];
-
-       if (len <= 0)
-               return 0;
-
-       msg[0] = data[0];
-       msg[1] = data[1];
-
-       spi_message_init(&m);
-       memset(&t, 0, (sizeof t));
-
-       t.tx_buf = &msg[0];
-       t.len = len;
-
-       spi_message_add_tail(&t, &m);
-       spi_sync(spi, &m);
-
-       return len;
-}
 #endif /* CONFIG_SPI_MASTER */
 
 static int wm8510_probe(struct platform_device *pdev)
@@ -790,7 +766,6 @@ static int wm8510_probe(struct platform_device *pdev)
 #endif
 #if defined(CONFIG_SPI_MASTER)
        if (setup->spi) {
-               codec->hw_write = (hw_write_t)wm8510_spi_write;
                ret = spi_register_driver(&wm8510_spi_driver);
                if (ret != 0)
                        printk(KERN_ERR "can't add spi driver");
index a28630de9c91ef77e9c3cd8fe1487facfe6bd7fa..16e969a762c3934bd9af11b5e240a0f5aa1f0b75 100644 (file)
@@ -425,30 +425,6 @@ static struct spi_driver wm8728_spi_driver = {
        .probe          = wm8728_spi_probe,
        .remove         = __devexit_p(wm8728_spi_remove),
 };
-
-static int wm8728_spi_write(struct spi_device *spi, const char *data, int len)
-{
-       struct spi_transfer t;
-       struct spi_message m;
-       u8 msg[2];
-
-       if (len <= 0)
-               return 0;
-
-       msg[0] = data[0];
-       msg[1] = data[1];
-
-       spi_message_init(&m);
-       memset(&t, 0, (sizeof t));
-
-       t.tx_buf = &msg[0];
-       t.len = len;
-
-       spi_message_add_tail(&t, &m);
-       spi_sync(spi, &m);
-
-       return len;
-}
 #endif /* CONFIG_SPI_MASTER */
 
 static int wm8728_probe(struct platform_device *pdev)
@@ -478,7 +454,6 @@ static int wm8728_probe(struct platform_device *pdev)
 #endif
 #if defined(CONFIG_SPI_MASTER)
        if (setup->spi) {
-               codec->hw_write = (hw_write_t)wm8728_spi_write;
                ret = spi_register_driver(&wm8728_spi_driver);
                if (ret != 0)
                        printk(KERN_ERR "can't add spi driver");
index 27fc942a5ced035a8e1cdb946e3cc2878ca7e491..6232afd907efdbfb4e3bf68cb60b45cf6b855803 100644 (file)
@@ -591,30 +591,6 @@ static void wm8731_unregister(struct wm8731_priv *wm8731)
 }
 
 #if defined(CONFIG_SPI_MASTER)
-static int wm8731_spi_write(struct spi_device *spi, const char *data, int len)
-{
-       struct spi_transfer t;
-       struct spi_message m;
-       u8 msg[2];
-
-       if (len <= 0)
-               return 0;
-
-       msg[0] = data[0];
-       msg[1] = data[1];
-
-       spi_message_init(&m);
-       memset(&t, 0, (sizeof t));
-
-       t.tx_buf = &msg[0];
-       t.len = len;
-
-       spi_message_add_tail(&t, &m);
-       spi_sync(spi, &m);
-
-       return len;
-}
-
 static int __devinit wm8731_spi_probe(struct spi_device *spi)
 {
        struct snd_soc_codec *codec;
@@ -626,7 +602,6 @@ static int __devinit wm8731_spi_probe(struct spi_device *spi)
 
        codec = &wm8731->codec;
        codec->control_data = spi;
-       codec->hw_write = (hw_write_t)wm8731_spi_write;
        codec->dev = &spi->dev;
 
        dev_set_drvdata(&spi->dev, wm8731);
index e6422b161678552aff5a4b62930e3d51997edd13..4ba1e7e93fb4dbfc99cb28e04e7baa82318102f3 100644 (file)
@@ -911,30 +911,6 @@ static struct spi_driver wm8750_spi_driver = {
        .probe          = wm8750_spi_probe,
        .remove         = __devexit_p(wm8750_spi_remove),
 };
-
-static int wm8750_spi_write(struct spi_device *spi, const char *data, int len)
-{
-       struct spi_transfer t;
-       struct spi_message m;
-       u8 msg[2];
-
-       if (len <= 0)
-               return 0;
-
-       msg[0] = data[0];
-       msg[1] = data[1];
-
-       spi_message_init(&m);
-       memset(&t, 0, (sizeof t));
-
-       t.tx_buf = &msg[0];
-       t.len = len;
-
-       spi_message_add_tail(&t, &m);
-       spi_sync(spi, &m);
-
-       return len;
-}
 #endif
 
 static int wm8750_probe(struct platform_device *pdev)
@@ -973,7 +949,6 @@ static int wm8750_probe(struct platform_device *pdev)
 #endif
 #if defined(CONFIG_SPI_MASTER)
        if (setup->spi) {
-               codec->hw_write = (hw_write_t)wm8750_spi_write;
                ret = spi_register_driver(&wm8750_spi_driver);
                if (ret != 0)
                        printk(KERN_ERR "can't add spi driver");
index 7486d3ec787ef5d582429cde4a392ecf78b9991d..1c8653523c8c08898aa9b831e917624335d76716 100644 (file)
@@ -979,30 +979,6 @@ static struct i2c_driver wm8988_i2c_driver = {
 #endif
 
 #if defined(CONFIG_SPI_MASTER)
-static int wm8988_spi_write(struct spi_device *spi, const char *data, int len)
-{
-       struct spi_transfer t;
-       struct spi_message m;
-       u8 msg[2];
-
-       if (len <= 0)
-               return 0;
-
-       msg[0] = data[0];
-       msg[1] = data[1];
-
-       spi_message_init(&m);
-       memset(&t, 0, (sizeof t));
-
-       t.tx_buf = &msg[0];
-       t.len = len;
-
-       spi_message_add_tail(&t, &m);
-       spi_sync(spi, &m);
-
-       return len;
-}
-
 static int __devinit wm8988_spi_probe(struct spi_device *spi)
 {
        struct wm8988_priv *wm8988;
@@ -1013,7 +989,6 @@ static int __devinit wm8988_spi_probe(struct spi_device *spi)
                return -ENOMEM;
 
        codec = &wm8988->codec;
-       codec->hw_write = (hw_write_t)wm8988_spi_write;
        codec->control_data = spi;
        codec->dev = &spi->dev;
 
index ab058b81163304ce599c4c1b5c1664db24dc0c8e..56ec3f22bf1c26711dd44f78c01f1189aaf4c4f4 100644 (file)
@@ -12,6 +12,7 @@
  */
 
 #include <linux/i2c.h>
+#include <linux/spi/spi.h>
 #include <sound/soc.h>
 
 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,
                return -EIO;
 }
 
+#if defined(CONFIG_SPI_MASTER)
+static int snd_soc_7_9_spi_write(void *control_data, const char *data,
+                                int len)
+{
+       struct spi_device *spi = control_data;
+       struct spi_transfer t;
+       struct spi_message m;
+       u8 msg[2];
+
+       if (len <= 0)
+               return 0;
+
+       msg[0] = data[0];
+       msg[1] = data[1];
+
+       spi_message_init(&m);
+       memset(&t, 0, (sizeof t));
+
+       t.tx_buf = &msg[0];
+       t.len = len;
+
+       spi_message_add_tail(&t, &m);
+       spi_sync(spi, &m);
+
+       return len;
+}
+#else
+#define snd_soc_7_9_spi_write NULL
+#endif
+
 static int snd_soc_8_16_write(struct snd_soc_codec *codec, unsigned int reg,
                              unsigned int value)
 {
@@ -115,12 +146,12 @@ static struct {
        int addr_bits;
        int data_bits;
        int (*write)(struct snd_soc_codec *codec, unsigned int, unsigned int);
+       int (*spi_write)(void *, const char *, int);
        unsigned int (*read)(struct snd_soc_codec *, unsigned int);
        unsigned int (*i2c_read)(struct snd_soc_codec *, unsigned int);
 } io_types[] = {
-       { 7, 9, snd_soc_7_9_write, snd_soc_7_9_read },
-       { 8, 16,
-         snd_soc_8_16_write, snd_soc_8_16_read,
+       { 7, 9, snd_soc_7_9_write, snd_soc_7_9_spi_write, snd_soc_7_9_read },
+       { 8, 16, snd_soc_8_16_write, NULL, snd_soc_8_16_read,
          snd_soc_8_16_read_i2c },
 };
 
@@ -177,6 +208,8 @@ int snd_soc_codec_set_cache_io(struct snd_soc_codec *codec,
                break;
 
        case SND_SOC_SPI:
+               if (io_types[i].spi_write)
+                       codec->hw_write = io_types[i].spi_write;
                break;
        }