Lines Matching +full:codec +full:- +full:aif1
1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright(c) 2019-2020 Intel Corporation.
5 * Intel SOF Machine Driver with Realtek rt5682 Codec
6 * and speaker codec MAX98357A or RT1015.
22 #include <sound/soc-acpi.h>
26 #include "../common/soc-intel-quirks.h"
31 /* Driver-specific board quirks: from bit 0 to 7 */
40 sof_rt5682_quirk = (unsigned long)id->driver_data; in sof_rt5682_quirk_cb()
57 DMI_MATCH(DMI_PRODUCT_NAME, "UP-CHT01"),
74 DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98373_ALC5682I_I2S_UP4"),
86 DMI_MATCH(DMI_OEM_STRING, "AUDIO-ADL_MAX98373_ALC5682I_I2S"),
97 DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98390_ALC5682I_I2S"),
108 DMI_MATCH(DMI_OEM_STRING, "AUDIO-MAX98360_ALC5682I_I2S_AMP_SSP2"),
143 struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card); in sof_rt5682_codec_init()
144 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; in sof_rt5682_codec_init()
145 struct snd_soc_jack *jack = &ctx->headset_jack; in sof_rt5682_codec_init()
149 if (ctx->rt5682.mclk_en) { in sof_rt5682_codec_init()
152 dev_err(rtd->dev, "invalid mclk freq %d\n", mclk_freq); in sof_rt5682_codec_init()
153 return -EINVAL; in sof_rt5682_codec_init()
158 dev_info(rtd->dev, "enable ASRC\n"); in sof_rt5682_codec_init()
160 switch (ctx->codec_type) { in sof_rt5682_codec_init()
184 dev_err(rtd->dev, "invalid codec type %d\n", in sof_rt5682_codec_init()
185 ctx->codec_type); in sof_rt5682_codec_init()
186 return -EINVAL; in sof_rt5682_codec_init()
190 if (ctx->rt5682.is_legacy_cpu) { in sof_rt5682_codec_init()
201 ret = clk_prepare_enable(ctx->rt5682.mclk); in sof_rt5682_codec_init()
203 clk_disable_unprepare(ctx->rt5682.mclk); in sof_rt5682_codec_init()
205 ret = clk_set_rate(ctx->rt5682.mclk, 19200000); in sof_rt5682_codec_init()
208 dev_err(rtd->dev, "unable to set MCLK rate\n"); in sof_rt5682_codec_init()
216 ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack", in sof_rt5682_codec_init()
224 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret); in sof_rt5682_codec_init()
228 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE); in sof_rt5682_codec_init()
229 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND); in sof_rt5682_codec_init()
230 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP); in sof_rt5682_codec_init()
231 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN); in sof_rt5682_codec_init()
233 if (ctx->codec_type == CODEC_RT5650) { in sof_rt5682_codec_init()
240 dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret); in sof_rt5682_codec_init()
249 struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component; in sof_rt5682_codec_exit()
258 struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card); in sof_rt5682_hw_params()
262 if (ctx->rt5682.mclk_en) { in sof_rt5682_hw_params()
263 if (ctx->rt5682.is_legacy_cpu) { in sof_rt5682_hw_params()
264 ret = clk_prepare_enable(ctx->rt5682.mclk); in sof_rt5682_hw_params()
266 dev_err(rtd->dev, in sof_rt5682_hw_params()
272 switch (ctx->codec_type) { in sof_rt5682_hw_params()
283 dev_err(rtd->dev, "invalid codec type %d\n", in sof_rt5682_hw_params()
284 ctx->codec_type); in sof_rt5682_hw_params()
285 return -EINVAL; in sof_rt5682_hw_params()
291 dev_err(rtd->dev, "invalid mclk freq %d\n", pll_in); in sof_rt5682_hw_params()
292 return -EINVAL; in sof_rt5682_hw_params()
295 switch (ctx->codec_type) { in sof_rt5682_hw_params()
306 dev_err(rtd->dev, "invalid codec type %d\n", in sof_rt5682_hw_params()
307 ctx->codec_type); in sof_rt5682_hw_params()
308 return -EINVAL; in sof_rt5682_hw_params()
314 dev_err(rtd->dev, "invalid bclk freq %d\n", pll_in); in sof_rt5682_hw_params()
315 return -EINVAL; in sof_rt5682_hw_params()
323 switch (ctx->codec_type) { in sof_rt5682_hw_params()
334 dev_err(rtd->dev, "invalid codec type %d\n", in sof_rt5682_hw_params()
335 ctx->codec_type); in sof_rt5682_hw_params()
336 return -EINVAL; in sof_rt5682_hw_params()
339 switch (ctx->codec_type) { in sof_rt5682_hw_params()
341 pll_id = 0; /* not used in codec driver */ in sof_rt5682_hw_params()
369 dev_err(rtd->dev, "invalid codec type %d\n", ctx->codec_type); in sof_rt5682_hw_params()
370 return -EINVAL; in sof_rt5682_hw_params()
373 /* Configure pll for codec */ in sof_rt5682_hw_params()
377 dev_err(rtd->dev, "snd_soc_dai_set_pll err = %d\n", ret); in sof_rt5682_hw_params()
380 /* Configure sysclk for codec */ in sof_rt5682_hw_params()
384 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret); in sof_rt5682_hw_params()
393 dev_err(rtd->dev, "set TDM slot err:%d\n", ret); in sof_rt5682_hw_params()
407 struct snd_soc_dapm_context *dapm = &card->dapm; in sof_card_late_probe()
410 if (ctx->amp_type == CODEC_MAX98373) { in sof_card_late_probe()
433 /* HP jack connectors - unknown if we have jack detection */
460 struct snd_soc_card *card = rtd->card; in rt5650_spk_init()
463 ret = snd_soc_dapm_new_controls(&card->dapm, rt5650_spk_widgets, in rt5650_spk_init()
466 dev_err(rtd->dev, "fail to add rt5650 spk widgets, ret %d\n", in rt5650_spk_init()
474 dev_err(rtd->dev, "fail to add rt5650 spk kcontrols, ret %d\n", in rt5650_spk_init()
479 ret = snd_soc_dapm_add_routes(&card->dapm, rt5650_spk_dapm_routes, in rt5650_spk_init()
482 dev_err(rtd->dev, "fail to add dapm routes, ret=%d\n", ret); in rt5650_spk_init()
487 /* sof audio machine driver for rt5682 codec */
489 .name = "rt5682", /* the sof- prefix is added by the core */
503 .name = "i2c-10EC5682:00",
504 .dai_name = "rt5682-aif1",
510 .name = "i2c-RTL5682:00",
511 .dai_name = "rt5682s-aif1",
517 .name = "i2c-10EC5650:00",
518 .dai_name = "rt5645-aif1",
521 .name = "i2c-10EC5650:00",
522 .dai_name = "rt5645-aif2",
536 if (!ctx->codec_link) { in sof_card_dai_links_create()
537 dev_err(dev, "codec link not available"); in sof_card_dai_links_create()
538 return -EINVAL; in sof_card_dai_links_create()
541 /* codec-specific fields for headphone codec */ in sof_card_dai_links_create()
542 switch (ctx->codec_type) { in sof_card_dai_links_create()
544 ctx->codec_link->codecs = &rt5650_components[0]; in sof_card_dai_links_create()
545 ctx->codec_link->num_codecs = 1; in sof_card_dai_links_create()
548 ctx->codec_link->codecs = rt5682_component; in sof_card_dai_links_create()
549 ctx->codec_link->num_codecs = ARRAY_SIZE(rt5682_component); in sof_card_dai_links_create()
552 ctx->codec_link->codecs = rt5682s_component; in sof_card_dai_links_create()
553 ctx->codec_link->num_codecs = ARRAY_SIZE(rt5682s_component); in sof_card_dai_links_create()
556 dev_err(dev, "invalid codec type %d\n", ctx->codec_type); in sof_card_dai_links_create()
557 return -EINVAL; in sof_card_dai_links_create()
560 ctx->codec_link->init = sof_rt5682_codec_init; in sof_card_dai_links_create()
561 ctx->codec_link->exit = sof_rt5682_codec_exit; in sof_card_dai_links_create()
562 ctx->codec_link->ops = &sof_rt5682_ops; in sof_card_dai_links_create()
564 if (!ctx->rt5682.is_legacy_cpu) { in sof_card_dai_links_create()
574 ctx->codec_link->ignore_pmdown_time = 1; in sof_card_dai_links_create()
577 if (ctx->amp_type == CODEC_NONE) in sof_card_dai_links_create()
580 if (!ctx->amp_link) { in sof_card_dai_links_create()
582 return -EINVAL; in sof_card_dai_links_create()
585 /* codec-specific fields for speaker amplifier */ in sof_card_dai_links_create()
586 switch (ctx->amp_type) { in sof_card_dai_links_create()
588 max_98357a_dai_link(ctx->amp_link); in sof_card_dai_links_create()
591 max_98360a_dai_link(ctx->amp_link); in sof_card_dai_links_create()
594 max_98373_dai_link(dev, ctx->amp_link); in sof_card_dai_links_create()
597 max_98390_dai_link(dev, ctx->amp_link); in sof_card_dai_links_create()
600 sof_rt1011_dai_link(dev, ctx->amp_link); in sof_card_dai_links_create()
603 sof_rt1015_dai_link(ctx->amp_link); in sof_card_dai_links_create()
606 sof_rt1015p_dai_link(ctx->amp_link); in sof_card_dai_links_create()
609 sof_rt1019p_dai_link(ctx->amp_link); in sof_card_dai_links_create()
613 ctx->amp_link->codecs = &rt5650_components[1]; in sof_card_dai_links_create()
614 ctx->amp_link->num_codecs = 1; in sof_card_dai_links_create()
615 ctx->amp_link->init = rt5650_spk_init; in sof_card_dai_links_create()
616 ctx->amp_link->ops = &sof_rt5682_ops; in sof_card_dai_links_create()
619 dev_err(dev, "invalid amp type %d\n", ctx->amp_type); in sof_card_dai_links_create()
620 return -EINVAL; in sof_card_dai_links_create()
636 struct snd_soc_acpi_mach *mach = pdev->dev.platform_data; in sof_audio_probe()
641 if (pdev->id_entry && pdev->id_entry->driver_data) in sof_audio_probe()
642 sof_rt5682_quirk = (unsigned long)pdev->id_entry->driver_data; in sof_audio_probe()
646 dev_dbg(&pdev->dev, "sof_rt5682_quirk = %lx\n", sof_rt5682_quirk); in sof_audio_probe()
649 ctx = sof_intel_board_get_ctx(&pdev->dev, sof_rt5682_quirk); in sof_audio_probe()
651 return -ENOMEM; in sof_audio_probe()
653 if (ctx->codec_type == CODEC_RT5650) { in sof_audio_probe()
654 card_name = devm_kstrdup(&pdev->dev, "rt5650", GFP_KERNEL); in sof_audio_probe()
656 return -ENOMEM; in sof_audio_probe()
661 if (ctx->amp_type == CODEC_NONE) in sof_audio_probe()
662 ctx->amp_type = CODEC_RT5650; in sof_audio_probe()
665 if (mach->mach_params.codec_mask & IDISP_CODEC_MASK) in sof_audio_probe()
666 ctx->hdmi.idisp_codec = true; in sof_audio_probe()
669 ctx->rt5682.is_legacy_cpu = true; in sof_audio_probe()
670 ctx->dmic_be_num = 0; in sof_audio_probe()
672 ctx->hdmi_num = 0; in sof_audio_probe()
675 ctx->dmic_be_num = 1; in sof_audio_probe()
678 ctx->link_order_overwrite = GLK_LINK_ORDER; in sof_audio_probe()
680 /* backward-compatible with existing devices */ in sof_audio_probe()
681 switch (ctx->amp_type) { in sof_audio_probe()
683 card_name = devm_kstrdup(&pdev->dev, "glkrt5682max", in sof_audio_probe()
686 return -ENOMEM; in sof_audio_probe()
694 /* backward-compatible with existing devices */ in sof_audio_probe()
695 switch (ctx->amp_type) { in sof_audio_probe()
697 card_name = devm_kstrdup(&pdev->dev, "cml_rt1011_rt5682", in sof_audio_probe()
700 return -ENOMEM; in sof_audio_probe()
710 ctx->rt5682.mclk_en = true; in sof_audio_probe()
713 if (ctx->rt5682.is_legacy_cpu) { in sof_audio_probe()
714 ctx->rt5682.mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3"); in sof_audio_probe()
715 if (IS_ERR(ctx->rt5682.mclk)) { in sof_audio_probe()
716 ret = PTR_ERR(ctx->rt5682.mclk); in sof_audio_probe()
718 dev_err(&pdev->dev, in sof_audio_probe()
724 ret = clk_prepare_enable(ctx->rt5682.mclk); in sof_audio_probe()
726 dev_err(&pdev->dev, in sof_audio_probe()
734 ret = sof_card_dai_links_create(&pdev->dev, &sof_audio_card_rt5682, ctx); in sof_audio_probe()
739 switch (ctx->amp_type) { in sof_audio_probe()
744 max_98390_set_codec_conf(&pdev->dev, &sof_audio_card_rt5682); in sof_audio_probe()
747 sof_rt1011_codec_conf(&pdev->dev, &sof_audio_card_rt5682); in sof_audio_probe()
760 /* no codec conf required */ in sof_audio_probe()
763 dev_err(&pdev->dev, "invalid amp type %d\n", ctx->amp_type); in sof_audio_probe()
764 return -EINVAL; in sof_audio_probe()
767 sof_audio_card_rt5682.dev = &pdev->dev; in sof_audio_probe()
771 mach->mach_params.platform); in sof_audio_probe()
777 return devm_snd_soc_register_card(&pdev->dev, in sof_audio_probe()