3
0
Fork 0
forked from mirrors/linux

Backlight for v6.16

* Framebuffer Subsystem (fbdev):
     * The display's blanking status is now tracked in `struct fb_info`
     * `framebuffer_alloc()` initializes the blank state to `FB_BLANK_UNBLANK`
     * `register_framebuffer()` sets the state to `FB_BLANK_POWERDOWN` if an `fb_blank`
       callback exists, ensuring `FB_EVENT_BLANK` listeners correctly see the display
       being turned on during the first modeset
     * The `FB_EVENT_BLANK` event data now includes both the new and the old blank states
   * Qualcomm WLED Backlight:
     * Added a NULL check after `devm_kasprintf()` in `wled_configure()` to prevent a
       potential NULL pointer dereference if memory allocation fails
 
   * Framebuffer Subsystem (fbdev):
     * `fb_blank()` has been reworked to return early on errors, without functional
       changes, in preparation for further state tracking improvements
     * Fbdev now calls dedicated functions in the backlight subsystems to notify them
       of blank state changes, instead of relying on fbdev event notifiers
     * For LCDs, fbdev also calls a dedicated function to notify of mode changes
   * Backlight Subsystem:
     * Implemented fbdev blank state tracking using the (newly enhanced) blank state
       information provided directly by `FB_EVENT_BLANK`
     * Removed internal blank state tracking fields (`fb_bl_on`) from
       `struct backlight_device`
     * Moved the handling of blank-state updates into a separate internal helper
       function, `backlight_notify_blank()`
     * Removed support for fbdev events and replaced it with a dedicated function call
       interface (`backlight_notify_blank()` and `backlight_notify_blank_all()`) for
       display drivers to update backlight status
   * LCD Subsystem:
     * Moved the handling of display updates (blank events and mode changes) from
       fbdev event notifiers to separate internal helper functions (`lcd_notify_blank`,
       `lcd_notify_mode_change`)
     * Removed support for fbdev events and replaced it with dedicated function call
       interfaces (`lcd_notify_blank_all()`, `lcd_notify_mode_change_all()`)
     * The LCD subsystem now maintains its own internal list of LCD devices instead of
       relying on fbdev notifiers
   * LED Backlight Trigger:
     * Moved the handling of blank-state updates into a separate internal helper,
       `ledtrig_backlight_notify_blank()`
     * Removed support for fbdev events and replaced it with a dedicated function call,
       `ledtrig_backlight_blank()`, for fbdev to notify trigger of blank state changes
     * The LED backlight trigger now maintains its own internal list of triggers
       instead of relying on fbdev notifiers
 
   * Framebuffer Subsystem (fbdev):
     * Removed the definitions for the unused fbdev event constants
       `FB_EVENT_MODE_CHANGE` and `FB_EVENT_BLANK` from the header file
 -----BEGIN PGP SIGNATURE-----
 
 iQIzBAABCgAdFiEEdrbJNaO+IJqU8IdIUa+KL4f8d2EFAmg+xqwACgkQUa+KL4f8
 d2EIgA//SGigE46rNLd1+s87V4latrf672BtTs+2sioAGY7f9nzEdntMjk7o9/2G
 U//hJXP2Qr5WLdPVUQOi2ZZUMCks7sMgVx0KfCFiiYW8W0Vwhvl+17ZF3HLOqCCf
 JdQ9m69B1ubdAuyxD91ad84lofZtYEjDw/gK95gNrTaLhx4s/T5G9MrDU+qlZs3y
 npDhrnoQCclFcawSSDDhTUjiRcJFs3V1h3jUGi0Pz8PL1K/maR4fwgvw4ovkDjsR
 5on6cBjpuQoxz1KqlauuSc6OKWZUq8OHrFl7T9YIbn5ACuq2z47XBO0uluCJjrip
 MLvDCpxb7BcDRwcKDMZff6PWJMm4czVnNMgeGlQIUeIvZ/oD4CLCbas9BRYLiDpG
 jIzQOk7TSLiZaPwZFNoxRMJFKdC63K9+dLmncpKuAGf9Lh7fYdDv2Ch605zy1Zxf
 wumU9Bw2rj32iLaIUrsQHN6liIj41tHocRJHOUDkKb2fqzxq17+6NAe2qriRMHoS
 n4Mp+FmKUeBothw5bgRUKRZP4ff8stM0mCDL7ChKxNqJi4Wal8ok+hg3jhNZfW+O
 8ulSwrhJW/hjLrW29RyQIyB2Bz19H4/ZKdRjxfHgWgUdXQZLH5zBhtE0IISbdrBC
 FiRtrDyeWN1btvatEp4CKeKi6gEO+ZktxsFr5Zi7IYIN685iyug=
 =jhYi
 -----END PGP SIGNATURE-----

Merge tag 'backlight-next-6.16' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight

Pull backlight updates from Lee Jones:
 "Framebuffer Subsystem (fbdev):
   - The display's blanking status is now tracked in 'struct fb_info'
   - 'framebuffer_alloc()' initializes the blank state to FB_BLANK_UNBLANK
   - 'register_framebuffer()' sets the state to 'FB_BLANK_POWERDOWN' if
     an 'fb_blank' callback exists, ensuring 'FB_EVENT_BLANK' listeners
     correctly see the display being turned on during the first modeset
   - The 'FB_EVENT_BLANK' event data now includes both the new and the
     old blank states
   - 'fb_blank()' has been reworked to return early on errors, without
     functional changes, in preparation for further state tracking
     improvements
   - Fbdev now calls dedicated functions in the backlight subsystems to
     notify them of blank state changes, instead of relying on fbdev
     event notifiers
   - For LCDs, fbdev also calls a dedicated function to notify of mode
     changes
   - Removed the definitions for the unused fbdev event constants
     'FB_EVENT_MODE_CHANGE' and 'FB_EVENT_BLANK' from the header file

  Backlight Subsystem:
   - Implemented fbdev blank state tracking using the (newly enhanced)
     blank state information provided directly by 'FB_EVENT_BLANK'
   - Removed internal blank state tracking fields ('fb_bl_on') from
     'struct backlight_device'
   - Moved the handling of blank-state updates into a separate internal
     helper function, 'backlight_notify_blank()'
   - Removed support for fbdev events and replaced it with a dedicated
     function call interface ('backlight_notify_blank()' and
     'backlight_notify_blank_all()') for display drivers to update
     backlight status

  LCD Subsystem:
   - Moved the handling of display updates (blank events and mode
     changes) from fbdev event notifiers to separate internal helper
     functions ('lcd_notify_blank',
     'lcd_notify_mode_change')
   - Removed support for fbdev events and replaced it with dedicated
     function call interfaces ('lcd_notify_blank_all()',
     'lcd_notify_mode_change_all()')
   - The LCD subsystem now maintains its own internal list of LCD
     devices instead of relying on fbdev notifiers

  LED Backlight Trigger:
   - Moved the handling of blank-state updates into a separate internal
     helper, 'ledtrig_backlight_notify_blank()'
   - Removed support for fbdev events and replaced it with a dedicated
     function call, 'ledtrig_backlight_blank()', for fbdev to notify
     trigger of blank state changes
   - The LED backlight trigger now maintains its own internal list of
     triggers instead of relying on fbdev notifiers

  Qualcomm WLED Backlight:
   - Added a NULL check after 'devm_kasprintf()' in 'wled_configure()'
     to prevent a potential NULL pointer dereference if memory
     allocation fails"

* tag 'backlight-next-6.16' of git://git.kernel.org/pub/scm/linux/kernel/git/lee/backlight:
  backlight: pm8941: Add NULL check in wled_configure()
  fbdev: Remove constants of unused events
  leds: backlight trigger: Replace fb events with a dedicated function call
  leds: backlight trigger: Move blank-state handling into helper
  backlight: lcd: Replace fb events with a dedicated function call
  backlight: lcd: Move event handling into helpers
  backlight: Replace fb events with a dedicated function call
  backlight: Move blank-state handling into helper
  backlight: Implement fbdev tracking with blank state from event
  fbdev: Send old blank state in FB_EVENT_BLANK
  fbdev: Track display blanking state
  fbdev: Rework fb_blank()
This commit is contained in:
Linus Torvalds 2025-06-03 12:52:25 -07:00
commit a9dfb7db96
12 changed files with 222 additions and 213 deletions

View file

