Skip to content

Commit b01beb2

Browse files
Thomas Zimmermannlag-linaro
authored andcommitted
backlight: Replace fb events with a dedicated function call
Remove support for fb events from backlight subsystem. Provide the helper backlight_notify_blank_all() instead. Also export the existing helper backlight_notify_blank() to update a single backlight device. In fbdev, call either helper to inform the backlight subsystem of changes to a display's blank state. If the framebuffer device has a specific backlight, only update this one; otherwise update all. v4: - protect blacklight declarations with IS_REACHABLE() (kernel test robot) v3: - declare empty fb_bl_notify_blank() as static inline (kernel test robot) Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de> Acked-by: Simona Vetter <simona.vetter@ffwll.ch> Reviewed-by: "Daniel Thompson (RISCstar)" <danielt@kernel.org> Link: https://lore.kernel.org/r/20250321095517.313713-7-tzimmermann@suse.de Signed-off-by: Lee Jones <lee@kernel.org>
1 parent 4bfb77f commit b01beb2

File tree

5 files changed

+46
-79
lines changed

5 files changed

+46
-79
lines changed

drivers/video/backlight/backlight.c

Lines changed: 12 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include <linux/notifier.h>
1616
#include <linux/ctype.h>
1717
#include <linux/err.h>
18-
#include <linux/fb.h>
1918
#include <linux/slab.h>
2019

2120
#ifdef CONFIG_PMAC_BACKLIGHT
@@ -57,10 +56,10 @@
5756
* a hot-key to adjust backlight, the driver must notify the backlight
5857
* core that brightness has changed using backlight_force_update().
5958
*
60-
* The backlight driver core receives notifications from fbdev and
61-
* if the event is FB_EVENT_BLANK and if the value of blank, from the
62-
* FBIOBLANK ioctrl, results in a change in the backlight state the
63-
* update_status() operation is called.
59+
* Display drives can control the backlight device's status using
60+
* backlight_notify_blank() and backlight_notify_blank_all(). If this
61+
* results in a change in the backlight state the functions call the
62+
* update_status() operation.
6463
*/
6564

6665
static struct list_head backlight_dev_list;
@@ -78,11 +77,8 @@ static const char *const backlight_scale_types[] = {
7877
[BACKLIGHT_SCALE_NON_LINEAR] = "non-linear",
7978
};
8079

81-
#if defined(CONFIG_FB_CORE) || (defined(CONFIG_FB_CORE_MODULE) && \
82-
defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE))
83-
static void backlight_notify_blank(struct backlight_device *bd,
84-
struct device *display_dev,
85-
bool fb_on, bool prev_fb_on)
80+
void backlight_notify_blank(struct backlight_device *bd, struct device *display_dev,
81+
bool fb_on, bool prev_fb_on)
8682
{
8783
guard(mutex)(&bd->ops_lock);
8884

@@ -103,68 +99,18 @@ static void backlight_notify_blank(struct backlight_device *bd,
10399
}
104100
}
105101
}
102+
EXPORT_SYMBOL(backlight_notify_blank);
106103

107-
/*
108-
* fb_notifier_callback
109-
*
110-
* This callback gets called when something important happens inside a
111-
* framebuffer driver. The backlight core only cares about FB_BLANK_UNBLANK
112-
* which is reported to the driver using backlight_update_status()
113-
* as a state change.
114-
*
115-
* There may be several fbdev's connected to the backlight device,
116-
* in which case they are kept track of. A state change is only reported
117-
* if there is a change in backlight for the specified fbdev.
118-
*/
119-
static int fb_notifier_callback(struct notifier_block *self,
120-
unsigned long event, void *data)
104+
void backlight_notify_blank_all(struct device *display_dev, bool fb_on, bool prev_fb_on)
121105
{
122106
struct backlight_device *bd;
123-
struct fb_event *evdata = data;
124-
struct fb_info *info = evdata->info;
125-
const int *fb_blank = evdata->data;
126-
struct backlight_device *fb_bd = fb_bl_device(info);
127-
bool fb_on, prev_fb_on;
128-
129-
/* If we aren't interested in this event, skip it immediately ... */
130-
if (event != FB_EVENT_BLANK)
131-
return 0;
132-
133-
bd = container_of(self, struct backlight_device, fb_notif);
134-
135-
if (fb_bd && fb_bd != bd)
136-
return 0;
137-
138-
fb_on = fb_blank[0] == FB_BLANK_UNBLANK;
139-
prev_fb_on = fb_blank[1] == FB_BLANK_UNBLANK;
140-
141-
backlight_notify_blank(bd, info->device, fb_on, prev_fb_on);
142-
143-
return 0;
144-
}
145-
146-
static int backlight_register_fb(struct backlight_device *bd)
147-
{
148-
memset(&bd->fb_notif, 0, sizeof(bd->fb_notif));
149-
bd->fb_notif.notifier_call = fb_notifier_callback;
150107

151-
return fb_register_client(&bd->fb_notif);
152-
}
108+
guard(mutex)(&backlight_dev_list_mutex);
153109

154-
static void backlight_unregister_fb(struct backlight_device *bd)
155-
{
156-
fb_unregister_client(&bd->fb_notif);
157-
}
158-
#else
159-
static inline int backlight_register_fb(struct backlight_device *bd)
160-
{
161-
return 0;
110+
list_for_each_entry(bd, &backlight_dev_list, entry)
111+
backlight_notify_blank(bd, display_dev, fb_on, prev_fb_on);
162112
}
163-
164-
static inline void backlight_unregister_fb(struct backlight_device *bd)
165-
{
166-
}
167-
#endif /* CONFIG_FB_CORE */
113+
EXPORT_SYMBOL(backlight_notify_blank_all);
168114

169115
static void backlight_generate_event(struct backlight_device *bd,
170116
enum backlight_update_reason reason)
@@ -455,12 +401,6 @@ struct backlight_device *backlight_device_register(const char *name,
455401
return ERR_PTR(rc);
456402
}
457403

458-
rc = backlight_register_fb(new_bd);
459-
if (rc) {
460-
device_unregister(&new_bd->dev);
461-
return ERR_PTR(rc);
462-
}
463-
464404
new_bd->ops = ops;
465405

466406
#ifdef CONFIG_PMAC_BACKLIGHT
@@ -547,7 +487,6 @@ void backlight_device_unregister(struct backlight_device *bd)
547487
bd->ops = NULL;
548488
mutex_unlock(&bd->ops_lock);
549489

550-
backlight_unregister_fb(bd);
551490
device_unregister(&bd->dev);
552491
}
553492
EXPORT_SYMBOL(backlight_device_unregister);

drivers/video/fbdev/core/fb_backlight.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// SPDX-License-Identifier: GPL-2.0-or-later
22

3+
#include <linux/backlight.h>
34
#include <linux/export.h>
45
#include <linux/fb.h>
56
#include <linux/mutex.h>
@@ -36,4 +37,15 @@ struct backlight_device *fb_bl_device(struct fb_info *info)
3637
return info->bl_dev;
3738
}
3839
EXPORT_SYMBOL(fb_bl_device);
40+
41+
void fb_bl_notify_blank(struct fb_info *info, int old_blank)
42+
{
43+
bool on = info->blank == FB_BLANK_UNBLANK;
44+
bool prev_on = old_blank == FB_BLANK_UNBLANK;
45+
46+
if (info->bl_dev)
47+
backlight_notify_blank(info->bl_dev, info->device, on, prev_on);
48+
else
49+
backlight_notify_blank_all(info->device, on, prev_on);
50+
}
3951
#endif

drivers/video/fbdev/core/fbmem.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ int fb_blank(struct fb_info *info, int blank)
363363
if (ret)
364364
goto err;
365365

366+
fb_bl_notify_blank(info, old_blank);
367+
366368
fb_notifier_call_chain(FB_EVENT_BLANK, &event);
367369

368370
return 0;

include/linux/backlight.h

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <linux/device.h>
1313
#include <linux/fb.h>
1414
#include <linux/mutex.h>
15-
#include <linux/notifier.h>
1615
#include <linux/types.h>
1716

1817
/**
@@ -278,11 +277,6 @@ struct backlight_device {
278277
*/
279278
const struct backlight_ops *ops;
280279

281-
/**
282-
* @fb_notif: The framebuffer notifier block
283-
*/
284-
struct notifier_block fb_notif;
285-
286280
/**
287281
* @entry: List entry of all registered backlight devices
288282
*/
@@ -400,6 +394,22 @@ struct backlight_device *backlight_device_get_by_type(enum backlight_type type);
400394
int backlight_device_set_brightness(struct backlight_device *bd,
401395
unsigned long brightness);
402396

397+
#if IS_REACHABLE(CONFIG_BACKLIGHT_CLASS_DEVICE)
398+
void backlight_notify_blank(struct backlight_device *bd,
399+
struct device *display_dev,
400+
bool fb_on, bool prev_fb_on);
401+
void backlight_notify_blank_all(struct device *display_dev,
402+
bool fb_on, bool prev_fb_on);
403+
#else
404+
static inline void backlight_notify_blank(struct backlight_device *bd,
405+
struct device *display_dev,
406+
bool fb_on, bool prev_fb_on)
407+
{ }
408+
static inline void backlight_notify_blank_all(struct device *display_dev,
409+
bool fb_on, bool prev_fb_on)
410+
{ }
411+
#endif
412+
403413
#define to_backlight_device(obj) container_of(obj, struct backlight_device, dev)
404414

405415
/**

include/linux/fb.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,11 +758,15 @@ extern void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max)
758758

759759
#if IS_ENABLED(CONFIG_FB_BACKLIGHT)
760760
struct backlight_device *fb_bl_device(struct fb_info *info);
761+
void fb_bl_notify_blank(struct fb_info *info, int old_blank);
761762
#else
762763
static inline struct backlight_device *fb_bl_device(struct fb_info *info)
763764
{
764765
return NULL;
765766
}
767+
768+
static inline void fb_bl_notify_blank(struct fb_info *info, int old_blank)
769+
{ }
766770
#endif
767771

768772
static inline struct lcd_device *fb_lcd_device(struct fb_info *info)

0 commit comments

Comments
 (0)