tomsom / yoga-linux

Run Linux on the Lenovo Yoga 7 14 (14ARB7) with AMD Ryzen 6800U (Rembrand).
https://github.com/tomsom/yoga-linux/wiki
57 stars 2 forks source link

broken speakers #3

Open Okazakee opened 1 year ago

Okazakee commented 1 year ago

any news on 4 functioning speakers? There was a problem with pins connection not recognised by kernel or something like that.

Okazakee commented 1 year ago

So, using this will enable both tweeters and normal woofers w/out tlp just using systemd, confirm?

lamarios commented 1 year ago

Same fix as the wiki page, just simpler.

tomsom commented 1 year ago

Just a note on the wiki guide. I'm not sure why tlp is necessary same for the wake from suspend script as this can be done with the systemd unit as well and more compatible with some immutable distros (silverblue for example)

Disabling the power management is still required. then just add a single unit file in systemd:

[Unit]
Description=yoga7 bass speaker on
After=graphical.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target
[Service]
ExecStart=/bin/bash -c '/usr/sbin/i2cset -y 3 0x48 0x2 0 && /usr/sbin/i2cset -y 3 0x48 0x3 0'
[Install]
WantedBy=graphical.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target

enabling it then it works as expected.

Thank you :) Just changed it in the wiki

stuarthayhurst commented 1 year ago

What needs to be done upstream for this to be working out of the box?

Okazakee commented 1 year ago

Hello guys, I am pleased to announce that after the audio fix, all speakers work correctly and I've also found a useful repo with few pulseaudio presets to use with EasyEffects. God bless pipewire.

Using the custom preset gets me a really good audio experience even under linux finally.

Here's what you have to do:

  1. Install Easyeffects with the store (be sure to update to ver 6.3.0, i had some strange behaviour).
  2. Install "Advanced Auto Gain" profile from this repo using the command bash -c "$(curl -fsSL https://raw.githubusercontent.com/JackHack96/PulseEffects-Presets/master/install.sh)".
  3. Open EasyEffects and load auto gain profile.

Make sure to enable easyeffects and profiles on boot Hope this gets injected in the wiki :)

Okazakee commented 1 year ago

To clarify, I think this issue should be kept open until an official kernel fix or something that avoids the use of the current hack is introduced.

lamarios commented 1 year ago

that helps a lot. Thanks !

rodude123 commented 1 year ago

Hello guys, I am pleased to announce that after the audio fix, all speakers work correctly and I've also found a useful repo with few pulseaudio presets to use with EasyEffects. God bless pipewire.

Using the custom preset gets me a really good audio experience even under linux finally.

Here's what you have to do:

1. Install **Easyeffects** with the store (be sure to update to **ver 6.3.0**, i had some strange behaviour).

2. Install "**Advanced Auto Gain**" profile from this [repo](https://github.com/JackHack96/EasyEffects-Presets) using the command `bash -c "$(curl -fsSL https://raw.githubusercontent.com/JackHack96/PulseEffects-Presets/master/install.sh)"`.

3. Open EasyEffects and load auto gain profile.

Make sure to enable easyeffects and profiles on boot Hope this gets injected in the wiki :)

what setting did you use, I still have to use Analog Stereo Duplex/Output, can't use the Analog Surround 4.0 Output. If I test all speakers it works but the audio playing from a media source doesn't want to play from all speakers if I use Analog Surround 4.0 Output

Okazakee commented 1 year ago

Weird, I only have a single device showing in gnome, before and after the fix...

rodude123 commented 1 year ago

Weird, I only have a single device showing in gnome, before and after the fix...

what device is it just Hi-Fi Quality Music? That's what I used to have until I turned off ucm in the wire plumber config for pipewire

tomsom commented 1 year ago

Hello peeps! I'm a bit confused. For me max. 2 speakers will work at the same time. Also messing with i2cset changes the output speakers but if the audio stream is interrupted it changes back to the tweeters and I have to run the i2cset command again.

