1 // SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
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.
6 // Copyright(c) 2021, 2023 Advanced Micro Devices, Inc.
8 // Authors: Ajit Kumar Pandey <AjitKumar.Pandey@amd.com>
9 // Vijendar Mukunda <Vijendar.Mukunda@amd.com>
13 * Machine Driver Interface for ACP HW block
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>
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"
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"
40 #define TDM_MODE_ENABLE 1
42 const struct dmi_system_id acp_quirk_table
[] = {
44 /* Google skyrim proto-0 */
46 DMI_EXACT_MATCH(DMI_PRODUCT_FAMILY
, "Google_Skyrim"),
48 .driver_data
= (void *)TDM_MODE_ENABLE
,
52 EXPORT_SYMBOL_GPL(acp_quirk_table
);
54 static const unsigned int channels
[] = {
58 static const unsigned int rates
[] = {
62 static const struct snd_pcm_hw_constraint_list constraints_rates
= {
63 .count
= ARRAY_SIZE(rates
),
68 static const struct snd_pcm_hw_constraint_list constraints_channels
= {
69 .count
= ARRAY_SIZE(channels
),
74 static int acp_clk_enable(struct acp_card_drvdata
*drvdata
,
75 unsigned int srate
, unsigned int bclk_ratio
)
77 clk_set_rate(drvdata
->wclk
, srate
);
78 clk_set_rate(drvdata
->bclk
, srate
* bclk_ratio
);
80 return clk_prepare_enable(drvdata
->wclk
);
83 /* Declare RT5682 codec components */
84 SND_SOC_DAILINK_DEF(rt5682
,
85 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5682:00", "rt5682-aif1")));
87 static struct snd_soc_jack rt5682_jack
;
88 static struct snd_soc_jack_pin rt5682_jack_pins
[] = {
90 .pin
= "Headphone Jack",
91 .mask
= SND_JACK_HEADPHONE
,
95 .mask
= SND_JACK_MICROPHONE
,
99 static const struct snd_kcontrol_new rt5682_controls
[] = {
100 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
101 SOC_DAPM_PIN_SWITCH("Headset Mic"),
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
),
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" },
115 /* Define card ops for RT5682 CODEC */
116 static int acp_card_rt5682_init(struct snd_soc_pcm_runtime
*rtd
)
118 struct snd_soc_card
*card
= rtd
->card
;
119 struct acp_card_drvdata
*drvdata
= card
->drvdata
;
120 struct snd_soc_dai
*codec_dai
= snd_soc_rtd_to_codec(rtd
, 0);
121 struct snd_soc_component
*component
= codec_dai
->component
;
124 dev_info(rtd
->dev
, "codec dai name = %s\n", codec_dai
->name
);
126 if (drvdata
->hs_codec_id
!= RT5682
)
129 drvdata
->wclk
= clk_get(component
->dev
, "rt5682-dai-wclk");
130 drvdata
->bclk
= clk_get(component
->dev
, "rt5682-dai-bclk");
132 ret
= snd_soc_dapm_new_controls(&card
->dapm
, rt5682_widgets
,
133 ARRAY_SIZE(rt5682_widgets
));
135 dev_err(rtd
->dev
, "unable to add widget dapm controls, ret %d\n", ret
);
139 ret
= snd_soc_add_card_controls(card
, rt5682_controls
,
140 ARRAY_SIZE(rt5682_controls
));
142 dev_err(rtd
->dev
, "unable to add card controls, ret %d\n", ret
);
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
,
152 ARRAY_SIZE(rt5682_jack_pins
));
154 dev_err(card
->dev
, "HP jack creation failed %d\n", ret
);
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
);
163 ret
= snd_soc_component_set_jack(component
, &rt5682_jack
, NULL
);
165 dev_err(rtd
->dev
, "Headset Jack call-back failed: %d\n", ret
);
169 return snd_soc_dapm_add_routes(&rtd
->card
->dapm
, rt5682_map
, ARRAY_SIZE(rt5682_map
));
172 static int acp_card_hs_startup(struct snd_pcm_substream
*substream
)
174 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
175 struct snd_soc_pcm_runtime
*rtd
= snd_soc_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
= snd_soc_rtd_to_codec(rtd
, 0);
182 if (drvdata
->tdm_mode
)
183 fmt
= SND_SOC_DAIFMT_DSP_A
;
185 fmt
= SND_SOC_DAIFMT_I2S
;
187 if (drvdata
->soc_mclk
)
188 fmt
|= SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBC_CFC
;
190 fmt
|= SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBP_CFP
;
192 ret
= snd_soc_dai_set_fmt(codec_dai
, fmt
);
194 dev_err(rtd
->card
->dev
, "Failed to set dai fmt: %d\n", ret
);
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
,
207 static void acp_card_shutdown(struct snd_pcm_substream
*substream
)
209 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
210 struct snd_soc_card
*card
= rtd
->card
;
211 struct acp_card_drvdata
*drvdata
= card
->drvdata
;
213 if (!drvdata
->soc_mclk
)
214 clk_disable_unprepare(drvdata
->wclk
);
217 static int acp_card_rt5682_hw_params(struct snd_pcm_substream
*substream
,
218 struct snd_pcm_hw_params
*params
)
220 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
221 struct snd_soc_card
*card
= rtd
->card
;
222 struct acp_card_drvdata
*drvdata
= card
->drvdata
;
223 struct snd_soc_dai
*codec_dai
= snd_soc_rtd_to_codec(rtd
, 0);
224 struct snd_soc_dai
*cpu_dai
= snd_soc_rtd_to_cpu(rtd
, 0);
226 unsigned int fmt
, srate
, ch
, format
;
228 srate
= params_rate(params
);
229 ch
= params_channels(params
);
230 format
= params_physical_width(params
);
232 if (drvdata
->tdm_mode
)
233 fmt
= SND_SOC_DAIFMT_DSP_A
;
235 fmt
= SND_SOC_DAIFMT_I2S
;
237 if (drvdata
->soc_mclk
)
238 fmt
|= SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBC_CFC
;
240 fmt
|= SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBP_CFP
;
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
);
248 ret
= snd_soc_dai_set_fmt(codec_dai
, fmt
);
250 dev_err(rtd
->card
->dev
, "Failed to set dai fmt: %d\n", ret
);
254 if (drvdata
->tdm_mode
) {
256 * As codec supports slot 0 and slot 1 for playback and capture.
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
);
264 ret
= snd_soc_dai_set_tdm_slot(codec_dai
, 0x3, 0x3, 8, 16);
266 dev_warn(rtd
->dev
, "set TDM slot err:%d\n", ret
);
271 ret
= snd_soc_dai_set_pll(codec_dai
, RT5682_PLL2
, RT5682_PLL2_S_MCLK
,
272 PCO_PLAT_CLK
, RT5682_PLL_FREQ
);
274 dev_err(rtd
->dev
, "Failed to set codec PLL: %d\n", ret
);
278 ret
= snd_soc_dai_set_sysclk(codec_dai
, RT5682_SCLK_S_PLL2
,
279 RT5682_PLL_FREQ
, SND_SOC_CLOCK_IN
);
281 dev_err(rtd
->dev
, "Failed to set codec SYSCLK: %d\n", ret
);
285 if (drvdata
->tdm_mode
) {
286 ret
= snd_soc_dai_set_pll(codec_dai
, RT5682S_PLL1
, RT5682S_PLL_S_BCLK1
,
289 dev_err(rtd
->dev
, "Failed to set codec PLL: %d\n", ret
);
293 ret
= snd_soc_dai_set_sysclk(codec_dai
, RT5682S_SCLK_S_PLL1
,
294 49152000, SND_SOC_CLOCK_IN
);
296 dev_err(rtd
->dev
, "Failed to set codec SYSCLK: %d\n", ret
);
301 /* Set tdm/i2s1 master bclk ratio */
302 ret
= snd_soc_dai_set_bclk_ratio(codec_dai
, ch
* format
);
304 dev_err(rtd
->dev
, "Failed to set rt5682 tdm bclk ratio: %d\n", ret
);
308 if (!drvdata
->soc_mclk
) {
309 ret
= acp_clk_enable(drvdata
, srate
, ch
* format
);
311 dev_err(rtd
->card
->dev
, "Failed to enable HS clk: %d\n", ret
);
319 static const struct snd_soc_ops acp_card_rt5682_ops
= {
320 .startup
= acp_card_hs_startup
,
321 .shutdown
= acp_card_shutdown
,
322 .hw_params
= acp_card_rt5682_hw_params
,
325 /* Define RT5682S CODEC component*/
326 SND_SOC_DAILINK_DEF(rt5682s
,
327 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-RTL5682:00", "rt5682s-aif1")));
329 static struct snd_soc_jack rt5682s_jack
;
330 static struct snd_soc_jack_pin rt5682s_jack_pins
[] = {
332 .pin
= "Headphone Jack",
333 .mask
= SND_JACK_HEADPHONE
,
336 .pin
= "Headset Mic",
337 .mask
= SND_JACK_MICROPHONE
,
341 static const struct snd_kcontrol_new rt5682s_controls
[] = {
342 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
343 SOC_DAPM_PIN_SWITCH("Headset Mic"),
346 static const struct snd_soc_dapm_widget rt5682s_widgets
[] = {
347 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
348 SND_SOC_DAPM_MIC("Headset Mic", NULL
),
351 static const struct snd_soc_dapm_route rt5682s_map
[] = {
352 { "Headphone Jack", NULL
, "HPOL" },
353 { "Headphone Jack", NULL
, "HPOR" },
354 { "IN1P", NULL
, "Headset Mic" },
357 static int acp_card_rt5682s_init(struct snd_soc_pcm_runtime
*rtd
)
359 struct snd_soc_card
*card
= rtd
->card
;
360 struct acp_card_drvdata
*drvdata
= card
->drvdata
;
361 struct snd_soc_dai
*codec_dai
= snd_soc_rtd_to_codec(rtd
, 0);
362 struct snd_soc_component
*component
= codec_dai
->component
;
365 dev_info(rtd
->dev
, "codec dai name = %s\n", codec_dai
->name
);
367 if (drvdata
->hs_codec_id
!= RT5682S
)
370 if (!drvdata
->soc_mclk
) {
371 drvdata
->wclk
= clk_get(component
->dev
, "rt5682-dai-wclk");
372 drvdata
->bclk
= clk_get(component
->dev
, "rt5682-dai-bclk");
375 ret
= snd_soc_dapm_new_controls(&card
->dapm
, rt5682s_widgets
,
376 ARRAY_SIZE(rt5682s_widgets
));
378 dev_err(rtd
->dev
, "unable to add widget dapm controls, ret %d\n", ret
);
382 ret
= snd_soc_add_card_controls(card
, rt5682s_controls
,
383 ARRAY_SIZE(rt5682s_controls
));
385 dev_err(rtd
->dev
, "unable to add card controls, ret %d\n", ret
);
389 ret
= snd_soc_card_jack_new_pins(card
, "Headset Jack",
390 SND_JACK_HEADSET
| SND_JACK_LINEOUT
|
391 SND_JACK_BTN_0
| SND_JACK_BTN_1
|
392 SND_JACK_BTN_2
| SND_JACK_BTN_3
,
395 ARRAY_SIZE(rt5682s_jack_pins
));
397 dev_err(card
->dev
, "HP jack creation failed %d\n", ret
);
401 snd_jack_set_key(rt5682s_jack
.jack
, SND_JACK_BTN_0
, KEY_PLAYPAUSE
);
402 snd_jack_set_key(rt5682s_jack
.jack
, SND_JACK_BTN_1
, KEY_VOICECOMMAND
);
403 snd_jack_set_key(rt5682s_jack
.jack
, SND_JACK_BTN_2
, KEY_VOLUMEUP
);
404 snd_jack_set_key(rt5682s_jack
.jack
, SND_JACK_BTN_3
, KEY_VOLUMEDOWN
);
406 ret
= snd_soc_component_set_jack(component
, &rt5682s_jack
, NULL
);
408 dev_err(rtd
->dev
, "Headset Jack call-back failed: %d\n", ret
);
412 return snd_soc_dapm_add_routes(&rtd
->card
->dapm
, rt5682s_map
, ARRAY_SIZE(rt5682s_map
));
415 static int acp_card_rt5682s_hw_params(struct snd_pcm_substream
*substream
,
416 struct snd_pcm_hw_params
*params
)
418 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
419 struct snd_soc_card
*card
= rtd
->card
;
420 struct acp_card_drvdata
*drvdata
= card
->drvdata
;
421 struct snd_soc_dai
*codec_dai
= snd_soc_rtd_to_codec(rtd
, 0);
422 struct snd_soc_dai
*cpu_dai
= snd_soc_rtd_to_cpu(rtd
, 0);
424 unsigned int fmt
, srate
, ch
, format
;
426 srate
= params_rate(params
);
427 ch
= params_channels(params
);
428 format
= params_physical_width(params
);
430 if (drvdata
->tdm_mode
)
431 fmt
= SND_SOC_DAIFMT_DSP_A
;
433 fmt
= SND_SOC_DAIFMT_I2S
;
435 if (drvdata
->soc_mclk
)
436 fmt
|= SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBC_CFC
;
438 fmt
|= SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBP_CFP
;
440 ret
= snd_soc_dai_set_fmt(cpu_dai
, fmt
);
441 if (ret
&& ret
!= -ENOTSUPP
) {
442 dev_err(rtd
->dev
, "Failed to set dai fmt: %d\n", ret
);
446 ret
= snd_soc_dai_set_fmt(codec_dai
, fmt
);
448 dev_err(rtd
->card
->dev
, "Failed to set dai fmt: %d\n", ret
);
452 if (drvdata
->tdm_mode
) {
454 * As codec supports slot 0 and slot 1 for playback and capture.
456 ret
= snd_soc_dai_set_tdm_slot(cpu_dai
, 0x3, 0x3, 8, 16);
457 if (ret
&& ret
!= -ENOTSUPP
) {
458 dev_err(rtd
->dev
, "set TDM slot err: %d\n", ret
);
462 ret
= snd_soc_dai_set_tdm_slot(codec_dai
, 0x3, 0x3, 8, 16);
464 dev_warn(rtd
->dev
, "set TDM slot err:%d\n", ret
);
469 ret
= snd_soc_dai_set_pll(codec_dai
, RT5682S_PLL2
, RT5682S_PLL_S_MCLK
,
470 PCO_PLAT_CLK
, RT5682_PLL_FREQ
);
472 dev_err(rtd
->dev
, "Failed to set codec PLL: %d\n", ret
);
476 ret
= snd_soc_dai_set_sysclk(codec_dai
, RT5682S_SCLK_S_PLL2
,
477 RT5682_PLL_FREQ
, SND_SOC_CLOCK_IN
);
479 dev_err(rtd
->dev
, "Failed to set codec SYSCLK: %d\n", ret
);
483 if (drvdata
->tdm_mode
) {
484 ret
= snd_soc_dai_set_pll(codec_dai
, RT5682S_PLL1
, RT5682S_PLL_S_BCLK1
,
487 dev_err(rtd
->dev
, "Failed to set codec PLL: %d\n", ret
);
491 ret
= snd_soc_dai_set_sysclk(codec_dai
, RT5682S_SCLK_S_PLL1
,
492 49152000, SND_SOC_CLOCK_IN
);
494 dev_err(rtd
->dev
, "Failed to set codec SYSCLK: %d\n", ret
);
499 /* Set tdm/i2s1 master bclk ratio */
500 ret
= snd_soc_dai_set_bclk_ratio(codec_dai
, ch
* format
);
502 dev_err(rtd
->dev
, "Failed to set rt5682 tdm bclk ratio: %d\n", ret
);
506 clk_set_rate(drvdata
->wclk
, srate
);
507 clk_set_rate(drvdata
->bclk
, srate
* ch
* format
);
508 if (!drvdata
->soc_mclk
) {
509 ret
= acp_clk_enable(drvdata
, srate
, ch
* format
);
511 dev_err(rtd
->card
->dev
, "Failed to enable HS clk: %d\n", ret
);
519 static const struct snd_soc_ops acp_card_rt5682s_ops
= {
520 .startup
= acp_card_hs_startup
,
521 .hw_params
= acp_card_rt5682s_hw_params
,
524 static const unsigned int dmic_channels
[] = {
525 DUAL_CHANNEL
, FOUR_CHANNEL
,
528 static const struct snd_pcm_hw_constraint_list dmic_constraints_channels
= {
529 .count
= ARRAY_SIZE(dmic_channels
),
530 .list
= dmic_channels
,
534 static int acp_card_dmic_startup(struct snd_pcm_substream
*substream
)
536 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
538 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
539 &dmic_constraints_channels
);
540 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
546 static const struct snd_soc_ops acp_card_dmic_ops
= {
547 .startup
= acp_card_dmic_startup
,
550 /* Declare RT1019 codec components */
551 SND_SOC_DAILINK_DEF(rt1019
,
552 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC1019:00", "rt1019-aif"),
553 COMP_CODEC("i2c-10EC1019:01", "rt1019-aif")));
555 static const struct snd_kcontrol_new rt1019_controls
[] = {
556 SOC_DAPM_PIN_SWITCH("Left Spk"),
557 SOC_DAPM_PIN_SWITCH("Right Spk"),
560 static const struct snd_soc_dapm_widget rt1019_widgets
[] = {
561 SND_SOC_DAPM_SPK("Left Spk", NULL
),
562 SND_SOC_DAPM_SPK("Right Spk", NULL
),
565 static const struct snd_soc_dapm_route rt1019_map_lr
[] = {
566 { "Left Spk", NULL
, "Left SPO" },
567 { "Right Spk", NULL
, "Right SPO" },
570 static struct snd_soc_codec_conf rt1019_conf
[] = {
572 .dlc
= COMP_CODEC_CONF("i2c-10EC1019:01"),
573 .name_prefix
= "Left",
576 .dlc
= COMP_CODEC_CONF("i2c-10EC1019:00"),
577 .name_prefix
= "Right",
581 static int acp_card_rt1019_init(struct snd_soc_pcm_runtime
*rtd
)
583 struct snd_soc_card
*card
= rtd
->card
;
584 struct acp_card_drvdata
*drvdata
= card
->drvdata
;
587 if (drvdata
->amp_codec_id
!= RT1019
)
590 ret
= snd_soc_dapm_new_controls(&card
->dapm
, rt1019_widgets
,
591 ARRAY_SIZE(rt1019_widgets
));
593 dev_err(rtd
->dev
, "unable to add widget dapm controls, ret %d\n", ret
);
597 ret
= snd_soc_add_card_controls(card
, rt1019_controls
,
598 ARRAY_SIZE(rt1019_controls
));
600 dev_err(rtd
->dev
, "unable to add card controls, ret %d\n", ret
);
604 return snd_soc_dapm_add_routes(&rtd
->card
->dapm
, rt1019_map_lr
,
605 ARRAY_SIZE(rt1019_map_lr
));
608 static int acp_card_rt1019_hw_params(struct snd_pcm_substream
*substream
,
609 struct snd_pcm_hw_params
*params
)
611 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
612 struct snd_soc_card
*card
= rtd
->card
;
613 struct acp_card_drvdata
*drvdata
= card
->drvdata
;
614 struct snd_soc_dai
*codec_dai
;
615 struct snd_soc_dai
*cpu_dai
= snd_soc_rtd_to_cpu(rtd
, 0);
617 unsigned int fmt
, srate
, ch
, format
;
619 srate
= params_rate(params
);
620 ch
= params_channels(params
);
621 format
= params_physical_width(params
);
623 if (drvdata
->amp_codec_id
!= RT1019
)
626 if (drvdata
->tdm_mode
)
627 fmt
= SND_SOC_DAIFMT_DSP_A
;
629 fmt
= SND_SOC_DAIFMT_I2S
;
631 if (drvdata
->soc_mclk
)
632 fmt
|= SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBC_CFC
;
634 fmt
|= SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBP_CFP
;
636 ret
= snd_soc_dai_set_fmt(cpu_dai
, fmt
);
637 if (ret
&& ret
!= -ENOTSUPP
) {
638 dev_err(rtd
->dev
, "Failed to set dai fmt: %d\n", ret
);
642 if (drvdata
->tdm_mode
) {
644 * As codec supports slot 2 and slot 3 for playback.
646 ret
= snd_soc_dai_set_tdm_slot(cpu_dai
, 0xC, 0, 8, 16);
647 if (ret
&& ret
!= -ENOTSUPP
) {
648 dev_err(rtd
->dev
, "set TDM slot err: %d\n", ret
);
653 for_each_rtd_codec_dais(rtd
, i
, codec_dai
) {
654 if (strcmp(codec_dai
->name
, "rt1019-aif"))
657 if (drvdata
->tdm_mode
)
658 ret
= snd_soc_dai_set_pll(codec_dai
, 0, RT1019_PLL_S_BCLK
,
659 TDM_CHANNELS
* format
* srate
, 256 * srate
);
661 ret
= snd_soc_dai_set_pll(codec_dai
, 0, RT1019_PLL_S_BCLK
,
662 ch
* format
* srate
, 256 * srate
);
667 ret
= snd_soc_dai_set_sysclk(codec_dai
, RT1019_SCLK_S_PLL
,
668 256 * srate
, SND_SOC_CLOCK_IN
);
672 if (drvdata
->tdm_mode
) {
673 ret
= snd_soc_dai_set_fmt(codec_dai
, SND_SOC_DAIFMT_DSP_A
674 | SND_SOC_DAIFMT_NB_NF
);
676 dev_err(rtd
->card
->dev
, "Failed to set dai fmt: %d\n", ret
);
681 * As codec supports slot 2 for left channel playback.
683 if (!strcmp(codec_dai
->component
->name
, "i2c-10EC1019:00")) {
684 ret
= snd_soc_dai_set_tdm_slot(codec_dai
, 0x4, 0x4, 8, 16);
690 * As codec supports slot 3 for right channel playback.
692 if (!strcmp(codec_dai
->component
->name
, "i2c-10EC1019:01")) {
693 ret
= snd_soc_dai_set_tdm_slot(codec_dai
, 0x8, 0x8, 8, 16);
700 if (!drvdata
->soc_mclk
) {
701 ret
= acp_clk_enable(drvdata
, srate
, ch
* format
);
703 dev_err(rtd
->card
->dev
, "Failed to enable AMP clk: %d\n", ret
);
711 static int acp_card_amp_startup(struct snd_pcm_substream
*substream
)
713 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
715 runtime
->hw
.channels_max
= DUAL_CHANNEL
;
716 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
717 &constraints_channels
);
718 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
724 static const struct snd_soc_ops acp_card_rt1019_ops
= {
725 .startup
= acp_card_amp_startup
,
726 .shutdown
= acp_card_shutdown
,
727 .hw_params
= acp_card_rt1019_hw_params
,
730 /* Declare Maxim codec components */
731 SND_SOC_DAILINK_DEF(max98360a
,
732 DAILINK_COMP_ARRAY(COMP_CODEC("MX98360A:00", "HiFi")));
734 static const struct snd_kcontrol_new max98360a_controls
[] = {
735 SOC_DAPM_PIN_SWITCH("Spk"),
738 static const struct snd_soc_dapm_widget max98360a_widgets
[] = {
739 SND_SOC_DAPM_SPK("Spk", NULL
),
742 static const struct snd_soc_dapm_route max98360a_map
[] = {
743 {"Spk", NULL
, "Speaker"},
746 static int acp_card_maxim_init(struct snd_soc_pcm_runtime
*rtd
)
748 struct snd_soc_card
*card
= rtd
->card
;
749 struct acp_card_drvdata
*drvdata
= card
->drvdata
;
752 if (drvdata
->amp_codec_id
!= MAX98360A
)
755 ret
= snd_soc_dapm_new_controls(&card
->dapm
, max98360a_widgets
,
756 ARRAY_SIZE(max98360a_widgets
));
758 dev_err(rtd
->dev
, "unable to add widget dapm controls, ret %d\n", ret
);
762 ret
= snd_soc_add_card_controls(card
, max98360a_controls
,
763 ARRAY_SIZE(max98360a_controls
));
765 dev_err(rtd
->dev
, "unable to add card controls, ret %d\n", ret
);
769 return snd_soc_dapm_add_routes(&rtd
->card
->dapm
, max98360a_map
,
770 ARRAY_SIZE(max98360a_map
));
773 static int acp_card_maxim_hw_params(struct snd_pcm_substream
*substream
,
774 struct snd_pcm_hw_params
*params
)
776 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
777 struct snd_soc_card
*card
= rtd
->card
;
778 struct acp_card_drvdata
*drvdata
= card
->drvdata
;
779 struct snd_soc_dai
*cpu_dai
= snd_soc_rtd_to_cpu(rtd
, 0);
780 unsigned int fmt
, srate
, ch
, format
;
783 srate
= params_rate(params
);
784 ch
= params_channels(params
);
785 format
= params_physical_width(params
);
787 if (drvdata
->tdm_mode
)
788 fmt
= SND_SOC_DAIFMT_DSP_A
;
790 fmt
= SND_SOC_DAIFMT_I2S
;
792 if (drvdata
->soc_mclk
)
793 fmt
|= SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBC_CFC
;
795 fmt
|= SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBP_CFP
;
797 ret
= snd_soc_dai_set_fmt(cpu_dai
, fmt
);
798 if (ret
&& ret
!= -ENOTSUPP
) {
799 dev_err(rtd
->dev
, "Failed to set dai fmt: %d\n", ret
);
803 if (drvdata
->tdm_mode
) {
805 * As codec supports slot 2 and slot 3 for playback.
807 ret
= snd_soc_dai_set_tdm_slot(cpu_dai
, 0xC, 0, 8, 16);
808 if (ret
&& ret
!= -ENOTSUPP
) {
809 dev_err(rtd
->dev
, "set TDM slot err: %d\n", ret
);
814 if (!drvdata
->soc_mclk
) {
815 ret
= acp_clk_enable(drvdata
, srate
, ch
* format
);
817 dev_err(rtd
->card
->dev
, "Failed to enable AMP clk: %d\n", ret
);
824 static const struct snd_soc_ops acp_card_maxim_ops
= {
825 .startup
= acp_card_amp_startup
,
826 .shutdown
= acp_card_shutdown
,
827 .hw_params
= acp_card_maxim_hw_params
,
830 SND_SOC_DAILINK_DEF(max98388
,
831 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-ADS8388:00", MAX98388_CODEC_DAI
),
832 COMP_CODEC("i2c-ADS8388:01", MAX98388_CODEC_DAI
)));
834 static const struct snd_kcontrol_new max98388_controls
[] = {
835 SOC_DAPM_PIN_SWITCH("Left Spk"),
836 SOC_DAPM_PIN_SWITCH("Right Spk"),
839 static const struct snd_soc_dapm_widget max98388_widgets
[] = {
840 SND_SOC_DAPM_SPK("Left Spk", NULL
),
841 SND_SOC_DAPM_SPK("Right Spk", NULL
),
844 static const struct snd_soc_dapm_route max98388_map
[] = {
845 { "Left Spk", NULL
, "Left BE_OUT" },
846 { "Right Spk", NULL
, "Right BE_OUT" },
849 static struct snd_soc_codec_conf max98388_conf
[] = {
851 .dlc
= COMP_CODEC_CONF("i2c-ADS8388:00"),
852 .name_prefix
= "Left",
855 .dlc
= COMP_CODEC_CONF("i2c-ADS8388:01"),
856 .name_prefix
= "Right",
860 static const unsigned int max98388_format
[] = {16};
862 static struct snd_pcm_hw_constraint_list constraints_sample_bits_max
= {
863 .list
= max98388_format
,
864 .count
= ARRAY_SIZE(max98388_format
),
867 static int acp_card_max98388_startup(struct snd_pcm_substream
*substream
)
869 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
871 runtime
->hw
.channels_max
= DUAL_CHANNEL
;
872 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
873 &constraints_channels
);
874 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
876 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_SAMPLE_BITS
,
877 &constraints_sample_bits_max
);
882 static int acp_card_max98388_init(struct snd_soc_pcm_runtime
*rtd
)
884 struct snd_soc_card
*card
= rtd
->card
;
885 struct acp_card_drvdata
*drvdata
= card
->drvdata
;
888 if (drvdata
->amp_codec_id
!= MAX98388
)
891 ret
= snd_soc_dapm_new_controls(&card
->dapm
, max98388_widgets
,
892 ARRAY_SIZE(max98388_widgets
));
895 dev_err(rtd
->dev
, "unable to add widget dapm controls, ret %d\n", ret
);
896 /* Don't need to add routes if widget addition failed */
900 ret
= snd_soc_add_card_controls(card
, max98388_controls
,
901 ARRAY_SIZE(max98388_controls
));
903 dev_err(rtd
->dev
, "unable to add card controls, ret %d\n", ret
);
907 return snd_soc_dapm_add_routes(&rtd
->card
->dapm
, max98388_map
,
908 ARRAY_SIZE(max98388_map
));
911 static int acp_max98388_hw_params(struct snd_pcm_substream
*substream
,
912 struct snd_pcm_hw_params
*params
)
914 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
915 struct snd_soc_card
*card
= rtd
->card
;
916 struct snd_soc_dai
*codec_dai
=
917 snd_soc_card_get_codec_dai(card
,
921 ret
= snd_soc_dai_set_fmt(codec_dai
,
922 SND_SOC_DAIFMT_CBS_CFS
| SND_SOC_DAIFMT_I2S
|
923 SND_SOC_DAIFMT_NB_NF
);
930 static const struct snd_soc_ops acp_max98388_ops
= {
931 .startup
= acp_card_max98388_startup
,
932 .hw_params
= acp_max98388_hw_params
,
935 /* Declare nau8825 codec components */
936 SND_SOC_DAILINK_DEF(nau8825
,
937 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10508825:00", "nau8825-hifi")));
939 static struct snd_soc_jack nau8825_jack
;
940 static struct snd_soc_jack_pin nau8825_jack_pins
[] = {
942 .pin
= "Headphone Jack",
943 .mask
= SND_JACK_HEADPHONE
,
946 .pin
= "Headset Mic",
947 .mask
= SND_JACK_MICROPHONE
,
951 static const struct snd_kcontrol_new nau8825_controls
[] = {
952 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
953 SOC_DAPM_PIN_SWITCH("Headset Mic"),
956 static const struct snd_soc_dapm_widget nau8825_widgets
[] = {
957 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
958 SND_SOC_DAPM_MIC("Headset Mic", NULL
),
961 static const struct snd_soc_dapm_route nau8825_map
[] = {
962 { "Headphone Jack", NULL
, "HPOL" },
963 { "Headphone Jack", NULL
, "HPOR" },
966 static int acp_card_nau8825_init(struct snd_soc_pcm_runtime
*rtd
)
968 struct snd_soc_card
*card
= rtd
->card
;
969 struct acp_card_drvdata
*drvdata
= card
->drvdata
;
970 struct snd_soc_dai
*codec_dai
= snd_soc_rtd_to_codec(rtd
, 0);
971 struct snd_soc_component
*component
= codec_dai
->component
;
974 dev_info(rtd
->dev
, "codec dai name = %s\n", codec_dai
->name
);
976 if (drvdata
->hs_codec_id
!= NAU8825
)
979 ret
= snd_soc_dapm_new_controls(&card
->dapm
, nau8825_widgets
,
980 ARRAY_SIZE(nau8825_widgets
));
982 dev_err(rtd
->dev
, "unable to add widget dapm controls, ret %d\n", ret
);
986 ret
= snd_soc_add_card_controls(card
, nau8825_controls
,
987 ARRAY_SIZE(nau8825_controls
));
989 dev_err(rtd
->dev
, "unable to add card controls, ret %d\n", ret
);
993 ret
= snd_soc_card_jack_new_pins(card
, "Headset Jack",
994 SND_JACK_HEADSET
| SND_JACK_LINEOUT
|
995 SND_JACK_BTN_0
| SND_JACK_BTN_1
|
996 SND_JACK_BTN_2
| SND_JACK_BTN_3
,
999 ARRAY_SIZE(nau8825_jack_pins
));
1001 dev_err(card
->dev
, "HP jack creation failed %d\n", ret
);
1005 snd_jack_set_key(nau8825_jack
.jack
, SND_JACK_BTN_0
, KEY_PLAYPAUSE
);
1006 snd_jack_set_key(nau8825_jack
.jack
, SND_JACK_BTN_1
, KEY_VOICECOMMAND
);
1007 snd_jack_set_key(nau8825_jack
.jack
, SND_JACK_BTN_2
, KEY_VOLUMEUP
);
1008 snd_jack_set_key(nau8825_jack
.jack
, SND_JACK_BTN_3
, KEY_VOLUMEDOWN
);
1010 ret
= snd_soc_component_set_jack(component
, &nau8825_jack
, NULL
);
1012 dev_err(rtd
->dev
, "Headset Jack call-back failed: %d\n", ret
);
1016 return snd_soc_dapm_add_routes(&rtd
->card
->dapm
, nau8825_map
, ARRAY_SIZE(nau8825_map
));
1019 static int acp_nau8825_hw_params(struct snd_pcm_substream
*substream
,
1020 struct snd_pcm_hw_params
*params
)
1022 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
1023 struct snd_soc_card
*card
= rtd
->card
;
1024 struct acp_card_drvdata
*drvdata
= card
->drvdata
;
1025 struct snd_soc_dai
*codec_dai
= snd_soc_rtd_to_codec(rtd
, 0);
1026 struct snd_soc_dai
*cpu_dai
= snd_soc_rtd_to_cpu(rtd
, 0);
1030 ret
= snd_soc_dai_set_sysclk(codec_dai
, NAU8825_CLK_FLL_FS
,
1031 (48000 * 256), SND_SOC_CLOCK_IN
);
1033 dev_err(rtd
->dev
, "snd_soc_dai_set_sysclk err = %d\n", ret
);
1035 ret
= snd_soc_dai_set_pll(codec_dai
, 0, 0, params_rate(params
),
1036 params_rate(params
) * 256);
1038 dev_err(rtd
->dev
, "can't set FLL: %d\n", ret
);
1042 if (drvdata
->tdm_mode
)
1043 fmt
= SND_SOC_DAIFMT_DSP_A
;
1045 fmt
= SND_SOC_DAIFMT_I2S
;
1047 if (drvdata
->soc_mclk
)
1048 fmt
|= SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBC_CFC
;
1050 fmt
|= SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBP_CFP
;
1052 ret
= snd_soc_dai_set_fmt(cpu_dai
, fmt
);
1053 if (ret
&& ret
!= -ENOTSUPP
) {
1054 dev_err(rtd
->dev
, "Failed to set dai fmt: %d\n", ret
);
1058 ret
= snd_soc_dai_set_fmt(codec_dai
, fmt
);
1060 dev_err(rtd
->card
->dev
, "Failed to set dai fmt: %d\n", ret
);
1064 if (drvdata
->tdm_mode
) {
1066 * As codec supports slot 4 and slot 5 for playback and slot 6 for capture.
1068 ret
= snd_soc_dai_set_tdm_slot(cpu_dai
, 0x30, 0xC0, 8, 16);
1069 if (ret
&& ret
!= -ENOTSUPP
) {
1070 dev_err(rtd
->dev
, "set TDM slot err: %d\n", ret
);
1074 ret
= snd_soc_dai_set_tdm_slot(codec_dai
, 0x40, 0x30, 8, 16);
1076 dev_warn(rtd
->dev
, "set TDM slot err:%d\n", ret
);
1083 static int acp_nau8825_startup(struct snd_pcm_substream
*substream
)
1085 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1087 runtime
->hw
.channels_max
= 2;
1088 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
1089 &constraints_channels
);
1091 runtime
->hw
.formats
= SNDRV_PCM_FMTBIT_S16_LE
;
1092 snd_pcm_hw_constraint_list(runtime
, 0,
1093 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
1097 static const struct snd_soc_ops acp_card_nau8825_ops
= {
1098 .startup
= acp_nau8825_startup
,
1099 .hw_params
= acp_nau8825_hw_params
,
1102 static int platform_clock_control(struct snd_soc_dapm_widget
*w
,
1103 struct snd_kcontrol
*k
, int event
)
1105 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
1106 struct snd_soc_card
*card
= dapm
->card
;
1107 struct snd_soc_dai
*codec_dai
;
1110 codec_dai
= snd_soc_card_get_codec_dai(card
, NAU8821_CODEC_DAI
);
1112 dev_err(card
->dev
, "Codec dai not found\n");
1116 if (SND_SOC_DAPM_EVENT_OFF(event
)) {
1117 ret
= snd_soc_dai_set_sysclk(codec_dai
, NAU8821_CLK_INTERNAL
,
1118 0, SND_SOC_CLOCK_IN
);
1120 dev_err(card
->dev
, "set sysclk err = %d\n", ret
);
1124 ret
= snd_soc_dai_set_sysclk(codec_dai
, NAU8821_CLK_FLL_BLK
, 0,
1127 dev_err(codec_dai
->dev
, "can't set FS clock %d\n", ret
);
1128 ret
= snd_soc_dai_set_pll(codec_dai
, 0, 0, NAU8821_BCLK
,
1131 dev_err(codec_dai
->dev
, "can't set FLL: %d\n", ret
);
1136 static struct snd_soc_jack nau8821_jack
;
1137 static struct snd_soc_jack_pin nau8821_jack_pins
[] = {
1139 .pin
= "Headphone Jack",
1140 .mask
= SND_JACK_HEADPHONE
,
1143 .pin
= "Headset Mic",
1144 .mask
= SND_JACK_MICROPHONE
,
1148 static const struct snd_kcontrol_new nau8821_controls
[] = {
1149 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
1150 SOC_DAPM_PIN_SWITCH("Headset Mic"),
1153 static const struct snd_soc_dapm_widget nau8821_widgets
[] = {
1154 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
1155 SND_SOC_DAPM_MIC("Headset Mic", NULL
),
1156 SND_SOC_DAPM_MIC("Int Mic", NULL
),
1157 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM
, 0, 0,
1158 platform_clock_control
, SND_SOC_DAPM_PRE_PMU
|
1159 SND_SOC_DAPM_POST_PMD
),
1162 static const struct snd_soc_dapm_route nau8821_audio_route
[] = {
1163 /* HP jack connectors - unknown if we have jack detection */
1164 { "Headphone Jack", NULL
, "HPOL" },
1165 { "Headphone Jack", NULL
, "HPOR" },
1166 { "MICL", NULL
, "Headset Mic" },
1167 { "MICR", NULL
, "Headset Mic" },
1168 { "DMIC", NULL
, "Int Mic" },
1169 { "Headphone Jack", NULL
, "Platform Clock" },
1170 { "Headset Mic", NULL
, "Platform Clock" },
1171 { "Int Mic", NULL
, "Platform Clock" },
1174 static const unsigned int nau8821_format
[] = {16};
1176 static struct snd_pcm_hw_constraint_list constraints_sample_bits
= {
1177 .list
= nau8821_format
,
1178 .count
= ARRAY_SIZE(nau8821_format
),
1181 static int acp_8821_init(struct snd_soc_pcm_runtime
*rtd
)
1183 struct snd_soc_card
*card
= rtd
->card
;
1184 struct snd_soc_dai
*codec_dai
= snd_soc_rtd_to_codec(rtd
, 0);
1185 struct snd_soc_component
*component
= codec_dai
->component
;
1188 dev_info(rtd
->dev
, "codec dai name = %s\n", codec_dai
->name
);
1190 ret
= snd_soc_dapm_new_controls(&card
->dapm
, nau8821_widgets
,
1191 ARRAY_SIZE(nau8821_widgets
));
1193 dev_err(rtd
->dev
, "unable to add widget dapm controls, ret %d\n", ret
);
1194 // Don't need to add routes if widget addition failed
1198 ret
= snd_soc_add_card_controls(card
, nau8821_controls
,
1199 ARRAY_SIZE(nau8821_controls
));
1201 dev_err(rtd
->dev
, "unable to add card controls, ret %d\n", ret
);
1205 ret
= snd_soc_card_jack_new_pins(card
, "Headset Jack",
1206 SND_JACK_HEADSET
| SND_JACK_LINEOUT
|
1207 SND_JACK_BTN_0
| SND_JACK_BTN_1
|
1208 SND_JACK_BTN_2
| SND_JACK_BTN_3
,
1211 ARRAY_SIZE(nau8821_jack_pins
));
1213 dev_err(rtd
->dev
, "Headset Jack creation failed %d\n", ret
);
1217 snd_jack_set_key(nau8821_jack
.jack
, SND_JACK_BTN_0
, KEY_PLAYPAUSE
);
1218 snd_jack_set_key(nau8821_jack
.jack
, SND_JACK_BTN_1
, KEY_VOICECOMMAND
);
1219 snd_jack_set_key(nau8821_jack
.jack
, SND_JACK_BTN_2
, KEY_VOLUMEUP
);
1220 snd_jack_set_key(nau8821_jack
.jack
, SND_JACK_BTN_3
, KEY_VOLUMEDOWN
);
1222 nau8821_enable_jack_detect(component
, &nau8821_jack
);
1224 return snd_soc_dapm_add_routes(&rtd
->card
->dapm
, nau8821_audio_route
,
1225 ARRAY_SIZE(nau8821_audio_route
));
1228 static int acp_8821_startup(struct snd_pcm_substream
*substream
)
1230 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1232 runtime
->hw
.channels_max
= DUAL_CHANNEL
;
1233 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
1234 &constraints_channels
);
1235 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
1236 &constraints_rates
);
1237 snd_pcm_hw_constraint_list(substream
->runtime
, 0,
1238 SNDRV_PCM_HW_PARAM_SAMPLE_BITS
,
1239 &constraints_sample_bits
);
1243 static int acp_nau8821_hw_params(struct snd_pcm_substream
*substream
,
1244 struct snd_pcm_hw_params
*params
)
1246 struct snd_soc_pcm_runtime
*rtd
= snd_soc_substream_to_rtd(substream
);
1247 struct snd_soc_card
*card
= rtd
->card
;
1248 struct acp_card_drvdata
*drvdata
= card
->drvdata
;
1249 struct snd_soc_dai
*codec_dai
= snd_soc_rtd_to_codec(rtd
, 0);
1253 if (drvdata
->soc_mclk
)
1254 fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBC_CFC
;
1256 fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
| SND_SOC_DAIFMT_CBP_CFP
;
1258 ret
= snd_soc_dai_set_fmt(codec_dai
, fmt
);
1260 dev_err(rtd
->card
->dev
, "Failed to set dai fmt: %d\n", ret
);
1264 ret
= snd_soc_dai_set_sysclk(codec_dai
, NAU8821_CLK_FLL_BLK
, 0,
1267 dev_err(card
->dev
, "can't set FS clock %d\n", ret
);
1268 ret
= snd_soc_dai_set_pll(codec_dai
, 0, 0, snd_soc_params_to_bclk(params
),
1269 params_rate(params
) * 256);
1271 dev_err(card
->dev
, "can't set FLL: %d\n", ret
);
1276 static const struct snd_soc_ops acp_8821_ops
= {
1277 .startup
= acp_8821_startup
,
1278 .hw_params
= acp_nau8821_hw_params
,
1281 SND_SOC_DAILINK_DEF(nau8821
,
1282 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-NVTN2020:00",
1283 NAU8821_CODEC_DAI
)));
1285 /* Declare DMIC codec components */
1286 SND_SOC_DAILINK_DEF(dmic_codec
,
1287 DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
1289 /* Declare ACP CPU components */
1290 static struct snd_soc_dai_link_component platform_component
[] = {
1292 .name
= "acp_asoc_renoir.0",
1296 static struct snd_soc_dai_link_component platform_rmb_component
[] = {
1298 .name
= "acp_asoc_rembrandt.0",
1302 static struct snd_soc_dai_link_component platform_acp63_component
[] = {
1304 .name
= "acp_asoc_acp63.0",
1308 static struct snd_soc_dai_link_component platform_acp70_component
[] = {
1310 .name
= "acp_asoc_acp70.0",
1314 static struct snd_soc_dai_link_component sof_component
[] = {
1316 .name
= "0000:04:00.5",
1320 SND_SOC_DAILINK_DEF(i2s_sp
,
1321 DAILINK_COMP_ARRAY(COMP_CPU("acp-i2s-sp")));
1322 SND_SOC_DAILINK_DEF(i2s_hs
,
1323 DAILINK_COMP_ARRAY(COMP_CPU("acp-i2s-hs")));
1324 SND_SOC_DAILINK_DEF(sof_sp
,
1325 DAILINK_COMP_ARRAY(COMP_CPU("acp-sof-sp")));
1326 SND_SOC_DAILINK_DEF(sof_sp_virtual
,
1327 DAILINK_COMP_ARRAY(COMP_CPU("acp-sof-sp-virtual")));
1328 SND_SOC_DAILINK_DEF(sof_hs
,
1329 DAILINK_COMP_ARRAY(COMP_CPU("acp-sof-hs")));
1330 SND_SOC_DAILINK_DEF(sof_hs_virtual
,
1331 DAILINK_COMP_ARRAY(COMP_CPU("acp-sof-hs-virtual")));
1332 SND_SOC_DAILINK_DEF(sof_bt
,
1333 DAILINK_COMP_ARRAY(COMP_CPU("acp-sof-bt")));
1334 SND_SOC_DAILINK_DEF(sof_dmic
,
1335 DAILINK_COMP_ARRAY(COMP_CPU("acp-sof-dmic")));
1336 SND_SOC_DAILINK_DEF(pdm_dmic
,
1337 DAILINK_COMP_ARRAY(COMP_CPU("acp-pdm-dmic")));
1339 static int acp_rtk_set_bias_level(struct snd_soc_card
*card
,
1340 struct snd_soc_dapm_context
*dapm
,
1341 enum snd_soc_bias_level level
)
1343 struct snd_soc_component
*component
= dapm
->component
;
1344 struct acp_card_drvdata
*drvdata
= card
->drvdata
;
1350 if (strncmp(component
->name
, "i2c-RTL5682", 11) &&
1351 strncmp(component
->name
, "i2c-10EC1019", 12))
1355 * For Realtek's codec and amplifier components,
1356 * the lrck and bclk must be enabled brfore their all dapms be powered on,
1357 * and must be disabled after their all dapms be powered down
1361 case SND_SOC_BIAS_STANDBY
:
1362 if (snd_soc_dapm_get_bias_level(dapm
) == SND_SOC_BIAS_OFF
) {
1364 /* Increase bclk's enable_count */
1365 ret
= clk_prepare_enable(drvdata
->bclk
);
1367 dev_err(component
->dev
, "Failed to enable bclk %d\n", ret
);
1370 * Decrease bclk's enable_count.
1371 * While the enable_count is 0, the bclk would be closed.
1373 clk_disable_unprepare(drvdata
->bclk
);
1383 int acp_sofdsp_dai_links_create(struct snd_soc_card
*card
)
1385 struct snd_soc_dai_link
*links
;
1386 struct device
*dev
= card
->dev
;
1387 struct acp_card_drvdata
*drv_data
= card
->drvdata
;
1388 int i
= 0, num_links
= 0;
1390 if (drv_data
->hs_cpu_id
)
1392 if (drv_data
->bt_cpu_id
)
1394 if (drv_data
->amp_cpu_id
)
1396 if (drv_data
->dmic_cpu_id
)
1399 links
= devm_kcalloc(dev
, num_links
, sizeof(struct snd_soc_dai_link
), GFP_KERNEL
);
1403 if (drv_data
->hs_cpu_id
== I2S_SP
) {
1404 links
[i
].name
= "acp-headset-codec";
1405 links
[i
].id
= HEADSET_BE_ID
;
1406 links
[i
].cpus
= sof_sp
;
1407 links
[i
].num_cpus
= ARRAY_SIZE(sof_sp
);
1408 links
[i
].platforms
= sof_component
;
1409 links
[i
].num_platforms
= ARRAY_SIZE(sof_component
);
1410 links
[i
].nonatomic
= true;
1411 links
[i
].no_pcm
= 1;
1412 if (!drv_data
->hs_codec_id
) {
1413 /* Use dummy codec if codec id not specified */
1414 links
[i
].codecs
= &snd_soc_dummy_dlc
;
1415 links
[i
].num_codecs
= 1;
1417 if (drv_data
->hs_codec_id
== RT5682
) {
1418 links
[i
].codecs
= rt5682
;
1419 links
[i
].num_codecs
= ARRAY_SIZE(rt5682
);
1420 links
[i
].init
= acp_card_rt5682_init
;
1421 links
[i
].ops
= &acp_card_rt5682_ops
;
1423 if (drv_data
->hs_codec_id
== RT5682S
) {
1424 links
[i
].codecs
= rt5682s
;
1425 links
[i
].num_codecs
= ARRAY_SIZE(rt5682s
);
1426 links
[i
].init
= acp_card_rt5682s_init
;
1427 links
[i
].ops
= &acp_card_rt5682s_ops
;
1429 if (drv_data
->hs_codec_id
== NAU8821
) {
1430 links
[i
].codecs
= nau8821
;
1431 links
[i
].num_codecs
= ARRAY_SIZE(nau8821
);
1432 links
[i
].init
= acp_8821_init
;
1433 links
[i
].ops
= &acp_8821_ops
;
1438 if (drv_data
->hs_cpu_id
== I2S_HS
) {
1439 links
[i
].name
= "acp-headset-codec";
1440 links
[i
].id
= HEADSET_BE_ID
;
1441 links
[i
].cpus
= sof_hs
;
1442 links
[i
].num_cpus
= ARRAY_SIZE(sof_hs
);
1443 links
[i
].platforms
= sof_component
;
1444 links
[i
].num_platforms
= ARRAY_SIZE(sof_component
);
1445 links
[i
].nonatomic
= true;
1446 links
[i
].no_pcm
= 1;
1447 if (!drv_data
->hs_codec_id
) {
1448 /* Use dummy codec if codec id not specified */
1449 links
[i
].codecs
= &snd_soc_dummy_dlc
;
1450 links
[i
].num_codecs
= 1;
1452 if (drv_data
->hs_codec_id
== NAU8825
) {
1453 links
[i
].codecs
= nau8825
;
1454 links
[i
].num_codecs
= ARRAY_SIZE(nau8825
);
1455 links
[i
].init
= acp_card_nau8825_init
;
1456 links
[i
].ops
= &acp_card_nau8825_ops
;
1458 if (drv_data
->hs_codec_id
== RT5682S
) {
1459 links
[i
].codecs
= rt5682s
;
1460 links
[i
].num_codecs
= ARRAY_SIZE(rt5682s
);
1461 links
[i
].init
= acp_card_rt5682s_init
;
1462 links
[i
].ops
= &acp_card_rt5682s_ops
;
1467 if (drv_data
->amp_cpu_id
== I2S_SP
) {
1468 links
[i
].name
= "acp-amp-codec";
1469 links
[i
].id
= AMP_BE_ID
;
1470 if (drv_data
->acp_rev
== ACP_RN_PCI_ID
) {
1471 links
[i
].cpus
= sof_sp
;
1472 links
[i
].num_cpus
= ARRAY_SIZE(sof_sp
);
1474 links
[i
].cpus
= sof_sp_virtual
;
1475 links
[i
].num_cpus
= ARRAY_SIZE(sof_sp_virtual
);
1477 links
[i
].platforms
= sof_component
;
1478 links
[i
].num_platforms
= ARRAY_SIZE(sof_component
);
1479 links
[i
].playback_only
= 1;
1480 links
[i
].nonatomic
= true;
1481 links
[i
].no_pcm
= 1;
1482 if (!drv_data
->amp_codec_id
) {
1483 /* Use dummy codec if codec id not specified */
1484 links
[i
].codecs
= &snd_soc_dummy_dlc
;
1485 links
[i
].num_codecs
= 1;
1487 if (drv_data
->amp_codec_id
== RT1019
) {
1488 links
[i
].codecs
= rt1019
;
1489 links
[i
].num_codecs
= ARRAY_SIZE(rt1019
);
1490 links
[i
].ops
= &acp_card_rt1019_ops
;
1491 links
[i
].init
= acp_card_rt1019_init
;
1492 card
->codec_conf
= rt1019_conf
;
1493 card
->num_configs
= ARRAY_SIZE(rt1019_conf
);
1495 if (drv_data
->amp_codec_id
== MAX98360A
) {
1496 links
[i
].codecs
= max98360a
;
1497 links
[i
].num_codecs
= ARRAY_SIZE(max98360a
);
1498 links
[i
].ops
= &acp_card_maxim_ops
;
1499 links
[i
].init
= acp_card_maxim_init
;
1504 if (drv_data
->amp_cpu_id
== I2S_HS
) {
1505 links
[i
].name
= "acp-amp-codec";
1506 links
[i
].id
= AMP_BE_ID
;
1507 links
[i
].cpus
= sof_hs_virtual
;
1508 links
[i
].num_cpus
= ARRAY_SIZE(sof_hs_virtual
);
1509 links
[i
].platforms
= sof_component
;
1510 links
[i
].num_platforms
= ARRAY_SIZE(sof_component
);
1511 links
[i
].playback_only
= 1;
1512 links
[i
].nonatomic
= true;
1513 links
[i
].no_pcm
= 1;
1514 if (!drv_data
->amp_codec_id
) {
1515 /* Use dummy codec if codec id not specified */
1516 links
[i
].codecs
= &snd_soc_dummy_dlc
;
1517 links
[i
].num_codecs
= 1;
1519 if (drv_data
->amp_codec_id
== MAX98360A
) {
1520 links
[i
].codecs
= max98360a
;
1521 links
[i
].num_codecs
= ARRAY_SIZE(max98360a
);
1522 links
[i
].ops
= &acp_card_maxim_ops
;
1523 links
[i
].init
= acp_card_maxim_init
;
1525 if (drv_data
->amp_codec_id
== MAX98388
) {
1526 links
[i
].playback_only
= 0;
1527 links
[i
].codecs
= max98388
;
1528 links
[i
].num_codecs
= ARRAY_SIZE(max98388
);
1529 links
[i
].ops
= &acp_max98388_ops
;
1530 links
[i
].init
= acp_card_max98388_init
;
1531 card
->codec_conf
= max98388_conf
;
1532 card
->num_configs
= ARRAY_SIZE(max98388_conf
);
1534 if (drv_data
->amp_codec_id
== RT1019
) {
1535 links
[i
].codecs
= rt1019
;
1536 links
[i
].num_codecs
= ARRAY_SIZE(rt1019
);
1537 links
[i
].ops
= &acp_card_rt1019_ops
;
1538 links
[i
].init
= acp_card_rt1019_init
;
1539 card
->codec_conf
= rt1019_conf
;
1540 card
->num_configs
= ARRAY_SIZE(rt1019_conf
);
1545 if (drv_data
->bt_cpu_id
== I2S_BT
) {
1546 links
[i
].name
= "acp-bt-codec";
1547 links
[i
].id
= BT_BE_ID
;
1548 links
[i
].cpus
= sof_bt
;
1549 links
[i
].num_cpus
= ARRAY_SIZE(sof_bt
);
1550 links
[i
].platforms
= sof_component
;
1551 links
[i
].num_platforms
= ARRAY_SIZE(sof_component
);
1552 links
[i
].nonatomic
= true;
1553 links
[i
].no_pcm
= 1;
1554 if (!drv_data
->bt_codec_id
) {
1555 /* Use dummy codec if codec id not specified */
1556 links
[i
].codecs
= &snd_soc_dummy_dlc
;
1557 links
[i
].num_codecs
= 1;
1562 if (drv_data
->dmic_cpu_id
== DMIC
) {
1563 links
[i
].name
= "acp-dmic-codec";
1564 links
[i
].id
= DMIC_BE_ID
;
1565 links
[i
].codecs
= dmic_codec
;
1566 links
[i
].num_codecs
= ARRAY_SIZE(dmic_codec
);
1567 links
[i
].cpus
= sof_dmic
;
1568 links
[i
].num_cpus
= ARRAY_SIZE(sof_dmic
);
1569 links
[i
].platforms
= sof_component
;
1570 links
[i
].num_platforms
= ARRAY_SIZE(sof_component
);
1571 links
[i
].capture_only
= 1;
1572 links
[i
].nonatomic
= true;
1573 links
[i
].no_pcm
= 1;
1576 card
->dai_link
= links
;
1577 card
->num_links
= num_links
;
1578 card
->set_bias_level
= acp_rtk_set_bias_level
;
1582 EXPORT_SYMBOL_NS_GPL(acp_sofdsp_dai_links_create
, "SND_SOC_AMD_MACH");
1584 int acp_legacy_dai_links_create(struct snd_soc_card
*card
)
1586 struct snd_soc_dai_link
*links
;
1587 struct device
*dev
= card
->dev
;
1588 struct acp_card_drvdata
*drv_data
= card
->drvdata
;
1589 int i
= 0, num_links
= 0;
1592 if (drv_data
->hs_cpu_id
)
1594 if (drv_data
->amp_cpu_id
)
1596 if (drv_data
->dmic_cpu_id
)
1599 links
= devm_kcalloc(dev
, num_links
, sizeof(struct snd_soc_dai_link
), GFP_KERNEL
);
1603 if (drv_data
->hs_cpu_id
== I2S_SP
) {
1604 links
[i
].name
= "acp-headset-codec";
1605 links
[i
].id
= HEADSET_BE_ID
;
1606 links
[i
].cpus
= i2s_sp
;
1607 links
[i
].num_cpus
= ARRAY_SIZE(i2s_sp
);
1608 links
[i
].platforms
= platform_component
;
1609 links
[i
].num_platforms
= ARRAY_SIZE(platform_component
);
1610 if (!drv_data
->hs_codec_id
) {
1611 /* Use dummy codec if codec id not specified */
1612 links
[i
].codecs
= &snd_soc_dummy_dlc
;
1613 links
[i
].num_codecs
= 1;
1615 if (drv_data
->hs_codec_id
== RT5682
) {
1616 links
[i
].codecs
= rt5682
;
1617 links
[i
].num_codecs
= ARRAY_SIZE(rt5682
);
1618 links
[i
].init
= acp_card_rt5682_init
;
1619 links
[i
].ops
= &acp_card_rt5682_ops
;
1621 if (drv_data
->hs_codec_id
== RT5682S
) {
1622 links
[i
].codecs
= rt5682s
;
1623 links
[i
].num_codecs
= ARRAY_SIZE(rt5682s
);
1624 links
[i
].init
= acp_card_rt5682s_init
;
1625 links
[i
].ops
= &acp_card_rt5682s_ops
;
1627 if (drv_data
->hs_codec_id
== ES83XX
) {
1628 rc
= acp_ops_configure_link(card
, &links
[i
]);
1630 dev_err(dev
, "Failed to configure link for ES83XX: %d\n", rc
);
1637 if (drv_data
->hs_cpu_id
== I2S_HS
) {
1638 links
[i
].name
= "acp-headset-codec";
1639 links
[i
].id
= HEADSET_BE_ID
;
1640 links
[i
].cpus
= i2s_hs
;
1641 links
[i
].num_cpus
= ARRAY_SIZE(i2s_hs
);
1642 switch (drv_data
->acp_rev
) {
1643 case ACP_RMB_PCI_ID
:
1644 links
[i
].platforms
= platform_rmb_component
;
1645 links
[i
].num_platforms
= ARRAY_SIZE(platform_rmb_component
);
1648 links
[i
].platforms
= platform_acp63_component
;
1649 links
[i
].num_platforms
= ARRAY_SIZE(platform_acp63_component
);
1652 links
[i
].platforms
= platform_component
;
1653 links
[i
].num_platforms
= ARRAY_SIZE(platform_component
);
1657 if (!drv_data
->hs_codec_id
) {
1658 /* Use dummy codec if codec id not specified */
1659 links
[i
].codecs
= &snd_soc_dummy_dlc
;
1660 links
[i
].num_codecs
= 1;
1662 if (drv_data
->hs_codec_id
== NAU8825
) {
1663 links
[i
].codecs
= nau8825
;
1664 links
[i
].num_codecs
= ARRAY_SIZE(nau8825
);
1665 links
[i
].init
= acp_card_nau8825_init
;
1666 links
[i
].ops
= &acp_card_nau8825_ops
;
1668 if (drv_data
->hs_codec_id
== RT5682S
) {
1669 links
[i
].codecs
= rt5682s
;
1670 links
[i
].num_codecs
= ARRAY_SIZE(rt5682s
);
1671 links
[i
].init
= acp_card_rt5682s_init
;
1672 links
[i
].ops
= &acp_card_rt5682s_ops
;
1677 if (drv_data
->amp_cpu_id
== I2S_SP
) {
1678 links
[i
].name
= "acp-amp-codec";
1679 links
[i
].id
= AMP_BE_ID
;
1680 links
[i
].cpus
= i2s_sp
;
1681 links
[i
].num_cpus
= ARRAY_SIZE(i2s_sp
);
1682 links
[i
].platforms
= platform_component
;
1683 links
[i
].num_platforms
= ARRAY_SIZE(platform_component
);
1684 links
[i
].playback_only
= 1;
1685 if (!drv_data
->amp_codec_id
) {
1686 /* Use dummy codec if codec id not specified */
1687 links
[i
].codecs
= &snd_soc_dummy_dlc
;
1688 links
[i
].num_codecs
= 1;
1690 if (drv_data
->amp_codec_id
== RT1019
) {
1691 links
[i
].codecs
= rt1019
;
1692 links
[i
].num_codecs
= ARRAY_SIZE(rt1019
);
1693 links
[i
].ops
= &acp_card_rt1019_ops
;
1694 links
[i
].init
= acp_card_rt1019_init
;
1695 card
->codec_conf
= rt1019_conf
;
1696 card
->num_configs
= ARRAY_SIZE(rt1019_conf
);
1698 if (drv_data
->amp_codec_id
== MAX98360A
) {
1699 links
[i
].codecs
= max98360a
;
1700 links
[i
].num_codecs
= ARRAY_SIZE(max98360a
);
1701 links
[i
].ops
= &acp_card_maxim_ops
;
1702 links
[i
].init
= acp_card_maxim_init
;
1707 if (drv_data
->amp_cpu_id
== I2S_HS
) {
1708 links
[i
].name
= "acp-amp-codec";
1709 links
[i
].id
= AMP_BE_ID
;
1710 links
[i
].cpus
= i2s_hs
;
1711 links
[i
].num_cpus
= ARRAY_SIZE(i2s_hs
);
1712 switch (drv_data
->acp_rev
) {
1713 case ACP_RMB_PCI_ID
:
1714 links
[i
].platforms
= platform_rmb_component
;
1715 links
[i
].num_platforms
= ARRAY_SIZE(platform_rmb_component
);
1718 links
[i
].platforms
= platform_acp63_component
;
1719 links
[i
].num_platforms
= ARRAY_SIZE(platform_acp63_component
);
1722 links
[i
].platforms
= platform_component
;
1723 links
[i
].num_platforms
= ARRAY_SIZE(platform_component
);
1727 links
[i
].playback_only
= 1;
1728 if (!drv_data
->amp_codec_id
) {
1729 /* Use dummy codec if codec id not specified */
1730 links
[i
].codecs
= &snd_soc_dummy_dlc
;
1731 links
[i
].num_codecs
= 1;
1733 if (drv_data
->amp_codec_id
== MAX98360A
) {
1734 links
[i
].codecs
= max98360a
;
1735 links
[i
].num_codecs
= ARRAY_SIZE(max98360a
);
1736 links
[i
].ops
= &acp_card_maxim_ops
;
1737 links
[i
].init
= acp_card_maxim_init
;
1739 if (drv_data
->amp_codec_id
== RT1019
) {
1740 links
[i
].codecs
= rt1019
;
1741 links
[i
].num_codecs
= ARRAY_SIZE(rt1019
);
1742 links
[i
].ops
= &acp_card_rt1019_ops
;
1743 links
[i
].init
= acp_card_rt1019_init
;
1744 card
->codec_conf
= rt1019_conf
;
1745 card
->num_configs
= ARRAY_SIZE(rt1019_conf
);
1750 if (drv_data
->dmic_cpu_id
== DMIC
) {
1751 links
[i
].name
= "acp-dmic-codec";
1752 links
[i
].stream_name
= "DMIC capture";
1753 links
[i
].id
= DMIC_BE_ID
;
1754 if (drv_data
->dmic_codec_id
== DMIC
) {
1755 links
[i
].codecs
= dmic_codec
;
1756 links
[i
].num_codecs
= ARRAY_SIZE(dmic_codec
);
1758 /* Use dummy codec if codec id not specified */
1759 links
[i
].codecs
= &snd_soc_dummy_dlc
;
1760 links
[i
].num_codecs
= 1;
1762 links
[i
].cpus
= pdm_dmic
;
1763 links
[i
].num_cpus
= ARRAY_SIZE(pdm_dmic
);
1764 switch (drv_data
->acp_rev
) {
1765 case ACP_RMB_PCI_ID
:
1766 links
[i
].platforms
= platform_rmb_component
;
1767 links
[i
].num_platforms
= ARRAY_SIZE(platform_rmb_component
);
1770 links
[i
].platforms
= platform_acp63_component
;
1771 links
[i
].num_platforms
= ARRAY_SIZE(platform_acp63_component
);
1775 links
[i
].platforms
= platform_acp70_component
;
1776 links
[i
].num_platforms
= ARRAY_SIZE(platform_acp70_component
);
1779 links
[i
].platforms
= platform_component
;
1780 links
[i
].num_platforms
= ARRAY_SIZE(platform_component
);
1783 links
[i
].ops
= &acp_card_dmic_ops
;
1784 links
[i
].capture_only
= 1;
1787 card
->dai_link
= links
;
1788 card
->num_links
= num_links
;
1789 card
->set_bias_level
= acp_rtk_set_bias_level
;
1793 EXPORT_SYMBOL_NS_GPL(acp_legacy_dai_links_create
, "SND_SOC_AMD_MACH");
1795 MODULE_DESCRIPTION("AMD ACP Common Machine driver");
1796 MODULE_LICENSE("GPL v2");