1 // SPDX-License-Identifier: GPL-2.0
2 //
3 // mt8186-mt6366-common.c
4 //	--  MT8186 MT6366 ALSA common driver
5 //
6 // Copyright (c) 2022 MediaTek Inc.
7 // Author: Jiaxin Yu <jiaxin.yu@mediatek.com>
8 //
9 #include <sound/soc.h>
10 
11 #include "../../codecs/mt6358.h"
12 #include "../common/mtk-afe-platform-driver.h"
13 #include "mt8186-afe-common.h"
14 #include "mt8186-mt6366-common.h"
15 
mt8186_mt6366_init(struct snd_soc_pcm_runtime * rtd)16 int mt8186_mt6366_init(struct snd_soc_pcm_runtime *rtd)
17 {
18 	struct snd_soc_component *cmpnt_afe =
19 		snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME);
20 	struct snd_soc_component *cmpnt_codec =
21 		asoc_rtd_to_codec(rtd, 0)->component;
22 	struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt_afe);
23 	struct mt8186_afe_private *afe_priv = afe->platform_priv;
24 	struct snd_soc_dapm_context *dapm = &rtd->card->dapm;
25 	int ret;
26 
27 	/* set mtkaif protocol */
28 	mt6358_set_mtkaif_protocol(cmpnt_codec,
29 				   MT6358_MTKAIF_PROTOCOL_1);
30 	afe_priv->mtkaif_protocol = MT6358_MTKAIF_PROTOCOL_1;
31 
32 	ret = snd_soc_dapm_sync(dapm);
33 	if (ret) {
34 		dev_err(rtd->dev, "failed to snd_soc_dapm_sync\n");
35 		return ret;
36 	}
37 
38 	return 0;
39 }
40 EXPORT_SYMBOL_GPL(mt8186_mt6366_init);
41 
mt8186_mt6366_card_set_be_link(struct snd_soc_card * card,struct snd_soc_dai_link * link,struct device_node * node,char * link_name)42 int mt8186_mt6366_card_set_be_link(struct snd_soc_card *card,
43 				   struct snd_soc_dai_link *link,
44 				   struct device_node *node,
45 				   char *link_name)
46 {
47 	int ret;
48 
49 	if (node && strcmp(link->name, link_name) == 0) {
50 		ret = snd_soc_of_get_dai_link_codecs(card->dev, node, link);
51 		if (ret < 0)
52 			return dev_err_probe(card->dev, ret, "get dai link codecs fail\n");
53 	}
54 
55 	return 0;
56 }
57 EXPORT_SYMBOL_GPL(mt8186_mt6366_card_set_be_link);
58