xref: /openbmc/u-boot/include/pwm.h (revision e8f80a5a)
1*83d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0+ */
23f129280SDonghwa Lee /*
33f129280SDonghwa Lee  * header file for pwm driver.
43f129280SDonghwa Lee  *
5fc760cb8SSimon Glass  * Copyright 2016 Google Inc.
63f129280SDonghwa Lee  * Copyright (c) 2011 samsung electronics
73f129280SDonghwa Lee  * Donghwa Lee <dh09.lee@samsung.com>
83f129280SDonghwa Lee  */
93f129280SDonghwa Lee 
103f129280SDonghwa Lee #ifndef _pwm_h_
113f129280SDonghwa Lee #define _pwm_h_
123f129280SDonghwa Lee 
13fc760cb8SSimon Glass /* struct pwm_ops: Operations for the PWM uclass */
14fc760cb8SSimon Glass struct pwm_ops {
15fc760cb8SSimon Glass 	/**
16fc760cb8SSimon Glass 	 * set_config() - Set the PWM configuration
17fc760cb8SSimon Glass 	 *
18fc760cb8SSimon Glass 	 * @dev:	PWM device to update
19fc760cb8SSimon Glass 	 * @channel:	PWM channel to update
20fc760cb8SSimon Glass 	 * @period_ns:	PWM period in nanoseconds
21fc760cb8SSimon Glass 	 * @duty_ns:	PWM duty period in nanoseconds
22fc760cb8SSimon Glass 	 * @return 0 if OK, -ve on error
23fc760cb8SSimon Glass 	 */
24fc760cb8SSimon Glass 	int (*set_config)(struct udevice *dev, uint channel, uint period_ns,
25fc760cb8SSimon Glass 			  uint duty_ns);
26fc760cb8SSimon Glass 
27fc760cb8SSimon Glass 	/**
28fc760cb8SSimon Glass 	 * set_enable() - Enable or disable the PWM
29fc760cb8SSimon Glass 	 *
30fc760cb8SSimon Glass 	 * @dev:	PWM device to update
31fc760cb8SSimon Glass 	 * @channel:	PWM channel to update
32fc760cb8SSimon Glass 	 * @enable:	true to enable, false to disable
33fc760cb8SSimon Glass 	 * @return 0 if OK, -ve on error
34fc760cb8SSimon Glass 	 */
35fc760cb8SSimon Glass 	int (*set_enable)(struct udevice *dev, uint channel, bool enable);
360b60111aSKever Yang 	/**
370b60111aSKever Yang 	 * set_invert() - Set the PWM invert
380b60111aSKever Yang 	 *
390b60111aSKever Yang 	 * @dev:        PWM device to update
400b60111aSKever Yang 	 * @channel:    PWM channel to update
410b60111aSKever Yang 	 * @polarity:   true to invert, false to keep normal polarity
420b60111aSKever Yang 	 * @return 0 if OK, -ve on error
430b60111aSKever Yang 	 */
440b60111aSKever Yang 	int (*set_invert)(struct udevice *dev, uint channel, bool polarity);
45fc760cb8SSimon Glass };
46fc760cb8SSimon Glass 
47fc760cb8SSimon Glass #define pwm_get_ops(dev)	((struct pwm_ops *)(dev)->driver->ops)
48fc760cb8SSimon Glass 
49fc760cb8SSimon Glass /**
50fc760cb8SSimon Glass  * pwm_set_config() - Set the PWM configuration
51fc760cb8SSimon Glass  *
52fc760cb8SSimon Glass  * @dev:	PWM device to update
53fc760cb8SSimon Glass  * @channel:	PWM channel to update
54fc760cb8SSimon Glass  * @period_ns:	PWM period in nanoseconds
55fc760cb8SSimon Glass  * @duty_ns:	PWM duty period in nanoseconds
56fc760cb8SSimon Glass  * @return 0 if OK, -ve on error
57fc760cb8SSimon Glass  */
58fc760cb8SSimon Glass int pwm_set_config(struct udevice *dev, uint channel, uint period_ns,
59fc760cb8SSimon Glass 		   uint duty_ns);
60fc760cb8SSimon Glass 
61fc760cb8SSimon Glass /**
62fc760cb8SSimon Glass  * pwm_set_enable() - Enable or disable the PWM
63fc760cb8SSimon Glass  *
64fc760cb8SSimon Glass  * @dev:	PWM device to update
65fc760cb8SSimon Glass  * @channel:	PWM channel to update
66fc760cb8SSimon Glass  * @enable:	true to enable, false to disable
67fc760cb8SSimon Glass  * @return 0 if OK, -ve on error
68fc760cb8SSimon Glass  */
69fc760cb8SSimon Glass int pwm_set_enable(struct udevice *dev, uint channel, bool enable);
70fc760cb8SSimon Glass 
710b60111aSKever Yang /**
720b60111aSKever Yang  * pwm_set_invert() - Set pwm default polarity
730b60111aSKever Yang  *
740b60111aSKever Yang  * @dev:	PWM device to update
750b60111aSKever Yang  * @channel:	PWM channel to update
760b60111aSKever Yang  * @polarity:	true to invert, false to keep normal polarity
770b60111aSKever Yang  * @return 0 if OK, -ve on error
780b60111aSKever Yang  */
790b60111aSKever Yang int pwm_set_invert(struct udevice *dev, uint channel, bool polarity);
800b60111aSKever Yang 
81fc760cb8SSimon Glass /* Legacy interface */
82fc760cb8SSimon Glass #ifndef CONFIG_DM_PWM
833f129280SDonghwa Lee int	pwm_init		(int pwm_id, int div, int invert);
843f129280SDonghwa Lee int	pwm_config		(int pwm_id, int duty_ns, int period_ns);
853f129280SDonghwa Lee int	pwm_enable		(int pwm_id);
863f129280SDonghwa Lee void	pwm_disable		(int pwm_id);
87fc760cb8SSimon Glass #endif
883f129280SDonghwa Lee 
893f129280SDonghwa Lee #endif /* _pwm_h_ */
90