aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/video/backlight/pwm_bl.c
diff options
context:
space:
mode:
authorThierry Reding <treding@nvidia.com>2013-10-02 12:01:02 -0400
committerThierry Reding <thierry.reding@gmail.com>2013-10-16 03:05:57 -0400
commit97c38437115aa0c3fb2d50c488814b503ba529e0 (patch)
treef7afc5b092a60ff9e7b7973f15ee9b550e9ab659 /drivers/video/backlight/pwm_bl.c
parent62b744a87c1170b339f993aa3cfb22465974816a (diff)
pwm-backlight: Track enable state
Follow up patches will add support for more complex means of powering the backlight on and off such as using a regulator. To prevent calls to the regulator API from becoming unbalanced, keep track of the enabled state internally. Signed-off-by: Thierry Reding <treding@nvidia.com>
Diffstat (limited to 'drivers/video/backlight/pwm_bl.c')
-rw-r--r--drivers/video/backlight/pwm_bl.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index ab9d5e6012a4..4053efbe5edb 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -27,6 +27,7 @@ struct pwm_bl_data {
27 unsigned int period; 27 unsigned int period;
28 unsigned int lth_brightness; 28 unsigned int lth_brightness;
29 unsigned int *levels; 29 unsigned int *levels;
30 bool enabled;
30 int (*notify)(struct device *, 31 int (*notify)(struct device *,
31 int brightness); 32 int brightness);
32 void (*notify_after)(struct device *, 33 void (*notify_after)(struct device *,
@@ -40,6 +41,9 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness,
40{ 41{
41 int duty_cycle, err; 42 int duty_cycle, err;
42 43
44 if (pb->enabled)
45 return;
46
43 if (pb->levels) { 47 if (pb->levels) {
44 duty_cycle = pb->levels[brightness]; 48 duty_cycle = pb->levels[brightness];
45 max = pb->levels[max]; 49 max = pb->levels[max];
@@ -52,12 +56,18 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness,
52 56
53 pwm_config(pb->pwm, duty_cycle, pb->period); 57 pwm_config(pb->pwm, duty_cycle, pb->period);
54 pwm_enable(pb->pwm); 58 pwm_enable(pb->pwm);
59 pb->enabled = true;
55} 60}
56 61
57static void pwm_backlight_power_off(struct pwm_bl_data *pb) 62static void pwm_backlight_power_off(struct pwm_bl_data *pb)
58{ 63{
64 if (!pb->enabled)
65 return;
66
59 pwm_config(pb->pwm, 0, pb->period); 67 pwm_config(pb->pwm, 0, pb->period);
60 pwm_disable(pb->pwm); 68 pwm_disable(pb->pwm);
69
70 pb->enabled = false;
61} 71}
62 72
63static int pwm_backlight_update_status(struct backlight_device *bl) 73static int pwm_backlight_update_status(struct backlight_device *bl)
@@ -216,6 +226,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
216 pb->check_fb = data->check_fb; 226 pb->check_fb = data->check_fb;
217 pb->exit = data->exit; 227 pb->exit = data->exit;
218 pb->dev = &pdev->dev; 228 pb->dev = &pdev->dev;
229 pb->enabled = false;
219 230
220 pb->pwm = devm_pwm_get(&pdev->dev, NULL); 231 pb->pwm = devm_pwm_get(&pdev->dev, NULL);
221 if (IS_ERR(pb->pwm)) { 232 if (IS_ERR(pb->pwm)) {