All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: linux-sound@vger.kernel.org
Cc: alsa-devel@alsa-project.org, tiwai@suse.de, broonie@kernel.org,
	"Charles Keepax" <ckeepax@opensource.cirrus.com>,
	"Richard Fitzgerald" <rf@opensource.cirrus.com>,
	"Shuming Fan" <shumingf@realtek.com>,
	"Jack Yu" <jack.yu@realtek.com>,
	"Oder Chiou" <oder_chiou@realtek.com>,
	"Bard liao" <yung-chuan.liao@linux.intel.com>,
	"Chao Song" <chao.song@linux.intel.com>,
	"Péter Ujfalusi" <peter.ujfalusi@linux.intel.com>,
	"Pierre-Louis Bossart" <pierre-louis.bossart@linux.intel.com>
Subject: [PATCH 24/34] ASoC: Intel: sof_sdw: use generic rtd_init function for Realtek SDW DMICs
Date: Tue, 26 Mar 2024 11:04:19 -0500	[thread overview]
Message-ID: <20240326160429.13560-25-pierre-louis.bossart@linux.intel.com> (raw)
In-Reply-To: <20240326160429.13560-1-pierre-louis.bossart@linux.intel.com>

From: Bard Liao <yung-chuan.liao@linux.intel.com>

The only thing that the rt_xxx_rtd_init() functions do is to set
card->components. And we can set card->components with name_prefix
as rt712_sdca_dmic_rtd_init() does.
And sof_sdw_rtd_init() will always select the first dai with the
given dai->name from codec_info_list[]. Unfortunately, we have
different codecs with the same dai name. For example, dai name of
rt715 and rt715-sdca are both "rt715-aif2". Using a generic rtd_init
allow sof_sdw_rtd_init() run the rtd_init() callback from a similar
codec dai.

Fixes: 8266c73126b7 ("ASoC: Intel: sof_sdw: add common sdw dai link init")
Reviewed-by: Chao Song <chao.song@linux.intel.com>
Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com>
Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
---
 sound/soc/intel/boards/Makefile          |  1 +
 sound/soc/intel/boards/sof_sdw.c         | 12 +++---
 sound/soc/intel/boards/sof_sdw_common.h  |  1 +
 sound/soc/intel/boards/sof_sdw_rt_dmic.c | 52 ++++++++++++++++++++++++
 4 files changed, 60 insertions(+), 6 deletions(-)
 create mode 100644 sound/soc/intel/boards/sof_sdw_rt_dmic.c

diff --git a/sound/soc/intel/boards/Makefile b/sound/soc/intel/boards/Makefile
index bbf796a5f7ba..08cfd4baecdd 100644
--- a/sound/soc/intel/boards/Makefile
+++ b/sound/soc/intel/boards/Makefile
@@ -42,6 +42,7 @@ snd-soc-sof-sdw-objs += sof_sdw.o				\
 			sof_sdw_rt711.o sof_sdw_rt_sdca_jack_common.o	\
 			sof_sdw_rt712_sdca.o sof_sdw_rt715.o	\
 			sof_sdw_rt715_sdca.o sof_sdw_rt722_sdca.o	\
+			sof_sdw_rt_dmic.o			\
 			sof_sdw_cs42l42.o sof_sdw_cs42l43.o	\
 			sof_sdw_cs_amp.o			\
 			sof_sdw_dmic.o				\
diff --git a/sound/soc/intel/boards/sof_sdw.c b/sound/soc/intel/boards/sof_sdw.c
index 3e6a758c98ab..0e376cb0ce0b 100644
--- a/sound/soc/intel/boards/sof_sdw.c
+++ b/sound/soc/intel/boards/sof_sdw.c
@@ -749,7 +749,7 @@ static struct sof_sdw_codec_info codec_info_list[] = {
 				.dai_name = "rt712-sdca-dmic-aif1",
 				.dai_type = SOF_SDW_DAI_TYPE_MIC,
 				.dailink = {SDW_UNUSED_DAI_ID, SDW_DMIC_DAI_ID},
-				.rtd_init = rt712_sdca_dmic_rtd_init,
+				.rtd_init = rt_dmic_rtd_init,
 			},
 		},
 		.dai_num = 1,
@@ -779,7 +779,7 @@ static struct sof_sdw_codec_info codec_info_list[] = {
 				.dai_name = "rt712-sdca-dmic-aif1",
 				.dai_type = SOF_SDW_DAI_TYPE_MIC,
 				.dailink = {SDW_UNUSED_DAI_ID, SDW_DMIC_DAI_ID},
-				.rtd_init = rt712_sdca_dmic_rtd_init,
+				.rtd_init = rt_dmic_rtd_init,
 			},
 		},
 		.dai_num = 1,
@@ -841,7 +841,7 @@ static struct sof_sdw_codec_info codec_info_list[] = {
 				.dai_name = "rt715-aif2",
 				.dai_type = SOF_SDW_DAI_TYPE_MIC,
 				.dailink = {SDW_UNUSED_DAI_ID, SDW_DMIC_DAI_ID},
-				.rtd_init = rt715_sdca_rtd_init,
+				.rtd_init = rt_dmic_rtd_init,
 			},
 		},
 		.dai_num = 1,
@@ -856,7 +856,7 @@ static struct sof_sdw_codec_info codec_info_list[] = {
 				.dai_name = "rt715-aif2",
 				.dai_type = SOF_SDW_DAI_TYPE_MIC,
 				.dailink = {SDW_UNUSED_DAI_ID, SDW_DMIC_DAI_ID},
-				.rtd_init = rt715_sdca_rtd_init,
+				.rtd_init = rt_dmic_rtd_init,
 			},
 		},
 		.dai_num = 1,
@@ -871,7 +871,7 @@ static struct sof_sdw_codec_info codec_info_list[] = {
 				.dai_name = "rt715-aif2",
 				.dai_type = SOF_SDW_DAI_TYPE_MIC,
 				.dailink = {SDW_UNUSED_DAI_ID, SDW_DMIC_DAI_ID},
-				.rtd_init = rt715_rtd_init,
+				.rtd_init = rt_dmic_rtd_init,
 			},
 		},
 		.dai_num = 1,
@@ -886,7 +886,7 @@ static struct sof_sdw_codec_info codec_info_list[] = {
 				.dai_name = "rt715-aif2",
 				.dai_type = SOF_SDW_DAI_TYPE_MIC,
 				.dailink = {SDW_UNUSED_DAI_ID, SDW_DMIC_DAI_ID},
-				.rtd_init = rt715_rtd_init,
+				.rtd_init = rt_dmic_rtd_init,
 			},
 		},
 		.dai_num = 1,
diff --git a/sound/soc/intel/boards/sof_sdw_common.h b/sound/soc/intel/boards/sof_sdw_common.h
index e21ef79126b2..decaed97fa74 100644
--- a/sound/soc/intel/boards/sof_sdw_common.h
+++ b/sound/soc/intel/boards/sof_sdw_common.h
@@ -197,6 +197,7 @@ int rt712_sdca_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd);
 int rt712_spk_rtd_init(struct snd_soc_pcm_runtime *rtd);
 int rt715_rtd_init(struct snd_soc_pcm_runtime *rtd);
 int rt715_sdca_rtd_init(struct snd_soc_pcm_runtime *rtd);
+int rt_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd);
 int rt_amp_spk_rtd_init(struct snd_soc_pcm_runtime *rtd);
 int rt_sdca_jack_rtd_init(struct snd_soc_pcm_runtime *rtd);
 
diff --git a/sound/soc/intel/boards/sof_sdw_rt_dmic.c b/sound/soc/intel/boards/sof_sdw_rt_dmic.c
new file mode 100644
index 000000000000..9091f5b5c648
--- /dev/null
+++ b/sound/soc/intel/boards/sof_sdw_rt_dmic.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0-only
+// Copyright (c) 2024 Intel Corporation
+
+/*
+ * sof_sdw_rt_dmic - Helpers to handle Realtek SDW DMIC from generic machine driver
+ */
+
+#include <linux/device.h>
+#include <linux/errno.h>
+#include <sound/soc.h>
+#include <sound/soc-acpi.h>
+#include "sof_board_helpers.h"
+#include "sof_sdw_common.h"
+
+static const char * const dmics[] = {
+	"rt715",
+	"rt712-sdca-dmic",
+};
+
+int rt_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd)
+{
+	struct snd_soc_card *card = rtd->card;
+	struct snd_soc_component *component;
+	struct snd_soc_dai *codec_dai;
+	char *mic_name;
+
+	codec_dai = get_codec_dai_by_name(rtd, dmics, ARRAY_SIZE(dmics));
+	if (!codec_dai)
+		return -EINVAL;
+
+	component = codec_dai->component;
+
+	/*
+	 * rt715-sdca (aka rt714) is a special case that uses different name in card->components
+	 * and component->name_prefix.
+	 */
+	if (!strcmp(component->name_prefix, "rt714"))
+		mic_name = devm_kasprintf(card->dev, GFP_KERNEL, "rt715-sdca");
+	else
+		mic_name = devm_kasprintf(card->dev, GFP_KERNEL, "%s", component->name_prefix);
+
+	card->components = devm_kasprintf(card->dev, GFP_KERNEL,
+					  "%s mic:%s", card->components,
+					  mic_name);
+	if (!card->components)
+		return -ENOMEM;
+
+	dev_dbg(card->dev, "card->components: %s\n", card->components);
+
+	return 0;
+}
+MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_BOARD_HELPERS);
-- 
2.40.1


  parent reply	other threads:[~2024-03-26 16:05 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-26 16:03 [PATCH 00/34] ASoC: Intel: boards: updates for 6.10 - part2 Pierre-Louis Bossart
2024-03-26 16:03 ` [PATCH 01/34] ASoC: intel: sof_sdw: Make find_codec_info_part() return a pointer Pierre-Louis Bossart
2024-03-26 16:03 ` [PATCH 02/34] ASoC: intel: sof_sdw: Make find_codec_info_acpi() " Pierre-Louis Bossart
2024-03-26 16:03 ` [PATCH 03/34] ASoC: intel: sof_sdw: Make find_codec_info_dai() " Pierre-Louis Bossart
2024-03-26 16:03 ` [PATCH 04/34] ASoC: intel: sof_sdw: Only pass codec_conf pointer around Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 05/34] ASoC: intel: sof_sdw: Set channel map directly from endpoints Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 06/34] ASoC: Intel: sof_sdw: Move get_codec_dai_by_name() into sof_sdw itself Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 07/34] ASoC: Intel: sof_sdw: Move flags to private struct Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 08/34] ASoC: Intel: sof_sdw: Only pass dai_link pointer around Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 09/34] ASoC: Intel: sof_sdw: Use for_each_set_bit Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 10/34] ASoC: Intel: sof_sdw: Factor out SSP DAI creation Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 11/34] ASoC: Intel: sof_sdw: Factor out DMIC " Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 12/34] ASoC: Intel: sof_sdw: Factor out HDMI " Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 13/34] ASoC: Intel: sof_sdw: Factor out BlueTooth " Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 14/34] ASoC: Intel: sof_sdw: Factor out codec name generation Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 15/34] ASoC: Intel: soc-acpi-intel-arl-match: Add rt711 sdca codec support Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 16/34] ASoC: Intel: sof_sdw: Remove no longer supported quirk Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 17/34] ASoC: intel: soc-acpi: Add missing cs42l43 endpoints Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 18/34] ASoC: Intel: sof-sdw: Add new code for parsing the snd_soc_acpi structs Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 19/34] ASoC: Intel: sof_sdw: Move counting and codec_conf to new parsing Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 20/34] ASoC: Intel: sof_sdw: Move ignore_pch_dmic " Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 21/34] ASoC: Intel: sof_sdw: Move append_dai_type " Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 22/34] ASoC: Intel: sof_sdw: Move generation of DAI links " Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 23/34] ASoC: intel: sof_sdw: Factor out SoundWire DAI creation Pierre-Louis Bossart
2024-03-26 16:04 ` Pierre-Louis Bossart [this message]
2024-03-26 16:04 ` [PATCH 25/34] ASoC: Intel: sof_sdw: remove unused rt dmic rtd_init Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 26/34] ASoC: Intel: sof_sdw_rt722_sdca: set rtd_init in codec_info_list[] Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 27/34] ASoC: Intel: sof_sdw_rt722_sdca: use rt_dmic_rtd_init Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 28/34] ASoC: rt715-sdca: rename dai name with rt715-sdca prefix Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 29/34] ASoC: Intel: sof_sdw: change rt715-sdca dai name Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 30/34] ASoC: Intel: change cs35l56 name_prefix Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 31/34] ASoC: Intel: sof_sdw: Don't pass acpi_link_adr to init functions Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 32/34] ASoC: Intel: sof_sdw: Remove redundant initialisations Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 33/34] ASoC: Intel: sof_sdw: Add quirk for optional codec speakers Pierre-Louis Bossart
2024-03-26 16:04 ` [PATCH 34/34] ASoC: Intel: sof_sdw: Add support for cs42l43 optional speaker output Pierre-Louis Bossart
2024-03-27 15:10 ` [PATCH 00/34] ASoC: Intel: boards: updates for 6.10 - part2 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=20240326160429.13560-25-pierre-louis.bossart@linux.intel.com \
    --to=pierre-louis.bossart@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=chao.song@linux.intel.com \
    --cc=ckeepax@opensource.cirrus.com \
    --cc=jack.yu@realtek.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=oder_chiou@realtek.com \
    --cc=peter.ujfalusi@linux.intel.com \
    --cc=rf@opensource.cirrus.com \
    --cc=shumingf@realtek.com \
    --cc=tiwai@suse.de \
    --cc=yung-chuan.liao@linux.intel.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.