<div dir="auto">Please drop the UPSTREAM prefix. Might be needed in the ChromeOS patch, but not for upstream.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Mar 25, 2022, 2:29 AM Ryan Lin <<a href="mailto:tsung-hua.lin@amd.com">tsung-hua.lin@amd.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Disable ABM feature when the system is running on AC mode to get<br>
the more perfect contrast of the display.<br>
<br>
Signed-off-by: Ryan Lin <<a href="mailto:tsung-hua.lin@amd.com" target="_blank" rel="noreferrer">tsung-hua.lin@amd.com</a>><br>
<br>
---<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c | 4 ++<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 +<br>
drivers/gpu/drm/amd/display/dc/dce/dmub_abm.c | 58 ++++++++++++-------<br>
drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h | 1 +<br>
4 files changed, 42 insertions(+), 22 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c<br>
index c560c1ab62ecb..bc8bb9aad2e36 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c<br>
@@ -822,6 +822,10 @@ static int amdgpu_acpi_event(struct notifier_block *nb,<br>
struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, acpi_nb);<br>
struct acpi_bus_event *entry = (struct acpi_bus_event *)data;<br>
<br>
+ if (strcmp(entry->device_class, "battery") == 0) {<br>
+ adev->pm.ac_power = power_supply_is_system_supplied() > 0;<br>
+ }<br>
+<br>
if (strcmp(entry->device_class, ACPI_AC_CLASS) == 0) {<br>
if (power_supply_is_system_supplied() > 0)<br>
DRM_DEBUG_DRIVER("pm: AC\n");<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
index abfcc1304ba0c..3a0afe7602727 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c<br>
@@ -3454,6 +3454,7 @@ int amdgpu_device_init(struct amdgpu_device *adev,<br>
<br>
adev->gfx.gfx_off_req_count = 1;<br>
adev->pm.ac_power = power_supply_is_system_supplied() > 0;<br>
+ adev->pm.old_ac_power = true;<br>
<br>
atomic_set(&adev->throttling_logging_enabled, 1);<br>
/*<br>
diff --git a/drivers/gpu/drm/amd/display/dc/dce/dmub_abm.c b/drivers/gpu/drm/amd/display/dc/dce/dmub_abm.c<br>
index 54a1408c8015c..478a734b66926 100644<br>
--- a/drivers/gpu/drm/amd/display/dc/dce/dmub_abm.c<br>
+++ b/drivers/gpu/drm/amd/display/dc/dce/dmub_abm.c<br>
@@ -23,6 +23,8 @@<br>
*<br>
*/<br>
<br>
+#include <linux/power_supply.h><br>
+#include "amdgpu.h"<br>
#include "dmub_abm.h"<br>
#include "dce_abm.h"<br>
#include "dc.h"<br>
@@ -51,6 +53,7 @@<br>
#define DISABLE_ABM_IMMEDIATELY 255<br>
<br>
<br>
+extern uint amdgpu_dm_abm_level;<br>
<br>
static void dmub_abm_enable_fractional_pwm(struct dc_context *dc)<br>
{<br>
@@ -117,28 +120,6 @@ static void dmub_abm_init(struct abm *abm, uint32_t backlight)<br>
dmub_abm_enable_fractional_pwm(abm->ctx);<br>
}<br>
<br>
-static unsigned int dmub_abm_get_current_backlight(struct abm *abm)<br>
-{<br>
- struct dce_abm *dce_abm = TO_DMUB_ABM(abm);<br>
- unsigned int backlight = REG_READ(BL1_PWM_CURRENT_ABM_LEVEL);<br>
-<br>
- /* return backlight in hardware format which is unsigned 17 bits, with<br>
- * 1 bit integer and 16 bit fractional<br>
- */<br>
- return backlight;<br>
-}<br>
-<br>
-static unsigned int dmub_abm_get_target_backlight(struct abm *abm)<br>
-{<br>
- struct dce_abm *dce_abm = TO_DMUB_ABM(abm);<br>
- unsigned int backlight = REG_READ(BL1_PWM_TARGET_ABM_LEVEL);<br>
-<br>
- /* return backlight in hardware format which is unsigned 17 bits, with<br>
- * 1 bit integer and 16 bit fractional<br>
- */<br>
- return backlight;<br>
-}<br>
-<br>
static bool dmub_abm_set_level(struct abm *abm, uint32_t level)<br>
{<br>
union dmub_rb_cmd cmd;<br>
@@ -148,6 +129,9 @@ static bool dmub_abm_set_level(struct abm *abm, uint32_t level)<br>
int edp_num;<br>
uint8_t panel_mask = 0;<br>
<br>
+ if (power_supply_is_system_supplied() > 0)<br>
+ level = 0;<br>
+<br>
get_edp_links(dc->dc, edp_links, &edp_num);<br>
<br>
for (i = 0; i < edp_num; i++) {<br>
@@ -170,6 +154,36 @@ static bool dmub_abm_set_level(struct abm *abm, uint32_t level)<br>
return true;<br>
}<br>
<br>
+static unsigned int dmub_abm_get_current_backlight(struct abm *abm)<br>
+{<br>
+ struct dce_abm *dce_abm = TO_DMUB_ABM(abm);<br>
+ unsigned int backlight = REG_READ(BL1_PWM_CURRENT_ABM_LEVEL);<br>
+ struct dc_context *dc = abm->ctx;<br>
+ struct amdgpu_device *adev = dc->driver_context;<br>
+<br>
+ if (adev->pm.ac_power != adev->pm.old_ac_power) {<br>
+ dmub_abm_set_level(abm, amdgpu_dm_abm_level);<br>
+ adev->pm.ac_power = power_supply_is_system_supplied() > 0;<br>
+ adev->pm.old_ac_power = adev->pm.ac_power;<br>
+ }<br>
+<br>
+ /* return backlight in hardware format which is unsigned 17 bits, with<br>
+ * 1 bit integer and 16 bit fractional<br>
+ */<br>
+ return backlight;<br>
+}<br>
+<br>
+static unsigned int dmub_abm_get_target_backlight(struct abm *abm)<br>
+{<br>
+ struct dce_abm *dce_abm = TO_DMUB_ABM(abm);<br>
+ unsigned int backlight = REG_READ(BL1_PWM_TARGET_ABM_LEVEL);<br>
+<br>
+ /* return backlight in hardware format which is unsigned 17 bits, with<br>
+ * 1 bit integer and 16 bit fractional<br>
+ */<br>
+ return backlight;<br>
+}<br>
+<br>
static bool dmub_abm_init_config(struct abm *abm,<br>
const char *src,<br>
unsigned int bytes,<br>
diff --git a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h<br>
index f6e0e7d8a0077..de459411a0e83 100644<br>
--- a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h<br>
+++ b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h<br>
@@ -445,6 +445,7 @@ struct amdgpu_pm {<br>
uint32_t smu_prv_buffer_size;<br>
struct amdgpu_bo *smu_prv_buffer;<br>
bool ac_power;<br>
+ bool old_ac_power;<br>
/* powerplay feature */<br>
uint32_t pp_feature;<br>
<br>
-- <br>
2.25.1<br>
<br>
</blockquote></div>