]> nv-tegra.nvidia Code Review - linux-2.6.git/blobdiff - sound/soc/soc-core.c
ASOC: Tegra: Fix Tegra20 BT SCO playback/record
[linux-2.6.git] / sound / soc / soc-core.c
index b5e5758456bd162bbd6b582586daf81f12a4e298..ef69f5a0270991e7990055b109282cd6e66afa08 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/bitops.h>
 #include <linux/debugfs.h>
 #include <linux/platform_device.h>
+#include <linux/ctype.h>
 #include <linux/slab.h>
 #include <sound/ac97_codec.h>
 #include <sound/core.h>
@@ -44,7 +45,6 @@
 
 #define NAME_SIZE      32
 
-static DEFINE_MUTEX(pcm_mutex);
 static DECLARE_WAIT_QUEUE_HEAD(soc_pm_waitq);
 
 #ifdef CONFIG_DEBUG_FS
@@ -58,9 +58,7 @@ static LIST_HEAD(dai_list);
 static LIST_HEAD(platform_list);
 static LIST_HEAD(codec_list);
 
-static int snd_soc_register_card(struct snd_soc_card *card);
-static int snd_soc_unregister_card(struct snd_soc_card *card);
-static int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num);
+int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num);
 
 /*
  * This is a timeout to do a DAPM powerdown after a stream is closed().
@@ -71,10 +69,73 @@ static int pmdown_time = 5000;
 module_param(pmdown_time, int, 0);
 MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
 
+/* returns the minimum number of bytes needed to represent
+ * a particular given value */
+static int min_bytes_needed(unsigned long val)
+{
+       int c = 0;
+       int i;
+
+       for (i = (sizeof val * 8) - 1; i >= 0; --i, ++c)
+               if (val & (1UL << i))
+                       break;
+       c = (sizeof val * 8) - c;
+       if (!c || (c % 8))
+               c = (c + 8) / 8;
+       else
+               c /= 8;
+       return c;
+}
+
+/* fill buf which is 'len' bytes with a formatted
+ * string of the form 'reg: value\n' */
+static int format_register_str(struct snd_soc_codec *codec,
+                              unsigned int reg, char *buf, size_t len)
+{
+       int wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
+       int regsize = codec->driver->reg_word_size * 2;
+       int ret;
+       char tmpbuf[len + 1];
+       char regbuf[regsize + 1];
+
+       /* since tmpbuf is allocated on the stack, warn the callers if they
+        * try to abuse this function */
+       WARN_ON(len > 63);
+
+       /* +2 for ': ' and + 1 for '\n' */
+       if (wordsize + regsize + 2 + 1 != len)
+               return -EINVAL;
+
+       ret = snd_soc_read(codec , reg);
+       if (ret < 0) {
+               memset(regbuf, 'X', regsize);
+               regbuf[regsize] = '\0';
+       } else {
+               snprintf(regbuf, regsize + 1, "%.*x", regsize, ret);
+       }
+
+       /* prepare the buffer */
+       snprintf(tmpbuf, len + 1, "%.*x: %s\n", wordsize, reg, regbuf);
+       /* copy it back to the caller without the '\0' */
+       memcpy(buf, tmpbuf, len);
+
+       return 0;
+}
+
 /* codec register dump */
-static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf)
+static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf,
+                                 size_t count, loff_t pos)
 {
-       int ret, i, step = 1, count = 0;
+       int i, step = 1;
+       int wordsize, regsize;
+       int len;
+       size_t total = 0;
+       loff_t p = 0;
+
+       wordsize = min_bytes_needed(codec->driver->reg_cache_size) * 2;
+       regsize = codec->driver->reg_word_size * 2;
+
+       len = wordsize + regsize + 2 + 1;
 
        if (!codec->driver->reg_cache_size)
                return 0;
@@ -82,55 +143,37 @@ static ssize_t soc_codec_reg_show(struct snd_soc_codec *codec, char *buf)
        if (codec->driver->reg_cache_step)
                step = codec->driver->reg_cache_step;
 
-       count += sprintf(buf, "%s registers\n", codec->name);
        for (i = 0; i < codec->driver->reg_cache_size; i += step) {
-               if (codec->driver->readable_register && !codec->driver->readable_register(codec, i))
+               if (codec->readable_register && !codec->readable_register(codec, i))
                        continue;
-
-               count += sprintf(buf + count, "%2x: ", i);
-               if (count >= PAGE_SIZE - 1)
-                       break;
-
                if (codec->driver->display_register) {
                        count += codec->driver->display_register(codec, buf + count,
                                                         PAGE_SIZE - count, i);
                } else {
-                       /* If the read fails it's almost certainly due to
-                        * the register being volatile and the device being
-                        * powered off.
-                        */
-                       ret = snd_soc_read(codec, i);
-                       if (ret >= 0)
-                               count += snprintf(buf + count,
-                                                 PAGE_SIZE - count,
-                                                 "%4x", ret);
-                       else
-                               count += snprintf(buf + count,
-                                                 PAGE_SIZE - count,
-                                                 "<no data: %d>", ret);
+                       /* only support larger than PAGE_SIZE bytes debugfs
+                        * entries for the default case */
+                       if (p >= pos) {
+                               if (total + len >= count - 1)
+                                       break;
+                               format_register_str(codec, i, buf + total, len);
+                               total += len;
+                       }
+                       p += len;
                }
-
-               if (count >= PAGE_SIZE - 1)
-                       break;
-
-               count += snprintf(buf + count, PAGE_SIZE - count, "\n");
-               if (count >= PAGE_SIZE - 1)
-                       break;
        }
 
-       /* Truncate count; min() would cause a warning */
-       if (count >= PAGE_SIZE)
-               count = PAGE_SIZE - 1;
+       total = min(total, count - 1);
 
-       return count;
+       return total;
 }
+
 static ssize_t codec_reg_show(struct device *dev,
        struct device_attribute *attr, char *buf)
 {
        struct snd_soc_pcm_runtime *rtd =
                        container_of(dev, struct snd_soc_pcm_runtime, dev);
 
-       return soc_codec_reg_show(rtd->codec, buf);
+       return soc_codec_reg_show(rtd->codec, buf, PAGE_SIZE, 0);
 }
 
 static DEVICE_ATTR(codec_reg, 0444, codec_reg_show, NULL);
@@ -169,16 +212,28 @@ static int codec_reg_open_file(struct inode *inode, struct file *file)
 }
 
 static ssize_t codec_reg_read_file(struct file *file, char __user *user_buf,
-                              size_t count, loff_t *ppos)
+                                  size_t count, loff_t *ppos)
 {
        ssize_t ret;
        struct snd_soc_codec *codec = file->private_data;
-       char *buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
+       char *buf;
+
+       if (*ppos < 0 || !count)
+               return -EINVAL;
+
+       buf = kmalloc(count, GFP_KERNEL);
        if (!buf)
                return -ENOMEM;
-       ret = soc_codec_reg_show(codec, buf);
-       if (ret >= 0)
-               ret = simple_read_from_buffer(user_buf, count, ppos, buf, ret);
+
+       ret = soc_codec_reg_show(codec, buf, count, *ppos);
+       if (ret >= 0) {
+               if (copy_to_user(user_buf, buf, ret)) {
+                       kfree(buf);
+                       return -EFAULT;
+               }
+               *ppos += ret;
+       }
+
        kfree(buf);
        return ret;
 }
@@ -187,7 +242,7 @@ static ssize_t codec_reg_write_file(struct file *file,
                const char __user *user_buf, size_t count, loff_t *ppos)
 {
        char buf[32];
-       int buf_size;
+       size_t buf_size;
        char *start = buf;
        unsigned long reg, value;
        int step = 1;
@@ -204,8 +259,6 @@ static ssize_t codec_reg_write_file(struct file *file,
        while (*start == ' ')
                start++;
        reg = simple_strtoul(start, &start, 16);
-       if ((reg >= codec->driver->reg_cache_size) || (reg % step))
-               return -EINVAL;
        while (*start == ' ')
                start++;
        if (strict_strtoul(start, 16, &value))
@@ -237,6 +290,11 @@ static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
                return;
        }
 
+       debugfs_create_bool("cache_sync", 0444, codec->debugfs_codec_root,
+                           &codec->cache_sync);
+       debugfs_create_bool("cache_only", 0444, codec->debugfs_codec_root,
+                           &codec->cache_only);
+
        codec->debugfs_reg = debugfs_create_file("codec_reg", 0644,
                                                 codec->debugfs_codec_root,
                                                 codec, &codec_reg_fops);
@@ -244,13 +302,7 @@ static void soc_init_codec_debugfs(struct snd_soc_codec *codec)
                printk(KERN_WARNING
                       "ASoC: Failed to create codec register debugfs file\n");
 
-       codec->dapm.debugfs_dapm = debugfs_create_dir("dapm",
-                                                codec->debugfs_codec_root);
-       if (!codec->dapm.debugfs_dapm)
-               printk(KERN_WARNING
-                      "Failed to create DAPM debugfs directory\n");
-
-       snd_soc_dapm_debugfs_init(&codec->dapm);
+       snd_soc_dapm_debugfs_init(&codec->dapm, codec->debugfs_codec_root);
 }
 
 static void soc_cleanup_codec_debugfs(struct snd_soc_codec *codec)
@@ -433,546 +485,11 @@ static int soc_ac97_dev_register(struct snd_soc_codec *codec)
 }
 #endif
 
-static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream)
-{
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-       struct snd_soc_dai *codec_dai = rtd->codec_dai;
-       int ret;
-
-       if (codec_dai->driver->symmetric_rates || cpu_dai->driver->symmetric_rates ||
-                       rtd->dai_link->symmetric_rates) {
-               dev_dbg(&rtd->dev, "Symmetry forces %dHz rate\n",
-                               rtd->rate);
-
-               ret = snd_pcm_hw_constraint_minmax(substream->runtime,
-                                                  SNDRV_PCM_HW_PARAM_RATE,
-                                                  rtd->rate,
-                                                  rtd->rate);
-               if (ret < 0) {
-                       dev_err(&rtd->dev,
-                               "Unable to apply rate symmetry constraint: %d\n", ret);
-                       return ret;
-               }
-       }
-
-       return 0;
-}
-
-/*
- * Called by ALSA when a PCM substream is opened, the runtime->hw record is
- * then initialized and any private data can be allocated. This also calls
- * startup for the cpu DAI, platform, machine and codec DAI.
- */
-static int soc_pcm_open(struct snd_pcm_substream *substream)
-{
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_pcm_runtime *runtime = substream->runtime;
-       struct snd_soc_platform *platform = rtd->platform;
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-       struct snd_soc_dai *codec_dai = rtd->codec_dai;
-       struct snd_soc_dai_driver *cpu_dai_drv = cpu_dai->driver;
-       struct snd_soc_dai_driver *codec_dai_drv = codec_dai->driver;
-       int ret = 0;
-
-       mutex_lock(&pcm_mutex);
-
-       /* startup the audio subsystem */
-       if (cpu_dai->driver->ops->startup) {
-               ret = cpu_dai->driver->ops->startup(substream, cpu_dai);
-               if (ret < 0) {
-                       printk(KERN_ERR "asoc: can't open interface %s\n",
-                               cpu_dai->name);
-                       goto out;
-               }
-       }
-
-       if (platform->driver->ops->open) {
-               ret = platform->driver->ops->open(substream);
-               if (ret < 0) {
-                       printk(KERN_ERR "asoc: can't open platform %s\n", platform->name);
-                       goto platform_err;
-               }
-       }
-
-       if (codec_dai->driver->ops->startup) {
-               ret = codec_dai->driver->ops->startup(substream, codec_dai);
-               if (ret < 0) {
-                       printk(KERN_ERR "asoc: can't open codec %s\n",
-                               codec_dai->name);
-                       goto codec_dai_err;
-               }
-       }
-
-       if (rtd->dai_link->ops && rtd->dai_link->ops->startup) {
-               ret = rtd->dai_link->ops->startup(substream);
-               if (ret < 0) {
-                       printk(KERN_ERR "asoc: %s startup failed\n", rtd->dai_link->name);
-                       goto machine_err;
-               }
-       }
-
-       /* Check that the codec and cpu DAIs are compatible */
-       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
-               runtime->hw.rate_min =
-                       max(codec_dai_drv->playback.rate_min,
-                           cpu_dai_drv->playback.rate_min);
-               runtime->hw.rate_max =
-                       min(codec_dai_drv->playback.rate_max,
-                           cpu_dai_drv->playback.rate_max);
-               runtime->hw.channels_min =
-                       max(codec_dai_drv->playback.channels_min,
-                               cpu_dai_drv->playback.channels_min);
-               runtime->hw.channels_max =
-                       min(codec_dai_drv->playback.channels_max,
-                               cpu_dai_drv->playback.channels_max);
-               runtime->hw.formats =
-                       codec_dai_drv->playback.formats & cpu_dai_drv->playback.formats;
-               runtime->hw.rates =
-                       codec_dai_drv->playback.rates & cpu_dai_drv->playback.rates;
-               if (codec_dai_drv->playback.rates
-                          & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
-                       runtime->hw.rates |= cpu_dai_drv->playback.rates;
-               if (cpu_dai_drv->playback.rates
-                          & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
-                       runtime->hw.rates |= codec_dai_drv->playback.rates;
-       } else {
-               runtime->hw.rate_min =
-                       max(codec_dai_drv->capture.rate_min,
-                           cpu_dai_drv->capture.rate_min);
-               runtime->hw.rate_max =
-                       min(codec_dai_drv->capture.rate_max,
-                           cpu_dai_drv->capture.rate_max);
-               runtime->hw.channels_min =
-                       max(codec_dai_drv->capture.channels_min,
-                               cpu_dai_drv->capture.channels_min);
-               runtime->hw.channels_max =
-                       min(codec_dai_drv->capture.channels_max,
-                               cpu_dai_drv->capture.channels_max);
-               runtime->hw.formats =
-                       codec_dai_drv->capture.formats & cpu_dai_drv->capture.formats;
-               runtime->hw.rates =
-                       codec_dai_drv->capture.rates & cpu_dai_drv->capture.rates;
-               if (codec_dai_drv->capture.rates
-                          & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
-                       runtime->hw.rates |= cpu_dai_drv->capture.rates;
-               if (cpu_dai_drv->capture.rates
-                          & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
-                       runtime->hw.rates |= codec_dai_drv->capture.rates;
-       }
-
-       snd_pcm_limit_hw_rates(runtime);
-       if (!runtime->hw.rates) {
-               printk(KERN_ERR "asoc: %s <-> %s No matching rates\n",
-                       codec_dai->name, cpu_dai->name);
-               goto config_err;
-       }
-       if (!runtime->hw.formats) {
-               printk(KERN_ERR "asoc: %s <-> %s No matching formats\n",
-                       codec_dai->name, cpu_dai->name);
-               goto config_err;
-       }
-       if (!runtime->hw.channels_min || !runtime->hw.channels_max) {
-               printk(KERN_ERR "asoc: %s <-> %s No matching channels\n",
-                               codec_dai->name, cpu_dai->name);
-               goto config_err;
-       }
-
-       /* Symmetry only applies if we've already got an active stream. */
-       if (cpu_dai->active || codec_dai->active) {
-               ret = soc_pcm_apply_symmetry(substream);
-               if (ret != 0)
-                       goto config_err;
-       }
-
-       pr_debug("asoc: %s <-> %s info:\n",
-                       codec_dai->name, cpu_dai->name);
-       pr_debug("asoc: rate mask 0x%x\n", runtime->hw.rates);
-       pr_debug("asoc: min ch %d max ch %d\n", runtime->hw.channels_min,
-                runtime->hw.channels_max);
-       pr_debug("asoc: min rate %d max rate %d\n", runtime->hw.rate_min,
-                runtime->hw.rate_max);
-
-       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
-               cpu_dai->playback_active++;
-               codec_dai->playback_active++;
-       } else {
-               cpu_dai->capture_active++;
-               codec_dai->capture_active++;
-       }
-       cpu_dai->active++;
-       codec_dai->active++;
-       rtd->codec->active++;
-       mutex_unlock(&pcm_mutex);
-       return 0;
-
-config_err:
-       if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown)
-               rtd->dai_link->ops->shutdown(substream);
-
-machine_err:
-       if (codec_dai->driver->ops->shutdown)
-               codec_dai->driver->ops->shutdown(substream, codec_dai);
-
-codec_dai_err:
-       if (platform->driver->ops->close)
-               platform->driver->ops->close(substream);
-
-platform_err:
-       if (cpu_dai->driver->ops->shutdown)
-               cpu_dai->driver->ops->shutdown(substream, cpu_dai);
-out:
-       mutex_unlock(&pcm_mutex);
-       return ret;
-}
-
-/*
- * Power down the audio subsystem pmdown_time msecs after close is called.
- * This is to ensure there are no pops or clicks in between any music tracks
- * due to DAPM power cycling.
- */
-static void close_delayed_work(struct work_struct *work)
-{
-       struct snd_soc_pcm_runtime *rtd =
-                       container_of(work, struct snd_soc_pcm_runtime, delayed_work.work);
-       struct snd_soc_dai *codec_dai = rtd->codec_dai;
-
-       mutex_lock(&pcm_mutex);
-
-       pr_debug("pop wq checking: %s status: %s waiting: %s\n",
-                codec_dai->driver->playback.stream_name,
-                codec_dai->playback_active ? "active" : "inactive",
-                codec_dai->pop_wait ? "yes" : "no");
-
-       /* are we waiting on this codec DAI stream */
-       if (codec_dai->pop_wait == 1) {
-               codec_dai->pop_wait = 0;
-               snd_soc_dapm_stream_event(rtd,
-                       codec_dai->driver->playback.stream_name,
-                       SND_SOC_DAPM_STREAM_STOP);
-       }
-
-       mutex_unlock(&pcm_mutex);
-}
-
-/*
- * Called by ALSA when a PCM substream is closed. Private data can be
- * freed here. The cpu DAI, codec DAI, machine and platform are also
- * shutdown.
- */
-static int soc_codec_close(struct snd_pcm_substream *substream)
-{
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_platform *platform = rtd->platform;
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-       struct snd_soc_dai *codec_dai = rtd->codec_dai;
-       struct snd_soc_codec *codec = rtd->codec;
-
-       mutex_lock(&pcm_mutex);
-
-       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
-               cpu_dai->playback_active--;
-               codec_dai->playback_active--;
-       } else {
-               cpu_dai->capture_active--;
-               codec_dai->capture_active--;
-       }
-
-       cpu_dai->active--;
-       codec_dai->active--;
-       codec->active--;
-
-       /* Muting the DAC suppresses artifacts caused during digital
-        * shutdown, for example from stopping clocks.
-        */
-       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-               snd_soc_dai_digital_mute(codec_dai, 1);
-
-       if (cpu_dai->driver->ops->shutdown)
-               cpu_dai->driver->ops->shutdown(substream, cpu_dai);
-
-       if (codec_dai->driver->ops->shutdown)
-               codec_dai->driver->ops->shutdown(substream, codec_dai);
-
-       if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown)
-               rtd->dai_link->ops->shutdown(substream);
-
-       if (platform->driver->ops->close)
-               platform->driver->ops->close(substream);
-       cpu_dai->runtime = NULL;
-
-       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
-               /* start delayed pop wq here for playback streams */
-               codec_dai->pop_wait = 1;
-               schedule_delayed_work(&rtd->delayed_work,
-                       msecs_to_jiffies(rtd->pmdown_time));
-       } else {
-               /* capture streams can be powered down now */
-               snd_soc_dapm_stream_event(rtd,
-                       codec_dai->driver->capture.stream_name,
-                       SND_SOC_DAPM_STREAM_STOP);
-       }
-
-       mutex_unlock(&pcm_mutex);
-       return 0;
-}
-
-/*
- * Called by ALSA when the PCM substream is prepared, can set format, sample
- * rate, etc.  This function is non atomic and can be called multiple times,
- * it can refer to the runtime info.
- */
-static int soc_pcm_prepare(struct snd_pcm_substream *substream)
-{
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_platform *platform = rtd->platform;
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-       struct snd_soc_dai *codec_dai = rtd->codec_dai;
-       int ret = 0;
-
-       mutex_lock(&pcm_mutex);
-
-       if (rtd->dai_link->ops && rtd->dai_link->ops->prepare) {
-               ret = rtd->dai_link->ops->prepare(substream);
-               if (ret < 0) {
-                       printk(KERN_ERR "asoc: machine prepare error\n");
-                       goto out;
-               }
-       }
-
-       if (platform->driver->ops->prepare) {
-               ret = platform->driver->ops->prepare(substream);
-               if (ret < 0) {
-                       printk(KERN_ERR "asoc: platform prepare error\n");
-                       goto out;
-               }
-       }
-
-       if (codec_dai->driver->ops->prepare) {
-               ret = codec_dai->driver->ops->prepare(substream, codec_dai);
-               if (ret < 0) {
-                       printk(KERN_ERR "asoc: codec DAI prepare error\n");
-                       goto out;
-               }
-       }
-
-       if (cpu_dai->driver->ops->prepare) {
-               ret = cpu_dai->driver->ops->prepare(substream, cpu_dai);
-               if (ret < 0) {
-                       printk(KERN_ERR "asoc: cpu DAI prepare error\n");
-                       goto out;
-               }
-       }
-
-       /* cancel any delayed stream shutdown that is pending */
-       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
-           codec_dai->pop_wait) {
-               codec_dai->pop_wait = 0;
-               cancel_delayed_work(&rtd->delayed_work);
-       }
-
-       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-               snd_soc_dapm_stream_event(rtd,
-                                         codec_dai->driver->playback.stream_name,
-                                         SND_SOC_DAPM_STREAM_START);
-       else
-               snd_soc_dapm_stream_event(rtd,
-                                         codec_dai->driver->capture.stream_name,
-                                         SND_SOC_DAPM_STREAM_START);
-
-       snd_soc_dai_digital_mute(codec_dai, 0);
-
-out:
-       mutex_unlock(&pcm_mutex);
-       return ret;
-}
-
-/*
- * Called by ALSA when the hardware params are set by application. This
- * function can also be called multiple times and can allocate buffers
- * (using snd_pcm_lib_* ). It's non-atomic.
- */
-static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
-                               struct snd_pcm_hw_params *params)
-{
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_platform *platform = rtd->platform;
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-       struct snd_soc_dai *codec_dai = rtd->codec_dai;
-       int ret = 0;
-
-       mutex_lock(&pcm_mutex);
-
-       if (rtd->dai_link->ops && rtd->dai_link->ops->hw_params) {
-               ret = rtd->dai_link->ops->hw_params(substream, params);
-               if (ret < 0) {
-                       printk(KERN_ERR "asoc: machine hw_params failed\n");
-                       goto out;
-               }
-       }
-
-       if (codec_dai->driver->ops->hw_params) {
-               ret = codec_dai->driver->ops->hw_params(substream, params, codec_dai);
-               if (ret < 0) {
-                       printk(KERN_ERR "asoc: can't set codec %s hw params\n",
-                               codec_dai->name);
-                       goto codec_err;
-               }
-       }
-
-       if (cpu_dai->driver->ops->hw_params) {
-               ret = cpu_dai->driver->ops->hw_params(substream, params, cpu_dai);
-               if (ret < 0) {
-                       printk(KERN_ERR "asoc: interface %s hw params failed\n",
-                               cpu_dai->name);
-                       goto interface_err;
-               }
-       }
-
-       if (platform->driver->ops->hw_params) {
-               ret = platform->driver->ops->hw_params(substream, params);
-               if (ret < 0) {
-                       printk(KERN_ERR "asoc: platform %s hw params failed\n",
-                               platform->name);
-                       goto platform_err;
-               }
-       }
-
-       rtd->rate = params_rate(params);
-
-out:
-       mutex_unlock(&pcm_mutex);
-       return ret;
-
-platform_err:
-       if (cpu_dai->driver->ops->hw_free)
-               cpu_dai->driver->ops->hw_free(substream, cpu_dai);
-
-interface_err:
-       if (codec_dai->driver->ops->hw_free)
-               codec_dai->driver->ops->hw_free(substream, codec_dai);
-
-codec_err:
-       if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free)
-               rtd->dai_link->ops->hw_free(substream);
-
-       mutex_unlock(&pcm_mutex);
-       return ret;
-}
-
-/*
- * Frees resources allocated by hw_params, can be called multiple times
- */
-static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
-{
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_platform *platform = rtd->platform;
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-       struct snd_soc_dai *codec_dai = rtd->codec_dai;
-       struct snd_soc_codec *codec = rtd->codec;
-
-       mutex_lock(&pcm_mutex);
-
-       /* apply codec digital mute */
-       if (!codec->active)
-               snd_soc_dai_digital_mute(codec_dai, 1);
-
-       /* free any machine hw params */
-       if (rtd->dai_link->ops && rtd->dai_link->ops->hw_free)
-               rtd->dai_link->ops->hw_free(substream);
-
-       /* free any DMA resources */
-       if (platform->driver->ops->hw_free)
-               platform->driver->ops->hw_free(substream);
-
-       /* now free hw params for the DAIs  */
-       if (codec_dai->driver->ops->hw_free)
-               codec_dai->driver->ops->hw_free(substream, codec_dai);
-
-       if (cpu_dai->driver->ops->hw_free)
-               cpu_dai->driver->ops->hw_free(substream, cpu_dai);
-
-       mutex_unlock(&pcm_mutex);
-       return 0;
-}
-
-static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
-{
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_platform *platform = rtd->platform;
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-       struct snd_soc_dai *codec_dai = rtd->codec_dai;
-       int ret;
-
-       if (codec_dai->driver->ops->trigger) {
-               ret = codec_dai->driver->ops->trigger(substream, cmd, codec_dai);
-               if (ret < 0)
-                       return ret;
-       }
-
-       if (platform->driver->ops->trigger) {
-               ret = platform->driver->ops->trigger(substream, cmd);
-               if (ret < 0)
-                       return ret;
-       }
-
-       if (cpu_dai->driver->ops->trigger) {
-               ret = cpu_dai->driver->ops->trigger(substream, cmd, cpu_dai);
-               if (ret < 0)
-                       return ret;
-       }
-       return 0;
-}
-
-/*
- * soc level wrapper for pointer callback
- * If cpu_dai, codec_dai, platform driver has the delay callback, than
- * the runtime->delay will be updated accordingly.
- */
-static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
-{
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_platform *platform = rtd->platform;
-       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
-       struct snd_soc_dai *codec_dai = rtd->codec_dai;
-       struct snd_pcm_runtime *runtime = substream->runtime;
-       snd_pcm_uframes_t offset = 0;
-       snd_pcm_sframes_t delay = 0;
-
-       if (platform->driver->ops->pointer)
-               offset = platform->driver->ops->pointer(substream);
-
-       if (cpu_dai->driver->ops->delay)
-               delay += cpu_dai->driver->ops->delay(substream, cpu_dai);
-
-       if (codec_dai->driver->ops->delay)
-               delay += codec_dai->driver->ops->delay(substream, codec_dai);
-
-       if (platform->driver->delay)
-               delay += platform->driver->delay(substream, codec_dai);
-
-       runtime->delay = delay;
-
-       return offset;
-}
-
-/* ASoC PCM operations */
-static struct snd_pcm_ops soc_pcm_ops = {
-       .open           = soc_pcm_open,
-       .close          = soc_codec_close,
-       .hw_params      = soc_pcm_hw_params,
-       .hw_free        = soc_pcm_hw_free,
-       .prepare        = soc_pcm_prepare,
-       .trigger        = soc_pcm_trigger,
-       .pointer        = soc_pcm_pointer,
-};
-
-#ifdef CONFIG_PM
+#ifdef CONFIG_PM_SLEEP
 /* powers down audio subsystem for suspend */
