Repository navigation
ASoC: codec: max98373-sdw: fix a amixer error when codec is suspended - #2226
Conversation
|
@ClarexZhou can you help to validate this PR for #2221? I tested it on TGL. Thanks! |
kv2019i
left a comment
There was a problem hiding this comment.
At minimum commit message needs to be adjusted... some of the registers are real volatile data.
| case MAX98373_R203E_AMP_PATH_GAIN: | ||
| case MAX98373_R2054_MEAS_ADC_PVDD_CH_READBACK: | ||
| case MAX98373_R2055_MEAS_ADC_THERM_CH_READBACK: | ||
| case MAX98373_R20B6_BDE_CUR_STATE_READBACK: |
There was a problem hiding this comment.
Hmm, AMP_PATH_GAIN I can understand, but "MEAS_ADC_*" seems like really volatile data. OTOH, exposing volatile regs directly as kcontrols does not seem like a good idea. Not sure what the right solution is... reading incorrect temperature readings does not sound good either.
There was a problem hiding this comment.
OTOH, exposing volatile regs directly as kcontrols does not seem like a good idea. Not sure what the right solution is... reading incorrect temperature readings does not sound good either.
Agree. Maybe "ADC PVDD" and "ADC TEMP" are for special purpose. And it makes sense that we can't get the value in suspended.
There was a problem hiding this comment.
I wonder if this is correct? Isn't the issue more that we expose some registers that should not be shown to users, or if they are shown the put/get routines should include a pm_runtime_get_sync/put_autosuspend?. It'd be odd to change the nature of regmap registers.
There was a problem hiding this comment.
I agree to remove AMP_PATH_GAIN from volatile register list, but 0x2054, 0x2055 and 0x2086 are real volatile registers to update amp ADC values. Amp driver will return only cached value instead of reading actual value from h/w if these registers are removed from the volatile list. PVDD level and amp temperature are changing over time and it is being used for speaker calibration application running in user space. Reading ADC values while amp is suspended is not expected operation since amp is likely powered off in this state. Adding pm get_sync/auto suspend into put/get routine makes sense to me.
There was a problem hiding this comment.
@ryans-lee thanks for you idea and patch. Today I only have very limited time to access our device with your patch and found one issue. the "compnent->suspend" is only set for S3 sleep, not for runtime suspend. I modify it to "if (snd_soc_dapm_get_bias_level(&component->dapm) != SND_SOC_BIAS_OFF)", but I have to test it on device to confirm it.
+static int max98373_adc_get(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
+ struct max98373_priv *max98373 =
+ snd_soc_component_get_drvdata(component);
+ struct soc_mixer_control *mc =
+ (struct soc_mixer_control *)kcontrol->private_value;
+ int reg = 0;
+
+ if (!component->suspend)
+ regmap_read(max98373->regmap, mc->reg, ®);
+ ucontrol->value.integer.value[0] = reg;
+
+ return 0;
+}
Verified on tgL chrome laptop with max98373 in SDW mode, issue is fix and works OK. |
1569fb2 to
c134603
Compare
bardliao
left a comment
There was a problem hiding this comment.
Sorry, but we can't remove the registers from max98373_volatile_reg() if they are volatile.
9060a39 to
fd06129
Compare
|
hi all and @ryans-lee , please review this update. Thanks! |
plbossart
left a comment
There was a problem hiding this comment.
Sorry I don't fully understand this PR, there are too many confusing parts.
| int reg = 0; | ||
|
|
||
| if (snd_soc_dapm_get_bias_level(&component->dapm) != SND_SOC_BIAS_OFF) | ||
| regmap_read(max98373->regmap, mc->reg, ®); |
There was a problem hiding this comment.
@RanderWang is there any other codec driver which does this sort of things? If not we are going to have difficulties upstreaming this without explanations of why this is needed.
There was a problem hiding this comment.
@RanderWang I'm not sure if it is really necessary doing pm resume/suspend for the volatile register access while amp is suspended. Can we try to add 'pm_runtime_get_sync' before register read and then call 'pm_runtime_put_autosuspend' ?
Doing this in 'get' function kcontrol is also not common, but I don't have better idea here.
There was a problem hiding this comment.
@ryans-lee When will these kcontrol be used? IMO we don't need to know these value when amp is suspended, right? Maybe we don't need the ASoC: codec: max98373: Add get support for ADC widgets commit and just let it return error in suspended. In other words, I don't think it is a bug if the kcontrol return error when we try to get a value which is meaningless at that moment. What do you think?
There was a problem hiding this comment.
This control is being used to get PVDD level and chip temperature when calibration application is running. The calibration is performed mostly in the factory, but it could be called during amp run-time by calibration app.
Yes, I thought this is not a bug because we can't expect normal value while amp is suspended. @RanderWang What was the impact of -EBUSY error? Was it just because of access to 'MAX98373_R203E_AMP_PATH_GAIN'? not other volatile registers?
| 0x00); | ||
| regmap_write(max98373->regmap, | ||
| MAX98373_R203E_AMP_PATH_GAIN, | ||
| 0x00); |
There was a problem hiding this comment.
this doesn't look good, we removed this on purpose to take Mark Brown's into account, not sure why this needed to be added again?
| static bool max98373_volatile_reg(struct device *dev, unsigned int reg) | ||
| { | ||
| switch (reg) { | ||
| case MAX98373_R203E_AMP_PATH_GAIN: |
There was a problem hiding this comment.
sorry, I really don't understand this. If this is a hardware register that can change on its own, then it needs to be volatile.
There was a problem hiding this comment.
It is based on comments "I agree to remove AMP_PATH_GAIN from volatile register list" from Ryans. @ryans-lee , can you explain this ? thanks!
There was a problem hiding this comment.
I confirm this register is non-volatile.
@plbossart ryans shared me this patch and I did a little refinement. @ryans-lee can you help to answer these questions ? |
|
@plbossart To my understanding, what this PR do is
|
If codec is suspended, a error of Device or resource busy occurs when executing amixer. Amixer accesses AMP_PATH_GAIN which is a volatile register and the regmap is set to cache_only when codec is suspended, so regmap can't get its data from regmap cache and return -EBUSY. Actually this register can be set by user and remain unchanged, so we can get its value from regmap cache. This patch removes volatile attribute of this register and initializes it to let regmap cache work. Signed-off-by: Rander Wang <rander.wang@intel.com> Signed-off-by: Ryan Lee <ryans.lee@maximintegrated.com>
fd06129 to
b82ead2
Compare
|
update PR. @plbossart @ryans-lee I checked these registers which are only used by user to check feedback status. So they are only useful when playback is working and it makes no sense to read it when codec is suspended. I submitted this PR to fix amixer issue but now most part of the PR is unnecessary. A recent commit: cf6e26c refined ASoC framework. now ASoC doesn't return error to user mode application and only report error in kernel log. So now amixer works even codec is suspended. Bard though this behavior is accessible: not every mixer read should be successful |
|
Since we've got confirmation this fix is legit (#2226 (comment)) I'll go ahead and merge. I'll also squash with the rest of the changes and send this upstream today. |
If codec is suspended, a error of Device or resource busy occurs when
executing amixer. Amixer accesses some codec registers are volatile and
the regmap is set to cache_only when codec is suspended, so regmap can't
get these data from regmap cache and return -EBUSY.
Actually these registers can be set by user and remain unchanged, so we
can get its value from regmap cache. This patch remove volatile attribute
of these registers to let regmap cache work.
fixes #2221