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: "Cezary Rojewski" <cezary.rojewski@intel.com>,
	tiwai@suse.de, "Péter Ujfalusi" <peter.ujfalusi@linux.intel.com>,
	"Huajun Li" <huajun.li@intel.com>,
	"Pierre-Louis Bossart" <pierre-louis.bossart@linux.intel.com>,
	"Nikolai Kostrigin" <nickel@altlinux.org>,
	broonie@kernel.org, "Mauro Carvalho Chehab" <mchehab@kernel.org>,
	"Bard Liao" <yung-chuan.liao@linux.intel.com>
Subject: [PATCH 06/20] ASoC: Intel: soc-acpi: quirk topology filename dynamically
Date: Tue,  8 Mar 2022 13:25:56 -0600	[thread overview]
Message-ID: <20220308192610.392950-7-pierre-louis.bossart@linux.intel.com> (raw)
In-Reply-To: <20220308192610.392950-1-pierre-louis.bossart@linux.intel.com>

Different topology filenames may be required depending on which SSP is
used, and whether or not digital mics are present.

This patch adds a tplg_quirk_mask and in the case of the SOF driver
adds the relevant configurations.

This is a short-term solution to the ES8336 support issues.

In a long-term solution, we would need an interface where the machine
driver or platform driver have the ability to alter the topology
hard-coded low-level hardware support, e.g. by substituting an
interface for another, or disabling an interface that is not supported
on a given skew.

BugLink: https://github.com/thesofproject/linux/issues/3248
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Reviewed-by: Péter Ujfalusi <peter.ujfalusi@linux.intel.com>
---
 include/sound/soc-acpi.h                      | 20 +++++++
 .../intel/common/soc-acpi-intel-bxt-match.c   |  5 +-
 .../intel/common/soc-acpi-intel-cml-match.c   |  5 +-
 .../intel/common/soc-acpi-intel-glk-match.c   |  5 +-
 .../intel/common/soc-acpi-intel-jsl-match.c   |  5 +-
 .../intel/common/soc-acpi-intel-tgl-match.c   |  5 +-
 sound/soc/sof/intel/hda.c                     | 52 +++++++++++++++++++
 7 files changed, 92 insertions(+), 5 deletions(-)

diff --git a/include/sound/soc-acpi.h b/include/sound/soc-acpi.h
index 093bbe7f0e1f..d33cf8df14b1 100644
--- a/include/sound/soc-acpi.h
+++ b/include/sound/soc-acpi.h
@@ -125,6 +125,24 @@ struct snd_soc_acpi_link_adr {
 	const struct snd_soc_acpi_adr_device *adr_d;
 };
 
