Skip to content

Commit

Permalink
ASoC: intel/sdw_utils: move machine driver dai link helper functions
Browse files Browse the repository at this point in the history
Move machine driver dai link helper functions to common place holder,
So that it can be used by other platform machine driver.
Rename these functions with "asoc_sdw" tag as a prefix.

Link: thesofproject#5068
Signed-off-by: Vijendar Mukunda <[email protected]>
Reviewed-by: Bard Liao <[email protected]>
Reviewed-by: Pierre-Louis Bossart <[email protected]>
Link: https://patch.msgid.link/[email protected]
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
vijendarmukunda authored and broonie committed Aug 1, 2024
1 parent e377c94 commit 778dcb0
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 52 deletions.
5 changes: 5 additions & 0 deletions include/sound/soc_sdw_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ struct asoc_sdw_codec_info *asoc_sdw_find_codec_info_acpi(const u8 *acpi_id);
struct asoc_sdw_codec_info *asoc_sdw_find_codec_info_dai(const char *dai_name,
int *dai_index);

struct snd_soc_dai_link *asoc_sdw_mc_find_codec_dai_used(struct snd_soc_card *card,
const char *dai_name);

void asoc_sdw_mc_dailink_exit_loop(struct snd_soc_card *card);

int asoc_sdw_rtd_init(struct snd_soc_pcm_runtime *rtd);

/* DMIC support */
Expand Down
54 changes: 2 additions & 52 deletions sound/soc/intel/boards/sof_sdw.c
Original file line number Diff line number Diff line change
Expand Up @@ -1238,56 +1238,6 @@ static int sof_sdw_card_late_probe(struct snd_soc_card *card)
return ret;
}

/* 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 *dai_link;
int i;
int j;

for_each_card_prelinks(card, i, dai_link) {
for (j = 0; j < dai_link->num_codecs; j++) {
/* Check each codec in a link */
if (!strcmp(dai_link->codecs[j].dai_name, dai_name))
return dai_link;
}
}
return NULL;
}

static void mc_dailink_exit_loop(struct snd_soc_card *card)
{
struct snd_soc_dai_link *dai_link;
struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card);
int ret;
int i, j;

for (i = 0; i < ctx->codec_info_list_count; i++) {
for (j = 0; j < codec_info_list[i].dai_num; j++) {
codec_info_list[i].dais[j].rtd_init_done = false;
/* Check each dai in codec_info_lis to see if it is used in the link */
if (!codec_info_list[i].dais[j].exit)
continue;
/*
* We don't need to call .exit function if there is no matched
* dai link found.
*/
dai_link = mc_find_codec_dai_used(card,
codec_info_list[i].dais[j].dai_name);
if (dai_link) {
/* Do the .exit function if the codec dai is used in the link */
ret = codec_info_list[i].dais[j].exit(card, dai_link);
if (ret)
dev_warn(card->dev,
"codec exit failed %d\n",
ret);
break;
}
}
}
}

static int mc_probe(struct platform_device *pdev)
{
struct snd_soc_acpi_mach *mach = dev_get_platdata(&pdev->dev);
Expand Down Expand Up @@ -1368,7 +1318,7 @@ static int mc_probe(struct platform_device *pdev)
ret = devm_snd_soc_register_card(card->dev, card);
if (ret) {
dev_err_probe(card->dev, ret, "snd_soc_register_card failed %d\n", ret);
mc_dailink_exit_loop(card);
asoc_sdw_mc_dailink_exit_loop(card);
return ret;
}

Expand All @@ -1381,7 +1331,7 @@ static void mc_remove(struct platform_device *pdev)
{
struct snd_soc_card *card = platform_get_drvdata(pdev);

mc_dailink_exit_loop(card);
asoc_sdw_mc_dailink_exit_loop(card);
}

static const struct platform_device_id mc_id_table[] = {
Expand Down
52 changes: 52 additions & 0 deletions sound/soc/sdw_utils/soc_sdw_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,5 +864,57 @@ const char *asoc_sdw_get_codec_name(struct device *dev,
}
EXPORT_SYMBOL_NS(asoc_sdw_get_codec_name, SND_SOC_SDW_UTILS);

/* helper to get the link that the codec DAI is used */
struct snd_soc_dai_link *asoc_sdw_mc_find_codec_dai_used(struct snd_soc_card *card,
const char *dai_name)
{
struct snd_soc_dai_link *dai_link;
int i;
int j;

for_each_card_prelinks(card, i, dai_link) {
for (j = 0; j < dai_link->num_codecs; j++) {
/* Check each codec in a link */
if (!strcmp(dai_link->codecs[j].dai_name, dai_name))
return dai_link;
}
}
return NULL;
}
EXPORT_SYMBOL_NS(asoc_sdw_mc_find_codec_dai_used, SND_SOC_SDW_UTILS);

void asoc_sdw_mc_dailink_exit_loop(struct snd_soc_card *card)
{
struct snd_soc_dai_link *dai_link;
struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card);
int ret;
int i, j;

for (i = 0; i < ctx->codec_info_list_count; i++) {
for (j = 0; j < codec_info_list[i].dai_num; j++) {
codec_info_list[i].dais[j].rtd_init_done = false;
/* Check each dai in codec_info_lis to see if it is used in the link */
if (!codec_info_list[i].dais[j].exit)
continue;
/*
* We don't need to call .exit function if there is no matched
* dai link found.
*/
dai_link = asoc_sdw_mc_find_codec_dai_used(card,
codec_info_list[i].dais[j].dai_name);
if (dai_link) {
/* Do the .exit function if the codec dai is used in the link */
ret = codec_info_list[i].dais[j].exit(card, dai_link);
if (ret)
dev_warn(card->dev,
"codec exit failed %d\n",
ret);
break;
}
}
}
}
EXPORT_SYMBOL_NS(asoc_sdw_mc_dailink_exit_loop, SND_SOC_SDW_UTILS);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("SoundWire ASoC helpers");

0 comments on commit 778dcb0

Please sign in to comment.