* [PATCH v2] leds: trigger: tty: Do not use LED_ON/OFF constants, use led_blink_set_oneshot instead
@ 2023-08-02 9:07 Marek Behún
2023-08-17 10:58 ` (subset) " Lee Jones
0 siblings, 1 reply; 2+ messages in thread
From: Marek Behún @ 2023-08-02 9:07 UTC (permalink / raw)
To: Uwe Kleine-König, Pavel Machek, Lee Jones, linux-leds
Cc: Marek Behún
The tty LED trigger uses the obsolete LED_ON & LED_OFF constants when
setting LED brightness. This is bad because the LED_ON constant is equal
to 1, and so when activating the tty LED trigger on a LED class device
with max_brightness greater than 1, the LED is dimmer than it can be
(when max_brightness is 255, the LED is very dimm indeed; some devices
translate 1/255 to 0, so the LED is OFF all the time).
Instead of directly setting brightness to a specific value, use the
led_blink_set_oneshot() function from LED core to configure the blink.
This function takes the current configured brightness as blink
brightness if not zero, and max brightness otherwise.
This also changes the behavior of the TTY LED trigger. Previously if
rx/tx stats kept changing, the LED was ON all the time they kept
changing. With this patch the LED will blink on TTY activity.
Fixes: fd4a641ac88f ("leds: trigger: implement a tty trigger")
Signed-off-by: Marek Behún <kabel@kernel.org>
---
drivers/leds/trigger/ledtrig-tty.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/drivers/leds/trigger/ledtrig-tty.c b/drivers/leds/trigger/ledtrig-tty.c
index f62db7e520b5..8ae0d2d284af 100644
--- a/drivers/leds/trigger/ledtrig-tty.c
+++ b/drivers/leds/trigger/ledtrig-tty.c
@@ -7,6 +7,8 @@
#include <linux/tty.h>
#include <uapi/linux/serial.h>
+#define LEDTRIG_TTY_INTERVAL 50
+
struct ledtrig_tty_data {
struct led_classdev *led_cdev;
struct delayed_work dwork;
@@ -122,17 +124,19 @@ 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);
+ unsigned long interval = LEDTRIG_TTY_INTERVAL;
+
+ led_blink_set_oneshot(trigger_data->led_cdev, &interval,
+ &interval, 0);
trigger_data->rx = icount.rx;
trigger_data->tx = icount.tx;
- } else {
- led_set_brightness_sync(trigger_data->led_cdev, LED_OFF);
}
out:
mutex_unlock(&trigger_data->mutex);
- schedule_delayed_work(&trigger_data->dwork, msecs_to_jiffies(100));
+ schedule_delayed_work(&trigger_data->dwork,
+ msecs_to_jiffies(LEDTRIG_TTY_INTERVAL * 2));
}
static struct attribute *ledtrig_tty_attrs[] = {
--
2.41.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: (subset) [PATCH v2] leds: trigger: tty: Do not use LED_ON/OFF constants, use led_blink_set_oneshot instead
2023-08-02 9:07 [PATCH v2] leds: trigger: tty: Do not use LED_ON/OFF constants, use led_blink_set_oneshot instead Marek Behún
@ 2023-08-17 10:58 ` Lee Jones
0 siblings, 0 replies; 2+ messages in thread
From: Lee Jones @ 2023-08-17 10:58 UTC (permalink / raw)
To: Uwe Kleine-König, Pavel Machek, Lee Jones, linux-leds,
Marek Behún
On Wed, 02 Aug 2023 11:07:53 +0200, Marek Behún wrote:
> The tty LED trigger uses the obsolete LED_ON & LED_OFF constants when
> setting LED brightness. This is bad because the LED_ON constant is equal
> to 1, and so when activating the tty LED trigger on a LED class device
> with max_brightness greater than 1, the LED is dimmer than it can be
> (when max_brightness is 255, the LED is very dimm indeed; some devices
> translate 1/255 to 0, so the LED is OFF all the time).
>
> [...]
Applied, thanks!
[1/1] leds: trigger: tty: Do not use LED_ON/OFF constants, use led_blink_set_oneshot instead
commit: 730094577e0c37e1bc40be37cbd41f71b0a8a2a4
--
Lee Jones [李琼斯]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-08-17 10:59 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-02 9:07 [PATCH v2] leds: trigger: tty: Do not use LED_ON/OFF constants, use led_blink_set_oneshot instead Marek Behún
2023-08-17 10:58 ` (subset) " Lee Jones
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.