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