This is why I'm hesitant to label the audio issues as fixed. Am I the only one with those issues and it's just my system that is messed up in some way(then I'll change readme oc) or does anyone else have the same problems?

P.S. I'm on kernel 6.1.6, fedora

Edit: Listening a little closer I'm pretty sure(not certain tho) that not max. 2 speakers work, but that the woofers work with one tweeter(only the right one)(3 total). Which is weird? Also in the settings only a dual stereo speaker setup gets detected (Gnome & KDE) ("Hifi Quality Music") as well.

Myaats commented 1 year ago

Hello peeps! I'm a bit confused. For me max. 2 speakers will work at the same time. Also messing with i2cset changes the output speakers but if the audio stream is interrupted it changes back to the tweeters and I have to run the i2cset command again.

This is why I'm hesitant to label the audio issues as fixed. Am I the only one with those issues and it's just my system that is messed up in some way(then I'll change readme oc) or does anyone else have the same problems?

P.S. I'm on kernel 6.1.6, fedora

Edit: Listening a little closer I'm pretty sure(not certain tho) that not max. 2 speakers work, but that the woofers work with one tweeter(only the right one)(3 total). Which is weird? Also in the settings only a dual stereo speaker setup gets detected (Gnome & KDE) ("Hifi Quality Music") as well.

You can fix the reset issue by setting i2cset -y (ADAPTER FOR AMP, usually 3) 0x48 0x30 0x99

I diffed all the registers with what they are set on Windows to find that one.

Note that the i2c adapter id still seem not to be deterministic and can be different when you boot.

tomsom commented 1 year ago

It seems to work for me, thank you very much :) So basically I want to execute /usr/sbin/i2cset -y 3 0x48 0x2 0 && /usr/sbin/i2cset -y 3 0x48 0x3 0 && /usr/sbin/i2cset -y 3 0x48 0x30 0x99 with the systemd service.. or is there a better solution? Idk a lot about that kinda stuff so i wanna ask before maybe adding it to the wiki..

Okazakee commented 1 year ago

I suggest to add that workaround in the wiki if someone else can't use the default one

rodude123 commented 1 year ago

It seems to work for me, thank you very much :) So basically I want to execute /usr/sbin/i2cset -y 3 0x48 0x2 0 && /usr/sbin/i2cset -y 3 0x48 0x3 0 && /usr/sbin/i2cset -y 3 0x48 0x30 0x99 with the systemd service.. or is there a better solution? Idk a lot about that kinda stuff so i wanna ask before maybe adding it to the wiki..

This also works but only when I'm in Analog stereo duplex but not well when I'm in Analog Surround 4.0

jendakol commented 1 year ago

Hi, I just installed Ubuntu 22.04 to my Yoga 7 14ARB7 and want to note that the speakers don't work even after upgrading kernel to 6.1.9. Executing /usr/sbin/i2cset -y 3 0x48 0x2 0 && /usr/sbin/i2cset -y 3 0x48 0x3 0 && /usr/sbin/i2cset -y 3 0x48 0x30 0x99 works like a charm though. Thx!

g3blv commented 1 year ago

Will /usr/sbin/i2cset -y 3 0x48 0x2 0 && /usr/sbin/i2cset -y 3 0x48 0x3 0 && /usr/sbin/i2cset -y 3 0x48 0x30 0x99 also work for Lenovo Yoga S940-14IIL with Intel Core™ i7-1065G7 and Fedora Workstation 37 or are different values needed?

I tried running it, but I got Error: Write failed.

soupglasses commented 1 year ago

So I tried some more things today. Following https://github.com/agasecond/QemuDumpHDAVerbs got me further than other repositories. Passing in with vfio-pci:

33:00.6 Audio device [0403]: Advanced Micro Devices, Inc. [AMD] Family 17h/19h HD Audio Controller [1022:15e3]

Gets both speakers and headphones to show up in Windows 11. Installed drivers makes the HDA verbs show up. Awesome! But, it never made sound. No matter what i pass in, speaker or headset, will make it output audio i can hear. I may upload some HDA verbs from what i have gotten here, but they may be corrupt and not hold any value at all.

Notably, it will start with error about

qemu-system-x86_64: vfio: Cannot reset device 0000:33:00.6, depends on group 16 which is not owned.
qemu-system-x86_64: vfio: Cannot reset device 0000:33:00.6, depends on group 16 which is not owned.

From my understanding, this is due to the device being linked to the VGA device.

33:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Rembrandt [Radeon 680M] [1002:1681] (rev c1)

I sadly dont think we can pass-trough the whole internal GPU as well.

HDA verbs that may be corrupt: bootup-shutdown.txt messing-with-audio-settings.txt

