ASoC: simple-card: Enable and disable DAI clocks as needed
authorJyri Sarha <jsarha@ti.com>
Tue, 13 Jan 2015 19:16:34 +0000 (21:16 +0200)
committerMark Brown <broonie@kernel.org>
Thu, 15 Jan 2015 11:45:52 +0000 (11:45 +0000)
Call clk_prepare_enable() and clk_disable_unprepare() for cpu dai
clock and codec dai clock in dai statup and shutdown callbacks. This
to make sure the related clock are enabled when the audio device is
used.

Signed-off-by: Jyri Sarha <jsarha@ti.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Documentation/devicetree/bindings/sound/simple-card.txt
include/sound/simple_card.h
sound/soc/generic/simple-card.c

index c3cba600bf112b70b4667e2001fe6c02ccb8da93..73bf314f7240483514db27980ef6aa63dd0298f2 100644 (file)
@@ -75,6 +75,11 @@ Optional CPU/CODEC subnodes properties:
                                          it can be specified via "clocks" if system has
                                          clock node (= common clock), or "system-clock-frequency"
                                          (if system doens't support common clock)
+                                         If a clock is specified, it is
+                                         enabled with clk_prepare_enable()
+                                         in dai startup() and disabled with
+                                         clk_disable_unprepare() in dai
+                                         shutdown().
 
 Example 1 - single DAI link:
 
index 9b0ac77177b6e3aa13156822a2c23f61635e56bd..1255ddb1d3e2c22d05b188a82bc589f62c307b9b 100644 (file)
@@ -20,6 +20,7 @@ struct asoc_simple_dai {
        unsigned int sysclk;
        int slots;
        int slot_width;
+       struct clk *clk;
 };
 
 struct asoc_simple_card_info {
index fb9240fdc9b70095d364e3e90e14c16653ca4aff..cb3998d96cca3803431d7c9a0ac970f59b51a2a2 100644 (file)
@@ -39,6 +39,37 @@ struct simple_card_data {
 #define simple_priv_to_link(priv, i) ((priv)->snd_card.dai_link + i)
 #define simple_priv_to_props(priv, i) ((priv)->dai_props + i)
 
+static int asoc_simple_card_startup(struct snd_pcm_substream *substream)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card);
+       struct simple_dai_props *dai_props =
+               &priv->dai_props[rtd - rtd->card->rtd];
+       int ret;
+
+       ret = clk_prepare_enable(dai_props->cpu_dai.clk);
+       if (ret)
+               return ret;
+       
+       ret = clk_prepare_enable(dai_props->codec_dai.clk);
+       if (ret)
+               clk_disable_unprepare(dai_props->cpu_dai.clk);
+
+       return ret;
+}
+
+static void asoc_simple_card_shutdown(struct snd_pcm_substream *substream)
+{
+       struct snd_soc_pcm_runtime *rtd = substream->private_data;
+       struct simple_card_data *priv = snd_soc_card_get_drvdata(rtd->card);
+       struct simple_dai_props *dai_props =
+               &priv->dai_props[rtd - rtd->card->rtd];
+
+       clk_disable_unprepare(dai_props->cpu_dai.clk);
+
+       clk_disable_unprepare(dai_props->codec_dai.clk);
+}
+
 static int asoc_simple_card_hw_params(struct snd_pcm_substream *substream,
                                      struct snd_pcm_hw_params *params)
 {
@@ -58,6 +89,8 @@ static int asoc_simple_card_hw_params(struct snd_pcm_substream *substream,
 }
 
 static struct snd_soc_ops asoc_simple_card_ops = {
+       .startup = asoc_simple_card_startup,
+       .shutdown = asoc_simple_card_shutdown,
        .hw_params = asoc_simple_card_hw_params,
 };
 
@@ -219,6 +252,7 @@ asoc_simple_card_sub_parse_of(struct device_node *np,
                }
 
                dai->sysclk = clk_get_rate(clk);
+               dai->clk = clk;
        } else if (!of_property_read_u32(np, "system-clock-frequency", &val)) {
                dai->sysclk = val;
        } else {