Skip to content

Commit

Permalink
ASoC: Intel: sof_rt5682: support NHLT detection
Browse files Browse the repository at this point in the history
Add a quirk flag SOF_TPLG_NHLT_SSP_DETECT to detect the SSP port
number and register dai links of headphone codec, speaker amplifier,
and Bluetooth offload when receiving NHLT table in IPC4 topology.

Signed-off-by: Brent Lu <brent.lu@intel.com>
  • Loading branch information
brentlu committed Jul 26, 2023
1 parent 7dfa15a commit 58c2492
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions sound/soc/intel/boards/sof_rt5682.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
#define SOF_MAX98390_SPEAKER_AMP_PRESENT BIT(24)
#define SOF_MAX98390_TWEETER_SPEAKER_PRESENT BIT(25)
#define SOF_RT1019_SPEAKER_AMP_PRESENT BIT(26)
#define SOF_TPLG_NHLT_SSP_DETECT BIT(28)


/* Default: MCLK on, MCLK 19.2M, SSP0 */
Expand Down Expand Up @@ -531,6 +532,22 @@ static int sof_card_late_probe(struct snd_soc_card *card)
return hdac_hdmi_jack_port_init(component, &card->dapm);
}

static int soc_card_add_dai_link(struct snd_soc_card *card,
struct snd_soc_dai_link *dai_link)
{
if (!strcmp(dai_link->name, "NHLT-RENDER-CAPTURE") ||
!strcmp(dai_link->name, "NHLT-RENDER-ONLY") ||
!strcmp(dai_link->name, "NHLT-CAPTURE-ONLY") ||
!strcmp(dai_link->name, "NHLT-BT")) {
/* fixup and register this dai link later when we receive NHLT
* table from IPC4 topology
*/
dai_link->ignore = true;
}

return 0;
}

static const struct snd_kcontrol_new sof_controls[] = {
SOC_DAPM_PIN_SWITCH("Headphone Jack"),
SOC_DAPM_PIN_SWITCH("Headset Mic"),
Expand Down Expand Up @@ -643,8 +660,12 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
goto devm_err;

/* codec SSP */
links[id].name = devm_kasprintf(dev, GFP_KERNEL,
"SSP%d-Codec", ssp_codec);
if (sof_rt5682_quirk & SOF_TPLG_NHLT_SSP_DETECT)
links[id].name = devm_kasprintf(dev, GFP_KERNEL,
"NHLT-RENDER-CAPTURE");
else
links[id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec",
ssp_codec);
if (!links[id].name)
goto devm_err;

Expand Down Expand Up @@ -767,8 +788,12 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,

/* speaker amp */
if (sof_rt5682_quirk & SOF_SPEAKER_AMP_PRESENT) {
links[id].name = devm_kasprintf(dev, GFP_KERNEL,
"SSP%d-Codec", ssp_amp);
if (sof_rt5682_quirk & SOF_TPLG_NHLT_SSP_DETECT)
links[id].name = devm_kasprintf(dev, GFP_KERNEL,
"NHLT-RENDER-ONLY");
else
links[id].name = devm_kasprintf(dev, GFP_KERNEL,
"SSP%d-Codec", ssp_amp);
if (!links[id].name)
goto devm_err;

Expand Down Expand Up @@ -838,23 +863,29 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
int port = (sof_rt5682_quirk & SOF_BT_OFFLOAD_SSP_MASK) >>
SOF_BT_OFFLOAD_SSP_SHIFT;

if (sof_rt5682_quirk & SOF_TPLG_NHLT_SSP_DETECT)
links[id].name = devm_kasprintf(dev, GFP_KERNEL,
"NHLT-BT");
else
links[id].name = devm_kasprintf(dev, GFP_KERNEL,
"SSP%d-BT", port);
if (!links[id].name)
goto devm_err;

links[id].id = id;
links[id].cpus = &cpus[id];
links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
"SSP%d Pin", port);
if (!links[id].cpus->dai_name)
goto devm_err;
links[id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-BT", port);
if (!links[id].name)
goto devm_err;
links[id].num_cpus = 1;
links[id].codecs = &asoc_dummy_dlc;
links[id].num_codecs = 1;
links[id].platforms = platform_component;
links[id].num_platforms = ARRAY_SIZE(platform_component);
links[id].dpcm_playback = 1;
links[id].dpcm_capture = 1;
links[id].no_pcm = 1;
links[id].num_cpus = 1;
}

return links;
Expand Down Expand Up @@ -972,6 +1003,9 @@ static int sof_audio_probe(struct platform_device *pdev)
if (sof_rt5682_quirk & SOF_RT1015_SPEAKER_AMP_PRESENT)
sof_rt1015_codec_conf(&sof_audio_card_rt5682);

if (sof_rt5682_quirk & SOF_TPLG_NHLT_SSP_DETECT)
sof_audio_card_rt5682.add_dai_link = soc_card_add_dai_link;

INIT_LIST_HEAD(&ctx->hdmi_pcm_list);

sof_audio_card_rt5682.dev = &pdev->dev;
Expand Down

0 comments on commit 58c2492

Please sign in to comment.