Message ID | 20231006160437.15627-10-ddrokosov@salutedevices.com |
---|---|
State | New |
Headers | show |
Series | leds: aw200xx: several driver updates | expand |
On Fri, Oct 6, 2023 at 7:05 PM Dmitry Rokosov <ddrokosov@salutedevices.com> wrote: > > From: George Stark <gnstark@salutedevices.com> > > use DIV_ROUND_UP instead of coarse div Please, respect English grammar and punctuation. Refer to macros and functions as func() (note the parentheses). ... > #define AW200XX_REG_DIM2FADE(x) ((x) + 1) > +#define AW200XX_REG_FADE2DIM(fade) \ > + DIV_ROUND_UP((fade) * AW200XX_DIM_MAX, AW200XX_FADE_MAX) Have you checked if the overflow is _now_ possible (compiling on 32-bit platforms as well)?
On Fri, Oct 06, 2023 at 09:03:47PM +0300, Andy Shevchenko wrote: > On Fri, Oct 6, 2023 at 7:05 PM Dmitry Rokosov > <ddrokosov@salutedevices.com> wrote: > > > > From: George Stark <gnstark@salutedevices.com> > > > > use DIV_ROUND_UP instead of coarse div > > Please, respect English grammar and punctuation. > Refer to macros and functions as func() (note the parentheses). > > ... > > > #define AW200XX_REG_DIM2FADE(x) ((x) + 1) > > +#define AW200XX_REG_FADE2DIM(fade) \ > > + DIV_ROUND_UP((fade) * AW200XX_DIM_MAX, AW200XX_FADE_MAX) > > Have you checked if the overflow is _now_ possible (compiling on > 32-bit platforms as well)? I suppose we shouldn't carry on about overflow here because the value of fade cannot exceed 255, and DIM_MAX is set at 63 You can find maximum values of fade and dim in the aw200xx driver header: #define AW200XX_DIM_MAX (BIT(6) - 1) #define AW200XX_FADE_MAX (BIT(8) - 1)
On Mon, Oct 09, 2023 at 04:18:08PM +0300, Dmitry Rokosov wrote: > On Fri, Oct 06, 2023 at 09:03:47PM +0300, Andy Shevchenko wrote: > > On Fri, Oct 6, 2023 at 7:05 PM Dmitry Rokosov > > <ddrokosov@salutedevices.com> wrote: > > > > > > From: George Stark <gnstark@salutedevices.com> > > > > > > use DIV_ROUND_UP instead of coarse div > > > > Please, respect English grammar and punctuation. > > Refer to macros and functions as func() (note the parentheses). > > > > ... > > > > > #define AW200XX_REG_DIM2FADE(x) ((x) + 1) > > > +#define AW200XX_REG_FADE2DIM(fade) \ > > > + DIV_ROUND_UP((fade) * AW200XX_DIM_MAX, AW200XX_FADE_MAX) > > > > Have you checked if the overflow is _now_ possible (compiling on > > 32-bit platforms as well)? > > I suppose we shouldn't carry on about overflow here because the value of > fade cannot exceed 255, and DIM_MAX is set at 63 > > You can find maximum values of fade and dim in the aw200xx driver > header: > > #define AW200XX_DIM_MAX (BIT(6) - 1) > #define AW200XX_FADE_MAX (BIT(8) - 1) I agree that checking if the fade is not greater than FADE_MAX will not be excessive. The LED subsystem is capable of sending brightness levels higher than 255
On 10/9/23 17:02, Dmitry Rokosov wrote: > On Mon, Oct 09, 2023 at 04:18:08PM +0300, Dmitry Rokosov wrote: >> On Fri, Oct 06, 2023 at 09:03:47PM +0300, Andy Shevchenko wrote: >>> On Fri, Oct 6, 2023 at 7:05 PM Dmitry Rokosov >>> <ddrokosov@salutedevices.com> wrote: >>>> >>>> From: George Stark <gnstark@salutedevices.com> >>>> >>>> use DIV_ROUND_UP instead of coarse div >>> >>> Please, respect English grammar and punctuation. >>> Refer to macros and functions as func() (note the parentheses). >>> >>> ... >>> >>>> #define AW200XX_REG_DIM2FADE(x) ((x) + 1) >>>> +#define AW200XX_REG_FADE2DIM(fade) \ >>>> + DIV_ROUND_UP((fade) * AW200XX_DIM_MAX, AW200XX_FADE_MAX) >>> >>> Have you checked if the overflow is _now_ possible (compiling on >>> 32-bit platforms as well)? >> >> I suppose we shouldn't carry on about overflow here because the value of >> fade cannot exceed 255, and DIM_MAX is set at 63 >> >> You can find maximum values of fade and dim in the aw200xx driver >> header: >> >> #define AW200XX_DIM_MAX (BIT(6) - 1) >> #define AW200XX_FADE_MAX (BIT(8) - 1) > > I agree that checking if the fade is not greater than FADE_MAX will not > be excessive. The LED subsystem is capable of sending brightness levels > higher than 255 > Probably we should set max_brightness to AW200XX_FADE_MAX in led_classdev when adding leds.
diff --git a/drivers/leds/leds-aw200xx.c b/drivers/leds/leds-aw200xx.c index 5a1a93ffe36c..09b8bc6724c7 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)