-
Notifications
You must be signed in to change notification settings - Fork 138
ASoC: SDCA: support Q7.8 volume format #5563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ASoC: SDCA: support Q7.8 volume format #5563
Conversation
include/sound/soc.h
Outdated
| struct snd_ctl_elem_value *ucontrol); | ||
| int snd_soc_put_volsw(struct snd_kcontrol *kcontrol, | ||
| struct snd_ctl_elem_value *ucontrol); | ||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will fix
include/sound/soc.h
Outdated
| unsigned int sign_bit; | ||
| unsigned int invert:1; | ||
| unsigned int autodisable:1; | ||
| unsigned int sdca_vol_q7p8:1; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
sound/soc/sdca/sdca_asoc.c
Outdated
| mc->min = ((int)tlv[2] / step); | ||
| mc->max = ((int)tlv[3] / step); | ||
| mc->shift = step; | ||
| mc->rshift = step; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
4897262 to
27731dd
Compare
include/sound/soc.h
Outdated
| /* Limited maximum value specified as presented through the control */ | ||
| int platform_max; | ||
| int reg, rreg; | ||
| int step; |
There was a problem hiding this comment.
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.
sound/soc/sdca/sdca_asoc.c
Outdated
| val -= mc->min; | ||
|
|
||
| if (mc->invert) | ||
| val = max - val; |
There was a problem hiding this comment.
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.
sound/soc/sdca/sdca_asoc.c
Outdated
| return -EINVAL; | ||
|
|
||
| if (mc->sign_bit) | ||
| val = sign_extend32(val, mc->sign_bit); |
There was a problem hiding this comment.
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.
sound/soc/sdca/sdca_asoc.c
Outdated
| } | ||
| 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, |
There was a problem hiding this comment.
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.
|
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. |
27731dd to
05dee72
Compare
@charleskeepax I updated v3 patch. That patch only added reg_to_ctl/ctl_to_reg function for Q78 format in the soc-ops.c. |
@charleskeepax Would you mind reviewing the v3 patch? Thanks. |
sound/soc/soc-ops.c
Outdated
| val1 |= soc_mixer_ctl_to_reg(mc, | ||
| val1 |= ctl_to_reg(mc, | ||
| ucontrol->value.integer.value[1], | ||
| mask, mc->rshift, max); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will fix
sound/soc/soc-ops.c
Outdated
| return -EINVAL; | ||
|
|
||
| reg_val = val + mc->min; | ||
| ret_val = (((int)(((int)reg_val * (int)mc->shift) << 8)) / 100); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will reduce that
|
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]>
05dee72 to
c65c386
Compare
@charleskeepax Thanks for the review. Will send the patch and see if Mark or anyone has any suggestions. |
|
The PR is upstreamed |
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