All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: alsa-devel@alsa-project.org
Cc: bardliao@realtek.com, broonie@kernel.org,
	Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>,
	jack.yu@realtek.com
Subject: [PATCH 15/19] ASoC: rt5640: add ASRC support
Date: Thu, 17 Dec 2015 20:35:52 -0600	[thread overview]
Message-ID: <1450406156-22246-16-git-send-email-pierre-louis.bossart@linux.intel.com> (raw)
In-Reply-To: <1450406156-22246-1-git-send-email-pierre-louis.bossart@linux.intel.com>

From: Jack Yu <jack.yu@realtek.com>

Signed-off-by: Jack Yu <jack.yu@realtek.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
---
 sound/soc/codecs/rt5640.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/codecs/rt5640.h |  17 ++++++++
 2 files changed, 119 insertions(+)

diff --git a/sound/soc/codecs/rt5640.c b/sound/soc/codecs/rt5640.c
index f2beb1a..18f2d3b 100644
--- a/sound/soc/codecs/rt5640.c
+++ b/sound/soc/codecs/rt5640.c
@@ -488,6 +488,18 @@ static int is_sys_clk_from_pll(struct snd_soc_dapm_widget *source,
 		return 0;
 }
 
+static int is_using_asrc(struct snd_soc_dapm_widget *source,
+			 struct snd_soc_dapm_widget *sink)
+{
+	struct snd_soc_codec *codec = snd_soc_dapm_to_codec(source->dapm);
+	struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec);
+
+	if (!rt5640->asrc_en)
+		return 0;
+
+	return 1;
+}
+
 /* Digital Mixer */
 static const struct snd_kcontrol_new rt5640_sto_adc_l_mix[] = {
 	SOC_DAPM_SINGLE("ADC1 Switch", RT5640_STO_ADC_MIXER,
@@ -1059,6 +1071,20 @@ static int rt5640_hp_post_event(struct snd_soc_dapm_widget *w,
 static const struct snd_soc_dapm_widget rt5640_dapm_widgets[] = {
 	SND_SOC_DAPM_SUPPLY("PLL1", RT5640_PWR_ANLG2,
 			RT5640_PWR_PLL_BIT, 0, NULL, 0),
+
+	/* ASRC */
+	SND_SOC_DAPM_SUPPLY_S("Stereo Filter ASRC", 1, RT5640_ASRC_1,
+			 15, 0, NULL, 0),
+	SND_SOC_DAPM_SUPPLY_S("I2S2 Filter ASRC", 1, RT5640_ASRC_1,
+			 12, 0, NULL, 0),
+	SND_SOC_DAPM_SUPPLY_S("I2S2 ASRC", 1, RT5640_ASRC_1,
+			 11, 0, NULL, 0),
+	SND_SOC_DAPM_SUPPLY_S("DMIC1 ASRC", 1, RT5640_ASRC_1,
+			 9, 0, NULL, 0),
+	SND_SOC_DAPM_SUPPLY_S("DMIC2 ASRC", 1, RT5640_ASRC_1,
+			 8, 0, NULL, 0),
+
+
 	/* Input Side */
 	/* micbias */
 	SND_SOC_DAPM_SUPPLY("LDO2", RT5640_PWR_ANLG1,
@@ -1319,6 +1345,12 @@ static const struct snd_soc_dapm_widget rt5639_specific_dapm_widgets[] = {
 };
 
 static const struct snd_soc_dapm_route rt5640_dapm_routes[] = {
+	{ "I2S1", NULL, "Stereo Filter ASRC", is_using_asrc },
+	{ "I2S2", NULL, "I2S2 ASRC", is_using_asrc },
+	{ "I2S2", NULL, "I2S2 Filter ASRC", is_using_asrc },
+	{ "DMIC1", NULL, "DMIC1 ASRC", is_using_asrc },
+	{ "DMIC2", NULL, "DMIC2 ASRC", is_using_asrc },
+
 	{"IN1P", NULL, "LDO2"},
 	{"IN2P", NULL, "LDO2"},
 	{"IN3P", NULL, "LDO2"},
@@ -1981,6 +2013,76 @@ int rt5640_dmic_enable(struct snd_soc_codec *codec,
 }
 EXPORT_SYMBOL_GPL(rt5640_dmic_enable);
 
+int rt5640_sel_asrc_clk_src(struct snd_soc_codec *codec,
+		unsigned int filter_mask, unsigned int clk_src)
+{
+	struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec);
+	unsigned int asrc2_mask = 0;
+	unsigned int asrc2_value = 0;
+
+	switch (clk_src) {
+	case RT5640_CLK_SEL_SYS:
+	case RT5640_CLK_SEL_ASRC:
+		break;
+
+	default:
+		return -EINVAL;
+	}
+
+	if (!filter_mask)
+		return -EINVAL;
+
+	if (filter_mask & RT5640_DA_STEREO_FILTER) {
+		asrc2_mask |= RT5640_STO_DAC_M_MASK;
+		asrc2_value = (asrc2_value & ~RT5640_STO_DAC_M_MASK)
+			| (clk_src << RT5640_STO_DAC_M_SFT);
+	}
+
+	if (filter_mask & RT5640_DA_MONO_L_FILTER) {
+		asrc2_mask |= RT5640_MDA_L_M_MASK;
+		asrc2_value = (asrc2_value & ~RT5640_MDA_L_M_MASK)
+			| (clk_src << RT5640_MDA_L_M_SFT);
+	}
+
+	if (filter_mask & RT5640_DA_MONO_R_FILTER) {
+		asrc2_mask |= RT5640_MDA_R_M_MASK;
+		asrc2_value = (asrc2_value & ~RT5640_MDA_R_M_MASK)
+			| (clk_src << RT5640_MDA_R_M_SFT);
+	}
+
+	if (filter_mask & RT5640_AD_STEREO_FILTER) {
+		asrc2_mask |= RT5640_ADC_M_MASK;
+		asrc2_value = (asrc2_value & ~RT5640_ADC_M_MASK)
+			| (clk_src << RT5640_ADC_M_SFT);
+	}
+
+	if (filter_mask & RT5640_AD_MONO_L_FILTER) {
+		asrc2_mask |= RT5640_MAD_L_M_MASK;
+		asrc2_value = (asrc2_value & ~RT5640_MAD_L_M_MASK)
+			| (clk_src << RT5640_MAD_L_M_SFT);
+	}
+
+	if (filter_mask & RT5640_AD_MONO_R_FILTER)  {
+		asrc2_mask |= RT5640_MAD_R_M_MASK;
+		asrc2_value = (asrc2_value & ~RT5640_MAD_R_M_MASK)
+			| (clk_src << RT5640_MAD_R_M_SFT);
+	}
+
+	snd_soc_update_bits(codec, RT5640_ASRC_2,
+		asrc2_mask, asrc2_value);
+
+	if (snd_soc_read(codec, RT5640_ASRC_2)) {
+		rt5640->asrc_en = true;
+		snd_soc_update_bits(codec, RT5640_JD_CTRL, 0x3, 0x3);
+	} else {
+		rt5640->asrc_en = false;
+		snd_soc_update_bits(codec, RT5640_JD_CTRL, 0x3, 0x0);
+	}
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(rt5640_sel_asrc_clk_src);
+
 static int rt5640_probe(struct snd_soc_codec *codec)
 {
 	struct snd_soc_dapm_context *dapm = snd_soc_codec_get_dapm(codec);
diff --git a/sound/soc/codecs/rt5640.h b/sound/soc/codecs/rt5640.h
index 3deb8ba..83a7150 100644
--- a/sound/soc/codecs/rt5640.h
+++ b/sound/soc/codecs/rt5640.h
@@ -1033,6 +1033,10 @@
 #define RT5640_DMIC_2_M_NOR			(0x0 << 8)
 #define RT5640_DMIC_2_M_ASYN			(0x1 << 8)
 
+/* ASRC clock source selection (0x84) */
+#define RT5640_CLK_SEL_SYS			(0x0)
+#define RT5640_CLK_SEL_ASRC			(0x1)
+
 /* ASRC Control 2 (0x84) */
 #define RT5640_MDA_L_M_MASK			(0x1 << 15)
 #define RT5640_MDA_L_M_SFT			15
@@ -2079,6 +2083,16 @@ enum {
 	RT5640_DMIC2,
 };
 
+/* filter mask */
+enum {
+	RT5640_DA_STEREO_FILTER = 0x1,
+	RT5640_DA_MONO_L_FILTER = (0x1 << 1),
+	RT5640_DA_MONO_R_FILTER = (0x1 << 2),
+	RT5640_AD_STEREO_FILTER = (0x1 << 3),
+	RT5640_AD_MONO_L_FILTER = (0x1 << 4),
+	RT5640_AD_MONO_R_FILTER = (0x1 << 5),
+};
+
 struct rt5640_priv {
 	struct snd_soc_codec *codec;
 	struct rt5640_platform_data pdata;
@@ -2095,9 +2109,12 @@ struct rt5640_priv {
 	int pll_out;
 
 	bool hp_mute;
+	bool asrc_en;
 };
 
 int rt5640_dmic_enable(struct snd_soc_codec *codec,
 		       bool dmic1_data_pin, bool dmic2_data_pin);
+int rt5640_sel_asrc_clk_src(struct snd_soc_codec *codec,
+		unsigned int filter_mask, unsigned int clk_src);
 
 #endif
-- 
1.9.1

  parent reply	other threads:[~2015-12-18  2:37 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-18  2:35 [PATCH 00/19] Baytrail/Cherrytrail cleanups and fixes Pierre-Louis Bossart
2015-12-18  2:35 ` [PATCH 01/19] ASoC: Intel: fix ACPI probe regression with Atom DPCM driver Pierre-Louis Bossart
2015-12-18 10:56   ` Takashi Iwai
2015-12-18 15:26     ` Pierre-Louis Bossart
2016-01-05 17:49   ` Applied "ASoC: Intel: fix ACPI probe regression with Atom DPCM driver" to the asoc tree Mark Brown
2015-12-18  2:35 ` [PATCH 02/19] ASoC: Intel: bytcr_rt5640: set SSP to I2S mode 2ch Pierre-Louis Bossart
2015-12-19 11:51   ` Applied "ASoC: Intel: bytcr_rt5640: set SSP to I2S mode 2ch" to the asoc tree Mark Brown
2015-12-18  2:35 ` [PATCH 03/19] ASoC: Intel: boards: align pin names between byt-rt5640 drivers Pierre-Louis Bossart
2015-12-19 11:51   ` Applied "ASoC: Intel: boards: align pin names between byt-rt5640 drivers" to the asoc tree Mark Brown
2015-12-18  2:35 ` [PATCH 04/19] ASoC: Intel: boards: start merging byt-rt5640 drivers Pierre-Louis Bossart
2015-12-19 11:51   ` Applied "ASoC: Intel: boards: start merging byt-rt5640 drivers" to the asoc tree Mark Brown
2015-12-18  2:35 ` [PATCH 05/19] ASoC: Intel: boards: merge DMI-based quirks in bytcr-rt5640 driver Pierre-Louis Bossart
2015-12-19 11:51   ` Applied "ASoC: Intel: boards: merge DMI-based quirks in bytcr-rt5640 driver" to the asoc tree Mark Brown
2015-12-18  2:35 ` [PATCH 06/19] ASoC: Intel: tag byt-rt5640 machine driver as deprecated Pierre-Louis Bossart
2015-12-19 11:51   ` Applied "ASoC: Intel: tag byt-rt5640 machine driver as deprecated" to the asoc tree Mark Brown
2015-12-18  2:35 ` [PATCH 07/19] ASoc: Intel: Atom: add deep buffer definitions for atom platforms Pierre-Louis Bossart
2015-12-19 11:51   ` Applied "ASoc: Intel: Atom: add deep buffer definitions for atom platforms" to the asoc tree Mark Brown
2015-12-18  2:35 ` [PATCH 08/19] ASoC: Intel: boards: add DEEP_BUFFER support for BYT/CHT/BSW Pierre-Louis Bossart
2015-12-19 11:51   ` Applied "ASoC: Intel: boards: add DEEP_BUFFER support for BYT/CHT/BSW" to the asoc tree Mark Brown
2015-12-18  2:35 ` [PATCH 09/19] ASoC: Intel: Atom: add 24-bit support for media playback and capture Pierre-Louis Bossart
2015-12-19 11:51   ` Applied "ASoC: Intel: Atom: add 24-bit support for media playback and capture" to the asoc tree Mark Brown
2015-12-18  2:35 ` [PATCH 10/19] ASoC: Intel: Atom: clean-up compressed DAI definition Pierre-Louis Bossart
2015-12-19 11:51   ` Applied "ASoC: Intel: Atom: clean-up compressed DAI definition" to the asoc tree Mark Brown
2015-12-18  2:35 ` [PATCH 11/19] ASoC: Intel: Atom: flip logic for gain Switch Pierre-Louis Bossart
2015-12-19 11:51   ` Applied "ASoC: Intel: Atom: flip logic for gain Switch" to the asoc tree Mark Brown
2015-12-18  2:35 ` [PATCH 12/19] ASoC: codec: rt5651: add ACPI and OF support Pierre-Louis Bossart
2015-12-19 11:50   ` Mark Brown
2015-12-21 16:18     ` Pierre-Louis Bossart
2015-12-23  5:29       ` Bard Liao
2015-12-18  2:35 ` [PATCH 13/19] ASoC: Intel: add bytct-rt5651 machine driver Pierre-Louis Bossart
2015-12-18  2:35 ` [PATCH 14/19] ASoC: intel: boards: add card for MinnowBoard I2S access Pierre-Louis Bossart
2015-12-18  2:35 ` Pierre-Louis Bossart [this message]
2016-01-05 12:33   ` Applied "ASoC: rt5640: add ASRC support" to the asoc tree Mark Brown
2015-12-18  2:35 ` [PATCH 16/19] ASoC: Intel: bytcr-rt5640: enable ASRC Pierre-Louis Bossart
2016-01-05 17:49   ` Applied "ASoC: Intel: bytcr-rt5640: enable ASRC" to the asoc tree Mark Brown
2015-12-18  2:35 ` [PATCH 17/19] ASoC: Intel: bytcr_rt5640: fixup DAI codec_name with HID Pierre-Louis Bossart
2016-01-05 17:49   ` Applied "ASoC: Intel: bytcr_rt5640: fixup DAI codec_name with HID" to the asoc tree Mark Brown
2015-12-18  2:35 ` [PATCH 18/19] ASoC: Intel: Atom: add support for RT5642 Pierre-Louis Bossart
2016-01-05 17:49   ` Applied "ASoC: Intel: Atom: add support for RT5642" to the asoc tree Mark Brown
2015-12-18  2:35 ` [PATCH 19/19] ASoC: Intel: Atom: Add support for HP ElitePad 1000 G2 Pierre-Louis Bossart
2016-01-05 17:49   ` Applied "ASoC: Intel: Atom: Add support for HP ElitePad 1000 G2" 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=1450406156-22246-16-git-send-email-pierre-louis.bossart@linux.intel.com \
    --to=pierre-louis.bossart@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=bardliao@realtek.com \
    --cc=broonie@kernel.org \
    --cc=jack.yu@realtek.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.