1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
2 //
3 // This file is provided under a dual BSD/GPLv2 license. When using or
4 // redistributing this file, you may do so under either license.
5 //
6 // Copyright(c) 2021 Advanced Micro Devices, Inc.
7 //
8 // Authors: Ajit Kumar Pandey <AjitKumar.Pandey@amd.com>
9 //	    Vijendar Mukunda <Vijendar.Mukunda@amd.com>
10 //
11 
12 /*
13  * Machine Driver Interface for ACP HW block
14  */
15 
16 #include <sound/core.h>
17 #include <sound/jack.h>
18 #include <sound/pcm_params.h>
19 #include <sound/soc-dapm.h>
20 #include <sound/soc.h>
21 #include <linux/input.h>
22 #include <linux/module.h>
23 
24 #include "../../codecs/rt5682.h"
25 #include "../../codecs/rt1019.h"
26 #include "../../codecs/rt5682s.h"
27 #include "../../codecs/nau8825.h"
28 #include "../../codecs/nau8821.h"
29 #include "acp-mach.h"
30 
31 #define PCO_PLAT_CLK 48000000
32 #define RT5682_PLL_FREQ (48000 * 512)
33 #define DUAL_CHANNEL	2
34 #define FOUR_CHANNEL	4
35 #define NAU8821_CODEC_DAI	"nau8821-hifi"
36 #define NAU8821_BCLK		1536000
37 #define NAU8821_FREQ_OUT	12288000
38 #define MAX98388_CODEC_DAI	"max98388-aif1"
39 
40 #define TDM_MODE_ENABLE 1
41 
42 const struct dmi_system_id acp_quirk_table[] = {
43 	{
44 		/* Google skyrim proto-0 */
45 		.matches = {
46 			DMI_EXACT_MATCH(DMI_PRODUCT_FAMILY, "Google_Skyrim"),
47 		},
48 		.driver_data = (void *)TDM_MODE_ENABLE,
49 	},
50 	{}
51 };
52 EXPORT_SYMBOL_GPL(acp_quirk_table);
53 
54 static const unsigned int channels[] = {
55 	DUAL_CHANNEL,
56 };
57 
58 static const unsigned int rates[] = {
59 	48000,
60 };
61 
62 static const struct snd_pcm_hw_constraint_list constraints_rates = {
63 	.count = ARRAY_SIZE(rates),
64 	.list  = rates,
65 	.mask = 0,
66 };
67 
68 static const struct snd_pcm_hw_constraint_list constraints_channels = {
69 	.count = ARRAY_SIZE(channels),
70 	.list = channels,
71 	.mask = 0,
72 };
73 
74 static int acp_clk_enable(struct acp_card_drvdata *drvdata,
75 			  unsigned int srate, unsigned int bclk_ratio)
76 {
77 	clk_set_rate(drvdata->wclk, srate);
78 	clk_set_rate(drvdata->bclk, srate * bclk_ratio);
79 
80 	return clk_prepare_enable(drvdata->wclk);
81 }
82 
83 /* Declare RT5682 codec components */
84 SND_SOC_DAILINK_DEF(rt5682,
85 	DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5682:00", "rt5682-aif1")));
86 
87 static struct snd_soc_jack rt5682_jack;
88 static struct snd_soc_jack_pin rt5682_jack_pins[] = {
89 	{
90 		.pin = "Headphone Jack",
91 		.mask = SND_JACK_HEADPHONE,
92 	},
93 	{
94 		.pin = "Headset Mic",
95 		.mask = SND_JACK_MICROPHONE,
96 	},
97 };
98 
99 static const struct snd_kcontrol_new rt5682_controls[] = {
100 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
101 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
102 };
103 
104 static const struct snd_soc_dapm_widget rt5682_widgets[] = {
105 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
106 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
107 };
108 
109 static const struct snd_soc_dapm_route rt5682_map[] = {
110 	{ "Headphone Jack", NULL, "HPOL" },
111 	{ "Headphone Jack", NULL, "HPOR" },
112 	{ "IN1P", NULL, "Headset Mic" },
113 };
114 
115 /* Define card ops for RT5682 CODEC */
116 static int acp_card_rt5682_init(struct snd_soc_pcm_runtime *rtd)
117 {
118 	struct snd_soc_card *card = rtd->card;
119 	struct acp_card_drvdata *drvdata = card->drvdata;
120 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
121 	struct snd_soc_component *component = codec_dai->component;
122 	int ret;
123 
124 	dev_info(rtd->dev, "codec dai name = %s\n", codec_dai->name);
125 
126 	if (drvdata->hs_codec_id != RT5682)
127 		return -EINVAL;
128 
129 	drvdata->wclk = clk_get(component->dev, "rt5682-dai-wclk");
130 	drvdata->bclk = clk_get(component->dev, "rt5682-dai-bclk");
131 
132 	ret = snd_soc_dapm_new_controls(&card->dapm, rt5682_widgets,
133 					ARRAY_SIZE(rt5682_widgets));
134 	if (ret) {
135 		dev_err(rtd->dev, "unable to add widget dapm controls, ret %d\n", ret);
136 		return ret;
137 	}
138 
139 	ret = snd_soc_add_card_controls(card, rt5682_controls,
140 					ARRAY_SIZE(rt5682_controls));
141 	if (ret) {
142 		dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
143 		return ret;
144 	}
145 
146 	ret = snd_soc_card_jack_new_pins(card, "Headset Jack",
147 					 SND_JACK_HEADSET | SND_JACK_LINEOUT |
148 					 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
149 					 SND_JACK_BTN_2 | SND_JACK_BTN_3,
150 					 &rt5682_jack,
151 					 rt5682_jack_pins,
152 					 ARRAY_SIZE(rt5682_jack_pins));
153 	if (ret) {
154 		dev_err(card->dev, "HP jack creation failed %d\n", ret);
155 		return ret;
156 	}
157 
158 	snd_jack_set_key(rt5682_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
159 	snd_jack_set_key(rt5682_jack.jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
160 	snd_jack_set_key(rt5682_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
161 	snd_jack_set_key(rt5682_jack.jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
162 
163 	ret = snd_soc_component_set_jack(component, &rt5682_jack, NULL);
164 	if (ret) {
165 		dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
166 		return ret;
167 	}
168 
169 	return snd_soc_dapm_add_routes(&rtd->card->dapm, rt5682_map, ARRAY_SIZE(rt5682_map));
170 }
171 
172 static int acp_card_hs_startup(struct snd_pcm_substream *substream)
173 {
174 	struct snd_pcm_runtime *runtime = substream->runtime;
175 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
176 	struct snd_soc_card *card = rtd->card;
177 	struct acp_card_drvdata *drvdata = card->drvdata;
178 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
179 	int ret;
180 	unsigned int fmt;
181 
182 	if (drvdata->tdm_mode)
183 		fmt = SND_SOC_DAIFMT_DSP_A;
184 	else
185 		fmt = SND_SOC_DAIFMT_I2S;
186 
187 	if (drvdata->soc_mclk)
188 		fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBC_CFC;
189 	else
190 		fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBP_CFP;
191 
192 	ret =  snd_soc_dai_set_fmt(codec_dai, fmt);
193 	if (ret < 0) {
194 		dev_err(rtd->card->dev, "Failed to set dai fmt: %d\n", ret);
195 		return ret;
196 	}
197 
198 	runtime->hw.channels_max = DUAL_CHANNEL;
199 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
200 				      &constraints_channels);
201 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
202 				      &constraints_rates);
203 
204 	return ret;
205 }
206 
207 static void acp_card_shutdown(struct snd_pcm_substream *substream)
208 {
209 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
210 	struct snd_soc_card *card = rtd->card;
211 	struct acp_card_drvdata *drvdata = card->drvdata;
212 
213 	if (!drvdata->soc_mclk)
214 		clk_disable_unprepare(drvdata->wclk);
215 }
216 
217 static int acp_card_rt5682_hw_params(struct snd_pcm_substream *substream,
218 				      struct snd_pcm_hw_params *params)
219 {
220 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
221 	struct snd_soc_card *card = rtd->card;
222 	struct acp_card_drvdata *drvdata = card->drvdata;
223 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
224 	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
225 	int ret;
226 	unsigned int fmt, srate, ch, format;
227 
228 	srate = params_rate(params);
229 	ch = params_channels(params);
230 	format = params_physical_width(params);
231 
232 	if (drvdata->tdm_mode)
233 		fmt = SND_SOC_DAIFMT_DSP_A;
234 	else
235 		fmt = SND_SOC_DAIFMT_I2S;
236 
237 	if (drvdata->soc_mclk)
238 		fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBC_CFC;
239 	else
240 		fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBP_CFP;
241 
242 	ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
243 	if (ret && ret != -ENOTSUPP) {
244 		dev_err(rtd->dev, "Failed to set dai fmt: %d\n", ret);
245 		return ret;
246 	}
247 
248 	ret =  snd_soc_dai_set_fmt(codec_dai, fmt);
249 	if (ret < 0) {
250 		dev_err(rtd->card->dev, "Failed to set dai fmt: %d\n", ret);
251 		return ret;
252 	}
253 
254 	if (drvdata->tdm_mode) {
255 		/**
256 		 * As codec supports slot 0 and slot 1 for playback and capture.
257 		 */
258 		ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0x3, 0x3, 8, 16);
259 		if (ret && ret != -ENOTSUPP) {
260 			dev_err(rtd->dev, "set TDM slot err: %d\n", ret);
261 			return ret;
262 		}
263 
264 		ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x3, 0x3, 8, 16);
265 		if (ret < 0) {
266 			dev_warn(rtd->dev, "set TDM slot err:%d\n", ret);
267 			return ret;
268 		}
269 	}
270 
271 	ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL2, RT5682_PLL2_S_MCLK,
272 				  PCO_PLAT_CLK, RT5682_PLL_FREQ);
273 	if (ret < 0) {
274 		dev_err(rtd->dev, "Failed to set codec PLL: %d\n", ret);
275 		return ret;
276 	}
277 
278 	ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL2,
279 				     RT5682_PLL_FREQ, SND_SOC_CLOCK_IN);
280 	if (ret < 0) {
281 		dev_err(rtd->dev, "Failed to set codec SYSCLK: %d\n", ret);
282 		return ret;
283 	}
284 
285 	/* Set tdm/i2s1 master bclk ratio */
286 	ret = snd_soc_dai_set_bclk_ratio(codec_dai, ch * format);
287 	if (ret < 0) {
288 		dev_err(rtd->dev, "Failed to set rt5682 tdm bclk ratio: %d\n", ret);
289 		return ret;
290 	}
291 
292 	if (!drvdata->soc_mclk) {
293 		ret = acp_clk_enable(drvdata, srate, ch * format);
294 		if (ret < 0) {
295 			dev_err(rtd->card->dev, "Failed to enable HS clk: %d\n", ret);
296 			return ret;
297 		}
298 	}
299 
300 	return 0;
301 }
302 
303 static const struct snd_soc_ops acp_card_rt5682_ops = {
304 	.startup = acp_card_hs_startup,
305 	.shutdown = acp_card_shutdown,
306 	.hw_params = acp_card_rt5682_hw_params,
307 };
308 
309 /* Define RT5682S CODEC component*/
310 SND_SOC_DAILINK_DEF(rt5682s,
311 		    DAILINK_COMP_ARRAY(COMP_CODEC("i2c-RTL5682:00", "rt5682s-aif1")));
312 
313 static struct snd_soc_jack rt5682s_jack;
314 static struct snd_soc_jack_pin rt5682s_jack_pins[] = {
315 	{
316 		.pin = "Headphone Jack",
317 		.mask = SND_JACK_HEADPHONE,
318 	},
319 	{
320 		.pin = "Headset Mic",
321 		.mask = SND_JACK_MICROPHONE,
322 	},
323 };
324 
325 static const struct snd_kcontrol_new rt5682s_controls[] = {
326 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
327 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
328 };
329 
330 static const struct snd_soc_dapm_widget rt5682s_widgets[] = {
331 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
332 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
333 };
334 
335 static const struct snd_soc_dapm_route rt5682s_map[] = {
336 	{ "Headphone Jack", NULL, "HPOL" },
337 	{ "Headphone Jack", NULL, "HPOR" },
338 	{ "IN1P", NULL, "Headset Mic" },
339 };
340 
341 static int acp_card_rt5682s_init(struct snd_soc_pcm_runtime *rtd)
342 {
343 	struct snd_soc_card *card = rtd->card;
344 	struct acp_card_drvdata *drvdata = card->drvdata;
345 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
346 	struct snd_soc_component *component = codec_dai->component;
347 	int ret;
348 
349 	dev_info(rtd->dev, "codec dai name = %s\n", codec_dai->name);
350 
351 	if (drvdata->hs_codec_id != RT5682S)
352 		return -EINVAL;
353 
354 	if (!drvdata->soc_mclk) {
355 		drvdata->wclk = clk_get(component->dev, "rt5682-dai-wclk");
356 		drvdata->bclk = clk_get(component->dev, "rt5682-dai-bclk");
357 	}
358 
359 	ret = snd_soc_dapm_new_controls(&card->dapm, rt5682s_widgets,
360 					ARRAY_SIZE(rt5682s_widgets));
361 	if (ret) {
362 		dev_err(rtd->dev, "unable to add widget dapm controls, ret %d\n", ret);
363 		return ret;
364 	}
365 
366 	ret = snd_soc_add_card_controls(card, rt5682s_controls,
367 					ARRAY_SIZE(rt5682s_controls));
368 	if (ret) {
369 		dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
370 		return ret;
371 	}
372 
373 	ret = snd_soc_card_jack_new_pins(card, "Headset Jack",
374 					 SND_JACK_HEADSET | SND_JACK_LINEOUT |
375 					 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
376 					 SND_JACK_BTN_2 | SND_JACK_BTN_3,
377 					 &rt5682s_jack,
378 					 rt5682s_jack_pins,
379 					 ARRAY_SIZE(rt5682s_jack_pins));
380 	if (ret) {
381 		dev_err(card->dev, "HP jack creation failed %d\n", ret);
382 		return ret;
383 	}
384 
385 	snd_jack_set_key(rt5682s_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
386 	snd_jack_set_key(rt5682s_jack.jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
387 	snd_jack_set_key(rt5682s_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
388 	snd_jack_set_key(rt5682s_jack.jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
389 
390 	ret = snd_soc_component_set_jack(component, &rt5682s_jack, NULL);
391 	if (ret) {
392 		dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
393 		return ret;
394 	}
395 
396 	return snd_soc_dapm_add_routes(&rtd->card->dapm, rt5682s_map, ARRAY_SIZE(rt5682s_map));
397 }
398 
399 static int acp_card_rt5682s_hw_params(struct snd_pcm_substream *substream,
400 				      struct snd_pcm_hw_params *params)
401 {
402 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
403 	struct snd_soc_card *card = rtd->card;
404 	struct acp_card_drvdata *drvdata = card->drvdata;
405 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
406 	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
407 	int ret;
408 	unsigned int fmt, srate, ch, format;
409 
410 	srate = params_rate(params);
411 	ch = params_channels(params);
412 	format = params_physical_width(params);
413 
414 	if (drvdata->tdm_mode)
415 		fmt = SND_SOC_DAIFMT_DSP_A;
416 	else
417 		fmt = SND_SOC_DAIFMT_I2S;
418 
419 	if (drvdata->soc_mclk)
420 		fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBC_CFC;
421 	else
422 		fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBP_CFP;
423 
424 	ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
425 	if (ret && ret != -ENOTSUPP) {
426 		dev_err(rtd->dev, "Failed to set dai fmt: %d\n", ret);
427 		return ret;
428 	}
429 
430 	ret =  snd_soc_dai_set_fmt(codec_dai, fmt);
431 	if (ret < 0) {
432 		dev_err(rtd->card->dev, "Failed to set dai fmt: %d\n", ret);
433 		return ret;
434 	}
435 
436 	if (drvdata->tdm_mode) {
437 		/**
438 		 * As codec supports slot 0 and slot 1 for playback and capture.
439 		 */
440 		ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0x3, 0x3, 8, 16);
441 		if (ret && ret != -ENOTSUPP) {
442 			dev_err(rtd->dev, "set TDM slot err: %d\n", ret);
443 			return ret;
444 		}
445 
446 		ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x3, 0x3, 8, 16);
447 		if (ret < 0) {
448 			dev_warn(rtd->dev, "set TDM slot err:%d\n", ret);
449 			return ret;
450 		}
451 	}
452 
453 	ret = snd_soc_dai_set_pll(codec_dai, RT5682S_PLL2, RT5682S_PLL_S_MCLK,
454 				  PCO_PLAT_CLK, RT5682_PLL_FREQ);
455 	if (ret < 0) {
456 		dev_err(rtd->dev, "Failed to set codec PLL: %d\n", ret);
457 		return ret;
458 	}
459 
460 	ret = snd_soc_dai_set_sysclk(codec_dai, RT5682S_SCLK_S_PLL2,
461 				     RT5682_PLL_FREQ, SND_SOC_CLOCK_IN);
462 	if (ret < 0) {
463 		dev_err(rtd->dev, "Failed to set codec SYSCLK: %d\n", ret);
464 		return ret;
465 	}
466 
467 	/* Set tdm/i2s1 master bclk ratio */
468 	ret = snd_soc_dai_set_bclk_ratio(codec_dai, ch * format);
469 	if (ret < 0) {
470 		dev_err(rtd->dev, "Failed to set rt5682 tdm bclk ratio: %d\n", ret);
471 		return ret;
472 	}
473 
474 	clk_set_rate(drvdata->wclk, srate);
475 	clk_set_rate(drvdata->bclk, srate * ch * format);
476 
477 	return 0;
478 }
479 
480 static const struct snd_soc_ops acp_card_rt5682s_ops = {
481 	.startup = acp_card_hs_startup,
482 	.hw_params = acp_card_rt5682s_hw_params,
483 };
484 
485 static const unsigned int dmic_channels[] = {
486 	DUAL_CHANNEL, FOUR_CHANNEL,
487 };
488 
489 static const struct snd_pcm_hw_constraint_list dmic_constraints_channels = {
490 	.count = ARRAY_SIZE(dmic_channels),
491 	.list = dmic_channels,
492 	.mask = 0,
493 };
494 
495 static int acp_card_dmic_startup(struct snd_pcm_substream *substream)
496 {
497 	struct snd_pcm_runtime *runtime = substream->runtime;
498 
499 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
500 				   &dmic_constraints_channels);
501 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
502 				   &constraints_rates);
503 
504 	return 0;
505 }
506 
507 static const struct snd_soc_ops acp_card_dmic_ops = {
508 	.startup = acp_card_dmic_startup,
509 };
510 
511 /* Declare RT1019 codec components */
512 SND_SOC_DAILINK_DEF(rt1019,
513 	DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC1019:00", "rt1019-aif"),
514 			  COMP_CODEC("i2c-10EC1019:01", "rt1019-aif")));
515 
516 static const struct snd_kcontrol_new rt1019_controls[] = {
517 	SOC_DAPM_PIN_SWITCH("Left Spk"),
518 	SOC_DAPM_PIN_SWITCH("Right Spk"),
519 };
520 
521 static const struct snd_soc_dapm_widget rt1019_widgets[] = {
522 	SND_SOC_DAPM_SPK("Left Spk", NULL),
523 	SND_SOC_DAPM_SPK("Right Spk", NULL),
524 };
525 
526 static const struct snd_soc_dapm_route rt1019_map_lr[] = {
527 	{ "Left Spk", NULL, "Left SPO" },
528 	{ "Right Spk", NULL, "Right SPO" },
529 };
530 
531 static struct snd_soc_codec_conf rt1019_conf[] = {
532 	{
533 		 .dlc = COMP_CODEC_CONF("i2c-10EC1019:01"),
534 		 .name_prefix = "Left",
535 	},
536 	{
537 		 .dlc = COMP_CODEC_CONF("i2c-10EC1019:00"),
538 		 .name_prefix = "Right",
539 	},
540 };
541 
542 static int acp_card_rt1019_init(struct snd_soc_pcm_runtime *rtd)
543 {
544 	struct snd_soc_card *card = rtd->card;
545 	struct acp_card_drvdata *drvdata = card->drvdata;
546 	int ret;
547 
548 	if (drvdata->amp_codec_id != RT1019)
549 		return -EINVAL;
550 
551 	ret = snd_soc_dapm_new_controls(&card->dapm, rt1019_widgets,
552 					ARRAY_SIZE(rt1019_widgets));
553 	if (ret) {
554 		dev_err(rtd->dev, "unable to add widget dapm controls, ret %d\n", ret);
555 		return ret;
556 	}
557 
558 	ret = snd_soc_add_card_controls(card, rt1019_controls,
559 					ARRAY_SIZE(rt1019_controls));
560 	if (ret) {
561 		dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
562 		return ret;
563 	}
564 
565 	return snd_soc_dapm_add_routes(&rtd->card->dapm, rt1019_map_lr,
566 				       ARRAY_SIZE(rt1019_map_lr));
567 }
568 
569 static int acp_card_rt1019_hw_params(struct snd_pcm_substream *substream,
570 				     struct snd_pcm_hw_params *params)
571 {
572 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
573 	struct snd_soc_card *card = rtd->card;
574 	struct acp_card_drvdata *drvdata = card->drvdata;
575 	struct snd_soc_dai *codec_dai;
576 	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
577 	int i, ret = 0;
578 	unsigned int fmt, srate, ch, format;
579 
580 	srate = params_rate(params);
581 	ch = params_channels(params);
582 	format = params_physical_width(params);
583 
584 	if (drvdata->amp_codec_id != RT1019)
585 		return -EINVAL;
586 
587 	if (drvdata->tdm_mode)
588 		fmt = SND_SOC_DAIFMT_DSP_A;
589 	else
590 		fmt = SND_SOC_DAIFMT_I2S;
591 
592 	if (drvdata->soc_mclk)
593 		fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBC_CFC;
594 	else
595 		fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBP_CFP;
596 
597 	ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
598 	if (ret && ret != -ENOTSUPP) {
599 		dev_err(rtd->dev, "Failed to set dai fmt: %d\n", ret);
600 		return ret;
601 	}
602 
603 	if (drvdata->tdm_mode) {
604 		/**
605 		 * As codec supports slot 2 and slot 3 for playback.
606 		 */
607 		ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0xC, 0, 8, 16);
608 		if (ret && ret != -ENOTSUPP) {
609 			dev_err(rtd->dev, "set TDM slot err: %d\n", ret);
610 			return ret;
611 		}
612 	}
613 
614 	for_each_rtd_codec_dais(rtd, i, codec_dai) {
615 		if (strcmp(codec_dai->name, "rt1019-aif"))
616 			continue;
617 
618 		if (drvdata->tdm_mode)
619 			ret = snd_soc_dai_set_pll(codec_dai, 0, RT1019_PLL_S_BCLK,
620 						  TDM_CHANNELS * format * srate, 256 * srate);
621 		else
622 			ret = snd_soc_dai_set_pll(codec_dai, 0, RT1019_PLL_S_BCLK,
623 						  ch * format * srate, 256 * srate);
624 
625 		if (ret < 0)
626 			return ret;
627 
628 		ret = snd_soc_dai_set_sysclk(codec_dai, RT1019_SCLK_S_PLL,
629 					     256 * srate, SND_SOC_CLOCK_IN);
630 		if (ret < 0)
631 			return ret;
632 
633 		if (drvdata->tdm_mode) {
634 			ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_DSP_A
635 							| SND_SOC_DAIFMT_NB_NF);
636 			if (ret < 0) {
637 				dev_err(rtd->card->dev, "Failed to set dai fmt: %d\n", ret);
638 				return ret;
639 			}
640 
641 			/**
642 			 * As codec supports slot 2 for left channel playback.
643 			 */
644 			if (!strcmp(codec_dai->component->name, "i2c-10EC1019:00")) {
645 				ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x4, 0x4, 8, 16);
646 				if (ret < 0)
647 					break;
648 			}
649 
650 			/**
651 			 * As codec supports slot 3 for right channel playback.
652 			 */
653 			if (!strcmp(codec_dai->component->name, "i2c-10EC1019:01")) {
654 				ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x8, 0x8, 8, 16);
655 				if (ret < 0)
656 					break;
657 			}
658 		}
659 	}
660 
661 	if (!drvdata->soc_mclk) {
662 		ret = acp_clk_enable(drvdata, srate, ch * format);
663 		if (ret < 0) {
664 			dev_err(rtd->card->dev, "Failed to enable AMP clk: %d\n", ret);
665 			return ret;
666 		}
667 	}
668 
669 	return 0;
670 }
671 
672 static int acp_card_amp_startup(struct snd_pcm_substream *substream)
673 {
674 	struct snd_pcm_runtime *runtime = substream->runtime;
675 
676 	runtime->hw.channels_max = DUAL_CHANNEL;
677 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
678 				      &constraints_channels);
679 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
680 				      &constraints_rates);
681 
682 	return 0;
683 }
684 
685 static const struct snd_soc_ops acp_card_rt1019_ops = {
686 	.startup = acp_card_amp_startup,
687 	.shutdown = acp_card_shutdown,
688 	.hw_params = acp_card_rt1019_hw_params,
689 };
690 
691 /* Declare Maxim codec components */
692 SND_SOC_DAILINK_DEF(max98360a,
693 	DAILINK_COMP_ARRAY(COMP_CODEC("MX98360A:00", "HiFi")));
694 
695 static const struct snd_kcontrol_new max98360a_controls[] = {
696 	SOC_DAPM_PIN_SWITCH("Spk"),
697 };
698 
699 static const struct snd_soc_dapm_widget max98360a_widgets[] = {
700 	SND_SOC_DAPM_SPK("Spk", NULL),
701 };
702 
703 static const struct snd_soc_dapm_route max98360a_map[] = {
704 	{"Spk", NULL, "Speaker"},
705 };
706 
707 static int acp_card_maxim_init(struct snd_soc_pcm_runtime *rtd)
708 {
709 	struct snd_soc_card *card = rtd->card;
710 	struct acp_card_drvdata *drvdata = card->drvdata;
711 	int ret;
712 
713 	if (drvdata->amp_codec_id != MAX98360A)
714 		return -EINVAL;
715 
716 	ret = snd_soc_dapm_new_controls(&card->dapm, max98360a_widgets,
717 					ARRAY_SIZE(max98360a_widgets));
718 	if (ret) {
719 		dev_err(rtd->dev, "unable to add widget dapm controls, ret %d\n", ret);
720 		return ret;
721 	}
722 
723 	ret = snd_soc_add_card_controls(card, max98360a_controls,
724 					ARRAY_SIZE(max98360a_controls));
725 	if (ret) {
726 		dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
727 		return ret;
728 	}
729 
730 	return snd_soc_dapm_add_routes(&rtd->card->dapm, max98360a_map,
731 				       ARRAY_SIZE(max98360a_map));
732 }
733 
734 static int acp_card_maxim_hw_params(struct snd_pcm_substream *substream,
735 				    struct snd_pcm_hw_params *params)
736 {
737 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
738 	struct snd_soc_card *card = rtd->card;
739 	struct acp_card_drvdata *drvdata = card->drvdata;
740 	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
741 	unsigned int fmt, srate, ch, format;
742 	int ret;
743 
744 	srate = params_rate(params);
745 	ch = params_channels(params);
746 	format = params_physical_width(params);
747 
748 	if (drvdata->tdm_mode)
749 		fmt = SND_SOC_DAIFMT_DSP_A;
750 	else
751 		fmt = SND_SOC_DAIFMT_I2S;
752 
753 	if (drvdata->soc_mclk)
754 		fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBC_CFC;
755 	else
756 		fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBP_CFP;
757 
758 	ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
759 	if (ret && ret != -ENOTSUPP) {
760 		dev_err(rtd->dev, "Failed to set dai fmt: %d\n", ret);
761 		return ret;
762 	}
763 
764 	if (drvdata->tdm_mode) {
765 		/**
766 		 * As codec supports slot 2 and slot 3 for playback.
767 		 */
768 		ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0xC, 0, 8, 16);
769 		if (ret && ret != -ENOTSUPP) {
770 			dev_err(rtd->dev, "set TDM slot err: %d\n", ret);
771 			return ret;
772 		}
773 	}
774 
775 	if (!drvdata->soc_mclk) {
776 		ret = acp_clk_enable(drvdata, srate, ch * format);
777 		if (ret < 0) {
778 			dev_err(rtd->card->dev, "Failed to enable AMP clk: %d\n", ret);
779 			return ret;
780 		}
781 	}
782 	return 0;
783 }
784 
785 static const struct snd_soc_ops acp_card_maxim_ops = {
786 	.startup = acp_card_amp_startup,
787 	.shutdown = acp_card_shutdown,
788 	.hw_params = acp_card_maxim_hw_params,
789 };
790 
791 SND_SOC_DAILINK_DEF(max98388,
792 		    DAILINK_COMP_ARRAY(COMP_CODEC("i2c-ADS8388:00", "max98388-aif1"),
793 				       COMP_CODEC("i2c-ADS8388:01", "max98388-aif1")));
794 
795 static const struct snd_kcontrol_new max98388_controls[] = {
796 	SOC_DAPM_PIN_SWITCH("Left Spk"),
797 	SOC_DAPM_PIN_SWITCH("Right Spk"),
798 };
799 
800 static const struct snd_soc_dapm_widget max98388_widgets[] = {
801 	SND_SOC_DAPM_SPK("Left Spk", NULL),
802 	SND_SOC_DAPM_SPK("Right Spk", NULL),
803 };
804 
805 static const struct snd_soc_dapm_route max98388_map[] = {
806 	{ "Left Spk", NULL, "Left BE_OUT" },
807 	{ "Right Spk", NULL, "Right BE_OUT" },
808 };
809 
810 static struct snd_soc_codec_conf max98388_conf[] = {
811 	{
812 		.dlc = COMP_CODEC_CONF("i2c-ADS8388:00"),
813 		.name_prefix = "Left",
814 	},
815 	{
816 		.dlc = COMP_CODEC_CONF("i2c-ADS8388:01"),
817 		.name_prefix = "Right",
818 	},
819 };
820 
821 static const unsigned int max98388_format[] = {16};
822 
823 static struct snd_pcm_hw_constraint_list constraints_sample_bits_max = {
824 	.list = max98388_format,
825 	.count = ARRAY_SIZE(max98388_format),
826 };
827 
828 static int acp_card_max98388_startup(struct snd_pcm_substream *substream)
829 {
830 	struct snd_pcm_runtime *runtime = substream->runtime;
831 
832 	runtime->hw.channels_max = DUAL_CHANNEL;
833 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
834 				   &constraints_channels);
835 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
836 				   &constraints_rates);
837 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
838 				   &constraints_sample_bits_max);
839 
840 	return 0;
841 }
842 
843 static int acp_card_max98388_init(struct snd_soc_pcm_runtime *rtd)
844 {
845 	struct snd_soc_card *card = rtd->card;
846 	struct acp_card_drvdata *drvdata = card->drvdata;
847 	int ret;
848 
849 	if (drvdata->amp_codec_id != MAX98388)
850 		return -EINVAL;
851 
852 	ret = snd_soc_dapm_new_controls(&card->dapm, max98388_widgets,
853 					ARRAY_SIZE(max98388_widgets));
854 
855 	if (ret) {
856 		dev_err(rtd->dev, "unable to add widget dapm controls, ret %d\n", ret);
857 		/* Don't need to add routes if widget addition failed */
858 		return ret;
859 	}
860 
861 	ret = snd_soc_add_card_controls(card, max98388_controls,
862 					ARRAY_SIZE(max98388_controls));
863 	if (ret) {
864 		dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
865 		return ret;
866 	}
867 
868 	return snd_soc_dapm_add_routes(&rtd->card->dapm, max98388_map,
869 				       ARRAY_SIZE(max98388_map));
870 }
871 
872 static int acp_max98388_hw_params(struct snd_pcm_substream *substream,
873 				  struct snd_pcm_hw_params *params)
874 {
875 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
876 	struct snd_soc_card *card = rtd->card;
877 	struct snd_soc_dai *codec_dai =
878 			snd_soc_card_get_codec_dai(card,
879 						   MAX98388_CODEC_DAI);
880 	int ret;
881 
882 	ret = snd_soc_dai_set_fmt(codec_dai,
883 				  SND_SOC_DAIFMT_CBS_CFS | SND_SOC_DAIFMT_I2S |
884 				  SND_SOC_DAIFMT_NB_NF);
885 	if (ret < 0)
886 		return ret;
887 
888 	return ret;
889 }
890 
891 static const struct snd_soc_ops acp_max98388_ops = {
892 	.startup = acp_card_max98388_startup,
893 	.hw_params = acp_max98388_hw_params,
894 };
895 
896 /* Declare nau8825 codec components */
897 SND_SOC_DAILINK_DEF(nau8825,
898 		    DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10508825:00", "nau8825-hifi")));
899 
900 static struct snd_soc_jack nau8825_jack;
901 static struct snd_soc_jack_pin nau8825_jack_pins[] = {
902 	{
903 		.pin = "Headphone Jack",
904 		.mask = SND_JACK_HEADPHONE,
905 	},
906 	{
907 		.pin = "Headset Mic",
908 		.mask = SND_JACK_MICROPHONE,
909 	},
910 };
911 
912 static const struct snd_kcontrol_new nau8825_controls[] = {
913 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
914 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
915 };
916 
917 static const struct snd_soc_dapm_widget nau8825_widgets[] = {
918 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
919 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
920 };
921 
922 static const struct snd_soc_dapm_route nau8825_map[] = {
923 	{ "Headphone Jack", NULL, "HPOL" },
924 	{ "Headphone Jack", NULL, "HPOR" },
925 };
926 
927 static int acp_card_nau8825_init(struct snd_soc_pcm_runtime *rtd)
928 {
929 	struct snd_soc_card *card = rtd->card;
930 	struct acp_card_drvdata *drvdata = card->drvdata;
931 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
932 	struct snd_soc_component *component = codec_dai->component;
933 	int ret;
934 
935 	dev_info(rtd->dev, "codec dai name = %s\n", codec_dai->name);
936 
937 	if (drvdata->hs_codec_id != NAU8825)
938 		return -EINVAL;
939 
940 	ret = snd_soc_dapm_new_controls(&card->dapm, nau8825_widgets,
941 					ARRAY_SIZE(nau8825_widgets));
942 	if (ret) {
943 		dev_err(rtd->dev, "unable to add widget dapm controls, ret %d\n", ret);
944 		return ret;
945 	}
946 
947 	ret = snd_soc_add_card_controls(card, nau8825_controls,
948 					ARRAY_SIZE(nau8825_controls));
949 	if (ret) {
950 		dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
951 		return ret;
952 	}
953 
954 	ret = snd_soc_card_jack_new_pins(card, "Headset Jack",
955 					 SND_JACK_HEADSET | SND_JACK_LINEOUT |
956 					 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
957 					 SND_JACK_BTN_2 | SND_JACK_BTN_3,
958 					 &nau8825_jack,
959 					 nau8825_jack_pins,
960 					 ARRAY_SIZE(nau8825_jack_pins));
961 	if (ret) {
962 		dev_err(card->dev, "HP jack creation failed %d\n", ret);
963 		return ret;
964 	}
965 
966 	snd_jack_set_key(nau8825_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
967 	snd_jack_set_key(nau8825_jack.jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
968 	snd_jack_set_key(nau8825_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
969 	snd_jack_set_key(nau8825_jack.jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
970 
971 	ret = snd_soc_component_set_jack(component, &nau8825_jack, NULL);
972 	if (ret) {
973 		dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
974 		return ret;
975 	}
976 
977 	return snd_soc_dapm_add_routes(&rtd->card->dapm, nau8825_map, ARRAY_SIZE(nau8825_map));
978 }
979 
980 static int acp_nau8825_hw_params(struct snd_pcm_substream *substream,
981 				 struct snd_pcm_hw_params *params)
982 {
983 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
984 	struct snd_soc_card *card = rtd->card;
985 	struct acp_card_drvdata *drvdata = card->drvdata;
986 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
987 	struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
988 	int ret;
989 	unsigned int fmt;
990 
991 	ret = snd_soc_dai_set_sysclk(codec_dai, NAU8825_CLK_FLL_FS,
992 				     (48000 * 256), SND_SOC_CLOCK_IN);
993 	if (ret < 0)
994 		dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
995 
996 	ret = snd_soc_dai_set_pll(codec_dai, 0, 0, params_rate(params),
997 				  params_rate(params) * 256);
998 	if (ret < 0) {
999 		dev_err(rtd->dev, "can't set FLL: %d\n", ret);
1000 		return ret;
1001 	}
1002 
1003 	if (drvdata->tdm_mode)
1004 		fmt = SND_SOC_DAIFMT_DSP_A;
1005 	else
1006 		fmt = SND_SOC_DAIFMT_I2S;
1007 
1008 	if (drvdata->soc_mclk)
1009 		fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBC_CFC;
1010 	else
1011 		fmt |= SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBP_CFP;
1012 
1013 	ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
1014 	if (ret && ret != -ENOTSUPP) {
1015 		dev_err(rtd->dev, "Failed to set dai fmt: %d\n", ret);
1016 		return ret;
1017 	}
1018 
1019 	ret =  snd_soc_dai_set_fmt(codec_dai, fmt);
1020 	if (ret < 0) {
1021 		dev_err(rtd->card->dev, "Failed to set dai fmt: %d\n", ret);
1022 		return ret;
1023 	}
1024 
1025 	if (drvdata->tdm_mode) {
1026 		/**
1027 		 * As codec supports slot 4 and slot 5 for playback and slot 6 for capture.
1028 		 */
1029 		ret = snd_soc_dai_set_tdm_slot(cpu_dai, 0x30, 0xC0, 8, 16);
1030 		if (ret && ret != -ENOTSUPP) {
1031 			dev_err(rtd->dev, "set TDM slot err: %d\n", ret);
1032 			return ret;
1033 		}
1034 
1035 		ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x40, 0x30, 8, 16);
1036 		if (ret < 0) {
1037 			dev_warn(rtd->dev, "set TDM slot err:%d\n", ret);
1038 			return ret;
1039 		}
1040 	}
1041 	return ret;
1042 }
1043 
1044 static int acp_nau8825_startup(struct snd_pcm_substream *substream)
1045 {
1046 	struct snd_pcm_runtime *runtime = substream->runtime;
1047 
1048 	runtime->hw.channels_max = 2;
1049 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
1050 				   &constraints_channels);
1051 
1052 	runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
1053 	snd_pcm_hw_constraint_list(runtime, 0,
1054 				   SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
1055 	return 0;
1056 }
1057 
1058 static const struct snd_soc_ops acp_card_nau8825_ops = {
1059 	.startup =  acp_nau8825_startup,
1060 	.hw_params = acp_nau8825_hw_params,
1061 };
1062 
1063 static int platform_clock_control(struct snd_soc_dapm_widget *w,
1064 				  struct snd_kcontrol *k, int  event)
1065 {
1066 	struct snd_soc_dapm_context *dapm = w->dapm;
1067 	struct snd_soc_card *card = dapm->card;
1068 	struct snd_soc_dai *codec_dai;
1069 	int ret = 0;
1070 
1071 	codec_dai = snd_soc_card_get_codec_dai(card, NAU8821_CODEC_DAI);
1072 	if (!codec_dai) {
1073 		dev_err(card->dev, "Codec dai not found\n");
1074 		return -EIO;
1075 	}
1076 
1077 	if (SND_SOC_DAPM_EVENT_OFF(event)) {
1078 		ret = snd_soc_dai_set_sysclk(codec_dai, NAU8821_CLK_INTERNAL,
1079 					     0, SND_SOC_CLOCK_IN);
1080 		if (ret < 0) {
1081 			dev_err(card->dev, "set sysclk err = %d\n", ret);
1082 			return -EIO;
1083 		}
1084 	} else {
1085 		ret = snd_soc_dai_set_sysclk(codec_dai, NAU8821_CLK_FLL_BLK, 0,
1086 					     SND_SOC_CLOCK_IN);
1087 		if (ret < 0)
1088 			dev_err(codec_dai->dev, "can't set FS clock %d\n", ret);
1089 		ret = snd_soc_dai_set_pll(codec_dai, 0, 0, NAU8821_BCLK,
1090 					  NAU8821_FREQ_OUT);
1091 		if (ret < 0)
1092 			dev_err(codec_dai->dev, "can't set FLL: %d\n", ret);
1093 	}
1094 	return ret;
1095 }
1096 
1097 static struct snd_soc_jack nau8821_jack;
1098 static struct snd_soc_jack_pin nau8821_jack_pins[] = {
1099 	{
1100 		.pin = "Headphone Jack",
1101 		.mask = SND_JACK_HEADPHONE,
1102 	},
1103 	{
1104 		.pin = "Headset Mic",
1105 		.mask = SND_JACK_MICROPHONE,
1106 	},
1107 };
1108 
1109 static const struct snd_kcontrol_new nau8821_controls[] = {
1110 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
1111 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
1112 };
1113 
1114 static const struct snd_soc_dapm_widget nau8821_widgets[] = {
1115 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
1116 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
1117 	SND_SOC_DAPM_MIC("Int Mic", NULL),
1118 	SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
1119 			    platform_clock_control, SND_SOC_DAPM_PRE_PMU |
1120 			    SND_SOC_DAPM_POST_PMD),
1121 };
1122 
1123 static const struct snd_soc_dapm_route nau8821_audio_route[] = {
1124 	/* HP jack connectors - unknown if we have jack detection */
1125 	{ "Headphone Jack", NULL, "HPOL" },
1126 	{ "Headphone Jack", NULL, "HPOR" },
1127 	{ "MICL", NULL, "Headset Mic" },
1128 	{ "MICR", NULL, "Headset Mic" },
1129 	{ "DMIC", NULL, "Int Mic" },
1130 	{ "Headphone Jack", NULL, "Platform Clock" },
1131 	{ "Headset Mic", NULL, "Platform Clock" },
1132 	{ "Int Mic", NULL, "Platform Clock" },
1133 };
1134 
1135 static const unsigned int nau8821_format[] = {16};
1136 
1137 static struct snd_pcm_hw_constraint_list constraints_sample_bits = {
1138 	.list = nau8821_format,
1139 	.count = ARRAY_SIZE(nau8821_format),
1140 };
1141 
1142 static int acp_8821_init(struct snd_soc_pcm_runtime *rtd)
1143 {
1144 	struct snd_soc_card *card = rtd->card;
1145 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
1146 	struct snd_soc_component *component = codec_dai->component;
1147 	int ret;
1148 
1149 	dev_info(rtd->dev, "codec dai name = %s\n", codec_dai->name);
1150 
1151 	ret = snd_soc_dapm_new_controls(&card->dapm, nau8821_widgets,
1152 					ARRAY_SIZE(nau8821_widgets));
1153 	if (ret) {
1154 		dev_err(rtd->dev, "unable to add widget dapm controls, ret %d\n", ret);
1155 		// Don't need to add routes if widget addition failed
1156 		return ret;
1157 	}
1158 
1159 	ret = snd_soc_add_card_controls(card, nau8821_controls,
1160 					ARRAY_SIZE(nau8821_controls));
1161 	if (ret) {
1162 		dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
1163 		return ret;
1164 	}
1165 
1166 	ret = snd_soc_card_jack_new_pins(card, "Headset Jack",
1167 					 SND_JACK_HEADSET | SND_JACK_LINEOUT |
1168 					 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
1169 					 SND_JACK_BTN_2 | SND_JACK_BTN_3,
1170 					 &nau8821_jack,
1171 					 nau8821_jack_pins,
1172 					 ARRAY_SIZE(nau8821_jack_pins));
1173 	if (ret) {
1174 		dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
1175 		return ret;
1176 	}
1177 
1178 	snd_jack_set_key(nau8821_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
1179 	snd_jack_set_key(nau8821_jack.jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
1180 	snd_jack_set_key(nau8821_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
1181 	snd_jack_set_key(nau8821_jack.jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
1182 
1183 	nau8821_enable_jack_detect(component, &nau8821_jack);
1184 
1185 	return snd_soc_dapm_add_routes(&rtd->card->dapm, nau8821_audio_route,
1186 				       ARRAY_SIZE(nau8821_audio_route));
1187 }
1188 
1189 static int acp_8821_startup(struct snd_pcm_substream *substream)
1190 {
1191 	struct snd_pcm_runtime *runtime = substream->runtime;
1192 
1193 	runtime->hw.channels_max = DUAL_CHANNEL;
1194 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
1195 				   &constraints_channels);
1196 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
1197 				   &constraints_rates);
1198 	snd_pcm_hw_constraint_list(substream->runtime, 0,
1199 				   SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
1200 				   &constraints_sample_bits);
1201 	return 0;
1202 }
1203 
1204 static int acp_nau8821_hw_params(struct snd_pcm_substream *substream,
1205 				 struct snd_pcm_hw_params *params)
1206 {
1207 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
1208 	struct snd_soc_card *card = rtd->card;
1209 	struct acp_card_drvdata *drvdata = card->drvdata;
1210 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
1211 	int ret;
1212 	unsigned int fmt;
1213 
1214 	if (drvdata->soc_mclk)
1215 		fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBC_CFC;
1216 	else
1217 		fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | SND_SOC_DAIFMT_CBP_CFP;
1218 
1219 	ret =  snd_soc_dai_set_fmt(codec_dai, fmt);
1220 	if (ret < 0) {
1221 		dev_err(rtd->card->dev, "Failed to set dai fmt: %d\n", ret);
1222 		return ret;
1223 	}
1224 
1225 	ret = snd_soc_dai_set_sysclk(codec_dai, NAU8821_CLK_FLL_BLK, 0,
1226 				     SND_SOC_CLOCK_IN);
1227 	if (ret < 0)
1228 		dev_err(card->dev, "can't set FS clock %d\n", ret);
1229 	ret = snd_soc_dai_set_pll(codec_dai, 0, 0, snd_soc_params_to_bclk(params),
1230 				  params_rate(params) * 256);
1231 	if (ret < 0)
1232 		dev_err(card->dev, "can't set FLL: %d\n", ret);
1233 
1234 	return ret;
1235 }
1236 
1237 static const struct snd_soc_ops acp_8821_ops = {
1238 	.startup = acp_8821_startup,
1239 	.hw_params = acp_nau8821_hw_params,
1240 };
1241 
1242 SND_SOC_DAILINK_DEF(nau8821,
1243 		    DAILINK_COMP_ARRAY(COMP_CODEC("i2c-NVTN2020:00",
1244 						  "nau8821-hifi")));
1245 
1246 /* Declare DMIC codec components */
1247 SND_SOC_DAILINK_DEF(dmic_codec,
1248 		DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
1249 
1250 /* Declare ACP CPU components */
1251 static struct snd_soc_dai_link_component platform_component[] = {
1252 	{
1253 		 .name = "acp_asoc_renoir.0",
1254 	}
1255 };
1256 
1257 static struct snd_soc_dai_link_component platform_rmb_component[] = {
1258 	{
1259 		.name = "acp_asoc_rembrandt.0",
1260 	}
1261 };
1262 
1263 static struct snd_soc_dai_link_component sof_component[] = {
1264 	{
1265 		 .name = "0000:04:00.5",
1266 	}
1267 };
1268 
1269 SND_SOC_DAILINK_DEF(i2s_sp,
1270 	DAILINK_COMP_ARRAY(COMP_CPU("acp-i2s-sp")));
1271 SND_SOC_DAILINK_DEF(i2s_hs,
1272 		    DAILINK_COMP_ARRAY(COMP_CPU("acp-i2s-hs")));
1273 SND_SOC_DAILINK_DEF(sof_sp,
1274 	DAILINK_COMP_ARRAY(COMP_CPU("acp-sof-sp")));
1275 SND_SOC_DAILINK_DEF(sof_sp_virtual,
1276 	DAILINK_COMP_ARRAY(COMP_CPU("acp-sof-sp-virtual")));
1277 SND_SOC_DAILINK_DEF(sof_hs,
1278 		    DAILINK_COMP_ARRAY(COMP_CPU("acp-sof-hs")));
1279 SND_SOC_DAILINK_DEF(sof_hs_virtual,
1280 	DAILINK_COMP_ARRAY(COMP_CPU("acp-sof-hs-virtual")));
1281 SND_SOC_DAILINK_DEF(sof_dmic,
1282 	DAILINK_COMP_ARRAY(COMP_CPU("acp-sof-dmic")));
1283 SND_SOC_DAILINK_DEF(pdm_dmic,
1284 	DAILINK_COMP_ARRAY(COMP_CPU("acp-pdm-dmic")));
1285 
1286 static int acp_rtk_set_bias_level(struct snd_soc_card *card,
1287 				  struct snd_soc_dapm_context *dapm,
1288 				  enum snd_soc_bias_level level)
1289 {
1290 	struct snd_soc_component *component = dapm->component;
1291 	struct acp_card_drvdata *drvdata = card->drvdata;
1292 	int ret = 0;
1293 
1294 	if (!component)
1295 		return 0;
1296 
1297 	if (strncmp(component->name, "i2c-RTL5682", 11) &&
1298 	    strncmp(component->name, "i2c-10EC1019", 12))
1299 		return 0;
1300 
1301 	/*
1302 	 * For Realtek's codec and amplifier components,
1303 	 * the lrck and bclk must be enabled brfore their all dapms be powered on,
1304 	 * and must be disabled after their all dapms be powered down
1305 	 * to avoid any pop.
1306 	 */
1307 	switch (level) {
1308 	case SND_SOC_BIAS_STANDBY:
1309 		if (snd_soc_dapm_get_bias_level(dapm) == SND_SOC_BIAS_OFF) {
1310 
1311 			/* Increase bclk's enable_count */
1312 			ret = clk_prepare_enable(drvdata->bclk);
1313 			if (ret < 0)
1314 				dev_err(component->dev, "Failed to enable bclk %d\n", ret);
1315 		} else {
1316 			/*
1317 			 * Decrease bclk's enable_count.
1318 			 * While the enable_count is 0, the bclk would be closed.
1319 			 */
1320 			clk_disable_unprepare(drvdata->bclk);
1321 		}
1322 		break;
1323 	default:
1324 		break;
1325 	}
1326 
1327 	return ret;
1328 }
1329 
1330 int acp_sofdsp_dai_links_create(struct snd_soc_card *card)
1331 {
1332 	struct snd_soc_dai_link *links;
1333 	struct device *dev = card->dev;
1334 	struct acp_card_drvdata *drv_data = card->drvdata;
1335 	int i = 0, num_links = 0;
1336 
1337 	if (drv_data->hs_cpu_id)
1338 		num_links++;
1339 	if (drv_data->amp_cpu_id)
1340 		num_links++;
1341 	if (drv_data->dmic_cpu_id)
1342 		num_links++;
1343 
1344 	links = devm_kcalloc(dev, num_links, sizeof(struct snd_soc_dai_link), GFP_KERNEL);
1345 	if (!links)
1346 		return -ENOMEM;
1347 
1348 	if (drv_data->hs_cpu_id == I2S_SP) {
1349 		links[i].name = "acp-headset-codec";
1350 		links[i].id = HEADSET_BE_ID;
1351 		links[i].cpus = sof_sp;
1352 		links[i].num_cpus = ARRAY_SIZE(sof_sp);
1353 		links[i].platforms = sof_component;
1354 		links[i].num_platforms = ARRAY_SIZE(sof_component);
1355 		links[i].dpcm_playback = 1;
1356 		links[i].dpcm_capture = 1;
1357 		links[i].nonatomic = true;
1358 		links[i].no_pcm = 1;
1359 		if (!drv_data->hs_codec_id) {
1360 			/* Use dummy codec if codec id not specified */
1361 			links[i].codecs = &asoc_dummy_dlc;
1362 			links[i].num_codecs = 1;
1363 		}
1364 		if (drv_data->hs_codec_id == RT5682) {
1365 			links[i].codecs = rt5682;
1366 			links[i].num_codecs = ARRAY_SIZE(rt5682);
1367 			links[i].init = acp_card_rt5682_init;
1368 			links[i].ops = &acp_card_rt5682_ops;
1369 		}
1370 		if (drv_data->hs_codec_id == RT5682S) {
1371 			links[i].codecs = rt5682s;
1372 			links[i].num_codecs = ARRAY_SIZE(rt5682s);
1373 			links[i].init = acp_card_rt5682s_init;
1374 			links[i].ops = &acp_card_rt5682s_ops;
1375 		}
1376 		if (drv_data->hs_codec_id == NAU8821) {
1377 			links[i].codecs = nau8821;
1378 			links[i].num_codecs = ARRAY_SIZE(nau8821);
1379 			links[i].init = acp_8821_init;
1380 			links[i].ops = &acp_8821_ops;
1381 		}
1382 		i++;
1383 	}
1384 
1385 	if (drv_data->hs_cpu_id == I2S_HS) {
1386 		links[i].name = "acp-headset-codec";
1387 		links[i].id = HEADSET_BE_ID;
1388 		links[i].cpus = sof_hs;
1389 		links[i].num_cpus = ARRAY_SIZE(sof_hs);
1390 		links[i].platforms = sof_component;
1391 		links[i].num_platforms = ARRAY_SIZE(sof_component);
1392 		links[i].dpcm_playback = 1;
1393 		links[i].dpcm_capture = 1;
1394 		links[i].nonatomic = true;
1395 		links[i].no_pcm = 1;
1396 		if (!drv_data->hs_codec_id) {
1397 			/* Use dummy codec if codec id not specified */
1398 			links[i].codecs = &asoc_dummy_dlc;
1399 			links[i].num_codecs = 1;
1400 		}
1401 		if (drv_data->hs_codec_id == NAU8825) {
1402 			links[i].codecs = nau8825;
1403 			links[i].num_codecs = ARRAY_SIZE(nau8825);
1404 			links[i].init = acp_card_nau8825_init;
1405 			links[i].ops = &acp_card_nau8825_ops;
1406 		}
1407 		if (drv_data->hs_codec_id == RT5682S) {
1408 			links[i].codecs = rt5682s;
1409 			links[i].num_codecs = ARRAY_SIZE(rt5682s);
1410 			links[i].init = acp_card_rt5682s_init;
1411 			links[i].ops = &acp_card_rt5682s_ops;
1412 		}
1413 		i++;
1414 	}
1415 
1416 	if (drv_data->amp_cpu_id == I2S_SP) {
1417 		links[i].name = "acp-amp-codec";
1418 		links[i].id = AMP_BE_ID;
1419 		if (drv_data->platform == RENOIR) {
1420 			links[i].cpus = sof_sp;
1421 			links[i].num_cpus = ARRAY_SIZE(sof_sp);
1422 		} else {
1423 			links[i].cpus = sof_sp_virtual;
1424 			links[i].num_cpus = ARRAY_SIZE(sof_sp_virtual);
1425 		}
1426 		links[i].platforms = sof_component;
1427 		links[i].num_platforms = ARRAY_SIZE(sof_component);
1428 		links[i].dpcm_playback = 1;
1429 		links[i].nonatomic = true;
1430 		links[i].no_pcm = 1;
1431 		if (!drv_data->amp_codec_id) {
1432 			/* Use dummy codec if codec id not specified */
1433 			links[i].codecs = &asoc_dummy_dlc;
1434 			links[i].num_codecs = 1;
1435 		}
1436 		if (drv_data->amp_codec_id == RT1019) {
1437 			links[i].codecs = rt1019;
1438 			links[i].num_codecs = ARRAY_SIZE(rt1019);
1439 			links[i].ops = &acp_card_rt1019_ops;
1440 			links[i].init = acp_card_rt1019_init;
1441 			card->codec_conf = rt1019_conf;
1442 			card->num_configs = ARRAY_SIZE(rt1019_conf);
1443 		}
1444 		if (drv_data->amp_codec_id == MAX98360A) {
1445 			links[i].codecs = max98360a;
1446 			links[i].num_codecs = ARRAY_SIZE(max98360a);
1447 			links[i].ops = &acp_card_maxim_ops;
1448 			links[i].init = acp_card_maxim_init;
1449 		}
1450 		i++;
1451 	}
1452 
1453 	if (drv_data->amp_cpu_id == I2S_HS) {
1454 		links[i].name = "acp-amp-codec";
1455 		links[i].id = AMP_BE_ID;
1456 		links[i].cpus = sof_hs_virtual;
1457 		links[i].num_cpus = ARRAY_SIZE(sof_hs_virtual);
1458 		links[i].platforms = sof_component;
1459 		links[i].num_platforms = ARRAY_SIZE(sof_component);
1460 		links[i].dpcm_playback = 1;
1461 		links[i].nonatomic = true;
1462 		links[i].no_pcm = 1;
1463 		if (!drv_data->amp_codec_id) {
1464 			/* Use dummy codec if codec id not specified */
1465 			links[i].codecs = &asoc_dummy_dlc;
1466 			links[i].num_codecs = 1;
1467 		}
1468 		if (drv_data->amp_codec_id == MAX98360A) {
1469 			links[i].codecs = max98360a;
1470 			links[i].num_codecs = ARRAY_SIZE(max98360a);
1471 			links[i].ops = &acp_card_maxim_ops;
1472 			links[i].init = acp_card_maxim_init;
1473 		}
1474 		if (drv_data->amp_codec_id == MAX98388) {
1475 			links[i].codecs = max98388;
1476 			links[i].num_codecs = ARRAY_SIZE(max98388);
1477 			links[i].ops = &acp_max98388_ops;
1478 			links[i].init = acp_card_max98388_init;
1479 			card->codec_conf = max98388_conf;
1480 			card->num_configs = ARRAY_SIZE(max98388_conf);
1481 		}
1482 		if (drv_data->amp_codec_id == RT1019) {
1483 			links[i].codecs = rt1019;
1484 			links[i].num_codecs = ARRAY_SIZE(rt1019);
1485 			links[i].ops = &acp_card_rt1019_ops;
1486 			links[i].init = acp_card_rt1019_init;
1487 			card->codec_conf = rt1019_conf;
1488 			card->num_configs = ARRAY_SIZE(rt1019_conf);
1489 		}
1490 		i++;
1491 	}
1492 
1493 	if (drv_data->dmic_cpu_id == DMIC) {
1494 		links[i].name = "acp-dmic-codec";
1495 		links[i].id = DMIC_BE_ID;
1496 		links[i].codecs = dmic_codec;
1497 		links[i].num_codecs = ARRAY_SIZE(dmic_codec);
1498 		links[i].cpus = sof_dmic;
1499 		links[i].num_cpus = ARRAY_SIZE(sof_dmic);
1500 		links[i].platforms = sof_component;
1501 		links[i].num_platforms = ARRAY_SIZE(sof_component);
1502 		links[i].dpcm_capture = 1;
1503 		links[i].nonatomic = true;
1504 		links[i].no_pcm = 1;
1505 	}
1506 
1507 	card->dai_link = links;
1508 	card->num_links = num_links;
1509 	card->set_bias_level = acp_rtk_set_bias_level;
1510 
1511 	return 0;
1512 }
1513 EXPORT_SYMBOL_NS_GPL(acp_sofdsp_dai_links_create, SND_SOC_AMD_MACH);
1514 
1515 int acp_legacy_dai_links_create(struct snd_soc_card *card)
1516 {
1517 	struct snd_soc_dai_link *links;
1518 	struct device *dev = card->dev;
1519 	struct acp_card_drvdata *drv_data = card->drvdata;
1520 	int i = 0, num_links = 0;
1521 
1522 	if (drv_data->hs_cpu_id)
1523 		num_links++;
1524 	if (drv_data->amp_cpu_id)
1525 		num_links++;
1526 	if (drv_data->dmic_cpu_id)
1527 		num_links++;
1528 
1529 	links = devm_kcalloc(dev, num_links, sizeof(struct snd_soc_dai_link), GFP_KERNEL);
1530 	if (!links)
1531 		return -ENOMEM;
1532 
1533 	if (drv_data->hs_cpu_id == I2S_SP) {
1534 		links[i].name = "acp-headset-codec";
1535 		links[i].id = HEADSET_BE_ID;
1536 		links[i].cpus = i2s_sp;
1537 		links[i].num_cpus = ARRAY_SIZE(i2s_sp);
1538 		links[i].platforms = platform_component;
1539 		links[i].num_platforms = ARRAY_SIZE(platform_component);
1540 		links[i].dpcm_playback = 1;
1541 		links[i].dpcm_capture = 1;
1542 		if (!drv_data->hs_codec_id) {
1543 			/* Use dummy codec if codec id not specified */
1544 			links[i].codecs = &asoc_dummy_dlc;
1545 			links[i].num_codecs = 1;
1546 		}
1547 		if (drv_data->hs_codec_id == RT5682) {
1548 			links[i].codecs = rt5682;
1549 			links[i].num_codecs = ARRAY_SIZE(rt5682);
1550 			links[i].init = acp_card_rt5682_init;
1551 			links[i].ops = &acp_card_rt5682_ops;
1552 		}
1553 		if (drv_data->hs_codec_id == RT5682S) {
1554 			links[i].codecs = rt5682s;
1555 			links[i].num_codecs = ARRAY_SIZE(rt5682s);
1556 			links[i].init = acp_card_rt5682s_init;
1557 			links[i].ops = &acp_card_rt5682s_ops;
1558 		}
1559 		i++;
1560 	}
1561 
1562 	if (drv_data->hs_cpu_id == I2S_HS) {
1563 		links[i].name = "acp-headset-codec";
1564 		links[i].id = HEADSET_BE_ID;
1565 		links[i].cpus = i2s_hs;
1566 		links[i].num_cpus = ARRAY_SIZE(i2s_hs);
1567 		if (drv_data->platform == REMBRANDT) {
1568 			links[i].platforms = platform_rmb_component;
1569 			links[i].num_platforms = ARRAY_SIZE(platform_rmb_component);
1570 		} else {
1571 			links[i].platforms = platform_component;
1572 			links[i].num_platforms = ARRAY_SIZE(platform_component);
1573 		}
1574 		links[i].dpcm_playback = 1;
1575 		links[i].dpcm_capture = 1;
1576 		if (!drv_data->hs_codec_id) {
1577 			/* Use dummy codec if codec id not specified */
1578 			links[i].codecs = &asoc_dummy_dlc;
1579 			links[i].num_codecs = 1;
1580 		}
1581 		if (drv_data->hs_codec_id == NAU8825) {
1582 			links[i].codecs = nau8825;
1583 			links[i].num_codecs = ARRAY_SIZE(nau8825);
1584 			links[i].init = acp_card_nau8825_init;
1585 			links[i].ops = &acp_card_nau8825_ops;
1586 		}
1587 		if (drv_data->hs_codec_id == RT5682S) {
1588 			links[i].codecs = rt5682s;
1589 			links[i].num_codecs = ARRAY_SIZE(rt5682s);
1590 			links[i].init = acp_card_rt5682s_init;
1591 			links[i].ops = &acp_card_rt5682s_ops;
1592 		}
1593 		i++;
1594 	}
1595 
1596 	if (drv_data->amp_cpu_id == I2S_SP) {
1597 		links[i].name = "acp-amp-codec";
1598 		links[i].id = AMP_BE_ID;
1599 		links[i].cpus = i2s_sp;
1600 		links[i].num_cpus = ARRAY_SIZE(i2s_sp);
1601 		links[i].platforms = platform_component;
1602 		links[i].num_platforms = ARRAY_SIZE(platform_component);
1603 		links[i].dpcm_playback = 1;
1604 		if (!drv_data->amp_codec_id) {
1605 			/* Use dummy codec if codec id not specified */
1606 			links[i].codecs = &asoc_dummy_dlc;
1607 			links[i].num_codecs = 1;
1608 		}
1609 		if (drv_data->amp_codec_id == RT1019) {
1610 			links[i].codecs = rt1019;
1611 			links[i].num_codecs = ARRAY_SIZE(rt1019);
1612 			links[i].ops = &acp_card_rt1019_ops;
1613 			links[i].init = acp_card_rt1019_init;
1614 			card->codec_conf = rt1019_conf;
1615 			card->num_configs = ARRAY_SIZE(rt1019_conf);
1616 		}
1617 		if (drv_data->amp_codec_id == MAX98360A) {
1618 			links[i].codecs = max98360a;
1619 			links[i].num_codecs = ARRAY_SIZE(max98360a);
1620 			links[i].ops = &acp_card_maxim_ops;
1621 			links[i].init = acp_card_maxim_init;
1622 		}
1623 		i++;
1624 	}
1625 
1626 	if (drv_data->amp_cpu_id == I2S_HS) {
1627 		links[i].name = "acp-amp-codec";
1628 		links[i].id = AMP_BE_ID;
1629 		links[i].cpus = i2s_hs;
1630 		links[i].num_cpus = ARRAY_SIZE(i2s_hs);
1631 		if (drv_data->platform == REMBRANDT) {
1632 			links[i].platforms = platform_rmb_component;
1633 			links[i].num_platforms = ARRAY_SIZE(platform_rmb_component);
1634 		} else {
1635 			links[i].platforms = platform_component;
1636 			links[i].num_platforms = ARRAY_SIZE(platform_component);
1637 		}
1638 		links[i].dpcm_playback = 1;
1639 		if (!drv_data->amp_codec_id) {
1640 			/* Use dummy codec if codec id not specified */
1641 			links[i].codecs = &asoc_dummy_dlc;
1642 			links[i].num_codecs = 1;
1643 		}
1644 		if (drv_data->amp_codec_id == MAX98360A) {
1645 			links[i].codecs = max98360a;
1646 			links[i].num_codecs = ARRAY_SIZE(max98360a);
1647 			links[i].ops = &acp_card_maxim_ops;
1648 			links[i].init = acp_card_maxim_init;
1649 		}
1650 		if (drv_data->amp_codec_id == RT1019) {
1651 			links[i].codecs = rt1019;
1652 			links[i].num_codecs = ARRAY_SIZE(rt1019);
1653 			links[i].ops = &acp_card_rt1019_ops;
1654 			links[i].init = acp_card_rt1019_init;
1655 			card->codec_conf = rt1019_conf;
1656 			card->num_configs = ARRAY_SIZE(rt1019_conf);
1657 		}
1658 		i++;
1659 	}
1660 
1661 	if (drv_data->dmic_cpu_id == DMIC) {
1662 		links[i].name = "acp-dmic-codec";
1663 		links[i].id = DMIC_BE_ID;
1664 		if (drv_data->dmic_codec_id == DMIC) {
1665 			links[i].codecs = dmic_codec;
1666 			links[i].num_codecs = ARRAY_SIZE(dmic_codec);
1667 		} else {
1668 			/* Use dummy codec if codec id not specified */
1669 			links[i].codecs = &asoc_dummy_dlc;
1670 			links[i].num_codecs = 1;
1671 		}
1672 		links[i].cpus = pdm_dmic;
1673 		links[i].num_cpus = ARRAY_SIZE(pdm_dmic);
1674 		if (drv_data->platform == REMBRANDT) {
1675 			links[i].platforms = platform_rmb_component;
1676 			links[i].num_platforms = ARRAY_SIZE(platform_rmb_component);
1677 		} else {
1678 			links[i].platforms = platform_component;
1679 			links[i].num_platforms = ARRAY_SIZE(platform_component);
1680 		}
1681 		links[i].ops = &acp_card_dmic_ops;
1682 		links[i].dpcm_capture = 1;
1683 	}
1684 
1685 	card->dai_link = links;
1686 	card->num_links = num_links;
1687 	card->set_bias_level = acp_rtk_set_bias_level;
1688 
1689 	return 0;
1690 }
1691 EXPORT_SYMBOL_NS_GPL(acp_legacy_dai_links_create, SND_SOC_AMD_MACH);
1692 
1693 MODULE_LICENSE("GPL v2");
1694