2 * Backlight Lowlevel Control Abstraction
4 * Copyright (C) 2003,2004 Hewlett-Packard Company
8 #ifndef _LINUX_BACKLIGHT_H
9 #define _LINUX_BACKLIGHT_H
11 #include <linux/device.h>
13 #include <linux/mutex.h>
14 #include <linux/notifier.h>
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
,
43 enum backlight_notification
{
45 BACKLIGHT_UNREGISTERED
,
48 struct backlight_device
;
51 struct backlight_ops
{
54 #define BL_CORE_SUSPENDRESUME (1 << 0)
56 /* Notify the backlight driver some property has changed */
57 int (*update_status
)(struct backlight_device
*);
58 /* Return the current backlight brightness (accounting for power,
60 int (*get_brightness
)(struct backlight_device
*);
61 /* Check if given framebuffer device is the one bound to this backlight;
62 return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */
63 int (*check_fb
)(struct backlight_device
*, struct fb_info
*);
66 /* This structure defines all the properties of a backlight */
67 struct backlight_properties
{
68 /* Current User requested brightness (0 - max_brightness) */
70 /* Maximal value for brightness (read-only) */
72 /* Current FB Power mode (0: full on, 1..3: power saving
73 modes; 4: full off), see FB_BLANK_XXX */
75 /* FB Blanking active? (values as for power) */
76 /* Due to be removed, please use (state & BL_CORE_FBBLANK) */
79 enum backlight_type type
;
80 /* Flags used to signal drivers of state changes */
81 /* Upper 4 bits are reserved for driver internal use */
84 #define BL_CORE_SUSPENDED (1 << 0) /* backlight is suspended */
85 #define BL_CORE_FBBLANK (1 << 1) /* backlight is under an fb blank event */
86 #define BL_CORE_DRIVER4 (1 << 28) /* reserved for driver specific use */
87 #define BL_CORE_DRIVER3 (1 << 29) /* reserved for driver specific use */
88 #define BL_CORE_DRIVER2 (1 << 30) /* reserved for driver specific use */
89 #define BL_CORE_DRIVER1 (1 << 31) /* reserved for driver specific use */
93 struct backlight_device
{
94 /* Backlight properties */
95 struct backlight_properties props
;
97 /* Serialise access to update_status method */
98 struct mutex update_lock
;
100 /* This protects the 'ops' field. If 'ops' is NULL, the driver that
101 registered this device has been unloaded, and if class_get_devdata()
102 points to something in the body of that driver, it is also invalid. */
103 struct mutex ops_lock
;
104 const struct backlight_ops
*ops
;
106 /* The framebuffer notifier block */
107 struct notifier_block fb_notif
;
109 /* list entry of all registered backlight devices */
110 struct list_head entry
;
114 /* Multiple framebuffers may share one backlight device */
115 bool fb_bl_on
[FB_MAX
];
120 static inline int backlight_update_status(struct backlight_device
*bd
)
124 mutex_lock(&bd
->update_lock
);
125 if (bd
->ops
&& bd
->ops
->update_status
)
126 ret
= bd
->ops
->update_status(bd
);
127 mutex_unlock(&bd
->update_lock
);
132 extern struct backlight_device
*backlight_device_register(const char *name
,
133 struct device
*dev
, void *devdata
, const struct backlight_ops
*ops
,
134 const struct backlight_properties
*props
);
135 extern struct backlight_device
*devm_backlight_device_register(
136 struct device
*dev
, const char *name
, struct device
*parent
,
137 void *devdata
, const struct backlight_ops
*ops
,
138 const struct backlight_properties
*props
);
139 extern void backlight_device_unregister(struct backlight_device
*bd
);
140 extern void devm_backlight_device_unregister(struct device
*dev
,
141 struct backlight_device
*bd
);
142 extern void backlight_force_update(struct backlight_device
*bd
,
143 enum backlight_update_reason reason
);
144 extern bool backlight_device_registered(enum backlight_type type
);
145 extern int backlight_register_notifier(struct notifier_block
*nb
);
146 extern int backlight_unregister_notifier(struct notifier_block
*nb
);
148 #define to_backlight_device(obj) container_of(obj, struct backlight_device, dev)
150 static inline void * bl_get_data(struct backlight_device
*bl_dev
)
152 return dev_get_drvdata(&bl_dev
->dev
);
155 struct generic_bl_info
{
158 int default_intensity
;
160 void (*set_bl_intensity
)(int intensity
);
161 void (*kick_battery
)(void);
165 struct backlight_device
*of_find_backlight_by_node(struct device_node
*node
);
167 static inline struct backlight_device
*
168 of_find_backlight_by_node(struct device_node
*node
)