output of `lspci -nn` ```console 00:00.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h PCIe Root Complex [1022:14b5] (rev 01) 00:00.2 IOMMU [0806]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h IOMMU [1022:14b6] 00:01.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h PCIe Dummy Host Bridge [1022:14b7] (rev 01) 00:02.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h PCIe Dummy Host Bridge [1022:14b7] (rev 01) 00:02.3 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h PCIe GPP Bridge [1022:14ba] 00:02.4 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h PCIe GPP Bridge [1022:14ba] 00:02.5 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h PCIe GPP Bridge [1022:14ba] 00:03.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h PCIe Dummy Host Bridge [1022:14b7] (rev 01) 00:03.1 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Family 19h USB4/Thunderbolt PCIe tunnel [1022:14cd] 00:04.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h PCIe Dummy Host Bridge [1022:14b7] (rev 01) 00:08.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h PCIe Dummy Host Bridge [1022:14b7] (rev 01) 00:08.1 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h Internal PCIe GPP Bridge [1022:14b9] (rev 10) 00:08.3 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h Internal PCIe GPP Bridge [1022:14b9] (rev 10) 00:14.0 SMBus [0c05]: Advanced Micro Devices, Inc. [AMD] FCH SMBus Controller [1022:790b] (rev 71) 00:14.3 ISA bridge [0601]: Advanced Micro Devices, Inc. [AMD] FCH LPC Bridge [1022:790e] (rev 51) 00:18.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Rembrandt Data Fabric: Device 18h; Function 0 [1022:1679] 00:18.1 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Rembrandt Data Fabric: Device 18h; Function 1 [1022:167a] 00:18.2 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Rembrandt Data Fabric: Device 18h; Function 2 [1022:167b] 00:18.3 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Rembrandt Data Fabric: Device 18h; Function 3 [1022:167c] 00:18.4 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Rembrandt Data Fabric: Device 18h; Function 4 [1022:167d] 00:18.5 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Rembrandt Data Fabric: Device 18h; Function 5 [1022:167e] 00:18.6 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Rembrandt Data Fabric: Device 18h; Function 6 [1022:167f] 00:18.7 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Rembrandt Data Fabric: Device 18h; Function 7 [1022:1680] 01:00.0 Network controller [0280]: MEDIATEK Corp. MT7922 802.11ax PCI Express Wireless Network Adapter [14c3:0616] 02:00.0 Non-Volatile memory controller [0108]: Micron Technology Inc Device [1344:5411] (rev 01) 03:00.0 SD Host controller [0805]: O2 Micro, Inc. SD/MMC Card Reader Controller [1217:8621] (rev 01) 33:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Rembrandt [Radeon 680M] [1002:1681] (rev c1) 33:00.1 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] Rembrandt Radeon High Definition Audio Controller [1002:1640] 33:00.2 Encryption controller [1080]: Advanced Micro Devices, Inc. [AMD] VanGogh PSP/CCP [1022:1649] 33:00.3 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Rembrandt USB4 XHCI controller #3 [1022:161d] 33:00.4 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Rembrandt USB4 XHCI controller #4 [1022:161e] 33:00.5 Multimedia controller [0480]: Advanced Micro Devices, Inc. [AMD] ACP/ACP3X/ACP6x Audio Coprocessor [1022:15e2] (rev 60) 33:00.6 Audio device [0403]: Advanced Micro Devices, Inc. [AMD] Family 17h/19h HD Audio Controller [1022:15e3] 34:00.0 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Rembrandt USB4 XHCI controller #8 [1022:161f] 34:00.3 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Rembrandt USB4 XHCI controller #5 [1022:15d6] 34:00.4 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Rembrandt USB4 XHCI controller #6 [1022:15d7] 34:00.5 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Rembrandt USB4/Thunderbolt NHI controller #1 [1022:162e] ```
IOMMU output ```console $ for dp in $(find /sys/kernel/iommu_groups/*/devices/*); do ploc=$(basename $dp | sed 's/0000://'); igrp=$(echo $dp | awk -F/ '{print $5}'); dinfo=$(lspci -nn | grep -E "^$ploc"); echo "[IOMMU $igrp] $dinfo" ; done [IOMMU 0] 00:01.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h PCIe Dummy Host Bridge [1022:14b7] (rev 01) [IOMMU 10] 00:08.3 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h Internal PCIe GPP Bridge [1022:14b9] (rev 10) [IOMMU 11] 00:14.0 SMBus [0c05]: Advanced Micro Devices, Inc. [AMD] FCH SMBus Controller [1022:790b] (rev 71) [IOMMU 11] 00:14.3 ISA bridge [0601]: Advanced Micro Devices, Inc. [AMD] FCH LPC Bridge [1022:790e] (rev 51) [IOMMU 12] 00:18.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Rembrandt Data Fabric: Device 18h; Function 0 [1022:1679] [IOMMU 12] 00:18.1 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Rembrandt Data Fabric: Device 18h; Function 1 [1022:167a] [IOMMU 12] 00:18.2 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Rembrandt Data Fabric: Device 18h; Function 2 [1022:167b] [IOMMU 12] 00:18.3 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Rembrandt Data Fabric: Device 18h; Function 3 [1022:167c] [IOMMU 12] 00:18.4 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Rembrandt Data Fabric: Device 18h; Function 4 [1022:167d] [IOMMU 12] 00:18.5 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Rembrandt Data Fabric: Device 18h; Function 5 [1022:167e] [IOMMU 12] 00:18.6 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Rembrandt Data Fabric: Device 18h; Function 6 [1022:167f] [IOMMU 12] 00:18.7 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Rembrandt Data Fabric: Device 18h; Function 7 [1022:1680] [IOMMU 13] 01:00.0 Network controller [0280]: MEDIATEK Corp. MT7922 802.11ax PCI Express Wireless Network Adapter [14c3:0616] [IOMMU 14] 02:00.0 Non-Volatile memory controller [0108]: Micron Technology Inc Device [1344:5411] (rev 01) [IOMMU 15] 03:00.0 SD Host controller [0805]: O2 Micro, Inc. SD/MMC Card Reader Controller [1217:8621] (rev 01) [IOMMU 16] 33:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Rembrandt [Radeon 680M] [1002:1681] (rev c1) [IOMMU 17] 33:00.1 Audio device [0403]: Advanced Micro Devices, Inc. [AMD/ATI] Rembrandt Radeon High Definition Audio Controller [1002:1640] [IOMMU 18] 33:00.2 Encryption controller [1080]: Advanced Micro Devices, Inc. [AMD] VanGogh PSP/CCP [1022:1649] [IOMMU 19] 33:00.3 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Rembrandt USB4 XHCI controller #3 [1022:161d] [IOMMU 1] 00:02.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h PCIe Dummy Host Bridge [1022:14b7] (rev 01) [IOMMU 20] 33:00.4 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Rembrandt USB4 XHCI controller #4 [1022:161e] [IOMMU 21] 33:00.5 Multimedia controller [0480]: Advanced Micro Devices, Inc. [AMD] ACP/ACP3X/ACP6x Audio Coprocessor [1022:15e2] (rev 60) [IOMMU 22] 33:00.6 Audio device [0403]: Advanced Micro Devices, Inc. [AMD] Family 17h/19h HD Audio Controller [1022:15e3] [IOMMU 23] 34:00.0 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Rembrandt USB4 XHCI controller #8 [1022:161f] [IOMMU 24] 34:00.3 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Rembrandt USB4 XHCI controller #5 [1022:15d6] [IOMMU 25] 34:00.4 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Rembrandt USB4 XHCI controller #6 [1022:15d7] [IOMMU 26] 34:00.5 USB controller [0c03]: Advanced Micro Devices, Inc. [AMD] Rembrandt USB4/Thunderbolt NHI controller #1 [1022:162e] [IOMMU 2] 00:02.3 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h PCIe GPP Bridge [1022:14ba] [IOMMU 3] 00:02.4 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h PCIe GPP Bridge [1022:14ba] [IOMMU 4] 00:02.5 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h PCIe GPP Bridge [1022:14ba] [IOMMU 5] 00:03.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h PCIe Dummy Host Bridge [1022:14b7] (rev 01) [IOMMU 6] 00:03.1 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Family 19h USB4/Thunderbolt PCIe tunnel [1022:14cd] [IOMMU 7] 00:04.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h PCIe Dummy Host Bridge [1022:14b7] (rev 01) [IOMMU 8] 00:08.0 Host bridge [0600]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h PCIe Dummy Host Bridge [1022:14b7] (rev 01) [IOMMU 9] 00:08.1 PCI bridge [0604]: Advanced Micro Devices, Inc. [AMD] Family 17h-19h Internal PCIe GPP Bridge [1022:14b9] (rev 10) ```
Details of GRUB command and kernel ```console $ cat /etc/dracut.conf.d/10-vfio.conf force_drivers+=" vfio_pci vfio vfio_iommu_type1 vfio_virqfd " $ sudo grubby --info /boot/vmlinuz-6.1.9-200.acs.fc37.x86_64 index=1 kernel="/boot/vmlinuz-6.1.9-200.acs.fc37.x86_64" args="ro rd.lvm.lv=nvme_vg/Fedora rhgb quiet vfio-pci.ids=1022:15e3,1002:1640 iommu=pt intel_iommu=on amd_iommu=on pcie_acs_override=downstream,multifunction" root="/dev/mapper/nvme_vg-Fedora" initrd="/boot/initramfs-linux.img" title="Fedora Linux (6.1.9-200.acs.fc37.x86_64) 37 (Workstation Edition)" id="24720004e3004a409a84c0db97ffe82d-6.1.9-200.acs.fc37.x86_64" ```
stuarthayhurst commented 1 year ago

