From patchwork Tue Nov 21 12:28:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Chiu X-Patchwork-Id: 1866714 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4SZNwB52ccz1ySW for ; Tue, 21 Nov 2023 23:28:57 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1r5Ps1-0004qf-NW; Tue, 21 Nov 2023 12:28:49 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1r5Prw-0004pS-Td for kernel-team@lists.ubuntu.com; Tue, 21 Nov 2023 12:28:45 +0000 Received: from mail-pf1-f200.google.com (mail-pf1-f200.google.com [209.85.210.200]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 7957C3F6E7 for ; Tue, 21 Nov 2023 12:28:44 +0000 (UTC) Received: by mail-pf1-f200.google.com with SMTP id d2e1a72fcca58-6b5cac99d3dso8450859b3a.2 for ; Tue, 21 Nov 2023 04:28:44 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700569723; x=1701174523; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ehUWyNwkoisKjOWc8HvnmMeIOJEcjUE/6JpZXs6f4Ek=; b=mLPxTMjOB3vvcnXtDkK/0HD1Vl5BdBCWHNSMwaapc81VgHqmuSpNxFnf5k9NigN5sN u6RxklZlJW3NLhliMPxGniQTEOJBoroD/TokuCLBDdS0uuDG4I2LJwkNCFayI2ESyjQH 2toq1/+4x6xmJizcRNlQKgqbGbHFiOCoAtj5zxxKz1vwwbf0nCkqYbWS+aM9dE5PboNw lyQ+QGA2U7JciG/nNJdhWmC5WoMVvXZ1zDm8O5Woj5ynGXONmw/ck1vCAvum3B9kkAbW gTaPSYJf+RjM+U+h652G4e8AZj6Ya3NyWUsPULkrxNAqaJcfuuUPZLQkhlM0nsTyNcQP qw3Q== X-Gm-Message-State: AOJu0YwfAB6ncErQzBP3OZ36/ZjPRluU3jwDJIeOK23FL4Po8/15Ctoc 1Y2vFSMbcpOWjDao67DkGxrqnLa4zScxGpVoQsy5pflM17GI2ktoujeIPS3z7z+4Z5xk21pZyuk Wp1/babIUe04DSkEEls9tuABWdT1KR1LKv6pjd3lh4kPrc6UGxg== X-Received: by 2002:a05:6a00:3a09:b0:6cb:a1a7:ebcb with SMTP id fj9-20020a056a003a0900b006cba1a7ebcbmr6945085pfb.24.1700569722850; Tue, 21 Nov 2023 04:28:42 -0800 (PST) X-Google-Smtp-Source: AGHT+IH/a6YC+zzNO5SqFk0UkfN/LTaIyoyec1/c4r8sj7KdX7Q0CyuTkNjrsDIeH50VZ7Hb//+22Q== X-Received: by 2002:a05:6a00:3a09:b0:6cb:a1a7:ebcb with SMTP id fj9-20020a056a003a0900b006cba1a7ebcbmr6945062pfb.24.1700569722425; Tue, 21 Nov 2023 04:28:42 -0800 (PST) Received: from localhost.localdomain (114-36-219-155.dynamic-ip.hinet.net. [114.36.219.155]) by smtp.gmail.com with ESMTPSA id o12-20020a056a00214c00b006c34015a8f2sm8006096pfk.146.2023.11.21.04.28.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Nov 2023 04:28:42 -0800 (PST) From: Chris Chiu To: kernel-team@lists.ubuntu.com Subject: [PATCH 4/6][SRU][M] ALSA: hda/realtek: Support ACPI Notification framework via component binding Date: Tue, 21 Nov 2023 20:28:31 +0800 Message-Id: <20231121122833.11493-5-chris.chiu@canonical.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231121122833.11493-1-chris.chiu@canonical.com> References: <20231121122833.11493-1-chris.chiu@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Stefan Binding BugLink: https://bugs.launchpad.net/bugs/2039151 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 Link: https://lore.kernel.org/r/20230921162849.1988124-3-sbinding@opensource.cirrus.com Signed-off-by: Takashi Iwai (cherry picked from commit 7ce669334c55c50ecc2909c42275a3eec0039799) Signed-off-by: Chris Chiu --- 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 c79d25ca8d16..d93deb78e3f5 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 @@ -6688,12 +6689,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) @@ -6701,6 +6781,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); }