Lines Matching +full:- +full:pwm
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * A simple sysfs interface for the generic PWM framework
15 #include <linux/pwm.h>
19 struct pwm_device *pwm; member
33 return export->pwm; in child_to_pwm_device()
40 const struct pwm_device *pwm = child_to_pwm_device(child); in period_show() local
43 pwm_get_state(pwm, &state); in period_show()
53 struct pwm_device *pwm = export->pwm; in period_store() local
62 mutex_lock(&export->lock); in period_store()
63 pwm_get_state(pwm, &state); in period_store()
65 ret = pwm_apply_state(pwm, &state); in period_store()
66 mutex_unlock(&export->lock); in period_store()
75 const struct pwm_device *pwm = child_to_pwm_device(child); in duty_cycle_show() local
78 pwm_get_state(pwm, &state); in duty_cycle_show()
88 struct pwm_device *pwm = export->pwm; in duty_cycle_store() local
97 mutex_lock(&export->lock); in duty_cycle_store()
98 pwm_get_state(pwm, &state); in duty_cycle_store()
100 ret = pwm_apply_state(pwm, &state); in duty_cycle_store()
101 mutex_unlock(&export->lock); in duty_cycle_store()
111 const struct pwm_device *pwm = child_to_pwm_device(child); in oneshot_count_show() local
114 pwm_get_state(pwm, &state); in oneshot_count_show()
124 struct pwm_device *pwm = export->pwm; in oneshot_count_store() local
133 mutex_lock(&export->lock); in oneshot_count_store()
134 pwm_get_state(pwm, &state); in oneshot_count_store()
136 ret = pwm_apply_state(pwm, &state); in oneshot_count_store()
137 mutex_unlock(&export->lock); in oneshot_count_store()
147 const struct pwm_device *pwm = child_to_pwm_device(child); in enable_show() local
150 pwm_get_state(pwm, &state); in enable_show()
160 struct pwm_device *pwm = export->pwm; in enable_store() local
168 mutex_lock(&export->lock); in enable_store()
170 pwm_get_state(pwm, &state); in enable_store()
180 ret = -EINVAL; in enable_store()
184 ret = pwm_apply_state(pwm, &state); in enable_store()
187 mutex_unlock(&export->lock); in enable_store()
195 const struct pwm_device *pwm = child_to_pwm_device(child); in polarity_show() local
199 pwm_get_state(pwm, &state); in polarity_show()
219 struct pwm_device *pwm = export->pwm; in polarity_store() local
229 return -EINVAL; in polarity_store()
231 mutex_lock(&export->lock); in polarity_store()
232 pwm_get_state(pwm, &state); in polarity_store()
234 ret = pwm_apply_state(pwm, &state); in polarity_store()
235 mutex_unlock(&export->lock); in polarity_store()
244 struct pwm_device *pwm = child_to_pwm_device(child); in capture_show() local
248 ret = pwm_capture(pwm, &result, jiffies_to_msecs(HZ)); in capture_show()
259 const struct pwm_device *pwm = child_to_pwm_device(child); in output_type_show() local
263 pwm_get_state(pwm, &state); in output_type_show()
300 ATTRIBUTE_GROUPS(pwm);
309 static int pwm_export_child(struct device *parent, struct pwm_device *pwm) in pwm_export_child() argument
315 if (test_and_set_bit(PWMF_EXPORTED, &pwm->flags)) in pwm_export_child()
316 return -EBUSY; in pwm_export_child()
320 clear_bit(PWMF_EXPORTED, &pwm->flags); in pwm_export_child()
321 return -ENOMEM; in pwm_export_child()
324 export->pwm = pwm; in pwm_export_child()
325 mutex_init(&export->lock); in pwm_export_child()
327 export->child.release = pwm_export_release; in pwm_export_child()
328 export->child.parent = parent; in pwm_export_child()
329 export->child.devt = MKDEV(0, 0); in pwm_export_child()
330 export->child.groups = pwm_groups; in pwm_export_child()
331 dev_set_name(&export->child, "pwm%u", pwm->hwpwm); in pwm_export_child()
333 ret = device_register(&export->child); in pwm_export_child()
335 clear_bit(PWMF_EXPORTED, &pwm->flags); in pwm_export_child()
336 put_device(&export->child); in pwm_export_child()
340 pwm_prop[0] = kasprintf(GFP_KERNEL, "EXPORT=pwm%u", pwm->hwpwm); in pwm_export_child()
342 kobject_uevent_env(&parent->kobj, KOBJ_CHANGE, pwm_prop); in pwm_export_child()
353 static int pwm_unexport_child(struct device *parent, struct pwm_device *pwm) in pwm_unexport_child() argument
358 if (!test_and_clear_bit(PWMF_EXPORTED, &pwm->flags)) in pwm_unexport_child()
359 return -ENODEV; in pwm_unexport_child()
361 child = device_find_child(parent, pwm, pwm_unexport_match); in pwm_unexport_child()
363 return -ENODEV; in pwm_unexport_child()
365 pwm_prop[0] = kasprintf(GFP_KERNEL, "UNEXPORT=pwm%u", pwm->hwpwm); in pwm_unexport_child()
367 kobject_uevent_env(&parent->kobj, KOBJ_CHANGE, pwm_prop); in pwm_unexport_child()
373 pwm_put(pwm); in pwm_unexport_child()
383 struct pwm_device *pwm; in export_store() local
391 if (hwpwm >= chip->npwm) in export_store()
392 return -ENODEV; in export_store()
394 pwm = pwm_request_from_chip(chip, hwpwm, "sysfs"); in export_store()
395 if (IS_ERR(pwm)) in export_store()
396 return PTR_ERR(pwm); in export_store()
398 ret = pwm_export_child(parent, pwm); in export_store()
400 pwm_put(pwm); in export_store()
418 if (hwpwm >= chip->npwm) in unexport_store()
419 return -ENODEV; in unexport_store()
421 ret = pwm_unexport_child(parent, &chip->pwms[hwpwm]); in unexport_store()
432 return sprintf(buf, "%u\n", chip->npwm); in npwm_show()
444 /* takes export->lock on success */
446 struct pwm_device *pwm, in pwm_class_get_state() argument
452 if (!test_bit(PWMF_EXPORTED, &pwm->flags)) in pwm_class_get_state()
455 child = device_find_child(parent, pwm, pwm_unexport_match); in pwm_class_get_state()
462 mutex_lock(&export->lock); in pwm_class_get_state()
463 pwm_get_state(pwm, state); in pwm_class_get_state()
469 struct pwm_device *pwm, in pwm_class_apply_state() argument
472 int ret = pwm_apply_state(pwm, state); in pwm_class_apply_state()
475 mutex_unlock(&export->lock); in pwm_class_apply_state()
487 struct pwm_device *pwm = &chip->pwms[i]; in pwm_class_resume_npwm() local
491 export = pwm_class_get_state(parent, pwm, &state); in pwm_class_resume_npwm()
495 state.enabled = export->suspend.enabled; in pwm_class_resume_npwm()
496 ret = pwm_class_apply_state(export, pwm, &state); in pwm_class_resume_npwm()
510 for (i = 0; i < chip->npwm; i++) { in pwm_class_suspend()
511 struct pwm_device *pwm = &chip->pwms[i]; in pwm_class_suspend() local
515 export = pwm_class_get_state(parent, pwm, &state); in pwm_class_suspend()
519 export->suspend = state; in pwm_class_suspend()
521 ret = pwm_class_apply_state(export, pwm, &state); in pwm_class_suspend()
524 * roll back the PWM devices that were disabled by in pwm_class_suspend()
539 return pwm_class_resume_npwm(parent, chip->npwm); in pwm_class_resume()
545 .name = "pwm",
564 parent = device_create(&pwm_class, chip->dev, MKDEV(0, 0), chip, in pwmchip_sysfs_export()
565 "pwmchip%d", chip->base); in pwmchip_sysfs_export()
567 dev_warn(chip->dev, in pwmchip_sysfs_export()
582 for (i = 0; i < chip->npwm; i++) { in pwmchip_sysfs_unexport()
583 struct pwm_device *pwm = &chip->pwms[i]; in pwmchip_sysfs_unexport() local
585 if (test_bit(PWMF_EXPORTED, &pwm->flags)) in pwmchip_sysfs_unexport()
586 pwm_unexport_child(parent, pwm); in pwmchip_sysfs_unexport()