Skip to content
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

Kernel 6.6.y and DAC Allo Piano 2.1+Kali fails init #6527

Closed
foonerd opened this issue Dec 10, 2024 · 73 comments
Closed

Kernel 6.6.y and DAC Allo Piano 2.1+Kali fails init #6527

foonerd opened this issue Dec 10, 2024 · 73 comments

Comments

@foonerd
Copy link
Contributor

foonerd commented Dec 10, 2024

Describe the bug

It seems that sound/soc/bcm/allo-piano-dac-plus.c is not parsing parameters for alsa use. What I can observe is that the dtoverlay partly fails register the card:

[   19.836848] snd-allo-piano-dac-plus soc:sound: snd_soc_register_card() failed: -517
[   19.882239] snd-allo-piano-dac-plus soc:sound: snd_soc_register_card() failed: -517

However module somewhat loads:
ls -la /sys/module/snd_soc_allo_piano_dac_plus/

drwxr-xr-x   6 root root    0 Dec 10 08:08 .
drwxr-xr-x 150 root root    0 Jan  1  1970 ..
-r--r--r--   1 root root 4096 Dec 10 08:08 coresize
drwxr-xr-x   2 root root    0 Dec 10 08:08 drivers
drwxr-xr-x   2 root root    0 Dec 10 08:08 holders
-r--r--r--   1 root root 4096 Dec 10 08:08 initsize
-r--r--r--   1 root root 4096 Dec 10 08:08 initstate
drwxr-xr-x   2 root root    0 Dec 10 08:08 notes
-r--r--r--   1 root root 4096 Dec 10 08:08 refcnt
drwxr-xr-x   2 root root    0 Dec 10 08:08 sections
-r--r--r--   1 root root 4096 Dec 10 08:08 srcversion
-r--r--r--   1 root root 4096 Dec 10 08:08 taint
--w-------   1 root root 4096 Dec 10 08:08 uevent

Simple test with alsa-info shows that the expected DAC's control parameters are missing:

ALSA Information Script v 0.5.1
--------------------------------

This script visits the following commands/files to collect diagnostic
information about your ALSA installation and sound related hardware.

  dmesg
  lspci
  aplay
  amixer
  alsactl
  rpm, dpkg
  /proc/asound/
  /sys/class/sound/
  ~/.asoundrc (etc.)

See '/usr/sbin/alsa-info --help' for command line options.

