Received: by 10.223.164.202 with SMTP id h10csp47364wrb; Wed, 29 Nov 2017 16:45:18 -0800 (PST) X-Google-Smtp-Source: AGs4zMYVudUO1QmmLSF3mDfSvePKZpG5vLQM0OxQ/4rB9a9vxtuBsyEOHj8Sw2xvXiTuRuD70nPq X-Received: by 10.101.78.7 with SMTP id r7mr681200pgt.209.1512002718500; Wed, 29 Nov 2017 16:45:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512002718; cv=none; d=google.com; s=arc-20160816; b=u5kgyPM8nwVGPlcRMNyVXzJZkgEwrciNlhlyWADvCuxMCU3jULR8WKvq0P5r6qLSW1 j8gkZulJ92bPn2tUou0gF2HA1e3iKm3pj2N7Iz1Hl686XpKbTvD5gTT+2nuam+TCWV3+ 1ppugulAQ8wVx7OpeHkcGRTNeNQg0oUxreXTDevogFYVeoNyt0RDfztLhQ9SIscasDmf bTp04t0oz8DyNsZXri682GKg7OiDXCjygqC4iJ9by8Xk+2QY+NykQ1Yt6r/iFrfHdAlF AJI/0n9dmgNxTCicJomnHP2OLYZVb/HWk/pf17FCAXVsSOHachHqlXIs9FkLkg9h+pws sk3A== 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:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature:arc-authentication-results; bh=fiAp8i+/LICVgIPPRleCo7LZ8Ybs8j4ua29iKuwYD00=; b=xSct+tB4jzqhb1Qt3qVSPQDip7ZoczFLAfdJWD/ksfGmLh2yG+NWfv8QSzLs6147md lI3AkDIFVCAyzo6GFJqOhkkHJRAbXDzTzSp6H892IXkwkI7v+KlWWxNcNmjnayRAxoAD s+3ONMGsY195ytcFEu4wkP3sjR//HaWlnAONJujEnf0U1YBBsON/nreUTUgxljtlawhh L/chsFteUONYPNfSYh5uU18pIr+G/lQ14nzAKhWHr4SjyaqUbUFlY0awZxhxTXfVAhoa B9/RjsYYDmCvTQQOxOy88Um15tF/SGeo9/THcBiLNT84o+Zih1FWbxa6/y0NAiKa08CX qiZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Sa0pw2Ku; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q11si2088331pgc.718.2017.11.29.16.45.04; Wed, 29 Nov 2017 16:45:18 -0800 (PST) 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=@google.com header.s=20161025 header.b=Sa0pw2Ku; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753736AbdK3Aoi (ORCPT + 99 others); Wed, 29 Nov 2017 19:44:38 -0500 Received: from mail-ua0-f195.google.com ([209.85.217.195]:34027 "EHLO mail-ua0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753543AbdK3Aog (ORCPT ); Wed, 29 Nov 2017 19:44:36 -0500 Received: by mail-ua0-f195.google.com with SMTP id d26so4680019uak.1 for ; Wed, 29 Nov 2017 16:44:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=fiAp8i+/LICVgIPPRleCo7LZ8Ybs8j4ua29iKuwYD00=; b=Sa0pw2KuiayjReX4BihRdyti/2frQ2qQ8YXK4xH0/pKh82O5e2Szl+swjPiIAldQzT U00f9BaBku2Ax76HAMPHvD7wI1+d9PRUgmqcCpuTD2Rs4xZky0ln3xh020hpZ7O/e28e d1QAUk7A9MygxJS0BRrm0EDKC+bjDmUYHhSvEozuehkixLGvVLhav4we1p1OKGek5EXz bxiitLypyiYra4FYVVbmNKj3kwDuAvyybngMQ5FXBCfUgHXDmnaIlvJvljrYzPiZ2dGD jDuXKpPw/jMM9dTF0fTeD9Q/MiACtrLSwzkm5Vv7dvCv51ntPfezjAd/wDPwfna3KcAJ q9vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=fiAp8i+/LICVgIPPRleCo7LZ8Ybs8j4ua29iKuwYD00=; b=eMYkL0Afl0e6rMKFcIrkNGPKWwe+/plNGLj7mFgGyKVVZp9aQa+zX8XrqCaYFesNCb kCSj3AjZu9Lt++JORDwXv3jcpMHbiWB4fY6PgHqSwHUh5c3BfhA1ziG+nm69CzpVO1jJ 49qGj0x2nwr5X9GLWDt7hfhf15MGOWcB4hwtKw+fY6nQIWFuXsuwWPga1g6JHrbk9397 G9eOXwjJ8o8JJxWEgt3dbgUh62KiN/M9j6Fy12DgB/n5y3tevABhgdA7oEeuNPSb2kVy sIj5oqaK9DkcFEDTNuvcm0TalhRTJkJ80rCbQJ8h4RN1IEgJ1RIoYpHuc8XIex6rJq3Q B+yQ== X-Gm-Message-State: AKGB3mKOOq3Dd0M1QfgvrprscQ4+XMhgXJl2ORMRr8K1c4Wznte7ay9B gpxmd3D0y8QCebBrKG+83B9BNNuPiyuJ+g4V6uAiGA== X-Received: by 10.176.8.201 with SMTP id o9mr623070uaf.155.1512002675464; Wed, 29 Nov 2017 16:44:35 -0800 (PST) MIME-Version: 1.0 Received: by 10.31.146.68 with HTTP; Wed, 29 Nov 2017 16:44:34 -0800 (PST) In-Reply-To: <20171116141151.21171-3-enric.balletbo@collabora.com> References: <20171116141151.21171-1-enric.balletbo@collabora.com> <20171116141151.21171-3-enric.balletbo@collabora.com> From: Doug Anderson Date: Wed, 29 Nov 2017 16:44:34 -0800 Message-ID: Subject: Re: [RFC v2 2/2] backlight: pwm_bl: compute brightness of LED linearly to human eye. To: Enric Balletbo i Serra Cc: Daniel Thompson , Jingoo Han , Richard Purdie , Jacek Anaszewski , Pavel Machek , Rob Herring , Brian Norris , Guenter Roeck , Lee Jones , Alexandru Stan , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Thu, Nov 16, 2017 at 6:11 AM, Enric Balletbo i Serra wrote: > When you want to change the brightness using a PWM signal, one thing you > need to consider is how human perceive the brightness. Human perceive the > brightness change non-linearly, we have better sensitivity at low > luminance than high luminance, so to achieve perceived linear dimming, th= e > brightness must be matches to the way our eyes behave. The CIE 1931 > lightness formula is what actually describes how we perceive light. > > This patch adds support to compute the brightness levels based on a stati= c > table filled with the numbers provided by the CIE 1931 algorithm, for now > it only supports PWM resolutions up to 65535 (16 bits) with 1024 steps. > Lower PWM resolutions are implemented using the same curve but with less > steps, e.g. For a PWM resolution of 256 (8 bits) we have 37 steps. Your patch assumes that the input to your formula (luminance, I think) scales linearly with PWM duty cycle. I don't personally know this, but has anyone confirmed it's common in reality, or at least is a close enough approximation of reality? > The calculation of the duty cycle using the CIE 1931 algorithm is enabled= by > default when you do not define the 'brightness-levels' propriety in your > device tree. One note is that you probably still want at least a "min" duty cycle. I seem to remember some PWM backlights don't work well when the duty cycle is too low and it would still be nice to be able to use your table. > Signed-off-by: Enric Balletbo i Serra > --- > drivers/video/backlight/pwm_bl.c | 160 +++++++++++++++++++++++++++++++++= ++---- > include/linux/pwm_backlight.h | 1 + > 2 files changed, 147 insertions(+), 14 deletions(-) Something I'd like to see in a patch somewhere in this series is a way to expose the backlight "units" to userspace. As far as I know right now the backlight exposed to userspace is "unitless", but it would be nice for userspace to query that the backlight is now linear to human perception. For old code, it could always expose the unit as "unknown". > diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/p= wm_bl.c > index 59b1bfb..ea96358 100644 > --- a/drivers/video/backlight/pwm_bl.c > +++ b/drivers/video/backlight/pwm_bl.c > @@ -26,6 +26,112 @@ > > #define NSTEPS 256 > > +/* > + * CIE lightness to PWM conversion table. The CIE 1931 lightness formula= is what > + * actually describes how we perceive light: > + * > + * Y =3D (L* / 902.3) if L* =E2=89=A4 0.08856 > + * Y =3D ((L* + 16) / 116)^3 if L* > 0.08856 > + * > + * Where Y is the luminance (output) between 0.0 and 1.0, and L* is the > + * lightness (input) between 0 and 100. Just because I'm stupid and not 100% sure, I think: luminance =3D the amount of light coming out of the screen lightness =3D how bright a human perceives the screen to be Is that right? If so could you add it to the comments? So "output" here is the output to the PWM and "input" is the input from userspace (and thus should be expressed in terms of human perception). > + 0, 7, 14, 21, 28, 35, 43, 50, 57, 64, 71, 78, 85, 92, 99, 106, 11= 4, 121, Seems like you could save space (and nicely use the previous patch) by using the linear interpolation code from the previous patch, since 0 + 7 =3D 7 + 7 =3D 14 + 7 =3D 21 + 7 =3D 28 + 7 =3D 35 ...and it would likely be OK to keep going and be slight off, so: + 7 =3D 42 + 7 =3D 49 + 7 =3D 56 + 7 =3D 63 + 7 =3D 70 ... ... In other words it seems like you're just providing a default table... -Doug From 1584241125376833263@xxx Thu Nov 16 16:34:32 +0000 2017 X-GM-THRID: 1584241125376833263 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread