xref: /freebsd/sys/compat/linuxkpi/common/include/linux/pm.h (revision 3753988c5d22393fbdefb6aa16b5a5a699d05642)
14abbf816SBjoern A. Zeeb /*-
24abbf816SBjoern A. Zeeb  * SPDX-License-Identifier: BSD-2-Clause
34abbf816SBjoern A. Zeeb  *
4*3753988cSBjoern A. Zeeb  * Copyright (c) 2020-2024 The FreeBSD Foundation
54abbf816SBjoern A. Zeeb  *
64abbf816SBjoern A. Zeeb  * This software was developed by Björn Zeeb under sponsorship from
74abbf816SBjoern A. Zeeb  * the FreeBSD Foundation.
84abbf816SBjoern A. Zeeb  *
94abbf816SBjoern A. Zeeb  * Redistribution and use in source and binary forms, with or without
104abbf816SBjoern A. Zeeb  * modification, are permitted provided that the following conditions
114abbf816SBjoern A. Zeeb  * are met:
124abbf816SBjoern A. Zeeb  * 1. Redistributions of source code must retain the above copyright
134abbf816SBjoern A. Zeeb  *    notice, this list of conditions and the following disclaimer.
144abbf816SBjoern A. Zeeb  * 2. Redistributions in binary form must reproduce the above copyright
154abbf816SBjoern A. Zeeb  *    notice, this list of conditions and the following disclaimer in the
164abbf816SBjoern A. Zeeb  *    documentation and/or other materials provided with the distribution.
174abbf816SBjoern A. Zeeb  *
184abbf816SBjoern A. Zeeb  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
194abbf816SBjoern A. Zeeb  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
204abbf816SBjoern A. Zeeb  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
214abbf816SBjoern A. Zeeb  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
224abbf816SBjoern A. Zeeb  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
234abbf816SBjoern A. Zeeb  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
244abbf816SBjoern A. Zeeb  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
254abbf816SBjoern A. Zeeb  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
264abbf816SBjoern A. Zeeb  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
274abbf816SBjoern A. Zeeb  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
284abbf816SBjoern A. Zeeb  * SUCH DAMAGE.
294abbf816SBjoern A. Zeeb  */
304abbf816SBjoern A. Zeeb 
314abbf816SBjoern A. Zeeb #ifndef	_LINUXKPI_LINUX_PM_H
324abbf816SBjoern A. Zeeb #define	_LINUXKPI_LINUX_PM_H
334abbf816SBjoern A. Zeeb 
34934cb7a3SBjoern A. Zeeb #include <linux/kernel.h>	/* pr_debug */
354cb3cb2dSJake Freeland #include <asm/atomic.h>
364cb3cb2dSJake Freeland 
372ff0f051SEmmanuel Vadot /* Needed but breaks linux_usb.c */
382ff0f051SEmmanuel Vadot /* #include <linux/completion.h> */
392ff0f051SEmmanuel Vadot /* #include <linux/wait.h> */
402ff0f051SEmmanuel Vadot 
41934cb7a3SBjoern A. Zeeb struct device;
42934cb7a3SBjoern A. Zeeb 
430e981d79SBjoern A. Zeeb typedef struct pm_message {
440e981d79SBjoern A. Zeeb 	int event;
450e981d79SBjoern A. Zeeb } pm_message_t;
460e981d79SBjoern A. Zeeb 
472ff0f051SEmmanuel Vadot struct dev_pm_domain {
482ff0f051SEmmanuel Vadot };
492ff0f051SEmmanuel Vadot 
504cb3cb2dSJake Freeland struct dev_pm_info {
514cb3cb2dSJake Freeland 	atomic_t usage_count;
524cb3cb2dSJake Freeland };
534cb3cb2dSJake Freeland 
542ff0f051SEmmanuel Vadot #define	PM_EVENT_FREEZE		0x0001
552ff0f051SEmmanuel Vadot #define	PM_EVENT_SUSPEND	0x0002
562ff0f051SEmmanuel Vadot 
574052b0e4SBjoern A. Zeeb #define	pm_sleep_ptr(_p)					\
584052b0e4SBjoern A. Zeeb     IS_ENABLED(CONFIG_PM_SLEEP) ? (_p) : NULL
594052b0e4SBjoern A. Zeeb 
604abbf816SBjoern A. Zeeb #ifdef CONFIG_PM_SLEEP
61*3753988cSBjoern A. Zeeb #define	__SET_PM_OPS(_suspendfunc, _resumefunc)			\
624abbf816SBjoern A. Zeeb 	.suspend	= _suspendfunc,				\
634abbf816SBjoern A. Zeeb 	.resume		= _resumefunc,				\
644abbf816SBjoern A. Zeeb 	.freeze		= _suspendfunc,				\
654abbf816SBjoern A. Zeeb 	.thaw		= _resumefunc,				\
664abbf816SBjoern A. Zeeb 	.poweroff	= _suspendfunc,				\
674abbf816SBjoern A. Zeeb 	.restore	= _resumefunc,				\
68*3753988cSBjoern A. Zeeb 
69*3753988cSBjoern A. Zeeb #define	SIMPLE_DEV_PM_OPS(_name, _suspendfunc, _resumefunc)	\
70*3753988cSBjoern A. Zeeb const struct dev_pm_ops _name = {				\
71*3753988cSBjoern A. Zeeb 	__SET_PM_OPS(_suspendfunc, _resumefunc)			\
724abbf816SBjoern A. Zeeb }
734052b0e4SBjoern A. Zeeb 
744052b0e4SBjoern A. Zeeb #define	DEFINE_SIMPLE_DEV_PM_OPS(_name, _suspendfunc, _resumefunc) \
754052b0e4SBjoern A. Zeeb const struct dev_pm_ops _name = {				\
76*3753988cSBjoern A. Zeeb 	__SET_PM_OPS(_suspendfunc, _resumefunc)			\
774052b0e4SBjoern A. Zeeb }
78*3753988cSBjoern A. Zeeb 
79*3753988cSBjoern A. Zeeb #define	SET_SYSTEM_SLEEP_PM_OPS(_suspendfunc, _resumefunc)	\
80*3753988cSBjoern A. Zeeb 	__SET_PM_OPS(_suspendfunc, _resumefunc)
814abbf816SBjoern A. Zeeb #else
824abbf816SBjoern A. Zeeb #define	SIMPLE_DEV_PM_OPS(_name, _suspendfunc, _resumefunc)	\
834abbf816SBjoern A. Zeeb const struct dev_pm_ops _name = {				\
844abbf816SBjoern A. Zeeb }
854052b0e4SBjoern A. Zeeb #define	DEFINE_SIMPLE_DEV_PM_OPS(_name, _suspendfunc, _resumefunc) \
864052b0e4SBjoern A. Zeeb const struct dev_pm_ops _name = {				\
874052b0e4SBjoern A. Zeeb }
884abbf816SBjoern A. Zeeb #endif
894abbf816SBjoern A. Zeeb 
90*3753988cSBjoern A. Zeeb bool linuxkpi_device_can_wakeup(struct device *);
91*3753988cSBjoern A. Zeeb #define	device_can_wakeup(_dev)		linuxkpi_device_can_wakeup(_dev)
92*3753988cSBjoern A. Zeeb 
93934cb7a3SBjoern A. Zeeb static inline void
pm_wakeup_event(struct device * dev __unused,unsigned int x __unused)94934cb7a3SBjoern A. Zeeb pm_wakeup_event(struct device *dev __unused, unsigned int x __unused)
95934cb7a3SBjoern A. Zeeb {
96934cb7a3SBjoern A. Zeeb 
97934cb7a3SBjoern A. Zeeb 	pr_debug("%s: TODO\n", __func__);
98934cb7a3SBjoern A. Zeeb }
99934cb7a3SBjoern A. Zeeb 
1004abbf816SBjoern A. Zeeb #endif	/* _LINUXKPI_LINUX_PM_H */
101