With CM4 I was using the following code in /etc/rc.local to enable speakers at startup:
# CM4
echo 523 | sudo tee /sys/class/gpio/export
echo out | sudo tee /sys/class/gpio/gpio523/direction
echo 1 | sudo tee /sys/class/gpio/gpio523/value
Now, after some research I established a working solution for CM5.
You need to use dtoverlay=audremap-pi5,pins_12_13
in config.txt and have 6.12.17 kernel at least.
And after comparing PI4 and PI5 gpio mappings, I found that gpio580 is what we need! Here some pins from schematic:
HP_DET - GPIO10
PA_EN - GPIO11
AUD_PWMO - GPIO12
AUD_PWM1 - GPIO13
# CM5
echo 580 | sudo tee /sys/class/gpio/export
echo out | sudo tee /sys/class/gpio/gpio580/direction
echo 1 | sudo tee /sys/class/gpio/gpio580/value
And now sound is working from speakers.
Here is the relevant output from /sys/kernel/debug/gpio
:
gpio-580 (GPIO11 |sysfs ) out hi
gpio-581 (GPIO12 )
gpio-582 (GPIO13 )