From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: "Péter Ujfalusi" <peter.ujfalusi@linux.intel.com>
Cc: lgirdwood@gmail.com, broonie@kernel.org,
linux-sound@vger.kernel.org, kai.vehmanen@linux.intel.com,
seppo.ingalsuo@linux.intel.com, stable@vger.kernel.org,
niranjan.hy@ti.com
Subject: Re: [PATCH] ASoC: soc-ops: Correct the max value for clamp in soc_mixer_reg_to_ctl()
Date: Wed, 17 Dec 2025 13:42:24 +0000 [thread overview]
Message-ID: <aUKzQCIF6DvVRRUJ@opensource.cirrus.com> (raw)
In-Reply-To: <a7038077-2dfd-4a14-b38f-09a5ed3713be@linux.intel.com>
On Wed, Dec 17, 2025 at 03:13:45PM +0200, Péter Ujfalusi wrote:
> On 17/12/2025 14:47, Charles Keepax wrote:
> > On Wed, Dec 17, 2025 at 02:06:23PM +0200, Peter Ujfalusi wrote:
> >> sound/soc/soc-ops.c | 2 +-
> >> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>
> >> diff --git a/sound/soc/soc-ops.c b/sound/soc/soc-ops.c
> >> index ce86978c158d..6a18c56a9746 100644
> >> --- a/sound/soc/soc-ops.c
> >> +++ b/sound/soc/soc-ops.c
> >> @@ -148,7 +148,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);
> >> + val = clamp(val, mc->min, mc->min + max);
> >
> > This won't work, for an SX control it is perfectly valid for
> > the value read from the register to be smaller than the minimum
> > value specified in the control.
>
> Hrm, so an SX control returns sort of rand() and the value have no
> correlation to min or max?
lol, yes exactly :-) arn't they great
> The value can wrap at any random value to 0 and continue from 0 up to
> some value, which is the max?
Mostly correct, not any random value it wraps at the mask.
> How this is in practice for the cs42l43' Headphone Digital Volume?
> SOC_DOUBLE_SX_TLV("Headphone Digital Volume", CS42L43_HPPATHVOL,
> CS42L43_AMP3_PATH_VOL_SHIFT, CS42L43_AMP4_PATH_VOL_SHIFT,
> 0x11B, 229, cs42l43_headphone_tlv),
>
> min=283
> max=229
> shifts: 0 and 16
> masks are 0x1ff
>
> if you step 229 from 283 then you reach 0x1ff, this is the max the mask
> can cover.
Not quite your maths is off by one, 229 + 283 = 512 = 0x200,
which is then &ed with the mask to get 0x0. Which on the cs42l43
headphones a value of 0x0->0dB. Stepping 1 back from that would
give you 0x1FF->-0.5dB.
> > I often think of it in terms of a 2's compliement number
> > with an implicit sign bit.
>
> I see, but why???
Mostly because hardware people love to wind me up, I assume. But
more seriously, imagine an 4-bit signed number volume control
with 5 values:
0xE -> -2 -> -2dB
0xF -> -1 -> -1dB
0x0 -> 0 -> 0dB
0x1 -> 1 -> 1dB
0x2 -> 2 -> 2dB
Super, a very sensible control, but wait being a good hardware
engineer you realise you don't need 4 bits to represent 5 values
you can get away with 3 bits for that and save like 2 gates
resulting in an ice cream and a plaque from your manager. So
you drop the sign bit giving you:
0x6 -> -2dB
0x7 -> -1dB
0x0 -> 0dB
0x1 -> 1dB
0x2 -> 2dB
This then results in an SX control with a minimum of 0x6 and a
mask of 0x7.
Thanks,
Charles
next prev parent reply other threads:[~2025-12-17 13:42 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-17 12:06 [PATCH] ASoC: soc-ops: Correct the max value for clamp in soc_mixer_reg_to_ctl() Peter Ujfalusi
2025-12-17 12:16 ` Mark Brown
2025-12-17 12:20 ` Péter Ujfalusi
2025-12-17 12:36 ` Richard Fitzgerald
2025-12-17 12:38 ` Péter Ujfalusi
2025-12-17 12:40 ` Richard Fitzgerald
2025-12-17 12:44 ` Mark Brown
2025-12-17 13:01 ` Péter Ujfalusi
2025-12-17 13:16 ` Richard Fitzgerald
2025-12-17 13:54 ` Péter Ujfalusi
2025-12-17 13:56 ` Mark Brown
2025-12-17 13:59 ` Péter Ujfalusi
2025-12-17 14:00 ` Mark Brown
2025-12-17 14:19 ` Péter Ujfalusi
2025-12-17 14:22 ` Mark Brown
2025-12-17 13:18 ` Mark Brown
2025-12-17 12:17 ` Péter Ujfalusi
2025-12-17 12:47 ` Charles Keepax
2025-12-17 13:13 ` Péter Ujfalusi
2025-12-17 13:42 ` Charles Keepax [this message]
2025-12-17 14:31 ` Péter Ujfalusi
2025-12-17 15:00 ` Charles Keepax
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=aUKzQCIF6DvVRRUJ@opensource.cirrus.com \
--to=ckeepax@opensource.cirrus.com \
--cc=broonie@kernel.org \
--cc=kai.vehmanen@linux.intel.com \
--cc=lgirdwood@gmail.com \
--cc=linux-sound@vger.kernel.org \
--cc=niranjan.hy@ti.com \
--cc=peter.ujfalusi@linux.intel.com \
--cc=seppo.ingalsuo@linux.intel.com \
--cc=stable@vger.kernel.org \
/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