Skip to content

ASoC: codec: max98373-sdw: fix a amixer error when codec is suspended - #2226

Merged
plbossart merged 1 commit into
thesofproject:topic/sof-devfrom
RanderWang:98373_amixer_error
Jul 2, 2020
Merged

plbossart merged 1 commit into
thesofproject:topic/sof-devfrom
RanderWang:98373_amixer_error

Conversation

@RanderWang

Copy link
Copy Markdown

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

@RanderWang

Copy link
Copy Markdown
Author

@ClarexZhou can you help to validate this PR for #2221? I tested it on TGL.

Thanks!

@kv2019i kv2019i left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

thanks, @ryans-lee could you help to check this ?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@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, &reg);
+       ucontrol->value.integer.value[0] = reg;
+
+       return 0;
+}

@ClarexZhou

Copy link
Copy Markdown

@ClarexZhou can you help to validate this PR for #2221? I tested it on TGL.

Thanks!

Verified on tgL chrome laptop with max98373 in SDW mode, issue is fix and works OK.

@RanderWang
RanderWang force-pushed the 98373_amixer_error branch from 1569fb2 to c134603 Compare June 23, 2020 09:51

@bardliao bardliao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry, but we can't remove the registers from max98373_volatile_reg() if they are volatile.

@RanderWang
RanderWang force-pushed the 98373_amixer_error branch 3 times, most recently from 9060a39 to fd06129 Compare June 28, 2020 07:46
@RanderWang

Copy link
Copy Markdown
Author

hi all and @ryans-lee , please review this update. Thanks!

bardliao
bardliao previously approved these changes Jun 29, 2020

@bardliao bardliao left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@plbossart plbossart left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry I don't fully understand this PR, there are too many confusing parts.

Comment thread sound/soc/codecs/max98373.c Outdated
int reg = 0;

if (snd_soc_dapm_get_bias_level(&component->dapm) != SND_SOC_BIAS_OFF)
regmap_read(max98373->regmap, mc->reg, &reg);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@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?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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?

Comment thread sound/soc/codecs/max98373.c Outdated
0x00);
regmap_write(max98373->regmap,
MAX98373_R203E_AMP_PATH_GAIN,
0x00);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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!

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I confirm this register is non-volatile.

@RanderWang

Copy link
Copy Markdown
Author

Sorry I don't fully understand this PR, there are too many confusing parts.

@plbossart ryans shared me this patch and I did a little refinement. @ryans-lee can you help to answer these questions ?

@bardliao

Copy link
Copy Markdown
Collaborator

@plbossart To my understanding, what this PR do is

  1. MAX98373_R203E_AMP_PATH_GAIN is not a volatile register, so remove it from max98373_volatile_reg()
  2. Get volatile kcontrol value indirectly by max98373_adc_get(). So we will get 0 instead of an error when the bias level is off. The second commit also set the kcontrol _put function NULL, so we will get error if we try to set these volatile kcontrols

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>
@RanderWang

Copy link
Copy Markdown
Author

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

@plbossart

Copy link
Copy Markdown
Member

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.

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.

[BUG][TGL]Terminal shows "cannot load mixer controls: Device or resource busy" when open alsamixer when pm runtime in suspended status.

6 participants