]> git.karo-electronics.de Git - linux-beck.git/commitdiff
greybus: audio: Update pm runtime support in dai_ops callback
authorVaibhav Agarwal <vaibhav.agarwal@linaro.org>
Thu, 4 Aug 2016 09:44:37 +0000 (15:14 +0530)
committerGreg Kroah-Hartman <gregkh@google.com>
Thu, 4 Aug 2016 17:07:30 +0000 (19:07 +0200)
Ensure pm runtime get_sync/put protection in codec_dai ops callback
functions before accessing apbridge.

Signed-off-by: Vaibhav Agarwal <vaibhav.agarwal@linaro.org>
Reviewed-by: Mark Greer <mgreer@animalcreek.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
drivers/staging/greybus/audio_codec.c

index b64aca523d5371e64f973378ca672a01ce658f54..9f050bd95c7c32bdee16de4355ea5672e1be1f91 100644 (file)
@@ -405,6 +405,7 @@ static int gbcodec_hw_params(struct snd_pcm_substream *substream,
        uint32_t format, rate;
        struct gbaudio_module_info *module;
        struct gbaudio_data_connection *data;
+       struct gb_bundle *bundle;
        struct gbaudio_codec_info *codec = dev_get_drvdata(dai->dev);
 
        mutex_lock(&codec->lock);
@@ -456,6 +457,13 @@ static int gbcodec_hw_params(struct snd_pcm_substream *substream,
                return -EINVAL;
        }
 
+       bundle = to_gb_bundle(module->dev);
+       ret = gb_pm_runtime_get_sync(bundle);
+       if (ret) {
+               mutex_unlock(&codec->lock);
+               return ret;
+       }
+
        ret = gb_audio_apbridgea_set_config(data->connection, 0,
                                            AUDIO_APBRIDGEA_PCM_FMT_16,
                                            AUDIO_APBRIDGEA_PCM_RATE_48000,
@@ -466,6 +474,9 @@ static int gbcodec_hw_params(struct snd_pcm_substream *substream,
                mutex_unlock(&codec->lock);
                return ret;
        }
+
+       gb_pm_runtime_put_noidle(bundle);
+
        codec->stream[substream->stream].state = GBAUDIO_CODEC_HWPARAMS;
        codec->stream[substream->stream].format = format;
        codec->stream[substream->stream].rate = rate;
@@ -482,6 +493,7 @@ static int gbcodec_prepare(struct snd_pcm_substream *substream,
        int ret;
        struct gbaudio_module_info *module;
        struct gbaudio_data_connection *data;
+       struct gb_bundle *bundle;
        struct gbaudio_codec_info *codec = dev_get_drvdata(dai->dev);
 
        mutex_lock(&codec->lock);
@@ -504,6 +516,13 @@ static int gbcodec_prepare(struct snd_pcm_substream *substream,
                return -ENODEV;
        }
 
+       bundle = to_gb_bundle(module->dev);
+       ret = gb_pm_runtime_get_sync(bundle);
+       if (ret) {
+               mutex_unlock(&codec->lock);
+               return ret;
+       }
+
        switch (substream->stream) {
        case SNDRV_PCM_STREAM_PLAYBACK:
                ret = gb_audio_apbridgea_set_tx_data_size(data->connection, 0,
@@ -521,6 +540,8 @@ static int gbcodec_prepare(struct snd_pcm_substream *substream,
                return ret;
        }
 
+       gb_pm_runtime_put_noidle(bundle);
+
        codec->stream[substream->stream].state = GBAUDIO_CODEC_PREPARE;
        mutex_unlock(&codec->lock);
        return 0;
@@ -531,6 +552,7 @@ static int gbcodec_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
        int ret;
        struct gbaudio_data_connection *data;
        struct gbaudio_module_info *module;
+       struct gb_bundle *bundle;
        struct gbaudio_codec_info *codec = dev_get_drvdata(dai->dev);
 
 
@@ -563,6 +585,13 @@ static int gbcodec_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
                return -ENODEV;
        }
 
+       bundle = to_gb_bundle(module->dev);
+       ret = gb_pm_runtime_get_sync(bundle);
+       if (ret) {
+               mutex_unlock(&codec->lock);
+               return ret;
+       }
+
        if (!mute && !stream) {/* start playback */
                ret = gb_audio_apbridgea_prepare_tx(data->connection,
                                                    0);
@@ -597,6 +626,7 @@ static int gbcodec_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
                                    module->name, mute ? "Mute" : "Unmute",
                                    stream ? "Capture" : "Playback", ret);
 
+       gb_pm_runtime_put_noidle(bundle);
        mutex_unlock(&codec->lock);
        return ret;
 }