summaryrefslogtreecommitdiff
path: root/include/pwm.h (plain)
blob: 1a5b4d2c3a8019847161c7a8797dbfbe2681ca08
1/*
2 * header file for pwm driver.
3 *
4 * Copyright (c) 2011 samsung electronics
5 * Donghwa Lee <dh09.lee@samsung.com>
6 *
7 * SPDX-License-Identifier: GPL-2.0+
8 */
9
10#ifndef _pwm_h_
11#define _pwm_h_
12
13/* struct pwm_ops: Operations for the PWM uclass */
14struct pwm_ops {
15 /**
16 * set_config() - Set the PWM configuration
17 *
18 * @dev: PWM device to update
19 * @channel: PWM channel to update
20 * @period_ns: PWM period in nanoseconds
21 * @duty_ns: PWM duty period in nanoseconds
22 * @return 0 if OK, -ve on error
23 */
24 int (*set_config)(struct udevice *dev, uint channel, uint period_ns,
25 uint duty_ns);
26
27 /**
28 * set_enable() - Enable or disable the PWM
29 *
30 * @dev: PWM device to update
31 * @channel: PWM channel to update
32 * @enable: true to enable, false to disable
33 * @return 0 if OK, -ve on error
34 */
35 int (*set_enable)(struct udevice *dev, uint channel, bool enable);
36 /**
37 * set_invert() - Set the PWM invert
38 *
39 * @dev: PWM device to update
40 * @channel: PWM channel to update
41 * @polarity: true to invert, false to keep normal polarity
42 * @return 0 if OK, -ve on error
43 */
44 int (*set_invert)(struct udevice *dev, uint channel, bool polarity);
45#ifdef CONFIG_PWM_MESON
46 /**
47 * set_times() - Set the PWM times
48 *
49 * @dev: PWM device to update
50 * @channel: PWM channel to update
51 * @times: dual channel to set times
52 * @return 0 if OK, -ve on error
53 */
54 int (*set_times)(struct udevice *dev, uint channel, uint times);
55 /**
56 * set_blink_times() - Set the PWM blink times
57 *
58 * @dev: PWM device to update
59 * @channel: PWM channel to update
60 * @times: set blink times
61 * @return 0 if OK, -ve on error
62 */
63 int (*set_blink_times)(struct udevice *dev, uint channel, uint times);
64 /**
65 * set_blink_enable() - Enable or disable the PWM blink
66 *
67 * @dev: PWM device to update
68 * @channel: PWM channel to update
69 * @enable: true to enable, false to disable
70 * @return 0 if OK, -ve on error
71 */
72 int (*set_blink_enable)(struct udevice *dev, uint channel, bool enable);
73#endif
74};
75
76#define pwm_get_ops(dev) ((struct pwm_ops *)(dev)->driver->ops)
77
78/**
79 * pwm_set_config() - Set the PWM configuration
80 *
81 * @dev: PWM device to update
82 * @channel: PWM channel to update
83 * @period_ns: PWM period in nanoseconds
84 * @duty_ns: PWM duty period in nanoseconds
85 * @return 0 if OK, -ve on error
86 */
87int pwm_set_config(struct udevice *dev, uint channel, uint period_ns,
88 uint duty_ns);
89
90/**
91 * pwm_set_enable() - Enable or disable the PWM
92 *
93 * @dev: PWM device to update
94 * @channel: PWM channel to update
95 * @enable: true to enable, false to disable
96 * @return 0 if OK, -ve on error
97 */
98int pwm_set_enable(struct udevice *dev, uint channel, bool enable);
99
100/**
101 * pwm_set_invert() - Set pwm default polarity
102 *
103 * @dev: PWM device to update
104 * @channel: PWM channel to update
105 * @polarity: true to invert, false to keep normal polarity
106 * @return 0 if OK, -ve on error
107 */
108int pwm_set_invert(struct udevice *dev, uint channel, bool polarity);
109#ifdef CONFIG_PWM_MESON
110/**
111 * pwm_set_times() - Set the PWM times
112 *
113 * @dev: PWM device to update
114 * @channel: PWM channel to update
115 * @times: dual channel to set times
116 * @return 0 if OK, -ve on error
117 */
118int pwm_set_times(struct udevice *dev, uint channel, uint times);
119
120/**
121 * pwm_set_blink_times() - Set the PWM blink times
122 *
123 * @dev: PWM device to update
124 * @channel: PWM channel to update
125 * @times: set blink times
126 * @return 0 if OK, -ve on error
127 */
128int pwm_set_blink_times(struct udevice *dev, uint channel, uint times);
129
130/**
131 * pwm_set_blink_enable() - Enable or disable the PWM blink
132 *
133 * @dev: PWM device to update
134 * @channel: PWM channel to update
135 * @enable: true to enable, false to disable
136 * @return 0 if OK, -ve on error
137 */
138int pwm_set_blink_enable(struct udevice *dev, uint channel, bool enable);
139#endif
140/* Legacy interface */
141#ifndef CONFIG_DM_PWM
142int pwm_init (int pwm_id, int div, int invert);
143int pwm_config (int pwm_id, int duty_ns, int period_ns);
144int pwm_enable (int pwm_id);
145void pwm_disable (int pwm_id);
146#endif
147
148#endif /* _pwm_h_ */
149