ASoC: arizona: Add gating for clock when used for direct MCLK
authorCharles Keepax <ckeepax@opensource.wolfsonmicro.com>
Fri, 21 Oct 2016 13:15:57 +0000 (14:15 +0100)
committerMark Brown <broonie@kernel.org>
Mon, 24 Oct 2016 16:42:43 +0000 (17:42 +0100)
Whilst ultimately we would like to move all the clocking over to the
clock framework, as an intermediate step to get people going for now
gating the source clocks for SYSCLK/ASYNCCLK when they are configured
to come directly from an MCLK pin.

Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Tested-by: Sylwester Nawrocki <s.nawrocki@samsung.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/arizona.c
sound/soc/codecs/arizona.h
sound/soc/codecs/cs47l24.c
sound/soc/codecs/wm5102.c
sound/soc/codecs/wm5110.c
sound/soc/codecs/wm8997.c
sound/soc/codecs/wm8998.c

index 846ca079845fa8d141411e6944f369e904e95b61..10be50ae2f76044e9b8c1fecce66dd62591bdae1 100644 (file)
@@ -1233,6 +1233,46 @@ static int arizona_set_opclk(struct snd_soc_codec *codec, unsigned int clk,
        return -EINVAL;
 }
 
+int arizona_clk_ev(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 arizona *arizona = dev_get_drvdata(codec->dev->parent);
+       unsigned int val;
+       int clk_idx;
+       int ret;
+
+       ret = regmap_read(arizona->regmap, w->reg, &val);
+       if (ret) {
+               dev_err(codec->dev, "Failed to check clock source: %d\n", ret);
+               return ret;
+       }
+
+       val = (val & ARIZONA_SYSCLK_SRC_MASK) >> ARIZONA_SYSCLK_SRC_SHIFT;
+
+       switch (val) {
+       case ARIZONA_CLK_SRC_MCLK1:
+               clk_idx = ARIZONA_MCLK1;
+               break;
+       case ARIZONA_CLK_SRC_MCLK2:
+               clk_idx = ARIZONA_MCLK2;
+               break;
+       default:
+               return 0;
+       }
+
+       switch (event) {
+       case SND_SOC_DAPM_PRE_PMU:
+               return clk_prepare_enable(arizona->mclk[clk_idx]);
+       case SND_SOC_DAPM_POST_PMD:
+               clk_disable_unprepare(arizona->mclk[clk_idx]);
+               return 0;
+       default:
+               return 0;
+       }
+}
+EXPORT_SYMBOL_GPL(arizona_clk_ev);
+
 int arizona_set_sysclk(struct snd_soc_codec *codec, int clk_id,
                       int source, unsigned int freq, int dir)
 {
index 850aa338ba293e2dca4b47f81fc93662e238bd50..9d0997bec8706fcdd98d2d4f13a887ab130c97a2 100644 (file)
@@ -273,6 +273,8 @@ extern int arizona_eq_coeff_put(struct snd_kcontrol *kcontrol,
 extern int arizona_lhpf_coeff_put(struct snd_kcontrol *kcontrol,
                                  struct snd_ctl_elem_value *ucontrol);
 
+extern int arizona_clk_ev(struct snd_soc_dapm_widget *w,
+                         struct snd_kcontrol *kcontrol, int event);
 extern int arizona_set_sysclk(struct snd_soc_codec *codec, int clk_id,
                              int source, unsigned int freq, int dir);
 
index 5b22564f037cf9367dfb0fd82915d58fbee78db5..7df6a67690387336809dbf74ff98051f7aaa46b0 100644 (file)
@@ -335,9 +335,11 @@ static const struct snd_kcontrol_new cs47l24_aec_loopback_mux =
 
 static const struct snd_soc_dapm_widget cs47l24_dapm_widgets[] = {
 SND_SOC_DAPM_SUPPLY("SYSCLK", ARIZONA_SYSTEM_CLOCK_1,
-                   ARIZONA_SYSCLK_ENA_SHIFT, 0, NULL, 0),
+                   ARIZONA_SYSCLK_ENA_SHIFT, 0, arizona_clk_ev,
+                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
 SND_SOC_DAPM_SUPPLY("ASYNCCLK", ARIZONA_ASYNC_CLOCK_1,
-                   ARIZONA_ASYNC_CLK_ENA_SHIFT, 0, NULL, 0),
+                   ARIZONA_ASYNC_CLK_ENA_SHIFT, 0, arizona_clk_ev,
+                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
 SND_SOC_DAPM_SUPPLY("OPCLK", ARIZONA_OUTPUT_SYSTEM_CLOCK,
                    ARIZONA_OPCLK_ENA_SHIFT, 0, NULL, 0),
 SND_SOC_DAPM_SUPPLY("ASYNCOPCLK", ARIZONA_OUTPUT_ASYNC_CLOCK,
index 93876c6d48ee9a850516771339fad3be22ce980b..bb3de5b3d816872c09e462b139619dee68918af8 100644 (file)
@@ -607,6 +607,9 @@ static int wm5102_sysclk_ev(struct snd_soc_dapm_widget *w,
                break;
        case SND_SOC_DAPM_PRE_PMD:
                break;
+       case SND_SOC_DAPM_PRE_PMU:
+       case SND_SOC_DAPM_POST_PMD:
+               return arizona_clk_ev(w, kcontrol, event);
        default:
                return 0;
        }
@@ -1077,9 +1080,11 @@ static const struct snd_kcontrol_new wm5102_aec_loopback_mux =
 static const struct snd_soc_dapm_widget wm5102_dapm_widgets[] = {
 SND_SOC_DAPM_SUPPLY("SYSCLK", ARIZONA_SYSTEM_CLOCK_1, ARIZONA_SYSCLK_ENA_SHIFT,
                    0, wm5102_sysclk_ev,
-                   SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
+                   SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD |
+                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
 SND_SOC_DAPM_SUPPLY("ASYNCCLK", ARIZONA_ASYNC_CLOCK_1,
-                   ARIZONA_ASYNC_CLK_ENA_SHIFT, 0, NULL, 0),
+                   ARIZONA_ASYNC_CLK_ENA_SHIFT, 0, arizona_clk_ev,
+                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
 SND_SOC_DAPM_SUPPLY("OPCLK", ARIZONA_OUTPUT_SYSTEM_CLOCK,
                    ARIZONA_OPCLK_ENA_SHIFT, 0, NULL, 0),
 SND_SOC_DAPM_SUPPLY("ASYNCOPCLK", ARIZONA_OUTPUT_ASYNC_CLOCK,
index 06bae3b23fced6fa4efa949e8fdb2af7bdb20499..407dc4a43b07738345c87257af40f3247007ba0e 100644 (file)
@@ -183,7 +183,9 @@ static int wm5110_sysclk_ev(struct snd_soc_dapm_widget *w,
                                regmap_write_async(regmap, patch[i].reg,
                                                   patch[i].def);
                break;
-
+       case SND_SOC_DAPM_PRE_PMU:
+       case SND_SOC_DAPM_POST_PMD:
+               return arizona_clk_ev(w, kcontrol, event);
        default:
                break;
        }
@@ -1073,9 +1075,11 @@ static const struct snd_kcontrol_new wm5110_output_anc_src[] = {
 
 static const struct snd_soc_dapm_widget wm5110_dapm_widgets[] = {
 SND_SOC_DAPM_SUPPLY("SYSCLK", ARIZONA_SYSTEM_CLOCK_1, ARIZONA_SYSCLK_ENA_SHIFT,
-                   0, wm5110_sysclk_ev, SND_SOC_DAPM_POST_PMU),
+                   0, wm5110_sysclk_ev, SND_SOC_DAPM_POST_PMU |
+                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
 SND_SOC_DAPM_SUPPLY("ASYNCCLK", ARIZONA_ASYNC_CLOCK_1,
-                   ARIZONA_ASYNC_CLK_ENA_SHIFT, 0, NULL, 0),
+                   ARIZONA_ASYNC_CLK_ENA_SHIFT, 0, arizona_clk_ev,
+                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
 SND_SOC_DAPM_SUPPLY("OPCLK", ARIZONA_OUTPUT_SYSTEM_CLOCK,
                    ARIZONA_OPCLK_ENA_SHIFT, 0, NULL, 0),
 SND_SOC_DAPM_SUPPLY("ASYNCOPCLK", ARIZONA_OUTPUT_ASYNC_CLOCK,
index 2f2821b3382f055a9560413240797e4c56579c61..f5f5d4352670a3d6d6ae00ad8b8b3fb0bbbe987c 100644 (file)
@@ -108,6 +108,9 @@ static int wm8997_sysclk_ev(struct snd_soc_dapm_widget *w,
                break;
        case SND_SOC_DAPM_PRE_PMD:
                break;
+       case SND_SOC_DAPM_PRE_PMU:
+       case SND_SOC_DAPM_POST_PMD:
+               return arizona_clk_ev(w, kcontrol, event);
        default:
                return 0;
        }
@@ -408,9 +411,11 @@ static const struct snd_kcontrol_new wm8997_aec_loopback_mux =
 static const struct snd_soc_dapm_widget wm8997_dapm_widgets[] = {
 SND_SOC_DAPM_SUPPLY("SYSCLK", ARIZONA_SYSTEM_CLOCK_1, ARIZONA_SYSCLK_ENA_SHIFT,
                    0, wm8997_sysclk_ev,
-                   SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
+                   SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD |
+                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
 SND_SOC_DAPM_SUPPLY("ASYNCCLK", ARIZONA_ASYNC_CLOCK_1,
-                   ARIZONA_ASYNC_CLK_ENA_SHIFT, 0, NULL, 0),
+                   ARIZONA_ASYNC_CLK_ENA_SHIFT, 0, arizona_clk_ev,
+                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
 SND_SOC_DAPM_SUPPLY("OPCLK", ARIZONA_OUTPUT_SYSTEM_CLOCK,
                    ARIZONA_OPCLK_ENA_SHIFT, 0, NULL, 0),
 SND_SOC_DAPM_SUPPLY("ASYNCOPCLK", ARIZONA_OUTPUT_ASYNC_CLOCK,
index bcc2e1060a6c3ce1e48fce7ea2780249830e6525..3eaa3615b82e021bcfbc71c406e3a8f8a3138299 100644 (file)
@@ -541,9 +541,11 @@ static const struct snd_kcontrol_new wm8998_aec_loopback_mux[] = {
 
 static const struct snd_soc_dapm_widget wm8998_dapm_widgets[] = {
 SND_SOC_DAPM_SUPPLY("SYSCLK", ARIZONA_SYSTEM_CLOCK_1,
-                   ARIZONA_SYSCLK_ENA_SHIFT, 0, NULL, 0),
+                   ARIZONA_SYSCLK_ENA_SHIFT, 0, arizona_clk_ev,
+                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
 SND_SOC_DAPM_SUPPLY("ASYNCCLK", ARIZONA_ASYNC_CLOCK_1,
-                   ARIZONA_ASYNC_CLK_ENA_SHIFT, 0, NULL, 0),
+                   ARIZONA_ASYNC_CLK_ENA_SHIFT, 0, arizona_clk_ev,
+                   SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
 SND_SOC_DAPM_SUPPLY("OPCLK", ARIZONA_OUTPUT_SYSTEM_CLOCK,
                    ARIZONA_OPCLK_ENA_SHIFT, 0, NULL, 0),
 SND_SOC_DAPM_SUPPLY("ASYNCOPCLK", ARIZONA_OUTPUT_ASYNC_CLOCK,