From patchwork Thu Apr 27 07:41:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1774364 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=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=e4Ut8ODn; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (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 4Q6SNg3gtlz23vH for ; Thu, 27 Apr 2023 17:41:38 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1prwFq-0007k1-Iu; Thu, 27 Apr 2023 07:41:26 +0000 Received: from mail-pg1-f176.google.com ([209.85.215.176]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1prwFn-0007jS-E1 for kernel-team@lists.ubuntu.com; Thu, 27 Apr 2023 07:41:23 +0000 Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-51f1b6e8179so5833277a12.3 for ; Thu, 27 Apr 2023 00:41:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682581281; x=1685173281; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=sEko8d0udnprFbFkWA/Ah7iSSalmKqsTqKIkqubj7S8=; b=e4Ut8ODnD55rL1YWCetaoIKHTszgssA3hJDxAbtFOE9112Q8zLMQuVqijO3L801o+6 TGharyWb874L2VCfd3M7T9aj3giiWntT9oP5rIPuI/BEjbxgxJuQ3Vx0WwxEonnH0IXZ aEjzLDN+ebU/N8wiTmGY2Hz6SiuPnTbIM92prB4c8nJuoOjEl84x+36bYvyZMb7MkWpb qXHiFW6XjzsrnpY8lyNHF+GjAAC8clX+YyLpEPPc+yqck7JuJqiF/vCjDXRw484Vfxgl fcKc70dfPw8T1LYNiGv2kEmr2CDOMzyFuFQZjmXo3eCyrgaSxFjXyiyynbWQjBhi/Aun 0uXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682581281; x=1685173281; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:sender:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=sEko8d0udnprFbFkWA/Ah7iSSalmKqsTqKIkqubj7S8=; b=ih7IN/HBaYc5PcbU5AGdU3BEDo0CLRMojpbrj1VeI/4Ku6tt6BirjObgMWPlD2AVin XfHsBahE+ac42d8176N7aKRSCwKam5sDpjhgkgoqUwSxQBnzUsfd6ERQ5BlQsd8t6c1Y FQLVLz4PVn2sTVZX7ZrN+/6jG45zHR8GQnTDrNv81t795+KK36rmnSN5v2LhASGt0TkB xJ86QM1Lc9XwAXbQOeG8JGbQdk1sfMkKImUXxE0scvbpRxJwlGqubZry34ckcZfTFQhZ QcP6k+4WMSygMY01w81nmtWPSweyHrCzWVMErrpyuUKOUKxhNVymQNTbgIQ8l8K2/Jgk O7Ug== X-Gm-Message-State: AC+VfDw/91RU9RqsL4lVxTcZQbSkrDq7BTQGZWFo2HNonpkshQ/DRo4t lwAkX1ctmFZgGfa17tAv6UdQbcYRpbPWcg== X-Google-Smtp-Source: ACHHUZ7aPts8SzCMo28DMWCufF20iy5QxJrg5/+07e1S42qNAyQIhPGUF4FgKYN7m/OJ2JNU+TnGcw== X-Received: by 2002:a05:6a20:d690:b0:f2:fcba:7872 with SMTP id it16-20020a056a20d69000b000f2fcba7872mr751396pzb.28.1682581281153; Thu, 27 Apr 2023 00:41:21 -0700 (PDT) Received: from localhost (220-135-95-34.hinet-ip.hinet.net. [220.135.95.34]) by smtp.gmail.com with ESMTPSA id t65-20020a628144000000b0063b8b8580a7sm12396519pfd.29.2023.04.27.00.41.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 00:41:20 -0700 (PDT) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/6][SRU][OEM-6.0] ACPI: video: Add acpi_video_backlight_use_native() helper Date: Thu, 27 Apr 2023 15:41:11 +0800 Message-Id: <20230427074116.188543-2-acelan.kao@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230427074116.188543-1-acelan.kao@canonical.com> References: <20230427074116.188543-1-acelan.kao@canonical.com> MIME-Version: 1.0 Received-SPF: pass client-ip=209.85.215.176; envelope-from=acelan@gmail.com; helo=mail-pg1-f176.google.com 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: Hans de Goede BugLink: https://launchpad.net/bugs/2017774 ATM on x86 laptops where we want userspace to use the acpi_video backlight device we often register both the GPU's native backlight device and acpi_video's firmware acpi_video# backlight device. This relies on userspace preferring firmware type backlight devices over native ones, but registering 2 backlight devices for a single display really is undesirable. On x86 laptops where the native GPU backlight device should be used, the registering of other backlight devices is avoided by their drivers using acpi_video_get_backlight_type() and only registering their backlight if the return value matches their type. acpi_video_get_backlight_type() uses backlight_device_get_by_type(BACKLIGHT_RAW) to determine if a native driver is available and will never return native if this returns false. This means that the GPU's native backlight registering code cannot just call acpi_video_get_backlight_type() to determine if it should register its backlight, since acpi_video_get_backlight_type() will never return native until the native backlight has already registered. To fix this add a new internal native function parameter to acpi_video_get_backlight_type(), which when set to true will make acpi_video_get_backlight_type() behave as if a native backlight has already been registered. And add a new acpi_video_backlight_use_native() helper, which sets this to true, for use in native GPU backlight code. Changes in v2: - Replace adding a native parameter to acpi_video_get_backlight_type() with adding a new acpi_video_backlight_use_native() helper. Acked-by: Rafael J. Wysocki Signed-off-by: Hans de Goede (cherry picked from commit 2600bfa3df9944562d43d1f17016832a6ffa3b38) Signed-off-by: Chia-Lin Kao (AceLan) --- drivers/acpi/video_detect.c | 24 ++++++++++++++++++++---- include/acpi/video.h | 5 +++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/drivers/acpi/video_detect.c b/drivers/acpi/video_detect.c index 68a566f69684..5f620054bff4 100644 --- a/drivers/acpi/video_detect.c +++ b/drivers/acpi/video_detect.c @@ -17,8 +17,9 @@ * Otherwise vendor specific drivers like thinkpad_acpi, asus-laptop, * sony_acpi,... can take care about backlight brightness. * - * Backlight drivers can use acpi_video_get_backlight_type() to determine - * which driver should handle the backlight. + * Backlight drivers can use acpi_video_get_backlight_type() to determine which + * driver should handle the backlight. RAW/GPU-driver backlight drivers must + * use the acpi_video_backlight_use_native() helper for this. * * If CONFIG_ACPI_VIDEO is neither set as "compiled in" (y) nor as a module (m) * this file will not be compiled and acpi_video_get_backlight_type() will @@ -635,9 +636,10 @@ static int acpi_video_backlight_notify(struct notifier_block *nb, * Arguably the native on win8 check should be done first, but that would * be a behavior change, which may causes issues. */ -enum acpi_backlight_type acpi_video_get_backlight_type(void) +static enum acpi_backlight_type __acpi_video_get_backlight_type(bool native) { static DEFINE_MUTEX(init_mutex); + static bool native_available; static bool init_done; static long video_caps; @@ -657,6 +659,8 @@ enum acpi_backlight_type acpi_video_get_backlight_type(void) backlight_notifier_registered = true; init_done = true; } + if (native) + native_available = true; mutex_unlock(&init_mutex); if (acpi_backlight_cmdline != acpi_backlight_undef) @@ -668,13 +672,25 @@ enum acpi_backlight_type acpi_video_get_backlight_type(void) if (!(video_caps & ACPI_VIDEO_BACKLIGHT)) return acpi_backlight_vendor; - if (acpi_osi_is_win8() && backlight_device_get_by_type(BACKLIGHT_RAW)) + if (acpi_osi_is_win8() && + (native_available || backlight_device_get_by_type(BACKLIGHT_RAW))) return acpi_backlight_native; return acpi_backlight_video; } + +enum acpi_backlight_type acpi_video_get_backlight_type(void) +{ + return __acpi_video_get_backlight_type(false); +} EXPORT_SYMBOL(acpi_video_get_backlight_type); +bool acpi_video_backlight_use_native(void) +{ + return __acpi_video_get_backlight_type(true) == acpi_backlight_native; +} +EXPORT_SYMBOL(acpi_video_backlight_use_native); + /* * Set the preferred backlight interface type based on DMI info. * This function allows DMI blacklists to be implemented by external diff --git a/include/acpi/video.h b/include/acpi/video.h index db8548ff03ce..4705e339c252 100644 --- a/include/acpi/video.h +++ b/include/acpi/video.h @@ -56,6 +56,7 @@ extern void acpi_video_unregister(void); extern int acpi_video_get_edid(struct acpi_device *device, int type, int device_id, void **edid); extern enum acpi_backlight_type acpi_video_get_backlight_type(void); +extern bool acpi_video_backlight_use_native(void); extern void acpi_video_set_dmi_backlight_type(enum acpi_backlight_type type); /* * Note: The value returned by acpi_video_handles_brightness_key_presses() @@ -77,6 +78,10 @@ static inline enum acpi_backlight_type acpi_video_get_backlight_type(void) { return acpi_backlight_vendor; } +static inline bool acpi_video_backlight_use_native(void) +{ + return true; +} static inline void acpi_video_set_dmi_backlight_type(enum acpi_backlight_type type) { }