backlight: Fix external uses of backlight internal semaphore
[linux-2.6/btrfs-unstable.git] / include / linux / backlight.h
blobd1426b852bdfe28001b86b95532cd0c1d62971d8
1 /*
2 * Backlight Lowlevel Control Abstraction
4 * Copyright (C) 2003,2004 Hewlett-Packard Company
6 */
8 #ifndef _LINUX_BACKLIGHT_H
9 #define _LINUX_BACKLIGHT_H
11 #include <linux/device.h>
12 #include <linux/mutex.h>
13 #include <linux/notifier.h>
15 /* Notes on locking:
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.
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.
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.
27 * Any other use of the locks below is probably wrong.
30 struct backlight_device;
31 struct fb_info;
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 *);
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;
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;
71 static inline void backlight_update_status(struct backlight_device *bd)
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);
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);
83 #define to_backlight_device(obj) container_of(obj, struct backlight_device, class_dev)
85 #endif