All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] leds: gpio: Set max brightness to 1
@ 2020-12-29 14:24 Dylan Van Assche
  2020-12-29 16:04 ` Pavel Machek
  0 siblings, 1 reply; 3+ messages in thread
From: Dylan Van Assche @ 2020-12-29 14:24 UTC (permalink / raw)
  To: pavel, dmurphy, linux-leds, linux-kernel; +Cc: 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.

Signed-off-by: Dylan Van Assche <me@dylanvanassche.be>
---
v2 drops an obsolete change in include/linux/leds.h

 drivers/leds/leds-gpio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index 93f5b1b60fde..0d66f19d71ba 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -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)
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] leds: gpio: Set max brightness to 1
  2020-12-29 14:24 [PATCH v2] leds: gpio: Set max brightness to 1 Dylan Van Assche
@ 2020-12-29 16:04 ` Pavel Machek
  2020-12-29 18:09   ` Dylan Van Assche
  0 siblings, 1 reply; 3+ messages in thread
From: Pavel Machek @ 2020-12-29 16:04 UTC (permalink / raw)
  To: Dylan Van Assche; +Cc: dmurphy, linux-leds, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 1041 bytes --]

Hi!

> 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.
> 
> Signed-off-by: Dylan Van Assche <me@dylanvanassche.be>
> ---
> v2 drops an obsolete change in include/linux/leds.h

I thought that one looked odd.

> +++ b/drivers/leds/leds-gpio.c
> @@ -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:

> +	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
-- 
http://www.livejournal.com/~pavelmachek

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] leds: gpio: Set max brightness to 1
  2020-12-29 16:04 ` Pavel Machek
@ 2020-12-29 18:09   ` Dylan Van Assche
  0 siblings, 0 replies; 3+ messages in thread
From: Dylan Van Assche @ 2020-12-29 18:09 UTC (permalink / raw)
  To: Pavel Machek; +Cc: dmurphy, linux-leds, linux-kernel

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

On Tue, 2020-12-29 at 17:04 +0100, Pavel Machek wrote:
> Hi!
> 
> > 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.
> > 
> > Signed-off-by: Dylan Van Assche <me@dylanvanassche.be>
> > ---
> > v2 drops an obsolete change in include/linux/leds.h
> 
> I thought that one looked odd.
> 
> > +++ b/drivers/leds/leds-gpio.c
> > @@ -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:
> 
> > +	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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-29 18:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-29 14:24 [PATCH v2] leds: gpio: Set max brightness to 1 Dylan Van Assche
2020-12-29 16:04 ` Pavel Machek
2020-12-29 18:09   ` Dylan Van Assche

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.