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");
25 dev_dbg(dev, "%s no specified codec\n", dai_link->name);
29 /* set card codec info */
30 ret = snd_soc_of_get_dai_link_codecs(dev, codec_node, dai_link);
32 of_node_put(codec_node);
35 return dev_err_probe(dev, ret, "%s: codec dai not found\n",
41 static int set_dailink_daifmt(struct snd_soc_card *card,
42 struct device_node *sub_node,
43 struct snd_soc_dai_link *dai_link)
52 { "cpu", SND_SOC_DAIFMT_CBC_CFC },
53 { "codec", SND_SOC_DAIFMT_CBP_CFP },
56 daifmt = snd_soc_daifmt_parse_format(sub_node, NULL);
58 dai_link->dai_fmt &= SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK;
59 dai_link->dai_fmt |= daifmt;
63 * check "mediatek,clk-provider = xxx"
64 * SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK area
66 ret = of_property_read_string(sub_node, "mediatek,clk-provider", &str);
70 for (i = 0; i < ARRAY_SIZE(of_clk_table); i++) {
71 if (strcmp(str, of_clk_table[i].name) == 0) {
72 dai_link->dai_fmt &= ~SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK;
73 dai_link->dai_fmt |= of_clk_table[i].val;
82 int parse_dai_link_info(struct snd_soc_card *card)
84 struct device *dev = card->dev;
85 struct device_node *sub_node;
86 struct snd_soc_dai_link *dai_link;
87 const char *dai_link_name;
90 /* Loop over all the dai link sub nodes */
91 for_each_available_child_of_node(dev->of_node, sub_node) {
92 if (of_property_read_string(sub_node, "link-name",
94 of_node_put(sub_node);
98 for_each_card_prelinks(card, i, dai_link) {
99 if (!strcmp(dai_link_name, dai_link->name))
103 if (i >= card->num_links) {
104 of_node_put(sub_node);
108 ret = set_card_codec_info(card, sub_node, dai_link);
110 of_node_put(sub_node);
114 ret = set_dailink_daifmt(card, sub_node, dai_link);
116 of_node_put(sub_node);
123 EXPORT_SYMBOL_GPL(parse_dai_link_info);
125 void clean_card_reference(struct snd_soc_card *card)
127 struct snd_soc_dai_link *dai_link;
130 /* release codec reference gotten by set_card_codec_info */
131 for_each_card_prelinks(card, i, dai_link)
132 snd_soc_of_put_dai_link_codecs(dai_link);
134 EXPORT_SYMBOL_GPL(clean_card_reference);