Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2431819rdb; Thu, 21 Sep 2023 20:19:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHeSKS1CTfArPB05Kpnzb1DtKoHQsd8phJDm9fMOxca4sEcVaX/yYbrNtKcSz6qMwcd5FJ3 X-Received: by 2002:a05:6a20:8e01:b0:13f:c40c:379 with SMTP id y1-20020a056a208e0100b0013fc40c0379mr9455833pzj.13.1695352775961; Thu, 21 Sep 2023 20:19:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695352775; cv=none; d=google.com; s=arc-20160816; b=z5pLg1GFIAPDeS9Gorwz91JXPJlbp2QM3Zcw62a6cPPf3fMI8zF/2zd9GSd9YgNgoL KDrhzk02ijAVmFjSnrdDKEi+NIQJUgFcjRRD+ZEnrPkh15dXEKy/4V31KJh6eexSLX7H krSebY6wyh2YWbAVCxFxxOD2OcfAetCNZh4Oi/BQkeKBLsURN/AvOmZHZq8MD4+UaR7l 3YqjRKkX8FA30QpUwDt7DuG/HTdI2z5wcZlL8aZlOB1XWslN+vi2ruEUHoRktqQ0w9nv huzJaDVp8ESCX+RiDX4tmyL8sWKP+a5v3h10MdAOuCyfYGZW0NE6xD6l33ThWAzdEsNS l1tg== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=p1Png+N6iCp2Y9Samkt3Ejdu6Hik57jvhh5dG+CbAjM=; fh=w0YUzQ46fBcI9TSX4/vlEjRtiHb0kiqukhFXye02PR8=; b=QlgU/pwGTlJSbiMlZuYuo4jlYYngAcUVGHCuUpK5QwJ3WbLfW0uuieU/YWhrkVP3tb jDTy4oVxRXVpXqua9hhc2C5jdlbKiVZxyk0jbH0rmSvWOfXumNTYGzmMUBW1w8RqKN0W yE+11h+T4yAiipFIoO0fo7VOfGl/sQlTHkXAg990kyOm7//DPUFA1RwdwaE/Q+TAqgn4 cIjYe8c1bSZMqi04q3Bx8upQEZHzUWTYVVzNuaYKplRvhXp6HNiRP0Z7crrZ6uCpxDbd VXjbNXm7NZ3pNSpH80OTW9WeIL9Y7bjOVXsVq9LAeK6CWBuN84yMiUkjO1ay5mb8zRxb knwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=XtkFuL0F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id cp1-20020a170902e78100b001bbac6722e6si2693301plb.371.2023.09.21.20.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Sep 2023 20:19:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b=XtkFuL0F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id DEB168377245; Thu, 21 Sep 2023 14:09:21 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231572AbjIUVHu (ORCPT + 99 others); Thu, 21 Sep 2023 17:07:50 -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: 8bit Content-Type: text/plain X-Proofpoint-GUID: Mj6zCoeq71EVG4BdInqjfA3StwOxbG4x X-Proofpoint-ORIG-GUID: Mj6zCoeq71EVG4BdInqjfA3StwOxbG4x X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:09:22 -0700 (PDT) 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 */ +#include #include #include #include @@ -6704,12 +6705,91 @@ static void alc287_fixup_legion_15imhg05_speakers(struct hda_codec *codec, } } +#ifdef CONFIG_ACPI +static void comp_acpi_device_notify(acpi_handle handle, u32 event, void *data) +{ + struct hda_codec *cdc = data; + struct alc_spec *spec = cdc->spec; + int i; + + codec_info(cdc, "ACPI Notification %d\n", event); + + for (i = 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), event, + spec->comps[i].dev); + } +} + +static int comp_bind_acpi(struct device *dev) +{ + struct hda_codec *cdc = dev_to_hda_codec(dev); + struct alc_spec *spec = cdc->spec; + bool support_notifications = false; + struct acpi_device *adev; + int ret; + int i; + + adev = spec->comps[0].adev; + if (!acpi_device_handle(adev)) + return 0; + + for (i = 0; i < HDA_MAX_COMPONENTS; i++) + support_notifications = support_notifications || + spec->comps[i].acpi_notifications_supported; + + if (support_notifications) { + ret = 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 = dev_to_hda_codec(dev); + struct alc_spec *spec = cdc->spec; + struct acpi_device *adev; + int ret; + + adev = spec->comps[0].adev; + if (!acpi_device_handle(adev)) + return; + + ret = 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 = dev_to_hda_codec(dev); struct alc_spec *spec = cdc->spec; + int ret; + + ret = component_bind_all(dev, spec->comps); + if (ret) + return ret; - return component_bind_all(dev, spec->comps); + return comp_bind_acpi(dev); } static void comp_unbind(struct device *dev) @@ -6717,6 +6797,7 @@ static void comp_unbind(struct device *dev) struct hda_codec *cdc = dev_to_hda_codec(dev); struct alc_spec *spec = cdc->spec; + comp_unbind_acpi(dev); component_unbind_all(dev, spec->comps); } -- 2.34.1