diff mbox series

[SRU,L,1/1] ALSA: hda/realtek - ALC287 I2S speaker platform support

Message ID 20230922114314.215587-3-aaron.ma@canonical.com
State New
Headers show
Series Fix unstable audio at low levels on Thinkpad P1G4 | expand

Commit Message

Aaron Ma Sept. 22, 2023, 11:43 a.m. UTC
From: Kailang Yang <kailang@realtek.com>

BugLink: https://bugs.launchpad.net/bugs/2037077

0x17 was only speaker pin, DAC assigned will be 0x03. Headphone
assigned to 0x02.
Playback via headphone will get EQ filter processing. So,it needs to
swap DAC.

Tested-by: Mark Pearson <mpearson@lenovo.com>
Signed-off-by: Kailang Yang <kailang@realtek.com>
Link: https://lore.kernel.org/r/4e4cfa1b3b4c46838aecafc6e8b6f876@realtek.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
(backported from commit e43252db7e207a2e194e6a4883a43a31a776a968)
[ AaronMa: Adjusted for minor context ]
Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
---
 sound/pci/hda/patch_realtek.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

Comments

Roxana Nicolescu Sept. 29, 2023, 9:07 a.m. UTC | #1
On 22/09/2023 13:43, Aaron Ma wrote:
> From: Kailang Yang <kailang@realtek.com>
>
> BugLink: https://bugs.launchpad.net/bugs/2037077
>
> 0x17 was only speaker pin, DAC assigned will be 0x03. Headphone
> assigned to 0x02.
> Playback via headphone will get EQ filter processing. So,it needs to
> swap DAC.
>
> Tested-by: Mark Pearson <mpearson@lenovo.com>
> Signed-off-by: Kailang Yang <kailang@realtek.com>
> Link: https://lore.kernel.org/r/4e4cfa1b3b4c46838aecafc6e8b6f876@realtek.com
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> (backported from commit e43252db7e207a2e194e6a4883a43a31a776a968)
> [ AaronMa: Adjusted for minor context ]
> Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
> ---
>   sound/pci/hda/patch_realtek.c | 30 ++++++++++++++++++++++++++++++
>   1 file changed, 30 insertions(+)
>
> diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
> index 8a2eee0f6231..8142f2bc0bd2 100644
> --- a/sound/pci/hda/patch_realtek.c
> +++ b/sound/pci/hda/patch_realtek.c
> @@ -6961,6 +6961,27 @@ static void alc295_fixup_dell_inspiron_top_speakers(struct hda_codec *codec,
>   	}
>   }
>   
> +/* Forcibly assign NID 0x03 to HP while NID 0x02 to SPK */
> +static void alc287_fixup_bind_dacs(struct hda_codec *codec,
> +				    const struct hda_fixup *fix, int action)
> +{
> +	struct alc_spec *spec = codec->spec;
> +	static const hda_nid_t conn[] = { 0x02, 0x03 }; /* exclude 0x06 */
> +	static const hda_nid_t preferred_pairs[] = {
> +		0x17, 0x02, 0x21, 0x03, 0
> +	};
> +
> +	if (action != HDA_FIXUP_ACT_PRE_PROBE)
> +		return;
> +
> +	snd_hda_override_conn_list(codec, 0x17, ARRAY_SIZE(conn), conn);
> +	spec->gen.preferred_dacs = preferred_pairs;
> +	spec->gen.auto_mute_via_amp = 1;
> +	snd_hda_codec_write_cache(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
> +			    0x0); /* Make sure 0x14 was disable */
> +}
> +
> +
>   enum {
>   	ALC269_FIXUP_GPIO2,
>   	ALC269_FIXUP_SONY_VAIO,
> @@ -7211,6 +7232,7 @@ enum {
>   	ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN,
>   	ALC295_FIXUP_DELL_INSPIRON_TOP_SPEAKERS,
>   	ALC236_FIXUP_DELL_DUAL_CODECS,
> +	ALC287_FIXUP_THINKPAD_I2S_SPK,
Had to adjust this because ALC287_FIXUP_CS35L41_I2C_2_THINKPAD_ACPI was 
added
while applying upstream stable patches.
>   };
>   
>   /* A special fixup for Lenovo C940 and Yoga Duet 7;
> @@ -9215,6 +9237,10 @@ static const struct hda_fixup alc269_fixups[] = {
>   		.chained = true,
>   		.chain_id = ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
>   	},
> +	[ALC287_FIXUP_THINKPAD_I2S_SPK] = {
> +		.type = HDA_FIXUP_FUNC,
> +		.v.func = alc287_fixup_bind_dacs,
> +	},
>   };
>   
>   static const struct snd_pci_quirk alc269_fixup_tbl[] = {
> @@ -10306,6 +10332,10 @@ static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = {
>   		{0x17, 0x90170111},
>   		{0x19, 0x03a11030},
>   		{0x21, 0x03211020}),
> +	SND_HDA_PIN_QUIRK(0x10ec0287, 0x17aa, "Lenovo", ALC287_FIXUP_THINKPAD_I2S_SPK,
> +		{0x17, 0x90170110},
> +		{0x19, 0x03a11030},
> +		{0x21, 0x03211020}),
>   	SND_HDA_PIN_QUIRK(0x10ec0286, 0x1025, "Acer", ALC286_FIXUP_ACER_AIO_MIC_NO_PRESENCE,
>   		{0x12, 0x90a60130},
>   		{0x17, 0x90170110},
diff mbox series

Patch

diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 8a2eee0f6231..8142f2bc0bd2 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -6961,6 +6961,27 @@  static void alc295_fixup_dell_inspiron_top_speakers(struct hda_codec *codec,
 	}
 }
 
+/* Forcibly assign NID 0x03 to HP while NID 0x02 to SPK */
+static void alc287_fixup_bind_dacs(struct hda_codec *codec,
+				    const struct hda_fixup *fix, int action)
+{
+	struct alc_spec *spec = codec->spec;
+	static const hda_nid_t conn[] = { 0x02, 0x03 }; /* exclude 0x06 */
+	static const hda_nid_t preferred_pairs[] = {
+		0x17, 0x02, 0x21, 0x03, 0
+	};
+
+	if (action != HDA_FIXUP_ACT_PRE_PROBE)
+		return;
+
+	snd_hda_override_conn_list(codec, 0x17, ARRAY_SIZE(conn), conn);
+	spec->gen.preferred_dacs = preferred_pairs;
+	spec->gen.auto_mute_via_amp = 1;
+	snd_hda_codec_write_cache(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
+			    0x0); /* Make sure 0x14 was disable */
+}
+
+
 enum {
 	ALC269_FIXUP_GPIO2,
 	ALC269_FIXUP_SONY_VAIO,
@@ -7211,6 +7232,7 @@  enum {
 	ALC287_FIXUP_YOGA9_14IAP7_BASS_SPK_PIN,
 	ALC295_FIXUP_DELL_INSPIRON_TOP_SPEAKERS,
 	ALC236_FIXUP_DELL_DUAL_CODECS,
+	ALC287_FIXUP_THINKPAD_I2S_SPK,
 };
 
 /* A special fixup for Lenovo C940 and Yoga Duet 7;
@@ -9215,6 +9237,10 @@  static const struct hda_fixup alc269_fixups[] = {
 		.chained = true,
 		.chain_id = ALC255_FIXUP_DELL1_MIC_NO_PRESENCE,
 	},
+	[ALC287_FIXUP_THINKPAD_I2S_SPK] = {
+		.type = HDA_FIXUP_FUNC,
+		.v.func = alc287_fixup_bind_dacs,
+	},
 };
 
 static const struct snd_pci_quirk alc269_fixup_tbl[] = {
@@ -10306,6 +10332,10 @@  static const struct snd_hda_pin_quirk alc269_pin_fixup_tbl[] = {
 		{0x17, 0x90170111},
 		{0x19, 0x03a11030},
 		{0x21, 0x03211020}),
+	SND_HDA_PIN_QUIRK(0x10ec0287, 0x17aa, "Lenovo", ALC287_FIXUP_THINKPAD_I2S_SPK,
+		{0x17, 0x90170110},
+		{0x19, 0x03a11030},
+		{0x21, 0x03211020}),
 	SND_HDA_PIN_QUIRK(0x10ec0286, 0x1025, "Acer", ALC286_FIXUP_ACER_AIO_MIC_NO_PRESENCE,
 		{0x12, 0x90a60130},
 		{0x17, 0x90170110},