Commit d3fc5c4d authored by Bard Liao's avatar Bard Liao Committed by Mark Brown

ASoC: Intel: sof_sdw: add multi dailink support for a codec

A codec may support multiple dais for different purpose. For example,
the rt712 codec supports jack and amp on different dais and machine
driver needs to create different dailink for those dais.
Reviewed-by: default avatarRanjani Sridharan <ranjani.sridharan@linux.intel.com>
Signed-off-by: default avatarBard Liao <yung-chuan.liao@linux.intel.com>
Signed-off-by: default avatarPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Link: https://lore.kernel.org/r/20230602202225.249209-7-pierre-louis.bossart@linux.intel.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 5714aabd
...@@ -843,6 +843,7 @@ static int get_sdw_dailink_info(struct device *dev, const struct snd_soc_acpi_li ...@@ -843,6 +843,7 @@ static int get_sdw_dailink_info(struct device *dev, const struct snd_soc_acpi_li
bool group_visited[SDW_MAX_GROUPS]; bool group_visited[SDW_MAX_GROUPS];
bool no_aggregation; bool no_aggregation;
int i; int i;
int j;
no_aggregation = sof_sdw_quirk & SOF_SDW_NO_AGGREGATION; no_aggregation = sof_sdw_quirk & SOF_SDW_NO_AGGREGATION;
*sdw_cpu_dai_num = 0; *sdw_cpu_dai_num = 0;
...@@ -870,17 +871,19 @@ static int get_sdw_dailink_info(struct device *dev, const struct snd_soc_acpi_li ...@@ -870,17 +871,19 @@ static int get_sdw_dailink_info(struct device *dev, const struct snd_soc_acpi_li
endpoint = link->adr_d[i].endpoints; endpoint = link->adr_d[i].endpoints;
/* count DAI number for playback and capture */ for (j = 0; j < codec_info->dai_num; j++) {
for_each_pcm_streams(stream) { /* count DAI number for playback and capture */
if (!codec_info->dais[0].direction[stream]) for_each_pcm_streams(stream) {
continue; if (!codec_info->dais[j].direction[stream])
continue;
(*sdw_cpu_dai_num)++; (*sdw_cpu_dai_num)++;
/* count BE for each non-aggregated slave or group */ /* count BE for each non-aggregated slave or group */
if (!endpoint->aggregated || no_aggregation || if (!endpoint->aggregated || no_aggregation ||
!group_visited[endpoint->group_id]) !group_visited[endpoint->group_id])
(*sdw_be_num)++; (*sdw_be_num)++;
}
} }
if (endpoint->aggregated) if (endpoint->aggregated)
...@@ -956,7 +959,8 @@ static int create_codec_dai_name(struct device *dev, ...@@ -956,7 +959,8 @@ static int create_codec_dai_name(struct device *dev,
struct snd_soc_codec_conf *codec_conf, struct snd_soc_codec_conf *codec_conf,
int codec_count, int codec_count,
int *codec_conf_index, int *codec_conf_index,
int adr_index) int adr_index,
int dai_index)
{ {
int _codec_index = -1; int _codec_index = -1;
int i; int i;
...@@ -1012,7 +1016,7 @@ static int create_codec_dai_name(struct device *dev, ...@@ -1012,7 +1016,7 @@ static int create_codec_dai_name(struct device *dev,
_codec_index = codec_index; _codec_index = codec_index;
codec[comp_index].dai_name = codec[comp_index].dai_name =
codec_info_list[codec_index].dais[0].dai_name; codec_info_list[codec_index].dais[dai_index].dai_name;
codec_conf[*codec_conf_index].dlc = codec[comp_index]; codec_conf[*codec_conf_index].dlc = codec[comp_index];
codec_conf[*codec_conf_index].name_prefix = link->adr_d[i].name_prefix; codec_conf[*codec_conf_index].name_prefix = link->adr_d[i].name_prefix;
...@@ -1026,7 +1030,7 @@ static int create_codec_dai_name(struct device *dev, ...@@ -1026,7 +1030,7 @@ static int create_codec_dai_name(struct device *dev,
static int set_codec_init_func(struct snd_soc_card *card, static int set_codec_init_func(struct snd_soc_card *card,
const struct snd_soc_acpi_link_adr *link, const struct snd_soc_acpi_link_adr *link,
struct snd_soc_dai_link *dai_links, struct snd_soc_dai_link *dai_links,
bool playback, int group_id, int adr_index) bool playback, int group_id, int adr_index, int dai_index)
{ {
int i = adr_index; int i = adr_index;
...@@ -1046,11 +1050,13 @@ static int set_codec_init_func(struct snd_soc_card *card, ...@@ -1046,11 +1050,13 @@ static int set_codec_init_func(struct snd_soc_card *card,
if (codec_index < 0) if (codec_index < 0)
return codec_index; return codec_index;
/* The group_id is > 0 iff the codec is aggregated */ /* The group_id is > 0 iff the codec is aggregated */
if (link->adr_d[i].endpoints->group_id != group_id) if (link->adr_d[i].endpoints->group_id != group_id)
continue; continue;
if (codec_info_list[codec_index].dais[0].init)
codec_info_list[codec_index].dais[0].init(card, if (codec_info_list[codec_index].dais[dai_index].init)
codec_info_list[codec_index].dais[dai_index].init(card,
link, link,
dai_links, dai_links,
&codec_info_list[codec_index], &codec_info_list[codec_index],
...@@ -1166,7 +1172,8 @@ static int create_sdw_dailink(struct snd_soc_card *card, ...@@ -1166,7 +1172,8 @@ static int create_sdw_dailink(struct snd_soc_card *card,
int *codec_conf_index, int *codec_conf_index,
bool *ignore_pch_dmic, bool *ignore_pch_dmic,
bool append_dai_type, bool append_dai_type,
int adr_index) int adr_index,
int dai_index)
{ {
const struct snd_soc_acpi_link_adr *link_next; const struct snd_soc_acpi_link_adr *link_next;
struct snd_soc_dai_link_component *codecs; struct snd_soc_dai_link_component *codecs;
...@@ -1206,7 +1213,8 @@ static int create_sdw_dailink(struct snd_soc_card *card, ...@@ -1206,7 +1213,8 @@ static int create_sdw_dailink(struct snd_soc_card *card,
continue; continue;
ret = create_codec_dai_name(dev, link_next, codecs, codec_idx, ret = create_codec_dai_name(dev, link_next, codecs, codec_idx,
codec_conf, codec_count, codec_conf_index, adr_index); codec_conf, codec_count, codec_conf_index,
adr_index, dai_index);
if (ret < 0) if (ret < 0)
return ret; return ret;
...@@ -1235,10 +1243,10 @@ static int create_sdw_dailink(struct snd_soc_card *card, ...@@ -1235,10 +1243,10 @@ static int create_sdw_dailink(struct snd_soc_card *card,
"SDW%d-Capture-%s", "SDW%d-Capture-%s",
}; };
if (!codec_info->dais[0].direction[stream]) if (!codec_info->dais[dai_index].direction[stream])
continue; continue;
*link_id = codec_info->dais[0].dailink[stream]; *link_id = codec_info->dais[dai_index].dailink[stream];
if (*link_id < 0) { if (*link_id < 0) {
dev_err(dev, "Invalid dailink id %d\n", *link_id); dev_err(dev, "Invalid dailink id %d\n", *link_id);
return -EINVAL; return -EINVAL;
...@@ -1248,7 +1256,7 @@ static int create_sdw_dailink(struct snd_soc_card *card, ...@@ -1248,7 +1256,7 @@ static int create_sdw_dailink(struct snd_soc_card *card,
if (append_dai_type) { if (append_dai_type) {
name = devm_kasprintf(dev, GFP_KERNEL, name = devm_kasprintf(dev, GFP_KERNEL,
sdw_stream_name[stream + 2], cpu_dai_id[0], sdw_stream_name[stream + 2], cpu_dai_id[0],
type_strings[codec_info->dais[0].dai_type]); type_strings[codec_info->dais[dai_index].dai_type]);
} else { } else {
name = devm_kasprintf(dev, GFP_KERNEL, name = devm_kasprintf(dev, GFP_KERNEL,
sdw_stream_name[stream], cpu_dai_id[0]); sdw_stream_name[stream], cpu_dai_id[0]);
...@@ -1305,7 +1313,7 @@ static int create_sdw_dailink(struct snd_soc_card *card, ...@@ -1305,7 +1313,7 @@ static int create_sdw_dailink(struct snd_soc_card *card,
dai_links[*link_index].nonatomic = true; dai_links[*link_index].nonatomic = true;
ret = set_codec_init_func(card, link, dai_links + (*link_index)++, ret = set_codec_init_func(card, link, dai_links + (*link_index)++,
playback, group_id, adr_index); playback, group_id, adr_index, dai_index);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "failed to init codec %d", codec_index); dev_err(dev, "failed to init codec %d", codec_index);
return ret; return ret;
...@@ -1328,6 +1336,7 @@ static int sof_card_codec_conf_alloc(struct device *dev, ...@@ -1328,6 +1336,7 @@ static int sof_card_codec_conf_alloc(struct device *dev,
const struct snd_soc_acpi_link_adr *adr_link; const struct snd_soc_acpi_link_adr *adr_link;
struct snd_soc_codec_conf *c_conf; struct snd_soc_codec_conf *c_conf;
int num_codecs = 0; int num_codecs = 0;
int codec_index;
int i; int i;
adr_link = mach_params->links; adr_link = mach_params->links;
...@@ -1342,8 +1351,11 @@ static int sof_card_codec_conf_alloc(struct device *dev, ...@@ -1342,8 +1351,11 @@ static int sof_card_codec_conf_alloc(struct device *dev,
adr_link->adr_d[i].adr); adr_link->adr_d[i].adr);
return -EINVAL; return -EINVAL;
} }
codec_index = find_codec_info_part(adr_link->adr_d[i].adr);
if (codec_index < 0)
return codec_index;
num_codecs += codec_info_list[codec_index].dai_num;
} }
num_codecs += adr_link->num_adr;
} }
c_conf = devm_kzalloc(dev, num_codecs * sizeof(*c_conf), GFP_KERNEL); c_conf = devm_kzalloc(dev, num_codecs * sizeof(*c_conf), GFP_KERNEL);
...@@ -1380,6 +1392,7 @@ static int sof_card_dai_links_create(struct device *dev, ...@@ -1380,6 +1392,7 @@ static int sof_card_dai_links_create(struct device *dev,
int total_cpu_dai_num; int total_cpu_dai_num;
int sdw_cpu_dai_num; int sdw_cpu_dai_num;
int i, j, be_id = 0; int i, j, be_id = 0;
int codec_index;
int cpu_id = 0; int cpu_id = 0;
int comp_num; int comp_num;
int ret; int ret;
...@@ -1468,6 +1481,14 @@ static int sof_card_dai_links_create(struct device *dev, ...@@ -1468,6 +1481,14 @@ static int sof_card_dai_links_create(struct device *dev,
* snd_soc_acpi_adr_device array. They won't be described in different adr_links. * snd_soc_acpi_adr_device array. They won't be described in different adr_links.
*/ */
for (i = 0; i < adr_link->num_adr; i++) { for (i = 0; i < adr_link->num_adr; i++) {
/* find codec info to get dai_num */
codec_index = find_codec_info_part(adr_link->adr_d[i].adr);
if (codec_index < 0)
return codec_index;
if (codec_info_list[codec_index].dai_num > 1) {
append_dai_type = true;
goto out;
}
for (j = 0; j < i; j++) { for (j = 0; j < i; j++) {
if ((SDW_PART_ID(adr_link->adr_d[i].adr) != if ((SDW_PART_ID(adr_link->adr_d[i].adr) !=
SDW_PART_ID(adr_link->adr_d[j].adr)) || SDW_PART_ID(adr_link->adr_d[j].adr)) ||
...@@ -1498,15 +1519,22 @@ static int sof_card_dai_links_create(struct device *dev, ...@@ -1498,15 +1519,22 @@ static int sof_card_dai_links_create(struct device *dev,
group_generated[endpoint->group_id]) group_generated[endpoint->group_id])
continue; continue;
ret = create_sdw_dailink(card, dev, &link_index, links, sdw_be_num, /* find codec info to get dai_num */
sdw_cpu_dai_num, cpus, adr_link, codec_index = find_codec_info_part(adr_link->adr_d[i].adr);
&cpu_id, group_generated, if (codec_index < 0)
codec_conf, codec_conf_count, return codec_index;
&be_id, &codec_conf_index,
&ignore_pch_dmic, append_dai_type, i); for (j = 0; j < codec_info_list[codec_index].dai_num ; j++) {
if (ret < 0) { ret = create_sdw_dailink(card, dev, &link_index, links, sdw_be_num,
dev_err(dev, "failed to create dai link %d", link_index); sdw_cpu_dai_num, cpus, adr_link,
return ret; &cpu_id, group_generated,
codec_conf, codec_conf_count,
&be_id, &codec_conf_index,
&ignore_pch_dmic, append_dai_type, i, j);
if (ret < 0) {
dev_err(dev, "failed to create dai link %d", link_index);
return ret;
}
} }
} }
} }
...@@ -1545,6 +1573,7 @@ static int sof_card_dai_links_create(struct device *dev, ...@@ -1545,6 +1573,7 @@ static int sof_card_dai_links_create(struct device *dev,
return -ENOMEM; return -ENOMEM;
ssp_components->name = codec_name; ssp_components->name = codec_name;
/* TODO: support multi codec dai on SSP when it is needed */
ssp_components->dai_name = info->dais[0].dai_name; ssp_components->dai_name = info->dais[0].dai_name;
cpus[cpu_id].dai_name = cpu_name; cpus[cpu_id].dai_name = cpu_name;
...@@ -1686,6 +1715,24 @@ static struct snd_soc_card card_sof_sdw = { ...@@ -1686,6 +1715,24 @@ static struct snd_soc_card card_sof_sdw = {
.late_probe = sof_sdw_card_late_probe, .late_probe = sof_sdw_card_late_probe,
}; };
/* helper to get the link that the codec DAI is used */
static struct snd_soc_dai_link *mc_find_codec_dai_used(struct snd_soc_card *card,
const char *dai_name)
{
struct snd_soc_dai_link *link;
int i;
int j;
for_each_card_prelinks(card, i, link) {
for (j = 0; j < link->num_codecs; j++) {
/* Check each codec in a link */
if (!strcmp(link->codecs[j].dai_name, dai_name))
return link;
}
}
return NULL;
}
static void mc_dailink_exit_loop(struct snd_soc_card *card) static void mc_dailink_exit_loop(struct snd_soc_card *card)
{ {
struct snd_soc_dai_link *link; struct snd_soc_dai_link *link;
...@@ -1693,16 +1740,18 @@ static void mc_dailink_exit_loop(struct snd_soc_card *card) ...@@ -1693,16 +1740,18 @@ static void mc_dailink_exit_loop(struct snd_soc_card *card)
int i, j; int i, j;
for (i = 0; i < ARRAY_SIZE(codec_info_list); i++) { for (i = 0; i < ARRAY_SIZE(codec_info_list); i++) {
if (!codec_info_list[i].dais[0].exit) for (j = 0; j < codec_info_list[i].dai_num; j++) {
continue; /* Check each dai in codec_info_lis to see if it is used in the link */
/* if (!codec_info_list[i].dais[j].exit)
* We don't need to call .exit function if there is no matched continue;
* dai link found. /*
*/ * We don't need to call .exit function if there is no matched
for_each_card_prelinks(card, j, link) { * dai link found.
if (!strcmp(link->codecs[0].dai_name, */
codec_info_list[i].dais[0].dai_name)) { link = mc_find_codec_dai_used(card, codec_info_list[i].dais[j].dai_name);
ret = codec_info_list[i].dais[0].exit(card, link); if (link) {
/* Do the .exit function if the codec dai is used in the link */
ret = codec_info_list[i].dais[j].exit(card, link);
if (ret) if (ret)
dev_warn(card->dev, dev_warn(card->dev,
"codec exit failed %d\n", "codec exit failed %d\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment