Skip to content

Commit e6c6fea

Browse files
Thomas Zimmermannlag-linaro
authored andcommitted
backlight: Match backlight device against struct fb_info.bl_dev
Framebuffer drivers for devices with dedicated backlight are supposed to set struct fb_info.bl_dev to the backlight's respective device. Use the value to match backlight and framebuffer in the backlight core code. The code first tests against struct backlight_ops.check_ops. If this test succeeds, it performs the test against fbdev. So backlight drivers can override the later test as before. Fbdev's backlight support depends on CONFIG_FB_BACKLIGHT. To avoid ifdef in the code, the new helper fb_bl_device() returns the backlight device, or NULL if the config option has been disabled. The test in the backlight code will then do nothing. v4: * declare empty fb_bl_device() as static inline * export fb_bl_device() v3: * hide ifdef in fb_bl_device() (Lee) * no if-else blocks (Andy) Signed-off-by: Thomas Zimmermann <[email protected]> Reviewed-by: Daniel Thompson <[email protected]> Reviewed-by: Javier Martinez Canillas <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lee Jones <[email protected]>
1 parent 4cece76 commit e6c6fea

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

drivers/video/backlight/backlight.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ static int fb_notifier_callback(struct notifier_block *self,
9898
{
9999
struct backlight_device *bd;
100100
struct fb_event *evdata = data;
101-
int node = evdata->info->node;
101+
struct fb_info *info = evdata->info;
102+
struct backlight_device *fb_bd = fb_bl_device(info);
103+
int node = info->node;
102104
int fb_blank = 0;
103105

104106
/* If we aren't interested in this event, skip it immediately ... */
@@ -110,7 +112,9 @@ static int fb_notifier_callback(struct notifier_block *self,
110112

111113
if (!bd->ops)
112114
goto out;
113-
if (bd->ops->check_fb && !bd->ops->check_fb(bd, evdata->info))
115+
if (bd->ops->check_fb && !bd->ops->check_fb(bd, info))
116+
goto out;
117+
if (fb_bd && fb_bd != bd)
114118
goto out;
115119

116120
fb_blank = *(int *)evdata->data;

drivers/video/fbdev/core/fb_backlight.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,10 @@ void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max)
3030
mutex_unlock(&fb_info->bl_curve_mutex);
3131
}
3232
EXPORT_SYMBOL_GPL(fb_bl_default_curve);
33+
34+
struct backlight_device *fb_bl_device(struct fb_info *info)
35+
{
36+
return info->bl_dev;
37+
}
38+
EXPORT_SYMBOL(fb_bl_device);
3339
#endif

include/linux/fb.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,15 @@ extern struct fb_info *framebuffer_alloc(size_t size, struct device *dev);
738738
extern void framebuffer_release(struct fb_info *info);
739739
extern void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max);
740740

741+
#if IS_ENABLED(CONFIG_FB_BACKLIGHT)
742+
struct backlight_device *fb_bl_device(struct fb_info *info);
743+
#else
744+
static inline struct backlight_device *fb_bl_device(struct fb_info *info)
745+
{
746+
return NULL;
747+
}
748+
#endif
749+
741750
/* fbmon.c */
742751
#define FB_MAXTIMINGS 0
743752
#define FB_VSYNCTIMINGS 1

0 commit comments

Comments
 (0)