diff options
author | Thierry Reding <treding@nvidia.com> | 2013-10-07 05:32:02 -0400 |
---|---|---|
committer | Nitin Garg <nitin.garg@freescale.com> | 2014-04-16 09:58:17 -0400 |
commit | f4fdade48676b2754b28fcd7d165136330cff68e (patch) | |
tree | 1e5d35edab54312942bfc37a58f3b908fc62c66a | |
parent | 55b5ff2630f2a4ee89163230746d5d331cf3a9df (diff) |
pwm-backlight: Refactor backlight power on/off
In preparation for adding an optional regulator and enable GPIO to the
driver, split the power on and power off sequences into separate
functions to reduce code duplication at the multiple call sites.
Signed-off-by: Thierry Reding <treding@nvidia.com>
(cherry picked from commit 62b744a87c1170b339f993aa3cfb22465974816a)
-rw-r--r-- | drivers/video/backlight/pwm_bl.c | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index 90c1dffaa539..1bc20528eec1 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c | |||
@@ -36,6 +36,31 @@ struct pwm_bl_data { | |||
36 | const char *fb_names[FB_MAX]; | 36 | const char *fb_names[FB_MAX]; |
37 | }; | 37 | }; |
38 | 38 | ||
39 | static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness, | ||
40 | int max) | ||
41 | { | ||
42 | int duty_cycle, err; | ||
43 | |||
44 | if (pb->levels) { | ||
45 | duty_cycle = pb->levels[brightness]; | ||
46 | max = pb->levels[max]; | ||
47 | } else { | ||
48 | duty_cycle = brightness; | ||
49 | } | ||
50 | |||
51 | duty_cycle = (duty_cycle * (pb->period - pb->lth_brightness) / max) + | ||
52 | pb->lth_brightness; | ||
53 | |||
54 | pwm_config(pb->pwm, duty_cycle, pb->period); | ||
55 | pwm_enable(pb->pwm); | ||
56 | } | ||
57 | |||
58 | static void pwm_backlight_power_off(struct pwm_bl_data *pb) | ||
59 | { | ||
60 | pwm_config(pb->pwm, 0, pb->period); | ||
61 | pwm_disable(pb->pwm); | ||
62 | } | ||
63 | |||
39 | static int pwm_backlight_update_status(struct backlight_device *bl) | 64 | static int pwm_backlight_update_status(struct backlight_device *bl) |
40 | { | 65 | { |
41 | struct pwm_bl_data *pb = bl_get_data(bl); | 66 | struct pwm_bl_data *pb = bl_get_data(bl); |
@@ -50,24 +75,10 @@ static int pwm_backlight_update_status(struct backlight_device *bl) | |||
50 | if (pb->notify) | 75 | if (pb->notify) |
51 | brightness = pb->notify(pb->dev, brightness); | 76 | brightness = pb->notify(pb->dev, brightness); |
52 | 77 | ||
53 | if (brightness == 0) { | 78 | if (brightness > 0) |
54 | pwm_config(pb->pwm, 0, pb->period); | 79 | pwm_backlight_power_on(pb, brightness, max); |
55 | pwm_disable(pb->pwm); | 80 | else |
56 | } else { | 81 | pwm_backlight_power_off(pb); |
57 | int duty_cycle; | ||
58 | |||
59 | if (pb->levels) { | ||
60 | duty_cycle = pb->levels[brightness]; | ||
61 | max = pb->levels[max]; | ||
62 | } else { | ||
63 | duty_cycle = brightness; | ||
64 | } | ||
65 | |||
66 | duty_cycle = pb->lth_brightness + | ||
67 | (duty_cycle * (pb->period - pb->lth_brightness) / max); | ||
68 | pwm_config(pb->pwm, duty_cycle, pb->period); | ||
69 | pwm_enable(pb->pwm); | ||
70 | } | ||
71 | 82 | ||
72 | if (pb->notify_after) | 83 | if (pb->notify_after) |
73 | pb->notify_after(pb->dev, brightness); | 84 | pb->notify_after(pb->dev, brightness); |
@@ -298,8 +309,7 @@ static int pwm_backlight_remove(struct platform_device *pdev) | |||
298 | struct pwm_bl_data *pb = bl_get_data(bl); | 309 | struct pwm_bl_data *pb = bl_get_data(bl); |
299 | 310 | ||
300 | backlight_device_unregister(bl); | 311 | backlight_device_unregister(bl); |
301 | pwm_config(pb->pwm, 0, pb->period); | 312 | pwm_backlight_power_off(pb); |
302 | pwm_disable(pb->pwm); | ||
303 | 313 | ||
304 | if (pb->exit) | 314 | if (pb->exit) |
305 | pb->exit(&pdev->dev); | 315 | pb->exit(&pdev->dev); |
@@ -316,8 +326,7 @@ static int pwm_backlight_suspend(struct device *dev) | |||
316 | if (pb->notify) | 326 | if (pb->notify) |
317 | pb->notify(pb->dev, 0); | 327 | pb->notify(pb->dev, 0); |
318 | 328 | ||
319 | pwm_config(pb->pwm, 0, pb->period); | 329 | pwm_backlight_power_off(pb); |
320 | pwm_disable(pb->pwm); | ||
321 | 330 | ||
322 | if (pb->notify_after) | 331 | if (pb->notify_after) |
323 | pb->notify_after(pb->dev, 0); | 332 | pb->notify_after(pb->dev, 0); |