How to add patch?

I found this solution to fixing the audio on my Legion 7 here on the forum. However how am I supposed to add this patch? All the instructions I can find are extremely vague. I will add the patch below for reference. Is this the right solution to my sound problems and is there a step by step how to for me to add the patch?


diff --git a/sound/pci/hda/legion_15imhg05_speakers.c b/sound/pci/hda/legion_15imhg05_speakers.c
new file mode 100644
index 000000000000..e64761d949c8
--- /dev/null
+++ b/sound/pci/hda/legion_15imhg05_speakers.c
@@ -0,0 +1,495 @@
+// SPDX-License-Identifier: GPL-2.0
+/* Fixes for Lenovo Legion 15IMHg05 speaker output. */
+
+static const struct hda_verb alc287_legion_15imhg05_coefs[] = {
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x24 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x41 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x2 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, 0x4b0, 0x20 },
+
+    // Set right speaker for Legion 7i.
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x24 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x42 },
+
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0xc },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x2a },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x2 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, 0x4b0, 0x20 },
+    {}
+};
+
+static const struct hda_verb alc287_yoga7_14itl5_coefs[] = {
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x24 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x41 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x2 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, 0x4b0, 0x20 },
+
+    // set right speaker Yoga 7i.
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x24 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x46 },
+
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0xc },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x2a },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x2 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, 0x4b0, 0x20 },
+    {}
+};
+
+static const struct hda_verb alc287_13s_gen2_itl_coefs[] = {
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x24 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x41 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x3c },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x11 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x3c },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x11 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0xc },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1a },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0xc },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1a },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0xf },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x42 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0xf },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x42 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x10 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x40 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x10 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x40 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x3 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x9 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x3 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x9 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1c },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x4c },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1c },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x4c },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1d },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x4e },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1d },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x4e },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1b },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1b },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x19 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x25 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x19 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x25 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x18 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x37 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x18 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x37 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1a },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x40 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1a },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x40 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x16 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x76 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x16 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x76 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x15 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x15 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x15 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x15 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x7 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x86 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x7 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x86 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x2 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x2 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x2 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x2 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x24 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x42 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x24 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x42 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x3c },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x11 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x3c },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x11 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0xc },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x2a },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0xc },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x2a },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0xf },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x46 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0xf },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x46 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x10 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x44 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x10 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x44 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x3 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x9 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x3 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x9 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1c },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x4c },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1c },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x4c },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1d },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x4e },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1d },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x4e },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1b },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1b },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x19 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x25 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x19 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x25 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x18 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x37 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x18 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x37 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1a },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x40 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1a },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x40 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x16 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x76 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x16 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x76 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x17 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x10 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x17 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x10 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x15 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x15 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x15 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x15 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x7 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x86 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x7 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x86 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x2 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x2 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x1 },
+    {0x20, 0x4b0, 0x20 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x29 },
+    {0x20, AC_VERB_SET_COEF_INDEX, 0x26 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x2 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, AC_VERB_SET_PROC_COEF, 0x0 },
+    {0x20, 0x4b0, 0x20 },
+    {}
+};
+
+static void alc287_fixup_legion_15imhg05_speakers(struct hda_codec *codec,
+						  const struct hda_fixup *fix,
+						  int action) {
+    struct alc_spec *spec = codec->spec;
+
+    switch (action) {
+    case HDA_FIXUP_ACT_INIT:
+	spec->gen.automute_speaker = 0;
+	//snd_hda_add_verbs(codec, alc287_legion_15imhg05_coefs);
+	break;
+    }
+}
+
+static void alc287_fixup_legion_yoga7_speakers(struct hda_codec *codec,
+					       const struct hda_fixup *fix,
+					       int action) {
+    struct alc_spec *spec = codec->spec;
+
+    switch (action) {
+    case HDA_FIXUP_ACT_INIT:
+	//spec->gen.automute_speaker = 0;
+	snd_hda_add_verbs(codec, alc287_yoga7_14itl5_coefs);
+	break;
+    }
+}
+
+static void alc287_fixup_lenovo_13s_gen2_itl_speakers(struct hda_codec *codec,
+						      const struct hda_fixup *fix,
+						      int action) {
+    struct alc_spec *spec = codec->spec;
+
+    switch (action) {
+    case HDA_FIXUP_ACT_INIT:
+	snd_hda_add_verbs(codec, alc287_13s_gen2_itl_coefs);
+	break;
+    }
+}
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index e46e43dac6bf..d9fa4e4ceb5b 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -6352,6 +6352,9 @@ static void alc_fixup_thinkpad_acpi(struct hda_codec *codec,
 /* for alc285_fixup_ideapad_s740_coef() */
 #include "ideapad_s740_helper.c"
 
+/* For alc287_fixup_legion_15imhg05_speakers() */
+#include "legion_15imhg05_speakers.c"
+
 enum {
 	ALC269_FIXUP_GPIO2,
 	ALC269_FIXUP_SONY_VAIO,
@@ -6561,6 +6564,10 @@ enum {
 	ALC287_FIXUP_IDEAPAD_BASS_SPK_AMP,
 	ALC623_FIXUP_LENOVO_THINKSTATION_P340,
 	ALC255_FIXUP_ACER_HEADPHONE_AND_MIC,
+	ALC287_FIXUP_LEGION_15IMHG05_SPEAKERS,
+	ALC287_FIXUP_LEGION_15IMHG05_AUTOMUTE,
+	ALC287_FIXUP_YOGA7_14ITL_SPEAKERS,
+	ALC287_FIXUP_13S_GEN2_SPEAKERS,
 };
 
 static const struct hda_fixup alc269_fixups[] = {
@@ -8088,6 +8095,30 @@ static const struct hda_fixup alc269_fixups[] = {
 		.chained = true,
 		.chain_id = ALC269_FIXUP_THINKPAD_ACPI,
 	},
+	[ALC287_FIXUP_LEGION_15IMHG05_SPEAKERS] = {
+		.type = HDA_FIXUP_VERBS,
+		.v.verbs = alc287_legion_15imhg05_coefs,
+		.chained = true,
+		.chain_id = ALC287_FIXUP_LEGION_15IMHG05_AUTOMUTE,
+	},
+	[ALC287_FIXUP_LEGION_15IMHG05_AUTOMUTE] = {
+		.type = HDA_FIXUP_FUNC,
+		.v.func = alc287_fixup_legion_15imhg05_speakers,
+		.chained = true,
+		.chain_id = ALC269_FIXUP_HEADSET_MODE,
+	},
+	[ALC287_FIXUP_YOGA7_14ITL_SPEAKERS] = {
+		.type = HDA_FIXUP_VERBS,
+		.v.verbs = alc287_yoga7_14itl5_coefs,
+		.chained = true,
+		.chain_id = ALC269_FIXUP_HEADSET_MODE,
+	},
+	[ALC287_FIXUP_13S_GEN2_SPEAKERS] = {
+		.type = HDA_FIXUP_FUNC,
+		.v.func = alc287_fixup_lenovo_13s_gen2_itl_speakers,
+		.chained = true,
+		.chain_id = ALC269_FIXUP_HEADSET_MODE,
+	},
 	[ALC295_FIXUP_ASUS_DACS] = {
 		.type = HDA_FIXUP_FUNC,
 		.v.func = alc295_fixup_asus_dacs,
@@ -8520,6 +8551,10 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
 	SND_PCI_QUIRK(0x17aa, 0x3818, "Lenovo C940", ALC298_FIXUP_LENOVO_SPK_VOLUME),
 	SND_PCI_QUIRK(0x17aa, 0x3827, "Ideapad S740", ALC285_FIXUP_IDEAPAD_S740_COEF),
 	SND_PCI_QUIRK(0x17aa, 0x3843, "Yoga 9i", ALC287_FIXUP_IDEAPAD_BASS_SPK_AMP),
+	SND_PCI_QUIRK(0x17aa, 0x3813, "Lenovo Legion 7", ALC287_FIXUP_LEGION_15IMHG05_SPEAKERS),
+	SND_PCI_QUIRK(0x17aa, 0x3847, "Lenovo Legion 7 16ACHg6", ALC287_FIXUP_LEGION_15IMHG05_SPEAKERS),
+	SND_PCI_QUIRK(0x17aa, 0x3852, "Lenovo Yoga 7 14ITL5", ALC287_FIXUP_YOGA7_14ITL_SPEAKERS),
+	SND_PCI_QUIRK(0x17aa, 0x3819, "Lenovo 13s Gen2 ITL", ALC287_FIXUP_13S_GEN2_SPEAKERS),
 	SND_PCI_QUIRK(0x17aa, 0x3902, "Lenovo E50-80", ALC269_FIXUP_DMIC_THINKPAD_ACPI),
 	SND_PCI_QUIRK(0x17aa, 0x3977, "IdeaPad S210", ALC283_FIXUP_INT_MIC),
 	SND_PCI_QUIRK(0x17aa, 0x3978, "Lenovo B50-70", ALC269_FIXUP_DMIC_THINKPAD_ACPI),

You need to clone repo, apply path via git am <patchfile> and build modified program.

If I’m not mistaken, then that’s a kernel patch for the Intel hda driver. You would need to download the full kernel sources and then apply the patch. And then you’d have to rebuild the kernel.

Are you sure you want to go there? :face_with_raised_eyebrow:

Ah I see, well NO! Haha I would much rather just install a packet and have it fixed but this is the only solution I could find. Is there any other solutions? All the forum post I can find about this problem are quite old.

If there are, then I’m afraid I can’t help you with that. I only rarely ever use a laptop, and I also steer very clear of non-standard hardware or anything with a “Designed for Microsoft™ Windows®” sticker on it.

:man_shrugging:

Maybe some other forum member knows how to deal with your audio problem ─ whatever said problem is, because you didn’t tell us. :frowning:

:crossed_fingers:

Yeah maybe start with that, open a support thread with your issue and let see if there is a solution then
:wink:

1 Like

This ALSA patch for Realtek ALC287 is from this Bugzilla report
208555 – No sound from speakers using Realtek ALC287

This patch was merged into Linux Kernel in October
LKML: Greg Kroah-Hartman: [PATCH 5.14 037/172] ALSA: hda/realtek: Quirks to enable speaker output for Lenovo Legion 7i 15IMHG05, Yoga 7i 14ITL5/15ITL5, and 13s Gen2 laptops.
And is included with kernels > v5.14.10
patch_realtek.c - sound/pci/hda/patch_realtek.c - Linux source code (v5.14.10) - Bootlin

If your onboard audio codec has the Vendor ID: product ID number [17aa:3852] or
[17aa:3853] , and system is booted using kernel v5.14 (or v5.15) , the patch will be applied automatically

2 Likes

Hi thx for the tip, did not fix my sound problem.I will start a more proper support thread as suggested.