Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp102038ybl; Thu, 22 Aug 2019 20:45:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqxnnUp1v3n/PlE6S+55EZZsrwqLS+yfrMY+VnPNNlOmfn5N0540qlVh2UdjI3kVqdeDBTzI X-Received: by 2002:a17:902:248:: with SMTP id 66mr2355864plc.19.1566531901252; Thu, 22 Aug 2019 20:45:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566531901; cv=none; d=google.com; s=arc-20160816; b=M02hhktj/z03cm5bLHHJRE4YLIpPyTp2intZEYzMqDEnN7+lsaHsO50RlhN630R/um uloze+qOtC2SlxTzPvA4lzw2Qtul80RS0IsynDaUTvt3n7/eahLft+F+F6zjN2EXLYEs UAmQlhZ4eQWEd5BxRWnQ8fETWMILLn1Vn+Px+GCiC89nTy9YmJvS4IOvPalVnMUPTk1D lBVbgrYQuJbplK31NlP6JTzNIvSqcICiZak0rw2atHbv4nbi5XeUbsi0+j8gYXQn20as 5RLAgiY2/ePZ5pO4dW/wSqdihS+Ptm5vgHuG+bArOdQzcmLNXLQg0FBq0elY5Rkhin0Y OAYw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=a+52TDdQFadDpM3gO91M0oTQ6fXAgctxkiENzX68Fcg=; b=vcWd1Hk9TwbvcoQPo+d33Lsg/2ka495PJbUFvoU5Isx/BmlUC+97Od7765tYO/b8yI C/+5gOvNAkxTTURWz/nHgKilUDFsJHmi/lu+M96k9oFtYyw82v4fPswTOm9LV1ubeRET 4Eq5ZM0JeXf7rmnIVPC6xwcUXQtf6aq7l5HYYi0CAtHTwDQJLrpy8zs0woJKUV76GzJL KgMyWhujiEwDRyReBkcCzRyZ248hkbYPrADyjdsJSUVyMv4I2VA6mTfVeLI4gjXGbnVQ tshOrsL1LD/0zW7Vkggf/F0isYjDvcGMNBEs5jjlhyuSULC2oxfYA06Ozsr1XwypKu2D Biuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=drPAA4Cg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w13si1374789pfi.181.2019.08.22.20.44.45; Thu, 22 Aug 2019 20:45:01 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=drPAA4Cg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391842AbfHVRd2 (ORCPT + 99 others); Thu, 22 Aug 2019 13:33:28 -0400 Received: from mail.kernel.org ([198.145.29.99]:48908 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404423AbfHVRZ1 (ORCPT ); Thu, 22 Aug 2019 13:25:27 -0400 Received: from localhost (wsip-184-188-36-2.sd.sd.cox.net [184.188.36.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 617322064A; Thu, 22 Aug 2019 17:25:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566494726; bh=Ug2fpKLtiZUKPS4J5IkahslTsQaZFMtcx6ut+UNQiTg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=drPAA4Cg/jrfym9GeOj2KCYZWgtsXKlq0VPyBGzy4d1ZpTJiYtfetaLpxQ8JzLctW 9L0X2R1hXCqcFswlgiuRM39KJxusRa1rkVvKW8O4z6WkzAUHXCAi9Ckka4hO10QkWN RsgeIl1oTZ389uJMWD2tKmNNOPjhyUovTs12/hO8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hui Wang , Takashi Iwai Subject: [PATCH 4.19 16/85] ALSA: hda - Add a generic reboot_notify Date: Thu, 22 Aug 2019 10:18:49 -0700 Message-Id: <20190822171731.827835566@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190822171731.012687054@linuxfoundation.org> References: <20190822171731.012687054@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hui Wang commit 871b9066027702e6e6589da0e1edd3b7dede7205 upstream. Make codec enter D3 before rebooting or poweroff can fix the noise issue on some laptops. And in theory it is harmless for all codecs to enter D3 before rebooting or poweroff, let us add a generic reboot_notify, then realtek and conexant drivers can call this function. Cc: stable@vger.kernel.org Signed-off-by: Hui Wang Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- sound/pci/hda/hda_generic.c | 19 +++++++++++++++++++ sound/pci/hda/hda_generic.h | 1 + sound/pci/hda/patch_conexant.c | 6 +----- sound/pci/hda/patch_realtek.c | 11 +---------- 4 files changed, 22 insertions(+), 15 deletions(-) --- a/sound/pci/hda/hda_generic.c +++ b/sound/pci/hda/hda_generic.c @@ -6033,6 +6033,24 @@ void snd_hda_gen_free(struct hda_codec * } EXPORT_SYMBOL_GPL(snd_hda_gen_free); +/** + * snd_hda_gen_reboot_notify - Make codec enter D3 before rebooting + * @codec: the HDA codec + * + * This can be put as patch_ops reboot_notify function. + */ +void snd_hda_gen_reboot_notify(struct hda_codec *codec) +{ + /* Make the codec enter D3 to avoid spurious noises from the internal + * speaker during (and after) reboot + */ + snd_hda_codec_set_power_to_all(codec, codec->core.afg, AC_PWRST_D3); + snd_hda_codec_write(codec, codec->core.afg, 0, + AC_VERB_SET_POWER_STATE, AC_PWRST_D3); + msleep(10); +} +EXPORT_SYMBOL_GPL(snd_hda_gen_reboot_notify); + #ifdef CONFIG_PM /** * snd_hda_gen_check_power_status - check the loopback power save state @@ -6060,6 +6078,7 @@ static const struct hda_codec_ops generi .init = snd_hda_gen_init, .free = snd_hda_gen_free, .unsol_event = snd_hda_jack_unsol_event, + .reboot_notify = snd_hda_gen_reboot_notify, #ifdef CONFIG_PM .check_power_status = snd_hda_gen_check_power_status, #endif --- a/sound/pci/hda/hda_generic.h +++ b/sound/pci/hda/hda_generic.h @@ -336,6 +336,7 @@ int snd_hda_gen_parse_auto_config(struct struct auto_pin_cfg *cfg); int snd_hda_gen_build_controls(struct hda_codec *codec); int snd_hda_gen_build_pcms(struct hda_codec *codec); +void snd_hda_gen_reboot_notify(struct hda_codec *codec); /* standard jack event callbacks */ void snd_hda_gen_hp_automute(struct hda_codec *codec, --- a/sound/pci/hda/patch_conexant.c +++ b/sound/pci/hda/patch_conexant.c @@ -188,11 +188,7 @@ static void cx_auto_reboot_notify(struct /* Turn the problematic codec into D3 to avoid spurious noises from the internal speaker during (and after) reboot */ cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, false); - - snd_hda_codec_set_power_to_all(codec, codec->core.afg, AC_PWRST_D3); - snd_hda_codec_write(codec, codec->core.afg, 0, - AC_VERB_SET_POWER_STATE, AC_PWRST_D3); - msleep(10); + snd_hda_gen_reboot_notify(codec); } static void cx_auto_free(struct hda_codec *codec) --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -868,15 +868,6 @@ static void alc_reboot_notify(struct hda alc_shutup(codec); } -/* power down codec to D3 at reboot/shutdown; set as reboot_notify ops */ -static void alc_d3_at_reboot(struct hda_codec *codec) -{ - snd_hda_codec_set_power_to_all(codec, codec->core.afg, AC_PWRST_D3); - snd_hda_codec_write(codec, codec->core.afg, 0, - AC_VERB_SET_POWER_STATE, AC_PWRST_D3); - msleep(10); -} - #define alc_free snd_hda_gen_free #ifdef CONFIG_PM @@ -5111,7 +5102,7 @@ static void alc_fixup_tpt440_dock(struct struct alc_spec *spec = codec->spec; if (action == HDA_FIXUP_ACT_PRE_PROBE) { - spec->reboot_notify = alc_d3_at_reboot; /* reduce noise */ + spec->reboot_notify = snd_hda_gen_reboot_notify; /* reduce noise */ spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP; codec->power_save_node = 0; /* avoid click noises */ snd_hda_apply_pincfgs(codec, pincfgs);