Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp268798ybj; Thu, 19 Sep 2019 14:08:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqya3Nc4HG1HPca4+v7DuMk8Xbm+hvfFs6wRNjVRPGC6tdIJEjpmcyEZtaysFCQZvHaheFgc X-Received: by 2002:a17:906:128a:: with SMTP id k10mr16563995ejb.9.1568927285048; Thu, 19 Sep 2019 14:08:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568927285; cv=none; d=google.com; s=arc-20160816; b=VMe1SqYV2Yg1tqhA1eGaVg5nKhDdBuwfBZK5Cb75PvTDfj4c8IVKM4UC8rM4ndpRV6 Y7yWLg0hybdXu02kUbRfqfnzQbTlbe3rNfZlb5h/J/l+JihgvA2R2bmJHtSTeXdvaB3+ NxJLffs7wFaWbPaxLOO/0Kq1wT/8Irf/LCsL8YM2sKuSAidvS2/KBQTm6CSaJFIBn5/t LHhRuCTrv6klFz0uC9Ngp5cQcTh6J3DgJwuFOS0EHLhAN6fqA/oGnAFxEYPXlEwbAH8c p6bj2VhjUPgOLad4IHWMNV82lKpMWSWx5zTcVfhU61BT3FrcPkyjJ8OKum7YzmYYN9QW 6aVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=9jGZhci6ir2QQxaMaZ4RPKwsW6VmlML93zQ3UVVvLVc=; b=lUqusDFjz4mut5Wjkzg5NMu+4DxJE+pOzykNL8IrmPVxcAIrhGcg73ZQWgeylMyaMP Toe5vdYej6wEyP+YfmvP7ZKJpGYXtwithBXrOigecCnVOI3eB4B3yuiZiXDncqRRhVBR 8kazTY/gVTt9OGuyGD89DSMuGUAWQX9z8iLxFtOWPHNToA8qYu5yF6LAyz8Gs9qi112g cBdi0EVws/qzmSVAEwCqNBc0wOxuC8Hkoqu7zW0KFxf2IKkYuoXoKpU/rRrcHSSPXYS7 uS7ZqFXiQ9YHNGKR8yeTBKYJSBSdXPjRcSGrJq5YiG8lj8t/aLZ8biavQvRpa/0vohT7 YQug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=OCn3gIYj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g23si176817ejm.398.2019.09.19.14.07.38; Thu, 19 Sep 2019 14:08:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=OCn3gIYj; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388887AbfISOGb (ORCPT + 99 others); Thu, 19 Sep 2019 10:06:31 -0400 Received: from mail-lf1-f68.google.com ([209.85.167.68]:40800 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388605AbfISOGb (ORCPT ); Thu, 19 Sep 2019 10:06:31 -0400 Received: by mail-lf1-f68.google.com with SMTP id d17so2470175lfa.7 for ; Thu, 19 Sep 2019 07:06:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=9jGZhci6ir2QQxaMaZ4RPKwsW6VmlML93zQ3UVVvLVc=; b=OCn3gIYj+wUYxAtXas8eOyf4fSEWhP2JZywuNcvWhoXd2re/NpOYXHVgx+ktYyP5cV f+T9+6Yleq+jPzmdljsDSTYYkv0hRJ4OXI6VngwNHBQhZ+MPKG8XvWun3Tnm4NO4agx6 jyhuQWbNOO26WlFgyizU4iA2+osQUAPnhKYiE= 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=9jGZhci6ir2QQxaMaZ4RPKwsW6VmlML93zQ3UVVvLVc=; b=ZRs/QlCuEKuA4CQ9FSZI1SI5ordO6BEMuE82Vf/IhD1E2upsH3VSILuZYu+FfYIreB mielVic8/bsCxPm2M1tqg4abVC5LwdiUUrAPtm90hEKcj/8O1eSfjJVcfmJIYUtuNrcA bwHsBP2rDnuDbjLa1fMamiOA/S/Z+6fg07nUAzMIyeEW6yLPDTny1zMBGMPJHAGtG4VR ufKqr6+bKBsjXXIsNug6SE4aYlqU8TqRuh5v/k0aKD6TAEJ/T+RNb1jgmKFnoNVjVpnt Apo9oUos2RGkK+QoXGsc6k9wNAhQLxMLjaBh1NpcK8I2EVj5bChEwXVfWVDb5PtKPEjB EUIg== X-Gm-Message-State: APjAAAXE772/GM73aTmzoCEwBW6noKw49PEmRqrMIXXQn2h5LTXStZWR NqWsTJ/hXfij17x2cBTK142FBZmWRaJcFO6A X-Received: by 2002:ac2:51a7:: with SMTP id f7mr5064133lfk.119.1568901989001; Thu, 19 Sep 2019 07:06:29 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id h3sm1687886ljf.12.2019.09.19.07.06.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2019 07:06:28 -0700 (PDT) From: Rasmus Villemoes To: Thierry Reding , Lee Jones , Daniel Thompson , Jingoo Han , Bartlomiej Zolnierkiewicz Cc: Rasmus Villemoes , linux-pwm@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/5] backlight: pwm_bl: fix cie1913 comments and constant Date: Thu, 19 Sep 2019 16:06:16 +0200 Message-Id: <20190919140620.32407-1-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The "break-even" point for the two formulas is L==8, which is also what the code actually implements. [Incidentally, at that point one has Y=0.008856, not 0.08856]. Moreover, all the sources I can find say the linear factor is 903.3 rather than 902.3, which makes sense since then the formulas agree at L==8, both yielding the 0.008856 figure to four significant digits. Signed-off-by: Rasmus Villemoes --- drivers/video/backlight/pwm_bl.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index 2201b8c78641..be36be1cacb7 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -155,8 +155,8 @@ static const struct backlight_ops pwm_backlight_ops = { * * The CIE 1931 lightness formula is what actually describes how we perceive * light: - * Y = (L* / 902.3) if L* ≤ 0.08856 - * Y = ((L* + 16) / 116)^3 if L* > 0.08856 + * Y = (L* / 903.3) if L* ≤ 8 + * Y = ((L* + 16) / 116)^3 if L* > 8 * * Where Y is the luminance, the amount of light coming out of the screen, and * is a number between 0.0 and 1.0; and L* is the lightness, how bright a human @@ -169,9 +169,15 @@ static u64 cie1931(unsigned int lightness, unsigned int scale) { u64 retval; + /* + * @lightness is given as a number between 0 and 1, expressed + * as a fixed-point number in scale @scale. Convert to a + * percentage, still expressed as a fixed-point number, so the + * above formulas can be applied. + */ lightness *= 100; if (lightness <= (8 * scale)) { - retval = DIV_ROUND_CLOSEST_ULL(lightness * 10, 9023); + retval = DIV_ROUND_CLOSEST_ULL(lightness * 10, 9033); } else { retval = int_pow((lightness + (16 * scale)) / 116, 3); retval = DIV_ROUND_CLOSEST_ULL(retval, (scale * scale)); -- 2.20.1