Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2496332pxa; Mon, 17 Aug 2020 11:03:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDLGeKqlXLwkMWu46oEFf4A52Nu3qdHL/8i1s8z7+qCgO4i9f94vBeeKg4lbTiq8rufxZ2 X-Received: by 2002:aa7:cdd0:: with SMTP id h16mr16132498edw.116.1597687406633; Mon, 17 Aug 2020 11:03:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597687406; cv=none; d=google.com; s=arc-20160816; b=z5XKvgWIsnjYPATlYgtIKwuzQ0pNBCWHphiH60uCe2/m4R2st4WkIWJsOF2owLFq0X 7cRb/VeGqS/8DyqC9S1sWW/2OxHZo64e2EMtqzDLfTAt9cA2OZhVI66cvw+1TXnQ2YBJ Dq5CHTiL65eBWawhcpPKSLHJiWDA/pYrKYr1+GBX1twzL69ODZ+KZCI6z8QoZRyWV1KX neNfIuu0GyzsYueX0aL/jp15pxULQ+jcD3B117o5M9FzSfgRhgHIwm7uKcPu9GeJnZFY A8zwCqpXZcq5JSQ5QEeLbUQH9V9Es9SF/JP9PGxi9wHyHVTDdnq1iQvrTWCrXPotA3GW HI7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=xpqTsrG3Vt+9rDMAnpoJVGMbucsRUJ6l/Nbc7i/7gDA=; b=j6kxoqqqJMXdiUPYAY64l71X/+tsVAPJPevpVSf+pqy02oWO0D1rnCuZXLPVM5htCU Iq0s5FGgrEn/yK+Exk1mFpWErdrQ9VMUkh2YXc7WvpWCf5oE9vSDzMDQE4rpkTYYOseN SHCdcCilskR9IlOwKGKBR6/1KyDjtuqf+bSWMnIoAy7kJeGL1iVcf5iAL+SGhrdDNM5v wpoTQore8LUFgwuPxdlUGkECn+Vte+b0rmLE0gxccspN33dcZTt6A6DdCxAOD0jWWxpk /adNi2VDCam7W4AZE4zCWDm71cAcwMwPM598jDs2PLJknYz9AWkzx1e84yBY5faBQDmY eSAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=h6ZG5ld+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lm15si11187220ejb.129.2020.08.17.11.03.03; Mon, 17 Aug 2020 11:03:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=h6ZG5ld+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.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: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731129AbgHQSAi (ORCPT + 99 others); Mon, 17 Aug 2020 14:00:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731268AbgHQR7l (ORCPT ); Mon, 17 Aug 2020 13:59:41 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE5A4C061389 for ; Mon, 17 Aug 2020 10:59:40 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id g8so13989589wmk.3 for ; Mon, 17 Aug 2020 10:59:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=xpqTsrG3Vt+9rDMAnpoJVGMbucsRUJ6l/Nbc7i/7gDA=; b=h6ZG5ld+KvETec+uQL+lRN1c5eWYIQtVdKcid3x29ZR6yoRvAKfH5SNMoqyuhoXHqY vn3Yq0Mkz234dFO8/B7pWQ72jTjCf39QvXhvWIoqLGReggdC6HOPcQdWBUE5OcN3yN2J k0GMO2isL+iYSCyS8Ki6wat/iJPKx1SGR8a5mfMBmStrFeNgQk4/DGy6a/7gEtB46B5Z RUTbyfgnL1BUp1/FciwUEhZjN4snWastUJ6yA5f1r+HPzORjvhbblR1O6qIG0aQz8Skk Q8W/nc1k6kjrufjywWABDg81yz4UpSwLugQq6Mh4GvuHGCUBh8jIm130wFdVCFH8Axmr bUEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=xpqTsrG3Vt+9rDMAnpoJVGMbucsRUJ6l/Nbc7i/7gDA=; b=quZQCM8Lwto85ul7PWYK6eu9rQ8nF50Rl8+V3e5GJ3OwtkBsWuhZNSL4SpFlVnSZn4 ykcBZt4Cxtvkp7R7z/tDn1MUBDxFJm3ufZIzMKoYnd0ouoB+iLAhRJx7dARigNG5rWal QcPJ+1TO7TKT5gGHhNsSgpmPC+11IER89jVYQCUDzCL6LmYLBZzMpZzsP1HveGFFRLjA qB4SRvmIEJlOdWNyxmAaLgu/+ZtNCvXnaURHlm8rl3GrjmXcBc7HofLXHeO3OaLM71B+ 6dW1gdXmefWGhWfnrnh6h97QycufmKs1stV3P+x7bQVrAzYXd+QbZMCSOmTbbGWDjFpj ZTJA== X-Gm-Message-State: AOAM533e+tMNVvbP5eEHxA8v9lMhLj8VBPr794UwDSuUIRHoxrsQPHB+ 71LQ3aQxeqh+3axgooZSC++7Qxj8aZuxeDki5Xc= X-Received: by 2002:a7b:c941:: with SMTP id i1mr15423755wml.73.1597687179587; Mon, 17 Aug 2020 10:59:39 -0700 (PDT) MIME-Version: 1.0 References: <20200804201313.6464-1-amonakov@ispras.ru> In-Reply-To: From: Alex Deucher Date: Mon, 17 Aug 2020 13:59:28 -0400 Message-ID: Subject: Re: [PATCH v2] drm/amd/display: use correct scale for actual_brightness To: Alexander Monakov Cc: amd-gfx list , Alex Deucher , LKML , Nicholas Kazlauskas Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 17, 2020 at 3:09 AM Alexander Monakov wrote: > > Ping. Patch looks good to me: Reviewed-by: Alex Deucher Nick, unless you have any objections, I'll go ahead and apply it. Alex > > On Tue, 4 Aug 2020, Alexander Monakov wrote: > > > Documentation for sysfs backlight level interface requires that > > values in both 'brightness' and 'actual_brightness' files are > > interpreted to be in range from 0 to the value given in the > > 'max_brightness' file. > > > > With amdgpu, max_brightness gives 255, and values written by the user > > into 'brightness' are internally rescaled to a wider range. However, > > reading from 'actual_brightness' gives the raw register value without > > inverse rescaling. This causes issues for various userspace tools such > > as PowerTop and systemd that expect the value to be in the correct > > range. > > > > Introduce a helper to retrieve internal backlight range. Use it to > > reimplement 'convert_brightness' as 'convert_brightness_from_user' and > > introduce 'convert_brightness_to_user'. > > > > Bug: https://bugzilla.kernel.org/show_bug.cgi?id=203905 > > Bug: https://gitlab.freedesktop.org/drm/amd/-/issues/1242 > > Cc: Alex Deucher > > Cc: Nicholas Kazlauskas > > Signed-off-by: Alexander Monakov > > --- > > v2: split convert_brightness to &_from_user and &_to_user (Nicholas) > > > > .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 81 +++++++++---------- > > 1 file changed, 40 insertions(+), 41 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 710edc70e37e..b60a763f3f95 100644 > > --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c > > +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c > > @@ -2881,51 +2881,50 @@ static int set_backlight_via_aux(struct dc_link *link, uint32_t brightness) > > return rc ? 0 : 1; > > } > > > > -static u32 convert_brightness(const struct amdgpu_dm_backlight_caps *caps, > > - const uint32_t user_brightness) > > +static int get_brightness_range(const struct amdgpu_dm_backlight_caps *caps, > > + unsigned *min, unsigned *max) > > { > > - u32 min, max, conversion_pace; > > - u32 brightness = user_brightness; > > - > > if (!caps) > > - goto out; > > + return 0; > > > > - if (!caps->aux_support) { > > - max = caps->max_input_signal; > > - min = caps->min_input_signal; > > - /* > > - * 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 > > - */ > > - conversion_pace = 0x101; > > - brightness = > > - user_brightness > > - * conversion_pace > > - * (max - min) > > - / AMDGPU_MAX_BL_LEVEL > > - + min * conversion_pace; > > + if (caps->aux_support) { > > + // Firmware limits are in nits, DC API wants millinits. > > + *max = 1000 * caps->aux_max_input_signal; > > + *min = 1000 * caps->aux_min_input_signal; > > } else { > > - /* TODO > > - * We are doing a linear interpolation here, which is OK but > > - * does not provide the optimal result. We probably want > > - * something close to the Perceptual Quantizer (PQ) curve. > > - */ > > - max = caps->aux_max_input_signal; > > - min = caps->aux_min_input_signal; > > - > > - brightness = (AMDGPU_MAX_BL_LEVEL - user_brightness) * min > > - + user_brightness * max; > > - // Multiple the value by 1000 since we use millinits > > - brightness *= 1000; > > - brightness = DIV_ROUND_CLOSEST(brightness, AMDGPU_MAX_BL_LEVEL); > > + // Firmware limits are 8-bit, PWM control is 16-bit. > > + *max = 0x101 * caps->max_input_signal; > > + *min = 0x101 * caps->min_input_signal; > > } > > + return 1; > > +} > > > > -out: > > - return brightness; > > +static u32 convert_brightness_from_user(const struct amdgpu_dm_backlight_caps *caps, > > + uint32_t brightness) > > +{ > > + unsigned min, max; > > + > > + if (!get_brightness_range(caps, &min, &max)) > > + return brightness; > > + > > + // Rescale 0..255 to min..max > > + return min + DIV_ROUND_CLOSEST((max - min) * brightness, > > + AMDGPU_MAX_BL_LEVEL); > > +} > > + > > +static u32 convert_brightness_to_user(const struct amdgpu_dm_backlight_caps *caps, > > + uint32_t brightness) > > +{ > > + unsigned min, max; > > + > > + if (!get_brightness_range(caps, &min, &max)) > > + return brightness; > > + > > + if (brightness < min) > > + return 0; > > + // Rescale min..max to 0..255 > > + return DIV_ROUND_CLOSEST(AMDGPU_MAX_BL_LEVEL * (brightness - min), > > + max - min); > > } > > > > static int amdgpu_dm_backlight_update_status(struct backlight_device *bd) > > @@ -2941,7 +2940,7 @@ static int amdgpu_dm_backlight_update_status(struct backlight_device *bd) > > > > link = (struct dc_link *)dm->backlight_link; > > > > - brightness = convert_brightness(&caps, bd->props.brightness); > > + brightness = convert_brightness_from_user(&caps, bd->props.brightness); > > // Change brightness based on AUX property > > if (caps.aux_support) > > return set_backlight_via_aux(link, brightness); > > @@ -2958,7 +2957,7 @@ static int amdgpu_dm_backlight_get_brightness(struct backlight_device *bd) > > > > if (ret == DC_ERROR_UNEXPECTED) > > return bd->props.brightness; > > - return ret; > > + return convert_brightness_to_user(&dm->backlight_caps, ret); > > } > > > > static const struct backlight_ops amdgpu_dm_backlight_ops = { > > > > base-commit: bcf876870b95592b52519ed4aafcf9d95999bc9c > > > _______________________________________________ > amd-gfx mailing list > amd-gfx@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/amd-gfx