51d4005418f90cb7705246df428521a542c0d83c
5 #include <linux/mutex.h>
11 #if IS_ENABLED(CONFIG_PWM)
13 * pwm_request - request a PWM device
15 struct pwm_device
*pwm_request(int pwm_id
, const char *label
);
18 * pwm_free - free a PWM device
20 void pwm_free(struct pwm_device
*pwm
);
23 * pwm_config - change a PWM device configuration
25 int pwm_config(struct pwm_device
*pwm
, int duty_ns
, int period_ns
);
28 * pwm_enable - start a PWM output toggling
30 int pwm_enable(struct pwm_device
*pwm
);
33 * pwm_disable - stop a PWM output toggling
35 void pwm_disable(struct pwm_device
*pwm
);
37 static inline struct pwm_device
*pwm_request(int pwm_id
, const char *label
)
39 return ERR_PTR(-ENODEV
);
42 static inline void pwm_free(struct pwm_device
*pwm
)
46 static inline int pwm_config(struct pwm_device
*pwm
, int duty_ns
, int period_ns
)
51 static inline int pwm_enable(struct pwm_device
*pwm
)
56 static inline void pwm_disable(struct pwm_device
*pwm
)
64 * enum pwm_polarity - polarity of a PWM signal
65 * @PWM_POLARITY_NORMAL: a high signal for the duration of the duty-
66 * cycle, followed by a low signal for the remainder of the pulse
68 * @PWM_POLARITY_INVERSED: a low signal for the duration of the duty-
69 * cycle, followed by a high signal for the remainder of the pulse
74 PWM_POLARITY_INVERSED
,
78 * struct pwm_args - board-dependent PWM arguments
79 * @period: reference period
80 * @polarity: reference polarity
82 * This structure describes board-dependent arguments attached to a PWM
83 * device. These arguments are usually retrieved from the PWM lookup table or
86 * Do not confuse this with the PWM state: PWM arguments represent the initial
87 * configuration that users want to use on this PWM device rather than the
88 * current PWM hardware state.
92 enum pwm_polarity polarity
;
96 PWMF_REQUESTED
= 1 << 0,
97 PWMF_ENABLED
= 1 << 1,
98 PWMF_EXPORTED
= 1 << 2,
102 * struct pwm_state - state of a PWM channel
103 * @period: PWM period (in nanoseconds)
104 * @duty_cycle: PWM duty cycle (in nanoseconds)
105 * @polarity: PWM polarity
109 unsigned int duty_cycle
;
110 enum pwm_polarity polarity
;
114 * struct pwm_device - PWM channel object
115 * @label: name of the PWM device
116 * @flags: flags associated with the PWM device
117 * @hwpwm: per-chip relative index of the PWM device
118 * @pwm: global index of the PWM device
119 * @chip: PWM chip providing this PWM device
120 * @chip_data: chip-private data associated with the PWM device
121 * @args: PWM arguments
122 * @state: curent PWM channel state
129 struct pwm_chip
*chip
;
132 struct pwm_args args
;
133 struct pwm_state state
;
137 * pwm_get_state() - retrieve the current PWM state
139 * @state: state to fill with the current PWM state
141 static inline void pwm_get_state(const struct pwm_device
*pwm
,
142 struct pwm_state
*state
)
147 static inline bool pwm_is_enabled(const struct pwm_device
*pwm
)
149 return test_bit(PWMF_ENABLED
, &pwm
->flags
);
152 static inline void pwm_set_period(struct pwm_device
*pwm
, unsigned int period
)
155 pwm
->state
.period
= period
;
158 static inline unsigned int pwm_get_period(const struct pwm_device
*pwm
)
160 struct pwm_state state
;
162 pwm_get_state(pwm
, &state
);
167 static inline void pwm_set_duty_cycle(struct pwm_device
*pwm
, unsigned int duty
)
170 pwm
->state
.duty_cycle
= duty
;
173 static inline unsigned int pwm_get_duty_cycle(const struct pwm_device
*pwm
)
175 struct pwm_state state
;
177 pwm_get_state(pwm
, &state
);
179 return state
.duty_cycle
;
183 * pwm_set_polarity - configure the polarity of a PWM signal
185 int pwm_set_polarity(struct pwm_device
*pwm
, enum pwm_polarity polarity
);
187 static inline enum pwm_polarity
pwm_get_polarity(const struct pwm_device
*pwm
)
189 struct pwm_state state
;
191 pwm_get_state(pwm
, &state
);
193 return state
.polarity
;
196 static inline void pwm_get_args(const struct pwm_device
*pwm
,
197 struct pwm_args
*args
)
202 static inline void pwm_apply_args(struct pwm_device
*pwm
)
204 pwm_set_polarity(pwm
, pwm
->args
.polarity
);
208 * struct pwm_ops - PWM controller operations
209 * @request: optional hook for requesting a PWM
210 * @free: optional hook for freeing a PWM
211 * @config: configure duty cycles and period length for this PWM
212 * @set_polarity: configure the polarity of this PWM
213 * @enable: enable PWM output toggling
214 * @disable: disable PWM output toggling
215 * @dbg_show: optional routine to show contents in debugfs
216 * @owner: helps prevent removal of modules exporting active PWMs
219 int (*request
)(struct pwm_chip
*chip
, struct pwm_device
*pwm
);
220 void (*free
)(struct pwm_chip
*chip
, struct pwm_device
*pwm
);
221 int (*config
)(struct pwm_chip
*chip
, struct pwm_device
*pwm
,
222 int duty_ns
, int period_ns
);
223 int (*set_polarity
)(struct pwm_chip
*chip
, struct pwm_device
*pwm
,
224 enum pwm_polarity polarity
);
225 int (*enable
)(struct pwm_chip
*chip
, struct pwm_device
*pwm
);
226 void (*disable
)(struct pwm_chip
*chip
, struct pwm_device
*pwm
);
227 #ifdef CONFIG_DEBUG_FS
228 void (*dbg_show
)(struct pwm_chip
*chip
, struct seq_file
*s
);
230 struct module
*owner
;
234 * struct pwm_chip - abstract a PWM controller
235 * @dev: device providing the PWMs
236 * @list: list node for internal use
237 * @ops: callbacks for this PWM controller
238 * @base: number of first PWM controlled by this chip
239 * @npwm: number of PWMs controlled by this chip
240 * @pwms: array of PWM devices allocated by the framework
241 * @of_xlate: request a PWM device given a device tree PWM specifier
242 * @of_pwm_n_cells: number of cells expected in the device tree PWM specifier
243 * @can_sleep: must be true if the .config(), .enable() or .disable()
244 * operations may sleep
248 struct list_head list
;
249 const struct pwm_ops
*ops
;
253 struct pwm_device
*pwms
;
255 struct pwm_device
* (*of_xlate
)(struct pwm_chip
*pc
,
256 const struct of_phandle_args
*args
);
257 unsigned int of_pwm_n_cells
;
261 #if IS_ENABLED(CONFIG_PWM)
262 int pwm_set_chip_data(struct pwm_device
*pwm
, void *data
);
263 void *pwm_get_chip_data(struct pwm_device
*pwm
);
265 int pwmchip_add_with_polarity(struct pwm_chip
*chip
,
266 enum pwm_polarity polarity
);
267 int pwmchip_add(struct pwm_chip
*chip
);
268 int pwmchip_remove(struct pwm_chip
*chip
);
269 struct pwm_device
*pwm_request_from_chip(struct pwm_chip
*chip
,
273 struct pwm_device
*of_pwm_xlate_with_flags(struct pwm_chip
*pc
,
274 const struct of_phandle_args
*args
);
276 struct pwm_device
*pwm_get(struct device
*dev
, const char *con_id
);
277 struct pwm_device
*of_pwm_get(struct device_node
*np
, const char *con_id
);
278 void pwm_put(struct pwm_device
*pwm
);
280 struct pwm_device
*devm_pwm_get(struct device
*dev
, const char *con_id
);
281 struct pwm_device
*devm_of_pwm_get(struct device
*dev
, struct device_node
*np
,
283 void devm_pwm_put(struct device
*dev
, struct pwm_device
*pwm
);
285 bool pwm_can_sleep(struct pwm_device
*pwm
);
287 static inline int pwm_set_chip_data(struct pwm_device
*pwm
, void *data
)
292 static inline void *pwm_get_chip_data(struct pwm_device
*pwm
)
297 static inline int pwmchip_add(struct pwm_chip
*chip
)
302 static inline int pwmchip_add_inversed(struct pwm_chip
*chip
)
307 static inline int pwmchip_remove(struct pwm_chip
*chip
)
312 static inline struct pwm_device
*pwm_request_from_chip(struct pwm_chip
*chip
,
316 return ERR_PTR(-ENODEV
);
319 static inline struct pwm_device
*pwm_get(struct device
*dev
,
320 const char *consumer
)
322 return ERR_PTR(-ENODEV
);
325 static inline struct pwm_device
*of_pwm_get(struct device_node
*np
,
328 return ERR_PTR(-ENODEV
);
331 static inline void pwm_put(struct pwm_device
*pwm
)
335 static inline struct pwm_device
*devm_pwm_get(struct device
*dev
,
336 const char *consumer
)
338 return ERR_PTR(-ENODEV
);
341 static inline struct pwm_device
*devm_of_pwm_get(struct device
*dev
,
342 struct device_node
*np
,
345 return ERR_PTR(-ENODEV
);
348 static inline void devm_pwm_put(struct device
*dev
, struct pwm_device
*pwm
)
352 static inline bool pwm_can_sleep(struct pwm_device
*pwm
)
359 struct list_head list
;
360 const char *provider
;
365 enum pwm_polarity polarity
;
368 #define PWM_LOOKUP(_provider, _index, _dev_id, _con_id, _period, _polarity) \
370 .provider = _provider, \
375 .polarity = _polarity \
378 #if IS_ENABLED(CONFIG_PWM)
379 void pwm_add_table(struct pwm_lookup
*table
, size_t num
);
380 void pwm_remove_table(struct pwm_lookup
*table
, size_t num
);
382 static inline void pwm_add_table(struct pwm_lookup
*table
, size_t num
)
386 static inline void pwm_remove_table(struct pwm_lookup
*table
, size_t num
)
391 #ifdef CONFIG_PWM_SYSFS
392 void pwmchip_sysfs_export(struct pwm_chip
*chip
);
393 void pwmchip_sysfs_unexport(struct pwm_chip
*chip
);
395 static inline void pwmchip_sysfs_export(struct pwm_chip
*chip
)
399 static inline void pwmchip_sysfs_unexport(struct pwm_chip
*chip
)
402 #endif /* CONFIG_PWM_SYSFS */
404 #endif /* __LINUX_PWM_H */
This page took 0.038589 seconds and 4 git commands to generate.