1 // SPDX-License-Identifier: GPL-2.0
3 * mtk-soundcard-driver.c -- MediaTek soundcard driver common
5 * Copyright (c) 2022 MediaTek Inc.
6 * Author: Trevor Wu <trevor.wu@mediatek.com>
9 #include <linux/module.h>
11 #include <sound/soc.h>
13 #include "mtk-soundcard-driver.h"
15 static int set_card_codec_info(struct snd_soc_card *card,
16 struct device_node *sub_node,
17 struct snd_soc_dai_link *dai_link)
19 struct device *dev = card->dev;
20 struct device_node *codec_node;
23 codec_node = of_get_child_by_name(sub_node, "codec");
27 /* set card codec info */
28 ret = snd_soc_of_get_dai_link_codecs(dev, codec_node, dai_link);
30 of_node_put(codec_node);
33 return dev_err_probe(dev, ret, "%s: codec dai not found\n",
39 int parse_dai_link_info(struct snd_soc_card *card)
41 struct device *dev = card->dev;
42 struct device_node *sub_node;
43 struct snd_soc_dai_link *dai_link;
44 const char *dai_link_name;
47 /* Loop over all the dai link sub nodes */
48 for_each_available_child_of_node(dev->of_node, sub_node) {
49 if (of_property_read_string(sub_node, "link-name",
53 for_each_card_prelinks(card, i, dai_link) {
54 if (!strcmp(dai_link_name, dai_link->name))
58 if (i >= card->num_links)
61 ret = set_card_codec_info(card, sub_node, dai_link);
68 EXPORT_SYMBOL_GPL(parse_dai_link_info);
70 void clean_card_reference(struct snd_soc_card *card)
72 struct snd_soc_dai_link *dai_link;
75 /* release codec reference gotten by set_card_codec_info */
76 for_each_card_prelinks(card, i, dai_link)
77 snd_soc_of_put_dai_link_codecs(dai_link);
79 EXPORT_SYMBOL_GPL(clean_card_reference);