Skip to contentSkip to conversation

leds: trigger/tty: Use led_set_brightness() to support all use cases

PATCH In review Juergen Borleis 4 participants 5 messages May 3, 2021 – Feb 23, 2024 LED

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 leds: trigger/tty: Use led_set_brightness() to support all use cases

Using led_set_brightness_sync() only works for LEDs which are connected via some kind of external bus like I²C or SPI. But it doesn't work for the simple use case of directly connected LEDs via GPIOs. Because this function only honors the led_classdev::brightness_set_blocking callback. But the LED-GPIO driver registers the led_classdev::brightness_set member if the GPIO can be modified directly and thus, TTY triggers fail silently with -ENOTSUPP.

With the previously used led_set_brightness() it works for both use cases. This function first checks for the simple case where the GPIO can be changed without additional overhead, and if it fails, does the modification via a workqueue.

---
 drivers/leds/trigger/ledtrig-tty.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/leds/trigger/ledtrig-tty.c +2 -2
index f62db7e..af61281 100644
@@ -122,12 +122,12 @@ static void ledtrig_tty_work(struct work_struct *work)
 
 	if (icount.rx != trigger_data->rx ||
 	    icount.tx != trigger_data->tx) {
-		led_set_brightness_sync(trigger_data->led_cdev, LED_ON);
+		led_set_brightness(trigger_data->led_cdev, LED_ON);
 
 		trigger_data->rx = icount.rx;
 		trigger_data->tx = icount.tx;
 	} else {
-		led_set_brightness_sync(trigger_data->led_cdev, LED_OFF);
+		led_set_brightness(trigger_data->led_cdev, LED_OFF);
 	}
 
 out:
Signature · 1 line
2.20.1
#1 lore raw
Quoted 3 lines · Juergen Borleis

Using led_set_brightness_sync() only works for LEDs which are connected via some kind of external bus like I²C or SPI. But it doesn't work for the simple use case of directly connected LEDs via GPIOs.

Really? I'd need to check.

Quoted 9 lines

Because this function only honors the led_classdev::brightness_set_blocking callback. But the LED-GPIO driver registers the led_classdev::brightness_set member if the GPIO can be modified directly and thus, TTY triggers fail silently with -ENOTSUPP.

With the previously used led_set_brightness() it works for both use cases. This function first checks for the simple case where the GPIO can be changed without additional overhead, and if it fails, does the modification via a workqueue.

Yeah, but that is not what we want. We are already running in the workqueue.

We really should have a API that can be called from process context, and just simply sets the brightness.

Best regards,
Pavel

Signature · 1 line
http://www.livejournal.com/~pavelmachek
#2 lore raw
In reply to Juergen Borleis

Hello Jürgen,

Quoted 25 lines · Juergen Borleis

Using led_set_brightness_sync() only works for LEDs which are connected via some kind of external bus like I²C or SPI. But it doesn't work for the simple use case of directly connected LEDs via GPIOs. Because this function only honors the led_classdev::brightness_set_blocking callback. But the LED-GPIO driver registers the led_classdev::brightness_set member if the GPIO can be modified directly and thus, TTY triggers fail silently with -ENOTSUPP.

With the previously used led_set_brightness() it works for both use cases. This function first checks for the simple case where the GPIO can be changed without additional overhead, and if it fails, does the modification via a workqueue.

---
 drivers/leds/trigger/ledtrig-tty.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/leds/trigger/ledtrig-tty.c +0 -0
index f62db7e..af61281 100644
@@ -122,12 +122,12 @@ static void ledtrig_tty_work(struct work_struct *work)
 
 	if (icount.rx != trigger_data->rx ||

drivers/leds/trigger/ledtrig-tty.c static void ledtrig_tty_work(struct work_struct *work) · line 131

Quoted 10 lines
drivers/leds/trigger/ledtrig-tty.c +2 -2
 	    icount.tx != trigger_data->tx) {
-		led_set_brightness_sync(trigger_data->led_cdev, LED_ON);
+		led_set_brightness(trigger_data->led_cdev, LED_ON);
 
 		trigger_data->rx = icount.rx;
 		trigger_data->tx = icount.tx;
 	} else {
-		led_set_brightness_sync(trigger_data->led_cdev, LED_OFF);
+		led_set_brightness(trigger_data->led_cdev, LED_OFF);
 	}

This problem still exists, right?

I think the right thing here is to call led_set_brightness_nosleep() however.

Having said that, I think there are too many variants of led_set_brightness which makes it difficult to pick the right one.

(I'm aware of
- led_set_brightness_nosleep
- led_set_brightness_nopm
- led_set_brightness_sync
- led_set_brightness

and there are a few more static variants in led-core.c (__led_set_brightness, __led_set_brightness_blocking, set_brightness_delayed).)

Best regards
Uwe