-static int soc_suspend(struct device *dev)
+int snd_soc_suspend(struct device *dev)
 {
-       struct platform_device *pdev = to_platform_device(dev);
-       struct snd_soc_card *card = platform_get_drvdata(pdev);
+       struct snd_soc_card *card = dev_get_drvdata(dev);
        struct snd_soc_codec *codec;
        int i;
 
@@ -1013,7 +530,7 @@ static int soc_suspend(struct device *dev)
        }
 
        if (card->suspend_pre)
-               card->suspend_pre(pdev, PMSG_SUSPEND);
+               card->suspend_pre(card);
 
        for (i = 0; i < card->num_rtd; i++) {
                struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
@@ -1061,6 +578,7 @@ static int soc_suspend(struct device *dev)
                        case SND_SOC_BIAS_OFF:
                                codec->driver->suspend(codec, PMSG_SUSPEND);
                                codec->suspended = 1;
+                               codec->cache_sync = 1;
                                break;
                        default:
                                dev_dbg(codec->dev, "CODEC is on over suspend\n");
@@ -1080,10 +598,11 @@ static int soc_suspend(struct device *dev)
        }
 
        if (card->suspend_post)
-               card->suspend_post(pdev, PMSG_SUSPEND);
+               card->suspend_post(card);
 
        return 0;
 }
