Lines Matching refs:pwm
23 #include <linux/pwm.h>
33 #include <dt-bindings/pwm/pwm.h>
44 static struct pwm_device *pwm_to_device(unsigned int pwm)
46 return radix_tree_lookup(&pwm_tree, pwm);
49 static int alloc_pwms(int pwm, unsigned int count)
54 if (pwm >= MAX_PWMS)
57 if (pwm >= 0)
58 from = pwm;
63 if (pwm >= 0 && start != pwm)
77 struct pwm_device *pwm = &chip->pwms[i];
78 radix_tree_delete(&pwm_tree, pwm->pwm);
110 static int pwm_device_request(struct pwm_device *pwm, const char *label)
114 if (test_bit(PWMF_REQUESTED, &pwm->flags))
117 if (!try_module_get(pwm->chip->ops->owner))
120 if (pwm->chip->ops->request) {
121 err = pwm->chip->ops->request(pwm->chip, pwm);
123 module_put(pwm->chip->ops->owner);
128 set_bit(PWMF_REQUESTED, &pwm->flags);
129 pwm->label = label;
137 struct pwm_device *pwm;
145 pwm = pwm_request_from_chip(pc, args->args[0], NULL);
146 if (IS_ERR(pwm))
147 return pwm;
149 pwm_set_period(pwm, args->args[1]);
152 pwm_set_polarity(pwm, PWM_POLARITY_INVERSED);
154 pwm_set_polarity(pwm, PWM_POLARITY_NORMAL);
156 return pwm;
163 struct pwm_device *pwm;
171 pwm = pwm_request_from_chip(pc, args->args[0], NULL);
172 if (IS_ERR(pwm))
173 return pwm;
175 pwm_set_period(pwm, args->args[1]);
177 return pwm;
201 * @pwm: PWM device
204 int pwm_set_chip_data(struct pwm_device *pwm, void *data)
206 if (!pwm)
209 pwm->chip_data = data;
217 * @pwm: PWM device
219 void *pwm_get_chip_data(struct pwm_device *pwm)
221 return pwm ? pwm->chip_data : NULL;
234 struct pwm_device *pwm;
248 chip->pwms = kzalloc(chip->npwm * sizeof(*pwm), GFP_KERNEL);
257 pwm = &chip->pwms[i];
259 pwm->chip = chip;
260 pwm->pwm = chip->base + i;
261 pwm->hwpwm = i;
263 radix_tree_insert(&pwm_tree, pwm->pwm, pwm);
299 struct pwm_device *pwm = &chip->pwms[i];
301 if (test_bit(PWMF_REQUESTED, &pwm->flags)) {
329 struct pwm_device *pwm_request(int pwm, const char *label)
334 if (pwm < 0 || pwm >= MAX_PWMS)
339 dev = pwm_to_device(pwm);
370 struct pwm_device *pwm;
377 pwm = &chip->pwms[index];
379 err = pwm_device_request(pwm, label);
381 pwm = ERR_PTR(err);
384 return pwm;
390 * @pwm: PWM device
394 void pwm_free(struct pwm_device *pwm)
396 pwm_put(pwm);
402 * @pwm: PWM device
406 int pwm_config(struct pwm_device *pwm, int duty_ns, int period_ns)
410 if (!pwm || duty_ns < 0 || period_ns <= 0 || duty_ns > period_ns)
413 err = pwm->chip->ops->config(pwm->chip, pwm, duty_ns, period_ns);
417 pwm->duty_cycle = duty_ns;
418 pwm->period = period_ns;
426 * @pwm: PWM device
431 int pwm_set_polarity(struct pwm_device *pwm, enum pwm_polarity polarity)
435 if (!pwm || !pwm->chip->ops)
438 if (!pwm->chip->ops->set_polarity)
441 if (test_bit(PWMF_ENABLED, &pwm->flags))
444 err = pwm->chip->ops->set_polarity(pwm->chip, pwm, polarity);
448 pwm->polarity = polarity;
456 * @pwm: PWM device
458 int pwm_enable(struct pwm_device *pwm)
460 if (pwm && !test_and_set_bit(PWMF_ENABLED, &pwm->flags))
461 return pwm->chip->ops->enable(pwm->chip, pwm);
463 return pwm ? 0 : -EINVAL;
469 * @pwm: PWM device
471 void pwm_disable(struct pwm_device *pwm)
473 if (pwm && test_and_clear_bit(PWMF_ENABLED, &pwm->flags))
474 pwm->chip->ops->disable(pwm->chip, pwm);
506 * be requested. Otherwise the "pwm-names" property is used to do a reverse
507 * lookup of the PWM index. This also means that the "pwm-names" property
513 struct pwm_device *pwm = NULL;
520 index = of_property_match_string(np, "pwm-names", con_id);
525 err = of_parse_phandle_with_args(np, "pwms", "#pwm-cells", index,
535 pwm = ERR_CAST(pc);
540 pr_debug("%s: wrong #pwm-cells for %s\n", np->full_name,
542 pwm = ERR_PTR(-EINVAL);
546 pwm = pc->of_xlate(pc, &args);
547 if (IS_ERR(pwm))
552 * "pwm-names" property if it exists. Otherwise use the name of
556 err = of_property_read_string_index(np, "pwm-names", index,
562 pwm->label = con_id;
567 return pwm;
602 struct pwm_device *pwm = ERR_PTR(-EPROBE_DEFER);
669 pwm = pwm_request_from_chip(chip, chosen->index, con_id ?: dev_id);
670 if (IS_ERR(pwm))
673 pwm_set_period(pwm, chosen->period);
674 pwm_set_polarity(pwm, chosen->polarity);
678 return pwm;
684 * @pwm: PWM device
686 void pwm_put(struct pwm_device *pwm)
688 if (!pwm)
693 if (!test_and_clear_bit(PWMF_REQUESTED, &pwm->flags)) {
698 if (pwm->chip->ops->free)
699 pwm->chip->ops->free(pwm->chip, pwm);
701 pwm->label = NULL;
703 module_put(pwm->chip->ops->owner);
724 struct pwm_device **ptr, *pwm;
730 pwm = pwm_get(dev, con_id);
731 if (!IS_ERR(pwm)) {
732 *ptr = pwm;
738 return pwm;
754 struct pwm_device **ptr, *pwm;
760 pwm = of_pwm_get(np, con_id);
761 if (!IS_ERR(pwm)) {
762 *ptr = pwm;
768 return pwm;
785 * @pwm: PWM device
791 void devm_pwm_put(struct device *dev, struct pwm_device *pwm)
793 WARN_ON(devres_release(dev, devm_pwm_release, devm_pwm_match, pwm));
799 * @pwm: PWM device
803 bool pwm_can_sleep(struct pwm_device *pwm)
805 return pwm->chip->can_sleep;
815 struct pwm_device *pwm = &chip->pwms[i];
817 seq_printf(s, " pwm-%-3d (%-20.20s):", i, pwm->label);
819 if (test_bit(PWMF_REQUESTED, &pwm->flags))
822 if (test_bit(PWMF_ENABLED, &pwm->flags))
888 debugfs_create_file("pwm", S_IFREG | S_IRUGO, NULL, NULL,