xoocoon / hp-15-ew0xxx-snd-fix

DKMS module for fixing the sound on Linux for HP models Envy x360 15-ew0xxx
GNU General Public License v3.0
32 stars 15 forks source link

FYI: Cirrus fix in Kernel 6.7.1 (confirmed, Realtek quirk patch still necessary) #31

Open readtedium opened 6 months ago

readtedium commented 6 months ago

Just pointing out that a patch for the sound issue is just about to hit in 6.7.1, covering each of the machines that this patch is supposed to repair. Once 6.7.1 hits in Fedora in a day or two, I will report back, in which case the Readme might need to be updated to mention this.

Patches here for evidence: https://elixir.bootlin.com/linux/v6.7.1/source/sound/pci/hda/cs35l41_hda_property.c

(FWIW I haven’t been able to use this on my Nobara install—seems like it doesn’t like Fedora offshoots.)

UPDATE: Looks like the issue is completely patched in linux-next-20240119, if you’re feeling adventurous (thx @poligarpi ): https://bbs.archlinux.org/viewtopic.php?id=287450

UPDATE 2: The full patch appears to be landing in 6.9; it’s in the current release candidate.

UPDATE 3: The full patch has been added to the mainline kernel starting with 6.9.

TheBlackmeister commented 6 months ago

please, keep us posted!

readtedium commented 6 months ago

Loaded the 6.7.1 firmware manually using Koji. Confirming that the Cirrus driver successfully loaded without this patch installed:

[   52.080397] nobara-pc kernel: Serial bus multi instantiate pseudo device driver CSC3551:00: Instantiated 2 I2C devices.
[   52.391431] nobara-pc kernel: cs35l41-hda i2c-CSC3551:00-cs35l41-hda.0: Adding DSD properties for 103C8A2D
[   52.393966] nobara-pc kernel: cs35l41-hda i2c-CSC3551:00-cs35l41-hda.0: Using extra _DSD properties, bypassing _DSD in ACPI
[   52.559370] nobara-pc kernel: cs35l41-hda i2c-CSC3551:00-cs35l41-hda.0: Cirrus Logic CS35L41 (35a40), Revision: B2
[   52.587927] nobara-pc kernel: cs35l41-hda i2c-CSC3551:00-cs35l41-hda.1: Adding DSD properties for 103C8A2D
[   52.590643] nobara-pc kernel: cs35l41-hda i2c-CSC3551:00-cs35l41-hda.1: Using extra _DSD properties, bypassing _DSD in ACPI
[   52.590655] nobara-pc kernel: cs35l41-hda i2c-CSC3551:00-cs35l41-hda.1: Reset line busy, assuming shared reset
[   52.701742] nobara-pc kernel: cs35l41-hda i2c-CSC3551:00-cs35l41-hda.1: Cirrus Logic CS35L41 (35a40), Revision: B2

No sound, however. So it appears the adding a quirk may still be necessary. Will keep experimenting.

readtedium commented 6 months ago

Confirming after patching it works with the quirk patch alone. So at this point it looks like we’re a few Realtek patches away from this totally being covered in the kernel.

TheBlackmeister commented 6 months ago

I've installed kernel 6.7.1 on Ubuntu 23.10. I have now this output: image

How did you install the realtek patch? Mine throws this error: image

readtedium commented 6 months ago

You’re on the right track with the first—that’s what you want to see.

Pasting in my setup_snd-hda-codec-realtek.sh file if it helps. Note the different line numbers on line 71 and different entries.

I also had to modify SOURCE_VERSION_STRING to 6.7.1 in kernel-module_patch.sh because my Linux build name was causing problems. (Note that I am using Nobara Linux which is based off of Fedora.)

#!/bin/bash

# see https://www.collabora.com/news-and-blog/blog/2021/05/05/quick-hack-patching-kernel-module-using-dkms/

# make the script stop on error
set -e

BIN_ABSPATH="$(dirname "$(readlink -f "${0}")")"

KERNEL_MODULE_NAME='snd-hda-codec-realtek'
DKMS_MODULE_VERSION='0.1'

declare -a QUIRKS=( 'ALC245_FIXUP_CS35L41_SPI_2' 'ALC287_FIXUP_CS35L41_I2C_2' )

IS_AUTO_PATCH=false
TARGET_QUIRK=

if [[ ! $EUID = 0 ]]; then
  echo "Only root can perform this setup. Aborting."
  exit 1
fi

# Evaluate cmd line arguments #####################################################################

POSITIONAL_ARGUMENTS=( )
while [[ $# -gt 0 ]] ; do
  argument="$1"
  case $argument in
    -a|--auto)
      IS_AUTO_PATCH=true
      shift
      ;;
    -q|--quirk)
      TARGET_QUIRK=$2
      shift 2
      ;;
    --)
      break
      ;;
    *)
      POSITIONAL_ARGUMENTS+=("$1")
      shift
      ;;
  esac
done
set -- "${POSITIONAL_ARGUMENTS[@]}"

if [ $IS_AUTO_PATCH = true ] && { [ -z $TARGET_QUIRK ] || [ ! $TARGET_QUIRK =~ ^$QUIRKS$ ]; }; then
  printf "%s\n$( for i in $( seq 1 ${#QUIRKS[@]} ); do echo -n '    %s\n'; done )%s\n" 'Please specify one of' ${QUIRKS[*]} "as Realtek quirk to apply to your machine (at your own risk), e.g. -q ${QUIRKS[0]}"
  exit 1
fi

# set up the actual DKMS module -------------------------------------------------------------------

"${BIN_ABSPATH}/dkms-module_create.sh" "${KERNEL_MODULE_NAME}" "${DKMS_MODULE_VERSION}"

if [ $IS_AUTO_PATCH = true ]; then
  # generate the patch based on the system running (added by samliddicott)
  if read PRODUCT < /sys/devices/virtual/dmi/id/product_name &&
      read ID < /sys/class/sound/hwC0D0/subsystem_id &&
      ID1=$(printf "0x%04x" $(( ID >> 16 & 0xffff ))) &&
      ID2=$(printf "0x%04x" $(( ID & 0xffff ))); then
    AUTO_PATCH_LINE="SND_PCI_QUIRK($ID1, $ID2, "'"'"$PRODUCT"'"'", $TARGET_QUIRK),"
  fi
fi

