Skip to content

ASoC: max98373: don't access volatile registers in bias off - #2532

Closed
bardliao wants to merge 1 commit into
thesofproject:topic/sof-devfrom
bardliao:max98373-volatile
Closed

bardliao wants to merge 1 commit into
thesofproject:topic/sof-devfrom
bardliao:max98373-volatile

Conversation

@bardliao

Copy link
Copy Markdown
Collaborator

We will set regcache_cache_only true in suspend. As a result,
regmap_read will return error when we try to read volatile
registers in suspend. Besides, it doesn't make sense to read
feedback data when codec is not active.

Signed-off-by: Bard Liao yung-chuan.liao@linux.intel.com

@naveen-manohar

Copy link
Copy Markdown

Verified Basic Maxim-Speaker Functionality(non-dsm) & also issue mentioned at #2510 isn't observed.

naveen-manohar
naveen-manohar previously approved these changes Oct 26, 2020
@plbossart

Copy link
Copy Markdown
Member

@bardliao checkpatch issues?

@bardliao

Copy link
Copy Markdown
Collaborator Author

@bardliao checkpatch issues?

updated

Comment thread sound/soc/codecs/max98373.c Outdated
* We can't get the feedback data when codec is off, set
* value = 0 and return 0 to avoid error.
*/
ucontrol->value.integer.value[0] = 0;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

can we set value to 0xFFFFFFF make user be aware that it is invalid ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

can we set value to 0xFFFFFFF make user be aware that it is invalid ?

I am fine with that. What is your opinion @ryans-lee ?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do you mean 0xFFFFFFF not 0xFFFFFFFF? Either ways are okay to me.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@ryans-lee What does the value mean? My purpose is that user application will do nothing if it gets the value when codec is suspended. Which value is better to you? 0 or 0xFFFFFFFF? BTW ucontrol->value.integer.value[0] is long type, so we can set it to -1 if we want.

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.

@bardliao I've been reading through the previous PRs and it is starting to seem this may be the best option. One thing that still bugs me is that what user-space app is actually reading the values when the problem occurs. I did not find this info in thesofproject/sof#3541 for instance. How would the user-space application filter valid values from non-valid ones? Benefit of -EBUSY is that it's at least a well-documented interface and user-space knows it can't get the value now.

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.

I'd agree with @kv2019i - let's not re-invent the wheel. If .cache_only is enabled, regmap_read() returns -EBUSY. This isn't the only codec driver that uses regmap and supports rt-pm, is it? What do other drivers do? How do other user-space programs handle these cases?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'd agree with @kv2019i - let's not re-invent the wheel. If .cache_only is enabled, regmap_read() returns -EBUSY. This isn't the only codec driver that uses regmap and supports rt-pm, is it? What do other drivers do? How do other user-space programs handle these cases?

regmap_read() returns -EBUSY because .cache_only is enabled AND the register is volatile. Using a volatile register in a kcontrol is not common. I think using specific _get/_put functions is a common way to handle a kcontrol which is not just simply read/write a register bit to get/set the kcontrol value.

ryans-lee
ryans-lee previously approved these changes Oct 29, 2020

@ryans-lee ryans-lee left a comment

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'm not quite sure if codec driver really need to have similar bias level check for volatile register read in the future. It looks like workaround, but I do not have better idea. Thanks.

@bardliao bardliao changed the title [TEST] ASoC: max98373: don't access volatile registers in bias off ASoC: max98373: don't access volatile registers in bias off Oct 29, 2020
@naveen-manohar
naveen-manohar self-requested a review November 2, 2020 01:38

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

Still some questions on the chosen solution.

Comment thread sound/soc/codecs/max98373.c Outdated
* We can't get the feedback data when codec is off, set
* value = 0 and return 0 to avoid error.
*/
ucontrol->value.integer.value[0] = 0;

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.

@bardliao I've been reading through the previous PRs and it is starting to seem this may be the best option. One thing that still bugs me is that what user-space app is actually reading the values when the problem occurs. I did not find this info in thesofproject/sof#3541 for instance. How would the user-space application filter valid values from non-valid ones? Benefit of -EBUSY is that it's at least a well-documented interface and user-space knows it can't get the value now.

@bardliao

bardliao commented Nov 3, 2020

Copy link
Copy Markdown
Collaborator Author

@bardliao I've been reading through the previous PRs and it is starting to seem this may be the best option. One thing that still bugs me is that what user-space app is actually reading the values when the problem occurs. I did not find this info in thesofproject/sof#3541 for instance.

@kv2019i I guess CRAS would try to get all values of kcontrols and we will get the max98373 sdw:1:19f:8373:0:7: ASoC: error at soc_component_read_no_lock on sdw:1:19f:8373:0:7: -16 error if it try to get it when the codec is suspended.

How would the user-space application filter valid values from non-valid ones? Benefit of -EBUSY is that it's at least a well-documented interface and user-space knows it can't get the value now.

