linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniel Thompson <daniel.thompson@linaro.org>
To: Matthias Kaehlcke <mka@chromium.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	Lee Jones <lee.jones@linaro.org>,
	Jingoo Han <jingoohan1@gmail.com>,
	Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
Cc: linux-pwm@vger.kernel.org, dri-devel@lists.freedesktop.org,
	linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	Enric Balletbo i Serra <enric.balletbo@collabora.com>,
	Douglas Anderson <dianders@chromium.org>,
	Brian Norris <briannorris@chromium.org>,
	Pavel Machek <pavel@ucw.cz>,
	Jacek Anaszewski <jacek.anaszewski@gmail.com>
Subject: Re: [PATCH 4/4] backlight: pwm_bl: Set scale type for brightness curves specified in the DT
Date: Fri, 21 Jun 2019 13:10:19 +0000	[thread overview]
Message-ID: <9ea1bb40-95a6-7a67-a8a6-ecc77a70e547@linaro.org> (raw)
In-Reply-To: <20190613194326.180889-5-mka@chromium.org>

On 13/06/2019 20:43, Matthias Kaehlcke wrote:
> Check if a brightness curve specified in the device tree is linear or
> not and set the corresponding property accordingly. This makes the
> scale type available to userspace via the 'scale' sysfs attribute.
> 
> To determine if a curve is linear it is compared to a interpolated linear
> curve between min and max brightness. The curve is considered linear if
> no value deviates more than +/-5% of ${brightness_range} from their
> interpolated value.
> 
> Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
> ---
>   drivers/video/backlight/pwm_bl.c | 25 +++++++++++++++++++++++++
>   1 file changed, 25 insertions(+)
> 
> diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
> index f067fe7aa35d..912407b6d67f 100644
> --- a/drivers/video/backlight/pwm_bl.c
> +++ b/drivers/video/backlight/pwm_bl.c
> @@ -404,6 +404,26 @@ int pwm_backlight_brightness_default(struct device *dev,
>   }
>   #endif
>   
> +static bool pwm_backlight_is_linear(struct platform_pwm_backlight_data *data)
> +{
> +	unsigned int nlevels = data->max_brightness + 1;
> +	unsigned int min_val = data->levels[0];
> +	unsigned int max_val = data->levels[nlevels - 1];
> +	unsigned int slope = (100 * (max_val - min_val)) / nlevels;

Why 100 (rather than a power of 2)?

It would also be good to have a comment here saying what the maximum 
quantization error is. Doesn't have to be over complex just mentioning 
something like the following (assuming you agree that its true ;-) ):

   Multiplying by XXX means that even in pathalogical cases such as
   (max_val - min_val) = nlevels then the error at max_val is less than
   1%.

With a suitable comment in the fixed point code:
Acked-by: Daniel Thompson <daniel.thompson@linaro.org>


Daniel.


> +	unsigned int margin = (max_val - min_val) / 20; /* 5% */
> +	int i;
> +
> +	for (i = 1; i < nlevels; i++) {
> +		unsigned int linear_value = min_val + ((i * slope) / 100);
> +		unsigned int delta = abs(linear_value - data->levels[i]);
> +
> +		if (delta > margin)
> +			return false;
> +	}
> +
> +	return true;
> +}
> +
>   static int pwm_backlight_initial_power_state(const struct pwm_bl_data *pb)
>   {
>   	struct device_node *node = pb->dev->of_node;
> @@ -567,6 +587,11 @@ static int pwm_backlight_probe(struct platform_device *pdev)
>   
>   			pb->levels = data->levels;
>   		}
> +
> +		if (pwm_backlight_is_linear(data))
> +			props.scale = BACKLIGHT_SCALE_LINEAR;
> +		else
> +			props.scale = BACKLIGHT_SCALE_NON_LINEAR;
>   	} else if (!data->max_brightness) {
>   		/*
>   		 * If no brightness levels are provided and max_brightness is
> 

  reply	other threads:[~2019-06-21 13:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-13 19:43 [PATCH 0/4] backlight: Expose brightness curve type through sysfs Matthias Kaehlcke
2019-06-13 19:43 ` [PATCH 1/4] MAINTAINERS: Add entry for stable backlight sysfs ABI documentation Matthias Kaehlcke
2019-06-19 11:05   ` Daniel Thompson
2019-06-13 19:43 ` [PATCH 2/4] backlight: Expose brightness curve type through sysfs Matthias Kaehlcke
2019-06-13 21:56   ` Matthias Kaehlcke
2019-06-13 19:43 ` [PATCH 3/4] backlight: pwm_bl: Set scale type for CIE 1931 curves Matthias Kaehlcke
2019-06-19  9:17   ` Enric Balletbo i Serra
2019-06-21 12:55   ` Daniel Thompson
2019-06-27  9:24     ` Lee Jones
2019-06-27 15:49       ` Daniel Thompson
2019-06-13 19:43 ` [PATCH 4/4] backlight: pwm_bl: Set scale type for brightness curves specified in the DT Matthias Kaehlcke
2019-06-21 13:10   ` Daniel Thompson [this message]
2019-06-24 18:54     ` Matthias Kaehlcke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9ea1bb40-95a6-7a67-a8a6-ecc77a70e547@linaro.org \
    --to=daniel.thompson@linaro.org \
    --cc=b.zolnierkie@samsung.com \
    --cc=briannorris@chromium.org \
    --cc=dianders@chromium.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=enric.balletbo@collabora.com \
    --cc=jacek.anaszewski@gmail.com \
    --cc=jingoohan1@gmail.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pwm@vger.kernel.org \
    --cc=mka@chromium.org \
    --cc=pavel@ucw.cz \
    --cc=thierry.reding@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).