video: backlight: fix pwm's duty cycle calculation
authorDario Binacchi <dariobin@libero.it>
Sun, 11 Oct 2020 12:28:04 +0000 (14:28 +0200)
committerAnatolij Gustschin <agust@denx.de>
Sun, 18 Oct 2020 13:07:33 +0000 (15:07 +0200)
For levels equal to the maximum value, the duty cycle must be equal to
the period.

Signed-off-by: Dario Binacchi <dariobin@libero.it>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/video/pwm_backlight.c
test/dm/panel.c

index acfde7b..9519180 100644 (file)
@@ -63,7 +63,7 @@ static int set_pwm(struct pwm_backlight_priv *priv)
        int ret;
 
        duty_cycle = priv->period_ns * (priv->cur_level - priv->min_level) /
-               (priv->max_level - priv->min_level + 1);
+               (priv->max_level - priv->min_level);
        ret = pwm_set_config(priv->pwm, priv->channel, priv->period_ns,
                             duty_cycle);
        if (ret)
index a840fb4..49f5ac7 100644 (file)
@@ -40,7 +40,7 @@ static int dm_test_panel(struct unit_test_state *uts)
        ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
                                           &enable, &polarity));
        ut_asserteq(1000, period_ns);
-       ut_asserteq(170 * 1000 / 256, duty_ns);
+       ut_asserteq(170 * 1000 / 255, duty_ns);
        ut_asserteq(true, enable);
        ut_asserteq(false, polarity);
        ut_asserteq(1, sandbox_gpio_get_value(gpio, 1));
@@ -49,29 +49,29 @@ static int dm_test_panel(struct unit_test_state *uts)
        ut_assertok(panel_set_backlight(dev, 40));
        ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
                                           &enable, &polarity));
-       ut_asserteq(64 * 1000 / 256, duty_ns);
+       ut_asserteq(64 * 1000 / 255, duty_ns);
 
        ut_assertok(panel_set_backlight(dev, BACKLIGHT_MAX));
        ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
                                           &enable, &polarity));
-       ut_asserteq(255 * 1000 / 256, duty_ns);
+       ut_asserteq(255 * 1000 / 255, duty_ns);
 
        ut_assertok(panel_set_backlight(dev, BACKLIGHT_MIN));
        ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
                                           &enable, &polarity));
-       ut_asserteq(0 * 1000 / 256, duty_ns);
+       ut_asserteq(0 * 1000 / 255, duty_ns);
        ut_asserteq(1, sandbox_gpio_get_value(gpio, 1));
 
        ut_assertok(panel_set_backlight(dev, BACKLIGHT_DEFAULT));
        ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
                                           &enable, &polarity));
        ut_asserteq(true, enable);
-       ut_asserteq(170 * 1000 / 256, duty_ns);
+       ut_asserteq(170 * 1000 / 255, duty_ns);
 
        ut_assertok(panel_set_backlight(dev, BACKLIGHT_OFF));
        ut_assertok(sandbox_pwm_get_config(pwm, 0, &period_ns, &duty_ns,
                                           &enable, &polarity));
-       ut_asserteq(0 * 1000 / 256, duty_ns);
+       ut_asserteq(0 * 1000 / 255, duty_ns);
        ut_asserteq(0, sandbox_gpio_get_value(gpio, 1));
        ut_asserteq(false, regulator_get_enable(reg));