@ -10,7 +10,6 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/fb.h>
#include <linux/leds.h> #include <linux/leds.h>
#include "../leds.h" #include "../leds.h"
@ -21,29 +20,20 @@ struct bl_trig_notifier {
struct led_classdev *led; struct led_classdev *led;
int brightness; int brightness;
int old_status; int old_status;
struct notifier_block notifier;
unsigned invert; unsigned invert;
struct list_head entry;
}; };
static int fb_notifier_callback(struct notifier_block *p, static DEFINE_MUTEX(ledtrig_backlight_list_mutex);
unsigned long event, void *data) static LIST_HEAD(ledtrig_backlight_list);
static void ledtrig_backlight_notify_blank(struct bl_trig_notifier *n, int new_status)
{ {
struct bl_trig_notifier *n = container_of(p,
struct bl_trig_notifier, notifier);
struct led_classdev *led = n->led; struct led_classdev *led = n->led;
struct fb_event *fb_event = data;
int *blank;
int new_status;
/* If we aren't interested in this event, skip it immediately ... */
if (event != FB_EVENT_BLANK)
return 0;
blank = fb_event->data;
new_status = *blank ? BLANK : UNBLANK;
if (new_status == n->old_status) if (new_status == n->old_status)
return 0; return;
if ((n->old_status == UNBLANK) ^ n->invert) { if ((n->old_status == UNBLANK) ^ n->invert) {
n->brightness = led->brightness; n->brightness = led->brightness;
@ -53,10 +43,20 @@ static int fb_notifier_callback(struct notifier_block *p,
} }
n->old_status = new_status; n->old_status = new_status;
return 0;
} }
void ledtrig_backlight_blank(bool blank)
{
struct bl_trig_notifier *n;
int new_status = blank ? BLANK : UNBLANK;
guard(mutex)(&ledtrig_backlight_list_mutex);
list_for_each_entry(n, &ledtrig_backlight_list, entry)
ledtrig_backlight_notify_blank(n, new_status);
}
EXPORT_SYMBOL(ledtrig_backlight_blank);
static ssize_t bl_trig_invert_show(struct device *dev, static ssize_t bl_trig_invert_show(struct device *dev,
struct device_attribute *attr, char *buf) struct device_attribute *attr, char *buf)
{ {
@ -100,8 +100,6 @@ ATTRIBUTE_GROUPS(bl_trig);
static int bl_trig_activate(struct led_classdev *led) static int bl_trig_activate(struct led_classdev *led)
{ {
int ret;
struct bl_trig_notifier *n; struct bl_trig_notifier *n;
n = kzalloc(sizeof(struct bl_trig_notifier), GFP_KERNEL); n = kzalloc(sizeof(struct bl_trig_notifier), GFP_KERNEL);
@ -112,11 +110,9 @@ static int bl_trig_activate(struct led_classdev *led)
n->led = led; n->led = led;
n->brightness = led->brightness; n->brightness = led->brightness;
n->old_status = UNBLANK; n->old_status = UNBLANK;
n->notifier.notifier_call = fb_notifier_callback;
ret = fb_register_client(&n->notifier); guard(mutex)(&ledtrig_backlight_list_mutex);
if (ret) list_add(&n->entry, &ledtrig_backlight_list);
dev_err(led->dev, "unable to register backlight trigger\n");
return 0; return 0;
} }
@ -125,7 +121,9 @@ static void bl_trig_deactivate(struct led_classdev *led)
{ {
struct bl_trig_notifier *n = led_get_trigger_data(led); struct bl_trig_notifier *n = led_get_trigger_data(led);
fb_unregister_client(&n->notifier); guard(mutex)(&ledtrig_backlight_list_mutex);
list_del(&n->entry);
kfree(n); kfree(n);
} }

View file

@ -15,7 +15,6 @@
#include <linux/notifier.h> #include <linux/notifier.h>
#include <linux/ctype.h> #include <linux/ctype.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/fb.h>
#include <linux/slab.h> #include <linux/slab.h>
#ifdef CONFIG_PMAC_BACKLIGHT #ifdef CONFIG_PMAC_BACKLIGHT
@ -57,10 +56,10 @@
* a hot-key to adjust backlight, the driver must notify the backlight * a hot-key to adjust backlight, the driver must notify the backlight
* core that brightness has changed using backlight_force_update(). * core that brightness has changed using backlight_force_update().
* *
* The backlight driver core receives notifications from fbdev and * Display drives can control the backlight device's status using
* if the event is FB_EVENT_BLANK and if the value of blank, from the * backlight_notify_blank() and backlight_notify_blank_all(). If this
* FBIOBLANK ioctrl, results in a change in the backlight state the * results in a change in the backlight state the functions call the
* update_status() operation is called. * update_status() operation.
*/ */
static struct list_head backlight_dev_list; static struct list_head backlight_dev_list;
@ -78,85 +77,40 @@ static const char *const backlight_scale_types[] = {
[BACKLIGHT_SCALE_NON_LINEAR] = "non-linear", [BACKLIGHT_SCALE_NON_LINEAR] = "non-linear",
}; };
#if defined(CONFIG_FB_CORE) || (defined(CONFIG_FB_CORE_MODULE) && \ void backlight_notify_blank(struct backlight_device *bd, struct device *display_dev,
defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)) bool fb_on, bool prev_fb_on)
/*
* 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)
{ {
struct backlight_device *bd; guard(mutex)(&bd->ops_lock);
struct fb_event *evdata = data;
struct fb_info *info = evdata->info;
struct backlight_device *fb_bd = fb_bl_device(info);
int node = info->node;
int fb_blank = 0;
/* 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);
mutex_lock(&bd->ops_lock);
if (!bd->ops) if (!bd->ops)
goto out; return;
if (bd->ops->controls_device && !bd->ops->controls_device(bd, info->device)) if (bd->ops->controls_device && !bd->ops->controls_device(bd, display_dev))
goto out; return;
if (fb_bd && fb_bd != bd)
goto out;
fb_blank = *(int *)evdata->data; if (fb_on && (!prev_fb_on || !bd->use_count)) {
if (fb_blank == FB_BLANK_UNBLANK && !bd->fb_bl_on[node]) {
bd->fb_bl_on[node] = true;
if (!bd->use_count++) { if (!bd->use_count++) {
bd->props.state &= ~BL_CORE_FBBLANK; bd->props.state &= ~BL_CORE_FBBLANK;
backlight_update_status(bd); backlight_update_status(bd);
} }
} else if (fb_blank != FB_BLANK_UNBLANK && bd->fb_bl_on[node]) { } else if (!fb_on && prev_fb_on && bd->use_count) {
bd->fb_bl_on[node] = false;
if (!(--bd->use_count)) { if (!(--bd->use_count)) {
bd->props.state |= BL_CORE_FBBLANK; bd->props.state |= BL_CORE_FBBLANK;
backlight_update_status(bd); backlight_update_status(bd);
} }
} }
out:
mutex_unlock(&bd->ops_lock);
return 0;
} }
EXPORT_SYMBOL(backlight_notify_blank);
static int backlight_register_fb(struct backlight_device *bd) void backlight_notify_blank_all(struct device *display_dev, bool fb_on, bool prev_fb_on)
{ {
memset(&bd->fb_notif, 0, sizeof(bd->fb_notif)); struct backlight_device *bd;
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) list_for_each_entry(bd, &backlight_dev_list, entry)
{ backlight_notify_blank(bd, display_dev, fb_on, prev_fb_on);
fb_unregister_client(&bd->fb_notif);
} }
#else EXPORT_SYMBOL(backlight_notify_blank_all);
static inline int backlight_register_fb(struct backlight_device *bd)
{
return 0;
}
static inline void backlight_unregister_fb(struct backlight_device *bd)
{
}
#endif /* CONFIG_FB_CORE */
static void backlight_generate_event(struct backlight_device *bd, static void backlight_generate_event(struct backlight_device *bd,
enum backlight_update_reason reason) enum backlight_update_reason reason)
@ -447,12 +401,6 @@ struct backlight_device *backlight_device_register(const char *name,
return ERR_PTR(rc); 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; new_bd->ops = ops;
#ifdef CONFIG_PMAC_BACKLIGHT #ifdef CONFIG_PMAC_BACKLIGHT
@ -539,7 +487,6 @@ void backlight_device_unregister(struct backlight_device *bd)
bd->ops = NULL; bd->ops = NULL;
mutex_unlock(&bd->ops_lock); mutex_unlock(&bd->ops_lock);
backlight_unregister_fb(bd);
device_unregister(&bd->dev); device_unregister(&bd->dev);
} }
EXPORT_SYMBOL(backlight_device_unregister); EXPORT_SYMBOL(backlight_device_unregister);