The user space application may not know if the value is valid or not. But those kcontrols are the feedback information used for speaker protection. So I think it is meaningless if the amp is not active.

naveen-manohar
naveen-manohar previously approved these changes Nov 3, 2020
RanderWang
RanderWang previously approved these changes Nov 4, 2020

@RanderWang RanderWang left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@kv2019i

kv2019i commented Nov 9, 2020

Copy link
Copy Markdown
Collaborator

@bardliao wrote:

@kv2019i I guess CRAS would try to get all values of kcontrols and we will get the max98373 sdw:1:19f:8373:0:7: ASoC: error at soc_component_read_no_lock on sdw:1:19f:8373:0:7: -16 error if it try to get it when the codec is suspended.

Hmm. I wonder if this should be discussed on alsa-devel directly. I understand this the warnings are misleading, But it's not obvious what is the correct behavior:

  1. return cached value # not ok for a volatile register
  2. return an error code to signal codec is not available # current behavior, but CRAS hits this as it dumps all kcontrol values
  3. return a fake value # this patch
  4. wake-up the codec and always return a valid value

None of these are ideal. I kind of like (2) as it doesn't at least generate any silent errors. E.g.

How would the user-space application filter valid values from non-valid ones?
The user space application may not know if the value is valid or not. But those kcontrols are
the feedback information used for speaker protection. So I think it is meaningless if the amp is not active.

But that's a lot of "ifs" in there. How does the CRAS function reading the kcontrols know that amp is not active? And how would other apps know of this dependency?

If seems it would be better not to hide the dependencies, but rather make it explicit with either (2) or (4).

This seems to be rare enough case that a a discussion on alsa-devel would probably be good to have to get recommendations which way to go.

@plbossart

Copy link
Copy Markdown
Member

Agree with @kv2019i we should send this as an RFC to get feedback on what the expected behavior is when accessing a volatile register when a device is suspended.

@bardliao

Copy link
Copy Markdown
Collaborator Author

Agree with @kv2019i we should send this as an RFC to get feedback on what the expected behavior is when accessing a volatile register when a device is suspended.

Sure, I will do it.

@lyakh

lyakh commented Nov 10, 2020

Copy link
Copy Markdown
Collaborator

Hmm. I wonder if this should be discussed on alsa-devel directly. I understand this the warnings are misleading, But it's not obvious what is the correct behavior:

1. return cached value # not ok for a volatile register

2. return an error code to signal codec is not available # current behavior, but CRAS hits this as it dumps all kcontrol values

@kv2019i Can we get any opinion from CRAS people?

3. return a fake value # this patch

4. wake-up the codec and always return a valid value

@kv2019i kv2019i added the upstream Patch has been sent to upstream (e.g. alsa-devel) label Nov 11, 2020
@bardliao bardliao closed this Nov 20, 2020
@bardliao bardliao reopened this Nov 27, 2020
@naveen-manohar

naveen-manohar commented Nov 27, 2020 •

Copy link
Copy Markdown

Tried for 3 iteration and observe that issue persists.
LOG:
dmesg_3_28112020_000415_cold_boot.txt
dmesg_1_28112020_000050_cold_boot.txt
dmesg_2_28112020_000232_cold_boot.txt

2020-11-28T00:01:22,097715+05:30 max98373 sdw:1:19f:8373:0:7: ASoC: error at snd_soc_component_update_bits on sdw:1:19f:8373:0:7: -16
2020-11-28T00:01:22,097748+05:30 max98373 sdw:1:19f:8373:0:7: ASoC: error at snd_soc_component_update_bits on sdw:1:19f:8373:0:7: -16
2020-11-28T00:01:22,097765+05:30 max98373 sdw:1:19f:8373:0:7: ASoC: error at snd_soc_component_update_bits on sdw:1:19f:8373:0:7: -16
2020-11-28T00:01:22,097986+05:30 max98373 sdw:1:19f:8373:0:3: ASoC: error at snd_soc_component_update_bits on sdw:1:19f:8373:0:3: -16
2020-11-28T00:01:22,098004+05:30 max98373 sdw:1:19f:8373:0:3: ASoC: error at snd_soc_component_update_bits on sdw:1:19f:8373:0:3: -16
2020-11-28T00:01:22,098014+05:30 max98373 sdw:1:19f:8373:0:3: ASoC: error at snd_soc_component_update_bits on sdw:1:19f:8373:0:3: -16
2020-11-28T00:01:22,099365+05:30 max98373 sdw:1:19f:8373:0:7: ASoC: error at snd_soc_component_update_bits on sdw:1:19f:8373:0:7: -16
2020-11-28T00:01:22,099384+05:30 max98373 sdw:1:19f:8373:0:7: ASoC: error at snd_soc_component_update_bits on sdw:1:19f:8373:0:7: -16
2020-11-28T00:01:22,099397+05:30 max98373 sdw:1:19f:8373:0:7: ASoC: error at snd_soc_component_update_bits on sdw:1:19f:8373:0:7: -16
2020-11-28T00:01:22,099612+05:30 max98373 sdw:1:19f:8373:0:3: ASoC: error at snd_soc_component_update_bits on sdw:1:19f:8373:0:3: -16
2020-11-28T00:01:22,099630+05:30 max98373 sdw:1:19f:8373:0:3: ASoC: error at snd_soc_component_update_bits on sdw:1:19f:8373:0:3: -16
2020-11-28T00:01:22,099637+05:30 max98373 sdw:1:19f:8373:0:3: ASoC: error at snd_soc_component_update_bits on sdw:1:19f:8373:0:3: -16

This is just a top level analysis to indicate that still issue persists, seems like the same volatile registers are causing this issue. we can re-confirm with debug prints.
@bardliao have sent you the scripts and steps to repro this issue.

@bardliao

Copy link
Copy Markdown
Collaborator Author

@naveen-manohar Thanks for your test. Sorry, I forgot to assign max98373->cache in previous version. Fixed it now.

naveen-manohar
naveen-manohar previously approved these changes Nov 30, 2020

@naveen-manohar naveen-manohar left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

With the limited stress test at my end, i'm not observing the warnings message.
And Speaker Audio Functions without any regression.

Comment thread sound/soc/codecs/max98373.h Outdated
bool interleave_mode;
unsigned int ch_size;
bool tdm_mode;
/* cache for reading a vaild fake feedback value */

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

'vaild' may be misspelled - perhaps 'valid'?

Also there are warnings from checkpatch - "WARNING: line over 80 characters"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

'vaild' may be misspelled - perhaps 'valid'?

Fixed, thanks.

Also there are warnings from checkpatch - "WARNING: line over 80 characters"

The limitation is 100 characters now. So, it should be fine.

naveen-manohar
naveen-manohar previously approved these changes Nov 30, 2020
@bardliao

bardliao commented Dec 2, 2020

Copy link
Copy Markdown
Collaborator Author

I saw Mark has applied the previous version. So close

@bardliao bardliao closed this Dec 2, 2020
@bardliao bardliao reopened this Dec 9, 2020
@bardliao

bardliao commented Dec 9, 2020

Copy link
Copy Markdown
Collaborator Author

@plbossart @ryans-lee Do you have any comment for this PR? If no, I will send it to upstream directly.

@plbossart

Copy link
Copy Markdown
Member

@plbossart @ryans-lee Do you have any comment for this PR? If no, I will send it to upstream directly.

You lost me here, I thought Mark applied the previous version?

@bardliao

bardliao commented Dec 9, 2020

Copy link
Copy Markdown
Collaborator Author

@plbossart @ryans-lee Do you have any comment for this PR? If no, I will send it to upstream directly.

You lost me here, I thought Mark applied the previous version?

It seems to be applied, but I can't find it on Mark's tree. And https://www.spinics.net/lists/alsa-devel/msg119319.html shows (no commit info). So I think it was not applied.

@plbossart

Copy link
Copy Markdown
Member

@plbossart @ryans-lee Do you have any comment for this PR? If no, I will send it to upstream directly.

You lost me here, I thought Mark applied the previous version?

It seems to be applied, but I can't find it on Mark's tree. And https://www.spinics.net/lists/alsa-devel/msg119319.html shows (no commit info). So I think it was not applied.

Better if you ask Mark directly?

@bardliao

Copy link
Copy Markdown
Collaborator Author

Closing it for now as I resent it to upstream

We will set regcache_cache_only true in suspend. As a result,
regmap_read will return error when we try to read volatile
registers in suspend. Besides, it doesn't make sense to read
feedback data when codec is not active. To make userspace
happy, this patch returns a cached value shich should be a
valid value.

Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
@bardliao

Copy link
Copy Markdown
Collaborator Author

@naveen-manohar I updated the PR according to Mark's comment. Could you test it?

@naveen-manohar

Copy link
Copy Markdown

@naveen-manohar I updated the PR according to Mark's comment. Could you test it?

Did verify the latest-patch-set(v3), speaker audio works fine and earlier warning logs are not observed during suspend..

@bardliao

Copy link
Copy Markdown
Collaborator Author

@naveen-manohar I updated the PR according to Mark's comment. Could you test it?

Did verify the latest-patch-set(v3), speaker audio works fine and earlier warning logs are not observed during suspend..

Thanks for the test. I sent it to upstream so close it for now

@bardliao bardliao closed this Dec 17, 2020
@plbossart

plbossart commented Jun 11, 2021 via email •

Copy link
Copy Markdown
Member

@sathyap-chrome

Copy link
Copy Markdown

Hi @plbossart i deleted the comment since the OS we used was old and hence this was seen. Later we re rechecked and its fine.

@plbossart

Copy link
Copy Markdown
Member

Hi @plbossart i deleted the comment since the OS we used was old and hence this was seen. Later we re rechecked and its fine.

ok let's keep this closed then. thanks for the information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

upstream Patch has been sent to upstream (e.g. alsa-devel)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants