]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
backlight: pwm_bl: add configurable delay between re-enabling PWM and switching backl...
authorLothar Waßmann <LW@KARO-electronics.de>
Wed, 11 Oct 2017 10:15:43 +0000 (12:15 +0200)
committerLothar Waßmann <LW@KARO-electronics.de>
Wed, 11 Oct 2017 10:15:43 +0000 (12:15 +0200)
When switching the backlight on, the LCD may need some time to adjust
to the configured PWM duty cycle. Add a configurable delay between
configuring the PWM and enabling the backlight regulator to account
for this.

Documentation/devicetree/bindings/leds/backlight/pwm-backlight.txt
drivers/video/backlight/pwm_bl.c

index 764db86d441ad131aceca0e15146d5c914d97919..95594c341a571e68ec4dbe5885be8ad81342af64 100644 (file)
@@ -17,6 +17,10 @@ Optional properties:
                "pwms" property (see PWM binding[0])
   - enable-gpios: contains a single GPIO specifier for the GPIO which enables
                   and disables the backlight (see GPIO binding[1])
+  - turn-on-delay-ms: delay in milliseconds between configuring the PWM
+                 and switching PWM on. This may be required to eliminate
+                 flicker when switching the PWM on after it has been
+                 disabled.
 
 [0]: Documentation/devicetree/bindings/pwm/pwm.txt
 [1]: Documentation/devicetree/bindings/gpio/gpio.txt
index 921f322dd2877eb7c2a78bab0cfcaca37862d98f..9578f6516c65a5b0d88e1c163c4053e0cfa0366e 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/pwm_backlight.h>
 #include <linux/regulator/consumer.h>
 #include <linux/slab.h>
+#include <linux/delay.h>
 
 struct pwm_bl_data {
        struct pwm_device       *pwm;
@@ -35,6 +36,7 @@ struct pwm_bl_data {
        struct gpio_desc        *enable_gpio;
        unsigned int            scale;
        bool                    legacy;
+       int                     turn_on_delay_ms;
        int                     (*notify)(struct device *,
                                          int brightness);
        void                    (*notify_after)(struct device *,
@@ -52,6 +54,17 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness)
 
        pwm_enable(pb->pwm);
 
+       if (pb->turn_on_delay_ms > 0) {
+               dev_dbg(pb->dev, "Sleeping %u..%uµs\n",
+                       pb->turn_on_delay_ms * 1000,
+                       pb->turn_on_delay_ms * 1100);
+               if (pb->turn_on_delay_ms > 20)
+                       msleep(pb->turn_on_delay_ms);
+               else
+                       usleep_range(pb->turn_on_delay_ms * 1000,
+                            pb->turn_on_delay_ms * 1100);
+       }
+
        err = regulator_enable(pb->power_supply);
        if (err < 0)
                dev_err(pb->dev, "failed to enable power supply\n");
@@ -108,8 +121,9 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
                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)
                pb->notify_after(pb->dev, brightness);
@@ -264,9 +278,9 @@ static int pwm_backlight_probe(struct platform_device *pdev)
                                pb->scale = data->levels[i];
 
                pb->levels = data->levels;
-       } else
+       } else {
                pb->scale = data->max_brightness;
-
+       }
        pb->notify = data->notify;
        pb->notify_after = data->notify_after;
        pb->check_fb = data->check_fb;
@@ -329,6 +343,8 @@ static int pwm_backlight_probe(struct platform_device *pdev)
                goto err_alloc;
        }
 
+       of_property_read_u32(node, "turn-on-delay-ms", &pb->turn_on_delay_ms);
+
        dev_dbg(&pdev->dev, "got pwm for backlight\n");
 
        /*