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;
91 unsigned int duty_cycle;
92 enum pwm_polarity polarity;
95 static inline bool pwm_is_enabled(const struct pwm_device *pwm)
97 return test_bit(PWMF_ENABLED, &pwm->flags);
100 static inline void pwm_set_period(struct pwm_device *pwm, unsigned int period)
103 pwm->period = period;
106 static inline unsigned int pwm_get_period(const struct pwm_device *pwm)
108 return pwm ? pwm->period : 0;
111 static inline void pwm_set_duty_cycle(struct pwm_device *pwm, unsigned int duty)
114 pwm->duty_cycle = duty;
117 static inline unsigned int pwm_get_duty_cycle(const struct pwm_device *pwm)
119 return pwm ? pwm->duty_cycle : 0;
123 * pwm_set_polarity - configure the polarity of a PWM signal
125 int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity);
127 static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm)
129 return pwm ? pwm->polarity : PWM_POLARITY_NORMAL;
133 * struct pwm_ops - PWM controller operations
134 * @request: optional hook for requesting a PWM
135 * @free: optional hook for freeing a PWM
136 * @config: configure duty cycles and period length for this PWM
137 * @set_polarity: configure the polarity of this PWM
138 * @enable: enable PWM output toggling
139 * @disable: disable PWM output toggling
140 * @dbg_show: optional routine to show contents in debugfs
141 * @owner: helps prevent removal of modules exporting active PWMs
144 int (*request)(struct pwm_chip *chip, struct pwm_device *pwm);
145 void (*free)(struct pwm_chip *chip, struct pwm_device *pwm);
146 int (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
147 int duty_ns, int period_ns);
148 int (*set_polarity)(struct pwm_chip *chip, struct pwm_device *pwm,
149 enum pwm_polarity polarity);
150 int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm);
151 void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm);
152 #ifdef CONFIG_DEBUG_FS
153 void (*dbg_show)(struct pwm_chip *chip, struct seq_file *s);
155 struct module *owner;
159 * struct pwm_chip - abstract a PWM controller
160 * @dev: device providing the PWMs
161 * @list: list node for internal use
162 * @ops: callbacks for this PWM controller
163 * @base: number of first PWM controlled by this chip
164 * @npwm: number of PWMs controlled by this chip
165 * @pwms: array of PWM devices allocated by the framework
166 * @can_sleep: must be true if the .config(), .enable() or .disable()
167 * operations may sleep
171 struct list_head list;
172 const struct pwm_ops *ops;
176 struct pwm_device *pwms;
178 struct pwm_device * (*of_xlate)(struct pwm_chip *pc,
179 const struct of_phandle_args *args);
180 unsigned int of_pwm_n_cells;
184 #if IS_ENABLED(CONFIG_PWM)
185 int pwm_set_chip_data(struct pwm_device *pwm, void *data);
186 void *pwm_get_chip_data(struct pwm_device *pwm);
188 int pwmchip_add_with_polarity(struct pwm_chip *chip,
189 enum pwm_polarity polarity);
190 int pwmchip_add(struct pwm_chip *chip);
191 int pwmchip_remove(struct pwm_chip *chip);
192 struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
196 struct pwm_device *of_pwm_xlate_with_flags(struct pwm_chip *pc,
197 const struct of_phandle_args *args);
199 struct pwm_device *pwm_get(struct device *dev, const char *con_id);
200 struct pwm_device *of_pwm_get(struct device_node *np, const char *con_id);
201 void pwm_put(struct pwm_device *pwm);
203 struct pwm_device *devm_pwm_get(struct device *dev, const char *con_id);
204 struct pwm_device *devm_of_pwm_get(struct device *dev, struct device_node *np,
206 void devm_pwm_put(struct device *dev, struct pwm_device *pwm);
208 bool pwm_can_sleep(struct pwm_device *pwm);
210 static inline int pwm_set_chip_data(struct pwm_device *pwm, void *data)
215 static inline void *pwm_get_chip_data(struct pwm_device *pwm)
220 static inline int pwmchip_add(struct pwm_chip *chip)
225 static inline int pwmchip_add_inversed(struct pwm_chip *chip)
230 static inline int pwmchip_remove(struct pwm_chip *chip)
235 static inline struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
239 return ERR_PTR(-ENODEV);
242 static inline struct pwm_device *pwm_get(struct device *dev,
243 const char *consumer)
245 return ERR_PTR(-ENODEV);
248 static inline struct pwm_device *of_pwm_get(struct device_node *np,
251 return ERR_PTR(-ENODEV);
254 static inline void pwm_put(struct pwm_device *pwm)
258 static inline struct pwm_device *devm_pwm_get(struct device *dev,
259 const char *consumer)
261 return ERR_PTR(-ENODEV);
264 static inline struct pwm_device *devm_of_pwm_get(struct device *dev,
265 struct device_node *np,
268 return ERR_PTR(-ENODEV);
271 static inline void devm_pwm_put(struct device *dev, struct pwm_device *pwm)
275 static inline bool pwm_can_sleep(struct pwm_device *pwm)
282 struct list_head list;
283 const char *provider;
288 enum pwm_polarity polarity;
291 #define PWM_LOOKUP(_provider, _index, _dev_id, _con_id, _period, _polarity) \
293 .provider = _provider, \
298 .polarity = _polarity \
301 #if IS_ENABLED(CONFIG_PWM)
302 void pwm_add_table(struct pwm_lookup *table, size_t num);
303 void pwm_remove_table(struct pwm_lookup *table, size_t num);
305 static inline void pwm_add_table(struct pwm_lookup *table, size_t num)
309 static inline void pwm_remove_table(struct pwm_lookup *table, size_t num)
314 #ifdef CONFIG_PWM_SYSFS
315 void pwmchip_sysfs_export(struct pwm_chip *chip);
316 void pwmchip_sysfs_unexport(struct pwm_chip *chip);
318 static inline void pwmchip_sysfs_export(struct pwm_chip *chip)
322 static inline void pwmchip_sysfs_unexport(struct pwm_chip *chip)
325 #endif /* CONFIG_PWM_SYSFS */
327 #endif /* __LINUX_PWM_H */