Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Thierry Reding and committed by
Thierry Reding
22ceeee1 8265b2e4

+15
+2
Documentation/devicetree/bindings/video/backlight/pwm-backlight.txt
··· 10 10 last value in the array represents a 100% duty cycle (brightest). 11 11 - default-brightness-level: the default brightness level (index into the 12 12 array defined by the "brightness-levels" property) 13 + - power-supply: regulator for supply voltage 13 14 14 15 Optional properties: 15 16 - pwm-names: a list of names for the PWM devices specified in the ··· 30 29 brightness-levels = <0 4 8 16 32 64 128 255>; 31 30 default-brightness-level = <6>; 32 31 32 + power-supply = <&vdd_bl_reg>; 33 33 enable-gpios = <&gpio 58 0>; 34 34 };
+13
drivers/video/backlight/pwm_bl.c
··· 21 21 #include <linux/err.h> 22 22 #include <linux/pwm.h> 23 23 #include <linux/pwm_backlight.h> 24 + #include <linux/regulator/consumer.h> 24 25 #include <linux/slab.h> 25 26 26 27 struct pwm_bl_data { ··· 31 30 unsigned int lth_brightness; 32 31 unsigned int *levels; 33 32 bool enabled; 33 + struct regulator *power_supply; 34 34 int enable_gpio; 35 35 unsigned long enable_gpio_flags; 36 36 int (*notify)(struct device *, ··· 62 60 63 61 pwm_config(pb->pwm, duty_cycle, pb->period); 64 62 63 + err = regulator_enable(pb->power_supply); 64 + if (err < 0) 65 + dev_err(pb->dev, "failed to enable power supply\n"); 66 + 65 67 if (gpio_is_valid(pb->enable_gpio)) { 66 68 if (pb->enable_gpio_flags & PWM_BACKLIGHT_GPIO_ACTIVE_LOW) 67 69 gpio_set_value(pb->enable_gpio, 0); ··· 92 86 gpio_set_value(pb->enable_gpio, 0); 93 87 } 94 88 89 + regulator_disable(pb->power_supply); 95 90 pb->enabled = false; 96 91 } 97 92 ··· 273 266 pb->enable_gpio, ret); 274 267 goto err_alloc; 275 268 } 269 + } 270 + 271 + pb->power_supply = devm_regulator_get(&pdev->dev, "power"); 272 + if (IS_ERR(pb->power_supply)) { 273 + ret = PTR_ERR(pb->power_supply); 274 + goto err_gpio; 276 275 } 277 276 278 277 pb->pwm = devm_pwm_get(&pdev->dev, NULL);