[PATCH] drm/amd/display: Set default brightness according to ACPI
Alex Deucher
alexdeucher at gmail.com
Fri Jun 7 13:49:31 UTC 2024
On Fri, Jun 7, 2024 at 3:22 AM Mario Limonciello
<mario.limonciello at amd.com> wrote:
>
> Currently, amdgpu will always set up the brightness at 100% when it
> loads. However this is jarring when the BIOS has it previously
> programmed to a much lower value.
>
> The ACPI ATIF method includes two members for "ac_level" and "dc_level".
> These represent the default values that should be used if the system is
> brought up in AC and DC respectively.
>
> Use these values to set up the default brightness when the backlight
> device is registered.
>
> Signed-off-by: Mario Limonciello <mario.limonciello at amd.com>
Acked-by: Alex Deucher <alexander.deucher at amd.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c | 4 ++++
> drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 12 +++++++++++-
> drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 8 ++++++++
> 3 files changed, 23 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
> index 7099ff9cf8c5..f85ace0384d2 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
> @@ -383,6 +383,8 @@ static int amdgpu_atif_query_backlight_caps(struct amdgpu_atif *atif)
> characteristics.min_input_signal;
> atif->backlight_caps.max_input_signal =
> characteristics.max_input_signal;
> + atif->backlight_caps.ac_level = characteristics.ac_level;
> + atif->backlight_caps.dc_level = characteristics.dc_level;
> out:
> kfree(info);
> return err;
> @@ -1268,6 +1270,8 @@ void amdgpu_acpi_get_backlight_caps(struct amdgpu_dm_backlight_caps *caps)
> caps->caps_valid = atif->backlight_caps.caps_valid;
> caps->min_input_signal = atif->backlight_caps.min_input_signal;
> caps->max_input_signal = atif->backlight_caps.max_input_signal;
> + caps->ac_level = atif->backlight_caps.ac_level;
> + caps->dc_level = atif->backlight_caps.dc_level;
> }
>
> /**
> 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 5fd7210b2479..71aa0c518951 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> @@ -77,6 +77,7 @@
> #include <linux/types.h>
> #include <linux/pm_runtime.h>
> #include <linux/pci.h>
> +#include <linux/power_supply.h>
> #include <linux/firmware.h>
> #include <linux/component.h>
> #include <linux/dmi.h>
> @@ -4321,6 +4322,7 @@ amdgpu_dm_register_backlight_device(struct amdgpu_dm_connector *aconnector)
> struct drm_device *drm = aconnector->base.dev;
> struct amdgpu_display_manager *dm = &drm_to_adev(drm)->dm;
> struct backlight_properties props = { 0 };
> + struct amdgpu_dm_backlight_caps caps = { 0 };
> char bl_name[16];
>
> if (aconnector->bl_idx == -1)
> @@ -4333,8 +4335,16 @@ amdgpu_dm_register_backlight_device(struct amdgpu_dm_connector *aconnector)
> return;
> }
>
> + amdgpu_acpi_get_backlight_caps(&caps);
> + if (caps.caps_valid) {
> + if (power_supply_is_system_supplied() > 0)
> + props.brightness = caps.ac_level;
> + else
> + props.brightness = caps.dc_level;
> + } else
> + props.brightness = AMDGPU_MAX_BL_LEVEL;
> +
> props.max_brightness = AMDGPU_MAX_BL_LEVEL;
> - props.brightness = AMDGPU_MAX_BL_LEVEL;
> props.type = BACKLIGHT_RAW;
>
> snprintf(bl_name, sizeof(bl_name), "amdgpu_bl%d",
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
> index b246e82f5b0d..df72cb71e95a 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
> @@ -173,6 +173,14 @@ struct amdgpu_dm_backlight_caps {
> * @aux_support: Describes if the display supports AUX backlight.
> */
> bool aux_support;
> + /**
> + * @ac_level: the default brightness if booted on AC
> + */
> + u8 ac_level;
> + /**
> + * @dc_level: the default brightness if booted on DC
> + */
> + u8 dc_level;
> };
>
> /**
> --
> 2.43.0
>
More information about the amd-gfx
mailing list