Path: blob/main/sys/compat/linuxkpi/common/include/linux/backlight.h
39604 views
/*-1* Copyright (c) 2020 The FreeBSD Foundation2*3* This software was developed by Emmanuel Vadot under sponsorship4* from the FreeBSD Foundation.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#ifndef _LINUXKPI_LINUX_BACKLIGHT_H_29#define _LINUXKPI_LINUX_BACKLIGHT_H_3031#include <linux/notifier.h>3233struct backlight_device;3435enum backlight_type {36BACKLIGHT_RAW = 0,37};3839struct backlight_properties {40int type;41int max_brightness;42int brightness;43int power;44};4546enum backlight_notification {47BACKLIGHT_REGISTERED,48BACKLIGHT_UNREGISTERED,49};5051enum backlight_update_reason {52BACKLIGHT_UPDATE_HOTKEY = 053};5455struct backlight_ops {56int options;57#define BL_CORE_SUSPENDRESUME 158int (*update_status)(struct backlight_device *);59int (*get_brightness)(struct backlight_device *);60};6162struct backlight_device {63const struct backlight_ops *ops;64struct backlight_properties props;65void *data;66struct device *dev;67char *name;68};6970#define bl_get_data(bd) (bd)->data7172struct backlight_device *linux_backlight_device_register(const char *name,73struct device *dev, void *data, const struct backlight_ops *ops, struct backlight_properties *props);74void linux_backlight_device_unregister(struct backlight_device *bd);75#define backlight_device_register(name, dev, data, ops, props) \76linux_backlight_device_register(name, dev, data, ops, props)77#define backlight_device_unregister(bd) linux_backlight_device_unregister(bd)7879static inline int80backlight_update_status(struct backlight_device *bd)81{82return (bd->ops->update_status(bd));83}8485static inline void86backlight_force_update(struct backlight_device *bd, int reason)87{88bd->props.brightness = bd->ops->get_brightness(bd);89}9091static inline int92backlight_get_brightness(struct backlight_device *bd)93{9495return (bd->props.brightness);96}9798static inline int99backlight_device_set_brightness(struct backlight_device *bd, int brightness)100{101102if (brightness > bd->props.max_brightness)103return (EINVAL);104bd->props.brightness = brightness;105return (bd->ops->update_status(bd));106}107108static inline int109backlight_enable(struct backlight_device *bd)110{111if (bd == NULL)112return (0);113bd->props.power = 0/* FB_BLANK_UNBLANK */;114return (backlight_update_status(bd));115}116117static inline int118backlight_disable(struct backlight_device *bd)119{120if (bd == NULL)121return (0);122bd->props.power = 4/* FB_BLANK_POWERDOWN */;123return (backlight_update_status(bd));124}125126static inline bool127backlight_is_blank(struct backlight_device *bd)128{129130return (bd->props.power != 0/* FB_BLANK_UNBLANK */);131}132133#endif /* _LINUXKPI_LINUX_BACKLIGHT_H_ */134135136