View file

@ -15,86 +15,59 @@
#include <linux/notifier.h> #include <linux/notifier.h>
#include <linux/ctype.h> #include <linux/ctype.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/fb.h>
#include <linux/slab.h> #include <linux/slab.h>
#if defined(CONFIG_FB) || (defined(CONFIG_FB_MODULE) && \ static DEFINE_MUTEX(lcd_dev_list_mutex);
defined(CONFIG_LCD_CLASS_DEVICE_MODULE)) static LIST_HEAD(lcd_dev_list);
static int to_lcd_power(int fb_blank)
{
switch (fb_blank) {
case FB_BLANK_UNBLANK:
return LCD_POWER_ON;
/* deprecated; TODO: should become 'off' */
case FB_BLANK_NORMAL:
return LCD_POWER_REDUCED;
case FB_BLANK_VSYNC_SUSPEND:
return LCD_POWER_REDUCED_VSYNC_SUSPEND;
/* 'off' */
case FB_BLANK_HSYNC_SUSPEND:
case FB_BLANK_POWERDOWN:
default:
return LCD_POWER_OFF;
}
}
/* This callback gets called when something important happens inside a static void lcd_notify_blank(struct lcd_device *ld, struct device *display_dev,
* framebuffer driver. We're looking if that important event is blanking, int power)
* and if it is, we're switching lcd power as well ...
*/
static int fb_notifier_callback(struct notifier_block *self,
unsigned long event, void *data)
{ {
struct lcd_device *ld = container_of(self, struct lcd_device, fb_notif);
struct fb_event *evdata = data;
struct fb_info *info = evdata->info;
struct lcd_device *fb_lcd = fb_lcd_device(info);
guard(mutex)(&ld->ops_lock); guard(mutex)(&ld->ops_lock);
if (!ld->ops) if (!ld->ops || !ld->ops->set_power)
return 0; return;
if (ld->ops->controls_device && !ld->ops->controls_device(ld, info->device)) if (ld->ops->controls_device && !ld->ops->controls_device(ld, display_dev))
return 0; return;
if (fb_lcd && fb_lcd != ld)
return 0;
if (event == FB_EVENT_BLANK) { ld->ops->set_power(ld, power);
int power = to_lcd_power(*(int *)evdata->data);
if (ld->ops->set_power)
ld->ops->set_power(ld, power);
} else {
const struct fb_videomode *videomode = evdata->data;
if (ld->ops->set_mode)
ld->ops->set_mode(ld, videomode->xres, videomode->yres);
}
return 0;
} }
static int lcd_register_fb(struct lcd_device *ld) void lcd_notify_blank_all(struct device *display_dev, int power)
{ {
memset(&ld->fb_notif, 0, sizeof(ld->fb_notif)); struct lcd_device *ld;
ld->fb_notif.notifier_call = fb_notifier_callback;
return fb_register_client(&ld->fb_notif); guard(mutex)(&lcd_dev_list_mutex);
list_for_each_entry(ld, &lcd_dev_list, entry)
lcd_notify_blank(ld, display_dev, power);
}
EXPORT_SYMBOL(lcd_notify_blank_all);
static void lcd_notify_mode_change(struct lcd_device *ld, struct device *display_dev,
unsigned int width, unsigned int height)
{
guard(mutex)(&ld->ops_lock);
if (!ld->ops || !ld->ops->set_mode)
return;
if (ld->ops->controls_device && !ld->ops->controls_device(ld, display_dev))
return;
ld->ops->set_mode(ld, width, height);
} }
static void lcd_unregister_fb(struct lcd_device *ld) void lcd_notify_mode_change_all(struct device *display_dev,
unsigned int width, unsigned int height)
{ {
fb_unregister_client(&ld->fb_notif); struct lcd_device *ld;
}
#else
static int lcd_register_fb(struct lcd_device *ld)
{
return 0;
}
static inline void lcd_unregister_fb(struct lcd_device *ld) guard(mutex)(&lcd_dev_list_mutex);
{
list_for_each_entry(ld, &lcd_dev_list, entry)
lcd_notify_mode_change(ld, display_dev, width, height);
} }
#endif /* CONFIG_FB */ EXPORT_SYMBOL(lcd_notify_mode_change_all);
static ssize_t lcd_power_show(struct device *dev, struct device_attribute *attr, static ssize_t lcd_power_show(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
@ -245,11 +218,8 @@ struct lcd_device *lcd_device_register(const char *name, struct device *parent,
return ERR_PTR(rc); return ERR_PTR(rc);
} }
rc = lcd_register_fb(new_ld); guard(mutex)(&lcd_dev_list_mutex);
if (rc) { list_add(&new_ld->entry, &lcd_dev_list);
device_unregister(&new_ld->dev);
return ERR_PTR(rc);
}
return new_ld; return new_ld;
} }
@ -266,10 +236,12 @@ void lcd_device_unregister(struct lcd_device *ld)
if (!ld) if (!ld)
return; return;
guard(mutex)(&lcd_dev_list_mutex);
list_del(&ld->entry);
mutex_lock(&ld->ops_lock); mutex_lock(&ld->ops_lock);
ld->ops = NULL; ld->ops = NULL;
mutex_unlock(&ld->ops_lock); mutex_unlock(&ld->ops_lock);
lcd_unregister_fb(ld);
device_unregister(&ld->dev); device_unregister(&ld->dev);
} }

