xref: /freebsd/sys/compat/linuxkpi/common/include/linux/backlight.h (revision 2b68c973378d3ffeff501ca8c9db5bd21a2283ea)
1*2b68c973SEmmanuel Vadot /*-
2*2b68c973SEmmanuel Vadot  * Copyright (c) 2020 The FreeBSD Foundation
3*2b68c973SEmmanuel Vadot  *
4*2b68c973SEmmanuel Vadot  * This software was developed by Emmanuel Vadot under sponsorship
5*2b68c973SEmmanuel Vadot  * from the FreeBSD Foundation.
6*2b68c973SEmmanuel Vadot  *
7*2b68c973SEmmanuel Vadot  * Redistribution and use in source and binary forms, with or without
8*2b68c973SEmmanuel Vadot  * modification, are permitted provided that the following conditions
9*2b68c973SEmmanuel Vadot  * are met:
10*2b68c973SEmmanuel Vadot  * 1. Redistributions of source code must retain the above copyright
11*2b68c973SEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer.
12*2b68c973SEmmanuel Vadot  * 2. Redistributions in binary form must reproduce the above copyright
13*2b68c973SEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer in the
14*2b68c973SEmmanuel Vadot  *    documentation and/or other materials provided with the distribution.
15*2b68c973SEmmanuel Vadot  *
16*2b68c973SEmmanuel Vadot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17*2b68c973SEmmanuel Vadot  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18*2b68c973SEmmanuel Vadot  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19*2b68c973SEmmanuel Vadot  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20*2b68c973SEmmanuel Vadot  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21*2b68c973SEmmanuel Vadot  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22*2b68c973SEmmanuel Vadot  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23*2b68c973SEmmanuel Vadot  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24*2b68c973SEmmanuel Vadot  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25*2b68c973SEmmanuel Vadot  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26*2b68c973SEmmanuel Vadot  * SUCH DAMAGE.
27*2b68c973SEmmanuel Vadot  *
28*2b68c973SEmmanuel Vadot  * $FreeBSD$
29*2b68c973SEmmanuel Vadot  */
30*2b68c973SEmmanuel Vadot 
31*2b68c973SEmmanuel Vadot #ifndef _LINUX_BACKLIGHT_H_
32*2b68c973SEmmanuel Vadot #define _LINUX_BACKLIGHT_H_
33*2b68c973SEmmanuel Vadot 
34*2b68c973SEmmanuel Vadot #include <linux/notifier.h>
35*2b68c973SEmmanuel Vadot 
36*2b68c973SEmmanuel Vadot struct backlight_device;
37*2b68c973SEmmanuel Vadot 
38*2b68c973SEmmanuel Vadot enum backlight_type {
39*2b68c973SEmmanuel Vadot 	BACKLIGHT_RAW = 0,
40*2b68c973SEmmanuel Vadot };
41*2b68c973SEmmanuel Vadot 
42*2b68c973SEmmanuel Vadot struct backlight_properties {
43*2b68c973SEmmanuel Vadot 	int type;
44*2b68c973SEmmanuel Vadot 	int max_brightness;
45*2b68c973SEmmanuel Vadot 	int brightness;
46*2b68c973SEmmanuel Vadot 	int power;
47*2b68c973SEmmanuel Vadot };
48*2b68c973SEmmanuel Vadot 
49*2b68c973SEmmanuel Vadot enum backlight_notification {
50*2b68c973SEmmanuel Vadot 	BACKLIGHT_REGISTERED,
51*2b68c973SEmmanuel Vadot 	BACKLIGHT_UNREGISTERED,
52*2b68c973SEmmanuel Vadot };
53*2b68c973SEmmanuel Vadot 
54*2b68c973SEmmanuel Vadot enum backlight_update_reason {
55*2b68c973SEmmanuel Vadot 	BACKLIGHT_UPDATE_HOTKEY = 0
56*2b68c973SEmmanuel Vadot };
57*2b68c973SEmmanuel Vadot 
58*2b68c973SEmmanuel Vadot struct backlight_ops {
59*2b68c973SEmmanuel Vadot 	int options;
60*2b68c973SEmmanuel Vadot #define	BL_CORE_SUSPENDRESUME   1
61*2b68c973SEmmanuel Vadot 	int (*update_status)(struct backlight_device *);
62*2b68c973SEmmanuel Vadot 	int (*get_brightness)(struct backlight_device *);
63*2b68c973SEmmanuel Vadot };
64*2b68c973SEmmanuel Vadot 
65*2b68c973SEmmanuel Vadot struct backlight_device {
66*2b68c973SEmmanuel Vadot 	const struct backlight_ops *ops;
67*2b68c973SEmmanuel Vadot 	struct backlight_properties props;
68*2b68c973SEmmanuel Vadot 	void *data;
69*2b68c973SEmmanuel Vadot 	struct device *dev;
70*2b68c973SEmmanuel Vadot 	char *name;
71*2b68c973SEmmanuel Vadot };
72*2b68c973SEmmanuel Vadot 
73*2b68c973SEmmanuel Vadot #define bl_get_data(bd) (bd)->data
74*2b68c973SEmmanuel Vadot 
75*2b68c973SEmmanuel Vadot struct backlight_device *linux_backlight_device_register(const char *name,
76*2b68c973SEmmanuel Vadot     struct device *dev, void *data, const struct backlight_ops *ops, struct backlight_properties *props);
77*2b68c973SEmmanuel Vadot void linux_backlight_device_unregister(struct backlight_device *bd);
78*2b68c973SEmmanuel Vadot #define	backlight_device_register(name, dev, data, ops, props)	\
79*2b68c973SEmmanuel Vadot 	linux_backlight_device_register(name, dev, data, ops, props)
80*2b68c973SEmmanuel Vadot #define	backlight_device_unregister(bd)	linux_backlight_device_unregister(bd)
81*2b68c973SEmmanuel Vadot 
82*2b68c973SEmmanuel Vadot static inline void
83*2b68c973SEmmanuel Vadot backlight_update_status(struct backlight_device *bd)
84*2b68c973SEmmanuel Vadot {
85*2b68c973SEmmanuel Vadot 	bd->ops->update_status(bd);
86*2b68c973SEmmanuel Vadot }
87*2b68c973SEmmanuel Vadot 
88*2b68c973SEmmanuel Vadot static inline void
89*2b68c973SEmmanuel Vadot backlight_force_update(struct backlight_device *bd, int reason)
90*2b68c973SEmmanuel Vadot {
91*2b68c973SEmmanuel Vadot 	bd->props.brightness = bd->ops->get_brightness(bd);
92*2b68c973SEmmanuel Vadot }
93*2b68c973SEmmanuel Vadot 
94*2b68c973SEmmanuel Vadot #endif	/* _LINUX_BACKLIGHT_H_ */
95