ASoC: da7213: Add DAI DAPM event to control DAI clocks
authorAdam Thomson <Adam.Thomson.Opensource@diasemi.com>
Tue, 10 May 2016 15:11:04 +0000 (16:11 +0100)
committerMark Brown <broonie@kernel.org>
Tue, 10 May 2016 18:24:16 +0000 (19:24 +0100)
Currently, when Codec is I2S master DAI clocks are continuously
generated even if all audio streams have stopped. To improve
efficiency, control of the DAI clocks for master mode have been
moved to a DAPM widget event so they're only enabled as required.

Signed-off-by: Adam Thomson <Adam.Thomson.Opensource@diasemi.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/da7213.c
sound/soc/codecs/da7213.h

index 7278f93460c1ee1f5eb48fafaf2f95d0aa406c62..701bd620474709dcf500687cef0eb0292862c1a7 100644 (file)
@@ -725,6 +725,36 @@ static const struct snd_kcontrol_new da7213_dapm_mixoutr_controls[] = {
 };
 
 
+/*
+ * DAPM Events
+ */
+
+static int da7213_dai_event(struct snd_soc_dapm_widget *w,
+                           struct snd_kcontrol *kcontrol, int event)
+{
+       struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm);
+       struct da7213_priv *da7213 = snd_soc_codec_get_drvdata(codec);
+
+       switch (event) {
+       case SND_SOC_DAPM_PRE_PMU:
+               /* Enable DAI clks for master mode */
+               if (da7213->master)
+                       snd_soc_update_bits(codec, DA7213_DAI_CLK_MODE,
+                                           DA7213_DAI_CLK_EN_MASK,
+                                           DA7213_DAI_CLK_EN_MASK);
+               return 0;
+       case SND_SOC_DAPM_POST_PMD:
+               /* Disable DAI clks if in master mode */
+               if (da7213->master)
+                       snd_soc_update_bits(codec, DA7213_DAI_CLK_MODE,
+                                           DA7213_DAI_CLK_EN_MASK, 0);
+               return 0;
+       default:
+               return -EINVAL;
+       }
+}
+
+
 /*
  * DAPM widgets
  */
@@ -736,7 +766,8 @@ static const struct snd_soc_dapm_widget da7213_dapm_widgets[] = {
 
        /* Use a supply here as this controls both input & output DAIs */
        SND_SOC_DAPM_SUPPLY("DAI", DA7213_DAI_CTRL, DA7213_DAI_EN_SHIFT,
-                           DA7213_NO_INVERT, NULL, 0),
+                           DA7213_NO_INVERT, da7213_dai_event,
+                           SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
 
        /*
         * Input
@@ -1143,11 +1174,9 @@ static int da7213_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
        /* Set master/slave mode */
        switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
        case SND_SOC_DAIFMT_CBM_CFM:
-               dai_clk_mode |= DA7213_DAI_CLK_EN_MASTER_MODE;
                da7213->master = true;
                break;
        case SND_SOC_DAIFMT_CBS_CFS:
-               dai_clk_mode |= DA7213_DAI_CLK_EN_SLAVE_MODE;
                da7213->master = false;
                break;
        default:
index 030fd691b07626ab599fe53bd0b3a1903268b94b..5de5c2997e0c38a786ec75381e7b040e670852fb 100644 (file)
 #define DA7213_DAI_BCLKS_PER_WCLK_MASK                         (0x3 << 0)
 #define DA7213_DAI_CLK_POL_INV                                 (0x1 << 2)
 #define DA7213_DAI_WCLK_POL_INV                                        (0x1 << 3)
-#define DA7213_DAI_CLK_EN_SLAVE_MODE                           (0x0 << 7)
-#define DA7213_DAI_CLK_EN_MASTER_MODE                          (0x1 << 7)
 #define DA7213_DAI_CLK_EN_MASK                                 (0x1 << 7)
 
 /* DA7213_DAI_CTRL = 0x29 */