Skip to content

Commit 5915a3d

Browse files
Aaron Lurafaeljw
authored andcommitted
backlight: introduce backlight_device_registered
Introduce a new API for modules to query if a specific type of backlight device has been registered. This is useful for some backlight device provider module (e.g. ACPI video) to know if a native control interface(e.g. the interface created by i915) is available and then do things accordingly (e.g. avoid registering its own on Win8 systems). Signed-off-by: Aaron Lu <aaron.lu@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 068aab7 commit 5915a3d

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

drivers/video/backlight/backlight.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
#include <asm/backlight.h>
2222
#endif
2323

24+
static struct list_head backlight_dev_list;
25+
static struct mutex backlight_dev_list_mutex;
26+
2427
static const char *const backlight_types[] = {
2528
[BACKLIGHT_RAW] = "raw",
2629
[BACKLIGHT_PLATFORM] = "platform",
@@ -349,10 +352,32 @@ struct backlight_device *backlight_device_register(const char *name,
349352
mutex_unlock(&pmac_backlight_mutex);
350353
#endif
351354

355+
mutex_lock(&backlight_dev_list_mutex);
356+
list_add(&new_bd->entry, &backlight_dev_list);
357+
mutex_unlock(&backlight_dev_list_mutex);
358+
352359
return new_bd;
353360
}
354361
EXPORT_SYMBOL(backlight_device_register);
355362

363+
bool backlight_device_registered(enum backlight_type type)
364+
{
365+
bool found = false;
366+
struct backlight_device *bd;
367+
368+
mutex_lock(&backlight_dev_list_mutex);
369+
list_for_each_entry(bd, &backlight_dev_list, entry) {
370+
if (bd->props.type == type) {
371+
found = true;
372+
break;
373+
}
374+
}
375+
mutex_unlock(&backlight_dev_list_mutex);
376+
377+
return found;
378+
}
379+
EXPORT_SYMBOL(backlight_device_registered);
380+
356381
/**
357382
* backlight_device_unregister - unregisters a backlight device object.
358383
* @bd: the backlight device object to be unregistered and freed.
@@ -364,6 +389,10 @@ void backlight_device_unregister(struct backlight_device *bd)
364389
if (!bd)
365390
return;
366391

392+
mutex_lock(&backlight_dev_list_mutex);
393+
list_del(&bd->entry);
394+
mutex_unlock(&backlight_dev_list_mutex);
395+
367396
#ifdef CONFIG_PMAC_BACKLIGHT
368397
mutex_lock(&pmac_backlight_mutex);
369398
if (pmac_backlight == bd)
@@ -499,6 +528,8 @@ static int __init backlight_class_init(void)
499528

500529
backlight_class->dev_groups = bl_device_groups;
501530
backlight_class->pm = &backlight_class_dev_pm_ops;
531+
INIT_LIST_HEAD(&backlight_dev_list);
532+
mutex_init(&backlight_dev_list_mutex);
502533
return 0;
503534
}
504535

include/linux/backlight.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ struct backlight_device {
100100
/* The framebuffer notifier block */
101101
struct notifier_block fb_notif;
102102

103+
/* list entry of all registered backlight devices */
104+
struct list_head entry;
105+
103106
struct device dev;
104107
};
105108

@@ -123,6 +126,7 @@ extern void devm_backlight_device_unregister(struct device *dev,
123126
struct backlight_device *bd);
124127
extern void backlight_force_update(struct backlight_device *bd,
125128
enum backlight_update_reason reason);
129+
extern bool backlight_device_registered(enum backlight_type type);
126130

127131
#define to_backlight_device(obj) container_of(obj, struct backlight_device, dev)
128132

0 commit comments

Comments
 (0)