• Home
  • Raw
  • Download

Lines Matching full:pwm

23 #include <linux/pwm.h>
33 #include <dt-bindings/pwm/pwm.h>
44 static struct pwm_device *pwm_to_device(unsigned int pwm) in pwm_to_device() argument
46 return radix_tree_lookup(&pwm_tree, pwm); in pwm_to_device()
49 static int alloc_pwms(int pwm, unsigned int count) in alloc_pwms() argument
54 if (pwm >= MAX_PWMS) in alloc_pwms()
57 if (pwm >= 0) in alloc_pwms()
58 from = pwm; in alloc_pwms()
63 if (pwm >= 0 && start != pwm) in alloc_pwms()
77 struct pwm_device *pwm = &chip->pwms[i]; in free_pwms() local
79 radix_tree_delete(&pwm_tree, pwm->pwm); in free_pwms()
111 static int pwm_device_request(struct pwm_device *pwm, const char *label) in pwm_device_request() argument
115 if (test_bit(PWMF_REQUESTED, &pwm->flags)) in pwm_device_request()
118 if (!try_module_get(pwm->chip->ops->owner)) in pwm_device_request()
121 if (pwm->chip->ops->request) { in pwm_device_request()
122 err = pwm->chip->ops->request(pwm->chip, pwm); in pwm_device_request()
124 module_put(pwm->chip->ops->owner); in pwm_device_request()
129 set_bit(PWMF_REQUESTED, &pwm->flags); in pwm_device_request()
130 pwm->label = label; in pwm_device_request()
138 struct pwm_device *pwm; in of_pwm_xlate_with_flags() local
151 pwm = pwm_request_from_chip(pc, args->args[0], NULL); in of_pwm_xlate_with_flags()
152 if (IS_ERR(pwm)) in of_pwm_xlate_with_flags()
153 return pwm; in of_pwm_xlate_with_flags()
155 pwm->args.period = args->args[1]; in of_pwm_xlate_with_flags()
156 pwm->args.polarity = PWM_POLARITY_NORMAL; in of_pwm_xlate_with_flags()
159 pwm->args.polarity = PWM_POLARITY_INVERSED; in of_pwm_xlate_with_flags()
161 return pwm; in of_pwm_xlate_with_flags()
168 struct pwm_device *pwm; in of_pwm_simple_xlate() local
181 pwm = pwm_request_from_chip(pc, args->args[0], NULL); in of_pwm_simple_xlate()
182 if (IS_ERR(pwm)) in of_pwm_simple_xlate()
183 return pwm; in of_pwm_simple_xlate()
185 pwm->args.period = args->args[1]; in of_pwm_simple_xlate()
187 return pwm; in of_pwm_simple_xlate()
210 * pwm_set_chip_data() - set private chip data for a PWM
211 * @pwm: PWM device
216 int pwm_set_chip_data(struct pwm_device *pwm, void *data) in pwm_set_chip_data() argument
218 if (!pwm) in pwm_set_chip_data()
221 pwm->chip_data = data; in pwm_set_chip_data()
228 * pwm_get_chip_data() - get private chip data for a PWM
229 * @pwm: PWM device
231 * Returns: A pointer to the chip-private data for the PWM device.
233 void *pwm_get_chip_data(struct pwm_device *pwm) in pwm_get_chip_data() argument
235 return pwm ? pwm->chip_data : NULL; in pwm_get_chip_data()
253 * pwmchip_add_with_polarity() - register a new PWM chip
254 * @chip: the PWM chip to add
255 * @polarity: initial polarity of PWM channels
257 * Register a new PWM chip. If chip->base < 0 then a dynamically assigned base
266 struct pwm_device *pwm; in pwmchip_add_with_polarity() local
282 chip->pwms = kcalloc(chip->npwm, sizeof(*pwm), GFP_KERNEL); in pwmchip_add_with_polarity()
291 pwm = &chip->pwms[i]; in pwmchip_add_with_polarity()
293 pwm->chip = chip; in pwmchip_add_with_polarity()
294 pwm->pwm = chip->base + i; in pwmchip_add_with_polarity()
295 pwm->hwpwm = i; in pwmchip_add_with_polarity()
296 pwm->state.polarity = polarity; in pwmchip_add_with_polarity()
299 chip->ops->get_state(chip, pwm, &pwm->state); in pwmchip_add_with_polarity()
301 radix_tree_insert(&pwm_tree, pwm->pwm, pwm); in pwmchip_add_with_polarity()
325 * pwmchip_add() - register a new PWM chip
326 * @chip: the PWM chip to add
328 * Register a new PWM chip. If chip->base < 0 then a dynamically assigned base
340 * pwmchip_remove() - remove a PWM chip
341 * @chip: the PWM chip to remove
343 * Removes a PWM chip. This function may return busy if the PWM chip provides
344 * a PWM device that is still requested.
358 struct pwm_device *pwm = &chip->pwms[i]; in pwmchip_remove() local
360 if (test_bit(PWMF_REQUESTED, &pwm->flags)) { in pwmchip_remove()
380 * pwm_request() - request a PWM device
381 * @pwm: global PWM device index
382 * @label: PWM device label
386 * Returns: A pointer to a PWM device or an ERR_PTR()-encoded error code on
389 struct pwm_device *pwm_request(int pwm, const char *label) in pwm_request() argument
394 if (pwm < 0 || pwm >= MAX_PWMS) in pwm_request()
399 dev = pwm_to_device(pwm); in pwm_request()
417 * pwm_request_from_chip() - request a PWM device relative to a PWM chip
418 * @chip: PWM chip
419 * @index: per-chip index of the PWM to request
420 * @label: a literal description string of this PWM
422 * Returns: A pointer to the PWM device at the given index of the given PWM
424 * specified PWM chip or if the PWM device cannot be requested.
430 struct pwm_device *pwm; in pwm_request_from_chip() local
437 pwm = &chip->pwms[index]; in pwm_request_from_chip()
439 err = pwm_device_request(pwm, label); in pwm_request_from_chip()
441 pwm = ERR_PTR(err); in pwm_request_from_chip()
444 return pwm; in pwm_request_from_chip()
449 * pwm_free() - free a PWM device
450 * @pwm: PWM device
454 void pwm_free(struct pwm_device *pwm) in pwm_free() argument
456 pwm_put(pwm); in pwm_free()
461 * pwm_apply_state() - atomically apply a new state to a PWM device
462 * @pwm: PWM device
463 * @state: new state to apply. This can be adjusted by the PWM driver
467 int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state) in pwm_apply_state() argument
471 if (!pwm || !state || !state->period || in pwm_apply_state()
475 if (!memcmp(state, &pwm->state, sizeof(*state))) in pwm_apply_state()
478 if (pwm->chip->ops->apply) { in pwm_apply_state()
479 err = pwm->chip->ops->apply(pwm->chip, pwm, state); in pwm_apply_state()
483 pwm->state = *state; in pwm_apply_state()
488 if (state->polarity != pwm->state.polarity) { in pwm_apply_state()
489 if (!pwm->chip->ops->set_polarity) in pwm_apply_state()
493 * Changing the polarity of a running PWM is in pwm_apply_state()
494 * only allowed when the PWM driver implements in pwm_apply_state()
497 if (pwm->state.enabled) { in pwm_apply_state()
498 pwm->chip->ops->disable(pwm->chip, pwm); in pwm_apply_state()
499 pwm->state.enabled = false; in pwm_apply_state()
502 err = pwm->chip->ops->set_polarity(pwm->chip, pwm, in pwm_apply_state()
507 pwm->state.polarity = state->polarity; in pwm_apply_state()
510 if (state->period != pwm->state.period || in pwm_apply_state()
511 state->duty_cycle != pwm->state.duty_cycle) { in pwm_apply_state()
512 err = pwm->chip->ops->config(pwm->chip, pwm, in pwm_apply_state()
518 pwm->state.duty_cycle = state->duty_cycle; in pwm_apply_state()
519 pwm->state.period = state->period; in pwm_apply_state()
522 if (state->enabled != pwm->state.enabled) { in pwm_apply_state()
524 err = pwm->chip->ops->enable(pwm->chip, pwm); in pwm_apply_state()
528 pwm->chip->ops->disable(pwm->chip, pwm); in pwm_apply_state()
531 pwm->state.enabled = state->enabled; in pwm_apply_state()
540 * pwm_capture() - capture and report a PWM signal
541 * @pwm: PWM device
547 int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result, in pwm_capture() argument
552 if (!pwm || !pwm->chip->ops) in pwm_capture()
555 if (!pwm->chip->ops->capture) in pwm_capture()
559 err = pwm->chip->ops->capture(pwm->chip, pwm, result, timeout); in pwm_capture()
567 * pwm_adjust_config() - adjust the current PWM config to the PWM arguments
568 * @pwm: PWM device
570 * This function will adjust the PWM config to the PWM arguments provided
571 * by the DT or PWM lookup table. This is particularly useful to adapt
574 int pwm_adjust_config(struct pwm_device *pwm) in pwm_adjust_config() argument
579 pwm_get_args(pwm, &pargs); in pwm_adjust_config()
580 pwm_get_state(pwm, &state); in pwm_adjust_config()
583 * If the current period is zero it means that either the PWM driver in pwm_adjust_config()
584 * does not support initial state retrieval or the PWM has not yet in pwm_adjust_config()
595 return pwm_apply_state(pwm, &state); in pwm_adjust_config()
599 * Adjust the PWM duty cycle/period based on the period value provided in pwm_adjust_config()
600 * in PWM args. in pwm_adjust_config()
618 return pwm_apply_state(pwm, &state); in pwm_adjust_config()
640 * of_pwm_get() - request a PWM via the PWM framework
641 * @np: device node to get the PWM from
644 * Returns the PWM device parsed from the phandle and index specified in the
646 * Values parsed from the device tree are stored in the returned PWM device
649 * If con_id is NULL, the first PWM device listed in the "pwms" property will
650 * be requested. Otherwise the "pwm-names" property is used to do a reverse
651 * lookup of the PWM index. This also means that the "pwm-names" property
652 * becomes mandatory for devices that look up the PWM device via the con_id
655 * Returns: A pointer to the requested PWM device or an ERR_PTR()-encoded
660 struct pwm_device *pwm = NULL; in of_pwm_get() local
667 index = of_property_match_string(np, "pwm-names", con_id); in of_pwm_get()
672 err = of_parse_phandle_with_args(np, "pwms", "#pwm-cells", index, in of_pwm_get()
682 pr_err("%s(): PWM chip not found\n", __func__); in of_pwm_get()
684 pwm = ERR_CAST(pc); in of_pwm_get()
688 pwm = pc->of_xlate(pc, &args); in of_pwm_get()
689 if (IS_ERR(pwm)) in of_pwm_get()
694 * "pwm-names" property if it exists. Otherwise use the name of in of_pwm_get()
698 err = of_property_read_string_index(np, "pwm-names", index, in of_pwm_get()
704 pwm->label = con_id; in of_pwm_get()
709 return pwm; in of_pwm_get()
714 * pwm_add_table() - register PWM device consumers
731 * pwm_remove_table() - unregister PWM device consumers
748 * pwm_get() - look up and request a PWM device
749 * @dev: device for PWM consumer
753 * a device tree, a PWM chip and a relative index is looked up via a table
756 * Once a PWM chip has been found the specified PWM device will be requested
759 * Returns: A pointer to the requested PWM device or an ERR_PTR()-encoded
765 struct pwm_device *pwm; in pwm_get() local
783 * If a match is found, the provider PWM chip is looked up by name in pwm_get()
784 * and a PWM device is requested using the PWM device per-chip index. in pwm_get()
834 * the PWM chip lookup. This can be used to work around driver load in pwm_get()
847 pwm = pwm_request_from_chip(chip, chosen->index, con_id ?: dev_id); in pwm_get()
848 if (IS_ERR(pwm)) in pwm_get()
849 return pwm; in pwm_get()
851 pwm->args.period = chosen->period; in pwm_get()
852 pwm->args.polarity = chosen->polarity; in pwm_get()
854 return pwm; in pwm_get()
859 * pwm_put() - release a PWM device
860 * @pwm: PWM device
862 void pwm_put(struct pwm_device *pwm) in pwm_put() argument
864 if (!pwm) in pwm_put()
869 if (!test_and_clear_bit(PWMF_REQUESTED, &pwm->flags)) { in pwm_put()
870 pr_warn("PWM device already freed\n"); in pwm_put()
874 if (pwm->chip->ops->free) in pwm_put()
875 pwm->chip->ops->free(pwm->chip, pwm); in pwm_put()
877 pwm_set_chip_data(pwm, NULL); in pwm_put()
878 pwm->label = NULL; in pwm_put()
880 module_put(pwm->chip->ops->owner); in pwm_put()
893 * @dev: device for PWM consumer
896 * This function performs like pwm_get() but the acquired PWM device will
899 * Returns: A pointer to the requested PWM device or an ERR_PTR()-encoded
904 struct pwm_device **ptr, *pwm; in devm_pwm_get() local
910 pwm = pwm_get(dev, con_id); in devm_pwm_get()
911 if (!IS_ERR(pwm)) { in devm_pwm_get()
912 *ptr = pwm; in devm_pwm_get()
918 return pwm; in devm_pwm_get()
924 * @dev: device for PWM consumer
925 * @np: device node to get the PWM from
928 * This function performs like of_pwm_get() but the acquired PWM device will
931 * Returns: A pointer to the requested PWM device or an ERR_PTR()-encoded
937 struct pwm_device **ptr, *pwm; in devm_of_pwm_get() local
943 pwm = of_pwm_get(np, con_id); in devm_of_pwm_get()
944 if (!IS_ERR(pwm)) { in devm_of_pwm_get()
945 *ptr = pwm; in devm_of_pwm_get()
951 return pwm; in devm_of_pwm_get()
967 * @dev: device for PWM consumer
968 * @pwm: PWM device
970 * Release a PWM previously allocated using devm_pwm_get(). Calling this
974 void devm_pwm_put(struct device *dev, struct pwm_device *pwm) in devm_pwm_put() argument
976 WARN_ON(devres_release(dev, devm_pwm_release, devm_pwm_match, pwm)); in devm_pwm_put()
986 struct pwm_device *pwm = &chip->pwms[i]; in pwm_dbg_show() local
989 pwm_get_state(pwm, &state); in pwm_dbg_show()
991 seq_printf(s, " pwm-%-3d (%-20.20s):", i, pwm->label); in pwm_dbg_show()
993 if (test_bit(PWMF_REQUESTED, &pwm->flags)) in pwm_dbg_show()
1032 seq_printf(s, "%s%s/%s, %d PWM device%s\n", (char *)s->private, in pwm_seq_show()
1067 debugfs_create_file("pwm", S_IFREG | S_IRUGO, NULL, NULL, in pwm_debugfs_init()