It's worth noting that the 14IAL7 which is just the Intel version of the 14ARB7 already have a quirk for this including HDA verbs, I tried enabling it through kernel parameters without much luck. Since it shares the same chassis, codec and audio specs I would expect it to be the same. One guess is that the issue may have been the DSP w/ AMD Raphael not really being supported with kernel 6.0 which I tested with (Not sure if this could be related, i don't know the linux audio codec stack). Otherwise there could be differences in hardware, but I would find that weird.

I checked the subsystem id of the ALC287 codec in the 14ARB7 which has 0x17aa3870 and it is just one value over the 14IAL7 with 0x17aa3869 seen in this patch adding the quirk for that model https://www.spinics.net/lists/alsa-devel/msg146221.html

I don't have a good setup for doing kernel development, but if anyone else wants to continue, this is where i ended my research into it.

Is this still worth trying? I've got a setup working for building custom Debian kernels to patch my SSD issues kernel side, I can give this a try if it's worth it.

Okazakee commented 1 year ago

@stuarthayhurst You don't know how much I envy you for that patch working lmao

Myaats commented 1 year ago

It's worth noting that the 14IAL7 which is just the Intel version of the 14ARB7 already have a quirk for this including HDA verbs, I tried enabling it through kernel parameters without much luck. Since it shares the same chassis, codec and audio specs I would expect it to be the same. One guess is that the issue may have been the DSP w/ AMD Raphael not really being supported with kernel 6.0 which I tested with (Not sure if this could be related, i don't know the linux audio codec stack). Otherwise there could be differences in hardware, but I would find that weird. I checked the subsystem id of the ALC287 codec in the 14ARB7 which has 0x17aa3870 and it is just one value over the 14IAL7 with 0x17aa3869 seen in this patch adding the quirk for that model https://www.spinics.net/lists/alsa-devel/msg146221.html I don't have a good setup for doing kernel development, but if anyone else wants to continue, this is where i ended my research into it.

