]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - include/linux/pwm.h
10 #if IS_ENABLED(CONFIG_PWM)
12 * pwm_request - request a PWM device
14 struct pwm_device
*pwm_request(int pwm_id
, const char *label
);
17 * pwm_free - free a PWM device
19 void pwm_free(struct pwm_device
*pwm
);
22 * pwm_config - change a PWM device configuration
24 int pwm_config(struct pwm_device
*pwm
, int duty_ns
, int period_ns
);
27 * pwm_enable - start a PWM output toggling
29 int pwm_enable(struct pwm_device
*pwm
);
32 * pwm_disable - stop a PWM output toggling
34 void pwm_disable(struct pwm_device
*pwm
);
36 static inline struct pwm_device
*pwm_request(int pwm_id
, const char *label
)
38 return ERR_PTR(-ENODEV
);
41 static inline void pwm_free(struct pwm_device
*pwm
)
45 static inline int pwm_config(struct pwm_device
*pwm
, int duty_ns
, int period_ns
)
50 static inline int pwm_enable(struct pwm_device
*pwm
)
55 static inline void pwm_disable(struct pwm_device
*pwm
)
63 * enum pwm_polarity - polarity of a PWM signal
64 * @PWM_POLARITY_NORMAL: a high signal for the duration of the duty-
65 * cycle, followed by a low signal for the remainder of the pulse
67 * @PWM_POLARITY_INVERSED: a low signal for the duration of the duty-
68 * cycle, followed by a high signal for the remainder of the pulse
73 PWM_POLARITY_INVERSED
,
77 PWMF_REQUESTED
= 1 << 0,
78 PWMF_ENABLED
= 1 << 1,
79 PWMF_EXPORTED
= 1 << 2,
87 struct pwm_chip
*chip
;
90 unsigned int period
; /* in nanoseconds */
91 unsigned int duty_cycle
; /* in nanoseconds */
92 enum pwm_polarity polarity
;
95 static inline void pwm_set_period(struct pwm_device
*pwm
, unsigned int period
)
101 static inline unsigned int pwm_get_period(struct pwm_device
*pwm
)
103 return pwm
? pwm
->period
: 0;
106 static inline void pwm_set_duty_cycle(struct pwm_device
*pwm
, unsigned int duty
)
109 pwm
->duty_cycle
= duty
;
112 static inline unsigned int pwm_get_duty_cycle(struct pwm_device
*pwm
)
114 return pwm
? pwm
->duty_cycle
: 0;
118 * pwm_set_polarity - configure the polarity of a PWM signal
120 int pwm_set_polarity(struct pwm_device
*pwm
, enum pwm_polarity polarity
);
123 * struct pwm_ops - PWM controller operations
124 * @request: optional hook for requesting a PWM
125 * @free: optional hook for freeing a PWM
126 * @config: configure duty cycles and period length for this PWM
127 * @set_polarity: configure the polarity of this PWM
128 * @enable: enable PWM output toggling
129 * @disable: disable PWM output toggling
130 * @dbg_show: optional routine to show contents in debugfs
131 * @owner: helps prevent removal of modules exporting active PWMs
134 int (*request
)(struct pwm_chip
*chip
,
135 struct pwm_device
*pwm
);
136 void (*free
)(struct pwm_chip
*chip
,
137 struct pwm_device
*pwm
);
138 int (*config
)(struct pwm_chip
*chip
,
139 struct pwm_device
*pwm
,
140 int duty_ns
, int period_ns
);
141 int (*set_polarity
)(struct pwm_chip
*chip
,
142 struct pwm_device
*pwm
,
143 enum pwm_polarity polarity
);
144 int (*enable
)(struct pwm_chip
*chip
,
145 struct pwm_device
*pwm
);
146 void (*disable
)(struct pwm_chip
*chip
,
147 struct pwm_device
*pwm
);
148 #ifdef CONFIG_DEBUG_FS
149 void (*dbg_show
)(struct pwm_chip
*chip
,
152 struct module
*owner
;
156 * struct pwm_chip - abstract a PWM controller
157 * @dev: device providing the PWMs
158 * @list: list node for internal use
159 * @ops: callbacks for this PWM controller
160 * @base: number of first PWM controlled by this chip
161 * @npwm: number of PWMs controlled by this chip
162 * @pwms: array of PWM devices allocated by the framework
163 * @can_sleep: must be true if the .config(), .enable() or .disable()
164 * operations may sleep
168 struct list_head list
;
169 const struct pwm_ops
*ops
;
173 struct pwm_device
*pwms
;
175 struct pwm_device
* (*of_xlate
)(struct pwm_chip
*pc
,
176 const struct of_phandle_args
*args
);
177 unsigned int of_pwm_n_cells
;
181 #if IS_ENABLED(CONFIG_PWM)
182 int pwm_set_chip_data(struct pwm_device
*pwm
, void *data
);
183 void *pwm_get_chip_data(struct pwm_device
*pwm
);
185 int pwmchip_add_with_polarity(struct pwm_chip
*chip
,
186 enum pwm_polarity polarity
);
187 int pwmchip_add(struct pwm_chip
*chip
);
188 int pwmchip_remove(struct pwm_chip
*chip
);
189 struct pwm_device
*pwm_request_from_chip(struct pwm_chip
*chip
,
193 struct pwm_device
*of_pwm_xlate_with_flags(struct pwm_chip
*pc
,
194 const struct of_phandle_args
*args
);
196 struct pwm_device
*pwm_get(struct device
*dev
, const char *con_id
);
197 struct pwm_device
*of_pwm_get(struct device_node
*np
, const char *con_id
);
198 void pwm_put(struct pwm_device
*pwm
);
200 struct pwm_device
*devm_pwm_get(struct device
*dev
, const char *con_id
);
201 struct pwm_device
*devm_of_pwm_get(struct device
*dev
, struct device_node
*np
,
203 void devm_pwm_put(struct device
*dev
, struct pwm_device
*pwm
);
205 bool pwm_can_sleep(struct pwm_device
*pwm
);
207 static inline int pwm_set_chip_data(struct pwm_device
*pwm
, void *data
)
212 static inline void *pwm_get_chip_data(struct pwm_device
*pwm
)
217 static inline int pwmchip_add(struct pwm_chip
*chip
)
222 static inline int pwmchip_add_inversed(struct pwm_chip
*chip
)
227 static inline int pwmchip_remove(struct pwm_chip
*chip
)
232 static inline struct pwm_device
*pwm_request_from_chip(struct pwm_chip
*chip
,
236 return ERR_PTR(-ENODEV
);
239 static inline struct pwm_device
*pwm_get(struct device
*dev
,
240 const char *consumer
)
242 return ERR_PTR(-ENODEV
);
245 static inline struct pwm_device
*of_pwm_get(struct device_node
*np
,
248 return ERR_PTR(-ENODEV
);
251 static inline void pwm_put(struct pwm_device
*pwm
)
255 static inline struct pwm_device
*devm_pwm_get(struct device
*dev
,
256 const char *consumer
)
258 return ERR_PTR(-ENODEV
);
261 static inline struct pwm_device
*devm_of_pwm_get(struct device
*dev
,
262 struct device_node
*np
,
265 return ERR_PTR(-ENODEV
);
268 static inline void devm_pwm_put(struct device
*dev
, struct pwm_device
*pwm
)
272 static inline bool pwm_can_sleep(struct pwm_device
*pwm
)
279 struct list_head list
;
280 const char *provider
;
285 enum pwm_polarity polarity
;
288 #define PWM_LOOKUP(_provider, _index, _dev_id, _con_id, _period, _polarity) \
290 .provider = _provider, \
295 .polarity = _polarity \
298 #if IS_ENABLED(CONFIG_PWM)
299 void pwm_add_table(struct pwm_lookup
*table
, size_t num
);
300 void pwm_remove_table(struct pwm_lookup
*table
, size_t num
);
302 static inline void pwm_add_table(struct pwm_lookup
*table
, size_t num
)
306 static inline void pwm_remove_table(struct pwm_lookup
*table
, size_t num
)
311 #ifdef CONFIG_PWM_SYSFS
312 void pwmchip_sysfs_export(struct pwm_chip
*chip
);
313 void pwmchip_sysfs_unexport(struct pwm_chip
*chip
);
315 static inline void pwmchip_sysfs_export(struct pwm_chip
*chip
)
319 static inline void pwmchip_sysfs_unexport(struct pwm_chip
*chip
)
322 #endif /* CONFIG_PWM_SYSFS */
324 #endif /* __LINUX_PWM_H */