aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2008-10-07 06:56:20 -0400
committerTakashi Iwai <tiwai@suse.de>2008-10-12 20:17:15 -0400
commit5e357952b186555afa0ff4da87431c16503a8ad7 (patch)
tree44834045234ae528e128a2ccbe73ff368ce283f0
parentdd0c0c805d932f34e87ee3c2db9eaee0974bfef8 (diff)
ALSA: ASoC: Add WM8510 SPI support
Implement SPI support for WM8510, cut'n'pasting from the support for WM8731 contributed by Cliff Cai and Alan Horstmann since the wire format is the same for both codecs. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--sound/soc/codecs/wm8510.c70
-rw-r--r--sound/soc/codecs/wm8510.h1
2 files changed, 69 insertions, 2 deletions
diff --git a/sound/soc/codecs/wm8510.c b/sound/soc/codecs/wm8510.c
index 9a37c8d95ed2..16768a5acc4c 100644
--- a/sound/soc/codecs/wm8510.c
+++ b/sound/soc/codecs/wm8510.c
@@ -18,6 +18,7 @@
18#include <linux/pm.h> 18#include <linux/pm.h>
19#include <linux/i2c.h> 19#include <linux/i2c.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/spi/spi.h>
21#include <sound/core.h> 22#include <sound/core.h>
22#include <sound/pcm.h> 23#include <sound/pcm.h>
23#include <sound/pcm_params.h> 24#include <sound/pcm_params.h>
@@ -747,6 +748,62 @@ err_driver:
747} 748}
748#endif 749#endif
749 750
751#if defined(CONFIG_SPI_MASTER)
752static int __devinit wm8510_spi_probe(struct spi_device *spi)
753{
754 struct snd_soc_device *socdev = wm8510_socdev;
755 struct snd_soc_codec *codec = socdev->codec;
756 int ret;
757
758 codec->control_data = spi;
759
760 ret = wm8510_init(socdev);
761 if (ret < 0)
762 dev_err(&spi->dev, "failed to initialise WM8510\n");
763
764 return ret;
765}
766
767static int __devexit wm8510_spi_remove(struct spi_device *spi)
768{
769 return 0;
770}
771
772static struct spi_driver wm8510_spi_driver = {
773 .driver = {
774 .name = "wm8510",
775 .bus = &spi_bus_type,
776 .owner = THIS_MODULE,
777 },
778 .probe = wm8510_spi_probe,
779 .remove = __devexit_p(wm8510_spi_remove),
780};
781
782static int wm8510_spi_write(struct spi_device *spi, const char *data, int len)
783{
784 struct spi_transfer t;
785 struct spi_message m;
786 u8 msg[2];
787
788 if (len <= 0)
789 return 0;
790
791 msg[0] = data[0];
792 msg[1] = data[1];
793
794 spi_message_init(&m);
795 memset(&t, 0, (sizeof t));
796
797 t.tx_buf = &msg[0];
798 t.len = len;
799
800 spi_message_add_tail(&t, &m);
801 spi_sync(spi, &m);
802
803 return len;
804}
805#endif /* CONFIG_SPI_MASTER */
806
750static int wm8510_probe(struct platform_device *pdev) 807static int wm8510_probe(struct platform_device *pdev)
751{ 808{
752 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 809 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
@@ -772,8 +829,14 @@ static int wm8510_probe(struct platform_device *pdev)
772 codec->hw_write = (hw_write_t)i2c_master_send; 829 codec->hw_write = (hw_write_t)i2c_master_send;
773 ret = wm8510_add_i2c_device(pdev, setup); 830 ret = wm8510_add_i2c_device(pdev, setup);
774 } 831 }
775#else 832#endif
776 /* Add other interfaces here */ 833#if defined(CONFIG_SPI_MASTER)
834 if (setup->spi) {
835 codec->hw_write = (hw_write_t)wm8510_spi_write;
836 ret = spi_register_driver(&wm8510_spi_driver);
837 if (ret != 0)
838 printk(KERN_ERR "can't add spi driver");
839 }
777#endif 840#endif
778 841
779 if (ret != 0) 842 if (ret != 0)
@@ -796,6 +859,9 @@ static int wm8510_remove(struct platform_device *pdev)
796 i2c_unregister_device(codec->control_data); 859 i2c_unregister_device(codec->control_data);
797 i2c_del_driver(&wm8510_i2c_driver); 860 i2c_del_driver(&wm8510_i2c_driver);
798#endif 861#endif
862#if defined(CONFIG_SPI_MASTER)
863 spi_unregister_driver(&wm8510_spi_driver);
864#endif
799 kfree(codec); 865 kfree(codec);
800 866
801 return 0; 867 return 0;
diff --git a/sound/soc/codecs/wm8510.h b/sound/soc/codecs/wm8510.h
index c53683960456..bdefcf5c69ff 100644
--- a/sound/soc/codecs/wm8510.h
+++ b/sound/soc/codecs/wm8510.h
@@ -94,6 +94,7 @@
94#define WM8510_MCLKDIV_12 (7 << 5) 94#define WM8510_MCLKDIV_12 (7 << 5)
95 95
96struct wm8510_setup_data { 96struct wm8510_setup_data {
97 int spi;
97 int i2c_bus; 98 int i2c_bus;
98 unsigned short i2c_address; 99 unsigned short i2c_address;
99}; 100};