View file

@ -1406,9 +1406,11 @@ static int wled_configure(struct wled *wled)
wled->ctrl_addr = be32_to_cpu(*prop_addr); wled->ctrl_addr = be32_to_cpu(*prop_addr);
rc = of_property_read_string(dev->of_node, "label", &wled->name); rc = of_property_read_string(dev->of_node, "label", &wled->name);
if (rc) if (rc) {
wled->name = devm_kasprintf(dev, GFP_KERNEL, "%pOFn", dev->of_node); wled->name = devm_kasprintf(dev, GFP_KERNEL, "%pOFn", dev->of_node);
if (!wled->name)
return -ENOMEM;
}
switch (wled->version) { switch (wled->version) {
case 3: case 3:
u32_opts = wled3_opts; u32_opts = wled3_opts;

View file

@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-or-later // SPDX-License-Identifier: GPL-2.0-or-later
#include <linux/backlight.h>
#include <linux/export.h> #include <linux/export.h>
#include <linux/fb.h> #include <linux/fb.h>
#include <linux/mutex.h> #include <linux/mutex.h>
@ -36,4 +37,15 @@ struct backlight_device *fb_bl_device(struct fb_info *info)
return info->bl_dev; return info->bl_dev;
} }
EXPORT_SYMBOL(fb_bl_device); 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 #endif

