ASoC: Add more natural support for no-DMA DAIs
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Wed, 27 Apr 2011 17:16:32 +0000 (18:16 +0100)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Wed, 27 Apr 2011 21:33:11 +0000 (22:33 +0100)
Since we can now support multiple platforms allow machines to not specify
a platform in a DAI link. Since the rest of the code requires that we have
a struct device for all objects we do this by substituting in a dummy
device that we register automatically.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Jassi Brar <jassisinghbrar@gmail.com>
Acked-by: Liam Girdwood <lrg@ti.com>
sound/soc/soc-core.c
sound/soc/soc-utils.c

index 9dc1311..16be3e5 100644 (file)
@@ -1299,6 +1299,7 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
        struct snd_soc_codec *codec;
        struct snd_soc_platform *platform;
        struct snd_soc_dai *codec_dai, *cpu_dai;
+       const char *platform_name;
 
        if (rtd->complete)
                return 1;
@@ -1351,13 +1352,18 @@ find_codec:
                        dai_link->codec_name);
 
 find_platform:
-       /* do we already have the CODEC DAI for this link ? */
-       if (rtd->platform) {
+       /* do we need a platform? */
+       if (rtd->platform)
                goto out;
-       }
-       /* no, then find CPU DAI from registered DAIs*/
+
+       /* if there's no platform we match on the empty platform */
+       platform_name = dai_link->platform_name;
+       if (!platform_name)
+               platform_name = "snd-soc-dummy";
+
+       /* no, then find one from the set of registered platforms */
        list_for_each_entry(platform, &platform_list, list) {
-               if (!strcmp(platform->name, dai_link->platform_name)) {
+               if (!strcmp(platform->name, platform_name)) {
                        rtd->platform = platform;
                        goto out;
                }
index 3f45e6a..2865791 100644 (file)
@@ -13,6 +13,7 @@
  *  option) any later version.
  */
 
+#include <linux/platform_device.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
@@ -55,3 +56,57 @@ int snd_soc_params_to_bclk(struct snd_pcm_hw_params *params)
                return ret;
 }
 EXPORT_SYMBOL_GPL(snd_soc_params_to_bclk);
+
+static struct snd_soc_platform_driver dummy_platform;
+
+static __devinit int snd_soc_dummy_probe(struct platform_device *pdev)
+{
+       return snd_soc_register_platform(&pdev->dev, &dummy_platform);
+}
+
+static __devexit int snd_soc_dummy_remove(struct platform_device *pdev)
+{
+       snd_soc_unregister_platform(&pdev->dev);
+
+       return 0;
+}
+
+static struct platform_driver soc_dummy_driver = {
+       .driver = {
+               .name = "snd-soc-dummy",
+               .owner = THIS_MODULE,
+       },
+       .probe = snd_soc_dummy_probe,
+       .remove = __devexit_p(snd_soc_dummy_remove),
+};
+
+static struct platform_device *soc_dummy_dev;
+
+static int __init snd_soc_util_init(void)
+{
+       int ret;
+
+       soc_dummy_dev = platform_device_alloc("snd-soc-dummy", -1);
+       if (!soc_dummy_dev)
+               return -ENOMEM;
+
+       ret = platform_device_add(soc_dummy_dev);
+       if (ret != 0) {
+               platform_device_put(soc_dummy_dev);
+               return ret;
+       }
+
+       ret = platform_driver_register(&soc_dummy_driver);
+       if (ret != 0)
+               platform_device_unregister(soc_dummy_dev);
+
+       return ret;
+}
+module_init(snd_soc_util_init);
+
+static void __exit snd_soc_util_exit(void)
+{
+       platform_device_unregister(soc_dummy_dev);
+       platform_driver_unregister(&soc_dummy_driver);
+}
+module_exit(snd_soc_util_exit);