1 // SPDX-License-Identifier: GPL-2.0 2 // 3 // mt6797-mt6351.c -- MT6797 MT6351 ALSA SoC machine driver 4 // 5 // Copyright (c) 2018 MediaTek Inc. 6 // Author: KaiChieh Chuang <kaichieh.chuang@mediatek.com> 7 8 #include <linux/module.h> 9 #include <sound/soc.h> 10 11 #include "mt6797-afe-common.h" 12 13 static struct snd_soc_dai_link mt6797_mt6351_dai_links[] = { 14 /* FE */ 15 { 16 .name = "Playback_1", 17 .stream_name = "Playback_1", 18 .cpu_dai_name = "DL1", 19 .codec_name = "snd-soc-dummy", 20 .codec_dai_name = "snd-soc-dummy-dai", 21 .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 22 SND_SOC_DPCM_TRIGGER_PRE}, 23 .dynamic = 1, 24 .dpcm_playback = 1, 25 }, 26 { 27 .name = "Playback_2", 28 .stream_name = "Playback_2", 29 .cpu_dai_name = "DL2", 30 .codec_name = "snd-soc-dummy", 31 .codec_dai_name = "snd-soc-dummy-dai", 32 .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 33 SND_SOC_DPCM_TRIGGER_PRE}, 34 .dynamic = 1, 35 .dpcm_playback = 1, 36 }, 37 { 38 .name = "Playback_3", 39 .stream_name = "Playback_3", 40 .cpu_dai_name = "DL3", 41 .codec_name = "snd-soc-dummy", 42 .codec_dai_name = "snd-soc-dummy-dai", 43 .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 44 SND_SOC_DPCM_TRIGGER_PRE}, 45 .dynamic = 1, 46 .dpcm_playback = 1, 47 }, 48 { 49 .name = "Capture_1", 50 .stream_name = "Capture_1", 51 .cpu_dai_name = "UL1", 52 .codec_name = "snd-soc-dummy", 53 .codec_dai_name = "snd-soc-dummy-dai", 54 .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 55 SND_SOC_DPCM_TRIGGER_PRE}, 56 .dynamic = 1, 57 .dpcm_capture = 1, 58 }, 59 { 60 .name = "Capture_2", 61 .stream_name = "Capture_2", 62 .cpu_dai_name = "UL2", 63 .codec_name = "snd-soc-dummy", 64 .codec_dai_name = "snd-soc-dummy-dai", 65 .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 66 SND_SOC_DPCM_TRIGGER_PRE}, 67 .dynamic = 1, 68 .dpcm_capture = 1, 69 }, 70 { 71 .name = "Capture_3", 72 .stream_name = "Capture_3", 73 .cpu_dai_name = "UL3", 74 .codec_name = "snd-soc-dummy", 75 .codec_dai_name = "snd-soc-dummy-dai", 76 .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 77 SND_SOC_DPCM_TRIGGER_PRE}, 78 .dynamic = 1, 79 .dpcm_capture = 1, 80 }, 81 { 82 .name = "Capture_Mono_1", 83 .stream_name = "Capture_Mono_1", 84 .cpu_dai_name = "UL_MONO_1", 85 .codec_name = "snd-soc-dummy", 86 .codec_dai_name = "snd-soc-dummy-dai", 87 .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 88 SND_SOC_DPCM_TRIGGER_PRE}, 89 .dynamic = 1, 90 .dpcm_capture = 1, 91 }, 92 { 93 .name = "Hostless_LPBK", 94 .stream_name = "Hostless_LPBK", 95 .cpu_dai_name = "Hostless LPBK DAI", 96 .codec_name = "snd-soc-dummy", 97 .codec_dai_name = "snd-soc-dummy-dai", 98 .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 99 SND_SOC_DPCM_TRIGGER_PRE}, 100 .dynamic = 1, 101 .dpcm_playback = 1, 102 .dpcm_capture = 1, 103 .ignore_suspend = 1, 104 }, 105 { 106 .name = "Hostless_Speech", 107 .stream_name = "Hostless_Speech", 108 .cpu_dai_name = "Hostless Speech DAI", 109 .codec_name = "snd-soc-dummy", 110 .codec_dai_name = "snd-soc-dummy-dai", 111 .trigger = {SND_SOC_DPCM_TRIGGER_PRE, 112 SND_SOC_DPCM_TRIGGER_PRE}, 113 .dynamic = 1, 114 .dpcm_playback = 1, 115 .dpcm_capture = 1, 116 .ignore_suspend = 1, 117 }, 118 /* BE */ 119 { 120 .name = "Primary Codec", 121 .cpu_dai_name = "ADDA", 122 .codec_dai_name = "mt6351-snd-codec-aif1", 123 .no_pcm = 1, 124 .dpcm_playback = 1, 125 .dpcm_capture = 1, 126 .ignore_suspend = 1, 127 }, 128 { 129 .name = "PCM 1", 130 .cpu_dai_name = "PCM 1", 131 .codec_name = "snd-soc-dummy", 132 .codec_dai_name = "snd-soc-dummy-dai", 133 .no_pcm = 1, 134 .dpcm_playback = 1, 135 .dpcm_capture = 1, 136 .ignore_suspend = 1, 137 }, 138 { 139 .name = "PCM 2", 140 .cpu_dai_name = "PCM 2", 141 .codec_name = "snd-soc-dummy", 142 .codec_dai_name = "snd-soc-dummy-dai", 143 .no_pcm = 1, 144 .dpcm_playback = 1, 145 .dpcm_capture = 1, 146 .ignore_suspend = 1, 147 }, 148 }; 149 150 static struct snd_soc_card mt6797_mt6351_card = { 151 .name = "mt6797-mt6351", 152 .owner = THIS_MODULE, 153 .dai_link = mt6797_mt6351_dai_links, 154 .num_links = ARRAY_SIZE(mt6797_mt6351_dai_links), 155 }; 156 157 static int mt6797_mt6351_dev_probe(struct platform_device *pdev) 158 { 159 struct snd_soc_card *card = &mt6797_mt6351_card; 160 struct device_node *platform_node, *codec_node; 161 int ret, i; 162 163 card->dev = &pdev->dev; 164 165 platform_node = of_parse_phandle(pdev->dev.of_node, 166 "mediatek,platform", 0); 167 if (!platform_node) { 168 dev_err(&pdev->dev, "Property 'platform' missing or invalid\n"); 169 return -EINVAL; 170 } 171 for (i = 0; i < card->num_links; i++) { 172 if (mt6797_mt6351_dai_links[i].platform_name) 173 continue; 174 mt6797_mt6351_dai_links[i].platform_of_node = platform_node; 175 } 176 177 codec_node = of_parse_phandle(pdev->dev.of_node, 178 "mediatek,audio-codec", 0); 179 if (!codec_node) { 180 dev_err(&pdev->dev, 181 "Property 'audio-codec' missing or invalid\n"); 182 return -EINVAL; 183 } 184 for (i = 0; i < card->num_links; i++) { 185 if (mt6797_mt6351_dai_links[i].codec_name) 186 continue; 187 mt6797_mt6351_dai_links[i].codec_of_node = codec_node; 188 } 189 190 ret = devm_snd_soc_register_card(&pdev->dev, card); 191 if (ret) 192 dev_err(&pdev->dev, "%s snd_soc_register_card fail %d\n", 193 __func__, ret); 194 195 return ret; 196 } 197 198 #ifdef CONFIG_OF 199 static const struct of_device_id mt6797_mt6351_dt_match[] = { 200 {.compatible = "mediatek,mt6797-mt6351-sound",}, 201 {} 202 }; 203 #endif 204 205 static struct platform_driver mt6797_mt6351_driver = { 206 .driver = { 207 .name = "mt6797-mt6351", 208 .owner = THIS_MODULE, 209 #ifdef CONFIG_OF 210 .of_match_table = mt6797_mt6351_dt_match, 211 #endif 212 }, 213 .probe = mt6797_mt6351_dev_probe, 214 }; 215 216 module_platform_driver(mt6797_mt6351_driver); 217 218 /* Module information */ 219 MODULE_DESCRIPTION("MT6797 MT6351 ALSA SoC machine driver"); 220 MODULE_AUTHOR("KaiChieh Chuang <kaichieh.chuang@mediatek.com>"); 221 MODULE_LICENSE("GPL v2"); 222 MODULE_ALIAS("mt6797 mt6351 soc card"); 223 224