ASoC: da7219: MCLK should be enabled before DAI clocks
authorAdam Thomson <Adam.Thomson.Opensource@diasemi.com>
Mon, 7 Jan 2019 16:11:46 +0000 (16:11 +0000)
committerMark Brown <broonie@kernel.org>
Wed, 9 Jan 2019 14:37:21 +0000 (14:37 +0000)
For platforms using the Common Clock Framework to control the
codec's DAI clocks, MCLK should be enabled prior to DAI clocks
being turned on. For some platforms the codec is already
provided with an MCLK reference and can therefore control MCLK
itself as it needs to.

To improve functionality MCLK is now added as a parent to the
DAI clocks, if MCLK was provided, so that if they are enabled MCLK
will automatically be enabled as a prerequisite by the CCF.

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

index 513ec036865363e94549795d57b9abafd0179af0..a20a610c7ee55746de0ff2dc9c6e87f3f94da41e 100644 (file)
@@ -1804,7 +1804,7 @@ static const struct clk_ops da7219_dai_clks_ops = {
        .is_prepared = da7219_dai_clks_is_prepared,
 };
 
-static void da7219_register_dai_clks(struct snd_soc_component *component)
+static int da7219_register_dai_clks(struct snd_soc_component *component)
 {
        struct device *dev = component->dev;
        struct da7219_priv *da7219 = snd_soc_component_get_drvdata(component);
@@ -1812,9 +1812,17 @@ static void da7219_register_dai_clks(struct snd_soc_component *component)
        struct clk_init_data init = {};
        struct clk *dai_clks;
        struct clk_lookup *dai_clks_lookup;
+       const char *parent_name;
+
+       if (da7219->mclk) {
+               parent_name = __clk_get_name(da7219->mclk);
+               init.parent_names = &parent_name;
+               init.num_parents = 1;
+       } else {
+               init.parent_names = NULL;
+               init.num_parents = 0;
+       }
 
-       init.parent_names = NULL;
-       init.num_parents = 0;
        init.name = pdata->dai_clks_name;
        init.ops = &da7219_dai_clks_ops;
        da7219->dai_clks_hw.init = &init;
@@ -1823,7 +1831,7 @@ static void da7219_register_dai_clks(struct snd_soc_component *component)
        if (IS_ERR(dai_clks)) {
                dev_warn(dev, "Failed to register DAI clocks: %ld\n",
                         PTR_ERR(dai_clks));
-               return;
+               return PTR_ERR(dai_clks);
        }
        da7219->dai_clks = dai_clks;
 
@@ -1835,13 +1843,18 @@ static void da7219_register_dai_clks(struct snd_soc_component *component)
                dai_clks_lookup = clkdev_create(dai_clks, pdata->dai_clks_name,
                                                "%s", dev_name(dev));
                if (!dai_clks_lookup)
-                       dev_warn(dev, "Failed to create DAI clkdev");
+                       return -ENOMEM;
                else
                        da7219->dai_clks_lookup = dai_clks_lookup;
        }
+
+       return 0;
 }
 #else
-static inline void da7219_register_dai_clks(struct snd_soc_component *component) {}
+static inline int da7219_register_dai_clks(struct snd_soc_component *component)
+{
+       return 0;
+}
 #endif /* CONFIG_COMMON_CLK */
 
 static void da7219_handle_pdata(struct snd_soc_component *component)
@@ -1854,8 +1867,6 @@ static void da7219_handle_pdata(struct snd_soc_component *component)
 
                da7219->wakeup_source = pdata->wakeup_source;
 
-               da7219_register_dai_clks(component);
-
                /* Mic Bias voltages */
                switch (pdata->micbias_lvl) {
                case DA7219_MICBIAS_1_6V:
@@ -1947,6 +1958,11 @@ static int da7219_probe(struct snd_soc_component *component)
                }
        }
 
+       /* Register CCF DAI clock control */
+       ret = da7219_register_dai_clks(component);
+       if (ret)
+               return ret;
+
        /* Default PC counter to free-running */
        snd_soc_component_update_bits(component, DA7219_PC_COUNT, DA7219_PC_FREERUN_MASK,
                            DA7219_PC_FREERUN_MASK);