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