From: Thierry Reding Date: Fri, 18 Oct 2013 08:46:24 +0000 (+0200) Subject: pwm-backlight: Fix brightness adjustment X-Git-Tag: firefly_0821_release~6278 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=685f4a4b7182ed27763da246a0d6726aebe3df21;p=firefly-linux-kernel-4.4.55.git pwm-backlight: Fix brightness adjustment Split adjustment of the brightness (by changing the PWM duty cycle) from the power on sequence. This fixes an issue where the brightness can no longer be updated once the backlight has been enabled. Reported-by: Marc Dietrich Signed-off-by: Thierry Reding Conflicts: drivers/video/backlight/pwm_bl.c --- diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index 4323edaf253b..e5a0e7dc48ab 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -43,21 +43,11 @@ struct pwm_bl_data { static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness) { - unsigned int lth = pb->lth_brightness; int duty_cycle, err; if (pb->enabled) return; - if (pb->levels) - duty_cycle = pb->levels[brightness]; - else - duty_cycle = brightness; - - duty_cycle = (duty_cycle * (pb->period - lth) / pb->scale) + lth; - - pwm_config(pb->pwm, duty_cycle, pb->period); - if (gpio_is_valid(pb->enable_gpio)) { if (pb->enable_gpio_flags & PWM_BACKLIGHT_GPIO_ACTIVE_LOW) gpio_set_value(pb->enable_gpio, 0); @@ -87,10 +77,24 @@ static void pwm_backlight_power_off(struct pwm_bl_data *pb) pb->enabled = false; } +static int compute_duty_cycle(struct pwm_bl_data *pb, int brightness) +{ + unsigned int lth = pb->lth_brightness; + int duty_cycle; + + if (pb->levels) + duty_cycle = pb->levels[brightness]; + else + duty_cycle = brightness; + + return (duty_cycle * (pb->period - lth) / pb->scale) + lth; +} + static int pwm_backlight_update_status(struct backlight_device *bl) { struct pwm_bl_data *pb = bl_get_data(bl); int brightness = bl->props.brightness; + int duty_cycle; if (bl->props.power != FB_BLANK_UNBLANK || bl->props.fb_blank != FB_BLANK_UNBLANK || @@ -100,9 +104,11 @@ static int pwm_backlight_update_status(struct backlight_device *bl) if (pb->notify) brightness = pb->notify(pb->dev, brightness); - if (brightness > 0) + if (brightness > 0) { + duty_cycle = compute_duty_cycle(pb, brightness); + pwm_config(pb->pwm, duty_cycle, pb->period); pwm_backlight_power_on(pb, brightness); - else + } else pwm_backlight_power_off(pb); if (pb->notify_after)