Lines Matching +full:chip +full:- +full:relative
1 /* SPDX-License-Identifier: GPL-2.0 */
15 * enum pwm_polarity - polarity of a PWM signal
16 * @PWM_POLARITY_NORMAL: a high signal for the duration of the duty-
19 * @PWM_POLARITY_INVERSED: a low signal for the duration of the duty-
29 * struct pwm_args - board-dependent PWM arguments
33 * This structure describes board-dependent arguments attached to a PWM
52 * struct pwm_state - state of a PWM channel
66 * struct pwm_device - PWM channel object
69 * @hwpwm: per-chip relative index of the PWM device
71 * @chip: PWM chip providing this PWM device
72 * @chip_data: chip-private data associated with the PWM device
82 struct pwm_chip *chip; member
91 * pwm_get_state() - retrieve the current PWM state
98 *state = pwm->state; in pwm_get_state()
113 pwm->state.period = period; in pwm_set_period()
128 pwm->state.duty_cycle = duty; in pwm_set_duty_cycle()
152 *args = pwm->args; in pwm_get_args()
156 * pwm_init_state() - prepare a new state to be applied with pwm_apply_state()
163 * and polarity fields with the reference values defined in pwm->args.
164 * Once the function returns, you can adjust the ->enabled and ->duty_cycle
167 * ->duty_cycle is initially set to zero to avoid cases where the current
168 * ->duty_cycle value exceed the pwm_args->period one, which would trigger
169 * an error if the user calls pwm_apply_state() without adjusting ->duty_cycle
183 state->period = args.period; in pwm_init_state()
184 state->polarity = args.polarity; in pwm_init_state()
185 state->duty_cycle = 0; in pwm_init_state()
189 * pwm_get_relative_duty_cycle() - Get a relative duty cycle value
191 * @scale: target scale of the relative duty cycle
194 * in nanosecond) into a value relative to the period.
204 if (!state->period) in pwm_get_relative_duty_cycle()
207 return DIV_ROUND_CLOSEST_ULL((u64)state->duty_cycle * scale, in pwm_get_relative_duty_cycle()
208 state->period); in pwm_get_relative_duty_cycle()
212 * pwm_set_relative_duty_cycle() - Set a relative duty cycle value
214 * @duty_cycle: relative duty cycle value
217 * This functions converts a relative into an absolute duty cycle (expressed
218 * in nanoseconds), and puts the result in state->duty_cycle.
226 * This functions returns -EINVAL if @duty_cycle and/or @scale are
234 return -EINVAL; in pwm_set_relative_duty_cycle()
236 state->duty_cycle = DIV_ROUND_CLOSEST_ULL((u64)duty_cycle * in pwm_set_relative_duty_cycle()
237 state->period, in pwm_set_relative_duty_cycle()
244 * struct pwm_ops - PWM controller operations
250 * called once per PWM device when the PWM chip is
259 int (*request)(struct pwm_chip *chip, struct pwm_device *pwm);
260 void (*free)(struct pwm_chip *chip, struct pwm_device *pwm);
261 int (*capture)(struct pwm_chip *chip, struct pwm_device *pwm,
263 int (*apply)(struct pwm_chip *chip, struct pwm_device *pwm,
265 void (*get_state)(struct pwm_chip *chip, struct pwm_device *pwm,
270 int (*config)(struct pwm_chip *chip, struct pwm_device *pwm,
272 int (*set_polarity)(struct pwm_chip *chip, struct pwm_device *pwm,
274 int (*enable)(struct pwm_chip *chip, struct pwm_device *pwm);
275 void (*disable)(struct pwm_chip *chip, struct pwm_device *pwm);
279 * struct pwm_chip - abstract a PWM controller
282 * @base: number of first PWM controlled by this chip
283 * @npwm: number of PWMs controlled by this chip
305 * struct pwm_capture - PWM capture data
322 * pwm_config() - change a PWM device configuration
335 return -EINVAL; in pwm_config()
338 return -EINVAL; in pwm_config()
350 * pwm_enable() - start a PWM output toggling
360 return -EINVAL; in pwm_enable()
371 * pwm_disable() - stop a PWM output toggling
395 int pwmchip_add_with_polarity(struct pwm_chip *chip,
397 int pwmchip_add(struct pwm_chip *chip);
398 int pwmchip_remove(struct pwm_chip *chip);
399 struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip,
421 return ERR_PTR(-ENODEV); in pwm_request()
431 return -ENOTSUPP; in pwm_apply_state()
436 return -ENOTSUPP; in pwm_adjust_config()
442 return -EINVAL; in pwm_config()
449 return -EINVAL; in pwm_capture()
454 return -EINVAL; in pwm_enable()
463 return -EINVAL; in pwm_set_chip_data()
471 static inline int pwmchip_add(struct pwm_chip *chip) in pwmchip_add() argument
473 return -EINVAL; in pwmchip_add()
476 static inline int pwmchip_add_inversed(struct pwm_chip *chip) in pwmchip_add_inversed() argument
478 return -EINVAL; in pwmchip_add_inversed()
481 static inline int pwmchip_remove(struct pwm_chip *chip) in pwmchip_remove() argument
483 return -EINVAL; in pwmchip_remove()
486 static inline struct pwm_device *pwm_request_from_chip(struct pwm_chip *chip, in pwm_request_from_chip() argument
490 return ERR_PTR(-ENODEV); in pwm_request_from_chip()
496 return ERR_PTR(-ENODEV); in pwm_get()
503 return ERR_PTR(-ENODEV); in of_pwm_get()
513 return ERR_PTR(-ENODEV); in devm_pwm_get()
520 return ERR_PTR(-ENODEV); in devm_of_pwm_get()
527 return ERR_PTR(-ENODEV); in devm_fwnode_pwm_get()
561 state.polarity = pwm->args.polarity; in pwm_apply_args()
562 state.period = pwm->args.period; in pwm_apply_args()
608 void pwmchip_sysfs_export(struct pwm_chip *chip);
609 void pwmchip_sysfs_unexport(struct pwm_chip *chip);
611 static inline void pwmchip_sysfs_export(struct pwm_chip *chip) in pwmchip_sysfs_export() argument
615 static inline void pwmchip_sysfs_unexport(struct pwm_chip *chip) in pwmchip_sysfs_unexport() argument