Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp5566806ybp; Tue, 8 Oct 2019 05:06:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwBUxOK2ZZ+VX6lx75mwFBwfaF2enR3zq7/RfnVskGLN23NQOVfIJMHQQecb7coEu09CNmO X-Received: by 2002:aa7:d295:: with SMTP id w21mr33866130edq.302.1570536381525; Tue, 08 Oct 2019 05:06:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570536381; cv=none; d=google.com; s=arc-20160816; b=wU7lP35D6CnlcgneDmX5EeOujxCTFnBUIH/8dGktHqx1S4/GZcjsPy6BvhyD/xRCVE Opy6DsWph5Fj8XbL9YDU5AIM1S2//q/Cybd2GXvhWb8gJow3+o6UPPzgp5EUfoOUQ4Qd RFDt/dfxFurNtVmNG0bFulg5tYYR3q3tmiUHJP2xF9VCz0sFhnE2i9YpBXjZotsRyEAI t6gkhBGSRk5DeQUzxvqpCAhaRMjxEzZwfmLC/1CIbeg+IRwvYpayW6U5HahISoiY15oO SwozLN6uXzljE+mg8eXAhTVBLKPyc38boIjjcVXdo1N8MQDSkCvtYcCT6+TVQ/UauXZy TxqQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kZ+v3Ie5jsyMpg1/r8HbbsX7sXk3b8d5gKwzOHbV1b8=; b=Y8z4ViaQ7pKxWcNP5LKBvMKKs/21rKdDJpB/eOBiunX1mSRZkNwl2aMmPeV7nJXwBP sYvUwiey5SliCLZ8K+zLkXyxP8UoM3GHfX/1TKigf5RUzxichDqDYxB8JJzlnPdKIpPt GIlYX4iARUB9kB1UTefV1Agt1gM8GTrECCt8Ky4QdXm0mmfyQ69R22870uWgyiuFUczG h3/bNUYRyQqEEU2nf0GSnfmrHTgreREtLNl2q5SwctF5NiCekFC1Fe1CkivkDc1L2nlV x9HyEEtGVP9t9F0RydIwDE3tFE3/rGjcLugCGAmuW03w27yATsyKLpgY0cVRnLeDvqVv DFNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=W0ddgUpZ; 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 s20si9045433ejx.223.2019.10.08.05.05.57; Tue, 08 Oct 2019 05:06:21 -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=W0ddgUpZ; 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 S1730901AbfJHMFW (ORCPT + 99 others); Tue, 8 Oct 2019 08:05:22 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:35634 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730750AbfJHMFV (ORCPT ); Tue, 8 Oct 2019 08:05:21 -0400 Received: by mail-lj1-f194.google.com with SMTP id m7so17241637lji.2 for ; Tue, 08 Oct 2019 05:05:19 -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:in-reply-to:references :mime-version:content-transfer-encoding; bh=kZ+v3Ie5jsyMpg1/r8HbbsX7sXk3b8d5gKwzOHbV1b8=; b=W0ddgUpZ8caX090N18rJXEGsy5RctbdFr4Uj8eEHV+WXpAquDOJGemg+ouB0b7rO2k wQfnFphLbbQKFY/9KqpuIJl8qs1h1g3Lae36ILXsc4WNO/eomzP41sRPtH5RcLggU2XK ai8CJyNSJdiOh5PVAUkZIqTEPEq2lsZk8iZhY= 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=kZ+v3Ie5jsyMpg1/r8HbbsX7sXk3b8d5gKwzOHbV1b8=; b=hvcT4pLjg4xKZeFW065i9zPADI1GyvinhgDta4iIKowGgflZto41glUjIyxWhm9bpo UqNtUIsjprePJaKTMGf95stBdEFyBGtU+uH6qjX8JqAr8/zvycp0/wGtd3viwguUqdbu ZILCuzRFJIDEKBxQahxFgtBBuYb6eFedQ+tmGQuSpBPwDf9d0QrZ91j3iCWC5WpiI6hB wB/k0/+cdLST/np3Jpa3RdBJEGsiHl+/R5hyKTtxL+OYWhbF1QFept5tayhAmhyHx2Xa FsAv4kY3xeftZYrqcUF1ACdWGWH6PSRRgUIf7PddfGhO/SxcYvei/+okFVP/nRMlIXRb UKVA== X-Gm-Message-State: APjAAAWgBCQ3ELo9M6BhVeyPrr4e06lkQFzcgC66WMj5KfFXmVIXM60I Hl5ZBzOkK93TN3Bqi+1i9UjbJQ== X-Received: by 2002:a2e:810e:: with SMTP id d14mr22480784ljg.160.1570536318667; Tue, 08 Oct 2019 05:05:18 -0700 (PDT) Received: from prevas-ravi.prevas.se ([81.216.59.226]) by smtp.gmail.com with ESMTPSA id z18sm3918033ljh.17.2019.10.08.05.05.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Oct 2019 05:05:17 -0700 (PDT) From: Rasmus Villemoes To: Thierry Reding , =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= , 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 v2 1/4] backlight: pwm_bl: fix cie1913 comments and constant Date: Tue, 8 Oct 2019 14:03:24 +0200 Message-Id: <20191008120327.24208-2-linux@rasmusvillemoes.dk> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191008120327.24208-1-linux@rasmusvillemoes.dk> References: <20191008120327.24208-1-linux@rasmusvillemoes.dk> 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. Reviewed-by: Daniel Thompson 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 746eebc411df..cc44a02e95c7 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