xref: /freebsd/sys/compat/linuxkpi/common/include/linux/backlight.h (revision 2cc3af6e1d795c6d33afaf994c18abaab87a443b)
12b68c973SEmmanuel Vadot /*-
22b68c973SEmmanuel Vadot  * Copyright (c) 2020 The FreeBSD Foundation
32b68c973SEmmanuel Vadot  *
42b68c973SEmmanuel Vadot  * This software was developed by Emmanuel Vadot under sponsorship
52b68c973SEmmanuel Vadot  * from the FreeBSD Foundation.
62b68c973SEmmanuel Vadot  *
72b68c973SEmmanuel Vadot  * Redistribution and use in source and binary forms, with or without
82b68c973SEmmanuel Vadot  * modification, are permitted provided that the following conditions
92b68c973SEmmanuel Vadot  * are met:
102b68c973SEmmanuel Vadot  * 1. Redistributions of source code must retain the above copyright
112b68c973SEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer.
122b68c973SEmmanuel Vadot  * 2. Redistributions in binary form must reproduce the above copyright
132b68c973SEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer in the
142b68c973SEmmanuel Vadot  *    documentation and/or other materials provided with the distribution.
152b68c973SEmmanuel Vadot  *
162b68c973SEmmanuel Vadot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
172b68c973SEmmanuel Vadot  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
182b68c973SEmmanuel Vadot  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
192b68c973SEmmanuel Vadot  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
202b68c973SEmmanuel Vadot  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
212b68c973SEmmanuel Vadot  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
222b68c973SEmmanuel Vadot  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
232b68c973SEmmanuel Vadot  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
242b68c973SEmmanuel Vadot  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
252b68c973SEmmanuel Vadot  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
262b68c973SEmmanuel Vadot  * SUCH DAMAGE.
272b68c973SEmmanuel Vadot  *
282b68c973SEmmanuel Vadot  * $FreeBSD$
292b68c973SEmmanuel Vadot  */
302b68c973SEmmanuel Vadot 
31307f78f3SVladimir Kondratyev #ifndef _LINUXKPI_LINUX_BACKLIGHT_H_
32307f78f3SVladimir Kondratyev #define _LINUXKPI_LINUX_BACKLIGHT_H_
332b68c973SEmmanuel Vadot 
342b68c973SEmmanuel Vadot #include <linux/notifier.h>
352b68c973SEmmanuel Vadot 
362b68c973SEmmanuel Vadot struct backlight_device;
372b68c973SEmmanuel Vadot 
382b68c973SEmmanuel Vadot enum backlight_type {
392b68c973SEmmanuel Vadot 	BACKLIGHT_RAW = 0,
402b68c973SEmmanuel Vadot };
412b68c973SEmmanuel Vadot 
422b68c973SEmmanuel Vadot struct backlight_properties {
432b68c973SEmmanuel Vadot 	int type;
442b68c973SEmmanuel Vadot 	int max_brightness;
452b68c973SEmmanuel Vadot 	int brightness;
462b68c973SEmmanuel Vadot 	int power;
472b68c973SEmmanuel Vadot };
482b68c973SEmmanuel Vadot 
492b68c973SEmmanuel Vadot enum backlight_notification {
502b68c973SEmmanuel Vadot 	BACKLIGHT_REGISTERED,
512b68c973SEmmanuel Vadot 	BACKLIGHT_UNREGISTERED,
522b68c973SEmmanuel Vadot };
532b68c973SEmmanuel Vadot 
542b68c973SEmmanuel Vadot enum backlight_update_reason {
552b68c973SEmmanuel Vadot 	BACKLIGHT_UPDATE_HOTKEY = 0
562b68c973SEmmanuel Vadot };
572b68c973SEmmanuel Vadot 
582b68c973SEmmanuel Vadot struct backlight_ops {
592b68c973SEmmanuel Vadot 	int options;
602b68c973SEmmanuel Vadot #define	BL_CORE_SUSPENDRESUME   1
612b68c973SEmmanuel Vadot 	int (*update_status)(struct backlight_device *);
622b68c973SEmmanuel Vadot 	int (*get_brightness)(struct backlight_device *);
632b68c973SEmmanuel Vadot };
642b68c973SEmmanuel Vadot 
652b68c973SEmmanuel Vadot struct backlight_device {
662b68c973SEmmanuel Vadot 	const struct backlight_ops *ops;
672b68c973SEmmanuel Vadot 	struct backlight_properties props;
682b68c973SEmmanuel Vadot 	void *data;
692b68c973SEmmanuel Vadot 	struct device *dev;
702b68c973SEmmanuel Vadot 	char *name;
712b68c973SEmmanuel Vadot };
722b68c973SEmmanuel Vadot 
732b68c973SEmmanuel Vadot #define bl_get_data(bd) (bd)->data
742b68c973SEmmanuel Vadot 
752b68c973SEmmanuel Vadot struct backlight_device *linux_backlight_device_register(const char *name,
762b68c973SEmmanuel Vadot     struct device *dev, void *data, const struct backlight_ops *ops, struct backlight_properties *props);
772b68c973SEmmanuel Vadot void linux_backlight_device_unregister(struct backlight_device *bd);
782b68c973SEmmanuel Vadot #define	backlight_device_register(name, dev, data, ops, props)	\
792b68c973SEmmanuel Vadot 	linux_backlight_device_register(name, dev, data, ops, props)
802b68c973SEmmanuel Vadot #define	backlight_device_unregister(bd)	linux_backlight_device_unregister(bd)
812b68c973SEmmanuel Vadot 
82b52e3638SVladimir Kondratyev static inline int
832b68c973SEmmanuel Vadot backlight_update_status(struct backlight_device *bd)
842b68c973SEmmanuel Vadot {
85b52e3638SVladimir Kondratyev 	return (bd->ops->update_status(bd));
862b68c973SEmmanuel Vadot }
872b68c973SEmmanuel Vadot 
882b68c973SEmmanuel Vadot static inline void
892b68c973SEmmanuel Vadot backlight_force_update(struct backlight_device *bd, int reason)
902b68c973SEmmanuel Vadot {
912b68c973SEmmanuel Vadot 	bd->props.brightness = bd->ops->get_brightness(bd);
922b68c973SEmmanuel Vadot }
932b68c973SEmmanuel Vadot 
94b52e3638SVladimir Kondratyev static inline int
95*2cc3af6eSEmmanuel Vadot backlight_device_set_brightness(struct backlight_device *bd, int brightness)
96*2cc3af6eSEmmanuel Vadot {
97*2cc3af6eSEmmanuel Vadot 
98*2cc3af6eSEmmanuel Vadot 	if (brightness > bd->props.max_brightness)
99*2cc3af6eSEmmanuel Vadot 		return (EINVAL);
100*2cc3af6eSEmmanuel Vadot 	bd->props.brightness = brightness;
101*2cc3af6eSEmmanuel Vadot 	return (bd->ops->update_status(bd));
102*2cc3af6eSEmmanuel Vadot }
103*2cc3af6eSEmmanuel Vadot 
104*2cc3af6eSEmmanuel Vadot static inline int
105b52e3638SVladimir Kondratyev backlight_enable(struct backlight_device *bd)
106b52e3638SVladimir Kondratyev {
107b52e3638SVladimir Kondratyev 	if (bd == NULL)
108b52e3638SVladimir Kondratyev 		return (0);
109b52e3638SVladimir Kondratyev 	bd->props.power = 0/* FB_BLANK_UNBLANK */;
110b52e3638SVladimir Kondratyev 	return (backlight_update_status(bd));
111b52e3638SVladimir Kondratyev }
112b52e3638SVladimir Kondratyev 
113b52e3638SVladimir Kondratyev static inline int
114b52e3638SVladimir Kondratyev backlight_disable(struct backlight_device *bd)
115b52e3638SVladimir Kondratyev {
116b52e3638SVladimir Kondratyev 	if (bd == NULL)
117b52e3638SVladimir Kondratyev 		return (0);
118b52e3638SVladimir Kondratyev 	bd->props.power = 4/* FB_BLANK_POWERDOWN */;
119b52e3638SVladimir Kondratyev 	return (backlight_update_status(bd));
120b52e3638SVladimir Kondratyev }
121b52e3638SVladimir Kondratyev 
122307f78f3SVladimir Kondratyev #endif	/* _LINUXKPI_LINUX_BACKLIGHT_H_ */
123