From 5076fbed57f7f58c839e7ea5a2495c1d083417ae Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Wed, 19 Jun 2019 16:59:27 +0300 Subject: backlight: pwm_bl: Convert to use SPDX identifier Reduce size of duplicated comments by switching to use SPDX identifier. No functional change. While here, correct MODULE_LICENSE() string to be aligned with license text. Signed-off-by: Andy Shevchenko Acked-by: Daniel Thompson Signed-off-by: Lee Jones --- drivers/video/backlight/pwm_bl.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'drivers') diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index fb45f866b923..1f7f8d5c0bf1 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -1,13 +1,8 @@ +// SPDX-License-Identifier: GPL-2.0 /* - * linux/drivers/video/backlight/pwm_bl.c - * - * simple PWM based backlight control, board code has to setup + * Simple PWM based backlight control, board code has to setup * 1) pin configuration so PWM waveforms can output * 2) platform_data being correctly configured - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. */ #include @@ -708,5 +703,5 @@ static struct platform_driver pwm_backlight_driver = { module_platform_driver(pwm_backlight_driver); MODULE_DESCRIPTION("PWM based Backlight Driver"); -MODULE_LICENSE("GPL"); +MODULE_LICENSE("GPL v2"); MODULE_ALIAS("platform:pwm-backlight"); -- cgit v1.2.3-58-ga151 From 98b7404eb7d64e55f8fdd419cb3965a8abf0e217 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Wed, 19 Jun 2019 18:21:27 +0300 Subject: backlight: gpio_backlight: Enable ACPI enumeration ACPI allows to enumerate specific devices by using compatible strings. Enable that enumeration for GPIO based backlight devices. Signed-off-by: Andy Shevchenko Acked-by: Daniel Thompson Signed-off-by: Lee Jones --- drivers/video/backlight/gpio_backlight.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) (limited to 'drivers') diff --git a/drivers/video/backlight/gpio_backlight.c b/drivers/video/backlight/gpio_backlight.c index e470da95d806..05c12df62b27 100644 --- a/drivers/video/backlight/gpio_backlight.c +++ b/drivers/video/backlight/gpio_backlight.c @@ -18,6 +18,7 @@ #include #include #include +#include #include struct gpio_backlight { @@ -61,11 +62,10 @@ static int gpio_backlight_probe_dt(struct platform_device *pdev, struct gpio_backlight *gbl) { struct device *dev = &pdev->dev; - struct device_node *np = dev->of_node; enum gpiod_flags flags; int ret; - gbl->def_value = of_property_read_bool(np, "default-on"); + gbl->def_value = device_property_read_bool(dev, "default-on"); flags = gbl->def_value ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; gbl->gpiod = devm_gpiod_get(dev, NULL, flags); @@ -89,26 +89,19 @@ static int gpio_backlight_probe(struct platform_device *pdev) struct backlight_properties props; struct backlight_device *bl; struct gpio_backlight *gbl; - struct device_node *np = pdev->dev.of_node; int ret; - if (!pdata && !np) { - dev_err(&pdev->dev, - "failed to find platform data or device tree node.\n"); - return -ENODEV; - } - gbl = devm_kzalloc(&pdev->dev, sizeof(*gbl), GFP_KERNEL); if (gbl == NULL) return -ENOMEM; gbl->dev = &pdev->dev; - if (np) { + if (pdev->dev.fwnode) { ret = gpio_backlight_probe_dt(pdev, gbl); if (ret) return ret; - } else { + } else if (pdata) { /* * Legacy platform data GPIO retrieveal. Do not expand * the use of this code path, currently only used by one @@ -129,6 +122,10 @@ static int gpio_backlight_probe(struct platform_device *pdev) gbl->gpiod = gpio_to_desc(pdata->gpio); if (!gbl->gpiod) return -EINVAL; + } else { + dev_err(&pdev->dev, + "failed to find platform data or device tree node.\n"); + return -ENODEV; } memset(&props, 0, sizeof(props)); @@ -149,19 +146,17 @@ static int gpio_backlight_probe(struct platform_device *pdev) return 0; } -#ifdef CONFIG_OF static struct of_device_id gpio_backlight_of_match[] = { { .compatible = "gpio-backlight" }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, gpio_backlight_of_match); -#endif static struct platform_driver gpio_backlight_driver = { .driver = { .name = "gpio-backlight", - .of_match_table = of_match_ptr(gpio_backlight_of_match), + .of_match_table = gpio_backlight_of_match, }, .probe = gpio_backlight_probe, }; -- cgit v1.2.3-58-ga151 From 73fbfc499448455f1e1c77717040e09e25f1d976 Mon Sep 17 00:00:00 2001 From: Matthias Kaehlcke Date: Wed, 12 Jun 2019 11:00:03 -0700 Subject: backlight: pwm_bl: Fix heuristic to determine number of brightness levels With commit 88ba95bedb79 ("backlight: pwm_bl: Compute brightness of LED linearly to human eye") the number of set bits (aka hweight()) in the PWM period is used in the heuristic to determine the number of brightness levels, when the brightness table isn't specified in the DT. The number of set bits doesn't provide a reliable clue about the length of the period, instead change the heuristic to: nlevels = period / fls(period) Also limit the maximum number of brightness levels to 4096 to avoid excessively large tables. With this the number of levels increases monotonically with the PWM period, until the maximum of 4096 levels is reached: period (ns) # levels 100 16 500 62 1000 111 5000 416 10000 769 50000 3333 100000 4096 Fixes: 88ba95bedb79 ("backlight: pwm_bl: Compute brightness of LED linearly to human eye") Signed-off-by: Matthias Kaehlcke Acked-by: Daniel Thompson Tested-by: Enric Balletbo i Serra Signed-off-by: Lee Jones --- drivers/video/backlight/pwm_bl.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) (limited to 'drivers') diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index 1f7f8d5c0bf1..abfd1bca2c11 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -189,29 +189,17 @@ int pwm_backlight_brightness_default(struct device *dev, struct platform_pwm_backlight_data *data, unsigned int period) { - unsigned int counter = 0; - unsigned int i, n; + unsigned int i; u64 retval; /* - * Count the number of bits needed to represent the period number. The - * number of bits is used to calculate the number of levels used for the - * brightness-levels table, the purpose of this calculation is have a - * pre-computed table with enough levels to get linear brightness - * perception. The period is divided by the number of bits so for a - * 8-bit PWM we have 255 / 8 = 32 brightness levels or for a 16-bit PWM - * we have 65535 / 16 = 4096 brightness levels. - * - * Note that this method is based on empirical testing on different - * devices with PWM of 8 and 16 bits of resolution. + * 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. */ - n = period; - while (n) { - counter += n % 2; - n >>= 1; - } + data->max_brightness = + min((int)DIV_ROUND_UP(period, fls(period)), 4096); - data->max_brightness = DIV_ROUND_UP(period, counter); data->levels = devm_kcalloc(dev, data->max_brightness, sizeof(*data->levels), GFP_KERNEL); if (!data->levels) -- cgit v1.2.3-58-ga151