cat: /tmp/alsa-info.2lPuin51C4/acpidevicestatus.tmp: No such file or directory
pgrep: pattern that searches for process name longer than 15 characters will result in zero matches
Try `pgrep -f' option to match against the complete command line.
cat: '/sys/module/snd_soc_allo_piano_dac_plus/parameters/*': No such file or directory

In addition, there seems to be a deadlock after module load preventing init level change.

Steps to reproduce the behaviour

Load overlay with config.txt:

# Enable audio (loads snd_bcm2835)
dtparam=audio=off
[all]
dtoverlay=allo-piano-dac-plus-pcm512x-audio

Load manually:

sudo dtoveraly allo-piano-dac-plus-pcm512x-audio

Device (s)

Raspberry Pi 3 Mod. B+, Raspberry Pi 4 Mod. B, Raspberry Pi 400, Raspberry Pi 5, Raspberry Pi CM4, Raspberry Pi CM4 Lite, Other

System

cat /etc/rpi-issue

Raspberry Pi reference 2024-07-04
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, 48efb5fc5485fafdc9de8ad481eb5c09e1182656, stage5

vcgencmd version

Nov 26 2024 12:54:19 
Copyright (c) 2012 Broadcom
version 2ae30f53898ae2f1ba77ff570a92991bedfb0398 (clean) (release) (start)

uname -a

Linux bookworm 6.6.62+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.6.62-1+rpt1 (2024-11-25) aarch64 GNU/Linux

Logs

dmesg shows continuously:

[  242.652712] INFO: task alsactl:514 blocked for more than 120 seconds.
[  242.652754]       Tainted: G         C         6.6.62+rpt-rpi-v8 #1 Debian 1:6.6.62-1+rpt1
[  242.652766] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[  242.652773] task:alsactl         state:D stack:0     pid:514   ppid:1      flags:0x00000805
[  242.652800] Call trace:
[  242.652810]  __switch_to+0xe0/0x148
[  242.652841]  __schedule+0x37c/0xd60
[  242.652856]  schedule+0x64/0x108
[  242.652871]  schedule_preempt_disabled+0x2c/0x50
[  242.652893]  rwsem_down_read_slowpath+0x214/0x528
[  242.652915]  down_read+0xac/0xc0
[  242.652931]  snd_soc_card_get_kcontrol+0x34/0xc0 [snd_soc_core]
[  242.653171]  snd_soc_limit_volume+0x2c/0x80 [snd_soc_core]
[  242.653360]  pcm512x_set_reg_master+0x110/0x138 [snd_soc_allo_piano_dac_plus]
[  242.653401]  snd_ctl_elem_write+0xfc/0x208 [snd]
[  242.653508]  snd_ctl_ioctl+0x14c/0x920 [snd]
[  242.653598]  __arm64_sys_ioctl+0xb4/0x100
[  242.653619]  invoke_syscall+0x50/0x128
[  242.653642]  el0_svc_common.constprop.0+0xc8/0xf0
[  242.653662]  do_el0_svc+0x24/0x38
[  242.653681]  el0_svc+0x38/0xd0
[  242.653702]  el0t_64_sync_handler+0x100/0x130
[  242.653723]  el0t_64_sync+0x190/0x198
[  242.653745] INFO: task alsactl:532 blocked for more than 120 seconds.
[  242.653758]       Tainted: G         C         6.6.62+rpt-rpi-v8 #1 Debian 1:6.6.62-1+rpt1
[  242.653768] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[  242.653775] task:alsactl         state:D stack:0     pid:532   ppid:1      flags:0x00000004
[  242.653796] Call trace:
[  242.653803]  __switch_to+0xe0/0x148
[  242.653820]  __schedule+0x37c/0xd60
[  242.653834]  schedule+0x64/0x108
[  242.653849]  schedule_preempt_disabled+0x2c/0x50
[  242.653865]  rwsem_down_write_slowpath+0x32c/0x6d8
[  242.653888]  down_write+0x98/0xa8
[  242.653906]  snd_ctl_release+0x74/0x130 [snd]
[  242.653996]  __fput+0xc4/0x290
[  242.654017]  __fput_sync+0x58/0x70
[  242.654037]  __arm64_sys_close+0x40/0x90
[  242.654056]  invoke_syscall+0x50/0x128
[  242.654076]  el0_svc_common.constprop.0+0x48/0xf0
[  242.654095]  do_el0_svc+0x24/0x38
[  242.654113]  el0_svc+0x38/0xd0
[  242.654133]  el0t_64_sync_handler+0x100/0x130
[  242.654154]  el0t_64_sync+0x190/0x198
[  242.654221] INFO: task wireplumber:989 blocked for more than 120 seconds.
[  242.654233]       Tainted: G         C         6.6.62+rpt-rpi-v8 #1 Debian 1:6.6.62-1+rpt1
[  242.654243] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[  242.654251] task:wireplumber     state:D stack:0     pid:989   ppid:961    flags:0x00000804
[  242.654271] Call trace:
[  242.654277]  __switch_to+0xe0/0x148
[  242.654293]  __schedule+0x37c/0xd60
[  242.654308]  schedule+0x64/0x108
[  242.654322]  schedule_preempt_disabled+0x2c/0x50
[  242.654338]  rwsem_down_write_slowpath+0x32c/0x6d8
[  242.654356]  down_write+0x98/0xa8
[  242.654372]  snd_ctl_release+0x74/0x130 [snd]
[  242.654467]  __fput+0xc4/0x290
[  242.654488]  __fput_sync+0x58/0x70
[  242.654507]  __arm64_sys_close+0x40/0x90
[  242.654525]  invoke_syscall+0x50/0x128
[  242.654544]  el0_svc_common.constprop.0+0xc8/0xf0
[  242.654563]  do_el0_svc+0x24/0x38
[  242.654583]  el0_svc+0x38/0xd0
[  242.654603]  el0t_64_sync_handler+0x100/0x130
[  242.654623]  el0t_64_sync+0x190/0x198
[  363.484702] INFO: task alsactl:514 blocked for more than 241 seconds.
[  363.484745]       Tainted: G         C         6.6.62+rpt-rpi-v8 #1 Debian 1:6.6.62-1+rpt1
[  363.484758] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.

Additional context

No response

@foonerd
Copy link
Contributor Author

foonerd commented Dec 10, 2024

The last working kernel version was 6.1.y.
Checked with a simple overlay allo-piano-dac-pcm512x-audio and a single chip channel loads with a simplified controls. It leads me to believe, that the switch part is not functioning as it is meant to be.

@pelwell
Copy link
Contributor

pelwell commented Dec 10, 2024

517 is EPROBEDEFER, which means "not yet" - the kernel will try again later. It's nice if drivers suppress those error messages as they can be confusing, but otherwise I don['t see anything wrong there. The stall is probably caused by something failing to release a mutex.

Like most of the drivers we host in our kernel, we can't offer any support for them unless they reveal an underlying problem in the bits we do maintain. Our involvement consists of forward-porting the patches to new kernel versions, which is basically just a matter of getting them to compile again when the APIs change.

Allo seems to be long gone - your best hope would be that one of the users out there has some coding experience. Even a relative novice could learn quite a bit about the problem by scattering a few pr_info() calls around the driver.

@foonerd
Copy link
Contributor Author

foonerd commented Dec 10, 2024

Thank you for looking into this. Appreciated. Being a "novice" as you mention I can dive into the module, however will need a bit of guidance: mutex. What troubleshooting steps or actions would you suggest?

@pelwell
Copy link
Contributor

pelwell commented Dec 10, 2024

Here's a rough plan of action:

  1. After booting your current kernel, run dmesg -l err,warn and look for any messages that might be relevant.
  2. Once the error has occurred, run that dmesg again, and look for additions. Report your findings.
  3. As you'll be building your own kernel you should use the fastest Pi you have, which looks to be a Pi 5. To avoid the need to set up a cross-compiler, I recommend you use a 64-bit image (to match the 64-bit kernel). Just in case something goes disastrously wrong, you might want to install a fresh image to a spare card - even a 64-bit Lite image would be enough.
  4. Follow the kernel build instructions here: https://www.raspberrypi.com/documentation/computers/linux_kernel.html#building
    You need the "Natively build a kernel" instructions.
  5. Once compilation has completed, follow the installation steps and verify that it boots.
  6. Now we're going trace all the snd_soc_... calls. At the top of the file, after the last #include, add:
#define snd_soc_component_read(c, r) my_snd_soc_component_read(c, r, __LINE__)
#define snd_soc_component_write(c, r, v) my_snd_soc_component_write(c, r, v, __LINE__)
static unsigned int my_snd_soc_component_read(struct snd_soc_component *component,
				      unsigned int reg, int line);
static int my_snd_soc_component_write(struct snd_soc_component *component,
			    unsigned int reg, unsigned int val, int line);
  1. At the end of the file (before MODULE_AUTHOR should be OK), put this:
#undef snd_soc_component_read
#undef snd_soc_component_write

static unsigned int my_snd_soc_component_read(struct snd_soc_component *component,
				      unsigned int reg, int line)
{
	unsigned int val;
	pr_info("< read %x (%d)\n", reg, line);
	val = snd_soc_component_read(component, reg);
	pr_info("> read %x -> %x (%d)\n", reg, val, line);
	return val;
}

static int my_snd_soc_component_write(struct snd_soc_component *component,
			    unsigned int reg, unsigned int val, int line)
{
	int ret;
	pr_info("< write %x = %x (%d)\n", reg, val, line);
	ret = snd_soc_component_write(component, reg, val);
	pr_info("> write %x = %x ret %d (%d)\n", reg, val, ret, line);
	return ret;
}
  1. Rebuild and reinstall the kernel (it should be quick this time since you've only changed one file), and confirm that you are seeing messages (dmesg -l err).
  2. Run it until you get a failure, then dmesg -l err,warn | pastebinit (you may need to sudo apt install pastebinit first).

@foonerd
Copy link
Contributor Author

foonerd commented Dec 10, 2024

Thank you for the steps. This round, the module was built against "stock" Pi kernel - 6.6.62-v7+ #1816 using cross-compiler.

load dtoverlay -> http://paste.debian.net/1339146/
after reboot on alsa test -> http://paste.debian.net/1339151/

I would expect a bit more output at this time, however the test was on Pi 3B+, moving to Pi5 or CM5 to speed-up the native build work.

@foonerd
Copy link
Contributor Author

foonerd commented Dec 10, 2024

Stock kernel:
uname -a
Linux foopi 6.6.62+rpt-rpi-2712 #1 SMP PREEMPT Debian 1:6.6.62-1+rpt1 (2024-11-25) aarch64 GNU/Linux

dmesg -l err,warn

No overlays DAC overlay dynamic DAC overlay reboot
https://paste.debian.net/hidden/6fb41fac/ https://paste.debian.net/hidden/e3bfc68c/ https://paste.debian.net/hidden/81078b39/

There are no new messages from test other than task alsactl:67778 blocked for more than xxx seconds.
On shutdown/reboot the alsa-restore.service stop job waits for over 5 min; hard reset.

@foonerd
Copy link
Contributor Author

foonerd commented Dec 10, 2024

Kernel from repo:
uname -a
Linux foopi 6.6.63-v8-16k+ #1 SMP PREEMPT Tue Dec 10 13:25:12 GMT 2024 aarch64 GNU/Linux

dmesg -l err,warn

No overlays DAC overlay dynamic DAC overlay reboot
https://paste.debian.net/hidden/55089d41/ https://paste.debian.net/hidden/4e15b3e3/ https://paste.debian.net/hidden/f6ed63d9/

Same behaviour as before.

@pelwell
Copy link
Contributor

pelwell commented Dec 10, 2024

Odd. Can you put another pr_err (any message you like) before the "return 0;" at the end of snd_allo_piano_dac_probe? That should confirm whether the driver initialisation is completing or not.

@foonerd
Copy link
Contributor Author

foonerd commented Dec 10, 2024

Kernel with updated module:
uname -a
Linux foopi 6.6.63-v8-16k+ #1 SMP PREEMPT Tue Dec 10 13:25:12 GMT 2024 aarch64 GNU/Linux

dmesg -l err,warn

No overlays DAC overlay dynamic DAC overlay reboot
https://paste.debian.net/hidden/a4c4c1a0/ https://paste.debian.net/hidden/44f61fe7/ https://paste.debian.net/hidden/e8d35d5f/

Same behaviour as before.

@foonerd
Copy link
Contributor Author

foonerd commented Dec 10, 2024

Odd. Can you put another pr_err (any message you like) before the "return 0;" at the end of snd_allo_piano_dac_probe? That should confirm whether the driver initialisation is completing or not.

                if ((mute_gpio[0]) && (mute_gpio[1]))
                        snd_allo_piano_gpio_mute(&snd_allo_piano_dac);
                pr_err("DAC issue #6527\n");

                return 0;

Result: https://paste.debian.net/hidden/0aaf8bb3/

Looks like it does.

@pelwell
Copy link
Contributor

pelwell commented Dec 10, 2024

(I'll take your word that there is no change - you don't need to upload the logs each time)
Let's just double check that all the probe calls are failing - add another message at the start of snd_allo_piano_dac_probe, then if we only see it twice followed by two -517s then we know that the instantiation never succeeds.

@6by9
Copy link
Contributor

6by9 commented Dec 10, 2024

sudo cat /sys/kernel/debug/devices_deferred should also tell you if there are still outstanding devices that are deferred. (The dependency will only be listed if the driver has used dev_err_probe though)

@foonerd
Copy link
Contributor Author

foonerd commented Dec 10, 2024

sudo cat /sys/kernel/debug/devices_deferred should also tell you if there are still outstanding devices that are deferred. (The dependency will only be listed if the driver has used dev_err_probe though)

Nothing, just empty:

foonerd@foopi:~ $ sudo cat /sys/kernel/debug/devices_deferred
foonerd@foopi:~ $ sudo ls -la /sys/kernel/debug/devices_deferred
-r--r--r-- 1 root root 0 Jan  1  1970 /sys/kernel/debug/devices_deferred

@pelwell
Copy link
Contributor

pelwell commented Dec 10, 2024

(The dependency will only be listed if the driver has used dev_err_probe though)

It doesn't.

@foonerd
Copy link
Contributor Author

foonerd commented Dec 10, 2024

add another message at the start of snd_allo_piano_dac_probe, then if we only see it twice followed by two -517s then we know that the instantiation never succeeds.

This is getting interesting - https://paste.debian.net/hidden/168f11aa/

Purely boot only, nothing touched... yet.

@pelwell
Copy link
Contributor

pelwell commented Dec 10, 2024

Well that's a bit of a relief - I was beginning to wonder how you could be getting so far if the probe() had never succeeded.

@6by9
Copy link
Contributor

6by9 commented Dec 10, 2024

(The dependency will only be listed if the driver has used dev_err_probe though)

It doesn't.

The fact it is still deferred would be listed, just not what the dependency was.

@foonerd
Copy link
Contributor Author

foonerd commented Dec 10, 2024

Honestly, I'm scratching my head for past two weeks, doubting my sanity with this.
On the serious note - there is a quite clever switch in the code. Perhaps barking up the wrong tree - could the overlay as such need a revamp?

@pelwell
Copy link
Contributor

pelwell commented Dec 10, 2024

It seems unlikely, since it only provides a static configuration - by the time you've exited the probe function, the overlay plays no further part.

@foonerd
Copy link
Contributor Author

foonerd commented Dec 10, 2024

To add to the confusion, when using basic overlay: allo-piano-dac-pcm512x-audio the DAC works with limited functionality. This bypasses all channels separation 2xPCM, lowpass, etc.

@pelwell
Copy link
Contributor

pelwell commented Dec 10, 2024

Are you seeing any of my debug output when you use the controls? If not, which controls are available to you in this subset?

@foonerd
Copy link
Contributor Author

foonerd commented Dec 10, 2024

I think I made my last remark confusing.
Hardware is Piano 2.1

  1. When using https://github.com/raspberrypi/linux/blob/rpi-6.6.y/sound/soc/bcm/allo-piano-dac.c via overlay https://github.com/raspberrypi/linux/blob/rpi-6.6.y/arch/arm/boot/dts/overlays/allo-piano-dac-pcm512x-audio-overlay.dts there are limited controls I was referring to. Audio is active via one of the pcm512x chip.

  2. However, the DAC should be using https://github.com/raspberrypi/linux/blob/rpi-6.6.y/sound/soc/bcm/allo-piano-dac-plus.c via overlay https://github.com/raspberrypi/linux/blob/rpi-6.6.y/arch/arm/boot/dts/overlays/allo-piano-dac-plus-pcm512x-audio-overlay.dts and this is where debug output has been added.

Will add debug params to 1 and check.

@foonerd
Copy link
Contributor Author

foonerd commented Dec 10, 2024

The 1 seems to be producing events. Not sure how this is going to help though.

Comparing with working DAC on kernel 6.1.y, the node parameters is created under /sys/module/snd_soc_allo_piano_dac_plus/ and this is what alsa is using for hw2. On kernel 6.6.y node is missing.

@foonerd
Copy link
Contributor Author

foonerd commented Dec 10, 2024

A simple test, forcing bogus return 0; from snd_allo_piano_dac_probe and it is clear that all the params are not available to alsa. There is literally nothing in dmesg nor journalctl to follow up on. Any ideas?

@foonerd
Copy link
Contributor Author

foonerd commented Dec 10, 2024

Hey @pelwell,

This is getting interesting. After adding #include <linux/i2c.h> all of the sudden:

[   12.949688] < read 13d (306)
[   12.949693] > read 13d -> 30 (306)
[   12.949694] < read 13e (308)
[   12.949695] > read 13e -> 30 (308)
[   12.949697] < write 13e = 30 (328)
[   12.950447] > write 13e = 30 ret 0 (328)
[   12.950449] < write 13d = 30 (330)
[   12.951185] > write 13d = 30 ret 0 (330)
[   12.951187] < write 103 = 0 (332)
[   12.951916] > write 103 = 0 ret 0 (332)
[   12.951917] < write 103 = 0 (334)
[   12.952646] > write 103 = 0 ret 0 (334)

@pelwell
Copy link
Contributor

pelwell commented Dec 10, 2024

The output here (https://paste.debian.net/hidden/168f11aa/) showed it reaching the end of snd_allo_piano_dac_probe ("DAC issue #6527"), so why do you need to force it? And what changed between that run and the previous one (that produced much less output), other than the addition of the "DAC probe begin" message?

@foonerd
Copy link
Contributor Author

foonerd commented Dec 10, 2024

The only differences at this point were:

  1. add another message at the start of snd_allo_piano_dac_probe
  2. switched all power off, coffee break, power back on

@pelwell
Copy link
Contributor

pelwell commented Dec 10, 2024

Your log above shows the output from snd_allo_piano_dual_mode_put, turning dual_mode off. Do any other controls exist/work?

@foonerd
Copy link
Contributor Author

foonerd commented Dec 10, 2024

The amixer is used to set specific hwdevice with params. However, module once loaded renders alsa completely unresponsive and console hungs. No other controls are available. The continuous message kernel: INFO: task alsactl:1683 blocked for more than xxx seconds about 2 min apart.

@foonerd
Copy link
Contributor Author

foonerd commented Dec 11, 2024

Well, the DAC init is stuck here, indefinite loop:

[  484.320360] "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message.
[  484.320363] task:alsactl         state:D stack:0     pid:750   ppid:1      flags:0x00400801
[  484.320369] Call trace:
[  484.320372]  __switch_to+0xe0/0x148
[  484.320381]  __schedule+0x31c/0xd60
[  484.320385]  schedule+0x64/0x108
[  484.320389]  schedule_preempt_disabled+0x2c/0x50
[  484.320393]  rwsem_down_write_slowpath+0x23c/0x6e0
[  484.320398]  down_write+0xa0/0xb0
[  484.320402]  snd_ctl_release+0x74/0x138 [snd]
[  484.320427]  __fput+0xc4/0x290
[  484.320432]  __fput_sync+0x58/0x70
[  484.320434]  __arm64_sys_close+0x40/0x90
[  484.320440]  invoke_syscall+0x50/0x128
[  484.320446]  el0_svc_common.constprop.0+0xd0/0xf8
[  484.320450]  do_el0_svc_compat+0x28/0x48
[  484.320455]  el0_svc_compat+0x30/0x88
[  484.320458]  el0t_32_sync_handler+0x98/0x148
[  484.320461]  el0t_32_sync+0x194/0x198

I think without addressing this part, we can't progress further.
Earlier on you mention that this may be related to mutex. Suggestions?

@foonerd
Copy link
Contributor Author

foonerd commented Jan 1, 2025

Thank you for looking into this.
The problem surfaces when setting volume above ca' 25% of threshold, after this level audio become distorted; similar to over-amplification. Hence why I think that this is linked.

If you can spare a bit of time, and take a look into the last week discussions in community thread.

dmesg:

[   16.550860] snd-allo-piano-dac-plus soc:sound: Failed to set master volume limit: -22
[   16.550884] snd-allo-piano-dac-plus soc:sound: Failed to set subwoofer volume limit: -22
[  314.091468] snd-allo-piano-dac-plus soc:sound: snd_soc_register_card() failed: -517
[  314.096541] snd-allo-piano-dac-plus soc:sound: snd_soc_register_card() failed: -517
[  314.116804] snd-allo-piano-dac-plus soc:sound: snd_soc_register_card() failed: -517
[  314.121478] snd-allo-piano-dac-plus soc:sound: Failed to set master volume limit: -22
[  314.121500] snd-allo-piano-dac-plus soc:sound: Failed to set subwoofer volume limit: -22

popcornmix pushed a commit that referenced this issue Jan 2, 2025
Calling snd_soc_limit_volume from within a kcontrol put handler seems
to cause a deadlock as it attempts to claim a write lock that is already
held. Call snd_soc_limit_volume from the main initialisation code
instead, to avoid the recursive locking.

See: #6527

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this issue Jan 2, 2025
Calling snd_soc_limit_volume from within a kcontrol put handler seems
to cause a deadlock as it attempts to claim a write lock that is already
held. Call snd_soc_limit_volume from the main initialisation code
instead, to avoid the recursive locking.

See: #6527

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this issue Jan 6, 2025
Calling snd_soc_limit_volume from within a kcontrol put handler seems
to cause a deadlock as it attempts to claim a write lock that is already
held. Call snd_soc_limit_volume from the main initialisation code
instead, to avoid the recursive locking.

See: #6527

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
@foonerd
Copy link
Contributor Author

foonerd commented Jan 7, 2025

Hey @pelwell,

Let me know, which version/combination I can help testing. I still have the debug build from our initial investigation.
Noticed few things which may help:
soc:sound: snd_soc_register_card() failed: -517 happens when DSP firmware is loaded.
snd-allo-piano-dac-plus soc:sound: Failed to set master volume limit: -22 happens, when DAC is set in dual stereo mode.

Something I have not noticed before:
dmesg -w | grep pcm512x

[   31.056865] pcm512x 1-004c: No SCLK, using BCLK: -2
[   31.058415] pcm512x 1-004d: No SCLK, using BCLK: -2
[   31.084708] pcm512x 1-004c: No SCLK, using BCLK: -2
[   31.084719] pcm512x 1-004d: No SCLK, using BCLK: -2
[   31.269532] pcm512x 1-004c: No SCLK, using BCLK: -2
[   31.269542] pcm512x 1-004d: No SCLK, using BCLK: -2
[   31.392276] pcm512x 1-004c: No SCLK, using BCLK: -2
[   31.392285] pcm512x 1-004d: No SCLK, using BCLK: -2

Regarding audio stage itself, it is over-amplified. Raspberry Pi 4B, Pi5 2/4/8GB with the same results.
Pi Kernel 6.1.x: External AMP is set @ 50%, DAC @ 40 - 90% and no distortion.
Pi Kernel 6.6.x: External AMP is set @ 5%, DAC @ 25% and distortion is audible.

@foonerd
Copy link
Contributor Author

foonerd commented Jan 8, 2025

Hey @pelwell,

Question regarding snd_allo_piano_dac_init

is unassigned at this point. Perhaps setting ret = 0 avoids unintentional propagation of undefined or stale values.
In 6.1 this is controlled by and

@foonerd
Copy link
Contributor Author

foonerd commented Jan 8, 2025

Perhaps move to

as int i, j, ret = 0; would make sense? Comparing with other dacs, the struct snd_soc_card *card = rtd->card; is part of if (digital_gain_0db_limit) {}. In piano case, it is directly under snd_soc_pcm_runtime.

@foonerd
Copy link
Contributor Author

foonerd commented Jan 8, 2025

Another place I am looking at do bolt on

compatible = "allo,piano-dac-plus";
digital_gain_0db_limit = <1>;

@foonerd
Copy link
Contributor Author

foonerd commented Jan 8, 2025

@pelwell,

The same system, only kernel is different. From amixer -c<num> scontents there is clear evidence that the digital_gain_0db_limit is ineffective and range 0 -> 255 is always set in kernel 6.6.y.

Kernel Card Link
6.1.y amixer -c2 scontents http://paste.debian.net/1343878/
6.6.y amixer -c0 scontents http://paste.debian.net/1343882/

@pelwell
Copy link
Contributor

pelwell commented Jan 8, 2025

Perhaps setting ret = 0 avoids unintentional propagation of undefined or stale values.

The variable is initialised on the very next (non-blank) line. This isn't the cause of the problem.

Another place I am looking at do bolt on

I don't understand what you mean.

I'm back looking at this issue (it would be nice to be rid of it). It seems likely that my initial uneasiness ("I'm not sure if the code was arranged as it was for good reasons or just carelessness.") may have been justified.

@foonerd
Copy link
Contributor Author

foonerd commented Jan 8, 2025

Another place I am looking at do bolt on

I don't understand what you mean.

Sometimes it is possible to nudge with an overlay parameters. Ignore this please, makes no effect.

I can share module code via Pastezone if this helps.

@pelwell
Copy link
Contributor

pelwell commented Jan 8, 2025

Thanks, but that won't be necessary - it's completely reproducible here.

pelwell added a commit to pelwell/linux that referenced this issue Jan 8, 2025
Controls which only exist when snd_soc_register_card returns can't be
modified before then. Move the setting of volume limits to just before
the end of the probe function.

Link: raspberrypi#6527

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
@foonerd
Copy link
Contributor Author

foonerd commented Jan 8, 2025

Hey @pelwell ,

Excellent result. No distortion, no dmesg errors. Kernel 6.6.y amixer -c0 scontents: http://paste.debian.net/1344094/

I will test with 24db_digital_gain and glb_mclk in dtoverlay, just to check if gain and Kali still works.

@foonerd
Copy link
Contributor Author

foonerd commented Jan 8, 2025

Hey @pelwell,

Dtoverlay Result Comment
dtoverlay=allo-piano-dac-plus-pcm512x-audio http://paste.debian.net/1344094/ digital_gain_0db_limit in effect
allo-piano-dac-plus-pcm512x-audio,24db_digital_gain http://paste.debian.net/1344097/ 24db_digital_gain in effect
allo-piano-dac-plus-pcm512x-audio,glb_mclk pcm512x 1-004c: Setting SCLK as input clock & disabled PLL
pcm512x 1-004d: Setting SCLK as input clock & disabled PLL
Kali re-clocker SCLK active

All checks out.

@pelwell
Copy link
Contributor

pelwell commented Jan 8, 2025

And that's with all three patches applied?

@foonerd
Copy link
Contributor Author

foonerd commented Jan 8, 2025

All three.

Code with extra traces (will remove in final build) here: https://dpaste.com/AYHDNNBNL
I think that change to pcm512x is cosmetic, bears no functional effect. Nonetheless, removes the message from dmesg.

pelwell added a commit that referenced this issue Jan 8, 2025
Controls which only exist when snd_soc_register_card returns can't be
modified before then. Move the setting of volume limits to just before
the end of the probe function.

Link: #6527

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
@pelwell
Copy link
Contributor

pelwell commented Jan 8, 2025

Thanks - that's merged now.

@foonerd
Copy link
Contributor Author

foonerd commented Jan 8, 2025

Thank you. Will trigger community build and get this tested. Perhaps let's leave this open for a day or two, test results pending.

pelwell added a commit that referenced this issue Jan 9, 2025
Controls which only exist when snd_soc_register_card returns can't be
modified before then. Move the setting of volume limits to just before
the end of the probe function.

Link: #6527

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
pelwell added a commit that referenced this issue Jan 9, 2025
Controls which only exist when snd_soc_register_card returns can't be
modified before then. Move the setting of volume limits to just before
the end of the probe function.

Link: #6527

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this issue Jan 10, 2025
Calling snd_soc_limit_volume from within a kcontrol put handler seems
to cause a deadlock as it attempts to claim a write lock that is already
held. Call snd_soc_limit_volume from the main initialisation code
instead, to avoid the recursive locking.

See: #6527

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this issue Jan 10, 2025
Controls which only exist when snd_soc_register_card returns can't be
modified before then. Move the setting of volume limits to just before
the end of the probe function.

Link: #6527

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
@foonerd
Copy link
Contributor Author

foonerd commented Jan 11, 2025

Based on community feedback, closing as resolved.

@foonerd foonerd closed this as completed Jan 11, 2025
popcornmix pushed a commit that referenced this issue Jan 13, 2025
Calling snd_soc_limit_volume from within a kcontrol put handler seems
to cause a deadlock as it attempts to claim a write lock that is already
held. Call snd_soc_limit_volume from the main initialisation code
instead, to avoid the recursive locking.

See: #6527

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
popcornmix pushed a commit that referenced this issue Jan 13, 2025
Controls which only exist when snd_soc_register_card returns can't be
modified before then. Move the setting of volume limits to just before
the end of the probe function.

Link: #6527

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
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

No branches or pull requests

4 participants