[Razer Phone 2 ROMs, Kernels, Recoveries, & Other D] thecubed:
Warrior1988: A2DP isn't in play here, and I'm using the stock /system and /vendor partitions, so any razer-customized tweaks are still present.

Currently, I've been working on figuring out the codec mappings to make sure that when audio is being recorded in the custom kernel that all the appropriate routing is set to enable audio from the tfa98xx chip (NXP amplifier, apparently supports digital microphones too?) or the wcd934x codec.

I'm not sure where the microphones are physically connected internally, so I'm working backwards from what gets enabled/disabled when recording audio in the stock kernel.

So far I have observed a few things (pardon my potentially incorrect terminology, the whole linux ASOC sound layer is new to me):

1. Audio in the stock and custom kernels is being captured by the mixer device called "SDM845 Media1", and it is capturing from SLIMBUS_0_TX input.

[Recording]
aura:/sys/module # cat /sys/kernel/debug/asoc/sdm845-tavil-snd-card/SDM845\ Media1/state
[SDM845 Media1 - Playback]
State: new
Backends:
No active DSP links
[SDM845 Media1 - Capture]
State: start
Hardware Params: Format = S16_LE, Channels = 1, Rate = 16000
Backends:
- SLIMBUS_0_TX
State: start
Hardware Params: Format = S16_LE, Channels = 1, Rate = 48000

2. You can also see when recording and not recording that in both kernels the SLIMBUS_0_TX input is wired correctly to the right mixer:

[Not recording]
aura:/sys # cat ./kernel/debug/asoc/sdm845-tavil-snd-card/platform:soc:qcom,msm-pcm-routing/dapm/SLIMBUS_0_TX
SLIMBUS_0_TX: Off in 2 out 0 - R0(0x0) mask 0x1
stream Slimbus Capture inactive
out "static" "SLIM0_UL_HL"
in "static" "Slimbus Capture"
in "static" "BE_IN"

[Recording]
aura:/sys # cat ./kernel/debug/asoc/sdm845-tavil-snd-card/platform:soc:qcom,msm-pcm-routing/dapm/SLIMBUS_0_TX
SLIMBUS_0_TX: On in 2 out 1 - R0(0x0) mask 0x1
stream Slimbus Capture inactive
out "static" "SLIM0_UL_HL"
out "SLIM_0_TX" "MultiMedia1 Mixer"
in "static" "Slimbus Capture"
in "static" "BE_IN"

Now that I've observed those things, I need to do a bit more research on how audio can get enabled/disabled on each of the chips that touch it.

For instance, in the custom kernel, I noticed that during recording sounds the DMIC* lines on the second tfa98xx aren't enabled. I haven't checked in the stock kernel yet - but if the tfa98xx chip is providing mic bias, it's possible that everything is wired right for input but since the mic bias isn't on, the mic isn't powered and thus we get no sound.

(Updated side note, why is Razer Phone 2 is using two TFA9888 chips? The tfa98xx.cnt firmware references TFA9892 which is mono only, too. I need to see a disassembly to figure out what chips it's actually using...)

aura:/sys # cat ./kernel/debug/asoc/sdm845-tavil-snd-card/codec:tfa98xx.4-0034/dapm/DMIC*
DMIC1: Off in 1 out 0
out "static" "AIF OUT"
DMIC2: Off in 1 out 0
out "static" "AIF OUT"
DMIC3: Off in 1 out 0
out "static" "AIF OUT"
DMIC4: Off in 1 out 0
out "static" "AIF OUT"
aura:/sys # cat ./kernel/debug/asoc/sdm845-tavil-snd-card/codec:tfa98xx.4-0035/dapm/DMIC*
DMIC1: Off in 1 out 0
out "static" "AIF OUT"
in "static" "MIC BIAS1"
DMIC2: Off in 1 out 0
out "static" "AIF OUT"
DMIC3: Off in 1 out 0
out "static" "AIF OUT"
in "static" "MIC BIAS3"
DMIC4: Off in 1 out 0
out "static" "AIF OUT"

Update: just noticed that this path doesn't exist on stock kernel. So the TFA driver I have doesn't match the one Razer is using. Interesting!

Also, I'm not sure why SLIMBUS_2 playback/capture aren't shown as 'dynamic DAI' linked (the '(*)' means it's a dynamic DAI)... Probably not important though.

aura:/proc/asound # cat pcm
00-00: MultiMedia1 (*) : : playback 1 : capture 1
00-01: MultiMedia2 (*) : : playback 1 : capture 1
00-02: VoiceMMode1 (*) : : playback 1 : capture 1
00-03: VoIP (*) : : playback 1 : capture 1
00-04: MultiMedia3 (*) : : playback 1
00-05: SLIMBUS_0 Hostless (*) : : playback 1 : capture 1
00-06: AFE-PROXY RX msm-stub-rx-6 : : playback 1
00-07: AFE-PROXY TX msm-stub-tx-7 : : capture 1
00-09: AUXPCM Hostless (*) : : playback 1 : capture 1
00-10: SLIMBUS_1 Hostless (*) : : playback 1 : capture 1
00-11: SLIMBUS_3 Hostless (*) : : playback 1 : capture 1
00-12: SLIMBUS_4 Hostless (*) : : playback 1 : capture 1
00-13: MultiMedia5 (*) : : playback 1 : capture 1
00-14: Listen 1 Audio Service (*) : : capture 1
00-16: MultiMedia10 (*) : : playback 1 : capture 1
00-17: MM_NOIRQ (*) : : playback 1 : capture 1
00-18: HDMI_RX_HOSTLESS (*) : : playback 1
00-19: VoiceMMode2 (*) : : playback 1 : capture 1
00-20: Listen 2 Audio Service (*) : : capture 1
00-21: Listen 3 Audio Service (*) : : capture 1
00-22: Listen 4 Audio Service (*) : : capture 1
00-23: Listen 5 Audio Service (*) : : capture 1
00-24: Listen 6 Audio Service (*) : : capture 1
00-25: Listen 7 Audio Service (*) : : capture 1
00-26: Listen 8 Audio Service (*) : : capture 1
00-27: MultiMedia9 (*) : : playback 1 : capture 1
00-33: MM_NOIRQ_2 (*) : : playback 1 : capture 1
00-34: SLIMBUS8_HOSTLESS Capture (*) : : capture 1
00-35: Slimbus4 Capture tavil_vifeedback-35 : : capture 1
00-36: SLIMBUS_2 Hostless Playback tavil_rx2-36 : : playback 1
00-37: SLIMBUS_2 Hostless Capture tavil_tx2-37 : : capture 1
00-38: MultiMedia6 (*) : : playback 1 : capture 1
00-39: USB Audio Hostless (*) : : playback 1 : capture 1
00-80: QUAT_MI2S_RX Hostless (*) : : playback 1

Meanwhile, we've reached out to Razer to see if they'll bless us with the full and complete kernel source this time ;)