-
-
Save hamidzr/dd81e429dc86f4327ded7a2030e7d7d9 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
# README You probablyl don't need this script anymore. Please read the comments below to catch up. | |
## Description | |
# Lenovo Carbon X1 Gen 7 - Audio and microphone fix - kernel 5.3+ required. | |
# The script has only been tested for Arch and OpenSuse, | |
# Original thread: https://forums.lenovo.com/t5/Ubuntu/Guide-X1-Carbon-7th-Generation-Ubuntu-compatability/td-p/4489823 | |
# Prereq: Install Linux 5.3 or newer | |
# NOTE: run this script as root and at your own risk. | |
firmware_version=v1.4.1 | |
echo Copy https://github.com/thesofproject/sof/releases/download/${firmware_version}/sof-cnl-${firmware_version}.ri to /lib/firmware/intel/sof/ as sof-cnl.ri | |
mkdir -p /lib/firmware/intel/sof/ | |
curl -L https://github.com/thesofproject/sof/releases/download/${firmware_version}/sof-cnl-${firmware_version}.ri -o /lib/firmware/intel/sof/sof-cnl.ri | |
echo Copy https://github.hamidza.re/dl/sof-hda-generic.tplg to /lib/firmware/intel/sof-tplg/ as sof-hda-generic-4ch.tplg | |
mkdir -p /lib/firmware/intel/sof-tplg/ | |
curl -L https://github.hamidza.re/dl/sof-hda-generic.tplg -o /lib/firmware/intel/sof-tplg/sof-hda-generic-4ch.tplg | |
ln -s /lib/firmware/intel/sof-tplg/sof-hda-generic-4ch.tplg /lib/firmware/intel/sof-tplg/sof-hda-generic.tplg | |
echo creating file /etc/modprobe.d/alsa-base.conf ------ | |
cat <<EOT >> /etc/modprobe.d/alsa-base.conf | |
# autoloader aliases | |
install sound-slot-0 /sbin/modprobe snd-card-0 | |
install sound-slot-1 /sbin/modprobe snd-card-1 | |
install sound-slot-2 /sbin/modprobe snd-card-2 | |
install sound-slot-3 /sbin/modprobe snd-card-3 | |
install sound-slot-4 /sbin/modprobe snd-card-4 | |
install sound-slot-5 /sbin/modprobe snd-card-5 | |
install sound-slot-6 /sbin/modprobe snd-card-6 | |
install sound-slot-7 /sbin/modprobe snd-card-7 | |
# Cause optional modules to be loaded above generic modules | |
install snd /sbin/modprobe --ignore-install snd $CMDLINE_OPTS && { /sbin/modprobe --quiet --use-blacklist snd-ioctl32 ; /sbin/modprobe --quiet --use-blacklist snd-seq ; } | |
# | |
# Workaround at bug #499695 (reverted in Ubuntu see LP #319505) | |
install snd-pcm /sbin/modprobe --ignore-install snd-pcm $CMDLINE_OPTS && { /sbin/modprobe --quiet --use-blacklist snd-pcm-oss ; : ; } | |
install snd-mixer /sbin/modprobe --ignore-install snd-mixer $CMDLINE_OPTS && { /sbin/modprobe --quiet --use-blacklist snd-mixer-oss ; : ; } | |
install snd-seq /sbin/modprobe --ignore-install snd-seq $CMDLINE_OPTS && { /sbin/modprobe --quiet --use-blacklist snd-seq-midi ; /sbin/modprobe --quiet --use-blacklist snd-seq-oss ; : ; } | |
# | |
install snd-rawmidi /sbin/modprobe --ignore-install snd-rawmidi $CMDLINE_OPTS && { /sbin/modprobe --quiet --use-blacklist snd-seq-midi ; : ; } | |
# Cause optional modules to be loaded above sound card driver modules | |
install snd-emu10k1 /sbin/modprobe --ignore-install snd-emu10k1 $CMDLINE_OPTS && { /sbin/modprobe --quiet --use-blacklist snd-emu10k1-synth ; } | |
install snd-via82xx /sbin/modprobe --ignore-install snd-via82xx $CMDLINE_OPTS && { /sbin/modprobe --quiet --use-blacklist snd-seq ; } | |
# Load saa7134-alsa instead of saa7134 (which gets dragged in by it anyway) | |
install saa7134 /sbin/modprobe --ignore-install saa7134 $CMDLINE_OPTS && { /sbin/modprobe --quiet --use-blacklist saa7134-alsa ; : ; } | |
# Prevent abnormal drivers from grabbing index 0 | |
options bt87x index=-2 | |
options cx88_alsa index=-2 | |
options saa7134-alsa index=-2 | |
options snd-atiixp-modem index=-2 | |
options snd-intel8x0m index=-2 | |
options snd-via82xx-modem index=-2 | |
options snd-usb-audio index=-2 | |
options snd-usb-caiaq index=-2 | |
options snd-usb-ua101 index=-2 | |
options snd-usb-us122l index=-2 | |
options snd-usb-usx2y index=-2 | |
# Ubuntu #62691, enable MPU for snd-cmipci | |
options snd-cmipci mpu_port=0x330 fm_port=0x388 | |
# Keep snd-pcsp from being loaded as first soundcard | |
options snd-pcsp index=-2 | |
# Keep snd-usb-audio from being loaded as first soundcard | |
options snd-usb-audio index=-2 | |
EOT | |
echo finished creating /etc/modprobe.d/alsa_base.conf ------ | |
echo creating file /etc/modprobe.d/blacklist.conf ------- | |
cat <<EOT >> /etc/modprobe.d/blacklist.conf | |
blacklist snd_hda_intel | |
blacklist snd_soc_skl | |
EOT | |
echo finished creating /etc/modprobe.d/blacklist.conf ------- | |
echo creating file /usr/share/alsa/ucm/sof-skl_hda_card/HiFi.conf ------- | |
mkdir -p /usr/share/alsa/ucm/sof-skl_hda_card | |
cat <<EOT >> /usr/share/alsa/ucm/sof-skl_hda_card/HiFi.conf | |
# Use case Configuration for skl-hda-card | |
SectionVerb { | |
EnableSequence [ | |
cdev "hw:sofsklhdacard" | |
cset "name='Master Playback Switch' on" | |
cset "name='Capture Switch' on" | |
] | |
DisableSequence [ | |
cdev "hw:sofsklhdacard" | |
] | |
} | |
SectionDevice."Headphone" { | |
Comment "Headphone" | |
EnableSequence [ | |
cdev "hw:sofsklhdacard" | |
cset "name='Headphone Playback Switch' on" | |
] | |
DisableSequence [ | |
cdev "hw:sofsklhdacard" | |
cset "name='Headphone Playback Switch' off" | |
] | |
Value { | |
PlaybackPCM "hw:sofsklhdacard,0" | |
PlaybackChannels "2" | |
JackName "sof-skl_hda_card Headphone" | |
JackType "gpio" | |
JackSwitch "12" | |
JackControl "Headphone Jack" | |
} | |
} | |
SectionDevice."Speaker" { | |
Comment "Speaker" | |
EnableSequence [ | |
cdev "hw:sofsklhdacard" | |
cset "name='Speaker Playback Switch' on" | |
] | |
DisableSequence [ | |
cset "name='Speaker Playback Switch' off" | |
] | |
Value { | |
PlaybackPCM "hw:sofsklhdacard,0" | |
JackHWMute "Headphone" | |
PlaybackChannels "2" | |
} | |
} | |
SectionDevice."Headset" { | |
Comment "Headset Mic" | |
ConflictingDevice [ | |
"DMIC Stereo" | |
] | |
EnableSequence [ | |
cdev "hw:sofsklhdacard" | |
] | |
DisableSequence [ | |
cdev "hw:sofsklhdacard" | |
] | |
Value { | |
CapturePCM "hw:0,0" | |
CaptureChannels "2" | |
JackControl "Mic Jack" | |
} | |
} | |
SectionDevice."Dmic" { | |
Comment "DMIC Stereo" | |
ConflictingDevice [ | |
"Headset Mic" | |
] | |
EnableSequence [ | |
cdev "hw:sofsklhdacard" | |
] | |
DisableSequence [ | |
cdev "hw:sofsklhdacard" | |
] | |
Value { | |
CapturePCM "hw:0,6" | |
CaptureChannels "2" | |
} | |
} | |
SectionDevice."HDMI1" { | |
Comment "HDMI1/DP1 Output" | |
EnableSequence [ | |
cdev "hw:sofsklhdacard" | |
cset "name='hif5-0 Jack Switch' on" | |
cset "name='Pin5-Port0 Mux' 1" | |
] | |
DisableSequence [ | |
cdev "hw:sofsklhdacard" | |
cset "name='Pin5-Port0 Mux' 0" | |
cset "name='hif5-0 Jack Switch' off" | |
] | |
Value { | |
PlaybackPCM "hw:0,3" | |
PlaybackChannels "2" | |
JackControl "HDMI/DP, pcm=11 Jack" | |
} | |
} | |
SectionDevice."HDMI2" { | |
Comment "HDMI2/DP2 Output" | |
EnableSequence [ | |
cdev "hw:sofsklhdacard" | |
cset "name='hif6-0 Jack Switch' on" | |
cset "name='Pin6-Port0 Mux' 2" | |
] | |
DisableSequence [ | |
cdev "hw:sofsklhdacard" | |
cset "name='Pin6-Port0 Mux' 0" | |
cset "name='hif6-0 Jack Switch' off" | |
] | |
Value { | |
PlaybackPCM "hw:0,4" | |
PlaybackChannels "2" | |
JackControl "HDMI/DP, pcm=12 Jack" | |
} | |
} | |
SectionDevice."HDMI3" { | |
Comment "HDMI3/DP3 Output" | |
EnableSequence [ | |
cdev "hw:sofsklhdacard" | |
cset "name='hif7-0 Jack Switch' on" | |
cset "name='Pin7-Port0 Mux' 3" | |
] | |
DisableSequence [ | |
cdev "hw:sofsklhdacard" | |
cset "name='Pin7-Port0 Mux' 0" | |
cset "name='hif7-0 Jack Switch' off" | |
] | |
Value { | |
PlaybackPCM "hw:0,5" | |
PlaybackChannels "2" | |
JackControl "HDMI/DP, pcm=13 Jack" | |
} | |
} | |
EOT | |
echo finished creating /usr/share/alsa/ucm/sof-skl_hda_card/HiFi.conf ------- | |
echo creating file /usr/share/alsa/ucm/sof-skl_hda_card/sof-skl_hda_card.conf ------ | |
cat <<EOT >> /usr/share/alsa/ucm/sof-skl_hda_card/sof-skl_hda_card.conf | |
SectionUseCase."HiFi" { | |
File "HiFi.conf" | |
Comment "Play HiFi quality Music" | |
} | |
EOT | |
echo finished creating /usr/share/alsa/ucm/sof-skl_hda_card/sof-skl_hda_card.conf ------- | |
echo "Reboot and run alsamixer. Use F6 to select the sound card and F4 to go to Capture, then turn all of the channels up to 100" | |
echo "If there is no sound card detected, ‘dmesg | grep sof’ can be used to see what went wrong" |
Hey,
for me this was resolved when the fix was coming with the usual package updates (kernel, linux-firmware, sof). Have you guys tried to update your X1s firmwares to the latest with fwupd
and tried a Live-CD for Linux Mint 20.1 or Ubuntu 20.04.2. Even with live-cd the sound should work like expected. Aso make sure, that no own workarounds are still in place. Try "apt-get install --reinstall linux-firmware alsa-base....` and so on to really have the repos packages in place. It's curious why it doesn't work. For my X1 7ths its now already fixed for some months :/
I managed to resolve everything. Good speaker audio, working microphone and microphone LED.
If you aren't starting fresh and tried a bunch of stuff, a couple things that were actually breaking it for me, here's how I got everything working:
- Remove the kernel boot parameter
snd_hda_intel.dmic_detect=0
if you have it set. - Remove the modprobe option
options snd_intel_dspcfg dsp_driver=1
if you have it set. - Add both
blacklist snd_hda_intel
andblacklist snd_soc_skl
to/etc/modprobe.d/blacklist.conf
- Add both
load-module module-alsa-sink device=hw:0,0 channels=4
andload-module module-alsa-source device=hw:0,7 channels=4
to the end of/etc/pulse/default.pa
Reboot, and your audio devices should be working. but your microphone LED will not be toggling correctly.
The Microphone LED follows the analog headphone input, if you don't have one connected, it'll be muted by default and the light will be on. Ensure your current capture device is in the same state (muted or unmuted) of the analog microphone by doing
amixer sset Capture toggle
or toggling it in aslamixer so they match.
Once they are in the same state, rebind the key XF86AudioMicMute
to mute both the current capture device as well as the headphone capture device. I use i3, so I accomplished this by adding the following line to my ~/.config/i3/config
file:
bindsym XF86AudioMicMute exec amixer sset Capture toggle && amixer -c0 sset Capture toggle
The active capture device is toggled with the first sset Capture, and the headphone mic is toggled with the -c0 sset Capture. Since the LED follows the headset microphone, the LED will toggle as well.
I managed to resolve everything. Good speaker audio, working microphone and microphone LED.
If you aren't starting fresh and tried a bunch of stuff, a couple things that were actually breaking it for me, here's how I got everything working:
- Remove the kernel boot parameter
snd_hda_intel.dmic_detect=0
if you have it set.- Remove the modprobe option
options snd_intel_dspcfg dsp_driver=1
if you have it set.- Add both
blacklist snd_hda_intel
andblacklist snd_soc_skl
to/etc/modprobe.d/blacklist.conf
- Add both
load-module module-alsa-sink device=hw:0,0 channels=4
andload-module module-alsa-source device=hw:0,7 channels=4
to the end of/etc/pulse/default.pa
Reboot, and your audio devices should be working. but your microphone LED will not be toggling correctly.
The Microphone LED follows the analog headphone input, if you don't have one connected, it'll be muted by default and the light will be on. Ensure your current capture device is in the same state (muted or unmuted) of the analog microphone by doing
amixer sset Capture toggle
or toggling it in aslamixer so they match.Once they are in the same state, rebind the key
XF86AudioMicMute
to mute both the current capture device as well as the headphone capture device. I use i3, so I accomplished this by adding the following line to my~/.config/i3/config
file:
bindsym XF86AudioMicMute exec amixer sset Capture toggle && amixer -c0 sset Capture toggle
The active capture device is toggled with the first sset Capture, and the headphone mic is toggled with the -c0 sset Capture. Since the LED follows the headset microphone, the LED will toggle as well.
Just saw your update on Archlinux talk, the LED microphone works perfect by using your solution
@SippieCup hello, im not sure if i did this correctly but no changes in audio quality after adding those lines to the pulse file, actually, the journal started to show the following output after adding the lines:
Failed to load module "module-alsa-sink" (argument: "device=hw:0,0 channels=4"): initialization failed
i also thought this wasnt necessary with pulseaudio14
i thought that too, but adding it made the microphone work. ymmv
My microphone worked even without adding the lines, the issue in my case is the underperformance of the bass sound and i couldnt solve it
When you switch between Windows and Linux, make sure that you power off/power on, not merely reboot. Some of the codec hardware state is not reset by a machine reset.
I just tested with a Ubuntu 20.04.2 live system (from a usb disk) that the bass level is as expected (good) on my machine. In that situation, the following command shows:
# hda-verb /dev/snd/hwC0D0 0x17 GET_CONNECT_SEL 0
nid = 0x17, verb = 0xf01, param = 0x0
value = 0x1
Please make the same test and report if you find the sound level to be good in the Ubuntu live system and what's the output of hda-verb. To run hda-verb on Ubuntu, you need to install the "alsa-tools" package from the "universe" component.
thanks @gobenji for your response
ok so i opened windows played some music and then shut down the computer completely, then i ran a live ubuntu system, i played the same exact song in the same exact software and ran the command you gave me, then i shut down the computer and booted into my daily system which is arch and then played the same song in the same software and then ran the command, i got the same sound and the same output in both linux systems
nid = 0x17, verb = 0xf01, param = 0x0 value = 0x1
but my bass is still underperforming, it does not sounds that bad, if i didnt have windows i maybe wouldn't notice, but having windows let me compare, it really sounds a little bit better there, the first distro i tried was ubuntu 20.04 in last year's september and the sound was really poor, there is a clear difference between that time and this, but its still missing a little bit to get the windows sound, this laptop have one of the best sound systems that available in this kind of device, its frustrating to be unable to solve this.
How about if you stop pulseaudio, adjust volume mixers to the maximum and run get_amp.sh, do you get the same values shown here:
$ ps -C pulseaudio
$ systemctl --user stop pulseaudio.socket
$ ps -C pulseaudio # check that there is no more pulseaudio process
$ amixer -c sofhdadsp cset name='Master Playback Volume' 100%
numid=12,iface=MIXER,name='Master Playback Volume'
; type=INTEGER,access=rw---R--,values=1,min=0,max=87,step=0
: values=87
| dBscale-min=-65.25dB,step=0.75dB,mute=0
# ./get_amp.sh 0x02
87, 87
# ./get_amp.sh 0x03
87, 87
If you play this normalized sample after doing the above, is the volume still unsatisfactory?
aplay -Dhw:0,0 one-two.wav
Does anyone know if the original files replaced by the new files in the script can be recovered? I'm actually not sure if they are completely new or if they overwrote something.
The hifi configurations of alsa-ucm-conf 1.2.4 is missing speaker parameters.
/usr/share/alsa/ucm2/sof-hda-dsp/HiFi.conf
Downgrade it to 1.2.3-2, it works fine for me.
sudo downgrade alsa-ucm-conf
The hifi configurations of alsa-ucm-conf 1.2.4 is missing speaker parameters.
/usr/share/alsa/ucm2/sof-hda-dsp/HiFi.confDowngrade it to 1.2.3-2, it works fine for me.
sudo downgrade alsa-ucm-conf
That got the speakers and microphone working on my thinkpad x1 carbon gen 7 using Manjaro with kernel 5.15
But, the microphone volume is extremely quiet and bumping the microphone level up to 150% still doesn't produce any audible sound from the microphone.
This script worked great on a fresh X1 Carbon Gen 10 with ubuntu 22.04 💯 I just had to install firmware-sof-signed
, Thank you 🙏
This script worked great on a fresh X1 Carbon Gen 10 with ubuntu 22.04 💯 I just had to install
firmware-sof-signed
, Thank you 🙏
I'm glad it's still working. although at this point I was hoping it's no longer needed... it's been a few years.
Add both
blacklist snd_hda_intel
andblacklist snd_soc_skl
to/etc/modprobe.d/blacklist.conf
Add both
load-module module-alsa-sink device=hw:0,0 channels=4
andload-module module-alsa-source device=hw:0,7 channels=4
to the end of/etc/pulse/default.pa
Reboot, and your audio devices should be working. but your microphone LED will not be toggling correctly.
The Microphone LED follows the analog headphone input, if you don't have one connected, it'll be muted by default and the light will be on. Ensure your current capture device is in the same state (muted or unmuted) of the analog microphone by doing
amixer sset Capture toggle
or toggling it in aslamixer so they match.Once they are in the same state, rebind the key
XF86AudioMicMute
to mute both the current capture device as well as the headphone capture device. I use i3, so I accomplished this by adding the following line to my~/.config/i3/config
file:
bindsym XF86AudioMicMute exec amixer sset Capture toggle && amixer -c0 sset Capture toggle
The active capture device is toggled with the first sset Capture, and the headphone mic is toggled with the -c0 sset Capture. Since the LED follows the headset microphone, the LED will toggle as well.
This worked for me!
Edit 2:
Just my chance I found the error. I am using an external monitor which is connected via Thunderbolt to my monitor which transfers power, the video and audio signal. For windows (and other Linux distros such as Manjaro) I can just leave my laptop closed and only use my external monitor, but Ubuntu ONLY seems to recognise the laptop speaker when I boot with the laptop "physically" open.
Edit:
I do not know what changed, but after a few restarts the problem came up again and I am at the start again. I tried the force reinstall, but still no good. Very weird behaviour.
Old
For anyone on an old ThinkPad:
I am working on a Lenovo ThinkPad X1 Yoga 4th Gen and installed the latest Ubuntu LTS (22.04 at time of writing). I tried the options above but what seemed to help was:
Have the blacktlist as mentioned above AND also forcefully reinstalling what martinseener mentioned above.
I think there are still some serious issues that I feel Lenovo ought to put out a push for the popping from the headphone jack. I left a comment on the forums. Hopefully, it will be resolved by them.