From patchwork Fri Jul 26 14:26:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13742836 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6059510953 for ; Fri, 26 Jul 2024 14:25:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722003958; cv=none; b=tXdKSC5YzORxun6QlIoDwNMW2l3SUBFKYGUJkza/VXk7TTZcMpyf3w4juFm4FlRUegfiCNmig5YCdUtzQ1Exh1zmJQ9t3ouNLszg01FzNMFsCeUabbJ8VtAcpxiLonfmELkrYYs74ilZmBbpfsXhVUWgkQcsuk0hiDMHAubY89s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722003958; c=relaxed/simple; bh=F6hYFJFM1Wz6FrMXY9qRCizS9Nhu9WREQJbyy0keEA4=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=kIfSFHux6eDxYJAjMK5yHfQcRq0ZrGvlpvOhV3SmXcIENlxS3Nn21WIkBFDI3uiM7wdhCKyEjM9HrgUQ1zfYKQeENwOP5lC0CIY1pr1CA0C3Ca3jyuuRtnTxF2RFExNesHURG3hMEh1b9I6d3jyTYlzlB7L/gLiN4YjwYN6ZEHY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=o9WWxv0q; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=JDqhyROo; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=Gv4DlMFE; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=QBMcoibf; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="o9WWxv0q"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="JDqhyROo"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="Gv4DlMFE"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="QBMcoibf" Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3A07D1F8AA; Fri, 26 Jul 2024 14:25:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722003954; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=FtvrKoBncqHURFlgdXkg+oF35zjMYsmQOGG6b+QA+rE=; b=o9WWxv0qnaUM7ZQIlfOtjukVmv/qWzcJj/wwAlFeUHG7MOMiX36qG7e85w+KhhnOxdkqfe qbq2wiqkNt5pZnNHPDIygbMzdg6H3cJkyJtvsy7QmBxd6kNM4CsKhzQ58oJ+tSZlBA29ZD UTH6FC79PGizyfsBolyJNTpooF1Ta24= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722003954; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=FtvrKoBncqHURFlgdXkg+oF35zjMYsmQOGG6b+QA+rE=; b=JDqhyROoiXkZWn/Pz13B0OREqWnll4WWaB1/ZfrEHODKnw4c52UpxwzAcoHKBtarV7RzzD 0bpv6oxk5qkokiBA== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=Gv4DlMFE; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=QBMcoibf DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722003953; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=FtvrKoBncqHURFlgdXkg+oF35zjMYsmQOGG6b+QA+rE=; b=Gv4DlMFEi3KvS/J2Pj6fGGQ8+Ua7iPGal5Yb+qE02oGJLHQO0iWAEq5GHvlW9G5CwdLU3J NuC42EXwl0fIUH6iTnK//NJcy2Zc9TUBW0gQ3wzDMlI1Ezrtovwz3j94qsyseWdkrPGNzz c3uIr+BNfgV0HaB1CeuutnCz9YwHAaM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722003953; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=FtvrKoBncqHURFlgdXkg+oF35zjMYsmQOGG6b+QA+rE=; b=QBMcoibfgiUR2Rkk6OgtKgydUXMPw0hPTVYM2x5Mx/ZfVl7q/XMyeiV5ofylGuAMgTneP9 IQvjcxN209wzXzCw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 21091138A7; Fri, 26 Jul 2024 14:25:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id fPTdBvGxo2YwHwAAD6G6ig (envelope-from ); Fri, 26 Jul 2024 14:25:53 +0000 From: Takashi Iwai To: linux-sound@vger.kernel.org Subject: [PATCH 1/2] ALSA: hda/generic: Add a helper to mute speakers at suspend/shutdown Date: Fri, 26 Jul 2024 16:26:19 +0200 Message-ID: <20240726142625.2460-1-tiwai@suse.de> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Server: rspamd1.dmz-prg2.suse.org X-Rspamd-Action: no action X-Rspamd-Queue-Id: 3A07D1F8AA X-Spam-Score: -2.81 X-Spam-Level: X-Spam-Flag: NO X-Spamd-Result: default: False [-2.81 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_ONE(0.00)[1]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; TO_DN_NONE(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_TRACE(0.00)[suse.de:+]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,suse.de:dkim,imap1.dmz-prg2.suse.org:rdns,imap1.dmz-prg2.suse.org:helo] Some devices indicate click noises at suspend or shutdown when the speakers are unmuted. This patch adds a helper, snd_hda_gen_shutup_speakers(), to work around it. The new function is supposed to be called at suspend or shutdown by the codec driver, and it mutes the speakers. The mute status isn't cached, hence the original mute state will be restored at resume again. Signed-off-by: Takashi Iwai --- sound/pci/hda/hda_generic.c | 63 +++++++++++++++++++++++++++++++++++++ sound/pci/hda/hda_generic.h | 1 + 2 files changed, 64 insertions(+) diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c index f64d9dc197a3..9cff87dfbecb 100644 --- a/sound/pci/hda/hda_generic.c +++ b/sound/pci/hda/hda_generic.c @@ -4955,6 +4955,69 @@ void snd_hda_gen_stream_pm(struct hda_codec *codec, hda_nid_t nid, bool on) } EXPORT_SYMBOL_GPL(snd_hda_gen_stream_pm); +/* forcibly mute the speaker output without caching; return true if updated */ +static bool force_mute_output_path(struct hda_codec *codec, hda_nid_t nid) +{ + if (!nid) + return false; + if (!nid_has_mute(codec, nid, HDA_OUTPUT)) + return false; /* no mute, skip */ + if (snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) & + snd_hda_codec_amp_read(codec, nid, 1, HDA_OUTPUT, 0) & + HDA_AMP_MUTE) + return false; /* both channels already muted, skip */ + + /* direct amp update without caching */ + snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, + AC_AMP_SET_OUTPUT | AC_AMP_SET_LEFT | + AC_AMP_SET_RIGHT | HDA_AMP_MUTE); + return true; +} + +/** + * snd_hda_gen_shutup_speakers - Forcibly mute the speaker outputs + * @codec: the HDA codec + * + * Forcibly mute the speaker outputs, to be called at suspend or shutdown. + * + * The mute state done by this function isn't cached, hence the original state + * will be restored at resume. + * + * Return true if the mute state has been changed. + */ +bool snd_hda_gen_shutup_speakers(struct hda_codec *codec) +{ + struct hda_gen_spec *spec = codec->spec; + const int *paths; + const struct nid_path *path; + int i, p, num_paths; + bool updated = false; + + /* if already powered off, do nothing */ + if (!snd_hdac_is_power_on(&codec->core)) + return false; + + if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT) { + paths = spec->out_paths; + num_paths = spec->autocfg.line_outs; + } else { + paths = spec->speaker_paths; + num_paths = spec->autocfg.speaker_outs; + } + + for (i = 0; i < num_paths; i++) { + path = snd_hda_get_path_from_idx(codec, paths[i]); + if (!path) + continue; + for (p = 0; p < path->depth; p++) + if (force_mute_output_path(codec, path->path[p])) + updated = true; + } + + return updated; +} +EXPORT_SYMBOL_GPL(snd_hda_gen_shutup_speakers); + /** * snd_hda_gen_parse_auto_config - Parse the given BIOS configuration and * set up the hda_gen_spec diff --git a/sound/pci/hda/hda_generic.h b/sound/pci/hda/hda_generic.h index 8f5ecf740c49..08544601b4ce 100644 --- a/sound/pci/hda/hda_generic.h +++ b/sound/pci/hda/hda_generic.h @@ -353,5 +353,6 @@ int snd_hda_gen_add_mute_led_cdev(struct hda_codec *codec, int snd_hda_gen_add_micmute_led_cdev(struct hda_codec *codec, int (*callback)(struct led_classdev *, enum led_brightness)); +bool snd_hda_gen_shutup_speakers(struct hda_codec *codec); #endif /* __SOUND_HDA_GENERIC_H */ From patchwork Fri Jul 26 14:26:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Takashi Iwai X-Patchwork-Id: 13742835 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 30526101E2 for ; Fri, 26 Jul 2024 14:25:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722003957; cv=none; b=k/FuEtVHixaaKsm4090+cKpGQhG3B0kcT2rBNxzLcUJRgLKwcjjNo9iOqoQ2ZD0iwDHj4MH/4mR9GSlRWXxswtl60YNyt9YRfe/nWXOXrX8ZAZqRKEUEqUWK3Qv7eVcDnjmie5xd2XfHQneE+K5QKlOUcgZ8kyLQLT0cHtBMw24= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722003957; c=relaxed/simple; bh=gw4wPf2HOzjxhvqoWEbGYPNqnBgx4hK1S/FE5kofA8k=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SFRwqlqmtEITWVcgpoxJmCVfzXxvVsp6+PkNgM8xdm1CNTVbbc4fVoFweXaoaZ46mBzaaT7M6T47uxKU/eYaiy/AE/aXvfuoTyBZJSr8Jo32cJ28ylHgTHYh6qkDXF83ej1sCpBl5v9j1hmCicKxTN+/ze+YNtiywBBjZokx+3Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=dcBGOFo3; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=22tAOm9u; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b=gXm2rhz5; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b=zLuUHmG1; arc=none smtp.client-ip=195.135.223.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="dcBGOFo3"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="22tAOm9u"; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.b="gXm2rhz5"; dkim=permerror (0-bit key) header.d=suse.de header.i=@suse.de header.b="zLuUHmG1" Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 64FBE1F8AE; Fri, 26 Jul 2024 14:25:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722003954; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sbNae9TNg504zcGg96qeYo2+LGuYHw0JlBrGbb8jfw4=; b=dcBGOFo39VqzUD9mm7AFCQ4tVzw2EofSXer89ndAZJQ4jZPOWSxD6qQ16Obn1zx908AuaA cYBv4I8HttI2n+v1S7fAdXxb9yc3HvmcCr/+T4iG1AO6FeRNmzmTUgbVQpSgYHDl6dpsJP FHymraQv6gA+MM3bw1yIzXCy6/DmkOk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722003954; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sbNae9TNg504zcGg96qeYo2+LGuYHw0JlBrGbb8jfw4=; b=22tAOm9uF4qsz8j5UfGHX8dcK/7ZNuIyhipw84n09dg2ro2g8gg9nOV2T3jW9Up79wuEyp 0VR2ltyN/7kG/xDQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1722003953; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sbNae9TNg504zcGg96qeYo2+LGuYHw0JlBrGbb8jfw4=; b=gXm2rhz5gB64sWiyyRlDasoia5lWS22FRy3JUYs7q3BT7a1Wr0UqJkmsEyPPPrFjgL7wla 5oOdpLYBXsIXQp/UwYzmEBtcbLULcGb0pUYC4xjuk/BH6l19nBzAx17Y5LxfNVZAjdu5SB Go+9Ss3CLTkt6TvrV7GOOom0WBnodUk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1722003953; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sbNae9TNg504zcGg96qeYo2+LGuYHw0JlBrGbb8jfw4=; b=zLuUHmG1MSlIRG9pFCfWjspuDYqm3Jb4WT+A9IzCmYVok0XDjdA9qbjwHsv51Xot16V3vS cqGQTi6NA/Tp+9Cw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 3FEEB13A9D; Fri, 26 Jul 2024 14:25:53 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id ABtjDvGxo2YwHwAAD6G6ig (envelope-from ); Fri, 26 Jul 2024 14:25:53 +0000 From: Takashi Iwai To: linux-sound@vger.kernel.org Subject: [PATCH 2/2] ALSA: hda/conexant: Mute speakers at suspend / shutdown Date: Fri, 26 Jul 2024 16:26:20 +0200 Message-ID: <20240726142625.2460-2-tiwai@suse.de> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240726142625.2460-1-tiwai@suse.de> References: <20240726142625.2460-1-tiwai@suse.de> Precedence: bulk X-Mailing-List: linux-sound@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Level: X-Spamd-Result: default: False [-2.60 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; MIME_GOOD(-0.10)[text/plain]; TO_MATCH_ENVRCPT_ALL(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; FUZZY_BLOCKED(0.00)[rspamd.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCVD_TLS_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:email,imap1.dmz-prg2.suse.org:helo,suse.com:url] X-Spam-Flag: NO X-Spam-Score: -2.60 Use the new helper to mute speakers at suspend / shutdown for avoiding click noises. Link: https://bugzilla.suse.com/show_bug.cgi?id=1228269 Signed-off-by: Takashi Iwai --- sound/pci/hda/patch_conexant.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c index 4472923ba694..f030669243f9 100644 --- a/sound/pci/hda/patch_conexant.c +++ b/sound/pci/hda/patch_conexant.c @@ -205,6 +205,8 @@ static void cx_auto_shutdown(struct hda_codec *codec) { struct conexant_spec *spec = codec->spec; + snd_hda_gen_shutup_speakers(codec); + /* 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);