Merge remote-tracking branches 'asoc/topic/tlv', 'asoc/topic/tlv320aic23', 'asoc...
[cascardo/linux.git] / sound / soc / soc-core.c
index bca8a71..d4bfd4a 100644 (file)
@@ -270,12 +270,33 @@ static const struct file_operations codec_reg_fops = {
        .llseek = default_llseek,
 };
 
+static struct dentry *soc_debugfs_create_dir(struct dentry *parent,
+       const char *fmt, ...)
+{
+       struct dentry *de;
+       va_list ap;
+       char *s;
+
+       va_start(ap, fmt);
+       s = kvasprintf(GFP_KERNEL, fmt, ap);
+       va_end(ap);
+
+       if (!s)
+               return NULL;
+
+       de = debugfs_create_dir(s, parent);
+       kfree(s);
+
+       return de;
+}
+
 static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
 {
-       struct dentry *debugfs_card_root = codec->card->debugfs_card_root;
+       struct dentry *debugfs_card_root = codec->component.card->debugfs_card_root;
 
-       codec->debugfs_codec_root = debugfs_create_dir(codec->component.name,
-                                                      debugfs_card_root);
+       codec->debugfs_codec_root = soc_debugfs_create_dir(debugfs_card_root,
+                                               "codec:%s",
+                                               codec->component.name);
        if (!codec->debugfs_codec_root) {
                dev_warn(codec->dev,
                        "ASoC: Failed to create codec debugfs directory\n");
@@ -304,17 +325,18 @@ static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
 
 static void soc_init_platform_debugfs(struct snd_soc_platform *platform)
 {
-       struct dentry *debugfs_card_root = platform->card->debugfs_card_root;
+       struct dentry *debugfs_card_root = platform->component.card->debugfs_card_root;
 
-       platform->debugfs_platform_root = debugfs_create_dir(
-               platform->component.name, debugfs_card_root);
+       platform->debugfs_platform_root = soc_debugfs_create_dir(debugfs_card_root,
+                                               "platform:%s",
+                                               platform->component.name);
        if (!platform->debugfs_platform_root) {
                dev_warn(platform->dev,
                        "ASoC: Failed to create platform debugfs directory\n");
                return;
        }
 
-       snd_soc_dapm_debugfs_init(&platform->dapm,
+       snd_soc_dapm_debugfs_init(&platform->component.dapm,
                platform->debugfs_platform_root);
 }
 
@@ -524,11 +546,12 @@ static int soc_ac97_dev_register(struct snd_soc_codec *codec)
        int err;
 
        codec->ac97->dev.bus = &ac97_bus_type;
-       codec->ac97->dev.parent = codec->card->dev;
+       codec->ac97->dev.parent = codec->component.card->dev;
        codec->ac97->dev.release = soc_ac97_device_release;
 
        dev_set_name(&codec->ac97->dev, "%d-%d:%s",
-                    codec->card->snd_card->number, 0, codec->component.name);
+                    codec->component.card->snd_card->number, 0,
+                    codec->component.name);
        err = device_register(&codec->ac97->dev);
        if (err < 0) {
                dev_err(codec->dev, "ASoC: Can't register ac97 bus\n");
@@ -554,7 +577,7 @@ int snd_soc_suspend(struct device *dev)
 {
        struct snd_soc_card *card = dev_get_drvdata(dev);
        struct snd_soc_codec *codec;
-       int i;
+       int i, j;
 
        /* If the initialization of this soc device failed, there is no codec
         * associated with it. Just bail out in this case.
@@ -574,14 +597,17 @@ int snd_soc_suspend(struct device *dev)
 
        /* mute any active DACs */
        for (i = 0; i < card->num_rtd; i++) {
-               struct snd_soc_dai *dai = card->rtd[i].codec_dai;
-               struct snd_soc_dai_driver *drv = dai->driver;
 
                if (card->rtd[i].dai_link->ignore_suspend)
                        continue;
 
-               if (drv->ops->digital_mute && dai->playback_active)
-                       drv->ops->digital_mute(dai, 1);
+               for (j = 0; j < card->rtd[i].num_codecs; j++) {
+                       struct snd_soc_dai *dai = card->rtd[i].codec_dais[j];
+                       struct snd_soc_dai_driver *drv = dai->driver;
+
+                       if (drv->ops->digital_mute && dai->playback_active)
+                               drv->ops->digital_mute(dai, 1);
+               }
        }
 
        /* suspend all pcms */
@@ -612,8 +638,12 @@ int snd_soc_suspend(struct device *dev)
 
        /* close any waiting streams and save state */
        for (i = 0; i < card->num_rtd; i++) {
+               struct snd_soc_dai **codec_dais = card->rtd[i].codec_dais;
                flush_delayed_work(&card->rtd[i].delayed_work);
-               card->rtd[i].codec->dapm.suspend_bias_level = card->rtd[i].codec->dapm.bias_level;
+               for (j = 0; j < card->rtd[i].num_codecs; j++) {
+                       codec_dais[j]->codec->dapm.suspend_bias_level =
+                                       codec_dais[j]->codec->dapm.bias_level;
+               }
        }
 
        for (i = 0; i < card->num_rtd; i++) {
@@ -697,7 +727,7 @@ static void soc_resume_deferred(struct work_struct *work)
        struct snd_soc_card *card =
                        container_of(work, struct snd_soc_card, deferred_resume_work);
        struct snd_soc_codec *codec;
-       int i;
+       int i, j;
 
        /* our power state is still SNDRV_CTL_POWER_D3hot from suspend time,
         * so userspace apps are blocked from touching us
@@ -758,14 +788,17 @@ static void soc_resume_deferred(struct work_struct *work)
 
        /* unmute any active DACs */
        for (i = 0; i < card->num_rtd; i++) {
-               struct snd_soc_dai *dai = card->rtd[i].codec_dai;
-               struct snd_soc_dai_driver *drv = dai->driver;
 
                if (card->rtd[i].dai_link->ignore_suspend)
                        continue;
 
-               if (drv->ops->digital_mute && dai->playback_active)
-                       drv->ops->digital_mute(dai, 0);
+               for (j = 0; j < card->rtd[i].num_codecs; j++) {
+                       struct snd_soc_dai *dai = card->rtd[i].codec_dais[j];
+                       struct snd_soc_dai_driver *drv = dai->driver;
+
+                       if (drv->ops->digital_mute && dai->playback_active)
+                               drv->ops->digital_mute(dai, 0);
+               }
        }
 
        for (i = 0; i < card->num_rtd; i++) {
@@ -810,12 +843,19 @@ int snd_soc_resume(struct device *dev)
 
        /* activate pins from sleep state */
        for (i = 0; i < card->num_rtd; i++) {
-               struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
-               struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai;
+               struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
+               struct snd_soc_dai **codec_dais = rtd->codec_dais;
+               struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+               int j;
+
                if (cpu_dai->active)
                        pinctrl_pm_select_default_state(cpu_dai->dev);
-               if (codec_dai->active)
-                       pinctrl_pm_select_default_state(codec_dai->dev);
+
+               for (j = 0; j < rtd->num_codecs; j++) {
+                       struct snd_soc_dai *codec_dai = codec_dais[j];
+                       if (codec_dai->active)
+                               pinctrl_pm_select_default_state(codec_dai->dev);
+               }
        }
 
        /* AC97 devices might have other drivers hanging off them so
@@ -847,8 +887,9 @@ EXPORT_SYMBOL_GPL(snd_soc_resume);
 static const struct snd_soc_dai_ops null_dai_ops = {
 };
 
-static struct snd_soc_codec *soc_find_codec(const struct device_node *codec_of_node,
-                                           const char *codec_name)
+static struct snd_soc_codec *soc_find_codec(
+                                       const struct device_node *codec_of_node,
+                                       const char *codec_name)
 {
        struct snd_soc_codec *codec;
 
@@ -886,9 +927,12 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
        struct snd_soc_dai_link *dai_link = &card->dai_link[num];
        struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
        struct snd_soc_component *component;
+       struct snd_soc_dai_link_component *codecs = dai_link->codecs;
+       struct snd_soc_dai **codec_dais = rtd->codec_dais;
        struct snd_soc_platform *platform;
        struct snd_soc_dai *cpu_dai;
        const char *platform_name;
+       int i;
 
        dev_dbg(card->dev, "ASoC: binding %s at idx %d\n", dai_link->name, num);
 
@@ -915,24 +959,30 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
                return -EPROBE_DEFER;
        }
 
-       /* Find CODEC from registered list */
-       rtd->codec = soc_find_codec(dai_link->codec_of_node,
-                                   dai_link->codec_name);
-       if (!rtd->codec) {
-               dev_err(card->dev, "ASoC: CODEC %s not registered\n",
-                       dai_link->codec_name);
-               return -EPROBE_DEFER;
-       }
+       rtd->num_codecs = dai_link->num_codecs;
 
-       /* Find CODEC DAI from registered list */
-       rtd->codec_dai = soc_find_codec_dai(rtd->codec,
-                                           dai_link->codec_dai_name);
-       if (!rtd->codec_dai) {
-               dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
-                       dai_link->codec_dai_name);
-               return -EPROBE_DEFER;
+       /* Find CODEC from registered CODECs */
+       for (i = 0; i < rtd->num_codecs; i++) {
+               struct snd_soc_codec *codec;
+               codec = soc_find_codec(codecs[i].of_node, codecs[i].name);
+               if (!codec) {
+                       dev_err(card->dev, "ASoC: CODEC %s not registered\n",
+                               codecs[i].name);
+                       return -EPROBE_DEFER;
+               }
+
+               codec_dais[i] = soc_find_codec_dai(codec, codecs[i].dai_name);
+               if (!codec_dais[i]) {
+                       dev_err(card->dev, "ASoC: CODEC DAI %s not registered\n",
+                               codecs[i].dai_name);
+                       return -EPROBE_DEFER;
+               }
        }
 
+       /* Single codec links expect codec and codec_dai in runtime data */
+       rtd->codec_dai = codec_dais[0];
+       rtd->codec = rtd->codec_dai->codec;
+
        /* if there's no platform we match on the empty platform */
        platform_name = dai_link->platform_name;
        if (!platform_name && !dai_link->platform_of_node)
@@ -974,11 +1024,10 @@ static int soc_remove_platform(struct snd_soc_platform *platform)
        }
 
        /* Make sure all DAPM widgets are freed */
-       snd_soc_dapm_free(&platform->dapm);
+       snd_soc_dapm_free(&platform->component.dapm);
 
        soc_cleanup_platform_debugfs(platform);
        platform->probed = 0;
-       list_del(&platform->card_list);
        module_put(platform->dev->driver->owner);
 
        return 0;
@@ -1023,8 +1072,8 @@ static void soc_remove_codec_dai(struct snd_soc_dai *codec_dai, int order)
 static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order)
 {
        struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
-       struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
-       int err;
+       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+       int i, err;
 
        /* unregister the rtd device */
        if (rtd->dev_registered) {
@@ -1035,7 +1084,8 @@ static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order)
        }
 
        /* remove the CODEC DAI */
-       soc_remove_codec_dai(codec_dai, order);
+       for (i = 0; i < rtd->num_codecs; i++)
+               soc_remove_codec_dai(rtd->codec_dais[i], order);
 
        /* remove the cpu_dai */
        if (cpu_dai && cpu_dai->probed &&
@@ -1048,11 +1098,8 @@ static void soc_remove_link_dais(struct snd_soc_card *card, int num, int order)
                                        cpu_dai->name, err);
                }
                cpu_dai->probed = 0;
-
-               if (!cpu_dai->codec) {
-                       snd_soc_dapm_free(&cpu_dai->dapm);
+               if (!cpu_dai->codec)
                        module_put(cpu_dai->dev->driver->owner);
-               }
        }
 }
 
@@ -1061,9 +1108,9 @@ static void soc_remove_link_components(struct snd_soc_card *card, int num,
 {
        struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
        struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-       struct snd_soc_dai *codec_dai = rtd->codec_dai;
        struct snd_soc_platform *platform = rtd->platform;
        struct snd_soc_codec *codec;
+       int i;
 
        /* remove the platform */
        if (platform && platform->probed &&
@@ -1072,8 +1119,8 @@ static void soc_remove_link_components(struct snd_soc_card *card, int num,
        }
 
        /* remove the CODEC-side CODEC */
-       if (codec_dai) {
-               codec = codec_dai->codec;
+       for (i = 0; i < rtd->num_codecs; i++) {
+               codec = rtd->codec_dais[i]->codec;
                if (codec && codec->probed &&
                    codec->driver->remove_order == order)
                        soc_remove_codec(codec);
@@ -1133,7 +1180,7 @@ static int soc_probe_codec(struct snd_soc_card *card,
        const struct snd_soc_codec_driver *driver = codec->driver;
        struct snd_soc_dai *dai;
 
-       codec->card = card;
+       codec->component.card = card;
        codec->dapm.card = card;
        soc_set_name_prefix(card, &codec->component);
 
@@ -1209,8 +1256,8 @@ static int soc_probe_platform(struct snd_soc_card *card,
        struct snd_soc_component *component;
        struct snd_soc_dai *dai;
 
-       platform->card = card;
-       platform->dapm.card = card;
+       platform->component.card = card;
+       platform->component.dapm.card = card;
 
        if (!try_module_get(platform->dev->driver->owner))
                return -ENODEV;
@@ -1218,7 +1265,7 @@ static int soc_probe_platform(struct snd_soc_card *card,
        soc_init_platform_debugfs(platform);
 
        if (driver->dapm_widgets)
-               snd_soc_dapm_new_controls(&platform->dapm,
+               snd_soc_dapm_new_controls(&platform->component.dapm,
                        driver->dapm_widgets, driver->num_dapm_widgets);
 
        /* Create DAPM widgets for each DAI stream */
@@ -1226,10 +1273,11 @@ static int soc_probe_platform(struct snd_soc_card *card,
                if (component->dev != platform->dev)
                        continue;
                list_for_each_entry(dai, &component->dai_list, list)
-                       snd_soc_dapm_new_dai_widgets(&platform->dapm, dai);
+                       snd_soc_dapm_new_dai_widgets(&platform->component.dapm,
+                               dai);
        }
 
-       platform->dapm.idle_bias_off = 1;
+       platform->component.dapm.idle_bias_off = 1;
 
        if (driver->probe) {
                ret = driver->probe(platform);
@@ -1244,13 +1292,12 @@ static int soc_probe_platform(struct snd_soc_card *card,
                snd_soc_add_platform_controls(platform, driver->controls,
                                     driver->num_controls);
        if (driver->dapm_routes)
-               snd_soc_dapm_add_routes(&platform->dapm, driver->dapm_routes,
-                                       driver->num_dapm_routes);
+               snd_soc_dapm_add_routes(&platform->component.dapm,
+                       driver->dapm_routes, driver->num_dapm_routes);
 
        /* mark platform as probed and add to card platform list */
        platform->probed = 1;
-       list_add(&platform->card_list, &card->platform_dev_list);
-       list_add(&platform->dapm.list, &card->dapm_list);
+       list_add(&platform->component.dapm.list, &card->dapm_list);
 
        return 0;
 
@@ -1266,83 +1313,17 @@ static void rtd_release(struct device *dev)
        kfree(dev);
 }
 
-static int soc_aux_dev_init(struct snd_soc_card *card,
-                           struct snd_soc_codec *codec,
-                           int num)
-{
-       struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
-       struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
-       int ret;
-
-       rtd->card = card;
-
-       /* do machine specific initialization */
-       if (aux_dev->init) {
-               ret = aux_dev->init(&codec->dapm);
-               if (ret < 0)
-                       return ret;
-       }
-
-       rtd->codec = codec;
-
-       return 0;
-}
-
-static int soc_dai_link_init(struct snd_soc_card *card,
-                            struct snd_soc_codec *codec,
-                            int num)
-{
-       struct snd_soc_dai_link *dai_link =  &card->dai_link[num];
-       struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
-       int ret;
-
-       rtd->card = card;
-
-       /* do machine specific initialization */
-       if (dai_link->init) {
-               ret = dai_link->init(rtd);
-               if (ret < 0)
-                       return ret;
-       }
-
-       rtd->codec = codec;
-
-       return 0;
-}
-
-static int soc_post_component_init(struct snd_soc_card *card,
-                                  struct snd_soc_codec *codec,
-                                  int num, int dailess)
+static int soc_post_component_init(struct snd_soc_pcm_runtime *rtd,
+       const char *name)
 {
-       struct snd_soc_dai_link *dai_link = NULL;
-       struct snd_soc_aux_dev *aux_dev = NULL;
-       struct snd_soc_pcm_runtime *rtd;
-       const char *name;
        int ret = 0;
 
-       if (!dailess) {
-               dai_link = &card->dai_link[num];
-               rtd = &card->rtd[num];
-               name = dai_link->name;
-               ret = soc_dai_link_init(card, codec, num);
-       } else {
-               aux_dev = &card->aux_dev[num];
-               rtd = &card->rtd_aux[num];
-               name = aux_dev->name;
-               ret = soc_aux_dev_init(card, codec, num);
-       }
-
-       if (ret < 0) {
-               dev_err(card->dev, "ASoC: failed to init %s: %d\n", name, ret);
-               return ret;
-       }
-
        /* register the rtd device */
        rtd->dev = kzalloc(sizeof(struct device), GFP_KERNEL);
        if (!rtd->dev)
                return -ENOMEM;
        device_initialize(rtd->dev);
-       rtd->dev->parent = card->dev;
+       rtd->dev->parent = rtd->card->dev;
        rtd->dev->release = rtd_release;
        rtd->dev->init_name = name;
        dev_set_drvdata(rtd->dev, rtd);
@@ -1355,7 +1336,7 @@ static int soc_post_component_init(struct snd_soc_card *card,
        if (ret < 0) {
                /* calling put_device() here to free the rtd->dev */
                put_device(rtd->dev);
-               dev_err(card->dev,
+               dev_err(rtd->card->dev,
                        "ASoC: failed to register runtime device: %d\n", ret);
                return ret;
        }
@@ -1364,26 +1345,15 @@ static int soc_post_component_init(struct snd_soc_card *card,
        /* add DAPM sysfs entries for this codec */
        ret = snd_soc_dapm_sys_add(rtd->dev);
        if (ret < 0)
-               dev_err(codec->dev,
+               dev_err(rtd->dev,
                        "ASoC: failed to add codec dapm sysfs entries: %d\n", ret);
 
        /* add codec sysfs entries */
        ret = device_create_file(rtd->dev, &dev_attr_codec_reg);
        if (ret < 0)
-               dev_err(codec->dev,
+               dev_err(rtd->dev,
                        "ASoC: failed to add codec sysfs files: %d\n", ret);
 
-#ifdef CONFIG_DEBUG_FS
-       /* add DPCM sysfs entries */
-       if (!dailess && !dai_link->dynamic)
-               goto out;
-
-       ret = soc_dpcm_debugfs_add(rtd);
-       if (ret < 0)
-               dev_err(rtd->dev, "ASoC: failed to add dpcm sysfs entries: %d\n", ret);
-
-out:
-#endif
        return 0;
 }
 
@@ -1392,9 +1362,8 @@ static int soc_probe_link_components(struct snd_soc_card *card, int num,
 {
        struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
        struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-       struct snd_soc_dai *codec_dai = rtd->codec_dai;
        struct snd_soc_platform *platform = rtd->platform;
-       int ret;
+       int i, ret;
 
        /* probe the CPU-side component, if it is a CODEC */
        if (cpu_dai->codec &&
@@ -1405,12 +1374,14 @@ static int soc_probe_link_components(struct snd_soc_card *card, int num,
                        return ret;
        }
 
-       /* probe the CODEC-side component */
-       if (!codec_dai->codec->probed &&
-           codec_dai->codec->driver->probe_order == order) {
-               ret = soc_probe_codec(card, codec_dai->codec);
-               if (ret < 0)
-                       return ret;
+       /* probe the CODEC-side components */
+       for (i = 0; i < rtd->num_codecs; i++) {
+               if (!rtd->codec_dais[i]->codec->probed &&
+                   rtd->codec_dais[i]->codec->driver->probe_order == order) {
+                       ret = soc_probe_codec(card, rtd->codec_dais[i]->codec);
+                       if (ret < 0)
+                               return ret;
+               }
        }
 
        /* probe the platform */
@@ -1450,12 +1421,16 @@ static int soc_probe_codec_dai(struct snd_soc_card *card,
 
 static int soc_link_dai_widgets(struct snd_soc_card *card,
                                struct snd_soc_dai_link *dai_link,
-                               struct snd_soc_dai *cpu_dai,
-                               struct snd_soc_dai *codec_dai)
+                               struct snd_soc_pcm_runtime *rtd)
 {
+       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+       struct snd_soc_dai *codec_dai = rtd->codec_dai;
        struct snd_soc_dapm_widget *play_w, *capture_w;
        int ret;
 
+       if (rtd->num_codecs > 1)
+               dev_warn(card->dev, "ASoC: Multiple codecs not supported yet\n");
+
        /* link the DAI widgets */
        play_w = codec_dai->playback_widget;
        capture_w = cpu_dai->capture_widget;
@@ -1488,19 +1463,18 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
 {
        struct snd_soc_dai_link *dai_link = &card->dai_link[num];
        struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
-       struct snd_soc_codec *codec = rtd->codec;
        struct snd_soc_platform *platform = rtd->platform;
-       struct snd_soc_dai *codec_dai = rtd->codec_dai;
        struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-       int ret;
+       int i, ret;
 
        dev_dbg(card->dev, "ASoC: probe %s dai link %d late %d\n",
                        card->name, num, order);
 
        /* config components */
        cpu_dai->platform = platform;
-       codec_dai->card = card;
        cpu_dai->card = card;
+       for (i = 0; i < rtd->num_codecs; i++)
+               rtd->codec_dais[i]->card = card;
 
        /* set default power off timeout */
        rtd->pmdown_time = pmdown_time;
@@ -1509,11 +1483,8 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
        if (!cpu_dai->probed &&
                        cpu_dai->driver->probe_order == order) {
                if (!cpu_dai->codec) {
-                       cpu_dai->dapm.card = card;
                        if (!try_module_get(cpu_dai->dev->driver->owner))
                                return -ENODEV;
-
-                       list_add(&cpu_dai->dapm.list, &card->dapm_list);
                }
 
                if (cpu_dai->driver->probe) {
@@ -1530,18 +1501,43 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
        }
 
        /* probe the CODEC DAI */
-       ret = soc_probe_codec_dai(card, codec_dai, order);
-       if (ret)
-               return ret;
+       for (i = 0; i < rtd->num_codecs; i++) {
+               ret = soc_probe_codec_dai(card, rtd->codec_dais[i], order);
+               if (ret)
+                       return ret;
+       }
 
        /* complete DAI probe during last probe */
        if (order != SND_SOC_COMP_ORDER_LAST)
                return 0;
 
-       ret = soc_post_component_init(card, codec, num, 0);
+       /* do machine specific initialization */
+       if (dai_link->init) {
+               ret = dai_link->init(rtd);
+               if (ret < 0) {
+                       dev_err(card->dev, "ASoC: failed to init %s: %d\n",
+                               dai_link->name, ret);
+                       return ret;
+               }
+       }
+
+       ret = soc_post_component_init(rtd, dai_link->name);
        if (ret)
                return ret;
 
+#ifdef CONFIG_DEBUG_FS
+       /* add DPCM sysfs entries */
+       if (dai_link->dynamic) {
+               ret = soc_dpcm_debugfs_add(rtd);
+               if (ret < 0) {
+                       dev_err(rtd->dev,
+                               "ASoC: failed to add dpcm sysfs entries: %d\n",
+                               ret);
+                       return ret;
+               }
+       }
+#endif
+
        ret = device_create_file(rtd->dev, &dev_attr_pmdown_time);
        if (ret < 0)
                dev_warn(rtd->dev, "ASoC: failed to add pmdown_time sysfs: %d\n",
@@ -1570,16 +1566,18 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
                                                codec2codec_close_delayed_work);
 
                        /* link the DAI widgets */
-                       ret = soc_link_dai_widgets(card, dai_link,
-                                       cpu_dai, codec_dai);
+                       ret = soc_link_dai_widgets(card, dai_link, rtd);
                        if (ret)
                                return ret;
                }
        }
 
        /* add platform data for AC97 devices */
-       if (rtd->codec_dai->driver->ac97_control)
-               snd_ac97_dev_add_pdata(codec->ac97, rtd->cpu_dai->ac97_pdata);
+       for (i = 0; i < rtd->num_codecs; i++) {
+               if (rtd->codec_dais[i]->driver->ac97_control)
+                       snd_ac97_dev_add_pdata(rtd->codec_dais[i]->codec->ac97,
+                                              rtd->cpu_dai->ac97_pdata);
+       }
 
        return 0;
 }
@@ -1617,11 +1615,6 @@ static int soc_register_ac97_codec(struct snd_soc_codec *codec,
        return 0;
 }
 
-static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
-{
-       return soc_register_ac97_codec(rtd->codec, rtd->codec_dai);
-}
-
 static void soc_unregister_ac97_codec(struct snd_soc_codec *codec)
 {
        if (codec->ac97_registered) {
@@ -1630,75 +1623,77 @@ static void soc_unregister_ac97_codec(struct snd_soc_codec *codec)
        }
 }
 
-static void soc_unregister_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
+static int soc_register_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
 {
-       soc_unregister_ac97_codec(rtd->codec);
-}
-#endif
+       int i, ret;
 
-static struct snd_soc_codec *soc_find_matching_codec(struct snd_soc_card *card,
-       int num)
-{
-       struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
-       struct snd_soc_codec *codec;
+       for (i = 0; i < rtd->num_codecs; i++) {
+               struct snd_soc_dai *codec_dai = rtd->codec_dais[i];
 
-       /* find CODEC from registered CODECs */
-       list_for_each_entry(codec, &codec_list, list) {
-               if (aux_dev->codec_of_node &&
-                  (codec->dev->of_node != aux_dev->codec_of_node))
-                       continue;
-               if (aux_dev->codec_name &&
-                       strcmp(codec->component.name, aux_dev->codec_name))
-                       continue;
-               return codec;
+               ret = soc_register_ac97_codec(codec_dai->codec, codec_dai);
+               if (ret) {
+                       while (--i >= 0)
+                               soc_unregister_ac97_codec(codec_dai->codec);
+                       return ret;
+               }
        }
 
-       return NULL;
+       return 0;
 }
 
-static int soc_check_aux_dev(struct snd_soc_card *card, int num)
+static void soc_unregister_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
 {
-       struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
-       const char *codecname = aux_dev->codec_name;
-       struct snd_soc_codec *codec = soc_find_matching_codec(card, num);
-
-       if (codec)
-               return 0;
-       if (aux_dev->codec_of_node)
-               codecname = of_node_full_name(aux_dev->codec_of_node);
+       int i;
 
-       dev_err(card->dev, "ASoC: %s not registered\n", codecname);
-       return -EPROBE_DEFER;
+       for (i = 0; i < rtd->num_codecs; i++)
+               soc_unregister_ac97_codec(rtd->codec_dais[i]->codec);
 }
+#endif
 
-static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
+static int soc_bind_aux_dev(struct snd_soc_card *card, int num)
 {
+       struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
        struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
        const char *codecname = aux_dev->codec_name;
-       int ret = -ENODEV;
-       struct snd_soc_codec *codec = soc_find_matching_codec(card, num);
 
-       if (!codec) {
+       rtd->codec = soc_find_codec(aux_dev->codec_of_node, codecname);
+       if (!rtd->codec) {
                if (aux_dev->codec_of_node)
                        codecname = of_node_full_name(aux_dev->codec_of_node);
 
-               /* codec not found */
-               dev_err(card->dev, "ASoC: codec %s not found", codecname);
+               dev_err(card->dev, "ASoC: %s not registered\n", codecname);
                return -EPROBE_DEFER;
        }
 
-       if (codec->probed) {
-               dev_err(codec->dev, "ASoC: codec already probed");
+       return 0;
+}
+
+static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
+{
+       struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
+       struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
+       int ret;
+
+       if (rtd->codec->probed) {
+               dev_err(rtd->codec->dev, "ASoC: codec already probed\n");
                return -EBUSY;
        }
 
-       ret = soc_probe_codec(card, codec);
+       ret = soc_probe_codec(card, rtd->codec);
        if (ret < 0)
                return ret;
 
-       ret = soc_post_component_init(card, codec, num, 1);
+       /* do machine specific initialization */
+       if (aux_dev->init) {
+               ret = aux_dev->init(&rtd->codec->dapm);
+               if (ret < 0) {
+                       dev_err(card->dev, "ASoC: failed to init %s: %d\n",
+                               aux_dev->name, ret);
+                       return ret;
+               }
+       }
 
-       return ret;
+       return soc_post_component_init(rtd, aux_dev->name);
 }
 
 static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
@@ -1750,9 +1745,9 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
                        goto base_error;
        }
 
-       /* check aux_devs too */
+       /* bind aux_devs too */
        for (i = 0; i < card->num_aux_devs; i++) {
-               ret = soc_check_aux_dev(card, i);
+               ret = soc_bind_aux_dev(card, i);
                if (ret != 0)
                        goto base_error;
        }
@@ -1850,16 +1845,23 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
                                        card->num_dapm_routes);
 
        for (i = 0; i < card->num_links; i++) {
+               struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
                dai_link = &card->dai_link[i];
                dai_fmt = dai_link->dai_fmt;
 
                if (dai_fmt) {
-                       ret = snd_soc_dai_set_fmt(card->rtd[i].codec_dai,
-                                                 dai_fmt);
-                       if (ret != 0 && ret != -ENOTSUPP)
-                               dev_warn(card->rtd[i].codec_dai->dev,
-                                        "ASoC: Failed to set DAI format: %d\n",
-                                        ret);
+                       struct snd_soc_dai **codec_dais = rtd->codec_dais;
+                       int j;
+
+                       for (j = 0; j < rtd->num_codecs; j++) {
+                               struct snd_soc_dai *codec_dai = codec_dais[j];
+
+                               ret = snd_soc_dai_set_fmt(codec_dai, dai_fmt);
+                               if (ret != 0 && ret != -ENOTSUPP)
+                                       dev_warn(codec_dai->dev,
+                                                "ASoC: Failed to set DAI format: %d\n",
+                                                ret);
+                       }
                }
 
                /* If this is a regular CPU link there will be a platform */
@@ -2058,10 +2060,15 @@ int snd_soc_poweroff(struct device *dev)
 
        /* deactivate pins to sleep state */
        for (i = 0; i < card->num_rtd; i++) {
-               struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
-               struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai;
-               pinctrl_pm_select_sleep_state(codec_dai->dev);
+               struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
+               struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+               int j;
+
                pinctrl_pm_select_sleep_state(cpu_dai->dev);
+               for (j = 0; j < rtd->num_codecs; j++) {
+                       struct snd_soc_dai *codec_dai = rtd->codec_dais[j];
+                       pinctrl_pm_select_sleep_state(codec_dai->dev);
+               }
        }
 
        return 0;
@@ -2386,6 +2393,25 @@ struct snd_kcontrol *snd_soc_card_get_kcontrol(struct snd_soc_card *soc_card,
 }
 EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol);
 
+/**
+ * snd_soc_add_component_controls - Add an array of controls to a component.
+ *
+ * @component: Component to add controls to
+ * @controls: Array of controls to add
+ * @num_controls: Number of elements in the array
+ *
+ * Return: 0 for success, else error.
+ */
+int snd_soc_add_component_controls(struct snd_soc_component *component,
+       const struct snd_kcontrol_new *controls, unsigned int num_controls)
+{
+       struct snd_card *card = component->card->snd_card;
+
+       return snd_soc_add_controls(card, component->dev, controls,
+                       num_controls, component->name_prefix, component);
+}
+EXPORT_SYMBOL_GPL(snd_soc_add_component_controls);
+
 /**
  * snd_soc_add_codec_controls - add an array of controls to a codec.
  * Convenience function to add a list of controls. Many codecs were
@@ -2398,12 +2424,10 @@ EXPORT_SYMBOL_GPL(snd_soc_card_get_kcontrol);
  * Return 0 for success, else error.
  */
 int snd_soc_add_codec_controls(struct snd_soc_codec *codec,
-       const struct snd_kcontrol_new *controls, int num_controls)
+       const struct snd_kcontrol_new *controls, unsigned int num_controls)
 {
-       struct snd_card *card = codec->card->snd_card;
-
-       return snd_soc_add_controls(card, codec->dev, controls, num_controls,
-                       codec->component.name_prefix, &codec->component);
+       return snd_soc_add_component_controls(&codec->component, controls,
+               num_controls);
 }
 EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls);
 
@@ -2418,12 +2442,10 @@ EXPORT_SYMBOL_GPL(snd_soc_add_codec_controls);
  * Return 0 for success, else error.
  */
 int snd_soc_add_platform_controls(struct snd_soc_platform *platform,
-       const struct snd_kcontrol_new *controls, int num_controls)
+       const struct snd_kcontrol_new *controls, unsigned int num_controls)
 {
-       struct snd_card *card = platform->card->snd_card;
-
-       return snd_soc_add_controls(card, platform->dev, controls, num_controls,
-                       NULL, &platform->component);
+       return snd_soc_add_component_controls(&platform->component, controls,
+               num_controls);
 }
 EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls);
 
@@ -3095,7 +3117,7 @@ EXPORT_SYMBOL_GPL(snd_soc_get_volsw_range);
 int snd_soc_limit_volume(struct snd_soc_codec *codec,
        const char *name, int max)
 {
-       struct snd_card *card = codec->card->snd_card;
+       struct snd_card *card = codec->component.card->snd_card;
        struct snd_kcontrol *kctl;
        struct soc_mixer_control *mc;
        int found = 0;
@@ -3267,6 +3289,27 @@ int snd_soc_bytes_info_ext(struct snd_kcontrol *kcontrol,
 }
 EXPORT_SYMBOL_GPL(snd_soc_bytes_info_ext);
 
+int snd_soc_bytes_tlv_callback(struct snd_kcontrol *kcontrol, int op_flag,
+                               unsigned int size, unsigned int __user *tlv)
+{
+       struct soc_bytes_ext *params = (void *)kcontrol->private_value;
+       unsigned int count = size < params->max ? size : params->max;
+       int ret = -ENXIO;
+
+       switch (op_flag) {
+       case SNDRV_CTL_TLV_OP_READ:
+               if (params->get)
+                       ret = params->get(tlv, count);
+               break;
+       case SNDRV_CTL_TLV_OP_WRITE:
+               if (params->put)
+                       ret = params->put(tlv, count);
+               break;
+       }
+       return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_bytes_tlv_callback);
+
 /**
  * snd_soc_info_xr_sx - signed multi register info callback
  * @kcontrol: mreg control
@@ -3641,6 +3684,9 @@ int snd_soc_dai_set_tdm_slot(struct snd_soc_dai *dai,
        else
                snd_soc_xlate_tdm_slot_mask(slots, &tx_mask, &rx_mask);
 
+       dai->tx_mask = tx_mask;
+       dai->rx_mask = rx_mask;
+
        if (dai->driver && dai->driver->ops->set_tdm_slot)
                return dai->driver->ops->set_tdm_slot(dai, tx_mask, rx_mask,
                                slots, slot_width);
@@ -3713,6 +3759,33 @@ int snd_soc_dai_digital_mute(struct snd_soc_dai *dai, int mute,
 }
 EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
 
+static int snd_soc_init_multicodec(struct snd_soc_card *card,
+                                  struct snd_soc_dai_link *dai_link)
+{
+       /* Legacy codec/codec_dai link is a single entry in multicodec */
+       if (dai_link->codec_name || dai_link->codec_of_node ||
+           dai_link->codec_dai_name) {
+               dai_link->num_codecs = 1;
+
+               dai_link->codecs = devm_kzalloc(card->dev,
+                               sizeof(struct snd_soc_dai_link_component),
+                               GFP_KERNEL);
+               if (!dai_link->codecs)
+                       return -ENOMEM;
+
+               dai_link->codecs[0].name = dai_link->codec_name;
+               dai_link->codecs[0].of_node = dai_link->codec_of_node;
+               dai_link->codecs[0].dai_name = dai_link->codec_dai_name;
+       }
+
+       if (!dai_link->codecs) {
+               dev_err(card->dev, "ASoC: DAI link has no CODECs\n");
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
 /**
  * snd_soc_register_card - Register a card with the ASoC core
  *
@@ -3721,7 +3794,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
  */
 int snd_soc_register_card(struct snd_soc_card *card)
 {
-       int i, ret;
+       int i, j, ret;
 
        if (!card->name || !card->dev)
                return -EINVAL;
@@ -3729,22 +3802,29 @@ int snd_soc_register_card(struct snd_soc_card *card)
        for (i = 0; i < card->num_links; i++) {
                struct snd_soc_dai_link *link = &card->dai_link[i];
 
-               /*
-                * Codec must be specified by 1 of name or OF node,
-                * not both or neither.
-                */
-               if (!!link->codec_name == !!link->codec_of_node) {
-                       dev_err(card->dev,
-                               "ASoC: Neither/both codec name/of_node are set for %s\n",
-                               link->name);
-                       return -EINVAL;
+               ret = snd_soc_init_multicodec(card, link);
+               if (ret) {
+                       dev_err(card->dev, "ASoC: failed to init multicodec\n");
+                       return ret;
                }
-               /* Codec DAI name must be specified */
-               if (!link->codec_dai_name) {
-                       dev_err(card->dev,
-                               "ASoC: codec_dai_name not set for %s\n",
-                               link->name);
-                       return -EINVAL;
+
+               for (j = 0; j < link->num_codecs; j++) {
+                       /*
+                        * Codec must be specified by 1 of name or OF node,
+                        * not both or neither.
+                        */
+                       if (!!link->codecs[j].name ==
+                           !!link->codecs[j].of_node) {
+                               dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n",
+                                       link->name);
+                               return -EINVAL;
+                       }
+                       /* Codec DAI name must be specified */
+                       if (!link->codecs[j].dai_name) {
+                               dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n",
+                                       link->name);
+                               return -EINVAL;
+                       }
                }
 
                /*
@@ -3797,8 +3877,19 @@ int snd_soc_register_card(struct snd_soc_card *card)
        card->num_rtd = 0;
        card->rtd_aux = &card->rtd[card->num_links];
 
-       for (i = 0; i < card->num_links; i++)
+       for (i = 0; i < card->num_links; i++) {
+               card->rtd[i].card = card;
                card->rtd[i].dai_link = &card->dai_link[i];
+               card->rtd[i].codec_dais = devm_kzalloc(card->dev,
+                                       sizeof(struct snd_soc_dai *) *
+                                       (card->rtd[i].dai_link->num_codecs),
+                                       GFP_KERNEL);
+               if (card->rtd[i].codec_dais == NULL)
+                       return -ENOMEM;
+       }
+
+       for (i = 0; i < card->num_aux_devs; i++)
+               card->rtd_aux[i].card = card;
 
        INIT_LIST_HEAD(&card->dapm_dirty);
        card->instantiated = 0;
@@ -3811,10 +3902,16 @@ int snd_soc_register_card(struct snd_soc_card *card)
 
        /* deactivate pins to sleep state */
        for (i = 0; i < card->num_rtd; i++) {
-               struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
-               struct snd_soc_dai *codec_dai = card->rtd[i].codec_dai;
-               if (!codec_dai->active)
-                       pinctrl_pm_select_sleep_state(codec_dai->dev);
+               struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
+               struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
+               int j;
+
+               for (j = 0; j < rtd->num_codecs; j++) {
+                       struct snd_soc_dai *codec_dai = rtd->codec_dais[j];
+                       if (!codec_dai->active)
+                               pinctrl_pm_select_sleep_state(codec_dai->dev);
+               }
+
                if (!cpu_dai->active)
                        pinctrl_pm_select_sleep_state(cpu_dai->dev);
        }
@@ -3974,13 +4071,9 @@ static int snd_soc_register_dais(struct snd_soc_component *component,
                dai->component = component;
                dai->dev = dev;
                dai->driver = &dai_drv[i];
-               dai->dapm.dev = dev;
                if (!dai->driver->ops)
                        dai->driver->ops = &null_dai_ops;
 
-               if (!dai->codec)
-                       dai->dapm.idle_bias_off = 1;
-
                list_add(&dai->list, &component->dai_list);
 
                dev_dbg(dev, "ASoC: Registered DAI '%s'\n", dai->name);
@@ -3994,9 +4087,27 @@ err:
        return ret;
 }
 
+static void snd_soc_component_seq_notifier(struct snd_soc_dapm_context *dapm,
+       enum snd_soc_dapm_type type, int subseq)
+{
+       struct snd_soc_component *component = dapm->component;
+
+       component->driver->seq_notifier(component, type, subseq);
+}
+
+static int snd_soc_component_stream_event(struct snd_soc_dapm_context *dapm,
+       int event)
+{
+       struct snd_soc_component *component = dapm->component;
+
+       return component->driver->stream_event(component, event);
+}
+
 static int snd_soc_component_initialize(struct snd_soc_component *component,
        const struct snd_soc_component_driver *driver, struct device *dev)
 {
+       struct snd_soc_dapm_context *dapm;
+
        component->name = fmt_single_name(dev, &component->id);
        if (!component->name) {
                dev_err(dev, "ASoC: Failed to allocate name\n");
@@ -4006,6 +4117,18 @@ static int snd_soc_component_initialize(struct snd_soc_component *component,
        component->dev = dev;
        component->driver = driver;
 
+       if (!component->dapm_ptr)
+               component->dapm_ptr = &component->dapm;
+
+       dapm = component->dapm_ptr;
+       dapm->dev = dev;
+       dapm->component = component;
+       dapm->bias_level = SND_SOC_BIAS_OFF;
+       if (driver->seq_notifier)
+               dapm->seq_notifier = snd_soc_component_seq_notifier;
+       if (driver->stream_event)
+               dapm->stream_event = snd_soc_component_stream_event;
+
        INIT_LIST_HEAD(&component->dai_list);
        mutex_init(&component->io_mutex);
 
@@ -4138,10 +4261,6 @@ int snd_soc_add_platform(struct device *dev, struct snd_soc_platform *platform,
 
        platform->dev = dev;
        platform->driver = platform_drv;
-       platform->dapm.dev = dev;
-       platform->dapm.platform = platform;
-       platform->dapm.component = &platform->component;
-       platform->dapm.stream_event = platform_drv->stream_event;
        if (platform_drv->write)
                platform->component.write = snd_soc_platform_drv_write;
        if (platform_drv->read)
@@ -4285,6 +4404,14 @@ static int snd_soc_codec_drv_read(struct snd_soc_component *component,
        return 0;
 }
 
+static int snd_soc_codec_set_bias_level(struct snd_soc_dapm_context *dapm,
+       enum snd_soc_bias_level level)
+{
+       struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm);
+
+       return codec->driver->set_bias_level(codec, level);
+}
+
 /**
  * snd_soc_register_codec - Register a codec with the ASoC core
  *
@@ -4306,6 +4433,8 @@ int snd_soc_register_codec(struct device *dev,
        if (codec == NULL)
                return -ENOMEM;
 
+       codec->component.dapm_ptr = &codec->dapm;
+
        ret = snd_soc_component_initialize(&codec->component,
                        &codec_drv->component_driver, dev);
        if (ret)
@@ -4316,12 +4445,11 @@ int snd_soc_register_codec(struct device *dev,
        if (codec_drv->read)
                codec->component.read = snd_soc_codec_drv_read;
        codec->component.ignore_pmdown_time = codec_drv->ignore_pmdown_time;
-       codec->dapm.bias_level = SND_SOC_BIAS_OFF;
-       codec->dapm.dev = dev;
        codec->dapm.codec = codec;
-       codec->dapm.component = &codec->component;
-       codec->dapm.seq_notifier = codec_drv->seq_notifier;
-       codec->dapm.stream_event = codec_drv->stream_event;
+       if (codec_drv->seq_notifier)
+               codec->dapm.seq_notifier = codec_drv->seq_notifier;
+       if (codec_drv->set_bias_level)
+               codec->dapm.set_bias_level = snd_soc_codec_set_bias_level;
        codec->dev = dev;
        codec->driver = codec_drv;
        codec->component.val_bytes = codec_drv->reg_word_size;
@@ -4411,9 +4539,16 @@ EXPORT_SYMBOL_GPL(snd_soc_unregister_codec);
 int snd_soc_of_parse_card_name(struct snd_soc_card *card,
                               const char *propname)
 {
-       struct device_node *np = card->dev->of_node;
+       struct device_node *np;
        int ret;
 
+       if (!card->dev) {
+               pr_err("card->dev is not set before calling %s\n", __func__);
+               return -EINVAL;
+       }
+
+       np = card->dev->of_node;
+
        ret = of_property_read_string_index(np, propname, 0, &card->name);
        /*
         * EINVAL means the property does not exist. This is fine providing