Lines Matching +full:chip +full:- +full:relative
1 /* SPDX-License-Identifier: GPL-2.0 */
12 * enum pwm_polarity - polarity of a PWM signal
13 * @PWM_POLARITY_NORMAL: a high signal for the duration of the duty-
16 * @PWM_POLARITY_INVERSED: a low signal for the duration of the duty-
26 * struct pwm_args - board-dependent PWM arguments
30 * This structure describes board-dependent arguments attached to a PWM
49 * struct pwm_state - state of a PWM channel
68 * struct pwm_device - PWM channel object
71 * @hwpwm: per-chip relative index of the PWM device
72 * @chip: PWM chip providing this PWM device
81 struct pwm_chip *chip; member
89 * pwm_get_state() - retrieve the current PWM state
101 *state = pwm->state; in pwm_get_state()
143 *args = pwm->args; in pwm_get_args()
147 * pwm_init_state() - prepare a new state to be applied with pwm_apply_might_sleep()
154 * and polarity fields with the reference values defined in pwm->args.
155 * Once the function returns, you can adjust the ->enabled and ->duty_cycle
158 * ->duty_cycle is initially set to zero to avoid cases where the current
159 * ->duty_cycle value exceed the pwm_args->period one, which would trigger
160 * an error if the user calls pwm_apply_might_sleep() without adjusting ->duty_cycle
174 state->period = args.period; in pwm_init_state()
175 state->polarity = args.polarity; in pwm_init_state()
176 state->duty_cycle = 0; in pwm_init_state()
177 state->usage_power = false; in pwm_init_state()
181 * pwm_get_relative_duty_cycle() - Get a relative duty cycle value
183 * @scale: target scale of the relative duty cycle
186 * in nanosecond) into a value relative to the period.
196 if (!state->period) in pwm_get_relative_duty_cycle()
199 return DIV_ROUND_CLOSEST_ULL((u64)state->duty_cycle * scale, in pwm_get_relative_duty_cycle()
200 state->period); in pwm_get_relative_duty_cycle()
204 * pwm_set_relative_duty_cycle() - Set a relative duty cycle value
206 * @duty_cycle: relative duty cycle value
209 * This functions converts a relative into an absolute duty cycle (expressed
210 * in nanoseconds), and puts the result in state->duty_cycle.
218 * This functions returns -EINVAL if @duty_cycle and/or @scale are
226 return -EINVAL; in pwm_set_relative_duty_cycle()
228 state->duty_cycle = DIV_ROUND_CLOSEST_ULL((u64)duty_cycle * in pwm_set_relative_duty_cycle()
229 state->period, in pwm_set_relative_duty_cycle()
236 * struct pwm_capture - PWM capture data
246 * struct pwm_ops - PWM controller operations
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
270 * @owner: module providing this chip
271 * @id: unique number of this PWM chip
272 * @npwm: number of PWMs controlled by this chip
275 * @atomic: can the driver's ->apply() be called in atomic context
285 struct pwm_device * (*of_xlate)(struct pwm_chip *chip,
301 * pwm_config() - change a PWM device configuration
314 return -EINVAL; in pwm_config()
317 return -EINVAL; in pwm_config()
329 * pwm_enable() - start a PWM output toggling
339 return -EINVAL; in pwm_enable()
350 * pwm_disable() - stop a PWM output toggling
369 * pwm_might_sleep() - is pwm_apply_atomic() supported?
376 return !pwm->chip->atomic; in pwm_might_sleep()
383 int __pwmchip_add(struct pwm_chip *chip, struct module *owner);
384 #define pwmchip_add(chip) __pwmchip_add(chip, THIS_MODULE) argument
385 void pwmchip_remove(struct pwm_chip *chip);
387 int __devm_pwmchip_add(struct device *dev, struct pwm_chip *chip, struct module *owner);
388 #define devm_pwmchip_add(dev, chip) __devm_pwmchip_add(dev, chip, THIS_MODULE) argument
390 struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
394 struct pwm_device *of_pwm_xlate_with_flags(struct pwm_chip *chip,
396 struct pwm_device *of_pwm_single_xlate(struct pwm_chip *chip,
416 return -EOPNOTSUPP; in pwm_apply_might_sleep()
422 return -EOPNOTSUPP; in pwm_apply_atomic()
427 return -EOPNOTSUPP; in pwm_adjust_config()
434 return -EINVAL; in pwm_config()
440 return -EINVAL; in pwm_enable()
452 return -EINVAL; in pwm_capture()
455 static inline int pwmchip_add(struct pwm_chip *chip) in pwmchip_add() argument
457 return -EINVAL; in pwmchip_add()
460 static inline int pwmchip_remove(struct pwm_chip *chip) in pwmchip_remove() argument
462 return -EINVAL; in pwmchip_remove()
465 static inline int devm_pwmchip_add(struct device *dev, struct pwm_chip *chip) in devm_pwmchip_add() argument
467 return -EINVAL; in devm_pwmchip_add()
470 static inline struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip, in pwm_request_from_chip() argument
475 return ERR_PTR(-ENODEV); in pwm_request_from_chip()
482 return ERR_PTR(-ENODEV); in pwm_get()
494 return ERR_PTR(-ENODEV); in devm_pwm_get()
502 return ERR_PTR(-ENODEV); in devm_fwnode_pwm_get()
532 state.polarity = pwm->args.polarity; in pwm_apply_args()
533 state.period = pwm->args.period; in pwm_apply_args()
539 /* only for backwards-compatibility, new code should not use this */
587 void pwmchip_sysfs_export(struct pwm_chip *chip);
588 void pwmchip_sysfs_unexport(struct pwm_chip *chip);
590 static inline void pwmchip_sysfs_export(struct pwm_chip *chip) in pwmchip_sysfs_export() argument
594 static inline void pwmchip_sysfs_unexport(struct pwm_chip *chip) in pwmchip_sysfs_unexport() argument