From patchwork Sun Jun 23 08:51:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13708531 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 316B1C27C4F for ; Sun, 23 Jun 2024 08:51:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C1EC910E187; Sun, 23 Jun 2024 08:51:35 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=weissschuh.net header.i=@weissschuh.net header.b="gmudr6v2"; dkim-atps=neutral Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by gabe.freedesktop.org (Postfix) with ESMTPS id AB77910E187; Sun, 23 Jun 2024 08:51:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1719132689; bh=U89xBvF/tNccWlyocvy/F0+d2O1P/5jRg3TgAdYjLq0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=gmudr6v2hsgdWWkFdCfOtDLeVaNc09pZB6JmCf2Myzz2r9Bhlst/R7OeG/c8ZIw+L wnqFLw82rbsDtqUvuN5YC2RsFcnsmEpa317SXaI5WHxK8H2CQzxJl3lTqYIHVgWiDz /QdMfWp5Sfg6AB+VtbWBoHjgu5i+wxW0Lrw17giw= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 23 Jun 2024 10:51:27 +0200 Subject: [PATCH v2 1/3] drm: Add panel backlight quirks MIME-Version: 1.0 Message-Id: <20240623-amdgpu-min-backlight-quirk-v2-1-cecf7f49da9b@weissschuh.net> References: <20240623-amdgpu-min-backlight-quirk-v2-0-cecf7f49da9b@weissschuh.net> In-Reply-To: <20240623-amdgpu-min-backlight-quirk-v2-0-cecf7f49da9b@weissschuh.net> To: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Harry Wentland , Leo Li , Rodrigo Siqueira , Mario Limonciello , Matt Hartley , Kieran Levin , Hans de Goede Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Dustin Howett , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1719132688; l=4963; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=U89xBvF/tNccWlyocvy/F0+d2O1P/5jRg3TgAdYjLq0=; b=j7PdKVU7XA1ADyOGT5eCUR1fny6sQZ0P4ss8CBhBMGm/8qslhxBEOU5lMnzocNkCS3whjtSvz S8mOs42IvHqCAPzKOg63gsrr1V+WBvyH9XdWm379XlQDGOHIz1ifMGv X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Panels using a PWM-controlled backlight source without an do not have a standard way to communicate their valid PWM ranges. On x86 the ranges are read from ACPI through driver-specific tables. The built-in ranges are not necessarily correct, or may grow stale if an older device can be retrofitted with newer panels. Add a quirk infrastructure with which the valid backlight ranges can be maintained as part of the kernel. Signed-off-by: Thomas Weißschuh --- Documentation/gpu/drm-kms-helpers.rst | 3 ++ drivers/gpu/drm/Kconfig | 4 ++ drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/drm_panel_backlight_quirks.c | 67 ++++++++++++++++++++++++++++ include/drm/drm_utils.h | 11 +++++ 5 files changed, 86 insertions(+) diff --git a/Documentation/gpu/drm-kms-helpers.rst b/Documentation/gpu/drm-kms-helpers.rst index 59cfe8a7a8ba..1998a2675210 100644 --- a/Documentation/gpu/drm-kms-helpers.rst +++ b/Documentation/gpu/drm-kms-helpers.rst @@ -224,6 +224,9 @@ Panel Helper Reference .. kernel-doc:: drivers/gpu/drm/drm_panel_orientation_quirks.c :export: +.. kernel-doc:: drivers/gpu/drm/drm_panel_backlight_quirks.c + :export: + Panel Self Refresh Helper Reference =================================== diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 959b19a04101..50ccb43315bf 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -443,6 +443,10 @@ config DRM_EXPORT_FOR_TESTS config DRM_PANEL_ORIENTATION_QUIRKS tristate +# Separate option as not all DRM drivers use it +config DRM_PANEL_BACKLIGHT_QUIRKS + tristate + config DRM_LIB_RANDOM bool default n diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index f9ca4f8fa6c5..6669913b907e 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -92,6 +92,7 @@ drm-$(CONFIG_DRM_PANIC) += drm_panic.o obj-$(CONFIG_DRM) += drm.o obj-$(CONFIG_DRM_PANEL_ORIENTATION_QUIRKS) += drm_panel_orientation_quirks.o +obj-$(CONFIG_DRM_PANEL_BACKLIGHT_QUIRKS) += drm_panel_backlight_quirks.o # # Memory-management helpers diff --git a/drivers/gpu/drm/drm_panel_backlight_quirks.c b/drivers/gpu/drm/drm_panel_backlight_quirks.c new file mode 100644 index 000000000000..a89b5fd1940e --- /dev/null +++ b/drivers/gpu/drm/drm_panel_backlight_quirks.c @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include + +struct drm_panel_backlight_entry { + struct { + enum dmi_field field; + const char * const value; + } dmi_match; + struct drm_edid_ident ident; + struct drm_panel_backlight_quirk quirk; +}; + +static const struct drm_panel_backlight_entry drm_panel_backlight_entries[] = { +}; + +static bool drm_panel_backlight_entry_matches(const struct drm_panel_backlight_entry *entry, + const struct drm_edid *edid) +{ + if (!dmi_match(entry->dmi_match.field, entry->dmi_match.value)) + return false; + + if (!drm_edid_match(edid, &entry->ident)) + return false; + + return true; +} + +/** + * drm_get_panel_panel_quirk - Check for panel backlight quirks + * @edid: EDID of the panel to check + * + * This function checks for platform specific (e.g. DMI based) quirks + * providing info on backlight control for systems where this cannot be + * probed from the hard-/firm-ware. + * + * Returns: + * A struct drm_panel_backlight_quirk if a quirk is found or NULL otherwise. + */ +const struct drm_panel_backlight_quirk *drm_get_panel_backlight_quirk(const struct drm_edid *edid) +{ + const struct drm_panel_backlight_entry *entry; + size_t i; + + if (!IS_ENABLED(CONFIG_DMI)) + return NULL; + + if (!edid) + return NULL; + + for (i = 0; i < ARRAY_SIZE(drm_panel_backlight_entries); i++) { + entry = &drm_panel_backlight_entries[i]; + + if (drm_panel_backlight_entry_matches(entry, edid)) + return &entry->quirk; + } + + return NULL; +} +EXPORT_SYMBOL(drm_get_panel_backlight_quirk); + +MODULE_LICENSE("GPL"); diff --git a/include/drm/drm_utils.h b/include/drm/drm_utils.h index 70775748d243..37cc6de1a01a 100644 --- a/include/drm/drm_utils.h +++ b/include/drm/drm_utils.h @@ -11,9 +11,20 @@ #define __DRM_UTILS_H__ #include +#include + +struct drm_panel_backlight_quirk { + struct { + bool pwm_min_brightness:1; + } overrides; + + u8 pwm_min_brightness; /* min_brightness/255 of max */ +}; int drm_get_panel_orientation_quirk(int width, int height); +const struct drm_panel_backlight_quirk *drm_get_panel_backlight_quirk(const struct drm_edid *edid); + signed long drm_timeout_abs_to_jiffies(int64_t timeout_nsec); #endif From patchwork Sun Jun 23 08:51:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13708533 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4363BC2BA18 for ; Sun, 23 Jun 2024 08:51:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 67BCE10E0FE; Sun, 23 Jun 2024 08:51:47 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=weissschuh.net header.i=@weissschuh.net header.b="p88ZX1vK"; dkim-atps=neutral Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by gabe.freedesktop.org (Postfix) with ESMTPS id B3DC010E1ED; Sun, 23 Jun 2024 08:51:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1719132689; bh=w+SrR5E2JH9+hXfgQFtUFlkQAtNtXTw/JtvQbmbDgI4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=p88ZX1vK0LXjzMv9Cuf3tt6aYObE6RfqxXtI4UUCWNhDlS/8pUHs6gt6TGIhBRyII piUqw4EzgSC5SJzS2SVOXyf+0NvY93HZQ7oeEaMX7hbKY4XRz8tJQPU3qihyA660ls KnFOZBO4EQlpluBZmv5c9qrXmxOo6WA4YYudn7+s= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 23 Jun 2024 10:51:28 +0200 Subject: [PATCH v2 2/3] drm: panel-backlight-quirks: Add Framework 13 matte panel MIME-Version: 1.0 Message-Id: <20240623-amdgpu-min-backlight-quirk-v2-2-cecf7f49da9b@weissschuh.net> References: <20240623-amdgpu-min-backlight-quirk-v2-0-cecf7f49da9b@weissschuh.net> In-Reply-To: <20240623-amdgpu-min-backlight-quirk-v2-0-cecf7f49da9b@weissschuh.net> To: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Harry Wentland , Leo Li , Rodrigo Siqueira , Mario Limonciello , Matt Hartley , Kieran Levin , Hans de Goede Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Dustin Howett , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1719132688; l=1413; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=w+SrR5E2JH9+hXfgQFtUFlkQAtNtXTw/JtvQbmbDgI4=; b=kObTJ0lXuxpRUDitaTT79l1LZGQynamMmqQkggT8nuu6Lxxyrp77H8ph0Vgw7YJBGZJoCCeqI HXJSPX3GUlCBx1Sh4goeIhsBO9tJ0ZcrMWYhTazIoelLw/0UaJwaF/U X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The value of "min_input_signal" returned from ATIF on a Framework AMD 13 is "12". This leads to a fairly bright minimum display backlight. Add a quirk to override that the minimum backlight PWM to "0" which leads to a much lower minimum brightness, which is still visible. Tested on a Framework AMD 13 BIOS 3.05 with the matte panel. Link: https://community.frame.work/t/25711/9 Link: https://community.frame.work/t/47036 Signed-off-by: Thomas Weißschuh --- drivers/gpu/drm/drm_panel_backlight_quirks.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/gpu/drm/drm_panel_backlight_quirks.c b/drivers/gpu/drm/drm_panel_backlight_quirks.c index a89b5fd1940e..e7671b1ba885 100644 --- a/drivers/gpu/drm/drm_panel_backlight_quirks.c +++ b/drivers/gpu/drm/drm_panel_backlight_quirks.c @@ -17,6 +17,15 @@ struct drm_panel_backlight_entry { }; static const struct drm_panel_backlight_entry drm_panel_backlight_entries[] = { + /* 13 inch matte panel */ + { + .dmi_match.field = DMI_BOARD_VENDOR, + .dmi_match.value = "Framework", + .ident.panel_id = drm_edid_encode_panel_id('B', 'O', 'E', 0x0bca), + .ident.name = "NE135FBM-N41", + .quirk.overrides.pwm_min_brightness = true, + .quirk.pwm_min_brightness = 0, + }, }; static bool drm_panel_backlight_entry_matches(const struct drm_panel_backlight_entry *entry, From patchwork Sun Jun 23 08:51:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13708530 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 9B723C27C4F for ; Sun, 23 Jun 2024 08:51:37 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B1B9210E0FA; Sun, 23 Jun 2024 08:51:35 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (1024-bit key; unprotected) header.d=weissschuh.net header.i=@weissschuh.net header.b="T49NgJZI"; dkim-atps=neutral Received: from todd.t-8ch.de (todd.t-8ch.de [159.69.126.157]) by gabe.freedesktop.org (Postfix) with ESMTPS id AF96610E1C0; Sun, 23 Jun 2024 08:51:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=weissschuh.net; s=mail; t=1719132689; bh=rczzmpjjlHlCtAKyfdbQlMnDUcEam5QWSyl/gkZmeUI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=T49NgJZIev0c63fiplfhzGkAuWQ/paHKXJ9+oa1374Ic3GcSGWJf5myt32dEIH1qi 3I/tomzIA9tRVYXA27wN9cxEZb+ye1RpFrC6JixWbFOOf0XIEaIE6+rSkbQ/x9dB2f BrUeKV4j2V9HgBpogKmho4NFjOqmPiJ9jCdr2/vc= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= Date: Sun, 23 Jun 2024 10:51:29 +0200 Subject: [PATCH v2 3/3] drm/amd/display: Add support backlight quirks MIME-Version: 1.0 Message-Id: <20240623-amdgpu-min-backlight-quirk-v2-3-cecf7f49da9b@weissschuh.net> References: <20240623-amdgpu-min-backlight-quirk-v2-0-cecf7f49da9b@weissschuh.net> In-Reply-To: <20240623-amdgpu-min-backlight-quirk-v2-0-cecf7f49da9b@weissschuh.net> To: Alex Deucher , =?utf-8?q?Christian_K=C3=B6nig?= , David Airlie , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Harry Wentland , Leo Li , Rodrigo Siqueira , Mario Limonciello , Matt Hartley , Kieran Levin , Hans de Goede Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Dustin Howett , =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Mailer: b4 0.14.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1719132688; l=2788; i=linux@weissschuh.net; s=20221212; h=from:subject:message-id; bh=rczzmpjjlHlCtAKyfdbQlMnDUcEam5QWSyl/gkZmeUI=; b=91+X03/aUODL2GDH3ZqzK48/y08D6dI+XwyYt1sZeGqua4CMOayPkJrOzc+4B24uRR0caZ7vY ikjqi1dxeVRA9O1UNQHhVY4kjP/r2qXpoz/32Jsw8BJnXBbylFYY6tY X-Developer-Key: i=linux@weissschuh.net; a=ed25519; pk=KcycQgFPX2wGR5azS7RhpBqedglOZVgRPfdFSPB1LNw= X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Not all platforms provide correct PWM backlight capabilities through ATIF. Use the generic drm backlight quirk infrastructure to override the capabilities where necessary. Signed-off-by: Thomas Weißschuh --- drivers/gpu/drm/amd/amdgpu/Kconfig | 1 + drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 28 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/drivers/gpu/drm/amd/amdgpu/Kconfig b/drivers/gpu/drm/amd/amdgpu/Kconfig index 692fa7cf8fd2..4fe0e8e74bb9 100644 --- a/drivers/gpu/drm/amd/amdgpu/Kconfig +++ b/drivers/gpu/drm/amd/amdgpu/Kconfig @@ -25,6 +25,7 @@ config DRM_AMDGPU select DRM_BUDDY select DRM_SUBALLOC_HELPER select DRM_EXEC + select DRM_PANEL_BACKLIGHT_QUIRKS # amdgpu depends on ACPI_VIDEO when ACPI is enabled, for select to work # ACPI_VIDEO's dependencies must also be selected. select INPUT if ACPI diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c index 60404385d4d0..2d8a6d875170 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -93,6 +93,7 @@ #include #include #include +#include #include #include #include @@ -3329,6 +3330,31 @@ static struct drm_mode_config_helper_funcs amdgpu_dm_mode_config_helperfuncs = { .atomic_commit_setup = drm_dp_mst_atomic_setup_commit, }; +static void amdgpu_dm_apply_backlight_quirks(struct amdgpu_dm_connector *aconnector, + struct amdgpu_dm_backlight_caps *caps) +{ + const struct drm_panel_backlight_quirk *quirk; + const struct drm_edid *edid; + + edid = drm_edid_alloc(aconnector->edid, EDID_LENGTH * (aconnector->edid->extensions + 1)); + if (!edid) + return; + + quirk = drm_get_panel_backlight_quirk(edid); + + drm_edid_free(edid); + + if (!quirk) + return; + + if (quirk->overrides.pwm_min_brightness && + caps->min_input_signal != quirk->pwm_min_brightness) { + drm_info(aconnector->base.dev, + "Quirk: backlight min_input_signal=%d\n", quirk->pwm_min_brightness); + caps->min_input_signal = quirk->pwm_min_brightness; + } +} + static void update_connector_ext_caps(struct amdgpu_dm_connector *aconnector) { struct amdgpu_dm_backlight_caps *caps; @@ -3369,6 +3395,8 @@ static void update_connector_ext_caps(struct amdgpu_dm_connector *aconnector) caps->aux_min_input_signal = 0; caps->aux_max_input_signal = 512; } + + amdgpu_dm_apply_backlight_quirks(aconnector, caps); } void amdgpu_dm_update_connector_after_detect(