Received: by 10.223.164.202 with SMTP id h10csp337377wrb; Thu, 30 Nov 2017 11:07:52 -0800 (PST) X-Google-Smtp-Source: AGs4zMY/OUKawlYQnPSrcB9e3PCeajlQ7Bl+T8S96Cx+dFjPqIFiwwNwEgjuN5eTg+z6tCGSctkN X-Received: by 10.98.87.142 with SMTP id i14mr7680939pfj.212.1512068872161; Thu, 30 Nov 2017 11:07:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512068872; cv=none; d=google.com; s=arc-20160816; b=1LEpNzt1qP1ZbEnKk9b3vQ2yIvCyCvhAhPk8WK5/94nvZvBYvvTLL+nEa7c/ZFfBt3 9QxeMJEneUFCGwkpYIh3qACBu8H4Mq8Tvjy0eQw+hE1TXiQD/kAeDHA7WsQh79k/ZJFY dnJQrmofJRq1NW3Ogmlo6y+NttHFVTTHrAM+Gl0VKcYovZ8G9BNErAwwQHlsT7Gnx4i5 gJowTTxq0Y4wQB6q4mS29XVIhkBjnZgkeSrmN84jKOBmTJ3G1Quv7yyTPsU+SC9Rp1NW ZNnfPg/PipYMnc1ZKStYdyNO4WwapGZXOySQ0Yjw3Lc+YLi4o4Su0Yg/YAL/8RQ+BbNc uQpQ== 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=8FM31BFVtgVdcBF1fWU5cOZDF8OrDVz+bOtxuOBPAhI=; b=j11FUE60s89ENwG29w3ps//PR+0BJzY/rjRf2SzMA33I36dAhcSJomk04lw8M2CIA9 Ll8wVYwEo8OsGyz6icxA6m3O8x9E4yZ6+jPWY+INzdwVkF6OytywzTqIpzmbB+OmYqXx s8cICx48Ce/3G7lM0kBGWt2H7fhTPs65fGanOlaQrdws9WMoPsYv2DARalQxizC+SLk2 INDjYI2r0ZZ7fdSCeUgRbqfmc0CDOaGI38uabOZuo2P4QjSYzFNB0vhTx98rWlAY1vih 7PfmvkptdmctchKQERxIUAN4nRjNDybYhk7QybO7uFJ6JHiTkyCUwldK2YgG+kpTEyyW MyNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=ERxoqtKD; 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 y3si3364527pgp.554.2017.11.30.11.07.36; Thu, 30 Nov 2017 11:07:52 -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=ERxoqtKD; 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 S1751695AbdK3TGU (ORCPT + 99 others); Thu, 30 Nov 2017 14:06:20 -0500 Received: from mail-vk0-f45.google.com ([209.85.213.45]:46111 "EHLO mail-vk0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750842AbdK3TGS (ORCPT ); Thu, 30 Nov 2017 14:06:18 -0500 Received: by mail-vk0-f45.google.com with SMTP id 138so4074106vko.13 for ; Thu, 30 Nov 2017 11:06:17 -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=8FM31BFVtgVdcBF1fWU5cOZDF8OrDVz+bOtxuOBPAhI=; b=ERxoqtKD12bbUvNfnYWKo3VIJNCh/8B4NV449ccOVADUQRqpDWfRit+0Px4fpEa2Dc e43urw/hG5XLhaYltWKxUAOAuYqyOWoG47iJl+fk7vkB2dMAMQOHluEuNZe26NyDWuNE kWQ75Z5WSC0RIpNU/U2YEHv2sLN5n8RRactbh+BY0sEf6JsrMU+t2FPcPLylwMe9O+P1 jWs43M8RGhkYkuJYnyfxMRB8Wz0ObDf0tTvZE9xlk65C54gejA00bH/dm0OhGGwpEq03 gOqVlMNffGU8Yl/Dt7BA3Lq5+xlguz+Wn+jqr5TCgMpqA57H2jhvIlx08eFtDB1c94zg vNuQ== 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=8FM31BFVtgVdcBF1fWU5cOZDF8OrDVz+bOtxuOBPAhI=; b=Jv2eYvhVEdY8O8SZh40/XYV9A2/3dm4X4423QgIUp/hEoOlDOIlaNLpXOmet6NFBLc RFsTtcGVE1KrTNyQg9BodxtxutpUsoOPyKoIGMj34R/BHMYcmrZStrBKxWh+/ahwmLES gKOk2ku3rfqN4phqC+gm+iPdh5ghFYhKhe3s1OBDie20n65oFAA1hNSlCDQHZ33c8QSV 4kLpDPaeugB2ypyR6w6KTvhLzXKeyj4ejc1/UVoohAF/DBP6RQoJu+JUynU8Co1lj4Li cAzd0TLffAw2fthheNPm8KtROEcSTE3MlxEmIqMejCmidEFIz85qtk6bVPQLG4vv8ALd q++A== X-Gm-Message-State: AKGB3mJe8LdXgYz+D9dJrkDYHrP+HRfuCn6kiKrG/Gvh0OMhT9D/XARf Wgn9hgKAIzJpRQA1bv4Xy47HZN95HjhC1MannJb/CQ== X-Received: by 10.31.226.71 with SMTP id z68mr2515734vkg.195.1512068776675; Thu, 30 Nov 2017 11:06:16 -0800 (PST) MIME-Version: 1.0 Received: by 10.31.146.68 with HTTP; Thu, 30 Nov 2017 11:06:15 -0800 (PST) In-Reply-To: References: <20171116141151.21171-1-enric.balletbo@collabora.com> <20171116141151.21171-3-enric.balletbo@collabora.com> From: Doug Anderson Date: Thu, 30 Nov 2017 11:06:15 -0800 Message-ID: Subject: Re: [RFC v2 2/2] backlight: pwm_bl: compute brightness of LED linearly to human eye. To: Enric Balletbo Serra Cc: Daniel Thompson , Enric Balletbo i Serra , 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 30, 2017 at 10:34 AM, Enric Balletbo Serra wrote: > Hi, > > 2017-11-30 12:27 GMT+01:00 Daniel Thompson : >> >> >> On 30/11/17 00:44, Doug Anderson wrote: >>> >>> 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 y= ou >>>> 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, >>>> the >>>> 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 >>>> static >>>> 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 le= ss >>>> 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? >> >> >> Isn't this the loop we went round for v1? >> >> We do know that its not linear, however the graphs from a couple of exam= ple >> devices didn't look too scary and nobody has proposed a better formula. >> >> At this point the linear interpolation code in patch 1 allows people wit= h >> especially alinear devices to express suitable brightness curves. >> >> However we also know that many DT authors choose not to create good >> brightness tables for their devices... and we'd rather they used allowed= the >> kernel to choose a model than to use no model at all. >> >> >> Daniel. >> >> >> >> Enric: BTW sorry I haven't replied so far. That's mostly because >> these looked more "real" and that I should pay them close >> attention (which requires time I haven't had spare to >> consume yet). >> > > No problem. It also took me some time to send v2 because of was busy > with other things :) > >> >> >>>> The calculation of the duty cycle using the CIE 1931 algorithm is enab= led >>>> by >>>> default when you do not define the 'brightness-levels' propriety in yo= ur >>>> 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. >>> > > Right, iirc that is needed on some veyron devices, and this is another > reason why the first patch needs to support to be able to describe > corrected gamma curves and not only linear-interpolation between 2 > points. I'd say that: > > 1. For low and high resolution PWMs, if you know nothing about PWM > backlight, patch 2 can provide to the user a default table that should > work. > 2. If you need something more specific you should use the old way > (aka, use brightness levels table) > 2.1 If you have a high resolution PWM you might be interested on > enable interpolation. The thing I was thinking was that it might be very common to have a min PWM duty cycle. It would be a shame if patch set #2 was almost a perfect fit but you were forced to specify a table in the device tree (to get your output to be linear w/ respect to human perception) just because you had a minimum duty cycle. >>>> 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/pwm_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 form= ula >>>> 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 t= he >>>> + * lightness (input) between 0 and 100. >>> >>> >>> Just because I'm stupid and not 100% sure, I think: >>> > > Just because I'm also stupid and I'm still learning :) I'll try to > clarify a bit more that ... > > >>> 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). >>> > > Yes, I think that how you describe luminance and lightness is right, > and sounds good improve the doc. > > To be clear the correction table for PWM values can be calculated with > this code. > > OUTPUT_SIZE =3D 65535 # Output integer size > INPUT_SIZE =3D 2047 > > def cie1931(L): > L =3D L*100.0 > if L <=3D 8: > return (L/902.3) > else: > return ((L+16.0)/116.0)**3 > > x =3D range(0,int(INPUT_SIZE+1)) > y =3D [int(round(cie1931(float(L)/INPUT_SIZE)*(OUTPUT_SIZE))) for L in x] Personally I'd love to see that little bit of code in the commit message to help explain where the table came from, though I'm known for putting PhD theses in my commit messages... ;) >>>> + 0, 7, 14, 21, 28, 35, 43, 50, 57, 64, 71, 78, 85, 92, 99, 106, >>>> 114, 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... >>> > > Yes, I think that's the Daniel idea ;) > >>> -Doug >>> >> > > Best regards, > - Enric From 1585517035857472791@xxx Thu Nov 30 18:34:35 +0000 2017 X-GM-THRID: 1584241125376833263 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread