Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH v4 2/6] ASoC: ops: add snd_soc_get_volsw_clamped
  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
  2025-09-11 16:04   ` Mark Brown
  0 siblings, 1 reply; 3+ messages in thread
From: Niranjan H Y @ 2025-09-11 15:56 UTC (permalink / raw)
  To: alsa-devel
  Cc: linux-sound, lgirdwood, broonie, perex, tiwai, yung-chuan.liao,
	cezary.rojewski, peter.ujfalusi, ranjani.sridharan, kai.vehmanen,
	pierre-louis.bossart, navada, shenghao-ding, v-hampiholi,
	baojun.xu, Niranjan H Y

  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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v4 2/6] ASoC: ops: add snd_soc_get_volsw_clamped
  2025-09-11 15:56 ` [PATCH v4 2/6] ASoC: ops: add snd_soc_get_volsw_clamped Niranjan H Y
@ 2025-09-11 16:04   ` Mark Brown
  0 siblings, 0 replies; 3+ messages in thread
From: Mark Brown @ 2025-09-11 16:04 UTC (permalink / raw)
  To: Niranjan H Y
  Cc: alsa-devel, linux-sound, lgirdwood, perex, tiwai, yung-chuan.liao,
	cezary.rojewski, peter.ujfalusi, ranjani.sridharan, kai.vehmanen,
	pierre-louis.bossart, navada, shenghao-ding, v-hampiholi,
	baojun.xu

[-- Attachment #1: Type: text/plain, Size: 542 bytes --]

On Thu, Sep 11, 2025 at 09:26:59PM +0530, Niranjan H Y wrote:
>   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.

Why is this a separate API, what is the situation where we would want to
report an invalid value from a control?  I was thinking of just adding
this to the existing operations rather than adding separate ones that
need to be explicitly set.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4 2/6] ASoC: ops: add snd_soc_get_volsw_clamped
@ 2025-09-12  8:35 Holalu Yogendra, Niranjan
  0 siblings, 0 replies; 3+ messages in thread
From: Holalu Yogendra, Niranjan @ 2025-09-12  8:35 UTC (permalink / raw)
  To: Mark Brown
  Cc: alsa-devel@alsa-project.org, linux-sound@vger.kernel.org,
	lgirdwood@gmail.com, 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 Kanyana, Mukund, Ding, Shenghao, Hampiholi, Vallabha,
	Xu, Baojun

> From: Mark Brown <broonie@kernel.org>
> Sent: Friday, September 12, 2025 12:02 AM
> Subject: Re: [EXTERNAL] Re: [PATCH v4 2/6] ASoC: ops: add
> snd_soc_get_volsw_clamped
> 
> On Thu, Sep 11, 2025 at 05:21:14PM +0000, Holalu Yogendra, Niranjan wrote:
> > > From: Mark Brown <broonie@kernel.org>
> 
> >   Since few of the drivers as still using the original API, and was not sure if
> > everyone wanted to clamp the register value, did not want to disturb the
> > original API snd_soc_get_volsw. Per my analysis, if register read fails due to
> In what situation would anything want to report an invalid value?
I am not sure if I fully follow. But in my case, for one of the cases,
valid amp volume is 0x0 to 0x14 with mask 0x1f - so if the register value read is
0x15 to 0x1f, it is invalid. But in the next patch, I will add the logic to clamp the value.

> > Are you thinking that this patch could be dropped and clamp the value to max in  
> > 'soc_get_volsw' (as in 1st patch) and use the same API ? Please suggest.
> Yes, everything should report valid values.  I/O errors should be
> propagated as errors.
I will update the next patch accordingly. 

Thanks 
Niranjan H Y

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-09-12  8:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-12  8:35 [PATCH v4 2/6] ASoC: ops: add snd_soc_get_volsw_clamped Holalu Yogendra, Niranjan
  -- strict thread matches above, loose matches on Subject: below --
2025-09-11 15:56 [PATCH v4 1/6] ASoC: ops: improve snd_soc_get_volsw Niranjan H Y
2025-09-11 15:56 ` [PATCH v4 2/6] ASoC: ops: add snd_soc_get_volsw_clamped Niranjan H Y
2025-09-11 16:04   ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox