tomsom / yoga-linux

Run Linux on the Lenovo Yoga 7 14 (14ARB7) with AMD Ryzen 6800U (Rembrand).
https://github.com/tomsom/yoga-linux/wiki
56 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.

mdi22 commented 1 year ago

As I understand, the speakers and the microphone will be fixed in Kernel 6.1 See https://bugzilla.kernel.org/show_bug.cgi?id=216299

Okazakee commented 1 year ago

Holy moly, it was about time! Thx for the news, i can't wait to get rid of windows finaly. I guess the only main issue now remains EQing the heck outta them?

mdi22 commented 1 year ago

We will see... The problem with the current kernel is, that the output is sent to the two "tweeters". That's why it sounds awful and is unsusable. Probably the output over the "normal" speakers will be fine. In any case, for fine tuning in my experience "Pulseaudio effects" works well. It's even possible to import Atmos profiles for the speakers, if you find them :-) But on my last Yoga the default sound is already good and a bit of ordinary equalizing makes it even better.

Okazakee commented 1 year ago

I am not scared, my father is a sound technician, I guess I'll spend some minutes with him if there are no suitable profiles online.

mdi22 commented 1 year ago

Good! Feel free to share them here :-)

tomsom commented 1 year ago

Hello peeps! Thank you for commenting here even though i have not kept this repo active recently. I hope to have some more time to contribute to the project in the near future. I played around with EasyEffect a few weeks ago but with no luck(i also have absolutely no audio experience) but with only the two tin can tweeters working there is probably not much hope anyway. It would be super cool if you'd share tuned sound profiles once all the speakers are working :)

tomsom commented 1 year ago

Ok, so i've upgraded to 6.1-rc1; unfortunately only the 2 speakers work still(and keep on sucking) :( But at least the internal mic is now supported🎉

Okazakee commented 1 year ago

Do you know if the fix has been skipped or just does not work?

tomsom commented 1 year ago

I don't really know more than you; but reading the thread you linked previously it seems the speakers are a separate issue that has not really been addressed yet. :/ If I read it correctly the mic issue also appeared on the Slim 7 though no one really investigated the speakers which seem to be a yoga 7 14 specific problem. I also have not found any more info on that online.. at least for now

Okazakee commented 1 year ago

ok I guess we have to spread the word then, any good @ we could ask for this issue?

tomsom commented 1 year ago

Nope unfortunately not, I'm completely new to this..🤷

shiftyphil commented 1 year ago

There's a script for enabling the bass speakers here: https://bugzilla.kernel.org/show_bug.cgi?id=208555#c695

Haven't had a chance to do much testing myself.

mdi22 commented 1 year ago

There's a script for enabling the bass speakers here: https://bugzilla.kernel.org/show_bug.cgi?id=208555#c695

Haven't had a chance to do much testing myself.

Thanks for the info! I can confirm that the output switches from the tweeters to the "normal" speakers by running

i2cset -y 3 0x48 0x2 0

i2cset has to be installed (in ubuntu by the package management with the package i2c-tools)

Very likely the instructions in the bugzilla link on how to do that on every boot will work, too.

Still, the speakers don't have much bass. It is quite OK using PulseEffects, enabling the equalizer and using the preset "gstreamer_pop".

Okazakee commented 1 year ago

Switches? So not both working on the same time

mdi22 commented 1 year ago

Switches? So not both working on the same time

I think sound is just switched to the two main speakers, but I'm not sure.

I think, otherwise Linux needs to have a multi-speaker-configuration, which would be somehow possible, but is not achieved with the command.

As I understand, the laptop has 4 "ordinary" speakers for surround plus 1 subwoofer? Plus 2 tweeters?

It's my first time I hear about tweeters, so I don't know how they would have to be accessed... Maybe the "normal" audio stream can be forwarded to them or you need a special channel like the subwoofer...

I'm already happy when I can use two main speakers. To use them all fully with sorround, tweeters and subwoofer we need people with good knowledge of ALSA... Maybe it can be posted in an ALSA forum and someone can help to configure the card and add it configuration to the kernel... It's even possible that the card could be recognized as surround only with a BIOS update. But I don't know :-)

shiftyphil commented 1 year ago

According to the specs, it is "Stereo speakers, 2W x2 (woofers), 2W x2 (tweeters)," No separate subwoofer.

I think just enabling the woofers get everything going, the tweeters were already working.

PulseAudio Volume Control (pavucontrol) can switch between stereo, 2.1 and 4.0 modes. 2.1 sounds terrible as all the bass is sent to a sub that doesn't exist. I don't have good enough hearing or reference material to tell whether stereo or 4.0 is the right mode.

Okazakee commented 1 year ago

Unless speakers are hw set to be splitted with a crossover, they are 4.0. However I think the crossover would be the simplest way for them to make it work in all scenarios, limiting drivers to 2.0 output and manage frequency through the hw crossover. It would be stupid in my opinion to treat 2 dumbass tweeters as 2 full speaker drivers, but OEMs are OEMs...

gitgud187 commented 1 year ago

There's been a fix for the speakers for some time now: https://github.com/PJungkamp/yoga9-linux/issues/8#issuecomment-1265454056

tomsom commented 1 year ago

Awesome thx :) Just added a wiki page to apply the fix; also modified it to make it work with fedora

Though stereo only till now

Okazakee commented 1 year ago

Hope there will be a way to joint the 2 options soon :/

soupglasses commented 1 year ago

For a real fix, we will likely need to sniff out the HDA verbs from the Windows side to apply them on Linux, for example trough HDAJackRetask or a Kernel patch. I'll add some quick links that i found on the subject, as I may try to mess with this down the line.

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.

rodude123 commented 1 year ago

There's a script for enabling the bass speakers here: https://bugzilla.kernel.org/show_bug.cgi?id=208555#c695 Haven't had a chance to do much testing myself.

Thanks for the info! I can confirm that the output switches from the tweeters to the "normal" speakers by running

i2cset -y 3 0x48 0x2 0

i2cset has to be installed (in ubuntu by the package management with the package i2c-tools)

Very likely the instructions in the bugzilla link on how to do that on every boot will work, too.

Still, the speakers don't have much bass. It is quite OK using PulseEffects, enabling the equalizer and using the preset "gstreamer_pop".

I've tried the command i2cset -y 3 0x48 0x2 0 on arch but it doesn't work I get this error, any ideas? image Is there likely to be a fix in linux 6.1rc7, I'm trying the mainline kernel now to see if it will fix it

soupglasses commented 1 year ago

@Myaats Did you try to apply it manually?

Apparently you should be able to do add this to /etc/modprobe/snd.conf on a recent version of the kernel (i think 6.0=<)

options snd_intel_dspcfg dsp_driver=1
options snd_hda_intel model=alc287-yoga9-bass-spk-pin

Do know you take the risk of possibly harming your computer by setting these options.

Myaats commented 1 year ago

@Myaats Did you try to apply it manually?

Apparently you should be able to do add this to /etc/modprobe/snd.conf on a recent version of the kernel (i think 6.0=<)

options snd_intel_dspcfg dsp_driver=1
options snd_hda_intel model=alc287-yoga9-bass-spk-pin

Do know you take the risk of possibly harming your computer by setting these options.

Yes I already tried that, but nothing changed, I know about the risks but since the 14ARB7 is sharing the chassis and codec with the 14IAL7 I don't believe there is much risk, they even share the hardware maintenance manual.

But as I noted it could be because the AMD ACP (Audio Co-Processor) which acts as the DSP, did not get recognize as the correct model until this got merged for 6.1 https://lore.kernel.org/all/20221019083323.444904947@linuxfoundation.org/.

I've just not bothered to pull it down and test further as the i2c workaround works most of time, I do have had the i2c bus lock up at times requiring a cold reboot to fix it.

soupglasses commented 1 year ago

Now that is certainly interesting, thanks for the link to that. Curious to see where we go from this.

rodude123 commented 1 year ago

I've managed to get i2c to work but now all I see is Play HiFi quality Music as the profile, I've set load-module module-udev-detect use_ucm=0 inside /etc/pulseaudio/default.pa but still nothing happens. I've even set it inside /etc/pipewire/pipewire-pulse.conf.d/default.pa but nothing happens. I'm using pipewire. I don't know what I have done as it used to show all 4 speakers. I applied it manually but nothing shows the 4 speakers @imsofi

soupglasses commented 1 year ago

Yeah i do not plan to use i2cset for solving the current audio issues, as you will not be able to get the 4 speakers working together with it alone (from my understanding). Using it this way is basically a hack to "change" the audio chip to output to the two bass speakers in the system instead of the default tweeters.

