Skip to content

Conversation

@shumingfan
Copy link

@shumingfan shumingfan commented Oct 21, 2025

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.

changed log
v2: create sdca_soc_get_volsw/sdca_soc_put_volsw in the SDCA code. For SDCA volume control only.
v3: use a function pointer for ctl_to_reg/reg_to_ctl for Q78 format

struct snd_ctl_elem_value *ucontrol);
int snd_soc_put_volsw(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably shouldn't be changing whitespace in unrelated places.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix

unsigned int sign_bit;
unsigned int invert:1;
unsigned int autodisable:1;
unsigned int sdca_vol_q7p8:1;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am a little nervous about pulling this into the ASoC core, have you looked at adding wrappers for snd_soc_get_volsw/snd_soc_put_volsw in the SDCA code, if it doesn't end up looking too messy I feel like that might be preferrable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood. I will update the patch.

mc->min = ((int)tlv[2] / step);
mc->max = ((int)tlv[3] / step);
mc->shift = step;
mc->rshift = step;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you can just use step as the shift here? I don't think this works, step is the gap between valid values, but shift is an actual bit shift.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shift will be used in the soc_mixer_reg_to_ctl/soc_mixer_ctl_to_reg function.
Do you think I should create another field to store the step value?

/* Limited maximum value specified as presented through the control */
int platform_max;
int reg, rreg;
int step;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are duplicating the handlers we can probably reuse the shift member for step, rather than adding a new one. I was just unsure before as we were using shift as a shift sometimes and as a step other times.

val -= mc->min;

if (mc->invert)
val = max - val;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can probably drop the invert we dont use it for volume controls in SDCA.

return -EINVAL;

if (mc->sign_bit)
val = sign_extend32(val, mc->sign_bit);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

q7.8 will always have a sign bit so can probably drop the if here.

}
EXPORT_SYMBOL_NS(sdca_asoc_populate_dapm, "SND_SOC_SDCA");

static int sdca_soc_vol_reg_to_ctl(struct soc_mixer_control *mc, unsigned int reg_val,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe update the name to include q78 or something incase we need to as most custom handlers in the future.

@charleskeepax
Copy link

Do we definitely need to duplicate the helpers? In my mind I thought it might be easier to wrap them such that we just do a little pre-processing on the values then call the normal handler. Fine if that ends up being too complex but just a thought to consider.

@shumingfan
Copy link
Author

Do we definitely need to duplicate the helpers? In my mind I thought it might be easier to wrap them such that we just do a little pre-processing on the values then call the normal handler. Fine if that ends up being too complex but just a thought to consider.

@charleskeepax I updated v3 patch. That patch only added reg_to_ctl/ctl_to_reg function for Q78 format in the soc-ops.c.
Could you take a look? Thanks.

@shumingfan
Copy link
Author

@charleskeepax I updated v3 patch. That patch only added reg_to_ctl/ctl_to_reg function for Q78 format in the soc-ops.c. Could you take a look? Thanks.

@charleskeepax Would you mind reviewing the v3 patch? Thanks.

val1 |= soc_mixer_ctl_to_reg(mc,
val1 |= ctl_to_reg(mc,
ucontrol->value.integer.value[1],
mask, mc->rshift, max);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should sort the indentation on these.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fix

return -EINVAL;

reg_val = val + mc->min;
ret_val = (((int)(((int)reg_val * (int)mc->shift) << 8)) / 100);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is all the casting necessary?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will reduce that

@charleskeepax
Copy link

I think this looks like it should work, still a little nervous about pushing changes into soc-ops for SDCA I am not sure it has the re-usability. I will have a poke see what it would look like if we pulled that in, but perhaps we should do the next bit of the review upstream see if Mark or anyone has any thoughts on that.

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]>
@shumingfan
Copy link
Author

I think this looks like it should work, still a little nervous about pushing changes into soc-ops for SDCA I am not sure it has the re-usability. I will have a poke see what it would look like if we pulled that in, but perhaps we should do the next bit of the review upstream see if Mark or anyone has any thoughts on that.

@charleskeepax Thanks for the review. Will send the patch and see if Mark or anyone has any suggestions.

@bardliao
Copy link
Collaborator

The PR is upstreamed

@bardliao bardliao closed this Nov 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants