Skip to content

Commit dc2139c

Browse files
Thomas Zimmermannlag-linaro
authored andcommitted
leds: backlight trigger: Replace fb events with a dedicated function call
Remove support for fb events from the led backlight trigger. Provide the helper ledtrig_backlight_blank() instead. Call it from fbdev to inform the trigger of changes to a display's blank state. Fbdev maintains a list of all installed notifiers. Instead of the fbdev notifiers, maintain an internal list of led backlight triggers. v3: - export ledtrig_backlight_blank() v2: - maintain global list of led backlight triggers (Lee) - avoid IS_REACHABLE() in source file (Lee) - notify on changes to blank state instead of display state - use lock guards - initialize led list and list mutex Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Acked-by: Simona Vetter <simona.vetter@ffwll.ch> Link: https://lore.kernel.org/r/20250321095517.313713-11-tzimmermann@suse.de Signed-off-by: Lee Jones <lee@kernel.org>
1 parent 28f8bab commit dc2139c

File tree

3 files changed

+33
-34
lines changed

3 files changed

+33
-34
lines changed

drivers/leds/trigger/ledtrig-backlight.c

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <linux/kernel.h>
1111
#include <linux/slab.h>
1212
#include <linux/init.h>
13-
#include <linux/fb.h>
1413
#include <linux/leds.h>
1514
#include "../leds.h"
1615

@@ -21,10 +20,14 @@ struct bl_trig_notifier {
2120
struct led_classdev *led;
2221
int brightness;
2322
int old_status;
24-
struct notifier_block notifier;
2523
unsigned invert;
24+
25+
struct list_head entry;
2626
};
2727

28+
static DEFINE_MUTEX(ledtrig_backlight_list_mutex);
29+
static LIST_HEAD(ledtrig_backlight_list);
30+
2831
static void ledtrig_backlight_notify_blank(struct bl_trig_notifier *n, int new_status)
2932
{
3033
struct led_classdev *led = n->led;
@@ -42,26 +45,17 @@ static void ledtrig_backlight_notify_blank(struct bl_trig_notifier *n, int new_s
4245
n->old_status = new_status;
4346
}
4447

45-
static int fb_notifier_callback(struct notifier_block *p,
46-
unsigned long event, void *data)
48+
void ledtrig_backlight_blank(bool blank)
4749
{
48-
struct bl_trig_notifier *n = container_of(p,
49-
struct bl_trig_notifier, notifier);
50-
struct fb_event *fb_event = data;
51-
int *blank;
52-
int new_status;
53-
54-
/* If we aren't interested in this event, skip it immediately ... */
55-
if (event != FB_EVENT_BLANK)
56-
return 0;
57-
58-
blank = fb_event->data;
59-
new_status = *blank ? BLANK : UNBLANK;
50+
struct bl_trig_notifier *n;
51+
int new_status = blank ? BLANK : UNBLANK;
6052

61-
ledtrig_backlight_notify_blank(n, new_status);
53+
guard(mutex)(&ledtrig_backlight_list_mutex);
6254

63-
return 0;
55+
list_for_each_entry(n, &ledtrig_backlight_list, entry)
56+
ledtrig_backlight_notify_blank(n, new_status);
6457
}
58+
EXPORT_SYMBOL(ledtrig_backlight_blank);
6559

6660
static ssize_t bl_trig_invert_show(struct device *dev,
6761
struct device_attribute *attr, char *buf)
@@ -106,8 +100,6 @@ ATTRIBUTE_GROUPS(bl_trig);
106100

107101
static int bl_trig_activate(struct led_classdev *led)
108102
{
109-
int ret;
110-
111103
struct bl_trig_notifier *n;
112104

113105
n = kzalloc(sizeof(struct bl_trig_notifier), GFP_KERNEL);
@@ -118,11 +110,9 @@ static int bl_trig_activate(struct led_classdev *led)
118110
n->led = led;
119111
n->brightness = led->brightness;
120112
n->old_status = UNBLANK;
121-
n->notifier.notifier_call = fb_notifier_callback;
122113

123-
ret = fb_register_client(&n->notifier);
124-
if (ret)
125-
dev_err(led->dev, "unable to register backlight trigger\n");
114+
guard(mutex)(&ledtrig_backlight_list_mutex);
115+
list_add(&n->entry, &ledtrig_backlight_list);
126116

127117
return 0;
128118
}
@@ -131,7 +121,9 @@ static void bl_trig_deactivate(struct led_classdev *led)
131121
{
132122
struct bl_trig_notifier *n = led_get_trigger_data(led);
133123

134-
fb_unregister_client(&n->notifier);
124+
guard(mutex)(&ledtrig_backlight_list_mutex);
125+
list_del(&n->entry);
126+
135127
kfree(n);
136128
}
137129

drivers/video/fbdev/core/fbmem.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/fb.h>
1717
#include <linux/fbcon.h>
1818
#include <linux/lcd.h>
19+
#include <linux/leds.h>
1920

2021
#include <video/nomodeset.h>
2122

@@ -369,11 +370,17 @@ static void fb_lcd_notify_blank(struct fb_info *info)
369370
lcd_notify_blank_all(info->device, power);
370371
}
371372

373+
static void fb_ledtrig_backlight_notify_blank(struct fb_info *info)
374+
{
375+
if (info->blank == FB_BLANK_UNBLANK)
376+
ledtrig_backlight_blank(false);
377+
else
378+
ledtrig_backlight_blank(true);
379+
}
380+
372381
int fb_blank(struct fb_info *info, int blank)
373382
{
374383
int old_blank = info->blank;
375-
struct fb_event event;
376-
int data[2];
377384
int ret;
378385

379386
if (!info->fbops->fb_blank)
@@ -382,11 +389,6 @@ int fb_blank(struct fb_info *info, int blank)
382389
if (blank > FB_BLANK_POWERDOWN)
383390
blank = FB_BLANK_POWERDOWN;
384391

385-
data[0] = blank;
386-
data[1] = old_blank;
387-
event.info = info;
388-
event.data = data;
389-
390392
info->blank = blank;
391393

392394
ret = info->fbops->fb_blank(blank, info);
@@ -395,8 +397,7 @@ int fb_blank(struct fb_info *info, int blank)
395397

396398
fb_bl_notify_blank(info, old_blank);
397399
fb_lcd_notify_blank(info);
398-
399-
fb_notifier_call_chain(FB_EVENT_BLANK, &event);
400+
fb_ledtrig_backlight_notify_blank(info);
400401

401402
return 0;
402403

include/linux/leds.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,12 @@ static inline void ledtrig_flash_ctrl(bool on) {}
640640
static inline void ledtrig_torch_ctrl(bool on) {}
641641
#endif
642642

643+
#if IS_REACHABLE(CONFIG_LEDS_TRIGGER_BACKLIGHT)
644+
void ledtrig_backlight_blank(bool blank);
645+
#else
646+
static inline void ledtrig_backlight_blank(bool blank) {}
647+
#endif
648+
643649
/*
644650
* Generic LED platform data for describing LED names and default triggers.
645651
*/

0 commit comments

Comments
 (0)