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,
83 * struct pwm_device - PWM channel object
84 * @label: name of the PWM device
85 * @flags: flags associated with the PWM device
86 * @hwpwm: per-chip relative index of the PWM device
87 * @pwm: global index of the PWM device
88 * @chip: PWM chip providing this PWM device
89 * @chip_data: chip-private data associated with the PWM device
90 * @period: period of the PWM signal (in nanoseconds)
91 * @duty_cycle: duty cycle of the PWM signal (in nanoseconds)
92 * @polarity: polarity of the PWM signal
99 struct pwm_chip *chip;
103 unsigned int duty_cycle;
104 enum pwm_polarity polarity;
107 static inline bool pwm_is_enabled(const struct pwm_device *pwm)
109 return test_bit(PWMF_ENABLED, &pwm->flags);
112 static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)
115 pwm->period = period;
118 static inline unsigned int pwm_get_period(const struct pwm_device *pwm)
120 return pwm ? pwm->period : 0;
123 static inline void pwm_set_duty_cycle(struct pwm_device *pwm, unsigned int duty)
126 pwm->duty_cycle = duty;
129 static inline unsigned int pwm_get_duty_cycle(const struct pwm_device *pwm)
131 return pwm ? pwm->duty_cycle : 0;
135 * pwm_set_polarity - configure the polarity of a PWM signal
137 int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity);
139 static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm)
141 return pwm ? pwm->polarity : PWM_POLARITY_NORMAL;
145 * struct pwm_ops - PWM controller operations
146 * @request: optional hook for requesting a PWM
147 * @free: optional hook for freeing a PWM
148 * @config: configure duty cycles and period length for this PWM
149 * @set_polarity: configure the polarity of this PWM
150 * @enable: enable PWM output toggling
151 * @disable: disable PWM output toggling
152 * @dbg_show: optional routine to show contents in debugfs
153 * @owner: helps prevent removal of modules exporting active PWMs
156 int (*request)(struct pwm_chip *chip, struct pwm_device *pwm);
157 void (*free)(struct pwm_chip *chip, struct pwm_device *pwm);
158 int (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
159 int duty_ns, int period_ns);
160 int (*set_polarity)(struct pwm_chip *chip, struct pwm_device *pwm,
161 enum pwm_polarity polarity);
162 int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm);
163 void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm);
164 #ifdef CONFIG_DEBUG_FS
165 void (*dbg_show)(struct pwm_chip *chip, struct seq_file *s);
167 struct module *owner;
171 * struct pwm_chip - abstract a PWM controller
172 * @dev: device providing the PWMs
173 * @list: list node for internal use
174 * @ops: callbacks for this PWM controller
175 * @base: number of first PWM controlled by this chip
176 * @npwm: number of PWMs controlled by this chip
177 * @pwms: array of PWM devices allocated by the framework
178 * @of_xlate: request a PWM device given a device tree PWM specifier
179 * @of_pwm_n_cells: number of cells expected in the device tree PWM specifier
180 * @can_sleep: must be true if the .config(), .enable() or .disable()
181 * operations may sleep
185 struct list_head list;
186 const struct pwm_ops *ops;
190 struct pwm_device *pwms;
192 struct pwm_device * (*of_xlate)(struct pwm_chip *pc,
193 const struct of_phandle_args *args);
194 unsigned int of_pwm_n_cells;
198 #if IS_ENABLED(CONFIG_PWM)
199 int pwm_set_chip_data(struct pwm_device *pwm, void *data);
200 void *pwm_get_chip_data(struct pwm_device *pwm);
202 int pwmchip_add_with_polarity(struct pwm_chip *chip,
203 enum pwm_polarity polarity);
204 int pwmchip_add(struct pwm_chip *chip);
205 int pwmchip_remove(struct pwm_chip *chip);
206 struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
210 struct pwm_device *of_pwm_xlate_with_flags(struct pwm_chip *pc,
211 const struct of_phandle_args *args);
213 struct pwm_device *pwm_get(struct device *dev, const char *con_id);
214 struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id);
215 void pwm_put(struct pwm_device *pwm);
217 struct pwm_device *devm_pwm_get(struct device *dev, const char *con_id);
218 struct pwm_device *devm_of_pwm_get(struct device *dev, struct device_node *np,
220 void devm_pwm_put(struct device *dev, struct pwm_device *pwm);
222 bool pwm_can_sleep(struct pwm_device *pwm);
224 static inline int pwm_set_chip_data(struct pwm_device *pwm, void *data)
229 static inline void *pwm_get_chip_data(struct pwm_device *pwm)
234 static inline int pwmchip_add(struct pwm_chip *chip)
239 static inline int pwmchip_add_inversed(struct pwm_chip *chip)
244 static inline int pwmchip_remove(struct pwm_chip *chip)
249 static inline struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
253 return ERR_PTR(-ENODEV);
256 static inline struct pwm_device *pwm_get(struct device *dev,
257 const char *consumer)
259 return ERR_PTR(-ENODEV);
262 static inline struct pwm_device *of_pwm_get(struct device_node *np,
265 return ERR_PTR(-ENODEV);
268 static inline void pwm_put(struct pwm_device *pwm)
272 static inline struct pwm_device *devm_pwm_get(struct device *dev,
273 const char *consumer)
275 return ERR_PTR(-ENODEV);
278 static inline struct pwm_device *devm_of_pwm_get(struct device *dev,
279 struct device_node *np,
282 return ERR_PTR(-ENODEV);
285 static inline void devm_pwm_put(struct device *dev, struct pwm_device *pwm)
289 static inline bool pwm_can_sleep(struct pwm_device *pwm)
296 struct list_head list;
297 const char *provider;
302 enum pwm_polarity polarity;
305 #define PWM_LOOKUP(_provider, _index, _dev_id, _con_id, _period, _polarity) \
307 .provider = _provider, \
312 .polarity = _polarity \
315 #if IS_ENABLED(CONFIG_PWM)
316 void pwm_add_table(struct pwm_lookup *table, size_t num);
317 void pwm_remove_table(struct pwm_lookup *table, size_t num);
319 static inline void pwm_add_table(struct pwm_lookup *table, size_t num)
323 static inline void pwm_remove_table(struct pwm_lookup *table, size_t num)
328 #ifdef CONFIG_PWM_SYSFS
329 void pwmchip_sysfs_export(struct pwm_chip *chip);
330 void pwmchip_sysfs_unexport(struct pwm_chip *chip);
332 static inline void pwmchip_sysfs_export(struct pwm_chip *chip)
336 static inline void pwmchip_sysfs_unexport(struct pwm_chip *chip)
339 #endif /* CONFIG_PWM_SYSFS */
341 #endif /* __LINUX_PWM_H */