Merge tag 'arc-fixes-for-3.13' of git://git.kernel.org/pub/scm/linux/kernel/git/vgupt...
[firefly-linux-kernel-4.4.55.git] / sound / soc / soc-pcm.c
index d4498723b375025cfacc21246f6f018be1c8e321..11a90cd027faca2956172f3dfa92f6d2ee46a8fe 100644 (file)
@@ -19,6 +19,7 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/delay.h>
+#include <linux/pinctrl/consumer.h>
 #include <linux/pm_runtime.h>
 #include <linux/slab.h>
 #include <linux/workqueue.h>
@@ -147,12 +148,12 @@ static void soc_pcm_apply_msb(struct snd_pcm_substream *substream,
        }
 }
 
-static void soc_pcm_init_runtime_hw(struct snd_pcm_hardware *hw,
+static void soc_pcm_init_runtime_hw(struct snd_pcm_runtime *runtime,
        struct snd_soc_pcm_stream *codec_stream,
        struct snd_soc_pcm_stream *cpu_stream)
 {
-       hw->rate_min = max(codec_stream->rate_min, cpu_stream->rate_min);
-       hw->rate_max = max(codec_stream->rate_max, cpu_stream->rate_max);
+       struct snd_pcm_hardware *hw = &runtime->hw;
+
        hw->channels_min = max(codec_stream->channels_min,
                cpu_stream->channels_min);
        hw->channels_max = min(codec_stream->channels_max,
@@ -165,6 +166,13 @@ static void soc_pcm_init_runtime_hw(struct snd_pcm_hardware *hw,
        if (cpu_stream->rates
                & (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_CONTINUOUS))
                hw->rates |= codec_stream->rates;
+
+       snd_pcm_limit_hw_rates(runtime);
+
+       hw->rate_min = max(hw->rate_min, cpu_stream->rate_min);
+       hw->rate_min = max(hw->rate_min, codec_stream->rate_min);
+       hw->rate_max = min_not_zero(hw->rate_max, cpu_stream->rate_max);
+       hw->rate_max = min_not_zero(hw->rate_max, codec_stream->rate_max);
 }
 
 /*
@@ -183,6 +191,8 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
        struct snd_soc_dai_driver *codec_dai_drv = codec_dai->driver;
        int ret = 0;
 
+       pinctrl_pm_select_default_state(cpu_dai->dev);
+       pinctrl_pm_select_default_state(codec_dai->dev);
        pm_runtime_get_sync(cpu_dai->dev);
        pm_runtime_get_sync(codec_dai->dev);
        pm_runtime_get_sync(platform->dev);
@@ -190,7 +200,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
        mutex_lock_nested(&rtd->pcm_mutex, rtd->pcm_subclass);
 
        /* startup the audio subsystem */
-       if (cpu_dai->driver->ops->startup) {
+       if (cpu_dai->driver->ops && cpu_dai->driver->ops->startup) {
                ret = cpu_dai->driver->ops->startup(substream, cpu_dai);
                if (ret < 0) {
                        dev_err(cpu_dai->dev, "ASoC: can't open interface"
@@ -208,7 +218,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
                }
        }
 
-       if (codec_dai->driver->ops->startup) {
+       if (codec_dai->driver->ops && codec_dai->driver->ops->startup) {
                ret = codec_dai->driver->ops->startup(substream, codec_dai);
                if (ret < 0) {
                        dev_err(codec_dai->dev, "ASoC: can't open codec"
@@ -232,15 +242,14 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
 
        /* Check that the codec and cpu DAIs are compatible */
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
-               soc_pcm_init_runtime_hw(&runtime->hw, &codec_dai_drv->playback,
+               soc_pcm_init_runtime_hw(runtime, &codec_dai_drv->playback,
                        &cpu_dai_drv->playback);
        } else {
-               soc_pcm_init_runtime_hw(&runtime->hw, &codec_dai_drv->capture,
+               soc_pcm_init_runtime_hw(runtime, &codec_dai_drv->capture,
                        &cpu_dai_drv->capture);
        }
 
        ret = -EINVAL;
-       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);
@@ -317,6 +326,10 @@ out:
        pm_runtime_put(platform->dev);
        pm_runtime_put(codec_dai->dev);
        pm_runtime_put(cpu_dai->dev);
+       if (!codec_dai->active)
+               pinctrl_pm_select_sleep_state(codec_dai->dev);
+       if (!cpu_dai->active)
+               pinctrl_pm_select_sleep_state(cpu_dai->dev);
 
        return ret;
 }
@@ -426,6 +439,10 @@ static int soc_pcm_close(struct snd_pcm_substream *substream)
        pm_runtime_put(platform->dev);
        pm_runtime_put(codec_dai->dev);
        pm_runtime_put(cpu_dai->dev);
+       if (!codec_dai->active)
+               pinctrl_pm_select_sleep_state(codec_dai->dev);
+       if (!cpu_dai->active)
+               pinctrl_pm_select_sleep_state(cpu_dai->dev);
 
        return 0;
 }
@@ -463,7 +480,7 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
                }
        }
 
-       if (codec_dai->driver->ops->prepare) {
+       if (codec_dai->driver->ops && codec_dai->driver->ops->prepare) {
                ret = codec_dai->driver->ops->prepare(substream, codec_dai);
                if (ret < 0) {
                        dev_err(codec_dai->dev, "ASoC: DAI prepare error: %d\n",
@@ -472,7 +489,7 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
                }
        }
 
-       if (cpu_dai->driver->ops->prepare) {
+       if (cpu_dai->driver->ops && cpu_dai->driver->ops->prepare) {
                ret = cpu_dai->driver->ops->prepare(substream, cpu_dai);
                if (ret < 0) {
                        dev_err(cpu_dai->dev, "ASoC: DAI prepare error: %d\n",
@@ -523,7 +540,7 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
                }
        }
 
-       if (codec_dai->driver->ops->hw_params) {
+       if (codec_dai->driver->ops && codec_dai->driver->ops->hw_params) {
                ret = codec_dai->driver->ops->hw_params(substream, params, codec_dai);
                if (ret < 0) {
                        dev_err(codec_dai->dev, "ASoC: can't set %s hw params:"
@@ -532,7 +549,7 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
                }
        }
 
-       if (cpu_dai->driver->ops->hw_params) {
+       if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_params) {
                ret = cpu_dai->driver->ops->hw_params(substream, params, cpu_dai);
                if (ret < 0) {
                        dev_err(cpu_dai->dev, "ASoC: %s hw params failed: %d\n",
@@ -559,11 +576,11 @@ out:
        return ret;
 
 platform_err:
-       if (cpu_dai->driver->ops->hw_free)
+       if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_free)
                cpu_dai->driver->ops->hw_free(substream, cpu_dai);
 
 interface_err:
-       if (codec_dai->driver->ops->hw_free)
+       if (codec_dai->driver->ops && codec_dai->driver->ops->hw_free)
                codec_dai->driver->ops->hw_free(substream, codec_dai);
 
 codec_err:
@@ -600,10 +617,10 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
                platform->driver->ops->hw_free(substream);
 
        /* now free hw params for the DAIs  */
-       if (codec_dai->driver->ops->hw_free)
+       if (codec_dai->driver->ops && codec_dai->driver->ops->hw_free)
                codec_dai->driver->ops->hw_free(substream, codec_dai);
 
-       if (cpu_dai->driver->ops->hw_free)
+       if (cpu_dai->driver->ops && cpu_dai->driver->ops->hw_free)
                cpu_dai->driver->ops->hw_free(substream, cpu_dai);
 
        mutex_unlock(&rtd->pcm_mutex);
@@ -618,7 +635,7 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
        struct snd_soc_dai *codec_dai = rtd->codec_dai;
        int ret;
 
-       if (codec_dai->driver->ops->trigger) {
+       if (codec_dai->driver->ops && codec_dai->driver->ops->trigger) {
                ret = codec_dai->driver->ops->trigger(substream, cmd, codec_dai);
                if (ret < 0)
                        return ret;
@@ -630,7 +647,7 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
                        return ret;
        }
 
-       if (cpu_dai->driver->ops->trigger) {
+       if (cpu_dai->driver->ops && cpu_dai->driver->ops->trigger) {
                ret = cpu_dai->driver->ops->trigger(substream, cmd, cpu_dai);
                if (ret < 0)
                        return ret;
@@ -647,19 +664,20 @@ static int soc_pcm_bespoke_trigger(struct snd_pcm_substream *substream,
        struct snd_soc_dai *codec_dai = rtd->codec_dai;
        int ret;
 
-       if (codec_dai->driver->ops->bespoke_trigger) {
+       if (codec_dai->driver->ops &&
+           codec_dai->driver->ops->bespoke_trigger) {
                ret = codec_dai->driver->ops->bespoke_trigger(substream, cmd, codec_dai);
                if (ret < 0)
                        return ret;
        }
 
-       if (platform->driver->bespoke_trigger) {
+       if (platform->driver->ops && platform->driver->bespoke_trigger) {
                ret = platform->driver->bespoke_trigger(substream, cmd);
                if (ret < 0)
                        return ret;
        }
 
-       if (cpu_dai->driver->ops->bespoke_trigger) {
+       if (cpu_dai->driver->ops && cpu_dai->driver->ops->bespoke_trigger) {
                ret = cpu_dai->driver->ops->bespoke_trigger(substream, cmd, cpu_dai);
                if (ret < 0)
                        return ret;
@@ -684,10 +702,10 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
        if (platform->driver->ops && platform->driver->ops->pointer)
                offset = platform->driver->ops->pointer(substream);
 
-       if (cpu_dai->driver->ops->delay)
+       if (cpu_dai->driver->ops && cpu_dai->driver->ops->delay)
                delay += cpu_dai->driver->ops->delay(substream, cpu_dai);
 
-       if (codec_dai->driver->ops->delay)
+       if (codec_dai->driver->ops && codec_dai->driver->ops->delay)
                delay += codec_dai->driver->ops->delay(substream, codec_dai);
 
        if (platform->driver->delay)
@@ -1037,6 +1055,12 @@ static int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
                struct snd_pcm_substream *be_substream =
                        snd_soc_dpcm_get_substream(be, stream);
 
+               if (!be_substream) {
+                       dev_err(be->dev, "ASoC: no backend %s stream\n",
+                               stream ? "capture" : "playback");
+                       continue;
+               }
+
                /* is this op for this BE ? */
                if (!snd_soc_dpcm_be_can_update(fe, be, stream))
                        continue;
@@ -1054,7 +1078,8 @@ static int dpcm_be_dai_startup(struct snd_soc_pcm_runtime *fe, int stream)
                    (be->dpcm[stream].state != SND_SOC_DPCM_STATE_CLOSE))
                        continue;
 
-               dev_dbg(be->dev, "ASoC: open BE %s\n", be->dai_link->name);
+               dev_dbg(be->dev, "ASoC: open %s BE %s\n",
+                       stream ? "capture" : "playback", be->dai_link->name);
 
                be_substream->runtime = be->dpcm[stream].runtime;
                err = soc_pcm_open(be_substream);
@@ -1673,7 +1698,7 @@ static int soc_pcm_ioctl(struct snd_pcm_substream *substream,
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
        struct snd_soc_platform *platform = rtd->platform;
 
-       if (platform->driver->ops->ioctl)
+       if (platform->driver->ops && platform->driver->ops->ioctl)
                return platform->driver->ops->ioctl(substream, cmd, arg);
        return snd_pcm_lib_ioctl(substream, cmd, arg);
 }
@@ -1934,8 +1959,8 @@ int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute)
 
                dev_dbg(be->dev, "ASoC: BE digital mute %s\n", be->dai_link->name);
 
-               if (drv->ops->digital_mute && dai->playback_active)
-                               drv->ops->digital_mute(dai, mute);
+               if (drv->ops && drv->ops->digital_mute && dai->playback_active)
+                       drv->ops->digital_mute(dai, mute);
        }
 
        return 0;
@@ -2224,7 +2249,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dpcm_can_be_params);
 int snd_soc_platform_trigger(struct snd_pcm_substream *substream,
                int cmd, struct snd_soc_platform *platform)
 {
-       if (platform->driver->ops->trigger)
+       if (platform->driver->ops && platform->driver->ops->trigger)
                return platform->driver->ops->trigger(substream, cmd);
        return 0;
 }