View file

@ -42,6 +42,7 @@ struct fb_info *framebuffer_alloc(size_t size, struct device *dev)
info->device = dev; info->device = dev;
info->fbcon_rotate_hint = -1; info->fbcon_rotate_hint = -1;
info->blank = FB_BLANK_UNBLANK;
#if IS_ENABLED(CONFIG_FB_BACKLIGHT) #if IS_ENABLED(CONFIG_FB_BACKLIGHT)
mutex_init(&info->bl_curve_mutex); mutex_init(&info->bl_curve_mutex);

View file

@ -15,6 +15,8 @@
#include <linux/export.h> #include <linux/export.h>
#include <linux/fb.h> #include <linux/fb.h>
#include <linux/fbcon.h> #include <linux/fbcon.h>
#include <linux/lcd.h>
#include <linux/leds.h>
#include <video/nomodeset.h> #include <video/nomodeset.h>
@ -220,6 +222,12 @@ static int fb_check_caps(struct fb_info *info, struct fb_var_screeninfo *var,
return err; return err;
} }
static void fb_lcd_notify_mode_change(struct fb_info *info,
struct fb_videomode *mode)
{
lcd_notify_mode_change_all(info->device, mode->xres, mode->yres);
}
int int
fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var) fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
{ {
@ -227,7 +235,6 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
u32 activate; u32 activate;
struct fb_var_screeninfo old_var; struct fb_var_screeninfo old_var;
struct fb_videomode mode; struct fb_videomode mode;
struct fb_event event;
u32 unused; u32 unused;
if (var->activate & FB_ACTIVATE_INV_MODE) { if (var->activate & FB_ACTIVATE_INV_MODE) {
@ -333,32 +340,71 @@ fb_set_var(struct fb_info *info, struct fb_var_screeninfo *var)
return ret; return ret;
} }
event.info = info; fb_lcd_notify_mode_change(info, &mode);
event.data = &mode;
fb_notifier_call_chain(FB_EVENT_MODE_CHANGE, &event);
return 0; return 0;
} }
EXPORT_SYMBOL(fb_set_var); EXPORT_SYMBOL(fb_set_var);
int static void fb_lcd_notify_blank(struct fb_info *info)
fb_blank(struct fb_info *info, int blank)
{ {
struct fb_event event; int power;
int ret = -EINVAL;
switch (info->blank) {
case FB_BLANK_UNBLANK:
power = LCD_POWER_ON;
break;
/* deprecated; TODO: should become 'off' */
case FB_BLANK_NORMAL:
power = LCD_POWER_REDUCED;
break;
case FB_BLANK_VSYNC_SUSPEND:
power = LCD_POWER_REDUCED_VSYNC_SUSPEND;
break;
/* 'off' */
case FB_BLANK_HSYNC_SUSPEND:
case FB_BLANK_POWERDOWN:
default:
power = LCD_POWER_OFF;
break;
}
lcd_notify_blank_all(info->device, power);
}
static void fb_ledtrig_backlight_notify_blank(struct fb_info *info)
{
if (info->blank == FB_BLANK_UNBLANK)
ledtrig_backlight_blank(false);
else
ledtrig_backlight_blank(true);
}
int fb_blank(struct fb_info *info, int blank)
{
int old_blank = info->blank;
int ret;
if (!info->fbops->fb_blank)
return -EINVAL;
if (blank > FB_BLANK_POWERDOWN) if (blank > FB_BLANK_POWERDOWN)
blank = FB_BLANK_POWERDOWN; blank = FB_BLANK_POWERDOWN;
event.info = info; info->blank = blank;
event.data = &blank;
if (info->fbops->fb_blank) ret = info->fbops->fb_blank(blank, info);
ret = info->fbops->fb_blank(blank, info); if (ret)
goto err;
if (!ret) fb_bl_notify_blank(info, old_blank);
fb_notifier_call_chain(FB_EVENT_BLANK, &event); fb_lcd_notify_blank(info);
fb_ledtrig_backlight_notify_blank(info);
return 0;
err:
info->blank = old_blank;
return ret; return ret;
} }
EXPORT_SYMBOL(fb_blank); EXPORT_SYMBOL(fb_blank);
@ -416,6 +462,14 @@ static int do_register_framebuffer(struct fb_info *fb_info)
mutex_init(&fb_info->lock); mutex_init(&fb_info->lock);
mutex_init(&fb_info->mm_lock); mutex_init(&fb_info->mm_lock);
/*
* With an fb_blank callback present, we assume that the
* display is blank, so that fb_blank() enables it on the
* first modeset.
*/
if (fb_info->fbops->fb_blank)
fb_info->blank = FB_BLANK_POWERDOWN;
fb_device_create(fb_info); fb_device_create(fb_info);
if (fb_info->pixmap.addr == NULL) { if (fb_info->pixmap.addr == NULL) {

View file

@ -242,11 +242,11 @@ static ssize_t store_blank(struct device *device,
return count; return count;
} }
static ssize_t show_blank(struct device *device, static ssize_t show_blank(struct device *device, struct device_attribute *attr, char *buf)
struct device_attribute *attr, char *buf)
{ {
// struct fb_info *fb_info = dev_get_drvdata(device); struct fb_info *fb_info = dev_get_drvdata(device);
return 0;
return sysfs_emit(buf, "%d\n", fb_info->blank);
} }
static ssize_t store_console(struct device *device, static ssize_t store_console(struct device *device,

View file

@ -12,7 +12,6 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/fb.h> #include <linux/fb.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/notifier.h>
#include <linux/types.h> #include <linux/types.h>
/** /**
@ -278,11 +277,6 @@ struct backlight_device {
*/ */
const struct backlight_ops *ops; const struct backlight_ops *ops;
/**
* @fb_notif: The framebuffer notifier block
*/
struct notifier_block fb_notif;
/** /**
* @entry: List entry of all registered backlight devices * @entry: List entry of all registered backlight devices
*/ */
@ -294,15 +288,7 @@ struct backlight_device {
struct device dev; struct device dev;
/** /**
* @fb_bl_on: The state of individual fbdev's. * @use_count: The number of unblanked displays.
*
* 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.
*/ */
int use_count; int use_count;
}; };
@ -408,6 +394,22 @@ struct backlight_device *backlight_device_get_by_type(enum backlight_type type);
int backlight_device_set_brightness(struct backlight_device *bd, int backlight_device_set_brightness(struct backlight_device *bd,
unsigned long brightness); 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) #define to_backlight_device(obj) container_of(obj, struct backlight_device, dev)
/** /**

View file

@ -129,18 +129,12 @@ struct fb_cursor_user {
* Register/unregister for framebuffer events * Register/unregister for framebuffer events
*/ */
/* The resolution of the passed in fb_info about to change */
#define FB_EVENT_MODE_CHANGE 0x01
#ifdef CONFIG_GUMSTIX_AM200EPD #ifdef CONFIG_GUMSTIX_AM200EPD
/* only used by mach-pxa/am200epd.c */ /* only used by mach-pxa/am200epd.c */
#define FB_EVENT_FB_REGISTERED 0x05 #define FB_EVENT_FB_REGISTERED 0x05
#define FB_EVENT_FB_UNREGISTERED 0x06 #define FB_EVENT_FB_UNREGISTERED 0x06
#endif #endif
/* A display blank is requested */
#define FB_EVENT_BLANK 0x09
struct fb_event { struct fb_event {
struct fb_info *info; struct fb_info *info;
void *data; void *data;
@ -472,6 +466,8 @@ struct fb_info {
struct list_head modelist; /* mode list */ struct list_head modelist; /* mode list */
struct fb_videomode *mode; /* current mode */ struct fb_videomode *mode; /* current mode */
int blank; /* current blanking; see FB_BLANK_ constants */
#if IS_ENABLED(CONFIG_FB_BACKLIGHT) #if IS_ENABLED(CONFIG_FB_BACKLIGHT)
/* assigned backlight device */ /* assigned backlight device */
/* set before framebuffer registration, /* set before framebuffer registration,
@ -756,11 +752,15 @@ extern void fb_bl_default_curve(struct fb_info *fb_info, u8 off, u8 min, u8 max)
#if IS_ENABLED(CONFIG_FB_BACKLIGHT) #if IS_ENABLED(CONFIG_FB_BACKLIGHT)
struct backlight_device *fb_bl_device(struct fb_info *info); struct backlight_device *fb_bl_device(struct fb_info *info);
void fb_bl_notify_blank(struct fb_info *info, int old_blank);
#else #else
static inline struct backlight_device *fb_bl_device(struct fb_info *info) static inline struct backlight_device *fb_bl_device(struct fb_info *info)
{ {
return NULL; return NULL;
} }
static inline void fb_bl_notify_blank(struct fb_info *info, int old_blank)
{ }
#endif #endif
static inline struct lcd_device *fb_lcd_device(struct fb_info *info) static inline struct lcd_device *fb_lcd_device(struct fb_info *info)

View file

@ -11,7 +11,6 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/notifier.h>
#define LCD_POWER_ON (0) #define LCD_POWER_ON (0)
#define LCD_POWER_REDUCED (1) // deprecated; don't use in new code #define LCD_POWER_REDUCED (1) // deprecated; don't use in new code
@ -79,8 +78,11 @@ struct lcd_device {
const struct lcd_ops *ops; const struct lcd_ops *ops;
/* Serialise access to set_power method */ /* Serialise access to set_power method */
struct mutex update_lock; struct mutex update_lock;
/* The framebuffer notifier block */
struct notifier_block fb_notif; /**
* @entry: List entry of all registered lcd devices
*/
struct list_head entry;
struct device dev; struct device dev;
}; };
@ -125,6 +127,19 @@ extern void lcd_device_unregister(struct lcd_device *ld);
extern void devm_lcd_device_unregister(struct device *dev, extern void devm_lcd_device_unregister(struct device *dev,
struct lcd_device *ld); struct lcd_device *ld);
#if IS_REACHABLE(CONFIG_LCD_CLASS_DEVICE)
void lcd_notify_blank_all(struct device *display_dev, int power);
void lcd_notify_mode_change_all(struct device *display_dev,
unsigned int width, unsigned int height);
#else
static inline void lcd_notify_blank_all(struct device *display_dev, int power)
{}
static inline void lcd_notify_mode_change_all(struct device *display_dev,
unsigned int width, unsigned int height)
{}
#endif
#define to_lcd_device(obj) container_of(obj, struct lcd_device, dev) #define to_lcd_device(obj) container_of(obj, struct lcd_device, dev)
static inline void * lcd_get_data(struct lcd_device *ld_dev) static inline void * lcd_get_data(struct lcd_device *ld_dev)

View file

@ -640,6 +640,12 @@ static inline void ledtrig_flash_ctrl(bool on) {}
static inline void ledtrig_torch_ctrl(bool on) {} static inline void ledtrig_torch_ctrl(bool on) {}
#endif #endif
#if IS_REACHABLE(CONFIG_LEDS_TRIGGER_BACKLIGHT)
void ledtrig_backlight_blank(bool blank);
#else
static inline void ledtrig_backlight_blank(bool blank) {}
#endif
/* /*
* Generic LED platform data for describing LED names and default triggers. * Generic LED platform data for describing LED names and default triggers.
*/ */