diff options
author | Thierry Reding <treding@nvidia.com> | 2013-08-30 06:38:34 -0400 |
---|---|---|
committer | Thierry Reding <thierry.reding@gmail.com> | 2013-10-16 03:20:09 -0400 |
commit | 22ceeee16eb8f0d04de3ef43a5174fb30ec18af9 (patch) | |
tree | 6c04eb3878e69ba47dbf33c76f0bad5cc8517fc1 /drivers/video/backlight | |
parent | 8265b2e4e62632b01f998095d1bbda4d281629fe (diff) |
pwm-backlight: Add power supply support
Backlights require a power supply to work properly. This commit adds a
regulator to power up and power down the backlight.
Signed-off-by: Thierry Reding <treding@nvidia.com>
Diffstat (limited to 'drivers/video/backlight')
-rw-r--r-- | drivers/video/backlight/pwm_bl.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index cdef4a346555..eec6c98527f9 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/err.h> | 21 | #include <linux/err.h> |
22 | #include <linux/pwm.h> | 22 | #include <linux/pwm.h> |
23 | #include <linux/pwm_backlight.h> | 23 | #include <linux/pwm_backlight.h> |
24 | #include <linux/regulator/consumer.h> | ||
24 | #include <linux/slab.h> | 25 | #include <linux/slab.h> |
25 | 26 | ||
26 | struct pwm_bl_data { | 27 | struct pwm_bl_data { |
@@ -30,6 +31,7 @@ struct pwm_bl_data { | |||
30 | unsigned int lth_brightness; | 31 | unsigned int lth_brightness; |
31 | unsigned int *levels; | 32 | unsigned int *levels; |
32 | bool enabled; | 33 | bool enabled; |
34 | struct regulator *power_supply; | ||
33 | int enable_gpio; | 35 | int enable_gpio; |
34 | unsigned long enable_gpio_flags; | 36 | unsigned long enable_gpio_flags; |
35 | int (*notify)(struct device *, | 37 | int (*notify)(struct device *, |
@@ -60,6 +62,10 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness, | |||
60 | 62 | ||
61 | pwm_config(pb->pwm, duty_cycle, pb->period); | 63 | pwm_config(pb->pwm, duty_cycle, pb->period); |
62 | 64 | ||
65 | err = regulator_enable(pb->power_supply); | ||
66 | if (err < 0) | ||
67 | dev_err(pb->dev, "failed to enable power supply\n"); | ||
68 | |||
63 | if (gpio_is_valid(pb->enable_gpio)) { | 69 | if (gpio_is_valid(pb->enable_gpio)) { |
64 | if (pb->enable_gpio_flags & PWM_BACKLIGHT_GPIO_ACTIVE_LOW) | 70 | if (pb->enable_gpio_flags & PWM_BACKLIGHT_GPIO_ACTIVE_LOW) |
65 | gpio_set_value(pb->enable_gpio, 0); | 71 | gpio_set_value(pb->enable_gpio, 0); |
@@ -86,6 +92,7 @@ static void pwm_backlight_power_off(struct pwm_bl_data *pb) | |||
86 | gpio_set_value(pb->enable_gpio, 0); | 92 | gpio_set_value(pb->enable_gpio, 0); |
87 | } | 93 | } |
88 | 94 | ||
95 | regulator_disable(pb->power_supply); | ||
89 | pb->enabled = false; | 96 | pb->enabled = false; |
90 | } | 97 | } |
91 | 98 | ||
@@ -268,6 +275,12 @@ static int pwm_backlight_probe(struct platform_device *pdev) | |||
268 | } | 275 | } |
269 | } | 276 | } |
270 | 277 | ||
278 | pb->power_supply = devm_regulator_get(&pdev->dev, "power"); | ||
279 | if (IS_ERR(pb->power_supply)) { | ||
280 | ret = PTR_ERR(pb->power_supply); | ||
281 | goto err_gpio; | ||
282 | } | ||
283 | |||
271 | pb->pwm = devm_pwm_get(&pdev->dev, NULL); | 284 | pb->pwm = devm_pwm_get(&pdev->dev, NULL); |
272 | if (IS_ERR(pb->pwm)) { | 285 | if (IS_ERR(pb->pwm)) { |
273 | dev_err(&pdev->dev, "unable to request PWM, trying legacy API\n"); | 286 | dev_err(&pdev->dev, "unable to request PWM, trying legacy API\n"); |