Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2100489pxb; Fri, 25 Mar 2022 11:05:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwm4jXPLgmgioBPqhyfwfp/ohN6j23W8YQZVz3uHL7YlFCvOb44NmgnKzZH8MyYtblYJZKR X-Received: by 2002:a17:902:c944:b0:154:38b8:aa46 with SMTP id i4-20020a170902c94400b0015438b8aa46mr12988738pla.144.1648231528032; Fri, 25 Mar 2022 11:05:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648231528; cv=none; d=google.com; s=arc-20160816; b=MNz5qgX2NMuAI8JeY+4VGUHqpnoMEQ080UqxjvmG+tdaSNgHW9HJDNE0Jw7m95J0mZ YzwV+6NIG21238AGrFL0PvlRSbk9ktN0HPdpphNizKZXb4YRsEg/KQa8KP6xycFaLUpO PCi+tEXBxBYdyQQxEasiMTaNfGV1QrjUutAeTwsj6EFPcW+pfDex8ytvDxeK/07vw2hd zOBs5hVENSTAdWmjeVg0gKFIRc1T4zhTfi/yCPXK3mvsVpDuHTDW7J0jtgkAuTQhf3bM W5W4PF0PJxXFp0b/LiZdjgsFm1LPWcYAenvKkA2fSJ9kifteViqpvVoLp4KbkChfD2fY Pgjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=d+UppTrxLQdaijQbmLi2ygRNUTwZayeuPKsfWsxc+Zo=; b=0TNJg12/Wqm+boNMsjkvp5fgGi+0QifgStpPSljEgFOXaYpnmmWzNKWNaLtLPwQWB4 JYB18fV0dgLJvQibSg9gvRusBTJ/oA4yUhz6pUTTm+RvsUeUGHyCb1610Zt/DF2GTAni oET0I/ztvjpj5P5DJiHHnqCfez8HzAwiG/1p5kLehSJ2MP4ryCSlnPBODBztFY/6NBve cOfF52PK4594TauXb5MvVhiucYNBU8pi2clY5Y5LWss2v2twgOzKWUhBLa1pEcN0ie1O pe6QZzbCwEPi3GC+tuzuUgZawMvYUqAD/QLHCYV08YIUWMpKxDmnRfxfigw9PqFUTyl+ dbFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Mr3uMt15; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id g24-20020a170902d5d800b00153b2d165fbsi2833629plh.515.2022.03.25.11.05.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 11:05:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Mr3uMt15; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 60B7C13195B; Fri, 25 Mar 2022 10:40:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359248AbiCYNIp (ORCPT + 99 others); Fri, 25 Mar 2022 09:08:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352493AbiCYNIp (ORCPT ); Fri, 25 Mar 2022 09:08:45 -0400 Received: from mail-oa1-x30.google.com (mail-oa1-x30.google.com [IPv6:2001:4860:4864:20::30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7433A8ED5 for ; Fri, 25 Mar 2022 06:07:10 -0700 (PDT) Received: by mail-oa1-x30.google.com with SMTP id 586e51a60fabf-de3f2a19c8so8079724fac.1 for ; Fri, 25 Mar 2022 06:07:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=d+UppTrxLQdaijQbmLi2ygRNUTwZayeuPKsfWsxc+Zo=; b=Mr3uMt15CEDF8Ba+6ECcUfzdpV5TOWE1Ts2aqBpikq7hdwnh2BhSkVNiY23MigyCo1 5/0a00IeRbTP8IQd+UUBezGhidat0d2Q4XYVkN8AAv33xgeuAfUg9n1oA7xGp6R97U3+ zbP7SRZnJPvIMAJ4+ZquoxHnZUTTk7qKxT+CsiVdM6zJRQZV8UW8naewzz38OZQPwjyL MWmBS63NuPUhU3p3Odf2FDnlOH7KIcDwDKaY4QNqNBiR9iqnlPVXpt1PjDY9wA6d8WzH fRTVhUWrbP+YT1D23WkVN0i6YMYvrCXsYTidkzrRXTYa9DPQYb+rCWLX6z2uz3j67LSm SQDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=d+UppTrxLQdaijQbmLi2ygRNUTwZayeuPKsfWsxc+Zo=; b=q/OirpOB3ptVdx3m9vWvY4zfgV3Amf5ndAxFQ/Soz3dQIkurl9tfw+v3M7TkyN2THn H4yNfoaHHfxmmT4NdeDo/h7FDD8E7RBno+t2Psf8sZ7jeeefoG557R4Z2B4Si4UKo0Ar nCNiKsqLDczeNRso7SYdWTq3wPgHnEeFOXNR7D9dWqcPsyqEaGT544lAhBjds8zf5EJh dRyfsnWjDHZCziVjZDES5q5JD/q6Nk17sCvHfw34e4DCujDClg1P8AujQxzwJMUnjSq2 wuPoNOpF8qSdAOIldh0UPGQrcfZDRHPUFAEPUVYL1SFmkLkzFQuh/Pdny3+oCRvpE3VG u+aw== X-Gm-Message-State: AOAM530WIbUk7DpO4pb5lrI/xppEv2ygJ7n20GfjXXmaiWXn8JOKu7pr IbNG+Js0M4fzUVqYesh+BcjAuGtj1U6m17Eh18A= X-Received: by 2002:a05:6870:630c:b0:da:b3f:324d with SMTP id s12-20020a056870630c00b000da0b3f324dmr4883902oao.253.1648213628946; Fri, 25 Mar 2022 06:07:08 -0700 (PDT) MIME-Version: 1.0 References: <20220325040515.4073706-1-tsung-hua.lin@amd.com> In-Reply-To: <20220325040515.4073706-1-tsung-hua.lin@amd.com> From: Alex Deucher Date: Fri, 25 Mar 2022 09:06:57 -0400 Message-ID: Subject: Re: [PATCH v2 3/25] drm/amdgpu: Disable ABM when AC mode To: Ryan Lin Cc: "Wentland, Harry" , "Leo (Sunpeng) Li" , "Deucher, Alexander" , Christian Koenig , Chunming Zhou , Dave Airlie , Daniel Vetter , Sean Paul , Bas Nieuwenhuizen , "Kazlauskas, Nicholas" , Sasha Levin , Mark Yacoub , Victor Lu , ching-shih.li@amd.corp-partner.google.com, "Siqueira, Rodrigo" , ddavenport@chromium.org, amd-gfx list , Maling list - DRI developers , LKML , leon.li@amd.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Mar 25, 2022 at 2:27 AM Ryan Lin wrote: > > Disable ABM feature when the system is running on AC mode to get > the more perfect contrast of the display. > > Signed-off-by: Ryan Lin > > --- > drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c | 4 ++ > drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 1 + > drivers/gpu/drm/amd/display/dc/dce/dmub_abm.c | 58 ++++++++++++------- > drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h | 1 + > 4 files changed, 42 insertions(+), 22 deletions(-) > > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c > index c560c1ab62ecb..bc8bb9aad2e36 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_acpi.c > @@ -822,6 +822,10 @@ static int amdgpu_acpi_event(struct notifier_block *nb, > struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, acpi_nb); > struct acpi_bus_event *entry = (struct acpi_bus_event *)data; > > + if (strcmp(entry->device_class, "battery") == 0) { > + adev->pm.ac_power = power_supply_is_system_supplied() > 0; > + } > + We already set adev->pm.ac_power in amdgpu_pm_acpi_event_handler() which gets called a few lines below. Alex > if (strcmp(entry->device_class, ACPI_AC_CLASS) == 0) { > if (power_supply_is_system_supplied() > 0) > DRM_DEBUG_DRIVER("pm: AC\n"); > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > index abfcc1304ba0c..3a0afe7602727 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c > @@ -3454,6 +3454,7 @@ int amdgpu_device_init(struct amdgpu_device *adev, > > adev->gfx.gfx_off_req_count = 1; > adev->pm.ac_power = power_supply_is_system_supplied() > 0; > + adev->pm.old_ac_power = true; > > atomic_set(&adev->throttling_logging_enabled, 1); > /* > diff --git a/drivers/gpu/drm/amd/display/dc/dce/dmub_abm.c b/drivers/gpu/drm/amd/display/dc/dce/dmub_abm.c > index 54a1408c8015c..478a734b66926 100644 > --- a/drivers/gpu/drm/amd/display/dc/dce/dmub_abm.c > +++ b/drivers/gpu/drm/amd/display/dc/dce/dmub_abm.c > @@ -23,6 +23,8 @@ > * > */ > > +#include > +#include "amdgpu.h" > #include "dmub_abm.h" > #include "dce_abm.h" > #include "dc.h" > @@ -51,6 +53,7 @@ > #define DISABLE_ABM_IMMEDIATELY 255 > > > +extern uint amdgpu_dm_abm_level; > > static void dmub_abm_enable_fractional_pwm(struct dc_context *dc) > { > @@ -117,28 +120,6 @@ static void dmub_abm_init(struct abm *abm, uint32_t backlight) > dmub_abm_enable_fractional_pwm(abm->ctx); > } > > -static unsigned int dmub_abm_get_current_backlight(struct abm *abm) > -{ > - struct dce_abm *dce_abm = TO_DMUB_ABM(abm); > - unsigned int backlight = REG_READ(BL1_PWM_CURRENT_ABM_LEVEL); > - > - /* return backlight in hardware format which is unsigned 17 bits, with > - * 1 bit integer and 16 bit fractional > - */ > - return backlight; > -} > - > -static unsigned int dmub_abm_get_target_backlight(struct abm *abm) > -{ > - struct dce_abm *dce_abm = TO_DMUB_ABM(abm); > - unsigned int backlight = REG_READ(BL1_PWM_TARGET_ABM_LEVEL); > - > - /* return backlight in hardware format which is unsigned 17 bits, with > - * 1 bit integer and 16 bit fractional > - */ > - return backlight; > -} > - > static bool dmub_abm_set_level(struct abm *abm, uint32_t level) > { > union dmub_rb_cmd cmd; > @@ -148,6 +129,9 @@ static bool dmub_abm_set_level(struct abm *abm, uint32_t level) > int edp_num; > uint8_t panel_mask = 0; > > + if (power_supply_is_system_supplied() > 0) > + level = 0; > + > get_edp_links(dc->dc, edp_links, &edp_num); > > for (i = 0; i < edp_num; i++) { > @@ -170,6 +154,36 @@ static bool dmub_abm_set_level(struct abm *abm, uint32_t level) > return true; > } > > +static unsigned int dmub_abm_get_current_backlight(struct abm *abm) > +{ > + struct dce_abm *dce_abm = TO_DMUB_ABM(abm); > + unsigned int backlight = REG_READ(BL1_PWM_CURRENT_ABM_LEVEL); > + struct dc_context *dc = abm->ctx; > + struct amdgpu_device *adev = dc->driver_context; > + > + if (adev->pm.ac_power != adev->pm.old_ac_power) { > + dmub_abm_set_level(abm, amdgpu_dm_abm_level); > + adev->pm.ac_power = power_supply_is_system_supplied() > 0; > + adev->pm.old_ac_power = adev->pm.ac_power; > + } > + > + /* return backlight in hardware format which is unsigned 17 bits, with > + * 1 bit integer and 16 bit fractional > + */ > + return backlight; > +} > + > +static unsigned int dmub_abm_get_target_backlight(struct abm *abm) > +{ > + struct dce_abm *dce_abm = TO_DMUB_ABM(abm); > + unsigned int backlight = REG_READ(BL1_PWM_TARGET_ABM_LEVEL); > + > + /* return backlight in hardware format which is unsigned 17 bits, with > + * 1 bit integer and 16 bit fractional > + */ > + return backlight; > +} > + > static bool dmub_abm_init_config(struct abm *abm, > const char *src, > unsigned int bytes, > diff --git a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h > index f6e0e7d8a0077..de459411a0e83 100644 > --- a/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h > +++ b/drivers/gpu/drm/amd/pm/inc/amdgpu_dpm.h > @@ -445,6 +445,7 @@ struct amdgpu_pm { > uint32_t smu_prv_buffer_size; > struct amdgpu_bo *smu_prv_buffer; > bool ac_power; > + bool old_ac_power; > /* powerplay feature */ > uint32_t pp_feature; > > -- > 2.25.1 >