]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
backlight: Replace fb events with a dedicated function call
authorThomas Zimmermann <tzimmermann@suse.de>
Fri, 21 Mar 2025 09:53:59 +0000 (10:53 +0100)
committerLee Jones <lee@kernel.org>
Thu, 10 Apr 2025 09:39:03 +0000 (10:39 +0100)
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>
drivers/video/backlight/backlight.c
drivers/video/fbdev/core/fb_backlight.c
drivers/video/fbdev/core/fbmem.c
include/linux/backlight.h
include/linux/fb.h

index 1c43f579396f7875f446bb9bea474549f6dd66d2..9dc93c5e480b40f7ffbf2f6b8aa2005d5eb1bbf9 100644 (file)
@@ -15,7 +15,6 @@
 #include <linux/notifier.h>
 #include <linux/ctype.h>
 #include <linux/err.h>
-#include <linux/fb.h>
 #include <linux/slab.h>
 
 #ifdef CONFIG_PMAC_BACKLIGHT
  * a hot-key to adjust backlight, the driver must notify the backlight
  * core that brightness has changed using backlight_force_update().
  *
- * The backlight driver core receives notifications from fbdev and
- * if the event is FB_EVENT_BLANK and if the value of blank, from the
- * FBIOBLANK ioctrl, results in a change in the backlight state the
- * update_status() operation is called.
+ * Display drives can control the backlight device's status using
+ * backlight_notify_blank() and backlight_notify_blank_all(). If this
+ * results in a change in the backlight state the functions call the
+ * update_status() operation.
  */
 
 static struct list_head backlight_dev_list;
@@ -78,11 +77,8 @@ static const char *const backlight_scale_types[] = {
        [BACKLIGHT_SCALE_NON_LINEAR]    = "non-linear",
 };
 
-#if defined(CONFIG_FB_CORE) || (defined(CONFIG_FB_CORE_MODULE) && \
-                               defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE))
-static void backlight_notify_blank(struct backlight_device *bd,
-                                  struct device *display_dev,
-                                  bool fb_on, bool prev_fb_on)
+void backlight_notify_blank(struct backlight_device *bd, struct device *display_dev,
+                           bool fb_on, bool prev_fb_on)
 {
        guard(mutex)(&bd->ops_lock);
 
@@ -103,68 +99,18 @@ static void backlight_notify_blank(struct backlight_device *bd,
                }
        }
 }
+EXPORT_SYMBOL(backlight_notify_blank);
 
-/*
- * fb_notifier_callback
- *
- * This callback gets called when something important happens inside a
- * framebuffer driver. The backlight core only cares about FB_BLANK_UNBLANK
- * which is reported to the driver using backlight_update_status()
- * as a state change.
- *
- * There may be several fbdev's connected to the backlight device,
- * in which case they are kept track of. A state change is only reported
- * if there is a change in backlight for the specified fbdev.
- */
-static int fb_notifier_callback(struct notifier_block *self,
-                               unsigned long event, void *data)
+void backlight_notify_blank_all(struct device *display_dev, bool fb_on, bool prev_fb_on)
 {
        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);
-       bool fb_on, prev_fb_on;
-
-       /* If we aren't interested in this event, skip it immediately ... */
-       if (event != FB_EVENT_BLANK)
-               return 0;
-
-       bd = container_of(self, struct backlight_device, fb_notif);
-
-       if (fb_bd && fb_bd != bd)
-               return 0;
-
-       fb_on = fb_blank[0] == FB_BLANK_UNBLANK;
-       prev_fb_on = fb_blank[1] == FB_BLANK_UNBLANK;
-
-       backlight_notify_blank(bd, info->device, fb_on, prev_fb_on);
-
-       return 0;
-}
-
-static int backlight_register_fb(struct backlight_device *bd)
-{
-       memset(&bd->fb_notif, 0, sizeof(bd->fb_notif));
-       bd->fb_notif.notifier_call = fb_notifier_callback;
 
-       return fb_register_client(&bd->fb_notif);
-}
+       guard(mutex)(&backlight_dev_list_mutex);
 
-static void backlight_unregister_fb(struct backlight_device *bd)
-{
-       fb_unregister_client(&bd->fb_notif);
-}
-#else
-static inline int backlight_register_fb(struct backlight_device *bd)
-{
-       return 0;
+       list_for_each_entry(bd, &backlight_dev_list, entry)
+               backlight_notify_blank(bd, display_dev, fb_on, prev_fb_on);
 }
-
-static inline void backlight_unregister_fb(struct backlight_device *bd)
-{
-}
-#endif /* CONFIG_FB_CORE */
+EXPORT_SYMBOL(backlight_notify_blank_all);
 
 static void backlight_generate_event(struct backlight_device *bd,
                                     enum backlight_update_reason reason)
