diff -rupN archlinux-linux/0005-ALSA-hda-realtek-Add-quirk-for-Lenovo-Yoga-9-14IAP7.patch archlinux-linux-patched/0005-ALSA-hda-realtek-Add-quirk-for-Lenovo-Yoga-9-14IAP7.patch
--- archlinux-linux/0005-ALSA-hda-realtek-Add-quirk-for-Lenovo-Yoga-9-14IAP7.patch	1970-01-01 02:00:00.000000000 +0200
+++ archlinux-linux-patched/0005-ALSA-hda-realtek-Add-quirk-for-Lenovo-Yoga-9-14IAP7.patch	2022-07-11 15:39:59.227560590 +0300
@@ -0,0 +1,171 @@
+From 5af8557e99de1d5bc459f22e13c88736ea565f5a Mon Sep 17 00:00:00 2001
+From: Philipp Jungkamp <p.jungkamp@gmx.net>
+Date: Mon, 13 Jun 2022 22:17:42 +0200
+Subject: [PATCH 5/7] ALSA: hda/realtek: Add quirk for Lenovo Yoga 9 14IAP7
+
+The Lenovo Yoga 9 14IAP7 it set up similarly to the Thinkpad X1 7th and 8th
+Gen. It also has the speakers attached to NID 0x14 and the bass speakers to
+NID 0x17, but here the codec misreports the NID 0x17 as unconnected.
+
+The bass speakers need additional hda verbs to activate. The coeffs from the
+Ideapad S740 (alc285_fixup_ideapad_coef) will activate the left bass speaker
+but not the right one. Sniffing the hda verbs from a Windows VM leads to a
+verb sequence which is similar to the one used for the Yoga 7 14ITL05.
+
+The pincfg and hda verbs will get the bass speakers working but the generic
+driver will connect them to NID 0x06 which has no volume control. So a
+a fix for the connection list and preferred connections is required to gain
+volume control. In contrast to aforementioned Thinkpads this device works
+with both DACs 0x02 and 0x03 a volume mixers, but DAC 0x02 should be preferred
+for a unified volume of speakers and bass and leave DAC 0x03 to the headphones.
+
+BugLink: https://bugzilla.kernel.org/show_bug.cgi?id=208555
+Signed-off-by: Philipp Jungkamp <p.jungkamp@gmx.de>
+---
+ sound/pci/hda/patch_realtek.c | 108 ++++++++++++++++++++++++++++++++++
+ 1 file changed, 108 insertions(+)
+
+diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
+index 323c74a04268..7d4db82c8662 100644
+--- a/sound/pci/hda/patch_realtek.c
++++ b/sound/pci/hda/patch_realtek.c
+@@ -6826,6 +6826,43 @@ static void alc_fixup_dell4_mic_no_presence_quiet(struct hda_codec *codec,
+ 	}
+ }
+ 
++static void alc287_fixup_yoga9_iap7_bass_spk_pin(struct hda_codec *codec,
++					  const struct hda_fixup *fix, int action)
++{
++	/* 
++	 * The Pin Complex 0x17 for the bass speakers is wrongly reported as
++	 * unconnected.
++	 */
++	static const struct hda_pintbl pincfgs[] = {
++		{ 0x17, 0x90170121 },
++		{ }
++	};
++	/* 
++	 * Avoid DAC 0x06 and 0x08, as they have no volume controls.
++	 * DAC 0x02 and 0x03 would be fine.
++	 */
++	static const hda_nid_t conn[] = { 0x02, 0x03 };
++	/* 
++	 * Prefer both speakerbar (0x14) and bass speakers (0x17) connected to DAC 0x02.
++	 * Headphones (0x21) are connected to DAC 0x03.
++	 */
++	static const hda_nid_t preferred_pairs[] = {
++		0x14, 0x02,
++		0x17, 0x02,
++		0x21, 0x03,
++		0
++	};
++	struct alc_spec *spec = codec->spec;
++
++	switch (action) {
++	case HDA_FIXUP_ACT_PRE_PROBE:
++		snd_hda_apply_pincfgs(codec, pincfgs);
++		snd_hda_override_conn_list(codec, 0x17, ARRAY_SIZE(conn), conn);
++		spec->gen.preferred_dacs = preferred_pairs;
++		break;
++	}
++}
++
+ enum {
+ 	ALC269_FIXUP_GPIO2,
+ 	ALC269_FIXUP_SONY_VAIO,
+@@ -7060,6 +7097,8 @@ enum {
+ 	ALC245_FIXUP_CS35L41_SPI_4_HP_GPIO_LED,
+ 	ALC285_FIXUP_HP_SPEAKERS_MICMUTE_LED,
+ 	ALC295_FIXUP_FRAMEWORK_LAPTOP_MIC_NO_PRESENCE,
++	ALC287_FIXUP_YOGA9_IAP7_BASS_SPK,
++	ALC287_FIXUP_YOGA9_IAP7_BASS_SPK_PIN,
+ };
+ 
+ static const struct hda_fixup alc269_fixups[] = {
+@@ -8871,6 +8910,74 @@ static const struct hda_fixup alc269_fixups[] = {
+ 		.chained = true,
+ 		.chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC
+ 	},
++	[ALC287_FIXUP_YOGA9_IAP7_BASS_SPK] = {
++		.type = HDA_FIXUP_VERBS,
++		.v.verbs = (const struct hda_verb[]) {
++			// enable left speaker
++			{ 0x20, 0x500, 0x24 },
++			{ 0x20, 0x400, 0x41 },
++
++			{ 0x20, 0x500, 0x26 },
++			{ 0x20, 0x400, 0xc },
++			{ 0x20, 0x400, 0x0 },
++			{ 0x20, 0x400, 0x1a },
++			{ 0x20, 0x4b0, 0x20 },
++
++			{ 0x20, 0x500, 0x26 },
++			{ 0x20, 0x400, 0xf },
++			{ 0x20, 0x400, 0x0 },
++			{ 0x20, 0x400, 0x42 },
++			{ 0x20, 0x4b0, 0x20 },
++
++			{ 0x20, 0x500, 0x26 },
++			{ 0x20, 0x400, 0x10 },
++			{ 0x20, 0x400, 0x0 },
++			{ 0x20, 0x400, 0x40 },
++			{ 0x20, 0x4b0, 0x20 },
++
++			{ 0x20, 0x500, 0x26 },
++			{ 0x20, 0x400, 0x2 },
++			{ 0x20, 0x400, 0x0 },
++			{ 0x20, 0x400, 0x0 },
++			{ 0x20, 0x4b0, 0x20 },
++
++			// enable righ speaker
++			{ 0x20, 0x500, 0x24 },
++			{ 0x20, 0x400, 0x46 },
++
++			{ 0x20, 0x500, 0x26 },
++			{ 0x20, 0x400, 0xc },
++			{ 0x20, 0x400, 0x0 },
++			{ 0x20, 0x400, 0x2a },
++			{ 0x20, 0x4b0, 0x20 },
++
++			{ 0x20, 0x500, 0x26 },
++			{ 0x20, 0x400, 0xf },
++			{ 0x20, 0x400, 0x0 },
++			{ 0x20, 0x400, 0x46 },
++			{ 0x20, 0x4b0, 0x20 },
++
++			{ 0x20, 0x500, 0x26 },
++			{ 0x20, 0x400, 0x10 },
++			{ 0x20, 0x400, 0x0 },
++			{ 0x20, 0x400, 0x44 },
++			{ 0x20, 0x4b0, 0x20 },
++
++			{ 0x20, 0x500, 0x26 },
++			{ 0x20, 0x400, 0x2 },
++			{ 0x20, 0x400, 0x0 },
++			{ 0x20, 0x400, 0x0 },
++			{ 0x20, 0x4b0, 0x20 },
++
++			{ },
++		},
++	},
++	[ALC287_FIXUP_YOGA9_IAP7_BASS_SPK_PIN] = {
++		.type = HDA_FIXUP_FUNC,
++		.v.func = alc287_fixup_yoga9_iap7_bass_spk_pin,
++		.chained = true,
++		.chain_id = ALC287_FIXUP_YOGA9_IAP7_BASS_SPK,
++	},
+ };
+ 
+ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
+@@ -9310,6 +9417,7 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = {
+ 	SND_PCI_QUIRK(0x17aa, 0x3176, "ThinkCentre Station", ALC283_FIXUP_HEADSET_MIC),
+ 	SND_PCI_QUIRK(0x17aa, 0x3178, "ThinkCentre Station", ALC283_FIXUP_HEADSET_MIC),
+ 	SND_PCI_QUIRK(0x17aa, 0x31af, "ThinkCentre Station", ALC623_FIXUP_LENOVO_THINKSTATION_P340),
+	SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo Yoga DuetITL 2021", ALC287_FIXUP_YOGA7_14ITL_SPEAKERS),
++	SND_PCI_QUIRK(0x17aa, 0x3801, "Yoga 9 14IAP7", ALC287_FIXUP_YOGA9_IAP7_BASS_SPK_PIN),
+ 	SND_PCI_QUIRK(0x17aa, 0x3813, "Legion 7i 15IMHG05", ALC287_FIXUP_LEGION_15IMHG05_SPEAKERS),
+ 	SND_PCI_QUIRK(0x17aa, 0x3818, "Lenovo C940", ALC298_FIXUP_LENOVO_SPK_VOLUME),
+ 	SND_PCI_QUIRK(0x17aa, 0x3819, "Lenovo 13s Gen2 ITL", ALC287_FIXUP_13S_GEN2_SPEAKERS),
+-- 
+2.37.0
+
diff -rupN archlinux-linux/sound/pci/hda/patch_realtek.c archlinux-linux-patched/sound/pci/hda/patch_realtek.c
--- archlinux-linux/sound/pci/hda/patch_realtek.c	2022-07-11 15:28:37.271990657 +0300
+++ archlinux-linux-patched/sound/pci/hda/patch_realtek.c	2022-07-11 15:41:28.415122403 +0300
@@ -6839,6 +6839,43 @@ static void alc_fixup_dell4_mic_no_prese
 	}
 }
 
+static void alc287_fixup_yoga9_iap7_bass_spk_pin(struct hda_codec *codec,
+					  const struct hda_fixup *fix, int action)
+{
+	/* 
+	 * The Pin Complex 0x17 for the bass speakers is wrongly reported as
+	 * unconnected.
+	 */
+	static const struct hda_pintbl pincfgs[] = {
+		{ 0x17, 0x90170121 },
+		{ }
+	};
+	/* 
+	 * Avoid DAC 0x06 and 0x08, as they have no volume controls.
+	 * DAC 0x02 and 0x03 would be fine.
+	 */
+	static const hda_nid_t conn[] = { 0x02, 0x03 };
+	/* 
+	 * Prefer both speakerbar (0x14) and bass speakers (0x17) connected to DAC 0x02.
+	 * Headphones (0x21) are connected to DAC 0x03.
+	 */
+	static const hda_nid_t preferred_pairs[] = {
+		0x14, 0x02,
+		0x17, 0x02,
+		0x21, 0x03,
+		0
+	};
+	struct alc_spec *spec = codec->spec;
+
+	switch (action) {
+	case HDA_FIXUP_ACT_PRE_PROBE:
+		snd_hda_apply_pincfgs(codec, pincfgs);
+		snd_hda_override_conn_list(codec, 0x17, ARRAY_SIZE(conn), conn);
+		spec->gen.preferred_dacs = preferred_pairs;
+		break;
+	}
+}
+
 enum {
 	ALC269_FIXUP_GPIO2,
 	ALC269_FIXUP_SONY_VAIO,
@@ -7074,6 +7111,8 @@ enum {
 	ALC245_FIXUP_CS35L41_SPI_4_HP_GPIO_LED,
 	ALC285_FIXUP_HP_SPEAKERS_MICMUTE_LED,
 	ALC295_FIXUP_FRAMEWORK_LAPTOP_MIC_NO_PRESENCE,
+	ALC287_FIXUP_YOGA9_IAP7_BASS_SPK,
+	ALC287_FIXUP_YOGA9_IAP7_BASS_SPK_PIN,
 };
 
 /* A special fixup for Lenovo C940 and Yoga Duet 7;
@@ -8906,6 +8945,74 @@ static const struct hda_fixup alc269_fix
 		.chained = true,
 		.chain_id = ALC269_FIXUP_HEADSET_MODE_NO_HP_MIC
 	},
+	[ALC287_FIXUP_YOGA9_IAP7_BASS_SPK] = {
+		.type = HDA_FIXUP_VERBS,
+		.v.verbs = (const struct hda_verb[]) {
+			// enable left speaker
+			{ 0x20, 0x500, 0x24 },
+			{ 0x20, 0x400, 0x41 },
+
+			{ 0x20, 0x500, 0x26 },
+			{ 0x20, 0x400, 0xc },
+			{ 0x20, 0x400, 0x0 },
+			{ 0x20, 0x400, 0x1a },
+			{ 0x20, 0x4b0, 0x20 },
+
+			{ 0x20, 0x500, 0x26 },
+			{ 0x20, 0x400, 0xf },
+			{ 0x20, 0x400, 0x0 },
+			{ 0x20, 0x400, 0x42 },
+			{ 0x20, 0x4b0, 0x20 },
+
+			{ 0x20, 0x500, 0x26 },
+			{ 0x20, 0x400, 0x10 },
+			{ 0x20, 0x400, 0x0 },
+			{ 0x20, 0x400, 0x40 },
+			{ 0x20, 0x4b0, 0x20 },
+
+			{ 0x20, 0x500, 0x26 },
+			{ 0x20, 0x400, 0x2 },
+			{ 0x20, 0x400, 0x0 },
+			{ 0x20, 0x400, 0x0 },
+			{ 0x20, 0x4b0, 0x20 },
+
+			// enable righ speaker
+			{ 0x20, 0x500, 0x24 },
+			{ 0x20, 0x400, 0x46 },
+
+			{ 0x20, 0x500, 0x26 },
+			{ 0x20, 0x400, 0xc },
+			{ 0x20, 0x400, 0x0 },
+			{ 0x20, 0x400, 0x2a },
+			{ 0x20, 0x4b0, 0x20 },
+
+			{ 0x20, 0x500, 0x26 },
+			{ 0x20, 0x400, 0xf },
+			{ 0x20, 0x400, 0x0 },
+			{ 0x20, 0x400, 0x46 },
+			{ 0x20, 0x4b0, 0x20 },
+
+			{ 0x20, 0x500, 0x26 },
+			{ 0x20, 0x400, 0x10 },
+			{ 0x20, 0x400, 0x0 },
+			{ 0x20, 0x400, 0x44 },
+			{ 0x20, 0x4b0, 0x20 },
+
+			{ 0x20, 0x500, 0x26 },
+			{ 0x20, 0x400, 0x2 },
+			{ 0x20, 0x400, 0x0 },
+			{ 0x20, 0x400, 0x0 },
+			{ 0x20, 0x4b0, 0x20 },
+
+			{ },
+		},
+	},
+	[ALC287_FIXUP_YOGA9_IAP7_BASS_SPK_PIN] = {
+		.type = HDA_FIXUP_FUNC,
+		.v.func = alc287_fixup_yoga9_iap7_bass_spk_pin,
+		.chained = true,
+		.chain_id = ALC287_FIXUP_YOGA9_IAP7_BASS_SPK,
+	},
 };
 
 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
@@ -9349,6 +9456,7 @@ static const struct snd_pci_quirk alc269
 	SND_PCI_QUIRK(0x17aa, 0x3178, "ThinkCentre Station", ALC283_FIXUP_HEADSET_MIC),
 	SND_PCI_QUIRK(0x17aa, 0x31af, "ThinkCentre Station", ALC623_FIXUP_LENOVO_THINKSTATION_P340),
 	SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo Yoga DuetITL 2021", ALC287_FIXUP_YOGA7_14ITL_SPEAKERS),
+	SND_PCI_QUIRK(0x17aa, 0x3801, "Yoga 9 14IAP7", ALC287_FIXUP_YOGA9_IAP7_BASS_SPK_PIN),
 	SND_PCI_QUIRK(0x17aa, 0x3813, "Legion 7i 15IMHG05", ALC287_FIXUP_LEGION_15IMHG05_SPEAKERS),
 	SND_PCI_QUIRK(0x17aa, 0x3818, "Lenovo C940 / Yoga Duet 7", ALC298_FIXUP_LENOVO_C940_DUET7),
 	SND_PCI_QUIRK(0x17aa, 0x3819, "Lenovo 13s Gen2 ITL", ALC287_FIXUP_13S_GEN2_SPEAKERS),
