diff options
author | George Stark <gnstark@salutedevices.com> | 2024-11-05 19:50:06 +0100 |
---|---|---|
committer | Lee Jones <lee@kernel.org> | 2024-11-12 13:14:00 +0100 |
commit | 8cb08101835d98fd69cfa2a2b06146eddc057df6 (patch) | |
tree | 12f339a13976b09018f1025231ee9f75ecb1dd2f /drivers/leds | |
parent | dt-bindings: leds: pwm: Add default-brightness property (diff) | |
download | linux-8cb08101835d98fd69cfa2a2b06146eddc057df6.tar.xz linux-8cb08101835d98fd69cfa2a2b06146eddc057df6.zip |
leds: pwm: Add optional DT property default-brightness
When probing if default LED state is on then default brightness will be
applied instead of max brightness.
Signed-off-by: George Stark <gnstark@salutedevices.com>
Link: https://lore.kernel.org/r/20241105185006.1380166-3-gnstark@salutedevices.com
Signed-off-by: Lee Jones <lee@kernel.org>
Diffstat (limited to 'drivers/leds')
-rw-r--r-- | drivers/leds/leds-pwm.c | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/drivers/leds/leds-pwm.c b/drivers/leds/leds-pwm.c index 34a03ef82007..c73134e7b951 100644 --- a/drivers/leds/leds-pwm.c +++ b/drivers/leds/leds-pwm.c @@ -62,6 +62,20 @@ static int led_pwm_set(struct led_classdev *led_cdev, return pwm_apply_might_sleep(led_dat->pwm, &led_dat->pwmstate); } +static int led_pwm_default_brightness_get(struct fwnode_handle *fwnode, + int max_brightness) +{ + unsigned int default_brightness; + int ret; + + ret = fwnode_property_read_u32(fwnode, "default-brightness", + &default_brightness); + if (ret < 0 || default_brightness > max_brightness) + default_brightness = max_brightness; + + return default_brightness; +} + __attribute__((nonnull)) static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv, struct led_pwm *led, struct fwnode_handle *fwnode) @@ -103,7 +117,8 @@ static int led_pwm_add(struct device *dev, struct led_pwm_priv *priv, /* set brightness */ switch (led->default_state) { case LEDS_DEFSTATE_ON: - led_data->cdev.brightness = led->max_brightness; + led_data->cdev.brightness = + led_pwm_default_brightness_get(fwnode, led->max_brightness); break; case LEDS_DEFSTATE_KEEP: { |