Skip to content

Commit 7300945

Browse files
elkablolag-linaro
authored andcommitted
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: fd4a641 ("leds: trigger: implement a tty trigger") Signed-off-by: Marek Behún <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent f044ae6 commit 7300945

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

drivers/leds/trigger/ledtrig-tty.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#include <linux/tty.h>
88
#include <uapi/linux/serial.h>
99

10+
#define LEDTRIG_TTY_INTERVAL 50
11+
1012
struct ledtrig_tty_data {
1113
struct led_classdev *led_cdev;
1214
struct delayed_work dwork;
@@ -122,17 +124,19 @@ static void ledtrig_tty_work(struct work_struct *work)
122124

123125
if (icount.rx != trigger_data->rx ||
124126
icount.tx != trigger_data->tx) {
125-
led_set_brightness_sync(trigger_data->led_cdev, LED_ON);
127+
unsigned long interval = LEDTRIG_TTY_INTERVAL;
128+
129+
led_blink_set_oneshot(trigger_data->led_cdev, &interval,
130+
&interval, 0);
126131

127132
trigger_data->rx = icount.rx;
128133
trigger_data->tx = icount.tx;
129-
} else {
130-
led_set_brightness_sync(trigger_data->led_cdev, LED_OFF);
131134
}
132135

133136
out:
134137
mutex_unlock(&trigger_data->mutex);
135-
schedule_delayed_work(&trigger_data->dwork, msecs_to_jiffies(100));
138+
schedule_delayed_work(&trigger_data->dwork,
139+
msecs_to_jiffies(LEDTRIG_TTY_INTERVAL * 2));
136140
}
137141

138142
static struct attribute *ledtrig_tty_attrs[] = {

0 commit comments

Comments
 (0)