I cant give much useful advice outside of that. As my laptop just got delayed to ship by another week, so i cant dig into it much further.

Okazakee commented 1 year ago

Yeah i do not plan to use i2c for solving the current audio issues, as you will not be able to get the 4 speakers working together with it alone (from my understanding). Using it this way is basically a hack to "change" the audio chip to output to the two bass speakers in the system instead of the default tweeters.

I cant give much useful advice outside of that. As my laptop just got delayed to ship by another week, so i cant dig into it much further.

Hello, is there a place where someone can contact you aside of this comment section? I would like to ask you some questions not only for speakers issue

soupglasses commented 1 year ago

This comment is likely something to follow closely^1, as there might be another person who is also attempting to dump the audio driver from windows. But there not been much activity for two months, at least not in that bugreport.

Another oddity to note, is that psref states that the 14ARB7 uses a Realtek ALC3306 codec^2, instead of ALC287 codec. Maybe compatible?

soupglasses commented 1 year ago

Hello, is there a place where someone can contact you aside of this comment section?

@Okazakee Yeah, I have an email address linked on my GitHub profile that you are free to email. :+1:

Myaats commented 1 year ago

Going to give a small update on my own research, I downloaded the Windows driver package for the 14ARB7 and the 14IAL7 to compare. While the machines definitely both use a generic Realtek audio codec driver, they contain different TI amp drivers. The 14ARB7 driver package has a driver specific for the TAS2563 with a firmware file. The 14IAL7 however uses some kind of generic TI smart amp driver without any model numbers recognizable either in the file names or the driver manifest. Due to this I don't think we can count on them having the same audio setup anymore.

The good news is that it is very easy to hack the existing TAS2562 amp driver (which also works with the TAS2563) to load with ACPI support instead of a device table, this solves the issue I have had with the userspace i2cset workaround as the adapter is not always at index 3 probably due to booting not necessarily being deterministic. Meanwhile with ACPI it uses the correct adapter always based on my testing.

One problem with this is that the ACPI table contains two I2cSerialBusV2 entries, one for each channel:

   Scope (_SB.I2CD)
    {
        Device (TAS)
        {
            Name (_HID, "INT8866")  // _HID: Hardware ID
            Name (_UID, Zero)  // _UID: Unique ID
            Method (_CRS, 0, NotSerialized)  // _CRS: Current Resource Settings
            {
                Name (RBUF, ResourceTemplate ()
                {
                    I2cSerialBusV2 (0x004C, ControllerInitiated, 0x00061A80,
                        AddressingMode7Bit, "\\_SB.I2CD",
                        0x00, ResourceConsumer, , Exclusive,
                        )
                    I2cSerialBusV2 (0x004D, ControllerInitiated, 0x00061A80,
                        AddressingMode7Bit, "\\_SB.I2CD",
                        0x00, ResourceConsumer, , Exclusive,
                        )
                    GpioInt (Edge, ActiveLow, SharedAndWake, PullNone, 0x0000,
                        "\\_SB.GPIO", 0x00, ResourceConsumer, ,
                        )
                        {   // Pin list
                            0x0020
                        }
                })
                Return (RBUF) /* \_SB_.I2CD.TAS_._CRS.RBUF */
            }

            Method (_STA, 0, NotSerialized)  // _STA: Status
            {
                Return (0x0F)
            }
        }
    }

Currently Linux will only i2c probe the first one, this is easily fixed by just overriding it to use 0x48 as the address on the i2c client with the i2c adapter when creating the i2c regmap and should be possible to add as a quirk.

Main issue holding my work back is the rest of the audio stack, after poking around it seems like the codec will need a DAI (digital audio interface) link to the Realtek codec for them to work together, see https://docs.kernel.org/sound/soc/codec-to-codec.html. Otherwise the sound system will just ignore the amp and the power settings will not be changed when audio is started/stopped being played over the speakers inside the TAS2562 codec driver. Hence no function related to the codec was called by the sound system during my testing.

Usually these kinds of combos with audio codec + audio amp/codec are done with ARM devices utilizing device tables instead of ACPI making configuring this easy. Luckily it seems like this is not the first device with a combo like this on a x86 platform making me think something like this may be needed: https://github.com/torvalds/linux/blob/master/sound/soc/intel/boards/sof_ssp_amp.c

There may be an easy solution to this but I have been unable to find one so far, it may make sense to try to involve someone more familiar with the Linux audio stack.

