Merge commit 'v2.6.34-rc1' into for-2.6.35
[pandora-kernel.git] / sound / soc / soc-core.c
index c8b0556..06c38d1 100644 (file)
@@ -315,7 +315,7 @@ static int soc_pcm_apply_symmetry(struct snd_pcm_substream *substream)
 
        if (codec_dai->symmetric_rates || cpu_dai->symmetric_rates ||
            machine->symmetric_rates) {
-               dev_dbg(card->dev, "Symmetry forces %dHz rate\n", 
+               dev_dbg(card->dev, "Symmetry forces %dHz rate\n",
                        machine->rate);
 
                ret = snd_pcm_hw_constraint_minmax(substream->runtime,
@@ -454,12 +454,15 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
        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 = 1;
-       else
-               cpu_dai->capture.active = codec_dai->capture.active = 1;
-       cpu_dai->active = codec_dai->active = 1;
-       cpu_dai->runtime = runtime;
+       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++;
        card->codec->active++;
        mutex_unlock(&pcm_mutex);
        return 0;
@@ -535,15 +538,16 @@ static int soc_codec_close(struct snd_pcm_substream *substream)
 
        mutex_lock(&pcm_mutex);
 
-       if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-               cpu_dai->playback.active = codec_dai->playback.active = 0;
-       else
-               cpu_dai->capture.active = codec_dai->capture.active = 0;
-
-       if (codec_dai->playback.active == 0 &&
-               codec_dai->capture.active == 0) {
-               cpu_dai->active = codec_dai->active = 0;
+       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
@@ -563,7 +567,6 @@ static int soc_codec_close(struct snd_pcm_substream *substream)
 
        if (platform->pcm_ops->close)
                platform->pcm_ops->close(substream);
-       cpu_dai->runtime = NULL;
 
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
                /* start delayed pop wq here for playback streams */
@@ -801,6 +804,41 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
        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_device *socdev = rtd->socdev;
+       struct snd_soc_card *card = socdev->card;
+       struct snd_soc_platform *platform = card->platform;
+       struct snd_soc_dai_link *machine = rtd->dai;
+       struct snd_soc_dai *cpu_dai = machine->cpu_dai;
+       struct snd_soc_dai *codec_dai = machine->codec_dai;
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       snd_pcm_uframes_t offset = 0;
+       snd_pcm_sframes_t delay = 0;
+
+       if (platform->pcm_ops->pointer)
+               offset = platform->pcm_ops->pointer(substream);
+
+       if (cpu_dai->ops->delay)
+               delay += cpu_dai->ops->delay(substream, cpu_dai);
+
+       if (codec_dai->ops->delay)
+               delay += codec_dai->ops->delay(substream, codec_dai);
+
+       if (platform->delay)
+               delay += platform->delay(substream, codec_dai);
+
+       runtime->delay = delay;
+
+       return offset;
+}
+
 /* ASoC PCM operations */
 static struct snd_pcm_ops soc_pcm_ops = {
        .open           = soc_pcm_open,
@@ -809,6 +847,7 @@ static struct snd_pcm_ops soc_pcm_ops = {
        .hw_free        = soc_pcm_hw_free,
        .prepare        = soc_pcm_prepare,
        .trigger        = soc_pcm_trigger,
+       .pointer        = soc_pcm_pointer,
 };
 
 #ifdef CONFIG_PM
@@ -858,7 +897,7 @@ static int soc_suspend(struct device *dev)
                if (cpu_dai->suspend && !cpu_dai->ac97_control)
                        cpu_dai->suspend(cpu_dai);
                if (platform->suspend)
-                       platform->suspend(cpu_dai);
+                       platform->suspend(&card->dai_link[i]);
        }
 
        /* close any waiting streams and save state */
@@ -947,7 +986,7 @@ static void soc_resume_deferred(struct work_struct *work)
                if (cpu_dai->resume && !cpu_dai->ac97_control)
                        cpu_dai->resume(cpu_dai);
                if (platform->resume)
-                       platform->resume(cpu_dai);
+                       platform->resume(&card->dai_link[i]);
        }
 
        if (card->resume_post)
@@ -1335,7 +1374,6 @@ static int soc_new_pcm(struct snd_soc_device *socdev,
        dai_link->pcm = pcm;
        pcm->private_data = rtd;
        soc_pcm_ops.mmap = platform->pcm_ops->mmap;
-       soc_pcm_ops.pointer = platform->pcm_ops->pointer;
        soc_pcm_ops.ioctl = platform->pcm_ops->ioctl;
        soc_pcm_ops.copy = platform->pcm_ops->copy;
        soc_pcm_ops.silence = platform->pcm_ops->silence;