1 /*-
2 * Copyright (c) 2022 Vladimir Kondratyev <wulf@FreeBSD.org>
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 */
25
26 #ifndef _LINUXKPI_LINUX_PWM_H_
27 #define _LINUXKPI_LINUX_PWM_H_
28
29 #include <linux/device.h>
30 #include <linux/err.h>
31
32 struct pwm_state {
33 uint64_t period;
34 bool enabled;
35 };
36
37 struct pwm_device {
38 struct pwm_state state;
39 };
40
41 static inline struct pwm_device *
pwm_get(struct device * dev,const char * consumer)42 pwm_get(struct device *dev, const char *consumer)
43 {
44 return (ERR_PTR(-ENODEV));
45 }
46
47 static inline void
pwm_put(struct pwm_device * pwm)48 pwm_put(struct pwm_device *pwm)
49 {
50 }
51
52 static inline int
pwm_enable(struct pwm_device * pwm)53 pwm_enable(struct pwm_device *pwm)
54 {
55 return (-EINVAL);
56 }
57
58 static inline void
pwm_disable(struct pwm_device * pwm)59 pwm_disable(struct pwm_device *pwm)
60 {
61 }
62
63 static inline bool
pwm_is_enabled(const struct pwm_device * pwm)64 pwm_is_enabled(const struct pwm_device *pwm)
65 {
66 return (false);
67 }
68
69 static inline unsigned int
pwm_get_relative_duty_cycle(const struct pwm_state * state,unsigned int scale)70 pwm_get_relative_duty_cycle(const struct pwm_state *state, unsigned int scale)
71 {
72 return (0);
73 }
74
75 static inline int
pwm_set_relative_duty_cycle(struct pwm_state * state,unsigned int duty_cycle,unsigned int scale)76 pwm_set_relative_duty_cycle(struct pwm_state *state, unsigned int duty_cycle,
77 unsigned int scale)
78 {
79 return (0);
80 }
81
82 static inline void
pwm_get_state(const struct pwm_device * pwm,struct pwm_state * state)83 pwm_get_state(const struct pwm_device *pwm, struct pwm_state *state)
84 {
85 *state = pwm->state;
86 }
87
88 static inline int
pwm_apply_state(struct pwm_device * pwm,const struct pwm_state * state)89 pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
90 {
91 return (-ENOTSUPP);
92 }
93
94 #endif /* _LINUXKPI_LINUX_PWM_H_ */
95