aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/video/backlight/pwm_bl.c30
1 files changed, 18 insertions, 12 deletions
diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index 32e96e3525a1..f77a7b0ca5e6 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -45,21 +45,11 @@ struct pwm_bl_data {
45 45
46static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness) 46static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness)
47{ 47{
48 unsigned int lth = pb->lth_brightness;
49 int duty_cycle, err; 48 int duty_cycle, err;
50 49
51 if (pb->enabled) 50 if (pb->enabled)
52 return; 51 return;
53 52
54 if (pb->levels)
55 duty_cycle = pb->levels[brightness];
56 else
57 duty_cycle = brightness;
58
59 duty_cycle = (duty_cycle * (pb->period - lth) / pb->scale) + lth;
60
61 pwm_config(pb->pwm, duty_cycle, pb->period);
62
63 err = regulator_enable(pb->power_supply); 53 err = regulator_enable(pb->power_supply);
64 if (err < 0) 54 if (err < 0)
65 dev_err(pb->dev, "failed to enable power supply\n"); 55 dev_err(pb->dev, "failed to enable power supply\n");
@@ -94,10 +84,24 @@ static void pwm_backlight_power_off(struct pwm_bl_data *pb)
94 pb->enabled = false; 84 pb->enabled = false;
95} 85}
96 86
87static int compute_duty_cycle(struct pwm_bl_data *pb, int brightness)
88{
89 unsigned int lth = pb->lth_brightness;
90 int duty_cycle;
91
92 if (pb->levels)
93 duty_cycle = pb->levels[brightness];
94 else
95 duty_cycle = brightness;
96
97 return (duty_cycle * (pb->period - lth) / pb->scale) + lth;
98}
99
97static int pwm_backlight_update_status(struct backlight_device *bl) 100static int pwm_backlight_update_status(struct backlight_device *bl)
98{ 101{
99 struct pwm_bl_data *pb = bl_get_data(bl); 102 struct pwm_bl_data *pb = bl_get_data(bl);
100 int brightness = bl->props.brightness; 103 int brightness = bl->props.brightness;
104 int duty_cycle;
101 105
102 if (bl->props.power != FB_BLANK_UNBLANK || 106 if (bl->props.power != FB_BLANK_UNBLANK ||
103 bl->props.fb_blank != FB_BLANK_UNBLANK || 107 bl->props.fb_blank != FB_BLANK_UNBLANK ||
@@ -107,9 +111,11 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
107 if (pb->notify) 111 if (pb->notify)
108 brightness = pb->notify(pb->dev, brightness); 112 brightness = pb->notify(pb->dev, brightness);
109 113
110 if (brightness > 0) 114 if (brightness > 0) {
115 duty_cycle = compute_duty_cycle(pb, brightness);
116 pwm_config(pb->pwm, duty_cycle, pb->period);
111 pwm_backlight_power_on(pb, brightness); 117 pwm_backlight_power_on(pb, brightness);
112 else 118 } else
113 pwm_backlight_power_off(pb); 119 pwm_backlight_power_off(pb);
114 120
115 if (pb->notify_after) 121 if (pb->notify_after)