Skip to content

Instantly share code, notes, and snippets.

@hamidzr
Last active June 2, 2023 01:43
Show Gist options
  • Save hamidzr/dd81e429dc86f4327ded7a2030e7d7d9 to your computer and use it in GitHub Desktop.
Save hamidzr/dd81e429dc86f4327ded7a2030e7d7d9 to your computer and use it in GitHub Desktop.
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"
@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