xref: /OK3568_Linux_fs/kernel/include/linux/backlight.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Backlight Lowlevel Control Abstraction
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (C) 2003,2004 Hewlett-Packard Company
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  */
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #ifndef _LINUX_BACKLIGHT_H
10*4882a593Smuzhiyun #define _LINUX_BACKLIGHT_H
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun #include <linux/device.h>
13*4882a593Smuzhiyun #include <linux/fb.h>
14*4882a593Smuzhiyun #include <linux/mutex.h>
15*4882a593Smuzhiyun #include <linux/notifier.h>
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun /**
18*4882a593Smuzhiyun  * enum backlight_update_reason - what method was used to update backlight
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  * A driver indicates the method (reason) used for updating the backlight
21*4882a593Smuzhiyun  * when calling backlight_force_update().
22*4882a593Smuzhiyun  */
23*4882a593Smuzhiyun enum backlight_update_reason {
24*4882a593Smuzhiyun 	/**
25*4882a593Smuzhiyun 	 * @BACKLIGHT_UPDATE_HOTKEY: The backlight was updated using a hot-key.
26*4882a593Smuzhiyun 	 */
27*4882a593Smuzhiyun 	BACKLIGHT_UPDATE_HOTKEY,
28*4882a593Smuzhiyun 
29*4882a593Smuzhiyun 	/**
30*4882a593Smuzhiyun 	 * @BACKLIGHT_UPDATE_SYSFS: The backlight was updated using sysfs.
31*4882a593Smuzhiyun 	 */
32*4882a593Smuzhiyun 	BACKLIGHT_UPDATE_SYSFS,
33*4882a593Smuzhiyun };
34*4882a593Smuzhiyun 
35*4882a593Smuzhiyun /**
36*4882a593Smuzhiyun  * enum backlight_type - the type of backlight control
37*4882a593Smuzhiyun  *
38*4882a593Smuzhiyun  * The type of interface used to control the backlight.
39*4882a593Smuzhiyun  */
40*4882a593Smuzhiyun enum backlight_type {
41*4882a593Smuzhiyun 	/**
42*4882a593Smuzhiyun 	 * @BACKLIGHT_RAW:
43*4882a593Smuzhiyun 	 *
44*4882a593Smuzhiyun 	 * The backlight is controlled using hardware registers.
45*4882a593Smuzhiyun 	 */
46*4882a593Smuzhiyun 	BACKLIGHT_RAW = 1,
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun 	/**
49*4882a593Smuzhiyun 	 * @BACKLIGHT_PLATFORM:
50*4882a593Smuzhiyun 	 *
51*4882a593Smuzhiyun 	 * The backlight is controlled using a platform-specific interface.
52*4882a593Smuzhiyun 	 */
53*4882a593Smuzhiyun 	BACKLIGHT_PLATFORM,
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun 	/**
56*4882a593Smuzhiyun 	 * @BACKLIGHT_FIRMWARE:
57*4882a593Smuzhiyun 	 *
58*4882a593Smuzhiyun 	 * The backlight is controlled using a standard firmware interface.
59*4882a593Smuzhiyun 	 */
60*4882a593Smuzhiyun 	BACKLIGHT_FIRMWARE,
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun 	/**
63*4882a593Smuzhiyun 	 * @BACKLIGHT_TYPE_MAX: Number of entries.
64*4882a593Smuzhiyun 	 */
65*4882a593Smuzhiyun 	BACKLIGHT_TYPE_MAX,
66*4882a593Smuzhiyun };
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun /**
69*4882a593Smuzhiyun  * enum backlight_notification - the type of notification
70*4882a593Smuzhiyun  *
71*4882a593Smuzhiyun  * The notifications that is used for notification sent to the receiver
72*4882a593Smuzhiyun  * that registered notifications using backlight_register_notifier().
73*4882a593Smuzhiyun  */
74*4882a593Smuzhiyun enum backlight_notification {
75*4882a593Smuzhiyun 	/**
76*4882a593Smuzhiyun 	 * @BACKLIGHT_REGISTERED: The backlight device is registered.
77*4882a593Smuzhiyun 	 */
78*4882a593Smuzhiyun 	BACKLIGHT_REGISTERED,
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun 	/**
81*4882a593Smuzhiyun 	 * @BACKLIGHT_UNREGISTERED: The backlight revice is unregistered.
82*4882a593Smuzhiyun 	 */
83*4882a593Smuzhiyun 	BACKLIGHT_UNREGISTERED,
84*4882a593Smuzhiyun };
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun /** enum backlight_scale - the type of scale used for brightness values
87*4882a593Smuzhiyun  *
88*4882a593Smuzhiyun  * The type of scale used for brightness values.
89*4882a593Smuzhiyun  */
90*4882a593Smuzhiyun enum backlight_scale {
91*4882a593Smuzhiyun 	/**
92*4882a593Smuzhiyun 	 * @BACKLIGHT_SCALE_UNKNOWN: The scale is unknown.
93*4882a593Smuzhiyun 	 */
94*4882a593Smuzhiyun 	BACKLIGHT_SCALE_UNKNOWN = 0,
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun 	/**
97*4882a593Smuzhiyun 	 * @BACKLIGHT_SCALE_LINEAR: The scale is linear.
98*4882a593Smuzhiyun 	 *
99*4882a593Smuzhiyun 	 * The linear scale will increase brightness the same for each step.
100*4882a593Smuzhiyun 	 */
101*4882a593Smuzhiyun 	BACKLIGHT_SCALE_LINEAR,
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun 	/**
104*4882a593Smuzhiyun 	 * @BACKLIGHT_SCALE_NON_LINEAR: The scale is not linear.
105*4882a593Smuzhiyun 	 *
106*4882a593Smuzhiyun 	 * This is often used when the brightness values tries to adjust to
107*4882a593Smuzhiyun 	 * the relative perception of the eye demanding a non-linear scale.
108*4882a593Smuzhiyun 	 */
109*4882a593Smuzhiyun 	BACKLIGHT_SCALE_NON_LINEAR,
110*4882a593Smuzhiyun };
111*4882a593Smuzhiyun 
112*4882a593Smuzhiyun struct backlight_device;
113*4882a593Smuzhiyun struct fb_info;
114*4882a593Smuzhiyun 
115*4882a593Smuzhiyun /**
116*4882a593Smuzhiyun  * struct backlight_ops - backlight operations
117*4882a593Smuzhiyun  *
118*4882a593Smuzhiyun  * The backlight operations are specified when the backlight device is registered.
119*4882a593Smuzhiyun  */
120*4882a593Smuzhiyun struct backlight_ops {
121*4882a593Smuzhiyun 	/**
122*4882a593Smuzhiyun 	 * @options: Configure how operations are called from the core.
123*4882a593Smuzhiyun 	 *
124*4882a593Smuzhiyun 	 * The options parameter is used to adjust the behaviour of the core.
125*4882a593Smuzhiyun 	 * Set BL_CORE_SUSPENDRESUME to get the update_status() operation called
126*4882a593Smuzhiyun 	 * upon suspend and resume.
127*4882a593Smuzhiyun 	 */
128*4882a593Smuzhiyun 	unsigned int options;
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun #define BL_CORE_SUSPENDRESUME	(1 << 0)
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun 	/**
133*4882a593Smuzhiyun 	 * @update_status: Operation called when properties have changed.
134*4882a593Smuzhiyun 	 *
135*4882a593Smuzhiyun 	 * Notify the backlight driver some property has changed.
136*4882a593Smuzhiyun 	 * The update_status operation is protected by the update_lock.
137*4882a593Smuzhiyun 	 *
138*4882a593Smuzhiyun 	 * The backlight driver is expected to use backlight_is_blank()
139*4882a593Smuzhiyun 	 * to check if the display is blanked and set brightness accordingly.
140*4882a593Smuzhiyun 	 * update_status() is called when any of the properties has changed.
141*4882a593Smuzhiyun 	 *
142*4882a593Smuzhiyun 	 * RETURNS:
143*4882a593Smuzhiyun 	 *
144*4882a593Smuzhiyun 	 * 0 on success, negative error code if any failure occurred.
145*4882a593Smuzhiyun 	 */
146*4882a593Smuzhiyun 	int (*update_status)(struct backlight_device *);
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun 	/**
149*4882a593Smuzhiyun 	 * @get_brightness: Return the current backlight brightness.
150*4882a593Smuzhiyun 	 *
151*4882a593Smuzhiyun 	 * The driver may implement this as a readback from the HW.
152*4882a593Smuzhiyun 	 * This operation is optional and if not present then the current
153*4882a593Smuzhiyun 	 * brightness property value is used.
154*4882a593Smuzhiyun 	 *
155*4882a593Smuzhiyun 	 * RETURNS:
156*4882a593Smuzhiyun 	 *
157*4882a593Smuzhiyun 	 * A brightness value which is 0 or a positive number.
158*4882a593Smuzhiyun 	 * On failure a negative error code is returned.
159*4882a593Smuzhiyun 	 */
160*4882a593Smuzhiyun 	int (*get_brightness)(struct backlight_device *);
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun 	/**
163*4882a593Smuzhiyun 	 * @check_fb: Check the framebuffer device.
164*4882a593Smuzhiyun 	 *
165*4882a593Smuzhiyun 	 * Check if given framebuffer device is the one bound to this backlight.
166*4882a593Smuzhiyun 	 * This operation is optional and if not implemented it is assumed that the
167*4882a593Smuzhiyun 	 * fbdev is always the one bound to the backlight.
168*4882a593Smuzhiyun 	 *
169*4882a593Smuzhiyun 	 * RETURNS:
170*4882a593Smuzhiyun 	 *
171*4882a593Smuzhiyun 	 * If info is NULL or the info matches the fbdev bound to the backlight return true.
172*4882a593Smuzhiyun 	 * If info does not match the fbdev bound to the backlight return false.
173*4882a593Smuzhiyun 	 */
174*4882a593Smuzhiyun 	int (*check_fb)(struct backlight_device *bd, struct fb_info *info);
175*4882a593Smuzhiyun };
176*4882a593Smuzhiyun 
177*4882a593Smuzhiyun /**
178*4882a593Smuzhiyun  * struct backlight_properties - backlight properties
179*4882a593Smuzhiyun  *
180*4882a593Smuzhiyun  * This structure defines all the properties of a backlight.
181*4882a593Smuzhiyun  */
182*4882a593Smuzhiyun struct backlight_properties {
183*4882a593Smuzhiyun 	/**
184*4882a593Smuzhiyun 	 * @brightness: The current brightness requested by the user.
185*4882a593Smuzhiyun 	 *
186*4882a593Smuzhiyun 	 * The backlight core makes sure the range is (0 to max_brightness)
187*4882a593Smuzhiyun 	 * when the brightness is set via the sysfs attribute:
188*4882a593Smuzhiyun 	 * /sys/class/backlight/<backlight>/brightness.
189*4882a593Smuzhiyun 	 *
190*4882a593Smuzhiyun 	 * This value can be set in the backlight_properties passed
191*4882a593Smuzhiyun 	 * to devm_backlight_device_register() to set a default brightness
192*4882a593Smuzhiyun 	 * value.
193*4882a593Smuzhiyun 	 */
194*4882a593Smuzhiyun 	int brightness;
195*4882a593Smuzhiyun 
196*4882a593Smuzhiyun 	/**
197*4882a593Smuzhiyun 	 * @max_brightness: The maximum brightness value.
198*4882a593Smuzhiyun 	 *
199*4882a593Smuzhiyun 	 * This value must be set in the backlight_properties passed to
200*4882a593Smuzhiyun 	 * devm_backlight_device_register() and shall not be modified by the
201*4882a593Smuzhiyun 	 * driver after registration.
202*4882a593Smuzhiyun 	 */
203*4882a593Smuzhiyun 	int max_brightness;
204*4882a593Smuzhiyun 
205*4882a593Smuzhiyun 	/**
206*4882a593Smuzhiyun 	 * @power: The current power mode.
207*4882a593Smuzhiyun 	 *
208*4882a593Smuzhiyun 	 * User space can configure the power mode using the sysfs
209*4882a593Smuzhiyun 	 * attribute: /sys/class/backlight/<backlight>/bl_power
210*4882a593Smuzhiyun 	 * When the power property is updated update_status() is called.
211*4882a593Smuzhiyun 	 *
212*4882a593Smuzhiyun 	 * The possible values are: (0: full on, 1 to 3: power saving
213*4882a593Smuzhiyun 	 * modes; 4: full off), see FB_BLANK_XXX.
214*4882a593Smuzhiyun 	 *
215*4882a593Smuzhiyun 	 * When the backlight device is enabled @power is set
216*4882a593Smuzhiyun 	 * to FB_BLANK_UNBLANK. When the backlight device is disabled
217*4882a593Smuzhiyun 	 * @power is set to FB_BLANK_POWERDOWN.
218*4882a593Smuzhiyun 	 */
219*4882a593Smuzhiyun 	int power;
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun 	/**
222*4882a593Smuzhiyun 	 * @fb_blank: The power state from the FBIOBLANK ioctl.
223*4882a593Smuzhiyun 	 *
224*4882a593Smuzhiyun 	 * When the FBIOBLANK ioctl is called @fb_blank is set to the
225*4882a593Smuzhiyun 	 * blank parameter and the update_status() operation is called.
226*4882a593Smuzhiyun 	 *
227*4882a593Smuzhiyun 	 * When the backlight device is enabled @fb_blank is set
228*4882a593Smuzhiyun 	 * to FB_BLANK_UNBLANK. When the backlight device is disabled
229*4882a593Smuzhiyun 	 * @fb_blank is set to FB_BLANK_POWERDOWN.
230*4882a593Smuzhiyun 	 *
231*4882a593Smuzhiyun 	 * Backlight drivers should avoid using this property. It has been
232*4882a593Smuzhiyun 	 * replaced by state & BL_CORE_FBLANK (although most drivers should
233*4882a593Smuzhiyun 	 * use backlight_is_blank() as the preferred means to get the blank
234*4882a593Smuzhiyun 	 * state).
235*4882a593Smuzhiyun 	 *
236*4882a593Smuzhiyun 	 * fb_blank is deprecated and will be removed.
237*4882a593Smuzhiyun 	 */
238*4882a593Smuzhiyun 	int fb_blank;
239*4882a593Smuzhiyun 
240*4882a593Smuzhiyun 	/**
241*4882a593Smuzhiyun 	 * @type: The type of backlight supported.
242*4882a593Smuzhiyun 	 *
243*4882a593Smuzhiyun 	 * The backlight type allows userspace to make appropriate
244*4882a593Smuzhiyun 	 * policy decisions based on the backlight type.
245*4882a593Smuzhiyun 	 *
246*4882a593Smuzhiyun 	 * This value must be set in the backlight_properties
247*4882a593Smuzhiyun 	 * passed to devm_backlight_device_register().
248*4882a593Smuzhiyun 	 */
249*4882a593Smuzhiyun 	enum backlight_type type;
250*4882a593Smuzhiyun 
251*4882a593Smuzhiyun 	/**
252*4882a593Smuzhiyun 	 * @state: The state of the backlight core.
253*4882a593Smuzhiyun 	 *
254*4882a593Smuzhiyun 	 * The state is a bitmask. BL_CORE_FBBLANK is set when the display
255*4882a593Smuzhiyun 	 * is expected to be blank. BL_CORE_SUSPENDED is set when the
256*4882a593Smuzhiyun 	 * driver is suspended.
257*4882a593Smuzhiyun 	 *
258*4882a593Smuzhiyun 	 * backlight drivers are expected to use backlight_is_blank()
259*4882a593Smuzhiyun 	 * in their update_status() operation rather than reading the
260*4882a593Smuzhiyun 	 * state property.
261*4882a593Smuzhiyun 	 *
262*4882a593Smuzhiyun 	 * The state is maintained by the core and drivers may not modify it.
263*4882a593Smuzhiyun 	 */
264*4882a593Smuzhiyun 	unsigned int state;
265*4882a593Smuzhiyun 
266*4882a593Smuzhiyun #define BL_CORE_SUSPENDED	(1 << 0)	/* backlight is suspended */
267*4882a593Smuzhiyun #define BL_CORE_FBBLANK		(1 << 1)	/* backlight is under an fb blank event */
268*4882a593Smuzhiyun 
269*4882a593Smuzhiyun 	/**
270*4882a593Smuzhiyun 	 * @scale: The type of the brightness scale.
271*4882a593Smuzhiyun 	 */
272*4882a593Smuzhiyun 	enum backlight_scale scale;
273*4882a593Smuzhiyun };
274*4882a593Smuzhiyun 
275*4882a593Smuzhiyun /**
276*4882a593Smuzhiyun  * struct backlight_device - backlight device data
277*4882a593Smuzhiyun  *
278*4882a593Smuzhiyun  * This structure holds all data required by a backlight device.
279*4882a593Smuzhiyun  */
280*4882a593Smuzhiyun struct backlight_device {
281*4882a593Smuzhiyun 	/**
282*4882a593Smuzhiyun 	 * @props: Backlight properties
283*4882a593Smuzhiyun 	 */
284*4882a593Smuzhiyun 	struct backlight_properties props;
285*4882a593Smuzhiyun 
286*4882a593Smuzhiyun 	/**
287*4882a593Smuzhiyun 	 * @update_lock: The lock used when calling the update_status() operation.
288*4882a593Smuzhiyun 	 *
289*4882a593Smuzhiyun 	 * update_lock is an internal backlight lock that serialise access
290*4882a593Smuzhiyun 	 * to the update_status() operation. The backlight core holds the update_lock
291*4882a593Smuzhiyun 	 * when calling the update_status() operation. The update_lock shall not
292*4882a593Smuzhiyun 	 * be used by backlight drivers.
293*4882a593Smuzhiyun 	 */
294*4882a593Smuzhiyun 	struct mutex update_lock;
295*4882a593Smuzhiyun 
296*4882a593Smuzhiyun 	/**
297*4882a593Smuzhiyun 	 * @ops_lock: The lock used around everything related to backlight_ops.
298*4882a593Smuzhiyun 	 *
299*4882a593Smuzhiyun 	 * ops_lock is an internal backlight lock that protects the ops pointer
300*4882a593Smuzhiyun 	 * and is used around all accesses to ops and when the operations are
301*4882a593Smuzhiyun 	 * invoked. The ops_lock shall not be used by backlight drivers.
302*4882a593Smuzhiyun 	 */
303*4882a593Smuzhiyun 	struct mutex ops_lock;
304*4882a593Smuzhiyun 
305*4882a593Smuzhiyun 	/**
306*4882a593Smuzhiyun 	 * @ops: Pointer to the backlight operations.
307*4882a593Smuzhiyun 	 *
308*4882a593Smuzhiyun 	 * If ops is NULL, the driver that registered this device has been unloaded,
309*4882a593Smuzhiyun 	 * and if class_get_devdata() points to something in the body of that driver,
310*4882a593Smuzhiyun 	 * it is also invalid.
311*4882a593Smuzhiyun 	 */
312*4882a593Smuzhiyun 	const struct backlight_ops *ops;
313*4882a593Smuzhiyun 
314*4882a593Smuzhiyun 	/**
315*4882a593Smuzhiyun 	 * @fb_notif: The framebuffer notifier block
316*4882a593Smuzhiyun 	 */
317*4882a593Smuzhiyun 	struct notifier_block fb_notif;
318*4882a593Smuzhiyun 
319*4882a593Smuzhiyun 	/**
320*4882a593Smuzhiyun 	 * @entry: List entry of all registered backlight devices
321*4882a593Smuzhiyun 	 */
322*4882a593Smuzhiyun 	struct list_head entry;
323*4882a593Smuzhiyun 
324*4882a593Smuzhiyun 	/**
325*4882a593Smuzhiyun 	 * @dev: Parent device.
326*4882a593Smuzhiyun 	 */
327*4882a593Smuzhiyun 	struct device dev;
328*4882a593Smuzhiyun 
329*4882a593Smuzhiyun 	/**
330*4882a593Smuzhiyun 	 * @fb_bl_on: The state of individual fbdev's.
331*4882a593Smuzhiyun 	 *
332*4882a593Smuzhiyun 	 * Multiple fbdev's may share one backlight device. The fb_bl_on
333*4882a593Smuzhiyun 	 * records the state of the individual fbdev.
334*4882a593Smuzhiyun 	 */
335*4882a593Smuzhiyun 	bool fb_bl_on[FB_MAX];
336*4882a593Smuzhiyun 
337*4882a593Smuzhiyun 	/**
338*4882a593Smuzhiyun 	 * @use_count: The number of uses of fb_bl_on.
339*4882a593Smuzhiyun 	 */
340*4882a593Smuzhiyun 	int use_count;
341*4882a593Smuzhiyun };
342*4882a593Smuzhiyun 
343*4882a593Smuzhiyun /**
344*4882a593Smuzhiyun  * backlight_update_status - force an update of the backlight device status
345*4882a593Smuzhiyun  * @bd: the backlight device
346*4882a593Smuzhiyun  */
backlight_update_status(struct backlight_device * bd)347*4882a593Smuzhiyun static inline int backlight_update_status(struct backlight_device *bd)
348*4882a593Smuzhiyun {
349*4882a593Smuzhiyun 	int ret = -ENOENT;
350*4882a593Smuzhiyun 
351*4882a593Smuzhiyun 	mutex_lock(&bd->update_lock);
352*4882a593Smuzhiyun 	if (bd->ops && bd->ops->update_status)
353*4882a593Smuzhiyun 		ret = bd->ops->update_status(bd);
354*4882a593Smuzhiyun 	mutex_unlock(&bd->update_lock);
355*4882a593Smuzhiyun 
356*4882a593Smuzhiyun 	return ret;
357*4882a593Smuzhiyun }
358*4882a593Smuzhiyun 
359*4882a593Smuzhiyun /**
360*4882a593Smuzhiyun  * backlight_enable - Enable backlight
361*4882a593Smuzhiyun  * @bd: the backlight device to enable
362*4882a593Smuzhiyun  */
backlight_enable(struct backlight_device * bd)363*4882a593Smuzhiyun static inline int backlight_enable(struct backlight_device *bd)
364*4882a593Smuzhiyun {
365*4882a593Smuzhiyun 	if (!bd)
366*4882a593Smuzhiyun 		return 0;
367*4882a593Smuzhiyun 
368*4882a593Smuzhiyun 	bd->props.power = FB_BLANK_UNBLANK;
369*4882a593Smuzhiyun 	bd->props.fb_blank = FB_BLANK_UNBLANK;
370*4882a593Smuzhiyun 	bd->props.state &= ~BL_CORE_FBBLANK;
371*4882a593Smuzhiyun 
372*4882a593Smuzhiyun 	return backlight_update_status(bd);
373*4882a593Smuzhiyun }
374*4882a593Smuzhiyun 
375*4882a593Smuzhiyun /**
376*4882a593Smuzhiyun  * backlight_disable - Disable backlight
377*4882a593Smuzhiyun  * @bd: the backlight device to disable
378*4882a593Smuzhiyun  */
backlight_disable(struct backlight_device * bd)379*4882a593Smuzhiyun static inline int backlight_disable(struct backlight_device *bd)
380*4882a593Smuzhiyun {
381*4882a593Smuzhiyun 	if (!bd)
382*4882a593Smuzhiyun 		return 0;
383*4882a593Smuzhiyun 
384*4882a593Smuzhiyun 	bd->props.power = FB_BLANK_POWERDOWN;
385*4882a593Smuzhiyun 	bd->props.fb_blank = FB_BLANK_POWERDOWN;
386*4882a593Smuzhiyun 	bd->props.state |= BL_CORE_FBBLANK;
387*4882a593Smuzhiyun 
388*4882a593Smuzhiyun 	return backlight_update_status(bd);
389*4882a593Smuzhiyun }
390*4882a593Smuzhiyun 
391*4882a593Smuzhiyun /**
392*4882a593Smuzhiyun  * backlight_is_blank - Return true if display is expected to be blank
393*4882a593Smuzhiyun  * @bd: the backlight device
394*4882a593Smuzhiyun  *
395*4882a593Smuzhiyun  * Display is expected to be blank if any of these is true::
396*4882a593Smuzhiyun  *
397*4882a593Smuzhiyun  *   1) if power in not UNBLANK
398*4882a593Smuzhiyun  *   2) if fb_blank is not UNBLANK
399*4882a593Smuzhiyun  *   3) if state indicate BLANK or SUSPENDED
400*4882a593Smuzhiyun  *
401*4882a593Smuzhiyun  * Returns true if display is expected to be blank, false otherwise.
402*4882a593Smuzhiyun  */
backlight_is_blank(const struct backlight_device * bd)403*4882a593Smuzhiyun static inline bool backlight_is_blank(const struct backlight_device *bd)
404*4882a593Smuzhiyun {
405*4882a593Smuzhiyun 	return bd->props.power != FB_BLANK_UNBLANK ||
406*4882a593Smuzhiyun 	       bd->props.fb_blank != FB_BLANK_UNBLANK ||
407*4882a593Smuzhiyun 	       bd->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK);
408*4882a593Smuzhiyun }
409*4882a593Smuzhiyun 
410*4882a593Smuzhiyun /**
411*4882a593Smuzhiyun  * backlight_get_brightness - Returns the current brightness value
412*4882a593Smuzhiyun  * @bd: the backlight device
413*4882a593Smuzhiyun  *
414*4882a593Smuzhiyun  * Returns the current brightness value, taking in consideration the current
415*4882a593Smuzhiyun  * state. If backlight_is_blank() returns true then return 0 as brightness
416*4882a593Smuzhiyun  * otherwise return the current brightness property value.
417*4882a593Smuzhiyun  *
418*4882a593Smuzhiyun  * Backlight drivers are expected to use this function in their update_status()
419*4882a593Smuzhiyun  * operation to get the brightness value.
420*4882a593Smuzhiyun  */
backlight_get_brightness(const struct backlight_device * bd)421*4882a593Smuzhiyun static inline int backlight_get_brightness(const struct backlight_device *bd)
422*4882a593Smuzhiyun {
423*4882a593Smuzhiyun 	if (backlight_is_blank(bd))
424*4882a593Smuzhiyun 		return 0;
425*4882a593Smuzhiyun 	else
426*4882a593Smuzhiyun 		return bd->props.brightness;
427*4882a593Smuzhiyun }
428*4882a593Smuzhiyun 
429*4882a593Smuzhiyun struct backlight_device *
430*4882a593Smuzhiyun backlight_device_register(const char *name, struct device *dev, void *devdata,
431*4882a593Smuzhiyun 			  const struct backlight_ops *ops,
432*4882a593Smuzhiyun 			  const struct backlight_properties *props);
433*4882a593Smuzhiyun struct backlight_device *
434*4882a593Smuzhiyun devm_backlight_device_register(struct device *dev, const char *name,
435*4882a593Smuzhiyun 			       struct device *parent, void *devdata,
436*4882a593Smuzhiyun 			       const struct backlight_ops *ops,
437*4882a593Smuzhiyun 			       const struct backlight_properties *props);
438*4882a593Smuzhiyun void backlight_device_unregister(struct backlight_device *bd);
439*4882a593Smuzhiyun void devm_backlight_device_unregister(struct device *dev,
440*4882a593Smuzhiyun 				      struct backlight_device *bd);
441*4882a593Smuzhiyun void backlight_force_update(struct backlight_device *bd,
442*4882a593Smuzhiyun 			    enum backlight_update_reason reason);
443*4882a593Smuzhiyun int backlight_register_notifier(struct notifier_block *nb);
444*4882a593Smuzhiyun int backlight_unregister_notifier(struct notifier_block *nb);
445*4882a593Smuzhiyun struct backlight_device *backlight_device_get_by_name(const char *name);
446*4882a593Smuzhiyun struct backlight_device *backlight_device_get_by_type(enum backlight_type type);
447*4882a593Smuzhiyun int backlight_device_set_brightness(struct backlight_device *bd,
448*4882a593Smuzhiyun 				    unsigned long brightness);
449*4882a593Smuzhiyun 
450*4882a593Smuzhiyun #define to_backlight_device(obj) container_of(obj, struct backlight_device, dev)
451*4882a593Smuzhiyun 
452*4882a593Smuzhiyun /**
453*4882a593Smuzhiyun  * bl_get_data - access devdata
454*4882a593Smuzhiyun  * @bl_dev: pointer to backlight device
455*4882a593Smuzhiyun  *
456*4882a593Smuzhiyun  * When a backlight device is registered the driver has the possibility
457*4882a593Smuzhiyun  * to supply a void * devdata. bl_get_data() return a pointer to the
458*4882a593Smuzhiyun  * devdata.
459*4882a593Smuzhiyun  *
460*4882a593Smuzhiyun  * RETURNS:
461*4882a593Smuzhiyun  *
462*4882a593Smuzhiyun  * pointer to devdata stored while registering the backlight device.
463*4882a593Smuzhiyun  */
bl_get_data(struct backlight_device * bl_dev)464*4882a593Smuzhiyun static inline void * bl_get_data(struct backlight_device *bl_dev)
465*4882a593Smuzhiyun {
466*4882a593Smuzhiyun 	return dev_get_drvdata(&bl_dev->dev);
467*4882a593Smuzhiyun }
468*4882a593Smuzhiyun 
469*4882a593Smuzhiyun #ifdef CONFIG_OF
470*4882a593Smuzhiyun struct backlight_device *of_find_backlight_by_node(struct device_node *node);
471*4882a593Smuzhiyun #else
472*4882a593Smuzhiyun static inline struct backlight_device *
of_find_backlight_by_node(struct device_node * node)473*4882a593Smuzhiyun of_find_backlight_by_node(struct device_node *node)
474*4882a593Smuzhiyun {
475*4882a593Smuzhiyun 	return NULL;
476*4882a593Smuzhiyun }
477*4882a593Smuzhiyun #endif
478*4882a593Smuzhiyun 
479*4882a593Smuzhiyun #if IS_ENABLED(CONFIG_BACKLIGHT_CLASS_DEVICE)
480*4882a593Smuzhiyun struct backlight_device *devm_of_find_backlight(struct device *dev);
481*4882a593Smuzhiyun #else
482*4882a593Smuzhiyun static inline struct backlight_device *
devm_of_find_backlight(struct device * dev)483*4882a593Smuzhiyun devm_of_find_backlight(struct device *dev)
484*4882a593Smuzhiyun {
485*4882a593Smuzhiyun 	return NULL;
486*4882a593Smuzhiyun }
487*4882a593Smuzhiyun #endif
488*4882a593Smuzhiyun 
489*4882a593Smuzhiyun #endif
490