module: Convert symbol namespace to string literal
[linux.git] / sound / soc / intel / boards / ehl_rt5660.c
blob5c7b218f22b72fa36493f9b0e09e3c512ba6e123
1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright (c) 2020 Intel Corporation
4 /*
5 * ehl_rt5660 - ASOC Machine driver for Elkhart Lake platforms
6 * with rt5660 codec
7 */
9 #include <linux/acpi.h>
10 #include <sound/core.h>
11 #include <linux/device.h>
12 #include <linux/errno.h>
13 #include <linux/gfp.h>
14 #include <sound/jack.h>
15 #include <linux/kernel.h>
16 #include <linux/list.h>
17 #include <linux/module.h>
18 #include <sound/pcm.h>
19 #include <sound/pcm_params.h>
20 #include <sound/soc.h>
21 #include <sound/soc-acpi.h>
23 #include "hda_dsp_common.h"
24 #include "../../codecs/rt5660.h"
26 #define DUAL_CHANNEL 2
27 #define HDMI_LINK_START 3
28 #define HDMI_LINE_END 6
29 #define NAME_SIZE 32
30 #define IDISP_CODEC_MASK 0x4
32 struct sof_card_private {
33 struct list_head hdmi_pcm_list;
34 bool idisp_codec;
37 static const struct snd_kcontrol_new rt5660_controls[] = {
38 SOC_DAPM_PIN_SWITCH("Speaker"),
39 /* There are two MICBIAS in rt5660, each for one MIC */
40 SOC_DAPM_PIN_SWITCH("Headset Mic"),
41 SOC_DAPM_PIN_SWITCH("Headset Mic2"),
42 SOC_DAPM_PIN_SWITCH("Line Out"),
45 static const struct snd_soc_dapm_widget rt5660_widgets[] = {
46 SND_SOC_DAPM_SPK("Speaker", NULL),
47 SND_SOC_DAPM_MIC("Headset Mic", NULL),
48 SND_SOC_DAPM_MIC("Headset Mic2", NULL),
49 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
50 SND_SOC_DAPM_LINE("Line Out", NULL),
53 static const struct snd_soc_dapm_route rt5660_map[] = {
54 {"Speaker", NULL, "SPO"},
56 {"Headset Mic", NULL, "MICBIAS1"},
57 {"Headset Mic2", NULL, "MICBIAS2"},
59 {"IN1P", NULL, "Headset Mic"},
60 {"IN2P", NULL, "Headset Mic2"},
62 {"Line Out", NULL, "LOUTL"},
63 {"Line Out", NULL, "LOUTR"},
65 {"DMic", NULL, "SoC DMIC"},
68 struct sof_hdmi_pcm {
69 struct list_head head;
70 struct snd_soc_dai *codec_dai;
71 int device;
74 static int hdmi_init(struct snd_soc_pcm_runtime *rtd)
76 struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
77 struct snd_soc_dai *dai = snd_soc_rtd_to_codec(rtd, 0);
78 struct sof_hdmi_pcm *pcm;
80 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
81 if (!pcm)
82 return -ENOMEM;
84 /* dai_link id is 1:1 mapped to the PCM device */
85 pcm->device = rtd->dai_link->id;
86 pcm->codec_dai = dai;
88 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
90 return 0;
93 static int card_late_probe(struct snd_soc_card *card)
95 struct sof_card_private *ctx = snd_soc_card_get_drvdata(card);
96 struct sof_hdmi_pcm *pcm;
98 if (list_empty(&ctx->hdmi_pcm_list))
99 return -ENOENT;
101 if (!ctx->idisp_codec)
102 return 0;
104 pcm = list_first_entry(&ctx->hdmi_pcm_list, struct sof_hdmi_pcm, head);
106 return hda_dsp_hdmi_build_controls(card, pcm->codec_dai->component);
109 static int rt5660_hw_params(struct snd_pcm_substream *substream,
110 struct snd_pcm_hw_params *params)
112 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
113 struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
114 int ret;
116 ret = snd_soc_dai_set_sysclk(codec_dai,
117 RT5660_SCLK_S_PLL1,
118 params_rate(params) * 512,
119 SND_SOC_CLOCK_IN);
120 if (ret < 0) {
121 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
122 return ret;
125 ret = snd_soc_dai_set_pll(codec_dai, 0,
126 RT5660_PLL1_S_BCLK,
127 params_rate(params) * 50,
128 params_rate(params) * 512);
129 if (ret < 0)
130 dev_err(codec_dai->dev, "can't set codec pll: %d\n", ret);
132 return ret;
135 static const struct snd_soc_ops rt5660_ops = {
136 .hw_params = rt5660_hw_params,
139 SND_SOC_DAILINK_DEF(ssp0_pin,
140 DAILINK_COMP_ARRAY(COMP_CPU("SSP0 Pin")));
142 SND_SOC_DAILINK_DEF(rt5660_codec,
143 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5660:00", "rt5660-aif1")));
145 SND_SOC_DAILINK_DEF(platform,
146 DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:1f.3")));
148 SND_SOC_DAILINK_DEF(dmic_pin,
149 DAILINK_COMP_ARRAY(COMP_CPU("DMIC01 Pin")));
150 SND_SOC_DAILINK_DEF(dmic_codec,
151 DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
152 SND_SOC_DAILINK_DEF(dmic16k,
153 DAILINK_COMP_ARRAY(COMP_CPU("DMIC16k Pin")));
155 SND_SOC_DAILINK_DEF(idisp1_pin,
156 DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")));
157 SND_SOC_DAILINK_DEF(idisp1_codec,
158 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi1")));
160 SND_SOC_DAILINK_DEF(idisp2_pin,
161 DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")));
162 SND_SOC_DAILINK_DEF(idisp2_codec,
163 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi2")));
165 SND_SOC_DAILINK_DEF(idisp3_pin,
166 DAILINK_COMP_ARRAY(COMP_CPU("iDisp3 Pin")));
167 SND_SOC_DAILINK_DEF(idisp3_codec,
168 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi3")));
170 SND_SOC_DAILINK_DEF(idisp4_pin,
171 DAILINK_COMP_ARRAY(COMP_CPU("iDisp4 Pin")));
172 SND_SOC_DAILINK_DEF(idisp4_codec,
173 DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi4")));
175 static struct snd_soc_dai_link ehl_rt5660_dailink[] = {
176 /* back ends */
178 .name = "SSP0-Codec",
179 .id = 0,
180 .no_pcm = 1,
181 .ops = &rt5660_ops,
182 SND_SOC_DAILINK_REG(ssp0_pin, rt5660_codec, platform),
185 .name = "dmic48k",
186 .id = 1,
187 .ignore_suspend = 1,
188 .capture_only = 1,
189 .no_pcm = 1,
190 SND_SOC_DAILINK_REG(dmic_pin, dmic_codec, platform),
193 .name = "dmic16k",
194 .id = 2,
195 .ignore_suspend = 1,
196 .capture_only = 1,
197 .no_pcm = 1,
198 SND_SOC_DAILINK_REG(dmic16k, dmic_codec, platform),
201 .name = "iDisp1",
202 .id = 5,
203 .init = hdmi_init,
204 .playback_only = 1,
205 .no_pcm = 1,
206 SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
209 .name = "iDisp2",
210 .id = 6,
211 .init = hdmi_init,
212 .playback_only = 1,
213 .no_pcm = 1,
214 SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
217 .name = "iDisp3",
218 .id = 7,
219 .init = hdmi_init,
220 .playback_only = 1,
221 .no_pcm = 1,
222 SND_SOC_DAILINK_REG(idisp3_pin, idisp3_codec, platform),
225 .name = "iDisp4",
226 .id = 8,
227 .init = hdmi_init,
228 .playback_only = 1,
229 .no_pcm = 1,
230 SND_SOC_DAILINK_REG(idisp4_pin, idisp4_codec, platform),
234 /* SoC card */
235 static struct snd_soc_card snd_soc_card_ehl_rt5660 = {
236 .name = "ehl-rt5660",
237 .owner = THIS_MODULE,
238 .dai_link = ehl_rt5660_dailink,
239 .num_links = ARRAY_SIZE(ehl_rt5660_dailink),
240 .dapm_widgets = rt5660_widgets,
241 .num_dapm_widgets = ARRAY_SIZE(rt5660_widgets),
242 .dapm_routes = rt5660_map,
243 .num_dapm_routes = ARRAY_SIZE(rt5660_map),
244 .controls = rt5660_controls,
245 .num_controls = ARRAY_SIZE(rt5660_controls),
246 .fully_routed = true,
247 .late_probe = card_late_probe,
250 /* If hdmi codec is not supported, switch to use dummy codec */
251 static void hdmi_link_init(struct snd_soc_card *card,
252 struct sof_card_private *ctx,
253 struct snd_soc_acpi_mach *mach)
255 int i;
257 if (mach->mach_params.codec_mask & IDISP_CODEC_MASK) {
258 ctx->idisp_codec = true;
259 return;
263 * if HDMI is not enabled in kernel config, or
264 * hdmi codec is not supported
266 for (i = HDMI_LINK_START; i <= HDMI_LINE_END; i++)
267 card->dai_link[i].codecs[0] = snd_soc_dummy_dlc;
270 static int snd_ehl_rt5660_probe(struct platform_device *pdev)
272 struct snd_soc_acpi_mach *mach;
273 struct snd_soc_card *card = &snd_soc_card_ehl_rt5660;
274 struct sof_card_private *ctx;
275 int ret;
277 card->dev = &pdev->dev;
279 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
280 if (!ctx)
281 return -ENOMEM;
282 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
283 snd_soc_card_set_drvdata(card, ctx);
285 mach = pdev->dev.platform_data;
286 ret = snd_soc_fixup_dai_links_platform_name(card,
287 mach->mach_params.platform);
288 if (ret)
289 return ret;
291 hdmi_link_init(card, ctx, mach);
293 return devm_snd_soc_register_card(&pdev->dev, card);
296 static const struct platform_device_id ehl_board_ids[] = {
297 { .name = "ehl_rt5660" },
300 MODULE_DEVICE_TABLE(platform, ehl_board_ids);
302 static struct platform_driver snd_ehl_rt5660_driver = {
303 .driver = {
304 .name = "ehl_rt5660",
305 .pm = &snd_soc_pm_ops,
307 .probe = snd_ehl_rt5660_probe,
308 .id_table = ehl_board_ids,
311 module_platform_driver(snd_ehl_rt5660_driver);
313 MODULE_DESCRIPTION("ASoC Intel(R) Elkhartlake + rt5660 Machine driver");
314 MODULE_AUTHOR("libin.yang@intel.com");
315 MODULE_LICENSE("GPL v2");
316 MODULE_IMPORT_NS("SND_SOC_INTEL_HDA_DSP_COMMON");