1 /*
2  * Copyright (c) 2022, Commonwealth Scientific and Industrial Research
3  * Organisation (CSIRO) ABN 41 687 119 230.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 /*
9  * This is not a real PWM driver. It is used to instantiate struct
10  * devices for the "vnd,pwm" devicetree compatible used in test code.
11  */
12 
13 #include <zephyr/kernel.h>
14 #include <zephyr/drivers/pwm.h>
15 
16 #define DT_DRV_COMPAT vnd_pwm
17 
vnd_pwm_set_cycles(const struct device * dev,uint32_t channel,uint32_t period_cycles,uint32_t pulse_cycles,pwm_flags_t flags)18 static int vnd_pwm_set_cycles(const struct device *dev, uint32_t channel,
19 			      uint32_t period_cycles, uint32_t pulse_cycles,
20 			      pwm_flags_t flags)
21 {
22 	return -ENOTSUP;
23 }
24 
25 #ifdef CONFIG_PWM_CAPTURE
vnd_pwm_configure_capture(const struct device * dev,uint32_t channel,pwm_flags_t flags,pwm_capture_callback_handler_t cb,void * user_data)26 static int vnd_pwm_configure_capture(const struct device *dev, uint32_t channel,
27 				     pwm_flags_t flags,
28 				     pwm_capture_callback_handler_t cb,
29 				     void *user_data)
30 {
31 	return -ENOTSUP;
32 }
33 
vnd_pwm_enable_capture(const struct device * dev,uint32_t channel)34 static int vnd_pwm_enable_capture(const struct device *dev, uint32_t channel)
35 {
36 	return -ENOTSUP;
37 }
38 
vnd_pwm_disable_capture(const struct device * dev,uint32_t channel)39 static int vnd_pwm_disable_capture(const struct device *dev, uint32_t channel)
40 {
41 	return -ENOTSUP;
42 }
43 #endif /* CONFIG_PWM_CAPTURE */
44 
vnd_pwm_get_cycles_per_sec(const struct device * dev,uint32_t channel,uint64_t * cycles)45 static int vnd_pwm_get_cycles_per_sec(const struct device *dev,
46 				      uint32_t channel, uint64_t *cycles)
47 {
48 	return -ENOTSUP;
49 }
50 
51 static const struct pwm_driver_api vnd_pwm_api = {
52 	.set_cycles = vnd_pwm_set_cycles,
53 #ifdef CONFIG_PWM_CAPTURE
54 	.configure_capture = vnd_pwm_configure_capture,
55 	.enable_capture = vnd_pwm_enable_capture,
56 	.disable_capture = vnd_pwm_disable_capture,
57 #endif /* CONFIG_PWM_CAPTURE */
58 	.get_cycles_per_sec = vnd_pwm_get_cycles_per_sec,
59 };
60 
61 #define VND_PWM_INIT(n)							       \
62 	DEVICE_DT_INST_DEFINE(n, NULL, NULL, NULL, NULL, POST_KERNEL,	       \
63 			      CONFIG_PWM_INIT_PRIORITY, &vnd_pwm_api);
64 
65 DT_INST_FOREACH_STATUS_OKAY(VND_PWM_INIT)
66