Merge branch 'asoc-4.18' into asoc-4.19 wmadsp dep
[sfrench/cifs-2.6.git] / sound / soc / soc-pcm.c
index 114e6c060cae8cb35833bdb3555f6620e5f2e6db..e8b98bfd4cf13bcb56d118a4c87a6e08ce5139e2 100644 (file)
@@ -1179,6 +1179,9 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
        snd_pcm_sframes_t codec_delay = 0;
        int i;
 
+       /* clearing the previous total delay */
+       runtime->delay = 0;
+
        for_each_rtdcom(rtd, rtdcom) {
                component = rtdcom->component;
 
@@ -1190,6 +1193,8 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
                offset = component->driver->ops->pointer(substream);
                break;
        }
+       /* base delay if assigned in pointer callback */
+       delay = runtime->delay;
 
        if (cpu_dai->driver->ops->delay)
                delay += cpu_dai->driver->ops->delay(substream, cpu_dai);
@@ -1707,6 +1712,14 @@ static void dpcm_runtime_merge_format(struct snd_pcm_substream *substream,
                int i;
 
                for (i = 0; i < be->num_codecs; i++) {
+                       /*
+                        * Skip CODECs which don't support the current stream
+                        * type. See soc_pcm_init_runtime_hw() for more details
+                        */
+                       if (!snd_soc_dai_stream_valid(be->codec_dais[i],
+                                                     stream))
+                               continue;
+
                        codec_dai_drv = be->codec_dais[i]->driver;
                        if (stream == SNDRV_PCM_STREAM_PLAYBACK)
                                codec_stream = &codec_dai_drv->playback;
@@ -1769,6 +1782,64 @@ static void dpcm_runtime_merge_chan(struct snd_pcm_substream *substream,
        }
 }
 
+static void dpcm_runtime_merge_rate(struct snd_pcm_substream *substream,
+                                   unsigned int *rates,
+                                   unsigned int *rate_min,
+                                   unsigned int *rate_max)
+{
+       struct snd_soc_pcm_runtime *fe = substream->private_data;
+       struct snd_soc_dpcm *dpcm;
+       int stream = substream->stream;
+
+       if (!fe->dai_link->dpcm_merged_rate)
+               return;
+
+       /*
+        * It returns merged BE codec channel;
+        * if FE want to use it (= dpcm_merged_chan)
+        */
+
+       list_for_each_entry(dpcm, &fe->dpcm[stream].be_clients, list_be) {
+               struct snd_soc_pcm_runtime *be = dpcm->be;
+               struct snd_soc_dai_driver *cpu_dai_drv =  be->cpu_dai->driver;
+               struct snd_soc_dai_driver *codec_dai_drv;
+               struct snd_soc_pcm_stream *codec_stream;
+               struct snd_soc_pcm_stream *cpu_stream;
+               int i;
+
+               if (stream == SNDRV_PCM_STREAM_PLAYBACK)
+                       cpu_stream = &cpu_dai_drv->playback;
+               else
+                       cpu_stream = &cpu_dai_drv->capture;
+
+               *rate_min = max(*rate_min, cpu_stream->rate_min);
+               *rate_max = min_not_zero(*rate_max, cpu_stream->rate_max);
+               *rates = snd_pcm_rate_mask_intersect(*rates, cpu_stream->rates);
+
+               for (i = 0; i < be->num_codecs; i++) {
+                       /*
+                        * Skip CODECs which don't support the current stream
+                        * type. See soc_pcm_init_runtime_hw() for more details
+                        */
+                       if (!snd_soc_dai_stream_valid(be->codec_dais[i],
+                                                     stream))
+                               continue;
+
+                       codec_dai_drv = be->codec_dais[i]->driver;
+                       if (stream == SNDRV_PCM_STREAM_PLAYBACK)
+                               codec_stream = &codec_dai_drv->playback;
+                       else
+                               codec_stream = &codec_dai_drv->capture;
+
+                       *rate_min = max(*rate_min, codec_stream->rate_min);
+                       *rate_max = min_not_zero(*rate_max,
+                                                codec_stream->rate_max);
+                       *rates = snd_pcm_rate_mask_intersect(*rates,
+                                               codec_stream->rates);
+               }
+       }
+}
+
 static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream)
 {
        struct snd_pcm_runtime *runtime = substream->runtime;
@@ -1784,6 +1855,8 @@ static void dpcm_set_fe_runtime(struct snd_pcm_substream *substream)
        dpcm_runtime_merge_format(substream, &runtime->hw.formats);
        dpcm_runtime_merge_chan(substream, &runtime->hw.channels_min,
                                &runtime->hw.channels_max);
+       dpcm_runtime_merge_rate(substream, &runtime->hw.rates,
+                               &runtime->hw.rate_min, &runtime->hw.rate_max);
 }
 
 static int dpcm_fe_dai_do_trigger(struct snd_pcm_substream *substream, int cmd);