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/rt5682.h"
26 #define CZ_PLAT_CLK 48000000
27 #define DUAL_CHANNEL 2
28 #define RT5682_PLL_FREQ (48000 * 512)
30 static struct snd_soc_jack cz_jack
;
31 static struct snd_soc_jack_pin cz_jack_pins
[] = {
33 .pin
= "Headphone Jack",
34 .mask
= SND_JACK_HEADPHONE
,
38 .mask
= SND_JACK_MICROPHONE
,
42 .mask
= SND_JACK_LINEOUT
,
46 static struct clk
*da7219_dai_wclk
;
47 static struct clk
*da7219_dai_bclk
;
48 static struct clk
*rt5682_dai_wclk
;
49 static struct clk
*rt5682_dai_bclk
;
51 void *acp_soc_is_rltk_max(struct device
*dev
);
53 static int cz_da7219_init(struct snd_soc_pcm_runtime
*rtd
)
56 struct snd_soc_card
*card
= rtd
->card
;
57 struct snd_soc_dai
*codec_dai
= snd_soc_rtd_to_codec(rtd
, 0);
58 struct snd_soc_component
*component
= codec_dai
->component
;
60 dev_info(rtd
->dev
, "codec dai name = %s\n", codec_dai
->name
);
62 ret
= snd_soc_dai_set_sysclk(codec_dai
, DA7219_CLKSRC_MCLK
,
63 CZ_PLAT_CLK
, SND_SOC_CLOCK_IN
);
65 dev_err(rtd
->dev
, "can't set codec sysclk: %d\n", ret
);
69 ret
= snd_soc_dai_set_pll(codec_dai
, 0, DA7219_SYSCLK_PLL
,
70 CZ_PLAT_CLK
, DA7219_PLL_FREQ_OUT_98304
);
72 dev_err(rtd
->dev
, "can't set codec pll: %d\n", ret
);
76 da7219_dai_wclk
= devm_clk_get(component
->dev
, "da7219-dai-wclk");
77 if (IS_ERR(da7219_dai_wclk
))
78 return PTR_ERR(da7219_dai_wclk
);
80 da7219_dai_bclk
= devm_clk_get(component
->dev
, "da7219-dai-bclk");
81 if (IS_ERR(da7219_dai_bclk
))
82 return PTR_ERR(da7219_dai_bclk
);
84 ret
= snd_soc_card_jack_new_pins(card
, "Headset Jack",
85 SND_JACK_HEADSET
| SND_JACK_LINEOUT
|
86 SND_JACK_BTN_0
| SND_JACK_BTN_1
|
87 SND_JACK_BTN_2
| SND_JACK_BTN_3
,
90 ARRAY_SIZE(cz_jack_pins
));
92 dev_err(card
->dev
, "HP jack creation failed %d\n", ret
);
96 snd_jack_set_key(cz_jack
.jack
, SND_JACK_BTN_0
, KEY_PLAYPAUSE
);
97 snd_jack_set_key(cz_jack
.jack
, SND_JACK_BTN_1
, KEY_VOLUMEUP
);
98 snd_jack_set_key(cz_jack
.jack
, SND_JACK_BTN_2
, KEY_VOLUMEDOWN
);
99 snd_jack_set_key(cz_jack
.jack
, SND_JACK_BTN_3
, KEY_VOICECOMMAND
);
101 snd_soc_component_set_jack(component
, &cz_jack
, NULL
);
106 static int da7219_clk_enable(struct snd_pcm_substream
*substream
)
109 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
112 * Set wclk to 48000 because the rate constraint of this driver is
113 * 48000. ADAU7002 spec: "The ADAU7002 requires a BCLK rate that is
114 * minimum of 64x the LRCLK sample rate." DA7219 is the only clk
115 * source so for all codecs we have to limit bclk to 64X lrclk.
117 clk_set_rate(da7219_dai_wclk
, 48000);
118 clk_set_rate(da7219_dai_bclk
, 48000 * 64);
119 ret
= clk_prepare_enable(da7219_dai_bclk
);
121 dev_err(rtd
->dev
, "can't enable master clock %d\n", ret
);
128 static void da7219_clk_disable(void)
130 clk_disable_unprepare(da7219_dai_bclk
);
133 static int cz_rt5682_init(struct snd_soc_pcm_runtime
*rtd
)
136 struct snd_soc_card
*card
= rtd
->card
;
137 struct snd_soc_dai
*codec_dai
= snd_soc_rtd_to_codec(rtd
, 0);
138 struct snd_soc_component
*component
= codec_dai
->component
;
140 dev_info(codec_dai
->dev
, "codec dai name = %s\n", codec_dai
->name
);
142 /* Set codec sysclk */
143 ret
= snd_soc_dai_set_sysclk(codec_dai
, RT5682_SCLK_S_PLL2
,
144 RT5682_PLL_FREQ
, SND_SOC_CLOCK_IN
);
146 dev_err(codec_dai
->dev
,
147 "Failed to set rt5682 SYSCLK: %d\n", ret
);
151 ret
= snd_soc_dai_set_pll(codec_dai
, RT5682_PLL2
, RT5682_PLL2_S_MCLK
,
152 CZ_PLAT_CLK
, RT5682_PLL_FREQ
);
154 dev_err(codec_dai
->dev
, "can't set rt5682 PLL: %d\n", ret
);
158 rt5682_dai_wclk
= devm_clk_get(component
->dev
, "rt5682-dai-wclk");
159 if (IS_ERR(rt5682_dai_wclk
))
160 return PTR_ERR(rt5682_dai_wclk
);
162 rt5682_dai_bclk
= devm_clk_get(component
->dev
, "rt5682-dai-bclk");
163 if (IS_ERR(rt5682_dai_bclk
))
164 return PTR_ERR(rt5682_dai_bclk
);
166 ret
= snd_soc_card_jack_new_pins(card
, "Headset Jack",
167 SND_JACK_HEADSET
| SND_JACK_LINEOUT
|
168 SND_JACK_BTN_0
| SND_JACK_BTN_1
|
169 SND_JACK_BTN_2
| SND_JACK_BTN_3
,
172 ARRAY_SIZE(cz_jack_pins
));
174 dev_err(card
->dev
, "HP jack creation failed %d\n", ret
);
178 snd_jack_set_key(cz_jack
.jack
, SND_JACK_BTN_0
, KEY_PLAYPAUSE
);
179 snd_jack_set_key(cz_jack
.jack
, SND_JACK_BTN_1
, KEY_VOLUMEUP
);
180 snd_jack_set_key(cz_jack
.jack
, SND_JACK_BTN_2
, KEY_VOLUMEDOWN
);
181 snd_jack_set_key(cz_jack
.jack
, SND_JACK_BTN_3
, KEY_VOICECOMMAND
);
183 ret
= snd_soc_component_set_jack(component
, &cz_jack
, NULL
);
185 dev_err(rtd
->dev
, "Headset Jack call-back failed: %d\n", ret
);
191 static int rt5682_clk_enable(struct snd_pcm_substream
*substream
)
194 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
197 * Set wclk to 48000 because the rate constraint of this driver is
198 * 48000. ADAU7002 spec: "The ADAU7002 requires a BCLK rate that is
199 * minimum of 64x the LRCLK sample rate." RT5682 is the only clk
200 * source so for all codecs we have to limit bclk to 64X lrclk.
202 ret
= clk_set_rate(rt5682_dai_wclk
, 48000);
204 dev_err(rtd
->dev
, "Error setting wclk rate: %d\n", ret
);
207 ret
= clk_set_rate(rt5682_dai_bclk
, 48000 * 64);
209 dev_err(rtd
->dev
, "Error setting bclk rate: %d\n", ret
);
212 ret
= clk_prepare_enable(rt5682_dai_wclk
);
214 dev_err(rtd
->dev
, "can't enable wclk %d\n", ret
);
220 static void rt5682_clk_disable(void)
222 clk_disable_unprepare(rt5682_dai_wclk
);
225 static const unsigned int channels
[] = {
229 static const unsigned int rates
[] = {
233 static const struct snd_pcm_hw_constraint_list constraints_rates
= {
234 .count
= ARRAY_SIZE(rates
),
239 static const struct snd_pcm_hw_constraint_list constraints_channels
= {
240 .count
= ARRAY_SIZE(channels
),
245 static int cz_da7219_play_startup(struct snd_pcm_substream
*substream
)
247 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
248 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
249 struct snd_soc_card
*card
= rtd
->card
;
250 struct acp_platform_info
*machine
= snd_soc_card_get_drvdata(card
);
253 * On this platform for PCM device we support stereo
256 runtime
->hw
.channels_max
= DUAL_CHANNEL
;
257 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
258 &constraints_channels
);
259 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
262 machine
->play_i2s_instance
= I2S_SP_INSTANCE
;
263 return da7219_clk_enable(substream
);
266 static int cz_da7219_cap_startup(struct snd_pcm_substream
*substream
)
268 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
269 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
270 struct snd_soc_card
*card
= rtd
->card
;
271 struct acp_platform_info
*machine
= snd_soc_card_get_drvdata(card
);
274 * On this platform for PCM device we support stereo
277 runtime
->hw
.channels_max
= DUAL_CHANNEL
;
278 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
279 &constraints_channels
);
280 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
283 machine
->cap_i2s_instance
= I2S_SP_INSTANCE
;
284 machine
->capture_channel
= CAP_CHANNEL1
;
285 return da7219_clk_enable(substream
);
288 static int cz_max_startup(struct snd_pcm_substream
*substream
)
290 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
291 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
292 struct snd_soc_card
*card
= rtd
->card
;
293 struct acp_platform_info
*machine
= snd_soc_card_get_drvdata(card
);
296 * On this platform for PCM device we support stereo
299 runtime
->hw
.channels_max
= DUAL_CHANNEL
;
300 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
301 &constraints_channels
);
302 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
305 machine
->play_i2s_instance
= I2S_BT_INSTANCE
;
306 return da7219_clk_enable(substream
);
309 static int cz_dmic0_startup(struct snd_pcm_substream
*substream
)
311 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
312 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
313 struct snd_soc_card
*card
= rtd
->card
;
314 struct acp_platform_info
*machine
= snd_soc_card_get_drvdata(card
);
317 * On this platform for PCM device we support stereo
320 runtime
->hw
.channels_max
= DUAL_CHANNEL
;
321 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
322 &constraints_channels
);
323 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
326 machine
->cap_i2s_instance
= I2S_BT_INSTANCE
;
327 return da7219_clk_enable(substream
);
330 static int cz_dmic1_startup(struct snd_pcm_substream
*substream
)
332 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
333 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
334 struct snd_soc_card
*card
= rtd
->card
;
335 struct acp_platform_info
*machine
= snd_soc_card_get_drvdata(card
);
338 * On this platform for PCM device we support stereo
341 runtime
->hw
.channels_max
= DUAL_CHANNEL
;
342 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
343 &constraints_channels
);
344 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
347 machine
->cap_i2s_instance
= I2S_SP_INSTANCE
;
348 machine
->capture_channel
= CAP_CHANNEL0
;
349 return da7219_clk_enable(substream
);
352 static void cz_da7219_shutdown(struct snd_pcm_substream
*substream
)
354 da7219_clk_disable();
357 static int cz_rt5682_play_startup(struct snd_pcm_substream
*substream
)
359 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
360 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
361 struct snd_soc_card
*card
= rtd
->card
;
362 struct acp_platform_info
*machine
= snd_soc_card_get_drvdata(card
);
365 * On this platform for PCM device we support stereo
368 runtime
->hw
.channels_max
= DUAL_CHANNEL
;
369 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
370 &constraints_channels
);
371 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
374 machine
->play_i2s_instance
= I2S_SP_INSTANCE
;
375 return rt5682_clk_enable(substream
);
378 static int cz_rt5682_cap_startup(struct snd_pcm_substream
*substream
)
380 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
381 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
382 struct snd_soc_card
*card
= rtd
->card
;
383 struct acp_platform_info
*machine
= snd_soc_card_get_drvdata(card
);
386 * On this platform for PCM device we support stereo
389 runtime
->hw
.channels_max
= DUAL_CHANNEL
;
390 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
391 &constraints_channels
);
392 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
395 machine
->cap_i2s_instance
= I2S_SP_INSTANCE
;
396 machine
->capture_channel
= CAP_CHANNEL1
;
397 return rt5682_clk_enable(substream
);
400 static int cz_rt5682_max_startup(struct snd_pcm_substream
*substream
)
402 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
403 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
404 struct snd_soc_card
*card
= rtd
->card
;
405 struct acp_platform_info
*machine
= snd_soc_card_get_drvdata(card
);
408 * On this platform for PCM device we support stereo
411 runtime
->hw
.channels_max
= DUAL_CHANNEL
;
412 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
413 &constraints_channels
);
414 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
417 machine
->play_i2s_instance
= I2S_BT_INSTANCE
;
418 return rt5682_clk_enable(substream
);
421 static int cz_rt5682_dmic0_startup(struct snd_pcm_substream
*substream
)
423 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
424 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
425 struct snd_soc_card
*card
= rtd
->card
;
426 struct acp_platform_info
*machine
= snd_soc_card_get_drvdata(card
);
429 * On this platform for PCM device we support stereo
432 runtime
->hw
.channels_max
= DUAL_CHANNEL
;
433 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
434 &constraints_channels
);
435 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
438 machine
->cap_i2s_instance
= I2S_BT_INSTANCE
;
439 return rt5682_clk_enable(substream
);
442 static int cz_rt5682_dmic1_startup(struct snd_pcm_substream
*substream
)
444 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
445 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
446 struct snd_soc_card
*card
= rtd
->card
;
447 struct acp_platform_info
*machine
= snd_soc_card_get_drvdata(card
);
450 * On this platform for PCM device we support stereo
453 runtime
->hw
.channels_max
= DUAL_CHANNEL
;
454 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
455 &constraints_channels
);
456 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
459 machine
->cap_i2s_instance
= I2S_SP_INSTANCE
;
460 machine
->capture_channel
= CAP_CHANNEL0
;
461 return rt5682_clk_enable(substream
);
464 static void cz_rt5682_shutdown(struct snd_pcm_substream
*substream
)
466 rt5682_clk_disable();
469 static const struct snd_soc_ops cz_da7219_play_ops
= {
470 .startup
= cz_da7219_play_startup
,
471 .shutdown
= cz_da7219_shutdown
,
474 static const struct snd_soc_ops cz_da7219_cap_ops
= {
475 .startup
= cz_da7219_cap_startup
,
476 .shutdown
= cz_da7219_shutdown
,
479 static const struct snd_soc_ops cz_max_play_ops
= {
480 .startup
= cz_max_startup
,
481 .shutdown
= cz_da7219_shutdown
,
484 static const struct snd_soc_ops cz_dmic0_cap_ops
= {
485 .startup
= cz_dmic0_startup
,
486 .shutdown
= cz_da7219_shutdown
,
489 static const struct snd_soc_ops cz_dmic1_cap_ops
= {
490 .startup
= cz_dmic1_startup
,
491 .shutdown
= cz_da7219_shutdown
,
494 static const struct snd_soc_ops cz_rt5682_play_ops
= {
495 .startup
= cz_rt5682_play_startup
,
496 .shutdown
= cz_rt5682_shutdown
,
499 static const struct snd_soc_ops cz_rt5682_cap_ops
= {
500 .startup
= cz_rt5682_cap_startup
,
501 .shutdown
= cz_rt5682_shutdown
,
504 static const struct snd_soc_ops cz_rt5682_max_play_ops
= {
505 .startup
= cz_rt5682_max_startup
,
506 .shutdown
= cz_rt5682_shutdown
,
509 static const struct snd_soc_ops cz_rt5682_dmic0_cap_ops
= {
510 .startup
= cz_rt5682_dmic0_startup
,
511 .shutdown
= cz_rt5682_shutdown
,
514 static const struct snd_soc_ops cz_rt5682_dmic1_cap_ops
= {
515 .startup
= cz_rt5682_dmic1_startup
,
516 .shutdown
= cz_rt5682_shutdown
,
519 SND_SOC_DAILINK_DEF(designware1
,
520 DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.1.auto")));
521 SND_SOC_DAILINK_DEF(designware2
,
522 DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.2.auto")));
523 SND_SOC_DAILINK_DEF(designware3
,
524 DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.3.auto")));
526 SND_SOC_DAILINK_DEF(dlgs
,
527 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-DLGS7219:00", "da7219-hifi")));
528 SND_SOC_DAILINK_DEF(rt5682
,
529 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5682:00", "rt5682-aif1")));
530 SND_SOC_DAILINK_DEF(mx
,
531 DAILINK_COMP_ARRAY(COMP_CODEC("MX98357A:00", "HiFi")));
532 SND_SOC_DAILINK_DEF(adau
,
533 DAILINK_COMP_ARRAY(COMP_CODEC("ADAU7002:00", "adau7002-hifi")));
535 SND_SOC_DAILINK_DEF(platform
,
536 DAILINK_COMP_ARRAY(COMP_PLATFORM("acp_audio_dma.0.auto")));
538 static struct snd_soc_dai_link cz_dai_7219_98357
[] = {
540 .name
= "amd-da7219-play",
541 .stream_name
= "Playback",
542 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
543 | SND_SOC_DAIFMT_CBP_CFP
,
544 .init
= cz_da7219_init
,
546 .trigger_stop
= SND_SOC_TRIGGER_ORDER_LDC
,
547 .ops
= &cz_da7219_play_ops
,
548 SND_SOC_DAILINK_REG(designware1
, dlgs
, platform
),
551 .name
= "amd-da7219-cap",
552 .stream_name
= "Capture",
553 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
554 | SND_SOC_DAIFMT_CBP_CFP
,
556 .trigger_stop
= SND_SOC_TRIGGER_ORDER_LDC
,
557 .ops
= &cz_da7219_cap_ops
,
558 SND_SOC_DAILINK_REG(designware2
, dlgs
, platform
),
561 .name
= "amd-max98357-play",
562 .stream_name
= "HiFi Playback",
563 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
564 | SND_SOC_DAIFMT_CBP_CFP
,
566 .trigger_stop
= SND_SOC_TRIGGER_ORDER_LDC
,
567 .ops
= &cz_max_play_ops
,
568 SND_SOC_DAILINK_REG(designware3
, mx
, platform
),
573 .stream_name
= "DMIC0 Capture",
574 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
575 | SND_SOC_DAIFMT_CBP_CFP
,
577 .trigger_stop
= SND_SOC_TRIGGER_ORDER_LDC
,
578 .ops
= &cz_dmic0_cap_ops
,
579 SND_SOC_DAILINK_REG(designware3
, adau
, platform
),
584 .stream_name
= "DMIC1 Capture",
585 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
586 | SND_SOC_DAIFMT_CBP_CFP
,
588 .trigger_stop
= SND_SOC_TRIGGER_ORDER_LDC
,
589 .ops
= &cz_dmic1_cap_ops
,
590 SND_SOC_DAILINK_REG(designware2
, adau
, platform
),
594 static struct snd_soc_dai_link cz_dai_5682_98357
[] = {
596 .name
= "amd-rt5682-play",
597 .stream_name
= "Playback",
598 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
599 | SND_SOC_DAIFMT_CBP_CFP
,
600 .init
= cz_rt5682_init
,
602 .trigger_stop
= SND_SOC_TRIGGER_ORDER_LDC
,
603 .ops
= &cz_rt5682_play_ops
,
604 SND_SOC_DAILINK_REG(designware1
, rt5682
, platform
),
607 .name
= "amd-rt5682-cap",
608 .stream_name
= "Capture",
609 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
610 | SND_SOC_DAIFMT_CBP_CFP
,
612 .trigger_stop
= SND_SOC_TRIGGER_ORDER_LDC
,
613 .ops
= &cz_rt5682_cap_ops
,
614 SND_SOC_DAILINK_REG(designware2
, rt5682
, platform
),
617 .name
= "amd-max98357-play",
618 .stream_name
= "HiFi Playback",
619 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
620 | SND_SOC_DAIFMT_CBP_CFP
,
622 .trigger_stop
= SND_SOC_TRIGGER_ORDER_LDC
,
623 .ops
= &cz_rt5682_max_play_ops
,
624 SND_SOC_DAILINK_REG(designware3
, mx
, platform
),
629 .stream_name
= "DMIC0 Capture",
630 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
631 | SND_SOC_DAIFMT_CBP_CFP
,
633 .trigger_stop
= SND_SOC_TRIGGER_ORDER_LDC
,
634 .ops
= &cz_rt5682_dmic0_cap_ops
,
635 SND_SOC_DAILINK_REG(designware3
, adau
, platform
),
640 .stream_name
= "DMIC1 Capture",
641 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
642 | SND_SOC_DAIFMT_CBP_CFP
,
644 .trigger_stop
= SND_SOC_TRIGGER_ORDER_LDC
,
645 .ops
= &cz_rt5682_dmic1_cap_ops
,
646 SND_SOC_DAILINK_REG(designware2
, adau
, platform
),
650 static const struct snd_soc_dapm_widget cz_widgets
[] = {
651 SND_SOC_DAPM_HP("Headphones", NULL
),
652 SND_SOC_DAPM_SPK("Speakers", NULL
),
653 SND_SOC_DAPM_LINE("Line Out", NULL
),
654 SND_SOC_DAPM_MIC("Headset Mic", NULL
),
655 SND_SOC_DAPM_MIC("Int Mic", NULL
),
658 static const struct snd_soc_dapm_route cz_audio_route
[] = {
659 {"Headphones", NULL
, "HPL"},
660 {"Headphones", NULL
, "HPR"},
661 {"MIC", NULL
, "Headset Mic"},
662 {"Speakers", NULL
, "Speaker"},
663 {"PDM_DAT", NULL
, "Int Mic"},
666 static const struct snd_soc_dapm_route cz_rt5682_audio_route
[] = {
667 {"Headphones", NULL
, "HPOL"},
668 {"Headphones", NULL
, "HPOR"},
669 {"IN1P", NULL
, "Headset Mic"},
670 {"Speakers", NULL
, "Speaker"},
671 {"PDM_DAT", NULL
, "Int Mic"},
674 static const struct snd_kcontrol_new cz_mc_controls
[] = {
675 SOC_DAPM_PIN_SWITCH("Headphones"),
676 SOC_DAPM_PIN_SWITCH("Speakers"),
677 SOC_DAPM_PIN_SWITCH("Line Out"),
678 SOC_DAPM_PIN_SWITCH("Headset Mic"),
679 SOC_DAPM_PIN_SWITCH("Int Mic"),
682 static struct snd_soc_card cz_card
= {
683 .name
= "acpd7219m98357",
684 .owner
= THIS_MODULE
,
685 .dai_link
= cz_dai_7219_98357
,
686 .num_links
= ARRAY_SIZE(cz_dai_7219_98357
),
687 .dapm_widgets
= cz_widgets
,
688 .num_dapm_widgets
= ARRAY_SIZE(cz_widgets
),
689 .dapm_routes
= cz_audio_route
,
690 .num_dapm_routes
= ARRAY_SIZE(cz_audio_route
),
691 .controls
= cz_mc_controls
,
692 .num_controls
= ARRAY_SIZE(cz_mc_controls
),
695 static struct snd_soc_card cz_rt5682_card
= {
696 .name
= "acpr5682m98357",
697 .owner
= THIS_MODULE
,
698 .dai_link
= cz_dai_5682_98357
,
699 .num_links
= ARRAY_SIZE(cz_dai_5682_98357
),
700 .dapm_widgets
= cz_widgets
,
701 .num_dapm_widgets
= ARRAY_SIZE(cz_widgets
),
702 .dapm_routes
= cz_rt5682_audio_route
,
703 .controls
= cz_mc_controls
,
704 .num_controls
= ARRAY_SIZE(cz_mc_controls
),
707 void *acp_soc_is_rltk_max(struct device
*dev
)
709 const struct acpi_device_id
*match
;
711 match
= acpi_match_device(dev
->driver
->acpi_match_table
, dev
);
714 return (void *)match
->driver_data
;
717 static struct regulator_consumer_supply acp_da7219_supplies
[] = {
718 REGULATOR_SUPPLY("VDD", "i2c-DLGS7219:00"),
719 REGULATOR_SUPPLY("VDDMIC", "i2c-DLGS7219:00"),
720 REGULATOR_SUPPLY("VDDIO", "i2c-DLGS7219:00"),
721 REGULATOR_SUPPLY("IOVDD", "ADAU7002:00"),
724 static struct regulator_init_data acp_da7219_data
= {
728 .num_consumer_supplies
= ARRAY_SIZE(acp_da7219_supplies
),
729 .consumer_supplies
= acp_da7219_supplies
,
732 static struct regulator_config acp_da7219_cfg
= {
733 .init_data
= &acp_da7219_data
,
736 static const struct regulator_ops acp_da7219_ops
= {
739 static const struct regulator_desc acp_da7219_desc
= {
740 .name
= "reg-fixed-1.8V",
741 .type
= REGULATOR_VOLTAGE
,
742 .owner
= THIS_MODULE
,
743 .ops
= &acp_da7219_ops
,
744 .fixed_uV
= 1800000, /* 1.8V */
748 static int cz_probe(struct platform_device
*pdev
)
751 struct snd_soc_card
*card
;
752 struct acp_platform_info
*machine
;
753 struct regulator_dev
*rdev
;
754 struct device
*dev
= &pdev
->dev
;
756 card
= (struct snd_soc_card
*)acp_soc_is_rltk_max(dev
);
759 if (!strcmp(card
->name
, "acpd7219m98357")) {
760 acp_da7219_cfg
.dev
= &pdev
->dev
;
761 rdev
= devm_regulator_register(&pdev
->dev
, &acp_da7219_desc
,
764 dev_err(&pdev
->dev
, "Failed to register regulator: %d\n",
770 machine
= devm_kzalloc(&pdev
->dev
, sizeof(struct acp_platform_info
),
774 card
->dev
= &pdev
->dev
;
775 platform_set_drvdata(pdev
, card
);
776 snd_soc_card_set_drvdata(card
, machine
);
777 ret
= devm_snd_soc_register_card(&pdev
->dev
, card
);
779 return dev_err_probe(&pdev
->dev
, ret
,
780 "devm_snd_soc_register_card(%s) failed\n",
783 acp_bt_uart_enable
= !device_property_read_bool(&pdev
->dev
,
789 static const struct acpi_device_id cz_audio_acpi_match
[] = {
790 { "AMD7219", (unsigned long)&cz_card
},
791 { "AMDI5682", (unsigned long)&cz_rt5682_card
},
794 MODULE_DEVICE_TABLE(acpi
, cz_audio_acpi_match
);
797 static struct platform_driver cz_pcm_driver
= {
799 .name
= "cz-da7219-max98357a",
800 .acpi_match_table
= ACPI_PTR(cz_audio_acpi_match
),
801 .pm
= &snd_soc_pm_ops
,
806 module_platform_driver(cz_pcm_driver
);
808 MODULE_AUTHOR("akshu.agrawal@amd.com");
809 MODULE_AUTHOR("Vijendar.Mukunda@amd.com");
810 MODULE_DESCRIPTION("DA7219, RT5682 & MAX98357A audio support");
811 MODULE_LICENSE("GPL v2");