]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - drivers/video/backlight/lp855x_bl.c
drivers/video/backlight/lp855x_bl.c: use generic PWM functions
[karo-tx-linux.git] / drivers / video / backlight / lp855x_bl.c
index aa6d4f71131f5b6bb22fba425bc04d5caa726a95..c4fd72f2f383df4d0586ed047b916397e6ac5c9f 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/backlight.h>
 #include <linux/err.h>
 #include <linux/platform_data/lp855x.h>
+#include <linux/pwm.h>
 
 /* Registers */
 #define BRIGHTNESS_CTRL                0x00
@@ -36,6 +37,7 @@ struct lp855x {
        struct device *dev;
        struct mutex xfer_lock;
        struct lp855x_platform_data *pdata;
+       struct pwm_device *pwm;
 };
 
 static int lp855x_read_byte(struct lp855x *lp, u8 reg, u8 *data)
@@ -121,6 +123,25 @@ static int lp855x_init_registers(struct lp855x *lp)
        return ret;
 }
 
+static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br)
+{
+       unsigned int period = lp->pdata->period_ns;
+       unsigned int duty = br * period / max_br;
+       struct pwm_device *pwm;
+
+       /* request pwm device with the consumer name */
+       if (!lp->pwm) {
+               pwm = devm_pwm_get(lp->dev, lp->chipname);
+               if (IS_ERR(pwm))
+                       return;
+
+               lp->pwm = pwm;
+       }
+
+       pwm_config(lp->pwm, duty, period);
+       duty == 0 ? pwm_disable(lp->pwm) : pwm_enable(lp->pwm);
+}
+
 static int lp855x_bl_update_status(struct backlight_device *bl)
 {
        struct lp855x *lp = bl_get_data(bl);
@@ -130,12 +151,10 @@ static int lp855x_bl_update_status(struct backlight_device *bl)
                bl->props.brightness = 0;
 
        if (mode == PWM_BASED) {
-               struct lp855x_pwm_data *pd = &lp->pdata->pwm_data;
                int br = bl->props.brightness;
                int max_br = bl->props.max_brightness;
 
-               if (pd->pwm_set_intensity)
-                       pd->pwm_set_intensity(br, max_br);
+               lp855x_pwm_ctrl(lp, br, max_br);
 
        } else if (mode == REGISTER_BASED) {
                u8 val = bl->props.brightness;
@@ -150,14 +169,7 @@ static int lp855x_bl_get_brightness(struct backlight_device *bl)
        struct lp855x *lp = bl_get_data(bl);
        enum lp855x_brightness_ctrl_mode mode = lp->pdata->mode;
 
-       if (mode == PWM_BASED) {
-               struct lp855x_pwm_data *pd = &lp->pdata->pwm_data;
-               int max_br = bl->props.max_brightness;
-
-               if (pd->pwm_get_intensity)
-                       bl->props.brightness = pd->pwm_get_intensity(max_br);
-
-       } else if (mode == REGISTER_BASED) {
+       if (mode == REGISTER_BASED) {
                u8 val = 0;
 
                lp855x_read_byte(lp, BRIGHTNESS_CTRL, &val);