From patchwork Tue Oct 15 20:03:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?THVrw6HFoSBLcmVqxI3DrQ==?= X-Patchwork-Id: 11191609 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7B213139A for ; Tue, 15 Oct 2019 20:03:34 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 626F420854 for ; Tue, 15 Oct 2019 20:03:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 626F420854 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AED416E3CE; Tue, 15 Oct 2019 20:03:33 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by gabe.freedesktop.org (Postfix) with ESMTPS id EB1396E3CE; Tue, 15 Oct 2019 20:03:31 +0000 (UTC) Received: by mail-wm1-x343.google.com with SMTP id r17so3079376wme.0; Tue, 15 Oct 2019 13:03:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Run5zEC2YDG4iaM/jJbIr5lBTYCoKzZFxdmUOW0FVlI=; b=YU9sNxYZzjkUYQczdMul3XI8OdHS1RbW41vqIXyMl8bXHYWAn287Gh2bi3ySASwbiq b1iGaltvrKUBMBz0HchsD9LGCVqbNhGuhI2bqBRD8Hw0Q6zZsnHLIPwkNCemYOgB+CkY pTJDmzOmQ5IkDSKorB4Zzuf74bhRh2HIFkoV3J3wqHRUAXZGSrPVkhH/Rreqqj7bi5k+ mJHP/FCWGEyOtgozPeQmsRSGS/bdI4ytFLml6JP2hbIYXFjXbwIN6x3G4ZnlL5NhzOig A5LI1LYfbGyvDOEIdIxa5GcpHr0CDjkb/7JwIuKdttNo6X1LzkEAIvrjl8or90DREYAS 3ADw== X-Gm-Message-State: APjAAAWDBwsTp5roa1FBJEuUL5sU3N5aq3UBZseSOESEZtEHjh77j3+b AgySnD6CJWNVFHpp4Q/ADL0= X-Google-Smtp-Source: APXvYqyngjOZb9RuA4ZcJM26t/RqZMBK9SR2u6UZ2pWc1HirH/kH8IvpqInoViI3MLiG0fXl2IxVTA== X-Received: by 2002:a7b:c30f:: with SMTP id k15mr128908wmj.161.1571169810490; Tue, 15 Oct 2019 13:03:30 -0700 (PDT) Received: from localhost.localdomain (ip-89-177-253-111.net.upcbroadband.cz. [89.177.253.111]) by smtp.gmail.com with ESMTPSA id y186sm420885wmb.41.2019.10.15.13.03.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 13:03:29 -0700 (PDT) From: =?utf-8?b?THVrw6HFoSBLcmVqxI3DrQ==?= To: Harry Wentland , Leo Li , Alex Deucher , Anthony Koo , Tony Cheng , amd-gfx@lists.freedesktop.org Subject: [RFC PATCH RESEND] drm/amd/display: Add back missing backlight level rounding Date: Tue, 15 Oct 2019 22:03:04 +0200 Message-Id: <20191015200304.30470-1-lskrejci@gmail.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Run5zEC2YDG4iaM/jJbIr5lBTYCoKzZFxdmUOW0FVlI=; b=HXp/SeYg1fKrMQOPdQfG9h5VRRp3P2aeRLj6da72BmX2sFCFK4Fgnr/VbuR8iQd7fa 6laBz3/eZUO7nGmFyycKfKlK8KDtDvPZWjHTx9uKYXql+qNtAYeCuGD2bN6wTQlkY/kb B5lKlUIp3exfF3y9YZBRrLcNfVK/PO861q7HZzjNV0+5JinR2ijUIsiLKy5ORp+kfWaw 6b5TI7nixU3SqTa72F98eff6XqqROpcHIgEvHgrMQ8Uhjn2pZnDbvFQC0uBkD2PcMGe/ rwgf3rcwaylcEaEXElzq5ikoqzkqpcd0OQ6NhzP8XLaWLo65Bp3de9DIDt4KDCH7QtYz gQlg== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: David Airlie , =?utf-8?b?THVrw6HFoSBLcmVqxI3DrQ==?= , dri-devel@lists.freedesktop.org, =?utf-8?q?Christian_K=C3=B6nig?= Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" [Why] Having the rounding of the backlight value restored to the way it was seemingly gets rid of backlight flickering on certain Stoney Ridge laptops. [How] Rescale the backlight level between min and max input signal value and round it to a number between 0x0 and 0xFF. Then, use the rounding mode that was previously in driver_set_backlight_level() and dmcu_set_backlight_level(), i.e. rescale the backlight level between 0x0 and 0x1000 by multiplying it by 0x101 and use the most significant bit of the fraction (or in this case the 8th bit of the value because it's the same thing, e.g. C3 * 0x101 = 0xC3C3 and C3 * 0x10101 = 0xC3C3C3) to round it. Fixes: 262485a50fd4 ("drm/amd/display: Expand dc to use 16.16 bit backlight") Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=204957 Signed-off-by: Lukáš Krejčí --- Notes: Bug: - Can be reproduced on HP 15-rb020nc (Stoney Ridge R2 E2-9000e APU) and Acer Aspire 3 A315-21G-91JL (Stoney Ridge R3 A4-9120 APU). - For me, the bug is inconsistent - it does not happen on every boot, but if it does happen, it's usually within three minutes after bootup. - It concerns the backlight. That means it can be reproduced on the framebuffer console. - Reproduces on Arch Linux (custom built) live CD, linux kernel v5.3.2 and Ubuntu 19.04, kernel-ppa/mainline v5.0.0-rc1, v5.0.0, v5.3.2, v5.3.4, v5.4-rc2. - Can not be reproduced on kernel v5.3.4 with this patch applied or on v4.20.0, 4.20.17, 4.19.75 (this bug is a regression). - The other person that reproduced the issue (see the Bugzilla link above) confirmed that the patch works for them too. Patch: - Is the comment modified by this commit correct? Both driver_set_backlight_level() and dmcu_set_backlight_level() check the 17th bit of `brightness` aka `backlight_pwm_u16_16`, but 262485a50fd4532a8d71165190adc7a0a19bcc9e ("drm/amd/display: Expand dc to use 16.16 bit backlight") specifically mentions 0xFFFF as the max backlight value. - use_smooth_brightness is false (no DMCU firmware available) on my laptop, so the other code path (dmcu_set_backlight_level()) is untested. - I'm not sure why the rounding fixes the issue and whether this function is the right place to add back the rounding (and whether it even is the right way to solve the issue), so that's why this patch is RFC. .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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 a52f0b13a2c8..af9a5f46b671 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c @@ -2083,17 +2083,22 @@ static int amdgpu_dm_backlight_update_status(struct backlight_device *bd) * The brightness input is in the range 0-255 * It needs to be rescaled to be between the * requested min and max input signal - * - * It also needs to be scaled up by 0x101 to - * match the DC interface which has a range of - * 0 to 0xffff */ brightness = brightness - * 0x101 + * 0x100 * (caps.max_input_signal - caps.min_input_signal) / AMDGPU_MAX_BL_LEVEL - + caps.min_input_signal * 0x101; + + caps.min_input_signal * 0x100; + + brightness = (brightness >> 8) + ((brightness >> 7) & 1); + /* + * It also needs to be scaled up by 0x101 and + * rounded off to match the DC interface which + * has a range of 0 to 0x10000 + */ + brightness *= 0x101; + brightness += (brightness >> 7) & 1; if (dc_link_set_backlight_level(dm->backlight_link, brightness, 0))