]> www.infradead.org Git - users/hch/misc.git/commitdiff
drm/amd/display: Set default brightness according to ACPI
authorMario Limonciello <mario.limonciello@amd.com>
Fri, 7 Jun 2024 06:02:28 +0000 (01:02 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 14 Jun 2024 20:17:11 +0000 (16:17 -0400)
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.

v2: squash in ACPI fix

Reviewed-by: Leo Li <sunpeng.li@amd.com>
Acked-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu.h
drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h

index 35faa286bb1cab5cd1761581b2f6d956374cd4bd..d942c90f88f1b4cc5806c27744d4b6a2cd39e42f 100644 (file)
@@ -1567,6 +1567,7 @@ static inline int amdgpu_acpi_power_shift_control(struct amdgpu_device *adev,
                                                  u8 dev_state, bool drv_state) { return 0; }
 static inline int amdgpu_acpi_smart_shift_update(struct drm_device *dev,
                                                 enum amdgpu_ss ss_state) { return 0; }
+static inline void amdgpu_acpi_get_backlight_caps(struct amdgpu_dm_backlight_caps *caps) { }
 #endif
 
 #if defined(CONFIG_ACPI) && defined(CONFIG_SUSPEND)
index 7099ff9cf8c50d7b7ea96149bcef235368fae165..f85ace0384d21893c94171d541f382a2ae3932a7 100644 (file)
@@ -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;
 }
 
 /**
index 448932ac06fb2f932d452c062826f68ab4a0f619..a2c098f1b07c2128d88797fa2f87064a574a6b2b 100644 (file)
@@ -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>
@@ -4571,6 +4572,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)
@@ -4583,8 +4585,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",
index 94fc4c15d2dbc0e94beb1802e650ddc55cd26e70..d64aabad032e85440733e84be632f2ffd988ac0c 100644 (file)
@@ -180,6 +180,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;
 };
 
 /**