1 // SPDX-License-Identifier: MIT 2 // 3 // Machine driver for AMD ACP Audio engine using DA7219, RT5682 & MAX98357 codec 4 // 5 //Copyright 2017-2021 Advanced Micro Devices, Inc. 6 7 #include <sound/core.h> 8 #include <sound/soc.h> 9 #include <sound/pcm.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> 21 22 #include "acp.h" 23 #include "../codecs/da7219.h" 24 #include "../codecs/rt5682.h" 25 26 #define CZ_PLAT_CLK 48000000 27 #define DUAL_CHANNEL 2 28 #define RT5682_PLL_FREQ (48000 * 512) 29 30 static struct snd_soc_jack cz_jack; 31 static struct clk *da7219_dai_wclk; 32 static struct clk *da7219_dai_bclk; 33 static struct clk *rt5682_dai_wclk; 34 static struct clk *rt5682_dai_bclk; 35 36 void *acp_soc_is_rltk_max(struct device *dev); 37 38 static int cz_da7219_init(struct snd_soc_pcm_runtime *rtd) 39 { 40 int ret; 41 struct snd_soc_card *card = rtd->card; 42 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); 43 struct snd_soc_component *component = codec_dai->component; 44 45 dev_info(rtd->dev, "codec dai name = %s\n", codec_dai->name); 46 47 ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK, 48 CZ_PLAT_CLK, SND_SOC_CLOCK_IN); 49 if (ret < 0) { 50 dev_err(rtd->dev, "can't set codec sysclk: %d\n", ret); 51 return ret; 52 } 53 54 ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_PLL, 55 CZ_PLAT_CLK, DA7219_PLL_FREQ_OUT_98304); 56 if (ret < 0) { 57 dev_err(rtd->dev, "can't set codec pll: %d\n", ret); 58 return ret; 59 } 60 61 da7219_dai_wclk = devm_clk_get(component->dev, "da7219-dai-wclk"); 62 if (IS_ERR(da7219_dai_wclk)) 63 return PTR_ERR(da7219_dai_wclk); 64 65 da7219_dai_bclk = devm_clk_get(component->dev, "da7219-dai-bclk"); 66 if (IS_ERR(da7219_dai_bclk)) 67 return PTR_ERR(da7219_dai_bclk); 68 69 ret = snd_soc_card_jack_new(card, "Headset Jack", 70 SND_JACK_HEADSET | SND_JACK_LINEOUT | 71 SND_JACK_BTN_0 | SND_JACK_BTN_1 | 72 SND_JACK_BTN_2 | SND_JACK_BTN_3, 73 &cz_jack); 74 if (ret) { 75 dev_err(card->dev, "HP jack creation failed %d\n", ret); 76 return ret; 77 } 78 79 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); 80 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_1, KEY_VOLUMEUP); 81 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN); 82 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_3, KEY_VOICECOMMAND); 83 84 snd_soc_component_set_jack(component, &cz_jack, NULL); 85 86 return 0; 87 } 88 89 static int da7219_clk_enable(struct snd_pcm_substream *substream) 90 { 91 int ret = 0; 92 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 93 94 /* 95 * Set wclk to 48000 because the rate constraint of this driver is 96 * 48000. ADAU7002 spec: "The ADAU7002 requires a BCLK rate that is 97 * minimum of 64x the LRCLK sample rate." DA7219 is the only clk 98 * source so for all codecs we have to limit bclk to 64X lrclk. 99 */ 100 clk_set_rate(da7219_dai_wclk, 48000); 101 clk_set_rate(da7219_dai_bclk, 48000 * 64); 102 ret = clk_prepare_enable(da7219_dai_bclk); 103 if (ret < 0) { 104 dev_err(rtd->dev, "can't enable master clock %d\n", ret); 105 return ret; 106 } 107 108 return ret; 109 } 110 111 static void da7219_clk_disable(void) 112 { 113 clk_disable_unprepare(da7219_dai_bclk); 114 } 115 116 static int cz_rt5682_init(struct snd_soc_pcm_runtime *rtd) 117 { 118 int ret; 119 struct snd_soc_card *card = rtd->card; 120 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); 121 struct snd_soc_component *component = codec_dai->component; 122 123 dev_info(codec_dai->dev, "codec dai name = %s\n", codec_dai->name); 124 125 /* Set codec sysclk */ 126 ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL2, 127 RT5682_PLL_FREQ, SND_SOC_CLOCK_IN); 128 if (ret < 0) { 129 dev_err(codec_dai->dev, 130 "Failed to set rt5682 SYSCLK: %d\n", ret); 131 return ret; 132 } 133 /* set codec PLL */ 134 ret = snd_soc_dai_set_pll(codec_dai, RT5682_PLL2, RT5682_PLL2_S_MCLK, 135 CZ_PLAT_CLK, RT5682_PLL_FREQ); 136 if (ret < 0) { 137 dev_err(codec_dai->dev, "can't set rt5682 PLL: %d\n", ret); 138 return ret; 139 } 140 141 rt5682_dai_wclk = devm_clk_get(component->dev, "rt5682-dai-wclk"); 142 if (IS_ERR(rt5682_dai_wclk)) 143 return PTR_ERR(rt5682_dai_wclk); 144 145 rt5682_dai_bclk = devm_clk_get(component->dev, "rt5682-dai-bclk"); 146 if (IS_ERR(rt5682_dai_bclk)) 147 return PTR_ERR(rt5682_dai_bclk); 148 149 ret = snd_soc_card_jack_new(card, "Headset Jack", 150 SND_JACK_HEADSET | SND_JACK_LINEOUT | 151 SND_JACK_BTN_0 | SND_JACK_BTN_1 | 152 SND_JACK_BTN_2 | SND_JACK_BTN_3, 153 &cz_jack); 154 if (ret) { 155 dev_err(card->dev, "HP jack creation failed %d\n", ret); 156 return ret; 157 } 158 159 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); 160 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_1, KEY_VOLUMEUP); 161 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN); 162 snd_jack_set_key(cz_jack.jack, SND_JACK_BTN_3, KEY_VOICECOMMAND); 163 164 ret = snd_soc_component_set_jack(component, &cz_jack, NULL); 165 if (ret) { 166 dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret); 167 return ret; 168 } 169 return 0; 170 } 171 172 static int rt5682_clk_enable(struct snd_pcm_substream *substream) 173 { 174 int ret; 175 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 176 177 /* 178 * Set wclk to 48000 because the rate constraint of this driver is 179 * 48000. ADAU7002 spec: "The ADAU7002 requires a BCLK rate that is 180 * minimum of 64x the LRCLK sample rate." RT5682 is the only clk 181 * source so for all codecs we have to limit bclk to 64X lrclk. 182 */ 183 ret = clk_set_rate(rt5682_dai_wclk, 48000); 184 if (ret) { 185 dev_err(rtd->dev, "Error setting wclk rate: %d\n", ret); 186 return ret; 187 } 188 ret = clk_set_rate(rt5682_dai_bclk, 48000 * 64); 189 if (ret) { 190 dev_err(rtd->dev, "Error setting bclk rate: %d\n", ret); 191 return ret; 192 } 193 ret = clk_prepare_enable(rt5682_dai_wclk); 194 if (ret < 0) { 195 dev_err(rtd->dev, "can't enable wclk %d\n", ret); 196 return ret; 197 } 198 return ret; 199 } 200 201 static void rt5682_clk_disable(void) 202 { 203 clk_disable_unprepare(rt5682_dai_wclk); 204 } 205 206 static const unsigned int channels[] = { 207 DUAL_CHANNEL, 208 }; 209 210 static const unsigned int rates[] = { 211 48000, 212 }; 213 214 static const struct snd_pcm_hw_constraint_list constraints_rates = { 215 .count = ARRAY_SIZE(rates), 216 .list = rates, 217 .mask = 0, 218 }; 219 220 static const struct snd_pcm_hw_constraint_list constraints_channels = { 221 .count = ARRAY_SIZE(channels), 222 .list = channels, 223 .mask = 0, 224 }; 225 226 static int cz_da7219_play_startup(struct snd_pcm_substream *substream) 227 { 228 struct snd_pcm_runtime *runtime = substream->runtime; 229 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 230 struct snd_soc_card *card = rtd->card; 231 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); 232 233 /* 234 * On this platform for PCM device we support stereo 235 */ 236 237 runtime->hw.channels_max = DUAL_CHANNEL; 238 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 239 &constraints_channels); 240 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 241 &constraints_rates); 242 243 machine->play_i2s_instance = I2S_SP_INSTANCE; 244 return da7219_clk_enable(substream); 245 } 246 247 static int cz_da7219_cap_startup(struct snd_pcm_substream *substream) 248 { 249 struct snd_pcm_runtime *runtime = substream->runtime; 250 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 251 struct snd_soc_card *card = rtd->card; 252 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); 253 254 /* 255 * On this platform for PCM device we support stereo 256 */ 257 258 runtime->hw.channels_max = DUAL_CHANNEL; 259 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 260 &constraints_channels); 261 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 262 &constraints_rates); 263 264 machine->cap_i2s_instance = I2S_SP_INSTANCE; 265 machine->capture_channel = CAP_CHANNEL1; 266 return da7219_clk_enable(substream); 267 } 268 269 static int cz_max_startup(struct snd_pcm_substream *substream) 270 { 271 struct snd_pcm_runtime *runtime = substream->runtime; 272 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 273 struct snd_soc_card *card = rtd->card; 274 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); 275 276 /* 277 * On this platform for PCM device we support stereo 278 */ 279 280 runtime->hw.channels_max = DUAL_CHANNEL; 281 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 282 &constraints_channels); 283 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 284 &constraints_rates); 285 286 machine->play_i2s_instance = I2S_BT_INSTANCE; 287 return da7219_clk_enable(substream); 288 } 289 290 static int cz_dmic0_startup(struct snd_pcm_substream *substream) 291 { 292 struct snd_pcm_runtime *runtime = substream->runtime; 293 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 294 struct snd_soc_card *card = rtd->card; 295 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); 296 297 /* 298 * On this platform for PCM device we support stereo 299 */ 300 301 runtime->hw.channels_max = DUAL_CHANNEL; 302 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 303 &constraints_channels); 304 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 305 &constraints_rates); 306 307 machine->cap_i2s_instance = I2S_BT_INSTANCE; 308 return da7219_clk_enable(substream); 309 } 310 311 static int cz_dmic1_startup(struct snd_pcm_substream *substream) 312 { 313 struct snd_pcm_runtime *runtime = substream->runtime; 314 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 315 struct snd_soc_card *card = rtd->card; 316 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); 317 318 /* 319 * On this platform for PCM device we support stereo 320 */ 321 322 runtime->hw.channels_max = DUAL_CHANNEL; 323 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 324 &constraints_channels); 325 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 326 &constraints_rates); 327 328 machine->cap_i2s_instance = I2S_SP_INSTANCE; 329 machine->capture_channel = CAP_CHANNEL0; 330 return da7219_clk_enable(substream); 331 } 332 333 static void cz_da7219_shutdown(struct snd_pcm_substream *substream) 334 { 335 da7219_clk_disable(); 336 } 337 338 static int cz_rt5682_play_startup(struct snd_pcm_substream *substream) 339 { 340 struct snd_pcm_runtime *runtime = substream->runtime; 341 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 342 struct snd_soc_card *card = rtd->card; 343 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); 344 345 /* 346 * On this platform for PCM device we support stereo 347 */ 348 349 runtime->hw.channels_max = DUAL_CHANNEL; 350 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 351 &constraints_channels); 352 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 353 &constraints_rates); 354 355 machine->play_i2s_instance = I2S_SP_INSTANCE; 356 return rt5682_clk_enable(substream); 357 } 358 359 static int cz_rt5682_cap_startup(struct snd_pcm_substream *substream) 360 { 361 struct snd_pcm_runtime *runtime = substream->runtime; 362 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 363 struct snd_soc_card *card = rtd->card; 364 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); 365 366 /* 367 * On this platform for PCM device we support stereo 368 */ 369 370 runtime->hw.channels_max = DUAL_CHANNEL; 371 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 372 &constraints_channels); 373 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 374 &constraints_rates); 375 376 machine->cap_i2s_instance = I2S_SP_INSTANCE; 377 machine->capture_channel = CAP_CHANNEL1; 378 return rt5682_clk_enable(substream); 379 } 380 381 static int cz_rt5682_max_startup(struct snd_pcm_substream *substream) 382 { 383 struct snd_pcm_runtime *runtime = substream->runtime; 384 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 385 struct snd_soc_card *card = rtd->card; 386 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); 387 388 /* 389 * On this platform for PCM device we support stereo 390 */ 391 392 runtime->hw.channels_max = DUAL_CHANNEL; 393 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 394 &constraints_channels); 395 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 396 &constraints_rates); 397 398 machine->play_i2s_instance = I2S_BT_INSTANCE; 399 return rt5682_clk_enable(substream); 400 } 401 402 static int cz_rt5682_dmic0_startup(struct snd_pcm_substream *substream) 403 { 404 struct snd_pcm_runtime *runtime = substream->runtime; 405 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 406 struct snd_soc_card *card = rtd->card; 407 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); 408 409 /* 410 * On this platform for PCM device we support stereo 411 */ 412 413 runtime->hw.channels_max = DUAL_CHANNEL; 414 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 415 &constraints_channels); 416 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 417 &constraints_rates); 418 419 machine->cap_i2s_instance = I2S_BT_INSTANCE; 420 return rt5682_clk_enable(substream); 421 } 422 423 static int cz_rt5682_dmic1_startup(struct snd_pcm_substream *substream) 424 { 425 struct snd_pcm_runtime *runtime = substream->runtime; 426 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); 427 struct snd_soc_card *card = rtd->card; 428 struct acp_platform_info *machine = snd_soc_card_get_drvdata(card); 429 430 /* 431 * On this platform for PCM device we support stereo 432 */ 433 434 runtime->hw.channels_max = DUAL_CHANNEL; 435 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 436 &constraints_channels); 437 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 438 &constraints_rates); 439 440 machine->cap_i2s_instance = I2S_SP_INSTANCE; 441 machine->capture_channel = CAP_CHANNEL0; 442 return rt5682_clk_enable(substream); 443 } 444 445 static void cz_rt5682_shutdown(struct snd_pcm_substream *substream) 446 { 447 rt5682_clk_disable(); 448 } 449 450 static const struct snd_soc_ops cz_da7219_play_ops = { 451 .startup = cz_da7219_play_startup, 452 .shutdown = cz_da7219_shutdown, 453 }; 454 455 static const struct snd_soc_ops cz_da7219_cap_ops = { 456 .startup = cz_da7219_cap_startup, 457 .shutdown = cz_da7219_shutdown, 458 }; 459 460 static const struct snd_soc_ops cz_max_play_ops = { 461 .startup = cz_max_startup, 462 .shutdown = cz_da7219_shutdown, 463 }; 464 465 static const struct snd_soc_ops cz_dmic0_cap_ops = { 466 .startup = cz_dmic0_startup, 467 .shutdown = cz_da7219_shutdown, 468 }; 469 470 static const struct snd_soc_ops cz_dmic1_cap_ops = { 471 .startup = cz_dmic1_startup, 472 .shutdown = cz_da7219_shutdown, 473 }; 474 475 static const struct snd_soc_ops cz_rt5682_play_ops = { 476 .startup = cz_rt5682_play_startup, 477 .shutdown = cz_rt5682_shutdown, 478 }; 479 480 static const struct snd_soc_ops cz_rt5682_cap_ops = { 481 .startup = cz_rt5682_cap_startup, 482 .shutdown = cz_rt5682_shutdown, 483 }; 484 485 static const struct snd_soc_ops cz_rt5682_max_play_ops = { 486 .startup = cz_rt5682_max_startup, 487 .shutdown = cz_rt5682_shutdown, 488 }; 489 490 static const struct snd_soc_ops cz_rt5682_dmic0_cap_ops = { 491 .startup = cz_rt5682_dmic0_startup, 492 .shutdown = cz_rt5682_shutdown, 493 }; 494 495 static const struct snd_soc_ops cz_rt5682_dmic1_cap_ops = { 496 .startup = cz_rt5682_dmic1_startup, 497 .shutdown = cz_rt5682_shutdown, 498 }; 499 500 SND_SOC_DAILINK_DEF(designware1, 501 DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.1.auto"))); 502 SND_SOC_DAILINK_DEF(designware2, 503 DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.2.auto"))); 504 SND_SOC_DAILINK_DEF(designware3, 505 DAILINK_COMP_ARRAY(COMP_CPU("designware-i2s.3.auto"))); 506 507 SND_SOC_DAILINK_DEF(dlgs, 508 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-DLGS7219:00", "da7219-hifi"))); 509 SND_SOC_DAILINK_DEF(rt5682, 510 DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5682:00", "rt5682-aif1"))); 511 SND_SOC_DAILINK_DEF(mx, 512 DAILINK_COMP_ARRAY(COMP_CODEC("MX98357A:00", "HiFi"))); 513 SND_SOC_DAILINK_DEF(adau, 514 DAILINK_COMP_ARRAY(COMP_CODEC("ADAU7002:00", "adau7002-hifi"))); 515 516 SND_SOC_DAILINK_DEF(platform, 517 DAILINK_COMP_ARRAY(COMP_PLATFORM("acp_audio_dma.0.auto"))); 518 519 static struct snd_soc_dai_link cz_dai_7219_98357[] = { 520 { 521 .name = "amd-da7219-play", 522 .stream_name = "Playback", 523 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF 524 | SND_SOC_DAIFMT_CBP_CFP, 525 .init = cz_da7219_init, 526 .dpcm_playback = 1, 527 .stop_dma_first = 1, 528 .ops = &cz_da7219_play_ops, 529 SND_SOC_DAILINK_REG(designware1, dlgs, platform), 530 }, 531 { 532 .name = "amd-da7219-cap", 533 .stream_name = "Capture", 534 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF 535 | SND_SOC_DAIFMT_CBP_CFP, 536 .dpcm_capture = 1, 537 .stop_dma_first = 1, 538 .ops = &cz_da7219_cap_ops, 539 SND_SOC_DAILINK_REG(designware2, dlgs, platform), 540 }, 541 { 542 .name = "amd-max98357-play", 543 .stream_name = "HiFi Playback", 544 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF 545 | SND_SOC_DAIFMT_CBP_CFP, 546 .dpcm_playback = 1, 547 .stop_dma_first = 1, 548 .ops = &cz_max_play_ops, 549 SND_SOC_DAILINK_REG(designware3, mx, platform), 550 }, 551 { 552 /* C panel DMIC */ 553 .name = "dmic0", 554 .stream_name = "DMIC0 Capture", 555 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF 556 | SND_SOC_DAIFMT_CBP_CFP, 557 .dpcm_capture = 1, 558 .stop_dma_first = 1, 559 .ops = &cz_dmic0_cap_ops, 560 SND_SOC_DAILINK_REG(designware3, adau, platform), 561 }, 562 { 563 /* A/B panel DMIC */ 564 .name = "dmic1", 565 .stream_name = "DMIC1 Capture", 566 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF 567 | SND_SOC_DAIFMT_CBP_CFP, 568 .dpcm_capture = 1, 569 .stop_dma_first = 1, 570 .ops = &cz_dmic1_cap_ops, 571 SND_SOC_DAILINK_REG(designware2, adau, platform), 572 }, 573 }; 574 575 static struct snd_soc_dai_link cz_dai_5682_98357[] = { 576 { 577 .name = "amd-rt5682-play", 578 .stream_name = "Playback", 579 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF 580 | SND_SOC_DAIFMT_CBP_CFP, 581 .init = cz_rt5682_init, 582 .dpcm_playback = 1, 583 .stop_dma_first = 1, 584 .ops = &cz_rt5682_play_ops, 585 SND_SOC_DAILINK_REG(designware1, rt5682, platform), 586 }, 587 { 588 .name = "amd-rt5682-cap", 589 .stream_name = "Capture", 590 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF 591 | SND_SOC_DAIFMT_CBP_CFP, 592 .dpcm_capture = 1, 593 .stop_dma_first = 1, 594 .ops = &cz_rt5682_cap_ops, 595 SND_SOC_DAILINK_REG(designware2, rt5682, platform), 596 }, 597 { 598 .name = "amd-max98357-play", 599 .stream_name = "HiFi Playback", 600 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF 601 | SND_SOC_DAIFMT_CBP_CFP, 602 .dpcm_playback = 1, 603 .stop_dma_first = 1, 604 .ops = &cz_rt5682_max_play_ops, 605 SND_SOC_DAILINK_REG(designware3, mx, platform), 606 }, 607 { 608 /* C panel DMIC */ 609 .name = "dmic0", 610 .stream_name = "DMIC0 Capture", 611 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF 612 | SND_SOC_DAIFMT_CBP_CFP, 613 .dpcm_capture = 1, 614 .stop_dma_first = 1, 615 .ops = &cz_rt5682_dmic0_cap_ops, 616 SND_SOC_DAILINK_REG(designware3, adau, platform), 617 }, 618 { 619 /* A/B panel DMIC */ 620 .name = "dmic1", 621 .stream_name = "DMIC1 Capture", 622 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF 623 | SND_SOC_DAIFMT_CBP_CFP, 624 .dpcm_capture = 1, 625 .stop_dma_first = 1, 626 .ops = &cz_rt5682_dmic1_cap_ops, 627 SND_SOC_DAILINK_REG(designware2, adau, platform), 628 }, 629 }; 630 631 static const struct snd_soc_dapm_widget cz_widgets[] = { 632 SND_SOC_DAPM_HP("Headphones", NULL), 633 SND_SOC_DAPM_SPK("Speakers", NULL), 634 SND_SOC_DAPM_MIC("Headset Mic", NULL), 635 SND_SOC_DAPM_MIC("Int Mic", NULL), 636 }; 637 638 static const struct snd_soc_dapm_route cz_audio_route[] = { 639 {"Headphones", NULL, "HPL"}, 640 {"Headphones", NULL, "HPR"}, 641 {"MIC", NULL, "Headset Mic"}, 642 {"Speakers", NULL, "Speaker"}, 643 {"PDM_DAT", NULL, "Int Mic"}, 644 }; 645 646 static const struct snd_soc_dapm_route cz_rt5682_audio_route[] = { 647 {"Headphones", NULL, "HPOL"}, 648 {"Headphones", NULL, "HPOR"}, 649 {"IN1P", NULL, "Headset Mic"}, 650 {"Speakers", NULL, "Speaker"}, 651 {"PDM_DAT", NULL, "Int Mic"}, 652 }; 653 654 static const struct snd_kcontrol_new cz_mc_controls[] = { 655 SOC_DAPM_PIN_SWITCH("Headphones"), 656 SOC_DAPM_PIN_SWITCH("Speakers"), 657 SOC_DAPM_PIN_SWITCH("Headset Mic"), 658 SOC_DAPM_PIN_SWITCH("Int Mic"), 659 }; 660 661 static struct snd_soc_card cz_card = { 662 .name = "acpd7219m98357", 663 .owner = THIS_MODULE, 664 .dai_link = cz_dai_7219_98357, 665 .num_links = ARRAY_SIZE(cz_dai_7219_98357), 666 .dapm_widgets = cz_widgets, 667 .num_dapm_widgets = ARRAY_SIZE(cz_widgets), 668 .dapm_routes = cz_audio_route, 669 .num_dapm_routes = ARRAY_SIZE(cz_audio_route), 670 .controls = cz_mc_controls, 671 .num_controls = ARRAY_SIZE(cz_mc_controls), 672 }; 673 674 static struct snd_soc_card cz_rt5682_card = { 675 .name = "acpr5682m98357", 676 .owner = THIS_MODULE, 677 .dai_link = cz_dai_5682_98357, 678 .num_links = ARRAY_SIZE(cz_dai_5682_98357), 679 .dapm_widgets = cz_widgets, 680 .num_dapm_widgets = ARRAY_SIZE(cz_widgets), 681 .dapm_routes = cz_rt5682_audio_route, 682 .controls = cz_mc_controls, 683 .num_controls = ARRAY_SIZE(cz_mc_controls), 684 }; 685 686 void *acp_soc_is_rltk_max(struct device *dev) 687 { 688 const struct acpi_device_id *match; 689 690 match = acpi_match_device(dev->driver->acpi_match_table, dev); 691 if (!match) 692 return NULL; 693 return (void *)match->driver_data; 694 } 695 696 static struct regulator_consumer_supply acp_da7219_supplies[] = { 697 REGULATOR_SUPPLY("VDD", "i2c-DLGS7219:00"), 698 REGULATOR_SUPPLY("VDDMIC", "i2c-DLGS7219:00"), 699 REGULATOR_SUPPLY("VDDIO", "i2c-DLGS7219:00"), 700 REGULATOR_SUPPLY("IOVDD", "ADAU7002:00"), 701 }; 702 703 static struct regulator_init_data acp_da7219_data = { 704 .constraints = { 705 .always_on = 1, 706 }, 707 .num_consumer_supplies = ARRAY_SIZE(acp_da7219_supplies), 708 .consumer_supplies = acp_da7219_supplies, 709 }; 710 711 static struct regulator_config acp_da7219_cfg = { 712 .init_data = &acp_da7219_data, 713 }; 714 715 static struct regulator_ops acp_da7219_ops = { 716 }; 717 718 static const struct regulator_desc acp_da7219_desc = { 719 .name = "reg-fixed-1.8V", 720 .type = REGULATOR_VOLTAGE, 721 .owner = THIS_MODULE, 722 .ops = &acp_da7219_ops, 723 .fixed_uV = 1800000, /* 1.8V */ 724 .n_voltages = 1, 725 }; 726 727 static int cz_probe(struct platform_device *pdev) 728 { 729 int ret; 730 struct snd_soc_card *card; 731 struct acp_platform_info *machine; 732 struct regulator_dev *rdev; 733 struct device *dev = &pdev->dev; 734 735 card = (struct snd_soc_card *)acp_soc_is_rltk_max(dev); 736 if (!card) 737 return -ENODEV; 738 if (!strcmp(card->name, "acpd7219m98357")) { 739 acp_da7219_cfg.dev = &pdev->dev; 740 rdev = devm_regulator_register(&pdev->dev, &acp_da7219_desc, 741 &acp_da7219_cfg); 742 if (IS_ERR(rdev)) { 743 dev_err(&pdev->dev, "Failed to register regulator: %d\n", 744 (int)PTR_ERR(rdev)); 745 return -EINVAL; 746 } 747 } 748 749 machine = devm_kzalloc(&pdev->dev, sizeof(struct acp_platform_info), 750 GFP_KERNEL); 751 if (!machine) 752 return -ENOMEM; 753 card->dev = &pdev->dev; 754 platform_set_drvdata(pdev, card); 755 snd_soc_card_set_drvdata(card, machine); 756 ret = devm_snd_soc_register_card(&pdev->dev, card); 757 if (ret) { 758 return dev_err_probe(&pdev->dev, ret, 759 "devm_snd_soc_register_card(%s) failed\n", 760 card->name); 761 } 762 acp_bt_uart_enable = !device_property_read_bool(&pdev->dev, 763 "bt-pad-enable"); 764 return 0; 765 } 766 767 #ifdef CONFIG_ACPI 768 static const struct acpi_device_id cz_audio_acpi_match[] = { 769 { "AMD7219", (unsigned long)&cz_card }, 770 { "AMDI5682", (unsigned long)&cz_rt5682_card}, 771 {}, 772 }; 773 MODULE_DEVICE_TABLE(acpi, cz_audio_acpi_match); 774 #endif 775 776 static struct platform_driver cz_pcm_driver = { 777 .driver = { 778 .name = "cz-da7219-max98357a", 779 .acpi_match_table = ACPI_PTR(cz_audio_acpi_match), 780 .pm = &snd_soc_pm_ops, 781 }, 782 .probe = cz_probe, 783 }; 784 785 module_platform_driver(cz_pcm_driver); 786 787 MODULE_AUTHOR("akshu.agrawal@amd.com"); 788 MODULE_AUTHOR("Vijendar.Mukunda@amd.com"); 789 MODULE_DESCRIPTION("DA7219, RT5682 & MAX98357A audio support"); 790 MODULE_LICENSE("GPL v2"); 791