backlight: Implement fbdev tracking with blank state from event

Look at the blank state provided by FB_EVENT_BLANK to determine
whether to enable or disable a backlight. Remove the tracking fields
from struct backlight_device.

Tracking requires three variables, fb_on, prev_fb_on and the
backlight's use_count. If fb_on is true, the display has been
unblanked. The backlight needs to be enabled if the display was
blanked before (i.e., prev_fb_on is false) or if use_count is still
at 0. If fb_on is false, the display has been blanked. In this case,
the backlight has to be disabled was unblanked before and the
backlight's use_count is greater than 0.

This change removes fbdev state tracking from blacklight. All the
backlight requires it its own use counter and information about
changes to the display. Removing fbdev internals makes  backlight
drivers easier to integrate into other display drivers, such as DRM.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: "Daniel Thompson (RISCstar)" <danielt@kernel.org>
Acked-by: Simona Vetter <simona.vetter@ffwll.ch>
Link: https://lore.kernel.org/r/20250321095517.313713-5-tzimmermann@suse.de
Signed-off-by: Lee Jones <lee@kernel.org>
This commit is contained in:
Thomas Zimmermann
2025-03-21 10:53:57 +01:00
committed by Lee Jones
parent dfb4bf1ac4
commit 726491f203
2 changed files with 8 additions and 16 deletions
+7 -7
View File
@@ -98,9 +98,9 @@ static int fb_notifier_callback(struct notifier_block *self,
struct backlight_device *bd;
struct fb_event *evdata = data;
struct fb_info *info = evdata->info;
const int *fb_blank = evdata->data;
struct backlight_device *fb_bd = fb_bl_device(info);
int node = info->node;
int fb_blank = 0;
bool fb_on, prev_fb_on;
/* If we aren't interested in this event, skip it immediately ... */
if (event != FB_EVENT_BLANK)
@@ -116,15 +116,15 @@ static int fb_notifier_callback(struct notifier_block *self,
if (fb_bd && fb_bd != bd)
goto out;
fb_blank = *(int *)evdata->data;
if (fb_blank == FB_BLANK_UNBLANK && !bd->fb_bl_on[node]) {
bd->fb_bl_on[node] = true;
fb_on = fb_blank[0] == FB_BLANK_UNBLANK;
prev_fb_on = fb_blank[1] == FB_BLANK_UNBLANK;
if (fb_on && (!prev_fb_on || !bd->use_count)) {
if (!bd->use_count++) {
bd->props.state &= ~BL_CORE_FBBLANK;
backlight_update_status(bd);
}
} else if (fb_blank != FB_BLANK_UNBLANK && bd->fb_bl_on[node]) {
bd->fb_bl_on[node] = false;
} else if (!fb_on && prev_fb_on && bd->use_count) {
if (!(--bd->use_count)) {
bd->props.state |= BL_CORE_FBBLANK;
backlight_update_status(bd);
+1 -9
View File
@@ -294,15 +294,7 @@ struct backlight_device {
struct device dev;
/**
* @fb_bl_on: The state of individual fbdev's.
*
* Multiple fbdev's may share one backlight device. The fb_bl_on
* records the state of the individual fbdev.
*/
bool fb_bl_on[FB_MAX];
/**
* @use_count: The number of uses of fb_bl_on.
* @use_count: The number of unblanked displays.
*/
int use_count;
};