From nobody Thu Sep 19 01:20:50 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFA28E7D0AB for ; Thu, 21 Sep 2023 21:07:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231831AbjIUVHv (ORCPT ); Thu, 21 Sep 2023 17:07:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232421AbjIUVHY (ORCPT ); Thu, 21 Sep 2023 17:07:24 -0400 Received: from mx0b-001ae601.pphosted.com (mx0b-001ae601.pphosted.com [67.231.152.168]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED33724880 for ; Thu, 21 Sep 2023 10:22:48 -0700 (PDT) Received: from pps.filterd (m0077474.ppops.net [127.0.0.1]) by mx0b-001ae601.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 38LFWYi5009262; Thu, 21 Sep 2023 11:28:59 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= PODMain02222019; bh=p1Png+N6iCp2Y9Samkt3Ejdu6Hik57jvhh5dG+CbAjM=; b= XtkFuL0FgfGYDd00xhJV05PLOISiBVx4X8LuRXiHgyc6BWObLVeQ3gxDyqOxbwRA 1U9Iem3JyuJQEumfpXnjqh6lmSx6KAG34PKrpK0OLj3ZzovAYpLWsfGmqadfWf1T eRjsYAskD04TLwVAiP2aoyZ3I8s6GMWMFk09xS3PUva2E27w3pWZsfGmRgCA8U7I 4AxJz9l673DYkbD7PwlIEYUEXF+44Fk93SamPysnYqZ/Xk437UvSZuE94j8Zamf4 xzymLTStzAAmpM9CqanBE/0rDs5YGLK/cTL7uwurEhnpCLqALPDsSTrPTdVXz/Ry TfI2QW7kz69cSkQhnjUEoQ== Received: from ediex02.ad.cirrus.com ([84.19.233.68]) by mx0b-001ae601.pphosted.com (PPS) with ESMTPS id 3t58shx0ab-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 11:28:59 -0500 (CDT) Received: from ediex01.ad.cirrus.com (198.61.84.80) by ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.37; Thu, 21 Sep 2023 17:28:57 +0100 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server id 15.2.1118.37 via Frontend Transport; Thu, 21 Sep 2023 17:28:57 +0100 Received: from sbinding-cirrus-dsktp2.ad.cirrus.com (unknown [198.90.238.135]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 3D47B15B9; Thu, 21 Sep 2023 16:28:57 +0000 (UTC) From: Stefan Binding To: Jaroslav Kysela , Takashi Iwai CC: , , , Stefan Binding Subject: [PATCH v5 2/4] ALSA: hda/realtek: Support ACPI Notification framework via component binding Date: Thu, 21 Sep 2023 17:28:47 +0100 Message-ID: <20230921162849.1988124-3-sbinding@opensource.cirrus.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230921162849.1988124-1-sbinding@opensource.cirrus.com> References: <20230921162849.1988124-1-sbinding@opensource.cirrus.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-GUID: Mj6zCoeq71EVG4BdInqjfA3StwOxbG4x X-Proofpoint-ORIG-GUID: Mj6zCoeq71EVG4BdInqjfA3StwOxbG4x X-Proofpoint-Spam-Reason: safe Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" For systems which have support for ACPI notifications, add a mechanism to register a handler for ACPI notifications and then call the acpi_notify api on the bound components. Registering a handler in the Realtek HDA driver, allows a single handler to be registered, which then calls into all the components, rather than attempting to register the same handler multiple times, once for each component. Signed-off-by: Stefan Binding --- sound/pci/hda/patch_realtek.c | 83 ++++++++++++++++++++++++++++++++++- 1 file changed, 82 insertions(+), 1 deletion(-) diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c index 883a7e865bc5..1e2b6a299dbc 100644 --- a/sound/pci/hda/patch_realtek.c +++ b/sound/pci/hda/patch_realtek.c @@ -10,6 +10,7 @@ * Jonathan Woithe */ =20 +#include #include #include #include @@ -6704,12 +6705,91 @@ static void alc287_fixup_legion_15imhg05_speakers(s= truct hda_codec *codec, } } =20 +#ifdef CONFIG_ACPI +static void comp_acpi_device_notify(acpi_handle handle, u32 event, void *d= ata) +{ + struct hda_codec *cdc =3D data; + struct alc_spec *spec =3D cdc->spec; + int i; + + codec_info(cdc, "ACPI Notification %d\n", event); + + for (i =3D 0; i < HDA_MAX_COMPONENTS; i++) { + if (spec->comps[i].dev && spec->comps[i].acpi_notify) + spec->comps[i].acpi_notify(acpi_device_handle(spec->comps[i].adev), eve= nt, + spec->comps[i].dev); + } +} + +static int comp_bind_acpi(struct device *dev) +{ + struct hda_codec *cdc =3D dev_to_hda_codec(dev); + struct alc_spec *spec =3D cdc->spec; + bool support_notifications =3D false; + struct acpi_device *adev; + int ret; + int i; + + adev =3D spec->comps[0].adev; + if (!acpi_device_handle(adev)) + return 0; + + for (i =3D 0; i < HDA_MAX_COMPONENTS; i++) + support_notifications =3D support_notifications || + spec->comps[i].acpi_notifications_supported; + + if (support_notifications) { + ret =3D acpi_install_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY, + comp_acpi_device_notify, cdc); + if (ret < 0) { + codec_warn(cdc, "Failed to install notify handler: %d\n", ret); + return 0; + } + + codec_dbg(cdc, "Notify handler installed\n"); + } + + return 0; +} + +static void comp_unbind_acpi(struct device *dev) +{ + struct hda_codec *cdc =3D dev_to_hda_codec(dev); + struct alc_spec *spec =3D cdc->spec; + struct acpi_device *adev; + int ret; + + adev =3D spec->comps[0].adev; + if (!acpi_device_handle(adev)) + return; + + ret =3D acpi_remove_notify_handler(adev->handle, ACPI_DEVICE_NOTIFY, + comp_acpi_device_notify); + if (ret < 0) + codec_warn(cdc, "Failed to uninstall notify handler: %d\n", ret); +} +#else +static int comp_bind_acpi(struct device *dev) +{ + return 0; +} + +static void comp_unbind_acpi(struct device *dev) +{ +} +#endif + static int comp_bind(struct device *dev) { struct hda_codec *cdc =3D dev_to_hda_codec(dev); struct alc_spec *spec =3D cdc->spec; + int ret; + + ret =3D component_bind_all(dev, spec->comps); + if (ret) + return ret; =20 - return component_bind_all(dev, spec->comps); + return comp_bind_acpi(dev); } =20 static void comp_unbind(struct device *dev) @@ -6717,6 +6797,7 @@ static void comp_unbind(struct device *dev) struct hda_codec *cdc =3D dev_to_hda_codec(dev); struct alc_spec *spec =3D cdc->spec; =20 + comp_unbind_acpi(dev); component_unbind_all(dev, spec->comps); } =20 --=20 2.34.1