+/*
+ * when set the topology uses the -ssp<N> suffix, where N is determined based on
+ * BIOS or DMI information
+ */
+#define SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER BIT(0)
+
+/*
+ * when more than one SSP is reported in the link mask, use the most significant.
+ * This choice was found to be valid on platforms with ES8336 codecs.
+ */
+#define SND_SOC_ACPI_TPLG_INTEL_SSP_MSB BIT(1)
+
+/*
+ * when set the topology uses the -dmic<N>ch suffix, where N is determined based on
+ * BIOS or DMI information
+ */
+#define SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER BIT(2)
+
 /**
  * snd_soc_acpi_mach: ACPI-based machine descriptor. Most of the fields are
  * related to the hardware, except for the firmware and topology file names.
@@ -146,6 +164,7 @@ struct snd_soc_acpi_link_adr {
  * @pdata: intended for platform data or machine specific-ops. This structure
  *  is not constant since this field may be updated at run-time
  * @sof_tplg_filename: Sound Open Firmware topology file name, if enabled
+ * @tplg_quirk_mask: quirks to select different topology files dynamically
  */
 /* Descriptor for SST ASoC machine driver */
 struct snd_soc_acpi_mach {
@@ -161,6 +180,7 @@ struct snd_soc_acpi_mach {
 	void *pdata;
 	struct snd_soc_acpi_mach_params mach_params;
 	const char *sof_tplg_filename;
+	const u32 tplg_quirk_mask;
 };
 
 #define SND_SOC_ACPI_MAX_CODECS 3
diff --git a/sound/soc/intel/common/soc-acpi-intel-bxt-match.c b/sound/soc/intel/common/soc-acpi-intel-bxt-match.c
index 718947068956..0a2d0874dc4f 100644
--- a/sound/soc/intel/common/soc-acpi-intel-bxt-match.c
+++ b/sound/soc/intel/common/soc-acpi-intel-bxt-match.c
@@ -80,7 +80,10 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_bxt_machines[] = {
 	{
 		.id = "ESSX8336",
 		.drv_name = "sof-essx8336",
-		.sof_tplg_filename = "sof-apl-es8336.tplg",
+		.sof_tplg_filename = "sof-apl-es8336", /* the tplg suffix is added at run time */
+		.tplg_quirk_mask = SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER |
+					SND_SOC_ACPI_TPLG_INTEL_SSP_MSB |
+					SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER,
 	},
 	{},
 };
diff --git a/sound/soc/intel/common/soc-acpi-intel-cml-match.c b/sound/soc/intel/common/soc-acpi-intel-cml-match.c
index d033474f8768..f75fa1b551d7 100644
--- a/sound/soc/intel/common/soc-acpi-intel-cml-match.c
+++ b/sound/soc/intel/common/soc-acpi-intel-cml-match.c
@@ -78,7 +78,10 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_cml_machines[] = {
 	{
 		.id = "ESSX8336",
 		.drv_name = "sof-essx8336",
-		.sof_tplg_filename = "sof-cml-es8336.tplg",
+		.sof_tplg_filename = "sof-cml-es8336", /* the tplg suffix is added at run time */
+		.tplg_quirk_mask = SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER |
+					SND_SOC_ACPI_TPLG_INTEL_SSP_MSB |
+					SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER,
 	},
 	{},
 };
diff --git a/sound/soc/intel/common/soc-acpi-intel-glk-match.c b/sound/soc/intel/common/soc-acpi-intel-glk-match.c
index c5ca077c7ac9..d494860b8190 100644
--- a/sound/soc/intel/common/soc-acpi-intel-glk-match.c
+++ b/sound/soc/intel/common/soc-acpi-intel-glk-match.c
@@ -55,7 +55,10 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_glk_machines[] = {
 	{
 		.id = "ESSX8336",
 		.drv_name = "sof-essx8336",
-		.sof_tplg_filename = "sof-glk-es8336.tplg",
+		.sof_tplg_filename = "sof-glk-es8336", /* the tplg suffix is added at run time */
+		.tplg_quirk_mask = SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER |
+					SND_SOC_ACPI_TPLG_INTEL_SSP_MSB |
+					SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER,
 	},
 	{},
 };
diff --git a/sound/soc/intel/common/soc-acpi-intel-jsl-match.c b/sound/soc/intel/common/soc-acpi-intel-jsl-match.c
index a2da5cad520c..53c42a4e1694 100644
--- a/sound/soc/intel/common/soc-acpi-intel-jsl-match.c
+++ b/sound/soc/intel/common/soc-acpi-intel-jsl-match.c
@@ -83,7 +83,10 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_jsl_machines[] = {
 	{
 		.id = "ESSX8336",
 		.drv_name = "sof-essx8336",
-		.sof_tplg_filename = "sof-jsl-es8336.tplg",
+		.sof_tplg_filename = "sof-jsl-es8336", /* the tplg suffix is added at run time */
+		.tplg_quirk_mask = SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER |
+					SND_SOC_ACPI_TPLG_INTEL_SSP_MSB |
+					SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER,
 	},
 	{},
 };
diff --git a/sound/soc/intel/common/soc-acpi-intel-tgl-match.c b/sound/soc/intel/common/soc-acpi-intel-tgl-match.c
index 224b54d35c7a..8bf14295deb0 100644
--- a/sound/soc/intel/common/soc-acpi-intel-tgl-match.c
+++ b/sound/soc/intel/common/soc-acpi-intel-tgl-match.c
@@ -393,7 +393,10 @@ struct snd_soc_acpi_mach snd_soc_acpi_intel_tgl_machines[] = {
 	{
 		.id = "ESSX8336",
 		.drv_name = "sof-essx8336",
-		.sof_tplg_filename = "sof-tgl-es8336.tplg",
+		.sof_tplg_filename = "sof-tgl-es8336", /* the tplg suffix is added at run time */
+		.tplg_quirk_mask = SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER |
+					SND_SOC_ACPI_TPLG_INTEL_SSP_MSB |
+					SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER,
 	},
 	{
 		.id = "10EC1308",
diff --git a/sound/soc/sof/intel/hda.c b/sound/soc/sof/intel/hda.c
index eebb3b318d79..07d8686632a5 100644
--- a/sound/soc/sof/intel/hda.c
+++ b/sound/soc/sof/intel/hda.c
@@ -1393,9 +1393,12 @@ struct snd_soc_acpi_mach *hda_machine_select(struct snd_sof_dev *sdev)
 	struct snd_sof_pdata *sof_pdata = sdev->pdata;
 	const struct sof_dev_desc *desc = sof_pdata->desc;
 	struct snd_soc_acpi_mach *mach;
+	const char *tplg_filename;
 
 	mach = snd_soc_acpi_find_machine(desc->machines);
 	if (mach) {
+		bool add_extension = false;
+
 		/*
 		 * If tplg file name is overridden, use it instead of
 		 * the one set in mach table
@@ -1406,6 +1409,21 @@ struct snd_soc_acpi_mach *hda_machine_select(struct snd_sof_dev *sdev)
 		/* report to machine driver if any DMICs are found */
 		mach->mach_params.dmic_num = check_dmic_num(sdev);
 
+		if (mach->tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER &&
+		    mach->mach_params.dmic_num) {
+			tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
+						       "%s%s%d%s",
+						       sof_pdata->tplg_filename,
+						       "-dmic",
+						       mach->mach_params.dmic_num,
+						       "ch");
+			if (!tplg_filename)
+				return NULL;
+
+			sof_pdata->tplg_filename = tplg_filename;
+			add_extension = true;
+		}
+
 		if (mach->link_mask) {
 			mach->mach_params.links = mach->links;
 			mach->mach_params.link_mask = mach->link_mask;
@@ -1413,6 +1431,40 @@ struct snd_soc_acpi_mach *hda_machine_select(struct snd_sof_dev *sdev)
 
 		/* report SSP link mask to machine driver */
 		mach->mach_params.i2s_link_mask = check_nhlt_ssp_mask(sdev);
+
+		if (mach->tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER &&
+		    mach->mach_params.i2s_link_mask) {
+			int ssp_num;
+
+			if (hweight_long(mach->mach_params.i2s_link_mask) > 1 &&
+			    !(mach->tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_SSP_MSB))
+				dev_warn(sdev->dev, "More than one SSP exposed by NHLT, choosing MSB\n");
+
+			/* fls returns 1-based results, SSPs indices are 0-based */
+			ssp_num = fls(mach->mach_params.i2s_link_mask) - 1;
+
+			tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
+						       "%s%s%d",
+						       sof_pdata->tplg_filename,
+						       "-ssp",
+						       ssp_num);
+			if (!tplg_filename)
+				return NULL;
+
+			sof_pdata->tplg_filename = tplg_filename;
+			add_extension = true;
+		}
+
+		if (add_extension) {
+			tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
+						       "%s%s",
+						       sof_pdata->tplg_filename,
+						       ".tplg");
+			if (!tplg_filename)
+				return NULL;
+
+			sof_pdata->tplg_filename = tplg_filename;
+		}
 	}
 
 	/*
-- 
2.30.2


  parent reply	other threads:[~2022-03-08 19:29 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-08 19:25 [PATCH 00/20] ALSA/ASoC/SOF/Intel: improve support for ES8336-based platforms Pierre-Louis Bossart
2022-03-08 19:25 ` [PATCH 01/20] ASoC: soc-acpi: fix kernel-doc descriptor Pierre-Louis Bossart
2022-03-08 19:25 ` [PATCH 02/20] ASoC: soc-acpi: add information on I2S/TDM link mask Pierre-Louis Bossart
2022-03-08 19:25 ` [PATCH 03/20] ASoC: SOF: Intel: hda: retrieve DMIC number for I2S boards Pierre-Louis Bossart
2022-03-09 16:49   ` Cezary Rojewski
2022-03-09 17:10     ` Pierre-Louis Bossart
2022-03-08 19:25 ` [PATCH 04/20] ALSA: intel-nhlt: add helper to detect SSP link mask Pierre-Louis Bossart
2022-03-09 10:03   ` Takashi Iwai
2022-03-09 17:01   ` Cezary Rojewski
2022-03-09 17:24     ` Pierre-Louis Bossart
2022-03-08 19:25 ` [PATCH 05/20] ASoC: SOF: Intel: hda: report SSP link mask to machine driver Pierre-Louis Bossart
2022-03-09 16:59   ` Cezary Rojewski
2022-03-09 17:16     ` Pierre-Louis Bossart
2022-03-08 19:25 ` Pierre-Louis Bossart [this message]
2022-03-08 19:25 ` [PATCH 07/20] ALSA: intel-dsp-config: add more ACPI HIDs for ES83x6 devices Pierre-Louis Bossart
2022-03-09 10:04   ` Takashi Iwai
2022-03-08 19:25 ` [PATCH 08/20] ASoC: Intel: soc-acpi: " Pierre-Louis Bossart
2022-03-08 19:25 ` [PATCH 09/20] ALSA: intel-dspconfig: add ES8336 support for CNL Pierre-Louis Bossart
2022-03-09 10:04   ` Takashi Iwai
2022-03-08 19:26 ` [PATCH 10/20] ASoC: Intel: soc-acpi: add ESSX8336 support on Cannon Lake machines Pierre-Louis Bossart
2022-03-08 19:26 ` [PATCH 11/20] ASoC: Intel: sof_es8336: make gpio optional Pierre-Louis Bossart
2022-03-08 19:26 ` [PATCH 12/20] ASoC: Intel: sof_es8336: get codec device with ACPI instead of bus search Pierre-Louis Bossart
2022-03-08 19:26 ` [PATCH 13/20] ASoC: Intel: Revert "ASoC: Intel: sof_es8336: add quirk for Huawei D15 2021" Pierre-Louis Bossart
2022-03-08 19:26 ` [PATCH 14/20] ASoC: Intel: sof_es8336: use NHLT information to set dmic and SSP Pierre-Louis Bossart
2022-03-08 19:26 ` [PATCH 15/20] ASoC: Intel: sof_es8336: log all quirks Pierre-Louis Bossart
2022-03-08 19:26 ` [PATCH 16/20] ASoC: Intel: sof_es8336: move comment to the right place Pierre-Louis Bossart
2022-03-08 19:26 ` [PATCH 17/20] ASoC: Intel: sof_es8336: add support for JD inverted quirk Pierre-Louis Bossart
2022-03-08 19:26 ` [PATCH 18/20] ASoC: Intel: sof_es8336: extend machine driver to support ES8326 codec Pierre-Louis Bossart
2022-03-08 19:26 ` [PATCH 19/20] ASoC: Intel: sof_es8336: add cfg-dmics component for UCM support Pierre-Louis Bossart
2022-03-08 19:26 ` [PATCH 20/20] ASoC: Intel: bytcht_es8316: move comment to the right place Pierre-Louis Bossart
2022-03-10 11:35 ` [PATCH 00/20] ALSA/ASoC/SOF/Intel: improve support for ES8336-based platforms 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=20220308192610.392950-7-pierre-louis.bossart@linux.intel.com \
    --to=pierre-louis.bossart@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=cezary.rojewski@intel.com \
    --cc=huajun.li@intel.com \
    --cc=mchehab@kernel.org \
    --cc=nickel@altlinux.org \
    --cc=peter.ujfalusi@linux.intel.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.