From patchwork Thu Apr 27 07:41:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AceLan Kao X-Patchwork-Id: 1774365 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=kc7llVwq; 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 4Q6SNg5Fd3z23vL for ; Thu, 27 Apr 2023 17:41:39 +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 1prwFw-0007ns-76; Thu, 27 Apr 2023 07:41:32 +0000 Received: from mail-pl1-f170.google.com ([209.85.214.170]) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1prwFs-0007kD-0k for kernel-team@lists.ubuntu.com; Thu, 27 Apr 2023 07:41:28 +0000 Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1a95aef9885so41147255ad.1 for ; Thu, 27 Apr 2023 00:41:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682581286; x=1685173286; 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=DHKoGkeafx/fLLOGmlQGB8WlpnlrLVFMVTsyValzMqM=; b=kc7llVwqxQ3rT1NMiXXwCMTHc7bG7YV6MfuXvxHhAglw53fjFphfz7JjICS9Qjo8jF XzjRT8QTl6SoY9JqZC57h4AZs9DiShcy1n5M2+qDiBEQeOBi09yrdz3UJsEpFZekgd57 B6/4ejiA/Ar9c47Sptjz/sTqKTGH9/pOlSqM8M+frVzSNFFewVCA7imRjyv5WdVnVAEl bFmefQ/aTzFW9oBlX4zhERjxDMiTYpIbOSmur7PBeIhWM2DuV1IwIuuH5f6QjwEMWeBG nwKSxrV7nsuY94JihBNzKicq6fcrNbkspxqrD35cY116TquUP8a7usj+2JxQep2Ene4t tqmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682581286; x=1685173286; 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=DHKoGkeafx/fLLOGmlQGB8WlpnlrLVFMVTsyValzMqM=; b=EG3PAs1ad6jeJd47slaMjKegLviv8kDNrT/wk+5b6Z8qcpc1yC0x00OtFRgfXois8f xYMnaFJDewddurWaGZb0h8xK+l5POlgVakTXnVS/8jz/w7O4gWkiLBk1VkAZBq1RtRob UkXjS0BZeXpoOyhiP99FiyuPSOAuZBtNfMLwPeHYMw+9H/ICGptKP4vOc10pitbNmCvL SWQcEPZ+OSoUu+llwcsoFJYbRJWMu9dugeb2MsNOxZOxaocU94ULFx5V4pwbiqgjVTde uCz1Wtt7GXrO8QBYBb4WGzBd4/88OaoYJagvimR6aT687uNl2je3jStKmr9WMsAAeosK VXQA== X-Gm-Message-State: AC+VfDzEqp5w7Ql9Gl/q0OOvKJexfCb5EgvjLCy1YJNjxX5HN2HyDGuy u9p2inVX4l7YazFE5UZlbmD/fJLPggqq8Q== X-Google-Smtp-Source: ACHHUZ55GM/XKl6zSD5K0+hiBSyiWHUX0XxmPnwWX/u7cMXXf9NCOoJfR8676rKe92K4oA56B/Pung== X-Received: by 2002:a17:902:f155:b0:1a1:b65c:dea7 with SMTP id d21-20020a170902f15500b001a1b65cdea7mr515269plb.47.1682581285823; Thu, 27 Apr 2023 00:41:25 -0700 (PDT) Received: from localhost (220-135-95-34.hinet-ip.hinet.net. [220.135.95.34]) by smtp.gmail.com with ESMTPSA id p17-20020a1709028a9100b001a6cd1e4205sm7923224plo.279.2023.04.27.00.41.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Apr 2023 00:41:25 -0700 (PDT) From: AceLan Kao To: kernel-team@lists.ubuntu.com Subject: [PATCH 3/6][SRU][OEM-6.0] ACPI: video: Refactor acpi_video_get_backlight_type() a bit Date: Thu, 27 Apr 2023 15:41:13 +0800 Message-Id: <20230427074116.188543-4-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.214.170; envelope-from=acelan@gmail.com; helo=mail-pl1-f170.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 Refactor acpi_video_get_backlight_type() so that the heuristics / detection steps are stricly in order of descending precedence. Also move the comments describing the steps to when the various steps are actually done, to avoid the comments getting out of sync with the code. Acked-by: Rafael J. Wysocki Signed-off-by: Hans de Goede (cherry picked from commit b39be9f441f9d7320e6020bdf8ec1522d6c81d1e) Signed-off-by: Chia-Lin Kao (AceLan) --- drivers/acpi/video_detect.c | 39 ++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/drivers/acpi/video_detect.c b/drivers/acpi/video_detect.c index 37c42d671930..110ad1a3b7f0 100644 --- a/drivers/acpi/video_detect.c +++ b/drivers/acpi/video_detect.c @@ -625,16 +625,6 @@ static int acpi_video_backlight_notify(struct notifier_block *nb, /* * Determine which type of backlight interface to use on this system, * First check cmdline, then dmi quirks, then do autodetect. - * - * The autodetect order is: - * 1) Is the acpi-video backlight interface supported -> - * no, use a vendor interface - * 2) Is this a win8 "ready" BIOS and do we have a native interface -> - * yes, use a native interface - * 3) Else use the acpi-video interface - * - * Arguably the native on win8 check should be done first, but that would - * be a behavior change, which may causes issues. */ static enum acpi_backlight_type __acpi_video_get_backlight_type(bool native) { @@ -663,19 +653,36 @@ static enum acpi_backlight_type __acpi_video_get_backlight_type(bool native) native_available = true; mutex_unlock(&init_mutex); + /* + * The below heuristics / detection steps are in order of descending + * presedence. The commandline takes presedence over anything else. + */ if (acpi_backlight_cmdline != acpi_backlight_undef) return acpi_backlight_cmdline; + /* DMI quirks override any autodetection. */ if (acpi_backlight_dmi != acpi_backlight_undef) return acpi_backlight_dmi; - if (!(video_caps & ACPI_VIDEO_BACKLIGHT)) - return acpi_backlight_vendor; - - if (acpi_osi_is_win8() && native_available) - return acpi_backlight_native; + /* On systems with ACPI video use either native or ACPI video. */ + if (video_caps & ACPI_VIDEO_BACKLIGHT) { + /* + * Windows 8 and newer no longer use the ACPI video interface, + * so it often does not work. If the ACPI tables are written + * for win8 and native brightness ctl is available, use that. + * + * The native check deliberately is inside the if acpi-video + * block on older devices without acpi-video support native + * is usually not the best choice. + */ + if (acpi_osi_is_win8() && native_available) + return acpi_backlight_native; + else + return acpi_backlight_video; + } - return acpi_backlight_video; + /* No ACPI video (old hw), use vendor specific fw methods. */ + return acpi_backlight_vendor; } enum acpi_backlight_type acpi_video_get_backlight_type(void)