Lines Matching +full:chip +full:- +full:relative
1 /* SPDX-License-Identifier: GPL-2.0 */
16 * enum pwm_polarity - polarity of a PWM signal
17 * @PWM_POLARITY_NORMAL: a high signal for the duration of the duty-
20 * @PWM_POLARITY_INVERSED: a low signal for the duration of the duty-
30 * struct pwm_args - board-dependent PWM arguments
34 * This structure describes board-dependent arguments attached to a PWM
53 * struct pwm_waveform - description of a PWM waveform
61 * PWM_POLARITY_NORMAL) and period - duty_cycle (.polarity =
67 * active or inactive level, go high-z or even continue to toggle.
78 * struct pwm_state - state of a PWM channel
97 * struct pwm_device - PWM channel object
100 * @hwpwm: per-chip relative index of the PWM device
101 * @chip: PWM chip providing this PWM device
110 struct pwm_chip *chip; member
118 * pwm_get_state() - retrieve the current PWM state
130 *state = pwm->state; in pwm_get_state()
172 *args = pwm->args; in pwm_get_args()
176 * pwm_init_state() - prepare a new state to be applied with pwm_apply_might_sleep()
183 * and polarity fields with the reference values defined in pwm->args.
184 * Once the function returns, you can adjust the ->enabled and ->duty_cycle
187 * ->duty_cycle is initially set to zero to avoid cases where the current
188 * ->duty_cycle value exceed the pwm_args->period one, which would trigger
189 * an error if the user calls pwm_apply_might_sleep() without adjusting ->duty_cycle
203 state->period = args.period; in pwm_init_state()
204 state->polarity = args.polarity; in pwm_init_state()
205 state->duty_cycle = 0; in pwm_init_state()
206 state->usage_power = false; in pwm_init_state()
210 * pwm_get_relative_duty_cycle() - Get a relative duty cycle value
212 * @scale: target scale of the relative duty cycle
215 * in nanosecond) into a value relative to the period.
225 if (!state->period) in pwm_get_relative_duty_cycle()
228 return DIV_ROUND_CLOSEST_ULL((u64)state->duty_cycle * scale, in pwm_get_relative_duty_cycle()
229 state->period); in pwm_get_relative_duty_cycle()
233 * pwm_set_relative_duty_cycle() - Set a relative duty cycle value
235 * @duty_cycle: relative duty cycle value
238 * This functions converts a relative into an absolute duty cycle (expressed
239 * in nanoseconds), and puts the result in state->duty_cycle.
247 * This functions returns -EINVAL if @duty_cycle and/or @scale are
255 return -EINVAL; in pwm_set_relative_duty_cycle()
257 state->duty_cycle = DIV_ROUND_CLOSEST_ULL((u64)duty_cycle * in pwm_set_relative_duty_cycle()
258 state->period, in pwm_set_relative_duty_cycle()
265 * struct pwm_capture - PWM capture data
275 * struct pwm_ops - PWM controller operations
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
313 * @owner: module providing this chip
314 * @id: unique number of this PWM chip
315 * @npwm: number of PWMs controlled by this chip
317 * @atomic: can the driver's ->apply() be called in atomic context
318 * @uses_pwmchip_alloc: signals if pwmchip_allow was used to allocate this chip
319 * @operational: signals if the chip can be used (or is already deregistered)
331 struct pwm_device * (*of_xlate)(struct pwm_chip *chip,
340 * depending on the chip being atomic or not either the mutex or
351 * pwmchip_supports_waveform() - checks if the given chip supports waveform callbacks
352 * @chip: The pwm_chip to test
354 * Returns true iff the pwm chip support the waveform functions like
357 static inline bool pwmchip_supports_waveform(struct pwm_chip *chip) in pwmchip_supports_waveform() argument
364 return chip->ops->write_waveform != NULL; in pwmchip_supports_waveform()
367 static inline struct device *pwmchip_parent(const struct pwm_chip *chip) in pwmchip_parent() argument
369 return chip->dev.parent; in pwmchip_parent()
372 static inline void *pwmchip_get_drvdata(struct pwm_chip *chip) in pwmchip_get_drvdata() argument
374 return dev_get_drvdata(&chip->dev); in pwmchip_get_drvdata()
377 static inline void pwmchip_set_drvdata(struct pwm_chip *chip, void *data) in pwmchip_set_drvdata() argument
379 dev_set_drvdata(&chip->dev, data); in pwmchip_set_drvdata()
394 * pwm_config() - change a PWM device configuration
407 return -EINVAL; in pwm_config()
410 return -EINVAL; in pwm_config()
422 * pwm_enable() - start a PWM output toggling
432 return -EINVAL; in pwm_enable()
443 * pwm_disable() - stop a PWM output toggling
462 * pwm_might_sleep() - is pwm_apply_atomic() supported?
469 return !pwm->chip->atomic; in pwm_might_sleep()
473 void pwmchip_put(struct pwm_chip *chip);
477 int __pwmchip_add(struct pwm_chip *chip, struct module *owner);
478 #define pwmchip_add(chip) __pwmchip_add(chip, THIS_MODULE) argument
479 void pwmchip_remove(struct pwm_chip *chip);
481 int __devm_pwmchip_add(struct device *dev, struct pwm_chip *chip, struct module *owner);
482 #define devm_pwmchip_add(dev, chip) __devm_pwmchip_add(dev, chip, THIS_MODULE) argument
484 struct pwm_device *of_pwm_xlate_with_flags(struct pwm_chip *chip,
486 struct pwm_device *of_pwm_single_xlate(struct pwm_chip *chip,
506 return -EOPNOTSUPP; in pwm_apply_might_sleep()
512 return -EOPNOTSUPP; in pwm_apply_atomic()
517 return -EOPNOTSUPP; in pwm_get_state_hw()
522 return -EOPNOTSUPP; in pwm_adjust_config()
529 return -EINVAL; in pwm_config()
535 return -EINVAL; in pwm_enable()
543 static inline void pwmchip_put(struct pwm_chip *chip) in pwmchip_put() argument
551 return ERR_PTR(-EINVAL); in pwmchip_alloc()
561 static inline int pwmchip_add(struct pwm_chip *chip) in pwmchip_add() argument
563 return -EINVAL; in pwmchip_add()
566 static inline int pwmchip_remove(struct pwm_chip *chip) in pwmchip_remove() argument
568 return -EINVAL; in pwmchip_remove()
571 static inline int devm_pwmchip_add(struct device *dev, struct pwm_chip *chip) in devm_pwmchip_add() argument
573 return -EINVAL; in devm_pwmchip_add()
580 return ERR_PTR(-ENODEV); in pwm_get()
592 return ERR_PTR(-ENODEV); in devm_pwm_get()
600 return ERR_PTR(-ENODEV); in devm_fwnode_pwm_get()
630 state.polarity = pwm->args.polarity; in pwm_apply_args()
631 state.period = pwm->args.period; in pwm_apply_args()