From: Sheetal <sheetal@nvidia.com>
To: Liam Girdwood <lgirdwood@gmail.com>, Mark Brown <broonie@kernel.org>
Cc: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.com>,
"Thierry Reding" <thierry.reding@kernel.org>,
Jonathan Hunter <jonathanh@nvidia.com>,
Sameer Pujar <spujar@nvidia.com>,
Mohan Kumar <mkumard@nvidia.com>,
"Kuninori Morimoto" <kuninori.morimoto.gx@renesas.com>,
<linux-sound@vger.kernel.org>, <linux-tegra@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, Sheetal <sheetal@nvidia.com>
Subject: [PATCH] ASoC: tegra: Add Mixer Fade controls
Date: Wed, 22 Apr 2026 10:29:57 +0000 [thread overview]
Message-ID: <20260422102957.2706861-1-sheetal@nvidia.com> (raw)
Add fade controls for the Tegra mixer to allow the user to configure
the gain and duration for each mixer stream. The mixer supports up to
10 input streams (RX1 through RX10), each with independently
configurable target gain and fade duration. The duration is specified
in terms of the total the number of samples and this is configured via
the N3 parameter in the mixer. The total duration (N3 parameter) used
in gain curve calculations of the form n/N3 or (N3-n)/N3, where n is
the current sample position.
The fade control accepts a comma-separated list of triplets:
amixer -c <card> cset name="MIXER1 Fade" \
"<id1>,<gain1>,<duration1>[,<id2>,<gain2>,<duration2>,...]"
id - mixer input RX stream index (1 to 10)
gain - target gain level
duration - fade duration in samples (N3 parameter)
Example: fade 2 streams simultaneously:
amixer -c <card> cset name="MIXER1 Fade" "1,12000,1024,2,15000,2048"
Stream 1: fade to gain 12000 over 1024 samples
Stream 2: fade to gain 15000 over 2048 samples
The fade status reports per-stream state for all 10 RX inputs:
amixer -c <card> cget name="MIXER1 Fade Status"
Output: "0,1,-1,-1,-1,-1,-1,-1,-1,-1"
-1 - inactive (no fade configured)
0 - active (fade in progress)
1 - complete (target gain reached)
Once fading completes, the status resets to inactive for that stream.
Signed-off-by: Sheetal <sheetal@nvidia.com>
---
sound/soc/tegra/tegra210_mixer.c | 179 ++++++++++++++++++++++++++++++-
sound/soc/tegra/tegra210_mixer.h | 16 ++-
2 files changed, 190 insertions(+), 5 deletions(-)
diff --git a/sound/soc/tegra/tegra210_mixer.c b/sound/soc/tegra/tegra210_mixer.c
index ce44117a0b9c..7990038f005f 100644
--- a/sound/soc/tegra/tegra210_mixer.c
+++ b/sound/soc/tegra/tegra210_mixer.c
@@ -151,10 +151,17 @@ static int tegra210_mixer_configure_gain(struct snd_soc_component *cmpnt,
for (i = 0; i < NUM_DURATION_PARMS; i++) {
int val;
- if (instant_gain)
+ if (instant_gain) {
val = 1;
- else
- val = gain_params.duration[i];
+ } else {
+ if (i == DURATION_N3_ID)
+ val = mixer->duration[id];
+ else if (i == DURATION_INV_N3_ID)
+ val = (BIT(31) * BIT(TEGRA210_MIXER_PRESCALAR)) /
+ mixer->duration[id];
+ else
+ val = gain_params.duration[i];
+ }
err = tegra210_mixer_write_ram(mixer,
REG_DURATION_PARAM(reg, i),
@@ -173,6 +180,124 @@ static int tegra210_mixer_configure_gain(struct snd_soc_component *cmpnt,
return err;
}
+static int tegra210_mixer_put_fade(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol);
+ struct tegra210_mixer *mixer = snd_soc_component_get_drvdata(cmpnt);
+ u32 rx_id, rx_gain, rx_duration;
+ int id, base, err = 0;
+
+ /* Process array of RX stream parameters (id, gain, duration) */
+ for (id = 0; id < TEGRA210_MIXER_RX_MAX; id++) {
+ base = 3 * id;
+ rx_id = ucontrol->value.integer.value[base];
+ rx_gain = ucontrol->value.integer.value[base + 1];
+ rx_duration = ucontrol->value.integer.value[base + 2];
+
+ if (rx_id > TEGRA210_MIXER_RX_MAX) {
+ dev_err(cmpnt->dev, "Invalid mixer rx index %d\n", rx_id);
+ return -EINVAL;
+ }
+
+ /* Array ends here, user isn't required to pass all RX configurations */
+ if (rx_id == 0 && rx_gain == 0 && rx_duration == 0)
+ break;
+
+ /* Convert 1-based rx_id to 0-based array index */
+ rx_id = rx_id - 1;
+
+ /* Only update if values are different */
+ if (mixer->duration[rx_id] != rx_duration ||
+ mixer->gain_value[rx_id] != rx_gain) {
+ err = tegra210_mixer_configure_gain(cmpnt, rx_id, false);
+ if (err) {
+ dev_err(cmpnt->dev,
+ "Failed to configure fade for channel %d\n",
+ rx_id);
+ return err;
+ }
+ err = 1;
+ mixer->duration[rx_id] = rx_duration;
+ mixer->gain_value[rx_id] = rx_gain;
+ }
+
+ if (!mixer->in_fade[rx_id]) {
+ pm_runtime_get_sync(cmpnt->dev);
+ err = regmap_update_bits(mixer->regmap,
+ MIXER_REG(TEGRA210_MIXER_RX1_CTRL, rx_id),
+ TEGRA210_MIXER_SAMPLE_COUNT_ENABLE,
+ TEGRA210_MIXER_SAMPLE_COUNT_ENABLE);
+ pm_runtime_put(cmpnt->dev);
+ if (err) {
+ dev_err(cmpnt->dev,
+ "Failed to enable sample count for channel %d\n", rx_id);
+ return err;
+ }
+ err = 1;
+ mixer->in_fade[rx_id] = true;
+ }
+ }
+
+ return err;
+}
+
+static int tegra210_mixer_get_fade(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol);
+ struct tegra210_mixer *mixer = snd_soc_component_get_drvdata(cmpnt);
+ u32 id, base, index = 0;
+
+ for (id = 0; id < TEGRA210_MIXER_RX_MAX; id++) {
+ if (mixer->in_fade[id]) {
+ base = 3 * index;
+ ucontrol->value.integer.value[base] = id + 1;
+ ucontrol->value.integer.value[base + 1] = mixer->gain_value[id];
+ ucontrol->value.integer.value[base + 2] = mixer->duration[id];
+ index++;
+ }
+ }
+
+ return 0;
+}
+
+static int tegra210_mixer_get_fade_status(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_component *cmpnt = snd_kcontrol_chip(kcontrol);
+ struct tegra210_mixer *mixer = snd_soc_component_get_drvdata(cmpnt);
+ u32 count;
+ int id;
+
+ pm_runtime_get_sync(cmpnt->dev);
+
+ for (id = 0; id < TEGRA210_MIXER_RX_MAX; id++) {
+ if (!mixer->in_fade[id]) {
+ ucontrol->value.integer.value[id] = TEGRA210_MIXER_FADE_IDLE;
+ continue;
+ }
+
+ regmap_read(mixer->regmap,
+ MIXER_REG(TEGRA210_MIXER_RX1_SAMPLE_COUNT, id),
+ &count);
+
+ if (count >= mixer->duration[id]) {
+ ucontrol->value.integer.value[id] = TEGRA210_MIXER_FADE_COMPLETE;
+ regmap_update_bits(mixer->regmap,
+ MIXER_REG(TEGRA210_MIXER_RX1_CTRL, id),
+ TEGRA210_MIXER_SAMPLE_COUNT_ENABLE, 0);
+ mixer->in_fade[id] = false;
+ } else {
+ ucontrol->value.integer.value[id] = TEGRA210_MIXER_FADE_ACTIVE;
+ }
+ }
+
+ pm_runtime_put(cmpnt->dev);
+
+ return 0;
+}
+
static int tegra210_mixer_get_gain(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol)
{
@@ -396,6 +521,44 @@ ADDER_CTRL_DECL(adder3, TEGRA210_MIXER_TX3_ADDER_CONFIG);
ADDER_CTRL_DECL(adder4, TEGRA210_MIXER_TX4_ADDER_CONFIG);
ADDER_CTRL_DECL(adder5, TEGRA210_MIXER_TX5_ADDER_CONFIG);
+static int tegra210_mixer_param_info(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_info *uinfo)
+{
+ struct soc_bytes *params = (void *)kcontrol->private_value;
+
+ if (strstr(kcontrol->id.name, "Status")) {
+ params->num_regs = 10;
+ uinfo->value.integer.min = TEGRA210_MIXER_FADE_IDLE;
+ uinfo->value.integer.max = TEGRA210_MIXER_FADE_COMPLETE;
+ } else {
+ params->num_regs = 30;
+ uinfo->value.integer.min = 0;
+ uinfo->value.integer.max = U32_MAX;
+ }
+
+ /* Set control info */
+ uinfo->type = params->mask;
+ uinfo->count = params->num_regs;
+
+ return 0;
+}
+
+#define MIXER_FADE_CTRL(xname, xbase, xnum_regs, xget, xput, xaccess, xmask) \
+{ \
+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
+ .info = tegra210_mixer_param_info, \
+ .name = xname, \
+ .access = xaccess, \
+ .get = xget, \
+ .put = xput, \
+ .private_value = (unsigned long)&(struct soc_bytes) \
+ { \
+ .base = xbase, \
+ .num_regs = xnum_regs, \
+ .mask = xmask \
+ } \
+},
+
#define GAIN_CTRL(id) \
SOC_SINGLE_EXT("RX" #id " Gain Volume", \
MIXER_GAIN_CFG_RAM_ADDR((id) - 1), 0, \
@@ -418,6 +581,11 @@ static const struct snd_kcontrol_new tegra210_mixer_gain_ctls[] = {
GAIN_CTRL(8)
GAIN_CTRL(9)
GAIN_CTRL(10)
+
+MIXER_FADE_CTRL("Fade", 0x0, 30, tegra210_mixer_get_fade, tegra210_mixer_put_fade,
+ SNDRV_CTL_ELEM_ACCESS_READWRITE, SNDRV_CTL_ELEM_TYPE_INTEGER)
+MIXER_FADE_CTRL("Fade Status", 0x0, 10, tegra210_mixer_get_fade_status, NULL,
+ SNDRV_CTL_ELEM_ACCESS_READ, SNDRV_CTL_ELEM_TYPE_INTEGER)
};
static const struct snd_soc_dapm_widget tegra210_mixer_widgets[] = {
@@ -579,6 +747,7 @@ static bool tegra210_mixer_volatile_reg(struct device *dev,
case TEGRA210_MIXER_GAIN_CFG_RAM_DATA:
case TEGRA210_MIXER_PEAKM_RAM_CTRL:
case TEGRA210_MIXER_PEAKM_RAM_DATA:
+ case TEGRA210_MIXER_RX1_SAMPLE_COUNT:
return true;
default:
return false;
@@ -632,8 +801,10 @@ static int tegra210_mixer_platform_probe(struct platform_device *pdev)
dev_set_drvdata(dev, mixer);
/* Use default gain value for all MIXER inputs */
- for (i = 0; i < TEGRA210_MIXER_RX_MAX; i++)
+ for (i = 0; i < TEGRA210_MIXER_RX_MAX; i++) {
mixer->gain_value[i] = gain_params.gain_value;
+ mixer->duration[i] = gain_params.duration[DURATION_N3_ID];
+ }
regs = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(regs))
diff --git a/sound/soc/tegra/tegra210_mixer.h b/sound/soc/tegra/tegra210_mixer.h
index a330530fbc61..da16f0002bfd 100644
--- a/sound/soc/tegra/tegra210_mixer.h
+++ b/sound/soc/tegra/tegra210_mixer.h
@@ -79,12 +79,24 @@
#define TEGRA210_MIXER_RX_LIMIT (TEGRA210_MIXER_RX_MAX * TEGRA210_MIXER_REG_STRIDE)
#define TEGRA210_MIXER_TX_MAX 5
#define TEGRA210_MIXER_TX_LIMIT (TEGRA210_MIXER_RX_LIMIT + (TEGRA210_MIXER_TX_MAX * TEGRA210_MIXER_REG_STRIDE))
+#define TEGRA210_MIXER_SAMPLE_COUNT_SHIFT 24
+#define TEGRA210_MIXER_SAMPLE_COUNT_ENABLE BIT(TEGRA210_MIXER_SAMPLE_COUNT_SHIFT)
#define REG_CFG_DONE_TRIGGER 0xf
#define VAL_CFG_DONE_TRIGGER 0x1
#define NUM_GAIN_POLY_COEFFS 9
-#define NUM_DURATION_PARMS 4
+
+#define TEGRA210_MIXER_PRESCALAR 6
+#define TEGRA210_MIXER_FADE_IDLE (-1)
+#define TEGRA210_MIXER_FADE_ACTIVE 0
+#define TEGRA210_MIXER_FADE_COMPLETE 1
+
+enum {
+ DURATION_N3_ID = 2,
+ DURATION_INV_N3_ID,
+ NUM_DURATION_PARMS,
+};
struct tegra210_mixer_gain_params {
int poly_coeff[NUM_GAIN_POLY_COEFFS];
@@ -94,6 +106,8 @@ struct tegra210_mixer_gain_params {
struct tegra210_mixer {
int gain_value[TEGRA210_MIXER_RX_MAX];
+ u32 duration[TEGRA210_MIXER_RX_MAX];
+ bool in_fade[TEGRA210_MIXER_RX_MAX];
struct regmap *regmap;
};
--
2.17.1
next reply other threads:[~2026-04-22 10:30 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-22 10:29 Sheetal [this message]
2026-04-22 11:26 ` [PATCH] ASoC: tegra: Add Mixer Fade controls Mark Brown
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260422102957.2706861-1-sheetal@nvidia.com \
--to=sheetal@nvidia.com \
--cc=broonie@kernel.org \
--cc=jonathanh@nvidia.com \
--cc=kuninori.morimoto.gx@renesas.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-sound@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=mkumard@nvidia.com \
--cc=perex@perex.cz \
--cc=spujar@nvidia.com \
--cc=thierry.reding@kernel.org \
--cc=tiwai@suse.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox