blob: f9959706ceb696536af9bfeb1cc3748e2dd6b28a [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Donghwa Lee3f129282011-03-07 21:11:42 +00002/*
3 * header file for pwm driver.
4 *
Simon Glassfc760cb2016-01-21 19:44:54 -07005 * Copyright 2016 Google Inc.
Donghwa Lee3f129282011-03-07 21:11:42 +00006 * Copyright (c) 2011 samsung electronics
7 * Donghwa Lee <dh09.lee@samsung.com>
Donghwa Lee3f129282011-03-07 21:11:42 +00008 */
9
10#ifndef _pwm_h_
11#define _pwm_h_
12
Simon Glass401d1c42020-10-30 21:38:53 -060013struct udevice;
14
Simon Glassfc760cb2016-01-21 19:44:54 -070015/* struct pwm_ops: Operations for the PWM uclass */
16struct pwm_ops {
17 /**
18 * set_config() - Set the PWM configuration
19 *
20 * @dev: PWM device to update
21 * @channel: PWM channel to update
22 * @period_ns: PWM period in nanoseconds
23 * @duty_ns: PWM duty period in nanoseconds
24 * @return 0 if OK, -ve on error
25 */
26 int (*set_config)(struct udevice *dev, uint channel, uint period_ns,
27 uint duty_ns);
28
29 /**
30 * set_enable() - Enable or disable the PWM
31 *
32 * @dev: PWM device to update
33 * @channel: PWM channel to update
34 * @enable: true to enable, false to disable
35 * @return 0 if OK, -ve on error
36 */
37 int (*set_enable)(struct udevice *dev, uint channel, bool enable);
Kever Yang0b601112017-04-24 10:27:49 +080038 /**
39 * set_invert() - Set the PWM invert
40 *
41 * @dev: PWM device to update
42 * @channel: PWM channel to update
43 * @polarity: true to invert, false to keep normal polarity
44 * @return 0 if OK, -ve on error
45 */
46 int (*set_invert)(struct udevice *dev, uint channel, bool polarity);
Simon Glassfc760cb2016-01-21 19:44:54 -070047};
48
49#define pwm_get_ops(dev) ((struct pwm_ops *)(dev)->driver->ops)
50
51/**
52 * pwm_set_config() - Set the PWM configuration
53 *
54 * @dev: PWM device to update
55 * @channel: PWM channel to update
56 * @period_ns: PWM period in nanoseconds
57 * @duty_ns: PWM duty period in nanoseconds
58 * @return 0 if OK, -ve on error
59 */
60int pwm_set_config(struct udevice *dev, uint channel, uint period_ns,
61 uint duty_ns);
62
63/**
64 * pwm_set_enable() - Enable or disable the PWM
65 *
66 * @dev: PWM device to update
67 * @channel: PWM channel to update
68 * @enable: true to enable, false to disable
69 * @return 0 if OK, -ve on error
70 */
71int pwm_set_enable(struct udevice *dev, uint channel, bool enable);
72
Kever Yang0b601112017-04-24 10:27:49 +080073/**
74 * pwm_set_invert() - Set pwm default polarity
75 *
76 * @dev: PWM device to update
77 * @channel: PWM channel to update
78 * @polarity: true to invert, false to keep normal polarity
79 * @return 0 if OK, -ve on error
80 */
81int pwm_set_invert(struct udevice *dev, uint channel, bool polarity);
82
Simon Glassfc760cb2016-01-21 19:44:54 -070083/* Legacy interface */
84#ifndef CONFIG_DM_PWM
Donghwa Lee3f129282011-03-07 21:11:42 +000085int pwm_init (int pwm_id, int div, int invert);
86int pwm_config (int pwm_id, int duty_ns, int period_ns);
87int pwm_enable (int pwm_id);
88void pwm_disable (int pwm_id);
Simon Glassfc760cb2016-01-21 19:44:54 -070089#endif
Donghwa Lee3f129282011-03-07 21:11:42 +000090
91#endif /* _pwm_h_ */