Is this still worth trying? I've got a setup working for building custom Debian kernels to patch my SSD issues kernel side, I can give this a try if it's worth it.

Did not work when I messed with it, and I don't think we can compare the devices directly as they have different drivers for the amp on Windows (14ARB7 compared to 14IAL7).

Personally I just ended up butchering the driver for the amp in the kernel to set the same registers as the Windows driver does and using ACPI instead of a DTB. I did not have patience to deal with Digital Audio Interface linking in the ALSA stack and just set it to always be enabled. If you want to mess with DAI linking it seems like the correct place to link it would be here.

In short a proper upstreamable fix would probably need these following things:

stuarthayhurst commented 1 year ago

I've never worked with the audio stack, and I've done very little with kernel development, but I know some of the basics at least? I'll see if I can get any of that working when I have some more time.

soupglasses commented 1 year ago

So i worked a bit on this on the side, applying the i2c commands and playing with @Myaats own patchset for the kernel.

Audio works correctly, it seems to act like windows with Dolby Atmos turned off. One thing that is interesting of note, is that the audio only comes up to about 30-35% of what Windows can, and gets completely beaten if Dolby Atmos gets turned on.

This had me a bit stumped until i read this post by Hector Martin, who is currently working on audio support for the Apple M1's. https://social.treehouse.systems/@marcan/109917995005981968

In short, Apple essentially overclocks their speaker system quite heavily with a software controlled gain.

There is currently work for Apple's audio driver to use a tool named speakersafetyd to do this trick on Linux as well. https://github.com/chadmed/speakersafetyd/ (NOTE: this tool is not applicable to us, so dont try to use it)

While i have not researched this extensively, it would line up with how impossible it has been trying to pass trough the audio chip with QEMU with the traditional patches, and the strange CORB messages that the audio driver constantly seems to give out. All slowly gaining upwards over time, like it is trying to turn something up is my guess now?

Maybe Dolby Atmos is not just an EQ?

@Myaats have you found anything that could indicate power or temperature of the speaker system?

Myaats commented 1 year ago

@Myaats have you found anything that could indicate power or temperature of the speaker system?

Only for the subwoofers, but that is all handled by the TAS2563 amp. The datasheet lists speaker thermal, over-excursion and various other protection features.

I don't think comparing to the new Macs makes much sense as Apple likes to move stuff from hardware to software. If I recall correctly even their flash storage is just flash chips without a dedicated storage controller in-between.

soupglasses commented 1 year ago

I've never worked with the audio stack, and I've done very little with kernel development, but I know some of the basics at least? I'll see if I can get any of that working when I have some more time.

The main issue is not so much how to apply this in the kernel, but rather how strangely the audio acts when put into a virtual machine or pass-trough state. To prove that we have set all the relevant registers we should have a full capture of the driver setting up the chip itself, but nobody that i know of has been able to do that yet.

We do have some steps like 0x48 0x2 to turn on the bass speakers which was found early on through a manual approach. Then we have @Myaats awesome efforts, who found a way to reboot the machine quickly enough to not have the audio chip reset itself after being first booted into linux. Where other options such as 0x48 0x30 0x99 was found to essentially "persist" the audio-configuration when plugging in/out the 3.5mm jack.

