]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
backlight: Implement fbdev tracking with blank state from event
authorThomas Zimmermann <tzimmermann@suse.de>
Fri, 21 Mar 2025 09:53:57 +0000 (10:53 +0100)
committerLee Jones <lee@kernel.org>
Thu, 10 Apr 2025 09:39:00 +0000 (10:39 +0100)
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>
drivers/video/backlight/backlight.c
include/linux/backlight.h

index f699e5827ccb3a41360a01a69dd2ac501d765510..bb01f57c4683a11cf6eee1969015a9b7cb96dfef 100644 (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);
index f5652e5a9060f69c43a708fec8bbffbd3a29da94..03723a5478f8c181cc1c41ea543044b2f6b3447a 100644 (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;
 };