Bug 219260

Summary: ThinkBook 13x G4 CS3541L intermittently distorted sound
Product: Drivers Reporter: Dmitry Savin (envelsavinds)
Component: Sound(ALSA)Assignee: Jaroslav Kysela (perex)
Status: RESOLVED CODE_FIX    
Severity: normal CC: patches, sbinding
Priority: P3    
Hardware: Intel   
OS: Linux   
Kernel Version: 6.11.0-0.rc6.348.vanilla.fc40.x86_64 Subsystem:
Regression: No Bisected commit-id:
Attachments: acpidump
bug_repro.cpp
dmesg.txt

Description Dmitry Savin 2024-09-10 20:24:31 UTC
Created attachment 306856 [details]
acpidump

Hi folks,
I am running Fedora 40 with kernel 6.11.0-0.rc6.348.vanilla.fc40.x86_64 on Lenovo ThinkBook 13x G4 that has c3541l amplifier and get distorted sound from time to time that mostly goes away on its own after stop / play cycle.

I also noticed that the issue is easier to trigger when I am running a bunch of tests in my app that uses ALSA, the distortion appears after a few snd_pcm_prepare/snd_pcm_start cycles regardless of the hardware configuration passed (gtest scenarios for my app). Re-init the hardware (snd_pcm_drain/drop->snd_pcm_prepare->snd_pcm_start) usually fixes the issue until next time.

I see that there were some sync difficulties with mdsync_up_seq in cs35l41,described in commit 77bf613f0bf08c021309cdb5f84b5f630b829261, so I wonder if you folks familiar with the hardware can see any potential race condition/edge case in the synchronization mechanism?

There were previously errors related to firmware failing to load about the time when the distortion was happening but those are now gone in 6.11rc6:

https://github.com/craigcabrey/thinkbook-13x-gen4-enablement/issues/9

Thanks!
Comment 1 Stefan Binding 2024-09-11 10:37:53 UTC
Hi,

Can you provide the set of steps that you say is able to trigger this issue?

Also, can you attach a full dmesg log - from boot to when you hit the issue?

Thanks,
Stefan
Comment 2 Dmitry Savin 2024-09-11 21:07:25 UTC
Created attachment 306866 [details]
bug_repro.cpp

A code snippet to reproduce the issue, distortion happens usually ~round 5 and 6 of the playback.
Comment 3 Dmitry Savin 2024-09-11 21:08:30 UTC
Created attachment 306867 [details]
dmesg.txt
Comment 4 Dmitry Savin 2024-09-11 21:12:36 UTC
I have attached a short snippet (well, as short as it could be with ALSA) to reproduce the problem. The actual scenario is whenever you repeatedly do the following after setting up ALSA device:
1. snd_pcm_prepare
2. Play  fragment (write data with writei or use mmap - doesn't matter)
3. snd_pcm_drain / snd_pcm_drop, then repeat from step 1.

Full close / open and re-init of the hardware doesn't have the issue.

The repro rate on the test code is ~2/10.
Comment 5 Stefan Binding 2024-09-19 13:44:39 UTC
Hi,

Is it possible for you to make an audio recording or video when this issue is reproduced?

I noticed that your script generates a full scale sine wave, have you tested this at a lower scale? Do you see this issue with different frequencies? Are you running this at full volume, and do you see differences if you change the volume?

Thanks,
Stefan
Comment 6 Dmitry Savin 2024-09-19 20:50:33 UTC
Please find the recordings for both the test code attached to the ticket and music fragment played (seeking triggers snd_pcm_prepeare / snd_pcm_start cycle, without format change).

https://www.dropbox.com/scl/fo/gvx28987cw6cqcscqfoiv/AMpEekbmVznS_6Dt7DSGjjE?rlkey=y91q9ar6aam3e0xlojzmq3ni6&st=bnim1ggo&dl=0

I use the full scale 440Hz sine wave just for the testing purposes (on the video it was reduced to a half), the issue happens with more complex signal too (i.e. speech or music), i.g. when watching youtube, for example. Reducing the amplitude of the signal doesn't make any difference.

I must note, that when playing through pipewire-alsa layer the issue appears significantly less often, however, even in this case I managed to catch it a few times, although did not record.

I am not quite sure what this distortion is but it sounds like DSP has some weird gain settings randomly. The overall volume doesn't increase at these moments but some of the frequencies are clearly too loud.

Just to note, the issue equally happens when listening through the headphones plugged into the 3.5mm port on side of the laptop which (mechanically) turns of the laptop speakers but doesn't happen when connecting bluetooth headphones.
Comment 7 Dmitry Savin 2024-09-19 21:04:18 UTC
Hm... Interesting.

When facing the issue in the headphones disconnecting them from the port makes the sound clear in the speakers, plugging the headphones back in brings back the distortion.

Can't reproduce it when tried the second time.

I wonder if that could be the laptop defect as well, I've found a few similar reports with Lenovo laptops but those were inconclusive of the root-cause of the issue.

```
g++ bug_repro.cpp -lasound -o bug_repro
```
Comment 8 Dmitry Savin 2024-09-20 21:11:13 UTC
Looks like a few similar issues in SOF were discussed and marked as fixes as late as March this year. The scenario described is exactly what I am experiencing.

https://github.com/thesofproject/sof/issues/8986
Comment 9 Dmitry Savin 2024-09-20 21:34:58 UTC
Opened a new issue:
https://github.com/thesofproject/sof/issues/9502
Comment 10 Dmitry Savin 2024-11-08 11:51:33 UTC
The fix has been merged last month.
Checked that the issue is not happening anymore Fedora 41 release.

https://github.com/thesofproject/linux/pull/5197