Signature · 2 lines
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |
maintainer
#3 lore raw
Quoted 53 lines · Uwe Kleine-König

Hello Jürgen,

Quoted 25 lines · Juergen Borleis

Using led_set_brightness_sync() only works for LEDs which are connected via some kind of external bus like I²C or SPI. But it doesn't work for the simple use case of directly connected LEDs via GPIOs. Because this function only honors the led_classdev::brightness_set_blocking callback. But the LED-GPIO driver registers the led_classdev::brightness_set member if the GPIO can be modified directly and thus, TTY triggers fail silently with -ENOTSUPP.

With the previously used led_set_brightness() it works for both use cases. This function first checks for the simple case where the GPIO can be changed without additional overhead, and if it fails, does the modification via a workqueue.

---
 drivers/leds/trigger/ledtrig-tty.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/leds/trigger/ledtrig-tty.c +0 -0
index f62db7e..af61281 100644
@@ -122,12 +122,12 @@ static void ledtrig_tty_work(struct work_struct *work)
 
 	if (icount.rx != trigger_data->rx ||

drivers/leds/trigger/ledtrig-tty.c static void ledtrig_tty_work(struct work_struct *work) · line 131

Quoted 10 lines
drivers/leds/trigger/ledtrig-tty.c +2 -2
 	    icount.tx != trigger_data->tx) {
-		led_set_brightness_sync(trigger_data->led_cdev, LED_ON);
+		led_set_brightness(trigger_data->led_cdev, LED_ON);
 
 		trigger_data->rx = icount.rx;
 		trigger_data->tx = icount.tx;
 	} else {
-		led_set_brightness_sync(trigger_data->led_cdev, LED_OFF);
+		led_set_brightness(trigger_data->led_cdev, LED_OFF);
 	}

This problem still exists, right?

I think the right thing here is to call led_set_brightness_nosleep() however.

Having said that, I think there are too many variants of led_set_brightness which makes it difficult to pick the right one.

(I'm aware of
- led_set_brightness_nosleep
- led_set_brightness_nopm
- led_set_brightness_sync
- led_set_brightness

Quoted 3 lines

and there are a few more static variants in led-core.c (__led_set_brightness, __led_set_brightness_blocking, set_brightness_delayed).)

This patch (and this response) was never sent to me.

Not a great deal I can do if I'm not aware of it.

Signature · 1 line
Lee Jones [李琼斯]
maintainer
#4 lore raw
Quoted 55 lines · Lee Jones
Quoted 53 lines · Uwe Kleine-König

Hello Jürgen,

Quoted 25 lines · Juergen Borleis

Using led_set_brightness_sync() only works for LEDs which are connected via some kind of external bus like I²C or SPI. But it doesn't work for the simple use case of directly connected LEDs via GPIOs. Because this function only honors the led_classdev::brightness_set_blocking callback. But the LED-GPIO driver registers the led_classdev::brightness_set member if the GPIO can be modified directly and thus, TTY triggers fail silently with -ENOTSUPP.

With the previously used led_set_brightness() it works for both use cases. This function first checks for the simple case where the GPIO can be changed without additional overhead, and if it fails, does the modification via a workqueue.

---
 drivers/leds/trigger/ledtrig-tty.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/leds/trigger/ledtrig-tty.c +0 -0
index f62db7e..af61281 100644
@@ -122,12 +122,12 @@ static void ledtrig_tty_work(struct work_struct *work)
 
 	if (icount.rx != trigger_data->rx ||

drivers/leds/trigger/ledtrig-tty.c static void ledtrig_tty_work(struct work_struct *work) · line 131

Quoted 10 lines
drivers/leds/trigger/ledtrig-tty.c +2 -2
 	    icount.tx != trigger_data->tx) {
-		led_set_brightness_sync(trigger_data->led_cdev, LED_ON);
+		led_set_brightness(trigger_data->led_cdev, LED_ON);
 
 		trigger_data->rx = icount.rx;
 		trigger_data->tx = icount.tx;
 	} else {
-		led_set_brightness_sync(trigger_data->led_cdev, LED_OFF);
+		led_set_brightness(trigger_data->led_cdev, LED_OFF);
 	}

This problem still exists, right?

I think the right thing here is to call led_set_brightness_nosleep() however.

Having said that, I think there are too many variants of led_set_brightness which makes it difficult to pick the right one.

(I'm aware of
- led_set_brightness_nosleep
- led_set_brightness_nopm
- led_set_brightness_sync
- led_set_brightness

Quoted 7 lines
Quoted 3 lines

and there are a few more static variants in led-core.c (__led_set_brightness, __led_set_brightness_blocking, set_brightness_delayed).)

This patch (and this response) was never sent to me.

Not a great deal I can do if I'm not aware of it.

Starting to think I've gone too far back in the LEDs ML's history? =;-)

Signature · 1 line
Lee Jones [李琼斯]