There is also the recent revelation above that the driver may be a lot more complex than the typical speaker drivers, using overclocking to achieve the loudness on Windows, which may need some rather advanced technical knowledge or manuals to figure out how to do.

Using i2cset -y 3 0x48 0x2 0 && i2cset -y 3 0x48 0x3 0 && i2cset -y 3 0x48 0x30 0x99 in a systemd module is probably what is the best way forwards for individuals today to have some decent, but safe volume on Linux.

For the up-streaming and further development, i am not sure. This has ended up being much more complex of a driver than i first expected. First step is honestly just figuring out a way to dump or follow the verbs being written, either linux with passthrough or something Windows side (which i do not think exists).

soyersoyer commented 1 year ago

Was PB_CFG1 (i2c 0x03) also 0x00 in windows? How do you dump the i2c in windows?

A firmware can be uploaded to the TAS2563. I think the windows driver just uploads a firmware based on the dolby profile. The "firmware" is a speaker tuning file (https://www.ti.com/lit/an/slaa765/slaa765.pdf). I think we can extract the speaker tuning file(s) from the windows driver and upload it and get the same characteristics.

Myaats commented 1 year ago

Was PB_CFG1 (i2c 0x03) also 0x00 in windows? How do you dump the i2c in windows?

I dumped the registers inside Linux after managing to hot-reboot, something that did not reset the amp. Then I diffed with the default registers I got after doing a full shutdown. PB_CFG1 was 0x20 in this dump which is the reset value per the datasheet.

A firmware can be uploaded to the TAS2563. I think the windows driver just uploads a firmware based on the dolby profile. The "firmware" is a speaker tuning file (https://www.ti.com/lit/an/slaa765/slaa765.pdf). I think we can extract the speaker tuning file(s) from the windows driver and upload it and get the same characteristics.

I already tried applying https://lkml.org/lkml/2020/6/9/802 and loading the firmware inside the Windows driver package, but changing to any of the DSP programs or configurations made no noticeable difference in audio for me. You can find a copy of the diff I used here.

soyersoyer commented 1 year ago

I also managed a hot-reboot (disable the i2c device in windows before restart). With the firmware in Linux it sounds like in windows without dolby.

It turned out there is some difference in the left-right amp registers. I've made a script to restore them.

i2cset -y 3 0x4c 0x08 0x5a # TDM_CFG2
i2cset -y 3 0x4d 0x08 0x6a

i2cset -y 3 0x4c 0x0a 0xf3 # TDM_CFG4
i2cset -y 3 0x4d 0x0a 0x93

i2cset -y 3 0x4c 0x0b 0x42 # TDM_CFG5
i2cset -y 3 0x4d 0x0b 0x46

i2cset -y 3 0x4c 0x0c 0x40 # TDM_CFG6
i2cset -y 3 0x4d 0x0c 0x44

i2cset -y 3 0x48 0x30 0x99 # INT & CLK CFG
i2cset -y 3 0x48 0x33 0xd4 # BOOST_CFG1
i2cset -y 3 0x48 0x35 0xa4 # BOOST_CFG3

i2cset -y 3 0x4c 0x36 0x0b # ?
i2cset -y 3 0x4d 0x36 0x0c

i2cset -y 3 0x48 0x38 0x21 # ?
i2cset -y 3 0x48 0x3c 0x58 # ?
i2cset -y 3 0x48 0x40 0xb6 # BST_ILIM_CFG0

i2cset -y 3 0x4c 0x46 0x04 # ASI2_CONFIG3
i2cset -y 3 0x4d 0x46 0x05

i2cset -y 3 0x4c 0x47 0xb1 # ?
i2cset -y 3 0x4d 0x47 0xb0

i2cset -y 3 0x48 0x02 0x00 # PWR_CTL

It doesn't load the firmware so please do not use it too loudly.

I checked that the amp power downs (software) automatically after the music stopped. (it sets the INT_LTCH3[7] (Interrupt due to DEVICE POWER DOWN) to 1)

The DAI link may not be necessary.

I'll try to load the firmware from userspace.

rodude123 commented 1 year ago

I also managed a hot-reboot (disable the i2c device in windows before restart). With the firmware in Linux it sounds like in windows without dolby.

It turned out there is some difference in the left-right amp registers. I've made a script to restore them.

i2cset -y 3 0x4c 0x08 0x5a # TDM_CFG2
i2cset -y 3 0x4d 0x08 0x6a

i2cset -y 3 0x4c 0x0a 0xf3 # TDM_CFG4
i2cset -y 3 0x4d 0x0a 0x93

i2cset -y 3 0x4c 0x0b 0x42 # TDM_CFG5
i2cset -y 3 0x4d 0x0b 0x46

i2cset -y 3 0x4c 0x0c 0x40 # TDM_CFG6
i2cset -y 3 0x4d 0x0c 0x44

i2cset -y 3 0x48 0x30 0x99 # INT & CLK CFG
i2cset -y 3 0x48 0x33 0xd4 # BOOST_CFG1
i2cset -y 3 0x48 0x35 0xa4 # BOOST_CFG3

i2cset -y 3 0x4c 0x36 0x0b # ?
i2cset -y 3 0x4d 0x36 0x0c

i2cset -y 3 0x48 0x38 0x21 # ?
i2cset -y 3 0x48 0x3c 0x58 # ?
i2cset -y 3 0x48 0x40 0xb6 # BST_ILIM_CFG0

i2cset -y 3 0x4c 0x46 0x04 # ASI2_CONFIG3
i2cset -y 3 0x4d 0x46 0x05

i2cset -y 3 0x4c 0x47 0xb1 # ?
i2cset -y 3 0x4d 0x47 0xb0

i2cset -y 3 0x48 0x02 0x00 # PWR_CTL

It doesn't load the firmware so please do not use it too loudly.

I checked that the amp power downs (software) automatically after the music stopped. (it sets the INT_LTCH3[7] (Interrupt due to DEVICE POWER DOWN) to 1)

The DAI link may not be necessary.

I'll try to load the firmware from userspace.

Thanks but it doesn't fix the issue when you switch to Surround Sound 4.0

dmxk06 commented 1 year ago

I also managed a hot-reboot (disable the i2c device in windows before restart). With the firmware in Linux it sounds like in windows without dolby.

It turned out there is some difference in the left-right amp registers. I've made a script to restore them.

i2cset -y 3 0x4c 0x08 0x5a # TDM_CFG2
i2cset -y 3 0x4d 0x08 0x6a

i2cset -y 3 0x4c 0x0a 0xf3 # TDM_CFG4
i2cset -y 3 0x4d 0x0a 0x93

i2cset -y 3 0x4c 0x0b 0x42 # TDM_CFG5
i2cset -y 3 0x4d 0x0b 0x46

i2cset -y 3 0x4c 0x0c 0x40 # TDM_CFG6
i2cset -y 3 0x4d 0x0c 0x44

i2cset -y 3 0x48 0x30 0x99 # INT & CLK CFG
i2cset -y 3 0x48 0x33 0xd4 # BOOST_CFG1
i2cset -y 3 0x48 0x35 0xa4 # BOOST_CFG3

i2cset -y 3 0x4c 0x36 0x0b # ?
i2cset -y 3 0x4d 0x36 0x0c

i2cset -y 3 0x48 0x38 0x21 # ?
i2cset -y 3 0x48 0x3c 0x58 # ?
i2cset -y 3 0x48 0x40 0xb6 # BST_ILIM_CFG0

i2cset -y 3 0x4c 0x46 0x04 # ASI2_CONFIG3
i2cset -y 3 0x4d 0x46 0x05

i2cset -y 3 0x4c 0x47 0xb1 # ?
i2cset -y 3 0x4d 0x47 0xb0

i2cset -y 3 0x48 0x02 0x00 # PWR_CTL

It doesn't load the firmware so please do not use it too loudly.

I checked that the amp power downs (software) automatically after the music stopped. (it sets the INT_LTCH3[7] (Interrupt due to DEVICE POWER DOWN) to 1)

The DAI link may not be necessary.

I'll try to load the firmware from userspace.

This works quite well, and doesn't seem to need the power management to be disabled to work either. Easyeffects doesn't seem to significantly improve the sound anymore though.

stuarthayhurst commented 1 year ago

The work to upstream the firmware loading patches seems to have stalled after the developer working on it left Texas Instruments, so we'd have to prompt them or do it, or try it ourselves :/

sjmikler commented 1 year ago

This command works well on Ubuntu, but on Manjaro Gnome I get an error: Error: Could not open file /dev/i2c-3 or /dev/i2c/3 : No such file or directory. This doesn't tell me anything, what can I do to fix this?

dmxk06 commented 1 year ago

This command works well on Ubuntu, but on Manjaro Gnome I get an error: Error: Could not open file /dev/i2c-3 or /dev/i2c/3 : No such file or directory. This doesn't tell me anything, what can I do to fix this?

You need to add i2c to your initramfs

Akinzekeel commented 1 year ago

I'm not sure if this is the correct way to do it, but I am also using Manjaro and had the same problem with i2c not working. I fixed it by adding i2c-dev to /etc/modules-load.d/modules.conf and rebooting.

deikatsuo commented 1 year ago

Hello guys, I am pleased to announce that after the audio fix, all speakers work correctly and I've also found a useful repo with few pulseaudio presets to use with EasyEffects. God bless pipewire.

Using the custom preset gets me a really good audio experience even under linux finally.

Here's what you have to do:

1. Install **Easyeffects** with the store (be sure to update to **ver 6.3.0**, i had some strange behaviour).

2. Install "**Advanced Auto Gain**" profile from this [repo](https://github.com/JackHack96/EasyEffects-Presets) using the command `bash -c "$(curl -fsSL https://raw.githubusercontent.com/JackHack96/PulseEffects-Presets/master/install.sh)"`.

3. Open EasyEffects and load auto gain profile.

Make sure to enable easyeffects and profiles on boot Hope this gets injected in the wiki :)

thanks

Akinzekeel commented 1 year ago

I upgraded to Kernel 6.4.0rc2-1 today and out of curiosity I decided to disable the i2c-workaround to see what happens. Even after rebooting, waking from standby, shutting down completely and booting again, the sound seems to be fine. In fact it seems the maximum volume is now quite a bit higher as well.

Can someone confirm this?

soupglasses commented 1 year ago

It could be related to the merged MIPI SoundWire support for AMD chipsets?

I will still need to try this out myself, but seems promising.

soupglasses commented 1 year ago

Just tested 6.4.0-rc4 and cannot get it to work. Bass speakers are turned off without any configuration.

EDIT: I might have forgotten to enable AMD Soundwire. :sweat_smile: I need to try again.

soupglasses commented 1 year ago

@Akinzekeel Can you tell us which flavor of kernel this is? Custom, Debian Sid, Fedora Rawhide, etc?

Akinzekeel commented 1 year ago

It's Manjaro. I updated the kernel through the Manjaro-settings kernel menu

soupglasses commented 1 year ago

Can you run aplay --list-devices and show the output of sudo lspci -v?

Akinzekeel commented 1 year ago
~ aplay --list-devices                                                            
**** Liste der Hardware-Geräte (PLAYBACK) ****
Karte 0: Generic [HD-Audio Generic], Gerät 3: HDMI 0 [HDMI 0]
  Sub-Geräte: 1/1
  Sub-Gerät #0: subdevice #0
Karte 0: Generic [HD-Audio Generic], Gerät 7: HDMI 1 [HDMI 1]
  Sub-Geräte: 1/1
  Sub-Gerät #0: subdevice #0
Karte 0: Generic [HD-Audio Generic], Gerät 8: HDMI 2 [HDMI 2]
  Sub-Geräte: 1/1
  Sub-Gerät #0: subdevice #0
Karte 1: Generic_1 [HD-Audio Generic], Gerät 0: ALC287 Analog [ALC287 Analog]
  Sub-Geräte: 0/1
  Sub-Gerät #0: subdevice #0

lspci output is quite long, so I attached it as txt file: lspci.txt

soupglasses commented 1 year ago

I cant see anything unique in there, can you try the following for me?

Akinzekeel commented 1 year ago

lsmod.output.txt snd_pci_acp6x.output.txt snd_hda_intel.output.txt

soupglasses commented 1 year ago

Yeah your device is not loading in snd_soc_tas2562 compared to mine. Have you set up anything like options snd_hda_intel before?

You can try a grep "snd_" /etc/modprobe.d/* but i dont know if it would be exhaustive.

Akinzekeel commented 1 year ago

I don't think I set up anything with snd_hda_intel before. /etc/modprobe.d/ only contains alsa-base.conf, and that file is empty.

Myaats commented 1 year ago

Yeah your device is not loading in snd_soc_tas2562 compared to mine. Have you set up anything like options snd_hda_intel before?

You can try a grep "snd_" /etc/modprobe.d/* but i dont know if it would be exhaustive.

snd_soc_tas2562 only works for you because you copied the patch I wrote to add ACPI support and just hard set the correct registers

soupglasses commented 1 year ago

I removed it from my configuration, so that patch is no longer present. I did however accidentally leave the module enabled, so it seems to have started loading the incorrect tas driver from linux itself. I will disable it and try again.

Akinzekeel commented 1 year ago

FWIW I have two 14ARB7's both running Manjaro (with kernel 6.4rc2-1 as of today) and sound seems to work fine on both of them so far without the i2c workaround. I can of course be mistaken, but I do feel like I would remember applying the ACPI patch on both devices.

soupglasses commented 1 year ago

I must say its most strange, as it does not work on my end. This will be very verbose, but my last idea would be a sudo modprobe -c output. Should list every configuration and option currently on the system. If i cant see a difference there, i must say I would be a bit stumped how to proceed further.