Lines Matching refs:pwm

12 #include <linux/pwm.h>
21 #include <dt-bindings/pwm/pwm.h>
24 #include <trace/events/pwm.h>
85 static int pwm_device_request(struct pwm_device *pwm, const char *label)
89 if (test_bit(PWMF_REQUESTED, &pwm->flags))
92 if (!try_module_get(pwm->chip->ops->owner))
95 if (pwm->chip->ops->request) {
96 err = pwm->chip->ops->request(pwm->chip, pwm);
98 module_put(pwm->chip->ops->owner);
103 if (pwm->chip->ops->get_state) {
113 err = pwm->chip->ops->get_state(pwm->chip, pwm, &state);
114 trace_pwm_get(pwm, &state, err);
117 pwm->state = state;
120 pwm->last = pwm->state;
123 set_bit(PWMF_REQUESTED, &pwm->flags);
124 pwm->label = label;
132 struct pwm_device *pwm;
144 pwm = pwm_request_from_chip(chip, args->args[0], NULL);
145 if (IS_ERR(pwm))
146 return pwm;
148 pwm->args.period = args->args[1];
149 pwm->args.polarity = PWM_POLARITY_NORMAL;
153 pwm->args.polarity = PWM_POLARITY_INVERSED;
156 return pwm;
163 struct pwm_device *pwm;
172 pwm = pwm_request_from_chip(chip, 0, NULL);
173 if (IS_ERR(pwm))
174 return pwm;
176 pwm->args.period = args->args[0];
177 pwm->args.polarity = PWM_POLARITY_NORMAL;
180 pwm->args.polarity = PWM_POLARITY_INVERSED;
182 return pwm;
194 if (of_property_read_u32(chip->dev->of_node, "#pwm-cells",
213 * @pwm: PWM device
218 int pwm_set_chip_data(struct pwm_device *pwm, void *data)
220 if (!pwm)
223 pwm->chip_data = data;
231 * @pwm: PWM device
235 void *pwm_get_chip_data(struct pwm_device *pwm)
237 return pwm ? pwm->chip_data : NULL;
265 struct pwm_device *pwm;
275 chip->pwms = kcalloc(chip->npwm, sizeof(*pwm), GFP_KERNEL);
291 pwm = &chip->pwms[i];
293 pwm->chip = chip;
294 pwm->pwm = chip->base + i;
295 pwm->hwpwm = i;
367 struct pwm_device *pwm;
374 pwm = &chip->pwms[index];
376 err = pwm_device_request(pwm, label);
378 pwm = ERR_PTR(err);
381 return pwm;
385 static void pwm_apply_state_debug(struct pwm_device *pwm,
388 struct pwm_state *last = &pwm->last;
389 struct pwm_chip *chip = pwm->chip;
405 err = chip->ops->get_state(chip, pwm, &s1);
406 trace_pwm_get(pwm, &s1, err);
464 err = chip->ops->apply(chip, pwm, &s1);
465 trace_pwm_apply(pwm, &s1, err);
473 err = chip->ops->get_state(chip, pwm, last);
474 trace_pwm_get(pwm, last, err);
493 * @pwm: PWM device
496 int pwm_apply_state(struct pwm_device *pwm, const struct pwm_state *state)
510 if (!pwm || !state || !state->period ||
514 chip = pwm->chip;
516 if (state->period == pwm->state.period &&
517 state->duty_cycle == pwm->state.duty_cycle &&
518 state->polarity == pwm->state.polarity &&
519 state->enabled == pwm->state.enabled &&
520 state->usage_power == pwm->state.usage_power)
523 err = chip->ops->apply(chip, pwm, state);
524 trace_pwm_apply(pwm, state, err);
528 pwm->state = *state;
531 * only do this after pwm->state was applied as some
534 pwm_apply_state_debug(pwm, state);
542 * @pwm: PWM device
548 int pwm_capture(struct pwm_device *pwm, struct pwm_capture *result,
553 if (!pwm || !pwm->chip->ops)
556 if (!pwm->chip->ops->capture)
560 err = pwm->chip->ops->capture(pwm->chip, pwm, result, timeout);
569 * @pwm: PWM device
575 int pwm_adjust_config(struct pwm_device *pwm)
580 pwm_get_args(pwm, &pargs);
581 pwm_get_state(pwm, &state);
596 return pwm_apply_state(pwm, &state);
619 return pwm_apply_state(pwm, &state);
641 struct pwm_device *pwm)
651 dev_warn(pwm->chip->dev,
656 dl = device_link_add(dev, pwm->chip->dev, DL_FLAG_AUTOREMOVE_CONSUMER);
659 dev_name(pwm->chip->dev));
678 * be requested. Otherwise the "pwm-names" property is used to do a reverse
679 * lookup of the PWM index. This also means that the "pwm-names" property
689 struct pwm_device *pwm = NULL;
697 index = of_property_match_string(np, "pwm-names", con_id);
702 err = of_parse_phandle_with_args(np, "pwms", "#pwm-cells", index,
714 pwm = ERR_CAST(chip);
718 pwm = chip->of_xlate(chip, &args);
719 if (IS_ERR(pwm))
722 dl = pwm_device_link_add(dev, pwm);
725 pwm_put(pwm);
726 pwm = ERR_CAST(dl);
732 * "pwm-names" property if it exists. Otherwise use the name of
736 err = of_property_read_string_index(np, "pwm-names", index,
742 pwm->label = con_id;
747 return pwm;
769 struct pwm_device *pwm;
787 pwm = pwm_request_from_chip(chip, args.args[0], NULL);
788 if (IS_ERR(pwm))
789 return pwm;
791 pwm->args.period = args.args[1];
792 pwm->args.polarity = PWM_POLARITY_NORMAL;
795 pwm->args.polarity = PWM_POLARITY_INVERSED;
797 return pwm;
853 struct pwm_device *pwm;
867 pwm = acpi_pwm_get(fwnode);
868 if (!IS_ERR(pwm) || PTR_ERR(pwm) != -ENOENT)
869 return pwm;
943 pwm = pwm_request_from_chip(chip, chosen->index, con_id ?: dev_id);
944 if (IS_ERR(pwm))
945 return pwm;
947 dl = pwm_device_link_add(dev, pwm);
949 pwm_put(pwm);
953 pwm->args.period = chosen->period;
954 pwm->args.polarity = chosen->polarity;
956 return pwm;
962 * @pwm: PWM device
964 void pwm_put(struct pwm_device *pwm)
966 if (!pwm)
971 if (!test_and_clear_bit(PWMF_REQUESTED, &pwm->flags)) {
976 if (pwm->chip->ops->free)
977 pwm->chip->ops->free(pwm->chip, pwm);
979 pwm_set_chip_data(pwm, NULL);
980 pwm->label = NULL;
982 module_put(pwm->chip->ops->owner);
988 static void devm_pwm_release(void *pwm)
990 pwm_put(pwm);
1006 struct pwm_device *pwm;
1009 pwm = pwm_get(dev, con_id);
1010 if (IS_ERR(pwm))
1011 return pwm;
1013 ret = devm_add_action_or_reset(dev, devm_pwm_release, pwm);
1017 return pwm;
1037 struct pwm_device *pwm = ERR_PTR(-ENODEV);
1041 pwm = of_pwm_get(dev, to_of_node(fwnode), con_id);
1043 pwm = acpi_pwm_get(fwnode);
1044 if (IS_ERR(pwm))
1045 return pwm;
1047 ret = devm_add_action_or_reset(dev, devm_pwm_release, pwm);
1051 return pwm;
1061 struct pwm_device *pwm = &chip->pwms[i];
1064 pwm_get_state(pwm, &state);
1066 seq_printf(s, " pwm-%-3d (%-20.20s):", i, pwm->label);
1068 if (test_bit(PWMF_REQUESTED, &pwm->flags))
1131 debugfs_create_file("pwm", 0444, NULL, NULL, &pwm_debugfs_fops);