Merge branch 'for-5.6' of https://git.kernel.org/pub/scm/linux/kernel/git/broonie...
[platform/kernel/linux-rpi.git] / sound / soc / soc-core.c
index b17366b..e7e70b4 100644 (file)
@@ -365,19 +365,20 @@ EXPORT_SYMBOL_GPL(snd_soc_get_pcm_runtime);
 void snd_soc_close_delayed_work(struct snd_soc_pcm_runtime *rtd)
 {
        struct snd_soc_dai *codec_dai = rtd->codec_dai;
+       int playback = SNDRV_PCM_STREAM_PLAYBACK;
 
        mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
 
        dev_dbg(rtd->dev,
                "ASoC: pop wq checking: %s status: %s waiting: %s\n",
                codec_dai->driver->playback.stream_name,
-               codec_dai->playback_active ? "active" : "inactive",
+               codec_dai->stream_active[playback] ? "active" : "inactive",
                rtd->pop_wait ? "yes" : "no");
 
        /* are we waiting on this codec DAI stream */
        if (rtd->pop_wait == 1) {
                rtd->pop_wait = 0;
-               snd_soc_dapm_stream_event(rtd, SNDRV_PCM_STREAM_PLAYBACK,
+               snd_soc_dapm_stream_event(rtd, playback,
                                          SND_SOC_DAPM_STREAM_STOP);
        }
 
@@ -431,6 +432,7 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
        struct snd_soc_component *component;
        struct device *dev;
        int ret;
+       int stream;
 
        /*
         * for rtd->dev
@@ -465,10 +467,10 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 
        rtd->dev = dev;
        INIT_LIST_HEAD(&rtd->list);
-       INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].be_clients);
-       INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].be_clients);
-       INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_PLAYBACK].fe_clients);
-       INIT_LIST_HEAD(&rtd->dpcm[SNDRV_PCM_STREAM_CAPTURE].fe_clients);
+       for_each_pcm_streams(stream) {
+               INIT_LIST_HEAD(&rtd->dpcm[stream].be_clients);
+               INIT_LIST_HEAD(&rtd->dpcm[stream].fe_clients);
+       }
        dev_set_drvdata(dev, rtd);
        INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
 
@@ -482,6 +484,14 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
                goto free_rtd;
 
        /*
+        * for rtd->cpu_dais
+        */
+       rtd->cpu_dais = devm_kcalloc(dev, dai_link->num_cpus,
+                                    sizeof(struct snd_soc_dai *),
+                                    GFP_KERNEL);
+       if (!rtd->cpu_dais)
+               goto free_rtd;
+       /*
         * rtd remaining settings
         */
        rtd->card = card;
@@ -514,6 +524,7 @@ int snd_soc_suspend(struct device *dev)
        struct snd_soc_card *card = dev_get_drvdata(dev);
        struct snd_soc_component *component;
        struct snd_soc_pcm_runtime *rtd;
+       int playback = SNDRV_PCM_STREAM_PLAYBACK;
        int i;
 
        /* If the card is not initialized yet there is nothing to do */
@@ -536,10 +547,9 @@ int snd_soc_suspend(struct device *dev)
                if (rtd->dai_link->ignore_suspend)
                        continue;
 
-               for_each_rtd_codec_dai(rtd, i, dai) {
-                       if (dai->playback_active)
-                               snd_soc_dai_digital_mute(dai, 1,
-                                               SNDRV_PCM_STREAM_PLAYBACK);
+               for_each_rtd_codec_dais(rtd, i, dai) {
+                       if (dai->stream_active[playback])
+                               snd_soc_dai_digital_mute(dai, 1, playback);
                }
        }
 
@@ -558,17 +568,14 @@ int snd_soc_suspend(struct device *dev)
        snd_soc_flush_all_delayed_work(card);
 
        for_each_card_rtds(card, rtd) {
+               int stream;
 
                if (rtd->dai_link->ignore_suspend)
                        continue;
 
-               snd_soc_dapm_stream_event(rtd,
-                                         SNDRV_PCM_STREAM_PLAYBACK,
-                                         SND_SOC_DAPM_STREAM_SUSPEND);
-
-               snd_soc_dapm_stream_event(rtd,
-                                         SNDRV_PCM_STREAM_CAPTURE,
-                                         SND_SOC_DAPM_STREAM_SUSPEND);
+               for_each_pcm_streams(stream)
+                       snd_soc_dapm_stream_event(rtd, stream,
+                                                 SND_SOC_DAPM_STREAM_SUSPEND);
        }
 
        /* Recheck all endpoints too, their state is affected by suspend */
@@ -664,30 +671,27 @@ static void soc_resume_deferred(struct work_struct *work)
        }
 
        for_each_card_rtds(card, rtd) {
+               int stream;
 
                if (rtd->dai_link->ignore_suspend)
                        continue;
 
-               snd_soc_dapm_stream_event(rtd,
-                                         SNDRV_PCM_STREAM_PLAYBACK,
-                                         SND_SOC_DAPM_STREAM_RESUME);
-
-               snd_soc_dapm_stream_event(rtd,
-                                         SNDRV_PCM_STREAM_CAPTURE,
-                                         SND_SOC_DAPM_STREAM_RESUME);
+               for_each_pcm_streams(stream)
+                       snd_soc_dapm_stream_event(rtd, stream,
+                                                 SND_SOC_DAPM_STREAM_RESUME);
        }
 
        /* unmute any active DACs */
        for_each_card_rtds(card, rtd) {
                struct snd_soc_dai *dai;
+               int playback = SNDRV_PCM_STREAM_PLAYBACK;
 
                if (rtd->dai_link->ignore_suspend)
                        continue;
 
-               for_each_rtd_codec_dai(rtd, i, dai) {
-                       if (dai->playback_active)
-                               snd_soc_dai_digital_mute(dai, 0,
-                                               SNDRV_PCM_STREAM_PLAYBACK);
+               for_each_rtd_codec_dais(rtd, i, dai) {
+                       if (dai->stream_active[playback])
+                               snd_soc_dai_digital_mute(dai, 0, playback);
                }
        }
 
@@ -837,7 +841,7 @@ static int soc_dai_link_sanity_check(struct snd_soc_card *card,
                                     struct snd_soc_dai_link *link)
 {
        int i;
-       struct snd_soc_dai_link_component *codec, *platform;
+       struct snd_soc_dai_link_component *cpu, *codec, *platform;
 
        for_each_link_codecs(link, i, codec) {
                /*
@@ -886,44 +890,38 @@ static int soc_dai_link_sanity_check(struct snd_soc_card *card,
                        return -EPROBE_DEFER;
        }
 
-       /* FIXME */
-       if (link->num_cpus > 1) {
-               dev_err(card->dev,
-                       "ASoC: multi cpu is not yet supported %s\n",
-                       link->name);
-               return -EINVAL;
-       }
-
-       /*
-        * CPU device may be specified by either name or OF node, but
-        * can be left unspecified, and will be matched based on DAI
-        * name alone..
-        */
-       if (link->cpus->name && link->cpus->of_node) {
-               dev_err(card->dev,
-                       "ASoC: Neither/both cpu name/of_node are set for %s\n",
-                       link->name);
-               return -EINVAL;
-       }
+       for_each_link_cpus(link, i, cpu) {
+               /*
+                * CPU device may be specified by either name or OF node, but
+                * can be left unspecified, and will be matched based on DAI
+                * name alone..
+                */
+               if (cpu->name && cpu->of_node) {
+                       dev_err(card->dev,
+                               "ASoC: Neither/both cpu name/of_node are set for %s\n",
+                               link->name);
+                       return -EINVAL;
+               }
 
-       /*
-        * Defer card registration if cpu dai component is not added to
-        * component list.
-        */
-       if ((link->cpus->of_node || link->cpus->name) &&
-           !soc_find_component(link->cpus))
-               return -EPROBE_DEFER;
+               /*
+                * Defer card registration if cpu dai component is not added to
+                * component list.
+                */
+               if ((cpu->of_node || cpu->name) &&
+                   !soc_find_component(cpu))
+                       return -EPROBE_DEFER;
 
-       /*
-        * At least one of CPU DAI name or CPU device name/node must be
-        * specified
-        */
-       if (!link->cpus->dai_name &&
-           !(link->cpus->name || link->cpus->of_node)) {
-               dev_err(card->dev,
-                       "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
-                       link->name);
-               return -EINVAL;
+               /*
+                * At least one of CPU DAI name or CPU device name/node must be
+                * specified
+                */
+               if (!cpu->dai_name &&
+                   !(cpu->name || cpu->of_node)) {
+                       dev_err(card->dev,
+                               "ASoC: Neither cpu_dai_name nor cpu_name/of_node are set for %s\n",
+                               link->name);
+                       return -EINVAL;
+               }
        }
 
        return 0;
@@ -966,7 +964,7 @@ int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
                            struct snd_soc_dai_link *dai_link)
 {
        struct snd_soc_pcm_runtime *rtd;
-       struct snd_soc_dai_link_component *codec, *platform;
+       struct snd_soc_dai_link_component *codec, *platform, *cpu;
        struct snd_soc_component *component;
        int i, ret;
 
@@ -991,14 +989,19 @@ int snd_soc_add_pcm_runtime(struct snd_soc_card *card,
        if (!rtd)
                return -ENOMEM;
 
-       /* FIXME: we need multi CPU support in the future */
-       rtd->cpu_dai = snd_soc_find_dai(dai_link->cpus);
-       if (!rtd->cpu_dai) {
-               dev_info(card->dev, "ASoC: CPU DAI %s not registered\n",
-                        dai_link->cpus->dai_name);
-               goto _err_defer;
+       rtd->num_cpus = dai_link->num_cpus;
+       for_each_link_cpus(dai_link, i, cpu) {
+               rtd->cpu_dais[i] = snd_soc_find_dai(cpu);
+               if (!rtd->cpu_dais[i]) {
+                       dev_info(card->dev, "ASoC: CPU DAI %s not registered\n",
+                                cpu->dai_name);
+                       goto _err_defer;
+               }
+               snd_soc_rtd_add_component(rtd, rtd->cpu_dais[i]->component);
        }
-       snd_soc_rtd_add_component(rtd, rtd->cpu_dai->component);
+
+       /* Single cpu links expect cpu and cpu_dai in runtime data */
+       rtd->cpu_dai = rtd->cpu_dais[0];
 
        /* Find CODEC from registered CODECs */
        rtd->num_codecs = dai_link->num_codecs;
@@ -1118,7 +1121,8 @@ static int soc_init_pcm_runtime(struct snd_soc_card *card,
                        dai_link->stream_name, ret);
                return ret;
        }
-       ret = soc_dai_pcm_new(&cpu_dai, 1, rtd);
+       ret = soc_dai_pcm_new(rtd->cpu_dais,
+                             rtd->num_cpus, rtd);
        if (ret < 0)
                return ret;
        ret = soc_dai_pcm_new(rtd->codec_dais,
@@ -1320,23 +1324,25 @@ static void soc_remove_link_dais(struct snd_soc_card *card)
 {
        int i;
        struct snd_soc_dai *codec_dai;
+       struct snd_soc_dai *cpu_dai;
        struct snd_soc_pcm_runtime *rtd;
        int order;
 
        for_each_comp_order(order) {
                for_each_card_rtds(card, rtd) {
                        /* remove the CODEC DAI */
-                       for_each_rtd_codec_dai(rtd, i, codec_dai)
+                       for_each_rtd_codec_dais(rtd, i, codec_dai)
                                soc_remove_dai(codec_dai, order);
 
-                       soc_remove_dai(rtd->cpu_dai, order);
+                       for_each_rtd_cpu_dais(rtd, i, cpu_dai)
+                               soc_remove_dai(cpu_dai, order);
                }
        }
 }
 
 static int soc_probe_link_dais(struct snd_soc_card *card)
 {
-       struct snd_soc_dai *codec_dai;
+       struct snd_soc_dai *codec_dai, *cpu_dai;
        struct snd_soc_pcm_runtime *rtd;
        int i, order, ret;
 
@@ -1347,12 +1353,15 @@ static int soc_probe_link_dais(struct snd_soc_card *card)
                                "ASoC: probe %s dai link %d late %d\n",
                                card->name, rtd->num, order);
 
-                       ret = soc_probe_dai(rtd->cpu_dai, order);
-                       if (ret)
-                               return ret;
+                       /* probe the CPU DAI */
+                       for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
+                               ret = soc_probe_dai(cpu_dai, order);
+                               if (ret)
+                                       return ret;
+                       }
 
                        /* probe the CODEC DAI */
-                       for_each_rtd_codec_dai(rtd, i, codec_dai) {
+                       for_each_rtd_codec_dais(rtd, i, codec_dai) {
                                ret = soc_probe_dai(codec_dai, order);
                                if (ret)
                                        return ret;
@@ -1481,12 +1490,13 @@ static void soc_remove_aux_devices(struct snd_soc_card *card)
 int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
        unsigned int dai_fmt)
 {
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+       struct snd_soc_dai *cpu_dai;
        struct snd_soc_dai *codec_dai;
+       unsigned int inv_dai_fmt;
        unsigned int i;
        int ret;
 
-       for_each_rtd_codec_dai(rtd, i, codec_dai) {
+       for_each_rtd_codec_dais(rtd, i, codec_dai) {
                ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
                if (ret != 0 && ret != -ENOTSUPP) {
                        dev_warn(codec_dai->dev,
@@ -1499,33 +1509,33 @@ int snd_soc_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
         * Flip the polarity for the "CPU" end of a CODEC<->CODEC link
         * the component which has non_legacy_dai_naming is Codec
         */
-       if (cpu_dai->component->driver->non_legacy_dai_naming) {
-               unsigned int inv_dai_fmt;
-
-               inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_MASTER_MASK;
-               switch (dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
-               case SND_SOC_DAIFMT_CBM_CFM:
-                       inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
-                       break;
-               case SND_SOC_DAIFMT_CBM_CFS:
-                       inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
-                       break;
-               case SND_SOC_DAIFMT_CBS_CFM:
-                       inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
-                       break;
-               case SND_SOC_DAIFMT_CBS_CFS:
-                       inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
-                       break;
-               }
-
-               dai_fmt = inv_dai_fmt;
+       inv_dai_fmt = dai_fmt & ~SND_SOC_DAIFMT_MASTER_MASK;
+       switch (dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) {
+       case SND_SOC_DAIFMT_CBM_CFM:
+               inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFS;
+               break;
+       case SND_SOC_DAIFMT_CBM_CFS:
+               inv_dai_fmt |= SND_SOC_DAIFMT_CBS_CFM;
+               break;
+       case SND_SOC_DAIFMT_CBS_CFM:
+               inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFS;
+               break;
+       case SND_SOC_DAIFMT_CBS_CFS:
+               inv_dai_fmt |= SND_SOC_DAIFMT_CBM_CFM;
+               break;
        }
+       for_each_rtd_cpu_dais(rtd, i, cpu_dai) {
+               unsigned int fmt = dai_fmt;
 
-       ret = snd_soc_dai_set_fmt(cpu_dai, dai_fmt);
-       if (ret != 0 && ret != -ENOTSUPP) {
-               dev_warn(cpu_dai->dev,
-                        "ASoC: Failed to set DAI format: %d\n", ret);
-               return ret;
+               if (cpu_dai->component->driver->non_legacy_dai_naming)
+                       fmt = inv_dai_fmt;
+
+               ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
+               if (ret != 0 && ret != -ENOTSUPP) {
+                       dev_warn(cpu_dai->dev,
+                                "ASoC: Failed to set DAI format: %d\n", ret);
+                       return ret;
+               }
        }
 
        return 0;
@@ -3122,6 +3132,14 @@ int snd_soc_get_dai_name(struct of_phandle_args *args,
                        *dai_name = dai->driver->name;
                        if (!*dai_name)
                                *dai_name = pos->name;
+               } else if (ret) {
+                       /*
+                        * if another error than ENOTSUPP is returned go on and
+                        * check if another component is provided with the same
+                        * node. This may happen if a device provides several
+                        * components
+                        */
+                       continue;
                }
 
                break;