aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Dunn <mikedunn@newsguy.com>2013-09-22 12:59:56 -0400
committerNitin Garg <nitin.garg@freescale.com>2014-04-16 09:58:17 -0400
commita8b160f1c0a57b57d38001bb795145078f92f01e (patch)
tree34910af614005c2ae595cbd980833387c67cf6d9
parent958f652dd6f28d558205d449fd44d90ce4ee0621 (diff)
pwm-backlight: Allow for non-increasing brightness levels
Currently the driver assumes that the values specified in the brightness-levels device tree property increase as they are parsed from left to right. But boards that invert the signal between the PWM output and the backlight will need to specify decreasing brightness-levels. This patch removes the assumption that the last element of the array is the maximum value, and instead searches the array for the maximum value and uses that in the duty cycle calculation. Signed-off-by: Mike Dunn <mikedunn@newsguy.com> Signed-off-by: Thierry Reding <treding@nvidia.com> (cherry picked from commit 8f43e18e2769b3b28383903d501b4da29e388aad) Conflicts: drivers/video/backlight/pwm_bl.c
-rw-r--r--drivers/video/backlight/pwm_bl.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index 18b885497289..65b63961d3fd 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -32,6 +32,7 @@ struct pwm_bl_data {
32 bool enabled; 32 bool enabled;
33 int enable_gpio; 33 int enable_gpio;
34 unsigned long enable_gpio_flags; 34 unsigned long enable_gpio_flags;
35 unsigned int scale;
35 int (*notify)(struct device *, 36 int (*notify)(struct device *,
36 int brightness); 37 int brightness);
37 void (*notify_after)(struct device *, 38 void (*notify_after)(struct device *,
@@ -41,23 +42,20 @@ struct pwm_bl_data {
41 const char *fb_names[FB_MAX]; 42 const char *fb_names[FB_MAX];
42}; 43};
43 44
44static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness, 45static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness)
45 int max)
46{ 46{
47 unsigned int lth = pb->lth_brightness;
47 int duty_cycle, err; 48 int duty_cycle, err;
48 49
49 if (pb->enabled) 50 if (pb->enabled)
50 return; 51 return;
51 52
52 if (pb->levels) { 53 if (pb->levels)
53 duty_cycle = pb->levels[brightness]; 54 duty_cycle = pb->levels[brightness];
54 max = pb->levels[max]; 55 else
55 } else {
56 duty_cycle = brightness; 56 duty_cycle = brightness;
57 }
58 57
59 duty_cycle = (duty_cycle * (pb->period - pb->lth_brightness) / max) + 58 duty_cycle = (duty_cycle * (pb->period - lth) / pb->scale) + lth;
60 pb->lth_brightness;
61 59
62 pwm_config(pb->pwm, duty_cycle, pb->period); 60 pwm_config(pb->pwm, duty_cycle, pb->period);
63 61
@@ -94,7 +92,6 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
94{ 92{
95 struct pwm_bl_data *pb = bl_get_data(bl); 93 struct pwm_bl_data *pb = bl_get_data(bl);
96 int brightness = bl->props.brightness; 94 int brightness = bl->props.brightness;
97 int max = bl->props.max_brightness;
98 95
99 if (bl->props.power != FB_BLANK_UNBLANK || 96 if (bl->props.power != FB_BLANK_UNBLANK ||
100 bl->props.fb_blank != FB_BLANK_UNBLANK || 97 bl->props.fb_blank != FB_BLANK_UNBLANK ||
@@ -105,7 +102,7 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
105 brightness = pb->notify(pb->dev, brightness); 102 brightness = pb->notify(pb->dev, brightness);
106 103
107 if (brightness > 0) 104 if (brightness > 0)
108 pwm_backlight_power_on(pb, brightness, max); 105 pwm_backlight_power_on(pb, brightness);
109 else 106 else
110 pwm_backlight_power_off(pb); 107 pwm_backlight_power_off(pb);
111 108
@@ -233,7 +230,6 @@ static int pwm_backlight_probe(struct platform_device *pdev)
233 struct backlight_properties props; 230 struct backlight_properties props;
234 struct backlight_device *bl; 231 struct backlight_device *bl;
235 struct pwm_bl_data *pb; 232 struct pwm_bl_data *pb;
236 unsigned int max;
237 int ret, index; 233 int ret, index;
238 234
239 if (!data) { 235 if (!data) {
@@ -269,10 +265,15 @@ static int pwm_backlight_probe(struct platform_device *pdev)
269 } 265 }
270 266
271 if (data->levels) { 267 if (data->levels) {
272 max = data->levels[data->max_brightness]; 268 unsigned int i;
269
270 for (i = 0; i <= data->max_brightness; i++)
271 if (data->levels[i] > pb->scale)
272 pb->scale = data->levels[i];
273
273 pb->levels = data->levels; 274 pb->levels = data->levels;
274 } else 275 } else
275 max = data->max_brightness; 276 pb->scale = data->max_brightness;
276 277
277 pb->enable_gpio = data->enable_gpio; 278 pb->enable_gpio = data->enable_gpio;
278 pb->enable_gpio_flags = data->enable_gpio_flags; 279 pb->enable_gpio_flags = data->enable_gpio_flags;
@@ -322,7 +323,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
322 pwm_set_period(pb->pwm, data->pwm_period_ns); 323 pwm_set_period(pb->pwm, data->pwm_period_ns);
323 324
324 pb->period = pwm_get_period(pb->pwm); 325 pb->period = pwm_get_period(pb->pwm);
325 pb->lth_brightness = data->lth_brightness * (pb->period / max); 326 pb->lth_brightness = data->lth_brightness * (pb->period / pb->scale);
326 327
327 memset(&props, 0, sizeof(struct backlight_properties)); 328 memset(&props, 0, sizeof(struct backlight_properties));
328 props.type = BACKLIGHT_RAW; 329 props.type = BACKLIGHT_RAW;