video: backlight: Parse PWM polarity cell
authorStefan Mavrodiev <stefan@olimex.com>
Fri, 12 Apr 2019 05:56:27 +0000 (08:56 +0300)
committerAnatolij Gustschin <agust@denx.de>
Sun, 14 Apr 2019 12:17:36 +0000 (14:17 +0200)
This patch enables the reading of the polarity cell from a PWM
phandle and calls pwm_set_invert().

Not all platforms have polarity cell, so skip if it's not pressent.

Signed-off-by: Stefan Mavrodiev <stefan@olimex.com>
Reviewed-by: Anatolij Gustschin <agust@denx.de>
drivers/video/pwm_backlight.c

index bd733f5f1ca5a221ed3844d53e816ceaac08c547..a587977c225045599aafe6b5c0b782ae3495041d 100644 (file)
@@ -39,6 +39,12 @@ struct pwm_backlight_priv {
        struct udevice *pwm;
        uint channel;
        uint period_ns;
+       /*
+        * the polarity of one PWM
+        * 0: normal polarity
+        * 1: inverted polarity
+        */
+       bool polarity;
        u32 *levels;
        int num_levels;
        uint default_level;
@@ -57,7 +63,10 @@ static int set_pwm(struct pwm_backlight_priv *priv)
                (priv->max_level - priv->min_level + 1);
        ret = pwm_set_config(priv->pwm, priv->channel, priv->period_ns,
                             duty_cycle);
+       if (ret)
+               return log_ret(ret);
 
+       ret = pwm_set_invert(priv->pwm, priv->channel, priv->polarity);
        return log_ret(ret);
 }
 
@@ -202,6 +211,8 @@ static int pwm_backlight_ofdata_to_platdata(struct udevice *dev)
                return log_msg_ret("Not enough arguments to pwm\n", -EINVAL);
        priv->channel = args.args[0];
        priv->period_ns = args.args[1];
+       if (args.args_count > 2)
+               priv->polarity = args.args[2];
 
        index = dev_read_u32_default(dev, "default-brightness-level", 255);
        cell = dev_read_prop(dev, "brightness-levels", &len);