Skip to content

Commit 4e84969

Browse files
committed
ASoC: Intel: sof_sdw: get sdw dmic number
The commit get the sdca sdw dmic number form the mipi-sdca-cluster-channel-id property. The dai link name will be used to select the function topology with a proper dmic channel number. Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
1 parent 21a9822 commit 4e84969

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

sound/soc/intel/boards/sof_sdw.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include <linux/soundwire/sdw_type.h>
1515
#include <linux/soundwire/sdw_intel.h>
1616
#include <sound/core.h>
17+
#include <sound/sdca_function.h>
18+
#include <sound/soc.h>
1719
#include <sound/soc-acpi.h>
1820
#include "sof_sdw_common.h"
1921
#include "../../codecs/rt711.h"
@@ -900,6 +902,23 @@ static const struct snd_soc_ops sdw_ops = {
900902

901903
static const char * const type_strings[] = {"SimpleJack", "SmartAmp", "SmartMic"};
902904

905+
static struct sdw_slave *sof_sdw_get_peripheral_by_codec_name(const char *codec_name)
906+
{
907+
struct snd_soc_component *component;
908+
909+
component = snd_soc_lookup_component_by_name(codec_name);
910+
if (!component)
911+
return NULL;
912+
913+
if (is_sdw_slave(component->dev))
914+
return dev_to_sdw_dev(component->dev);
915+
916+
if (component->dev->parent && is_sdw_slave(component->dev->parent))
917+
return dev_to_sdw_dev(component->dev->parent);
918+
919+
return NULL;
920+
}
921+
903922
static int create_sdw_dailink(struct snd_soc_card *card,
904923
struct asoc_sdw_dailink *sof_dai,
905924
struct snd_soc_dai_link **dai_links,
@@ -1011,6 +1030,37 @@ static int create_sdw_dailink(struct snd_soc_card *card,
10111030

10121031
codecs[j].name = sof_end->codec_name;
10131032
codecs[j].dai_name = sof_end->dai_info->dai_name;
1033+
1034+
if (sof_end->dai_info->dai_type == SOC_SDW_DAI_TYPE_MIC) {
1035+
struct sdw_slave *peripheral;
1036+
int sdw_mic_num;
1037+
int k;
1038+
1039+
peripheral = sof_sdw_get_peripheral_by_codec_name(sof_end->codec_name);
1040+
if (!peripheral) {
1041+
dev_err(dev, "failed to get peripheral for codec %s\n",
1042+
sof_end->codec_name);
1043+
break;
1044+
}
1045+
1046+
for (k = 0; k < peripheral->sdca_data.num_functions; k++) {
1047+
if (peripheral->sdca_data.function[k].type != SDCA_FUNCTION_TYPE_SMART_MIC)
1048+
continue;
1049+
1050+
sdw_mic_num = sdca_get_mic_count(peripheral, &peripheral->sdca_data.function[k]);
1051+
dev_dbg(dev, "%s mic num %d\n", sof_end->codec_name, sdw_mic_num);
1052+
if (sdw_mic_num > 0) {
1053+
char *tmp = name;
1054+
name = devm_kasprintf(dev, GFP_KERNEL, "%s-%dch", name, sdw_mic_num);
1055+
if (!name)
1056+
return -ENOMEM;
1057+
1058+
devm_kfree(dev, tmp);
1059+
}
1060+
}
1061+
1062+
}
1063+
10141064
if (sof_end->dai_info->dai_type == SOC_SDW_DAI_TYPE_MIC &&
10151065
mach_params->dmic_num > 0) {
10161066
dev_warn(dev,
@@ -1582,3 +1632,4 @@ MODULE_AUTHOR("Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>");
15821632
MODULE_LICENSE("GPL v2");
15831633
MODULE_IMPORT_NS("SND_SOC_INTEL_HDA_DSP_COMMON");
15841634
MODULE_IMPORT_NS("SND_SOC_SDW_UTILS");
1635+
MODULE_IMPORT_NS("SND_SOC_SDCA");

0 commit comments

Comments
 (0)