xref: /src/sys/compat/linuxkpi/common/include/linux/pwm.h (revision 0b02cfb9488a3ac6b75836ca9cee8227b9d4b54c)
12b743f65SEmmanuel Vadot /*-
22b743f65SEmmanuel Vadot  * Copyright (c) 2022 Vladimir Kondratyev <wulf@FreeBSD.org>
32b743f65SEmmanuel Vadot  *
42b743f65SEmmanuel Vadot  * Redistribution and use in source and binary forms, with or without
52b743f65SEmmanuel Vadot  * modification, are permitted provided that the following conditions
62b743f65SEmmanuel Vadot  * are met:
72b743f65SEmmanuel Vadot  * 1. Redistributions of source code must retain the above copyright
82b743f65SEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer.
92b743f65SEmmanuel Vadot  * 2. Redistributions in binary form must reproduce the above copyright
102b743f65SEmmanuel Vadot  *    notice, this list of conditions and the following disclaimer in the
112b743f65SEmmanuel Vadot  *    documentation and/or other materials provided with the distribution.
122b743f65SEmmanuel Vadot  *
132b743f65SEmmanuel Vadot  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
142b743f65SEmmanuel Vadot  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
152b743f65SEmmanuel Vadot  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
162b743f65SEmmanuel Vadot  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
172b743f65SEmmanuel Vadot  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
182b743f65SEmmanuel Vadot  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
192b743f65SEmmanuel Vadot  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
202b743f65SEmmanuel Vadot  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
212b743f65SEmmanuel Vadot  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
222b743f65SEmmanuel Vadot  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
232b743f65SEmmanuel Vadot  * SUCH DAMAGE.
242b743f65SEmmanuel Vadot  */
252b743f65SEmmanuel Vadot 
262b743f65SEmmanuel Vadot #ifndef _LINUXKPI_LINUX_PWM_H_
272b743f65SEmmanuel Vadot #define	_LINUXKPI_LINUX_PWM_H_
282b743f65SEmmanuel Vadot 
292b743f65SEmmanuel Vadot #include <linux/device.h>
302b743f65SEmmanuel Vadot #include <linux/err.h>
312b743f65SEmmanuel Vadot 
322b743f65SEmmanuel Vadot struct pwm_state {
332b743f65SEmmanuel Vadot 	uint64_t period;
342b743f65SEmmanuel Vadot 	bool enabled;
352b743f65SEmmanuel Vadot };
362b743f65SEmmanuel Vadot 
372b743f65SEmmanuel Vadot struct pwm_device {
382b743f65SEmmanuel Vadot 	struct pwm_state state;
392b743f65SEmmanuel Vadot };
402b743f65SEmmanuel Vadot 
412b743f65SEmmanuel Vadot static inline struct pwm_device *
pwm_get(struct device * dev,const char * consumer)422b743f65SEmmanuel Vadot pwm_get(struct device *dev, const char *consumer)
432b743f65SEmmanuel Vadot {
442b743f65SEmmanuel Vadot 	return (ERR_PTR(-ENODEV));
452b743f65SEmmanuel Vadot }
462b743f65SEmmanuel Vadot 
472b743f65SEmmanuel Vadot static inline void
pwm_put(struct pwm_device * pwm)482b743f65SEmmanuel Vadot pwm_put(struct pwm_device *pwm)
492b743f65SEmmanuel Vadot {
502b743f65SEmmanuel Vadot }
512b743f65SEmmanuel Vadot 
522b743f65SEmmanuel Vadot static inline int
pwm_enable(struct pwm_device * pwm)532b743f65SEmmanuel Vadot pwm_enable(struct pwm_device *pwm)
542b743f65SEmmanuel Vadot {
552b743f65SEmmanuel Vadot 	return (-EINVAL);
562b743f65SEmmanuel Vadot }
572b743f65SEmmanuel Vadot 
582b743f65SEmmanuel Vadot static inline void
pwm_disable(struct pwm_device * pwm)592b743f65SEmmanuel Vadot pwm_disable(struct pwm_device *pwm)
602b743f65SEmmanuel Vadot {
612b743f65SEmmanuel Vadot }
622b743f65SEmmanuel Vadot 
632b743f65SEmmanuel Vadot static inline bool
pwm_is_enabled(const struct pwm_device * pwm)642b743f65SEmmanuel Vadot pwm_is_enabled(const struct pwm_device *pwm)
652b743f65SEmmanuel Vadot {
662b743f65SEmmanuel Vadot 	return (false);
672b743f65SEmmanuel Vadot }
682b743f65SEmmanuel Vadot 
692b743f65SEmmanuel Vadot static inline unsigned int
pwm_get_relative_duty_cycle(const struct pwm_state * state,unsigned int scale)702b743f65SEmmanuel Vadot pwm_get_relative_duty_cycle(const struct pwm_state *state, unsigned int scale)
712b743f65SEmmanuel Vadot {
722b743f65SEmmanuel Vadot 	return (0);
732b743f65SEmmanuel Vadot }
742b743f65SEmmanuel Vadot 
752b743f65SEmmanuel Vadot static inline int
pwm_set_relative_duty_cycle(struct pwm_state * state,unsigned int duty_cycle,unsigned int scale)762b743f65SEmmanuel Vadot pwm_set_relative_duty_cycle(struct pwm_state *state, unsigned int duty_cycle,
772b743f65SEmmanuel Vadot     unsigned int scale)
782b743f65SEmmanuel Vadot {
792b743f65SEmmanuel Vadot 	return (0);
802b743f65SEmmanuel Vadot }
812b743f65SEmmanuel Vadot 
822b743f65SEmmanuel Vadot static inline void
pwm_get_state(const struct pwm_device * pwm,struct pwm_state * state)832b743f65SEmmanuel Vadot pwm_get_state(const struct pwm_device *pwm, struct pwm_state *state)
842b743f65SEmmanuel Vadot {
852b743f65SEmmanuel Vadot 	*state = pwm->state;
862b743f65SEmmanuel Vadot }
872b743f65SEmmanuel Vadot 
882b743f65SEmmanuel Vadot static inline int
pwm_apply_state(struct pwm_device * pwm,const struct pwm_state * state)892b743f65SEmmanuel Vadot pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
902b743f65SEmmanuel Vadot {
912b743f65SEmmanuel Vadot 	return (-ENOTSUPP);
922b743f65SEmmanuel Vadot }
932b743f65SEmmanuel Vadot 
940b02cfb9SJean-Sébastien Pédron static inline int
pwm_apply_might_sleep(struct pwm_device * pwm,const struct pwm_state * state)950b02cfb9SJean-Sébastien Pédron pwm_apply_might_sleep(struct pwm_device *pwm, const struct pwm_state *state)
960b02cfb9SJean-Sébastien Pédron {
970b02cfb9SJean-Sébastien Pédron 	return (0);
980b02cfb9SJean-Sébastien Pédron }
990b02cfb9SJean-Sébastien Pédron 
1002b743f65SEmmanuel Vadot #endif	/* _LINUXKPI_LINUX_PWM_H_ */
101