alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Cc: tiwai@suse.de, alsa-devel@alsa-project.org, broonie@kernel.org
Subject: Applied "ASoC: Intel: cht_bsw_rt5645: add Baytrail MCLK support" to the asoc tree
Date: Tue, 31 Jan 2017 21:18:09 +0000	[thread overview]
Message-ID: <E1cYfoX-0001B2-Sw@debutante> (raw)
In-Reply-To: <1485461385-14544-11-git-send-email-pierre-louis.bossart@linux.intel.com>

The patch

   ASoC: Intel: cht_bsw_rt5645: add Baytrail MCLK support

has been applied to the asoc tree at

   git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git 

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.  

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark

>From a50477e55fff69e1028f25624ee9fc9182d59b1f Mon Sep 17 00:00:00 2001
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Date: Thu, 26 Jan 2017 14:09:38 -0600
Subject: [PATCH] ASoC: Intel: cht_bsw_rt5645: add Baytrail MCLK support

The existing code assumes a 19.2 MHz MCLK as the default
hardware configuration. This is valid for CherryTrail but
not for Baytrail.

Add explicit MCLK configuration to set the 19.2 clock on/off
depending on DAPM events.

This is a prerequisite step to enable devices with Baytrail
and RT5645 such as Asus X205TA

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
---
 sound/soc/intel/boards/cht_bsw_rt5645.c | 84 ++++++++++++++++++++++++++++-----
 1 file changed, 71 insertions(+), 13 deletions(-)

diff --git a/sound/soc/intel/boards/cht_bsw_rt5645.c b/sound/soc/intel/boards/cht_bsw_rt5645.c
index f504a0e18f91..468228b73b0b 100644
--- a/sound/soc/intel/boards/cht_bsw_rt5645.c
+++ b/sound/soc/intel/boards/cht_bsw_rt5645.c
@@ -24,6 +24,9 @@
 #include <linux/acpi.h>
 #include <linux/platform_device.h>
 #include <linux/slab.h>
+#include <asm/cpu_device_id.h>
+#include <asm/platform_sst_audio.h>
+#include <linux/clk.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
 #include <sound/soc.h>
@@ -45,6 +48,7 @@ struct cht_mc_private {
 	struct snd_soc_jack jack;
 	struct cht_acpi_card *acpi_card;
 	char codec_name[16];
+	struct clk *mclk;
 };
 
 static inline struct snd_soc_dai *cht_get_codec_dai(struct snd_soc_card *card)
@@ -65,6 +69,7 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,
 	struct snd_soc_dapm_context *dapm = w->dapm;
 	struct snd_soc_card *card = dapm->card;
 	struct snd_soc_dai *codec_dai;
+	struct cht_mc_private *ctx = snd_soc_card_get_drvdata(card);
 	int ret;
 
 	codec_dai = cht_get_codec_dai(card);
@@ -73,19 +78,30 @@ static int platform_clock_control(struct snd_soc_dapm_widget *w,
 		return -EIO;
 	}
 
-	if (!SND_SOC_DAPM_EVENT_OFF(event))
-		return 0;
+	if (SND_SOC_DAPM_EVENT_ON(event)) {
+		if (ctx->mclk) {
+			ret = clk_prepare_enable(ctx->mclk);
+			if (ret < 0) {
+				dev_err(card->dev,
+					"could not configure MCLK state");
+				return ret;
+			}
+		}
+	} else {
+		/* Set codec sysclk source to its internal clock because codec PLL will
+		 * be off when idle and MCLK will also be off when codec is
+		 * runtime suspended. Codec needs clock for jack detection and button
+		 * press. MCLK is turned off with clock framework or ACPI.
+		 */
+		ret = snd_soc_dai_set_sysclk(codec_dai, RT5645_SCLK_S_RCCLK,
+					48000 * 512, SND_SOC_CLOCK_IN);
+		if (ret < 0) {
+			dev_err(card->dev, "can't set codec sysclk: %d\n", ret);
+			return ret;
+		}
 
-	/* Set codec sysclk source to its internal clock because codec PLL will
-	 * be off when idle and MCLK will also be off by ACPI when codec is
-	 * runtime suspended. Codec needs clock for jack detection and button
-	 * press.
-	 */
-	ret = snd_soc_dai_set_sysclk(codec_dai, RT5645_SCLK_S_RCCLK,
-			0, SND_SOC_CLOCK_IN);
-	if (ret < 0) {
-		dev_err(card->dev, "can't set codec sysclk: %d\n", ret);
-		return ret;
+		if (ctx->mclk)
+			clk_disable_unprepare(ctx->mclk);
 	}
 
 	return 0;
@@ -97,7 +113,7 @@ static const struct snd_soc_dapm_widget cht_dapm_widgets[] = {
 	SND_SOC_DAPM_MIC("Int Mic", NULL),
 	SND_SOC_DAPM_SPK("Ext Spk", NULL),
 	SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
-			platform_clock_control, SND_SOC_DAPM_POST_PMD),
+			platform_clock_control, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
 };
 
 static const struct snd_soc_dapm_route cht_rt5645_audio_map[] = {
@@ -225,6 +241,26 @@ static int cht_codec_init(struct snd_soc_pcm_runtime *runtime)
 
 	rt5645_set_jack_detect(codec, &ctx->jack, &ctx->jack, &ctx->jack);
 
+	if (ctx->mclk) {
+		/*
+		 * The firmware might enable the clock at
+		 * boot (this information may or may not
+		 * be reflected in the enable clock register).
+		 * To change the rate we must disable the clock
+		 * first to cover these cases. Due to common
+		 * clock framework restrictions that do not allow
+		 * to disable a clock that has not been enabled,
+		 * we need to enable the clock first.
+		 */
+		ret = clk_prepare_enable(ctx->mclk);
+		if (!ret)
+			clk_disable_unprepare(ctx->mclk);
+
+		ret = clk_set_rate(ctx->mclk, CHT_PLAT_CLK_3_HZ);
+
+		if (ret)
+			dev_err(runtime->dev, "unable to set MCLK rate\n");
+	}
 	return ret;
 }
 
@@ -349,6 +385,18 @@ static struct cht_acpi_card snd_soc_cards[] = {
 
 static char cht_rt5640_codec_name[16]; /* i2c-<HID>:00 with HID being 8 chars */
 
+static bool is_valleyview(void)
+{
+	static const struct x86_cpu_id cpu_ids[] = {
+		{ X86_VENDOR_INTEL, 6, 55 }, /* Valleyview, Bay Trail */
+		{}
+	};
+
+	if (!x86_match_cpu(cpu_ids))
+		return false;
+	return true;
+}
+
 static int snd_cht_mc_probe(struct platform_device *pdev)
 {
 	int ret_val = 0;
@@ -391,6 +439,16 @@ static int snd_cht_mc_probe(struct platform_device *pdev)
 		cht_dailink[dai_index].codec_name = cht_rt5640_codec_name;
 	}
 
+	if (is_valleyview()) {
+		drv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
+		if (IS_ERR(drv->mclk)) {
+			dev_err(&pdev->dev,
+				"Failed to get MCLK from pmc_plt_clk_3: %ld\n",
+				PTR_ERR(drv->mclk));
+			return PTR_ERR(drv->mclk);
+		}
+	}
+
 	snd_soc_card_set_drvdata(card, drv);
 	ret_val = devm_snd_soc_register_card(&pdev->dev, card);
 	if (ret_val) {
-- 
2.11.0

  reply	other threads:[~2017-01-31 21:18 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-26 20:09 [PATCH 00/17] Baytrail/Cherrytrail audio fixes Pierre-Louis Bossart
2017-01-26 20:09 ` [PATCH 01/17] ASoC: Intel: atom: fix frame polarity Pierre-Louis Bossart
2017-01-31 20:02   ` Applied "ASoC: Intel: atom: fix frame polarity" to the asoc tree Mark Brown
2017-01-26 20:09 ` [PATCH 02/17] ASoC: Intel: boards: remove .pm_ops in all Atom/DPCM machine drivers Pierre-Louis Bossart
2017-01-31 20:02   ` Applied "ASoC: Intel: boards: remove .pm_ops in all Atom/DPCM machine drivers" to the asoc tree Mark Brown
2017-01-26 20:09 ` [PATCH 03/17] ASoC: rt5640: Add "10EC3276" ACPI ID Pierre-Louis Bossart
2017-01-26 20:09 ` [PATCH 04/17] ASoC: Intel: Atom: Add HP Pavilion x2 10-p000 machine entry Pierre-Louis Bossart
2017-01-26 20:09 ` [PATCH 05/17] ASoC: Intel: add support for Realtek 5651 on Cherrytrail Pierre-Louis Bossart
2017-01-31 21:18   ` Applied "ASoC: Intel: add support for Realtek 5651 on Cherrytrail" to the asoc tree Mark Brown
2017-01-26 20:09 ` [PATCH 06/17] ASoC: codecs: rt5670: add quirk for Lenovo Thinkpad 10 Pierre-Louis Bossart
2017-01-31 21:17   ` Applied "ASoC: codecs: rt5670: add quirk for Lenovo Thinkpad 10" to the asoc tree Mark Brown
2017-01-26 20:09 ` [PATCH 07/17] ASoC: Intel: Baytrail: add quirk for Lenovo Thinkpad 10 Pierre-Louis Bossart
2017-01-31 21:17   ` Applied "ASoC: Intel: Baytrail: add quirk for Lenovo Thinkpad 10" to the asoc tree Mark Brown
2017-01-26 20:09 ` [PATCH 08/17] ASoC: rt5645: add support for RT5648 Pierre-Louis Bossart
2017-01-31 21:17   ` Applied "ASoC: rt5645: add support for RT5648" to the asoc tree Mark Brown
2017-01-26 20:09 ` [PATCH 09/17] ASoc: rt5645: add ACPI ID 10EC3270 Pierre-Louis Bossart
2017-01-31 21:17   ` Applied "ASoc: rt5645: add ACPI ID 10EC3270" to the asoc tree Mark Brown
2017-01-26 20:09 ` [PATCH 10/17] ASoC: Intel: cht_bsw_rt5645: add Baytrail MCLK support Pierre-Louis Bossart
2017-01-31 21:18   ` Mark Brown [this message]
2017-01-26 20:09 ` [PATCH 11/17] ASoC: Intel: Atom: add machine driver for baytrail-rt5645 hardware Pierre-Louis Bossart
2017-01-31 21:17   ` Applied "ASoC: Intel: Atom: add machine driver for baytrail-rt5645 hardware" to the asoc tree Mark Brown
2017-01-26 20:09 ` [PATCH 12/17] ASoC: Intel: add support for ALC3270 codec Pierre-Louis Bossart
2017-01-31 21:17   ` Applied "ASoC: Intel: add support for ALC3270 codec" to the asoc tree Mark Brown
2017-01-26 20:09 ` [PATCH 13/17] ASoC: Intel: cht_bsw_rt5645: harden ACPI device detection Pierre-Louis Bossart
2017-01-31 21:17   ` Applied "ASoC: Intel: cht_bsw_rt5645: harden ACPI device detection" to the asoc tree Mark Brown
2017-01-26 20:09 ` [PATCH 14/17] ASoC: rt5645: fix error handling for gpio detection Pierre-Louis Bossart
2017-01-31 20:00   ` Mark Brown
2017-01-31 20:29     ` Pierre-Louis Bossart
2017-01-26 20:09 ` [PATCH 15/17] ASoC: Intel: cht-bsw-rt5645: add quirks for SSP0/AIF1/AIF2 routing Pierre-Louis Bossart
2017-01-31 21:17   ` Applied "ASoC: Intel: cht-bsw-rt5645: add quirks for SSP0/AIF1/AIF2 routing" to the asoc tree Mark Brown
2017-01-26 20:09 ` [PATCH 16/17] ASoC: Intel: cht-bsw-rt5645: select ASRC source based on routing quirk Pierre-Louis Bossart
2017-01-31 21:17   ` Applied "ASoC: Intel: cht-bsw-rt5645: select ASRC source based on routing quirk" to the asoc tree Mark Brown
2017-01-26 20:09 ` [PATCH 17/17] ASoC: Intel: cht-bsw-rt5645: fix DAI formats Pierre-Louis Bossart
2017-01-31 21:17   ` Applied "ASoC: Intel: cht-bsw-rt5645: fix DAI formats" to the asoc tree Mark Brown

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=E1cYfoX-0001B2-Sw@debutante \
    --to=broonie@kernel.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=pierre-louis.bossart@linux.intel.com \
    --cc=tiwai@suse.de \
    /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;
as well as URLs for NNTP newsgroup(s).