Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

leds: trigger: tty: Do not use LED_ON/OFF constants, use led_blink_set_oneshot instead

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>
Link: https://lore.kernel.org/r/20230802090753.13611-1-kabel@kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>

authored by

Marek Behún and committed by
Lee Jones
73009457 f044ae6b

+8 -4
+8 -4
drivers/leds/trigger/ledtrig-tty.c
··· 7 7 #include <linux/tty.h> 8 8 #include <uapi/linux/serial.h> 9 9 10 + #define LEDTRIG_TTY_INTERVAL 50 11 + 10 12 struct ledtrig_tty_data { 11 13 struct led_classdev *led_cdev; 12 14 struct delayed_work dwork; ··· 124 122 125 123 if (icount.rx != trigger_data->rx || 126 124 icount.tx != trigger_data->tx) { 127 - led_set_brightness_sync(trigger_data->led_cdev, LED_ON); 125 + unsigned long interval = LEDTRIG_TTY_INTERVAL; 126 + 127 + led_blink_set_oneshot(trigger_data->led_cdev, &interval, 128 + &interval, 0); 128 129 129 130 trigger_data->rx = icount.rx; 130 131 trigger_data->tx = icount.tx; 131 - } else { 132 - led_set_brightness_sync(trigger_data->led_cdev, LED_OFF); 133 132 } 134 133 135 134 out: 136 135 mutex_unlock(&trigger_data->mutex); 137 - schedule_delayed_work(&trigger_data->dwork, msecs_to_jiffies(100)); 136 + schedule_delayed_work(&trigger_data->dwork, 137 + msecs_to_jiffies(LEDTRIG_TTY_INTERVAL * 2)); 138 138 } 139 139 140 140 static struct attribute *ledtrig_tty_attrs[] = {