ASoC: pcm: Add soc_dai_hw_params helper
authorBenoit Cousson <bcousson@baylibre.com>
Tue, 8 Jul 2014 21:19:38 +0000 (23:19 +0200)
committerMark Brown <broonie@linaro.org>
Wed, 16 Jul 2014 22:06:27 +0000 (23:06 +0100)
Add a function helper to factorize the hw_params code.

Suggested by Lars-Peter Clausen <lars@metafoo.de>

Signed-off-by: Benoit Cousson <bcousson@baylibre.com>
Tested-by: Lars-Peter Clausen <lars@metafoo.de>
Reviewed-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@linaro.org>
include/sound/soc.h
sound/soc/soc-dapm.c
sound/soc/soc-pcm.c

index f2142cf3f243c41789446cbaac6c336eb0874eb1..98555f833ab40715abf37396bd8164274e00221f 100644 (file)
@@ -436,6 +436,10 @@ int snd_soc_set_runtime_hwparams(struct snd_pcm_substream *substream,
 int snd_soc_platform_trigger(struct snd_pcm_substream *substream,
                int cmd, struct snd_soc_platform *platform);
 
+int soc_dai_hw_params(struct snd_pcm_substream *substream,
+                     struct snd_pcm_hw_params *params,
+                     struct snd_soc_dai *dai);
+
 /* Jack reporting */
 int snd_soc_jack_new(struct snd_soc_codec *codec, const char *id, int type,
                     struct snd_soc_jack *jack);
index 5c63c3b49f3f14059033990b7501fd057a3dd503..9a047f360993cba2fe4ac87bf10ce17d537d65eb 100644 (file)
@@ -3214,27 +3214,15 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
 
        switch (event) {
        case SND_SOC_DAPM_PRE_PMU:
-               if (source->driver->ops && source->driver->ops->hw_params) {
-                       substream.stream = SNDRV_PCM_STREAM_CAPTURE;
-                       ret = source->driver->ops->hw_params(&substream,
-                                                            params, source);
-                       if (ret != 0) {
-                               dev_err(source->dev,
-                                       "ASoC: hw_params() failed: %d\n", ret);
-                               goto out;
-                       }
-               }
+               substream.stream = SNDRV_PCM_STREAM_CAPTURE;
+               ret = soc_dai_hw_params(&substream, params, source);
+               if (ret < 0)
+                       goto out;
 
-               if (sink->driver->ops && sink->driver->ops->hw_params) {
-                       substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
-                       ret = sink->driver->ops->hw_params(&substream, params,
-                                                          sink);
-                       if (ret != 0) {
-                               dev_err(sink->dev,
-                                       "ASoC: hw_params() failed: %d\n", ret);
-                               goto out;
-                       }
-               }
+               substream.stream = SNDRV_PCM_STREAM_PLAYBACK;
+               ret = soc_dai_hw_params(&substream, params, sink);
+               if (ret < 0)
+                       goto out;
                break;
 
        case SND_SOC_DAPM_POST_PMU:
index ec56d1831a8699916b65c86df95665111fded72f..3ec87d8aa1811654655289700c2b0a4def4e8302 100644 (file)
@@ -789,6 +789,24 @@ static void soc_pcm_codec_params_fixup(struct snd_pcm_hw_params *params,
        interval->max = channels;
 }
 
+int soc_dai_hw_params(struct snd_pcm_substream *substream,
+                     struct snd_pcm_hw_params *params,
+                     struct snd_soc_dai *dai)
+{
+       int ret;
+
+       if (dai->driver->ops && dai->driver->ops->hw_params) {
+               ret = dai->driver->ops->hw_params(substream, params, dai);
+               if (ret < 0) {
+                       dev_err(dai->dev, "ASoC: can't set %s hw params: %d\n",
+                               dai->name, ret);
+                       return ret;
+               }
+       }
+
+       return 0;
+}
+
 /*
  * Called by ALSA when the hardware params are set by application. This
  * function can also be called multiple times and can allocate buffers
@@ -832,17 +850,9 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
                        soc_pcm_codec_params_fixup(&codec_params,
                                                   codec_dai->rx_mask);
 
-               if (codec_dai->driver->ops &&
-                   codec_dai->driver->ops->hw_params) {
-                       ret = codec_dai->driver->ops->hw_params(substream,
-                                               &codec_params, codec_dai);
-                       if (ret < 0) {
-                               dev_err(codec_dai->dev,
-                                       "ASoC: can't set %s hw params: %d\n",
-                                       codec_dai->name, ret);
-                               goto codec_err;
-                       }
-               }
+               ret = soc_dai_hw_params(substream, &codec_params, codec_dai);
+               if(ret < 0)
+                       goto codec_err;
 
                codec_dai->rate = params_rate(&codec_params);
                codec_dai->channels = params_channels(&codec_params);
@@ -850,14 +860,9 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
                                                params_format(&codec_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",
-                               cpu_dai->name, ret);
-                       goto interface_err;
-               }
-       }
+       ret = soc_dai_hw_params(substream, params, cpu_dai);
+       if (ret < 0)
+               goto interface_err;
 
        if (platform->driver->ops && platform->driver->ops->hw_params) {
                ret = platform->driver->ops->hw_params(substream, params);