Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm: panel-backlight-quirks: Convert brightness quirk to generic structure

Currently, the brightness quirk is limited to minimum brightness only.
Refactor it to a structure, so that more quirks can be added in the
future. Reserve 0 value for "no quirk", and use u16 to allow minimum
brightness up to 255.

Tested-by: Philip Müller <philm@manjaro.org>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Antheas Kapenekakis <lkml@antheas.dev>
Link: https://lore.kernel.org/r/20250829145541.512671-3-lkml@antheas.dev
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Mario Limonciello (AMD) <superm1@kernel.org>

authored by

Antheas Kapenekakis and committed by
Mario Limonciello (AMD)
6eee1ef9 9931e4be

+35 -25
+8 -4
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
··· 3612 3612 3613 3613 static void update_connector_ext_caps(struct amdgpu_dm_connector *aconnector) 3614 3614 { 3615 + const struct drm_panel_backlight_quirk *panel_backlight_quirk; 3615 3616 struct amdgpu_dm_backlight_caps *caps; 3616 3617 struct drm_connector *conn_base; 3617 3618 struct amdgpu_device *adev; 3618 3619 struct drm_luminance_range_info *luminance_range; 3619 - int min_input_signal_override; 3620 3620 3621 3621 if (aconnector->bl_idx == -1 || 3622 3622 aconnector->dc_link->connector_signal != SIGNAL_TYPE_EDP) ··· 3656 3656 else 3657 3657 caps->aux_min_input_signal = 1; 3658 3658 3659 - min_input_signal_override = drm_get_panel_min_brightness_quirk(aconnector->drm_edid); 3660 - if (min_input_signal_override >= 0) 3661 - caps->min_input_signal = min_input_signal_override; 3659 + panel_backlight_quirk = 3660 + drm_get_panel_backlight_quirk(aconnector->drm_edid); 3661 + if (!IS_ERR_OR_NULL(panel_backlight_quirk)) { 3662 + if (panel_backlight_quirk->min_brightness) 3663 + caps->min_input_signal = 3664 + panel_backlight_quirk->min_brightness - 1; 3665 + } 3662 3666 } 3663 3667 3664 3668 DEFINE_FREE(sink_release, struct dc_sink *, if (_T) dc_sink_release(_T))
+21 -20
drivers/gpu/drm/drm_panel_backlight_quirks.c
··· 8 8 #include <drm/drm_edid.h> 9 9 #include <drm/drm_utils.h> 10 10 11 - struct drm_panel_min_backlight_quirk { 11 + struct drm_get_panel_backlight_quirk { 12 12 struct { 13 13 enum dmi_field field; 14 14 const char * const value; 15 15 } dmi_match; 16 16 struct drm_edid_ident ident; 17 - u8 min_brightness; 17 + struct drm_panel_backlight_quirk quirk; 18 18 }; 19 19 20 - static const struct drm_panel_min_backlight_quirk drm_panel_min_backlight_quirks[] = { 20 + static const struct drm_get_panel_backlight_quirk drm_panel_min_backlight_quirks[] = { 21 21 /* 13 inch matte panel */ 22 22 { 23 23 .dmi_match.field = DMI_BOARD_VENDOR, 24 24 .dmi_match.value = "Framework", 25 25 .ident.panel_id = drm_edid_encode_panel_id('B', 'O', 'E', 0x0bca), 26 26 .ident.name = "NE135FBM-N41", 27 - .min_brightness = 0, 27 + .quirk = { .min_brightness = 1, }, 28 28 }, 29 29 /* 13 inch glossy panel */ 30 30 { ··· 32 32 .dmi_match.value = "Framework", 33 33 .ident.panel_id = drm_edid_encode_panel_id('B', 'O', 'E', 0x095f), 34 34 .ident.name = "NE135FBM-N41", 35 - .min_brightness = 0, 35 + .quirk = { .min_brightness = 1, }, 36 36 }, 37 37 /* 13 inch 2.8k panel */ 38 38 { ··· 40 40 .dmi_match.value = "Framework", 41 41 .ident.panel_id = drm_edid_encode_panel_id('B', 'O', 'E', 0x0cb4), 42 42 .ident.name = "NE135A1M-NY1", 43 - .min_brightness = 0, 43 + .quirk = { .min_brightness = 1, }, 44 44 }, 45 45 }; 46 46 47 - static bool drm_panel_min_backlight_quirk_matches(const struct drm_panel_min_backlight_quirk *quirk, 48 - const struct drm_edid *edid) 47 + static bool drm_panel_min_backlight_quirk_matches( 48 + const struct drm_get_panel_backlight_quirk *quirk, 49 + const struct drm_edid *edid) 49 50 { 50 51 if (!dmi_match(quirk->dmi_match.field, quirk->dmi_match.value)) 51 52 return false; ··· 58 57 } 59 58 60 59 /** 61 - * drm_get_panel_min_brightness_quirk - Get minimum supported brightness level for a panel. 60 + * drm_get_panel_backlight_quirk - Get backlight quirks for a panel 62 61 * @edid: EDID of the panel to check 63 62 * 64 63 * This function checks for platform specific (e.g. DMI based) quirks 65 64 * providing info on the minimum backlight brightness for systems where this 66 - * cannot be probed correctly from the hard-/firm-ware. 65 + * cannot be probed correctly from the hard-/firm-ware and other sources. 67 66 * 68 67 * Returns: 69 - * A negative error value or 70 - * an override value in the range [0, 255] representing 0-100% to be scaled to 71 - * the drivers target range. 68 + * a drm_panel_backlight_quirk struct if a quirk was found, otherwise an 69 + * error pointer. 72 70 */ 73 - int drm_get_panel_min_brightness_quirk(const struct drm_edid *edid) 71 + const struct drm_panel_backlight_quirk * 72 + drm_get_panel_backlight_quirk(const struct drm_edid *edid) 74 73 { 75 - const struct drm_panel_min_backlight_quirk *quirk; 74 + const struct drm_get_panel_backlight_quirk *quirk; 76 75 size_t i; 77 76 78 77 if (!IS_ENABLED(CONFIG_DMI)) 79 - return -ENODATA; 78 + return ERR_PTR(-ENODATA); 80 79 81 80 if (!edid) 82 - return -EINVAL; 81 + return ERR_PTR(-EINVAL); 83 82 84 83 for (i = 0; i < ARRAY_SIZE(drm_panel_min_backlight_quirks); i++) { 85 84 quirk = &drm_panel_min_backlight_quirks[i]; 86 85 87 86 if (drm_panel_min_backlight_quirk_matches(quirk, edid)) 88 - return quirk->min_brightness; 87 + return &quirk->quirk; 89 88 } 90 89 91 - return -ENODATA; 90 + return ERR_PTR(-ENODATA); 92 91 } 93 - EXPORT_SYMBOL(drm_get_panel_min_brightness_quirk); 92 + EXPORT_SYMBOL(drm_get_panel_backlight_quirk); 94 93 95 94 MODULE_DESCRIPTION("Quirks for panel backlight overrides"); 96 95 MODULE_LICENSE("GPL");
+6 -1
include/drm/drm_utils.h
··· 16 16 17 17 int drm_get_panel_orientation_quirk(int width, int height); 18 18 19 - int drm_get_panel_min_brightness_quirk(const struct drm_edid *edid); 19 + struct drm_panel_backlight_quirk { 20 + u16 min_brightness; 21 + }; 22 + 23 + const struct drm_panel_backlight_quirk * 24 + drm_get_panel_backlight_quirk(const struct drm_edid *edid); 20 25 21 26 signed long drm_timeout_abs_to_jiffies(int64_t timeout_nsec); 22 27