diff options
author | George Stark <gnstark@salutedevices.com> | 2023-11-25 21:05:16 +0100 |
---|---|---|
committer | Lee Jones <lee@kernel.org> | 2023-12-13 12:29:00 +0100 |
commit | 150bca53652d8dcef9714d0873a86e129391f1e6 (patch) | |
tree | eb1bc19387e9de8612a2e608aed2254e4e328813 /drivers/leds/leds-aw200xx.c | |
parent | leds: aw200xx: Enable disable_locking flag in regmap config (diff) | |
download | linux-150bca53652d8dcef9714d0873a86e129391f1e6.tar.xz linux-150bca53652d8dcef9714d0873a86e129391f1e6.zip |
leds: aw200xx: Improve autodim calculation method
It is highly recommended to leverage the DIV_ROUND_UP() function as a
more refined and mathematically precise alternative to employing a
coarse division method.
Signed-off-by: George Stark <gnstark@salutedevices.com>
Signed-off-by: Dmitry Rokosov <ddrokosov@salutedevices.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/20231125200519.1750-9-ddrokosov@salutedevices.com
Signed-off-by: Lee Jones <lee@kernel.org>
Diffstat (limited to 'drivers/leds/leds-aw200xx.c')
-rw-r--r-- | drivers/leds/leds-aw200xx.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/drivers/leds/leds-aw200xx.c b/drivers/leds/leds-aw200xx.c index 220860258dec..fe9b1565cef0 100644 --- a/drivers/leds/leds-aw200xx.c +++ b/drivers/leds/leds-aw200xx.c @@ -87,6 +87,8 @@ #define AW200XX_REG_DIM(x, columns) \ AW200XX_REG(AW200XX_PAGE4, AW200XX_LED2REG(x, columns) * 2) #define AW200XX_REG_DIM2FADE(x) ((x) + 1) +#define AW200XX_REG_FADE2DIM(fade) \ + DIV_ROUND_UP((fade) * AW200XX_DIM_MAX, AW200XX_FADE_MAX) /* * Duty ratio of display scan (see p.15 of datasheet for formula): @@ -195,9 +197,7 @@ static int aw200xx_brightness_set(struct led_classdev *cdev, dim = led->dim; if (dim < 0) - dim = max_t(int, - brightness / (AW200XX_FADE_MAX / AW200XX_DIM_MAX), - 1); + dim = AW200XX_REG_FADE2DIM(brightness); ret = regmap_write(chip->regmap, reg, dim); if (ret) @@ -462,6 +462,7 @@ static int aw200xx_probe_fw(struct device *dev, struct aw200xx *chip) led->num = source; led->chip = chip; led->cdev.brightness_set_blocking = aw200xx_brightness_set; + led->cdev.max_brightness = AW200XX_FADE_MAX; led->cdev.groups = dim_groups; init_data.fwnode = child; |