Linux Sound subsystem development
 help / color / mirror / Atom feed
From: Niranjan H Y <niranjan.hy@ti.com>
To: <alsa-devel@alsa-project.org>
Cc: <linux-sound@vger.kernel.org>, <lgirdwood@gmail.com>,
	<broonie@kernel.org>, <perex@perex.cz>, <tiwai@suse.com>,
	<yung-chuan.liao@linux.intel.com>, <cezary.rojewski@intel.com>,
	<peter.ujfalusi@linux.intel.com>,
	<ranjani.sridharan@linux.intel.com>,
	<kai.vehmanen@linux.intel.com>, <pierre-louis.bossart@linux.dev>,
	<navada@ti.com>, <shenghao-ding@ti.com>, <v-hampiholi@ti.com>,
	<baojun.xu@ti.com>, Niranjan H Y <niranjan.hy@ti.com>
Subject: [PATCH v4 2/6] ASoC: ops: add snd_soc_get_volsw_clamped
Date: Thu, 11 Sep 2025 21:26:59 +0530	[thread overview]
Message-ID: <20250911155704.2236-2-niranjan.hy@ti.com> (raw)
In-Reply-To: <20250911155704.2236-1-niranjan.hy@ti.com>

  Add API snd_soc_get_volsw_clamped to read
  the volume from device. This similar to
  existing API snd_soc_get_volsw. But has
  additional step to clamp the value to max value
  if the register value is larger than max value.

Signed-off-by: Niranjan H Y <niranjan.hy@ti.com>
---
 include/sound/soc.h |  2 ++
 sound/soc/soc-ops.c | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/include/sound/soc.h b/include/sound/soc.h
index 1fffef311..34a490ece 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -553,6 +553,8 @@ int snd_soc_info_volsw_sx(struct snd_kcontrol *kcontrol,
 #define snd_soc_info_bool_ext		snd_ctl_boolean_mono_info
 int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
 	struct snd_ctl_elem_value *ucontrol);
+int snd_soc_get_volsw_clamped(struct snd_kcontrol *kcontrol,
+	struct snd_ctl_elem_value *ucontrol);
 int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
 	struct snd_ctl_elem_value *ucontrol);
 #define snd_soc_get_volsw_2r snd_soc_get_volsw
diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
index 59e91741b..4d1ee5cd2 100644
--- a/sound/soc/soc-ops.c
+++ b/sound/soc/soc-ops.c
@@ -354,6 +354,28 @@ int snd_soc_get_volsw(struct snd_kcontrol *kcontrol,
 }
 EXPORT_SYMBOL_GPL(snd_soc_get_volsw);
 
+/**
+ * snd_soc_get_volsw_clamped - single mixer get callback with range
+ * @kcontrol: mixer control
+ * @ucontrol: control element information
+ *
+ * Similar to snd_soc_get_volsw, with additional operation to
+ * clamp the register value to its maximum.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_get_volsw_clamped(struct snd_kcontrol *kcontrol,
+			      struct snd_ctl_elem_value *ucontrol)
+{
+	struct soc_mixer_control *mc =
+		(struct soc_mixer_control *)kcontrol->private_value;
+	unsigned int mask = soc_mixer_mask(mc);
+
+	return soc_get_volsw(kcontrol, ucontrol, mc, mask,
+			     mc->max - mc->min, true);
+}
+EXPORT_SYMBOL_GPL(snd_soc_get_volsw_clamped);
+
 /**
  * snd_soc_put_volsw - single mixer put callback with range
  * @kcontrol: mixer control
-- 
2.45.2


  reply	other threads:[~2025-09-11 15:57 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-11 15:56 [PATCH v4 1/6] ASoC: ops: improve snd_soc_get_volsw Niranjan H Y
2025-09-11 15:56 ` Niranjan H Y [this message]
2025-09-11 16:04   ` [PATCH v4 2/6] ASoC: ops: add snd_soc_get_volsw_clamped Mark Brown
2025-09-11 17:21     ` [EXTERNAL] " Holalu Yogendra, Niranjan
2025-09-11 18:32       ` Mark Brown
2025-09-11 15:57 ` [PATCH v4 3/6] ASoc: tas2783A: Add soundwire based codec driver Niranjan H Y
2025-09-11 15:57 ` [PATCH v4 4/6] ASoc: tas2783A: machine driver amp utility for TI devices Niranjan H Y
2025-09-11 15:57 ` [PATCH v4 5/6] ASoc: tas2783A: add machine driver changes Niranjan H Y
2025-09-11 15:57 ` [PATCH v4 6/6] tas2783A: Add acpi match changes for Intel MTL Niranjan H Y
  -- strict thread matches above, loose matches on Subject: below --
2025-09-12  8:35 [PATCH v4 2/6] ASoC: ops: add snd_soc_get_volsw_clamped Holalu Yogendra, Niranjan

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=20250911155704.2236-2-niranjan.hy@ti.com \
    --to=niranjan.hy@ti.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=baojun.xu@ti.com \
    --cc=broonie@kernel.org \
    --cc=cezary.rojewski@intel.com \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=navada@ti.com \
    --cc=perex@perex.cz \
    --cc=peter.ujfalusi@linux.intel.com \
    --cc=pierre-louis.bossart@linux.dev \
    --cc=ranjani.sridharan@linux.intel.com \
    --cc=shenghao-ding@ti.com \
    --cc=tiwai@suse.com \
    --cc=v-hampiholi@ti.com \
    --cc=yung-chuan.liao@linux.intel.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