aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/backlight.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/backlight.h')
-rw-r--r--include/linux/backlight.h50
1 files changed, 39 insertions, 11 deletions
diff --git a/include/linux/backlight.h b/include/linux/backlight.h
index a5cf1beacb44..1023ba0d6e55 100644
--- a/include/linux/backlight.h
+++ b/include/linux/backlight.h
@@ -9,17 +9,28 @@
9#define _LINUX_BACKLIGHT_H 9#define _LINUX_BACKLIGHT_H
10 10
11#include <linux/device.h> 11#include <linux/device.h>
12#include <linux/mutex.h>
12#include <linux/notifier.h> 13#include <linux/notifier.h>
13 14
15/* Notes on locking:
16 *
17 * backlight_device->ops_lock is an internal backlight lock protecting the
18 * ops pointer and no code outside the core should need to touch it.
19 *
20 * Access to update_status() is serialised by the update_lock mutex since
21 * most drivers seem to need this and historically get it wrong.
22 *
23 * Most drivers don't need locking on their get_brightness() method.
24 * If yours does, you need to implement it in the driver. You can use the
25 * update_lock mutex if appropriate.
26 *
27 * Any other use of the locks below is probably wrong.
28 */
29
14struct backlight_device; 30struct backlight_device;
15struct fb_info; 31struct fb_info;
16 32
17/* This structure defines all the properties of a backlight 33struct backlight_ops {
18 (usually attached to a LCD). */
19struct backlight_properties {
20 /* Owner module */
21 struct module *owner;
22
23 /* Notify the backlight driver some property has changed */ 34 /* Notify the backlight driver some property has changed */
24 int (*update_status)(struct backlight_device *); 35 int (*update_status)(struct backlight_device *);
25 /* Return the current backlight brightness (accounting for power, 36 /* Return the current backlight brightness (accounting for power,
@@ -28,7 +39,10 @@ struct backlight_properties {
28 /* Check if given framebuffer device is the one bound to this backlight; 39 /* Check if given framebuffer device is the one bound to this backlight;
29 return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */ 40 return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */
30 int (*check_fb)(struct fb_info *); 41 int (*check_fb)(struct fb_info *);
42};
31 43
44/* This structure defines all the properties of a backlight */
45struct backlight_properties {
32 /* Current User requested brightness (0 - max_brightness) */ 46 /* Current User requested brightness (0 - max_brightness) */
33 int brightness; 47 int brightness;
34 /* Maximal value for brightness (read-only) */ 48 /* Maximal value for brightness (read-only) */
@@ -41,20 +55,34 @@ struct backlight_properties {
41}; 55};
42 56
43struct backlight_device { 57struct backlight_device {
44 /* This protects the 'props' field. If 'props' is NULL, the driver that 58 /* Backlight properties */
59 struct backlight_properties props;
60
61 /* Serialise access to update_status method */
62 struct mutex update_lock;
63
64 /* This protects the 'ops' field. If 'ops' is NULL, the driver that
45 registered this device has been unloaded, and if class_get_devdata() 65 registered this device has been unloaded, and if class_get_devdata()
46 points to something in the body of that driver, it is also invalid. */ 66 points to something in the body of that driver, it is also invalid. */
47 struct semaphore sem; 67 struct mutex ops_lock;
48 /* If this is NULL, the backing module is unloaded */ 68 struct backlight_ops *ops;
49 struct backlight_properties *props; 69
50 /* The framebuffer notifier block */ 70 /* The framebuffer notifier block */
51 struct notifier_block fb_notif; 71 struct notifier_block fb_notif;
52 /* The class device structure */ 72 /* The class device structure */
53 struct class_device class_dev; 73 struct class_device class_dev;
54}; 74};
55 75
76static inline void backlight_update_status(struct backlight_device *bd)
77{
78 mutex_lock(&bd->update_lock);
79 if (bd->ops && bd->ops->update_status)
80 bd->ops->update_status(bd);
81 mutex_unlock(&bd->update_lock);
82}
83
56extern struct backlight_device *backlight_device_register(const char *name, 84extern struct backlight_device *backlight_device_register(const char *name,
57 struct device *dev,void *devdata,struct backlight_properties *bp); 85 struct device *dev, void *devdata, struct backlight_ops *ops);
58extern void backlight_device_unregister(struct backlight_device *bd); 86extern void backlight_device_unregister(struct backlight_device *bd);
59 87
60#define to_backlight_device(obj) container_of(obj, struct backlight_device, class_dev) 88#define to_backlight_device(obj) container_of(obj, struct backlight_device, class_dev)