soupglasses commented 1 year ago

@Myaats one question i have is if there's a reason you don't sniff the verbs off the driver?^1 It seems like a simple way to get this working, but i think it may need each boot to be predictable.

Myaats commented 1 year ago

@Myaats one question i have is if there's a reason you don't sniff the verbs off the driver?1 It seems like a simple way to get this working, but i think it may need each boot to be predictable.

Footnotes

1. https://github.com/ryanprescott/realtek-verb-tools/wiki/How-to-sniff-verbs-from-a-Windows-sound-driver [leftwards_arrow_with_hook](#user-content-fnref-1-adb6300f8c60242128a137f0ab8fa0d7)

The Realtek codec is already configured correctly to get audio output, otherwise it would not be fixable just by setting some registers on the separate TI amp. I doubt the HDA verbs alone will solve anything since the amp has it's own driver on Windows. It may improve audio quality but I do not see how it would solve amp issue.

Edit: I guess there could be some communication/reset pin wireup as the TAS2563 amp seems to reset when you plug something into the headphone jack even without a driver.

soupglasses commented 1 year ago

Well the "fix" with the registers are essentially just setting it to use bottom firing speakers with 0x48 0x2?^1 Then from my understanding 0x48 0x3 is changing the gain of the amplifier to be lower.^2

I don't think this gets all four speakers working, but i may be wrong on that. As I have not been able to test this out.

Myaats commented 1 year ago

Well the "fix" with the registers are essentially just setting it to use bottom firing speakers with 0x48 0x2?1 Then from my understanding 0x48 0x3 is changing the gain of the amplifier to be lower.2

I don't think this gets all four speakers working, but i may be wrong on that. As I have not been able to test this out.

Footnotes

1. https://bugzilla.kernel.org/show_bug.cgi?id=208555#c689 [leftwards_arrow_with_hook](#user-content-fnref-1-7470efa60bc8791b27554ddba9ec2fcf)

2. https://bugzilla.kernel.org/show_bug.cgi?id=208555#c695 [leftwards_arrow_with_hook](#user-content-fnref-2-7470efa60bc8791b27554ddba9ec2fcf)

The datasheet is actually avaliable so we can see exactly what these registers are doing. If you look from page 63 you will see that 0x02 is the PWR_CTL register with a reset (default) value of 0xE. This corresponds to 1110 binary meaning current sense down, voltage sense down and mode is software shutdown, meaning no analog audio amplification. Setting this register to 0 enables these and sets the mode to active.

I am not sure why 0x03 (PB_CFG1) is being set to 0 by Gergo as there is no valid amp level for 0 in the AMP_LEVEL bitfield, 0x2 seems like a more correct value for the register if you want the safest value possible unless I missed something in the datasheet.

Myaats commented 1 year ago

Just wanted to mention I have finally found a way to stop the amp from resetting itself either during headset unplug, sleep or randomly. I rebooted from Windows after looking around and it seems like there is a certain chance that the amp will not reset itself before getting into Linux. This enabled me to dump all the values of the registers with values set by the Windows driver.

By manually setting values that differed after resetting the amp I was able to isolate the exact register to stop this behavior.

# Use at your own risk
i2cset -y (ADAPTER FOR AMP) 0x48 0x30 0x99

Some of the values bits are not documented by the datasheet but it is set by the Windows Driver

Here is the full diff with comments of the default registers compared to the ones after having used Windows. Note some of these are read only state registers. https://gist.github.com/Myaats/576ff6f8f7b307c4e21249276c22d8e1

maxbernyk commented 1 year ago

on acrhlinux (yoga 7 amd 6800u) i2cset returns error: Error: Could not open file/dev/i2c-3' or /dev/i2c/3': No such file or directory similar error for bus 1 and 2.

mcdax commented 1 year ago

@maxbernyk I have've the the problem. It seems that @rodude123 solved it somehow.

rodude123 commented 1 year ago

@maxbernyk I have've the the problem. It seems that @rodude123 solved it somehow.

what problem sorry?

mcdax commented 1 year ago

@maxbernyk I have've the the problem. It seems that @rodude123 solved it somehow.

what problem sorry?

image

Myaats commented 1 year ago

@maxbernyk I have've the the problem. It seems that @rodude123 solved it somehow.

what problem sorry?

image

Load the i2c-dev kernel module.

