Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Lenovo Carbon X1 Gen 7 - Audio and microphone fix - https://wiki.archlinux.org/index.php/Lenovo_ThinkPad_X1_Carbon_(Gen_7) might be all you need.
#!/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"
@dubrovskyi
Copy link

dubrovskyi commented Jan 31, 2021

Can anyone help to get mic working, with X1 carbon 7th gen?

My mic also stopped working after updating the kernel. Moreover whole sound disappeared too. Finally I fixed sound. Internal mic still doesn’t work. I plug external one. Also still looking for solution

@tejaskumark
Copy link

tejaskumark commented Feb 1, 2021

@hamidzr File not able to download due to DNS not getting resolved. Is there any other alternative? https://github.hamidzare.xyz/dl/sof-hda-generic.tplg

@hamidzr
Copy link
Author

hamidzr commented Feb 1, 2021

@hamidzr File not able to download due to DNS not getting resolved. Is there any other alternative? https://github.hamidzare.xyz/dl/sof-hda-generic.tplg

I don't think you need it anymore with the newer kernels but here it is.
https://github.com/hamidzr/hamidzr.github.io/blob/master/dl/sof-hda-generic.tplg

@tejaskumark
Copy link

tejaskumark commented Feb 1, 2021

@hamidzr Thanks for quick reply. I am using Ubuntu Linux 5.4.0-64-generic #72~18.04.1-Ubuntu, I followed your script but sound still doesn't work. Any other pointer?

@dubrovskyi
Copy link

dubrovskyi commented Feb 1, 2021

@hamidzr Thanks for quick reply. I am using Ubuntu Linux 5.4.0-64-generic #72~18.04.1-Ubuntu, I followed your script but sound still doesn't work. Any other pointer?

Try follow arch wiki for Lenovo Thinkpad. There was a solution to fix the issue

@BramFr
Copy link

BramFr commented Feb 1, 2021

@tejaskumark
Copy link

tejaskumark commented Feb 1, 2021

@BramFr @igoodkit Thanks for reply. Currently my pulseaudio is 11.1 and sof-firmware(suggested by blog is 1.4.2-1). How can I update sof-frimware and pulseaudio to specific version on Ubuntu, is there any way?

@lgtegetege
Copy link

lgtegetege commented Feb 9, 2021

Lenovo Thinkpad

https://wiki.archlinux.org/index.php/Lenovo_ThinkPad_X1_Carbon_(Gen_7)#Audio

Hello, arch wiki says that since pulseaudio 14, all you need is sof-firmware, however i have a fresh arch install, with pulseaudio (14.2-2), sof firmware (1.6.1-1) and the kernel (5.10.14) on their latest versions and my bass is still underperforming, i dont know if this happens only in thinkpads carbon gen8 and not in gen7, or if everybody is experiencing the same issue no matter what version are using, i noticed this because im dualbooting with windows 10 and i can compare the audio performance.

@SippieCup
Copy link

SippieCup commented Feb 10, 2021

Lenovo Thinkpad

https://wiki.archlinux.org/index.php/Lenovo_ThinkPad_X1_Carbon_(Gen_7)#Audio

Hello, arch wiki says that since pulseaudio 14, all you need is sof-firmware, however i have a fresh arch install, with pulseaudio (14.2-2), sof firmware (1.6.1-1) and the kernel (5.10.14) on their latest versions and my bass is still underperforming, i dont know if this happens only in thinkpads carbon gen8 and not in gen7, or if everybody is experiencing the same issue no matter what version are using, i noticed this because im dualbooting with windows 10 and i can compare the audio performance.

I have the same issues, nothing seems to get it to work unfortunately. Hopefully someone smarter than me can chime in.

@jacksongoode
Copy link

jacksongoode commented Feb 10, 2021

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.

@martinseener
Copy link

martinseener commented Feb 10, 2021

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 :/

@SippieCup
Copy link

SippieCup commented Feb 17, 2021

@lgtegetege

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 and blacklist snd_soc_skl to /etc/modprobe.d/blacklist.conf
  • Add both load-module module-alsa-sink device=hw:0,0 channels=4 and load-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.

@huyhoang8398
Copy link

huyhoang8398 commented Feb 17, 2021

@lgtegetege

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 and blacklist snd_soc_skl to /etc/modprobe.d/blacklist.conf
  • Add both load-module module-alsa-sink device=hw:0,0 channels=4 and load-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

@lgtegetege
Copy link

lgtegetege commented Feb 18, 2021

@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

@SippieCup
Copy link

SippieCup commented Feb 19, 2021

i thought that too, but adding it made the microphone work. ymmv

@lgtegetege
Copy link

lgtegetege commented Feb 19, 2021

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

@gobenji
Copy link

gobenji commented Feb 19, 2021

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.

@lgtegetege
Copy link

lgtegetege commented Feb 20, 2021

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.

@gobenji
Copy link

gobenji commented Feb 20, 2021

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

@jacksongoode
Copy link

jacksongoode commented Feb 27, 2021

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.

@gorgiaxx
Copy link

gorgiaxx commented May 27, 2021

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

@corndog2000
Copy link

corndog2000 commented Nov 30, 2021

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

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.

@Pixel-Jack
Copy link

Pixel-Jack commented Aug 11, 2022

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 🙏

@hamidzr
Copy link
Author

hamidzr commented Aug 11, 2022

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.

@5HT2
Copy link

5HT2 commented Sep 8, 2022

  • Add both blacklist snd_hda_intel and blacklist snd_soc_skl to /etc/modprobe.d/blacklist.conf

  • Add both load-module module-alsa-sink device=hw:0,0 channels=4 and load-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!

@MartinRJDagleish
Copy link

MartinRJDagleish commented Sep 10, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment