mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: <Codrin.Ciubotariu@microchip.com>
To: <lars@metafoo.de>, <lgirdwood@gmail.com>, <broonie@kernel.org>
Cc: <alsa-devel@alsa-project.org>, <linux-kernel@vger.kernel.org>,
	<Codrin.Ciubotariu@microchip.com>
Subject: [PATCH 5/5] ASoC: codecs: ad193x: Add support to disable on-chip PLL
Date: Mon, 18 Feb 2019 16:10:36 +0000	[thread overview]
Message-ID: <20190218160954.13929-6-codrin.ciubotariu@microchip.com> (raw)
In-Reply-To: <20190218160954.13929-1-codrin.ciubotariu@microchip.com>

From: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>

The on-chip PLL can be disabled if on the MCLKI pin we have an external
clock at 512 x fs. This clock can be used as direct internal clock for
ADCs or DACs.
To support this, we add an extra clock id that can be configured
using the set_sysclk() callback.

Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
---
 sound/soc/codecs/ad193x.c | 26 +++++++++++++++++++++++++-
 sound/soc/codecs/ad193x.h |  8 ++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/sound/soc/codecs/ad193x.c b/sound/soc/codecs/ad193x.c
index f8cf182518a3..96d7cb2e4a56 100644
--- a/sound/soc/codecs/ad193x.c
+++ b/sound/soc/codecs/ad193x.c
@@ -100,6 +100,15 @@ static const struct snd_soc_dapm_widget ad193x_adc_widgets[] = {
 	SND_SOC_DAPM_INPUT("ADC2IN"),
 };
 
+static int ad193x_check_pll(struct snd_soc_dapm_widget *source,
+			    struct snd_soc_dapm_widget *sink)
+{
+	struct snd_soc_component *component = snd_soc_dapm_to_component(source->dapm);
+	struct ad193x_priv *ad193x = snd_soc_component_get_drvdata(component);
+
+	return !!ad193x->sysclk;
+}
+
 static const struct snd_soc_dapm_route audio_paths[] = {
 	{ "DAC", NULL, "SYSCLK" },
 	{ "DAC Output", NULL, "DAC" },
@@ -108,7 +117,7 @@ static const struct snd_soc_dapm_route audio_paths[] = {
 	{ "DAC2OUT", NULL, "DAC Output" },
 	{ "DAC3OUT", NULL, "DAC Output" },
 	{ "DAC4OUT", NULL, "DAC Output" },
-	{ "SYSCLK", NULL, "PLL_PWR" },
+	{ "SYSCLK", NULL, "PLL_PWR", &ad193x_check_pll },
 };
 
 static const struct snd_soc_dapm_route ad193x_adc_audio_paths[] = {
@@ -276,7 +285,22 @@ static int ad193x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
 		int clk_id, unsigned int freq, int dir)
 {
 	struct snd_soc_component *component = codec_dai->component;
+	struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
 	struct ad193x_priv *ad193x = snd_soc_component_get_drvdata(component);
+
+	if (clk_id == AD193X_SYSCLK_MCLK) {
+		/* MCLK must be 512 x fs */
+		if (dir == SND_SOC_CLOCK_OUT || freq != 24576000)
+			return -EINVAL;
+
+		regmap_update_bits(ad193x->regmap, AD193X_PLL_CLK_CTRL1,
+				   AD193X_PLL_SRC_MASK,
+				   AD193X_PLL_DAC_SRC_MCLK |
+				   AD193X_PLL_CLK_SRC_MCLK);
+
+		snd_soc_dapm_sync(dapm);
+		return 0;
+	}
 	switch (freq) {
 	case 12288000:
 	case 18432000:
diff --git a/sound/soc/codecs/ad193x.h b/sound/soc/codecs/ad193x.h
index 8b1e65f928d2..27d6afbd7dfb 100644
--- a/sound/soc/codecs/ad193x.h
+++ b/sound/soc/codecs/ad193x.h
@@ -31,6 +31,11 @@ int ad193x_probe(struct device *dev, struct regmap *regmap,
 #define AD193X_PLL_INPUT_512    (2 << 1)
 #define AD193X_PLL_INPUT_768    (3 << 1)
 #define AD193X_PLL_CLK_CTRL1    0x01
+#define AD193X_PLL_SRC_MASK	0x03
+#define AD193X_PLL_DAC_SRC_PLL  0
+#define AD193X_PLL_DAC_SRC_MCLK 1
+#define AD193X_PLL_CLK_SRC_PLL  (0 << 1)
+#define AD193X_PLL_CLK_SRC_MCLK	(1 << 1)
 #define AD193X_DAC_CTRL0        0x02
 #define AD193X_DAC_POWERDOWN           0x01
 #define AD193X_DAC_SERFMT_MASK		0xC0
@@ -96,4 +101,7 @@ int ad193x_probe(struct device *dev, struct regmap *regmap,
 
 #define AD193X_NUM_REGS          17
 
+#define AD193X_SYSCLK_PLL	0
+#define AD193X_SYSCLK_MCLK	1
+
 #endif
-- 
2.17.1


  parent reply	other threads:[~2019-02-18 16:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-18 16:10 [PATCH 0/5] ASoC: codecs: ad193x: Several fixes and imprevements Codrin.Ciubotariu
2019-02-18 16:10 ` [PATCH 1/5] ASoC: codecs: ad193x: Remove capture support for codecs without ADC Codrin.Ciubotariu
2019-02-18 18:49   ` Applied "ASoC: codecs: ad193x: Remove capture support for codecs without ADC" to the asoc tree Mark Brown
2019-02-18 16:10 ` [PATCH 2/5] ASoC: codecs: ad193x: Set constraint to always have 32 sample bits Codrin.Ciubotariu
2019-02-18 18:49   ` Applied "ASoC: codecs: ad193x: Set constraint to always have 32 sample bits" to the asoc tree Mark Brown
2019-02-18 16:10 ` [PATCH 3/5] ASoC: codecs: ad193x: Fix frame polarity for DSP_A format Codrin.Ciubotariu
2019-02-18 18:49   ` Applied "ASoC: codecs: ad193x: Fix frame polarity for DSP_A format" to the asoc tree Mark Brown
2019-02-18 16:10 ` [PATCH 4/5] ASoC: codecs: ad193x: Add runtime support for DSP_A and I2S modes Codrin.Ciubotariu
2019-02-18 18:49   ` Applied "ASoC: codecs: ad193x: Add runtime support for DSP_A and I2S modes" to the asoc tree Mark Brown
2019-02-18 16:10 ` Codrin.Ciubotariu [this message]
2019-02-18 18:49   ` Applied "ASoC: codecs: ad193x: Add support to disable on-chip PLL" " Mark Brown
2019-02-18 16:57 ` [PATCH 0/5] ASoC: codecs: ad193x: Several fixes and imprevements Codrin.Ciubotariu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190218160954.13929-6-codrin.ciubotariu@microchip.com \
    --to=codrin.ciubotariu@microchip.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=lars@metafoo.de \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®