# create the patch file to apply to the source of the snd-hda-codec-realtek kernel module
tee "/usr/src/${KERNEL_MODULE_NAME}-${DKMS_MODULE_VERSION}/patch_realtek.patch" <<EOF
--- sound/pci/hda/patch_realtek.c.orig
+++ sound/pci/hda/patch_realtek.c
@@ -9896,6 +9896,13 @@
    SND_PCI_QUIRK(0x103c, 0x89c6, "Zbook Fury 17 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
    SND_PCI_QUIRK(0x103c, 0x89ca, "HP", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
    SND_PCI_QUIRK(0x103c, 0x89d3, "HP EliteBook 645 G9 (MB 89D2)", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
+    $AUTO_PATCH_LINE
+  SND_PCI_QUIRK(0x103c, 0x8a06, "HP Dragonfly Folio 13.5 inch G3 2-in-1 Notebook PC", ALC245_FIXUP_CS35L41_SPI_2),
+  SND_PCI_QUIRK(0x103c, 0x8a29, "HP Envy x360 15-ew0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2d, "HP Envy 16-h0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2e, "HP Envy Laptop 17t-cr0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8bdf, "HP Envy x360 2-in-1 Laptop 15-fe0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8be5, "HP ENVY Laptop 16-h1xxx", ALC287_FIXUP_CS35L41_I2C_2),
    SND_PCI_QUIRK(0x103c, 0x8a0f, "HP Pavilion 14-ec1xxx", ALC287_FIXUP_HP_GPIO_LED),
    SND_PCI_QUIRK(0x103c, 0x8a20, "HP Laptop 15s-fq5xxx", ALC236_FIXUP_HP_MUTE_LED_COEFBIT2),
    SND_PCI_QUIRK(0x103c, 0x8a25, "HP Victus 16-d1xxx (MB 8A25)", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
EOF

"${BIN_ABSPATH}/dkms-module_build.sh" "${KERNEL_MODULE_NAME}" "${DKMS_MODULE_VERSION}"
TheBlackmeister commented 6 months ago

Thank you. I have fixed some of the scripts to don't check the kernel version automatically and the fix works. To summarize what I did:

I modified SOURCE_VERSION_STRING in kernel-module-patch.sh as follows:

[ "${SOURCE_SUB_VERSION}" = '0' ] && unset SOURCE_SUB_VERSION
SOURCE_VERSION_STRING="6.7.1"

Then I modified kernel-version-get.sh:

#!/bin/bash

KERNEL_VERSION="6.7.1-060701-generic"

if [[ -z "${KERNEL_VERSION}" ]]; then
  echo "Determining the kernel version not (yet) supported for your Linux distro. You might want to modify the distro-specific commands. Aborting."
  exit 4
fi

# split kernel version into individual elements
SOURCE_MAJOR_VERSION="${KERNEL_VERSION%%.*}"
SOURCE_MINOR_VERSION="${KERNEL_VERSION#*.}"
SOURCE_MINOR_VERSION="${SOURCE_MINOR_VERSION%%.*}"
SOURCE_SUB_VERSION="${KERNEL_VERSION##*.}"
SOURCE_SUB_VERSION="${SOURCE_SUB_VERSION%%-*}"

if grep -q "^ID_LIKE=debian" /etc/os-release && [ -z "${SOURCE_SUB_VERSION}" ] && [ -e "/usr/src/linux-headers-${KERNEL_VERSION}/Makefile" ]; then
  makefile="/usr/src/linux-headers-${KERNEL_VERSION}/Makefile"
  if [[ "$(wc -l < $makefile)" -eq 1 ]] && grep -q "^include " $makefile ; then
    makefile=$(tr -s " " < $makefile | cut -d " " -f 2)
  fi

  SOURCE_SUB_VERSION=$(grep "SUBLEVEL =" $makefile | tr -d " " | cut -d "=" -f 2)
elif grep -q "^ID=arch" /etc/os-release; then
  SOURCE_SUB_VERSION=$(uname -r | cut -d '.' -f 3 | cut -d '-' -f 1)
elif grep -q "^ID=fedora" /etc/os-release; then
  makefile="/usr/src/kernels/${KERNEL_VERSION}/Makefile"
  SOURCE_SUB_VERSION=$(uname -r | cut -d '.' -f 3 | cut -d '-' -f 1)
fi

I removed the whole if statement regarding distro specific commands and added KERNEL_VERSION manually. If you are on Ubuntu (tested on Ubuntu 23.10), you have to manually set the KERNEL_VERSION to uname -r output. Run uname -r on your terminal and paste the output as KERNEL_VERSION variable.

After rebooting, the speakers are working. Dmesg output:

blackmeister@BlackHP:~$ sudo dmesg | grep cs35l41-hda
[sudo] password for blackmeister: 
[    3.791594] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.0: Adding DSD properties for 103C8A29
[    3.792579] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.0: Using extra _DSD properties, bypassing _DSD in ACPI
[    3.853763] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.0: Cirrus Logic CS35L41 (35a40), Revision: B2
[    3.854089] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.1: Adding DSD properties for 103C8A29
[    3.854645] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.1: Using extra _DSD properties, bypassing _DSD in ACPI
[    3.854648] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.1: Reset line busy, assuming shared reset
[    3.916961] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.1: Cirrus Logic CS35L41 (35a40), Revision: B2
[    6.485662] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.0: Falling back to default firmware.
[    6.486276] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.0: DSP1: Firmware version: 3
[    6.486279] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.0: DSP1: cirrus/cs35l41-dsp1-spk-prot.wmfw: Fri 24 Jun 2022 14:55:56 GMT Daylight Time
[    7.360879] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.0: DSP1: Firmware: 400a4 vendor: 0x2 v0.58.0, 2 algorithms
[    7.362910] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.0: DSP1: cirrus/cs35l41-dsp1-spk-prot.bin: v0.58.0
[    7.362914] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.0: DSP1: spk-prot: e:\workspace\workspace\tibranch_release_playback_6.76_2\ormis\staging\default_tunings\internal\CS35L53\Fixed_Attenuation_Mono_48000_29.78.0\full\Fixed_Attenuation_Mono_48000_29.78.0_full.bin
[    7.411342] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.0: CS35L41 Bound - SSID: 103C8A29, BST: 0, VSPK: 0, CH: L, FW EN: 1, SPKID: 1
[    7.411348] snd_hda_codec_realtek ehdaudio0D0: bound i2c-CSC3551:00-cs35l41-hda.0 (ops cs35l41_hda_comp_ops [snd_hda_scodec_cs35l41])
[    7.435454] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.1: Falling back to default firmware.
[    7.435605] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.1: DSP1: Firmware version: 3
[    7.435607] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.1: DSP1: cirrus/cs35l41-dsp1-spk-prot.wmfw: Fri 24 Jun 2022 14:55:56 GMT Daylight Time
[    8.293085] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.1: DSP1: Firmware: 400a4 vendor: 0x2 v0.58.0, 2 algorithms
[    8.295490] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.1: DSP1: cirrus/cs35l41-dsp1-spk-prot.bin: v0.58.0
[    8.295530] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.1: DSP1: spk-prot: e:\workspace\workspace\tibranch_release_playback_6.76_2\ormis\staging\default_tunings\internal\CS35L53\Fixed_Attenuation_Mono_48000_29.78.0\full\Fixed_Attenuation_Mono_48000_29.78.0_full.bin
[    8.350540] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.1: CS35L41 Bound - SSID: 103C8A29, BST: 0, VSPK: 0, CH: R, FW EN: 1, SPKID: 1
[    8.350564] snd_hda_codec_realtek ehdaudio0D0: bound i2c-CSC3551:00-cs35l41-hda.1 (ops cs35l41_hda_comp_ops [snd_hda_scodec_cs35l41])
readtedium commented 6 months ago

Great news! One small thing that probably needs to get patched in all this: It looks like there’s a version of the HP Envy 16-h0xxx, 0x8a2d, that is unaccounted for in the patch as it stands in the archive. (Guess which one I have.)

It seems like the logic of this script breaks down if you have an odd kernel version name or use an odd distro.

ilyasdc commented 5 months ago

Quirk only works on HP ENVY x360 2-in-1 Laptop 13-bf0xxx, sound is even louder ( from what I've seen in the patch, tincreased the value of the boost levels set by the ~inductance~ capacitance value). Hope it will resolve the problems with sound missing after waking from sleep.

readtedium commented 5 months ago

Just an update here. The quirks are likely to get into an upcoming version of the kernel very shortly—they were added at the end of last month, and notably, it appears that some of the fixes repair models with four amps:

https://lore.kernel.org/all/20240126164005.367021-1-sbinding@opensource.cirrus.com/

If anyone is feeling like adding this stuff on your own, it’s here.

RuuddR commented 5 months ago

I just tried this on Ubuntu 23.10 with kernel version 6.7.5 and laptop HP ENVY Laptop 16-h1xxx, but I can't get further than this. With command: sudo dmesg | grep cs35l41.hda

[    3.229025] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.0: Using extra _DSD properties, bypassing _DSD in ACPI
[    3.285629] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.0: Cirrus Logic CS35L41 (35a40), Revision: B2
[    3.285965] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.1: Adding DSD properties for 103C8BE5
[    3.286422] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.1: Using extra _DSD properties, bypassing _DSD in ACPI
[    3.286423] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.1: Reset line busy, assuming shared reset
[    3.348262] cs35l41-hda i2c-CSC3551:00-cs35l41-hda.1: Cirrus Logic CS35L41 (35a40), Revision: B2

The dkms status command prints the following:

snd-hda-codec-realtek/0.1, 6.7.5-060705-generic, x86_64: installed
snd-hda-scodec-cs35l41/0.1: added

I wouldn't need the snd-hda-scodec-cs35l41, right? Any idea where I might find something?

readtedium commented 5 months ago

@RuuddR The driver appears to be installed, but you shouldn’t need the snd-hda-scodec-cs35l41, as that’s already installed by the kernel. The setup_snd-hda-codec-realtek.sh script needs some small modifications to match the current file setup for the system, and you need to add your model to the list. Based on what the Cirrus employee added to the kernel, it should look like this:

SND_PCI_QUIRK(0x103c, 0x8be5, "HP Envy 16", ALC287_FIXUP_CS35L41_I2C_2),

If you can paste your setup_snd-hda-codec-realtek.sh that might help.

RuuddR commented 5 months ago

@readtedium Alright, that's what I also thought about the cs35l41. When I check the codecs in Jackretask it says Realtek ALC245, so based on that I modified my setup script to be this:

#!/bin/bash

# see https://www.collabora.com/news-and-blog/blog/2021/05/05/quick-hack-patching-kernel-module-using-dkms/

# make the script stop on error
set -e

BIN_ABSPATH="$(dirname "$(readlink -f "${0}")")"

KERNEL_MODULE_NAME='snd-hda-codec-realtek'
DKMS_MODULE_VERSION='0.1'

declare -a QUIRKS=( 'ALC245_FIXUP_CS35L41_SPI_2' 'ALC287_FIXUP_CS35L41_I2C_2' )

IS_AUTO_PATCH=false
TARGET_QUIRK=

if [[ ! $EUID = 0 ]]; then
  echo "Only root can perform this setup. Aborting."
  exit 1
fi

# Evaluate cmd line arguments #####################################################################

POSITIONAL_ARGUMENTS=( )
while [[ $# -gt 0 ]] ; do
  argument="$1"
  case $argument in
    -a|--auto)
      IS_AUTO_PATCH=true
      shift
      ;;
    -q|--quirk)
      TARGET_QUIRK=$2
      shift 2
      ;;
    --)
      break
      ;;
    *)
      POSITIONAL_ARGUMENTS+=("$1")
      shift
      ;;
  esac
done
set -- "${POSITIONAL_ARGUMENTS[@]}"

if [ $IS_AUTO_PATCH = true ] && { [ -z $TARGET_QUIRK ] || [ ! $TARGET_QUIRK =~ ^$QUIRKS$ ]; }; then
  printf "%s\n$( for i in $( seq 1 ${#QUIRKS[@]} ); do echo -n '    %s\n'; done )%s\n" 'Please specify one of' ${QUIRKS[*]} "as Realtek quirk to apply to your machine (at your own risk), e.g. -q ${QUIRKS[0]}"
  exit 1
fi

# set up the actual DKMS module -------------------------------------------------------------------

"${BIN_ABSPATH}/dkms-module_create.sh" "${KERNEL_MODULE_NAME}" "${DKMS_MODULE_VERSION}"

if [ $IS_AUTO_PATCH = true ]; then
  # generate the patch based on the system running (added by samliddicott)
  if read PRODUCT < /sys/devices/virtual/dmi/id/product_name &&
      read ID < /sys/class/sound/hwC0D0/subsystem_id &&
      ID1=$(printf "0x%04x" $(( ID >> 16 & 0xffff ))) &&
      ID2=$(printf "0x%04x" $(( ID & 0xffff ))); then
    AUTO_PATCH_LINE="SND_PCI_QUIRK($ID1, $ID2, "'"'"$PRODUCT"'"'", $TARGET_QUIRK),"
  fi
fi

# create the patch file to apply to the source of the snd-hda-codec-realtek kernel module
tee "/usr/src/${KERNEL_MODULE_NAME}-${DKMS_MODULE_VERSION}/patch_realtek.patch" <<EOF
--- sound/pci/hda/patch_realtek.c.orig
+++ sound/pci/hda/patch_realtek.c
@@ -9896,6 +9896,13 @@
  SND_PCI_QUIRK(0x103c, 0x89c6, "Zbook Fury 17 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
  SND_PCI_QUIRK(0x103c, 0x89ca, "HP", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
  SND_PCI_QUIRK(0x103c, 0x89d3, "HP EliteBook 645 G9 (MB 89D2)", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
+  SND_PCI_QUIRK(0x103c, 0x8a06, "HP Dragonfly Folio 13.5 inch G3 2-in-1 Notebook PC", ALC245_FIXUP_CS35L41_SPI_2),
+  SND_PCI_QUIRK(0x103c, 0x8a29, "HP Envy x360 15-ew0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2d, "HP Envy 16-h0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2e, "HP Envy Laptop 17t-cr0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8bdf, "HP Envy x360 2-in-1 Laptop 15-fe0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8be5, "HP ENVY Laptop 16-h1xxx", ALC245_FIXUP_CS35L41_SPI_2),
  SND_PCI_QUIRK(0x103c, 0x8a0f, "HP Pavilion 14-ec1xxx", ALC287_FIXUP_HP_GPIO_LED),
  SND_PCI_QUIRK(0x103c, 0x8a20, "HP Laptop 15s-fq5xxx", ALC236_FIXUP_HP_MUTE_LED_COEFBIT2),
  SND_PCI_QUIRK(0x103c, 0x8a25, "HP Victus 16-d1xxx (MB 8A25)", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
EOF

"${BIN_ABSPATH}/dkms-module_build.sh" "${KERNEL_MODULE_NAME}" "${DKMS_MODULE_VERSION}"
readtedium commented 5 months ago

The issue is with your patch. The patch_realtek.c line count needs to be exact and should match the kernel version. The current version of the file is here. It looks like you lost a line as well. For 6.7.5, that portion of the code should look like this:

# create the patch file to apply to the source of the snd-hda-codec-realtek kernel module
tee "/usr/src/${KERNEL_MODULE_NAME}-${DKMS_MODULE_VERSION}/patch_realtek.patch" <<EOF
--- sound/pci/hda/patch_realtek.c.orig
+++ sound/pci/hda/patch_realtek.c
@@ -9919,6 +9919,13 @@
  SND_PCI_QUIRK(0x103c, 0x89c6, "Zbook Fury 17 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
  SND_PCI_QUIRK(0x103c, 0x89ca, "HP", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
  SND_PCI_QUIRK(0x103c, 0x89d3, "HP EliteBook 645 G9 (MB 89D2)", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
+    $AUTO_PATCH_LINE
+  SND_PCI_QUIRK(0x103c, 0x8a06, "HP Dragonfly Folio 13.5 inch G3 2-in-1 Notebook PC", ALC245_FIXUP_CS35L41_SPI_2),
+  SND_PCI_QUIRK(0x103c, 0x8a29, "HP Envy x360 15-ew0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2d, "HP Envy 16-h0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2e, "HP Envy Laptop 17t-cr0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8bdf, "HP Envy x360 2-in-1 Laptop 15-fe0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8be5, "HP Envy 16-h1xxx", ALC287_FIXUP_CS35L41_I2C_2),
  SND_PCI_QUIRK(0x103c, 0x8a0f, "HP Pavilion 14-ec1xxx", ALC287_FIXUP_HP_GPIO_LED),
  SND_PCI_QUIRK(0x103c, 0x8a20, "HP Laptop 15s-fq5xxx", ALC236_FIXUP_HP_MUTE_LED_COEFBIT2),
  SND_PCI_QUIRK(0x103c, 0x8a25, "HP Victus 16-d1xxx (MB 8A25)", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
EOF

Finally, be sure to use this line for your system: SND_PCI_QUIRK(0x103c, 0x8be5, "HP Envy 16-h1xxx", ALC287_FIXUP_CS35L41_I2C_2),

Re-run the patch with that tweak and see how it goes.

RuuddR commented 5 months ago

Ah okay, I thought that I had to look here. Unfortunately there is no sound as of yet. Do I run it with the following command:

sudo chmod u+x setup_snd-hda-codec-realtek.sh
sudo ./setup_snd-hda-codec-realtek.sh

I really appreciate the time you take to help me, thank you!

readtedium commented 5 months ago

Strange. Keep it 9897 for now and see where it gets you. Nothing like inconsistency! :)

But yes, run that script. If you can, can you paste in the output it gives you when you run the command? It will tell you whether it went through.

RuuddR commented 5 months ago

Alright, so it says hunk failed. I guess that that is the issue?

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
build-essential is already the newest version (12.10ubuntu1).
dkms is already the newest version (3.0.11-1ubuntu10).
dwarves is already the newest version (1.25-0ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
--- sound/pci/hda/patch_realtek.c.orig
+++ sound/pci/hda/patch_realtek.c
@@ -9897,6 +9897,13 @@
  SND_PCI_QUIRK(0x103c, 0x89c6, "Zbook Fury 17 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
  SND_PCI_QUIRK(0x103c, 0x89ca, "HP", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
  SND_PCI_QUIRK(0x103c, 0x89d3, "HP EliteBook 645 G9 (MB 89D2)", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
+  
+  SND_PCI_QUIRK(0x103c, 0x8a06, "HP Dragonfly Folio 13.5 inch G3 2-in-1 Notebook PC", ALC245_FIXUP_CS35L41_SPI_2),
+  SND_PCI_QUIRK(0x103c, 0x8a29, "HP Envy x360 15-ew0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2d, "HP Envy 16-h0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2e, "HP Envy Laptop 17t-cr0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8bdf, "HP Envy x360 2-in-1 Laptop 15-fe0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8be5, "HP Envy 16-h1xxx", ALC287_FIXUP_CS35L41_I2C_2),
  SND_PCI_QUIRK(0x103c, 0x8a0f, "HP Pavilion 14-ec1xxx", ALC287_FIXUP_HP_GPIO_LED),
  SND_PCI_QUIRK(0x103c, 0x8a20, "HP Laptop 15s-fq5xxx", ALC236_FIXUP_HP_MUTE_LED_COEFBIT2),
  SND_PCI_QUIRK(0x103c, 0x8a25, "HP Victus 16-d1xxx (MB 8A25)", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
Building for kernel version 6.7.5-060705-generic
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start
Sign command: /usr/bin/kmodsign
Signing key: /var/lib/shim-signed/mok/MOK.priv
Public certificate (MOK): /var/lib/shim-signed/mok/MOK.der

Running the pre_build script:
Building for kernel version 6.7.5-060705-generic
Downloading source 6.7.5 for installed kernel 6.7.5-060705-generic
--2024-02-20 15:17:46--  https://mirrors.edge.kernel.org/pub/linux/kernel/v6.x/linux-6.7.5.tar.xz
Resolving mirrors.edge.kernel.org (mirrors.edge.kernel.org)... 2604:1380:4601:e00::3, 147.75.80.249
Connecting to mirrors.edge.kernel.org (mirrors.edge.kernel.org)|2604:1380:4601:e00::3|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 141436804 (135M) [application/x-xz]
Saving to: ‘linux-6.7.5.tar.xz’

linux-6.7.5.tar.xz                           100%[============================================================================================>] 134,88M  10,0MB/s    in 14s     

2024-02-20 15:17:59 (9,88 MB/s) - ‘linux-6.7.5.tar.xz’ saved [141436804/141436804]

Extracting original source of the kernel module
Applying patch_realtek.patch
patching file patch_realtek.c
Hunk #1 FAILED at 9897.
1 out of 1 hunk FAILED -- saving rejects to file patch_realtek.c.rej

Building module:
Cleaning build area...
make -j20 KERNELRELEASE=6.7.5-060705-generic -C /lib/modules/6.7.5-060705-generic/build M=/var/lib/dkms/snd-hda-codec-realtek/0.1/build....
Signing module /var/lib/dkms/snd-hda-codec-realtek/0.1/build/snd-hda-codec-realtek.ko
Cleaning build area...
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start
Module snd-hda-codec-realtek-0.1 for kernel 6.7.5-060705-generic (x86_64).
Before uninstall, this module version was ACTIVE on this kernel.

snd-hda-codec-realtek.ko.zst:
 - Uninstallation
   - Deleting from: /lib/modules/6.7.5-060705-generic/updates/dkms/
 - Original module
   - No original module was found for this module on this kernel.
   - Use the dkms install command to reinstall any previous module version.
depmod...

snd-hda-codec-realtek.ko.zst:
Running module version sanity check.
 - Original module
 - Installation
   - Installing to /lib/modules/6.7.5-060705-generic/updates/dkms/
depmod...
update-initramfs: Generating /boot/initrd.img-6.7.5-060705-generic

Please reboot your system and check whether snd-hda-codec-realtek has been loaded via the command
    dkms status
readtedium commented 5 months ago

Did this line get lost somewhere?

+ $AUTO_PATCH_LINE

RuuddR commented 5 months ago

That line is empty, maybe because of using the command without the parameters, I just retried it with the parameters and this is the output:

./setup_snd-hda-codec-realtek.sh: line 48: [: =~: binary operator expected
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
build-essential is already the newest version (12.10ubuntu1).
dkms is already the newest version (3.0.11-1ubuntu10).
dwarves is already the newest version (1.25-0ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.
--- sound/pci/hda/patch_realtek.c.orig
+++ sound/pci/hda/patch_realtek.c
@@ -9897,6 +9897,13 @@
  SND_PCI_QUIRK(0x103c, 0x89c6, "Zbook Fury 17 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
  SND_PCI_QUIRK(0x103c, 0x89ca, "HP", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
  SND_PCI_QUIRK(0x103c, 0x89d3, "HP EliteBook 645 G9 (MB 89D2)", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
+  SND_PCI_QUIRK(0x103c, 0x8be5, "HP ENVY Laptop 16-h1xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a06, "HP Dragonfly Folio 13.5 inch G3 2-in-1 Notebook PC", ALC245_FIXUP_CS35L41_SPI_2),
+  SND_PCI_QUIRK(0x103c, 0x8a29, "HP Envy x360 15-ew0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2d, "HP Envy 16-h0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2e, "HP Envy Laptop 17t-cr0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8bdf, "HP Envy x360 2-in-1 Laptop 15-fe0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8be5, "HP Envy 16-h1xxx", ALC287_FIXUP_CS35L41_I2C_2),
  SND_PCI_QUIRK(0x103c, 0x8a0f, "HP Pavilion 14-ec1xxx", ALC287_FIXUP_HP_GPIO_LED),
  SND_PCI_QUIRK(0x103c, 0x8a20, "HP Laptop 15s-fq5xxx", ALC236_FIXUP_HP_MUTE_LED_COEFBIT2),
  SND_PCI_QUIRK(0x103c, 0x8a25, "HP Victus 16-d1xxx (MB 8A25)", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
Building for kernel version 6.7.5-060705-generic
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start
Sign command: /usr/bin/kmodsign
Signing key: /var/lib/shim-signed/mok/MOK.priv
Public certificate (MOK): /var/lib/shim-signed/mok/MOK.der

Running the pre_build script:
Building for kernel version 6.7.5-060705-generic
Downloading source 6.7.5 for installed kernel 6.7.5-060705-generic
--2024-02-20 15:36:44--  https://mirrors.edge.kernel.org/pub/linux/kernel/v6.x/linux-6.7.5.tar.xz
Resolving mirrors.edge.kernel.org (mirrors.edge.kernel.org)... 2604:1380:4601:e00::3, 147.75.80.249
Connecting to mirrors.edge.kernel.org (mirrors.edge.kernel.org)|2604:1380:4601:e00::3|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 141436804 (135M) [application/x-xz]
Saving to: ‘linux-6.7.5.tar.xz’

linux-6.7.5.tar.xz                         100%[=====================================================================================>] 134,88M  10,2MB/s    in 14s     

2024-02-20 15:36:58 (9,65 MB/s) - ‘linux-6.7.5.tar.xz’ saved [141436804/141436804]

Extracting original source of the kernel module
Applying patch_realtek.patch
patching file patch_realtek.c
Hunk #1 FAILED at 9897.
1 out of 1 hunk FAILED -- saving rejects to file patch_realtek.c.rej

Building module:
Cleaning build area...
make -j20 KERNELRELEASE=6.7.5-060705-generic -C /lib/modules/6.7.5-060705-generic/build M=/var/lib/dkms/snd-hda-codec-realtek/0.1/build....
Signing module /var/lib/dkms/snd-hda-codec-realtek/0.1/build/snd-hda-codec-realtek.ko
Cleaning build area...
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start
Module snd-hda-codec-realtek-0.1 for kernel 6.7.5-060705-generic (x86_64).
Before uninstall, this module version was ACTIVE on this kernel.

snd-hda-codec-realtek.ko.zst:
 - Uninstallation
   - Deleting from: /lib/modules/6.7.5-060705-generic/updates/dkms/
 - Original module
   - No original module was found for this module on this kernel.
   - Use the dkms install command to reinstall any previous module version.
depmod...

snd-hda-codec-realtek.ko.zst:
Running module version sanity check.
 - Original module
 - Installation
   - Installing to /lib/modules/6.7.5-060705-generic/updates/dkms/
depmod...
update-initramfs: Generating /boot/initrd.img-6.7.5-060705-generic

Please reboot your system and check whether snd-hda-codec-realtek has been loaded via the command
    dkms status

I also tried this with line 9919 and same error.

readtedium commented 5 months ago

I double-checked the kernel, it’s 9897. Trying to determine the cause of the ELF error, may be slightly above my pay grade.

Looks like a similar issue emerged in #6, may want to look there for clues.

RuuddR commented 5 months ago

Thank you for checking it out and helping me! I will check that issue out and I might go through the make logs and see if there is something there as well.

poligarpi commented 5 months ago

According to this forum, this is completely fixed in linux-next-20240119 https://bbs.archlinux.org/viewtopic.php?id=287450

readtedium commented 5 months ago

@poligarpi oddly enough, I caught that earlier tonight. Don’t think I’m going to be hopping on a linux-next build myself, but definitely great news.

I will update the original post in the thread to account for that, though.

poligarpi commented 5 months ago

@poligarpi oddly enough, I caught that earlier tonight. Don’t think I’m going to be hopping on a linux-next build myself, but definitely great news.

I will update the original post in the thread to account for that, though.

My HP Envy x360 15-fh0xxx just arrived today, compiled linux-next and I can confirm that the fix is present, audio quality is great, a little low on volume tough

readtedium commented 5 months ago

For anyone dealing with quiet speakers, I recommend EasyEffects with this preset:

https://github.com/sebastian-de/easyeffects-thinkpad-unsuck

It seems like an EQ problem more than anything.

readtedium commented 5 months ago

I just tried linux-next on a secondary install and wow, that really helped the volume on my Envy, no additional software packages needed.

readtedium commented 4 months ago

Looks like the patch is landing in 6.9—it’s in 6.9-rc1 if you’d like to try it without being stuck with a next patch.

https://www.kernel.org

Osc100 commented 3 months ago

Indeed, I'm using a fresh installation of Fedora Silverblue Rawhide with kernel 6.9.0-0.rc2 and audio is working out of the box now!

My laptop model is: HP ENVY Laptop 16-h1xxx

I can use Silverblue now :smile:

ahmedeladl00 commented 2 months ago

have the same problem using kernel Linux 6.7.12-amd64 the first git commit was working with an old kernel could be there any solution ? image

readtedium commented 2 months ago

@ahmedeladl00 upgrade your kernel to a 6.9 release candidate if you can—it’s pretty stable at this point. That’s the easiest solution at this point, and basically works nearly seamlessly with no additional patching.

Otherwise, you need to patch your HP device into the quirks file using setup_snd-hda-codec-realtek.sh. You will need to modify the setup_snd-hda-codec-realtek.sh to match the patch_realtek.c for your kernel version.

ahmedeladl00 commented 2 months ago

firstly thanks for your fast reply secondly I already edited the file but the problem is still there

sudo ./setup_snd-hda-codec-realtek.sh
Detected kernel version 6.7.12-amd64.
Corresponding kernel source version is 6.7.12.
Detected kernel version 6.7.12-amd64.
Corresponding kernel source version is 6.7.12.
build-essential is already the newest version (12.10).
dkms is already the newest version (3.0.13-1).
dwarves is already the newest version (1.24-4.1).
Summary:
  Upgrading: 0, Installing: 0, Removing: 0, Not Upgrading: 0
--- sound/pci/hda/patch_realtek.c.orig
+++ sound/pci/hda/patch_realtek.c
@@ -9452,6 +9452,13 @@
    SND_PCI_QUIRK(0x103c, 0x89c6, "Zbook Fury 17 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
    SND_PCI_QUIRK(0x103c, 0x89ca, "HP", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
    SND_PCI_QUIRK(0x103c, 0x89d3, "HP EliteBook 645 G9 (MB 89D2)", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
+    
+  SND_PCI_QUIRK(0x103c, 0x8a06, "HP Dragonfly Folio 13.5 inch G3 2-in-1 Notebook PC", ALC245_FIXUP_CS35L41_SPI_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2a, "HP HP ENVY x360 2-in-1 Laptop 15-ew0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2c, "HP Envy 16-h0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2e, "HP Envy Laptop 17t-cr0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8bdf, "HP Envy x360 2-in-1 Laptop 15-fe0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8be5, "HP ENVY Laptop 16-h1xxx", ALC287_FIXUP_CS35L41_I2C_2),
    SND_PCI_QUIRK(0x103c, 0x8a78, "HP Dev One", ALC285_FIXUP_HP_LIMIT_INT_MIC_BOOST),
    SND_PCI_QUIRK(0x103c, 0x8aa0, "HP ProBook 440 G9 (MB 8A9E)", ALC236_FIXUP_HP_GPIO_LED),
    SND_PCI_QUIRK(0x103c, 0x8aa3, "HP ProBook 450 G9 (MB 8AA1)", ALC236_FIXUP_HP_GPIO_LED),
Detected kernel version 6.7.12-amd64.
Corresponding kernel source version is 6.7.12.
Detected kernel version: 6.7.12-amd64
Building and installing DKMS module for 6.7.12-amd64...
Sign command: /lib/modules/6.7.12-amd64/build/scripts/sign-file
Signing key: /var/lib/dkms/mok.key
Public certificate (MOK): /var/lib/dkms/mok.pub

Running the pre_build script:
Detected kernel version 6.7.12-amd64.
Corresponding kernel source version is 6.7.12.
Building for kernel version 6.7.12-amd64
Downloading source 6.7.12 for installed kernel 6.7.12-amd64
--2024-05-07 01:01:11--  https://mirrors.edge.kernel.org/pub/linux/kernel/v6.x/linux-6.7.12.tar.xz
Resolving mirrors.edge.kernel.org (mirrors.edge.kernel.org)... 2604:1380:4601:e00::3, 147.75.80.249
Connecting to mirrors.edge.kernel.org (mirrors.edge.kernel.org)|2604:1380:4601:e00::3|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 141495752 (135M) [application/x-xz]
Saving to: ‘linux-6.7.12.tar.xz’

linux-6.7.12.tar.xz                                         100%[=========================================================================================================================================>] 134.94M  10.6MB/s    in 20s     

2024-05-07 01:01:32 (6.67 MB/s) - ‘linux-6.7.12.tar.xz’ saved [141495752/141495752]

Extracting original source of the kernel module
Applying patch_realtek.patch
patching file patch_realtek.c
Hunk #1 FAILED at 9452.
1 out of 1 hunk FAILED -- saving rejects to file patch_realtek.c.rej

Building module:
Cleaning build area...
Building module(s)....
Signing module /var/lib/dkms/snd-hda-codec-realtek/0.1/build/snd-hda-codec-realtek.ko
Cleaning build area...
Module snd-hda-codec-realtek-0.1 for kernel 6.7.12-amd64 (x86_64).
Before uninstall, this module version was ACTIVE on this kernel.

snd-hda-codec-realtek.ko.xz:
 - Uninstallation
   - Deleting from: /lib/modules/6.7.12-amd64/updates/dkms/
 - Original module
   - No original module was found for this module on this kernel.
   - Use the dkms install command to reinstall any previous module version.
depmod....

snd-hda-codec-realtek.ko.xz:
Running module version sanity check.
 - Original module
 - Installation
   - Installing to /lib/modules/6.7.12-amd64/updates/dkms/
depmod....
DKMS module installation completed.
Updating initramfs for Debian or derivatives...
update-initramfs: Generating /boot/initrd.img-6.7.12-amd64
W: Possible missing firmware /lib/firmware/i915/mtl_gsc_1.bin for module i915

Please reboot your system and check whether snd-hda-codec-realtek has been loaded via the command 'dkms status'.

as you can see FAILED at 9452.

i tried yesterday to update the kernel to 6.9 but happend some problems with me so i rolled back.

readtedium commented 2 months ago

@ahmedeladl00 You have to change the line number to match where the patch is going to be entered. Based on the version you told me, you should change the line reference from @@ -9452,6 +9452,13 @@ to @@ -9996,6 +9996,13 @@ .

If it for some reason does not work, tweak that part of the file.

ahmedeladl00 commented 2 months ago

Edited it now to be @@ -9996,6 +9996,13 @@ and got

Extracting original source of the kernel module
Applying patch_realtek.patch
patching file patch_realtek.c
Hunk #1 FAILED at 9996.
1 out of 1 hunk FAILED -- saving rejects to file patch_realtek.c.rej

I appreciate your time

readtedium commented 2 months ago

Looking again, it appears that the entries changed in that section directly below where we’re trying to patch, and you need to update to account for that. Please change to:

  SND_PCI_QUIRK(0x103c, 0x89c6, "Zbook Fury 17 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
  SND_PCI_QUIRK(0x103c, 0x89ca, "HP", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
  SND_PCI_QUIRK(0x103c, 0x89d3, "HP EliteBook 645 G9 (MB 89D2)", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
+    $AUTO_PATCH_LINE
+  SND_PCI_QUIRK(0x103c, 0x8a06, "HP Dragonfly Folio 13.5 inch G3 2-in-1 Notebook PC", ALC245_FIXUP_CS35L41_SPI_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2a, "HP HP ENVY x360 2-in-1 Laptop 15-ew0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2c, "HP Envy 16-h0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2e, "HP Envy Laptop 17t-cr0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8bdf, "HP Envy x360 2-in-1 Laptop 15-fe0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8be5, "HP ENVY Laptop 16-h1xxx", ALC287_FIXUP_CS35L41_I2C_2),
  SND_PCI_QUIRK(0x103c, 0x8a0f, "HP Pavilion 14-ec1xxx", ALC287_FIXUP_HP_GPIO_LED),
  SND_PCI_QUIRK(0x103c, 0x8a20, "HP Laptop 15s-fq5xxx", ALC236_FIXUP_HP_MUTE_LED_COEFBIT2),
  SND_PCI_QUIRK(0x103c, 0x8a25, "HP Victus 16-d1xxx (MB 8A25)", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
ahmedeladl00 commented 2 months ago

Extracting original source of the kernel module
Applying patch_realtek.patch
patch: **** Only garbage was found in the patch input.

and after a reboot there is no change !

readtedium commented 2 months ago

Extracting original source of the kernel module
Applying patch_realtek.patch
patch: **** Only garbage was found in the patch input.

and after a reboot there is no change !

Please share your full file, thanks.

ahmedeladl00 commented 2 months ago
#!/bin/bash

# see https://www.collabora.com/news-and-blog/blog/2021/05/05/quick-hack-patching-kernel-module-using-dkms/

# make the script stop on error
set -e

BIN_ABSPATH="$(dirname "$(readlink -f "${0}")")"

KERNEL_MODULE_NAME='snd-hda-codec-realtek'
DKMS_MODULE_VERSION='0.1'

declare -a QUIRKS=( 'ALC245_FIXUP_CS35L41_SPI_2' 'ALC287_FIXUP_CS35L41_I2C_2' )

IS_AUTO_PATCH=false
TARGET_QUIRK=

. kernel-version_get.sh

if [ ! $SOURCE_MAJOR_VERSION = 6 ]; then
  echo "Patch ${KERNEL_MODULE_NAME} only applicable to kernel versions 6.x"
  exit 1
fi

if [[ ! $EUID = 0 ]]; then
  echo "Only root can perform this setup. Aborting."
  exit 1
fi

# Evaluate cmd line arguments #####################################################################

POSITIONAL_ARGUMENTS=( )
while [[ $# -gt 0 ]] ; do
  argument="$1"
  case $argument in
    -a|--auto)
      IS_AUTO_PATCH=true
      shift
      ;;
    -q|--quirk)
      TARGET_QUIRK=$2
      shift 2
      ;;
    --)
      break
      ;;
    *)
      POSITIONAL_ARGUMENTS+=("$1")
      shift
      ;;
  esac
done
set -- "${POSITIONAL_ARGUMENTS[@]}"

if [[ $IS_AUTO_PATCH == true && ( -z $TARGET_QUIRK || ! $TARGET_QUIRK =~ ${QUIRKS[*]} ) ]]; then
  printf "%s\n$( for i in $( seq 1 ${#QUIRKS[@]} ); do echo -n '    %s\n'; done )%s\n" 'Please specify one of' ${QUIRKS[*]} "as Realtek quirk to apply to your machine (at your own risk), e.g. -q ${QUIRKS[0]}"
  exit 1
fi

# set up the actual DKMS module -------------------------------------------------------------------

"${BIN_ABSPATH}/dkms-module_create.sh" "${KERNEL_MODULE_NAME}" "${DKMS_MODULE_VERSION}"

if [ $IS_AUTO_PATCH = true ]; then
  # generate the patch based on the system running (added by samliddicott)
  if read PRODUCT < /sys/devices/virtual/dmi/id/product_name &&
      read ID < /sys/class/sound/hwC0D0/subsystem_id &&
      ID1=$(printf "0x%04x" $(( ID >> 16 & 0xffff ))) &&
      ID2=$(printf "0x%04x" $(( ID & 0xffff ))); then
    AUTO_PATCH_LINE="SND_PCI_QUIRK($ID1, $ID2, "'"'"$PRODUCT"'"'", $TARGET_QUIRK),"
  fi
fi

# create the patch file to apply to the source of the snd-hda-codec-realtek kernel module
if [ $SOURCE_MINOR_VERSION = 8 ]; then
  tee "/usr/src/${KERNEL_MODULE_NAME}-${DKMS_MODULE_VERSION}/patch_realtek.patch" <<EOF
--- sound/pci/hda/patch_realtek.c.orig
+++ sound/pci/hda/patch_realtek.c
  SND_PCI_QUIRK(0x103c, 0x89c6, "Zbook Fury 17 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
  SND_PCI_QUIRK(0x103c, 0x89ca, "HP", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
  SND_PCI_QUIRK(0x103c, 0x89d3, "HP EliteBook 645 G9 (MB 89D2)", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
+    $AUTO_PATCH_LINE
+  SND_PCI_QUIRK(0x103c, 0x8a06, "HP Dragonfly Folio 13.5 inch G3 2-in-1 Notebook PC", ALC245_FIXUP_CS35L41_SPI_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2a, "HP HP ENVY x360 2-in-1 Laptop 15-ew0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2c, "HP Envy 16-h0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2e, "HP Envy Laptop 17t-cr0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8bdf, "HP Envy x360 2-in-1 Laptop 15-fe0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8be5, "HP ENVY Laptop 16-h1xxx", ALC287_FIXUP_CS35L41_I2C_2),
  SND_PCI_QUIRK(0x103c, 0x8a0f, "HP Pavilion 14-ec1xxx", ALC287_FIXUP_HP_GPIO_LED),
  SND_PCI_QUIRK(0x103c, 0x8a20, "HP Laptop 15s-fq5xxx", ALC236_FIXUP_HP_MUTE_LED_COEFBIT2),
  SND_PCI_QUIRK(0x103c, 0x8a25, "HP Victus 16-d1xxx (MB 8A25)", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
EOF
else
  tee "/usr/src/${KERNEL_MODULE_NAME}-${DKMS_MODULE_VERSION}/patch_realtek.patch" <<EOF
--- sound/pci/hda/patch_realtek.c.orig
+++ sound/pci/hda/patch_realtek.c
  SND_PCI_QUIRK(0x103c, 0x89c6, "Zbook Fury 17 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
  SND_PCI_QUIRK(0x103c, 0x89ca, "HP", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
  SND_PCI_QUIRK(0x103c, 0x89d3, "HP EliteBook 645 G9 (MB 89D2)", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
+    $AUTO_PATCH_LINE
+  SND_PCI_QUIRK(0x103c, 0x8a06, "HP Dragonfly Folio 13.5 inch G3 2-in-1 Notebook PC", ALC245_FIXUP_CS35L41_SPI_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2a, "HP HP ENVY x360 2-in-1 Laptop 15-ew0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2c, "HP Envy 16-h0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2e, "HP Envy Laptop 17t-cr0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8bdf, "HP Envy x360 2-in-1 Laptop 15-fe0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8be5, "HP ENVY Laptop 16-h1xxx", ALC287_FIXUP_CS35L41_I2C_2),
  SND_PCI_QUIRK(0x103c, 0x8a0f, "HP Pavilion 14-ec1xxx", ALC287_FIXUP_HP_GPIO_LED),
  SND_PCI_QUIRK(0x103c, 0x8a20, "HP Laptop 15s-fq5xxx", ALC236_FIXUP_HP_MUTE_LED_COEFBIT2),
  SND_PCI_QUIRK(0x103c, 0x8a25, "HP Victus 16-d1xxx (MB 8A25)", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
EOF
fi

"${BIN_ABSPATH}/dkms-module_build.sh" "${KERNEL_MODULE_NAME}" "${DKMS_MODULE_VERSION}"
readtedium commented 2 months ago

You deleted the @@ -9996,6 +9996,13 @@ line, which is necessary for the patch to work. The patch sections should each look like this:

--- sound/pci/hda/patch_realtek.c.orig
+++ sound/pci/hda/patch_realtek.c
@@ -9996,6 +9996,13 @@
  SND_PCI_QUIRK(0x103c, 0x89c6, "Zbook Fury 17 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
  SND_PCI_QUIRK(0x103c, 0x89ca, "HP", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
  SND_PCI_QUIRK(0x103c, 0x89d3, "HP EliteBook 645 G9 (MB 89D2)", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
+    $AUTO_PATCH_LINE
+  SND_PCI_QUIRK(0x103c, 0x8a06, "HP Dragonfly Folio 13.5 inch G3 2-in-1 Notebook PC", ALC245_FIXUP_CS35L41_SPI_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2a, "HP HP ENVY x360 2-in-1 Laptop 15-ew0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2c, "HP Envy 16-h0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2e, "HP Envy Laptop 17t-cr0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8bdf, "HP Envy x360 2-in-1 Laptop 15-fe0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8be5, "HP ENVY Laptop 16-h1xxx", ALC287_FIXUP_CS35L41_I2C_2),
  SND_PCI_QUIRK(0x103c, 0x8a0f, "HP Pavilion 14-ec1xxx", ALC287_FIXUP_HP_GPIO_LED),
  SND_PCI_QUIRK(0x103c, 0x8a20, "HP Laptop 15s-fq5xxx", ALC236_FIXUP_HP_MUTE_LED_COEFBIT2),
  SND_PCI_QUIRK(0x103c, 0x8a25, "HP Victus 16-d1xxx (MB 8A25)", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
EOF
ahmedeladl00 commented 2 months ago
patch: **** malformed patch at line 15:

so this line in the patch is

--- sound/pci/hda/patch_realtek.c.orig
+++ sound/pci/hda/patch_realtek.c
@@ -9996,6 +9996,13 @@
  SND_PCI_QUIRK(0x103c, 0x89c6, "Zbook Fury 17 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
  SND_PCI_QUIRK(0x103c, 0x89ca, "HP", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
  SND_PCI_QUIRK(0x103c, 0x89d3, "HP EliteBook 645 G9 (MB 89D2)", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
+  SND_PCI_QUIRK(0x103c, 0x8a06, "HP Dragonfly Folio 13.5 inch G3 2-in-1 Notebook PC", ALC245_FIXUP_CS35L41_SPI_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2a, "HP HP ENVY x360 2-in-1 Laptop 15-ew0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2c, "HP Envy 16-h0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8a2e, "HP Envy Laptop 17t-cr0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8bdf, "HP Envy x360 2-in-1 Laptop 15-fe0xxx", ALC287_FIXUP_CS35L41_I2C_2),
+  SND_PCI_QUIRK(0x103c, 0x8be5, "HP ENVY Laptop 16-h1xxx", ALC287_FIXUP_CS35L41_I2C_2),
  SND_PCI_QUIRK(0x103c, 0x8a0f, "HP Pavilion 14-ec1xxx", ALC287_FIXUP_HP_GPIO_LED),
  SND_PCI_QUIRK(0x103c, 0x8a20, "HP Laptop 15s-fq5xxx", ALC236_FIXUP_HP_MUTE_LED_COEFBIT2),
  SND_PCI_QUIRK(0x103c, 0x8a25, "HP Victus 16-d1xxx (MB 8A25)", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),

which is SND_PCI_QUIRK(0x103c, 0x8a25, "HP Victus 16-d1xxx (MB 8A25)", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),

readtedium commented 2 months ago

Did you include the EOF and the $AUTO_PATCH_LINE? The reason it may be giving you issues is because the patch isn’t 13 lines right now.

ahmedeladl00 commented 2 months ago

I deleted the $AUTO_PATCH_LINE and wrote it manually and yes I think that I included EOF before ending the if

readtedium commented 2 months ago

I deleted the $AUTO_PATCH_LINE and wrote it manually and yes I think that I included EOF before ending the if

So what do you have currently in your file?

ahmedeladl00 commented 2 months ago

I went to an old version of the repo which was woking with me

#!/bin/sh

# see https://www.collabora.com/news-and-blog/blog/2021/05/05/quick-hack-patching-kernel-module-using-dkms/

# make the script stop on error
set -e

KERNEL_MODULE_NAME='snd-hda-codec-realtek'
DKMS_MODULE_VERSION='0.1'

./dkms-module_prepare.sh

# set up the actual DKMS module -------------------------------------------------------------------

./dkms-module_create.sh "${KERNEL_MODULE_NAME}" "${DKMS_MODULE_VERSION}"

# create the patch file to apply to the source of the snd-hda-codec-realtek kernel module
sudo tee "/usr/src/${KERNEL_MODULE_NAME}-${DKMS_MODULE_VERSION}/patch_realtek.patch" <<'EOF'
--- sound/pci/hda/patch_realtek.c.orig
+++ sound/pci/hda/patch_realtek.c
@@ -9996,6 +9996,13 @@
    SND_PCI_QUIRK(0x103c, 0x89c6, "Zbook Fury 17 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
    SND_PCI_QUIRK(0x103c, 0x89ca, "HP", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
    SND_PCI_QUIRK(0x103c, 0x89d3, "HP EliteBook 645 G9 (MB 89D2)", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
+  SND_PCI_QUIRK(0x103c, 0x8a78, "HP Dev One", ALC285_FIXUP_HP_LIMIT_INT_MIC_BOOST),
    SND_PCI_QUIRK(0x103c, 0x8a78, "HP Dev One", ALC285_FIXUP_HP_LIMIT_INT_MIC_BOOST),
-   SND_PCI_QUIRK(0x103c, 0x8aa0, "HP ProBook 440 G9 (MB 8A9E)", ALC236_FIXUP_HP_GPIO_LED),
+   SND_PCI_QUIRK(0x103c, 0x8a2a, "HP Envy x360 15-ew0xxx", ALC287_FIXUP_CS35L41_I2C_2),
    SND_PCI_QUIRK(0x103c, 0x8aa3, "HP ProBook 450 G9 (MB 8AA1)", ALC236_FIXUP_HP_GPIO_LED),
    SND_PCI_QUIRK(0x103c, 0x8aa8, "HP EliteBook 640 G9 (MB 8AA6)", ALC236_FIXUP_HP_GPIO_LED),
    SND_PCI_QUIRK(0x103c, 0x8aab, "HP EliteBook 650 G9 (MB 8AA9)", ALC236_FIXUP_HP_GPIO_LED),
-    SND_PCI_QUIRK(0x103c, 0x8abb, "HP ZBook Firefly 14 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
+   SND_PCI_QUIRK(0x103c, 0x8abb, "HP ZBook Firefly 14 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
    SND_PCI_QUIRK(0x103c, 0x8ad1, "HP EliteBook 840 14 inch G9 Notebook PC", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
    SND_PCI_QUIRK(0x103c, 0x8ad2, "HP EliteBook 860 16 inch G9 Notebook PC", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
    SND_PCI_QUIRK(0x103c, 0x8b42, "HP", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
EOF

./dkms-module_build.sh "${KERNEL_MODULE_NAME}" "${DKMS_MODULE_VERSION}"

and edited the line to be @@ -9996,6 +9996,13 @@ and now i get this output

Extracting original source of the kernel module
Applying patch_realtek.patch
patching file patch_realtek.c
patch: **** malformed patch at line 12:     SND_PCI_QUIRK(0x103c, 0x8aa8, "HP EliteBook 640 G9 (MB 8AA6)", ALC236_FIXUP_HP_GPIO_LED),
readtedium commented 2 months ago

Did you try copy-pasting exactly what I gave you up earlier in the thread? That’s what you should be using, exactly.

ahmedeladl00 commented 2 months ago

i made now a new clone and just edited what you gave me in the thread and again the same problem of the hunk failed

Extracting original source of the kernel module
Applying patch_realtek.patch
patching file patch_realtek.c
Hunk #1 FAILED at 9996.
1 out of 1 hunk FAILED -- saving rejects to file patch_realtek.c.rej
readtedium commented 2 months ago

I encourage you to go back to the patch file, look at what you’re actually patching against, and ensure that it is a 1:1 match. I don’t know how much I can help you from here, but I recommend tweaking the line numbers and ensure that the patch is going where you think it is. I think you’re close.

ahmedeladl00 commented 2 months ago

I am so thankful to you. It works now and I will explain what I did.

firstly I understood what should be edited as I was doing things without complete understanding.

I opend /usr/src/linux-source-6.7/sound/pci/hda/patch_realtek.c to take the lines from it because as I thought the problem were in the indentation

but I think that the real problem were in the calculation of the number lines so I just added the line for my laptop for that the file is just from the old version to be

#!/bin/sh

# see https://www.collabora.com/news-and-blog/blog/2021/05/05/quick-hack-patching-kernel-module-using-dkms/

# make the script stop on error
set -e

KERNEL_MODULE_NAME='snd-hda-codec-realtek'
DKMS_MODULE_VERSION='0.1'

./dkms-module_prepare.sh

# set up the actual DKMS module -------------------------------------------------------------------

./dkms-module_create.sh "${KERNEL_MODULE_NAME}" "${DKMS_MODULE_VERSION}"

# create the patch file to apply to the source of the snd-hda-codec-realtek kernel module
sudo tee "/usr/src/${KERNEL_MODULE_NAME}-${DKMS_MODULE_VERSION}/patch_realtek.patch" <<'EOF'
--- sound/pci/hda/patch_realtek.c.orig
+++ sound/pci/hda/patch_realtek.c
@@ -9996,6 +9996,7 @@
    SND_PCI_QUIRK(0x103c, 0x89c6, "Zbook Fury 17 G9", ALC245_FIXUP_CS35L41_SPI_2_HP_GPIO_LED),
    SND_PCI_QUIRK(0x103c, 0x89ca, "HP", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
    SND_PCI_QUIRK(0x103c, 0x89d3, "HP EliteBook 645 G9 (MB 89D2)", ALC236_FIXUP_HP_MUTE_LED_MICMUTE_VREF),
+   SND_PCI_QUIRK(0x103c, 0x8a2a, "HP Envy x360 15-ew0xxx", ALC287_FIXUP_CS35L41_I2C_2),
    SND_PCI_QUIRK(0x103c, 0x8a0f, "HP Pavilion 14-ec1xxx", ALC287_FIXUP_HP_GPIO_LED),
    SND_PCI_QUIRK(0x103c, 0x8a20, "HP Laptop 15s-fq5xxx", ALC236_FIXUP_HP_MUTE_LED_COEFBIT2),
    SND_PCI_QUIRK(0x103c, 0x8a25, "HP Victus 16-d1xxx (MB 8A25)", ALC245_FIXUP_HP_MUTE_LED_COEFBIT),
EOF

./dkms-module_build.sh "${KERNEL_MODULE_NAME}" "${DKMS_MODULE_VERSION}"

but now I am facing a problem that the audio is low. thanks

readtedium commented 2 months ago

@ahmedeladl00 Glad to hear! The low-volume issue is fixed in the 6.9 release candidate, but EasyEffects is a good solution to boost the volume as a stop-gap.

ahmedeladl00 commented 2 months ago

Regarding the low sound problem -> I will say something dumb. It was not the sound system from the laptop. I just made the app to be low volume because it was load at the headphones :joy::joy: thanks for help and your time

poligarpi commented 2 months ago

Kernel 6.9 stable is set to release this Sunday, May 12 if anyone interested, maybe Debian will get it next year but for anyone else running a more up to date distro, hopefully will get the update next week.