From patchwork Mon Oct 24 11:30:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8911 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp434280wru; Mon, 24 Oct 2022 05:51:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4kU8QNq5Sda3LCA63WAHoExpjix6/b0teCK55MYkE054BkAXaogHjqBPICdn/Hd1xROCK4 X-Received: by 2002:a17:906:3019:b0:7a7:6425:7d1e with SMTP id 25-20020a170906301900b007a764257d1emr4550157ejz.663.1666615911021; Mon, 24 Oct 2022 05:51:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615911; cv=none; d=google.com; s=arc-20160816; b=bYz0A4hiVxwQpAEspt43z97UjE5xsP34rNvChduU3VTlEhP2BpX1ZXfIaDA2wAftu6 PeKExqVLGrf40e4FHFnm9ZgSDDGDt3IXmyJ36TAalmgPbWfno1t/FjIBqD0NjZqpfLno ilCdkhzqVg6fxznht/HfvBnrCAVeeu49Icj5JqWRiOFM1NgsgUC8C9mZAWcqIazUnuvd vb6yQVsweWmSG09SCm0Iw7ZpVDxjsDSU3i39//dwV3u83ZWl3LAe2wKGGzbCkKJQg0GM wunuAYC2JSoukiUsPR2iwPwOFKhXzDt0OMooEEsU86ingkCu6vCwB9X7cCy3N1twK5UX PeUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wNLsOR9sMAGTz8IJxdzfeWZ5+9K+er4XE69megKINC0=; b=BVzgKqm0Do17M4gUW9TRvmOjY2oIMvTFlA73a1dv/HsXXvJiXszeV7YtYVDiuHd/0/ sRT8kCN9Os95LLxgzJNo/Zv29iGIcJsIsLmo8WaXmpRm8xwZyFnJpzP3NNYBD3MixhfI yldtDl5Zll/3mNcj4esQ4JIpCGgPaTsPEGAYCHm9UqE6Rd7yhKEkNijPijhNVNf4ug+Z aAPex1Ak+FD30UqniUal/9jclqzgglWFHIllbLXo1XpThlxfIh9ictIAVqqAo+pTiVkD GhA3x1XhHx0ium65zrWGbJOOR65Ol1ignKhyXuL97rCMiq/bf3RuPmpGvEEu7RUtf4bJ NE2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=c1tWbXIa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id he18-20020a1709073d9200b0078ca7bbf616si31926883ejc.746.2022.10.24.05.51.22; Mon, 24 Oct 2022 05:51:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=c1tWbXIa; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234312AbiJXMuL (ORCPT + 99 others); Mon, 24 Oct 2022 08:50:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234585AbiJXMpL (ORCPT ); Mon, 24 Oct 2022 08:45:11 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F54622531; Mon, 24 Oct 2022 05:09:44 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DA702612B1; Mon, 24 Oct 2022 12:08:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EEB14C433D6; Mon, 24 Oct 2022 12:08:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666613332; bh=GvrN2gzQkrI3b84T+M2mKLypIgpyFxYr4imErMtP4aM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c1tWbXIasAhvtDVvBlfEIXPkNVm9xPpAbLDUsUYF6MbeyVgwNE8uPCwY0gB1AMtWM NHhjZvKHCxrmSzoj4drd/9VRlDUp5Jkzz5nTTQbAw5exQw8sBYwg/MvADZnRkmaor3 jP+1lUEwvb7Itq+XgXx/EAju7kJIFL20CQhLuPhk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Takashi Iwai , Sasha Levin Subject: [PATCH 5.4 097/255] ALSA: hda: beep: Simplify keep-power-at-enable behavior Date: Mon, 24 Oct 2022 13:30:07 +0200 Message-Id: <20221024113005.715321102@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024113002.471093005@linuxfoundation.org> References: <20221024113002.471093005@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747573445876622276?= X-GMAIL-MSGID: =?utf-8?q?1747573445876622276?= From: Takashi Iwai [ Upstream commit 4c8d695cb9bc5f6fd298a586602947b2fc099a64 ] The recent fix for IDT codecs to keep the power up while the beep is enabled can be better integrated into the beep helper code. This patch cleans up the code with refactoring. Fixes: 414d38ba8710 ("ALSA: hda/sigmatel: Keep power up while beep is enabled") Link: https://lore.kernel.org/r/20220906092306.26183-1-tiwai@suse.de Signed-off-by: Takashi Iwai Signed-off-by: Sasha Levin --- sound/pci/hda/hda_beep.c | 15 +++++++++++++-- sound/pci/hda/hda_beep.h | 1 + sound/pci/hda/patch_sigmatel.c | 25 ++----------------------- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/sound/pci/hda/hda_beep.c b/sound/pci/hda/hda_beep.c index c6e1e03a5e4d..5a50b6c1d604 100644 --- a/sound/pci/hda/hda_beep.c +++ b/sound/pci/hda/hda_beep.c @@ -118,6 +118,12 @@ static int snd_hda_beep_event(struct input_dev *dev, unsigned int type, return 0; } +static void turn_on_beep(struct hda_beep *beep) +{ + if (beep->keep_power_at_enable) + snd_hda_power_up_pm(beep->codec); +} + static void turn_off_beep(struct hda_beep *beep) { cancel_work_sync(&beep->beep_work); @@ -125,6 +131,8 @@ static void turn_off_beep(struct hda_beep *beep) /* turn off beep */ generate_tone(beep, 0); } + if (beep->keep_power_at_enable) + snd_hda_power_down_pm(beep->codec); } /** @@ -140,7 +148,9 @@ int snd_hda_enable_beep_device(struct hda_codec *codec, int enable) enable = !!enable; if (beep->enabled != enable) { beep->enabled = enable; - if (!enable) + if (enable) + turn_on_beep(beep); + else turn_off_beep(beep); return 1; } @@ -167,7 +177,8 @@ static int beep_dev_disconnect(struct snd_device *device) input_unregister_device(beep->dev); else input_free_device(beep->dev); - turn_off_beep(beep); + if (beep->enabled) + turn_off_beep(beep); return 0; } diff --git a/sound/pci/hda/hda_beep.h b/sound/pci/hda/hda_beep.h index a25358a4807a..db76e3ddba65 100644 --- a/sound/pci/hda/hda_beep.h +++ b/sound/pci/hda/hda_beep.h @@ -25,6 +25,7 @@ struct hda_beep { unsigned int enabled:1; unsigned int linear_tone:1; /* linear tone for IDT/STAC codec */ unsigned int playing:1; + unsigned int keep_power_at_enable:1; /* set by driver */ struct work_struct beep_work; /* scheduled task for beep event */ struct mutex mutex; void (*power_hook)(struct hda_beep *beep, bool on); diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c index 04a89171327d..e42a6c5c1ba3 100644 --- a/sound/pci/hda/patch_sigmatel.c +++ b/sound/pci/hda/patch_sigmatel.c @@ -4302,6 +4302,8 @@ static int stac_parse_auto_config(struct hda_codec *codec) if (codec->beep) { /* IDT/STAC codecs have linear beep tone parameter */ codec->beep->linear_tone = spec->linear_tone_beep; + /* keep power up while beep is enabled */ + codec->beep->keep_power_at_enable = 1; /* if no beep switch is available, make its own one */ caps = query_amp_caps(codec, nid, HDA_OUTPUT); if (!(caps & AC_AMPCAP_MUTE)) { @@ -4442,28 +4444,6 @@ static int stac_suspend(struct hda_codec *codec) stac_shutup(codec); return 0; } - -static int stac_check_power_status(struct hda_codec *codec, hda_nid_t nid) -{ -#ifdef CONFIG_SND_HDA_INPUT_BEEP - struct sigmatel_spec *spec = codec->spec; -#endif - int ret = snd_hda_gen_check_power_status(codec, nid); - -#ifdef CONFIG_SND_HDA_INPUT_BEEP - if (nid == spec->gen.beep_nid && codec->beep) { - if (codec->beep->enabled != spec->beep_power_on) { - spec->beep_power_on = codec->beep->enabled; - if (spec->beep_power_on) - snd_hda_power_up_pm(codec); - else - snd_hda_power_down_pm(codec); - } - ret |= spec->beep_power_on; - } -#endif - return ret; -} #else #define stac_suspend NULL #endif /* CONFIG_PM */ @@ -4476,7 +4456,6 @@ static const struct hda_codec_ops stac_patch_ops = { .unsol_event = snd_hda_jack_unsol_event, #ifdef CONFIG_PM .suspend = stac_suspend, - .check_power_status = stac_check_power_status, #endif .reboot_notify = stac_shutup, };