backlight: Fix external uses of backlight internal semaphore
[safe/jmp/linux-2.6] / include / linux / backlight.h
1 /*
2  * Backlight Lowlevel Control Abstraction
3  *
4  * Copyright (C) 2003,2004 Hewlett-Packard Company
5  *
6  */
7
8 #ifndef _LINUX_BACKLIGHT_H
9 #define _LINUX_BACKLIGHT_H
10
11 #include <linux/device.h>
12 #include <linux/mutex.h>
13 #include <linux/notifier.h>
14
15 /* Notes on locking:
16  *
17  * backlight_device->sem is an internal backlight lock protecting the props
18  * field 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
30 struct backlight_device;
31 struct fb_info;
32
33 /* This structure defines all the properties of a backlight
34    (usually attached to a LCD). */
35 struct backlight_properties {
36         /* Notify the backlight driver some property has changed */
37         int (*update_status)(struct backlight_device *);
38         /* Return the current backlight brightness (accounting for power,
39            fb_blank etc.) */
40         int (*get_brightness)(struct backlight_device *);
41         /* Check if given framebuffer device is the one bound to this backlight;
42            return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */
43         int (*check_fb)(struct fb_info *);
44
45         /* Current User requested brightness (0 - max_brightness) */
46         int brightness;
47         /* Maximal value for brightness (read-only) */
48         int max_brightness;
49         /* Current FB Power mode (0: full on, 1..3: power saving
50            modes; 4: full off), see FB_BLANK_XXX */
51         int power;
52         /* FB Blanking active? (values as for power) */
53         int fb_blank;
54 };
55
56 struct backlight_device {
57         /* This protects the 'props' field. If 'props' is NULL, the driver that
58            registered this device has been unloaded, and if class_get_devdata()
59            points to something in the body of that driver, it is also invalid. */
60         struct semaphore sem;
61         /* If this is NULL, the backing module is unloaded */
62         struct backlight_properties *props;
63         /* Serialise access to update_status method */
64         struct mutex update_lock;
65         /* The framebuffer notifier block */
66         struct notifier_block fb_notif;
67         /* The class device structure */
68         struct class_device class_dev;
69 };
70
71 static inline void backlight_update_status(struct backlight_device *bd)
72 {
73         mutex_lock(&bd->update_lock);
74         if (bd->props && bd->props->update_status)
75                 bd->props->update_status(bd);
76         mutex_unlock(&bd->update_lock);
77 }
78
79 extern struct backlight_device *backlight_device_register(const char *name,
80         struct device *dev,void *devdata,struct backlight_properties *bp);
81 extern void backlight_device_unregister(struct backlight_device *bd);
82
83 #define to_backlight_device(obj) container_of(obj, struct backlight_device, class_dev)
84
85 #endif