Skip to contentSkip to conversation

leds: gpio: Set max brightness to 1

PATCH In review Dylan Van Assche 2 participants 2 messages Jan 25, 2021 – Feb 18, 2021 LED

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 leds: gpio: Set max brightness to 1

GPIO LEDs only know 2 states: ON or OFF and do not have PWM capabilities. However, the max brightness is reported as 255.

This patch sets the max brightness value of a GPIO controlled LED to 1.

Tested on my PinePhone 1.2.

---
v2 drops an obsolete change in include/linux/leds.h v3 simplifies the patch for better readability

 drivers/leds/leds-gpio.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/leds/leds-gpio.c +3 -1
index 93f5b1b60fde..242bb38cadee 100644
@@ -96,7 +96,9 @@ static int create_gpio_led(const struct gpio_led *template,
 	} else {
 		state = (template->default_state == LEDS_GPIO_DEFSTATE_ON);
 	}
-	led_dat->cdev.brightness = state ? LED_FULL : LED_OFF;
+	led_dat->cdev.brightness = state;
+	led_dat->cdev.max_brightness = 1;
+
 	if (!template->retain_state_suspended)
 		led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
 	if (template->panic_indicator)
Signature · 1 line
2.30.0
#1 lore raw
Quoted 8 lines · Dylan Van Assche

GPIO LEDs only know 2 states: ON or OFF and do not have PWM capabilities. However, the max brightness is reported as 255.

This patch sets the max brightness value of a GPIO controlled LED to 1.

Tested on my PinePhone 1.2.

I believe I have applied this already.

Thanks for patches,
Pavel

Signature · 1 line
http://www.livejournal.com/~pavelmachek