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 <spujar@nvidia.com>
Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3097585
GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
Reviewed-by: Sharad Gupta <sharadg@nvidia.com>
Reviewed-by: Mohan kumar <mkumard@nvidia.com>
Reviewed-by: svcacv <svcacv@nvidia.com>
This commit is contained in:
Sameer Pujar
2024-03-15 13:31:55 +00:00
committed by mobile promotions
parent 26987b5170
commit 33a45472ab
2 changed files with 82 additions and 13 deletions

View File

@@ -1,15 +1,13 @@
// SPDX-License-Identifier: GPL-2.0-only // SPDX-License-Identifier: GPL-2.0-only
/* // SPDX-FileCopyrightText: Copyright (c) 2014-2024 NVIDIA CORPORATION. All rights reserved.
* tegra_asoc_machine.c - Tegra DAI links parser //
* // tegra_asoc_machine.c - Tegra DAI links parser
* Copyright (c) 2014-2023 NVIDIA CORPORATION. All rights reserved.
*
*/
#include <nvidia/conftest.h> #include <nvidia/conftest.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of.h> #include <linux/of.h>
#include <linux/version.h>
#include <sound/simple_card_utils.h> #include <sound/simple_card_utils.h>
#include <sound/jack.h> #include <sound/jack.h>
#include <sound/soc.h> #include <sound/soc.h>
@@ -649,11 +647,74 @@ struct tegra_machine_control_data {
unsigned int master_mode; 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, static int tegra_machine_codec_set_dai_fmt(struct snd_soc_pcm_runtime *rtd,
unsigned int frame_mode, unsigned int frame_mode,
unsigned int master_mode) unsigned int master_mode)
{ {
unsigned int fmt = rtd->dai_link->dai_fmt; unsigned int fmt = rtd->dai_link->dai_fmt;
int ret;
if (frame_mode) { if (frame_mode) {
fmt &= ~SND_SOC_DAIFMT_FORMAT_MASK; 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; 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);
} }
/* /*

View File

@@ -32,6 +32,8 @@
#include <sound/soc.h> #include <sound/soc.h>
#include <sound/pcm_params.h> #include <sound/pcm_params.h>
#include "tegra_asoc_machine.h"
static int dai_get_rate(struct snd_kcontrol *kcontrol, static int dai_get_rate(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol) 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; struct snd_soc_dai *dai;
/* Fixup CPU DAI */ /* Fixup CPU DAI */
#if KERNEL_VERSION(6, 7, 0) > LINUX_VERSION_CODE #if defined(NV_SND_SOC_RTD_TO_CODEC_PRESENT) /* Linux 6.7*/
dai = asoc_rtd_to_cpu(rtd, 0);
#else
dai = snd_soc_rtd_to_cpu(rtd, 0); dai = snd_soc_rtd_to_cpu(rtd, 0);
#else
dai = asoc_rtd_to_cpu(rtd, 0);
#endif #endif
if (!dai_is_dummy(dai)) if (!dai_is_dummy(dai))
tegra_dai_fixup(dai, params); tegra_dai_fixup(dai, params);
/* Fixup Codec DAI */ /* Fixup Codec DAI */
#if KERNEL_VERSION(6, 7, 0) > LINUX_VERSION_CODE #if defined(NV_SND_SOC_RTD_TO_CODEC_PRESENT) /* Linux 6.7*/
dai = asoc_rtd_to_codec(rtd, 0);
#else
dai = snd_soc_rtd_to_codec(rtd, 0); dai = snd_soc_rtd_to_codec(rtd, 0);
#else
dai = asoc_rtd_to_codec(rtd, 0);
#endif #endif
if (!dai_is_dummy(dai)) if (!dai_is_dummy(dai))
@@ -402,6 +404,8 @@ static int tegra_mixer_control_probe(struct platform_device *pdev)
ARRAY_SIZE(tegra210_mixer_ctls)); ARRAY_SIZE(tegra210_mixer_ctls));
} }
tegra_machine_add_i2s_codec_controls(card);
/* Fixup callback for BE codec2codec links */ /* Fixup callback for BE codec2codec links */
for_each_card_rtds(card, rtd) { for_each_card_rtds(card, rtd) {
/* Skip FE links for sound card with DPCM routes for AHUB */ /* Skip FE links for sound card with DPCM routes for AHUB */