blk-mq: bitmap tag: use clear_bit_unlock in bt_clear_tag()
[linux-2.6/btrfs-unstable.git] / include / linux / backlight.h
blob72647429adf61e3fac4b0b91efc0f9c1eeb2c63c
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/fb.h>
13 #include <linux/mutex.h>
14 #include <linux/notifier.h>
16 /* Notes on locking:
18 * backlight_device->ops_lock is an internal backlight lock protecting the
19 * ops pointer and no code outside the core should need to touch it.
21 * Access to update_status() is serialised by the update_lock mutex since
22 * most drivers seem to need this and historically get it wrong.
24 * Most drivers don't need locking on their get_brightness() method.
25 * If yours does, you need to implement it in the driver. You can use the
26 * update_lock mutex if appropriate.
28 * Any other use of the locks below is probably wrong.
31 enum backlight_update_reason {
32 BACKLIGHT_UPDATE_HOTKEY,
33 BACKLIGHT_UPDATE_SYSFS,
36 enum backlight_type {
37 BACKLIGHT_RAW = 1,
38 BACKLIGHT_PLATFORM,
39 BACKLIGHT_FIRMWARE,
40 BACKLIGHT_TYPE_MAX,
43 struct backlight_device;
44 struct fb_info;
46 struct backlight_ops {
47 unsigned int options;
49 #define BL_CORE_SUSPENDRESUME (1 << 0)
51 /* Notify the backlight driver some property has changed */
52 int (*update_status)(struct backlight_device *);
53 /* Return the current backlight brightness (accounting for power,
54 fb_blank etc.) */
55 int (*get_brightness)(struct backlight_device *);
56 /* Check if given framebuffer device is the one bound to this backlight;
57 return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */
58 int (*check_fb)(struct backlight_device *, struct fb_info *);
61 /* This structure defines all the properties of a backlight */
62 struct backlight_properties {
63 /* Current User requested brightness (0 - max_brightness) */
64 int brightness;
65 /* Maximal value for brightness (read-only) */
66 int max_brightness;
67 /* Current FB Power mode (0: full on, 1..3: power saving
68 modes; 4: full off), see FB_BLANK_XXX */
69 int power;
70 /* FB Blanking active? (values as for power) */
71 /* Due to be removed, please use (state & BL_CORE_FBBLANK) */
72 int fb_blank;
73 /* Backlight type */
74 enum backlight_type type;
75 /* Flags used to signal drivers of state changes */
76 /* Upper 4 bits are reserved for driver internal use */
77 unsigned int state;
79 #define BL_CORE_SUSPENDED (1 << 0) /* backlight is suspended */
80 #define BL_CORE_FBBLANK (1 << 1) /* backlight is under an fb blank event */
81 #define BL_CORE_DRIVER4 (1 << 28) /* reserved for driver specific use */
82 #define BL_CORE_DRIVER3 (1 << 29) /* reserved for driver specific use */
83 #define BL_CORE_DRIVER2 (1 << 30) /* reserved for driver specific use */
84 #define BL_CORE_DRIVER1 (1 << 31) /* reserved for driver specific use */
88 struct backlight_device {
89 /* Backlight properties */
90 struct backlight_properties props;
92 /* Serialise access to update_status method */
93 struct mutex update_lock;
95 /* This protects the 'ops' field. If 'ops' is NULL, the driver that
96 registered this device has been unloaded, and if class_get_devdata()
97 points to something in the body of that driver, it is also invalid. */
98 struct mutex ops_lock;
99 const struct backlight_ops *ops;
101 /* The framebuffer notifier block */
102 struct notifier_block fb_notif;
104 /* list entry of all registered backlight devices */
105 struct list_head entry;
107 struct device dev;
109 /* Multiple framebuffers may share one backlight device */
110 bool fb_bl_on[FB_MAX];
112 int use_count;
115 static inline void backlight_update_status(struct backlight_device *bd)
117 mutex_lock(&bd->update_lock);
118 if (bd->ops && bd->ops->update_status)
119 bd->ops->update_status(bd);
120 mutex_unlock(&bd->update_lock);
123 extern struct backlight_device *backlight_device_register(const char *name,
124 struct device *dev, void *devdata, const struct backlight_ops *ops,
125 const struct backlight_properties *props);
126 extern struct backlight_device *devm_backlight_device_register(
127 struct device *dev, const char *name, struct device *parent,
128 void *devdata, const struct backlight_ops *ops,
129 const struct backlight_properties *props);
130 extern void backlight_device_unregister(struct backlight_device *bd);
131 extern void devm_backlight_device_unregister(struct device *dev,
132 struct backlight_device *bd);
133 extern void backlight_force_update(struct backlight_device *bd,
134 enum backlight_update_reason reason);
135 extern bool backlight_device_registered(enum backlight_type type);
137 #define to_backlight_device(obj) container_of(obj, struct backlight_device, dev)
139 static inline void * bl_get_data(struct backlight_device *bl_dev)
141 return dev_get_drvdata(&bl_dev->dev);
144 struct generic_bl_info {
145 const char *name;
146 int max_intensity;
147 int default_intensity;
148 int limit_mask;
149 void (*set_bl_intensity)(int intensity);
150 void (*kick_battery)(void);
153 #ifdef CONFIG_OF
154 struct backlight_device *of_find_backlight_by_node(struct device_node *node);
155 #else
156 static inline struct backlight_device *
157 of_find_backlight_by_node(struct device_node *node)
159 return NULL;
161 #endif
163 #endif