aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThierry Reding <treding@nvidia.com>2013-10-02 12:01:02 -0400
committerNitin Garg <nitin.garg@freescale.com>2014-04-16 09:58:17 -0400
commit8dd7bf5719f2a0e7b2179e2ae980a014f375e40a (patch)
treed96f4069d03d7c0445de22a6e6e55956b09c9250
parentf4fdade48676b2754b28fcd7d165136330cff68e (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> (cherry picked from commit 97c38437115aa0c3fb2d50c488814b503ba529e0)
-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 1bc20528eec1..51a802fff50d 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 *,
@@ -41,6 +42,9 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness,
41{ 42{
42 int duty_cycle, err; 43 int duty_cycle, err;
43 44
45 if (pb->enabled)
46 return;
47
44 if (pb->levels) { 48 if (pb->levels) {
45 duty_cycle = pb->levels[brightness]; 49 duty_cycle = pb->levels[brightness];
46 max = pb->levels[max]; 50 max = pb->levels[max];
@@ -53,12 +57,18 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness,
53 57
54 pwm_config(pb->pwm, duty_cycle, pb->period); 58 pwm_config(pb->pwm, duty_cycle, pb->period);
55 pwm_enable(pb->pwm); 59 pwm_enable(pb->pwm);
60 pb->enabled = true;
56} 61}
57 62
58static void pwm_backlight_power_off(struct pwm_bl_data *pb) 63static void pwm_backlight_power_off(struct pwm_bl_data *pb)
59{ 64{
65 if (!pb->enabled)
66 return;
67
60 pwm_config(pb->pwm, 0, pb->period); 68 pwm_config(pb->pwm, 0, pb->period);
61 pwm_disable(pb->pwm); 69 pwm_disable(pb->pwm);
70
71 pb->enabled = false;
62} 72}
63 73
64static int pwm_backlight_update_status(struct backlight_device *bl) 74static int pwm_backlight_update_status(struct backlight_device *bl)
@@ -247,6 +257,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
247 pb->check_fb = np ? pwm_backlight_check_fb_dt : data->check_fb; 257 pb->check_fb = np ? pwm_backlight_check_fb_dt : data->check_fb;
248 pb->exit = data->exit; 258 pb->exit = data->exit;
249 pb->dev = &pdev->dev; 259 pb->dev = &pdev->dev;
260 pb->enabled = false;
250 261
251 pb->pwm = devm_pwm_get(&pdev->dev, NULL); 262 pb->pwm = devm_pwm_get(&pdev->dev, NULL);
252 if (IS_ERR(pb->pwm)) { 263 if (IS_ERR(pb->pwm)) {