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 | |
| 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>
| -rw-r--r-- | Documentation/devicetree/bindings/video/backlight/pwm-backlight.txt | 2 | ||||
| -rw-r--r-- | drivers/video/backlight/pwm_bl.c | 13 |
2 files changed, 15 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/video/backlight/pwm-backlight.txt b/Documentation/devicetree/bindings/video/backlight/pwm-backlight.txt index 72810cc2dbc1..764db86d441a 100644 --- a/Documentation/devicetree/bindings/video/backlight/pwm-backlight.txt +++ b/Documentation/devicetree/bindings/video/backlight/pwm-backlight.txt | |||
| @@ -10,6 +10,7 @@ Required properties: | |||
| 10 | last value in the array represents a 100% duty cycle (brightest). | 10 | last value in the array represents a 100% duty cycle (brightest). |
| 11 | - default-brightness-level: the default brightness level (index into the | 11 | - default-brightness-level: the default brightness level (index into the |
| 12 | array defined by the "brightness-levels" property) | 12 | array defined by the "brightness-levels" property) |
| 13 | - power-supply: regulator for supply voltage | ||
| 13 | 14 | ||
| 14 | Optional properties: | 15 | Optional properties: |
| 15 | - pwm-names: a list of names for the PWM devices specified in the | 16 | - pwm-names: a list of names for the PWM devices specified in the |
| @@ -29,5 +30,6 @@ Example: | |||
| 29 | brightness-levels = <0 4 8 16 32 64 128 255>; | 30 | brightness-levels = <0 4 8 16 32 64 128 255>; |
| 30 | default-brightness-level = <6>; | 31 | default-brightness-level = <6>; |
| 31 | 32 | ||
| 33 | power-supply = <&vdd_bl_reg>; | ||
| 32 | enable-gpios = <&gpio 58 0>; | 34 | enable-gpios = <&gpio 58 0>; |
| 33 | }; | 35 | }; |
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"); |