@@ -455,12 +401,6 @@ struct backlight_device *backlight_device_register(const char *name,
                return ERR_PTR(rc);
        }
 
-       rc = backlight_register_fb(new_bd);
-       if (rc) {
-               device_unregister(&new_bd->dev);
-               return ERR_PTR(rc);
-       }
-
        new_bd->ops = ops;
 
 #ifdef CONFIG_PMAC_BACKLIGHT
@@ -547,7 +487,6 @@ void backlight_device_unregister(struct backlight_device *bd)
        bd->ops = NULL;
        mutex_unlock(&bd->ops_lock);
 
-       backlight_unregister_fb(bd);
        device_unregister(&bd->dev);
 }
 EXPORT_SYMBOL(backlight_device_unregister);
index 6fdaa9f81be90c413868bdd8f10d025bbb6a8ecd..dbed9696f4c5f6655342894ac58f322a24af4026 100644 (file)
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 
+#include <linux/backlight.h>
 #include <linux/export.h>
 #include <linux/fb.h>
 #include <linux/mutex.h>
@@ -36,4 +37,15 @@ struct backlight_device *fb_bl_device(struct fb_info *info)
        return info->bl_dev;
 }
 EXPORT_SYMBOL(fb_bl_device);
+
+void fb_bl_notify_blank(struct fb_info *info, int old_blank)
+{
+       bool on = info->blank == FB_BLANK_UNBLANK;
+       bool prev_on = old_blank == FB_BLANK_UNBLANK;
+
+       if (info->bl_dev)
+               backlight_notify_blank(info->bl_dev, info->device, on, prev_on);
+       else
+               backlight_notify_blank_all(info->device, on, prev_on);
+}
 #endif
index 9650b641d8e84765fa903774d4d4bfeaa5c73fa6..c931f270ac343eaaf622dfa9c745b4fd5fda85a1 100644 (file)
@@ -363,6 +363,8 @@ int fb_blank(struct fb_info *info, int blank)
        if (ret)
                goto err;
 
+       fb_bl_notify_blank(info, old_blank);
+
        fb_notifier_call_chain(FB_EVENT_BLANK, &event);
 
        return 0;
index 03723a5478f8c181cc1c41ea543044b2f6b3447a..10e626db7eee5a84b21caed1af3bed57b5ae46a0 100644 (file)
@@ -12,7 +12,6 @@
 #include <linux/device.h>
 #include <linux/fb.h>
 #include <linux/mutex.h>
-#include <linux/notifier.h>
 #include <linux/types.h>
 
 /**
@@ -278,11 +277,6 @@ struct backlight_device {
         */
        const struct backlight_ops *ops;
 
-       /**
-        * @fb_notif: The framebuffer notifier block
-        */
-       struct notifier_block fb_notif;
-
        /**
         * @entry: List entry of all registered backlight devices
         */
@@ -400,6 +394,22 @@ struct backlight_device *backlight_device_get_by_type(enum backlight_type type);
 int backlight_device_set_brightness(struct backlight_device *bd,
                                    unsigned long brightness);
 
+#if IS_REACHABLE(CONFIG_BACKLIGHT_CLASS_DEVICE)
+void backlight_notify_blank(struct backlight_device *bd,
+                           struct device *display_dev,
+                           bool fb_on, bool prev_fb_on);
+void backlight_notify_blank_all(struct device *display_dev,
+                               bool fb_on, bool prev_fb_on);
+#else
+static inline void backlight_notify_blank(struct backlight_device *bd,
+                                         struct device *display_dev,
+                                         bool fb_on, bool prev_fb_on)
+{ }
+static inline void backlight_notify_blank_all(struct device *display_dev,
+                                             bool fb_on, bool prev_fb_on)
+{ }
+#endif
+
 #define to_backlight_device(obj) container_of(obj, struct backlight_device, dev)
 
 /**
index 348aa2e146e2afd70fed3f809c42f0afd75e7479..835e13d6eba82c315c4256daee5125dd692299ee 100644 (file)
@@ -758,11 +758,15 @@ extern void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max)
 
 #if IS_ENABLED(CONFIG_FB_BACKLIGHT)
 struct backlight_device *fb_bl_device(struct fb_info *info);
+void fb_bl_notify_blank(struct fb_info *info, int old_blank);
 #else
 static inline struct backlight_device *fb_bl_device(struct fb_info *info)
 {
        return NULL;
 }
+
+static inline void fb_bl_notify_blank(struct fb_info *info, int old_blank)
+{ }
 #endif
 
 static inline struct lcd_device *fb_lcd_device(struct fb_info *info)