ASoC: SOF: Intel: support tplg suffix detection
authorBrent Lu <brent.lu@intel.com>
Wed, 27 Mar 2024 16:23:57 +0000 (11:23 -0500)
committerMark Brown <broonie@kernel.org>
Thu, 28 Mar 2024 13:58:15 +0000 (13:58 +0000)
Add new flags to tplg_quirk_mask to detect and append codec/amplifier
tplg suffix to topology file name at runtime. With this feature we
could implement an enumeration entry for all boards which implement
same headphone codec regardless the speaker amplifier type.

Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Signed-off-by: Brent Lu <brent.lu@intel.com>
Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://msgid.link/r/20240327162408.63953-8-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
include/sound/soc-acpi.h
sound/soc/sof/intel/hda.c

index 23d6d6bfb073645c9ce583831b886c0765700619..1d8f35ca1d6f33945ca41c671f9ec7a9b2b43a18 100644 (file)
@@ -151,6 +151,18 @@ struct snd_soc_acpi_link_adr {
  */
 #define SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER BIT(2)
 
+/*
+ * when set the speaker amplifier name suffix (i.e. "-max98360a") will be
+ * appended to topology file name
+ */
+#define SND_SOC_ACPI_TPLG_INTEL_AMP_NAME BIT(3)
+
+/*
+ * when set the headphone codec name suffix (i.e. "-rt5682") will be appended to
+ * topology file name
+ */
+#define SND_SOC_ACPI_TPLG_INTEL_CODEC_NAME BIT(4)
+
 /**
  * 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.
index 7fe72b06545147aee2bde593de7c7a5129de4a10..e26b8fd682e5e6ed99873ff7531406b673b5129a 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/soundwire/sdw_intel.h>
 #include <sound/intel-dsp-config.h>
 #include <sound/intel-nhlt.h>
+#include <sound/soc-acpi-intel-ssp-common.h>
 #include <sound/sof.h>
 #include <sound/sof/xtensa.h>
 #include <sound/hda-mlink.h>
@@ -1676,13 +1677,36 @@ void hda_set_mach_params(struct snd_soc_acpi_mach *mach,
        mach_params->dai_drivers = desc->ops->drv;
 }
 
+static int check_tplg_quirk_mask(struct snd_soc_acpi_mach *mach)
+{
+       u32 dmic_ssp_quirk;
+       u32 codec_amp_name_quirk;
+
+       /*
+        * In current implementation dmic and ssp quirks are designed for es8336
+        * machine driver and could not be mixed with codec name and amp name
+        * quirks.
+        */
+       dmic_ssp_quirk = mach->tplg_quirk_mask &
+                        (SND_SOC_ACPI_TPLG_INTEL_DMIC_NUMBER | SND_SOC_ACPI_TPLG_INTEL_SSP_NUMBER);
+       codec_amp_name_quirk = mach->tplg_quirk_mask &
+                        (SND_SOC_ACPI_TPLG_INTEL_AMP_NAME | SND_SOC_ACPI_TPLG_INTEL_CODEC_NAME);
+
+       if (dmic_ssp_quirk && codec_amp_name_quirk)
+               return -EINVAL;
+
+       return 0;
+}
+
 struct snd_soc_acpi_mach *hda_machine_select(struct snd_sof_dev *sdev)
 {
        u32 interface_mask = hda_get_interface_mask(sdev);
        struct snd_sof_pdata *sof_pdata = sdev->pdata;
        const struct sof_dev_desc *desc = sof_pdata->desc;
        struct snd_soc_acpi_mach *mach = NULL;
+       enum snd_soc_acpi_intel_codec codec_type;
        const char *tplg_filename;
+       const char *tplg_suffix;
 
        /* Try I2S or DMIC if it is supported */
        if (interface_mask & (BIT(SOF_DAI_INTEL_SSP) | BIT(SOF_DAI_INTEL_DMIC)))
@@ -1701,6 +1725,17 @@ struct snd_soc_acpi_mach *hda_machine_select(struct snd_sof_dev *sdev)
                        tplg_fixup = true;
                }
 
+               /*
+                * Checking quirk mask integrity; some quirk flags could not be
+                * set concurrently.
+                */
+               if (tplg_fixup &&
+                   check_tplg_quirk_mask(mach)) {
+                       dev_err(sdev->dev, "Invalid tplg quirk mask 0x%x\n",
+                               mach->tplg_quirk_mask);
+                       return NULL;
+               }
+
                /* report to machine driver if any DMICs are found */
                mach->mach_params.dmic_num = check_dmic_num(sdev);
 
@@ -1775,6 +1810,52 @@ struct snd_soc_acpi_mach *hda_machine_select(struct snd_sof_dev *sdev)
                        }
                }
 
+               codec_type = snd_soc_acpi_intel_detect_amp_type(sdev->dev);
+
+               if (tplg_fixup &&
+                   mach->tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_AMP_NAME &&
+                   codec_type != CODEC_NONE) {
+                       tplg_suffix = snd_soc_acpi_intel_get_amp_tplg_suffix(codec_type);
+                       if (!tplg_suffix) {
+                               dev_err(sdev->dev, "no tplg suffix found, amp %d\n",
+                                       codec_type);
+                               return NULL;
+                       }
+
+                       tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
+                                                      "%s-%s",
+                                                      sof_pdata->tplg_filename,
+                                                      tplg_suffix);
+                       if (!tplg_filename)
+                               return NULL;
+
+                       sof_pdata->tplg_filename = tplg_filename;
+                       add_extension = true;
+               }
+
+               codec_type = snd_soc_acpi_intel_detect_codec_type(sdev->dev);
+
+               if (tplg_fixup &&
+                   mach->tplg_quirk_mask & SND_SOC_ACPI_TPLG_INTEL_CODEC_NAME &&
+                   codec_type != CODEC_NONE) {
+                       tplg_suffix = snd_soc_acpi_intel_get_codec_tplg_suffix(codec_type);
+                       if (!tplg_suffix) {
+                               dev_err(sdev->dev, "no tplg suffix found, codec %d\n",
+                                       codec_type);
+                               return NULL;
+                       }
+
+                       tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
+                                                      "%s-%s",
+                                                      sof_pdata->tplg_filename,
+                                                      tplg_suffix);
+                       if (!tplg_filename)
+                               return NULL;
+
+                       sof_pdata->tplg_filename = tplg_filename;
+                       add_extension = true;
+               }
+
                if (tplg_fixup && add_extension) {
                        tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
                                                       "%s%s",
@@ -1842,3 +1923,4 @@ MODULE_IMPORT_NS(SND_INTEL_SOUNDWIRE_ACPI);
 MODULE_IMPORT_NS(SOUNDWIRE_INTEL_INIT);
 MODULE_IMPORT_NS(SOUNDWIRE_INTEL);
 MODULE_IMPORT_NS(SND_SOC_SOF_HDA_MLINK);
+MODULE_IMPORT_NS(SND_SOC_ACPI_INTEL_MATCH);