]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4 LT |
2 | /* |
3 | * Backlight Lowlevel Control Abstraction | |
4 | * | |
5 | * Copyright (C) 2003,2004 Hewlett-Packard Company | |
6 | * | |
7 | */ | |
8 | ||
9 | #ifndef _LINUX_BACKLIGHT_H | |
10 | #define _LINUX_BACKLIGHT_H | |
11 | ||
12 | #include <linux/device.h> | |
a55944ca | 13 | #include <linux/fb.h> |
28ee086d | 14 | #include <linux/mutex.h> |
1da177e4 LT |
15 | #include <linux/notifier.h> |
16 | ||
28ee086d RP |
17 | /* Notes on locking: |
18 | * | |
599a52d1 RP |
19 | * backlight_device->ops_lock is an internal backlight lock protecting the |
20 | * ops pointer and no code outside the core should need to touch it. | |
28ee086d RP |
21 | * |
22 | * Access to update_status() is serialised by the update_lock mutex since | |
23 | * most drivers seem to need this and historically get it wrong. | |
24 | * | |
25 | * Most drivers don't need locking on their get_brightness() method. | |
26 | * If yours does, you need to implement it in the driver. You can use the | |
27 | * update_lock mutex if appropriate. | |
28 | * | |
29 | * Any other use of the locks below is probably wrong. | |
30 | */ | |
31 | ||
325253a6 MG |
32 | enum backlight_update_reason { |
33 | BACKLIGHT_UPDATE_HOTKEY, | |
34 | BACKLIGHT_UPDATE_SYSFS, | |
35 | }; | |
36 | ||
bb7ca747 MG |
37 | enum backlight_type { |
38 | BACKLIGHT_RAW = 1, | |
39 | BACKLIGHT_PLATFORM, | |
40 | BACKLIGHT_FIRMWARE, | |
41 | BACKLIGHT_TYPE_MAX, | |
42 | }; | |
43 | ||
3cc6919b HG |
44 | enum backlight_notification { |
45 | BACKLIGHT_REGISTERED, | |
46 | BACKLIGHT_UNREGISTERED, | |
47 | }; | |
48 | ||
d55c028f MK |
49 | enum backlight_scale { |
50 | BACKLIGHT_SCALE_UNKNOWN = 0, | |
51 | BACKLIGHT_SCALE_LINEAR, | |
52 | BACKLIGHT_SCALE_NON_LINEAR, | |
53 | }; | |
54 | ||
1da177e4 LT |
55 | struct backlight_device; |
56 | struct fb_info; | |
57 | ||
599a52d1 | 58 | struct backlight_ops { |
b4144e4f | 59 | unsigned int options; |
c835ee7f RP |
60 | |
61 | #define BL_CORE_SUSPENDRESUME (1 << 0) | |
62 | ||
6ca01765 | 63 | /* Notify the backlight driver some property has changed */ |
b4144e4f | 64 | int (*update_status)(struct backlight_device *); |
6ca01765 RP |
65 | /* Return the current backlight brightness (accounting for power, |
66 | fb_blank etc.) */ | |
b4144e4f | 67 | int (*get_brightness)(struct backlight_device *); |
1da177e4 LT |
68 | /* Check if given framebuffer device is the one bound to this backlight; |
69 | return 0 if not, !=0 if it is. If NULL, backlight always matches the fb. */ | |
57e148b6 | 70 | int (*check_fb)(struct backlight_device *, struct fb_info *); |
599a52d1 | 71 | }; |
6ca01765 | 72 | |
599a52d1 RP |
73 | /* This structure defines all the properties of a backlight */ |
74 | struct backlight_properties { | |
6ca01765 RP |
75 | /* Current User requested brightness (0 - max_brightness) */ |
76 | int brightness; | |
77 | /* Maximal value for brightness (read-only) */ | |
78 | int max_brightness; | |
79 | /* Current FB Power mode (0: full on, 1..3: power saving | |
80 | modes; 4: full off), see FB_BLANK_XXX */ | |
81 | int power; | |
82 | /* FB Blanking active? (values as for power) */ | |
c835ee7f | 83 | /* Due to be removed, please use (state & BL_CORE_FBBLANK) */ |
6ca01765 | 84 | int fb_blank; |
bb7ca747 MG |
85 | /* Backlight type */ |
86 | enum backlight_type type; | |
c835ee7f | 87 | /* Flags used to signal drivers of state changes */ |
c835ee7f | 88 | unsigned int state; |
d55c028f MK |
89 | /* Type of the brightness scale (linear, non-linear, ...) */ |
90 | enum backlight_scale scale; | |
c835ee7f RP |
91 | |
92 | #define BL_CORE_SUSPENDED (1 << 0) /* backlight is suspended */ | |
93 | #define BL_CORE_FBBLANK (1 << 1) /* backlight is under an fb blank event */ | |
c835ee7f | 94 | |
1da177e4 LT |
95 | }; |
96 | ||
97 | struct backlight_device { | |
599a52d1 RP |
98 | /* Backlight properties */ |
99 | struct backlight_properties props; | |
100 | ||
28ee086d RP |
101 | /* Serialise access to update_status method */ |
102 | struct mutex update_lock; | |
599a52d1 RP |
103 | |
104 | /* This protects the 'ops' field. If 'ops' is NULL, the driver that | |
105 | registered this device has been unloaded, and if class_get_devdata() | |
106 | points to something in the body of that driver, it is also invalid. */ | |
107 | struct mutex ops_lock; | |
9905a43b | 108 | const struct backlight_ops *ops; |
599a52d1 | 109 | |
1da177e4 LT |
110 | /* The framebuffer notifier block */ |
111 | struct notifier_block fb_notif; | |
655bfd7a | 112 | |
5915a3db AL |
113 | /* list entry of all registered backlight devices */ |
114 | struct list_head entry; | |
115 | ||
655bfd7a | 116 | struct device dev; |
a55944ca LY |
117 | |
118 | /* Multiple framebuffers may share one backlight device */ | |
119 | bool fb_bl_on[FB_MAX]; | |
120 | ||
121 | int use_count; | |
1da177e4 LT |
122 | }; |
123 | ||
cca0ba2d | 124 | static inline int backlight_update_status(struct backlight_device *bd) |
28ee086d | 125 | { |
cca0ba2d HH |
126 | int ret = -ENOENT; |
127 | ||
28ee086d | 128 | mutex_lock(&bd->update_lock); |
599a52d1 | 129 | if (bd->ops && bd->ops->update_status) |
cca0ba2d | 130 | ret = bd->ops->update_status(bd); |
28ee086d | 131 | mutex_unlock(&bd->update_lock); |
cca0ba2d HH |
132 | |
133 | return ret; | |
28ee086d RP |
134 | } |
135 | ||
5b698be0 MM |
136 | /** |
137 | * backlight_enable - Enable backlight | |
138 | * @bd: the backlight device to enable | |
139 | */ | |
140 | static inline int backlight_enable(struct backlight_device *bd) | |
141 | { | |
142 | if (!bd) | |
143 | return 0; | |
144 | ||
145 | bd->props.power = FB_BLANK_UNBLANK; | |
146 | bd->props.fb_blank = FB_BLANK_UNBLANK; | |
147 | bd->props.state &= ~BL_CORE_FBBLANK; | |
148 | ||
149 | return backlight_update_status(bd); | |
150 | } | |
151 | ||
152 | /** | |
153 | * backlight_disable - Disable backlight | |
154 | * @bd: the backlight device to disable | |
155 | */ | |
156 | static inline int backlight_disable(struct backlight_device *bd) | |
157 | { | |
158 | if (!bd) | |
159 | return 0; | |
160 | ||
161 | bd->props.power = FB_BLANK_POWERDOWN; | |
162 | bd->props.fb_blank = FB_BLANK_POWERDOWN; | |
163 | bd->props.state |= BL_CORE_FBBLANK; | |
164 | ||
165 | return backlight_update_status(bd); | |
166 | } | |
167 | ||
c2adda27 MM |
168 | /** |
169 | * backlight_put - Drop backlight reference | |
170 | * @bd: the backlight device to put | |
171 | */ | |
172 | static inline void backlight_put(struct backlight_device *bd) | |
173 | { | |
174 | if (bd) | |
175 | put_device(&bd->dev); | |
176 | } | |
177 | ||
1da177e4 | 178 | extern struct backlight_device *backlight_device_register(const char *name, |
a19a6ee6 MG |
179 | struct device *dev, void *devdata, const struct backlight_ops *ops, |
180 | const struct backlight_properties *props); | |
8318fde4 JH |
181 | extern struct backlight_device *devm_backlight_device_register( |
182 | struct device *dev, const char *name, struct device *parent, | |
183 | void *devdata, const struct backlight_ops *ops, | |
184 | const struct backlight_properties *props); | |
1da177e4 | 185 | extern void backlight_device_unregister(struct backlight_device *bd); |
8318fde4 JH |
186 | extern void devm_backlight_device_unregister(struct device *dev, |
187 | struct backlight_device *bd); | |
325253a6 MG |
188 | extern void backlight_force_update(struct backlight_device *bd, |
189 | enum backlight_update_reason reason); | |
3cc6919b HG |
190 | extern int backlight_register_notifier(struct notifier_block *nb); |
191 | extern int backlight_unregister_notifier(struct notifier_block *nb); | |
f6a4790a AL |
192 | extern struct backlight_device *backlight_device_get_by_type(enum backlight_type type); |
193 | extern int backlight_device_set_brightness(struct backlight_device *bd, unsigned long brightness); | |
1da177e4 | 194 | |
655bfd7a RP |
195 | #define to_backlight_device(obj) container_of(obj, struct backlight_device, dev) |
196 | ||
197 | static inline void * bl_get_data(struct backlight_device *bl_dev) | |
198 | { | |
199 | return dev_get_drvdata(&bl_dev->dev); | |
200 | } | |
1da177e4 | 201 | |
c3f8f650 RP |
202 | struct generic_bl_info { |
203 | const char *name; | |
204 | int max_intensity; | |
205 | int default_intensity; | |
206 | int limit_mask; | |
207 | void (*set_bl_intensity)(int intensity); | |
208 | void (*kick_battery)(void); | |
209 | }; | |
210 | ||
762a936f TR |
211 | #ifdef CONFIG_OF |
212 | struct backlight_device *of_find_backlight_by_node(struct device_node *node); | |
213 | #else | |
214 | static inline struct backlight_device * | |
215 | of_find_backlight_by_node(struct device_node *node) | |
216 | { | |
217 | return NULL; | |
218 | } | |
219 | #endif | |
220 | ||
c2adda27 MM |
221 | #if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE) |
222 | struct backlight_device *of_find_backlight(struct device *dev); | |
2e4ef334 | 223 | struct backlight_device *devm_of_find_backlight(struct device *dev); |
c2adda27 MM |
224 | #else |
225 | static inline struct backlight_device *of_find_backlight(struct device *dev) | |
226 | { | |
227 | return NULL; | |
228 | } | |
2e4ef334 MM |
229 | |
230 | static inline struct backlight_device * | |
231 | devm_of_find_backlight(struct device *dev) | |
232 | { | |
233 | return NULL; | |
234 | } | |
c2adda27 MM |
235 | #endif |
236 | ||
1da177e4 | 237 | #endif |