diff mbox series

[04/16] ASoC: Intel: avs: i2s_test: Validate machine board configuration

Message ID 20231011121703.363652-5-amadeuszx.slawinski@linux.intel.com
State Superseded
Headers show
Series Harden SSP boards and add TDM support | expand

Commit Message

Amadeusz Sławiński Oct. 11, 2023, 12:16 p.m. UTC
I2S test board can be used in any SSP and TDM configuration.

Reviewed-by: Cezary Rojewski <cezary.rojewski@intel.com>
Signed-off-by: Amadeusz Sławiński <amadeuszx.slawinski@linux.intel.com>
---
 sound/soc/intel/avs/boards/i2s_test.c | 55 ++++++++++++++++++---------
 1 file changed, 38 insertions(+), 17 deletions(-)

Comments

kernel test robot Oct. 12, 2023, 1:15 a.m. UTC | #1
Hi Amadeusz,

kernel test robot noticed the following build errors:

[auto build test ERROR on broonie-sound/for-next]
[also build test ERROR on next-20231011]
[cannot apply to tiwai-sound/for-next tiwai-sound/for-linus linus/master v6.6-rc5]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Amadeusz-S-awi-ski/ASoC-Intel-avs-Only-create-SSP-d-snd_soc_dai_driver-when-requested/20231011-202503
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
patch link:    https://lore.kernel.org/r/20231011121703.363652-5-amadeuszx.slawinski%40linux.intel.com
patch subject: [PATCH 04/16] ASoC: Intel: avs: i2s_test: Validate machine board configuration
config: x86_64-randconfig-002-20231011 (https://download.01.org/0day-ci/archive/20231012/202310120938.yY6jJXJE-lkp@intel.com/config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231012/202310120938.yY6jJXJE-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202310120938.yY6jJXJE-lkp@intel.com/

All errors (new ones prefixed by >>):

   ld: sound/soc/intel/avs/boards/i2s_test.o: in function `avs_mach_singular_ssp':
>> sound/soc/intel/avs/boards/../utils.h:16: multiple definition of `avs_mach_singular_ssp'; sound/soc/intel/avs/topology.o:sound/soc/intel/avs/utils.h:16: first defined here
   ld: sound/soc/intel/avs/boards/i2s_test.o: in function `avs_mach_ssp_port':
>> sound/soc/intel/avs/boards/../utils.h:21: multiple definition of `avs_mach_ssp_port'; sound/soc/intel/avs/topology.o:sound/soc/intel/avs/utils.h:21: first defined here
   ld: sound/soc/intel/avs/boards/i2s_test.o: in function `avs_mach_singular_tdm':
>> sound/soc/intel/avs/boards/../utils.h:26: multiple definition of `avs_mach_singular_tdm'; sound/soc/intel/avs/topology.o:sound/soc/intel/avs/utils.h:26: first defined here
   ld: sound/soc/intel/avs/boards/i2s_test.o: in function `avs_mach_ssp_tdm':
>> sound/soc/intel/avs/boards/../utils.h:33: multiple definition of `avs_mach_ssp_tdm'; sound/soc/intel/avs/topology.o:sound/soc/intel/avs/utils.h:33: first defined here
   ld: sound/soc/intel/avs/boards/i2s_test.o: in function `avs_mach_get_ssp_tdm':
>> sound/soc/intel/avs/boards/../utils.h:40: multiple definition of `avs_mach_get_ssp_tdm'; sound/soc/intel/avs/topology.o:sound/soc/intel/avs/utils.h:40: first defined here


vim +16 sound/soc/intel/avs/boards/../utils.h

4251ca5fe7340a Amadeusz Sławiński 2023-10-11  13  
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  14  inline bool avs_mach_singular_ssp(struct snd_soc_acpi_mach *mach)
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  15  {
4251ca5fe7340a Amadeusz Sławiński 2023-10-11 @16  	return hweight_long(mach->mach_params.i2s_link_mask) == 1;
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  17  }
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  18  
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  19  inline u32 avs_mach_ssp_port(struct snd_soc_acpi_mach *mach)
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  20  {
4251ca5fe7340a Amadeusz Sławiński 2023-10-11 @21  	return __ffs(mach->mach_params.i2s_link_mask);
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  22  }
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  23  
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  24  inline bool avs_mach_singular_tdm(struct snd_soc_acpi_mach *mach, u32 port)
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  25  {
4251ca5fe7340a Amadeusz Sławiński 2023-10-11 @26  	unsigned long *tdms = mach->pdata;
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  27  
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  28  	return !tdms || (hweight_long(tdms[port]) == 1);
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  29  }
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  30  
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  31  inline u32 avs_mach_ssp_tdm(struct snd_soc_acpi_mach *mach, u32 port)
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  32  {
4251ca5fe7340a Amadeusz Sławiński 2023-10-11 @33  	unsigned long *tdms = mach->pdata;
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  34  
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  35  	return tdms ? __ffs(tdms[port]) : 0;
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  36  }
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  37  
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  38  inline int avs_mach_get_ssp_tdm(struct device *dev, struct snd_soc_acpi_mach *mach,
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  39  				int *ssp_port, int *tdm_slot)
4251ca5fe7340a Amadeusz Sławiński 2023-10-11 @40  {
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  41  	int port;
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  42  
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  43  	if (!avs_mach_singular_ssp(mach)) {
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  44  		dev_err(dev, "Invalid SSP configuration\n");
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  45  		return -EINVAL;
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  46  	}
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  47  	port = avs_mach_ssp_port(mach);
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  48  
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  49  	if (!avs_mach_singular_tdm(mach, port)) {
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  50  		dev_err(dev, "Invalid TDM configuration\n");
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  51  		return -EINVAL;
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  52  	}
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  53  	*ssp_port = port;
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  54  	*tdm_slot = avs_mach_ssp_tdm(mach, *ssp_port);
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  55  
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  56  	return 0;
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  57  }
4251ca5fe7340a Amadeusz Sławiński 2023-10-11  58
diff mbox series

Patch

diff --git a/sound/soc/intel/avs/boards/i2s_test.c b/sound/soc/intel/avs/boards/i2s_test.c
index 1dd0c59a8d91..3d03e1eed3a9 100644
--- a/sound/soc/intel/avs/boards/i2s_test.c
+++ b/sound/soc/intel/avs/boards/i2s_test.c
@@ -12,9 +12,10 @@ 
 #include <sound/soc.h>
 #include <sound/soc-acpi.h>
 #include <sound/soc-dapm.h>
+#include "../utils.h"
 
 static int avs_create_dai_link(struct device *dev, const char *platform_name, int ssp_port,
-			       struct snd_soc_dai_link **dai_link)
+			       int tdm_slot, struct snd_soc_dai_link **dai_link)
 {
 	struct snd_soc_dai_link_component *platform;
 	struct snd_soc_dai_link *dl;
@@ -26,12 +27,14 @@  static int avs_create_dai_link(struct device *dev, const char *platform_name, in
 
 	platform->name = platform_name;
 
-	dl->name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec", ssp_port);
+	dl->name = devm_kasprintf(dev, GFP_KERNEL,
+				  AVS_STRING_FMT("SSP", "-Codec", ssp_port, tdm_slot));
 	dl->cpus = devm_kzalloc(dev, sizeof(*dl->cpus), GFP_KERNEL);
 	if (!dl->name || !dl->cpus)
 		return -ENOMEM;
 
-	dl->cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d Pin", ssp_port);
+	dl->cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
+					    AVS_STRING_FMT("SSP", " Pin", ssp_port, tdm_slot));
 	dl->codecs = &snd_soc_dummy_dlc;
 	if (!dl->cpus->dai_name || !dl->codecs->name || !dl->codecs->dai_name)
 		return -ENOMEM;
@@ -51,7 +54,7 @@  static int avs_create_dai_link(struct device *dev, const char *platform_name, in
 	return 0;
 }
 
-static int avs_create_dapm_routes(struct device *dev, int ssp_port,
+static int avs_create_dapm_routes(struct device *dev, int ssp_port, int tdm_slot,
 				  struct snd_soc_dapm_route **routes, int *num_routes)
 {
 	struct snd_soc_dapm_route *dr;
@@ -61,13 +64,17 @@  static int avs_create_dapm_routes(struct device *dev, int ssp_port,
 	if (!dr)
 		return -ENOMEM;
 
-	dr[0].sink = devm_kasprintf(dev, GFP_KERNEL, "ssp%dpb", ssp_port);
-	dr[0].source = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Tx", ssp_port);
+	dr[0].sink = devm_kasprintf(dev, GFP_KERNEL,
+				    AVS_STRING_FMT("ssp", "pb", ssp_port, tdm_slot));
+	dr[0].source = devm_kasprintf(dev, GFP_KERNEL,
+				      AVS_STRING_FMT("ssp", " Tx", ssp_port, tdm_slot));
 	if (!dr[0].sink || !dr[0].source)
 		return -ENOMEM;
 
-	dr[1].sink = devm_kasprintf(dev, GFP_KERNEL, "ssp%d Rx", ssp_port);
-	dr[1].source = devm_kasprintf(dev, GFP_KERNEL, "ssp%dcp", ssp_port);
+	dr[1].sink = devm_kasprintf(dev, GFP_KERNEL,
+				    AVS_STRING_FMT("ssp", " Rx", ssp_port, tdm_slot));
+	dr[1].source = devm_kasprintf(dev, GFP_KERNEL,
+				      AVS_STRING_FMT("ssp", "cp", ssp_port, tdm_slot));
 	if (!dr[1].sink || !dr[1].source)
 		return -ENOMEM;
 
@@ -77,7 +84,7 @@  static int avs_create_dapm_routes(struct device *dev, int ssp_port,
 	return 0;
 }
 
-static int avs_create_dapm_widgets(struct device *dev, int ssp_port,
+static int avs_create_dapm_widgets(struct device *dev, int ssp_port, int tdm_slot,
 				   struct snd_soc_dapm_widget **widgets, int *num_widgets)
 {
 	struct snd_soc_dapm_widget *dw;
@@ -89,13 +96,15 @@  static int avs_create_dapm_widgets(struct device *dev, int ssp_port,
 
 	dw[0].id = snd_soc_dapm_hp;
 	dw[0].reg = SND_SOC_NOPM;
-	dw[0].name = devm_kasprintf(dev, GFP_KERNEL, "ssp%dpb", ssp_port);
+	dw[0].name = devm_kasprintf(dev, GFP_KERNEL,
+				    AVS_STRING_FMT("ssp", "pb", ssp_port, tdm_slot));
 	if (!dw[0].name)
 		return -ENOMEM;
 
 	dw[1].id = snd_soc_dapm_mic;
 	dw[1].reg = SND_SOC_NOPM;
-	dw[1].name = devm_kasprintf(dev, GFP_KERNEL, "ssp%dcp", ssp_port);
+	dw[1].name = devm_kasprintf(dev, GFP_KERNEL,
+				    AVS_STRING_FMT("ssp", "cp", ssp_port, tdm_slot));
 	if (!dw[1].name)
 		return -ENOMEM;
 
@@ -115,33 +124,45 @@  static int avs_i2s_test_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	const char *pname;
 	int num_routes, num_widgets;
-	int ssp_port, ret;
+	int ssp_port, tdm_slot, ret;
 
 	mach = dev_get_platdata(dev);
 	pname = mach->mach_params.platform;
-	ssp_port = __ffs(mach->mach_params.i2s_link_mask);
+
+	if (!avs_mach_singular_ssp(mach)) {
+		dev_err(dev, "Invalid SSP configuration\n");
+		return -EINVAL;
+	}
+	ssp_port = avs_mach_ssp_port(mach);
+
+	if (!avs_mach_singular_tdm(mach, ssp_port)) {
+		dev_err(dev, "Invalid TDM configuration\n");
+		return -EINVAL;
+	}
+	tdm_slot = avs_mach_ssp_tdm(mach, ssp_port);
 
 	card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
 	if (!card)
 		return -ENOMEM;
 
-	card->name = devm_kasprintf(dev, GFP_KERNEL, "ssp%d-loopback", ssp_port);
+	card->name = devm_kasprintf(dev, GFP_KERNEL,
+				    AVS_STRING_FMT("ssp", "-loopback", ssp_port, tdm_slot));
 	if (!card->name)
 		return -ENOMEM;
 
-	ret = avs_create_dai_link(dev, pname, ssp_port, &dai_link);
+	ret = avs_create_dai_link(dev, pname, ssp_port, tdm_slot, &dai_link);
 	if (ret) {
 		dev_err(dev, "Failed to create dai link: %d\n", ret);
 		return ret;
 	}
 
-	ret = avs_create_dapm_routes(dev, ssp_port, &routes, &num_routes);
+	ret = avs_create_dapm_routes(dev, ssp_port, tdm_slot, &routes, &num_routes);
 	if (ret) {
 		dev_err(dev, "Failed to create dapm routes: %d\n", ret);
 		return ret;
 	}
 
-	ret = avs_create_dapm_widgets(dev, ssp_port, &widgets, &num_widgets);
+	ret = avs_create_dapm_widgets(dev, ssp_port, tdm_slot, &widgets, &num_widgets);
 	if (ret) {
 		dev_err(dev, "Failed to create dapm widgets: %d\n", ret);
 		return ret;