thesofproject / linux

Linux kernel source tree
Other
90 stars 129 forks source link

Hardware-dependent RT714 DMIC settings needed #5043

Closed plbossart closed 1 month ago

plbossart commented 4 months ago

UCM relies on this setting

BootSequence [
    cset "name='rt714 ADC 22 Mux' 'DMIC3'"

But as noted in https://wiki.archlinux.org/title/Dell_XPS_17_(9720)#Microphone and https://github.com/thesofproject/sof/issues/7799#issuecomment-2151551316 the working setting is DMIC1

The question is: can this be detected from ACPI, or do we have to quirk the component string to make UCM aware of the DMIC hardware layout.

@jack-cy-yu @shumingfan @bardliao @eighthave FYI

jack-cy-yu commented 4 months ago

I'd like to borrow one device to make sure why dmic1 is used but not dmic3, because per my understanding, rt714 is configured to use dmic3 in schematics

jack-cy-yu commented 4 months ago

@plbossart Do you know how can we get "PCI ID(SVID/SSID)" on the device (Dell_XPS_17_9720) ? Our hardware engineer team would like to check the schematics first, and they'd like to know the corresponding "PCI ID(SVID/SSID)", because for DELL-9720 device, there are many versions of schematics, but it can be classfied by "PCI ID(SVID/SSID)".

jack-cy-yu commented 4 months ago

@plbossart Do you know how can we get "PCI ID(SVID/SSID)" on the device (Dell_XPS_17_9720) ? Our hardware engineer team would like to check the schematics first, and they'd like to know the corresponding "PCI ID(SVID/SSID)", because for DELL-9720 device, there are many versions of schematics, but it can be classfied by "PCI ID(SVID/SSID)".

We've got these ID info.

jack-cy-yu commented 4 months ago

@plbossart @eighthave Could you help dump registers while recording with DMIC1, and another register dump while DMIC3 recording? Thanks.

eighthave commented 4 months ago

Yes, sure, as long as you walk me through how. I'm a Debian Developer and former audio programmer, so I know my way around, but I have only high level understanding of kernel-level stuff.

jack-cy-yu commented 4 months ago

@eighthave Please use "cat /sys/kernel/debug/regmap/sdw-addr/registers" to dump registers while recording with DMIC1 and DMIC3. And for "sdw-addr", there are "sdw:xxxxxx" and "sdw:xxxxxx-sdw-mbq", we need both dump. Thanks.

eighthave commented 4 months ago

Here's how I did it:

for f in /sys/kernel/debug/regmap/sdw*/name ; do
  cat $(dirname $f)/registers > "/tmp/rt714 ADC 22 Mux [DMIC3] $(basename $(dirname $f)) $(cat $f).bin"&
done
sleep 10
killall cat

And here are the resulting files: rt714 ADC 22 Mux.zip

eighthave commented 4 months ago

Also, I hadn't tried DMIC3 before, only DMIC1. It seems that DMIC3 works fine.

jack-cy-yu commented 4 months ago

@eighthave You can record with DMIC3 !? I thought @plbossart added this issue because you failed to record with DMIC3? Did I miss any information or I misunderstand this issue?

eighthave commented 4 months ago

With the defaults that I got with Debian/bookworm, I could not record from either the built-in microphone, nor the headset jack. I went through the steps in https://wiki.archlinux.org/title/Dell_XPS_17_(9720)#Microphone and that allowed recording on both the built-in microphone and the headset jack. I could be wrong, but I think "rt714 ADC 22 Mux" was not set to DMIC3 when I made the changes.

jack-cy-yu commented 4 months ago

Looks like an UCM issue, you can double check your UCM (/usr/share/alsa/ucm2) and compare with https://github.com/alsa-project/alsa-ucm-conf/blob/master/ucm2/codecs/rt715-sdca/init.conf https://github.com/alsa-project/alsa-ucm-conf/blob/master/ucm2/sof-soundwire/rt715-sdca.conf https://github.com/alsa-project/alsa-ucm-conf/blob/master/ucm2/sof-soundwire/sof-soundwire.conf

check if there are differences related to rt715.

eighthave commented 4 months ago

It is a plain upstream v1.2.8 (Debian/stable), except for three patches related to Pine* and Librem:

https://salsa.debian.org/alsa-team/alsa-ucm-conf/-/tree/debian/1.2.8-1

Should I upgrade to 1.2.11?

eighthave commented 4 months ago

This is the diff:

$  diff -uw /usr/share/alsa/ucm2/codecs/rt715-sdca/init.conf ucm2/codecs/rt715-sdca/init.conf
$  diff -uw /usr/share/alsa/ucm2/sof-soundwire/rt715-sdca.conf ucm2/sof-soundwire/rt715-sdca.conf
--- /usr/share/alsa/ucm2/sof-soundwire/rt715-sdca.conf  2022-10-24 10:17:39.000000000 +0200
+++ ucm2/sof-soundwire/rt715-sdca.conf  2024-06-07 10:44:38.932859077 +0200
@@ -17,5 +17,6 @@
          CaptureSwitch "rt714 FU02 Capture Switch"
          CaptureVolume "rt714 FU02 Capture Volume"
          CaptureMixerElem "rt714 FU02"
+       CaptureMicInfoFile "${var:LibDir}/dmics-nhlt.json"
    }
 }
