Lines Matching full:pwm
11 MODULE_IMPORT_NS("PWM");
16 * enum pwm_polarity - polarity of a PWM signal
30 * struct pwm_args - board-dependent PWM arguments
34 * This structure describes board-dependent arguments attached to a PWM
35 * device. These arguments are usually retrieved from the PWM lookup table or
38 * Do not confuse this with the PWM state: PWM arguments represent the initial
39 * configuration that users want to use on this PWM device rather than the
40 * current PWM hardware state.
53 * struct pwm_waveform - description of a PWM waveform
54 * @period_length_ns: PWM period
55 * @duty_length_ns: PWM duty cycle
58 * This is a representation of a PWM waveform alternative to struct pwm_state
64 * Note there is no explicit bool for enabled. A "disabled" PWM is represented
65 * by .period_length_ns = 0. Note further that the behaviour of a "disabled" PWM
78 * struct pwm_state - state of a PWM channel
79 * @period: PWM period (in nanoseconds)
80 * @duty_cycle: PWM duty cycle (in nanoseconds)
81 * @polarity: PWM polarity
82 * @enabled: PWM enabled status
83 * @usage_power: If set, the PWM driver is only required to maintain the power
97 * struct pwm_device - PWM channel object
98 * @label: name of the PWM device
99 * @flags: flags associated with the PWM device
100 * @hwpwm: per-chip relative index of the PWM device
101 * @chip: PWM chip providing this PWM device
102 * @args: PWM arguments
118 * pwm_get_state() - retrieve the current PWM state
119 * @pwm: PWM device
120 * @state: state to fill with the current PWM state
122 * The returned PWM state represents the state that was applied by a previous call to
127 static inline void pwm_get_state(const struct pwm_device *pwm, in pwm_get_state() argument
130 *state = pwm->state; in pwm_get_state()
133 static inline bool pwm_is_enabled(const struct pwm_device *pwm) in pwm_is_enabled() argument
137 pwm_get_state(pwm, &state); in pwm_is_enabled()
142 static inline u64 pwm_get_period(const struct pwm_device *pwm) in pwm_get_period() argument
146 pwm_get_state(pwm, &state); in pwm_get_period()
151 static inline u64 pwm_get_duty_cycle(const struct pwm_device *pwm) in pwm_get_duty_cycle() argument
155 pwm_get_state(pwm, &state); in pwm_get_duty_cycle()
160 static inline enum pwm_polarity pwm_get_polarity(const struct pwm_device *pwm) in pwm_get_polarity() argument
164 pwm_get_state(pwm, &state); in pwm_get_polarity()
169 static inline void pwm_get_args(const struct pwm_device *pwm, in pwm_get_args() argument
172 *args = pwm->args; in pwm_get_args()
177 * @pwm: PWM device
178 * @state: state to fill with the prepared PWM state
181 * to the PWM device with pwm_apply_might_sleep(). This is a convenient function
182 * that first retrieves the current PWM state and the replaces the period
183 * and polarity fields with the reference values defined in pwm->args.
192 static inline void pwm_init_state(const struct pwm_device *pwm, in pwm_init_state() argument
198 pwm_get_state(pwm, state); in pwm_init_state()
201 pwm_get_args(pwm, &args); in pwm_init_state()
211 * @state: PWM state to extract the duty cycle from
219 * pwm_get_state(pwm, &state);
234 * @state: PWM state to fill
243 * pwm_init_state(pwm, &state);
245 * pwm_apply_might_sleep(pwm, &state);
265 * struct pwm_capture - PWM capture data
266 * @period: period of the PWM signal (in nanoseconds)
267 * @duty_cycle: duty cycle of the PWM signal (in nanoseconds)
275 * struct pwm_ops - PWM controller operations
276 * @request: optional hook for requesting a PWM
277 * @free: optional hook for freeing a PWM
278 * @capture: capture and report PWM signal
284 * @apply: atomically apply a new PWM config
285 * @get_state: get the current PWM state.
288 int (*request)(struct pwm_chip *chip, struct pwm_device *pwm);
289 void (*free)(struct pwm_chip *chip, struct pwm_device *pwm);
290 int (*capture)(struct pwm_chip *chip, struct pwm_device *pwm,
294 int (*round_waveform_tohw)(struct pwm_chip *chip, struct pwm_device *pwm,
296 int (*round_waveform_fromhw)(struct pwm_chip *chip, struct pwm_device *pwm,
298 int (*read_waveform)(struct pwm_chip *chip, struct pwm_device *pwm,
300 int (*write_waveform)(struct pwm_chip *chip, struct pwm_device *pwm,
303 int (*apply)(struct pwm_chip *chip, struct pwm_device *pwm,
305 int (*get_state)(struct pwm_chip *chip, struct pwm_device *pwm,
310 * struct pwm_chip - abstract a PWM controller
312 * @ops: callbacks for this PWM controller
314 * @id: unique number of this PWM chip
316 * @of_xlate: request a PWM device given a device tree PWM specifier
322 * @pwms: array of PWM devices allocated by the framework
335 /* only used internally by the PWM framework */
354 * Returns true iff the pwm chip support the waveform functions like
384 /* PWM consumer APIs */
385 int pwm_round_waveform_might_sleep(struct pwm_device *pwm, struct pwm_waveform *wf);
386 int pwm_get_waveform_might_sleep(struct pwm_device *pwm, struct pwm_waveform *wf);
387 int pwm_set_waveform_might_sleep(struct pwm_device *pwm, const struct pwm_waveform *wf, bool exact);
388 int pwm_apply_might_sleep(struct pwm_device *pwm, const struct pwm_state *state);
389 int pwm_apply_atomic(struct pwm_device *pwm, const struct pwm_state *state);
390 int pwm_get_state_hw(struct pwm_device *pwm, struct pwm_state *state);
391 int pwm_adjust_config(struct pwm_device *pwm);
394 * pwm_config() - change a PWM device configuration
395 * @pwm: PWM device
401 static inline int pwm_config(struct pwm_device *pwm, int duty_ns, in pwm_config() argument
406 if (!pwm) in pwm_config()
412 pwm_get_state(pwm, &state); in pwm_config()
418 return pwm_apply_might_sleep(pwm, &state); in pwm_config()
422 * pwm_enable() - start a PWM output toggling
423 * @pwm: PWM device
427 static inline int pwm_enable(struct pwm_device *pwm) in pwm_enable() argument
431 if (!pwm) in pwm_enable()
434 pwm_get_state(pwm, &state); in pwm_enable()
439 return pwm_apply_might_sleep(pwm, &state); in pwm_enable()
443 * pwm_disable() - stop a PWM output toggling
444 * @pwm: PWM device
446 static inline void pwm_disable(struct pwm_device *pwm) in pwm_disable() argument
450 if (!pwm) in pwm_disable()
453 pwm_get_state(pwm, &state); in pwm_disable()
458 pwm_apply_might_sleep(pwm, &state); in pwm_disable()
463 * @pwm: PWM device
467 static inline bool pwm_might_sleep(struct pwm_device *pwm) in pwm_might_sleep() argument
469 return !pwm->chip->atomic; in pwm_might_sleep()
472 /* PWM provider APIs */
490 void pwm_put(struct pwm_device *pwm);
497 static inline bool pwm_might_sleep(struct pwm_device *pwm) in pwm_might_sleep() argument
502 static inline int pwm_apply_might_sleep(struct pwm_device *pwm, in pwm_apply_might_sleep() argument
509 static inline int pwm_apply_atomic(struct pwm_device *pwm, in pwm_apply_atomic() argument
515 static inline int pwm_get_state_hw(struct pwm_device *pwm, struct pwm_state *state) in pwm_get_state_hw() argument
520 static inline int pwm_adjust_config(struct pwm_device *pwm) in pwm_adjust_config() argument
525 static inline int pwm_config(struct pwm_device *pwm, int duty_ns, in pwm_config() argument
532 static inline int pwm_enable(struct pwm_device *pwm) in pwm_enable() argument
538 static inline void pwm_disable(struct pwm_device *pwm) in pwm_disable() argument
583 static inline void pwm_put(struct pwm_device *pwm) in pwm_put() argument
604 static inline void pwm_apply_args(struct pwm_device *pwm) in pwm_apply_args() argument
609 * PWM users calling pwm_apply_args() expect to have a fresh config in pwm_apply_args()
611 * The problem is, polarity can only be changed when the PWM is in pwm_apply_args()
614 * PWM drivers supporting hardware readout may declare the PWM device in pwm_apply_args()
616 * existing behavior, where all PWM devices are declared as disabled in pwm_apply_args()
621 * the PWM device and set the reference period and polarity config. in pwm_apply_args()
623 * Note that PWM users requiring a smooth handover between the in pwm_apply_args()
625 * PWM devices) will have to switch to the atomic API and avoid calling in pwm_apply_args()
630 state.polarity = pwm->args.polarity; in pwm_apply_args()
631 state.period = pwm->args.period; in pwm_apply_args()
634 pwm_apply_might_sleep(pwm, &state); in pwm_apply_args()