ASoC: SSM2602: add SPI support
authorMike Frysinger <vapier@gentoo.org>
Thu, 7 Apr 2011 06:05:11 +0000 (02:05 -0400)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Fri, 8 Apr 2011 00:24:24 +0000 (09:24 +0900)
The ssm2602 codec has a SPI interface as well as I2C, so add the simple
bit of glue to make it usable.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
sound/soc/codecs/Kconfig
sound/soc/codecs/ssm2602.c

index 78da05b5e5ebf4d0e4428cc0a1f80d3e15597837..ee7374e8e97e4bfd3aa72c9b0dd8cad9035f00a6 100644 (file)
@@ -40,7 +40,7 @@ config SND_SOC_ALL_CODECS
        select SND_SOC_SGTL5000 if I2C
        select SND_SOC_SN95031 if INTEL_SCU_IPC
        select SND_SOC_SPDIF
-       select SND_SOC_SSM2602 if I2C
+       select SND_SOC_SSM2602 if SND_SOC_I2C_AND_SPI
        select SND_SOC_STAC9766 if SND_SOC_AC97_BUS
        select SND_SOC_TLV320AIC23 if I2C
        select SND_SOC_TLV320AIC26 if SPI_MASTER
index 8a2b52fa4a7ea0ab4bbbc61030dc0ffd2a250335..7e2194975360ed357daad656ed2387c1c60108b6 100644 (file)
@@ -32,6 +32,7 @@
 #include <linux/delay.h>
 #include <linux/pm.h>
 #include <linux/i2c.h>
+#include <linux/spi/spi.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 #include <sound/core.h>
@@ -556,6 +557,43 @@ static struct snd_soc_codec_driver soc_codec_dev_ssm2602 = {
        .reg_cache_default = ssm2602_reg,
 };
 
+#if defined(CONFIG_SPI_MASTER)
+static int __devinit ssm2602_spi_probe(struct spi_device *spi)
+{
+       struct ssm2602_priv *ssm2602;
+       int ret;
+
+       ssm2602 = kzalloc(sizeof(struct ssm2602_priv), GFP_KERNEL);
+       if (ssm2602 == NULL)
+               return -ENOMEM;
+
+       spi_set_drvdata(spi, ssm2602);
+       ssm2602->control_type = SND_SOC_SPI;
+
+       ret = snd_soc_register_codec(&spi->dev,
+                       &soc_codec_dev_ssm2602, &ssm2602_dai, 1);
+       if (ret < 0)
+               kfree(ssm2602);
+       return ret;
+}
+
+static int __devexit ssm2602_spi_remove(struct spi_device *spi)
+{
+       snd_soc_unregister_codec(&spi->dev);
+       kfree(spi_get_drvdata(spi));
+       return 0;
+}
+
+static struct spi_driver ssm2602_spi_driver = {
+       .driver = {
+               .name   = "ssm2602",
+               .owner  = THIS_MODULE,
+       },
+       .probe          = ssm2602_spi_probe,
+       .remove         = __devexit_p(ssm2602_spi_remove),
+};
+#endif
+
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
 /*
  * ssm2602 2 wire address is determined by GPIO5
@@ -612,19 +650,29 @@ static struct i2c_driver ssm2602_i2c_driver = {
 static int __init ssm2602_modinit(void)
 {
        int ret = 0;
+
+#if defined(CONFIG_SPI_MASTER)
+       ret = spi_register_driver(&ssm2602_spi_driver);
+       if (ret)
+               return ret;
+#endif
+
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
        ret = i2c_add_driver(&ssm2602_i2c_driver);
-       if (ret != 0) {
-               printk(KERN_ERR "Failed to register SSM2602 I2C driver: %d\n",
-                      ret);
-       }
+       if (ret)
+               return ret;
 #endif
+
        return ret;
 }
 module_init(ssm2602_modinit);
 
 static void __exit ssm2602_exit(void)
 {
+#if defined(CONFIG_SPI_MASTER)
+       spi_unregister_driver(&ssm2602_spi_driver);
+#endif
+
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
        i2c_del_driver(&ssm2602_i2c_driver);
 #endif