ASoC: SDCA: support Q7.8 volume format
Subsystems (3)
PATCH 1/1 ASoC: SDCA: support Q7.8 volume format
From: Shuming Fan <[email protected]>
The SDCA specification uses Q7.8 volume format.
This patch adds a field to indicate whether it is SDCA volume control and supports the volume settings.
--- include/sound/soc.h | 1 + sound/soc/sdca/sdca_asoc.c | 34 ++++++--------------- sound/soc/soc-ops.c | 62 +++++++++++++++++++++++++++++++------- 3 files changed, 61 insertions(+), 36 deletions(-)
include/sound/soc.h +1 -0
@@ -1225,6 +1225,7 @@ struct soc_mixer_control {unsigned int sign_bit; unsigned int invert:1; unsigned int autodisable:1; + unsigned int sdca_q78:1;#ifdef CONFIG_SND_SOC_TOPOLOGY struct snd_soc_dobj dobj;#endif
sound/soc/sdca/sdca_asoc.c +9 -25
@@ -795,7 +795,6 @@ static int control_limit_kctl(struct device *dev,struct sdca_control_range *range;int min, max, step;unsigned int *tlv; -int shift;if (control->type !=SDCA_CTL_DATATYPE_Q7P8DB )return 0 ;
@@ -814,37 +813,22 @@ static int control_limit_kctl(struct device *dev, min =sign_extend32 (min, control->nbits -1 ); max =sign_extend32 (max, control->nbits -1 ); -/* -* FIXME: Only support power of 2 step sizes as this can be supported -* by a simple shift. -*/ -if (hweight32 (step) !=1 ) { -dev_err (dev,"%s: %s: currently unsupported step size\n" , - entity->label, control->label); -return -EINVAL ; - } - -/* -* The SDCA volumes are in steps of 1/256th of a dB, a step down of -* 64 (shift of 6) gives 1/4dB. 1/4dB is the smallest unit that is also -* representable in the ALSA TLVs which are in 1/100ths of a dB. -*/ - shift =max (ffs (step) -1 ,6 ); - tlv =devm_kcalloc (dev,4 ,sizeof (*tlv),GFP_KERNEL );if (!tlv)return -ENOMEM ; - tlv[0 ] =SNDRV_CTL_TLVT_DB_SCALE ; + tlv[0 ] =SNDRV_CTL_TLVT_DB_MINMAX ; tlv[1 ] =2 *sizeof (*tlv); tlv[2 ] = (min *100 ) >>8 ; - tlv[3 ] = ((1 << shift) *100 ) >>8 ; + tlv[3 ] = (max *100 ) >>8 ; + + step = (step *100 ) >>8 ; - mc->min = min >> shift; - mc->max = max >> shift; - mc->shift = shift; - mc->rshift = shift; - mc->sign_bit =15 - shift; + mc->min = ((int )tlv[2 ] / step); + mc->max = ((int )tlv[3 ] / step); + mc->shift = step; + mc->sign_bit =15 ; + mc->sdca_q78 =1 ; kctl->tlv.p = tlv; kctl->access |=SNDRV_CTL_ELEM_ACCESS_TLV_READ ;
sound/soc/soc-ops.c +51 -11
103 lines not on this page · raw message
Signature · 1 line
2.51.1
Charles Keepax
maintainerQuoted 11 lines · On Wed, Nov 05, 2025 at 05:11:22PM +0800, [email protected] wrote:
From: Shuming Fan <[email protected]>
The SDCA specification uses Q7.8 volume format.
This patch adds a field to indicate whether it is SDCA volume control and supports the volume settings.Signed-off-by Shuming Fan <[email protected]>--- include/sound/soc.h | 1 + sound/soc/sdca/sdca_asoc.c | 34 ++++++--------------- sound/soc/soc-ops.c | 62 +++++++++++++++++++++++++++++++-------
Mark, how do you feel about putting this in soc-ops? I think I am good with putting it here, the code is definitely a little smaller than open coding helpers in the SDCA code. However, I do have a slight doubt that this doesn't have great reusability outside of SDCA.
sound/soc/soc-ops.c int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, · line 118
Quoted 6 lines
sound/soc/soc-ops.c +6
-0+static int sdca_soc_q78_reg_to_ctl (struct soc_mixer_control *mc,unsigned int reg_val, +unsigned int mask,unsigned int shift,int max) +{ +int val = reg_val; + +if (WARN_ON (!mc->shift))
We should use the function argument for shift in these functions.
sound/soc/soc-ops.c static int soc_put_volsw(struct snd_kcontrol *kcontrol, · line 235
Quoted 8 lines
static int soc_mixer_reg_to_ctl(struct
soc_mixer_control*mc, unsigned intreg_val,sound/soc/soc-ops.c +1
-0unsigned int mask, unsigned int shift, int max) {@@ -202,14 +232,22 @@ static int soc_put_volsw(struct snd_kcontrol *kcontrol,unsigned int val2 =0 ;bool double_r = false;int ret; +unsigned int (*ctl_to_reg)(struct soc_mixer_control *,int ,unsigned int ,unsigned int ,int );
Would be nice to put this at the top of the variable list, given the length.
Thanks,
Charles
Mark Brown
maintainerQuoted 11 lines · Charles Keepax
Quoted 3 lines · On Wed, Nov 05, 2025 at 05:11:22PM +0800, [email protected] wrote:
The SDCA specification uses Q7.8 volume format.
This patch adds a field to indicate whether it is SDCA volume control and supports the volume settings.Mark, how do you feel about putting this in soc-ops? I think I am good with putting it here, the code is definitely a little smaller than open coding helpers in the SDCA code. However, I do have a slight doubt that this doesn't have great reusability outside of SDCA.
Yeah, it's a bit unclear but probably fine. The functions aren't super complex so it's not really a problem other than the small extra code size for non-SDCA systems but there's already a bunch of niche helpers that aren't used by that many systems so meh.
Quoted 9 lines
Quoted 1 line
+static int sdca_soc_q78_reg_to_ctl(struct
soc_mixer_control*mc, unsignedint
reg_val,sound/soc/soc-ops.c int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, · line 118
Quoted 5 lines
sound/soc/soc-ops.c +5
-0+ unsigned int mask, unsigned int shift, +int max) { + int val = reg_val; + +if (WARN_ON (!mc->shift))We should use the function argument for shift in these functions.
It is intentional to do this.
The patch only uses the 'shift' field to store the step value and the 'rshift' field remains zero. Therefore, we could reuse the function 'soc_put_volsw' and generate the correct result for stereo volume.
Quoted 11 lines
Quoted 1 line
static int soc_mixer_reg_to_ctl(struct
soc_mixer_control*mc, unsigned int
reg_val,Quoted 8 lines
unsigned int mask, unsigned int shift,
int max) { @@ -202,14 +232,22 @@ static int soc_put_volsw(structsnd_kcontrol*kcontrol,unsigned int val2 = 0; bool double_r = false; int ret;+ unsigned int (*ctl_to_reg)(struct
soc_mixer_control*, int,
+ unsigned int, unsigned int, int);
Quoted 1 line
Would be nice to put this at the top of the variable list, given the length.
Will fix
Charles Keepax
maintainerQuoted 10 lines · Shuming [范書銘]
Quoted 9 lines
Quoted 1 line
+static int sdca_soc_q78_reg_to_ctl(struct
soc_mixer_control*mc, unsignedint
reg_val,sound/soc/soc-ops.c int snd_soc_put_enum_double(struct snd_kcontrol *kcontrol, · line 118
Quoted 5 lines
sound/soc/soc-ops.c +5
-0+ unsigned int mask, unsigned int shift, +int max) { + int val = reg_val; + +if (WARN_ON (!mc->shift))We should use the function argument for shift in these functions.
Quoted 3 lines
It is intentional to do this.
The patch only uses the 'shift' field to store the step value and the 'rshift' field remains zero. Therefore, we could reuse the function 'soc_put_volsw' and generate the correct result for stereo volume.
Ah ok that does make sense, perhaps a comment for this would be good.
Quoted 11 lines
Quoted 11 lines
Quoted 1 line
static int soc_mixer_reg_to_ctl(struct
soc_mixer_control*mc, unsigned int
reg_val,Quoted 8 lines
unsigned int mask, unsigned int shift,
int max) { @@ -202,14 +232,22 @@ static int soc_put_volsw(structsnd_kcontrol*kcontrol,unsigned int val2 = 0; bool double_r = false; int ret;+ unsigned int (*ctl_to_reg)(struct
soc_mixer_control*, int,
+ unsigned int, unsigned int, int);
Quoted 3 lines
Quoted 1 line
Would be nice to put this at the top of the variable list, given the length.
Will fix
Thanks,
Charles