Lines Matching full:pwm
12 * enum pwm_polarity - polarity of a PWM signal
26 * struct pwm_args - board-dependent PWM arguments
30 * This structure describes board-dependent arguments attached to a PWM
31 * device. These arguments are usually retrieved from the PWM lookup table or
34 * Do not confuse this with the PWM state: PWM arguments represent the initial
35 * configuration that users want to use on this PWM device rather than the
36 * current PWM hardware state.
49 * struct pwm_state - state of a PWM channel
50 * @period: PWM period (in nanoseconds)
51 * @duty_cycle: PWM duty cycle (in nanoseconds)
52 * @polarity: PWM polarity
53 * @enabled: PWM enabled status
54 * @usage_power: If set, the PWM driver is only required to maintain the power
68 * struct pwm_device - PWM channel object
69 * @label: name of the PWM device
70 * @flags: flags associated with the PWM device
71 * @hwpwm: per-chip relative index of the PWM device
72 * @chip: PWM chip providing this PWM device
73 * @args: PWM arguments
89 * pwm_get_state() - retrieve the current PWM state
90 * @pwm: PWM device
91 * @state: state to fill with the current PWM state
93 * The returned PWM state represents the state that was applied by a previous call to
98 static inline void pwm_get_state(const struct pwm_device *pwm, in pwm_get_state() argument
101 *state = pwm->state; in pwm_get_state()
104 static inline bool pwm_is_enabled(const struct pwm_device *pwm) in pwm_is_enabled() argument
108 pwm_get_state(pwm, &state); in pwm_is_enabled()
113 static inline u64 pwm_get_period(const struct pwm_device *pwm) in pwm_get_period() argument
117 pwm_get_state(pwm, &state); in pwm_get_period()
122 static inline u64 pwm_get_duty_cycle(const struct pwm_device *pwm) in pwm_get_duty_cycle() argument
126 pwm_get_state(pwm, &state); in pwm_get_duty_cycle()
131 static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm) in pwm_get_polarity() argument
135 pwm_get_state(pwm, &state); in pwm_get_polarity()
140 static inline void pwm_get_args(const struct pwm_device *pwm, in pwm_get_args() argument
143 *args = pwm->args; in pwm_get_args()
148 * @pwm: PWM device
149 * @state: state to fill with the prepared PWM state
152 * to the PWM device with pwm_apply_might_sleep(). This is a convenient function
153 * that first retrieves the current PWM state and the replaces the period
154 * and polarity fields with the reference values defined in pwm->args.
163 static inline void pwm_init_state(const struct pwm_device *pwm, in pwm_init_state() argument
169 pwm_get_state(pwm, state); in pwm_init_state()
172 pwm_get_args(pwm, &args); in pwm_init_state()
182 * @state: PWM state to extract the duty cycle from
190 * pwm_get_state(pwm, &state);
205 * @state: PWM state to fill
214 * pwm_init_state(pwm, &state);
216 * pwm_apply_might_sleep(pwm, &state);
236 * struct pwm_capture - PWM capture data
237 * @period: period of the PWM signal (in nanoseconds)
238 * @duty_cycle: duty cycle of the PWM signal (in nanoseconds)
246 * struct pwm_ops - PWM controller operations
247 * @request: optional hook for requesting a PWM
248 * @free: optional hook for freeing a PWM
249 * @capture: capture and report PWM signal
250 * @apply: atomically apply a new PWM config
251 * @get_state: get the current PWM state. This function is only
252 * called once per PWM device when the PWM chip is
256 int (*request)(struct pwm_chip *chip, struct pwm_device *pwm);
257 void (*free)(struct pwm_chip *chip, struct pwm_device *pwm);
258 int (*capture)(struct pwm_chip *chip, struct pwm_device *pwm,
260 int (*apply)(struct pwm_chip *chip, struct pwm_device *pwm,
262 int (*get_state)(struct pwm_chip *chip, struct pwm_device *pwm,
267 * struct pwm_chip - abstract a PWM controller
269 * @ops: callbacks for this PWM controller
271 * @id: unique number of this PWM chip
273 * @of_xlate: request a PWM device given a device tree PWM specifier
274 * @of_pwm_n_cells: number of cells expected in the device tree PWM specifier
276 * @pwms: array of PWM devices allocated by the framework
290 /* only used internally by the PWM framework */
295 /* PWM user APIs */
296 int pwm_apply_might_sleep(struct pwm_device *pwm, const struct pwm_state *state);
297 int pwm_apply_atomic(struct pwm_device *pwm, const struct pwm_state *state);
298 int pwm_adjust_config(struct pwm_device *pwm);
301 * pwm_config() - change a PWM device configuration
302 * @pwm: PWM device
308 static inline int pwm_config(struct pwm_device *pwm, int duty_ns, in pwm_config() argument
313 if (!pwm) in pwm_config()
319 pwm_get_state(pwm, &state); in pwm_config()
325 return pwm_apply_might_sleep(pwm, &state); in pwm_config()
329 * pwm_enable() - start a PWM output toggling
330 * @pwm: PWM device
334 static inline int pwm_enable(struct pwm_device *pwm) in pwm_enable() argument
338 if (!pwm) in pwm_enable()
341 pwm_get_state(pwm, &state); in pwm_enable()
346 return pwm_apply_might_sleep(pwm, &state); in pwm_enable()
350 * pwm_disable() - stop a PWM output toggling
351 * @pwm: PWM device
353 static inline void pwm_disable(struct pwm_device *pwm) in pwm_disable() argument
357 if (!pwm) in pwm_disable()
360 pwm_get_state(pwm, &state); in pwm_disable()
365 pwm_apply_might_sleep(pwm, &state); in pwm_disable()
370 * @pwm: PWM device
374 static inline bool pwm_might_sleep(struct pwm_device *pwm) in pwm_might_sleep() argument
376 return !pwm->chip->atomic; in pwm_might_sleep()
379 /* PWM provider APIs */
380 int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result,
400 void pwm_put(struct pwm_device *pwm);
407 static inline bool pwm_might_sleep(struct pwm_device *pwm) in pwm_might_sleep() argument
412 static inline int pwm_apply_might_sleep(struct pwm_device *pwm, in pwm_apply_might_sleep() argument
419 static inline int pwm_apply_atomic(struct pwm_device *pwm, in pwm_apply_atomic() argument
425 static inline int pwm_adjust_config(struct pwm_device *pwm) in pwm_adjust_config() argument
430 static inline int pwm_config(struct pwm_device *pwm, int duty_ns, in pwm_config() argument
437 static inline int pwm_enable(struct pwm_device *pwm) in pwm_enable() argument
443 static inline void pwm_disable(struct pwm_device *pwm) in pwm_disable() argument
448 static inline int pwm_capture(struct pwm_device *pwm, in pwm_capture() argument
485 static inline void pwm_put(struct pwm_device *pwm) in pwm_put() argument
506 static inline void pwm_apply_args(struct pwm_device *pwm) in pwm_apply_args() argument
511 * PWM users calling pwm_apply_args() expect to have a fresh config in pwm_apply_args()
513 * The problem is, polarity can only be changed when the PWM is in pwm_apply_args()
516 * PWM drivers supporting hardware readout may declare the PWM device in pwm_apply_args()
518 * existing behavior, where all PWM devices are declared as disabled in pwm_apply_args()
523 * the PWM device and set the reference period and polarity config. in pwm_apply_args()
525 * Note that PWM users requiring a smooth handover between the in pwm_apply_args()
527 * PWM devices) will have to switch to the atomic API and avoid calling in pwm_apply_args()
532 state.polarity = pwm->args.polarity; in pwm_apply_args()
533 state.period = pwm->args.period; in pwm_apply_args()
536 pwm_apply_might_sleep(pwm, &state); in pwm_apply_args()
540 static inline int pwm_apply_state(struct pwm_device *pwm, in pwm_apply_state() argument
543 return pwm_apply_might_sleep(pwm, state); in pwm_apply_state()