Skip to content

Instantly share code, notes, and snippets.

@benvsuw
Last active April 30, 2024 21:03
Show Gist options
  • Save benvsuw/c4431c7a1e122c2c408255e42b29f639 to your computer and use it in GitHub Desktop.
Save benvsuw/c4431c7a1e122c2c408255e42b29f639 to your computer and use it in GitHub Desktop.
Manjaro Custom Kernel for HP Envy 13 with ITHC and Sound Fixes

Custom Manjaro Kernel

I use this configuration to compile a kernel for my HP Envy x360 13-bf0xxx with touchscreen. Touchscreen and pen works, sound partly works.

Setup

Clone these repositories:

git clone https://github.com/quo/ithc-linux.git
git clone https://github.com/linux-surface/intel-precise-touch.git
git clone https://github.com/torvalds/linux

Add a symlink to connect the driver source code to linux:

cd linux/drivers/hid
ln -s ../../../ithc-linux/src/ ithc
ln -s ../../../intel-precise-touch/src ipts

Add intel iommu patch and ithc option to Kconfig:

cd linux/
git apply ../ithc-linux/intel-iommu.patch
git apply ../custom-kernel/ithc-kconfig.patch
git apply ../custom-kernel/ipts-kconfig.patch

You might need some build tools or dependencies. On Manjaro I needed to install cpio package.

Kernel Build Instructions

Regenerate config from current config and enable ITHC (Device Drivers -> HID Bus Support -> Intel Touch Host Controller):

cd linux/
zcat /proc/config.gz >> .config
make menuconfig

Update the version string and git commit any changes (Optional, appends -ck<MMYY>):

grep -e '^EXTRAVERSION.*-ck[0-9]*' Makefile || \
sed -i 's:^\(EXTRAVERSION = .*\):\1-ck'$(date +%m%y)':' Makefile
git add Makefile drivers/hid/Kconfig drivers/hid/Makefile drivers/iommu/intel/irq_remapping.c
git commit -m "Custom kernel $(date +%m%y)"

Optionally change CONFIG_LOCALVERSION in '.config' file.

Compile and install:

make -j$(nproc)
sudo make modules_install
sudo make install

Post Kernel Build Instructions

Move the image, recreate initramfs and refresh grub:

sudo su
VERSION="$(file -bL /boot/vmlinuz | grep -oe 'version [^+ ]*' | cut -f2 -d' ')"
mv /boot/vmlinuz /boot/vmlinuz-$VERSION-$(uname -m)

cat >/etc/mkinitcpio.d/linux-ck$(date +%m%y).preset <<EOF
# mkinitcpio preset file for the '$VERSION-$(uname -r)' package

#ALL_config="/etc/mkinitcpio.conf"
ALL_kver="/boot/vmlinuz-$VERSION-$(uname -m)"
ALL_microcode=(/boot/*-ucode.img)

PRESETS=('default' 'fallback')

#default_config="/etc/mkinitcpio.conf"
default_image="/boot/initramfs-$VERSION-$(uname -m).img"
#default_uki="/efi/EFI/Linux/manjaro-$VERSION-$(uname -m).efi"
#default_options="--splash /usr/share/systemd/bootctl/splash-manjaro.bmp"

#fallback_config="/etc/mkinitcpio.conf"
fallback_image="/boot/initramfs-$VERSION-$(uname -m)-fallback.img"
#fallback_uki="/efi/EFI/Linux/manjaro-$VERSION-$(uname -m)-fallback.efi"
fallback_options="-S autodetect"
EOF

mkinitcpio -p linux-ck$(date +%m%y)

grub-mkconfig -o /boot/grub/grub.cfg

For sound, ensure the following settings are NOT present in GRUB_CMDLINE_LINUX_DEFAULT or alsa-base.conf:

  • snd_hda_intel.dmic_detect=0
  • snd_intel_dspcfg.dsp_driver=1

Check with grep -rn GRUB_CMDLINE_LINUX_DEFAULT /etc/default/grub and cat /etc/modprobe.d/alsa-base.conf.

Further sound fixes available at Jerryxia32/envy_x360_fix.


ithc-kconfig.patch:

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index 4c682c6507..f36221e8cc 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -1351,4 +1351,6 @@ source "drivers/hid/amd-sfh-hid/Kconfig"
 
 source "drivers/hid/surface-hid/Kconfig"
 
+source "drivers/hid/ithc/Kconfig"
+
 endif # HID_SUPPORT
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index 082a728eac..16fa4608e4 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -170,3 +170,4 @@ obj-$(INTEL_ISH_FIRMWARE_DOWNLOADER)	+= intel-ish-hid/
 obj-$(CONFIG_AMD_SFH_HID)       += amd-sfh-hid/
 
 obj-$(CONFIG_SURFACE_HID_CORE)  += surface-hid/
+obj-$(CONFIG_HID_ITHC)		+= ithc/

ipts-kconfig.patch:

diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig
index f36221e8cc..9e6ac611cf 100644
--- a/drivers/hid/Kconfig
+++ b/drivers/hid/Kconfig
@@ -1353,4 +1353,6 @@ source "drivers/hid/surface-hid/Kconfig"
 
 source "drivers/hid/ithc/Kconfig"
 
+source "drivers/hid/ipts/Kconfig"
+
 endif # HID_SUPPORT
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile
index 16fa4608e4..7d5640aef5 100644
--- a/drivers/hid/Makefile
+++ b/drivers/hid/Makefile
@@ -171,3 +171,4 @@ obj-$(CONFIG_AMD_SFH_HID)       += amd-sfh-hid/
 
 obj-$(CONFIG_SURFACE_HID_CORE)  += surface-hid/
 obj-$(CONFIG_HID_ITHC)		+= ithc/
+obj-$(CONFIG_HID_IPTS)		+= ipts/
@ESHARK22
Copy link

Thanks a lot for this. Along with Jerryxia32/envy_x360_fix, it helped me getting touch and sound working on my HP envy x360 (13-bf0xxx - i5-1230U).

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