From patchwork Mon Jan 14 20:03:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomas Espeleta X-Patchwork-Id: 10764291 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D508D1390 for ; Tue, 15 Jan 2019 10:56:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C2DB82B46F for ; Tue, 15 Jan 2019 10:56:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B6F4B2B4A1; Tue, 15 Jan 2019 10:56:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DEB572B46F for ; Tue, 15 Jan 2019 10:56:43 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 4BC8226744A; Tue, 15 Jan 2019 11:56:38 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 1A582267128; Mon, 14 Jan 2019 21:04:21 +0100 (CET) Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by alsa0.perex.cz (Postfix) with ESMTP id 2B226266AD7 for ; Mon, 14 Jan 2019 21:04:18 +0100 (CET) Received: by mail-wr1-f66.google.com with SMTP id q18so310195wrx.9 for ; Mon, 14 Jan 2019 12:04:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tTpBZI8lVHbCJGYTsxFveNQUq4NVCPvVkdNjNMkcNdw=; b=SlWef2MoENOaSFYdZOWLgZuNMfpJDnjvICJ1oAUqzbhI5ofkn553iuTXPz2I08OzNo ag8Vu6gLnDoQJf/dq4obPicngvVcj2SP9A2kojNVX61EzTkwWrk2BeNR+0V/8KUJkUBd 2pZfaHSMrlt9wajlMJpSy1mSflOBz9z+B79s/YFTq/9bysHM0Lfs0/yadngy03zp59jS ao05ZpDMh+kzlSpmaqRxzzwgCr6L5mlfYtAFgAGdxw94ZsfENsO+lR1YC0lwCbSmrkPY kiLIBzZ8DvSyl5PGGRoP8qJ/Ua+cmz9NnzSsztPKQMXrV31VF2SORLGc9jGXpSJ2+Kp/ kz2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tTpBZI8lVHbCJGYTsxFveNQUq4NVCPvVkdNjNMkcNdw=; b=DIf9x2+lYjLZe5yCyV4It6YpFPv65VjZQUS9pmvZ7k0wuCi/O22O7JT6tNSGjcHlKE Hq/fWCKUgXVSY9WB25vGqExdFKq0oWYz1/1dEwFVcf+pQboj0861ZL+dj5RFeQSWu5p5 MMYNXqo8Qhzf9smNu/AYkLvR0G56KPBjT/PND3j0kBvxuIWiqEttVhoFSfCjyL9dE9ls FTbzYZcTRdxhB9t5ijRuDpmwIOmQh2FhT1lBRgVB6ATN7LIs698RnrSZVZ7Qh3DG+NDQ YLnFx7JSEaSZEAuFcRy6pnQG39SMOzUgk71k2zEVOUNwgn5P3o9GhQF4BgQdydC4XFOg mgYA== X-Gm-Message-State: AJcUukeWEgJ8CRTpgbYPT8UXldIktR1/zq956IvYOAHh+Xfc7LZbd0P4 LthOo7tadKZ4lWAdG75TrfNOwTN6 X-Google-Smtp-Source: ALg8bN4S0TM7FDQI3WCEPNhAJq1Knb4GuQmTV5YJO+HIYTP1QoYFCYMHP55Q+nhQEtnPz1FrH47R9w== X-Received: by 2002:adf:8068:: with SMTP id 95mr112379wrk.181.1547496258275; Mon, 14 Jan 2019 12:04:18 -0800 (PST) Received: from localhost.localdomain (79.109.70.67.dyn.user.ono.com. [79.109.70.67]) by smtp.googlemail.com with ESMTPSA id t12sm77785213wrr.65.2019.01.14.12.04.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Jan 2019 12:04:17 -0800 (PST) From: Tomas Espeleta To: alsa-devel@alsa-project.org Date: Mon, 14 Jan 2019 21:03:53 +0100 Message-Id: <20190114200353.4114-1-tomas.espeleta@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Mailman-Approved-At: Tue, 15 Jan 2019 11:56:33 +0100 Cc: Kailang , Tomas Espeleta Subject: [alsa-devel] [PATCH] make huawei matebook X right speaker work X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Hard coded coefficients to make Huawuei Matebook X right speaker work. The Matebook X has a ALC298, please refer to bug 197801 on how these numbers were reverse engineered from the Windows driver The reversed engineered sequence represents a repeating pattern of verbs, and the only values that are changing periodically are written on indexes 0x23 and 0x25: 0x500, 0x23 0x400, VALUE1 0x500, 0x25 0x400, VALUE2 * fixes bug 197801 * skipped reading sequences (0x500 - 0xc00 sequences are ignored) * static values from reverse engineering are used Signed-off-by: Tomas Espeleta --- sound/pci/hda/patch_realtek.c | 70 +++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 3 deletions(-) diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index 0b3e7a18ca78..ec3972d9e30d 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -3628,6 +3628,64 @@ static void alc269_x101_hp_automute_hook(struct hda_codec *codec, vref); } +struct hda_alc298_mbxinit { + unsigned char value_0x23; + unsigned char value_0x25; +}; + +void alc298_stereo_seq(struct hda_codec *codec, + struct hda_alc298_mbxinit *initval, int first) +{ + snd_hda_codec_write(codec, 0x6, 0, 0x73e, 0x0); + alc_write_coef_idx(codec, 0x26, 0xb000); + + if (first) + snd_hda_codec_write(codec, 0x21, 0, 0xf09, 0x0); + + snd_hda_codec_write(codec, 0x6, 0, 0x73e, 0x80); + alc_write_coef_idx(codec, 0x26, 0xf000); + alc_write_coef_idx(codec, 0x23, initval->value_0x23); + + if (initval->value_0x23 != 0x1e) + alc_write_coef_idx(codec, 0x25, initval->value_0x25); + + snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0x26); + snd_hda_codec_write(codec, 0x20, 0, 0x4b0, 0x10); +} + +void alc298_fixup_huawei_mbx_stereo(struct hda_codec *codec, + const struct hda_fixup *fix, int action) +{ + // Initialization magic + static struct hda_alc298_mbxinit dac_init[] = { + {0xc, 0x0}, {0xd, 0x0}, {0xe, 0x0}, {0xf, 0x0}, + {0x10, 0x0}, {0x1a, 0x40}, {0x1b, 0x82}, {0x1c, 0x0}, + {0x1d, 0x0}, {0x1e, 0x0}, {0x1f, 0x0}, + {0x20, 0xc2}, {0x21, 0xc8}, {0x22, 0x26}, {0x23, 0x24}, + {0x27, 0xff}, {0x28, 0xff}, {0x29, 0xff}, {0x2a, 0x8f}, + {0x2b, 0x2}, {0x2c, 0x48}, {0x2d, 0x34}, {0x2e, 0x0}, + {0x2f, 0x0}, + {0x30, 0x0}, {0x31, 0x0}, {0x32, 0x0}, {0x33, 0x0}, + {0x34, 0x0}, {0x35, 0x1}, {0x36, 0x93}, {0x37, 0xc}, + {0x38, 0x0}, {0x39, 0x0}, {0x3a, 0xf8}, {0x38, 0x80}, + {} + }; + struct hda_alc298_mbxinit *seq = dac_init; + + // Start + snd_hda_codec_write(codec, 0x6, 0, 0x73e, 0x0); + snd_hda_codec_write(codec, 0x6, 0, 0x73e, 0x80); + alc_write_coef_idx(codec, 0x26, 0xf000); + alc_write_coef_idx(codec, 0x22, 0x31); + alc_write_coef_idx(codec, 0x23, 0xb); + alc_write_coef_idx(codec, 0x25, 0x0); + snd_hda_codec_write(codec, 0x20, 0, AC_VERB_SET_COEF_INDEX, 0x26); + snd_hda_codec_write(codec, 0x20, 0, 0x4b0, 0x10); + + for (; seq->value_0x23; seq++) + alc298_stereo_seq(codec, seq, seq == dac_init); +} + static void alc269_fixup_x101_headset_mic(struct hda_codec *codec, const struct hda_fixup *fix, int action) { @@ -3638,7 +3696,6 @@ static void alc269_fixup_x101_headset_mic(struct hda_codec *codec, } } - /* update mute-LED according to the speaker mute state via mic VREF pin */ static void alc269_fixup_mic_mute_hook(void *private_data, int enabled) { @@ -5582,6 +5639,7 @@ enum { ALC255_FIXUP_DUMMY_LINEOUT_VERB, ALC255_FIXUP_DELL_HEADSET_MIC, ALC256_FIXUP_HUAWEI_MBXP_PINS, + ALC298_FIXUP_HUAWEI_MBX_STEREO, ALC295_FIXUP_HP_X360, ALC221_FIXUP_HP_HEADSET_MIC, ALC285_FIXUP_LENOVO_HEADPHONE_NOISE, @@ -5880,6 +5938,12 @@ static const struct hda_fixup alc269_fixups[] = { .chained = true, .chain_id = ALC255_FIXUP_MIC_MUTE_LED }, + [ALC298_FIXUP_HUAWEI_MBX_STEREO] = { + .type = HDA_FIXUP_FUNC, + .v.func = alc298_fixup_huawei_mbx_stereo, + .chained = true, + .chain_id = ALC255_FIXUP_MIC_MUTE_LED + }, [ALC269_FIXUP_ASUS_X101_FUNC] = { .type = HDA_FIXUP_FUNC, .v.func = alc269_fixup_x101_headset_mic, @@ -6778,8 +6842,8 @@ static const struct snd_pci_quirk alc269_fixup_tbl[] = { SND_PCI_QUIRK(0x17aa, 0x511f, "Thinkpad", ALC298_FIXUP_TPT470_DOCK), SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_PCM_44K), SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD), - SND_PCI_QUIRK(0x19e5, 0x3200, "Huawei MBX", ALC255_FIXUP_MIC_MUTE_LED), - SND_PCI_QUIRK(0x19e5, 0x3201, "Huawei MBX", ALC255_FIXUP_MIC_MUTE_LED), + SND_PCI_QUIRK(0x19e5, 0x3200, "Huawei MBX", ALC298_FIXUP_HUAWEI_MBX_STEREO), + SND_PCI_QUIRK(0x19e5, 0x3201, "Huawei MBX", ALC298_FIXUP_HUAWEI_MBX_STEREO), SND_PCI_QUIRK(0x19e5, 0x3204, "Huawei MBXP", ALC256_FIXUP_HUAWEI_MBXP_PINS), SND_PCI_QUIRK(0x1b7d, 0xa831, "Ordissimo EVE2 ", ALC269VB_FIXUP_ORDISSIMO_EVE2), /* Also known as Malata PC-B1303 */