+EXPORT_SYMBOL_GPL(snd_soc_suspend);
 
 /* deferred resume work, so resume can complete before we finished
  * setting our codec back up, which can be very slow on I2C
@@ -1092,7 +611,6 @@ 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 platform_device *pdev = to_platform_device(card->dev);
        struct snd_soc_codec *codec;
        int i;
 
@@ -1106,7 +624,7 @@ static void soc_resume_deferred(struct work_struct *work)
        snd_power_change_state(card->snd_card, SNDRV_CTL_POWER_D2);
 
        if (card->resume_pre)
-               card->resume_pre(pdev);
+               card->resume_pre(card);
 
        /* resume AC97 DAIs */
        for (i = 0; i < card->num_rtd; i++) {
@@ -1181,7 +699,7 @@ static void soc_resume_deferred(struct work_struct *work)
        }
 
        if (card->resume_post)
-               card->resume_post(pdev);
+               card->resume_post(card);
 
        dev_dbg(card->dev, "resume work completed\n");
 
@@ -1190,11 +708,10 @@ static void soc_resume_deferred(struct work_struct *work)
 }
 
 /* powers up audio subsystem after a suspend */
-static int soc_resume(struct device *dev)
+int snd_soc_resume(struct device *dev)
 {
-       struct platform_device *pdev = to_platform_device(dev);
-       struct snd_soc_card *card = platform_get_drvdata(pdev);
-       int i;
+       struct snd_soc_card *card = dev_get_drvdata(dev);
+       int i, ac97_control = 0;
 
        /* AC97 devices might have other drivers hanging off them so
         * need to resume immediately.  Other drivers don't have that
@@ -1203,21 +720,23 @@ static int soc_resume(struct device *dev)
         */
        for (i = 0; i < card->num_rtd; i++) {
                struct snd_soc_dai *cpu_dai = card->rtd[i].cpu_dai;
-               if (cpu_dai->driver->ac97_control) {
-                       dev_dbg(dev, "Resuming AC97 immediately\n");
-                       soc_resume_deferred(&card->deferred_resume_work);
-               } else {
-                       dev_dbg(dev, "Scheduling resume work\n");
-                       if (!schedule_work(&card->deferred_resume_work))
-                               dev_err(dev, "resume work item may be lost\n");
-               }
+               ac97_control |= cpu_dai->driver->ac97_control;
+       }
+       if (ac97_control) {
+               dev_dbg(dev, "Resuming AC97 immediately\n");
+               soc_resume_deferred(&card->deferred_resume_work);
+       } else {
+               dev_dbg(dev, "Scheduling resume work\n");
+               if (!schedule_work(&card->deferred_resume_work))
+                       dev_err(dev, "resume work item may be lost\n");
        }
 
        return 0;
 }
+EXPORT_SYMBOL_GPL(snd_soc_resume);
 #else
-#define soc_suspend    NULL
-#define soc_resume     NULL
+#define snd_soc_suspend NULL
+#define snd_soc_resume NULL
 #endif
 
 static struct snd_soc_dai_ops null_dai_ops = {
@@ -1230,6 +749,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;
@@ -1242,10 +762,6 @@ static int soc_bind_dai_link(struct snd_soc_card *card, int num)
        /* no, then find CPU DAI from registered DAIs*/
        list_for_each_entry(cpu_dai, &dai_list, list) {
                if (!strcmp(cpu_dai->name, dai_link->cpu_dai_name)) {
-
-                       if (!try_module_get(cpu_dai->dev->driver->owner))
-                               return -ENODEV;
-
                        rtd->cpu_dai = cpu_dai;
                        goto find_codec;
                }
@@ -1282,13 +798,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;
                }
@@ -1328,7 +849,7 @@ static void soc_remove_codec(struct snd_soc_codec *codec)
        module_put(codec->dev->driver->owner);
 }
 
-static void soc_remove_dai_link(struct snd_soc_card *card, int num)
+static void soc_remove_dai_link(struct snd_soc_card *card, int num, int order)
 {
        struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
        struct snd_soc_codec *codec = rtd->codec;
@@ -1345,7 +866,8 @@ static void soc_remove_dai_link(struct snd_soc_card *card, int num)
        }
 
        /* remove the CODEC DAI */
-       if (codec_dai && codec_dai->probed) {
+       if (codec_dai && codec_dai->probed &&
+                       codec_dai->driver->remove_order == order) {
                if (codec_dai->driver->remove) {
                        err = codec_dai->driver->remove(codec_dai);
                        if (err < 0)
@@ -1356,7 +878,8 @@ static void soc_remove_dai_link(struct snd_soc_card *card, int num)
        }
 
        /* remove the platform */
-       if (platform && platform->probed) {
+       if (platform && platform->probed &&
+                       platform->driver->remove_order == order) {
                if (platform->driver->remove) {
                        err = platform->driver->remove(platform);
                        if (err < 0)
@@ -1368,11 +891,13 @@ static void soc_remove_dai_link(struct snd_soc_card *card, int num)
        }
 
        /* remove the CODEC */
-       if (codec && codec->probed)
+       if (codec && codec->probed &&
+                       codec->driver->remove_order == order)
                soc_remove_codec(codec);
 
        /* remove the cpu_dai */
-       if (cpu_dai && cpu_dai->probed) {
+       if (cpu_dai && cpu_dai->probed &&
+                       cpu_dai->driver->remove_order == order) {
                if (cpu_dai->driver->remove) {
                        err = cpu_dai->driver->remove(cpu_dai);
                        if (err < 0)
@@ -1384,6 +909,18 @@ static void soc_remove_dai_link(struct snd_soc_card *card, int num)
        }
 }
 
+static void soc_remove_dai_links(struct snd_soc_card *card)
+{
+       int dai, order;
+
+       for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
+                       order++) {
+               for (dai = 0; dai < card->num_rtd; dai++)
+                       soc_remove_dai_link(card, dai, order);
+       }
+       card->num_rtd = 0;
+}
+
 static void soc_set_name_prefix(struct snd_soc_card *card,
                                struct snd_soc_codec *codec)
 {
@@ -1405,31 +942,95 @@ static int soc_probe_codec(struct snd_soc_card *card,
                           struct snd_soc_codec *codec)
 {
        int ret = 0;
+       const struct snd_soc_codec_driver *driver = codec->driver;
 
        codec->card = card;
        codec->dapm.card = card;
        soc_set_name_prefix(card, codec);
 
-       if (codec->driver->probe) {
-               ret = codec->driver->probe(codec);
+       if (!try_module_get(codec->dev->driver->owner))
+               return -ENODEV;
+
+       soc_init_codec_debugfs(codec);
+
+       if (driver->dapm_widgets)
+               snd_soc_dapm_new_controls(&codec->dapm, driver->dapm_widgets,
+                                         driver->num_dapm_widgets);
+
+       if (driver->probe) {
+               ret = driver->probe(codec);
                if (ret < 0) {
                        dev_err(codec->dev,
                                "asoc: failed to probe CODEC %s: %d\n",
                                codec->name, ret);
-                       return ret;
+                       goto err_probe;
                }
        }
 
-       soc_init_codec_debugfs(codec);
+       if (driver->controls)
+               snd_soc_add_controls(codec, driver->controls,
+                                    driver->num_controls);
+       if (driver->dapm_routes)
+               snd_soc_dapm_add_routes(&codec->dapm, driver->dapm_routes,
+                                       driver->num_dapm_routes);
 
        /* mark codec as probed and add to card codec list */
-       if (!try_module_get(codec->dev->driver->owner))
-               return -ENODEV;
-
        codec->probed = 1;
        list_add(&codec->card_list, &card->codec_dev_list);
        list_add(&codec->dapm.list, &card->dapm_list);
 
+       return 0;
+
+err_probe:
+       soc_cleanup_codec_debugfs(codec);
+       module_put(codec->dev->driver->owner);
+
+       return ret;
+}
+
+static int soc_probe_platform(struct snd_soc_card *card,
+                          struct snd_soc_platform *platform)
+{
+       int ret = 0;
+       const struct snd_soc_platform_driver *driver = platform->driver;
+
+       platform->card = card;
+       platform->dapm.card = card;
+
+       if (!try_module_get(platform->dev->driver->owner))
+               return -ENODEV;
+
+       if (driver->dapm_widgets)
+               snd_soc_dapm_new_controls(&platform->dapm,
+                       driver->dapm_widgets, driver->num_dapm_widgets);
+
+       if (driver->probe) {
+               ret = driver->probe(platform);
+               if (ret < 0) {
+                       dev_err(platform->dev,
+                               "asoc: failed to probe platform %s: %d\n",
+                               platform->name, ret);
+                       goto err_probe;
+               }
+       }
+
+       if (driver->controls)
+               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);
+
+       /* 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);
+
+       return 0;
+
+err_probe:
+       module_put(platform->dev->driver->owner);
+
        return ret;
 }
 
@@ -1454,6 +1055,7 @@ static int soc_post_component_init(struct snd_soc_card *card,
                rtd = &card->rtd_aux[num];
                name = aux_dev->name;
        }
+       rtd->card = card;
 
        /* machine controls, routes and widgets are not prefixed */
        temp = codec->name_prefix;
@@ -1472,14 +1074,13 @@ static int soc_post_component_init(struct snd_soc_card *card,
 
        /* Make sure all DAPM widgets are instantiated */
        snd_soc_dapm_new_widgets(&codec->dapm);
-       snd_soc_dapm_sync(&codec->dapm);
 
        /* register the rtd device */
        rtd->codec = codec;
-       rtd->card = card;
        rtd->dev.parent = card->dev;
        rtd->dev.release = rtd_release;
        rtd->dev.init_name = name;
+       mutex_init(&rtd->pcm_mutex);
        ret = device_register(&rtd->dev);
        if (ret < 0) {
                dev_err(card->dev,
@@ -1504,7 +1105,7 @@ static int soc_post_component_init(struct snd_soc_card *card,
        return 0;
 }
 
-static int soc_probe_dai_link(struct snd_soc_card *card, int num)
+static int soc_probe_dai_link(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];
@@ -1513,7 +1114,8 @@ static int soc_probe_dai_link(struct snd_soc_card *card, int num)
        struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
        int ret;
 
-       dev_dbg(card->dev, "probe %s dai link %d\n", card->name, num);
+       dev_dbg(card->dev, "probe %s dai link %d late %d\n",
+                       card->name, num, order);
 
        /* config components */
        codec_dai->codec = codec;
@@ -1525,48 +1127,43 @@ static int soc_probe_dai_link(struct snd_soc_card *card, int num)
        rtd->pmdown_time = pmdown_time;
 
        /* probe the cpu_dai */
-       if (!cpu_dai->probed) {
+       if (!cpu_dai->probed &&
+                       cpu_dai->driver->probe_order == order) {
+               if (!try_module_get(cpu_dai->dev->driver->owner))
+                       return -ENODEV;
+
                if (cpu_dai->driver->probe) {
                        ret = cpu_dai->driver->probe(cpu_dai);
                        if (ret < 0) {
                                printk(KERN_ERR "asoc: failed to probe CPU DAI %s\n",
                                                cpu_dai->name);
+                               module_put(cpu_dai->dev->driver->owner);
                                return ret;
                        }
                }
                cpu_dai->probed = 1;
-               /* mark cpu_dai as probed and add to card cpu_dai list */
+               /* mark cpu_dai as probed and add to card dai list */
                list_add(&cpu_dai->card_list, &card->dai_dev_list);
        }
 
        /* probe the CODEC */
-       if (!codec->probed) {
+       if (!codec->probed &&
+                       codec->driver->probe_order == order) {
                ret = soc_probe_codec(card, codec);
                if (ret < 0)
                        return ret;
        }
 
        /* probe the platform */
-       if (!platform->probed) {
-               if (platform->driver->probe) {
-                       ret = platform->driver->probe(platform);
-                       if (ret < 0) {
-                               printk(KERN_ERR "asoc: failed to probe platform %s\n",
-                                               platform->name);
-                               return ret;
-                       }
-               }
-               /* mark platform as probed and add to card platform list */
-
-               if (!try_module_get(platform->dev->driver->owner))
-                       return -ENODEV;
-
-               platform->probed = 1;
-               list_add(&platform->card_list, &card->platform_dev_list);
+       if (!platform->probed &&
+                       platform->driver->probe_order == order) {
+               ret = soc_probe_platform(card, platform);
+               if (ret < 0)
+                       return ret;
        }
 
        /* probe the CODEC DAI */
-       if (!codec_dai->probed) {
+       if (!codec_dai->probed && codec_dai->driver->probe_order == order) {
                if (codec_dai->driver->probe) {
                        ret = codec_dai->driver->probe(codec_dai);
                        if (ret < 0) {
@@ -1576,13 +1173,14 @@ static int soc_probe_dai_link(struct snd_soc_card *card, int num)
                        }
                }
 
-               /* mark cpu_dai as probed and add to card cpu_dai list */
+               /* mark codec_dai as probed and add to card dai list */
                codec_dai->probed = 1;
                list_add(&codec_dai->card_list, &card->dai_dev_list);
        }
 
-       /* DAPM dai link stream work */
-       INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
+       /* complete DAI probe during last probe */
+       if (order != SND_SOC_COMP_ORDER_LAST)
+               return 0;
 
        ret = soc_post_component_init(card, codec, num, 0);
        if (ret)
@@ -1669,9 +1267,6 @@ static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
        goto out;
 
 found:
-       if (!try_module_get(codec->dev->driver->owner))
-               return -ENODEV;
-
        ret = soc_probe_codec(card, codec);
        if (ret < 0)
                return ret;
@@ -1721,11 +1316,10 @@ static int snd_soc_init_codec_cache(struct snd_soc_codec *codec,
 
 static void snd_soc_instantiate_card(struct snd_soc_card *card)
 {
-       struct platform_device *pdev = to_platform_device(card->dev);
        struct snd_soc_codec *codec;
        struct snd_soc_codec_conf *codec_conf;
        enum snd_soc_compress_type compress_type;
-       int ret, i;
+       int ret, i, order;
 
        mutex_lock(&card->mutex);
 
@@ -1778,24 +1372,41 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
        }
        card->snd_card->dev = card->dev;
 
-#ifdef CONFIG_PM
+       card->dapm.bias_level = SND_SOC_BIAS_OFF;
+       card->dapm.dev = card->dev;
+       card->dapm.card = card;
+       list_add(&card->dapm.list, &card->dapm_list);
+
+#ifdef CONFIG_DEBUG_FS
+       snd_soc_dapm_debugfs_init(&card->dapm, card->debugfs_card_root);
+#endif
+
+#ifdef CONFIG_PM_SLEEP
        /* deferred resume work */
        INIT_WORK(&card->deferred_resume_work, soc_resume_deferred);
 #endif
 
+       if (card->dapm_widgets)
+               snd_soc_dapm_new_controls(&card->dapm, card->dapm_widgets,
+                                         card->num_dapm_widgets);
+
        /* initialise the sound card only once */
        if (card->probe) {
-               ret = card->probe(pdev);
+               ret = card->probe(card);
                if (ret < 0)
                        goto card_probe_error;
        }
 
-       for (i = 0; i < card->num_links; i++) {
-               ret = soc_probe_dai_link(card, i);
-               if (ret < 0) {
-                       pr_err("asoc: failed to instantiate card %s: %d\n",
+       /* early DAI link probe */
+       for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
+                       order++) {
+               for (i = 0; i < card->num_links; i++) {
+                       ret = soc_probe_dai_link(card, i, order);
+                       if (ret < 0) {
+                               pr_err("asoc: failed to instantiate card %s: %d\n",
                               card->name, ret);
-                       goto probe_dai_err;
+                               goto probe_dai_err;
+                       }
                }
        }
 
@@ -1808,10 +1419,45 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
                }
        }
 
+       /* We should have a non-codec control add function but we don't */
+       if (card->controls)
+               snd_soc_add_controls(list_first_entry(&card->codec_dev_list,
+                                                     struct snd_soc_codec,
+                                                     card_list),
+                                    card->controls,
+                                    card->num_controls);
+
+       if (card->dapm_routes)
+               snd_soc_dapm_add_routes(&card->dapm, card->dapm_routes,
+                                       card->num_dapm_routes);
+
        snprintf(card->snd_card->shortname, sizeof(card->snd_card->shortname),
-                "%s",  card->name);
-       snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
                 "%s", card->name);
+       snprintf(card->snd_card->longname, sizeof(card->snd_card->longname),
+                "%s", card->long_name ? card->long_name : card->name);
+       snprintf(card->snd_card->driver, sizeof(card->snd_card->driver),
+                "%s", card->driver_name ? card->driver_name : card->name);
+       for (i = 0; i < ARRAY_SIZE(card->snd_card->driver); i++) {
+               switch (card->snd_card->driver[i]) {
+               case '_':
+               case '-':
+               case '\0':
+                       break;
+               default:
+                       if (!isalnum(card->snd_card->driver[i]))
+                               card->snd_card->driver[i] = '_';
+                       break;
+               }
+       }
+
+       if (card->late_probe) {
+               ret = card->late_probe(card);
+               if (ret < 0) {
+                       dev_err(card->dev, "%s late_probe() failed: %d\n",
+                               card->name, ret);
+                       goto probe_aux_dev_err;
+               }
+       }
 
        ret = snd_card_register(card->snd_card);
        if (ret < 0) {
@@ -1841,12 +1487,11 @@ probe_aux_dev_err:
                soc_remove_aux_dev(card, i);
 
 probe_dai_err:
-       for (i = 0; i < card->num_links; i++)
-               soc_remove_dai_link(card, i);
+       soc_remove_dai_links(card);
 
 card_probe_error:
        if (card->remove)
-               card->remove(pdev);
+               card->remove(card);
 
        snd_card_free(card->snd_card);
 
@@ -1870,16 +1515,15 @@ static int soc_probe(struct platform_device *pdev)
        struct snd_soc_card *card = platform_get_drvdata(pdev);
        int ret = 0;
 
+       /*
+        * no card, so machine driver should be registering card
+        * we should not be here in that case so ret error
+        */
+       if (!card)
+               return -EINVAL;
+
        /* Bodge while we unpick instantiation */
        card->dev = &pdev->dev;
-       INIT_LIST_HEAD(&card->dai_dev_list);
-       INIT_LIST_HEAD(&card->codec_dev_list);
-       INIT_LIST_HEAD(&card->platform_dev_list);
-       INIT_LIST_HEAD(&card->widgets);
-       INIT_LIST_HEAD(&card->paths);
-       INIT_LIST_HEAD(&card->dapm_list);
-
-       soc_init_card_debugfs(card);
 
        ret = snd_soc_register_card(card);
        if (ret != 0) {
@@ -1890,45 +1534,49 @@ static int soc_probe(struct platform_device *pdev)
        return 0;
 }
 
-/* removes a socdev */
-static int soc_remove(struct platform_device *pdev)
+static int soc_cleanup_card_resources(struct snd_soc_card *card)
 {
-       struct snd_soc_card *card = platform_get_drvdata(pdev);
        int i;
 
-       if (card->instantiated) {
+       /* make sure any delayed work runs */
+       for (i = 0; i < card->num_rtd; i++) {
+               struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
+               flush_delayed_work_sync(&rtd->delayed_work);
+       }
 
-               /* make sure any delayed work runs */
-               for (i = 0; i < card->num_rtd; i++) {
-                       struct snd_soc_pcm_runtime *rtd = &card->rtd[i];
-                       flush_delayed_work_sync(&rtd->delayed_work);
-               }
+       /* remove auxiliary devices */
+       for (i = 0; i < card->num_aux_devs; i++)
+               soc_remove_aux_dev(card, i);
 
-               /* remove auxiliary devices */
-               for (i = 0; i < card->num_aux_devs; i++)
-                       soc_remove_aux_dev(card, i);
+       /* remove and free each DAI */
+       soc_remove_dai_links(card);
 
-               /* remove and free each DAI */
-               for (i = 0; i < card->num_rtd; i++)
-                       soc_remove_dai_link(card, i);
+       soc_cleanup_card_debugfs(card);
 
-               soc_cleanup_card_debugfs(card);
+       /* remove the card */
+       if (card->remove)
+               card->remove(card);
 
-               /* remove the card */
-               if (card->remove)
-                       card->remove(pdev);
+       snd_soc_dapm_free(&card->dapm);
 
-               kfree(card->rtd);
-               snd_card_free(card->snd_card);
-       }
-       snd_soc_unregister_card(card);
+       kfree(card->rtd);
+       snd_card_free(card->snd_card);
        return 0;
+
 }
 
-static int soc_poweroff(struct device *dev)
+/* removes a socdev */
+static int soc_remove(struct platform_device *pdev)
 {
-       struct platform_device *pdev = to_platform_device(dev);
        struct snd_soc_card *card = platform_get_drvdata(pdev);
+
+       snd_soc_unregister_card(card);
+       return 0;
+}
+
+int snd_soc_poweroff(struct device *dev)
+{
+       struct snd_soc_card *card = dev_get_drvdata(dev);
        int i;
 
        if (!card->instantiated)
@@ -1945,80 +1593,26 @@ static int soc_poweroff(struct device *dev)
 
        return 0;
 }
+EXPORT_SYMBOL_GPL(snd_soc_poweroff);
 
-static const struct dev_pm_ops soc_pm_ops = {
-       .suspend = soc_suspend,
-       .resume = soc_resume,
-       .poweroff = soc_poweroff,
+const struct dev_pm_ops snd_soc_pm_ops = {
+       .suspend = snd_soc_suspend,
+       .resume = snd_soc_resume,
+       .poweroff = snd_soc_poweroff,
 };
+EXPORT_SYMBOL_GPL(snd_soc_pm_ops);
 
 /* ASoC platform driver */
 static struct platform_driver soc_driver = {
        .driver         = {
                .name           = "soc-audio",
                .owner          = THIS_MODULE,
-               .pm             = &soc_pm_ops,
+               .pm             = &snd_soc_pm_ops,
        },
        .probe          = soc_probe,
        .remove         = soc_remove,
 };
 
-/* create a new pcm */
-static int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int 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;
-       struct snd_pcm *pcm;
-       char new_name[64];
-       int ret = 0, playback = 0, capture = 0;
-
-       /* check client and interface hw capabilities */
-       snprintf(new_name, sizeof(new_name), "%s %s-%d",
-                       rtd->dai_link->stream_name, codec_dai->name, num);
-
-       if (codec_dai->driver->playback.channels_min)
-               playback = 1;
-       if (codec_dai->driver->capture.channels_min)
-               capture = 1;
-
-       dev_dbg(rtd->card->dev, "registered pcm #%d %s\n",num,new_name);
-       ret = snd_pcm_new(rtd->card->snd_card, new_name,
-                       num, playback, capture, &pcm);
-       if (ret < 0) {
-               printk(KERN_ERR "asoc: can't create pcm for codec %s\n", codec->name);
-               return ret;
-       }
-
-       rtd->pcm = pcm;
-       pcm->private_data = rtd;
-       soc_pcm_ops.mmap = platform->driver->ops->mmap;
-       soc_pcm_ops.pointer = platform->driver->ops->pointer;
-       soc_pcm_ops.ioctl = platform->driver->ops->ioctl;
-       soc_pcm_ops.copy = platform->driver->ops->copy;
-       soc_pcm_ops.silence = platform->driver->ops->silence;
-       soc_pcm_ops.ack = platform->driver->ops->ack;
-       soc_pcm_ops.page = platform->driver->ops->page;
-
-       if (playback)
-               snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
-
-       if (capture)
-               snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
-
-       ret = platform->driver->pcm_new(rtd->card->snd_card, codec_dai, pcm);
-       if (ret < 0) {
-               printk(KERN_ERR "asoc: platform pcm constructor failed\n");
-               return ret;
-       }
-
-       pcm->private_free = platform->driver->pcm_free;
-       printk(KERN_INFO "asoc: %s <-> %s mapping ok\n", codec_dai->name,
-               cpu_dai->name);
-       return ret;
-}
-
 /**
  * snd_soc_codec_volatile_register: Report if a register is volatile.
  *
@@ -2027,15 +1621,84 @@ static int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
  *
  * Boolean function indiciating if a CODEC register is volatile.
  */
-int snd_soc_codec_volatile_register(struct snd_soc_codec *codec, int reg)
+int snd_soc_codec_volatile_register(struct snd_soc_codec *codec,
+                                   unsigned int reg)
 {
-       if (codec->driver->volatile_register)
-               return codec->driver->volatile_register(codec, reg);
+       if (codec->volatile_register)
+               return codec->volatile_register(codec, reg);
        else
                return 0;
 }
 EXPORT_SYMBOL_GPL(snd_soc_codec_volatile_register);
 
+/**
+ * snd_soc_codec_readable_register: Report if a register is readable.
+ *
+ * @codec: CODEC to query.
+ * @reg: Register to query.
+ *
+ * Boolean function indicating if a CODEC register is readable.
+ */
+int snd_soc_codec_readable_register(struct snd_soc_codec *codec,
+                                   unsigned int reg)
+{
+       if (codec->readable_register)
+               return codec->readable_register(codec, reg);
+       else
+               return 1;
+}
+EXPORT_SYMBOL_GPL(snd_soc_codec_readable_register);
+
+/**
+ * snd_soc_codec_writable_register: Report if a register is writable.
+ *
+ * @codec: CODEC to query.
+ * @reg: Register to query.
+ *
+ * Boolean function indicating if a CODEC register is writable.
+ */
+int snd_soc_codec_writable_register(struct snd_soc_codec *codec,
+                                   unsigned int reg)
+{
+       if (codec->writable_register)
+               return codec->writable_register(codec, reg);
+       else
+               return 1;
+}
+EXPORT_SYMBOL_GPL(snd_soc_codec_writable_register);
+
+int snd_soc_platform_read(struct snd_soc_platform *platform,
+                                       unsigned int reg)
+{
+       unsigned int ret;
+
+       if (!platform->driver->read) {
+               dev_err(platform->dev, "platform has no read back\n");
+               return -1;
+       }
+
+       ret = platform->driver->read(platform, reg);
+       dev_dbg(platform->dev, "read %x => %x\n", reg, ret);
+       trace_snd_soc_preg_read(platform, reg, ret);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_platform_read);
+
+int snd_soc_platform_write(struct snd_soc_platform *platform,
+                                        unsigned int reg, unsigned int val)
+{
+       if (!platform->driver->write) {
+               dev_err(platform->dev, "platform has no write back\n");
+               return -1;
+       }
+
+       dev_dbg(platform->dev, "write %x = %x\n", reg, val);
+       trace_snd_soc_preg_write(platform, reg, val);
+       return platform->driver->write(platform, reg, val);
+}
+EXPORT_SYMBOL_GPL(snd_soc_platform_write);
+
 /**
  * snd_soc_new_ac97_codec - initailise AC97 device
  * @codec: audio codec
@@ -2118,6 +1781,13 @@ unsigned int snd_soc_write(struct snd_soc_codec *codec,
 }
 EXPORT_SYMBOL_GPL(snd_soc_write);
 
+unsigned int snd_soc_bulk_write_raw(struct snd_soc_codec *codec,
+                                   unsigned int reg, const void *data, size_t len)
+{
+       return codec->bulk_write_raw(codec, reg, data, len);
+}
+EXPORT_SYMBOL_GPL(snd_soc_bulk_write_raw);
+
 /**
  * snd_soc_update_bits - update codec register bits
  * @codec: audio codec
@@ -2141,7 +1811,7 @@ int snd_soc_update_bits(struct snd_soc_codec *codec, unsigned short reg,
                return ret;
 
        old = ret;
-       new = (old & ~mask) | value;
+       new = (old & ~mask) | (value & mask);
        change = old != new;
        if (change) {
                ret = snd_soc_write(codec, reg, new);
@@ -2232,22 +1902,45 @@ EXPORT_SYMBOL_GPL(snd_soc_set_runtime_hwparams);
  * @_template: control template
  * @data: control private data
  * @long_name: control long name
+ * @prefix: control name prefix
  *
  * Create a new mixer control from a template control.
  *
  * Returns 0 for success, else error.
  */
 struct snd_kcontrol *snd_soc_cnew(const struct snd_kcontrol_new *_template,
-       void *data, char *long_name)
+                                 void *data, char *long_name,
+                                 const char *prefix)
 {
        struct snd_kcontrol_new template;
+       struct snd_kcontrol *kcontrol;
+       char *name = NULL;
+       int name_len;
 
        memcpy(&template, _template, sizeof(template));
-       if (long_name)
-               template.name = long_name;
        template.index = 0;
 
-       return snd_ctl_new1(&template, data);
+       if (!long_name)
+               long_name = template.name;
+
+       if (prefix) {
+               name_len = strlen(long_name) + strlen(prefix) + 2;
+               name = kmalloc(name_len, GFP_KERNEL);
+               if (!name)
+                       return NULL;
+
+               snprintf(name, name_len, "%s %s", prefix, long_name);
+
+               template.name = name;
+       } else {
+               template.name = long_name;
+       }
+
+       kcontrol = snd_ctl_new1(&template, data);
+
+       kfree(name);
+
+       return kcontrol;
 }
 EXPORT_SYMBOL_GPL(snd_soc_cnew);
 
@@ -2266,22 +1959,16 @@ int snd_soc_add_controls(struct snd_soc_codec *codec,
        const struct snd_kcontrol_new *controls, int num_controls)
 {
        struct snd_card *card = codec->card->snd_card;
-       char prefixed_name[44], *name;
        int err, i;
 
        for (i = 0; i < num_controls; i++) {
                const struct snd_kcontrol_new *control = &controls[i];
-               if (codec->name_prefix) {
-                       snprintf(prefixed_name, sizeof(prefixed_name), "%s %s",
-                                codec->name_prefix, control->name);
-                       name = prefixed_name;
-               } else {
-                       name = control->name;
-               }
-               err = snd_ctl_add(card, snd_soc_cnew(control, codec, name));
+               err = snd_ctl_add(card, snd_soc_cnew(control, codec,
+                                                    control->name,
+                                                    codec->name_prefix));
                if (err < 0) {
                        dev_err(codec->dev, "%s: Failed to add %s: %d\n",
-                               codec->name, name, err);
+                               codec->name, control->name, err);
                        return err;
                }
        }
@@ -2290,6 +1977,36 @@ int snd_soc_add_controls(struct snd_soc_codec *codec,
 }
 EXPORT_SYMBOL_GPL(snd_soc_add_controls);
 
+/**
+ * snd_soc_add_platform_controls - add an array of controls to a platform.
+ * Convienience function to add a list of controls.
+ *
+ * @platform: platform 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_platform_controls(struct snd_soc_platform *platform,
+       const struct snd_kcontrol_new *controls, int num_controls)
+{
+       struct snd_card *card = platform->card->snd_card;
+       int err, i;
+
+       for (i = 0; i < num_controls; i++) {
+               const struct snd_kcontrol_new *control = &controls[i];
+               err = snd_ctl_add(card, snd_soc_cnew(control, platform,
+                               control->name, NULL));
+               if (err < 0) {
+                       dev_err(platform->dev, "Failed to add %s %d\n",control->name, err);
+                       return err;
+               }
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_add_platform_controls);
+
 /**
  * snd_soc_info_enum_double - enumerated double mixer info callback
  * @kcontrol: mixer control
@@ -2962,11 +2679,33 @@ int snd_soc_dai_set_sysclk(struct snd_soc_dai *dai, int clk_id,
 {
        if (dai->driver && dai->driver->ops->set_sysclk)
                return dai->driver->ops->set_sysclk(dai, clk_id, freq, dir);
+       else if (dai->codec && dai->codec->driver->set_sysclk)
+               return dai->codec->driver->set_sysclk(dai->codec, clk_id,
+                                                     freq, dir);
        else
                return -EINVAL;
 }
 EXPORT_SYMBOL_GPL(snd_soc_dai_set_sysclk);
 
+/**
+ * snd_soc_codec_set_sysclk - configure CODEC system or master clock.
+ * @codec: CODEC
+ * @clk_id: DAI specific clock ID
+ * @freq: new clock frequency in Hz
+ * @dir: new clock direction - input/output.
+ *
+ * Configures the CODEC master (MCLK) or system (SYSCLK) clocking.
+ */
+int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
+       unsigned int freq, int dir)
+{
+       if (codec->driver->set_sysclk)
+               return codec->driver->set_sysclk(codec, clk_id, freq, dir);
+       else
+               return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(snd_soc_codec_set_sysclk);
+
 /**
  * snd_soc_dai_set_clkdiv - configure DAI clock dividers.
  * @dai: DAI
@@ -3003,11 +2742,35 @@ int snd_soc_dai_set_pll(struct snd_soc_dai *dai, int pll_id, int source,
        if (dai->driver && dai->driver->ops->set_pll)
                return dai->driver->ops->set_pll(dai, pll_id, source,
                                         freq_in, freq_out);
+       else if (dai->codec && dai->codec->driver->set_pll)
+               return dai->codec->driver->set_pll(dai->codec, pll_id, source,
+                                                  freq_in, freq_out);
        else
                return -EINVAL;
 }
 EXPORT_SYMBOL_GPL(snd_soc_dai_set_pll);
 
+/*
+ * snd_soc_codec_set_pll - configure codec PLL.
+ * @codec: CODEC
+ * @pll_id: DAI specific PLL ID
+ * @source: DAI specific source for the PLL
+ * @freq_in: PLL input clock frequency in Hz
+ * @freq_out: requested PLL output clock frequency in Hz
+ *
+ * Configures and enables PLL to generate output clock based on input clock.
+ */
+int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
+                         unsigned int freq_in, unsigned int freq_out)
+{
+       if (codec->driver->set_pll)
+               return codec->driver->set_pll(codec, pll_id, source,
+                                             freq_in, freq_out);
+       else
+               return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(snd_soc_codec_set_pll);
+
 /**
  * snd_soc_dai_set_fmt - configure DAI hardware audio format.
  * @dai: DAI
@@ -3107,17 +2870,20 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_digital_mute);
  *
  * @card: Card to register
  *
- * Note that currently this is an internal only function: it will be
- * exposed to machine drivers after further backporting of ASoC v2
- * registration APIs.
  */
-static int snd_soc_register_card(struct snd_soc_card *card)
+int snd_soc_register_card(struct snd_soc_card *card)
 {
        int i;
 
        if (!card->name || !card->dev)
                return -EINVAL;
 
+       dev_set_drvdata(card->dev, card);
+
+       snd_soc_initialize_card_lists(card);
+
+       soc_init_card_debugfs(card);
+
        card->rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime) *
                            (card->num_links + card->num_aux_devs),
                            GFP_KERNEL);
@@ -3141,18 +2907,18 @@ static int snd_soc_register_card(struct snd_soc_card *card)
 
        return 0;
 }
+EXPORT_SYMBOL_GPL(snd_soc_register_card);
 
 /**
  * snd_soc_unregister_card - Unregister a card with the ASoC core
  *
  * @card: Card to unregister
  *
- * Note that currently this is an internal only function: it will be
- * exposed to machine drivers after further backporting of ASoC v2
- * registration APIs.
  */
-static int snd_soc_unregister_card(struct snd_soc_card *card)
+int snd_soc_unregister_card(struct snd_soc_card *card)
 {
+       if (card->instantiated)
+               soc_cleanup_card_resources(card);
        mutex_lock(&client_mutex);
        list_del(&card->list);
        mutex_unlock(&client_mutex);
@@ -3160,6 +2926,7 @@ static int snd_soc_unregister_card(struct snd_soc_card *card)
 
        return 0;
 }
+EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
 
 /*
  * Simplify DAI link configuration by removing ".-1" from device names
@@ -3234,7 +3001,7 @@ int snd_soc_register_dai(struct device *dev,
 
        dai = kzalloc(sizeof(struct snd_soc_dai), GFP_KERNEL);
        if (dai == NULL)
-                       return -ENOMEM;
+               return -ENOMEM;
 
        /* create DAI component name */
        dai->name = fmt_single_name(dev, &dai->id);
@@ -3373,7 +3140,7 @@ int snd_soc_register_platform(struct device *dev,
 
        platform = kzalloc(sizeof(struct snd_soc_platform), GFP_KERNEL);
        if (platform == NULL)
-                       return -ENOMEM;
+               return -ENOMEM;
 
        /* create platform component name */
        platform->name = fmt_single_name(dev, &platform->id);
@@ -3384,6 +3151,8 @@ int snd_soc_register_platform(struct device *dev,
 
        platform->dev = dev;
        platform->driver = platform_drv;
+       platform->dapm.dev = dev;
+       platform->dapm.platform = platform;
 
        mutex_lock(&client_mutex);
        list_add(&platform->list, &platform_list);
@@ -3489,9 +3258,13 @@ int snd_soc_register_codec(struct device *dev,
 
        codec->write = codec_drv->write;
        codec->read = codec_drv->read;
+       codec->volatile_register = codec_drv->volatile_register;
+       codec->readable_register = codec_drv->readable_register;
+       codec->writable_register = codec_drv->writable_register;
        codec->dapm.bias_level = SND_SOC_BIAS_OFF;
        codec->dapm.dev = dev;
        codec->dapm.codec = codec;
+       codec->dapm.seq_notifier = codec_drv->seq_notifier;
        codec->dev = dev;
        codec->driver = codec_drv;
        codec->num_dai = num_dai;
@@ -3517,6 +3290,15 @@ int snd_soc_register_codec(struct device *dev,
                }
        }
 
+       if (codec_drv->reg_access_size && codec_drv->reg_access_default) {
+               if (!codec->volatile_register)
+                       codec->volatile_register = snd_soc_default_volatile_register;
+               if (!codec->readable_register)
+                       codec->readable_register = snd_soc_default_readable_register;
+               if (!codec->writable_register)
+                       codec->writable_register = snd_soc_default_writable_register;
+       }
+
        for (i = 0; i < num_dai; i++) {
                fixup_codec_formats(&dai_drv[i].playback);
                fixup_codec_formats(&dai_drv[i].capture);
@@ -3603,12 +3385,16 @@ static int __init snd_soc_init(void)
                pr_warn("ASoC: Failed to create platform list debugfs file\n");
 #endif
 
+       snd_soc_util_init();
+
        return platform_driver_register(&soc_driver);
 }
 module_init(snd_soc_init);
 
 static void __exit snd_soc_exit(void)
 {
+       snd_soc_util_exit();
+
 #ifdef CONFIG_DEBUG_FS
        debugfs_remove_recursive(snd_soc_debugfs_root);
 #endif