1 // SPDX-License-Identifier: MIT
3 // Machine driver for AMD ACP Audio engine using DA7219, RT5682 & MAX98357 codec
5 //Copyright 2017-2021 Advanced Micro Devices, Inc.
7 #include <sound/core.h>
10 #include <sound/pcm_params.h>
11 #include <sound/soc-dapm.h>
12 #include <sound/jack.h>
13 #include <linux/clk.h>
14 #include <linux/gpio.h>
15 #include <linux/module.h>
16 #include <linux/regulator/machine.h>
17 #include <linux/regulator/driver.h>
18 #include <linux/i2c.h>
19 #include <linux/input.h>
20 #include <linux/acpi.h>
23 #include "../codecs/da7219.h"
24 #include "../codecs/da7219-aad.h"
25 #include "../codecs/rt5682.h"
27 #define CZ_PLAT_CLK 48000000
28 #define DUAL_CHANNEL 2
29 #define RT5682_PLL_FREQ (48000 * 512)
31 static struct snd_soc_jack cz_jack;
32 static struct clk *da7219_dai_wclk;
33 static struct clk *da7219_dai_bclk;
34 static struct clk *rt5682_dai_wclk;
35 static struct clk *rt5682_dai_bclk;
37 void *acp_soc_is_rltk_max(struct device *dev);
39 static int cz_da7219_init(struct snd_soc_pcm_runtime *rtd)
42 struct snd_soc_card *card = rtd->card;
43 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
44 struct snd_soc_component *component = codec_dai->component;
46 dev_info(rtd->dev, "codec dai name = %s\n", codec_dai->name);
48 ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK,
49 CZ_PLAT_CLK, SND_SOC_CLOCK_IN);
51 dev_err(rtd->dev, "can't set codec sysclk: %d\n", ret);
55 ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_PLL,
56 CZ_PLAT_CLK, DA7219_PLL_FREQ_OUT_98304);
58 dev_err(rtd->dev, "can't set codec pll: %d\n", ret);
62 da7219_dai_wclk = devm_clk_get(component->dev, "da7219-dai-wclk");
63 if (IS_ERR(da7219_dai_wclk))
64 return PTR_ERR(da7219_dai_wclk);
66 da7219_dai_bclk = devm_clk_get(component->dev, "da7219-dai-bclk");
67 if (IS_ERR(da7219_dai_bclk))
68 return PTR_ERR(da7219_dai_bclk);
70 ret = snd_soc_card_jack_new(card, "Headset Jack",
71 SND_JACK_HEADSET | SND_JACK_LINEOUT |
72 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
73 SND_JACK_BTN_2 | SND_JACK_BTN_3,
76 dev_err(card->dev, "HP jack creation failed %d\n", ret);
80 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
81 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
82 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
83 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_3, KEY_VOICECOMMAND);
85 da7219_aad_jack_det(component, &cz_jack);
90 static int da7219_clk_enable(struct snd_pcm_substream *substream)
93 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
96 * Set wclk to 48000 because the rate constraint of this driver is
97 * 48000. ADAU7002 spec: "The ADAU7002 requires a BCLK rate that is
98 * minimum of 64x the LRCLK sample rate." DA7219 is the only clk
99 * source so for all codecs we have to limit bclk to 64X lrclk.
101 clk_set_rate(da7219_dai_wclk, 48000);
102 clk_set_rate(da7219_dai_bclk, 48000 * 64);
103 ret = clk_prepare_enable(da7219_dai_bclk);
105 dev_err(rtd->dev, "can't enable master clock %d\n", ret);
112 static void da7219_clk_disable(void)
114 clk_disable_unprepare(da7219_dai_bclk);
117 static int cz_rt5682_init(struct snd_soc_pcm_runtime *rtd)
120 struct snd_soc_card *card = rtd->card;
121 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
122 struct snd_soc_component *component = codec_dai->component;
124 dev_info(codec_dai->dev, "codec dai name = %s\n", codec_dai->name);
126 /* Set codec sysclk */
127 ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL2,
128 RT5682_PLL_FREQ, SND_SOC_CLOCK_IN);
130 dev_err(codec_dai->dev,
131 "Failed to set rt5682 SYSCLK: %d\n", ret);
135 ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL2, RT5682_PLL2_S_MCLK,
136 CZ_PLAT_CLK, RT5682_PLL_FREQ);
138 dev_err(codec_dai->dev, "can't set rt5682 PLL: %d\n", ret);
142 rt5682_dai_wclk = devm_clk_get(component->dev, "rt5682-dai-wclk");
143 if (IS_ERR(rt5682_dai_wclk))
144 return PTR_ERR(rt5682_dai_wclk);
146 rt5682_dai_bclk = devm_clk_get(component->dev, "rt5682-dai-bclk");
147 if (IS_ERR(rt5682_dai_bclk))
148 return PTR_ERR(rt5682_dai_bclk);
150 ret = snd_soc_card_jack_new(card, "Headset Jack",
151 SND_JACK_HEADSET | SND_JACK_LINEOUT |
152 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
153 SND_JACK_BTN_2 | SND_JACK_BTN_3,
156 dev_err(card->dev, "HP jack creation failed %d\n", ret);
160 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
161 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
162 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
163 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_3, KEY_VOICECOMMAND);
165 ret = snd_soc_component_set_jack(component, &cz_jack, NULL);
167 dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
173 static int rt5682_clk_enable(struct snd_pcm_substream *substream)
176 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
179 * Set wclk to 48000 because the rate constraint of this driver is
180 * 48000. ADAU7002 spec: "The ADAU7002 requires a BCLK rate that is
181 * minimum of 64x the LRCLK sample rate." RT5682 is the only clk
182 * source so for all codecs we have to limit bclk to 64X lrclk.
184 ret = clk_set_rate(rt5682_dai_wclk, 48000);
186 dev_err(rtd->dev, "Error setting wclk rate: %d\n", ret);
189 ret = clk_set_rate(rt5682_dai_bclk, 48000 * 64);
191 dev_err(rtd->dev, "Error setting bclk rate: %d\n", ret);
194 ret = clk_prepare_enable(rt5682_dai_wclk);
196 dev_err(rtd->dev, "can't enable wclk %d\n", ret);
202 static void rt5682_clk_disable(void)
204 clk_disable_unprepare(rt5682_dai_wclk);
207 static const unsigned int channels[] = {
211 static const unsigned int rates[] = {
215 static const struct snd_pcm_hw_constraint_list constraints_rates = {
216 .count = ARRAY_SIZE(rates),
221 static const struct snd_pcm_hw_constraint_list constraints_channels = {
222 .count = ARRAY_SIZE(channels),
227 static int cz_da7219_play_startup(struct snd_pcm_substream *substream)
229 struct snd_pcm_runtime *runtime = substream->runtime;
230 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
231 struct snd_soc_card *card = rtd->card;
232 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
235 * On this platform for PCM device we support stereo
238 runtime->hw.channels_max = DUAL_CHANNEL;
239 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
240 &constraints_channels);
241 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
244 machine->play_i2s_instance = I2S_SP_INSTANCE;
245 return da7219_clk_enable(substream);
248 static int cz_da7219_cap_startup(struct snd_pcm_substream *substream)
250 struct snd_pcm_runtime *runtime = substream->runtime;
251 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
252 struct snd_soc_card *card = rtd->card;
253 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
256 * On this platform for PCM device we support stereo
259 runtime->hw.channels_max = DUAL_CHANNEL;
260 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
261 &constraints_channels);
262 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
265 machine->cap_i2s_instance = I2S_SP_INSTANCE;
266 machine->capture_channel = CAP_CHANNEL1;
267 return da7219_clk_enable(substream);
270 static int cz_max_startup(struct snd_pcm_substream *substream)
272 struct snd_pcm_runtime *runtime = substream->runtime;
273 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
274 struct snd_soc_card *card = rtd->card;
275 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
278 * On this platform for PCM device we support stereo
281 runtime->hw.channels_max = DUAL_CHANNEL;
282 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
283 &constraints_channels);
284 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
287 machine->play_i2s_instance = I2S_BT_INSTANCE;
288 return da7219_clk_enable(substream);
291 static int cz_dmic0_startup(struct snd_pcm_substream *substream)
293 struct snd_pcm_runtime *runtime = substream->runtime;
294 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
295 struct snd_soc_card *card = rtd->card;
296 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
299 * On this platform for PCM device we support stereo
302 runtime->hw.channels_max = DUAL_CHANNEL;
303 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
304 &constraints_channels);
305 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
308 machine->cap_i2s_instance = I2S_BT_INSTANCE;
309 return da7219_clk_enable(substream);
312 static int cz_dmic1_startup(struct snd_pcm_substream *substream)
314 struct snd_pcm_runtime *runtime = substream->runtime;
315 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
316 struct snd_soc_card *card = rtd->card;
317 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
320 * On this platform for PCM device we support stereo
323 runtime->hw.channels_max = DUAL_CHANNEL;
324 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
325 &constraints_channels);
326 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
329 machine->cap_i2s_instance = I2S_SP_INSTANCE;
330 machine->capture_channel = CAP_CHANNEL0;
331 return da7219_clk_enable(substream);
334 static void cz_da7219_shutdown(struct snd_pcm_substream *substream)
336 da7219_clk_disable();
339 static int cz_rt5682_play_startup(struct snd_pcm_substream *substream)
341 struct snd_pcm_runtime *runtime = substream->runtime;
342 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
343 struct snd_soc_card *card = rtd->card;
344 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
347 * On this platform for PCM device we support stereo
350 runtime->hw.channels_max = DUAL_CHANNEL;
351 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
352 &constraints_channels);
353 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
356 machine->play_i2s_instance = I2S_SP_INSTANCE;
357 return rt5682_clk_enable(substream);
360 static int cz_rt5682_cap_startup(struct snd_pcm_substream *substream)
362 struct snd_pcm_runtime *runtime = substream->runtime;
363 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
364 struct snd_soc_card *card = rtd->card;
365 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
368 * On this platform for PCM device we support stereo
371 runtime->hw.channels_max = DUAL_CHANNEL;
372 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
373 &constraints_channels);
374 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
377 machine->cap_i2s_instance = I2S_SP_INSTANCE;
378 machine->capture_channel = CAP_CHANNEL1;
379 return rt5682_clk_enable(substream);
382 static int cz_rt5682_max_startup(struct snd_pcm_substream *substream)
384 struct snd_pcm_runtime *runtime = substream->runtime;
385 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
386 struct snd_soc_card *card = rtd->card;
387 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
390 * On this platform for PCM device we support stereo
393 runtime->hw.channels_max = DUAL_CHANNEL;
394 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
395 &constraints_channels);
396 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
399 machine->play_i2s_instance = I2S_BT_INSTANCE;
400 return rt5682_clk_enable(substream);
403 static int cz_rt5682_dmic0_startup(struct snd_pcm_substream *substream)
405 struct snd_pcm_runtime *runtime = substream->runtime;
406 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
407 struct snd_soc_card *card = rtd->card;
408 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
411 * On this platform for PCM device we support stereo
414 runtime->hw.channels_max = DUAL_CHANNEL;
415 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
416 &constraints_channels);
417 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
420 machine->cap_i2s_instance = I2S_BT_INSTANCE;
421 return rt5682_clk_enable(substream);
424 static int cz_rt5682_dmic1_startup(struct snd_pcm_substream *substream)
426 struct snd_pcm_runtime *runtime = substream->runtime;
427 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
428 struct snd_soc_card *card = rtd->card;
429 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card);
432 * On this platform for PCM device we support stereo
435 runtime->hw.channels_max = DUAL_CHANNEL;
436 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
437 &constraints_channels);
438 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
441 machine->cap_i2s_instance = I2S_SP_INSTANCE;
442 machine->capture_channel = CAP_CHANNEL0;
443 return rt5682_clk_enable(substream);
446 static void cz_rt5682_shutdown(struct snd_pcm_substream *substream)
448 rt5682_clk_disable();
451 static const struct snd_soc_ops cz_da7219_play_ops = {
452 .startup = cz_da7219_play_startup,
453 .shutdown = cz_da7219_shutdown,
456 static const struct snd_soc_ops cz_da7219_cap_ops = {
457 .startup = cz_da7219_cap_startup,
458 .shutdown = cz_da7219_shutdown,
461 static const struct snd_soc_ops cz_max_play_ops = {
462 .startup = cz_max_startup,
463 .shutdown = cz_da7219_shutdown,
466 static const struct snd_soc_ops cz_dmic0_cap_ops = {
467 .startup = cz_dmic0_startup,
468 .shutdown = cz_da7219_shutdown,
471 static const struct snd_soc_ops cz_dmic1_cap_ops = {
472 .startup = cz_dmic1_startup,
473 .shutdown = cz_da7219_shutdown,
476 static const struct snd_soc_ops cz_rt5682_play_ops = {
477 .startup = cz_rt5682_play_startup,
478 .shutdown = cz_rt5682_shutdown,
481 static const struct snd_soc_ops cz_rt5682_cap_ops = {
482 .startup = cz_rt5682_cap_startup,
483 .shutdown = cz_rt5682_shutdown,
486 static const struct snd_soc_ops cz_rt5682_max_play_ops = {
487 .startup = cz_rt5682_max_startup,
488 .shutdown = cz_rt5682_shutdown,
491 static const struct snd_soc_ops cz_rt5682_dmic0_cap_ops = {
492 .startup = cz_rt5682_dmic0_startup,
493 .shutdown = cz_rt5682_shutdown,
496 static const struct snd_soc_ops cz_rt5682_dmic1_cap_ops = {
497 .startup = cz_rt5682_dmic1_startup,
498 .shutdown = cz_rt5682_shutdown,
501 SND_SOC_DAILINK_DEF(designware1,
502 DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.1.auto")));
503 SND_SOC_DAILINK_DEF(designware2,
504 DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.2.auto")));
505 SND_SOC_DAILINK_DEF(designware3,
506 DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.3.auto")));
508 SND_SOC_DAILINK_DEF(dlgs,
509 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-DLGS7219:00", "da7219-hifi")));
510 SND_SOC_DAILINK_DEF(rt5682,
511 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5682:00", "rt5682-aif1")));
512 SND_SOC_DAILINK_DEF(mx,
513 DAILINK_COMP_ARRAY(COMP_CODEC("MX98357A:00", "HiFi")));
514 SND_SOC_DAILINK_DEF(adau,
515 DAILINK_COMP_ARRAY(COMP_CODEC("ADAU7002:00", "adau7002-hifi")));
517 SND_SOC_DAILINK_DEF(platform,
518 DAILINK_COMP_ARRAY(COMP_PLATFORM("acp_audio_dma.0.auto")));
520 static struct snd_soc_dai_link cz_dai_7219_98357[] = {
522 .name = "amd-da7219-play",
523 .stream_name = "Playback",
524 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
525 | SND_SOC_DAIFMT_CBP_CFP,
526 .init = cz_da7219_init,
529 .ops = &cz_da7219_play_ops,
530 SND_SOC_DAILINK_REG(designware1, dlgs, platform),
533 .name = "amd-da7219-cap",
534 .stream_name = "Capture",
535 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
536 | SND_SOC_DAIFMT_CBP_CFP,
539 .ops = &cz_da7219_cap_ops,
540 SND_SOC_DAILINK_REG(designware2, dlgs, platform),
543 .name = "amd-max98357-play",
544 .stream_name = "HiFi Playback",
545 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
546 | SND_SOC_DAIFMT_CBP_CFP,
549 .ops = &cz_max_play_ops,
550 SND_SOC_DAILINK_REG(designware3, mx, platform),
555 .stream_name = "DMIC0 Capture",
556 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
557 | SND_SOC_DAIFMT_CBP_CFP,
560 .ops = &cz_dmic0_cap_ops,
561 SND_SOC_DAILINK_REG(designware3, adau, platform),
566 .stream_name = "DMIC1 Capture",
567 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
568 | SND_SOC_DAIFMT_CBP_CFP,
571 .ops = &cz_dmic1_cap_ops,
572 SND_SOC_DAILINK_REG(designware2, adau, platform),
576 static struct snd_soc_dai_link cz_dai_5682_98357[] = {
578 .name = "amd-rt5682-play",
579 .stream_name = "Playback",
580 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
581 | SND_SOC_DAIFMT_CBP_CFP,
582 .init = cz_rt5682_init,
585 .ops = &cz_rt5682_play_ops,
586 SND_SOC_DAILINK_REG(designware1, rt5682, platform),
589 .name = "amd-rt5682-cap",
590 .stream_name = "Capture",
591 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
592 | SND_SOC_DAIFMT_CBP_CFP,
595 .ops = &cz_rt5682_cap_ops,
596 SND_SOC_DAILINK_REG(designware2, rt5682, platform),
599 .name = "amd-max98357-play",
600 .stream_name = "HiFi Playback",
601 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
602 | SND_SOC_DAIFMT_CBP_CFP,
605 .ops = &cz_rt5682_max_play_ops,
606 SND_SOC_DAILINK_REG(designware3, mx, platform),
611 .stream_name = "DMIC0 Capture",
612 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
613 | SND_SOC_DAIFMT_CBP_CFP,
616 .ops = &cz_rt5682_dmic0_cap_ops,
617 SND_SOC_DAILINK_REG(designware3, adau, platform),
622 .stream_name = "DMIC1 Capture",
623 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
624 | SND_SOC_DAIFMT_CBP_CFP,
627 .ops = &cz_rt5682_dmic1_cap_ops,
628 SND_SOC_DAILINK_REG(designware2, adau, platform),
632 static const struct snd_soc_dapm_widget cz_widgets[] = {
633 SND_SOC_DAPM_HP("Headphones", NULL),
634 SND_SOC_DAPM_SPK("Speakers", NULL),
635 SND_SOC_DAPM_MIC("Headset Mic", NULL),
636 SND_SOC_DAPM_MIC("Int Mic", NULL),
639 static const struct snd_soc_dapm_route cz_audio_route[] = {
640 {"Headphones", NULL, "HPL"},
641 {"Headphones", NULL, "HPR"},
642 {"MIC", NULL, "Headset Mic"},
643 {"Speakers", NULL, "Speaker"},
644 {"PDM_DAT", NULL, "Int Mic"},
647 static const struct snd_soc_dapm_route cz_rt5682_audio_route[] = {
648 {"Headphones", NULL, "HPOL"},
649 {"Headphones", NULL, "HPOR"},
650 {"IN1P", NULL, "Headset Mic"},
651 {"Speakers", NULL, "Speaker"},
652 {"PDM_DAT", NULL, "Int Mic"},
655 static const struct snd_kcontrol_new cz_mc_controls[] = {
656 SOC_DAPM_PIN_SWITCH("Headphones"),
657 SOC_DAPM_PIN_SWITCH("Speakers"),
658 SOC_DAPM_PIN_SWITCH("Headset Mic"),
659 SOC_DAPM_PIN_SWITCH("Int Mic"),
662 static struct snd_soc_card cz_card = {
663 .name = "acpd7219m98357",
664 .owner = THIS_MODULE,
665 .dai_link = cz_dai_7219_98357,
666 .num_links = ARRAY_SIZE(cz_dai_7219_98357),
667 .dapm_widgets = cz_widgets,
668 .num_dapm_widgets = ARRAY_SIZE(cz_widgets),
669 .dapm_routes = cz_audio_route,
670 .num_dapm_routes = ARRAY_SIZE(cz_audio_route),
671 .controls = cz_mc_controls,
672 .num_controls = ARRAY_SIZE(cz_mc_controls),
675 static struct snd_soc_card cz_rt5682_card = {
676 .name = "acpr5682m98357",
677 .owner = THIS_MODULE,
678 .dai_link = cz_dai_5682_98357,
679 .num_links = ARRAY_SIZE(cz_dai_5682_98357),
680 .dapm_widgets = cz_widgets,
681 .num_dapm_widgets = ARRAY_SIZE(cz_widgets),
682 .dapm_routes = cz_rt5682_audio_route,
683 .controls = cz_mc_controls,
684 .num_controls = ARRAY_SIZE(cz_mc_controls),
687 void *acp_soc_is_rltk_max(struct device *dev)
689 const struct acpi_device_id *match;
691 match = acpi_match_device(dev->driver->acpi_match_table, dev);
694 return (void *)match->driver_data;
697 static struct regulator_consumer_supply acp_da7219_supplies[] = {
698 REGULATOR_SUPPLY("VDD", "i2c-DLGS7219:00"),
699 REGULATOR_SUPPLY("VDDMIC", "i2c-DLGS7219:00"),
700 REGULATOR_SUPPLY("VDDIO", "i2c-DLGS7219:00"),
701 REGULATOR_SUPPLY("IOVDD", "ADAU7002:00"),
704 static struct regulator_init_data acp_da7219_data = {
708 .num_consumer_supplies = ARRAY_SIZE(acp_da7219_supplies),
709 .consumer_supplies = acp_da7219_supplies,
712 static struct regulator_config acp_da7219_cfg = {
713 .init_data = &acp_da7219_data,
716 static struct regulator_ops acp_da7219_ops = {
719 static const struct regulator_desc acp_da7219_desc = {
720 .name = "reg-fixed-1.8V",
721 .type = REGULATOR_VOLTAGE,
722 .owner = THIS_MODULE,
723 .ops = &acp_da7219_ops,
724 .fixed_uV = 1800000, /* 1.8V */
728 static int cz_probe(struct platform_device *pdev)
731 struct snd_soc_card *card;
732 struct acp_platform_info *machine;
733 struct regulator_dev *rdev;
734 struct device *dev = &pdev->dev;
736 card = (struct snd_soc_card *)acp_soc_is_rltk_max(dev);
739 if (!strcmp(card->name, "acpd7219m98357")) {
740 acp_da7219_cfg.dev = &pdev->dev;
741 rdev = devm_regulator_register(&pdev->dev, &acp_da7219_desc,
744 dev_err(&pdev->dev, "Failed to register regulator: %d\n",
750 machine = devm_kzalloc(&pdev->dev, sizeof(struct acp_platform_info),
754 card->dev = &pdev->dev;
755 platform_set_drvdata(pdev, card);
756 snd_soc_card_set_drvdata(card, machine);
757 ret = devm_snd_soc_register_card(&pdev->dev, card);
759 return dev_err_probe(&pdev->dev, ret,
760 "devm_snd_soc_register_card(%s) failed\n",
763 acp_bt_uart_enable = !device_property_read_bool(&pdev->dev,
769 static const struct acpi_device_id cz_audio_acpi_match[] = {
770 { "AMD7219", (unsigned long)&cz_card },
771 { "AMDI5682", (unsigned long)&cz_rt5682_card},
774 MODULE_DEVICE_TABLE(acpi, cz_audio_acpi_match);
777 static struct platform_driver cz_pcm_driver = {
779 .name = "cz-da7219-max98357a",
780 .acpi_match_table = ACPI_PTR(cz_audio_acpi_match),
781 .pm = &snd_soc_pm_ops,
786 module_platform_driver(cz_pcm_driver);
788 MODULE_AUTHOR("akshu.agrawal@amd.com");
789 MODULE_AUTHOR("Vijendar.Mukunda@amd.com");
790 MODULE_DESCRIPTION("DA7219, RT5682 & MAX98357A audio support");
791 MODULE_LICENSE("GPL v2");