Lines Matching +full:parent +full:- +full:child
1 // SPDX-License-Identifier: GPL-2.0-or-later
18 struct device child; member
24 static struct pwm_export *child_to_pwm_export(struct device *child) in child_to_pwm_export() argument
26 return container_of(child, struct pwm_export, child); in child_to_pwm_export()
29 static struct pwm_device *child_to_pwm_device(struct device *child) in child_to_pwm_device() argument
31 struct pwm_export *export = child_to_pwm_export(child); in child_to_pwm_device()
33 return export->pwm; in child_to_pwm_device()
36 static ssize_t period_show(struct device *child, in period_show() argument
40 const struct pwm_device *pwm = child_to_pwm_device(child); in period_show()
48 static ssize_t period_store(struct device *child, in period_store() argument
52 struct pwm_export *export = child_to_pwm_export(child); in period_store()
53 struct pwm_device *pwm = export->pwm; in period_store()
62 mutex_lock(&export->lock); in period_store()
66 mutex_unlock(&export->lock); in period_store()
71 static ssize_t duty_cycle_show(struct device *child, in duty_cycle_show() argument
75 const struct pwm_device *pwm = child_to_pwm_device(child); in duty_cycle_show()
83 static ssize_t duty_cycle_store(struct device *child, in duty_cycle_store() argument
87 struct pwm_export *export = child_to_pwm_export(child); in duty_cycle_store()
88 struct pwm_device *pwm = export->pwm; in duty_cycle_store()
97 mutex_lock(&export->lock); in duty_cycle_store()
101 mutex_unlock(&export->lock); in duty_cycle_store()
107 static ssize_t oneshot_count_show(struct device *child, in oneshot_count_show() argument
111 const struct pwm_device *pwm = child_to_pwm_device(child); in oneshot_count_show()
119 static ssize_t oneshot_count_store(struct device *child, in oneshot_count_store() argument
123 struct pwm_export *export = child_to_pwm_export(child); in oneshot_count_store()
124 struct pwm_device *pwm = export->pwm; in oneshot_count_store()
133 mutex_lock(&export->lock); in oneshot_count_store()
137 mutex_unlock(&export->lock); in oneshot_count_store()
143 static ssize_t enable_show(struct device *child, in enable_show() argument
147 const struct pwm_device *pwm = child_to_pwm_device(child); in enable_show()
155 static ssize_t enable_store(struct device *child, in enable_store() argument
159 struct pwm_export *export = child_to_pwm_export(child); in enable_store()
160 struct pwm_device *pwm = export->pwm; in enable_store()
168 mutex_lock(&export->lock); in enable_store()
180 ret = -EINVAL; in enable_store()
187 mutex_unlock(&export->lock); in enable_store()
191 static ssize_t polarity_show(struct device *child, in polarity_show() argument
195 const struct pwm_device *pwm = child_to_pwm_device(child); in polarity_show()
214 static ssize_t polarity_store(struct device *child, in polarity_store() argument
218 struct pwm_export *export = child_to_pwm_export(child); in polarity_store()
219 struct pwm_device *pwm = export->pwm; in polarity_store()
229 return -EINVAL; in polarity_store()
231 mutex_lock(&export->lock); in polarity_store()
235 mutex_unlock(&export->lock); in polarity_store()
240 static ssize_t capture_show(struct device *child, in capture_show() argument
244 struct pwm_device *pwm = child_to_pwm_device(child); in capture_show()
255 static ssize_t output_type_show(struct device *child, in output_type_show() argument
259 const struct pwm_device *pwm = child_to_pwm_device(child); in output_type_show()
302 static void pwm_export_release(struct device *child) in pwm_export_release() argument
304 struct pwm_export *export = child_to_pwm_export(child); in pwm_export_release()
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()
348 static int pwm_unexport_match(struct device *child, void *data) in pwm_unexport_match() argument
350 return child_to_pwm_device(child) == data; in pwm_unexport_match()
353 static int pwm_unexport_child(struct device *parent, struct pwm_device *pwm) in pwm_unexport_child() argument
355 struct device *child; in pwm_unexport_child() local
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()
362 if (!child) 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()
371 put_device(child); in pwm_unexport_child()
372 device_unregister(child); in pwm_unexport_child()
378 static ssize_t export_store(struct device *parent, in export_store() argument
382 struct pwm_chip *chip = dev_get_drvdata(parent); in export_store()
391 if (hwpwm >= chip->npwm) in export_store()
392 return -ENODEV; in export_store()
398 ret = pwm_export_child(parent, pwm); in export_store()
406 static ssize_t unexport_store(struct device *parent, in unexport_store() argument
410 struct pwm_chip *chip = dev_get_drvdata(parent); in unexport_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()
427 static ssize_t npwm_show(struct device *parent, struct device_attribute *attr, in npwm_show() argument
430 const struct pwm_chip *chip = dev_get_drvdata(parent); in npwm_show()
432 return sprintf(buf, "%u\n", chip->npwm); in npwm_show()
444 /* takes export->lock on success */
445 static struct pwm_export *pwm_class_get_state(struct device *parent, in pwm_class_get_state() argument
449 struct device *child; in pwm_class_get_state() local
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()
456 if (!child) in pwm_class_get_state()
459 export = child_to_pwm_export(child); in pwm_class_get_state()
460 put_device(child); /* for device_find_child() */ in pwm_class_get_state()
462 mutex_lock(&export->lock); in pwm_class_get_state()
475 mutex_unlock(&export->lock); in pwm_class_apply_state()
480 static int pwm_class_resume_npwm(struct device *parent, unsigned int npwm) in pwm_class_resume_npwm() argument
482 struct pwm_chip *chip = dev_get_drvdata(parent); in pwm_class_resume_npwm()
487 struct pwm_device *pwm = &chip->pwms[i]; in pwm_class_resume_npwm()
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()
504 static int __maybe_unused pwm_class_suspend(struct device *parent) in pwm_class_suspend() argument
506 struct pwm_chip *chip = dev_get_drvdata(parent); in pwm_class_suspend()
510 for (i = 0; i < chip->npwm; i++) { in pwm_class_suspend()
511 struct pwm_device *pwm = &chip->pwms[i]; in pwm_class_suspend()
515 export = pwm_class_get_state(parent, pwm, &state); in pwm_class_suspend()
519 export->suspend = state; in pwm_class_suspend()
527 pwm_class_resume_npwm(parent, i); in pwm_class_suspend()
535 static int __maybe_unused pwm_class_resume(struct device *parent) in pwm_class_resume() argument
537 struct pwm_chip *chip = dev_get_drvdata(parent); in pwm_class_resume()
539 return pwm_class_resume_npwm(parent, chip->npwm); in pwm_class_resume()
551 static int pwmchip_sysfs_match(struct device *parent, const void *data) in pwmchip_sysfs_match() argument
553 return dev_get_drvdata(parent) == data; in pwmchip_sysfs_match()
558 struct device *parent; in pwmchip_sysfs_export() local
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()
566 if (IS_ERR(parent)) { in pwmchip_sysfs_export()
567 dev_warn(chip->dev, in pwmchip_sysfs_export()
574 struct device *parent; in pwmchip_sysfs_unexport() local
577 parent = class_find_device(&pwm_class, NULL, chip, in pwmchip_sysfs_unexport()
579 if (!parent) in pwmchip_sysfs_unexport()
582 for (i = 0; i < chip->npwm; i++) { in pwmchip_sysfs_unexport()
583 struct pwm_device *pwm = &chip->pwms[i]; in pwmchip_sysfs_unexport()
585 if (test_bit(PWMF_EXPORTED, &pwm->flags)) in pwmchip_sysfs_unexport()
586 pwm_unexport_child(parent, pwm); in pwmchip_sysfs_unexport()
589 put_device(parent); in pwmchip_sysfs_unexport()
590 device_unregister(parent); in pwmchip_sysfs_unexport()