Lines Matching refs:pwm

11 #include <linux/pwm.h>
21 #include <dt-bindings/pwm/pwm.h>
24 #include <trace/events/pwm.h>
35 static struct pwm_device *pwm_to_device(unsigned int pwm)
37 return radix_tree_lookup(&pwm_tree, pwm);
40 static int alloc_pwms(int pwm, unsigned int count)
45 if (pwm >= MAX_PWMS)
48 if (pwm >= 0)
49 from = pwm;
54 if (pwm >= 0 && start != pwm)
68 struct pwm_device *pwm = &chip->pwms[i];
70 radix_tree_delete(&pwm_tree, pwm->pwm);
102 static int pwm_device_request(struct pwm_device *pwm, const char *label)
106 if (test_bit(PWMF_REQUESTED, &pwm->flags))
109 if (!try_module_get(pwm->chip->ops->owner))
112 if (pwm->chip->ops->request) {
113 err = pwm->chip->ops->request(pwm->chip, pwm);
115 module_put(pwm->chip->ops->owner);
120 if (pwm->chip->ops->get_state) {
121 pwm->chip->ops->get_state(pwm->chip, pwm, &pwm->state);
122 trace_pwm_get(pwm, &pwm->state);
125 pwm->last = pwm->state;
128 set_bit(PWMF_REQUESTED, &pwm->flags);
129 pwm->label = label;
137 struct pwm_device *pwm;
150 pwm = pwm_request_from_chip(pc, args->args[0], NULL);
151 if (IS_ERR(pwm))
152 return pwm;
154 pwm->args.period = args->args[1];
155 pwm->args.polarity = PWM_POLARITY_NORMAL;
158 pwm->args.polarity = PWM_POLARITY_INVERSED;
160 return pwm;
167 struct pwm_device *pwm;
180 pwm = pwm_request_from_chip(pc, args->args[0], NULL);
181 if (IS_ERR(pwm))
182 return pwm;
184 pwm->args.period = args->args[1];
186 return pwm;
210 * @pwm: PWM device
215 int pwm_set_chip_data(struct pwm_device *pwm, void *data)
217 if (!pwm)
220 pwm->chip_data = data;
228 * @pwm: PWM device
232 void *pwm_get_chip_data(struct pwm_device *pwm)
234 return pwm ? pwm->chip_data : NULL;
276 struct pwm_device *pwm;
292 chip->pwms = kcalloc(chip->npwm, sizeof(*pwm), GFP_KERNEL);
301 pwm = &chip->pwms[i];
303 pwm->chip = chip;
304 pwm->pwm = chip->base + i;
305 pwm->hwpwm = i;
306 pwm->state.polarity = polarity;
308 radix_tree_insert(&pwm_tree, pwm->pwm, pwm);
365 struct pwm_device *pwm = &chip->pwms[i];
367 if (test_bit(PWMF_REQUESTED, &pwm->flags)) {
388 * @pwm: global PWM device index
396 struct pwm_device *pwm_request(int pwm, const char *label)
401 if (pwm < 0 || pwm >= MAX_PWMS)
406 dev = pwm_to_device(pwm);
437 struct pwm_device *pwm;
444 pwm = &chip->pwms[index];
446 err = pwm_device_request(pwm, label);
448 pwm = ERR_PTR(err);
451 return pwm;
457 * @pwm: PWM device
461 void pwm_free(struct pwm_device *pwm)
463 pwm_put(pwm);
467 static void pwm_apply_state_debug(struct pwm_device *pwm,
470 struct pwm_state *last = &pwm->last;
471 struct pwm_chip *chip = pwm->chip;
487 chip->ops->get_state(chip, pwm, &s1);
488 trace_pwm_get(pwm, &s1);
543 err = chip->ops->apply(chip, pwm, &s1);
550 trace_pwm_apply(pwm, &s1);
552 chip->ops->get_state(chip, pwm, last);
553 trace_pwm_get(pwm, last);
570 * @pwm: PWM device
573 int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
578 if (!pwm || !state || !state->period ||
582 chip = pwm->chip;
584 if (state->period == pwm->state.period &&
585 state->duty_cycle == pwm->state.duty_cycle &&
586 state->polarity == pwm->state.polarity &&
587 state->enabled == pwm->state.enabled)
591 err = chip->ops->apply(chip, pwm, state);
595 trace_pwm_apply(pwm, state);
597 pwm->state = *state;
600 * only do this after pwm->state was applied as some
603 pwm_apply_state_debug(pwm, state);
608 if (state->polarity != pwm->state.polarity) {
617 if (pwm->state.enabled) {
618 chip->ops->disable(chip, pwm);
619 pwm->state.enabled = false;
622 err = chip->ops->set_polarity(chip, pwm,
627 pwm->state.polarity = state->polarity;
630 if (state->period != pwm->state.period ||
631 state->duty_cycle != pwm->state.duty_cycle) {
632 err = chip->ops->config(pwm->chip, pwm,
638 pwm->state.duty_cycle = state->duty_cycle;
639 pwm->state.period = state->period;
642 if (state->enabled != pwm->state.enabled) {
644 err = chip->ops->enable(chip, pwm);
648 chip->ops->disable(chip, pwm);
651 pwm->state.enabled = state->enabled;
661 * @pwm: PWM device
667 int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result,
672 if (!pwm || !pwm->chip->ops)
675 if (!pwm->chip->ops->capture)
679 err = pwm->chip->ops->capture(pwm->chip, pwm, result, timeout);
688 * @pwm: PWM device
694 int pwm_adjust_config(struct pwm_device *pwm)
699 pwm_get_args(pwm, &pargs);
700 pwm_get_state(pwm, &state);
715 return pwm_apply_state(pwm, &state);
738 return pwm_apply_state(pwm, &state);
760 struct pwm_device *pwm)
770 dev_warn(pwm->chip->dev,
775 dl = device_link_add(dev, pwm->chip->dev, DL_FLAG_AUTOREMOVE_CONSUMER);
778 dev_name(pwm->chip->dev));
797 * be requested. Otherwise the "pwm-names" property is used to do a reverse
798 * lookup of the PWM index. This also means that the "pwm-names" property
808 struct pwm_device *pwm = NULL;
816 index = of_property_match_string(np, "pwm-names", con_id);
821 err = of_parse_phandle_with_args(np, "pwms", "#pwm-cells", index,
833 pwm = ERR_CAST(pc);
837 pwm = pc->of_xlate(pc, &args);
838 if (IS_ERR(pwm))
841 dl = pwm_device_link_add(dev, pwm);
844 pwm_free(pwm);
845 pwm = ERR_CAST(dl);
851 * "pwm-names" property if it exists. Otherwise use the name of
855 err = of_property_read_string_index(np, "pwm-names", index,
861 pwm->label = con_id;
866 return pwm;
894 * @fwnode: firmware node to get the "pwm" property from
911 struct pwm_device *pwm = ERR_PTR(-ENODEV);
935 pwm = pwm_request_from_chip(chip, args.args[0], NULL);
936 if (IS_ERR(pwm))
937 return pwm;
939 pwm->args.period = args.args[1];
940 pwm->args.polarity = PWM_POLARITY_NORMAL;
943 pwm->args.polarity = PWM_POLARITY_INVERSED;
946 return pwm;
1001 struct pwm_device *pwm;
1015 pwm = acpi_pwm_get(dev->fwnode);
1016 if (!IS_ERR(pwm) || PTR_ERR(pwm) != -ENOENT)
1017 return pwm;
1091 pwm = pwm_request_from_chip(chip, chosen->index, con_id ?: dev_id);
1092 if (IS_ERR(pwm))
1093 return pwm;
1095 dl = pwm_device_link_add(dev, pwm);
1097 pwm_free(pwm);
1101 pwm->args.period = chosen->period;
1102 pwm->args.polarity = chosen->polarity;
1104 return pwm;
1110 * @pwm: PWM device
1112 void pwm_put(struct pwm_device *pwm)
1114 if (!pwm)
1119 if (!test_and_clear_bit(PWMF_REQUESTED, &pwm->flags)) {
1124 if (pwm->chip->ops->free)
1125 pwm->chip->ops->free(pwm->chip, pwm);
1127 pwm_set_chip_data(pwm, NULL);
1128 pwm->label = NULL;
1130 module_put(pwm->chip->ops->owner);
1154 struct pwm_device **ptr, *pwm;
1160 pwm = pwm_get(dev, con_id);
1161 if (!IS_ERR(pwm)) {
1162 *ptr = pwm;
1168 return pwm;
1187 struct pwm_device **ptr, *pwm;
1193 pwm = of_pwm_get(dev, np, con_id);
1194 if (!IS_ERR(pwm)) {
1195 *ptr = pwm;
1201 return pwm;
1221 struct pwm_device **ptr, *pwm = ERR_PTR(-ENODEV);
1228 pwm = of_pwm_get(dev, to_of_node(fwnode), con_id);
1230 pwm = acpi_pwm_get(fwnode);
1232 if (!IS_ERR(pwm)) {
1233 *ptr = pwm;
1239 return pwm;
1256 * @pwm: PWM device
1262 void devm_pwm_put(struct device *dev, struct pwm_device *pwm)
1264 WARN_ON(devres_release(dev, devm_pwm_release, devm_pwm_match, pwm));
1274 struct pwm_device *pwm = &chip->pwms[i];
1277 pwm_get_state(pwm, &state);
1279 seq_printf(s, " pwm-%-3d (%-20.20s):", i, pwm->label);
1281 if (test_bit(PWMF_REQUESTED, &pwm->flags))
1341 debugfs_create_file("pwm", S_IFREG | S_IRUGO, NULL, NULL,