Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4654348ybi; Tue, 11 Jun 2019 10:09:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqx9o1R8DBpQVyEmozhNlwAj0g6mAKFW3s8G8cyK+5Qk92DUywSD8XcRFb2/HsAh6AjVQgwz X-Received: by 2002:a63:1657:: with SMTP id 23mr19943724pgw.98.1560272978338; Tue, 11 Jun 2019 10:09:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560272978; cv=none; d=google.com; s=arc-20160816; b=qdEOqRaNrPmC/Y+Y8KtWPt/DtkfhflE5HB5Z8wxWH+q85e4HX7X2QyziMQ+WxT3gGl Mv2c0OANKoFzrxPelcZZb4oSfHZjcvj6pnn5tExAbeOQh0DyrHX/aUi/Ms/vehvLuIFo BRuhCLGRcjmSg3JM6Szliv823eSVO6e6AgfZx9bFcqiZ6fEf1LyUoU+E56xSuGdgxlbT sykAX9wf9lyBju/r1yL5K6PUQacl0LwXksi7qYYZrMBl5ZWsoCJyZyQK0Zyf6sf716z7 PFV6Ey+9ALMyeCt+n6naxcLbIZIoAjgC3tIU4zcZHFYdB6j1TPAks1jveKNlCYrEONYH zQfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=D/6K52cqkgjun9QL50SRby3oaZewpSvBQVwA1lCewfo=; b=rnYFwe/P44IgbIl4XeWhTvkB5S8QhzsVdVTfFn6op8peHd5LehDSSRp0vC9jBgDsVw ZoWdN1qlAMgU716VUa/1EzEkI/53DkxvLI1hYDEsqLtLBqcBm1FWs+18Gep9WreAXoNQ EeQwGvPpY8ddyIUR3jQf7lXGWxzQ9R2dTuGKUST0pC0wgkmresO5tQ+7OUdTOMhrGQuy 4bvyEf4bOD8y8xvW4AhgLjwlDTeX5843YDQH/04Grtn0RJpsmUNnCrVNRfAMhvUxziOl mQQVUp2y3nbp3tx2XHAgZnTOXXXZLZvDcB3Ngk16ahVMbf/HRww+uAT8d9RD5dik6uTH Yxwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=XtFdaHCT; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b3si13556396plb.367.2019.06.11.10.09.22; Tue, 11 Jun 2019 10:09:38 -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=@chromium.org header.s=google header.b=XtFdaHCT; 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=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2405021AbfFKRB1 (ORCPT + 99 others); Tue, 11 Jun 2019 13:01:27 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:44436 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404944AbfFKRB1 (ORCPT ); Tue, 11 Jun 2019 13:01:27 -0400 Received: by mail-pg1-f193.google.com with SMTP id n2so7287303pgp.11 for ; Tue, 11 Jun 2019 10:01:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=D/6K52cqkgjun9QL50SRby3oaZewpSvBQVwA1lCewfo=; b=XtFdaHCTpTDf0qQhQfuAjHKGqAns0vrUqrQg02/8jVmR8p0ZzKKlHKnR9VJJBokSNm ZgAQrr+A/h9J30599wfzOGisk8Qu8DlWAbSCBG5dzc6KA8829UtBGHKxwnkcRV2MXxbW ILseuhOSbtocL+Hw4Y3nT83V4Ab6Y2qlkb2SU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=D/6K52cqkgjun9QL50SRby3oaZewpSvBQVwA1lCewfo=; b=a9pVliwxELH88mWmReZxlWzCEF5aUAHl2eC5ss/e19s0oy+4iKlNr8h/bTCn1PA3Cm +NWsLj5JL9Ll6IwVwpckpovAHuxFXaUX3/M18BPc09ORrdGyN9MeBOzvJFBYck66215E NFly+85kK2fBQcr2rwxDXGOeFSWbfldoFpB7w1WETqkOKRCdFzrDDFQT/lcTLSgwpYS9 jVe8zmprSrOtnmittkfxMsIIkUC9vcsx++DmUyBBF56LN42YJdeMiioeuwHmuh4pKv67 VV5awohVEHw5k7+bNOycppdi57Jxs7gdMLGoyFoZLetXKioTjT0XFdy7bteb63STL1Et hojg== X-Gm-Message-State: APjAAAWAOdO6AUaTbiIyoWss2GQDB9ylMSErZsvNPSaNWivPRW+pkaNU nIFM8QMFvY7ufHdqb4tbX10ZZA== X-Received: by 2002:a63:4e10:: with SMTP id c16mr20869964pgb.214.1560272486514; Tue, 11 Jun 2019 10:01:26 -0700 (PDT) Received: from localhost ([2620:15c:202:1:75a:3f6e:21d:9374]) by smtp.gmail.com with ESMTPSA id p1sm5962781pff.74.2019.06.11.10.01.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Jun 2019 10:01:25 -0700 (PDT) Date: Tue, 11 Jun 2019 10:01:23 -0700 From: Matthias Kaehlcke To: Daniel Thompson Cc: Lee Jones , Jingoo Han , Jacek Anaszewski , Pavel Machek , Rob Herring , Mark Rutland , Thierry Reding , Bartlomiej Zolnierkiewicz , Enric Balletbo i Serra , dri-devel@lists.freedesktop.org, linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, linux-fbdev@vger.kernel.org, Douglas Anderson , Brian Norris Subject: Re: [PATCH 2/2] backlight: pwm_bl: Get number of brightness levels for CIE 1931 from the device tree Message-ID: <20190611170123.GD137143@google.com> References: <20190610233739.29477-1-mka@chromium.org> <20190610233739.29477-2-mka@chromium.org> <20190611153314.cj6j6l4kcl4kk4t2@holly.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20190611153314.cj6j6l4kcl4kk4t2@holly.lan> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Daniel, On Tue, Jun 11, 2019 at 04:33:14PM +0100, Daniel Thompson wrote: > On Mon, Jun 10, 2019 at 04:37:39PM -0700, Matthias Kaehlcke wrote: > > Commit 88ba95bedb79 ("backlight: pwm_bl: Compute brightness of LED > > linearly to human eye") uses pwm_period / hweight32(pwm_period) as > > as heuristic to determine the number of brightness levels when the DT > > doesn't provide a brightness level table. This heuristic is broken > > and can result in excessively large brightness tables. > > > > Instead of using the heuristic try to retrieve the number of > > brightness levels from the device tree (property 'max-brightness' > > + 1). If the value is not specified use a default of 256 levels. > > I'll look at the code tomorrow but why 256? > > To me it feels simultaneously too big for a simple 8-bit PWM and too > small for animated backlight effects. I agree there is no one-size-fits-it-all default, 256 seemed like a possible compromise. > I certainly agree that an override could be useful but I'm not clear why > deriving a default based on the period is bogus (and the description is > merely concerned about uselessly big tables). Maybe it's not necessarily bogus, but the current heuristic that counts the number of set bits (hweight()) in the period certainly is. IIUC the period provides a clue about the PWM resolution, because it would be hard/impossible to accomodate the high resolution in shorter periods. > /* > * Once we have 4096 levels there's little point going much higher... > * neither interactive sliders nor animation benefits from having > * more values in the table. > */ > max_brightness = min(DIV_ROUND_UP(period, ffs(period), 4096); I was also considering something along these lines, but wasn't sure if there is indeed a relation between the period and the PWM resolution. I take your suggestion as a confirmation :)