xref: /openbmc/u-boot/drivers/pwm/pwm-uclass.c (revision 12308b12)
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2016 Google, Inc
4  * Written by Simon Glass <sjg@chromium.org>
5  */
6 
7 #include <common.h>
8 #include <dm.h>
9 #include <pwm.h>
10 
11 int pwm_set_invert(struct udevice *dev, uint channel, bool polarity)
12 {
13 	struct pwm_ops *ops = pwm_get_ops(dev);
14 
15 	if (!ops->set_invert)
16 		return -ENOSYS;
17 
18 	return ops->set_invert(dev, channel, polarity);
19 }
20 
21 int pwm_set_config(struct udevice *dev, uint channel, uint period_ns,
22 		   uint duty_ns)
23 {
24 	struct pwm_ops *ops = pwm_get_ops(dev);
25 
26 	if (!ops->set_config)
27 		return -ENOSYS;
28 
29 	return ops->set_config(dev, channel, period_ns, duty_ns);
30 }
31 
32 int pwm_set_enable(struct udevice *dev, uint channel, bool enable)
33 {
34 	struct pwm_ops *ops = pwm_get_ops(dev);
35 
36 	if (!ops->set_enable)
37 		return -ENOSYS;
38 
39 	return ops->set_enable(dev, channel, enable);
40 }
41 
42 UCLASS_DRIVER(pwm) = {
43 	.id		= UCLASS_PWM,
44 	.name		= "pwm",
45 };
46