Skip to contentSkip to conversation

leds: gpio: Set max brightness to 1

PATCH Superseded Dylan Van Assche 2 participants 3 messages Dec 29, 2020 LED

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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

 drivers/leds/leds-gpio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/leds/leds-gpio.c +2 -1
index 93f5b1b60fde..0d66f19d71ba 100644
@@ -96,7 +96,8 @@ 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_ON : LED_OFF;
+	led_dat->cdev.max_brightness = LED_ON;
 	if (!template->retain_state_suspended)
 		led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
 	if (template->panic_indicator)
Signature · 1 line
2.26.2
#1 lore raw

Hi!

Quoted 10 lines

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

I thought that one looked odd.

drivers/leds/leds-gpio.c static int create_gpio_led(const struct gpio_led *template, · line 100

Quoted 8 lines

+++ b/drivers/leds/leds-gpio.c

drivers/leds/leds-gpio.c +2 -1
@@ -96,7 +96,8 @@ 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_ON : LED_OFF;
+	led_dat->cdev.max_brightness = LED_ON;

Would simpler version work:

Review static int create_gpio_led(const struct gpio_led *template, · line 102

Quoted 2 lines
(quoted diff) +2 -0
+	led_dat->cdev.brightness = state;
+	led_dat->cdev.max_brightness = 1;

? Easier to understand... I'd prefer that version unless it causes warnings or something.

Pavel

Signature · 1 line
http://www.livejournal.com/~pavelmachek
#2 lore raw

Hi!

Thanks for the feedback!
Indeed, this can be even more simplified with your suggestion. I will send a new version of the patch soon.

Happy holidays!

Kind regards,
Dylan Van Assche

Quoted 37 lines · Pavel Machek

Hi!

Quoted 4 lines

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

Quoted 8 lines

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

I thought that one looked odd.

drivers/leds/leds-gpio.c static int create_gpio_led(const struct gpio_led · line 102

Quoted 10 lines

+++ b/drivers/leds/leds-gpio.c

drivers/leds/leds-gpio.c +2 -1
@@ -96,7 +96,8 @@ 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_ON : LED_OFF;
+	led_dat->cdev.max_brightness = LED_ON;

Would simpler version work:

Review static int create_gpio_led(const struct gpio_led

Quoted 2 lines
(quoted diff) +2 -0
+	led_dat->cdev.brightness = state;
+	led_dat->cdev.max_brightness = 1;

? Easier to understand... I'd prefer that version unless it causes warnings or something.

Pavel