$  diff -uw /usr/share/alsa/ucm2/sof-soundwire/sof-soundwire.conf ucm2/sof-soundwire/sof-soundwire.conf
--- /usr/share/alsa/ucm2/sof-soundwire/sof-soundwire.conf   2022-10-24 10:17:39.000000000 +0200
+++ ucm2/sof-soundwire/sof-soundwire.conf   2024-06-07 10:44:38.932859077 +0200
@@ -15,6 +15,7 @@
    HeadsetCodec1 ""
    MicCodec1 ""
    Mics1 "0"
+   Iec61937Pcms1 ""
 }

 DefineRegex {
@@ -35,19 +36,76 @@
        String "${CardComponents}"
    }
    MicCodec {
-       Regex " mic:([a-z0-9]+(-sdca)?)"
+       Regex " mic:([a-z0-9]+(-dmic)?+(-sdca)?)"
        String "${CardComponents}"
    }
    Mics {
        Regex " cfg-mics:([1-9][0-9]*)"
        String "${CardComponents}"
    }
+   Iec61937Pcms {
+       Regex "iec61937-pcm:(([0-9]+(,))*[0-9]+)"
+       String "${CardComponents}"
+   }
 }

+DefineRegex.MultiCodec {
+   Regex "(rt722(-sdca)?)"
+   String "${var:SpeakerCodec1} ${var:HeadsetCodec1} ${var:MicCodec1}"
+}
+
+If.multi_init {
+   Condition {
+       Type String
+       Empty "${var:MultiCodec1} "
+   }
+   False {
+       Define {
+           MultiSpeakerShadow "${var:SpeakerCodec1}"
+           MultiMicShadow "${var:MicCodec1}"
+       }
+       Include.multi_init.File "/codecs/${var:MultiCodec1}/init.conf"
+   }
+}
+
+If.multi_speaker {
+   Condition {
+       Type RegexMatch
+       Regex "${var:SpeakerCodec1}"
+       String "${var:MultiCodec1}"
+   }
+   True {
+       Define.SpeakerCodec1 ""
+   }
+}
+
+If.multi_mic {
+   Condition {
+       Type RegexMatch
+       Regex "${var:MicCodec1}"
+       String "${var:MultiCodec1}"
+   }
+   True {
+       Define.MicCodec1 ""
+   }
+}
+
+If.multi_headset {
+   Condition {
+       Type RegexMatch
+       Regex "${var:HeadsetCodec1}"
+       String "${var:MultiCodec1}"
+   }
+   True {
+       Define.HeadsetCodec1 ""
+   }
+}
+
+
 If.hs_init {
    Condition {
        Type RegexMatch
-       Regex "(rt5682|rt700|rt711(-sdca)?)"
+       Regex "(cs42l43|rt5682|rt700|rt711|rt713(-sdca)?)"
        String "${var:HeadsetCodec1}"
    }
    True.Include.hs_init.File "/codecs/${var:HeadsetCodec1}/init.conf"
@@ -56,8 +114,88 @@
 If.mic_init {
    Condition {
        Type RegexMatch
-       Regex "(rt715(-sdca)?)"
+       Regex "(rt713-dmic|rt715(-sdca)?)"
        String "${var:MicCodec1}"
    }
    True.Include.mic_init.File "/codecs/${var:MicCodec1}/init.conf"
 }
+
+If.mic_init_rt715 {
+   Condition {
+       Type String
+       Needle "rt715"
+       Haystack "${var:MicCodec1}"
+   }
+   True.BootSequence [
+       sysw "-/class/sound/ctl-led/mic/card${CardNumber}/detach:PGA5.0 5 Master Capture Switch"
+   ]
+}
+
+If.pga_init_pga2 {
+   Condition {
+       Type ControlExists
+       Control "name='PGA2.0 2 Master Capture Switch'"
+   }
+   True.BootSequence [
+       cset "name='PGA2.0 2 Master Capture Switch' 1"
+   ]
+}
+
+If.pga_init_pga5 {
+   Condition {
+       Type ControlExists
+       Control "name='PGA5.0 5 Master Capture Switch'"
+   }
+   True.BootSequence [
+       cset "name='PGA5.0 5 Master Capture Switch' 1"
+   ]
+}
+
+If.mics-array {
+   Condition {
+       Type String
+       Empty "${var:Mics1}"
+   }
+   False.FixedBootSequence {
+        # dmic array info
+       exec "-nhlt-dmic-info -o ${var:LibDir}/dmics-nhlt.json"
+   }
+}
+
+Include.hdmi-pcm.File "/common/pcm/hdmi.conf"
+
+If.Hdmi5-iec61937 {
+   Condition {
+       Type RegexMatch
+       Regex "((^|,)[5](,|$))"
+       String "${var:Iec61937Pcms1}"
+   }
+   True.Macro.hdmi5.HdmiPCM { Device 5 Index 0 }
+}
+
+If.Hdmi6-iec61937 {
+   Condition {
+       Type RegexMatch
+       Regex "((^|,)[6](,|$))"
+       String "${var:Iec61937Pcms1}"
+   }
+   True.Macro.hdmi6.HdmiPCM { Device 6 Index 1 }
+}
+
+If.Hdmi7-iec61937 {
+   Condition {
+       Type RegexMatch
+       Regex "((^|,)[7](,|$))"
+       String "${var:Iec61937Pcms1}"
+   }
+   True.Macro.hdmi7.HdmiPCM { Device 7 Index 2 }
+}
+
+If.HdmiIec61937 {
+   Condition {
+       Type RegexMatch
+       Regex "((^|,)[567](,|$))"
+       String "${var:Iec61937Pcms1}"
+   }
+   True.Macro.save_hdmi_cfg.HdmiPCMSave { Name "42-sof-hdmi" }
+}
jack-cy-yu commented 4 months ago

Is there any error message related to UCM in dmesg? It seems that rt715 is already included in your original UCM, I don't know why UCM doesn't take effect. @plbossart Do you have any comment?

eighthave commented 4 months ago

Looks like lots in syslog, but none currently in dmesg:

# grep -i ucm /var/log/syslog
[snip]
2024-06-06T21:35:49.142956+02:00 monolith pipewire[2632]: I spa.alsa [alsa-pcm.c:1010:spa_alsa_open]: 0x55d9a9271948: ALSA device open '_ucm0001.hw:sofsoundwire,2' playback
2024-06-06T21:35:49.227485+02:00 monolith pipewire[2632]: I spa.alsa [alsa-pcm.c:934:probe_pitch_ctl]: _ucm0001.hw:sofsoundwire,2 could not find ctl device: No such file or directory
2024-06-06T22:45:09.095723+02:00 monolith pipewire[2632]: I spa.alsa [alsa-pcm.c:1010:spa_alsa_open]: 0x55d9a9271948: ALSA device open '_ucm0001.hw:sofsoundwire,2' playback
2024-06-06T22:45:09.184266+02:00 monolith pipewire[2632]: I spa.alsa [alsa-pcm.c:934:probe_pitch_ctl]: _ucm0001.hw:sofsoundwire,2 could not find ctl device: No such file or directory
2024-06-06T23:06:10.222229+02:00 monolith pipewire[2632]: I spa.alsa [alsa-pcm.c:1010:spa_alsa_open]: 0x55d9a9271948: ALSA device open '_ucm0001.hw:sofsoundwire,2' playback
2024-06-06T23:06:10.313301+02:00 monolith pipewire[2632]: I spa.alsa [alsa-pcm.c:934:probe_pitch_ctl]: _ucm0001.hw:sofsoundwire,2 could not find ctl device: No such file or directory
2024-06-07T09:38:19.342526+02:00 monolith pipewire[2632]: I spa.alsa [alsa-pcm.c:1010:spa_alsa_open]: 0x55d9a9271948: ALSA device open '_ucm0001.hw:sofsoundwire,2' playback
2024-06-07T09:38:19.342759+02:00 monolith pipewire[2632]: I spa.alsa [alsa-pcm.c:934:probe_pitch_ctl]: _ucm0001.hw:sofsoundwire,2 could not find ctl device: No such file or directory
2024-06-07T09:39:28.193831+02:00 monolith pipewire[2632]: I spa.alsa [alsa-pcm.c:1010:spa_alsa_open]: 0x55d9a92433e8: ALSA device open '_ucm0001.hw:sofsoundwire' playback
2024-06-07T09:39:28.441495+02:00 monolith pipewire[2632]: D spa.alsa [alsa-pcm.c:951:probe_pitch_ctl]: _ucm0001.hw:sofsoundwire: did not find ctl Playback Pitch 1000000: No such file or directory
2024-06-07T10:08:46.886419+02:00 monolith pipewire[2632]: I spa.alsa [alsa-pcm.c:1010:spa_alsa_open]: 0x55d9a92ce408: ALSA device open '_ucm0001.hw:sofsoundwire,4' capture
2024-06-07T10:08:46.900599+02:00 monolith pipewire[2632]: I spa.alsa [alsa-pcm.c:934:probe_pitch_ctl]: _ucm0001.hw:sofsoundwire,4 could not find ctl device: No such file or directory
2024-06-07T10:43:22.562231+02:00 monolith pipewire[2632]: I spa.alsa [alsa-pcm.c:1010:spa_alsa_open]: 0x55d9a92433e8: ALSA device open '_ucm0001.hw:sofsoundwire' playback
2024-06-07T10:43:22.930199+02:00 monolith pipewire[2632]: D spa.alsa [alsa-pcm.c:951:probe_pitch_ctl]: _ucm0001.hw:sofsoundwire: did not find ctl Playback Pitch 1000000: No such file or directory
2024-06-07T11:11:24.296492+02:00 monolith pipewire[2632]: I spa.alsa [alsa-pcm.c:1010:spa_alsa_open]: 0x55d9a92433e8: ALSA device open '_ucm0001.hw:sofsoundwire' playback
2024-06-07T11:11:24.668388+02:00 monolith pipewire[2632]: D spa.alsa [alsa-pcm.c:951:probe_pitch_ctl]: _ucm0001.hw:sofsoundwire: did not find ctl Playback Pitch 1000000: No such file or directory
plbossart commented 1 month ago

not clear if this bug is current, please open a new issue with data if this persists.