You will still risk it breaking. The i2c adapter id does not seem to be deterministic on my system, sometimes getting 6 as id instead of 3. The only reliable source I have found for it is the ACPI table.

rodude123 commented 1 year ago

@maxbernyk I have've the the problem. It seems that @rodude123 solved it somehow.

what problem sorry?

image

do you have i2cset installed? Also run as sudo

mcdax commented 1 year ago

Thank you! i2c-dev was installed for the kernel that wasn't active yet (6.1.1). After a reboot, I was able to enable it.

maxbernyk commented 1 year ago

do you have i2cset installed? Also run as sudo

I had i2cset installed, but i2c-dev wasn't loaded. I loaded it manually with modprobe i2c-dev and now it's kinda working. Thanks @Myaats and @rodude123 !

But now I'm stuck at the next step: i2cset -y 3 0x48 0x2 0 && i2cset -y 3 0x48 0x3 0 (with sudo) don't change anything with the sound. Maybe the sound device number is wrong? sudo i2cdetect -l returns:

i2c-0   i2c             Synopsys DesignWare I2C adapter         I2C adapter
i2c-1   i2c             Synopsys DesignWare I2C adapter         I2C adapter
i2c-2   i2c             Synopsys DesignWare I2C adapter         I2C adapter
i2c-3   i2c             Synopsys DesignWare I2C adapter         I2C adapter
i2c-4   smbus           SMBus PIIX4 adapter port 0 at 0b00      SMBus adapter
i2c-5   smbus           SMBus PIIX4 adapter port 2 at 0b00      SMBus adapter
i2c-6   smbus           SMBus PIIX4 adapter port 1 at 0b20      SMBus adapter
i2c-7   i2c             AMDGPU DM i2c hw bus 0                  I2C adapter
i2c-8   i2c             AMDGPU DM i2c hw bus 1                  I2C adapter
i2c-9   i2c             AMDGPU DM i2c hw bus 2                  I2C adapter
i2c-10  i2c             AMDGPU DM i2c hw bus 3                  I2C adapter
i2c-11  i2c             AMDGPU DM i2c hw bus 4                  I2C adapter
i2c-12  i2c             AMDGPU DM i2c hw bus 5                  I2C adapter
i2c-13  i2c             AMDGPU DM i2c hw bus 6                  I2C adapter
i2c-14  i2c             AMDGPU DM i2c hw bus 7                  I2C adapter
i2c-15  i2c             AMDGPU DM aux hw bus 0                  I2C adapter
i2c-16  i2c             AMDGPU DM aux hw bus 2                  I2C adapter
i2c-17  i2c             AMDGPU DM aux hw bus 3                  I2C adapter
i2c-18  i2c             AMDGPU DM aux hw bus 4                  I2C adapter
i2c-19  i2c             AMDGPU DM aux hw bus 5                  I2C adapter
i2c-20  i2c             AMDGPU DM aux hw bus 6                  I2C adapter
i2c-21  i2c             AMDGPU DM aux hw bus 7                  I2C adapter

PS Also, don't know what to make of this: sudo i2cdetect 3

Warning: Can't use SMBus Quick Write command, will skip some addresses
WARNING! This program can confuse your I2C bus, cause data loss and worse!
I will probe file /dev/i2c-3.
I will probe address range 0x08-0x77.
Continue? [Y/n] 
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                                                 
10:                                                 
20:                                                 
30: -- -- -- -- -- -- -- --                         
40:                                                 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60:                                                 
70:

PS After multiple restarts the solutioin is working!

rodude123 commented 1 year ago

I've again tried the hack with kernel 6.1.1 and it doesn't work any ideas? Can someone tell me if it works for them

rodude123 commented 1 year ago

The hack works with 6.1.2 and also the front speakers are also turned on so it's not just switched the rears on it's kept the front on too

rodude123 commented 1 year ago

With the hack, I can confirm that all the speakers work but it still doesn't sound as good as it does on windows I think. (Don't have windows installed on my system to confirm.) Although it's much better than before. I think it could be because the windows version has Dolby atmos optimizations built-in to the software/driver, which again is proprietary so not sure if that will come to the kernel.

rodude123 commented 1 year ago

After some fiddling around I found out that using Analog Stereo Duplex/Output resulted in the best sound even though I would have thought that using Analog surround output 4.0 would have resulted in the best sound. It could still be a driver issue but cannot confirm

lamarios 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.