public inbox for alsa-devel@alsa-project.org
 help / color / mirror / Atom feed
From: Richard Acayan <mailingradian@gmail.com>
To: Niranjan H Y <niranjan.hy@ti.com>
Cc: alsa-devel@alsa-project.org, 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
Subject: Re: [PATCH v5 1/5] ASoC: ops: improve snd_soc_get_volsw
Date: Wed, 31 Dec 2025 22:34:23 -0500	[thread overview]
Message-ID: <aVXrPzG0hp47hA0Y@rdacayan> (raw)
In-Reply-To: <20250912083624.804-1-niranjan.hy@ti.com>

On Fri, Sep 12, 2025 at 02:06:20PM +0530, Niranjan H Y wrote:
> * add error handling in case register read fails
> * clamp the values if the register value read is
>   out of range
> 
> Signed-off-by: Niranjan H Y <niranjan.hy@ti.com>
> --
> v5:
>  - remove clamp parameter
>  - move the boundary check after sign-bit extension
> ---
>  sound/soc/soc-ops.c | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
> index a629e0eac..03f74c32d 100644
> --- a/sound/soc/soc-ops.c
> +++ b/sound/soc/soc-ops.c
> @@ -118,6 +118,7 @@ static int soc_mixer_reg_to_ctl(struct soc_mixer_control *mc, unsigned int reg_v
>  	if (mc->sign_bit)
>  		val = sign_extend32(val, mc->sign_bit);
>  
> +	val = clamp(val, mc->min, mc->max);

This code path is shared with SX controls, when the maximum would be
mc->min + mc->max. The max parameter to the function can be used to get
a more sensible maximum (otherwise there could be cases where min > max):

	mc->min + max

Also, the Digital PCM Volume in CS35L36 has some trouble with this. It
maps -102dB to 0x4D0 and -0.125dB to 0x7FF (mask 0x7FF). At +0dB,
it's supposed to wrap around to 0x000, then go up to +12dB at 0x060.
This clamping reads +0dB and above (0x000 to 0x060) as -102dB, since it
doesn't account for signed values.

      parent reply	other threads:[~2026-03-04 16:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-12  8:36 [PATCH v5 1/5] ASoC: ops: improve snd_soc_get_volsw Niranjan H Y
2025-09-12  8:36 ` [PATCH v5 2/5] ASoc: tas2783A: Add soundwire based codec driver Niranjan H Y
2025-09-12  8:36 ` [PATCH v5 3/5] ASoc: tas2783A: machine driver amp utility for TI devices Niranjan H Y
2025-09-12  8:36 ` [PATCH v5 4/5] ASoc: tas2783A: add machine driver changes Niranjan H Y
2025-09-12  8:36 ` [PATCH v5 5/5] tas2783A: Add acpi match changes for Intel MTL Niranjan H Y
2025-09-22 11:58 ` [PATCH v5 1/5] ASoC: ops: improve snd_soc_get_volsw Mark Brown
2025-09-23  8:20 ` Mark Brown
2026-01-01  3:34 ` Richard Acayan [this message]

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=aVXrPzG0hp47hA0Y@rdacayan \
    --to=mailingradian@gmail.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=niranjan.hy@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