mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Svyatoslav Ryhel <clamor95@gmail.com>
To: Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Liam Girdwood <lgirdwood@gmail.com>,
	Mark Brown <broonie@kernel.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	Jonathan Hunter <jonathanh@nvidia.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
	Svyatoslav Ryhel <clamor95@gmail.com>,
	Maxim Schwalm <maxim.schwalm@gmail.com>,
	Dmitry Osipenko <digetx@gmail.com>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	alsa-devel@alsa-project.org, linux-tegra@vger.kernel.org,
	linux-staging@lists.linux.dev
Subject: [PATCH v1 04/10] ASoC: tegra: Support RT5631 by machine driver
Date: Tue, 21 Feb 2023 20:32:05 +0200	[thread overview]
Message-ID: <20230221183211.21964-5-clamor95@gmail.com> (raw)
In-Reply-To: <20230221183211.21964-1-clamor95@gmail.com>

Add Realtek ALC5631/RT5631 codec support to the Tegra ASoC machine driver.
The RT5631 codec is found on devices like ASUS Transformer TF201, TF700T
and other Tegra-based Android tablets.

Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
Signed-off-by: Ion Agorria <ion@agorria.com>
---
 sound/soc/tegra/Kconfig              |  9 ++++
 sound/soc/tegra/tegra_asoc_machine.c | 74 ++++++++++++++++++++++++++++
 2 files changed, 83 insertions(+)

diff --git a/sound/soc/tegra/Kconfig b/sound/soc/tegra/Kconfig
index b6712a3d1fa1..ff905e5dcd86 100644
--- a/sound/soc/tegra/Kconfig
+++ b/sound/soc/tegra/Kconfig
@@ -189,6 +189,15 @@ config SND_SOC_TEGRA_AUDIO_GRAPH_CARD
 config SND_SOC_TEGRA_MACHINE_DRV
 	tristate
 
+config SND_SOC_TEGRA_RT5631
+	tristate "SoC Audio support for Tegra boards using an RT5631 codec"
+	depends on SND_SOC_TEGRA && I2C && GPIOLIB
+	select SND_SOC_TEGRA_MACHINE_DRV
+	select SND_SOC_RT5631
+	help
+	  Say Y or M here if you want to add support for SoC audio on Tegra
+	  boards using the RT5631 codec, such as Transformer.
+
 config SND_SOC_TEGRA_RT5640
 	tristate "SoC Audio support for Tegra boards using an RT5640 codec"
 	depends on I2C && GPIOLIB
diff --git a/sound/soc/tegra/tegra_asoc_machine.c b/sound/soc/tegra/tegra_asoc_machine.c
index 78faa8bcae27..607800ec07a6 100644
--- a/sound/soc/tegra/tegra_asoc_machine.c
+++ b/sound/soc/tegra/tegra_asoc_machine.c
@@ -51,6 +51,17 @@ static struct snd_soc_jack_gpio tegra_machine_headset_jack_gpio = {
 };
 
 /* Mic Jack */
+static int headset_check(void *data)
+{
+	struct tegra_machine *machine = (struct tegra_machine *)data;
+
+	/* Detect mic insertion only if 3.5 jack is in */
+	if (gpiod_get_value_cansleep(machine->gpiod_hp_det) &&
+	    gpiod_get_value_cansleep(machine->gpiod_mic_det))
+		return SND_JACK_MICROPHONE;
+
+	return 0;
+}
 
 static struct snd_soc_jack tegra_machine_mic_jack;
 
@@ -183,8 +194,15 @@ int tegra_asoc_machine_init(struct snd_soc_pcm_runtime *rtd)
 			return err;
 		}
 
+		tegra_machine_mic_jack_gpio.data = machine;
 		tegra_machine_mic_jack_gpio.desc = machine->gpiod_mic_det;
 
+		if (of_property_read_bool(card->dev->of_node,
+					  "nvidia,coupled-mic-hp-det")) {
+			tegra_machine_mic_jack_gpio.desc = machine->gpiod_hp_det;
+			tegra_machine_mic_jack_gpio.jack_status_check = headset_check;
+		};
+
 		err = snd_soc_jack_add_gpios(&tegra_machine_mic_jack, 1,
 					     &tegra_machine_mic_jack_gpio);
 		if (err)
@@ -238,6 +256,27 @@ static unsigned int tegra_machine_mclk_rate_12mhz(unsigned int srate)
 	return mclk;
 }
 
+static unsigned int tegra_machine_mclk_rate_6mhz(unsigned int srate)
+{
+	unsigned int mclk;
+
+	switch (srate) {
+	case 64000:
+	case 88200:
+	case 96000:
+		mclk = 128 * srate;
+		break;
+	default:
+		mclk = 256 * srate;
+		break;
+	}
+	/* FIXME: Codec only requires >= 3MHz if OSR==0 */
+	while (mclk < 6000000)
+		mclk *= 2;
+
+	return mclk;
+}
+
 static int tegra_machine_hw_params(struct snd_pcm_substream *substream,
 				   struct snd_pcm_hw_params *params)
 {
@@ -865,6 +904,40 @@ static const struct tegra_asoc_data tegra_rt5632_data = {
 	.add_headset_jack = true,
 };
 
+/* RT5631 machine */
+
+SND_SOC_DAILINK_DEFS(rt5631_hifi,
+	DAILINK_COMP_ARRAY(COMP_EMPTY()),
+	DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "rt5631-hifi")),
+	DAILINK_COMP_ARRAY(COMP_EMPTY()));
+
+static struct snd_soc_dai_link tegra_rt5631_dai = {
+	.name = "RT5631",
+	.stream_name = "RT5631 PCM",
+	.init = tegra_asoc_machine_init,
+	.dai_fmt = SND_SOC_DAIFMT_I2S |
+		   SND_SOC_DAIFMT_NB_NF |
+		   SND_SOC_DAIFMT_CBS_CFS,
+	SND_SOC_DAILINK_REG(rt5631_hifi),
+};
+
+static struct snd_soc_card snd_soc_tegra_rt5631 = {
+	.components = "codec:rt5631",
+	.dai_link = &tegra_rt5631_dai,
+	.num_links = 1,
+	.fully_routed = true,
+};
+
+static const struct tegra_asoc_data tegra_rt5631_data = {
+	.mclk_rate = tegra_machine_mclk_rate_6mhz,
+	.card = &snd_soc_tegra_rt5631,
+	.add_common_dapm_widgets = true,
+	.add_common_controls = true,
+	.add_common_snd_ops = true,
+	.add_mic_jack = true,
+	.add_hp_jack = true,
+};
+
 static const struct of_device_id tegra_machine_of_match[] = {
 	{ .compatible = "nvidia,tegra-audio-trimslice", .data = &tegra_trimslice_data },
 	{ .compatible = "nvidia,tegra-audio-max98090", .data = &tegra_max98090_data },
@@ -874,6 +947,7 @@ static const struct of_device_id tegra_machine_of_match[] = {
 	{ .compatible = "nvidia,tegra-audio-rt5677", .data = &tegra_rt5677_data },
 	{ .compatible = "nvidia,tegra-audio-rt5640", .data = &tegra_rt5640_data },
 	{ .compatible = "nvidia,tegra-audio-alc5632", .data = &tegra_rt5632_data },
+	{ .compatible = "nvidia,tegra-audio-rt5631", .data = &tegra_rt5631_data },
 	{},
 };
 MODULE_DEVICE_TABLE(of, tegra_machine_of_match);
-- 
2.37.2


  parent reply	other threads:[~2023-02-21 18:32 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-21 18:32 [PATCH v1 00/10] Fix sound on ASUS Transformers Svyatoslav Ryhel
2023-02-21 18:32 ` [PATCH v1 01/10] dt-bindings: sound: nvidia,tegra-audio-common: add new property Svyatoslav Ryhel
2023-02-26 19:35   ` Rob Herring
2023-02-21 18:32 ` [PATCH v1 02/10] sound: soc: jack: allow multiple interrupt per gpio Svyatoslav Ryhel
2023-02-21 22:08   ` Mark Brown
2023-02-22  7:53     ` Svyatoslav Ryhel
2023-02-22 12:16       ` Mark Brown
2023-02-21 18:32 ` [PATCH v1 03/10] dt-bindings: sound: nvidia,tegra-audio: add RT5631 CODEC Svyatoslav Ryhel
2023-02-26 19:37   ` Rob Herring
2023-02-28  8:15   ` Krzysztof Kozlowski
2023-02-21 18:32 ` Svyatoslav Ryhel [this message]
2023-02-21 19:32   ` [PATCH v1 04/10] ASoC: tegra: Support RT5631 by machine driver Dan Carpenter
2023-02-22  7:55     ` Svyatoslav Ryhel
2023-02-22 13:28       ` Dan Carpenter
2023-02-22 14:57         ` Mark Brown
2023-02-21 22:23   ` Mark Brown
2023-02-22  8:00     ` Svyatoslav Ryhel
2023-02-22 12:17       ` Mark Brown
2023-02-21 18:32 ` [PATCH v1 05/10] dt-bindings: sound: nvidia,tegra-audio: add MAX9808x CODEC Svyatoslav Ryhel
2023-02-26 19:38   ` Rob Herring
2023-02-21 18:32 ` [PATCH v1 06/10] ASoC: tegra: Support MAX9808x by machine driver Svyatoslav Ryhel
2023-02-21 18:32 ` [PATCH v1 07/10] ARM: tegra: transformers: update bindings of sound graph Svyatoslav Ryhel
2023-02-21 22:26   ` Mark Brown
2023-02-22  8:02     ` Svyatoslav Ryhel
2023-02-22 12:19       ` Mark Brown
2023-02-21 18:32 ` [PATCH v1 08/10] dt-bindings: dsp: add Fortemedia FM34 DSP Svyatoslav Ryhel
2023-02-26 19:42   ` Rob Herring
2023-02-21 18:32 ` [PATCH v1 09/10] staging: dsp: add support for Fortemedia FM34NE DSP Svyatoslav Ryhel
2023-02-21 19:27   ` Greg Kroah-Hartman
2023-02-22  8:19     ` Svyatoslav Ryhel
2023-02-22  9:21       ` Greg Kroah-Hartman
2023-02-22  9:39         ` Святослав Ригель
2023-02-22 11:15           ` Greg Kroah-Hartman
2023-02-22 12:19       ` Mark Brown
2023-02-21 19:39   ` Dan Carpenter
2023-02-22  8:06     ` Svyatoslav Ryhel
2023-02-22 13:31       ` Dan Carpenter
2023-02-21 22:41   ` Mark Brown
2023-02-22  8:14     ` Svyatoslav Ryhel
2023-02-22 12:36       ` Mark Brown
2023-02-21 18:32 ` [PATCH v1 10/10] ARM: tegra: transformers: bind FM34NE DSP on supported devices Svyatoslav Ryhel
2023-03-06 13:31 ` (subset) [PATCH v1 00/10] Fix sound on ASUS Transformers 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=20230221183211.21964-5-clamor95@gmail.com \
    --to=clamor95@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=digetx@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=jonathanh@nvidia.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-staging@lists.linux.dev \
    --cc=linux-tegra@vger.kernel.org \
    --cc=maxim.schwalm@gmail.com \
    --cc=perex@perex.cz \
    --cc=robh+dt@kernel.org \
    --cc=thierry.reding@gmail.com \
    --cc=tiwai@suse.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 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®