Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3627082ybi; Mon, 10 Jun 2019 13:40:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqxqTx2XyDR1JK4gfamuRrK5f/zEugdrJV5fbI+vQw+Cvw4i+9eZytnMb+JX/zzCm2eBmgMs X-Received: by 2002:aa7:8108:: with SMTP id b8mr77316914pfi.205.1560199232914; Mon, 10 Jun 2019 13:40:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560199232; cv=none; d=google.com; s=arc-20160816; b=bAsBfyCWCdHLlQiu3wqHMZsxz5z3yJIJtKREy3AAYnbSykPtgDUnfbu+5NgbNn1s4P Ju0UAUKcbGh+hJQpD0S7DonLkxgjuQj1B4910qkXM3E+X6AUQiWg1o/5eRKr2pFhzvpa wCAdWL6lxWJNqc/M7RkOWtkAPx0+GzyYcfTSzn5NP4iWiHyHt6VHNeBKHXSLHYGz6M4s 4hao3rf7NAHEj0vITMafs5PLPU8IAAMl6/zYQ2rkO04Z7A4WW8OqOLldGpkxD//iIZfo fJc4gknxpcqLqFokavhkZlxzy1Zv1fgWgNOM9FK8aqDJwN2j1rxyey+N8YhubndyiWOQ rKyA== 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=cFNnx6L3NQaEKxP/8K3frHUq1rFUCkpHgDob39ijY5g=; b=Y+9XcxyGHTC1kp/MlOWoAUloikeGi0EXU8Tp2vE2sJ15tg7kskircJqTpWOibueUyU Iyqf+zyok07QK25ffCbXI/6lJ0gfhqPGr4QjZtpLZ4UF2yMItFFpFMGxocfhONNUyjTH o2DL/qOoNJH9RFSid0zdW3F1bmdJZeXKKDr001ywGsp9Uhcc/O2kKmhPNNLK17CCyuHs spaM3ieYK4ZmMk1GdETNXkVL3SFactDDhZPXUxSV5z0l3wW4qWg911prdAL3C4xSL1F1 67vyW/9fOqZ8lFfV1BdX+GiNwM3S+Q5xX0hodO/bcUEwvrcyUIw44yTsfsiTkYex54d8 OW6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=nTiLWlQR; 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 r140si11029640pgr.29.2019.06.10.13.40.17; Mon, 10 Jun 2019 13:40:32 -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=nTiLWlQR; 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 S2389703AbfFJUjc (ORCPT + 99 others); Mon, 10 Jun 2019 16:39:32 -0400 Received: from mail-pf1-f180.google.com ([209.85.210.180]:33106 "EHLO mail-pf1-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389331AbfFJUjc (ORCPT ); Mon, 10 Jun 2019 16:39:32 -0400 Received: by mail-pf1-f180.google.com with SMTP id x15so5982578pfq.0 for ; Mon, 10 Jun 2019 13:39:31 -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=cFNnx6L3NQaEKxP/8K3frHUq1rFUCkpHgDob39ijY5g=; b=nTiLWlQRWOOai+AcxpoBEJbMuF+pVTFt3BBsdGsjBOfzmaVbCKcFK4s23SNo7e2GTJ jtJwXoqfHvpq4Np+08z9PvSLKiHZVRf80d/XzE7Wn/rC2nS4tJyoONnw7T6sQ/wwJBOZ iHfLawG6mwBu3z8LTK8RLQahT1Mt4eKFXWYu0= 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=cFNnx6L3NQaEKxP/8K3frHUq1rFUCkpHgDob39ijY5g=; b=mYQKF1yFWCpg1eyzq3uFUjBK1GIa62f0H6pIB4cVMhPSaU//ekPaqdcBSo1v63atot zfszMLwE+GS6cVEnts84TwYgDpxLQLO1zmmkdVddJ2GvvvGTWkk5TP+Si/i0Vyytp8Vu +aT4aRy3KfHtbaD+JsMFWewF22miyIgrEq+9HKOydPwktbDD+lDExaLIVZRH85tZmycZ LvNyxo0R+V+aMlsXYHCCw8T8rJxDsRivR3CLttkn6bdMVxdHuRXmbD0RH2K+7fJ61eOI UrQG14aNBF44ze1MXd2n7EXsi1KyWimgJqL4WvdTi7dFSmSVlNI9fOYgfuq7k8SbDmVF 7dmw== X-Gm-Message-State: APjAAAVtEhgOrwv4YeH7tpBU46Pe1Fh6P6vY/qBczggDz7WxBk+gWOPy /YCGCwssirCKPp7iPb5ZN3rGxQ== X-Received: by 2002:a65:4786:: with SMTP id e6mr17183159pgs.85.1560199171334; Mon, 10 Jun 2019 13:39:31 -0700 (PDT) Received: from localhost ([2620:15c:202:1:75a:3f6e:21d:9374]) by smtp.gmail.com with ESMTPSA id n127sm11632938pga.57.2019.06.10.13.39.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 10 Jun 2019 13:39:30 -0700 (PDT) Date: Mon, 10 Jun 2019 13:39:28 -0700 From: Matthias Kaehlcke To: Enric Balletbo i Serra Cc: Pavel Machek , Daniel Thompson , Doug Anderson , Rob Herring , Jingoo Han , Richard Purdie , Jacek Anaszewski , Brian Norris , Guenter Roeck , Lee Jones , Alexandru Stan , linux-leds@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com Subject: Re: [PATCH v3 3/4] backlight: pwm_bl: compute brightness of LED linearly to human eye. Message-ID: <20190610203928.GA137143@google.com> References: <20180208113032.27810-1-enric.balletbo@collabora.com> <20180208113032.27810-4-enric.balletbo@collabora.com> <20190607220947.GR40515@google.com> <20190608210226.GB2359@xo-6d-61-c0.localdomain> <819ecbcd-18e3-0f6b-6121-67cb363df440@collabora.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <819ecbcd-18e3-0f6b-6121-67cb363df440@collabora.com> 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 Enric On Mon, Jun 10, 2019 at 12:00:02PM +0200, Enric Balletbo i Serra wrote: > Hi Matthias, > > On 8/6/19 23:02, Pavel Machek wrote: > > Hi! > > > >>> + * Note that this method is based on empirical testing on different > >>> + * devices with PWM of 8 and 16 bits of resolution. > >>> + */ > >>> + n = period; > >>> + while (n) { > >>> + counter += n % 2; > >>> + n >>= 1; > >>> + } > >> > >> I don't quite follow the heuristics above. Are you sure the number of > >> PWM bits can be infered from the period? What if the period value (in > >> ns) doesn't directly correspond to a register value? And even if it > >> did, counting the number of set bits (the above loops is a > >> re-implementation of ffs()) doesn't really result in the dividers > >> mentioned in the comment. E.g. a period of 32768 ns (0x8000) results > >> in a divider of 1, i.e. 32768 brighness levels. > >> > > Right, I think that only works on the cases that we only have one pwm cell, and > looks like during my tests I did only tests on devices with one pwm cell :-( > > And as you point the code is broken for other cases (pwm-cells > 1) > > >> On veyron minnie the period is 1000000 ns, which results in 142858 > >> levels (1000000 / 7)! > >> > >> Not sure if there is a clean solution using heuristics, a DT property > >> specifying the number of levels could be an alternative. This could > >> also be useful to limit the number of (mostly) redundant levels, even > >> the intended max of 4096 seems pretty high. > >> > > Looking again looks like we _can not_ deduce the number of bits of a pwm, it is > not exposed at all, so I think we will need to end adding a property to specify > this. Something similar to what leds-pwm binding does, it has: > > max-brightness : Maximum brightness possible for the LED Thanks for the confirmation that I didn't just miss some clever trick. I also think that some kind of DT property is needed, I'll try to come up with a reasonable name, keeping in mind that some devices might not want to use the entire range of levels.