From 33a45472abafb2e73dd3e1aed12c4bb069fa733b Mon Sep 17 00:00:00 2001 From: Sameer Pujar Date: Fri, 15 Mar 2024 13:31:55 +0000 Subject: [PATCH] ASoC: tegra: Add I2S controls for format/mode There are test cases in ap_audio, which check for different data formats and producer/consumer modes for Tegra I2S and external codec I2S. Add these controls for a full GVS coverage. Two types of DAI links are handled: - Normal/codec2codec DAI links where the DAI mapping is done by default between Tegra and external codec I2S. So just calling legacy tegra_machine_add_i2s_codec_controls() API from override driver is good enough. - For DPCM case, the DAIs are not directly mapped and thus codec is dummy for Tegra I2S. Hence for this DAPM function snd_soc_dapm_dai_get_connected_widgets() is used to find the connected codec widget and apply the complementary DAI format setting. Also use this opportunity to cleanup Linux version code check. It is now recommended to define a macro for the relevant kernel version and macro name is related to what actually is changing for a kernel version. Bug 4451662 Bug 4453772 Change-Id: I881838411af5498e4d7f1dec76b3c11ad05de12b Signed-off-by: Sameer Pujar Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3097585 GVS: Gerrit_Virtual_Submit Reviewed-by: Sharad Gupta Reviewed-by: Mohan kumar Reviewed-by: svcacv --- sound/soc/tegra/tegra_asoc_machine.c | 79 ++++++++++++++++++++++++--- sound/soc/tegra/tegra_mixer_control.c | 16 ++++-- 2 files changed, 82 insertions(+), 13 deletions(-) diff --git a/sound/soc/tegra/tegra_asoc_machine.c b/sound/soc/tegra/tegra_asoc_machine.c index 8dbd1573..a59f9758 100644 --- a/sound/soc/tegra/tegra_asoc_machine.c +++ b/sound/soc/tegra/tegra_asoc_machine.c @@ -1,15 +1,13 @@ // SPDX-License-Identifier: GPL-2.0-only -/* - * tegra_asoc_machine.c - Tegra DAI links parser - * - * Copyright (c) 2014-2023 NVIDIA CORPORATION. All rights reserved. - * - */ +// SPDX-FileCopyrightText: Copyright (c) 2014-2024 NVIDIA CORPORATION. All rights reserved. +// +// tegra_asoc_machine.c - Tegra DAI links parser #include #include #include +#include #include #include #include @@ -649,11 +647,74 @@ struct tegra_machine_control_data { unsigned int master_mode; }; +static struct snd_soc_pcm_runtime *tegra_get_be(struct snd_soc_card *card, + struct snd_soc_dapm_widget *widget, + int stream) +{ + struct snd_soc_pcm_runtime *be; + struct snd_soc_dapm_widget *w; + struct snd_soc_dai *dai; + int i; + + for_each_card_rtds(card, be) { + for_each_rtd_dais(be, i, dai) { + w = snd_soc_dai_get_widget(dai, stream); + if (w == widget) + return be; + } + } + + return NULL; +} + +/* + * In case of DPCM DAI link for i2s<->codec, note that the DAIs are + * not directly mapped. The 'rtd' for codec is different in case of + * a DPCM DAI link. + */ +static int dpcm_runtime_set_dai_fmt(struct snd_soc_pcm_runtime *rtd, + unsigned int fmt) +{ +#if defined(NV_SND_SOC_RTD_TO_CODEC_PRESENT) /* Linux 6.7*/ + struct snd_soc_dai *dai = snd_soc_rtd_to_cpu(rtd, 0); +#else + struct snd_soc_dai *dai = asoc_rtd_to_cpu(rtd, 0); +#endif + struct snd_soc_dapm_widget_list *list; + int stream = SNDRV_PCM_STREAM_PLAYBACK; + struct snd_soc_pcm_runtime *be; + struct snd_soc_dapm_widget *widget; + int i, ret; + + /* nothing to be done if it is a normal sound card */ + if (!rtd->card->component_chaining) + return 0; + + snd_soc_dapm_dai_get_connected_widgets(dai, stream, &list, NULL); + + for_each_dapm_widgets(list, i, widget) { + if (widget->id != snd_soc_dapm_dai_in && + widget->id != snd_soc_dapm_dai_out) + continue; + + be = tegra_get_be(rtd->card, widget, stream); + if (!be) + continue; + + ret = snd_soc_runtime_set_dai_fmt(be, fmt); + if (ret < 0) + return ret; + } + + return 0; +} + static int tegra_machine_codec_set_dai_fmt(struct snd_soc_pcm_runtime *rtd, unsigned int frame_mode, unsigned int master_mode) { unsigned int fmt = rtd->dai_link->dai_fmt; + int ret; if (frame_mode) { fmt &= ~SND_SOC_DAIFMT_FORMAT_MASK; @@ -670,7 +731,11 @@ static int tegra_machine_codec_set_dai_fmt(struct snd_soc_pcm_runtime *rtd, fmt |= SND_SOC_DAIFMT_CBS_CFS; } - return snd_soc_runtime_set_dai_fmt(rtd, fmt); + ret = snd_soc_runtime_set_dai_fmt(rtd, fmt); + if (ret < 0) + return ret; + + return dpcm_runtime_set_dai_fmt(rtd, fmt); } /* diff --git a/sound/soc/tegra/tegra_mixer_control.c b/sound/soc/tegra/tegra_mixer_control.c index 0d16ffb3..cfa05f5d 100644 --- a/sound/soc/tegra/tegra_mixer_control.c +++ b/sound/soc/tegra/tegra_mixer_control.c @@ -32,6 +32,8 @@ #include #include +#include "tegra_asoc_machine.h" + static int dai_get_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { @@ -325,20 +327,20 @@ static int tegra_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai; /* Fixup CPU DAI */ -#if KERNEL_VERSION(6, 7, 0) > LINUX_VERSION_CODE - dai = asoc_rtd_to_cpu(rtd, 0); -#else +#if defined(NV_SND_SOC_RTD_TO_CODEC_PRESENT) /* Linux 6.7*/ dai = snd_soc_rtd_to_cpu(rtd, 0); +#else + dai = asoc_rtd_to_cpu(rtd, 0); #endif if (!dai_is_dummy(dai)) tegra_dai_fixup(dai, params); /* Fixup Codec DAI */ -#if KERNEL_VERSION(6, 7, 0) > LINUX_VERSION_CODE - dai = asoc_rtd_to_codec(rtd, 0); -#else +#if defined(NV_SND_SOC_RTD_TO_CODEC_PRESENT) /* Linux 6.7*/ dai = snd_soc_rtd_to_codec(rtd, 0); +#else + dai = asoc_rtd_to_codec(rtd, 0); #endif if (!dai_is_dummy(dai)) @@ -402,6 +404,8 @@ static int tegra_mixer_control_probe(struct platform_device *pdev) ARRAY_SIZE(tegra210_mixer_ctls)); } + tegra_machine_add_i2s_codec_controls(card); + /* Fixup callback for BE codec2codec links */ for_each_card_rtds(card, rtd) { /* Skip FE links for sound card with DPCM routes for AHUB */